Lean / Reader
Lean reader

SharpParity.lean

45 lines6 declarations1 × sorry / admit / native_decideimports PaletteCross

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

  1. import PaletteCross
  2. namespace ParityPalettes
  3. theorem sig_congr {α : Type} (f g : α → Bool) (xs : List α)
  4. (h : ∀ x ∈ xs, f x = g x) : sig f xs = sig g xs := by
  5. induction xs with
  6. | nil => rfl
  7. | cons x xs ih =>
  8. simp only [sig]
  9. rw [h x (by simp),ih (fun t ht => h t (by simp [ht]))]
  10. def eqMask (n w : Nat) (side : Bool) : Nat := sig (sameAt n w side) (crossRows n)
  11. theorem eqMask_rename (p : Fin 4 → Fin 4) (hp : Function.Injective p)
  12. (n w : Nat) (side : Bool) :
  13. eqMask n (rename p ((n+1-side.toNat)/2) w) side = eqMask n w side :=
  14. sig_congr _ _ _ (same_rename p hp n w side)
  15. def incompatible37 : Bool :=
  16. let left := (layer 15).map (fun w => eqMask 37 w false)
  17. let right := (layer 14).map (fun w => eqMask 37 w true)
  18. left.all fun l => right.all fun r => l &&& r != 0
  19. theorem table37 : incompatible37 = true := by native_decide
  20. theorem forcedPair37 (left right : Nat) (hl : legal 19 left = true)
  21. (hr : legal 18 right = true) (wl : left < 4^19) (wr : right < 4^18) :
  22. ∃ row ∈ crossRows 37, sameAt 37 left false row = true ∧ sameAt 37 right true row = true := by
  23. obtain ⟨p,hp,lp⟩ := normalize 15 left hl wl
  24. obtain ⟨q,hq,rq⟩ := normalize 14 right hr wr
  25. have t := table37
  26. unfold incompatible37 at t
  27. simp only [List.all_eq_true,List.mem_map,forall_exists_index,and_imp,
  28. forall_apply_eq_imp_iff₂, bne_iff_ne] at t
  29. have hx := t _ lp _ rq
  30. change eqMask 37 (rename p ((37+1-Bool.false.toNat)/2) left) false &&&
  31. eqMask 37 (rename q ((37+1-Bool.true.toNat)/2) right) true ≠ 0 at hx
  32. rw [eqMask_rename p hp, eqMask_rename q hq] at hx
  33. by_contra! h
  34. apply hx
  35. exact and_zero_of_avoids _ _ _ (by simpa using h)
  36. end ParityPalettes