| /-
|
| Quadratic Ledger Geometry (QLG) – Core Proof Framework
|
| No mathlib imports. Pure Lean 4 core.
|
|
|
| The routing algebra: balance equation, invariant preservation, proof gates.
|
| -/
|
|
|
|
|
| abbrev Vec3 = Fin 3 → Int
|
|
|
|
|
| abbrev Matrix3 = Fin 3 → Fin 3 → Int
|
|
|
|
|
| def dot (v w : Vec3) : Int :=
|
| (v 0 * w 0 + v 1 * w 1 + v 2 * w 2)
|
|
|
|
|
| def matVec (A : Matrix3) (x : Vec3) : Vec3 :=
|
| fun i =>
|
| (A i 0 * x 0 + A i 1 * x 1 + A i 2 * x 2)
|
|
|
|
|
| def transpose (M : Matrix3) : Matrix3 :=
|
| fun i j => M j i
|
|
|
|
|
| def matAdd (A B : Matrix3) : Matrix3 :=
|
| fun i j => A i j + B i j
|
|
|
|
|
| def smul (c : Int) (M : Matrix3) : Matrix3 :=
|
| fun i j => c * M i j
|
|
|
|
|
| def quadForm (Q : Matrix3) (x : Vec3) : Int :=
|
| dot x (matVec Q x)
|
|
|
|
|
| def psd (M : Matrix3) : Prop :=
|
| ∀ v : Vec3, 0 ≤ dot v (matVec M v)
|
|
|
|
|
| def nsd (M : Matrix3) : Prop :=
|
| ∀ v : Vec3, 0 ≤ dot v (matVec M v)
|
|
|
|
|
| structure QLG where
|
| Q : Matrix3
|
| b : Vec3
|
| c : Int
|
| K : Int
|
| Qplus Qminus : Matrix3
|
| h_psd : psd Qplus
|
| h_nsd : nsd Qminus
|
|
|
|
|
| def isBalanced (L : QLG) (x : Vec3) : Prop :=
|
| (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 unitSphereQLG : QLG :=
|
| { Q := fun i j => if i = j then 1 else 0
|
| b := fun _ => 0
|
| c := -1
|
| K := 1
|
| Qplus := fun i j => if i = j then 1 else 0
|
| Qminus := fun i j => 0
|
| h_psd := by
|
| intro v
|
| simp only [dot, matVec]
|
| nlinarith [sq_nonneg (v 0), sq_nonneg (v 1), sq_nonneg (v 2)]
|
| h_nsd := by
|
| intro v
|
| simp only [dot, matVec]
|
| ring_nf
|
| }
|
|
|
|
|
| def unitWitness : Vec3 := ![1, 0, 0]
|
|
|
|
|
| theorem unitSphere_has_solution :
|
| isBalanced unitSphereQLG unitWitness := by
|
| constructor
|
| ·
|
| simp [isBalanced, unitSphereQLG, unitWitness, quadForm, dot, matVec]
|
| norm_num
|
| constructor
|
| ·
|
| simp [unitSphereQLG, unitWitness, quadForm, dot, matVec]
|
| norm_num
|
| ·
|
| simp [unitSphereQLG, unitWitness, quadForm, dot, matVec]
|
| norm_num
|
|
|