Lean sources / SurfaceBlowup / Recursion / Events.lean

Return and exit events of the blowup recursion

923 lines · 14 public declarations · raw file · declaration index

1/-2Copyright (c) 2026 Asvin G, Claude (Anthropic), GPT-6-Astra (OpenAI). All rights reserved.3Released under Apache 2.0 license as described in the file LICENSE.4Authors: Asvin G, Claude (Anthropic), GPT-6-Astra (OpenAI)5-/6import SurfaceBlowup.Recursion.ChildMembers7 8/-!9# Return and exit events of the blowup recursion10 11For a surface universe, the recursion follows an ideal through successive blowups: at a12single state `single a c` it may return to the same state (self cells) `k` times before13exiting through a non-self cell. This file computes the masses of the exit events (in terms14of the exit law and the return weight), proves measurability of all recursion events, shows15that bad exits and never-returning ideals are null, and concludes by strong induction on the16state rank that the law statement holds for every member of a surface universe.17 18## Main results19 20* `exit_cell_type_mass`, `exit_cell_coeff_nonneg`: mass of the type box of an exit cell.21* `exit_event_zero_mass`, `exit_event_succ_mass`, `return_event_mass`: masses of exit and22  return events.23* `recursion_events_measurable`, `bad_exit_null`, `never_return_null`.24* `recursion_crossing_law`, `recursion_single_law`, `universal_law_statement`: the law.25* `type_event_null_difference`, `etale_type_event_measurable`,26  `unramified_generic_fibre_ascent`.27 28Provenance: `Thm_SurfaceBlowupV2_` nodes `exit_cell_type_mass`, `exit_event_succ_mass`,29`recursion_events_measurable`, `bad_exit_null`, `exit_event_zero_mass`,30`recursion_crossing_step`, `return_event_mass`, `never_return_null`, `recursion_single_step`,31`universal_law_statement`, `type_event_null_difference`, `etale_type_event_measurable`,32`unramified_generic_fibre_ascent`.33-/34 35open scoped BigOperators ENNReal TensorProduct36 37namespace SurfaceBlowup38 39/-! ### Exit cells -/40 41private theorem piFinset_sum_reindex (σ : FactorType) (q : ℚ) {m n : ℕ} (h : m = n)42    (a : Fin n → ℕ × Law) :43    (∑ τ ∈ Fintype.piFinset (fun j : Fin m => ((a (Fin.cast h j)).2.map Prod.fst).toFinset),44      (if σ = ∑ j, scaleType (a (Fin.cast h j)).1 (τ j) then45        ∏ j, (lawCoeff (a (Fin.cast h j)).2 (τ j)).eval (q ^ (a (Fin.cast h j)).1) else 0)) =46    ∑ τ ∈ Fintype.piFinset (fun j : Fin n => ((a j).2.map Prod.fst).toFinset),47      (if σ = ∑ j, scaleType (a j).1 (τ j) then48        ∏ j, (lawCoeff (a j).2 (τ j)).eval (q ^ (a j).1) else 0) := by49  subst h; rfl50 51private theorem lawCoeff_lawProd_descend_eval (l : List (ℕ × State)) (hδ : ∀ z ∈ l, 0 < z.1)52    (σ : FactorType) (q : ℚ) :53    (lawCoeff (lawProd (l.map fun z => lawDescend z.1 (stateLaw z.2))) σ).eval q =54    ∑ τ ∈ Fintype.piFinset (fun j : Fin l.length => ((stateLaw (l.get j).2).map Prod.fst).toFinset),55      (if σ = ∑ j, scaleType (l.get j).1 (τ j) then56        ∏ j, (lawCoeff (stateLaw (l.get j).2) (τ j)).eval (q ^ (l.get j).1) else 0) := by57  have h := law_coeff_prod_descend (l.map fun z => (z.1, stateLaw z.2))58    (by intro z hz; obtain ⟨w, hw, rfl⟩ := List.mem_map.1 hz; exact hδ w hw) σ q59  rw [List.map_map] at h60  rw [show ((fun z : ℕ × Law => lawDescend z.1 z.2) ∘ fun z : ℕ × State => (z.1, stateLaw z.2)) =61    (fun z => lawDescend z.1 (stateLaw z.2)) from rfl] at h62  have hl : (l.map fun z => (z.1, stateLaw z.2)).length = l.length := List.length_map _63  have hg : (l.map fun z => (z.1, stateLaw z.2)).get =64      fun j => ((l.get (Fin.cast hl j)).1, stateLaw (l.get (Fin.cast hl j)).2) := by65    funext j; simp66  rw [hg] at h67  rw [h]68  exact piFinset_sum_reindex σ q hl (fun j => ((l.get j).1, stateLaw (l.get j).2))69 70/-- The residue field of the `j`-th child of a cell has cardinality `q ^ δⱼ`. -/71private theorem child_q_eq_pow (U : SurfaceUniverse) (i : U.ι) (c : (U.M i).cellIndex)72    (j : (U.M i).childIdx c) :73    ((U.M (U.child i c j)).q : ℚ) = ((U.M i).q : ℚ) ^ (((U.M i).childList c).get j).1 := by74  rw [U.child_residue i c j]; push_cast; rfl75 76/-- The children of an exit cell have smaller rank, so they satisfy the law statement. -/77private theorem exit_child_law (U : SurfaceUniverse) (i : U.ι)78    (hIH : ∀ i' : U.ι, (U.M i').s.rank < (U.M i).s.rank → U.LawStatement i') (c : U.exitCells i)79    (j : (U.M i).childIdx c.1) : U.LawStatement (U.child i c.1 j) :=80  hIH _ (by81    rw [U.child_state i c.1 j]82    exact nonself_child_rank_lt _ (U.M i).valid _ c.1.1.2 c.2 _ (List.get_mem _ _))83 84/-- The law coefficients of the children of an exit cell, evaluated at `q ^ δⱼ`, are85nonnegative. -/86private theorem exit_child_coeff_nonneg (U : SurfaceUniverse) (i : U.ι)87    (hIH : ∀ i' : U.ι, (U.M i').s.rank < (U.M i).s.rank → U.LawStatement i') (c : U.exitCells i)88    (j : (U.M i).childIdx c.1) (t : FactorType) :89    0 ≤ (lawCoeff (stateLaw (((U.M i).childList c.1).get j).2) t).eval90      (((U.M i).q : ℚ) ^ (((U.M i).childList c.1).get j).1) := by91  have := ((exit_child_law U i hIH c j).1 t).2.192  rwa [U.child_state i c.1 j, child_q_eq_pow] at this93 94/-- The `σ`-coefficient of the product of the descended children laws of an exit cell is95nonnegative. -/96theorem exit_cell_coeff_nonneg (U : SurfaceUniverse) (i : U.ι)97    (hIH : ∀ i' : U.ι, (U.M i').s.rank < (U.M i).s.rank → U.LawStatement i') (c : U.exitCells i)98    (σ : FactorType) :99    0 ≤ (lawCoeff (lawProd (((U.M i).childList c.1).map fun z ↦ lawDescend z.1 (stateLaw z.2)))100      σ).eval ((U.M i).q : ℚ) := by101  rw [lawCoeff_lawProd_descend_eval ((U.M i).childList c.1)102    (fun z hz ↦ children_residue_degree_pos _ _ _ hz)]103  refine Finset.sum_nonneg fun τ _ ↦ ?_104  split_ifs105  exacts [Finset.prod_nonneg fun j _ ↦ exit_child_coeff_nonneg U i hIH c j (τ j), le_rfl]106 107/-- The child box of an exit cell where the `j`-th child terminates with type `τ j` has mass108`P(d) · vol · ∏ⱼ Cⱼ(τ j)`, with `P(d)` the divisor probability of the cell and `Cⱼ` the law109coefficients of the children evaluated at `q ^ δⱼ`. -/110private theorem exit_child_box_mass (U : SurfaceUniverse) (i : U.ι)111    (hnt : (U.M i).s.terminal = false)112    (hIH : ∀ i' : U.ι, (U.M i').s.rank < (U.M i).s.rank → U.LawStatement i') (c : U.exitCells i)113    (τ : (U.M i).childIdx c.1 → FactorType) :114    (U.M i).μ (U.childBox i c.1 (fun j ↦ U.termTypeEvent (U.child i c.1 j) (τ j))) =115      ENNReal.ofReal ((((divisorProbability (U.M i).s ((U.M i).cellDegree c.1)).eval116        ((U.M i).q : ℚ) * (stateVolume (U.M i).s).eval ((U.M i).q : ℚ) *117        ∏ j, (lawCoeff (stateLaw (((U.M i).childList c.1).get j).2) (τ j)).eval118          (((U.M i).q : ℚ) ^ (((U.M i).childList c.1).get j).1) : ℚ)) : ℝ) := by119  have hq : 2 ≤ (U.M i).q := (universe_basic_facts U i).1120  have hL := exit_child_law U i hIH c121  have hsj : ∀ j, (U.M (U.child i c.1 j)).s = (((U.M i).childList c.1).get j).2 :=122    fun j ↦ U.child_state i c.1 j123  -- child volumes `V j` and child law coefficients `C j`, evaluated at `q ^ δⱼ`124  let V : (U.M i).childIdx c.1 → ℚ := fun j ↦ (stateVolume (((U.M i).childList c.1).get j).2).eval125    (((U.M i).q : ℚ) ^ (((U.M i).childList c.1).get j).1)126  let C : (U.M i).childIdx c.1 → ℚ := fun j ↦127    (lawCoeff (stateLaw (((U.M i).childList c.1).get j).2) (τ j)).eval128      (((U.M i).q : ℚ) ^ (((U.M i).childList c.1).get j).1)129  have hC : ∀ j, 0 ≤ C j := fun j ↦ exit_child_coeff_nonneg U i hIH c j (τ j)130  have hV : ∀ j, 0 < V j := by131    intro j132    have hqc : 2 ≤ (U.M (U.child i c.1 j)).q := U.child_residue i c.1 j ▸ hq.trans133      (Nat.le_self_pow (children_residue_degree_pos _ _ _ (List.get_mem _ _)).ne' _)134    have := (density_value_arith _ hqc (.const 1) (.const 1) (by simp [Expr.eval])135      (by simp [Expr.eval]) 0 _ (U.M (U.child i c.1 j)).valid).2.2.2.2.2.2.1136    rwa [hsj j, child_q_eq_pow] at this137  have hmeas : ∀ j, MeasurableSet (U.termTypeEvent (U.child i c.1 j) (τ j)) :=138    fun j ↦ ((hL j).1 (τ j)).1139  have hmu : ∀ j, (U.M (U.child i c.1 j)).μ (U.termTypeEvent (U.child i c.1 j) (τ j)) =140      ENNReal.ofReal (((C j * V j : ℚ)) : ℝ) := by141    intro j142    have e1 : (lawCoeff (stateLaw (U.M (U.child i c.1 j)).s) (τ j)).eval143        ((U.M (U.child i c.1 j)).q : ℚ) = C j := by rw [hsj j, child_q_eq_pow]144    have e2 : (stateVolume (U.M (U.child i c.1 j)).s).eval ((U.M (U.child i c.1 j)).q : ℚ) =145        V j := by rw [hsj j, child_q_eq_pow]146    rw [((hL j).1 (τ j)).2.2, U.volume]147    simp only [densityValue]148    rw [e1, e2, ← ENNReal.ofReal_mul (by exact_mod_cast hC j)]149    push_cast; rfl150  have hqpos : (0 : ℝ) < ((U.M i).q : ℝ) := by exact_mod_cast (show 0 < (U.M i).q by omega)151  -- the volume ratio `q^{-tri d} · ∏ V j / vol = P(d)`152  have hratio : ((U.M i).q : ℚ)⁻¹ ^ tri ((U.M i).cellDegree c.1) * (∏ j, V j) /153      (stateVolume (U.M i).s).eval ((U.M i).q : ℚ) =154      (divisorProbability (U.M i).s ((U.M i).cellDegree c.1)).eval ((U.M i).q : ℚ) := by155    have hprodV : (((U.M i).childList c.1).map fun z ↦156        (stateVolume z.2).eval (((U.M i).q : ℚ) ^ z.1)).prod = ∏ j, V j := by157      rw [← Fin.prod_univ_fun_getElem]; rfl158    rw [← hprodV]159    exact child_volume_ratio (U.M i).s (U.M i).valid c.1.1.1 c.1.1.2 _ hq160  have hVs := (density_value_arith _ hq (.const 1) (.const 1) (by simp [Expr.eval])161      (by simp [Expr.eval]) 0 _ (U.M i).valid).2.2.2.2.2.2.2162  change (U.M i).μ ((U.M i).cell c.1 ∩ U.Φ i c.1 ⁻¹' Set.pi Set.univ _) = _163  rw [U.Φ_measure i hnt c.1 _ hmeas, Finset.prod_congr rfl (fun j _ ↦ hmu j),164    ← ENNReal.ofReal_prod_of_nonneg (fun j _ ↦ by have := hC j; have := hV j; positivity),165    ← ENNReal.ofReal_natCast, ← ENNReal.ofReal_inv_of_pos hqpos,166    ← ENNReal.ofReal_pow (inv_nonneg.2 hqpos.le), ← ENNReal.ofReal_mul (by positivity), ← hratio]167  congr 1168  push_cast169  rw [Finset.prod_mul_distrib]170  field_simp171  exact mul_comm _ _172 173/-- The type-`σ` box of a cell is the disjoint union, over the child types `τ` adding up to `σ`174(with residue scaling), of the child boxes where the `j`-th child terminates with type `τ j`. -/175private theorem typeBox_measure_eq_tsum (U : SurfaceUniverse) (i : U.ι)176    (hnt : (U.M i).s.terminal = false) (c : (U.M i).cellIndex) (σ : FactorType)177    (hmeas : ∀ j t, MeasurableSet (U.termTypeEvent (U.child i c j) t)) :178    (U.M i).μ (U.typeBox i c σ) = ∑' τ : (U.M i).childIdx c → FactorType,179      if σ = ∑ j, scaleType ((U.M i).childDelta c j) (τ j) then180        (U.M i).μ (U.childBox i c (fun j ↦ U.termTypeEvent (U.child i c j) (τ j))) else 0 := by181  unfold SurfaceUniverse.typeBox182  rw [MeasureTheory.measure_iUnion]183  · congr 1; funext τ184    rw [Set.iUnion_eq_if]185    split_ifs186    · rfl187    · exact MeasureTheory.measure_empty188  · intro τ τ' hne189    rw [Function.onFun, Set.disjoint_left]190    intro J hJ hJ'191    simp only [Set.mem_iUnion] at hJ hJ'192    obtain ⟨_, hJ⟩ := hJ193    obtain ⟨_, hJ'⟩ := hJ'194    obtain ⟨j, hj⟩ := Function.ne_iff.1 hne195    have h1 := hJ.2 j (Set.mem_univ j)196    obtain ⟨σ0, -, huniq⟩ := terminates_type_unique U _ _ h1.2197    exact hj ((huniq _ h1.1.2).trans (huniq _ (hJ'.2 j (Set.mem_univ j)).1.2).symm)198  · exact fun τ ↦ MeasurableSet.iUnion fun _ ↦ U.Φ_measurable i hnt c _ fun j ↦ hmeas j (τ j)199 200/-- Mass of the type-`σ` box of a non-self (exit) cell: the divisor probability of the cell201times the `σ`-coefficient of the product of the descended children laws, times the volume of202the state set. -/203theorem exit_cell_type_mass (U : SurfaceUniverse) (i : U.ι) (hnt : (U.M i).s.terminal = false)204    (hIH : ∀ i' : U.ι, (U.M i').s.rank < (U.M i).s.rank → U.LawStatement i') (c : U.exitCells i)205    (σ : FactorType) :206    (U.M i).μ (U.typeBox i c.1 σ) =207      densityValue (.mul (divisorProbability (U.M i).s ((U.M i).cellDegree c.1))208        (lawCoeff (lawProd (((U.M i).childList c.1).map fun z ↦ lawDescend z.1 (stateLaw z.2))) σ))209        (U.M i).q * (U.M i).μ (U.M i).stateSet := by210  -- sum the child box masses over the finitely many child types with nonzero coefficient211  have hq : 2 ≤ (U.M i).q := (universe_basic_facts U i).1212  set A : ℚ := (divisorProbability (U.M i).s ((U.M i).cellDegree c.1)).eval ((U.M i).q : ℚ) *213    (stateVolume (U.M i).s).eval ((U.M i).q : ℚ) with hAdef214  let C : (U.M i).childIdx c.1 → FactorType → ℚ := fun j t ↦215    (lawCoeff (stateLaw (((U.M i).childList c.1).get j).2) t).eval216      (((U.M i).q : ℚ) ^ (((U.M i).childList c.1).get j).1)217  have hC : ∀ j t, 0 ≤ C j t := exit_child_coeff_nonneg U i hIH c218  have hA : 0 ≤ A := mul_nonneg (divisor_probability_pos _ hq _ _ 2 le_rfl).1.le219    (density_value_arith _ hq (.const 1) (.const 1) (by simp [Expr.eval])220      (by simp [Expr.eval]) 0 _ (U.M i).valid).2.2.2.2.2.2.1.le221  let g : ((U.M i).childIdx c.1 → FactorType) → ℚ := fun τ ↦222    if σ = ∑ j, scaleType ((U.M i).childDelta c.1 j) (τ j) then A * ∏ j, C j (τ j) else 0223  have hg : ∀ τ, 0 ≤ g τ := fun τ ↦ by224    simp only [g]; split_ifs225    exacts [mul_nonneg hA (Finset.prod_nonneg fun j _ ↦ hC j (τ j)), le_rfl]226  have hstep1 : (U.M i).μ (U.typeBox i c.1 σ) = ∑' τ, ENNReal.ofReal ((g τ : ℚ) : ℝ) := by227    rw [typeBox_measure_eq_tsum U i hnt c.1 σ fun j t ↦ ((exit_child_law U i hIH c j).1 t).1]228    congr 1; funext τ229    simp only [g]230    split_ifs231    · exact exit_child_box_mass U i hnt hIH c τ232    · simp233  have hstep2 : ∑' τ, ENNReal.ofReal ((g τ : ℚ) : ℝ) =234      ∑ τ ∈ Fintype.piFinset (fun j : (U.M i).childIdx c.1 ↦235        ((stateLaw (((U.M i).childList c.1).get j).2).map Prod.fst).toFinset),236        ENNReal.ofReal ((g τ : ℚ) : ℝ) := by237    refine tsum_eq_sum fun τ hτ ↦ ?_238    rw [Fintype.mem_piFinset] at hτ239    push Not at hτ240    obtain ⟨j, hj⟩ := hτ241    have h0 : ∏ j, C j (τ j) = 0 := Finset.prod_eq_zero (Finset.mem_univ j)242      ((law_coeff_prod_formula 0 Fin.elim0 (τ j) _).2 _ _ hj)243    simp [g, h0]244  have hVs := (density_value_arith _ hq (.const 1) (.const 1) (by simp [Expr.eval])245      (by simp [Expr.eval]) 0 _ (U.M i).valid).2.2.2.2.2.2.1246  rw [hstep1, hstep2, ← ENNReal.ofReal_sum_of_nonneg (fun τ _ ↦ by exact_mod_cast hg τ), U.volume]247  simp only [densityValue]248  rw [← ENNReal.ofReal_mul' (by exact_mod_cast hVs.le), ← Rat.cast_sum, ← Rat.cast_mul, Expr.eval,249    lawCoeff_lawProd_descend_eval ((U.M i).childList c.1)250      (fun z hz ↦ children_residue_degree_pos _ _ _ hz), Finset.mul_sum, Finset.sum_mul]251  congr 2252  refine Finset.sum_congr rfl fun τ _ ↦ ?_253  simp only [g]254  by_cases hσ : σ = ∑ j, scaleType ((U.M i).childDelta c.1 j) (τ j)255  · rw [ite_eq_left hσ,256      ite_eq_left (show σ = ∑ j, scaleType (((U.M i).childList c.1).get j).1 (τ j) from hσ)]257    ring258  · rw [ite_eq_right hσ,259      ite_eq_right (show ¬σ = ∑ j, scaleType (((U.M i).childList c.1).get j).1 (τ j) from hσ)]260    ring261 262/-! ### Return chains at single states -/263 264private theorem list_sum_filter {α : Type} (s : Finset α) (p : α → Prop) [DecidablePred p]265    (f : α → ℚ) :266    ((s.toList.filter (fun x => decide (p x))).map f).sum = ∑ x ∈ s.filter p, f x := by267  rw [Finset.sum_eq_multiset_sum, Finset.filter_val, ← Finset.coe_toList s]268  rw [Multiset.filter_coe, Multiset.map_coe, Multiset.sum_coe]269 270open scoped Classical in271private theorem self_facts (a c q : ℕ) (ha : 0 < a) (hc : 2 ≤ c) (s : State)272    (hs : s = State.single a c) :273    (∀ P : TangentPattern s.degree, Allowed s P → SelfPattern s P → P.d.val = c ∧ children s P =274        [(1, State.single a c)]) ∧275    (((allowedPatterns s).toList.filter (SelfPattern s)).map fun P => (tangentCount s P).eval q).sum276        = q := by277  subst hs; exact self_patterns_of_single_state a c q ha hc278 279private theorem list_get_of_eq_singleton {α : Type} (l : List α) (x : α) (h : l = [x])280    (j : Fin l.length) : l.get j = x := by281  subst h; simp282 283private theorem eval_pow_nonneg (x : Expr) (q : ℚ) (hx : 0 ≤ x.eval q) (n : ℕ) :284    0 ≤ (x.pow n).eval q :=285  expression_pow_eval x q n ▸ pow_nonneg hx n286 287open scoped Classical in288/-- The self cells of a measured surface are counted by the divisors of the self patterns. -/289private theorem natCard_selfCells (M : MeasuredSurface) (hfin : ∀ P : TangentPattern M.s.degree,290    Finite (patternDivisors (IsLocalRing.ResidueField M.R) M.s P)) :291    (Nat.card {c : M.cellIndex // M.IsSelfCell c} : ℚ) =292      ∑ P ∈ (allowedPatterns M.s).filter (SelfPattern M.s),293        (Nat.card (patternDivisors (IsLocalRing.ResidueField M.R) M.s P) : ℚ) := by294  let e : {c : M.cellIndex // M.IsSelfCell c} ≃295      Σ P : {P : TangentPattern M.s.degree // Allowed M.s P ∧ SelfPattern M.s P},296        patternDivisors (IsLocalRing.ResidueField M.R) M.s P.1 :=297    { toFun := fun c => ⟨⟨c.1.1.1, c.1.1.2, c.2⟩, c.1.2⟩298      invFun := fun c => ⟨⟨⟨c.1.1, c.1.2.1⟩, c.2⟩, c.1.2.2⟩299      left_inv := by rintro ⟨⟨⟨P, h⟩, d⟩, h'⟩; rfl300      right_inv := by rintro ⟨⟨P, h⟩, d⟩; rfl }301  rw [Nat.card_congr e, Nat.card_sigma]302  push_cast303  symm; apply Finset.sum_subtype304  intro x; simp [allowedPatterns]305 306/-- At a single state `single a c` (`a > 0`, `c ≥ 2`), every self cell has degree `c` and the307single child `(1, single a c)`, its child surfaces have the same state and residue308cardinality, and there are exactly `q` self cells. -/309private theorem self_cells_facts (U : SurfaceUniverse) {a c : ℕ} (ha : 0 < a) (hc : 2 ≤ c)310    (i : U.ι) (hs : (U.M i).s = State.single a c) :311    (∀ c' : U.selfCells i, (U.M i).cellDegree c'.1 = c ∧312      (U.M i).childList c'.1 = [(1, State.single a c)]) ∧313    (∀ (c' : U.selfCells i) (j : (U.M i).childIdx c'.1),314      (U.M (U.child i c'.1 j)).s = State.single a c ∧ (U.M (U.child i c'.1 j)).q = (U.M i).q) ∧315    Finite (U.selfCells i) ∧ (Nat.card (U.selfCells i) : ℚ) = (U.M i).q := by316  classical317  obtain ⟨hq, -, -, -, _⟩ := universe_basic_facts U i318  have hntM : (U.M i).s.terminal = false := by319    obtain ⟨c', rfl⟩ : ∃ c', c = c' + 2 := ⟨c - 2, by omega⟩320    rw [hs]; rfl321  have hsf := self_facts a c (U.M i).q ha hc (U.M i).s hs322  have hcell : ∀ c' : U.selfCells i, (U.M i).cellDegree c'.1 = c ∧323      (U.M i).childList c'.1 = [(1, State.single a c)] :=324    fun c' => hsf.1 c'.1.1.1 c'.1.1.2 c'.2325  refine ⟨hcell, fun c' j => ?_, Subtype.finite, ?_⟩326  · have hg := list_get_of_eq_singleton _ _ (hcell c').2 j327    refine ⟨?_, ?_⟩328    · rw [U.child_state]; simp only [MeasuredSurface.childState, hg]329    · rw [U.child_residue]; simp only [MeasuredSurface.childDelta, hg, pow_one]330  · rw [show Nat.card (U.selfCells i) = Nat.card {c : (U.M i).cellIndex // (U.M i).IsSelfCell c}331      from rfl, natCard_selfCells (U.M i) (U.divisors_finite i), ← hsf.2, list_sum_filter]332    exact Finset.sum_congr rfl fun P hP =>333      U.divisor_count i hntM P (Finset.mem_filter.1 (Finset.mem_filter.1 hP).1).2334 335/-- The return weight `q · q^{-tri c}` as an extended nonnegative real. -/336private theorem densityValue_returnWeight (q : ℕ) (hq : 2 ≤ q) (c : ℕ) :337    densityValue (returnWeight c) q = (q : ℝ≥0∞) * (q : ℝ≥0∞)⁻¹ ^ tri c := by338  have h := density_value_arith q hq .var (.inv (.pow .var (tri c))) (by simp [Expr.eval])339    (by simp only [Expr.eval]; exact inv_nonneg.mpr (eval_pow_nonneg _ _ (by simp [Expr.eval]) _))340    (tri c) (State.single 1 1) ⟨Nat.one_pos, Nat.one_pos⟩341  rw [returnWeight, h.1, h.2.2.1]342  simp [densityValue, Expr.eval]343 344/-- One more return at `single a c`: if an event family `E` is measurable with mass `m · vol` at345every member in state `single a c` with the same residue cardinality, then the union over the346self cells of `i` of the child boxes of `E` is measurable with mass `λ · m · vol`, where `λ` is347the return weight. -/348private theorem self_cells_union_mass (U : SurfaceUniverse) {a c : ℕ} (ha : 0 < a) (hc : 2 ≤ c)349    (i : U.ι) (hs : (U.M i).s = State.single a c) (E : ∀ i' : U.ι, Set (Ideal (U.M i').R))350    (m : ℝ≥0∞)351    (hE : ∀ i' : U.ι, (U.M i').s = State.single a c → (U.M i').q = (U.M i).q →352      (U.M i').μ (E i') = m * (U.M i').μ (U.M i').stateSet ∧ MeasurableSet (E i')) :353    (U.M i).μ (⋃ c' : U.selfCells i, U.childBox i c'.1 (fun j ↦ E (U.child i c'.1 j))) =354      densityValue (returnWeight c) (U.M i).q * m * (U.M i).μ (U.M i).stateSet ∧355    MeasurableSet (⋃ c' : U.selfCells i, U.childBox i c'.1 (fun j ↦ E (U.child i c'.1 j))) := by356  obtain ⟨hq, -, -, -, -⟩ := universe_basic_facts U i357  have hntM : (U.M i).s.terminal = false := by358    obtain ⟨c', rfl⟩ : ∃ c', c = c' + 2 := ⟨c - 2, by omega⟩359    rw [hs]; rfl360  obtain ⟨hcell, hchild, _, hcard⟩ := self_cells_facts U ha hc i hs361  -- each self cell has a single child, in the same state, with the same residue cardinality362  have hbox : ∀ c' : U.selfCells i,363      MeasurableSet (U.childBox i c'.1 (fun j ↦ E (U.child i c'.1 j))) ∧364      (U.M i).μ (U.childBox i c'.1 (fun j ↦ E (U.child i c'.1 j))) =365        ((U.M i).q : ℝ≥0∞)⁻¹ ^ tri c * (m * (U.M i).μ (U.M i).stateSet) := by366    intro c'367    have hG : ∀ j, MeasurableSet (E (U.child i c'.1 j)) :=368      fun j ↦ (hE _ (hchild c' j).1 (hchild c' j).2).2369    refine ⟨U.Φ_measurable i hntM c'.1 _ hG, ?_⟩370    unfold SurfaceUniverse.childBox371    rw [U.Φ_measure i hntM c'.1 _ hG, (hcell c').1]372    have j0 : (U.M i).childIdx c'.1 := ⟨0, by rw [(hcell c').2]; simp⟩373    have : Subsingleton ((U.M i).childIdx c'.1) := by374      change Subsingleton (Fin ((U.M i).childList c'.1).length)375      rw [(hcell c').2]; simp only [List.length_singleton]; infer_instance376    rw [Fintype.prod_subsingleton _ j0]377    congr 1378    rw [(hE _ (hchild c' j0).1 (hchild c' j0).2).1, U.volume, U.volume, (hchild c' j0).1, hs,379      (hchild c' j0).2]380  have hdisj : Pairwise (Function.onFun Disjoint fun c' : U.selfCells i ↦381      U.childBox i c'.1 (fun j ↦ E (U.child i c'.1 j))) := fun x y hxy ↦382    (U.cells_disjoint i hntM (fun h ↦ hxy (Subtype.ext h))).mono383      Set.inter_subset_left Set.inter_subset_left384  let : Fintype (U.selfCells i) := Fintype.ofFinite _385  refine ⟨?_, MeasurableSet.iUnion fun c' ↦ (hbox c').1⟩386  have hcardN : Fintype.card (U.selfCells i) = (U.M i).q := by387    rw [← Nat.card_eq_fintype_card]; exact_mod_cast hcard388  rw [MeasureTheory.measure_iUnion hdisj (fun c' ↦ (hbox c').1), tsum_fintype,389    Finset.sum_congr rfl (fun c' _ ↦ (hbox c').2), Finset.sum_const, Finset.card_univ,390    nsmul_eq_mul, hcardN, densityValue_returnWeight _ hq]391  ring392 393/-- If the immediate exit event at `single a c` has mass `G · vol`, then the exit event after394`k` returns has mass `λᵏ · G · vol`, where `λ` is the return weight; it is measurable. -/395theorem exit_event_succ_mass (U : SurfaceUniverse) (a c : ℕ) (ha : 0 < a) (hc : 2 ≤ c)Proof of Theorem 6.2396    (σ : FactorType) (q₀ : ℕ) (G : ℚ)397    (hexit : ∀ i : U.ι, (U.M i).s = State.single a c → (U.M i).q = q₀ → (U.M i).μ398        (U.exitEvent σ 0 i) = ENNReal.ofReal (G : ℝ) * (U.M i).μ (U.M i).stateSet ∧ MeasurableSet399        (U.exitEvent σ 0 i))400    (k : ℕ) :401    ∀ i : U.ι, (U.M i).s = State.single a c → (U.M i).q = q₀ →402    (U.M i).μ (U.exitEvent σ k i) = ENNReal.ofReal ((((returnWeight c).eval (q₀ : ℚ)) ^ k * G : ℚ) :403        ℝ) * (U.M i).μ (U.M i).stateSet ∧404    MeasurableSet (U.exitEvent σ k i) := by405  induction k with406  | zero =>407    intro i hs hq0408    simpa using hexit i hs hq0409  | succ k ih =>410    intro i hs hq0411    have hy : 0 ≤ (returnWeight c).eval (q₀ : ℚ) :=412      (return_weight_bounds _ c (hq0 ▸ (universe_basic_facts U i).1) hc).1.le413    obtain ⟨hmass, hmeas⟩ := self_cells_union_mass U ha hc i hs (U.exitEvent σ k) _414      fun i' hs' hq' ↦ ih i' hs' (hq'.trans hq0)415    refine ⟨hmass.trans ?_, hmeas⟩416    rw [hq0, densityValue, ← ENNReal.ofReal_mul (by exact_mod_cast hy)]417    congr 2; push_cast; ring418 419/-! ### Measurability and null sets -/420 421/-- At a nonterminal state (assuming the law for smaller ranks), all return, exit, terminating422exit and bad exit events of members in the same state are measurable. -/423theorem recursion_events_measurable (U : SurfaceUniverse) (i : U.ι)424    (hnt : (U.M i).s.terminal = false)425    (hIH : ∀ i' : U.ι, (U.M i').s.rank < (U.M i).s.rank → U.LawStatement i') :426    ∀ i' : U.ι, (U.M i').s = (U.M i).s → ∀ (k : ℕ) (σ : FactorType),427    MeasurableSet (U.returnEvent k i') ∧ MeasurableSet (U.exitEvent σ k i') ∧428    MeasurableSet (U.termExitEvent k i') ∧ MeasurableSet (U.badExitEvent k i') := by429  intro i₀ hs₀ k σ430  induction k generalizing i₀ with431  | zero =>432    have hnt' : (U.M i₀).s.terminal = false := by rw [hs₀]; exact hnt433    have : Finite (U.M i₀).cellIndex := (universe_basic_facts U i₀).2.2.2.2434    have : Countable (U.exitCells i₀) := by unfold SurfaceUniverse.exitCells; infer_instance435    have hrk : ∀ (c : U.exitCells i₀) j, (U.M (U.child i₀ c.1 j)).s.rank < (U.M i).s.rank := by436      intro c j437      rw [U.child_state, ← hs₀]438      exact nonself_child_rank_lt (U.M i₀).s (U.M i₀).valid c.1.1.1 c.1.1.2 c.2 _439        (List.get_mem _ _)440    refine ⟨U.stateSet_measurable i₀, ?_, ?_, ?_⟩441    · simp only [SurfaceUniverse.exitEvent]442      refine MeasurableSet.iUnion fun c => ?_443      unfold SurfaceUniverse.typeBox444      refine MeasurableSet.iUnion fun τ => MeasurableSet.iUnion fun _ => ?_445      exact U.Φ_measurable i₀ hnt' c.1 _ fun j => ((hIH _ (hrk c j)).1 (τ j)).1446    · simp only [SurfaceUniverse.termExitEvent]447      refine MeasurableSet.iUnion fun c => ?_448      exact U.Φ_measurable i₀ hnt' c.1 _ fun j => (hIH _ (hrk c j)).2.1449    · simp only [SurfaceUniverse.badExitEvent]450      refine MeasurableSet.iUnion fun c => MeasurableSet.iUnion fun j₀ => ?_451      refine U.Φ_measurable i₀ hnt' c.1 _ fun j => ?_452      by_cases hj : j = j₀453      · subst hj454        rw [Function.update_self]455        exact (U.stateSet_measurable _).inter (hIH _ (hrk c j)).2.1.compl456      · rw [Function.update_of_ne hj]457        exact MeasurableSet.univ458  | succ k ih =>459    have hnt' : (U.M i₀).s.terminal = false := by rw [hs₀]; exact hnt460    have : Finite (U.M i₀).cellIndex := (universe_basic_facts U i₀).2.2.2.2461    have : Countable (U.selfCells i₀) := by unfold SurfaceUniverse.selfCells; infer_instance462    have hst : ∀ (c : U.selfCells i₀) j, (U.M (U.child i₀ c.1 j)).s = (U.M i).s := by463      intro c j464      rw [U.child_state, ← hs₀]465      obtain ⟨a, b, -, h⟩ := c.2466      have hm : ∀ z ∈ (U.M i₀).childList c.1, z = (1, (U.M i₀).s) := by467        intro z hz468        unfold MeasuredSurface.childList at hz469        rw [h] at hz470        simpa using hz471      exact congrArg Prod.snd (hm _ (List.get_mem _ _))472    refine ⟨?_, ?_, ?_, ?_⟩473    · simp only [SurfaceUniverse.returnEvent]474      exact MeasurableSet.iUnion fun c =>475        U.Φ_measurable i₀ hnt' c.1 _ fun j => (ih _ (hst c j)).1476    · simp only [SurfaceUniverse.exitEvent]477      exact MeasurableSet.iUnion fun c =>478        U.Φ_measurable i₀ hnt' c.1 _ fun j => (ih _ (hst c j)).2.1479    · simp only [SurfaceUniverse.termExitEvent]480      exact MeasurableSet.iUnion fun c =>481        U.Φ_measurable i₀ hnt' c.1 _ fun j => (ih _ (hst c j)).2.2.1482    · simp only [SurfaceUniverse.badExitEvent]483      exact MeasurableSet.iUnion fun c =>484        U.Φ_measurable i₀ hnt' c.1 _ fun j => (ih _ (hst c j)).2.2.2485 486/-- Bad exit events are null at a nonterminal state, assuming the law for smaller ranks. -/487theorem bad_exit_null (U : SurfaceUniverse) (i : U.ι) (hnt : (U.M i).s.terminal = false)Proof of Theorem 6.2488    (hIH : ∀ i' : U.ι, (U.M i').s.rank < (U.M i).s.rank → U.LawStatement i') (k : ℕ) :489    ∀ i' : U.ι, (U.M i').s = (U.M i).s → (U.M i').μ (U.badExitEvent k i') = 0 := by490  induction k with491  | zero =>492    intro i' hi'493    have hnt' : (U.M i').s.terminal = false := hi' ▸ hnt494    have : Finite (U.M i').cellIndex := (universe_basic_facts U i').2.2.2.2495    have : Countable (U.exitCells i') := by unfold SurfaceUniverse.exitCells; infer_instance496    simp only [SurfaceUniverse.badExitEvent]497    refine MeasureTheory.measure_iUnion_null fun c => MeasureTheory.measure_iUnion_null fun j₀ => ?_498    have hrank : ∀ j, (U.M (U.child i' c.1 j)).s.rank < (U.M i).s.rank := by499      intro j500      rw [U.child_state, ← hi']501      exact nonself_child_rank_lt (U.M i').s (U.M i').valid c.1.1.1 c.1.1.2 c.2502        _ (List.get_mem _ _)503    have hL := hIH _ (hrank j₀)504    have hmeas : ∀ j, MeasurableSet (Function.update (fun j =>505        (Set.univ : Set (Ideal (U.M (U.child i' c.1 j)).R))) j₀506        (U.nonterminatingSet (U.child i' c.1 j₀)) j) := by507      intro j508      by_cases h : j = j₀509      · subst h; rw [Function.update_self]510        exact (U.stateSet_measurable _).inter hL.2.1.compl511      · rw [Function.update_of_ne h]; exact MeasurableSet.univ512    unfold SurfaceUniverse.childBox513    rw [U.Φ_measure i' hnt' c.1 _ hmeas]514    rw [Finset.prod_eq_zero (Finset.mem_univ j₀) (by rw [Function.update_self]; exact hL.2.2),515        mul_zero]516  | succ k ih =>517    intro i' hi'518    have hnt' : (U.M i').s.terminal = false := hi' ▸ hnt519    have : Finite (U.M i').cellIndex := (universe_basic_facts U i').2.2.2.2520    have : Countable (U.selfCells i') := by unfold SurfaceUniverse.selfCells; infer_instance521    simp only [SurfaceUniverse.badExitEvent]522    refine MeasureTheory.measure_iUnion_null fun c => ?_523    have hs : ∀ j, (U.M (U.child i' c.1 j)).s = (U.M i).s := by524      intro j525      rw [U.child_state, ← hi']526      obtain ⟨a, b, _, hch⟩ := c.2527      have hm := List.get_mem ((U.M i').childList c.1) j528      have : (U.M i').childList c.1 = [(1, (U.M i').s)] := hch529      have key : ∀ z ∈ (U.M i').childList c.1, z = (1, (U.M i').s) := by530        rw [this]; simp531      have hm := key _ hm532      unfold MeasuredSurface.childState533      rw [hm]534    have hmeas : ∀ j, MeasurableSet (U.badExitEvent k (U.child i' c.1 j)) := fun j =>535      (recursion_events_measurable U i hnt hIH _ (hs j) k ∅).2.2.2536    unfold SurfaceUniverse.childBox537    rw [U.Φ_measure i' hnt' c.1 _ hmeas]538    have hpos : 0 < ((U.M i').childList c.1).length := by539      obtain ⟨a, b, _, hch⟩ := c.2540      have : (U.M i').childList c.1 = [(1, (U.M i').s)] := hch541      rw [this]; simp542    rw [Finset.prod_eq_zero_iff.mpr ⟨⟨0, hpos⟩, Finset.mem_univ _, ih _ (hs _)⟩, mul_zero]543 544/-- Summing the weight `P(d) · (σ-coefficient of the descended children laws)` over the exit545cells gives the `σ`-coefficient of the exit law. -/546private theorem exit_cell_weight_sum (U : SurfaceUniverse) (i : U.ι)547    (hnt : (U.M i).s.terminal = false) (σ : FactorType)548    [Fintype (U.exitCells i)] :549    ∑ c : U.exitCells i,550      (divisorProbability (U.M i).s ((U.M i).cellDegree c.1)).eval ((U.M i).q : ℚ) *551        (lawCoeff (lawProd (((U.M i).childList c.1).map fun z => lawDescend z.1 (stateLaw z.2)))552          σ).eval ((U.M i).q : ℚ) =553      (lawCoeff (exitLaw (U.M i).s) σ).eval ((U.M i).q : ℚ) := by554  classical555  let : ∀ P, Fintype (patternDivisors (IsLocalRing.ResidueField (U.M i).R) (U.M i).s P) :=556    fun P => @Fintype.ofFinite _ (U.divisors_finite i P)557  set M := U.M i with hM558  set s := M.s with hs559  set qq : ℚ := (M.q : ℚ) with hqq560  let F : M.cellIndex → ℚ := fun c =>561    (divisorProbability s (M.cellDegree c)).eval qq *562      (lawCoeff (lawProd ((M.childList c).map fun z => lawDescend z.1 (stateLaw z.2))) σ).eval qq563  let g : TangentPattern s.degree → ℚ := fun P => if SelfPattern s P then 0 else564    (tangentCount s P).eval qq * ((divisorProbability s P.d.val).eval qq *565      (lawCoeff (lawProd ((children s P).map fun z => lawDescend z.1 (stateLaw z.2))) σ).eval qq)566  have h1 : ∑ c : U.exitCells i, F c.1 =567      ∑ c : M.cellIndex, if M.IsSelfCell c then 0 else F c := by568    rw [Finset.sum_ite, Finset.sum_const_zero, zero_add]569    exact (Finset.sum_subtype _ (fun x => by570      simp only [Finset.mem_filter, Finset.mem_univ, true_and]; exact Iff.rfl) F).symm571  have h2 : (∑ c : M.cellIndex, if M.IsSelfCell c then 0 else F c) =572      ∑ P : M.allowedPattern, g P.1 := by573    rw [Fintype.sum_sigma]574    refine Finset.sum_congr rfl fun P _ => ?_575    change ∑ D : patternDivisors (IsLocalRing.ResidueField M.R) s P.1,576        (if SelfPattern s P.1 then (0 : ℚ) else (divisorProbability s P.1.d.val).eval qq *577          (lawCoeff (lawProd ((children s P.1).map fun z => lawDescend z.1 (stateLaw z.2)))578              σ).eval qq)579        = g P.1580    rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, ← Nat.card_eq_fintype_card,581      U.divisor_count i hnt P.1 P.2]582    simp only [g]583    split_ifs584    · simp585    · simp only [mul_eq_mul_right_iff, mul_eq_zero]; left; rfl586  have h3 : ∑ P : M.allowedPattern, g P.1 = ∑ P ∈ allowedPatterns s, g P :=587    (Finset.sum_subtype _ (fun x => by588      simp only [allowedPatterns, Finset.mem_filter, Finset.mem_univ, true_and]589      exact Iff.rfl) g).symm590  have h4 : (lawCoeff (exitLaw s) σ).eval qq = ∑ P ∈ allowedPatterns s, g P := by591    unfold exitLaw592    rw [(law_coeff_flatMap _ _ _ [] [] σ qq).2.2, Finset.sum_map_toList]593    refine Finset.sum_congr rfl fun P _ => ?_594    simp only [g]595    split_ifs596    · exact (law_coeff_flatMap Unit [] (fun _ => []) [] [] σ qq).2.1597    · rw [law_coeff_scale]; change _ * _ * _ = _; ring598  exact h1.trans (h2.trans (h3.trans h4.symm))599 600/-- The immediate exit event of type `σ` has mass equal to the `σ`-coefficient of the exit law601times the volume of the state set; this coefficient is nonnegative and the event measurable. -/602theorem exit_event_zero_mass (U : SurfaceUniverse) (i : U.ι) (hnt : (U.M i).s.terminal = false)603    (hIH : ∀ i' : U.ι, (U.M i').s.rank < (U.M i).s.rank → U.LawStatement i') (σ : FactorType) :604    (U.M i).μ (U.exitEvent σ 0 i) = densityValue (lawCoeff (exitLaw (U.M i).s) σ) (U.M i).q *605        (U.M i).μ (U.M i).stateSet ∧606    0 ≤ (lawCoeff (exitLaw (U.M i).s) σ).eval ((U.M i).q : ℚ) ∧607      MeasurableSet (U.exitEvent σ 0 i) := by608  classical609  obtain ⟨hq, -, -, -, -⟩ := universe_basic_facts U i610  have hmeas : MeasurableSet (U.exitEvent σ 0 i) :=611    ((recursion_events_measurable U i hnt hIH) i rfl 0 σ).2.1612  set M := U.M i with hM613  set s := M.s with hs614  set qq : ℚ := (M.q : ℚ) with hqq615  -- the per-cell rational weight616  let F : M.cellIndex → ℚ := fun c =>617    (divisorProbability s (M.cellDegree c)).eval qq *618      (lawCoeff (lawProd ((M.childList c).map fun z => lawDescend z.1 (stateLaw z.2))) σ).eval qq619  have hFnn : ∀ c : U.exitCells i, 0 ≤ F c.1 := by620    intro c621    exact mul_nonneg ((divisor_probability_pos M.q hq s _ 2 le_rfl).1.le)622      (exit_cell_coeff_nonneg U i hIH c σ)623  have hbox_sub : ∀ c σ', U.typeBox i c σ' ⊆ M.cell c := by624    intro c σ' x hx625    simp only [SurfaceUniverse.typeBox, Set.mem_iUnion] at hx626    obtain ⟨τ, _, hx⟩ := hx627    exact hx.1628  have hbox_eq : ∀ c : U.exitCells i, U.typeBox i c.1 σ = U.exitEvent σ 0 i ∩ M.cell c.1 := by629    intro c630    ext x631    constructor632    · intro hx633      exact ⟨Set.mem_iUnion.2 ⟨c, hx⟩, hbox_sub _ _ hx⟩634    · rintro ⟨hE, hc⟩635      obtain ⟨c', hx'⟩ := Set.mem_iUnion.1 hE636      by_cases h : c'.1 = c.1637      · rw [← h]; exact hx'638      · exact absurd (U.cells_disjoint i hnt h) (Set.not_disjoint_iff.2 ⟨x, hbox_sub _ _ hx', hc⟩)639  let : ∀ P, Fintype (patternDivisors (IsLocalRing.ResidueField M.R) s P) :=640    fun P => @Fintype.ofFinite _ (U.divisors_finite i P)641  let : Fintype (U.exitCells i) := by unfold SurfaceUniverse.exitCells; infer_instance642  have hsum : (M.μ (U.exitEvent σ 0 i)) = ∑ c : U.exitCells i, ENNReal.ofReal ((F c.1 : ℚ) : ℝ) *643      M.μ M.stateSet := by644    rw [show U.exitEvent σ 0 i = ⋃ c : U.exitCells i, U.typeBox i c.1 σ from rfl]645    rw [MeasureTheory.measure_iUnion, tsum_fintype]646    · exact Finset.sum_congr rfl fun c _ => exit_cell_type_mass U i hnt hIH c σ647    · intro c c' hcc'648      have hne : c.1 ≠ c'.1 := fun h => hcc' (Subtype.ext h)649      exact (U.cells_disjoint i hnt hne).mono (hbox_sub _ _) (hbox_sub _ _)650    · intro c651      rw [hbox_eq c]652      exact hmeas.inter (U.cell_measurable i hnt c.1)653  have hrat : ∑ c : U.exitCells i, F c.1 = (lawCoeff (exitLaw s) σ).eval qq :=654    exit_cell_weight_sum U i hnt σ655  refine ⟨?_, ?_, hmeas⟩656  · rw [hsum, ← Finset.sum_mul, ← ENNReal.ofReal_sum_of_nonneg657      (fun c _ => by exact_mod_cast hFnn c)]658    change _ = ENNReal.ofReal (((lawCoeff (exitLaw s) σ).eval qq : ℚ) : ℝ) * _659    rw [← hrat]660    push_cast661    rfl662  · rw [← hrat]663    exact Finset.sum_nonneg fun c _ => hFnn c664 665/-! ### Crossing states, return events and the law statement -/666 667/-- The law statement at a crossing state, assuming it for all states of smaller rank. -/668theorem recursion_crossing_law (U : SurfaceUniverse) (i : U.ι) (a b c h : ℕ)Proof of Theorem 6.2669    (hs : (U.M i).s = State.crossing a b c h)670    (hIH : ∀ i' : U.ι, (U.M i').s.rank < (U.M i).s.rank → U.LawStatement i') :671    U.LawStatement i := by672  have hnt : (U.M i).s.terminal = false := by rw [hs]; rfl673  have hv : (U.M i).s.Valid := (U.M i).valid674  have h560 := (single_state_return_chain U i hnt)675  have h551 := (state_law_unfold _ hv hnt).2 a b c h hs676  refine ⟨fun σ => ?_, ?_, ?_⟩677  · have e := ((h560 σ).2 a b c h hs).1678    obtain ⟨m, nn, ms⟩ := exit_event_zero_mass U i hnt hIH σ679    rw [e, h551]680    exact ⟨ms, nn, m⟩681  · have e := ((h560 (default)).2 a b c h hs).2682    rw [e]683    exact (recursion_events_measurable U i hnt hIH i rfl 0 default).2.2.1684  · exact MeasureTheory.measure_mono_null685      ((nonterminating_subset_return_or_bad U i hnt).2 a b c h hs)686      (bad_exit_null U i hnt hIH 0 i rfl)687 688/-- At `single a c`, the event of returning `k` times has mass `λᵏ · vol`, with `λ` the return689weight, and is measurable. -/690theorem return_event_mass (U : SurfaceUniverse) (a c : ℕ) (ha : 0 < a) (hc : 2 ≤ c) (k : ℕ) :Proof of Theorem 6.2691    ∀ i : U.ι, (U.M i).s = State.single a c →692    (U.M i).μ (U.returnEvent k i) = densityValue ((returnWeight c).pow k) (U.M i).q * (U.M i).μ693        (U.M i).stateSet ∧694    MeasurableSet (U.returnEvent k i) := by695  have hvalid : (State.single a c).Valid := ⟨ha, by omega⟩696  induction k with697  | zero =>698    intro i hs699    obtain ⟨hq, -, -, -, -⟩ := universe_basic_facts U i700    refine ⟨?_, U.stateSet_measurable i⟩701    simp only [SurfaceUniverse.returnEvent, Expr.pow]702    rw [(density_value_arith (U.M i).q hq (.const 1) (.const 1) (by norm_num [Expr.eval])703      (by norm_num [Expr.eval]) 0 _ hvalid).2.2.2.1, one_mul]704  | succ k ih =>705    intro i hs706    obtain ⟨hq, -, -, -, -⟩ := universe_basic_facts U i707    obtain ⟨hmass, hmeas⟩ := self_cells_union_mass U ha hc i hs (U.returnEvent k)708      (densityValue ((returnWeight c).pow k) (U.M i).q) fun i' hs' hq' ↦ by709        rw [← hq']; exact ih i' hs'710    refine ⟨hmass.trans ?_, hmeas⟩711    have hy := (return_weight_bounds _ c hq hc).1.le712    rw [Expr.pow, (density_value_arith (U.M i).q hq _ _ (eval_pow_nonneg _ _ hy k) hy 0 _713      hvalid).1]714    ring715 716/-- At `single a c` the set of ideals that return infinitely often is measurable and null. -/717theorem never_return_null (U : SurfaceUniverse) (a c : ℕ) (ha : 0 < a) (hc : 2 ≤ c) (i : U.ι)Proof of Theorem 6.2718    (hs : (U.M i).s = State.single a c) :719    (U.M i).μ (⋂ k, U.returnEvent k i) = 0 ∧ MeasurableSet (⋂ k, U.returnEvent k i) := by720  have hmass := fun k => return_event_mass U a c ha hc k i hs721  refine ⟨?_, MeasurableSet.iInter fun k => (hmass k).2⟩722  obtain ⟨hq, -, hfin, -⟩ := universe_basic_facts U i723  obtain ⟨hpos, -, hlt⟩ := return_weight_bounds (U.M i).q c hq hc724  have hlt' : ENNReal.ofReal (((returnWeight c).eval ((U.M i).q : ℚ) : ℚ) : ℝ) < 1 := by725    rw [ENNReal.ofReal_lt_one]; exact_mod_cast hlt726  have hle : ∀ k, (U.M i).μ (⋂ k, U.returnEvent k i) ≤727      (ENNReal.ofReal (((returnWeight c).eval ((U.M i).q : ℚ) : ℚ) : ℝ)) ^ k * (U.M i).μ728          (U.M i).stateSet := by729    intro k730    refine (MeasureTheory.measure_mono (Set.iInter_subset _ k)).trans ?_731    rw [(hmass k).1, densityValue, expression_pow_eval, ← ENNReal.ofReal_pow732        (by exact_mod_cast hpos.le)]733    norm_cast734  have ht := ENNReal.Tendsto.mul_const (ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one hlt')735    (Or.inr hfin)736  rw [zero_mul] at ht737  exact le_antisymm (ge_of_tendsto' ht hle) zero_le738 739/-- The law statement at a nonterminal single state, assuming it for all states of smaller rank. -/740theorem recursion_single_law (U : SurfaceUniverse) (i : U.ι) (a c : ℕ) (hc : 2 ≤ c)Proof of Theorem 6.2741    (hs : (U.M i).s = State.single a c)742    (hIH : ∀ i' : U.ι, (U.M i').s.rank < (U.M i).s.rank → U.LawStatement i') :743    U.LawStatement i := by744  have hnt : (U.M i).s.terminal = false := by745    rw [hs]; obtain ⟨c', rfl⟩ : ∃ c', c = c' + 2 := ⟨c - 2, by omega⟩; rfl746  have hv : (U.M i).s.Valid := (U.M i).valid747  have ha : 0 < a := by rw [hs] at hv; exact hv.1748  have h560 := single_state_return_chain U i hnt749  have h551 := (state_law_unfold _ hv hnt).1 a c hs750  have hq := (universe_basic_facts U i).1751  obtain ⟨hl0, -, hl1⟩ := return_weight_bounds _ c hq hc752  refine ⟨fun σ => ?_, ?_, ?_⟩753  · set q₀ := (U.M i).q with hq₀754    set lam : ℚ := (returnWeight c).eval (q₀ : ℚ) with hlam755    set G : ℚ := (lawCoeff (exitLaw (State.single a c)) σ).eval (q₀ : ℚ) with hGdef756    have hG : 0 ≤ G := by757      have := (exit_event_zero_mass U i hnt hIH σ).2.1758      rwa [hs] at this759    have hexit : ∀ i' : U.ι, (U.M i').s = State.single a c → (U.M i').q = q₀ →760        (U.M i').μ (U.exitEvent σ 0 i') = ENNReal.ofReal (G : ℝ) * (U.M i').μ (U.M i').stateSet761          ∧ MeasurableSet (U.exitEvent σ 0 i') := by762      intro i' hs' hq'763      have hnt' : (U.M i').s.terminal = false := by rw [hs', ← hs]; exact hnt764      have hIH' : ∀ j : U.ι, (U.M j).s.rank < (U.M i').s.rank → U.LawStatement j := by765        rw [hs', ← hs]; exact hIH766      obtain ⟨m, -, ms⟩ := exit_event_zero_mass U i' hnt' hIH' σ767      rw [hs', hq'] at m768      exact ⟨m, ms⟩769    have hk := fun k => exit_event_succ_mass U a c ha hc σ q₀ G hexit k i hs rfl770    obtain ⟨e, hdisj, -⟩ := (h560 σ).1 a c hs771    have hcoef : (lawCoeff (stateLaw (U.M i).s) σ).eval (q₀ : ℚ) = (1 - lam)⁻¹ * G := by772      rw [h551, law_coeff_scale, hs]773      simp only [Expr.eval, Expr.sub, Expr.neg, neg_mul, one_mul, hlam, hGdef]774      ring775    have hpos : (0 : ℚ) < 1 - lam := by linarith776    rw [e, hcoef]777    refine ⟨MeasurableSet.iUnion fun k => (hk k).2, by positivity, ?_⟩778    rw [MeasureTheory.measure_iUnion hdisj fun k => (hk k).2]779    simp only [fun k => (hk k).1]780    rw [ENNReal.tsum_mul_right, densityValue, ← ENNReal.ofReal_tsum_of_nonneg]781    · congr 2782      have := geometric_exit_sum (lam : ℝ) (G : ℝ) (by exact_mod_cast hl0.le)783        (by exact_mod_cast hl1)784      rw [hcoef]785      push_cast786      rw [this.tsum_eq]787      field_simp788    · intro k; push_cast; positivity789    · have := geometric_exit_sum (lam : ℝ) (G : ℝ) (by exact_mod_cast hl0.le)790        (by exact_mod_cast hl1)791      push_cast792      exact this.summable793  · rw [((h560 default).1 a c hs).2.2]794    exact MeasurableSet.iUnion fun k =>795      (recursion_events_measurable U i hnt hIH i rfl k default).2.2.1796  · refine MeasureTheory.measure_mono_null797      ((nonterminating_subset_return_or_bad U i hnt).1 a c hs) ?_798    refine MeasureTheory.measure_union_null799      (never_return_null U a c ha hc i hs).1 ?_800    exact MeasureTheory.measure_iUnion_null fun k =>801      bad_exit_null U i hnt hIH k i rfl802 803/-- The law statement holds for every member of a surface universe. -/804theorem universal_law_statement (U : SurfaceUniverse) :Theorem 6.2805    ∀ i : U.ι, U.LawStatement i := by806  have key : ∀ n : ℕ, ∀ i : U.ι, (U.M i).s.rank = n → U.LawStatement i := by807    intro n808    induction n using Nat.strong_induction_on with809    | _ n ih =>810      intro i hn811      have hIH : ∀ i' : U.ι, (U.M i').s.rank < (U.M i).s.rank → U.LawStatement i' :=812        fun i' h => ih _ (hn ▸ h) i' rfl813      have hv := (U.M i).valid814      generalize hs : (U.M i).s = s at hv815      cases s with816      | single a c =>817        by_cases h1 : c = 1818        · subst h1819          exact recursion_terminal_law U i (by rw [hs]; rfl)820        · have : 2 ≤ c := by821            have := hv.2; omega822          exact recursion_single_law U i a c this hs hIH823      | crossing a b c h =>824        exact recursion_crossing_law U i a b c h hs hIH825  exact fun i => key _ i rfl826 827/-! ### Type events -/828 829/-- The terminating type-`σ` event is measurable, contained in the type-`σ` event, and differs830from it by a subset of the null nonterminating set. -/831theorem type_event_null_difference (U : SurfaceUniverse) (i : U.ι) (σ : FactorType) :832    MeasurableSet (U.termTypeEvent i σ) ∧ U.termTypeEvent i σ ⊆ U.typeEvent i σ ∧833    U.typeEvent i σ ⊆ U.termTypeEvent i σ ∪ U.nonterminatingSet i ∧834    (U.M i).μ (U.nonterminatingSet i) = 0 := by835  have h := universal_law_statement U i836  refine ⟨(h.1 σ).1, Set.inter_subset_left, ?_, h.2.2⟩837  intro J hJ838  by_cases ht : J ∈ U.terminatingSet i839  · exact Or.inl ⟨hJ, ht⟩840  · refine Or.inr ⟨?_, ht⟩841    exact hJ.1842 843/-- Under the étale type-transport hypotheses, every type event of a surface universe is844measurable. -/845theorem etale_type_event_measurable (U : SurfaceUniverse)846    (hE1 : U.ChildTypesExist) (δ : ∀ i : U.ι, Ideal (U.M i).R → ℕ) (hE2 : U.InvariantDecreases δ)847    (i : U.ι) (σ : FactorType) :848    MeasurableSet (U.typeEvent i σ) := by849  rw [etale_type_event_eq_term U hE1 δ hE2 i σ]850  exact (type_event_null_difference U i σ).1851 852/-- A decomposition `K ⊗[O] B ≃ ∏ᵢ Lᵢ` of the generic fibre ascends along an unramified extension853`O → Oδ` (with `π` remaining a uniformizer) to `Kδ ⊗[Oδ] B ≃ ∏ᵢ Lᵢ`, compatibly with the854`O`-structures. -/855theorem unramified_generic_fibre_ascent (O Oδ : Type) [CommRing O] [IsDomain O]856    [IsDiscreteValuationRing O] [CommRing Oδ] [IsDomain Oδ] [IsDiscreteValuationRing Oδ]857    [Algebra O Oδ] [Module.Finite O Oδ] [Module.Free O Oδ] (δ : ℕ) (hrank : Module.finrank O Oδ = δ)858    (pi : O) (hpi : Irreducible pi) (hpiδ : Irreducible (algebraMap O Oδ pi)) (B : Type)859    [CommRing B] [Algebra O B] [Algebra Oδ B] [IsScalarTower O Oδ B] (ι : Type)860    (L : ι → Type) [∀ i, Field (L i)] [∀ i, Algebra (BaseField O) (L i)]861    [∀ i, FiniteDimensional (BaseField O) (L i)]862    (e : TensorProduct O (BaseField O) B ≃ₐ[BaseField O] (∀ i, L i)) :863    ∃ (_ : ∀ i, Algebra (BaseField Oδ) (L i)) (_ : ∀ i, Algebra Oδ (L i))864        (_ : ∀ i, IsScalarTower Oδ (BaseField Oδ) (L i))865        (_ : ∀ i, FiniteDimensional (BaseField Oδ) (L i))866        (_ : TensorProduct Oδ (BaseField Oδ) B ≃ₐ[BaseField Oδ] (∀ i, L i)),867    ∀ i (c : O),868    algebraMap Oδ (L i) (algebraMap O Oδ c) = algebraMap (BaseField O) (L i)869        (algebraMap O (BaseField O) c) := by870  obtain ⟨-, -, hfr⟩ := unramified_fraction_base_change O Oδ δ hrank pi hpi hpiδ871  set K := BaseField O872  set Kδ := BaseField Oδ873  let rA : Algebra Oδ (TensorProduct O K Oδ) := Algebra.TensorProduct.rightAlgebra874  -- Oδ-algebra equivalence K ⊗ Oδ ≃ Oδ ⊗ K875  let c : TensorProduct O K Oδ ≃ₐ[Oδ] TensorProduct O Oδ K :=876    AlgEquiv.ofRingEquiv (f := (Algebra.TensorProduct.comm O K Oδ).toRingEquiv) (by877      intro x878      change (Algebra.TensorProduct.comm O K Oδ) ((1 : K) ⊗ₜ x) = x ⊗ₜ (1 : K)879      simp)880  have : IsFractionRing Oδ (TensorProduct O Oδ K) := IsLocalization.isLocalization_of_algEquiv _ c881  let ψ : Kδ ≃ₐ[Oδ] TensorProduct O Oδ K :=882    IsLocalization.algEquiv (nonZeroDivisors Oδ) Kδ (TensorProduct O Oδ K)883  let Θ : TensorProduct Oδ Kδ B ≃+* TensorProduct O K B :=884    ((Algebra.TensorProduct.comm Oδ Kδ B).toRingEquiv.trans885      (Algebra.TensorProduct.congr (AlgEquiv.refl : B ≃ₐ[Oδ] B) ψ).toRingEquiv).trans886      ((Algebra.TensorProduct.cancelBaseChange O Oδ Oδ B K).toRingEquiv.trans887        (Algebra.TensorProduct.comm O B K).toRingEquiv)888  let E₀ : TensorProduct Oδ Kδ B ≃+* (∀ i, L i) := Θ.trans e.toRingEquiv889  let f : ∀ i, Kδ →+* L i := fun i =>890    (Pi.evalRingHom L i).comp (E₀.toRingHom.comp Algebra.TensorProduct.includeLeftRingHom)891  let iA : ∀ i, Algebra Kδ (L i) := fun i => (f i).toAlgebra892  let iB : ∀ i, Algebra Oδ (L i) := fun i => ((algebraMap Kδ (L i)).comp893      (algebraMap Oδ Kδ)).toAlgebra894  have iC : ∀ i, IsScalarTower Oδ Kδ (L i) := fun i => IsScalarTower.of_algebraMap_eq (fun _ => rfl)895  let φ : K →+* Kδ := ψ.symm.toRingHom.comp Algebra.TensorProduct.includeRight.toRingHom896  let : Algebra K Kδ := φ.toAlgebra897  have hΘ : ∀ k : K, Θ (φ k ⊗ₜ 1) = k ⊗ₜ 1 := by898    intro k899    simp [Θ, φ]900  have : ∀ i, IsScalarTower K Kδ (L i) := fun i => IsScalarTower.of_algebraMap_eq (fun k => by901    change algebraMap K (L i) k = (e (Θ (φ k ⊗ₜ 1))) i902    rw [hΘ]903    have := e.commutes k904    rw [Algebra.TensorProduct.algebraMap_apply, Algebra.algebraMap_self, RingHom.id_apply] at this905    rw [this]906    rfl)907  have iD : ∀ i, FiniteDimensional Kδ (L i) := fun i => Module.Finite.of_restrictScalars_finite K Kδ908      (L i)909  refine ⟨iA, iB, iC, iD, AlgEquiv.ofRingEquiv (f := E₀) ?_, ?_⟩910  · exact fun r => rfl911  -- the `Oδ`-structure restricts to the `O`-structure through `K`912  have hφO : ∀ c : O, φ (algebraMap O K c) = algebraMap Oδ Kδ (algebraMap O Oδ c) := by913    intro c914    change ψ.symm (Algebra.TensorProduct.includeRight (algebraMap O K c)) = _915    rw [AlgHom.commutes, IsScalarTower.algebraMap_apply O Oδ (TensorProduct O Oδ K)]916    exact ψ.symm.commutes _917  intro i c918  change algebraMap Kδ (L i) (algebraMap Oδ Kδ (algebraMap O Oδ c)) = algebraMap K (L i)919      (algebraMap O K c)920  rw [← hφO, IsScalarTower.algebraMap_apply K Kδ (L i)]921  rfl922 923end SurfaceBlowup