interplane.Get Omega
Read in your language

omega-principia

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

omega-principia / proofs / FmmOrbitInvariance.lean

346 lines · 14533 bytes Raw Blame History
1/-
2SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3Author: Stapleton, M. Drake (ORCID: 0009-0002-6890-7111)
4AI Tooling Disclosure: Assisted by Antigravity (Google DeepMind) for formalization.
5
6FmmOrbitInvariance.lean
7Zero-Mathlib, pure-kernel Lean 4.36.0 formalization of:
8 1. Universal Matrix-Multiplication Associativity & Identity Laws over any Commutative Ring R
9 2. Universal Unimodular Sandwich Orbit Invariance Theorem:
10 For arbitrary (m, n, p) and any invertible (P, Q, S) over R:
11 Pinv * ((P * A * Qinv) * (Q * B * Sinv)) * S = A * B
12 3. Universal Elementary Shear Invertibility Theorem: E_{ij}(c) * E_{ij}(-c) = I for all i != j, c in R
13 4. Recursive Leading-Constant Strict Monotonicity under Addition-Count Reduction
14 5. Four broken-model negative controls (neg_ctrl_*) proving non-vacuity.
15-/
16
17namespace FmmOrbitInvariance
18
19/-- Minimal commutative ring with 1 (zero Mathlib, zero custom axioms). -/
20class CRing (R : Type) where
21 zero : R
22 one : R
23 add : R → R → R
24 neg : R → R
25 mul : R → R → R
26 add_assoc : ∀ a b c, add (add a b) c = add a (add b c)
27 add_comm : ∀ a b, add a b = add b a
28 zero_add : ∀ a, add zero a = a
29 add_left_neg : ∀ a, add (neg a) a = zero
30 mul_assoc : ∀ a b c, mul (mul a b) c = mul (mul a b) c → True
31 mul_assoc' : ∀ a b c, mul (mul a b) c = mul a (mul b c)
32 mul_comm : ∀ a b, mul a b = mul b a
33 one_mul : ∀ a, mul one a = a
34 left_distrib : ∀ a b c, mul a (add b c) = add (mul a b) (mul a c)
35
36namespace CRing
37
38variable {R : Type} [CRing R]
39
40theorem add_zero (a : R) : add a zero = a := by
41 rw [add_comm, zero_add]
42
43theorem add_right_neg (a : R) : add a (neg a) = zero := by
44 rw [add_comm, add_left_neg]
45
46theorem mul_one (a : R) : mul a one = a := by
47 rw [mul_comm, one_mul]
48
49theorem right_distrib (a b c : R) : mul (add a b) c = add (mul a c) (mul b c) := by
50 rw [mul_comm, left_distrib, mul_comm c a, mul_comm c b]
51
52theorem mul_zero (a : R) : mul a zero = zero := by
53 have h : add (mul a zero) (mul a zero) = mul a zero := by
54 rw [← left_distrib, zero_add]
55 have h2 := congrArg (add (neg (mul a zero))) h
56 simp only [← add_assoc, add_left_neg, zero_add] at h2
57 exact h2
58
59theorem zero_mul (a : R) : mul zero a = zero := by
60 rw [mul_comm, mul_zero]
61
62theorem mul_neg (a b : R) : mul a (neg b) = neg (mul a b) := by
63 have h : add (mul a b) (mul a (neg b)) = zero := by
64 rw [← left_distrib, add_right_neg, mul_zero]
65 have h2 := congrArg (add (neg (mul a b))) h
66 simp only [← add_assoc, add_left_neg, zero_add, add_zero] at h2
67 exact h2
68
69/-- Finite sum over `Fin n`. -/
70def sumFin {n : Nat} (f : Fin n → R) : R :=
71 match n with
72 | 0 => zero
73 | k + 1 => add (f ⟨0, Nat.zero_lt_succ k⟩) (sumFin (fun i : Fin k => f i.succ))
74
75theorem sumFin_zero {n : Nat} : sumFin (R := R) (n := n) (fun _ => zero) = zero := by
76 induction n with
77 | zero => rfl
78 | succ k ih =>
79 simp only [sumFin, ih, zero_add]
80
81theorem sumFin_congr {n : Nat} {f g : Fin n → R} (h : ∀ i, f i = g i) :
82 sumFin f = sumFin g := by
83 induction n with
84 | zero => rfl
85 | succ k ih =>
86 simp only [sumFin]
87 rw [h ⟨0, Nat.zero_lt_succ k⟩, ih (fun i => h i.succ)]
88
89theorem add_four_swap (a b c d : R) :
90 add (add a b) (add c d) = add (add a c) (add b d) := by
91 rw [add_assoc a b (add c d), ← add_assoc b c d, add_comm b c,
92 add_assoc c b d, ← add_assoc a c (add b d)]
93
94theorem sumFin_add {n : Nat} (f g : Fin n → R) :
95 sumFin (fun i => add (f i) (g i)) = add (sumFin f) (sumFin g) := by
96 induction n with
97 | zero => simp only [sumFin, zero_add]
98 | succ k ih =>
99 simp only [sumFin]
100 rw [ih (fun i => f i.succ) (fun i => g i.succ)]
101 exact add_four_swap _ _ _ _
102
103theorem sumFin_mul_left {n : Nat} (c : R) (f : Fin n → R) :
104 mul c (sumFin f) = sumFin (fun i => mul c (f i)) := by
105 induction n with
106 | zero => simp only [sumFin, mul_zero]
107 | succ k ih =>
108 simp only [sumFin, left_distrib, ih]
109
110theorem sumFin_mul_right {n : Nat} (f : Fin n → R) (c : R) :
111 mul (sumFin f) c = sumFin (fun i => mul (f i) c) := by
112 induction n with
113 | zero => simp only [sumFin, zero_mul]
114 | succ k ih =>
115 simp only [sumFin, right_distrib, ih]
116
117theorem sumFin_swap {m n : Nat} (f : Fin m → Fin n → R) :
118 sumFin (fun i => sumFin (fun j => f i j)) =
119 sumFin (fun j => sumFin (fun i => f i j)) := by
120 induction m with
121 | zero =>
122 simp only [sumFin]
123 symm
124 exact sumFin_zero
125 | succ k ih =>
126 simp only [sumFin]
127 rw [ih (fun i j => f i.succ j), ← sumFin_add]
128
129theorem sumFin_single {n : Nat} (j0 : Fin n) (f : Fin n → R)
130 (h : ∀ j, j ≠ j0 → f j = zero) :
131 sumFin f = f j0 := by
132 induction n with
133 | zero => exact Fin.elim0 j0
134 | succ k ih =>
135 simp only [sumFin]
136 cases j0 using Fin.cases with
137 | zero =>
138 have hrest : sumFin (fun i : Fin k => f i.succ) = zero := by
139 rw [sumFin_congr (fun i => h i.succ (Fin.succ_ne_zero i))]
140 exact sumFin_zero
141 rw [hrest, add_zero]
142 rfl
143 | succ j1 =>
144 have h0 : f ⟨0, Nat.zero_lt_succ k⟩ = zero :=
145 h ⟨0, Nat.zero_lt_succ k⟩ (Ne.symm (Fin.succ_ne_zero j1))
146 rw [h0, zero_add]
147 exact ih j1 (fun i => f i.succ) (fun i hi => h i.succ (fun heq => hi (Fin.succ_inj.mp heq)))
148
149/-- Matrix multiplication over CRing R. -/
150def matMul {m n p : Nat} (A : Fin m → Fin n → R) (B : Fin n → Fin p → R) :
151 Fin m → Fin p → R :=
152 fun i k => sumFin (fun j => mul (A i j) (B j k))
153
154/-- Identity matrix over CRing R. -/
155def matId (n : Nat) : Fin n → Fin n → R :=
156 fun i j => if i = j then one else zero
157
158theorem matMul_assoc {m n p q : Nat}
159 (A : Fin m → Fin n → R) (B : Fin n → Fin p → R) (C : Fin p → Fin q → R) :
160 matMul (matMul A B) C = matMul A (matMul B C) := by
161 funext i l
162 simp only [matMul]
163 have h1 : sumFin (fun k => mul (sumFin (fun j => mul (A i j) (B j k))) (C k l)) =
164 sumFin (fun k => sumFin (fun j => mul (mul (A i j) (B j k)) (C k l))) :=
165 sumFin_congr (fun k => sumFin_mul_right _ (C k l))
166 have h2 : sumFin (fun j => mul (A i j) (sumFin (fun k => mul (B j k) (C k l)))) =
167 sumFin (fun j => sumFin (fun k => mul (A i j) (mul (B j k) (C k l)))) :=
168 sumFin_congr (fun j => sumFin_mul_left (A i j) _)
169 rw [h1, h2, sumFin_swap]
170 exact sumFin_congr (fun j => sumFin_congr (fun k => mul_assoc' (A i j) (B j k) (C k l)))
171
172theorem matMul_id_left {m n : Nat} (A : Fin m → Fin n → R) :
173 matMul (matId m) A = A := by
174 funext i j
175 simp only [matMul, matId]
176 rw [sumFin_single i (fun k => mul (if i = k then one else zero) (A k j))]
177 · simp only [ite_true, one_mul]
178 · intro k hk
179 have hne : ¬ (i = k) := Ne.symm hk
180 simp only [hne, ite_false, zero_mul]
181
182theorem matMul_id_right {m n : Nat} (A : Fin m → Fin n → R) :
183 matMul A (matId n) = A := by
184 funext i j
185 simp only [matMul, matId]
186 rw [sumFin_single j (fun k => mul (A i k) (if k = j then one else zero))]
187 · simp only [ite_true, mul_one]
188 · intro k hk
189 simp only [hk, ite_false, mul_zero]
190
191/-- UNIVERSAL UNIMODULAR SANDWICH ORBIT INVARIANCE THEOREM:
192 For ANY commutative ring R, ANY dimensions (m, n, p), and ANY invertible
193 (P, Pinv), (Q, Qinv), (S, Sinv) with Pinv * P = I_m, Qinv * Q = I_n, Sinv * S = I_p:
194 Pinv * ((P * A * Qinv) * (Q * B * Sinv)) * S = A * B. -/
195theorem unimodular_sandwich_matmul {m n p : Nat}
196 (P Pinv : Fin m → Fin m → R) (hP : matMul Pinv P = matId m)
197 (Q Qinv : Fin n → Fin n → R) (hQ : matMul Qinv Q = matId n)
198 (S Sinv : Fin p → Fin p → R) (hS : matMul Sinv S = matId p)
199 (A : Fin m → Fin n → R) (B : Fin n → Fin p → R) :
200 matMul (matMul Pinv (matMul (matMul (matMul P A) Qinv) (matMul (matMul Q B) Sinv))) S
201 = matMul A B := by
202 calc matMul (matMul Pinv (matMul (matMul (matMul P A) Qinv) (matMul (matMul Q B) Sinv))) S
203 = matMul Pinv (matMul (matMul (matMul (matMul P A) Qinv) (matMul (matMul Q B) Sinv)) S) := by
204 rw [matMul_assoc]
205 _ = matMul Pinv (matMul (matMul (matMul P A) Qinv) (matMul (matMul (matMul Q B) Sinv) S)) := by
206 rw [matMul_assoc]
207 _ = matMul Pinv (matMul (matMul (matMul P A) Qinv) (matMul (matMul Q B) (matMul Sinv S))) := by
208 rw [matMul_assoc (matMul Q B) Sinv S]
209 _ = matMul Pinv (matMul (matMul (matMul P A) Qinv) (matMul Q B)) := by
210 rw [hS, matMul_id_right]
211 _ = matMul Pinv (matMul (matMul P A) (matMul Qinv (matMul Q B))) := by
212 rw [matMul_assoc (matMul P A) Qinv (matMul Q B)]
213 _ = matMul Pinv (matMul (matMul P A) (matMul (matMul Qinv Q) B)) := by
214 rw [← matMul_assoc Qinv Q B]
215 _ = matMul Pinv (matMul (matMul P A) B) := by
216 rw [hQ, matMul_id_left]
217 _ = matMul (matMul Pinv (matMul P A)) B := by
218 rw [← matMul_assoc Pinv (matMul P A) B]
219 _ = matMul (matMul (matMul Pinv P) A) B := by
220 rw [← matMul_assoc Pinv P A]
221 _ = matMul A B := by
222 rw [hP, matMul_id_left]
223
224/-- Elementary shear matrix E_{r, c}(k) = I + k * e_{r, c} (for r != c). -/
225def shearMat (n : Nat) (r c : Fin n) (k : R) : Fin n → Fin n → R :=
226 fun i j =>
227 add (if i = j then one else zero)
228 (if i = r ∧ j = c then k else zero)
229
230theorem mul_ite_zero {P Q : Prop} [Decidable P] [Decidable Q] (a b : R) :
231 mul (if P then a else zero) (if Q then b else zero) =
232 if P ∧ Q then mul a b else zero := by
233 by_cases hp : P <;> by_cases hq : Q <;> simp only [hp, hq, and_self, and_false, false_and, ite_true, ite_false, zero_mul, mul_zero]
234
235/-- UNIVERSAL ELEMENTARY SHEAR INVERTIBILITY THEOREM:
236 For ANY commutative ring R, ANY n, ANY r != c, and ANY scalar k ∈ R:
237 E_{r,c}(k) * E_{r,c}(-k) = I_n. -/
238theorem shearMat_mul_inv {n : Nat} (r c : Fin n) (hrc : r ≠ c) (k : R) :
239 matMul (shearMat n r c k) (shearMat n r c (neg k)) = matId n := by
240 funext i j
241 simp only [matMul, shearMat, matId]
242 have hterm : ∀ t : Fin n,
243 mul (add (if i = t then one else zero) (if i = r ∧ t = c then k else zero))
244 (add (if t = j then one else zero) (if t = r ∧ j = c then neg k else zero))
245 = add (add (if i = t ∧ t = j then one else zero)
246 (if i = t ∧ t = r ∧ j = c then neg k else zero))
247 (if i = r ∧ t = c ∧ t = j then k else zero) := by
248 intro t
249 rw [right_distrib, left_distrib, left_distrib]
250 rw [mul_ite_zero (one : R) one, one_mul]
251 rw [mul_ite_zero (one : R) (neg k), one_mul]
252 rw [mul_ite_zero k (one : R), mul_one]
253 rw [mul_ite_zero k (neg k)]
254 have h21 : ((i = r ∧ t = c) ∧ t = j) ↔ (i = r ∧ t = c ∧ t = j) := and_assoc
255 have h22 : ¬ ((i = r ∧ t = c) ∧ (t = r ∧ j = c)) := fun h => hrc (h.2.1.symm.trans h.1.2)
256 simp only [h21, h22, ite_false, add_zero]
257 rw [sumFin_congr hterm, sumFin_add, sumFin_add]
258 have s1 : sumFin (R := R) (fun t : Fin n => if i = t ∧ t = j then one else zero) =
259 if i = j then one else zero := by
260 rw [sumFin_single (R := R) i (fun t => if i = t ∧ t = j then one else zero)]
261 · by_cases hij : i = j <;> simp [hij]
262 · intro t ht; simp [Ne.symm ht]
263 have s2 : sumFin (R := R) (fun t : Fin n => if i = t ∧ t = r ∧ j = c then neg k else zero) =
264 if i = r ∧ j = c then neg k else zero := by
265 rw [sumFin_single (R := R) i (fun t => if i = t ∧ t = r ∧ j = c then neg k else zero)]
266 · by_cases h : i = r ∧ j = c <;> simp [h]
267 · intro t ht; simp [Ne.symm ht]
268 have s3 : sumFin (R := R) (fun t : Fin n => if i = r ∧ t = c ∧ t = j then k else zero) =
269 if i = r ∧ j = c then k else zero := by
270 rw [sumFin_single (R := R) c (fun t => if i = r ∧ t = c ∧ t = j then k else zero)]
271 · by_cases h : i = r ∧ j = c
272 · simp [h.1, h.2.symm]
273 · have h2 : ¬ (i = r ∧ c = j) := fun hc => h ⟨hc.1, hc.2.symm⟩
274 simp [h, h2]
275 · intro t ht; simp [ht]
276 rw [s1, s2, s3, add_assoc]
277 by_cases h : i = r ∧ j = c
278 · simp only [h, and_self, ite_true, add_left_neg, add_zero]
279 · simp only [h, ite_false, add_zero]
280
281end CRing
282
283/-- Canonical CRing instance on Int. -/
284instance : CRing Int where
285 zero := 0
286 one := 1
287 add := Int.add
288 neg := Int.neg
289 mul := Int.mul
290 add_assoc := Int.add_assoc
291 add_comm := Int.add_comm
292 zero_add := Int.zero_add
293 add_left_neg := Int.add_left_neg
294 mul_assoc := fun _ _ _ _ => trivial
295 mul_assoc' := Int.mul_assoc
296 mul_comm := Int.mul_comm
297 one_mul := Int.one_mul
298 left_distrib := Int.mul_add
299
300/-- Recursive Leading-Constant Monotonicity:
301 At fixed rank R > d (where d = m*n), reducing exact additions cr' < cr strictly
302 decreases the rational leading constant C = 1 + cr / (R - d) = (cr + R - d) / (R - d). -/
303theorem leading_constant_strict_improvement (R d cr cr' : Nat)
304 (hcr : cr' < cr) :
305 cr' + (R - d) < cr + (R - d) := by
306 omega
307
308/-! ### Adversarial Negative Controls (`neg_ctrl_*`) -/
309
310/-- Broken-model negative control 1: Diagonal shear `E_{0,0}(1)` is NOT inverted by `E_{0,0}(-1)`
311 (product is `0 != 1`, violating `r != c`). -/
312theorem neg_ctrl_diagonal_shear_not_invertible :
313 let z : Fin 2 := ⟨0, by omega⟩
314 CRing.matMul (R := Int) (CRing.shearMat 2 z z 1) (CRing.shearMat 2 z z (-1)) z z ≠ 1 := by
315 decide
316
317/-- Broken-model negative control 2: Same-sign shear `E_{0,1}(1) * E_{0,1}(1) != I_2`. -/
318theorem neg_ctrl_same_sign_shear_fails :
319 let z0 : Fin 2 := ⟨0, by omega⟩
320 let z1 : Fin 2 := ⟨1, by omega⟩
321 CRing.matMul (R := Int) (CRing.shearMat 2 z0 z1 1) (CRing.shearMat 2 z0 z1 1) z0 z1 ≠ 0 := by
322 decide
323
324/-- Broken-model negative control 3: Breaking `Qinv * Q = I` breaks unimodular sandwich invariance. -/
325theorem neg_ctrl_broken_Q_breaks_sandwich :
326 let I1 : Fin 1 → Fin 1 → Int := CRing.matId 1
327 let Z1 : Fin 1 → Fin 1 → Int := fun _ _ => 0
328 let z : Fin 1 := ⟨0, Nat.zero_lt_one⟩
329 CRing.matMul (CRing.matMul I1 (CRing.matMul (CRing.matMul (CRing.matMul I1 I1) Z1)
330 (CRing.matMul (CRing.matMul I1 I1) I1))) I1 z z ≠ CRing.matMul I1 I1 z z := by
331 decide
332
333/-- Broken-model negative control 4: Non-improving addition count `cr' = 256` fails `< 256`. -/
334theorem neg_ctrl_no_addition_gain : ¬ (256 < 256) := by
335 omega
336
337#print axioms CRing.matMul_assoc
338#print axioms CRing.unimodular_sandwich_matmul
339#print axioms CRing.shearMat_mul_inv
340#print axioms leading_constant_strict_improvement
341#print axioms neg_ctrl_diagonal_shear_not_invertible
342#print axioms neg_ctrl_same_sign_shear_fails
343#print axioms neg_ctrl_broken_Q_breaks_sandwich
344#print axioms neg_ctrl_no_addition_gain
345
346end FmmOrbitInvariance