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

146 lines · 7018 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/CoveringArrayOctalBitplaneW16.lean
4
5 Standalone Zero-Mathlib Lean 4.36.0 Formal Proof of Universal Bit-Plane &
6 Prime-Power Digit-Projection Theorems for Strength-3 Covering Arrays (Wave 16):
7 1. Universal Base-`b` Digit-Plane Projection (`ca3_base_digit_projection`):
8 for ANY base `b >= 1`, shift `d >= 1`, and upper radix `u >= 1`, extracting the
9 middle base-`b` digit `(x / d) % b` from any `CA(N; 3, k, u * b * d)` yields a
10 valid `CA(N; 3, k, b)`.
11 2. Universal Octal Bit-Plane Corollaries (`ca3_octal_bit0`, `ca3_octal_bit1`, `ca3_octal_bit2`):
12 every octal `CA(N; 3, k, 8)` projects to three valid binary `CA(N; 3, k, 2)` bit-planes
13 (`x % 2`, `(x / 2) % 2`, `(x / 4) % 2`).
14 3. Universal Octal-to-Quaternary Projections (`ca3_octal_low_quat`, `ca3_octal_high_quat`):
15 every octal `CA(N; 3, k, 8)` projects to a quaternary `CA(N; 3, k, 4)` via `x % 4`.
16 4. Four literal broken-model negative controls (`neg_ctrl_*`).
17
18 0 sorry, 0 admit, 0 native_decide, 0 custom axioms, 0 unsafe, 0 Mathlib.
19-/
20
21namespace CoveringArrayOctalBitplaneW16
22
23def IsCA3 (N k v : Nat) (rows : List (List Nat)) : Prop :=
24 rows.length = N ∧
25 (∀ r, r < N → (rows.getD r []).length = k ∧
26 ∀ c, c < k → (rows.getD r []).getD c v < v) ∧
27 (∀ c0 c1 c2,
28 c0 < k → c1 < k → c2 < k →
29 c0 ≠ c1 → c0 ≠ c2 → c1 ≠ c2 →
30 ∀ p0 p1 p2, p0 < v → p1 < v → p2 < v →
31 ∃ r, r < N ∧
32 (rows.getD r []).getD c0 v = p0 ∧
33 (rows.getD r []).getD c1 v = p1 ∧
34 (rows.getD r []).getD c2 v = p2)
35
36theorem getD_map {α β : Type} (f : α → β) (l : List α) (i : Nat) (da : α) (db : β)
37 (hi : i < l.length) :
38 (l.map f).getD i db = f (l.getD i da) := by
39 induction l generalizing i with
40 | nil => cases hi
41 | cons a rest ih =>
42 cases i with
43 | zero => simp [List.getD]
44 | succ j =>
45 simp only [List.length_cons] at hi
46 simp only [List.map_cons, List.getD_cons_succ]
47 exact ih j (Nat.lt_of_succ_lt_succ hi)
48
49theorem digit_lift_lt {p u b d : Nat} (hp : p < b) (hu : 0 < u) (hd : 0 < d) :
50 p * d < u * b * d := by
51 have h1 : p * d < b * d := Nat.mul_lt_mul_of_pos_right hp hd
52 have h2 : 1 * b ≤ u * b := Nat.mul_le_mul_right b hu
53 have h3 : b * d ≤ u * b * d := by
54 rw [Nat.one_mul] at h2
55 exact Nat.mul_le_mul_right d h2
56 omega
57
58/-- Theorem 1 (Universal Base-`b` Digit-Plane Projection):
59 For any `CA(N; 3, k, u * b * d)` with `u, b, d >= 1`, extracting `(x / d) % b`
60 entrywise yields a valid `CA(N; 3, k, b)`. -/
61theorem ca3_base_digit_projection
62 {N k u b d : Nat} {rows : List (List Nat)}
63 (hca : IsCA3 N k (u * b * d) rows) (hu : 0 < u) (hb : 0 < b) (hd : 0 < d) :
64 IsCA3 N k b (rows.map (fun row => row.map (fun x => (x / d) % b))) := by
65 obtain ⟨hlen, hwf, hcov⟩ := hca
66 refine ⟨by simp [hlen], ?_, ?_⟩
67 · intro r hr
68 have hr' : r < rows.length := by omega
69 have hrow : (rows.map (fun row => row.map (fun x => (x / d) % b))).getD r [] =
70 (rows.getD r []).map (fun x => (x / d) % b) :=
71 getD_map _ rows r [] [] hr'
72 obtain ⟨hrlen, _⟩ := hwf r hr
73 rw [hrow]
74 refine ⟨by rw [List.length_map]; exact hrlen, ?_⟩
75 intro c hc
76 rw [getD_map (fun x => (x / d) % b) (rows.getD r []) c (u * b * d) b (by omega)]
77 exact Nat.mod_lt _ hb
78 · intro c0 c1 c2 hc0 hc1 hc2 h01 h02 h12 p0 p1 p2 hp0 hp1 hp2
79 obtain ⟨r, hr, he0, he1, he2⟩ :=
80 hcov c0 c1 c2 hc0 hc1 hc2 h01 h02 h12 (p0 * d) (p1 * d) (p2 * d)
81 (digit_lift_lt hp0 hu hd) (digit_lift_lt hp1 hu hd) (digit_lift_lt hp2 hu hd)
82 have hr' : r < rows.length := by omega
83 have hrlen : (rows.getD r []).length = k := (hwf r hr).1
84 have hrow : (rows.map (fun row => row.map (fun x => (x / d) % b))).getD r [] =
85 (rows.getD r []).map (fun x => (x / d) % b) :=
86 getD_map _ rows r [] [] hr'
87 refine ⟨r, hr, ?_, ?_, ?_⟩
88 · rw [hrow, getD_map _ (rows.getD r []) c0 (u * b * d) b (by omega), he0, Nat.mul_div_cancel p0 hd, Nat.mod_eq_of_lt hp0]
89 · rw [hrow, getD_map _ (rows.getD r []) c1 (u * b * d) b (by omega), he1, Nat.mul_div_cancel p1 hd, Nat.mod_eq_of_lt hp1]
90 · rw [hrow, getD_map _ (rows.getD r []) c2 (u * b * d) b (by omega), he2, Nat.mul_div_cancel p2 hd, Nat.mod_eq_of_lt hp2]
91
92/-- Corollary 2a: Octal bit-plane 0 (`x % 2`) yields a binary `CA(N; 3, k, 2)`. -/
93theorem ca3_octal_bit0 {N k : Nat} {rows : List (List Nat)} (hca : IsCA3 N k 8 rows) :
94 IsCA3 N k 2 (rows.map (fun row => row.map (fun x => (x / 1) % 2))) :=
95 ca3_base_digit_projection (u := 4) (b := 2) (d := 1) hca (by omega) (by omega) (by omega)
96
97/-- Corollary 2b: Octal bit-plane 1 (`(x / 2) % 2`) yields a binary `CA(N; 3, k, 2)`. -/
98theorem ca3_octal_bit1 {N k : Nat} {rows : List (List Nat)} (hca : IsCA3 N k 8 rows) :
99 IsCA3 N k 2 (rows.map (fun row => row.map (fun x => (x / 2) % 2))) :=
100 ca3_base_digit_projection (u := 2) (b := 2) (d := 2) hca (by omega) (by omega) (by omega)
101
102/-- Corollary 2c: Octal bit-plane 2 (`(x / 4) % 2`) yields a binary `CA(N; 3, k, 2)`. -/
103theorem ca3_octal_bit2 {N k : Nat} {rows : List (List Nat)} (hca : IsCA3 N k 8 rows) :
104 IsCA3 N k 2 (rows.map (fun row => row.map (fun x => (x / 4) % 2))) :=
105 ca3_base_digit_projection (u := 1) (b := 2) (d := 4) hca (by omega) (by omega) (by omega)
106
107/-- Corollary 3: Octal low-2-bit projection (`x % 4`) yields a quaternary `CA(N; 3, k, 4)`. -/
108theorem ca3_octal_low_quat {N k : Nat} {rows : List (List Nat)} (hca : IsCA3 N k 8 rows) :
109 IsCA3 N k 4 (rows.map (fun row => row.map (fun x => (x / 1) % 4))) :=
110 ca3_base_digit_projection (u := 2) (b := 4) (d := 1) hca (by omega) (by omega) (by omega)
111
112/-! ## Broken-Model Negative Controls (`neg_ctrl_*`) -/
113
114theorem neg_ctrl_empty_not_ca3_v8 : ¬ IsCA3 0 3 8 [] := by
115 intro hca
116 obtain ⟨r, hr, _⟩ :=
117 hca.2.2 0 1 2 (by omega) (by omega) (by omega) (by omega) (by omega) (by omega)
118 0 0 0 (by omega) (by omega) (by omega)
119 omega
120
121theorem neg_ctrl_bad_octal_symbol : ¬ IsCA3 1 3 8 [[8, 0, 0]] := by
122 intro hca
123 have hlt := (hca.2.1 0 (by omega)).2 0 (by omega)
124 simp at hlt
125
126theorem neg_ctrl_const_zero_not_octal : ¬ IsCA3 1 3 8 [[0, 0, 0]] := by
127 intro hca
128 obtain ⟨r, hr, he0, _⟩ :=
129 hca.2.2 0 1 2 (by omega) (by omega) (by omega) (by omega) (by omega) (by omega)
130 7 0 0 (by omega) (by omega) (by omega)
131 have hr0 : r = 0 := by omega
132 subst hr0; simp at he0
133
134theorem neg_ctrl_bit_shift_overflow : ¬ (8 * 1 < 1 * 2 * 4) := by decide
135
136#print axioms ca3_base_digit_projection
137#print axioms ca3_octal_bit0
138#print axioms ca3_octal_bit1
139#print axioms ca3_octal_bit2
140#print axioms ca3_octal_low_quat
141#print axioms neg_ctrl_empty_not_ca3_v8
142#print axioms neg_ctrl_bad_octal_symbol
143#print axioms neg_ctrl_const_zero_not_octal
144#print axioms neg_ctrl_bit_shift_overflow
145
146end CoveringArrayOctalBitplaneW16