Lean / Reader
Lean reader

Insertion.lean

95 lines18 declarationsno sorryimports ColourRestrictions

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.

  1. import ColourRestrictions
  2. namespace ProgressionColours.Insertion
  3. set_option maxHeartbeats 1500000
  4. set_option maxRecDepth 10000
  5. /-- The published `k7_N77` witness of Arhan Canli, with zero-based positions. -/
  6. 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]
  7. def old (i : ℕ) : ℕ := word[i]?.getD 0
  8. def insertAt (p col i : ℕ) : ℕ := if i<p then old i else if i=p then col else old (i-1)
  9. abbrev Query := Fin 78 × Fin 26
  10. def low (a b c d : ℕ) : Bool :=
  11. !((a != b && a != c && b != c) || (a != b && a != d && b != d) ||
  12. (a != c && a != d && c != d) || (b != c && b != d && c != d))
  13. def Fails (p : Fin 78) (col : Fin 7) (q : Query) : Bool :=
  14. let a := q.1.val
  15. let d := q.2.val
  16. let f := insertAt p.val col.val
  17. 0<d && a+3*d<78 && low (f a) (f (a+d)) (f (a+2*d)) (f (a+3*d))
  18. def Ensemble (S : Finset Query) : Prop := ∀ p c, ∃ q∈S, Fails p c q=true
  19. def A : Query := (2,25)
  20. def B : Query := (0,25)
  21. def C : Query := (13,17)
  22. def D : Query := (0,20)
  23. theorem three_obstructions : Ensemble {A,B,C} := by
  24. have h : ∀ (p : Fin 78) (c : Fin 7),
  25. Fails p c A=true ∨ Fails p c B=true ∨ Fails p c C=true := by decide
  26. intro p c
  27. rcases h p c with ha | hb | hc
  28. · exact ⟨A,by simp,ha⟩
  29. · exact ⟨B,by simp,hb⟩
  30. · exact ⟨C,by simp,hc⟩
  31. private theorem unique_end (q : Query) (hf : Fails 77 4 q=true) : q=A := by
  32. exact (by decide : ∀ i : Fin 78, ∀ j : Fin 26, Fails 77 4 (i,j)=true → (i,j)=A) q.1 q.2 hf
  33. private theorem front (q : Query) (hf : Fails 0 5 q=true) : q=B ∨ q=D := by
  34. exact (by decide : ∀ i : Fin 78, ∀ j : Fin 26, Fails 0 5 (i,j)=true → (i,j)=B ∨ (i,j)=D) q.1 q.2 hf
  35. theorem obstruction_minimum (S : Finset Query) (h : Ensemble S) : 3≤S.card := by
  36. obtain ⟨a,ha,fa⟩ := h 77 4
  37. obtain ⟨b,hb,fb⟩ := h 0 5
  38. obtain ⟨c,hc,fc⟩ := h 35 4
  39. have ea := unique_end a fa
  40. have eb := front b fb
  41. have good : Fails 35 4 A=false ∧ Fails 35 4 B=false ∧ Fails 35 4 D=false := by decide
  42. have hab : a≠b := by rcases eb with rfl|rfl <;> rw [ea] <;> decide
  43. have hac : a≠c := by rintro rfl; rw [ea,good.1] at fc;contradiction
  44. have hbc : b≠c := by rintro rfl;rcases eb with rfl|rfl <;> simp [good.2.1,good.2.2] at fc
  45. have sub : ({a,b,c} : Finset Query) ⊆ S := by
  46. intro x hx
  47. simp only [Finset.mem_insert,Finset.mem_singleton] at hx
  48. rcases hx with rfl | rfl | rfl <;> assumption
  49. simpa [hab,hac,hbc] using Finset.card_le_card sub
  50. theorem old_valid_checks : ∀ (a : Fin 77) (d : Fin 26),
  51. 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 decide
  52. private theorem low_cover (a b c d : ℕ) (hl : low a b c d=true) :
  53. ∃ u v : ℕ, (a=u ∨ a=v) ∧ (b=u ∨ b=v) ∧ (c=u ∨ c=v) ∧ (d=u ∨ d=v) := by
  54. simp [low] at hl
  55. by_cases hab : a=b
  56. · by_cases hac : a=c
  57. · exact ⟨a,d,by grind⟩
  58. · exact ⟨a,c,by grind⟩
  59. · exact ⟨a,b,by grind⟩
  60. theorem no_single_insertion (p : Fin 78) (col : Fin 7) : ¬ Valid 78 2 (insertAt p col) := by
  61. intro hv
  62. obtain ⟨q,_,hq⟩ := three_obstructions p col
  63. simp only [Fails,Bool.and_eq_true,decide_eq_true_eq] at hq
  64. set a := q.1.val
  65. set d := q.2.val
  66. let f := insertAt p.val col.val
  67. obtain ⟨u,v,hh⟩ := low_cover _ _ _ _ hq.2
  68. obtain ⟨x,hx,hu,hv'⟩ := hv a d hq.1.1 hq.1.2 u v
  69. obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hx
  70. have jbound := Finset.mem_range.mp hj
  71. change (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 hh
  72. change f (a+j*d) ≠ u at hu
  73. change f (a+j*d) ≠ v at hv'
  74. have dis : j=0 ∨ j=1 ∨ j=2 ∨ j=3 := by omega
  75. rcases dis with rfl|rfl|rfl|rfl <;> simp_all
  76. end ProgressionColours.Insertion