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 / Matmul4x4LocalObstruction.lean

276 lines · 11761 bytes Raw Blame History
1-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2-- proofs/Matmul4x4LocalObstruction.lean
3-- Formal Lean 4 verification for the 4x4 Matrix Multiplication Local Obstruction Study:
4-- 1. Exact equivalence between 2-adic residual ((T - S0)/2) mod 2 and pairwise-overlap
5-- parity (S0 * (S0 - 1) / 2) mod 2 whenever T in {0,1} and S0 = T (mod 2).
6-- 2. Soundness of the rank-1 dual obstruction criterion (if >=2 of P_t, Q_t, S_t are even
7-- for every term t, then sum_t P_t*Q_t*S_t = 0 mod 4, contradicting Sigma_T = 2 mod 4).
8-- 3. Soundness of bounded-support local sub-box dual certificates (zero-extension preserves
9-- global J-annihilation across all 48R columns and refutes any mod-4 lift).
10-- 4. Two formal broken-model negative controls (neg_ctrl_*).
11-- Zero sorry, zero native_decide, standard core axioms only.
12
13namespace Matmul4x4LocalObstruction
14
15-- Helper: finite sum over Fin n (zero Mathlib dependency)
16def finSum {n : Nat} (f : Fin n → Int) : Int :=
17 match n with
18 | 0 => 0
19 | k + 1 => finSum (fun i : Fin k => f i.castSucc) + f ⟨k, Nat.lt_succ_self k⟩
20
21theorem finSum_zero_mod4 {n : Nat} (f : Fin n → Int) (h : ∀ i, f i % 4 = 0) :
22 finSum f % 4 = 0 := by
23 induction n with
24 | zero => rfl
25 | succ k ih =>
26 simp only [finSum]
27 have h1 := ih (fun i => f i.castSucc) (fun i => h i.castSucc)
28 have h2 := h ⟨k, Nat.lt_succ_self k⟩
29 omega
30
31theorem finSum_zero_mod2 {n : Nat} (f : Fin n → Int) (h : ∀ i, f i % 2 = 0) :
32 finSum f % 2 = 0 := by
33 induction n with
34 | zero => rfl
35 | succ k ih =>
36 simp only [finSum]
37 have h1 := ih (fun i => f i.castSucc) (fun i => h i.castSucc)
38 have h2 := h ⟨k, Nat.lt_succ_self k⟩
39 omega
40
41theorem finSum_mod2_eq {n : Nat} (f g : Fin n → Int) (h : ∀ i, f i % 2 = g i % 2) :
42 finSum f % 2 = finSum g % 2 := by
43 induction n with
44 | zero => rfl
45 | succ k ih =>
46 simp only [finSum]
47 have h1 := ih (fun i => f i.castSucc) (fun i => g i.castSucc) (fun i => h i.castSucc)
48 have h2 := h ⟨k, Nat.lt_succ_self k⟩
49 omega
50
51theorem finSum_add {n : Nat} (f g : Fin n → Int) :
52 finSum (fun i => f i + g i) = finSum f + finSum g := by
53 induction n with
54 | zero => rfl
55 | succ k ih =>
56 simp only [finSum]
57 rw [ih (fun i => f i.castSucc) (fun i => g i.castSucc)]
58 omega
59
60theorem finSum_mul_left {n : Nat} (c : Int) (f : Fin n → Int) :
61 finSum (fun i => c * f i) = c * finSum f := by
62 induction n with
63 | zero => simp [finSum]
64 | succ k ih =>
65 simp only [finSum]
66 rw [ih (fun i => f i.castSucc), Int.mul_add]
67
68theorem finSum_mul_right {n : Nat} (f : Fin n → Int) (c : Int) :
69 finSum (fun i => f i * c) = finSum f * c := by
70 induction n with
71 | zero => simp [finSum]
72 | succ k ih =>
73 simp only [finSum]
74 rw [ih (fun i => f i.castSucc), Int.add_mul]
75
76theorem finSum_swap {m n : Nat} (f : Fin m → Fin n → Int) :
77 finSum (fun i => finSum (fun j => f i j)) =
78 finSum (fun j => finSum (fun i => f i j)) := by
79 induction m with
80 | zero =>
81 simp only [finSum]
82 induction n with
83 | zero => rfl
84 | succ k ihk =>
85 simp only [finSum]
86 rw [← ihk (fun j => f · j.castSucc)]
87 omega
88 | succ k ih =>
89 simp only [finSum]
90 rw [ih (fun i j => f i.castSucc j)]
91 rw [← finSum_add]
92
93-- 1. Exact equivalence between 2-adic residual ((T - S0)/2) mod 2 and floor(S0/2) mod 2
94theorem r2_eq_half_floor_mod2 (S0 T : Int) (hT : T = 0 ∨ T = 1)
95 (hmod : S0 % 2 = T % 2) :
96 ((T - S0) / 2) % 2 = (S0 / 2) % 2 := by
97 rcases hT with rfl | rfl <;> omega
98
99-- 2. Exact equivalence between floor(S0/2) mod 2 and pairwise overlap count C(S0,2) mod 2
100theorem half_floor_eq_binom2_mod2 (S0 : Int) (hS0 : S0 ≥ 0) :
101 (S0 / 2) % 2 = ((S0 * (S0 - 1)) / 2) % 2 := by
102 have h4 : S0 % 4 = 0 ∨ S0 % 4 = 1 ∨ S0 % 4 = 2 ∨ S0 % 4 = 3 := by omega
103 rcases h4 with h0 | h1 | h2 | h3
104 · have hq : ∃ q : Int, S0 = 4 * q := ⟨S0 / 4, by omega⟩
105 rcases hq with ⟨q, rfl⟩
106 have hmul : 4 * q * (4 * q - 1) = 2 * (2 * (q * (4 * q - 1))) := by
107 have a : 4 * q * (4 * q - 1) = 4 * (q * (4 * q - 1)) := Int.mul_assoc 4 q (4 * q - 1)
108 rw [a]; omega
109 omega
110 · have hq : ∃ q : Int, S0 = 4 * q + 1 := ⟨S0 / 4, by omega⟩
111 rcases hq with ⟨q, rfl⟩
112 have hmul : (4 * q + 1) * (4 * q + 1 - 1) = 2 * (2 * ((4 * q + 1) * q)) := by
113 have a : 4 * q + 1 - 1 = 4 * q := by omega
114 rw [a, ← Int.mul_assoc, Int.mul_comm (4 * q + 1) 4, Int.mul_assoc]
115 omega
116 omega
117 · have hq : ∃ q : Int, S0 = 4 * q + 2 := ⟨S0 / 4, by omega⟩
118 rcases hq with ⟨q, rfl⟩
119 have hmul : (4 * q + 2) * (4 * q + 2 - 1) = 2 * ((2 * q + 1) * (4 * q + 1)) := by
120 have b : 4 * q + 2 - 1 = 4 * q + 1 := by omega
121 have a : 4 * q + 2 = 2 * (2 * q + 1) := by omega
122 rw [b, a, Int.mul_assoc]
123 have hdiv : ((4 * q + 2) * (4 * q + 2 - 1)) / 2 = (2 * q + 1) * (4 * q + 1) := by
124 rw [hmul]; omega
125 have hodd : ((2 * q + 1) * (4 * q + 1)) % 2 = 1 := by
126 have ha : (2 * q + 1) % 2 = 1 := by omega
127 have hb : (4 * q + 1) % 2 = 1 := by omega
128 rw [Int.mul_emod, ha, hb]
129 decide
130 rw [hdiv, hodd]; omega
131 · have hq : ∃ q : Int, S0 = 4 * q + 3 := ⟨S0 / 4, by omega⟩
132 rcases hq with ⟨q, rfl⟩
133 have hmul : (4 * q + 3) * (4 * q + 3 - 1) = 2 * ((4 * q + 3) * (2 * q + 1)) := by
134 have a : 4 * q + 3 - 1 = 2 * (2 * q + 1) := by omega
135 rw [a, ← Int.mul_assoc, Int.mul_comm (4 * q + 3) 2, Int.mul_assoc]
136 have hdiv : ((4 * q + 3) * (4 * q + 3 - 1)) / 2 = (4 * q + 3) * (2 * q + 1) := by
137 rw [hmul]; omega
138 have hodd : ((4 * q + 3) * (2 * q + 1)) % 2 = 1 := by
139 have ha : (4 * q + 3) % 2 = 1 := by omega
140 have hb : (2 * q + 1) % 2 = 1 := by omega
141 rw [Int.mul_emod, ha, hb]
142 decide
143 rw [hdiv, hodd]; omega
144
145-- 3. Rank-1 dual witness termwise divisibility by 4
146theorem rank1_two_even_factors_mod4 (P Q S : Int)
147 (h : (P % 2 = 0 ∧ Q % 2 = 0) ∨ (P % 2 = 0 ∧ S % 2 = 0) ∨ (Q % 2 = 0 ∧ S % 2 = 0)) :
148 (P * Q * S) % 4 = 0 := by
149 rcases h with ⟨hP, hQ⟩ | ⟨hP, hS⟩ | ⟨hQ, hS⟩
150 · have ⟨p, hp⟩ : ∃ p, P = 2 * p := ⟨P / 2, by omega⟩
151 have ⟨q, hq⟩ : ∃ q, Q = 2 * q := ⟨Q / 2, by omega⟩
152 rw [hp, hq]
153 have ha : 2 * p * (2 * q) * S = 4 * (p * q * S) := by
154 have h4 : (2 * 2 : Int) = 4 := rfl
155 rw [Int.mul_assoc 2 p (2 * q), ← Int.mul_assoc p 2 q, Int.mul_comm p 2,
156 Int.mul_assoc 2 p q, ← Int.mul_assoc 2 2 (p * q), h4, Int.mul_assoc 4 (p * q) S]
157 rw [ha]; omega
158 · have ⟨p, hp⟩ : ∃ p, P = 2 * p := ⟨P / 2, by omega⟩
159 have ⟨s, hs⟩ : ∃ s, S = 2 * s := ⟨S / 2, by omega⟩
160 rw [hp, hs]
161 have ha : 2 * p * Q * (2 * s) = 4 * (p * Q * s) := by
162 rw [Int.mul_assoc 2 p Q, Int.mul_assoc 2 (p * Q) (2 * s),
163 ← Int.mul_assoc (p * Q) 2 s, Int.mul_comm (p * Q) 2,
164 Int.mul_assoc 2 (p * Q) s, ← Int.mul_assoc 2 2 (p * Q * s)]
165 rfl
166 rw [ha]; omega
167 · have ⟨q, hq⟩ : ∃ q, Q = 2 * q := ⟨Q / 2, by omega⟩
168 have ⟨s, hs⟩ : ∃ s, S = 2 * s := ⟨S / 2, by omega⟩
169 rw [hq, hs]
170 have ha : P * (2 * q) * (2 * s) = 4 * (P * q * s) := by
171 rw [← Int.mul_assoc P 2 q, Int.mul_comm P 2, Int.mul_assoc 2 P q,
172 Int.mul_assoc 2 (P * q) (2 * s), ← Int.mul_assoc (P * q) 2 s,
173 Int.mul_comm (P * q) 2, Int.mul_assoc 2 (P * q) s, ← Int.mul_assoc 2 2 (P * q * s)]
174 rfl
175 rw [ha]; omega
176
177-- 4. Rank-1 dual obstruction theorem: if every term has >=2 even contractions and target contraction = 2 mod 4,
178-- then NO mod-4 lift can match the contracted tensor sum modulo 4.
179theorem rank1_dual_obstruction_mod4 {R : Nat}
180 (P Q S : Fin R → Int) (SigmaT : Int)
181 (h_two_even : ∀ t : Fin R,
182 (P t % 2 = 0 ∧ Q t % 2 = 0) ∨ (P t % 2 = 0 ∧ S t % 2 = 0) ∨ (Q t % 2 = 0 ∧ S t % 2 = 0))
183 (h_target : SigmaT % 4 = 2) :
184 finSum (fun t => P t * Q t * S t) % 4 ≠ SigmaT % 4 := by
185 have h0 : finSum (fun t => P t * Q t * S t) % 4 = 0 := by
186 apply finSum_zero_mod4
187 intro t
188 exact rank1_two_even_factors_mod4 (P t) (Q t) (S t) (h_two_even t)
189 omega
190
191-- 5. Local sub-box dual certificate soundness:
192-- Any dual vector lam supported on a subset S (lam i = 0 for i not in S) that annihilates
193-- every column of J restricted to S and satisfies lam^T r2 = 1 (mod 2) refutes any global solution x.
194theorem local_subbox_obstruction_sound {m n : Nat}
195 (S : Fin m → Bool) (J : Fin m → Fin n → Int) (r2 lam : Fin m → Int)
196 (h_supp : ∀ i : Fin m, S i = false → lam i = 0)
197 (h_loc_ann : ∀ j : Fin n, finSum (fun i => (if S i then lam i * J i j else 0)) % 2 = 0)
198 (h_loc_one : finSum (fun i => (if S i then lam i * r2 i else 0)) % 2 = 1) :
199 ¬ ∃ x : Fin n → Int, ∀ i : Fin m, finSum (fun j => J i j * x j) % 2 = r2 i % 2 := by
200 have h_eq_ann : ∀ j : Fin n,
201 (fun i => lam i * J i j) = (fun i => if S i then lam i * J i j else 0) := by
202 intro j
203 funext i
204 cases hSi : S i with
205 | true => simp
206 | false =>
207 have h0 := h_supp i hSi
208 simp [h0]
209 have h_eq_r2 :
210 (fun i => lam i * r2 i) = (fun i => if S i then lam i * r2 i else 0) := by
211 funext i
212 cases hSi : S i with
213 | true => simp
214 | false =>
215 have h0 := h_supp i hSi
216 simp [h0]
217 intro ⟨x, hx⟩
218 have hlhs : finSum (fun i => lam i * finSum (fun j => J i j * x j)) % 2 =
219 finSum (fun i => lam i * r2 i) % 2 := by
220 apply finSum_mod2_eq
221 intro i
222 rw [Int.mul_emod, hx i, ← Int.mul_emod]
223 have hswap : finSum (fun i => lam i * finSum (fun j => J i j * x j)) =
224 finSum (fun j => finSum (fun i => lam i * J i j) * x j) := by
225 have h1 : (fun i => lam i * finSum (fun j => J i j * x j)) =
226 (fun i => finSum (fun j => (lam i * J i j) * x j)) := by
227 funext i
228 rw [← finSum_mul_left]
229 congr 1
230 funext j
231 exact (Int.mul_assoc (lam i) (J i j) (x j)).symm
232 rw [h1, finSum_swap]
233 congr 1
234 funext j
235 exact finSum_mul_right (fun i => lam i * J i j) (x j)
236 have hzero : finSum (fun j => finSum (fun i => lam i * J i j) * x j) % 2 = 0 := by
237 apply finSum_zero_mod2
238 intro j
239 rw [Int.mul_emod, h_eq_ann j, h_loc_ann j]
240 simp
241 rw [hswap, hzero, h_eq_r2, h_loc_one] at hlhs
242 omega
243
244-- 6. Negative Control 1: Only ONE even factor does NOT force P*Q*S = 0 (mod 4)
245theorem neg_ctrl_one_even_factor_insufficient :
246 ∃ P Q S : Int, P % 2 = 0 ∧ (P * Q * S) % 4 = 2 := by
247 exact ⟨2, 1, 1, by decide, by decide⟩
248
249-- 7. Negative Control 2: A local witness with even residual parity (lam^T r2 = 0) does NOT obstruct lifting
250theorem neg_ctrl_local_even_residual_admits_lift :
251 ∃ (S : Fin 2 → Bool) (J : Fin 2 → Fin 1 → Int) (r2 lam : Fin 2 → Int) (x : Fin 1 → Int),
252 (∀ i, S i = false → lam i = 0) ∧
253 (∀ j, finSum (fun i => if S i then lam i * J i j else 0) % 2 = 0) ∧
254 finSum (fun i => if S i then lam i * r2 i else 0) % 2 = 0 ∧
255 (∀ i, finSum (fun j => J i j * x j) % 2 = r2 i % 2) := by
256 refine ⟨fun i => i.val == 0, fun _ _ => 0, fun _ => 0, fun i => if i.val == 0 then 1 else 0,
257 fun _ => 0, ?_, ?_, ?_, ?_⟩
258 · intro i hi
259 rcases i with ⟨v, hv⟩
260 have : v = 0 ∨ v = 1 := by omega
261 rcases this with rfl | rfl <;> simp at hi ⊢
262 · intro j
263 simp [finSum]
264 · decide
265 · intro i
266 simp [finSum]
267
268#print axioms r2_eq_half_floor_mod2
269#print axioms half_floor_eq_binom2_mod2
270#print axioms rank1_two_even_factors_mod4
271#print axioms rank1_dual_obstruction_mod4
272#print axioms local_subbox_obstruction_sound
273#print axioms neg_ctrl_one_even_factor_insufficient
274#print axioms neg_ctrl_local_even_residual_admits_lift
275
276end Matmul4x4LocalObstruction