AlgebraicAnalysis/Ore/RightHilbertBasis.lean

AlgebraicAnalysis library · bbbbf3fc358ca8100b158cec4cf47f336ab70163

1 module
2 public import AlgebraicAnalysis.Ore.RightQuotient
3 public import Mathlib.RingTheory.Noetherian.Filter
4 public import Mathlib.RingTheory.Noetherian.Basic
5 
6 @[expose] public section
7 
8 /-!
9 # The derivation-Ore right Hilbert-basis theorem
10 
11 This file is a right-sided version of the leading-coefficient proof for a
12 differential Ore extension.  Coefficients are allowed to be noncommutative:
13 right ideals of the coefficient ring are represented as submodules for the
14 opposite scalar ring.
15 -/
16 
17 namespace AlgebraicAnalysis.OreDerivationRightHilbertBasis
18 
19 open Polynomial
20 open AlgebraicAnalysis
21 open AlgebraicAnalysis.OreDivision
22 open AlgebraicAnalysis.OreAssociativity
23 open AlgebraicAnalysis.OreRightQuotient
24 
25 noncomputable section
26 
27 universe u
28 
29 variable {B : Type u} [Ring B]
30 
31 /-- The right Hilbert-basis assertion for one derivation-Ore stage. -/
32 def DerivationOreRightHilbertBasis : Prop :=
33   ∀ {B : Type u} [Ring B], IsNoetherianRing Bᵐᵒᵖ →
34     ∀ D : OreDivisionDerivation B,
35       IsNoetherianRing (NormalOre D)ᵐᵒᵖ
36 
37 @[simp] theorem rightScalar_smul_def (b : Bᵐᵒᵖ) (c : B) :
38     b • c = c * b.unop := by
39   rw [MulOpposite.smul_eq_mul_unop]
40 
41 private theorem rightScalar_top_span :
42     Submodule.span Bᵐᵒᵖ ({1} : Set B) = ⊤ := by
43   apply top_unique
44   intro c hc
45   have h1 : (1 : B) ∈ Submodule.span Bᵐᵒᵖ ({1} : Set B) :=
46     Submodule.subset_span (by simp)
47   have hc' := Submodule.smul_mem
48     (Submodule.span Bᵐᵒᵖ ({1} : Set B)) (MulOpposite.op c) h1
49   simpa [rightScalar_smul_def] using hc'
50 
51 private theorem rightScalar_module_finite : Module.Finite Bᵐᵒᵖ B := by
52   refine ⟨?_⟩
53   refine ⟨({1} : Finset B), ?_⟩
54   change Submodule.span Bᵐᵒᵖ (({1} : Finset B) : Set B) = ⊤
55   simpa only [Finset.coe_singleton] using
56     (rightScalar_top_span (B := B))
57 
58 private theorem rightScalar_isNoetherian
59     [IsNoetherianRing Bᵐᵒᵖ] : IsNoetherian Bᵐᵒᵖ B := by
60   letI : Module.Finite Bᵐᵒᵖ B := rightScalar_module_finite
61   exact isNoetherian_of_isNoetherianRing_of_finite Bᵐᵒᵖ B
62 
63 /-- Additive equivalence between coefficient-left polynomials and normal forms. -/
64 def normalPolyEquiv (D : OreDivisionDerivation B) :
65     Polynomial B ≃+ NormalOre D :=
66   { normalFormAddEquiv D with }
67 
68 lemma rightMul_coeff_C_of_degree_le
69     (D : OreDivisionDerivation B) (p : Polynomial B) (b : B) (n : ℕ)
70     (hp : p.degree ≤ (n : WithBot ℕ)) :
71     (rightMul D p (Polynomial.C b)).coeff n = p.coeff n * b := by
72   by_cases hp0 : p = 0
73   · subst p
74     simp [OreDivision.rightMul, OreDivision.rightMulMonomial,
75       OreDivision.rightTerm]
76   have hpnat : p.natDegree ≤ n :=
77     Polynomial.natDegree_le_of_degree_le hp
78   by_cases heq : p.natDegree = n
79   · rw [show Polynomial.C b = Polynomial.monomial 0 b by simp,
80       rightMul_monomial]
81     have htop := rightMulMonomial_coeff_top D p hp0 b 0
82     rw [Nat.add_zero] at htop
83     simpa [Polynomial.leadingCoeff, heq] using htop
84   · have hlt : p.natDegree < n := lt_of_le_of_ne hpnat heq
85     have hprod : (rightMul D p (Polynomial.C b)).degree <
86         (n : WithBot ℕ) := by
87       have hle := rightMul_degree_le D p (Polynomial.C b)
88       have hnatC : (Polynomial.C b).natDegree = 0 := by simp
89       rw [hnatC] at hle
90       have hle' : (rightMul D p (Polynomial.C b)).degree ≤
91           (p.natDegree : WithBot ℕ) := by simpa using hle
92       exact lt_of_le_of_lt hle' (WithBot.coe_lt_coe.2 hlt)
93     have hzprod := Polynomial.coeff_eq_zero_of_degree_lt hprod
94     have hz : p.coeff n = 0 := by
95       apply Polynomial.coeff_eq_zero_of_degree_lt
96       rw [Polynomial.degree_eq_natDegree hp0]
97       exact WithBot.coe_lt_coe.2 hlt
98     simp [hzprod, hz]
99 
100 /-- The degree-at-most-`n` submodule of normal forms. -/
101 def normalDegreeLE (D : OreDivisionDerivation B) (n : ℕ) :
102     Submodule Bᵐᵒᵖ (NormalOre D) :=
103   { carrier := {z | ((normalPolyEquiv D).symm z).degree ≤ (n : WithBot ℕ)}
104     zero_mem' := by
105       change ((normalPolyEquiv D).symm (0 : NormalOre D)).degree ≤ _
106       rw [(normalPolyEquiv D).symm.map_zero]
107       simp
108     add_mem' := by
109       intro x y hx hy
110       change ((normalPolyEquiv D).symm (x + y)).degree ≤ _
111       rw [(normalPolyEquiv D).symm.map_add]
112       exact le_trans (Polynomial.degree_add_le _ _) (max_le hx hy)
113     smul_mem' := by
114       intro b z hz
115       obtain ⟨p, rfl⟩ := normalForm_surjective D z
116       change ((normalPolyEquiv D).symm (b • normalForm D p)).degree ≤ _
117       change ((normalPolyEquiv D).symm ((normalPolyEquiv D) p)).degree ≤ _ at hz
118       rw [(normalPolyEquiv D).symm_apply_apply] at hz
119       have hpdeg : p.degree ≤ (n : WithBot ℕ) := hz
120       have hpnat : p.natDegree ≤ n :=
121         Polynomial.natDegree_le_of_degree_le hpdeg
122       have hmul : b • normalForm D p =
123           normalForm D (rightMul D p (Polynomial.C b.unop)) := by
124         rw [normalOre_op_smul_def, ← normalForm_C, ← normalForm_mul]
125       rw [hmul]
126       change ((normalPolyEquiv D).symm
127         ((normalPolyEquiv D) (rightMul D p (Polynomial.C b.unop)))).degree ≤ _
128       rw [(normalPolyEquiv D).symm_apply_apply]
129       exact (rightMul_degree_le D p (Polynomial.C b.unop)).trans
130         (by
131           simp only [Polynomial.natDegree_C, Nat.cast_zero, add_zero]
132           exact_mod_cast hpnat) }
133 
134 /-- The `n`th coefficient functional on the degree window. -/
135 def normalCoeffNth (D : OreDivisionDerivation B) (n : ℕ) :
136     normalDegreeLE D n →ₗ[Bᵐᵒᵖ] B where
137   toFun z := ((normalPolyEquiv D).symm z).coeff n
138   map_add' x y := by
139     change ((normalPolyEquiv D).symm (x + y)).coeff n = _
140     rw [(normalPolyEquiv D).symm.map_add, Polynomial.coeff_add]
141   map_smul' b z := by
142     let p := (normalPolyEquiv D).symm z.1
143     have hp : p.degree ≤ (n : WithBot ℕ) := by
144       change ((normalPolyEquiv D).symm z.1).degree ≤ _
145       exact z.2
146     have hz : normalForm D p = z.1 := by
147       change (normalPolyEquiv D) p = z.1
148       exact (normalPolyEquiv D).apply_symm_apply z.1
149     change ((normalPolyEquiv D).symm (b • z.1)).coeff n =
150       b • ((normalPolyEquiv D).symm z.1).coeff n
151     rw [← hz]
152     rw [normalOre_op_smul_def, ← normalForm_C, ← normalForm_mul]
153     change ((normalPolyEquiv D).symm
154         ((normalPolyEquiv D) (rightMul D p (Polynomial.C b.unop)))).coeff n =
155       b • ((normalPolyEquiv D).symm ((normalPolyEquiv D) p)).coeff n
156     rw [(normalPolyEquiv D).symm_apply_apply,
157       (normalPolyEquiv D).symm_apply_apply]
158     rw [rightMul_coeff_C_of_degree_le D p b.unop n hp]
159     rfl
160 
161 /-- The degree window cut out by a right ideal. -/
162 def rightIdealDegreeLE (D : OreDivisionDerivation B)
163     (I : Submodule (NormalOre D)ᵐᵒᵖ (NormalOre D)) (n : ℕ) :
164     Submodule Bᵐᵒᵖ (NormalOre D) :=
165   normalDegreeLE D n ⊓ rightIdealAsCoeffSubmodule D I
166 
167 /-- The leading-coefficient submodule at a fixed degree. -/
168 def leadingCoeffNth (D : OreDivisionDerivation B)
169     (I : Submodule (NormalOre D)ᵐᵒᵖ (NormalOre D)) (n : ℕ) :
170     Submodule Bᵐᵒᵖ B :=
171   let J := rightIdealDegreeLE D I n
172   let incl : J →ₗ[Bᵐᵒᵖ] normalDegreeLE D n :=
173     { toFun := fun z => ⟨z.1, z.2.1⟩
174       map_add' := by intro x y; rfl
175       map_smul' := by intro b x; rfl }
176   let f : J →ₗ[Bᵐᵒᵖ] B := (normalCoeffNth D n).comp incl
177   Submodule.map f (⊤ : Submodule Bᵐᵒᵖ J)
178 
179 lemma mem_leadingCoeffNth (D : OreDivisionDerivation B)
180     (I : Submodule (NormalOre D)ᵐᵒᵖ (NormalOre D)) (n : ℕ) (c : B) :
181     c ∈ leadingCoeffNth D I n ↔
182       ∃ p : Polynomial B, normalForm D p ∈ I ∧
183         p.degree ≤ (n : WithBot ℕ) ∧ p.coeff n = c := by
184   constructor
185   · intro hc
186     change c ∈ Submodule.map _ (⊤ : Submodule Bᵐᵒᵖ (rightIdealDegreeLE D I n)) at hc
187     rw [Submodule.mem_map] at hc
188     rcases hc with ⟨z, hz, rfl⟩
189     let p := (normalPolyEquiv D).symm z.1
190     refine ⟨p, ?_, ?_, ?_⟩
191     · change normalForm D p ∈ I
192       have hpz : normalForm D p = z.1 := by
193         change (normalPolyEquiv D) p = z.1
194         exact (normalPolyEquiv D).apply_symm_apply z.1
195       rw [hpz]
196       simpa [rightIdealAsCoeffSubmodule] using z.2.2
197     · change p.degree ≤ (n : WithBot ℕ)
198       exact z.2.1
199     · change ((normalPolyEquiv D).symm z.1).coeff n = _
200       rfl
201   · rintro ⟨p, hpI, hpdeg, hpc⟩
202     let z : rightIdealDegreeLE D I n :=
203       ⟨normalForm D p, (by
204         change ((normalPolyEquiv D).symm ((normalPolyEquiv D) p)).degree ≤ _
205         rw [(normalPolyEquiv D).symm_apply_apply]
206         exact hpdeg), hpI⟩
207     refine ⟨z, Submodule.mem_top, ?_⟩
208     dsimp [z, normalCoeffNth]
209     have hinv : (normalPolyEquiv D).symm (normalForm D p) = p := by
210       change (normalPolyEquiv D).symm ((normalPolyEquiv D) p) = p
211       exact (normalPolyEquiv D).symm_apply_apply p
212     rw [hinv]
213     exact hpc
214 
215 lemma rightMul_Xpow_coeff_of_degree_le
216     [Nontrivial B]
217     (D : OreDivisionDerivation B) (p : Polynomial B) (n j : ℕ)
218     (hp : p.degree ≤ (n : WithBot ℕ)) :
219     (rightMul D p (Polynomial.X ^ j)).coeff (n + j) = p.coeff n := by
220   by_cases hp0 : p = 0
221   · subst p
222     simp [OreDivision.rightMul, OreDivision.rightMulMonomial,
223       OreDivision.rightTerm, Polynomial.sum_def]
224   have hpnat : p.natDegree ≤ n :=
225     Polynomial.natDegree_le_of_degree_le hp
226   by_cases heq : p.natDegree = n
227   · rw [Polynomial.X_pow_eq_monomial, rightMul_monomial]
228     have htop := rightMulMonomial_coeff_top D p hp0 1 j
229     simpa [Polynomial.leadingCoeff, heq] using htop
230   · have hlt : p.natDegree < n := lt_of_le_of_ne hpnat heq
231     have hprod : (rightMul D p (Polynomial.X ^ j)).degree <
232         ((n + j : ℕ) : WithBot ℕ) := by
233       have hle := rightMul_degree_le D p (Polynomial.X ^ j)
234       have hnatX : (Polynomial.X ^ j : Polynomial B).natDegree = j := by
235         simp
236       rw [hnatX] at hle
237       have hlt' : p.natDegree + j < n + j := Nat.add_lt_add_right hlt j
238       exact lt_of_le_of_lt hle (WithBot.coe_lt_coe.2 hlt')
239     have hzprod := Polynomial.coeff_eq_zero_of_degree_lt hprod
240     have hz : p.coeff n = 0 := by
241       apply Polynomial.coeff_eq_zero_of_degree_lt
242       rw [Polynomial.degree_eq_natDegree hp0]
243       exact WithBot.coe_lt_coe.2 hlt
244     simp [hzprod, hz]
245 
246 lemma leadingCoeffNth_mono [Nontrivial B] (D : OreDivisionDerivation B)
247     (I : Submodule (NormalOre D)ᵐᵒᵖ (NormalOre D))
248     {m n : ℕ} (hmn : m ≤ n) :
249     leadingCoeffNth D I m ≤ leadingCoeffNth D I n := by
250   intro c hc
251   rw [mem_leadingCoeffNth] at hc ⊢
252   rcases hc with ⟨p, hpI, hpdeg, hpc⟩
253   refine ⟨rightMul D p (Polynomial.X ^ (n - m)), ?_, ?_, ?_⟩
254   · rw [normalForm_mul]
255     have hmem := I.smul_mem
256       (MulOpposite.op (normalForm D (Polynomial.X ^ (n - m)))) hpI
257     simpa [op_smul_eq_mul] using hmem
258   · have hpnat : p.natDegree ≤ m :=
259       Polynomial.natDegree_le_of_degree_le hpdeg
260     have hdeg := rightMul_degree_le D p (Polynomial.X ^ (n - m))
261     have hnat : (Polynomial.X ^ (n - m) : Polynomial B).natDegree = n - m :=
262       Polynomial.natDegree_X_pow _
263     rw [hnat] at hdeg
264     have hadd : p.natDegree + (n - m) ≤ n := by
265       exact (Nat.add_le_add_right hpnat (n - m)).trans_eq
266         (Nat.add_sub_of_le hmn)
267     exact hdeg.trans (by exact_mod_cast hadd)
268   · have hc' := rightMul_Xpow_coeff_of_degree_le D p m (n - m) hpdeg
269     rw [Nat.add_sub_of_le hmn] at hc'
270     exact hc'.trans hpc
271 
272 /-- The monotone chain of leading-coefficient submodules. -/
273 def leadingCoeffChain [Nontrivial B] (D : OreDivisionDerivation B)
274     (I : Submodule (NormalOre D)ᵐᵒᵖ (NormalOre D)) :
275     ℕ →o Submodule Bᵐᵒᵖ B where
276   toFun n := leadingCoeffNth D I n
277   monotone' _m _n h := leadingCoeffNth_mono D I h
278 
279 theorem exists_leadingCoeff_stable
280     [Nontrivial B]
281     [IsNoetherianRing Bᵐᵒᵖ]
282     (D : OreDivisionDerivation B)
283     (I : Submodule (NormalOre D)ᵐᵒᵖ (NormalOre D)) :
284     ∃ N : ℕ, ∀ n, N ≤ n → leadingCoeffNth D I n = leadingCoeffNth D I N := by
285   letI : IsNoetherian Bᵐᵒᵖ B := rightScalar_isNoetherian
286   let f := leadingCoeffChain D I
287   have hconst : Filter.EventuallyConst
288       (f : ℕ → Submodule Bᵐᵒᵖ B) Filter.atTop :=
289     eventuallyConst_of_isNoetherian f
290   rcases Filter.eventuallyConst_atTop.mp hconst with ⟨N, hN⟩
291   exact ⟨N, fun n hn => hN n hn⟩
292 
293 lemma normalDegreeLE_le_window (D : OreDivisionDerivation B) (n : ℕ) :
294     normalDegreeLE D n ≤ rightCoefficientWindow D (n + 1) := by
295   intro z hz
296   let p := (normalPolyEquiv D).symm z
297   have hpdeg : p.degree ≤ (n : WithBot ℕ) := by
298     change ((normalPolyEquiv D).symm z).degree ≤ _
299     exact hz
300   have hp : p = 0 ∨ p.natDegree < n + 1 := by
301     by_cases hp0 : p = 0
302     · exact Or.inl hp0
303     · right
304       have hpnat : p.natDegree ≤ n :=
305         Polynomial.natDegree_le_of_degree_le hpdeg
306       omega
307   have hw := normalForm_mem_rightCoefficientWindow_of_degree_lt
308     D p (n + 1) hp
309   have hzval : normalForm D p = z := by
310     change (normalPolyEquiv D) p = z
311     exact (normalPolyEquiv D).apply_symm_apply z
312   rw [← hzval]
313   exact hw
314 
315 /-- The degree window embedded in the finite coefficient window. -/
316 def normalDegreeLEToWindow (D : OreDivisionDerivation B) (n : ℕ) :
317     normalDegreeLE D n →ₗ[Bᵐᵒᵖ] rightCoefficientWindow D (n + 1) where
318   toFun z := ⟨z.1, normalDegreeLE_le_window D n z.2⟩
319   map_add' x y := by rfl
320   map_smul' b x := by rfl
321 
322 /-- Inclusion of an ideal degree window into the full degree window. -/
323 def normalDegreeIncl (D : OreDivisionDerivation B) (n : ℕ)
324     (J : Submodule Bᵐᵒᵖ (NormalOre D))
325     (hJ : J ≤ normalDegreeLE D n) :
326     J →ₗ[Bᵐᵒᵖ] normalDegreeLE D n where
327   toFun z := ⟨z.1, hJ z.2⟩
328   map_add' x y := by rfl
329   map_smul' b x := by rfl
330 
331 theorem rightIdealDegreeLE_fg
332     [IsNoetherianRing Bᵐᵒᵖ]
333     (D : OreDivisionDerivation B)
334     (I : Submodule (NormalOre D)ᵐᵒᵖ (NormalOre D)) (n : ℕ) :
335     (rightIdealDegreeLE D I n).FG := by
336   letI : Module.Finite Bᵐᵒᵖ (rightCoefficientWindow D (n + 1)) :=
337     Module.Finite.span_of_finite Bᵐᵒᵖ (Set.finite_range
338       (fun j : Fin (n + 1) => normalForm D (Polynomial.X ^ (j : ℕ))))
339   letI : IsNoetherian Bᵐᵒᵖ (rightCoefficientWindow D (n + 1)) :=
340     isNoetherian_of_isNoetherianRing_of_finite Bᵐᵒᵖ
341       (rightCoefficientWindow D (n + 1))
342   letI : Module.Finite Bᵐᵒᵖ (normalDegreeLE D n) :=
343     Module.Finite.of_injective
344       (normalDegreeLEToWindow D n) (by
345         intro x y h
346         apply Subtype.ext
347         exact congrArg
348           (fun z : rightCoefficientWindow D (n + 1) => (z : NormalOre D)) h)
349   letI : IsNoetherian Bᵐᵒᵖ (normalDegreeLE D n) :=
350     isNoetherian_of_isNoetherianRing_of_finite Bᵐᵒᵖ
351       (normalDegreeLE D n)
352   let incl := normalDegreeIncl D n (rightIdealDegreeLE D I n) inf_le_left
353   letI : Module.Finite Bᵐᵒᵖ (rightIdealDegreeLE D I n) :=
354     Module.Finite.of_injective incl (by
355       intro x y h
356       apply Subtype.ext
357       exact congrArg
358         (fun z : normalDegreeLE D n => (z : NormalOre D)) h)
359   have htop : (⊤ : Submodule Bᵐᵒᵖ (rightIdealDegreeLE D I n)).FG :=
360     Module.finite_def.mp (inferInstance :
361       Module.Finite Bᵐᵒᵖ (rightIdealDegreeLE D I n))
362   exact (Submodule.fg_top (rightIdealDegreeLE D I n)).mp htop
363 
364 theorem normalOre_rightIdeal_fg_of_op_noetherian
365     [Nontrivial B] [IsNoetherianRing Bᵐᵒᵖ]
366     (D : OreDivisionDerivation B)
367     (I : Submodule (NormalOre D)ᵐᵒᵖ (NormalOre D)) : I.FG := by
368   obtain ⟨N, hstable⟩ := exists_leadingCoeff_stable D I
369   obtain ⟨s, hs⟩ := rightIdealDegreeLE_fg D I N
370   let K : Submodule (NormalOre D)ᵐᵒᵖ (NormalOre D) :=
371     Submodule.span (NormalOre D)ᵐᵒᵖ (s : Set (NormalOre D))
372   have hKsub : K ≤ I := by
373     apply Submodule.span_le.2
374     intro z hz
375     have hzJ : z ∈ rightIdealDegreeLE D I N := by
376       rw [← hs]
377       exact Submodule.subset_span hz
378     exact hzJ.2
379   refine ⟨s, ?_⟩
380   apply le_antisymm hKsub
381   intro z hz
382   obtain ⟨p, rfl⟩ := normalForm_surjective D z
383   have hBspan_le :
384       Submodule.span Bᵐᵒᵖ (s : Set (NormalOre D)) ≤
385         rightIdealAsCoeffSubmodule D K := by
386     apply Submodule.span_le.2
387     intro x hx
388     exact Submodule.subset_span hx
389   have hgen : ∀ n : ℕ, ∀ p : Polynomial B,
390       p.natDegree = n → normalForm D p ∈ I → normalForm D p ∈ K := by
391     intro n
392     induction n using Nat.strong_induction_on with
393     | h n ih =>
394       intro p hpn hpI
395       by_cases hp0 : p = 0
396       · subst p
397         simp [normalForm_zero]
398       by_cases hsmall : p.natDegree ≤ N
399       · have hpdeg : p.degree ≤ (N : WithBot ℕ) := by
400           rw [Polynomial.degree_eq_natDegree hp0]
401           exact WithBot.coe_le_coe.2 hsmall
402         have hnormalP : normalForm D p ∈ normalDegreeLE D N := by
403           have hinv : (normalPolyEquiv D).symm (normalForm D p) = p := by
404             change (normalPolyEquiv D).symm ((normalPolyEquiv D) p) = p
405             exact (normalPolyEquiv D).symm_apply_apply p
406           change ((normalPolyEquiv D).symm (normalForm D p)).degree ≤
407             (N : WithBot ℕ)
408           rw [hinv]
409           exact hpdeg
410         have hpJ : normalForm D p ∈ rightIdealDegreeLE D I N :=
411           ⟨hnormalP, hpI⟩
412         have hpB : normalForm D p ∈
413             Submodule.span Bᵐᵒᵖ (s : Set (NormalOre D)) := by
414           rw [hs]
415           exact hpJ
416         exact hBspan_le hpB
417       · have hlarge : N < p.natDegree := lt_of_not_ge hsmall
418         let c := p.leadingCoeff
419         have hcne : c ≠ 0 := Polynomial.leadingCoeff_ne_zero.mpr hp0
420         have hpc : p.coeff n = c := by
421           dsimp [c]
422           rw [Polynomial.leadingCoeff, hpn]
423         have hcN : c ∈ leadingCoeffNth D I N := by
424           rw [← hstable p.natDegree (le_of_lt hlarge)]
425           rw [mem_leadingCoeffNth]
426           refine ⟨p, hpI, ?_, ?_⟩
427           · exact Polynomial.degree_le_natDegree
428           · dsimp [c]
429         rcases (mem_leadingCoeffNth D I N c).mp hcN with
430           ⟨q, hqI, hqdeg, hqcoeff⟩
431         let u := rightMul D q (Polynomial.X ^ (n - N))
432         have huI : normalForm D u ∈ I := by
433           rw [normalForm_mul]
434           have hmem := I.smul_mem
435             (MulOpposite.op (normalForm D (Polynomial.X ^ (n - N)))) hqI
436           simpa [u, op_smul_eq_mul] using hmem
437         have huK : normalForm D u ∈ K := by
438           have hnormalQ : normalForm D q ∈ normalDegreeLE D N := by
439             have hinv : (normalPolyEquiv D).symm (normalForm D q) = q := by
440               change (normalPolyEquiv D).symm ((normalPolyEquiv D) q) = q
441               exact (normalPolyEquiv D).symm_apply_apply q
442             change ((normalPolyEquiv D).symm (normalForm D q)).degree ≤
443               (N : WithBot ℕ)
444             rw [hinv]
445             exact hqdeg
446           have hqJ : normalForm D q ∈ rightIdealDegreeLE D I N :=
447             ⟨hnormalQ, hqI⟩
448           have hqB : normalForm D q ∈
449               Submodule.span Bᵐᵒᵖ (s : Set (NormalOre D)) := by
450             rw [hs]
451             exact hqJ
452           have hmulK := K.smul_mem
453             (MulOpposite.op (normalForm D (Polynomial.X ^ (n - N))))
454             (hBspan_le hqB)
455           simpa [u, normalForm_mul, op_smul_eq_mul] using hmulK
456         have hucoeff : u.coeff n = c := by
457           dsimp [u]
458           have hqcoeff' :=
459             rightMul_Xpow_coeff_of_degree_le D q N (n - N) hqdeg
460           have hNn : N ≤ n := hpn ▸ le_of_lt hlarge
461           rw [Nat.add_sub_of_le hNn] at hqcoeff'
462           rw [hqcoeff']
463           exact hqcoeff
464         have hu0 : u ≠ 0 := by
465           intro hu
466           have hthis : u.coeff n = (0 : Polynomial B).coeff n := by
467             simpa using congrArg (fun r : Polynomial B => r.coeff n) hu
468           rw [hucoeff] at hthis
469           exact hcne (by simpa using hthis)
470         have hule : u.degree ≤ (n : WithBot ℕ) := by
471           dsimp [u]
472           have hdeg := rightMul_degree_le D q (Polynomial.X ^ (n - N))
473           have hqnat : q.natDegree ≤ N :=
474             Polynomial.natDegree_le_of_degree_le hqdeg
475           have hnatX : (Polynomial.X ^ (n - N) : Polynomial B).natDegree =
476               n - N := Polynomial.natDegree_X_pow _
477           rw [hnatX] at hdeg
478           have hadd : q.natDegree + (n - N) ≤ n := by
479             exact (Nat.add_le_add_right hqnat (n - N)).trans_eq
480               (Nat.add_sub_of_le (hpn ▸ le_of_lt hlarge))
481           exact hdeg.trans (by exact_mod_cast hadd)
482         have hun : u.natDegree = n := by
483           apply le_antisymm
484           · exact Polynomial.natDegree_le_of_degree_le hule
485           · apply Polynomial.le_natDegree_of_mem_supp
486             rw [Polynomial.mem_support_iff]
487             exact hucoeff.trans_ne hcne
488         have hudeg : u.degree = (n : WithBot ℕ) := by
489           rw [Polynomial.degree_eq_natDegree hu0, hun]
490         have hpdeg : p.degree = (n : WithBot ℕ) := by
491           rw [Polynomial.degree_eq_natDegree hp0, hpn]
492         have hplead : p.leadingCoeff = u.leadingCoeff := by
493           rw [Polynomial.leadingCoeff, hpn,
494             Polynomial.leadingCoeff, hun, hpc, hucoeff]
495         let r := p - u
496         have hrI : normalForm D r ∈ I := by
497           dsimp [r]
498           rw [show normalForm D (p - u) =
499               normalForm D p - normalForm D u from
500             map_sub (normalFormAddHom D) p u]
501           exact I.sub_mem hpI huI
502         have hrdeg : r.degree < (n : WithBot ℕ) := by
503           dsimp [r]
504           have hsub := Polynomial.degree_sub_lt (hpdeg.trans hudeg.symm) hp0 hplead
505           simpa [hpdeg] using hsub
506         by_cases hr0 : r = 0
507         · have hpr : p = u := sub_eq_zero.mp hr0
508           rw [hpr]
509           exact huK
510         · have hrnat : r.natDegree < n := by
511             have hrdeg' : (r.natDegree : WithBot ℕ) <
512                 (n : WithBot ℕ) := by
513               rw [Polynomial.degree_eq_natDegree hr0] at hrdeg
514               exact hrdeg
515             exact WithBot.coe_lt_coe.mp hrdeg'
516           have hrK := ih r.natDegree hrnat r rfl hrI
517           have huK' := huK
518           change normalForm D p ∈ K
519           rw [show p = u + r by dsimp [r]; abel, normalForm_add]
520           exact K.add_mem huK' hrK
521   exact hgen p.natDegree p rfl hz
522 
523 theorem normalOre_op_isNoetherian_of_nontrivial
524     [Nontrivial B] [IsNoetherianRing Bᵐᵒᵖ]
525     (D : OreDivisionDerivation B) :
526     IsNoetherianRing (NormalOre D)ᵐᵒᵖ := by
527   refine ⟨?_⟩
528   intro J
529   let e : NormalOre D ≃ₗ[(NormalOre D)ᵐᵒᵖ] (NormalOre D)ᵐᵒᵖ :=
530     MulOpposite.opLinearEquiv (NormalOre D)ᵐᵒᵖ
531   let I : Submodule (NormalOre D)ᵐᵒᵖ (NormalOre D) :=
532     J.comap e.toLinearMap
533   have hI : I.FG := normalOre_rightIdeal_fg_of_op_noetherian D I
534   have hmap : I.map e.toLinearMap = J := by
535     exact Submodule.map_comap_eq_of_surjective e.surjective J
536   rw [← hmap]
537   exact hI.map e.toLinearMap
538 
539 theorem normalOre_op_isNoetherian_of_subsingleton
540     [Subsingleton B] (D : OreDivisionDerivation B) :
541     IsNoetherianRing (NormalOre D)ᵐᵒᵖ := by
542   letI : Subsingleton (NormalOre D) :=
543     ⟨fun x y => by
544       obtain ⟨p, rfl⟩ := normalForm_surjective D x
545       obtain ⟨q, rfl⟩ := normalForm_surjective D y
546       exact congrArg (normalForm D) (Subsingleton.elim p q)⟩
547   rw [isNoetherianRing_iff]
548   exact isNoetherian_of_subsingleton
549     (NormalOre D)ᵐᵒᵖ (NormalOre D)ᵐᵒᵖ
550 
551 theorem derivationOre_rightHilbertBasis :
552     DerivationOreRightHilbertBasis.{u} := by
553   intro B _ hB D
554   letI : IsNoetherianRing Bᵐᵒᵖ := hB
555   by_cases hnt : Nontrivial B
556   · letI : Nontrivial B := hnt
557     exact normalOre_op_isNoetherian_of_nontrivial D
558   · haveI : Subsingleton B := not_nontrivial_iff_subsingleton.mp hnt
559     exact normalOre_op_isNoetherian_of_subsingleton D
560 
561 #print axioms rightScalar_smul_def
562 #print axioms normalOre_rightIdeal_fg_of_op_noetherian
563 #print axioms normalOre_op_isNoetherian_of_nontrivial
564 #print axioms normalOre_op_isNoetherian_of_subsingleton
565 #print axioms derivationOre_rightHilbertBasis
566 end
567 
568 end AlgebraicAnalysis.OreDerivationRightHilbertBasis
569