Lean / Reader
Lean readerLeanResult.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports LeanFixedSum, LeanTraceProduct, LeanTraceFiber, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import LeanFixedSumimport LeanTraceProductimport LeanTraceFibernoncomputable sectionnamespace SplitSandpileopen Finsetdef uncolored {n d : ℕ} (o : Order) (g : Gaps n d) :=(coloredTrace o g).map (fun c ↦ c.1+c.2)open Classical indef profileSet (o : Order) (n d : ℕ) (w : List ℕ) : Finset (Gaps n d) :=univ.filter fun g ↦ Sorted g ∧ finishes o g ∧ uncolored o g = wlemma uncolored_valid {n d : ℕ} (o : Order) (g : Gaps n d) (hf : finishes o g) :(∀ j ∈ uncolored o g, 0<j) ∧ (uncolored o g).sum=n+d := byconstructor· intro j hjobtain ⟨c,hc,rfl⟩ := List.mem_map.mp hjexact trace_positive o g hf c hc· have hend := trace_endpoint o g hfsimp only [prefixState_end,Prod.mk.injEq] at hendsimp only [uncolored,List.sum_map_add,hend.1,hend.2]private def fixedWeight (o : Order) (q : ℝ) (cs : List Counts) :=match o with| .cti => fixedCT q 1 true 1 cs| .itc => fixedIT q 1 1 cstheorem profile_generating {n d : ℕ} (o : Order) (w : List ℕ) (hw : ∀ j∈w,0<j)(hsum : w.sum=n+d) {q : ℝ} (hq : 1<q) :(∑ g ∈ profileSet o n d w, q^(level g)) =∑ cs ∈ (refinements w).filter (fun cs ↦ cliqueCount cs=n), fixedWeight o q cs := byclassicallet S := profileSet o n d wlet T := (refinements w).filter (fun cs ↦ cliqueCount cs=n)have hmap (g : Gaps n d) (hg : g∈S) : coloredTrace o g ∈ T := byobtain ⟨_,hf,he⟩ : Sorted g ∧ finishes o g ∧ uncolored o g=w := by simpa [S,profileSet] using hghave hh := trace_endpoint o g hfrw [prefixState_end,Prod.mk.injEq] at hhexact mem_filter.mpr ⟨(mem_refinements ..).mpr he,hh.1⟩change (∑ g ∈ S, q^(level g)) = ∑ cs ∈ T, _rw [← sum_fiberwise_of_maps_to hmap]apply sum_congr rflintro cs hcsobtain ⟨hc,hn⟩ := mem_filter.mp hcshave hcw := (mem_refinements ..).mp hchave hpos (c : Counts) (h : c∈cs) : 0<c.1+c.2 := hw _ (hcw ▸ List.mem_map_of_mem h)have htot := congrArg List.sum hcwrw [List.sum_map_add,hsum] at htotchange (cs.map Prod.fst).sum=n at hnhave hend : prefixState cs cs.length=(n,d) := byrw [prefixState_end,Prod.mk.injEq]exact ⟨hn,by omega⟩have hmem (g : Gaps n d) : g ∈ S.filter (fun g ↦ coloredTrace o g=cs) ↔HasProfile o g (prefixState cs) cs.length := bysimp only [S,profileSet,mem_filter,mem_univ,true_and,HasProfile]constructor· rintro ⟨⟨hs,hf,_⟩,he⟩exact ⟨hs,(trace_fiber_iff o g cs hpos hend).mp ⟨hf,he⟩⟩· rintro ⟨hs,ht⟩obtain ⟨hf,he⟩ := (trace_fiber_iff o g cs hpos hend).mpr htexact ⟨⟨hs,hf,by simpa only [uncolored,he] using hcw⟩,he⟩calc_ = ∑ g : ProfileFiber (n:=n) (d:=d) o (prefixState cs) cs.length, q^(level g.val) :=Finset.sum_subtype _ hmem __ = ∏ i : Fin cs.length, shapeFactor q o (prefixState cs) i :=fixed_profile_sum o _ _ (prefixState_monotone cs) (prefixState_zero cs) hend hq_ = _ := by cases o <;> first | exact prefix_product_cti q cs | exact prefix_product_itc q cstheorem profile_generating_eq (n d : ℕ) (w : List ℕ) {q : ℝ} (hq : 1<q) :(∑ g ∈ profileSet .cti n d w, q^(level g)) = ∑ g ∈ profileSet .itc n d w, q^(level g) := byclassicalby_cases hv : (∀ j ∈ w, 0<j) ∧ w.sum=n+d· rw [profile_generating _ _ hv.1 hv.2 hq,profile_generating _ _ hv.1 hv.2 hq]exact colored_profile_clique_count hq w hv.1 n· have hempty (o : Order) : profileSet o n d w = ∅ := byapply eq_empty_iff_forall_notMem.mprintro g hgobtain ⟨_,hf,he⟩ : Sorted g ∧ finishes o g ∧ uncolored o g=w := by simpa [profileSet] using hgexact hv (he ▸ uncolored_valid o g hf)simp [hempty]theorem card_by_level {α : Type*} (s t : Finset α) (f : α→ℕ)(h : ∀ q : ℝ, 1<q → ∑ i ∈ s, q^(f i) = ∑ i ∈ t, q^(f i)) (ell : ℕ) :(s.filter (fun i ↦ f i=ell)).card = (t.filter (fun i ↦ f i=ell)).card := byclassicallet p := fun (u : Finset α) ↦ ∑ i ∈ u, Polynomial.monomial (f i) (1:ℝ)have he : p s = p t := byapply Polynomial.eq_of_infinite_eval_eqapply (Set.Ioi_infinite (1:ℝ)).monointro q hqsimpa [p,Polynomial.eval_finsetSum,Polynomial.eval_monomial] using h q hqhave hc := congrArg (fun a : Polynomial ℝ ↦ a.coeff ell) hesimp only [p,Polynomial.finsetSum_coeff,Polynomial.coeff_monomial] at hcsimp only [Finset.card_filter]exact_mod_cast hc/-- Equidistribution for every complete ordered list of wave totals and level. -/theorem equidistribution_profile (n d ell : ℕ) (w : List ℕ) :((profileSet .cti n d w).filter (fun g ↦ level g=ell)).card =((profileSet .itc n d w).filter (fun g ↦ level g=ell)).card :=card_by_level _ _ _ (fun _ h ↦ profile_generating_eq n d w h) elldef listDelay (N : ℕ) (w : List ℕ) : ℕ :=∑ i ∈ range N, i * (w[i]?).getD 0theorem delay_as_list {n d : ℕ} (o : Order) (g : Gaps n d) (hf : finishes o g) :delay o g = listDelay (n+d) (uncolored o g) := byapply sum_congr rflintro i _by_cases hi : i < (coloredTrace o g).length· simp only [uncolored,List.getElem?_map,List.getElem?_eq_getElem hi,Option.map_some,Option.getD_some,coloredTrace_get]· have hlen : burnLength o g ≤ i := by simpa using (Nat.le_of_not_gt hi)have hfull (j : ℕ) (hj : burnLength o g ≤ j) : afterRound o g j = (n,d) := byapply le_antisymm (after_bound ..)calc(n,d) = afterRound o g (burnLength o g) := (first_finish o g hf).1.symm_ ≤ _ := after_mono_all o g hjsimp [uncolored,List.getElem?_eq_none (Nat.le_of_not_gt hi),wave,hfull i hlen,hfull (i+1) (by omega)]theorem joint_from_sets (o : Order) (n d ell r : ℕ) (W : Finset (List ℕ))(hW : ∀ g : Gaps n d, uncolored o g ∈ W) :joint o n d ell r = ∑ w ∈ W.filter (fun w ↦ listDelay (n+d) w=r),((profileSet o n d w).filter (fun g ↦ level g = ell)).card := byclassicallet s := univ.filter (fun g : Gaps n d ↦ Sorted g ∧ finishes o g ∧ level g=ell)let t := W.filter (fun w ↦ listDelay (n+d) w=r)have h := Finset.sum_card_fiberwise_eq_card_filter s t (uncolored o)have h1 (w : List ℕ) : (s.filter (fun g ↦ uncolored o g=w)).card =((profileSet o n d w).filter (fun g ↦ level g=ell)).card := bycongr 1ext gsimp [s,profileSet,and_assoc,and_left_comm,and_comm]have h2 : (s.filter (fun g ↦ uncolored o g∈t)).card = joint o n d ell r := bycongr 1ext gsimp only [s,t,mem_filter,mem_univ,true_and,hW]constructor· rintro ⟨⟨hs,hf,hl⟩,hd⟩exact ⟨hs,hf,hl,(delay_as_list o g hf).trans hd⟩· rintro ⟨hs,hf,hl,hd⟩exact ⟨⟨hs,hf,hl⟩,(delay_as_list o g hf).symm.trans hd⟩simpa only [h1,h2,t] using h.symm/-- Conjecture 6.1 of Derycke, Dukes and Le Borgne, coefficient by coefficient,on sorted stable gap configurations burnt by the two actual schedules. -/theorem cti_itc_equidistribution (n d ell r : ℕ) : joint .cti n d ell r = joint .itc n d ell r := byclassicallet W := univ.image (@uncolored n d .cti) ∪ univ.image (@uncolored n d .itc)have hC (g : Gaps n d) : uncolored .cti g∈W := mem_union_left _ (mem_image_of_mem _ (mem_univ g))have hI (g : Gaps n d) : uncolored .itc g∈W := mem_union_right _ (mem_image_of_mem _ (mem_univ g))rw [joint_from_sets _ _ _ _ _ W hC,joint_from_sets _ _ _ _ _ W hI]exact sum_congr rfl (fun w _ ↦ equidistribution_profile n d ell w)end SplitSandpile