Stafford38/Geometry/ActualSelectedNormalizationDivisorEtale.lean

This project (Stafford38) · 1029fdb382eee06e7b59bcf32801f40931e2079a

1 module
2 public import Stafford38.Geometry.ActualNormalizationDivisorEtale
3 public import Stafford38.Geometry.ActualChartNormalizationCenter
4 public import Stafford38.Geometry.ActualOptionColumnBinding
5 public import Stafford38.Geometry.ActualChartResidueMapCoherence
6 public import Stafford38.Geometry.ActualNormalizationCenterResidueKernel
7 public import Stafford38.Geometry.FieldEquivFiniteType
8 public import Stafford38.Geometry.SelectedResidueNormalizationLocalization
9 public import Stafford38.Geometry.ResidueBasisLocalization
10 public import Mathlib.Algebra.MvPolynomial.Rename
11 
12 
13 @[expose] public section
14 
15 set_option autoImplicit false
16 set_option maxHeartbeats 5000000
17 set_option synthInstance.maxHeartbeats 600000
18 set_option linter.style.haveILetI false
19 
20 noncomputable section
21 
22 namespace Stafford38.Geometry.ActualSelectedNormalizationDivisorEtale
23 
24 open IsLocalRing
25 open Stafford38.Geometry.AsymptoticDivisorExistence
26 open Stafford38.Geometry.AsymptoticChartArcAdapter
27 open Stafford38.Geometry.ComponentFunctionFieldBoundary
28 open Stafford38.Geometry.ComponentProjectiveClosure
29 open Stafford38.Geometry.ComponentProjectiveChartKernel
30 open Stafford38.Geometry.GeneralDivisorialVisibleFrame
31 open Stafford38.Geometry.RelativeCoefficientDVR
32 open Stafford38.Geometry.RelativeRetainedBoundaryPlace
33 open Stafford38.Geometry.RetainedGroundMapIdentification
34 open Stafford38.Geometry.SelectedResidueCoefficientLocalization
35 open Stafford38.Geometry.ChartGenericPointFractionRing
36 open Stafford38.Geometry.ProjectiveChartNormalizationCenter
37 open Stafford38.Geometry.MvPolynomialFractionFieldTranscendenceBasis
38 
39 universe u v w
40 
41 structure ActualOptionEtaleCertificate
42     (k : Type u) [Field k] (σ : Type v) (B : Type w)
43     [CommRing B] [Algebra k B]
44     (prime : Ideal B)
45     (parameter : B) (rows : σ → B)
46     (optionMap : MvPolynomial (Option σ) k →ₐ[k] B) : Prop where
47   prime_isPrime : prime.IsPrime
48   optionMap_none : optionMap (MvPolynomial.X none) = parameter
49   optionMap_some : ∀ i : σ,
50     optionMap (MvPolynomial.X (some i)) = rows i
51   formallyEtale :
52     letI : prime.IsPrime := prime_isPrime
53     let actualMap : MvPolynomial (Option σ) k →ₐ[k] Localization.AtPrime prime :=
54       (IsScalarTower.toAlgHom k B (Localization.AtPrime prime)).comp optionMap
55     letI : Algebra (MvPolynomial (Option σ) k) (Localization.AtPrime prime) :=
56       actualMap.toRingHom.toAlgebra
57     Algebra.FormallyEtale (MvPolynomial (Option σ) k) (Localization.AtPrime prime)
58 
59 private theorem span_atPrime_congr
60     {k : Type u} [Field k] {B : Type w} [CommRing B] [Algebra k B]
61     (P Q : Ideal B) [P.IsPrime] [Q.IsPrime] (h : P = Q) (s : B)
62     (hs : Ideal.span {algebraMap B (Localization.AtPrime Q) s} =
63       maximalIdeal (Localization.AtPrime Q)) :
64     Ideal.span {algebraMap B (Localization.AtPrime P) s} =
65       maximalIdeal (Localization.AtPrime P) := by
66   cases h
67   exact hs
68 
69 private theorem formallyEtale_atPrime_congr
70     {R : Type u} [CommRing R] {B : Type w} [CommRing B]
71     (P Q : Ideal B) [P.IsPrime] [Q.IsPrime]
72     (h : P = Q) (f : R →+* B)
73     (hf :
74       letI : Algebra R (Localization.AtPrime P) :=
75         ((algebraMap B (Localization.AtPrime P)).comp f).toAlgebra
76       Algebra.FormallyEtale R (Localization.AtPrime P)) :
77     letI : Algebra R (Localization.AtPrime Q) :=
78       ((algebraMap B (Localization.AtPrime Q)).comp f).toAlgebra
79     Algebra.FormallyEtale R (Localization.AtPrime Q) := by
80   cases h
81   exact hf
82 
83 /-- The affine chart algebra selected by the retained witness. Its chart
84 coordinates use the same generic owner as arbitrary projective charts. -/
85 abbrev actualSelectedChartAlgebra
86     {k : Type u} [Field k] [CharZero k] {m : ℕ} {hm : 0 < m}
87     (P : PrimeSpectrum (MvPolynomial (Fin m) k))
88     (w : GeneralDivisorialVisibleFrameWitness hm P) :
89   Subalgebra k (ComponentFractionField P) :=
90   chartGenericPointSubalgebra P w.column.chart
91     (chartAffineCoordinateEquiv w.column.chart)
92 
93 noncomputable def actualSelectedNormalization
94     {k : Type u} [Field k] [CharZero k] {m : ℕ} {hm : 0 < m}
95     (P : PrimeSpectrum (MvPolynomial (Fin m) k))
96     (w : GeneralDivisorialVisibleFrameWitness hm P) :
97     Subalgebra (actualSelectedChartAlgebra P w).toSubring
98       (ComponentFractionField P) := by
99   let W := w.column.W
100   let F := ComponentFractionField P
101   letI : Algebra (CoordinateZeroLocalRing W.coefficientField) F := W.ambientAlgebra
102   let Q := actualSelectedChartAlgebra P w
103   letI : Algebra Q F := Q.val.toAlgebra
104   letI : Algebra Q.toSubring F := Q.toSubring.subtype.toAlgebra
105   exact integralClosure Q.toSubring F
106 
107 noncomputable def actualSelectedNormalizationCoefficients
108     {k : Type u} [Field k] [CharZero k] {m : ℕ} {hm : 0 < m}
109     (P : PrimeSpectrum (MvPolynomial (Fin m) k))
110     (w : GeneralDivisorialVisibleFrameWitness hm P) :
111     k →+* actualSelectedNormalization P w := by
112   let W := w.column.W
113   let F := ComponentFractionField P
114   letI : Algebra (CoordinateZeroLocalRing W.coefficientField) F := W.ambientAlgebra
115   let Q := actualSelectedChartAlgebra P w
116   let B := actualSelectedNormalization P w
117   letI : Algebra Q.toSubring (ComponentFractionField P) :=
118     Q.toSubring.subtype.toAlgebra
119   exact (chartSubalgebraToIntegralClosure Q).comp (algebraMap k Q)
120 
121 noncomputable def actualSelectedNormalizationCenter
122     {k : Type u} [Field k] [CharZero k] {m : ℕ} {hm : 0 < m}
123     (P : PrimeSpectrum (MvPolynomial (Fin m) k))
124     (w : GeneralDivisorialVisibleFrameWitness hm P)
125     (hQV : let W := w.column.W
126       let F := ComponentFractionField P
127       letI : Algebra (CoordinateZeroLocalRing W.coefficientField) F := W.ambientAlgebra
128       (actualSelectedChartAlgebra P w).toSubring ≤ W.place.valuation.toSubring) :
129     Ideal (actualSelectedNormalization P w).toSubring := by
130   let W := w.column.W
131   let F := ComponentFractionField P
132   letI : Algebra (CoordinateZeroLocalRing W.coefficientField) F := W.ambientAlgebra
133   let Q := actualSelectedChartAlgebra P w
134   exact integralClosureCenter Q.toSubring w.column.W.place.valuation hQV
135 
136 noncomputable def actualSelectedNormalizationCenterPrime
137     {k : Type u} [Field k] [CharZero k] {m : ℕ} {hm : 0 < m}
138     (P : PrimeSpectrum (MvPolynomial (Fin m) k))
139     (w : GeneralDivisorialVisibleFrameWitness hm P)
140     (hQV : let W := w.column.W
141       let F := ComponentFractionField P
142       letI : Algebra (CoordinateZeroLocalRing W.coefficientField) F := W.ambientAlgebra
143       (actualSelectedChartAlgebra P w).toSubring ≤ W.place.valuation.toSubring) :
144     Ideal (actualSelectedNormalization P w) := by
145   let W := w.column.W
146   let F := ComponentFractionField P
147   letI : Algebra (CoordinateZeroLocalRing W.coefficientField) F := W.ambientAlgebra
148   let B := actualSelectedNormalization P w
149   let eB := Stafford38.Geometry.ActualChartNormalizationCenter.subalgebraToSubringRingEquiv B
150   exact (actualSelectedNormalizationCenter P w hQV).comap eB.toRingHom
151 
152 noncomputable def actualSelectedNormalizationRows
153     {k : Type u} [Field k] [CharZero k] {m : ℕ} {hm : 0 < m}
154     (P : PrimeSpectrum (MvPolynomial (Fin m) k))
155     (w : GeneralDivisorialVisibleFrameWitness hm P)
156     {t : Type v} (index : t → Fin m) :
157     t → actualSelectedNormalization P w :=
158   fun z =>
159     let W := w.column.W
160     let F := ComponentFractionField P
161     letI : Algebra (CoordinateZeroLocalRing W.coefficientField) F := W.ambientAlgebra
162     let qB := Stafford38.Geometry.ActualOptionColumnBinding.actualNormalizedProjectiveColumnInIntegralClosure
163       hm P w
164     qB (chartAffineCoordinateEquiv w.column.chart (index z)).1
165 
166 /-- Formal etaleness of the actual option-coordinate map on the selected
167 normalization center. The selected residue basis and its chart-coordinate
168 representatives are fixed inputs, so the coefficient localization, center
169 height, and map are all built from the same retained witness data. The
170 divisor parameter is explicit; callers can feed the one numerator already
171 used in their order factorizations. -/
172 theorem formallyEtale_at_selected_actual_normalization_center_core
173     {k : Type u} [Field k] [CharZero k]
174     {m : ℕ} (hm : 0 < m)
175     (P : PrimeSpectrum (MvPolynomial (Fin m) k))
176     (w : GeneralDivisorialVisibleFrameWitness hm P) :
177     let C := w.column
178     let W := C.W
179     let F := ComponentFractionField P
180     letI : Algebra (CoordinateZeroLocalRing W.coefficientField) F := W.ambientAlgebra
181     let U := W.place.valuation
182     let V := U.toSubring
183     letI : IsDiscreteValuationRing V := W.place.isDiscrete
184     letI : IsLocalRing V := W.place.isDiscrete.toIsLocalRing
185     letI : Algebra W.coefficientField V :=
186       (relativeCoefficientMap W.coefficientField W.place).toAlgebra
187     letI : Algebra k V := C.groundCoeff.toAlgebra
188     let κ := ResidueField V
189     letI : Algebra k κ := retainedResidueGroundAlgebra P ⟨0, hm⟩ W
190     let B := actualSelectedNormalization P w
191     let coeff := actualSelectedNormalizationCoefficients P w
192     letI : Algebra k B := coeff.toAlgebra
193     ∀ (hQV : (actualSelectedChartAlgebra P w).toSubring ≤ V),
194     ∀ (t : Set κ), t.Finite →
195     IsTranscendenceBasis k ((↑) : t → κ) →
196     ∀ (index : t → Fin m), Function.Injective index →
197     (∀ z : t, residue V
198       (w.column.q ((chartAffineCoordinateEquiv w.column.chart) (index z)).1) = (z : κ)) →
199     ∀ (s : B) (hP_B : (actualSelectedNormalizationCenterPrime P w hQV).IsPrime),
200     s ≠ 0 → s ∈ actualSelectedNormalizationCenterPrime P w hQV →
201     ∀ (hspan :
202       letI : (actualSelectedNormalizationCenterPrime P w hQV).IsPrime := hP_B;
203       Ideal.span (Set.singleton (algebraMap B
204         (Localization.AtPrime (actualSelectedNormalizationCenterPrime P w hQV)) s)) =
205           maximalIdeal (Localization.AtPrime (actualSelectedNormalizationCenterPrime P w hQV))),
206     ∀ (fOption : MvPolynomial (Option t) k →ₐ[k] B),
207     (fOption (MvPolynomial.X (none : Option t)) = s) →
208     (∀ z : t, fOption (MvPolynomial.X (some z)) =
209       actualSelectedNormalizationRows P w index z) →
210     ActualOptionEtaleCertificate k t B
211       (actualSelectedNormalizationCenterPrime P w hQV) s
212       (actualSelectedNormalizationRows P w index) fOption := by
213   intro C W F U V κ B coeff hQV t htFinite htBasis index hindex hres
214     s hP_B hs0 hsP hspan fOption hnone hsomeRow
215   classical
216   letI : Fintype t := htFinite.fintype
217   letI : Algebra (CoordinateZeroLocalRing W.coefficientField) F := W.ambientAlgebra
218   letI : IsDiscreteValuationRing V := W.place.isDiscrete
219   letI : IsLocalRing V := W.place.isDiscrete.toIsLocalRing
220   letI : Algebra W.coefficientField V :=
221     (relativeCoefficientMap W.coefficientField W.place).toAlgebra
222   letI : Algebra k V := C.groundCoeff.toAlgebra
223   letI : Algebra k B := coeff.toAlgebra
224   letI : IsScalarTower k V F := C.groundTower
225   let retained : Algebra k κ := retainedResidueGroundAlgebra P ⟨0, hm⟩ W
226   letI : Algebra k κ := retained
227   have hretainedMap : @algebraMap k κ _ _ retained = (residue V).comp C.groundCoeff := by
228     simpa [C, W, V, κ, C.groundCoeff_eq_retained] using w.retainedGroundMap
229   letI : IsScalarTower k V κ := IsScalarTower.of_algebraMap_eq fun c => by
230     have h := RingHom.congr_fun hretainedMap c
231     change algebraMap k κ c = residue V (C.groundCoeff c)
232     exact h
233   let echart := chartAffineCoordinateEquiv C.chart
234   let Q : Subalgebra k F := Algebra.adjoin k (Set.range (chartGenericPoint P C.chart echart))
235   have hground : ∀ c : k, (algebraMap k V c : F) = algebraMap k F c := by
236     intro c
237     exact DFunLike.congr_fun C.groundCoeff_commutes c
238   let x : t → Q := fun z =>
239     ⟨chartGenericPoint P C.chart echart (index z),
240       Algebra.subset_adjoin (R := k) (A := F) (Set.mem_range_self (index z))⟩
241   have hx : ∀ z : t,
242       residue V ⟨(x z : F), hQV (x z).property⟩ = (z : κ) := by
243     intro z
244     have hnorm := chartGenericPoint_eq_normalized_lift
245       (P := P) (V := V) C.chart echart C.q C.scale C.chart_one C.q_commonScale
246     have hxV : (⟨(x z : F), hQV (x z).property⟩ : V) =
247         C.q (echart (index z)).1 := by
248       apply Subtype.ext
249       change chartGenericPoint P C.chart echart (index z) =
250         (C.q (echart (index z)).1 : F)
251       exact congrFun hnorm (index z)
252     rw [hxV]
253     exact hres z
254   have hchartPoint : componentProjectivePoint P C.chart ≠ 0 := by
255     intro hz
256     have hq := C.q_commonScale C.chart
257     change (C.q C.chart : F) = C.scale * componentProjectivePoint P C.chart at hq
258     have hq1 : (C.q C.chart : F) = 1 := congrArg Subtype.val C.chart_one
259     rw [hz, mul_zero, hq1] at hq
260     exact one_ne_zero hq
261   have hBasisData :=
262     Stafford38.Geometry.ActualChartRelativeDegree.same_witness_component_trdeg_one_from_basis
263       hm P w t htFinite htBasis index hres
264   let eA := Classical.choose hBasisData
265   have hBasisData1 := Classical.choose_spec hBasisData
266   let fA := Classical.choose hBasisData1
267   have hBasisData2 := Classical.choose_spec hBasisData1
268   let iA := Classical.choose hBasisData2
269   have hBasisData3 := Classical.choose_spec hBasisData2
270   let g := Classical.choose hBasisData3
271   have hBasisData4 := Classical.choose_spec hBasisData3
272   let fEV := Classical.choose hBasisData4
273   have hBasisData5 := Classical.choose_spec hBasisData4
274   let fEF := Classical.choose hBasisData5
275   have hBasisProps := Classical.choose_spec hBasisData5
276   have hg := hBasisProps.1
277   have hgenA := hBasisProps.2.1
278   have hfA := hBasisProps.2.2.1
279   have hgvar := hBasisProps.2.2.2.1
280   have hresE := hBasisProps.2.2.2.2.1
281   have hfE := hBasisProps.2.2.2.2.2.1
282   have hiA := hBasisProps.2.2.2.2.2.2.1
283   have hgen := hBasisProps.2.2.2.2.2.2.2.1
284   have htrdeg := hBasisProps.2.2.2.2.2.2.2.2
285   letI : Algebra (FractionRing (MvPolynomial t k)) F := fEF.toRingHom.toAlgebra
286   let P0 := MvPolynomial t k
287   let E := FractionRing P0
288   let R0 : Subalgebra k Q := Algebra.adjoin k (Set.range x)
289   letI : Algebra Q.toSubring F := Q.toSubring.subtype.toAlgebra
290   have hQfrac : IsFractionRing Q.toSubring F := by
291     let hQ : IsFractionRing Q F :=
292       chartGenericPointSubalgebra_isFractionRing P C.chart echart hchartPoint
293     letI : IsFractionRing Q F := hQ
294     letI : FaithfulSMul Q.toSubring F :=
295       (faithfulSMul_iff_algebraMap_injective Q.toSubring F).mpr Subtype.val_injective
296     apply IsFractionRing.of_field Q.toSubring F
297     intro z
298     obtain ⟨a, b, hb, hz⟩ := IsFractionRing.div_surjective Q z
299     let eqv := Stafford38.Geometry.ActualChartNormalizationCenter.subalgebraToSubringRingEquiv Q
300     refine ⟨eqv a, eqv b, ?_⟩
301     change z = (eqv a : F) / (eqv b : F)
302     calc
303       z = (a : F) / (b : F) := hz.symm
304       _ = (eqv a : F) / (eqv b : F) := by rfl
305   letI : IsFractionRing Q.toSubring F := hQfrac
306   letI : Algebra k Q.toSubring := Q.algebra
307   letI : IsScalarTower k Q.toSubring F := IsScalarTower.of_algebraMap_eq fun _ => rfl
308   have hQfinite : Algebra.FiniteType k Q.toSubring := by
309     change Algebra.FiniteType k Q
310     exact chartGenericPointSubalgebra_finiteType P C.chart echart
311   letI : Algebra.FiniteType k Q.toSubring := hQfinite
312   letI : Algebra Q.toSubring B := B.algebra
313   letI : IsScalarTower k Q.toSubring B := IsScalarTower.of_algebraMap_eq fun _ => rfl
314   have hBfinite : Algebra.FiniteType k B :=
315     Stafford38.Geometry.ProjectiveChartNormalizationFinite.integralClosure_finiteType_over_base
316       k Q.toSubring F
317   have hBfracSubring : IsFractionRing B.toSubring F :=
318     Stafford38.Geometry.IntegralClosureCenterDVR.integralClosure_isFractionRing Q.toSubring
319   letI : IsFractionRing B.toSubring F := hBfracSubring
320   letI : FaithfulSMul B F :=
321     (faithfulSMul_iff_algebraMap_injective B F).mpr Subtype.val_injective
322   have hBfrac : IsFractionRing B F := by
323     apply IsFractionRing.of_field B F
324     intro z
325     obtain ⟨a, b, hb, hz⟩ := IsFractionRing.div_surjective B.toSubring z
326     let eqv := Stafford38.Geometry.ActualChartNormalizationCenter.subalgebraToSubringRingEquiv B
327     refine ⟨eqv.symm a, eqv.symm b, ?_⟩
328     change z = (eqv.symm a : F) / (eqv.symm b : F)
329     calc
330       z = (a : F) / (b : F) := hz.symm
331       _ = (eqv.symm a : F) / (eqv.symm b : F) := by rfl
332   letI : IsFractionRing B F := hBfrac
333   letI : Algebra E κ := g.toRingHom.toAlgebra
334   letI : IsScalarTower k E κ := IsScalarTower.of_algebraMap_eq fun c =>
335     (g.commutes c).symm
336   have hvars : IsTranscendenceBasis k
337       (fun z : t => algebraMap E κ (algebraMap P0 E (MvPolynomial.X z))) := by
338     change IsTranscendenceBasis k
339       (fun z : t => g (algebraMap P0 E (MvPolynomial.X z)))
340     have hfun : (fun z : t => g (algebraMap P0 E (MvPolynomial.X z))) =
341         ((↑) : t → κ) := by
342       funext z
343       exact hgvar z
344     rw [hfun]
345     exact htBasis
346   have hκalg : Algebra.IsAlgebraic E κ :=
347     isAlgebraic_fractionRing_of_variable_images_isTranscendenceBasis hvars
348   let e := chartAffineCoordinateEquiv C.chart
349   have hQV' : Q.toSubring ≤ V := hQV
350   have hground' := hground
351   have hLocData :=
352     Stafford38.Geometry.SelectedResidueCoefficientLocalization.exists_chart_normalization_localization_map
353       Q U hground' hQV' htBasis x hx
354   choose j fB fLoc hjF hfBF hLoc0 hcomp using hLocData
355   letI : Algebra R0 B := j.toAlgebra
356   let L := Localization (Algebra.algebraMapSubmonoid B (nonZeroDivisors R0))
357   letI : Algebra B L := inferInstance
358   letI : SMul R0 F := (inferInstance : Algebra R0 F).toSMul
359   letI : SMul B F := (inferInstance : Algebra B F).toSMul
360   letI : SMul k R0 := (inferInstance : Algebra k R0).toSMul
361   letI : SMul R0 B := (inferInstance : Algebra R0 B).toSMul
362   letI : SMul k B := (inferInstance : Algebra k B).toSMul
363   have hRF : algebraMap R0 F = (algebraMap B F).comp (algebraMap R0 B) := by
364     ext a
365     change (a : F) = (j a : F)
366     exact (hjF a).symm
367   letI : IsScalarTower R0 B F := IsScalarTower.of_algebraMap_eq' hRF
368   have hJMap (a : R0) : algebraMap R0 B a = j a := rfl
369   have hKB : algebraMap k B = (algebraMap R0 B).comp (algebraMap k R0) := by
370     ext c
371     change (algebraMap k B c : F) =
372       (algebraMap R0 B (algebraMap k R0 c) : F)
373     change (algebraMap k B c : F) = (j (algebraMap k R0 c) : F)
374     rw [hjF]
375     rfl
376   letI : IsScalarTower k R0 B := IsScalarTower.of_algebraMap_eq' hKB
377   have hinj : Function.Injective (algebraMap R0 B) := by
378     intro a b hab
379     apply Subtype.ext
380     apply Subtype.val_injective
381     have hab' : j a = j b := by rw [← hJMap a, ← hJMap b]; exact hab
382     calc
383       ((a : Q) : F) = ((j a : B) : F) := (hjF a).symm
384       _ = ((j b : B) : F) := congrArg (fun z : B => (z : F)) hab'
385       _ = ((b : Q) : F) := hjF b
386   obtain ⟨fEL, hELgen, hELfinite, hELdomain, hFdata⟩ :=
387     Stafford38.Geometry.FieldEquivFiniteType.exists_finiteType_domain_fractionField_localization
388       (k := k) (P := P0) (R := R0) (B := B) (F := F) eA hinj
389   obtain ⟨fF, hFextend, hFfrac⟩ := hFdata
390   letI : Algebra E L := fEL.toRingHom.toAlgebra
391   letI : Algebra L F := fF.toAlgebra
392   letI : IsDomain L := hELdomain
393   have hELgen' : ∀ p : P0,
394       fEL (algebraMap P0 E p) = algebraMap B L (j (eA p)) := by
395     intro p
396     calc
397       fEL (algebraMap P0 E p) = algebraMap B L (algebraMap R0 B (eA p)) := hELgen p
398       _ = algebraMap B L (j (eA p)) := congrArg (algebraMap B L) (hJMap (eA p))
399   have hEFgen : ∀ p : P0,
400       fF (fEL (algebraMap P0 E p)) = fEF (algebraMap P0 E p) := by
401     intro p
402     calc
403       fF (fEL (algebraMap P0 E p)) =
404           fF (algebraMap B L (algebraMap R0 B (eA p))) := congrArg fF (hELgen p)
405       _ = algebraMap B F (algebraMap R0 B (eA p)) := hFextend _
406       _ = (j (eA p) : F) := congrArg (fun b : B => (b : F)) (hJMap (eA p))
407       _ = (((eA p : R0) : Q) : F) := hjF (eA p)
408       _ = fEF (algebraMap P0 E p) := (hgen p).symm
409   have hCoherence :=
410     Stafford38.Geometry.FieldEquivFiniteType.fractionField_map_coherence
411       fEL fF fEF hEFgen
412   have hEFmap := hCoherence.1
413   have hEFLtower := hCoherence.2
414   letI : IsScalarTower (FractionRing P0)
415       (Localization (Algebra.algebraMapSubmonoid B (nonZeroDivisors R0))) F := hEFLtower
416   let rhoL : L →+* κ := (residue V).comp fLoc
417   let rhoB : B →+* κ := (residue V).comp fB
418   let qV : Q →ₐ[k] V :=
419     Stafford38.Geometry.SelectedResidueCoefficientLocalization.chartAlgebraToValuation
420       Q U hground hQV
421   have hAchart : fA.comp eA.toAlgHom =
422       qV.comp ((Subalgebra.val R0).comp eA.toAlgHom) := by
423     apply MvPolynomial.algHom_ext
424     intro z
425     change fA (eA (MvPolynomial.X z)) = qV ((eA (MvPolynomial.X z) : R0) : Q)
426     calc
427       fA (eA (MvPolynomial.X z)) =
428           (⟨(x z : F), hQV (x z).property⟩ : V) := hfA z
429       _ = qV (x z) := by apply Subtype.ext; rfl
430       _ = qV ((eA (MvPolynomial.X z) : R0) : Q) :=
431         congrArg qV (hgenA z).symm
432   have hRhoE : rhoL.comp fEL.toRingHom = g.toRingHom :=
433     Stafford38.Geometry.ActualChartResidueMapCoherence.residue_map_coherence
434       eA iA fEV fA g fEL (algebraMap B L) fLoc fB j (Subalgebra.val R0) qV
435       (residue V) rhoL hELgen' hLoc0 rfl hcomp hAchart hfE
436       (fun p => hiA p) hresE
437   let rhoE : L →ₐ[E] κ := {
438     toRingHom := rhoL
439     commutes' := by
440       intro z
441       change rhoL (algebraMap E L z) = algebraMap E κ z
442       change rhoL (fEL z) = g z
443       exact RingHom.congr_fun hRhoE z
444   }
445   letI : Algebra.IsAlgebraic E κ := hκalg
446   let p : Ideal L := RingHom.ker rhoL
447   have hpprime : p.IsPrime := RingHom.ker_isPrime _
448   letI : p.IsPrime := hpprime
449   have hpmax : p.IsMaximal := by
450     change (RingHom.ker (rhoE : L →+* κ)).IsMaximal
451     exact Stafford38.Geometry.ResidueBasisLocalization.ker_isMaximal_of_algebraic_residue
452       (E := E) (A := L) (K := κ) rhoE
453   letI : p.IsMaximal := hpmax
454   have hLoc : rhoL.comp (algebraMap B L) = rhoB := by
455     ext b
456     change residue V (fLoc (algebraMap B L b)) = residue V (fB b)
457     exact congrArg (residue V) (RingHom.congr_fun hLoc0 b)
458   let eB := Stafford38.Geometry.ActualChartNormalizationCenter.subalgebraToSubringRingEquiv B
459   let center := actualSelectedNormalizationCenter P w hQV
460   let P_B := actualSelectedNormalizationCenterPrime P w hQV
461   letI : P_B.IsPrime := hP_B
462   have hcenterKernel : RingHom.ker rhoB = center.comap eB.toRingHom :=
463     Stafford38.Geometry.ActualNormalizationCenterResidueKernel.residue_kernel_eq_canonical_center_comap
464       Q.toSubring U hQV eB fB (by intro b; rfl) hfBF
465   have hcontract : p.comap (algebraMap B L) = center.comap eB.toRingHom := by
466     ext b
467     change rhoL (algebraMap B L b) = 0 ↔ b ∈ center.comap eB.toRingHom
468     have heq : rhoL (algebraMap B L b) = rhoB b := by
469       simpa only [RingHom.comp_apply] using congrArg (fun q : B →+* κ => q b) hLoc
470     rw [heq, ← hcenterKernel]
471     exact (RingHom.mem_ker (f := rhoB)).symm
472   have hcontractB : p.comap (algebraMap B L) = P_B := hcontract
473   let f : P0 →ₐ[k] B := (IsScalarTower.toAlgHom k R0 B).comp eA.toAlgHom
474   have hfMap (z : P0) : f z = algebraMap R0 B (eA z) := rfl
475   have hELf (z : P0) :
476       fEL (algebraMap P0 E z) = algebraMap B L (f z) := by
477     calc
478       fEL (algebraMap P0 E z) = algebraMap B L (j (eA z)) := hELgen' z
479       _ = algebraMap B L (algebraMap R0 B (eA z)) :=
480         congrArg (algebraMap B L) (hJMap (eA z)).symm
481       _ = algebraMap B L (f z) :=
482         congrArg (algebraMap B L) (hfMap z).symm
483   have hcoeffL :
484       (algebraMap E L).comp (algebraMap P0 E) =
485         (algebraMap B L).comp f.toRingHom := by
486     apply RingHom.ext
487     intro z
488     change fEL (algebraMap P0 E z) = algebraMap B L (f z)
489     exact hELf z
490   have hresVar (z : P0) : rhoB (f z) = g (algebraMap P0 E z) := by
491     have h := congrArg (fun φ : E →+* κ => φ (algebraMap P0 E z)) hRhoE
492     calc
493       rhoB (f z) = rhoL (algebraMap B L (f z)) := by
494         exact (RingHom.congr_fun hLoc (f z)).symm
495       _ = rhoL (fEL (algebraMap P0 E z)) := by
496         exact congrArg rhoL (hELf z).symm
497       _ = g (algebraMap P0 E z) := h
498   have hinjResid : Function.Injective (rhoB.comp f.toRingHom) := by
499     intro a b hab
500     apply IsFractionRing.injective P0 E
501     apply hg
502     calc
503       g (algebraMap P0 E a) = rhoB (f a) := (hresVar a).symm
504       _ = rhoB (f b) := hab
505       _ = g (algebraMap P0 E b) := hresVar b
506   have hheight : (p.comap (algebraMap B L)).height = 1 := by
507     have hcenter :=
508       Stafford38.Geometry.ActualChartNormalizationCenter.actual_chart_normalization_center_height_one_of_selected_basis
509         hm P w t htFinite htBasis index hindex hres
510     rw [hcontract]
511     exact (RingEquiv.height_comap eB center).trans hcenter
512   let qB := Stafford38.Geometry.ActualOptionColumnBinding.actualNormalizedProjectiveColumnInIntegralClosure
513     hm P w
514   obtain ⟨_hchartB, _hcoeB, hrowsB⟩ :=
515     Stafford38.Geometry.ActualOptionColumnBinding.actualNormalizedProjectiveColumnInIntegralClosure_spec
516       hm P w
517   have hfF (z : t) : ((f (MvPolynomial.X z) : B) : F) =
518       chartGenericPoint P C.chart echart (index z) := by
519     change ((j (eA (MvPolynomial.X z)) : B) : F) = _
520     rw [hjF]
521     change ((eA (MvPolynomial.X z) : R0) : F) = _
522     calc
523       ((eA (MvPolynomial.X z) : R0) : F) = (x z : F) :=
524         congrArg (fun a : Q => (a : F)) (hgenA z)
525       _ = chartGenericPoint P C.chart echart (index z) := rfl
526   have hrowTof (z : t) :
527       actualSelectedNormalizationRows P w index z = f (MvPolynomial.X z) := by
528     apply Subtype.ext
529     change ((qB (echart (index z)).1 : B) : F) = _
530     exact (hrowsB (index z)).trans (hfF z).symm
531   have hsome : ∀ z : t,
532       fOption (MvPolynomial.X (some z)) = f (MvPolynomial.X z) := by
533     intro z
534     rw [hsomeRow z, hrowTof z]
535   letI : P_B.IsPrime := hP_B
536   let actualMap : MvPolynomial (Option t) k →ₐ[k] Localization.AtPrime P_B :=
537     (IsScalarTower.toAlgHom k B (Localization.AtPrime P_B)).comp fOption
538   letI : Algebra (MvPolynomial (Option t) k)
539       (Localization.AtPrime P_B) := actualMap.toRingHom.toAlgebra
540   letI : IsNoetherianRing B := Algebra.FiniteType.isNoetherianRing k B
541   letI : IsIntegrallyClosedIn B F := by
542     change IsIntegrallyClosedIn (integralClosure Q.toSubring F) F
543     infer_instance
544   letI : IsIntegrallyClosed B := IsIntegrallyClosed.of_isIntegrallyClosedIn B F
545   letI : (p.comap (algebraMap B L)).IsPrime := by
546     rw [hcontract]
547     exact hP_B
548   have hsP' : s ∈ p.comap (algebraMap B L) := by
549     rw [hcontract]
550     exact hsP
551   have hspan' :
552       Ideal.span (Set.singleton (algebraMap B
553         (Localization.AtPrime (p.comap (algebraMap B L))) s)) =
554           maximalIdeal (Localization.AtPrime (p.comap (algebraMap B L))) := by
555     exact span_atPrime_congr (k := k) (B := B)
556       (p.comap (algebraMap B L)) P_B hcontractB s hspan
557   have hEt := Stafford38.Geometry.ActualNormalizationDivisorEtale.formallyEtale_at_actual_normalization_center_of_specified_parameter
558     p rhoL rhoB rfl hLoc f hinjResid hcoeffL hELfinite hheight s hs0 hsP' hspan'
559     fOption hnone hsome
560   exact {
561     prime_isPrime := hP_B
562     optionMap_none := hnone
563     optionMap_some := hsomeRow
564     formallyEtale := formallyEtale_atPrime_congr
565       (P := p.comap (algebraMap B L)) (Q := P_B) hcontractB
566       fOption.toRingHom hEt
567   }
568 
569 end Stafford38.Geometry.ActualSelectedNormalizationDivisorEtale
570