math / data /lean /OAI /Combinatorics /MatrixRemoval /DirectNonshattering.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
12.2 kB
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