Lean / Reader
Lean reader

AffineColours.lean

100 lines19 declarationsno sorryimports Mathlib.Tactic Mathlib.GroupTheory.Perm.Fin
  1. import Mathlib.Tactic
  2. import Mathlib.GroupTheory.Perm.Fin
  3. namespace AffineColours
  4. def equalPairs {α : Type*} [DecidableEq α] (a b c d : α) : ℕ :=
  5. (if a=b then 1 else 0) + (if a=c then 1 else 0) + (if a=d then 1 else 0) +
  6. (if b=c then 1 else 0) + (if b=d then 1 else 0) + (if c=d then 1 else 0)
  7. theorem pairCriterion {α : Type*} [DecidableEq α] (a b c d : α) :
  8. 3 ≤ ({a,b,c,d} : Finset α).card ↔ equalPairs a b c d ≤ 1 := by
  9. by_cases hab : a=b <;> by_cases hac : a=c <;> by_cases had : a=d <;>
  10. by_cases hbc : b=c <;> by_cases hbd : b=d <;> by_cases hcd : c=d <;>
  11. simp_all [equalPairs, Finset.card_insert_of_notMem]
  12. def packed : ℕ := 4249435753119052576007099789721455590363978824005653704617637945869838442270659337976577868545
  13. def shade (i : ℕ) : ℕ := (packed >>> (4*i)) % 16
  14. def rotate (c : ℕ) := if c=0 then 0 else 1 + 3*((c-1)/3) + c%3
  15. def valid (w : ℕ → ℕ) := ∀ a d : ℕ, 0<d → a+3*d<78 →
  16. 3 ≤ ({w a,w (a+d),w (a+2*d),w (a+3*d)} : Finset ℕ).card
  17. set_option maxHeartbeats 4000000
  18. set_option maxRecDepth 20000
  19. theorem tenRange : ∀ i : Fin 78, shade i < 10 := by decide
  20. theorem tenEquivariant : ∀ i : Fin 78, shade ((23*(i.val+1))%79-1) = rotate (shade i) := by decide
  21. theorem rotateOrderThree : ∀ i : Fin 10, rotate (rotate (rotate i)) = i := by decide
  22. theorem tenCheck : ∀ a : Fin 78, ∀ d : Fin 26, 0<d.val → a.val+3*d.val<78 →
  23. equalPairs (shade a) (shade (a.val+d.val)) (shade (a.val+2*d.val)) (shade (a.val+3*d.val)) ≤ 1 := by decide
  24. theorem tenValid : valid shade := by
  25. intro a d hd hb
  26. exact (pairCriterion ..).2 (tenCheck ⟨a,by omega⟩ ⟨d,by omega⟩ hd hb)
  27. theorem affineCubeParameters : ∀ a b : Fin 78,
  28. ((a.val^3)%78=1 ∧ ((a.val^2+a.val+1)*b.val)%78=0) ↔
  29. (a.val=1 ∧ (b.val=0 ∨ b.val=26 ∨ b.val=52)) ∨ ((a.val=55 ∨ a.val=61) ∧ b.val%2=0) := by decide
  30. theorem affineThirteenthMultiplier : ∀ a : Fin 78, (a.val^13)%78=1 ↔ a.val=1 := by decide
  31. theorem thirteenthShift : ∀ b : Fin 78, (13*b.val)%78=0 ↔ b.val%6=0 := by decide
  32. theorem paletteOrderThirteen {k : ℕ} (hk : k<13) (σ : Equiv.Perm (Fin k)) (hσ : σ^13=1) : σ=1 := by
  33. have hdiv := orderOf_dvd_of_pow_eq_one hσ
  34. rcases (Nat.dvd_prime (show Nat.Prime 13 by decide)).mp hdiv with h | h
  35. · exact orderOf_eq_one_iff.mp h
  36. · have hc : orderOf σ ∣ Fintype.card (Equiv.Perm (Fin k)) := orderOf_dvd_card
  37. rw [h, Fintype.card_perm, Fintype.card_fin] at hc
  38. exact False.elim ((show ¬13 ∣ k.factorial from fun hd => by interval_cases k <;> norm_num [Nat.factorial] at hd) hc)
  39. /-- The order-thirteen multiplier 18 forces a monochromatic triple in the row 62,63,64,65. -/
  40. theorem noThirteenPrime {w : ℕ → ℕ} (hw : valid w)
  41. (hinv : ∀ i : Fin 78, w ((18*(i.val+1))%79-1) = w i) : False := by
  42. have step (i : ℕ) (h : i<78) : w ((18*(i+1))%79-1) = w i := hinv ⟨i,h⟩
  43. have he : w 61 = w 63 := calc
  44. w 61 = w 20 := step 20 (by decide)
  45. _ = w 66 := step 66 (by decide)
  46. _ = w 51 := step 51 (by decide)
  47. _ = w 37 := step 37 (by decide)
  48. _ = w 45 := step 45 (by decide)
  49. _ = w 63 := step 63 (by decide)
  50. have hf : w 63 = w 64 := step 64 (by decide)
  51. have hr := hw 61 1 (by decide) (by decide)
  52. change 3 ≤ ({w 61,w 62,w 63,w 64} : Finset ℕ).card at hr
  53. have hc := (pairCriterion (w 61) (w 62) (w 63) (w 64)).mp hr
  54. rw [he, hf] at hc
  55. simp [equalPairs] at hc
  56. theorem noThirteenShift {w : ℕ → ℕ} (hw : valid w)
  57. (hinv : ∀ i : Fin 78, w ((i.val+6)%78) = w i) : False := by
  58. have h₁ : w 6 = w 0 := hinv 0
  59. have h₂ : w 12 = w 6 := hinv 6
  60. have h₃ : w 18 = w 12 := hinv 12
  61. have hr := hw 0 6 (by decide) (by decide)
  62. change 3 ≤ ({w 0,w 6,w 12,w 18} : Finset ℕ).card at hr
  63. rw [h₃,h₂,h₁] at hr
  64. simp at hr
  65. theorem fourthOrderParameters : ∀ a b : Fin 78,
  66. (((a.val^2)%78≠1 ∨ ((a.val+1)*b.val)%78≠0) ∧
  67. (a.val^4)%78=1 ∧ ((a.val+1)*(a.val^2+1)*b.val)%78=0) ↔
  68. a.val=5 ∨ a.val=47 ∨ ((a.val=31 ∨ a.val=73) ∧ b.val%3=0) := by decide
  69. theorem exponentTwoCommutes {G : Type*} [Group G] (h : ∀ x : G, x*x=1) (a b : G) : a*b=b*a := by
  70. have hinv (x : G) : x⁻¹=x := calc
  71. x⁻¹ = x⁻¹*(x*x) := by rw [h]; simp
  72. _ = x := by group
  73. calc
  74. a*b = (a*b)⁻¹ := (hinv _).symm
  75. _ = b⁻¹*a⁻¹ := mul_inv_rev a b
  76. _ = b*a := by rw [hinv,hinv]
  77. end AffineColours