Lean sources / SurfaceBlowup / Blowup / ExceptionalLayers.lean

Exceptional layers of the point blow-up

843 lines · 11 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.Blowup.CurveOrders7 8/-!9# Exceptional layers of the point blow-up10 11Points and layers of the exceptional divisor of the blow-up of a two-dimensional local ring at12`(t, x)`. We identify the closed points of the exceptional fibre of the chart with monic13irreducible polynomials (affine directions) together with the point at infinity of the opposite14chart, compute their residue lengths, describe the principal layers `(e)^j ⧸ (e)^(j+1)` as15polynomial modules, and normalize glued generators at exceptional level one via Laurent16polynomial arithmetic.17 18## Main results19 20* `SurfaceBlowup.direction_point_maximal`, `SurfaceBlowup.infinity_point_maximal`: the closed21  points of the exceptional divisor and their lengths.22* `SurfaceBlowup.chart_point_eq_directionPoint`: every exceptional chart point is a direction23  point.24* `SurfaceBlowup.chart_layer_polynomial_coordinates`: layers are polynomial modules.25* `SurfaceBlowup.glued_level_one_normalization`: normalization of glued generators.26 27Provenance: `Thm_SurfaceBlowupV2_` nodes `laurent_monomial_shift_trailing_degree`,28`glued_level_one_normalization`, `laurent_nonnegative_twist_kernel`,29`laurent_split_nonnegative_twist`, `length_eq_of_surjective_onto_field`,30`blowup_chart_exceptional_point_polynomial`, `chart_point_eq_directionPoint`,31`direction_point_maximal`, `direction_point_overlap_maximal`, `infinity_point_maximal`,32`principal_layer_map_{kernel,range}`, `principal_layer_quotient_equiv`,33`chart_layer_polynomial_coordinates`, `rootMultiplicity_map_eq_count_normalizedFactors`.34-/35 36open scoped BigOperators ENNReal37 38namespace SurfaceBlowup39 40/-- If `PA = c T^m · T^d · PB(T⁻¹)` in `k[T, T⁻¹]` with `PA, PB ≠ 0`, then the trailing degree of41`PA` is `m + d - deg PB`. -/42private theorem laurent_monomial_shift_trailing_degree (k : Type) [Field k] (PA PB : Polynomial k)43    (hA : PA ≠ 0) (hB : PB ≠ 0) (c : k) (m : ℤ) (d : ℕ)44    (h : PA.toLaurent = LaurentPolynomial.C c * LaurentPolynomial.T m *45      (LaurentPolynomial.T (d : ℤ) * LaurentPolynomial.invert (R := k) PB.toLaurent)) :46    (PA.natTrailingDegree : ℤ) = m + (d : ℤ) - (PB.natDegree : ℤ) := by47  set e : ℤ := m + d - PB.natDegree with he48  set a : ℕ := e.toNat49  set b : ℕ := (-e).toNat50  have hab : (a : ℤ) - b = e := by omega51  have hinv : LaurentPolynomial.invert (R := k) PB.toLaurent52      = PB.reverse.toLaurent * LaurentPolynomial.T (-(PB.natDegree : ℤ)) := by53    rw [LaurentPolynomial.toLaurent_reverse, mul_assoc, ← LaurentPolynomial.T_add]54    simp55  have key : PA * Polynomial.X ^ b = Polynomial.C c * Polynomial.X ^ a * PB.reverse := by56    apply Polynomial.toLaurent_injective57    simp only [map_mul, Polynomial.toLaurent_X_pow, Polynomial.toLaurent_C, h, hinv]58    have : LaurentPolynomial.T (R := k) m * (LaurentPolynomial.T (d : ℤ) *59        LaurentPolynomial.T (-(PB.natDegree : ℤ))) * LaurentPolynomial.T (b : ℤ)60        = LaurentPolynomial.T (a : ℤ) := by61      simp only [← LaurentPolynomial.T_add]; congr 1; omega62    rw [← this]63    ring64  have hc : c ≠ 0 := by65    rintro rfl66    exact hA (by simpa using key)67  have hR : PB.reverse.natTrailingDegree = 0 := Polynomial.natTrailingDegree_reverse _68  have := congrArg Polynomial.natTrailingDegree key69  rw [Polynomial.natTrailingDegree_mul hA (pow_ne_zero _ Polynomial.X_ne_zero),70    Polynomial.natTrailingDegree_mul (mul_ne_zero (Polynomial.C_ne_zero.2 hc)71      (pow_ne_zero _ Polynomial.X_ne_zero)) (by simpa using hB),72    Polynomial.natTrailingDegree_mul (Polynomial.C_ne_zero.2 hc)73      (pow_ne_zero _ Polynomial.X_ne_zero), hR] at this74  simp at this75  omega76 77/-- The coefficients of `∑_{i ≤ N} f i X^i`. -/78private theorem coeff_sum_fin_C_mul_X_pow {S : Type} [Semiring S] (N : ℕ)79    (f : Fin (N + 1) → S) (j : ℕ) :80    (∑ i : Fin (N + 1), Polynomial.C (f i) * Polynomial.X ^ i.val).coeff j =81      if h : j < N + 1 then f ⟨j, h⟩ else 0 := by82  simp only [Polynomial.finsetSum_coeff, Polynomial.coeff_C_mul_X_pow]83  split_ifs with h84  · rw [Finset.sum_eq_single ⟨j, h⟩ (fun i _ hi ↦ ite_eq_right fun hj ↦ hi (Fin.ext hj.symm))85      (by simp)]86    simp87  · exact Finset.sum_eq_zero fun i _ ↦ ite_eq_right (by omega)88 89open LaurentPolynomial in90/-- The exceptional fibre of the overlap chart of the blow-up at `(t, x)` embeds into the Laurent91polynomial ring `(R ⧸ (t, x))[z, z⁻¹]`, sending constants to constants and the slope to `z`; the92embedding has a ring-hom left inverse. -/93private theorem exists_overlap_exceptional_laurent (R : Type) [CommRing R] (t x : R) :94    ∃ (φ : (BlowupOverlap R t x ⧸ Ideal.span {overlapException R t x}) →+*95        LaurentPolynomial (R ⧸ Ideal.span ({t,x} : Set R)))96      (ψ : LaurentPolynomial (R ⧸ Ideal.span ({t,x} : Set R)) →+*97        (BlowupOverlap R t x ⧸ Ideal.span {overlapException R t x})),98      ψ.comp φ = RingHom.id _ ∧99      (∀ r : R, φ (Ideal.Quotient.mk _ (algebraMap (BlowupChart R t x) (BlowupOverlap R t x)100        (chartBase R t x r))) = C (Ideal.Quotient.mk _ r)) ∧101      φ (Ideal.Quotient.mk _ (algebraMap (BlowupChart R t x) (BlowupOverlap R t x)102        (chartSlope R t x))) = T 1 := by103  set I : Ideal R := Ideal.span ({t,x} : Set R)104  set E : Ideal (BlowupOverlap R t x) := Ideal.span {overlapException R t x}105  have htI : t ∈ I := Ideal.subset_span (by simp)106  have hxI : x ∈ I := Ideal.subset_span (by simp)107  let zQ : (BlowupOverlap R t x ⧸ E)ˣ :=108    ((IsLocalization.Away.algebraMap_isUnit (chartSlope R t x)).map (Ideal.Quotient.mk E)).unit109  let fK : (R ⧸ I) →+* (BlowupOverlap R t x ⧸ E) :=110    Ideal.Quotient.lift I ((Ideal.Quotient.mk E).comp (algebraMap R (BlowupOverlap R t x)))111      fun a ha ↦ by112        refine (Ideal.span_le.2 (Set.pair_subset ?_ ?_) : I ≤ RingHom.ker _) ha <;>113          simp only [SetLike.mem_coe, RingHom.mem_ker, RingHom.comp_apply,114            Ideal.Quotient.eq_zero_iff_mem] <;>115          rw [IsScalarTower.algebraMap_apply R (BlowupChart R t x)]116        · exact Ideal.subset_span rfl117        · change algebraMap _ _ (chartBase R t x x) ∈ _118          rw [← blowup_chart_relation, map_mul]119          exact Ideal.mul_mem_right _ _ (Ideal.subset_span rfl)120  let ψ := eval₂ fK zQ121  let φ₀ : BlowupChart R t x →+* LaurentPolynomial (R ⧸ I) :=122    Ideal.Quotient.lift _ (Polynomial.eval₂RingHom (C.comp (Ideal.Quotient.mk I)) (T 1))123      fun a ha ↦ by124        obtain ⟨c, rfl⟩ := Ideal.mem_span_singleton'.mp ha125        simp [blowupRelation, Ideal.Quotient.eq_zero_iff_mem.mpr htI,126          Ideal.Quotient.eq_zero_iff_mem.mpr hxI]127  have hφ₀ : IsUnit (φ₀ (chartSlope R t x)) := by128    simpa [φ₀, chartSlope] using isUnit_T (R := R ⧸ I) 1129  let φ₁ : BlowupOverlap R t x →+* LaurentPolynomial (R ⧸ I) :=130    IsLocalization.Away.lift (chartSlope R t x) hφ₀131  let φ : (BlowupOverlap R t x ⧸ E) →+* LaurentPolynomial (R ⧸ I) :=132    Ideal.Quotient.lift E φ₁ fun a ha ↦ by133      obtain ⟨c, rfl⟩ := Ideal.mem_span_singleton'.mp ha134      simp [φ₁, overlapException, φ₀, chartBase, Ideal.Quotient.eq_zero_iff_mem.mpr htI]135  have hφA : ∀ a : BlowupChart R t x,136      φ (Ideal.Quotient.mk E (algebraMap (BlowupChart R t x) (BlowupOverlap R t x) a)) = φ₀ a :=137    fun a ↦ by simp only [φ, φ₁, Ideal.Quotient.lift_mk, IsLocalization.Away.lift_eq]138  have hφ₀C : ∀ r : R, φ₀ (chartBase R t x r) = C (Ideal.Quotient.mk I r) :=139    fun r ↦ by simp [φ₀, chartBase]140  have hφ₀Z : φ₀ (chartSlope R t x) = T 1 := by simp [φ₀, chartSlope]141  have hψC : ∀ r : R, ψ (C (Ideal.Quotient.mk I r)) = Ideal.Quotient.mk E142      (algebraMap (BlowupChart R t x) (BlowupOverlap R t x) (chartBase R t x r)) := fun r ↦ by143    simp only [ψ, eval₂_C, fK]144    rfl145  have hψφ : ψ.comp φ = RingHom.id _ := by146    refine Ideal.Quotient.ringHom_ext <|147      IsLocalization.ringHom_ext (Submonoid.powers (chartSlope R t x)) <|148      Ideal.Quotient.ringHom_ext <| Polynomial.ringHom_ext (fun a ↦ ?_) ?_ <;>149      simp only [RingHom.comp_apply, RingHom.id_apply] <;> rw [hφA]150    · have := hφ₀C a151      simp only [chartBase, RingHom.comp_apply] at this hψC152      rw [this]; exact hψC a153    · change ψ (φ₀ (chartSlope R t x)) = _154      rw [hφ₀Z]; simp [ψ, zQ, chartSlope]155  exact ⟨φ, ψ, hψφ, fun r ↦ (hφA _).trans (hφ₀C r), (hφA _).trans hφ₀Z⟩156 157open LaurentPolynomial in158/-- Normalization of glued generators at exceptional level one: if the images of the chart elements159`gA` and `gB` generate the same principal ideal of the exceptional divisor of the overlap, `gA`160reduces to a polynomial of trailing degree `r` and `gB` to one of degree `n` with `r + n = d`,161then `gA ≡ u · z^d · gB` modulo the exceptional divisor for some unit `u` of `R`. -/162theorem glued_level_one_normalization (R : Type) [CommRing R] (t x : R)163    [(Ideal.span ({t,x} : Set R)).IsMaximal] [IsLocalRing R] (_hreg : RegularParameterPair R t x)164    (beta : BlowupRestriction R t x) (d : ℕ) (gA : BlowupChart R t x) (gB : BlowupChart R x t)165    (hoverlap : Ideal.span {Ideal.Quotient.mk (Ideal.span {overlapException R t x})166                              ((algebraMap (BlowupChart R t x) (BlowupOverlap R t x)) gA)} =167      Ideal.span {Ideal.Quotient.mk (Ideal.span {overlapException R t x}) (beta.right gB)})168    (hregB : Function.Injective (fun c : BlowupOverlap R t x ⧸169      (Ideal.span {overlapException R t x}) => Ideal.Quotient.mk170      (Ideal.span {overlapException R t x}) (beta.right gB) * c)) (m n : ℕ) (cA : Fin (m+1) → R)171    (cB : Fin (n+1) → R) (hgA : gA - ∑ i : Fin (m+1),172      algebraMap R (BlowupChart R t x) (cA i) * (chartSlope R t x)^i.val ∈ chartExceptional R t x)173    (hgB : gB - ∑ i : Fin (n+1), algebraMap R (BlowupChart R x t) (cB i) * (chartSlope R x t)^i.val174      ∈ chartExceptional R x t) (r : ℕ) (hlow : ∀ i : Fin (m+1), i.val < r →175      cA i ∈ Ideal.span {t,x}) (hr : ∀ i : Fin (m+1), i.val = r → cA i ∉ Ideal.span {t,x})176    (hrm : r ≤ m) (htop : cB (Fin.last n) ∉ Ideal.span {t,x}) (hdeg : r + n = d) :177    ∃ u : Rˣ, (algebraMap (BlowupChart R t x) (BlowupOverlap R t x)) gA - algebraMap R178    (BlowupOverlap R t x) (u : R) * ((overlapSlope R t x)^d * beta.right gB) ∈179    (Ideal.span {overlapException R t x}) := by180  -- Reduce both generators to Laurent polynomials over `R ⧸ (t, x)` on the exceptional fibre181  -- of the overlap; they differ by a unit `c z^m'` there, and comparing degrees gives `m' = d`.182  set I : Ideal R := Ideal.span ({t,x} : Set R)183  set E : Ideal (BlowupOverlap R t x) := Ideal.span {overlapException R t x}184  have htI : t ∈ I := Ideal.subset_span (by simp)185  have hxI : x ∈ I := Ideal.subset_span (by simp)186  obtain ⟨φ, ψ, hψφ, hφC, hφZ⟩ := exists_overlap_exceptional_laurent R t x187  have hψ : ∀ y, ψ (φ y) = y := RingHom.congr_fun hψφ188  set PA : Polynomial (R ⧸ I) :=189    ∑ i : Fin (m+1), Polynomial.C (Ideal.Quotient.mk I (cA i)) * Polynomial.X ^ i.val with hPA190  set PB : Polynomial (R ⧸ I) :=191    ∑ i : Fin (n+1), Polynomial.C (Ideal.Quotient.mk I (cB i)) * Polynomial.X ^ i.val with hPB192  have hPAr : PA.coeff r ≠ 0 := by193    rw [hPA, coeff_sum_fin_C_mul_X_pow, dite_eq_left (by omega), Ne, Ideal.Quotient.eq_zero_iff_mem]194    exact hr ⟨r, by omega⟩ rfl195  have hPA0 : PA ≠ 0 := fun h ↦ hPAr (by simp [h])196  have hPAtr : PA.natTrailingDegree = r :=197    le_antisymm (Polynomial.natTrailingDegree_le_of_ne_zero hPAr) <|198      Polynomial.le_natTrailingDegree hPA0 fun j hj ↦ by199        rw [hPA, coeff_sum_fin_C_mul_X_pow, dite_eq_left (by omega)]200        exact Ideal.Quotient.eq_zero_iff_mem.mpr (hlow ⟨j, by omega⟩ hj)201  have hPBn : PB.coeff n ≠ 0 := by202    rw [hPB, coeff_sum_fin_C_mul_X_pow, dite_eq_left (by omega), Ne, Ideal.Quotient.eq_zero_iff_mem]203    exact htop204  have hPB0 : PB ≠ 0 := fun h ↦ hPBn (by simp [h])205  have hPBdeg : PB.natDegree = n :=206    Polynomial.natDegree_eq_of_le_of_coeff_ne_zero (Polynomial.natDegree_le_iff_coeff_eq_zero.2207      fun j hj ↦ by rw [hPB, coeff_sum_fin_C_mul_X_pow, dite_eq_right (by omega)]) hPBn208  -- images209  let ΦA : BlowupChart R t x →+* LaurentPolynomial (R ⧸ I) :=210    φ.comp ((Ideal.Quotient.mk E).comp (algebraMap (BlowupChart R t x) (BlowupOverlap R t x)))211  have hΦAexc : ∀ y ∈ chartExceptional R t x, ΦA y = 0 := fun y hy ↦ by212    obtain ⟨c, rfl⟩ := Ideal.mem_span_singleton'.mp hy213    rw [map_mul, show ΦA (chartBase R t x t) = _ from hφC t,214      Ideal.Quotient.eq_zero_iff_mem.mpr htI, map_zero, mul_zero]215  have hφa : φ (Ideal.Quotient.mk E (algebraMap (BlowupChart R t x) (BlowupOverlap R t x) gA)) =216      PA.toLaurent := by217    change ΦA gA = _218    rw [sub_eq_zero.1 ((map_sub ΦA _ _).symm.trans (hΦAexc _ hgA)), hPA, map_sum, map_sum]219    refine Finset.sum_congr rfl fun i _ ↦ ?_220    rw [map_mul, map_pow, Polynomial.toLaurent_C_mul_X_pow, show ΦA (chartSlope R t x) = _ from hφZ,221      T_pow, mul_one]222    exact congrArg (· * _) (hφC _)223  let ΦB : BlowupChart R x t →+* LaurentPolynomial (R ⧸ I) :=224    φ.comp ((Ideal.Quotient.mk E).comp beta.right.toRingHom)225  have hΦBC : ∀ c : R,226      ΦB (algebraMap R (BlowupChart R x t) c) = C (Ideal.Quotient.mk I c) := by227    intro c228    simp only [ΦB, RingHom.comp_apply, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, AlgHom.commutes]229    rw [IsScalarTower.algebraMap_apply R (BlowupChart R t x) (BlowupOverlap R t x)]230    exact hφC c231  have hΦBW : ΦB (chartSlope R x t) = T (-1) := by232    simp only [ΦB, RingHom.comp_apply, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, beta.slope]233    have h1 : φ (Ideal.Quotient.mk E (IsLocalization.Away.invSelf (chartSlope R t x))) *234        T 1 = 1 := by235      rw [← hφZ, ← map_mul, ← map_mul, mul_comm, IsLocalization.Away.mul_invSelf, map_one,236        map_one]237    have h2 : T (-1) * T (R := R ⧸ I) 1 = 1 := by rw [← T_add]; simp238    exact (isUnit_T (R := R ⧸ I) 1).mul_left_injective (h1.trans h2.symm)239  have hΦBexc : ∀ y ∈ chartExceptional R x t, ΦB y = 0 := fun y hy ↦ by240    obtain ⟨c, rfl⟩ := Ideal.mem_span_singleton'.mp hy241    rw [map_mul, show chartBase R x t x = algebraMap R _ x from rfl, hΦBC,242      Ideal.Quotient.eq_zero_iff_mem.mpr hxI, map_zero, mul_zero]243  have hφb : φ (Ideal.Quotient.mk E (beta.right gB)) = invert PB.toLaurent := by244    change ΦB gB = _245    rw [sub_eq_zero.1 ((map_sub ΦB _ _).symm.trans (hΦBexc _ hgB)), hPB, map_sum, map_sum, map_sum]246    refine Finset.sum_congr rfl fun i _ ↦ ?_247    rw [map_mul, map_pow, Polynomial.toLaurent_C_mul_X_pow, hΦBW, T_pow, hΦBC,248      map_mul, invert_C, invert_T]249    congr 2250    ring251  -- unit comparison252  obtain ⟨v, hv⟩ := regular_principal_generators_associated (BlowupOverlap R t x ⧸ E)253    (Ideal.Quotient.mk E (beta.right gB))254    (Ideal.Quotient.mk E (algebraMap (BlowupChart R t x) (BlowupOverlap R t x) gA))255    (fun y₁ y₂ h ↦ hregB (by simpa [mul_comm] using h)) hoverlap.symm256  obtain ⟨c, hc, m', hm'⟩ :=257    (letI := Ideal.Quotient.field I; laurent_isUnit_iff_monomial (R ⧸ I) (φ v)).mp (v.isUnit.map φ)258  have hmain : PA.toLaurent = C c * T m' *259      (T ((0:ℕ):ℤ) * invert (R := R ⧸ I) PB.toLaurent) := by260    rw [← hφa, hv, map_mul, hm', hφb]; simp261  have hdeg' := letI := Ideal.Quotient.field I262    laurent_monomial_shift_trailing_degree (R ⧸ I) PA PB hPA0 hPB0 c m' 0 hmain263  rw [hPAtr, hPBdeg] at hdeg'264  have hm'd : m' = (d : ℤ) := by push_cast at hdeg'; omega265  obtain ⟨u, hu⟩ := units_lift_from_local_quotient R I266    (IsLocalRing.le_maximalIdeal (Ideal.IsMaximal.ne_top inferInstance))267    (letI := Ideal.Quotient.field I; isUnit_iff_ne_zero.mpr hc).unit268  simp only [IsUnit.unit_spec] at hu269  refine ⟨u, ?_⟩270  rw [← Ideal.Quotient.eq, hv, ← hψ v, hm', hm'd, ← hu, show T (d : ℤ) = T 1 ^ d by271    rw [T_pow, mul_one], ← hφC, ← hφZ, ← map_pow, ← map_mul, hψ]272  rw [show algebraMap R (BlowupOverlap R t x) u =273    algebraMap (BlowupChart R t x) _ (chartBase R t x u) from rfl]274  simp only [map_mul, map_pow, overlapSlope]275  ring276 277private theorem laurent_twist_kernel_coeff_toLaurent {k : Type} [CommRing k] (f : Polynomial k)278    (z : ℤ) : f.toLaurent.coeff z = if 0 ≤ z then f.coeff z.toNat else 0 := by279  split_ifs with hz280  · obtain ⟨n, rfl⟩ := Int.eq_ofNat_of_zero_le hz281    rw [LaurentPolynomial.coeff_toLaurent]282    have := Finsupp.mapDomain_apply_of_injective (Nat.castEmbedding (R := ℤ)).injective283      f.toFinsupp.coeff n284    simp only [Nat.castEmbedding_apply] at this285    simp only [Int.toNat_natCast]; exact this.trans rfl286  · rw [LaurentPolynomial.coeff_toLaurent]287    apply Finsupp.mapDomain_of_notMem_range288    rintro ⟨n, hn⟩289    simp at hn290    omega291 292private theorem toLaurent_coeff_of_eq_T_mul_invert {k : Type} [CommRing k] (m : ℕ)293    (P Q : Polynomial k)294    (h : P.toLaurent = LaurentPolynomial.T (m : ℤ) * LaurentPolynomial.invert (R := k) Q.toLaurent)295    (n : ℤ) : P.toLaurent.coeff n = Q.toLaurent.coeff (m - n) := by296  rw [h, LaurentPolynomial.T, AddMonoidAlgebra.coeff_single_mul_apply,297    LaurentPolynomial.invert_apply, one_mul]298  congr 1; ring299 300/-- If `P(T) = T^m · Q(T⁻¹)` in `k[T, T⁻¹]` with `m ≥ 0`, then `deg P ≤ m` and `Q` is the reversal301of `P` at level `m`. -/302theorem laurent_nonnegative_twist_kernel (k : Type) [CommRing k] (m : ℕ) (P Q : Polynomial k)303    (h : P.toLaurent =304      LaurentPolynomial.T (m : ℤ) * LaurentPolynomial.invert (R := k) Q.toLaurent) :305    P.natDegree ≤ m ∧ ∀ i : ℕ, Q.coeff i = if i ≤ m then P.coeff (m - i) else 0 := by306  have key := toLaurent_coeff_of_eq_T_mul_invert m P Q h307  simp only [laurent_twist_kernel_coeff_toLaurent] at key308  refine ⟨?_, fun i ↦ ?_⟩309  · rw [Polynomial.natDegree_le_iff_coeff_eq_zero]310    intro n hn311    have := key n312    simp only [Nat.cast_nonneg, ite_true, Int.toNat_natCast] at this313    rw [this, ite_eq_right]314    have : (m : ℕ) < n := by exact_mod_cast hn315    omega316  · split_ifs with hi317    · have := key ((m - i : ℕ) : ℤ)318      simp only [Nat.cast_nonneg, ite_true, Int.toNat_natCast] at this319      rw [this, ite_eq_left (by omega)]320      congr 1; omega321    · have := key ((m : ℤ) - i)322      rw [ite_eq_right (by omega), ite_eq_left (by omega)] at this323      rw [show ((m : ℤ) - ((m : ℤ) - i)).toNat = i by omega] at this324      exact this.symm325 326/-- For `m ≥ -1`, every Laurent polynomial can be written as `P(T) - T^m · Q(T⁻¹)` with `P, Q`327polynomials. -/328theorem laurent_split_nonnegative_twist (k : Type) [CommRing k] (m : ℤ) (hm : -1 ≤ m)329    (F : LaurentPolynomial k) :330    ∃ P Q : Polynomial k, F = P.toLaurent - LaurentPolynomial.T m *331    (LaurentPolynomial.invert (R := k) Q.toLaurent) := by332  induction F using LaurentPolynomial.induction_on' with333  | add p q hp hq =>334    obtain ⟨P1, Q1, h1⟩ := hp335    obtain ⟨P2, Q2, h2⟩ := hq336    refine ⟨P1 + P2, Q1 + Q2, ?_⟩337    rw [h1, h2]338    simp only [map_add]339    ring340  | C_mul_T n a =>341    rcases le_or_gt 0 n with hn | hn342    · refine ⟨Polynomial.C a * Polynomial.X ^ n.toNat, 0, ?_⟩343      simp only [map_zero, mul_zero, sub_zero, map_mul, Polynomial.toLaurent_C,344        Polynomial.toLaurent_X_pow]345      rw [Int.toNat_of_nonneg hn]346    · refine ⟨0, -(Polynomial.C a * Polynomial.X ^ (m - n).toNat), ?_⟩347      simp only [map_zero, map_neg, map_mul, Polynomial.toLaurent_C,348        Polynomial.toLaurent_X_pow, LaurentPolynomial.invert_C, LaurentPolynomial.invert_T,349        zero_sub, mul_neg, neg_neg]350      rw [Int.toNat_of_nonneg (by omega), mul_left_comm, ← LaurentPolynomial.T_add]351      congr 2352      ring353 354/-- If `R` acts on a finite-dimensional `k`-vector space `M` through a surjection `f : R → k`, then355the `R`-length of `M` equals its `k`-dimension. -/356private theorem length_eq_of_surjective_onto_field (R k M : Type) [CommRing R] [Field k]357    [AddCommGroup M]358    [Module R M] [Module k M] (f : R →+* k) (hf : Function.Surjective f)359    (hcompat : ∀ (r : R) (m : M), r • m = f r • m) [Module.Finite k M] :360    Module.length R M = (Module.finrank k M : ℕ∞) := by361  have : RingHomSurjective f := ⟨hf⟩362  let g : M →ₛₗ[f] M := ⟨AddHom.id M, fun r m ↦ hcompat r m⟩363  rw [← Module.length_eq_finrank k M]364  rw [Module.length, Module.length, WithBot.unbot_inj,365    Order.krullDim_eq_of_orderIso (Submodule.orderIsoMapComapOfBijective g Function.bijective_id)]366 367/-- Given an identification `e` of the exceptional fibre of the chart with `(R/(t,x))[Z]`, a maximal368ideal `P` containing `t` corresponds to a monic irreducible `φ`: `P` maps onto `(φ)`, contains369the slope iff `φ = Z`, and has `R`-length `deg φ`. -/370theorem blowup_chart_exceptional_point_polynomial (R : Type) [CommRing R] (t x : R)371    [(Ideal.span ({t,x} : Set R)).IsMaximal]372    (e : (BlowupChart R t x ⧸ chartExceptional R t x) ≃+* Polynomial373      (R ⧸ Ideal.span ({t,x} : Set R))) (he : ∀ r : R,374      e (Ideal.Quotient.mk (chartExceptional R t x) (chartBase R t x r)) =375      Polynomial.C (Ideal.Quotient.mk (Ideal.span ({t,x} : Set R)) r))376    (heZ : e (Ideal.Quotient.mk (chartExceptional R t x) (chartSlope R t x)) = Polynomial.X)377    (P : Ideal (BlowupChart R t x)) [P.IsMaximal] (hP : chartBase R t x t ∈ P) :378    ∃ φ : Polynomial (R ⧸ Ideal.span ({t,x} : Set R)), φ.Monic ∧ Irreducible φ ∧379    (P.map (Ideal.Quotient.mk (chartExceptional R t x))).map e = Ideal.span {φ} ∧380    (chartSlope R t x ∈ P ↔ φ = Polynomial.X) ∧ Module.length R (BlowupChart R t x ⧸ P) =381    (φ.natDegree : ℕ∞) := by382  let : Field (R ⧸ Ideal.span ({t,x} : Set R)) := Ideal.Quotient.field _383  have hIP : chartExceptional R t x ≤ P := by384    rw [show chartExceptional R t x = Ideal.span {chartBase R t x t} from rfl, Ideal.span_le]385    simpa using hP386  set Pb := P.map (Ideal.Quotient.mk (chartExceptional R t x)) with hPb387  have hmk : Function.Surjective (Ideal.Quotient.mk (chartExceptional R t x)) :=388    Ideal.Quotient.mk_surjective389  have hcomap : Pb.comap (Ideal.Quotient.mk (chartExceptional R t x)) = P := by390    rw [hPb, Ideal.comap_map_of_surjective _ hmk]391    exact le_antisymm392      (sup_le le_rfl fun a ha ↦ hIP (by simpa [Ideal.Quotient.eq_zero_iff_mem] using ha))393      le_sup_left394  have hPbmax : Pb.IsMaximal :=395    (Ideal.map_eq_top_or_isMaximal_of_surjective _ hmk ‹P.IsMaximal›).resolve_left fun h ↦396      Ideal.IsMaximal.ne_top ‹_› (by rw [← hcomap, hPb, h, Ideal.comap_top])397  set Q := Pb.map e with hQ398  have hQmax : Q.IsMaximal := (Ideal.isMaximal_map_iff_of_bijective _ e.bijective).2 hPbmax399  obtain ⟨ψ, hψ'⟩ := IsPrincipalIdealRing.principal Q400  rw [Ideal.submodule_span_eq] at hψ'401  have hψ0 : ψ ≠ 0 := by402    rintro rfl403    rw [hψ', Ideal.span_singleton_eq_bot.2 rfl] at hQmax404    exact Polynomial.not_isField _ (Ring.isField_iff_maximal_bot.2 hQmax)405  have hψprime : Prime ψ := (Ideal.span_singleton_prime hψ0).1 (hψ' ▸ hQmax.isPrime)406  have hu : IsUnit (Polynomial.C ψ.leadingCoeff⁻¹) :=407    Polynomial.isUnit_C.2 (inv_ne_zero (Polynomial.leadingCoeff_ne_zero.2 hψ0)).isUnit408  set φ := ψ * Polynomial.C ψ.leadingCoeff⁻¹ with hφ409  have hmon : φ.Monic := Polynomial.monic_mul_leadingCoeff_inv hψ0410  have hirr : Irreducible φ := (associated_mul_unit_right ψ _ hu).irreducible hψprime.irreducible411  have hQφ : Ideal.span {φ} = Q := by rw [hφ, Ideal.span_singleton_mul_right_unit hu, ← hψ']412  refine ⟨φ, hmon, hirr, hQφ.symm, ?_, ?_⟩413  · rw [← hcomap, Ideal.mem_comap, ← Ideal.apply_mem_of_equiv_iff (f := e), heZ, ← hQ, ← hQφ,414      Ideal.mem_span_singleton]415    exact ⟨fun h ↦ Polynomial.eq_of_monic_of_associated hmon Polynomial.monic_X416      (associated_of_dvd_dvd h (hirr.dvd_symm Polynomial.irreducible_X h)), fun h ↦ h ▸ dvd_rfl⟩417  · let Ψ : (BlowupChart R t x ⧸ P) ≃+*418        (Polynomial (R ⧸ Ideal.span ({t,x} : Set R)) ⧸ Ideal.span {φ}) :=419      (DoubleQuot.quotQuotEquivQuotOfLE hIP).symm.trans (Ideal.quotientEquiv _ _ e hQφ)420    have hΨ : ∀ r : R, Ψ (Ideal.Quotient.mk P (chartBase R t x r)) =421        Ideal.Quotient.mk (Ideal.span {φ})422          (Polynomial.C (Ideal.Quotient.mk (Ideal.span ({t,x} : Set R)) r)) := by423      intro r424      simp only [Ψ, RingEquiv.trans_apply, DoubleQuot.quotQuotEquivQuotOfLE_symm_mk]425      exact congrArg _ (he r)426    let L := (AlgEquiv.ofRingEquiv (R := R) (f := Ψ) (fun r ↦ hΨ r)).toLinearEquiv427    rw [L.length_eq]428    have : Module.Finite (R ⧸ Ideal.span ({t,x} : Set R))429        (Polynomial (R ⧸ Ideal.span ({t,x} : Set R)) ⧸ Ideal.span {φ}) :=430      Module.finite_of_finrank_pos431        (by rw [finrank_quotient_span_eq_natDegree]; exact hirr.natDegree_pos)432    rw [length_eq_of_surjective_onto_field R (R ⧸ Ideal.span ({t,x} : Set R)) _433      (Ideal.Quotient.mk _) Ideal.Quotient.mk_surjective ?_, finrank_quotient_span_eq_natDegree]434    intro r m435    exact (algebraMap_smul (R ⧸ Ideal.span ({t,x} : Set R)) r m).symm436 437/-- Every maximal ideal of the chart containing `t` is the direction point of an affine direction438`φ` over the residue field; it maps onto `(φ)` in the exceptional fibre and contains the slope439iff `φ` is the zero direction. -/440theorem chart_point_eq_directionPoint (R : Type) [CommRing R] [IsLocalRing R] (t x : R)441    [(Ideal.span ({t,x} : Set R)).IsMaximal]442    (e : (BlowupChart R t x ⧸ chartExceptional R t x) ≃+* Polynomial (IsLocalRing.ResidueField R))443    (he : ∀ r : R, e (Ideal.Quotient.mk (chartExceptional R t x) (chartBase R t x r)) =444      Polynomial.C (IsLocalRing.residue R r))445    (heZ : e (Ideal.Quotient.mk (chartExceptional R t x) (chartSlope R t x)) = Polynomial.X)446    (P : Ideal (BlowupChart R t x)) [P.IsMaximal] (hP : chartBase R t x t ∈ P) :447    ∃ φ : AffineDirection (IsLocalRing.ResidueField R), P = directionPoint R t x e φ ∧448    (P.map (Ideal.Quotient.mk (chartExceptional R t x))).map e = Ideal.span {φ.val} ∧449    (chartSlope R t x ∈ P ↔ φ = zeroAffine (IsLocalRing.ResidueField R)) := by450  have hm : Ideal.span ({t,x} : Set R) = IsLocalRing.maximalIdeal R :=451    IsLocalRing.eq_maximalIdeal ‹_›452  let κ : (R ⧸ Ideal.span ({t,x} : Set R)) ≃+* IsLocalRing.ResidueField R :=453    Ideal.quotEquivOfEq hm454  have hκ : ∀ r : R, κ (Ideal.Quotient.mk _ r) = IsLocalRing.residue R r := fun r ↦ rfl455  let M := Polynomial.mapEquiv κ456  let e₀ := e.trans M.symm457  have he₀ : ∀ r : R, e₀ (Ideal.Quotient.mk (chartExceptional R t x) (chartBase R t x r)) =458      Polynomial.C (Ideal.Quotient.mk (Ideal.span ({t,x} : Set R)) r) := by459    intro r460    apply M.injective461    simp only [e₀, RingEquiv.trans_apply, RingEquiv.apply_symm_apply, he]462    simp [M, Polynomial.mapEquiv_apply, hκ]463  have heZ₀ :464      e₀ (Ideal.Quotient.mk (chartExceptional R t x) (chartSlope R t x)) = Polynomial.X := by465    apply M.injective466    simp only [e₀, RingEquiv.trans_apply, RingEquiv.apply_symm_apply, heZ]467    simp [M, Polynomial.mapEquiv_apply]468  obtain ⟨φ₀, hmon, hirr, himg, hZ, -⟩ :=469    blowup_chart_exceptional_point_polynomial R t x e₀ he₀ heZ₀ P hP470  have hirr' : Irreducible (Polynomial.map κ.toRingHom φ₀) :=471    (MulEquiv.irreducible_iff M.toMulEquiv).2 hirr472  let φ : AffineDirection (IsLocalRing.ResidueField R) :=473    ⟨Polynomial.map κ.toRingHom φ₀, hmon.map _, hirr'⟩474  have himg' : (P.map (Ideal.Quotient.mk (chartExceptional R t x))).map e = Ideal.span {φ.val} := by475    have he : e.toRingHom = M.toRingHom.comp e₀.toRingHom := by476      exact RingHom.ext fun a ↦ by simp [e₀]477    change Ideal.map e.toRingHom _ = _478    rw [he, ← Ideal.map_map]479    change Ideal.map M (Ideal.map e₀ _) = _480    rw [himg, Ideal.map_span, Set.image_singleton]481    rfl482  refine ⟨φ, ?_, himg', ?_⟩483  · let ψ := e.toRingHom.comp (Ideal.Quotient.mk (chartExceptional R t x))484    have hψ : Function.Surjective ψ :=485      e.surjective.comp Ideal.Quotient.mk_surjective486    have hmap : P.map ψ = Ideal.span {φ.val} := by487      rw [← himg']488      change _ = Ideal.map e.toRingHom _489      rw [Ideal.map_map]490    change P = (Ideal.span {φ.val}).comap ψ491    rw [← hmap, Ideal.comap_map_of_surjective _ hψ]492    have hker : Ideal.comap ψ ⊥ = chartExceptional R t x := by493      rw [← RingHom.ker_eq_comap_bot]494      ext a495      simp [ψ, RingHom.mem_ker, Ideal.Quotient.eq_zero_iff_mem]496    rw [hker, eq_comm, sup_eq_left]497    exact (Ideal.span_singleton_le_iff_mem _).2 hP498  · rw [hZ]499    refine ⟨by rintro rfl; apply Subtype.ext; simp [φ, zeroAffine], fun h ↦ M.injective ?_⟩500    have := congrArg Subtype.val h501    simp only [φ, zeroAffine] at this502    simpa [M] using this503 504/-- The direction point of an affine direction `φ` is a maximal ideal containing `t`; it contains505the slope iff `φ` is the zero direction, maps onto `(φ)` in the exceptional fibre, has506`R`-length `deg φ`, and depends injectively on `φ`. -/507theorem direction_point_maximal (O R : Type) [CommRing O] [IsDomain O] [IsDiscreteValuationRing O]508    [CommRing R] [IsDomain R] [Algebra O R] [IsRegularLocalRing R] (S : SurfaceData O R)509    (e : (BlowupChart R S.t S.x ⧸ chartExceptional R S.t S.x) ≃+* Polynomial510      (IsLocalRing.ResidueField R)) (he : ∀ r : R,511      e (Ideal.Quotient.mk (chartExceptional R S.t S.x) (chartBase R S.t S.x r)) =512      Polynomial.C (IsLocalRing.residue R r))513    (heZ : e (Ideal.Quotient.mk (chartExceptional R S.t S.x) (chartSlope R S.t S.x)) = Polynomial.X)514    (φ : AffineDirection (IsLocalRing.ResidueField R)) :515    (directionPoint R S.t S.x e φ).IsMaximal ∧516    chartBase R S.t S.x S.t ∈ directionPoint R S.t S.x e φ ∧517    (chartSlope R S.t S.x ∈ directionPoint R S.t S.x e φ ↔ φ =518      zeroAffine (IsLocalRing.ResidueField R)) ∧519    ((directionPoint R S.t S.x e φ).map (Ideal.Quotient.mk (chartExceptional R S.t S.x))).map e =520    Ideal.span {φ.val} ∧ Module.length R (BlowupChart R S.t S.x ⧸ directionPoint R S.t S.x e φ) =521    (φ.val.natDegree : ℕ∞) ∧ Function.Injective (directionPoint R S.t S.x e) := by522  set k := IsLocalRing.ResidueField R523  set A := BlowupChart R S.t S.x524  set ψ : A →+* Polynomial k :=525    e.toRingHom.comp (Ideal.Quotient.mk (chartExceptional R S.t S.x))526  have hψ : Function.Surjective ψ :=527    e.surjective.comp Ideal.Quotient.mk_surjective528  have hP : ∀ φ' : AffineDirection k,529      directionPoint R S.t S.x e φ' = (Ideal.span {φ'.val}).comap ψ := fun _ ↦ rfl530  have hmap : ∀ φ' : AffineDirection k,531      ((directionPoint R S.t S.x e φ').map (Ideal.Quotient.mk (chartExceptional R S.t S.x))).map e532        = Ideal.span {φ'.val} := by533    intro φ'534    change Ideal.map e.toRingHom (Ideal.map (Ideal.Quotient.mk _) _) = _535    rw [Ideal.map_map, hP]536    exact Ideal.map_comap_of_surjective ψ hψ _537  have hmon : ∀ φ₁ φ₂ : AffineDirection k, Ideal.span {φ₁.val} = Ideal.span {φ₂.val} → φ₁ = φ₂ := by538    intro φ₁ φ₂ h539    rw [Ideal.span_singleton_eq_span_singleton] at h540    exact Subtype.ext (Polynomial.eq_of_monic_of_associated φ₁.2.1 φ₂.2.1 h)541  have hbase : ∀ r : R, ψ (chartBase R S.t S.x r) = Polynomial.C (IsLocalRing.residue R r) := he542  refine ⟨?_, ?_, ?_, hmap φ, ?_, ?_⟩543  · rw [hP]544    have := PrincipalIdealRing.isMaximal_of_irreducible φ.2.2545    exact Ideal.comap_isMaximal_of_surjective ψ hψ546  · rw [hP, Ideal.mem_comap, hbase]547    have ht : S.t ∈ IsLocalRing.maximalIdeal R := by548      rw [← S.parameters]; exact Ideal.subset_span (by simp)549    rw [(IsLocalRing.residue_eq_zero_iff _).2 ht, map_zero]550    exact zero_mem _551  · rw [hP, Ideal.mem_comap]552    change e (Ideal.Quotient.mk _ (chartSlope R S.t S.x)) ∈ _ ↔ _553    rw [heZ, Ideal.mem_span_singleton]554    constructor555    · intro h556      exact Subtype.ext (Polynomial.eq_of_monic_of_associated φ.2.1 Polynomial.monic_X557        (φ.2.2.associated_of_dvd Polynomial.irreducible_X h))558    · rintro rfl; exact dvd_refl _559  · let E : (A ⧸ directionPoint R S.t S.x e φ) ≃+* Polynomial k ⧸ Ideal.span {φ.val} :=560      (Ideal.quotEquivOfEq (by rw [← RingHom.comap_ker, Ideal.mk_ker, hP])).trans561        (RingHom.quotientKerEquivOfSurjective (f := (Ideal.Quotient.mk (Ideal.span {φ.val})).comp ψ)562          (Ideal.Quotient.mk_surjective.comp hψ))563    let L := (AlgEquiv.ofRingEquiv (R := R) (f := E)564      fun r ↦ congrArg (Ideal.Quotient.mk _) (hbase r)).toLinearEquiv565    rw [L.length_eq]566    have : Module.Finite k (Polynomial k ⧸ Ideal.span {φ.val}) := Module.finite_of_finrank_pos567      (by rw [finrank_quotient_span_eq_natDegree]; exact φ.2.2.natDegree_pos)568    rw [length_eq_of_surjective_onto_field R k _ (IsLocalRing.residue R)569      IsLocalRing.residue_surjective ?_, finrank_quotient_span_eq_natDegree]570    intro r m571    exact (algebraMap_smul k r m).symm572  · intro φ₁ φ₂ h573    apply hmon574    rw [← hmap φ₁, ← hmap φ₂, h]575 576/-- For a nonzero affine direction, the direction point generates a maximal ideal of the overlap577chart that contains `t` and contracts back to the direction point. -/578theorem direction_point_overlap_maximal (O R : Type) [CommRing O] [IsDomain O]579    [IsDiscreteValuationRing O] [CommRing R] [IsDomain R] [Algebra O R] [IsRegularLocalRing R]580    (S : SurfaceData O R) (e : (BlowupChart R S.t S.x ⧸ chartExceptional R S.t S.x) ≃+* Polynomial581      (IsLocalRing.ResidueField R)) (he : ∀ r : R,582      e (Ideal.Quotient.mk (chartExceptional R S.t S.x) (chartBase R S.t S.x r)) =583      Polynomial.C (IsLocalRing.residue R r))584    (heZ : e (Ideal.Quotient.mk (chartExceptional R S.t S.x) (chartSlope R S.t S.x)) = Polynomial.X)585    (φ : AffineDirection (IsLocalRing.ResidueField R))586    (hφ : φ ≠ zeroAffine (IsLocalRing.ResidueField R)) :587    ((directionPoint R S.t S.x e φ).map (algebraMap (BlowupChart R S.t S.x)588      (BlowupOverlap R S.t S.x))).IsMaximal ∧589    (algebraMap (BlowupChart R S.t S.x) (BlowupOverlap R S.t S.x)) (chartBase R S.t S.x S.t) ∈590    (directionPoint R S.t S.x e φ).map (algebraMap (BlowupChart R S.t S.x)591      (BlowupOverlap R S.t S.x)) ∧ ((directionPoint R S.t S.x e φ).map592      (algebraMap (BlowupChart R S.t S.x) (BlowupOverlap R S.t S.x))).comap593    (algebraMap (BlowupChart R S.t S.x) (BlowupOverlap R S.t S.x)) =594      directionPoint R S.t S.x e φ := by595  obtain ⟨hmax, ht, hZ, -⟩ := direction_point_maximal O R S e he heZ φ596  set P := directionPoint R S.t S.x e φ597  have hZP : chartSlope R S.t S.x ∉ P := fun h ↦ hφ (hZ.mp h)598  have hd : Disjoint ((Submonoid.powers (chartSlope R S.t S.x) : Submonoid _) :599      Set (BlowupChart R S.t S.x)) (P : Set _) := by600    rw [Set.disjoint_left]601    rintro _ ⟨n, rfl⟩ hn602    exact hZP (hmax.isPrime.mem_of_pow_mem n hn)603  have hcomap : (P.map (algebraMap (BlowupChart R S.t S.x) (BlowupOverlap R S.t S.x))).comap604      (algebraMap (BlowupChart R S.t S.x) (BlowupOverlap R S.t S.x)) = P :=605    IsLocalization.under_map_of_isPrime_disjoint (Submonoid.powers (chartSlope R S.t S.x)) _606      hmax.isPrime hd607  have hprime :=608    IsLocalization.isPrime_of_isPrime_disjoint (Submonoid.powers (chartSlope R S.t S.x))609    (BlowupOverlap R S.t S.x) P hmax.isPrime hd610  refine ⟨?_, Ideal.mem_map_of_mem _ ht, hcomap⟩611  obtain ⟨M, hM, hle⟩ := Ideal.exists_le_maximal _ hprime.ne_top612  have hcM : M.comap (algebraMap (BlowupChart R S.t S.x) (BlowupOverlap R S.t S.x)) = P := by613    refine (hmax.eq_of_le (Ideal.comap_ne_top _ hM.ne_top) ?_).symm614    rw [← hcomap]; exact Ideal.comap_mono hle615  have : M = P.map (algebraMap (BlowupChart R S.t S.x) (BlowupOverlap R S.t S.x)) := by616    rw [← hcM]; exact (IsLocalization.map_under (Submonoid.powers (chartSlope R S.t S.x)) _ M).symm617  rw [← this]; exact hM618 619/-- The point at infinity of the opposite chart is a maximal ideal containing `x` and the slope,620with `R`-length one. -/621theorem infinity_point_maximal (O R : Type) [CommRing O] [IsDomain O] [IsDiscreteValuationRing O]622    [CommRing R] [IsDomain R] [Algebra O R] [IsRegularLocalRing R] (S : SurfaceData O R) :623    (infinityPoint R S.t S.x).IsMaximal ∧ chartBase R S.x S.t S.x ∈ infinityPoint R S.t S.x ∧624    chartSlope R S.x S.t ∈ infinityPoint R S.t S.x ∧ Module.length R625    (BlowupChart R S.x S.t ⧸ infinityPoint R S.t S.x) = 1 := by626  have hker : ∃ φ : BlowupChart R S.x S.t →+* IsLocalRing.ResidueField R,627      (∀ r, φ (chartBase R S.x S.t r) = IsLocalRing.residue R r) ∧628      φ (chartSlope R S.x S.t) = 0 ∧ RingHom.ker φ = infinityPoint R S.t S.x := by629    have hx : IsLocalRing.residue R S.x = 0 := by630      rw [IsLocalRing.residue_eq_zero_iff, ← S.parameters]631      exact Ideal.subset_span (by simp)632    have ht : IsLocalRing.residue R S.t = 0 := by633      rw [IsLocalRing.residue_eq_zero_iff, ← S.parameters]634      exact Ideal.subset_span (by simp)635    let ψ : Polynomial R →+* IsLocalRing.ResidueField R :=636      Polynomial.eval₂RingHom (IsLocalRing.residue R) 0637    have hψ : Ideal.span {blowupRelation R S.x S.t} ≤ RingHom.ker ψ := by638      rw [Ideal.span_le, Set.singleton_subset_iff]639      simp [ψ, blowupRelation, ht]640    refine ⟨Ideal.Quotient.lift _ ψ fun a ha ↦ hψ ha, fun r ↦ ?_, ?_, ?_⟩641    · change ψ (Polynomial.C r) = _642      simp [ψ]643    · change ψ Polynomial.X = _644      simp [ψ]645    · ext b646      obtain ⟨p, rfl⟩ := Ideal.Quotient.mk_surjective b647      have hrel := blowup_chart_relation R S.x S.t648      have hI_x : chartBase R S.x S.t S.x ∈ infinityPoint R S.t S.x := Ideal.subset_span (by simp)649      have hI_W : chartSlope R S.x S.t ∈ infinityPoint R S.t S.x := Ideal.subset_span (by simp)650      have hI_t : chartBase R S.x S.t S.t ∈ infinityPoint R S.t S.x := by651        rw [← hrel]; exact Ideal.mul_mem_right _ _ hI_x652      have hp := Polynomial.divX_mul_X_add p653      have hmk : Ideal.Quotient.mk (Ideal.span {blowupRelation R S.x S.t}) p =654          Ideal.Quotient.mk (Ideal.span {blowupRelation R S.x S.t}) (p.divX) * chartSlope R S.x S.t655          + chartBase R S.x S.t (p.coeff 0) := by656        conv_lhs => rw [← hp]657        simp [chartSlope, chartBase]658      have hψp : ψ p = IsLocalRing.residue R (p.coeff 0) := by659        simp [ψ, Polynomial.eval₂_at_zero]660      simp only [RingHom.mem_ker]661      change ψ p = 0 ↔ _662      refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩663      · rw [hψp, IsLocalRing.residue_eq_zero_iff, ← S.parameters] at h664        rw [hmk]665        refine Ideal.add_mem _ (Ideal.mul_mem_left _ _ hI_W) ?_666        have : Ideal.map (chartBase R S.x S.t) (Ideal.span {S.t, S.x}) ≤667            infinityPoint R S.t S.x := by668          rw [Ideal.map_span, Ideal.span_le]669          rintro _ ⟨y, hy, rfl⟩670          rcases hy with rfl | rfl671          · exact hI_t672          · exact hI_x673        exact this (Ideal.mem_map_of_mem _ h)674      · have hle : infinityPoint R S.t S.x ≤675            RingHom.ker (Ideal.Quotient.lift _ ψ fun a ha ↦ hψ ha) := by676          rw [infinityPoint, Ideal.span_le]677          rintro _ (rfl | rfl)678          · change ψ (Polynomial.C S.x) = 0679            simpa [ψ] using hx680          · change ψ Polynomial.X = 0681            simp [ψ]682        exact hle h683  obtain ⟨φ, hφ1, hφ2, hφk⟩ := hker684  have hsurj : Function.Surjective φ := by685    intro y686    obtain ⟨r, rfl⟩ := IsLocalRing.residue_surjective y687    exact ⟨chartBase R S.x S.t r, hφ1 r⟩688  have hmax : (infinityPoint R S.t S.x).IsMaximal := by689    rw [← hφk]; exact RingHom.ker_isMaximal_of_surjective φ hsurj690  refine ⟨hmax, Ideal.subset_span (by simp), Ideal.subset_span (by simp), ?_⟩691  let e0 : (BlowupChart R S.x S.t ⧸ infinityPoint R S.t S.x) ≃+* IsLocalRing.ResidueField R :=692    (Ideal.quotEquivOfEq hφk.symm).trans (RingHom.quotientKerEquivOfSurjective hsurj)693  rw [(AlgEquiv.ofRingEquiv (R := R) (f := e0) fun r ↦ hφ1 r).toLinearEquiv.length_eq,694    length_eq_of_surjective_onto_field R _ _ (IsLocalRing.residue R)695      IsLocalRing.residue_surjective fun r m ↦ rfl]696  simp697 698/-- If `e` is a nonzerodivisor, the kernel of the layer map `a ↦ e^j a` into `A ⧸ (e)^(j+1)` is699`(e)`. -/700private theorem principal_layer_map_kernel (A : Type) [CommRing A] (e : A) (j : ℕ)701    (he : Function.Injective (fun a : A ↦ e*a)) :702    LinearMap.ker (principalLayerMap A e j) = Ideal.span {e} := by703  have hinj : IsLeftRegular (e ^ j) := IsLeftRegular.pow j he704  ext a705  simp only [LinearMap.mem_ker, principalLayerMap, LinearMap.toSpanSingleton_apply,706    Algebra.smul_def, Ideal.Quotient.algebraMap_eq]707  rw [← map_mul, Ideal.Quotient.eq_zero_iff_mem, Ideal.span_singleton_pow,708    Ideal.mem_span_singleton, Ideal.mem_span_singleton]709  constructor710  · rintro ⟨b, hb⟩711    exact ⟨b, hinj (show e ^ j * a = e ^ j * (e * b) by linear_combination hb)⟩712  · rintro ⟨b, rfl⟩713    exact ⟨b, by ring⟩714 715/-- The range of the layer map `a ↦ e^j a` into `A ⧸ (e)^(j+1)` is the kernel of the reduction to `A716⧸ (e)^j`. -/717private theorem principal_layer_map_range (A : Type) [CommRing A] (e : A) (j : ℕ) :718    LinearMap.range (principalLayerMap A e j) = LinearMap.ker719    (principalPowerReduction A e j).toLinearMap := by720  ext x721  constructor722  · rintro ⟨a, rfl⟩723    rw [LinearMap.mem_ker]724    simp only [principalLayerMap, LinearMap.toSpanSingleton_apply, principalPowerReduction,725      AlgHom.toLinearMap_apply, map_smul, Ideal.Quotient.factorₐ_apply, Ideal.Quotient.factor_mk]726    rw [(Ideal.Quotient.eq_zero_iff_mem).2 (Ideal.pow_mem_pow (Ideal.mem_span_singleton_self e) j),727      smul_zero]728  · intro hx729    obtain ⟨b, rfl⟩ := Ideal.Quotient.mk_surjective x730    rw [LinearMap.mem_ker] at hx731    simp only [principalPowerReduction, AlgHom.toLinearMap_apply, Ideal.Quotient.factorₐ_apply,732      Ideal.Quotient.factor_mk] at hx733    rw [Ideal.Quotient.eq_zero_iff_mem, Ideal.span_singleton_pow,734      Ideal.mem_span_singleton'] at hx735    obtain ⟨a, rfl⟩ := hx736    refine ⟨a, ?_⟩737    simp only [principalLayerMap, LinearMap.toSpanSingleton_apply]738    rw [Algebra.smul_def, Ideal.Quotient.algebraMap_eq, ← map_mul]739 740/-- If `e` is a nonzerodivisor, the layer map induces an `A`-linear isomorphism from `A ⧸ (e)` onto741the principal layer `(e)^j ⧸ (e)^(j+1)`. -/742theorem principal_layer_quotient_equiv (A : Type) [CommRing A] (e : A) (j : ℕ)743    (he : Function.Injective (fun a : A ↦ e*a)) :744    ∃ L : (A ⧸ Ideal.span {e}) ≃ₗ[A] PrincipalLayer A e j, ∀ a : A,745    (L (Ideal.Quotient.mk (Ideal.span {e}) a)).val = principalLayerMap A e j a := by746  have hk := principal_layer_map_kernel A e j he747  have hr := principal_layer_map_range A e j748  refine ⟨((Submodule.quotEquivOfEq _ _ hk.symm).trans749    (LinearMap.quotKerEquivRange (principalLayerMap A e j))).trans (LinearEquiv.ofEq _ _ hr), ?_⟩750  intro a751  rfl752 753/-- Each exceptional layer of the chart is `R`-linearly isomorphic to `(R/(t,x))[Z]`, the monomial754`r Z^i` corresponding to the layer class of `r · z^i`. -/755theorem chart_layer_polynomial_coordinates (R : Type) [CommRing R] (t x : R)(4.1)756    (hreg : RegularParameterPair R t x) (j : ℕ) :757    ∃ L : Polynomial (R ⧸ Ideal.span {t,x}) ≃ₗ[R] PrincipalLayer (BlowupChart R t x)758    (chartBase R t x t) j, ∀ r : R, ∀ i : ℕ,759    (L (Polynomial.C (Ideal.Quotient.mk (Ideal.span {t,x}) r) * Polynomial.X^i)).val =760    principalLayerMap (BlowupChart R t x) (chartBase R t x t) j761    (chartBase R t x r * (chartSlope R t x)^i) := by762  have he := blowup_exceptional_parameter_regular R t x hreg763  obtain ⟨L1, hL1⟩ := principal_layer_quotient_equiv (BlowupChart R t x)764    (chartBase R t x t) j he765  obtain ⟨e1, he1b, he1s⟩ := exceptional_chart_is_affine_line R t x766  have hI : exceptionalLevelIdeal R t x 1 = Ideal.span {chartBase R t x t} := by767    simp [exceptionalLevelIdeal]768  let φ : (BlowupChart R t x ⧸ Ideal.span {chartBase R t x t}) ≃+*769      Polynomial (R ⧸ Ideal.span {t,x}) :=770    (Ideal.quotEquivOfEq hI.symm).trans e1771  have hφ : ∀ a : BlowupChart R t x,772      φ (Ideal.Quotient.mk _ a) = e1 (Ideal.Quotient.mk (exceptionalLevelIdeal R t x 1) a) := by773    intro a; rfl774  have hφb : ∀ r : R, φ (Ideal.Quotient.mk _ (chartBase R t x r)) =775      Polynomial.C (Ideal.Quotient.mk (Ideal.span {t,x}) r) := by776    intro r; rw [hφ]; exact he1b r777  have hφs : φ (Ideal.Quotient.mk _ (chartSlope R t x)) = Polynomial.X := by778    rw [hφ]; exact he1s779  let φl := (AlgEquiv.ofRingEquiv (R := R) (f := φ) fun r ↦ hφb r).toLinearEquiv780  refine ⟨φl.symm.trans (L1.restrictScalars R), ?_⟩781  intro r i782  have key : φl.symm (Polynomial.C (Ideal.Quotient.mk (Ideal.span {t,x}) r) * Polynomial.X^i)783      = Ideal.Quotient.mk _ (chartBase R t x r * (chartSlope R t x)^i) := by784    rw [LinearEquiv.symm_apply_eq]785    change _ = φ _786    rw [map_mul, map_pow, map_mul, map_pow, hφb, hφs]787  simp only [LinearEquiv.trans_apply, key, LinearEquiv.restrictScalars_apply]788  exact hL1 _789 790open scoped Classical in791open Polynomial UniqueFactorizationMonoid in792/-- Over a finite field `k`, if `ᾱ` is a root of the monic irreducible `φ` in an extension `k'`,793then the multiplicity of `ᾱ` as a root of `G` equals the multiplicity of `φ` among the794normalized factors of `G`. -/795theorem rootMultiplicity_map_eq_count_normalizedFactors (k k' : Type) [Field k] [Finite k]796    [Field k'] (ι : k →+* k') (G : Polynomial k) (hG : G ≠ 0) (φ : Polynomial k)797    (hφ : φ.Monic ∧ Irreducible φ) (alphaBar : k') (hroot : (φ.map ι).eval alphaBar = 0) :798    Polynomial.rootMultiplicity alphaBar (G.map ι) = Multiset.count φ799    (UniqueFactorizationMonoid.normalizedFactors G) := by800  have key : ∀ ψ : k[X], ψ.Monic → Irreducible ψ →801      rootMultiplicity alphaBar (ψ.map ι) = Multiset.count φ {ψ} := by802    intro ψ hm hi803    rw [Multiset.count_singleton]804    split_ifs with h805    · subst h806      have := PerfectField.ofFinite (K := k)807      have hsep : (φ.map ι).Separable := (PerfectField.separable_of_irreducible hi).map808      have hne : φ.map ι ≠ 0 := Polynomial.map_ne_zero hi.ne_zero809      have h1 := rootMultiplicity_le_one_of_separable hsep alphaBar810      have h2 : 0 < rootMultiplicity alphaBar (φ.map ι) :=811        (rootMultiplicity_pos hne).2 hroot812      omega813    · rw [rootMultiplicity_eq_zero_iff]814      intro hr815      exfalso816      obtain ⟨a, b, hab⟩ := (EuclideanDomain.dvd_or_coprime φ ψ hφ.2).resolve_left (by817        intro hd818        exact h (eq_of_monic_of_associated hφ.1 hm (hφ.2.associated_of_dvd hi hd)))819        |>.map (mapRingHom ι)820      have := congrArg (eval alphaBar) hab821      simp only [coe_mapRingHom, eval_add, eval_mul, hroot, hr.eq_zero, mul_zero, add_zero,822        eval_one] at this823      exact zero_ne_one this824  induction G using UniqueFactorizationMonoid.induction_on_prime with825  | h₁ => exact absurd rfl hG826  | h₂ x hx =>827    obtain ⟨c, hc, rfl⟩ := Polynomial.isUnit_iff.1 hx828    rw [normalizedFactors_of_isUnit hx, Polynomial.map_C, rootMultiplicity_C]829    rfl830  | h₃ a p ha hp ih =>831    have ha0 : a ≠ 0 := right_ne_zero_of_mul hG832    have hp0 : p ≠ 0 := hp.ne_zero833    rw [normalizedFactors_mul hp0 ha0, Multiset.count_add, Polynomial.map_mul,834      rootMultiplicity_mul (by simpa using hG), ih ha0,835      normalizedFactors_irreducible hp.irreducible]836    congr 1837    rw [← key _ (Polynomial.monic_normalize hp0)838      ((normalize_associated p).symm.irreducible hp.irreducible), normalize_apply,839      Polynomial.map_mul,840      rootMultiplicity_mul (by simpa [Polynomial.map_ne_zero_iff ι.injective] using hp0),841      coe_normUnit, Polynomial.map_C, rootMultiplicity_C, add_zero]842 843end SurfaceBlowup