Lean / Reader
Lean readerSharedColour.lean
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.
import SharpParitynamespace ParityPalettesdef hasShared (n w : Nat) (side : Bool) (c : Fin 4) (both : Bool) (r : CrossRow) : Bool :=let length := (n+1-side.toNat)/2let a := parPos r side / 2let x := endDigit length w a == c.vallet y := endDigit length w (a+r.2) == c.valif both then x && y else x || ytheorem hasShared_rename (p : Fin 4 → Fin 4) (hp : Function.Injective p)(n w : Nat) (side : Bool) (c : Fin 4) (both : Bool) (r : CrossRow) (hr : r ∈ crossRows n) :hasShared n (rename p ((n+1-side.toNat)/2) w) side (p c) both r =hasShared n w side c both r := byobtain ⟨_,ho,hb⟩ := crossBounds hrhave hidx : (parPos r side)/2+r.2 < (n+1-side.toNat)/2 := bycases side <;> simp [parPos] <;> split <;> omegahave hc : (p c).val = permDigit p c.val := by simp [permDigit, Nat.mod_eq_of_lt c.isLt]simp only [hasShared,endDigit,hc]rw [rename_digit,rename_digit,perm_eq _ hp _ _ (digit_lt _ _) c.isLt,perm_eq _ hp _ _ (digit_lt _ _) c.isLt] <;> omegadef marks (n w : Nat) (side : Bool) (c : Fin 4) : Nat × Nat :=(sig (hasShared n w side c true) (crossRows n),sig (hasShared n w side c false) (crossRows n))theorem marks_rename (p : Fin 4 → Fin 4) (hp : Function.Injective p)(n w : Nat) (side : Bool) (c : Fin 4) :marks n (rename p ((n+1-side.toNat)/2) w) side (p c) = marks n w side c := byexact Prod.ext (sig_congr _ _ _ (hasShared_rename p hp n w side c true))(sig_congr _ _ _ (hasShared_rename p hp n w side c false))def info (n w : Nat) (side : Bool) : Nat × List (Nat × Nat) :=(eqMask n w side, (List.finRange 4).map (marks n w side))def incompatible35 : Bool :=let left := (layer 14).map (fun w => info 35 w false)let right := (layer 13).map (fun w => info 35 w true)left.all fun l => right.all fun r =>(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)theorem table35 : incompatible35 = true := by native_decidetheorem overlap_of_ne_zero {α : Type} (f g : α → Bool) (xs : List α)(h : sig f xs &&& sig g xs ≠ 0) : ∃ t ∈ xs, f t = true ∧ g t = true := byby_contra! h'exact h (and_zero_of_avoids _ _ _ (by simpa using h'))theorem forcedPair35 (left right : Nat) (a b : Fin 4) (hl : legal 18 left = true)(hr : legal 17 right = true) (wl : left < 4^18) (wr : right < 4^17) :∃ r ∈ crossRows 35,(sameAt 35 left false r = true ∧ sameAt 35 right true r = true) ∨(hasShared 35 left false a true r = true ∧ hasShared 35 right true b false r = true) ∨(hasShared 35 left false a false r = true ∧ hasShared 35 right true b true r = true) := byobtain ⟨p,hp,lp⟩ := normalize 14 left hl wlobtain ⟨q,hq,rq⟩ := normalize 13 right hr wrhave t := table35unfold incompatible35 at tsimp only [List.all_eq_true,List.mem_map,forall_exists_index,and_imp,forall_apply_eq_imp_iff₂,Bool.or_eq_true,bne_iff_ne] at trcases t _ lp _ rq with separate | shared· change eqMask 35 (rename p ((35+1-Bool.false.toNat)/2) left) false &&&eqMask 35 (rename q ((35+1-Bool.true.toNat)/2) right) true ≠ 0 at separaterw [eqMask_rename p hp, eqMask_rename q hq] at separateobtain ⟨r, hr, h⟩ := overlap_of_ne_zero _ _ _ separateexact ⟨r,hr,Or.inl h⟩· simp only [info,List.mem_map,forall_exists_index,and_imp,List.mem_finRange, forall_const] at sharedhave hh := shared _ (p a) rfl _ (q b) rflchange (marks 35 (rename p ((35+1-Bool.false.toNat)/2) left) false (p a)).1 &&&(marks 35 (rename q ((35+1-Bool.true.toNat)/2) right) true (q b)).2 ≠ 0 ∨(marks 35 (rename p ((35+1-Bool.false.toNat)/2) left) false (p a)).2 &&&(marks 35 (rename q ((35+1-Bool.true.toNat)/2) right) true (q b)).1 ≠ 0 at hhrw [marks_rename p hp,marks_rename q hq] at hhrcases hh with h | h· obtain ⟨r, hr, hv⟩ := overlap_of_ne_zero _ _ _ hexact ⟨r,hr,Or.inr (Or.inl hv)⟩· obtain ⟨r, hr, hv⟩ := overlap_of_ne_zero _ _ _ hexact ⟨r,hr,Or.inr (Or.inr hv)⟩end ParityPalettes