Lean / Reader
Lean reader

SharedColour.lean

82 lines9 declarations1 × sorry / admit / native_decideimports SharpParity

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

  1. import SharpParity
  2. namespace ParityPalettes
  3. def hasShared (n w : Nat) (side : Bool) (c : Fin 4) (both : Bool) (r : CrossRow) : Bool :=
  4. let length := (n+1-side.toNat)/2
  5. let a := parPos r side / 2
  6. let x := endDigit length w a == c.val
  7. let y := endDigit length w (a+r.2) == c.val
  8. if both then x && y else x || y
  9. theorem hasShared_rename (p : Fin 4 → Fin 4) (hp : Function.Injective p)
  10. (n w : Nat) (side : Bool) (c : Fin 4) (both : Bool) (r : CrossRow) (hr : r ∈ crossRows n) :
  11. hasShared n (rename p ((n+1-side.toNat)/2) w) side (p c) both r =
  12. hasShared n w side c both r := by
  13. obtain ⟨_,ho,hb⟩ := crossBounds hr
  14. have hidx : (parPos r side)/2+r.2 < (n+1-side.toNat)/2 := by
  15. cases side <;> simp [parPos] <;> split <;> omega
  16. have hc : (p c).val = permDigit p c.val := by simp [permDigit, Nat.mod_eq_of_lt c.isLt]
  17. simp only [hasShared,endDigit,hc]
  18. rw [rename_digit,rename_digit,perm_eq _ hp _ _ (digit_lt _ _) c.isLt,
  19. perm_eq _ hp _ _ (digit_lt _ _) c.isLt] <;> omega
  20. def marks (n w : Nat) (side : Bool) (c : Fin 4) : Nat × Nat :=
  21. (sig (hasShared n w side c true) (crossRows n),sig (hasShared n w side c false) (crossRows n))
  22. theorem marks_rename (p : Fin 4 → Fin 4) (hp : Function.Injective p)
  23. (n w : Nat) (side : Bool) (c : Fin 4) :
  24. marks n (rename p ((n+1-side.toNat)/2) w) side (p c) = marks n w side c := by
  25. exact Prod.ext (sig_congr _ _ _ (hasShared_rename p hp n w side c true))
  26. (sig_congr _ _ _ (hasShared_rename p hp n w side c false))
  27. def info (n w : Nat) (side : Bool) : Nat × List (Nat × Nat) :=
  28. (eqMask n w side, (List.finRange 4).map (marks n w side))
  29. def incompatible35 : Bool :=
  30. let left := (layer 14).map (fun w => info 35 w false)
  31. let right := (layer 13).map (fun w => info 35 w true)
  32. left.all fun l => right.all fun r =>
  33. (l.1 &&& r.1 != 0) || l.2.all (fun a => r.2.all fun b => a.1 &&& b.2 != 0 || a.2 &&& b.1 != 0)
  34. theorem table35 : incompatible35 = true := by native_decide
  35. theorem overlap_of_ne_zero {α : Type} (f g : α → Bool) (xs : List α)
  36. (h : sig f xs &&& sig g xs ≠ 0) : ∃ t ∈ xs, f t = true ∧ g t = true := by
  37. by_contra! h'
  38. exact h (and_zero_of_avoids _ _ _ (by simpa using h'))
  39. theorem forcedPair35 (left right : Nat) (a b : Fin 4) (hl : legal 18 left = true)
  40. (hr : legal 17 right = true) (wl : left < 4^18) (wr : right < 4^17) :
  41. ∃ r ∈ crossRows 35,
  42. (sameAt 35 left false r = true ∧ sameAt 35 right true r = true) ∨
  43. (hasShared 35 left false a true r = true ∧ hasShared 35 right true b false r = true) ∨
  44. (hasShared 35 left false a false r = true ∧ hasShared 35 right true b true r = true) := by
  45. obtain ⟨p,hp,lp⟩ := normalize 14 left hl wl
  46. obtain ⟨q,hq,rq⟩ := normalize 13 right hr wr
  47. have t := table35
  48. unfold incompatible35 at t
  49. simp only [List.all_eq_true,List.mem_map,forall_exists_index,and_imp,
  50. forall_apply_eq_imp_iff₂,Bool.or_eq_true,bne_iff_ne] at t
  51. rcases t _ lp _ rq with separate | shared
  52. · change eqMask 35 (rename p ((35+1-Bool.false.toNat)/2) left) false &&&
  53. eqMask 35 (rename q ((35+1-Bool.true.toNat)/2) right) true ≠ 0 at separate
  54. rw [eqMask_rename p hp, eqMask_rename q hq] at separate
  55. obtain ⟨r, hr, h⟩ := overlap_of_ne_zero _ _ _ separate
  56. exact ⟨r,hr,Or.inl h⟩
  57. · simp only [info,List.mem_map,forall_exists_index,and_imp,
  58. List.mem_finRange, forall_const] at shared
  59. have hh := shared _ (p a) rfl _ (q b) rfl
  60. change (marks 35 (rename p ((35+1-Bool.false.toNat)/2) left) false (p a)).1 &&&
  61. (marks 35 (rename q ((35+1-Bool.true.toNat)/2) right) true (q b)).2 ≠ 0 ∨
  62. (marks 35 (rename p ((35+1-Bool.false.toNat)/2) left) false (p a)).2 &&&
  63. (marks 35 (rename q ((35+1-Bool.true.toNat)/2) right) true (q b)).1 ≠ 0 at hh
  64. rw [marks_rename p hp,marks_rename q hq] at hh
  65. rcases hh with h | h
  66. · obtain ⟨r, hr, hv⟩ := overlap_of_ne_zero _ _ _ h
  67. exact ⟨r,hr,Or.inr (Or.inl hv)⟩
  68. · obtain ⟨r, hr, hv⟩ := overlap_of_ne_zero _ _ _ h
  69. exact ⟨r,hr,Or.inr (Or.inr hv)⟩
  70. end ParityPalettes