statement
stringlengths
1
615
proof
stringlengths
0
8.26k
type
stringclasses
11 values
symbolic_name
stringlengths
1
64
library
stringclasses
29 values
filename
stringclasses
121 values
imports
listlengths
0
15
deps
listlengths
0
20
docstring
stringlengths
0
1.5k
source_url
stringclasses
1 value
commit
stringclasses
1 value
fromArray (A : Array (Array (Array Float))) : EncodedMatrixList
Id.run <| do let mut eml := empty for (i, ai) in A.data.enum do for (j, aij) in ai.data.enum do for (k, aijk) in aij.data.enum do if j >= k && (aijk > 0 || aijk < 0) then eml := eml.addEntry (EncodedMatrixListEntry.mk i j k aijk) return eml
def
CBF.EncodedMatrixList.fromArray
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
EncodedMatrixListListEntry where i : Nat j : Nat k : Nat l : Nat value : Float
structure
CBF.EncodedMatrixListListEntry
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
Represents the entry `Aₖₗ` in the `j`-th matrix of the `i`-th list.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
fromIndexAndEncodedMatrixList (i : Nat) (emle : EncodedMatrixListEntry) : EncodedMatrixListListEntry
EncodedMatrixListListEntry.mk i emle.i emle.j emle.k emle.value
def
CBF.EncodedMatrixListListEntry.fromIndexAndEncodedMatrixList
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
EncodedMatrixListList where n : Nat values : List EncodedMatrixListListEntry
structure
CBF.EncodedMatrixListList
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
Represents `C = [L₁, ...]` where each `Lᵢ` is a list of matrices and `n` is the total number of non-zero entries.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
empty : EncodedMatrixListList
EncodedMatrixListList.mk 0 []
def
CBF.EncodedMatrixListList.empty
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
isEmpty (emll : EncodedMatrixListList) : Prop
emll.n = 0
def
CBF.EncodedMatrixListList.isEmpty
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addEntry (emll : EncodedMatrixListList) (emlle : EncodedMatrixListListEntry) : EncodedMatrixListList
if emlle.value > 0 || emlle.value < 0 then EncodedMatrixListList.mk (emll.n + 1) (emll.values.concat emlle) else emll
def
CBF.EncodedMatrixListList.addEntry
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
stack (eml1 eml2 : EncodedMatrixListList) : EncodedMatrixListList
EncodedMatrixListList.mk (eml1.n + eml2.n) (eml1.values ++ eml2.values)
def
CBF.EncodedMatrixListList.stack
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
fromIndexAndEncodedMatrixList (i : Nat) (eml : EncodedMatrixList) : EncodedMatrixListList
Id.run <| do let mut emll := empty for emle in eml.values do let emlle := EncodedMatrixListListEntry.fromIndexAndEncodedMatrixList i emle emll := emll.addEntry emlle emll
def
CBF.EncodedMatrixListList.fromIndexAndEncodedMatrixList
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
fromArray (A : Array (Array (Array (Array Float)))) : EncodedMatrixListList
Id.run <| do let mut emll := empty for (i, ai) in A.data.enum do for (j, aij) in ai.data.enum do for (k, aijk) in aij.data.enum do for (l, aijkl) in aijk.data.enum do if k >= l && (aijkl > 0 || aijkl < 0) then emll := emll.addEntry (EncodedMatrixListListEntry.mk i j k l aijkl...
def
CBF.EncodedMatrixListList.fromArray
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
Problem where version : Nat objSense : ObjSense scalarVariables : ConeProduct PSDVariables : DimensionList scalarConstraints : ConeProduct PSDConstraints : DimensionList objectivePSDVariablesCoord : EncodedMatrixList objectiveScalarVariablesCoord : EncodedVector objectiveShiftCoord : EncodedValue sc...
structure
CBF.Problem
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
This is the main definition. It represents a full problem in conic benchmark format. The problem is defined as follows: min/max g^obj s.t. g_i ∈ K_i for i ∈ I --> Scalar constraints G_i ∈ K_i for i ∈ I^PSD --> PSD constraints x_j ∈ K_j for j ∈ J --> Scalar var...
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
empty : Problem
{ version := 3, objSense := ObjSense.MIN, scalarVariables := ConeProduct.empty, PSDVariables := DimensionList.empty, scalarConstraints := ConeProduct.empty, PSDConstraints := DimensionList.empty, objectivePSDVariablesCoord := EncodedMatrixList.empty, objectiveScalarVariablesCoord := EncodedVector.empty,...
def
CBF.Problem.empty
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setVersion (p : Problem) (v : Nat) : Problem
{ p with version := v }
def
CBF.Problem.setVersion
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setObjSense (p : Problem) (os : ObjSense) : Problem
{ p with objSense := os }
def
CBF.Problem.setObjSense
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setScalarVariables (p : Problem) (cp : ConeProduct) : Problem
{ p with scalarVariables := cp }
def
CBF.Problem.setScalarVariables
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setPSDVariables (p : Problem) (dl : DimensionList) : Problem
{ p with PSDVariables := dl }
def
CBF.Problem.setPSDVariables
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setScalarConstraints (p : Problem) (cp : ConeProduct) : Problem
{ p with scalarConstraints := cp }
def
CBF.Problem.setScalarConstraints
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setPSDConstraints (p : Problem) (dl : DimensionList) : Problem
{ p with PSDConstraints := dl }
def
CBF.Problem.setPSDConstraints
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setObjectivePSDVariablesCoord (p : Problem) (eml : EncodedMatrixList) : Problem
{ p with objectivePSDVariablesCoord := eml }
def
CBF.Problem.setObjectivePSDVariablesCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setObjectiveScalarVariablesCoord (p : Problem) (ev : EncodedVector) : Problem
{ p with objectiveScalarVariablesCoord := ev }
def
CBF.Problem.setObjectiveScalarVariablesCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setObjectiveShiftCoord (p : Problem) (ev : EncodedValue) : Problem
{ p with objectiveShiftCoord := ev }
def
CBF.Problem.setObjectiveShiftCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setScalarConstraintsPSDVariablesCoord (p : Problem) (emll : EncodedMatrixListList) : Problem
{ p with scalarConstraintsPSDVariablesCoord := emll }
def
CBF.Problem.setScalarConstraintsPSDVariablesCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setScalarConstraintsScalarVariablesCoord (p : Problem) (em : EncodedMatrix) : Problem
{ p with scalarConstraintsScalarVariablesCoord := em }
def
CBF.Problem.setScalarConstraintsScalarVariablesCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setScalarConstraintsShiftCoord (p : Problem) (ev : EncodedVector) : Problem
{ p with scalarConstraintsShiftCoord := ev }
def
CBF.Problem.setScalarConstraintsShiftCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setPSDConstraintsScalarVariablesCoord (p : Problem) (emll : EncodedMatrixListList) : Problem
{ p with PSDConstraintsScalarVariablesCoord := emll }
def
CBF.Problem.setPSDConstraintsScalarVariablesCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
setPSDConstraintsShiftCoord (p : Problem) (eml : EncodedMatrixList) : Problem
{ p with PSDConstraintsShiftCoord := eml }
def
CBF.Problem.setPSDConstraintsShiftCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addScalarVariable (p : Problem) (c : Cone) : Problem
{ p with scalarVariables := p.scalarVariables.addCone c }
def
CBF.Problem.addScalarVariable
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addPSDVariable (p : Problem) (d : Nat) : Problem
{ p with PSDVariables := p.PSDVariables.addDimension d }
def
CBF.Problem.addPSDVariable
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addScalarConstraint (p : Problem) (c : Cone) : Problem
{ p with scalarConstraints := p.scalarConstraints.addCone c }
def
CBF.Problem.addScalarConstraint
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addPSDConstraint (p : Problem) (d : Nat) : Problem
{ p with PSDConstraints := p.PSDConstraints.addDimension d }
def
CBF.Problem.addPSDConstraint
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addScalarConstraintsPSDVariablesCoord (p : Problem) (i : Nat) (eml : EncodedMatrixList) : Problem
let emll := EncodedMatrixListList.fromIndexAndEncodedMatrixList i eml { p with scalarConstraintsPSDVariablesCoord := p.scalarConstraintsPSDVariablesCoord.stack emll }
def
CBF.Problem.addScalarConstraintsPSDVariablesCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addScalarConstraintsScalarVariablesCoord (p : Problem) (i : Nat) (ev : EncodedVector) : Problem
let em := EncodedMatrix.fromIndexAndEncodedVector i ev { p with scalarConstraintsScalarVariablesCoord := p.scalarConstraintsScalarVariablesCoord.stack em }
def
CBF.Problem.addScalarConstraintsScalarVariablesCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addScalarConstraintsShiftCoord (p : Problem) (i : Nat) (v : Float) : Problem
let ev := EncodedVector.fromIndexAndValue i v { p with scalarConstraintsShiftCoord := p.scalarConstraintsShiftCoord.stack ev}
def
CBF.Problem.addScalarConstraintsShiftCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addPSDConstraintsScalarVariablesCoord (p : Problem) (i : Nat) (eml : EncodedMatrixList) : Problem
let emll := EncodedMatrixListList.fromIndexAndEncodedMatrixList i eml { p with PSDConstraintsScalarVariablesCoord := p.PSDConstraintsScalarVariablesCoord.stack emll }
def
CBF.Problem.addPSDConstraintsScalarVariablesCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addPSDConstraintsShiftCoord (p : Problem) (i : Nat) (em : EncodedMatrix) : Problem
let eml := EncodedMatrixList.fromIndexAndEncodedMatrix i em { p with PSDConstraintsShiftCoord := p.PSDConstraintsShiftCoord.stack eml }
def
CBF.Problem.addPSDConstraintsShiftCoord
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addScalarValuedAffineConstraint (p : Problem) (c : Cone) (Fk : EncodedMatrixList) (ak : EncodedVector) (bk : Float) : Problem
Id.run <| do let k := p.scalarConstraints.k let mut newP := p newP := newP.addScalarConstraint c newP := newP.addScalarConstraintsPSDVariablesCoord k Fk newP := newP.addScalarConstraintsScalarVariablesCoord k ak newP := newP.addScalarConstraintsShiftCoord k bk newP
def
CBF.Problem.addScalarValuedAffineConstraint
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
addMatrixValuedAffineConstraint (p : Problem) (d : Nat) (Hk : EncodedMatrixList) (Dk : EncodedMatrix) : Problem
Id.run <| do let k := p.PSDConstraints.n let mut newP := p newP := newP.addPSDConstraint d newP := newP.addPSDConstraintsScalarVariablesCoord k Hk newP := newP.addPSDConstraintsShiftCoord k Dk newP
def
CBF.Problem.addMatrixValuedAffineConstraint
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBF.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
inferDimension (ty : Expr) : MetaM (List (Nat × Nat))
match ty.consumeMData with | .const ``Real _ => return [(1, 1)] | .forallE _ (.app (.const ``Fin _) nExpr) e _ => match e with | .const ``Real _ => do let n : Nat ← evalExpr Nat (mkConst ``Nat) nExpr return [(n, 1)] | .forallE _ (.app (.const ``Fin _) mExpr) (.const ``Real _) _ => do ...
def
CvxLean.inferDimension
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBFOfProblemData.lean
[ "CvxLean.Lib.Math.Data.Real", "CvxLean.Meta.Minimization", "CvxLean.Meta.Util.Error", "CvxLean.Command.Solve.Float.ProblemData", "CvxLean.Command.Solve.Mosek.CBF" ]
[]
Given thet type of the domain return the dimensions of each component. For example, for `ℝ × (Fin n → ℝ) × (Matrix (Fin m) (Fin k) ℝ)`, return `[(1, 1), (n, 1), (m, k)]`
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
getTotalDim (minExpr : MinimizationExpr) : MetaM Nat
do let vars ← decomposeDomainInstantiating minExpr let mut totalDim := 0 for (_, varTy) in vars do let dims ← inferDimension varTy for (n, m) in dims do totalDim := totalDim + n * m return totalDim
def
CvxLean.getTotalDim
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBFOfProblemData.lean
[ "CvxLean.Lib.Math.Data.Real", "CvxLean.Meta.Minimization", "CvxLean.Meta.Util.Error", "CvxLean.Command.Solve.Float.ProblemData", "CvxLean.Command.Solve.Mosek.CBF" ]
[]
Total dimension of a problem. For example, `ℝ × (Fin n → ℝ) × (Matrix (Fin m) (Fin k) ℝ)` has total dimension `1 + n + mk`. We use this to know how many optimization variables to generate.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
translateCone : ScalarConeType → CBF.ConeType
| ScalarConeType.Zero => CBF.ConeType.LEq | ScalarConeType.PosOrth => CBF.ConeType.LPos | ScalarConeType.Exp => CBF.ConeType.EXP | ScalarConeType.Q => CBF.ConeType.Q | ScalarConeType.QR => CBF.ConeType.QR
def
CvxLean.CBF.translateCone
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBFOfProblemData.lean
[ "CvxLean.Lib.Math.Data.Real", "CvxLean.Meta.Minimization", "CvxLean.Meta.Util.Error", "CvxLean.Command.Solve.Float.ProblemData", "CvxLean.Command.Solve.Mosek.CBF" ]
[ "CBF.ConeType" ]
Translate generic cone types from `CvxLean/Command/Solve/Float/ProblemData.lean` to MOSEK cones.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
groupCones (sections : ScalarAffineSections) (l : List CBF.Cone) : MetaM (List CBF.Cone)
do let l := l.toArray let mut res := [] let mut currIdx := 0 for idx in sections.data do let group := l[currIdx:idx] if h : group.size > 0 then let c := group.get ⟨0, h⟩ let coneType := c.type for c' in group do if !(c'.type = coneType) then throwSolveError "only cone...
def
CvxLean.CBF.groupCones
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBFOfProblemData.lean
[ "CvxLean.Lib.Math.Data.Real", "CvxLean.Meta.Minimization", "CvxLean.Meta.Util.Error", "CvxLean.Command.Solve.Float.ProblemData", "CvxLean.Command.Solve.Mosek.CBF" ]
[ "CBF.Cone" ]
Constraints in non-matrix cones with intrinsic dimension (`𝒦ₑ`, `𝒬ⁿ⁺¹`, and `𝒬ᵣⁿ⁺²`) are defined by a series of constraints. These need to be grouped appropriately. In `CvxLean/Command/Solve/Float/Coeffs.lean` we keep track of these groups as "sections". These are used here to correctly write the problem in CBF.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
ofProblemData (minExpr : MinimizationExpr) (data : ProblemData) (sections : ScalarAffineSections) : MetaM CBF.Problem
do let totalDim ← getTotalDim minExpr let mut cbf := CBF.Problem.empty cbf := cbf.addScalarVariable (CBF.Cone.mk CBF.ConeType.F totalDim) if h : data.objective.isSome then let sa := data.objective.get h let AEnc := CBF.EncodedMatrixList.fromArray #[sa.A] let aEnc := CBF.EncodedVector.fromArray sa....
def
CvxLean.CBF.ofProblemData
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/CBFOfProblemData.lean
[ "CvxLean.Lib.Math.Data.Real", "CvxLean.Meta.Minimization", "CvxLean.Meta.Util.Error", "CvxLean.Command.Solve.Float.ProblemData", "CvxLean.Command.Solve.Mosek.CBF" ]
[ "CBF.EncodedMatrix.fromArray", "CBF.EncodedMatrixList.fromArray", "CBF.EncodedVector.fromArray", "CBF.Problem", "CBF.Problem.empty" ]
Convert numerical problem data of a problem into CBF format to be solved by MOSEK.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
mosekBinPath
""
def
mosekBinPath
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Path.lean
[]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
Summary where name : String problemStatus : String solutionStatus : String objectiveName : String primalObjective : Float dualObjective : Float
structure
Sol.Summary
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Stores general information about the solution, crucially the optimality status of the problem and the attained values.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
StatusKey | UN | BS | SB | LL | UL | EQ | IN
inductive
Sol.StatusKey
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Variable status. Following MOSEK's documentation: UN : Unknown status. BS : Basic. Not at limit, adjusted to satisfy the constraints. SB : Superbasic. Not at limit, adjusted to minimize or maximize the objective. LL : At the lower limit (bound). UL : At the upper limit (bound). EQ : Lower limit is identical to upper li...
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
Constraint where index : Nat name : String status : StatusKey activity : Float lowerLimit : Option Float upperLimit : Option Float dualLower : Option Float dualUpper : Option Float
structure
Sol.Constraint
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Value of an optimization constraint.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
Variable extends Constraint where conicDual : Option Float
structure
Sol.Variable
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Value of an optimization variable.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
SymmMatrixVariable where index : Nat name : String I : Nat J : Nat primal : Option Float dual : Option Float
structure
Sol.SymmMatrixVariable
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Value of an entry of and symmetric matrix optimization variable.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
Result where summary : Summary constraints : List Constraint vars : List Variable symmMatrixVars : List SymmMatrixVariable
structure
Sol.Result
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
All the data in MOSEK's solution file format.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
Response | success (res : Result) : Response | failure (code : Nat) : Response
inductive
Sol.Response
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Either a full result or a MOSEK error code.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
ws' : Parsec Unit
fun it => Lean.Parsec.ParseResult.success (skipWs' it) () where skipWs' (it : String.Iterator) : String.Iterator := if it.hasNext then let c := it.curr if c = '\u0009' ∨ c = '\u000d' ∨ c = '\u0020' then skipWs' it.next else it else it
def
Sol.Parser.ws'
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Variation of 'ws' not skipping line breaks.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
endOfLine : Parsec Unit
skipChar '\u000a' <|> eof
def
Sol.Parser.endOfLine
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
End of line (or file).
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
char : Parsec Char
asciiLetter <|> hexDigit <|> pchar '_' <|> fail "Invalid character."
def
Sol.Parser.char
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse only valid characters.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
string : Parsec String
many1Chars char
def
Sol.Parser.string
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse string containing only valid characters as in `char`.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
nat : Parsec Nat
Json.Parser.natMaybeZero
def
Sol.Parser.nat
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse a `Nat` using the `JsonNumber` parser.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
float : Parsec Float
fun it₁ => match Json.Parser.num it₁ with | ParseResult.success it₂ res => let f := Float.ofScientific res.mantissa.natAbs true res.exponent ParseResult.success it₂ (if res.mantissa < 0 then -f else f) | ParseResult.error it₂ err => ParseResult.error it₂ err
def
Sol.Parser.float
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse a `Float` using the `JsonNumber` parser.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
optionFloat : Parsec (Option Float)
(some <$> float) <|> (skipString "NONE" *> pure none)
def
Sol.Parser.optionFloat
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Use `float` or return none if the string is `"NONE"`.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
summaryIdentifier (id : String) : Parsec Unit
skipString id *> ws' *> skipChar ':' *> ws'
def
Sol.Parser.summaryIdentifier
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Skip the beginning of a summary line.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
summaryLine (id : String) (p : Parsec α) : Parsec α
summaryIdentifier id *> p <* ws' <* endOfLine
def
Sol.Parser.summaryLine
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Generic function to parse summary lines.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
stringSummaryLine (id : String) : Parsec String
summaryLine id string
def
Sol.Parser.stringSummaryLine
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Specialize `summaryLine` to strings.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
floatSummaryLine (id : String) : Parsec Float
summaryLine id float
def
Sol.Parser.floatSummaryLine
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Specialize `summaryLine` to floats.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
summary : Parsec Summary
Summary.mk <$> ((skipString "NAME" *> ws' *> skipChar ':' *> ws') *> pure "anonymous" <* endOfLine) <*> stringSummaryLine "PROBLEM STATUS" <*> stringSummaryLine "SOLUTION STATUS" <*> stringSummaryLine "OBJECTIVE NAME" <*> floatSummaryLine "PRIMAL OBJECTIVE" <*> floatSummaryLine "DUAL OBJECTIVE" <* ...
def
Sol.Parser.summary
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse the whole `Sol.summary` section.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
constraintsTitle : Parsec Unit
skipString "CONSTRAINTS" <* ws' <* endOfLine
def
Sol.Parser.constraintsTitle
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Skip the title in the constraints section.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
constraintsHeaders : Parsec Unit
skipString "INDEX" <* ws' <* skipString "NAME" <* ws' <* skipString "AT" <* ws' <* skipString "ACTIVITY" <* ws' <* skipString "LOWER LIMIT" <* ws' <* skipString "UPPER LIMIT" <* ws' <* skipString "DUAL LOWER" <* ws' <* skipString "DUAL UPPER" <* ws' <* endOfLine
def
Sol.Parser.constraintsHeaders
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Skip the headers in the constraints section.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
statusKey : Parsec StatusKey
(skipString "UN" *> pure StatusKey.UN) <|> (skipString "BS" *> pure StatusKey.BS) <|> (skipString "SB" *> pure StatusKey.SB) <|> (skipString "LL" *> pure StatusKey.LL) <|> (skipString "UL" *> pure StatusKey.UL) <|> (skipString "EQ" *> pure StatusKey.EQ) <|> (skipString "**" *> pure StatusKey.IN) <|> (fail...
def
Sol.Parser.statusKey
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse a `StatusKey`.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
constraintElem (p : Parsec α) : Parsec α
ws' *> p
def
Sol.Parser.constraintElem
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Generic function to parse constraint elements, handling whitespaces.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
constraint : Parsec Constraint
Constraint.mk <$> constraintElem nat <*> constraintElem string <*> constraintElem statusKey <*> constraintElem float <*> constraintElem optionFloat <*> constraintElem optionFloat <*> constraintElem optionFloat <*> constraintElem optionFloat <* ws' <* endOfLine
def
Sol.Parser.constraint
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse a `Constraint` line.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
constraints : Parsec (List Constraint)
constraintsTitle *> constraintsHeaders *> Array.data <$> many constraint
def
Sol.Parser.constraints
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse the whole `Sol.Result.constraints` section.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
varsTitle : Parsec Unit
skipString "VARIABLES" <* endOfLine
def
Sol.Parser.varsTitle
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Skip the title in the variables section.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
varsHeaders : Parsec Unit
skipString "INDEX" <* ws' <* skipString "NAME" <* ws' <* skipString "AT" <* ws' <* skipString "ACTIVITY" <* ws' <* skipString "LOWER LIMIT" <* ws' <* skipString "UPPER LIMIT" <* ws' <* skipString "DUAL LOWER" <* ws' <* skipString "DUAL UPPER" <* ws' <* (skipString "CONIC DUAL"...
def
Sol.Parser.varsHeaders
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Skip the headers in the variables section. Handle CONIC DUAL case.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
var : Parsec Variable
let noBreakConstraint := Constraint.mk <$> constraintElem nat <*> constraintElem string <*> constraintElem statusKey <*> constraintElem float <*> constraintElem optionFloat <*> constraintElem optionFloat <*> constraintElem optionFloat <*> constraintElem optionFloat ...
def
Sol.Parser.var
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse a `Variable` line.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
vars : Parsec (List Variable)
varsTitle *> varsHeaders *> Array.data <$> many var
def
Sol.Parser.vars
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse the whole `Sol.Result.variables` section.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
symmMatrixVarsTitle : Parsec Unit
skipString "SYMMETRIC MATRIX VARIABLES" <* endOfLine
def
Sol.Parser.symmMatrixVarsTitle
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Skip the title in the symmetric matrix variables section.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
symmMatrixVarsHeaders : Parsec Unit
skipString "INDEX" <* ws' <* skipString "NAME" <* ws' <* skipString "I" <* ws' <* skipString "J" <* ws' <* skipString "PRIMAL" <* ws' <* skipString "DUAL" <* ws' <* endOfLine
def
Sol.Parser.symmMatrixVarsHeaders
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Skip the headers in the symmetric matrix variables section.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
symmMatrixVar : Parsec SymmMatrixVariable
SymmMatrixVariable.mk <$> constraintElem nat <*> constraintElem string <*> constraintElem nat <*> constraintElem nat <*> constraintElem optionFloat <*> constraintElem optionFloat <* ws' <* endOfLine
def
Sol.Parser.symmMatrixVar
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse a `SymmMatrixVariable` line.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
symmMatrixVars : Parsec (List SymmMatrixVariable)
(symmMatrixVarsTitle *> symmMatrixVarsHeaders *> Array.data <$> many symmMatrixVar) <|> pure []
def
Sol.Parser.symmMatrixVars
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse the whole `Sol.Result.symmMatrixVariables` section.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
result : Parsec Result
Result.mk <$> summary <* ws <*> constraints <* ws <*> vars <* ws <*> symmMatrixVars <* ws
def
Sol.Parser.result
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse the whole `Sol.Result` object.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
parse (s : String) : Except String Result
match result s.mkIterator with | Parsec.ParseResult.success _ res => Except.ok res | Parsec.ParseResult.error it err => Except.error s!"Error at offset {it.i.byteIdx}. Error: {err}.}"
def
Sol.Parser.parse
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/Sol.lean
[ "Lean.Data.Parsec", "Lean.Data.Json.Parser" ]
[]
Parse using `result` and handle errors.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
Variable.toSimpleVarSol (v : Sol.Variable) : SimpleVarSol
{ name := v.name, value := v.activity }
def
CvxLean.Sol.Variable.toSimpleVarSol
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/SolToSolutionData.lean
[ "CvxLean.Meta.Util.Error", "CvxLean.Command.Solve.Float.SolutionData", "CvxLean.Command.Solve.Mosek.Sol" ]
[ "Sol.Variable" ]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
SymmMatrixVariable.toSimpleMatrixVarSol (v : Sol.SymmMatrixVariable) : SimpleMatrixVarSol
{ name := v.name, I := v.I, J := v.J, value := v.primal }
def
CvxLean.Sol.SymmMatrixVariable.toSimpleMatrixVarSol
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/SolToSolutionData.lean
[ "CvxLean.Meta.Util.Error", "CvxLean.Command.Solve.Float.SolutionData", "CvxLean.Command.Solve.Mosek.Sol" ]
[ "Sol.SymmMatrixVariable" ]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
Result.toSolutionData (sol : Sol.Result) : SolutionData
{ status := sol.summary.problemStatus, varsSols := sol.vars.map Variable.toSimpleVarSol, matrixVarsSols := sol.symmMatrixVars.map SymmMatrixVariable.toSimpleMatrixVarSol }
def
CvxLean.Sol.Result.toSolutionData
Command.Solve.Mosek
CvxLean/Command/Solve/Mosek/SolToSolutionData.lean
[ "CvxLean.Meta.Util.Error", "CvxLean.Command.Solve.Float.SolutionData", "CvxLean.Command.Solve.Mosek.Sol" ]
[ "Sol.Result" ]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
evalTimeCmd : CommandElab
fun stx => match stx with | `(time_cmd $cmd) => do let before ← BaseIO.toIO IO.monoMsNow elabCommand cmd let after ← BaseIO.toIO IO.monoMsNow let diff := after - before dbg_trace s!"Command time: {diff} ms" | _ => throwUnsupportedSyntax
def
evalTimeCmd
Command.Util
CvxLean/Command/Util/TimeCmd.lean
[ "Lean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
p₁
optimization (x y : ℝ) maximize sqrt (x - y) subject to c1 : y = 2 * x - 3 c2 : x ^ (2 : ℝ) ≤ 2 c3 : 0 ≤ x - y #check p₁ -- Apply DCP transformation and call solver. solve p₁ #eval p₁.status #eval p₁.solution #eval p₁.value
def
LT2024.p₁
Demos
CvxLean/Demos/LT2024.lean
[ "CvxLean" ]
[ "c1" ]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
p₂
optimization (x : ℝ) minimize (x) subject to c1 : 1 / 1000 ≤ x c2 : 1 / sqrt x ≤ exp x -- solve p₂ -- set_option trace.Meta.debug true -- Equivalence mode. equivalence eqv₂/q₂ : p₂ := by pre_dcp solve q₂ #print q₂.conicForm #eval q₂.status #eval q₂.solution #eval q₂.value
def
LT2024.p₂
Demos
CvxLean/Demos/LT2024.lean
[ "CvxLean" ]
[ "c1" ]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
p₃ (Awall Aflr α β γ δ : ℝ)
optimization (h w d : ℝ) minimize (1 / (h * w * d)) subject to c1 : 0 < h c2 : 0 < w c3 : 0 < d c4 : 2 * (h * w + h * d) ≤ Awall c5 : w * d ≤ Aflr c6 : α ≤ h / w c7 : h / w ≤ β c8 : γ ≤ d / w c9 : d / w ≤ δ equivalence* eqv₃/q₃ : p₃ 100 10 0.5 2 0.5 2 := by...
def
LT2024.p₃
Demos
CvxLean/Demos/LT2024.lean
[ "CvxLean" ]
[ "c1", "c5" ]
Maximizing the volume of a box. See: https://www.cvxpy.org/examples/dgp/max_volume_box.html
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
p₃.solution
eqv₃.backward_map q₃.solution #eval p₃.solution
def
LT2024.p₃.solution
Demos
CvxLean/Demos/LT2024.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
h
p₃.solution.1
def
LT2024.h
Demos
CvxLean/Demos/LT2024.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
w
p₃.solution.2.1
def
LT2024.w
Demos
CvxLean/Demos/LT2024.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
d
p₃.solution.2.2 #eval h * w * d #eval 2 * (h * w + h * d) ≤ 100 #eval w * d ≤ 10 #eval 0.5 ≤ h / w #eval h / w ≤ 2 #eval 0.5 ≤ d / w #eval d / w ≤ 2
def
LT2024.d
Demos
CvxLean/Demos/LT2024.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
p
optimization (x y : ℝ) minimize -2 * x subject to c₁ : 0 ≤ x c₂ : 1 < y c₃ : log (y - 1) ≤ 2 * sqrt x + 1 c₄ : 3 * x + 5 * y ≤ 10 -- Transform (proving `p ≡ q`). equivalence* eqv/q : p := by change_of_variables! (v) (y ↦ v + 1) change_of_variables! (w) (v ↦ exp w) remove_constr c...
def
p
Demos
CvxLean/Demos/README.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
covEstimation (n : ℕ) (N : ℕ) (α : ℝ) (y : Fin N → Fin n → ℝ)
optimization (R : Matrix (Fin n) (Fin n) ℝ) maximize (∏ i, gaussianPdf R (y i)) subject to c_pos_def : R.PosDef c_sparse : R⁻¹.abs.sum ≤ α reduction* red/covEstimationConvex (n : ℕ) (N : ℕ) (α : ℝ) (y : Fin N → Fin n → ℝ) : covEstimation n N α y := by -- Change objective function. reduction_s...
def
CovarianceEstimation.covEstimation
Examples
CvxLean/Examples/CovarianceEstimation.lean
[ "CvxLean" ]
[ "Matrix.PosDef_inv_iff_PosDef", "Real.inverse_eq_inv", "gaussianPdf", "log_prod_gaussianPdf", "prod_gaussianPdf_pos", "sum_quadForm" ]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
nₚ : ℕ
2
def
CovarianceEstimation.nₚ
Examples
CvxLean/Examples/CovarianceEstimation.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
Nₚ : ℕ
4
def
CovarianceEstimation.Nₚ
Examples
CvxLean/Examples/CovarianceEstimation.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
αₚ : ℝ
1
def
CovarianceEstimation.αₚ
Examples
CvxLean/Examples/CovarianceEstimation.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
yₚ : Fin Nₚ → Fin nₚ → ℝ
![![0, 2], ![2, 0], ![-2, 0], ![0, -2]] solve covEstimationConvex nₚ Nₚ αₚ yₚ #print covEstimationConvex.conicForm -- minimize -- -(-(Nₚ • log (sqrt ((2 * π) ^ nₚ)) + Nₚ • (-Vec.sum t.0 / 2)) + -- -(↑Nₚ * trace ((covarianceMatrix fun i => yₚ i) * Rᵀ) / 2)) -- subject to -- _ : Real.nonnegOrthCone (α...
def
CovarianceEstimation.yₚ
Examples
CvxLean/Examples/CovarianceEstimation.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
Rₚ_opt
red.backward_map nₚ Nₚ αₚ.float yₚ.float covEstimationConvex.solution #eval Rₚ_opt
def
CovarianceEstimation.Rₚ_opt
Examples
CvxLean/Examples/CovarianceEstimation.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
leastSquares {n : ℕ} (a : Fin n → ℝ)
optimization (x : ℝ) minimize (∑ i, ((a i - x) ^ 2) : ℝ)
def
leastSquares
Examples
CvxLean/Examples/FittingSphere.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
mean {n : ℕ} (a : Fin n → ℝ) : ℝ
(1 / n) * ∑ i, (a i)
def
mean
Examples
CvxLean/Examples/FittingSphere.lean
[ "CvxLean" ]
[]
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
leastSquares_alt_objFun {n : ℕ} (hn : 0 < n) (a : Fin n → ℝ) (x : ℝ) : (∑ i, ((a i - x) ^ 2)) = n * ((x - mean a) ^ 2 + (mean (a ^ 2) - (mean a) ^ 2))
by calc -- 1) Σ (aᵢ - x)² = Σ (aᵢ² - 2aᵢx + x²) _ = ∑ i, ((a i) ^ 2 - 2 * (a i) * x + (x ^ 2)) := by congr; funext i; simp; ring -- 2) ... = Σ aᵢ² - 2xΣ aᵢ + nx² _ = ∑ i, ((a i) ^ 2) - 2 * x * ∑ i, (a i) + n * (x ^ 2) := by rw [sum_add_distrib, sum_sub_distrib, ← sum_mul, ← mul_sum]; simp [sum_const];...
lemma
leastSquares_alt_objFun
Examples
CvxLean/Examples/FittingSphere.lean
[ "CvxLean" ]
[ "mean" ]
It is useful to rewrite the sum of squares in the following way to prove `leastSquares_optimal_eq_mean`, following Marty Cohen's answer in https://math.stackexchange.com/questions/2554243.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840
leastSquares_optimal_eq_mean {n : ℕ} (hn : 0 < n) (a : Fin n → ℝ) (x : ℝ) (h : (leastSquares a).optimal x) : x = mean a
by simp [optimal, feasible, leastSquares] at h replace h : ∀ y, (x - mean a) ^ 2 ≤ (y - mean a) ^ 2 := by intros y have hy := h y have h_rw_x := leastSquares_alt_objFun hn a x have h_rw_y := leastSquares_alt_objFun hn a y simp only [rpow_two] at h_rw_x h_rw_y ⊢ rwa [h_rw_x, h_rw_y, mul_le_m...
lemma
leastSquares_optimal_eq_mean
Examples
CvxLean/Examples/FittingSphere.lean
[ "CvxLean" ]
[ "leastSquares", "leastSquares_alt_objFun", "mean" ]
Key result about least squares: `x* = mean a`.
https://github.com/verified-optimization/CvxLean
c62c2f292c6420f31a12e738ebebdfed50f6f840