Lean sources / SurfaceBlowup / Unramified / HomogeneousCells.lean

Measure-preserving maps between homogeneous cells

782 lines · 5 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.Measure.AdicTransport7import SurfaceBlowup.Unramified.FrobeniusDescent8 9/-!10# Measure-preserving maps between homogeneous cells11 12Over a complete discrete valuation ring `O` with finite residue field, the normalized Haar measures13on residue cells of monic polynomials, on reduced form cells and on projective cells are related by14explicit algebraic maps. This file shows that these maps are measure preserving.15 16## Main results17 18* `SurfaceBlowup.form_product_measurable`: the reduced form-product map is Borel measurable.19* `SurfaceBlowup.factor_cells_measure_preserving`: multiplying monic lifts of pairwise coprime20  residue factors pushes the product of the factor cell measures to the cell measure of the product.21* `SurfaceBlowup.form_cell_monic_identification`: reduced form cells normalized at the last22  coordinate are monic residue cells, and coordinate reversal identifies the form cell of `X ^ r`23  normalized at `0` with the monic residue cell of `X ^ r`, measure-preservingly.24* `SurfaceBlowup.form_cells_measure_preserving`: the homogeneous analogue of the first result for25  reduced form cells.26* `SurfaceBlowup.projective_cell_normalization_pushforward`: normalizing a primitive vector at a27  coordinate where its residue form is `1` pushes the projective cell measure to the reduced form28  cell measure.29 30## Implementation notes31 32The three measure-preservation proofs share one skeleton33(`measurePreserving_cellMeasure_of_balls`): both measures are finite and agree on the34generating `𝔪`-adic balls, which reduces to balls of radius `𝔪 ^ L`, `L ≥ 1`, centred in the35target cell (balls centred outside the cell miss it).36 37Provenance: `Thm_SurfaceBlowupV2_{form_product_measurable, factor_cells_measure_preserving,38form_cell_monic_identification, form_cells_measure_preserving,39projective_cell_normalization_pushforward}` (`form_product_measurable` moved from40`Unramified/LocalDescent.lean`).41-/42 43namespace SurfaceBlowup44 45open scoped BigOperators ENNReal46 47/-! ### A skeleton for measure preservation onto a cell -/48 49/-- A measurable map `f` sending `P`-almost every point into a measurable cell `D` (a single50residue class modulo `𝔪`, with `cellMeasure O N D` a probability measure) pushes the probability51measure `P` forward to `cellMeasure O N D` as soon as both measures agree on the `𝔪 ^ L`-balls52(`L ≥ 1`) centred in `D`. -/53private theorem measurePreserving_cellMeasure_of_balls (O : Type) [CommRing O] [IsDomain O]54    [IsDiscreteValuationRing O] [TopologicalSpace O] [IsTopologicalRing O] [CompactSpace O]55    [T2Space O] [SecondCountableTopology O] [MeasurableSpace O] [BorelSpace O]56    (htop : IsAdic (IsLocalRing.maximalIdeal O)) {α : Type} [MeasurableSpace α]57    (P : MeasureTheory.Measure α) [MeasureTheory.IsProbabilityMeasure P] (N : ℕ)58    (D : Set (Fin N → O)) (hDm : MeasurableSet D)59    [MeasureTheory.IsProbabilityMeasure (cellMeasure O N D)]60    (hDball : ∀ z ∈ D, D = {y | ∀ j, y j - z j ∈ IsLocalRing.maximalIdeal O})61    (f : α → Fin N → O) (hf : Measurable f) (S : Set α) (hS : P Sᶜ = 0)62    (hSD : Set.MapsTo f S D)63    (hball : ∀ L, 1 ≤ L → ∀ x ∈ D,64      P (f ⁻¹' {y | ∀ j, y j - x j ∈ IsLocalRing.maximalIdeal O ^ L}) =65        cellMeasure O N D {y | ∀ j, y j - x j ∈ IsLocalRing.maximalIdeal O ^ L}) :66    MeasureTheory.MeasurePreserving f P (cellMeasure O N D) := by67  set m := IsLocalRing.maximalIdeal O68  have hgen := finite_coordinate_borel_cylinders O m htop N69  refine ⟨hf, finite_measures_from_cylinders O (Fin N → O) m _ _ hgen fun L x => ?_⟩70  have hB : {y : Fin N → O | adicCongr m L y x} = {y | ∀ j, y j - x j ∈ m ^ L} := by71    ext y; exact finite_coordinate_adic_congruence O N m L y x72  have hBm : MeasurableSet {y : Fin N → O | ∀ j, y j - x j ∈ m ^ L} := by73    have h1 : @MeasurableSet _ (adicCylinderSpace m (Fin N → O)) {y | adicCongr m L y x} :=74      MeasurableSpace.measurableSet_generateFrom (Or.inr ⟨L, x, rfl⟩)75    rwa [← hgen, hB] at h176  rw [hB, MeasureTheory.Measure.map_apply hf hBm]77  rcases Nat.eq_zero_or_pos L with rfl | hL78  · have : {y : Fin N → O | ∀ j, y j - x j ∈ m ^ 0} = Set.univ := by ext y; simp79    rw [this, Set.preimage_univ, MeasureTheory.measure_univ, MeasureTheory.measure_univ]80  by_cases hx : x ∈ D81  · exact hball L hL x hx82  -- a ball around a point outside `D` misses `D`, so both sides vanish83  have hfar : ∀ y ∈ D, ¬ ∀ j, y j - x j ∈ m ^ L := fun y hy hyx => hx <| by84    rw [hDball y hy]85    exact fun j => by simpa only [neg_sub] using m.neg_mem (Ideal.pow_le_self (by omega) (hyx j))86  have h0 : cellMeasure O N D {y | ∀ j, y j - x j ∈ m ^ L} = 0 := by87    rw [cellMeasure, MeasureTheory.Measure.smul_apply, MeasureTheory.Measure.restrict_apply' hDm,88      show {y : Fin N → O | ∀ j, y j - x j ∈ m ^ L} ∩ D = ∅ from89        Set.eq_empty_of_forall_notMem fun y ⟨h1, h2⟩ => hfar y h2 h1]90    simp91  rw [h0]92  exact MeasureTheory.measure_mono_null (fun a ha haS => hfar _ (hSD haS) ha) hS93 94/-! ### Products of monic residue cells -/95 96/-- Multiplying monic lifts of pairwise coprime monic residue polynomials `g i` pushes the product97of the normalized cell measures forward to the normalized cell measure of `∏ i, g i`. -/98theorem factor_cells_measure_preserving (O : Type) [CommRing O] [IsDomain O]Lemma 7.199    [IsDiscreteValuationRing O] [IsAdicComplete (IsLocalRing.maximalIdeal O) O]100    [Finite (IsLocalRing.ResidueField O)] [TopologicalSpace O] [IsTopologicalRing O]101    [CompactSpace O] [T2Space O] [SecondCountableTopology O] [MeasurableSpace O] [BorelSpace O]102    (htop : IsAdic (IsLocalRing.maximalIdeal O)) (ι : Type) [Fintype ι]103    (g : ι → Polynomial (IsLocalRing.ResidueField O)) (hg : ∀ i, (g i).Monic)104    (hc : ∀ i j, i ≠ j → IsCoprime (g i) (g j))105    [hσ : ∀ i, MeasureTheory.SigmaFinite106      (cellMeasure O (g i).natDegree (residueCell O (g i).natDegree (g i)))] :107    MeasureTheory.MeasurePreserving (factorProduct (fun i => (g i).natDegree))108      (MeasureTheory.Measure.pi109        (fun i => cellMeasure O (g i).natDegree (residueCell O (g i).natDegree (g i))))110      (cellMeasure O (∑ i, (g i).natDegree)111        (residueCell O (∑ i, (g i).natDegree) (∏ i, g i))) := by112  set m := IsLocalRing.maximalIdeal O113  set n := ∑ i, (g i).natDegree114  set C := residueCell O n (∏ i, g i)115  set PC := Set.pi Set.univ (fun i => residueCell O (g i).natDegree (g i))116  set f := factorProduct (O := O) (fun i => (g i).natDegree)117  set q : ℝ≥0∞ := (Nat.card (IsLocalRing.ResidueField O) : ℝ≥0∞) with hq118  have hfm : Measurable f := (factor_product_continuous O ι (fun i => (g i).natDegree)).2119  have hGm : (∏ i, g i).Monic := Polynomial.monic_prod_of_monic _ _ (fun i _ => hg i)120  have hGn : (∏ i, g i).natDegree = n := Polynomial.natDegree_prod_of_monic _ _ (fun i _ => hg i)121  obtain ⟨hCm, hCmass, hρprob⟩ := residue_cell_mass O htop n (∏ i, g i) hGm hGn122  obtain ⟨hPprob, hPnull, hPball⟩ := factor_cell_product_measure O htop ι g hg123  have hbij := factor_product_bijection O ι g hg hc124  obtain ⟨pi, hpi⟩ := IsDiscreteValuationRing.exists_irreducible O125  have hq0 : q ≠ 0 := Nat.cast_ne_zero.2 Nat.card_pos.ne'126  have hqt : q ≠ ⊤ := by simp [hq]127  have hqi0 : q⁻¹ ^ n ≠ 0 := pow_ne_zero _ (ENNReal.inv_ne_zero.mpr hqt)128  have hqit : q⁻¹ ^ n ≠ ⊤ := ENNReal.pow_ne_top (ENNReal.inv_ne_top.mpr hq0)129  refine measurePreserving_cellMeasure_of_balls O htop _ n C hCm (residue_cell_cylinder O n _).1 f130    hfm PC hPnull hbij.mapsTo fun j hj x hx => ?_131  set B := {y : Fin n → O | ∀ i, y i - x i ∈ m ^ j} with hBdef132  have hmj : m ^ j ≤ m := Ideal.pow_le_self (by omega)133  obtain ⟨a', ha', hfa'⟩ := hbij.surjOn hx134  have hBC : B ⊆ C := fun y hy => by135    change y ∈ residueCell O n (∏ i, g i)136    rw [(residue_cell_cylinder O n _).1 x hx]137    exact fun i => hmj (hy i)138  have hpre : f ⁻¹' B ∩ PC = Set.pi Set.univ139      (fun i => {b : Fin (g i).natDegree → O | ∀ k, b k - a' i k ∈ m ^ j}) := by140    ext a141    constructor142    · rintro ⟨hfa, haP⟩143      simpa using (factor_product_congruence_iff O ι g hc j a a' haP ha').1144        fun k => by have h := hfa k; rw [← hfa'] at h; exact h145    · intro ha146      simp only [Set.mem_pi, Set.mem_univ, Set.mem_ofPred_eq, true_implies] at ha147      have haP : a ∈ PC := by148        simp only [PC, Set.mem_pi, Set.mem_univ, true_implies]149        intro i150        rw [(residue_cell_cylinder O _ _).1 _ (ha' i (Set.mem_univ i))]151        exact fun k => hmj (ha i k)152      refine ⟨?_, haP⟩153      change ∀ k, f a k - x k ∈ m ^ j154      rw [← hfa']155      exact (factor_product_congruence_iff O ι g hc j a a' haP ha').2 ha156  have hmass : coefficientMeasure O n B = q⁻¹ ^ (n * j) := by157    have := coefficient_uniformizer_cylinder_mass O htop n pi hpi j x158    rw [← hpi.maximalIdeal_eq] at this159    rw [← this]160    congr 1161    ext y; exact (finite_coordinate_adic_congruence O n m j y x).symm162  rw [← MeasureTheory.measure_inter_conull hPnull, hpre, hPball j hj a' ha', cellMeasure,163    MeasureTheory.Measure.smul_apply, smul_eq_mul, MeasureTheory.Measure.restrict_apply' hCm,164    Set.inter_eq_left.mpr hBC, hCmass, hmass]165  obtain ⟨k, rfl⟩ : ∃ k, j = k + 1 := ⟨j - 1, by omega⟩166  rw [Nat.add_sub_cancel, mul_add, mul_one, pow_add, ← mul_assoc, mul_comm _ (q⁻¹ ^ (n * k)),167    mul_assoc, ENNReal.inv_mul_cancel hqi0 hqit, mul_one]168 169/-! ### Reduced form cells versus monic residue cells -/170 171private theorem formPoly_coeff_fin {A : Type} [CommRing A] {n : ℕ} (a : Fin (n + 1) → A)172    (k : Fin (n + 1)) : (formPoly a).coeff (k : ℕ) = a k := by173  simp [formPoly, Polynomial.finsetSum_coeff, Polynomial.coeff_X_pow, Fin.val_inj]174 175private theorem formPoly_inj_fin {A : Type} [CommRing A] {n : ℕ} (a a' : Fin (n + 1) → A) :176    formPoly a = formPoly a' ↔ a = a' :=177  ⟨fun h => funext fun k => by rw [← formPoly_coeff_fin a k, ← formPoly_coeff_fin a' k, h],178    fun h => h ▸ rfl⟩179 180private theorem formPoly_map_fin {A B : Type} [CommRing A] [CommRing B] (f : A →+* B) {n : ℕ}181    (a : Fin (n + 1) → A) : (formPoly a).map f = formPoly (fun i => f (a i)) := by182  simp [formPoly, Polynomial.map_sum]183 184private theorem formPoly_insertOne_last_eq {A : Type} [CommRing A] {d : ℕ} (b : Fin d → A) :185    formPoly (insertOne (Fin.last d) b) = monicPolyO b := by186  unfold formPoly monicPolyO insertOne187  rw [Fin.sum_univ_castSucc]188  simp [add_comm]189 190private theorem reducedFormCell_last_eq (O : Type) [CommRing O] [IsLocalRing O] (d : ℕ)191    (g : Fin (d + 1) → IsLocalRing.ResidueField O) :192    reducedFormCell O d (Fin.last d) g = residueCell O d (formPoly g) := by193  ext b194  simp only [reducedFormCell, normalizedFormCell, residueCell, Set.mem_ofPred_eq]195  have h1 : insertOne (Fin.last d) b (Fin.last d) = 1 := by simp [insertOne]196  rw [← formPoly_insertOne_last_eq, formPoly_map_fin, formPoly_inj_fin]197  simp only [h1, true_and]198  rfl199 200private theorem insertOne_last_comp_rev {A : Type} [CommRing A] {r : ℕ} (b : Fin r → A) :201    insertOne (Fin.last r) (b ∘ Fin.rev) = insertOne 0 b ∘ Fin.rev := by202  funext i203  refine Fin.lastCases ?_ (fun j => ?_) i204  · simp [insertOne]205  · simp [insertOne, Fin.rev_castSucc]206 207private theorem mem_reducedFormCell_zero_iff (O : Type) [CommRing O] [IsLocalRing O] (r : ℕ)208    (b : Fin r → O) :209    b ∈ reducedFormCell O r 0 (Pi.single 0 1) ↔210      b ∘ Fin.rev ∈ residueCell O r (Polynomial.X ^ r) := by211  have hX : (Polynomial.X ^ r : Polynomial (IsLocalRing.ResidueField O))212      = formPoly (Pi.single (Fin.last r) 1) := by213    have h0 : monicPolyO (0 : Fin r → IsLocalRing.ResidueField O) = Polynomial.X ^ r := by214      simp [monicPolyO]215    rw [← h0, ← formPoly_insertOne_last_eq]216    congr 1217    funext i218    refine Fin.lastCases ?_ (fun j => ?_) i219    · simp [insertOne]220    · simp [insertOne, Fin.castSucc_ne_last]221  rw [hX, ← reducedFormCell_last_eq]222  simp only [reducedFormCell, normalizedFormCell, Set.mem_ofPred_eq, insertOne_last_comp_rev]223  have h0 : insertOne 0 b 0 = 1 := by simp [insertOne]224  simp only [Function.comp_apply, Fin.rev_last, h0, true_and]225  constructor226  · intro h; rw [← (show (Pi.single 0 1 : Fin (r+1) → IsLocalRing.ResidueField O) ∘ Fin.rev227        = Pi.single (Fin.last r) 1 from ?_), ← h]228    · rfl229    · funext i; simp [Pi.single_apply, Fin.rev_eq_iff]230  · intro h231    funext i232    have := congrFun h (Fin.rev i)233    simp only [residueVector, Function.comp_apply, Fin.rev_rev] at this ⊢234    rw [this]; simp [Pi.single_apply, Fin.rev_eq_iff]235 236private theorem comp_rev_comp_rev {A : Type} {r : ℕ} (b : Fin r → A) :237    (b ∘ Fin.rev) ∘ Fin.rev = b := by238  funext i; simp239 240/-- Reduced form cells normalized at the last coordinate are monic residue cells; coordinate241reversal is a bijection, compatible with congruences and measure preserving, from the reduced form242cell of `X ^ r` normalized at `0` onto the monic residue cell of `X ^ r`. -/243theorem form_cell_monic_identification (O : Type) [CommRing O] [IsDomain O]244    [IsDiscreteValuationRing O] [IsAdicComplete (IsLocalRing.maximalIdeal O) O]245    [Finite (IsLocalRing.ResidueField O)] [TopologicalSpace O] [IsTopologicalRing O]246    [CompactSpace O] [T2Space O] [SecondCountableTopology O] [MeasurableSpace O] [BorelSpace O]247    (htop : IsAdic (IsLocalRing.maximalIdeal O)) (r : ℕ) :248    (∀ (d : ℕ) (g : Fin (d+1) → IsLocalRing.ResidueField O),249      reducedFormCell O d (Fin.last d) g = residueCell O d (formPoly g)) ∧250    Set.BijOn (fun b : Fin r → O => b ∘ Fin.rev) (reducedFormCell O r 0 (Pi.single 0 1))251      (residueCell O r (Polynomial.X ^ r)) ∧252    (∀ (L : ℕ) (b b' : Fin r → O), (∀ j, b j - b' j ∈ (IsLocalRing.maximalIdeal O) ^ L) ↔253      ∀ j, (b ∘ Fin.rev) j - (b' ∘ Fin.rev) j ∈ (IsLocalRing.maximalIdeal O) ^ L) ∧254    MeasureTheory.MeasurePreserving (fun b : Fin r → O => b ∘ Fin.rev)255      (cellMeasure O r (reducedFormCell O r 0 (Pi.single 0 1)))256      (cellMeasure O r (residueCell O r (Polynomial.X ^ r))) := by257  have hcong : ∀ (L : ℕ) (b b' : Fin r → O),258      (∀ j, b j - b' j ∈ (IsLocalRing.maximalIdeal O) ^ L) ↔259        ∀ j, (b ∘ Fin.rev) j - (b' ∘ Fin.rev) j ∈ (IsLocalRing.maximalIdeal O) ^ L :=260    fun L b b' => ⟨fun h j => h _, fun h j => by simpa using h (Fin.rev j)⟩261  refine ⟨reducedFormCell_last_eq O, ?_, hcong, ?_⟩262  · refine ⟨fun b hb => (mem_reducedFormCell_zero_iff O r b).1 hb, ?_,263      fun b' hb' => ⟨b' ∘ Fin.rev, ?_, ?_⟩⟩264    · intro b _ b' _ h265      simpa [comp_rev_comp_rev] using congrArg (fun c : Fin r → O => c ∘ Fin.rev) h266    · rw [mem_reducedFormCell_zero_iff]; simpa [comp_rev_comp_rev] using hb'267    · simp [comp_rev_comp_rev]268  let R : (Fin r → O) ≃ᵐ (Fin r → O) :=269    { toFun := fun b => b ∘ Fin.rev270      invFun := fun b => b ∘ Fin.rev271      left_inv := comp_rev_comp_rev272      right_inv := comp_rev_comp_rev273      measurable_toFun := measurable_pi_iff.2 (fun j => measurable_pi_apply _)274      measurable_invFun := measurable_pi_iff.2 (fun j => measurable_pi_apply _) }275  have hR : ∀ b, R b = b ∘ Fin.rev := fun _ => rfl276  have hμ : MeasureTheory.MeasurePreserving R (coefficientMeasure O r)277      (coefficientMeasure O r) := by278    refine ⟨R.measurable, ?_⟩279    have huniv : coefficientMeasure O r Set.univ = 1 := by280      simpa using coefficient_cylinder_mass O htop r 0 0281    have : MeasureTheory.IsFiniteMeasure (coefficientMeasure O r) := ⟨by simp [huniv]⟩282    refine finite_measures_from_cylinders O (Fin r → O) (IsLocalRing.maximalIdeal O) _ _283      (finite_coordinate_borel_cylinders O _ htop r) fun j x => ?_284    have hset : ∀ z : Fin r → O, {y | adicCongr (IsLocalRing.maximalIdeal O) j y z}285        = {y | ∀ i, y i - z i ∈ (IsLocalRing.maximalIdeal O) ^ j} := fun z => by286      ext y; exact finite_coordinate_adic_congruence O r _ j y z287    rw [hset, R.map_apply]288    have hpre : R ⁻¹' {y | ∀ i, y i - x i ∈ (IsLocalRing.maximalIdeal O) ^ j}289        = {y | ∀ i, y i - (x ∘ Fin.rev) i ∈ (IsLocalRing.maximalIdeal O) ^ j} := by290      ext y291      simp only [Set.mem_preimage, Set.mem_ofPred_eq, hR]292      rw [hcong j y (x ∘ Fin.rev)]293      simp294    rw [hpre, coefficient_cylinder_mass O htop, coefficient_cylinder_mass O htop]295  have hpre : R ⁻¹' residueCell O r (Polynomial.X ^ r) = reducedFormCell O r 0 (Pi.single 0 1) := by296    ext b; simp [hR, mem_reducedFormCell_zero_iff]297  have h2 := hμ.restrict_preimage_emb R.measurableEmbedding (residueCell O r (Polynomial.X ^ r))298  have hmass := hμ.measure_preimage_emb R.measurableEmbedding (residueCell O r (Polynomial.X ^ r))299  rw [hpre] at h2 hmass300  refine ⟨R.measurable, ?_⟩301  unfold cellMeasure302  rw [MeasureTheory.Measure.map_smul, show (fun b : Fin r → O => b ∘ Fin.rev) = ⇑R from rfl,303    h2.map_eq, hmass]304  exact R.measurable.aemeasurable305 306/-! ### Measurability of form products -/307 308/-- The reduced form-product map is Borel measurable. -/309theorem form_product_measurable (O : Type) [CommRing O] [IsDomain O] [IsDiscreteValuationRing O]310    [IsAdicComplete (IsLocalRing.maximalIdeal O) O] [Finite (IsLocalRing.ResidueField O)]311    [TopologicalSpace O] [IsTopologicalRing O] [CompactSpace O] [T2Space O]312    [SecondCountableTopology O] [MeasurableSpace O] [BorelSpace O]313    (htop : IsAdic (IsLocalRing.maximalIdeal O)) (ι : Type) [Fintype ι] (d : ι → ℕ)314    (ν : ∀ i, Fin (d i + 1)) (g : ∀ i, Fin (d i + 1) → IsLocalRing.ResidueField O)315    (hgν : ∀ i, g i (ν i) = 1) (hc : FormsCoprime d g) (μ : Fin ((∑ i, d i) + 1))316    (hμ : formProd d g μ = 1) :317    Measurable (reducedFormProduct O d ν g μ) := by318  set m := IsLocalRing.maximalIdeal O319  set f := reducedFormProduct O d ν g μ320  set PC : Set (∀ i, Fin (d i) → O) :=321    Set.pi Set.univ (fun i ↦ reducedFormCell O (d i) (ν i) (g i))322  have hPC : MeasurableSet PC := MeasurableSet.univ_pi (fun i ↦323    (normalized_form_cell_cylinder_mass O htop (d i) (ν i) (g i) (hgν i)).2.2.2.1)324  have hoff : ∀ a, a ∉ PC → f a = 0 := fun a ha ↦ by325    simp only [f, reducedFormProduct]326    exact ite_eq_right fun h ↦ ha fun i _ ↦ h i327  have hball : ∀ (k : ℕ) (L : ℕ) (x : Fin k → O),328      MeasurableSet {b : Fin k → O | ∀ j, b j - x j ∈ m ^ L} := fun k L x ↦ by329    have hk := finite_coordinate_borel_cylinders O m htop k330    have : @MeasurableSet _ (adicCylinderSpace m (Fin k → O)) {b | adicCongr m L b x} :=331      MeasurableSpace.measurableSet_generateFrom (Or.inr ⟨L, x, rfl⟩)332    rw [← hk] at this333    convert this using 1334    ext b335    exact (finite_coordinate_adic_congruence O k m L b x).symm336  have hk := finite_coordinate_borel_cylinders O m htop (∑ i, d i)337  change @Measurable _ _ _ (inferInstance : MeasurableSpace (Fin _ → O)) f338  rw [hk]339  refine measurable_generateFrom ?_340  rintro s (rfl | ⟨L, x, rfl⟩)341  · simp342  obtain ⟨_, hsymm, htrans, -, -⟩ := adic_congruence_rules O (Fin (∑ i, d i) → O) m343  by_cases hne : ∃ a₀ ∈ PC, adicCongr m L (f a₀) x344  · obtain ⟨a₀, ha₀, hfa₀⟩ := hne345    have heq : f ⁻¹' {y | adicCongr m L y x} =346        (PC ∩ Set.pi Set.univ (fun i ↦ {b : Fin (d i) → O | ∀ j, b j - a₀ i j ∈ m ^ L})) ∪347        (PCᶜ ∩ {_a | adicCongr m L (0 : Fin (∑ i, d i) → O) x}) := by348      ext a349      simp only [Set.mem_preimage, Set.mem_ofPred_eq, Set.mem_union, Set.mem_inter_iff,350        Set.mem_compl_iff, Set.mem_univ_pi]351      by_cases ha : a ∈ PC352      · simp only [ha, true_and, not_true_eq_false, false_and, or_false]353        constructor354        · intro h355          have h2 : adicCongr m L (f a) (f a₀) := htrans _ _ _ _ h (hsymm _ _ _ hfa₀)356          rw [finite_coordinate_adic_congruence] at h2357          exact form_product_congruence_reflects O ι d ν g hgν hc μ hμ a a₀ ha ha₀ L h2358        · intro h359          refine htrans _ _ _ _ ?_ hfa₀360          rw [finite_coordinate_adic_congruence]361          exact (form_product_maps_to_and_preserves O ι d ν g μ hμ a a₀ ha ha₀).2.2.2 L h362      · simp only [ha, false_and, false_or, not_false_eq_true, true_and, hoff a ha]363    rw [heq]364    exact (hPC.inter (MeasurableSet.univ_pi (fun i ↦ hball _ _ _))).union365      (hPC.compl.inter (MeasurableSet.const _))366  · push Not at hne367    have heq : f ⁻¹' {y | adicCongr m L y x} =368        PCᶜ ∩ {_a | adicCongr m L (0 : Fin (∑ i, d i) → O) x} := by369      ext a370      simp only [Set.mem_preimage, Set.mem_ofPred_eq, Set.mem_inter_iff, Set.mem_compl_iff]371      by_cases ha : a ∈ PC372      · simp only [ha, not_true_eq_false, false_and, iff_false]373        exact hne a ha374      · simp only [ha, not_false_eq_true, true_and, hoff a ha]375    rw [heq]376    exact hPC.compl.inter (MeasurableSet.const _)377 378/-! ### Products of reduced form cells -/379 380/-- The homogeneous analogue of `factor_cells_measure_preserving`: the reduced form product map381pushes the product of the normalized reduced form cell measures forward to the normalized reduced382form cell measure of the product form. -/383theorem form_cells_measure_preserving (O : Type) [CommRing O] [IsDomain O]Lemma 7.1384    [IsDiscreteValuationRing O] [IsAdicComplete (IsLocalRing.maximalIdeal O) O]385    [Finite (IsLocalRing.ResidueField O)] [TopologicalSpace O] [IsTopologicalRing O]386    [CompactSpace O] [T2Space O] [SecondCountableTopology O] [MeasurableSpace O] [BorelSpace O]387    (htop : IsAdic (IsLocalRing.maximalIdeal O)) (ι : Type) [Fintype ι] (d : ι → ℕ)388    (ν : ∀ i, Fin (d i + 1)) (g : ∀ i, Fin (d i + 1) → IsLocalRing.ResidueField O)389    (hgν : ∀ i, g i (ν i) = 1) (hc : FormsCoprime d g) (μ : Fin ((∑ i, d i) + 1))390    (hμ : formProd d g μ = 1)391    [hσ : ∀ i, MeasureTheory.SigmaFinite392      (cellMeasure O (d i) (reducedFormCell O (d i) (ν i) (g i)))] :393    MeasureTheory.MeasurePreserving (reducedFormProduct O d ν g μ)394      (MeasureTheory.Measure.pi395        (fun i => cellMeasure O (d i) (reducedFormCell O (d i) (ν i) (g i))))396      (cellMeasure O (∑ i, d i) (reducedFormCell O (∑ i, d i) μ (formProd d g))) := by397  let m := IsLocalRing.maximalIdeal O398  let f := reducedFormProduct O d ν g μ399  let P := MeasureTheory.Measure.pi400    (fun i => cellMeasure O (d i) (reducedFormCell O (d i) (ν i) (g i)))401  let PC := Set.pi Set.univ (fun i => reducedFormCell O (d i) (ν i) (g i))402  let D := reducedFormCell O (∑ i, d i) μ (formProd d g)403  have hfm : Measurable f := form_product_measurable O htop ι d ν g hgν hc μ hμ404  obtain ⟨hPprob, hPnull, hPball⟩ := form_cell_product_measure O htop ι d ν g hgν405  obtain ⟨-, hDball, -, hDmeas, -, hDprob, hDmass⟩ :=406    normalized_form_cell_cylinder_mass O htop (∑ i, d i) μ (formProd d g) hμ407  refine measurePreserving_cellMeasure_of_balls O htop P _ D hDmeas hDball f hfm PC hPnull408    (fun a ha => (form_product_maps_to_and_preserves O ι d ν g μ hμ a a ha ha).1)409    fun L hL x hx => ?_410  have hmL : m ^ L ≤ m := Ideal.pow_le_self (by omega)411  rw [hDmass L x hL hx]412  obtain ⟨a', ha', rfl⟩ := (form_product_bijection O ι d ν g hgν hc μ hμ).surjOn hx413  have hsub : Set.pi Set.univ (fun i => {b : Fin (d i) → O | ∀ j, b j - a' i j ∈ m ^ L}) ⊆414      PC := by415    intro a ha i _416    change a i ∈ reducedFormCell O (d i) (ν i) (g i)417    rw [(normalized_form_cell_cylinder_mass O htop (d i) (ν i) (g i) (hgν i)).2.1 (a' i)418      (ha' i trivial)]419    exact fun j => hmL (ha i trivial j)420  rw [← MeasureTheory.measure_inter_conull hPnull, ← hPball L hL a' ha']421  congr 1422  ext a423  constructor424  · rintro ⟨h1, h2⟩ i _ j425    exact form_product_congruence_reflects O ι d ν g hgν hc μ hμ a a' h2 ha' L h1 i j426  · exact fun ha => ⟨(form_product_maps_to_and_preserves O ι d ν g μ hμ a a' (hsub ha)427      ha').2.2.2 L (fun i j => ha i trivial j), hsub ha⟩428 429/-! ### Projective cells -/430 431/-- The number of residue classes modulo `𝔪 ^ L` of units is `q ^ L - q ^ (L - 1)`. -/432private theorem card_units_mod_pow (O : Type) [CommRing O] [IsDomain O]433    [IsDiscreteValuationRing O] [Finite (IsLocalRing.ResidueField O)] (L : ℕ) (hL : 1 ≤ L) :434    Nat.card {c : O ⧸ (IsLocalRing.maximalIdeal O)^L |435        ∃ y, Ideal.Quotient.mk _ y = c ∧ y ∉ IsLocalRing.maximalIdeal O}436      = Nat.card (IsLocalRing.ResidueField O) ^ L -437        Nat.card (IsLocalRing.ResidueField O) ^ (L-1) := by438  set m := IsLocalRing.maximalIdeal O439  have hle : m ^ L ≤ m := Ideal.pow_le_self (by omega)440  set J : Ideal (O ⧸ m ^ L) := m.map (Ideal.Quotient.mk (m ^ L))441  have hU : {c : O ⧸ m^L | ∃ y, Ideal.Quotient.mk _ y = c ∧ y ∉ m} =442      (J : Set (O ⧸ m^L))ᶜ := by443    ext c444    simp only [Set.mem_ofPred_eq, Set.mem_compl_iff, SetLike.mem_coe, J,445      Ideal.mem_map_iff_of_surjective _ Ideal.Quotient.mk_surjective]446    constructor447    · rintro ⟨y, rfl, hy⟩ ⟨z, hz, hzy⟩448      exact hy (by simpa using m.sub_mem hz (hle (Ideal.Quotient.eq.mp hzy)))449    · intro h450      obtain ⟨y, rfl⟩ := Ideal.Quotient.mk_surjective c451      exact ⟨y, rfl, fun hy => h ⟨y, hy, rfl⟩⟩452  have hQ := residue_quotient_card O L453  have hq0 : 0 < Nat.card (IsLocalRing.ResidueField O) := Nat.card_pos454  have hfin : Finite (O ⧸ m ^ L) := Nat.finite_of_card_ne_zero (by rw [hQ]; positivity)455  have hcard := Submodule.card_eq_card_quotient_mul_card J456  have hquot : Nat.card ((O ⧸ m ^ L) ⧸ J) = Nat.card (IsLocalRing.ResidueField O) :=457    Nat.card_congr (DoubleQuot.quotQuotEquivQuotOfLE hle).toEquiv458  rw [hquot, hQ] at hcard459  have hJ : Nat.card J = Nat.card (IsLocalRing.ResidueField O) ^ (L - 1) := by460    obtain ⟨k, rfl⟩ : ∃ k, L = k + 1 := ⟨L - 1, by omega⟩461    rw [pow_succ] at hcard462    simpa using (Nat.eq_of_mul_eq_mul_right hq0 hcard).symm463  rw [hU, Nat.card_coe_set_eq]464  have h2 := Set.ncard_add_ncard_compl (J : Set (O ⧸ m^L))465  have h3 : (J : Set (O ⧸ m^L)).ncard = Nat.card (IsLocalRing.ResidueField O) ^ (L - 1) := by466    rw [← hJ]; rfl467  rw [h3, hQ] at h2468  omega469 470/-- The set of vectors with unit `μ`-coordinate that are congruent modulo `𝔪 ^ L` to a multiple471of `bt` (with `bt μ = 1`) is measurable, of mass `(q ^ L - q ^ (L - 1)) / (q ^ L) ^ (n + 1)`. -/472private theorem unit_multiple_cylinder_mass (O : Type) [CommRing O] [IsDomain O]473    [IsDiscreteValuationRing O] [IsAdicComplete (IsLocalRing.maximalIdeal O) O]474    [Finite (IsLocalRing.ResidueField O)] [TopologicalSpace O] [IsTopologicalRing O]475    [CompactSpace O] [T2Space O] [SecondCountableTopology O] [MeasurableSpace O] [BorelSpace O]476    (htop : IsAdic (IsLocalRing.maximalIdeal O)) (n L : ℕ) (hL : 1 ≤ L) (μ : Fin (n + 1))477    (bt : Fin (n + 1) → O) (hb : bt μ = 1) :478    MeasurableSet {a : Fin (n+1) → O | a μ ∉ IsLocalRing.maximalIdeal O ∧479      ∀ j, a j - a μ * bt j ∈ (IsLocalRing.maximalIdeal O) ^ L} ∧480    coefficientMeasure O (n+1) {a : Fin (n+1) → O | a μ ∉ IsLocalRing.maximalIdeal O ∧481      ∀ j, a j - a μ * bt j ∈ (IsLocalRing.maximalIdeal O) ^ L}482      = ((Nat.card (IsLocalRing.ResidueField O) ^ L -483          Nat.card (IsLocalRing.ResidueField O) ^ (L-1) : ℕ) : ℝ≥0∞) /484        ((Nat.card (IsLocalRing.ResidueField O) ^ L) ^ (n+1) : ℕ) := by485  set m := IsLocalRing.maximalIdeal O486  have hle : m ^ L ≤ m := Ideal.pow_le_self (by omega)487  have hQ := residue_quotient_card O L488  have : Finite (O ⧸ m ^ L) :=489    Nat.finite_of_card_ne_zero (by rw [hQ]; exact (pow_pos Nat.card_pos L).ne')490  let mk := Ideal.Quotient.mk (m ^ L)491  let π : (Fin (n+1) → O) →+ (Fin (n+1) → O ⧸ m ^ L) :=492    (mk : O →+ O ⧸ m ^ L).compLeft (Fin (n+1))493  have hπ : ∀ a j, π a j = mk (a j) := fun _ _ => rfl494  set U := {c : O ⧸ m^L | ∃ y, mk y = c ∧ y ∉ m} with hUdef495  set S := (fun c : O ⧸ m^L => fun j => c * mk (bt j)) '' U with hSdef496  have hE : {a : Fin (n+1) → O | a μ ∉ m ∧ ∀ j, a j - a μ * bt j ∈ m ^ L} = π ⁻¹' S := by497    ext a498    simp only [Set.mem_ofPred_eq, Set.mem_preimage, hSdef, hUdef, Set.mem_image]499    constructor500    · rintro ⟨h1, h2⟩501      refine ⟨mk (a μ), ⟨a μ, rfl, h1⟩, funext fun j => ?_⟩502      rw [hπ, ← map_mul]503      exact (Ideal.Quotient.eq.mpr (h2 j)).symm504    · rintro ⟨c, ⟨y, rfl, hy⟩, hc⟩505      have hj : ∀ j, mk (a j) = mk y * mk (bt j) := fun j => by rw [← hπ, ← hc]506      have hμ' : mk (a μ) = mk y := by rw [hj μ, hb, map_one, mul_one]507      have hyμ : a μ - y ∈ m ^ L := Ideal.Quotient.eq.mp hμ'508      refine ⟨fun h => hy (by simpa using m.sub_mem h (hle hyμ)),509        fun j => Ideal.Quotient.eq.mp ?_⟩510      rw [map_mul, hj j, hμ']511  have hsurj : Function.Surjective π := fun v =>512    ⟨fun j => (Ideal.Quotient.mk_surjective (v j)).choose,513      funext fun j => (Ideal.Quotient.mk_surjective (v j)).choose_spec⟩514  have hball : ∀ x0 : Fin (n+1) → O,515      MeasurableSet {b' : Fin (n+1) → O | ∀ j, b' j - x0 j ∈ m ^ L} := by516    intro x0517    have : @MeasurableSet _ (adicCylinderSpace m (Fin (n+1) → O))518        {b' : Fin (n+1) → O | ∀ j, b' j - x0 j ∈ m ^ L} := by519      apply MeasurableSpace.measurableSet_generateFrom520      refine Or.inr ⟨L, x0, ?_⟩521      ext y522      simp only [Set.mem_ofPred_eq]523      rw [finite_coordinate_adic_congruence]524    rwa [← finite_coordinate_borel_cylinders O m htop (n+1)] at this525  have hfib : ∀ v, MeasurableSet {x | π x = v} := by526    intro v527    obtain ⟨x0, rfl⟩ := hsurj v528    convert hball x0 using 1529    ext x530    simp only [Set.mem_ofPred_eq]531    exact ⟨fun h j => Ideal.Quotient.eq.mp (by rw [← hπ, ← hπ, h]),532      fun h => funext fun j => Ideal.Quotient.eq.mpr (h j)⟩533  have := coefficient_measure_probability O htop (n+1)534  have : MeasureTheory.Measure.IsAddLeftInvariant (coefficientMeasure O (n+1)) := by535    unfold coefficientMeasure; infer_instance536  have hmeas : MeasurableSet (π ⁻¹' S) := by537    have : π ⁻¹' S = ⋃ s ∈ S, {x | π x = s} := by ext; simp538    rw [this]539    exact MeasurableSet.biUnion (Set.to_countable S) fun s _ => hfib s540  refine ⟨hE ▸ hmeas, ?_⟩541  rw [hE, finite_quotient_event_mass _ _ (coefficientMeasure O (n+1)) π hsurj hfib S]542  have hS : Nat.card S = Nat.card U :=543    Nat.card_image_of_injective (fun c c' h => by simpa [hb] using congrFun h μ) _544  rw [hS, card_units_mod_pow O L hL, Nat.card_fun, hQ, Nat.card_fin]545 546private theorem projective_mass_ratio (q n L : ℕ) (hq : 1 < q) (hL : 1 ≤ L) :547    (((q : ℝ≥0∞) - 1) * (q : ℝ≥0∞)⁻¹ ^ (n+1))⁻¹ *548        (((q ^ L - q ^ (L-1) : ℕ) : ℝ≥0∞) / ((q ^ L) ^ (n+1) : ℕ))549      = (q : ℝ≥0∞)⁻¹ ^ (n * (L-1)) := by550  obtain ⟨k, rfl⟩ : ∃ k, L = k + 1 := ⟨L - 1, by omega⟩551  simp only [Nat.add_sub_cancel]552  rw [show q ^ (k+1) - q ^ k = q ^ k * (q - 1) by rw [pow_succ, Nat.mul_sub, mul_one]]553  have hq0 : (q : ℝ≥0∞) ≠ 0 := by exact_mod_cast (by omega : q ≠ 0)554  have hqt : (q : ℝ≥0∞) ≠ ⊤ := ENNReal.natCast_ne_top q555  have hqr : (q : ℝ≥0∞) * (q : ℝ≥0∞)⁻¹ = 1 := ENNReal.mul_inv_cancel hq0 hqt556  have hq1 : ((q - 1 : ℕ) : ℝ≥0∞) = (q : ℝ≥0∞) - 1 := by557    rw [ENNReal.natCast_sub]; simp558  have hs0 : (q : ℝ≥0∞) - 1 ≠ 0 := by559    rw [← hq1]; exact_mod_cast (by omega : q - 1 ≠ 0)560  have hst : (q : ℝ≥0∞) - 1 ≠ ⊤ := ENNReal.sub_ne_top hqt561  push_cast562  rw [div_eq_mul_inv, ENNReal.mul_inv (Or.inl hs0) (Or.inl hst), ← pow_mul]563  simp only [ENNReal.inv_pow, inv_inv]564  set r := (q : ℝ≥0∞)⁻¹565  set Q := (q : ℝ≥0∞)566  set s := Q - 1567  have hss : s⁻¹ * s = 1 := ENNReal.inv_mul_cancel hs0 hst568  rw [show (k+1) * (n+1) = (n + 1 + k) + n * k by ring, pow_add r]569  have hpow : Q ^ (n+1+k) * r ^ (n+1+k) = 1 := by rw [← mul_pow, hqr, one_pow]570  calc s⁻¹ * Q ^ (n + 1) * (Q ^ k * s * (r ^ (n + 1 + k) * r ^ (n * k)))571      = (s⁻¹ * s) * (Q ^ (n+1+k) * r ^ (n+1+k)) * r ^ (n * k) := by ring572    _ = r ^ (n * k) := by rw [hss, hpow, one_mul, one_mul]573 574private theorem projectiveNormalize_alg (O : Type) [CommRing O] [IsLocalRing O] (n : ℕ)575    (G : Fin (n + 1) → IsLocalRing.ResidueField O) (μ : Fin (n + 1)) (hGμ : G μ = 1) :576    Set.MapsTo (projectiveNormalize O n G μ) (projectiveCell O n G) (reducedFormCell O n μ G) ∧577    Set.SurjOn (projectiveNormalize O n G μ) (projectiveCell O n G) (reducedFormCell O n μ G) ∧578    (∀ a ∈ projectiveCell O n G, ∀ a' ∈ projectiveCell O n G,579      projectiveNormalize O n G μ a = projectiveNormalize O n G μ a' ↔580        ∃ u : Oˣ, a' = (u : O) • a) := by581  set PC := projectiveCell O n G582  have hunit : ∀ a ∈ PC, ∃ v : Oˣ, a μ = v ∧583      residueVector O a = IsLocalRing.residue O (v : O) • G := by584    rintro a ⟨-, c, hc, hac⟩585    have hr : IsLocalRing.residue O (a μ) = c := by586      simpa [residueVector, hGμ] using congrFun hac μ587    have hu : IsUnit (a μ) := by588      rw [← IsLocalRing.notMem_maximalIdeal, ← IsLocalRing.residue_eq_zero_iff, hr]; exact hc589    exact ⟨hu.unit, rfl, by rw [hac]; simp [hr]⟩590  have hnorm : ∀ (a : Fin (n+1) → O) (v : Oˣ), a μ = v →591      normalizeAt μ a = ((v⁻¹ : Oˣ) : O) • a := fun a v hv => by592    simp only [normalizeAt, hv, Ring.inverse_unit]593  have hins : ∀ w : Fin (n+1) → O, w μ = 1 → insertOne μ (dropCoord μ w) = w := fun w hw => by594    simp only [insertOne, dropCoord]595    rw [← hw]; exact Fin.insertNth_self_removeNth μ w596  have hnm : ∀ a ∈ PC, projectiveNormalize O n G μ a = dropCoord μ (normalizeAt μ a) :=597    fun a ha => ite_eq_left ha598  have hnμ : ∀ a ∈ PC, normalizeAt μ a μ = 1 := by599    intro a ha600    obtain ⟨v, hv, -⟩ := hunit a ha601    rw [hnorm a v hv]; simp [hv]602  have hinj : ∀ a ∈ PC, ∀ a' ∈ PC,603      projectiveNormalize O n G μ a = projectiveNormalize O n G μ a' ↔604        normalizeAt μ a = normalizeAt μ a' := by605    intro a ha a' ha'606    rw [hnm a ha, hnm a' ha']607    exact ⟨fun h => by rw [← hins _ (hnμ a ha), ← hins _ (hnμ a' ha'), h], fun h => by rw [h]⟩608  refine ⟨?_, ?_, ?_⟩609  · intro a ha610    obtain ⟨v, hv, hres⟩ := hunit a ha611    change insertOne μ (projectiveNormalize O n G μ a) ∈ normalizedFormCell O n μ G612    rw [hnm a ha, hins _ (hnμ a ha)]613    refine ⟨hnμ a ha, ?_⟩614    rw [hnorm a v hv]615    funext i616    have := congrFun hres i617    simp only [residueVector, Pi.smul_apply, smul_eq_mul, map_mul] at this ⊢618    rw [this, ← mul_assoc, ← map_mul, Units.inv_mul, map_one, one_mul]619  · intro b hb620    obtain ⟨h1, h2⟩ : insertOne μ b ∈ normalizedFormCell O n μ G := hb621    have hPC : insertOne μ b ∈ PC :=622      ⟨⟨μ, by rw [h1]; exact isUnit_one⟩, 1, one_ne_zero, by rw [h2, one_smul]⟩623    refine ⟨insertOne μ b, hPC, ?_⟩624    rw [hnm _ hPC]625    simp only [normalizeAt]626    rw [h1, Ring.inverse_one, one_smul]627    simp only [dropCoord, insertOne, Fin.removeNth_insertNth]628  · intro a ha a' ha'629    rw [hinj a ha a' ha']630    obtain ⟨v, hv, -⟩ := hunit a ha631    obtain ⟨v', hv', -⟩ := hunit a' ha'632    rw [hnorm a v hv, hnorm a' v' hv']633    constructor634    · intro h635      refine ⟨v' * v⁻¹, funext fun j => ?_⟩636      have := congrFun h j637      simp only [Pi.smul_apply, smul_eq_mul] at this ⊢638      calc a' j = (v' : O) * (((v'⁻¹ : Oˣ) : O) * a' j) := by639              rw [← mul_assoc, Units.mul_inv, one_mul]640        _ = _ := by rw [← this]; simp only [Units.val_mul]; ring641    · rintro ⟨u, rfl⟩642      obtain rfl : v' = u * v := by643        ext; rw [← hv', Units.val_mul, ← hv]; simp644      funext j645      simp only [Pi.smul_apply, smul_eq_mul, mul_inv_rev, Units.val_mul]646      rw [← mul_assoc, mul_assoc (v⁻¹ : Oˣ).val, Units.inv_mul, mul_one]647 648private theorem projectiveNormalize_preimage_ball (O : Type) [CommRing O] [IsLocalRing O]649    (n : ℕ) (G : Fin (n + 1) → IsLocalRing.ResidueField O) (μ : Fin (n + 1)) (L : ℕ) (hL : 1 ≤ L)650    (x : Fin n → O) (hx : x ∈ reducedFormCell O n μ G) :651    projectiveCell O n G ∩652        projectiveNormalize O n G μ ⁻¹' {y | ∀ j, y j - x j ∈ (IsLocalRing.maximalIdeal O) ^ L}653      = {a | a μ ∉ IsLocalRing.maximalIdeal O ∧654          ∀ j, a j - a μ * insertOne μ x j ∈ (IsLocalRing.maximalIdeal O) ^ L} := by655  set m := IsLocalRing.maximalIdeal O656  have hle : m ^ L ≤ m := Ideal.pow_le_self (by omega)657  obtain ⟨h1, h2⟩ : insertOne μ x ∈ normalizedFormCell O n μ G := hx658  have hxs : ∀ i, insertOne μ x (μ.succAbove i) = x i := fun i => by659    simp [insertOne, Fin.insertNth_apply_succAbove]660  ext a661  simp only [Set.mem_inter_iff, Set.mem_preimage, Set.mem_ofPred_eq]662  constructor663  · rintro ⟨⟨-, c, hc, hac⟩, hB⟩664    have hG : G μ = 1 := by simpa [residueVector, h1] using (congrFun h2 μ).symm665    have hr : IsLocalRing.residue O (a μ) = c := by simpa [residueVector, hG] using congrFun hac μ666    have hu : IsUnit (a μ) := by667      rw [← IsLocalRing.notMem_maximalIdeal, ← IsLocalRing.residue_eq_zero_iff, hr]; exact hc668    refine ⟨IsLocalRing.notMem_maximalIdeal.mpr hu, fun j => ?_⟩669    rw [projectiveNormalize, ite_eq_left ⟨⟨μ, hu⟩, c, hc, hac⟩] at hB670    rcases Fin.eq_self_or_eq_succAbove μ j with rfl | ⟨i, rfl⟩671    · rw [h1, mul_one, sub_self]; exact Submodule.zero_mem _672    · have := hB i673      simp only [dropCoord, normalizeAt, Fin.removeNth, Pi.smul_apply, smul_eq_mul] at this674      rw [hxs]675      convert Ideal.mul_mem_left (m ^ L) (a μ) this using 1676      rw [mul_sub, ← mul_assoc, Ring.mul_inverse_cancel _ hu, one_mul]677  · rintro ⟨hμ, hj⟩678    have hu : IsUnit (a μ) := IsLocalRing.notMem_maximalIdeal.mp hμ679    have hres : residueVector O a = IsLocalRing.residue O (a μ) • G := by680      funext j681      have : IsLocalRing.residue O (a j) = IsLocalRing.residue O (a μ * insertOne μ x j) :=682        Ideal.Quotient.eq.mpr (hle (hj j))683      rw [← h2]684      simpa [residueVector, map_mul] using this685    have hPC : a ∈ projectiveCell O n G :=686      ⟨⟨μ, hu⟩, _, (hu.map (IsLocalRing.residue O)).ne_zero, hres⟩687    refine ⟨hPC, fun i => ?_⟩688    rw [projectiveNormalize, ite_eq_left hPC]689    simp only [dropCoord, normalizeAt, Fin.removeNth, Pi.smul_apply, smul_eq_mul]690    have h3 := Ideal.mul_mem_left (m ^ L) (Ring.inverse (a μ)) (hj (μ.succAbove i))691    rw [hxs] at h3692    convert h3 using 1693    rw [mul_sub, ← mul_assoc, Ring.inverse_mul_cancel _ hu, one_mul]694 695/-- Normalizing a primitive vector at a coordinate `μ` with `G μ = 1` maps the projective cell of696`G` onto the reduced form cell of `G`, with fibres the unit multiples, and pushes the normalized697projective cell measure forward to the normalized reduced form cell measure. -/698theorem projective_cell_normalization_pushforward (O : Type) [CommRing O] [IsDomain O]699    [IsDiscreteValuationRing O] [IsAdicComplete (IsLocalRing.maximalIdeal O) O]700    [Finite (IsLocalRing.ResidueField O)] [TopologicalSpace O] [IsTopologicalRing O]701    [CompactSpace O] [T2Space O] [SecondCountableTopology O] [MeasurableSpace O] [BorelSpace O]702    (htop : IsAdic (IsLocalRing.maximalIdeal O)) (n : ℕ)703    (G : Fin (n + 1) → IsLocalRing.ResidueField O) (μ : Fin (n + 1)) (hGμ : G μ = 1) :704    Set.MapsTo (projectiveNormalize O n G μ) (projectiveCell O n G) (reducedFormCell O n μ G) ∧705    Set.SurjOn (projectiveNormalize O n G μ) (projectiveCell O n G) (reducedFormCell O n μ G) ∧706    (∀ a ∈ projectiveCell O n G, ∀ a' ∈ projectiveCell O n G,707      projectiveNormalize O n G μ a = projectiveNormalize O n G μ a' ↔708        ∃ u : Oˣ, a' = (u : O) • a) ∧709    MeasureTheory.MeasurePreserving (projectiveNormalize O n G μ)710      (cellMeasure O (n+1) (projectiveCell O n G)) (cellMeasure O n (reducedFormCell O n μ G)) := by711  obtain ⟨hmaps, hsurjOn, hfibre⟩ := projectiveNormalize_alg O n G μ hGμ712  refine ⟨hmaps, hsurjOn, hfibre, ?_⟩713  set m := IsLocalRing.maximalIdeal O714  set nm := projectiveNormalize O n G μ715  set PC := projectiveCell O n G716  set D := reducedFormCell O n μ G717  set q := Nat.card (IsLocalRing.ResidueField O)718  have hq1 : 1 < q := Finite.one_lt_card719  have hG0 : G ≠ 0 := fun h => by simp [h] at hGμ720  obtain ⟨hPCm, hPCmass⟩ := projective_cell_mass O htop n G hG0721  obtain ⟨-, hDball, -, hDmeas, -, hDprob, hDmass⟩ :=722    normalized_form_cell_cylinder_mass O htop n μ G hGμ723  have hgen := finite_coordinate_borel_cylinders O m htop n724  have hB : ∀ (L : ℕ) (x : Fin n → O),725      {y : Fin n → O | adicCongr m L y x} = {y | ∀ j, y j - x j ∈ m ^ L} := fun L x => by726    ext y; exact finite_coordinate_adic_congruence O n m L y x727  -- the preimage of a ball around a point outside `D` is empty728  have hkey : ∀ L (x : Fin n → O), 1 ≤ L → x ∉ D →729      PC ∩ nm ⁻¹' {y | ∀ j, y j - x j ∈ m ^ L} = ∅ := fun L x hL hx => by730    refine Set.eq_empty_of_forall_notMem fun a ⟨ha, hyx⟩ => hx ?_731    change x ∈ reducedFormCell O n μ G732    rw [hDball _ (hmaps ha)]733    exact fun j => by734      simpa only [neg_sub] using m.neg_mem (Ideal.pow_le_self (by omega : L ≠ 0) (hyx j))735  have hPCB : ∀ L (x : Fin n → O), MeasurableSet (PC ∩ nm ⁻¹' {y | ∀ j, y j - x j ∈ m ^ L}) := by736    intro L x737    rcases Nat.eq_zero_or_pos L with rfl | hL738    · have : {y : Fin n → O | ∀ j, y j - x j ∈ m ^ 0} = Set.univ := by ext y; simp739      rw [this, Set.preimage_univ, Set.inter_univ]; exact hPCm740    by_cases hx : x ∈ D741    · rw [projectiveNormalize_preimage_ball O n G μ L hL x hx]742      exact (unit_multiple_cylinder_mass O htop n L hL μ (insertOne μ x) (by simp [insertOne])).1743    · rw [hkey L x hL hx]; exact MeasurableSet.empty744  have hoff : ∀ a, a ∉ PC → nm a = 0 := fun a ha => ite_eq_right ha745  have hnmm : Measurable nm := by746    change @Measurable _ _ _ (inferInstance : MeasurableSpace (Fin n → O)) nm747    rw [hgen]748    refine measurable_generateFrom ?_749    rintro s (rfl | ⟨L, x, rfl⟩)750    · simp751    rw [hB]752    have : nm ⁻¹' {y | ∀ j, y j - x j ∈ m ^ L} = (PC ∩ nm ⁻¹' {y | ∀ j, y j - x j ∈ m ^ L}) ∪753        (PCᶜ ∩ {_a | (0 : Fin n → O) ∈ {y : Fin n → O | ∀ j, y j - x j ∈ m ^ L}}) := by754      ext a755      by_cases ha : a ∈ PC756      · simp [ha]757      · simp [ha, hoff a ha]758    rw [this]759    exact (hPCB L x).union (hPCm.compl.inter (MeasurableSet.const _))760  have hμ0 : coefficientMeasure O (n+1) PC ≠ 0 := by761    rw [hPCmass]762    refine mul_ne_zero ?_ (pow_ne_zero _ (ENNReal.inv_ne_zero.mpr (ENNReal.natCast_ne_top _)))763    rw [← Nat.cast_one, ← ENNReal.natCast_sub]; exact_mod_cast (by omega : q - 1 ≠ 0)764  have hμt : coefficientMeasure O (n+1) PC ≠ ⊤ := by765    have := coefficient_measure_probability O htop (n+1)766    exact MeasureTheory.measure_ne_top _ _767  have : MeasureTheory.IsProbabilityMeasure (cellMeasure O (n+1) PC) := by768    constructor769    rw [cellMeasure, MeasureTheory.Measure.smul_apply,770      MeasureTheory.Measure.restrict_apply MeasurableSet.univ, Set.univ_inter, smul_eq_mul,771      ENNReal.inv_mul_cancel hμ0 hμt]772  refine measurePreserving_cellMeasure_of_balls O htop _ n D hDmeas hDball nm hnmm PC773    (by rw [cellMeasure, MeasureTheory.Measure.smul_apply,774      MeasureTheory.Measure.restrict_apply' hPCm, Set.compl_inter_self,775      MeasureTheory.measure_empty, smul_zero]) hmaps fun L hL x hx => ?_776  rw [cellMeasure, MeasureTheory.Measure.smul_apply, MeasureTheory.Measure.restrict_apply' hPCm,777    smul_eq_mul, Set.inter_comm, hDmass L x hL hx,778    projectiveNormalize_preimage_ball O n G μ L hL x hx,779    (unit_multiple_cylinder_mass O htop n L hL μ (insertOne μ x) (by simp [insertOne])).2, hPCmass]780  exact projective_mass_ratio q n L hq1 hL781 782end SurfaceBlowup