Lean / Reader
Lean reader

ArbitraryInsertion.lean

74 lines5 declarationsno sorryimports Insertion

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports Insertion, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import Insertion
  2. namespace ProgressionColours.Insertion
  3. set_option maxRecDepth 10000
  4. set_option maxHeartbeats 1500000
  5. private theorem new_obstructions : ∀ p : Fin 78, ∃ q ∈ ([A,B,C] : List Query),
  6. low (insertAt p 7 q.1) (insertAt p 7 (q.1.val+q.2.val)) (insertAt p 7 (q.1.val+2*q.2.val))
  7. (insertAt p 7 (q.1.val+3*q.2.val))=true := by
  8. have t : ∀ p : Fin 78,
  9. (fun q : Query => low (insertAt p 7 q.1) (insertAt p 7 (q.1.val+q.2.val))
  10. (insertAt p 7 (q.1.val+2*q.2.val)) (insertAt p 7 (q.1.val+3*q.2.val))) A = true ∨
  11. (fun q : Query => low (insertAt p 7 q.1) (insertAt p 7 (q.1.val+q.2.val))
  12. (insertAt p 7 (q.1.val+2*q.2.val)) (insertAt p 7 (q.1.val+3*q.2.val))) B = true ∨
  13. (fun q : Query => low (insertAt p 7 q.1) (insertAt p 7 (q.1.val+q.2.val))
  14. (insertAt p 7 (q.1.val+2*q.2.val)) (insertAt p 7 (q.1.val+3*q.2.val))) C = true := by decide
  15. intro p
  16. rcases t p with ha|hb|hc
  17. · exact ⟨A,by simp,ha⟩
  18. · exact ⟨B,by simp,hb⟩
  19. · exact ⟨C,by simp,hc⟩
  20. private theorem four_low {u v w z : ℕ} (h : low u v w z=true) :
  21. ∃ a b, (u=a ∨ u=b) ∧ (v=a ∨ v=b) ∧ (w=a ∨ w=b) ∧ (z=a ∨ z=b) := by
  22. simp [low] at h
  23. by_cases hv : u=v
  24. · by_cases hw : u=w
  25. · exact ⟨u,z,by grind⟩
  26. · exact ⟨u,w,by grind⟩
  27. · exact ⟨u,v,by grind⟩
  28. private theorem spare_invalid (p : Fin 78) : ¬ Valid 78 2 (insertAt p 7) := by
  29. intro hv
  30. obtain ⟨q,hq,hl⟩ := new_obstructions p
  31. have bounds : 0<q.2.val ∧ q.1.val+3*q.2.val<78 := by
  32. simp only [List.mem_cons,List.not_mem_nil,or_false] at hq
  33. rcases hq with rfl|rfl|rfl <;> decide
  34. obtain ⟨u,v,h⟩ := four_low hl
  35. obtain ⟨x,hx,hu,hv'⟩ := hv _ _ bounds.1 bounds.2 u v
  36. obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hx
  37. have := Finset.mem_range.mp hj
  38. have dis : j=0 ∨ j=1 ∨ j=2 ∨ j=3 := by omega
  39. rcases dis with rfl|rfl|rfl|rfl <;> simp_all
  40. private theorem old_small (i : ℕ) : old i<7 := by
  41. by_cases hi : i<77
  42. · exact (by decide : ∀ j : Fin 77, old j.val<7) ⟨i,hi⟩
  43. · have hs : word.size=77 := by decide
  44. have ho : word[i]?=none := Array.getElem?_eq_none (by omega)
  45. simp [old,ho]
  46. theorem insertion_any_colour (p : Fin 78) (col : ℕ) : ¬ Valid 78 2 (insertAt p col) := by
  47. by_cases h : col<7
  48. · exact no_single_insertion p ⟨col,h⟩
  49. intro hv
  50. let relabel (x : ℕ) := if x=7 then col else x
  51. have eq (i : ℕ) : insertAt p col i = relabel (insertAt p 7 i) := by
  52. have keep (j : ℕ) : relabel (old j) = old j := by
  53. have ne : old j≠7 := by have := old_small j;omega
  54. simp [relabel,ne]
  55. by_cases hlt : i<p
  56. · simp [insertAt,hlt,keep]
  57. · by_cases he : i=p
  58. · simp [insertAt,he,relabel]
  59. · simp [insertAt,hlt,he,keep]
  60. apply spare_invalid p
  61. intro a d hd hi u v
  62. obtain ⟨x,hx,hu,hv'⟩ := hv a d hd hi (relabel u) (relabel v)
  63. rw [eq] at hu hv'
  64. exact ⟨x,hx,fun h => hu (congrArg relabel h),fun h => hv' (congrArg relabel h)⟩
  65. end ProgressionColours.Insertion