Lean / Reader
Lean readerInsertion.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports ColourRestrictions, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import ColourRestrictionsnamespace ProgressionColours.Insertionset_option maxHeartbeats 1500000set_option maxRecDepth 10000/-- The published `k7_N77` witness of Arhan Canli, with zero-based positions. -/def word : Array Nat := #[1, 1, 6, 2, 1, 1, 0, 4, 4, 6, 3, 5, 3, 4, 5, 2, 1, 2, 0, 3, 3, 4, 2, 2, 5, 0, 5, 6, 6, 0, 4, 3, 4, 6, 3, 1, 5, 1, 3, 5, 2, 0, 2, 1, 1, 0, 4, 2, 2, 5, 4, 5, 6, 6, 0, 4, 1, 4, 6, 3, 1, 5, 0, 4, 0, 3, 3, 1, 2, 6, 2, 1, 6, 2, 5, 2, 0]def old (i : ℕ) : ℕ := word[i]?.getD 0def insertAt (p col i : ℕ) : ℕ := if i<p then old i else if i=p then col else old (i-1)abbrev Query := Fin 78 × Fin 26def low (a b c d : ℕ) : Bool :=!((a != b && a != c && b != c) || (a != b && a != d && b != d) ||(a != c && a != d && c != d) || (b != c && b != d && c != d))def Fails (p : Fin 78) (col : Fin 7) (q : Query) : Bool :=let a := q.1.vallet d := q.2.vallet f := insertAt p.val col.val0<d && a+3*d<78 && low (f a) (f (a+d)) (f (a+2*d)) (f (a+3*d))def Ensemble (S : Finset Query) : Prop := ∀ p c, ∃ q∈S, Fails p c q=truedef A : Query := (2,25)def B : Query := (0,25)def C : Query := (13,17)def D : Query := (0,20)theorem three_obstructions : Ensemble {A,B,C} := byhave h : ∀ (p : Fin 78) (c : Fin 7),Fails p c A=true ∨ Fails p c B=true ∨ Fails p c C=true := by decideintro p crcases h p c with ha | hb | hc· exact ⟨A,by simp,ha⟩· exact ⟨B,by simp,hb⟩· exact ⟨C,by simp,hc⟩private theorem unique_end (q : Query) (hf : Fails 77 4 q=true) : q=A := byexact (by decide : ∀ i : Fin 78, ∀ j : Fin 26, Fails 77 4 (i,j)=true → (i,j)=A) q.1 q.2 hfprivate theorem front (q : Query) (hf : Fails 0 5 q=true) : q=B ∨ q=D := byexact (by decide : ∀ i : Fin 78, ∀ j : Fin 26, Fails 0 5 (i,j)=true → (i,j)=B ∨ (i,j)=D) q.1 q.2 hftheorem obstruction_minimum (S : Finset Query) (h : Ensemble S) : 3≤S.card := byobtain ⟨a,ha,fa⟩ := h 77 4obtain ⟨b,hb,fb⟩ := h 0 5obtain ⟨c,hc,fc⟩ := h 35 4have ea := unique_end a fahave eb := front b fbhave good : Fails 35 4 A=false ∧ Fails 35 4 B=false ∧ Fails 35 4 D=false := by decidehave hab : a≠b := by rcases eb with rfl|rfl <;> rw [ea] <;> decidehave hac : a≠c := by rintro rfl; rw [ea,good.1] at fc;contradictionhave hbc : b≠c := by rintro rfl;rcases eb with rfl|rfl <;> simp [good.2.1,good.2.2] at fchave sub : ({a,b,c} : Finset Query) ⊆ S := byintro x hxsimp only [Finset.mem_insert,Finset.mem_singleton] at hxrcases hx with rfl | rfl | rfl <;> assumptionsimpa [hab,hac,hbc] using Finset.card_le_card subtheorem old_valid_checks : ∀ (a : Fin 77) (d : Fin 26),0<d.val → a.val+3*d.val<77 → low (old a) (old (a+d.val)) (old (a+2*d.val)) (old (a+3*d.val))=false := by decideprivate theorem low_cover (a b c d : ℕ) (hl : low a b c d=true) :∃ u v : ℕ, (a=u ∨ a=v) ∧ (b=u ∨ b=v) ∧ (c=u ∨ c=v) ∧ (d=u ∨ d=v) := bysimp [low] at hlby_cases hab : a=b· by_cases hac : a=c· exact ⟨a,d,by grind⟩· exact ⟨a,c,by grind⟩· exact ⟨a,b,by grind⟩theorem no_single_insertion (p : Fin 78) (col : Fin 7) : ¬ Valid 78 2 (insertAt p col) := byintro hvobtain ⟨q,_,hq⟩ := three_obstructions p colsimp only [Fails,Bool.and_eq_true,decide_eq_true_eq] at hqset a := q.1.valset d := q.2.vallet f := insertAt p.val col.valobtain ⟨u,v,hh⟩ := low_cover _ _ _ _ hq.2obtain ⟨x,hx,hu,hv'⟩ := hv a d hq.1.1 hq.1.2 u vobtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hxhave jbound := Finset.mem_range.mp hjchange (f a=u ∨ f a=v) ∧ (f (a+d)=u ∨ f (a+d)=v) ∧ (f (a+2*d)=u ∨ f (a+2*d)=v) ∧ (f (a+3*d)=u ∨ f (a+3*d)=v) at hhchange f (a+j*d) ≠ u at huchange f (a+j*d) ≠ v at hv'have dis : j=0 ∨ j=1 ∨ j=2 ∨ j=3 := by omegarcases dis with rfl|rfl|rfl|rfl <;> simp_allend ProgressionColours.Insertion