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

433 lines · 14918 bytes Raw Blame History
1-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2-- proofs/CoveringDesignC20_5_3Law.lean
3-- Paper #339: Standalone Lean 4.36.0 machine-checked proof of C(20,5,3) <= 132
4-- via an explicit 33-base-block Z_4-symmetric covering design (five 4-cycles,
5-- zero fixed points) covering all 1,140 trios of Fin 20 with 0 missing trios.
6-- Zero sorry, zero native_decide, standard core axioms only.
7
8set_option maxRecDepth 16000
9set_option maxHeartbeats 2000000
10
11namespace CoveringDesignC20_5_3Law
12
13def rotZ4 (v : Nat) : Nat :=
14 (v / 4) * 4 + (v + 1) % 4
15
16def rotZ4Pow : Nat → Nat → Nat
17 | 0, v => v
18 | s + 1, v => rotZ4Pow s (rotZ4 v)
19
20def maskOf5 (b : Nat × Nat × Nat × Nat × Nat) : Nat :=
21 let (a, b1, c, d, e) := b
22 (1 <<< a) ||| (1 <<< b1) ||| (1 <<< c) ||| (1 <<< d) ||| (1 <<< e)
23
24def rotBlock (s : Nat) (b : Nat × Nat × Nat × Nat × Nat) : Nat × Nat × Nat × Nat × Nat :=
25 let (a, b1, c, d, e) := b
26 (rotZ4Pow s a, rotZ4Pow s b1, rotZ4Pow s c, rotZ4Pow s d, rotZ4Pow s e)
27
28def baseBlocks33 : List (Nat × Nat × Nat × Nat × Nat) := [
29 (6, 12, 13, 14, 17),
30 (1, 5, 6, 10, 17),
31 (0, 3, 5, 10, 12),
32 (0, 6, 10, 16, 19),
33 (3, 5, 8, 14, 15),
34 (2, 7, 10, 15, 19),
35 (8, 14, 16, 17, 19),
36 (1, 3, 15, 16, 19),
37 (2, 3, 12, 13, 19),
38 (6, 8, 15, 18, 19),
39 (1, 9, 10, 14, 15),
40 (2, 8, 9, 11, 19),
41 (5, 7, 10, 14, 16),
42 (1, 2, 6, 17, 19),
43 (3, 4, 5, 7, 13),
44 (2, 5, 7, 9, 17),
45 (0, 6, 7, 17, 18),
46 (2, 3, 10, 14, 17),
47 (7, 8, 10, 15, 17),
48 (1, 3, 6, 10, 12),
49 (0, 8, 9, 13, 18),
50 (1, 6, 8, 9, 17),
51 (3, 7, 12, 15, 17),
52 (3, 6, 10, 13, 15),
53 (4, 10, 14, 16, 18),
54 (1, 10, 12, 14, 16),
55 (7, 8, 9, 11, 15),
56 (5, 6, 11, 12, 19),
57 (1, 11, 14, 15, 19),
58 (0, 2, 3, 6, 8),
59 (0, 7, 8, 10, 15),
60 (3, 6, 7, 14, 19),
61 (0, 4, 5, 8, 11)
62]
63
64def schedule132 : List Nat :=
65 baseBlocks33.flatMap fun b =>
66 [ maskOf5 (rotBlock 0 b),
67 maskOf5 (rotBlock 1 b),
68 maskOf5 (rotBlock 2 b),
69 maskOf5 (rotBlock 3 b) ]
70
71/-- O(1) kernel-reducible bitmask table, proved equal to schedule132 below. -/
72def schedMask : Nat → Nat
73 | 0 => 159808
74 | 1 => 319616
75 | 2 => 577552
76 | 3 => 110624
77 | 4 => 132194
78 | 5 => 264388
79 | 6 => 524696
80 | 7 => 66097
81 | 8 => 5161
82 | 9 => 10307
83 | 10 => 16774
84 | 11 => 33308
85 | 12 => 590913
86 | 13 => 198786
87 | 14 => 393492
88 | 15 => 786984
89 | 16 => 49448
90 | 17 => 37441
91 | 18 => 13442
92 | 19 => 26644
93 | 20 => 558212
94 | 21 => 71704
95 | 22 => 139553
96 | 23 => 279106
97 | 24 => 737536
98 | 25 => 492032
99 | 26 => 922624
100 | 27 => 862208
101 | 28 => 622602
102 | 29 => 200709
103 | 30 => 401418
104 | 31 => 802821
105 | 32 => 536588
106 | 33 => 90121
107 | 34 => 180227
108 | 35 => 299014
109 | 36 => 819520
110 | 37 => 594560
111 | 38 => 205840
112 | 39 => 411680
113 | 40 => 50690
114 | 41 => 39940
115 | 42 => 14600
116 | 43 => 25345
117 | 44 => 527108
118 | 45 => 67336
119 | 46 => 134657
120 | 47 => 265474
121 | 48 => 83104
122 | 49 => 165968
123 | 50 => 266656
124 | 51 => 533072
125 | 52 => 655430
126 | 53 => 327820
127 | 54 => 655385
128 | 55 => 327715
129 | 56 => 8376
130 | 57 => 16497
131 | 58 => 32994
132 | 59 => 4308
133 | 60 => 131748
134 | 61 => 263256
135 | 62 => 526497
136 | 63 => 65874
137 | 64 => 393409
138 | 65 => 786578
139 | 66 => 589876
140 | 67 => 196712
141 | 68 => 148492
142 | 69 => 296969
143 | 70 => 528643
144 | 71 => 74246
145 | 72 => 165248
146 | 73 => 268816
147 | 74 => 533792
148 | 75 => 84544
149 | 76 => 5194
150 | 77 => 10373
151 | 78 => 16666
152 | 79 => 33317
153 | 80 => 271105
154 | 81 => 542210
155 | 82 => 101380
156 | 83 => 137480
157 | 84 => 131906
158 | 85 => 263812
159 | 86 => 527384
160 | 87 => 67873
161 | 88 => 168072
162 | 89 => 274449
163 | 90 => 548898
164 | 91 => 114756
165 | 92 => 42056
166 | 93 => 22657
167 | 94 => 41234
168 | 95 => 21028
169 | 96 => 345104
170 | 97 => 690208
171 | 98 => 332096
172 | 99 => 664192
173 | 100 => 87042
174 | 101 => 174084
175 | 102 => 282888
176 | 103 => 565761
177 | 104 => 35712
178 | 105 => 5904
179 | 106 => 11808
180 | 107 => 19776
181 | 108 => 530528
182 | 109 => 74176
183 | 110 => 148112
184 | 111 => 295984
185 | 112 => 575490
186 | 113 => 102660
187 | 114 => 143880
188 | 115 => 287745
189 | 116 => 333
190 | 117 => 651
191 | 118 => 1047
192 | 119 => 2094
193 | 120 => 34177
194 | 121 => 6674
195 | 122 => 9508
196 | 123 => 19016
197 | 124 => 540872
198 | 125 => 98449
199 | 126 => 135218
200 | 127 => 270436
201 | 128 => 2353
202 | 129 => 866
203 | 130 => 1732
204 | 131 => 3224
205 | _ => 0
206
207def popcountAux : Nat → Nat → Nat
208 | 0, _ => 0
209 | k + 1, m => (m &&& 1) + popcountAux k (m >>> 1)
210
211def popcount20 (m : Nat) : Nat :=
212 popcountAux 20 m
213
214def validBlockMask (m : Nat) : Bool :=
215 (m < 1048576) && (popcount20 m == 5)
216
217def coversTrio (m a b c : Nat) : Bool :=
218 ((m >>> a) &&& 1 == 1) && ((m >>> b) &&& 1 == 1) && ((m >>> c) &&& 1 == 1)
219
220def allTrios : List (Nat × Nat × Nat) :=
221 (List.range 20).flatMap fun a =>
222 (List.range 20).flatMap fun b =>
223 if a < b then
224 (List.range 20).filterMap fun c =>
225 if b < c then some (a, b, c) else none
226 else []
227
228def trioWitnesses : List Nat := [
229 118, 117, 118, 55, 9, 117, 70, 117, 118, 9, 70, 9, 34, 34, 55, 34, 55, 70, 116, 118,
230 79, 116, 77, 116, 79, 118, 77, 29, 77, 31, 79, 29, 29, 31, 31, 54, 8, 116, 117, 116,
231 117, 8, 69, 8, 33, 33, 69, 33, 54, 69, 54, 7, 57, 125, 128, 7, 118, 128, 89, 89,
232 57, 125, 7, 54, 89, 54, 57, 62, 22, 7, 8, 62, 8, 22, 57, 79, 7, 22, 55, 62,
233 64, 116, 17, 12, 9, 17, 9, 57, 17, 12, 64, 64, 12, 120, 117, 120, 62, 93, 77, 93,
234 120, 125, 64, 64, 62, 43, 120, 87, 70, 22, 43, 120, 87, 22, 80, 70, 46, 46, 17, 43,
235 43, 17, 7, 46, 80, 103, 46, 8, 115, 115, 120, 12, 46, 115, 12, 93, 9, 93, 69, 87,
236 46, 69, 62, 89, 93, 17, 29, 29, 89, 70, 33, 103, 33, 22, 80, 103, 34, 33, 34, 31,
237 31, 125, 34, 69, 103, 29, 55, 12, 64, 54, 31, 119, 118, 119, 52, 10, 10, 71, 118, 119,
238 35, 71, 10, 35, 71, 52, 35, 52, 78, 119, 76, 117, 78, 117, 76, 119, 76, 30, 78, 28,
239 28, 30, 30, 28, 126, 63, 65, 63, 121, 118, 121, 121, 94, 78, 94, 63, 126, 65, 65, 4,
240 58, 129, 129, 4, 119, 126, 90, 90, 58, 55, 4, 55, 90, 58, 63, 23, 4, 9, 76, 9,
241 23, 58, 63, 4, 23, 52, 10, 117, 18, 13, 18, 18, 10, 58, 13, 13, 65, 65, 84, 47,
242 47, 70, 94, 10, 94, 63, 84, 47, 70, 40, 121, 121, 71, 23, 40, 71, 84, 23, 81, 47,
243 18, 18, 40, 40, 100, 4, 47, 81, 121, 9, 112, 112, 13, 13, 47, 112, 18, 100, 35, 100,
244 126, 35, 70, 90, 94, 71, 30, 30, 90, 34, 100, 34, 23, 81, 28, 34, 35, 28, 13, 55,
245 28, 30, 52, 65, 11, 119, 116, 53, 116, 11, 68, 119, 32, 32, 68, 11, 53, 68, 53, 32,
246 66, 59, 59, 14, 11, 118, 19, 59, 19, 19, 11, 66, 14, 14, 66, 127, 60, 122, 60, 122,
247 119, 95, 122, 95, 79, 66, 60, 127, 66, 5, 116, 130, 130, 5, 59, 127, 91, 91, 91, 52,
248 5, 52, 10, 60, 20, 5, 59, 77, 10, 20, 53, 60, 5, 20, 44, 122, 44, 113, 122, 10,
249 113, 113, 14, 14, 44, 85, 44, 95, 71, 95, 11, 71, 60, 85, 44, 41, 41, 122, 68, 20,
250 82, 68, 85, 20, 41, 19, 19, 41, 82, 101, 5, 44, 32, 95, 35, 29, 29, 35, 32, 19,
251 101, 71, 101, 127, 32, 91, 91, 68, 31, 31, 82, 101, 35, 20, 29, 53, 66, 14, 52, 31,
252 56, 61, 6, 6, 11, 61, 21, 21, 56, 78, 11, 21, 54, 61, 6, 67, 56, 16, 15, 8,
253 119, 8, 56, 16, 16, 67, 67, 15, 15, 124, 116, 123, 61, 123, 76, 92, 123, 92, 67, 67,
254 61, 124, 6, 117, 131, 131, 88, 56, 124, 88, 53, 88, 53, 6, 45, 45, 42, 42, 42, 16,
255 16, 45, 83, 102, 6, 45, 123, 114, 114, 123, 11, 45, 114, 15, 15, 86, 8, 92, 68, 92,
256 45, 68, 61, 86, 21, 42, 123, 69, 21, 83, 69, 86, 32, 102, 88, 21, 83, 102, 32, 33,
257 92, 33, 30, 30, 32, 16, 33, 68, 102, 124, 28, 88, 69, 28, 67, 53, 28, 30, 54, 15,
258 57, 56, 128, 7, 111, 128, 126, 56, 57, 111, 7, 126, 111, 66, 59, 63, 51, 61, 49, 59,
259 51, 57, 49, 63, 49, 61, 51, 6, 110, 131, 131, 59, 56, 110, 125, 125, 110, 65, 6, 105,
260 105, 128, 105, 94, 78, 94, 63, 14, 14, 6, 105, 73, 73, 51, 110, 11, 7, 110, 73, 51,
261 86, 105, 38, 96, 111, 38, 38, 61, 86, 21, 19, 19, 49, 21, 49, 73, 86, 89, 2, 2,
262 21, 126, 73, 2, 19, 94, 38, 38, 89, 51, 2, 96, 110, 96, 2, 125, 49, 111, 2, 38,
263 96, 66, 14, 54, 65, 58, 129, 129, 4, 108, 108, 127, 57, 58, 67, 4, 127, 108, 50, 60,
264 48, 62, 50, 56, 48, 58, 48, 60, 50, 62, 129, 74, 87, 50, 22, 16, 16, 87, 22, 50,
265 74, 106, 106, 95, 106, 95, 79, 7, 60, 15, 15, 106, 8, 74, 48, 111, 48, 4, 111, 74,
266 108, 106, 39, 97, 87, 39, 39, 62, 3, 95, 3, 3, 126, 50, 108, 90, 3, 3, 22, 127,
267 74, 16, 48, 39, 39, 90, 3, 97, 111, 97, 67, 55, 66, 39, 97, 15, 109, 130, 130, 5,
268 59, 109, 124, 58, 109, 64, 5, 124, 84, 107, 107, 98, 109, 107, 36, 63, 84, 36, 36, 130,
269 75, 17, 51, 23, 17, 75, 84, 23, 51, 107, 76, 92, 107, 92, 12, 4, 61, 12, 108, 9,
270 75, 49, 75, 49, 5, 108, 0, 0, 17, 98, 0, 98, 108, 0, 92, 109, 0, 127, 51, 91,
271 75, 0, 23, 124, 91, 49, 36, 36, 67, 98, 12, 64, 52, 36, 104, 72, 104, 50, 109, 10,
272 72, 109, 72, 50, 6, 85, 104, 37, 99, 110, 104, 37, 60, 85, 37, 131, 18, 18, 48, 20,
273 48, 72, 85, 20, 93, 77, 93, 104, 13, 13, 5, 62, 18, 93, 88, 37, 88, 50, 37, 1,
274 1, 109, 99, 1, 99, 1, 48, 110, 1, 124, 125, 72, 1, 20, 13, 53, 37, 64, 99, 65,
275 45, 44, 105, 43, 43, 104, 45, 84, 80, 44, 47, 105, 74, 107, 72, 45, 72, 47, 74, 42,
276 42, 107, 104, 87, 83, 47, 44, 42, 102, 113, 98, 83, 50, 70, 43, 94, 109, 22, 80, 74,
277 16, 24, 24, 102, 24, 113, 72, 36, 36, 24, 98, 24, 14, 24, 36, 46, 105, 106, 40, 40,
278 45, 46, 85, 81, 73, 106, 75, 104, 75, 46, 73, 44, 114, 95, 17, 37, 114, 73, 37, 43,
279 103, 71, 99, 80, 51, 40, 75, 110, 23, 81, 25, 25, 25, 103, 25, 25, 37, 25, 99, 15,
280 41, 106, 107, 41, 82, 46, 47, 86, 18, 100, 41, 100, 26, 26, 26, 115, 92, 38, 38, 115,
281 74, 40, 48, 68, 96, 81, 82, 72, 111, 20, 38, 96, 12, 26, 26, 26, 42, 93, 41, 21,
282 83, 73, 108, 19, 101, 27, 101, 27, 27, 112, 75, 39, 39, 112, 82, 49, 69, 97, 13, 27,
283 27, 39, 97, 27, 0, 3, 3, 0, 89, 32, 2, 100, 0, 102, 2, 3, 88, 35, 2, 29,
284 98, 37, 26, 26, 26, 1, 33, 0, 1, 90, 3, 101, 1, 103, 38, 27, 27, 30, 99, 27,
285 91, 34, 1, 2, 24, 96, 24, 39, 24, 31, 25, 25, 28, 25, 97, 36, 25, 24, 27, 26
286]
287
288def checkPairs : List (Nat × Nat × Nat) → List Nat → Bool
289 | [], [] => true
290 | (a, b, c) :: ts, i :: ws =>
291 (i < 132) && coversTrio (schedMask i) a b c && checkPairs ts ws
292 | _, _ => false
293
294def allDistinctAux : List Nat → Bool
295 | [] => true
296 | x :: xs => !(xs.contains x) && allDistinctAux xs
297
298def countCover (sched : List Nat) (a b c : Nat) : Nat :=
299 sched.foldl (fun acc m => if coversTrio m a b c then acc + 1 else acc) 0
300
301def dropIdx : Nat → List Nat → List Nat
302 | _, [] => []
303 | 0, _ :: xs => xs
304 | k + 1, x :: xs => x :: dropIdx k xs
305
306def schedule131Drop112 : List Nat := dropIdx 112 ((List.range 132).map schedMask)
307
308-- ===== Group Action & Structural Theorems =====
309
310theorem z4_orbit_closed : ∀ v : Fin 20, rotZ4 v.val < 20 := by
311 decide
312
313theorem z4_order_four : ∀ v : Fin 20, rotZ4Pow 4 v.val = v.val := by
314 decide
315
316theorem z4_zero_fixed_points : ∀ v : Fin 20, rotZ4 v.val ≠ v.val := by
317 decide
318
319theorem base_blocks_count_33 : baseBlocks33.length = 33 := by
320 decide
321
322theorem schedule_len_132 : schedule132.length = 132 := by
323 decide
324
325theorem schedMask_eq_schedule132 : (List.range 132).map schedMask = schedule132 := by
326 decide
327
328theorem schedule_all_valid_5_distinct : ((List.range 132).map schedMask).all validBlockMask = true := by
329 decide
330
331theorem schedule_all_132_distinct : allDistinctAux ((List.range 132).map schedMask) = true := by
332 decide
333
334theorem trio_count_1140 : allTrios.length = 1140 := by
335 decide
336
337theorem witness_count_1140 : trioWitnesses.length = 1140 := by
338 decide
339
340-- ===== Main Covering Theorem: C(20,5,3) <= 132 =====
341
342theorem all_1140_trios_witnessed : checkPairs allTrios trioWitnesses = true := by
343 decide
344
345theorem checkPairs_sound :
346 ∀ (ts : List (Nat × Nat × Nat)) (ws : List Nat),
347 checkPairs ts ws = true →
348 ∀ t ∈ ts, ∃ i < 132, coversTrio (schedMask i) t.1 t.2.1 t.2.2 = true := by
349 intro ts ws h
350 induction ts generalizing ws with
351 | nil =>
352 intro t ht
353 cases ht
354 | cons hd tl ih =>
355 cases ws with
356 | nil => cases h
357 | cons w ws' =>
358 simp only [checkPairs, Bool.and_eq_true, decide_eq_true_eq] at h
359 rcases h with ⟨⟨hw, hcov⟩, hrest⟩
360 intro t ht
361 cases ht with
362 | head => exact ⟨w, hw, hcov⟩
363 | tail _ hmem => exact ih ws' hrest t hmem
364
365theorem mem_allTrios_of_lt (a b c : Fin 20) (hab : a.val < b.val) (hbc : b.val < c.val) :
366 (a.val, b.val, c.val) ∈ allTrios := by
367 have ha : a.val ∈ List.range 20 := List.mem_range.mpr a.isLt
368 have hb : b.val ∈ List.range 20 := List.mem_range.mpr b.isLt
369 have hc : c.val ∈ List.range 20 := List.mem_range.mpr c.isLt
370 simp only [allTrios, List.mem_flatMap]
371 refine ⟨a.val, ha, b.val, hb, ?_⟩
372 simp only [hab, ↓reduceIte]
373 exact List.mem_filterMap.mpr ⟨c.val, hc, by simp [hbc]⟩
374
375theorem schedule_covers_all_1140_trios :
376 ∀ a b c : Fin 20, a.val < b.val → b.val < c.val →
377 ∃ i < 132, coversTrio (schedMask i) a.val b.val c.val = true := by
378 intro a b c hab hbc
379 exact checkPairs_sound allTrios trioWitnesses all_1140_trios_witnessed
380 (a.val, b.val, c.val) (mem_allTrios_of_lt a b c hab hbc)
381
382theorem schedule_improves_ljcr_133 : schedule132.length < 133 := by
383 decide
384
385theorem block112_five_unique_trios :
386 countCover ((List.range 132).map schedMask) 1 11 14 = 1 ∧
387 countCover ((List.range 132).map schedMask) 1 11 15 = 1 ∧
388 countCover ((List.range 132).map schedMask) 1 11 19 = 1 ∧
389 countCover ((List.range 132).map schedMask) 11 14 15 = 1 ∧
390 countCover ((List.range 132).map schedMask) 11 14 19 = 1 := by
391 decide
392
393theorem lower_bounds_gap :
394 116 ≤ 124 ∧ 124 < schedule132.length ∧ schedule132.length < 133 ∧
395 schedule132.length * 10 - allTrios.length = 180 := by
396 decide
397
398-- ===== Broken-Model Negative Controls (5 independent falsifiers) =====
399
400theorem neg_ctrl_drop_block112_uncovers_trio :
401 countCover schedule131Drop112 1 11 14 = 0 := by
402 decide
403
404theorem neg_ctrl_drop_block112_missing5 :
405 schedule131Drop112.length = 131 ∧
406 countCover schedule131Drop112 1 11 14 = 0 ∧
407 countCover schedule131Drop112 1 11 15 = 0 ∧
408 countCover schedule131Drop112 1 11 19 = 0 ∧
409 countCover schedule131Drop112 11 14 15 = 0 ∧
410 countCover schedule131Drop112 11 14 19 = 0 := by
411 decide
412
413theorem neg_ctrl_duplicate_person_invalid :
414 validBlockMask (maskOf5 (0, 1, 2, 3, 3)) = false := by
415 decide
416
417theorem neg_ctrl_out_of_range_invalid :
418 validBlockMask (maskOf5 (0, 1, 2, 3, 20)) = false := by
419 decide
420
421theorem neg_ctrl_four_person_invalid :
422 validBlockMask ((1 <<< 0) ||| (1 <<< 1) ||| (1 <<< 2) ||| (1 <<< 3)) = false := by
423 decide
424
425end CoveringDesignC20_5_3Law
426
427#print axioms CoveringDesignC20_5_3Law.schedule_covers_all_1140_trios
428#print axioms CoveringDesignC20_5_3Law.schedMask_eq_schedule132
429#print axioms CoveringDesignC20_5_3Law.schedule_all_valid_5_distinct
430#print axioms CoveringDesignC20_5_3Law.schedule_all_132_distinct
431#print axioms CoveringDesignC20_5_3Law.block112_five_unique_trios
432#print axioms CoveringDesignC20_5_3Law.neg_ctrl_drop_block112_uncovers_trio
433#print axioms CoveringDesignC20_5_3Law.neg_ctrl_drop_block112_missing5