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

124 lines · 5107 bytes Raw Blame History
1-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2-- General Zero-Mathlib Lean 4.36.0 Structural Theorems:
3-- Composite-Alphabet Strength-2 Covering Array Factorization & Decimal (v = 10 = 2 * 5) Splitting.
4-- Author: M. Drake Stapleton (ORCID: 0009-0002-6890-7111)
5-- 0 sorry, 0 native_decide, zero custom axioms.
6
7namespace CoveringArrayDecimalFactorizationW17
8
9def IsCA2 (N k v : Nat) (A : Fin N → Fin k → Nat) : Prop :=
10 (∀ r c, A r c < v) ∧
11 (∀ c0 c1 : Fin k, c0 ≠ c1 →
12 ∀ a0 a1 : Nat, a0 < v → a1 < v →
13 ∃ r : Fin N, A r c0 = a0 ∧ A r c1 = a1)
14
15/-- Universal strength-2 alphabet-homomorphism projection:
16 any surjection `f : [0, v1) -> [0, v2)` preserves strength-2 covering arrays. -/
17theorem ca2_surjective_projection {N k v1 v2 : Nat} {A : Fin N → Fin k → Nat}
18 (f : Nat → Nat)
19 (hf_range : ∀ x, x < v1 → f x < v2)
20 (hf_surj : ∀ y, y < v2 → ∃ x, x < v1 ∧ f x = y)
21 (hA : IsCA2 N k v1 A) :
22 IsCA2 N k v2 (fun r c => f (A r c)) := by
23 refine ⟨?_, ?_⟩
24 · intro r c
25 exact hf_range (A r c) (hA.1 r c)
26 · intro c0 c1 hne b0 b1 hb0 hb1
27 rcases hf_surj b0 hb0 with ⟨a0, ha0, rfl⟩
28 rcases hf_surj b1 hb1 with ⟨a1, ha1, rfl⟩
29 rcases hA.2 c0 c1 hne a0 a1 ha0 ha1 with ⟨r, hr0, hr1⟩
30 exact ⟨r, congrArg f hr0, congrArg f hr1⟩
31
32/-- Composite-alphabet lower-factor projection: `CA(N; 2, k, a * b)` projects via `x % a`
33 onto `CA(N; 2, k, a)` for all `a > 0, b > 0`. -/
34theorem ca2_mod_projection {N k a b : Nat} {A : Fin N → Fin k → Nat}
35 (ha : 0 < a) (hb : 0 < b)
36 (hA : IsCA2 N k (a * b) A) :
37 IsCA2 N k a (fun r c => A r c % a) := by
38 apply ca2_surjective_projection (fun x => x % a)
39 · intro x _
40 exact Nat.mod_lt x ha
41 · intro y hy
42 refine ⟨y, ?_, Nat.mod_eq_of_lt hy⟩
43 have h1 : a ≤ a * b := Nat.le_mul_of_pos_right a hb
44 exact Nat.lt_of_lt_of_le hy h1
45 · exact hA
46
47/-- Composite-alphabet upper-factor projection: `CA(N; 2, k, a * b)` projects via `x / a`
48 onto `CA(N; 2, k, b)` for all `a > 0, b > 0`. -/
49theorem ca2_div_projection {N k a b : Nat} {A : Fin N → Fin k → Nat}
50 (ha : 0 < a) (_hb : 0 < b)
51 (hA : IsCA2 N k (a * b) A) :
52 IsCA2 N k b (fun r c => A r c / a) := by
53 apply ca2_surjective_projection (fun x => x / a)
54 · intro x hx
55 exact (Nat.div_lt_iff_lt_mul ha).2 (by rw [Nat.mul_comm]; exact hx)
56 · intro y hy
57 refine ⟨a * y, ?_, ?_⟩
58 · exact Nat.mul_lt_mul_of_pos_left hy ha
59 · rw [Nat.mul_comm]
60 exact Nat.mul_div_cancel y ha
61 · exact hA
62
63/-- Decimal (`v = 10 = 2 * 5`) Binary Projection: every decimal strength-2 CA induces a binary strength-2 CA. -/
64theorem ca2_decimal_binary_projection {N k : Nat} {A : Fin N → Fin k → Nat}
65 (hA : IsCA2 N k 10 A) :
66 IsCA2 N k 2 (fun r c => A r c % 2) :=
67 ca2_mod_projection (a := 2) (b := 5) (by decide) (by decide) hA
68
69/-- Decimal (`v = 10 = 2 * 5`) Quinary Projection: every decimal strength-2 CA induces a quinary strength-2 CA. -/
70theorem ca2_decimal_quinary_projection {N k : Nat} {A : Fin N → Fin k → Nat}
71 (hA : IsCA2 N k 10 A) :
72 IsCA2 N k 5 (fun r c => A r c / 2) :=
73 ca2_div_projection (a := 2) (b := 5) (by decide) (by decide) hA
74
75/-- Column-truncation monotonicity for strength-2 covering arrays. -/
76theorem ca2_column_truncate {N k1 k2 v : Nat} {A : Fin N → Fin k2 → Nat}
77 (hk : k1 ≤ k2) (hA : IsCA2 N k2 v A) :
78 IsCA2 N k1 v (fun r c => A r ⟨c.val, Nat.lt_of_lt_of_le c.isLt hk⟩) := by
79 refine ⟨?_, ?_⟩
80 · intro r c
81 exact hA.1 r ⟨c.val, Nat.lt_of_lt_of_le c.isLt hk⟩
82 · intro c0 c1 hne a0 a1 ha0 ha1
83 have hne' : (⟨c0.val, Nat.lt_of_lt_of_le c0.isLt hk⟩ : Fin k2) ≠
84 ⟨c1.val, Nat.lt_of_lt_of_le c1.isLt hk⟩ := by
85 intro heq
86 apply hne
87 exact Fin.ext (congrArg (fun x : Fin k2 => x.val) heq)
88 exact hA.2 _ _ hne' a0 a1 ha0 ha1
89
90-- Broken-model negative controls (>= 4 literal neg_ctrl_*)
91
92theorem neg_ctrl_empty_not_ca2_v10 :
93 ¬ IsCA2 0 2 10 (fun r _ => Fin.elim0 r) := by
94 intro h
95 rcases h.2 ⟨0, by decide⟩ ⟨1, by decide⟩ (by decide) 0 0 (by decide) (by decide) with ⟨r, _, _⟩
96 exact Fin.elim0 r
97
98theorem neg_ctrl_bad_decimal_symbol :
99 ¬ IsCA2 1 2 10 (fun _ _ => 10) := by
100 intro h
101 have hlt := h.1 ⟨0, by decide⟩ ⟨0, by decide⟩
102 exact Nat.lt_irrefl 10 hlt
103
104theorem neg_ctrl_const_zero_not_ca2_v7 :
105 ¬ IsCA2 109 2 7 (fun _ _ => 0) := by
106 intro h
107 rcases h.2 ⟨0, by decide⟩ ⟨1, by decide⟩ (by decide) 1 0 (by decide) (by decide) with ⟨r, hr0, _⟩
108 exact Nat.noConfusion hr0
109
110theorem neg_ctrl_factor_overflow : ¬ (10 / 2 < 5) := by
111 decide
112
113#print axioms ca2_surjective_projection
114#print axioms ca2_mod_projection
115#print axioms ca2_div_projection
116#print axioms ca2_decimal_binary_projection
117#print axioms ca2_decimal_quinary_projection
118#print axioms ca2_column_truncate
119#print axioms neg_ctrl_empty_not_ca2_v10
120#print axioms neg_ctrl_bad_decimal_symbol
121#print axioms neg_ctrl_const_zero_not_ca2_v7
122#print axioms neg_ctrl_factor_overflow
123
124end CoveringArrayDecimalFactorizationW17