Lean / Reader
Lean readerProof.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports OMAStatements.S_mo_52886, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import OMAStatements.S_mo_52886namespace OMA.S_mo_52886private def dot (p q : Point) : Int := p.1*q.1+p.2*q.2theorem actDir_parity : ∀ g d : Fin 8, (actDir g d).val % 2 = d.val % 2 := by decidetheorem nonidentity_rotation_fixes_no_dir :∀ g d : Fin 8, g ≠ 0 → g.val < 4 → actDir g d ≠ d := by decidetheorem reflection_fixed_dirs :∀ g d : Fin 8, 4 ≤ g.val → (actDir g d = d ↔ d.val = g.val-4 ∨ d.val = g.val) := bydecidetheorem fixed_directions_parallel : ∀ (g d e : Fin 8), g ≠ 0 →actDir g d = d → actDir g e = e → d = e ∨ plus (point d) (point e) = (0,0) := by decideprivate theorem point_action : ∀ g d, point (actDir g d) = actPoint g (point d) := by decideprivate theorem action_origin (g : Fin 8) : actPoint g (0,0) = (0,0) := byunfold actPointsplit <;> decideprivate theorem action_add (g : Fin 8) (p q : Point) :actPoint g (plus p q) = plus (actPoint g p) (actPoint g q) := byunfold actPointsplit <;> simp [plus, Int.neg_add]private theorem action_injective (g : Fin 8) (p q : Point) :actPoint g p = actPoint g q → p = q := byrcases p with ⟨x,y⟩rcases q with ⟨z,t⟩unfold actPointsplit <;> simp <;> grindprivate theorem plus_injective (p q r : Point) : plus p q = plus p r → q = r := byrcases p with ⟨x,y⟩rcases q with ⟨a,b⟩rcases r with ⟨c,d⟩simp [plus]private theorem nodup_map_iff (f : α → β) (hf : ∀ p q, f p = f q → p = q) (s : List α) :(s.map f).Nodup ↔ s.Nodup := byinduction s with| nil => simp| cons a s ih =>simp only [List.map_cons, List.nodup_cons, List.mem_map, ih]constructor· rintro ⟨hn,hs⟩exact ⟨fun ha => hn ⟨a,ha,rfl⟩, hs⟩· rintro ⟨hn,hs⟩exact ⟨fun ⟨x,hx,heq⟩ => hn (hf x a heq ▸ hx), hs⟩theorem vertices_actWord (g : Fin 8) (w : List (Fin 8)) :vertices (actWord g w) = (vertices w).map (actPoint g) := byinduction w with| nil => simp [actWord,vertices,action_origin]| cons d w ih =>change (0,0) :: (vertices (actWord g w)).map (plus (point (actDir g d))) =((0,0) :: (vertices w).map (plus (point d))).map (actPoint g)rw [ih, List.map_cons, action_origin, List.map_map, List.map_map, point_action]congr 1apply List.map_congr_leftintro p hpexact (action_add g (point d) p).symmtheorem selfAvoid_actWord (g : Fin 8) (w : List (Fin 8)) :selfAvoid (actWord g w) ↔ selfAvoid w := byunfold selfAvoidrw [vertices_actWord]exact nodup_map_iff _ (action_injective g) _theorem selfAvoid_tail (d : Fin 8) (w : List (Fin 8)) :selfAvoid (d :: w) → selfAvoid w := byintro hexact (nodup_map_iff _ (plus_injective (point d)) _).mp (List.nodup_cons.mp h).2private theorem origin_mem (w : List (Fin 8)) : ((0,0) : Point) ∈ vertices w := bycases w <;> simp [vertices]private theorem no_immediate_return (d e : Fin 8) (w : List (Fin 8))(h : selfAvoid (d :: e :: w)) : plus (point d) (point e) ≠ (0,0) := byintro heapply (List.nodup_cons.mp h).1apply List.mem_map.mprrefine ⟨point e, ?_, he⟩change point e ∈ (0,0) :: (vertices w).map (plus (point e))apply List.mem_cons_of_memexact List.mem_map.mpr ⟨(0,0),origin_mem w,by simp [plus]⟩private theorem fixed_cons {g : Fin 8} (hg : g ≠ 0) (rest : List (Fin 8)) (d : Fin 8)(h : selfAvoid (d :: rest)) (hf : actWord g (d :: rest) = d :: rest) :d :: rest = List.replicate (rest.length+1) d := byinduction rest generalizing d with| nil => rfl| cons e w ih =>have hfix : actDir g d = d ∧ actWord g (e :: w) = e :: w := List.cons.inj hfhave efix : actDir g e = e := (List.cons.inj hfix.2).1have de : d = e := (fixed_directions_parallel g d e hg hfix.1 efix).resolve_right(no_immediate_return d e w h)subst ehave tail := ih d (selfAvoid_tail _ _ h) hfix.2change d :: d :: w = d :: List.replicate (w.length+1) dexact congrArg (List.cons d) tailtheorem fixed_word_iff (g : Fin 8) (w : List (Fin 8)) (hg : g ≠ 0) (hw : w ≠ [])(h : selfAvoid w) :actWord g w = w ↔ ∃ d, actDir g d = d ∧ w = List.replicate w.length d := bycases w with| nil => contradiction| cons d w =>constructor· intro hfexact ⟨d,(List.cons.inj hf).1,fixed_cons hg w d h hf⟩· rintro ⟨e,he,hw'⟩rw [hw']simp [actWord,he]private theorem unit_dot_pos : ∀ d : Fin 8, 0 < dot (point d) (point d) := by decideprivate theorem dot_plus (p q r : Point) : dot p (plus q r) = dot p q + dot p r := bysimp [dot,plus,Int.mul_add]omegaprivate theorem repeat_forward (d : Fin 8) (n : Nat) :∀ p ∈ vertices (List.replicate n d), 0 ≤ dot (point d) p := byinduction n with| zero => simp [vertices,dot]| succ n ih =>intro p hprw [List.replicate_succ] at hprcases List.mem_cons.mp hp with h | h· subst p; simp [dot]· obtain ⟨q,hq,rfl⟩ := List.mem_map.mp hrw [dot_plus]have := ih q hqhave := unit_dot_pos domegatheorem selfAvoid_replicate (n : Nat) (d : Fin 8) : selfAvoid (List.replicate n d) := byinduction n with| zero => simp [selfAvoid,vertices]| succ n ih =>rw [List.replicate_succ]apply List.nodup_cons.mprconstructor· intro hzobtain ⟨p,hp,heq⟩ := List.mem_map.mp hzhave hd := dot_plus (point d) (point d) prw [heq] at hdhave h0 : dot (point d) (0,0) = 0 := by simp [dot]have := unit_dot_pos dhave := repeat_forward d n p hpomega· exact (nodup_map_iff _ (plus_injective (point d)) _).mpr ihprivate def product (g h : Fin 8) : Fin 8 :=⟨((g.val % 4 + (if g.val < 4 then h.val%4 else 4-h.val%4)) % 4 +(if (g.val < 4) ↔ (h.val < 4) then 0 else 4)) % 8, by omega⟩private def inverse (g : Fin 8) : Fin 8 :=⟨if g.val < 4 then (4-g.val)%4 else g.val, by split <;> omega⟩private theorem dir_product : ∀ g h d, actDir (product g h) d = actDir g (actDir h d) := by decideprivate theorem dir_zero : ∀ d, actDir 0 d = d := by decideprivate theorem prod_inverse : ∀ g, product (inverse g) g = 0 := by decideprivate theorem prod_inverse' : ∀ g, product g (inverse g) = 0 := by decideprivate theorem all_directions : ∀ g : Fin 8, g ∈ directions := by decideprivate theorem dirs_nodup : directions.Nodup := by decideprivate theorem left_permute : ∀ g, (directions.map (product g)).Perm directions := by decideprivate theorem word_product (g h : Fin 8) (w : Word) :actWord (product g h) w = actWord g (actWord h w) := byinduction w with| nil => rfl| cons d w ih => simpa only [actWord, List.map_cons, dir_product] using congrArg (actDir g (actDir h d) :: ·) ihprivate theorem word_zero (w : Word) : actWord 0 w = w := byrw [actWord, show actDir 0 = id from funext dir_zero, List.map_id]private theorem inject_word (g : Fin 8) (x y : Word) (h : actWord g x = actWord g y) : x=y := bysimpa only [← word_product, prod_inverse, word_zero] using congrArg (actWord (inverse g)) hprivate theorem same_iff (w v : Word) : sameShape w v ↔ ∃ g, actWord g w = v := bysimp [sameShape, List.any_eq_true, all_directions]private theorem same_action (w v : Word) (g : Fin 8) : sameShape (actWord g w) v = sameShape w v := byapply Bool.eq_iff_iff.mprrw [same_iff, same_iff]constructor· rintro ⟨h,rfl⟩exact ⟨product h g, word_product ..⟩· rintro ⟨h,rfl⟩refine ⟨product h (inverse g), ?_⟩rw [word_product, ← word_product (inverse g) g, prod_inverse, word_zero]private theorem rep_action (ws : List Word) (w : Word) (g : Fin 8) :representative ws (actWord g w) = representative ws w := byunfold representativerw [show sameShape (actWord g w) = sameShape w from funext (fun v => same_action w v g)]private theorem rep_exists (ws : List Word) (w : Word) (hw : w ∈ ws) :∃ g, representative ws w = some (actWord g w) := bycases he : representative ws w with| none =>have hh := (List.find?_eq_none.mp he) w hwexact False.elim (hh ((same_iff ..).2 ⟨0, word_zero w⟩))| some v =>obtain ⟨g,rfl⟩ := (same_iff w v).1 (List.find?_some he)exact ⟨g,rfl⟩theorem mem_walks (w : Word) (a b : Nat) :w ∈ walks a b ↔ w.length = a+b ∧ selfAvoid w ∧ diagonalCount w=b := byhave enum (n : Nat) (x : Word) : x ∈ allWords n ↔ x.length = n := byinduction n generalizing x with| zero => simp [allWords]| succ n ih =>cases x with| nil => simp [allWords]| cons d x => simp [allWords, List.mem_flatMap, all_directions, ih]simp [walks, enum, selfAvoid]private theorem nodup_map_inj (xs : List α) (f : α → β) (hi : ∀ x y, f x = f y → x=y)(hn : xs.Nodup) : (xs.map f).Nodup := byinduction xs with| nil => simp| cons x xs ih =>rcases List.nodup_cons.mp hn with ⟨hx,ht⟩apply List.nodup_cons.mprconstructor· rintro hlobtain ⟨y,hy,he⟩ := List.mem_map.mp hlexact hx (hi y x he ▸ hy)· exact ih httheorem walks_nodup (a b : Nat) : (walks a b).Nodup := byhave enum (n : Nat) : (allWords n).Nodup := byinduction n with| zero => simp [allWords]| succ n ih =>apply List.pairwise_flatMap.mprconstructor· intro d hdexact nodup_map_inj _ _ (fun _ _ h => (List.cons.inj h).2) ih· apply List.Pairwise.imp _ dirs_nodupintro x y h v hv w hwobtain ⟨v',_,rfl⟩ := List.mem_map.mp hvobtain ⟨w',_,rfl⟩ := List.mem_map.mp hwexact fun he => h (List.cons.inj he).1exact (enum _).filter _private theorem diagonal_action (g : Fin 8) (w : Word) : diagonalCount (actWord g w) = diagonalCount w := bysimp [diagonalCount, actWord, Function.comp_def, actDir_parity]private theorem walk_action (g : Fin 8) (w : Word) (a b : Nat) :actWord g w ∈ walks a b ↔ w ∈ walks a b := bysimp only [mem_walks, selfAvoid_actWord, diagonal_action]simp [actWord]private theorem perm_walks (g : Fin 8) (a b : Nat) :((walks a b).map (actWord g)).Perm (walks a b) := byapply (List.perm_ext_iff_of_nodup (nodup_map_inj _ _ (inject_word g) (walks_nodup ..)) (walks_nodup ..)).2intro wrw [List.mem_map]constructor· rintro ⟨u,hu,rfl⟩exact (walk_action ..).2 hu· intro hwrefine ⟨actWord (inverse g) w,(walk_action ..).2 hw,?_⟩rw [← word_product, prod_inverse', word_zero]private theorem representative_multiplicity (ws : List Word) (w : Word) (hw : w ∈ ws) :directions.countP (fun g => isRepresentative ws (actWord g w)) =directions.countP (fun g => actWord g w == w) := byobtain ⟨h,hh⟩ := rep_exists ws w hwrw [← (left_permute h).countP_eq (fun g => isRepresentative ws (actWord g w)), List.countP_map]apply List.countP_congrintro g _simp only [Function.comp_apply, isRepresentative, rep_action, hh, beq_iff_eq, Option.some.injEq, word_product]exact ⟨fun e => (inject_word h _ _ e).symm, fun e => congrArg (actWord h) e.symm⟩/-- Each anchored legal walk shares its square-symmetry orbit with exactly oneword counted by the representative predicate. -/theorem unique_representative (a b : Nat) (w : Word) (hw : w ∈ walks a b) :∃ v, v ∈ walks a b ∧ sameShape w v ∧ isRepresentative (walks a b) v ∧∀ u, sameShape w u → isRepresentative (walks a b) u → u = v := byobtain ⟨g,hg⟩ := rep_exists (walks a b) w hwrefine ⟨actWord g w,(walk_action ..).2 hw,(same_iff ..).2 ⟨g,rfl⟩,?_,?_⟩· simp only [isRepresentative, rep_action, hg, beq_self_eq_true]· intro u hu hrobtain ⟨h,rfl⟩ := (same_iff ..).1 husimp only [isRepresentative, rep_action, hg, beq_iff_eq, Option.some.injEq] at hrexact hr.symmprivate theorem swap_counts (xs : List α) (ys : List β) (p : α → β → Bool) :(xs.map (fun x => ys.countP (p x))).sum =(ys.map (fun y => xs.countP (fun x => p x y))).sum := byinduction xs with| nil =>simp only [List.map_nil, List.sum_nil, List.countP_nil]induction ys with| nil => rfl| cons _ ys ih => simpa only [List.map_cons, List.sum_cons, Nat.zero_add] using ih| cons x xs ih =>simp only [List.map_cons, List.sum_cons, ih]clear ihinduction ys with| nil => simp| cons y ys hy =>simp only [List.map_cons, List.sum_cons, List.countP_cons] at hy ⊢split <;> omegaprivate theorem burnside (a b : Nat) :8 * shapeCount a b =((walks a b).map (fun w => directions.countP (fun g => actWord g w == w))).sum := bylet ws := walks a blet r := isRepresentative wshave hon (g : Fin 8) : ws.countP (fun w => r (actWord g w)) = ws.countP r := bysimpa only [List.countP_map, Function.comp_def] using (perm_walks g a b).countP_eq rcalc8 * shapeCount a b = (directions.map (fun g => ws.countP (fun w => r (actWord g w)))).sum := bysimp only [hon, directions, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil]change 8 * ws.countP r = _omega_ = (ws.map (fun w => directions.countP (fun g => r (actWord g w)))).sum := swap_counts .._ = _ := congrArg List.sum (List.map_congr_left fun w hw => representative_multiplicity ws w hw)private def straight (w : Word) : Bool :=directions.any (fun d => List.replicate w.length d == w)private theorem straight_iff (w : Word) : straight w ↔ ∃ d, w = List.replicate w.length d := bysimp only [straight, List.any_eq_true, all_directions, true_and, beq_iff_eq]exact exists_congr fun _ => eq_commprivate theorem rep_dir_inj (n : Nat) (hn : n ≠ 0) (x y : Fin 8) :List.replicate n x = List.replicate n y → x=y := bycases n with| zero => contradiction| succ n => exact fun h => (List.cons.inj h).1private theorem rep_stab (n : Nat) (hn : n ≠ 0) (d : Fin 8) :directions.countP (fun g => actWord g (List.replicate n d) == List.replicate n d) = 2 := byhave table : ∀ d : Fin 8, directions.countP (fun g => actDir g d == d) = 2 := by deciderw [← table d]apply List.countP_congrintro g _simp only [actWord, List.map_replicate, beq_iff_eq]exact ⟨rep_dir_inj n hn _ _, congrArg (List.replicate n)⟩private theorem stab_size (w : Word) (hn : w ≠ []) (ha : selfAvoid w) :directions.countP (fun g => actWord g w == w) = 1 + (if straight w then 1 else 0) := byby_cases ht : straight w· obtain ⟨d,he⟩ := (straight_iff w).1 htsimp only [ht, if_true, Nat.reduceAdd]have hlen : w.length ≠ 0 := by simpa using hnsimpa only [← he] using rep_stab w.length hlen d· rw [if_neg ht, Nat.add_zero]have table : directions.countP (fun g => g == 0) = 1 := by deciderw [← table]apply List.countP_congrintro g _simp only [beq_iff_eq]constructor· intro heby_cases hg : g=0· exact hg· obtain ⟨d,_,hh⟩ := (fixed_word_iff g w hg hn ha).1 heexact False.elim (ht ((straight_iff w).2 ⟨d,hh⟩))· rintro rflexact word_zero wprivate theorem sum_stab (a b : Nat) (hn : a+b ≠ 0) :8*shapeCount a b = rootedCount a b + (walks a b).countP straight := byrw [burnside]have changeWeight : (walks a b).map (fun w => directions.countP (fun g => actWord g w == w)) =(walks a b).map (fun w => 1 + (if straight w then 1 else 0)) := byapply List.map_congr_leftintro w hwrcases (mem_walks ..).1 hw with ⟨hl,ha,_⟩apply stab_size w _ harintro rflexact hn hl.symmrw [changeWeight]unfold rootedCountgeneralize walks a b = wsinduction ws with| nil => simp| cons w ws ih =>simp only [List.map_cons, List.sum_cons, List.length_cons, List.countP_cons] at *split <;> omegaprivate theorem count_straight (a b : Nat) (hn : a+b ≠ 0) :(walks a b).countP straight = if a=0 ∨ b=0 then 4 else 0 := bylet n := a+blet ds := directions.filter (fun d => diagonalCount (List.replicate n d) == b)have hp : ((walks a b).filter straight).Perm (ds.map (List.replicate n)) := byapply (List.perm_ext_iff_of_nodup ((walks_nodup a b).filter _)(nodup_map_inj _ _ (rep_dir_inj n hn) (dirs_nodup.filter _))).2intro wsimp only [List.mem_filter, mem_walks, straight_iff, List.mem_map]constructor· rintro ⟨⟨hl,_,hc⟩,d,hd⟩rw [hl] at hdrefine ⟨d,⟨all_directions d,?_⟩,hd.symm⟩change (diagonalCount (List.replicate (a+b) d) == b) = truesimpa only [← hd, beq_iff_eq] using hc· rintro ⟨d,hm,rfl⟩obtain ⟨_,hc⟩ := hmexact ⟨⟨List.length_replicate, selfAvoid_replicate .., beq_iff_eq.mp hc⟩,d,by simp⟩rw [List.countP_eq_length_filter, hp.length_eq, List.length_map]unfold ds nhave table : ∀ (x y : Bool),(directions.filter (fun d => if d.val % 2 == 1 then x else y)).length =(if x then 4 else 0) + (if y then 4 else 0) := by decidehave counts (d : Fin 8) : (diagonalCount (List.replicate (a+b) d) == b) =(if d.val % 2 == 1 then a+b == b else 0 == b) := byunfold diagonalCountrw [List.countP_replicate]split <;> rflrw [show (fun d => diagonalCount (List.replicate (a+b) d) == b) = _ from funext counts, table]simp only [beq_iff_eq]split <;> split <;> split <;> omega/-- Exact number of square-symmetry classes of anchored vertex-self-avoiding walks,with prescribed counts of axial and diagonal edges. -/theorem orbit_formula (a b : Nat) :8 * shapeCount a b = rootedCount a b + correction a b := byby_cases hn : a+b = 0· obtain ⟨rfl,rfl⟩ : a=0 ∧ b=0 := by omegadecide· rw [sum_stab a b hn, count_straight a b hn]simp only [correction, if_neg hn]theorem shapeCount_eq (a b : Nat) :shapeCount a b = (rootedCount a b + correction a b) / 8 := byhave h := orbit_formula a bomegaend OMA.S_mo_52886theorem OMA.solution : OMA.S_mo_52886.claim := byexact OMA.S_mo_52886.shapeCount_eq