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

208 lines · 8773 bytes Raw Blame History
1/-
2 SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3 /Users/drakestapleton/workspace/omega-principia/experiments/math_8h_comb/lean/CoveringArrayQuinaryVolumeW15.lean
4
5 Standalone Zero-Mathlib Lean 4.36.0 Formal Proof of Universal Combinatorial
6 Volume Lower Bounds for Covering Arrays (Wave 15):
7 1. Pure-Core Surjection-Cardinality Pigeonhole Lemma (`range_subset_len_le`):
8 if every `m < M` belongs to a list `L : List Nat`, then `M <= L.length`.
9 2. Universal Strength-3 Volume Lower Bound (`ca3_volume_lower_bound`):
10 for ALL `N, k, v : Nat` with `k >= 3`, any `CA(N; 3, k, v)` satisfies `v * v * v <= N`
11 (proving `CAN(3, k, v) >= v^3` universally, e.g. `CAN(3, 11, 5) >= 125`, `CAN(3, 17, 8) >= 512`).
12 3. Universal Strength-2 Volume Lower Bound (`ca2_volume_lower_bound`):
13 for ALL `N, k, v : Nat` with `k >= 2`, any `CA(N; 2, k, v)` satisfies `v * v <= N`.
14 4. Four literal broken-model negative controls (`neg_ctrl_*`), including universal
15 impossibility of `CA(124; 3, 11, 5)` for EVERY matrix `rows`!
16
17 0 sorry, 0 admit, 0 native_decide, 0 custom axioms, 0 unsafe, 0 Mathlib.
18-/
19
20namespace CoveringArrayQuinaryVolumeW15
21
22def IsCA3 (N k v : Nat) (rows : List (List Nat)) : Prop :=
23 rows.length = N ∧
24 (∀ r, r < N → (rows.getD r []).length = k ∧
25 ∀ c, c < k → (rows.getD r []).getD c v < v) ∧
26 (∀ c0 c1 c2,
27 c0 < k → c1 < k → c2 < k →
28 c0 ≠ c1 → c0 ≠ c2 → c1 ≠ c2 →
29 ∀ p0 p1 p2, p0 < v → p1 < v → p2 < v →
30 ∃ r, r < N ∧
31 (rows.getD r []).getD c0 v = p0 ∧
32 (rows.getD r []).getD c1 v = p1 ∧
33 (rows.getD r []).getD c2 v = p2)
34
35def IsCA2 (N k v : Nat) (rows : List (List Nat)) : Prop :=
36 rows.length = N ∧
37 (∀ r, r < N → (rows.getD r []).length = k ∧
38 ∀ c, c < k → (rows.getD r []).getD c v < v) ∧
39 (∀ c0 c1,
40 c0 < k → c1 < k → c0 ≠ c1 →
41 ∀ p0 p1, p0 < v → p1 < v →
42 ∃ r, r < N ∧
43 (rows.getD r []).getD c0 v = p0 ∧
44 (rows.getD r []).getD c1 v = p1)
45
46/-- Remove the first occurrence of `x` from `L`. -/
47def eraseOne (x : Nat) : List Nat → List Nat
48 | [] => []
49 | a :: rest => if a == x then rest else a :: eraseOne x rest
50
51theorem eraseOne_len_of_mem {x : Nat} : ∀ (L : List Nat), x ∈ L → (eraseOne x L).length + 1 = L.length
52 | [], h => by cases h
53 | a :: rest, h => by
54 unfold eraseOne
55 by_cases hax : a = x
56 · simp [hax]
57 · simp only [beq_iff_eq, hax, ↓reduceIte, List.length_cons]
58 cases h with
59 | head => exact False.elim (hax rfl)
60 | tail _ hm => have ih := eraseOne_len_of_mem rest hm; omega
61
62theorem mem_eraseOne_of_ne {x y : Nat} (hne : y ≠ x) :
63 ∀ (L : List Nat), y ∈ L → y ∈ eraseOne x L
64 | [], h => by cases h
65 | a :: rest, h => by
66 unfold eraseOne
67 by_cases hax : a = x
68 · simp only [beq_iff_eq, hax, ↓reduceIte]
69 cases h with
70 | head => exact False.elim (hne hax)
71 | tail _ hm => exact hm
72 · simp only [beq_iff_eq, hax, ↓reduceIte]
73 cases h with
74 | head => exact List.Mem.head _
75 | tail _ hm => exact List.Mem.tail _ (mem_eraseOne_of_ne hne rest hm)
76
77/-- Pure-core Pigeonhole / Surjection Cardinality Theorem:
78 if every natural number `m < M` belongs to `L`, then `M <= L.length`. -/
79theorem range_subset_len_le :
80 ∀ (M : Nat) (L : List Nat), (∀ m, m < M → m ∈ L) → M ≤ L.length
81 | 0, _, _ => Nat.zero_le _
82 | M + 1, L, hcov => by
83 have hM : M ∈ L := hcov M (Nat.lt_succ_self M)
84 have hlen := eraseOne_len_of_mem L hM
85 have hsub : ∀ m, m < M → m ∈ eraseOne M L := fun m hm =>
86 mem_eraseOne_of_ne (by omega) L (hcov m (Nat.lt_succ_of_lt hm))
87 have ih := range_subset_len_le M (eraseOne M L) hsub
88 omega
89
90theorem mem_of_getD {α : Type} [Inhabited α] (l : List α) (i : Nat) (hi : i < l.length) :
91 l.getD i default ∈ l := by
92 induction l generalizing i with
93 | nil => cases hi
94 | cons a rest ih =>
95 cases i with
96 | zero => simp [List.getD]
97 | succ j =>
98 simp only [List.length_cons] at hi
99 simp only [List.getD_cons_succ]
100 exact List.mem_cons_of_mem a (ih j (Nat.lt_of_succ_lt_succ hi))
101
102/-- Theorem 1 (Universal Strength-3 Volume Lower Bound `v^3 <= N`):
103 Every `CA(N; 3, k, v)` with `k >= 3` satisfies `v * v * v <= N`. -/
104theorem ca3_volume_lower_bound
105 {N k v : Nat} {rows : List (List Nat)}
106 (hca : IsCA3 N k v rows) (hk : 3 ≤ k) :
107 v * v * v ≤ N := by
108 by_cases hv : v = 0
109 · subst hv; simp
110 · have hvpos : 0 < v := Nat.pos_of_ne_zero hv
111 obtain ⟨hlen, _, hcov⟩ := hca
112 let enc : List Nat → Nat := fun row =>
113 (row.getD 0 v * v + row.getD 1 v) * v + row.getD 2 v
114 have hsub : ∀ m, m < v * v * v → m ∈ rows.map enc := by
115 intro m hm
116 have hv2pos : 0 < v * v := Nat.mul_pos hvpos hvpos
117 let p2 := m % v
118 let q := m / v
119 let p1 := q % v
120 let p0 := q / v
121 have hp2 : p2 < v := Nat.mod_lt m hvpos
122 have hq : q < v * v := Nat.div_lt_of_lt_mul (by rw [Nat.mul_comm]; exact hm)
123 have hp1 : p1 < v := Nat.mod_lt q hvpos
124 have hp0 : p0 < v := Nat.div_lt_of_lt_mul (by rw [Nat.mul_comm]; exact hq)
125 obtain ⟨r, hr, he0, he1, he2⟩ :=
126 hcov 0 1 2 (by omega) (by omega) (by omega) (by omega) (by omega) (by omega)
127 p0 p1 p2 hp0 hp1 hp2
128 have hmem : rows.getD r [] ∈ rows := mem_of_getD rows r (by omega)
129 have henc : enc (rows.getD r []) = m := by
130 show ((rows.getD r []).getD 0 v * v + (rows.getD r []).getD 1 v) * v + (rows.getD r []).getD 2 v = m
131 rw [he0, he1, he2]
132 have hqeq : p0 * v + p1 = q := by
133 dsimp [p0, p1]; rw [Nat.mul_comm (q / v) v, Nat.div_add_mod]
134 rw [hqeq]
135 dsimp [q, p2]; rw [Nat.mul_comm (m / v) v, Nat.div_add_mod]
136 rw [← henc]
137 exact List.mem_map_of_mem hmem
138 have hle := range_subset_len_le (v * v * v) (rows.map enc) hsub
139 simp only [List.length_map, hlen] at hle
140 exact hle
141
142/-- Theorem 2 (Universal Strength-2 Volume Lower Bound `v^2 <= N`):
143 Every `CA(N; 2, k, v)` with `k >= 2` satisfies `v * v <= N`. -/
144theorem ca2_volume_lower_bound
145 {N k v : Nat} {rows : List (List Nat)}
146 (hca : IsCA2 N k v rows) (hk : 2 ≤ k) :
147 v * v ≤ N := by
148 by_cases hv : v = 0
149 · subst hv; simp
150 · have hvpos : 0 < v := Nat.pos_of_ne_zero hv
151 obtain ⟨hlen, _, hcov⟩ := hca
152 let enc : List Nat → Nat := fun row => row.getD 0 v * v + row.getD 1 v
153 have hsub : ∀ m, m < v * v → m ∈ rows.map enc := by
154 intro m hm
155 let p1 := m % v
156 let p0 := m / v
157 have hp1 : p1 < v := Nat.mod_lt m hvpos
158 have hp0 : p0 < v := Nat.div_lt_of_lt_mul (by rw [Nat.mul_comm]; exact hm)
159 obtain ⟨r, hr, he0, he1⟩ :=
160 hcov 0 1 (by omega) (by omega) (by omega) p0 p1 hp0 hp1
161 have hmem : rows.getD r [] ∈ rows := mem_of_getD rows r (by omega)
162 have henc : enc (rows.getD r []) = m := by
163 show (rows.getD r []).getD 0 v * v + (rows.getD r []).getD 1 v = m
164 rw [he0, he1]; dsimp [p0, p1]; rw [Nat.mul_comm (m / v) v, Nat.div_add_mod]
165 rw [← henc]
166 exact List.mem_map_of_mem hmem
167 have hle := range_subset_len_le (v * v) (rows.map enc) hsub
168 simp only [List.length_map, hlen] at hle
169 exact hle
170
171/-! ## Broken-Model Negative Controls (`neg_ctrl_*`) -/
172
173/-- Negative Control 1: No matrix can form a `CA(124; 3, 11, 5)` (below `5^3 = 125`). -/
174theorem neg_ctrl_ca3_quinary_below_125 (rows : List (List Nat)) :
175 ¬ IsCA3 124 11 5 rows := by
176 intro hca
177 have h := ca3_volume_lower_bound hca (by omega)
178 omega
179
180/-- Negative Control 2: No matrix can form a `CA(511; 3, 17, 8)` (below `8^3 = 512`). -/
181theorem neg_ctrl_ca3_octal_below_512 (rows : List (List Nat)) :
182 ¬ IsCA3 511 17 8 rows := by
183 intro hca
184 have h := ca3_volume_lower_bound hca (by omega)
185 omega
186
187/-- Negative Control 3: No matrix can form a `CA(24; 2, 11, 5)` (below `5^2 = 25`). -/
188theorem neg_ctrl_ca2_quinary_below_25 (rows : List (List Nat)) :
189 ¬ IsCA2 24 11 5 rows := by
190 intro hca
191 have h := ca2_volume_lower_bound hca (by omega)
192 omega
193
194/-- Negative Control 4: A 2-element list cannot cover `{0, 1, 2}` (`3 <= 2` is false). -/
195theorem neg_ctrl_pigeonhole_3_into_2 : ¬ (∀ m, m < 3 → m ∈ ([0, 1] : List Nat)) := by
196 intro h
197 have hle := range_subset_len_le 3 [0, 1] h
198 simp at hle
199
200#print axioms range_subset_len_le
201#print axioms ca3_volume_lower_bound
202#print axioms ca2_volume_lower_bound
203#print axioms neg_ctrl_ca3_quinary_below_125
204#print axioms neg_ctrl_ca3_octal_below_512
205#print axioms neg_ctrl_ca2_quinary_below_25
206#print axioms neg_ctrl_pigeonhole_3_into_2
207
208end CoveringArrayQuinaryVolumeW15