Download data/lean/OAI/Combinatorics/MatrixRemoval/DirectNonshattering.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatrixRemoval/DirectNonshattering.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/MatrixRemoval/DirectNonshattering.lean
-
curl -L -o DirectNonshattering.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatrixRemoval/DirectNonshattering.lean
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 | |