File size: 12,231 Bytes
e5a97c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | import Mathlib
namespace OAI
/-!
A direct qualitative proof of the non-anchor trace obstruction.
No enumeration of suffix generators is needed.
If all binary words occur, any two selected columns in the same class can be
separated by a singleton word, contradicting their suffix monotonicity.
Thus all five classes are distinct. The word 11110 then uses four classes,
while a variable row uses at most three and a dummy row is all ones.
-/
universe uR uC uK uL uRho uBeta
namespace Problem348.DirectNonshattering
open Finset
/-- A surjective family of class-monotone words separates the column classes. -/
theorem class_injective_of_surjective
{R : Type uR} {C : Type uC} {K : Type uK} [DecidableEq C] [LinearOrder K]
{L : Type uL} (classOf : C → L) (key : C → K) (A : R → C → Bool)
(hmono : ∀ r i j, classOf i = classOf j → key i ≤ key j →
A r i = true → A r j = true)
(hsurj : Function.Surjective A) : Function.Injective classOf := by
intro i j hij
by_contra hne
rcases le_total (key i) (key j) with hle | hle
· obtain ⟨r, hr⟩ := hsurj (fun x => decide (x = i))
have hi : A r i = true := by rw [hr]; simp
have hj : A r j = true := hmono r i j hij hle hi
rw [hr] at hj
simp [Ne.symm hne] at hj
· obtain ⟨r, hr⟩ := hsurj (fun x => decide (x = j))
have hj : A r j = true := by rw [hr]; simp
have hi : A r i = true := hmono r j i hij.symm hle hj
rw [hr] at hi
simp [hne] at hi
/-- General form: `q + 2` columns cannot be shattered by classwise suffix
rows supported on at most `q` classes, together with all-one rows. -/
theorem not_surjective_of_card
{R : Type uR} {C : Type uC} {L : Type uL} {K : Type uK} [Fintype C] [DecidableEq C] [DecidableEq L]
[LinearOrder K] (q : ℕ) (hcard : q + 2 ≤ Fintype.card C)
(classOf : C → L) (key : C → K) (A : R → C → Bool)
(hmono : ∀ r i j, classOf i = classOf j → key i ≤ key j →
A r i = true → A r j = true)
(hsupport : ∀ r,
((univ.filter (fun i => A r i = true)).image classOf).card ≤ q ∨
(∀ i, A r i = true)) :
¬ Function.Surjective A := by
classical
intro hsurj
have hinj := class_injective_of_surjective classOf key A hmono hsurj
have : Nonempty C := Fintype.card_pos_iff.mp (by omega)
let j : C := Classical.arbitrary C
obtain ⟨r, hr⟩ := hsurj (fun i => decide (i ≠ j))
rcases hsupport r with hs | hd
· rw [hr, card_image_of_injective _ hinj] at hs
change (univ.filter (fun i : C => decide (i ≠ j) = true)).card ≤ q at hs
have hfilter : (univ.filter (fun i : C => decide (i ≠ j) = true)) =
univ.erase j := by
ext i
simp
rw [hfilter, card_erase_of_mem (mem_univ j), card_univ] at hs
omega
· have hj := hd j
rw [hr] at hj
simp at hj
/-- No family with suffixes in at most three classes, plus all-one rows,
realizes every binary word on five columns. -/
theorem not_surjective_five
{R : Type uR} {L : Type uL} {K : Type uK} [DecidableEq L] [LinearOrder K]
(classOf : Fin 5 → L) (key : Fin 5 → K) (A : R → Fin 5 → Bool)
(hmono : ∀ r i j, classOf i = classOf j → key i ≤ key j →
A r i = true → A r j = true)
(hsupport : ∀ r,
((univ.filter (fun i => A r i = true)).image classOf).card ≤ 3 ∨
(∀ i, A r i = true)) :
¬ Function.Surjective A :=
not_surjective_of_card 3 (by simp) classOf key A hmono hsupport
/-- The conclusion in a form convenient for a five-column shattering test. -/
theorem exists_missing_word
{R : Type uR} {L : Type uL} {K : Type uK} [DecidableEq L] [LinearOrder K]
(classOf : Fin 5 → L) (key : Fin 5 → K) (A : R → Fin 5 → Bool)
(hmono : ∀ r i j, classOf i = classOf j → key i ≤ key j →
A r i = true → A r j = true)
(hsupport : ∀ r,
((univ.filter (fun i => A r i = true)).image classOf).card ≤ 3 ∨
(∀ i, A r i = true)) :
∃ w : Fin 5 → Bool, ∀ r, A r ≠ w := by
simpa only [Function.Surjective, not_forall, not_exists] using
not_surjective_five classOf key A hmono hsupport
/-- A column equal to one in every row also rules out shattering immediately. -/
theorem not_surjective_of_constant_column
{R : Type uR} {C : Type uC} (A : R → C → Bool) (j : C)
(hj : ∀ r, A r j = true) : ¬ Function.Surjective A := by
intro hsurj
obtain ⟨r, hr⟩ := hsurj (fun _ => false)
have h := hj r
rw [hr] at h
cases h
/-- Whole-host version. Dummy columns are all ones, and every non-dummy row
has at most three active classes among the non-dummy columns. The chosen five
columns need not be ordered or even assumed distinct. -/
theorem not_surjective_selected_columns
{R : Type uR} {C : Type uC} {L : Type uL} {K : Type uK} [Fintype C] [DecidableEq C] [DecidableEq L]
[LinearOrder K]
(A : R → C → Bool) (dummyRow : R → Prop) (dummyColumn : C → Prop)
[DecidablePred dummyColumn]
(classOf : C → L) (key : C → K)
(hrow : ∀ r, dummyRow r → ∀ c, A r c = true)
(hcolumn : ∀ c, dummyColumn c → ∀ r, A r c = true)
(hmono : ∀ r, ¬ dummyRow r → ∀ c d,
¬ dummyColumn c → ¬ dummyColumn d → classOf c = classOf d →
key c ≤ key d → A r c = true → A r d = true)
(hsupport : ∀ r, ¬ dummyRow r →
((univ.filter (fun c => ¬ dummyColumn c ∧ A r c = true)).image classOf).card ≤ 3)
(selected : Fin 5 → C) :
¬ Function.Surjective (fun r i => A r (selected i)) := by
classical
by_cases hdummy : ∃ i, dummyColumn (selected i)
· obtain ⟨i, hi⟩ := hdummy
exact not_surjective_of_constant_column (fun r j => A r (selected j)) i
(hcolumn (selected i) hi)
· have hnondummy : ∀ i, ¬ dummyColumn (selected i) := by
simpa only [not_exists] using hdummy
apply not_surjective_five (classOf ∘ selected) (key ∘ selected)
(fun r i => A r (selected i))
· intro r i j hij hle hi
by_cases hr : dummyRow r
· exact hrow r hr (selected j)
· exact hmono r hr (selected i) (selected j)
(hnondummy i) (hnondummy j) hij hle hi
· intro r
by_cases hr : dummyRow r
· exact Or.inr (fun i => hrow r hr (selected i))
· left
refine (card_le_card (show
(univ.filter (fun i => A r (selected i) = true)).image (classOf ∘ selected) ⊆
(univ.filter (fun c => ¬ dummyColumn c ∧ A r c = true)).image classOf
from ?_)).trans (hsupport r hr)
intro l hl
obtain ⟨i, hi, rfl⟩ := mem_image.mp hl
exact mem_image.mpr ⟨selected i,
mem_filter.mpr ⟨mem_univ _, hnondummy i, (mem_filter.mp hi).2⟩, rfl⟩
/-- On `k+2` coordinates, classwise monotone traces with at most `k`
active classes, allowing also the constant-one trace, omit a Boolean word.
The rank need not be injective within a class. -/
theorem exists_missing_word_with_zero {ρ : Type uRho} {β : Type uBeta} [DecidableEq β] (k : ℕ)
(cls : Fin (k + 2) → β) (key : Fin (k + 2) → ℕ)
(trace : ρ → Fin (k + 2) → Bool)
(hup : ∀ r a b, cls a = cls b → key a ≤ key b →
trace r a = true → trace r b = true)
(hsupport : ∀ r, (∀ j, trace r j = true) ∨
((Finset.univ.filter (fun j => trace r j = true)).image cls).card ≤ k) :
∃ word : Fin (k + 2) → Bool,
(∃ j, word j = false) ∧ ∀ r, trace r ≠ word := by
classical
by_cases hinj : Function.Injective cls
· let word : Fin (k + 2) → Bool := fun j => decide (j ≠ 0)
refine ⟨word, ⟨0, by simp [word]⟩, ?_⟩
intro r heq
rcases hsupport r with hall | hsmall
· have hzero := hall 0
rw [heq] at hzero
simp [word] at hzero
· rw [heq] at hsmall
rw [Finset.card_image_of_injective _ hinj] at hsmall
have hset : Finset.univ.filter (fun j : Fin (k + 2) => word j = true) =
Finset.univ.erase 0 := by
ext j
simp [word]
rw [hset] at hsmall
simp at hsmall
· obtain ⟨a, b, hab, hne⟩ := Function.not_injective_iff.mp hinj
have hp : ∃ a b : Fin (k + 2),
a ≠ b ∧ cls a = cls b ∧ key a ≤ key b := by
rcases le_total (key a) (key b) with h | h
· exact ⟨a, b, hne, hab, h⟩
· exact ⟨b, a, hne.symm, hab.symm, h⟩
obtain ⟨a, b, hne, hab, hkey⟩ := hp
let word : Fin (k + 2) → Bool := fun j => decide (j = a)
refine ⟨word, ⟨b, by simp [word, hne.symm]⟩, ?_⟩
intro r heq
have ha : trace r a = true := by simp [heq, word]
have hb := hup r a b hab hkey ha
simp [heq, word, hne.symm] at hb
/-- Coordinatewise form of the missing-word theorem. -/
theorem exists_missing_word_pointwise {ρ : Type uRho} {β : Type uBeta} [DecidableEq β] (k : ℕ)
(cls : Fin (k + 2) → β) (key : Fin (k + 2) → ℕ)
(trace : ρ → Fin (k + 2) → Bool)
(hup : ∀ r a b, cls a = cls b → key a ≤ key b →
trace r a = true → trace r b = true)
(hsupport : ∀ r, (∀ j, trace r j = true) ∨
((Finset.univ.filter (fun j => trace r j = true)).image cls).card ≤ k) :
∃ word : Fin (k + 2) → Bool, ∀ r, ∃ j, trace r j ≠ word j := by
classical
obtain ⟨word, _, hw⟩ := exists_missing_word_with_zero k cls key trace hup hsupport
refine ⟨word, fun r => ?_⟩
by_contra h
push Not at h
exact hw r (funext h)
/-- Matrix-facing form, handling both dummy columns and dummy rows.
No injectivity assumption on the selected columns is needed. -/
theorem matrix_missing_word {R : Type uR} {C : Type uC} {β : Type uBeta} [DecidableEq β] (k : ℕ)
(A : R → C → Bool) (cols : Fin (k + 2) → C)
(cls : C → β) (key : C → ℕ) (dummyRow : R → Prop) (dummyCol : C → Prop)
(hdummyRow : ∀ r, dummyRow r → ∀ c, A r c = true)
(hdummyCol : ∀ c, dummyCol c → ∀ r, A r c = true)
(hup : ∀ r, ¬ dummyRow r → ∀ a b,
¬ dummyCol a → ¬ dummyCol b → cls a = cls b → key a ≤ key b →
A r a = true → A r b = true)
(hsupport : ∀ r, ¬ dummyRow r →
(∀ j, ¬ dummyCol (cols j)) →
((Finset.univ.filter (fun j => A r (cols j) = true)).image
(cls ∘ cols)).card ≤ k) :
∃ word : Fin (k + 2) → Bool, ∀ r, ∃ j, A r (cols j) ≠ word j := by
classical
by_cases hd : ∃ j, dummyCol (cols j)
· obtain ⟨j, hj⟩ := hd
refine ⟨fun _ => false, fun r => ⟨j, ?_⟩⟩
simp [hdummyCol (cols j) hj r]
· push Not at hd
apply exists_missing_word_pointwise k (cls ∘ cols) (key ∘ cols)
(fun r j => A r (cols j))
· intro r a b hab hkey ha
by_cases hr : dummyRow r
· exact hdummyRow r hr (cols b)
· exact hup r hr (cols a) (cols b) (hd a) (hd b) hab hkey ha
· intro r
by_cases hr : dummyRow r
· exact Or.inl (fun j => hdummyRow r hr (cols j))
· exact Or.inr (hsupport r hr hd)
/-- An explicit cover by at most `k` column classes is enough for the
support premise. This form avoids cardinal computations on selected columns. -/
theorem matrix_missing_word_of_class_cover {R : Type uR} {C : Type uC} {β : Type uBeta} [DecidableEq β] (k : ℕ)
(A : R → C → Bool) (cols : Fin (k + 2) → C)
(cls : C → β) (key : C → ℕ) (dummyRow : R → Prop) (dummyCol : C → Prop)
(hdummyRow : ∀ r, dummyRow r → ∀ c, A r c = true)
(hdummyCol : ∀ c, dummyCol c → ∀ r, A r c = true)
(hup : ∀ r, ¬ dummyRow r → ∀ a b,
¬ dummyCol a → ¬ dummyCol b → cls a = cls b → key a ≤ key b →
A r a = true → A r b = true)
(hcover : ∀ r, ¬ dummyRow r → ∃ S : Finset β, S.card ≤ k ∧
∀ c, ¬ dummyCol c → A r c = true → cls c ∈ S) :
∃ word : Fin (k + 2) → Bool, ∀ r, ∃ j, A r (cols j) ≠ word j := by
classical
apply matrix_missing_word k A cols cls key dummyRow dummyCol hdummyRow hdummyCol hup
intro r hr hcols
obtain ⟨S, hS, hmem⟩ := hcover r hr
apply le_trans (Finset.card_le_card ?_) hS
intro c hc
obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hc
exact hmem (cols j) (hcols j) (Finset.mem_filter.mp hj).2
end Problem348.DirectNonshattering
end OAI
|