Download lean/HyperKitty/QLGLean4.lean from Snapkitty/hyperkitty-constraint-dsl: direct link, hf CLI and curl.
- Browser
- Download file 3.12 kB
-
https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/lean/HyperKitty/QLGLean4.lean
- Command line
-
hf download hf://Snapkitty/hyperkitty-constraint-dsl/lean/HyperKitty/QLGLean4.lean
-
curl -L -o QLGLean4.lean https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/lean/HyperKitty/QLGLean4.lean
3.12 kB
Lean 4 · 15
declarations statementsfull
structure MyComplex where body · 3 lines
re : Int
im : Int
deriving DecidableEq, Reprdef I : MyComplex := ⟨0, 1⟩ abbrev Vec3 = Fin 3 → Int def dot (v w : Vec3) : Int := body · 1 line
(v 0 * w 0 + v 1 * w 1 + v 2 * w 2)abbrev Matrix3 = Fin 3 → Fin 3 → Int def matVec (A : Matrix3) (x : Vec3) : Vec3 := body · 1 line
fun i => (A i 0 * x 0 + A i 1 * x 1 + A i 2 * x 2)def quadForm (Q : Matrix3) (x : Vec3) : Int := body · 1 line
dot x (matVec Q x)def I3 : Matrix3 := body · 1 line
fun i j => if i = j then 1 else 0def transpose (M : Matrix3) : Matrix3 := body · 1 line
fun i j => M j idef psd (M : Matrix3) : Prop := body · 1 line
∀ v : Vec3, 0 ≤ dot v (matVec M v)def nsqd (M : Matrix3) : Prop := body · 1 line
∀ v : Vec3, 0 ≤ dot v (matVec (transpose M) v)structure QLG where body · 8 lines
Q : Matrix3
b : Vec3
c : Int
K : Int
Qplus Qminus : Matrix3
Qp_s : psd Qplus
Qm_s : nsqd Qminus
deriving DecidableEqdef isBalanced (L : QLG) (x : Vec3) : Prop := body · 3 lines
(quadForm L.Q x + dot L.b x + L.c = 0) ∧
(quadForm L.Qplus x = quadForm L.Qminus x) ∧
(quadForm L.Qplus x = L.K)def exampleQLG : QLG := body · 15 lines
{ Q := fun i j => if i = j then 1 else 0 -- Q = I₃
b := fun _ => 0
c := -1
K := 1
Qplus := fun i j => if i = j then 1 else 0 -- Q⁺ = I₃
Qminus := fun i j => 0 -- Q⁻ = 0
Qp_s := by
intro v
simp [psd, quadForm, dot, matVec, I3]
nlinarith [sq_nonneg (v 0), sq_nonneg (v 1), sq_nonneg (v 2)]
Qm_s := by
intro v
simp [nsqd, quadForm, dot, matVec, I3, transpose]
nlinarith
}theorem exampleQLG_has_solution :
∃ (x : Vec3), isBalanced exampleQLG x ∧ x ≠ (fun _ => 0) := by proof · 9 lines
use ![1, 0, 0]
constructor
· -- Prove isBalanced
simp [exampleQLG, isBalanced, quadForm, dot, matVec, I3]
norm_num
· -- Prove x ≠ 0 vector
intro h
have h₁ := congr_fun h 0
norm_num at h₁Outline