Lean / Reader
Lean reader

LeanResult.lean

160 lines12 declarationsno sorryimports LeanFixedSum LeanTraceProduct LeanTraceFiber

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.

  1. import LeanFixedSum
  2. import LeanTraceProduct
  3. import LeanTraceFiber
  4. noncomputable section
  5. namespace SplitSandpile
  6. open Finset
  7. def uncolored {n d : ℕ} (o : Order) (g : Gaps n d) :=
  8. (coloredTrace o g).map (fun c ↦ c.1+c.2)
  9. open Classical in
  10. def profileSet (o : Order) (n d : ℕ) (w : List ℕ) : Finset (Gaps n d) :=
  11. univ.filter fun g ↦ Sorted g ∧ finishes o g ∧ uncolored o g = w
  12. lemma uncolored_valid {n d : ℕ} (o : Order) (g : Gaps n d) (hf : finishes o g) :
  13. (∀ j ∈ uncolored o g, 0<j) ∧ (uncolored o g).sum=n+d := by
  14. constructor
  15. · intro j hj
  16. obtain ⟨c,hc,rfl⟩ := List.mem_map.mp hj
  17. exact trace_positive o g hf c hc
  18. · have hend := trace_endpoint o g hf
  19. simp only [prefixState_end,Prod.mk.injEq] at hend
  20. simp only [uncolored,List.sum_map_add,hend.1,hend.2]
  21. private def fixedWeight (o : Order) (q : ℝ) (cs : List Counts) :=
  22. match o with
  23. | .cti => fixedCT q 1 true 1 cs
  24. | .itc => fixedIT q 1 1 cs
  25. theorem profile_generating {n d : ℕ} (o : Order) (w : List ℕ) (hw : ∀ j∈w,0<j)
  26. (hsum : w.sum=n+d) {q : ℝ} (hq : 1<q) :
  27. (∑ g ∈ profileSet o n d w, q^(level g)) =
  28. ∑ cs ∈ (refinements w).filter (fun cs ↦ cliqueCount cs=n), fixedWeight o q cs := by
  29. classical
  30. let S := profileSet o n d w
  31. let T := (refinements w).filter (fun cs ↦ cliqueCount cs=n)
  32. have hmap (g : Gaps n d) (hg : g∈S) : coloredTrace o g ∈ T := by
  33. obtain ⟨_,hf,he⟩ : Sorted g ∧ finishes o g ∧ uncolored o g=w := by simpa [S,profileSet] using hg
  34. have hh := trace_endpoint o g hf
  35. rw [prefixState_end,Prod.mk.injEq] at hh
  36. exact mem_filter.mpr ⟨(mem_refinements ..).mpr he,hh.1⟩
  37. change (∑ g ∈ S, q^(level g)) = ∑ cs ∈ T, _
  38. rw [← sum_fiberwise_of_maps_to hmap]
  39. apply sum_congr rfl
  40. intro cs hcs
  41. obtain ⟨hc,hn⟩ := mem_filter.mp hcs
  42. have hcw := (mem_refinements ..).mp hc
  43. have hpos (c : Counts) (h : c∈cs) : 0<c.1+c.2 := hw _ (hcw ▸ List.mem_map_of_mem h)
  44. have htot := congrArg List.sum hcw
  45. rw [List.sum_map_add,hsum] at htot
  46. change (cs.map Prod.fst).sum=n at hn
  47. have hend : prefixState cs cs.length=(n,d) := by
  48. rw [prefixState_end,Prod.mk.injEq]
  49. exact ⟨hn,by omega⟩
  50. have hmem (g : Gaps n d) : g ∈ S.filter (fun g ↦ coloredTrace o g=cs) ↔
  51. HasProfile o g (prefixState cs) cs.length := by
  52. simp only [S,profileSet,mem_filter,mem_univ,true_and,HasProfile]
  53. constructor
  54. · rintro ⟨⟨hs,hf,_⟩,he⟩
  55. exact ⟨hs,(trace_fiber_iff o g cs hpos hend).mp ⟨hf,he⟩⟩
  56. · rintro ⟨hs,ht⟩
  57. obtain ⟨hf,he⟩ := (trace_fiber_iff o g cs hpos hend).mpr ht
  58. exact ⟨⟨hs,hf,by simpa only [uncolored,he] using hcw⟩,he⟩
  59. calc
  60. _ = ∑ g : ProfileFiber (n:=n) (d:=d) o (prefixState cs) cs.length, q^(level g.val) :=
  61. Finset.sum_subtype _ hmem _
  62. _ = ∏ i : Fin cs.length, shapeFactor q o (prefixState cs) i :=
  63. fixed_profile_sum o _ _ (prefixState_monotone cs) (prefixState_zero cs) hend hq
  64. _ = _ := by cases o <;> first | exact prefix_product_cti q cs | exact prefix_product_itc q cs
  65. theorem profile_generating_eq (n d : ℕ) (w : List ℕ) {q : ℝ} (hq : 1<q) :
  66. (∑ g ∈ profileSet .cti n d w, q^(level g)) = ∑ g ∈ profileSet .itc n d w, q^(level g) := by
  67. classical
  68. by_cases hv : (∀ j ∈ w, 0<j) ∧ w.sum=n+d
  69. · rw [profile_generating _ _ hv.1 hv.2 hq,profile_generating _ _ hv.1 hv.2 hq]
  70. exact colored_profile_clique_count hq w hv.1 n
  71. · have hempty (o : Order) : profileSet o n d w = ∅ := by
  72. apply eq_empty_iff_forall_notMem.mpr
  73. intro g hg
  74. obtain ⟨_,hf,he⟩ : Sorted g ∧ finishes o g ∧ uncolored o g=w := by simpa [profileSet] using hg
  75. exact hv (he ▸ uncolored_valid o g hf)
  76. simp [hempty]
  77. theorem card_by_level {α : Type*} (s t : Finset α) (f : α→ℕ)
  78. (h : ∀ q : ℝ, 1<q → ∑ i ∈ s, q^(f i) = ∑ i ∈ t, q^(f i)) (ell : ℕ) :
  79. (s.filter (fun i ↦ f i=ell)).card = (t.filter (fun i ↦ f i=ell)).card := by
  80. classical
  81. let p := fun (u : Finset α) ↦ ∑ i ∈ u, Polynomial.monomial (f i) (1:ℝ)
  82. have he : p s = p t := by
  83. apply Polynomial.eq_of_infinite_eval_eq
  84. apply (Set.Ioi_infinite (1:ℝ)).mono
  85. intro q hq
  86. simpa [p,Polynomial.eval_finsetSum,Polynomial.eval_monomial] using h q hq
  87. have hc := congrArg (fun a : Polynomial ℝ ↦ a.coeff ell) he
  88. simp only [p,Polynomial.finsetSum_coeff,Polynomial.coeff_monomial] at hc
  89. simp only [Finset.card_filter]
  90. exact_mod_cast hc
  91. /-- Equidistribution for every complete ordered list of wave totals and level. -/
  92. theorem equidistribution_profile (n d ell : ℕ) (w : List ℕ) :
  93. ((profileSet .cti n d w).filter (fun g ↦ level g=ell)).card =
  94. ((profileSet .itc n d w).filter (fun g ↦ level g=ell)).card :=
  95. card_by_level _ _ _ (fun _ h ↦ profile_generating_eq n d w h) ell
  96. def listDelay (N : ℕ) (w : List ℕ) : ℕ :=
  97. ∑ i ∈ range N, i * (w[i]?).getD 0
  98. theorem delay_as_list {n d : ℕ} (o : Order) (g : Gaps n d) (hf : finishes o g) :
  99. delay o g = listDelay (n+d) (uncolored o g) := by
  100. apply sum_congr rfl
  101. intro i _
  102. by_cases hi : i < (coloredTrace o g).length
  103. · simp only [uncolored,List.getElem?_map,List.getElem?_eq_getElem hi,
  104. Option.map_some,Option.getD_some,coloredTrace_get]
  105. · have hlen : burnLength o g ≤ i := by simpa using (Nat.le_of_not_gt hi)
  106. have hfull (j : ℕ) (hj : burnLength o g ≤ j) : afterRound o g j = (n,d) := by
  107. apply le_antisymm (after_bound ..)
  108. calc
  109. (n,d) = afterRound o g (burnLength o g) := (first_finish o g hf).1.symm
  110. _ ≤ _ := after_mono_all o g hj
  111. simp [uncolored,List.getElem?_eq_none (Nat.le_of_not_gt hi),wave,hfull i hlen,
  112. hfull (i+1) (by omega)]
  113. theorem joint_from_sets (o : Order) (n d ell r : ℕ) (W : Finset (List ℕ))
  114. (hW : ∀ g : Gaps n d, uncolored o g ∈ W) :
  115. joint o n d ell r = ∑ w ∈ W.filter (fun w ↦ listDelay (n+d) w=r),
  116. ((profileSet o n d w).filter (fun g ↦ level g = ell)).card := by
  117. classical
  118. let s := univ.filter (fun g : Gaps n d ↦ Sorted g ∧ finishes o g ∧ level g=ell)
  119. let t := W.filter (fun w ↦ listDelay (n+d) w=r)
  120. have h := Finset.sum_card_fiberwise_eq_card_filter s t (uncolored o)
  121. have h1 (w : List ℕ) : (s.filter (fun g ↦ uncolored o g=w)).card =
  122. ((profileSet o n d w).filter (fun g ↦ level g=ell)).card := by
  123. congr 1
  124. ext g
  125. simp [s,profileSet,and_assoc,and_left_comm,and_comm]
  126. have h2 : (s.filter (fun g ↦ uncolored o g∈t)).card = joint o n d ell r := by
  127. congr 1
  128. ext g
  129. simp only [s,t,mem_filter,mem_univ,true_and,hW]
  130. constructor
  131. · rintro ⟨⟨hs,hf,hl⟩,hd⟩
  132. exact ⟨hs,hf,hl,(delay_as_list o g hf).trans hd⟩
  133. · rintro ⟨hs,hf,hl,hd⟩
  134. exact ⟨⟨hs,hf,hl⟩,(delay_as_list o g hf).symm.trans hd⟩
  135. simpa only [h1,h2,t] using h.symm
  136. /-- Conjecture 6.1 of Derycke, Dukes and Le Borgne, coefficient by coefficient,
  137. on sorted stable gap configurations burnt by the two actual schedules. -/
  138. theorem cti_itc_equidistribution (n d ell r : ℕ) : joint .cti n d ell r = joint .itc n d ell r := by
  139. classical
  140. let W := univ.image (@uncolored n d .cti) ∪ univ.image (@uncolored n d .itc)
  141. have hC (g : Gaps n d) : uncolored .cti g∈W := mem_union_left _ (mem_image_of_mem _ (mem_univ g))
  142. have hI (g : Gaps n d) : uncolored .itc g∈W := mem_union_right _ (mem_image_of_mem _ (mem_univ g))
  143. rw [joint_from_sets _ _ _ _ _ W hC,joint_from_sets _ _ _ _ _ W hI]
  144. exact sum_congr rfl (fun w _ ↦ equidistribution_profile n d ell w)
  145. end SplitSandpile