Stafford38/Paper/Section5/JacobianConverse.lean

This project (Stafford38) · 1029fdb382eee06e7b59bcf32801f40931e2079a

1 module
2 
3 public import Stafford38.Paper.Support.DimensionTheory
4 public import Stafford38.Paper.Section5.GenericTangentRank
5 public import Stafford38.Geometry.SmoothAffineConormal
6 public import Stafford38.Geometry.ExactDivisorialVisibleFrameExistence
7 public import Mathlib.RingTheory.Smooth.Local
8 public import Mathlib.RingTheory.Etale.Kaehler
9 
10 @[expose] public section
11 
12 /-!
13 # The Jacobian criterion: Jacobian smooth points are Mathlib smooth points
14 
15 Let `𝔭 ⊂ K[x] = K[x_1, …, x_n]` be prime, `y ∈ V(𝔭)`, and suppose that
16 `span {df_y : f ∈ 𝔭}` has dimension `c = n - trdeg_K Frac(K[x]/𝔭)`.  Choose
17 `f_1, …, f_c ∈ 𝔭` with independent differentials at `y` and let `P'` be the
18 localization of `K[x]` at `y`.
19 
20 1. `B = P'/(f_1, …, f_c)` is a regular local ring: `dim B ≥ n - c` by Krull's height
21    theorem (`le_height_ker_aeval`), and `𝔪_B` is generated by `n - c` linear forms
22    (Taylor expansion and Nakayama).  Hence `B` is a domain.
23 2. The prime `𝔯 = ker(K[x] → B)` lies between `(f)` and `𝔭`.  At the generic point of
24    `𝔯` the Jacobian of `f` still has rank `c` (a `c × c` minor is a unit at `y`), so
25    `trdeg K[x]/𝔯 = dim Θ ≤ n - c = trdeg K[x]/𝔭` (Lemma 5.12(a)); a nonzero prime lowers
26    the transcendence degree (`trdeg_quotient_lt`), so `𝔯 = 𝔭` and `𝔭 P' = (f) P'`.
27 3. Mathlib's local Jacobian criterion
28    (`Algebra.FormallySmooth.iff_injective_cotangentComplexBaseChange`) for
29    `P' → (K[x]/𝔭)_𝔪` then reduces smoothness to the independence of the `df_i(y)`.
30 -/
31 
32 namespace Stafford38.Paper.Section5
33 
34 open MvPolynomial IsLocalRing
35 open Stafford38.Paper.Support
36 open Stafford38.Geometry
37 open Stafford38.Geometry.AffineConormalSpan
38 open Stafford38.Geometry.CoisotropicTranslation
39 
40 noncomputable section
41 
42 universe u
43 
44 section Taylor
45 
46 variable {k : Type u} [Field k] {n : ℕ}
47 
48 /-- The maximal ideal `𝔪_y = ker(eval_y)` of a point `y ∈ K^n`. -/
49 abbrev pointIdeal (y : Fin n → k) : Ideal (MvPolynomial (Fin n) k) :=
50   RingHom.ker (MvPolynomial.aeval (R := k) y)
51 
52 instance (y : Fin n → k) : (pointIdeal y).IsPrime := RingHom.ker_isPrime _
53 
54 theorem mem_pointIdeal {y : Fin n → k} {g : MvPolynomial (Fin n) k} :
55     g ∈ pointIdeal y ↔ MvPolynomial.eval y g = 0 := by
56   rw [RingHom.mem_ker]
57   rfl
58 
59 /-- The linear form `Σ_j v_j (x_j - y_j)`. -/
60 def linearPart (y : Fin n → k) : (Fin n → k) →ₗ[k] MvPolynomial (Fin n) k where
61   toFun v := ∑ j, C (v j) * (X j - C (y j))
62   map_add' v w := by simp [add_mul, Finset.sum_add_distrib]
63   map_smul' a v := by
64     simp only [Pi.smul_apply, smul_eq_mul, map_mul, RingHom.id_apply]
65     rw [Finset.smul_sum]
66     refine Finset.sum_congr rfl fun j _ ↦ ?_
67     rw [MvPolynomial.smul_eq_C_mul]
68     ring
69 
70 theorem linearPart_mem (y v : Fin n → k) : linearPart y v ∈ pointIdeal y := by
71   refine Ideal.sum_mem _ fun j _ ↦ Ideal.mul_mem_left (pointIdeal y) (C (v j)) ?_
72   rw [mem_pointIdeal]
73   simp
74 
75 theorem linearPart_single (y : Fin n → k) (j : Fin n) :
76     linearPart y (Pi.single j 1) = X j - C (y j) := by
77   classical
78   simp [linearPart, Pi.single_apply]
79 
80 theorem differentialAt_add (y : Fin n → k) (p q : MvPolynomial (Fin n) k) :
81     differentialAt y (p + q) = differentialAt y p + differentialAt y q := by
82   funext i
83   simp [differentialAt]
84 
85 /-- **Taylor expansion to first order.** `g - g(y) - Σ_j ∂_j g(y) (x_j - y_j) ∈ 𝔪_y²`. -/
86 theorem taylor_mem_pointIdeal_sq (y : Fin n → k) (g : MvPolynomial (Fin n) k) :
87     g - C (MvPolynomial.eval y g) - linearPart y (differentialAt y g) ∈ pointIdeal y ^ 2 := by
88   classical
89   induction g using MvPolynomial.induction_on with
90   | C a =>
91     have : differentialAt y (C a) = 0 := by funext i; simp [differentialAt]
92     simp [this]
93   | add p q hp hq =>
94     rw [differentialAt_add, map_add]
95     convert add_mem hp hq using 1
96     simp only [map_add]
97     ring
98   | mul_X p j hp =>
99     have hd : differentialAt y (p * X j) =
100         y j • differentialAt y p + MvPolynomial.eval y p • Pi.single j 1 := by
101       funext i
102       simp only [differentialAt, MvPolynomial.pderiv_mul, MvPolynomial.pderiv_X, map_add,
103         map_mul, MvPolynomial.eval_X, Pi.add_apply, Pi.smul_apply, smul_eq_mul]
104       by_cases h : i = j
105       · subst h; simp; ring
106       · simp [h, Ne.symm h]; ring
107     have hid : p * X j - C (MvPolynomial.eval y (p * X j)) -
108         linearPart y (differentialAt y (p * X j)) =
109         linearPart y (differentialAt y p) * (X j - C (y j)) +
110           (p - C (MvPolynomial.eval y p) - linearPart y (differentialAt y p)) * X j := by
111       rw [hd, map_add, map_smul, map_smul, linearPart_single, MvPolynomial.eval_mul,
112         MvPolynomial.eval_X, MvPolynomial.smul_eq_C_mul, MvPolynomial.smul_eq_C_mul, map_mul]
113       ring
114     rw [hid, pow_two]
115     exact add_mem (Ideal.mul_mem_mul (linearPart_mem _ _) (by rw [mem_pointIdeal]; simp))
116       (Ideal.mul_mem_right _ _ (pow_two (pointIdeal y) ▸ hp))
117 
118 end Taylor
119 
120 section RegularQuotient
121 
122 variable {k : Type u} [Field k] {n : ℕ}
123 
124 theorem withBot_natCast_le_of_add_le {a c : ℕ} {D : WithBot ℕ∞}
125     (h : ((a + c : ℕ) : WithBot ℕ∞) ≤ D + c) : (a : WithBot ℕ∞) ≤ D := by
126   induction D using WithBot.recBotCoe with
127   | bot => simp at h
128   | coe d =>
129     induction d using ENat.recTopCoe with
130     | top => exact_mod_cast le_top
131     | coe d =>
132       have : a + c ≤ d + c := by exact_mod_cast h
133       exact_mod_cast (by omega : a ≤ d)
134 
135 /-- Nakayama: if `𝔪 ⊆ N + 𝔪²` then `𝔪 ⊆ N`. -/
136 theorem maximalIdeal_le_of_le_sup_sq {R : Type*} [CommRing R] [IsLocalRing R]
137     [IsNoetherianRing R] {N : Ideal R} (h : maximalIdeal R ≤ N ⊔ maximalIdeal R * maximalIdeal R) :
138     maximalIdeal R ≤ N := by
139   apply Submodule.le_of_le_smul_of_le_jacobson_bot (IsNoetherian.noetherian _)
140     (IsLocalRing.jacobson_eq_maximalIdeal ⊥ bot_ne_top).ge
141   rw [smul_eq_mul]
142   exact h
143 
144 /-- **`P'/(f_1, …, f_c)` is a regular local ring, hence a domain**, when the `f_i` vanish
145 at `y` and have linearly independent differentials there. -/
146 theorem isDomain_localization_quotient {ι : Type*} [Fintype ι] (y : Fin n → k)
147     (f : ι → MvPolynomial (Fin n) k) (hfy : ∀ i, MvPolynomial.eval y (f i) = 0)
148     (hli : LinearIndependent k fun i ↦ differentialAt y (f i)) :
149     IsDomain (Localization.AtPrime (pointIdeal y) ⧸
150       (Ideal.span (Set.range f)).map
151         (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)))) := by
152   classical
153   let 𝔮 : Ideal (MvPolynomial (Fin n) k) := Ideal.span (Set.range f)
154   let 𝔮' : Ideal (Localization.AtPrime (pointIdeal y)) := 𝔮.map (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)))
155   let c := Fintype.card ι
156   have hcn : c ≤ n := by
157     have := hli.fintype_card_le_finrank
158     simpa using this
159   have h𝔮M : 𝔮 ≤ pointIdeal y := by
160     rw [Ideal.span_le]
161     rintro _ ⟨i, rfl⟩
162     exact mem_pointIdeal.2 (hfy i)
163   have h𝔮'le : 𝔮' ≤ maximalIdeal (Localization.AtPrime (pointIdeal y)) := by
164     rw [← Localization.AtPrime.map_eq_maximalIdeal]
165     exact Ideal.map_mono h𝔮M
166   have hne : 𝔮' ≠ ⊤ := fun h ↦ (maximalIdeal.isMaximal (Localization.AtPrime (pointIdeal y))).ne_top (top_le_iff.1 (h ▸ h𝔮'le))
167   have : Nontrivial ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮') := Ideal.Quotient.nontrivial_iff.2 hne
168   have : IsLocalRing ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮') :=
169     IsLocalRing.of_surjective' (Ideal.Quotient.mk _) Ideal.Quotient.mk_surjective
170   -- `dim B ≥ n - c`
171   have hdimP' : (n : WithBot ℕ∞) ≤ ringKrullDim (Localization.AtPrime (pointIdeal y)) := by
172     rw [IsLocalization.AtPrime.ringKrullDim_eq_height (pointIdeal y) (Localization.AtPrime (pointIdeal y))]
173     exact_mod_cast le_height_ker_aeval y
174   have hsf : 𝔮'.spanFinrank ≤ c := by
175     have h1 : 𝔮' = Ideal.span (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)) '' Set.range f) := Ideal.map_span _ _
176     rw [h1]
177     refine (Submodule.spanFinrank_span_le_ncard_of_finite ((Set.finite_range f).image _)).trans ?_
178     refine (Set.ncard_image_le (Set.finite_range f)).trans ?_
179     rw [← Set.image_univ]
180     refine (Set.ncard_image_le Set.finite_univ).trans ?_
181     simp [c]
182   have hdimB : ((n - c : ℕ) : WithBot ℕ∞) ≤ ringKrullDim ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮') := by
183     have hht := height_le_ringKrullDim_quotient_add_spanFinrank (p := maximalIdeal (Localization.AtPrime (pointIdeal y))) h𝔮'le
184     rw [IsLocalRing.maximalIdeal_height_eq_ringKrullDim] at hht
185     apply withBot_natCast_le_of_add_le (c := c)
186     calc (((n - c) + c : ℕ) : WithBot ℕ∞) = n := by rw [Nat.sub_add_cancel hcn]
187       _ ≤ ringKrullDim (Localization.AtPrime (pointIdeal y)) := hdimP'
188       _ ≤ ringKrullDim ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮') + 𝔮'.spanFinrank := hht
189       _ ≤ ringKrullDim ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮') + c := by gcongr
190   -- `𝔪_B` is generated by `n - c` elements
191   let W : Submodule k (Fin n → k) := Submodule.span k (Set.range fun i ↦ differentialAt y (f i))
192   obtain ⟨Wc, hWc⟩ := Submodule.exists_isCompl W
193   have hWrank : Module.finrank k W = c := finrank_span_eq_card hli
194   have hWcrank : Module.finrank k Wc = n - c := by
195     have := Submodule.finrank_add_eq_of_isCompl hWc
196     rw [Module.finrank_fin_fun, hWrank] at this
197     omega
198   let bc := Module.finBasis k Wc
199   let ℓ : Fin (Module.finrank k Wc) → (MvPolynomial (Fin n) k) := fun t ↦ linearPart y (bc t)
200   let J : Ideal (MvPolynomial (Fin n) k) := Ideal.span (Set.range ℓ)
201   have hcover : pointIdeal y ≤ J ⊔ 𝔮 ⊔ pointIdeal y * pointIdeal y := by
202     rw [← pow_two]
203     intro a ha
204     have ha0 : MvPolynomial.eval y a = 0 := mem_pointIdeal.1 ha
205     have hT := taylor_mem_pointIdeal_sq y a
206     rw [ha0, map_zero, sub_zero] at hT
207     obtain ⟨w, hw, w', hw', hww⟩ := Submodule.mem_sup.1
208       (hWc.sup_eq_top ▸ Submodule.mem_top : differentialAt y a ∈ W ⊔ Wc)
209     have hW : W ≤ ((𝔮 ⊔ pointIdeal y ^ 2).restrictScalars k).comap (linearPart y) := by
210       rw [Submodule.span_le]
211       rintro _ ⟨i, rfl⟩
212       have hTi := taylor_mem_pointIdeal_sq y (f i)
213       rw [hfy i, map_zero, sub_zero] at hTi
214       change linearPart y (differentialAt y (f i)) ∈ 𝔮 ⊔ pointIdeal y ^ 2
215       have : linearPart y (differentialAt y (f i)) =
216           f i - (f i - linearPart y (differentialAt y (f i))) := by ring
217       rw [this]
218       exact sub_mem (Ideal.mem_sup_left (Ideal.subset_span ⟨i, rfl⟩)) (Ideal.mem_sup_right hTi)
219     have hWc' : linearPart y w' ∈ J := by
220       have := bc.sum_repr ⟨w', hw'⟩
221       have h2 : w' = ∑ t, bc.repr ⟨w', hw'⟩ t • (bc t : Fin n → k) := by
222         have h := congrArg Subtype.val this
223         rw [Submodule.coe_sum] at h
224         simp_rw [Submodule.coe_smul] at h
225         exact h.symm
226       rw [h2, map_sum]
227       exact Ideal.sum_mem _ fun t _ ↦ by
228         rw [map_smul, MvPolynomial.smul_eq_C_mul]
229         exact Ideal.mul_mem_left _ _ (Ideal.subset_span ⟨t, rfl⟩)
230     have hsplit : a = (a - linearPart y (differentialAt y a)) + linearPart y w +
231         linearPart y w' := by
232       rw [add_assoc, ← map_add, hww]
233       ring
234     rw [hsplit]
235     have hw2 : linearPart y w ∈ 𝔮 ⊔ pointIdeal y ^ 2 := hW hw
236     refine add_mem (add_mem (Ideal.mem_sup_right hT) ?_) (Ideal.mem_sup_left
237       (Ideal.mem_sup_left hWc'))
238     obtain ⟨u, hu, v, hv, huv⟩ := Submodule.mem_sup.1 hw2
239     rw [← huv]
240     exact add_mem (Ideal.mem_sup_left (Ideal.mem_sup_right hu)) (Ideal.mem_sup_right hv)
241   let φ : (MvPolynomial (Fin n) k) →+* (Localization.AtPrime (pointIdeal y)) ⧸ 𝔮' := (Ideal.Quotient.mk 𝔮').comp (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)))
242   have h𝔪B : maximalIdeal ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮') = (pointIdeal y).map φ := by
243     rw [← Ideal.map_map, Localization.AtPrime.map_eq_maximalIdeal,
244       map_maximalIdeal_of_surjective _ Ideal.Quotient.mk_surjective]
245   have h𝔮B : 𝔮.map φ = ⊥ := by
246     rw [← Ideal.map_map]
247     exact Ideal.map_quotient_self 𝔮'
248   have hJle : J.map φ ≤ maximalIdeal ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮') := by
249     rw [h𝔪B]
250     apply Ideal.map_mono
251     rw [Ideal.span_le]
252     rintro _ ⟨t, rfl⟩
253     exact linearPart_mem _ _
254   have hNak : maximalIdeal ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮') ≤ J.map φ := by
255     have h := Ideal.map_mono (f := φ) hcover
256     have hsq : (pointIdeal y * pointIdeal y).map φ ≤
257         (pointIdeal y).map φ * (pointIdeal y).map φ := by
258       rw [Ideal.map_le_iff_le_comap]
259       refine Ideal.mul_le.2 fun a ha b hb ↦ ?_
260       rw [Ideal.mem_comap, map_mul]
261       exact Ideal.mul_mem_mul (Ideal.mem_map_of_mem _ ha) (Ideal.mem_map_of_mem _ hb)
262     rw [Ideal.map_sup, Ideal.map_sup, h𝔮B, sup_bot_eq] at h
263     replace h := h.trans (sup_le_sup_left hsq _)
264     rw [← h𝔪B] at h
265     exact maximalIdeal_le_of_le_sup_sq (R := (Localization.AtPrime (pointIdeal y)) ⧸ 𝔮') h
266   have heq : maximalIdeal ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮') = Ideal.span (φ '' Set.range ℓ) := by
267     rw [le_antisymm hNak hJle, Ideal.map_span]
268   have hμ : (maximalIdeal ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮')).spanFinrank ≤ n - c := by
269     rw [heq]
270     refine (Submodule.spanFinrank_span_le_ncard_of_finite ((Set.finite_range ℓ).image _)).trans ?_
271     refine (Set.ncard_image_le (Set.finite_range ℓ)).trans ?_
272     rw [← Set.image_univ]
273     refine (Set.ncard_image_le Set.finite_univ).trans ?_
274     simp [hWcrank]
275   exact isDomain_of_spanFinrank_maximalIdeal_le _ ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮') rfl
276     ((by exact_mod_cast hμ : ((maximalIdeal ((Localization.AtPrime (pointIdeal y)) ⧸ 𝔮')).spanFinrank : WithBot ℕ∞) ≤
277       ((n - c : ℕ) : WithBot ℕ∞)).trans hdimB)
278 
279 end RegularQuotient
280 
281 section GenericRank
282 
283 variable {k : Type u} [Field k] {n : ℕ} {I : Ideal (MvPolynomial (Fin n) k)}
284   {L : Type*} [Field L] [Algebra k L] [Algebra (MvPolynomial (Fin n) k ⧸ I) L]
285   [IsScalarTower k (MvPolynomial (Fin n) k ⧸ I) L]
286 
287 /-- The image of `p` in `L` is `p` evaluated at the point `(x̄_i)_i ∈ L^n`. -/
288 theorem algebraMap_quotient_mk_eq_eval₂ (p : MvPolynomial (Fin n) k) :
289     algebraMap (MvPolynomial (Fin n) k ⧸ I) L (Ideal.Quotient.mk I p) =
290       MvPolynomial.eval₂ (algebraMap k L) (GenericPointKaehlerConormal.genericPoint I L) p := by
291   have hhom : MvPolynomial.aeval (GenericPointKaehlerConormal.genericPoint I L) =
292       (IsScalarTower.toAlgHom k (MvPolynomial (Fin n) k ⧸ I) L).comp
293         (Ideal.Quotient.mkₐ k I) := by
294     apply MvPolynomial.algHom_ext
295     intro i
296     simp [GenericPointKaehlerConormal.genericPoint]
297   have h := congrArg (fun φ ↦ φ p) hhom
298   simpa [MvPolynomial.aeval_def] using h.symm
299 
300 end GenericRank
301 
302 section Generization
303 
304 variable {k : Type u} [Field k] {n : ℕ}
305 
306 /-- **The Jacobian rank does not drop at the generic point of a prime `𝔯 ⊆ 𝔪_y`.** If
307 `f_1, …, f_c ∈ 𝔯` have independent differentials at `y ∈ V(𝔯)`, the tangent space at the
308 generic point of `𝔯` has dimension at most `n - c`: a `c × c` minor of the Jacobian is `1`
309 at `y`, hence not in `𝔯`. -/
310 theorem finrank_genericTangent_le {ι : Type*} [Fintype ι] (𝔯 : Ideal (MvPolynomial (Fin n) k))
311     [𝔯.IsPrime] (y : Fin n → k) (h𝔯 : 𝔯 ≤ pointIdeal y)
312     (f : ι → MvPolynomial (Fin n) k) (hf : ∀ i, f i ∈ 𝔯)
313     (hli : LinearIndependent k fun i ↦ differentialAt y (f i)) :
314     Module.finrank (FractionRing (MvPolynomial (Fin n) k ⧸ 𝔯))
315         (zariskiTangentSpace
316           (GenericPointKaehlerConormal.genericPoint 𝔯 (FractionRing (MvPolynomial (Fin n) k ⧸ 𝔯)))
317           (𝔯.map (MvPolynomial.map (algebraMap k (FractionRing (MvPolynomial (Fin n) k ⧸ 𝔯)))))) ≤
318       n - Fintype.card ι := by
319   classical
320   let L := FractionRing (MvPolynomial (Fin n) k ⧸ 𝔯)
321   let yb := GenericPointKaehlerConormal.genericPoint 𝔯 L
322   let ψ : MvPolynomial (Fin n) k →+* L :=
323     (algebraMap (MvPolynomial (Fin n) k ⧸ 𝔯) L).comp (Ideal.Quotient.mk 𝔯)
324   have hψ : ∀ p, ψ p = MvPolynomial.eval₂ (algebraMap k L) yb p :=
325     fun p ↦ algebraMap_quotient_mk_eq_eval₂ (I := 𝔯) (L := L) p
326   have hψC : ∀ c : k, ψ (C c) = algebraMap k L c := by
327     intro c; rw [hψ]; simp
328   -- the Jacobian at `y` and at the generic point
329   let A0 : Matrix ι (Fin n) k := Matrix.of fun i j ↦ differentialAt y (f i) j
330   let AL : Matrix ι (Fin n) L := Matrix.of fun i j ↦ ψ (pderiv j (f i))
331   have hA0surj : Function.Surjective A0.mulVecLin := by
332     rw [← LinearMap.range_eq_top]
333     apply Submodule.eq_top_of_finrank_eq
334     have h1 : Module.finrank k (LinearMap.range A0.mulVecLin) = A0.rank := rfl
335     rw [h1, Matrix.rank_eq_finrank_span_row]
336     have hrows : Set.range A0.row = Set.range fun i ↦ differentialAt y (f i) := rfl
337     rw [hrows, finrank_span_eq_card hli, Module.finrank_fintype_fun_eq_card]
338   choose G hG using fun i' : ι ↦ hA0surj (Pi.single i' 1)
339   let Mk : Matrix (Fin n) ι k := Matrix.of fun j i' ↦ G i' j
340   have hA0Mk : A0 * Mk = 1 := by
341     ext i i'
342     have := congrFun (hG i') i
343     simp only [Matrix.mulVecLin_apply, Matrix.mulVec, dotProduct] at this
344     simp only [Matrix.mul_apply, Mk, Matrix.of_apply, Matrix.one_apply]
345     rw [this, Pi.single_apply]
346   let N : Matrix ι ι (MvPolynomial (Fin n) k) :=
347     Matrix.of fun i i' ↦ ∑ j, pderiv j (f i) * C (Mk j i')
348   have hNy : (MvPolynomial.eval y).mapMatrix N = A0 * Mk := by
349     ext i i'
350     simp [N, A0, Matrix.mul_apply, differentialAt]
351   have hdetN : N.det ∉ 𝔯 := by
352     intro h
353     have h1 := h𝔯 h
354     rw [mem_pointIdeal, RingHom.map_det, hNy, hA0Mk, Matrix.det_one] at h1
355     exact one_ne_zero h1
356   have hNL : ψ.mapMatrix N = AL * Mk.map (algebraMap k L) := by
357     ext i i'
358     simp [N, AL, Matrix.mul_apply, hψC]
359   have hdetL : IsUnit (AL * Mk.map (algebraMap k L)).det := by
360     rw [← hNL, ← RingHom.map_det]
361     refine isUnit_iff_ne_zero.2 fun h ↦ hdetN ?_
362     have h' : algebraMap (MvPolynomial (Fin n) k ⧸ 𝔯) L (Ideal.Quotient.mk 𝔯 N.det) = 0 := h
363     rw [(IsFractionRing.injective _ L).eq_iff' (map_zero _),
364       Ideal.Quotient.eq_zero_iff_mem] at h'
365     exact h'
366   have hALsurj : Function.Surjective AL.mulVecLin := by
367     intro v
368     obtain ⟨u, hu⟩ := Matrix.mulVec_surjective_iff_isUnit.2
369       ((Matrix.isUnit_iff_isUnit_det _).2 hdetL) v
370     refine ⟨Matrix.mulVec (Mk.map (algebraMap k L)) u, ?_⟩
371     rw [Matrix.mulVecLin_apply, Matrix.mulVec_mulVec, hu]
372   -- tangent vectors are killed by the Jacobian
373   have hT : zariskiTangentSpace yb (𝔯.map (MvPolynomial.map (algebraMap k L))) ≤
374       LinearMap.ker AL.mulVecLin := by
375     intro w hw
376     rw [zariskiTangentSpace, Submodule.mem_dualCoannihilator] at hw
377     rw [LinearMap.mem_ker]
378     funext i
379     have hmem : MvPolynomial.map (algebraMap k L) (f i) ∈
380         𝔯.map (MvPolynomial.map (algebraMap k L)) := Ideal.mem_map_of_mem _ (hf i)
381     have h := hw (differentialCovector yb _) (Submodule.subset_span ⟨⟨_, hmem⟩, rfl⟩)
382     simp only [differentialCovector_apply, differentialAt, pderiv_map, eval_map] at h
383     simp only [Matrix.mulVecLin_apply, Matrix.mulVec, dotProduct, AL, Matrix.of_apply, hψ,
384       Pi.zero_apply]
385     exact h
386   have hrn := LinearMap.finrank_range_add_finrank_ker AL.mulVecLin
387   rw [LinearMap.range_eq_top.2 hALsurj, finrank_top, Module.finrank_fintype_fun_eq_card,
388     Module.finrank_fin_fun] at hrn
389   have hker : Module.finrank L (LinearMap.ker AL.mulVecLin) = n - Fintype.card ι := by
390     omega
391   exact (Submodule.finrank_mono hT).trans hker.le
392 
393 end Generization
394 
395 section LocalEquations
396 
397 variable {k : Type u} [Field k] [CharZero k] {n : ℕ}
398 
399 /-- **`𝔭 P' = (f_1, …, f_c) P'`.** Under the Jacobian hypothesis the equations `f_i`
400 generate `𝔭` near `y`: the kernel `𝔯` of `K[x] → P'/(f)` is a prime between `(f)` and `𝔭`
401 (`isDomain_localization_quotient`), of transcendence degree at most `n - c`
402 (`finrank_genericTangent_le`, Lemma 5.12(a)), hence equal to `𝔭` (`trdeg_quotient_toNat_lt`). -/
403 theorem map_le_map_span_of_jacobian (𝔓 : PrimeSpectrum (MvPolynomial (Fin n) k))
404     {y : Fin n → k} (hy : y ∈ MvPolynomial.zeroLocus k 𝔓.asIdeal)
405     {ι : Type*} [Fintype ι] (f : ι → MvPolynomial (Fin n) k) (hf : ∀ i, f i ∈ 𝔓.asIdeal)
406     (hli : LinearIndependent k fun i ↦ differentialAt y (f i))
407     (hc : Fintype.card ι +
408       (Algebra.trdeg k (FractionRing (MvPolynomial (Fin n) k ⧸ 𝔓.asIdeal))).toNat = n) :
409     𝔓.asIdeal.map (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y))) ≤
410       (Ideal.span (Set.range f)).map
411         (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y))) := by
412   classical
413   have h𝔓y : 𝔓.asIdeal ≤ pointIdeal y := fun g hg ↦ by
414     rw [mem_pointIdeal]
415     simpa using (MvPolynomial.mem_zeroLocus_iff.1 hy) g hg
416   have hfy : ∀ i, MvPolynomial.eval y (f i) = 0 := fun i ↦ mem_pointIdeal.1 (h𝔓y (hf i))
417   have hdom := isDomain_localization_quotient y f hfy hli
418   let φ : MvPolynomial (Fin n) k →+* Localization.AtPrime (pointIdeal y) ⧸
419       (Ideal.span (Set.range f)).map
420         (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y))) :=
421     (Ideal.Quotient.mk _).comp (algebraMap _ _)
422   let 𝔯 := RingHom.ker φ
423   have : 𝔯.IsPrime := RingHom.ker_isPrime φ
424   have hf𝔯 : ∀ i, f i ∈ 𝔯 := fun i ↦ by
425     rw [RingHom.mem_ker]
426     exact (Ideal.Quotient.eq_zero_iff_mem).2
427       (Ideal.mem_map_of_mem _ (Ideal.subset_span ⟨i, rfl⟩))
428   have h𝔯𝔓 : 𝔯 ≤ 𝔓.asIdeal := by
429     intro g hg
430     rw [RingHom.mem_ker] at hg
431     have hg' := (Ideal.Quotient.eq_zero_iff_mem).1 hg
432     obtain ⟨⟨a, s⟩, hs⟩ := (IsLocalization.mem_map_algebraMap_iff (pointIdeal y).primeCompl
433       (Localization.AtPrime (pointIdeal y))).1 hg'
434     rw [← map_mul] at hs
435     obtain ⟨t, ht⟩ := (IsLocalization.eq_iff_exists (pointIdeal y).primeCompl
436       (Localization.AtPrime (pointIdeal y))).1 hs
437     have hspan : Ideal.span (Set.range f) ≤ 𝔓.asIdeal := by
438       rw [Ideal.span_le]
439       rintro _ ⟨i, rfl⟩
440       exact hf i
441     have hmem : (t : MvPolynomial (Fin n) k) * (g * s) ∈ 𝔓.asIdeal := by
442       rw [ht]
443       exact Ideal.mul_mem_left _ _ (hspan a.2)
444     have ht𝔓 : (t : MvPolynomial (Fin n) k) ∉ 𝔓.asIdeal := fun h ↦ t.2 (h𝔓y h)
445     have hs𝔓 : (s : MvPolynomial (Fin n) k) ∉ 𝔓.asIdeal := fun h ↦ s.2 (h𝔓y h)
446     rcases 𝔓.isPrime.mem_or_mem hmem with h | h
447     · exact absurd h ht𝔓
448     · rcases 𝔓.isPrime.mem_or_mem h with h | h
449       · exact h
450       · exact absurd h hs𝔓
451   have h𝔓𝔯 : 𝔓.asIdeal ≤ 𝔯 := by
452     by_contra hne
453     have hlt : 𝔯 < 𝔓.asIdeal := lt_of_le_of_ne h𝔯𝔓 fun h ↦ hne h.ge
454     have h1 := trdeg_quotient_toNat_lt (K := k) hlt
455     have h2 := finrank_genericTangent_le 𝔯 y (h𝔯𝔓.trans h𝔓y) f hf𝔯 hli
456     let R0 : PrimeSpectrum (MvPolynomial (Fin n) k) := ⟨𝔯, inferInstance⟩
457     have h512 := generic_tangent_finrank_eq_component_kaehler_finrank
458       (F := FractionRing (MvPolynomial (Fin n) k ⧸ 𝔯))
459       (E := FractionRing (MvPolynomial (Fin n) k ⧸ 𝔯)) (I := 𝔯)
460     simp only [Algebra.algebraMap_self, RingHom.id_apply] at h512
461     have htr := (component_kaehler_finrank_eq_trdeg (k := k)
462       (AffineComponentCoordinateSplit.componentCoordinate R0)
463       (ExactDivisorialVisibleFrameExistence.componentCoordinate_adjoin_eq_top R0)).2
464     have e1 := trdeg_fractionRing (K := k) (MvPolynomial (Fin n) k ⧸ 𝔯)
465     have e2 := trdeg_fractionRing (K := k) (MvPolynomial (Fin n) k ⧸ 𝔓.asIdeal)
466     change Module.finrank (FractionRing (MvPolynomial (Fin n) k ⧸ 𝔯))
467       Ω[FractionRing (MvPolynomial (Fin n) k ⧸ 𝔯)⁄k] = _ at htr
468     rw [e1] at htr
469     rw [e2] at hc
470     rw [h512, htr] at h2
471     omega
472   rw [Ideal.map_le_iff_le_comap]
473   intro g hg
474   have := h𝔓𝔯 hg
475   rw [RingHom.mem_ker] at this
476   rw [Ideal.mem_comap]
477   exact (Ideal.Quotient.eq_zero_iff_mem (I := (Ideal.span (Set.range f)).map
478     (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y))))).1 this
479 
480 end LocalEquations
481 
482 section Criterion
483 
484 variable {k : Type u} [Field k] {n : ℕ}
485 
486 set_option maxHeartbeats 2000000 in
487 open TensorProduct in
488 /-- The local Jacobian criterion for the presentation `P' → R_𝔪`, `R = K[x]/𝔭`, once
489 `𝔭 P' ⊆ (f_1, …, f_c) P'` with `f_i ∈ 𝔭` and independent `df_i(y)`.  The ring `R` is
490 abstracted as `A` with a surjection `π : K[x] → A` of kernel `𝔭`. -/
491 theorem formallySmooth_localization_of_jacobian
492     {A : Type u} [CommRing A] [Algebra k A] (𝔭 : Ideal (MvPolynomial (Fin n) k)) [𝔭.IsPrime]
493     (π : MvPolynomial (Fin n) k →ₐ[k] A) (hπ : Function.Surjective π)
494     (hπker : ∀ p, π p = 0 ↔ p ∈ 𝔭) (y : Fin n → k) (e : A →ₐ[k] k)
495     (heval : ∀ p, e (π p) = MvPolynomial.aeval y p)
496     [(RingHom.ker e.toRingHom).IsPrime]
497     {ι : Type*} [Fintype ι] (f : ι → MvPolynomial (Fin n) k) (hf : ∀ i, f i ∈ 𝔭)
498     (hli : LinearIndependent k fun i ↦ differentialAt y (f i))
499     (hloc : 𝔭.map (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y))) ≤
500       (Ideal.span (Set.range f)).map
501         (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)))) :
502     Algebra.FormallySmooth k (Localization.AtPrime (RingHom.ker e.toRingHom)) := by
503   classical
504   have hMT : (pointIdeal y).primeCompl ≤ (RingHom.ker e.toRingHom).primeCompl.comap π.toRingHom := by
505     intro s hs h
506     apply hs
507     have h' : e (π s) = 0 := h
508     rw [heval] at h'
509     exact h'
510   let θ : (Localization.AtPrime (pointIdeal y)) →+* (Localization.AtPrime (RingHom.ker e.toRingHom)) := IsLocalization.map (Localization.AtPrime (RingHom.ker e.toRingHom)) π.toRingHom hMT
511   let : Algebra (Localization.AtPrime (pointIdeal y)) (Localization.AtPrime (RingHom.ker e.toRingHom)) := θ.toAlgebra
512   have hθ : ∀ p, θ (algebraMap _ (Localization.AtPrime (pointIdeal y)) p) = algebraMap A (Localization.AtPrime (RingHom.ker e.toRingHom)) (π p) := fun p ↦ IsLocalization.map_eq _ _
513   have : IsScalarTower k (Localization.AtPrime (pointIdeal y)) (Localization.AtPrime (RingHom.ker e.toRingHom)) :=
514     IsScalarTower.of_algebraMap_eq fun c ↦ by
515       change _ = θ (algebraMap k (Localization.AtPrime (pointIdeal y)) c)
516       rw [IsScalarTower.algebraMap_apply k (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)), hθ,
517         IsScalarTower.algebraMap_apply k A (Localization.AtPrime (RingHom.ker e.toRingHom))]
518       simp
519   -- smoothness of `(Localization.AtPrime (pointIdeal y))` and its differentials
520   have : Algebra.FormallyEtale (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)) :=
521     .of_isLocalization (pointIdeal y).primeCompl
522   have : Algebra.FormallySmooth k (Localization.AtPrime (pointIdeal y)) := .comp _ (MvPolynomial (Fin n) k) _
523   have : Module.Free (Localization.AtPrime (pointIdeal y)) Ω[(Localization.AtPrime (pointIdeal y))⁄k] :=
524     .of_equiv (KaehlerDifferential.tensorKaehlerEquivOfFormallyEtale k (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)))
525   have : Module.Finite (Localization.AtPrime (pointIdeal y)) Ω[(Localization.AtPrime (pointIdeal y))⁄k] :=
526     .of_surjective (KaehlerDifferential.tensorKaehlerEquivOfFormallyEtale k
527       (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y))).toLinearMap (LinearEquiv.surjective _)
528   -- surjectivity and kernel
529   have h₁ : Function.Surjective (algebraMap (Localization.AtPrime (pointIdeal y)) (Localization.AtPrime (RingHom.ker e.toRingHom))) := by
530     intro z
531     obtain ⟨⟨a, t⟩, rfl⟩ := IsLocalization.mk'_surjective (RingHom.ker e.toRingHom).primeCompl z
532     obtain ⟨p, rfl⟩ := hπ a
533     obtain ⟨q, hq⟩ := hπ (t : A)
534     have hq' : q ∈ (pointIdeal y).primeCompl := by
535       intro h
536       apply t.2
537       rw [← hq]
538       change e (π q) = 0
539       rw [heval]
540       exact h
541     refine ⟨IsLocalization.mk' (Localization.AtPrime (pointIdeal y)) p ⟨q, hq'⟩, ?_⟩
542     change θ _ = _
543     rw [IsLocalization.map_mk']
544     congr 1
545     exact Subtype.ext hq
546   have h₂ : (RingHom.ker (algebraMap (Localization.AtPrime (pointIdeal y)) (Localization.AtPrime (RingHom.ker e.toRingHom)))).FG := IsNoetherian.noetherian _
547   let 𝔮' : Ideal (Localization.AtPrime (pointIdeal y)) := (Ideal.span (Set.range f)).map (algebraMap (MvPolynomial (Fin n) k) _)
548   have hker : RingHom.ker (algebraMap (Localization.AtPrime (pointIdeal y)) (Localization.AtPrime (RingHom.ker e.toRingHom))) ≤ 𝔮' := by
549     intro z hz
550     obtain ⟨⟨p, q⟩, rfl⟩ := IsLocalization.mk'_surjective (pointIdeal y).primeCompl z
551     rw [RingHom.mem_ker] at hz
552     change θ _ = 0 at hz
553     rw [IsLocalization.map_mk', IsLocalization.mk'_eq_zero_iff] at hz
554     obtain ⟨⟨m, hm⟩, hm0⟩ := hz
555     obtain ⟨r, rfl⟩ := hπ m
556     have hm0' : r * p ∈ 𝔭 := (hπker _).1 (by rw [map_mul]; exact hm0)
557     have hr : r ∉ 𝔭 := fun h ↦ hm (by
558       change (π r) ∈ (RingHom.ker e.toRingHom)
559       rw [(hπker r).2 h]
560       exact (RingHom.ker e.toRingHom).zero_mem)
561     have hp : p ∈ 𝔭 := (Ideal.IsPrime.mem_or_mem inferInstance hm0').resolve_left hr
562     have : algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)) p ∈ 𝔮' := hloc (Ideal.mem_map_of_mem _ hp)
563     change IsLocalization.mk' _ p q ∈ 𝔮'
564     rw [IsLocalization.mk'_eq_mul_mk'_one]
565     exact Ideal.mul_mem_right _ _ this
566   have hmemN : ∀ i, algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)) (f i) ∈
567       RingHom.ker (algebraMap (Localization.AtPrime (pointIdeal y)) (Localization.AtPrime (RingHom.ker e.toRingHom))) := by
568     intro i
569     rw [RingHom.mem_ker]
570     change θ _ = 0
571     rw [hθ, (hπker _).2 (hf i), map_zero]
572   have h𝔮N : 𝔮' ≤ RingHom.ker (algebraMap (Localization.AtPrime (pointIdeal y)) (Localization.AtPrime (RingHom.ker e.toRingHom))) := by
573     rw [Ideal.map_le_iff_le_comap, Ideal.span_le]
574     rintro _ ⟨i, rfl⟩
575     exact hmemN i
576   rw [Algebra.FormallySmooth.iff_injective_cotangentComplexBaseChange_residueField (Localization.AtPrime (pointIdeal y)) h₁ h₂]
577   -- the point `y` in the residue field
578   let : Algebra (MvPolynomial (Fin n) k) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) :=
579     ((algebraMap (Localization.AtPrime (pointIdeal y)) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))).comp (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)))).toAlgebra
580   have : IsScalarTower (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) := IsScalarTower.of_algebraMap_eq fun _ ↦ rfl
581   have : IsScalarTower k (MvPolynomial (Fin n) k) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) := IsScalarTower.of_algebraMap_eq fun c ↦ by
582     change _ = algebraMap (Localization.AtPrime (pointIdeal y)) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) (algebraMap _ (Localization.AtPrime (pointIdeal y)) (C c))
583     rw [← MvPolynomial.algebraMap_eq,
584       ← IsScalarTower.algebraMap_apply k (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)),
585       ← IsScalarTower.algebraMap_apply k (Localization.AtPrime (pointIdeal y))]
586   have hRFy : ∀ p : MvPolynomial (Fin n) k, algebraMap (MvPolynomial (Fin n) k) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) p =
587       MvPolynomial.aeval (algebraMap k (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) ∘ y) p := by
588     intro p
589     rw [MvPolynomial.aeval_algebraMap_apply]
590     change IsLocalRing.residue (Localization.AtPrime (RingHom.ker e.toRingHom)) (θ (algebraMap _ (Localization.AtPrime (pointIdeal y)) p)) =
591       IsLocalRing.residue (Localization.AtPrime (RingHom.ker e.toRingHom)) (algebraMap k (Localization.AtPrime (RingHom.ker e.toRingHom)) (aeval y p))
592     rw [hθ, ← sub_eq_zero, ← map_sub, IsLocalRing.residue_eq_zero_iff,
593       IsScalarTower.algebraMap_apply k A (Localization.AtPrime (RingHom.ker e.toRingHom)), ← map_sub,
594       ← Localization.AtPrime.map_eq_maximalIdeal]
595     apply Ideal.mem_map_of_mem
596     change e _ = 0
597     rw [map_sub, heval, AlgHom.commutes]
598     simp
599   have hRFk : ∀ s : (pointIdeal y).primeCompl,
600       algebraMap (MvPolynomial (Fin n) k) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) s ≠ 0 := by
601     intro s h
602     rw [hRFy, MvPolynomial.aeval_algebraMap_apply] at h
603     refine s.2 (mem_pointIdeal.2 ?_)
604     rw [← MvPolynomial.coe_aeval_eq_eval]
605     exact (FaithfulSMul.algebraMap_injective k (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))) (h.trans (map_zero _).symm)
606   have hunitP : ∀ s : (pointIdeal y).primeCompl,
607       IsUnit (algebraMap (MvPolynomial (Fin n) k) (Module.End (MvPolynomial (Fin n) k) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))) s) := by
608     intro s
609     rw [Module.End.isUnit_iff]
610     have hs := hRFk s
611     have hfun : ⇑(algebraMap (MvPolynomial (Fin n) k) (Module.End (MvPolynomial (Fin n) k) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))) s) =
612         fun x ↦ algebraMap (MvPolynomial (Fin n) k) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) s * x :=
613       funext fun x ↦ Algebra.smul_def (s : MvPolynomial (Fin n) k) x
614     rw [hfun]
615     exact ⟨mul_right_injective₀ hs, fun x ↦ ⟨(algebraMap _ (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) (s : MvPolynomial (Fin n) k))⁻¹ * x,
616       by simp only; rw [← mul_assoc, mul_inv_cancel₀ hs, one_mul]⟩⟩
617   -- the differentials at `y` as functionals on `κ ⊗ Ω_{(Localization.AtPrime (pointIdeal y))}`
618   let Θ : Fin n → ((IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) ⊗[(Localization.AtPrime (pointIdeal y))]
619       Ω[(Localization.AtPrime (pointIdeal y))⁄k] →ₗ[(IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))] (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))) := fun j ↦
620     LinearMap.liftBaseChange (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))
621       (LinearMap.extendScalarsOfIsLocalization (pointIdeal y).primeCompl
622         (Localization.AtPrime (pointIdeal y))
623         (IsLocalizedModule.lift (pointIdeal y).primeCompl
624           (KaehlerDifferential.map k k (MvPolynomial (Fin n) k)
625             (Localization.AtPrime (pointIdeal y)))
626           (mkDerivation k (Pi.single j (1 : (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))))) :
627             Derivation k (MvPolynomial (Fin n) k) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))).liftKaehlerDifferential hunitP))
628   have hΘ : ∀ j p, Θ j ((1 : (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))) ⊗ₜ KaehlerDifferential.D k _
629       (algebraMap (MvPolynomial (Fin n) k) (Localization.AtPrime (pointIdeal y)) p)) =
630       algebraMap k (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) (differentialAt y p j) := by
631     intro j p
632     simp only [Θ, LinearMap.liftBaseChange_tmul, one_smul,
633       LinearMap.extendScalarsOfIsLocalization_apply']
634     rw [← KaehlerDifferential.map_D k k, IsLocalizedModule.lift_apply,
635       Derivation.liftKaehlerDifferential_comp_D,
636       GenericPointKaehlerConormal.mkDerivation_eq_sum_pderiv _ _ hRFy]
637     rw [Finset.sum_eq_single j (fun i _ hij ↦ by rw [Pi.single_eq_of_ne hij, mul_zero])
638       (by simp), Pi.single_eq_same, mul_one, MvPolynomial.aeval_algebraMap_apply]
639     rfl
640   -- the generators `1 ⊗ f_i` span `κ ⊗ ker`
641   let N := RingHom.ker (algebraMap (Localization.AtPrime (pointIdeal y))
642     (Localization.AtPrime (RingHom.ker e.toRingHom)))
643   let u : ι → (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) ⊗[(Localization.AtPrime (pointIdeal y))] N :=
644     fun i ↦ (1 : (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))) ⊗ₜ ⟨_, hmemN i⟩
645   have key : ∀ x (hx : x ∈ 𝔮'), ∀ a : (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))),
646       a ⊗ₜ (⟨x, h𝔮N hx⟩ : N) ∈ Submodule.span (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) (Set.range u) := by
647     intro x hx
648     have hx' : x ∈ Ideal.span (algebraMap (MvPolynomial (Fin n) k) _ '' Set.range f) := by
649       have h' : x ∈ Ideal.map (algebraMap (MvPolynomial (Fin n) k)
650           (Localization.AtPrime (pointIdeal y))) (Ideal.span (Set.range f)) := hx
651       rwa [Ideal.map_span] at h'
652     induction hx' using Submodule.span_induction with
653     | mem x hxs =>
654       obtain ⟨_, ⟨i, rfl⟩, rfl⟩ := hxs
655       intro a
656       have : a ⊗ₜ (⟨_, h𝔮N hx⟩ : N) = a • u i := by
657         simp only [u, TensorProduct.smul_tmul', smul_eq_mul, mul_one]
658       rw [this]
659       exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨i, rfl⟩)
660     | zero =>
661       intro a
662       have : (⟨0, h𝔮N hx⟩ : N) = 0 := rfl
663       rw [this, TensorProduct.tmul_zero]
664       exact Submodule.zero_mem _
665     | add x z hx₁ hz₁ ihx ihz =>
666       intro a
667       have hx2 : x ∈ 𝔮' := by
668         change x ∈ Ideal.map _ (Ideal.span (Set.range f)); rw [Ideal.map_span]; exact hx₁
669       have hz2 : z ∈ 𝔮' := by
670         change z ∈ Ideal.map _ (Ideal.span (Set.range f)); rw [Ideal.map_span]; exact hz₁
671       have : (⟨x + z, h𝔮N hx⟩ : N) = ⟨x, h𝔮N hx2⟩ + ⟨z, h𝔮N hz2⟩ := rfl
672       rw [this, TensorProduct.tmul_add]
673       exact Submodule.add_mem _ (ihx hx2 a) (ihz hz2 a)
674     | smul c x hx₁ ihx =>
675       intro a
676       have hx2 : x ∈ 𝔮' := by
677         change x ∈ Ideal.map _ (Ideal.span (Set.range f)); rw [Ideal.map_span]; exact hx₁
678       have : (⟨c • x, h𝔮N hx⟩ : N) = c • ⟨x, h𝔮N hx2⟩ := rfl
679       rw [this, ← TensorProduct.smul_tmul]
680       exact ihx hx2 (c • a)
681   have hspan : ∀ t : (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) ⊗[(Localization.AtPrime (pointIdeal y))] N,
682       t ∈ Submodule.span (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) (Set.range u) := by
683     intro t
684     induction t using TensorProduct.inductionOn with
685     | tmul a z => exact key z.1 (hker z.2) a
686     | add t₁ t₂ h₁ h₂ => exact Submodule.add_mem _ h₁ h₂
687   have hliRF : LinearIndependent (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) fun i j ↦ algebraMap k (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) (differentialAt y (f i) j) :=
688     (linearIndependent_algebraMap_comp_iff (R := k) (S := (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))) (ι' := Fin n)).2 hli
689   rw [← LinearMap.ker_eq_bot, Submodule.eq_bot_iff]
690   intro t ht
691   obtain ⟨a, rfl⟩ := (Submodule.mem_span_range_iff_exists_fun (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))).1 (hspan t)
692   rw [LinearMap.mem_ker, map_sum] at ht
693   have hχ : ∀ i, KaehlerDifferential.cotangentComplexBaseChange k (Localization.AtPrime (RingHom.ker e.toRingHom))
694       (Localization.AtPrime (pointIdeal y)) (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom)))
695       (u i) = (1 : IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) ⊗ₜ
696         KaehlerDifferential.D k _ (algebraMap (MvPolynomial (Fin n) k)
697           (Localization.AtPrime (pointIdeal y)) (f i)) := by
698     intro i
699     rw [KaehlerDifferential.cotangentComplexBaseChange_tmul, one_smul]
700     rfl
701   have hcoef : ∑ i, a i • (fun j ↦ algebraMap k (IsLocalRing.ResidueField (Localization.AtPrime (RingHom.ker e.toRingHom))) (differentialAt y (f i) j)) = 0 := by
702     funext j
703     have := congrArg (Θ j) ht
704     simp only [map_sum, map_smul, map_zero, hχ, hΘ] at this
705     simp only [Finset.sum_apply, Pi.smul_apply, Pi.zero_apply]
706     exact this
707   have ha := (Fintype.linearIndependent_iff.1 hliRF) a hcoef
708   simp only [ha, zero_smul, Finset.sum_const_zero]
709 
710 
711 open Stafford38.Geometry.SmoothAffineConormal in
712 /-- **Jacobian smooth points are Mathlib smooth points.** If `f_1, …, f_c ∈ 𝔭` have
713 independent differentials at `y ∈ V(𝔭)` and `c + trdeg_K Frac(K[x]/𝔭) = n`, then `y` is a
714 smooth point of `K[x]/𝔭`. -/
715 theorem smoothAffinePoint_of_jacobian [IsAlgClosed k] [CharZero k]
716     (𝔓 : PrimeSpectrum (MvPolynomial (Fin n) k))
717     {y : Fin n → k} (hy : y ∈ MvPolynomial.zeroLocus k 𝔓.asIdeal)
718     {ι : Type*} [Fintype ι] (f : ι → MvPolynomial (Fin n) k) (hf : ∀ i, f i ∈ 𝔓.asIdeal)
719     (hli : LinearIndependent k fun i ↦ differentialAt y (f i))
720     (hc : Fintype.card ι +
721       (Algebra.trdeg k (FractionRing (MvPolynomial (Fin n) k ⧸ 𝔓.asIdeal))).toNat = n) :
722     SmoothAffinePoint 𝔓.asIdeal y := by
723   have hloc := map_le_map_span_of_jacobian 𝔓 hy f hf hli hc
724   have hyI : ∀ p ∈ 𝔓.asIdeal, MvPolynomial.aeval y p = 0 := fun p hp ↦
725     (MvPolynomial.mem_zeroLocus_iff.1 hy) p hp
726   let e : (MvPolynomial (Fin n) k ⧸ 𝔓.asIdeal) →ₐ[k] k := Ideal.Quotient.liftₐ _ (aeval y) hyI
727   have heval : ∀ p, e (Ideal.Quotient.mk 𝔓.asIdeal p) = MvPolynomial.aeval y p := fun p ↦ by
728     simp [e]
729   refine ⟨e, heval, ?_⟩
730   have : (RingHom.ker e.toRingHom).IsPrime := RingHom.ker_isPrime e
731   exact formallySmooth_localization_of_jacobian 𝔓.asIdeal (Ideal.Quotient.mkₐ k 𝔓.asIdeal)
732     Ideal.Quotient.mk_surjective (fun p ↦ Ideal.Quotient.eq_zero_iff_mem) y e heval f hf hli hloc
733 
734 end Criterion
735 
736 end
737 
738 #print axioms mem_pointIdeal
739 #print axioms linearPart_mem
740 #print axioms linearPart_single
741 #print axioms differentialAt_add
742 #print axioms taylor_mem_pointIdeal_sq
743 #print axioms withBot_natCast_le_of_add_le
744 #print axioms maximalIdeal_le_of_le_sup_sq
745 #print axioms isDomain_localization_quotient
746 #print axioms algebraMap_quotient_mk_eq_eval₂
747 #print axioms finrank_genericTangent_le
748 #print axioms map_le_map_span_of_jacobian
749 #print axioms formallySmooth_localization_of_jacobian
750 #print axioms smoothAffinePoint_of_jacobian
751 
752 end Stafford38.Paper.Section5
753