source stringlengths 17 118 | lean4 stringlengths 0 335k |
|---|---|
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/StructurePolynomial.lean | import Mathlib.FieldTheory.Finite.Polynomial
import Mathlib.NumberTheory.Basic
import Mathlib.RingTheory.WittVector.WittPolynomial
/-!
# Witt structure polynomials
In this file we prove the main theorem that makes the whole theory of Witt vectors work.
Briefly, consider a polynomial `Φ : MvPolynomial idx ℤ` over the integers,
with polynomials variables indexed by an arbitrary type `idx`.
Then there exists a unique family of polynomials `φ : ℕ → MvPolynomial (idx × ℕ) Φ`
such that for all `n : ℕ` we have (`wittStructureInt_existsUnique`)
```
bind₁ φ (wittPolynomial p ℤ n) = bind₁ (fun i ↦ (rename (prod.mk i) (wittPolynomial p ℤ n))) Φ
```
In other words: evaluating the `n`-th Witt polynomial on the family `φ`
is the same as evaluating `Φ` on the (appropriately renamed) `n`-th Witt polynomials.
N.b.: As far as we know, these polynomials do not have a name in the literature,
so we have decided to call them the “Witt structure polynomials”. See `wittStructureInt`.
## Special cases
With the main result of this file in place, we apply it to certain special polynomials.
For example, by taking `Φ = X tt + X ff` resp. `Φ = X tt * X ff`
we obtain families of polynomials `witt_add` resp. `witt_mul`
(with type `ℕ → MvPolynomial (Bool × ℕ) ℤ`) that will be used in later files to define the
addition and multiplication on the ring of Witt vectors.
## Outline of the proof
The proof of `wittStructureInt_existsUnique` is rather technical, and takes up most of this file.
We start by proving the analogous version for polynomials with rational coefficients,
instead of integer coefficients.
In this case, the solution is rather easy,
since the Witt polynomials form a faithful change of coordinates
in the polynomial ring `MvPolynomial ℕ ℚ`.
We therefore obtain a family of polynomials `wittStructureRat Φ`
for every `Φ : MvPolynomial idx ℚ`.
If `Φ` has integer coefficients, then the polynomials `wittStructureRat Φ n` do so as well.
Proving this claim is the essential core of this file, and culminates in
`map_wittStructureInt`, which proves that upon mapping the coefficients
of `wittStructureInt Φ n` from the integers to the rationals,
one obtains `wittStructureRat Φ n`.
Ultimately, the proof of `map_wittStructureInt` relies on
```
dvd_sub_pow_of_dvd_sub {R : Type*} [CommRing R] {p : ℕ} {a b : R} :
(p : R) ∣ a - b → ∀ (k : ℕ), (p : R) ^ (k + 1) ∣ a ^ p ^ k - b ^ p ^ k
```
## Main results
* `wittStructureRat Φ`: the family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℚ`
associated with `Φ : MvPolynomial idx ℚ` and satisfying the property explained above.
* `wittStructureRat_prop`: the proof that `wittStructureRat` indeed satisfies the property.
* `wittStructureInt Φ`: the family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℤ`
associated with `Φ : MvPolynomial idx ℤ` and satisfying the property explained above.
* `map_wittStructureInt`: the proof that the integral polynomials `with_structure_int Φ`
are equal to `wittStructureRat Φ` when mapped to polynomials with rational coefficients.
* `wittStructureInt_prop`: the proof that `wittStructureInt` indeed satisfies the property.
* Five families of polynomials that will be used to define the ring structure
on the ring of Witt vectors:
- `WittVector.wittZero`
- `WittVector.wittOne`
- `WittVector.wittAdd`
- `WittVector.wittMul`
- `WittVector.wittNeg`
(We also define `WittVector.wittSub`, and later we will prove that it describes subtraction,
which is defined as `fun a b ↦ a + -b`. See `WittVector.sub_coeff` for this proof.)
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
open MvPolynomial Set
open Finset (range)
open Finsupp (single)
-- This lemma reduces a bundled morphism to a "mere" function,
-- and consequently the simplifier cannot use a lot of powerful simp-lemmas.
-- We disable this locally, and probably it should be disabled globally in mathlib.
attribute [-simp] coe_eval₂Hom
variable {p : ℕ} {R : Type*} {idx : Type*} [CommRing R]
open scoped Witt
section PPrime
variable (p)
variable [hp : Fact p.Prime]
-- Notation with ring of coefficients explicit
set_option quotPrecheck false in
@[inherit_doc]
scoped[Witt] notation "W_" => wittPolynomial p
-- Notation with ring of coefficients implicit
set_option quotPrecheck false in
@[inherit_doc]
scoped[Witt] notation "W" => wittPolynomial p _
/-- `wittStructureRat Φ` is a family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℚ`
that are uniquely characterised by the property that
```
bind₁ (wittStructureRat p Φ) (wittPolynomial p ℚ n) =
bind₁ (fun i ↦ (rename (prod.mk i) (wittPolynomial p ℚ n))) Φ
```
In other words: evaluating the `n`-th Witt polynomial on the family `wittStructureRat Φ`
is the same as evaluating `Φ` on the (appropriately renamed) `n`-th Witt polynomials.
See `wittStructureRat_prop` for this property,
and `wittStructureRat_existsUnique` for the fact that `wittStructureRat`
gives the unique family of polynomials with this property.
These polynomials turn out to have integral coefficients,
but it requires some effort to show this.
See `wittStructureInt` for the version with integral coefficients,
and `map_wittStructureInt` for the fact that it is equal to `wittStructureRat`
when mapped to polynomials over the rationals. -/
noncomputable def wittStructureRat (Φ : MvPolynomial idx ℚ) (n : ℕ) : MvPolynomial (idx × ℕ) ℚ :=
bind₁ (fun k => bind₁ (fun i => rename (Prod.mk i) (W_ ℚ k)) Φ) (xInTermsOfW p ℚ n)
theorem wittStructureRat_prop (Φ : MvPolynomial idx ℚ) (n : ℕ) :
bind₁ (wittStructureRat p Φ) (W_ ℚ n) = bind₁ (fun i => rename (Prod.mk i) (W_ ℚ n)) Φ :=
calc
bind₁ (wittStructureRat p Φ) (W_ ℚ n) =
bind₁ (fun k => bind₁ (fun i => (rename (Prod.mk i)) (W_ ℚ k)) Φ)
(bind₁ (xInTermsOfW p ℚ) (W_ ℚ n)) := by
rw [bind₁_bind₁]; exact eval₂Hom_congr (RingHom.ext_rat _ _) rfl rfl
_ = bind₁ (fun i => rename (Prod.mk i) (W_ ℚ n)) Φ := by
rw [bind₁_xInTermsOfW_wittPolynomial p _ n, bind₁_X_right]
theorem wittStructureRat_existsUnique (Φ : MvPolynomial idx ℚ) :
∃! φ : ℕ → MvPolynomial (idx × ℕ) ℚ,
∀ n : ℕ, bind₁ φ (W_ ℚ n) = bind₁ (fun i => rename (Prod.mk i) (W_ ℚ n)) Φ := by
refine ⟨wittStructureRat p Φ, ?_, ?_⟩
· intro n; apply wittStructureRat_prop
· intro φ H
funext n
rw [show φ n = bind₁ φ (bind₁ (W_ ℚ) (xInTermsOfW p ℚ n)) by
rw [bind₁_wittPolynomial_xInTermsOfW p, bind₁_X_right]]
rw [bind₁_bind₁]
exact eval₂Hom_congr (RingHom.ext_rat _ _) (funext H) rfl
theorem wittStructureRat_rec_aux (Φ : MvPolynomial idx ℚ) (n : ℕ) :
wittStructureRat p Φ n * C ((p : ℚ) ^ n) =
bind₁ (fun b => rename (fun i => (b, i)) (W_ ℚ n)) Φ -
∑ i ∈ range n, C ((p : ℚ) ^ i) * wittStructureRat p Φ i ^ p ^ (n - i) := by
have := xInTermsOfW_aux p ℚ n
replace := congr_arg (bind₁ fun k : ℕ => bind₁ (fun i => rename (Prod.mk i) (W_ ℚ k)) Φ) this
rw [map_mul, bind₁_C_right] at this
rw [wittStructureRat, this]; clear this
conv_lhs => simp only [map_sub, bind₁_X_right]
rw [sub_right_inj]
simp only [map_sum, map_mul, bind₁_C_right, map_pow]
rfl
/-- Write `wittStructureRat p φ n` in terms of `wittStructureRat p φ i` for `i < n`. -/
theorem wittStructureRat_rec (Φ : MvPolynomial idx ℚ) (n : ℕ) :
wittStructureRat p Φ n =
C (1 / (p : ℚ) ^ n) *
(bind₁ (fun b => rename (fun i => (b, i)) (W_ ℚ n)) Φ -
∑ i ∈ range n, C ((p : ℚ) ^ i) * wittStructureRat p Φ i ^ p ^ (n - i)) := by
calc
wittStructureRat p Φ n = C (1 / (p : ℚ) ^ n) * (wittStructureRat p Φ n * C ((p : ℚ) ^ n)) := ?_
_ = _ := by rw [wittStructureRat_rec_aux]
rw [mul_left_comm, ← C_mul, div_mul_cancel₀, C_1, mul_one]
exact pow_ne_zero _ (Nat.cast_ne_zero.2 hp.1.ne_zero)
/-- `wittStructureInt Φ` is a family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℤ`
that are uniquely characterised by the property that
```
bind₁ (wittStructureInt p Φ) (wittPolynomial p ℤ n) =
bind₁ (fun i ↦ (rename (prod.mk i) (wittPolynomial p ℤ n))) Φ
```
In other words: evaluating the `n`-th Witt polynomial on the family `wittStructureInt Φ`
is the same as evaluating `Φ` on the (appropriately renamed) `n`-th Witt polynomials.
See `wittStructureInt_prop` for this property,
and `wittStructureInt_existsUnique` for the fact that `wittStructureInt`
gives the unique family of polynomials with this property. -/
noncomputable def wittStructureInt (Φ : MvPolynomial idx ℤ) (n : ℕ) : MvPolynomial (idx × ℕ) ℤ :=
Finsupp.mapRange Rat.num (Rat.num_intCast 0) (wittStructureRat p (map (Int.castRingHom ℚ) Φ) n)
variable {p}
theorem bind₁_rename_expand_wittPolynomial (Φ : MvPolynomial idx ℤ) (n : ℕ)
(IH :
∀ m : ℕ,
m < n + 1 →
map (Int.castRingHom ℚ) (wittStructureInt p Φ m) =
wittStructureRat p (map (Int.castRingHom ℚ) Φ) m) :
bind₁ (fun b => rename (fun i => (b, i)) (expand p (W_ ℤ n))) Φ =
bind₁ (fun i => expand p (wittStructureInt p Φ i)) (W_ ℤ n) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [map_bind₁, map_rename, map_expand, rename_expand, map_wittPolynomial]
have key := (wittStructureRat_prop p (map (Int.castRingHom ℚ) Φ) n).symm
apply_fun expand p at key
simp only [expand_bind₁] at key
rw [key]; clear key
apply eval₂Hom_congr' rfl _ rfl
rintro i hi -
rw [wittPolynomial_vars, Finset.mem_range] at hi
simp only [IH i hi]
theorem C_p_pow_dvd_bind₁_rename_wittPolynomial_sub_sum (Φ : MvPolynomial idx ℤ) (n : ℕ)
(IH :
∀ m : ℕ,
m < n →
map (Int.castRingHom ℚ) (wittStructureInt p Φ m) =
wittStructureRat p (map (Int.castRingHom ℚ) Φ) m) :
(C ((p ^ n :) : ℤ) : MvPolynomial (idx × ℕ) ℤ) ∣
bind₁ (fun b : idx => rename (fun i => (b, i)) (wittPolynomial p ℤ n)) Φ -
∑ i ∈ range n, C ((p : ℤ) ^ i) * wittStructureInt p Φ i ^ p ^ (n - i) := by
rcases n with - | n
· simp only [isUnit_one, pow_zero, C_1, IsUnit.dvd,
Nat.cast_one]
-- prepare a useful equation for rewriting
have key := bind₁_rename_expand_wittPolynomial Φ n IH
apply_fun map (Int.castRingHom (ZMod (p ^ (n + 1)))) at key
conv_lhs at key => simp only [map_bind₁, map_rename, map_expand, map_wittPolynomial]
-- clean up and massage
rw [C_dvd_iff_zmod, RingHom.map_sub, sub_eq_zero, map_bind₁]
simp only [map_rename, map_wittPolynomial, wittPolynomial_zmod_self]
rw [key]; clear key IH
rw [bind₁, aeval_wittPolynomial, map_sum, map_sum, Finset.sum_congr rfl]
intro k hk
rw [Finset.mem_range, Nat.lt_succ_iff] at hk
rw [← sub_eq_zero, ← RingHom.map_sub, ← C_dvd_iff_zmod, C_eq_coe_nat, ← Nat.cast_pow,
← Nat.cast_pow, C_eq_coe_nat, ← mul_sub]
have : p ^ (n + 1) = p ^ k * p ^ (n - k + 1) := by
rw [← pow_add, ← add_assoc]; congr 2; rw [add_comm, ← tsub_eq_iff_eq_add_of_le hk]
rw [this]
rw [Nat.cast_mul, Nat.cast_pow, Nat.cast_pow]
apply mul_dvd_mul_left ((p : MvPolynomial (idx × ℕ) ℤ) ^ k)
rw [show p ^ (n + 1 - k) = p * p ^ (n - k) by rw [← pow_succ', ← tsub_add_eq_add_tsub hk]]
rw [pow_mul]
-- the machine!
apply dvd_sub_pow_of_dvd_sub
rw [← C_eq_coe_nat, C_dvd_iff_zmod, RingHom.map_sub, sub_eq_zero, map_expand, RingHom.map_pow,
MvPolynomial.expand_zmod]
variable (p)
@[simp]
theorem map_wittStructureInt (Φ : MvPolynomial idx ℤ) (n : ℕ) :
map (Int.castRingHom ℚ) (wittStructureInt p Φ n) =
wittStructureRat p (map (Int.castRingHom ℚ) Φ) n := by
induction n using Nat.strong_induction_on with | h n IH => ?_
rw [wittStructureInt, map_mapRange_eq_iff, Int.coe_castRingHom]
intro c
rw [wittStructureRat_rec, coeff_C_mul, mul_comm, mul_div_assoc', mul_one]
have sum_induction_steps :
map (Int.castRingHom ℚ)
(∑ i ∈ range n, C ((p : ℤ) ^ i) * wittStructureInt p Φ i ^ p ^ (n - i)) =
∑ i ∈ range n,
C ((p : ℚ) ^ i) * wittStructureRat p (map (Int.castRingHom ℚ) Φ) i ^ p ^ (n - i) := by
rw [map_sum]
apply Finset.sum_congr rfl
intro i hi
rw [Finset.mem_range] at hi
simp only [IH i hi, RingHom.map_mul, RingHom.map_pow, map_C]
rfl
simp only [← sum_induction_steps, ← map_wittPolynomial p (Int.castRingHom ℚ), ← map_rename, ←
map_bind₁, ← RingHom.map_sub, coeff_map]
rw [show (p : ℚ) ^ n = ((↑(p ^ n) : ℤ) : ℚ) by norm_cast]
rw [← Rat.den_eq_one_iff, eq_intCast, Rat.den_div_intCast_eq_one_iff]
swap; · exact mod_cast pow_ne_zero n hp.1.ne_zero
revert c; rw [← C_dvd_iff_dvd_coeff]
exact C_p_pow_dvd_bind₁_rename_wittPolynomial_sub_sum Φ n IH
theorem wittStructureInt_prop (Φ : MvPolynomial idx ℤ) (n) :
bind₁ (wittStructureInt p Φ) (wittPolynomial p ℤ n) =
bind₁ (fun i => rename (Prod.mk i) (W_ ℤ n)) Φ := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
have := wittStructureRat_prop p (map (Int.castRingHom ℚ) Φ) n
simpa only [map_bind₁, ← eval₂Hom_map_hom, eval₂Hom_C_left, map_rename, map_wittPolynomial,
AlgHom.coe_toRingHom, map_wittStructureInt]
theorem eq_wittStructureInt (Φ : MvPolynomial idx ℤ) (φ : ℕ → MvPolynomial (idx × ℕ) ℤ)
(h : ∀ n, bind₁ φ (wittPolynomial p ℤ n) = bind₁ (fun i => rename (Prod.mk i) (W_ ℤ n)) Φ) :
φ = wittStructureInt p Φ := by
funext k
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
rw [map_wittStructureInt]
-- Porting note: was `refine' congr_fun _ k`
revert k
refine congr_fun ?_
apply ExistsUnique.unique (wittStructureRat_existsUnique p (map (Int.castRingHom ℚ) Φ))
· intro n
specialize h n
apply_fun map (Int.castRingHom ℚ) at h
simpa only [map_bind₁, ← eval₂Hom_map_hom, eval₂Hom_C_left, map_rename, map_wittPolynomial,
AlgHom.coe_toRingHom] using h
· intro n; apply wittStructureRat_prop
theorem wittStructureInt_existsUnique (Φ : MvPolynomial idx ℤ) :
∃! φ : ℕ → MvPolynomial (idx × ℕ) ℤ,
∀ n : ℕ,
bind₁ φ (wittPolynomial p ℤ n) = bind₁ (fun i : idx => rename (Prod.mk i) (W_ ℤ n)) Φ :=
⟨wittStructureInt p Φ, wittStructureInt_prop _ _, eq_wittStructureInt _ _⟩
theorem witt_structure_prop (Φ : MvPolynomial idx ℤ) (n) :
aeval (fun i => map (Int.castRingHom R) (wittStructureInt p Φ i)) (wittPolynomial p ℤ n) =
aeval (fun i => rename (Prod.mk i) (W n)) Φ := by
convert congr_arg (map (Int.castRingHom R)) (wittStructureInt_prop p Φ n) using 1 <;>
rw [hom_bind₁] <;>
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
· rfl
· simp only [map_rename, map_wittPolynomial]
theorem wittStructureInt_rename {σ : Type*} (Φ : MvPolynomial idx ℤ) (f : idx → σ) (n : ℕ) :
wittStructureInt p (rename f Φ) n = rename (Prod.map f id) (wittStructureInt p Φ n) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [map_rename, map_wittStructureInt, wittStructureRat, rename_bind₁, rename_rename,
bind₁_rename]
rfl
@[simp]
theorem constantCoeff_wittStructureRat_zero (Φ : MvPolynomial idx ℚ) :
constantCoeff (wittStructureRat p Φ 0) = constantCoeff Φ := by
simp only [wittStructureRat, bind₁, map_aeval, xInTermsOfW_zero, constantCoeff_rename,
constantCoeff_wittPolynomial, aeval_X, constantCoeff_comp_algebraMap, eval₂Hom_zero'_apply,
RingHom.id_apply]
theorem constantCoeff_wittStructureRat (Φ : MvPolynomial idx ℚ) (h : constantCoeff Φ = 0) (n : ℕ) :
constantCoeff (wittStructureRat p Φ n) = 0 := by
simp only [wittStructureRat, eval₂Hom_zero'_apply, h, bind₁, map_aeval, constantCoeff_rename,
constantCoeff_wittPolynomial, constantCoeff_comp_algebraMap, RingHom.id_apply,
constantCoeff_xInTermsOfW]
@[simp]
theorem constantCoeff_wittStructureInt_zero (Φ : MvPolynomial idx ℤ) :
constantCoeff (wittStructureInt p Φ 0) = constantCoeff Φ := by
have inj : Function.Injective (Int.castRingHom ℚ) := by intro m n; exact Int.cast_inj.mp
apply inj
rw [← constantCoeff_map, map_wittStructureInt, constantCoeff_wittStructureRat_zero,
constantCoeff_map]
theorem constantCoeff_wittStructureInt (Φ : MvPolynomial idx ℤ) (h : constantCoeff Φ = 0) (n : ℕ) :
constantCoeff (wittStructureInt p Φ n) = 0 := by
have inj : Function.Injective (Int.castRingHom ℚ) := by intro m n; exact Int.cast_inj.mp
apply inj
rw [← constantCoeff_map, map_wittStructureInt, constantCoeff_wittStructureRat, RingHom.map_zero]
rw [constantCoeff_map, h, RingHom.map_zero]
variable (R)
-- we could relax the fintype on `idx`, but then we need to cast from finset to set.
-- for our applications `idx` is always finite.
theorem wittStructureRat_vars [Fintype idx] (Φ : MvPolynomial idx ℚ) (n : ℕ) :
(wittStructureRat p Φ n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) := by
rw [wittStructureRat]
intro x hx
simp only [Finset.mem_product, true_and, Finset.mem_univ, Finset.mem_range]
obtain ⟨k, hk, hx'⟩ := mem_vars_bind₁ _ _ hx
obtain ⟨i, -, hx''⟩ := mem_vars_bind₁ _ _ hx'
obtain ⟨j, hj, rfl⟩ := mem_vars_rename _ _ hx''
rw [wittPolynomial_vars, Finset.mem_range] at hj
replace hk := xInTermsOfW_vars_subset p _ hk
grind
-- we could relax the fintype on `idx`, but then we need to cast from finset to set.
-- for our applications `idx` is always finite.
theorem wittStructureInt_vars [Fintype idx] (Φ : MvPolynomial idx ℤ) (n : ℕ) :
(wittStructureInt p Φ n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) := by
have : Function.Injective (Int.castRingHom ℚ) := Int.cast_injective
rw [← vars_map_of_injective _ this, map_wittStructureInt]
apply wittStructureRat_vars
end PPrime |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/WittPolynomial.lean | import Mathlib.Algebra.CharP.Invertible
import Mathlib.Algebra.MvPolynomial.Variables
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.Algebra.MvPolynomial.Expand
import Mathlib.Algebra.Order.Ring.Rat
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.ZMod.Basic
/-!
# Witt polynomials
To endow `WittVector p R` with a ring structure,
we need to study the so-called Witt polynomials.
Fix a base value `p : ℕ`.
The `p`-adic Witt polynomials are an infinite family of polynomials
indexed by a natural number `n`, taking values in an arbitrary ring `R`.
The variables of these polynomials are represented by natural numbers.
The variable set of the `n`th Witt polynomial contains at most `n+1` elements `{0, ..., n}`,
with exactly these variables when `R` has characteristic `0`.
These polynomials are used to define the addition and multiplication operators
on the type of Witt vectors. (While this type itself is not complicated,
the ring operations are what make it interesting.)
When the base `p` is invertible in `R`, the `p`-adic Witt polynomials
form a basis for `MvPolynomial ℕ R`, equivalent to the standard basis.
## Main declarations
* `WittPolynomial p R n`: the `n`-th Witt polynomial, viewed as polynomial over the ring `R`
* `xInTermsOfW p R n`: if `p` is invertible, the polynomial `X n` is contained in the subalgebra
generated by the Witt polynomials. `xInTermsOfW p R n` is the explicit polynomial,
which upon being bound to the Witt polynomials yields `X n`.
* `bind₁_wittPolynomial_xInTermsOfW`: the proof of the claim that
`bind₁ (xInTermsOfW p R) (W_ R n) = X n`
* `bind₁_xInTermsOfW_wittPolynomial`: the converse of the above statement
## Notation
In this file we use the following notation
* `p` is a natural number, typically assumed to be prime.
* `R` and `S` are commutative rings
* `W n` (and `W_ R n` when the ring needs to be explicit) denotes the `n`th Witt polynomial
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
open MvPolynomial
open Finset hiding map
open Finsupp (single)
--attribute [-simp] coe_eval₂_hom
variable (p : ℕ)
variable (R : Type*) [CommRing R]
/-- `wittPolynomial p R n` is the `n`-th Witt polynomial
with respect to a prime `p` with coefficients in a commutative ring `R`.
It is defined as:
`∑_{i ≤ n} p^i X_i^{p^{n-i}} ∈ R[X_0, X_1, X_2, …]`. -/
noncomputable def wittPolynomial (n : ℕ) : MvPolynomial ℕ R :=
∑ i ∈ range (n + 1), monomial (single i (p ^ (n - i))) ((p : R) ^ i)
theorem wittPolynomial_eq_sum_C_mul_X_pow (n : ℕ) :
wittPolynomial p R n = ∑ i ∈ range (n + 1), C ((p : R) ^ i) * X i ^ p ^ (n - i) := by
apply sum_congr rfl
rintro i -
rw [monomial_eq, Finsupp.prod_single_index]
rw [pow_zero]
/-! We set up notation locally to this file, to keep statements short and comprehensible.
This allows us to simply write `W n` or `W_ ℤ n`. -/
-- Notation with ring of coefficients explicit
set_option quotPrecheck false in
@[inherit_doc]
scoped[Witt] notation "W_" => wittPolynomial p
-- Notation with ring of coefficients implicit
set_option quotPrecheck false in
@[inherit_doc]
scoped[Witt] notation "W" => wittPolynomial p _
open Witt
/-! The first observation is that the Witt polynomial doesn't really depend on the coefficient ring.
If we map the coefficients through a ring homomorphism, we obtain the corresponding Witt polynomial
over the target ring. -/
section
variable {R} {S : Type*} [CommRing S]
@[simp]
theorem map_wittPolynomial (f : R →+* S) (n : ℕ) : map f (W n) = W n := by
rw [wittPolynomial, map_sum, wittPolynomial]
refine sum_congr rfl fun i _ => ?_
rw [map_monomial, RingHom.map_pow, map_natCast]
variable (R)
@[simp]
theorem constantCoeff_wittPolynomial [hp : Fact p.Prime] (n : ℕ) :
constantCoeff (wittPolynomial p R n) = 0 := by
simp only [wittPolynomial, map_sum, constantCoeff_monomial]
rw [sum_eq_zero]
rintro i _
rw [if_neg]
rw [Finsupp.single_eq_zero]
exact ne_of_gt (pow_pos hp.1.pos _)
@[simp]
theorem wittPolynomial_zero : wittPolynomial p R 0 = X 0 := by
simp only [wittPolynomial, X, sum_singleton, range_one, pow_zero, zero_add, tsub_self]
@[simp]
theorem wittPolynomial_one : wittPolynomial p R 1 = C (p : R) * X 1 + X 0 ^ p := by
simp only [wittPolynomial_eq_sum_C_mul_X_pow, sum_range_succ_comm, range_one, sum_singleton,
one_mul, pow_one, C_1, pow_zero, tsub_self, tsub_zero]
theorem aeval_wittPolynomial {A : Type*} [CommRing A] [Algebra R A] (f : ℕ → A) (n : ℕ) :
aeval f (W_ R n) = ∑ i ∈ range (n + 1), (p : A) ^ i * f i ^ p ^ (n - i) := by
simp [wittPolynomial, map_sum, aeval_monomial, Finsupp.prod_single_index]
/-- Over the ring `ZMod (p^(n+1))`, we produce the `n+1`st Witt polynomial
by expanding the `n`th Witt polynomial by `p`. -/
@[simp]
theorem wittPolynomial_zmod_self (n : ℕ) :
W_ (ZMod (p ^ (n + 1))) (n + 1) = expand p (W_ (ZMod (p ^ (n + 1))) n) := by
simp only [wittPolynomial_eq_sum_C_mul_X_pow]
rw [sum_range_succ, ← Nat.cast_pow, CharP.cast_eq_zero (ZMod (p ^ (n + 1))) (p ^ (n + 1)), C_0,
zero_mul, add_zero, map_sum, sum_congr rfl]
intro k hk
rw [map_mul (expand p), map_pow (expand p), expand_X, algHom_C, ← pow_mul, ← pow_succ']
congr
rw [mem_range] at hk
rw [add_comm, add_tsub_assoc_of_le (Nat.lt_succ_iff.mp hk), ← add_comm]
section PPrime
variable [hp : NeZero p]
theorem wittPolynomial_vars [CharZero R] (n : ℕ) : (wittPolynomial p R n).vars = range (n + 1) := by
have : ∀ i, (monomial (Finsupp.single i (p ^ (n - i))) ((p : R) ^ i)).vars = {i} := by
intro i
refine vars_monomial_single i (pow_ne_zero _ hp.1) ?_
rw [← Nat.cast_pow, Nat.cast_ne_zero]
exact pow_ne_zero i hp.1
rw [wittPolynomial, vars_sum_of_disjoint]
· simp only [this, biUnion_singleton_eq_self]
· simp only [this]
intro a b h
apply disjoint_singleton_left.mpr
rwa [mem_singleton]
theorem wittPolynomial_vars_subset (n : ℕ) : (wittPolynomial p R n).vars ⊆ range (n + 1) := by
rw [← map_wittPolynomial p (Int.castRingHom R), ← wittPolynomial_vars p ℤ]
apply vars_map
end PPrime
end
/-!
## Witt polynomials as a basis of the polynomial algebra
If `p` is invertible in `R`, then the Witt polynomials form a basis
of the polynomial algebra `MvPolynomial ℕ R`.
The polynomials `xInTermsOfW` give the coordinate transformation in the backwards direction.
-/
/-- The `xInTermsOfW p R n` is the polynomial on the basis of Witt polynomials
that corresponds to the ordinary `X n`. -/
noncomputable def xInTermsOfW [Invertible (p : R)] : ℕ → MvPolynomial ℕ R
| n => (X n - ∑ i : Fin n,
C ((p : R) ^ (i : ℕ)) * xInTermsOfW i ^ p ^ (n - (i : ℕ))) * C ((⅟p : R) ^ n)
theorem xInTermsOfW_eq [Invertible (p : R)] {n : ℕ} : xInTermsOfW p R n =
(X n - ∑ i ∈ range n, C ((p : R) ^ i) *
xInTermsOfW p R i ^ p ^ (n - i)) * C ((⅟p : R) ^ n) := by
rw [xInTermsOfW, ← Fin.sum_univ_eq_sum_range]
@[simp]
theorem constantCoeff_xInTermsOfW [hp : Fact p.Prime] [Invertible (p : R)] (n : ℕ) :
constantCoeff (xInTermsOfW p R n) = 0 := by
induction n using Nat.strongRecOn with | ind n IH => ?_
rw [xInTermsOfW_eq, mul_comm, RingHom.map_mul, RingHom.map_sub, map_sum, constantCoeff_C,
constantCoeff_X, zero_sub, mul_neg, neg_eq_zero, sum_eq_zero, mul_zero]
intro m H
rw [mem_range] at H
simp only [RingHom.map_mul, RingHom.map_pow, map_natCast, IH m H]
rw [zero_pow, mul_zero]
exact pow_ne_zero _ hp.1.ne_zero
@[simp]
theorem xInTermsOfW_zero [Invertible (p : R)] : xInTermsOfW p R 0 = X 0 := by
rw [xInTermsOfW_eq, range_zero, sum_empty, pow_zero, C_1, mul_one, sub_zero]
section PPrime
variable [hp : Fact p.Prime]
theorem xInTermsOfW_vars_aux (n : ℕ) :
n ∈ (xInTermsOfW p ℚ n).vars ∧ (xInTermsOfW p ℚ n).vars ⊆ range (n + 1) := by
induction n using Nat.strongRecOn with | ind n ih => ?_
rw [xInTermsOfW_eq, mul_comm, vars_C_mul _ (Invertible.ne_zero _),
vars_sub_of_disjoint, vars_X, range_add_one, insert_eq]
on_goal 1 =>
simp only [true_and, true_or, mem_union, mem_singleton]
intro i
rw [mem_union, mem_union]
apply Or.imp id
on_goal 2 => rw [vars_X, disjoint_singleton_left]
all_goals
intro H
replace H := vars_sum_subset _ _ H
rw [mem_biUnion] at H
rcases H with ⟨j, hj, H⟩
rw [vars_C_mul] at H
swap
· apply pow_ne_zero
exact mod_cast hp.1.ne_zero
rw [mem_range] at hj
replace H := (ih j hj).2 (vars_pow _ _ H)
rw [mem_range] at H
· rw [mem_range]
cutsat
· cutsat
theorem xInTermsOfW_vars_subset (n : ℕ) : (xInTermsOfW p ℚ n).vars ⊆ range (n + 1) :=
(xInTermsOfW_vars_aux p n).2
end PPrime
theorem xInTermsOfW_aux [Invertible (p : R)] (n : ℕ) :
xInTermsOfW p R n * C ((p : R) ^ n) =
X n - ∑ i ∈ range n, C ((p : R) ^ i) * xInTermsOfW p R i ^ p ^ (n - i) := by
rw [xInTermsOfW_eq, mul_assoc, ← C_mul, ← mul_pow, invOf_mul_self,
one_pow, C_1, mul_one]
@[simp]
theorem bind₁_xInTermsOfW_wittPolynomial [Invertible (p : R)] (k : ℕ) :
bind₁ (xInTermsOfW p R) (W_ R k) = X k := by
rw [wittPolynomial_eq_sum_C_mul_X_pow, map_sum]
simp only [map_pow, map_mul, algHom_C, algebraMap_eq]
rw [sum_range_succ_comm, tsub_self, pow_zero, pow_one, bind₁_X_right, mul_comm, ← C_pow,
xInTermsOfW_aux]
simp only [C_pow, bind₁_X_right, sub_add_cancel]
@[simp]
theorem bind₁_wittPolynomial_xInTermsOfW [Invertible (p : R)] (n : ℕ) :
bind₁ (W_ R) (xInTermsOfW p R n) = X n := by
induction n using Nat.strongRecOn with | ind n H => ?_
rw [xInTermsOfW_eq, map_mul, map_sub, bind₁_X_right, algHom_C, map_sum,
show X n = (X n * C ((p : R) ^ n)) * C ((⅟p : R) ^ n) by
rw [mul_assoc, ← C_mul, ← mul_pow, mul_invOf_self, one_pow, map_one, mul_one]]
congr 1
rw [wittPolynomial_eq_sum_C_mul_X_pow, sum_range_succ_comm,
tsub_self, pow_zero, pow_one, mul_comm (X n), add_sub_assoc, add_eq_left, sub_eq_zero]
apply sum_congr rfl
intro i h
rw [mem_range] at h
rw [map_mul, map_pow (bind₁ _), algHom_C, H i h, algebraMap_eq] |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/DiscreteValuationRing.lean | import Mathlib.RingTheory.WittVector.Domain
import Mathlib.RingTheory.WittVector.MulCoeff
import Mathlib.RingTheory.DiscreteValuationRing.Basic
import Mathlib.Tactic.LinearCombination
/-!
# Witt vectors over a perfect ring
This file establishes that Witt vectors over a perfect field are a discrete valuation ring.
When `k` is a perfect ring, a nonzero `a : 𝕎 k` can be written as `p^m * b` for some `m : ℕ` and
`b : 𝕎 k` with nonzero 0th coefficient.
When `k` is also a field, this `b` can be chosen to be a unit of `𝕎 k`.
## Main declarations
* `WittVector.exists_eq_pow_p_mul`: the existence of this element `b` over a perfect ring
* `WittVector.exists_eq_pow_p_mul'`: the existence of this unit `b` over a perfect field
* `WittVector.isDiscreteValuationRing`: `𝕎 k` is a discrete valuation ring if `k` is a perfect field
-/
noncomputable section
namespace WittVector
variable {p : ℕ} [hp : Fact p.Prime]
local notation "𝕎" => WittVector p
section CommRing
variable {k : Type*} [CommRing k] [CharP k p]
/-- This is the `n+1`st coefficient of our inverse. -/
def succNthValUnits (n : ℕ) (a : Units k) (A : 𝕎 k) (bs : Fin (n + 1) → k) : k :=
-↑(a⁻¹ ^ p ^ (n + 1)) *
(A.coeff (n + 1) * ↑(a⁻¹ ^ p ^ (n + 1)) + nthRemainder p n (truncateFun (n + 1) A) bs)
/--
Recursively defines the sequence of coefficients for the inverse to a Witt vector whose first entry
is a unit.
-/
noncomputable def inverseCoeff (a : Units k) (A : 𝕎 k) : ℕ → k
| 0 => ↑a⁻¹
| n + 1 => succNthValUnits n a A fun i => inverseCoeff a A i.val
/--
Upgrade a Witt vector `A` whose first entry `A.coeff 0` is a unit to be, itself, a unit in `𝕎 k`.
-/
def mkUnit {a : Units k} {A : 𝕎 k} (hA : A.coeff 0 = a) : Units (𝕎 k) :=
Units.mkOfMulEqOne A (@WittVector.mk' p _ (inverseCoeff a A)) (by
ext n
induction n with
| zero => simp [WittVector.mul_coeff_zero, inverseCoeff, hA]
| succ n => ?_
let H_coeff := A.coeff (n + 1) * ↑(a⁻¹ ^ p ^ (n + 1)) +
nthRemainder p n (truncateFun (n + 1) A) fun i : Fin (n + 1) => inverseCoeff a A i
have H := Units.mul_inv (a ^ p ^ (n + 1))
linear_combination (norm := skip) -H_coeff * H
have ha : (a : k) ^ p ^ (n + 1) = ↑(a ^ p ^ (n + 1)) := by norm_cast
have ha_inv : (↑a⁻¹ : k) ^ p ^ (n + 1) = ↑(a ^ p ^ (n + 1))⁻¹ := by norm_cast
simp only [nthRemainder_spec, inverseCoeff, succNthValUnits, hA,
one_coeff_eq_of_pos, Nat.succ_pos', ha_inv, ha, inv_pow]
ring!)
@[simp]
theorem coe_mkUnit {a : Units k} {A : 𝕎 k} (hA : A.coeff 0 = a) : (mkUnit hA : 𝕎 k) = A :=
rfl
end CommRing
section Field
variable {k : Type*} [Field k] [CharP k p]
theorem isUnit_of_coeff_zero_ne_zero (x : 𝕎 k) (hx : x.coeff 0 ≠ 0) : IsUnit x := by
let y : kˣ := Units.mk0 (x.coeff 0) hx
have hy : x.coeff 0 = y := rfl
exact (mkUnit hy).isUnit
variable (p)
theorem irreducible : Irreducible (p : 𝕎 k) := by
have hp : ¬IsUnit (p : 𝕎 k) := by
intro hp
simpa only [constantCoeff_apply, coeff_p_zero, not_isUnit_zero] using
(constantCoeff : WittVector p k →+* _).isUnit_map hp
refine ⟨hp, fun a b hab => ?_⟩
obtain ⟨ha0, hb0⟩ : a ≠ 0 ∧ b ≠ 0 := by
rw [← mul_ne_zero_iff]; intro h; rw [h] at hab; exact p_nonzero p k hab
obtain ⟨m, a, ha, rfl⟩ := verschiebung_nonzero ha0
obtain ⟨n, b, hb, rfl⟩ := verschiebung_nonzero hb0
cases m; · exact Or.inl (isUnit_of_coeff_zero_ne_zero a ha)
rcases n with - | n; · exact Or.inr (isUnit_of_coeff_zero_ne_zero b hb)
rw [iterate_verschiebung_mul] at hab
apply_fun fun x => coeff x 1 at hab
simp only [coeff_p_one, Nat.add_succ, add_comm _ n, Function.iterate_succ', Function.comp_apply,
verschiebung_coeff_add_one, verschiebung_coeff_zero] at hab
exact (one_ne_zero hab).elim
end Field
section PerfectRing
variable {k : Type*} [CommRing k] [CharP k p] [PerfectRing k p]
theorem exists_eq_pow_p_mul (a : 𝕎 k) (ha : a ≠ 0) :
∃ (m : ℕ) (b : 𝕎 k), b.coeff 0 ≠ 0 ∧ a = (p : 𝕎 k) ^ m * b := by
obtain ⟨m, c, hc, hcm⟩ := WittVector.verschiebung_nonzero ha
obtain ⟨b, rfl⟩ := (frobenius_bijective p k).surjective.iterate m c
rw [WittVector.iterate_frobenius_coeff] at hc
have := congr_fun (WittVector.verschiebung_frobenius_comm.comp_iterate m) b
simp only [Function.comp_apply] at this
rw [← this] at hcm
refine ⟨m, b, ?_, ?_⟩
· contrapose! hc
simp [hc, zero_pow <| pow_ne_zero _ hp.out.ne_zero]
· simp_rw [← mul_left_iterate (p : 𝕎 k) m]
convert hcm using 2
ext1 x
rw [mul_comm, ← WittVector.verschiebung_frobenius x]; rfl
end PerfectRing
section PerfectField
variable {k : Type*} [Field k] [CharP k p] [PerfectRing k p]
theorem exists_eq_pow_p_mul' (a : 𝕎 k) (ha : a ≠ 0) :
∃ (m : ℕ) (b : Units (𝕎 k)), a = (p : 𝕎 k) ^ m * b := by
obtain ⟨m, b, h₁, h₂⟩ := exists_eq_pow_p_mul a ha
let b₀ := Units.mk0 (b.coeff 0) h₁
have hb₀ : b.coeff 0 = b₀ := rfl
exact ⟨m, mkUnit hb₀, h₂⟩
/-- The ring of Witt Vectors of a perfect field of positive characteristic is a DVR.
-/
instance isDiscreteValuationRing : IsDiscreteValuationRing (𝕎 k) :=
IsDiscreteValuationRing.ofHasUnitMulPowIrreducibleFactorization (by
refine ⟨p, irreducible p, fun {x} hx => ?_⟩
obtain ⟨n, b, hb⟩ := exists_eq_pow_p_mul' x hx
exact ⟨n, b, hb.symm⟩)
end PerfectField
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/TeichmullerSeries.lean | import Mathlib.RingTheory.WittVector.Complete
import Mathlib.RingTheory.WittVector.Teichmuller
/-!
# Teichmuller Series
Let `R` be a characteristic `p` perfect ring. In this file, we show that
every element `x` of the Witt vectors `𝕎 R` can be written as the
(`p`-adic) summation of Teichmuller series, namely
`∑ i, (teichmuller p
(((frobeniusEquiv R p).symm ^ i) (x.coeff i)) * p ^ i)`
## Main theorems
* `WittVector.dvd_sub_sum_teichmuller_iterateFrobeniusEquiv_coeff` : `p ^ (n + 1)` divides
`x` minus the summation of the first `n + 1` terms of the Teichmuller series.
* `WittVector.eq_of_apply_teichmuller_eq` : Given a ring `S` such that `p` is nilpotent in `S`
and two ring maps `f g : 𝕎 R →+* S`, if they coincide on the teichmuller representatives,
then they are equal.
## TODO
Show that the Teichmuller series is unique.
-/
open Ideal Quotient
namespace WittVector
variable {p : ℕ} [hp : Fact (Nat.Prime p)]
local notation "𝕎" => WittVector p
variable {R : Type*} [CommRing R]
theorem sum_coeff_eq_coeff_sum {α : Type*} {S : Finset α} (x : α → 𝕎 R)
(h : ∀ (n : ℕ), Subsingleton {r | r ∈ S ∧ (x r).coeff n ≠ 0}) (n : ℕ) :
(∑ s ∈ S, x s).coeff n = ∑ (s ∈ S), (x s).coeff n := by
classical
induction S using Finset.induction generalizing n with
| empty =>
simp
| insert a S' ha hind =>
have : (∀ (n : ℕ), Subsingleton {r | r ∈ S' ∧ (x r).coeff n ≠ 0}) := by
refine fun n ↦ ⟨fun b c ↦ ?_⟩
ext
exact congrArg (fun x ↦ x.1) <|
(h n).allEq ⟨b.1, S'.subset_insert a b.2.1, b.2.2⟩ ⟨c.1, S'.subset_insert a c.2.1, c.2.2⟩
replace hind := hind this
simp only [ha, not_false_eq_true, Finset.sum_insert]
have : ∀ (n : ℕ), (x a).coeff n = 0 ∨ (∑ s ∈ S', x s).coeff n = 0 := by
simp only [hind]
by_contra! h
obtain ⟨m, hma, hmS'⟩ := h
have := Finset.sum_eq_zero.mt hmS'
push_neg at this
choose b hb hb' using this
have : a = b :=
congrArg (fun x ↦ x.1) <|
(h m).allEq ⟨a, S'.mem_insert_self a, hma⟩ ⟨b, S'.mem_insert_of_mem hb, hb'⟩
exact ha (this ▸ hb)
rw [coeff_add_of_disjoint n _ _ this, hind n]
variable [CharP R p]
@[simp]
theorem teichmuller_mul_pow_coeff (n : ℕ) (x : R) :
(teichmuller p x * p ^ n).coeff n = x ^ p ^ n := by
simpa using WittVector.mul_pow_charP_coeff_succ (teichmuller p x) (m := 0)
theorem teichmuller_mul_pow_coeff_of_ne (x : R)
{m n : ℕ} (h : m ≠ n) : (teichmuller p x * p ^ n).coeff m = 0 := by
cases Nat.lt_or_lt_of_ne h with
| inl h =>
exact WittVector.mul_pow_charP_coeff_zero (teichmuller p x) h
| inr h =>
rw [← Nat.sub_add_cancel h.le, WittVector.mul_pow_charP_coeff_succ (teichmuller p x),
WittVector.teichmuller_coeff_pos p x (m - n) (Nat.zero_lt_sub_of_lt h), zero_pow]
simp [Nat.Prime.ne_zero Fact.out]
variable [PerfectRing R p]
/--
`p ^ (n + 1)` divides
`x` minus the summation of the first `n + 1` terms of the Teichmuller series.
-/
theorem dvd_sub_sum_teichmuller_iterateFrobeniusEquiv_coeff (x : 𝕎 R) (n : ℕ) :
(p : 𝕎 R) ^ (n + 1) ∣ x - ∑ (i ≤ n), (teichmuller p
(((_root_.frobeniusEquiv R p).symm ^ i) (x.coeff i)) * p ^ i) := by
rw [← Ideal.mem_span_singleton, mem_span_p_pow_iff_le_coeff_eq_zero,
← le_coeff_eq_iff_le_sub_coeff_eq_zero]
intro i hi
rw [WittVector.sum_coeff_eq_coeff_sum]
· rw [Finset.sum_eq_add_sum_diff_singleton (Finset.mem_Iic.mpr (Nat.lt_succ_iff.mp hi))]
let g := fun x : ℕ ↦ (0 : R)
rw [Finset.sum_congr rfl (g := g)]
· simp [g]
· intro b hb
simp only [Finset.mem_sdiff, Finset.mem_Iic, Finset.mem_singleton] at hb
exact teichmuller_mul_pow_coeff_of_ne _ (Ne.intro hb.2).symm
· refine fun n ↦ ⟨fun ⟨a, _, ha⟩ ⟨b, _, hb⟩ ↦ ?_⟩
ext
dsimp only [ne_eq, Set.mem_setOf_eq]
rw [← Not.imp_symm (teichmuller_mul_pow_coeff_of_ne _) ha]
exact Not.imp_symm (teichmuller_mul_pow_coeff_of_ne _) hb
/--
Given a ring `S` such that `p` is nilpotent in `S`
and two ring maps `f g : 𝕎 R →+* S`, if they coincide on the teichmuller representatives,
then they are equal.
-/
theorem eq_of_apply_teichmuller_eq
{S : Type*} [CommRing S] (f g : 𝕎 R →+* S) (hp : IsNilpotent (p : S))
(h : ∀ (x : R), f (teichmuller p x) = g (teichmuller p x)) : f = g := by
obtain ⟨n, hn⟩ := hp
ext x
obtain ⟨c, hc⟩ := (dvd_sub_sum_teichmuller_iterateFrobeniusEquiv_coeff x n)
calc
f x = f (x - ∑ (i ≤ n), teichmuller p (((_root_.frobeniusEquiv R p).symm ^ i)
(x.coeff i)) * p ^ i) + f (∑ (i ≤ n), teichmuller p
(((_root_.frobeniusEquiv R p).symm ^ i) (x.coeff i)) * p ^ i) := by simp
_ = ∑ (i ≤ n), f (teichmuller p (((_root_.frobeniusEquiv R p).symm ^ i)
(x.coeff i))) * p ^ i := by rw [hc]; simp [pow_succ, hn]
_ = ∑ (i ≤ n), g (teichmuller p
(((_root_.frobeniusEquiv R p).symm ^ i) (x.coeff i))) * p ^ i := by simp [h]
_ = g (x - ∑ (i ≤ n), teichmuller p (((_root_.frobeniusEquiv R p).symm ^ i)
(x.coeff i)) * p ^ i) + g (∑ (i ≤ n), teichmuller p (((_root_.frobeniusEquiv R p).symm ^ i)
(x.coeff i)) * p ^ i) := by rw [hc]; simp [pow_succ, hn]
_ = g x := by simp
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/MulCoeff.lean | import Mathlib.Algebra.MvPolynomial.Supported
import Mathlib.RingTheory.WittVector.Truncated
/-!
# Leading terms of Witt vector multiplication
The goal of this file is to study the leading terms of the formula for the `n+1`st coefficient
of a product of Witt vectors `x` and `y` over a ring of characteristic `p`.
We aim to isolate the `n+1`st coefficients of `x` and `y`, and express the rest of the product
in terms of a function of the lower coefficients.
For most of this file we work with terms of type `MvPolynomial (Fin 2 × ℕ) ℤ`.
We will eventually evaluate them in `k`, but first we must take care of a calculation
that needs to happen in characteristic 0.
## Main declarations
* `WittVector.nth_mul_coeff`: expresses the coefficient of a product of Witt vectors
in terms of the previous coefficients of the multiplicands.
-/
noncomputable section
namespace WittVector
variable (p : ℕ) [hp : Fact p.Prime]
variable {k : Type*} [CommRing k]
local notation "𝕎" => WittVector p
local notation "𝕄" => MvPolynomial (Fin 2 × ℕ) ℤ
open Finset MvPolynomial
/--
```
(∑ i ∈ range n, (y.coeff i)^(p^(n-i)) * p^i.val) *
(∑ i ∈ range n, (y.coeff i)^(p^(n-i)) * p^i.val)
```
-/
def wittPolyProd (n : ℕ) : 𝕄 :=
rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ n) *
rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ n)
theorem wittPolyProd_vars (n : ℕ) : (wittPolyProd p n).vars ⊆ univ ×ˢ range (n + 1) := by
rw [wittPolyProd]
apply Subset.trans (vars_mul _ _)
refine union_subset ?_ ?_ <;>
· refine Subset.trans (vars_rename _ _) ?_
simp [wittPolynomial_vars, image_subset_iff]
/-- The "remainder term" of `WittVector.wittPolyProd`. See `mul_polyOfInterest_aux2`. -/
def wittPolyProdRemainder (n : ℕ) : 𝕄 :=
∑ i ∈ range n, (p : 𝕄) ^ i * wittMul p i ^ p ^ (n - i)
theorem wittPolyProdRemainder_vars (n : ℕ) :
(wittPolyProdRemainder p n).vars ⊆ univ ×ˢ range n := by
rw [wittPolyProdRemainder]
refine Subset.trans (vars_sum_subset _ _) ?_
rw [biUnion_subset]
intro x hx
apply Subset.trans (vars_mul _ _)
refine union_subset ?_ ?_
· apply Subset.trans (vars_pow _ _)
have : (p : 𝕄) = C (p : ℤ) := by simp only [Int.cast_natCast, eq_intCast]
rw [this, vars_C]
apply empty_subset
· apply Subset.trans (vars_pow _ _)
apply Subset.trans (wittMul_vars _ _)
apply product_subset_product (Subset.refl _)
simpa using hx
/-- `remainder p n` represents the remainder term from `mul_polyOfInterest_aux3`.
`wittPolyProd p (n+1)` will have variables up to `n+1`,
but `remainder` will only have variables up to `n`.
-/
def remainder (n : ℕ) : 𝕄 :=
(∑ x ∈ range (n + 1),
(rename (Prod.mk 0)) ((monomial (Finsupp.single x (p ^ (n + 1 - x)))) ((p : ℤ) ^ x))) *
∑ x ∈ range (n + 1),
(rename (Prod.mk 1)) ((monomial (Finsupp.single x (p ^ (n + 1 - x)))) ((p : ℤ) ^ x))
theorem remainder_vars (n : ℕ) : (remainder p n).vars ⊆ univ ×ˢ range (n + 1) := by
rw [remainder]
apply Subset.trans (vars_mul _ _)
refine union_subset ?_ ?_ <;>
· refine Subset.trans (vars_sum_subset _ _) ?_
rw [biUnion_subset]
intro x hx
rw [rename_monomial, vars_monomial, Finsupp.mapDomain_single]
· apply Subset.trans Finsupp.support_single_subset
simpa using mem_range.mp hx
· apply pow_ne_zero
exact mod_cast hp.out.ne_zero
/-- This is the polynomial whose degree we want to get a handle on. -/
def polyOfInterest (n : ℕ) : 𝕄 :=
wittMul p (n + 1) + (p : 𝕄) ^ (n + 1) * X (0, n + 1) * X (1, n + 1) -
X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) -
X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1))
theorem mul_polyOfInterest_aux1 (n : ℕ) :
∑ i ∈ range (n + 1), (p : 𝕄) ^ i * wittMul p i ^ p ^ (n - i) = wittPolyProd p n := by
simp only [wittPolyProd]
convert wittStructureInt_prop p (X (0 : Fin 2) * X 1) n using 1
· simp only [wittPolynomial, wittMul]
rw [map_sum]
congr 1 with i
congr 1
have hsupp : (Finsupp.single i (p ^ (n - i))).support = {i} := by
rw [Finsupp.support_eq_singleton]
simp only [and_true, Finsupp.single_eq_same, Ne]
exact pow_ne_zero _ hp.out.ne_zero
simp only [bind₁_monomial, hsupp, Int.cast_natCast, prod_singleton, eq_intCast,
Finsupp.single_eq_same, Int.cast_pow]
· simp only [map_mul, bind₁_X_right]
theorem mul_polyOfInterest_aux2 (n : ℕ) :
(p : 𝕄) ^ n * wittMul p n + wittPolyProdRemainder p n = wittPolyProd p n := by
convert mul_polyOfInterest_aux1 p n
rw [sum_range_succ, add_comm, Nat.sub_self, pow_zero, pow_one]
rfl
-- We redeclare `p` here to locally discard the unneeded `p.Prime` hypothesis.
theorem mul_polyOfInterest_aux3 (p n : ℕ) : wittPolyProd p (n + 1) =
-((p : 𝕄) ^ (n + 1) * X (0, n + 1)) * ((p : 𝕄) ^ (n + 1) * X (1, n + 1)) +
(p : 𝕄) ^ (n + 1) * X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) +
(p : 𝕄) ^ (n + 1) * X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) +
remainder p n := by
-- a useful auxiliary fact
have mvpz : (p : 𝕄) ^ (n + 1) = MvPolynomial.C ((p : ℤ) ^ (n + 1)) := by norm_cast
rw [wittPolyProd, wittPolynomial, map_sum, map_sum]
conv_lhs =>
arg 1
rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul,
rename_C, rename_X, ← mvpz]
conv_lhs =>
arg 2
rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul,
rename_C, rename_X, ← mvpz]
conv_rhs =>
enter [1, 1, 2, 2]
rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul,
rename_C, rename_X, ← mvpz]
conv_rhs =>
enter [1, 2, 2]
rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul,
rename_C, rename_X, ← mvpz]
simp only [add_mul, mul_add]
rw [add_comm _ (remainder p n)]
simp only [add_assoc]
apply congrArg (Add.add _)
ring
theorem mul_polyOfInterest_aux4 (n : ℕ) :
(p : 𝕄) ^ (n + 1) * wittMul p (n + 1) =
-((p : 𝕄) ^ (n + 1) * X (0, n + 1)) * ((p : 𝕄) ^ (n + 1) * X (1, n + 1)) +
(p : 𝕄) ^ (n + 1) * X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) +
(p : 𝕄) ^ (n + 1) * X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) +
(remainder p n - wittPolyProdRemainder p (n + 1)) := by
rw [← add_sub_assoc, eq_sub_iff_add_eq, mul_polyOfInterest_aux2]
exact mul_polyOfInterest_aux3 _ _
theorem mul_polyOfInterest_aux5 (n : ℕ) :
(p : 𝕄) ^ (n + 1) * polyOfInterest p n = remainder p n - wittPolyProdRemainder p (n + 1) := by
simp only [polyOfInterest, mul_sub, mul_add, sub_eq_iff_eq_add']
rw [mul_polyOfInterest_aux4 p n]
ring
theorem mul_polyOfInterest_vars (n : ℕ) :
((p : 𝕄) ^ (n + 1) * polyOfInterest p n).vars ⊆ univ ×ˢ range (n + 1) := by
rw [mul_polyOfInterest_aux5]
apply Subset.trans (vars_sub_subset _)
refine union_subset ?_ ?_
· apply remainder_vars
· apply wittPolyProdRemainder_vars
theorem polyOfInterest_vars_eq (n : ℕ) : (polyOfInterest p n).vars =
((p : 𝕄) ^ (n + 1) * (wittMul p (n + 1) + (p : 𝕄) ^ (n + 1) * X (0, n + 1) * X (1, n + 1) -
X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) -
X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)))).vars := by
have : (p : 𝕄) ^ (n + 1) = C ((p : ℤ) ^ (n + 1)) := by norm_cast
rw [polyOfInterest, this, vars_C_mul]
apply pow_ne_zero
exact mod_cast hp.out.ne_zero
theorem polyOfInterest_vars (n : ℕ) : (polyOfInterest p n).vars ⊆ univ ×ˢ range (n + 1) := by
rw [polyOfInterest_vars_eq]; apply mul_polyOfInterest_vars
theorem peval_polyOfInterest (n : ℕ) (x y : 𝕎 k) :
peval (polyOfInterest p n) ![fun i => x.coeff i, fun i => y.coeff i] =
(x * y).coeff (n + 1) + p ^ (n + 1) * x.coeff (n + 1) * y.coeff (n + 1) -
y.coeff (n + 1) * ∑ i ∈ range (n + 1 + 1), p ^ i * x.coeff i ^ p ^ (n + 1 - i) -
x.coeff (n + 1) * ∑ i ∈ range (n + 1 + 1), p ^ i * y.coeff i ^ p ^ (n + 1 - i) := by
simp only [polyOfInterest, peval,
Function.uncurry_apply_pair, aeval_X, Matrix.cons_val_one, map_mul, Matrix.cons_val_zero,
map_sub]
rw [sub_sub, add_comm (_ * _), ← sub_sub]
simp [wittPolynomial_eq_sum_C_mul_X_pow, aeval, mul_coeff, peval, map_natCast,
map_add, map_pow, map_mul]
variable [CharP k p]
/-- The characteristic `p` version of `peval_polyOfInterest` -/
theorem peval_polyOfInterest' (n : ℕ) (x y : 𝕎 k) :
peval (polyOfInterest p n) ![fun i => x.coeff i, fun i => y.coeff i] =
(x * y).coeff (n + 1) - y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) -
x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) := by
rw [peval_polyOfInterest]
have : (p : k) = 0 := CharP.cast_eq_zero k p
simp only [this, ne_eq, add_eq_zero, and_false, zero_pow, zero_mul, add_zero,
not_false_eq_true, reduceCtorEq]
have sum_zero_pow_mul_pow_p (y : 𝕎 k) : ∑ x ∈ range (n + 1 + 1),
(0 : k) ^ x * y.coeff x ^ p ^ (n + 1 - x) = y.coeff 0 ^ p ^ (n + 1) := by
rw [Finset.sum_eq_single_of_mem 0] <;> simp +contextual
congr <;> apply sum_zero_pow_mul_pow_p
variable (k)
theorem nth_mul_coeff' (n : ℕ) :
∃ f : TruncatedWittVector p (n + 1) k → TruncatedWittVector p (n + 1) k → k,
∀ x y : 𝕎 k, f (truncateFun (n + 1) x) (truncateFun (n + 1) y) =
(x * y).coeff (n + 1) - y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) -
x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) := by
simp only [← peval_polyOfInterest']
obtain ⟨f₀, hf₀⟩ := exists_restrict_to_vars k (polyOfInterest_vars p n)
have : ∀ (a : Multiset (Fin 2)) (b : Multiset ℕ), a ×ˢ b = a.product b := fun a b => rfl
let f : TruncatedWittVector p (n + 1) k → TruncatedWittVector p (n + 1) k → k := by
intro x y
apply f₀
rintro ⟨a, ha⟩
apply Function.uncurry ![x, y]
simp_rw [product_val, this, range_val, Multiset.range_succ] at ha
let S : Set (Fin 2 × ℕ) := (fun a => a.2 = n ∨ a.2 < n)
have ha' : a ∈ S := by
convert ha
dsimp [S]
congr!
simp
refine ⟨a.fst, ⟨a.snd, ?_⟩⟩
obtain ⟨ha, ha⟩ := ha' <;> omega
use f
intro x y
dsimp [f, peval]
rw [← hf₀]
congr
ext a
obtain ⟨a, ha⟩ := a
obtain ⟨i, m⟩ := a
fin_cases i <;> rfl -- surely this case split is not necessary
theorem nth_mul_coeff (n : ℕ) :
∃ f : TruncatedWittVector p (n + 1) k → TruncatedWittVector p (n + 1) k → k,
∀ x y : 𝕎 k, (x * y).coeff (n + 1) =
x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) + y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) +
f (truncateFun (n + 1) x) (truncateFun (n + 1) y) := by
obtain ⟨f, hf⟩ := nth_mul_coeff' p k n
use f
intro x y
rw [hf x y]
ring
variable {k}
/--
Produces the "remainder function" of the `n+1`st coefficient, which does not depend on the `n+1`st
coefficients of the inputs. -/
def nthRemainder (n : ℕ) : (Fin (n + 1) → k) → (Fin (n + 1) → k) → k :=
Classical.choose (nth_mul_coeff p k n)
theorem nthRemainder_spec (n : ℕ) (x y : 𝕎 k) : (x * y).coeff (n + 1) =
x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) + y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) +
nthRemainder p n (truncateFun (n + 1) x) (truncateFun (n + 1) y) :=
Classical.choose_spec (nth_mul_coeff p k n) _ _
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/Verschiebung.lean | import Mathlib.RingTheory.WittVector.Basic
import Mathlib.RingTheory.WittVector.IsPoly
/-!
## The Verschiebung operator
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
open MvPolynomial
variable {p : ℕ} {R S : Type*} [CommRing R] [CommRing S]
local notation "𝕎" => WittVector p -- type as `\bbW`
noncomputable section
/-- `verschiebungFun x` shifts the coefficients of `x` up by one,
by inserting 0 as the 0th coefficient.
`x.coeff i` then becomes `(verschiebungFun x).coeff (i + 1)`.
`verschiebungFun` is the underlying function of the additive monoid hom `WittVector.verschiebung`.
-/
def verschiebungFun (x : 𝕎 R) : 𝕎 R :=
@mk' p _ fun n => if n = 0 then 0 else x.coeff (n - 1)
theorem verschiebungFun_coeff (x : 𝕎 R) (n : ℕ) :
(verschiebungFun x).coeff n = if n = 0 then 0 else x.coeff (n - 1) := by
simp only [verschiebungFun]
theorem verschiebungFun_coeff_zero (x : 𝕎 R) : (verschiebungFun x).coeff 0 = 0 := by
rw [verschiebungFun_coeff, if_pos rfl]
@[simp]
theorem verschiebungFun_coeff_succ (x : 𝕎 R) (n : ℕ) :
(verschiebungFun x).coeff n.succ = x.coeff n :=
rfl
@[ghost_simps]
theorem ghostComponent_zero_verschiebungFun [hp : Fact p.Prime] (x : 𝕎 R) :
ghostComponent 0 (verschiebungFun x) = 0 := by
rw [ghostComponent_apply, aeval_wittPolynomial, Finset.range_one, Finset.sum_singleton,
verschiebungFun_coeff_zero, pow_zero, pow_zero, pow_one, one_mul]
@[ghost_simps]
theorem ghostComponent_verschiebungFun [hp : Fact p.Prime] (x : 𝕎 R) (n : ℕ) :
ghostComponent (n + 1) (verschiebungFun x) = p * ghostComponent n x := by
simp only [ghostComponent_apply, aeval_wittPolynomial]
rw [Finset.sum_range_succ', verschiebungFun_coeff, if_pos rfl,
zero_pow (pow_ne_zero _ hp.1.ne_zero), mul_zero, add_zero, Finset.mul_sum, Finset.sum_congr rfl]
rintro i -
simp only [pow_succ', verschiebungFun_coeff_succ, Nat.succ_sub_succ_eq_sub, mul_assoc]
/-- The 0th Verschiebung polynomial is 0. For `n > 0`, the `n`th Verschiebung polynomial is the
variable `X (n-1)`.
-/
def verschiebungPoly (n : ℕ) : MvPolynomial ℕ ℤ :=
if n = 0 then 0 else X (n - 1)
@[simp]
theorem verschiebungPoly_zero : verschiebungPoly 0 = 0 :=
rfl
theorem aeval_verschiebung_poly' (x : 𝕎 R) (n : ℕ) :
aeval x.coeff (verschiebungPoly n) = (verschiebungFun x).coeff n := by
rcases n with - | n
· simp only [verschiebungPoly, ite_true, map_zero, verschiebungFun_coeff_zero]
· rw [verschiebungPoly, verschiebungFun_coeff_succ, if_neg n.succ_ne_zero, aeval_X,
add_tsub_cancel_right]
variable (p)
/-- `WittVector.verschiebung` has polynomial structure given by `WittVector.verschiebungPoly`.
-/
instance verschiebungFun_isPoly : IsPoly p fun R _Rcr => @verschiebungFun p R _Rcr := by
use verschiebungPoly
simp only [aeval_verschiebung_poly', forall₃_true_iff]
-- We add this example as a verification that Lean 4's instance resolution can handle the `IsPoly`
-- typeclass, whereas Lean 3 needed a bespoke `@[is_poly]` attribute.
example (p : ℕ) (f : ⦃R : Type _⦄ → [CommRing R] → WittVector p R → WittVector p R) [IsPoly p f] :
IsPoly p (fun (R : Type*) (I : CommRing R) ↦ verschiebungFun ∘ (@f R I)) :=
inferInstance
variable {p}
variable [hp : Fact p.Prime]
/--
`verschiebung x` shifts the coefficients of `x` up by one, by inserting 0 as the 0th coefficient.
`x.coeff i` then becomes `(verschiebung x).coeff (i + 1)`.
This is an additive monoid hom with underlying function `verschiebung_fun`.
-/
noncomputable def verschiebung : 𝕎 R →+ 𝕎 R where
toFun := verschiebungFun
map_zero' := by
ext ⟨⟩ <;> rw [verschiebungFun_coeff] <;>
simp only [zero_coeff, ite_self]
map_add' := by
ghost_calc _ _
rintro ⟨⟩ <;> ghost_simp
/-- `WittVector.verschiebung` is a polynomial function. -/
@[is_poly]
theorem verschiebung_isPoly : IsPoly p fun _ _ => verschiebung (p := p) :=
verschiebungFun_isPoly p
/-- verschiebung is a natural transformation -/
@[simp]
theorem map_verschiebung (f : R →+* S) (x : 𝕎 R) :
map f (verschiebung x) = verschiebung (map f x) := by
ext ⟨-, -⟩
· exact f.map_zero
· rfl
@[ghost_simps]
theorem ghostComponent_zero_verschiebung (x : 𝕎 R) : ghostComponent 0 (verschiebung x) = 0 :=
ghostComponent_zero_verschiebungFun _
@[ghost_simps]
theorem ghostComponent_verschiebung (x : 𝕎 R) (n : ℕ) :
ghostComponent (n + 1) (verschiebung x) = p * ghostComponent n x :=
ghostComponent_verschiebungFun _ _
@[simp]
theorem verschiebung_coeff_zero (x : 𝕎 R) : (verschiebung x).coeff 0 = 0 :=
rfl
-- simp_nf complains if this is simp
theorem verschiebung_coeff_add_one (x : 𝕎 R) (n : ℕ) :
(verschiebung x).coeff (n + 1) = x.coeff n :=
rfl
@[simp]
theorem verschiebung_coeff_succ (x : 𝕎 R) (n : ℕ) : (verschiebung x).coeff n.succ = x.coeff n :=
rfl
variable (p R) in
theorem verschiebung_injective : Function.Injective (verschiebung : 𝕎 R → 𝕎 R) := by
rw [injective_iff_map_eq_zero]
intro w h
ext n
rw [← verschiebung_coeff_succ, h]
simp only [zero_coeff]
theorem aeval_verschiebungPoly (x : 𝕎 R) (n : ℕ) :
aeval x.coeff (verschiebungPoly n) = (verschiebung x).coeff n :=
aeval_verschiebung_poly' x n
@[simp]
theorem bind₁_verschiebungPoly_wittPolynomial (n : ℕ) :
bind₁ verschiebungPoly (wittPolynomial p ℤ n) =
if n = 0 then 0 else p * wittPolynomial p ℤ (n - 1) := by
apply MvPolynomial.funext
intro x
split_ifs with hn
· simp only [hn, wittPolynomial_zero, bind₁_X_right, verschiebungPoly_zero, map_zero]
· obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn
rw [Nat.succ_eq_add_one, add_tsub_cancel_right]
simp only [map_mul]
rw [map_natCast, hom_bind₁]
calc
_ = ghostComponent (n + 1) (verschiebung <| mk p x) := by
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
funext k
simp only [← aeval_verschiebungPoly]
exact eval₂Hom_congr (RingHom.ext_int _ _) rfl rfl
_ = _ := by rw [ghostComponent_verschiebung]; rfl
end
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/Basic.lean | import Mathlib.Algebra.MvPolynomial.Counit
import Mathlib.Algebra.MvPolynomial.Invertible
import Mathlib.RingTheory.WittVector.Defs
/-!
# Witt vectors
This file verifies that the ring operations on `WittVector p R`
satisfy the axioms of a commutative ring.
## Main definitions
* `WittVector.map`: lifts a ring homomorphism `R →+* S` to a ring homomorphism `𝕎 R →+* 𝕎 S`.
* `WittVector.ghostComponent n x`: evaluates the `n`th Witt polynomial
on the first `n` coefficients of `x`, producing a value in `R`.
This is a ring homomorphism.
* `WittVector.ghostMap`: a ring homomorphism `𝕎 R →+* (ℕ → R)`, obtained by packaging
all the ghost components together.
If `p` is invertible in `R`, then the ghost map is an equivalence,
which we use to define the ring operations on `𝕎 R`.
* `WittVector.CommRing`: the ring structure induced by the ghost components.
## Notation
We use notation `𝕎 R`, entered `\bbW`, for the Witt vectors over `R`.
## Implementation details
As we prove that the ghost components respect the ring operations, we face a number of repetitive
proofs. To avoid duplicating code we factor these proofs into a custom tactic, only slightly more
powerful than a tactic macro. This tactic is not particularly useful outside of its applications
in this file.
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
noncomputable section
open MvPolynomial Function
variable {p : ℕ} {R S : Type*} [CommRing R] [CommRing S]
variable {α : Type*} {β : Type*}
local notation "𝕎" => WittVector p
local notation "W_" => wittPolynomial p
-- type as `\bbW`
open scoped Witt
namespace WittVector
/-- `f : α → β` induces a map from `𝕎 α` to `𝕎 β` by applying `f` componentwise.
If `f` is a ring homomorphism, then so is `f`, see `WittVector.map f`. -/
def mapFun (f : α → β) : 𝕎 α → 𝕎 β := fun x => mk _ (f ∘ x.coeff)
namespace mapFun
theorem injective (f : α → β) (hf : Injective f) : Injective (mapFun f : 𝕎 α → 𝕎 β) :=
fun _ _ h => ext fun n => hf (congr_arg (fun x => coeff x n) h :)
theorem surjective (f : α → β) (hf : Surjective f) : Surjective (mapFun f : 𝕎 α → 𝕎 β) := fun x =>
⟨mk _ fun n => Classical.choose <| hf <| x.coeff n,
by ext n; simp only [mapFun, coeff_mk, comp_apply, Classical.choose_spec (hf (x.coeff n))]⟩
/-- Auxiliary tactic for showing that `mapFun` respects the ring operations. -/
macro "map_fun_tac" : tactic => `(tactic| (
-- TODO: the Lean 3 version of this tactic was more functional
ext n
simp only [mapFun, mk, comp_apply, zero_coeff, map_zero,
-- the lemmas on the next line do not have the `simp` tag in mathlib4
add_coeff, sub_coeff, mul_coeff, neg_coeff, nsmul_coeff, zsmul_coeff, pow_coeff,
peval, map_aeval, algebraMap_int_eq, coe_eval₂Hom] <;>
try { cases n <;> simp <;> done } <;> -- this line solves `one`
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl <;>
ext ⟨i, k⟩ <;>
fin_cases i <;> rfl))
variable [Fact p.Prime]
-- Porting note: using `(x y : 𝕎 R)` instead of `(x y : WittVector p R)` produced sorries.
variable (f : R →+* S) (x y : WittVector p R)
-- and until `pow`.
-- We do not tag these lemmas as `@[simp]` because they will be bundled in `map` later on.
theorem zero : mapFun f (0 : 𝕎 R) = 0 := by map_fun_tac
theorem one : mapFun f (1 : 𝕎 R) = 1 := by map_fun_tac
theorem add : mapFun f (x + y) = mapFun f x + mapFun f y := by map_fun_tac
theorem sub : mapFun f (x - y) = mapFun f x - mapFun f y := by map_fun_tac
theorem mul : mapFun f (x * y) = mapFun f x * mapFun f y := by map_fun_tac
theorem neg : mapFun f (-x) = -mapFun f x := by map_fun_tac
theorem nsmul (n : ℕ) (x : WittVector p R) : mapFun f (n • x) = n • mapFun f x := by map_fun_tac
theorem zsmul (z : ℤ) (x : WittVector p R) : mapFun f (z • x) = z • mapFun f x := by map_fun_tac
theorem pow (n : ℕ) : mapFun f (x ^ n) = mapFun f x ^ n := by map_fun_tac
theorem natCast (n : ℕ) : mapFun f (n : 𝕎 R) = n :=
show mapFun f n.unaryCast = (n : WittVector p S) by
induction n <;> simp [*, Nat.unaryCast, add, one, zero] <;> rfl
theorem intCast (n : ℤ) : mapFun f (n : 𝕎 R) = n :=
show mapFun f n.castDef = (n : WittVector p S) by
cases n <;> simp [*, Int.castDef, neg, natCast] <;> rfl
end mapFun
end WittVector
namespace WittVector
/-- Evaluates the `n`th Witt polynomial on the first `n` coefficients of `x`,
producing a value in `R`.
This function will be bundled as the ring homomorphism `WittVector.ghostMap`
once the ring structure is available,
but we rely on it to set up the ring structure in the first place. -/
private def ghostFun : 𝕎 R → ℕ → R := fun x n => aeval x.coeff (W_ ℤ n)
section Tactic
open Lean Elab Tactic
/-- An auxiliary tactic for proving that `ghostFun` respects the ring operations. -/
elab "ghost_fun_tac " φ:term ", " fn:term : tactic => do
evalTactic (← `(tactic| (
ext n
have := congr_fun (congr_arg (@peval R _ _) (wittStructureInt_prop p $φ n)) $fn
simp only [wittZero, OfNat.ofNat, Zero.zero, wittOne, One.one,
HAdd.hAdd, Add.add, HSub.hSub, Sub.sub, Neg.neg, HMul.hMul, Mul.mul, HPow.hPow, Pow.pow,
wittNSMul, wittZSMul, HSMul.hSMul, SMul.smul]
simpa +unfoldPartialApp [WittVector.ghostFun, aeval_rename, aeval_bind₁,
comp, uncurry, peval, eval] using this
)))
end Tactic
section GhostFun
-- The following lemmas are not `@[simp]` because they will be bundled in `ghostMap` later on.
@[local simp]
theorem matrix_vecEmpty_coeff {R} (i j) :
@coeff p R (Matrix.vecEmpty i) j = (Matrix.vecEmpty i : ℕ → R) j := by
rcases i with ⟨_ | _ | _ | _ | i_val, ⟨⟩⟩
variable [Fact p.Prime]
variable (x y : WittVector p R)
private theorem ghostFun_zero : ghostFun (0 : 𝕎 R) = 0 := by
ghost_fun_tac 0, ![]
private theorem ghostFun_one : ghostFun (1 : 𝕎 R) = 1 := by
ghost_fun_tac 1, ![]
private theorem ghostFun_add : ghostFun (x + y) = ghostFun x + ghostFun y := by
ghost_fun_tac X 0 + X 1, ![x.coeff, y.coeff]
private theorem ghostFun_natCast (i : ℕ) : ghostFun (i : 𝕎 R) = i :=
show ghostFun i.unaryCast = _ by
induction i <;> simp [*, Nat.unaryCast, ghostFun_zero, ghostFun_one, ghostFun_add]
private theorem ghostFun_sub : ghostFun (x - y) = ghostFun x - ghostFun y := by
ghost_fun_tac X 0 - X 1, ![x.coeff, y.coeff]
private theorem ghostFun_mul : ghostFun (x * y) = ghostFun x * ghostFun y := by
ghost_fun_tac X 0 * X 1, ![x.coeff, y.coeff]
private theorem ghostFun_neg : ghostFun (-x) = -ghostFun x := by ghost_fun_tac -X 0, ![x.coeff]
private theorem ghostFun_intCast (i : ℤ) : ghostFun (i : 𝕎 R) = i :=
show ghostFun i.castDef = _ by
cases i <;> simp [*, Int.castDef, ghostFun_natCast, ghostFun_neg]
private lemma ghostFun_nsmul (m : ℕ) (x : WittVector p R) : ghostFun (m • x) = m • ghostFun x := by
ghost_fun_tac m • (X 0), ![x.coeff]
private lemma ghostFun_zsmul (m : ℤ) (x : WittVector p R) : ghostFun (m • x) = m • ghostFun x := by
ghost_fun_tac m • (X 0), ![x.coeff]
private theorem ghostFun_pow (m : ℕ) : ghostFun (x ^ m) = ghostFun x ^ m := by
ghost_fun_tac X 0 ^ m, ![x.coeff]
end GhostFun
variable (p) (R)
/-- The bijection between `𝕎 R` and `ℕ → R`, under the assumption that `p` is invertible in `R`.
In `WittVector.ghostEquiv` we upgrade this to an isomorphism of rings. -/
private def ghostEquiv' [Invertible (p : R)] : 𝕎 R ≃ (ℕ → R) where
toFun := ghostFun
invFun x := mk p fun n => aeval x (xInTermsOfW p R n)
left_inv := by
intro x
ext n
have := bind₁_wittPolynomial_xInTermsOfW p R n
apply_fun aeval x.coeff at this
simpa +unfoldPartialApp only [aeval_bind₁, aeval_X, ghostFun,
aeval_wittPolynomial]
right_inv := by
intro x
ext n
have := bind₁_xInTermsOfW_wittPolynomial p R n
apply_fun aeval x at this
simpa only [aeval_bind₁, aeval_X, ghostFun, aeval_wittPolynomial]
variable [Fact p.Prime]
@[local instance]
private def comm_ring_aux₁ : CommRing (𝕎 (MvPolynomial R ℚ)) :=
(ghostEquiv' p (MvPolynomial R ℚ)).injective.commRing ghostFun ghostFun_zero ghostFun_one
ghostFun_add ghostFun_mul ghostFun_neg ghostFun_sub ghostFun_nsmul ghostFun_zsmul
ghostFun_pow ghostFun_natCast ghostFun_intCast
@[local instance]
private abbrev comm_ring_aux₂ : CommRing (𝕎 (MvPolynomial R ℤ)) :=
(mapFun.injective _ <| map_injective (Int.castRingHom ℚ) Int.cast_injective).commRing _
(mapFun.zero _) (mapFun.one _) (mapFun.add _) (mapFun.mul _) (mapFun.neg _) (mapFun.sub _)
(mapFun.nsmul _) (mapFun.zsmul _) (mapFun.pow _) (mapFun.natCast _) (mapFun.intCast _)
/-- The commutative ring structure on `𝕎 R`. -/
instance : CommRing (𝕎 R) :=
(mapFun.surjective _ <| counit_surjective _).commRing (mapFun <| MvPolynomial.counit _)
(mapFun.zero _) (mapFun.one _) (mapFun.add _) (mapFun.mul _) (mapFun.neg _) (mapFun.sub _)
(mapFun.nsmul _) (mapFun.zsmul _) (mapFun.pow _) (mapFun.natCast _) (mapFun.intCast _)
variable {p R}
/-- `WittVector.map f` is the ring homomorphism `𝕎 R →+* 𝕎 S` naturally induced
by a ring homomorphism `f : R →+* S`. It acts coefficientwise. -/
noncomputable def map (f : R →+* S) : 𝕎 R →+* 𝕎 S where
toFun := mapFun f
map_zero' := mapFun.zero f
map_one' := mapFun.one f
map_add' := mapFun.add f
map_mul' := mapFun.mul f
theorem map_injective (f : R →+* S) (hf : Injective f) : Injective (map f : 𝕎 R → 𝕎 S) :=
mapFun.injective f hf
theorem map_surjective (f : R →+* S) (hf : Surjective f) : Surjective (map f : 𝕎 R → 𝕎 S) :=
mapFun.surjective f hf
@[simp]
theorem map_coeff (f : R →+* S) (x : 𝕎 R) (n : ℕ) : (map f x).coeff n = f (x.coeff n) :=
rfl
variable (R) in
@[simp]
theorem map_id : WittVector.map (RingHom.id R) = RingHom.id (𝕎 R) := by
ext; simp
theorem map_eq_zero_iff (f : R →+* S) {x : WittVector p R} :
((map f) x) = 0 ↔ ∀ n, f (x.coeff n) = 0 := by
refine ⟨fun h n ↦ ?_, fun h ↦ ?_⟩
· apply_fun (·.coeff n) at h
simpa using h
· ext n
simpa using h n
/-- `WittVector.ghostMap` is a ring homomorphism that maps each Witt vector
to the sequence of its ghost components. -/
def ghostMap : 𝕎 R →+* ℕ → R where
toFun := ghostFun
map_zero' := ghostFun_zero
map_one' := ghostFun_one
map_add' := ghostFun_add
map_mul' := ghostFun_mul
/-- Evaluates the `n`th Witt polynomial on the first `n` coefficients of `x`,
producing a value in `R`. -/
def ghostComponent (n : ℕ) : 𝕎 R →+* R :=
(Pi.evalRingHom _ n).comp ghostMap
theorem ghostComponent_apply (n : ℕ) (x : 𝕎 R) : ghostComponent n x = aeval x.coeff (W_ ℤ n) :=
rfl
theorem pow_dvd_ghostComponent_of_dvd_coeff {x : 𝕎 R} {n : ℕ}
(hx : ∀ i ≤ n, (p : R) ∣ x.coeff i) : (p : R) ^ (n + 1) ∣ ghostComponent n x := by
rw [WittVector.ghostComponent_apply, wittPolynomial, MvPolynomial.aeval_sum]
apply Finset.dvd_sum
intro i hi
simp only [Finset.mem_range] at hi
have : (MvPolynomial.aeval x.coeff) ((MvPolynomial.monomial (R := ℤ)
(Finsupp.single i (p ^ (n - i)))) (p ^ i)) = ((p : R) ^ i) * (x.coeff i) ^ (p ^ (n - i)) := by
simp [MvPolynomial.aeval_monomial, map_pow]
rw [this, show n + 1 = (n - i) + 1 + i by omega, pow_add, mul_comm]
apply mul_dvd_mul_left
refine (pow_dvd_pow_of_dvd ?_ _).trans (pow_dvd_pow _ ?_)
· exact hx i (Nat.le_of_lt_succ hi)
· exact ((n - i).lt_two_pow_self).succ_le.trans
(pow_left_mono (n - i) (Nat.Prime.two_le Fact.out))
@[simp]
theorem ghostMap_apply (x : 𝕎 R) (n : ℕ) : ghostMap x n = ghostComponent n x :=
rfl
section Invertible
variable (p R)
variable [Invertible (p : R)]
/-- `WittVector.ghostMap` is a ring isomorphism when `p` is invertible in `R`. -/
def ghostEquiv : 𝕎 R ≃+* (ℕ → R) :=
{ (ghostMap : 𝕎 R →+* ℕ → R), ghostEquiv' p R with }
@[simp]
theorem ghostEquiv_coe : (ghostEquiv p R : 𝕎 R →+* ℕ → R) = ghostMap :=
rfl
theorem ghostMap.bijective_of_invertible : Function.Bijective (ghostMap : 𝕎 R → ℕ → R) :=
(ghostEquiv p R).bijective
end Invertible
/-- `WittVector.coeff x 0` as a `RingHom` -/
@[simps]
noncomputable def constantCoeff : 𝕎 R →+* R where
toFun x := x.coeff 0
map_zero' := by simp
map_one' := by simp
map_add' := add_coeff_zero
map_mul' := mul_coeff_zero
instance [Nontrivial R] : Nontrivial (𝕎 R) :=
constantCoeff.domain_nontrivial
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/Frobenius.lean | import Mathlib.Algebra.Algebra.ZMod
import Mathlib.Data.Nat.Multiplicity
import Mathlib.FieldTheory.Perfect
import Mathlib.RingTheory.WittVector.Basic
import Mathlib.RingTheory.WittVector.IsPoly
/-!
## The Frobenius operator
If `R` has characteristic `p`, then there is a ring endomorphism `frobenius R p`
that raises `r : R` to the power `p`.
By applying `WittVector.map` to `frobenius R p`, we obtain a ring endomorphism `𝕎 R →+* 𝕎 R`.
It turns out that this endomorphism can be described by polynomials over `ℤ`
that do not depend on `R` or the fact that it has characteristic `p`.
In this way, we obtain a Frobenius endomorphism `WittVector.frobeniusFun : 𝕎 R → 𝕎 R`
for every commutative ring `R`.
Unfortunately, the aforementioned polynomials cannot be obtained using the machinery
of `wittStructureInt` that was developed in `StructurePolynomial.lean`.
We therefore have to define the polynomials by hand, and check that they have the required property.
In case `R` has characteristic `p`, we show in `frobenius_eq_map_frobenius`
that `WittVector.frobeniusFun` is equal to `WittVector.map (frobenius R p)`.
### Main definitions and results
* `frobeniusPoly`: the polynomials that describe the coefficients of `frobeniusFun`;
* `frobeniusFun`: the Frobenius endomorphism on Witt vectors;
* `frobeniusFun_isPoly`: the tautological assertion that Frobenius is a polynomial function;
* `frobenius_eq_map_frobenius`: the fact that in characteristic `p`, Frobenius is equal to
`WittVector.map (frobenius R p)`.
TODO: Show that `WittVector.frobeniusFun` is a ring homomorphism,
and bundle it into `WittVector.frobenius`.
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
variable {p : ℕ} {R : Type*} [hp : Fact p.Prime] [CommRing R]
local notation "𝕎" => WittVector p -- type as `\bbW`
noncomputable section
open MvPolynomial Finset
variable (p)
/-- The rational polynomials that give the coefficients of `frobenius x`,
in terms of the coefficients of `x`.
These polynomials actually have integral coefficients,
see `frobeniusPoly` and `map_frobeniusPoly`. -/
def frobeniusPolyRat (n : ℕ) : MvPolynomial ℕ ℚ :=
bind₁ (wittPolynomial p ℚ ∘ fun n => n + 1) (xInTermsOfW p ℚ n)
theorem bind₁_frobeniusPolyRat_wittPolynomial (n : ℕ) :
bind₁ (frobeniusPolyRat p) (wittPolynomial p ℚ n) = wittPolynomial p ℚ (n + 1) := by
delta frobeniusPolyRat
rw [← bind₁_bind₁, bind₁_xInTermsOfW_wittPolynomial, bind₁_X_right, Function.comp_apply]
local notation "v" => multiplicity
/-- An auxiliary polynomial over the integers, that satisfies
`p * (frobeniusPolyAux p n) + X n ^ p = frobeniusPoly p n`.
This makes it easy to show that `frobeniusPoly p n` is congruent to `X n ^ p`
modulo `p`. -/
noncomputable def frobeniusPolyAux : ℕ → MvPolynomial ℕ ℤ
| n => X (n + 1) - ∑ i : Fin n, have _ := i.is_lt
∑ j ∈ range (p ^ (n - i)),
(((X (i : ℕ) ^ p) ^ (p ^ (n - (i : ℕ)) - (j + 1)) : MvPolynomial ℕ ℤ) *
(frobeniusPolyAux i) ^ (j + 1)) *
C (((p ^ (n - i)).choose (j + 1) / (p ^ (n - i - v p (j + 1)))
* ↑p ^ (j - v p (j + 1)) : ℕ) : ℤ)
omit hp in
theorem frobeniusPolyAux_eq (n : ℕ) :
frobeniusPolyAux p n =
X (n + 1) - ∑ i ∈ range n,
∑ j ∈ range (p ^ (n - i)),
(X i ^ p) ^ (p ^ (n - i) - (j + 1)) * frobeniusPolyAux p i ^ (j + 1) *
C ↑((p ^ (n - i)).choose (j + 1) / p ^ (n - i - v p (j + 1)) *
↑p ^ (j - v p (j + 1)) : ℕ) := by
rw [frobeniusPolyAux, ← Fin.sum_univ_eq_sum_range]
/-- The polynomials that give the coefficients of `frobenius x`,
in terms of the coefficients of `x`. -/
def frobeniusPoly (n : ℕ) : MvPolynomial ℕ ℤ :=
X n ^ p + C (p : ℤ) * frobeniusPolyAux p n
/-
Our next goal is to prove
```
lemma map_frobeniusPoly (n : ℕ) :
MvPolynomial.map (Int.castRingHom ℚ) (frobeniusPoly p n) = frobeniusPolyRat p n
```
This lemma has a rather long proof, but it mostly boils down to applying induction,
and then using the following two key facts at the right point.
-/
/-- A key divisibility fact for the proof of `WittVector.map_frobeniusPoly`. -/
theorem map_frobeniusPoly.key₁ (n j : ℕ) (hj : j < p ^ n) :
p ^ (n - v p (j + 1)) ∣ (p ^ n).choose (j + 1) := by
apply pow_dvd_of_le_emultiplicity
rw [hp.out.emultiplicity_choose_prime_pow hj j.succ_ne_zero]
/-- A key numerical identity needed for the proof of `WittVector.map_frobeniusPoly`. -/
theorem map_frobeniusPoly.key₂ {n i j : ℕ} (hi : i ≤ n) (hj : j < p ^ (n - i)) :
j - v p (j + 1) + n = i + j + (n - i - v p (j + 1)) := by
generalize h : v p (j + 1) = m
rsuffices ⟨h₁, h₂⟩ : m ≤ n - i ∧ m ≤ j
· rw [tsub_add_eq_add_tsub h₂, add_comm i j, add_tsub_assoc_of_le (h₁.trans (Nat.sub_le n i)),
add_assoc, tsub_right_comm, add_comm i,
tsub_add_cancel_of_le (le_tsub_of_add_le_right ((le_tsub_iff_left hi).mp h₁))]
have hle : p ^ m ≤ j + 1 := h ▸ Nat.le_of_dvd j.succ_pos (pow_multiplicity_dvd _ _)
exact ⟨(Nat.pow_le_pow_iff_right hp.1.one_lt).1 (hle.trans hj),
Nat.le_of_lt_succ ((m.lt_pow_self hp.1.one_lt).trans_le hle)⟩
theorem map_frobeniusPoly (n : ℕ) :
MvPolynomial.map (Int.castRingHom ℚ) (frobeniusPoly p n) = frobeniusPolyRat p n := by
rw [frobeniusPoly, RingHom.map_add, RingHom.map_mul, RingHom.map_pow, map_C, map_X, eq_intCast,
Int.cast_natCast, frobeniusPolyRat]
refine Nat.strong_induction_on n ?_; clear n
intro n IH
rw [xInTermsOfW_eq]
simp only [map_sum, map_sub, map_mul, map_pow (bind₁ _), bind₁_C_right]
have h1 : (p : ℚ) ^ n * ⅟(p : ℚ) ^ n = 1 := by rw [← mul_pow, mul_invOf_self, one_pow]
rw [bind₁_X_right, Function.comp_apply, wittPolynomial_eq_sum_C_mul_X_pow, sum_range_succ,
sum_range_succ, tsub_self, add_tsub_cancel_left, pow_zero, pow_one, pow_one, sub_mul, add_mul,
add_mul, mul_right_comm, mul_right_comm (C ((p : ℚ) ^ (n + 1))), ← C_mul, ← C_mul, pow_succ',
mul_assoc (p : ℚ) ((p : ℚ) ^ n), h1, mul_one, C_1, one_mul, add_comm _ (X n ^ p), add_assoc,
← add_sub, add_right_inj, frobeniusPolyAux_eq, RingHom.map_sub, map_X, mul_sub, sub_eq_add_neg,
add_comm _ (C (p : ℚ) * X (n + 1)), ← add_sub,
add_right_inj, neg_eq_iff_eq_neg, neg_sub, eq_comm]
simp only [map_sum, mul_sum, sum_mul, ← sum_sub_distrib]
apply sum_congr rfl
intro i hi
rw [mem_range] at hi
rw [← IH i hi]
clear IH
rw [add_comm (X i ^ p), add_pow, sum_range_succ', pow_zero, tsub_zero, Nat.choose_zero_right,
one_mul, Nat.cast_one, mul_one, mul_add, add_mul, Nat.succ_sub (le_of_lt hi),
Nat.succ_eq_add_one (n - i), pow_succ', pow_mul, add_sub_cancel_right, mul_sum, sum_mul]
apply sum_congr rfl
intro j hj
rw [mem_range] at hj
rw [RingHom.map_mul, RingHom.map_mul, RingHom.map_pow, RingHom.map_pow, RingHom.map_pow,
RingHom.map_pow, RingHom.map_pow, map_C, map_X, mul_pow]
rw [mul_comm (C (p : ℚ) ^ i), mul_comm _ ((X i ^ p) ^ _), mul_comm (C (p : ℚ) ^ (j + 1)),
mul_comm (C (p : ℚ))]
simp only [mul_assoc]
apply congr_arg
apply congr_arg
rw [← C_eq_coe_nat]
simp only [← RingHom.map_pow, ← C_mul]
rw [C_inj]
simp only [invOf_eq_inv, eq_intCast, inv_pow, Int.cast_natCast, Nat.cast_mul, Int.cast_mul]
rw [Rat.natCast_div _ _ (map_frobeniusPoly.key₁ p (n - i) j hj)]
push_cast
linear_combination (norm := skip) -p / p ^ n / p ^ (n - i - v p (j + 1))
* (p ^ (n - i)).choose (j + 1) * congr((p : ℚ) ^ $(map_frobeniusPoly.key₂ p hi.le hj))
field [hp.1.ne_zero]
theorem frobeniusPoly_zmod (n : ℕ) :
MvPolynomial.map (Int.castRingHom (ZMod p)) (frobeniusPoly p n) = X n ^ p := by
rw [frobeniusPoly, RingHom.map_add, RingHom.map_pow, RingHom.map_mul, map_X, map_C]
simp only [Int.cast_natCast, add_zero, eq_intCast, ZMod.natCast_self, zero_mul, C_0]
@[simp]
theorem bind₁_frobeniusPoly_wittPolynomial (n : ℕ) :
bind₁ (frobeniusPoly p) (wittPolynomial p ℤ n) = wittPolynomial p ℤ (n + 1) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [map_bind₁, map_frobeniusPoly, bind₁_frobeniusPolyRat_wittPolynomial,
map_wittPolynomial]
variable {p}
/-- `frobeniusFun` is the function underlying the ring endomorphism
`frobenius : 𝕎 R →+* frobenius 𝕎 R`. -/
def frobeniusFun (x : 𝕎 R) : 𝕎 R :=
mk p fun n => MvPolynomial.aeval x.coeff (frobeniusPoly p n)
omit hp in
theorem coeff_frobeniusFun (x : 𝕎 R) (n : ℕ) :
coeff (frobeniusFun x) n = MvPolynomial.aeval x.coeff (frobeniusPoly p n) := by
rw [frobeniusFun, coeff_mk]
variable (p) in
/-- `frobeniusFun` is tautologically a polynomial function.
See also `frobenius_isPoly`. -/
instance frobeniusFun_isPoly : IsPoly p fun R _ Rcr => @frobeniusFun p R _ Rcr :=
⟨⟨frobeniusPoly p, by intros; funext n; apply coeff_frobeniusFun⟩⟩
@[ghost_simps]
theorem ghostComponent_frobeniusFun (n : ℕ) (x : 𝕎 R) :
ghostComponent n (frobeniusFun x) = ghostComponent (n + 1) x := by
simp only [ghostComponent_apply, frobeniusFun, coeff_mk, ← bind₁_frobeniusPoly_wittPolynomial,
aeval_bind₁]
/-- If `R` has characteristic `p`, then there is a ring endomorphism
that raises `r : R` to the power `p`.
By applying `WittVector.map` to this endomorphism,
we obtain a ring endomorphism `frobenius R p : 𝕎 R →+* 𝕎 R`.
The underlying function of this morphism is `WittVector.frobeniusFun`.
-/
def frobenius : 𝕎 R →+* 𝕎 R where
toFun := frobeniusFun
map_zero' := by
refine IsPoly.ext (IsPoly.comp (hg := frobeniusFun_isPoly p) (hf := WittVector.zeroIsPoly))
(IsPoly.comp (hg := WittVector.zeroIsPoly) (hf := frobeniusFun_isPoly p))
?_ _ 0
simp only [Function.comp_apply, map_zero, forall_const]
ghost_simp
map_one' := by
refine
IsPoly.ext (IsPoly.comp (hg := frobeniusFun_isPoly p) (hf := WittVector.oneIsPoly))
(IsPoly.comp (hg := WittVector.oneIsPoly) (hf := frobeniusFun_isPoly p)) ?_ _ 0
simp only [Function.comp_apply, map_one, forall_const]
ghost_simp
map_add' := by ghost_calc _ _; ghost_simp
map_mul' := by ghost_calc _ _; ghost_simp
theorem coeff_frobenius (x : 𝕎 R) (n : ℕ) :
coeff (frobenius x) n = MvPolynomial.aeval x.coeff (frobeniusPoly p n) :=
coeff_frobeniusFun _ _
@[ghost_simps]
theorem ghostComponent_frobenius (n : ℕ) (x : 𝕎 R) :
ghostComponent n (frobenius x) = ghostComponent (n + 1) x :=
ghostComponent_frobeniusFun _ _
variable (p)
/-- `frobenius` is tautologically a polynomial function. -/
instance frobenius_isPoly : IsPoly p fun R _Rcr => @frobenius p R _ _Rcr :=
frobeniusFun_isPoly _
section CharP
variable [CharP R p]
@[simp]
theorem coeff_frobenius_charP (x : 𝕎 R) (n : ℕ) : coeff (frobenius x) n = x.coeff n ^ p := by
rw [coeff_frobenius]
letI : Algebra (ZMod p) R := ZMod.algebra _ _
-- outline of the calculation, proofs follow below
calc
aeval (fun k => x.coeff k) (frobeniusPoly p n) =
aeval (fun k => x.coeff k)
(MvPolynomial.map (Int.castRingHom (ZMod p)) (frobeniusPoly p n)) := ?_
_ = aeval (fun k => x.coeff k) (X n ^ p : MvPolynomial ℕ (ZMod p)) := ?_
_ = x.coeff n ^ p := ?_
· conv_rhs => rw [aeval_eq_eval₂Hom, eval₂Hom_map_hom]
apply eval₂Hom_congr (RingHom.ext_int _ _) rfl rfl
· rw [frobeniusPoly_zmod]
· rw [map_pow, aeval_X]
theorem frobenius_eq_map_frobenius : @frobenius p R _ _ = map (_root_.frobenius R p) := by
ext (x n)
simp only [coeff_frobenius_charP, map_coeff, frobenius_def]
@[simp]
theorem frobenius_zmodp (x : 𝕎 (ZMod p)) : frobenius x = x := by
simp only [WittVector.ext_iff, coeff_frobenius_charP, ZMod.pow_card,
forall_const]
variable (R)
/-- `WittVector.frobenius` as an equiv. -/
@[simps -fullyApplied]
def frobeniusEquiv [PerfectRing R p] : WittVector p R ≃+* WittVector p R :=
{ (WittVector.frobenius : WittVector p R →+* WittVector p R) with
toFun := WittVector.frobenius
invFun := map (_root_.frobeniusEquiv R p).symm
left_inv := fun f => ext fun n => by
rw [frobenius_eq_map_frobenius]
exact frobeniusEquiv_symm_apply_frobenius R p _
right_inv := fun f => ext fun n => by
rw [frobenius_eq_map_frobenius]
exact frobenius_apply_frobeniusEquiv_symm R p _ }
theorem frobenius_bijective [PerfectRing R p] :
Function.Bijective (@WittVector.frobenius p R _ _) :=
(frobeniusEquiv p R).bijective
end CharP
end
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/Compare.lean | import Mathlib.RingTheory.WittVector.Truncated
import Mathlib.RingTheory.WittVector.Identities
import Mathlib.NumberTheory.Padics.RingHoms
/-!
# Comparison isomorphism between `WittVector p (ZMod p)` and `ℤ_[p]`
We construct a ring isomorphism between `WittVector p (ZMod p)` and `ℤ_[p]`.
This isomorphism follows from the fact that both satisfy the universal property
of the inverse limit of `ZMod (p^n)`.
## Main declarations
* `WittVector.toZModPow`: a family of compatible ring homs `𝕎 (ZMod p) → ZMod (p^k)`
* `WittVector.equiv`: the isomorphism
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
noncomputable section
variable {p : ℕ} [hp : Fact p.Prime]
local notation "𝕎" => WittVector p
namespace TruncatedWittVector
variable (p) (n : ℕ) (R : Type*) [CommRing R]
theorem eq_of_le_of_cast_pow_eq_zero [CharP R p] (i : ℕ) (hin : i ≤ n)
(hpi : (p : TruncatedWittVector p n R) ^ i = 0) : i = n := by
contrapose! hpi
replace hin := lt_of_le_of_ne hin hpi; clear hpi
have : (p : TruncatedWittVector p n R) ^ i = WittVector.truncate n ((p : 𝕎 R) ^ i) := by
rw [RingHom.map_pow, map_natCast]
rw [this, ne_eq, TruncatedWittVector.ext_iff, not_forall]; clear this
use ⟨i, hin⟩
rw [WittVector.coeff_truncate, coeff_zero, Fin.val_mk, WittVector.coeff_p_pow]
haveI : Nontrivial R := CharP.nontrivial_of_char_ne_one hp.1.ne_one
exact one_ne_zero
section Iso
variable {R}
theorem card_zmod : Fintype.card (TruncatedWittVector p n (ZMod p)) = p ^ n := by
rw [card, ZMod.card]
theorem charP_zmod : CharP (TruncatedWittVector p n (ZMod p)) (p ^ n) :=
charP_of_prime_pow_injective _ _ _ (card_zmod _ _) (eq_of_le_of_cast_pow_eq_zero p n (ZMod p))
attribute [local instance] charP_zmod
/-- The unique isomorphism between `ZMod p^n` and `TruncatedWittVector p n (ZMod p)`.
This isomorphism exists, because `TruncatedWittVector p n (ZMod p)` is a finite ring
with characteristic and cardinality `p^n`.
-/
def zmodEquivTrunc : ZMod (p ^ n) ≃+* TruncatedWittVector p n (ZMod p) :=
ZMod.ringEquiv (TruncatedWittVector p n (ZMod p)) (card_zmod _ _)
theorem zmodEquivTrunc_apply {x : ZMod (p ^ n)} :
zmodEquivTrunc p n x =
ZMod.castHom (m := p ^ n) (by rfl) (TruncatedWittVector p n (ZMod p)) x :=
rfl
/-- The following diagram commutes:
```text
ZMod (p^n) ----------------------------> ZMod (p^m)
| |
| |
v v
TruncatedWittVector p n (ZMod p) ----> TruncatedWittVector p m (ZMod p)
```
Here the vertical arrows are `TruncatedWittVector.zmodEquivTrunc`,
the horizontal arrow at the top is `ZMod.castHom`,
and the horizontal arrow at the bottom is `TruncatedWittVector.truncate`.
-/
theorem commutes {m : ℕ} (hm : n ≤ m) :
(truncate hm).comp (zmodEquivTrunc p m).toRingHom =
(zmodEquivTrunc p n).toRingHom.comp (ZMod.castHom (pow_dvd_pow p hm) _) :=
RingHom.ext_zmod _ _
theorem commutes' {m : ℕ} (hm : n ≤ m) (x : ZMod (p ^ m)) :
truncate hm (zmodEquivTrunc p m x) = zmodEquivTrunc p n (ZMod.castHom (pow_dvd_pow p hm) _ x) :=
show (truncate hm).comp (zmodEquivTrunc p m).toRingHom x = _ by rw [commutes _ _ hm]; rfl
theorem commutes_symm' {m : ℕ} (hm : n ≤ m) (x : TruncatedWittVector p m (ZMod p)) :
(zmodEquivTrunc p n).symm (truncate hm x) =
ZMod.castHom (pow_dvd_pow p hm) _ ((zmodEquivTrunc p m).symm x) := by
apply (zmodEquivTrunc p n).injective
rw [← commutes' _ _ hm]
simp
/-- The following diagram commutes:
```text
TruncatedWittVector p n (ZMod p) ----> TruncatedWittVector p m (ZMod p)
| |
| |
v v
ZMod (p^n) ----------------------------> ZMod (p^m)
```
Here the vertical arrows are `(TruncatedWittVector.zmodEquivTrunc p _).symm`,
the horizontal arrow at the top is `ZMod.castHom`,
and the horizontal arrow at the bottom is `TruncatedWittVector.truncate`.
-/
theorem commutes_symm {m : ℕ} (hm : n ≤ m) :
(zmodEquivTrunc p n).symm.toRingHom.comp (truncate hm) =
(ZMod.castHom (pow_dvd_pow p hm) _).comp (zmodEquivTrunc p m).symm.toRingHom := by
ext; apply commutes_symm'
end Iso
end TruncatedWittVector
namespace WittVector
open TruncatedWittVector
variable (p)
/-- `toZModPow` is a family of compatible ring homs. We get this family by composing
`TruncatedWittVector.zmodEquivTrunc` (in right-to-left direction) with `WittVector.truncate`. -/
def toZModPow (k : ℕ) : 𝕎 (ZMod p) →+* ZMod (p ^ k) :=
(zmodEquivTrunc p k).symm.toRingHom.comp (truncate k)
theorem toZModPow_compat (m n : ℕ) (h : m ≤ n) :
(ZMod.castHom (pow_dvd_pow p h) (ZMod (p ^ m))).comp (toZModPow p n) = toZModPow p m :=
calc
(ZMod.castHom _ (ZMod (p ^ m))).comp ((zmodEquivTrunc p n).symm.toRingHom.comp (truncate n))
_ = ((zmodEquivTrunc p m).symm.toRingHom.comp (TruncatedWittVector.truncate h)).comp
(truncate n) := by
rw [commutes_symm, RingHom.comp_assoc]
_ = (zmodEquivTrunc p m).symm.toRingHom.comp (truncate m) := by
rw [RingHom.comp_assoc, truncate_comp_wittVector_truncate]
/-- `toPadicInt` lifts `toZModPow : 𝕎 (ZMod p) →+* ZMod (p ^ k)` to a ring hom to `ℤ_[p]`
using `PadicInt.lift`, the universal property of `ℤ_[p]`.
-/
def toPadicInt : 𝕎 (ZMod p) →+* ℤ_[p] :=
PadicInt.lift <| toZModPow_compat p
theorem zmodEquivTrunc_compat (k₁ k₂ : ℕ) (hk : k₁ ≤ k₂) :
(TruncatedWittVector.truncate hk).comp
((zmodEquivTrunc p k₂).toRingHom.comp (PadicInt.toZModPow k₂)) =
(zmodEquivTrunc p k₁).toRingHom.comp (PadicInt.toZModPow k₁) := by
rw [← RingHom.comp_assoc, commutes, RingHom.comp_assoc,
PadicInt.zmod_cast_comp_toZModPow _ _ hk]
/-- `fromPadicInt` uses `WittVector.lift` to lift `TruncatedWittVector.zmodEquivTrunc`
composed with `PadicInt.toZModPow` to a ring hom `ℤ_[p] →+* 𝕎 (ZMod p)`.
-/
def fromPadicInt : ℤ_[p] →+* 𝕎 (ZMod p) :=
(WittVector.lift fun k => (zmodEquivTrunc p k).toRingHom.comp (PadicInt.toZModPow k)) <|
zmodEquivTrunc_compat _
theorem toPadicInt_comp_fromPadicInt : (toPadicInt p).comp (fromPadicInt p) = RingHom.id ℤ_[p] := by
rw [← PadicInt.toZModPow_eq_iff_ext]
intro n
rw [← RingHom.comp_assoc, toPadicInt, PadicInt.lift_spec]
simp only [fromPadicInt, toZModPow, RingHom.comp_id]
rw [RingHom.comp_assoc, truncate_comp_lift, ← RingHom.comp_assoc]
simp only [RingEquiv.symm_toRingHom_comp_toRingHom, RingHom.id_comp]
theorem toPadicInt_comp_fromPadicInt_ext (x) :
(toPadicInt p).comp (fromPadicInt p) x = RingHom.id ℤ_[p] x := by
rw [toPadicInt_comp_fromPadicInt]
theorem fromPadicInt_comp_toPadicInt :
(fromPadicInt p).comp (toPadicInt p) = RingHom.id (𝕎 (ZMod p)) := by
apply WittVector.hom_ext
intro n
rw [fromPadicInt, ← RingHom.comp_assoc, truncate_comp_lift, RingHom.comp_assoc]
simp only [toPadicInt, toZModPow, RingHom.comp_id, PadicInt.lift_spec, RingHom.id_comp, ←
RingHom.comp_assoc, RingEquiv.toRingHom_comp_symm_toRingHom]
theorem fromPadicInt_comp_toPadicInt_ext (x) :
(fromPadicInt p).comp (toPadicInt p) x = RingHom.id (𝕎 (ZMod p)) x := by
rw [fromPadicInt_comp_toPadicInt]
/-- The ring of Witt vectors over `ZMod p` is isomorphic to the ring of `p`-adic integers. This
equivalence is witnessed by `WittVector.toPadicInt` with inverse `WittVector.fromPadicInt`.
-/
def equiv : 𝕎 (ZMod p) ≃+* ℤ_[p] where
toFun := toPadicInt p
invFun := fromPadicInt p
left_inv := fromPadicInt_comp_toPadicInt_ext _
right_inv := toPadicInt_comp_fromPadicInt_ext _
map_mul' := RingHom.map_mul _
map_add' := RingHom.map_add _
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/InitTail.lean | import Mathlib.RingTheory.WittVector.Basic
import Mathlib.RingTheory.WittVector.IsPoly
/-!
# `init` and `tail`
Given a Witt vector `x`, we are sometimes interested
in its components before and after an index `n`.
This file defines those operations, proves that `init` is polynomial,
and shows how that polynomial interacts with `MvPolynomial.bind₁`.
## Main declarations
* `WittVector.init n x`: the first `n` coefficients of `x`, as a Witt vector. All coefficients at
indices ≥ `n` are 0.
* `WittVector.tail n x`: the complementary part to `init`. All coefficients at indices < `n` are 0,
otherwise they are the same as in `x`.
* `WittVector.coeff_add_of_disjoint`: if `x` and `y` are Witt vectors such that for every `n`
the `n`-th coefficient of `x` or of `y` is `0`, then the coefficients of `x + y`
are just `x.coeff n + y.coeff n`.
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
variable {p : ℕ} (n : ℕ) {R : Type*} [CommRing R]
-- type as `\bbW`
local notation "𝕎" => WittVector p
namespace WittVector
open MvPolynomial
noncomputable section
section
open scoped Classical in
/-- `WittVector.select P x`, for a predicate `P : ℕ → Prop` is the Witt vector
whose `n`-th coefficient is `x.coeff n` if `P n` is true, and `0` otherwise.
-/
def select (P : ℕ → Prop) (x : 𝕎 R) : 𝕎 R :=
mk p fun n => if P n then x.coeff n else 0
section Select
variable (P : ℕ → Prop)
open scoped Classical in
/-- The polynomial that witnesses that `WittVector.select` is a polynomial function.
`selectPoly n` is `X n` if `P n` holds, and `0` otherwise. -/
def selectPoly (n : ℕ) : MvPolynomial ℕ ℤ :=
if P n then X n else 0
theorem coeff_select (x : 𝕎 R) (n : ℕ) :
(select P x).coeff n = aeval x.coeff (selectPoly P n) := by
dsimp [select, selectPoly]
split_ifs with hi <;> simp
instance select_isPoly {P : ℕ → Prop} : IsPoly p fun _ _ x => select P x := by
use selectPoly P
rintro R _Rcr x
funext i
apply coeff_select
variable [hp : Fact p.Prime]
theorem select_add_select_not : ∀ x : 𝕎 R, select P x + select (fun i => ¬P i) x = x := by
-- Porting note: TC search was insufficient to find this instance, even though all required
-- instances exist. See zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/WittVector.20saga/near/370073526]
have : IsPoly p fun {R} [CommRing R] x ↦ select P x + select (fun i ↦ ¬P i) x :=
IsPoly₂.diag (hf := IsPoly₂.comp)
ghost_calc x
intro n
simp only [RingHom.map_add]
suffices
(bind₁ (selectPoly P)) (wittPolynomial p ℤ n) +
(bind₁ (selectPoly fun i => ¬P i)) (wittPolynomial p ℤ n) =
wittPolynomial p ℤ n by
apply_fun aeval x.coeff at this
simpa only [map_add, aeval_bind₁, ← coeff_select]
simp only [wittPolynomial_eq_sum_C_mul_X_pow, selectPoly, map_sum, map_pow, map_mul,
bind₁_X_right, bind₁_C_right, ← Finset.sum_add_distrib, ← mul_add]
apply Finset.sum_congr rfl
refine fun m _ => mul_eq_mul_left_iff.mpr (Or.inl ?_)
rw [ite_pow, zero_pow (pow_ne_zero _ hp.out.ne_zero)]
by_cases Pm : P m
· rw [if_pos Pm, if_neg <| not_not_intro Pm, zero_pow Fin.pos'.ne', add_zero]
· rwa [if_neg Pm, if_pos, zero_add]
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
(x + y).coeff n = x.coeff n + y.coeff n := by
let P : ℕ → Prop := fun n => y.coeff n = 0
haveI : DecidablePred P := Classical.decPred P
set z := mk p fun n => if P n then x.coeff n else y.coeff n
have hx : select P z = x := by
ext1 n; rw [select, coeff_mk, coeff_mk]
split_ifs with hn
· rfl
· rw [(h n).resolve_right hn]
have hy : select (fun i => ¬P i) z = y := by
ext1 n; rw [select, coeff_mk, coeff_mk]
split_ifs with hn
· exact hn.symm
· rfl
calc
(x + y).coeff n = z.coeff n := by rw [← hx, ← hy, select_add_select_not P z]
_ = x.coeff n + y.coeff n := by
simp only [z, mk.eq_1]
split_ifs with y0
· rw [y0, add_zero]
· rw [h n |>.resolve_right y0, zero_add]
end Select
variable [Fact p.Prime]
/-- `WittVector.init n x` is the Witt vector of which the first `n` coefficients are those from `x`
and all other coefficients are `0`.
See `WittVector.tail` for the complementary part.
-/
def init (n : ℕ) : 𝕎 R → 𝕎 R :=
select fun i => i < n
/-- `WittVector.tail n x` is the Witt vector of which the first `n` coefficients are `0`
and all other coefficients are those from `x`.
See `WittVector.init` for the complementary part. -/
def tail (n : ℕ) : 𝕎 R → 𝕎 R :=
select fun i => n ≤ i
@[simp]
theorem init_add_tail (x : 𝕎 R) (n : ℕ) : init n x + tail n x = x := by
simp only [init, tail, ← not_lt, select_add_select_not]
end
/--
`init_ring` is an auxiliary tactic that discharges goals factoring `init` over ring operations.
-/
syntax (name := initRing) "init_ring" (" using " term)? : tactic
-- Porting note: this tactic requires that we turn hygiene off (note the free `n`).
-- TODO: make this tactic hygienic.
open Lean Elab Tactic in
elab_rules : tactic
| `(tactic| init_ring $[ using $a:term]?) => withMainContext <| set_option hygiene false in do
evalTactic <|← `(tactic|(
rw [WittVector.ext_iff]
intro i
simp only [WittVector.init, WittVector.select, WittVector.coeff_mk]
split_ifs with hi <;> try {rfl}
))
if let some e := a then
evalTactic <|← `(tactic|(
simp only [WittVector.add_coeff, WittVector.mul_coeff, WittVector.neg_coeff,
WittVector.sub_coeff, WittVector.nsmul_coeff, WittVector.zsmul_coeff, WittVector.pow_coeff]
apply MvPolynomial.eval₂Hom_congr' (RingHom.ext_int _ _) _ rfl
rintro ⟨b, k⟩ h -
replace h := $e:term p _ h
simp only [Finset.mem_range, Finset.mem_product, true_and, Finset.mem_univ] at h
have hk : k < n := by omega
fin_cases b <;> simp only [Function.uncurry, Matrix.cons_val_zero, Matrix.head_cons,
WittVector.coeff_mk, Matrix.cons_val_one, WittVector.mk, Fin.mk_zero, Matrix.cons_val',
Matrix.empty_val', Matrix.cons_val_fin_one, Matrix.cons_val_zero,
hk, if_true]
))
@[simp]
theorem init_init (x : 𝕎 R) (n : ℕ) : init n (init n x) = init n x := by
init_ring
section
variable [Fact p.Prime]
theorem init_add (x y : 𝕎 R) (n : ℕ) : init n (x + y) = init n (init n x + init n y) := by
init_ring using wittAdd_vars
theorem init_mul (x y : 𝕎 R) (n : ℕ) : init n (x * y) = init n (init n x * init n y) := by
init_ring using wittMul_vars
theorem init_neg (x : 𝕎 R) (n : ℕ) : init n (-x) = init n (-init n x) := by
init_ring using wittNeg_vars
theorem init_sub (x y : 𝕎 R) (n : ℕ) : init n (x - y) = init n (init n x - init n y) := by
init_ring using wittSub_vars
theorem init_nsmul (m : ℕ) (x : 𝕎 R) (n : ℕ) : init n (m • x) = init n (m • init n x) := by
init_ring using fun p [Fact (Nat.Prime p)] n => wittNSMul_vars p m n
theorem init_zsmul (m : ℤ) (x : 𝕎 R) (n : ℕ) : init n (m • x) = init n (m • init n x) := by
init_ring using fun p [Fact (Nat.Prime p)] n => wittZSMul_vars p m n
theorem init_pow (m : ℕ) (x : 𝕎 R) (n : ℕ) : init n (x ^ m) = init n (init n x ^ m) := by
init_ring using fun p [Fact (Nat.Prime p)] n => wittPow_vars p m n
end
section
variable (p)
/-- `WittVector.init n x` is polynomial in the coefficients of `x`. -/
theorem init_isPoly (n : ℕ) : IsPoly p fun _ _ => init n :=
select_isPoly (P := fun i => i < n)
end
end
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/Domain.lean | import Mathlib.RingTheory.WittVector.Identities
/-!
# Witt vectors over a domain
This file builds to the proof `WittVector.instIsDomain`,
an instance that says if `R` is an integral domain, then so is `𝕎 R`.
It depends on the API around iterated applications
of `WittVector.verschiebung` and `WittVector.frobenius`
found in `Identities.lean`.
The [proof sketch](https://math.stackexchange.com/questions/4117247/ring-of-witt-vectors-over-an-integral-domain/4118723#4118723)
goes as follows:
any nonzero $x$ is an iterated application of $V$
to some vector $w_x$ whose 0th component is nonzero (`WittVector.verschiebung_nonzero`).
Known identities (`WittVector.iterate_verschiebung_mul`) allow us to transform
the product of two such $x$ and $y$
to the form $V^{m+n}\left(F^n(w_x) \cdot F^m(w_y)\right)$,
the 0th component of which must be nonzero.
## Main declarations
* `WittVector.iterate_verschiebung_mul_coeff` : an identity from [Haze09]
* `WittVector.instIsDomain`
-/
noncomputable section
namespace WittVector
open Function
variable {p : ℕ} {R : Type*}
local notation "𝕎" => WittVector p -- type as `\bbW`
/-!
## The `shift` operator
-/
/--
`WittVector.verschiebung` translates the entries of a Witt vector upward, inserting 0s in the gaps.
`WittVector.shift` does the opposite, removing the first entries.
This is mainly useful as an auxiliary construction for `WittVector.verschiebung_nonzero`.
-/
def shift (x : 𝕎 R) (n : ℕ) : 𝕎 R :=
@mk' p R fun i => x.coeff (n + i)
theorem shift_coeff (x : 𝕎 R) (n k : ℕ) : (x.shift n).coeff k = x.coeff (n + k) :=
rfl
variable [hp : Fact p.Prime] [CommRing R]
theorem verschiebung_shift (x : 𝕎 R) (k : ℕ) (h : ∀ i < k + 1, x.coeff i = 0) :
verschiebung (x.shift k.succ) = x.shift k := by
ext ⟨j⟩
· rw [verschiebung_coeff_zero, shift_coeff, h]
apply Nat.lt_succ_self
· simp only [verschiebung_coeff_succ, shift]
congr 1
rw [Nat.add_succ, add_comm, Nat.add_succ, add_comm]
theorem eq_iterate_verschiebung {x : 𝕎 R} {n : ℕ} (h : ∀ i < n, x.coeff i = 0) :
x = verschiebung^[n] (x.shift n) := by
induction n with
| zero => cases x; simp [shift]
| succ k ih =>
dsimp; rw [verschiebung_shift]
· exact ih fun i hi => h _ (hi.trans (Nat.lt_succ_self _))
· exact h
theorem verschiebung_nonzero {x : 𝕎 R} (hx : x ≠ 0) :
∃ n : ℕ, ∃ x' : 𝕎 R, x'.coeff 0 ≠ 0 ∧ x = verschiebung^[n] x' := by
classical
have hex : ∃ k : ℕ, x.coeff k ≠ 0 := by
by_contra! hall
apply hx
ext i
simp only [hall, zero_coeff]
let n := Nat.find hex
use n, x.shift n
refine ⟨Nat.find_spec hex, eq_iterate_verschiebung fun i hi => not_not.mp ?_⟩
exact Nat.find_min hex hi
/-!
## Witt vectors over a domain
If `R` is an integral domain, then so is `𝕎 R`.
This argument is adapted from
<https://math.stackexchange.com/questions/4117247/ring-of-witt-vectors-over-an-integral-domain/4118723#4118723>.
-/
instance [CharP R p] [NoZeroDivisors R] : NoZeroDivisors (𝕎 R) :=
⟨fun {x y} => by
contrapose!
rintro ⟨ha, hb⟩
rcases verschiebung_nonzero ha with ⟨na, wa, hwa0, rfl⟩
rcases verschiebung_nonzero hb with ⟨nb, wb, hwb0, rfl⟩
refine ne_of_apply_ne (fun x => x.coeff (na + nb)) ?_
dsimp only
rw [iterate_verschiebung_mul_coeff, zero_coeff]
exact mul_ne_zero (pow_ne_zero _ hwa0) (pow_ne_zero _ hwb0)⟩
instance instIsDomain [CharP R p] [IsDomain R] : IsDomain (𝕎 R) :=
NoZeroDivisors.to_isDomain _
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/Defs.lean | import Mathlib.RingTheory.WittVector.StructurePolynomial
/-!
# Witt vectors
In this file we define the type of `p`-typical Witt vectors and ring operations on it.
The ring axioms are verified in `Mathlib/RingTheory/WittVector/Basic.lean`.
For a fixed commutative ring `R` and prime `p`,
a Witt vector `x : 𝕎 R` is an infinite sequence `ℕ → R` of elements of `R`.
However, the ring operations `+` and `*` are not defined in the obvious component-wise way.
Instead, these operations are defined via certain polynomials
using the machinery in `Mathlib/RingTheory/WittVector/StructurePolynomial.lean`.
The `n`th value of the sum of two Witt vectors can depend on the `0`-th through `n`th values
of the summands. This effectively simulates a “carrying” operation.
## Main definitions
* `WittVector p R`: the type of `p`-typical Witt vectors with coefficients in `R`.
* `WittVector.coeff x n`: projects the `n`th value of the Witt vector `x`.
## Notation
We use notation `𝕎 R`, entered `\bbW`, for the Witt vectors over `R`.
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
noncomputable section
/-- `WittVector p R` is the ring of `p`-typical Witt vectors over the commutative ring `R`,
where `p` is a prime number.
If `p` is invertible in `R`, this ring is isomorphic to `ℕ → R` (the product of `ℕ` copies of `R`).
If `R` is a ring of characteristic `p`, then `WittVector p R` is a ring of characteristic `0`.
The canonical example is `WittVector p (ZMod p)`,
which is isomorphic to the `p`-adic integers `ℤ_[p]`. -/
structure WittVector (p : ℕ) (R : Type*) where mk' ::
/-- `x.coeff n` is the `n`th coefficient of the Witt vector `x`.
This concept does not have a standard name in the literature.
-/
coeff : ℕ → R
/-- Construct a Witt vector `mk p x : 𝕎 R` from a sequence `x` of elements of `R`.
This is preferred over `WittVector.mk'` because it has `p` explicit.
-/
def WittVector.mk (p : ℕ) {R : Type*} (coeff : ℕ → R) : WittVector p R := mk' coeff
variable {p : ℕ}
/- We cannot make this `localized` notation, because the `p` on the RHS doesn't occur on the left
Hiding the `p` in the notation is very convenient, so we opt for repeating the `local notation`
in other files that use Witt vectors. -/
local notation "𝕎" => WittVector p -- type as `\bbW`
namespace WittVector
variable {R : Type*}
@[ext]
theorem ext {x y : 𝕎 R} (h : ∀ n, x.coeff n = y.coeff n) : x = y := by
cases x
cases y
simp only at h
simp [funext_iff, h]
variable (p)
@[simp]
theorem coeff_mk (x : ℕ → R) : (mk p x).coeff = x :=
rfl
/- These instances are not needed for the rest of the development,
but it is interesting to establish early on that `WittVector p` is a lawful functor. -/
instance : Functor (WittVector p) where
map f v := mk p (f ∘ v.coeff)
mapConst a _ := mk p fun _ => a
instance : LawfulFunctor (WittVector p) where
map_const := rfl
id_map _ := rfl
comp_map _ _ _ := rfl
variable [hp : Fact p.Prime] [CommRing R]
open MvPolynomial
section RingOperations
/-- The polynomials used for defining the element `0` of the ring of Witt vectors. -/
def wittZero : ℕ → MvPolynomial (Fin 0 × ℕ) ℤ :=
wittStructureInt p 0
/-- The polynomials used for defining the element `1` of the ring of Witt vectors. -/
def wittOne : ℕ → MvPolynomial (Fin 0 × ℕ) ℤ :=
wittStructureInt p 1
/-- The polynomials used for defining the addition of the ring of Witt vectors. -/
def wittAdd : ℕ → MvPolynomial (Fin 2 × ℕ) ℤ :=
wittStructureInt p (X 0 + X 1)
/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/
def wittNSMul (n : ℕ) : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ :=
wittStructureInt p (n • X (0 : (Fin 1)))
/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/
def wittZSMul (n : ℤ) : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ :=
wittStructureInt p (n • X (0 : (Fin 1)))
/-- The polynomials used for describing the subtraction of the ring of Witt vectors. -/
def wittSub : ℕ → MvPolynomial (Fin 2 × ℕ) ℤ :=
wittStructureInt p (X 0 - X 1)
/-- The polynomials used for defining the multiplication of the ring of Witt vectors. -/
def wittMul : ℕ → MvPolynomial (Fin 2 × ℕ) ℤ :=
wittStructureInt p (X 0 * X 1)
/-- The polynomials used for defining the negation of the ring of Witt vectors. -/
def wittNeg : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ :=
wittStructureInt p (-X 0)
/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/
def wittPow (n : ℕ) : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ :=
wittStructureInt p (X 0 ^ n)
variable {p}
/-- An auxiliary definition used in `WittVector.eval`.
Evaluates a polynomial whose variables come from the disjoint union of `k` copies of `ℕ`,
with a curried evaluation `x`.
This can be defined more generally but we use only a specific instance here. -/
def peval {k : ℕ} (φ : MvPolynomial (Fin k × ℕ) ℤ) (x : Fin k → ℕ → R) : R :=
aeval (Function.uncurry x) φ
/-- Let `φ` be a family of polynomials, indexed by natural numbers, whose variables come from the
disjoint union of `k` copies of `ℕ`, and let `xᵢ` be a Witt vector for `0 ≤ i < k`.
`eval φ x` evaluates `φ` mapping the variable `X_(i, n)` to the `n`th coefficient of `xᵢ`.
Instantiating `φ` with certain polynomials defined in
`Mathlib/RingTheory/WittVector/StructurePolynomial.lean` establishes the
ring operations on `𝕎 R`. For example, `WittVector.wittAdd` is such a `φ` with `k = 2`;
evaluating this at `(x₀, x₁)` gives us the sum of two Witt vectors `x₀ + x₁`.
-/
def eval {k : ℕ} (φ : ℕ → MvPolynomial (Fin k × ℕ) ℤ) (x : Fin k → 𝕎 R) : 𝕎 R :=
mk p fun n => peval (φ n) fun i => (x i).coeff
instance : Zero (𝕎 R) :=
⟨eval (wittZero p) ![]⟩
instance : Inhabited (𝕎 R) :=
⟨0⟩
instance : One (𝕎 R) :=
⟨eval (wittOne p) ![]⟩
instance : Add (𝕎 R) :=
⟨fun x y => eval (wittAdd p) ![x, y]⟩
instance : Sub (𝕎 R) :=
⟨fun x y => eval (wittSub p) ![x, y]⟩
instance hasNatScalar : SMul ℕ (𝕎 R) :=
⟨fun n x => eval (wittNSMul p n) ![x]⟩
instance hasIntScalar : SMul ℤ (𝕎 R) :=
⟨fun n x => eval (wittZSMul p n) ![x]⟩
instance : Mul (𝕎 R) :=
⟨fun x y => eval (wittMul p) ![x, y]⟩
instance : Neg (𝕎 R) :=
⟨fun x => eval (wittNeg p) ![x]⟩
instance hasNatPow : Pow (𝕎 R) ℕ :=
⟨fun x n => eval (wittPow p n) ![x]⟩
instance : NatCast (𝕎 R) :=
⟨Nat.unaryCast⟩
instance : IntCast (𝕎 R) :=
⟨Int.castDef⟩
end RingOperations
section WittStructureSimplifications
@[simp]
theorem wittZero_eq_zero (n : ℕ) : wittZero p n = 0 := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittZero, wittStructureRat, bind₁, aeval_zero', constantCoeff_xInTermsOfW, map_zero,
map_wittStructureInt]
@[simp]
theorem wittOne_zero_eq_one : wittOne p 0 = 1 := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittOne, wittStructureRat, xInTermsOfW_zero, map_one, bind₁_X_right,
map_wittStructureInt]
@[simp]
theorem wittOne_pos_eq_zero (n : ℕ) (hn : 0 < n) : wittOne p n = 0 := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittOne, wittStructureRat, RingHom.map_zero, map_one,
map_wittStructureInt]
induction n using Nat.strong_induction_on with | h n IH => ?_
rw [xInTermsOfW_eq]
simp only [map_mul, map_sub, map_sum, map_pow, bind₁_X_right,
bind₁_C_right]
rw [sub_mul, one_mul]
rw [Finset.sum_eq_single 0]
· simp only [invOf_eq_inv, one_mul, tsub_zero, pow_zero]
simp only [one_pow, one_mul, xInTermsOfW_zero, sub_self, bind₁_X_right]
· intro i hin hi0
rw [Finset.mem_range] at hin
rw [IH _ hin (Nat.pos_of_ne_zero hi0), zero_pow (pow_ne_zero _ hp.1.ne_zero), mul_zero]
· grind
@[simp]
theorem wittAdd_zero : wittAdd p 0 = X (0, 0) + X (1, 0) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittAdd, wittStructureRat, map_add, rename_X, xInTermsOfW_zero, map_X,
wittPolynomial_zero, bind₁_X_right, map_wittStructureInt]
@[simp]
theorem wittSub_zero : wittSub p 0 = X (0, 0) - X (1, 0) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittSub, wittStructureRat, map_sub, rename_X, xInTermsOfW_zero, map_X,
wittPolynomial_zero, bind₁_X_right, map_wittStructureInt]
@[simp]
theorem wittMul_zero : wittMul p 0 = X (0, 0) * X (1, 0) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittMul, wittStructureRat, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero,
map_mul, bind₁_X_right, map_wittStructureInt]
@[simp]
theorem wittNeg_zero : wittNeg p 0 = -X (0, 0) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittNeg, wittStructureRat, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero,
map_neg, bind₁_X_right, map_wittStructureInt]
@[simp]
theorem constantCoeff_wittAdd (n : ℕ) : constantCoeff (wittAdd p n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [add_zero, RingHom.map_add, constantCoeff_X]
@[simp]
theorem constantCoeff_wittSub (n : ℕ) : constantCoeff (wittSub p n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [sub_zero, RingHom.map_sub, constantCoeff_X]
@[simp]
theorem constantCoeff_wittMul (n : ℕ) : constantCoeff (wittMul p n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [mul_zero, RingHom.map_mul, constantCoeff_X]
@[simp]
theorem constantCoeff_wittNeg (n : ℕ) : constantCoeff (wittNeg p n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [neg_zero, RingHom.map_neg, constantCoeff_X]
@[simp]
theorem constantCoeff_wittNSMul (m : ℕ) (n : ℕ) : constantCoeff (wittNSMul p m n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [smul_zero, map_nsmul, constantCoeff_X]
@[simp]
theorem constantCoeff_wittZSMul (z : ℤ) (n : ℕ) : constantCoeff (wittZSMul p z n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [smul_zero, map_zsmul, constantCoeff_X]
end WittStructureSimplifications
section Coeff
variable (R)
@[simp]
theorem zero_coeff (n : ℕ) : (0 : 𝕎 R).coeff n = 0 :=
show (aeval _ (wittZero p n) : R) = 0 by simp only [wittZero_eq_zero, map_zero]
@[simp]
theorem one_coeff_zero : (1 : 𝕎 R).coeff 0 = 1 :=
show (aeval _ (wittOne p 0) : R) = 1 by simp only [wittOne_zero_eq_one, map_one]
@[simp]
theorem one_coeff_eq_of_pos (n : ℕ) (hn : 0 < n) : coeff (1 : 𝕎 R) n = 0 :=
show (aeval _ (wittOne p n) : R) = 0 by simp only [hn, wittOne_pos_eq_zero, map_zero]
variable {p R}
@[simp]
theorem v2_coeff {p' R'} (x y : WittVector p' R') (i : Fin 2) :
(![x, y] i).coeff = ![x.coeff, y.coeff] i := by fin_cases i <;> simp
theorem add_coeff (x y : 𝕎 R) (n : ℕ) :
(x + y).coeff n = peval (wittAdd p n) ![x.coeff, y.coeff] := by
simp [(· + ·), Add.add, eval]
theorem sub_coeff (x y : 𝕎 R) (n : ℕ) :
(x - y).coeff n = peval (wittSub p n) ![x.coeff, y.coeff] := by
simp [(· - ·), Sub.sub, eval]
theorem mul_coeff (x y : 𝕎 R) (n : ℕ) :
(x * y).coeff n = peval (wittMul p n) ![x.coeff, y.coeff] := by
simp [(· * ·), Mul.mul, eval]
theorem neg_coeff (x : 𝕎 R) (n : ℕ) : (-x).coeff n = peval (wittNeg p n) ![x.coeff] := by
simp [Neg.neg, eval, Matrix.cons_fin_one]
theorem nsmul_coeff (m : ℕ) (x : 𝕎 R) (n : ℕ) :
(m • x).coeff n = peval (wittNSMul p m n) ![x.coeff] := by
simp [(· • ·), SMul.smul, eval, Matrix.cons_fin_one]
theorem zsmul_coeff (m : ℤ) (x : 𝕎 R) (n : ℕ) :
(m • x).coeff n = peval (wittZSMul p m n) ![x.coeff] := by
simp [(· • ·), SMul.smul, eval, Matrix.cons_fin_one]
theorem pow_coeff (m : ℕ) (x : 𝕎 R) (n : ℕ) :
(x ^ m).coeff n = peval (wittPow p m n) ![x.coeff] := by
simp [(· ^ ·), Pow.pow, eval, Matrix.cons_fin_one]
theorem add_coeff_zero (x y : 𝕎 R) : (x + y).coeff 0 = x.coeff 0 + y.coeff 0 := by
simp [add_coeff, peval, Function.uncurry]
theorem mul_coeff_zero (x y : 𝕎 R) : (x * y).coeff 0 = x.coeff 0 * y.coeff 0 := by
simp [mul_coeff, peval, Function.uncurry]
end Coeff
theorem wittAdd_vars (n : ℕ) : (wittAdd p n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittSub_vars (n : ℕ) : (wittSub p n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittMul_vars (n : ℕ) : (wittMul p n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittNeg_vars (n : ℕ) : (wittNeg p n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittNSMul_vars (m : ℕ) (n : ℕ) :
(wittNSMul p m n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittZSMul_vars (m : ℤ) (n : ℕ) :
(wittZSMul p m n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittPow_vars (m : ℕ) (n : ℕ) : (wittPow p m n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/IsPoly.lean | import Mathlib.Algebra.MvPolynomial.Funext
import Mathlib.Algebra.Ring.ULift
import Mathlib.RingTheory.WittVector.Basic
/-!
# The `IsPoly` predicate
`WittVector.IsPoly` is a (type-valued) predicate on functions `f : Π R, 𝕎 R → 𝕎 R`.
It asserts that there is a family of polynomials `φ : ℕ → MvPolynomial ℕ ℤ`,
such that the `n`th coefficient of `f x` is equal to `φ n` evaluated on the coefficients of `x`.
Many operations on Witt vectors satisfy this predicate (or an analogue for higher arity functions).
We say that such a function `f` is a *polynomial function*.
The power of satisfying this predicate comes from `WittVector.IsPoly.ext`.
It shows that if `φ` and `ψ` witness that `f` and `g` are polynomial functions,
then `f = g` not merely when `φ = ψ`, but in fact it suffices to prove
```
∀ n, bind₁ φ (wittPolynomial p _ n) = bind₁ ψ (wittPolynomial p _ n)
```
(in other words, when evaluating the Witt polynomials on `φ` and `ψ`, we get the same values)
which will then imply `φ = ψ` and hence `f = g`.
Even though this sufficient condition looks somewhat intimidating,
it is rather pleasant to check in practice;
more so than direct checking of `φ = ψ`.
In practice, we apply this technique to show that the composition of `WittVector.frobenius`
and `WittVector.verschiebung` is equal to multiplication by `p`.
## Main declarations
* `WittVector.IsPoly`, `WittVector.IsPoly₂`:
two predicates that assert that a unary/binary function on Witt vectors
is polynomial in the coefficients of the input values.
* `WittVector.IsPoly.ext`, `WittVector.IsPoly₂.ext`:
two polynomial functions are equal if their families of polynomials are equal
after evaluating the Witt polynomials on them.
* `WittVector.IsPoly.comp` (+ many variants) show that unary/binary compositions
of polynomial functions are polynomial.
* `WittVector.idIsPoly`, `WittVector.negIsPoly`,
`WittVector.addIsPoly₂`, `WittVector.mulIsPoly₂`:
several well-known operations are polynomial functions
(for Verschiebung, Frobenius, and multiplication by `p`, see their respective files).
## On higher arity analogues
Ideally, there should be a predicate `IsPolyₙ` for functions of higher arity,
together with `IsPolyₙ.comp` that shows how such functions compose.
Since mathlib does not have a library on composition of higher arity functions,
we have only implemented the unary and binary variants so far.
Nullary functions (a.k.a. constants) are treated
as constant functions and fall under the unary case.
## Tactics
There are important metaprograms defined in this file:
the tactics `ghost_simp` and `ghost_calc` and the attribute `@[ghost_simps]`.
These are used in combination to discharge proofs of identities between polynomial functions.
The `ghost_calc` tactic makes use of the `IsPoly` and `IsPoly₂` typeclass and its instances.
(In Lean 3, there was an `@[is_poly]` attribute to manage these instances,
because typeclass resolution did not play well with function composition.
This no longer seems to be an issue, so that such instances can be defined directly.)
Any lemma doing "ring equation rewriting" with polynomial functions should be tagged
`@[ghost_simps]`, e.g.
```lean
@[ghost_simps]
lemma bind₁_frobenius_poly_wittPolynomial (n : ℕ) :
bind₁ (frobenius_poly p) (wittPolynomial p ℤ n) = (wittPolynomial p ℤ (n+1))
```
Proofs of identities between polynomial functions will often follow the pattern
```lean
ghost_calc _
<minor preprocessing>
ghost_simp
```
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
universe u
variable {p : ℕ} {R S : Type u} {idx : Type*} [CommRing R] [CommRing S]
local notation "𝕎" => WittVector p -- type as `\bbW`
open MvPolynomial
open Function (uncurry)
variable (p)
noncomputable section
/-!
### The `IsPoly` predicate
-/
theorem poly_eq_of_wittPolynomial_bind_eq' [Fact p.Prime] (f g : ℕ → MvPolynomial (idx × ℕ) ℤ)
(h : ∀ n, bind₁ f (wittPolynomial p _ n) = bind₁ g (wittPolynomial p _ n)) : f = g := by
ext1 n
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
rw [← funext_iff] at h
replace h :=
congr_arg (fun fam => bind₁ (MvPolynomial.map (Int.castRingHom ℚ) ∘ fam) (xInTermsOfW p ℚ n)) h
simpa only [Function.comp_def, map_bind₁, map_wittPolynomial, ← bind₁_bind₁,
bind₁_wittPolynomial_xInTermsOfW, bind₁_X_right] using h
theorem poly_eq_of_wittPolynomial_bind_eq [Fact p.Prime] (f g : ℕ → MvPolynomial ℕ ℤ)
(h : ∀ n, bind₁ f (wittPolynomial p _ n) = bind₁ g (wittPolynomial p _ n)) : f = g := by
ext1 n
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
rw [← funext_iff] at h
replace h :=
congr_arg (fun fam => bind₁ (MvPolynomial.map (Int.castRingHom ℚ) ∘ fam) (xInTermsOfW p ℚ n)) h
simpa only [Function.comp_def, map_bind₁, map_wittPolynomial, ← bind₁_bind₁,
bind₁_wittPolynomial_xInTermsOfW, bind₁_X_right] using h
-- Ideally, we would generalise this to n-ary functions
-- But we don't have a good theory of n-ary compositions in mathlib
/--
A function `f : Π R, 𝕎 R → 𝕎 R` that maps Witt vectors to Witt vectors over arbitrary base rings
is said to be *polynomial* if there is a family of polynomials `φₙ` over `ℤ` such that the `n`th
coefficient of `f x` is given by evaluating `φₙ` at the coefficients of `x`.
See also `WittVector.IsPoly₂` for the binary variant.
The `ghost_calc` tactic makes use of the `IsPoly` and `IsPoly₂` typeclass and its instances.
(In Lean 3, there was an `@[is_poly]` attribute to manage these instances,
because typeclass resolution did not play well with function composition.
This no longer seems to be an issue, so that such instances can be defined directly.)
-/
class IsPoly (f : ∀ ⦃R⦄ [CommRing R], WittVector p R → 𝕎 R) : Prop where mk' ::
poly :
∃ φ : ℕ → MvPolynomial ℕ ℤ,
∀ ⦃R⦄ [CommRing R] (x : 𝕎 R), (f x).coeff = fun n => aeval x.coeff (φ n)
/-- The identity function on Witt vectors is a polynomial function. -/
instance idIsPoly : IsPoly p fun _ _ => id :=
⟨⟨X, by intros; simp only [aeval_X, id]⟩⟩
instance idIsPolyI' : IsPoly p fun _ _ a => a :=
WittVector.idIsPoly _
namespace IsPoly
instance : Inhabited (IsPoly p fun _ _ => id) :=
⟨WittVector.idIsPoly p⟩
variable {p}
theorem ext [Fact p.Prime] {f g} (hf : IsPoly p f) (hg : IsPoly p g)
(h : ∀ (R : Type u) [_Rcr : CommRing R] (x : 𝕎 R) (n : ℕ),
ghostComponent n (f x) = ghostComponent n (g x)) :
∀ (R : Type u) [_Rcr : CommRing R] (x : 𝕎 R), f x = g x := by
obtain ⟨φ, hf⟩ := hf
obtain ⟨ψ, hg⟩ := hg
intros
ext n
rw [hf, hg, poly_eq_of_wittPolynomial_bind_eq p φ ψ]
intro k
apply MvPolynomial.funext
intro x
simp only [hom_bind₁]
specialize h (ULift ℤ) (mk p fun i => ⟨x i⟩) k
simp only [ghostComponent_apply, aeval_eq_eval₂Hom] at h
apply (ULift.ringEquiv.symm : ℤ ≃+* _).injective
simp only [← RingEquiv.coe_toRingHom, map_eval₂Hom]
convert h using 1
all_goals
simp only [hf, hg, MvPolynomial.eval, map_eval₂Hom]
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext1
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
simp only [coeff_mk]; rfl
/-- The composition of polynomial functions is polynomial. -/
instance comp {g f} [hg : IsPoly p g] [hf : IsPoly p f] :
IsPoly p fun R _Rcr => @g R _Rcr ∘ @f R _Rcr := by
obtain ⟨φ, hf⟩ := hf
obtain ⟨ψ, hg⟩ := hg
use fun n => bind₁ φ (ψ n)
intros
simp only [aeval_bind₁, Function.comp, hg, hf]
end IsPoly
/-- A binary function `f : Π R, 𝕎 R → 𝕎 R → 𝕎 R` on Witt vectors
is said to be *polynomial* if there is a family of polynomials `φₙ` over `ℤ` such that the `n`th
coefficient of `f x y` is given by evaluating `φₙ` at the coefficients of `x` and `y`.
See also `WittVector.IsPoly` for the unary variant.
The `ghost_calc` tactic makes use of the `IsPoly` and `IsPoly₂` typeclass and its instances.
(In Lean 3, there was an `@[is_poly]` attribute to manage these instances,
because typeclass resolution did not play well with function composition.
This no longer seems to be an issue, so that such instances can be defined directly.)
-/
class IsPoly₂ (f : ∀ ⦃R⦄ [CommRing R], WittVector p R → 𝕎 R → 𝕎 R) : Prop where mk' ::
poly :
∃ φ : ℕ → MvPolynomial (Fin 2 × ℕ) ℤ,
∀ ⦃R⦄ [CommRing R] (x y : 𝕎 R), (f x y).coeff = fun n => peval (φ n) ![x.coeff, y.coeff]
variable {p}
/-- The composition of polynomial functions is polynomial. -/
instance IsPoly₂.comp {h f g} [hh : IsPoly₂ p h] [hf : IsPoly p f] [hg : IsPoly p g] :
IsPoly₂ p fun _ _Rcr x y => h (f x) (g y) := by
obtain ⟨φ, hf⟩ := hf
obtain ⟨ψ, hg⟩ := hg
obtain ⟨χ, hh⟩ := hh
refine ⟨⟨fun n ↦ bind₁ (uncurry <|
![fun k ↦ rename (Prod.mk (0 : Fin 2)) (φ k),
fun k ↦ rename (Prod.mk (1 : Fin 2)) (ψ k)]) (χ n), ?_⟩⟩
intros
funext n
simp +unfoldPartialApp only [peval, aeval_bind₁, hh, hf, hg,
uncurry]
apply eval₂Hom_congr rfl _ rfl
ext ⟨i, n⟩
fin_cases i <;> simp [aeval_eq_eval₂Hom, eval₂Hom_rename, Function.comp_def]
/-- The composition of a polynomial function with a binary polynomial function is polynomial. -/
instance IsPoly.comp₂ {g f} [hg : IsPoly p g] [hf : IsPoly₂ p f] :
IsPoly₂ p fun _ _Rcr x y => g (f x y) := by
obtain ⟨φ, hf⟩ := hf
obtain ⟨ψ, hg⟩ := hg
use fun n => bind₁ φ (ψ n)
intros
simp only [peval, aeval_bind₁, hg, hf]
/-- The diagonal `fun x ↦ f x x` of a polynomial function `f` is polynomial. -/
instance IsPoly₂.diag {f} [hf : IsPoly₂ p f] : IsPoly p fun _ _Rcr x => f x x := by
obtain ⟨φ, hf⟩ := hf
refine ⟨⟨fun n => bind₁ (uncurry ![X, X]) (φ n), ?_⟩⟩
intros; funext n
simp +unfoldPartialApp only [hf, peval, uncurry, aeval_bind₁]
apply eval₂Hom_congr rfl _ rfl
ext ⟨i, k⟩
fin_cases i <;> simp
/-- The additive negation is a polynomial function on Witt vectors. -/
instance negIsPoly [Fact p.Prime] : IsPoly p fun R _ => @Neg.neg (𝕎 R) _ :=
⟨⟨fun n => rename Prod.snd (wittNeg p n), by
intros; funext n
rw [neg_coeff, aeval_eq_eval₂Hom, eval₂Hom_rename]
apply eval₂Hom_congr rfl _ rfl
ext ⟨i, k⟩; fin_cases i; rfl⟩⟩
section ZeroOne
/- To avoid a theory of 0-ary functions (a.k.a. constants)
we model them as constant unary functions. -/
/-- The function that is constantly zero on Witt vectors is a polynomial function. -/
instance zeroIsPoly [Fact p.Prime] : IsPoly p fun _ _ _ => 0 :=
⟨⟨0, by intros; funext n; simp only [Pi.zero_apply, map_zero, zero_coeff]⟩⟩
@[simp]
theorem bind₁_zero_wittPolynomial [Fact p.Prime] (n : ℕ) :
bind₁ (0 : ℕ → MvPolynomial ℕ R) (wittPolynomial p R n) = 0 := by
rw [← aeval_eq_bind₁, aeval_zero, constantCoeff_wittPolynomial, RingHom.map_zero]
/-- The coefficients of `1 : 𝕎 R` as polynomials. -/
def onePoly (n : ℕ) : MvPolynomial ℕ ℤ :=
if n = 0 then 1 else 0
@[simp]
theorem bind₁_onePoly_wittPolynomial [hp : Fact p.Prime] (n : ℕ) :
bind₁ onePoly (wittPolynomial p ℤ n) = 1 := by
rw [wittPolynomial_eq_sum_C_mul_X_pow, map_sum, Finset.sum_eq_single 0]
· simp only [onePoly, one_pow, one_mul, map_pow, C_1, pow_zero, bind₁_X_right, if_true]
· intro i _hi hi0
simp only [onePoly, if_neg hi0, zero_pow (pow_ne_zero _ hp.1.ne_zero), mul_zero, map_pow,
bind₁_X_right, map_mul]
· simp
/-- The function that is constantly one on Witt vectors is a polynomial function. -/
instance oneIsPoly [Fact p.Prime] : IsPoly p fun _ _ _ => 1 :=
⟨⟨onePoly, by
intros; funext n; cases n
· simp only [one_coeff_zero, onePoly, ite_true, map_one]
· simp only [Nat.succ_pos', one_coeff_eq_of_pos, onePoly, Nat.succ_ne_zero, ite_false,
map_zero]
⟩⟩
end ZeroOne
/-- Addition of Witt vectors is a polynomial function. -/
instance addIsPoly₂ [Fact p.Prime] : IsPoly₂ p fun _ _ => (· + ·) :=
⟨⟨wittAdd p, by intros; ext; exact add_coeff _ _ _⟩⟩
/-- Multiplication of Witt vectors is a polynomial function. -/
instance mulIsPoly₂ [Fact p.Prime] : IsPoly₂ p fun _ _ => (· * ·) :=
⟨⟨wittMul p, by intros; ext; exact mul_coeff _ _ _⟩⟩
-- unfortunately this is not universe polymorphic, merely because `f` isn't
theorem IsPoly.map [Fact p.Prime] {f} (hf : IsPoly p f) (g : R →+* S) (x : 𝕎 R) :
map g (f x) = f (map g x) := by
-- this could be turned into a tactic “macro” (taking `hf` as parameter)
-- so that applications do not have to worry about the universe issue
-- see `IsPoly₂.map` for a slightly more general proof strategy
obtain ⟨φ, hf⟩ := hf
ext n
simp_rw [map_coeff, hf, map_aeval, funext (map_coeff g _), RingHom.ext_int _ (algebraMap ℤ S),
aeval_eq_eval₂Hom]
namespace IsPoly₂
instance [Fact p.Prime] : Inhabited (IsPoly₂ p (fun _ _ => (· + ·))) :=
⟨addIsPoly₂⟩
theorem ext [Fact p.Prime] {f g} (hf : IsPoly₂ p f) (hg : IsPoly₂ p g)
(h : ∀ (R : Type u) [_Rcr : CommRing R] (x y : 𝕎 R) (n : ℕ),
ghostComponent n (f x y) = ghostComponent n (g x y)) :
∀ (R) [_Rcr : CommRing R] (x y : 𝕎 R), f x y = g x y := by
obtain ⟨φ, hf⟩ := hf
obtain ⟨ψ, hg⟩ := hg
intros
ext n
rw [hf, hg, poly_eq_of_wittPolynomial_bind_eq' p φ ψ]
intro k
apply MvPolynomial.funext
intro x
simp only [hom_bind₁]
specialize h (ULift ℤ) (mk p fun i => ⟨x (0, i)⟩) (mk p fun i => ⟨x (1, i)⟩) k
simp only [ghostComponent_apply, aeval_eq_eval₂Hom] at h
apply (ULift.ringEquiv.symm : ℤ ≃+* _).injective
simp only [← RingEquiv.coe_toRingHom, map_eval₂Hom]
convert h using 1
all_goals
simp only [hf, hg, MvPolynomial.eval, map_eval₂Hom]
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext1
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext ⟨b, _⟩
fin_cases b <;> simp only [coeff_mk, uncurry] <;> rfl
-- unfortunately this is not universe polymorphic, merely because `f` isn't
theorem map [Fact p.Prime] {f} (hf : IsPoly₂ p f) (g : R →+* S) (x y : 𝕎 R) :
map g (f x y) = f (map g x) (map g y) := by
-- this could be turned into a tactic “macro” (taking `hf` as parameter)
-- so that applications do not have to worry about the universe issue
obtain ⟨φ, hf⟩ := hf
ext n
simp +unfoldPartialApp only [map_coeff, hf, map_aeval, peval, uncurry]
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext ⟨i, k⟩
fin_cases i <;> simp
end IsPoly₂
attribute [ghost_simps] AlgHom.id_apply map_natCast RingHom.map_zero RingHom.map_one RingHom.map_mul
RingHom.map_add RingHom.map_sub RingHom.map_neg RingHom.id_apply mul_add add_mul add_zero zero_add
mul_one one_mul mul_zero zero_mul Nat.succ_ne_zero add_tsub_cancel_right
Nat.succ_eq_add_one if_true eq_self_iff_true if_false forall_true_iff forall₂_true_iff
forall₃_true_iff
end
namespace Tactic
open Lean Parser.Tactic Elab.Tactic
/-- A macro for a common simplification when rewriting with ghost component equations. -/
syntax (name := ghostSimp) "ghost_simp" (simpArgs)? : tactic
macro_rules
| `(tactic| ghost_simp $[[$simpArgs,*]]?) => do
let args := simpArgs.map (·.getElems) |>.getD #[]
`(tactic| simp only [← sub_eq_add_neg, ghost_simps, $args,*])
/-- `ghost_calc` is a tactic for proving identities between polynomial functions.
Typically, when faced with a goal like
```lean
∀ (x y : 𝕎 R), verschiebung (x * frobenius y) = verschiebung x * y
```
you can
1. call `ghost_calc`
2. do a small amount of manual work -- maybe nothing, maybe `rintro`, etc
3. call `ghost_simp`
and this will close the goal.
`ghost_calc` cannot detect whether you are dealing with unary or binary polynomial functions.
You must give it arguments to determine this.
If you are proving a universally quantified goal like the above,
call `ghost_calc _ _`.
If the variables are introduced already, call `ghost_calc x y`.
In the unary case, use `ghost_calc _` or `ghost_calc x`.
`ghost_calc` is a light wrapper around type class inference.
All it does is apply the appropriate extensionality lemma and try to infer the resulting goals.
This is subtle and Lean's elaborator doesn't like it because of the HO unification involved,
so it is easier (and prettier) to put it in a tactic script.
-/
syntax (name := ghostCalc) "ghost_calc" (ppSpace colGt term:max)* : tactic
private def runIntro (ref : Syntax) (n : Name) : TacticM FVarId := do
let fvarId ← liftMetaTacticAux fun g => do
let (fv, g') ← g.intro n
return (fv, [g'])
withMainContext do
Elab.Term.addLocalVarInfo ref (mkFVar fvarId)
return fvarId
private def getLocalOrIntro (t : Term) : TacticM FVarId := do
match t with
| `(_) => runIntro t `_
| `($id:ident) => getFVarId id <|> runIntro id id.getId
| _ => Elab.throwUnsupportedSyntax
elab_rules : tactic | `(tactic| ghost_calc $[$ids']*) => do
let ids ← ids'.mapM getLocalOrIntro
withMainContext do
let idsS ← ids.mapM (fun id => Elab.Term.exprToSyntax (.fvar id))
let some (α, lhs, rhs) := (← getMainTarget'').eq?
| throwError "ghost_calc expecting target to be an equality"
let (``WittVector, #[_, R]) := α.getAppFnArgs
| throwError "ghost_calc expecting target to be an equality of `WittVector`s"
let instR ← Meta.synthInstance (← Meta.mkAppM ``CommRing #[R])
unless instR.isFVar do
throwError "{← Meta.inferType instR} instance is not local"
let f ← Meta.mkLambdaFVars (#[R, instR] ++ ids.map .fvar) lhs
let g ← Meta.mkLambdaFVars (#[R, instR] ++ ids.map .fvar) rhs
let fS ← Elab.Term.exprToSyntax f
let gS ← Elab.Term.exprToSyntax g
match idsS with
| #[x] => evalTactic (← `(tactic| refine IsPoly.ext (f := $fS) (g := $gS) ?_ ?_ ?_ _ $x))
| #[x, y] => evalTactic (← `(tactic| refine IsPoly₂.ext (f := $fS) (g := $gS) ?_ ?_ ?_ _ $x $y))
| _ => throwError "ghost_calc takes either one or two arguments"
let nm ← withMainContext <|
if let .fvar fvarId := (R : Expr) then
fvarId.getUserName
else
Meta.getUnusedUserName `R
evalTactic <| ← `(tactic| iterate 2 infer_instance)
let R := mkIdent nm
evalTactic <| ← `(tactic| clear! $R)
evalTactic <| ← `(tactic| intro $(mkIdent nm):ident $(mkIdent (.str nm "_inst")):ident $ids'*)
end Tactic
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/Truncated.lean | import Mathlib.RingTheory.WittVector.InitTail
/-!
# Truncated Witt vectors
The ring of truncated Witt vectors (of length `n`) is a quotient of the ring of Witt vectors.
It retains the first `n` coefficients of each Witt vector.
In this file, we set up the basic quotient API for this ring.
The ring of Witt vectors is the projective limit of all the rings of truncated Witt vectors.
## Main declarations
- `TruncatedWittVector`: the underlying type of the ring of truncated Witt vectors
- `TruncatedWittVector.instCommRing`: the ring structure on truncated Witt vectors
- `WittVector.truncate`: the quotient homomorphism that truncates a Witt vector,
to obtain a truncated Witt vector
- `TruncatedWittVector.truncate`: the homomorphism that truncates
a truncated Witt vector of length `n` to one of length `m` (for some `m ≤ n`)
- `WittVector.lift`: the unique ring homomorphism into the ring of Witt vectors
that is compatible with a family of ring homomorphisms to the truncated Witt vectors:
this realizes the ring of Witt vectors as projective limit of the rings of truncated Witt vectors
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
open Function (Injective Surjective)
noncomputable section
variable {p : ℕ} (n : ℕ) (R : Type*)
local notation "𝕎" => WittVector p -- type as `\bbW`
/-- A truncated Witt vector over `R` is a vector of elements of `R`,
i.e., the first `n` coefficients of a Witt vector.
We will define operations on this type that are compatible with the (untruncated) Witt
vector operations.
`TruncatedWittVector p n R` takes a parameter `p : ℕ` that is not used in the definition.
In practice, this number `p` is assumed to be a prime number,
and under this assumption we construct a ring structure on `TruncatedWittVector p n R`.
(`TruncatedWittVector p₁ n R` and `TruncatedWittVector p₂ n R` are definitionally
equal as types but will have different ring operations.)
-/
@[nolint unusedArguments]
def TruncatedWittVector (_ : ℕ) (n : ℕ) (R : Type*) :=
Fin n → R
instance (p n : ℕ) (R : Type*) [Inhabited R] : Inhabited (TruncatedWittVector p n R) :=
⟨fun _ => default⟩
variable {n R}
namespace TruncatedWittVector
variable (p) in
/-- Create a `TruncatedWittVector` from a vector `x`. -/
def mk (x : Fin n → R) : TruncatedWittVector p n R :=
x
/-- `x.coeff i` is the `i`th entry of `x`. -/
def coeff (i : Fin n) (x : TruncatedWittVector p n R) : R :=
x i
@[ext]
theorem ext {x y : TruncatedWittVector p n R} (h : ∀ i, x.coeff i = y.coeff i) : x = y :=
funext h
@[simp]
theorem coeff_mk (x : Fin n → R) (i : Fin n) : (mk p x).coeff i = x i :=
rfl
@[simp]
theorem mk_coeff (x : TruncatedWittVector p n R) : (mk p fun i => x.coeff i) = x := by
ext i; rw [coeff_mk]
variable [CommRing R]
/-- We can turn a truncated Witt vector `x` into a Witt vector
by setting all coefficients after `x` to be 0.
-/
def out (x : TruncatedWittVector p n R) : 𝕎 R :=
@WittVector.mk' p _ fun i => if h : i < n then x.coeff ⟨i, h⟩ else 0
@[simp]
theorem coeff_out (x : TruncatedWittVector p n R) (i : Fin n) : x.out.coeff i = x.coeff i := by
rw [out]; dsimp only; rw [dif_pos i.is_lt, Fin.eta]
theorem out_injective : Injective (@out p n R _) := by
intro x y h
ext i
rw [WittVector.ext_iff] at h
simpa only [coeff_out] using h ↑i
end TruncatedWittVector
namespace WittVector
variable (n)
section
/-- `truncateFun n x` uses the first `n` entries of `x` to construct a `TruncatedWittVector`,
which has the same base `p` as `x`.
This function is bundled into a ring homomorphism in `WittVector.truncate` -/
def truncateFun (x : 𝕎 R) : TruncatedWittVector p n R :=
TruncatedWittVector.mk p fun i => x.coeff i
end
variable {n}
@[simp]
theorem coeff_truncateFun (x : 𝕎 R) (i : Fin n) : (truncateFun n x).coeff i = x.coeff i := by
rw [truncateFun, TruncatedWittVector.coeff_mk]
variable [CommRing R]
@[simp]
theorem out_truncateFun (x : 𝕎 R) : (truncateFun n x).out = init n x := by
ext i
dsimp [TruncatedWittVector.out, init, select, coeff_mk]
split_ifs with hi; swap; · rfl
rw [coeff_truncateFun, Fin.val_mk]
end WittVector
namespace TruncatedWittVector
variable [CommRing R]
@[simp]
theorem truncateFun_out (x : TruncatedWittVector p n R) : x.out.truncateFun n = x := by
simp only [WittVector.truncateFun, coeff_out, mk_coeff]
open WittVector
variable (p n R)
variable [Fact p.Prime]
instance : Zero (TruncatedWittVector p n R) :=
⟨truncateFun n 0⟩
instance : One (TruncatedWittVector p n R) :=
⟨truncateFun n 1⟩
instance : NatCast (TruncatedWittVector p n R) :=
⟨fun i => truncateFun n i⟩
instance : IntCast (TruncatedWittVector p n R) :=
⟨fun i => truncateFun n i⟩
instance : Add (TruncatedWittVector p n R) :=
⟨fun x y => truncateFun n (x.out + y.out)⟩
instance : Mul (TruncatedWittVector p n R) :=
⟨fun x y => truncateFun n (x.out * y.out)⟩
instance : Neg (TruncatedWittVector p n R) :=
⟨fun x => truncateFun n (-x.out)⟩
instance : Sub (TruncatedWittVector p n R) :=
⟨fun x y => truncateFun n (x.out - y.out)⟩
instance hasNatScalar : SMul ℕ (TruncatedWittVector p n R) :=
⟨fun m x => truncateFun n (m • x.out)⟩
instance hasIntScalar : SMul ℤ (TruncatedWittVector p n R) :=
⟨fun m x => truncateFun n (m • x.out)⟩
instance hasNatPow : Pow (TruncatedWittVector p n R) ℕ :=
⟨fun x m => truncateFun n (x.out ^ m)⟩
@[simp]
theorem coeff_zero (i : Fin n) : (0 : TruncatedWittVector p n R).coeff i = 0 := by
change coeff i (truncateFun _ 0 : TruncatedWittVector p n R) = 0
rw [coeff_truncateFun, WittVector.zero_coeff]
end TruncatedWittVector
/-- A macro tactic used to prove that `truncateFun` respects ring operations. -/
macro (name := witt_truncateFun_tac) "witt_truncateFun_tac" : tactic =>
`(tactic|
{ show _ = WittVector.truncateFun n _
apply TruncatedWittVector.out_injective
iterate rw [WittVector.out_truncateFun]
first
| rw [WittVector.init_add]
| rw [WittVector.init_mul]
| rw [WittVector.init_neg]
| rw [WittVector.init_sub]
| rw [WittVector.init_nsmul]
| rw [WittVector.init_zsmul]
| rw [WittVector.init_pow]})
namespace WittVector
variable (p n R)
variable [CommRing R]
theorem truncateFun_surjective : Surjective (@truncateFun p n R) :=
Function.RightInverse.surjective TruncatedWittVector.truncateFun_out
variable [Fact p.Prime]
@[simp]
theorem truncateFun_zero : truncateFun n (0 : 𝕎 R) = 0 := rfl
@[simp]
theorem truncateFun_one : truncateFun n (1 : 𝕎 R) = 1 := rfl
variable {p R}
@[simp]
theorem truncateFun_add (x y : 𝕎 R) :
truncateFun n (x + y) = truncateFun n x + truncateFun n y := by
witt_truncateFun_tac
@[simp]
theorem truncateFun_mul (x y : 𝕎 R) :
truncateFun n (x * y) = truncateFun n x * truncateFun n y := by
witt_truncateFun_tac
theorem truncateFun_neg (x : 𝕎 R) : truncateFun n (-x) = -truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_sub (x y : 𝕎 R) :
truncateFun n (x - y) = truncateFun n x - truncateFun n y := by
witt_truncateFun_tac
theorem truncateFun_nsmul (m : ℕ) (x : 𝕎 R) : truncateFun n (m • x) = m • truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_zsmul (m : ℤ) (x : 𝕎 R) : truncateFun n (m • x) = m • truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_pow (x : 𝕎 R) (m : ℕ) : truncateFun n (x ^ m) = truncateFun n x ^ m := by
witt_truncateFun_tac
theorem truncateFun_natCast (m : ℕ) : truncateFun n (m : 𝕎 R) = m := rfl
theorem truncateFun_intCast (m : ℤ) : truncateFun n (m : 𝕎 R) = m := rfl
end WittVector
namespace TruncatedWittVector
open WittVector
variable (p n R)
variable [CommRing R]
variable [Fact p.Prime]
instance instCommRing : CommRing (TruncatedWittVector p n R) :=
(truncateFun_surjective p n R).commRing _ (truncateFun_zero p n R) (truncateFun_one p n R)
(truncateFun_add n) (truncateFun_mul n) (truncateFun_neg n) (truncateFun_sub n)
(truncateFun_nsmul n) (truncateFun_zsmul n) (truncateFun_pow n) (truncateFun_natCast n)
(truncateFun_intCast n)
end TruncatedWittVector
namespace WittVector
open TruncatedWittVector
variable (n)
variable [CommRing R]
variable [Fact p.Prime]
/-- `truncate n` is a ring homomorphism that truncates `x` to its first `n` entries
to obtain a `TruncatedWittVector`, which has the same base `p` as `x`. -/
noncomputable def truncate : 𝕎 R →+* TruncatedWittVector p n R where
toFun := truncateFun n
map_zero' := truncateFun_zero p n R
map_add' := truncateFun_add n
map_one' := truncateFun_one p n R
map_mul' := truncateFun_mul n
variable (p R)
theorem truncate_surjective : Surjective (truncate n : 𝕎 R → TruncatedWittVector p n R) :=
truncateFun_surjective p n R
variable {p n R}
@[simp]
theorem coeff_truncate (x : 𝕎 R) (i : Fin n) : (truncate n x).coeff i = x.coeff i :=
coeff_truncateFun _ _
variable (n)
theorem mem_ker_truncate (x : 𝕎 R) :
x ∈ RingHom.ker (truncate (p := p) n) ↔ ∀ i < n, x.coeff i = 0 := by
simp only [RingHom.mem_ker, truncate, RingHom.coe_mk, TruncatedWittVector.ext_iff,
coeff_zero]
exact Fin.forall_iff
variable (p)
@[simp]
theorem truncate_mk' (f : ℕ → R) :
truncate n (@mk' p _ f) = TruncatedWittVector.mk _ fun k => f k := by
ext i
simp only [coeff_truncate, TruncatedWittVector.coeff_mk]
end WittVector
namespace TruncatedWittVector
variable [CommRing R]
section
variable [Fact p.Prime]
/-- A ring homomorphism that truncates a truncated Witt vector of length `m` to
a truncated Witt vector of length `n`, for `n ≤ m`.
-/
def truncate {m : ℕ} (hm : n ≤ m) : TruncatedWittVector p m R →+* TruncatedWittVector p n R :=
RingHom.liftOfRightInverse (WittVector.truncate m) out truncateFun_out
⟨WittVector.truncate n, by
intro x
simp only [WittVector.mem_ker_truncate]
intro h i hi
exact h i (lt_of_lt_of_le hi hm)⟩
@[simp]
theorem truncate_comp_wittVector_truncate {m : ℕ} (hm : n ≤ m) :
(truncate (p := p) (R := R) hm).comp (WittVector.truncate m) = WittVector.truncate n :=
RingHom.liftOfRightInverse_comp _ _ _ _
@[simp]
theorem truncate_wittVector_truncate {m : ℕ} (hm : n ≤ m) (x : 𝕎 R) :
truncate hm (WittVector.truncate m x) = WittVector.truncate n x :=
RingHom.liftOfRightInverse_comp_apply _ _ _ _ _
@[simp]
theorem truncate_truncate {n₁ n₂ n₃ : ℕ} (h1 : n₁ ≤ n₂) (h2 : n₂ ≤ n₃)
(x : TruncatedWittVector p n₃ R) :
(truncate h1) (truncate h2 x) = truncate (h1.trans h2) x := by
obtain ⟨x, rfl⟩ := WittVector.truncate_surjective (p := p) n₃ R x
simp only [truncate_wittVector_truncate]
@[simp]
theorem truncate_comp {n₁ n₂ n₃ : ℕ} (h1 : n₁ ≤ n₂) (h2 : n₂ ≤ n₃) :
(truncate (p := p) (R := R) h1).comp (truncate h2) = truncate (h1.trans h2) := by
ext1 x; simp only [truncate_truncate, Function.comp_apply, RingHom.coe_comp]
theorem truncate_surjective {m : ℕ} (hm : n ≤ m) : Surjective (truncate (p := p) (R := R) hm) := by
intro x
obtain ⟨x, rfl⟩ := WittVector.truncate_surjective (p := p) _ R x
exact ⟨WittVector.truncate _ x, truncate_wittVector_truncate _ _⟩
@[simp]
theorem coeff_truncate {m : ℕ} (hm : n ≤ m) (i : Fin n) (x : TruncatedWittVector p m R) :
(truncate hm x).coeff i = x.coeff (Fin.castLE hm i) := by
obtain ⟨y, rfl⟩ := @WittVector.truncate_surjective p _ _ _ _ x
simp only [truncate_wittVector_truncate, WittVector.coeff_truncate, Fin.coe_castLE]
end
section Fintype
instance {R : Type*} [Fintype R] : Fintype (TruncatedWittVector p n R) :=
Pi.instFintype
variable (p n R)
theorem card {R : Type*} [Fintype R] :
Fintype.card (TruncatedWittVector p n R) = Fintype.card R ^ n := by
simp only [TruncatedWittVector, Fintype.card_fin, Fintype.card_fun]
end Fintype
variable [Fact p.Prime]
theorem iInf_ker_truncate : ⨅ i : ℕ, RingHom.ker (WittVector.truncate (p := p) (R := R) i) = ⊥ := by
rw [Submodule.eq_bot_iff]
intro x hx
ext
simp only [WittVector.mem_ker_truncate, Ideal.mem_iInf, WittVector.zero_coeff] at hx ⊢
exact hx _ _ (Nat.lt_succ_self _)
end TruncatedWittVector
namespace WittVector
open TruncatedWittVector hiding truncate coeff
section lift
variable [CommRing R]
variable [Fact p.Prime]
variable {S : Type*} [Semiring S]
variable (f : ∀ k : ℕ, S →+* TruncatedWittVector p k R)
variable
(f_compat : ∀ (k₁ k₂ : ℕ) (hk : k₁ ≤ k₂), (TruncatedWittVector.truncate hk).comp (f k₂) = f k₁)
variable (n)
/-- Given a family `fₖ : S → TruncatedWittVector p k R` and `s : S`, we produce a Witt vector by
defining the `k`th entry to be the final entry of `fₖ s`.
-/
def liftFun (s : S) : 𝕎 R :=
@WittVector.mk' p _ fun k => TruncatedWittVector.coeff (Fin.last k) (f (k + 1) s)
variable {f} in
include f_compat in
@[simp]
theorem truncate_liftFun (s : S) : WittVector.truncate n (liftFun f s) = f n s := by
ext i
simp only [liftFun, TruncatedWittVector.coeff_mk, WittVector.truncate_mk']
rw [← f_compat (i + 1) n i.is_lt, RingHom.comp_apply, TruncatedWittVector.coeff_truncate]
congr 1 with _
/--
Given compatible ring homs from `S` into `TruncatedWittVector n` for each `n`, we can lift these
to a ring hom `S → 𝕎 R`.
`lift` defines the universal property of `𝕎 R` as the inverse limit of `TruncatedWittVector n`.
-/
def lift : S →+* 𝕎 R := by
refine { toFun := liftFun f
map_zero' := ?_
map_one' := ?_
map_add' := ?_
map_mul' := ?_ } <;>
( intros
rw [← sub_eq_zero, ← Ideal.mem_bot, ← iInf_ker_truncate, Ideal.mem_iInf]
simp [RingHom.mem_ker, f_compat])
variable {f}
@[simp]
theorem truncate_lift (s : S) : WittVector.truncate n (lift _ f_compat s) = f n s :=
truncate_liftFun _ f_compat s
@[simp]
theorem truncate_comp_lift : (WittVector.truncate n).comp (lift _ f_compat) = f n := by
ext1; rw [RingHom.comp_apply, truncate_lift]
/-- The uniqueness part of the universal property of `𝕎 R`. -/
theorem lift_unique (g : S →+* 𝕎 R) (g_compat : ∀ k, (WittVector.truncate k).comp g = f k) :
lift _ f_compat = g := by
ext1 x
rw [← sub_eq_zero, ← Ideal.mem_bot, ← iInf_ker_truncate, Ideal.mem_iInf]
intro i
simp only [RingHom.mem_ker, g_compat, ← RingHom.comp_apply, truncate_comp_lift, RingHom.map_sub,
sub_self]
/-- The universal property of `𝕎 R` as projective limit of truncated Witt vector rings. -/
@[simps]
def liftEquiv : { f : ∀ k, S →+* TruncatedWittVector p k R // ∀ (k₁ k₂) (hk : k₁ ≤ k₂),
(TruncatedWittVector.truncate hk).comp (f k₂) = f k₁ } ≃ (S →+* 𝕎 R) where
toFun f := lift f.1 f.2
invFun g :=
⟨fun k => (truncate k).comp g, by
intro _ _ h
simp only [← RingHom.comp_assoc, truncate_comp_wittVector_truncate]⟩
left_inv := by rintro ⟨f, hf⟩; simp only [truncate_comp_lift]
right_inv _ := lift_unique _ _ fun _ => rfl
theorem hom_ext (g₁ g₂ : S →+* 𝕎 R) (h : ∀ k, (truncate k).comp g₁ = (truncate k).comp g₂) :
g₁ = g₂ :=
liftEquiv.symm.injective <| Subtype.ext <| funext h
end lift
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/FrobeniusFractionField.lean | import Mathlib.Data.Nat.Cast.WithTop
import Mathlib.FieldTheory.IsAlgClosed.Basic
import Mathlib.RingTheory.WittVector.DiscreteValuationRing
/-!
# Solving equations about the Frobenius map on the field of fractions of `𝕎 k`
The goal of this file is to prove `WittVector.exists_frobenius_solution_fractionRing`,
which says that for an algebraically closed field `k` of characteristic `p` and `a, b` in the
field of fractions of Witt vectors over `k`,
there is a solution `b` to the equation `φ b * a = p ^ m * b`, where `φ` is the Frobenius map.
Most of this file builds up the equivalent theorem over `𝕎 k` directly,
moving to the field of fractions at the end.
See `WittVector.frobeniusRotation` and its specification.
The construction proceeds by recursively defining a sequence of coefficients as solutions to a
polynomial equation in `k`. We must define these as generic polynomials using Witt vector API
(`WittVector.wittMul`, `wittPolynomial`) to show that they satisfy the desired equation.
Preliminary work is done in the dependency `RingTheory.WittVector.MulCoeff`
to isolate the `n+1`st coefficients of `x` and `y` in the `n+1`st coefficient of `x*y`.
This construction is described in Dupuis, Lewis, and Macbeth,
[Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022].
We approximately follow an approach sketched on MathOverflow:
<https://mathoverflow.net/questions/62468/about-frobenius-of-witt-vectors>
The result is a dependency for the proof of `WittVector.isocrystal_classification`,
the classification of one-dimensional isocrystals over an algebraically closed field.
-/
noncomputable section
namespace WittVector
variable (p : ℕ) [hp : Fact p.Prime]
local notation "𝕎" => WittVector p
namespace RecursionMain
/-!
## The recursive case of the vector coefficients
The first coefficient of our solution vector is easy to define below.
In this section we focus on the recursive case.
The goal is to turn `WittVector.wittPolyProd n` into a univariate polynomial
whose variable represents the `n`th coefficient of `x` in `x * a`.
-/
section CommRing
variable {k : Type*} [CommRing k] [CharP k p]
open Polynomial
/-- The root of this polynomial determines the `n+1`st coefficient of our solution. -/
def succNthDefiningPoly (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k) : Polynomial k :=
X ^ p * C (a₁.coeff 0 ^ p ^ (n + 1)) - X * C (a₂.coeff 0 ^ p ^ (n + 1)) +
C
(a₁.coeff (n + 1) * (bs 0 ^ p) ^ p ^ (n + 1) +
nthRemainder p n (fun v => bs v ^ p) (truncateFun (n + 1) a₁) -
a₂.coeff (n + 1) * bs 0 ^ p ^ (n + 1) -
nthRemainder p n bs (truncateFun (n + 1) a₂))
theorem succNthDefiningPoly_degree [IsDomain k] (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k)
(ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
(succNthDefiningPoly p n a₁ a₂ bs).degree = p := by
have : (X ^ p * C (a₁.coeff 0 ^ p ^ (n + 1))).degree = (p : WithBot ℕ) := by
rw [degree_mul, degree_C]
· simp only [Nat.cast_withBot, add_zero, degree_X, degree_pow, Nat.smul_one_eq_cast]
· exact pow_ne_zero _ ha₁
have : (X ^ p * C (a₁.coeff 0 ^ p ^ (n + 1)) - X * C (a₂.coeff 0 ^ p ^ (n + 1))).degree =
(p : WithBot ℕ) := by
rw [degree_sub_eq_left_of_degree_lt, this]
rw [this, degree_mul, degree_C, degree_X, add_zero]
· exact mod_cast hp.out.one_lt
· exact pow_ne_zero _ ha₂
rw [succNthDefiningPoly, degree_add_eq_left_of_degree_lt, this]
apply lt_of_le_of_lt degree_C_le
rw [this]
exact mod_cast hp.out.pos
end CommRing
section IsAlgClosed
variable {k : Type*} [Field k] [CharP k p] [IsAlgClosed k]
theorem root_exists (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k) (ha₁ : a₁.coeff 0 ≠ 0)
(ha₂ : a₂.coeff 0 ≠ 0) : ∃ b : k, (succNthDefiningPoly p n a₁ a₂ bs).IsRoot b :=
IsAlgClosed.exists_root _ <| by
simp only [succNthDefiningPoly_degree p n a₁ a₂ bs ha₁ ha₂, ne_eq, Nat.cast_eq_zero,
hp.out.ne_zero, not_false_eq_true]
/-- This is the `n+1`st coefficient of our solution, projected from `root_exists`. -/
def succNthVal (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k) (ha₁ : a₁.coeff 0 ≠ 0)
(ha₂ : a₂.coeff 0 ≠ 0) : k :=
Classical.choose (root_exists p n a₁ a₂ bs ha₁ ha₂)
theorem succNthVal_spec (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k) (ha₁ : a₁.coeff 0 ≠ 0)
(ha₂ : a₂.coeff 0 ≠ 0) :
(succNthDefiningPoly p n a₁ a₂ bs).IsRoot (succNthVal p n a₁ a₂ bs ha₁ ha₂) :=
Classical.choose_spec (root_exists p n a₁ a₂ bs ha₁ ha₂)
theorem succNthVal_spec' (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k) (ha₁ : a₁.coeff 0 ≠ 0)
(ha₂ : a₂.coeff 0 ≠ 0) :
succNthVal p n a₁ a₂ bs ha₁ ha₂ ^ p * a₁.coeff 0 ^ p ^ (n + 1) +
a₁.coeff (n + 1) * (bs 0 ^ p) ^ p ^ (n + 1) +
nthRemainder p n (fun v => bs v ^ p) (truncateFun (n + 1) a₁) =
succNthVal p n a₁ a₂ bs ha₁ ha₂ * a₂.coeff 0 ^ p ^ (n + 1) +
a₂.coeff (n + 1) * bs 0 ^ p ^ (n + 1) +
nthRemainder p n bs (truncateFun (n + 1) a₂) := by
rw [← sub_eq_zero]
have := succNthVal_spec p n a₁ a₂ bs ha₁ ha₂
simp only [Polynomial.eval_X, Polynomial.eval_C,
Polynomial.eval_pow, succNthDefiningPoly, Polynomial.eval_mul, Polynomial.eval_add,
Polynomial.eval_sub, Polynomial.IsRoot.def]
at this
convert this using 1
ring
end IsAlgClosed
end RecursionMain
namespace RecursionBase
variable {k : Type*} [Field k] [IsAlgClosed k]
theorem solution_pow (a₁ a₂ : 𝕎 k) : ∃ x : k, x ^ (p - 1) = a₂.coeff 0 / a₁.coeff 0 :=
IsAlgClosed.exists_pow_nat_eq _ <| tsub_pos_of_lt hp.out.one_lt
/-- The base case (0th coefficient) of our solution vector. -/
def solution (a₁ a₂ : 𝕎 k) : k :=
Classical.choose <| solution_pow p a₁ a₂
theorem solution_spec (a₁ a₂ : 𝕎 k) : solution p a₁ a₂ ^ (p - 1) = a₂.coeff 0 / a₁.coeff 0 :=
Classical.choose_spec <| solution_pow p a₁ a₂
theorem solution_nonzero {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
solution p a₁ a₂ ≠ 0 := by
intro h
have := solution_spec p a₁ a₂
rw [h, zero_pow] at this
· simpa [ha₁, ha₂] using _root_.div_eq_zero_iff.mp this.symm
· exact Nat.sub_ne_zero_of_lt hp.out.one_lt
theorem solution_spec' {a₁ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (a₂ : 𝕎 k) :
solution p a₁ a₂ ^ p * a₁.coeff 0 = solution p a₁ a₂ * a₂.coeff 0 := by
have := solution_spec p a₁ a₂
obtain ⟨q, hq⟩ := Nat.exists_eq_succ_of_ne_zero hp.out.ne_zero
have hq' : q = p - 1 := by simp only [hq, tsub_zero, Nat.succ_sub_succ_eq_sub]
conv_lhs =>
congr
congr
· skip
· rw [hq]
rw [pow_succ', hq', this]
field
end RecursionBase
open RecursionMain RecursionBase
section FrobeniusRotation
section IsAlgClosed
variable {k : Type*} [Field k] [CharP k p] [IsAlgClosed k]
/-- Recursively defines the sequence of coefficients for `WittVector.frobeniusRotation`. -/
noncomputable def frobeniusRotationCoeff {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0)
(ha₂ : a₂.coeff 0 ≠ 0) : ℕ → k
| 0 => solution p a₁ a₂
| n + 1 => succNthVal p n a₁ a₂ (fun i => frobeniusRotationCoeff ha₁ ha₂ i.val) ha₁ ha₂
/-- For nonzero `a₁` and `a₂`, `frobeniusRotation a₁ a₂` is a Witt vector that satisfies the
equation `frobenius (frobeniusRotation a₁ a₂) * a₁ = (frobeniusRotation a₁ a₂) * a₂`.
-/
def frobeniusRotation {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) : 𝕎 k :=
WittVector.mk p (frobeniusRotationCoeff p ha₁ ha₂)
theorem frobeniusRotation_nonzero {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
frobeniusRotation p ha₁ ha₂ ≠ 0 := by
intro h
apply solution_nonzero p ha₁ ha₂
simpa [← h, frobeniusRotation, frobeniusRotationCoeff] using WittVector.zero_coeff p k 0
theorem frobenius_frobeniusRotation {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
frobenius (frobeniusRotation p ha₁ ha₂) * a₁ = frobeniusRotation p ha₁ ha₂ * a₂ := by
ext n
rcases n with - | n
· simp only [WittVector.mul_coeff_zero, WittVector.coeff_frobenius_charP, frobeniusRotation,
coeff_mk, frobeniusRotationCoeff]
exact solution_spec' _ ha₁ _
· simp only [nthRemainder_spec, WittVector.coeff_frobenius_charP,
frobeniusRotation, coeff_mk, frobeniusRotationCoeff]
have :=
succNthVal_spec' p n a₁ a₂ (fun i : Fin (n + 1) => frobeniusRotationCoeff p ha₁ ha₂ i.val)
ha₁ ha₂
simp only [frobeniusRotationCoeff, Fin.val_zero] at this
convert this using 3; clear this
apply TruncatedWittVector.ext
intro i
simp only [WittVector.coeff_truncateFun, WittVector.coeff_frobenius_charP]
rfl
local notation "φ" => IsFractionRing.ringEquivOfRingEquiv (frobeniusEquiv p k)
-- see https://github.com/leanprover-community/mathlib4/issues/29041
set_option linter.unusedSimpArgs false in
theorem exists_frobenius_solution_fractionRing_aux (m n : ℕ) (r' q' : 𝕎 k) (hr' : r'.coeff 0 ≠ 0)
(hq' : q'.coeff 0 ≠ 0) (hq : (p : 𝕎 k) ^ n * q' ∈ nonZeroDivisors (𝕎 k)) :
let b : 𝕎 k := frobeniusRotation p hr' hq'
IsFractionRing.ringEquivOfRingEquiv (frobeniusEquiv p k)
(algebraMap (𝕎 k) (FractionRing (𝕎 k)) b) *
Localization.mk ((p : 𝕎 k) ^ m * r') ⟨(p : 𝕎 k) ^ n * q', hq⟩ =
(p : Localization (nonZeroDivisors (𝕎 k))) ^ (m - n : ℤ) *
algebraMap (𝕎 k) (FractionRing (𝕎 k)) b := by
intro b
have key : WittVector.frobenius b * r' = q' * b := by
linear_combination frobenius_frobeniusRotation p hr' hq'
have hq'' : algebraMap (𝕎 k) (FractionRing (𝕎 k)) q' ≠ 0 := by
have hq''' : q' ≠ 0 := fun h => hq' (by simp [h])
simpa only [Ne, map_zero] using
(IsFractionRing.injective (𝕎 k) (FractionRing (𝕎 k))).ne hq'''
rw [zpow_sub₀ (FractionRing.p_nonzero p k)]
simp [field, FractionRing.p_nonzero p k]
convert congr_arg (fun x => algebraMap (𝕎 k) (FractionRing (𝕎 k)) x) key using 1
· simp only [RingHom.map_mul]
· simp only [RingHom.map_mul]
theorem exists_frobenius_solution_fractionRing {a : FractionRing (𝕎 k)} (ha : a ≠ 0) :
∃ᵉ (b ≠ 0) (m : ℤ), φ b * a = (p : FractionRing (𝕎 k)) ^ m * b := by
revert ha
refine Localization.induction_on a ?_
rintro ⟨r, q, hq⟩ hrq
have hq0 : q ≠ 0 := mem_nonZeroDivisors_iff_ne_zero.1 hq
have hr0 : r ≠ 0 := fun h => hrq (by simp [h])
obtain ⟨m, r', hr', rfl⟩ := exists_eq_pow_p_mul r hr0
obtain ⟨n, q', hq', rfl⟩ := exists_eq_pow_p_mul q hq0
let b := frobeniusRotation p hr' hq'
refine ⟨algebraMap (𝕎 k) (FractionRing (𝕎 k)) b, ?_, m - n, ?_⟩
· simpa only [map_zero] using
(IsFractionRing.injective (WittVector p k) (FractionRing (WittVector p k))).ne
(frobeniusRotation_nonzero p hr' hq')
exact exists_frobenius_solution_fractionRing_aux p m n r' q' hr' hq' hq
end IsAlgClosed
end FrobeniusRotation
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/MulP.lean | import Mathlib.RingTheory.WittVector.IsPoly
/-!
## Multiplication by `n` in the ring of Witt vectors
In this file we show that multiplication by `n` in the ring of Witt vectors
is a polynomial function. We then use this fact to show that the composition of Frobenius
and Verschiebung is equal to multiplication by `p`.
### Main declarations
* `mulN_isPoly`: multiplication by `n` is a polynomial function
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
variable {p : ℕ} {R : Type*} [hp : Fact p.Prime] [CommRing R]
local notation "𝕎" => WittVector p -- type as `\bbW`
open MvPolynomial
noncomputable section
variable (p) in
/-- `wittMulN p n` is the family of polynomials that computes
the coefficients of `x * n` in terms of the coefficients of the Witt vector `x`. -/
noncomputable def wittMulN : ℕ → ℕ → MvPolynomial ℕ ℤ
| 0 => 0
| n + 1 => fun k => bind₁ (Function.uncurry <| ![wittMulN n, X]) (wittAdd p k)
theorem mulN_coeff (n : ℕ) (x : 𝕎 R) (k : ℕ) :
(x * n).coeff k = aeval x.coeff (wittMulN p n k) := by
induction n generalizing k with
| zero => simp only [Nat.cast_zero, mul_zero, zero_coeff, wittMulN, Pi.zero_apply, map_zero]
| succ n ih =>
rw [wittMulN, Nat.cast_add, Nat.cast_one, mul_add, mul_one, aeval_bind₁, add_coeff]
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext1 ⟨b, i⟩
fin_cases b
· simp [Function.uncurry, Matrix.cons_val_zero, ih]
· simp [Function.uncurry, Matrix.cons_val_one, aeval_X]
variable (p)
/-- Multiplication by `n` is a polynomial function. -/
@[is_poly]
theorem mulN_isPoly (n : ℕ) : IsPoly p fun _ _Rcr x => x * n :=
⟨⟨wittMulN p n, fun R _Rcr x => by funext k; exact mulN_coeff n x k⟩⟩
@[simp]
theorem bind₁_wittMulN_wittPolynomial (n k : ℕ) :
bind₁ (wittMulN p n) (wittPolynomial p ℤ k) = n * wittPolynomial p ℤ k := by
induction n with
| zero => simp [wittMulN, zero_mul, bind₁_zero_wittPolynomial]
| succ n ih =>
rw [wittMulN, ← bind₁_bind₁, wittAdd, wittStructureInt_prop]
simp only [map_add, Nat.cast_succ, bind₁_X_right]
rw [add_mul, one_mul, bind₁_rename, bind₁_rename]
simp only [ih, Function.uncurry, Function.comp_def, bind₁_X_left, AlgHom.id_apply,
Matrix.cons_val_zero, Matrix.cons_val_one]
end
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/Identities.lean | import Mathlib.RingTheory.WittVector.Frobenius
import Mathlib.RingTheory.WittVector.Verschiebung
import Mathlib.RingTheory.WittVector.MulP
/-!
## Identities between operations on the ring of Witt vectors
In this file we derive common identities between the Frobenius and Verschiebung operators.
## Main declarations
* `frobenius_verschiebung`: the composition of Frobenius and Verschiebung is multiplication by `p`
* `verschiebung_mul_frobenius`: the “projection formula”: `V(x * F y) = V x * y`
* `iterate_verschiebung_mul_coeff`: an identity from [Haze09] 6.2
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
variable {p : ℕ} {R : Type*} [hp : Fact p.Prime] [CommRing R]
-- type as `\bbW`
local notation "𝕎" => WittVector p
noncomputable section
-- Porting note: `ghost_calc` failure: the manual instances had to be added.
/-- The composition of Frobenius and Verschiebung is multiplication by `p`. -/
theorem frobenius_verschiebung (x : 𝕎 R) : frobenius (verschiebung x) = x * p := by
have : IsPoly p fun {R} [CommRing R] x ↦ frobenius (verschiebung x) :=
IsPoly.comp (hg := frobenius_isPoly p) (hf := verschiebung_isPoly)
have : IsPoly p fun {R} [CommRing R] x ↦ x * p := mulN_isPoly p p
ghost_calc x
ghost_simp [mul_comm]
/-- Verschiebung is the same as multiplication by `p` on the ring of Witt vectors of `ZMod p`. -/
theorem verschiebung_zmod (x : 𝕎 (ZMod p)) : verschiebung x = x * p := by
rw [← frobenius_verschiebung, frobenius_zmodp]
variable (p R)
theorem coeff_p_pow [CharP R p] (i : ℕ) : ((p : 𝕎 R) ^ i).coeff i = 1 := by
induction i with
| zero => simp only [one_coeff_zero, pow_zero]
| succ i h =>
rw [pow_succ, ← frobenius_verschiebung, coeff_frobenius_charP,
verschiebung_coeff_succ, h, one_pow]
theorem coeff_p_pow_eq_zero [CharP R p] {i j : ℕ} (hj : j ≠ i) : ((p : 𝕎 R) ^ i).coeff j = 0 := by
induction i generalizing j with
| zero =>
rw [pow_zero, one_coeff_eq_of_pos]
exact Nat.pos_of_ne_zero hj
| succ i hi =>
rw [pow_succ, ← frobenius_verschiebung, coeff_frobenius_charP]
cases j
· rw [verschiebung_coeff_zero, zero_pow hp.out.ne_zero]
· rw [verschiebung_coeff_succ, hi (ne_of_apply_ne _ hj), zero_pow hp.out.ne_zero]
theorem coeff_p [CharP R p] (i : ℕ) : (p : 𝕎 R).coeff i = if i = 1 then 1 else 0 := by
split_ifs with hi
· simpa only [hi, pow_one] using coeff_p_pow p R 1
· simpa only [pow_one] using coeff_p_pow_eq_zero p R hi
@[simp]
theorem coeff_p_zero [CharP R p] : (p : 𝕎 R).coeff 0 = 0 := by
rw [coeff_p, if_neg]
exact zero_ne_one
@[simp]
theorem coeff_p_one [CharP R p] : (p : 𝕎 R).coeff 1 = 1 := by rw [coeff_p, if_pos rfl]
theorem p_nonzero [Nontrivial R] [CharP R p] : (p : 𝕎 R) ≠ 0 := by
intro h
simpa only [h, zero_coeff, zero_ne_one] using coeff_p_one p R
theorem FractionRing.p_nonzero [Nontrivial R] [CharP R p] : (p : FractionRing (𝕎 R)) ≠ 0 := by
simpa using (IsFractionRing.injective (𝕎 R) (FractionRing (𝕎 R))).ne (WittVector.p_nonzero _ _)
variable {p R}
-- Porting note: `ghost_calc` failure: the manual instances had to be added.
/-- The “projection formula” for Frobenius and Verschiebung. -/
theorem verschiebung_mul_frobenius (x y : 𝕎 R) :
verschiebung (x * frobenius y) = verschiebung x * y := by
have : IsPoly₂ p fun {R} [Rcr : CommRing R] x y ↦ verschiebung (x * frobenius y) :=
IsPoly.comp₂ (hg := verschiebung_isPoly)
(hf := IsPoly₂.comp (hh := mulIsPoly₂) (hf := idIsPolyI' p) (hg := frobenius_isPoly p))
have : IsPoly₂ p fun {R} [CommRing R] x y ↦ verschiebung x * y :=
IsPoly₂.comp (hh := mulIsPoly₂) (hf := verschiebung_isPoly) (hg := idIsPolyI' p)
ghost_calc x y
rintro ⟨⟩ <;> ghost_simp [mul_assoc]
theorem mul_charP_coeff_zero [CharP R p] (x : 𝕎 R) : (x * p).coeff 0 = 0 := by
rw [← frobenius_verschiebung, coeff_frobenius_charP, verschiebung_coeff_zero,
zero_pow hp.out.ne_zero]
theorem mul_charP_coeff_succ [CharP R p] (x : 𝕎 R) (i : ℕ) :
(x * p).coeff (i + 1) = x.coeff i ^ p := by
rw [← frobenius_verschiebung, coeff_frobenius_charP, verschiebung_coeff_succ]
theorem mul_pow_charP_coeff_zero [CharP R p] (x : 𝕎 R) {m n : ℕ} (h : m < n) :
(x * p ^ n).coeff m = 0 := by
induction n generalizing m with
| zero => contradiction
| succ n ih =>
rw [pow_succ, ← mul_assoc]
cases m with
| zero => exact mul_charP_coeff_zero _
| succ m' =>
rw [mul_charP_coeff_succ, ih, zero_pow hp.out.ne_zero]
simpa using h
theorem mul_pow_charP_coeff_succ [CharP R p] (x : 𝕎 R) {m n : ℕ} :
(x * p ^ n).coeff (m + n) = x.coeff m ^ (p ^ n) := by
induction n generalizing m with
| zero => simp
| succ n ih =>
rw [pow_succ, ← mul_assoc, ← add_assoc, mul_charP_coeff_succ, pow_succ, pow_mul]
congr
exact ih
theorem verschiebung_frobenius [CharP R p] (x : 𝕎 R) : verschiebung (frobenius x) = x * p := by
ext ⟨i⟩
· rw [mul_charP_coeff_zero, verschiebung_coeff_zero]
· rw [mul_charP_coeff_succ, verschiebung_coeff_succ, coeff_frobenius_charP]
theorem verschiebung_frobenius_comm [CharP R p] :
Function.Commute (verschiebung : 𝕎 R → 𝕎 R) frobenius := fun x => by
rw [verschiebung_frobenius, frobenius_verschiebung]
/-!
## Iteration lemmas
-/
open Function
theorem iterate_verschiebung_coeff_eq_zero (x : 𝕎 R) {n : ℕ} {m : ℕ} (h : m < n) :
(verschiebung^[n] x).coeff m = 0 := by
induction n generalizing m with
| zero => contradiction
| succ n ih =>
rw [iterate_succ_apply']
cases m with
| zero => exact verschiebung_coeff_zero _
| succ m' =>
rw [verschiebung_coeff_succ, ih]
simpa using h
theorem iterate_verschiebung_coeff (x : 𝕎 R) (n k : ℕ) :
(verschiebung^[n] x).coeff (k + n) = x.coeff k := by
induction n with
| zero => simp
| succ k ih => rw [iterate_succ_apply', Nat.add_succ, verschiebung_coeff_succ]; exact ih
theorem iterate_verschiebung_mul_left (x y : 𝕎 R) (i : ℕ) :
verschiebung^[i] x * y = verschiebung^[i] (x * frobenius^[i] y) := by
induction i generalizing y with
| zero => simp
| succ i ih =>
rw [iterate_succ_apply', ← verschiebung_mul_frobenius, ih, iterate_succ_apply',
iterate_succ_apply]
section CharP
variable [CharP R p]
theorem iterate_verschiebung_mul (x y : 𝕎 R) (i j : ℕ) :
verschiebung^[i] x * verschiebung^[j] y =
verschiebung^[i + j] (frobenius^[j] x * frobenius^[i] y) := by
calc
_ = verschiebung^[i] (x * frobenius^[i] (verschiebung^[j] y)) := ?_
_ = verschiebung^[i] (x * verschiebung^[j] (frobenius^[i] y)) := ?_
_ = verschiebung^[i] (verschiebung^[j] (frobenius^[i] y) * x) := ?_
_ = verschiebung^[i] (verschiebung^[j] (frobenius^[i] y * frobenius^[j] x)) := ?_
_ = verschiebung^[i + j] (frobenius^[i] y * frobenius^[j] x) := ?_
_ = _ := ?_
· apply iterate_verschiebung_mul_left
· rw [verschiebung_frobenius_comm.iterate_iterate]
· rw [mul_comm]
· rw [iterate_verschiebung_mul_left]
· rw [iterate_add_apply]
· rw [mul_comm]
theorem iterate_frobenius_coeff (x : 𝕎 R) (i k : ℕ) :
(frobenius^[i] x).coeff k = x.coeff k ^ p ^ i := by
induction i with
| zero => simp
| succ i ih => rw [iterate_succ_apply', coeff_frobenius_charP, ih]; ring_nf
/-- This is a slightly specialized form of [Hazewinkel, *Witt Vectors*][Haze09] 6.2 equation 5. -/
theorem iterate_verschiebung_mul_coeff (x y : 𝕎 R) (i j : ℕ) :
(verschiebung^[i] x * verschiebung^[j] y).coeff (i + j) =
x.coeff 0 ^ p ^ j * y.coeff 0 ^ p ^ i := by
calc
_ = (verschiebung^[i + j] (frobenius^[j] x * frobenius^[i] y)).coeff (i + j) := ?_
_ = (frobenius^[j] x * frobenius^[i] y).coeff 0 := ?_
_ = (frobenius^[j] x).coeff 0 * (frobenius^[i] y).coeff 0 := ?_
_ = _ := ?_
· rw [iterate_verschiebung_mul]
· convert iterate_verschiebung_coeff (p := p) (R := R) _ _ _ using 2
rw [zero_add]
· apply mul_coeff_zero
· simp only [iterate_frobenius_coeff]
theorem iterate_verschiebung_iterate_frobenius (x : 𝕎 R) (n : ℕ) :
verschiebung^[n] (frobenius^[n] x) = x * (p ^ n) := by
rw [← comp_apply (f := verschiebung^[n]),
← Function.Commute.comp_iterate verschiebung_frobenius_comm]
induction n with
| zero => simp
| succ n ih =>
rw [iterate_succ_apply', ih, pow_succ, comp_apply, verschiebung_frobenius, mul_assoc]
end CharP
end
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/Isocrystal.lean | import Mathlib.RingTheory.WittVector.FrobeniusFractionField
/-!
## F-isocrystals over a perfect field
When `k` is an integral domain, so is `𝕎 k`, and we can consider its field of fractions `K(p, k)`.
The endomorphism `WittVector.frobenius` lifts to `φ : K(p, k) → K(p, k)`; if `k` is perfect, `φ` is
an automorphism.
Let `k` be a perfect integral domain. Let `V` be a vector space over `K(p,k)`.
An *isocrystal* is a bijective map `V → V` that is `φ`-semilinear.
A theorem of Dieudonné and Manin classifies the finite-dimensional isocrystals over algebraically
closed fields. In the one-dimensional case, this classification states that the isocrystal
structures are parametrized by their "slope" `m : ℤ`.
Any one-dimensional isocrystal is isomorphic to `φ(p^m • x) : K(p,k) → K(p,k)` for some `m`.
This file proves this one-dimensional case of the classification theorem.
The construction is described in Dupuis, Lewis, and Macbeth,
[Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022].
## Main declarations
* `WittVector.Isocrystal`: a vector space over the field `K(p, k)` additionally equipped with a
Frobenius-linear automorphism.
* `WittVector.isocrystal_classification`: a one-dimensional isocrystal admits an isomorphism to one
of the standard one-dimensional isocrystals.
## Notation
This file introduces notation in the scope `Isocrystal`.
* `K(p, k)`: `FractionRing (WittVector p k)`
* `φ(p, k)`: `WittVector.FractionRing.frobeniusRingHom p k`
* `M →ᶠˡ[p, k] M₂`: `LinearMap (WittVector.FractionRing.frobeniusRingHom p k) M M₂`
* `M ≃ᶠˡ[p, k] M₂`: `LinearEquiv (WittVector.FractionRing.frobeniusRingHom p k) M M₂`
* `Φ(p, k)`: `WittVector.Isocrystal.frobenius p k`
* `M →ᶠⁱ[p, k] M₂`: `WittVector.IsocrystalHom p k M M₂`
* `M ≃ᶠⁱ[p, k] M₂`: `WittVector.IsocrystalEquiv p k M M₂`
## References
* [Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022]
* [Theory of commutative formal groups over fields of finite characteristic][manin1963]
* <https://www.math.ias.edu/~lurie/205notes/Lecture26-Isocrystals.pdf>
-/
noncomputable section
open Module
namespace WittVector
variable (p : ℕ) [Fact p.Prime]
variable (k : Type*) [CommRing k]
/-- The fraction ring of the space of `p`-Witt vectors on `k` -/
scoped[Isocrystal] notation "K(" p ", " k ")" => FractionRing (WittVector p k)
open Isocrystal
section PerfectRing
variable [IsDomain k] [CharP k p] [PerfectRing k p]
/-! ### Frobenius-linear maps -/
/-- The Frobenius automorphism of `k` induces an automorphism of `K`. -/
def FractionRing.frobenius : K(p, k) ≃+* K(p, k) :=
IsFractionRing.ringEquivOfRingEquiv (frobeniusEquiv p k)
/-- The Frobenius automorphism of `k` induces an endomorphism of `K`. For notation purposes.
Notation `φ(p, k)` in the `Isocrystal` namespace. -/
def FractionRing.frobeniusRingHom : K(p, k) →+* K(p, k) :=
FractionRing.frobenius p k
@[inherit_doc]
scoped[Isocrystal] notation "φ(" p ", " k ")" => WittVector.FractionRing.frobeniusRingHom p k
instance inv_pair₁ : RingHomInvPair φ(p, k) (FractionRing.frobenius p k).symm :=
RingHomInvPair.of_ringEquiv (FractionRing.frobenius p k)
instance inv_pair₂ : RingHomInvPair ((FractionRing.frobenius p k).symm : K(p, k) →+* K(p, k))
(FractionRing.frobenius p k) :=
RingHomInvPair.of_ringEquiv (FractionRing.frobenius p k).symm
/-- The Frobenius automorphism of `k`, as a linear map -/
scoped[Isocrystal]
notation3:50 M " →ᶠˡ[" p ", " k "] " M₂ =>
LinearMap (WittVector.FractionRing.frobeniusRingHom p k) M M₂
/-- The Frobenius automorphism of `k`, as a linear equivalence -/
scoped[Isocrystal]
notation3:50 M " ≃ᶠˡ[" p ", " k "] " M₂ =>
LinearEquiv (WittVector.FractionRing.frobeniusRingHom p k) M M₂
/-! ### Isocrystals -/
/-- An isocrystal is a vector space over the field `K(p, k)` additionally equipped with a
Frobenius-linear automorphism.
-/
class Isocrystal (V : Type*) [AddCommGroup V] extends Module K(p, k) V where
frob : V ≃ᶠˡ[p, k] V
open WittVector
variable (V : Type*) [AddCommGroup V] [Isocrystal p k V]
variable (V₂ : Type*) [AddCommGroup V₂] [Isocrystal p k V₂]
variable {V} in
/--
Project the Frobenius automorphism from an isocrystal. Denoted by `Φ(p, k)` when V can be inferred.
-/
def Isocrystal.frobenius : V ≃ᶠˡ[p, k] V :=
Isocrystal.frob (p := p) (k := k) (V := V)
@[inherit_doc] scoped[Isocrystal] notation "Φ(" p ", " k ")" => WittVector.Isocrystal.frobenius p k
/-- A homomorphism between isocrystals respects the Frobenius map.
Notation `M →ᶠⁱ [p, k]` in the `Isocrystal` namespace. -/
structure IsocrystalHom extends V →ₗ[K(p, k)] V₂ where
frob_equivariant : ∀ x : V, Φ(p, k) (toLinearMap x) = toLinearMap (Φ(p, k) x)
/-- An isomorphism between isocrystals respects the Frobenius map.
Notation `M ≃ᶠⁱ [p, k]` in the `Isocrystal` namespace. -/
structure IsocrystalEquiv extends V ≃ₗ[K(p, k)] V₂ where
frob_equivariant : ∀ x : V, Φ(p, k) (toLinearEquiv x) = toLinearEquiv (Φ(p, k) x)
@[inherit_doc] scoped[Isocrystal]
notation:50 M " →ᶠⁱ[" p ", " k "] " M₂ => WittVector.IsocrystalHom p k M M₂
@[inherit_doc] scoped[Isocrystal]
notation:50 M " ≃ᶠⁱ[" p ", " k "] " M₂ => WittVector.IsocrystalEquiv p k M M₂
end PerfectRing
open scoped Isocrystal
/-! ### Classification of isocrystals in dimension 1 -/
/-- Type synonym for `K(p, k)` to carry the standard 1-dimensional isocrystal structure
of slope `m : ℤ`.
-/
@[nolint unusedArguments]
def StandardOneDimIsocrystal (_m : ℤ) : Type _ :=
K(p, k)
deriving AddCommGroup, Module K(p, k)
section PerfectRing
variable [IsDomain k] [CharP k p] [PerfectRing k p]
/-- The standard one-dimensional isocrystal of slope `m : ℤ` is an isocrystal. -/
instance (m : ℤ) : Isocrystal p k (StandardOneDimIsocrystal p k m) where
frob :=
(FractionRing.frobenius p k).toSemilinearEquiv.trans
(LinearEquiv.smulOfNeZero _ _ _ (zpow_ne_zero m (WittVector.FractionRing.p_nonzero p k)))
@[simp]
theorem StandardOneDimIsocrystal.frobenius_apply (m : ℤ) (x : StandardOneDimIsocrystal p k m) :
Φ(p, k) x = (p : K(p, k)) ^ m • φ(p, k) x := rfl
end PerfectRing
/-- A one-dimensional isocrystal over an algebraically closed field
admits an isomorphism to one of the standard (indexed by `m : ℤ`) one-dimensional isocrystals. -/
theorem isocrystal_classification (k : Type*) [Field k] [IsAlgClosed k] [CharP k p] (V : Type*)
[AddCommGroup V] [Isocrystal p k V] (h_dim : finrank K(p, k) V = 1) :
∃ m : ℤ, Nonempty (StandardOneDimIsocrystal p k m ≃ᶠⁱ[p, k] V) := by
haveI : Nontrivial V := Module.nontrivial_of_finrank_eq_succ h_dim
obtain ⟨x, hx⟩ : ∃ x : V, x ≠ 0 := exists_ne 0
have : Φ(p, k) x ≠ 0 := by simpa only [map_zero] using Φ(p, k).injective.ne hx
obtain ⟨a, ha, hax⟩ : ∃ a : K(p, k), a ≠ 0 ∧ Φ(p, k) x = a • x := by
rw [finrank_eq_one_iff_of_nonzero' x hx] at h_dim
obtain ⟨a, ha⟩ := h_dim (Φ(p, k) x)
refine ⟨a, ?_, ha.symm⟩
intro ha'
apply this
simp only [← ha, ha', zero_smul]
obtain ⟨b, hb, m, hmb⟩ := WittVector.exists_frobenius_solution_fractionRing p ha
replace hmb : φ(p, k) b * a = (p : K(p, k)) ^ m * b := by convert hmb
use m
let F₀ : StandardOneDimIsocrystal p k m →ₗ[K(p, k)] V := LinearMap.toSpanSingleton K(p, k) V x
let F : StandardOneDimIsocrystal p k m ≃ₗ[K(p, k)] V := by
refine LinearEquiv.ofBijective F₀ ⟨?_, ?_⟩
· rw [← LinearMap.ker_eq_bot]
exact LinearMap.ker_toSpanSingleton K(p, k) V hx
· rw [← LinearMap.range_eq_top]
rw [← (finrank_eq_one_iff_of_nonzero x hx).mp h_dim]
rw [LinearMap.span_singleton_eq_range]
refine ⟨⟨(LinearEquiv.smulOfNeZero K(p, k) _ _ hb).trans F, fun c ↦ ?_⟩⟩
rw [LinearEquiv.trans_apply, LinearEquiv.trans_apply, LinearEquiv.smulOfNeZero_apply,
LinearEquiv.smulOfNeZero_apply, LinearEquiv.map_smul, LinearEquiv.map_smul,
LinearEquiv.ofBijective_apply, LinearEquiv.ofBijective_apply,
StandardOneDimIsocrystal.frobenius_apply]
unfold StandardOneDimIsocrystal
rw [LinearMap.toSpanSingleton_apply K(p, k) V x c, LinearMap.toSpanSingleton_apply K(p, k) V x]
simp only [hax,
LinearEquiv.map_smulₛₗ, Algebra.id.smul_eq_mul]
simp only [← mul_smul]
congr 1
linear_combination φ(p, k) c * hmb
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/WittVector/Teichmuller.lean | import Mathlib.RingTheory.WittVector.Basic
/-!
# Teichmüller lifts
This file defines `WittVector.teichmuller`, a monoid hom `R →* 𝕎 R`, which embeds `r : R` as the
`0`-th component of a Witt vector whose other coefficients are `0`.
## Main declarations
- `WittVector.teichmuller`: the Teichmuller map.
- `WittVector.map_teichmuller`: `WittVector.teichmuller` is a natural transformation.
- `WittVector.ghostComponent_teichmuller`:
the `n`-th ghost component of `WittVector.teichmuller p r` is `r ^ p ^ n`.
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
open MvPolynomial
variable (p : ℕ) {R S : Type*} [hp : Fact p.Prime] [CommRing R] [CommRing S]
local notation "𝕎" => WittVector p -- type as `\bbW`
/-- The underlying function of the monoid hom `WittVector.teichmuller`.
The `0`-th coefficient of `teichmullerFun p r` is `r`, and all others are `0`.
-/
def teichmullerFun (r : R) : 𝕎 R :=
⟨fun n => if n = 0 then r else 0⟩
/-!
## `teichmuller` is a monoid homomorphism
On ghost components, it is clear that `teichmullerFun` is a monoid homomorphism.
But in general the ghost map is not injective.
We follow the same strategy as for proving that the ring operations on `𝕎 R`
satisfy the ring axioms.
1. We first prove it for rings `R` where `p` is invertible,
because then the ghost map is in fact an isomorphism.
2. After that, we derive the result for `MvPolynomial R ℤ`,
3. and from that we can prove the result for arbitrary `R`.
-/
private theorem ghostComponent_teichmullerFun (r : R) (n : ℕ) :
ghostComponent n (teichmullerFun p r) = r ^ p ^ n := by
rw [ghostComponent_apply, aeval_wittPolynomial, Finset.sum_eq_single 0, pow_zero, one_mul,
tsub_zero]
· rfl
· intro i _ h0
simp [teichmullerFun, h0, hp.1.ne_zero]
· rw [Finset.mem_range]; intro h; exact (h (Nat.succ_pos n)).elim
private theorem map_teichmullerFun (f : R →+* S) (r : R) :
map f (teichmullerFun p r) = teichmullerFun p (f r) := by
ext n; cases n
· rfl
· exact f.map_zero
private theorem teichmuller_mul_aux₁ {R : Type*} (x y : MvPolynomial R ℚ) :
teichmullerFun p (x * y) = teichmullerFun p x * teichmullerFun p y := by
apply (ghostMap.bijective_of_invertible p (MvPolynomial R ℚ)).1
rw [RingHom.map_mul]
ext1 n
simp only [Pi.mul_apply, ghostMap_apply, ghostComponent_teichmullerFun, mul_pow]
private theorem teichmuller_mul_aux₂ {R : Type*} (x y : MvPolynomial R ℤ) :
teichmullerFun p (x * y) = teichmullerFun p x * teichmullerFun p y := by
refine map_injective (MvPolynomial.map (Int.castRingHom ℚ))
(MvPolynomial.map_injective _ Int.cast_injective) ?_
simp only [teichmuller_mul_aux₁, map_teichmullerFun, RingHom.map_mul]
/-- The Teichmüller lift of an element of `R` to `𝕎 R`.
The `0`-th coefficient of `teichmuller p r` is `r`, and all others are `0`.
This is a monoid homomorphism. -/
def teichmuller : R →* 𝕎 R where
toFun := teichmullerFun p
map_one' := by
ext ⟨⟩
· rw [one_coeff_zero]; rfl
· rw [one_coeff_eq_of_pos _ _ _ (Nat.succ_pos _)]; rfl
map_mul' := by
intro x y
rcases counit_surjective R x with ⟨x, rfl⟩
rcases counit_surjective R y with ⟨y, rfl⟩
simp only [← map_teichmullerFun, ← RingHom.map_mul, teichmuller_mul_aux₂]
@[simp]
theorem teichmuller_coeff_zero (r : R) : (teichmuller p r).coeff 0 = r :=
rfl
@[simp]
theorem teichmuller_coeff_pos (r : R) : ∀ (n : ℕ) (_ : 0 < n), (teichmuller p r).coeff n = 0
| _ + 1, _ => rfl
@[simp]
theorem teichmuller_zero : teichmuller p (0 : R) = 0 := by
ext ⟨⟩ <;> · rw [zero_coeff]; rfl
/-- `teichmuller` is a natural transformation. -/
@[simp]
theorem map_teichmuller (f : R →+* S) (r : R) : map f (teichmuller p r) = teichmuller p (f r) :=
map_teichmullerFun _ _ _
/-- The `n`-th ghost component of `teichmuller p r` is `r ^ p ^ n`. -/
@[simp]
theorem ghostComponent_teichmuller (r : R) (n : ℕ) :
ghostComponent n (teichmuller p r) = r ^ p ^ n :=
ghostComponent_teichmullerFun _ _ _
end WittVector |
.lake/packages/mathlib/Mathlib/RingTheory/GradedAlgebra/Basic.lean | import Mathlib.Algebra.DirectSum.Algebra
import Mathlib.Algebra.DirectSum.Decomposition
import Mathlib.Algebra.DirectSum.Internal
import Mathlib.Algebra.DirectSum.Ring
/-!
# Internally-graded rings and algebras
This file defines the typeclass `GradedAlgebra 𝒜`, for working with an algebra `A` that is
internally graded by a collection of submodules `𝒜 : ι → Submodule R A`.
See the docstring of that typeclass for more information.
## Main definitions
* `GradedRing 𝒜`: the typeclass, which is a combination of `SetLike.GradedMonoid`, and
`DirectSum.Decomposition 𝒜`.
* `GradedAlgebra 𝒜`: A convenience alias for `GradedRing` when `𝒜` is a family of submodules.
* `DirectSum.decomposeRingEquiv 𝒜 : A ≃ₐ[R] ⨁ i, 𝒜 i`, a more bundled version of
`DirectSum.decompose 𝒜`.
* `DirectSum.decomposeAlgEquiv 𝒜 : A ≃ₐ[R] ⨁ i, 𝒜 i`, a more bundled version of
`DirectSum.decompose 𝒜`.
* `GradedAlgebra.proj 𝒜 i` is the linear map from `A` to its degree `i : ι` component, such that
`proj 𝒜 i x = decompose 𝒜 x i`.
## Implementation notes
For now, we do not have internally-graded semirings and internally-graded rings; these can be
represented with `𝒜 : ι → Submodule ℕ A` and `𝒜 : ι → Submodule ℤ A` respectively, since all
`Semiring`s are ℕ-algebras via `Semiring.toNatAlgebra`, and all `Ring`s are `ℤ`-algebras via
`Ring.toIntAlgebra`.
## Tags
graded algebra, graded ring, graded semiring, decomposition
-/
open DirectSum
variable {ι R A σ : Type*}
section GradedRing
variable [DecidableEq ι] [AddMonoid ι] [CommSemiring R] [Semiring A] [Algebra R A]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ)
open DirectSum
/-- An internally-graded `R`-algebra `A` is one that can be decomposed into a collection
of `Submodule R A`s indexed by `ι` such that the canonical map `A → ⨁ i, 𝒜 i` is bijective and
respects multiplication, i.e. the product of an element of degree `i` and an element of degree `j`
is an element of degree `i + j`.
Note that the fact that `A` is internally-graded, `GradedAlgebra 𝒜`, implies an externally-graded
algebra structure `DirectSum.GAlgebra R (fun i ↦ ↥(𝒜 i))`, which in turn makes available an
`Algebra R (⨁ i, 𝒜 i)` instance.
-/
class GradedRing (𝒜 : ι → σ) extends SetLike.GradedMonoid 𝒜, DirectSum.Decomposition 𝒜
variable [GradedRing 𝒜]
namespace DirectSum
/-- If `A` is graded by `ι` with degree `i` component `𝒜 i`, then it is isomorphic as
a ring to a direct sum of components. -/
def decomposeRingEquiv : A ≃+* ⨁ i, 𝒜 i :=
RingEquiv.symm
{ (decomposeAddEquiv 𝒜).symm with
map_mul' := (coeRingHom 𝒜).map_mul }
@[simp]
theorem decompose_one : decompose 𝒜 (1 : A) = 1 :=
map_one (decomposeRingEquiv 𝒜)
@[simp]
theorem decompose_symm_one : (decompose 𝒜).symm 1 = (1 : A) :=
map_one (decomposeRingEquiv 𝒜).symm
@[simp]
theorem decompose_mul (x y : A) : decompose 𝒜 (x * y) = decompose 𝒜 x * decompose 𝒜 y :=
map_mul (decomposeRingEquiv 𝒜) x y
@[simp]
theorem decompose_symm_mul (x y : ⨁ i, 𝒜 i) :
(decompose 𝒜).symm (x * y) = (decompose 𝒜).symm x * (decompose 𝒜).symm y :=
map_mul (decomposeRingEquiv 𝒜).symm x y
end DirectSum
/-- The projection maps of a graded ring -/
def GradedRing.proj (i : ι) : A →+ A :=
(AddSubmonoidClass.subtype (𝒜 i)).comp <|
(DFinsupp.evalAddMonoidHom i).comp <|
RingHom.toAddMonoidHom <| RingEquiv.toRingHom <| DirectSum.decomposeRingEquiv 𝒜
@[simp]
theorem GradedRing.proj_apply (i : ι) (r : A) :
GradedRing.proj 𝒜 i r = (decompose 𝒜 r : ⨁ i, 𝒜 i) i :=
rfl
theorem GradedRing.proj_recompose (a : ⨁ i, 𝒜 i) (i : ι) :
GradedRing.proj 𝒜 i ((decompose 𝒜).symm a) = (decompose 𝒜).symm (DirectSum.of _ i (a i)) := by
rw [GradedRing.proj_apply, decompose_symm_of, Equiv.apply_symm_apply]
theorem GradedRing.mem_support_iff [∀ (i) (x : 𝒜 i), Decidable (x ≠ 0)] (r : A) (i : ι) :
i ∈ (decompose 𝒜 r).support ↔ GradedRing.proj 𝒜 i r ≠ 0 :=
DFinsupp.mem_support_iff.trans ZeroMemClass.coe_eq_zero.not.symm
end GradedRing
section AddCancelMonoid
open DirectSum
variable [DecidableEq ι] [Semiring A] [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ)
variable {i j : ι}
namespace DirectSum
theorem coe_decompose_mul_add_of_left_mem [AddLeftCancelMonoid ι] [GradedRing 𝒜] {a b : A}
(a_mem : a ∈ 𝒜 i) : (decompose 𝒜 (a * b) (i + j) : A) = a * decompose 𝒜 b j := by
lift a to 𝒜 i using a_mem
rw [decompose_mul, decompose_coe, coe_of_mul_apply_add]
theorem coe_decompose_mul_add_of_right_mem [AddRightCancelMonoid ι] [GradedRing 𝒜] {a b : A}
(b_mem : b ∈ 𝒜 j) : (decompose 𝒜 (a * b) (i + j) : A) = decompose 𝒜 a i * b := by
lift b to 𝒜 j using b_mem
rw [decompose_mul, decompose_coe, coe_mul_of_apply_add]
theorem decompose_mul_add_left [AddLeftCancelMonoid ι] [GradedRing 𝒜] (a : 𝒜 i) {b : A} :
decompose 𝒜 (↑a * b) (i + j) =
@GradedMonoid.GMul.mul ι (fun i => 𝒜 i) _ _ _ _ a (decompose 𝒜 b j) :=
Subtype.ext <| coe_decompose_mul_add_of_left_mem 𝒜 a.2
theorem decompose_mul_add_right [AddRightCancelMonoid ι] [GradedRing 𝒜] {a : A} (b : 𝒜 j) :
decompose 𝒜 (a * ↑b) (i + j) =
@GradedMonoid.GMul.mul ι (fun i => 𝒜 i) _ _ _ _ (decompose 𝒜 a i) b :=
Subtype.ext <| coe_decompose_mul_add_of_right_mem 𝒜 b.2
theorem coe_decompose_mul_of_left_mem_zero [AddMonoid ι] [GradedRing 𝒜] {a b : A}
(a_mem : a ∈ 𝒜 0) : (decompose 𝒜 (a * b) j : A) = a * decompose 𝒜 b j := by
lift a to 𝒜 0 using a_mem
rw [decompose_mul, decompose_coe, coe_of_mul_apply_of_mem_zero]
theorem coe_decompose_mul_of_right_mem_zero [AddMonoid ι] [GradedRing 𝒜] {a b : A}
(b_mem : b ∈ 𝒜 0) : (decompose 𝒜 (a * b) i : A) = decompose 𝒜 a i * b := by
lift b to 𝒜 0 using b_mem
rw [decompose_mul, decompose_coe, coe_mul_of_apply_of_mem_zero]
end DirectSum
end AddCancelMonoid
section GradedAlgebra
variable [DecidableEq ι] [AddMonoid ι] [CommSemiring R] [Semiring A] [Algebra R A]
variable (𝒜 : ι → Submodule R A)
/-- A special case of `GradedRing` with `σ = Submodule R A`. This is useful both because it
can avoid typeclass search, and because it provides a more concise name. -/
abbrev GradedAlgebra :=
GradedRing 𝒜
/-- A helper to construct a `GradedAlgebra` when the `SetLike.GradedMonoid` structure is already
available. This makes the `left_inv` condition easier to prove, and phrases the `right_inv`
condition in a way that allows custom `@[ext]` lemmas to apply.
See note [reducible non-instances]. -/
abbrev GradedAlgebra.ofAlgHom [SetLike.GradedMonoid 𝒜] (decompose : A →ₐ[R] ⨁ i, 𝒜 i)
(right_inv : (DirectSum.coeAlgHom 𝒜).comp decompose = AlgHom.id R A)
(left_inv : ∀ i (x : 𝒜 i), decompose (x : A) = DirectSum.of (fun i => ↥(𝒜 i)) i x) :
GradedAlgebra 𝒜 where
decompose' := decompose
left_inv := AlgHom.congr_fun right_inv
right_inv := by
suffices decompose.comp (DirectSum.coeAlgHom 𝒜) = AlgHom.id _ _ from AlgHom.congr_fun this
ext i x : 2
exact (decompose.congr_arg <| DirectSum.coeAlgHom_of _ _ _).trans (left_inv i x)
variable [GradedAlgebra 𝒜]
namespace DirectSum
/-- If `A` is graded by `ι` with degree `i` component `𝒜 i`, then it is isomorphic as
an algebra to a direct sum of components. -/
-- We have to write the `@[simps]` lemmas by hand to see through the
-- `AlgEquiv.symm (decomposeAddEquiv 𝒜).symm`.
def decomposeAlgEquiv : A ≃ₐ[R] ⨁ i, 𝒜 i :=
AlgEquiv.symm
{ (decomposeAddEquiv 𝒜).symm with
map_mul' := map_mul (coeAlgHom 𝒜)
commutes' := (coeAlgHom 𝒜).commutes }
@[simp]
lemma decomposeAlgEquiv_apply (a : A) :
decomposeAlgEquiv 𝒜 a = decompose 𝒜 a := rfl
@[simp]
lemma decomposeAlgEquiv_symm_apply (a : ⨁ i, 𝒜 i) :
(decomposeAlgEquiv 𝒜).symm a = (decompose 𝒜).symm a := rfl
@[simp]
lemma decompose_algebraMap (r : R) :
decompose 𝒜 (algebraMap R A r) = algebraMap R (⨁ i, 𝒜 i) r :=
(decomposeAlgEquiv 𝒜).commutes r
@[simp]
lemma decompose_symm_algebraMap (r : R) :
(decompose 𝒜).symm (algebraMap R (⨁ i, 𝒜 i) r) = algebraMap R A r :=
(decomposeAlgEquiv 𝒜).symm.commutes r
end DirectSum
open DirectSum
/-- The projection maps of graded algebra -/
def GradedAlgebra.proj (𝒜 : ι → Submodule R A) [GradedAlgebra 𝒜] (i : ι) : A →ₗ[R] A :=
(𝒜 i).subtype.comp <| (DFinsupp.lapply i).comp <| (decomposeAlgEquiv 𝒜).toAlgHom.toLinearMap
@[simp]
theorem GradedAlgebra.proj_apply (i : ι) (r : A) :
GradedAlgebra.proj 𝒜 i r = (decompose 𝒜 r : ⨁ i, 𝒜 i) i :=
rfl
theorem GradedAlgebra.proj_recompose (a : ⨁ i, 𝒜 i) (i : ι) :
GradedAlgebra.proj 𝒜 i ((decompose 𝒜).symm a) = (decompose 𝒜).symm (of _ i (a i)) := by
rw [GradedAlgebra.proj_apply, decompose_symm_of, Equiv.apply_symm_apply]
theorem GradedAlgebra.mem_support_iff [DecidableEq A] (r : A) (i : ι) :
i ∈ (decompose 𝒜 r).support ↔ GradedAlgebra.proj 𝒜 i r ≠ 0 :=
DFinsupp.mem_support_iff.trans Submodule.coe_eq_zero.not.symm
end GradedAlgebra
section CanonicalOrder
open SetLike.GradedMonoid DirectSum
variable [Semiring A] [DecidableEq ι]
variable [AddCommMonoid ι] [PartialOrder ι] [CanonicallyOrderedAdd ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜]
/-- If `A` is graded by a canonically ordered additive monoid, then the projection map `x ↦ x₀`
is a ring homomorphism.
-/
@[simps]
def GradedRing.projZeroRingHom : A →+* A where
toFun a := decompose 𝒜 a 0
map_one' := decompose_of_mem_same 𝒜 SetLike.GradedOne.one_mem
map_zero' := by rw [decompose_zero, zero_apply, ZeroMemClass.coe_zero]
map_add' _ _ := by rw [decompose_add, add_apply, AddMemClass.coe_add]
map_mul' := by
refine DirectSum.Decomposition.inductionOn 𝒜 (fun x => ?_) ?_ ?_
· simp only [zero_mul, decompose_zero, zero_apply, ZeroMemClass.coe_zero]
· rintro i ⟨c, hc⟩
refine DirectSum.Decomposition.inductionOn 𝒜 ?_ ?_ ?_
· simp only [mul_zero, decompose_zero, zero_apply, ZeroMemClass.coe_zero]
· rintro j ⟨c', hc'⟩
simp only
by_cases h : i + j = 0
· rw [decompose_of_mem_same 𝒜
(show c * c' ∈ 𝒜 0 from h ▸ SetLike.GradedMul.mul_mem hc hc'),
decompose_of_mem_same 𝒜 (show c ∈ 𝒜 0 from (add_eq_zero.mp h).1 ▸ hc),
decompose_of_mem_same 𝒜 (show c' ∈ 𝒜 0 from (add_eq_zero.mp h).2 ▸ hc')]
· rw [decompose_of_mem_ne 𝒜 (SetLike.GradedMul.mul_mem hc hc') h]
rcases show i ≠ 0 ∨ j ≠ 0 by rwa [add_eq_zero, not_and_or] at h with h' | h'
· simp only [decompose_of_mem_ne 𝒜 hc h', zero_mul]
· simp only [decompose_of_mem_ne 𝒜 hc' h', mul_zero]
· intro _ _ hd he
simp only [mul_add, decompose_add, add_apply, AddMemClass.coe_add, hd, he]
· rintro _ _ ha hb _
simp only [add_mul, decompose_add, add_apply, AddMemClass.coe_add, ha, hb]
section GradeZero
/-- The ring homomorphism from `A` to `𝒜 0` sending every `a : A` to `a₀`. -/
def GradedRing.projZeroRingHom' : A →+* 𝒜 0 :=
((GradedRing.projZeroRingHom 𝒜).codRestrict _ fun _x => SetLike.coe_mem _ :
A →+* SetLike.GradeZero.subsemiring 𝒜)
@[simp] lemma GradedRing.coe_projZeroRingHom'_apply (a : A) :
(GradedRing.projZeroRingHom' 𝒜 a : A) = GradedRing.projZeroRingHom 𝒜 a := rfl
@[simp] lemma GradedRing.projZeroRingHom'_apply_coe (a : 𝒜 0) :
GradedRing.projZeroRingHom' 𝒜 a = a := by
ext; simp only [coe_projZeroRingHom'_apply, projZeroRingHom_apply, decompose_coe, of_eq_same]
/-- The ring homomorphism `GradedRing.projZeroRingHom' 𝒜` is surjective. -/
lemma GradedRing.projZeroRingHom'_surjective :
Function.Surjective (GradedRing.projZeroRingHom' 𝒜) :=
Function.RightInverse.surjective (GradedRing.projZeroRingHom'_apply_coe 𝒜)
end GradeZero
variable {a b : A} {n i : ι}
namespace DirectSum
theorem coe_decompose_mul_of_left_mem_of_not_le (a_mem : a ∈ 𝒜 i) (h : ¬i ≤ n) :
(decompose 𝒜 (a * b) n : A) = 0 := by
lift a to 𝒜 i using a_mem
rwa [decompose_mul, decompose_coe, coe_of_mul_apply_of_not_le]
theorem coe_decompose_mul_of_right_mem_of_not_le (b_mem : b ∈ 𝒜 i) (h : ¬i ≤ n) :
(decompose 𝒜 (a * b) n : A) = 0 := by
lift b to 𝒜 i using b_mem
rwa [decompose_mul, decompose_coe, coe_mul_of_apply_of_not_le]
variable [Sub ι] [OrderedSub ι] [AddLeftReflectLE ι]
theorem coe_decompose_mul_of_left_mem_of_le (a_mem : a ∈ 𝒜 i) (h : i ≤ n) :
(decompose 𝒜 (a * b) n : A) = a * decompose 𝒜 b (n - i) := by
lift a to 𝒜 i using a_mem
rwa [decompose_mul, decompose_coe, coe_of_mul_apply_of_le]
theorem coe_decompose_mul_of_right_mem_of_le (b_mem : b ∈ 𝒜 i) (h : i ≤ n) :
(decompose 𝒜 (a * b) n : A) = decompose 𝒜 a (n - i) * b := by
lift b to 𝒜 i using b_mem
rwa [decompose_mul, decompose_coe, coe_mul_of_apply_of_le]
theorem coe_decompose_mul_of_left_mem (n) [Decidable (i ≤ n)] (a_mem : a ∈ 𝒜 i) :
(decompose 𝒜 (a * b) n : A) = if i ≤ n then a * decompose 𝒜 b (n - i) else 0 := by
lift a to 𝒜 i using a_mem
rw [decompose_mul, decompose_coe, coe_of_mul_apply]
theorem coe_decompose_mul_of_right_mem (n) [Decidable (i ≤ n)] (b_mem : b ∈ 𝒜 i) :
(decompose 𝒜 (a * b) n : A) = if i ≤ n then decompose 𝒜 a (n - i) * b else 0 := by
lift b to 𝒜 i using b_mem
rw [decompose_mul, decompose_coe, coe_mul_of_apply]
end DirectSum
end CanonicalOrder
namespace DirectSum.IsInternal
variable {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] [Algebra R A]
variable {ι : Type*} [DecidableEq ι] [AddMonoid ι]
variable {M : ι → Submodule R A} [SetLike.GradedMonoid M]
-- The following lines were given on Zulip by Adam Topaz
/-- The canonical isomorphism of an internal direct sum with the ambient algebra -/
noncomputable def coeAlgEquiv (hM : DirectSum.IsInternal M) :
(DirectSum ι fun i => ↥(M i)) ≃ₐ[R] A :=
{ RingEquiv.ofBijective (DirectSum.coeAlgHom M) hM with commutes' := fun r => by simp }
/-- Given an `R`-algebra `A` and a family `ι → Submodule R A` of submodules
parameterized by an additive monoid `ι`
and satisfying `SetLike.GradedMonoid M` (essentially, is multiplicative)
such that `DirectSum.IsInternal M` (`A` is the direct sum of the `M i`),
we endow `A` with the structure of a graded algebra.
The submodules are the *homogeneous* parts. -/
noncomputable def gradedAlgebra (hM : DirectSum.IsInternal M) : GradedAlgebra M :=
{ (inferInstance : SetLike.GradedMonoid M) with
decompose' := hM.coeAlgEquiv.symm
left_inv := hM.coeAlgEquiv.symm.left_inv
right_inv := hM.coeAlgEquiv.left_inv }
end DirectSum.IsInternal |
.lake/packages/mathlib/Mathlib/RingTheory/GradedAlgebra/HomogeneousLocalization.lean | import Mathlib.Algebra.Group.Submonoid.Finsupp
import Mathlib.Order.Filter.AtTopBot.Defs
import Mathlib.RingTheory.Adjoin.Basic
import Mathlib.RingTheory.GradedAlgebra.FiniteType
import Mathlib.RingTheory.Localization.AtPrime.Basic
import Mathlib.RingTheory.Localization.Away.Basic
/-!
# Homogeneous Localization
## Notation
- `ι` is a commutative monoid;
- `A` is a commutative ring;
- `σ` is a class of additive subgroups of `A`;
- `𝒜 : ι → σ` is the grading of `A`;
- `x : Submonoid A` is a submonoid
## Main definitions and results
This file constructs the subring of `Aₓ` where the numerator and denominator have the same grading,
i.e. `{a/b ∈ Aₓ | ∃ (i : ι), a ∈ 𝒜ᵢ ∧ b ∈ 𝒜ᵢ}`.
* `HomogeneousLocalization.NumDenSameDeg`: a structure with a numerator and denominator field
where they are required to have the same grading.
However `NumDenSameDeg 𝒜 x` cannot have a ring structure for many reasons, for example if `c`
is a `NumDenSameDeg`, then generally, `c + (-c)` is not necessarily `0` for degree reasons ---
`0` is considered to have grade zero (see `deg_zero`) but `c + (-c)` has the same degree as `c`. To
circumvent this, we quotient `NumDenSameDeg 𝒜 x` by the kernel of `c ↦ c.num / c.den`.
* `HomogeneousLocalization.NumDenSameDeg.embedding`: for `x : Submonoid A` and any
`c : NumDenSameDeg 𝒜 x`, or equivalent a numerator and a denominator of the same degree,
we get an element `c.num / c.den` of `Aₓ`.
* `HomogeneousLocalization`: `NumDenSameDeg 𝒜 x` quotiented by kernel of `embedding 𝒜 x`.
* `HomogeneousLocalization.val`: if `f : HomogeneousLocalization 𝒜 x`, then `f.val` is an element
of `Aₓ`. In another word, one can view `HomogeneousLocalization 𝒜 x` as a subring of `Aₓ`
through `HomogeneousLocalization.val`.
* `HomogeneousLocalization.num`: if `f : HomogeneousLocalization 𝒜 x`, then `f.num : A` is the
numerator of `f`.
* `HomogeneousLocalization.den`: if `f : HomogeneousLocalization 𝒜 x`, then `f.den : A` is the
denominator of `f`.
* `HomogeneousLocalization.deg`: if `f : HomogeneousLocalization 𝒜 x`, then `f.deg : ι` is the
degree of `f` such that `f.num ∈ 𝒜 f.deg` and `f.den ∈ 𝒜 f.deg`
(see `HomogeneousLocalization.num_mem_deg` and `HomogeneousLocalization.den_mem_deg`).
* `HomogeneousLocalization.num_mem_deg`: if `f : HomogeneousLocalization 𝒜 x`, then
`f.num_mem_deg` is a proof that `f.num ∈ 𝒜 f.deg`.
* `HomogeneousLocalization.den_mem_deg`: if `f : HomogeneousLocalization 𝒜 x`, then
`f.den_mem_deg` is a proof that `f.den ∈ 𝒜 f.deg`.
* `HomogeneousLocalization.eq_num_div_den`: if `f : HomogeneousLocalization 𝒜 x`, then
`f.val : Aₓ` is equal to `f.num / f.den`.
* `HomogeneousLocalization.isLocalRing`: `HomogeneousLocalization 𝒜 x` is a local ring when `x` is
the complement of some prime ideals.
* `HomogeneousLocalization.map`: Let `A` and `B` be two graded rings and `g : A → B` a
grading-preserving ring map. If `P ≤ A` and `Q ≤ B` are submonoids such that `P ≤ g⁻¹(Q)`, then
`g` induces a ring map between the homogeneous localization of `A` at `P` and the homogeneous
localization of `B` at `Q`.
## References
* [Robin Hartshorne, *Algebraic Geometry*][Har77]
-/
noncomputable section
open DirectSum Pointwise
open DirectSum SetLike
variable {ι A σ : Type*}
variable [CommRing A] [SetLike σ A]
local notation "at " x => Localization x
namespace HomogeneousLocalization
section
/-- Let `x` be a submonoid of `A`, then `NumDenSameDeg 𝒜 x` is a structure with a numerator and a
denominator with same grading such that the denominator is contained in `x`.
-/
structure NumDenSameDeg (𝒜 : ι → σ) (x : Submonoid A) where
deg : ι
(num den : 𝒜 deg)
den_mem : (den : A) ∈ x
end
namespace NumDenSameDeg
open SetLike.GradedMonoid Submodule
@[ext]
theorem ext {𝒜 : ι → σ} (x : Submonoid A)
{c1 c2 : NumDenSameDeg 𝒜 x} (hdeg : c1.deg = c2.deg) (hnum : (c1.num : A) = c2.num)
(hden : (c1.den : A) = c2.den) : c1 = c2 := by
rcases c1 with ⟨i1, ⟨n1, hn1⟩, ⟨d1, hd1⟩, h1⟩
rcases c2 with ⟨i2, ⟨n2, hn2⟩, ⟨d2, hd2⟩, h2⟩
dsimp only [Subtype.coe_mk] at *
subst hdeg hnum hden
congr
section Neg
variable [NegMemClass σ A] {𝒜 : ι → σ} (x : Submonoid A)
instance : Neg (NumDenSameDeg 𝒜 x) where
neg c := ⟨c.deg, ⟨-c.num, neg_mem c.num.2⟩, c.den, c.den_mem⟩
@[simp]
theorem deg_neg (c : NumDenSameDeg 𝒜 x) : (-c).deg = c.deg :=
rfl
@[simp]
theorem num_neg (c : NumDenSameDeg 𝒜 x) : ((-c).num : A) = -c.num :=
rfl
@[simp]
theorem den_neg (c : NumDenSameDeg 𝒜 x) : ((-c).den : A) = c.den :=
rfl
end Neg
section SMul
variable {𝒜 : ι → σ} (x : Submonoid A) {α : Type*} [SMul α A] [SMulMemClass σ α A]
instance : SMul α (NumDenSameDeg 𝒜 x) where
smul m c := ⟨c.deg, m • c.num, c.den, c.den_mem⟩
@[simp]
theorem deg_smul (c : NumDenSameDeg 𝒜 x) (m : α) : (m • c).deg = c.deg :=
rfl
@[simp]
theorem num_smul (c : NumDenSameDeg 𝒜 x) (m : α) : ((m • c).num : A) = m • c.num :=
rfl
@[simp]
theorem den_smul (c : NumDenSameDeg 𝒜 x) (m : α) : ((m • c).den : A) = c.den :=
rfl
end SMul
variable [AddSubmonoidClass σ A] {𝒜 : ι → σ} (x : Submonoid A)
variable [AddCommMonoid ι] [DecidableEq ι] [GradedRing 𝒜]
open GradedOne in
instance : One (NumDenSameDeg 𝒜 x) where
one :=
{ deg := 0
num := ⟨1, one_mem⟩
den := ⟨1, one_mem⟩
den_mem := one_mem _ }
@[simp]
theorem deg_one : (1 : NumDenSameDeg 𝒜 x).deg = 0 :=
rfl
@[simp]
theorem num_one : ((1 : NumDenSameDeg 𝒜 x).num : A) = 1 :=
rfl
@[simp]
theorem den_one : ((1 : NumDenSameDeg 𝒜 x).den : A) = 1 :=
rfl
open GradedOne in
instance : Zero (NumDenSameDeg 𝒜 x) where
zero := ⟨0, 0, ⟨1, one_mem⟩, one_mem _⟩
@[simp]
theorem deg_zero : (0 : NumDenSameDeg 𝒜 x).deg = 0 :=
rfl
@[simp]
theorem num_zero : (0 : NumDenSameDeg 𝒜 x).num = 0 :=
rfl
@[simp]
theorem den_zero : ((0 : NumDenSameDeg 𝒜 x).den : A) = 1 :=
rfl
open GradedMul in
instance : Mul (NumDenSameDeg 𝒜 x) where
mul p q :=
{ deg := p.deg + q.deg
num := ⟨p.num * q.num, mul_mem p.num.prop q.num.prop⟩
den := ⟨p.den * q.den, mul_mem p.den.prop q.den.prop⟩
den_mem := Submonoid.mul_mem _ p.den_mem q.den_mem }
@[simp]
theorem deg_mul (c1 c2 : NumDenSameDeg 𝒜 x) : (c1 * c2).deg = c1.deg + c2.deg :=
rfl
@[simp]
theorem num_mul (c1 c2 : NumDenSameDeg 𝒜 x) : ((c1 * c2).num : A) = c1.num * c2.num :=
rfl
@[simp]
theorem den_mul (c1 c2 : NumDenSameDeg 𝒜 x) : ((c1 * c2).den : A) = c1.den * c2.den :=
rfl
instance : Add (NumDenSameDeg 𝒜 x) where
add c1 c2 :=
{ deg := c1.deg + c2.deg
num := ⟨c1.den * c2.num + c2.den * c1.num,
add_mem (GradedMul.mul_mem c1.den.2 c2.num.2)
(add_comm c2.deg c1.deg ▸ GradedMul.mul_mem c2.den.2 c1.num.2)⟩
den := ⟨c1.den * c2.den, GradedMul.mul_mem c1.den.2 c2.den.2⟩
den_mem := Submonoid.mul_mem _ c1.den_mem c2.den_mem }
@[simp]
theorem deg_add (c1 c2 : NumDenSameDeg 𝒜 x) : (c1 + c2).deg = c1.deg + c2.deg :=
rfl
@[simp]
theorem num_add (c1 c2 : NumDenSameDeg 𝒜 x) :
((c1 + c2).num : A) = c1.den * c2.num + c2.den * c1.num :=
rfl
@[simp]
theorem den_add (c1 c2 : NumDenSameDeg 𝒜 x) : ((c1 + c2).den : A) = c1.den * c2.den :=
rfl
instance : CommMonoid (NumDenSameDeg 𝒜 x) where
mul_assoc _ _ _ := ext _ (add_assoc _ _ _) (mul_assoc _ _ _) (mul_assoc _ _ _)
one_mul _ := ext _ (zero_add _) (one_mul _) (one_mul _)
mul_one _ := ext _ (add_zero _) (mul_one _) (mul_one _)
mul_comm _ _ := ext _ (add_comm _ _) (mul_comm _ _) (mul_comm _ _)
instance : Pow (NumDenSameDeg 𝒜 x) ℕ where
pow c n :=
⟨n • c.deg, @GradedMonoid.GMonoid.gnpow _ (fun i => ↥(𝒜 i)) _ _ n _ c.num,
@GradedMonoid.GMonoid.gnpow _ (fun i => ↥(𝒜 i)) _ _ n _ c.den, by
induction n with
| zero => simp only [coe_gnpow, pow_zero, one_mem]
| succ n ih => simpa only [pow_succ, coe_gnpow] using x.mul_mem ih c.den_mem⟩
@[simp]
theorem deg_pow (c : NumDenSameDeg 𝒜 x) (n : ℕ) : (c ^ n).deg = n • c.deg :=
rfl
@[simp]
theorem num_pow (c : NumDenSameDeg 𝒜 x) (n : ℕ) : ((c ^ n).num : A) = (c.num : A) ^ n :=
rfl
@[simp]
theorem den_pow (c : NumDenSameDeg 𝒜 x) (n : ℕ) : ((c ^ n).den : A) = (c.den : A) ^ n :=
rfl
variable (𝒜)
/-- For `x : prime ideal of A` and any `p : NumDenSameDeg 𝒜 x`, or equivalent a numerator and a
denominator of the same degree, we get an element `p.num / p.den` of `Aₓ`.
-/
def embedding (p : NumDenSameDeg 𝒜 x) : at x :=
Localization.mk p.num ⟨p.den, p.den_mem⟩
end NumDenSameDeg
end HomogeneousLocalization
/-- For `x : prime ideal of A`, `HomogeneousLocalization 𝒜 x` is `NumDenSameDeg 𝒜 x` modulo the
kernel of `embedding 𝒜 x`. This is essentially the subring of `Aₓ` where the numerator and
denominator share the same grading.
-/
def HomogeneousLocalization (𝒜 : ι → σ) (x : Submonoid A) : Type _ :=
Quotient (Setoid.ker <| HomogeneousLocalization.NumDenSameDeg.embedding 𝒜 x)
namespace HomogeneousLocalization
open HomogeneousLocalization HomogeneousLocalization.NumDenSameDeg
section
variable {𝒜 : ι → σ} {x : Submonoid A}
/-- Construct an element of `HomogeneousLocalization 𝒜 x` from a homogeneous fraction. -/
abbrev mk (y : HomogeneousLocalization.NumDenSameDeg 𝒜 x) : HomogeneousLocalization 𝒜 x :=
Quotient.mk'' y
lemma mk_surjective : Function.Surjective (mk (𝒜 := 𝒜) (x := x)) :=
Quotient.mk''_surjective
/-- View an element of `HomogeneousLocalization 𝒜 x` as an element of `Aₓ` by forgetting that the
numerator and denominator are of the same grading.
-/
def val (y : HomogeneousLocalization 𝒜 x) : at x :=
Quotient.liftOn' y (NumDenSameDeg.embedding 𝒜 x) fun _ _ => id
@[simp]
theorem val_mk (i : NumDenSameDeg 𝒜 x) :
val (mk i) = Localization.mk (i.num : A) ⟨i.den, i.den_mem⟩ :=
rfl
variable (x)
@[ext]
theorem val_injective : Function.Injective (HomogeneousLocalization.val (𝒜 := 𝒜) (x := x)) :=
fun a b => Quotient.recOnSubsingleton₂' a b fun _ _ h => Quotient.sound' h
variable (𝒜) {x} in
lemma subsingleton (hx : 0 ∈ x) : Subsingleton (HomogeneousLocalization 𝒜 x) :=
have := IsLocalization.subsingleton (S := at x) hx
(HomogeneousLocalization.val_injective (𝒜 := 𝒜) (x := x)).subsingleton
end
section SMul
variable {𝒜 : ι → σ} (x : Submonoid A)
variable {α : Type*} [SMul α A] [IsScalarTower α A A] [SMulMemClass σ α A]
instance : SMul α (HomogeneousLocalization 𝒜 x) where
smul m := Quotient.map' (m • ·) fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) => by
change Localization.mk _ _ = Localization.mk _ _
simp only [num_smul, den_smul]
convert congr_arg (fun z : at x => m • z) h <;> rw [Localization.smul_mk]
@[simp] lemma mk_smul (i : NumDenSameDeg 𝒜 x) (m : α) : mk (m • i) = m • mk i := rfl
@[simp]
theorem val_smul (n : α) : ∀ y : HomogeneousLocalization 𝒜 x, (n • y).val = n • y.val :=
Quotient.ind' fun _ ↦ by rw [← mk_smul, val_mk, val_mk, Localization.smul_mk, num_smul]; rfl
end SMul
section nsmul
variable [AddSubmonoidClass σ A] {𝒜 : ι → σ} (x : Submonoid A)
instance : SMul ℕ (HomogeneousLocalization 𝒜 x) :=
haveI := AddSubmonoidClass.nsmulMemClass (S := σ) (M := A)
HomogeneousLocalization.instSMul x
theorem val_nsmul (n : ℕ) (y : HomogeneousLocalization 𝒜 x) : (n • y).val = n • y.val := by
rw [val_smul, OreLocalization.nsmul_eq_nsmul]
end nsmul
section zsmul
variable [AddSubgroupClass σ A] {𝒜 : ι → σ} (x : Submonoid A)
instance : SMul ℤ (HomogeneousLocalization 𝒜 x) :=
haveI := AddSubgroupClass.zsmulMemClass (S := σ) (M := A)
HomogeneousLocalization.instSMul x
theorem val_zsmul (n : ℤ) (y : HomogeneousLocalization 𝒜 x) : (n • y).val = n • y.val := by
rw [val_smul, OreLocalization.zsmul_eq_zsmul]
end zsmul
section Neg
variable [NegMemClass σ A] {𝒜 : ι → σ} (x : Submonoid A)
instance : Neg (HomogeneousLocalization 𝒜 x) where
neg := Quotient.map' Neg.neg fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) => by
change Localization.mk _ _ = Localization.mk _ _
simp only [num_neg, den_neg, ← Localization.neg_mk]
exact congr_arg Neg.neg h
@[simp] lemma mk_neg (i : NumDenSameDeg 𝒜 x) : mk (-i) = -mk i := rfl
@[simp]
theorem val_neg {x} : ∀ y : HomogeneousLocalization 𝒜 x, (-y).val = -y.val :=
Quotient.ind' fun y ↦ by rw [← mk_neg, val_mk, val_mk, Localization.neg_mk]; rfl
end Neg
variable [AddSubgroupClass σ A] [AddCommMonoid ι] [DecidableEq ι]
variable {𝒜 : ι → σ} [GradedRing 𝒜] (x : Submonoid A)
instance hasPow : Pow (HomogeneousLocalization 𝒜 x) ℕ where
pow z n :=
(Quotient.map' (· ^ n) fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) => by
change Localization.mk _ _ = Localization.mk _ _
simp only [num_pow, den_pow]
convert congr_arg (fun z : at x => z ^ n) h <;> rw [Localization.mk_pow] <;> rfl :
HomogeneousLocalization 𝒜 x → HomogeneousLocalization 𝒜 x)
z
@[simp] lemma mk_pow (i : NumDenSameDeg 𝒜 x) (n : ℕ) : mk (i ^ n) = mk i ^ n := rfl
instance : Add (HomogeneousLocalization 𝒜 x) where
add :=
Quotient.map₂ (· + ·)
fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) c3 c4
(h' : Localization.mk _ _ = Localization.mk _ _) => by
change Localization.mk _ _ = Localization.mk _ _
simp only [num_add, den_add]
convert congr_arg₂ (· + ·) h h' <;> rw [Localization.add_mk] <;> rfl
@[simp] lemma mk_add (i j : NumDenSameDeg 𝒜 x) : mk (i + j) = mk i + mk j := rfl
instance : Sub (HomogeneousLocalization 𝒜 x) where sub z1 z2 := z1 + -z2
instance : Mul (HomogeneousLocalization 𝒜 x) where
mul :=
Quotient.map₂ (· * ·)
fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) c3 c4
(h' : Localization.mk _ _ = Localization.mk _ _) => by
change Localization.mk _ _ = Localization.mk _ _
simp only [num_mul, den_mul]
convert congr_arg₂ (· * ·) h h' <;> rw [Localization.mk_mul] <;> rfl
@[simp] lemma mk_mul (i j : NumDenSameDeg 𝒜 x) : mk (i * j) = mk i * mk j := rfl
instance : One (HomogeneousLocalization 𝒜 x) where one := Quotient.mk'' 1
@[simp] lemma mk_one : mk (1 : NumDenSameDeg 𝒜 x) = 1 := rfl
instance : Zero (HomogeneousLocalization 𝒜 x) where zero := Quotient.mk'' 0
@[simp] lemma mk_zero : mk (0 : NumDenSameDeg 𝒜 x) = 0 := rfl
theorem zero_eq : (0 : HomogeneousLocalization 𝒜 x) = Quotient.mk'' 0 :=
rfl
theorem one_eq : (1 : HomogeneousLocalization 𝒜 x) = Quotient.mk'' 1 :=
rfl
variable {x}
@[simp]
theorem val_zero : (0 : HomogeneousLocalization 𝒜 x).val = 0 :=
Localization.mk_zero _
@[simp]
theorem val_one : (1 : HomogeneousLocalization 𝒜 x).val = 1 :=
Localization.mk_one
@[simp]
theorem val_add : ∀ y1 y2 : HomogeneousLocalization 𝒜 x, (y1 + y2).val = y1.val + y2.val :=
Quotient.ind₂' fun y1 y2 ↦ by rw [← mk_add, val_mk, val_mk, val_mk, Localization.add_mk]; rfl
@[simp]
theorem val_mul : ∀ y1 y2 : HomogeneousLocalization 𝒜 x, (y1 * y2).val = y1.val * y2.val :=
Quotient.ind₂' fun y1 y2 ↦ by rw [← mk_mul, val_mk, val_mk, val_mk, Localization.mk_mul]; rfl
@[simp]
theorem val_sub (y1 y2 : HomogeneousLocalization 𝒜 x) : (y1 - y2).val = y1.val - y2.val := by
rw [sub_eq_add_neg, ← val_neg, ← val_add]; rfl
@[simp]
theorem val_pow : ∀ (y : HomogeneousLocalization 𝒜 x) (n : ℕ), (y ^ n).val = y.val ^ n :=
Quotient.ind' fun y n ↦ by rw [← mk_pow, val_mk, val_mk, Localization.mk_pow]; rfl
instance : NatCast (HomogeneousLocalization 𝒜 x) :=
⟨Nat.unaryCast⟩
instance : IntCast (HomogeneousLocalization 𝒜 x) :=
⟨Int.castDef⟩
@[simp]
theorem val_natCast (n : ℕ) : (n : HomogeneousLocalization 𝒜 x).val = n :=
show val (Nat.unaryCast n) = _ by induction n <;> simp [Nat.unaryCast, *]
@[simp]
theorem val_intCast (n : ℤ) : (n : HomogeneousLocalization 𝒜 x).val = n :=
show val (Int.castDef n) = _ by cases n <;> simp [Int.castDef, *]
instance homogeneousLocalizationCommRing : CommRing (HomogeneousLocalization 𝒜 x) :=
(HomogeneousLocalization.val_injective x).commRing _ val_zero val_one val_add val_mul val_neg
val_sub (val_nsmul x · ·) (val_zsmul x · ·) val_pow val_natCast val_intCast
instance homogeneousLocalizationAlgebra :
Algebra (HomogeneousLocalization 𝒜 x) (Localization x) where
smul p q := p.val * q
algebraMap :=
{ toFun := val
map_one' := val_one
map_mul' := val_mul
map_zero' := val_zero
map_add' := val_add }
commutes' _ _ := mul_comm _ _
smul_def' _ _ := rfl
@[simp] lemma algebraMap_apply (y) :
algebraMap (HomogeneousLocalization 𝒜 x) (Localization x) y = y.val := rfl
lemma mk_eq_zero_of_num (f : NumDenSameDeg 𝒜 x) (h : f.num = 0) : mk f = 0 := by
apply val_injective
simp only [val_mk, val_zero, h, ZeroMemClass.coe_zero, Localization.mk_zero]
lemma mk_eq_zero_of_den (f : NumDenSameDeg 𝒜 x) (h : f.den = 0) : mk f = 0 := by
have := subsingleton 𝒜 (h ▸ f.den_mem)
exact Subsingleton.elim _ _
variable (𝒜 x) in
/-- The map from `𝒜 0` to the degree `0` part of `𝒜ₓ` sending `f ↦ f/1`. -/
def fromZeroRingHom : 𝒜 0 →+* HomogeneousLocalization 𝒜 x where
toFun f := .mk ⟨0, f, 1, one_mem _⟩
map_one' := rfl
map_mul' f g := by ext; simp [Localization.mk_mul]
map_zero' := rfl
map_add' f g := by ext; simp [Localization.add_mk, add_comm f.1 g.1]
instance : Algebra (𝒜 0) (HomogeneousLocalization 𝒜 x) :=
(fromZeroRingHom 𝒜 x).toAlgebra
lemma algebraMap_eq : algebraMap (𝒜 0) (HomogeneousLocalization 𝒜 x) = fromZeroRingHom 𝒜 x := rfl
instance : IsScalarTower (𝒜 0) (HomogeneousLocalization 𝒜 x) (Localization x) :=
.of_algebraMap_eq' rfl
end HomogeneousLocalization
namespace HomogeneousLocalization
open HomogeneousLocalization HomogeneousLocalization.NumDenSameDeg
section
variable {𝒜 : ι → σ} {x : Submonoid A}
/-- Numerator of an element in `HomogeneousLocalization x`. -/
def num (f : HomogeneousLocalization 𝒜 x) : A :=
(Quotient.out f).num
/-- Denominator of an element in `HomogeneousLocalization x`. -/
def den (f : HomogeneousLocalization 𝒜 x) : A :=
(Quotient.out f).den
/-- For an element in `HomogeneousLocalization x`, degree is the natural number `i` such that
`𝒜 i` contains both numerator and denominator. -/
def deg (f : HomogeneousLocalization 𝒜 x) : ι :=
(Quotient.out f).deg
theorem den_mem (f : HomogeneousLocalization 𝒜 x) : f.den ∈ x :=
(Quotient.out f).den_mem
theorem num_mem_deg (f : HomogeneousLocalization 𝒜 x) : f.num ∈ 𝒜 f.deg :=
(Quotient.out f).num.2
theorem den_mem_deg (f : HomogeneousLocalization 𝒜 x) : f.den ∈ 𝒜 f.deg :=
(Quotient.out f).den.2
theorem eq_num_div_den (f : HomogeneousLocalization 𝒜 x) :
f.val = Localization.mk f.num ⟨f.den, f.den_mem⟩ :=
congr_arg HomogeneousLocalization.val (Quotient.out_eq' f).symm
theorem den_smul_val (f : HomogeneousLocalization 𝒜 x) :
f.den • f.val = algebraMap _ _ f.num := by
rw [eq_num_div_den, Localization.mk_eq_mk', IsLocalization.smul_mk']
exact IsLocalization.mk'_mul_cancel_left _ ⟨_, _⟩
theorem ext_iff_val (f g : HomogeneousLocalization 𝒜 x) : f = g ↔ f.val = g.val :=
⟨congr_arg val, fun e ↦ val_injective x e⟩
end
section
variable [AddSubgroupClass σ A] {𝒜 : ι → σ} {x : Submonoid A}
variable [AddCommMonoid ι] [DecidableEq ι] [GradedRing 𝒜]
variable (𝒜) (𝔭 : Ideal A) [Ideal.IsPrime 𝔭]
/-- Localizing a ring homogeneously at a prime ideal. -/
abbrev AtPrime :=
HomogeneousLocalization 𝒜 𝔭.primeCompl
theorem isUnit_iff_isUnit_val (f : HomogeneousLocalization.AtPrime 𝒜 𝔭) :
IsUnit f.val ↔ IsUnit f := by
refine ⟨fun h1 ↦ ?_, IsUnit.map (algebraMap _ _)⟩
rcases h1 with ⟨⟨a, b, eq0, eq1⟩, rfl : a = f.val⟩
obtain ⟨f, rfl⟩ := mk_surjective f
obtain ⟨b, s, rfl⟩ := IsLocalization.exists_mk'_eq 𝔭.primeCompl b
rw [val_mk, Localization.mk_eq_mk', ← IsLocalization.mk'_mul, IsLocalization.mk'_eq_iff_eq_mul,
one_mul, IsLocalization.eq_iff_exists (M := 𝔭.primeCompl)] at eq0
obtain ⟨c, hc : _ = c.1 * (f.den.1 * s.1)⟩ := eq0
have : f.num.1 ∉ 𝔭 := by
exact fun h ↦ mul_mem c.2 (mul_mem f.den_mem s.2)
(hc ▸ Ideal.mul_mem_left _ c.1 (Ideal.mul_mem_right b _ h))
refine .of_mul_eq_one (Quotient.mk'' ⟨f.1, f.3, f.2, this⟩) ?_
rw [← mk_mul, ext_iff_val, val_mk]
simp [mul_comm f.den.1]
instance : Nontrivial (HomogeneousLocalization.AtPrime 𝒜 𝔭) :=
⟨⟨0, 1, fun r => by simp [ext_iff_val, val_zero, val_one, zero_ne_one] at r⟩⟩
instance isLocalRing : IsLocalRing (HomogeneousLocalization.AtPrime 𝒜 𝔭) :=
IsLocalRing.of_isUnit_or_isUnit_one_sub_self fun a => by
simpa only [← isUnit_iff_isUnit_val, val_sub, val_one]
using IsLocalRing.isUnit_or_isUnit_one_sub_self _
end
section
/-- Localizing away from powers of `f` homogeneously. -/
abbrev Away (𝒜 : ι → σ) (f : A) :=
HomogeneousLocalization 𝒜 (Submonoid.powers f)
variable [AddSubgroupClass σ A] [AddCommMonoid ι] [DecidableEq ι]
variable {𝒜 : ι → σ} [GradedRing 𝒜] {f : A}
theorem Away.eventually_smul_mem {m} (hf : f ∈ 𝒜 m) (z : Away 𝒜 f) :
∀ᶠ n in Filter.atTop, f ^ n • z.val ∈ algebraMap _ _ '' (𝒜 (n • m) : Set A) := by
obtain ⟨k, hk : f ^ k = _⟩ := z.den_mem
apply Filter.mem_of_superset (Filter.Ici_mem_atTop k)
rintro k' (hk' : k ≤ k')
simp only [Set.mem_image, SetLike.mem_coe, Set.mem_setOf_eq]
by_cases hfk : f ^ k = 0
· refine ⟨0, zero_mem _, ?_⟩
rw [← tsub_add_cancel_of_le hk', map_zero, pow_add, hfk, mul_zero, zero_smul]
rw [← tsub_add_cancel_of_le hk', pow_add, mul_smul, hk, den_smul_val,
Algebra.smul_def, ← map_mul]
rw [← smul_eq_mul, add_smul,
DirectSum.degree_eq_of_mem_mem 𝒜 (SetLike.pow_mem_graded _ hf) (hk.symm ▸ z.den_mem_deg) hfk]
exact ⟨_, SetLike.mul_mem_graded (SetLike.pow_mem_graded _ hf) z.num_mem_deg, rfl⟩
end
section
variable [AddSubgroupClass σ A] [AddCommMonoid ι] [DecidableEq ι]
variable (𝒜 : ι → σ) [GradedRing 𝒜]
variable {B τ : Type*} [CommRing B] [SetLike τ B] [AddSubgroupClass τ B]
variable (ℬ : ι → τ) [GradedRing ℬ]
variable {P : Submonoid A} {Q : Submonoid B}
/--
Let `A, B` be two graded rings with the same indexing set and `g : A → B` be a graded ring
homomorphism (i.e. `g(Aₘ) ⊆ Bₘ`). Let `P ≤ A` be a submonoid and `Q ≤ B` be a submonoid such that
`P ≤ g⁻¹ Q`, then `g` induce a map from the homogeneous localizations `A⁰_P` to the homogeneous
localizations `B⁰_Q`.
-/
def map (g : A →+* B)
(comap_le : P ≤ Q.comap g) (hg : ∀ i, ∀ a ∈ 𝒜 i, g a ∈ ℬ i) :
HomogeneousLocalization 𝒜 P →+* HomogeneousLocalization ℬ Q where
toFun := Quotient.map'
(fun x ↦ ⟨x.1, ⟨_, hg _ _ x.2.2⟩, ⟨_, hg _ _ x.3.2⟩, comap_le x.4⟩)
fun x y (e : x.embedding = y.embedding) ↦ by
apply_fun IsLocalization.map (Localization Q) g comap_le at e
simp_rw [HomogeneousLocalization.NumDenSameDeg.embedding, Localization.mk_eq_mk',
IsLocalization.map_mk', ← Localization.mk_eq_mk'] at e
exact e
map_add' := Quotient.ind₂' fun x y ↦ by
simp only [← mk_add, Quotient.map'_mk'', num_add, map_add, map_mul, den_add]; rfl
map_mul' := Quotient.ind₂' fun x y ↦ by
simp only [← mk_mul, Quotient.map'_mk'', num_mul, map_mul, den_mul]; rfl
map_zero' := by simp only [← mk_zero (𝒜 := 𝒜), Quotient.map'_mk'', deg_zero,
num_zero, ZeroMemClass.coe_zero, map_zero, den_zero, map_one]; rfl
map_one' := by simp only [← mk_one (𝒜 := 𝒜), Quotient.map'_mk'',
num_one, den_one, map_one]; rfl
/--
Let `A` be a graded ring and `P ≤ Q` be two submonoids, then the homogeneous localization of `A`
at `P` embeds into the homogeneous localization of `A` at `Q`.
-/
abbrev mapId {P Q : Submonoid A} (h : P ≤ Q) :
HomogeneousLocalization 𝒜 P →+* HomogeneousLocalization 𝒜 Q :=
map 𝒜 𝒜 (RingHom.id _) h (fun _ _ ↦ id)
lemma map_mk (g : A →+* B)
(comap_le : P ≤ Q.comap g) (hg : ∀ i, ∀ a ∈ 𝒜 i, g a ∈ ℬ i) (x) :
map 𝒜 ℬ g comap_le hg (mk x) =
mk ⟨x.1, ⟨_, hg _ _ x.2.2⟩, ⟨_, hg _ _ x.3.2⟩, comap_le x.4⟩ :=
rfl
end
section mapAway
variable [AddSubgroupClass σ A] [AddCommMonoid ι] [DecidableEq ι]
variable (𝒜 : ι → σ) [GradedRing 𝒜]
variable {e : ι} {f : A} {g : A} (hg : g ∈ 𝒜 e) {x : A} (hx : x = f * g)
/-- Given `f ∣ x`, this is the map `A_{(f)} → A_f → A_x`. We will lift this to a map
`A_{(f)} → A_{(x)}` in `awayMap`. -/
private def awayMapAux (hx : f ∣ x) : Away 𝒜 f →+* Localization.Away x :=
(Localization.awayLift (algebraMap A _) _
(isUnit_of_dvd_unit (map_dvd _ hx) (IsLocalization.Away.algebraMap_isUnit x))).comp
(algebraMap (Away 𝒜 f) (Localization.Away f))
lemma awayMapAux_mk (n a i hi) :
awayMapAux 𝒜 ⟨_, hx⟩ (mk ⟨n, a, ⟨f ^ i, hi⟩, ⟨i, rfl⟩⟩) =
Localization.mk (a * g ^ i) ⟨x ^ i, (Submonoid.mem_powers_iff _ _).mpr ⟨i, rfl⟩⟩ := by
have : algebraMap A (Localization.Away x) f *
(Localization.mk g ⟨f * g, (Submonoid.mem_powers_iff _ _).mpr ⟨1, by simp [hx]⟩⟩) = 1 := by
rw [← Algebra.smul_def, Localization.smul_mk]
exact Localization.mk_self ⟨f*g, _⟩
simp [awayMapAux]
rw [Localization.awayLift_mk (hv := this), ← Algebra.smul_def,
Localization.mk_pow, Localization.smul_mk]
subst hx
rfl
include hg in
lemma range_awayMapAux_subset :
Set.range (awayMapAux 𝒜 (f := f) ⟨_, hx⟩) ⊆ Set.range (val (𝒜 := 𝒜)) := by
rintro _ ⟨z, rfl⟩
obtain ⟨⟨n, ⟨a, ha⟩, ⟨b, hb'⟩, j, rfl : _ = b⟩, rfl⟩ := mk_surjective z
use mk ⟨n+j•e,⟨a*g^j, ?_⟩, ⟨x^j, ?_⟩, j, rfl⟩
· simp [awayMapAux_mk 𝒜 (hx := hx)]
· apply SetLike.mul_mem_graded ha
exact SetLike.pow_mem_graded _ hg
· rw [hx, mul_pow]
apply SetLike.mul_mem_graded hb'
exact SetLike.pow_mem_graded _ hg
/-- Given `x = f * g` with `g` homogeneous of positive degree,
this is the map `A_{(f)} → A_{(x)}` taking `a/f^i` to `ag^i/(fg)^i`. -/
def awayMap : Away 𝒜 f →+* Away 𝒜 x := by
let e := RingEquiv.ofLeftInverse (f := algebraMap (Away 𝒜 x) (Localization.Away x))
(h := (val_injective _).hasLeftInverse.choose_spec)
refine RingHom.comp (e.symm.toRingHom.comp (Subring.inclusion ?_))
(awayMapAux 𝒜 (f := f) ⟨_, hx⟩).rangeRestrict
exact range_awayMapAux_subset 𝒜 hg hx
lemma val_awayMap_eq_aux (a) : (awayMap 𝒜 hg hx a).val = awayMapAux 𝒜 ⟨_, hx⟩ a := by
let e := RingEquiv.ofLeftInverse (f := algebraMap (Away 𝒜 x) (Localization.Away x))
(h := (val_injective _).hasLeftInverse.choose_spec)
dsimp [awayMap]
convert_to (e (e.symm ⟨awayMapAux 𝒜 (f := f) ⟨_, hx⟩ a,
range_awayMapAux_subset 𝒜 hg hx ⟨_, rfl⟩⟩)).1 = _
rw [e.apply_symm_apply]
lemma val_awayMap (a) : (awayMap 𝒜 hg hx a).val = Localization.awayLift (algebraMap A _) _
(isUnit_of_dvd_unit (map_dvd _ ⟨_, hx⟩) (IsLocalization.Away.algebraMap_isUnit x)) a.val := by
rw [val_awayMap_eq_aux]
rfl
lemma awayMap_fromZeroRingHom (a) :
awayMap 𝒜 hg hx (fromZeroRingHom 𝒜 _ a) = fromZeroRingHom 𝒜 _ a := by
ext
simp only [fromZeroRingHom, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk,
val_awayMap, val_mk, SetLike.GradeZero.coe_one]
convert IsLocalization.lift_eq _ _
lemma val_awayMap_mk (n a i hi) : (awayMap 𝒜 hg hx (mk ⟨n, a, ⟨f ^ i, hi⟩, ⟨i, rfl⟩⟩)).val =
Localization.mk (a * g ^ i) ⟨x ^ i, (Submonoid.mem_powers_iff _ _).mpr ⟨i, rfl⟩⟩ := by
rw [val_awayMap_eq_aux, awayMapAux_mk 𝒜 (hx := hx)]
/-- Given `x = f * g` with `g` homogeneous of positive degree,
this is the map `A_{(f)} → A_{(x)}` taking `a/f^i` to `ag^i/(fg)^i`. -/
def awayMapₐ : Away 𝒜 f →ₐ[𝒜 0] Away 𝒜 x where
__ := awayMap 𝒜 hg hx
commutes' _ := awayMap_fromZeroRingHom ..
@[simp] lemma awayMapₐ_apply (a) : awayMapₐ 𝒜 hg hx a = awayMap 𝒜 hg hx a := rfl
/-- This is a convenient constructor for `Away 𝒜 f` when `f` is homogeneous.
`Away.mk 𝒜 hf n x hx` is the fraction `x / f ^ n`. -/
protected def Away.mk {d : ι} (hf : f ∈ 𝒜 d) (n : ℕ) (x : A) (hx : x ∈ 𝒜 (n • d)) : Away 𝒜 f :=
HomogeneousLocalization.mk ⟨n • d, ⟨x, hx⟩, ⟨f ^ n, SetLike.pow_mem_graded n hf⟩, ⟨n, rfl⟩⟩
@[simp]
lemma Away.val_mk {d : ι} (n : ℕ) (hf : f ∈ 𝒜 d) (x : A) (hx : x ∈ 𝒜 (n • d)) :
(Away.mk 𝒜 hf n x hx).val = Localization.mk x ⟨f ^ n, by use n⟩ :=
rfl
protected
lemma Away.mk_surjective {d : ι} (hf : f ∈ 𝒜 d) (x : Away 𝒜 f) :
∃ n a ha, Away.mk 𝒜 hf n a ha = x := by
obtain ⟨⟨N, ⟨s, hs⟩, ⟨b, hn⟩, ⟨n, (rfl : _ = b)⟩⟩, rfl⟩ := mk_surjective x
by_cases hfn : f ^ n = 0
· have := HomogeneousLocalization.subsingleton 𝒜 (x := .powers f) ⟨n, hfn⟩
exact ⟨0, 0, zero_mem _, Subsingleton.elim _ _⟩
obtain rfl := DirectSum.degree_eq_of_mem_mem 𝒜 hn (SetLike.pow_mem_graded n hf) hfn
exact ⟨n, s, hs, by ext; simp⟩
open SetLike in
@[simp]
lemma awayMap_mk {d : ι} (n : ℕ) (hf : f ∈ 𝒜 d) (a : A) (ha : a ∈ 𝒜 (n • d)) :
awayMap 𝒜 hg hx (Away.mk 𝒜 hf n a ha) = Away.mk 𝒜 (hx ▸ mul_mem_graded hf hg) n
(a * g ^ n) (by rw [smul_add]; exact mul_mem_graded ha (pow_mem_graded n hg)) := by
ext
exact val_awayMap_mk ..
end mapAway
section isLocalization
variable [AddSubgroupClass σ A] {𝒜 : ℕ → σ} [GradedRing 𝒜]
variable {e d : ℕ} {f : A} (hf : f ∈ 𝒜 d) {g : A} (hg : g ∈ 𝒜 e)
/-- The element `t := g ^ d / f ^ e` such that `A_{(fg)} = A_{(f)}[1/t]`. -/
abbrev Away.isLocalizationElem : Away 𝒜 f :=
Away.mk 𝒜 hf e (g ^ d) (by convert SetLike.pow_mem_graded d hg using 2; exact mul_comm _ _)
variable {x : A} (hx : x = f * g)
/-- Let `t := g ^ d / f ^ e`, then `A_{(fg)} = A_{(f)}[1/t]`. -/
theorem Away.isLocalization_mul (hd : d ≠ 0) :
letI := (awayMap 𝒜 hg hx).toAlgebra
IsLocalization.Away (isLocalizationElem hf hg) (Away 𝒜 x) := by
letI := (awayMap 𝒜 hg hx).toAlgebra
constructor
· rintro ⟨r, n, rfl⟩
rw [map_pow, RingHom.algebraMap_toAlgebra]
let z : Away 𝒜 x := Away.mk 𝒜 (hx ▸ SetLike.mul_mem_graded hf hg) (d + e)
(g ^ e * f ^ (2 * e + d)) <| by
convert SetLike.mul_mem_graded (SetLike.pow_mem_graded e hg)
(SetLike.pow_mem_graded (2 * e + d) hf) using 2
ring
refine (isUnit_iff_exists_inv.mpr ⟨z, ?_⟩).pow _
ext
simp only [val_mul, val_one, awayMap_mk, Away.val_mk, z, Localization.mk_mul]
rw [← Localization.mk_one, Localization.mk_eq_mk_iff, Localization.r_iff_exists]
use 1
simp only [OneMemClass.coe_one, one_mul, Submonoid.coe_mul, mul_one, hx]
ring
· intro z
obtain ⟨n, s, hs, rfl⟩ := Away.mk_surjective 𝒜 (hx ▸ SetLike.mul_mem_graded hf hg) z
rcases d with - | d
· contradiction
let t : Away 𝒜 f := Away.mk 𝒜 hf (n * (e + 1)) (s * g ^ (n * d)) <| by
convert SetLike.mul_mem_graded hs (SetLike.pow_mem_graded _ hg) using 2; simp; ring
refine ⟨⟨t, ⟨_, ⟨n, rfl⟩⟩⟩, ?_⟩
ext
simp only [RingHom.algebraMap_toAlgebra, map_pow, awayMap_mk, val_mul, val_mk, val_pow,
Localization.mk_pow, Localization.mk_mul, t]
rw [Localization.mk_eq_mk_iff, Localization.r_iff_exists]
exact ⟨1, by simp; ring⟩
· intro a b e
obtain ⟨n, a, ha, rfl⟩ := Away.mk_surjective 𝒜 hf a
obtain ⟨m, b, hb, rfl⟩ := Away.mk_surjective 𝒜 hf b
replace e := congr_arg val e
simp only [RingHom.algebraMap_toAlgebra, awayMap_mk, val_mk,
Localization.mk_eq_mk_iff, Localization.r_iff_exists] at e
obtain ⟨⟨_, k, rfl⟩, hc⟩ := e
refine ⟨⟨_, k + m + n, rfl⟩, ?_⟩
ext
simp only [val_mul, val_pow, val_mk, Localization.mk_pow,
Localization.mk_eq_mk_iff, Localization.r_iff_exists, Submonoid.coe_mul, Localization.mk_mul,
SubmonoidClass.coe_pow, Subtype.exists, exists_prop]
refine ⟨_, ⟨k, rfl⟩, ?_⟩
rcases d with - | d
· contradiction
subst hx
convert congr(f ^ (e * (k + m + n)) * g ^ (d * (k + m + n)) * $hc) using 1 <;> ring
end isLocalization
section span
variable [AddSubgroupClass σ A] [AddCommMonoid ι] [DecidableEq ι] {𝒜 : ι → σ} [GradedRing 𝒜] in
/--
Let `𝒜` be a graded ring, finitely generated (as an algebra) over `𝒜₀` by `{ vᵢ }`,
where `vᵢ` has degree `dvᵢ`.
If `f : A` has degree `d`, then `𝒜_(f)` is generated (as a module) over `𝒜₀` by
elements of the form `(∏ i, vᵢ ^ aᵢ) / fᵃ` such that `∑ aᵢ • dvᵢ = a • d`.
-/
theorem Away.span_mk_prod_pow_eq_top {f : A} {d : ι} (hf : f ∈ 𝒜 d)
{ι' : Type*} [Fintype ι'] (v : ι' → A)
(hx : Algebra.adjoin (𝒜 0) (Set.range v) = ⊤) (dv : ι' → ι) (hxd : ∀ i, v i ∈ 𝒜 (dv i)) :
Submodule.span (𝒜 0) { (Away.mk 𝒜 hf a (∏ i, v i ^ ai i)
(hai ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i) : Away 𝒜 f) |
(a : ℕ) (ai : ι' → ℕ) (hai : ∑ i, ai i • dv i = a • d) } = ⊤ := by
by_cases HH : Subsingleton (HomogeneousLocalization.Away 𝒜 f)
· exact Subsingleton.elim _ _
rw [← top_le_iff]
rintro x -
obtain ⟨⟨n, ⟨a, ha⟩, ⟨b, hb'⟩, ⟨j, (rfl : _ = b)⟩⟩, rfl⟩ := mk_surjective x
by_cases hfj : f ^ j = 0
· exact (HH (HomogeneousLocalization.subsingleton _ ⟨_, hfj⟩)).elim
have : DirectSum.decompose 𝒜 a n = ⟨a, ha⟩ := Subtype.ext (DirectSum.decompose_of_mem_same 𝒜 ha)
simp_rw [← this]
clear this ha
have : a ∈ Submodule.span (𝒜 0) (Submonoid.closure (Set.range v)) := by
rw [← Algebra.adjoin_eq_span, hx]
trivial
induction this using Submodule.span_induction with
| mem a ha' =>
obtain ⟨ai, rfl⟩ := Submonoid.exists_of_mem_closure_range _ _ ha'
clear ha'
by_cases H : ∑ i, ai i • dv i = n
· apply Submodule.subset_span
refine ⟨j, ai, H.trans ?_, ?_⟩
· exact DirectSum.degree_eq_of_mem_mem 𝒜 hb'
(SetLike.pow_mem_graded j hf) hfj
· ext
simp only [val_mk, Away.val_mk]
congr
refine (DirectSum.decompose_of_mem_same _ ?_).symm
exact H ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i
· convert zero_mem (Submodule.span (𝒜 0) _)
ext
have : (DirectSum.decompose 𝒜 (∏ i : ι', v i ^ ai i) n).1 = 0 := by
refine DirectSum.decompose_of_mem_ne _ ?_ H
exact SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i
simp [this, Localization.mk_zero]
| zero =>
convert zero_mem (Submodule.span (𝒜 0) _)
ext; simp [Localization.mk_zero]
| add s t hs ht hs' ht' =>
convert add_mem hs' ht'
ext; simp [← Localization.add_mk_self]
| smul r x hx hx' =>
convert Submodule.smul_mem _ r hx'
ext
simp [Algebra.smul_def, algebraMap_eq, fromZeroRingHom, Localization.mk_mul,
-decompose_mul, coe_decompose_mul_of_left_mem_zero 𝒜 r.2]
variable [AddSubgroupClass σ A] {𝒜 : ℕ → σ} [GradedRing 𝒜] in
/-- This is strictly weaker than `Away.adjoin_mk_prod_pow_eq_top`. -/
private
theorem Away.adjoin_mk_prod_pow_eq_top_of_pos {f : A} {d : ℕ} (hf : f ∈ 𝒜 d)
{ι' : Type*} [Fintype ι'] (v : ι' → A)
(hx : Algebra.adjoin (𝒜 0) (Set.range v) = ⊤) (dv : ι' → ℕ)
(hxd : ∀ i, v i ∈ 𝒜 (dv i)) (hxd' : ∀ i, 0 < dv i) :
Algebra.adjoin (𝒜 0) { Away.mk 𝒜 hf a (∏ i, v i ^ ai i)
(hai ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i) |
(a : ℕ) (ai : ι' → ℕ) (hai : ∑ i, ai i • dv i = a • d) (_ : ∀ i, ai i ≤ d) } = ⊤ := by
rw [← top_le_iff]
change ⊤ ≤ (Algebra.adjoin (𝒜 0) _).toSubmodule
rw [← HomogeneousLocalization.Away.span_mk_prod_pow_eq_top hf v hx dv hxd, Submodule.span_le]
rintro _ ⟨a, ai, hai, rfl⟩
have H₀ : (a - ∑ i : ι', dv i * (ai i / d)) • d = ∑ k : ι', (ai k % d) • dv k := by
rw [smul_eq_mul, tsub_mul, ← smul_eq_mul, ← hai]
conv => enter [1, 1, 2, i]; rw [← Nat.mod_add_div (ai i) d]
simp_rw [smul_eq_mul, add_mul, Finset.sum_add_distrib,
mul_assoc, ← Finset.mul_sum, mul_comm d, mul_comm (_ / _)]
simp only [add_tsub_cancel_right]
have H : Away.mk 𝒜 hf a (∏ i, v i ^ ai i)
(hai ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i) =
Away.mk 𝒜 hf (a - ∑ i : ι', dv i * (ai i / d)) (∏ i, v i ^ (ai i % d))
(H₀ ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i) *
∏ i, Away.isLocalizationElem hf (hxd i) ^ (ai i / d) := by
apply (show Function.Injective (algebraMap (Away 𝒜 f) (Localization.Away f))
from val_injective _)
simp only [map_pow, map_prod, map_mul]
simp only [HomogeneousLocalization.algebraMap_apply, val_mk,
Localization.mk_pow, Localization.mk_prod, Localization.mk_mul,
← Finset.prod_mul_distrib, ← pow_add, ← pow_mul]
congr
· ext i
congr
exact Eq.symm (Nat.mod_add_div (ai i) d)
· simp only [SubmonoidClass.coe_finset_prod, ← pow_add, ← pow_mul,
Finset.prod_pow_eq_pow_sum, SubmonoidClass.coe_pow]
rw [tsub_add_cancel_of_le]
rcases d.eq_zero_or_pos with hd | hd
· simp [hd]
rw [← mul_le_mul_iff_of_pos_right hd, ← smul_eq_mul (a := a), ← hai, Finset.sum_mul]
simp_rw [smul_eq_mul, mul_comm (ai _), mul_assoc]
gcongr
exact Nat.div_mul_le_self (ai _) d
rw [H, SetLike.mem_coe]
apply (Algebra.adjoin (𝒜 0) _).mul_mem
· apply Algebra.subset_adjoin
refine ⟨a - ∑ i : ι', dv i * (ai i / d), (ai · % d), H₀.symm, ?_, rfl⟩
rcases d.eq_zero_or_pos with hd | hd
· have : ∀ (x : ι'), ai x = 0 := by simpa [hd, fun i ↦ (hxd' i).ne'] using hai
simp [this]
exact fun i ↦ (Nat.mod_lt _ hd).le
apply prod_mem
· classical
rintro j -
apply pow_mem
apply Algebra.subset_adjoin
refine ⟨dv j, Pi.single j d, ?_, ?_, ?_⟩
· simp [Pi.single_apply, mul_comm]
· aesop (add simp Pi.single_apply)
ext
simp [Pi.single_apply]
variable [AddSubgroupClass σ A] {𝒜 : ℕ → σ} [GradedRing 𝒜] in
/--
Let `𝒜` be a graded ring, finitely generated (as an algebra) over `𝒜₀` by `{ vᵢ }`,
where `vᵢ` has degree `dvᵢ`.
If `f : A` has degree `d`, then `𝒜_(f)` is generated (as an algebra) over `𝒜₀` by
elements of the form `(∏ i, vᵢ ^ aᵢ) / fᵃ` such that `∑ aᵢ • dvᵢ = a • d` and `∀ i, aᵢ ≤ d`.
-/
theorem Away.adjoin_mk_prod_pow_eq_top {f : A} {d : ℕ} (hf : f ∈ 𝒜 d)
(ι' : Type*) [Fintype ι'] (v : ι' → A)
(hx : Algebra.adjoin (𝒜 0) (Set.range v) = ⊤) (dv : ι' → ℕ) (hxd : ∀ i, v i ∈ 𝒜 (dv i)) :
Algebra.adjoin (𝒜 0) { Away.mk 𝒜 hf a (∏ i, v i ^ ai i)
(hai ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i) |
(a : ℕ) (ai : ι' → ℕ) (hai : ∑ i, ai i • dv i = a • d) (_ : ∀ i, ai i ≤ d) } = ⊤ := by
classical
let s := Finset.univ.filter (0 < dv ·)
have := Away.adjoin_mk_prod_pow_eq_top_of_pos hf (ι' := s) (v ∘ Subtype.val) ?_
(dv ∘ Subtype.val) (fun _ ↦ hxd _) (by simp [s])
swap
· rw [← top_le_iff, ← hx, Algebra.adjoin_le_iff, Set.range_subset_iff]
intro i
rcases (dv i).eq_zero_or_pos with hi | hi
· exact algebraMap_mem (R := 𝒜 0) _ ⟨v i, hi ▸ hxd i⟩
exact Algebra.subset_adjoin ⟨⟨i, by simpa [s] using hi⟩, rfl⟩
rw [← top_le_iff, ← this]
apply Algebra.adjoin_mono
rintro _ ⟨a, ai, hai : ∑ x ∈ s.attach, _ = _, h, rfl⟩
refine ⟨a, fun i ↦ if hi : i ∈ s then ai ⟨i, hi⟩ else 0, ?_, ?_, ?_⟩
· simpa [Finset.sum_attach_eq_sum_dite] using hai
· simp [apply_dite, dite_apply, h]
· congr 1
change _ = ∏ x ∈ s.attach, _
simp [Finset.prod_attach_eq_prod_dite]
variable [AddSubgroupClass σ A] {𝒜 : ℕ → σ} [GradedRing 𝒜] [Algebra.FiniteType (𝒜 0) A] in
lemma Away.finiteType (f : A) (d : ℕ) (hf : f ∈ 𝒜 d) :
Algebra.FiniteType (𝒜 0) (Away 𝒜 f) := by
constructor
obtain ⟨s, hs, hs'⟩ := GradedAlgebra.exists_finset_adjoin_eq_top_and_homogeneous_ne_zero 𝒜
choose dx hdx hxd using Subtype.forall'.mp hs'
simp_rw [Subalgebra.fg_def, ← top_le_iff,
← Away.adjoin_mk_prod_pow_eq_top hf (ι' := s) Subtype.val (by simpa) dx hxd]
rcases d.eq_zero_or_pos with hd | hd
· let f' := Away.mk 𝒜 hf 1 1 (by simp [hd, GradedOne.one_mem])
refine ⟨{f'}, Set.finite_singleton f', ?_⟩
rw [Algebra.adjoin_le_iff]
rintro _ ⟨a, ai, hai, hai', rfl⟩
obtain rfl : ai = 0 := funext <| by simpa [hd, hdx] using hai
simp only [Finset.univ_eq_attach, Pi.zero_apply, pow_zero, Finset.prod_const_one, mem_coe]
convert pow_mem (Algebra.self_mem_adjoin_singleton (𝒜 0) f') a using 1
ext
simp [f', Localization.mk_pow]
refine ⟨_, ?_, le_rfl⟩
let b := ∑ i, dx i
let s' : Set ((Fin (b + 1)) × (s → Fin (d + 1))) := { ai | ∑ i, (ai.2 i).1 * dx i = ai.1 * d }
let F : s' → Away 𝒜 f := fun ai ↦ Away.mk 𝒜 hf ai.1.1.1 (∏ i, i ^ (ai.1.2 i).1)
(by convert SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i; exact ai.2.symm)
apply (Set.finite_range F).subset
rintro _ ⟨a, ai, hai, hai', rfl⟩
refine ⟨⟨⟨⟨a, ?_⟩, fun i ↦ ⟨ai i, (hai' i).trans_lt d.lt_succ_self⟩⟩, hai⟩, rfl⟩
rw [Nat.lt_succ, ← mul_le_mul_iff_of_pos_right hd, ← smul_eq_mul, ← hai, Finset.sum_mul]
simp_rw [smul_eq_mul, mul_comm _ d]
gcongr
exact hai' _
end span
end HomogeneousLocalization |
.lake/packages/mathlib/Mathlib/RingTheory/GradedAlgebra/FiniteType.lean | import Mathlib.RingTheory.FiniteType
import Mathlib.RingTheory.GradedAlgebra.Basic
/-!
# Graded rings of finite type
We show that graded rings of finite type (over the 0-th component) are
generated by homogeneous elements of positive degree.
-/
variable {S σ ι : Type*} [DecidableEq ι] [AddCommMonoid ι]
variable [CommRing S] [SetLike σ S] [AddSubgroupClass σ S]
variable (𝒜 : ι → σ) [GradedRing 𝒜]
variable [Algebra.FiniteType (𝒜 0) S]
namespace GradedAlgebra
theorem exists_finset_adjoin_eq_top_and_homogeneous :
∃ s : Finset S, Algebra.adjoin (A := S) (𝒜 0) s = ⊤ ∧
∀ i ∈ s, SetLike.IsHomogeneousElem 𝒜 i := by
classical
obtain ⟨F, hF⟩ := Algebra.FiniteType.out (R := 𝒜 0) (A := S)
let ι₀ := Σ (x : F), (DirectSum.decompose 𝒜 x.1).support
let x (i : ι₀) : S := ((DirectSum.decompose 𝒜) i.1 i.2).1
refine ⟨Finset.univ.image x, ?_, by simpa using fun f ↦ ⟨_, (DirectSum.decompose 𝒜 f.1 f.2).2⟩⟩
rw [← top_le_iff, ← hF, Algebra.adjoin_le_iff]
intro s hs
rw [← DirectSum.sum_support_decompose 𝒜 s]
exact sum_mem fun n hn ↦ Algebra.subset_adjoin (by simpa using ⟨⟨⟨s, hs⟩, n, hn⟩, rfl⟩)
theorem exists_finset_adjoin_eq_top_and_homogeneous_ne_zero :
∃ s : Finset S, Algebra.adjoin (A := S) (𝒜 0) s = ⊤ ∧ ∀ i ∈ s, ∃ n ≠ 0, i ∈ 𝒜 n := by
obtain ⟨s, h₁, h₂⟩ := exists_finset_adjoin_eq_top_and_homogeneous 𝒜
choose! n hn using h₂
refine ⟨s.filter (n · ≠ 0), ?_, by simpa using fun i hi hin ↦ ⟨n i, hin, hn i hi⟩⟩
rw [← top_le_iff, ← h₁, Algebra.adjoin_le_iff]
rintro i hi
by_cases hi0 : n i = 0
· exact Subalgebra.algebraMap_mem
(Algebra.adjoin (𝒜 0) (s.filter (n · ≠ 0) : Set S)) ⟨i, hi0 ▸ hn i hi⟩
· exact Algebra.subset_adjoin (by simpa [hi0] using hi)
end GradedAlgebra |
.lake/packages/mathlib/Mathlib/RingTheory/GradedAlgebra/Noetherian.lean | import Mathlib.RingTheory.GradedAlgebra.Basic
import Mathlib.RingTheory.Noetherian.Basic
/-!
# The properties of a graded Noetherian ring.
This file proves that the 0-th grade of a Noetherian ring is
also a Noetherian ring.
-/
variable {ι A σ : Type*}
variable [Ring A] [IsNoetherianRing A]
variable [DecidableEq ι] [AddCommMonoid ι] [PartialOrder ι] [CanonicallyOrderedAdd ι]
variable [SetLike σ A] [AddSubgroupClass σ A]
variable (𝒜 : ι → σ) [GradedRing 𝒜]
namespace GradedRing
/-- If the internally graded ring `A` is Noetherian, then `𝒜 0` is a Noetherian ring. -/
instance GradeZero.isNoetherianRing : IsNoetherianRing (𝒜 0) :=
isNoetherianRing_of_surjective
A (𝒜 0) (GradedRing.projZeroRingHom' 𝒜) (GradedRing.projZeroRingHom'_surjective 𝒜)
end GradedRing |
.lake/packages/mathlib/Mathlib/RingTheory/GradedAlgebra/Radical.lean | import Mathlib.RingTheory.GradedAlgebra.Homogeneous.Ideal
/-!
This file contains a proof that the radical of any homogeneous ideal is a homogeneous ideal
## Main statements
* `Ideal.IsHomogeneous.isPrime_iff`: for any `I : Ideal A`, if `I` is homogeneous, then
`I` is prime if and only if `I` is homogeneously prime, i.e. `I ≠ ⊤` and if `x, y` are
homogeneous elements such that `x * y ∈ I`, then at least one of `x,y` is in `I`.
* `Ideal.IsPrime.homogeneousCore`: for any `I : Ideal A`, if `I` is prime, then
`I.homogeneous_core 𝒜` (i.e. the largest homogeneous ideal contained in `I`) is also prime.
* `Ideal.IsHomogeneous.radical`: for any `I : Ideal A`, if `I` is homogeneous, then the
radical of `I` is homogeneous as well.
* `HomogeneousIdeal.radical`: for any `I : HomogeneousIdeal 𝒜`, `I.radical` is the
radical of `I` as a `HomogeneousIdeal 𝒜`.
## Implementation details
Throughout this file, the indexing type `ι` of grading is assumed to be a
`LinearOrderedCancelAddCommMonoid`. This might be stronger than necessary but cancelling
property is strictly necessary; for a counterexample of how `Ideal.IsHomogeneous.isPrime_iff`
fails for a non-cancellative set see `Counterexamples/HomogeneousPrimeNotPrime.lean`.
## Tags
homogeneous, radical
-/
open GradedRing DirectSum SetLike Finset
variable {ι σ A : Type*}
variable [CommRing A]
variable [AddCommMonoid ι] [LinearOrder ι] [IsOrderedCancelAddMonoid ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] {𝒜 : ι → σ} [GradedRing 𝒜]
theorem Ideal.IsHomogeneous.isPrime_of_homogeneous_mem_or_mem {I : Ideal A} (hI : I.IsHomogeneous 𝒜)
(I_ne_top : I ≠ ⊤)
(homogeneous_mem_or_mem :
∀ {x y : A}, IsHomogeneousElem 𝒜 x → IsHomogeneousElem 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I) :
Ideal.IsPrime I :=
⟨I_ne_top, by
intro x y hxy
by_contra! rid
obtain ⟨rid₁, rid₂⟩ := rid
classical
/-
The idea of the proof is the following :
since `x * y ∈ I` and `I` homogeneous, then `proj i (x * y) ∈ I` for any `i : ι`.
Then consider two sets `{i ∈ x.support | xᵢ ∉ I}` and `{j ∈ y.support | yⱼ ∉ J}`;
let `max₁, max₂` be the maximum of the two sets, then `proj (max₁ + max₂) (x * y) ∈ I`.
Then, `proj max₁ x ∉ I` and `proj max₂ j ∉ I`
but `proj i x ∈ I` for all `max₁ < i` and `proj j y ∈ I` for all `max₂ < j`.
` proj (max₁ + max₂) (x * y)`
`= ∑ {(i, j) ∈ supports | i + j = max₁ + max₂}, xᵢ * yⱼ`
`= proj max₁ x * proj max₂ y`
` + ∑ {(i, j) ∈ supports \ {(max₁, max₂)} | i + j = max₁ + max₂}, xᵢ * yⱼ`.
This is a contradiction, because both `proj (max₁ + max₂) (x * y) ∈ I` and the sum on the
right-hand side is in `I` however `proj max₁ x * proj max₂ y` is not in `I`.
-/
set set₁ := {i ∈ (decompose 𝒜 x).support | proj 𝒜 i x ∉ I} with set₁_eq
set set₂ := {i ∈ (decompose 𝒜 y).support | proj 𝒜 i y ∉ I} with set₂_eq
have nonempty :
∀ x : A, x ∉ I → {i ∈ (decompose 𝒜 x).support | proj 𝒜 i x ∉ I}.Nonempty := by
intro x hx
rw [filter_nonempty_iff]
contrapose! hx
simp_rw [proj_apply] at hx
rw [← sum_support_decompose 𝒜 x]
exact Ideal.sum_mem _ hx
set max₁ := set₁.max' (nonempty x rid₁)
set max₂ := set₂.max' (nonempty y rid₂)
have mem_max₁ : max₁ ∈ set₁ := max'_mem set₁ (nonempty x rid₁)
have mem_max₂ : max₂ ∈ set₂ := max'_mem set₂ (nonempty y rid₂)
replace hxy : proj 𝒜 (max₁ + max₂) (x * y) ∈ I := hI _ hxy
have mem_I : proj 𝒜 max₁ x * proj 𝒜 max₂ y ∈ I := by
set antidiag :=
{z ∈ (decompose 𝒜 x).support ×ˢ (decompose 𝒜 y).support | z.1 + z.2 = max₁ + max₂}
with ha
have mem_antidiag : (max₁, max₂) ∈ antidiag := by
simp only [antidiag, mem_filter, mem_product]
exact ⟨⟨mem_of_mem_filter _ mem_max₁, mem_of_mem_filter _ mem_max₂⟩, trivial⟩
have eq_add_sum :=
calc
proj 𝒜 (max₁ + max₂) (x * y) = ∑ ij ∈ antidiag, proj 𝒜 ij.1 x * proj 𝒜 ij.2 y := by
simp_rw [ha, proj_apply, DirectSum.decompose_mul, DirectSum.coe_mul_apply 𝒜]
_ =
proj 𝒜 max₁ x * proj 𝒜 max₂ y +
∑ ij ∈ antidiag.erase (max₁, max₂), proj 𝒜 ij.1 x * proj 𝒜 ij.2 y :=
(add_sum_erase _ _ mem_antidiag).symm
rw [eq_sub_of_add_eq eq_add_sum.symm]
refine Ideal.sub_mem _ hxy (Ideal.sum_mem _ fun z H => ?_)
rcases z with ⟨i, j⟩
simp only [antidiag, mem_erase, Prod.mk_inj, Ne, mem_filter, mem_product] at H
rcases H with ⟨H₁, ⟨H₂, H₃⟩, H₄⟩
have max_lt : max₁ < i ∨ max₂ < j := by
convert le_or_lt_of_add_le_add H₄.ge using 1
rw [Ne.le_iff_lt]
rintro rfl
cases H₁ ⟨rfl, add_left_cancel H₄⟩
rcases max_lt with max_lt | max_lt
· -- in this case `max₁ < i`, then `xᵢ ∈ I`; for otherwise `i ∈ set₁` then `i ≤ max₁`.
have notMem : i ∉ set₁ := fun h =>
lt_irrefl _ ((max'_lt_iff set₁ (nonempty x rid₁)).mp max_lt i h)
rw [set₁_eq] at notMem
simp only [not_and, Classical.not_not, mem_filter] at notMem
exact Ideal.mul_mem_right _ I (notMem H₂)
· -- in this case `max₂ < j`, then `yⱼ ∈ I`; for otherwise `j ∈ set₂`, then `j ≤ max₂`.
have notMem : j ∉ set₂ := fun h =>
lt_irrefl _ ((max'_lt_iff set₂ (nonempty y rid₂)).mp max_lt j h)
rw [set₂_eq] at notMem
simp only [not_and, Classical.not_not, mem_filter] at notMem
exact Ideal.mul_mem_left I _ (notMem H₃)
have notMem_I : proj 𝒜 max₁ x * proj 𝒜 max₂ y ∉ I := by
have neither_mem : proj 𝒜 max₁ x ∉ I ∧ proj 𝒜 max₂ y ∉ I := by
rw [mem_filter] at mem_max₁ mem_max₂
exact ⟨mem_max₁.2, mem_max₂.2⟩
intro _rid
rcases homogeneous_mem_or_mem ⟨max₁, SetLike.coe_mem _⟩ ⟨max₂, SetLike.coe_mem _⟩ mem_I
with h | h
· apply neither_mem.1 h
· apply neither_mem.2 h
exact notMem_I mem_I⟩
theorem Ideal.IsHomogeneous.isPrime_iff {I : Ideal A} (h : I.IsHomogeneous 𝒜) :
I.IsPrime ↔
I ≠ ⊤ ∧
∀ {x y : A},
IsHomogeneousElem 𝒜 x → IsHomogeneousElem 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I :=
⟨fun HI => ⟨HI.ne_top, fun _ _ hxy => Ideal.IsPrime.mem_or_mem HI hxy⟩,
fun ⟨I_ne_top, homogeneous_mem_or_mem⟩ =>
h.isPrime_of_homogeneous_mem_or_mem I_ne_top @homogeneous_mem_or_mem⟩
theorem Ideal.IsPrime.homogeneousCore {I : Ideal A} (h : I.IsPrime) :
(I.homogeneousCore 𝒜).toIdeal.IsPrime := by
apply (Ideal.homogeneousCore 𝒜 I).isHomogeneous.isPrime_of_homogeneous_mem_or_mem
· exact ne_top_of_le_ne_top h.ne_top (Ideal.toIdeal_homogeneousCore_le 𝒜 I)
rintro x y hx hy hxy
have H := h.mem_or_mem (Ideal.toIdeal_homogeneousCore_le 𝒜 I hxy)
refine H.imp ?_ ?_
· exact Ideal.mem_homogeneousCore_of_homogeneous_of_mem hx
· exact Ideal.mem_homogeneousCore_of_homogeneous_of_mem hy
theorem Ideal.IsHomogeneous.radical_eq {I : Ideal A} (hI : I.IsHomogeneous 𝒜) :
I.radical = InfSet.sInf { J | Ideal.IsHomogeneous 𝒜 J ∧ I ≤ J ∧ J.IsPrime } := by
rw [Ideal.radical_eq_sInf]
apply le_antisymm
· exact sInf_le_sInf fun J => And.right
· refine sInf_le_sInf_of_isCoinitialFor ?_
rintro J ⟨HJ₁, HJ₂⟩
refine ⟨(J.homogeneousCore 𝒜).toIdeal, ?_, J.toIdeal_homogeneousCore_le _⟩
refine ⟨HomogeneousIdeal.isHomogeneous _, ?_, HJ₂.homogeneousCore⟩
exact hI.toIdeal_homogeneousCore_eq_self.symm.trans_le (Ideal.homogeneousCore_mono _ HJ₁)
theorem Ideal.IsHomogeneous.radical {I : Ideal A} (h : I.IsHomogeneous 𝒜) :
I.radical.IsHomogeneous 𝒜 := by
rw [h.radical_eq]
exact Ideal.IsHomogeneous.sInf fun _ => And.left
/-- The radical of a homogeneous ideal, as another homogeneous ideal. -/
def HomogeneousIdeal.radical (I : HomogeneousIdeal 𝒜) : HomogeneousIdeal 𝒜 :=
⟨I.toIdeal.radical, I.isHomogeneous.radical⟩
@[simp]
theorem HomogeneousIdeal.coe_radical (I : HomogeneousIdeal 𝒜) :
I.radical.toIdeal = I.toIdeal.radical := rfl |
.lake/packages/mathlib/Mathlib/RingTheory/GradedAlgebra/Homogeneous/Subsemiring.lean | import Mathlib.Algebra.DirectSum.Decomposition
import Mathlib.RingTheory.GradedAlgebra.Basic
/-!
# Homogeneous subsemirings of a graded semiring
This file defines homogeneous subsemirings of a graded semiring, as well as operations on them.
## Main definitions
* `HomogeneousSubsemiring 𝒜`: The type of subsemirings which satisfy `SetLike.IsHomogeneous`.
-/
open DirectSum Set SetLike
variable {ι σ A : Type*} [AddMonoid ι] [Semiring A]
variable [SetLike σ A] [AddSubmonoidClass σ A]
variable (𝒜 : ι → σ) [DecidableEq ι] [GradedRing 𝒜]
variable (R : Subsemiring A)
section HomogeneousDef
variable {R} in
theorem DirectSum.SetLike.IsHomogeneous.mem_iff (hR : IsHomogeneous 𝒜 R) {a} :
a ∈ R ↔ ∀ i, (decompose 𝒜 a i : A) ∈ R :=
AddSubmonoidClass.IsHomogeneous.mem_iff 𝒜 _ hR
/-- A `HomogeneousSubsemiring` is a `Subsemiring` that satisfies `IsHomogeneous`. -/
structure HomogeneousSubsemiring extends Subsemiring A where
is_homogeneous' : IsHomogeneous 𝒜 toSubsemiring
variable {𝒜}
namespace HomogeneousSubsemiring
theorem toSubsemiring_injective :
(toSubsemiring : HomogeneousSubsemiring 𝒜 → Subsemiring A).Injective :=
fun ⟨x, hx⟩ ⟨y, hy⟩ => fun (h : x = y) => by simp [h]
instance setLike : SetLike (HomogeneousSubsemiring 𝒜) A where
coe x := x.carrier
coe_injective' _ _ h := toSubsemiring_injective <| SetLike.coe_injective h
theorem isHomogeneous (R : HomogeneousSubsemiring 𝒜) :
IsHomogeneous 𝒜 R := R.is_homogeneous'
instance subsemiringClass : SubsemiringClass (HomogeneousSubsemiring 𝒜) A where
mul_mem {a} := a.toSubsemiring.mul_mem
one_mem {a} := a.toSubsemiring.one_mem
add_mem {a} := a.toSubsemiring.add_mem
zero_mem {a} := a.toSubsemiring.zero_mem
@[ext]
theorem ext {R S : HomogeneousSubsemiring 𝒜}
(h : R.toSubsemiring = S.toSubsemiring) : R = S :=
HomogeneousSubsemiring.toSubsemiring_injective h
theorem ext' {R S : HomogeneousSubsemiring 𝒜}
(h : ∀ i, ∀ a ∈ 𝒜 i, a ∈ R ↔ a ∈ S) : R = S :=
AddSubmonoidClass.IsHomogeneous.ext R.2 S.2 h
@[simp high]
theorem mem_iff {R : HomogeneousSubsemiring 𝒜} {a} :
a ∈ R.toSubsemiring ↔ a ∈ R :=
Iff.rfl
end HomogeneousSubsemiring
theorem IsHomogeneous.subsemiringClosure {s : Set A}
(h : ∀ (i : ι) ⦃x : A⦄, x ∈ s → (decompose 𝒜 x i : A) ∈ s) :
IsHomogeneous 𝒜 (Subsemiring.closure s) := fun i x hx ↦ by
induction hx using Subsemiring.closure_induction generalizing i with
| mem _ hx => exact Subsemiring.subset_closure <| h i hx
| zero => simp
| one =>
rw [decompose_one, one_def]
obtain rfl | h := eq_or_ne i 0 <;> simp [of_eq_of_ne, *]
| add _ _ _ _ h₁ h₂ => simpa using add_mem (h₁ i) (h₂ i)
| mul x y _ _ h₁ h₂ =>
classical
rw [decompose_mul, DirectSum.mul_eq_dfinsuppSum]
rw [DFinsupp.sum_apply, DFinsupp.sum, AddSubmonoidClass.coe_finset_sum]
refine sum_mem fun j _ ↦ ?_
rw [DFinsupp.sum_apply, DFinsupp.sum, AddSubmonoidClass.coe_finset_sum]
refine sum_mem fun k _ ↦ ?_
obtain rfl | h := eq_or_ne i (j + k) <;> simp [of_eq_of_ne, mul_mem, *]
theorem IsHomogeneous.subsemiringClosure_of_isHomogeneousElem {s : Set A}
(h : ∀ x ∈ s, IsHomogeneousElem 𝒜 x) :
IsHomogeneous 𝒜 (Subsemiring.closure s) :=
Subsemiring.closure_insert_zero s ▸ IsHomogeneous.subsemiringClosure fun i x hx ↦
hx.elim (by subst ·; simp) fun hx ↦ by
obtain ⟨j, hj⟩ := h x hx
obtain rfl | h := eq_or_ne i j <;> simp [decompose_of_mem _ hj, of_eq_of_ne, *]
end HomogeneousDef
section HomogeneousCore
/-- For any subsemiring `R`, not necessarily homogeneous, `R.homogeneousCore 𝒜` is the largest
homogeneous subsemiring contained in `R`. -/
def Subsemiring.homogeneousCore : HomogeneousSubsemiring 𝒜 where
__ := Subsemiring.closure ((↑) '' (((↑) : Subtype (IsHomogeneousElem 𝒜) → A) ⁻¹' R))
is_homogeneous' := IsHomogeneous.subsemiringClosure_of_isHomogeneousElem fun x ↦ by
rintro ⟨x, _, rfl⟩; exact x.2
theorem Subsemiring.homogeneousCore_mono : Monotone (Subsemiring.homogeneousCore 𝒜) :=
fun _ _ h => Subsemiring.closure_mono <| Set.image_mono <| fun _ ↦ @h _
theorem Subsemiring.toSubsemiring_homogeneousCore_le : (R.homogeneousCore 𝒜).toSubsemiring ≤ R :=
Subsemiring.closure_le.2 <| image_preimage_subset _ _
end HomogeneousCore
section IsHomogeneousSubsemiringDefs
theorem Subsemiring.isHomogeneous_iff_forall_subset :
SetLike.IsHomogeneous 𝒜 R ↔ ∀ i, (R : Set A) ⊆ GradedRing.proj 𝒜 i ⁻¹' (R : Set A) :=
Iff.rfl
theorem Subsemiring.isHomogeneous_iff_subset_iInter :
SetLike.IsHomogeneous 𝒜 R ↔ (R : Set A) ⊆ ⋂ i, GradedRing.proj 𝒜 i ⁻¹' R :=
subset_iInter_iff.symm
end IsHomogeneousSubsemiringDefs |
.lake/packages/mathlib/Mathlib/RingTheory/GradedAlgebra/Homogeneous/Ideal.lean | import Mathlib.LinearAlgebra.Finsupp.SumProd
import Mathlib.RingTheory.GradedAlgebra.Basic
import Mathlib.RingTheory.Ideal.Basic
import Mathlib.RingTheory.Ideal.BigOperators
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.RingTheory.GradedAlgebra.Homogeneous.Submodule
/-!
# Homogeneous ideals of a graded algebra
This file defines homogeneous ideals of `GradedRing 𝒜` where `𝒜 : ι → Submodule R A` and
operations on them.
## Main definitions
For any `I : Ideal A`:
* `Ideal.IsHomogeneous 𝒜 I`: The property that an ideal is closed under `GradedRing.proj`.
* `HomogeneousIdeal 𝒜`: The structure extending ideals which satisfy `Ideal.IsHomogeneous`.
* `Ideal.homogeneousCore I 𝒜`: The largest homogeneous ideal smaller than `I`.
* `Ideal.homogeneousHull I 𝒜`: The smallest homogeneous ideal larger than `I`.
## Main statements
* `HomogeneousIdeal.completeLattice`: `Ideal.IsHomogeneous` is preserved by `⊥`, `⊤`, `⊔`, `⊓`,
`⨆`, `⨅`, and so the subtype of homogeneous ideals inherits a complete lattice structure.
* `Ideal.homogeneousCore.gi`: `Ideal.homogeneousCore` forms a Galois insertion with coercion.
* `Ideal.homogeneousHull.gi`: `Ideal.homogeneousHull` forms a Galois insertion with coercion.
## Implementation notes
We introduce `Ideal.homogeneousCore'` earlier than might be expected so that we can get access
to `Ideal.IsHomogeneous.iff_exists` as quickly as possible.
## Tags
graded algebra, homogeneous
-/
open SetLike DirectSum Set
open Pointwise DirectSum
variable {ι σ A : Type*}
section HomogeneousDef
variable [Semiring A]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ)
variable [DecidableEq ι] [AddMonoid ι] [GradedRing 𝒜]
variable (I : Ideal A)
/-- An `I : Ideal A` is homogeneous if for every `r ∈ I`, all homogeneous components
of `r` are in `I`. -/
abbrev Ideal.IsHomogeneous : Prop := Submodule.IsHomogeneous I 𝒜
theorem Ideal.IsHomogeneous.mem_iff {I} (hI : Ideal.IsHomogeneous 𝒜 I) {x} :
x ∈ I ↔ ∀ i, (decompose 𝒜 x i : A) ∈ I :=
AddSubmonoidClass.IsHomogeneous.mem_iff 𝒜 _ hI
/-- For any `Semiring A`, we collect the homogeneous ideals of `A` into a type. -/
abbrev HomogeneousIdeal := HomogeneousSubmodule 𝒜 𝒜
variable {𝒜}
/-- Converting a homogeneous ideal to an ideal. -/
abbrev HomogeneousIdeal.toIdeal (I : HomogeneousIdeal 𝒜) : Ideal A :=
I.toSubmodule
theorem HomogeneousIdeal.isHomogeneous (I : HomogeneousIdeal 𝒜) :
I.toIdeal.IsHomogeneous 𝒜 := I.is_homogeneous'
theorem HomogeneousIdeal.toIdeal_injective :
Function.Injective (HomogeneousIdeal.toIdeal : HomogeneousIdeal 𝒜 → Ideal A) :=
HomogeneousSubmodule.toSubmodule_injective 𝒜 𝒜
instance HomogeneousIdeal.setLike : SetLike (HomogeneousIdeal 𝒜) A :=
HomogeneousSubmodule.setLike 𝒜 𝒜
@[ext]
theorem HomogeneousIdeal.ext {I J : HomogeneousIdeal 𝒜} (h : I.toIdeal = J.toIdeal) : I = J :=
HomogeneousIdeal.toIdeal_injective h
theorem HomogeneousIdeal.ext' {I J : HomogeneousIdeal 𝒜} (h : ∀ i, ∀ x ∈ 𝒜 i, x ∈ I ↔ x ∈ J) :
I = J := HomogeneousSubmodule.ext' 𝒜 𝒜 h
@[simp high]
theorem HomogeneousIdeal.mem_iff {I : HomogeneousIdeal 𝒜} {x : A} : x ∈ I.toIdeal ↔ x ∈ I :=
Iff.rfl
end HomogeneousDef
section HomogeneousCore
variable [Semiring A]
variable [SetLike σ A] (𝒜 : ι → σ)
variable (I : Ideal A)
/-- For any `I : Ideal A`, not necessarily homogeneous, `I.homogeneousCore' 𝒜`
is the largest homogeneous ideal of `A` contained in `I`, as an ideal. -/
def Ideal.homogeneousCore' (I : Ideal A) : Ideal A :=
Ideal.span ((↑) '' (((↑) : Subtype (SetLike.IsHomogeneousElem 𝒜) → A) ⁻¹' I))
theorem Ideal.homogeneousCore'_mono : Monotone (Ideal.homogeneousCore' 𝒜) :=
fun _ _ I_le_J => Ideal.span_mono <| Set.image_mono fun _ => @I_le_J _
theorem Ideal.homogeneousCore'_le : I.homogeneousCore' 𝒜 ≤ I :=
Ideal.span_le.2 <| image_preimage_subset _ _
end HomogeneousCore
section IsHomogeneousIdealDefs
variable [Semiring A]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ)
variable [DecidableEq ι] [AddMonoid ι] [GradedRing 𝒜]
variable (I : Ideal A)
theorem Ideal.isHomogeneous_iff_forall_subset :
I.IsHomogeneous 𝒜 ↔ ∀ i, (I : Set A) ⊆ GradedRing.proj 𝒜 i ⁻¹' I :=
Iff.rfl
theorem Ideal.isHomogeneous_iff_subset_iInter :
I.IsHomogeneous 𝒜 ↔ (I : Set A) ⊆ ⋂ i, GradedRing.proj 𝒜 i ⁻¹' ↑I :=
subset_iInter_iff.symm
theorem Ideal.mul_homogeneous_element_mem_of_mem
{I : Ideal A} (r x : A) (hx₁ : SetLike.IsHomogeneousElem 𝒜 x)
(hx₂ : x ∈ I) (j : ι) : GradedRing.proj 𝒜 j (r * x) ∈ I := by
classical
rw [← DirectSum.sum_support_decompose 𝒜 r, Finset.sum_mul, map_sum]
apply Ideal.sum_mem
intro k _
obtain ⟨i, hi⟩ := hx₁
have mem₁ : (DirectSum.decompose 𝒜 r k : A) * x ∈ 𝒜 (k + i) :=
GradedMul.mul_mem (SetLike.coe_mem _) hi
rw [GradedRing.proj_apply, DirectSum.decompose_of_mem 𝒜 mem₁, coe_of_apply]
split_ifs
· exact I.mul_mem_left _ hx₂
· exact I.zero_mem
theorem Ideal.homogeneous_span (s : Set A) (h : ∀ x ∈ s, SetLike.IsHomogeneousElem 𝒜 x) :
(Ideal.span s).IsHomogeneous 𝒜 := by
rintro i r hr
rw [Ideal.span, Finsupp.span_eq_range_linearCombination] at hr
rw [LinearMap.mem_range] at hr
obtain ⟨s, rfl⟩ := hr
rw [Finsupp.linearCombination_apply, Finsupp.sum, decompose_sum, DFinsupp.finset_sum_apply,
AddSubmonoidClass.coe_finset_sum]
refine Ideal.sum_mem _ ?_
rintro z hz1
rw [smul_eq_mul]
refine Ideal.mul_homogeneous_element_mem_of_mem 𝒜 (s z) z ?_ ?_ i
· rcases z with ⟨z, hz2⟩
apply h _ hz2
· exact Ideal.subset_span z.2
/-- For any `I : Ideal A`, not necessarily homogeneous, `I.homogeneousCore' 𝒜`
is the largest homogeneous ideal of `A` contained in `I`. -/
def Ideal.homogeneousCore : HomogeneousIdeal 𝒜 :=
⟨Ideal.homogeneousCore' 𝒜 I,
Ideal.homogeneous_span _ _ fun _ h => by
have := Subtype.image_preimage_coe (setOf (SetLike.IsHomogeneousElem 𝒜)) (I : Set A)
exact (cast congr(_ ∈ $this) h).1⟩
theorem Ideal.homogeneousCore_mono : Monotone (Ideal.homogeneousCore 𝒜) :=
Ideal.homogeneousCore'_mono 𝒜
theorem Ideal.toIdeal_homogeneousCore_le : (I.homogeneousCore 𝒜).toIdeal ≤ I :=
Ideal.homogeneousCore'_le 𝒜 I
variable {𝒜 I}
theorem Ideal.mem_homogeneousCore_of_homogeneous_of_mem {x : A} (h : SetLike.IsHomogeneousElem 𝒜 x)
(hmem : x ∈ I) : x ∈ I.homogeneousCore 𝒜 :=
Ideal.subset_span ⟨⟨x, h⟩, hmem, rfl⟩
theorem Ideal.IsHomogeneous.toIdeal_homogeneousCore_eq_self (h : I.IsHomogeneous 𝒜) :
(I.homogeneousCore 𝒜).toIdeal = I := by
apply le_antisymm (I.homogeneousCore'_le 𝒜) _
intro x hx
classical
rw [← DirectSum.sum_support_decompose 𝒜 x]
exact Ideal.sum_mem _ fun j _ => Ideal.subset_span ⟨⟨_, isHomogeneousElem_coe _⟩, h _ hx, rfl⟩
@[simp]
theorem HomogeneousIdeal.toIdeal_homogeneousCore_eq_self (I : HomogeneousIdeal 𝒜) :
I.toIdeal.homogeneousCore 𝒜 = I := by
ext1
convert Ideal.IsHomogeneous.toIdeal_homogeneousCore_eq_self I.isHomogeneous
variable (𝒜 I)
theorem Ideal.IsHomogeneous.iff_eq : I.IsHomogeneous 𝒜 ↔ (I.homogeneousCore 𝒜).toIdeal = I :=
⟨fun hI => hI.toIdeal_homogeneousCore_eq_self, fun hI => hI ▸ (Ideal.homogeneousCore 𝒜 I).2⟩
theorem Ideal.IsHomogeneous.iff_exists :
I.IsHomogeneous 𝒜 ↔ ∃ S : Set (homogeneousSubmonoid 𝒜), I = Ideal.span ((↑) '' S) := by
rw [Ideal.IsHomogeneous.iff_eq, eq_comm]
exact ((Set.image_preimage.compose (Submodule.gi _ _).gc).exists_eq_l _).symm
end IsHomogeneousIdealDefs
/-! ### Operations
In this section, we show that `Ideal.IsHomogeneous` is preserved by various notations, then use
these results to provide these notation typeclasses for `HomogeneousIdeal`. -/
section Operations
section Semiring
variable [Semiring A] [DecidableEq ι] [AddMonoid ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜]
namespace Ideal.IsHomogeneous
theorem bot : Ideal.IsHomogeneous 𝒜 ⊥ := fun i r hr => by
simp only [Ideal.mem_bot] at hr
rw [hr, decompose_zero, zero_apply]
apply Ideal.zero_mem
theorem top : Ideal.IsHomogeneous 𝒜 ⊤ := fun i r _ => by simp only [Submodule.mem_top]
variable {𝒜}
theorem inf {I J : Ideal A} (HI : I.IsHomogeneous 𝒜) (HJ : J.IsHomogeneous 𝒜) :
(I ⊓ J).IsHomogeneous 𝒜 :=
fun _ _ hr => ⟨HI _ hr.1, HJ _ hr.2⟩
theorem sup {I J : Ideal A} (HI : I.IsHomogeneous 𝒜) (HJ : J.IsHomogeneous 𝒜) :
(I ⊔ J).IsHomogeneous 𝒜 := by
rw [iff_exists] at HI HJ ⊢
obtain ⟨⟨s₁, rfl⟩, ⟨s₂, rfl⟩⟩ := HI, HJ
refine ⟨s₁ ∪ s₂, ?_⟩
rw [Set.image_union]
exact (Submodule.span_union _ _).symm
protected theorem iSup {κ : Sort*} {f : κ → Ideal A} (h : ∀ i, (f i).IsHomogeneous 𝒜) :
(⨆ i, f i).IsHomogeneous 𝒜 := by
simp_rw [iff_exists] at h ⊢
choose s hs using h
refine ⟨⋃ i, s i, ?_⟩
simp_rw [Set.image_iUnion, Ideal.span_iUnion]
congr
exact funext hs
protected theorem iInf {κ : Sort*} {f : κ → Ideal A} (h : ∀ i, (f i).IsHomogeneous 𝒜) :
(⨅ i, f i).IsHomogeneous 𝒜 := by
intro i x hx
simp only [Ideal.mem_iInf] at hx ⊢
exact fun j => h _ _ (hx j)
theorem iSup₂ {κ : Sort*} {κ' : κ → Sort*} {f : ∀ i, κ' i → Ideal A}
(h : ∀ i j, (f i j).IsHomogeneous 𝒜) : (⨆ (i) (j), f i j).IsHomogeneous 𝒜 :=
IsHomogeneous.iSup fun i => IsHomogeneous.iSup <| h i
theorem iInf₂ {κ : Sort*} {κ' : κ → Sort*} {f : ∀ i, κ' i → Ideal A}
(h : ∀ i j, (f i j).IsHomogeneous 𝒜) : (⨅ (i) (j), f i j).IsHomogeneous 𝒜 :=
IsHomogeneous.iInf fun i => IsHomogeneous.iInf <| h i
theorem sSup {ℐ : Set (Ideal A)} (h : ∀ I ∈ ℐ, Ideal.IsHomogeneous 𝒜 I) :
(sSup ℐ).IsHomogeneous 𝒜 := by
rw [sSup_eq_iSup]
exact iSup₂ h
theorem sInf {ℐ : Set (Ideal A)} (h : ∀ I ∈ ℐ, Ideal.IsHomogeneous 𝒜 I) :
(sInf ℐ).IsHomogeneous 𝒜 := by
rw [sInf_eq_iInf]
exact iInf₂ h
end Ideal.IsHomogeneous
variable {𝒜}
namespace HomogeneousIdeal
instance : PartialOrder (HomogeneousIdeal 𝒜) :=
SetLike.instPartialOrder
instance : Top (HomogeneousIdeal 𝒜) :=
⟨⟨⊤, Ideal.IsHomogeneous.top 𝒜⟩⟩
instance : Bot (HomogeneousIdeal 𝒜) :=
⟨⟨⊥, Ideal.IsHomogeneous.bot 𝒜⟩⟩
instance : Max (HomogeneousIdeal 𝒜) :=
⟨fun I J => ⟨_, I.isHomogeneous.sup J.isHomogeneous⟩⟩
instance : Min (HomogeneousIdeal 𝒜) :=
⟨fun I J => ⟨_, I.isHomogeneous.inf J.isHomogeneous⟩⟩
instance : SupSet (HomogeneousIdeal 𝒜) :=
⟨fun S => ⟨⨆ s ∈ S, toIdeal s, Ideal.IsHomogeneous.iSup₂ fun s _ => s.isHomogeneous⟩⟩
instance : InfSet (HomogeneousIdeal 𝒜) :=
⟨fun S => ⟨⨅ s ∈ S, toIdeal s, Ideal.IsHomogeneous.iInf₂ fun s _ => s.isHomogeneous⟩⟩
@[simp]
theorem coe_top : ((⊤ : HomogeneousIdeal 𝒜) : Set A) = univ :=
rfl
@[simp]
theorem coe_bot : ((⊥ : HomogeneousIdeal 𝒜) : Set A) = 0 :=
rfl
@[simp]
theorem coe_sup (I J : HomogeneousIdeal 𝒜) : ↑(I ⊔ J) = (I + J : Set A) :=
Submodule.coe_sup _ _
@[simp]
theorem coe_inf (I J : HomogeneousIdeal 𝒜) : (↑(I ⊓ J) : Set A) = ↑I ∩ ↑J :=
rfl
@[simp]
theorem toIdeal_top : (⊤ : HomogeneousIdeal 𝒜).toIdeal = (⊤ : Ideal A) :=
rfl
@[simp]
theorem toIdeal_bot : (⊥ : HomogeneousIdeal 𝒜).toIdeal = (⊥ : Ideal A) :=
rfl
@[simp]
theorem toIdeal_sup (I J : HomogeneousIdeal 𝒜) : (I ⊔ J).toIdeal = I.toIdeal ⊔ J.toIdeal :=
rfl
@[simp]
theorem toIdeal_inf (I J : HomogeneousIdeal 𝒜) : (I ⊓ J).toIdeal = I.toIdeal ⊓ J.toIdeal :=
rfl
@[simp]
theorem toIdeal_sSup (ℐ : Set (HomogeneousIdeal 𝒜)) : (sSup ℐ).toIdeal = ⨆ s ∈ ℐ, toIdeal s :=
rfl
@[simp]
theorem toIdeal_sInf (ℐ : Set (HomogeneousIdeal 𝒜)) : (sInf ℐ).toIdeal = ⨅ s ∈ ℐ, toIdeal s :=
rfl
@[simp]
theorem toIdeal_iSup {κ : Sort*} (s : κ → HomogeneousIdeal 𝒜) :
(⨆ i, s i).toIdeal = ⨆ i, (s i).toIdeal := by
rw [iSup, toIdeal_sSup, iSup_range]
@[simp]
theorem toIdeal_iInf {κ : Sort*} (s : κ → HomogeneousIdeal 𝒜) :
(⨅ i, s i).toIdeal = ⨅ i, (s i).toIdeal := by
rw [iInf, toIdeal_sInf, iInf_range]
theorem toIdeal_iSup₂ {κ : Sort*} {κ' : κ → Sort*} (s : ∀ i, κ' i → HomogeneousIdeal 𝒜) :
(⨆ (i) (j), s i j).toIdeal = ⨆ (i) (j), (s i j).toIdeal := by
simp_rw [toIdeal_iSup]
theorem toIdeal_iInf₂ {κ : Sort*} {κ' : κ → Sort*} (s : ∀ i, κ' i → HomogeneousIdeal 𝒜) :
(⨅ (i) (j), s i j).toIdeal = ⨅ (i) (j), (s i j).toIdeal := by
simp_rw [toIdeal_iInf]
@[simp]
theorem eq_top_iff (I : HomogeneousIdeal 𝒜) : I = ⊤ ↔ I.toIdeal = ⊤ :=
toIdeal_injective.eq_iff.symm
@[simp]
theorem eq_bot_iff (I : HomogeneousIdeal 𝒜) : I = ⊥ ↔ I.toIdeal = ⊥ :=
toIdeal_injective.eq_iff.symm
instance completeLattice : CompleteLattice (HomogeneousIdeal 𝒜) :=
toIdeal_injective.completeLattice _ toIdeal_sup toIdeal_inf toIdeal_sSup toIdeal_sInf toIdeal_top
toIdeal_bot
instance : Add (HomogeneousIdeal 𝒜) :=
⟨(· ⊔ ·)⟩
@[simp]
theorem toIdeal_add (I J : HomogeneousIdeal 𝒜) : (I + J).toIdeal = I.toIdeal + J.toIdeal :=
rfl
instance : Inhabited (HomogeneousIdeal 𝒜) where default := ⊥
end HomogeneousIdeal
end Semiring
section CommSemiring
variable [CommSemiring A]
variable [DecidableEq ι] [AddMonoid ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] {𝒜 : ι → σ} [GradedRing 𝒜]
variable (I : Ideal A)
theorem Ideal.IsHomogeneous.mul {I J : Ideal A} (HI : I.IsHomogeneous 𝒜) (HJ : J.IsHomogeneous 𝒜) :
(I * J).IsHomogeneous 𝒜 := by
rw [Ideal.IsHomogeneous.iff_exists] at HI HJ ⊢
obtain ⟨⟨s₁, rfl⟩, ⟨s₂, rfl⟩⟩ := HI, HJ
rw [Ideal.span_mul_span']
exact ⟨s₁ * s₂, congr_arg _ <| (Set.image_mul (homogeneousSubmonoid 𝒜).subtype).symm⟩
instance : Mul (HomogeneousIdeal 𝒜) where
mul I J := ⟨I.toIdeal * J.toIdeal, I.isHomogeneous.mul J.isHomogeneous⟩
@[simp]
theorem HomogeneousIdeal.toIdeal_mul (I J : HomogeneousIdeal 𝒜) :
(I * J).toIdeal = I.toIdeal * J.toIdeal :=
rfl
end CommSemiring
end Operations
/-! ### Homogeneous core
Note that many results about the homogeneous core came earlier in this file, as they are helpful
for building the lattice structure. -/
section homogeneousCore
open HomogeneousIdeal
variable [Semiring A] [DecidableEq ι] [AddMonoid ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜]
variable (I : Ideal A)
theorem Ideal.homogeneousCore.gc : GaloisConnection toIdeal (Ideal.homogeneousCore 𝒜) := fun I _ =>
⟨fun H => I.toIdeal_homogeneousCore_eq_self ▸ Ideal.homogeneousCore_mono 𝒜 H,
fun H => le_trans H (Ideal.homogeneousCore'_le _ _)⟩
/-- `toIdeal : HomogeneousIdeal 𝒜 → Ideal A` and `Ideal.homogeneousCore 𝒜` forms a Galois
coinsertion. -/
def Ideal.homogeneousCore.gi : GaloisCoinsertion toIdeal (Ideal.homogeneousCore 𝒜) where
choice I HI :=
⟨I, le_antisymm (I.toIdeal_homogeneousCore_le 𝒜) HI ▸ HomogeneousIdeal.isHomogeneous _⟩
gc := Ideal.homogeneousCore.gc 𝒜
u_l_le _ := Ideal.homogeneousCore'_le _ _
choice_eq I H := le_antisymm H (I.toIdeal_homogeneousCore_le _)
theorem Ideal.homogeneousCore_eq_sSup :
I.homogeneousCore 𝒜 = sSup { J : HomogeneousIdeal 𝒜 | J.toIdeal ≤ I } :=
Eq.symm <| IsLUB.sSup_eq <| (Ideal.homogeneousCore.gc 𝒜).isGreatest_u.isLUB
theorem Ideal.homogeneousCore'_eq_sSup :
I.homogeneousCore' 𝒜 = sSup { J : Ideal A | J.IsHomogeneous 𝒜 ∧ J ≤ I } := by
refine (IsLUB.sSup_eq ?_).symm
apply IsGreatest.isLUB
have coe_mono : Monotone (toIdeal : HomogeneousIdeal 𝒜 → Ideal A) := fun x y => id
convert coe_mono.map_isGreatest (Ideal.homogeneousCore.gc 𝒜).isGreatest_u using 1
ext x
rw [mem_image, mem_setOf_eq]
refine ⟨fun hI => ⟨⟨x, hI.1⟩, ⟨hI.2, rfl⟩⟩, ?_⟩
rintro ⟨x, ⟨hx, rfl⟩⟩
exact ⟨x.isHomogeneous, hx⟩
end homogeneousCore
/-! ### Homogeneous hulls -/
section HomogeneousHull
open HomogeneousIdeal
variable [Semiring A] [DecidableEq ι] [AddMonoid ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜]
variable (I : Ideal A)
/-- For any `I : Ideal A`, not necessarily homogeneous, `I.homogeneousHull 𝒜` is
the smallest homogeneous ideal containing `I`. -/
def Ideal.homogeneousHull : HomogeneousIdeal 𝒜 :=
⟨Ideal.span { r : A | ∃ (i : ι) (x : I), (DirectSum.decompose 𝒜 (x : A) i : A) = r }, by
refine Ideal.homogeneous_span _ _ fun x hx => ?_
obtain ⟨i, x, rfl⟩ := hx
apply SetLike.isHomogeneousElem_coe⟩
theorem Ideal.le_toIdeal_homogeneousHull : I ≤ (Ideal.homogeneousHull 𝒜 I).toIdeal := by
intro r hr
classical
rw [← DirectSum.sum_support_decompose 𝒜 r]
refine Ideal.sum_mem _ ?_
intro j _
apply Ideal.subset_span
use j
use ⟨r, hr⟩
theorem Ideal.homogeneousHull_mono : Monotone (Ideal.homogeneousHull 𝒜) := fun I J I_le_J => by
apply Ideal.span_mono
rintro r ⟨hr1, ⟨x, hx⟩, rfl⟩
exact ⟨hr1, ⟨⟨x, I_le_J hx⟩, rfl⟩⟩
variable {I 𝒜}
theorem Ideal.IsHomogeneous.toIdeal_homogeneousHull_eq_self (h : I.IsHomogeneous 𝒜) :
(Ideal.homogeneousHull 𝒜 I).toIdeal = I := by
apply le_antisymm _ (Ideal.le_toIdeal_homogeneousHull _ _)
apply Ideal.span_le.2
rintro _ ⟨i, x, rfl⟩
exact h _ x.prop
@[simp]
theorem HomogeneousIdeal.homogeneousHull_toIdeal_eq_self (I : HomogeneousIdeal 𝒜) :
I.toIdeal.homogeneousHull 𝒜 = I :=
HomogeneousIdeal.toIdeal_injective <| I.isHomogeneous.toIdeal_homogeneousHull_eq_self
variable (I 𝒜)
theorem Ideal.toIdeal_homogeneousHull_eq_iSup :
(I.homogeneousHull 𝒜).toIdeal = ⨆ i, Ideal.span (GradedRing.proj 𝒜 i '' I) := by
rw [← Ideal.span_iUnion]
apply congr_arg Ideal.span _
ext1
simp only [Set.mem_iUnion, Set.mem_image, mem_setOf_eq, GradedRing.proj_apply, SetLike.exists,
exists_prop, SetLike.mem_coe]
theorem Ideal.homogeneousHull_eq_iSup :
I.homogeneousHull 𝒜 =
⨆ i, ⟨Ideal.span (GradedRing.proj 𝒜 i '' I), Ideal.homogeneous_span 𝒜 _ (by
rintro _ ⟨x, -, rfl⟩
apply SetLike.isHomogeneousElem_coe)⟩ := by
ext1
rw [Ideal.toIdeal_homogeneousHull_eq_iSup, toIdeal_iSup]
end HomogeneousHull
section GaloisConnection
open HomogeneousIdeal
variable [Semiring A] [DecidableEq ι] [AddMonoid ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜]
theorem Ideal.homogeneousHull.gc : GaloisConnection (Ideal.homogeneousHull 𝒜) toIdeal := fun _ J =>
⟨le_trans (Ideal.le_toIdeal_homogeneousHull _ _),
fun H => J.homogeneousHull_toIdeal_eq_self ▸ Ideal.homogeneousHull_mono 𝒜 H⟩
/-- `Ideal.homogeneousHull 𝒜` and `toIdeal : HomogeneousIdeal 𝒜 → Ideal A` form a Galois
insertion. -/
def Ideal.homogeneousHull.gi : GaloisInsertion (Ideal.homogeneousHull 𝒜) toIdeal where
choice I H := ⟨I, le_antisymm H (I.le_toIdeal_homogeneousHull 𝒜) ▸ isHomogeneous _⟩
gc := Ideal.homogeneousHull.gc 𝒜
le_l_u _ := Ideal.le_toIdeal_homogeneousHull _ _
choice_eq I H := le_antisymm (I.le_toIdeal_homogeneousHull 𝒜) H
theorem Ideal.homogeneousHull_eq_sInf (I : Ideal A) :
Ideal.homogeneousHull 𝒜 I = sInf { J : HomogeneousIdeal 𝒜 | I ≤ J.toIdeal } :=
Eq.symm <| IsGLB.sInf_eq <| (Ideal.homogeneousHull.gc 𝒜).isLeast_l.isGLB
end GaloisConnection
section IrrelevantIdeal
variable [Semiring A]
variable [DecidableEq ι]
variable [AddCommMonoid ι] [PartialOrder ι] [CanonicallyOrderedAdd ι]
variable [SetLike σ A] [AddSubmonoidClass σ A] (𝒜 : ι → σ) [GradedRing 𝒜]
open GradedRing SetLike.GradedMonoid DirectSum
/-- For a graded ring `⨁ᵢ 𝒜ᵢ` graded by a `CanonicallyOrderedAddCommMonoid ι`, the irrelevant ideal
refers to `⨁_{i>0} 𝒜ᵢ`, or equivalently `{a | a₀ = 0}`. This definition is used in `Proj`
construction where `ι` is always `ℕ` so the irrelevant ideal is simply elements with `0` as
0-th coordinate.
-/
def HomogeneousIdeal.irrelevant : HomogeneousIdeal 𝒜 :=
⟨RingHom.ker (GradedRing.projZeroRingHom 𝒜), fun i r (hr : (decompose 𝒜 r 0 : A) = 0) => by
change (decompose 𝒜 (decompose 𝒜 r _ : A) 0 : A) = 0
by_cases h : i = 0
· rw [h, hr, decompose_zero, zero_apply, ZeroMemClass.coe_zero]
· rw [decompose_of_mem_ne 𝒜 (SetLike.coe_mem _) h]⟩
@[simp]
theorem HomogeneousIdeal.mem_irrelevant_iff (a : A) :
a ∈ HomogeneousIdeal.irrelevant 𝒜 ↔ proj 𝒜 0 a = 0 :=
Iff.rfl
@[simp]
theorem HomogeneousIdeal.toIdeal_irrelevant :
(HomogeneousIdeal.irrelevant 𝒜).toIdeal = RingHom.ker (GradedRing.projZeroRingHom 𝒜) :=
rfl
end IrrelevantIdeal |
.lake/packages/mathlib/Mathlib/RingTheory/GradedAlgebra/Homogeneous/Submodule.lean | import Mathlib.RingTheory.GradedAlgebra.Basic
import Mathlib.Algebra.GradedMulAction
/-!
# Homogeneous submodules of a graded module
This file defines homogeneous submodule of a graded module `⨁ᵢ ℳᵢ` over graded ring `⨁ᵢ 𝒜ᵢ` and
operations on them.
## Main definitions
For any `p : Submodule A M`:
* `Submodule.IsHomogeneous ℳ p`: The property that a submodule is closed under `GradedModule.proj`.
* `HomogeneousSubmodule 𝒜 ℳ`: The structure extending submodules which satisfy
`Submodule.IsHomogeneous`.
## Implementation notes
The **notion** of homogeneous submodule does not rely on a graded ring, only a decomposition of the
the module. However, most interesting properties of homogeneous submodules do rely on the base ring
being a graded ring. For technical reasons, we make `HomogeneousSubmodule` depend on a graded ring.
For example, if the definition of a homogeneous submodule does not depend on a graded ring, the
instance that `HomogeneousSubmodule` is a complete lattice cannot be synthesized due to
synthesization order.
## Tags
graded algebra, homogeneous
-/
open SetLike DirectSum Pointwise Set
variable {ιA ιM σA σM A M : Type*}
variable [Semiring A] [AddCommMonoid M] [Module A M]
section HomogeneousDef
/--
An `A`-submodule `p ⊆ M` is homogeneous if for every `m ∈ p`, all homogeneous components of `m` are
in `p`.
-/
def Submodule.IsHomogeneous (p : Submodule A M) (ℳ : ιM → σM)
[DecidableEq ιM] [SetLike σM M] [AddSubmonoidClass σM M] [Decomposition ℳ] : Prop :=
SetLike.IsHomogeneous ℳ p
theorem Submodule.IsHomogeneous.mem_iff {p : Submodule A M}
(ℳ : ιM → σM)
[DecidableEq ιM] [SetLike σM M] [AddSubmonoidClass σM M] [Decomposition ℳ]
(hp : p.IsHomogeneous ℳ) {x} :
x ∈ p ↔ ∀ i, (decompose ℳ x i : M) ∈ p :=
AddSubmonoidClass.IsHomogeneous.mem_iff ℳ _ hp
/-- For any `Semiring A`, we collect the homogeneous submodule of `A`-modules into a type. -/
structure HomogeneousSubmodule (𝒜 : ιA → σA) (ℳ : ιM → σM)
[DecidableEq ιA] [AddMonoid ιA] [SetLike σA A] [AddSubmonoidClass σA A] [GradedRing 𝒜]
[DecidableEq ιM] [SetLike σM M] [AddSubmonoidClass σM M] [Decomposition ℳ]
[VAdd ιA ιM] [GradedSMul 𝒜 ℳ]
extends Submodule A M where
is_homogeneous' : toSubmodule.IsHomogeneous ℳ
variable (𝒜 : ιA → σA) (ℳ : ιM → σM)
variable [DecidableEq ιA] [AddMonoid ιA] [SetLike σA A] [AddSubmonoidClass σA A] [GradedRing 𝒜]
variable [DecidableEq ιM] [SetLike σM M] [AddSubmonoidClass σM M] [Decomposition ℳ]
variable [VAdd ιA ιM] [GradedSMul 𝒜 ℳ]
instance : SetLike (HomogeneousSubmodule 𝒜 ℳ) M where
coe X := X.toSubmodule
coe_injective' := by
rintro ⟨p, hp⟩ ⟨q, hq⟩ (h : (p : Set M) = q)
simpa using h
instance : AddSubmonoidClass (HomogeneousSubmodule 𝒜 ℳ) M where
zero_mem p := p.toSubmodule.zero_mem
add_mem hx hy := Submodule.add_mem _ hx hy
instance : SMulMemClass (HomogeneousSubmodule 𝒜 ℳ) A M where
smul_mem := by
intro x r m hm
exact Submodule.smul_mem x.toSubmodule r hm
variable {𝒜 ℳ} in
theorem HomogeneousSubmodule.isHomogeneous (p : HomogeneousSubmodule 𝒜 ℳ) :
p.toSubmodule.IsHomogeneous ℳ :=
p.is_homogeneous'
theorem HomogeneousSubmodule.toSubmodule_injective :
Function.Injective
(HomogeneousSubmodule.toSubmodule : HomogeneousSubmodule 𝒜 ℳ → Submodule A M) :=
fun ⟨x, hx⟩ ⟨y, hy⟩ ↦ fun (h : x = y) ↦ by simp [h]
instance HomogeneousSubmodule.setLike : SetLike (HomogeneousSubmodule 𝒜 ℳ) M where
coe p := p.toSubmodule
coe_injective' _ _ h := HomogeneousSubmodule.toSubmodule_injective 𝒜 ℳ <| SetLike.coe_injective h
@[ext]
theorem HomogeneousSubmodule.ext
{I J : HomogeneousSubmodule 𝒜 ℳ} (h : I.toSubmodule = J.toSubmodule) : I = J :=
HomogeneousSubmodule.toSubmodule_injective _ _ h
/--
The set-theoretic extensionality of `HomogeneousSubmodule`.
-/
theorem HomogeneousSubmodule.ext' {I J : HomogeneousSubmodule 𝒜 ℳ}
(h : ∀ i, ∀ x ∈ ℳ i, x ∈ I ↔ x ∈ J) :
I = J := by
ext
rw [I.isHomogeneous.mem_iff, J.isHomogeneous.mem_iff]
apply forall_congr'
exact fun i ↦ h i _ (decompose ℳ _ i).2
@[simp]
theorem HomogeneousSubmodule.mem_toSubmodule_iff {I : HomogeneousSubmodule 𝒜 ℳ} {x : M} :
x ∈ I.toSubmodule (A := A) ↔ x ∈ I :=
Iff.rfl
end HomogeneousDef |
.lake/packages/mathlib/Mathlib/RingTheory/UniqueFactorizationDomain/Finite.lean | import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors
/-!
# Finiteness of divisors
## Main results
* `UniqueFactorizationMonoid.fintypeSubtypeDvd`: elements of a UFM with finitely many units have
finitely many divisors.
-/
assert_not_exists Field
variable {α : Type*}
local infixl:50 " ~ᵤ " => Associated
namespace UniqueFactorizationMonoid
/-- If `y` is a nonzero element of a unique factorization monoid with finitely
many units (e.g. `ℤ`, `Ideal (ring_of_integers K)`), it has finitely many divisors. -/
noncomputable def fintypeSubtypeDvd {M : Type*} [CancelCommMonoidWithZero M]
[UniqueFactorizationMonoid M] [Fintype Mˣ] (y : M) (hy : y ≠ 0) : Fintype { x // x ∣ y } := by
haveI : Nontrivial M := ⟨⟨y, 0, hy⟩⟩
haveI : NormalizationMonoid M := UniqueFactorizationMonoid.normalizationMonoid
haveI := Classical.decEq M
haveI := Classical.decEq (Associates M)
-- We'll show `fun (u : Mˣ) (f ⊆ factors y) ↦ u * Π f` is injective
-- and has image exactly the divisors of `y`.
refine
Fintype.ofFinset
(((normalizedFactors y).powerset.toFinset ×ˢ (Finset.univ : Finset Mˣ)).image fun s =>
(s.snd : M) * s.fst.prod)
fun x => ?_
simp only [Finset.mem_image, Finset.mem_product, Finset.mem_univ, and_true,
Multiset.mem_toFinset, Multiset.mem_powerset]
constructor
· rintro ⟨s, hs, rfl⟩
change (s.snd : M) * s.fst.prod ∣ y
rw [(unit_associated_one.mul_right s.fst.prod).dvd_iff_dvd_left, one_mul,
← (prod_normalizedFactors hy).dvd_iff_dvd_right]
exact Multiset.prod_dvd_prod_of_le hs
· rintro (h : x ∣ y)
have hx : x ≠ 0 := by
refine mt (fun hx => ?_) hy
rwa [hx, zero_dvd_iff] at h
obtain ⟨u, hu⟩ := prod_normalizedFactors hx
refine ⟨⟨normalizedFactors x, u⟩, ?_, (mul_comm _ _).trans hu⟩
exact (dvd_iff_normalizedFactors_le_normalizedFactors hx hy).mp h
end UniqueFactorizationMonoid |
.lake/packages/mathlib/Mathlib/RingTheory/UniqueFactorizationDomain/GCDMonoid.lean | import Mathlib.RingTheory.UniqueFactorizationDomain.FactorSet
import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors
/-!
# Building GCD out of unique factorization
## Main results
* `UniqueFactorizationMonoid.toGCDMonoid`: choose a GCD monoid structure given unique factorization.
-/
variable {α : Type*}
local infixl:50 " ~ᵤ " => Associated
section
open Associates UniqueFactorizationMonoid
/-- `toGCDMonoid` constructs a GCD monoid out of a unique factorization domain. -/
noncomputable def UniqueFactorizationMonoid.toGCDMonoid (α : Type*) [CancelCommMonoidWithZero α]
[UniqueFactorizationMonoid α] : GCDMonoid α where
gcd a b := Quot.out (Associates.mk a ⊓ Associates.mk b : Associates α)
lcm a b := Quot.out (Associates.mk a ⊔ Associates.mk b : Associates α)
gcd_dvd_left a b := by
rw [← mk_dvd_mk, Associates.quot_out, congr_fun₂ dvd_eq_le]
exact inf_le_left
gcd_dvd_right a b := by
rw [← mk_dvd_mk, Associates.quot_out, congr_fun₂ dvd_eq_le]
exact inf_le_right
dvd_gcd {a b c} hac hab := by
rw [← mk_dvd_mk, Associates.quot_out, congr_fun₂ dvd_eq_le, le_inf_iff,
mk_le_mk_iff_dvd, mk_le_mk_iff_dvd]
exact ⟨hac, hab⟩
lcm_zero_left a := by simp
lcm_zero_right a := by simp
gcd_mul_lcm a b := by
rw [← mk_eq_mk_iff_associated, ← Associates.mk_mul_mk, ← associated_iff_eq, Associates.quot_out,
Associates.quot_out, mul_comm, sup_mul_inf, Associates.mk_mul_mk]
/-- `toNormalizedGCDMonoid` constructs a GCD monoid out of a normalization on a
unique factorization domain. -/
noncomputable def UniqueFactorizationMonoid.toNormalizedGCDMonoid (α : Type*)
[CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] [NormalizationMonoid α] :
NormalizedGCDMonoid α :=
{ ‹NormalizationMonoid α› with
gcd := fun a b => (Associates.mk a ⊓ Associates.mk b).out
lcm := fun a b => (Associates.mk a ⊔ Associates.mk b).out
gcd_dvd_left := fun a b => (out_dvd_iff a (Associates.mk a ⊓ Associates.mk b)).2 <| inf_le_left
gcd_dvd_right := fun a b =>
(out_dvd_iff b (Associates.mk a ⊓ Associates.mk b)).2 <| inf_le_right
dvd_gcd := fun {a} {b} {c} hac hab =>
show a ∣ (Associates.mk c ⊓ Associates.mk b).out by
rw [dvd_out_iff, le_inf_iff, mk_le_mk_iff_dvd, mk_le_mk_iff_dvd]
exact ⟨hac, hab⟩
lcm_zero_left := fun a => show (⊤ ⊔ Associates.mk a).out = 0 by simp
lcm_zero_right := fun a => show (Associates.mk a ⊔ ⊤).out = 0 by simp
gcd_mul_lcm := fun a b => by
rw [← out_mul, mul_comm, sup_mul_inf, mk_mul_mk, out_mk]
exact normalize_associated (a * b)
normalize_gcd := fun a b => by apply normalize_out _
normalize_lcm := fun a b => by apply normalize_out _ }
instance (α) [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] :
Nonempty (NormalizedGCDMonoid α) := by
letI := UniqueFactorizationMonoid.normalizationMonoid (α := α)
classical exact ⟨UniqueFactorizationMonoid.toNormalizedGCDMonoid α⟩
end |
.lake/packages/mathlib/Mathlib/RingTheory/UniqueFactorizationDomain/Multiplicative.lean | import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors
/-!
# Multiplicative maps on unique factorization domains
## Main results
* `UniqueFactorizationMonoid.induction_on_coprime`: if `P` holds for `0`, units and powers of
primes, and `P x ∧ P y` for coprime `x, y` implies `P (x * y)`, then `P` holds on all `a : α`.
* `UniqueFactorizationMonoid.multiplicative_of_coprime`: if `f` maps `p ^ i` to `(f p) ^ i` for
primes `p`, and `f` is multiplicative on coprime elements, then `f` is multiplicative everywhere.
-/
assert_not_exists Field
variable {α : Type*}
namespace UniqueFactorizationMonoid
variable {R : Type*} [CancelCommMonoidWithZero R] [UniqueFactorizationMonoid R]
section Multiplicative
variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α]
variable {β : Type*} [CancelCommMonoidWithZero β]
theorem prime_pow_coprime_prod_of_coprime_insert [DecidableEq α] {s : Finset α} (i : α → ℕ) (p : α)
(hps : p ∉ s) (is_prime : ∀ q ∈ insert p s, Prime q)
(is_coprime : ∀ᵉ (q ∈ insert p s) (q' ∈ insert p s), q ∣ q' → q = q') :
IsRelPrime (p ^ i p) (∏ p' ∈ s, p' ^ i p') := by
have hp := is_prime _ (Finset.mem_insert_self _ _)
refine (isRelPrime_iff_no_prime_factors <| pow_ne_zero _ hp.ne_zero).mpr ?_
intro d hdp hdprod hd
apply hps
replace hdp := hd.dvd_of_dvd_pow hdp
obtain ⟨q, q_mem', hdq⟩ := hd.exists_mem_multiset_dvd hdprod
obtain ⟨q, q_mem, rfl⟩ := Multiset.mem_map.mp q_mem'
replace hdq := hd.dvd_of_dvd_pow hdq
have : p ∣ q := dvd_trans (hd.irreducible.dvd_symm hp.irreducible hdp) hdq
convert q_mem using 0
rw [Finset.mem_val,
is_coprime _ (Finset.mem_insert_self p s) _ (Finset.mem_insert_of_mem q_mem) this]
/-- If `P` holds for units and powers of primes,
and `P x ∧ P y` for coprime `x, y` implies `P (x * y)`,
then `P` holds on a product of powers of distinct primes. -/
@[elab_as_elim]
theorem induction_on_prime_power {P : α → Prop} (s : Finset α) (i : α → ℕ)
(is_prime : ∀ p ∈ s, Prime p) (is_coprime : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q)
(h1 : ∀ {x}, IsUnit x → P x) (hpr : ∀ {p} (i : ℕ), Prime p → P (p ^ i))
(hcp : ∀ {x y}, IsRelPrime x y → P x → P y → P (x * y)) :
P (∏ p ∈ s, p ^ i p) := by
letI := Classical.decEq α
induction s using Finset.induction_on with
| empty => simpa using h1 isUnit_one
| insert p f' hpf' ih =>
rw [Finset.prod_insert hpf']
exact
hcp (prime_pow_coprime_prod_of_coprime_insert i p hpf' is_prime is_coprime)
(hpr (i p) (is_prime _ (Finset.mem_insert_self _ _)))
(ih (fun q hq => is_prime _ (Finset.mem_insert_of_mem hq)) fun q hq q' hq' =>
is_coprime _ (Finset.mem_insert_of_mem hq) _ (Finset.mem_insert_of_mem hq'))
/-- If `P` holds for `0`, units and powers of primes,
and `P x ∧ P y` for coprime `x, y` implies `P (x * y)`,
then `P` holds on all `a : α`. -/
@[elab_as_elim]
theorem induction_on_coprime {P : α → Prop} (a : α) (h0 : P 0) (h1 : ∀ {x}, IsUnit x → P x)
(hpr : ∀ {p} (i : ℕ), Prime p → P (p ^ i))
(hcp : ∀ {x y}, IsRelPrime x y → P x → P y → P (x * y)) : P a := by
letI := Classical.decEq α
have P_of_associated : ∀ {x y}, Associated x y → P x → P y := by
rintro x y ⟨u, rfl⟩ hx
exact hcp (fun p _ hpx => isUnit_of_dvd_unit hpx u.isUnit) hx (h1 u.isUnit)
by_cases ha0 : a = 0
· rwa [ha0]
haveI : Nontrivial α := ⟨⟨_, _, ha0⟩⟩
letI : NormalizationMonoid α := UniqueFactorizationMonoid.normalizationMonoid
refine P_of_associated (prod_normalizedFactors ha0) ?_
rw [← (normalizedFactors a).map_id, Finset.prod_multiset_map_count]
refine induction_on_prime_power _ _ ?_ ?_ @h1 @hpr @hcp <;> simp only [Multiset.mem_toFinset]
· apply prime_of_normalized_factor
· apply normalizedFactors_eq_of_dvd
/-- If `f` maps `p ^ i` to `(f p) ^ i` for primes `p`, and `f`
is multiplicative on coprime elements, then `f` is multiplicative on all products of primes. -/
theorem multiplicative_prime_power {f : α → β} (s : Finset α) (i j : α → ℕ)
(is_prime : ∀ p ∈ s, Prime p) (is_coprime : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q)
(h1 : ∀ {x y}, IsUnit y → f (x * y) = f x * f y)
(hpr : ∀ {p} (i : ℕ), Prime p → f (p ^ i) = f p ^ i)
(hcp : ∀ {x y}, IsRelPrime x y → f (x * y) = f x * f y) :
f (∏ p ∈ s, p ^ (i p + j p)) = f (∏ p ∈ s, p ^ i p) * f (∏ p ∈ s, p ^ j p) := by
letI := Classical.decEq α
induction s using Finset.induction_on with
| empty => simpa using h1 isUnit_one
| insert p s hps ih =>
have hpr_p := is_prime _ (Finset.mem_insert_self _ _)
have hpr_s : ∀ p ∈ s, Prime p := fun p hp => is_prime _ (Finset.mem_insert_of_mem hp)
have hcp_p := fun i => prime_pow_coprime_prod_of_coprime_insert i p hps is_prime is_coprime
have hcp_s : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q := fun p hp q hq =>
is_coprime p (Finset.mem_insert_of_mem hp) q (Finset.mem_insert_of_mem hq)
rw [Finset.prod_insert hps, Finset.prod_insert hps, Finset.prod_insert hps, hcp (hcp_p _),
hpr _ hpr_p, hcp (hcp_p _), hpr _ hpr_p, hcp (hcp_p (fun p => i p + j p)), hpr _ hpr_p,
ih hpr_s hcp_s, pow_add, mul_assoc, mul_left_comm (f p ^ j p), mul_assoc]
/-- If `f` maps `p ^ i` to `(f p) ^ i` for primes `p`, and `f`
is multiplicative on coprime elements, then `f` is multiplicative everywhere. -/
theorem multiplicative_of_coprime (f : α → β) (a b : α) (h0 : f 0 = 0)
(h1 : ∀ {x y}, IsUnit y → f (x * y) = f x * f y)
(hpr : ∀ {p} (i : ℕ), Prime p → f (p ^ i) = f p ^ i)
(hcp : ∀ {x y}, IsRelPrime x y → f (x * y) = f x * f y) :
f (a * b) = f a * f b := by
letI := Classical.decEq α
by_cases ha0 : a = 0
· rw [ha0, zero_mul, h0, zero_mul]
by_cases hb0 : b = 0
· rw [hb0, mul_zero, h0, mul_zero]
by_cases hf1 : f 1 = 0
· calc
f (a * b) = f (a * b * 1) := by rw [mul_one]
_ = 0 := by simp only [h1 isUnit_one, hf1, mul_zero]
_ = f a * f (b * 1) := by simp only [h1 isUnit_one, hf1, mul_zero]
_ = f a * f b := by rw [mul_one]
haveI : Nontrivial α := ⟨⟨_, _, ha0⟩⟩
letI : NormalizationMonoid α := UniqueFactorizationMonoid.normalizationMonoid
suffices
f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset,
p ^ ((normalizedFactors a).count p + (normalizedFactors b).count p)) =
f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset,
p ^ (normalizedFactors a).count p) *
f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset,
p ^ (normalizedFactors b).count p) by
obtain ⟨ua, a_eq⟩ := prod_normalizedFactors ha0
obtain ⟨ub, b_eq⟩ := prod_normalizedFactors hb0
rw [← a_eq, ← b_eq, mul_right_comm (Multiset.prod (normalizedFactors a)) ua
(Multiset.prod (normalizedFactors b) * ub), h1 ua.isUnit, h1 ub.isUnit, h1 ua.isUnit, ←
mul_assoc, h1 ub.isUnit, mul_right_comm _ (f ua), ← mul_assoc]
congr
rw [← (normalizedFactors a).map_id, ← (normalizedFactors b).map_id,
Finset.prod_multiset_map_count, Finset.prod_multiset_map_count,
Finset.prod_subset (Finset.subset_union_left (s₂ := (normalizedFactors b).toFinset)),
Finset.prod_subset (Finset.subset_union_right (s₂ := (normalizedFactors b).toFinset)), ←
Finset.prod_mul_distrib]
· simp_rw [id, ← pow_add, this]
all_goals simp only [Multiset.mem_toFinset]
· intro p _ hpb
simp [hpb]
· intro p _ hpa
simp [hpa]
refine multiplicative_prime_power _ _ _ ?_ ?_ @h1 @hpr @hcp
all_goals simp only [Multiset.mem_toFinset, Finset.mem_union]
· rintro p (hpa | hpb) <;> apply prime_of_normalized_factor <;> assumption
· rintro p (hp | hp) q (hq | hq) hdvd <;>
rw [← normalize_normalized_factor _ hp, ← normalize_normalized_factor _ hq] <;>
exact
normalize_eq_normalize hdvd
((prime_of_normalized_factor _ hp).irreducible.dvd_symm
(prime_of_normalized_factor _ hq).irreducible hdvd)
end Multiplicative
end UniqueFactorizationMonoid |
.lake/packages/mathlib/Mathlib/RingTheory/UniqueFactorizationDomain/Nat.lean | import Mathlib.Data.ENat.Basic
import Mathlib.Data.Nat.Factors
import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors
/-!
# Unique factorization of natural numbers
## Main definitions
* `Nat.instUniqueFactorizationMonoid`: the natural numbers have unique factorization
-/
assert_not_exists Field
namespace Nat
instance instWfDvdMonoid : WfDvdMonoid ℕ where
wf := by
refine RelHomClass.wellFounded
(⟨fun x : ℕ => if x = 0 then (⊤ : ℕ∞) else x, ?_⟩ : DvdNotUnit →r (· < ·)) wellFounded_lt
intro a b h
rcases a with - | a
· exfalso
revert h
simp [DvdNotUnit]
cases b
· simp
obtain ⟨h1, h2⟩ := dvd_and_not_dvd_iff.2 h
simp only [succ_ne_zero, cast_lt, if_false]
refine lt_of_le_of_ne (Nat.le_of_dvd (Nat.succ_pos _) h1) fun con => h2 ?_
rw [con]
instance instUniqueFactorizationMonoid : UniqueFactorizationMonoid ℕ where
irreducible_iff_prime := Nat.irreducible_iff_prime
open UniqueFactorizationMonoid
lemma factors_eq : ∀ n : ℕ, normalizedFactors n = n.primeFactorsList
| 0 => by simp
| n + 1 => by
rw [← Multiset.rel_eq, ← associated_eq_eq]
apply UniqueFactorizationMonoid.factors_unique irreducible_of_normalized_factor _
· rw [Multiset.prod_coe, Nat.prod_primeFactorsList n.succ_ne_zero]
exact prod_normalizedFactors n.succ_ne_zero
· intro x hx
rw [Nat.irreducible_iff_prime, ← Nat.prime_iff]
exact Nat.prime_of_mem_primeFactorsList hx
lemma factors_multiset_prod_of_irreducible {s : Multiset ℕ} (h : ∀ x : ℕ, x ∈ s → Irreducible x) :
normalizedFactors s.prod = s := by
rw [← Multiset.rel_eq, ← associated_eq_eq]
apply UniqueFactorizationMonoid.factors_unique irreducible_of_normalized_factor h
(prod_normalizedFactors _)
rw [Ne, Multiset.prod_eq_zero_iff]
exact fun con ↦ not_irreducible_zero (h 0 con)
end Nat |
.lake/packages/mathlib/Mathlib/RingTheory/UniqueFactorizationDomain/Multiplicity.lean | import Mathlib.RingTheory.Multiplicity
import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors
/-!
# Unique factorization and multiplicity
## Main results
* `UniqueFactorizationMonoid.emultiplicity_eq_count_normalizedFactors`: The multiplicity of an
irreducible factor of a nonzero element is exactly the number of times the normalized factor
occurs in the `normalizedFactors`.
-/
assert_not_exists Field
variable {α : Type*}
local infixl:50 " ~ᵤ " => Associated
theorem WfDvdMonoid.max_power_factor' [CommMonoidWithZero α] [WfDvdMonoid α] {a₀ x : α}
(h : a₀ ≠ 0) (hx : ¬IsUnit x) : ∃ (n : ℕ) (a : α), ¬x ∣ a ∧ a₀ = x ^ n * a := by
obtain ⟨a, ⟨n, rfl⟩, hm⟩ := wellFounded_dvdNotUnit.has_min
{a | ∃ n, x ^ n * a = a₀} ⟨a₀, 0, by rw [pow_zero, one_mul]⟩
refine ⟨n, a, ?_, rfl⟩; rintro ⟨d, rfl⟩
exact hm d ⟨n + 1, by rw [pow_succ, mul_assoc]⟩
⟨(right_ne_zero_of_mul <| right_ne_zero_of_mul h), x, hx, mul_comm _ _⟩
theorem WfDvdMonoid.max_power_factor [CommMonoidWithZero α] [WfDvdMonoid α] {a₀ x : α}
(h : a₀ ≠ 0) (hx : Irreducible x) : ∃ (n : ℕ) (a : α), ¬x ∣ a ∧ a₀ = x ^ n * a :=
max_power_factor' h hx.not_isUnit
theorem FiniteMultiplicity.of_not_isUnit [CancelCommMonoidWithZero α] [WfDvdMonoid α]
{a b : α} (ha : ¬IsUnit a) (hb : b ≠ 0) : FiniteMultiplicity a b := by
obtain ⟨n, c, ndvd, rfl⟩ := WfDvdMonoid.max_power_factor' hb ha
exact ⟨n, by rwa [pow_succ, mul_dvd_mul_iff_left (left_ne_zero_of_mul hb)]⟩
theorem FiniteMultiplicity.of_prime_left [CancelCommMonoidWithZero α] [WfDvdMonoid α]
{a b : α} (ha : Prime a) (hb : b ≠ 0) : FiniteMultiplicity a b :=
.of_not_isUnit ha.not_unit hb
namespace UniqueFactorizationMonoid
variable {R : Type*} [CancelCommMonoidWithZero R] [UniqueFactorizationMonoid R]
section multiplicity
variable [NormalizationMonoid R]
open Multiset
section
theorem le_emultiplicity_iff_replicate_le_normalizedFactors {a b : R} {n : ℕ} (ha : Irreducible a)
(hb : b ≠ 0) :
↑n ≤ emultiplicity a b ↔ replicate n (normalize a) ≤ normalizedFactors b := by
rw [← pow_dvd_iff_le_emultiplicity]
revert b
induction n with
| zero => simp
| succ n ih => ?_
intro b hb
constructor
· rintro ⟨c, rfl⟩
rw [Ne, pow_succ', mul_assoc, mul_eq_zero, not_or] at hb
rw [pow_succ', mul_assoc, normalizedFactors_mul hb.1 hb.2, replicate_succ,
normalizedFactors_irreducible ha, singleton_add, cons_le_cons_iff, ← ih hb.2]
apply Dvd.intro _ rfl
· rw [Multiset.le_iff_exists_add]
rintro ⟨u, hu⟩
rw [← (prod_normalizedFactors hb).dvd_iff_dvd_right, hu, prod_add, prod_replicate]
exact (Associated.pow_pow <| associated_normalize a).dvd.trans (Dvd.intro u.prod rfl)
/-- The multiplicity of an irreducible factor of a nonzero element is exactly the number of times
the normalized factor occurs in the `normalizedFactors`.
See also `count_normalizedFactors_eq` which expands the definition of `multiplicity`
to produce a specification for `count (normalizedFactors _) _`..
-/
theorem emultiplicity_eq_count_normalizedFactors [DecidableEq R] {a b : R} (ha : Irreducible a)
(hb : b ≠ 0) : emultiplicity a b = (normalizedFactors b).count (normalize a) := by
apply le_antisymm
· apply Order.le_of_lt_add_one
rw [← Nat.cast_one, ← Nat.cast_add, lt_iff_not_ge,
le_emultiplicity_iff_replicate_le_normalizedFactors ha hb, ← le_count_iff_replicate_le]
simp
rw [le_emultiplicity_iff_replicate_le_normalizedFactors ha hb, ← le_count_iff_replicate_le]
end
/-- The number of times an irreducible factor `p` appears in `normalizedFactors x` is defined by
the number of times it divides `x`.
See also `multiplicity_eq_count_normalizedFactors` if `n` is given by `multiplicity p x`.
-/
theorem count_normalizedFactors_eq [DecidableEq R] {p x : R} (hp : Irreducible p)
(hnorm : normalize p = p) {n : ℕ} (hle : p ^ n ∣ x) (hlt : ¬p ^ (n + 1) ∣ x) :
(normalizedFactors x).count p = n := by classical
by_cases hx0 : x = 0
· simp [hx0] at hlt
apply Nat.cast_injective (R := ℕ∞)
convert (emultiplicity_eq_count_normalizedFactors hp hx0).symm
· exact hnorm.symm
exact (emultiplicity_eq_coe.mpr ⟨hle, hlt⟩).symm
/-- The number of times an irreducible factor `p` appears in `normalizedFactors x` is defined by
the number of times it divides `x`. This is a slightly more general version of
`UniqueFactorizationMonoid.count_normalizedFactors_eq` that allows `p = 0`.
See also `multiplicity_eq_count_normalizedFactors` if `n` is given by `multiplicity p x`.
-/
theorem count_normalizedFactors_eq' [DecidableEq R] {p x : R} (hp : p = 0 ∨ Irreducible p)
(hnorm : normalize p = p) {n : ℕ} (hle : p ^ n ∣ x) (hlt : ¬p ^ (n + 1) ∣ x) :
(normalizedFactors x).count p = n := by
rcases hp with (rfl | hp)
· cases n
· exact count_eq_zero.2 (zero_notMem_normalizedFactors _)
· rw [zero_pow (Nat.succ_ne_zero _)] at hle hlt
exact absurd hle hlt
· exact count_normalizedFactors_eq hp hnorm hle hlt
end multiplicity
end UniqueFactorizationMonoid |
.lake/packages/mathlib/Mathlib/RingTheory/UniqueFactorizationDomain/Basic.lean | import Mathlib.Algebra.BigOperators.Associated
import Mathlib.Data.ENat.Basic
import Mathlib.RingTheory.UniqueFactorizationDomain.Defs
/-!
# Basic results un unique factorization monoids
## Main results
* `prime_factors_unique`: the prime factors of an element in a cancellative
commutative monoid with zero (e.g. an integral domain) are unique up to associates
* `UniqueFactorizationMonoid.factors_unique`: the irreducible factors of an element
in a unique factorization monoid (e.g. a UFD) are unique up to associates
* `UniqueFactorizationMonoid.iff_exists_prime_factors`: unique factorization exists iff each nonzero
elements factors into a product of primes
* `UniqueFactorizationMonoid.dvd_of_dvd_mul_left_of_no_prime_factors`: Euclid's lemma:
if `a ∣ b * c` and `a` and `c` have no common prime factors, `a ∣ b`.
* `UniqueFactorizationMonoid.dvd_of_dvd_mul_right_of_no_prime_factors`: Euclid's lemma:
if `a ∣ b * c` and `a` and `b` have no common prime factors, `a ∣ c`.
* `UniqueFactorizationMonoid.exists_reduced_factors`: in a UFM, we can divide out a common factor
to get relatively prime elements.
-/
assert_not_exists Field
variable {α : Type*}
local infixl:50 " ~ᵤ " => Associated
namespace WfDvdMonoid
variable [CommMonoidWithZero α]
open Associates Nat
theorem of_wfDvdMonoid_associates (_ : WfDvdMonoid (Associates α)) : WfDvdMonoid α :=
⟨(mk_surjective.wellFounded_iff mk_dvdNotUnit_mk_iff.symm).2 wellFounded_dvdNotUnit⟩
variable [WfDvdMonoid α]
instance wfDvdMonoid_associates : WfDvdMonoid (Associates α) :=
⟨(mk_surjective.wellFounded_iff mk_dvdNotUnit_mk_iff.symm).1 wellFounded_dvdNotUnit⟩
theorem wellFoundedLT_associates : WellFoundedLT (Associates α) :=
⟨Subrelation.wf dvdNotUnit_of_lt wellFounded_dvdNotUnit⟩
end WfDvdMonoid
theorem WfDvdMonoid.of_wellFoundedLT_associates [CancelCommMonoidWithZero α]
(h : WellFoundedLT (Associates α)) : WfDvdMonoid α :=
WfDvdMonoid.of_wfDvdMonoid_associates
⟨by
convert h.wf
ext
exact Associates.dvdNotUnit_iff_lt⟩
theorem WfDvdMonoid.iff_wellFounded_associates [CancelCommMonoidWithZero α] :
WfDvdMonoid α ↔ WellFoundedLT (Associates α) :=
⟨by apply WfDvdMonoid.wellFoundedLT_associates, WfDvdMonoid.of_wellFoundedLT_associates⟩
instance Associates.ufm [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] :
UniqueFactorizationMonoid (Associates α) :=
{ (WfDvdMonoid.wfDvdMonoid_associates : WfDvdMonoid (Associates α)) with
irreducible_iff_prime := by
rw [← Associates.irreducible_iff_prime_iff]
apply UniqueFactorizationMonoid.irreducible_iff_prime }
theorem prime_factors_unique [CancelCommMonoidWithZero α] :
∀ {f g : Multiset α},
(∀ x ∈ f, Prime x) → (∀ x ∈ g, Prime x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g := by
classical
intro f
induction f using Multiset.induction_on with
| empty =>
intro g _ hg h
exact Multiset.rel_zero_left.2 <|
Multiset.eq_zero_of_forall_notMem fun x hx =>
have : IsUnit g.prod := by simpa [associated_one_iff_isUnit] using h.symm
(hg x hx).not_unit <|
isUnit_iff_dvd_one.2 <| (Multiset.dvd_prod hx).trans (isUnit_iff_dvd_one.1 this)
| cons p f ih =>
intro g hf hg hfg
let ⟨b, hbg, hb⟩ :=
(exists_associated_mem_of_dvd_prod (hf p (by simp)) fun q hq => hg _ hq) <|
hfg.dvd_iff_dvd_right.1 (show p ∣ (p ::ₘ f).prod by simp)
haveI := Classical.decEq α
rw [← Multiset.cons_erase hbg]
exact
Multiset.Rel.cons hb
(ih (fun q hq => hf _ (by simp [hq]))
(fun {q} (hq : q ∈ g.erase b) => hg q (Multiset.mem_of_mem_erase hq))
(Associated.of_mul_left
(by rwa [← Multiset.prod_cons, ← Multiset.prod_cons, Multiset.cons_erase hbg]) hb
(hf p (by simp)).ne_zero))
namespace UniqueFactorizationMonoid
variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α]
theorem factors_unique {f g : Multiset α} (hf : ∀ x ∈ f, Irreducible x)
(hg : ∀ x ∈ g, Irreducible x) (h : f.prod ~ᵤ g.prod) : Multiset.Rel Associated f g :=
prime_factors_unique (fun x hx => UniqueFactorizationMonoid.irreducible_iff_prime.mp (hf x hx))
(fun x hx => UniqueFactorizationMonoid.irreducible_iff_prime.mp (hg x hx)) h
end UniqueFactorizationMonoid
/-- If an irreducible has a prime factorization,
then it is an associate of one of its prime factors. -/
theorem prime_factors_irreducible [CommMonoidWithZero α] {a : α} {f : Multiset α}
(ha : Irreducible a) (pfa : (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a) : ∃ p, a ~ᵤ p ∧ f = {p} := by
haveI := Classical.decEq α
refine @Multiset.induction_on _
(fun g => (g.prod ~ᵤ a) → (∀ b ∈ g, Prime b) → ∃ p, a ~ᵤ p ∧ g = {p}) f ?_ ?_ pfa.2 pfa.1
· intro h; exact (ha.not_isUnit (associated_one_iff_isUnit.1 (Associated.symm h))).elim
· rintro p s _ ⟨u, hu⟩ hs
use p
have hs0 : s = 0 := by
by_contra hs0
obtain ⟨q, hq⟩ := Multiset.exists_mem_of_ne_zero hs0
apply (hs q (by simp [hq])).2.1
refine (ha.isUnit_or_isUnit (?_ : _ = p * ↑u * (s.erase q).prod * _)).resolve_left ?_
· rw [mul_right_comm _ _ q, mul_assoc, ← Multiset.prod_cons, Multiset.cons_erase hq, ← hu,
mul_comm, mul_comm p _, mul_assoc]
simp
apply mt isUnit_of_mul_isUnit_left (mt isUnit_of_mul_isUnit_left _)
apply (hs p (Multiset.mem_cons_self _ _)).2.1
simp only [mul_one, Multiset.prod_cons, Multiset.prod_zero, hs0] at *
exact ⟨Associated.symm ⟨u, hu⟩, rfl⟩
theorem irreducible_iff_prime_of_existsUnique_irreducible_factors [CancelCommMonoidWithZero α]
(eif : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod ~ᵤ a)
(uif :
∀ f g : Multiset α,
(∀ x ∈ f, Irreducible x) →
(∀ x ∈ g, Irreducible x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g)
(p : α) : Irreducible p ↔ Prime p :=
letI := Classical.decEq α
⟨ fun hpi =>
⟨hpi.ne_zero, hpi.1, fun a b ⟨x, hx⟩ =>
if hab0 : a * b = 0 then
(eq_zero_or_eq_zero_of_mul_eq_zero hab0).elim (fun ha0 => by simp [ha0]) fun hb0 => by
simp [hb0]
else by
have hx0 : x ≠ 0 := fun hx0 => by simp_all
have ha0 : a ≠ 0 := left_ne_zero_of_mul hab0
have hb0 : b ≠ 0 := right_ne_zero_of_mul hab0
obtain ⟨fx, hfx⟩ := eif x hx0
obtain ⟨fa, hfa⟩ := eif a ha0
obtain ⟨fb, hfb⟩ := eif b hb0
have h : Multiset.Rel Associated (p ::ₘ fx) (fa + fb) := by
apply uif
· exact fun i hi => (Multiset.mem_cons.1 hi).elim (fun hip => hip.symm ▸ hpi) (hfx.1 _)
· exact fun i hi => (Multiset.mem_add.1 hi).elim (hfa.1 _) (hfb.1 _)
calc
Multiset.prod (p ::ₘ fx) ~ᵤ a * b := by
rw [hx, Multiset.prod_cons]; exact hfx.2.mul_left _
_ ~ᵤ fa.prod * fb.prod := hfa.2.symm.mul_mul hfb.2.symm
_ = _ := by rw [Multiset.prod_add]
exact
let ⟨q, hqf, hq⟩ := Multiset.exists_mem_of_rel_of_mem h (Multiset.mem_cons_self p _)
(Multiset.mem_add.1 hqf).elim
(fun hqa =>
Or.inl <| hq.dvd_iff_dvd_left.2 <| hfa.2.dvd_iff_dvd_right.1 (Multiset.dvd_prod hqa))
fun hqb =>
Or.inr <| hq.dvd_iff_dvd_left.2 <| hfb.2.dvd_iff_dvd_right.1 (Multiset.dvd_prod hqb)⟩,
Prime.irreducible⟩
namespace UniqueFactorizationMonoid
variable [CancelCommMonoidWithZero α]
variable [UniqueFactorizationMonoid α]
@[simp]
theorem factors_one : factors (1 : α) = 0 := by
nontriviality α using factors
rw [← Multiset.rel_zero_right]
refine factors_unique irreducible_of_factor (fun x hx => (Multiset.notMem_zero x hx).elim) ?_
rw [Multiset.prod_zero]
exact factors_prod one_ne_zero
theorem exists_mem_factors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) :
p ∣ a → ∃ q ∈ factors a, p ~ᵤ q := fun ⟨b, hb⟩ =>
have hb0 : b ≠ 0 := fun hb0 => by simp_all
have : Multiset.Rel Associated (p ::ₘ factors b) (factors a) :=
factors_unique
(fun _ hx => (Multiset.mem_cons.1 hx).elim (fun h => h.symm ▸ hp) (irreducible_of_factor _))
irreducible_of_factor
(Associated.symm <|
calc
Multiset.prod (factors a) ~ᵤ a := factors_prod ha0
_ = p * b := hb
_ ~ᵤ Multiset.prod (p ::ₘ factors b) := by
rw [Multiset.prod_cons]; exact (factors_prod hb0).symm.mul_left _
)
Multiset.exists_mem_of_rel_of_mem this (by simp)
theorem exists_mem_factors {x : α} (hx : x ≠ 0) (h : ¬IsUnit x) : ∃ p, p ∈ factors x := by
obtain ⟨p', hp', hp'x⟩ := WfDvdMonoid.exists_irreducible_factor h hx
obtain ⟨p, hp, _⟩ := exists_mem_factors_of_dvd hx hp' hp'x
exact ⟨p, hp⟩
open Classical in
theorem factors_mul {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) :
Multiset.Rel Associated (factors (x * y)) (factors x + factors y) := by
refine
factors_unique irreducible_of_factor
(fun a ha =>
(Multiset.mem_add.mp ha).by_cases (irreducible_of_factor _) (irreducible_of_factor _))
((factors_prod (mul_ne_zero hx hy)).trans ?_)
rw [Multiset.prod_add]
exact (Associated.mul_mul (factors_prod hx) (factors_prod hy)).symm
theorem factors_pow {x : α} (n : ℕ) :
Multiset.Rel Associated (factors (x ^ n)) (n • factors x) := by
match n with
| 0 => rw [zero_nsmul, pow_zero, factors_one, Multiset.rel_zero_right]
| n + 1 =>
by_cases h0 : x = 0
· simp [h0, zero_pow n.succ_ne_zero, nsmul_zero]
· rw [pow_succ', succ_nsmul']
refine Multiset.Rel.trans _ (factors_mul h0 (pow_ne_zero n h0)) ?_
refine Multiset.Rel.add ?_ <| factors_pow n
exact Multiset.rel_refl_of_refl_on fun y _ => Associated.refl _
@[simp]
theorem factors_pos (x : α) (hx : x ≠ 0) : 0 < factors x ↔ ¬IsUnit x := by
constructor
· intro h hx
obtain ⟨p, hp⟩ := Multiset.exists_mem_of_ne_zero h.ne'
exact (prime_of_factor _ hp).not_unit (isUnit_of_dvd_unit (dvd_of_mem_factors hp) hx)
· intro h
obtain ⟨p, hp⟩ := exists_mem_factors hx h
exact
bot_lt_iff_ne_bot.mpr
(mt Multiset.eq_zero_iff_forall_notMem.mp (not_forall.mpr ⟨p, not_not.mpr hp⟩))
open Multiset in
theorem factors_pow_count_prod [DecidableEq α] {x : α} (hx : x ≠ 0) :
(∏ p ∈ (factors x).toFinset, p ^ (factors x).count p) ~ᵤ x :=
calc
_ = prod (∑ a ∈ toFinset (factors x), count a (factors x) • {a}) := by
simp only [prod_sum, prod_nsmul, prod_singleton]
_ = prod (factors x) := by rw [toFinset_sum_count_nsmul_eq (factors x)]
_ ~ᵤ x := factors_prod hx
theorem factors_rel_of_associated {a b : α} (h : Associated a b) :
Multiset.Rel Associated (factors a) (factors b) := by
rcases iff_iff_and_or_not_and_not.mp h.eq_zero_iff with (⟨rfl, rfl⟩ | ⟨ha, hb⟩)
· simp
· refine factors_unique irreducible_of_factor irreducible_of_factor ?_
exact ((factors_prod ha).trans h).trans (factors_prod hb).symm
end UniqueFactorizationMonoid
namespace Associates
attribute [local instance] Associated.setoid
open Multiset UniqueFactorizationMonoid
variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α]
theorem unique' {p q : Multiset (Associates α)} :
(∀ a ∈ p, Irreducible a) → (∀ a ∈ q, Irreducible a) → p.prod = q.prod → p = q := by
apply Multiset.induction_on_multiset_quot p
apply Multiset.induction_on_multiset_quot q
intro s t hs ht eq
refine Multiset.map_mk_eq_map_mk_of_rel (UniqueFactorizationMonoid.factors_unique ?_ ?_ ?_)
· exact fun a ha => irreducible_mk.1 <| hs _ <| Multiset.mem_map_of_mem _ ha
· exact fun a ha => irreducible_mk.1 <| ht _ <| Multiset.mem_map_of_mem _ ha
have eq' : (Quot.mk Setoid.r : α → Associates α) = Associates.mk := funext quot_mk_eq_mk
rwa [eq', prod_mk, prod_mk, mk_eq_mk_iff_associated] at eq
theorem prod_le_prod_iff_le [Nontrivial α] {p q : Multiset (Associates α)}
(hp : ∀ a ∈ p, Irreducible a) (hq : ∀ a ∈ q, Irreducible a) : p.prod ≤ q.prod ↔ p ≤ q := by
refine ⟨?_, prod_le_prod⟩
rintro ⟨c, eqc⟩
refine Multiset.le_iff_exists_add.2 ⟨factors c, unique' hq (fun x hx ↦ ?_) ?_⟩
· obtain h | h := Multiset.mem_add.1 hx
· exact hp x h
· exact irreducible_of_factor _ h
· rw [eqc, Multiset.prod_add]
congr
refine associated_iff_eq.mp (factors_prod fun hc => ?_).symm
refine not_irreducible_zero (hq _ ?_)
rw [← prod_eq_zero_iff, eqc, hc, mul_zero]
end Associates
section ExistsPrimeFactors
variable [CancelCommMonoidWithZero α]
variable (pf : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a)
include pf
theorem WfDvdMonoid.of_exists_prime_factors : WfDvdMonoid α :=
⟨by
classical
refine RelHomClass.wellFounded
(RelHom.mk ?_ ?_ : (DvdNotUnit : α → α → Prop) →r ((· < ·) : ℕ∞ → ℕ∞ → Prop)) wellFounded_lt
· intro a
by_cases h : a = 0
· exact ⊤
exact ↑(Multiset.card (Classical.choose (pf a h)))
rintro a b ⟨ane0, ⟨c, hc, b_eq⟩⟩
rw [dif_neg ane0]
by_cases h : b = 0
· simp [h, lt_top_iff_ne_top]
· rw [dif_neg h, Nat.cast_lt]
have cne0 : c ≠ 0 := by
refine mt (fun con => ?_) h
rw [b_eq, con, mul_zero]
calc
Multiset.card (Classical.choose (pf a ane0)) <
_ + Multiset.card (Classical.choose (pf c cne0)) :=
lt_add_of_pos_right _
(Multiset.card_pos.mpr fun con => hc (associated_one_iff_isUnit.mp ?_))
_ = Multiset.card (Classical.choose (pf a ane0) + Classical.choose (pf c cne0)) :=
(Multiset.card_add _ _).symm
_ = Multiset.card (Classical.choose (pf b h)) :=
Multiset.card_eq_card_of_rel
(prime_factors_unique ?_ (Classical.choose_spec (pf _ h)).1 ?_)
· convert (Classical.choose_spec (pf c cne0)).2.symm
rw [con, Multiset.prod_zero]
· intro x hadd
rw [Multiset.mem_add] at hadd
rcases hadd with h | h <;> apply (Classical.choose_spec (pf _ _)).1 _ h <;> assumption
· rw [Multiset.prod_add]
trans a * c
· apply Associated.mul_mul <;> apply (Classical.choose_spec (pf _ _)).2 <;> assumption
· rw [← b_eq]
apply (Classical.choose_spec (pf _ _)).2.symm; assumption⟩
theorem irreducible_iff_prime_of_exists_prime_factors {p : α} : Irreducible p ↔ Prime p := by
by_cases hp0 : p = 0
· simp [hp0]
refine ⟨fun h => ?_, Prime.irreducible⟩
obtain ⟨f, hf⟩ := pf p hp0
obtain ⟨q, hq, rfl⟩ := prime_factors_irreducible h hf
rw [hq.prime_iff]
exact hf.1 q (Multiset.mem_singleton_self _)
theorem UniqueFactorizationMonoid.of_exists_prime_factors : UniqueFactorizationMonoid α :=
{ WfDvdMonoid.of_exists_prime_factors pf with
irreducible_iff_prime := irreducible_iff_prime_of_exists_prime_factors pf }
end ExistsPrimeFactors
theorem UniqueFactorizationMonoid.iff_exists_prime_factors [CancelCommMonoidWithZero α] :
UniqueFactorizationMonoid α ↔
∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a :=
⟨fun h => @UniqueFactorizationMonoid.exists_prime_factors _ _ h,
UniqueFactorizationMonoid.of_exists_prime_factors⟩
section
variable {β : Type*} [CancelCommMonoidWithZero α] [CancelCommMonoidWithZero β]
theorem MulEquiv.uniqueFactorizationMonoid (e : α ≃* β) (hα : UniqueFactorizationMonoid α) :
UniqueFactorizationMonoid β := by
rw [UniqueFactorizationMonoid.iff_exists_prime_factors] at hα ⊢
intro a ha
obtain ⟨w, hp, u, h⟩ :=
hα (e.symm a) fun h =>
ha <| by
convert← map_zero e
simp [← h]
exact
⟨w.map e, fun b hb =>
let ⟨c, hc, he⟩ := Multiset.mem_map.1 hb
he ▸ (prime_iff e).2 (hp c hc),
Units.map e.toMonoidHom u,
by
rw [Multiset.prod_hom, toMonoidHom_eq_coe, Units.coe_map, MonoidHom.coe_coe, ← map_mul e, h,
apply_symm_apply]⟩
theorem MulEquiv.uniqueFactorizationMonoid_iff (e : α ≃* β) :
UniqueFactorizationMonoid α ↔ UniqueFactorizationMonoid β :=
⟨e.uniqueFactorizationMonoid, e.symm.uniqueFactorizationMonoid⟩
end
namespace UniqueFactorizationMonoid
theorem of_existsUnique_irreducible_factors [CancelCommMonoidWithZero α]
(eif : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod ~ᵤ a)
(uif :
∀ f g : Multiset α,
(∀ x ∈ f, Irreducible x) →
(∀ x ∈ g, Irreducible x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g) :
UniqueFactorizationMonoid α :=
UniqueFactorizationMonoid.of_exists_prime_factors
(by
convert eif using 7
simp_rw [irreducible_iff_prime_of_existsUnique_irreducible_factors eif uif])
variable {R : Type*} [CancelCommMonoidWithZero R] [UniqueFactorizationMonoid R]
theorem isRelPrime_iff_no_prime_factors {a b : R} (ha : a ≠ 0) :
IsRelPrime a b ↔ ∀ ⦃d⦄, d ∣ a → d ∣ b → ¬Prime d :=
⟨fun h _ ha hb ↦ (·.not_unit <| h ha hb), fun h ↦ WfDvdMonoid.isRelPrime_of_no_irreducible_factors
(ha ·.1) fun _ irr ha hb ↦ h ha hb (UniqueFactorizationMonoid.irreducible_iff_prime.mp irr)⟩
/-- Euclid's lemma: if `a ∣ b * c` and `a` and `c` have no common prime factors, `a ∣ b`.
Compare `IsCoprime.dvd_of_dvd_mul_left`. -/
theorem dvd_of_dvd_mul_left_of_no_prime_factors {a b c : R} (ha : a ≠ 0)
(h : ∀ ⦃d⦄, d ∣ a → d ∣ c → ¬Prime d) : a ∣ b * c → a ∣ b :=
((isRelPrime_iff_no_prime_factors ha).mpr h).dvd_of_dvd_mul_right
/-- Euclid's lemma: if `a ∣ b * c` and `a` and `b` have no common prime factors, `a ∣ c`.
Compare `IsCoprime.dvd_of_dvd_mul_right`. -/
theorem dvd_of_dvd_mul_right_of_no_prime_factors {a b c : R} (ha : a ≠ 0)
(no_factors : ∀ {d}, d ∣ a → d ∣ b → ¬Prime d) : a ∣ b * c → a ∣ c := by
simpa [mul_comm b c] using dvd_of_dvd_mul_left_of_no_prime_factors ha @no_factors
/-- If `a ≠ 0, b` are elements of a unique factorization domain, then dividing
out their common factor `c'` gives `a'` and `b'` with no factors in common. -/
theorem exists_reduced_factors :
∀ a ≠ (0 : R), ∀ b,
∃ a' b' c', IsRelPrime a' b' ∧ c' * a' = a ∧ c' * b' = b := by
intro a
refine induction_on_prime a ?_ ?_ ?_
· intros
contradiction
· intro a a_unit _ b
use a, b, 1
constructor
· intro p p_dvd_a _
exact isUnit_of_dvd_unit p_dvd_a a_unit
· simp
· intro a p a_ne_zero p_prime ih_a pa_ne_zero b
by_cases h : p ∣ b
· rcases h with ⟨b, rfl⟩
obtain ⟨a', b', c', no_factor, ha', hb'⟩ := ih_a a_ne_zero b
refine ⟨a', b', p * c', @no_factor, ?_, ?_⟩
· rw [mul_assoc, ha']
· rw [mul_assoc, hb']
· obtain ⟨a', b', c', coprime, rfl, rfl⟩ := ih_a a_ne_zero b
refine ⟨p * a', b', c', ?_, mul_left_comm _ _ _, rfl⟩
intro q q_dvd_pa' q_dvd_b'
rcases p_prime.left_dvd_or_dvd_right_of_dvd_mul q_dvd_pa' with p_dvd_q | q_dvd_a'
· have : p ∣ c' * b' := dvd_mul_of_dvd_right (p_dvd_q.trans q_dvd_b') _
contradiction
exact coprime q_dvd_a' q_dvd_b'
theorem exists_reduced_factors' (a b : R) (hb : b ≠ 0) :
∃ a' b' c', IsRelPrime a' b' ∧ c' * a' = a ∧ c' * b' = b :=
let ⟨b', a', c', no_factor, hb, ha⟩ := exists_reduced_factors b hb a
⟨a', b', c', fun _ hpb hpa => no_factor hpa hpb, ha, hb⟩
end UniqueFactorizationMonoid |
.lake/packages/mathlib/Mathlib/RingTheory/UniqueFactorizationDomain/NormalizedFactors.lean | import Mathlib.Algebra.GCDMonoid.Basic
import Mathlib.Data.Multiset.OrderedMonoid
import Mathlib.RingTheory.UniqueFactorizationDomain.Basic
/-!
# Unique factorization and normalization
## Main definitions
* `UniqueFactorizationMonoid.normalizedFactors`: choose a multiset of prime factors that are unique
by normalizing them.
* `UniqueFactorizationMonoid.normalizationMonoid`: choose a way of normalizing the elements of a UFM
-/
assert_not_exists Field
variable {α : Type*}
local infixl:50 " ~ᵤ " => Associated
namespace UniqueFactorizationMonoid
variable [CancelCommMonoidWithZero α] [NormalizationMonoid α]
variable [UniqueFactorizationMonoid α]
/-- Noncomputably determines the multiset of prime factors. -/
noncomputable def normalizedFactors (a : α) : Multiset α :=
Multiset.map normalize <| factors a
/-- An arbitrary choice of factors of `x : M` is exactly the (unique) normalized set of factors,
if `M` has a trivial group of units. -/
@[simp]
theorem factors_eq_normalizedFactors {M : Type*} [CancelCommMonoidWithZero M]
[UniqueFactorizationMonoid M] [Subsingleton Mˣ] (x : M) : factors x = normalizedFactors x := by
unfold normalizedFactors
convert (Multiset.map_id (factors x)).symm
ext p
exact normalize_eq p
theorem prod_normalizedFactors {a : α} (ane0 : a ≠ 0) :
Associated (normalizedFactors a).prod a := by
rw [normalizedFactors, factors, dif_neg ane0]
refine Associated.trans ?_ (Classical.choose_spec (exists_prime_factors a ane0)).2
rw [← Associates.mk_eq_mk_iff_associated, ← Associates.prod_mk, ← Associates.prod_mk,
Multiset.map_map]
congr 2
ext
rw [Function.comp_apply, Associates.mk_normalize]
theorem prod_normalizedFactors_eq {a : α} (ane0 : a ≠ 0) :
(normalizedFactors a).prod = normalize a := by
trans normalize (normalizedFactors a).prod
· rw [normalizedFactors, ← map_multiset_prod, normalize_idem]
· exact normalize_eq_normalize_iff.mpr (dvd_dvd_iff_associated.mpr (prod_normalizedFactors ane0))
theorem prime_of_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → Prime x := by
rw [normalizedFactors, factors]
split_ifs with ane0; · simp
intro x hx; rcases Multiset.mem_map.1 hx with ⟨y, ⟨hy, rfl⟩⟩
rw [(normalize_associated _).prime_iff]
exact (Classical.choose_spec (UniqueFactorizationMonoid.exists_prime_factors a ane0)).1 y hy
theorem irreducible_of_normalized_factor {a : α} :
∀ x : α, x ∈ normalizedFactors a → Irreducible x := fun x h =>
(prime_of_normalized_factor x h).irreducible
theorem normalize_normalized_factor {a : α} :
∀ x : α, x ∈ normalizedFactors a → normalize x = x := by
rw [normalizedFactors, factors]
split_ifs with h; · simp
intro x hx
obtain ⟨y, _, rfl⟩ := Multiset.mem_map.1 hx
apply normalize_idem
theorem normalizedFactors_irreducible {a : α} (ha : Irreducible a) :
normalizedFactors a = {normalize a} := by
obtain ⟨p, a_assoc, hp⟩ :=
prime_factors_irreducible ha ⟨prime_of_normalized_factor, prod_normalizedFactors ha.ne_zero⟩
have p_mem : p ∈ normalizedFactors a := by
rw [hp]
exact Multiset.mem_singleton_self _
convert hp
rwa [← normalize_normalized_factor p p_mem, normalize_eq_normalize_iff, dvd_dvd_iff_associated]
theorem normalizedFactors_eq_of_dvd (a : α) :
∀ᵉ (p ∈ normalizedFactors a) (q ∈ normalizedFactors a), p ∣ q → p = q := by
intro p hp q hq hdvd
convert normalize_eq_normalize hdvd
((prime_of_normalized_factor _ hp).irreducible.dvd_symm
(prime_of_normalized_factor _ hq).irreducible hdvd) <;>
apply (normalize_normalized_factor _ ‹_›).symm
theorem exists_mem_normalizedFactors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) :
p ∣ a → ∃ q ∈ normalizedFactors a, p ~ᵤ q := fun ⟨b, hb⟩ =>
have hb0 : b ≠ 0 := fun hb0 => by simp_all
have : Multiset.Rel Associated (p ::ₘ normalizedFactors b) (normalizedFactors a) :=
factors_unique
(fun _ hx =>
(Multiset.mem_cons.1 hx).elim (fun h => h.symm ▸ hp) (irreducible_of_normalized_factor _))
irreducible_of_normalized_factor
(Associated.symm <|
calc
Multiset.prod (normalizedFactors a) ~ᵤ a := prod_normalizedFactors ha0
_ = p * b := hb
_ ~ᵤ Multiset.prod (p ::ₘ normalizedFactors b) := by
rw [Multiset.prod_cons]
exact (prod_normalizedFactors hb0).symm.mul_left _
)
Multiset.exists_mem_of_rel_of_mem this (by simp)
theorem exists_mem_normalizedFactors {x : α} (hx : x ≠ 0) (h : ¬IsUnit x) :
∃ p, p ∈ normalizedFactors x := by
obtain ⟨p', hp', hp'x⟩ := WfDvdMonoid.exists_irreducible_factor h hx
obtain ⟨p, hp, _⟩ := exists_mem_normalizedFactors_of_dvd hx hp' hp'x
exact ⟨p, hp⟩
@[simp]
theorem normalizedFactors_zero : normalizedFactors (0 : α) = 0 := by
simp [normalizedFactors, factors]
@[simp]
theorem normalizedFactors_one : normalizedFactors (1 : α) = 0 := by
rcases subsingleton_or_nontrivial α with h | h
· dsimp [normalizedFactors, factors]
simp [Subsingleton.elim (1 : α) 0]
· rw [← Multiset.rel_zero_right]
apply factors_unique irreducible_of_normalized_factor
· intro x hx
exfalso
apply Multiset.notMem_zero x hx
· apply prod_normalizedFactors one_ne_zero
@[simp]
theorem normalizedFactors_mul {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) :
normalizedFactors (x * y) = normalizedFactors x + normalizedFactors y := by
have h : (normalize : α → α) = Associates.out ∘ Associates.mk := by
ext
rw [Function.comp_apply, Associates.out_mk]
rw [← Multiset.map_id' (normalizedFactors (x * y)), ← Multiset.map_id' (normalizedFactors x), ←
Multiset.map_id' (normalizedFactors y), ← Multiset.map_congr rfl normalize_normalized_factor, ←
Multiset.map_congr rfl normalize_normalized_factor, ←
Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_add, h, ←
Multiset.map_map Associates.out, eq_comm, ← Multiset.map_map Associates.out]
refine congr rfl ?_
apply Multiset.map_mk_eq_map_mk_of_rel
apply factors_unique
· intro x hx
rcases Multiset.mem_add.1 hx with (hx | hx) <;> exact irreducible_of_normalized_factor x hx
· exact irreducible_of_normalized_factor
· rw [Multiset.prod_add]
exact
((prod_normalizedFactors hx).mul_mul (prod_normalizedFactors hy)).trans
(prod_normalizedFactors (mul_ne_zero hx hy)).symm
@[simp]
theorem normalizedFactors_pow {x : α} (n : ℕ) :
normalizedFactors (x ^ n) = n • normalizedFactors x := by
induction n with
| zero => simp [zero_nsmul]
| succ n ih =>
by_cases h0 : x = 0
· simp [h0, zero_pow n.succ_ne_zero, nsmul_zero]
rw [pow_succ', succ_nsmul', normalizedFactors_mul h0 (pow_ne_zero _ h0), ih]
theorem _root_.Irreducible.normalizedFactors_pow {p : α} (hp : Irreducible p) (k : ℕ) :
normalizedFactors (p ^ k) = Multiset.replicate k (normalize p) := by
rw [UniqueFactorizationMonoid.normalizedFactors_pow, normalizedFactors_irreducible hp,
Multiset.nsmul_singleton]
theorem normalizedFactors_prod_eq (s : Multiset α) (hs : ∀ a ∈ s, Irreducible a) :
normalizedFactors s.prod = s.map normalize := by
induction s using Multiset.induction with
| empty => rw [Multiset.prod_zero, normalizedFactors_one, Multiset.map_zero]
| cons a s ih =>
have ia := hs a (Multiset.mem_cons_self a _)
have ib := fun b h => hs b (Multiset.mem_cons_of_mem h)
obtain rfl | ⟨b, hb⟩ := s.empty_or_exists_mem
· rw [Multiset.cons_zero, Multiset.prod_singleton, Multiset.map_singleton,
normalizedFactors_irreducible ia]
haveI := nontrivial_of_ne b 0 (ib b hb).ne_zero
rw [Multiset.prod_cons, Multiset.map_cons,
normalizedFactors_mul ia.ne_zero (Multiset.prod_ne_zero fun h => (ib 0 h).ne_zero rfl),
normalizedFactors_irreducible ia, ih ib, Multiset.singleton_add]
theorem dvd_iff_normalizedFactors_le_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) :
x ∣ y ↔ normalizedFactors x ≤ normalizedFactors y := by
constructor
· rintro ⟨c, rfl⟩
simp [hx, right_ne_zero_of_mul hy]
· rw [← (prod_normalizedFactors hx).dvd_iff_dvd_left, ←
(prod_normalizedFactors hy).dvd_iff_dvd_right]
apply Multiset.prod_dvd_prod_of_le
theorem _root_.Associated.normalizedFactors_eq {a b : α} (h : Associated a b) :
normalizedFactors a = normalizedFactors b := by
unfold normalizedFactors
have h' : ⇑(normalize (α := α)) = Associates.out ∘ Associates.mk := funext Associates.out_mk
rw [h', ← Multiset.map_map, ← Multiset.map_map,
Associates.rel_associated_iff_map_eq_map.mp (factors_rel_of_associated h)]
theorem associated_iff_normalizedFactors_eq_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) :
x ~ᵤ y ↔ normalizedFactors x = normalizedFactors y :=
⟨Associated.normalizedFactors_eq, fun h =>
(prod_normalizedFactors hx).symm.trans (_root_.trans (by rw [h]) (prod_normalizedFactors hy))⟩
theorem normalizedFactors_of_irreducible_pow {p : α} (hp : Irreducible p) (k : ℕ) :
normalizedFactors (p ^ k) = Multiset.replicate k (normalize p) := by
rw [normalizedFactors_pow, normalizedFactors_irreducible hp, Multiset.nsmul_singleton]
theorem zero_notMem_normalizedFactors (x : α) : (0 : α) ∉ normalizedFactors x := fun h =>
Prime.ne_zero (prime_of_normalized_factor _ h) rfl
theorem ne_zero_of_mem_normalizedFactors {x a : α} (hx : x ∈ normalizedFactors a) : x ≠ 0 :=
ne_of_mem_of_not_mem hx <| zero_notMem_normalizedFactors a
@[deprecated (since := "2025-05-23")]
alias zero_not_mem_normalizedFactors := zero_notMem_normalizedFactors
theorem dvd_of_mem_normalizedFactors {a p : α} (H : p ∈ normalizedFactors a) : p ∣ a := by
by_cases hcases : a = 0
· rw [hcases]
exact dvd_zero p
· exact dvd_trans (Multiset.dvd_prod H) (Associated.dvd (prod_normalizedFactors hcases))
@[deprecated (since := "2025-08-26")]
alias dvd_of_normalized_factor := dvd_of_mem_normalizedFactors
theorem mem_normalizedFactors_iff [Subsingleton αˣ] {p x : α} (hx : x ≠ 0) :
p ∈ normalizedFactors x ↔ Prime p ∧ p ∣ x := by
constructor
· intro h
exact ⟨prime_of_normalized_factor p h, dvd_of_mem_normalizedFactors h⟩
· rintro ⟨hprime, hdvd⟩
obtain ⟨q, hqmem, hqeq⟩ := exists_mem_normalizedFactors_of_dvd hx hprime.irreducible hdvd
rw [associated_iff_eq] at hqeq
exact hqeq ▸ hqmem
theorem mem_normalizedFactors_iff' {p x : α} (h : x ≠ 0) :
p ∈ normalizedFactors x ↔ Irreducible p ∧ normalize p = p ∧ p ∣ x := by
refine ⟨fun h ↦ ⟨irreducible_of_normalized_factor p h, normalize_normalized_factor p h,
dvd_of_mem_normalizedFactors h⟩, fun ⟨h₁, h₂, h₃⟩ ↦ ?_⟩
obtain ⟨y, hy₁, hy₂⟩ := exists_mem_factors_of_dvd h h₁ h₃
exact Multiset.mem_map.mpr ⟨y, hy₁, by
rwa [← h₂, normalize_eq_normalize_iff_associated, Associated.comm]⟩
/-- Relatively prime elements have disjoint prime factors (as multisets). -/
theorem disjoint_normalizedFactors {a b : α} (hc : IsRelPrime a b) :
Disjoint (normalizedFactors a) (normalizedFactors b) := by
rw [Multiset.disjoint_left]
intro x hxa hxb
have x_dvd_a := dvd_of_mem_normalizedFactors hxa
have x_dvd_b := dvd_of_mem_normalizedFactors hxb
exact (prime_of_normalized_factor x hxa).not_unit (hc x_dvd_a x_dvd_b)
theorem exists_associated_prime_pow_of_unique_normalized_factor {p r : α}
(h : ∀ {m}, m ∈ normalizedFactors r → m = p) (hr : r ≠ 0) : ∃ i : ℕ, Associated (p ^ i) r := by
use (normalizedFactors r).card
have := UniqueFactorizationMonoid.prod_normalizedFactors hr
rwa [Multiset.eq_replicate_of_mem fun b => h, Multiset.prod_replicate] at this
theorem normalizedFactors_prod_of_prime [Subsingleton αˣ] {m : Multiset α}
(h : ∀ p ∈ m, Prime p) : normalizedFactors m.prod = m := by
cases subsingleton_or_nontrivial α
· obtain rfl : m = 0 := by
refine Multiset.eq_zero_of_forall_notMem fun x hx ↦ ?_
simpa [Subsingleton.elim x 0] using h x hx
simp
· simpa only [← Multiset.rel_eq, ← associated_eq_eq] using
prime_factors_unique prime_of_normalized_factor h
(prod_normalizedFactors (m.prod_ne_zero_of_prime h))
theorem mem_normalizedFactors_eq_of_associated {a b c : α} (ha : a ∈ normalizedFactors c)
(hb : b ∈ normalizedFactors c) (h : Associated a b) : a = b := by
rw [← normalize_normalized_factor a ha, ← normalize_normalized_factor b hb,
normalize_eq_normalize_iff]
exact Associated.dvd_dvd h
@[simp]
theorem normalizedFactors_pos (x : α) (hx : x ≠ 0) : 0 < normalizedFactors x ↔ ¬IsUnit x := by
constructor
· intro h hx
obtain ⟨p, hp⟩ := Multiset.exists_mem_of_ne_zero h.ne'
exact
(prime_of_normalized_factor _ hp).not_unit
(isUnit_of_dvd_unit (dvd_of_mem_normalizedFactors hp) hx)
· intro h
obtain ⟨p, hp⟩ := exists_mem_normalizedFactors hx h
exact
bot_lt_iff_ne_bot.mpr
(mt Multiset.eq_zero_iff_forall_notMem.mp (not_forall.mpr ⟨p, not_not.mpr hp⟩))
/--
The multiset of normalized factors of `x` is nil if and only if `x` is a unit.
The converse is true without the nonzero assumption, see `normalizedFactors_of_isUnit`.
-/
theorem normalizedFactors_eq_zero_iff {x : α} (hx : x ≠ 0) :
normalizedFactors x = 0 ↔ IsUnit x := by
rw [← not_iff_not, ← normalizedFactors_pos _ hx, pos_iff_ne_zero]
/--
If `x` is a unit, then the multiset of normalized factors of `x` is nil.
The converse is true with a nonzero assumption, see `normalizedFactors_eq_zero_iff`.
-/
theorem normalizedFactors_of_isUnit {x : α} (hx : IsUnit x) :
normalizedFactors x = 0 := by
obtain rfl | hx₀ := eq_or_ne x 0
· simp
rwa [normalizedFactors_eq_zero_iff hx₀]
theorem dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) :
DvdNotUnit x y ↔ normalizedFactors x < normalizedFactors y := by
constructor
· rintro ⟨_, c, hc, rfl⟩
simp only [hx, right_ne_zero_of_mul hy, normalizedFactors_mul, Ne, not_false_iff,
lt_add_iff_pos_right, normalizedFactors_pos, hc]
· intro h
exact
dvdNotUnit_of_dvd_of_not_dvd
((dvd_iff_normalizedFactors_le_normalizedFactors hx hy).mpr h.le)
(mt (dvd_iff_normalizedFactors_le_normalizedFactors hy hx).mp h.not_ge)
theorem normalizedFactors_multiset_prod (s : Multiset α) (hs : 0 ∉ s) :
normalizedFactors (s.prod) = (s.map normalizedFactors).sum := by
cases subsingleton_or_nontrivial α
· obtain rfl : s = 0 := by
apply Multiset.eq_zero_of_forall_notMem
intro _
convert hs
simp
induction s using Multiset.induction with
| empty => simp
| cons _ _ IH =>
rw [Multiset.prod_cons, Multiset.map_cons, Multiset.sum_cons, normalizedFactors_mul, IH]
· exact fun h ↦ hs (Multiset.mem_cons_of_mem h)
· exact fun h ↦ hs (h ▸ Multiset.mem_cons_self _ _)
· apply Multiset.prod_ne_zero
exact fun h ↦ hs (Multiset.mem_cons_of_mem h)
variable {β : Type*} [CancelCommMonoidWithZero β] [NormalizationMonoid β]
[UniqueFactorizationMonoid β] {F : Type*} [EquivLike F α β] [MulEquivClass F α β] {f : F}
/--
If the monoid equiv `f : α ≃* β` commutes with `normalize` then, for `a : α`, it yields a
bijection between the `normalizedFactors` of `a` and of `f a`.
-/
def normalizedFactorsEquiv (he : ∀ x, normalize (f x) = f (normalize x)) (a : α) :
{x // x ∈ normalizedFactors a} ≃ {y // y ∈ normalizedFactors (f a)} :=
Equiv.subtypeEquiv f fun x ↦ by
rcases eq_or_ne a 0 with rfl | ha
· simp
· simp [mem_normalizedFactors_iff' ha,
mem_normalizedFactors_iff' (EmbeddingLike.map_ne_zero_iff.mpr ha), map_dvd_iff_dvd_symm,
MulEquiv.irreducible_iff, he]
@[simp]
theorem normalizedFactorsEquiv_apply (he : ∀ x, normalize (f x) = f (normalize x))
{a p : α} (hp : p ∈ normalizedFactors a) :
normalizedFactorsEquiv he a ⟨p, hp⟩ = f p := rfl
@[simp]
theorem normalizedFactorsEquiv_symm_apply (he : ∀ x, normalize (f x) = f (normalize x))
{a : α} {q : β} (hq : q ∈ normalizedFactors (f a)) :
(normalizedFactorsEquiv he a).symm ⟨q, hq⟩ = (MulEquivClass.toMulEquiv f).symm q := rfl
end UniqueFactorizationMonoid
namespace UniqueFactorizationMonoid
open Multiset Associates
variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α]
open scoped Classical in
/-- Noncomputably defines a `normalizationMonoid` structure on a `UniqueFactorizationMonoid`. -/
protected noncomputable def normalizationMonoid : NormalizationMonoid α :=
normalizationMonoidOfMonoidHomRightInverse
{ toFun := fun a : Associates α =>
if a = 0 then 0
else
((normalizedFactors a).map
(Classical.choose mk_surjective.hasRightInverse : Associates α → α)).prod
map_one' := by nontriviality α; simp
map_mul' := fun x y => by
by_cases hx : x = 0
· simp [hx]
by_cases hy : y = 0
· simp [hy]
simp [hx, hy] }
(by
intro x
dsimp
by_cases hx : x = 0
· simp [hx]
have h : Associates.mkMonoidHom ∘ Classical.choose mk_surjective.hasRightInverse =
(id : Associates α → Associates α) := by
ext x
rw [Function.comp_apply, mkMonoidHom_apply,
Classical.choose_spec mk_surjective.hasRightInverse x]
rfl
rw [if_neg hx, ← mkMonoidHom_apply, MonoidHom.map_multiset_prod, map_map, h, map_id, ←
associated_iff_eq]
apply prod_normalizedFactors hx)
end UniqueFactorizationMonoid |
.lake/packages/mathlib/Mathlib/RingTheory/UniqueFactorizationDomain/Ideal.lean | import Mathlib.RingTheory.Ideal.Operations
import Mathlib.RingTheory.UniqueFactorizationDomain.Defs
/-!
# Unique factorization and ascending chain condition on ideals
## Main results
* `Ideal.setOf_isPrincipal_wellFoundedOn_gt`, `WfDvdMonoid.of_setOf_isPrincipal_wellFoundedOn_gt`
in a domain, well-foundedness of the strict version of ∣ is equivalent to the ascending
chain condition on principal ideals.
-/
variable {α : Type*}
open UniqueFactorizationMonoid in
/-- Every non-zero prime ideal in a unique factorization domain contains a prime element. -/
theorem Ideal.IsPrime.exists_mem_prime_of_ne_bot {R : Type*} [CommSemiring R] [IsDomain R]
[UniqueFactorizationMonoid R] {I : Ideal R} (hI₂ : I.IsPrime) (hI : I ≠ ⊥) :
∃ x ∈ I, Prime x := by
classical
obtain ⟨a : R, ha₁ : a ∈ I, ha₂ : a ≠ 0⟩ := Submodule.exists_mem_ne_zero_of_ne_bot hI
replace ha₁ : (factors a).prod ∈ I := by
obtain ⟨u : Rˣ, hu : (factors a).prod * u = a⟩ := factors_prod ha₂
rwa [← hu, mul_unit_mem_iff_mem _ u.isUnit] at ha₁
obtain ⟨p : R, hp₁ : p ∈ factors a, hp₂ : p ∈ I⟩ :=
(hI₂.multiset_prod_mem_iff_exists_mem <| factors a).1 ha₁
exact ⟨p, hp₂, prime_of_factor p hp₁⟩
section Ideal
/-- The ascending chain condition on principal ideals holds in a `WfDvdMonoid` domain. -/
lemma Ideal.setOf_isPrincipal_wellFoundedOn_gt [CommSemiring α] [WfDvdMonoid α] [IsDomain α] :
{I : Ideal α | I.IsPrincipal}.WellFoundedOn (· > ·) := by
have : {I : Ideal α | I.IsPrincipal} = ((fun a ↦ Ideal.span {a}) '' Set.univ) := by
ext
simp [Submodule.isPrincipal_iff, eq_comm]
rw [this, Set.wellFoundedOn_image, Set.wellFoundedOn_univ]
convert wellFounded_dvdNotUnit (α := α)
ext
exact Ideal.span_singleton_lt_span_singleton
/-- The ascending chain condition on principal ideals in a domain is sufficient to prove that
the domain is `WfDvdMonoid`. -/
lemma WfDvdMonoid.of_setOf_isPrincipal_wellFoundedOn_gt [CommSemiring α] [IsDomain α]
(h : {I : Ideal α | I.IsPrincipal}.WellFoundedOn (· > ·)) :
WfDvdMonoid α := by
have : WellFounded (α := {I : Ideal α // I.IsPrincipal}) (· > ·) := h
constructor
convert InvImage.wf (fun a => ⟨Ideal.span ({a} : Set α), _, rfl⟩) this
ext
exact Ideal.span_singleton_lt_span_singleton.symm
end Ideal |
.lake/packages/mathlib/Mathlib/RingTheory/UniqueFactorizationDomain/Defs.lean | import Mathlib.Algebra.BigOperators.Group.Multiset.Basic
import Mathlib.Algebra.Group.Submonoid.BigOperators
import Mathlib.Algebra.GroupWithZero.Associated
import Mathlib.Algebra.GroupWithZero.Submonoid.Primal
import Mathlib.Order.WellFounded
/-!
# Unique factorization
## Main Definitions
* `WfDvdMonoid` holds for `Monoid`s for which a strict divisibility relation is
well-founded.
* `UniqueFactorizationMonoid` holds for `WfDvdMonoid`s where
`Irreducible` is equivalent to `Prime`
-/
assert_not_exists Field Finsupp Ideal
variable {α : Type*}
local infixl:50 " ~ᵤ " => Associated
/-- Well-foundedness of the strict version of ∣, which is equivalent to the descending chain
condition on divisibility and to the ascending chain condition on
principal ideals in an integral domain.
-/
abbrev WfDvdMonoid (α : Type*) [CommMonoidWithZero α] : Prop :=
IsWellFounded α DvdNotUnit
theorem wellFounded_dvdNotUnit {α : Type*} [CommMonoidWithZero α] [h : WfDvdMonoid α] :
WellFounded (DvdNotUnit (α := α)) :=
h.wf
namespace WfDvdMonoid
variable [CommMonoidWithZero α]
open Associates Nat
variable [WfDvdMonoid α]
theorem exists_irreducible_factor {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) :
∃ i, Irreducible i ∧ i ∣ a :=
let ⟨b, hs, hr⟩ := wellFounded_dvdNotUnit.has_min { b | b ∣ a ∧ ¬IsUnit b } ⟨a, dvd_rfl, ha⟩
⟨b,
⟨hs.2, fun c d he =>
let h := dvd_trans ⟨d, he⟩ hs.1
or_iff_not_imp_left.2 fun hc =>
of_not_not fun hd => hr c ⟨h, hc⟩ ⟨ne_zero_of_dvd_ne_zero ha0 h, d, hd, he⟩⟩,
hs.1⟩
@[elab_as_elim]
theorem induction_on_irreducible {motive : α → Prop} (a : α)
(zero : motive 0) (unit : ∀ u : α, IsUnit u → motive u)
(mul : ∀ a i : α, a ≠ 0 → Irreducible i → motive a → motive (i * a)) : motive a :=
haveI := Classical.dec
wellFounded_dvdNotUnit.fix
(fun a ih =>
if ha0 : a = 0 then ha0.substr zero
else
if hau : IsUnit a then unit a hau
else
let ⟨i, i_irred, b, hb⟩ := exists_irreducible_factor hau ha0
let hb0 : b ≠ 0 := ne_zero_of_dvd_ne_zero ha0 ⟨i, mul_comm i b ▸ hb⟩
hb.symm ▸ mul b i hb0 i_irred <| ih b ⟨hb0, i, i_irred.1, mul_comm i b ▸ hb⟩)
a
theorem exists_factors (a : α) :
a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ Associated f.prod a :=
induction_on_irreducible a (fun h => (h rfl).elim)
(fun _ hu _ => ⟨0, fun _ h => False.elim (Multiset.notMem_zero _ h), hu.unit, one_mul _⟩)
fun a i ha0 hi ih _ =>
let ⟨s, hs⟩ := ih ha0
⟨i ::ₘ s, fun b H => (Multiset.mem_cons.1 H).elim (fun h => h.symm ▸ hi) (hs.1 b), by
rw [s.prod_cons i]
exact hs.2.mul_left i⟩
theorem not_unit_iff_exists_factors_eq (a : α) (hn0 : a ≠ 0) :
¬IsUnit a ↔ ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod = a ∧ f ≠ ∅ :=
⟨fun hnu => by
obtain ⟨f, hi, u, rfl⟩ := exists_factors a hn0
obtain ⟨b, h⟩ := Multiset.exists_mem_of_ne_zero fun h : f = 0 => hnu <| by simp [h]
classical
refine ⟨(f.erase b).cons (b * u), fun a ha => ?_, ?_, Multiset.cons_ne_zero⟩
· obtain rfl | ha := Multiset.mem_cons.1 ha
exacts [Associated.irreducible ⟨u, rfl⟩ (hi b h), hi a (Multiset.mem_of_mem_erase ha)]
· rw [Multiset.prod_cons, mul_comm b, mul_assoc, Multiset.prod_erase h, mul_comm],
fun ⟨_, hi, he, hne⟩ =>
let ⟨b, h⟩ := Multiset.exists_mem_of_ne_zero hne
not_isUnit_of_not_isUnit_dvd (hi b h).not_isUnit <| he ▸ Multiset.dvd_prod h⟩
theorem isRelPrime_of_no_irreducible_factors {x y : α} (nonzero : ¬(x = 0 ∧ y = 0))
(H : ∀ z : α, Irreducible z → z ∣ x → ¬z ∣ y) : IsRelPrime x y :=
isRelPrime_of_no_nonunits_factors nonzero fun _z znu znz zx zy ↦
have ⟨i, h1, h2⟩ := exists_irreducible_factor znu znz
H i h1 (h2.trans zx) (h2.trans zy)
end WfDvdMonoid
section Prio
-- set_option default_priority 100
-- see Note [default priority]
/--
Unique factorization monoids are defined as `CancelCommMonoidWithZero`s with well-founded
strict divisibility relations, but this is equivalent to more familiar definitions:
Each element (except zero) is uniquely represented as a multiset of irreducible factors.
Uniqueness is only up to associated elements.
Each element (except zero) is non-uniquely represented as a multiset
of prime factors.
To define a UFD using the definition in terms of multisets
of irreducible factors, use the definition `of_existsUnique_irreducible_factors`
To define a UFD using the definition in terms of multisets
of prime factors, use the definition `of_exists_prime_factors`
-/
class UniqueFactorizationMonoid (α : Type*) [CancelCommMonoidWithZero α] : Prop
extends IsWellFounded α DvdNotUnit where
protected irreducible_iff_prime : ∀ {a : α}, Irreducible a ↔ Prime a
instance (priority := 100) ufm_of_decomposition_of_wfDvdMonoid
[CancelCommMonoidWithZero α] [WfDvdMonoid α] [DecompositionMonoid α] :
UniqueFactorizationMonoid α :=
{ ‹WfDvdMonoid α› with irreducible_iff_prime := irreducible_iff_prime }
end Prio
namespace UniqueFactorizationMonoid
variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α]
theorem exists_prime_factors (a : α) :
a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a := by
simp_rw [← UniqueFactorizationMonoid.irreducible_iff_prime]
apply WfDvdMonoid.exists_factors a
lemma exists_prime_iff :
(∃ (p : α), Prime p) ↔ ∃ (x : α), x ≠ 0 ∧ ¬ IsUnit x := by
refine ⟨fun ⟨p, hp⟩ ↦ ⟨p, hp.ne_zero, hp.not_unit⟩, fun ⟨x, hx₀, hxu⟩ ↦ ?_⟩
obtain ⟨f, hf, -⟩ := WfDvdMonoid.exists_irreducible_factor hxu hx₀
exact ⟨f, UniqueFactorizationMonoid.irreducible_iff_prime.mp hf⟩
@[elab_as_elim]
theorem induction_on_prime {P : α → Prop} (a : α) (h₁ : P 0) (h₂ : ∀ x : α, IsUnit x → P x)
(h₃ : ∀ a p : α, a ≠ 0 → Prime p → P a → P (p * a)) : P a := by
simp_rw [← UniqueFactorizationMonoid.irreducible_iff_prime] at h₃
exact WfDvdMonoid.induction_on_irreducible a h₁ h₂ h₃
instance : DecompositionMonoid α where
primal a := by
obtain rfl | ha := eq_or_ne a 0; · exact isPrimal_zero
obtain ⟨f, hf, u, rfl⟩ := exists_prime_factors a ha
exact ((Submonoid.isPrimal α).multiset_prod_mem f (hf · ·|>.isPrimal)).mul u.isUnit.isPrimal
end UniqueFactorizationMonoid
namespace UniqueFactorizationMonoid
variable [CancelCommMonoidWithZero α]
variable [UniqueFactorizationMonoid α]
open Classical in
/-- Noncomputably determines the multiset of prime factors. -/
noncomputable def factors (a : α) : Multiset α :=
if h : a = 0 then 0 else Classical.choose (UniqueFactorizationMonoid.exists_prime_factors a h)
theorem factors_prod {a : α} (ane0 : a ≠ 0) : Associated (factors a).prod a := by
rw [factors, dif_neg ane0]
exact (Classical.choose_spec (exists_prime_factors a ane0)).2
@[simp]
theorem factors_zero : factors (0 : α) = 0 := by simp [factors]
theorem ne_zero_of_mem_factors {p a : α} (h : p ∈ factors a) : a ≠ 0 := by
rintro rfl
simp at h
theorem dvd_of_mem_factors {p a : α} (h : p ∈ factors a) : p ∣ a :=
dvd_trans (Multiset.dvd_prod h) (Associated.dvd (factors_prod (ne_zero_of_mem_factors h)))
theorem prime_of_factor {a : α} (x : α) (hx : x ∈ factors a) : Prime x := by
have ane0 := ne_zero_of_mem_factors hx
rw [factors, dif_neg ane0] at hx
exact (Classical.choose_spec (UniqueFactorizationMonoid.exists_prime_factors a ane0)).1 x hx
theorem irreducible_of_factor {a : α} : ∀ x : α, x ∈ factors a → Irreducible x := fun x h =>
(prime_of_factor x h).irreducible
end UniqueFactorizationMonoid |
.lake/packages/mathlib/Mathlib/RingTheory/UniqueFactorizationDomain/Finsupp.lean | import Mathlib.Data.Finsupp.Multiset
import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors
/-!
# Factors as finsupp
## Main definitions
* `UniqueFactorizationMonoid.factorization`: the multiset of irreducible factors as a `Finsupp`.
-/
variable {α : Type*}
local infixl:50 " ~ᵤ " => Associated
section Finsupp
variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α]
variable [NormalizationMonoid α] [DecidableEq α]
open UniqueFactorizationMonoid
/-- This returns the multiset of irreducible factors as a `Finsupp`. -/
noncomputable def factorization (n : α) : α →₀ ℕ :=
Multiset.toFinsupp (normalizedFactors n)
theorem factorization_eq_count {n p : α} :
factorization n p = Multiset.count p (normalizedFactors n) := by simp [factorization]
@[simp]
theorem factorization_zero : factorization (0 : α) = 0 := by simp [factorization]
@[simp]
theorem factorization_one : factorization (1 : α) = 0 := by simp [factorization]
/-- The support of `factorization n` is exactly the Finset of normalized factors -/
@[simp]
theorem support_factorization {n : α} :
(factorization n).support = (normalizedFactors n).toFinset := by
simp [factorization, Multiset.toFinsupp_support]
/-- For nonzero `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/
@[simp]
theorem factorization_mul {a b : α} (ha : a ≠ 0) (hb : b ≠ 0) :
factorization (a * b) = factorization a + factorization b := by
simp [factorization, normalizedFactors_mul ha hb]
/-- For any `p`, the power of `p` in `x^n` is `n` times the power in `x` -/
theorem factorization_pow {x : α} {n : ℕ} : factorization (x ^ n) = n • factorization x := by
ext
simp [factorization]
theorem associated_of_factorization_eq (a b : α) (ha : a ≠ 0) (hb : b ≠ 0)
(h : factorization a = factorization b) : Associated a b := by
simp_rw [factorization, AddEquiv.apply_eq_iff_eq] at h
rwa [associated_iff_normalizedFactors_eq_normalizedFactors ha hb]
end Finsupp |
.lake/packages/mathlib/Mathlib/RingTheory/UniqueFactorizationDomain/FactorSet.lean | import Mathlib.RingTheory.UniqueFactorizationDomain.Basic
import Mathlib.Tactic.Ring
/-!
# Set of factors
## Main definitions
* `Associates.FactorSet`: multiset of factors of an element, unique up to propositional equality.
* `Associates.factors`: determine the `FactorSet` for a given element.
## TODO
* set up the complete lattice structure on `FactorSet`.
-/
variable {α : Type*}
local infixl:50 " ~ᵤ " => Associated
namespace Associates
open UniqueFactorizationMonoid Associated Multiset
variable [CancelCommMonoidWithZero α]
/-- `FactorSet α` representation elements of unique factorization domain as multisets.
`Multiset α` produced by `normalizedFactors` are only unique up to associated elements, while the
multisets in `FactorSet α` are unique by equality and restricted to irreducible elements. This
gives us a representation of each element as a unique multisets (or the added ⊤ for 0), which has a
complete lattice structure. Infimum is the greatest common divisor and supremum is the least common
multiple.
-/
abbrev FactorSet.{u} (α : Type u) [CancelCommMonoidWithZero α] : Type u :=
WithTop (Multiset { a : Associates α // Irreducible a })
attribute [local instance] Associated.setoid
theorem FactorSet.coe_add {a b : Multiset { a : Associates α // Irreducible a }} :
(↑(a + b) : FactorSet α) = a + b := by norm_cast
theorem FactorSet.sup_add_inf_eq_add [DecidableEq (Associates α)] :
∀ a b : FactorSet α, a ⊔ b + a ⊓ b = a + b
| ⊤, b => show ⊤ ⊔ b + ⊤ ⊓ b = ⊤ + b by simp
| a, ⊤ => show a ⊔ ⊤ + a ⊓ ⊤ = a + ⊤ by simp
| WithTop.some a, WithTop.some b =>
show (a : FactorSet α) ⊔ b + (a : FactorSet α) ⊓ b = a + b by
rw [← WithTop.coe_sup, ← WithTop.coe_inf, ← WithTop.coe_add, ← WithTop.coe_add,
WithTop.coe_eq_coe]
exact Multiset.union_add_inter _ _
/-- Evaluates the product of a `FactorSet` to be the product of the corresponding multiset,
or `0` if there is none. -/
def FactorSet.prod : FactorSet α → Associates α
| ⊤ => 0
| WithTop.some s => (s.map (↑)).prod
@[simp]
theorem prod_top : (⊤ : FactorSet α).prod = 0 :=
rfl
@[simp]
theorem prod_coe {s : Multiset { a : Associates α // Irreducible a }} :
FactorSet.prod (s : FactorSet α) = (s.map (↑)).prod :=
rfl
@[simp]
theorem prod_add : ∀ a b : FactorSet α, (a + b).prod = a.prod * b.prod
| ⊤, b => show (⊤ + b).prod = (⊤ : FactorSet α).prod * b.prod by simp
| a, ⊤ => show (a + ⊤).prod = a.prod * (⊤ : FactorSet α).prod by simp
| WithTop.some a, WithTop.some b => by
rw [← FactorSet.coe_add, prod_coe, prod_coe, prod_coe, Multiset.map_add, Multiset.prod_add]
@[gcongr]
theorem prod_mono : ∀ {a b : FactorSet α}, a ≤ b → a.prod ≤ b.prod
| ⊤, b, h => by
have : b = ⊤ := top_unique h
rw [this, prod_top]
| a, ⊤, _ => show a.prod ≤ (⊤ : FactorSet α).prod by simp
| WithTop.some _, WithTop.some _, h =>
prod_le_prod <| Multiset.map_le_map <| WithTop.coe_le_coe.1 <| h
theorem FactorSet.prod_eq_zero_iff [Nontrivial α] (p : FactorSet α) : p.prod = 0 ↔ p = ⊤ := by
unfold FactorSet at p
induction p -- TODO: `induction_eliminator` doesn't work with `abbrev`
· simp only [Associates.prod_top]
· rw [prod_coe, Multiset.prod_eq_zero_iff, Multiset.mem_map, eq_false WithTop.coe_ne_top,
iff_false, not_exists]
exact fun a => not_and_of_not_right _ a.prop.ne_zero
section count
variable [DecidableEq (Associates α)]
/-- `bcount p s` is the multiplicity of `p` in the FactorSet `s` (with bundled `p`). -/
def bcount (p : { a : Associates α // Irreducible a }) :
FactorSet α → ℕ
| ⊤ => 0
| WithTop.some s => s.count p
variable [∀ p : Associates α, Decidable (Irreducible p)] {p : Associates α}
/-- `count p s` is the multiplicity of the irreducible `p` in the FactorSet `s`.
If `p` is not irreducible, `count p s` is defined to be `0`. -/
def count (p : Associates α) : FactorSet α → ℕ :=
if hp : Irreducible p then bcount ⟨p, hp⟩ else 0
@[simp]
theorem count_some (hp : Irreducible p) (s : Multiset _) :
count p (WithTop.some s) = s.count ⟨p, hp⟩ := by
simp only [count, dif_pos hp, bcount]
@[simp]
theorem count_zero (hp : Irreducible p) : count p (0 : FactorSet α) = 0 := by
simp only [count, dif_pos hp, bcount, Multiset.count_zero]
theorem count_reducible (hp : ¬Irreducible p) : count p = 0 := dif_neg hp
end count
section Mem
/-- membership in a FactorSet (bundled version) -/
def BfactorSetMem : { a : Associates α // Irreducible a } → FactorSet α → Prop
| _, ⊤ => True
| p, some l => p ∈ l
/-- `FactorSetMem p s` is the predicate that the irreducible `p` is a member of
`s : FactorSet α`.
If `p` is not irreducible, `p` is not a member of any `FactorSet`. -/
def FactorSetMem (s : FactorSet α) (p : Associates α) : Prop :=
letI : Decidable (Irreducible p) := Classical.dec _
if hp : Irreducible p then BfactorSetMem ⟨p, hp⟩ s else False
instance : Membership (Associates α) (FactorSet α) :=
⟨FactorSetMem⟩
@[simp]
theorem factorSetMem_eq_mem (p : Associates α) (s : FactorSet α) : FactorSetMem s p = (p ∈ s) :=
rfl
theorem mem_factorSet_top {p : Associates α} {hp : Irreducible p} : p ∈ (⊤ : FactorSet α) := by
dsimp only [Membership.mem]; dsimp only [FactorSetMem]; split_ifs; exact trivial
theorem mem_factorSet_some {p : Associates α} {hp : Irreducible p}
{l : Multiset { a : Associates α // Irreducible a }} :
p ∈ (l : FactorSet α) ↔ Subtype.mk p hp ∈ l := by
dsimp only [Membership.mem]; dsimp only [FactorSetMem]; split_ifs; rfl
theorem reducible_notMem_factorSet {p : Associates α} (hp : ¬Irreducible p) (s : FactorSet α) :
p ∉ s := fun h ↦ by
rwa [← factorSetMem_eq_mem, FactorSetMem, dif_neg hp] at h
@[deprecated (since := "2025-05-23")]
alias reducible_not_mem_factorSet := reducible_notMem_factorSet
theorem irreducible_of_mem_factorSet {p : Associates α} {s : FactorSet α} (h : p ∈ s) :
Irreducible p :=
by_contra fun hp ↦ reducible_notMem_factorSet hp s h
end Mem
variable [UniqueFactorizationMonoid α]
theorem FactorSet.unique [Nontrivial α] {p q : FactorSet α} (h : p.prod = q.prod) : p = q := by
-- TODO: `induction_eliminator` doesn't work with `abbrev`
unfold FactorSet at p q
induction p <;> induction q
· rfl
· rw [eq_comm, ← FactorSet.prod_eq_zero_iff, ← h, Associates.prod_top]
· rw [← FactorSet.prod_eq_zero_iff, h, Associates.prod_top]
· congr 1
rw [← Multiset.map_eq_map Subtype.coe_injective]
apply unique' _ _ h <;>
· intro a ha
obtain ⟨⟨a', irred⟩, -, rfl⟩ := Multiset.mem_map.mp ha
rwa [Subtype.coe_mk]
/-- This returns the multiset of irreducible factors as a `FactorSet`,
a multiset of irreducible associates `WithTop`. -/
noncomputable def factors' (a : α) : Multiset { a : Associates α // Irreducible a } :=
(factors a).pmap (fun a ha => ⟨Associates.mk a, irreducible_mk.2 ha⟩) irreducible_of_factor
@[simp]
theorem map_subtype_coe_factors' {a : α} :
(factors' a).map (↑) = (factors a).map Associates.mk := by
simp [factors', Multiset.map_pmap, Multiset.pmap_eq_map]
theorem factors'_cong {a b : α} (h : a ~ᵤ b) : factors' a = factors' b := by
obtain rfl | hb := eq_or_ne b 0
· rw [associated_zero_iff_eq_zero] at h
rw [h]
have ha : a ≠ 0 := by
contrapose! hb with ha
rw [← associated_zero_iff_eq_zero, ← ha]
exact h.symm
rw [← Multiset.map_eq_map Subtype.coe_injective, map_subtype_coe_factors',
map_subtype_coe_factors', ← rel_associated_iff_map_eq_map]
exact
factors_unique irreducible_of_factor irreducible_of_factor
((factors_prod ha).trans <| h.trans <| (factors_prod hb).symm)
/-- This returns the multiset of irreducible factors of an associate as a `FactorSet`,
a multiset of irreducible associates `WithTop`. -/
noncomputable def factors (a : Associates α) : FactorSet α := by
classical refine if h : a = 0 then ⊤ else Quotient.hrecOn a (fun x _ => factors' x) ?_ h
intro a b hab
apply Function.hfunext
· have : a ~ᵤ 0 ↔ b ~ᵤ 0 := Iff.intro (fun ha0 => hab.symm.trans ha0) fun hb0 => hab.trans hb0
simp only [associated_zero_iff_eq_zero] at this
simp only [quotient_mk_eq_mk, this, mk_eq_zero]
exact fun ha hb _ => heq_of_eq <| congr_arg some <| factors'_cong hab
@[simp]
theorem factors_zero : (0 : Associates α).factors = ⊤ :=
dif_pos rfl
@[simp]
theorem factors_mk (a : α) (h : a ≠ 0) : (Associates.mk a).factors = factors' a := by
classical
apply dif_neg
apply mt mk_eq_zero.1 h
@[simp]
theorem factors_prod (a : Associates α) : a.factors.prod = a := by
rcases Associates.mk_surjective a with ⟨a, rfl⟩
rcases eq_or_ne a 0 with rfl | ha
· simp
· simp [ha, prod_mk, mk_eq_mk_iff_associated, UniqueFactorizationMonoid.factors_prod,
-Quotient.eq]
@[simp]
theorem prod_factors [Nontrivial α] (s : FactorSet α) : s.prod.factors = s :=
FactorSet.unique <| factors_prod _
@[nontriviality]
theorem factors_subsingleton [Subsingleton α] {a : Associates α} : a.factors = ⊤ := by
have : Subsingleton (Associates α) := inferInstance
convert factors_zero
theorem factors_eq_top_iff_zero {a : Associates α} : a.factors = ⊤ ↔ a = 0 := by
nontriviality α
exact ⟨fun h ↦ by rwa [← factors_prod a, FactorSet.prod_eq_zero_iff], fun h ↦ h ▸ factors_zero⟩
theorem factors_eq_some_iff_ne_zero {a : Associates α} :
(∃ s : Multiset { p : Associates α // Irreducible p }, a.factors = s) ↔ a ≠ 0 := by
simp_rw [@eq_comm _ a.factors, ← WithTop.ne_top_iff_exists]
exact factors_eq_top_iff_zero.not
theorem eq_of_factors_eq_factors {a b : Associates α} (h : a.factors = b.factors) : a = b := by
have : a.factors.prod = b.factors.prod := by rw [h]
rwa [factors_prod, factors_prod] at this
@[deprecated (since := "2025-10-06")] alias eq_of_prod_eq_prod := FactorSet.unique
@[simp]
theorem factors_mul (a b : Associates α) : (a * b).factors = a.factors + b.factors := by
nontriviality α
refine FactorSet.unique <| eq_of_factors_eq_factors ?_
rw [prod_add, factors_prod, factors_prod, factors_prod]
@[gcongr]
theorem factors_mono : ∀ {a b : Associates α}, a ≤ b → a.factors ≤ b.factors
| s, t, ⟨d, eq⟩ => by rw [eq, factors_mul]; exact le_add_of_nonneg_right bot_le
@[simp]
theorem factors_le {a b : Associates α} : a.factors ≤ b.factors ↔ a ≤ b := by
refine ⟨fun h ↦ ?_, factors_mono⟩
have : a.factors.prod ≤ b.factors.prod := prod_mono h
rwa [factors_prod, factors_prod] at this
section count
variable [DecidableEq (Associates α)] [∀ p : Associates α, Decidable (Irreducible p)]
theorem eq_factors_of_eq_counts {a b : Associates α} (ha : a ≠ 0) (hb : b ≠ 0)
(h : ∀ p : Associates α, Irreducible p → p.count a.factors = p.count b.factors) :
a.factors = b.factors := by
obtain ⟨sa, h_sa⟩ := factors_eq_some_iff_ne_zero.mpr ha
obtain ⟨sb, h_sb⟩ := factors_eq_some_iff_ne_zero.mpr hb
simp_all only [count_some, WithTop.coe_eq_coe]
ext
grind
theorem eq_of_eq_counts {a b : Associates α} (ha : a ≠ 0) (hb : b ≠ 0)
(h : ∀ p : Associates α, Irreducible p → p.count a.factors = p.count b.factors) : a = b :=
eq_of_factors_eq_factors (eq_factors_of_eq_counts ha hb h)
theorem count_le_count_of_factors_le {a b p : Associates α} (hb : b ≠ 0) (hp : Irreducible p)
(h : a.factors ≤ b.factors) : p.count a.factors ≤ p.count b.factors := by
by_cases ha : a = 0
· simp_all
obtain ⟨sa, h_sa⟩ := factors_eq_some_iff_ne_zero.mpr ha
obtain ⟨sb, h_sb⟩ := factors_eq_some_iff_ne_zero.mpr hb
rw [h_sa, h_sb] at h ⊢
rw [count_some hp, count_some hp]; rw [WithTop.coe_le_coe] at h
exact Multiset.count_le_of_le _ h
theorem count_le_count_of_le {a b p : Associates α} (hb : b ≠ 0) (hp : Irreducible p) (h : a ≤ b) :
p.count a.factors ≤ p.count b.factors :=
count_le_count_of_factors_le hb hp <| factors_mono h
end count
theorem prod_le [Nontrivial α] {a b : FactorSet α} : a.prod ≤ b.prod ↔ a ≤ b := by
refine ⟨fun h ↦ ?_, prod_mono⟩
have : a.prod.factors ≤ b.prod.factors := factors_mono h
rwa [prod_factors, prod_factors] at this
open Classical in
noncomputable instance : Max (Associates α) :=
⟨fun a b => (a.factors ⊔ b.factors).prod⟩
open Classical in
noncomputable instance : Min (Associates α) :=
⟨fun a b => (a.factors ⊓ b.factors).prod⟩
open Classical in
noncomputable instance : Lattice (Associates α) :=
{ Associates.instPartialOrder with
sup := (· ⊔ ·)
inf := (· ⊓ ·)
sup_le := fun _ _ c hac hbc =>
factors_prod c ▸ prod_mono (sup_le (factors_mono hac) (factors_mono hbc))
le_sup_left := fun a _ => le_trans (le_of_eq (factors_prod a).symm) <| prod_mono <| le_sup_left
le_sup_right := fun _ b =>
le_trans (le_of_eq (factors_prod b).symm) <| prod_mono <| le_sup_right
le_inf := fun a _ _ hac hbc =>
factors_prod a ▸ prod_mono (le_inf (factors_mono hac) (factors_mono hbc))
inf_le_left := fun a _ => le_trans (prod_mono inf_le_left) (le_of_eq (factors_prod a))
inf_le_right := fun _ b => le_trans (prod_mono inf_le_right) (le_of_eq (factors_prod b)) }
open Classical in
theorem sup_mul_inf (a b : Associates α) : (a ⊔ b) * (a ⊓ b) = a * b :=
show (a.factors ⊔ b.factors).prod * (a.factors ⊓ b.factors).prod = a * b by
nontriviality α
refine eq_of_factors_eq_factors ?_
rw [← prod_add, prod_factors, factors_mul, FactorSet.sup_add_inf_eq_add]
theorem dvd_of_mem_factors {a p : Associates α} (hm : p ∈ factors a) :
p ∣ a := by
rcases eq_or_ne a 0 with rfl | ha0
· exact dvd_zero p
obtain ⟨a0, nza, ha'⟩ := exists_non_zero_rep ha0
rw [← Associates.factors_prod a]
rw [← ha', factors_mk a0 nza] at hm ⊢
rw [prod_coe]
apply Multiset.dvd_prod; apply Multiset.mem_map.mpr
exact ⟨⟨p, irreducible_of_mem_factorSet hm⟩, mem_factorSet_some.mp hm, rfl⟩
theorem dvd_of_mem_factors' {a : α} {p : Associates α} {hp : Irreducible p} {hz : a ≠ 0}
(h_mem : Subtype.mk p hp ∈ factors' a) : p ∣ Associates.mk a := by
haveI := Classical.decEq (Associates α)
apply dvd_of_mem_factors
rw [factors_mk _ hz]
apply mem_factorSet_some.2 h_mem
theorem mem_factors'_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) (hd : p ∣ a) :
Subtype.mk (Associates.mk p) (irreducible_mk.2 hp) ∈ factors' a := by
obtain ⟨q, hq, hpq⟩ := exists_mem_factors_of_dvd ha0 hp hd
apply Multiset.mem_pmap.mpr; use q; use hq
exact Subtype.eq (Eq.symm (mk_eq_mk_iff_associated.mpr hpq))
theorem mem_factors'_iff_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) :
Subtype.mk (Associates.mk p) (irreducible_mk.2 hp) ∈ factors' a ↔ p ∣ a := by
constructor
· rw [← mk_dvd_mk]
apply dvd_of_mem_factors'
apply ha0
· apply mem_factors'_of_dvd ha0 hp
theorem mem_factors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) (hd : p ∣ a) :
Associates.mk p ∈ factors (Associates.mk a) := by
rw [factors_mk _ ha0]
exact mem_factorSet_some.mpr (mem_factors'_of_dvd ha0 hp hd)
theorem mem_factors_iff_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) :
Associates.mk p ∈ factors (Associates.mk a) ↔ p ∣ a := by
constructor
· rw [← mk_dvd_mk]
apply dvd_of_mem_factors
· apply mem_factors_of_dvd ha0 hp
open Classical in
theorem exists_prime_dvd_of_not_inf_one {a b : α} (ha : a ≠ 0) (hb : b ≠ 0)
(h : Associates.mk a ⊓ Associates.mk b ≠ 1) : ∃ p : α, Prime p ∧ p ∣ a ∧ p ∣ b := by
have hz : factors (Associates.mk a) ⊓ factors (Associates.mk b) ≠ 0 := by
contrapose! h with hf
change (factors (Associates.mk a) ⊓ factors (Associates.mk b)).prod = 1
rw [hf]
exact Multiset.prod_zero
rw [factors_mk a ha, factors_mk b hb, ← WithTop.coe_inf] at hz
obtain ⟨⟨p0, p0_irr⟩, p0_mem⟩ := Multiset.exists_mem_of_ne_zero ((mt WithTop.coe_eq_coe.mpr) hz)
rw [Multiset.inf_eq_inter] at p0_mem
obtain ⟨p, rfl⟩ : ∃ p, Associates.mk p = p0 := Quot.exists_rep p0
refine ⟨p, ?_, ?_, ?_⟩
· rw [← UniqueFactorizationMonoid.irreducible_iff_prime, ← irreducible_mk]
exact p0_irr
· apply dvd_of_mk_le_mk
apply dvd_of_mem_factors' (Multiset.mem_inter.mp p0_mem).left
apply ha
· apply dvd_of_mk_le_mk
apply dvd_of_mem_factors' (Multiset.mem_inter.mp p0_mem).right
apply hb
theorem coprime_iff_inf_one {a b : α} (ha0 : a ≠ 0) (hb0 : b ≠ 0) :
Associates.mk a ⊓ Associates.mk b = 1 ↔ ∀ {d : α}, d ∣ a → d ∣ b → ¬Prime d := by
constructor
· intro hg p ha hb hp
refine (Associates.prime_mk.mpr hp).not_unit (isUnit_of_dvd_one ?_)
rw [← hg]
exact le_inf (mk_le_mk_of_dvd ha) (mk_le_mk_of_dvd hb)
· contrapose
intro hg hc
obtain ⟨p, hp, hpa, hpb⟩ := exists_prime_dvd_of_not_inf_one ha0 hb0 hg
exact hc hpa hpb hp
theorem factors_self [Nontrivial α] {p : Associates α} (hp : Irreducible p) :
p.factors = WithTop.some {⟨p, hp⟩} :=
FactorSet.unique
(by rw [factors_prod, FactorSet.prod.eq_def]; dsimp; rw [prod_singleton])
theorem factors_prime_pow [Nontrivial α] {p : Associates α} (hp : Irreducible p) (k : ℕ) :
factors (p ^ k) = WithTop.some (Multiset.replicate k ⟨p, hp⟩) :=
FactorSet.unique
(by
rw [Associates.factors_prod, FactorSet.prod.eq_def]
dsimp; rw [Multiset.map_replicate, Multiset.prod_replicate, Subtype.coe_mk])
theorem prime_pow_le_iff_le_bcount [DecidableEq (Associates α)] {m p : Associates α}
(h₁ : m ≠ 0) (h₂ : Irreducible p) {k : ℕ} : p ^ k ≤ m ↔ k ≤ bcount ⟨p, h₂⟩ m.factors := by
rcases Associates.exists_non_zero_rep h₁ with ⟨m, hm, rfl⟩
have := nontrivial_of_ne _ _ hm
rw [bcount.eq_def, factors_mk, Multiset.le_count_iff_replicate_le, ← factors_le,
factors_prime_pow, factors_mk, WithTop.coe_le_coe] <;> assumption
@[simp]
theorem factors_one [Nontrivial α] : factors (1 : Associates α) = 0 := by
apply FactorSet.unique
rw [Associates.factors_prod]
exact Multiset.prod_zero
@[simp]
theorem pow_factors [Nontrivial α] {a : Associates α} {k : ℕ} :
(a ^ k).factors = k • a.factors := by
induction k with
| zero => rw [zero_nsmul, pow_zero]; exact factors_one
| succ n h => rw [pow_succ, succ_nsmul, factors_mul, h]
section count
variable [DecidableEq (Associates α)] [∀ p : Associates α, Decidable (Irreducible p)]
theorem prime_pow_dvd_iff_le {m p : Associates α} (h₁ : m ≠ 0) (h₂ : Irreducible p) {k : ℕ} :
p ^ k ≤ m ↔ k ≤ count p m.factors := by
rw [count, dif_pos h₂, prime_pow_le_iff_le_bcount h₁]
theorem le_of_count_ne_zero {m p : Associates α} (h0 : m ≠ 0) (hp : Irreducible p) :
count p m.factors ≠ 0 → p ≤ m := by
nontriviality α
rw [← pos_iff_ne_zero]
intro h
rw [← pow_one p]
apply (prime_pow_dvd_iff_le h0 hp).2
simpa only
theorem count_ne_zero_iff_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) :
(Associates.mk p).count (Associates.mk a).factors ≠ 0 ↔ p ∣ a := by
nontriviality α
rw [← Associates.mk_le_mk_iff_dvd]
refine
⟨fun h =>
Associates.le_of_count_ne_zero (Associates.mk_ne_zero.mpr ha0)
(Associates.irreducible_mk.mpr hp) h,
fun h => ?_⟩
rw [← pow_one (Associates.mk p),
Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero.mpr ha0)
(Associates.irreducible_mk.mpr hp)] at h
exact (zero_lt_one.trans_le h).ne'
theorem count_self [Nontrivial α] {p : Associates α}
(hp : Irreducible p) : p.count p.factors = 1 := by
simp [factors_self hp, Associates.count_some hp]
theorem count_eq_zero_of_ne {p q : Associates α} (hp : Irreducible p)
(hq : Irreducible q) (h : p ≠ q) : p.count q.factors = 0 :=
not_ne_iff.mp fun h' ↦ h <| associated_iff_eq.mp <| hp.associated_of_dvd hq <|
le_of_count_ne_zero hq.ne_zero hp h'
theorem count_mul {a : Associates α} (ha : a ≠ 0) {b : Associates α}
(hb : b ≠ 0) {p : Associates α} (hp : Irreducible p) :
count p (factors (a * b)) = count p a.factors + count p b.factors := by
obtain ⟨a0, nza, rfl⟩ := exists_non_zero_rep ha
obtain ⟨b0, nzb, rfl⟩ := exists_non_zero_rep hb
rw [factors_mul, factors_mk a0 nza, factors_mk b0 nzb, ← FactorSet.coe_add, count_some hp,
Multiset.count_add, count_some hp, count_some hp]
theorem count_of_coprime {a : Associates α} (ha : a ≠ 0)
{b : Associates α} (hb : b ≠ 0) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) {p : Associates α}
(hp : Irreducible p) : count p a.factors = 0 ∨ count p b.factors = 0 := by
rw [or_iff_not_imp_left, ← Ne]
intro hca
contrapose! hab with hcb
exact ⟨p, le_of_count_ne_zero ha hp hca, le_of_count_ne_zero hb hp hcb,
UniqueFactorizationMonoid.irreducible_iff_prime.mp hp⟩
theorem count_mul_of_coprime {a : Associates α} {b : Associates α}
(hb : b ≠ 0) {p : Associates α} (hp : Irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) :
count p a.factors = 0 ∨ count p a.factors = count p (a * b).factors := by
by_cases ha : a = 0
· simp [ha]
rcases count_of_coprime ha hb hab hp with hz | hb0; · tauto
apply Or.intro_right
rw [count_mul ha hb hp, hb0, add_zero]
theorem count_mul_of_coprime' {a b : Associates α} {p : Associates α}
(hp : Irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) :
count p (a * b).factors = count p a.factors ∨ count p (a * b).factors = count p b.factors := by
by_cases ha : a = 0
· simp [ha]
by_cases hb : b = 0
· simp [hb]
rw [count_mul ha hb hp]
rcases count_of_coprime ha hb hab hp with ha0 | hb0
· apply Or.intro_right
rw [ha0, zero_add]
· apply Or.intro_left
rw [hb0, add_zero]
theorem dvd_count_of_dvd_count_mul {a b : Associates α} (hb : b ≠ 0)
{p : Associates α} (hp : Irreducible p) (hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) {k : ℕ}
(habk : k ∣ count p (a * b).factors) : k ∣ count p a.factors := by
by_cases ha : a = 0
· simpa [*] using habk
rcases count_of_coprime ha hb hab hp with hz | h
· rw [hz]
exact dvd_zero k
· rw [count_mul ha hb hp, h] at habk
exact habk
theorem count_pow [Nontrivial α] {a : Associates α} (ha : a ≠ 0)
{p : Associates α} (hp : Irreducible p) (k : ℕ) :
count p (a ^ k).factors = k * count p a.factors := by
induction k with
| zero => rw [pow_zero, factors_one, zero_mul, count_zero hp]
| succ n h => rw [pow_succ', count_mul ha (pow_ne_zero _ ha) hp, h]; ring
theorem dvd_count_pow [Nontrivial α] {a : Associates α} (ha : a ≠ 0)
{p : Associates α} (hp : Irreducible p) (k : ℕ) : k ∣ count p (a ^ k).factors := by
rw [count_pow ha hp]
apply dvd_mul_right
theorem is_pow_of_dvd_count {a : Associates α}
(ha : a ≠ 0) {k : ℕ} (hk : ∀ p : Associates α, Irreducible p → k ∣ count p a.factors) :
∃ b : Associates α, a = b ^ k := by
nontriviality α
obtain ⟨a0, hz, rfl⟩ := exists_non_zero_rep ha
rw [factors_mk a0 hz] at hk
have hk' : ∀ p, p ∈ factors' a0 → k ∣ (factors' a0).count p := by
rintro p -
have pp : p = ⟨p.val, p.2⟩ := by simp only [Subtype.coe_eta]
rw [pp, ← count_some p.2]
exact hk p.val p.2
obtain ⟨u, hu⟩ := Multiset.exists_smul_of_dvd_count _ hk'
use FactorSet.prod (u : FactorSet α)
apply eq_of_factors_eq_factors
rw [pow_factors, prod_factors, factors_mk a0 hz, hu]
exact WithBot.coe_nsmul u k
/-- The only divisors of prime powers are prime powers. See `eq_pow_find_of_dvd_irreducible_pow`
for an explicit expression as a p-power (without using `count`). -/
theorem eq_pow_count_factors_of_dvd_pow {p a : Associates α}
(hp : Irreducible p) {n : ℕ} (h : a ∣ p ^ n) : a = p ^ p.count a.factors := by
nontriviality α
have hph := pow_ne_zero n hp.ne_zero
have ha := ne_zero_of_dvd_ne_zero hph h
apply eq_of_eq_counts ha (pow_ne_zero _ hp.ne_zero)
have eq_zero_of_ne : ∀ q : Associates α, Irreducible q → q ≠ p → _ = 0 := fun q hq h' =>
Nat.eq_zero_of_le_zero <| by
convert count_le_count_of_le hph hq h
symm
rw [count_pow hp.ne_zero hq, count_eq_zero_of_ne hq hp h', mul_zero]
intro q hq
rw [count_pow hp.ne_zero hq]
by_cases h : q = p
· rw [h, count_self hp, mul_one]
· rw [count_eq_zero_of_ne hq hp h, mul_zero, eq_zero_of_ne q hq h]
theorem count_factors_eq_find_of_dvd_pow {a p : Associates α}
(hp : Irreducible p) [∀ n : ℕ, Decidable (a ∣ p ^ n)] {n : ℕ} (h : a ∣ p ^ n) :
@Nat.find (fun n => a ∣ p ^ n) _ ⟨n, h⟩ = p.count a.factors := by
apply le_antisymm
· refine Nat.find_le ⟨1, ?_⟩
rw [mul_one]
symm
exact eq_pow_count_factors_of_dvd_pow hp h
· have hph := pow_ne_zero (@Nat.find (fun n => a ∣ p ^ n) _ ⟨n, h⟩) hp.ne_zero
rcases subsingleton_or_nontrivial α with hα | hα
· simp [eq_iff_true_of_subsingleton] at hph
convert count_le_count_of_le hph hp (@Nat.find_spec (fun n => a ∣ p ^ n) _ ⟨n, h⟩)
rw [count_pow hp.ne_zero hp, count_self hp, mul_one]
end count
theorem eq_pow_of_mul_eq_pow {a b c : Associates α} (ha : a ≠ 0) (hb : b ≠ 0)
(hab : ∀ d, d ∣ a → d ∣ b → ¬Prime d) {k : ℕ} (h : a * b = c ^ k) :
∃ d : Associates α, a = d ^ k := by
classical
nontriviality α
by_cases hk0 : k = 0
· use 1
rw [hk0, pow_zero] at h ⊢
apply (mul_eq_one.1 h).1
· refine is_pow_of_dvd_count ha fun p hp ↦ ?_
apply dvd_count_of_dvd_count_mul hb hp hab
rw [h]
apply dvd_count_pow _ hp
rintro rfl
rw [zero_pow hk0] at h
cases mul_eq_zero.mp h <;> contradiction
/-- The only divisors of prime powers are prime powers. -/
theorem eq_pow_find_of_dvd_irreducible_pow {a p : Associates α} (hp : Irreducible p)
[∀ n : ℕ, Decidable (a ∣ p ^ n)] {n : ℕ} (h : a ∣ p ^ n) :
a = p ^ @Nat.find (fun n => a ∣ p ^ n) _ ⟨n, h⟩ := by
classical rw [count_factors_eq_find_of_dvd_pow hp, ← eq_pow_count_factors_of_dvd_pow hp h]
exact h
end Associates |
.lake/packages/mathlib/Mathlib/RingTheory/ZMod/Torsion.lean | import Mathlib.RingTheory.RootsOfUnity.EnoughRootsOfUnity
import Mathlib.FieldTheory.Finite.Basic
/-!
# Torsion group of `ZMod p` for prime `p`
This file shows that the `ZMod p` has `p - 1` roots-of-unity.
-/
namespace ZMod
lemma rootsOfUnity_eq_top {p : ℕ} [Fact p.Prime] :
(rootsOfUnity (p - 1) (ZMod p)) = ⊤ := by
ext
simpa [Units.ext_iff] using pow_card_sub_one_eq_one (Units.ne_zero _)
instance {p : ℕ} [Fact p.Prime] : HasEnoughRootsOfUnity (ZMod p) (p - 1) := by
have : NeZero (p - 1) := ⟨by have : 2 ≤ p := Nat.Prime.two_le Fact.out; grind⟩
refine HasEnoughRootsOfUnity.of_card_le ?_
have := Nat.card_congr (MulEquiv.subgroupCongr (ZMod.rootsOfUnity_eq_top (p := p))).toEquiv
rw [Nat.card_eq_fintype_card] at this
rw [this]
simp [Fintype.card_units]
end ZMod |
.lake/packages/mathlib/Mathlib/RingTheory/ZMod/UnitsCyclic.lean | import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Analysis.Normed.Ring.Lemmas
import Mathlib.Data.Nat.Choose.Dvd
import Mathlib.Data.ZMod.Units
import Mathlib.FieldTheory.Finite.Basic
/-! # Cyclicity of the units of `ZMod n`
`ZMod.isCyclic_units_iff` : `(ZMod n)ˣ` is cyclic iff
one of the following mutually exclusive cases happens:
- `n = 0` (then `ZMod 0 ≃+* ℤ` and the group of units is cyclic of order 2);
- `n = 1`, `2` or `4`
- `n` is a power `p ^ e` of an odd prime number, or twice such a power
(with `1 ≤ e`).
The individual cases are proved by `inferInstance` and are
also directly provided by :
* `ZMod.isCyclic_units_zero`
* `ZMod.isCyclic_units_one`
* `ZMod.isCyclic_units_two`
* `ZMod.isCyclic_units_four`
The case of prime numbers is also an instance:
* `ZMod.isCyclic_units_prime`
* `ZMod.not_isCyclic_units_eight`: `(ZMod 8)ˣ` is not cyclic
* `ZMod.orderOf_one_add_mul_prime`: the order of `1 + a * p`
modulo `p ^ (n + 1)` is `p ^ n` when `p` does not divide `a`.
* `ZMod.orderOf_five` : the order of `5` modulo `2 ^ (n + 3)` is `2 ^ (n + 1)`.
* `ZMod.isCyclic_units_of_prime_pow` : the case of odd prime powers
* `ZMod.isCyclic_units_two_pow_iff` : `(ZMod (2 ^ n))ˣ` is cyclic iff `n ≤ 2`.
The proofs mostly follow [Ireland and Rosen,
*A classical introduction to modern number theory*, chapter 4]
[IrelandRosen1990].
-/
open scoped Nat
namespace ZMod
section EasyCases
theorem isCyclic_units_zero :
IsCyclic (ZMod 0)ˣ := inferInstance
theorem isCyclic_units_one :
IsCyclic (ZMod 1)ˣ := inferInstance
theorem isCyclic_units_two :
IsCyclic (ZMod 2)ˣ := inferInstance
theorem isCyclic_units_four :
IsCyclic (ZMod 4)ˣ := by
apply isCyclic_of_prime_card (p := 2)
simp only [Nat.card_eq_fintype_card, card_units_eq_totient]
decide
/- The multiplicative group of `ZMod p` is cyclic. -/
theorem isCyclic_units_prime {p : ℕ} (hp : p.Prime) :
IsCyclic (ZMod p)ˣ :=
have : Fact (p.Prime) := ⟨hp⟩
inferInstance
theorem not_isCyclic_units_eight :
¬ IsCyclic (ZMod 8)ˣ := by
rw [IsCyclic.iff_exponent_eq_card, Nat.card_eq_fintype_card, card_units_eq_totient]
have h : Monoid.exponent (ZMod 8)ˣ ∣ 2 := Monoid.exponent_dvd_of_forall_pow_eq_one (by decide)
intro (h' : Monoid.exponent (ZMod 8)ˣ = 4)
simp [h'] at h
end EasyCases
section Divisibility
variable {R : Type*} [CommSemiring R] {u v : R} {p : ℕ}
lemma exists_one_add_mul_pow_prime_eq
(hp : p.Prime) (hvu : v ∣ u) (hpuv : p * u * v ∣ u ^ p) (x : R) :
∃ y, (1 + u * x) ^ p = 1 + p * u * (x + v * y) := by
rw [add_comm, add_pow]
rw [← Finset.add_sum_erase (a := 0) _ _ (by simp)]
simp_rw [one_pow, pow_zero, Nat.choose_zero_right, Nat.cast_one, mul_one]
rw [← Finset.add_sum_erase (a := 1) _ _ (by simp [hp.pos])]
rw [← Finset.sum_erase_add (a := p) _ _ (by -- aesop works but is slow
simp only [Finset.mem_erase]
rw [← and_assoc, and_comm (a := ¬ _), ← Nat.two_le_iff]
simp [hp.two_le])]
obtain ⟨a, ha⟩ := hvu
obtain ⟨b, hb⟩ := hpuv
use a * x ^ 2 * ∑ i ∈ (((Finset.range (p + 1)).erase 0).erase 1).erase p,
(u * x) ^ (i - 2) * (p.choose i / p : ℕ) + b * x ^ p
rw [mul_add]
congr 2
· rw [Nat.choose_one_right]; ring
simp only [mul_add, Finset.mul_sum]
congr 1
· congr! 1 with i hi
simp only [Finset.mem_erase, ne_eq, Finset.mem_range] at hi
have hi' : 2 ≤ i := by omega
calc
(u * x) ^ i * p.choose i =
(u * x) ^ (2 + (i - 2)) * p.choose i := by rw [Nat.add_sub_of_le hi']
_ = u ^ 2 * x ^ 2 * (u * x) ^ (i - 2) * p.choose i := by ring_nf
_ = u ^ 2 * x ^ 2 * (u * x) ^ (i - 2) * (p * (p.choose i / p) : ℕ) := by
rw [Nat.mul_div_cancel' (hp.dvd_choose_self hi.2.2.1 <| by cutsat)]
_ = u ^ 2 * x ^ 2 * (u * x) ^ (i - 2) * p * (p.choose i / p : ℕ) := by
simp only [Nat.cast_mul]; ring_nf
_ = p * u * (v * (a * x ^ 2 * ((u * x) ^ (i - 2) * (p.choose i / p : ℕ)))) := by
rw [ha]; ring
· calc
(u * x) ^ p * (p.choose p) = u ^ p * x ^ p := by simp [Nat.choose_self, mul_pow]
_ = p * u * v * b * x ^ p := by rw [hb]
_ = p * u * (v * (b * x ^ p)) := by ring_nf
lemma exists_one_add_mul_pow_prime_pow_eq {u v : R}
(hp : p.Prime) (hvu : v ∣ u) (hpuv : p * u * v ∣ u ^ p) (x : R) (m : ℕ) :
∃ y, (1 + u * x) ^ (p ^ m) = 1 + p ^ m * u * (x + v * y) :=
match m with
| 0 => ⟨0, by simp⟩
| m + 1 => by
rw [pow_succ', pow_mul]
obtain ⟨y, hy⟩ := exists_one_add_mul_pow_prime_eq hp hvu hpuv x
rw [hy]
obtain ⟨z, hz⟩ :=
exists_one_add_mul_pow_prime_pow_eq (u := p * u) (v := p * v) hp
(mul_dvd_mul_left _ hvu)
(by
rw [mul_pow]
simp only [← mul_assoc]
rw [mul_assoc, mul_assoc, ← mul_assoc u, mul_comm u]
apply mul_dvd_mul _ hpuv
rw [← pow_two]
exact pow_dvd_pow _ hp.two_le)
(x + v * y) m
use y + p * z
rw [hz]
ring
end Divisibility
section PrimePow
theorem orderOf_one_add_mul_prime_pow {p : ℕ} (hp : p.Prime) (m : ℕ) (hm0 : m ≠ 0)
(hpm : m + 2 ≤ p * m) (a : ℤ) (ha : ¬ (p : ℤ) ∣ a) (n : ℕ) :
orderOf (1 + p ^ m * a : ZMod (p ^ (n + m))) = p ^ n := by
match n with
| 0 => rw [← Nat.cast_pow, zero_add m, ZMod.natCast_self]; simp
| n + 1 =>
have := Fact.mk hp
have := exists_one_add_mul_pow_prime_pow_eq
(R := ZMod (p ^ (n + 1 + m))) (u := p ^ m) (v := p) hp (dvd_pow_self _ hm0) ?_ a
· apply orderOf_eq_prime_pow
· obtain ⟨y, hy⟩ := this n
rw [hy, ← pow_add, add_eq_left, mul_add, ← mul_assoc, ← pow_succ]
simp_rw [add_right_comm n _ 1, ← Nat.cast_pow, ZMod.natCast_self, zero_mul, add_zero]
rwa [← Int.cast_natCast, ← Int.cast_mul, ZMod.intCast_zmod_eq_zero_iff_dvd, add_right_comm,
pow_succ, Nat.cast_mul, Int.mul_dvd_mul_iff_left (by simp [hp.ne_zero])]
· obtain ⟨y, hy⟩ := this (n + 1)
rw [hy, ← pow_add, ← Nat.cast_pow]
simp
· rw [← pow_succ', ← pow_succ, ← pow_mul, mul_comm]
exact pow_dvd_pow _ hpm
theorem orderOf_one_add_mul_prime {p : ℕ} (hp : p.Prime) (hp2 : p ≠ 2) (a : ℤ)
(ha : ¬ (p : ℤ) ∣ a) (n : ℕ) :
orderOf (1 + p * a : ZMod (p ^ (n + 1))) = p ^ n := by
convert orderOf_one_add_mul_prime_pow hp 1 one_ne_zero _ a ha n using 1
· rw [pow_one]
· have := hp.two_le; cutsat
theorem orderOf_one_add_prime {p : ℕ} (hp : p.Prime) (hp2 : p ≠ 2) (n : ℕ) :
orderOf (1 + p : ZMod (p ^ (n + 1))) = p ^ n := by
convert orderOf_one_add_mul_prime hp hp2 1 _ n
· simp
· intro H
apply hp.ne_one
simpa using Int.eq_one_of_dvd_one (Int.natCast_nonneg p) H
/-- If `p` is an odd prime, then `(ZMod (p ^ n))ˣ` is cyclic for all n -/
theorem isCyclic_units_of_prime_pow (p : ℕ) (hp : p.Prime) (hp2 : p ≠ 2) (n : ℕ) :
IsCyclic (ZMod (p ^ n))ˣ := by
have _ : NeZero (p ^ n) := ⟨pow_ne_zero n hp.ne_zero⟩
have := Fact.mk hp
rcases n with _ | n
· rw [pow_zero]; infer_instance
-- We first consider the element `1 + p` of order `p ^ n`
set a := (1 + p : ZMod (p ^ (n + 1))) with ha_def
have ha : IsUnit a := by
rw [ha_def, ← Nat.cast_one (R := ZMod _), ← Nat.cast_add, ZMod.isUnit_iff_coprime]
apply Nat.Coprime.pow_right
simp only [Nat.coprime_add_self_left, Nat.coprime_one_left_eq_true]
have ha' : orderOf ha.unit = p ^ n := by
rw [← orderOf_injective _ Units.coeHom_injective ha.unit, Units.coeHom_apply, IsUnit.unit_spec]
exact orderOf_one_add_prime hp hp2 n
-- We lift a primitive root of unity mod `p`, an adequate power of which has order `p - 1`.
obtain ⟨c, hc⟩ := isCyclic_iff_exists_orderOf_eq_natCard.mp (isCyclic_units_prime hp)
rw [Nat.card_eq_fintype_card, ZMod.card_units] at hc
obtain ⟨(b : (ZMod (p ^ (n + 1)))ˣ), rfl⟩ :=
ZMod.unitsMap_surjective (Dvd.intro_left (p ^ n) rfl) c
have : p - 1 ∣ orderOf b := hc ▸ orderOf_map_dvd _ b
let k := orderOf b / (p - 1)
have : orderOf (b ^ k) = p - 1 := orderOf_pow_orderOf_div (orderOf_pos b).ne' this
rw [isCyclic_iff_exists_orderOf_eq_natCard]
-- The product of `ha.unit` and `b ^ k` has the required order
use ha.unit * b ^ k
rw [(Commute.all _ _).orderOf_mul_eq_mul_orderOf_of_coprime, this, Nat.card_eq_fintype_card,
ZMod.card_units_eq_totient, Nat.totient_prime_pow_succ hp, ← ha']
rw [ha', this]
apply Nat.Coprime.pow_left
rw [Nat.coprime_self_sub_right hp.pos]
simp
theorem isCyclic_units_two_pow_iff (n : ℕ) :
IsCyclic (ZMod (2 ^ n))ˣ ↔ n ≤ 2 := by
match n with
| 0 => simp [isCyclic_units_one]
| 1 => simp [isCyclic_units_prime Nat.prime_two]
| 2 => simp [isCyclic_units_four]
| n + 3 =>
simp only [Nat.reduceLeDiff, iff_false]
intro H
apply not_isCyclic_units_eight
have h : 2 ^ 3 ∣ 2 ^ (n + 3) := pow_dvd_pow _ (by cutsat)
exact isCyclic_of_surjective _ (unitsMap_surjective h)
lemma orderOf_one_add_four_mul (a : ℤ) (ha : Odd a) (n : ℕ) :
orderOf (1 + 4 * a : ZMod (2 ^ (n + 2))) = 2 ^ n := by
convert orderOf_one_add_mul_prime_pow Nat.prime_two 2 two_ne_zero le_rfl a ?_ n using 1
· norm_num
· rwa [← Int.not_even_iff_odd, even_iff_two_dvd] at ha
theorem orderOf_five (n : ℕ) :
orderOf (5 : ZMod (2 ^ (n + 2))) = 2 ^ n := by
convert orderOf_one_add_four_mul 1 (by simp) n
norm_num
end PrimePow
section Products
theorem isCyclic_units_four_mul_iff (n : ℕ) :
IsCyclic (ZMod (4 * n))ˣ ↔ n = 0 ∨ n = 1 := by
obtain rfl | hn0 := eq_or_ne n 0
· simp [isCyclic_units_zero]
obtain rfl | hn1 := eq_or_ne n 1
· simp [isCyclic_units_four]
refine iff_of_false ?_ (by simp [hn0, hn1])
obtain ⟨n, rfl⟩ | h2n := em (2 ∣ n)
· rw [← mul_assoc]
have : NeZero n := ⟨by simpa using hn0⟩
refine mt (fun _ ↦ ?_) not_isCyclic_units_eight
exact isCyclic_of_surjective _ (ZMod.unitsMap_surjective (m := 4 * 2 * n) (dvd_mul_right 8 _))
have : Nat.Coprime 4 n := (Nat.prime_two.coprime_iff_not_dvd.mpr h2n).pow_left 2
rw [((Units.mapEquiv (chineseRemainder this).toMulEquiv).trans .prodUnits).isCyclic,
Group.isCyclic_prod_iff]
rintro ⟨-, -, h⟩
have : NeZero n := ⟨hn0⟩
have : Odd (φ n) := by simpa [show φ 4 = 2 from rfl] using h
rw [Nat.odd_totient_iff] at this
cutsat
theorem isCyclic_units_two_mul_iff_of_odd (n : ℕ) (hn : Odd n) :
IsCyclic (ZMod (2 * n))ˣ ↔ IsCyclic (ZMod n)ˣ := by
simp [((Units.mapEquiv (chineseRemainder <| Nat.coprime_two_left.mpr hn).toMulEquiv).trans
.prodUnits).isCyclic, Group.isCyclic_prod_iff, isCyclic_units_two]
theorem not_isCyclic_units_of_mul_coprime (m n : ℕ)
(hm : Odd m) (hm1 : m ≠ 1) (hn : Odd n) (hn1 : n ≠ 1) (hmn : m.Coprime n) :
¬ IsCyclic (ZMod (m * n))ˣ := by
classical
have _ : NeZero m := ⟨Nat.ne_of_odd_add hm⟩
have _ : NeZero n := ⟨Nat.ne_of_odd_add hn⟩
let e := (Units.mapEquiv (chineseRemainder hmn).toMulEquiv).trans .prodUnits
rw [e.isCyclic, Group.isCyclic_prod_iff]
rintro ⟨-, -, h⟩
simp_rw [Nat.card_eq_fintype_card, card_units_eq_totient,
Nat.totient_coprime_totient_iff, hm1, hn1, false_or] at h
rcases h with (rfl | rfl)
· simp [← Nat.not_even_iff_odd] at hm
· simp [← Nat.not_even_iff_odd] at hn
theorem isCyclic_units_iff_of_odd {n : ℕ} (hn : Odd n) :
IsCyclic (ZMod n)ˣ ↔ ∃ (p m : ℕ), p.Prime ∧ Odd p ∧ n = p ^ m := by
have hn0 : n ≠ 0 := by rintro rfl; exact Nat.not_odd_zero hn
obtain rfl | h1 := eq_or_ne n 1
· simp_rw [isCyclic_units_one, true_iff]
exact ⟨3, 0, Nat.prime_three, by simp [Nat.odd_iff], by rw [pow_zero]⟩
have ⟨p, hp, dvd⟩ := n.exists_prime_and_dvd h1
have odd := hn.of_dvd_nat dvd
by_cases hnp : n = p ^ n.factorization p
· exact hnp ▸ iff_of_true (isCyclic_units_of_prime_pow p hp (odd.ne_two_of_dvd_nat dvd_rfl) _)
⟨p, _, hp, odd, rfl⟩
refine iff_of_false ?_ (mt ?_ hnp)
· have := n.ordProj_dvd p
rw [← Nat.mul_div_cancel' this]
refine not_isCyclic_units_of_mul_coprime _ _ (hn.of_dvd_nat this) ?_
(hn.of_dvd_nat (Nat.div_dvd_of_dvd this)) ?_ ((Nat.coprime_ordCompl hp hn0).pow_left ..)
· simpa only [Ne, pow_eq_one_iff (hp.factorization_pos_of_dvd hn0 dvd).ne'] using hp.ne_one
· contrapose! hnp
conv_lhs => rw [← Nat.div_mul_cancel this, hnp, one_mul]
rintro ⟨q, m, hq, -, rfl⟩
cases (Nat.prime_dvd_prime_iff_eq hp hq).mp (hp.dvd_of_dvd_pow dvd)
simp [hp.factorization_self] at hnp
end Products
/-- `(ZMod n)ˣ` is cyclic iff `n` is of the form
`0`, `1`, `2`, `4`, `p ^ m`, or `2 * p ^ m`,
where `p` is an odd prime and `1 ≤ m`. -/
theorem isCyclic_units_iff (n : ℕ) :
IsCyclic (ZMod n)ˣ ↔ n = 0 ∨ n = 1 ∨ n = 2 ∨ n = 4 ∨
∃ (p m : ℕ), p.Prime ∧ Odd p ∧ 1 ≤ m ∧ (n = p ^ m ∨ n = 2 * p ^ m) := by
by_cases h0 : n = 0
· rw [h0]; simp [isCyclic_units_zero]
by_cases h1 : n = 1
· rw [h1]; simp [isCyclic_units_one]
by_cases h2 : n = 2
· rw [h2]; simp [isCyclic_units_two]
by_cases h4 : n = 4
· rw [h4]; simp [isCyclic_units_four]
simp only [h0, h1, h2, h4, false_or, and_or_left, exists_or]
rcases (n.even_or_odd).symm with hn | hn
· rw [isCyclic_units_iff_of_odd hn, or_iff_left]
· congr! with p m
rw [and_iff_right_of_imp]
rintro rfl
contrapose! h1
cases Nat.lt_one_iff.mp h1
apply pow_zero
· rintro ⟨p, m, -, -, -, rfl⟩
simp [← Nat.not_even_iff_odd] at hn
obtain ⟨n, rfl⟩ := hn.two_dvd
rcases (n.even_or_odd).symm with hn | hn
· rw [isCyclic_units_two_mul_iff_of_odd _ hn, isCyclic_units_iff_of_odd hn, or_iff_right]
· congr! with p m
rw [Nat.mul_left_cancel_iff zero_lt_two, and_iff_right_of_imp]
rintro rfl
contrapose! h2
cases Nat.lt_one_iff.mp h2
rw [pow_zero, mul_one]
· rintro ⟨p, m, -, odd, -, eq⟩
have := eq ▸ odd.pow
simp [← Nat.not_even_iff_odd] at this
obtain ⟨n, rfl⟩ := hn.two_dvd
apply iff_of_false
· rw [← mul_assoc, show 2 * 2 = 4 from rfl, isCyclic_units_four_mul_iff]
cutsat
grind
end ZMod |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/EulerIdentity.lean | import Mathlib.Algebra.MvPolynomial.PDeriv
import Mathlib.RingTheory.MvPolynomial.Homogeneous
/-!
# Euler's homogeneous identity
## Main results
* `IsHomogeneous.sum_X_mul_pderiv`: Euler's identity for homogeneous polynomials:
for a multivariate homogeneous polynomial,
the product of each variable with the derivative with respect to that variable
sums up to the degree times the polynomial.
* `IsWeightedHomogeneous.sum_weight_X_mul_pderiv`: the weighted version of Euler's identity.
-/
namespace MvPolynomial
open Finsupp
variable {R σ M : Type*} [CommSemiring R] {φ : MvPolynomial σ R}
protected lemma IsWeightedHomogeneous.pderiv [AddCancelCommMonoid M] {w : σ → M} {n n' : M} {i : σ}
(h : φ.IsWeightedHomogeneous w n) (h' : n' + w i = n) :
(pderiv i φ).IsWeightedHomogeneous w n' := by
rw [← mem_weightedHomogeneousSubmodule, weightedHomogeneousSubmodule_eq_finsupp_supported,
Finsupp.supported_eq_span_single] at h
refine Submodule.span_induction ?_ ?_ (fun p q _ _ hp hq ↦ ?_) (fun r p _ h ↦ ?_) h
· rintro _ ⟨m, hm, rfl⟩
simp_rw [single_eq_monomial, pderiv_monomial, one_mul]
by_cases hi : m i = 0
· rw [hi, Nat.cast_zero, monomial_zero]; apply isWeightedHomogeneous_zero
convert isWeightedHomogeneous_monomial ..
rw [← add_right_cancel_iff (a := w i), h', ← hm, weight_sub_single_add hi]
· rw [map_zero]; apply isWeightedHomogeneous_zero
· rw [map_add]; exact hp.add hq
· rw [(pderiv i).map_smul]; exact (weightedHomogeneousSubmodule ..).smul_mem _ h
protected lemma IsHomogeneous.pderiv {n : ℕ} {i : σ} (h : φ.IsHomogeneous n) :
(pderiv i φ).IsHomogeneous (n - 1) := by
obtain _ | n := n
· rw [← totalDegree_zero_iff_isHomogeneous, totalDegree_eq_zero_iff_eq_C] at h
rw [h, pderiv_C]; apply isHomogeneous_zero
· exact IsWeightedHomogeneous.pderiv h rfl
variable [Fintype σ] {n : ℕ}
open Finset in
/-- Euler's identity for weighted homogeneous polynomials. -/
theorem IsWeightedHomogeneous.sum_weight_X_mul_pderiv {w : σ → ℕ}
(h : φ.IsWeightedHomogeneous w n) : ∑ i : σ, w i • (X i * pderiv i φ) = n • φ := by
rw [← mem_weightedHomogeneousSubmodule, weightedHomogeneousSubmodule_eq_finsupp_supported,
supported_eq_span_single] at h
refine Submodule.span_induction ?_ ?_ (fun p q _ _ hp hq ↦ ?_) (fun r p _ h ↦ ?_) h
· rintro _ ⟨m, hm, rfl⟩
simp_rw [single_eq_monomial, X_mul_pderiv_monomial, smul_smul, ← sum_smul, mul_comm (w _)]
congr
rwa [Set.mem_setOf, weight_apply, sum_fintype] at hm
intro; apply zero_smul
· simp
· simp_rw [map_add, left_distrib, smul_add, sum_add_distrib, hp, hq]
· simp_rw [(pderiv _).map_smul, nsmul_eq_mul, mul_smul_comm, ← Finset.smul_sum, ← nsmul_eq_mul, h]
/-- Euler's identity for homogeneous polynomials. -/
theorem IsHomogeneous.sum_X_mul_pderiv (h : φ.IsHomogeneous n) :
∑ i : σ, X i * pderiv i φ = n • φ := by
simp_rw [← h.sum_weight_X_mul_pderiv, Pi.one_apply, one_smul]
end MvPolynomial |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/Tower.lean | import Mathlib.Algebra.Algebra.Subalgebra.Tower
import Mathlib.Algebra.MvPolynomial.Eval
/-!
# Algebra towers for multivariate polynomial
This file proves some basic results about the algebra tower structure for the type
`MvPolynomial σ R`.
This structure itself is provided elsewhere as `MvPolynomial.isScalarTower`
When you update this file, you can also try to make a corresponding update in
`RingTheory.Polynomial.Tower`.
-/
variable (R A B : Type*) {σ : Type*}
namespace MvPolynomial
section Semiring
variable [CommSemiring R] [CommSemiring A] [CommSemiring B]
variable [Algebra R A] [Algebra A B] [Algebra R B]
variable [IsScalarTower R A B]
variable {R B}
theorem aeval_map_algebraMap (x : σ → B) (p : MvPolynomial σ R) :
aeval x (map (algebraMap R A) p) = aeval x p := by
rw [aeval_def, aeval_def, eval₂_map, IsScalarTower.algebraMap_eq R A B]
end Semiring
section CommSemiring
variable [CommSemiring R] [CommSemiring A] [CommSemiring B]
variable [Algebra R A] [Algebra A B] [Algebra R B] [IsScalarTower R A B]
variable {R A}
theorem aeval_algebraMap_apply (x : σ → A) (p : MvPolynomial σ R) :
aeval (algebraMap A B ∘ x) p = algebraMap A B (MvPolynomial.aeval x p) := by
rw [aeval_def, aeval_def, ← coe_eval₂Hom, ← coe_eval₂Hom, map_eval₂Hom, ←
IsScalarTower.algebraMap_eq, Function.comp_def]
@[simp]
lemma aeval_C_comp_left {ι : Type*} (f : σ → A) (p : MvPolynomial σ R) :
aeval (C (σ := ι) ∘ f) p = C (aeval f p) :=
aeval_algebraMap_apply ..
theorem aeval_algebraMap_eq_zero_iff [NoZeroSMulDivisors A B] [Nontrivial B] (x : σ → A)
(p : MvPolynomial σ R) : aeval (algebraMap A B ∘ x) p = 0 ↔ aeval x p = 0 := by
rw [aeval_algebraMap_apply, Algebra.algebraMap_eq_smul_one, smul_eq_zero,
iff_false_intro (one_ne_zero' B), or_false]
theorem aeval_algebraMap_eq_zero_iff_of_injective {x : σ → A} {p : MvPolynomial σ R}
(h : Function.Injective (algebraMap A B)) :
aeval (algebraMap A B ∘ x) p = 0 ↔ aeval x p = 0 := by
rw [aeval_algebraMap_apply, ← (algebraMap A B).map_zero, h.eq_iff]
end CommSemiring
end MvPolynomial
namespace Subalgebra
open MvPolynomial
section CommSemiring
variable {R A} [CommSemiring R] [CommSemiring A] [Algebra R A]
@[simp]
theorem mvPolynomial_aeval_coe (S : Subalgebra R A) (x : σ → S) (p : MvPolynomial σ R) :
aeval (fun i => (x i : A)) p = aeval x p := by convert aeval_algebraMap_apply A x p
end CommSemiring
end Subalgebra |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/Basic.lean | import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.MvPolynomial.Degrees
import Mathlib.Data.DFinsupp.Small
import Mathlib.Data.Fintype.Pi
import Mathlib.LinearAlgebra.Finsupp.VectorSpace
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
/-!
# Multivariate polynomials over commutative rings
This file contains basic facts about multivariate polynomials over commutative rings, for example
that the monomials form a basis.
## Main definitions
* `restrictTotalDegree σ R m`: the subspace of multivariate polynomials indexed by `σ` over the
commutative ring `R` of total degree at most `m`.
* `restrictDegree σ R m`: the subspace of multivariate polynomials indexed by `σ` over the
commutative ring `R` such that the degree in each individual variable is at most `m`.
## Main statements
* The multivariate polynomial ring over a commutative semiring of characteristic `p` has
characteristic `p`, and similarly for `CharZero`.
* `basisMonomials`: shows that the monomials form a basis of the vector space of multivariate
polynomials.
## TODO
Generalise to noncommutative (semi)rings
-/
noncomputable section
open Set LinearMap Module Submodule
universe u v
variable (σ : Type u) (R : Type v) [CommSemiring R] (p m : ℕ)
namespace MvPolynomial
instance {σ : Type*} {R : Type*} [CommSemiring R]
[Small.{u} R] [Small.{u} σ] :
Small.{u} (MvPolynomial σ R) :=
inferInstanceAs (Small.{u} ((σ →₀ ℕ) →₀ R))
section CharP
instance [CharP R p] : CharP (MvPolynomial σ R) p where
cast_eq_zero_iff n := by rw [← C_eq_coe_nat, ← C_0, C_inj, CharP.cast_eq_zero_iff R p]
end CharP
section CharZero
instance [CharZero R] : CharZero (MvPolynomial σ R) where
cast_injective x y hxy := by rwa [← C_eq_coe_nat, ← C_eq_coe_nat, C_inj, Nat.cast_inj] at hxy
end CharZero
section Homomorphism
theorem mapRange_eq_map {R S : Type*} [CommSemiring R] [CommSemiring S] (p : MvPolynomial σ R)
(f : R →+* S) : Finsupp.mapRange f f.map_zero p = map f p := by
rw [p.as_sum, Finsupp.mapRange_finset_sum, map_sum (map f)]
refine Finset.sum_congr rfl fun n _ => ?_
rw [map_monomial, ← single_eq_monomial, Finsupp.mapRange_single, single_eq_monomial]
end Homomorphism
section Degree
variable {σ}
/-- The submodule of polynomials that are sum of monomials in the set `s`. -/
def restrictSupport (s : Set (σ →₀ ℕ)) : Submodule R (MvPolynomial σ R) :=
Finsupp.supported _ _ s
/-- `restrictSupport R s` has a canonical `R`-basis indexed by `s`. -/
def basisRestrictSupport (s : Set (σ →₀ ℕ)) : Basis s R (restrictSupport R s) where
repr := Finsupp.supportedEquivFinsupp s
theorem restrictSupport_mono {s t : Set (σ →₀ ℕ)} (h : s ⊆ t) :
restrictSupport R s ≤ restrictSupport R t := Finsupp.supported_mono h
variable (σ)
/-- The submodule of polynomials of total degree less than or equal to `m`. -/
def restrictTotalDegree (m : ℕ) : Submodule R (MvPolynomial σ R) :=
restrictSupport R { n | (n.sum fun _ e => e) ≤ m }
/-- The submodule of polynomials such that the degree with respect to each individual variable is
less than or equal to `m`. -/
def restrictDegree (m : ℕ) : Submodule R (MvPolynomial σ R) :=
restrictSupport R { n | ∀ i, n i ≤ m }
variable {R}
theorem mem_restrictTotalDegree (p : MvPolynomial σ R) :
p ∈ restrictTotalDegree σ R m ↔ p.totalDegree ≤ m := by
rw [totalDegree, Finset.sup_le_iff]
rfl
theorem mem_restrictDegree (p : MvPolynomial σ R) (n : ℕ) :
p ∈ restrictDegree σ R n ↔ ∀ s ∈ p.support, ∀ i, (s : σ →₀ ℕ) i ≤ n := by
rw [restrictDegree, restrictSupport, Finsupp.mem_supported]
rfl
theorem mem_restrictDegree_iff_sup [DecidableEq σ] (p : MvPolynomial σ R) (n : ℕ) :
p ∈ restrictDegree σ R n ↔ ∀ i, p.degrees.count i ≤ n := by
simp only [mem_restrictDegree, degrees_def, Multiset.count_finset_sup, Finsupp.count_toMultiset,
Finset.sup_le_iff]
exact ⟨fun h n s hs => h s hs n, fun h s hs n => h n s hs⟩
variable (R)
theorem restrictTotalDegree_le_restrictDegree (m : ℕ) :
restrictTotalDegree σ R m ≤ restrictDegree σ R m :=
fun p hp ↦ (mem_restrictDegree _ _ _).mpr fun s hs i ↦ (degreeOf_le_iff.mp
(degreeOf_le_totalDegree p i) s hs).trans ((mem_restrictTotalDegree _ _ _).mp hp)
/-- The monomials form a basis on `MvPolynomial σ R`. -/
def basisMonomials : Basis (σ →₀ ℕ) R (MvPolynomial σ R) :=
Finsupp.basisSingleOne
@[simp]
theorem coe_basisMonomials :
(basisMonomials σ R : (σ →₀ ℕ) → MvPolynomial σ R) = fun s => monomial s 1 :=
rfl
/-- The `R`-module `MvPolynomial σ R` is free. -/
instance : Module.Free R (MvPolynomial σ R) :=
Module.Free.of_basis (MvPolynomial.basisMonomials σ R)
theorem linearIndependent_X : LinearIndependent R (X : σ → MvPolynomial σ R) :=
(basisMonomials σ R).linearIndependent.comp (fun s : σ => Finsupp.single s 1)
(Finsupp.single_left_injective one_ne_zero)
private lemma finite_setOf_bounded (α) [Finite α] (n : ℕ) : Finite {f : α →₀ ℕ | ∀ a, f a ≤ n} :=
((Set.Finite.pi' fun _ ↦ Set.finite_le_nat _).preimage DFunLike.coe_injective.injOn).to_subtype
instance [Finite σ] (N : ℕ) : Module.Finite R (restrictDegree σ R N) :=
have := finite_setOf_bounded σ N
Module.Finite.of_basis (basisRestrictSupport R _)
instance [Finite σ] (N : ℕ) : Module.Finite R (restrictTotalDegree σ R N) :=
have := finite_setOf_bounded σ N
have : Finite {s : σ →₀ ℕ | s.sum (fun _ e ↦ e) ≤ N} := by
rw [Set.finite_coe_iff] at this ⊢
exact this.subset fun n hn i ↦ (eq_or_ne (n i) 0).elim
(fun h ↦ h.trans_le N.zero_le) fun h ↦
(Finset.single_le_sum (fun _ _ ↦ Nat.zero_le _) <| Finsupp.mem_support_iff.mpr h).trans hn
Module.Finite.of_basis (basisRestrictSupport R _)
end Degree
end MvPolynomial |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/Ideal.lean | import Mathlib.Algebra.MonoidAlgebra.Ideal
import Mathlib.Algebra.MvPolynomial.Division
/-!
# Lemmas about ideals of `MvPolynomial`
Notably this contains results about monomial ideals.
## Main results
* `MvPolynomial.mem_ideal_span_monomial_image`
* `MvPolynomial.mem_ideal_span_X_image`
-/
variable {σ R : Type*}
namespace MvPolynomial
variable [CommSemiring R]
/-- `x` is in a monomial ideal generated by `s` iff every element of its support dominates one of
the generators. Note that `si ≤ xi` is analogous to saying that the monomial corresponding to `si`
divides the monomial corresponding to `xi`. -/
theorem mem_ideal_span_monomial_image {x : MvPolynomial σ R} {s : Set (σ →₀ ℕ)} :
x ∈ Ideal.span ((fun s => monomial s (1 : R)) '' s) ↔ ∀ xi ∈ x.support, ∃ si ∈ s, si ≤ xi := by
refine AddMonoidAlgebra.mem_ideal_span_of'_image.trans ?_
simp_rw [le_iff_exists_add, add_comm]
rfl
theorem mem_ideal_span_monomial_image_iff_dvd {x : MvPolynomial σ R} {s : Set (σ →₀ ℕ)} :
x ∈ Ideal.span ((fun s => monomial s (1 : R)) '' s) ↔
∀ xi ∈ x.support, ∃ si ∈ s, monomial si 1 ∣ monomial xi (x.coeff xi) := by
refine mem_ideal_span_monomial_image.trans (forall₂_congr fun xi hxi => ?_)
simp_rw [monomial_dvd_monomial, one_dvd, and_true, mem_support_iff.mp hxi, false_or]
/-- `x` is in a monomial ideal generated by variables `X` iff every element of its support
has a component in `s`. -/
theorem mem_ideal_span_X_image {x : MvPolynomial σ R} {s : Set σ} :
x ∈ Ideal.span (MvPolynomial.X '' s : Set (MvPolynomial σ R)) ↔
∀ m ∈ x.support, ∃ i ∈ s, (m : σ →₀ ℕ) i ≠ 0 := by
have := @mem_ideal_span_monomial_image σ R _ x ((fun i => Finsupp.single i 1) '' s)
rw [Set.image_image] at this
refine this.trans ?_
simp [Nat.one_le_iff_ne_zero]
end MvPolynomial |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/Groebner.lean | import Mathlib.Data.Finsupp.Lex
import Mathlib.Data.Finsupp.MonomialOrder
import Mathlib.Data.Finsupp.WellFounded
import Mathlib.Data.List.TFAE
import Mathlib.RingTheory.MvPolynomial.Homogeneous
import Mathlib.RingTheory.MvPolynomial.MonomialOrder
/-! # Division algorithm with respect to monomial orders
We provide a division algorithm with respect to monomial orders in polynomial rings.
Let `R` be a commutative ring, `σ` a type of indeterminates and `m : MonomialOrder σ`
a monomial ordering on `σ →₀ ℕ`.
Consider a family of polynomials `b : ι → MvPolynomial σ R` with invertible leading coefficients
(with respect to `m`) : we assume `hb : ∀ i, IsUnit (m.leadingCoeff (b i))`).
* `MonomialOrder.div hb f` furnishes
- a finitely supported family `g : ι →₀ MvPolynomial σ R`
- and a “remainder” `r : MvPolynomial σ R`
such that the three properties hold:
(1) One has `f = ∑ (g i) * (b i) + r`
(2) For every `i`, `m.degree ((g i) * (b i)` is less than or equal to that of `f`
(3) For every `i`, every monomial in the support of `r` is strictly smaller
than the leading term of `b i`,
The proof is done by induction, using two standard constructions
* `MonomialOrder.subLTerm f` deletes the leading term of a polynomial `f`
* `MonomialOrder.reduce hb f` subtracts from `f` the appropriate multiple of `b : MvPolynomial σ R`,
provided `IsUnit (m.leadingCoeff b)`.
* `MonomialOrder.div_set` is the variant of `MonomialOrder.div` for a set of polynomials.
* `MonomialOrder.div_single` is the variant of `MonomialOrder.div` for a single polynomial.
## Reference : [Becker-Weispfenning1993]
-/
namespace MonomialOrder
open MvPolynomial
open scoped MonomialOrder
variable {σ : Type*} {m : MonomialOrder σ} {R : Type*} [CommRing R]
variable (m) in
/-- Delete the leading term in a multivariate polynomial (for some monomial order) -/
noncomputable def subLTerm (f : MvPolynomial σ R) : MvPolynomial σ R :=
f - monomial (m.degree f) (m.leadingCoeff f)
theorem degree_sub_LTerm_le (f : MvPolynomial σ R) :
m.degree (m.subLTerm f) ≼[m] m.degree f := by
apply le_trans degree_sub_le
simp only [sup_le_iff, le_refl, true_and]
apply degree_monomial_le
theorem degree_sub_LTerm_lt {f : MvPolynomial σ R} (hf : m.degree f ≠ 0) :
m.degree (m.subLTerm f) ≺[m] m.degree f := by
rw [lt_iff_le_and_ne]
refine ⟨degree_sub_LTerm_le f, ?_⟩
classical
intro hf'
simp only [EmbeddingLike.apply_eq_iff_eq] at hf'
have : m.subLTerm f ≠ 0 := by
intro h
simp only [h, degree_zero] at hf'
exact hf hf'.symm
rw [← coeff_degree_ne_zero_iff (m := m), hf'] at this
apply this
simp [subLTerm, coeff_monomial, leadingCoeff]
variable (m) in
/-- Reduce a polynomial modulo a polynomial with unit leading term (for some monomial order) -/
noncomputable
def reduce {b : MvPolynomial σ R} (hb : IsUnit (m.leadingCoeff b)) (f : MvPolynomial σ R) :
MvPolynomial σ R :=
f - monomial (m.degree f - m.degree b) (hb.unit⁻¹ * m.leadingCoeff f) * b
theorem degree_reduce_lt {f b : MvPolynomial σ R} (hb : IsUnit (m.leadingCoeff b))
(hbf : m.degree b ≤ m.degree f) (hf : m.degree f ≠ 0) :
m.degree (m.reduce hb f) ≺[m] m.degree f := by
have H : m.degree f =
m.degree ((monomial (m.degree f - m.degree b)) (hb.unit⁻¹ * m.leadingCoeff f)) +
m.degree b := by
classical
rw [degree_monomial, if_neg]
· ext d
rw [tsub_add_cancel_of_le hbf]
· simp only [Units.mul_right_eq_zero, leadingCoeff_eq_zero_iff]
intro hf0
apply hf
simp [hf0]
have H' : coeff (m.degree f) (m.reduce hb f) = 0 := by
simp only [reduce, coeff_sub, sub_eq_zero]
nth_rewrite 2 [H]
rw [coeff_mul_of_degree_add (m := m), leadingCoeff_monomial, mul_comm, ← mul_assoc,
IsUnit.mul_val_inv, one_mul, ← leadingCoeff]
rw [lt_iff_le_and_ne]
constructor
· classical
apply le_trans degree_sub_le
simp only [sup_le_iff, le_refl, true_and]
apply le_of_le_of_eq degree_mul_le
rw [m.toSyn.injective.eq_iff]
exact H.symm
· intro K
simp only [EmbeddingLike.apply_eq_iff_eq] at K
nth_rewrite 1 [← K] at H'
rw [← leadingCoeff, leadingCoeff_eq_zero_iff] at H'
rw [H', degree_zero] at K
exact hf K.symm
/-- Division by a family of multivariate polynomials
whose leading coefficients are invertible with respect to a monomial order -/
theorem div {ι : Type*} {b : ι → MvPolynomial σ R}
(hb : ∀ i, IsUnit (m.leadingCoeff (b i))) (f : MvPolynomial σ R) :
∃ (g : ι →₀ (MvPolynomial σ R)) (r : MvPolynomial σ R),
f = Finsupp.linearCombination _ b g + r ∧
(∀ i, m.degree (b i * (g i)) ≼[m] m.degree f) ∧
(∀ c ∈ r.support, ∀ i, ¬ (m.degree (b i) ≤ c)) := by
by_cases! hb' : ∃ i, m.degree (b i) = 0
· obtain ⟨i, hb0⟩ := hb'
use Finsupp.single i ((hb i).unit⁻¹ • f), 0
constructor
· simp only [Finsupp.linearCombination_single, smul_eq_mul, add_zero]
simp only [smul_mul_assoc, ← smul_eq_iff_eq_inv_smul, Units.smul_isUnit]
nth_rewrite 2 [eq_C_of_degree_eq_zero hb0]
rw [mul_comm, smul_eq_C_mul]
constructor
· intro j
by_cases hj : j = i
· apply le_trans degree_mul_le
simp only [hj, hb0, Finsupp.single_eq_same, zero_add]
apply le_of_eq
simp only [EmbeddingLike.apply_eq_iff_eq]
apply degree_smul (Units.isRegular _)
· simp only [Finsupp.single_eq_of_ne hj, mul_zero, degree_zero, map_zero]
apply bot_le
· simp
by_cases hf0 : f = 0
· refine ⟨0, 0, by simp [hf0], ?_, by simp⟩
intro b
simp only [Finsupp.coe_zero, Pi.zero_apply, mul_zero, degree_zero, map_zero]
exact bot_le
by_cases! hf : ∃ i, m.degree (b i) ≤ m.degree f
· obtain ⟨i, hf⟩ := hf
have deg_reduce : m.degree (m.reduce (hb i) f) ≺[m] m.degree f := by
apply degree_reduce_lt (hb i) hf
intro hf0'
apply hb' i
simpa [hf0'] using hf
obtain ⟨g', r', H'⟩ := div hb (m.reduce (hb i) f)
use g' +
Finsupp.single i (monomial (m.degree f - m.degree (b i)) ((hb i).unit⁻¹ * m.leadingCoeff f))
use r'
constructor
· rw [map_add, add_assoc, add_comm _ r', ← add_assoc, ← H'.1]
simp [reduce]
constructor
· rintro j
simp only [Finsupp.coe_add, Pi.add_apply]
rw [mul_add]
apply le_trans degree_add_le
simp only [sup_le_iff]
constructor
· exact le_trans (H'.2.1 _) (le_of_lt deg_reduce)
· classical
rw [Finsupp.single_apply]
split_ifs with hc
· subst j
grw [degree_mul_le, map_add, degree_monomial_le, ← map_add, add_tsub_cancel_of_le hf]
· simp only [mul_zero, degree_zero, map_zero]
exact bot_le
· exact H'.2.2
· suffices ∃ (g' : ι →₀ MvPolynomial σ R), ∃ r',
(m.subLTerm f = Finsupp.linearCombination (MvPolynomial σ R) b g' + r') ∧
(∀ i, m.degree ((b i) * (g' i)) ≼[m] m.degree (m.subLTerm f)) ∧
(∀ c ∈ r'.support, ∀ i, ¬ m.degree (b i) ≤ c) by
obtain ⟨g', r', H'⟩ := this
use g', r' + monomial (m.degree f) (m.leadingCoeff f)
constructor
· simp [← add_assoc, ← H'.1, subLTerm]
constructor
· exact fun b ↦ le_trans (H'.2.1 b) (degree_sub_LTerm_le f)
· intro c hc i
by_cases hc' : c ∈ r'.support
· exact H'.2.2 c hc' i
· convert hf i
classical
have := MvPolynomial.support_add hc
rw [Finset.mem_union, Classical.or_iff_not_imp_left] at this
simpa only [Finset.mem_singleton] using support_monomial_subset (this hc')
by_cases hf'0 : m.subLTerm f = 0
· refine ⟨0, 0, by simp [hf'0], ?_, by simp⟩
intro b
simp only [Finsupp.coe_zero, Pi.zero_apply, mul_zero, degree_zero, map_zero]
exact bot_le
· exact (div hb) (m.subLTerm f)
termination_by WellFounded.wrap
((isWellFounded_iff m.syn fun x x_1 ↦ x < x_1).mp m.wf) (m.toSyn (m.degree f))
decreasing_by
· exact deg_reduce
· apply degree_sub_LTerm_lt
intro hf0
apply hf'0
simp only [subLTerm, sub_eq_zero]
nth_rewrite 1 [eq_C_of_degree_eq_zero hf0, hf0]
simp
/-- Division by a *set* of multivariate polynomials
whose leading coefficients are invertible with respect to a monomial order -/
theorem div_set {B : Set (MvPolynomial σ R)}
(hB : ∀ b ∈ B, IsUnit (m.leadingCoeff b)) (f : MvPolynomial σ R) :
∃ (g : B →₀ (MvPolynomial σ R)) (r : MvPolynomial σ R),
f = Finsupp.linearCombination _ (fun (b : B) ↦ (b : MvPolynomial σ R)) g + r ∧
(∀ (b : B), m.degree ((b : MvPolynomial σ R) * (g b)) ≼[m] m.degree f) ∧
(∀ c ∈ r.support, ∀ b ∈ B, ¬ (m.degree b ≤ c)) := by
obtain ⟨g, r, H⟩ := m.div (b := fun (p : B) ↦ p) (fun b ↦ hB b b.prop) f
exact ⟨g, r, H.1, H.2.1, fun c hc b hb ↦ H.2.2 c hc ⟨b, hb⟩⟩
/-- Division by a multivariate polynomial
whose leading coefficient is invertible with respect to a monomial order -/
theorem div_single {b : MvPolynomial σ R}
(hb : IsUnit (m.leadingCoeff b)) (f : MvPolynomial σ R) :
∃ (g : MvPolynomial σ R) (r : MvPolynomial σ R),
f = g * b + r ∧
(m.degree (b * g) ≼[m] m.degree f) ∧
(∀ c ∈ r.support, ¬ (m.degree b ≤ c)) := by
obtain ⟨g, r, hgr, h1, h2⟩ := div_set (B := {b}) (m := m) (by simp [hb]) f
specialize h1 ⟨b, by simp⟩
set q := g ⟨b, by simp⟩
simp only [Set.mem_singleton_iff, forall_eq] at h2
simp only at h1
refine ⟨q, r, ?_, h1, h2⟩
rw [hgr]
simp only [Finsupp.linearCombination, Finsupp.coe_lsum, LinearMap.coe_smulRight, LinearMap.id_coe,
id_eq, smul_eq_mul, add_left_inj]
rw [Finsupp.sum_eq_single ⟨b, by simp⟩ _ (by simp)]
simp +contextual
end MonomialOrder |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/FreeCommRing.lean | import Mathlib.RingTheory.FreeCommRing
/-!
# Constructing Ring terms from MvPolynomial
This file provides tools for constructing ring terms that can be evaluated to particular
`MvPolynomial`s. The main motivation is in model theory. It can be used to construct first-order
formulas whose realization is a property of an `MvPolynomial`
## Main definitions
* `FirstOrder.Ring.genericPolyMap` is a function that given a finite set of monomials
`monoms : ι → Finset (κ →₀ ℕ)` returns a function `ι → FreeCommRing ((Σ i : ι, monoms i) ⊕ κ)`
such that `genericPolyMap monoms i` is a ring term that can be evaluated to a polynomial
`p : MvPolynomial κ R` such that `p.support ⊆ monoms i`.
-/
assert_not_exists Cardinal
variable {ι κ R : Type*}
namespace FirstOrder
namespace Ring
open MvPolynomial FreeCommRing
/-- Given a finite set of monomials `monoms : ι → Finset (κ →₀ ℕ)`, the
`genericPolyMap monoms` is an indexed collection of elements of the `FreeCommRing`,
that can be evaluated to any collection `p : ι → MvPolynomial κ R` of
polynomials such that `∀ i, (p i).support ⊆ monoms i`. -/
def genericPolyMap (monoms : ι → Finset (κ →₀ ℕ)) :
ι → FreeCommRing ((Σ i : ι, monoms i) ⊕ κ) :=
fun i => (monoms i).attach.sum
(fun m => FreeCommRing.of (Sum.inl ⟨i, m⟩) *
Finsupp.prod m.1 (fun j n => FreeCommRing.of (Sum.inr j)^ n))
/-- Collections of `MvPolynomial`s, `p : ι → MvPolynomial κ R` such
that `∀ i, (p i).support ⊆ monoms i` can be identified with functions
`(Σ i, monoms i) → R` by using the coefficient function -/
noncomputable def mvPolynomialSupportLEEquiv
[DecidableEq κ] [CommRing R] [DecidableEq R]
(monoms : ι → Finset (κ →₀ ℕ)) :
{ p : ι → MvPolynomial κ R // ∀ i, (p i).support ⊆ monoms i } ≃
((Σ i, monoms i) → R) :=
{ toFun := fun p i => (p.1 i.1).coeff i.2,
invFun := fun p => ⟨fun i =>
{ toFun := fun m => if hm : m ∈ monoms i then p ⟨i, ⟨m, hm⟩⟩ else 0
support := {m ∈ monoms i | ∃ hm : m ∈ monoms i, p ⟨i, ⟨m, hm⟩⟩ ≠ 0},
mem_support_toFun := by simp },
fun i => Finset.filter_subset _ _⟩,
left_inv := fun p => by
ext i m
simp only [coeff, ne_eq, exists_prop, dite_eq_ite, Finsupp.coe_mk, ite_eq_left_iff]
intro hm
have : m ∉ (p.1 i).support := fun h => hm (p.2 i h)
simpa [coeff, eq_comm, MvPolynomial.mem_support_iff] using this
right_inv := fun p => by ext; simp [coeff] }
@[simp]
theorem MvPolynomialSupportLEEquiv_symm_apply_coeff [DecidableEq κ] [CommRing R] [DecidableEq R]
(p : ι → MvPolynomial κ R) : (mvPolynomialSupportLEEquiv (fun i => (p i).support)).symm
(fun i => (p i.1).coeff i.2.1) = ⟨p, fun _ => Finset.Subset.refl _⟩ :=
(mvPolynomialSupportLEEquiv (R := R) (fun i : ι => (p i).support)).symm_apply_apply
⟨p, fun _ => Finset.Subset.refl _⟩
@[simp]
theorem lift_genericPolyMap [DecidableEq κ] [CommRing R]
[DecidableEq R] (monoms : ι → Finset (κ →₀ ℕ))
(f : (i : ι) × { x // x ∈ monoms i } ⊕ κ → R) (i : ι) :
FreeCommRing.lift f (genericPolyMap monoms i) =
MvPolynomial.eval (f ∘ Sum.inr)
(((mvPolynomialSupportLEEquiv monoms).symm
(f ∘ Sum.inl)).1 i) := by
simp only [genericPolyMap, map_sum, map_mul, lift_of, support,
mvPolynomialSupportLEEquiv, coeff, Finset.sum_filter, MvPolynomial.eval_eq,
ne_eq, Function.comp, Equiv.coe_fn_symm_mk, Finsupp.coe_mk]
conv_rhs => rw [← Finset.sum_attach]
refine Finset.sum_congr rfl ?_
intro m _
simp only [Finsupp.prod, map_prod, map_pow, lift_of, Subtype.coe_eta, Finset.coe_mem,
exists_prop, true_and, dite_eq_ite, ite_true, ite_not]
split_ifs with h0 <;> simp_all
end Ring
end FirstOrder |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/Localization.lean | import Mathlib.Algebra.Module.LocalizedModule.IsLocalization
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.RingTheory.Ideal.Quotient.Operations
import Mathlib.RingTheory.Localization.Away.Basic
import Mathlib.RingTheory.Localization.BaseChange
import Mathlib.RingTheory.TensorProduct.MvPolynomial
/-!
# Localization and multivariate polynomial rings
In this file we show some results connecting multivariate polynomial rings and localization.
## Main results
- `MvPolynomial.isLocalization`: If `S` is the localization of `R` at a submonoid `M`, then
`MvPolynomial σ S` is the localization of `MvPolynomial σ R` at the image of `M` in
`MvPolynomial σ R`.
-/
variable {σ R : Type*} [CommRing R] (M : Submonoid R)
variable (S : Type*) [CommRing S] [Algebra R S]
namespace MvPolynomial
variable [IsLocalization M S]
attribute [local instance] algebraMvPolynomial
/--
If `S` is the localization of `R` at a submonoid `M`, then `MvPolynomial σ S`
is the localization of `MvPolynomial σ R` at `M.map MvPolynomial.C`.
See also `Polynomial.isLocalization` for the univariate case. -/
instance isLocalization : IsLocalization (M.map <| C (σ := σ)) (MvPolynomial σ S) :=
isLocalizedModule_iff_isLocalization.mp <| (isLocalizedModule_iff_isBaseChange M S _).mpr <|
.of_equiv (algebraTensorAlgEquiv _ _).toLinearEquiv fun _ ↦ by simp
lemma isLocalization_C_mk' (a : R) (m : M) :
C (IsLocalization.mk' S a m) = IsLocalization.mk' (MvPolynomial σ S) (C (σ := σ) a)
⟨C m, Submonoid.mem_map_of_mem C m.property⟩ := by
simp_rw [IsLocalization.eq_mk'_iff_mul_eq, algebraMap_def, map_C, ← map_mul,
IsLocalization.mk'_spec]
end MvPolynomial
namespace IsLocalization.Away
open MvPolynomial
variable (r : R) [IsLocalization.Away r S]
/-- The canonical algebra map from `MvPolynomial Unit R` quotiented by
`C r * X () - 1` to the localization of `R` away from `r`. -/
private noncomputable
def auxHom : (MvPolynomial Unit R) ⧸ (Ideal.span { C r * X () - 1 }) →ₐ[R] S :=
Ideal.Quotient.liftₐ (Ideal.span { C r * X () - 1}) (aeval (fun _ ↦ invSelf r)) <| by
intro p hp
refine Submodule.span_induction ?_ ?_ ?_ ?_ hp
· rintro p ⟨q, rfl⟩
simp
· simp
· intro p q _ _ hp hq
simp [hp, hq]
· intro a x _ hx
simp [hx]
@[simp]
private lemma auxHom_mk (p : MvPolynomial Unit R) :
auxHom S r p = aeval (S₁ := S) (fun _ ↦ invSelf r) p :=
rfl
private noncomputable
def auxInv : S →+* (MvPolynomial Unit R) ⧸ Ideal.span { C r * X () - 1 } :=
letI g : R →+* MvPolynomial Unit R ⧸ (Ideal.span { C r * X () - 1 }) :=
(Ideal.Quotient.mk _).comp C
IsLocalization.Away.lift (S := S) (g := g) r <| by
simp only [RingHom.coe_comp, Function.comp_apply, g]
rw [isUnit_iff_exists_inv]
use (Ideal.Quotient.mk _ <| X ())
rw [← map_mul, ← map_one (Ideal.Quotient.mk _), Ideal.Quotient.mk_eq_mk_iff_sub_mem]
exact Ideal.mem_span_singleton_self (C r * X () - 1)
private lemma auxHom_auxInv : (auxHom S r).toRingHom.comp (auxInv S r) = RingHom.id S := by
apply IsLocalization.ringHom_ext (Submonoid.powers r)
ext x
simp [auxInv]
private lemma auxInv_auxHom : (auxInv S r).comp (auxHom (S := S) r).toRingHom = RingHom.id _ := by
rw [← RingHom.cancel_right (Ideal.Quotient.mk_surjective)]
ext x
· simp [auxInv]
· simp only [auxInv, AlgHom.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe,
Function.comp_apply, auxHom_mk, aeval_X, RingHomCompTriple.comp_eq, invSelf, Away.lift,
lift_mk'_spec]
simp only [map_one]
rw [← map_one (Ideal.Quotient.mk _), ← map_mul, Ideal.Quotient.mk_eq_mk_iff_sub_mem,
← Ideal.neg_mem_iff, neg_sub]
exact Ideal.mem_span_singleton_self (C r * X x - 1)
/-- The canonical algebra isomorphism from `MvPolynomial Unit R` quotiented by
`C r * X () - 1` to the localization of `R` away from `r`. -/
noncomputable def mvPolynomialQuotientEquiv :
((MvPolynomial Unit R) ⧸ Ideal.span { C r * X () - 1 }) ≃ₐ[R] S where
toFun := auxHom S r
invFun := auxInv S r
left_inv x := by
simpa using congrFun (congrArg DFunLike.coe <| auxInv_auxHom S r) x
right_inv s := by
simpa using congrFun (congrArg DFunLike.coe <| auxHom_auxInv S r) s
map_mul' := by simp
map_add' := by simp
commutes' := by simp
@[simp]
lemma mvPolynomialQuotientEquiv_apply (p : MvPolynomial Unit R) :
mvPolynomialQuotientEquiv S r (Ideal.Quotient.mk _ p) = aeval (S₁ := S) (fun _ ↦ invSelf r) p :=
rfl
end IsLocalization.Away |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/Homogeneous.lean | import Mathlib.Algebra.DirectSum.Internal
import Mathlib.Algebra.GradedMonoid
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.Algebra.MvPolynomial.Equiv
import Mathlib.Algebra.MvPolynomial.Variables
import Mathlib.Algebra.Polynomial.Roots
import Mathlib.RingTheory.MvPolynomial.WeightedHomogeneous
import Mathlib.SetTheory.Cardinal.Basic
/-!
# Homogeneous polynomials
A multivariate polynomial `φ` is homogeneous of degree `n`
if all monomials occurring in `φ` have degree `n`.
## Main definitions/lemmas
* `IsHomogeneous φ n`: a predicate that asserts that `φ` is homogeneous of degree `n`.
* `homogeneousSubmodule σ R n`: the submodule of homogeneous polynomials of degree `n`.
* `homogeneousComponent n`: the additive morphism that projects polynomials onto
their summand that is homogeneous of degree `n`.
* `sum_homogeneousComponent`: every polynomial is the sum of its homogeneous components.
-/
namespace MvPolynomial
variable {σ : Type*} {τ : Type*} {R : Type*} {S : Type*}
/-
TODO
* show that `MvPolynomial σ R ≃ₐ[R] ⨁ i, homogeneousSubmodule σ R i`
-/
open Finsupp
/-- A multivariate polynomial `φ` is homogeneous of degree `n`
if all monomials occurring in `φ` have degree `n`. -/
def IsHomogeneous [CommSemiring R] (φ : MvPolynomial σ R) (n : ℕ) :=
IsWeightedHomogeneous 1 φ n
variable [CommSemiring R]
theorem weightedTotalDegree_one (φ : MvPolynomial σ R) :
weightedTotalDegree (1 : σ → ℕ) φ = φ.totalDegree := by
simp only [totalDegree, weightedTotalDegree, weight, LinearMap.toAddMonoidHom_coe,
linearCombination, Pi.one_apply, Finsupp.coe_lsum, LinearMap.coe_smulRight, LinearMap.id_coe,
id, Algebra.id.smul_eq_mul, mul_one]
theorem weightedTotalDegree_rename_of_injective {σ τ : Type*} {e : σ → τ}
{w : τ → ℕ} {P : MvPolynomial σ R} (he : Function.Injective e) :
weightedTotalDegree w (rename e P) = weightedTotalDegree (w ∘ e) P := by
classical
unfold weightedTotalDegree
rw [support_rename_of_injective he, Finset.sup_image]
congr; ext; unfold weight; simp
variable (σ R)
/-- The submodule of homogeneous `MvPolynomial`s of degree `n`. -/
def homogeneousSubmodule (n : ℕ) : Submodule R (MvPolynomial σ R) where
carrier := { x | x.IsHomogeneous n }
smul_mem' r a ha c hc := by
rw [coeff_smul] at hc
apply ha
intro h
apply hc
rw [h]
exact smul_zero r
zero_mem' _ hd := False.elim (hd <| coeff_zero _)
add_mem' {a b} ha hb c hc := by
rw [coeff_add] at hc
obtain h | h : coeff c a ≠ 0 ∨ coeff c b ≠ 0 := by
contrapose! hc
simp only [hc, add_zero]
· exact ha h
· exact hb h
@[simp]
lemma weightedHomogeneousSubmodule_one (n : ℕ) :
weightedHomogeneousSubmodule R 1 n = homogeneousSubmodule σ R n := rfl
variable {σ R}
@[simp]
theorem mem_homogeneousSubmodule (n : ℕ) (p : MvPolynomial σ R) :
p ∈ homogeneousSubmodule σ R n ↔ p.IsHomogeneous n := Iff.rfl
variable (σ R)
/-- While equal, the former has a convenient definitional reduction. -/
theorem homogeneousSubmodule_eq_finsupp_supported (n : ℕ) :
homogeneousSubmodule σ R n = Finsupp.supported _ R { d | d.degree = n } := by
simp_rw [degree_eq_weight_one]
exact weightedHomogeneousSubmodule_eq_finsupp_supported R 1 n
variable {σ R}
theorem homogeneousSubmodule_mul (m n : ℕ) :
homogeneousSubmodule σ R m * homogeneousSubmodule σ R n ≤ homogeneousSubmodule σ R (m + n) :=
weightedHomogeneousSubmodule_mul 1 m n
section
theorem isHomogeneous_monomial {d : σ →₀ ℕ} (r : R) {n : ℕ} (hn : d.degree = n) :
IsHomogeneous (monomial d r) n := by
rw [degree_eq_weight_one] at hn
exact isWeightedHomogeneous_monomial 1 d r hn
variable (σ)
theorem totalDegree_eq_zero_iff (p : MvPolynomial σ R) :
p.totalDegree = 0 ↔ ∀ (m : σ →₀ ℕ) (_ : m ∈ p.support) (x : σ), m x = 0 := by
rw [← weightedTotalDegree_one, weightedTotalDegree_eq_zero_iff _ p]
exact nonTorsionWeight_of (Function.const σ one_ne_zero)
theorem totalDegree_zero_iff_isHomogeneous {p : MvPolynomial σ R} :
p.totalDegree = 0 ↔ IsHomogeneous p 0 := by
rw [← weightedTotalDegree_one,
← isWeightedHomogeneous_zero_iff_weightedTotalDegree_eq_zero, IsHomogeneous]
alias ⟨isHomogeneous_of_totalDegree_zero, _⟩ := totalDegree_zero_iff_isHomogeneous
theorem isHomogeneous_C (r : R) : IsHomogeneous (C r : MvPolynomial σ R) 0 := by
apply isHomogeneous_monomial
simp only [Finsupp.degree, Finsupp.zero_apply, Finset.sum_const_zero]
variable (R)
theorem isHomogeneous_zero (n : ℕ) : IsHomogeneous (0 : MvPolynomial σ R) n :=
(homogeneousSubmodule σ R n).zero_mem
theorem isHomogeneous_one : IsHomogeneous (1 : MvPolynomial σ R) 0 :=
isHomogeneous_C _ _
variable {σ}
theorem isHomogeneous_X (i : σ) : IsHomogeneous (X i : MvPolynomial σ R) 1 := by
apply isHomogeneous_monomial
rw [Finsupp.degree, Finsupp.support_single_ne_zero _ one_ne_zero, Finset.sum_singleton]
exact Finsupp.single_eq_same
end
namespace IsHomogeneous
variable [CommSemiring S] {φ ψ : MvPolynomial σ R} {m n : ℕ}
theorem coeff_eq_zero (hφ : IsHomogeneous φ n) {d : σ →₀ ℕ} (hd : d.degree ≠ n) :
coeff d φ = 0 := by
rw [degree_eq_weight_one] at hd
exact IsWeightedHomogeneous.coeff_eq_zero hφ d hd
theorem inj_right (hm : IsHomogeneous φ m) (hn : IsHomogeneous φ n) (hφ : φ ≠ 0) : m = n := by
obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero hφ
rw [← hm hd, ← hn hd]
theorem add (hφ : IsHomogeneous φ n) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ + ψ) n :=
(homogeneousSubmodule σ R n).add_mem hφ hψ
theorem sum {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ℕ)
(h : ∀ i ∈ s, IsHomogeneous (φ i) n) : IsHomogeneous (∑ i ∈ s, φ i) n :=
(homogeneousSubmodule σ R n).sum_mem h
theorem mul (hφ : IsHomogeneous φ m) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ * ψ) (m + n) :=
homogeneousSubmodule_mul m n <| Submodule.mul_mem_mul hφ hψ
theorem prod {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ι → ℕ)
(h : ∀ i ∈ s, IsHomogeneous (φ i) (n i)) : IsHomogeneous (∏ i ∈ s, φ i) (∑ i ∈ s, n i) := by
classical
revert h
refine Finset.induction_on s ?_ ?_
· intro
simp only [isHomogeneous_one, Finset.sum_empty, Finset.prod_empty]
· intro i s his IH h
simp only [his, Finset.prod_insert, Finset.sum_insert, not_false_iff]
apply (h i (by grind)).mul (IH _)
grind
lemma C_mul (hφ : φ.IsHomogeneous m) (r : R) :
(C r * φ).IsHomogeneous m := by
simpa only [zero_add] using (isHomogeneous_C _ _).mul hφ
lemma _root_.MvPolynomial.isHomogeneous_C_mul_X (r : R) (i : σ) :
(C r * X i).IsHomogeneous 1 :=
(isHomogeneous_X _ _).C_mul _
lemma pow (hφ : φ.IsHomogeneous m) (n : ℕ) : (φ ^ n).IsHomogeneous (m * n) := by
rw [show φ ^ n = ∏ _i ∈ Finset.range n, φ by simp]
rw [show m * n = ∑ _i ∈ Finset.range n, m by simp [mul_comm]]
apply IsHomogeneous.prod _ _ _ (fun _ _ ↦ hφ)
lemma _root_.MvPolynomial.isHomogeneous_X_pow (i : σ) (n : ℕ) :
(X (R := R) i ^ n).IsHomogeneous n := by
simpa only [one_mul] using (isHomogeneous_X _ _).pow n
lemma _root_.MvPolynomial.isHomogeneous_C_mul_X_pow (r : R) (i : σ) (n : ℕ) :
(C r * X i ^ n).IsHomogeneous n :=
(isHomogeneous_X_pow _ _).C_mul _
lemma eval₂ (hφ : φ.IsHomogeneous m) (f : R →+* MvPolynomial τ S) (g : σ → MvPolynomial τ S)
(hf : ∀ r, (f r).IsHomogeneous 0) (hg : ∀ i, (g i).IsHomogeneous n) :
(eval₂ f g φ).IsHomogeneous (n * m) := by
apply IsHomogeneous.sum
intro i hi
rw [← zero_add (n * m)]
apply IsHomogeneous.mul (hf _) _
convert IsHomogeneous.prod _ _ (fun k ↦ n * i k) _
· rw [Finsupp.mem_support_iff] at hi
rw [← Finset.mul_sum, ← hφ hi, weight_apply]
simp_rw [smul_eq_mul, Finsupp.sum, Pi.one_apply, mul_one]
· rintro k -
apply (hg k).pow
lemma map (hφ : φ.IsHomogeneous n) (f : R →+* S) : (map f φ).IsHomogeneous n := by
simpa only [one_mul] using hφ.eval₂ _ _ (fun r ↦ isHomogeneous_C _ (f r)) (isHomogeneous_X _)
lemma aeval [Algebra R S] (hφ : φ.IsHomogeneous m)
(g : σ → MvPolynomial τ S) (hg : ∀ i, (g i).IsHomogeneous n) :
(aeval g φ).IsHomogeneous (n * m) :=
hφ.eval₂ _ _ (fun _ ↦ isHomogeneous_C _ _) hg
section CommRing
-- In this section we shadow the semiring `R` with a ring `R`.
variable {R σ : Type*} [CommRing R] {φ ψ : MvPolynomial σ R} {n : ℕ}
theorem neg (hφ : IsHomogeneous φ n) : IsHomogeneous (-φ) n :=
(homogeneousSubmodule σ R n).neg_mem hφ
theorem sub (hφ : IsHomogeneous φ n) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ - ψ) n :=
(homogeneousSubmodule σ R n).sub_mem hφ hψ
end CommRing
/-- The homogeneous degree bounds the total degree.
See also `MvPolynomial.IsHomogeneous.totalDegree` when `φ` is non-zero. -/
lemma totalDegree_le (hφ : IsHomogeneous φ n) : φ.totalDegree ≤ n := by
apply Finset.sup_le
intro d hd
rw [mem_support_iff] at hd
simp_rw [Finsupp.sum, ← hφ hd, weight_apply, Pi.one_apply, smul_eq_mul, mul_one, Finsupp.sum,
le_rfl]
theorem totalDegree (hφ : IsHomogeneous φ n) (h : φ ≠ 0) : totalDegree φ = n := by
apply le_antisymm hφ.totalDegree_le
obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero h
simp only [← hφ hd, MvPolynomial.totalDegree, Finsupp.sum]
replace hd := Finsupp.mem_support_iff.mpr hd
simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one]
-- Porting note: Original proof did not define `f`
exact Finset.le_sup (f := fun s ↦ ∑ x ∈ s.support, s x) hd
theorem rename_isHomogeneous {f : σ → τ} (h : φ.IsHomogeneous n) :
(rename f φ).IsHomogeneous n := by
rw [← φ.support_sum_monomial_coeff, map_sum]; simp_rw [rename_monomial]
apply IsHomogeneous.sum _ _ _ fun d hd ↦ isHomogeneous_monomial _ _
intro d hd
apply (Finsupp.sum_mapDomain_index_addMonoidHom fun _ ↦ .id ℕ).trans
convert h (mem_support_iff.mp hd)
simp only [weight_apply, AddMonoidHom.id_apply, Pi.one_apply, smul_eq_mul, mul_one]
theorem rename_isHomogeneous_iff {f : σ → τ} (hf : f.Injective) :
(rename f φ).IsHomogeneous n ↔ φ.IsHomogeneous n := by
refine ⟨fun h d hd ↦ ?_, rename_isHomogeneous⟩
convert ← @h (d.mapDomain f) _
· simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one]
exact Finsupp.sum_mapDomain_index_inj (h := fun _ ↦ id) hf
· rwa [coeff_rename_mapDomain f hf]
lemma finSuccEquiv_coeff_isHomogeneous {N : ℕ} {φ : MvPolynomial (Fin (N + 1)) R} {n : ℕ}
(hφ : φ.IsHomogeneous n) (i j : ℕ) (h : i + j = n) :
((finSuccEquiv _ _ φ).coeff i).IsHomogeneous j := by
intro d hd
rw [finSuccEquiv_coeff_coeff] at hd
have h' : (weight 1) (Finsupp.cons i d) = i + j := by
simpa [Finset.sum_subset_zero_on_sdiff (g := d.cons i)
(d.cons_support (y := i)) (by simp) (fun _ _ ↦ rfl), ← h] using hφ hd
simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one, Finsupp.sum_cons,
add_right_inj] at h' ⊢
exact h'
-- TODO: develop API for `optionEquivLeft` and get rid of the `[Fintype σ]` assumption
lemma coeff_isHomogeneous_of_optionEquivLeft_symm
[hσ : Finite σ] {p : Polynomial (MvPolynomial σ R)}
(hp : ((optionEquivLeft R σ).symm p).IsHomogeneous n) (i j : ℕ) (h : i + j = n) :
(p.coeff i).IsHomogeneous j := by
obtain ⟨k, ⟨e⟩⟩ := Finite.exists_equiv_fin σ
let e' := e.optionCongr.trans (_root_.finSuccEquiv _).symm
let F := renameEquiv R e
let F' := renameEquiv R e'
let φ := F' ((optionEquivLeft R σ).symm p)
have hφ : φ.IsHomogeneous n := hp.rename_isHomogeneous
suffices IsHomogeneous (F (p.coeff i)) j by
rwa [← (IsHomogeneous.rename_isHomogeneous_iff e.injective)]
convert hφ.finSuccEquiv_coeff_isHomogeneous i j h using 1
dsimp only [φ, F', F, renameEquiv_apply]
rw [finSuccEquiv_rename_finSuccEquiv, AlgEquiv.apply_symm_apply]
simp
open Polynomial in
private
lemma exists_eval_ne_zero_of_coeff_finSuccEquiv_ne_zero_aux
{N : ℕ} {F : MvPolynomial (Fin (Nat.succ N)) R} {n : ℕ} (hF : IsHomogeneous F n)
(hFn : ((finSuccEquiv R N) F).coeff n ≠ 0) :
∃ r, eval r F ≠ 0 := by
have hF₀ : F ≠ 0 := by contrapose! hFn; simp [hFn]
have hdeg : natDegree (finSuccEquiv R N F) < n + 1 := by
linarith [natDegree_finSuccEquiv F, degreeOf_le_totalDegree F 0, hF.totalDegree hF₀]
use Fin.cons 1 0
have aux : ∀ i ∈ Finset.range n, constantCoeff ((finSuccEquiv R N F).coeff i) = 0 := by
intro i hi
rw [Finset.mem_range] at hi
apply (hF.finSuccEquiv_coeff_isHomogeneous i (n-i) (by cutsat)).coeff_eq_zero
simp only [Finsupp.degree_zero]
rw [← Nat.sub_ne_zero_iff_lt] at hi
exact hi.symm
simp_rw [eval_eq_eval_mv_eval', eval_one_map, Polynomial.eval_eq_sum_range' hdeg,
eval_zero, one_pow, mul_one, map_sum, Finset.sum_range_succ, Finset.sum_eq_zero aux, zero_add]
contrapose! hFn
ext d
rw [coeff_zero]
obtain rfl | hd := eq_or_ne d 0
· apply hFn
· contrapose! hd
ext i
rw [Finsupp.coe_zero, Pi.zero_apply]
by_cases hi : i ∈ d.support
· have := hF.finSuccEquiv_coeff_isHomogeneous n 0 (add_zero _) hd
simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one, Finsupp.sum] at this
rw [Finset.sum_eq_zero_iff_of_nonneg (fun _ _ ↦ zero_le')] at this
exact this i hi
· simpa using hi
section IsDomain
-- In this section we shadow the semiring `R` with a domain `R`.
variable {R σ : Type*} [CommRing R] [IsDomain R] {F G : MvPolynomial σ R} {n : ℕ}
open Cardinal Polynomial
private
lemma exists_eval_ne_zero_of_totalDegree_le_card_aux {N : ℕ} {F : MvPolynomial (Fin N) R} {n : ℕ}
(hF : F.IsHomogeneous n) (hF₀ : F ≠ 0) (hnR : n ≤ #R) :
∃ r, eval r F ≠ 0 := by
induction N generalizing n with
| zero =>
use 0
contrapose! hF₀
ext d
simpa only [Subsingleton.elim d 0, eval_zero, coeff_zero] using hF₀
| succ N IH =>
have hdeg : natDegree (finSuccEquiv R N F) < n + 1 := by
linarith [natDegree_finSuccEquiv F, degreeOf_le_totalDegree F 0, hF.totalDegree hF₀]
obtain ⟨i, hi⟩ : ∃ i : ℕ, (finSuccEquiv R N F).coeff i ≠ 0 := by
contrapose! hF₀
exact (finSuccEquiv _ _).injective <| Polynomial.ext <| by simpa using hF₀
have hin : i ≤ n := by
contrapose! hi
exact coeff_eq_zero_of_natDegree_lt <| (Nat.le_of_lt_succ hdeg).trans_lt hi
obtain hFn | hFn := ne_or_eq ((finSuccEquiv R N F).coeff n) 0
· exact hF.exists_eval_ne_zero_of_coeff_finSuccEquiv_ne_zero_aux hFn
have hin : i < n := hin.lt_or_eq.elim id <| by aesop
obtain ⟨j, hj⟩ : ∃ j, i + (j + 1) = n := (Nat.exists_eq_add_of_lt hin).imp <| by cutsat
obtain ⟨r, hr⟩ : ∃ r, (eval r) (Polynomial.coeff ((finSuccEquiv R N) F) i) ≠ 0 :=
IH (hF.finSuccEquiv_coeff_isHomogeneous _ _ hj) hi (.trans (by norm_cast; cutsat) hnR)
set φ : R[X] := Polynomial.map (eval r) (finSuccEquiv _ _ F) with hφ
have hφ₀ : φ ≠ 0 := fun hφ₀ ↦ hr <| by
rw [← coeff_eval_eq_eval_coeff, ← hφ, hφ₀, Polynomial.coeff_zero]
have hφR : φ.natDegree < #R := by
refine lt_of_lt_of_le ?_ hnR
norm_cast
refine lt_of_le_of_lt natDegree_map_le ?_
suffices (finSuccEquiv _ _ F).natDegree ≠ n by cutsat
rintro rfl
refine leadingCoeff_ne_zero.mpr ?_ hFn
simpa using (finSuccEquiv R N).injective.ne hF₀
obtain ⟨r₀, hr₀⟩ : ∃ r₀, Polynomial.eval r₀ φ ≠ 0 :=
φ.exists_eval_ne_zero_of_natDegree_lt_card hφ₀ hφR
use Fin.cons r₀ r
rwa [eval_eq_eval_mv_eval']
/-- See `MvPolynomial.IsHomogeneous.eq_zero_of_forall_eval_eq_zero`
for a version that assumes `Infinite R`. -/
lemma eq_zero_of_forall_eval_eq_zero_of_le_card
(hF : F.IsHomogeneous n) (h : ∀ r : σ → R, eval r F = 0) (hnR : n ≤ #R) :
F = 0 := by
contrapose! h
-- reduce to the case where σ is finite
obtain ⟨k, f, hf, F, rfl⟩ := exists_fin_rename F
have hF₀ : F ≠ 0 := by rintro rfl; simp at h
have hF : F.IsHomogeneous n := by rwa [rename_isHomogeneous_iff hf] at hF
obtain ⟨r, hr⟩ := exists_eval_ne_zero_of_totalDegree_le_card_aux hF hF₀ hnR
obtain ⟨r, rfl⟩ := (Function.factorsThrough_iff _).mp <| (hf.factorsThrough r)
use r
rwa [eval_rename]
/-- See `MvPolynomial.IsHomogeneous.funext`
for a version that assumes `Infinite R`. -/
lemma funext_of_le_card (hF : F.IsHomogeneous n) (hG : G.IsHomogeneous n)
(h : ∀ r : σ → R, eval r F = eval r G) (hnR : n ≤ #R) :
F = G := by
rw [← sub_eq_zero]
apply eq_zero_of_forall_eval_eq_zero_of_le_card (hF.sub hG) _ hnR
simpa [sub_eq_zero] using h
/-- See `MvPolynomial.IsHomogeneous.eq_zero_of_forall_eval_eq_zero_of_le_card`
for a version that assumes `n ≤ #R`. -/
lemma eq_zero_of_forall_eval_eq_zero [Infinite R] {F : MvPolynomial σ R} {n : ℕ}
(hF : F.IsHomogeneous n) (h : ∀ r : σ → R, eval r F = 0) : F = 0 := by
apply eq_zero_of_forall_eval_eq_zero_of_le_card hF h
exact (Cardinal.nat_lt_aleph0 _).le.trans <| Cardinal.infinite_iff.mp ‹Infinite R›
/-- See `MvPolynomial.IsHomogeneous.funext_of_le_card`
for a version that assumes `n ≤ #R`. -/
lemma funext [Infinite R] {F G : MvPolynomial σ R} {n : ℕ}
(hF : F.IsHomogeneous n) (hG : G.IsHomogeneous n)
(h : ∀ r : σ → R, eval r F = eval r G) : F = G := by
apply funext_of_le_card hF hG h
exact (Cardinal.nat_lt_aleph0 _).le.trans <| Cardinal.infinite_iff.mp ‹Infinite R›
end IsDomain
/-- The homogeneous submodules form a graded ring. This instance is used by `DirectSum.commSemiring`
and `DirectSum.algebra`. -/
instance HomogeneousSubmodule.gcommSemiring : SetLike.GradedMonoid (homogeneousSubmodule σ R) where
one_mem := isHomogeneous_one σ R
mul_mem _ _ _ _ := IsHomogeneous.mul
end IsHomogeneous
noncomputable section
open Finset
/-- `homogeneousComponent n φ` is the part of `φ` that is homogeneous of degree `n`.
See `sum_homogeneousComponent` for the statement that `φ` is equal to the sum
of all its homogeneous components. -/
def homogeneousComponent [CommSemiring R] (n : ℕ) : MvPolynomial σ R →ₗ[R] MvPolynomial σ R :=
weightedHomogeneousComponent 1 n
section HomogeneousComponent
open Finset Finsupp
variable (n : ℕ) (φ ψ : MvPolynomial σ R)
theorem homogeneousComponent_mem :
homogeneousComponent n φ ∈ homogeneousSubmodule σ R n :=
weightedHomogeneousComponent_mem _ φ n
theorem coeff_homogeneousComponent (d : σ →₀ ℕ) :
coeff d (homogeneousComponent n φ) = if d.degree = n then coeff d φ else 0 := by
rw [degree_eq_weight_one]
convert coeff_weightedHomogeneousComponent n φ d
theorem homogeneousComponent_apply :
homogeneousComponent n φ = ∑ d ∈ φ.support with d.degree = n, monomial d (coeff d φ) := by
simp_rw [degree_eq_weight_one]
convert weightedHomogeneousComponent_apply n φ
theorem homogeneousComponent_isHomogeneous : (homogeneousComponent n φ).IsHomogeneous n :=
weightedHomogeneousComponent_isWeightedHomogeneous n φ
@[simp]
theorem homogeneousComponent_zero : homogeneousComponent 0 φ = C (coeff 0 φ) :=
weightedHomogeneousComponent_zero φ (fun _ => Nat.succ_ne_zero Nat.zero)
@[simp]
theorem homogeneousComponent_C_mul (n : ℕ) (r : R) :
homogeneousComponent n (C r * φ) = C r * homogeneousComponent n φ :=
weightedHomogeneousComponent_C_mul φ n r
theorem homogeneousComponent_eq_zero'
(h : ∀ d : σ →₀ ℕ, d ∈ φ.support → d.degree ≠ n) :
homogeneousComponent n φ = 0 := by
simp_rw [degree_eq_weight_one] at h
exact weightedHomogeneousComponent_eq_zero' n φ h
theorem homogeneousComponent_eq_zero (h : φ.totalDegree < n) : homogeneousComponent n φ = 0 := by
apply homogeneousComponent_eq_zero'
rw [totalDegree, Finset.sup_lt_iff (lt_of_le_of_lt (Nat.zero_le _) h)] at h
intro d hd; exact ne_of_lt (h d hd)
theorem sum_homogeneousComponent :
(∑ i ∈ range (φ.totalDegree + 1), homogeneousComponent i φ) = φ := by
ext1 d
suffices φ.totalDegree < d.support.sum d → 0 = coeff d φ by
simpa [coeff_sum, coeff_homogeneousComponent]
exact fun h => (coeff_eq_zero_of_totalDegree_lt h).symm
theorem homogeneousComponent_of_mem {m n : ℕ} {p : MvPolynomial σ R}
(h : p ∈ homogeneousSubmodule σ R n) :
homogeneousComponent m p = if m = n then p else 0 :=
weightedHomogeneousComponent_of_mem h
end HomogeneousComponent
end
noncomputable section GradedAlgebra
/-- The homogeneous submodules form a graded ring.
This instance is used by `DirectSum.commSemiring` and `DirectSum.algebra`. -/
lemma HomogeneousSubmodule.gradedMonoid :
SetLike.GradedMonoid (homogeneousSubmodule σ R) :=
WeightedHomogeneousSubmodule.gradedMonoid
/-- The decomposition of `MvPolynomial σ R` into homogeneous submodules. -/
abbrev decomposition :
DirectSum.Decomposition (homogeneousSubmodule σ R) :=
weightedDecomposition R (1 : σ → ℕ)
/-- `MvPolynomial σ R` as a graded algebra, graded by the degree.
We do not make this a global instance because one may want to consider a different
graded algebra structure on `MvPolynomial σ R`, induced by another weight function.
To make it a local instance, you may use
`attribute [local instance] MvPolynomial.gradedAlgebra`.
-/
abbrev gradedAlgebra : GradedAlgebra (homogeneousSubmodule σ R) :=
weightedGradedAlgebra R (1 : σ → ℕ)
theorem decomposition.decompose'_apply (φ : MvPolynomial σ R) (i : ℕ) :
(decomposition.decompose' φ i : MvPolynomial σ R) = homogeneousComponent i φ :=
weightedDecomposition.decompose'_apply R _ φ i
theorem decomposition.decompose'_eq :
decomposition.decompose' = fun φ : MvPolynomial σ R =>
DirectSum.mk (fun i : ℕ => ↥(homogeneousSubmodule σ R i)) (φ.support.image Finsupp.degree)
fun m => ⟨homogeneousComponent m φ, homogeneousComponent_mem m φ⟩ := by
rw [degree_eq_weight_one]
rfl
end GradedAlgebra
end MvPolynomial |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/WeightedHomogeneous.lean | import Mathlib.Algebra.BigOperators.Finprod
import Mathlib.Algebra.DirectSum.Decomposition
import Mathlib.Algebra.GradedMonoid
import Mathlib.Algebra.MvPolynomial.Basic
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Data.Finsupp.Weight
import Mathlib.RingTheory.GradedAlgebra.Basic
import Mathlib.Tactic.Order
/-!
# Weighted homogeneous polynomials
It is possible to assign weights (in a commutative additive monoid `M`) to the variables of a
multivariate polynomial ring, so that monomials of the ring then have a weighted degree with
respect to the weights of the variables. The weights are represented by a function `w : σ → M`,
where `σ` are the indeterminates.
A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m : M` if all monomials
occurring in `φ` have the same weighted degree `m`.
## Main definitions/lemmas
* `weightedTotalDegree' w φ` : the weighted total degree of a multivariate polynomial with respect
to the weights `w`, taking values in `WithBot M`.
* `weightedTotalDegree w φ` : When `M` has a `⊥` element, we can define the weighted total degree
of a multivariate polynomial as a function taking values in `M`.
* `IsWeightedHomogeneous w φ m`: a predicate that asserts that `φ` is weighted homogeneous
of weighted degree `m` with respect to the weights `w`.
* `weightedHomogeneousSubmodule R w m`: the submodule of homogeneous polynomials
of weighted degree `m`.
* `weightedHomogeneousComponent w m`: the additive morphism that projects polynomials
onto their summand that is weighted homogeneous of degree `n` with respect to `w`.
* `sum_weightedHomogeneousComponent`: every polynomial is the sum of its weighted homogeneous
components.
-/
noncomputable section
open Set Function Finset Finsupp AddMonoidAlgebra
variable {R M : Type*} [CommSemiring R]
namespace MvPolynomial
variable {σ : Type*}
section AddCommMonoid
variable [AddCommMonoid M]
/-! ### `weight` -/
section SemilatticeSup
variable [SemilatticeSup M]
/-- The weighted total degree of a multivariate polynomial, taking values in `WithBot M`. -/
def weightedTotalDegree' (w : σ → M) (p : MvPolynomial σ R) : WithBot M :=
p.support.sup fun s => weight w s
/-- The `weightedTotalDegree'` of a polynomial `p` is `⊥` if and only if `p = 0`. -/
theorem weightedTotalDegree'_eq_bot_iff (w : σ → M) (p : MvPolynomial σ R) :
weightedTotalDegree' w p = ⊥ ↔ p = 0 := by
simp only [weightedTotalDegree', Finset.sup_eq_bot_iff, mem_support_iff, WithBot.coe_ne_bot,
MvPolynomial.eq_zero_iff]
exact forall_congr' fun _ => Classical.not_not
/-- The `weightedTotalDegree'` of the zero polynomial is `⊥`. -/
theorem weightedTotalDegree'_zero (w : σ → M) :
weightedTotalDegree' w (0 : MvPolynomial σ R) = ⊥ := by
simp only [weightedTotalDegree', support_zero, Finset.sup_empty]
section OrderBot
variable [OrderBot M]
/-- When `M` has a `⊥` element, we can define the weighted total degree of a multivariate
polynomial as a function taking values in `M`. -/
def weightedTotalDegree (w : σ → M) (p : MvPolynomial σ R) : M :=
p.support.sup fun s => weight w s
/-- This lemma relates `weightedTotalDegree` and `weightedTotalDegree'`. -/
theorem weightedTotalDegree_coe (w : σ → M) (p : MvPolynomial σ R) (hp : p ≠ 0) :
weightedTotalDegree' w p = ↑(weightedTotalDegree w p) := by
rw [Ne, ← weightedTotalDegree'_eq_bot_iff w p, ← Ne, WithBot.ne_bot_iff_exists] at hp
obtain ⟨m, hm⟩ := hp
apply le_antisymm
· simp only [weightedTotalDegree, weightedTotalDegree', Finset.sup_le_iff, WithBot.coe_le_coe]
intro b
exact Finset.le_sup
· simp only [weightedTotalDegree]
have hm' : weightedTotalDegree' w p ≤ m := le_of_eq hm.symm
rw [← hm]
simpa [weightedTotalDegree'] using hm'
/-- The `weightedTotalDegree` of the zero polynomial is `⊥`. -/
theorem weightedTotalDegree_zero (w : σ → M) :
weightedTotalDegree w (0 : MvPolynomial σ R) = ⊥ := by
simp only [weightedTotalDegree, support_zero, Finset.sup_empty]
theorem le_weightedTotalDegree (w : σ → M) {φ : MvPolynomial σ R} {d : σ →₀ ℕ}
(hd : d ∈ φ.support) : weight w d ≤ φ.weightedTotalDegree w :=
le_sup hd
end OrderBot
end SemilatticeSup
/-- A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m` if all monomials
occurring in `φ` have weighted degree `m`. -/
def IsWeightedHomogeneous (w : σ → M) (φ : MvPolynomial σ R) (m : M) : Prop :=
∀ ⦃d⦄, coeff d φ ≠ 0 → weight w d = m
variable (R)
/-- The submodule of homogeneous `MvPolynomial`s of degree `n`. -/
def weightedHomogeneousSubmodule (w : σ → M) (m : M) : Submodule R (MvPolynomial σ R) where
carrier := { x | x.IsWeightedHomogeneous w m }
smul_mem' r a ha c hc := by
rw [coeff_smul] at hc
exact ha (right_ne_zero_of_mul hc)
zero_mem' _ hd := False.elim (hd <| coeff_zero _)
add_mem' {a} {b} ha hb c hc := by
rw [coeff_add] at hc
obtain h | h : coeff c a ≠ 0 ∨ coeff c b ≠ 0 := by
contrapose! hc
simp only [hc, add_zero]
· exact ha h
· exact hb h
@[simp]
theorem mem_weightedHomogeneousSubmodule (w : σ → M) (m : M) (p : MvPolynomial σ R) :
p ∈ weightedHomogeneousSubmodule R w m ↔ p.IsWeightedHomogeneous w m :=
Iff.rfl
/-- The submodule `weightedHomogeneousSubmodule R w m` of homogeneous `MvPolynomial`s of
degree `n` is equal to the `R`-submodule of all `p : (σ →₀ ℕ) →₀ R` such that
`p.support ⊆ {d | weight w d = m}`. While equal, the former has a
convenient definitional reduction. -/
theorem weightedHomogeneousSubmodule_eq_finsupp_supported (w : σ → M) (m : M) :
weightedHomogeneousSubmodule R w m = Finsupp.supported R R { d | weight w d = m } := by
ext x
rw [mem_supported, Set.subset_def]
simp only [Finsupp.mem_support_iff, mem_coe]
rfl
variable {R}
/-- The submodule generated by products `Pm * Pn` of weighted homogeneous polynomials of degrees `m`
and `n` is contained in the submodule of weighted homogeneous polynomials of degree `m + n`. -/
theorem weightedHomogeneousSubmodule_mul (w : σ → M) (m n : M) :
weightedHomogeneousSubmodule R w m * weightedHomogeneousSubmodule R w n ≤
weightedHomogeneousSubmodule R w (m + n) := by
classical
rw [Submodule.mul_le]
intro φ hφ ψ hψ c hc
rw [coeff_mul] at hc
obtain ⟨⟨d, e⟩, hde, H⟩ := Finset.exists_ne_zero_of_sum_ne_zero hc
have aux : coeff d φ ≠ 0 ∧ coeff e ψ ≠ 0 := by
contrapose! H
by_cases h : coeff d φ = 0 <;>
simp_all only [Ne, not_false_iff, zero_mul, mul_zero]
rw [← mem_antidiagonal.mp hde, ← hφ aux.1, ← hψ aux.2, map_add]
/-- Monomials are weighted homogeneous. -/
theorem isWeightedHomogeneous_monomial (w : σ → M) (d : σ →₀ ℕ) (r : R) {m : M}
(hm : weight w d = m) : IsWeightedHomogeneous w (monomial d r) m := by
classical
intro c hc
rw [coeff_monomial] at hc
split_ifs at hc with h
· subst c
exact hm
· contradiction
/-- A polynomial of weightedTotalDegree `⊥` is weighted_homogeneous of degree `⊥`. -/
theorem isWeightedHomogeneous_of_total_degree_zero [SemilatticeSup M] [OrderBot M] (w : σ → M)
{p : MvPolynomial σ R} (hp : weightedTotalDegree w p = (⊥ : M)) :
IsWeightedHomogeneous w p (⊥ : M) := by
intro d hd
have h := weightedTotalDegree_coe w p (MvPolynomial.ne_zero_iff.mpr ⟨d, hd⟩)
simp only [weightedTotalDegree', hp] at h
rw [eq_bot_iff, ← WithBot.coe_le_coe, ← h]
apply Finset.le_sup (mem_support_iff.mpr hd)
/-- Constant polynomials are weighted homogeneous of degree 0. -/
theorem isWeightedHomogeneous_C (w : σ → M) (r : R) :
IsWeightedHomogeneous w (C r : MvPolynomial σ R) 0 :=
isWeightedHomogeneous_monomial _ _ _ (map_zero _)
variable (R)
/-- 0 is weighted homogeneous of any degree. -/
theorem isWeightedHomogeneous_zero (w : σ → M) (m : M) :
IsWeightedHomogeneous w (0 : MvPolynomial σ R) m :=
(weightedHomogeneousSubmodule R w m).zero_mem
/-- 1 is weighted homogeneous of degree 0. -/
theorem isWeightedHomogeneous_one (w : σ → M) : IsWeightedHomogeneous w (1 : MvPolynomial σ R) 0 :=
isWeightedHomogeneous_C _ _
/-- An indeterminate `i : σ` is weighted homogeneous of degree `w i`. -/
theorem isWeightedHomogeneous_X (w : σ → M) (i : σ) :
IsWeightedHomogeneous w (X i : MvPolynomial σ R) (w i) := by
apply isWeightedHomogeneous_monomial
simp only [weight, LinearMap.toAddMonoidHom_coe, linearCombination_single, one_nsmul]
namespace IsWeightedHomogeneous
variable {R}
variable {φ ψ : MvPolynomial σ R} {m n : M}
/-- The weighted degree of a weighted homogeneous polynomial controls its support. -/
theorem coeff_eq_zero {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (d : σ →₀ ℕ)
(hd : weight w d ≠ n) : coeff d φ = 0 := by
have aux := mt (@hφ d) hd
rwa [Classical.not_not] at aux
/-- The weighted degree of a nonzero weighted homogeneous polynomial is well-defined. -/
theorem inj_right {w : σ → M} (hφ : φ ≠ 0) (hm : IsWeightedHomogeneous w φ m)
(hn : IsWeightedHomogeneous w φ n) : m = n := by
obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero hφ
rw [← hm hd, ← hn hd]
/-- The sum of two weighted homogeneous polynomials of degree `n` is weighted homogeneous of
weighted degree `n`. -/
theorem add {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (hψ : IsWeightedHomogeneous w ψ n) :
IsWeightedHomogeneous w (φ + ψ) n :=
(weightedHomogeneousSubmodule R w n).add_mem hφ hψ
/-- The sum of weighted homogeneous polynomials of degree `n` is weighted homogeneous of
weighted degree `n`. -/
theorem sum {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : M) {w : σ → M}
(h : ∀ i ∈ s, IsWeightedHomogeneous w (φ i) n) : IsWeightedHomogeneous w (∑ i ∈ s, φ i) n :=
(weightedHomogeneousSubmodule R w n).sum_mem h
/-- The product of weighted homogeneous polynomials of weighted degrees `m` and `n` is weighted
homogeneous of weighted degree `m + n`. -/
theorem mul {w : σ → M} (hφ : IsWeightedHomogeneous w φ m) (hψ : IsWeightedHomogeneous w ψ n) :
IsWeightedHomogeneous w (φ * ψ) (m + n) :=
weightedHomogeneousSubmodule_mul w m n <| Submodule.mul_mem_mul hφ hψ
theorem pow {w : σ → M} (hφ : IsWeightedHomogeneous w φ m) (n : ℕ) :
IsWeightedHomogeneous w (φ ^ n) (n • m) := by
induction n with
| zero => rw [pow_zero, zero_smul]; exact isWeightedHomogeneous_one R w
| succ n ih => rw [pow_succ, succ_nsmul]; exact ih.mul hφ
/-- A product of weighted homogeneous polynomials is weighted homogeneous, with weighted degree
equal to the sum of the weighted degrees. -/
theorem prod {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ι → M) {w : σ → M} :
(∀ i ∈ s, IsWeightedHomogeneous w (φ i) (n i)) →
IsWeightedHomogeneous w (∏ i ∈ s, φ i) (∑ i ∈ s, n i) := by
classical
refine Finset.induction_on s ?_ ?_
· intro
simp only [isWeightedHomogeneous_one, Finset.sum_empty, Finset.prod_empty]
· intro i s his IH h
simp only [his, Finset.prod_insert, Finset.sum_insert, not_false_iff]
apply (h i (Finset.mem_insert_self _ _)).mul (IH _)
intro j hjs
exact h j (Finset.mem_insert_of_mem hjs)
/-- A nonzero weighted-homogeneous polynomial of weighted degree `n` has weighted total degree
`n`. -/
theorem weighted_total_degree [SemilatticeSup M] {w : σ → M} (hφ : IsWeightedHomogeneous w φ n)
(h : φ ≠ 0) : weightedTotalDegree' w φ = n := by
simp only [weightedTotalDegree']
apply le_antisymm
· simp only [Finset.sup_le_iff, mem_support_iff, WithBot.coe_le_coe]
exact fun d hd => le_of_eq (hφ hd)
· obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero h
simp only [← hφ hd]
replace hd := Finsupp.mem_support_iff.mpr hd
apply Finset.le_sup hd
end IsWeightedHomogeneous
variable {R}
/-- The weighted homogeneous submodules form a graded monoid. -/
lemma WeightedHomogeneousSubmodule.gradedMonoid {w : σ → M} :
SetLike.GradedMonoid (weightedHomogeneousSubmodule R w) where
one_mem := isWeightedHomogeneous_one R w
mul_mem _ _ _ _ := IsWeightedHomogeneous.mul
/-- `weightedHomogeneousComponent w n φ` is the part of `φ` that is weighted homogeneous of
weighted degree `n`, with respect to the weights `w`.
See `sum_weightedHomogeneousComponent` for the statement that `φ` is equal to the sum
of all its weighted homogeneous components. -/
def weightedHomogeneousComponent (w : σ → M) (n : M) : MvPolynomial σ R →ₗ[R] MvPolynomial σ R :=
letI := Classical.decEq M
(Submodule.subtype _).comp <| Finsupp.restrictDom _ _ { d | weight w d = n }
section WeightedHomogeneousComponent
variable {w : σ → M} (n : M) (φ ψ : MvPolynomial σ R)
theorem coeff_weightedHomogeneousComponent [DecidableEq M] (d : σ →₀ ℕ) :
coeff d (weightedHomogeneousComponent w n φ) =
if weight w d = n then coeff d φ else 0 :=
letI := Classical.decEq M
Finsupp.filter_apply (fun d : σ →₀ ℕ => weight w d = n) φ d |>.trans <| by convert rfl
theorem weightedHomogeneousComponent_apply [DecidableEq M] :
weightedHomogeneousComponent w n φ =
∑ d ∈ φ.support with weight w d = n, monomial d (coeff d φ) :=
letI := Classical.decEq M
Finsupp.filter_eq_sum (fun d : σ →₀ ℕ => weight w d = n) φ |>.trans <| by convert rfl
/-- The `n` weighted homogeneous component of a polynomial is weighted homogeneous of
weighted degree `n`. -/
theorem weightedHomogeneousComponent_isWeightedHomogeneous :
(weightedHomogeneousComponent w n φ).IsWeightedHomogeneous w n := by
classical
intro d hd
contrapose! hd
rw [coeff_weightedHomogeneousComponent, if_neg hd]
theorem weightedHomogeneousComponent_mem (w : σ → M) (φ : MvPolynomial σ R) (m : M) :
weightedHomogeneousComponent w m φ ∈ weightedHomogeneousSubmodule R w m := by
rw [mem_weightedHomogeneousSubmodule]
exact weightedHomogeneousComponent_isWeightedHomogeneous m φ
@[simp]
theorem weightedHomogeneousComponent_C_mul (n : M) (r : R) :
weightedHomogeneousComponent w n (C r * φ) = C r * weightedHomogeneousComponent w n φ := by
simp only [C_mul', LinearMap.map_smul]
theorem weightedHomogeneousComponent_eq_zero'
(h : ∀ d : σ →₀ ℕ, d ∈ φ.support → weight w d ≠ n) :
weightedHomogeneousComponent w n φ = 0 := by
classical
rw [weightedHomogeneousComponent_apply, sum_eq_zero]
intro d hd; rw [mem_filter] at hd
exfalso; exact h _ hd.1 hd.2
theorem weightedHomogeneousComponent_eq_zero [SemilatticeSup M] [OrderBot M]
(h : weightedTotalDegree w φ < n) : weightedHomogeneousComponent w n φ = 0 := by
classical
rw [weightedHomogeneousComponent_apply, sum_eq_zero]
intro d hd
rw [Finset.mem_filter] at hd
exfalso
apply lt_irrefl n
nth_rw 1 [← hd.2]
exact lt_of_le_of_lt (le_weightedTotalDegree w hd.1) h
theorem weightedHomogeneousComponent_finsupp :
(Function.support fun m => weightedHomogeneousComponent w m φ).Finite := by
apply ((fun d : σ →₀ ℕ => (weight w) d) '' (φ.support : Set (σ →₀ ℕ))).toFinite.subset
intro m hm
by_contra hm'
apply hm (weightedHomogeneousComponent_eq_zero' m φ _)
simpa only [Set.mem_image, not_exists, not_and] using hm'
variable (w)
/-- Every polynomial is the sum of its weighted homogeneous components. -/
theorem sum_weightedHomogeneousComponent :
(finsum fun m => weightedHomogeneousComponent w m φ) = φ := by
classical
rw [finsum_eq_sum _ (weightedHomogeneousComponent_finsupp φ)]
ext1 d
simp only [coeff_sum, coeff_weightedHomogeneousComponent]
rw [Finset.sum_eq_single (weight w d)]
· rw [if_pos rfl]
· intro m _ hm'
rw [if_neg hm'.symm]
· intro hm
rw [if_pos rfl]
simp only [Finite.mem_toFinset, mem_support, Ne, Classical.not_not] at hm
have := coeff_weightedHomogeneousComponent (w := w) (weight w d) φ d
rw [hm, if_pos rfl, coeff_zero] at this
exact this.symm
theorem finsum_weightedHomogeneousComponent :
(finsum fun m => weightedHomogeneousComponent w m φ) = φ := by
rw [sum_weightedHomogeneousComponent]
variable {w}
theorem IsWeightedHomogeneous.weightedHomogeneousComponent_same {m : M} {p : MvPolynomial σ R}
(hp : IsWeightedHomogeneous w p m) :
weightedHomogeneousComponent w m p = p := by
classical
ext x
rw [coeff_weightedHomogeneousComponent]
by_cases zero_coeff : coeff x p = 0
· split_ifs
· rfl
rw [zero_coeff]
· rw [hp zero_coeff, if_pos rfl]
theorem IsWeightedHomogeneous.weightedHomogeneousComponent_ne {m : M} (n : M)
{p : MvPolynomial σ R} (hp : IsWeightedHomogeneous w p m) :
n ≠ m → weightedHomogeneousComponent w n p = 0 := by
classical
intro hn
ext x
rw [coeff_weightedHomogeneousComponent]
by_cases zero_coeff : coeff x p = 0
· simp [zero_coeff]
· rw [if_neg]
· rw [coeff_zero]
· rw [hp zero_coeff]; exact Ne.symm hn
/-- The weighted homogeneous components of a weighted homogeneous polynomial. -/
theorem weightedHomogeneousComponent_of_mem [DecidableEq M] {m n : M}
{p : MvPolynomial σ R} (h : p ∈ weightedHomogeneousSubmodule R w n) :
weightedHomogeneousComponent w m p = if m = n then p else 0 := by
simp only [mem_weightedHomogeneousSubmodule] at h
ext x
rw [coeff_weightedHomogeneousComponent]
by_cases zero_coeff : coeff x p = 0
· split_ifs <;>
simp only [zero_coeff, coeff_zero]
· rw [h zero_coeff]
simp only [show n = m ↔ m = n from eq_comm]
split_ifs with h1
· rfl
· simp only [coeff_zero]
@[deprecated (since := "2025-10-06")]
alias weightedHomogeneousComponent_of_isWeightedHomogeneous_same :=
IsWeightedHomogeneous.weightedHomogeneousComponent_same
@[deprecated (since := "2025-10-06")]
alias weightedHomogeneousComponent_of_isWeightedHomogeneous_ne :=
IsWeightedHomogeneous.weightedHomogeneousComponent_ne
variable (R w)
open DirectSum
theorem DirectSum.coeLinearMap_eq_dfinsuppSum [DecidableEq σ] [DecidableEq R] [DecidableEq M]
(x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) :
(coeLinearMap fun i : M => weightedHomogeneousSubmodule R w i) x =
DFinsupp.sum x (fun _ x => ↑x) := by
rw [_root_.DirectSum.coeLinearMap_eq_dfinsuppSum]
theorem DirectSum.coeAddMonoidHom_eq_support_sum [DecidableEq σ] [DecidableEq R] [DecidableEq M]
(x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) :
(DirectSum.coeAddMonoidHom fun i : M => weightedHomogeneousSubmodule R w i) x =
DFinsupp.sum x (fun _ x => ↑x) :=
DirectSum.coeLinearMap_eq_dfinsuppSum R w x
theorem DirectSum.coeLinearMap_eq_finsum [DecidableEq M]
(x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) :
(DirectSum.coeLinearMap fun i : M => weightedHomogeneousSubmodule R w i) x =
finsum fun m => x m := by
classical
rw [DirectSum.coeLinearMap_eq_dfinsuppSum, DFinsupp.sum, finsum_eq_sum_of_support_subset]
apply DirectSum.support_subset
theorem weightedHomogeneousComponent_directSum [DecidableEq M]
(x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) (m : M) :
(weightedHomogeneousComponent w m)
((DirectSum.coeLinearMap fun i : M => weightedHomogeneousSubmodule R w i) x) = x m := by
classical
rw [DirectSum.coeLinearMap_eq_dfinsuppSum, DFinsupp.sum, map_sum]
convert @Finset.sum_eq_single M (MvPolynomial σ R) _ (DFinsupp.support x) _ m _ _
· rw [IsWeightedHomogeneous.weightedHomogeneousComponent_same (x m).prop]
· intro n _ hmn
exact IsWeightedHomogeneous.weightedHomogeneousComponent_ne m (x n).prop hmn.symm
· rw [DFinsupp.notMem_support_iff]
intro hm; rw [hm, Submodule.coe_zero, map_zero]
end WeightedHomogeneousComponent
end AddCommMonoid
section OrderedAddCommMonoid
variable [AddCommMonoid M] [PartialOrder M]
{w : σ → M} (φ : MvPolynomial σ R)
/-- If `M` is a canonically `OrderedAddCommMonoid`, then the `weightedHomogeneousComponent`
of weighted degree `0` of a polynomial is its constant coefficient. -/
@[simp]
theorem weightedHomogeneousComponent_zero [CanonicallyOrderedAdd M] [IsAddTorsionFree M]
(hw : ∀ i : σ, w i ≠ 0) :
weightedHomogeneousComponent w 0 φ = C (coeff 0 φ) := by
classical
ext1 d
rcases Classical.em (d = 0) with (rfl | hd)
· simp only [coeff_weightedHomogeneousComponent, if_pos, map_zero, coeff_zero_C]
· rw [coeff_weightedHomogeneousComponent, if_neg, coeff_C, if_neg (Ne.symm hd)]
simp only [weight, LinearMap.toAddMonoidHom_coe, Finsupp.linearCombination_apply, Finsupp.sum,
sum_eq_zero_iff, Finsupp.mem_support_iff, Ne, smul_eq_zero, not_forall, not_or,
and_self_left, exists_prop]
simp only [DFunLike.ext_iff, Finsupp.coe_zero, Pi.zero_apply, not_forall] at hd
obtain ⟨i, hi⟩ := hd
exact ⟨i, hi, hw i⟩
/-- A weight function is nontorsion if its values are not torsion. -/
def NonTorsionWeight (w : σ → M) :=
∀ n x, n • w x = (0 : M) → n = 0
omit [PartialOrder M] in
theorem nonTorsionWeight_of [IsAddTorsionFree M] (hw : ∀ i : σ, w i ≠ 0) :
NonTorsionWeight w :=
fun _ x hnx => (smul_eq_zero_iff_left (hw x)).mp hnx
/-- If `w` is a nontorsion weight function, then the finitely supported function `m : σ →₀ ℕ`
has weighted degree zero if and only if `∀ x : σ, m x = 0`. -/
theorem weightedDegree_eq_zero_iff [CanonicallyOrderedAdd M]
(hw : NonTorsionWeight w) {m : σ →₀ ℕ} :
weight w m = 0 ↔ ∀ x : σ, m x = 0 := by
simp only [weight, Finsupp.linearCombination, LinearMap.toAddMonoidHom_coe, coe_lsum,
LinearMap.coe_smulRight, LinearMap.id_coe, id_eq]
rw [Finsupp.sum, Finset.sum_eq_zero_iff]
apply forall_congr'
intro x
rw [Finsupp.mem_support_iff]
constructor
· intro hx
by_contra hx'
exact absurd (hw _ _ (hx hx')) hx'
· order
end OrderedAddCommMonoid
section LinearOrderedAddCommMonoid
variable [AddCommMonoid M] [LinearOrder M] [OrderBot M] [CanonicallyOrderedAdd M]
{w : σ → M} (φ : MvPolynomial σ R)
/-- A multivariate polynomial is weighted homogeneous of weighted degree zero if and only if
its weighted total degree is equal to zero. -/
theorem isWeightedHomogeneous_zero_iff_weightedTotalDegree_eq_zero {p : MvPolynomial σ R} :
IsWeightedHomogeneous w p 0 ↔ p.weightedTotalDegree w = 0 := by
rw [weightedTotalDegree, ← bot_eq_zero, Finset.sup_eq_bot_iff, bot_eq_zero, IsWeightedHomogeneous]
apply forall_congr'
intro m
rw [mem_support_iff]
/-- If `w` is a nontorsion weight function, then a multivariate polynomial has weighted total
degree zero if and only if for every `m ∈ p.support` and `x : σ`, `m x = 0`. -/
theorem weightedTotalDegree_eq_zero_iff (hw : NonTorsionWeight w) (p : MvPolynomial σ R) :
p.weightedTotalDegree w = 0 ↔ ∀ (m : σ →₀ ℕ) (_ : m ∈ p.support) (x : σ), m x = 0 := by
rw [← isWeightedHomogeneous_zero_iff_weightedTotalDegree_eq_zero, IsWeightedHomogeneous]
apply forall_congr'
intro m
rw [mem_support_iff]
apply forall_congr'
intro _
exact weightedDegree_eq_zero_iff hw
end LinearOrderedAddCommMonoid
section GradedAlgebra
/- Here, given a weight `w : σ → M`, where `M` is an additive and commutative monoid, we endow the
ring of multivariate polynomials `MvPolynomial σ R` with the structure of a graded algebra -/
variable (w : σ → M) [AddCommMonoid M]
theorem weightedHomogeneousComponent_eq_zero_of_notMem [DecidableEq M]
(φ : MvPolynomial σ R) (i : M) (hi : i ∉ Finset.image (weight w) φ.support) :
weightedHomogeneousComponent w i φ = 0 := by
apply weightedHomogeneousComponent_eq_zero'
simp only [Finset.mem_image, mem_support_iff, ne_eq, not_exists, not_and] at hi
exact fun m hm ↦ hi m (mem_support_iff.mp hm)
@[deprecated (since := "2025-05-23")]
alias weightedHomogeneousComponent_eq_zero_of_not_mem :=
weightedHomogeneousComponent_eq_zero_of_notMem
variable (R)
/-- The `decompose'` argument of `weightedDecomposition`. -/
def decompose' [DecidableEq M] := fun φ : MvPolynomial σ R =>
DirectSum.mk (fun i : M => ↥(weightedHomogeneousSubmodule R w i))
(Finset.image (weight w) φ.support) fun m =>
⟨weightedHomogeneousComponent w m φ, weightedHomogeneousComponent_mem w φ m⟩
theorem decompose'_apply [DecidableEq M] (φ : MvPolynomial σ R) (m : M) :
(decompose' R w φ m : MvPolynomial σ R) = weightedHomogeneousComponent w m φ := by
rw [decompose']
by_cases hm : m ∈ Finset.image (weight w) φ.support
· simp only [DirectSum.mk_apply_of_mem hm, Subtype.coe_mk]
· rw [DirectSum.mk_apply_of_notMem hm, Submodule.coe_zero,
weightedHomogeneousComponent_eq_zero_of_notMem w φ m hm]
/-- Given a weight `w`, the decomposition of `MvPolynomial σ R` into weighted homogeneous
submodules -/
def weightedDecomposition [DecidableEq M] :
DirectSum.Decomposition (weightedHomogeneousSubmodule R w) where
decompose' := decompose' R w
left_inv φ := by
classical
conv_rhs => rw [← sum_weightedHomogeneousComponent w φ]
rw [← DirectSum.sum_support_of (decompose' R w φ)]
simp only [DirectSum.coeAddMonoidHom_of, map_sum,
finsum_eq_sum _ (weightedHomogeneousComponent_finsupp φ)]
apply Finset.sum_congr _ (fun m _ ↦ by rw [decompose'_apply])
ext m
simp only [DFinsupp.mem_support_toFun, ne_eq, Set.Finite.mem_toFinset, Function.mem_support,
not_iff_not]
conv_lhs => rw [← Subtype.coe_inj]
rw [decompose'_apply, Submodule.coe_zero]
right_inv x := by
classical
apply DFinsupp.ext
intro m
rw [← Subtype.coe_inj, decompose'_apply]
exact weightedHomogeneousComponent_directSum R w x m
/-- Given a weight, `MvPolynomial` as a graded algebra -/
def weightedGradedAlgebra [DecidableEq M] :
GradedAlgebra (weightedHomogeneousSubmodule R w) where
toDecomposition := weightedDecomposition R w
toGradedMonoid := WeightedHomogeneousSubmodule.gradedMonoid
theorem weightedDecomposition.decompose'_eq [DecidableEq M] :
(weightedDecomposition R w).decompose' = fun φ : MvPolynomial σ R =>
DirectSum.mk (fun i : M => ↥(weightedHomogeneousSubmodule R w i))
(Finset.image (weight w) φ.support) fun m =>
⟨weightedHomogeneousComponent w m φ, weightedHomogeneousComponent_mem w φ m⟩ := rfl
theorem weightedDecomposition.decompose'_apply [DecidableEq M]
(φ : MvPolynomial σ R) (m : M) :
((weightedDecomposition R w).decompose' φ m : MvPolynomial σ R) =
weightedHomogeneousComponent w m φ :=
MvPolynomial.decompose'_apply R w φ m
end GradedAlgebra
end MvPolynomial |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/MonomialOrder.lean | import Mathlib.Data.Finsupp.Lex
import Mathlib.Data.Finsupp.MonomialOrder
import Mathlib.Data.Finsupp.WellFounded
import Mathlib.Data.List.TFAE
import Mathlib.RingTheory.MvPolynomial.Homogeneous
import Mathlib.RingTheory.Nilpotent.Defs
/-! # Degree and leading coefficient of polynomials with respect to a monomial order
We consider a type `σ` of indeterminates and a commutative semiring `R`
and a monomial order `m : MonomialOrder σ`.
* `m.degree f` is the degree of `f` for the monomial ordering `m`.
* `m.leadingCoeff f` is the leading coefficient of `f` for the monomial ordering `m`.
* `m.Monic f` asserts that the leading coefficient of `f` is `1`.
* `m.leadingCoeff_ne_zero_iff f` asserts that this coefficient is nonzero iff `f ≠ 0`.
* in a field, `m.isUnit_leadingCoeff f` asserts that this coefficient is a unit iff `f ≠ 0`.
* `m.degree_add_le` : the `m.degree` of `f + g` is smaller than or equal to the supremum
of those of `f` and `g`.
* `m.degree_add_of_lt h` : the `m.degree` of `f + g` is equal to that of `f`
if the `m.degree` of `g` is strictly smaller than that `f`.
* `m.leadingCoeff_add_of_lt h`: then, the leading coefficient of `f + g` is that of `f`.
* `m.degree_add_of_ne h` : the `m.degree` of `f + g` is equal to that the supremum
of those of `f` and `g` if they are distinct.
* `m.degree_sub_le` : the `m.degree` of `f - g` is smaller than or equal to the supremum
of those of `f` and `g`.
* `m.degree_sub_of_lt h` : the `m.degree` of `f - g` is equal to that of `f`
if the `m.degree` of `g` is strictly smaller than that `f`.
* `m.leadingCoeff_sub_of_lt h`: then, the leading coefficient of `f - g` is that of `f`.
* `m.degree_mul_le`: the `m.degree` of `f * g` is smaller than or equal to the sum of those of
`f` and `g`.
* `m.degree_mul_of_mul_leadingCoeff_ne_zero` : if the product of the leading coefficients
is nonzero, then the degree is the sum of the degrees.
* `m.leadingCoeff_mul_of_mul_leadingCoeff_ne_zero` : if the product of the leading coefficients
is nonzero, then the leading coefficient is that product.
* `m.degree_mul_of_isRegular_left`, `m.degree_mul_of_isRegular_right` and `m.degree_mul`
assert the equality when the leading coefficient of `f` or `g` is regular,
or when `R` is a domain and `f` and `g` are nonzero.
* `m.leadingCoeff_mul_of_isRegular_left`, `m.leadingCoeff_mul_of_isRegular_right`
and `m.leadingCoeff_mul` say that `m.leadingCoeff (f * g) = m.leadingCoeff f * m.leadingCoeff g`
* `m.degree_pow_of_pow_leadingCoeff_ne_zero` : is the `n`th power of the leading coefficient
of `f` is nonzero, then the degree of `f ^ n` is `n • (m.degree f)`
* `m.leadingCoeff_pow_of_pow_leadingCoeff_ne_zero` : is the `n`th power of the leading coefficient
of `f` is nonzero, then the leading coefficient of `f ^ n` is that power.
* `m.degree_prod_of_regular` : the degree of a product of polynomials whose leading coefficients
are regular is the sum of their degrees.
* `m.leadingCoeff_prod_of_regular` : the leading coefficient of a product of polynomials
whose leading coefficients are regular is the product of their leading coefficients.
* `m.Monic.prod` : a product of monic polynomials is monic.
## Reference
[Becker-Weispfenning1993]
-/
namespace MonomialOrder
open MvPolynomial
open scoped MonomialOrder
variable {σ : Type*} {m : MonomialOrder σ}
section Semiring
variable {R : Type*} [CommSemiring R]
variable (m) in
/-- the degree of a multivariate polynomial with respect to a monomial ordering -/
def degree (f : MvPolynomial σ R) : σ →₀ ℕ :=
m.toSyn.symm (f.support.sup m.toSyn)
variable (m) in
/-- the leading coefficient of a multivariate polynomial with respect to a monomial ordering -/
def leadingCoeff (f : MvPolynomial σ R) : R :=
f.coeff (m.degree f)
variable (m) in
/-- A multivariate polynomial is `Monic` with respect to a monomial order
if its leading coefficient (for that monomial order) is 1. -/
def Monic (f : MvPolynomial σ R) : Prop :=
m.leadingCoeff f = 1
@[nontriviality] theorem Monic.of_subsingleton [Subsingleton R] {f : MvPolynomial σ R} :
m.Monic f :=
Subsingleton.eq_one (m.leadingCoeff f)
instance Monic.decidable [DecidableEq R] (f : MvPolynomial σ R) :
Decidable (m.Monic f) := by
unfold Monic; infer_instance
@[simp]
theorem Monic.leadingCoeff_eq_one {f : MvPolynomial σ R} (hf : m.Monic f) : m.leadingCoeff f = 1 :=
hf
theorem Monic.coeff_degree {f : MvPolynomial σ R} (hf : m.Monic f) : f.coeff (m.degree f) = 1 :=
hf
@[simp]
theorem degree_zero : m.degree (0 : MvPolynomial σ R) = 0 := by
simp [degree]
theorem ne_zero_of_degree_ne_zero {f : MvPolynomial σ R} (h : m.degree f ≠ 0) : f ≠ 0 := by
rintro rfl
exact h m.degree_zero
@[simp, nontriviality]
theorem degree_subsingleton [Subsingleton R] {f : MvPolynomial σ R} :
m.degree f = 0 := by
rw [Subsingleton.eq_zero f, degree_zero]
@[simp]
theorem leadingCoeff_zero : m.leadingCoeff (0 : MvPolynomial σ R) = 0 := by
simp [degree, leadingCoeff]
theorem Monic.ne_zero [Nontrivial R] {f : MvPolynomial σ R} (hf : m.Monic f) :
f ≠ 0 := by
rintro rfl
simp [Monic, leadingCoeff_zero] at hf
theorem degree_monomial_le {d : σ →₀ ℕ} (c : R) :
m.degree (monomial d c) ≼[m] d := by
simp only [degree, AddEquiv.apply_symm_apply]
apply le_trans (Finset.sup_mono support_monomial_subset)
simp only [Finset.sup_singleton, le_refl]
theorem degree_monomial {d : σ →₀ ℕ} (c : R) [Decidable (c = 0)] :
m.degree (monomial d c) = if c = 0 then 0 else d := by
simp only [degree, support_monomial]
split_ifs with hc <;> simp
theorem degree_X_le_single {s : σ} : m.degree (X s : MvPolynomial σ R) ≼[m] Finsupp.single s 1 :=
degree_monomial_le 1
theorem degree_X [Nontrivial R] {s : σ} :
m.degree (X s : MvPolynomial σ R) = Finsupp.single s 1 := by
classical
change m.degree (monomial (Finsupp.single s 1) (1 : R)) = _
rw [degree_monomial, if_neg one_ne_zero]
@[simp] theorem degree_one : m.degree (1 : MvPolynomial σ R) = 0 := by
nontriviality R
classical rw [MvPolynomial.one_def, degree_monomial]
simp
@[simp]
theorem leadingCoeff_monomial {d : σ →₀ ℕ} (c : R) :
m.leadingCoeff (monomial d c) = c := by
classical
simp only [leadingCoeff, degree_monomial]
split_ifs with hc <;> simp [hc]
@[simp] theorem monic_monomial_one {d : σ →₀ ℕ} :
m.Monic (monomial d (1 : R)) :=
m.leadingCoeff_monomial 1
theorem monic_monomial {d : σ →₀ ℕ} {c : R} :
m.Monic (monomial d c) ↔ c = 1 := by
rw [Monic, m.leadingCoeff_monomial]
theorem leadingCoeff_X {s : σ} :
m.leadingCoeff (X s : MvPolynomial σ R) = 1 :=
m.leadingCoeff_monomial 1
@[simp] theorem monic_X {s : σ} :
m.Monic (X s : MvPolynomial σ R) :=
monic_monomial_one
theorem leadingCoeff_one : m.leadingCoeff (1 : MvPolynomial σ R) = 1 :=
m.leadingCoeff_monomial 1
theorem monic_one : m.Monic (C 1 : MvPolynomial σ R) :=
monic_monomial_one
theorem degree_le_iff {f : MvPolynomial σ R} {d : σ →₀ ℕ} :
m.degree f ≼[m] d ↔ ∀ c ∈ f.support, c ≼[m] d := by
unfold degree
simp only [AddEquiv.apply_symm_apply, Finset.sup_le_iff, mem_support_iff, ne_eq]
theorem degree_lt_iff {f : MvPolynomial σ R} {d : σ →₀ ℕ} (hd : 0 ≺[m] d) :
m.degree f ≺[m] d ↔ ∀ c ∈ f.support, c ≺[m] d := by
simp only [map_zero] at hd
unfold degree
simp only [AddEquiv.apply_symm_apply]
exact Finset.sup_lt_iff hd
theorem le_degree {f : MvPolynomial σ R} {d : σ →₀ ℕ} (hd : d ∈ f.support) :
d ≼[m] m.degree f := by
unfold degree
simp only [AddEquiv.apply_symm_apply, Finset.le_sup hd]
theorem coeff_eq_zero_of_lt {f : MvPolynomial σ R} {d : σ →₀ ℕ} (hd : m.degree f ≺[m] d) :
f.coeff d = 0 := by
rw [← not_le] at hd
by_contra hf
apply hd (m.le_degree (mem_support_iff.mpr hf))
theorem leadingCoeff_ne_zero_iff {f : MvPolynomial σ R} :
m.leadingCoeff f ≠ 0 ↔ f ≠ 0 := by
constructor
· rw [not_imp_not]
intro hf
rw [hf, leadingCoeff_zero]
· intro hf
rw [← support_nonempty] at hf
rw [leadingCoeff, ← mem_support_iff, degree]
suffices f.support.sup m.toSyn ∈ m.toSyn '' f.support by
obtain ⟨d, hd, hd'⟩ := this
rw [← hd', AddEquiv.symm_apply_apply]
exact hd
exact Finset.sup_mem_of_nonempty hf
@[simp]
theorem leadingCoeff_eq_zero_iff {f : MvPolynomial σ R} :
leadingCoeff m f = 0 ↔ f = 0 := by
simp only [← not_iff_not, leadingCoeff_ne_zero_iff]
theorem coeff_degree_ne_zero_iff {f : MvPolynomial σ R} :
f.coeff (m.degree f) ≠ 0 ↔ f ≠ 0 :=
m.leadingCoeff_ne_zero_iff
theorem degree_mem_support_iff (f : MvPolynomial σ R) : m.degree f ∈ f.support ↔ f ≠ 0 :=
mem_support_iff.trans coeff_degree_ne_zero_iff
@[simp]
theorem coeff_degree_eq_zero_iff {f : MvPolynomial σ R} :
f.coeff (m.degree f) = 0 ↔ f = 0 :=
m.leadingCoeff_eq_zero_iff
lemma degree_mem_support {p : MvPolynomial σ R} (hp : p ≠ 0) :
m.degree p ∈ p.support := by
rwa [MvPolynomial.mem_support_iff, coeff_degree_ne_zero_iff]
theorem degree_eq_zero_iff_totalDegree_eq_zero {f : MvPolynomial σ R} :
m.degree f = 0 ↔ f.totalDegree = 0 := by
rw [← m.toSyn.injective.eq_iff]
rw [map_zero, ← m.bot_eq_zero, eq_bot_iff, m.bot_eq_zero, ← m.toSyn.map_zero]
rw [degree_le_iff]
rw [totalDegree_eq_zero_iff]
apply forall_congr'
intro d
apply imp_congr (rfl.to_iff)
rw [map_zero, ← m.bot_eq_zero, ← eq_bot_iff, m.bot_eq_zero]
simp only [EmbeddingLike.map_eq_zero_iff]
exact Finsupp.ext_iff
@[simp]
theorem degree_C (r : R) :
m.degree (C r) = 0 := by
rw [degree_eq_zero_iff_totalDegree_eq_zero, totalDegree_C]
theorem eq_C_of_degree_eq_zero {f : MvPolynomial σ R} (hf : m.degree f = 0) :
f = C (m.leadingCoeff f) := by
ext d
simp only [leadingCoeff, hf]
classical
by_cases hd : d = 0
· simp [hd]
· rw [coeff_C, if_neg (Ne.symm hd)]
apply coeff_eq_zero_of_lt (m := m)
rw [hf, map_zero, lt_iff_le_and_ne, ne_eq, eq_comm, EmbeddingLike.map_eq_zero_iff]
exact ⟨bot_le, hd⟩
theorem degree_eq_zero_iff {f : MvPolynomial σ R} :
m.degree f = 0 ↔ f = C (m.leadingCoeff f) :=
⟨MonomialOrder.eq_C_of_degree_eq_zero, fun h => by rw [h, MonomialOrder.degree_C]⟩
theorem degree_add_le {f g : MvPolynomial σ R} :
m.toSyn (m.degree (f + g)) ≤ m.toSyn (m.degree f) ⊔ m.toSyn (m.degree g) := by
conv_rhs => rw [← m.toSyn.apply_symm_apply (_ ⊔ _)]
rw [degree_le_iff]
simp only [AddEquiv.apply_symm_apply, le_sup_iff]
intro b hb
by_cases hf : b ∈ f.support
· left
exact m.le_degree hf
· right
apply m.le_degree
simp only [notMem_support_iff] at hf
simpa only [mem_support_iff, coeff_add, hf, zero_add] using hb
theorem degree_sum_le {α : Type*} {s : Finset α} {f : α → MvPolynomial σ R} :
(m.toSyn <| m.degree <| ∑ x ∈ s, f x) ≤ s.sup fun x ↦ (m.toSyn <| m.degree <| f x) := by
induction s using Finset.cons_induction_on with
| empty => simp
| cons a s haA h =>
rw [Finset.sum_cons, Finset.sup_cons]
exact le_trans m.degree_add_le (max_le_max le_rfl h)
theorem degree_add_of_lt {f g : MvPolynomial σ R} (h : m.degree g ≺[m] m.degree f) :
m.degree (f + g) = m.degree f := by
apply m.toSyn.injective
apply le_antisymm
· apply le_trans degree_add_le
simp only [sup_le_iff, le_refl, true_and, le_of_lt h]
· apply le_degree
rw [mem_support_iff, coeff_add, m.coeff_eq_zero_of_lt h, add_zero,
← leadingCoeff, leadingCoeff_ne_zero_iff]
intro hf
rw [← not_le, hf] at h
apply h
simp only [degree_zero, map_zero]
apply bot_le
theorem degree_add_eq_right_of_lt {f g : MvPolynomial σ R} (h : m.degree f ≺[m] m.degree g) :
m.degree (f + g) = m.degree g := by
rw [add_comm]
exact degree_add_of_lt h
theorem leadingCoeff_add_of_lt {f g : MvPolynomial σ R} (h : m.degree g ≺[m] m.degree f) :
m.leadingCoeff (f + g) = m.leadingCoeff f := by
simp only [leadingCoeff, m.degree_add_of_lt h, coeff_add, coeff_eq_zero_of_lt h, add_zero]
theorem Monic.add_of_lt {f g : MvPolynomial σ R} (hf : m.Monic f) (h : m.degree g ≺[m] m.degree f) :
m.Monic (f + g) := by
simp only [Monic, leadingCoeff_add_of_lt h, hf.leadingCoeff_eq_one]
theorem degree_add_of_ne {f g : MvPolynomial σ R}
(h : m.degree f ≠ m.degree g) :
m.toSyn (m.degree (f + g)) = m.toSyn (m.degree f) ⊔ m.toSyn (m.degree g) := by
by_cases h' : m.degree g ≺[m] m.degree f
· simp [degree_add_of_lt h', le_of_lt h']
· rw [not_lt, le_iff_eq_or_lt, Classical.or_iff_not_imp_left, EmbeddingLike.apply_eq_iff_eq] at h'
rw [add_comm, degree_add_of_lt (h' h), right_eq_sup]
simp only [le_of_lt (h' h)]
theorem degree_mul_le {f g : MvPolynomial σ R} :
m.degree (f * g) ≼[m] m.degree f + m.degree g := by
classical
rw [degree_le_iff]
intro c
rw [← not_lt, mem_support_iff, not_imp_not]
intro hc
rw [coeff_mul]
apply Finset.sum_eq_zero
rintro ⟨d, e⟩ hde
simp only [Finset.mem_antidiagonal] at hde
dsimp only
by_cases hd : m.degree f ≺[m] d
· rw [m.coeff_eq_zero_of_lt hd, zero_mul]
· suffices m.degree g ≺[m] e by
rw [m.coeff_eq_zero_of_lt this, mul_zero]
simp only [not_lt] at hd
apply lt_of_add_lt_add_left (a := m.toSyn d)
grw [← map_add _ _ e, hd, ← map_add, hde]
exact hc
/-- Multiplicativity of leading coefficients -/
theorem coeff_mul_of_add_of_degree_le {f g : MvPolynomial σ R} {a b : σ →₀ ℕ}
(ha : m.degree f ≼[m] a) (hb : m.degree g ≼[m] b) :
(f * g).coeff (a + b) = f.coeff a * g.coeff b := by
classical
rw [coeff_mul, Finset.sum_eq_single (a,b)]
· rintro ⟨c, d⟩ hcd h
simp only [Finset.mem_antidiagonal] at hcd
by_cases hf : m.degree f ≺[m] c
· rw [m.coeff_eq_zero_of_lt hf, zero_mul]
· suffices m.degree g ≺[m] d by
rw [coeff_eq_zero_of_lt this, mul_zero]
rw [not_lt] at hf
rw [← not_le]
intro hf'
apply h
suffices c = a by
simpa [Prod.mk.injEq, this] using hcd
apply m.toSyn.injective
apply le_antisymm (le_trans hf ha)
apply le_of_add_le_add_right (a := m.toSyn b)
rw [← map_add, ← hcd, map_add]
simp only [add_le_add_iff_left]
exact le_trans hf' hb
· simp
/-- Multiplicativity of leading coefficients -/
theorem coeff_mul_of_degree_add {f g : MvPolynomial σ R} :
(f * g).coeff (m.degree f + m.degree g) = m.leadingCoeff f * m.leadingCoeff g :=
coeff_mul_of_add_of_degree_le (le_of_eq rfl) (le_of_eq rfl)
/-- Monomial degree of product -/
theorem degree_mul_of_mul_leadingCoeff_ne_zero {f g : MvPolynomial σ R}
(hfg : m.leadingCoeff f * m.leadingCoeff g ≠ 0) :
m.degree (f * g) = m.degree f + m.degree g := by
apply m.toSyn.injective
apply le_antisymm degree_mul_le
apply le_degree
rw [mem_support_iff, coeff_mul_of_degree_add]
exact hfg
/-- Multiplicativity of leading coefficients -/
theorem leadingCoeff_mul_of_mul_leadingCoeff_ne_zero {f g : MvPolynomial σ R}
(hfg : m.leadingCoeff f * m.leadingCoeff g ≠ 0) :
m.leadingCoeff (f * g) = m.leadingCoeff f * m.leadingCoeff g := by
rw [leadingCoeff, ← coeff_mul_of_degree_add, degree_mul_of_mul_leadingCoeff_ne_zero hfg]
/-- Monomial degree of product -/
theorem degree_mul_of_isRegular_left {f g : MvPolynomial σ R}
(hf : IsRegular (m.leadingCoeff f)) (hg : g ≠ 0) :
m.degree (f * g) = m.degree f + m.degree g := by
apply degree_mul_of_mul_leadingCoeff_ne_zero
simp only [ne_eq, hf, IsRegular.left, IsLeftRegular.mul_left_eq_zero_iff,
leadingCoeff_eq_zero_iff]
exact hg
/-- Multiplicativity of leading coefficients -/
theorem leadingCoeff_mul_of_isRegular_left {f g : MvPolynomial σ R}
(hf : IsRegular (m.leadingCoeff f)) (hg : g ≠ 0) :
m.leadingCoeff (f * g) = m.leadingCoeff f * m.leadingCoeff g := by
simp only [leadingCoeff, degree_mul_of_isRegular_left hf hg, coeff_mul_of_degree_add]
/-- Monomial degree of product -/
theorem degree_mul_of_isRegular_right {f g : MvPolynomial σ R}
(hf : f ≠ 0) (hg : IsRegular (m.leadingCoeff g)) :
m.degree (f * g) = m.degree f + m.degree g := by
rw [mul_comm, m.degree_mul_of_isRegular_left hg hf, add_comm]
/-- Multiplicativity of leading coefficients -/
theorem leadingCoeff_mul_of_isRegular_right {f g : MvPolynomial σ R}
(hf : f ≠ 0) (hg : IsRegular (m.leadingCoeff g)) :
m.leadingCoeff (f * g) = m.leadingCoeff f * m.leadingCoeff g := by
simp only [leadingCoeff, degree_mul_of_isRegular_right hf hg, coeff_mul_of_degree_add]
theorem Monic.mul {f g : MvPolynomial σ R} (hf : m.Monic f) (hg : m.Monic g) :
m.Monic (f * g) := by
nontriviality R
suffices m.leadingCoeff f * m.leadingCoeff g = 1 by
rw [Monic, MonomialOrder.leadingCoeff,
degree_mul_of_mul_leadingCoeff_ne_zero, coeff_mul_of_degree_add, this]
rw [this]
exact one_ne_zero
rw [hf.leadingCoeff_eq_one, hg.leadingCoeff_eq_one, one_mul]
/-- Monomial degree of product -/
theorem degree_mul [IsCancelMulZero R] {f g : MvPolynomial σ R} (hf : f ≠ 0) (hg : g ≠ 0) :
m.degree (f * g) = m.degree f + m.degree g :=
degree_mul_of_isRegular_left (isRegular_of_ne_zero (leadingCoeff_ne_zero_iff.mpr hf)) hg
/-- Multiplicativity of leading coefficients -/
theorem leadingCoeff_mul [IsCancelMulZero R] {f g : MvPolynomial σ R} (hf : f ≠ 0) (hg : g ≠ 0) :
m.leadingCoeff (f * g) = m.leadingCoeff f * m.leadingCoeff g := by
rw [leadingCoeff, degree_mul hf hg, ← coeff_mul_of_degree_add]
/-- Monomial degree of powers -/
theorem degree_pow_le {f : MvPolynomial σ R} (n : ℕ) :
m.degree (f ^ n) ≼[m] n • (m.degree f) := by
induction n with
| zero => simp [m.degree_one]
| succ n hrec =>
simp only [pow_add, pow_one, add_smul, one_smul]
apply le_trans m.degree_mul_le
simp only [map_add, add_le_add_iff_right]
exact hrec
theorem coeff_pow_nsmul_degree (f : MvPolynomial σ R) (n : ℕ) :
(f ^ n).coeff (n • m.degree f) = m.leadingCoeff f ^ n := by
induction n with
| zero => simp
| succ n hrec =>
simp only [add_smul, one_smul, pow_add, pow_one]
rw [m.coeff_mul_of_add_of_degree_le (m.degree_pow_le _) le_rfl, hrec, leadingCoeff]
/-- Monomial degree of powers -/
theorem degree_pow_of_pow_leadingCoeff_ne_zero {f : MvPolynomial σ R} {n : ℕ}
(hf : m.leadingCoeff f ^ n ≠ 0) :
m.degree (f ^ n) = n • m.degree f := by
apply m.toSyn.injective
apply le_antisymm (m.degree_pow_le n)
apply le_degree
rw [mem_support_iff, coeff_pow_nsmul_degree]
exact hf
/-- Leading coefficient of powers -/
theorem leadingCoeff_pow_of_pow_leadingCoeff_ne_zero {f : MvPolynomial σ R} {n : ℕ}
(hf : m.leadingCoeff f ^ n ≠ 0) :
m.leadingCoeff (f ^ n) = m.leadingCoeff f ^ n := by
rw [leadingCoeff, degree_pow_of_pow_leadingCoeff_ne_zero hf, coeff_pow_nsmul_degree]
protected theorem Monic.pow {f : MvPolynomial σ R} {n : ℕ} (hf : m.Monic f) :
m.Monic (f ^ n) := by
nontriviality R
rw [Monic, leadingCoeff_pow_of_pow_leadingCoeff_ne_zero, hf.leadingCoeff_eq_one, one_pow]
rw [hf.leadingCoeff_eq_one, one_pow]
exact one_ne_zero
/-- Monomial degree of powers (in a reduced ring) -/
theorem degree_pow [IsReduced R] (f : MvPolynomial σ R) (n : ℕ) :
m.degree (f ^ n) = n • m.degree f := by
by_cases hf : f = 0
· rw [hf, degree_zero, smul_zero]
by_cases hn : n = 0
· rw [hn, pow_zero, degree_one]
· rw [zero_pow hn, degree_zero]
nontriviality R
apply degree_pow_of_pow_leadingCoeff_ne_zero
apply IsReduced.pow_ne_zero
rw [leadingCoeff_ne_zero_iff]
exact hf
/-- Leading coefficient of powers (in a reduced ring) -/
theorem leadingCoeff_pow [IsReduced R] (f : MvPolynomial σ R) (n : ℕ) :
m.leadingCoeff (f ^ n) = m.leadingCoeff f ^ n := by
rw [leadingCoeff, degree_pow, coeff_pow_nsmul_degree]
theorem degree_smul_le {r : R} {f : MvPolynomial σ R} :
m.degree (r • f) ≼[m] m.degree f := by
rw [smul_eq_C_mul]
apply le_of_le_of_eq degree_mul_le
simp
theorem degree_smul {r : R} (hr : IsRegular r) {f : MvPolynomial σ R} :
m.degree (r • f) = m.degree f := by
by_cases hf : f = 0
· simp [hf]
apply m.toSyn.injective
apply le_antisymm degree_smul_le
apply le_degree
simp only [mem_support_iff, smul_eq_C_mul]
rw [← zero_add (degree m f), ← degree_C r, coeff_mul_of_degree_add]
simp [leadingCoeff, hr.left.mul_left_eq_zero_iff, hf]
theorem degree_prod_le {ι : Type*} {P : ι → MvPolynomial σ R} {s : Finset ι} :
m.degree (∏ i ∈ s, P i) ≼[m] ∑ i ∈ s, m.degree (P i) := by
classical
induction s using Finset.induction_on with
| empty =>
simp only [Finset.prod_empty, Finset.sum_empty]
rw [← C_1, m.degree_C, map_zero]
| insert a s has hrec =>
rw [Finset.prod_insert has, Finset.sum_insert has]
apply le_trans degree_mul_le
simp only [map_add, add_le_add_iff_left, hrec]
theorem coeff_prod_sum_degree {ι : Type*} (P : ι → MvPolynomial σ R) (s : Finset ι) :
coeff (∑ i ∈ s, m.degree (P i)) (∏ i ∈ s, P i) = ∏ i ∈ s, m.leadingCoeff (P i) := by
classical
induction s using Finset.induction_on with
| empty => simp
| insert a s has hrec =>
simp only [Finset.prod_insert has, Finset.sum_insert has]
rw [coeff_mul_of_add_of_degree_le (le_of_eq rfl) degree_prod_le]
exact congr_arg₂ _ rfl hrec
-- TODO : it suffices that all leading coefficients but one are regular
theorem degree_prod_of_regular {ι : Type*}
{P : ι → MvPolynomial σ R} {s : Finset ι} (H : ∀ i ∈ s, IsRegular (m.leadingCoeff (P i))) :
m.degree (∏ i ∈ s, P i) = ∑ i ∈ s, m.degree (P i) := by
cases subsingleton_or_nontrivial R with
| inl _ => simp [Subsingleton.elim _ (0 : MvPolynomial σ R)]
| inr _ =>
apply m.toSyn.injective
refine le_antisymm degree_prod_le (m.le_degree ?_)
rw [mem_support_iff, m.coeff_prod_sum_degree]
exact (IsRegular.prod H).ne_zero
theorem degree_prod [IsCancelMulZero R] {ι : Type*} {P : ι → MvPolynomial σ R} {s : Finset ι}
(H : ∀ i ∈ s, P i ≠ 0) :
m.degree (∏ i ∈ s, P i) = ∑ i ∈ s, m.degree (P i) := by
apply degree_prod_of_regular
intro i hi
apply isRegular_of_ne_zero
rw [leadingCoeff_ne_zero_iff]
exact H i hi
-- TODO : it suffices that all leading coefficients but one are regular
theorem leadingCoeff_prod_of_regular {ι : Type*}
{P : ι → MvPolynomial σ R} {s : Finset ι} (H : ∀ i ∈ s, IsRegular (m.leadingCoeff (P i))) :
m.leadingCoeff (∏ i ∈ s, P i) = ∏ i ∈ s, m.leadingCoeff (P i) := by
simp only [leadingCoeff, degree_prod_of_regular H, coeff_prod_sum_degree]
/-- A product of monic polynomials is monic -/
protected theorem Monic.prod {ι : Type*} {P : ι → MvPolynomial σ R} {s : Finset ι}
(H : ∀ i ∈ s, m.Monic (P i)) :
m.Monic (∏ i ∈ s, P i) := by
rw [Monic, leadingCoeff_prod_of_regular]
· exact Finset.prod_eq_one H
· intro i hi
rw [(H i hi).leadingCoeff_eq_one]
exact isRegular_one
end Semiring
section Ring
variable {R : Type*} [CommRing R]
@[simp]
theorem degree_neg {f : MvPolynomial σ R} :
m.degree (-f) = m.degree f := by
unfold degree
rw [support_neg]
@[simp]
theorem leadingCoeff_neg {f : MvPolynomial σ R} :
m.leadingCoeff (-f) = - m.leadingCoeff f := by
simp only [leadingCoeff, degree_neg, coeff_neg]
theorem degree_sub_le {f g : MvPolynomial σ R} :
m.toSyn (m.degree (f - g)) ≤ m.toSyn (m.degree f) ⊔ m.toSyn (m.degree g) := by
rw [sub_eq_add_neg]
apply le_of_le_of_eq m.degree_add_le
rw [degree_neg]
theorem degree_sub_of_lt {f g : MvPolynomial σ R} (h : m.degree g ≺[m] m.degree f) :
m.degree (f - g) = m.degree f := by
rw [sub_eq_add_neg]
apply degree_add_of_lt
simp only [degree_neg, h]
theorem leadingCoeff_sub_of_lt {f g : MvPolynomial σ R} (h : m.degree g ≺[m] m.degree f) :
m.leadingCoeff (f - g) = m.leadingCoeff f := by
rw [sub_eq_add_neg]
apply leadingCoeff_add_of_lt
simp only [degree_neg, h]
end Ring
section Field
variable {R : Type*} [Field R]
theorem isUnit_leadingCoeff {f : MvPolynomial σ R} :
IsUnit (m.leadingCoeff f) ↔ f ≠ 0 := by
simp only [isUnit_iff_ne_zero, ne_eq, leadingCoeff_eq_zero_iff]
end Field
section Binomial
variable {R : Type*} [CommRing R]
open Finsupp MvPolynomial
lemma degree_X_add_C [Nontrivial R]
{ι : Type*} (m : MonomialOrder ι) (i : ι) (r : R) :
m.degree (X i + C r) = single i 1 := by
rw [degree_add_of_lt, degree_X]
simp only [degree_C, map_zero, degree_X]
rw [← bot_eq_zero, bot_lt_iff_ne_bot, bot_eq_zero, ← map_zero m.toSyn]
simp
lemma degree_X_sub_C [Nontrivial R]
{ι : Type*} (m : MonomialOrder ι) (i : ι) (r : R) :
m.degree (X i - C r) = single i 1 := by
rw [sub_eq_add_neg, ← map_neg, degree_X_add_C]
lemma monic_X_add_C {ι : Type*} (m : MonomialOrder ι) (i : ι) (r : R) :
m.Monic (X i + C r) := by
nontriviality R
apply monic_X.add_of_lt
simp [degree_C, degree_X, ← not_le, ← eq_zero_iff]
lemma monic_X_sub_C {ι : Type*} (m : MonomialOrder ι) (i : ι) (r : R) :
m.Monic (X i - C r) := by
rw [sub_eq_add_neg, ← map_neg]
apply monic_X_add_C
end Binomial
end MonomialOrder |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/MonomialOrder/DegLex.lean | import Mathlib.RingTheory.MvPolynomial.MonomialOrder
import Mathlib.Data.Finsupp.MonomialOrder.DegLex
/-! # Some lemmas about the degree lexicographic monomial order on multivariate polynomials -/
namespace MvPolynomial
open MonomialOrder Finsupp
open scoped MonomialOrder
variable {σ : Type*} {R : Type*} [CommSemiring R] {f g : MvPolynomial σ R}
section LinearOrder
variable [LinearOrder σ] [WellFoundedGT σ]
theorem degree_degLexDegree : (degLex.degree f).degree = f.totalDegree := by
by_cases hf : f = 0
· simp [hf]
apply le_antisymm
· exact le_totalDegree (degLex.degree_mem_support hf)
· unfold MvPolynomial.totalDegree
apply Finset.sup_le
intro b hb
exact DegLex.monotone_degree (degLex.le_degree hb)
theorem degLex_totalDegree_monotone (h : degLex.degree f ≼[degLex] degLex.degree g) :
f.totalDegree ≤ g.totalDegree := by
simp only [← MvPolynomial.degree_degLexDegree]
exact DegLex.monotone_degree h
end LinearOrder
theorem totalDegree_mul_of_isDomain [IsCancelMulZero R] (hf : f ≠ 0) (hg : g ≠ 0) :
totalDegree (f * g) = totalDegree f + totalDegree g := by
cases exists_wellOrder σ
rw [← degree_degLexDegree (σ := σᵒᵈ), ← degree_degLexDegree (σ := σᵒᵈ),
← degree_degLexDegree (σ := σᵒᵈ), MonomialOrder.degree_mul hf hg]
simp
end MvPolynomial |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/Symmetric/FundamentalTheorem.lean | import Mathlib.RingTheory.MvPolynomial.Symmetric.Defs
import Mathlib.RingTheory.MvPolynomial.Tower
import Mathlib.Data.Finsupp.Notation
import Mathlib.Data.Finsupp.WellFounded
/-!
# The Fundamental Theorem of Symmetric Polynomials
In a polynomial ring in `n` variables over a commutative ring, the subalgebra of symmetric
polynomials is freely generated by the first `n` elementary symmetric polynomials (excluding
the 0th, which is simply 1). This is expressed as an isomorphism
`MvPolynomial.esymmAlgEquiv` between `MvPolynomial (Fin n) R` and
the symmetric subalgebra of any polynomial ring `MvPolynomial σ R` with `#σ = n`.
The forward map is called `MvPolynomial.esymmAlgHom`.
## Proof strategy
We follow the alternative proof on the Wikipedia page
https://en.wikipedia.org/wiki/Elementary_symmetric_polynomial#Alternative_proof
It suffices to show `esymmAlgHom` is both injective and surjective.
Endow the Fintype `σ` with a linear order and endow the (monic) monomials in the polynomial ring
`MvPolynomial σ R` with the lexicographic order on `σ →₀ ℕ`, which is a well order.
Then any nonzero polynomial `p : MvPolynomial σ R` has a largest nonzero monomial
(`AddMonoidAlgebra.supDegree toLex p`) and the corresponding coefficient is
`AddMonoidAlgebra.leadingCoeff toLex p`. If `p` is symmetric, any permutation of a nonzero monomial
in `p` must also be a nonzero monomial in `p`, so the largest nonzero monomial must be antitone
as a function `σ → ℕ` (`MvPolynomial.IsSymmetric.antitone_supDegree`). We can then construct a
monomial in `MvPolynomial (Fin n) R` whose image under `esymmAlgHom` has the same `supDegree` and
`leadingCoeff` as `p`: `MvPolynomial.supDegree_esymmAlgHomMonomial` says that the `supDegree` of
the image is given by `Fin.accumulate`, and `Fin.accumulate_invAccumulate` says that
`Fin.invAccumulate` is inverse to `Fin.accumulate` for antitone monomials.
If we subtract the image from `p`, we are left with a symmetric polynomial of
lower `supDegree`, which we may assume to be in the image by induction,
thanks to the well-orderedness of `Lex (σ →₀ ℕ)`; the surjectivity of `esymmAlgHom`
follows. For injectivity, just notice that the images of different monic monomials in
`MvPolynomial (Fin n) R` have different `supDegree` (`Fin.accumulate_injective`), so if there is
at least one nonzero monomial, the images cannot all cancel out
(`AddMonoidAlgebra.sum_ne_zero_of_injOn_supDegree`).
We actually only define `Fin.accumulate` in the case `σ := Fin m` rather than an arbitrary Fintype
with a linear order; we show that `esymmAlgHom` is in fact surjective whenever `m ≤ n` and
injective whenever `n ≤ m`, and then transfer the results to any Fintype `σ`. See
`MvPolynomial.injective_esymmAlgHom` and `MvPolynomial.esymmAlgHom_surjective`.
-/
variable {σ τ R : Type*} {n m k : ℕ}
open AddMonoidAlgebra Finset
namespace Fin
section accumulate
/-- The `j`th entry of `accumulate n m t` is the sum of `t i` over all `i ≥ j`. -/
@[simps] def accumulate (n m : ℕ) : (Fin n → ℕ) →+ (Fin m → ℕ) where
toFun t j := ∑ i : Fin n with j.val ≤ i.val, t i
map_zero' := funext <| fun _ ↦ sum_eq_zero <| fun _ _ ↦ rfl
map_add' _ _ := funext <| fun _ ↦ sum_add_distrib
/-- The `i`th entry of `invAccumulate n m s` is `s i - s (i+1)`, where `s j = 0` if `j ≥ m`. -/
def invAccumulate (n m : ℕ) (s : Fin m → ℕ) (i : Fin n) : ℕ :=
(if hi : i < m then s ⟨i, hi⟩ else 0) - (if hi : i + 1 < m then s ⟨i + 1, hi⟩ else 0)
lemma accumulate_rec {i n m : ℕ} (hin : i < n) (him : i + 1 < m) (t : Fin n → ℕ) :
accumulate n m t ⟨i, Nat.lt_of_succ_lt him⟩ = t ⟨i, hin⟩ + accumulate n m t ⟨i + 1, him⟩ := by
simp_rw [accumulate_apply]
convert (add_sum_erase _ _ _).symm
· ext
rw [mem_erase]
simp_rw [mem_filter_univ, i.succ_le_iff, lt_iff_le_and_ne]
rw [and_comm, ne_comm, ← Fin.val_ne_iff]
· exact mem_filter.2 ⟨mem_univ _, le_rfl⟩
lemma accumulate_last {i n m : ℕ} (hin : i < n) (hmi : m = i + 1) (t : Fin n → ℕ)
(ht : ∀ j : Fin n, m ≤ j → t j = 0) :
accumulate n m t ⟨i, i.lt_succ_self.trans_eq hmi.symm⟩ = t ⟨i, hin⟩ := by
rw [accumulate_apply]
apply sum_eq_single_of_mem
· rw [mem_filter]; exact ⟨mem_univ _, le_rfl⟩
refine fun j hij hji ↦ ht j ?_
rw [mem_filter_univ] at hij
exact hmi.trans_le (hij.lt_of_ne (Fin.val_ne_iff.2 hji).symm).nat_succ_le
lemma accumulate_injective {n m} (hnm : n ≤ m) : Function.Injective (accumulate n m) := by
refine fun t s he ↦ funext fun i ↦ ?_
obtain h | h := lt_or_ge (i.1 + 1) m
· have := accumulate_rec i.2 h s
rwa [← he, accumulate_rec i.2 h t, add_right_cancel_iff] at this
· have := h.antisymm (i.2.nat_succ_le.trans hnm)
rw [← accumulate_last i.2 this t, ← accumulate_last i.2 this s, he]
iterate 2 { intro j hj; exact ((j.2.trans_le hnm).not_ge hj).elim }
lemma accumulate_invAccumulate {n m} (hmn : m ≤ n) {s : Fin m → ℕ} (hs : Antitone s) :
accumulate n m (invAccumulate n m s) = s := funext <| fun ⟨i, hi⟩ ↦ by
have := Nat.le_sub_one_of_lt hi
revert hi
refine Nat.decreasingInduction' (fun i hi _ ih him ↦ ?_) this fun hm ↦ ?_
· rw [← Nat.pred_eq_sub_one, Nat.lt_pred_iff, Nat.succ_eq_add_one] at hi
rw [accumulate_rec (him.trans_le hmn) hi, ih hi, invAccumulate, dif_pos him, dif_pos hi]
simp only
exact Nat.sub_add_cancel (hs i.le_succ)
· have := (Nat.sub_one_add_one <| Nat.ne_zero_of_lt hm).symm
rw [accumulate_last (hm.trans_le hmn) this, invAccumulate, dif_pos hm, dif_neg this.not_gt,
Nat.sub_zero]
intro j hj
rw [invAccumulate, dif_neg hj.not_gt, Nat.zero_sub]
end accumulate
end Fin
namespace MvPolynomial
open Fin
section CommSemiring
variable [CommSemiring R] [Fintype σ] [Fintype τ]
variable (σ R n) in
/-- The `R`-algebra homomorphism from $R[x_1,\dots,x_n]$ to the symmetric subalgebra of
$R[\{x_i \mid i ∈ σ\}]$ sending $x_i$ to the $i$-th elementary symmetric polynomial. -/
noncomputable def esymmAlgHom :
MvPolynomial (Fin n) R →ₐ[R] symmetricSubalgebra σ R :=
aeval (fun i ↦ ⟨esymm σ R (i + 1), esymm_isSymmetric σ R _⟩)
lemma esymmAlgHom_apply (p : MvPolynomial (Fin n) R) :
(esymmAlgHom σ R n p).val = aeval (fun i : Fin n ↦ esymm σ R (i + 1)) p :=
(Subalgebra.mvPolynomial_aeval_coe _ _ _).symm
lemma rename_esymmAlgHom (e : σ ≃ τ) :
(renameSymmetricSubalgebra e).toAlgHom.comp (esymmAlgHom σ R n) = esymmAlgHom τ R n := by
ext i : 2
simp_rw [AlgHom.comp_apply, esymmAlgHom, aeval_X, AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe,
renameSymmetricSubalgebra_apply_coe, rename_esymm]
variable (σ) in
/-- The image of a monomial under `esymmAlgHom`. -/
noncomputable def esymmAlgHomMonomial (t : Fin n →₀ ℕ) (r : R) :
MvPolynomial σ R := (esymmAlgHom σ R n <| monomial t r).val
variable {i : Fin n} {r : R}
lemma isSymmetric_esymmAlgHomMonomial (t : Fin n →₀ ℕ) (r : R) :
(esymmAlgHomMonomial σ t r).IsSymmetric := (esymmAlgHom _ _ _ _).2
lemma esymmAlgHomMonomial_single :
esymmAlgHomMonomial σ (Finsupp.single i k) r = C r * esymm σ R (i + 1) ^ k := by
rw [esymmAlgHomMonomial, esymmAlgHom_apply, aeval_monomial, algebraMap_eq,
Finsupp.prod_single_index]
exact pow_zero _
lemma esymmAlgHomMonomial_single_one :
esymmAlgHomMonomial σ (Finsupp.single i k) 1 = esymm σ R (i + 1) ^ k := by
rw [esymmAlgHomMonomial_single, map_one, one_mul]
lemma esymmAlgHomMonomial_add {t s : Fin n →₀ ℕ} :
esymmAlgHomMonomial σ (t + s) r = esymmAlgHomMonomial σ t r * esymmAlgHomMonomial σ s 1 := by
simp_rw [esymmAlgHomMonomial, esymmAlgHom_apply, ← map_mul, monomial_mul, mul_one]
lemma esymmAlgHom_zero : esymmAlgHomMonomial σ (0 : Fin n →₀ ℕ) r = C r := by
rw [esymmAlgHomMonomial, monomial_zero', esymmAlgHom_apply, aeval_C, algebraMap_eq]
private lemma supDegree_monic_esymm [Nontrivial R] {i : ℕ} (him : i < m) :
supDegree toLex (esymm (Fin m) R (i + 1)) =
toLex (Finsupp.indicator (Iic ⟨i, him⟩) fun _ _ ↦ 1) ∧
Monic toLex (esymm (Fin m) R (i + 1)) := by
have := supDegree_leadingCoeff_sum_eq (D := toLex) (s := univ.powersetCard (i + 1))
(i := Iic (⟨i, him⟩ : Fin m)) ?_ (f := fun s ↦ monomial (∑ j ∈ s, fun₀ | j => 1) (1 : R)) ?_
· rwa [← esymm_eq_sum_monomial, ← Finsupp.indicator_eq_sum_single, ← single_eq_monomial,
supDegree_single_ne_zero _ one_ne_zero, leadingCoeff_single toLex.injective] at this
· exact mem_powersetCard.2 ⟨subset_univ _, Fin.card_Iic _⟩
intro t ht hne
have ht' : #t = #(Iic (⟨i, him⟩ : Fin m)) := by
rw [(mem_powersetCard.1 ht).2, Fin.card_Iic]
simp_rw [← single_eq_monomial, supDegree_single_ne_zero _ one_ne_zero,
← Finsupp.indicator_eq_sum_single]
rw [ne_comm, Ne, ← subset_iff_eq_of_card_le ht'.le, not_subset] at hne
simp_rw [← mem_sdiff] at hne
have hkm := mem_sdiff.1 (min'_mem _ hne)
refine ⟨min' _ hne, fun k hk ↦ ?_, ?_⟩
all_goals simp only [ofLex_toLex, Finsupp.indicator_apply]
· have hki := mem_Iic.2 (hk.le.trans <| mem_Iic.1 hkm.1)
rw [dif_pos hki, dif_pos]
by_contra h
exact lt_irrefl k <| ((lt_min'_iff _ _).1 hk) _ <| mem_sdiff.2 ⟨hki, h⟩
· rw [dif_neg hkm.2, dif_pos hkm.1]; exact Nat.zero_lt_one
lemma supDegree_esymm [Nontrivial R] (him : i < m) :
ofLex (supDegree toLex <| esymm (Fin m) R (i + 1)) = accumulate n m (Finsupp.single i 1) := by
rw [(supDegree_monic_esymm him).1, ofLex_toLex]
ext j
simp_rw [Finsupp.indicator_apply, dite_eq_ite, mem_Iic, accumulate_apply, Finsupp.single_apply,
sum_ite_eq, mem_filter_univ, Fin.le_def]
lemma monic_esymm {i : ℕ} (him : i ≤ m) : Monic toLex (esymm (Fin m) R i) := by
cases i with
| zero =>
rw [esymm_zero]
exact monic_one toLex.injective
| succ i =>
nontriviality R
exact (supDegree_monic_esymm him).2
lemma leadingCoeff_esymmAlgHomMonomial (t : Fin n →₀ ℕ) (hnm : n ≤ m) :
leadingCoeff toLex (esymmAlgHomMonomial (Fin m) t r) = r := by
induction t using Finsupp.induction₂ with
| zero => rw [esymmAlgHom_zero, leadingCoeff_toLex_C]
| add_single i _ _ _ _ ih =>
rw [esymmAlgHomMonomial_add, esymmAlgHomMonomial_single_one,
((monic_esymm <| i.2.trans_le hnm).pow toLex_add toLex.injective).leadingCoeff_mul_eq_left,
ih]
exacts [toLex.injective, toLex_add]
lemma supDegree_esymmAlgHomMonomial (hr : r ≠ 0) (t : Fin n →₀ ℕ) (hnm : n ≤ m) :
ofLex (supDegree toLex <| esymmAlgHomMonomial (Fin m) t r) = accumulate n m t := by
nontriviality R
induction t using Finsupp.induction₂ with
| zero => simp_rw [esymmAlgHom_zero, supDegree_toLex_C, ofLex_zero, Finsupp.coe_zero, map_zero]
| add_single i _ _ _ _ ih =>
have := i.2.trans_le hnm
rw [esymmAlgHomMonomial_add, esymmAlgHomMonomial_single_one,
Monic.supDegree_mul_of_ne_zero_left toLex.injective toLex_add, ofLex_add, Finsupp.coe_add,
ih, Finsupp.coe_add, map_add, Monic.supDegree_pow rfl toLex_add toLex.injective, ofLex_smul,
Finsupp.coe_smul, supDegree_esymm this, ← map_nsmul, ← Finsupp.coe_smul,
Finsupp.smul_single, nsmul_one, Nat.cast_id]
· exact monic_esymm this
· exact (monic_esymm this).pow toLex_add toLex.injective
· rwa [Ne, ← leadingCoeff_eq_zero toLex.injective, leadingCoeff_esymmAlgHomMonomial _ hnm]
omit [Fintype σ] in
lemma IsSymmetric.antitone_supDegree [LinearOrder σ] {p : MvPolynomial σ R} (hp : p.IsSymmetric) :
Antitone ↑(ofLex <| p.supDegree toLex) := by
obtain rfl | h0 := eq_or_ne p 0
· rw [supDegree_zero, Finsupp.bot_eq_zero]
exact Pi.zero_mono
rw [Antitone]
by_contra! h
obtain ⟨i, j, hle, hlt⟩ := h
apply (le_sup (s := p.support) (f := toLex) _).not_gt
pick_goal 3
· rw [← hp (Equiv.swap i j), mem_support_iff, coeff_rename_mapDomain _ (Equiv.injective _)]
rw [Ne, ← leadingCoeff_eq_zero toLex.injective, leadingCoeff_toLex] at h0
assumption
refine ⟨i, fun k hk ↦ ?_, ?_⟩
all_goals dsimp only [Pi.toLex_apply, ofLex_toLex]
· conv_rhs => rw [← Equiv.swap_apply_of_ne_of_ne hk.ne (hk.trans_le hle).ne]
rw [Finsupp.mapDomain_apply (Equiv.injective _), supDegree]; rfl
· apply hlt.trans_eq
simp_rw [Finsupp.mapDomain_equiv_apply, Equiv.symm_swap, Equiv.swap_apply_left]
end CommSemiring
section CommRing
variable (R)
variable [Fintype σ] [CommRing R]
/- Also holds for a cancellative CommSemiring. -/
lemma esymmAlgHom_fin_injective (h : n ≤ m) :
Function.Injective (esymmAlgHom (Fin m) R n) := by
rw [injective_iff_map_eq_zero]
refine fun p ↦ (fun hp ↦ ?_).mtr
rw [p.as_sum, map_sum (esymmAlgHom (Fin m) R n), ← Subalgebra.coe_eq_zero,
AddSubmonoidClass.coe_finset_sum]
refine sum_ne_zero_of_injOn_supDegree (D := toLex) (support_eq_empty.not.2 hp) (fun t ht ↦ ?_)
(fun t ht s hs he ↦ DFunLike.ext' <| accumulate_injective h ?_)
· rw [← esymmAlgHomMonomial, Ne, ← leadingCoeff_eq_zero toLex.injective,
leadingCoeff_esymmAlgHomMonomial t h]
rwa [mem_support_iff] at ht
rw [mem_coe, mem_support_iff] at ht hs
dsimp only [Function.comp] at he
rwa [← esymmAlgHomMonomial, ← esymmAlgHomMonomial, ← ofLex_inj, DFunLike.ext'_iff,
supDegree_esymmAlgHomMonomial ht t h, supDegree_esymmAlgHomMonomial hs s h] at he
lemma esymmAlgHom_injective (hn : n ≤ Fintype.card σ) :
Function.Injective (esymmAlgHom σ R n) := by
rw [← rename_esymmAlgHom (Fintype.equivFin σ).symm, AlgHom.coe_comp]
exact (AlgEquiv.injective _).comp (esymmAlgHom_fin_injective R hn)
lemma esymmAlgHom_fin_bijective (n : ℕ) :
Function.Bijective (esymmAlgHom (Fin n) R n) := by
use esymmAlgHom_fin_injective R le_rfl
rintro ⟨p, hp⟩
rw [← AlgHom.mem_range]
obtain rfl | h0 := eq_or_ne p 0
· exact Subalgebra.zero_mem _
induction he : p.supDegree toLex using WellFoundedLT.induction generalizing p with | _ t ih
subst he
let t := Finsupp.equivFunOnFinite.symm (invAccumulate n n <| ↑(ofLex <| p.supDegree toLex))
have hd :
(esymmAlgHomMonomial _ t <| p.leadingCoeff toLex).supDegree toLex = p.supDegree toLex := by
rw [← ofLex_inj, DFunLike.ext'_iff, supDegree_esymmAlgHomMonomial _ _ le_rfl]
· exact accumulate_invAccumulate le_rfl hp.antitone_supDegree
· rwa [Ne, leadingCoeff_eq_zero toLex.injective]
obtain he | hne := eq_or_ne p (esymmAlgHomMonomial _ t <| p.leadingCoeff toLex)
· convert AlgHom.mem_range_self _ (monomial t <| p.leadingCoeff toLex)
have := (supDegree_sub_lt_of_leadingCoeff_eq toLex.injective hd.symm ?_).resolve_right hne
· specialize ih _ this _ (Subalgebra.sub_mem _ hp <| isSymmetric_esymmAlgHomMonomial _ _) _ rfl
· rwa [sub_ne_zero]
convert ← Subalgebra.add_mem _ ih ⟨monomial t (p.leadingCoeff toLex), rfl⟩
apply sub_add_cancel p
· rw [leadingCoeff_esymmAlgHomMonomial t le_rfl]
lemma esymmAlgHom_fin_surjective (h : m ≤ n) :
Function.Surjective (esymmAlgHom (Fin m) R n) := by
intro p
obtain ⟨q, rfl⟩ := (esymmAlgHom_fin_bijective R m).2 p
rw [← AlgHom.mem_range]
induction q using MvPolynomial.induction_on with
| C r => rw [← algebraMap_eq, AlgHom.commutes]; apply Subalgebra.algebraMap_mem
| add p q hp hq => rw [map_add]; exact Subalgebra.add_mem _ hp hq
| mul_X p i hp =>
rw [map_mul]
apply Subalgebra.mul_mem _ hp
rw [AlgHom.mem_range]
refine ⟨X ⟨i, i.2.trans_le h⟩, ?_⟩
simp_rw [esymmAlgHom, aeval_X]
lemma esymmAlgHom_surjective (hn : Fintype.card σ ≤ n) :
Function.Surjective (esymmAlgHom σ R n) := by
rw [← rename_esymmAlgHom (Fintype.equivFin σ).symm, AlgHom.coe_comp]
exact (AlgEquiv.surjective _).comp (esymmAlgHom_fin_surjective R hn)
variable (σ) in
/-- If the cardinality of `σ` is `n`, then `esymmAlgHom σ R n` is an isomorphism. -/
@[simps! apply]
noncomputable def esymmAlgEquiv (hn : Fintype.card σ = n) :
MvPolynomial (Fin n) R ≃ₐ[R] symmetricSubalgebra σ R :=
AlgEquiv.ofBijective (esymmAlgHom σ R n)
⟨esymmAlgHom_injective R hn.ge, esymmAlgHom_surjective R hn.le⟩
lemma esymmAlgEquiv_symm_apply (hn : Fintype.card σ = n) (i : Fin n) :
(esymmAlgEquiv σ R hn).symm ⟨esymm σ R (i + 1), esymm_isSymmetric σ R _⟩ = X i := by
apply_fun esymmAlgHom σ R n using esymmAlgHom_injective R hn.ge
simp_rw [esymmAlgEquiv, AlgEquiv.ofBijective_apply_symm_apply, esymmAlgHom, aeval_X]
end CommRing
end MvPolynomial |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/Symmetric/NewtonIdentities.lean | import Mathlib.Algebra.Algebra.Subalgebra.Basic
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.Algebra.MvPolynomial.Rename
import Mathlib.Data.Fintype.Basic
import Mathlib.RingTheory.MvPolynomial.Symmetric.Defs
/-!
# Newton's Identities
This file defines `MvPolynomial` power sums as a means of implementing Newton's identities. The
combinatorial proof, due to Zeilberger, defines for `k : ℕ` a subset `pairs` of
`(range k).powerset × range k` and a map `pairMap` such that `pairMap` is an involution on `pairs`,
and a map `weight` which identifies elements of `pairs` with the terms of the summation in Newton's
identities and which satisfies `weight ∘ pairMap = -weight`. The result therefore follows neatly
from an identity implemented in mathlib as `Finset.sum_involution`. Namely, we use
`Finset.sum_involution` to show that `∑ t ∈ pairs σ k, weight σ R k t = 0`. We then identify
`(-1) ^ k * k * esymm σ R k` with the terms of the weight sum for which `t.fst` has
cardinality `k`, and `(-1) ^ i * esymm σ R i * psum σ R (k - i)` with the terms of the weight sum
for which `t.fst` has cardinality `i` for `i < k`, and we thereby derive the main result
`(-1) ^ k * k * esymm σ R k + ∑ i ∈ range k, (-1) ^ i * esymm σ R i * psum σ R (k - i) = 0` (or
rather, two equivalent forms which provide direct definitions for `esymm` and `psum` in lower-degree
terms).
## Main declarations
* `MvPolynomial.mul_esymm_eq_sum`: a recurrence relation for the `k`th elementary
symmetric polynomial in terms of lower-degree elementary symmetric polynomials and power sums.
* `MvPolynomial.psum_eq_mul_esymm_sub_sum`: a recurrence relation for the degree-`k` power sum
in terms of lower-degree elementary symmetric polynomials and power sums.
## References
See [zeilberger1984] for the combinatorial proof of Newton's identities.
-/
open Equiv (Perm)
open MvPolynomial
noncomputable section
namespace MvPolynomial
open Finset Nat
namespace NewtonIdentities
variable (σ : Type*) (R : Type*) [CommRing R]
section DecidableEq
variable [DecidableEq σ]
private def pairMap (t : Finset σ × σ) : Finset σ × σ :=
if h : t.snd ∈ t.fst then (t.fst.erase t.snd, t.snd) else (t.fst.cons t.snd h, t.snd)
private lemma pairMap_ne_self (t : Finset σ × σ) : pairMap σ t ≠ t := by
rw [pairMap]
split_ifs with h1
all_goals by_contra ht; rw [← ht] at h1; simp_all
private lemma pairMap_of_snd_mem_fst {t : Finset σ × σ} (h : t.snd ∈ t.fst) :
pairMap σ t = (t.fst.erase t.snd, t.snd) := by
simp [pairMap, h]
private lemma pairMap_of_snd_notMem_fst {t : Finset σ × σ} (h : t.snd ∉ t.fst) :
pairMap σ t = (t.fst.cons t.snd h, t.snd) := by
simp [pairMap, h]
@[simp]
private theorem pairMap_involutive : (pairMap σ).Involutive := by
intro t
rw [pairMap, pairMap]
split_ifs with h1 h2 h3
· simp at h2
· simp [insert_erase h1]
· simp_all
· simp at h3
variable [Fintype σ]
private def pairs (k : ℕ) : Finset (Finset σ × σ) :=
{t | #t.1 ≤ k ∧ (#t.1 = k → t.snd ∈ t.fst)}
@[simp]
private lemma mem_pairs (k : ℕ) (t : Finset σ × σ) :
t ∈ pairs σ k ↔ #t.1 ≤ k ∧ (#t.1 = k → t.snd ∈ t.fst) := by
simp [pairs]
private def weight (k : ℕ) (t : Finset σ × σ) : MvPolynomial σ R :=
(-1) ^ #t.1 * ((∏ a ∈ t.fst, X a) * X t.snd ^ (k - #t.1))
private theorem pairMap_mem_pairs {k : ℕ} (t : Finset σ × σ) (h : t ∈ pairs σ k) :
pairMap σ t ∈ pairs σ k := by
rw [mem_pairs] at h ⊢
rcases (em (t.snd ∈ t.fst)) with h1 | h1
· rw [pairMap_of_snd_mem_fst σ h1]
simp only [h1, implies_true, and_true] at h
simp only [card_erase_of_mem h1, tsub_le_iff_right, mem_erase, ne_eq, h1]
refine ⟨le_step h, ?_⟩
by_contra h2
simp only [not_true_eq_false, and_true, not_forall, not_false_eq_true, exists_prop] at h2
rw [← h2] at h
exact not_le_of_gt (sub_lt (card_pos.mpr ⟨t.snd, h1⟩) zero_lt_one) h
· rw [pairMap_of_snd_notMem_fst σ h1]
simp only [h1] at h
simp only [card_cons, mem_cons, true_or, implies_true, and_true]
exact (le_iff_eq_or_lt.mp h.left).resolve_left h.right
private theorem weight_add_weight_pairMap {k : ℕ} (t : Finset σ × σ) (h : t ∈ pairs σ k) :
weight σ R k t + weight σ R k (pairMap σ t) = 0 := by
rw [weight, weight]
rw [mem_pairs] at h
have h2 (n : ℕ) : -(-1 : MvPolynomial σ R) ^ n = (-1) ^ (n + 1) := by
rw [← neg_one_mul ((-1 : MvPolynomial σ R) ^ n), pow_add, pow_one, mul_comm]
rcases (em (t.snd ∈ t.fst)) with h1 | h1
· rw [pairMap_of_snd_mem_fst σ h1]
simp only [← prod_erase_mul t.fst (fun j ↦ (X j : MvPolynomial σ R)) h1,
mul_assoc (∏ a ∈ erase t.fst t.snd, X a), card_erase_of_mem h1]
nth_rewrite 1 [← pow_one (X t.snd)]
simp only [← pow_add, add_comm]
have h3 : 1 ≤ #t.1 := lt_iff_add_one_le.mp (card_pos.mpr ⟨t.snd, h1⟩)
rw [← tsub_tsub_assoc h.left h3, ← neg_neg ((-1 : MvPolynomial σ R) ^ (#t.1 - 1)),
h2 (#t.1 - 1), Nat.sub_add_cancel h3]
simp
· rw [pairMap_of_snd_notMem_fst σ h1]
simp only [mul_comm, mul_assoc (∏ a ∈ t.fst, X a), card_cons, prod_cons]
nth_rewrite 2 [← pow_one (X t.snd)]
simp only [← pow_add, ← Nat.add_sub_assoc (Nat.lt_of_le_of_ne h.left (mt h.right h1)), add_comm,
Nat.succ_eq_add_one, Nat.add_sub_add_right]
rw [← neg_neg ((-1 : MvPolynomial σ R) ^ #t.1), h2]
simp
private theorem weight_sum (k : ℕ) : ∑ t ∈ pairs σ k, weight σ R k t = 0 :=
sum_involution (fun t _ ↦ pairMap σ t) (weight_add_weight_pairMap σ R)
(fun t _ ↦ (fun _ ↦ pairMap_ne_self σ t)) (pairMap_mem_pairs σ)
(fun t _ ↦ pairMap_involutive σ t)
private theorem sum_filter_pairs_eq_sum_powersetCard_sum (k : ℕ)
(f : Finset σ × σ → MvPolynomial σ R) :
∑ t ∈ pairs σ k with #t.1 = k, f t = ∑ A ∈ powersetCard k univ, ∑ j ∈ A, f (A, j) := by
apply sum_finset_product
aesop
private theorem sum_filter_pairs_eq_sum_powersetCard_mem_filter_antidiagonal_sum (k : ℕ) (a : ℕ × ℕ)
(ha : a ∈ {a ∈ antidiagonal k | a.fst < k}) (f : Finset σ × σ → MvPolynomial σ R) :
∑ t ∈ pairs σ k with #t.1 = a.1, f t = ∑ A ∈ powersetCard a.1 univ, ∑ j, f (A, j) := by
apply sum_finset_product
simp only [mem_filter, mem_powersetCard_univ, mem_univ, and_true, and_iff_right_iff_imp]
rintro p hp
have : #p.fst ≤ k := by apply le_of_lt; simp_all
aesop
private lemma filter_pairs_lt (k : ℕ) :
(pairs σ k).filter (fun (s, _) ↦ #s < k) =
(range k).disjiUnion (powersetCard · univ) ((pairwise_disjoint_powersetCard _).set_pairwise _)
×ˢ univ := by ext; aesop (add unsafe le_of_lt)
private theorem sum_filter_pairs_eq_sum_filter_antidiagonal_powersetCard_sum (k : ℕ)
(f : Finset σ × σ → MvPolynomial σ R) :
∑ t ∈ pairs σ k with #t.1 < k, f t =
∑ a ∈ antidiagonal k with a.fst < k, ∑ A ∈ powersetCard a.fst univ, ∑ j, f (A, j) := by
rw [filter_pairs_lt, sum_product, sum_disjiUnion]
refine sum_nbij' (fun n ↦ (n, k - n)) Prod.fst ?_ ?_ ?_ ?_ ?_ <;>
simp +contextual [@eq_comm _ _ k, le_of_lt]
private theorem disjoint_filter_pairs_lt_filter_pairs_eq (k : ℕ) :
Disjoint {t ∈ pairs σ k | #t.1 < k} {t ∈ pairs σ k | #t.1 = k} := by
rw [disjoint_filter]
exact fun _ _ h1 h2 ↦ lt_irrefl _ (h2.symm.subst h1)
private theorem disjUnion_filter_pairs_eq_pairs (k : ℕ) :
disjUnion {t ∈ pairs σ k | #t.1 < k} {t ∈ pairs σ k | #t.1 = k}
(disjoint_filter_pairs_lt_filter_pairs_eq σ k) = pairs σ k := by
grind [MvPolynomial.NewtonIdentities.pairs]
end DecidableEq
variable [Fintype σ]
private theorem esymm_summand_to_weight (k : ℕ) (A : Finset σ) (h : A ∈ powersetCard k univ) :
∑ j ∈ A, weight σ R k (A, j) = k * (-1) ^ k * (∏ i ∈ A, X i : MvPolynomial σ R) := by
simp [weight, mem_powersetCard_univ.mp h, mul_assoc]
private theorem esymm_to_weight [DecidableEq σ] (k : ℕ) : k * esymm σ R k =
(-1) ^ k * ∑ t ∈ pairs σ k with #t.1 = k, weight σ R k t := by
rw [esymm, sum_filter_pairs_eq_sum_powersetCard_sum σ R k (fun t ↦ weight σ R k t),
sum_congr rfl (esymm_summand_to_weight σ R k), mul_comm (k : MvPolynomial σ R) ((-1) ^ k),
← mul_sum, ← mul_assoc, ← mul_assoc, ← pow_add, Even.neg_one_pow ⟨k, rfl⟩, one_mul]
private theorem esymm_mul_psum_summand_to_weight (k : ℕ) (a : ℕ × ℕ) (ha : a ∈ antidiagonal k) :
∑ A ∈ powersetCard a.fst univ, ∑ j, weight σ R k (A, j) =
(-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd := by
simp only [esymm, psum, weight, ← mul_assoc, mul_sum]
rw [sum_comm]
refine sum_congr rfl fun x _ ↦ ?_
rw [sum_mul]
refine sum_congr rfl fun s hs ↦ ?_
rw [mem_powersetCard_univ.mp hs, ← mem_antidiagonal.mp ha, add_sub_self_left]
private theorem esymm_mul_psum_to_weight [DecidableEq σ] (k : ℕ) :
∑ a ∈ antidiagonal k with a.fst < k, (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd =
∑ t ∈ pairs σ k with #t.1 < k, weight σ R k t := by
rw [← sum_congr rfl (fun a ha ↦ esymm_mul_psum_summand_to_weight σ R k a (mem_filter.mp ha).left),
sum_filter_pairs_eq_sum_filter_antidiagonal_powersetCard_sum σ R k]
end NewtonIdentities
variable (σ : Type*) [Fintype σ] (R : Type*) [CommRing R]
/-- **Newton's identities** give a recurrence relation for the kth elementary symmetric polynomial
in terms of lower degree elementary symmetric polynomials and power sums. -/
theorem mul_esymm_eq_sum (k : ℕ) :
k * esymm σ R k = (-1) ^ (k + 1) *
∑ a ∈ antidiagonal k with a.1 < k, (-1) ^ a.1 * esymm σ R a.1 * psum σ R a.2 := by
classical
rw [NewtonIdentities.esymm_to_weight σ R k, NewtonIdentities.esymm_mul_psum_to_weight σ R k,
eq_comm, ← sub_eq_zero, sub_eq_add_neg, neg_mul_eq_neg_mul,
neg_eq_neg_one_mul ((-1 : MvPolynomial σ R) ^ k)]
nth_rw 2 [← pow_one (-1 : MvPolynomial σ R)]
rw [← pow_add, add_comm 1 k, ← left_distrib,
← sum_disjUnion (NewtonIdentities.disjoint_filter_pairs_lt_filter_pairs_eq σ k),
NewtonIdentities.disjUnion_filter_pairs_eq_pairs σ k, NewtonIdentities.weight_sum σ R k,
neg_one_pow_mul_eq_zero_iff.mpr rfl]
theorem sum_antidiagonal_card_esymm_psum_eq_zero :
∑ a ∈ antidiagonal (Fintype.card σ), (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd = 0 := by
let k := Fintype.card σ
suffices (-1 : MvPolynomial σ R) ^ (k + 1) *
∑ a ∈ antidiagonal k, (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd = 0 by
simpa using this
simp [k, ← sum_filter_add_sum_filter_not (antidiagonal k) (fun a ↦ a.fst < k),
← mul_esymm_eq_sum, mul_add, ← mul_assoc, ← pow_add, mul_comm ↑k (esymm σ R k)]
/-- A version of Newton's identities which may be more useful in the case that we know the values of
the elementary symmetric polynomials and would like to calculate the values of the power sums. -/
theorem psum_eq_mul_esymm_sub_sum (k : ℕ) (h : 0 < k) :
psum σ R k = (-1) ^ (k + 1) * k * esymm σ R k -
∑ a ∈ antidiagonal k with a.1 ∈ Set.Ioo 0 k, (-1) ^ a.fst * esymm σ R a.1 * psum σ R a.2 := by
simp only [Set.Ioo, Set.mem_setOf_eq, and_comm]
have hesymm := mul_esymm_eq_sum σ R k
rw [← (sum_filter_add_sum_filter_not {a ∈ antidiagonal k | a.fst < k}
(fun a ↦ 0 < a.fst) (fun a ↦ (-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd))] at hesymm
have sub_both_sides := congrArg (· - (-1 : MvPolynomial σ R) ^ (k + 1) *
∑ a ∈ {a ∈ antidiagonal k | a.fst < k} with 0 < a.fst,
(-1) ^ a.fst * esymm σ R a.fst * psum σ R a.snd) hesymm
simp only [left_distrib, add_sub_cancel_left] at sub_both_sides
have sub_both_sides := congrArg ((-1 : MvPolynomial σ R) ^ (k + 1) * ·) sub_both_sides
simp only [mul_sub_left_distrib, ← mul_assoc, ← pow_add, Even.neg_one_pow ⟨k + 1, rfl⟩, one_mul,
filter_filter (fun a : ℕ × ℕ ↦ a.fst < k) (fun a ↦ ¬0 < a.fst)]
at sub_both_sides
have : {a ∈ antidiagonal k | a.fst < k ∧ ¬0 < a.fst} = {(0, k)} := by
ext a
rw [mem_filter, mem_antidiagonal, mem_singleton]
refine ⟨?_, by rintro rfl; cutsat⟩
rintro ⟨ha, ⟨_, ha0⟩⟩
rw [← ha, Nat.eq_zero_of_not_pos ha0, zero_add, ← Nat.eq_zero_of_not_pos ha0]
rw [this, sum_singleton] at sub_both_sides
simp only [_root_.pow_zero, esymm_zero, mul_one, one_mul, filter_filter] at sub_both_sides
exact sub_both_sides.symm
end MvPolynomial |
.lake/packages/mathlib/Mathlib/RingTheory/MvPolynomial/Symmetric/Defs.lean | import Mathlib.Algebra.Algebra.Subalgebra.Basic
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.Combinatorics.Enumerative.Partition.Basic
/-!
# Symmetric Polynomials and Elementary Symmetric Polynomials
This file defines symmetric `MvPolynomial`s and the bases of elementary, complete homogeneous,
power sum, and monomial symmetric `MvPolynomial`s. We also prove some basic facts about them.
## Main declarations
* `MvPolynomial.IsSymmetric`
* `MvPolynomial.symmetricSubalgebra`
* `MvPolynomial.esymm`
* `MvPolynomial.hsymm`
* `MvPolynomial.psum`
* `MvPolynomial.msymm`
## Notation
+ `esymm σ R n` is the `n`th elementary symmetric polynomial in `MvPolynomial σ R`.
+ `hsymm σ R n` is the `n`th complete homogeneous symmetric polynomial in `MvPolynomial σ R`.
+ `psum σ R n` is the degree-`n` power sum in `MvPolynomial σ R`, i.e. the sum of monomials
`(X i)^n` over `i ∈ σ`.
+ `msymm σ R μ` is the monomial symmetric polynomial whose exponents set are the parts
of `μ ⊢ n` in `MvPolynomial σ R`.
As in other polynomial files, we typically use the notation:
+ `σ τ : Type*` (indexing the variables)
+ `R S : Type*` `[CommSemiring R]` `[CommSemiring S]` (the coefficients)
+ `r : R` elements of the coefficient ring
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `φ ψ : MvPolynomial σ R`
-/
open Equiv (Perm)
noncomputable section
namespace Multiset
variable {R : Type*} [CommSemiring R]
/-- The `n`th elementary symmetric function evaluated at the elements of `s` -/
def esymm (s : Multiset R) (n : ℕ) : R :=
((s.powersetCard n).map Multiset.prod).sum
theorem _root_.Finset.esymm_map_val {σ} (f : σ → R) (s : Finset σ) (n : ℕ) :
(s.val.map f).esymm n = (s.powersetCard n).sum fun t => t.prod f := by
simp only [esymm, powersetCard_map, ← Finset.map_val_val_powersetCard, map_map]
simp only [Function.comp_apply, Finset.prod_map_val, Finset.sum_map_val]
lemma pow_smul_esymm {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R]
[SMulCommClass S R R] (s : S) (n : ℕ) (m : Multiset R) :
s ^ n • m.esymm n = (m.map (s • ·)).esymm n := by
rw [esymm, smul_sum, map_map]
trans ((powersetCard n m).map (fun x : Multiset R ↦ s ^ card x • x.prod)).sum
· refine congr_arg _ (map_congr rfl (fun x hx ↦ ?_))
rw [Function.comp_apply, (mem_powersetCard.1 hx).2]
· simp_rw [smul_prod, esymm, powersetCard_map, map_map, Function.comp_def]
-- TODO: `Multiset.insert_eq_cons` being simp means that `esymm {x, y}` is not simp normal form
@[simp] lemma esymm_pair_one (x y : R) :
esymm (x ::ₘ {y}) 1 = x + y := by
simp [esymm, powersetCard_one, add_comm]
@[simp] lemma esymm_pair_two (x y : R) :
esymm (x ::ₘ {y}) 2 = x * y := by
simp [esymm, powersetCard_one]
end Multiset
namespace MvPolynomial
variable {σ τ : Type*} {R S : Type*}
/-- A `MvPolynomial φ` is symmetric if it is invariant under
permutations of its variables by the `rename` operation -/
def IsSymmetric [CommSemiring R] (φ : MvPolynomial σ R) : Prop :=
∀ e : Perm σ, rename e φ = φ
/-- The subalgebra of symmetric `MvPolynomial`s. -/
def symmetricSubalgebra (σ R : Type*) [CommSemiring R] : Subalgebra R (MvPolynomial σ R) where
carrier := setOf IsSymmetric
algebraMap_mem' r e := rename_C e r
mul_mem' ha hb e := by rw [map_mul, ha, hb]
add_mem' ha hb e := by rw [map_add, ha, hb]
@[simp]
theorem mem_symmetricSubalgebra [CommSemiring R] (p : MvPolynomial σ R) :
p ∈ symmetricSubalgebra σ R ↔ p.IsSymmetric :=
Iff.rfl
namespace IsSymmetric
section CommSemiring
variable [CommSemiring R] [CommSemiring S] {φ ψ : MvPolynomial σ R}
@[simp]
theorem C (r : R) : IsSymmetric (C r : MvPolynomial σ R) :=
(symmetricSubalgebra σ R).algebraMap_mem r
@[simp]
theorem zero : IsSymmetric (0 : MvPolynomial σ R) :=
(symmetricSubalgebra σ R).zero_mem
@[simp]
theorem one : IsSymmetric (1 : MvPolynomial σ R) :=
(symmetricSubalgebra σ R).one_mem
theorem add (hφ : IsSymmetric φ) (hψ : IsSymmetric ψ) : IsSymmetric (φ + ψ) :=
(symmetricSubalgebra σ R).add_mem hφ hψ
theorem mul (hφ : IsSymmetric φ) (hψ : IsSymmetric ψ) : IsSymmetric (φ * ψ) :=
(symmetricSubalgebra σ R).mul_mem hφ hψ
theorem smul (r : R) (hφ : IsSymmetric φ) : IsSymmetric (r • φ) :=
(symmetricSubalgebra σ R).smul_mem hφ r
@[simp]
theorem map (hφ : IsSymmetric φ) (f : R →+* S) : IsSymmetric (map f φ) := fun e => by
rw [← map_rename, hφ]
protected theorem rename (hφ : φ.IsSymmetric) (e : σ ≃ τ) : (rename e φ).IsSymmetric := fun _ => by
apply rename_injective _ e.symm.injective
simp_rw [rename_rename, ← Equiv.coe_trans, Equiv.self_trans_symm, Equiv.coe_refl, rename_id_apply]
rw [hφ]
@[simp]
theorem _root_.MvPolynomial.isSymmetric_rename {e : σ ≃ τ} :
(MvPolynomial.rename e φ).IsSymmetric ↔ φ.IsSymmetric :=
⟨fun h => by simpa using (IsSymmetric.rename (R := R) h e.symm), (IsSymmetric.rename · e)⟩
end CommSemiring
section CommRing
variable [CommRing R] {φ ψ : MvPolynomial σ R}
theorem neg (hφ : IsSymmetric φ) : IsSymmetric (-φ) :=
(symmetricSubalgebra σ R).neg_mem hφ
theorem sub (hφ : IsSymmetric φ) (hψ : IsSymmetric ψ) : IsSymmetric (φ - ψ) :=
(symmetricSubalgebra σ R).sub_mem hφ hψ
end CommRing
end IsSymmetric
/-- `MvPolynomial.rename` induces an isomorphism between the symmetric subalgebras. -/
@[simps!]
def renameSymmetricSubalgebra [CommSemiring R] (e : σ ≃ τ) :
symmetricSubalgebra σ R ≃ₐ[R] symmetricSubalgebra τ R :=
AlgEquiv.ofAlgHom
(((rename e).comp (symmetricSubalgebra σ R).val).codRestrict _ <| fun x => x.2.rename e)
(((rename e.symm).comp <| Subalgebra.val _).codRestrict _ <| fun x => x.2.rename e.symm)
(AlgHom.ext <| fun p => Subtype.ext <| by simp)
(AlgHom.ext <| fun p => Subtype.ext <| by simp)
variable (σ R : Type*) [CommSemiring R] [CommSemiring S] [Fintype σ] [Fintype τ]
section ElementarySymmetric
open Finset
/-- The `n`th elementary symmetric `MvPolynomial σ R`.
It is the sum over all the degree n squarefree monomials in `MvPolynomial σ R`. -/
def esymm (n : ℕ) : MvPolynomial σ R :=
∑ t ∈ powersetCard n univ, ∏ i ∈ t, X i
/--
`esymmPart` is the product of the symmetric polynomials `esymm μᵢ`,
where `μ = (μ₁, μ₂, ...)` is a partition.
-/
def esymmPart {n : ℕ} (μ : n.Partition) : MvPolynomial σ R := (μ.parts.map (esymm σ R)).prod
/-- The `n`th elementary symmetric `MvPolynomial σ R` is obtained by evaluating the
`n`th elementary symmetric at the `Multiset` of the monomials -/
theorem esymm_eq_multiset_esymm : esymm σ R = (univ.val.map X).esymm := by
exact funext fun n => (esymm_map_val X _ n).symm
theorem aeval_esymm_eq_multiset_esymm [Algebra R S] (n : ℕ) (f : σ → S) :
aeval f (esymm σ R n) = (univ.val.map f).esymm n := by
simp_rw [esymm, aeval_sum, aeval_prod, aeval_X, esymm_map_val]
/-- We can define `esymm σ R n` by summing over a subtype instead of over `powerset_len`. -/
theorem esymm_eq_sum_subtype (n : ℕ) :
esymm σ R n = ∑ t : {s : Finset σ // #s = n}, ∏ i ∈ (t : Finset σ), X i :=
sum_subtype _ (fun _ => mem_powersetCard_univ) _
/-- We can define `esymm σ R n` as a sum over explicit monomials -/
theorem esymm_eq_sum_monomial (n : ℕ) :
esymm σ R n = ∑ t ∈ powersetCard n univ, monomial (∑ i ∈ t, Finsupp.single i 1) 1 := by
simp_rw [monomial_sum_one, esymm, ← X_pow_eq_monomial, pow_one]
@[simp]
theorem esymm_zero : esymm σ R 0 = 1 := by
simp only [esymm, powersetCard_zero, sum_singleton, prod_empty]
@[simp]
theorem esymm_one : esymm σ R 1 = ∑ i, X i := by simp [esymm, powersetCard_one]
theorem esymmPart_zero : esymmPart σ R (.indiscrete 0) = 1 := by simp [esymmPart]
@[simp]
theorem esymmPart_indiscrete (n : ℕ) : esymmPart σ R (.indiscrete n) = esymm σ R n := by
cases n <;> simp [esymmPart]
theorem map_esymm (n : ℕ) (f : R →+* S) : map f (esymm σ R n) = esymm σ S n := by
simp_rw [esymm, map_sum, map_prod, map_X]
theorem rename_esymm (n : ℕ) (e : σ ≃ τ) : rename e (esymm σ R n) = esymm τ R n :=
calc
rename e (esymm σ R n) = ∑ x ∈ powersetCard n univ, ∏ i ∈ x, X (e i) := by
simp_rw [esymm, map_sum, map_prod, rename_X]
_ = ∑ t ∈ powersetCard n (univ.map e.toEmbedding), ∏ i ∈ t, X i := by
simp [powersetCard_map, -map_univ_equiv, (mapEmbedding_apply)]
_ = ∑ t ∈ powersetCard n univ, ∏ i ∈ t, X i := by rw [map_univ_equiv]
theorem esymm_isSymmetric (n : ℕ) : IsSymmetric (esymm σ R n) := by
intro
rw [rename_esymm]
theorem support_esymm'' [DecidableEq σ] [Nontrivial R] (n : ℕ) :
(esymm σ R n).support =
(powersetCard n (univ : Finset σ)).biUnion fun t =>
(Finsupp.single (∑ i ∈ t, Finsupp.single i 1) (1 : R)).support := by
rw [esymm_eq_sum_monomial]
simp only [← single_eq_monomial]
refine Finsupp.support_sum_eq_biUnion (powersetCard n (univ : Finset σ)) ?_
intro s t hst
rw [disjoint_left, Finsupp.support_single_ne_zero _ one_ne_zero]
rw [Finsupp.support_single_ne_zero _ one_ne_zero]
simp only [mem_singleton]
rintro a h rfl
have := congr_arg Finsupp.support h
rw [Finsupp.support_sum_eq_biUnion, Finsupp.support_sum_eq_biUnion] at this
· have hsingle : ∀ s : Finset σ, ∀ x : σ, x ∈ s → (Finsupp.single x 1).support = {x} := by
intro _ x _
rw [Finsupp.support_single_ne_zero x one_ne_zero]
have hs := biUnion_congr (of_eq_true (eq_self s)) (hsingle s)
have ht := biUnion_congr (of_eq_true (eq_self t)) (hsingle t)
rw [hs, ht] at this
· simp only [biUnion_singleton_eq_self] at this
exact absurd this hst.symm
all_goals intro x y; simp [Finsupp.support_single_disjoint]
theorem support_esymm' [DecidableEq σ] [Nontrivial R] (n : ℕ) : (esymm σ R n).support =
(powersetCard n (univ : Finset σ)).biUnion fun t => {∑ i ∈ t, Finsupp.single i 1} := by
rw [support_esymm'']
congr
funext
exact Finsupp.support_single_ne_zero _ one_ne_zero
theorem support_esymm [DecidableEq σ] [Nontrivial R] (n : ℕ) : (esymm σ R n).support =
(powersetCard n (univ : Finset σ)).image fun t => ∑ i ∈ t, Finsupp.single i 1 := by
rw [support_esymm']
exact biUnion_singleton
theorem degrees_esymm [Nontrivial R] {n : ℕ} (hpos : 0 < n) (hn : n ≤ Fintype.card σ) :
(esymm σ R n).degrees = (univ : Finset σ).val := by
classical
have :
(Finsupp.toMultiset ∘ fun t : Finset σ => ∑ i ∈ t, Finsupp.single i 1) = val := by
funext
simp
rw [degrees_def, support_esymm, sup_image, this]
have : ((powersetCard n univ).sup (fun (x : Finset σ) => x)).val
= sup (powersetCard n univ) val := by
refine comp_sup_eq_sup_comp _ ?_ ?_ <;> simp
rw [← this]
obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hpos.ne'
simpa using powersetCard_sup _ _ (Nat.lt_of_succ_le hn)
end ElementarySymmetric
section CompleteHomogeneousSymmetric
open Finset Multiset Sym
variable [DecidableEq σ] [DecidableEq τ]
/-- The `n`th complete homogeneous symmetric `MvPolynomial σ R`.
It is the sum over all the degree n monomials in `MvPolynomial σ R`. -/
def hsymm (n : ℕ) : MvPolynomial σ R := ∑ s : Sym σ n, (s.1.map X).prod
/-- `hsymmPart` is the product of the symmetric polynomials `hsymm μᵢ`,
where `μ = (μ₁, μ₂, ...)` is a partition. -/
def hsymmPart {n : ℕ} (μ : n.Partition) : MvPolynomial σ R := (μ.parts.map (hsymm σ R)).prod
@[simp]
theorem hsymm_zero : hsymm σ R 0 = 1 := by simp [hsymm, eq_nil_of_card_zero]
@[simp]
theorem hsymm_one : hsymm σ R 1 = ∑ i, X i := by
symm
apply Fintype.sum_equiv oneEquiv
simp only [oneEquiv_apply, Multiset.map_singleton, Multiset.prod_singleton, implies_true]
theorem hsymmPart_zero : hsymmPart σ R (.indiscrete 0) = 1 := by simp [hsymmPart]
@[simp]
theorem hsymmPart_indiscrete (n : ℕ) : hsymmPart σ R (.indiscrete n) = hsymm σ R n := by
cases n <;> simp [hsymmPart]
theorem map_hsymm (n : ℕ) (f : R →+* S) : map f (hsymm σ R n) = hsymm σ S n := by
simp [hsymm, ← Multiset.prod_hom']
theorem rename_hsymm (n : ℕ) (e : σ ≃ τ) : rename e (hsymm σ R n) = hsymm τ R n := by
simp_rw [hsymm, map_sum, ← prod_hom', rename_X]
apply Fintype.sum_equiv (equivCongr e)
simp
theorem hsymm_isSymmetric (n : ℕ) : IsSymmetric (hsymm σ R n) := rename_hsymm _ _ n
end CompleteHomogeneousSymmetric
section PowerSum
open Finset
/-- The degree-`n` power sum symmetric `MvPolynomial σ R`.
It is the sum over all the `n`-th powers of the variables. -/
def psum (n : ℕ) : MvPolynomial σ R := ∑ i, X i ^ n
/-- `psumPart` is the product of the symmetric polynomials `psum μᵢ`,
where `μ = (μ₁, μ₂, ...)` is a partition. -/
def psumPart {n : ℕ} (μ : n.Partition) : MvPolynomial σ R := (μ.parts.map (psum σ R)).prod
@[simp]
theorem psum_zero : psum σ R 0 = Fintype.card σ := by simp [psum]
@[simp]
theorem psum_one : psum σ R 1 = ∑ i, X i := by simp [psum]
@[simp]
theorem psumPart_zero : psumPart σ R (.indiscrete 0) = 1 := by simp [psumPart]
@[simp]
theorem psumPart_indiscrete {n : ℕ} (npos : n ≠ 0) :
psumPart σ R (.indiscrete n) = psum σ R n := by simp [psumPart, npos]
@[simp]
theorem rename_psum (n : ℕ) (e : σ ≃ τ) : rename e (psum σ R n) = psum τ R n := by
simp_rw [psum, map_sum, map_pow, rename_X, e.sum_comp (X · ^ n)]
theorem psum_isSymmetric (n : ℕ) : IsSymmetric (psum σ R n) := rename_psum _ _ n
end PowerSum
section MonomialSymmetric
variable [DecidableEq σ] [DecidableEq τ] {n : ℕ}
/-- The monomial symmetric `MvPolynomial σ R` with exponent set μ.
It is the sum over all the monomials in `MvPolynomial σ R` such that
the multiset of exponents is equal to the multiset of parts of μ. -/
def msymm (μ : n.Partition) : MvPolynomial σ R :=
∑ s : {a : Sym σ n // .ofSym a = μ}, (s.1.1.map X).prod
@[simp]
theorem msymm_zero : msymm σ R (.indiscrete 0) = 1 := by
rw [msymm, Fintype.sum_subsingleton _ ⟨(Sym.nil : Sym σ 0), rfl⟩]
simp
@[simp]
theorem msymm_one : msymm σ R (.indiscrete 1) = ∑ i, X i := by
have : (fun (x : Sym σ 1) ↦ x ∈ Set.univ) =
(fun x ↦ Nat.Partition.ofSym x = Nat.Partition.indiscrete 1) := by
simp_rw [Set.mem_univ, Nat.Partition.ofSym_one]
symm
rw [Fintype.sum_equiv (Equiv.trans Sym.oneEquiv (Equiv.Set.univ (Sym σ 1)).symm)
_ (fun s ↦ (s.1.1.map X).prod)]
· apply Fintype.sum_equiv (Equiv.subtypeEquivProp this)
intro x
congr
· intro x
rw [← Multiset.prod_singleton (X x), ← Multiset.map_singleton]
congr
@[simp]
theorem rename_msymm (μ : n.Partition) (e : σ ≃ τ) :
rename e (msymm σ R μ) = msymm τ R μ := by
rw [msymm, map_sum]
apply Fintype.sum_equiv (Nat.Partition.ofSymShapeEquiv μ e)
intro
rw [← Multiset.prod_hom, Multiset.map_map, Nat.Partition.ofSymShapeEquiv]
simp
theorem msymm_isSymmetric (μ : n.Partition) : IsSymmetric (msymm σ R μ) :=
rename_msymm _ _ μ
end MonomialSymmetric
end MvPolynomial |
.lake/packages/mathlib/Mathlib/RingTheory/Derivation/Lie.lean | import Mathlib.Algebra.Lie.OfAssociative
import Mathlib.RingTheory.Derivation.Basic
/-!
# Lie Algebra Structure on Derivations
## Main statements
- `Derivation.instLieAlgebra`: The `R`-derivations from `A` to `A` form a Lie algebra over `R`.
-/
namespace Derivation
variable {R : Type*} [CommRing R]
variable {A : Type*} [CommRing A] [Algebra R A]
variable {D1 D2 : Derivation R A A} (a : A)
section LieStructures
/-! ### Lie structures -/
/-- The commutator of derivations is again a derivation. -/
instance : Bracket (Derivation R A A) (Derivation R A A) :=
⟨fun D1 D2 =>
mk' ⁅(D1 : Module.End R A), (D2 : Module.End R A)⁆ fun a b => by
simp only [Ring.lie_def, map_add, Algebra.id.smul_eq_mul, Module.End.mul_apply, leibniz,
coeFn_coe, LinearMap.sub_apply]
ring⟩
@[simp]
theorem commutator_coe_linear_map : ↑⁅D1, D2⁆ = ⁅(D1 : Module.End R A), (D2 : Module.End R A)⁆ :=
rfl
theorem commutator_apply : ⁅D1, D2⁆ a = D1 (D2 a) - D2 (D1 a) :=
rfl
instance : LieRing (Derivation R A A) where
add_lie d e f := by ext a; simp only [commutator_apply, add_apply, map_add]; ring
lie_add d e f := by ext a; simp only [commutator_apply, add_apply, map_add]; ring
lie_self d := by ext a; simp only [commutator_apply]; ring_nf; simp
leibniz_lie d e f := by ext a; simp only [commutator_apply, add_apply, map_sub]; ring
instance instLieAlgebra : LieAlgebra R (Derivation R A A) :=
{ Derivation.instModule with
lie_smul := fun r d e => by
ext a; simp only [commutator_apply, map_smul, smul_sub, smul_apply] }
end LieStructures
end Derivation |
.lake/packages/mathlib/Mathlib/RingTheory/Derivation/DifferentialRing.lean | import Mathlib.RingTheory.Derivation.Basic
/-!
# Differential and Algebras
This file defines derivations from a commutative ring to itself as a typeclass, which lets us
use the x′ notation for the derivative of x.
-/
/-- A derivation from a ring to itself, as a typeclass. -/
@[ext]
class Differential (R : Type*) [CommRing R] where
/-- The `Derivation` associated with the ring. -/
deriv : Derivation ℤ R R
@[inherit_doc]
scoped[Differential] postfix:max "′" => Differential.deriv
open scoped Differential
open Lean PrettyPrinter Delaborator SubExpr in
/--
A delaborator for the x′ notation. This is required because it's not direct function application,
so the default delaborator doesn't work.
-/
@[app_delab DFunLike.coe]
def delabDeriv : Delab := do
let e ← getExpr
guard <| e.isAppOfArity' ``DFunLike.coe 6
guard <| (e.getArg!' 4).isAppOf' ``Differential.deriv
let arg ← withAppArg delab
`($arg′)
/--
A differential algebra is an `Algebra` where the derivation commutes with `algebraMap`.
-/
class DifferentialAlgebra (A B : Type*) [CommRing A] [CommRing B] [Algebra A B]
[Differential A] [Differential B] : Prop where
deriv_algebraMap : ∀ a : A, (algebraMap A B a)′ = algebraMap A B a′
export DifferentialAlgebra (deriv_algebraMap)
@[norm_cast]
lemma algebraMap.coe_deriv {A : Type*} {B : Type*} [CommRing A] [CommRing B] [Algebra A B]
[Differential A] [Differential B] [DifferentialAlgebra A B] (a : A) :
(a′ : A) = (a : B)′ :=
(DifferentialAlgebra.deriv_algebraMap _).symm
/--
A differential ring `A` and an algebra over it `B` share constants if all
constants in B are in the range of `algebraMap A B`.
-/
class Differential.ContainConstants (A B : Type*) [CommRing A] [CommRing B]
[Algebra A B] [Differential B] : Prop where
/-- If the derivative of x is 0, then it's in the range of `algebraMap A B`. -/
protected mem_range_of_deriv_eq_zero {x : B} (h : x′ = 0) : x ∈ (algebraMap A B).range
lemma mem_range_of_deriv_eq_zero (A : Type*) {B : Type*} [CommRing A] [CommRing B] [Algebra A B]
[Differential B] [Differential.ContainConstants A B] {x : B} (h : x′ = 0) :
x ∈ (algebraMap A B).range :=
Differential.ContainConstants.mem_range_of_deriv_eq_zero h
instance (A : Type*) [CommRing A] [Differential A] : DifferentialAlgebra A A where
deriv_algebraMap _ := rfl
instance (A : Type*) [CommRing A] [Differential A] : Differential.ContainConstants A A where
mem_range_of_deriv_eq_zero {x} _ := ⟨x, rfl⟩
/-- Transfer a `Differential` instance across a `RingEquiv`. -/
@[reducible]
def Differential.equiv {R R₂ : Type*} [CommRing R] [CommRing R₂] [Differential R₂]
(h : R ≃+* R₂) : Differential R :=
⟨Derivation.mk' (h.symm.toAddMonoidHom.toIntLinearMap ∘ₗ
Differential.deriv.toLinearMap ∘ₗ h.toAddMonoidHom.toIntLinearMap) (by simp)⟩
/--
Transfer a `DifferentialAlgebra` instance across a `AlgEquiv`.
-/
lemma DifferentialAlgebra.equiv {A : Type*} [CommRing A] [Differential A]
{R R₂ : Type*} [CommRing R] [CommRing R₂] [Differential R₂] [Algebra A R]
[Algebra A R₂] [DifferentialAlgebra A R₂] (h : R ≃ₐ[A] R₂) :
letI := Differential.equiv h.toRingEquiv
DifferentialAlgebra A R :=
letI := Differential.equiv h.toRingEquiv
⟨fun a ↦ by
change (LinearMap.comp ..) _ = _
simp only [AlgEquiv.toRingEquiv_eq_coe, RingHom.toAddMonoidHom_eq_coe,
RingEquiv.toRingHom_eq_coe, AlgEquiv.toRingEquiv_toRingHom, LinearMap.coe_comp,
AddMonoidHom.coe_toIntLinearMap, AddMonoidHom.coe_coe, RingHom.coe_coe, Derivation.coeFn_coe,
Function.comp_apply, AlgEquiv.commutes, deriv_algebraMap]
apply h.symm.commutes⟩ |
.lake/packages/mathlib/Mathlib/RingTheory/Derivation/Basic.lean | import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Derivative
/-!
# Derivations
This file defines derivation. A derivation `D` from the `R`-algebra `A` to the `A`-module `M` is an
`R`-linear map that satisfy the Leibniz rule `D (a * b) = a * D b + D a * b`.
## Main results
- `Derivation`: The type of `R`-derivations from `A` to `M`. This has an `A`-module structure.
- `Derivation.llcomp`: We may compose linear maps and derivations to obtain a derivation,
and the composition is bilinear.
See `RingTheory.Derivation.Lie` for
- `derivation.lie_algebra`: The `R`-derivations from `A` to `A` form a lie algebra over `R`.
and `RingTheory.Derivation.ToSquareZero` for
- `derivationToSquareZeroEquivLift`: The `R`-derivations from `A` into a square-zero ideal `I`
of `B` corresponds to the lifts `A →ₐ[R] B` of the map `A →ₐ[R] B ⧸ I`.
## Future project
- Generalize derivations into bimodules.
-/
open Algebra
/-- `D : Derivation R A M` is an `R`-linear map from `A` to `M` that satisfies the `leibniz`
equality. We also require that `D 1 = 0`. See `Derivation.mk'` for a constructor that deduces this
assumption from the Leibniz rule when `M` is cancellative.
TODO: update this when bimodules are defined. -/
structure Derivation (R : Type*) (A : Type*) (M : Type*)
[CommSemiring R] [CommSemiring A] [AddCommMonoid M] [Algebra R A] [Module A M] [Module R M]
extends A →ₗ[R] M where
protected map_one_eq_zero' : toLinearMap 1 = 0
protected leibniz' (a b : A) : toLinearMap (a * b) = a • toLinearMap b + b • toLinearMap a
/-- The `LinearMap` underlying a `Derivation`. -/
add_decl_doc Derivation.toLinearMap
namespace Derivation
section
variable {R : Type*} {A : Type*} {B : Type*} {M : Type*}
variable [CommSemiring R] [CommSemiring A] [CommSemiring B] [AddCommMonoid M]
variable [Algebra R A] [Algebra R B]
variable [Module A M] [Module B M] [Module R M]
variable (D : Derivation R A M) {D1 D2 : Derivation R A M} (r : R) (a b : A)
instance : FunLike (Derivation R A M) A M where
coe D := D.toFun
coe_injective' D1 D2 h := by cases D1; cases D2; congr; exact DFunLike.coe_injective h
instance : AddMonoidHomClass (Derivation R A M) A M where
map_add D := D.toLinearMap.map_add'
map_zero D := D.toLinearMap.map_zero
-- Not a simp lemma because it can be proved via `coeFn_coe` + `toLinearMap_eq_coe`
theorem toFun_eq_coe : D.toFun = ⇑D :=
rfl
/-- See Note [custom simps projection] -/
def Simps.apply (D : Derivation R A M) : A → M := D
initialize_simps_projections Derivation (toFun → apply)
attribute [coe] toLinearMap
instance hasCoeToLinearMap : Coe (Derivation R A M) (A →ₗ[R] M) :=
⟨fun D => D.toLinearMap⟩
@[simp]
theorem mk_coe (f : A →ₗ[R] M) (h₁ h₂) : ((⟨f, h₁, h₂⟩ : Derivation R A M) : A → M) = f :=
rfl
@[simp, norm_cast]
theorem coeFn_coe (f : Derivation R A M) : ⇑(f : A →ₗ[R] M) = f :=
rfl
theorem coe_injective : @Function.Injective (Derivation R A M) (A → M) DFunLike.coe :=
DFunLike.coe_injective
@[ext]
theorem ext (H : ∀ a, D1 a = D2 a) : D1 = D2 :=
DFunLike.ext _ _ H
theorem congr_fun (h : D1 = D2) (a : A) : D1 a = D2 a :=
DFunLike.congr_fun h a
protected theorem map_add : D (a + b) = D a + D b :=
map_add D a b
protected theorem map_zero : D 0 = 0 :=
map_zero D
@[simp]
theorem map_smul : D (r • a) = r • D a :=
D.toLinearMap.map_smul r a
@[simp]
theorem leibniz : D (a * b) = a • D b + b • D a :=
D.leibniz' _ _
@[simp]
theorem map_smul_of_tower {S : Type*} [SMul S A] [SMul S M] [LinearMap.CompatibleSMul A M S R]
(D : Derivation R A M) (r : S) (a : A) : D (r • a) = r • D a :=
D.toLinearMap.map_smul_of_tower r a
@[simp]
theorem map_one_eq_zero : D 1 = 0 :=
D.map_one_eq_zero'
@[simp]
theorem map_algebraMap : D (algebraMap R A r) = 0 := by
rw [← mul_one r, RingHom.map_mul, RingHom.map_one, ← smul_def, map_smul, map_one_eq_zero,
smul_zero]
@[simp]
theorem map_natCast (n : ℕ) : D (n : A) = 0 := by
rw [← nsmul_one, D.map_smul_of_tower n, map_one_eq_zero, smul_zero]
@[simp]
theorem leibniz_pow (n : ℕ) : D (a ^ n) = n • a ^ (n - 1) • D a := by
induction n with
| zero => rw [pow_zero, map_one_eq_zero, zero_smul]
| succ n ihn =>
rcases (zero_le n).eq_or_lt with (rfl | hpos)
· simp
· have : a * a ^ (n - 1) = a ^ n := by rw [← pow_succ', Nat.sub_add_cancel hpos]
simp only [pow_succ', leibniz, ihn, smul_comm a n (_ : M), smul_smul a, add_smul, this,
Nat.add_succ_sub_one, add_zero, one_nsmul]
open Polynomial in
@[simp]
theorem map_aeval (P : R[X]) (x : A) :
D (aeval x P) = aeval x (derivative P) • D x := by
induction P using Polynomial.induction_on
· simp
· simp [add_smul, *]
· simp [mul_smul, ← Nat.cast_smul_eq_nsmul A]
theorem eqOn_adjoin {s : Set A} (h : Set.EqOn D1 D2 s) : Set.EqOn D1 D2 (adjoin R s) := fun _ hx =>
Algebra.adjoin_induction (hx := hx) h
(fun r => (D1.map_algebraMap r).trans (D2.map_algebraMap r).symm)
(fun x y _ _ hx hy => by simp only [map_add, *]) fun x y _ _ hx hy => by simp only [leibniz, *]
/-- If adjoin of a set is the whole algebra, then any two derivations equal on this set are equal
on the whole algebra. -/
theorem ext_of_adjoin_eq_top (s : Set A) (hs : adjoin R s = ⊤) (h : Set.EqOn D1 D2 s) : D1 = D2 :=
ext fun _ => eqOn_adjoin h <| hs.symm ▸ trivial
-- Data typeclasses
instance : Zero (Derivation R A M) :=
⟨{ toLinearMap := 0
map_one_eq_zero' := rfl
leibniz' := fun a b => by simp only [add_zero, LinearMap.zero_apply, smul_zero] }⟩
@[simp]
theorem coe_zero : ⇑(0 : Derivation R A M) = 0 :=
rfl
@[simp]
theorem coe_zero_linearMap : ↑(0 : Derivation R A M) = (0 : A →ₗ[R] M) :=
rfl
theorem zero_apply (a : A) : (0 : Derivation R A M) a = 0 :=
rfl
instance : Add (Derivation R A M) :=
⟨fun D1 D2 =>
{ toLinearMap := D1 + D2
map_one_eq_zero' := by simp
leibniz' := fun a b => by
simp only [leibniz, LinearMap.add_apply, coeFn_coe, smul_add, add_add_add_comm] }⟩
@[simp]
theorem coe_add (D1 D2 : Derivation R A M) : ⇑(D1 + D2) = D1 + D2 :=
rfl
@[simp]
theorem coe_add_linearMap (D1 D2 : Derivation R A M) : ↑(D1 + D2) = (D1 + D2 : A →ₗ[R] M) :=
rfl
theorem add_apply : (D1 + D2) a = D1 a + D2 a :=
rfl
instance : Inhabited (Derivation R A M) :=
⟨0⟩
section Scalar
variable {S T : Type*}
variable [Monoid S] [DistribMulAction S M] [SMulCommClass R S M] [SMulCommClass S A M]
variable [Monoid T] [DistribMulAction T M] [SMulCommClass R T M] [SMulCommClass T A M]
instance : SMul S (Derivation R A M) :=
⟨fun r D =>
{ toLinearMap := r • D.1
map_one_eq_zero' := by rw [LinearMap.smul_apply, coeFn_coe, D.map_one_eq_zero, smul_zero]
leibniz' := fun a b => by simp only [LinearMap.smul_apply, coeFn_coe, leibniz, smul_add,
smul_comm r (_ : A) (_ : M)] }⟩
@[simp]
theorem coe_smul (r : S) (D : Derivation R A M) : ⇑(r • D) = r • ⇑D :=
rfl
@[simp]
theorem coe_smul_linearMap (r : S) (D : Derivation R A M) : ↑(r • D) = r • (D : A →ₗ[R] M) :=
rfl
theorem smul_apply (r : S) (D : Derivation R A M) : (r • D) a = r • D a :=
rfl
instance : AddCommMonoid (Derivation R A M) :=
coe_injective.addCommMonoid _ coe_zero coe_add fun _ _ => rfl
/-- `coeFn` as an `AddMonoidHom`. -/
def coeFnAddMonoidHom : Derivation R A M →+ A → M where
toFun := (⇑)
map_zero' := coe_zero
map_add' := coe_add
@[simp]
lemma coeFnAddMonoidHom_apply (D : Derivation R A M) : coeFnAddMonoidHom D = D := rfl
instance : DistribMulAction S (Derivation R A M) :=
Function.Injective.distribMulAction coeFnAddMonoidHom coe_injective coe_smul
instance [DistribMulAction Sᵐᵒᵖ M] [IsCentralScalar S M] :
IsCentralScalar S (Derivation R A M) where
op_smul_eq_smul _ _ := ext fun _ => op_smul_eq_smul _ _
instance [SMul S T] [IsScalarTower S T M] : IsScalarTower S T (Derivation R A M) :=
⟨fun _ _ _ => ext fun _ => smul_assoc _ _ _⟩
instance [SMulCommClass S T M] : SMulCommClass S T (Derivation R A M) :=
⟨fun _ _ _ => ext fun _ => smul_comm _ _ _⟩
end Scalar
instance instModule {S : Type*} [Semiring S] [Module S M] [SMulCommClass R S M]
[SMulCommClass S A M] : Module S (Derivation R A M) :=
Function.Injective.module S coeFnAddMonoidHom coe_injective coe_smul
section PushForward
variable {N : Type*} [AddCommMonoid N] [Module A N] [Module R N] [IsScalarTower R A M]
[IsScalarTower R A N]
variable (f : M →ₗ[A] N) (e : M ≃ₗ[A] N)
/-- We can push forward derivations using linear maps, i.e., the composition of a derivation with a
linear map is a derivation. Furthermore, this operation is linear on the spaces of derivations. -/
def _root_.LinearMap.compDer : Derivation R A M →ₗ[R] Derivation R A N where
toFun D :=
{ toLinearMap := (f : M →ₗ[R] N).comp (D : A →ₗ[R] M)
map_one_eq_zero' := by simp only [LinearMap.comp_apply, coeFn_coe, map_one_eq_zero, map_zero]
leibniz' := fun a b => by
simp only [coeFn_coe, LinearMap.comp_apply, LinearMap.map_add, leibniz,
LinearMap.coe_restrictScalars, LinearMap.map_smul] }
map_add' D₁ D₂ := by ext; exact LinearMap.map_add _ _ _
map_smul' r D := by dsimp; ext; exact LinearMap.map_smul (f : M →ₗ[R] N) _ _
@[simp]
theorem coe_to_linearMap_comp : (f.compDer D : A →ₗ[R] N) = (f : M →ₗ[R] N).comp (D : A →ₗ[R] M) :=
rfl
@[simp]
theorem coe_comp : (f.compDer D : A → N) = (f : M →ₗ[R] N).comp (D : A →ₗ[R] M) :=
rfl
/-- The composition of a derivation with a linear map as a bilinear map -/
@[simps]
def llcomp : (M →ₗ[A] N) →ₗ[A] Derivation R A M →ₗ[R] Derivation R A N where
toFun f := f.compDer
map_add' f₁ f₂ := by ext; rfl
map_smul' r D := by ext; rfl
/-- Pushing a derivation forward through a linear equivalence is an equivalence. -/
def _root_.LinearEquiv.compDer : Derivation R A M ≃ₗ[R] Derivation R A N :=
{ e.toLinearMap.compDer with
invFun := e.symm.toLinearMap.compDer
left_inv := fun D => by ext a; exact e.symm_apply_apply (D a)
right_inv := fun D => by ext a; exact e.apply_symm_apply (D a) }
@[simp]
theorem linearEquiv_coe_to_linearMap_comp :
(e.compDer D : A →ₗ[R] N) = (e.toLinearMap : M →ₗ[R] N).comp (D : A →ₗ[R] M) :=
rfl
@[simp]
theorem linearEquiv_coe_comp :
(e.compDer D : A → N) = (e.toLinearMap : M →ₗ[R] N).comp (D : A →ₗ[R] M) :=
rfl
end PushForward
variable (A) in
/-- For a tower `R → A → B` and an `R`-derivation `B → M`, we may compose with `A → B` to obtain an
`R`-derivation `A → M`. -/
@[simps!]
def compAlgebraMap [Algebra A B] [IsScalarTower R A B] [IsScalarTower A B M]
(d : Derivation R B M) : Derivation R A M where
map_one_eq_zero' := by simp
leibniz' a b := by simp
toLinearMap := d.toLinearMap.comp (IsScalarTower.toAlgHom R A B).toLinearMap
section RestrictScalars
variable {S : Type*} [CommSemiring S]
variable [Algebra S A] [Module S M] [LinearMap.CompatibleSMul A M R S]
variable (R)
/-- If `A` is both an `R`-algebra and an `S`-algebra; `M` is both an `R`-module and an `S`-module,
then an `S`-derivation `A → M` is also an `R`-derivation if it is also `R`-linear. -/
protected def restrictScalars (d : Derivation S A M) : Derivation R A M where
map_one_eq_zero' := d.map_one_eq_zero
leibniz' := d.leibniz
toLinearMap := d.toLinearMap.restrictScalars R
lemma coe_restrictScalars (d : Derivation S A M) : ⇑(d.restrictScalars R) = ⇑d := rfl
@[simp]
lemma restrictScalars_apply (d : Derivation S A M) (x : A) : d.restrictScalars R x = d x := rfl
end RestrictScalars
end
section Lift
variable {R : Type*} {A : Type*} {M : Type*}
variable [CommSemiring R] [CommRing A] [CommRing M]
variable [Algebra R A] [Algebra R M]
variable {F : Type*} [FunLike F A M] [AlgHomClass F R A M]
/--
Lift a derivation via an algebra homomorphism `f` with a right inverse such that
`f(x) = 0 → f(d(x)) = 0`. This gives the derivation `f ∘ d ∘ f⁻¹`.
This is needed for an argument in [Rosenlicht, M. Integration in finite terms][Rosenlicht_1972].
-/
def liftOfRightInverse {f : F} {f_inv : M → A} (hf : Function.RightInverse f_inv f)
⦃d : Derivation R A A⦄ (hd : ∀ x, f x = 0 → f (d x) = 0) : Derivation R M M where
toFun x := f (d (f_inv x))
map_add' x y := by
suffices f (d (f_inv (x + y) - (f_inv x + f_inv y))) = 0 by simpa [sub_eq_zero]
apply hd
simp [hf _]
map_smul' x y := by
suffices f (d (f_inv (x • y) - x • f_inv y)) = 0 by simpa [sub_eq_zero]
apply hd
simp [hf _]
map_one_eq_zero' := by
suffices f (d (f_inv 1 - 1)) = 0 by simpa [sub_eq_zero]
apply hd
simp [hf _]
leibniz' x y := by
suffices f (d (f_inv (x * y) - f_inv x * f_inv y)) = 0 by simpa [sub_eq_zero, hf _]
apply hd
simp [hf _]
@[simp]
lemma liftOfRightInverse_apply {f : F} {f_inv : M → A} (hf : Function.RightInverse f_inv f)
{d : Derivation R A A} (hd : ∀ x, f x = 0 → f (d x) = 0) (x : A) :
Derivation.liftOfRightInverse hf hd (f x) = f (d x) := by
suffices f (d (f_inv (f x) - x)) = 0 by simpa [sub_eq_zero]
apply hd
simp [hf _]
lemma liftOfRightInverse_eq {f : F} {f_inv₁ f_inv₂ : M → A} (hf₁ : Function.RightInverse f_inv₁ f)
(hf₂ : Function.RightInverse f_inv₂ f) :
liftOfRightInverse hf₁ = liftOfRightInverse hf₂ := by
ext _ _ x
obtain ⟨x, rfl⟩ := hf₁.surjective x
simp
/--
A noncomputable version of `liftOfRightInverse` for surjective homomorphisms.
-/
noncomputable abbrev liftOfSurjective {f : F} (hf : Function.Surjective f)
⦃d : Derivation R A A⦄ (hd : ∀ x, f x = 0 → f (d x) = 0) : Derivation R M M :=
d.liftOfRightInverse (Function.rightInverse_surjInv hf) hd
lemma liftOfSurjective_apply {f : F} (hf : Function.Surjective f)
{d : Derivation R A A} (hd : ∀ x, f x = 0 → f (d x) = 0) (x : A) :
Derivation.liftOfSurjective hf hd (f x) = f (d x) := by simp
end Lift
section Cancel
variable {R : Type*} [CommSemiring R] {A : Type*} [CommSemiring A] [Algebra R A] {M : Type*}
[AddCancelCommMonoid M] [Module R M] [Module A M]
/-- Define `Derivation R A M` from a linear map when `M` is cancellative by verifying the Leibniz
rule. -/
def mk' (D : A →ₗ[R] M) (h : ∀ a b, D (a * b) = a • D b + b • D a) : Derivation R A M where
toLinearMap := D
map_one_eq_zero' := (add_eq_left (a := D 1)).1 <| by
simpa only [one_smul, one_mul] using (h 1 1).symm
leibniz' := h
@[simp]
theorem coe_mk' (D : A →ₗ[R] M) (h) : ⇑(mk' D h) = D :=
rfl
@[simp]
theorem coe_mk'_linearMap (D : A →ₗ[R] M) (h) : (mk' D h : A →ₗ[R] M) = D :=
rfl
end Cancel
section
variable {R : Type*} [CommRing R]
variable {A : Type*} [CommRing A] [Algebra R A]
section
variable {M : Type*} [AddCommGroup M] [Module A M] [Module R M]
variable (D : Derivation R A M) {D1 D2 : Derivation R A M} (r : R) (a b : A)
protected theorem map_neg : D (-a) = -D a :=
map_neg D a
protected theorem map_sub : D (a - b) = D a - D b :=
map_sub D a b
@[simp]
theorem map_intCast (n : ℤ) : D (n : A) = 0 := by
rw [← zsmul_one, D.map_smul_of_tower n, map_one_eq_zero, smul_zero]
theorem leibniz_of_mul_eq_one {a b : A} (h : a * b = 1) : D a = -a ^ 2 • D b := by
rw [neg_smul]
refine eq_neg_of_add_eq_zero_left ?_
calc
D a + a ^ 2 • D b = a • b • D a + a • a • D b := by simp only [smul_smul, h, one_smul, sq]
_ = a • D (a * b) := by rw [leibniz, smul_add, add_comm]
_ = 0 := by rw [h, map_one_eq_zero, smul_zero]
theorem leibniz_invOf [Invertible a] : D (⅟a) = -⅟a ^ 2 • D a :=
D.leibniz_of_mul_eq_one <| invOf_mul_self a
section Field
variable {K : Type*} [Field K] [Module K M] [Algebra R K] (D : Derivation R K M)
theorem leibniz_inv (a : K) : D a⁻¹ = -a⁻¹ ^ 2 • D a := by
rcases eq_or_ne a 0 with (rfl | ha)
· simp
· exact D.leibniz_of_mul_eq_one (inv_mul_cancel₀ ha)
theorem leibniz_div (a b : K) : D (a / b) = b⁻¹ ^ 2 • (b • D a - a • D b) := by
simp only [div_eq_mul_inv, leibniz, leibniz_inv, inv_pow, neg_smul, smul_neg, smul_smul, add_comm,
sub_eq_add_neg, smul_add]
rw [← inv_mul_mul_self b⁻¹, inv_inv]
ring_nf
theorem leibniz_div_const (a b : K) (h : D b = 0) : D (a / b) = b⁻¹ • D a := by
simp only [leibniz_div, inv_pow, h, smul_zero, sub_zero, smul_smul]
rw [← mul_self_mul_inv b⁻¹, inv_inv]
ring_nf
lemma leibniz_zpow (a : K) (n : ℤ) : D (a ^ n) = n • a ^ (n - 1) • D a := by
by_cases hn : n = 0
· simp [hn]
by_cases ha : a = 0
· simp [ha, zero_zpow n hn]
rcases Int.natAbs_eq n with h | h
· rw [h]
simp only [zpow_natCast, leibniz_pow, natCast_zsmul]
rw [← zpow_natCast]
congr
cutsat
· rw [h, zpow_neg, zpow_natCast, leibniz_inv, leibniz_pow, inv_pow, ← pow_mul, ← zpow_natCast,
← zpow_natCast, ← Nat.cast_smul_eq_nsmul K, ← Int.cast_smul_eq_zsmul K, smul_smul, smul_smul,
smul_smul]
trans (-n.natAbs * (a ^ ((n.natAbs - 1 : ℕ) : ℤ) / (a ^ ((n.natAbs * 2 : ℕ) : ℤ)))) • D a
· ring_nf
rw [← zpow_sub₀ ha]
congr 3
· norm_cast
cutsat
end Field
instance : Neg (Derivation R A M) :=
⟨fun D =>
mk' (-D) fun a b => by
simp only [LinearMap.neg_apply, smul_neg, neg_add_rev, leibniz, coeFn_coe, add_comm]⟩
@[simp]
theorem coe_neg (D : Derivation R A M) : ⇑(-D) = -D :=
rfl
@[simp]
theorem coe_neg_linearMap (D : Derivation R A M) : ↑(-D) = (-D : A →ₗ[R] M) :=
rfl
theorem neg_apply : (-D) a = -D a :=
rfl
instance : Sub (Derivation R A M) :=
⟨fun D1 D2 =>
mk' (D1 - D2 : A →ₗ[R] M) fun a b => by
simp only [LinearMap.sub_apply, leibniz, coeFn_coe, smul_sub, add_sub_add_comm]⟩
@[simp]
theorem coe_sub (D1 D2 : Derivation R A M) : ⇑(D1 - D2) = D1 - D2 :=
rfl
@[simp]
theorem coe_sub_linearMap (D1 D2 : Derivation R A M) : ↑(D1 - D2) = (D1 - D2 : A →ₗ[R] M) :=
rfl
theorem sub_apply : (D1 - D2) a = D1 a - D2 a :=
rfl
instance : AddCommGroup (Derivation R A M) :=
coe_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => rfl) fun _ _ => rfl
end
end
end Derivation |
.lake/packages/mathlib/Mathlib/RingTheory/Derivation/MapCoeffs.lean | import Mathlib.RingTheory.Derivation.DifferentialRing
import Mathlib.Algebra.Polynomial.Module.Basic
import Mathlib.Algebra.Polynomial.Derivation
import Mathlib.FieldTheory.Separable
/-!
# Coefficient-wise derivation on polynomials
In this file we define applying a derivation on the coefficients of a polynomial,
show this forms a derivation, and prove `apply_eval_eq`, which shows that for a derivation `D`,
`D(p(x)) = (D.mapCoeffs p)(x) + D(x) * p'(x)`. `apply_aeval_eq` and `apply_aeval_eq'`
are generalizations of that for algebras. We also have a special case for `DifferentialAlgebra`s.
-/
noncomputable section
open Polynomial Module
namespace Derivation
variable {R A M : Type*} [CommRing R] [CommRing A] [Algebra R A] [AddCommGroup M]
[Module A M] [Module R M] (d : Derivation R A M)
/--
The `R`-derivation from `A[X]` to `M[X]` which applies the derivative to each
of the coefficients.
-/
def mapCoeffs : Derivation R A[X] (PolynomialModule A M) where
__ := (PolynomialModule.map A d.toLinearMap).comp
PolynomialModule.equivPolynomial.symm.toLinearMap
map_one_eq_zero' := show (Finsupp.single 0 1).mapRange (d : A → M) d.map_zero = 0 by simp
leibniz' p q := by
dsimp
induction p using Polynomial.induction_on' with
| add => simp only [add_mul, map_add, add_smul, smul_add, add_add_add_comm, *]
| monomial n a =>
induction q using Polynomial.induction_on' with
| add => simp only [mul_add, map_add, add_smul, smul_add, add_add_add_comm, *]
| monomial m b =>
refine Finsupp.ext fun i ↦ ?_
dsimp [PolynomialModule.equivPolynomial, PolynomialModule.map]
simp only [toFinsupp_mul, toFinsupp_monomial, AddMonoidAlgebra.single_mul_single]
change d _ = _ + _
-- TODO: copy more `Finsupp` API to `PolynomialModule`.
-- We have to do a bit of work to go through the identification
-- `PolynomialModule A M = ℕ →₀ M`...
dsimp only [PolynomialModule, Finsupp.mapRange.linearMap_apply, coeFn_coe]
rw [Finsupp.mapRange_single, Finsupp.mapRange_single]
-- ... and here we go back through the identification.
change _ = (_ • PolynomialModule.single A _ _) _ + (_ • PolynomialModule.single A _ _) i
simp only [PolynomialModule.monomial_smul_single, AddMonoidAlgebra.single_apply,
apply_ite d, leibniz, map_zero, PolynomialModule.single_apply, ite_add_zero,
add_comm m n]
@[simp]
lemma mapCoeffs_apply (p : A[X]) (i) :
d.mapCoeffs p i = d (coeff p i) := rfl
@[simp]
lemma mapCoeffs_monomial (n : ℕ) (x : A) :
d.mapCoeffs (monomial n x) = .single A n (d x) := Finsupp.ext fun _ ↦ by
simp [coeff_monomial, apply_ite d, PolynomialModule.single_apply]
@[simp]
lemma mapCoeffs_X :
d.mapCoeffs (X : A[X]) = 0 := by simp [← monomial_one_one_eq_X]
@[simp]
lemma mapCoeffs_C (x : A) :
d.mapCoeffs (C x) = .single A 0 (d x) := by simp [← monomial_zero_left]
variable {B M' : Type*} [CommRing B] [Algebra R B] [Algebra A B]
[AddCommGroup M'] [Module B M'] [Module R M'] [Module A M']
theorem apply_aeval_eq' (d' : Derivation R B M') (f : M →ₗ[A] M')
(h : ∀ a, f (d a) = d' (algebraMap A B a)) (x : B) (p : A[X]) :
d' (aeval x p) = PolynomialModule.eval x (PolynomialModule.map B f (d.mapCoeffs p)) +
aeval x (derivative p) • d' x := by
induction p using Polynomial.induction_on' with
| add => simp_all only [map_add, add_smul]; abel
| monomial =>
simp only [aeval_monomial, leibniz, leibniz_pow, mapCoeffs_monomial,
PolynomialModule.map_single, PolynomialModule.eval_single, derivative_monomial, map_mul,
_root_.map_natCast, h]
rw [add_comm, ← smul_smul, ← smul_smul, Nat.cast_smul_eq_nsmul]
theorem apply_aeval_eq [IsScalarTower R A B] [IsScalarTower A B M'] (d : Derivation R B M')
(x : B) (p : A[X]) :
d (aeval x p) = PolynomialModule.eval x ((d.compAlgebraMap A).mapCoeffs p) +
aeval x (derivative p) • d x := by
convert apply_aeval_eq' (d.compAlgebraMap A) d LinearMap.id _ x p
· apply Finsupp.ext
intro x
rfl
· intro a
rfl
theorem apply_eval_eq (x : A) (p : A[X]) :
d (eval x p) = PolynomialModule.eval x (d.mapCoeffs p) + eval x (derivative p) • d x :=
apply_aeval_eq d x p
end Derivation
namespace Differential
variable {A : Type*} [CommRing A] [Differential A]
/--
A specialization of `Derivation.mapCoeffs` for the case of a differential ring.
-/
def mapCoeffs : Derivation ℤ A[X] A[X] :=
PolynomialModule.equivPolynomialSelf.compDer Differential.deriv.mapCoeffs
@[simp]
lemma coeff_mapCoeffs (p : A[X]) (i) :
coeff (mapCoeffs p) i = (coeff p i)′ := rfl
@[simp]
lemma mapCoeffs_monomial (n : ℕ) (x : A) :
mapCoeffs (monomial n x) = monomial n x′ := by
simp [mapCoeffs]
@[simp]
lemma mapCoeffs_X :
mapCoeffs (X : A[X]) = 0 := by simp [← monomial_one_one_eq_X]
@[simp]
lemma mapCoeffs_C (x : A) :
mapCoeffs (C x) = C x′ := by simp [← monomial_zero_left]
variable {R : Type*} [CommRing R] [Differential R] [Algebra A R] [DifferentialAlgebra A R]
theorem deriv_aeval_eq (x : R) (p : A[X]) :
(aeval x p)′ = aeval x (mapCoeffs p) + aeval x (derivative p) * x′ := by
convert Derivation.apply_aeval_eq' Differential.deriv _ (Algebra.linearMap A R) ..
· simp [mapCoeffs]
· simp [deriv_algebraMap]
/--
The unique derivation which can be made to a `DifferentialAlgebra` on `A[X]` with
`X′ = v`.
-/
def implicitDeriv (v : A[X]) :
Derivation ℤ A[X] A[X] :=
mapCoeffs + v • derivative'.restrictScalars ℤ
@[simp]
lemma implicitDeriv_C (v : A[X]) (b : A) :
implicitDeriv v (C b) = C b′ := by
simp [implicitDeriv]
@[simp]
lemma implicitDeriv_X (v : A[X]) :
implicitDeriv v X = v := by
simp [implicitDeriv]
lemma deriv_aeval_eq_implicitDeriv (x : R) (v : A[X]) (h : x′ = aeval x v) (p : A[X]) :
(aeval x p)′ = aeval x (implicitDeriv v p) := by
simp [deriv_aeval_eq, implicitDeriv, h, mul_comm]
variable {R' : Type*} [CommRing R'] [Differential R'] [Algebra A R'] [DifferentialAlgebra A R']
variable [IsDomain R'] [Nontrivial R]
lemma algHom_deriv (f : R →ₐ[A] R') (hf : Function.Injective f) (x : R) (h : IsSeparable A x) :
f (x′) = (f x)′ := by
let p := minpoly A x
apply mul_left_cancel₀ (a := aeval (f x) (derivative p))
· rw [Polynomial.aeval_algHom]
simp only [AlgHom.coe_comp, Function.comp_apply, ne_eq, map_eq_zero_iff f hf]
apply Separable.aeval_derivative_ne_zero h (minpoly.aeval A x)
conv => lhs; rw [Polynomial.aeval_algHom]
simp only [AlgHom.coe_comp, Function.comp_apply, ← map_mul]
apply add_left_cancel (a := aeval (f x) (mapCoeffs p))
rw [← deriv_aeval_eq]
simp only [aeval_algHom, AlgHom.coe_comp, Function.comp_apply, ← map_add, ← deriv_aeval_eq,
minpoly.aeval, map_zero, p]
omit [Nontrivial R] in
lemma algEquiv_deriv (f : R ≃ₐ[A] R') (x : R) (h : IsSeparable A x) :
f (x′) = (f x)′ :=
haveI := f.nontrivial
algHom_deriv f.toAlgHom f.injective x h
variable [Algebra.IsSeparable A R]
/--
`algHom_deriv` in a separable algebra
-/
lemma algHom_deriv' (f : R →ₐ[A] R') (hf : Function.Injective f) (x : R) :
f (x′) = (f x)′ := algHom_deriv f hf x (Algebra.IsSeparable.isSeparable' x)
omit [Nontrivial R] in
/--
`algEquiv_deriv` in a separable algebra
-/
lemma algEquiv_deriv' (f : R ≃ₐ[A] R') (x : R) :
f (x′) = (f x)′ :=
haveI := f.nontrivial
algHom_deriv' f.toAlgHom f.injective x
end Differential |
.lake/packages/mathlib/Mathlib/RingTheory/Derivation/ToSquareZero.lean | import Mathlib.RingTheory.Derivation.Basic
import Mathlib.RingTheory.Ideal.Quotient.Operations
/-!
# Derivations into Square-Zero Ideals
## Main statements
- `derivationToSquareZeroOfLift`: The `R`-derivations from `A` into a square-zero ideal `I`
of `B` corresponds to the lifts `A →ₐ[R] B` of the map `A →ₐ[R] B ⧸ I`.
-/
section ToSquareZero
universe u v w
variable {R : Type u} {A : Type v} {B : Type w} [CommSemiring R] [CommSemiring A] [CommRing B]
variable [Algebra R A] [Algebra R B] (I : Ideal B)
/-- If `f₁ f₂ : A →ₐ[R] B` are two lifts of the same `A →ₐ[R] B ⧸ I`,
we may define a map `f₁ - f₂ : A →ₗ[R] I`. -/
def diffToIdealOfQuotientCompEq (f₁ f₂ : A →ₐ[R] B)
(e : (Ideal.Quotient.mkₐ R I).comp f₁ = (Ideal.Quotient.mkₐ R I).comp f₂) : A →ₗ[R] I :=
LinearMap.codRestrict (I.restrictScalars _) (f₁.toLinearMap - f₂.toLinearMap) (by
intro x
change f₁ x - f₂ x ∈ I
rw [← Ideal.Quotient.eq, ← Ideal.Quotient.mkₐ_eq_mk R, ← AlgHom.comp_apply, e]
rfl)
@[simp]
theorem diffToIdealOfQuotientCompEq_apply (f₁ f₂ : A →ₐ[R] B)
(e : (Ideal.Quotient.mkₐ R I).comp f₁ = (Ideal.Quotient.mkₐ R I).comp f₂) (x : A) :
((diffToIdealOfQuotientCompEq I f₁ f₂ e) x : B) = f₁ x - f₂ x :=
rfl
variable [Algebra A B]
/-- Given a tower of algebras `R → A → B`, and a square-zero `I : Ideal B`, each lift `A →ₐ[R] B`
of the canonical map `A →ₐ[R] B ⧸ I` corresponds to an `R`-derivation from `A` to `I`. -/
def derivationToSquareZeroOfLift [IsScalarTower R A B] (hI : I ^ 2 = ⊥) (f : A →ₐ[R] B)
(e : (Ideal.Quotient.mkₐ R I).comp f = IsScalarTower.toAlgHom R A (B ⧸ I)) :
Derivation R A I := by
refine
{ diffToIdealOfQuotientCompEq I f (IsScalarTower.toAlgHom R A B) ?_ with
map_one_eq_zero' := ?_
leibniz' := ?_ }
· rw [e]; ext; rfl
· ext; simp
· intro x y
let F := diffToIdealOfQuotientCompEq I f (IsScalarTower.toAlgHom R A B) (by rw [e]; ext; rfl)
have : (f x - algebraMap A B x) * (f y - algebraMap A B y) = 0 := by
rw [← Ideal.mem_bot, ← hI, pow_two]
convert Ideal.mul_mem_mul (F x).2 (F y).2 using 1
ext
dsimp only [Submodule.coe_add, Submodule.coe_mk, LinearMap.coe_mk,
diffToIdealOfQuotientCompEq_apply, Submodule.coe_smul_of_tower, IsScalarTower.coe_toAlgHom',
LinearMap.toFun_eq_coe]
simp only [map_mul, sub_mul, mul_sub, Algebra.smul_def] at this ⊢
rw [sub_eq_iff_eq_add, sub_eq_iff_eq_add] at this
simp only [this]
ring
variable (hI : I ^ 2 = ⊥)
theorem derivationToSquareZeroOfLift_apply [IsScalarTower R A B] (f : A →ₐ[R] B)
(e : (Ideal.Quotient.mkₐ R I).comp f = IsScalarTower.toAlgHom R A (B ⧸ I)) (x : A) :
(derivationToSquareZeroOfLift I hI f e x : B) = f x - algebraMap A B x :=
rfl
/-- Given a tower of algebras `R → A → B`, and a square-zero `I : Ideal B`, each `R`-derivation
from `A` to `I` corresponds to a lift `A →ₐ[R] B` of the canonical map `A →ₐ[R] B ⧸ I`. -/
@[simps -isSimp]
def liftOfDerivationToSquareZero [IsScalarTower R A B] (hI : I ^ 2 = ⊥) (f : Derivation R A I) :
A →ₐ[R] B :=
{ ((I.restrictScalars R).subtype.comp f.toLinearMap + (IsScalarTower.toAlgHom R A B).toLinearMap :
A →ₗ[R] B) with
toFun := fun x => f x + algebraMap A B x
map_one' := by
-- Note: added the `(algebraMap _ _)` hint because otherwise it would match `f 1`
rw [map_one (algebraMap _ _), f.map_one_eq_zero, Submodule.coe_zero, zero_add]
map_mul' := fun x y => by
have : (f x : B) * f y = 0 := by
rw [← Ideal.mem_bot, ← hI, pow_two]
convert Ideal.mul_mem_mul (f x).2 (f y).2 using 1
simp only [map_mul, f.leibniz, add_mul, mul_add, Submodule.coe_add,
Submodule.coe_smul_of_tower, Algebra.smul_def, this]
ring
commutes' := fun r => by
simp only [Derivation.map_algebraMap, zero_add, Submodule.coe_zero, ←
IsScalarTower.algebraMap_apply R A B r]
map_zero' := ((I.restrictScalars R).subtype.comp f.toLinearMap +
(IsScalarTower.toAlgHom R A B).toLinearMap).map_zero }
-- simp normal form is `liftOfDerivationToSquareZero_mk_apply'`
theorem liftOfDerivationToSquareZero_mk_apply [IsScalarTower R A B] (d : Derivation R A I) (x : A) :
Ideal.Quotient.mk I (liftOfDerivationToSquareZero I hI d x) = algebraMap A (B ⧸ I) x := by
rw [liftOfDerivationToSquareZero_apply, map_add, Ideal.Quotient.eq_zero_iff_mem.mpr (d x).prop,
zero_add]
rfl
@[simp]
theorem liftOfDerivationToSquareZero_mk_apply' (d : Derivation R A I) (x : A) :
(Ideal.Quotient.mk I) (d x) + (algebraMap A (B ⧸ I)) x = algebraMap A (B ⧸ I) x := by
simp only [Ideal.Quotient.eq_zero_iff_mem.mpr (d x).prop, zero_add]
/-- Given a tower of algebras `R → A → B`, and a square-zero `I : Ideal B`,
there is a 1-1 correspondence between `R`-derivations from `A` to `I` and
lifts `A →ₐ[R] B` of the canonical map `A →ₐ[R] B ⧸ I`. -/
@[simps!]
def derivationToSquareZeroEquivLift [IsScalarTower R A B] : Derivation R A I ≃
{ f : A →ₐ[R] B // (Ideal.Quotient.mkₐ R I).comp f = IsScalarTower.toAlgHom R A (B ⧸ I) } := by
refine ⟨fun d => ⟨liftOfDerivationToSquareZero I hI d, ?_⟩, fun f =>
(derivationToSquareZeroOfLift I hI f.1 f.2 :), ?_, ?_⟩
· ext x; exact liftOfDerivationToSquareZero_mk_apply I hI d x
· intro d; ext x; exact add_sub_cancel_right (d x : B) (algebraMap A B x)
· rintro ⟨f, hf⟩; ext x; exact sub_add_cancel (f x) (algebraMap A B x)
end ToSquareZero |
.lake/packages/mathlib/Mathlib/RingTheory/Etale/Kaehler.lean | import Mathlib.RingTheory.Etale.Basic
import Mathlib.RingTheory.Kaehler.JacobiZariski
import Mathlib.RingTheory.Localization.BaseChange
import Mathlib.RingTheory.Smooth.Kaehler
import Mathlib.RingTheory.Flat.Localization
/-!
# The differential module and étale algebras
## Main results
- `KaehlerDifferential.tensorKaehlerEquivOfFormallyEtale`:
The canonical isomorphism `T ⊗[S] Ω[S⁄R] ≃ₗ[T] Ω[T⁄R]` for `T` a formally étale `S`-algebra.
- `Algebra.tensorH1CotangentOfIsLocalization`:
The canonical isomorphism `T ⊗[S] H¹(L_{S⁄R}) ≃ₗ[T] H¹(L_{T⁄R})` for `T` a localization of `S`.
-/
universe u
variable (R S T : Type*) [CommRing R] [CommRing S] [CommRing T]
variable [Algebra R S] [Algebra R T] [Algebra S T] [IsScalarTower R S T]
open TensorProduct
/--
The canonical isomorphism `T ⊗[S] Ω[S⁄R] ≃ₗ[T] Ω[T⁄R]` for `T` a formally étale `S`-algebra.
Also see `S ⊗[R] Ω[A⁄R] ≃ₗ[S] Ω[S ⊗[R] A⁄S]` at `KaehlerDifferential.tensorKaehlerEquiv`.
-/
@[simps! apply] noncomputable
def KaehlerDifferential.tensorKaehlerEquivOfFormallyEtale [Algebra.FormallyEtale S T] :
T ⊗[S] Ω[S⁄R] ≃ₗ[T] Ω[T⁄R] := by
refine LinearEquiv.ofBijective (mapBaseChange R S T)
⟨?_, fun x ↦ (KaehlerDifferential.exact_mapBaseChange_map R S T x).mp (Subsingleton.elim _ _)⟩
rw [injective_iff_map_eq_zero]
intro x hx
obtain ⟨x, rfl⟩ := (Algebra.H1Cotangent.exact_δ_mapBaseChange R S T x).mp hx
rw [Subsingleton.elim x 0, map_zero]
lemma KaehlerDifferential.tensorKaehlerEquivOfFormallyEtale_symm_D_algebraMap
[Algebra.FormallyEtale S T] (s : S) :
(tensorKaehlerEquivOfFormallyEtale R S T).symm (D R T (algebraMap S T s)) = 1 ⊗ₜ D R S s := by
rw [LinearEquiv.symm_apply_eq, tensorKaehlerEquivOfFormallyEtale_apply, mapBaseChange_tmul,
one_smul, map_D]
lemma KaehlerDifferential.isBaseChange_of_formallyEtale [Algebra.FormallyEtale S T] :
IsBaseChange T (map R R S T) := by
change Function.Bijective _
convert (tensorKaehlerEquivOfFormallyEtale R S T).bijective using 1
change _ = ((tensorKaehlerEquivOfFormallyEtale
R S T).toLinearMap.restrictScalars S : T ⊗[S] Ω[S⁄R] → _)
congr!
ext
simp
instance KaehlerDifferential.isLocalizedModule_map (M : Submonoid S) [IsLocalization M T] :
IsLocalizedModule M (map R R S T) :=
have := Algebra.FormallyEtale.of_isLocalization (Rₘ := T) M
(isLocalizedModule_iff_isBaseChange M T _).mpr (isBaseChange_of_formallyEtale R S T)
namespace Algebra.Extension
open KaehlerDifferential
attribute [local instance] SMulCommClass.of_commMonoid
variable {R S T}
/-!
Suppose we have a morphism of extensions of `R`-algebras
```
0 → J → Q → T → 0
↑ ↑ ↑
0 → I → P → S → 0
```
-/
variable {P : Extension.{u} R S} {Q : Extension.{u} R T} (f : P.Hom Q)
/-- If `P → Q` is formally étale, then `T ⊗ₛ (S ⊗ₚ Ω[P/R]) ≃ T ⊗_Q Ω[Q/R]`. -/
noncomputable
def tensorCotangentSpace
(H : f.toRingHom.FormallyEtale) :
T ⊗[S] P.CotangentSpace ≃ₗ[T] Q.CotangentSpace :=
letI := f.toRingHom.toAlgebra
haveI : IsScalarTower R P.Ring Q.Ring :=
.of_algebraMap_eq fun r ↦ (f.toRingHom_algebraMap r).symm
letI := ((algebraMap S T).comp (algebraMap P.Ring S)).toAlgebra
haveI : IsScalarTower P.Ring S T := .of_algebraMap_eq' rfl
haveI : IsScalarTower P.Ring Q.Ring T :=
.of_algebraMap_eq fun r ↦ (f.algebraMap_toRingHom r).symm
haveI : FormallyEtale P.Ring Q.Ring := ‹_›
{ __ := (CotangentSpace.map f).liftBaseChange T
invFun := LinearMap.liftBaseChange T (by
refine LinearMap.liftBaseChange _ ?_ ∘ₗ
(tensorKaehlerEquivOfFormallyEtale R P.Ring Q.Ring).symm.toLinearMap
exact (TensorProduct.mk _ _ _ 1).restrictScalars P.Ring ∘ₗ
(TensorProduct.mk _ _ _ 1).restrictScalars P.Ring)
left_inv x := by
change (LinearMap.liftBaseChange _ _ ∘ₗ LinearMap.liftBaseChange _ _) x =
LinearMap.id (R := T) x
congr 1
ext : 4
refine Derivation.liftKaehlerDifferential_unique
(R := R) (S := P.Ring) (M := T ⊗[S] P.CotangentSpace) _ _ ?_
ext a
have : (tensorKaehlerEquivOfFormallyEtale R P.Ring Q.Ring).symm
((D R Q.Ring) (f.toRingHom a)) = 1 ⊗ₜ D _ _ a :=
tensorKaehlerEquivOfFormallyEtale_symm_D_algebraMap R P.Ring Q.Ring a
simp [this]
right_inv x := by
change (LinearMap.liftBaseChange _ _ ∘ₗ LinearMap.liftBaseChange _ _) x =
LinearMap.id (R := T) x
congr 1
ext a
dsimp
obtain ⟨x, hx⟩ := (tensorKaehlerEquivOfFormallyEtale R P.Ring _).surjective (D R Q.Ring a)
simp only [one_smul, ← hx, LinearEquiv.symm_apply_apply]
change (((CotangentSpace.map f).liftBaseChange T).restrictScalars Q.Ring ∘ₗ
LinearMap.liftBaseChange _ _) x = ((TensorProduct.mk _ _ _ 1) ∘ₗ
(tensorKaehlerEquivOfFormallyEtale R P.Ring Q.Ring).toLinearMap) x
congr 1
ext a
simp; rfl }
/-- (Implementation)
If `J ≃ Q ⊗ₚ I` (e.g. when `T = Q ⊗ₚ S` and `P → Q` is flat), then `T ⊗ₛ I/I² ≃ J/J²`.
This is the inverse. -/
noncomputable
def tensorCotangentInvFun
[alg : Algebra P.Ring Q.Ring] (halg : algebraMap P.Ring Q.Ring = f.toRingHom)
(H : Function.Bijective ((f.mapKer halg).liftBaseChange Q.Ring)) :
Q.Cotangent →+ T ⊗[S] P.Cotangent :=
letI := ((algebraMap S T).comp (algebraMap P.Ring S)).toAlgebra
haveI : IsScalarTower P.Ring S T := .of_algebraMap_eq' rfl
haveI : IsScalarTower P.Ring Q.Ring T :=
.of_algebraMap_eq fun r ↦ halg ▸ (f.algebraMap_toRingHom r).symm
letI e := LinearEquiv.ofBijective _ H
letI f' : Q.ker →ₗ[Q.Ring] T ⊗[S] P.Cotangent :=
(LinearMap.liftBaseChange _
((TensorProduct.mk _ _ _ 1).restrictScalars _ ∘ₗ Cotangent.mk)) ∘ₗ e.symm.toLinearMap
QuotientAddGroup.lift _ f' <| by
intro x hx
refine Submodule.smul_induction_on hx ?_ fun _ _ ↦ add_mem
clear x hx
rintro a ha b -
obtain ⟨x, hx⟩ := e.surjective ⟨a, ha⟩
obtain rfl : (e x).1 = a := congr_arg Subtype.val hx
obtain ⟨y, rfl⟩ := e.surjective b
simp only [AddMonoidHom.mem_ker, AddMonoidHom.coe_coe, map_smul,
LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply,
LinearEquiv.symm_apply_apply, f']
clear hx ha
induction x with
| zero => simp only [LinearEquiv.map_zero, ZeroMemClass.coe_zero, zero_smul]
| add x y _ _ =>
simp only [LinearEquiv.map_add, Submodule.coe_add, add_smul, zero_add, *]
| tmul a b =>
induction y with
| zero => simp only [LinearMap.map_zero, smul_zero]
| add x y hx hy => simp only [LinearMap.map_add, smul_add, hx, hy, zero_add]
| tmul c d =>
simp only [LinearMap.liftBaseChange_tmul, LinearMap.coe_comp, SetLike.val_smul,
LinearMap.coe_restrictScalars, Function.comp_apply, mk_apply, smul_eq_mul, e,
LinearMap.liftBaseChange_tmul, LinearEquiv.ofBijective_apply]
have h₂ : b.1 • Cotangent.mk d = 0 := by ext; simp [Cotangent.smul_eq_zero_of_mem _ b.2]
rw [TensorProduct.smul_tmul', mul_smul, f.mapKer_apply_coe, ← halg,
algebraMap_smul, ← TensorProduct.tmul_smul, h₂, tmul_zero, smul_zero]
omit [IsScalarTower R S T] in
lemma tensorCotangentInvFun_smul_mk
[alg : Algebra P.Ring Q.Ring] (halg : algebraMap P.Ring Q.Ring = f.toRingHom)
(H : Function.Bijective ((f.mapKer halg).liftBaseChange Q.Ring)) (x : Q.Ring) (y : P.ker) :
tensorCotangentInvFun f halg H (x • .mk ⟨f.toRingHom y, (f.mapKer halg y).2⟩) =
x • 1 ⊗ₜ .mk y := by
letI := ((algebraMap S T).comp (algebraMap P.Ring S)).toAlgebra
haveI : IsScalarTower P.Ring S T := .of_algebraMap_eq' rfl
haveI : IsScalarTower P.Ring Q.Ring T :=
.of_algebraMap_eq fun r ↦ halg ▸ (f.algebraMap_toRingHom r).symm
letI e := LinearEquiv.ofBijective _ H
trans tensorCotangentInvFun f halg H (.mk ((f.mapKer halg).liftBaseChange Q.Ring (x ⊗ₜ y)))
· simp; rfl
change ((TensorProduct.mk _ _ _ 1).restrictScalars _ ∘ₗ Cotangent.mk).liftBaseChange _
(e.symm (e (x ⊗ₜ y))) = _
rw [e.symm_apply_apply]
simp
/-- If `J ≃ Q ⊗ₚ I` (e.g. when `T = Q ⊗ₚ S` and `P → Q` is flat), then `T ⊗ₛ I/I² ≃ J/J²`. -/
noncomputable
def tensorCotangent [alg : Algebra P.Ring Q.Ring] (halg : algebraMap P.Ring Q.Ring = f.toRingHom)
(H : Function.Bijective ((f.mapKer halg).liftBaseChange Q.Ring)) :
T ⊗[S] P.Cotangent ≃ₗ[T] Q.Cotangent :=
{ __ := (Cotangent.map f).liftBaseChange T
invFun := tensorCotangentInvFun f halg H
left_inv x := by
simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom]
induction x with
| zero => simp only [map_zero]
| add x y _ _ => simp only [map_add, *]
| tmul a b =>
obtain ⟨b, rfl⟩ := Cotangent.mk_surjective b
obtain ⟨a, rfl⟩ := Q.algebraMap_surjective a
simp only [LinearMap.liftBaseChange_tmul, Cotangent.map_mk, Hom.toAlgHom_apply,
algebraMap_smul]
refine (tensorCotangentInvFun_smul_mk f halg H a b).trans ?_
simp [algebraMap_eq_smul_one, TensorProduct.smul_tmul']
right_inv x := by
obtain ⟨x, rfl⟩ := Cotangent.mk_surjective x
obtain ⟨x, rfl⟩ := H.surjective x
simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom]
induction x with
| zero => simp only [map_zero]
| add x y _ _ => simp only [map_add, *]
| tmul a b =>
simp only [LinearMap.liftBaseChange_tmul, map_smul]
simp [Hom.mapKer, tensorCotangentInvFun_smul_mk] }
/-- If `J ≃ Q ⊗ₚ I`, `S → T` is flat and `P → Q` is formally étale, then `T ⊗ H¹(L_P) ≃ H¹(L_Q)`. -/
noncomputable
def tensorH1Cotangent [alg : Algebra P.Ring Q.Ring] (halg : algebraMap P.Ring Q.Ring = f.toRingHom)
[Module.Flat S T]
(H₁ : f.toRingHom.FormallyEtale)
(H₂ : Function.Bijective ((f.mapKer halg).liftBaseChange Q.Ring)) :
T ⊗[S] P.H1Cotangent ≃ₗ[T] Q.H1Cotangent := by
refine .ofBijective ((H1Cotangent.map f).liftBaseChange T) ?_
constructor
· rw [injective_iff_map_eq_zero]
intro x hx
apply Module.Flat.lTensor_preserves_injective_linearMap _ h1Cotangentι_injective
apply (Extension.tensorCotangent f halg H₂).injective
simp only [map_zero]
rw [← h1Cotangentι.map_zero, ← hx]
change ((Cotangent.map f).liftBaseChange T ∘ₗ h1Cotangentι.baseChange T) x =
(h1Cotangentι ∘ₗ _) x
congr 1
ext x
simp
· intro x
have : Function.Exact (h1Cotangentι.baseChange T) (P.cotangentComplex.baseChange T) :=
Module.Flat.lTensor_exact T (LinearMap.exact_subtype_ker_map _)
obtain ⟨a, ha⟩ := (this ((Extension.tensorCotangent f halg H₂).symm x.1)).mp (by
apply (Extension.tensorCotangentSpace f H₁).injective
rw [LinearEquiv.map_zero, ← x.2]
have : (CotangentSpace.map f).liftBaseChange T ∘ₗ P.cotangentComplex.baseChange T =
Q.cotangentComplex ∘ₗ (Cotangent.map f).liftBaseChange T := by
ext x; obtain ⟨x, rfl⟩ := Cotangent.mk_surjective x; dsimp
simp only [CotangentSpace.map_tmul,
map_one, Hom.toAlgHom_apply, one_smul, cotangentComplex_mk]
exact (DFunLike.congr_fun this _).trans (DFunLike.congr_arg Q.cotangentComplex
((tensorCotangent f halg H₂).apply_symm_apply x.1)))
refine ⟨a, Subtype.ext (.trans ?_ ((LinearEquiv.eq_symm_apply _).mp ha))⟩
change (h1Cotangentι ∘ₗ (H1Cotangent.map f).liftBaseChange T) _ =
((Cotangent.map f).liftBaseChange T ∘ₗ h1Cotangentι.baseChange T) _
congr 1
ext; dsimp
end Extension
variable {S}
/-- let `p` be a submonoid of an `R`-algebra `S`. Then `Sₚ ⊗ H¹(L_{S/R}) ≃ H¹(L_{Sₚ/R})`. -/
noncomputable
def tensorH1CotangentOfIsLocalization (M : Submonoid S) [IsLocalization M T] :
T ⊗[S] H1Cotangent R S ≃ₗ[T] H1Cotangent R T := by
letI P : Extension R S := (Generators.self R S).toExtension
letI M' := M.comap (algebraMap P.Ring S)
letI fQ : Localization M' →ₐ[R] T := IsLocalization.liftAlgHom (M := M')
(f := (IsScalarTower.toAlgHom R S T).comp (IsScalarTower.toAlgHom R P.Ring S)) (fun ⟨y, hy⟩ ↦
by simpa using IsLocalization.map_units T ⟨algebraMap P.Ring S y, hy⟩)
letI Q : Extension R T := .ofSurjective fQ (by
intro x
obtain ⟨x, ⟨s, hs⟩, rfl⟩ := IsLocalization.exists_mk'_eq M x
obtain ⟨x, rfl⟩ := P.algebraMap_surjective x
obtain ⟨s, rfl⟩ := P.algebraMap_surjective s
refine ⟨IsLocalization.mk' _ x ⟨s, show s ∈ M' from hs⟩, ?_⟩
simp only [fQ, IsLocalization.coe_liftAlgHom, AlgHom.toRingHom_eq_coe]
rw [IsLocalization.lift_mk'_spec]
simp)
letI f : P.Hom Q :=
{ toRingHom := algebraMap P.Ring (Localization M')
toRingHom_algebraMap x := (IsScalarTower.algebraMap_apply R P.Ring (Localization M') _).symm
algebraMap_toRingHom x := @IsLocalization.lift_eq .. }
haveI : FormallySmooth R P.Ring := inferInstanceAs (FormallySmooth R (MvPolynomial _ _))
haveI : FormallySmooth P.Ring (Localization M') := .of_isLocalization M'
haveI : FormallySmooth R Q.Ring := .comp R P.Ring (Localization M')
haveI : Module.Flat S T := IsLocalization.flat T M
letI : Algebra P.Ring Q.Ring := inferInstanceAs (Algebra P.Ring (Localization M'))
letI := ((algebraMap S T).comp (algebraMap P.Ring S)).toAlgebra
letI := fQ.toRingHom.toAlgebra
haveI : IsScalarTower P.Ring S T := .of_algebraMap_eq' rfl
haveI : IsScalarTower P.Ring (Localization M') T :=
.of_algebraMap_eq fun r ↦ (f.algebraMap_toRingHom r).symm
haveI : IsLocalizedModule M' (IsScalarTower.toAlgHom P.Ring S T).toLinearMap := by
rw [isLocalizedModule_iff_isLocalization]
convert ‹IsLocalization M T› using 1
exact Submonoid.map_comap_eq_of_surjective P.algebraMap_surjective _
refine Extension.tensorH1Cotangent f rfl ?_ ?_ ≪≫ₗ Extension.equivH1CotangentOfFormallySmooth _
· exact RingHom.formallyEtale_algebraMap.mpr
(FormallyEtale.of_isLocalization (M := M') (Rₘ := Localization M'))
· let F : P.ker →ₗ[P.Ring] RingHom.ker fQ := f.mapKer rfl
refine (isLocalizedModule_iff_isBaseChange M' (Localization M') F).mp ?_
have : (LinearMap.ker <| Algebra.linearMap P.Ring S).localized' (Localization M') M'
(Algebra.linearMap P.Ring (Localization M')) = RingHom.ker fQ := by
rw [LinearMap.localized'_ker_eq_ker_localizedMap (Localization M') M'
(Algebra.linearMap P.Ring (Localization M'))
(f' := (IsScalarTower.toAlgHom P.Ring S T).toLinearMap)]
ext x
obtain ⟨x, ⟨s, hs⟩, rfl⟩ := IsLocalization.exists_mk'_eq M' x
simp only [LinearMap.mem_ker, LinearMap.extendScalarsOfIsLocalization_apply', RingHom.mem_ker,
IsLocalization.coe_liftAlgHom, AlgHom.toRingHom_eq_coe, IsLocalization.lift_mk'_spec,
RingHom.coe_coe, AlgHom.coe_comp, IsScalarTower.coe_toAlgHom', Function.comp_apply,
mul_zero, fQ]
have : IsLocalization.mk' (Localization M') x ⟨s, hs⟩ =
IsLocalizedModule.mk' (Algebra.linearMap P.Ring (Localization M')) x ⟨s, hs⟩ := by
rw [IsLocalization.mk'_eq_iff_eq_mul, mul_comm, ← Algebra.smul_def, ← Submonoid.smul_def,
IsLocalizedModule.mk'_cancel']
rfl
simp [this, ← IsScalarTower.algebraMap_apply]
have : F = ((LinearEquiv.ofEq _ _ this).restrictScalars P.Ring).toLinearMap ∘ₗ
P.ker.toLocalized' (Localization M') M' (Algebra.linearMap P.Ring (Localization M')) := by
ext; rfl
rw [this]
exact IsLocalizedModule.of_linearEquiv _ _ _
lemma tensorH1CotangentOfIsLocalization_toLinearMap
(M : Submonoid S) [IsLocalization M T] :
(tensorH1CotangentOfIsLocalization R T M).toLinearMap =
(Algebra.H1Cotangent.map R R S T).liftBaseChange T := by
ext x : 3
simp only [AlgebraTensorModule.curry_apply, curry_apply, LinearMap.coe_restrictScalars,
LinearEquiv.coe_coe, LinearMap.liftBaseChange_tmul, one_smul]
simp only [tensorH1CotangentOfIsLocalization, Generators.toExtension_Ring,
Generators.toExtension_commRing, Generators.toExtension_algebra₂,
Extension.tensorH1Cotangent,
LinearEquiv.ofBijective_apply, LinearMap.liftBaseChange_tmul, one_smul,
Extension.equivH1CotangentOfFormallySmooth, LinearEquiv.trans_apply]
letI P : Extension R S := (Generators.self R S).toExtension
letI M' := M.comap (algebraMap P.Ring S)
letI fQ : Localization M' →ₐ[R] T := IsLocalization.liftAlgHom (M := M')
(f := (IsScalarTower.toAlgHom R S T).comp (IsScalarTower.toAlgHom R P.Ring S)) (fun ⟨y, hy⟩ ↦
by simpa using IsLocalization.map_units T ⟨algebraMap P.Ring S y, hy⟩)
letI Q : Extension R T := .ofSurjective fQ (by
intro x
obtain ⟨x, ⟨s, hs⟩, rfl⟩ := IsLocalization.exists_mk'_eq M x
obtain ⟨x, rfl⟩ := P.algebraMap_surjective x
obtain ⟨s, rfl⟩ := P.algebraMap_surjective s
refine ⟨IsLocalization.mk' _ x ⟨s, show s ∈ M' from hs⟩, ?_⟩
simp only [fQ, IsLocalization.coe_liftAlgHom, AlgHom.toRingHom_eq_coe]
rw [IsLocalization.lift_mk'_spec]
simp)
letI f : (Generators.self R T).toExtension.Hom Q :=
{ toRingHom := (MvPolynomial.aeval Q.σ).toRingHom
toRingHom_algebraMap := (MvPolynomial.aeval Q.σ).commutes
algebraMap_toRingHom := by
have : (IsScalarTower.toAlgHom R Q.Ring T).comp (MvPolynomial.aeval Q.σ) =
IsScalarTower.toAlgHom _ (Generators.self R T).toExtension.Ring _ := by
ext i
change _ = algebraMap (Generators.self R T).Ring _ (.X i)
simp
exact DFunLike.congr_fun this }
rw [← Extension.H1Cotangent.equivOfFormallySmooth_symm, LinearEquiv.symm_apply_eq,
@Extension.H1Cotangent.equivOfFormallySmooth_apply (f := f),
Algebra.H1Cotangent.map, ← (Extension.H1Cotangent.map f).coe_restrictScalars S,
← LinearMap.comp_apply, ← Extension.H1Cotangent.map_comp, Extension.H1Cotangent.map_eq]
instance H1Cotangent.isLocalizedModule (M : Submonoid S) [IsLocalization M T] :
IsLocalizedModule M (Algebra.H1Cotangent.map R R S T) := by
rw [isLocalizedModule_iff_isBaseChange M T]
change Function.Bijective ((Algebra.H1Cotangent.map R R S T).liftBaseChange T)
rw [← tensorH1CotangentOfIsLocalization_toLinearMap R T M]
exact (tensorH1CotangentOfIsLocalization R T M).bijective
end Algebra |
.lake/packages/mathlib/Mathlib/RingTheory/Etale/Pi.lean | import Mathlib.RingTheory.Smooth.Pi
import Mathlib.RingTheory.Unramified.Pi
import Mathlib.RingTheory.Etale.Basic
/-!
# Formal-étaleness of finite products of rings
## Main result
- `Algebra.FormallyEtale.pi_iff`: If `I` is finite, `Π i : I, A i` is `R`-formally-étale
if and only if each `A i` is `R`-formally-étale.
-/
namespace Algebra.FormallyEtale
variable {R : Type*} {I : Type*} (A : I → Type*)
variable [CommRing R] [∀ i, CommRing (A i)] [∀ i, Algebra R (A i)]
theorem pi_iff [Finite I] :
FormallyEtale R (Π i, A i) ↔ ∀ i, FormallyEtale R (A i) := by
simp_rw [FormallyEtale.iff_formallyUnramified_and_formallySmooth, forall_and]
rw [FormallyUnramified.pi_iff A, FormallySmooth.pi_iff A]
instance [Finite I] [∀ i, FormallyEtale R (A i)] : FormallyEtale R (Π i, A i) :=
.of_formallyUnramified_and_formallySmooth
end Algebra.FormallyEtale |
.lake/packages/mathlib/Mathlib/RingTheory/Etale/Basic.lean | import Mathlib.RingTheory.Ideal.Quotient.Nilpotent
import Mathlib.RingTheory.Smooth.Basic
import Mathlib.RingTheory.Unramified.Basic
/-!
# Étale morphisms
An `R`-algebra `A` is formally etale if `Ω[A⁄R]` and `H¹(L_{A/R})` both vanish.
This is equivalent to the standard definition that "for every `R`-algebra `B`,
every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists
exactly one lift `A →ₐ[R] B`".
An `R`-algebra `A` is étale if it is formally étale and of finite presentation.
We show that the property extends onto nilpotent ideals, and that these properties are stable
under `R`-algebra homomorphisms and compositions.
We show that étale is stable under algebra isomorphisms, composition and
localization at an element.
-/
open scoped TensorProduct
universe u v
namespace Algebra
variable {R : Type u} {A : Type v} {B : Type*} [CommRing R] [CommRing A] [Algebra R A]
[CommRing B] [Algebra R B]
section
variable (R A) in
/-- An `R`-algebra `A` is formally etale if both `Ω[A⁄R]` and `H¹(L_{A/R})` are zero.
For the infinitesimal lifting definition, see `FormallyEtale.iff_comp_bijective`. -/
@[mk_iff, stacks 00UQ]
class FormallyEtale : Prop where
subsingleton_kaehlerDifferential : Subsingleton Ω[A⁄R]
subsingleton_h1Cotangent : Subsingleton (H1Cotangent R A)
attribute [instance]
FormallyEtale.subsingleton_kaehlerDifferential FormallyEtale.subsingleton_h1Cotangent
end
namespace FormallyEtale
section
instance (priority := 100) [FormallyEtale R A] :
FormallyUnramified R A := ⟨inferInstance⟩
instance (priority := 100) [FormallyEtale R A] : FormallySmooth R A :=
⟨inferInstance, inferInstance⟩
theorem iff_formallyUnramified_and_formallySmooth :
FormallyEtale R A ↔ FormallyUnramified R A ∧ FormallySmooth R A :=
⟨fun _ ↦ ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ ↦ ⟨inferInstance, inferInstance⟩⟩
@[deprecated (since := "2025-11-03")]
alias iff_unramified_and_smooth := iff_formallyUnramified_and_formallySmooth
theorem of_formallyUnramified_and_formallySmooth [FormallyUnramified R A]
[FormallySmooth R A] : FormallyEtale R A :=
FormallyEtale.iff_formallyUnramified_and_formallySmooth.mpr ⟨‹_›, ‹_›⟩
@[deprecated (since := "2025-11-03")]
alias of_unramified_and_smooth := of_formallyUnramified_and_formallySmooth
variable (R A) in
lemma comp_bijective [FormallyEtale R A] (I : Ideal B) (hI : I ^ 2 = ⊥) :
Function.Bijective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I) :=
⟨FormallyUnramified.comp_injective I hI, FormallySmooth.comp_surjective R A I hI⟩
/--
An `R`-algebra `A` is formally etale iff "for every `R`-algebra `B`,
every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists
a unique lift `A →ₐ[R] B`".
-/
theorem iff_comp_bijective :
FormallyEtale R A ↔ ∀ ⦃B : Type max u v⦄ [CommRing B] [Algebra R B] (I : Ideal B), I ^ 2 = ⊥ →
Function.Bijective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I) :=
⟨fun _ _ ↦ comp_bijective R A, fun H ↦
have : FormallyUnramified R A := FormallyUnramified.iff_comp_injective_of_small.{max u v}.mpr
(by aesop (add safe Function.Bijective.injective))
have : FormallySmooth R A := FormallySmooth.of_comp_surjective
(by aesop (add safe Function.Bijective.surjective))
.of_formallyUnramified_and_formallySmooth⟩
end
section OfEquiv
theorem of_equiv [FormallyEtale R A] (e : A ≃ₐ[R] B) : FormallyEtale R B :=
FormallyEtale.iff_formallyUnramified_and_formallySmooth.mpr
⟨FormallyUnramified.of_equiv e, FormallySmooth.of_equiv e⟩
theorem iff_of_equiv (e : A ≃ₐ[R] B) : FormallyEtale R A ↔ FormallyEtale R B :=
⟨fun _ ↦ of_equiv e, fun _ ↦ of_equiv e.symm⟩
end OfEquiv
section Comp
variable (R A B) in
theorem comp [Algebra A B] [IsScalarTower R A B] [FormallyEtale R A] [FormallyEtale A B] :
FormallyEtale R B :=
FormallyEtale.iff_formallyUnramified_and_formallySmooth.mpr
⟨FormallyUnramified.comp R A B, FormallySmooth.comp R A B⟩
end Comp
section BaseChange
open scoped TensorProduct
instance [FormallyEtale R A] : FormallyEtale B (B ⊗[R] A) :=
.of_formallyUnramified_and_formallySmooth
end BaseChange
section Localization
/-!
We now consider a commutative square of commutative rings
```
R -----> S
| |
| |
v v
Rₘ ----> Sₘ
```
where `Rₘ` and `Sₘ` are the localisations of `R` and `S` at a multiplicatively closed
subset `M` of `R`.
-/
/-! Let R, S, Rₘ, Sₘ be commutative rings -/
variable {R S Rₘ Sₘ : Type*} [CommRing R] [CommRing S] [CommRing Rₘ] [CommRing Sₘ]
/-! Let M be a multiplicatively closed subset of `R` -/
variable (M : Submonoid R)
/-! Assume that the rings are in a commutative diagram as above. -/
variable [Algebra R S] [Algebra R Sₘ] [Algebra S Sₘ] [Algebra R Rₘ] [Algebra Rₘ Sₘ]
variable [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ]
/-! and that Rₘ and Sₘ are localizations of R and S at M. -/
variable [IsLocalization M Rₘ] [IsLocalization (M.map (algebraMap R S)) Sₘ]
include M
theorem of_isLocalization : FormallyEtale R Rₘ :=
FormallyEtale.iff_formallyUnramified_and_formallySmooth.mpr
⟨FormallyUnramified.of_isLocalization M, FormallySmooth.of_isLocalization M⟩
theorem localization_base [FormallyEtale R Sₘ] : FormallyEtale Rₘ Sₘ :=
FormallyEtale.iff_formallyUnramified_and_formallySmooth.mpr
⟨FormallyUnramified.localization_base M, FormallySmooth.localization_base M⟩
/-- The localization of a formally étale map is formally étale. -/
theorem localization_map [FormallyEtale R S] : FormallyEtale Rₘ Sₘ := by
haveI : FormallyEtale S Sₘ := FormallyEtale.of_isLocalization (M.map (algebraMap R S))
haveI : FormallyEtale R Sₘ := FormallyEtale.comp R S Sₘ
exact FormallyEtale.localization_base M
end Localization
end FormallyEtale
section
variable (R A) in
/-- An `R`-algebra `A` is étale if it is formally étale and of finite presentation. -/
@[stacks 00U1 "Note that this is a different definition from this Stacks entry, but
<https://stacks.math.columbia.edu/tag/00UR> shows that it is equivalent to the definition here."]
class Etale : Prop where
formallyEtale : FormallyEtale R A := by infer_instance
finitePresentation : FinitePresentation R A := by infer_instance
end
namespace Etale
attribute [instance] formallyEtale finitePresentation
/-- Being étale is transported via algebra isomorphisms. -/
theorem of_equiv [Etale R A] (e : A ≃ₐ[R] B) : Etale R B where
formallyEtale := FormallyEtale.of_equiv e
finitePresentation := FinitePresentation.equiv e
section Comp
variable (R A B)
/-- Étale is stable under composition. -/
theorem comp [Algebra A B] [IsScalarTower R A B] [Etale R A] [Etale A B] : Etale R B where
formallyEtale := FormallyEtale.comp R A B
finitePresentation := FinitePresentation.trans R A B
/-- Étale is stable under base change. -/
instance baseChange [Etale R A] : Etale B (B ⊗[R] A) where
end Comp
/-- Localization at an element is étale. -/
theorem of_isLocalizationAway (r : R) [IsLocalization.Away r A] : Etale R A where
formallyEtale := Algebra.FormallyEtale.of_isLocalization (Submonoid.powers r)
finitePresentation := IsLocalization.Away.finitePresentation r
@[deprecated (since := "2025-11-03")] alias of_isLocalization_Away := of_isLocalizationAway
end Etale
end Algebra
namespace RingHom
variable {R S : Type*} [CommRing R] [CommRing S]
/--
A ring homomorphism `R →+* A` is formally étale if it is formally unramified and formally smooth.
See `Algebra.FormallyEtale`.
-/
@[algebraize Algebra.FormallyEtale]
def FormallyEtale (f : R →+* S) : Prop :=
letI := f.toAlgebra
Algebra.FormallyEtale R S
lemma formallyEtale_algebraMap [Algebra R S] :
(algebraMap R S).FormallyEtale ↔ Algebra.FormallyEtale R S := by
rw [FormallyEtale, toAlgebra_algebraMap]
end RingHom |
.lake/packages/mathlib/Mathlib/RingTheory/Etale/Field.lean | import Mathlib.RingTheory.Etale.Pi
import Mathlib.RingTheory.Unramified.Field
/-!
# Étale algebras over fields
## Main results
Let `K` be a field, `A` be a `K`-algebra and `L` be a field extension of `K`.
- `Algebra.FormallyEtale.of_isSeparable`:
If `L` is separable over `K`, then `L` is formally étale over `K`.
- `Algebra.FormallyEtale.iff_isSeparable`:
If `L` is (essentially) of finite type over `K`, then `L/K` is étale iff `L/K` is separable.
- `Algebra.FormallyEtale.iff_exists_algEquiv_prod`:
If `A` is (essentially) of finite type over `K`,
then `A/K` is étale iff `A` is a finite product of separable field extensions.
- `Algebra.Etale.iff_exists_algEquiv_prod`:
`A/K` is étale iff `A` is a finite product of finite separable field extensions.
## References
- [B. Iversen, *Generic Local Structure of the Morphisms in Commutative Algebra*][iversen]
-/
universe u
variable (K L : Type*) (A : Type u) [Field K] [Field L] [CommRing A] [Algebra K L] [Algebra K A]
open Algebra Polynomial
open scoped TensorProduct
namespace Algebra.FormallyEtale
/--
This is a weaker version of `of_isSeparable` that additionally assumes `EssFiniteType K L`.
Use that instead.
This is Iversen Corollary II.5.3.
-/
theorem of_isSeparable_aux [Algebra.IsSeparable K L] [EssFiniteType K L] :
FormallyEtale K L := by
-- We already know that for field extensions
-- IsSeparable + EssFiniteType => FormallyUnramified + Finite
have := FormallyUnramified.of_isSeparable K L
have := FormallyUnramified.finite_of_free (R := K) (S := L)
-- We shall show that any `f : L → B/I` can be lifted to `L → B` if `I^2 = ⊥`
refine FormallyEtale.iff_comp_bijective.mpr fun B _ _ I h ↦ ?_
refine ⟨FormallyUnramified.iff_comp_injective_of_small.mp
(FormallyUnramified.of_isSeparable K L) I h, ?_⟩
intro f
-- By separability and finiteness, we may assume `L = K(α)` with `p` the minpoly of `α`.
let pb := Field.powerBasisOfFiniteOfSeparable K L
-- Let `x : B` such that `f(α) = x` in `B / I`.
obtain ⟨x, hx⟩ := Ideal.Quotient.mk_surjective (f pb.gen)
have helper : ∀ x, IsScalarTower.toAlgHom K B (B ⧸ I) x = Ideal.Quotient.mk I x := fun _ ↦ rfl
-- Then `p(x) = 0 mod I`, and the goal is to find some `ε ∈ I` such that
-- `p(x + ε) = p(x) + ε p'(x) = 0`, and we will get our lift into `B`.
have hx' : Ideal.Quotient.mk I (aeval x (minpoly K pb.gen)) = 0 := by
rw [← helper, ← aeval_algHom_apply, helper, hx, aeval_algHom_apply, minpoly.aeval, map_zero]
-- Since `p` is separable, `-p'(x)` is invertible in `B ⧸ I`,
obtain ⟨u, hu⟩ : ∃ u, (aeval x) (derivative (minpoly K pb.gen)) * u + 1 ∈ I := by
have := (isUnit_iff_ne_zero.mpr ((Algebra.IsSeparable.isSeparable K
pb.gen).aeval_derivative_ne_zero (minpoly.aeval K _))).map f
rw [← aeval_algHom_apply, ← hx, ← helper, aeval_algHom_apply, helper] at this
obtain ⟨u, hu⟩ := Ideal.Quotient.mk_surjective (-this.unit⁻¹ : B ⧸ I)
use u
rw [← Ideal.Quotient.eq_zero_iff_mem, map_add, map_mul, map_one, hu, mul_neg,
IsUnit.mul_val_inv, neg_add_cancel]
-- And `ε = p(x)/(-p'(x))` works.
use pb.liftEquiv.symm ⟨x + u * aeval x (minpoly K pb.gen), ?_⟩
· apply pb.algHom_ext
simp [hx, hx']
· rw [← eval_map_algebraMap, Polynomial.eval_add_of_sq_eq_zero, derivative_map,
← one_mul (eval x _), eval_map_algebraMap, eval_map_algebraMap, ← mul_assoc, ← add_mul,
← Ideal.mem_bot, ← h, pow_two, add_comm]
· exact Ideal.mul_mem_mul hu (Ideal.Quotient.eq_zero_iff_mem.mp hx')
rw [← Ideal.mem_bot, ← h]
apply Ideal.pow_mem_pow
rw [← Ideal.Quotient.eq_zero_iff_mem, map_mul, hx', mul_zero]
open scoped IntermediateField in
lemma of_isSeparable [Algebra.IsSeparable K L] : FormallyEtale K L := by
-- We shall show that any `f : L → B/I` can be lifted to `L → B` if `I^2 = ⊥`.
refine FormallyEtale.iff_comp_bijective.mpr fun B _ _ I h ↦ ?_
-- But we already know that there exists a unique lift for every finite subfield of `L`
-- by `of_isSeparable_aux`, so we can glue them all together.
refine ⟨FormallyUnramified.iff_comp_injective_of_small.mp
(FormallyUnramified.of_isSeparable K L) I h, ?_⟩
intro f
have : ∀ k : L, ∃! g : K⟮k⟯ →ₐ[K] B,
(Ideal.Quotient.mkₐ K I).comp g = f.comp (IsScalarTower.toAlgHom K _ L) := by
intro k
have := IsSeparable.of_algHom _ _ (IsScalarTower.toAlgHom K (K⟮k⟯) L)
have := IntermediateField.adjoin.finiteDimensional
(Algebra.IsSeparable.isSeparable K k).isIntegral
have := FormallyEtale.of_isSeparable_aux K (K⟮k⟯)
have := FormallyEtale.comp_bijective (R := K) (A := K⟮k⟯) I h
exact this.existsUnique _
choose g hg₁ hg₂ using this
have hg₃ : ∀ x y (h : x ∈ K⟮y⟯), g y ⟨x, h⟩ = g x (IntermediateField.AdjoinSimple.gen K x) := by
intro x y h
have e : K⟮x⟯ ≤ K⟮y⟯ := by
rw [IntermediateField.adjoin_le_iff]
rintro _ rfl
exact h
rw [← hg₂ _ ((g _).comp (IntermediateField.inclusion e))]
· rfl
apply AlgHom.ext
intro ⟨a, _⟩
rw [← AlgHom.comp_assoc, hg₁, AlgHom.comp_assoc]
simp
have H : ∀ x y : L, ∃ α : L, x ∈ K⟮α⟯ ∧ y ∈ K⟮α⟯ := by
intro x y
have : FiniteDimensional K K⟮x, y⟯ := by
apply IntermediateField.finiteDimensional_adjoin
intro x _; exact (Algebra.IsSeparable.isSeparable K x).isIntegral
have := IsSeparable.of_algHom _ _ (IsScalarTower.toAlgHom K (K⟮x, y⟯) L)
obtain ⟨⟨α, hα⟩, e⟩ := Field.exists_primitive_element K K⟮x, y⟯
apply_fun (IntermediateField.map (IntermediateField.val _)) at e
rw [IntermediateField.adjoin_map, ← AlgHom.fieldRange_eq_map] at e
simp only [IntermediateField.coe_val, Set.image_singleton,
IntermediateField.fieldRange_val] at e
have hx : x ∈ K⟮α⟯ := e ▸ IntermediateField.subset_adjoin K {x, y} (by simp)
have hy : y ∈ K⟮α⟯ := e ▸ IntermediateField.subset_adjoin K {x, y} (by simp)
exact ⟨α, hx, hy⟩
refine ⟨⟨⟨⟨⟨fun x ↦ g x (IntermediateField.AdjoinSimple.gen K x), ?_⟩, ?_⟩, ?_, ?_⟩, ?_⟩, ?_⟩
· change g 1 1 = 1; rw [map_one]
· intro x y
obtain ⟨α, hx, hy⟩ := H x y
simp only [← hg₃ _ _ hx, ← hg₃ _ _ hy, ← map_mul, ← hg₃ _ _ (mul_mem hx hy)]
rfl
· change g 0 0 = 0; rw [map_zero]
· intro x y
obtain ⟨α, hx, hy⟩ := H x y
simp only [← hg₃ _ _ hx, ← hg₃ _ _ hy, ← map_add, ← hg₃ _ _ (add_mem hx hy)]
rfl
· intro r
change g _ (algebraMap K _ r) = _
rw [AlgHom.commutes]
· ext x
simpa using AlgHom.congr_fun (hg₁ x) (IntermediateField.AdjoinSimple.gen K x)
theorem iff_isSeparable [EssFiniteType K L] :
FormallyEtale K L ↔ Algebra.IsSeparable K L :=
⟨fun _ ↦ FormallyUnramified.isSeparable K L, fun _ ↦ of_isSeparable K L⟩
attribute [local instance] IsArtinianRing.fieldOfSubtypeIsMaximal in
/--
If `A` is an essentially of finite type algebra over a field `K`, then `A` is formally étale
over `K` if and only if `A` is a finite product of separable field extensions.
-/
theorem iff_exists_algEquiv_prod [EssFiniteType K A] :
FormallyEtale K A ↔
∃ (I : Type u) (_ : Finite I) (Ai : I → Type u) (_ : ∀ i, Field (Ai i))
(_ : ∀ i, Algebra K (Ai i)) (_ : A ≃ₐ[K] Π i, Ai i),
∀ i, Algebra.IsSeparable K (Ai i) := by
classical
constructor
· intro H
have := FormallyUnramified.finite_of_free K A
have := FormallyUnramified.isReduced_of_field K A
have : IsArtinianRing A := isArtinian_of_tower K inferInstance
letI : Fintype (MaximalSpectrum A) := (nonempty_fintype _).some
let v (i : MaximalSpectrum A) : A := (IsArtinianRing.equivPi A).symm (Pi.single i 1)
let e : A ≃ₐ[K] _ := { __ := IsArtinianRing.equivPi A, commutes' := fun r ↦ rfl }
have := (FormallyEtale.iff_of_equiv e).mp inferInstance
rw [FormallyEtale.pi_iff] at this
exact ⟨_, inferInstance, _, _, _, e, fun I ↦ (iff_isSeparable _ _).mp inferInstance⟩
· intro ⟨I, _, Ai, _, _, e, _⟩
rw [FormallyEtale.iff_of_equiv e, FormallyEtale.pi_iff]
exact fun I ↦ of_isSeparable K (Ai I)
end Algebra.FormallyEtale
/--
`A` is étale over a field `K` if and only if
`A` is a finite product of finite separable field extensions.
-/
theorem Algebra.Etale.iff_exists_algEquiv_prod :
Etale K A ↔
∃ (I : Type u) (_ : Finite I) (Ai : I → Type u) (_ : ∀ i, Field (Ai i))
(_ : ∀ i, Algebra K (Ai i)) (_ : A ≃ₐ[K] Π i, Ai i),
∀ i, Module.Finite K (Ai i) ∧ Algebra.IsSeparable K (Ai i) := by
constructor
· intro H
obtain ⟨I, _, Ai, _, _, e, _⟩ := (FormallyEtale.iff_exists_algEquiv_prod K A).mp inferInstance
have := FormallyUnramified.finite_of_free K A
exact ⟨_, ‹_›, _, _, _, e, fun i ↦ ⟨.of_surjective ((LinearMap.proj i).comp e.toLinearMap)
((Function.surjective_eval i).comp e.surjective), inferInstance⟩⟩
· intro ⟨I, _, Ai, _, _, e, H⟩
choose h₁ h₂ using H
have := Module.Finite.of_surjective e.symm.toLinearMap e.symm.surjective
refine ⟨?_, FinitePresentation.of_finiteType.mp inferInstance⟩
exact (FormallyEtale.iff_exists_algEquiv_prod K A).mpr ⟨_, inferInstance, _, _, _, e, h₂⟩ |
.lake/packages/mathlib/Mathlib/RingTheory/Smooth/StandardSmooth.lean | import Mathlib.RingTheory.Extension.Presentation.Submersive
/-!
# Standard smooth algebras
A standard smooth algebra is an algebra that admits a `SubmersivePresentation`. A standard
smooth algebra is of relative dimension `n` if it admits a submersive presentation of
dimension `n`.
While every standard smooth algebra is smooth, the converse does not hold. But if `S` is `R`-smooth,
then `S` is `R`-standard smooth locally on `S`, i.e. there exists a set `{ t }` of `S` that
generates the unit ideal, such that `Sₜ` is `R`-standard smooth for every `t` (TODO, see below).
## Main definitions
All of these are in the `Algebra` namespace. Let `S` be an `R`-algebra.
- `Algebra.IsStandardSmooth`: `S` is `R`-standard smooth if `S` admits a submersive
`R`-presentation.
- `Algebra.IsStandardSmooth.relativeDimension`: If `S` is `R`-standard smooth this is the dimension
of an arbitrary submersive `R`-presentation of `S`. This is independent of the choice
of the presentation (TODO, see below).
- `Algebra.IsStandardSmoothOfRelativeDimension n`: `S` is `R`-standard smooth of relative dimension
`n` if it admits a submersive `R`-presentation of dimension `n`.
## TODO
- Show that locally on the target, smooth algebras are standard smooth.
## Notes
This contribution was created as part of the AIM workshop "Formalizing algebraic geometry"
in June 2024.
-/
universe t t' w w' u v
open TensorProduct Module MvPolynomial
variable (n m : ℕ)
namespace Algebra
variable (R : Type u) (S : Type v) (ι : Type w) (σ : Type t) [CommRing R] [CommRing S] [Algebra R S]
attribute [local instance] Fintype.ofFinite
/--
An `R`-algebra `S` is called standard smooth, if there
exists a submersive presentation.
-/
class IsStandardSmooth : Prop where
out : ∃ (ι σ : Type) (_ : Finite σ), Finite ι ∧ Nonempty (SubmersivePresentation R S ι σ)
variable [Finite σ]
lemma SubmersivePresentation.isStandardSmooth [Finite ι] (P : SubmersivePresentation R S ι σ) :
IsStandardSmooth R S := by
exact ⟨_, _, _, inferInstance, ⟨P.reindex (Fintype.equivFin _).symm (Fintype.equivFin _).symm⟩⟩
/--
The relative dimension of a standard smooth `R`-algebra `S` is
the dimension of an arbitrarily chosen submersive `R`-presentation of `S`.
Note: If `S` is non-trivial, this number is independent of the choice of the presentation as it is
equal to the `S`-rank of `Ω[S/R]`
(see `IsStandardSmoothOfRelativeDimension.rank_kaehlerDifferential`).
-/
noncomputable def IsStandardSmooth.relativeDimension [IsStandardSmooth R S] : ℕ :=
letI := ‹IsStandardSmooth R S›.out.choose_spec.choose_spec.choose
‹IsStandardSmooth R S›.out.choose_spec.choose_spec.choose_spec.2.some.dimension
/--
An `R`-algebra `S` is called standard smooth of relative dimension `n`, if there exists
a submersive presentation of dimension `n`.
-/
class IsStandardSmoothOfRelativeDimension : Prop where
out : ∃ (ι σ : Type) (_ : Finite σ) (_ : Finite ι) (P : SubmersivePresentation R S ι σ),
P.dimension = n
lemma SubmersivePresentation.isStandardSmoothOfRelativeDimension [Finite ι]
(P : SubmersivePresentation R S ι σ) (hP : P.dimension = n) :
IsStandardSmoothOfRelativeDimension n R S := by
refine ⟨⟨_, _, _, inferInstance,
P.reindex (Fintype.equivFin _).symm (Fintype.equivFin σ).symm, ?_⟩⟩
simp [hP]
variable {R} {S}
lemma IsStandardSmoothOfRelativeDimension.isStandardSmooth
[H : IsStandardSmoothOfRelativeDimension n R S] : IsStandardSmooth R S :=
⟨_, _, _, H.out.choose_spec.choose_spec.choose_spec.choose,
H.out.choose_spec.choose_spec.choose_spec.choose_spec.nonempty⟩
lemma IsStandardSmoothOfRelativeDimension.of_algebraMap_bijective
(h : Function.Bijective (algebraMap R S)) :
IsStandardSmoothOfRelativeDimension 0 R S :=
⟨_, _, _, inferInstance,
SubmersivePresentation.ofBijectiveAlgebraMap h, Presentation.ofBijectiveAlgebraMap_dimension h⟩
variable (R) in
instance IsStandardSmoothOfRelativeDimension.id :
IsStandardSmoothOfRelativeDimension 0 R R :=
IsStandardSmoothOfRelativeDimension.of_algebraMap_bijective Function.bijective_id
instance (priority := 100) IsStandardSmooth.finitePresentation [IsStandardSmooth R S] :
FinitePresentation R S := by
obtain ⟨_, _, _, _, ⟨P⟩⟩ := ‹IsStandardSmooth R S›
exact P.finitePresentation_of_isFinite
section Composition
variable (R S T) [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T]
lemma IsStandardSmooth.trans [IsStandardSmooth R S] [IsStandardSmooth S T] :
IsStandardSmooth R T where
out := by
obtain ⟨_, _, _, _, ⟨P⟩⟩ := ‹IsStandardSmooth R S›
obtain ⟨_, _, _, _, ⟨Q⟩⟩ := ‹IsStandardSmooth S T›
exact ⟨_, _, _, inferInstance, ⟨Q.comp P⟩⟩
lemma IsStandardSmoothOfRelativeDimension.trans [IsStandardSmoothOfRelativeDimension n R S]
[IsStandardSmoothOfRelativeDimension m S T] :
IsStandardSmoothOfRelativeDimension (m + n) R T where
out := by
obtain ⟨_, _, _, _, P, hP⟩ := ‹IsStandardSmoothOfRelativeDimension n R S›
obtain ⟨_, _, _, _, Q, hQ⟩ := ‹IsStandardSmoothOfRelativeDimension m S T›
refine ⟨_, _, _, inferInstance, Q.comp P, hP ▸ hQ ▸ ?_⟩
apply PreSubmersivePresentation.dimension_comp_eq_dimension_add_dimension
end Composition
lemma IsStandardSmooth.localization_away (r : R) [IsLocalization.Away r S] :
IsStandardSmooth R S where
out := ⟨_, _, _, inferInstance, ⟨SubmersivePresentation.localizationAway S r⟩⟩
lemma IsStandardSmoothOfRelativeDimension.localization_away (r : R) [IsLocalization.Away r S] :
IsStandardSmoothOfRelativeDimension 0 R S where
out := ⟨_, _, _, inferInstance, SubmersivePresentation.localizationAway S r,
Presentation.localizationAway_dimension_zero r⟩
section BaseChange
variable (T) [CommRing T] [Algebra R T]
instance IsStandardSmooth.baseChange [IsStandardSmooth R S] :
IsStandardSmooth T (T ⊗[R] S) where
out := by
obtain ⟨ι, σ, _, _, ⟨P⟩⟩ := ‹IsStandardSmooth R S›
exact ⟨ι, σ, _, inferInstance, ⟨P.baseChange T⟩⟩
instance IsStandardSmoothOfRelativeDimension.baseChange
[IsStandardSmoothOfRelativeDimension n R S] :
IsStandardSmoothOfRelativeDimension n T (T ⊗[R] S) where
out := by
obtain ⟨_, _, _, _, P, hP⟩ := ‹IsStandardSmoothOfRelativeDimension n R S›
exact ⟨_, _, _, inferInstance, P.baseChange T, hP⟩
end BaseChange
instance (priority := 100) [Subsingleton S] : IsStandardSmooth R S :=
⟨Unit, Unit, inferInstance, inferInstance, ⟨.ofSubsingleton R S⟩⟩
instance (priority := 100) [Subsingleton S] : IsStandardSmoothOfRelativeDimension 0 R S :=
⟨Unit, Unit, inferInstance, inferInstance, .ofSubsingleton R S, by simp [Presentation.dimension]⟩
end Algebra |
.lake/packages/mathlib/Mathlib/RingTheory/Smooth/Kaehler.lean | import Mathlib.RingTheory.Extension.Cotangent.Basic
/-!
# Relation of smoothness and `Ω[S⁄R]`
## Main results
- `retractionKerToTensorEquivSection`:
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with square-zero kernel `I`,
there is a one-to-one correspondence between `P`-linear retractions of `I →ₗ[P] S ⊗[P] Ω[P/R]`
and algebra homomorphism sections of `f`.
- `retractionKerCotangentToTensorEquivSection`:
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with kernel `I`,
there is a one-to-one correspondence between `P`-linear retractions of `I/I² →ₗ[P] S ⊗[P] Ω[P/R]`
and algebra homomorphism sections of `f‾ : P/I² → S`.
## Future projects
- Show that being smooth is local on stalks.
- Show that being formally smooth is Zariski-local (very hard).
## References
- https://stacks.math.columbia.edu/tag/00TH
- [B. Iversen, *Generic Local Structure of the Morphisms in Commutative Algebra*][iversen]
-/
universe u
open TensorProduct KaehlerDifferential
open Function (Surjective)
variable {R P S : Type*} [CommRing R] [CommRing P] [CommRing S]
variable [Algebra R P] [Algebra P S]
section ofSection
variable [Algebra R S] [IsScalarTower R P S]
-- Suppose we have a section (as an algebra homomorphism) of `P →ₐ[R] S`.
variable (g : S →ₐ[R] P)
/--
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with square-zero kernel `I`,
and a section `g : S →ₐ[R] P` (as an algebra homomorphism),
we get an `R`-derivation `P → I` via `x ↦ x - g (f x)`.
-/
@[simps]
def derivationOfSectionOfKerSqZero (f : P →ₐ[R] S) (hf' : (RingHom.ker f) ^ 2 = ⊥) (g : S →ₐ[R] P)
(hg : f.comp g = AlgHom.id R S) : Derivation R P (RingHom.ker f) where
toFun x := ⟨x - g (f x), by
simpa [RingHom.mem_ker, sub_eq_zero] using AlgHom.congr_fun hg.symm (f x)⟩
map_add' x y := by simp only [map_add, AddMemClass.mk_add_mk, Subtype.mk.injEq]; ring
map_smul' x y := by
ext
simp only [Algebra.smul_def, map_mul, AlgHom.commutes,
RingHom.id_apply, Submodule.coe_smul_of_tower]
ring
map_one_eq_zero' := by simp only [LinearMap.coe_mk, AddHom.coe_mk, map_one, sub_self,
Submodule.mk_eq_zero]
leibniz' a b := by
have : (a - g (f a)) * (b - g (f b)) = 0 := by
rw [← Ideal.mem_bot, ← hf', pow_two]
apply Ideal.mul_mem_mul
· simpa [RingHom.mem_ker, sub_eq_zero] using AlgHom.congr_fun hg.symm (f a)
· simpa [RingHom.mem_ker, sub_eq_zero] using AlgHom.congr_fun hg.symm (f b)
ext
rw [← sub_eq_zero]
conv_rhs => rw [← neg_zero, ← this]
simp only [LinearMap.coe_mk, AddHom.coe_mk, map_mul, SetLike.mk_smul_mk, smul_eq_mul, mul_sub,
AddMemClass.mk_add_mk, sub_mul, neg_sub]
ring
variable (hf' : (RingHom.ker (algebraMap P S)) ^ 2 = ⊥)
(hg : (IsScalarTower.toAlgHom R P S).comp g = AlgHom.id R S)
include hf' hg
lemma isScalarTower_of_section_of_ker_sqZero :
letI := g.toRingHom.toAlgebra; IsScalarTower P S (RingHom.ker (algebraMap P S)) := by
letI := g.toRingHom.toAlgebra
constructor
intro p s m
ext
change g (p • s) * m = p * (g s * m)
simp only [Algebra.smul_def, map_mul, mul_assoc, mul_left_comm _ (g s)]
congr 1
rw [← sub_eq_zero, ← Ideal.mem_bot, ← hf', pow_two, ← sub_mul]
refine Ideal.mul_mem_mul ?_ m.2
simpa [RingHom.mem_ker, sub_eq_zero] using AlgHom.congr_fun hg (algebraMap P S p)
/--
Given a surjective algebra hom `f : P →ₐ[R] S` with square-zero kernel `I`,
and a section `g : S →ₐ[R] P` (as algebra homs),
we get a retraction of the injection `I → S ⊗[P] Ω[P/R]`.
-/
noncomputable
def retractionOfSectionOfKerSqZero : S ⊗[P] Ω[P⁄R] →ₗ[P] RingHom.ker (algebraMap P S) :=
letI := g.toRingHom.toAlgebra
haveI := isScalarTower_of_section_of_ker_sqZero g hf' hg
letI f : _ →ₗ[P] RingHom.ker (algebraMap P S) := (derivationOfSectionOfKerSqZero
(IsScalarTower.toAlgHom R P S) hf' g hg).liftKaehlerDifferential
(f.liftBaseChange S).restrictScalars P
@[simp]
lemma retractionOfSectionOfKerSqZero_tmul_D (s : S) (t : P) :
retractionOfSectionOfKerSqZero g hf' hg (s ⊗ₜ .D _ _ t) =
g s * t - g s * g (algebraMap _ _ t) := by
letI := g.toRingHom.toAlgebra
haveI := isScalarTower_of_section_of_ker_sqZero g hf' hg
simp only [retractionOfSectionOfKerSqZero, AlgHom.toRingHom_eq_coe, LinearMap.coe_restrictScalars,
LinearMap.liftBaseChange_tmul, SetLike.val_smul_of_tower]
-- The issue is a mismatch between `RingHom.ker (algebraMap P S)` and
-- `RingHom.ker (IsScalarTower.toAlgHom R P S)`, but `rw` and `simp` can't rewrite it away...
erw [Derivation.liftKaehlerDifferential_comp_D]
exact mul_sub (g s) t (g (algebraMap P S t))
lemma retractionOfSectionOfKerSqZero_comp_kerToTensor :
(retractionOfSectionOfKerSqZero g hf' hg).comp (kerToTensor R P S) = LinearMap.id := by
ext x; simp [RingHom.mem_ker.mp x.2]
end ofSection
section ofRetraction
variable (l : S ⊗[P] Ω[P⁄R] →ₗ[P] RingHom.ker (algebraMap P S))
variable (hl : l.comp (kerToTensor R P S) = LinearMap.id)
include hl
-- suppose we have a (set-theoretic) section
variable (σ : S → P) (hσ : ∀ x, algebraMap P S (σ x) = x)
lemma sectionOfRetractionKerToTensorAux_prop (x y) (h : algebraMap P S x = algebraMap P S y) :
x - l (1 ⊗ₜ .D _ _ x) = y - l (1 ⊗ₜ .D _ _ y) := by
rw [sub_eq_iff_eq_add, sub_add_comm, ← sub_eq_iff_eq_add, ← Submodule.coe_sub,
← map_sub, ← tmul_sub, ← map_sub]
exact congr_arg Subtype.val (LinearMap.congr_fun hl.symm ⟨x - y, by simp [RingHom.mem_ker, h]⟩)
variable [Algebra R S] [IsScalarTower R P S]
variable (hf' : (RingHom.ker (algebraMap P S)) ^ 2 = ⊥)
include hf'
/--
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with square-zero kernel `I`.
Let `σ` be an arbitrary (set-theoretic) section of `f`.
Suppose we have a retraction `l` of the injection `I →ₗ[P] S ⊗[P] Ω[P/R]`, then
`x ↦ σ x - l (1 ⊗ D (σ x))` is an algebra homomorphism and a section to `f`.
-/
noncomputable
def sectionOfRetractionKerToTensorAux : S →ₐ[R] P where
toFun x := σ x - l (1 ⊗ₜ .D _ _ (σ x))
map_one' := by simp [sectionOfRetractionKerToTensorAux_prop l hl (σ 1) 1 (by simp [hσ])]
map_mul' a b := by
have (x y : _) : (l x).1 * (l y).1 = 0 := by
rw [← Ideal.mem_bot, ← hf', pow_two]; exact Ideal.mul_mem_mul (l x).2 (l y).2
simp only [sectionOfRetractionKerToTensorAux_prop l hl (σ (a * b)) (σ a * σ b) (by simp [hσ]),
Derivation.leibniz, tmul_add, tmul_smul, map_add, map_smul, Submodule.coe_add,
SetLike.val_smul, smul_eq_mul, mul_sub, sub_mul, this, sub_zero]
ring
map_add' a b := by
simp only [sectionOfRetractionKerToTensorAux_prop l hl (σ (a + b)) (σ a + σ b) (by simp [hσ]),
map_add, tmul_add, Submodule.coe_add, add_sub_add_comm]
map_zero' := by simp [sectionOfRetractionKerToTensorAux_prop l hl (σ 0) 0 (by simp [hσ])]
commutes' r := by
simp [sectionOfRetractionKerToTensorAux_prop l hl
(σ (algebraMap R S r)) (algebraMap R P r) (by simp [hσ, ← IsScalarTower.algebraMap_apply])]
lemma sectionOfRetractionKerToTensorAux_algebraMap (x : P) :
sectionOfRetractionKerToTensorAux l hl σ hσ hf' (algebraMap P S x) = x - l (1 ⊗ₜ .D _ _ x) :=
sectionOfRetractionKerToTensorAux_prop l hl _ x (by simp [hσ])
variable (hf : Surjective (algebraMap P S))
include hf
lemma toAlgHom_comp_sectionOfRetractionKerToTensorAux :
(IsScalarTower.toAlgHom R P S).comp
(sectionOfRetractionKerToTensorAux l hl σ hσ hf') = AlgHom.id _ _ := by
ext x
obtain ⟨x, rfl⟩ := hf x
simp [sectionOfRetractionKerToTensorAux_algebraMap, RingHom.mem_ker.mp]
/--
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with square-zero kernel `I`.
Suppose we have a retraction `l` of the injection `I →ₗ[P] S ⊗[P] Ω[P/R]`, then
`x ↦ σ x - l (1 ⊗ D (σ x))` is an algebra homomorphism and a section to `f`,
where `σ` is an arbitrary (set-theoretic) section of `f`
-/
noncomputable def sectionOfRetractionKerToTensor : S →ₐ[R] P :=
sectionOfRetractionKerToTensorAux l hl _ (fun x ↦ (hf x).choose_spec) hf'
@[simp]
lemma sectionOfRetractionKerToTensor_algebraMap (x : P) :
sectionOfRetractionKerToTensor l hl hf' hf (algebraMap P S x) = x - l (1 ⊗ₜ .D _ _ x) :=
sectionOfRetractionKerToTensorAux_algebraMap l hl _ _ hf' x
@[simp]
lemma toAlgHom_comp_sectionOfRetractionKerToTensor :
(IsScalarTower.toAlgHom R P S).comp
(sectionOfRetractionKerToTensor l hl hf' hf) = AlgHom.id _ _ :=
toAlgHom_comp_sectionOfRetractionKerToTensorAux (hf := hf) ..
end ofRetraction
variable [Algebra R S] [IsScalarTower R P S]
variable (hf' : (RingHom.ker (algebraMap P S)) ^ 2 = ⊥) (hf : Surjective (algebraMap P S))
/--
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with square-zero kernel `I`,
there is a one-to-one correspondence between `P`-linear retractions of `I →ₗ[P] S ⊗[P] Ω[P/R]`
and algebra homomorphism sections of `f`.
-/
noncomputable
def retractionKerToTensorEquivSection :
{ l // l ∘ₗ (kerToTensor R P S) = LinearMap.id } ≃
{ g // (IsScalarTower.toAlgHom R P S).comp g = AlgHom.id R S } where
toFun l := ⟨_, toAlgHom_comp_sectionOfRetractionKerToTensor _ l.2 hf' hf⟩
invFun g := ⟨_, retractionOfSectionOfKerSqZero_comp_kerToTensor _ hf' g.2⟩
left_inv l := by
ext s p
obtain ⟨s, rfl⟩ := hf s
have (x y : _) : (l.1 x).1 * (l.1 y).1 = 0 := by
rw [← Ideal.mem_bot, ← hf', pow_two]; exact Ideal.mul_mem_mul (l.1 x).2 (l.1 y).2
simp only [AlgebraTensorModule.curry_apply,
Derivation.coe_comp, LinearMap.coe_comp, LinearMap.coe_restrictScalars, Derivation.coeFn_coe,
Function.comp_apply, curry_apply, retractionOfSectionOfKerSqZero_tmul_D,
sectionOfRetractionKerToTensor_algebraMap, ← mul_sub, sub_sub_cancel]
rw [sub_mul]
simp only [this, Algebra.algebraMap_eq_smul_one, ← smul_tmul', LinearMapClass.map_smul,
SetLike.val_smul, smul_eq_mul, sub_zero]
right_inv g := by ext s; obtain ⟨s, rfl⟩ := hf s; simp
variable (R P S) in
/--
Given a tower of algebras `S/P/R`, with `I = ker(P → S)`,
this is the `R`-derivative `P/I² → S ⊗[P] Ω[P⁄R]` given by `[x] ↦ 1 ⊗ D x`.
-/
noncomputable
def derivationQuotKerSq :
Derivation R (P ⧸ (RingHom.ker (algebraMap P S) ^ 2)) (S ⊗[P] Ω[P⁄R]) := by
letI := Submodule.liftQ ((RingHom.ker (algebraMap P S) ^ 2).restrictScalars R)
(((mk P S _ 1).restrictScalars R).comp (KaehlerDifferential.D R P).toLinearMap)
refine ⟨this ?_, ?_, ?_⟩
· rintro x hx
simp only [Submodule.restrictScalars_mem, pow_two] at hx
simp only [LinearMap.mem_ker, LinearMap.coe_comp, LinearMap.coe_restrictScalars,
Derivation.coeFn_coe, Function.comp_apply, mk_apply]
refine Submodule.smul_induction_on hx ?_ ?_
· intro x hx y hy
simp only [smul_eq_mul, Derivation.leibniz, tmul_add, ← smul_tmul, Algebra.smul_def,
mul_one, RingHom.mem_ker.mp hx, RingHom.mem_ker.mp hy, zero_tmul, zero_add]
· intro x y hx hy; simp only [map_add, hx, hy, tmul_add, zero_add]
· change (1 : S) ⊗ₜ[P] KaehlerDifferential.D R P 1 = 0; simp
· intro a b
obtain ⟨a, rfl⟩ := Submodule.Quotient.mk_surjective _ a
obtain ⟨b, rfl⟩ := Submodule.Quotient.mk_surjective _ b
change (1 : S) ⊗ₜ[P] KaehlerDifferential.D R P (a * b) =
Ideal.Quotient.mk _ a • ((1 : S) ⊗ₜ[P] KaehlerDifferential.D R P b) +
Ideal.Quotient.mk _ b • ((1 : S) ⊗ₜ[P] KaehlerDifferential.D R P a)
simp only [← Ideal.Quotient.algebraMap_eq, IsScalarTower.algebraMap_smul,
Derivation.leibniz, tmul_add, tmul_smul]
@[simp]
lemma derivationQuotKerSq_mk (x : P) :
derivationQuotKerSq R P S x = 1 ⊗ₜ .D R P x := rfl
variable (R P S) in
/--
Given a tower of algebras `S/P/R`, with `I = ker(P → S)` and `Q := P/I²`,
there is an isomorphism of `S`-modules `S ⊗[Q] Ω[Q/R] ≃ S ⊗[P] Ω[P/R]`.
-/
noncomputable
def tensorKaehlerQuotKerSqEquiv :
S ⊗[P ⧸ (RingHom.ker (algebraMap P S) ^ 2)] Ω[(P ⧸ (RingHom.ker (algebraMap P S) ^ 2))⁄R] ≃ₗ[S]
S ⊗[P] Ω[P⁄R] :=
letI f₁ := (derivationQuotKerSq R P S).liftKaehlerDifferential
letI f₂ := AlgebraTensorModule.lift ((LinearMap.ringLmapEquivSelf S S _).symm f₁)
letI f₃ := KaehlerDifferential.map R R P (P ⧸ (RingHom.ker (algebraMap P S) ^ 2))
letI f₄ := ((mk (P ⧸ RingHom.ker (algebraMap P S) ^ 2) S _ 1).restrictScalars P).comp f₃
letI f₅ := AlgebraTensorModule.lift ((LinearMap.ringLmapEquivSelf S S _).symm f₄)
{ __ := f₂
invFun := f₅
left_inv := by
suffices f₅.comp f₂ = LinearMap.id from LinearMap.congr_fun this
ext a
obtain ⟨a, rfl⟩ := Ideal.Quotient.mk_surjective a
simp [f₁, f₂, f₃, f₄, f₅]
right_inv := by
suffices f₂.comp f₅ = LinearMap.id from LinearMap.congr_fun this
ext a
simp [f₁, f₂, f₃, f₄, f₅] }
@[simp]
lemma tensorKaehlerQuotKerSqEquiv_tmul_D (s t) :
tensorKaehlerQuotKerSqEquiv R P S (s ⊗ₜ .D _ _ (Ideal.Quotient.mk _ t)) = s ⊗ₜ .D _ _ t := by
change s • (derivationQuotKerSq R P S).liftKaehlerDifferential
(.D _ _ (Ideal.Quotient.mk _ t)) = _
simp [smul_tmul']
@[simp]
lemma tensorKaehlerQuotKerSqEquiv_symm_tmul_D (s t) :
(tensorKaehlerQuotKerSqEquiv R P S).symm (s ⊗ₜ .D _ _ t) =
s ⊗ₜ .D _ _ (Ideal.Quotient.mk _ t) := by
apply (tensorKaehlerQuotKerSqEquiv R P S).injective
simp
/--
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with kernel `I`,
there is a one-to-one correspondence between `P`-linear retractions of `I/I² →ₗ[P] S ⊗[P] Ω[P/R]`
and algebra homomorphism sections of `f‾ : P/I² → S`.
-/
noncomputable
def retractionKerCotangentToTensorEquivSection :
{ l // l ∘ₗ (kerCotangentToTensor R P S) = LinearMap.id } ≃
{ g // (IsScalarTower.toAlgHom R P S).kerSquareLift.comp g = AlgHom.id R S } := by
let P' := P ⧸ (RingHom.ker (algebraMap P S) ^ 2)
have h₁ : Surjective (algebraMap P' S) := Function.Surjective.of_comp (g := algebraMap P P') hf
have h₂ : RingHom.ker (algebraMap P' S) ^ 2 = ⊥ := by
rw [RingHom.algebraMap_toAlgebra, AlgHom.ker_kerSquareLift, Ideal.cotangentIdeal_square]
let e₁ : (RingHom.ker (algebraMap P S)).Cotangent ≃ₗ[P] (RingHom.ker (algebraMap P' S)) :=
(Ideal.cotangentEquivIdeal _).trans ((LinearEquiv.ofEq _ _
(IsScalarTower.toAlgHom R P S).ker_kerSquareLift.symm).restrictScalars P)
let e₂ : S ⊗[P'] Ω[P'⁄R] ≃ₗ[P] S ⊗[P] Ω[P⁄R] :=
(tensorKaehlerQuotKerSqEquiv R P S).restrictScalars P
have H : kerCotangentToTensor R P S =
e₂.toLinearMap ∘ₗ (kerToTensor R P' S ).restrictScalars P ∘ₗ e₁.toLinearMap := by
ext x
obtain ⟨x, rfl⟩ := Ideal.toCotangent_surjective _ x
exact (tensorKaehlerQuotKerSqEquiv_tmul_D 1 x.1).symm
refine Equiv.trans ?_ (retractionKerToTensorEquivSection (R := R) h₂ h₁)
refine ⟨fun ⟨l, hl⟩ ↦ ⟨⟨e₁.toLinearMap ∘ₗ l ∘ₗ e₂.toLinearMap, ?_⟩, ?_⟩,
fun ⟨l, hl⟩ ↦ ⟨e₁.symm.toLinearMap ∘ₗ l.restrictScalars P ∘ₗ e₂.symm.toLinearMap, ?_⟩, ?_, ?_⟩
· rintro x y
obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x
simp only [P', ← Ideal.Quotient.algebraMap_eq, IsScalarTower.algebraMap_smul]
exact (e₁.toLinearMap ∘ₗ l ∘ₗ e₂.toLinearMap).map_smul x y
· ext1 x
rw [H] at hl
obtain ⟨x, rfl⟩ := e₁.surjective x
exact DFunLike.congr_arg e₁ (LinearMap.congr_fun hl x)
· ext x
rw [H]
apply e₁.injective
simp only [LinearMap.coe_comp, LinearEquiv.coe_coe, LinearMap.coe_restrictScalars,
Function.comp_apply, LinearEquiv.symm_apply_apply, LinearMap.id_coe, id_eq,
LinearEquiv.apply_symm_apply]
exact LinearMap.congr_fun hl (e₁ x)
· intro f
ext x
simp only [AlgebraTensorModule.curry_apply, Derivation.coe_comp, LinearMap.coe_comp,
LinearMap.coe_restrictScalars, Derivation.coeFn_coe, Function.comp_apply, curry_apply,
LinearEquiv.coe_coe, LinearMap.coe_mk, AddHom.coe_coe,
LinearEquiv.apply_symm_apply, LinearEquiv.symm_apply_apply]
· intro f
ext x
simp only [AlgebraTensorModule.curry_apply, Derivation.coe_comp, LinearMap.coe_comp,
LinearMap.coe_restrictScalars, Derivation.coeFn_coe, Function.comp_apply, curry_apply,
LinearMap.coe_mk, AddHom.coe_coe, LinearEquiv.coe_coe,
LinearEquiv.symm_apply_apply, LinearEquiv.apply_symm_apply]
namespace Algebra.Extension
lemma CotangentSpace.map_toInfinitesimal_bijective (P : Extension.{u} R S) :
Function.Bijective (CotangentSpace.map P.toInfinitesimal) := by
suffices CotangentSpace.map P.toInfinitesimal =
(tensorKaehlerQuotKerSqEquiv _ _ _).symm.toLinearMap by
rw [this]; exact(tensorKaehlerQuotKerSqEquiv _ _ _).symm.bijective
letI : Algebra P.Ring P.infinitesimal.Ring := inferInstanceAs (Algebra P.Ring (P.Ring ⧸ _))
have : IsScalarTower P.Ring P.infinitesimal.Ring S := .of_algebraMap_eq' rfl
apply LinearMap.restrictScalars_injective P.Ring
ext x a
dsimp
simp only [map_tmul, algebraMap_self, RingHom.id_apply, Hom.toAlgHom_apply]
exact (tensorKaehlerQuotKerSqEquiv_symm_tmul_D _ _).symm
lemma Cotangent.map_toInfinitesimal_bijective (P : Extension.{u} R S) :
Function.Bijective (Cotangent.map P.toInfinitesimal) := by
constructor
· rw [injective_iff_map_eq_zero]
intro x hx
obtain ⟨x, rfl⟩ := Cotangent.mk_surjective x
have hx : x.1 ∈ P.ker ^ 2 := by
apply_fun Cotangent.val at hx
simp only [map_mk, Hom.toAlgHom_apply, val_mk, val_zero, Ideal.toCotangent_eq_zero,
Extension.ker_infinitesimal] at hx
rw [Ideal.cotangentIdeal_square] at hx
simpa only [toInfinitesimal, Ideal.mem_bot, infinitesimal,
Ideal.Quotient.eq_zero_iff_mem] using hx
ext
simpa [Ideal.toCotangent_eq_zero]
· intro x
obtain ⟨⟨x, hx⟩, rfl⟩ := Cotangent.mk_surjective x
obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x
rw [ker_infinitesimal, Ideal.mk_mem_cotangentIdeal] at hx
exact ⟨.mk ⟨x, hx⟩, rfl⟩
lemma H1Cotangent.map_toInfinitesimal_bijective (P : Extension.{u} R S) :
Function.Bijective (H1Cotangent.map P.toInfinitesimal) := by
constructor
· intro x y e
ext1
exact (Cotangent.map_toInfinitesimal_bijective P).1 (congr_arg Subtype.val e)
· intro ⟨x, hx⟩
obtain ⟨x, rfl⟩ := (Cotangent.map_toInfinitesimal_bijective P).2 x
refine ⟨⟨x, ?_⟩, rfl⟩
simpa [← CotangentSpace.map_cotangentComplex,
map_eq_zero_iff _ (CotangentSpace.map_toInfinitesimal_bijective P).injective] using hx
end Algebra.Extension |
.lake/packages/mathlib/Mathlib/RingTheory/Smooth/Pi.lean | import Mathlib.RingTheory.Idempotents
import Mathlib.RingTheory.Smooth.Basic
/-!
# Formal-smoothness of finite products of rings
## Main result
- `Algebra.FormallySmooth.pi_iff`: If `I` is finite, `Π i : I, A i` is `R`-formally-smooth
if and only if each `A i` is `R`-formally-smooth.
-/
namespace Algebra.FormallySmooth
variable {R : Type*} {I : Type*} (A : I → Type*)
variable [CommRing R] [∀ i, CommRing (A i)] [∀ i, Algebra R (A i)]
theorem of_pi [FormallySmooth R (Π i, A i)] (i) :
FormallySmooth R (A i) := by
classical
fapply FormallySmooth.of_split (Pi.evalAlgHom R A i)
· apply AlgHom.ofLinearMap
((Ideal.Quotient.mkₐ R _).toLinearMap.comp (LinearMap.single _ _ i))
· change Ideal.Quotient.mk _ (Pi.single i 1) = 1
rw [← (Ideal.Quotient.mk _).map_one, ← sub_eq_zero, ← map_sub,
Ideal.Quotient.eq_zero_iff_mem]
have : Pi.single i 1 - 1 ∈ RingHom.ker (Pi.evalAlgHom R A i).toRingHom := by
simp [RingHom.mem_ker]
convert neg_mem (Ideal.pow_mem_pow this 2) using 1
simp [pow_two, sub_mul, mul_sub, ← Pi.single_mul]
· intro x y
change Ideal.Quotient.mk _ _ = Ideal.Quotient.mk _ _ * Ideal.Quotient.mk _ _
simp only [AlgHom.toRingHom_eq_coe, LinearMap.coe_single, Pi.single_mul, map_mul]
· ext x
change (Pi.single i x) i = x
simp
theorem pi_iff [Finite I] :
FormallySmooth R (Π i, A i) ↔ ∀ i, FormallySmooth R (A i) := by
classical
cases nonempty_fintype I
constructor
· exact fun _ ↦ of_pi A
· refine fun H ↦ .of_comp_surjective fun B _ _ J hJ g ↦ ?_
have hJ' (x) (hx : x ∈ RingHom.ker (Ideal.Quotient.mk J)) : IsNilpotent x := by
refine ⟨2, show x ^ 2 ∈ (⊥ : Ideal B) from ?_⟩
rw [← hJ]
exact Ideal.pow_mem_pow (by simpa using hx) 2
obtain ⟨e, he, he'⟩ := ((CompleteOrthogonalIdempotents.single A).map
g.toRingHom).lift_of_isNilpotent_ker (Ideal.Quotient.mk J) hJ'
fun _ ↦ Ideal.Quotient.mk_surjective _
replace he' : ∀ i, Ideal.Quotient.mk J (e i) = g (Pi.single i 1) := congr_fun he'
let iso : B ≃ₐ[R] ∀ i, B ⧸ Ideal.span {1 - e i} :=
{ __ := Pi.algHom _ _ fun i ↦ Ideal.Quotient.mkₐ R _
__ := Equiv.ofBijective _ he.bijective_pi }
let J' := fun i ↦ J.map (Ideal.Quotient.mk (Ideal.span {1 - e i}))
let ι : ∀ i, (B ⧸ J →ₐ[R] (B ⧸ _) ⧸ J' i) := fun i ↦ Ideal.quotientMapₐ _
(IsScalarTower.toAlgHom R B _) Ideal.le_comap_map
have hι : ∀ i x, ι i x = 0 → (e i) * x = 0 := by
intro i x hix
have : x ∈ (Ideal.span {1 - e i}).map (Ideal.Quotient.mk J) := by
rw [← Ideal.ker_quotientMap_mk]; exact hix
rw [Ideal.map_span, Set.image_singleton, Ideal.mem_span_singleton] at this
obtain ⟨c, rfl⟩ := this
rw [← mul_assoc, ← map_mul, mul_sub, mul_one, (he.idem i).eq, sub_self, map_zero, zero_mul]
have : ∀ i : I, ∃ a : A i →ₐ[R] B ⧸ Ideal.span {1 - e i}, ∀ x,
Ideal.Quotient.mk (J' i) (a x) = ι i (g (Pi.single i x)) := by
intro i
let g' : A i →ₐ[R] (B ⧸ _) ⧸ (J' i) := by
apply AlgHom.ofLinearMap (((ι i).comp g).toLinearMap ∘ₗ LinearMap.single _ _ i)
· suffices Ideal.Quotient.mk (Ideal.span {1 - e i}) (e i) = 1 by simp [ι, ← he', this]
rw [← (Ideal.Quotient.mk _).map_one, eq_comm, Ideal.Quotient.mk_eq_mk_iff_sub_mem,
Ideal.mem_span_singleton]
· intro x y; simp [Pi.single_mul]
obtain ⟨a, ha⟩ := FormallySmooth.comp_surjective _ _ (I := J' i)
(by rw [← Ideal.map_pow, hJ, Ideal.map_bot]) g'
exact ⟨a, AlgHom.congr_fun ha⟩
choose a ha using this
use iso.symm.toAlgHom.comp (Pi.algHom _ _ fun i ↦ (a i).comp (Pi.evalAlgHom R A i))
ext x; rw [← AlgHom.toLinearMap_apply, ← AlgHom.toLinearMap_apply]; congr 1
ext i x
simp only [AlgEquiv.toAlgHom_eq_coe, AlgHom.comp_toLinearMap, AlgEquiv.toAlgHom_toLinearMap,
LinearMap.coe_comp, LinearMap.coe_single, Function.comp_apply, AlgHom.toLinearMap_apply,
AlgEquiv.toLinearMap_apply, Ideal.Quotient.mkₐ_eq_mk]
obtain ⟨y, hy⟩ := Ideal.Quotient.mk_surjective (a i x)
have hy' : Ideal.Quotient.mk (Ideal.span {1 - e i}) (y * e i) = a i x := by
have : Ideal.Quotient.mk (Ideal.span {1 - e i}) (e i) = 1 := by
rw [← (Ideal.Quotient.mk _).map_one, eq_comm, Ideal.Quotient.mk_eq_mk_iff_sub_mem,
Ideal.mem_span_singleton]
rw [map_mul, this, hy, mul_one]
trans Ideal.Quotient.mk J (y * e i)
· congr 1; apply iso.injective; ext j
suffices a j (Pi.single i x j) = Ideal.Quotient.mk _ (y * e i) by simpa using this
by_cases hij : i = j
· subst hij
rw [Pi.single_eq_same, hy']
· have : Ideal.Quotient.mk (Ideal.span {1 - e j}) (e i) = 0 := by
rw [Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton]
refine ⟨e i, by simp [he.ortho (Ne.symm hij), sub_mul]⟩
rw [Pi.single_eq_of_ne (Ne.symm hij), map_zero, map_mul, this, mul_zero]
· have : ι i (Ideal.Quotient.mk J (y * e i)) = ι i (g (Pi.single i x)) := by
rw [← ha, ← hy']
simp only [Ideal.quotient_map_mkₐ, IsScalarTower.coe_toAlgHom',
Ideal.Quotient.algebraMap_eq, Ideal.Quotient.mkₐ_eq_mk, ι]
rw [← sub_eq_zero, ← map_sub] at this
replace this := hι _ _ this
rwa [mul_sub, ← map_mul, mul_comm, mul_assoc, (he.idem i).eq, he', ← map_mul, ← Pi.single_mul,
one_mul, sub_eq_zero] at this
instance [Finite I] [∀ i, FormallySmooth R (A i)] : FormallySmooth R (Π i, A i) :=
(pi_iff _).mpr ‹_›
end Algebra.FormallySmooth |
.lake/packages/mathlib/Mathlib/RingTheory/Smooth/Basic.lean | import Mathlib.RingTheory.FiniteStability
import Mathlib.RingTheory.Ideal.Quotient.Nilpotent
import Mathlib.RingTheory.Localization.Away.AdjoinRoot
import Mathlib.RingTheory.Smooth.Kaehler
/-!
# Smooth morphisms
An `R`-algebra `A` is formally smooth if `Ω[A⁄R]` is `A`-projective and `H¹(L_{A/R}) = 0`.
This is equivalent to the standard definition that "for every `R`-algebra `B`,
every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists
at least one lift `A →ₐ[R] B`".
An `R`-algebra `A` is smooth if it is formally smooth and of finite presentation.
We show that the property of being formally smooth extends onto nilpotent ideals,
and that it is stable under `R`-algebra homomorphisms and compositions.
We show that smooth is stable under algebra isomorphisms, composition and
localization at an element.
## Main results
- `Algebra.FormallySmooth`: The class of formally smooth algebras.
- `Algebra.formallySmooth_iff` :
Formally smooth iff `Ω[A⁄R]` is `A`-projective and `H¹(L_{A/R}) = 0`.
- `Algebra.FormallySmooth.lift`: If `A` is formally smooth and `I` is nilpotent,
any map `A →ₐ[R] B ⧸ I` lifts to `A →ₐ[R] B`.
- `Algebra.FormallySmooth.iff_comp_surjective`: `A` is formally smooth iff
any map `A →ₐ[R] B ⧸ I` lifts to `A →ₐ[R] B` for any square zero `I`.
Suppose `P` is a formally smooth `R` algebra that surjects onto `A` with kernel `I`, then
- `Algebra.FormallySmooth.iff_split_surjection`: `A` is formally smooth iff
the algebra map `P ⧸ I² →ₐ[R] A` has an `R`-algebra section.
- `Algebra.Extension.equivH1CotangentOfFormallySmooth`:
`H¹(L_{A/R})` is isomorphic to `ker(I/I² → A ⊗[P] Ω[P⁄R])`.
- `Algebra.FormallySmooth.iff_split_injection`: `A` is formally smooth iff
the `P`-linear map `I/I² → A ⊗[P] Ω[P⁄R]` is split injective.
-/
open scoped TensorProduct
open Algebra.Extension KaehlerDifferential MvPolynomial
universe u v w
variable {R : Type u} {A : Type v} [CommRing R] [CommRing A] [Algebra R A]
variable {B P C : Type*} [CommRing B] [Algebra R B] [CommRing C] [Algebra R C]
[CommRing P] [Algebra R P]
namespace Algebra
section
variable (R A) in
/--
An `R`-algebra `A` is formally smooth if `Ω[A⁄R]` is `A`-projective and `H¹(L_{A/R}) = 0`.
For the infinitesimal lifting definition,
see `FormallySmooth.lift` and `FormallySmooth.iff_comp_surjective`.
-/
@[stacks 00TI "Also see 031J (6) for the the equivalence with the definition given here.", mk_iff]
class FormallySmooth : Prop where
projective_kaehlerDifferential : Module.Projective A Ω[A⁄R]
subsingleton_h1Cotangent : Subsingleton (H1Cotangent R A)
attribute [instance] FormallySmooth.projective_kaehlerDifferential
FormallySmooth.subsingleton_h1Cotangent
@[deprecated (since := "2025-10-25")]
alias FormallySmooth.iff_subsingleton_and_projective := Algebra.formallySmooth_iff
variable (R A) in
lemma FormallySmooth.comp_surjective [FormallySmooth R A] (I : Ideal B) (hI : I ^ 2 = ⊥) :
Function.Surjective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I) := by
intro f
let P : Algebra.Generators R A A := Generators.self R A
have hP : Function.Injective P.toExtension.cotangentComplex := by
rw [← LinearMap.ker_eq_bot, ← Submodule.subsingleton_iff_eq_bot]
exact FormallySmooth.subsingleton_h1Cotangent
obtain ⟨l, hl⟩ := ((P.toExtension.exact_cotangentComplex_toKaehler.split_tfae'.out 0 1 rfl rfl).mp
⟨P.toExtension.subsingleton_h1Cotangent.mp FormallySmooth.subsingleton_h1Cotangent,
Module.projective_lifting_property _ _ P.toExtension.toKaehler_surjective⟩).2
obtain ⟨g, hg⟩ := retractionKerCotangentToTensorEquivSection (R := R) P.algebraMap_surjective
⟨⟨⟨Cotangent.val, by simp⟩, by simpa using Cotangent.val_smul' (P := P.toExtension)⟩ ∘ₗ
l.restrictScalars P.toExtension.Ring, LinearMap.ext fun x ↦ congr($hl x)⟩
let σ := Function.surjInv (f := algebraMap B (B ⧸ I)) Ideal.Quotient.mk_surjective
have H (x : P.Ring) : ↑(aeval (σ ∘ f) x) = f (algebraMap _ A x) := by
rw [← Ideal.Quotient.algebraMap_eq, ← aeval_algebraMap_apply, P.algebraMap_eq,
AlgHom.coe_toRingHom, comp_aeval_apply, ← Function.comp_assoc, Function.comp_surjInv,]
rfl
let l : P.Ring ⧸ (RingHom.ker (algebraMap P.Ring A)) ^ 2 →ₐ[R] B :=
Ideal.Quotient.liftₐ _ (aeval (σ ∘ f)) <|
have : RingHom.ker (algebraMap P.Ring A) ≤ I.comap (aeval (σ ∘ f)).toRingHom := fun x hx ↦ by
simp_all [← Ideal.Quotient.eq_zero_iff_mem (I := I), -map_aeval]
show RingHom.ker _ ^ 2 ≤ RingHom.ker _ from
(Ideal.pow_right_mono this 2).trans ((Ideal.le_comap_pow _ _).trans_eq (hI ▸ rfl))
have : f.comp (IsScalarTower.toAlgHom R P.Ring A).kerSquareLift =
(Ideal.Quotient.mkₐ R _).comp l := by
refine Ideal.Quotient.algHom_ext _ (MvPolynomial.algHom_ext fun i ↦ ?_)
change f (algebraMap P.Ring A (.X i)) = algebraMap _ _ (MvPolynomial.aeval (σ ∘ f) (.X i))
simpa using (Function.surjInv_eq _ _).symm
exact ⟨l.comp g, by rw [← AlgHom.comp_assoc, ← this, AlgHom.comp_assoc, hg, AlgHom.comp_id]⟩
instance mvPolynomial (σ : Type*) : FormallySmooth R (MvPolynomial σ R) := by
let P : Generators R (MvPolynomial σ R) σ :=
.ofSurjective X (by simp [aeval_X_left, Function.Surjective])
have : Subsingleton ↥P.toExtension.ker :=
Submodule.subsingleton_iff_eq_bot.mpr (by simp [SetLike.ext_iff, map_id])
have : Subsingleton P.toExtension.Cotangent := Cotangent.mk_surjective.subsingleton
have := P.toExtension.h1Cotangentι_injective.subsingleton
exact ⟨inferInstance, P.equivH1Cotangent.symm.subsingleton⟩
end
namespace FormallySmooth
theorem exists_lift
[FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I) (g : A →ₐ[R] B ⧸ I) :
∃ f : A →ₐ[R] B, (Ideal.Quotient.mkₐ R I).comp f = g := by
revert g
change Function.Surjective (Ideal.Quotient.mkₐ R I).comp
revert ‹Algebra R B›
apply Ideal.IsNilpotent.induction_on (S := B) I hI
· intro B _ I hI _; exact FormallySmooth.comp_surjective R A I hI
· intro B _ I J hIJ h₁ h₂ _ g
let this : ((B ⧸ I) ⧸ J.map (Ideal.Quotient.mk I)) ≃ₐ[R] B ⧸ J :=
{
(DoubleQuot.quotQuotEquivQuotSup I J).trans
(Ideal.quotEquivOfEq (sup_eq_right.mpr hIJ)) with
commutes' := fun x => rfl }
obtain ⟨g', e⟩ := h₂ (this.symm.toAlgHom.comp g)
obtain ⟨g', rfl⟩ := h₁ g'
replace e := congr_arg this.toAlgHom.comp e
conv_rhs at e =>
rw [← AlgHom.comp_assoc, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_eq_coe,
AlgEquiv.comp_symm, AlgHom.id_comp]
exact ⟨g', e⟩
/-- For a formally smooth `R`-algebra `A` and a map `f : A →ₐ[R] B ⧸ I` with `I` square-zero,
this is an arbitrary lift `A →ₐ[R] B`. -/
noncomputable def lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I)
(g : A →ₐ[R] B ⧸ I) : A →ₐ[R] B :=
(FormallySmooth.exists_lift I hI g).choose
@[simp]
theorem comp_lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I)
(g : A →ₐ[R] B ⧸ I) : (Ideal.Quotient.mkₐ R I).comp (FormallySmooth.lift I hI g) = g :=
(FormallySmooth.exists_lift I hI g).choose_spec
@[simp]
theorem mk_lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I)
(g : A →ₐ[R] B ⧸ I) (x : A) : Ideal.Quotient.mk I (FormallySmooth.lift I hI g x) = g x :=
AlgHom.congr_fun (FormallySmooth.comp_lift I hI g :) x
variable {C : Type*} [CommRing C] [Algebra R C]
/-- For a formally smooth `R`-algebra `A` and a map `f : A →ₐ[R] B ⧸ I` with `I` nilpotent,
this is an arbitrary lift `A →ₐ[R] B`. -/
noncomputable def liftOfSurjective [FormallySmooth R A] (f : A →ₐ[R] C)
(g : B →ₐ[R] C) (hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker (g : B →+* C)) :
A →ₐ[R] B :=
FormallySmooth.lift _ hg' ((Ideal.quotientKerAlgEquivOfSurjective hg).symm.toAlgHom.comp f)
@[simp]
theorem liftOfSurjective_apply [FormallySmooth R A] (f : A →ₐ[R] C) (g : B →ₐ[R] C)
(hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker g) (x : A) :
g (FormallySmooth.liftOfSurjective f g hg hg' x) = f x := by
apply (Ideal.quotientKerAlgEquivOfSurjective hg).symm.injective
conv_rhs => rw [← AlgHom.coe_coe, ← AlgHom.comp_apply, ← FormallySmooth.mk_lift (A := A) _ hg']
apply (Ideal.quotientKerAlgEquivOfSurjective hg).injective
rw [AlgEquiv.apply_symm_apply, Ideal.quotientKerAlgEquivOfSurjective_apply]
simp only [liftOfSurjective, ← RingHom.ker_coe_toRingHom g, RingHom.kerLift_mk,
AlgEquiv.toAlgHom_eq_coe, RingHom.coe_coe]
@[simp]
theorem comp_liftOfSurjective [FormallySmooth R A] (f : A →ₐ[R] C) (g : B →ₐ[R] C)
(hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker (g : B →+* C)) :
g.comp (FormallySmooth.liftOfSurjective f g hg hg') = f :=
AlgHom.ext (FormallySmooth.liftOfSurjective_apply f g hg hg')
end FormallySmooth
namespace Extension
/--
Given extensions `0 → I₁ → P₁ → A → 0` and `0 → I₂ → P₂ → A → 0` with `P₁` formally smooth,
this is an arbitrarily chosen map `P₁/I₁² → P₂/I₂²` of extensions.
-/
noncomputable
def homInfinitesimal (P₁ P₂ : Extension R A) [FormallySmooth R P₁.Ring] :
P₁.infinitesimal.Hom P₂.infinitesimal :=
letI lift : P₁.Ring →ₐ[R] P₂.infinitesimal.Ring := FormallySmooth.liftOfSurjective
(IsScalarTower.toAlgHom R P₁.Ring A)
(IsScalarTower.toAlgHom R P₂.infinitesimal.Ring A)
P₂.infinitesimal.algebraMap_surjective
⟨2, show P₂.infinitesimal.ker ^ 2 = ⊥ by
rw [ker_infinitesimal]; exact Ideal.cotangentIdeal_square _⟩
{ toRingHom := (Ideal.Quotient.liftₐ (P₁.ker ^ 2) lift (by
change P₁.ker ^ 2 ≤ RingHom.ker lift
rw [pow_two, Ideal.mul_le]
have : ∀ r ∈ P₁.ker, lift r ∈ P₂.infinitesimal.ker :=
fun r hr ↦ (FormallySmooth.liftOfSurjective_apply _
(IsScalarTower.toAlgHom R P₂.infinitesimal.Ring A) _ _ r).trans hr
intro r hr s hs
rw [RingHom.mem_ker, map_mul, ← Ideal.mem_bot, ← P₂.ker.cotangentIdeal_square,
← ker_infinitesimal, pow_two]
exact Ideal.mul_mem_mul (this r hr) (this s hs))).toRingHom
toRingHom_algebraMap := by simp
algebraMap_toRingHom x := by
obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x
exact FormallySmooth.liftOfSurjective_apply _
(IsScalarTower.toAlgHom R P₂.infinitesimal.Ring A) _ _ x }
/-- Formally smooth extensions have isomorphic `H¹(L_P)`. -/
noncomputable
def H1Cotangent.equivOfFormallySmooth (P₁ P₂ : Extension R A)
[FormallySmooth R P₁.Ring] [FormallySmooth R P₂.Ring] :
P₁.H1Cotangent ≃ₗ[A] P₂.H1Cotangent :=
.ofBijective _ (H1Cotangent.map_toInfinitesimal_bijective P₁) ≪≫ₗ
H1Cotangent.equiv (Extension.homInfinitesimal _ _) (Extension.homInfinitesimal _ _)
≪≫ₗ .symm (.ofBijective _ (H1Cotangent.map_toInfinitesimal_bijective P₂))
lemma H1Cotangent.equivOfFormallySmooth_toLinearMap {P₁ P₂ : Extension R A} (f : P₁.Hom P₂)
[FormallySmooth R P₁.Ring] [FormallySmooth R P₂.Ring] :
(H1Cotangent.equivOfFormallySmooth P₁ P₂).toLinearMap = map f := by
ext1 x
refine (LinearEquiv.symm_apply_eq _).mpr ?_
change ((map (P₁.homInfinitesimal P₂)).restrictScalars A ∘ₗ map P₁.toInfinitesimal) x =
((map P₂.toInfinitesimal).restrictScalars A ∘ₗ map f) x
rw [← map_comp, ← map_comp, map_eq]
lemma H1Cotangent.equivOfFormallySmooth_apply {P₁ P₂ : Extension R A} (f : P₁.Hom P₂)
[FormallySmooth R P₁.Ring] [FormallySmooth R P₂.Ring] (x) :
H1Cotangent.equivOfFormallySmooth P₁ P₂ x = map f x := by
rw [← equivOfFormallySmooth_toLinearMap]; rfl
lemma H1Cotangent.equivOfFormallySmooth_symm (P₁ P₂ : Extension R A)
[FormallySmooth R P₁.Ring] [FormallySmooth R P₂.Ring] :
(equivOfFormallySmooth P₁ P₂).symm = equivOfFormallySmooth P₂ P₁ := rfl
/-- Any formally smooth extension can be used to calculate `H¹(L_{A/R})`. -/
noncomputable
def equivH1CotangentOfFormallySmooth (P : Extension R A) [FormallySmooth R P.Ring] :
P.H1Cotangent ≃ₗ[A] H1Cotangent R A :=
haveI : FormallySmooth R (Generators.self R A).toExtension.Ring :=
inferInstanceAs (FormallySmooth R (MvPolynomial _ _))
H1Cotangent.equivOfFormallySmooth _ _
lemma cotangentComplex_injective_iff
(P : Extension R A) [FormallySmooth R P.Ring] :
Function.Injective P.cotangentComplex ↔ Subsingleton (Algebra.H1Cotangent R A) := by
rw [← Algebra.Extension.subsingleton_h1Cotangent,
P.equivH1CotangentOfFormallySmooth.subsingleton_congr]
end Algebra.Extension
namespace Algebra.FormallySmooth
section iff_split
variable [Algebra.FormallySmooth R P]
lemma kerCotangentToTensor_injective_iff
[Algebra P A] [IsScalarTower R P A] (hf : Function.Surjective (algebraMap P A)) :
Function.Injective (kerCotangentToTensor R P A) ↔ Subsingleton (Algebra.H1Cotangent R A) :=
let P' : Algebra.Extension R A := ⟨P, _, Function.surjInv_eq hf⟩
have : Algebra.FormallySmooth R P'.Ring := ‹_›
P'.cotangentComplex_injective_iff
/--
Given a formally smooth `R`-algebra `P` and a surjective algebra homomorphism `f : P →ₐ[R] A`
with kernel `I` (typically a presentation `R[X] → A`),
`A` is formally smooth iff the `P`-linear map `I/I² → A ⊗[P] Ω[P⁄R]` is split injective.
Also see `Algebra.Extension.formallySmooth_iff_split_injection`
for the version in terms of `Extension`.
-/
@[stacks 031I]
theorem iff_split_injection
[Algebra P A] [IsScalarTower R P A] (hf : Function.Surjective (algebraMap P A)) :
Algebra.FormallySmooth R A ↔ ∃ l, l ∘ₗ (kerCotangentToTensor R P A) = LinearMap.id := by
rw [formallySmooth_iff, and_comm,
Module.Projective.iff_split_of_projective (KaehlerDifferential.mapBaseChange R P A)
(mapBaseChange_surjective R P A hf), ← kerCotangentToTensor_injective_iff hf]
convert (((exact_kerCotangentToTensor_mapBaseChange R _ _ hf).split_tfae'
(g := (KaehlerDifferential.mapBaseChange R P A).restrictScalars P)).out 0 1) using 2
· rw [← (LinearMap.extendScalarsOfSurjectiveEquiv hf).exists_congr_right]
simp only [LinearMap.ext_iff]; rfl
· rw [and_iff_right (by exact mapBaseChange_surjective R P A hf)]
/--
Given a formally smooth `R`-algebra `P` and a surjective algebra homomorphism `f : P →ₐ[R] S`
with kernel `I` (typically a presentation `R[X] → S`),
`S` is formally smooth iff the `P`-linear map `I/I² → S ⊗[P] Ω[P⁄R]` is split injective.
-/
@[stacks 031I]
theorem _root_.Algebra.Extension.formallySmooth_iff_split_injection
(P : Algebra.Extension.{w} R A) [FormallySmooth R P.Ring] :
Algebra.FormallySmooth R A ↔ ∃ l, l ∘ₗ P.cotangentComplex = LinearMap.id := by
refine (Algebra.FormallySmooth.iff_split_injection P.algebraMap_surjective).trans ?_
let e : P.ker.Cotangent ≃ₗ[P.Ring] P.Cotangent :=
{ __ := AddEquiv.refl _, map_smul' r m := by ext1; simp; rfl }
constructor
· intro ⟨l, hl⟩
exact ⟨(e.comp l).extendScalarsOfSurjective P.algebraMap_surjective,
LinearMap.ext (DFunLike.congr_fun hl : _)⟩
· intro ⟨l, hl⟩
exact ⟨e.symm.toLinearMap ∘ₗ l.restrictScalars P.Ring,
LinearMap.ext (DFunLike.congr_fun hl : _)⟩
/-- Let `P →ₐ[R] A` be a surjection with kernel `J`, and `P` a formally smooth `R`-algebra,
then `A` is formally smooth over `R` iff the surjection `P ⧸ J ^ 2 →ₐ[R] A` has a section.
Geometric intuition: we require that a first-order thickening of `Spec A` inside `Spec P` admits
a retraction. -/
theorem iff_split_surjection (f : P →ₐ[R] A) (hf : Function.Surjective f) :
FormallySmooth R A ↔ ∃ g, f.kerSquareLift.comp g = AlgHom.id R A := by
letI := f.toAlgebra
rw [iff_split_injection hf, ← nonempty_subtype, ← nonempty_subtype,
(retractionKerCotangentToTensorEquivSection hf).nonempty_congr]
rfl
theorem of_split (f : P →ₐ[R] A) (g : A →ₐ[R] P ⧸ RingHom.ker f.toRingHom ^ 2)
(h : f.kerSquareLift.comp g = AlgHom.id R A) :
FormallySmooth R A := by
refine (iff_split_surjection f fun x ↦ ?_).mpr ⟨g, h⟩
obtain ⟨y, hy⟩ := Ideal.Quotient.mk_surjective (g x)
exact ⟨y, congr(f.kerSquareLift $hy).trans congr($h x)⟩
theorem of_comp_surjective
(H : ∀ ⦃B : Type max u v⦄ [CommRing B] [Algebra R B] (I : Ideal B) (_ : I ^ 2 = ⊥),
Function.Surjective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I)) :
FormallySmooth R A := by
let P := Generators.self R A
let f := IsScalarTower.toAlgHom R P.Ring A
rw [iff_split_surjection f P.algebraMap_surjective]
have surj : Function.Surjective f.kerSquareLift :=
Ideal.Quotient.lift_surjective_of_surjective _ _ P.algebraMap_surjective
have sqz : RingHom.ker f.kerSquareLift.toRingHom ^ 2 = ⊥ := by
rw [AlgHom.ker_kerSquareLift, Ideal.cotangentIdeal_square]
dsimp only [AlgHom.toRingHom_eq_coe, RingHom.ker_coe_toRingHom] at sqz
obtain ⟨g, hg⟩ := H _ sqz (Ideal.quotientKerAlgEquivOfSurjective surj).symm.toAlgHom
refine ⟨g, AlgHom.ext fun x ↦ congr(f.kerSquareLift.kerLift ($hg x)).trans ?_⟩
obtain ⟨x, rfl⟩ := (Ideal.quotientKerAlgEquivOfSurjective surj).surjective x
obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x
simp only [AlgHom.toRingHom_eq_coe, AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe,
AlgEquiv.symm_apply_apply, AlgHom.coe_id, id_eq]
simp only [Ideal.quotientKerAlgEquivOfSurjective_apply]
/--
An `R`-algebra `A` is formally smooth iff "for every `R`-algebra `B`,
every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists
at least one lift `A →ₐ[R] B`".
-/
theorem iff_comp_surjective :
FormallySmooth R A ↔ ∀ ⦃B : Type max u v⦄ [CommRing B] [Algebra R B] (I : Ideal B), I ^ 2 = ⊥ →
Function.Surjective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I) :=
⟨fun _ _ ↦ comp_surjective R A, of_comp_surjective⟩
end iff_split
section OfEquiv
variable {R : Type*} [CommRing R]
variable {A B : Type*} [CommRing A] [Algebra R A] [CommRing B] [Algebra R B]
theorem of_equiv [FormallySmooth R A] (e : A ≃ₐ[R] B) : FormallySmooth R B :=
(iff_split_surjection e.toAlgHom e.surjective).mpr
⟨(Ideal.Quotient.mkₐ _ _).comp e.symm, AlgHom.ext e.apply_symm_apply⟩
theorem iff_of_equiv (e : A ≃ₐ[R] B) : FormallySmooth R A ↔ FormallySmooth R B :=
⟨fun _ ↦ of_equiv e, fun _ ↦ of_equiv e.symm⟩
end OfEquiv
section Polynomial
open scoped Polynomial in
instance polynomial (R : Type*) [CommRing R] :
FormallySmooth R R[X] := .of_equiv (MvPolynomial.pUnitAlgEquiv.{_, 0} R)
end Polynomial
section Comp
variable (R : Type*) [CommRing R]
variable (A : Type*) [CommRing A] [Algebra R A]
variable (B : Type*) [CommRing B] [Algebra R B] [Algebra A B] [IsScalarTower R A B]
theorem comp [FormallySmooth R A] [FormallySmooth A B] : FormallySmooth R B := by
refine .of_comp_surjective fun C _ _ I hI f ↦ ?_
obtain ⟨f', e⟩ := FormallySmooth.comp_surjective _ _ I hI (f.comp (IsScalarTower.toAlgHom R A B))
letI := f'.toRingHom.toAlgebra
obtain ⟨f'', e'⟩ := comp_surjective _ _ I hI { f with commutes' := AlgHom.congr_fun e.symm }
apply_fun AlgHom.restrictScalars R at e'
exact ⟨f''.restrictScalars _, e'.trans (AlgHom.ext fun _ => rfl)⟩
end Comp
section BaseChange
open scoped TensorProduct
variable {R : Type*} [CommRing R]
variable {A : Type*} [CommRing A] [Algebra R A]
variable (B : Type*) [CommRing B] [Algebra R B]
instance [FormallySmooth R A] : FormallySmooth B (B ⊗[R] A) := by
refine .of_comp_surjective fun C _ _ I hI f ↦ ?_
letI := ((algebraMap B C).comp (algebraMap R B)).toAlgebra
haveI : IsScalarTower R B C := IsScalarTower.of_algebraMap_eq' rfl
refine ⟨TensorProduct.productLeftAlgHom (Algebra.ofId B C) ?_, ?_⟩
· exact FormallySmooth.lift I ⟨2, hI⟩ ((f.restrictScalars R).comp TensorProduct.includeRight)
· apply AlgHom.restrictScalars_injective R
apply TensorProduct.ext'
intro b a
suffices algebraMap B _ b * f (1 ⊗ₜ[R] a) = f (b ⊗ₜ[R] a) by simpa [Algebra.ofId_apply]
rw [← Algebra.smul_def, ← map_smul, TensorProduct.smul_tmul', smul_eq_mul, mul_one]
end BaseChange
section Localization
variable {R A Rₘ Sₘ : Type*} [CommRing R] [CommRing A] [CommRing Rₘ] [CommRing Sₘ]
variable (M : Submonoid R)
variable [Algebra R A] [Algebra R Sₘ] [Algebra A Sₘ] [Algebra R Rₘ] [Algebra Rₘ Sₘ]
variable [IsScalarTower R Rₘ Sₘ] [IsScalarTower R A Sₘ]
variable [IsLocalization M Rₘ] [IsLocalization (M.map (algebraMap R A)) Sₘ]
include M
theorem of_isLocalization : FormallySmooth R Rₘ := by
refine .of_comp_surjective fun Q _ _ I e f ↦ ?_
have : ∀ x : M, IsUnit (algebraMap R Q x) := by
intro x
apply (IsNilpotent.isUnit_quotient_mk_iff ⟨2, e⟩).mp
convert (IsLocalization.map_units Rₘ x).map f
simp only [Ideal.Quotient.mk_algebraMap, AlgHom.commutes]
let this : Rₘ →ₐ[R] Q :=
{ IsLocalization.lift this with commutes' := IsLocalization.lift_eq this }
use this
apply AlgHom.coe_ringHom_injective
refine IsLocalization.ringHom_ext M ?_
ext
simp
theorem localization_base [FormallySmooth R Sₘ] : FormallySmooth Rₘ Sₘ := by
refine .of_comp_surjective fun Q _ _ I e f ↦ ?_
letI := ((algebraMap Rₘ Q).comp (algebraMap R Rₘ)).toAlgebra
letI : IsScalarTower R Rₘ Q := IsScalarTower.of_algebraMap_eq' rfl
let f : Sₘ →ₐ[Rₘ] Q := by
refine { FormallySmooth.lift I ⟨2, e⟩ (f.restrictScalars R) with commutes' := ?_ }
intro r
change
(RingHom.comp (FormallySmooth.lift I ⟨2, e⟩ (f.restrictScalars R) : Sₘ →+* Q)
(algebraMap _ _))
r =
algebraMap _ _ r
congr 1
refine IsLocalization.ringHom_ext M ?_
rw [RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq,
AlgHom.comp_algebraMap]
use f
ext
simp [f]
theorem localization_map [FormallySmooth R A] : FormallySmooth Rₘ Sₘ := by
haveI : FormallySmooth A Sₘ := FormallySmooth.of_isLocalization (M.map (algebraMap R A))
haveI : FormallySmooth R Sₘ := FormallySmooth.comp R A Sₘ
exact FormallySmooth.localization_base M
end Localization
end FormallySmooth
section
variable (R : Type*) [CommRing R]
variable (A : Type*) [CommRing A] [Algebra R A]
/-- An `R` algebra `A` is smooth if it is formally smooth and of finite presentation. -/
@[stacks 00T2 "In the stacks project, the definition of smooth is completely different, and tag
<https://stacks.math.columbia.edu/tag/00TN> proves that their definition is equivalent to this.",
mk_iff]
class Smooth [CommRing R] (A : Type u) [CommRing A] [Algebra R A] : Prop where
formallySmooth : FormallySmooth R A := by infer_instance
finitePresentation : FinitePresentation R A := by infer_instance
end
namespace Smooth
attribute [instance] formallySmooth finitePresentation
variable {R : Type*} [CommRing R]
variable {A B : Type*} [CommRing A] [Algebra R A] [CommRing B] [Algebra R B]
/-- Being smooth is transported via algebra isomorphisms. -/
theorem of_equiv [Smooth R A] (e : A ≃ₐ[R] B) : Smooth R B where
formallySmooth := FormallySmooth.of_equiv e
finitePresentation := FinitePresentation.equiv e
/-- Localization at an element is smooth. -/
theorem of_isLocalization_Away (r : R) [IsLocalization.Away r A] : Smooth R A where
formallySmooth := Algebra.FormallySmooth.of_isLocalization (Submonoid.powers r)
finitePresentation := IsLocalization.Away.finitePresentation r
section Comp
variable (R A B)
/-- Smooth is stable under composition. -/
theorem comp [Algebra A B] [IsScalarTower R A B] [Smooth R A] [Smooth A B] : Smooth R B where
formallySmooth := FormallySmooth.comp R A B
finitePresentation := FinitePresentation.trans R A B
/-- Smooth is stable under base change. -/
instance baseChange [Smooth R A] : Smooth B (B ⊗[R] A) where
end Comp
end Smooth
end Algebra |
.lake/packages/mathlib/Mathlib/RingTheory/Smooth/Local.lean | import Mathlib.RingTheory.LocalRing.Module
import Mathlib.RingTheory.Smooth.Basic
import Mathlib.RingTheory.TensorProduct.Free
/-!
# Formally smooth local algebras
-/
open TensorProduct IsLocalRing KaehlerDifferential
/--
The **Jacobian criterion** for smoothness of local algebras.
Suppose `S` is a local `R`-algebra, and `0 → I → P → S → 0` is a presentation such that
`P` is formally-smooth over `R`, `Ω[P⁄R]` is finite free over `P`,
(typically satisfied when `P` is the localization of a polynomial ring of finite type)
and `I` is finitely generated.
Then `S` is formally smooth iff `k ⊗ₛ I/I² → k ⊗ₚ Ω[P/R]` is injective,
where `k` is the residue field of `S`.
-/
theorem Algebra.FormallySmooth.iff_injective_lTensor_residueField.{u} {R S : Type*} [CommRing R]
[CommRing S] [IsLocalRing S] [Algebra R S] (P : Algebra.Extension.{u} R S)
[FormallySmooth R P.Ring]
[Module.Free P.Ring Ω[P.Ring⁄R]] [Module.Finite P.Ring Ω[P.Ring⁄R]]
(h' : P.ker.FG) :
Algebra.FormallySmooth R S ↔
Function.Injective (P.cotangentComplex.lTensor (ResidueField S)) := by
have : Module.Finite P.Ring P.Cotangent :=
have : Module.Finite P.Ring P.ker := ⟨(Submodule.fg_top _).mpr h'⟩
.of_surjective _ Extension.Cotangent.mk_surjective
have : Module.Finite S P.Cotangent := Module.Finite.of_restrictScalars_finite P.Ring _ _
rw [← IsLocalRing.split_injective_iff_lTensor_residueField_injective,
P.formallySmooth_iff_split_injection] |
.lake/packages/mathlib/Mathlib/RingTheory/Smooth/Locus.lean | import Mathlib.RingTheory.Etale.Kaehler
import Mathlib.RingTheory.Spectrum.Prime.FreeLocus
import Mathlib.RingTheory.Support
/-!
# Smooth locus of an algebra
Most results in this file are proved for algebras of finite presentations.
Some of them are true for arbitrary algebras but the proof is substantially harder.
## Main results
- `Algebra.smoothLocus` : The set of primes that are smooth over the base.
- `Algebra.basicOpen_subset_smoothLocus_iff` :
`D(f)` is contained in the smooth locus if and only if `A_f` is smooth over `R`.
- `Algebra.smoothLocus_eq_univ_iff` :
The smooth locus is the whole spectrum if and only if `A` is smooth over `R`.
- `Algebra.isOpen_smoothLocus` : The smooth locus is open.
-/
universe u
variable (R A : Type*) [CommRing R] [CommRing A] [Algebra R A]
namespace Algebra
variable {A} in
/--
An `R`-algebra `A` is smooth at a prime `p` of `A` if `Aₚ` is formally smooth over `R`.
This does not imply `Aₚ` is smooth over `R` under the mathlib definition
even if `A` is finitely presented,
but it can be shown that this is equivalent to the stacks project definition that `A` is smooth
at `p` if and only if there exists `f ∉ p` such that `A_f` is smooth over `R`.
See `Algebra.basicOpen_subset_smoothLocus_iff_smooth` and `Algebra.isOpen_smoothLocus`.
-/
@[stacks 00TB]
abbrev IsSmoothAt (p : Ideal A) [p.IsPrime] : Prop :=
Algebra.FormallySmooth R (Localization.AtPrime p)
/-- `Algebra.smoothLocus R A` is the set of primes `p` of `A`
such that `Aₚ` is formally smooth over `R`. -/
def smoothLocus : Set (PrimeSpectrum A) := { p | IsSmoothAt R p.asIdeal }
variable {R A}
attribute [local instance] Module.finitePresentation_of_projective in
lemma smoothLocus_eq_compl_support_inter [EssFiniteType R A] :
smoothLocus R A = (Module.support A (H1Cotangent R A))ᶜ ∩ Module.freeLocus A Ω[A⁄R] := by
ext p
simp only [Set.mem_inter_iff, Set.mem_compl_iff, Module.notMem_support_iff,
Module.mem_freeLocus]
refine (Algebra.formallySmooth_iff _ _).trans (and_comm.trans ?_)
congr! 1
· have := IsLocalizedModule.iso p.asIdeal.primeCompl
(H1Cotangent.map R R A (Localization.AtPrime p.asIdeal))
exact this.subsingleton_congr.symm
· trans Module.Free (Localization.AtPrime p.asIdeal) Ω[Localization.AtPrime p.asIdeal⁄R]
· have : EssFiniteType A (Localization.AtPrime p.asIdeal) :=
.of_isLocalization _ p.asIdeal.primeCompl
have : EssFiniteType R (Localization.AtPrime p.asIdeal) := .comp _ A _
exact ⟨fun _ ↦ Module.free_of_flat_of_isLocalRing, fun _ ↦ inferInstance⟩
· have := IsLocalizedModule.iso p.asIdeal.primeCompl
(KaehlerDifferential.map R R A (Localization.AtPrime p.asIdeal))
have := this.extendScalarsOfIsLocalization
p.asIdeal.primeCompl (Localization.AtPrime p.asIdeal)
exact ⟨fun H ↦ H.of_equiv' this.symm, fun H ↦ H.of_equiv' this⟩
lemma basicOpen_subset_smoothLocus_iff [FinitePresentation R A] {f : A} :
↑(PrimeSpectrum.basicOpen f) ⊆ smoothLocus R A ↔
Algebra.FormallySmooth R (Localization.Away f) := by
rw [smoothLocus_eq_compl_support_inter, Set.subset_inter_iff, Set.subset_compl_comm,
PrimeSpectrum.basicOpen_eq_zeroLocus_compl, compl_compl,
← LocalizedModule.subsingleton_iff_support_subset,
Algebra.formallySmooth_iff, iff_comm, and_comm]
congr! 1
· have := IsLocalizedModule.iso (.powers f) (H1Cotangent.map R R A (Localization.Away f))
rw [this.subsingleton_congr]
· rw [← PrimeSpectrum.basicOpen_eq_zeroLocus_compl, Module.basicOpen_subset_freeLocus_iff]
have := IsLocalizedModule.iso (.powers f)
(KaehlerDifferential.map R R A (Localization.Away f))
have := this.extendScalarsOfIsLocalization (.powers f) (Localization.Away f)
exact ⟨fun _ ↦ .of_equiv this.symm, fun _ ↦ .of_equiv this⟩
lemma basicOpen_subset_smoothLocus_iff_smooth [FinitePresentation R A] {f : A} :
↑(PrimeSpectrum.basicOpen f) ⊆ smoothLocus R A ↔
Algebra.Smooth R (Localization.Away f) := by
have : FinitePresentation A (Localization.Away f) := IsLocalization.Away.finitePresentation f
rw [basicOpen_subset_smoothLocus_iff]
exact ⟨fun H ↦ ⟨H, .trans _ A _⟩, fun H ↦ H.1⟩
lemma smoothLocus_eq_univ_iff [FinitePresentation R A] :
smoothLocus R A = Set.univ ↔ Algebra.FormallySmooth R A := by
have := IsLocalization.atUnits A (.powers 1) (S := Localization.Away (1 : A)) (by simp)
rw [Algebra.FormallySmooth.iff_of_equiv (this.restrictScalars R),
← basicOpen_subset_smoothLocus_iff]
simp
lemma smoothLocus_comap_of_isLocalization {Af : Type*} [CommRing Af] [Algebra A Af] [Algebra R Af]
[IsScalarTower R A Af] (f : A) [IsLocalization.Away f Af] :
PrimeSpectrum.comap (algebraMap A Af) ⁻¹' smoothLocus R A = smoothLocus R Af := by
ext p
let q := PrimeSpectrum.comap (algebraMap A Af) p
have : IsLocalization.AtPrime (Localization.AtPrime p.asIdeal) q.asIdeal :=
IsLocalization.isLocalization_isLocalization_atPrime_isLocalization (.powers f) _ p.asIdeal
refine Algebra.FormallySmooth.iff_of_equiv ?_
exact (IsLocalization.algEquiv q.asIdeal.primeCompl _ _).restrictScalars R
-- Note that this does not follow directly from `smoothLocus_eq_compl_support_inter` because
-- `H¹(L_{S/R})` is not necessarily finitely generated.
open PrimeSpectrum in
lemma isOpen_smoothLocus [FinitePresentation R A] : IsOpen (smoothLocus R A) := by
rw [isOpen_iff_forall_mem_open]
intro x hx
obtain ⟨_, ⟨_, ⟨f, rfl⟩, rfl⟩, hxf, hf⟩ :=
isBasis_basic_opens.exists_subset_of_mem_open
(smoothLocus_eq_compl_support_inter.le hx).2 Module.isOpen_freeLocus
rw [Module.basicOpen_subset_freeLocus_iff] at hf
let Af := Localization.Away f
have : Algebra.FinitePresentation A (Localization.Away f) :=
IsLocalization.Away.finitePresentation f
have : Algebra.FinitePresentation R (Localization.Away f) :=
.trans _ A _
have : IsOpen (smoothLocus R Af) := by
have := IsLocalizedModule.iso (.powers f)
(KaehlerDifferential.map R R A (Localization.Away f))
have := this.extendScalarsOfIsLocalization (.powers f) (Localization.Away f)
have := Module.Projective.of_equiv this
rw [smoothLocus_eq_compl_support_inter, Module.support_eq_zeroLocus]
exact (isClosed_zeroLocus _).isOpen_compl.inter Module.isOpen_freeLocus
rw [← smoothLocus_comap_of_isLocalization f] at this
replace this := (PrimeSpectrum.localization_away_isOpenEmbedding Af f).isOpenMap _ this
rw [Set.image_preimage_eq_inter_range, localization_away_comap_range Af f] at this
exact ⟨_, Set.inter_subset_left, this, hx, hxf⟩
end Algebra |
.lake/packages/mathlib/Mathlib/RingTheory/Smooth/StandardSmoothCotangent.lean | import Mathlib.LinearAlgebra.Basis.Exact
import Mathlib.RingTheory.Extension.Cotangent.Basic
import Mathlib.RingTheory.Smooth.StandardSmooth
import Mathlib.RingTheory.Smooth.Kaehler
import Mathlib.RingTheory.Etale.Basic
/-!
# Cotangent complex of a submersive presentation
Let `P` be a submersive presentation of `S` as an `R`-algebra and
denote by `I` the kernel `R[X] → S`. We show
- `SubmersivePresentation.free_cotangent`: `I ⧸ I ^ 2` is `S`-free on the classes of `P.relation i`.
- `SubmersivePresentation.subsingleton_h1Cotangent`: `H¹(L_{S/R}) = 0`.
- `SubmersivePresentation.free_kaehlerDifferential`: `Ω[S⁄R]` is `S`-free on the images of `dxᵢ`
where `i ∉ Set.range P.map`.
- `SubmersivePresentation.rank_kaehlerDifferential`: If `S` is non-trivial, the rank of
`Ω[S⁄R]` is the dimension of `P`.
We also provide the corresponding instances for standard smooth algebras as corollaries.
We keep the notation `I = ker(R[X] → S)` in all docstrings of this file.
-/
namespace Algebra
variable {R S ι σ : Type*} [CommRing R] [CommRing S] [Algebra R S]
section
open Extension Module MvPolynomial
namespace PreSubmersivePresentation
/--
Given a pre-submersive presentation, this is the composition
`I ⧸ I ^ 2 → ⊕ S dxᵢ → ⊕ S dxᵢ` where the second direct sum runs over
all `i : σ` induced by the injection `P.map : σ → ι`.
If `P` is submersive, this is an isomorphism. See `SubmersivePresentation.cotangentEquiv`.
-/
noncomputable def cotangentComplexAux [Finite σ] (P : PreSubmersivePresentation R S ι σ) :
P.toExtension.Cotangent →ₗ[S] σ → S :=
Finsupp.linearEquivFunOnFinite S S σ ∘ₗ Finsupp.lcomapDomain _ P.map_inj ∘ₗ
P.cotangentSpaceBasis.repr.toLinearMap ∘ₗ P.toExtension.cotangentComplex
lemma cotangentComplexAux_apply [Finite σ] (P : PreSubmersivePresentation R S ι σ)
(x : P.ker) (i : σ) :
P.cotangentComplexAux (Cotangent.mk x) i = (aeval P.val) (pderiv (P.map i) x.val) := by
dsimp only [cotangentComplexAux, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply,
cotangentComplex_mk]
simp only [Generators.toExtension_Ring, Finsupp.lcomapDomain_apply,
Finsupp.linearEquivFunOnFinite_apply, Finsupp.comapDomain_apply,
Generators.cotangentSpaceBasis_repr_tmul, one_mul]
lemma cotangentComplexAux_zero_iff [Finite σ] {P : PreSubmersivePresentation R S ι σ} (x : P.ker) :
P.cotangentComplexAux (Cotangent.mk x) = 0 ↔
∀ i : σ, (aeval P.val) (pderiv (P.map i) x.val) = 0 := by
rw [funext_iff]
simp_rw [cotangentComplexAux_apply, Pi.zero_apply]
end PreSubmersivePresentation
namespace SubmersivePresentation
variable [Finite σ] (P : SubmersivePresentation R S ι σ)
lemma cotangentComplexAux_injective [Finite σ] : Function.Injective P.cotangentComplexAux := by
rw [← LinearMap.ker_eq_bot, eq_bot_iff]
intro x hx
obtain ⟨(x : P.ker), rfl⟩ := Cotangent.mk_surjective x
rw [Submodule.mem_bot, Cotangent.mk_eq_zero_iff]
rw [LinearMap.mem_ker, P.cotangentComplexAux_zero_iff] at hx
have : x.val ∈ Ideal.span (Set.range P.relation) := by
rw [P.span_range_relation_eq_ker]
exact x.property
obtain ⟨c, hc⟩ := Finsupp.mem_ideal_span_range_iff_exists_finsupp.mp this
have heq (i : σ) :
aeval P.val (pderiv (P.map i) <| c.sum fun i a ↦ a * P.relation i) = 0 := by
rw [hc]
apply hx
simp only [Finsupp.sum, map_sum, Derivation.leibniz, smul_eq_mul, map_add, map_mul,
Presentation.aeval_val_relation, zero_mul, add_zero] at heq
have heq2 : ∑ i ∈ c.support,
aeval P.val (c i) • (fun j ↦ aeval P.val (pderiv (P.map j) (P.relation i))) = 0 := by
ext j
simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Pi.zero_apply]
apply heq
have (i : σ) : aeval P.val (c i) = 0 := by
have := P.linearIndependent_aeval_val_pderiv_relation
rw [linearIndependent_iff''] at this
have := this c.support (fun i ↦ aeval P.val (c i))
(by intro i; simp only [Finsupp.mem_support_iff, ne_eq, not_not]; intro h; simp [h]) heq2
exact this i
change _ ∈ P.ker ^ 2
rw [← hc]
apply Ideal.sum_mem
intro i hi
rw [pow_two]
apply Ideal.mul_mem_mul
· rw [P.ker_eq_ker_aeval_val]
simpa using this i
· exact P.relation_mem_ker i
lemma cotangentComplexAux_surjective [Finite σ] : Function.Surjective P.cotangentComplexAux := by
rw [← LinearMap.range_eq_top, _root_.eq_top_iff, ← P.basisDeriv.span_eq, Submodule.span_le]
rintro - ⟨i, rfl⟩
use Cotangent.mk ⟨P.relation i, P.relation_mem_ker i⟩
ext j
rw [P.cotangentComplexAux_apply]
simp
/-- The isomorphism of `S`-modules between `I ⧸ I ^ 2` and `σ → S` given
by `P.relation i ↦ ∂ⱼ (P.relation i)`. -/
@[simps! apply]
noncomputable def cotangentEquiv : P.toExtension.Cotangent ≃ₗ[S] σ → S :=
LinearEquiv.ofBijective _ ⟨P.cotangentComplexAux_injective, P.cotangentComplexAux_surjective⟩
lemma cotangentComplex_injective : Function.Injective P.toExtension.cotangentComplex := by
have := P.cotangentComplexAux_injective
simp only [PreSubmersivePresentation.cotangentComplexAux, LinearMap.coe_comp,
LinearEquiv.coe_coe] at this
exact Function.Injective.of_comp (Function.Injective.of_comp <| Function.Injective.of_comp this)
/-- If `P` is a submersive presentation, `H¹` of the associated cotangent complex vanishes. -/
instance subsingleton_h1Cotangent : Subsingleton P.toExtension.H1Cotangent := by
rw [Algebra.Extension.subsingleton_h1Cotangent]
exact cotangentComplex_injective P
/-- The classes of `P.relation i` form a basis of `I ⧸ I ^ 2`. -/
@[stacks 00T7 "(3)"]
noncomputable def basisCotangent : Basis σ S P.toExtension.Cotangent :=
P.basisDeriv.map P.cotangentEquiv.symm
lemma basisCotangent_apply (r : σ) :
P.basisCotangent r = Extension.Cotangent.mk ⟨P.relation r, P.relation_mem_ker r⟩ := by
symm
apply P.cotangentEquiv.injective
ext
simp_rw [basisCotangent, Basis.map_apply, LinearEquiv.apply_symm_apply, basisDeriv_apply]
apply P.toPreSubmersivePresentation.cotangentComplexAux_apply _ _
@[stacks 00T7 "(3)"]
instance free_cotangent : Module.Free S P.toExtension.Cotangent :=
Module.Free.of_basis P.basisCotangent
/--
If `P` is a submersive presentation, this is the section of the map
`I ⧸ I ^ 2 → ⊕ S dxᵢ` given by projecting to the summands indexed by `σ` and composing with the
inverse of `P.cotangentEquiv`.
By `SubmersivePresentation.sectionCotangent_comp` this is indeed a section.
-/
noncomputable def sectionCotangent : P.toExtension.CotangentSpace →ₗ[S] P.toExtension.Cotangent :=
(cotangentEquiv P).symm ∘ₗ (Finsupp.linearEquivFunOnFinite S S σ).toLinearMap ∘ₗ
Finsupp.lcomapDomain _ P.map_inj ∘ₗ P.cotangentSpaceBasis.repr.toLinearMap
lemma sectionCotangent_eq_iff [Finite σ]
(x : P.toExtension.CotangentSpace) (y : P.toExtension.Cotangent) :
sectionCotangent P x = y ↔
∀ i : σ, P.cotangentSpaceBasis.repr x (P.map i) = (P.cotangentComplexAux y) i := by
simp only [sectionCotangent, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply]
rw [← (cotangentEquiv P).injective.eq_iff, funext_iff, LinearEquiv.apply_symm_apply]
simp
lemma sectionCotangent_comp :
sectionCotangent P ∘ₗ P.toExtension.cotangentComplex = LinearMap.id := by
ext : 1
simp only [LinearMap.coe_comp, Function.comp_apply, LinearMap.id_coe, id_eq]
rw [sectionCotangent_eq_iff]
intro i
rfl
lemma sectionCotangent_zero_of_notMem_range (i : ι) (hi : i ∉ Set.range P.map) :
(sectionCotangent P) (P.cotangentSpaceBasis i) = 0 := by
classical
contrapose hi
rw [sectionCotangent_eq_iff] at hi
simp only [Basis.repr_self, map_zero, Pi.zero_apply, Finsupp.single_apply] at hi
grind
@[deprecated (since := "2025-05-23")]
alias sectionCotangent_zero_of_not_mem_range := sectionCotangent_zero_of_notMem_range
/--
Given a submersive presentation of `S` as `R`-algebra, any indexing type `κ` complementary to
the `σ` in `ι` indexes a basis of `Ω[S⁄R]`.
See `SubmersivePresentation.basisKaehler` for the special case `κ = (Set.range P.map)ᶜ`.
-/
noncomputable def basisKaehlerOfIsCompl {κ : Type*} {f : κ → ι}
(hf : Function.Injective f) (hcompl : IsCompl (Set.range f) (Set.range P.map)) :
Basis κ S Ω[S⁄R] := by
apply P.cotangentSpaceBasis.ofSplitExact (sectionCotangent_comp P)
Extension.exact_cotangentComplex_toKaehler Extension.toKaehler_surjective hf (b := P.map)
· intro i
apply sectionCotangent_zero_of_notMem_range _ _
simp [← hcompl.compl_eq]
· simp only [sectionCotangent, LinearMap.coe_comp, Function.comp_assoc, LinearEquiv.coe_coe]
apply LinearIndependent.map' _ _ P.cotangentEquiv.symm.ker
convert (Pi.basisFun S σ).linearIndependent
classical
ext i j
simp only [Function.comp_apply, Basis.repr_self, Finsupp.linearEquivFunOnFinite_apply,
Pi.basisFun_apply]
simp [Finsupp.single_eq_pi_single]
· exact hcompl.2
/-- Given a submersive presentation of `S` as `R`-algebra, the images of `dxᵢ`
for `i` in the complement of `σ` in `ι` form a basis of `Ω[S⁄R]`. -/
@[stacks 00T7 "(2)"]
noncomputable def basisKaehler :
Basis ((Set.range P.map)ᶜ : Set _) S Ω[S⁄R] :=
P.basisKaehlerOfIsCompl Subtype.val_injective <| by
rw [Subtype.range_coe_subtype]
exact IsCompl.symm isCompl_compl
/-- If `P` is a submersive presentation of `S` as an `R`-algebra, `Ω[S⁄R]` is free. -/
@[stacks 00T7 "(2)"]
theorem free_kaehlerDifferential (P : SubmersivePresentation R S ι σ) :
Module.Free S Ω[S⁄R] :=
Module.Free.of_basis P.basisKaehler
attribute [local instance] Fintype.ofFinite in
/-- If `P` is a submersive presentation of `S` as an `R`-algebra and `S` is nontrivial,
`Ω[S⁄R]` is free of rank the dimension of `P`, i.e. the number of generators minus the number
of relations. -/
theorem rank_kaehlerDifferential [Nontrivial S] [Finite ι]
(P : SubmersivePresentation R S ι σ) : Module.rank S Ω[S⁄R] = P.dimension := by
simp only [rank_eq_card_basis P.basisKaehler, Fintype.card_compl_set,
Presentation.dimension, Nat.card_eq_fintype_card, Set.card_range_of_injective P.map_inj]
end SubmersivePresentation
section LocalizationAway
variable (r : R) [IsLocalization.Away r S]
instance : Module.Free S (Generators.localizationAway S r).toExtension.Cotangent :=
inferInstanceAs <|
Module.Free S ((SubmersivePresentation.localizationAway S r).toExtension.Cotangent)
variable (S) in
/-- The image of `g * X - 1` in `I/I²` if `I` is the kernel of the canonical presentation
of the localization of `S` away from `g`. -/
noncomputable
abbrev Generators.cMulXSubOneCotangent : (Generators.localizationAway S r).toExtension.Cotangent :=
Extension.Cotangent.mk ⟨C r * X () - 1, C_mul_X_sub_one_mem_ker _⟩
lemma Generators.cMulXSubOneCotangent_eq :
cMulXSubOneCotangent S r = Extension.Cotangent.mk ⟨C r * X () - 1, C_mul_X_sub_one_mem_ker _⟩ :=
rfl
lemma SubmersivePresentation.basisCotangent_localizationAway_apply (x : Unit) :
(SubmersivePresentation.localizationAway S r).basisCotangent x =
Generators.cMulXSubOneCotangent S r :=
basisCotangent_apply _ _
variable (S) in
/--
The basis of `(g * X - 1) / (g * X - 1)²` given by the image of `g * X - 1`.
This is def-eq to `(SubmersivePresentation.localizationAway T g).basisCotangent`, but
```
(SubmersivePresentation.localizationAway T g).toExtension =
(Generators.localizationAway T g).toExtension
```
is not reducibly def-eq. Hence using the general `SubmersivePresentation.basisCotangent` leads
to `erw` hell.
-/
noncomputable
def Generators.basisCotangentAway (r : R) [IsLocalization.Away r S] :
Module.Basis Unit S (localizationAway S r).toExtension.Cotangent :=
(SubmersivePresentation.localizationAway S r).basisCotangent
lemma Generators.basisCotangentAway_apply (x : Unit) :
basisCotangentAway S r x = cMulXSubOneCotangent S r :=
SubmersivePresentation.basisCotangent_apply _ _
end LocalizationAway
/-- If `S` is `R`-standard smooth, `Ω[S⁄R]` is a free `S`-module. -/
instance IsStandardSmooth.free_kaehlerDifferential [IsStandardSmooth R S] :
Module.Free S Ω[S⁄R] := by
obtain ⟨_, _, _, _, ⟨P⟩⟩ := ‹IsStandardSmooth R S›
exact P.free_kaehlerDifferential
instance IsStandardSmooth.subsingleton_h1Cotangent [IsStandardSmooth R S] :
Subsingleton (H1Cotangent R S) := by
obtain ⟨_, _, _, _, ⟨P⟩⟩ := ‹IsStandardSmooth R S›
exact P.equivH1Cotangent.symm.toEquiv.subsingleton
/-- If `S` is non-trivial and `R`-standard smooth of relative dimension, `Ω[S⁄R]` is a free
`S`-module of rank `n`. -/
theorem IsStandardSmoothOfRelativeDimension.rank_kaehlerDifferential [Nontrivial S] (n : ℕ)
[IsStandardSmoothOfRelativeDimension n R S] :
Module.rank S Ω[S⁄R] = n := by
obtain ⟨_, _, _, _, ⟨P, hP⟩⟩ := ‹IsStandardSmoothOfRelativeDimension n R S›
rw [P.rank_kaehlerDifferential, hP]
instance IsStandardSmoothOfRelationDimension.subsingleton_kaehlerDifferential
[IsStandardSmoothOfRelativeDimension 0 R S] : Subsingleton Ω[S⁄R] := by
cases subsingleton_or_nontrivial S
· exact Module.subsingleton S _
haveI : IsStandardSmooth R S := IsStandardSmoothOfRelativeDimension.isStandardSmooth 0
exact Module.subsingleton_of_rank_zero
(IsStandardSmoothOfRelativeDimension.rank_kaehlerDifferential 0)
end
instance (priority := 900) [IsStandardSmooth R S] : Smooth R S where
formallySmooth := by
rw [Algebra.formallySmooth_iff]
exact ⟨inferInstance, inferInstance⟩
/-- If `S` is `R`-standard smooth of relative dimension zero, it is étale. -/
instance (priority := 900) [IsStandardSmoothOfRelativeDimension 0 R S] : Etale R S where
finitePresentation := (IsStandardSmoothOfRelativeDimension.isStandardSmooth 0).finitePresentation
formallyEtale :=
have : IsStandardSmooth R S := IsStandardSmoothOfRelativeDimension.isStandardSmooth 0
have : FormallyUnramified R S := ⟨inferInstance⟩
.of_formallyUnramified_and_formallySmooth
end Algebra |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Nonunits.lean | import Mathlib.RingTheory.Ideal.Maximal
/-!
# The set of non-invertible elements of a monoid
## Main definitions
* `nonunits` is the set of non-invertible elements of a monoid.
## Main results
* `exists_max_ideal_of_mem_nonunits`: every element of `nonunits` is contained in a maximal ideal
-/
variable {F α β : Type*} {a b : α}
/-- The set of non-invertible elements of a monoid. -/
def nonunits (α : Type*) [Monoid α] : Set α :=
{ a | ¬IsUnit a }
@[simp]
theorem mem_nonunits_iff [Monoid α] : a ∈ nonunits α ↔ ¬IsUnit a :=
Iff.rfl
theorem mul_mem_nonunits_right [CommMonoid α] : b ∈ nonunits α → a * b ∈ nonunits α :=
mt isUnit_of_mul_isUnit_right
theorem mul_mem_nonunits_left [CommMonoid α] : a ∈ nonunits α → a * b ∈ nonunits α :=
mt isUnit_of_mul_isUnit_left
theorem zero_mem_nonunits [MonoidWithZero α] : 0 ∈ nonunits α ↔ (0 : α) ≠ 1 :=
not_congr isUnit_zero_iff
@[simp high] -- High priority shortcut lemma
theorem one_notMem_nonunits [Monoid α] : (1 : α) ∉ nonunits α :=
not_not_intro isUnit_one
@[deprecated (since := "2025-05-23")] alias one_not_mem_nonunits := one_notMem_nonunits
@[simp high] -- High priority shortcut lemma
theorem map_mem_nonunits_iff [Monoid α] [Monoid β] [FunLike F α β] [MonoidHomClass F α β] (f : F)
[IsLocalHom f] (a) : f a ∈ nonunits β ↔ a ∈ nonunits α :=
⟨fun h ha => h <| ha.map f, fun h ha => h <| ha.of_map⟩
theorem coe_subset_nonunits [Semiring α] {I : Ideal α} (h : I ≠ ⊤) : (I : Set α) ⊆ nonunits α :=
fun _x hx hu => h <| I.eq_top_of_isUnit_mem hx hu
theorem exists_max_ideal_of_mem_nonunits [CommSemiring α] (h : a ∈ nonunits α) :
∃ I : Ideal α, I.IsMaximal ∧ a ∈ I := by
have : Ideal.span ({a} : Set α) ≠ ⊤ := by
intro H
rw [Ideal.span_singleton_eq_top] at H
contradiction
rcases Ideal.exists_le_maximal _ this with ⟨I, Imax, H⟩
use I, Imax
apply H
apply Ideal.subset_span
exact Set.mem_singleton a |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Oka.lean | import Mathlib.RingTheory.Ideal.Colon
/-!
# Oka predicates
This file introduces the notion of Oka predicates and standard results about them.
## Main results
- `Ideal.IsOka.isPrime_of_maximal_not`: if an ideal is maximal for not satisfying an Oka predicate,
then it is prime.
- `Ideal.IsOka.forall_of_forall_prime`: if all prime ideals of a ring satisfy an Oka predicate,
then all its ideals also satisfy the predicate.
## References
- [stacks-project]: The Stacks project, [tag 05K7](https://stacks.math.columbia.edu/tag/05K7)
- [lam_reyes_2009]: *Oka and Ako ideal families in commutative rings*, 2009
-/
namespace Ideal
variable {R : Type*} [CommSemiring R]
/-- A predicate `P : Ideal R → Prop` over the ideals of a ring `R` is said to be Oka if R satisfies
it (`P ⊤`) and whenever we have `I : Ideal R`, `P (I.colon (span {a})` and `P (I ⊔ span {a})` for
some `a : R` then `P I`. -/
@[stacks 05K9]
structure IsOka (P : Ideal R → Prop) : Prop where
top : P ⊤
oka {I : Ideal R} {a : R} : P (I ⊔ span {a}) → P (I.colon (span {a})) → P I
namespace IsOka
variable {P : Ideal R → Prop} (hP : IsOka P)
include hP
/-- If an ideal is maximal for not satisfying an Oka predicate then it is prime. -/
@[stacks 05KE]
theorem isPrime_of_maximal_not {I : Ideal R} (hI : Maximal (¬P ·) I) : I.IsPrime where
ne_top' hI' := hI.prop (hI' ▸ hP.top)
mem_or_mem' := by
by_contra!
obtain ⟨a, b, hab, ha, hb⟩ := this
have h₁ : P (I ⊔ span {a}) := of_not_not <| hI.not_prop_of_gt (Submodule.lt_sup_iff_notMem.2 ha)
have h₂ : P (I.colon (span {a})) := of_not_not <| hI.not_prop_of_gt <| lt_of_le_of_ne le_colon
(fun H ↦ hb <| H ▸ mem_colon_singleton.2 (mul_comm a b ▸ hab))
exact hI.prop (hP.oka h₁ h₂)
/-- If a ring `R` verify:
1. All prime ideals of `R` satisfy an Oka predicate `P`.
2. One ideal not satisfying `P` implies that there is an ideal maximal for not satisfying `P`.
Then all the ideals of `R` satisfy `P`. -/
theorem forall_of_forall_prime (hmax : ∀ I, ¬P I → ∃ I, Maximal (¬P ·) I)
(hprime : ∀ I, I.IsPrime → P I) (I : Ideal R) : P I := by
by_contra! hI
obtain ⟨I, hI⟩ := hmax I hI
exact hI.prop <| hprime I (hP.isPrime_of_maximal_not hI)
/-- A variant of `forall_of_forall_prime` with a different spelling of the condition `hmax`. -/
theorem forall_of_forall_prime'
(hchain : ∀ C ⊆ {I | ¬P I}, IsChain (· ≤ ·) C → ∀ _ ∈ C, P (sSup C) → ∃ I ∈ C, P I)
(hprime : ∀ I, I.IsPrime → P I) : ∀ I, P I := by
refine forall_of_forall_prime hP (fun I hI ↦ ?_) hprime
obtain ⟨M, _, hM⟩ : ∃ M, I ≤ M ∧ Maximal (¬P ·) M := by
refine zorn_le_nonempty₀ {I | ¬P I} (fun C hC₁ hC₂ J hJ ↦ ⟨sSup C, ?_, fun _ ↦ le_sSup⟩) I hI
intro H
obtain ⟨_, h₁, h₂⟩ := hchain C hC₁ hC₂ J hJ H
exact hC₁ h₁ h₂
exact ⟨M, hM⟩
end IsOka
end Ideal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Int.lean | import Mathlib.Algebra.Field.ZMod
import Mathlib.RingTheory.Ideal.Norm.AbsNorm
/-!
# Ideal of `ℤ`
We prove results about ideals of `ℤ` or ideals of extensions of `ℤ`.
In particular, for `I` an ideal of a ring `R` extending `ℤ`, we prove several results about
`absNorm (under ℤ I)` which is the smallest positive integer contained in `I`.
## Main definitions and results
* `Int.ideal_span_isMaximal_of_prime`: the ideal generated by a prime number is maximal.
* `Int.liesOver_span_absNorm`: the ideal generated by `absNorm (under ℤ I)` lies under `I`.
* `Int.absNorm_under_eq_sInf`: the predicate that the `absNorm (under ℤ I)` is the smallest
positive integer in `I`.
* `Int.absNorm_under_dvd_absNorm`: `absNorm (under ℤ I)` divides the norm of `I`.
* `Nat.absNorm_under_prime`: If `P` is a prime ideal, then `absNorm (under ℤ P)` is a prime number.
-/
instance Int.ideal_span_isMaximal_of_prime (p : ℕ) [Fact (Nat.Prime p)] :
(Ideal.span {(p : ℤ)}).IsMaximal :=
Ideal.Quotient.maximal_of_isField _ <|
(Int.quotientSpanNatEquivZMod p).toMulEquiv.isField (Field.toIsField _)
open Ideal
variable {R : Type*}
namespace Int
section Ring
variable [Ring R] {I : Ideal R}
instance liesOver_span_absNorm (I : Ideal R) :
I.LiesOver (span {(absNorm (under ℤ I) : ℤ)}) := by
rw [liesOver_iff, under_def, Int.ideal_span_absNorm_eq_self]
theorem cast_mem_ideal_iff {d : ℤ} :
(d : R) ∈ I ↔ (absNorm (under ℤ I) : ℤ) ∣ d := by
rw [← mem_span_singleton, ideal_span_absNorm_eq_self, under_def, mem_comap, eq_intCast]
variable (I)
theorem absNorm_under_mem :
(absNorm (under ℤ I) : R) ∈ I := by
rw [← cast_natCast, cast_mem_ideal_iff]
theorem absNorm_under_eq_sInf :
absNorm (under ℤ I) = sInf {d : ℕ | 0 < d ∧ (d : R) ∈ I} := by
by_cases h : absNorm (under ℤ I) = 0
· have : {d : ℕ | 0 < d ∧ ↑d ∈ I} = ∅ := by
refine Set.eq_empty_of_forall_notMem ?_
intro x ⟨hx₁, hx₂⟩
rw [← cast_natCast, cast_mem_ideal_iff, h, natCast_dvd_natCast, Nat.zero_dvd] at hx₂
rw [Nat.pos_iff_ne_zero] at hx₁
exact hx₁ hx₂
rw [h, this, Nat.sInf_empty]
· have h₁ : absNorm (under ℤ I) ∈ {d : ℕ | 0 < d ∧ ↑d ∈ I} :=
⟨Nat.pos_of_ne_zero h, absNorm_under_mem I⟩
refine le_antisymm ?_ (Nat.sInf_le h₁)
by_contra! h₀
have h₂ := (Nat.sInf_mem (Set.nonempty_of_mem h₁)).2
rw [← cast_natCast, cast_mem_ideal_iff, natCast_dvd_natCast] at h₂
exact lt_iff_not_ge.mp h₀ <| Nat.le_of_dvd (Nat.sInf_mem (Set.nonempty_of_mem h₁)).1 h₂
theorem absNorm_under_dvd_absNorm {S : Type*} [CommRing S] [IsDedekindDomain S] [Module.Free ℤ S]
(I : Ideal S) :
absNorm (under ℤ I) ∣ absNorm I := by
cases finite_or_infinite (S ⧸ I)
· have : Fintype (S ⧸ I) := Fintype.ofFinite (S ⧸ I)
have h_main {d : ℕ} : (d : S) ∈ I ↔ ∀ (x : S ⧸ I), d • x = 0 := by
simp_rw [nsmul_eq_mul, ← map_natCast (Ideal.Quotient.mk I), ← Quotient.eq_zero_iff_mem]
exact ⟨fun h _ ↦ by simp [h], fun h ↦ by simpa using h 1⟩
rw [Ideal.absNorm_apply I, Submodule.cardQuot_apply, Nat.card_eq_fintype_card]
simp_rw [absNorm_under_eq_sInf, h_main, ← AddMonoid.exponent_eq_sInf]
exact AddGroup.exponent_dvd_card (G := S ⧸ I)
· rw [absNorm_apply I, Submodule.cardQuot_apply, Nat.card_eq_zero_of_infinite]
exact Nat.dvd_zero _
end Ring
end Int
section CommRing
variable [CommRing R] [IsDomain R] [Algebra.IsIntegral ℤ R]
theorem Nat.absNorm_under_prime (P : Ideal R) [P.IsPrime] [NeZero P] :
(absNorm (under ℤ P)).Prime := by
rw [Nat.prime_iff_prime_int, ← span_singleton_prime, Int.ideal_span_absNorm_eq_self]
· infer_instance
· refine Int.natCast_ne_zero.mpr <| absNorm_eq_zero_iff.not.mpr ?_
have : P ≠ ⊥ := NeZero.ne _
contrapose! this
exact eq_bot_of_comap_eq_bot this
end CommRing |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/GoingDown.lean | import Mathlib.RingTheory.Ideal.GoingUp
import Mathlib.RingTheory.Flat.FaithfullyFlat.Algebra
import Mathlib.RingTheory.Flat.Localization
import Mathlib.RingTheory.Spectrum.Prime.Topology
/-!
# Going down
In this file we define a predicate `Algebra.HasGoingDown`: An `R`-algebra `S` satisfies
`Algebra.HasGoingDown R S` if for every pair of prime ideals `p ≤ q` of `R` with `Q` a prime
of `S` lying above `q`, there exists a prime `P ≤ Q` of `S` lying above `p`.
## Main results
- `Algebra.HasGoingDown.iff_generalizingMap_primeSpectrumComap`: going down is equivalent
to generalizations lifting along `Spec S → Spec R`.
- `Algebra.HasGoingDown.of_flat`: flat algebras satisfy going down.
## TODOs
- An integral extension of domains with normal base satisfies going down.
-/
/--
An `R`-algebra `S` satisfies `Algebra.HasGoingDown R S` if for every pair of
prime ideals `p ≤ q` of `R` with `Q` a prime of `S` lying above `q`, there exists a
prime `P ≤ Q` of `S` lying above `p`.
The condition only asks for `<` which is easier to prove, use
`Ideal.exists_ideal_le_liesOver_of_le` for applying it.
-/
@[stacks 00HV "(2)"]
class Algebra.HasGoingDown (R S : Type*) [CommRing R] [CommRing S] [Algebra R S] : Prop where
exists_ideal_le_liesOver_of_lt {p : Ideal R} [p.IsPrime] (Q : Ideal S) [Q.IsPrime] :
p < Q.under R → ∃ P ≤ Q, P.IsPrime ∧ P.LiesOver p
variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S]
lemma Ideal.exists_ideal_le_liesOver_of_le [Algebra.HasGoingDown R S]
{p q : Ideal R} [p.IsPrime] [q.IsPrime] (Q : Ideal S) [Q.IsPrime] [Q.LiesOver q]
(hle : p ≤ q) :
∃ P ≤ Q, P.IsPrime ∧ P.LiesOver p := by
by_cases h : p = q
· subst h
use Q
· have := Q.over_def q
subst this
exact Algebra.HasGoingDown.exists_ideal_le_liesOver_of_lt Q (lt_of_le_of_ne hle h)
lemma Ideal.exists_ideal_lt_liesOver_of_lt [Algebra.HasGoingDown R S]
{p q : Ideal R} [p.IsPrime] [q.IsPrime] (Q : Ideal S) [Q.IsPrime] [Q.LiesOver q]
(hpq : p < q) : ∃ P < Q, P.IsPrime ∧ P.LiesOver p := by
obtain ⟨P, hPQ, _, _⟩ := Q.exists_ideal_le_liesOver_of_le (p := p) (q := q) hpq.le
refine ⟨P, ?_, inferInstance, inferInstance⟩
by_contra hc
have : P = Q := eq_of_le_of_not_lt hPQ hc
subst this
simp [P.over_def p, P.over_def q] at hpq
lemma Ideal.exists_ltSeries_of_hasGoingDown [Algebra.HasGoingDown R S]
(l : LTSeries (PrimeSpectrum R)) (P : Ideal S) [P.IsPrime] [lo : P.LiesOver l.last.asIdeal] :
∃ (L : LTSeries (PrimeSpectrum S)),
L.length = l.length ∧
L.last = ⟨P, inferInstance⟩ ∧
List.map (algebraMap R S).specComap L.toList = l.toList := by
induction l using RelSeries.inductionOn generalizing P with
| singleton q =>
use RelSeries.singleton _ ⟨P, inferInstance⟩
simp only [RelSeries.singleton_length, RelSeries.last_singleton, RelSeries.toList_singleton,
List.map_cons, List.map_nil, List.cons.injEq, and_true, true_and]
ext : 1
simpa using lo.over.symm
| cons l q lt ih =>
simp only [RelSeries.last_cons] at lo
obtain ⟨L, len, last, spec⟩ := ih P
have : L.head.asIdeal.LiesOver l.head.asIdeal := by
constructor
rw [← L.toList_getElem_zero_eq_head, ← l.toList_getElem_zero_eq_head, Ideal.under_def]
have : l.toList[0] = (algebraMap R S).specComap L.toList[0] := by
rw [List.getElem_map_rev (algebraMap R S).specComap, List.getElem_of_eq spec.symm _]
rwa [RingHom.specComap, PrimeSpectrum.ext_iff] at this
obtain ⟨Q, Qlt, hQ, Qlo⟩ := Ideal.exists_ideal_lt_liesOver_of_lt L.head.asIdeal lt
use L.cons ⟨Q, hQ⟩ Qlt
simp only [RelSeries.cons_length, add_left_inj, RelSeries.last_cons]
exact ⟨len, last, by simpa [spec] using PrimeSpectrum.ext_iff.mpr Qlo.over.symm⟩
namespace Algebra.HasGoingDown
variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S]
/-- An `R`-algebra `S` has the going down property if and only if generalizations lift
along `Spec S → Spec R`. -/
@[stacks 00HW "(1)"]
lemma iff_generalizingMap_primeSpectrumComap :
Algebra.HasGoingDown R S ↔
GeneralizingMap (PrimeSpectrum.comap (algebraMap R S)) := by
refine ⟨?_, fun h ↦ ⟨fun {p} hp Q hQ hlt ↦ ?_⟩⟩
· intro h Q p hp
rw [← PrimeSpectrum.le_iff_specializes] at hp
obtain ⟨P, hle, hP, h⟩ := Q.asIdeal.exists_ideal_le_liesOver_of_le (p := p.asIdeal)
(q := Q.asIdeal.under R) hp
refine ⟨⟨P, hP⟩, (PrimeSpectrum.le_iff_specializes _ Q).mp hle, ?_⟩
ext : 1
exact h.over.symm
· have : (⟨p, hp⟩ : PrimeSpectrum R) ⤳ (PrimeSpectrum.comap (algebraMap R S) ⟨Q, hQ⟩) :=
(PrimeSpectrum.le_iff_specializes _ _).mp hlt.le
obtain ⟨P, hs, heq⟩ := h this
refine ⟨P.asIdeal, (PrimeSpectrum.le_iff_specializes _ _).mpr hs, P.2, ⟨?_⟩⟩
simpa [PrimeSpectrum.ext_iff] using heq.symm
variable (R S) in
@[stacks 00HX]
lemma trans (T : Type*) [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T]
[Algebra.HasGoingDown R S] [Algebra.HasGoingDown S T] :
Algebra.HasGoingDown R T := by
rw [iff_generalizingMap_primeSpectrumComap, IsScalarTower.algebraMap_eq R S T]
simp only [PrimeSpectrum.comap_comp, ContinuousMap.coe_comp]
apply GeneralizingMap.comp
· rwa [← iff_generalizingMap_primeSpectrumComap]
· rwa [← iff_generalizingMap_primeSpectrumComap]
/-- If for every prime of `S`, the map `Spec Sₚ → Spec Rₚ` is surjective,
the algebra satisfies going down. -/
lemma of_specComap_localRingHom_surjective
(H : ∀ (P : Ideal S) [P.IsPrime], Function.Surjective
(Localization.localRingHom (P.under R) P (algebraMap R S) rfl).specComap) :
Algebra.HasGoingDown R S where
exists_ideal_le_liesOver_of_lt {p} _ Q _ hlt := by
let pl : Ideal (Localization.AtPrime <| Q.under R) := p.map (algebraMap R _)
have : pl.IsPrime :=
Ideal.isPrime_map_of_isLocalizationAtPrime (Q.under R) hlt.le
obtain ⟨⟨Pl, _⟩, hl⟩ := H Q ⟨pl, inferInstance⟩
refine ⟨Pl.under S, ?_, Ideal.IsPrime.under S Pl, ⟨?_⟩⟩
· exact (IsLocalization.AtPrime.orderIsoOfPrime _ Q ⟨Pl, inferInstance⟩).2.2
· replace hl : Pl.under _ = pl := by simpa using hl
rw [Ideal.under_under, ← Ideal.under_under (B := (Localization.AtPrime <| Q.under R)) Pl, hl,
Ideal.under_map_of_isLocalizationAtPrime (Q.under R) hlt.le]
/-- Flat algebras satisfy the going down property. -/
@[stacks 00HS]
instance of_flat [Module.Flat R S] : Algebra.HasGoingDown R S := by
apply of_specComap_localRingHom_surjective
intro P hP
have : IsLocalHom (algebraMap (Localization.AtPrime <| P.under R) (Localization.AtPrime P)) := by
rw [RingHom.algebraMap_toAlgebra]
exact Localization.isLocalHom_localRingHom (P.under R) P (algebraMap R S) Ideal.LiesOver.over
have : Module.FaithfullyFlat (Localization.AtPrime (P.under R)) (Localization.AtPrime P) :=
Module.FaithfullyFlat.of_flat_of_isLocalHom
apply PrimeSpectrum.specComap_surjective_of_faithfullyFlat
end Algebra.HasGoingDown |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/NatInt.lean | import Mathlib.Algebra.EuclideanDomain.Int
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Data.Nat.Prime.Int
import Mathlib.RingTheory.Int.Basic
import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic
import Mathlib.RingTheory.KrullDimension.Basic
import Mathlib.RingTheory.PrincipalIdealDomain
/-!
# Prime ideals in ℕ and ℤ
## Main results
* `Ideal.isPrime_nat_iff`: the prime ideals in ℕ are ⟨0⟩, ⟨p⟩ (for prime `p`), and ⟨2, 3⟩ = {1}ᶜ.
The proof follows https://math.stackexchange.com/a/4224486.
* `Ideal.isPrime_int_iff` : the prime ideals in ℤ are ⟨0⟩ and ⟨p⟩ (for prime `p`).
-/
/-- The natural numbers form a local semiring. -/
instance : IsLocalRing ℕ where
isUnit_or_isUnit_of_add_one {a b} hab := by
have h : a = 1 ∨ b = 1 := by omega
apply h.imp <;> simp +contextual
open IsLocalRing Ideal
theorem Nat.mem_maximalIdeal_iff {n : ℕ} : n ∈ maximalIdeal ℕ ↔ n ≠ 1 := by simp
theorem Nat.coe_maximalIdeal : (maximalIdeal ℕ : Set ℕ) = {1}ᶜ := by ext; simp
theorem Nat.maximalIdeal_eq_span_two_three : maximalIdeal ℕ = span {2, 3} := by
refine le_antisymm (fun n h ↦ ?_) (span_le.mpr <| Set.pair_subset (by simp) (by simp))
obtain lt | lt := (mem_maximalIdeal_iff.mp h).lt_or_gt
· obtain rfl := lt_one_iff.mp lt; exact zero_mem _
exact mem_span_pair.mpr <|
exists_add_mul_eq_of_gcd_dvd_of_mul_pred_le 2 3 n (by simp) (show 2 ≤ n by cutsat)
theorem Nat.one_mem_span_iff {s : Set ℕ} : 1 ∈ span s ↔ 1 ∈ s := by
rw [← SetLike.mem_coe, ← not_iff_not]
simp_rw [← Set.mem_compl_iff, ← Set.singleton_subset_iff, Set.subset_compl_comm,
← coe_maximalIdeal, SetLike.coe_subset_coe, span_le]
theorem Nat.one_mem_closure_iff {s : Set ℕ} : 1 ∈ AddSubmonoid.closure s ↔ 1 ∈ s := by
rw [← Submodule.span_nat_eq_addSubmonoidClosure]
exact one_mem_span_iff
theorem Ideal.isPrime_nat_iff {P : Ideal ℕ} :
P.IsPrime ↔ P = ⊥ ∨ P = maximalIdeal ℕ ∨ ∃ p : ℕ, p.Prime ∧ P = span {p} := by
refine .symm ⟨?_, fun h ↦ or_iff_not_imp_left.mpr fun h0 ↦ or_iff_not_imp_right.mpr fun hsp ↦
(le_maximalIdeal h.ne_top).antisymm fun n hn ↦ ?_⟩
· rintro (rfl | rfl | ⟨p, hp, rfl⟩)
· exact bot_prime
· exact (maximalIdeal.isMaximal ℕ).isPrime
· rwa [span_singleton_prime (by simp [hp.ne_zero]), ← Nat.prime_iff]
rw [← le_bot_iff, SetLike.not_le_iff_exists] at h0
classical
let p := Nat.find h0
have ⟨(hp : p ∈ P), (hp0 : p ≠ 0)⟩ := Nat.find_spec h0
have : p ≠ 1 := ne_of_mem_of_not_mem hp P.one_notMem
have prime : p.Prime := Nat.prime_iff_not_exists_mul_eq.mpr <| .intro (by cutsat)
fun ⟨m, n, hm, hn, eq⟩ ↦ have := mul_ne_zero_iff.mp (eq ▸ hp0)
(h.mem_or_mem (eq ▸ hp)).elim (Nat.find_min h0 hm ⟨·, this.1⟩) (Nat.find_min h0 hn ⟨·, this.2⟩)
push_neg at hsp
have ⟨q, hq, hqp⟩ := SetLike.exists_of_lt
((P.span_singleton_le_iff_mem.mpr hp).lt_of_ne (hsp p prime).symm)
obtain rfl | hn1 := eq_or_ne n 0
· exact Ideal.zero_mem _
have : n ≠ 1 := Nat.mem_maximalIdeal_iff.mp hn
have ⟨a, b, eq⟩ := Nat.exists_add_mul_eq_of_gcd_dvd_of_mul_pred_le p q _
(by simp [prime.coprime_iff_not_dvd.mpr (Ideal.mem_span_singleton.not.mp hqp)])
(Nat.lt_pow_self (show 1 < n by cutsat)).le
exact h.mem_of_pow_mem _ (eq ▸ add_mem (P.mul_mem_left _ hp) (P.mul_mem_left _ hq))
theorem Ideal.map_comap_natCastRingHom_int {I : Ideal ℤ} :
(I.comap (Nat.castRingHom ℤ)).map (Nat.castRingHom ℤ) = I :=
map_comap_le.antisymm fun n hn ↦ n.sign_mul_natAbs ▸ mul_mem_left _ _ <| mem_map_of_mem _
(mem_comap.mpr <| show (n.natAbs : ℤ) ∈ I from n.sign_mul_self ▸ mul_mem_left _ _ hn)
theorem Ideal.isPrime_int_iff {P : Ideal ℤ} :
P.IsPrime ↔ P = ⊥ ∨ ∃ p : ℕ, p.Prime ∧ P = span {(p : ℤ)} :=
isPrime_iff_of_isPrincipalIdealRing_of_noZeroDivisors.trans <| or_congr_right
⟨fun ⟨p, hp, eq⟩ ↦ ⟨_, Int.prime_iff_natAbs_prime.mp hp, eq.trans
p.span_natAbs.symm⟩, fun ⟨_p, hp, eq⟩ ↦ ⟨_, Nat.prime_iff_prime_int.mp hp, eq⟩⟩
theorem ringKrullDim_nat : ringKrullDim ℕ = 2 := by
refine le_antisymm (iSup_le fun s ↦ le_of_not_gt fun hs ↦ ?_) ?_
· replace hs : 2 < s.length := ENat.coe_lt_coe.mp (WithBot.coe_lt_coe.mp hs)
let s := s.take ⟨3, by cutsat⟩
have : NeZero s.length := ⟨three_ne_zero⟩
have h1 : ⊥ < (s 1).asIdeal := bot_le.trans_lt (s.step 0)
obtain hmax | ⟨p, hp, hsp⟩ := (Ideal.isPrime_nat_iff.mp (s 1).2).resolve_left h1.ne'
· exact (le_maximalIdeal_of_isPrime (s 2).asIdeal).not_gt (hmax.symm.trans_lt (s.step 1))
obtain hmax | ⟨q, hq, hsq⟩ :=
(Ideal.isPrime_nat_iff.mp (s 2).2).resolve_left (h1.trans (s.step 1)).ne'
· exact (le_maximalIdeal_of_isPrime (s 3).asIdeal).not_gt (hmax.symm.trans_lt (s.step 2))
· exact hq.not_isUnit <| (Ideal.span_singleton_lt_span_singleton.mp
((hsp.symm.trans_lt (s.step 1)).trans_eq hsq)).isUnit_of_irreducible_right hp
· refine le_iSup_of_le ⟨2, ![⊥, ⟨_, (span_singleton_prime two_ne_zero).mpr <| Nat.prime_iff.mp
Nat.prime_two⟩, ⟨_, (maximalIdeal.isMaximal ℕ).isPrime⟩], fun i ↦ ?_⟩ le_rfl
fin_cases i
· exact bot_lt_iff_ne_bot.mpr (Ideal.span_singleton_eq_bot.not.mpr two_ne_zero)
· simp_rw [Nat.maximalIdeal_eq_span_two_three]
exact SetLike.lt_iff_le_and_exists.mpr ⟨Ideal.span_mono (by simp),
3, Ideal.subset_span (by simp), Ideal.mem_span_singleton.not.mpr <| by simp⟩ |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/AssociatedPrime.lean | import Mathlib.RingTheory.Ideal.AssociatedPrime.Basic
import Mathlib.Tactic.Linter.DeprecatedModule
deprecated_module (since := "2025-04-20") |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Colon.lean | import Mathlib.Algebra.Ring.Action.Pointwise.Set
import Mathlib.LinearAlgebra.Quotient.Defs
import Mathlib.RingTheory.Ideal.Maps
/-!
# The colon ideal
This file defines `Submodule.colon N P` as the ideal of all elements `r : R` such that `r • P ⊆ N`.
The normal notation for this would be `N : P` which has already been taken by type theory.
-/
namespace Submodule
open Pointwise
variable {R M : Type*}
section Semiring
variable [Semiring R] [AddCommMonoid M] [Module R M]
variable {N N₁ N₂ P P₁ P₂ : Submodule R M}
/-- `N.colon P` is the ideal of all elements `r : R` such that `r • P ⊆ N`. -/
def colon (N P : Submodule R M) : Ideal R where
carrier := {r : R | (r • P : Set M) ⊆ N}
add_mem' ha hb :=
(Set.add_smul_subset _ _ _).trans ((Set.add_subset_add ha hb).trans_eq (by simp))
zero_mem' := by simp [Set.zero_smul_set P.nonempty]
smul_mem' r := by
simp only [Set.mem_setOf_eq, smul_eq_mul, mul_smul, Set.smul_set_subset_iff]
intro x hx y hy
exact N.smul_mem _ (hx hy)
theorem mem_colon {r} : r ∈ N.colon P ↔ ∀ p ∈ P, r • p ∈ N := Set.smul_set_subset_iff
instance (priority := low) : (N.colon P).IsTwoSided where
mul_mem_of_left {r} s hr p hp := by
obtain ⟨p, hp, rfl⟩ := hp
exact hr ⟨_, P.smul_mem _ hp, (mul_smul ..).symm⟩
@[simp]
theorem colon_top {I : Ideal R} [I.IsTwoSided] : I.colon ⊤ = I := by
simp_rw [SetLike.ext_iff, mem_colon, smul_eq_mul]
exact fun x ↦ ⟨fun h ↦ mul_one x ▸ h 1 trivial, fun h _ _ ↦ I.mul_mem_right _ h⟩
@[simp]
theorem colon_bot : colon ⊥ N = N.annihilator := by
simp_rw [SetLike.ext_iff, mem_colon, mem_annihilator, mem_bot, forall_const]
theorem colon_mono (hn : N₁ ≤ N₂) (hp : P₁ ≤ P₂) : N₁.colon P₂ ≤ N₂.colon P₁ := fun _ hrnp =>
mem_colon.2 fun p₁ hp₁ => hn <| mem_colon.1 hrnp p₁ <| hp hp₁
theorem _root_.Ideal.le_colon {I J : Ideal R} [I.IsTwoSided] : I ≤ I.colon J := by
calc I = I.colon ⊤ := colon_top.symm
_ ≤ I.colon J := colon_mono (le_refl I) le_top
end Semiring
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
variable {N P : Submodule R M}
theorem mem_colon' {r} : r ∈ N.colon P ↔ P ≤ comap (r • (LinearMap.id : M →ₗ[R] M)) N :=
mem_colon
theorem iInf_colon_iSup (ι₁ : Sort*) (f : ι₁ → Submodule R M) (ι₂ : Sort*)
(g : ι₂ → Submodule R M) : (⨅ i, f i).colon (⨆ j, g j) = ⨅ (i) (j), (f i).colon (g j) :=
le_antisymm (le_iInf fun _ => le_iInf fun _ => colon_mono (iInf_le _ _) (le_iSup _ _)) fun _ H =>
mem_colon'.2 <|
iSup_le fun j =>
map_le_iff_le_comap.1 <|
le_iInf fun i =>
map_le_iff_le_comap.2 <|
mem_colon'.1 <|
have := (mem_iInf _).1 H i
have := (mem_iInf _).1 this j
this
@[simp]
theorem mem_colon_singleton {x : M} {r : R} : r ∈ N.colon (Submodule.span R {x}) ↔ r • x ∈ N :=
calc
r ∈ N.colon (Submodule.span R {x}) ↔ ∀ a : R, r • a • x ∈ N := by
simp [Submodule.mem_colon, Submodule.mem_span_singleton]
_ ↔ r • x ∈ N := by simp_rw [fun (a : R) ↦ smul_comm r a x]; exact SetLike.forall_smul_mem_iff
@[simp]
theorem _root_.Ideal.mem_colon_singleton {I : Ideal R} {x r : R} :
r ∈ I.colon (Ideal.span {x}) ↔ r * x ∈ I := by
simp only [← Ideal.submodule_span_eq, Submodule.mem_colon_singleton, smul_eq_mul]
end CommSemiring
section Ring
variable [Ring R] [AddCommGroup M] [Module R M]
variable {N P : Submodule R M}
@[simp]
lemma annihilator_map_mkQ_eq_colon : annihilator (P.map N.mkQ) = N.colon P := by
ext
rw [mem_annihilator, mem_colon]
exact ⟨fun H p hp ↦ (Quotient.mk_eq_zero N).1 (H (Quotient.mk p) (mem_map_of_mem hp)),
fun H _ ⟨p, hp, hpm⟩ ↦ hpm ▸ ((Quotient.mk_eq_zero N).2 <| H p hp)⟩
theorem annihilator_quotient : Module.annihilator R (M ⧸ N) = N.colon ⊤ := by
simp_rw [SetLike.ext_iff, Module.mem_annihilator, ← annihilator_map_mkQ_eq_colon, mem_annihilator,
map_top, LinearMap.range_eq_top.mpr (mkQ_surjective N), mem_top, forall_true_left,
forall_const]
theorem _root_.Ideal.annihilator_quotient {I : Ideal R} [I.IsTwoSided] :
Module.annihilator R (R ⧸ I) = I := by
rw [Submodule.annihilator_quotient, colon_top]
end Ring
end Submodule |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/KrullsHeightTheorem.lean | import Mathlib.RingTheory.HopkinsLevitzki
import Mathlib.RingTheory.Ideal.Height
import Mathlib.RingTheory.Localization.Submodule
import Mathlib.RingTheory.Nakayama
/-!
# Krull's Height Theorem
In this file, we prove **Krull's principal ideal theorem** (also known as
**Krullscher Hauptidealsatz**), and **Krull's height theorem** (also known as
**Krullscher Höhensatz**).
## Main Results
* `Ideal.height_le_one_of_isPrincipal_of_mem_minimalPrimes` : This theorem is the
**Krull's principal ideal theorem** (also known as **Krullscher Hauptidealsatz**), which states
that: In a commutative Noetherian ring `R`, any prime ideal that is minimal over a principal ideal
has height at most 1.
* `Ideal.height_le_spanRank_toENat_of_mem_minimal_primes` : This theorem is the
**Krull's height theorem** (also known as **Krullscher Höhensatz**), which states that:
In a commutative Noetherian ring `R`, any prime ideal that is minimal over an ideal generated by
`n` elements has height at most `n`.
* `Ideal.height_le_spanRank_toENat` : This theorem is a corollary of the **Krull's height theorem**
(also known as **Krullscher Höhensatz**). In a commutative Noetherian ring `R`, the height of
a (finitely-generated) ideal is smaller than or equal to the minimum number of generators for
this ideal.
* `Ideal.height_le_iff_exists_minimal_primes` : In a commutative Noetherian ring `R`, a prime ideal
`p` has height no greater than `n` if and only if it is a minimal ideal over some ideal generated
by no more than `n` elements.
-/
variable {R : Type*} [CommRing R] [IsNoetherianRing R]
lemma IsLocalRing.quotient_artinian_of_mem_minimalPrimes_of_isLocalRing
[IsLocalRing R] (I : Ideal R) (hp : IsLocalRing.maximalIdeal R ∈ I.minimalPrimes) :
IsArtinianRing (R ⧸ I) :=
have : Ring.KrullDimLE 0 (R ⧸ I) := Ring.krullDimLE_zero_iff.mpr fun J prime ↦
Ideal.isMaximal_of_isIntegral_of_isMaximal_comap _ <| by
convert IsLocalRing.maximalIdeal.isMaximal R
rw [Ideal.minimalPrimes, Set.mem_setOf] at hp
have := prime.comap (Ideal.Quotient.mk I)
exact hp.eq_of_le ⟨this, .trans (by simp) (Ideal.ker_le_comap _)⟩ (le_maximalIdeal this.1)
IsNoetherianRing.isArtinianRing_of_krullDimLE_zero
lemma Ideal.height_le_one_of_isPrincipal_of_mem_minimalPrimes_of_isLocalRing
[IsLocalRing R] (I : Ideal R) [I.IsPrincipal]
(hp : (IsLocalRing.maximalIdeal R) ∈ I.minimalPrimes) :
(IsLocalRing.maximalIdeal R).height ≤ 1 := by
refine Ideal.height_le_iff.mpr fun q h₁ h₂ ↦ ?_
suffices q.height = 0 by rw [this]; exact zero_lt_one
rw [← WithBot.coe_inj,
← IsLocalization.AtPrime.ringKrullDim_eq_height q (Localization.AtPrime q),
WithBot.coe_zero, ← ringKrullDimZero_iff_ringKrullDim_eq_zero,
← isArtinianRing_iff_krullDimLE_zero, isArtinianRing_iff_isNilpotent_maximalIdeal,
← Localization.AtPrime.map_eq_maximalIdeal]
have : IsArtinianRing (R ⧸ I) :=
IsLocalRing.quotient_artinian_of_mem_minimalPrimes_of_isLocalRing I hp
let f := algebraMap R (Localization.AtPrime q)
let qs : ℕ →o (Ideal (R ⧸ I))ᵒᵈ :=
{ toFun n := ((q.map f ^ n).comap f).map (Ideal.Quotient.mk I)
monotone' i j e := Ideal.map_mono (Ideal.comap_mono (Ideal.pow_le_pow_right e)) }
obtain ⟨n, hn⟩ := IsArtinian.monotone_stabilizes qs
refine ⟨n, ?_⟩
apply Submodule.eq_bot_of_le_smul_of_le_jacobson_bot (q.map f) _ (IsNoetherian.noetherian _)
rotate_left
· rw [IsLocalRing.jacobson_eq_maximalIdeal, Localization.AtPrime.map_eq_maximalIdeal]
exact bot_ne_top
rw [smul_eq_mul, ← pow_succ',
← (IsLocalization.orderEmbedding q.primeCompl (Localization.AtPrime q)).map_rel_iff]
refine Submodule.le_of_le_smul_of_le_jacobson_bot (I := I) (IsNoetherian.noetherian _) ?_ ?_
· rw [IsLocalRing.jacobson_eq_maximalIdeal]
exacts [hp.1.2, bot_ne_top]
· replace hn := congr(Ideal.comap (Ideal.Quotient.mk I) $(hn _ n.le_succ))
simp only [qs, OrderHom.coe_mk, ← RingHom.ker_eq_comap_bot, Ideal.mk_ker,
Ideal.comap_map_of_surjective _ Ideal.Quotient.mk_surjective] at hn
intro x hx
obtain ⟨y, hy, z, hz, rfl⟩ := Submodule.mem_sup.mp (hn.le (Ideal.mem_sup_left hx))
refine Submodule.add_mem_sup hy ?_
obtain ⟨z, rfl⟩ := (Submodule.IsPrincipal.mem_iff_eq_smul_generator I).mp hz
rw [smul_eq_mul, smul_eq_mul, mul_comm]
refine Ideal.mul_mem_mul ?_ (Submodule.IsPrincipal.generator_mem _)
dsimp [IsLocalization.orderEmbedding] at hx
rwa [Ideal.mem_comap, f.map_add, f.map_mul, Ideal.add_mem_iff_right _
(Ideal.pow_le_pow_right n.le_succ hy), mul_comm, Ideal.unit_mul_mem_iff_mem] at hx
refine IsLocalization.map_units (M := q.primeCompl) _ ⟨_, ?_⟩
change Submodule.IsPrincipal.generator I ∉ (↑q : Set R)
rw [← Set.singleton_subset_iff, ← Ideal.span_le, Ideal.span_singleton_generator]
exact fun e ↦ h₂.not_ge (hp.2 ⟨h₁, e⟩ h₂.le)
/-- **Krull's principal ideal theorem** (also known as **Krullscher Hauptidealsatz**) :
In a commutative Noetherian ring `R`, any prime ideal that is minimal over a principal ideal
has height at most 1. -/
lemma Ideal.height_le_one_of_isPrincipal_of_mem_minimalPrimes
(I : Ideal R) [I.IsPrincipal] (p : Ideal R) (hp : p ∈ I.minimalPrimes) : p.height ≤ 1 := by
have := hp.1.1
let f := algebraMap R (Localization.AtPrime p)
have := Ideal.height_le_one_of_isPrincipal_of_mem_minimalPrimes_of_isLocalRing (I.map f) ?_
· rwa [← IsLocalization.height_comap p.primeCompl,
Localization.AtPrime.comap_maximalIdeal] at this
· rwa [IsLocalization.minimalPrimes_map p.primeCompl (Localization.AtPrime p) I,
Set.mem_preimage, Localization.AtPrime.comap_maximalIdeal]
theorem Ideal.map_height_le_one_of_mem_minimalPrimes {I p : Ideal R} {x : R}
(hp : p ∈ (I ⊔ span {x}).minimalPrimes) : (p.map (Ideal.Quotient.mk I)).height ≤ 1 :=
let f := Ideal.Quotient.mk I
have : p.IsPrime := hp.1.1
have hfp : RingHom.ker f ≤ p := I.mk_ker.trans_le (le_sup_left.trans hp.1.2)
height_le_one_of_isPrincipal_of_mem_minimalPrimes ((span {x}).map f) (p.map f)
⟨⟨map_isPrime_of_surjective Quotient.mk_surjective hfp, map_mono (le_sup_right.trans hp.1.2)⟩,
fun _ ⟨hr, hxr⟩ hrp ↦ map_le_iff_le_comap.mpr <| hp.2 ⟨hr.comap f, sup_le_iff.mpr
⟨I.mk_ker.symm.trans_le <| ker_le_comap (Ideal.Quotient.mk I), le_comap_of_map_le hxr⟩⟩ <|
(comap_mono hrp).trans <| Eq.le <|
(p.comap_map_of_surjective _ Quotient.mk_surjective).trans <| sup_eq_left.mpr hfp⟩
/-- If `q < p` are prime ideals such that `p` is minimal over `span (s ∪ {x})` and
`t` is a set contained in `q` such that `s ⊆ √span (t ∪ {x})`, then `q` is minimal over `span t`.
This is used in the induction step for the proof of Krull's height theorem. -/
theorem Ideal.mem_minimalPrimes_span_of_mem_minimalPrimes_span_insert {q p : Ideal R} [q.IsPrime]
(hqp : q < p) (x : R) (s : Set R) (hp : p ∈ (span (insert x s)).minimalPrimes)
(t : Set R) (htq : t ⊆ q) (hsp : s ⊆ (span (insert x t)).radical) :
q ∈ (span t).minimalPrimes := by
let f := Quotient.mk (span t)
have hf : Function.Surjective f := Quotient.mk_surjective
have hI'q : span t ≤ q := span_le.mpr htq
have hI'p : span t ≤ p := hI'q.trans hqp.le
have := minimalPrimes_isPrime hp
have : (p.map f).IsPrime := map_isPrime_of_surjective hf (by rwa [mk_ker])
suffices h : (p.map f).height ≤ 1 by
have h_lt : q.map f < p.map f := (map_mono hqp.le).lt_of_not_ge fun e ↦ hqp.not_ge <| by
simpa only [comap_map_of_surjective f hf, ← RingHom.ker_eq_comap_bot, f, mk_ker,
sup_eq_left.mpr hI'q, sup_eq_left.mpr hI'p] using comap_mono (f := f) e
have : (q.map f).IsPrime := map_isPrime_of_surjective hf (by rwa [mk_ker])
have : (p.map f).FiniteHeight := ⟨Or.inr (h.trans_lt (WithTop.coe_lt_top 1)).ne⟩
rw [height_eq_primeHeight] at h
have := (primeHeight_strict_mono h_lt).trans_le h
rw [ENat.lt_one_iff_eq_zero, primeHeight_eq_zero_iff] at this
have := minimal_primes_comap_of_surjective hf this
rwa [comap_map_of_surjective f hf, ← RingHom.ker_eq_comap_bot,
mk_ker, sup_eq_left.mpr hI'q] at this
refine height_le_one_of_isPrincipal_of_mem_minimalPrimes ((span {x}).map f) (p.map f) ⟨⟨this,
map_mono <| span_le.mpr <| Set.singleton_subset_iff.mpr <| hp.1.2 <| subset_span <| .inl rfl⟩,
fun r ⟨hr, hxr⟩ hrp ↦ map_le_iff_le_comap.mpr (hp.2 ⟨hr.comap f, ?_⟩ ?_)⟩
· rw [span_le, Set.insert_subset_iff]
have := map_le_iff_le_comap.mp hxr (subset_span rfl)
refine ⟨this, hsp.trans ((hr.comap f).isRadical.radical_le_iff.mpr ?_)⟩
rw [span_le, Set.insert_subset_iff]
exact ⟨this, span_le.mp (mk_ker.symm.trans_le (ker_le_comap _))⟩
· conv_rhs => rw [← sup_eq_left.mpr hI'p, ← (span t).mk_ker, RingHom.ker_eq_comap_bot,
← comap_map_of_surjective f hf p]
exact comap_mono hrp
open IsLocalRing in
/-- **Krull's height theorem** (also known as **Krullscher Höhensatz**) :
In a commutative Noetherian ring `R`, any prime ideal that is minimal over an ideal generated
by `n` elements has height at most `n`. -/
nonrec lemma Ideal.height_le_spanRank_toENat_of_mem_minimal_primes
(I : Ideal R) (p : Ideal R) (hp : p ∈ I.minimalPrimes) :
p.height ≤ I.spanRank.toENat := by
classical
rw [I.spanRank_toENat_eq_iInf_finset_card, le_iInf_iff]
rintro ⟨s, (rfl : span s = I)⟩
induction hn : s.card using Nat.strong_induction_on generalizing R with
| h n H =>
replace hn : s.card ≤ n := hn.le
have := hp.1.1
cases n with
| zero =>
rw [ENat.coe_zero, nonpos_iff_eq_zero, height_eq_primeHeight p,
primeHeight_eq_zero_iff, minimalPrimes]
simp_all
| succ n =>
wlog hR : ∃ (_ : IsLocalRing R), p = maximalIdeal R
· rw [← Localization.AtPrime.comap_maximalIdeal (I := p)] at hp ⊢
rw [IsLocalization.height_comap p.primeCompl]
rw [← Set.mem_preimage, ← IsLocalization.minimalPrimes_map p.primeCompl, map_span] at hp
exact this _ (s.image (algebraMap R (Localization p.primeCompl))) (by simpa using hp)
inferInstance _ H (Finset.card_image_le.trans hn) ⟨inferInstance, rfl⟩
obtain ⟨_, rfl⟩ := hR
simp_rw [height_le_iff_covBy, ENat.coe_add, ENat.coe_one, ENat.lt_coe_add_one_iff]
intro q hq hpq hq'
obtain ⟨x, s', hxs', rfl, hxq⟩ : ∃ x s', x ∉ s' ∧ s = insert x s' ∧ x ∉ q := by
have : ¬(s : Set R) ⊆ q := by
rw [← span_le]
exact fun e ↦ lt_irrefl _ ((hp.2 ⟨hq, e⟩ hpq.le).trans_lt hpq)
obtain ⟨x, hxt, hxq⟩ := Set.not_subset.mp this
exact ⟨x, _, fun e ↦ (Finset.mem_erase.mp e).1 rfl, (Finset.insert_erase hxt).symm, hxq⟩
have : maximalIdeal R ≤ (q ⊔ span {x}).radical := by
rw [radical_eq_sInf, le_sInf_iff]
exact fun J ⟨hJ, hJ'⟩ ↦ by_contra fun h ↦ hq' J hJ' ((SetLike.lt_iff_le_and_exists.mpr
⟨le_sup_left, x, mem_sup_right (mem_span_singleton_self _), hxq⟩).trans_le hJ)
((le_maximalIdeal hJ'.ne_top).lt_of_not_ge h)
have h : (s' : Set R) ⊆ (q ⊔ span {x}).radical := by
have := hp.1.2.trans this
rw [span_le, Finset.coe_insert, Set.insert_subset_iff] at this
exact this.2
obtain ⟨t, ht, hspan⟩ := exists_subset_radical_span_sup_of_subset_radical_sup _ _ _ h
let t := Finset.univ.image t
suffices hq : q ∈ (span t).minimalPrimes from
have tcard : t.card ≤ n := Nat.le_of_lt_succ ((Finset.card_image_le.trans_lt <| by
simpa using Finset.card_lt_card (Finset.ssubset_insert hxs')).trans_le hn)
(H _ (tcard.trans_lt n.lt_succ_self) q t hq rfl).trans (by norm_cast)
rw [Finset.coe_insert] at hp
convert mem_minimalPrimes_span_of_mem_minimalPrimes_span_insert hpq _ _ hp _ ht ?_
· simp [t]
refine hspan.trans <| radical_mono ?_
rw [← Set.union_singleton, span_union]
/-- In a commutative Noetherian ring `R`, the height of a (finitely-generated) ideal is smaller
than or equal to the minimum number of generators for this ideal. -/
lemma Ideal.height_le_spanRank_toENat (I : Ideal R) (hI : I ≠ ⊤) :
I.height ≤ I.spanRank.toENat := by
obtain ⟨J, hJ⟩ := nonempty_minimalPrimes hI
refine (iInf₂_le J hJ).trans ?_
convert (I.height_le_spanRank_toENat_of_mem_minimal_primes J hJ)
exact Eq.symm (@height_eq_primeHeight _ _ J hJ.1.1)
lemma Ideal.height_le_spanFinrank (I : Ideal R) (hI : I ≠ ⊤) :
I.height ≤ I.spanFinrank := by
have : I.spanFinrank = I.spanRank.toENat := by
rw [Submodule.fg_iff_spanRank_eq_spanFinrank.mpr (IsNoetherian.noetherian I), map_natCast]
exact this ▸ height_le_spanRank_toENat I hI
lemma Ideal.height_le_spanRank (I : Ideal R) (hI : I ≠ ⊤) :
I.height ≤ I.spanRank := by
trans ↑I.spanRank.toENat
· exact_mod_cast I.height_le_spanRank_toENat hI
· exact I.spanRank.ofENat_toENat_le
instance Ideal.finiteHeight_of_isNoetherianRing (I : Ideal R) :
I.FiniteHeight := finiteHeight_iff_lt.mpr <| Or.elim (em (I = ⊤)) Or.inl
fun h ↦ Or.inr <| (I.height_le_spanFinrank h).trans_lt (ENat.coe_lt_top _)
instance [IsNoetherianRing R] [IsLocalRing R] : FiniteRingKrullDim R := by
apply finiteRingKrullDim_iff_ne_bot_and_top.mpr
rw [← IsLocalRing.maximalIdeal_height_eq_ringKrullDim]
constructor
· exact WithBot.coe_ne_bot
· rw [← WithBot.coe_top, ne_eq, WithBot.coe_inj]
exact ((IsLocalRing.maximalIdeal R).finiteHeight_iff.mp
(IsLocalRing.maximalIdeal R).finiteHeight_of_isNoetherianRing).resolve_left
Ideal.IsPrime.ne_top'
lemma Ideal.exists_spanRank_eq_and_height_eq (I : Ideal R) (hI : I ≠ ⊤) :
∃ J ≤ I, J.spanRank = I.height ∧ J.height = I.height := by
obtain ⟨J, hJ₁, hJ₂, hJ₃⟩ := exists_spanRank_le_and_le_height_of_le_height I _
(ENat.coe_toNat_le_self I.height)
rw [ENat.coe_toNat_eq_self.mpr (Ideal.height_ne_top hI)] at hJ₃
refine ⟨J, hJ₁, le_antisymm ?_ (le_trans ?_ (J.height_le_spanRank ?_)),
le_antisymm (Ideal.height_mono hJ₁) hJ₃⟩
· convert hJ₂
exact Cardinal.ofENat_eq_nat.mpr (ENat.coe_toNat (I.height_ne_top hI)).symm
· exact Cardinal.ofENat_le_ofENat_of_le hJ₃
· rintro rfl
exact hI (top_le_iff.mp hJ₁)
/-- In a commutative Noetherian ring `R`, a prime ideal `p` has height no greater than `n` if and
only if it is a minimal ideal over some ideal generated by no more than `n` elements. -/
lemma Ideal.height_le_iff_exists_minimalPrimes (p : Ideal R) [p.IsPrime]
(n : ℕ∞) : p.height ≤ n ↔ ∃ I : Ideal R, p ∈ I.minimalPrimes ∧ I.spanRank ≤ n := by
constructor
· intro h
obtain ⟨I, hI, e₁, e₂⟩ := exists_spanRank_eq_and_height_eq p (IsPrime.ne_top ‹_›)
refine ⟨I, Ideal.mem_minimalPrimes_of_height_eq hI e₂.ge, e₁.symm ▸ ?_⟩
norm_cast
· rintro ⟨I, hp, hI⟩
exact le_trans
(Ideal.height_le_spanRank_toENat_of_mem_minimal_primes I p hp)
(by simpa using (Cardinal.toENat.monotone' hI))
/-- If `p` is a prime in a Noetherian ring `R`, there exists a `p`-primary ideal `I`
spanned by `p.height` elements. -/
lemma Ideal.exists_finset_card_eq_height_of_isNoetherianRing (p : Ideal R) [p.IsPrime] :
∃ s : Finset R, p ∈ (span s).minimalPrimes ∧ s.card = p.height := by
obtain ⟨I, hI, hr⟩ := (p.height_le_iff_exists_minimalPrimes <| p.height).mp le_rfl
have hs : I.generators.Finite := (IsNoetherian.noetherian I).finite_generators
refine ⟨hs.toFinset, by rwa [hs.coe_toFinset, span, I.span_generators], ?_⟩
rw [← Set.ncard_eq_toFinset_card (hs := hs), (IsNoetherian.noetherian I).generators_ncard]
refine le_antisymm ?_ ?_
· rw [Submodule.fg_iff_spanRank_eq_spanFinrank.mpr (IsNoetherian.noetherian I)] at hr
exact Cardinal.nat_le_ofENat.mp hr
· convert_to p.height ≤ I.spanRank.toENat
· symm
simpa [Submodule.fg_iff_spanRank_eq_spanFinrank] using (IsNoetherian.noetherian I)
· exact I.height_le_spanRank_toENat_of_mem_minimal_primes _ hI |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Maps.lean | import Mathlib.Data.DFinsupp.Module
import Mathlib.RingTheory.Ideal.Operations
/-!
# Maps on modules and ideals
Main definitions include `Ideal.map`, `Ideal.comap`, `RingHom.ker`, `Module.annihilator`
and `Submodule.annihilator`.
-/
assert_not_exists Module.Basis -- See `RingTheory.Ideal.Basis`
Submodule.hasQuotient -- See `RingTheory.Ideal.Quotient.Operations`
universe u v w x
open Pointwise
namespace Ideal
section MapAndComap
variable {R : Type u} {S : Type v}
section Semiring
variable {F : Type*} [Semiring R] [Semiring S]
variable [FunLike F R S]
variable (f : F)
variable {I J : Ideal R} {K L : Ideal S}
/-- `I.map f` is the span of the image of the ideal `I` under `f`, which may be bigger than
the image itself. -/
def map (I : Ideal R) : Ideal S :=
span (f '' I)
/-- `I.comap f` is the preimage of `I` under `f`. -/
def comap [RingHomClass F R S] (I : Ideal S) : Ideal R where
carrier := f ⁻¹' I
add_mem' {x y} hx hy := by
simp only [Set.mem_preimage, SetLike.mem_coe, map_add f] at hx hy ⊢
exact add_mem hx hy
zero_mem' := by simp only [Set.mem_preimage, map_zero, SetLike.mem_coe, Submodule.zero_mem]
smul_mem' c x hx := by
simp only [smul_eq_mul, Set.mem_preimage, map_mul, SetLike.mem_coe] at *
exact mul_mem_left I _ hx
@[simp]
theorem coe_comap [RingHomClass F R S] (I : Ideal S) : (comap f I : Set R) = f ⁻¹' I := rfl
lemma comap_coe [RingHomClass F R S] (I : Ideal S) : I.comap (f : R →+* S) = I.comap f := rfl
lemma map_coe [RingHomClass F R S] (I : Ideal R) : I.map (f : R →+* S) = I.map f := rfl
variable {f}
theorem map_mono (h : I ≤ J) : map f I ≤ map f J :=
span_mono <| Set.image_mono h
theorem mem_map_of_mem (f : F) {I : Ideal R} {x : R} (h : x ∈ I) : f x ∈ map f I :=
subset_span ⟨x, h, rfl⟩
theorem apply_coe_mem_map (f : F) (I : Ideal R) (x : I) : f x ∈ I.map f :=
mem_map_of_mem f x.2
theorem map_le_iff_le_comap [RingHomClass F R S] : map f I ≤ K ↔ I ≤ comap f K :=
span_le.trans Set.image_subset_iff
@[simp]
theorem mem_comap [RingHomClass F R S] {x} : x ∈ comap f K ↔ f x ∈ K :=
Iff.rfl
theorem comap_mono [RingHomClass F R S] (h : K ≤ L) : comap f K ≤ comap f L :=
Set.preimage_mono fun _ hx => h hx
variable (f)
theorem comap_ne_top [RingHomClass F R S] (hK : K ≠ ⊤) : comap f K ≠ ⊤ :=
(ne_top_iff_one _).2 <| by rw [mem_comap, map_one]; exact (ne_top_iff_one _).1 hK
lemma exists_ideal_comap_le_prime {S} [CommSemiring S] [FunLike F R S] [RingHomClass F R S]
{f : F} (P : Ideal R) [P.IsPrime] (I : Ideal S) (le : I.comap f ≤ P) :
∃ Q ≥ I, Q.IsPrime ∧ Q.comap f ≤ P :=
have ⟨Q, hQ, hIQ, disj⟩ := I.exists_le_prime_disjoint (P.primeCompl.map f) <|
Set.disjoint_left.mpr fun _ ↦ by rintro hI ⟨r, hp, rfl⟩; exact hp (le hI)
⟨Q, hIQ, hQ, fun r hp' ↦ of_not_not fun hp ↦ Set.disjoint_left.mp disj hp' ⟨_, hp, rfl⟩⟩
variable {G : Type*} [FunLike G S R]
theorem map_le_comap_of_inv_on [RingHomClass G S R] (g : G) (I : Ideal R)
(hf : Set.LeftInvOn g f I) :
I.map f ≤ I.comap g := by
refine Ideal.span_le.2 ?_
rintro x ⟨x, hx, rfl⟩
rw [SetLike.mem_coe, mem_comap, hf hx]
exact hx
theorem comap_le_map_of_inv_on [RingHomClass F R S] (g : G) (I : Ideal S)
(hf : Set.LeftInvOn g f (f ⁻¹' I)) :
I.comap f ≤ I.map g :=
fun x (hx : f x ∈ I) => hf hx ▸ Ideal.mem_map_of_mem g hx
/-- The `Ideal` version of `Set.image_subset_preimage_of_inverse`. -/
theorem map_le_comap_of_inverse [RingHomClass G S R] (g : G) (I : Ideal R)
(h : Function.LeftInverse g f) :
I.map f ≤ I.comap g :=
map_le_comap_of_inv_on _ _ _ <| h.leftInvOn _
variable [RingHomClass F R S]
instance (priority := low) [K.IsTwoSided] : (comap f K).IsTwoSided :=
⟨fun b ha ↦ by rw [mem_comap, map_mul]; exact mul_mem_right _ _ ha⟩
/-- The `Ideal` version of `Set.preimage_subset_image_of_inverse`. -/
theorem comap_le_map_of_inverse (g : G) (I : Ideal S) (h : Function.LeftInverse g f) :
I.comap f ≤ I.map g :=
comap_le_map_of_inv_on _ _ _ <| h.leftInvOn _
instance IsPrime.comap [hK : K.IsPrime] : (comap f K).IsPrime :=
⟨comap_ne_top _ hK.1, fun {x y} => by simp only [mem_comap, map_mul]; apply hK.2⟩
variable (I J K L)
theorem map_top : map f ⊤ = ⊤ :=
(eq_top_iff_one _).2 <| subset_span ⟨1, trivial, map_one f⟩
theorem gc_map_comap : GaloisConnection (Ideal.map f) (Ideal.comap f) := fun _ _ =>
Ideal.map_le_iff_le_comap
@[simp]
theorem comap_id : I.comap (RingHom.id R) = I :=
Ideal.ext fun _ => Iff.rfl
@[simp]
lemma comap_idₐ {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] (I : Ideal S) :
Ideal.comap (AlgHom.id R S) I = I :=
I.comap_id
@[simp]
theorem map_id : I.map (RingHom.id R) = I :=
(gc_map_comap (RingHom.id R)).l_unique GaloisConnection.id comap_id
@[simp]
lemma map_idₐ {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] (I : Ideal S) :
Ideal.map (AlgHom.id R S) I = I :=
I.map_id
theorem comap_comap {T : Type*} [Semiring T] {I : Ideal T} (f : R →+* S) (g : S →+* T) :
(I.comap g).comap f = I.comap (g.comp f) :=
rfl
lemma comap_comapₐ {R A B C : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B]
[Algebra R B] [Semiring C] [Algebra R C] {I : Ideal C} (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(I.comap g).comap f = I.comap (g.comp f) :=
I.comap_comap f.toRingHom g.toRingHom
theorem map_map {T : Type*} [Semiring T] {I : Ideal R} (f : R →+* S) (g : S →+* T) :
(I.map f).map g = I.map (g.comp f) :=
((gc_map_comap f).compose (gc_map_comap g)).l_unique (gc_map_comap (g.comp f)) fun _ =>
comap_comap _ _
lemma map_mapₐ {R A B C : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B]
[Algebra R B] [Semiring C] [Algebra R C] {I : Ideal A} (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(I.map f).map g = I.map (g.comp f) :=
I.map_map f.toRingHom g.toRingHom
theorem map_span (f : F) (s : Set R) : map f (span s) = span (f '' s) := by
refine (Submodule.span_eq_of_le _ ?_ ?_).symm
· rintro _ ⟨x, hx, rfl⟩; exact mem_map_of_mem f (subset_span hx)
· rw [map_le_iff_le_comap, span_le, coe_comap, ← Set.image_subset_iff]
exact subset_span
variable {f I J K L}
theorem map_le_of_le_comap : I ≤ K.comap f → I.map f ≤ K :=
(gc_map_comap f).l_le
theorem le_comap_of_map_le : I.map f ≤ K → I ≤ K.comap f :=
(gc_map_comap f).le_u
theorem le_comap_map : I ≤ (I.map f).comap f :=
(gc_map_comap f).le_u_l _
theorem map_comap_le : (K.comap f).map f ≤ K :=
(gc_map_comap f).l_u_le _
@[simp]
theorem comap_top : (⊤ : Ideal S).comap f = ⊤ :=
(gc_map_comap f).u_top
@[simp]
theorem comap_eq_top_iff {I : Ideal S} : I.comap f = ⊤ ↔ I = ⊤ :=
⟨fun h => I.eq_top_iff_one.mpr (map_one f ▸ mem_comap.mp ((I.comap f).eq_top_iff_one.mp h)),
fun h => by rw [h, comap_top]⟩
@[simp]
theorem map_bot : (⊥ : Ideal R).map f = ⊥ :=
(gc_map_comap f).l_bot
theorem ne_bot_of_map_ne_bot (hI : map f I ≠ ⊥) : I ≠ ⊥ :=
fun h => hI (Eq.mpr (congrArg (fun I ↦ map f I = ⊥) h) map_bot)
variable (f I J K L)
@[simp]
theorem map_comap_map : ((I.map f).comap f).map f = I.map f :=
(gc_map_comap f).l_u_l_eq_l I
@[simp]
theorem comap_map_comap : ((K.comap f).map f).comap f = K.comap f :=
(gc_map_comap f).u_l_u_eq_u K
theorem map_sup : (I ⊔ J).map f = I.map f ⊔ J.map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup
theorem comap_inf : comap f (K ⊓ L) = comap f K ⊓ comap f L :=
rfl
variable {ι : Sort*}
theorem map_iSup (K : ι → Ideal R) : (iSup K).map f = ⨆ i, (K i).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup
theorem comap_iInf (K : ι → Ideal S) : (iInf K).comap f = ⨅ i, (K i).comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf
theorem map_sSup (s : Set (Ideal R)) : (sSup s).map f = ⨆ I ∈ s, (I : Ideal R).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sSup
theorem comap_sInf (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ s, (I : Ideal S).comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_sInf
theorem comap_sInf' (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ comap f '' s, I :=
_root_.trans (comap_sInf f s) (by rw [iInf_image])
/-- Variant of `Ideal.IsPrime.comap` where ideal is explicit rather than implicit. -/
theorem comap_isPrime [H : IsPrime K] : IsPrime (comap f K) :=
H.comap f
variable {I J K L}
theorem map_inf_le : map f (I ⊓ J) ≤ map f I ⊓ map f J :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_l.map_inf_le _ _
theorem le_comap_sup : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_u.le_map_sup _ _
-- TODO: Should these be simp lemmas?
theorem _root_.element_smul_restrictScalars {R S M}
[CommSemiring R] [CommSemiring S] [Algebra R S] [AddCommMonoid M]
[Module R M] [Module S M] [IsScalarTower R S M] (r : R) (N : Submodule S M) :
(algebraMap R S r • N).restrictScalars R = r • N.restrictScalars R :=
SetLike.coe_injective (congrArg (· '' _) (funext (algebraMap_smul S r)))
theorem smul_restrictScalars {R S M} [CommSemiring R] [CommSemiring S]
[Algebra R S] [AddCommMonoid M] [Module R M] [Module S M]
[IsScalarTower R S M] (I : Ideal R) (N : Submodule S M) :
(I.map (algebraMap R S) • N).restrictScalars R = I • N.restrictScalars R := by
simp_rw [map, Submodule.span_smul_eq, ← Submodule.coe_set_smul,
Submodule.set_smul_eq_iSup, ← element_smul_restrictScalars, iSup_image]
exact map_iSup₂ (Submodule.restrictScalarsLatticeHom R S M) _
@[simp]
theorem smul_top_eq_map {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S]
(I : Ideal R) : I • (⊤ : Submodule R S) = (I.map (algebraMap R S)).restrictScalars R :=
Eq.trans (smul_restrictScalars I (⊤ : Ideal S)).symm <|
congrArg _ <| Eq.trans (Ideal.smul_eq_mul _ _) (Ideal.mul_top _)
@[simp]
theorem coe_restrictScalars {R S : Type*} [Semiring R] [Semiring S] [Module R S]
[IsScalarTower R S S] (I : Ideal S) : (I.restrictScalars R : Set S) = ↑I :=
rfl
/-- The smallest `S`-submodule that contains all `x ∈ I * y ∈ J`
is also the smallest `R`-submodule that does so. -/
@[simp]
theorem restrictScalars_mul {R S : Type*} [Semiring R] [Semiring S] [Module R S]
[IsScalarTower R S S] (I J : Ideal S) :
(I * J).restrictScalars R = I.restrictScalars R * J.restrictScalars R :=
rfl
section Surjective
section
variable (hf : Function.Surjective f)
include hf
open Function
theorem map_comap_of_surjective (I : Ideal S) : map f (comap f I) = I :=
le_antisymm (map_le_iff_le_comap.2 le_rfl) fun s hsi =>
let ⟨r, hfrs⟩ := hf s
hfrs ▸ (mem_map_of_mem f <| show f r ∈ I from hfrs.symm ▸ hsi)
/-- `map` and `comap` are adjoint, and the composition `map f ∘ comap f` is the
identity -/
def giMapComap : GaloisInsertion (map f) (comap f) :=
GaloisInsertion.monotoneIntro (gc_map_comap f).monotone_u (gc_map_comap f).monotone_l
(fun _ => le_comap_map) (map_comap_of_surjective _ hf)
theorem map_surjective_of_surjective : Surjective (map f) :=
(giMapComap f hf).l_surjective
theorem comap_injective_of_surjective : Injective (comap f) :=
(giMapComap f hf).u_injective
theorem map_sup_comap_of_surjective (I J : Ideal S) : (I.comap f ⊔ J.comap f).map f = I ⊔ J :=
(giMapComap f hf).l_sup_u _ _
theorem map_iSup_comap_of_surjective (K : ι → Ideal S) : (⨆ i, (K i).comap f).map f = iSup K :=
(giMapComap f hf).l_iSup_u _
theorem map_inf_comap_of_surjective (I J : Ideal S) : (I.comap f ⊓ J.comap f).map f = I ⊓ J :=
(giMapComap f hf).l_inf_u _ _
theorem map_iInf_comap_of_surjective (K : ι → Ideal S) : (⨅ i, (K i).comap f).map f = iInf K :=
(giMapComap f hf).l_iInf_u _
theorem mem_image_of_mem_map_of_surjective {I : Ideal R} {y} (H : y ∈ map f I) : y ∈ f '' I :=
Submodule.span_induction (hx := H) (fun _ => id) ⟨0, I.zero_mem, map_zero f⟩
(fun _ _ _ _ ⟨x1, hx1i, hxy1⟩ ⟨x2, hx2i, hxy2⟩ =>
⟨x1 + x2, I.add_mem hx1i hx2i, hxy1 ▸ hxy2 ▸ map_add f _ _⟩)
fun c _ _ ⟨x, hxi, hxy⟩ =>
let ⟨d, hdc⟩ := hf c
⟨d * x, I.mul_mem_left _ hxi, hdc ▸ hxy ▸ map_mul f _ _⟩
theorem mem_map_iff_of_surjective {I : Ideal R} {y} : y ∈ map f I ↔ ∃ x, x ∈ I ∧ f x = y :=
⟨fun h => (Set.mem_image _ _ _).2 (mem_image_of_mem_map_of_surjective f hf h), fun ⟨_, hx⟩ =>
hx.right ▸ mem_map_of_mem f hx.left⟩
theorem le_map_of_comap_le_of_surjective : comap f K ≤ I → K ≤ map f I := fun h =>
map_comap_of_surjective f hf K ▸ map_mono h
end
theorem map_comap_eq_self_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
(I : Ideal S) : map e (comap e I) = I :=
I.map_comap_of_surjective e (EquivLike.surjective e)
theorem map_eq_submodule_map (f : R →+* S) [h : RingHomSurjective f] (I : Ideal R) :
I.map f = Submodule.map f.toSemilinearMap I :=
Submodule.ext fun _ => mem_map_iff_of_surjective f h.1
instance (priority := low) (f : R →+* S) [RingHomSurjective f] (I : Ideal R) [I.IsTwoSided] :
(I.map f).IsTwoSided where
mul_mem_of_left b ha := by
rw [map_eq_submodule_map] at ha ⊢
obtain ⟨a, ha, rfl⟩ := ha
obtain ⟨b, rfl⟩ := f.surjective b
rw [RingHom.coe_toSemilinearMap, ← map_mul]
exact ⟨_, I.mul_mem_right _ ha, rfl⟩
open Function in
theorem IsMaximal.comap_piEvalRingHom {ι : Type*} {R : ι → Type*} [∀ i, Semiring (R i)]
{i : ι} {I : Ideal (R i)} (h : I.IsMaximal) : (I.comap <| Pi.evalRingHom R i).IsMaximal := by
refine isMaximal_iff.mpr ⟨I.ne_top_iff_one.mp h.ne_top, fun J x le hxI hxJ ↦ ?_⟩
have ⟨r, y, hy, eq⟩ := h.exists_inv hxI
classical
convert J.add_mem (J.mul_mem_left (update 0 i r) hxJ)
(b := update 1 i y) (le <| by apply update_self i y 1 ▸ hy)
ext j
obtain rfl | ne := eq_or_ne j i
· simpa [eq_comm] using eq
· simp [update_of_ne ne]
theorem comap_le_comap_iff_of_surjective (hf : Function.Surjective f) (I J : Ideal S) :
comap f I ≤ comap f J ↔ I ≤ J :=
⟨fun h => (map_comap_of_surjective f hf I).symm.le.trans (map_le_of_le_comap h), fun h =>
le_comap_of_map_le ((map_comap_of_surjective f hf I).le.trans h)⟩
/-- The map on ideals induced by a surjective map preserves inclusion. -/
def orderEmbeddingOfSurjective (hf : Function.Surjective f) : Ideal S ↪o Ideal R where
toFun := comap f
inj' _ _ eq := SetLike.ext' (Set.preimage_injective.mpr hf <| SetLike.ext'_iff.mp eq)
map_rel_iff' := comap_le_comap_iff_of_surjective _ hf ..
theorem map_eq_top_or_isMaximal_of_surjective (hf : Function.Surjective f) {I : Ideal R}
(H : IsMaximal I) : map f I = ⊤ ∨ IsMaximal (map f I) :=
or_iff_not_imp_left.2 fun ne_top ↦ ⟨⟨ne_top, fun _J hJ ↦ comap_injective_of_surjective f hf <|
H.1.2 _ (le_comap_map.trans_lt <| (orderEmbeddingOfSurjective f hf).strictMono hJ)⟩⟩
end Surjective
section Pi
variable {ι : Type*} {R : ι → Type*} [∀ i, Semiring (R i)]
theorem map_evalRingHom_pi {I : Π i, Ideal (R i)} (i : ι) :
(pi I).map (Pi.evalRingHom R i) = I i := by
ext r
rw [mem_map_iff_of_surjective (Pi.evalRingHom R i) (Function.surjective_eval _)]
classical refine ⟨?_, fun hr ↦ ⟨_, single_mem_pi hr, by simp⟩⟩
rintro ⟨r, hr, rfl⟩
exact hr i
/-- Ideals in a finite direct product semiring `Πᵢ Rᵢ` are identified with tuples of ideals
in the individual semirings, in an order-preserving way.
(Note that this is not in general true for infinite direct products:
If infinitely many of the `Rᵢ` are nontrivial, then there exists an ideal of `Πᵢ Rᵢ` that
is not of the form `Πᵢ Iᵢ`, namely the ideal of finitely supported elements of `Πᵢ Rᵢ`
(it is also not a principal ideal).) -/
@[simps!] def piOrderIso [Finite ι] : Ideal (Π i, R i) ≃o Π i, Ideal (R i) := .symm
{ toFun := pi
invFun I i := I.map (Pi.evalRingHom R i)
left_inv _ := funext map_evalRingHom_pi
right_inv I := by
ext r
simp_rw [mem_pi, mem_map_iff_of_surjective (Pi.evalRingHom R _) (Function.surjective_eval _)]
refine ⟨(fun ⟨r', hr'⟩ ↦ ?_) ∘ Classical.skolem.mp, fun hr i ↦ ⟨r, hr, rfl⟩⟩
have := Fintype.ofFinite ι
classical rw [show r = ∑ i, Pi.single i 1 * r' i from funext fun i ↦ by
rw [← (hr' _).2, Finset.sum_apply, Fintype.sum_eq_single i fun j ne ↦ by simp [ne]]; simp]
exact sum_mem fun i _ ↦ I.mul_mem_left _ (hr' i).1
map_rel_iff' := pi_le_pi_iff }
instance [Finite ι] [∀ i, IsPrincipalIdealRing (R i)] : IsPrincipalIdealRing (Π i, R i) where
principal I := by
rw [← piOrderIso.symm_apply_apply I]
exact ⟨_, congr(pi $(funext fun i ↦
(Submodule.IsPrincipal.span_singleton_generator _).symm)).trans pi_span⟩
end Pi
section Injective
theorem comap_bot_le_of_injective (hf : Function.Injective f) : comap f ⊥ ≤ I := by
refine le_trans (fun x hx => ?_) bot_le
rw [mem_comap, Submodule.mem_bot, ← map_zero f] at hx
exact Eq.symm (hf hx) ▸ Submodule.zero_mem ⊥
theorem comap_bot_of_injective (hf : Function.Injective f) : Ideal.comap f ⊥ = ⊥ :=
le_bot_iff.mp (Ideal.comap_bot_le_of_injective f hf)
end Injective
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm (map f I) = I`. -/
@[simp]
theorem map_of_equiv {I : Ideal R} (f : R ≃+* S) :
(I.map (f : R →+* S)).map (f.symm : S →+* R) = I := by
rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, map_map,
RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, map_id]
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`,
then `comap f (comap f.symm I) = I`. -/
@[simp]
theorem comap_of_equiv {I : Ideal R} (f : R ≃+* S) :
(I.comap (f.symm : S →+* R)).comap (f : R →+* S) = I := by
rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, comap_comap,
RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, comap_id]
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f I = comap f.symm I`. -/
theorem map_comap_of_equiv {I : Ideal R} (f : R ≃+* S) : I.map (f : R →+* S) = I.comap f.symm :=
le_antisymm (Ideal.map_le_comap_of_inverse _ _ _ (Equiv.left_inv' _))
(Ideal.comap_le_map_of_inverse _ _ _ (Equiv.right_inv' _))
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `comap f.symm I = map f I`. -/
@[simp]
theorem comap_symm {I : Ideal R} (f : R ≃+* S) : I.comap f.symm = I.map f :=
(map_comap_of_equiv f).symm
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm I = comap f I`. -/
@[simp]
theorem map_symm {I : Ideal S} (f : R ≃+* S) : I.map f.symm = I.comap f :=
map_comap_of_equiv (RingEquiv.symm f)
@[simp]
theorem symm_apply_mem_of_equiv_iff {I : Ideal R} {f : R ≃+* S} {y : S} :
f.symm y ∈ I ↔ y ∈ I.map f := by
rw [← comap_symm, mem_comap]
@[simp]
theorem apply_mem_of_equiv_iff {I : Ideal R} {f : R ≃+* S} {x : R} :
f x ∈ I.map f ↔ x ∈ I := by
rw [← comap_symm, Ideal.mem_comap, f.symm_apply_apply]
theorem mem_map_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{I : Ideal R} (y : S) : y ∈ map e I ↔ ∃ x ∈ I, e x = y := by
constructor
· intro h
simp_rw [show map e I = _ from map_comap_of_equiv (e : R ≃+* S)] at h
exact ⟨(e : R ≃+* S).symm y, h, (e : R ≃+* S).apply_symm_apply y⟩
· rintro ⟨x, hx, rfl⟩
exact mem_map_of_mem e hx
section Bijective
variable (hf : Function.Bijective f) {I : Ideal R} {K : Ideal S}
include hf
/-- Special case of the correspondence theorem for isomorphic rings -/
def relIsoOfBijective : Ideal S ≃o Ideal R where
toFun := comap f
invFun := map f
left_inv := map_comap_of_surjective _ hf.2
right_inv J :=
le_antisymm
(fun _ h ↦ have ⟨y, hy, eq⟩ := (mem_map_iff_of_surjective _ hf.2).mp h; hf.1 eq ▸ hy)
le_comap_map
map_rel_iff' {_ _} := by
refine ⟨fun h ↦ ?_, comap_mono⟩
have := map_mono (f := f) h
simpa only [Equiv.coe_fn_mk, map_comap_of_surjective f hf.2] using this
theorem comap_le_iff_le_map : comap f K ≤ I ↔ K ≤ map f I :=
⟨fun h => le_map_of_comap_le_of_surjective f hf.right h, fun h =>
(relIsoOfBijective f hf).right_inv I ▸ comap_mono h⟩
lemma comap_map_of_bijective : (I.map f).comap f = I :=
le_antisymm ((comap_le_iff_le_map f hf).mpr fun _ ↦ id) le_comap_map
theorem isMaximal_map_iff_of_bijective : IsMaximal (map f I) ↔ IsMaximal I := by
simpa only [isMaximal_def] using (relIsoOfBijective _ hf).symm.isCoatom_iff _
theorem isMaximal_comap_iff_of_bijective : IsMaximal (comap f K) ↔ IsMaximal K := by
simpa only [isMaximal_def] using (relIsoOfBijective _ hf).isCoatom_iff _
alias ⟨_, IsMaximal.map_bijective⟩ := isMaximal_map_iff_of_bijective
alias ⟨_, IsMaximal.comap_bijective⟩ := isMaximal_comap_iff_of_bijective
/-- A ring isomorphism sends a maximal ideal to a maximal ideal. -/
instance map_isMaximal_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{p : Ideal R} [hp : p.IsMaximal] : (map e p).IsMaximal :=
hp.map_bijective e (EquivLike.bijective e)
/-- The pullback of a maximal ideal under a ring isomorphism is a maximal ideal. -/
instance comap_isMaximal_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{p : Ideal S} [hp : p.IsMaximal] : (comap e p).IsMaximal :=
hp.comap_bijective e (EquivLike.bijective e)
theorem isMaximal_iff_of_bijective : (⊥ : Ideal R).IsMaximal ↔ (⊥ : Ideal S).IsMaximal :=
⟨fun h ↦ map_bot (f := f) ▸ h.map_bijective f hf, fun h ↦ have e := RingEquiv.ofBijective f hf
map_bot (f := e.symm) ▸ h.map_bijective _ e.symm.bijective⟩
end Bijective
end Semiring
section Ring
variable {F : Type*} [Ring R] [Ring S]
variable [FunLike F R S] [RingHomClass F R S] (f : F) {I : Ideal R}
section Surjective
theorem comap_map_of_surjective (hf : Function.Surjective f) (I : Ideal R) :
comap f (map f I) = I ⊔ comap f ⊥ :=
le_antisymm
(fun r h =>
let ⟨s, hsi, hfsr⟩ := mem_image_of_mem_map_of_surjective f hf h
Submodule.mem_sup.2
⟨s, hsi, r - s, (Submodule.mem_bot S).2 <| by rw [map_sub, hfsr, sub_self],
add_sub_cancel s r⟩)
(sup_le (map_le_iff_le_comap.1 le_rfl) (comap_mono bot_le))
/-- Correspondence theorem -/
def relIsoOfSurjective (hf : Function.Surjective f) :
Ideal S ≃o { p : Ideal R // comap f ⊥ ≤ p } where
toFun J := ⟨comap f J, comap_mono bot_le⟩
invFun I := map f I.1
left_inv J := map_comap_of_surjective f hf J
right_inv I :=
Subtype.eq <|
show comap f (map f I.1) = I.1 from
(comap_map_of_surjective f hf I).symm ▸ le_antisymm (sup_le le_rfl I.2) le_sup_left
map_rel_iff' {I1 I2} :=
⟨fun H => map_comap_of_surjective f hf I1 ▸ map_comap_of_surjective f hf I2 ▸ map_mono H,
comap_mono⟩
-- May not hold if `R` is a semiring: consider `ℕ →+* ZMod 2`.
theorem comap_isMaximal_of_surjective (hf : Function.Surjective f) {K : Ideal S} [H : IsMaximal K] :
IsMaximal (comap f K) := by
refine ⟨⟨comap_ne_top _ H.1.1, fun J hJ => ?_⟩⟩
suffices map f J = ⊤ by
have := congr_arg (comap f) this
rw [comap_top, comap_map_of_surjective _ hf, eq_top_iff] at this
rw [eq_top_iff]
exact le_trans this (sup_le (le_of_eq rfl) (le_trans (comap_mono bot_le) (le_of_lt hJ)))
refine
H.1.2 (map f J)
(lt_of_le_of_ne (le_map_of_comap_le_of_surjective _ hf (le_of_lt hJ)) fun h =>
ne_of_lt hJ (_root_.trans (congr_arg (comap f) h) ?_))
rw [comap_map_of_surjective _ hf, sup_eq_left]
exact le_trans (comap_mono bot_le) (le_of_lt hJ)
end Surjective
end Ring
section CommRing
variable {F : Type*} [CommSemiring R] [CommSemiring S]
variable [FunLike F R S] [rc : RingHomClass F R S]
variable (f : F)
variable (I J : Ideal R) (K L : Ideal S)
protected theorem map_mul {R} [Semiring R] [FunLike F R S] [RingHomClass F R S]
(f : F) (I J : Ideal R) :
map f (I * J) = map f I * map f J :=
le_antisymm
(map_le_iff_le_comap.2 <|
mul_le.2 fun r hri s hsj =>
show (f (r * s)) ∈ map f I * map f J by
rw [map_mul]; exact mul_mem_mul (mem_map_of_mem f hri) (mem_map_of_mem f hsj))
(span_mul_span (↑f '' ↑I) (↑f '' ↑J) ▸ (span_le.2 <| by
rintro _ ⟨_, ⟨r, hri, rfl⟩, _, ⟨s, hsj, rfl⟩, rfl⟩
simp_rw [← map_mul]; exact mem_map_of_mem f (mul_mem_mul hri hsj)))
/-- The pushforward `Ideal.map` as a (semi)ring homomorphism. -/
@[simps]
def mapHom : Ideal R →+* Ideal S where
toFun := map f
map_mul' := Ideal.map_mul f
map_one' := by simp only [one_eq_top, Ideal.map_top f]
map_add' I J := Ideal.map_sup f I J
map_zero' := Ideal.map_bot
protected theorem map_pow (n : ℕ) : map f (I ^ n) = map f I ^ n :=
map_pow (mapHom f) I n
theorem comap_radical : comap f (radical K) = radical (comap f K) := by
ext
simp [radical]
variable {K}
theorem IsRadical.comap (hK : K.IsRadical) : (comap f K).IsRadical := by
rw [← hK.radical, comap_radical]
apply radical_isRadical
variable {I J L}
theorem map_radical_le : map f (radical I) ≤ radical (map f I) :=
map_le_iff_le_comap.2 fun r ⟨n, hrni⟩ => ⟨n, map_pow f r n ▸ mem_map_of_mem f hrni⟩
theorem le_comap_mul : comap f K * comap f L ≤ comap f (K * L) :=
map_le_iff_le_comap.1 <|
(Ideal.map_mul f (comap f K) (comap f L)).symm ▸
mul_mono (map_le_iff_le_comap.2 <| le_rfl) (map_le_iff_le_comap.2 <| le_rfl)
theorem le_comap_pow (n : ℕ) : K.comap f ^ n ≤ (K ^ n).comap f := by
induction n with
| zero =>
rw [pow_zero, pow_zero, Ideal.one_eq_top, Ideal.one_eq_top]
exact rfl.le
| succ n n_ih =>
rw [pow_succ, pow_succ]
exact (Ideal.mul_mono_left n_ih).trans (Ideal.le_comap_mul f)
lemma disjoint_map_primeCompl_iff_comap_le {S : Type*} [Semiring S] {f : R →+* S}
{p : Ideal R} {I : Ideal S} [p.IsPrime] :
Disjoint (I : Set S) (p.primeCompl.map f) ↔ I.comap f ≤ p :=
(@Set.disjoint_image_right _ _ f p.primeCompl I).trans disjoint_compl_right_iff
/-- For a prime ideal `p` of `R`, `p` extended to `S` and
restricted back to `R` is `p` if and only if `p` is the restriction of a prime in `S`. -/
lemma comap_map_eq_self_iff_of_isPrime {S : Type*} [CommSemiring S] {f : R →+* S}
(p : Ideal R) [p.IsPrime] :
(p.map f).comap f = p ↔ (∃ (q : Ideal S), q.IsPrime ∧ q.comap f = p) := by
refine ⟨fun hp ↦ ?_, ?_⟩
· obtain ⟨q, hq₁, hq₂, hq₃⟩ := Ideal.exists_le_prime_disjoint _ _
(disjoint_map_primeCompl_iff_comap_le.mpr hp.le)
exact ⟨q, hq₁, le_antisymm (disjoint_map_primeCompl_iff_comap_le.mp hq₃)
(map_le_iff_le_comap.mp hq₂)⟩
· rintro ⟨q, hq, rfl⟩
simp
/--
For a maximal ideal `p` of `R`, `p` extended to `S` and restricted back to `R` is `p` if
its image in `S` is not equal to `⊤`.
-/
theorem comap_map_eq_self_of_isMaximal (f : R →+* S) {p : Ideal R} [hP' : p.IsMaximal]
(hP : Ideal.map f p ≠ ⊤) : (map f p).comap f = p :=
(IsCoatom.le_iff_eq hP'.out (comap_ne_top _ hP)).mp <| le_comap_map
end CommRing
end MapAndComap
end Ideal
namespace RingHom
variable {R : Type u} {S : Type v} {T : Type w}
section Semiring
variable {F : Type*} {G : Type*} [Semiring R] [Semiring S] [Semiring T]
variable [FunLike F R S] [rcf : RingHomClass F R S] [FunLike G T S] [rcg : RingHomClass G T S]
variable (f : F) (g : G)
/-- Kernel of a ring homomorphism as an ideal of the domain. -/
def ker : Ideal R :=
Ideal.comap f ⊥
instance (priority := low) : (ker f).IsTwoSided := inferInstanceAs (Ideal.comap f ⊥).IsTwoSided
variable {f} in
/-- An element is in the kernel if and only if it maps to zero. -/
@[simp] theorem mem_ker {r} : r ∈ ker f ↔ f r = 0 := by rw [ker, Ideal.mem_comap, Submodule.mem_bot]
theorem ker_eq : (ker f : Set R) = Set.preimage f {0} :=
rfl
theorem ker_eq_comap_bot (f : F) : ker f = Ideal.comap f ⊥ :=
rfl
theorem comap_ker (f : S →+* R) (g : T →+* S) : (ker f).comap g = ker (f.comp g) := by
rw [RingHom.ker_eq_comap_bot, Ideal.comap_comap, RingHom.ker_eq_comap_bot]
/-- If the target is not the zero ring, then one is not in the kernel. -/
theorem one_notMem_ker [Nontrivial S] (f : F) : (1 : R) ∉ ker f := by
rw [mem_ker, map_one]
exact one_ne_zero
@[deprecated (since := "2025-05-23")] alias not_one_mem_ker := one_notMem_ker
theorem ker_ne_top [Nontrivial S] (f : F) : ker f ≠ ⊤ :=
(Ideal.ne_top_iff_one _).mpr <| one_notMem_ker f
lemma ker_eq_top_of_subsingleton [Subsingleton S] (f : F) : ker f = ⊤ :=
eq_top_iff.mpr fun _ _ ↦ Subsingleton.elim _ _
lemma _root_.Pi.ker_ringHom {ι : Type*} {R : ι → Type*} [∀ i, Semiring (R i)]
(φ : ∀ i, S →+* R i) : ker (Pi.ringHom φ) = ⨅ i, ker (φ i) := by
ext x
simp [mem_ker, funext_iff]
@[simp]
theorem ker_rangeSRestrict (f : R →+* S) : ker f.rangeSRestrict = ker f :=
Ideal.ext fun _ ↦ Subtype.ext_iff
@[simp]
theorem ker_coe_equiv (f : R ≃+* S) : ker (f : R →+* S) = ⊥ := by
ext; simp
theorem ker_coe_toRingHom : ker (f : R →+* S) = ker f := rfl
@[simp]
theorem ker_equiv {F' : Type*} [EquivLike F' R S] [RingEquivClass F' R S] (f : F') :
ker f = ⊥ := by
ext; simp
lemma ker_equiv_comp (f : R →+* S) (e : S ≃+* T) :
ker (e.toRingHom.comp f) = RingHom.ker f := by
rw [← RingHom.comap_ker, RingEquiv.toRingHom_eq_coe, RingHom.ker_coe_equiv, RingHom.ker]
end Semiring
section Ring
variable {F : Type*} [Ring R] [Semiring S] [FunLike F R S] [rc : RingHomClass F R S] (f : F)
theorem injective_iff_ker_eq_bot : Function.Injective f ↔ ker f = ⊥ := by
rw [SetLike.ext'_iff, ker_eq, Set.ext_iff]
exact injective_iff_map_eq_zero' f
theorem ker_eq_bot_iff_eq_zero : ker f = ⊥ ↔ ∀ x, f x = 0 → x = 0 := by
rw [← injective_iff_map_eq_zero f, injective_iff_ker_eq_bot]
lemma ker_comp_of_injective [Semiring T] (g : T →+* R) {f : R →+* S} (hf : Function.Injective f) :
ker (f.comp g) = RingHom.ker g := by
rw [← RingHom.comap_ker, (injective_iff_ker_eq_bot f).mp hf, RingHom.ker]
/-- Synonym for `RingHom.ker_coe_equiv`, but given an algebra equivalence. -/
@[simp] theorem _root_.AlgHom.ker_coe_equiv {R A B : Type*} [CommSemiring R] [Semiring A]
[Semiring B] [Algebra R A] [Algebra R B] (e : A ≃ₐ[R] B) :
RingHom.ker (e : A →+* B) = ⊥ :=
RingHom.ker_coe_equiv (e.toRingEquiv)
end Ring
section RingRing
variable {F : Type*} [Ring R] [Ring S] [FunLike F R S] [rc : RingHomClass F R S] (f : F)
theorem sub_mem_ker_iff {x y} : x - y ∈ ker f ↔ f x = f y := by rw [mem_ker, map_sub, sub_eq_zero]
@[simp]
theorem ker_rangeRestrict (f : R →+* S) : ker f.rangeRestrict = ker f :=
Ideal.ext fun _ ↦ Subtype.ext_iff
end RingRing
/-- The kernel of a homomorphism to a domain is a prime ideal. -/
theorem ker_isPrime {F : Type*} [Semiring R] [Semiring S] [IsDomain S]
[FunLike F R S] [RingHomClass F R S] (f : F) :
(ker f).IsPrime :=
have := Ideal.bot_prime (α := S)
inferInstanceAs (Ideal.comap f ⊥).IsPrime
/-- The kernel of a homomorphism to a division ring is a maximal ideal. -/
theorem ker_isMaximal_of_surjective {R K F : Type*} [Ring R] [DivisionRing K]
[FunLike F R K] [RingHomClass F R K] (f : F)
(hf : Function.Surjective f) : (ker f).IsMaximal :=
have := Ideal.bot_isMaximal (K := K)
Ideal.comap_isMaximal_of_surjective _ hf
end RingHom
section annihilator
section Semiring
variable {R M M' : Type*}
variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
variable (R M) in
/-- `Module.annihilator R M` is the ideal of all elements `r : R` such that `r • M = 0`. -/
def Module.annihilator : Ideal R := RingHom.ker (Module.toAddMonoidEnd R M)
theorem Module.mem_annihilator {r} : r ∈ Module.annihilator R M ↔ ∀ m : M, r • m = 0 :=
⟨fun h ↦ (congr($h ·)), (AddMonoidHom.ext ·)⟩
instance (priority := low) : (Module.annihilator R M).IsTwoSided :=
inferInstanceAs (RingHom.ker _).IsTwoSided
theorem LinearMap.annihilator_le_of_injective (f : M →ₗ[R] M') (hf : Function.Injective f) :
Module.annihilator R M' ≤ Module.annihilator R M := fun x h ↦ by
rw [Module.mem_annihilator] at h ⊢; exact fun m ↦ hf (by rw [map_smul, h, f.map_zero])
theorem LinearMap.annihilator_le_of_surjective (f : M →ₗ[R] M')
(hf : Function.Surjective f) : Module.annihilator R M ≤ Module.annihilator R M' := fun x h ↦ by
rw [Module.mem_annihilator] at h ⊢
intro m; obtain ⟨m, rfl⟩ := hf m
rw [← map_smul, h, f.map_zero]
theorem LinearEquiv.annihilator_eq (e : M ≃ₗ[R] M') :
Module.annihilator R M = Module.annihilator R M' :=
(e.annihilator_le_of_surjective e.surjective).antisymm (e.annihilator_le_of_injective e.injective)
theorem Module.comap_annihilator {R₀} [CommSemiring R₀] [Module R₀ M]
[Algebra R₀ R] [IsScalarTower R₀ R M] :
(Module.annihilator R M).comap (algebraMap R₀ R) = Module.annihilator R₀ M := by
ext x
simp [mem_annihilator]
lemma Module.annihilator_eq_bot {R M} [Ring R] [AddCommGroup M] [Module R M] :
Module.annihilator R M = ⊥ ↔ FaithfulSMul R M := by
rw [← le_bot_iff]
refine ⟨fun H ↦ ⟨fun {r s} H' ↦ ?_⟩, fun ⟨H⟩ {a} ha ↦ ?_⟩
· rw [← sub_eq_zero]
exact H (Module.mem_annihilator (r := r - s).mpr
(by simp only [sub_smul, H', sub_self, implies_true]))
· exact @H a 0 (by simp [Module.mem_annihilator.mp ha])
theorem Module.annihilator_eq_top_iff : annihilator R M = ⊤ ↔ Subsingleton M :=
⟨fun h ↦ ⟨fun m m' ↦ by
rw [← one_smul R m, ← one_smul R m']
simp_rw [mem_annihilator.mp (h ▸ Submodule.mem_top)]⟩,
fun _ ↦ top_le_iff.mp fun _ _ ↦ mem_annihilator.mpr fun _ ↦ Subsingleton.elim _ _⟩
theorem Module.annihilator_prod : annihilator R (M × M') = annihilator R M ⊓ annihilator R M' := by
ext
simp_rw [Ideal.mem_inf, mem_annihilator,
Prod.forall, Prod.smul_mk, Prod.mk_eq_zero, forall_and_left, ← forall_and_right]
theorem Module.annihilator_finsupp {ι : Type*} [Nonempty ι] :
annihilator R (ι →₀ M) = annihilator R M := by
ext r; simp_rw [mem_annihilator]
constructor <;> intro h
· refine Nonempty.elim ‹_› fun i : ι ↦ ?_
simpa using fun m ↦ congr($(h (Finsupp.single i m)) i)
· intro m; ext i; exact h _
section
variable {ι : Type*} {M : ι → Type*} [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
theorem Module.annihilator_dfinsupp : annihilator R (Π₀ i, M i) = ⨅ i, annihilator R (M i) := by
ext r; simp only [mem_annihilator, Ideal.mem_iInf]
constructor <;> intro h
· intro i m
classical simpa using DFunLike.congr_fun (h (DFinsupp.single i m)) i
· intro m; ext i; exact h i _
theorem Module.annihilator_pi : annihilator R (Π i, M i) = ⨅ i, annihilator R (M i) := by
ext r; simp only [mem_annihilator, Ideal.mem_iInf]
constructor <;> intro h
· intro i m
classical simpa using congr_fun (h (Pi.single i m)) i
· intro m; ext i; exact h i _
end
namespace Submodule
/-- `N.annihilator` is the ideal of all elements `r : R` such that `r • N = 0`. -/
abbrev annihilator (N : Submodule R M) : Ideal R :=
Module.annihilator R N
theorem annihilator_top : (⊤ : Submodule R M).annihilator = Module.annihilator R M :=
topEquiv.annihilator_eq
variable {I J : Ideal R} {N P : Submodule R M}
theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0 : M) := by
simp_rw [annihilator, Module.mem_annihilator, Subtype.forall, Subtype.ext_iff]; rfl
theorem annihilator_bot : (⊥ : Submodule R M).annihilator = ⊤ :=
top_le_iff.mp fun _ _ ↦ mem_annihilator.mpr fun _ ↦ by rintro rfl; rw [smul_zero]
theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ := by
rw [annihilator, Module.annihilator_eq_top_iff, Submodule.subsingleton_iff_eq_bot]
theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator := fun _ hrp =>
mem_annihilator.2 fun n hn => mem_annihilator.1 hrp n <| h hn
theorem annihilator_iSup (ι : Sort w) (f : ι → Submodule R M) :
annihilator (⨆ i, f i) = ⨅ i, annihilator (f i) :=
le_antisymm (le_iInf fun _ => annihilator_mono <| le_iSup _ _) fun r H =>
mem_annihilator.2 fun n hn ↦ iSup_induction f (motive := (r • · = 0)) hn
(fun i ↦ mem_annihilator.1 <| (mem_iInf _).mp H i) (smul_zero _)
fun m₁ m₂ h₁ h₂ ↦ by simp_rw [smul_add, h₁, h₂, add_zero]
theorem le_annihilator_iff {N : Submodule R M} {I : Ideal R} : I ≤ annihilator N ↔ I • N = ⊥ := by
simp_rw [← le_bot_iff, smul_le, SetLike.le_def, mem_annihilator]; rfl
@[simp]
theorem annihilator_smul (N : Submodule R M) : annihilator N • N = ⊥ :=
eq_bot_iff.2 (smul_le.2 fun _ => mem_annihilator.1)
@[simp]
theorem annihilator_mul (I : Ideal R) : annihilator I * I = ⊥ :=
annihilator_smul I
end Submodule
end Semiring
namespace Submodule
variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] {N : Submodule R M}
theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • (LinearMap.id : M →ₗ[R] M)) ⊥ :=
mem_annihilator.trans ⟨fun H n hn => (mem_bot R).2 <| H n hn, fun H _ hn => (mem_bot R).1 <| H hn⟩
theorem mem_annihilator_span (s : Set M) (r : R) :
r ∈ (Submodule.span R s).annihilator ↔ ∀ n : s, r • (n : M) = 0 := by
rw [Submodule.mem_annihilator]
constructor
· intro h n
exact h _ (Submodule.subset_span n.prop)
· intro h n hn
refine Submodule.span_induction ?_ ?_ ?_ ?_ hn
· intro x hx
exact h ⟨x, hx⟩
· exact smul_zero _
· intro x y _ _ hx hy
rw [smul_add, hx, hy, zero_add]
· intro a x _ hx
rw [smul_comm, hx, smul_zero]
theorem mem_annihilator_span_singleton (g : M) (r : R) :
r ∈ (Submodule.span R ({g} : Set M)).annihilator ↔ r • g = 0 := by simp [mem_annihilator_span]
open LinearMap in
theorem annihilator_span (s : Set M) :
(Submodule.span R s).annihilator = ⨅ g : s, ker (toSpanSingleton R M g.1) := by
ext; simp [mem_annihilator_span]
open LinearMap in
theorem annihilator_span_singleton (g : M) :
(Submodule.span R {g}).annihilator = ker (toSpanSingleton R M g) := by
simp [annihilator_span]
@[simp]
theorem mul_annihilator (I : Ideal R) : I * annihilator I = ⊥ := by rw [mul_comm, annihilator_mul]
end Submodule
end annihilator
namespace Ideal
variable {R : Type*} {S : Type*} {F : Type*}
section Semiring
variable [Semiring R] [Semiring S] [FunLike F R S] [rc : RingHomClass F R S]
theorem map_eq_bot_iff_le_ker {I : Ideal R} (f : F) : I.map f = ⊥ ↔ I ≤ RingHom.ker f := by
rw [RingHom.ker, eq_bot_iff, map_le_iff_le_comap]
theorem ker_le_comap {K : Ideal S} (f : F) : RingHom.ker f ≤ comap f K := fun _ hx =>
mem_comap.2 (RingHom.mem_ker.1 hx ▸ K.zero_mem)
/-- A ring isomorphism sends a prime ideal to a prime ideal. -/
instance map_isPrime_of_equiv {F' : Type*} [EquivLike F' R S] [RingEquivClass F' R S]
(f : F') {I : Ideal R} [IsPrime I] : IsPrime (map f I) := by
have h : I.map f = I.map ((f : R ≃+* S) : R →+* S) := rfl
rw [h, map_comap_of_equiv (f : R ≃+* S)]
exact Ideal.IsPrime.comap (RingEquiv.symm (f : R ≃+* S))
theorem map_eq_bot_iff_of_injective {I : Ideal R} {f : F} (hf : Function.Injective f) :
I.map f = ⊥ ↔ I = ⊥ := by
simp [map, span_eq_bot, ← map_zero f, -map_zero, hf.eq_iff, I.eq_bot_iff]
end Semiring
section Ring
variable [Ring R] [Ring S] [FunLike F R S] [rc : RingHomClass F R S]
lemma comap_map_of_surjective' (f : F) (hf : Function.Surjective f) (I : Ideal R) :
(I.map f).comap f = I ⊔ RingHom.ker f :=
comap_map_of_surjective f hf I
theorem map_sInf {A : Set (Ideal R)} {f : F} (hf : Function.Surjective f) :
(∀ J ∈ A, RingHom.ker f ≤ J) → map f (sInf A) = sInf (map f '' A) := by
refine fun h => le_antisymm (le_sInf ?_) ?_
· intro j hj y hy
obtain ⟨x, hx⟩ := (mem_map_iff_of_surjective f hf).1 hy
obtain ⟨J, hJ⟩ := (Set.mem_image _ _ _).mp hj
rw [← hJ.right, ← hx.right]
exact mem_map_of_mem f (sInf_le_of_le hJ.left (le_of_eq rfl) hx.left)
· intro y hy
obtain ⟨x, hx⟩ := hf y
refine hx ▸ mem_map_of_mem f ?_
have : ∀ I ∈ A, y ∈ map f I := by simpa using hy
rw [Submodule.mem_sInf]
intro J hJ
rcases (mem_map_iff_of_surjective f hf).1 (this J hJ) with ⟨x', hx', rfl⟩
have : x - x' ∈ J := by
apply h J hJ
rw [RingHom.mem_ker, map_sub, hx, sub_self]
simpa only [sub_add_cancel] using J.add_mem this hx'
theorem map_isPrime_of_surjective {f : F} (hf : Function.Surjective f) {I : Ideal R} [H : IsPrime I]
(hk : RingHom.ker f ≤ I) : IsPrime (map f I) := by
refine ⟨fun h => H.ne_top (eq_top_iff.2 ?_), fun {x y} => ?_⟩
· replace h := congr_arg (comap f) h
rw [comap_map_of_surjective _ hf, comap_top] at h
exact h ▸ sup_le (le_of_eq rfl) hk
· refine fun hxy => (hf x).recOn fun a ha => (hf y).recOn fun b hb => ?_
rw [← ha, ← hb, ← map_mul f, mem_map_iff_of_surjective _ hf] at hxy
rcases hxy with ⟨c, hc, hc'⟩
rw [← sub_eq_zero, ← map_sub] at hc'
have : a * b ∈ I := by
convert I.sub_mem hc (hk (hc' : c - a * b ∈ RingHom.ker f)) using 1
abel
exact
(H.mem_or_mem this).imp (fun h => ha ▸ mem_map_of_mem f h) fun h => hb ▸ mem_map_of_mem f h
lemma IsMaximal.map_of_surjective_of_ker_le {f : F} (hf : Function.Surjective f) {m : Ideal R}
[m.IsMaximal] (hk : RingHom.ker f ≤ m) : (m.map f).IsMaximal := by
refine m.map_eq_top_or_isMaximal_of_surjective f hf ‹_› |>.resolve_left fun h => ?_
apply congr_arg (comap f) at h
rw [comap_map_of_surjective _ hf, comap_top, ← RingHom.ker_eq_comap_bot, sup_of_le_left hk] at h
exact IsMaximal.ne_top ‹_› h
end Ring
section CommRing
variable [CommRing R] [CommRing S]
theorem map_ne_bot_of_ne_bot {S : Type*} [Ring S] [Nontrivial S] [Algebra R S]
[NoZeroSMulDivisors R S] {I : Ideal R} (h : I ≠ ⊥) : map (algebraMap R S) I ≠ ⊥ :=
(map_eq_bot_iff_of_injective (FaithfulSMul.algebraMap_injective R S)).mp.mt h
theorem map_eq_iff_sup_ker_eq_of_surjective {I J : Ideal R} (f : R →+* S)
(hf : Function.Surjective f) : map f I = map f J ↔ I ⊔ RingHom.ker f = J ⊔ RingHom.ker f := by
rw [← (comap_injective_of_surjective f hf).eq_iff, comap_map_of_surjective f hf,
comap_map_of_surjective f hf, RingHom.ker_eq_comap_bot]
theorem map_radical_of_surjective {f : R →+* S} (hf : Function.Surjective f) {I : Ideal R}
(h : RingHom.ker f ≤ I) : map f I.radical = (map f I).radical := by
rw [radical_eq_sInf, radical_eq_sInf]
have : ∀ J ∈ {J : Ideal R | I ≤ J ∧ J.IsPrime}, RingHom.ker f ≤ J := fun J hJ => h.trans hJ.left
convert map_sInf hf this
refine funext fun j => propext ⟨?_, ?_⟩
· rintro ⟨hj, hj'⟩
haveI : j.IsPrime := hj'
exact
⟨comap f j, ⟨⟨map_le_iff_le_comap.1 hj, comap_isPrime f j⟩, map_comap_of_surjective f hf j⟩⟩
· rintro ⟨J, ⟨hJ, hJ'⟩⟩
haveI : J.IsPrime := hJ.right
exact ⟨hJ' ▸ map_mono hJ.left, hJ' ▸ map_isPrime_of_surjective hf (le_trans h hJ.left)⟩
end CommRing
end Ideal
namespace RingHom
variable {A B C : Type*} [Ring A] [Ring B] [Ring C]
variable (f : A →+* B) (f_inv : B → A)
/-- Auxiliary definition used to define `liftOfRightInverse` -/
def liftOfRightInverseAux (hf : Function.RightInverse f_inv f) (g : A →+* C)
(hg : RingHom.ker f ≤ RingHom.ker g) :
B →+* C :=
{ AddMonoidHom.liftOfRightInverse f.toAddMonoidHom f_inv hf ⟨g.toAddMonoidHom, hg⟩ with
toFun := fun b => g (f_inv b)
map_one' := by
rw [← map_one g, ← sub_eq_zero, ← map_sub g, ← mem_ker]
apply hg
rw [mem_ker, map_sub f, sub_eq_zero, map_one f]
exact hf 1
map_mul' := by
intro x y
rw [← map_mul g, ← sub_eq_zero, ← map_sub g, ← mem_ker]
apply hg
rw [mem_ker, map_sub f, sub_eq_zero, map_mul f]
simp only [hf _] }
@[simp]
theorem liftOfRightInverseAux_comp_apply (hf : Function.RightInverse f_inv f) (g : A →+* C)
(hg : RingHom.ker f ≤ RingHom.ker g) (a : A) :
(f.liftOfRightInverseAux f_inv hf g hg) (f a) = g a :=
f.toAddMonoidHom.liftOfRightInverse_comp_apply f_inv hf ⟨g.toAddMonoidHom, hg⟩ a
/-- `liftOfRightInverse f hf g hg` is the unique ring homomorphism `φ`
* such that `φ.comp f = g` (`RingHom.liftOfRightInverse_comp`),
* where `f : A →+* B` has a right_inverse `f_inv` (`hf`),
* and `g : B →+* C` satisfies `hg : f.ker ≤ g.ker`.
See `RingHom.eq_liftOfRightInverse` for the uniqueness lemma.
```
A .
| \
f | \ g
| \
v \⌟
B ----> C
∃!φ
```
-/
def liftOfRightInverse (hf : Function.RightInverse f_inv f) :
{ g : A →+* C // RingHom.ker f ≤ RingHom.ker g } ≃ (B →+* C) where
toFun g := f.liftOfRightInverseAux f_inv hf g.1 g.2
invFun φ := ⟨φ.comp f, fun x hx => mem_ker.mpr <| by simp [mem_ker.mp hx]⟩
left_inv g := by
ext
simp only [comp_apply, liftOfRightInverseAux_comp_apply]
right_inv φ := by
ext b
simp [liftOfRightInverseAux, hf b]
/-- A non-computable version of `RingHom.liftOfRightInverse` for when no computable right
inverse is available, that uses `Function.surjInv`. -/
@[simp]
noncomputable abbrev liftOfSurjective (hf : Function.Surjective f) :
{ g : A →+* C // RingHom.ker f ≤ RingHom.ker g } ≃ (B →+* C) :=
f.liftOfRightInverse (Function.surjInv hf) (Function.rightInverse_surjInv hf)
theorem liftOfRightInverse_comp_apply (hf : Function.RightInverse f_inv f)
(g : { g : A →+* C // RingHom.ker f ≤ RingHom.ker g }) (x : A) :
(f.liftOfRightInverse f_inv hf g) (f x) = g.1 x :=
f.liftOfRightInverseAux_comp_apply f_inv hf g.1 g.2 x
theorem liftOfRightInverse_comp (hf : Function.RightInverse f_inv f)
(g : { g : A →+* C // RingHom.ker f ≤ RingHom.ker g }) :
(f.liftOfRightInverse f_inv hf g).comp f = g :=
RingHom.ext <| f.liftOfRightInverse_comp_apply f_inv hf g
theorem eq_liftOfRightInverse (hf : Function.RightInverse f_inv f) (g : A →+* C)
(hg : RingHom.ker f ≤ RingHom.ker g) (h : B →+* C) (hh : h.comp f = g) :
h = f.liftOfRightInverse f_inv hf ⟨g, hg⟩ := by
simp_rw [← hh]
exact ((f.liftOfRightInverse f_inv hf).apply_symm_apply _).symm
end RingHom
/-- Any ring isomorphism induces an order isomorphism of ideals. -/
@[simps apply]
def RingEquiv.idealComapOrderIso {R S : Type*} [Semiring R] [Semiring S] (e : R ≃+* S) :
Ideal S ≃o Ideal R where
toFun I := I.comap e
invFun I := I.map e
left_inv I := I.map_comap_of_surjective _ e.surjective
right_inv I := I.comap_map_of_bijective _ e.bijective
map_rel_iff' := by
simp [← Ideal.map_le_iff_le_comap, Ideal.map_comap_of_surjective _ e.surjective]
@[simp]
lemma RingEquiv.idealComapOrderIso_symm_apply
{R S : Type*} [Semiring R] [Semiring S] (e : R ≃+* S) (I : Ideal R) :
e.idealComapOrderIso.symm I = I.map e :=
rfl
namespace AlgHom
variable {R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B]
[Algebra R A] [Algebra R B] (f : A →ₐ[R] B)
lemma ker_coe : RingHom.ker f = RingHom.ker (f : A →+* B) := rfl
lemma coe_ideal_map (I : Ideal A) :
Ideal.map f I = Ideal.map (f : A →+* B) I := rfl
lemma comap_ker {C : Type*} [Semiring C] [Algebra R C] (f : B →ₐ[R] C) (g : A →ₐ[R] B) :
(RingHom.ker f).comap g = RingHom.ker (f.comp g) :=
RingHom.comap_ker f.toRingHom g.toRingHom
end AlgHom
namespace Algebra
variable {R : Type*} [CommSemiring R] (S : Type*) [Semiring S] [Algebra R S]
/-- The induced linear map from `I` to the span of `I` in an `R`-algebra `S`. -/
@[simps!]
def idealMap (I : Ideal R) : I →ₗ[R] I.map (algebraMap R S) :=
(Algebra.linearMap R S).restrict (q := (I.map (algebraMap R S)).restrictScalars R)
(fun _ ↦ Ideal.mem_map_of_mem _)
end Algebra
@[simp]
theorem FaithfulSMul.ker_algebraMap_eq_bot (R A : Type*) [CommSemiring R] [Semiring A]
[Algebra R A] [FaithfulSMul R A] : RingHom.ker (algebraMap R A) = ⊥ := by
ext; simp
section PrincipalIdeal
instance {R S : Type*} [Semiring R] [Semiring S] (f : R →+* S) (I : Ideal R) [I.IsPrincipal] :
(I.map f).IsPrincipal := by
obtain ⟨x, rfl⟩ := Submodule.IsPrincipal.principal I
exact ⟨f x, by
rw [← Ideal.span, ← Set.image_singleton, Ideal.map_span, Set.image_singleton,
Ideal.submodule_span_eq]⟩
end PrincipalIdeal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Prod.lean | import Mathlib.RingTheory.Ideal.Maps
/-!
# Ideals in product rings
For commutative rings `R` and `S` and ideals `I ≤ R`, `J ≤ S`, we define `Ideal.prod I J` as the
product `I × J`, viewed as an ideal of `R × S`. In `ideal_prod_eq` we show that every ideal of
`R × S` is of this form. Furthermore, we show that every prime ideal of `R × S` is of the form
`p × S` or `R × p`, where `p` is a prime ideal.
-/
universe u v
variable {R : Type u} {S : Type v} [Semiring R] [Semiring S] (I : Ideal R) (J : Ideal S)
namespace Ideal
/-- `I × J` as an ideal of `R × S`. -/
def prod : Ideal (R × S) := I.comap (RingHom.fst R S) ⊓ J.comap (RingHom.snd R S)
@[simp]
theorem coe_prod (I : Ideal R) (J : Ideal S) : ↑(prod I J) = (I ×ˢ J : Set (R × S)) :=
rfl
@[simp]
theorem mem_prod {x : R × S} : x ∈ prod I J ↔ x.1 ∈ I ∧ x.2 ∈ J :=
Iff.rfl
@[simp]
theorem prod_top_top : prod (⊤ : Ideal R) (⊤ : Ideal S) = ⊤ :=
Ideal.ext <| by simp
@[simp]
theorem prod_bot_bot : prod (⊥ : Ideal R) (⊥ : Ideal S) = ⊥ :=
SetLike.coe_injective <| Set.singleton_prod_singleton
@[gcongr]
theorem prod_mono {I₁ I₂ : Ideal R} {J₁ J₂ : Ideal S} (hI : I₁ ≤ I₂) (hJ : J₁ ≤ J₂) :
prod I₁ J₁ ≤ prod I₂ J₂ :=
Set.prod_mono hI hJ
theorem prod_mono_left {I₁ I₂ : Ideal R} {J : Ideal S} (hI : I₁ ≤ I₂) : prod I₁ J ≤ prod I₂ J :=
Set.prod_mono_left hI
theorem prod_mono_right {I : Ideal R} {J₁ J₂ : Ideal S} (hJ : J₁ ≤ J₂) : prod I J₁ ≤ prod I J₂ :=
Set.prod_mono_right hJ
/-- Every ideal of the product ring is of the form `I × J`, where `I` and `J` can be explicitly
given as the image under the projection maps. -/
theorem ideal_prod_eq (I : Ideal (R × S)) :
I = Ideal.prod (map (RingHom.fst R S) I : Ideal R) (map (RingHom.snd R S) I) := by
apply Ideal.ext
rintro ⟨r, s⟩
rw [mem_prod, mem_map_iff_of_surjective (RingHom.fst R S) Prod.fst_surjective,
mem_map_iff_of_surjective (RingHom.snd R S) Prod.snd_surjective]
refine ⟨fun h => ⟨⟨_, ⟨h, rfl⟩⟩, ⟨_, ⟨h, rfl⟩⟩⟩, ?_⟩
rintro ⟨⟨⟨r, s'⟩, ⟨h₁, rfl⟩⟩, ⟨⟨r', s⟩, ⟨h₂, rfl⟩⟩⟩
simpa using I.add_mem (I.mul_mem_left (1, 0) h₁) (I.mul_mem_left (0, 1) h₂)
@[simp]
theorem map_fst_prod (I : Ideal R) (J : Ideal S) : map (RingHom.fst R S) (prod I J) = I := by
ext x
rw [mem_map_iff_of_surjective (RingHom.fst R S) Prod.fst_surjective]
exact
⟨by
rintro ⟨x, ⟨h, rfl⟩⟩
exact h.1, fun h => ⟨⟨x, 0⟩, ⟨⟨h, Ideal.zero_mem _⟩, rfl⟩⟩⟩
@[simp]
theorem map_snd_prod (I : Ideal R) (J : Ideal S) : map (RingHom.snd R S) (prod I J) = J := by
ext x
rw [mem_map_iff_of_surjective (RingHom.snd R S) Prod.snd_surjective]
exact
⟨by
rintro ⟨x, ⟨h, rfl⟩⟩
exact h.2, fun h => ⟨⟨0, x⟩, ⟨⟨Ideal.zero_mem _, h⟩, rfl⟩⟩⟩
@[simp]
theorem map_prodComm_prod :
map ((RingEquiv.prodComm : R × S ≃+* S × R) : R × S →+* S × R) (prod I J) = prod J I := by
refine Trans.trans (ideal_prod_eq _) ?_
simp [map_map]
/-- Ideals of `R × S` are in one-to-one correspondence with pairs of ideals of `R` and ideals of
`S`. -/
def idealProdEquiv : Ideal (R × S) ≃o Ideal R × Ideal S where
toFun I := ⟨map (RingHom.fst R S) I, map (RingHom.snd R S) I⟩
invFun I := prod I.1 I.2
left_inv I := (ideal_prod_eq I).symm
right_inv := fun ⟨I, J⟩ => by simp
map_rel_iff' {I J} := by
simp only [Equiv.coe_fn_mk, ge_iff_le, Prod.mk_le_mk]
refine ⟨fun h ↦ ?_, fun h ↦ ⟨map_mono h, map_mono h⟩⟩
rw [ideal_prod_eq I, ideal_prod_eq J]
exact inf_le_inf (comap_mono h.1) (comap_mono h.2)
@[simp]
theorem idealProdEquiv_symm_apply (I : Ideal R) (J : Ideal S) :
idealProdEquiv.symm ⟨I, J⟩ = prod I J :=
rfl
theorem span_prod_le {s : Set R} {t : Set S} :
span (s ×ˢ t) ≤ prod (span s) (span t) := by
rw [ideal_prod_eq (span (s ×ˢ t)), map_span, map_span]
gcongr
· exact Set.fst_image_prod_subset _ _
· exact Set.snd_image_prod_subset _ _
theorem span_prod {s : Set R} {t : Set S} (hst : s.Nonempty ↔ t.Nonempty) :
span (s ×ˢ t) = prod (span s) (span t) := by
simp_rw [iff_iff_and_or_not_and_not, Set.not_nonempty_iff_eq_empty] at hst
obtain ⟨hs, ht⟩ | ⟨rfl, rfl⟩ := hst
· conv_lhs => rw [Ideal.ideal_prod_eq (Ideal.span (s ×ˢ t))]
congr 1
· rw [Ideal.map_span]
simp [Set.fst_image_prod _ ht]
· rw [Ideal.map_span]
simp [Set.snd_image_prod hs]
· simp
@[simp]
theorem prod_inj {I I' : Ideal R} {J J' : Ideal S} :
prod I J = prod I' J' ↔ I = I' ∧ J = J' := by
simp only [← idealProdEquiv_symm_apply, idealProdEquiv.symm.injective.eq_iff, Prod.mk_inj]
@[deprecated (since := "2025-05-22")] alias prod.ext_iff := prod_inj
@[simp]
theorem prod_eq_bot_iff {I : Ideal R} {J : Ideal S} :
prod I J = ⊥ ↔ I = ⊥ ∧ J = ⊥ := by
rw [← prod_inj, prod_bot_bot]
@[simp]
theorem prod_eq_top_iff {I : Ideal R} {J : Ideal S} :
prod I J = ⊤ ↔ I = ⊤ ∧ J = ⊤ := by
rw [← prod_inj, prod_top_top]
theorem isPrime_of_isPrime_prod_top {I : Ideal R} (h : (Ideal.prod I (⊤ : Ideal S)).IsPrime) :
I.IsPrime := by
constructor
· contrapose! h
rw [h, prod_top_top, isPrime_iff]
simp
· intro x y hxy
have : (⟨x, 1⟩ : R × S) * ⟨y, 1⟩ ∈ prod I ⊤ := by
rw [Prod.mk_mul_mk, mul_one, mem_prod]
exact ⟨hxy, trivial⟩
simpa using h.mem_or_mem this
theorem isPrime_of_isPrime_prod_top' {I : Ideal S} (h : (Ideal.prod (⊤ : Ideal R) I).IsPrime) :
I.IsPrime := by
apply isPrime_of_isPrime_prod_top (S := R)
rw [← map_prodComm_prod]
-- Note: couldn't synthesize the right instances without the `R` and `S` hints
exact map_isPrime_of_equiv (RingEquiv.prodComm (R := R) (S := S))
theorem isPrime_ideal_prod_top {I : Ideal R} [h : I.IsPrime] : (prod I (⊤ : Ideal S)).IsPrime where
ne_top' := by simpa using h.ne_top
mem_or_mem' {x y} := by simpa using h.mem_or_mem
theorem isPrime_ideal_prod_top' {I : Ideal S} [h : I.IsPrime] : (prod (⊤ : Ideal R) I).IsPrime := by
letI : IsPrime (prod I (⊤ : Ideal R)) := isPrime_ideal_prod_top
rw [← map_prodComm_prod]
-- Note: couldn't synthesize the right instances without the `R` and `S` hints
exact map_isPrime_of_equiv (RingEquiv.prodComm (R := S) (S := R))
theorem ideal_prod_prime_aux {I : Ideal R} {J : Ideal S} :
(Ideal.prod I J).IsPrime → I = ⊤ ∨ J = ⊤ := by
contrapose!
simp only [ne_top_iff_one, isPrime_iff, not_and, not_forall, not_or]
exact fun ⟨hI, hJ⟩ _ => ⟨⟨0, 1⟩, ⟨1, 0⟩, by simp, by simp [hJ], by simp [hI]⟩
/-- Classification of prime ideals in product rings: the prime ideals of `R × S` are precisely the
ideals of the form `p × S` or `R × p`, where `p` is a prime ideal of `R` or `S`. -/
theorem ideal_prod_prime (I : Ideal (R × S)) :
I.IsPrime ↔
(∃ p : Ideal R, p.IsPrime ∧ I = Ideal.prod p ⊤) ∨
∃ p : Ideal S, p.IsPrime ∧ I = Ideal.prod ⊤ p := by
constructor
· rw [ideal_prod_eq I]
intro hI
rcases ideal_prod_prime_aux hI with (h | h)
· right
rw [h] at hI ⊢
exact ⟨_, ⟨isPrime_of_isPrime_prod_top' hI, rfl⟩⟩
· left
rw [h] at hI ⊢
exact ⟨_, ⟨isPrime_of_isPrime_prod_top hI, rfl⟩⟩
· rintro (⟨p, ⟨h, rfl⟩⟩ | ⟨p, ⟨h, rfl⟩⟩)
· exact isPrime_ideal_prod_top
· exact isPrime_ideal_prod_top'
end Ideal
open Submodule.IsPrincipal in
instance [IsPrincipalIdealRing R] [IsPrincipalIdealRing S] : IsPrincipalIdealRing (R × S) where
principal I := by
rw [I.ideal_prod_eq, ← span_singleton_generator (I.map _),
← span_singleton_generator (I.map (RingHom.snd R S)), ← Ideal.span, ← Ideal.span,
← Ideal.span_prod (iff_of_true (by simp) (by simp)), Set.singleton_prod_singleton]
exact ⟨_, rfl⟩ |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Pointwise.lean | import Mathlib.Algebra.Ring.Action.End
import Mathlib.RingTheory.Ideal.Maps
/-! # Pointwise instances on `Ideal`s
This file provides the action `Ideal.pointwiseMulAction` which morally matches the action of
`mulActionSet` (though here an extra `Ideal.span` is inserted).
This action is available in the `Pointwise` locale.
## Implementation notes
This file is similar (but not identical) to `Mathlib/Algebra/Ring/Subsemiring/Pointwise.lean`.
Where possible, try to keep them in sync.
-/
open Set
variable {M R : Type*}
namespace Ideal
section Monoid
variable [Monoid M] [Semiring R] [MulSemiringAction M R]
/-- The action on an ideal corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale. -/
protected def pointwiseDistribMulAction : DistribMulAction M (Ideal R) where
smul a := Ideal.map (MulSemiringAction.toRingHom _ _ a)
one_smul I :=
congr_arg (I.map ·) (RingHom.ext <| one_smul M) |>.trans I.map_id
mul_smul _ _ I :=
congr_arg (I.map ·) (RingHom.ext <| mul_smul _ _) |>.trans (I.map_map _ _).symm
smul_zero _ := Ideal.map_bot
smul_add _ I J := Ideal.map_sup _ I J
scoped[Pointwise] attribute [instance] Ideal.pointwiseDistribMulAction
open Pointwise
/-- The action on an ideal corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale. -/
protected def pointwiseMulSemiringAction {R : Type*} [CommRing R] [MulSemiringAction M R] :
MulSemiringAction M (Ideal R) where
smul_one a := by simp only [Ideal.one_eq_top]; exact Ideal.map_top _
smul_mul a I J := Ideal.map_mul (MulSemiringAction.toRingHom _ _ a) I J
scoped[Pointwise] attribute [instance] Ideal.pointwiseMulSemiringAction
theorem pointwise_smul_def {a : M} (S : Ideal R) :
a • S = S.map (MulSemiringAction.toRingHom _ _ a) :=
rfl
-- note: unlike with `Subring`, `pointwise_smul_toAddSubgroup` wouldn't be true
theorem smul_mem_pointwise_smul (m : M) (r : R) (S : Ideal R) : r ∈ S → m • r ∈ m • S :=
fun h => subset_span <| Set.smul_mem_smul_set h
instance : CovariantClass M (Ideal R) HSMul.hSMul LE.le :=
⟨fun _ _ => map_mono⟩
-- note: unlike with `Subring`, `mem_smul_pointwise_iff_exists` wouldn't be true
@[simp]
theorem smul_bot (a : M) : a • (⊥ : Ideal R) = ⊥ :=
map_bot
theorem smul_sup (a : M) (S T : Ideal R) : a • (S ⊔ T) = a • S ⊔ a • T :=
map_sup _ _ _
theorem smul_closure (a : M) (s : Set R) : a • span s = span (a • s) :=
Ideal.map_span _ _
instance pointwise_central_scalar [MulSemiringAction Mᵐᵒᵖ R] [IsCentralScalar M R] :
IsCentralScalar M (Ideal R) :=
⟨fun _ S => (congr_arg fun f => S.map f) <| RingHom.ext <| op_smul_eq_smul _⟩
@[simp]
theorem pointwise_smul_toAddSubmonoid (a : M) (S : Ideal R)
(ha : Function.Surjective fun r : R => a • r) :
(a • S).toAddSubmonoid = a • S.toAddSubmonoid := by
ext
exact Ideal.mem_map_iff_of_surjective _ <| by exact ha
@[simp]
theorem pointwise_smul_toAddSubgroup {R : Type*} [Ring R] [MulSemiringAction M R]
(a : M) (S : Ideal R) (ha : Function.Surjective fun r : R => a • r) :
(a • S).toAddSubgroup = a • S.toAddSubgroup := by
ext
exact Ideal.mem_map_iff_of_surjective _ <| by exact ha
@[deprecated (since := "2025-07-08")]
alias pointwise_smul_toAddSubGroup := pointwise_smul_toAddSubgroup
end Monoid
section Group
variable [Group M] [Semiring R] [MulSemiringAction M R]
open Pointwise
theorem pointwise_smul_eq_comap {a : M} (S : Ideal R) :
a • S = S.comap (MulSemiringAction.toRingAut _ _ a).symm := by
ext
simp [pointwise_smul_def]
rfl
@[simp]
theorem smul_mem_pointwise_smul_iff {a : M} {S : Ideal R} {x : R} : a • x ∈ a • S ↔ x ∈ S :=
⟨fun h => by simpa using smul_mem_pointwise_smul a⁻¹ _ _ h, smul_mem_pointwise_smul _ _ _⟩
theorem mem_pointwise_smul_iff_inv_smul_mem {a : M} {S : Ideal R} {x : R} :
x ∈ a • S ↔ a⁻¹ • x ∈ S :=
⟨fun h => by simpa using smul_mem_pointwise_smul a⁻¹ _ _ h,
fun h => by simpa using smul_mem_pointwise_smul a _ _ h⟩
theorem mem_inv_pointwise_smul_iff {a : M} {S : Ideal R} {x : R} : x ∈ a⁻¹ • S ↔ a • x ∈ S := by
rw [mem_pointwise_smul_iff_inv_smul_mem, inv_inv]
@[simp]
theorem pointwise_smul_le_pointwise_smul_iff {a : M} {S T : Ideal R} : a • S ≤ a • T ↔ S ≤ T :=
⟨fun h => by simpa using smul_mono_right a⁻¹ h, fun h => smul_mono_right a h⟩
theorem pointwise_smul_subset_iff {a : M} {S T : Ideal R} : a • S ≤ T ↔ S ≤ a⁻¹ • T := by
rw [← pointwise_smul_le_pointwise_smul_iff (a := a⁻¹), inv_smul_smul]
theorem subset_pointwise_smul_iff {a : M} {S T : Ideal R} : S ≤ a • T ↔ a⁻¹ • S ≤ T := by
rw [← pointwise_smul_le_pointwise_smul_iff (a := a⁻¹), inv_smul_smul]
instance IsPrime.smul {I : Ideal R} [H : I.IsPrime] (g : M) : (g • I).IsPrime := by
rw [I.pointwise_smul_eq_comap]
apply H.comap
@[simp]
theorem IsPrime.smul_iff {I : Ideal R} (g : M) : (g • I).IsPrime ↔ I.IsPrime :=
⟨fun H ↦ inv_smul_smul g I ▸ H.smul g⁻¹, fun H ↦ H.smul g⟩
theorem inertia_le_stabilizer {R : Type*} [Ring R] (P : Ideal R) [MulSemiringAction M R] :
P.toAddSubgroup.inertia M ≤ MulAction.stabilizer M P := by
refine fun σ hσ ↦ SetLike.ext fun x ↦ ?_
rw [Ideal.mem_pointwise_smul_iff_inv_smul_mem,
← P.add_mem_iff_left (a := x) ((inv_mem hσ) x), add_sub_cancel]
/-! TODO: add `equivSMul` like we have for subgroup. -/
end Group
end Ideal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Over.lean | import Mathlib.Algebra.Algebra.Tower
import Mathlib.Algebra.Group.Subgroup.Actions
import Mathlib.RingTheory.Ideal.Pointwise
import Mathlib.RingTheory.Ideal.Quotient.Operations
/-!
# Ideals over/under ideals
This file concerns ideals lying over other ideals.
Let `f : R →+* S` be a ring homomorphism (typically a ring extension), `I` an ideal of `R` and
`J` an ideal of `S`. We say `J` lies over `I` (and `I` under `J`) if `I` is the `f`-preimage of `J`.
This is expressed here by writing `I = J.comap f`.
-/
-- for going-up results about integral extensions, see `Mathlib/RingTheory/Ideal/GoingUp.lean`
assert_not_exists Algebra.IsIntegral
-- for results about finiteness, see `Mathlib/RingTheory/Finiteness/Quotient.lean`
assert_not_exists Module.Finite
variable {R : Type*} [CommRing R]
namespace Ideal
open Submodule
open scoped Pointwise
section CommRing
variable {S : Type*} [CommRing S] {f : R →+* S} {I J : Ideal S}
variable {p : Ideal R} {P : Ideal S}
/-- If there is an injective map `R/p → S/P` such that following diagram commutes:
```
R → S
↓ ↓
R/p → S/P
```
then `P` lies over `p`.
-/
theorem comap_eq_of_scalar_tower_quotient [Algebra R S] [Algebra (R ⧸ p) (S ⧸ P)]
[IsScalarTower R (R ⧸ p) (S ⧸ P)] (h : Function.Injective (algebraMap (R ⧸ p) (S ⧸ P))) :
comap (algebraMap R S) P = p := by
ext x
rw [mem_comap, ← Quotient.eq_zero_iff_mem, ← Quotient.eq_zero_iff_mem, Quotient.mk_algebraMap,
IsScalarTower.algebraMap_apply R (R ⧸ p) (S ⧸ P), Quotient.algebraMap_eq]
constructor
· intro hx
exact (injective_iff_map_eq_zero (algebraMap (R ⧸ p) (S ⧸ P))).mp h _ hx
· intro hx
rw [hx, RingHom.map_zero]
variable [Algebra R S]
/-- `R / p` has a canonical map to `S / pS`. -/
instance Quotient.algebraQuotientMapQuotient : Algebra (R ⧸ p) (S ⧸ map (algebraMap R S) p) :=
Ideal.Quotient.algebraQuotientOfLEComap le_comap_map
@[simp]
theorem Quotient.algebraMap_quotient_map_quotient (x : R) :
letI f := algebraMap R S
algebraMap (R ⧸ p) (S ⧸ map f p) (Ideal.Quotient.mk p x) =
Ideal.Quotient.mk (map f p) (f x) :=
rfl
@[simp]
theorem Quotient.mk_smul_mk_quotient_map_quotient (x : R) (y : S) :
letI f := algebraMap R S
Quotient.mk p x • Quotient.mk (map f p) y = Quotient.mk (map f p) (f x * y) :=
Algebra.smul_def _ _
instance Quotient.tower_quotient_map_quotient [Algebra R S] :
IsScalarTower R (R ⧸ p) (S ⧸ map (algebraMap R S) p) :=
IsScalarTower.of_algebraMap_eq fun x => by
rw [Quotient.algebraMap_eq, Quotient.algebraMap_quotient_map_quotient,
Quotient.mk_algebraMap]
end CommRing
section ideal_liesOver
section Semiring
variable (A : Type*) [CommSemiring A] {B C : Type*} [Semiring B] [Semiring C] [Algebra A B]
[Algebra A C] (P : Ideal B) {Q : Ideal C} (p : Ideal A)
{G : Type*} [Group G] [MulSemiringAction G B] [SMulCommClass G A B] (g : G)
/-- The ideal obtained by pulling back the ideal `P` from `B` to `A`. -/
abbrev under : Ideal A := Ideal.comap (algebraMap A B) P
theorem under_def : P.under A = Ideal.comap (algebraMap A B) P := rfl
instance IsPrime.under [hP : P.IsPrime] : (P.under A).IsPrime :=
hP.comap (algebraMap A B)
@[simp]
lemma under_smul : (g • P : Ideal B).under A = P.under A := by
ext a
rw [mem_comap, mem_comap, mem_pointwise_smul_iff_inv_smul_mem, smul_algebraMap]
variable (B) in
theorem under_top : under A (⊤ : Ideal B) = ⊤ := comap_top
variable {A}
/-- `P` lies over `p` if `p` is the preimage of `P` by the `algebraMap`. -/
@[mk_iff] class LiesOver : Prop where
over : p = P.under A
instance over_under : P.LiesOver (P.under A) where over := rfl
theorem over_def [P.LiesOver p] : p = P.under A := LiesOver.over
theorem mem_of_liesOver [P.LiesOver p] (x : A) : x ∈ p ↔ algebraMap A B x ∈ P := by
rw [P.over_def p]
rfl
variable (A B) in
instance top_liesOver_top : (⊤ : Ideal B).LiesOver (⊤ : Ideal A) where
over := (under_top A B).symm
theorem eq_top_iff_of_liesOver [P.LiesOver p] : P = ⊤ ↔ p = ⊤ := by
rw [P.over_def p]
exact comap_eq_top_iff.symm
variable {P}
theorem LiesOver.of_eq_comap [Q.LiesOver p] {F : Type*} [FunLike F B C]
[AlgHomClass F A B C] (f : F) (h : P = Q.comap f) : P.LiesOver p where
over := by
rw [h]
exact (over_def Q p).trans <|
congrFun (congrFun (congrArg comap ((f : B →ₐ[A] C).comp_algebraMap.symm)) _) Q
theorem LiesOver.of_eq_map_equiv [P.LiesOver p] {E : Type*} [EquivLike E B C]
[AlgEquivClass E A B C] (σ : E) (h : Q = P.map σ) : Q.LiesOver p := by
rw [← show _ = P.map σ from comap_symm (σ : B ≃+* C)] at h
exact of_eq_comap p (σ : B ≃ₐ[A] C).symm h
variable {p} in
instance LiesOver.smul [h : P.LiesOver p] : (g • P).LiesOver p :=
⟨h.over.trans (under_smul A P g).symm⟩
variable (P) (Q)
instance comap_liesOver [Q.LiesOver p] {F : Type*} [FunLike F B C] [AlgHomClass F A B C]
(f : F) : (Q.comap f).LiesOver p :=
LiesOver.of_eq_comap p f rfl
instance map_equiv_liesOver [P.LiesOver p] {E : Type*} [EquivLike E B C] [AlgEquivClass E A B C]
(σ : E) : (P.map σ).LiesOver p :=
LiesOver.of_eq_map_equiv p σ rfl
end Semiring
section CommSemiring
variable {A : Type*} [CommSemiring A] {B : Type*} [CommSemiring B] {C : Type*} [Semiring C]
[Algebra A B] [Algebra B C] [Algebra A C] [IsScalarTower A B C]
(𝔓 : Ideal C) (P : Ideal B) (p : Ideal A)
@[simp]
theorem under_under : (𝔓.under B).under A = 𝔓.under A := by
simp_rw [comap_comap, ← IsScalarTower.algebraMap_eq]
theorem LiesOver.trans [𝔓.LiesOver P] [P.LiesOver p] : 𝔓.LiesOver p where
over := by rw [P.over_def p, 𝔓.over_def P, under_under]
theorem LiesOver.tower_bot [hp : 𝔓.LiesOver p] [hP : 𝔓.LiesOver P] : P.LiesOver p where
over := by rw [𝔓.over_def p, 𝔓.over_def P, under_under]
/--
Consider the following commutative diagram of ring maps
```
A → B
↓ ↓
C → D
```
and let `P` be an ideal of `B`. The image in `C` of the ideal of `A` under `P` is included
in the ideal of `C` under the image of `P` in `D`.
-/
theorem map_under_le_under_map {C D : Type*} [CommSemiring C] [Semiring D] [Algebra A C]
[Algebra C D] [Algebra A D] [Algebra B D] [IsScalarTower A C D] [IsScalarTower A B D] :
map (algebraMap A C) (under A P) ≤ under C (map (algebraMap B D) P) := by
apply le_comap_of_map_le
rw [map_map, ← IsScalarTower.algebraMap_eq, map_le_iff_le_comap,
IsScalarTower.algebraMap_eq A B D, ← comap_comap]
exact comap_mono <| le_comap_map
/--
Consider the following commutative diagram of ring maps
```
A → B
↓ ↓
C → D
```
and let `P` be an ideal of `B`. Assume that the image in `C` of the ideal of `A` under `P`
is maximal and that the image of `P` in `D` is not equal to `D`, then the image in `C` of the
ideal of `A` under `P` is equal to the ideal of `C` under the image of `P` in `D`.
-/
theorem under_map_eq_map_under {C D : Type*} [CommSemiring C] [Semiring D] [Algebra A C]
[Algebra C D] [Algebra A D] [Algebra B D] [IsScalarTower A C D] [IsScalarTower A B D]
(h₁ : (map (algebraMap A C) (under A P)).IsMaximal) (h₂ : map (algebraMap B D) P ≠ ⊤) :
under C (map (algebraMap B D) P) = map (algebraMap A C) (under A P) :=
(IsCoatom.le_iff_eq (isMaximal_def.mp h₁) (comap_ne_top (algebraMap C D) h₂)).mp <|
map_under_le_under_map P
theorem disjoint_primeCompl_of_liesOver [p.IsPrime] [hPp : 𝔓.LiesOver p] :
Disjoint ((Algebra.algebraMapSubmonoid C p.primeCompl) : Set C) (𝔓 : Set C) := by
rw [liesOver_iff, under_def, SetLike.ext'_iff, coe_comap] at hPp
simpa only [Algebra.algebraMapSubmonoid, primeCompl, hPp, ← le_compl_iff_disjoint_left]
using Set.subset_compl_comm.mp (by simp)
variable (B)
instance under_liesOver_of_liesOver [𝔓.LiesOver p] : (𝔓.under B).LiesOver p :=
LiesOver.tower_bot 𝔓 (𝔓.under B) p
end CommSemiring
section CommRing
variable (A : Type*) [CommRing A] (B : Type*) [Ring B] [Nontrivial B]
[Algebra A B] [NoZeroSMulDivisors A B] {p : Ideal A}
@[simp]
theorem under_bot : under A (⊥ : Ideal B) = ⊥ :=
comap_bot_of_injective (algebraMap A B) (FaithfulSMul.algebraMap_injective A B)
instance bot_liesOver_bot : (⊥ : Ideal B).LiesOver (⊥ : Ideal A) where
over := (under_bot A B).symm
variable {A B} in
theorem ne_bot_of_liesOver_of_ne_bot (hp : p ≠ ⊥) (P : Ideal B) [P.LiesOver p] : P ≠ ⊥ := by
contrapose! hp
rw [over_def P p, hp, under_bot]
end CommRing
namespace Quotient
variable (R : Type*) [CommSemiring R] {A B C : Type*} [CommRing A] [CommRing B] [CommRing C]
[Algebra A B] [Algebra A C] [Algebra R A] [Algebra R B] [IsScalarTower R A B]
(P : Ideal B) {Q : Ideal C} (p : Ideal A) [Q.LiesOver p] [P.LiesOver p]
(G : Type*) [Group G] [MulSemiringAction G B] [SMulCommClass G A B]
/-- If `P` lies over `p`, then canonically `B ⧸ P` is a `A ⧸ p`-algebra. -/
instance algebraOfLiesOver : Algebra (A ⧸ p) (B ⧸ P) :=
algebraQuotientOfLEComap (le_of_eq (P.over_def p))
@[simp]
lemma algebraMap_mk_of_liesOver (x : A) :
algebraMap (A ⧸ p) (B ⧸ P) (Ideal.Quotient.mk p x) = Ideal.Quotient.mk P (algebraMap _ _ x) :=
rfl
instance isScalarTower_of_liesOver : IsScalarTower R (A ⧸ p) (B ⧸ P) :=
IsScalarTower.of_algebraMap_eq' <|
congrArg (algebraMap B (B ⧸ P)).comp (IsScalarTower.algebraMap_eq R A B)
instance instFaithfulSMul : FaithfulSMul (A ⧸ p) (B ⧸ P) := by
rw [faithfulSMul_iff_algebraMap_injective]
rintro ⟨a⟩ ⟨b⟩ hab
apply Quotient.eq.mpr ((mem_of_liesOver P p (a - b)).mpr _)
rw [RingHom.map_sub]
exact Quotient.eq.mp hab
variable {p} in
theorem nontrivial_of_liesOver_of_ne_top (hp : p ≠ ⊤) : Nontrivial (B ⧸ P) :=
Quotient.nontrivial ((eq_top_iff_of_liesOver P p).mp.mt hp)
theorem nontrivial_of_liesOver_of_isPrime [hp : p.IsPrime] : Nontrivial (B ⧸ P) :=
nontrivial_of_liesOver_of_ne_top P hp.ne_top
section algEquiv
variable {P} {E : Type*} [EquivLike E B C] [AlgEquivClass E A B C] (σ : E)
/-- An `A ⧸ p`-algebra isomorphism between `B ⧸ P` and `C ⧸ Q` induced by an `A`-algebra
isomorphism between `B` and `C`, where `Q = σ P`. -/
def algEquivOfEqMap (h : Q = P.map σ) : (B ⧸ P) ≃ₐ[A ⧸ p] (C ⧸ Q) where
__ := quotientEquiv P Q σ h
commutes' := by
rintro ⟨x⟩
exact congrArg (Ideal.Quotient.mk Q) (AlgHomClass.commutes σ x)
@[simp]
theorem algEquivOfEqMap_apply (h : Q = P.map σ) (x : B) : algEquivOfEqMap p σ h x = σ x :=
rfl
/-- An `A ⧸ p`-algebra isomorphism between `B ⧸ P` and `C ⧸ Q` induced by an `A`-algebra
isomorphism between `B` and `C`, where `P = σ⁻¹ Q`. -/
def algEquivOfEqComap (h : P = Q.comap σ) : (B ⧸ P) ≃ₐ[A ⧸ p] (C ⧸ Q) :=
algEquivOfEqMap p σ ((congrArg (map σ) h).trans (Q.map_comap_eq_self_of_equiv σ)).symm
@[simp]
theorem algEquivOfEqComap_apply (h : P = Q.comap σ) (x : B) : algEquivOfEqComap p σ h x = σ x :=
rfl
end algEquiv
/-- If `P` lies over `p`, then the stabilizer of `P` acts on the extension `(B ⧸ P) / (A ⧸ p)`. -/
def stabilizerHom : MulAction.stabilizer G P →* ((B ⧸ P) ≃ₐ[A ⧸ p] (B ⧸ P)) where
toFun g := algEquivOfEqMap p (MulSemiringAction.toAlgEquiv A B g) g.2.symm
map_one' := by
ext ⟨x⟩
exact congrArg (Ideal.Quotient.mk P) (one_smul G x)
map_mul' g h := by
ext ⟨x⟩
exact congrArg (Ideal.Quotient.mk P) (mul_smul g h x)
@[simp] theorem stabilizerHom_apply (g : MulAction.stabilizer G P) (b : B) :
stabilizerHom P p G g b = ↑(g • b) :=
rfl
lemma ker_stabilizerHom :
(stabilizerHom P p G).ker = (P.toAddSubgroup.inertia G).subgroupOf _ := by
ext σ
simp [DFunLike.ext_iff, mk_surjective.forall, Quotient.eq,
Subgroup.mem_subgroupOf, Subgroup.smul_def]
theorem map_ker_stabilizer_subtype :
(stabilizerHom P p G).ker.map (Subgroup.subtype _) = P.toAddSubgroup.inertia G := by
simp [ker_stabilizerHom, Ideal.inertia_le_stabilizer]
end Quotient
end ideal_liesOver
section primesOver
variable {A : Type*} [CommSemiring A] (p : Ideal A) (B : Type*) [Semiring B] [Algebra A B]
/-- The set of all prime ideals in `B` that lie over an ideal `p` of `A`. -/
def primesOver : Set (Ideal B) :=
{ P : Ideal B | P.IsPrime ∧ P.LiesOver p }
variable {B}
instance primesOver.isPrime (Q : primesOver p B) : Q.1.IsPrime :=
Q.2.1
instance primesOver.liesOver (Q : primesOver p B) : Q.1.LiesOver p :=
Q.2.2
/-- If an ideal `P` of `B` is prime and lying over `p`, then it is in `primesOver p B`. -/
abbrev primesOver.mk (P : Ideal B) [hPp : P.IsPrime] [hp : P.LiesOver p] : primesOver p B :=
⟨P, ⟨hPp, hp⟩⟩
variable {p} in
theorem ne_bot_of_mem_primesOver {S : Type*} [Ring S] [Algebra R S] [Nontrivial S]
[NoZeroSMulDivisors R S] {p : Ideal R} (hp : p ≠ ⊥) {P : Ideal S}
(hP : P ∈ p.primesOver S) :
P ≠ ⊥ := @ne_bot_of_liesOver_of_ne_bot _ _ _ _ _ _ _ _ hp P hP.2
end primesOver
end Ideal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/IsPrimary.lean | import Mathlib.RingTheory.IsPrimary
import Mathlib.RingTheory.Ideal.Operations
/-!
# Primary ideals
A proper ideal `I` is primary iff `xy ∈ I` implies `x ∈ I` or `y ∈ radical I`.
## Main definitions
- `Ideal.IsPrimary`
## Implementation details
Uses a specialized phrasing of `Submodule.IsPrimary` to have better API-piercing usage.
-/
namespace Ideal
variable {R : Type*} [CommSemiring R]
/-- A proper ideal `I` is primary as a submodule. -/
abbrev IsPrimary (I : Ideal R) : Prop :=
Submodule.IsPrimary I
/-- A proper ideal `I` is primary iff `xy ∈ I` implies `x ∈ I` or `y ∈ radical I`. -/
lemma isPrimary_iff {I : Ideal R} :
I.IsPrimary ↔ I ≠ ⊤ ∧ ∀ {x y : R}, x * y ∈ I → x ∈ I ∨ y ∈ radical I := by
rw [IsPrimary, Submodule.IsPrimary, forall_comm]
simp only [mul_comm, mem_radical_iff,
← Submodule.ideal_span_singleton_smul, smul_eq_mul, mul_top, span_singleton_le_iff_mem]
theorem IsPrime.isPrimary {I : Ideal R} (hi : IsPrime I) : I.IsPrimary :=
isPrimary_iff.mpr
⟨hi.1, fun {_ _} hxy => (hi.mem_or_mem hxy).imp id fun hyi => le_radical hyi⟩
theorem isPrime_radical {I : Ideal R} (hi : I.IsPrimary) : IsPrime (radical I) :=
⟨mt radical_eq_top.1 hi.1,
fun {x y} ⟨m, hxy⟩ => by
rw [mul_pow] at hxy; rcases (isPrimary_iff.mp hi).2 hxy with h | h
· exact Or.inl ⟨m, h⟩
· exact Or.inr (mem_radical_of_pow_mem h)⟩
theorem isPrimary_inf {I J : Ideal R} (hi : I.IsPrimary) (hj : J.IsPrimary)
(hij : radical I = radical J) : (I ⊓ J).IsPrimary :=
isPrimary_iff.mpr
⟨ne_of_lt <| lt_of_le_of_lt inf_le_left (lt_top_iff_ne_top.2 hi.1),
fun {x y} ⟨hxyi, hxyj⟩ => by
rw [radical_inf, hij, inf_idem]
rcases (isPrimary_iff.mp hi).2 hxyi with hxi | hyi
· rcases (isPrimary_iff.mp hj).2 hxyj with hxj | hyj
· exact Or.inl ⟨hxi, hxj⟩
· exact Or.inr hyj
· rw [hij] at hyi
exact Or.inr hyi⟩
open Finset in
lemma isPrimary_finset_inf {ι} {s : Finset ι} {f : ι → Ideal R} {i : ι} (hi : i ∈ s)
(hs : ∀ ⦃y⦄, y ∈ s → (f y).IsPrimary)
(hs' : ∀ ⦃y⦄, y ∈ s → (f y).radical = (f i).radical) :
IsPrimary (s.inf f) := by
classical
induction s using Finset.induction_on generalizing i with
| empty => simp at hi
| insert a s ha IH =>
rcases s.eq_empty_or_nonempty with rfl | ⟨y, hy⟩
· simp only [insert_empty_eq, mem_singleton] at hi
simpa [hi] using hs
simp only [inf_insert]
have H : ∀ ⦃x : ι⦄, x ∈ s → (f x).radical = (f y).radical := by
intro x hx
rw [hs' (mem_insert_of_mem hx), hs' (mem_insert_of_mem hy)]
refine isPrimary_inf (hs (by simp)) (IH hy ?_ H) ?_
· intro x hx
exact hs (by simp [hx])
· rw [radical_finset_inf hy H, hs' (mem_insert_self _ _), hs' (mem_insert_of_mem hy)]
end Ideal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/IdempotentFG.lean | import Mathlib.Algebra.Ring.Idempotent
import Mathlib.Order.Basic
import Mathlib.RingTheory.Finiteness.Nakayama
/-!
## Lemmas on idempotent finitely generated ideals
-/
namespace Ideal
/-- A finitely generated idempotent ideal is generated by an idempotent element -/
theorem isIdempotentElem_iff_of_fg {R : Type*} [CommRing R] (I : Ideal R) (h : I.FG) :
IsIdempotentElem I ↔ ∃ e : R, IsIdempotentElem e ∧ I = R ∙ e := by
constructor
· intro e
obtain ⟨r, hr, hr'⟩ :=
Submodule.exists_mem_and_smul_eq_self_of_fg_of_le_smul I I h
(by
rw [smul_eq_mul]
exact e.ge)
simp_rw [smul_eq_mul] at hr'
refine ⟨r, hr' r hr, antisymm ?_ ((Submodule.span_singleton_le_iff_mem _ _).mpr hr)⟩
intro x hx
rw [← hr' x hx]
exact Ideal.mem_span_singleton'.mpr ⟨_, mul_comm _ _⟩
· rintro ⟨e, he, rfl⟩
simp [IsIdempotentElem, Ideal.span_singleton_mul_span_singleton, he.eq]
theorem isIdempotentElem_iff_eq_bot_or_top {R : Type*} [CommRing R] [IsDomain R] (I : Ideal R)
(h : I.FG) : IsIdempotentElem I ↔ I = ⊥ ∨ I = ⊤ := by
constructor
· intro H
obtain ⟨e, he, rfl⟩ := (I.isIdempotentElem_iff_of_fg h).mp H
simp only [Ideal.submodule_span_eq, Ideal.span_singleton_eq_bot]
apply Or.imp id _ (IsIdempotentElem.iff_eq_zero_or_one.mp he)
rintro rfl
simp
· rintro (rfl | rfl) <;> simp [IsIdempotentElem]
end Ideal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/GoingUp.lean | import Mathlib.RingTheory.Ideal.Over
import Mathlib.RingTheory.Localization.AtPrime.Basic
import Mathlib.RingTheory.Localization.Integral
/-!
# Ideals over/under ideals in integral extensions
This file proves some going-up results for integral algebras.
## Implementation notes
The proofs of the `comap_ne_bot` and `comap_lt_comap` families use an approach
specific for their situation: we construct an element in `I.comap f` from the
coefficients of a minimal polynomial.
Once mathlib has more material on the localization at a prime ideal, the results
can be proven using more general going-up/going-down theory.
-/
open Polynomial Submodule
open scoped Pointwise
namespace Ideal
section
variable {R : Type*} [CommRing R]
variable {S : Type*} [CommRing S] {f : R →+* S} {I J : Ideal S}
theorem coeff_zero_mem_comap_of_root_mem_of_eval_mem {r : S} (hr : r ∈ I) {p : R[X]}
(hp : p.eval₂ f r ∈ I) : p.coeff 0 ∈ I.comap f := by
rw [← p.divX_mul_X_add, eval₂_add, eval₂_C, eval₂_mul, eval₂_X] at hp
refine mem_comap.mpr ((I.add_mem_iff_right ?_).mp hp)
exact I.mul_mem_left _ hr
theorem coeff_zero_mem_comap_of_root_mem {r : S} (hr : r ∈ I) {p : R[X]} (hp : p.eval₂ f r = 0) :
p.coeff 0 ∈ I.comap f :=
coeff_zero_mem_comap_of_root_mem_of_eval_mem hr (hp.symm ▸ I.zero_mem)
theorem exists_coeff_ne_zero_mem_comap_of_non_zero_divisor_root_mem {r : S}
(r_non_zero_divisor : ∀ {x}, x * r = 0 → x = 0) (hr : r ∈ I) {p : R[X]} :
p ≠ 0 → p.eval₂ f r = 0 → ∃ i, p.coeff i ≠ 0 ∧ p.coeff i ∈ I.comap f := by
refine p.recOnHorner ?_ ?_ ?_
· intro h
contradiction
· intro p a coeff_eq_zero a_ne_zero _ _ hp
refine ⟨0, ?_, coeff_zero_mem_comap_of_root_mem hr hp⟩
simp [coeff_eq_zero, a_ne_zero]
· intro p p_nonzero ih _ hp
rw [eval₂_mul, eval₂_X] at hp
obtain ⟨i, hi, mem⟩ := ih p_nonzero (r_non_zero_divisor hp)
refine ⟨i + 1, ?_, ?_⟩
· simp [hi]
· simpa [hi] using mem
/-- Let `P` be an ideal in `R[x]`. The map
`R[x]/P → (R / (P ∩ R))[x] / (P / (P ∩ R))`
is injective.
-/
theorem injective_quotient_le_comap_map (P : Ideal R[X]) :
Function.Injective <|
Ideal.quotientMap
(Ideal.map (Polynomial.mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) P)
(Polynomial.mapRingHom (Ideal.Quotient.mk (P.comap (C : R →+* R[X]))))
le_comap_map := by
refine quotientMap_injective' (le_of_eq ?_)
rw [comap_map_of_surjective (mapRingHom (Ideal.Quotient.mk (P.comap (C : R →+* R[X]))))
(map_surjective (Ideal.Quotient.mk (P.comap (C : R →+* R[X]))) Ideal.Quotient.mk_surjective)]
refine le_antisymm (sup_le le_rfl ?_) (le_sup_of_le_left le_rfl)
refine fun p hp =>
polynomial_mem_ideal_of_coeff_mem_ideal P p fun n => Ideal.Quotient.eq_zero_iff_mem.mp ?_
simpa only [coeff_map, coe_mapRingHom] using ext_iff.mp (Ideal.mem_bot.mp (mem_comap.mp hp)) n
/-- The identity in this lemma asserts that the "obvious" square
```
R → (R / (P ∩ R))
↓ ↓
R[x] / P → (R / (P ∩ R))[x] / (P / (P ∩ R))
```
commutes. It is used, for instance, in the proof of `quotient_mk_comp_C_is_integral_of_jacobson`,
in the file `Mathlib/RingTheory/Jacobson/Polynomial.lean`.
-/
theorem quotient_mk_maps_eq (P : Ideal R[X]) :
((Quotient.mk (map (mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) P)).comp C).comp
(Quotient.mk (P.comap (C : R →+* R[X]))) =
(Ideal.quotientMap (map (mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) P)
(mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) le_comap_map).comp
((Quotient.mk P).comp C) := by
refine RingHom.ext fun x => ?_
repeat' rw [RingHom.coe_comp, Function.comp_apply]
rw [quotientMap_mk, coe_mapRingHom, map_C]
/-- This technical lemma asserts the existence of a polynomial `p` in an ideal `P ⊂ R[x]`
that is non-zero in the quotient `R / (P ∩ R) [x]`. The assumptions are equivalent to
`P ≠ 0` and `P ∩ R = (0)`.
-/
theorem exists_nonzero_mem_of_ne_bot {P : Ideal R[X]} (Pb : P ≠ ⊥) (hP : ∀ x : R, C x ∈ P → x = 0) :
∃ p : R[X], p ∈ P ∧ Polynomial.map (Quotient.mk (P.comap (C : R →+* R[X]))) p ≠ 0 := by
obtain ⟨m, hm⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr Pb)
refine ⟨m, Submodule.coe_mem m, fun pp0 => hm (Submodule.coe_eq_zero.mp ?_)⟩
refine
(injective_iff_map_eq_zero (Polynomial.mapRingHom (Ideal.Quotient.mk
(P.comap (C : R →+* R[X]))))).mp
?_ _ pp0
refine map_injective _ ((RingHom.injective_iff_ker_eq_bot (Ideal.Quotient.mk (P.comap C))).mpr ?_)
rw [mk_ker]
exact (Submodule.eq_bot_iff _).mpr fun x hx => hP x (mem_comap.mp hx)
end
section IsDomain
variable {R : Type*} [CommRing R]
variable {S : Type*} [CommRing S] {f : R →+* S} {I J : Ideal S}
theorem exists_coeff_ne_zero_mem_comap_of_root_mem [IsDomain S] {r : S} (r_ne_zero : r ≠ 0)
(hr : r ∈ I) {p : R[X]} :
p ≠ 0 → p.eval₂ f r = 0 → ∃ i, p.coeff i ≠ 0 ∧ p.coeff i ∈ I.comap f :=
exists_coeff_ne_zero_mem_comap_of_non_zero_divisor_root_mem
(fun {_} h => Or.resolve_right (mul_eq_zero.mp h) r_ne_zero) hr
theorem exists_coeff_mem_comap_sdiff_comap_of_root_mem_sdiff [IsPrime I] (hIJ : I ≤ J) {r : S}
(hr : r ∈ (J : Set S) \ I) {p : R[X]} (p_ne_zero : p.map (Quotient.mk (I.comap f)) ≠ 0)
(hpI : p.eval₂ f r ∈ I) : ∃ i, p.coeff i ∈ (J.comap f : Set R) \ I.comap f := by
obtain ⟨hrJ, hrI⟩ := hr
have rbar_ne_zero : Ideal.Quotient.mk I r ≠ 0 := mt (Quotient.mk_eq_zero I).mp hrI
have rbar_mem_J : Ideal.Quotient.mk I r ∈ J.map (Ideal.Quotient.mk I) := mem_map_of_mem _ hrJ
have quotient_f : ∀ x ∈ I.comap f, (Ideal.Quotient.mk I).comp f x = 0 := by
simp [Quotient.eq_zero_iff_mem]
have rbar_root :
(p.map (Ideal.Quotient.mk (I.comap f))).eval₂ (Quotient.lift (I.comap f) _ quotient_f)
(Ideal.Quotient.mk I r) =
0 := by
convert Quotient.eq_zero_iff_mem.mpr hpI
exact _root_.trans (eval₂_map _ _ _) (hom_eval₂ p f (Ideal.Quotient.mk I) r).symm
obtain ⟨i, ne_zero, mem⟩ :=
exists_coeff_ne_zero_mem_comap_of_root_mem rbar_ne_zero rbar_mem_J p_ne_zero rbar_root
rw [coeff_map] at ne_zero mem
refine ⟨i, (mem_quotient_iff_mem hIJ).mp ?_, mt ?_ ne_zero⟩
· simpa using mem
simp [Quotient.eq_zero_iff_mem]
theorem comap_lt_comap_of_root_mem_sdiff [I.IsPrime] (hIJ : I ≤ J) {r : S}
(hr : r ∈ (J : Set S) \ I) {p : R[X]} (p_ne_zero : p.map (Quotient.mk (I.comap f)) ≠ 0)
(hp : p.eval₂ f r ∈ I) : I.comap f < J.comap f :=
let ⟨i, hJ, hI⟩ := exists_coeff_mem_comap_sdiff_comap_of_root_mem_sdiff hIJ hr p_ne_zero hp
SetLike.lt_iff_le_and_exists.mpr ⟨comap_mono hIJ, p.coeff i, hJ, hI⟩
theorem mem_of_one_mem (h : (1 : S) ∈ I) (x) : x ∈ I :=
(I.eq_top_iff_one.mpr h).symm ▸ mem_top
theorem comap_lt_comap_of_integral_mem_sdiff [Algebra R S] [hI : I.IsPrime] (hIJ : I ≤ J) {x : S}
(mem : x ∈ (J : Set S) \ I) (integral : IsIntegral R x) :
I.comap (algebraMap R S) < J.comap (algebraMap R S) := by
obtain ⟨p, p_monic, hpx⟩ := integral
refine comap_lt_comap_of_root_mem_sdiff hIJ mem (map_monic_ne_zero p_monic) ?_
convert I.zero_mem
theorem comap_ne_bot_of_root_mem [IsDomain S] {r : S} (r_ne_zero : r ≠ 0) (hr : r ∈ I) {p : R[X]}
(p_ne_zero : p ≠ 0) (hp : p.eval₂ f r = 0) : I.comap f ≠ ⊥ := fun h =>
let ⟨_, hi, mem⟩ := exists_coeff_ne_zero_mem_comap_of_root_mem r_ne_zero hr p_ne_zero hp
absurd (mem_bot.mp (eq_bot_iff.mp h mem)) hi
theorem isMaximal_of_isIntegral_of_isMaximal_comap [Algebra R S] [Algebra.IsIntegral R S]
(I : Ideal S) [I.IsPrime] (hI : IsMaximal (I.comap (algebraMap R S))) : IsMaximal I :=
⟨⟨mt comap_eq_top_iff.mpr hI.1.1, fun _ I_lt_J =>
let ⟨I_le_J, x, hxJ, hxI⟩ := SetLike.lt_iff_le_and_exists.mp I_lt_J
comap_eq_top_iff.1 <|
hI.1.2 _ (comap_lt_comap_of_integral_mem_sdiff I_le_J ⟨hxJ, hxI⟩
(Algebra.IsIntegral.isIntegral x))⟩⟩
theorem isMaximal_of_isIntegral_of_isMaximal_comap' (f : R →+* S) (hf : f.IsIntegral) (I : Ideal S)
[I.IsPrime] (hI : IsMaximal (I.comap f)) : IsMaximal I :=
let _ : Algebra R S := f.toAlgebra
have : Algebra.IsIntegral R S := ⟨hf⟩
isMaximal_of_isIntegral_of_isMaximal_comap (R := R) (S := S) I hI
variable [Algebra R S]
theorem comap_ne_bot_of_algebraic_mem [IsDomain S] {x : S} (x_ne_zero : x ≠ 0) (x_mem : x ∈ I)
(hx : IsAlgebraic R x) : I.comap (algebraMap R S) ≠ ⊥ :=
let ⟨_, p_ne_zero, hp⟩ := hx
comap_ne_bot_of_root_mem x_ne_zero x_mem p_ne_zero hp
theorem comap_ne_bot_of_integral_mem [Nontrivial R] [IsDomain S] {x : S} (x_ne_zero : x ≠ 0)
(x_mem : x ∈ I) (hx : IsIntegral R x) : I.comap (algebraMap R S) ≠ ⊥ :=
comap_ne_bot_of_algebraic_mem x_ne_zero x_mem hx.isAlgebraic
theorem eq_bot_of_comap_eq_bot [Nontrivial R] [IsDomain S] [Algebra.IsIntegral R S]
(hI : I.comap (algebraMap R S) = ⊥) : I = ⊥ := by
refine eq_bot_iff.2 fun x hx => ?_
by_cases hx0 : x = 0
· exact hx0.symm ▸ Ideal.zero_mem ⊥
· exact absurd hI (comap_ne_bot_of_integral_mem hx0 hx (Algebra.IsIntegral.isIntegral x))
theorem isMaximal_comap_of_isIntegral_of_isMaximal [Algebra.IsIntegral R S] (I : Ideal S)
[hI : I.IsMaximal] : IsMaximal (I.comap (algebraMap R S)) := by
refine Ideal.Quotient.maximal_of_isField _ ?_
haveI : IsPrime (I.comap (algebraMap R S)) := comap_isPrime _ _
exact isField_of_isIntegral_of_isField
algebraMap_quotient_injective (by rwa [← Quotient.maximal_ideal_iff_isField_quotient])
theorem isMaximal_comap_of_isIntegral_of_isMaximal' {R S : Type*} [CommRing R] [CommRing S]
(f : R →+* S) (hf : f.IsIntegral) (I : Ideal S) [I.IsMaximal] : IsMaximal (I.comap f) :=
let _ : Algebra R S := f.toAlgebra
have : Algebra.IsIntegral R S := ⟨hf⟩
isMaximal_comap_of_isIntegral_of_isMaximal (R := R) (S := S) I
section IsIntegralClosure
variable (S) {A : Type*} [CommRing A]
variable [Algebra R A] [Algebra A S] [IsScalarTower R A S] [IsIntegralClosure A R S]
include S
theorem IsIntegralClosure.comap_lt_comap {I J : Ideal A} [I.IsPrime] (I_lt_J : I < J) :
I.comap (algebraMap R A) < J.comap (algebraMap R A) :=
let ⟨I_le_J, x, hxJ, hxI⟩ := SetLike.lt_iff_le_and_exists.mp I_lt_J
comap_lt_comap_of_integral_mem_sdiff I_le_J ⟨hxJ, hxI⟩ (IsIntegralClosure.isIntegral R S x)
theorem IsIntegralClosure.isMaximal_of_isMaximal_comap (I : Ideal A) [I.IsPrime]
(hI : IsMaximal (I.comap (algebraMap R A))) : IsMaximal I :=
have : Algebra.IsIntegral R A := IsIntegralClosure.isIntegral_algebra R S
isMaximal_of_isIntegral_of_isMaximal_comap I hI
variable [IsDomain A]
theorem IsIntegralClosure.comap_ne_bot [Nontrivial R] {I : Ideal A} (I_ne_bot : I ≠ ⊥) :
I.comap (algebraMap R A) ≠ ⊥ :=
let ⟨x, x_mem, x_ne_zero⟩ := I.ne_bot_iff.mp I_ne_bot
comap_ne_bot_of_integral_mem x_ne_zero x_mem (IsIntegralClosure.isIntegral R S x)
theorem IsIntegralClosure.eq_bot_of_comap_eq_bot [Nontrivial R] {I : Ideal A} :
I.comap (algebraMap R A) = ⊥ → I = ⊥ := by
contrapose
exact IsIntegralClosure.comap_ne_bot S
end IsIntegralClosure
theorem IntegralClosure.comap_lt_comap {I J : Ideal (integralClosure R S)} [I.IsPrime]
(I_lt_J : I < J) :
I.comap (algebraMap R (integralClosure R S)) < J.comap (algebraMap R (integralClosure R S)) :=
IsIntegralClosure.comap_lt_comap S I_lt_J
theorem IntegralClosure.isMaximal_of_isMaximal_comap (I : Ideal (integralClosure R S)) [I.IsPrime]
(hI : IsMaximal (I.comap (algebraMap R (integralClosure R S)))) : IsMaximal I :=
IsIntegralClosure.isMaximal_of_isMaximal_comap S I hI
section
variable [IsDomain S]
theorem IntegralClosure.comap_ne_bot [Nontrivial R] {I : Ideal (integralClosure R S)}
(I_ne_bot : I ≠ ⊥) : I.comap (algebraMap R (integralClosure R S)) ≠ ⊥ :=
IsIntegralClosure.comap_ne_bot S I_ne_bot
theorem IntegralClosure.eq_bot_of_comap_eq_bot [Nontrivial R] {I : Ideal (integralClosure R S)} :
I.comap (algebraMap R (integralClosure R S)) = ⊥ → I = ⊥ :=
IsIntegralClosure.eq_bot_of_comap_eq_bot S
/-- `comap (algebraMap R S)` is a surjection from the prime spec of `R` to prime spec of `S`.
`hP : (algebraMap R S).ker ≤ P` is a slight generalization of the extension being injective -/
theorem exists_ideal_over_prime_of_isIntegral_of_isDomain [Algebra.IsIntegral R S] (P : Ideal R)
[IsPrime P] (hP : RingHom.ker (algebraMap R S) ≤ P) :
∃ Q : Ideal S, IsPrime Q ∧ Q.comap (algebraMap R S) = P := by
have hP0 : (0 : S) ∉ Algebra.algebraMapSubmonoid S P.primeCompl := by
rintro ⟨x, ⟨hx, x0⟩⟩
exact absurd (hP x0) hx
let Rₚ := Localization P.primeCompl
let Sₚ := Localization (Algebra.algebraMapSubmonoid S P.primeCompl)
letI : IsDomain (Localization (Algebra.algebraMapSubmonoid S P.primeCompl)) :=
IsLocalization.isDomain_localization (le_nonZeroDivisors_of_noZeroDivisors hP0)
obtain ⟨Qₚ : Ideal Sₚ, Qₚ_maximal⟩ := exists_maximal Sₚ
let _ : Algebra Rₚ Sₚ := localizationAlgebra P.primeCompl S
have : Algebra.IsIntegral Rₚ Sₚ := ⟨isIntegral_localization⟩
have Qₚ_max : IsMaximal (comap _ Qₚ) :=
isMaximal_comap_of_isIntegral_of_isMaximal (R := Rₚ) (S := Sₚ) Qₚ
refine ⟨comap (algebraMap S Sₚ) Qₚ, ⟨comap_isPrime _ Qₚ, ?_⟩⟩
convert Localization.AtPrime.comap_maximalIdeal (I := P)
rw [comap_comap, ← IsLocalRing.eq_maximalIdeal Qₚ_max,
← IsLocalization.map_comp (P := S) (Q := Sₚ) (g := algebraMap R S)
(M := P.primeCompl) (T := Algebra.algebraMapSubmonoid S P.primeCompl) (S := Rₚ)
(fun p hp => Algebra.mem_algebraMapSubmonoid_of_mem ⟨p, hp⟩) ]
rfl
end
/-- More general going-up theorem than `exists_ideal_over_prime_of_isIntegral_of_isDomain`.
TODO: Version of going-up theorem with arbitrary length chains (by induction on this)?
Not sure how best to write an ascending chain in Lean -/
theorem exists_ideal_over_prime_of_isIntegral_of_isPrime
[Algebra.IsIntegral R S] (P : Ideal R) [IsPrime P]
(I : Ideal S) [IsPrime I] (hIP : I.comap (algebraMap R S) ≤ P) :
∃ Q ≥ I, IsPrime Q ∧ Q.comap (algebraMap R S) = P := by
obtain ⟨Q' : Ideal (S ⧸ I), ⟨Q'_prime, hQ'⟩⟩ :=
@exists_ideal_over_prime_of_isIntegral_of_isDomain (R ⧸ I.comap (algebraMap R S)) _ (S ⧸ I) _
Ideal.quotientAlgebra _ _
(map (Ideal.Quotient.mk (I.comap (algebraMap R S))) P)
(map_isPrime_of_surjective Quotient.mk_surjective (by simp [hIP]))
(le_trans (le_of_eq ((RingHom.injective_iff_ker_eq_bot _).1 algebraMap_quotient_injective))
bot_le)
refine ⟨Q'.comap _, le_trans (le_of_eq mk_ker.symm) (ker_le_comap _), ⟨comap_isPrime _ Q', ?_⟩⟩
rw [comap_comap]
refine _root_.trans ?_ (_root_.trans (congr_arg (comap (Ideal.Quotient.mk
(comap (algebraMap R S) I))) hQ') ?_)
· rw [comap_comap]
exact congr_arg (comap · Q') (RingHom.ext fun r => rfl)
· refine _root_.trans (comap_map_of_surjective _ Quotient.mk_surjective _) (sup_eq_left.2 ?_)
simpa [← RingHom.ker_eq_comap_bot] using hIP
theorem exists_ideal_over_prime_of_isIntegral [Algebra.IsIntegral R S] (P : Ideal R) [IsPrime P]
(I : Ideal S) (hIP : I.comap (algebraMap R S) ≤ P) :
∃ Q ≥ I, IsPrime Q ∧ Q.comap (algebraMap R S) = P := by
have ⟨P', hP, hP', hP''⟩ := exists_ideal_comap_le_prime P I hIP
obtain ⟨Q, hQ, hQ', hQ''⟩ := exists_ideal_over_prime_of_isIntegral_of_isPrime P P' hP''
exact ⟨Q, hP.trans hQ, hQ', hQ''⟩
instance nonempty_primesOver [Nontrivial S] [Algebra.IsIntegral R S] [NoZeroSMulDivisors R S]
(P : Ideal R) [P.IsPrime] :
Nonempty (primesOver P S) := by
obtain ⟨Q, _, hQ₁, hQ₂⟩ := exists_ideal_over_prime_of_isIntegral P (⊥ : Ideal S) (by simp)
exact ⟨Q, ⟨hQ₁, (liesOver_iff _ _).mpr hQ₂.symm⟩⟩
/-- `comap (algebraMap R S)` is a surjection from the max spec of `S` to max spec of `R`.
`hP : (algebraMap R S).ker ≤ P` is a slight generalization of the extension being injective -/
theorem exists_ideal_over_maximal_of_isIntegral [Algebra.IsIntegral R S]
(P : Ideal R) [P_max : IsMaximal P] (hP : RingHom.ker (algebraMap R S) ≤ P) :
∃ Q : Ideal S, IsMaximal Q ∧ Q.comap (algebraMap R S) = P := by
obtain ⟨Q, -, Q_prime, hQ⟩ := exists_ideal_over_prime_of_isIntegral P ⊥ hP
exact ⟨Q, isMaximal_of_isIntegral_of_isMaximal_comap _ (hQ.symm ▸ P_max), hQ⟩
theorem exists_maximal_ideal_liesOver_of_isIntegral [Algebra.IsIntegral R S] [FaithfulSMul R S]
(P : Ideal R) [P.IsMaximal] :
∃ (Q : Ideal S), Q.IsMaximal ∧ Q.LiesOver P := by
simp_rw [liesOver_iff, eq_comm (a := P)]
exact exists_ideal_over_maximal_of_isIntegral P (by
simp [(RingHom.injective_iff_ker_eq_bot _).mp (FaithfulSMul.algebraMap_injective R S)])
lemma map_eq_top_iff_of_ker_le {R S} [CommRing R] [CommRing S]
(f : R →+* S) {I : Ideal R} (hf₁ : RingHom.ker f ≤ I) (hf₂ : f.IsIntegral) :
I.map f = ⊤ ↔ I = ⊤ := by
constructor; swap
· rintro rfl; exact Ideal.map_top _
contrapose
intro h
obtain ⟨m, _, hm⟩ := Ideal.exists_le_maximal I h
let _ := f.toAlgebra
have : Algebra.IsIntegral _ _ := ⟨hf₂⟩
obtain ⟨m', _, rfl⟩ := exists_ideal_over_maximal_of_isIntegral m (hf₁.trans hm)
rw [← map_le_iff_le_comap] at hm
exact (hm.trans_lt (lt_top_iff_ne_top.mpr (IsMaximal.ne_top ‹_›))).ne
lemma map_eq_top_iff {R S} [CommRing R] [CommRing S]
(f : R →+* S) {I : Ideal R} (hf₁ : Function.Injective f) (hf₂ : f.IsIntegral) :
I.map f = ⊤ ↔ I = ⊤ :=
map_eq_top_iff_of_ker_le f (by simp [(RingHom.injective_iff_ker_eq_bot f).mp hf₁]) hf₂
end IsDomain
section IsIntegral
variable {A : Type*} [CommRing A] {B : Type*} [CommRing B] [Algebra A B] [Algebra.IsIntegral A B]
(P : Ideal B) (p : Ideal A) [P.LiesOver p]
variable (A) in
/-- If `B` is an integral `A`-algebra, `P` is a maximal ideal of `B`, then the pull back of
`P` is also a maximal ideal of `A`. -/
instance IsMaximal.under [P.IsMaximal] : (P.under A).IsMaximal :=
isMaximal_comap_of_isIntegral_of_isMaximal P
theorem IsMaximal.of_liesOver_isMaximal [hpm : p.IsMaximal] [P.IsPrime] : P.IsMaximal := by
rw [P.over_def p] at hpm
exact isMaximal_of_isIntegral_of_isMaximal_comap P hpm
theorem IsMaximal.of_isMaximal_liesOver [P.IsMaximal] : p.IsMaximal := by
rw [P.over_def p]
exact isMaximal_comap_of_isIntegral_of_isMaximal P
variable (A) in
theorem eq_bot_of_liesOver_bot [Nontrivial A] [IsDomain B] [h : P.LiesOver (⊥ : Ideal A)] :
P = ⊥ :=
eq_bot_of_comap_eq_bot <| ((liesOver_iff _ _).mp h).symm
variable (A) {P} in
theorem under_ne_bot [Nontrivial A] [IsDomain B] (hP : P ≠ ⊥) : under A P ≠ ⊥ :=
fun h ↦ hP <| eq_bot_of_comap_eq_bot h
/-- `B ⧸ P` is an integral `A ⧸ p`-algebra if `B` is a integral `A`-algebra. -/
instance Quotient.algebra_isIntegral_of_liesOver : Algebra.IsIntegral (A ⧸ p) (B ⧸ P) :=
Algebra.IsIntegral.tower_top A
@[deprecated (since := "2025-11-06")] alias exists_ideal_liesOver_maximal_of_isIntegral :=
exists_maximal_ideal_liesOver_of_isIntegral
end IsIntegral
section IsIntegral
variable {A : Type*} [CommRing A] {p : Ideal A} [p.IsMaximal] {B : Type*} [CommRing B]
[Algebra A B] [NoZeroSMulDivisors A B] [Algebra.IsIntegral A B] (Q : primesOver p B)
instance primesOver.isMaximal : Q.1.IsMaximal :=
Ideal.IsMaximal.of_liesOver_isMaximal Q.1 p
variable (A B) in
lemma primesOver_bot [Nontrivial A] [IsDomain B] : primesOver (⊥ : Ideal A) B = {⊥} := by
ext p
refine ⟨fun ⟨_, ⟨h⟩⟩ ↦ p.eq_bot_of_comap_eq_bot h.symm, ?_⟩
rintro rfl
exact ⟨Ideal.bot_prime, Ideal.bot_liesOver_bot A B⟩
end IsIntegral
end Ideal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Basic.lean | import Mathlib.Algebra.Field.IsField
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.LinearAlgebra.Finsupp.LinearCombination
import Mathlib.RingTheory.Ideal.Maximal
import Mathlib.Tactic.FinCases
/-!
# Ideals over a ring
This file contains an assortment of definitions and results for `Ideal R`,
the type of (left) ideals over a ring `R`.
Note that over commutative rings, left ideals and two-sided ideals are equivalent.
## Implementation notes
`Ideal R` is implemented using `Submodule R R`, where `•` is interpreted as `*`.
## TODO
Support right ideals, and two-sided ideals over non-commutative rings.
-/
variable {ι α β F : Type*}
open Set Function
open Pointwise
section Semiring
namespace Ideal
variable {R : ι → Type*} [Π i, Semiring (R i)] (I J : Π i, Ideal (R i))
section Pi
/-- `Πᵢ Iᵢ` as an ideal of `Πᵢ Rᵢ`. -/
def pi : Ideal (Π i, R i) where
carrier := { r | ∀ i, r i ∈ I i }
zero_mem' i := (I i).zero_mem
add_mem' ha hb i := (I i).add_mem (ha i) (hb i)
smul_mem' a _b hb i := (I i).mul_mem_left (a i) (hb i)
theorem mem_pi (r : Π i, R i) : r ∈ pi I ↔ ∀ i, r i ∈ I i :=
Iff.rfl
@[simp] theorem pi_span {r : Π i, R i} : pi (span {r ·}) = span {r} := by
ext; simp_rw [mem_pi, mem_span_singleton', funext_iff, Classical.skolem, Pi.mul_def]
instance (priority := low) [∀ i, (I i).IsTwoSided] : (pi I).IsTwoSided :=
⟨fun _b hb i ↦ mul_mem_right _ _ (hb i)⟩
variable {I J}
theorem single_mem_pi [DecidableEq ι] {i : ι} {r : R i} (hr : r ∈ I i) : Pi.single i r ∈ pi I := by
intro j
obtain rfl | ne := eq_or_ne i j
· simpa
· simp [ne]
@[simp] theorem pi_le_pi_iff : pi I ≤ pi J ↔ I ≤ J where
mp le i r hr := by classical simpa using le (single_mem_pi hr) i
mpr le r hr i := le i (hr i)
end Pi
section Commute
variable {α : Type*} [Semiring α] (I : Ideal α) {a b : α}
theorem add_pow_mem_of_pow_mem_of_le_of_commute {m n k : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≤ k + 1)
(hab : Commute a b) :
(a + b) ^ k ∈ I := by
simp_rw [hab.add_pow, ← Nat.cast_comm]
apply I.sum_mem
intro c _
apply mul_mem_left
by_cases h : m ≤ c
· rw [hab.pow_pow]
exact I.mul_mem_left _ (I.pow_mem_of_pow_mem ha h)
· refine I.mul_mem_left _ (I.pow_mem_of_pow_mem hb ?_)
cutsat
theorem add_pow_add_pred_mem_of_pow_mem_of_commute {m n : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hab : Commute a b) :
(a + b) ^ (m + n - 1) ∈ I :=
I.add_pow_mem_of_pow_mem_of_le_of_commute ha hb (by rw [← Nat.sub_le_iff_le_add]) hab
end Commute
end Ideal
end Semiring
section CommSemiring
variable {a b : α}
-- A separate namespace definition is needed because the variables were historically in a different
-- order.
namespace Ideal
variable [CommSemiring α] (I : Ideal α)
theorem add_pow_mem_of_pow_mem_of_le {m n k : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≤ k + 1) :
(a + b) ^ k ∈ I :=
I.add_pow_mem_of_pow_mem_of_le_of_commute ha hb hk (Commute.all ..)
theorem add_pow_add_pred_mem_of_pow_mem {m n : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) :
(a + b) ^ (m + n - 1) ∈ I :=
I.add_pow_add_pred_mem_of_pow_mem_of_commute ha hb (Commute.all ..)
theorem pow_multiset_sum_mem_span_pow [DecidableEq α] (s : Multiset α) (n : ℕ) :
s.sum ^ (Multiset.card s * n + 1) ∈
span ((s.map fun (x : α) ↦ x ^ (n + 1)).toFinset : Set α) := by
induction s using Multiset.induction_on with
| empty => simp
| cons a s hs => ?_
simp only [Finset.coe_insert, Multiset.map_cons, Multiset.toFinset_cons, Multiset.sum_cons,
Multiset.card_cons, add_pow]
refine Submodule.sum_mem _ ?_
intro c _hc
rw [mem_span_insert]
by_cases! h : n + 1 ≤ c
· refine ⟨a ^ (c - (n + 1)) * s.sum ^ ((Multiset.card s + 1) * n + 1 - c) *
((Multiset.card s + 1) * n + 1).choose c, 0, Submodule.zero_mem _, ?_⟩
rw [mul_comm _ (a ^ (n + 1))]
simp_rw [← mul_assoc]
rw [← pow_add, add_zero, add_tsub_cancel_of_le h]
· use 0
simp_rw [zero_mul, zero_add]
refine ⟨_, ?_, rfl⟩
replace h : c ≤ n := Nat.lt_succ_iff.mp h
have : (Multiset.card s + 1) * n + 1 - c = Multiset.card s * n + 1 + (n - c) := by
rw [add_mul, one_mul, add_assoc, add_comm n 1, ← add_assoc, add_tsub_assoc_of_le h]
rw [this, pow_add]
simp_rw [mul_assoc, mul_comm (s.sum ^ (Multiset.card s * n + 1)), ← mul_assoc]
exact mul_mem_left _ _ hs
theorem sum_pow_mem_span_pow {ι} (s : Finset ι) (f : ι → α) (n : ℕ) :
(∑ i ∈ s, f i) ^ (s.card * n + 1) ∈ span ((fun i => f i ^ (n + 1)) '' s) := by
classical
simpa only [Multiset.card_map, Multiset.map_map, comp_apply, Multiset.toFinset_map,
Finset.coe_image, Finset.val_toFinset] using pow_multiset_sum_mem_span_pow (s.1.map f) n
theorem span_pow_eq_top (s : Set α) (hs : span s = ⊤) (n : ℕ) :
span ((fun (x : α) => x ^ n) '' s) = ⊤ := by
rw [eq_top_iff_one]
rcases n with - | n
· obtain rfl | ⟨x, hx⟩ := eq_empty_or_nonempty s
· rw [Set.image_empty, hs]
trivial
· exact subset_span ⟨_, hx, pow_zero _⟩
rw [eq_top_iff_one, span, Finsupp.mem_span_iff_linearCombination] at hs
rcases hs with ⟨f, hf⟩
simp only [Finsupp.linearCombination, Finsupp.coe_lsum, Finsupp.sum, LinearMap.coe_smulRight,
LinearMap.id_coe, id_eq, smul_eq_mul] at hf
have := sum_pow_mem_span_pow f.support (fun a => f a * a) n
rw [hf, one_pow] at this
refine span_le.mpr ?_ this
rintro _ hx
simp_rw [Set.mem_image] at hx
rcases hx with ⟨x, _, rfl⟩
have : span ({(x : α) ^ (n + 1)} : Set α) ≤ span ((fun x : α => x ^ (n + 1)) '' s) := by
rw [span_le, Set.singleton_subset_iff]
exact subset_span ⟨x, x.prop, rfl⟩
refine this ?_
rw [mul_pow, mem_span_singleton]
exact ⟨f x ^ (n + 1), mul_comm _ _⟩
theorem span_range_pow_eq_top (s : Set α) (hs : span s = ⊤) (n : s → ℕ) :
span (Set.range fun x ↦ x.1 ^ n x) = ⊤ := by
have ⟨t, hts, mem⟩ := Submodule.mem_span_finite_of_mem_span ((eq_top_iff_one _).mp hs)
refine top_unique ((span_pow_eq_top _ ((eq_top_iff_one _).mpr mem) <|
t.attach.sup fun x ↦ n ⟨x, hts x.2⟩).ge.trans <| span_le.mpr ?_)
rintro _ ⟨x, hxt, rfl⟩
rw [← Nat.sub_add_cancel (Finset.le_sup <| t.mem_attach ⟨x, hxt⟩)]
simp_rw [pow_add]
exact mul_mem_left _ _ (subset_span ⟨_, rfl⟩)
theorem prod_mem {ι : Type*} {f : ι → α} {s : Finset ι}
(I : Ideal α) {i : ι} (hi : i ∈ s) (hfi : f i ∈ I) :
∏ i ∈ s, f i ∈ I := by
classical
rw [Finset.prod_eq_prod_diff_singleton_mul hi]
exact Ideal.mul_mem_left _ _ hfi
end Ideal
end CommSemiring
section DivisionSemiring
variable {K : Type*} [DivisionSemiring K] (I : Ideal K)
namespace Ideal
variable (K) in
/-- A bijection between (left) ideals of a division ring and `{0, 1}`, sending `⊥` to `0`
and `⊤` to `1`. -/
def equivFinTwo [DecidableEq (Ideal K)] : Ideal K ≃ Fin 2 where
toFun := fun I ↦ if I = ⊥ then 0 else 1
invFun := ![⊥, ⊤]
left_inv := fun I ↦ by rcases eq_bot_or_top I with rfl | rfl <;> simp
right_inv := fun i ↦ by fin_cases i <;> simp
instance : Finite (Ideal K) := let _i := Classical.decEq (Ideal K); ⟨equivFinTwo K⟩
/-- Ideals of a `DivisionSemiring` are a simple order. Thanks to the way abbreviations work,
this automatically gives an `IsSimpleModule K` instance. -/
instance isSimpleOrder : IsSimpleOrder (Ideal K) :=
⟨eq_bot_or_top⟩
end Ideal
end DivisionSemiring
-- TODO: consider moving the lemmas below out of the `Ring` namespace since they are
-- about `CommSemiring`s.
namespace Ring
variable {R : Type*} [CommSemiring R]
theorem exists_not_isUnit_of_not_isField [Nontrivial R] (hf : ¬IsField R) :
∃ (x : R) (_hx : x ≠ (0 : R)), ¬IsUnit x := by
have : ¬_ := fun h => hf ⟨exists_pair_ne R, mul_comm, h⟩
simp_rw [isUnit_iff_exists_inv]
push_neg at this ⊢
obtain ⟨x, hx, not_unit⟩ := this
exact ⟨x, hx, not_unit⟩
theorem not_isField_iff_exists_ideal_bot_lt_and_lt_top [Nontrivial R] :
¬IsField R ↔ ∃ I : Ideal R, ⊥ < I ∧ I < ⊤ := by
constructor
· intro h
obtain ⟨x, nz, nu⟩ := exists_not_isUnit_of_not_isField h
use Ideal.span {x}
rw [bot_lt_iff_ne_bot, lt_top_iff_ne_top]
exact ⟨mt Ideal.span_singleton_eq_bot.mp nz, mt Ideal.span_singleton_eq_top.mp nu⟩
· rintro ⟨I, bot_lt, lt_top⟩ hf
obtain ⟨x, mem, ne_zero⟩ := SetLike.exists_of_lt bot_lt
rw [Submodule.mem_bot] at ne_zero
obtain ⟨y, hy⟩ := hf.mul_inv_cancel ne_zero
rw [lt_top_iff_ne_top, Ne, Ideal.eq_top_iff_one, ← hy] at lt_top
exact lt_top (I.mul_mem_right _ mem)
theorem not_isField_iff_exists_prime [Nontrivial R] :
¬IsField R ↔ ∃ p : Ideal R, p ≠ ⊥ ∧ p.IsPrime :=
not_isField_iff_exists_ideal_bot_lt_and_lt_top.trans
⟨fun ⟨I, bot_lt, lt_top⟩ =>
let ⟨p, hp, le_p⟩ := I.exists_le_maximal (lt_top_iff_ne_top.mp lt_top)
⟨p, bot_lt_iff_ne_bot.mp (lt_of_lt_of_le bot_lt le_p), hp.isPrime⟩,
fun ⟨p, ne_bot, Prime⟩ => ⟨p, bot_lt_iff_ne_bot.mpr ne_bot, lt_top_iff_ne_top.mpr Prime.1⟩⟩
/-- Also see `Ideal.isSimpleOrder` for the forward direction as an instance when `R` is a
division (semi)ring.
This result actually holds for all division semirings, but we lack the predicate to state it. -/
theorem isField_iff_isSimpleOrder_ideal : IsField R ↔ IsSimpleOrder (Ideal R) := by
cases subsingleton_or_nontrivial R
· exact
⟨fun h => (not_isField_of_subsingleton _ h).elim, fun h =>
(false_of_nontrivial_of_subsingleton <| Ideal R).elim⟩
rw [← not_iff_not, Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top, ← not_iff_not]
push_neg
simp_rw [lt_top_iff_ne_top, bot_lt_iff_ne_bot, ← or_iff_not_imp_left, not_ne_iff]
exact ⟨fun h => ⟨h⟩, fun h => h.2⟩
/-- When a ring is not a field, the maximal ideals are nontrivial. -/
theorem ne_bot_of_isMaximal_of_not_isField [Nontrivial R] {M : Ideal R} (max : M.IsMaximal)
(not_field : ¬IsField R) : M ≠ ⊥ := by
rintro h
rw [h] at max
rcases max with ⟨⟨_h1, h2⟩⟩
obtain ⟨I, hIbot, hItop⟩ := not_isField_iff_exists_ideal_bot_lt_and_lt_top.mp not_field
exact ne_of_lt hItop (h2 I hIbot)
end Ring
namespace Ideal
variable {R : Type*} [CommSemiring R] [Nontrivial R]
theorem bot_lt_of_maximal (M : Ideal R) [hm : M.IsMaximal] (non_field : ¬IsField R) : ⊥ < M := by
rcases Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top.1 non_field with ⟨I, Ibot, Itop⟩
constructor; · simp
intro mle
apply lt_irrefl (⊤ : Ideal R)
have : M = ⊥ := eq_bot_iff.mpr mle
rw [← this] at Ibot
rwa [hm.1.2 I Ibot] at Itop
end Ideal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Operations.lean | import Mathlib.Algebra.Algebra.Operations
import Mathlib.Algebra.Module.BigOperators
import Mathlib.Data.Fintype.Lattice
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Ideal.Basic
import Mathlib.RingTheory.Nilpotent.Defs
import Mathlib.RingTheory.NonUnitalSubsemiring.Basic
import Mathlib.Tactic.Order
/-!
# More operations on modules and ideals
-/
assert_not_exists Module.Basis -- See `RingTheory.Ideal.Basis`
Submodule.hasQuotient -- See `RingTheory.Ideal.Quotient.Operations`
universe u v w x
open Pointwise
namespace Submodule
lemma coe_span_smul {R' M' : Type*} [CommSemiring R'] [AddCommMonoid M'] [Module R' M']
(s : Set R') (N : Submodule R' M') :
(Ideal.span s : Set R') • N = s • N :=
set_smul_eq_of_le _ _ _
(by rintro r n hr hn
induction hr using Submodule.span_induction with
| mem _ h => exact mem_set_smul_of_mem_mem h hn
| zero => rw [zero_smul]; exact Submodule.zero_mem _
| add _ _ _ _ ihr ihs => rw [add_smul]; exact Submodule.add_mem _ ihr ihs
| smul _ _ hr =>
rw [mem_span_set] at hr
obtain ⟨c, hc, rfl⟩ := hr
rw [Finsupp.sum, Finset.smul_sum, Finset.sum_smul]
refine Submodule.sum_mem _ fun i hi => ?_
rw [← mul_smul, smul_eq_mul, mul_comm, mul_smul]
exact mem_set_smul_of_mem_mem (hc hi) <| Submodule.smul_mem _ _ hn) <|
set_smul_mono_left _ Submodule.subset_span
lemma span_singleton_toAddSubgroup_eq_zmultiples (a : ℤ) :
(span ℤ {a}).toAddSubgroup = AddSubgroup.zmultiples a := by
ext i
simp [Ideal.mem_span_singleton', AddSubgroup.mem_zmultiples_iff]
@[simp] lemma _root_.Ideal.span_singleton_toAddSubgroup_eq_zmultiples (a : ℤ) :
(Ideal.span {a}).toAddSubgroup = AddSubgroup.zmultiples a :=
Submodule.span_singleton_toAddSubgroup_eq_zmultiples _
variable {R : Type u} {M : Type v} {M' F G : Type*}
section Semiring
variable [Semiring R] [AddCommMonoid M] [Module R M]
/-- This duplicates the global `smul_eq_mul`, but doesn't have to unfold anywhere near as much to
apply. -/
protected theorem _root_.Ideal.smul_eq_mul (I J : Ideal R) : I • J = I * J :=
rfl
variable {I J : Ideal R} {N : Submodule R M}
theorem smul_le_right : I • N ≤ N :=
smul_le.2 fun r _ _ ↦ N.smul_mem r
theorem map_le_smul_top (I : Ideal R) (f : R →ₗ[R] M) :
Submodule.map f I ≤ I • (⊤ : Submodule R M) := by
rintro _ ⟨y, hy, rfl⟩
rw [← mul_one y, ← smul_eq_mul, f.map_smul]
exact smul_mem_smul hy mem_top
variable (I J N)
@[simp]
theorem top_smul : (⊤ : Ideal R) • N = N :=
le_antisymm smul_le_right fun r hri => one_smul R r ▸ smul_mem_smul mem_top hri
protected theorem mul_smul : (I * J) • N = I • J • N :=
Submodule.smul_assoc _ _ _
theorem mem_of_span_top_of_smul_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M)
(H : ∀ r : s, (r : R) • x ∈ M') : x ∈ M' := by
suffices LinearMap.range (LinearMap.toSpanSingleton R M x) ≤ M' by
rw [← LinearMap.toSpanSingleton_one R M x]
exact this (LinearMap.mem_range_self _ 1)
rw [LinearMap.range_eq_map, ← hs, map_le_iff_le_comap, Ideal.span, span_le]
exact fun r hr ↦ H ⟨r, hr⟩
variable {M' : Type w} [AddCommMonoid M'] [Module R M']
@[simp]
theorem map_smul'' (f : M →ₗ[R] M') : (I • N).map f = I • N.map f :=
le_antisymm
(map_le_iff_le_comap.2 <|
smul_le.2 fun r hr n hn =>
show f (r • n) ∈ I • N.map f from
(f.map_smul r n).symm ▸ smul_mem_smul hr (mem_map_of_mem hn)) <|
smul_le.2 fun r hr _ hn =>
let ⟨p, hp, hfp⟩ := mem_map.1 hn
hfp ▸ f.map_smul r p ▸ mem_map_of_mem (smul_mem_smul hr hp)
theorem mem_smul_top_iff (N : Submodule R M) (x : N) :
x ∈ I • (⊤ : Submodule R N) ↔ (x : M) ∈ I • N := by
have : Submodule.map N.subtype (I • ⊤) = I • N := by
rw [Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype]
simp [← this, -map_smul'']
@[simp]
theorem smul_comap_le_comap_smul (f : M →ₗ[R] M') (S : Submodule R M') (I : Ideal R) :
I • S.comap f ≤ (I • S).comap f := by
refine Submodule.smul_le.mpr fun r hr x hx => ?_
rw [Submodule.mem_comap] at hx ⊢
rw [f.map_smul]
exact Submodule.smul_mem_smul hr hx
variable {I}
theorem mem_smul_span_singleton [I.IsTwoSided] {m : M} {x : M} :
x ∈ I • span R ({m} : Set M) ↔ ∃ y ∈ I, y • m = x :=
⟨fun hx =>
smul_induction_on hx
(fun r hri _ hnm =>
let ⟨s, hs⟩ := mem_span_singleton.1 hnm
⟨r * s, I.mul_mem_right _ hri, hs ▸ mul_smul r s m⟩)
fun m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩ =>
⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩,
fun ⟨_, hyi, hy⟩ => hy ▸ smul_mem_smul hyi (subset_span <| Set.mem_singleton m)⟩
variable (S : Set R) (T : Set M)
theorem span_smul_span [(Ideal.span S).IsTwoSided] :
Ideal.span S • span R T = span R (S • T) :=
le_antisymm (smul_le.mpr fun r hr m hm ↦ by
revert r
refine span_induction (fun m hm r hr ↦ span_induction
(fun r hr ↦ subset_span ⟨r, hr, m, hm, rfl⟩)
(by rw [zero_smul]; exact zero_mem _)
(fun _ _ _ _ h₁ h₂ ↦ by rw [add_smul]; exact add_mem h₁ h₂)
(fun _ _ _ h ↦ by rw [smul_assoc]; exact smul_mem _ _ h) hr)
(fun _ _ ↦ by rw [smul_zero]; exact zero_mem _)
(fun _ _ _ _ h₁ h₂ r hr ↦ by rw [smul_add]; exact add_mem (h₁ r hr) (h₂ r hr))
(fun r' m hm mem r hr ↦ by rw [← mul_smul]; exact mem _ (Ideal.mul_mem_right _ _ hr)) hm) <|
span_le.mpr fun m ↦ by
rintro ⟨s, hs, t, ht, rfl⟩
exact smul_mem_smul (subset_span hs) (subset_span ht)
variable [I.IsTwoSided]
theorem mem_smul_span {s : Set M} {x : M} :
x ∈ I • Submodule.span R s ↔ x ∈ Submodule.span R ((I : Set R) • s) := by
rw [← I.span_eq] at *
rw [Submodule.span_smul_span, I.span_eq]
variable (I)
/-- If `x` is an `I`-multiple of the submodule spanned by `f '' s`,
then we can write `x` as an `I`-linear combination of the elements of `f '' s`. -/
theorem mem_ideal_smul_span_iff_exists_sum {ι : Type*} (f : ι → M) (x : M) :
x ∈ I • span R (Set.range f) ↔
∃ (a : ι →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by
constructor; swap
· rintro ⟨a, ha, rfl⟩
exact Submodule.sum_mem _ fun c _ => smul_mem_smul (ha c) <| subset_span <| Set.mem_range_self _
refine fun hx => span_induction ?_ ?_ ?_ ?_ (mem_smul_span.mp hx)
· rintro x ⟨y, hy, x, ⟨i, rfl⟩, rfl⟩
refine ⟨Finsupp.single i y, fun j => ?_, ?_⟩
· letI := Classical.decEq ι
rw [Finsupp.single_apply]
split_ifs
· assumption
· exact I.zero_mem
refine @Finsupp.sum_single_index ι R M _ _ i _ (fun i y => y • f i) ?_
simp
· exact ⟨0, fun _ => I.zero_mem, Finsupp.sum_zero_index⟩
· rintro x y - - ⟨ax, hax, rfl⟩ ⟨ay, hay, rfl⟩
refine ⟨ax + ay, fun i => I.add_mem (hax i) (hay i), Finsupp.sum_add_index' ?_ ?_⟩ <;>
intros <;> simp only [zero_smul, add_smul]
· rintro c x - ⟨a, ha, rfl⟩
refine ⟨c • a, fun i => I.mul_mem_left c (ha i), ?_⟩
rw [Finsupp.sum_smul_index, Finsupp.smul_sum] <;> intros <;> simp only [zero_smul, mul_smul]
theorem mem_ideal_smul_span_iff_exists_sum' {ι : Type*} (s : Set ι) (f : ι → M) (x : M) :
x ∈ I • span R (f '' s) ↔
∃ (a : s →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by
rw [← Submodule.mem_ideal_smul_span_iff_exists_sum, ← Set.image_eq_range]
end Semiring
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
open Pointwise
variable {I : Ideal R} {N : Submodule R M}
theorem smul_eq_map₂ : I • N = Submodule.map₂ (LinearMap.lsmul R M) I N :=
le_antisymm (smul_le.mpr fun _m hm _n ↦ Submodule.apply_mem_map₂ _ hm)
(map₂_le.mpr fun _m hm _n ↦ smul_mem_smul hm)
variable (S : Set R) (T : Set M)
theorem ideal_span_singleton_smul (r : R) (N : Submodule R M) :
(Ideal.span {r} : Ideal R) • N = r • N := by
conv_lhs => rw [← span_eq N, span_smul_span]
simpa using span_eq (r • N)
/-- Given `s`, a generating set of `R`, to check that an `x : M` falls in a
submodule `M'` of `x`, we only need to show that `r ^ n • x ∈ M'` for some `n` for each `r : s`. -/
theorem mem_of_span_eq_top_of_smul_pow_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤)
(x : M) (H : ∀ r : s, ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M') : x ∈ M' := by
choose f hf using H
apply M'.mem_of_span_top_of_smul_mem _ (Ideal.span_range_pow_eq_top s hs f)
rintro ⟨_, r, hr, rfl⟩
exact hf r
open Pointwise in
@[simp]
theorem map_pointwise_smul (r : R) (N : Submodule R M) (f : M →ₗ[R] M') :
(r • N).map f = r • N.map f := by
simp_rw [← ideal_span_singleton_smul, map_smul'']
end CommSemiring
end Submodule
namespace Ideal
section Add
variable {R : Type u} [Semiring R]
@[simp]
theorem add_eq_sup {I J : Ideal R} : I + J = I ⊔ J :=
rfl
@[simp]
theorem zero_eq_bot : (0 : Ideal R) = ⊥ :=
rfl
@[simp]
theorem sum_eq_sup {ι : Type*} (s : Finset ι) (f : ι → Ideal R) : s.sum f = s.sup f :=
rfl
end Add
section Semiring
variable {R : Type u} [Semiring R] {I J K L : Ideal R}
@[simp, grind =]
theorem one_eq_top : (1 : Ideal R) = ⊤ := by
rw [Submodule.one_eq_span, ← Ideal.span, Ideal.span_singleton_one]
theorem add_eq_one_iff : I + J = 1 ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by
rw [one_eq_top, eq_top_iff_one, add_eq_sup, Submodule.mem_sup]
theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J :=
Submodule.smul_mem_smul hr hs
theorem bot_pow {n : ℕ} (hn : n ≠ 0) :
(⊥ : Ideal R) ^ n = ⊥ := Submodule.bot_pow hn
theorem pow_mem_pow {x : R} (hx : x ∈ I) (n : ℕ) : x ^ n ∈ I ^ n :=
Submodule.pow_mem_pow _ hx _
theorem mul_le : I * J ≤ K ↔ ∀ r ∈ I, ∀ s ∈ J, r * s ∈ K :=
Submodule.smul_le
theorem mul_le_left : I * J ≤ J :=
mul_le.2 fun _ _ _ => J.mul_mem_left _
@[simp]
theorem sup_mul_left_self : I ⊔ J * I = I :=
sup_eq_left.2 mul_le_left
@[simp]
theorem mul_left_self_sup : J * I ⊔ I = I :=
sup_eq_right.2 mul_le_left
theorem mul_le_right [I.IsTwoSided] : I * J ≤ I :=
mul_le.2 fun _ hr _ _ ↦ I.mul_mem_right _ hr
@[simp]
theorem sup_mul_right_self [I.IsTwoSided] : I ⊔ I * J = I :=
sup_eq_left.2 mul_le_right
@[simp]
theorem mul_right_self_sup [I.IsTwoSided] : I * J ⊔ I = I :=
sup_eq_right.2 mul_le_right
protected theorem mul_assoc : I * J * K = I * (J * K) :=
Submodule.smul_assoc I J K
variable (I)
theorem mul_bot : I * ⊥ = ⊥ := by simp
theorem bot_mul : ⊥ * I = ⊥ := by simp
@[simp]
theorem top_mul : ⊤ * I = I :=
Submodule.top_smul I
variable {I}
theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L :=
Submodule.smul_mono hik hjl
theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K :=
Submodule.smul_mono_left h
theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K :=
smul_mono_right I h
variable (I J K)
theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K :=
Submodule.smul_sup I J K
theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K :=
Submodule.sup_smul I J K
theorem mul_iSup {ι : Sort*} (J : ι → Ideal R) :
I * (⨆ i, J i) = ⨆ i, I * J i :=
Submodule.smul_iSup
theorem iSup_mul {ι : Sort*} (J : ι → Ideal R) (I : Ideal R) :
(⨆ i, J i) * I = ⨆ i, J i * I :=
Submodule.iSup_smul
variable {I J K}
theorem pow_le_pow_right {m n : ℕ} (h : m ≤ n) : I ^ n ≤ I ^ m := by
obtain _ | m := m
· rw [Submodule.pow_zero, one_eq_top]; exact le_top
obtain ⟨n, rfl⟩ := Nat.exists_eq_add_of_le h
rw [add_comm, Submodule.pow_add _ m.add_one_ne_zero]
exact mul_le_left
theorem pow_le_self {n : ℕ} (hn : n ≠ 0) : I ^ n ≤ I :=
calc
I ^ n ≤ I ^ 1 := pow_le_pow_right (Nat.pos_of_ne_zero hn)
_ = I := Submodule.pow_one _
theorem pow_right_mono (e : I ≤ J) (n : ℕ) : I ^ n ≤ J ^ n := by
induction n with
| zero => rw [Submodule.pow_zero, Submodule.pow_zero]
| succ _ hn =>
rw [Submodule.pow_succ, Submodule.pow_succ]
exact Ideal.mul_mono hn e
namespace IsTwoSided
instance (priority := low) [J.IsTwoSided] : (I * J).IsTwoSided :=
⟨fun b ha ↦ Submodule.mul_induction_on ha
(fun i hi j hj ↦ by rw [mul_assoc]; exact mul_mem_mul hi (mul_mem_right _ _ hj))
fun x y hx hy ↦ by rw [right_distrib]; exact add_mem hx hy⟩
variable [I.IsTwoSided] (m n : ℕ)
instance (priority := low) : (I ^ n).IsTwoSided :=
n.rec
(by rw [Submodule.pow_zero, one_eq_top]; infer_instance)
(fun _ _ ↦ by rw [Submodule.pow_succ]; infer_instance)
protected theorem mul_one : I * 1 = I :=
mul_le_right.antisymm
fun i hi ↦ mul_one i ▸ mul_mem_mul hi (one_eq_top (R := R) ▸ Submodule.mem_top)
protected theorem pow_add : I ^ (m + n) = I ^ m * I ^ n := by
obtain rfl | h := eq_or_ne n 0
· rw [add_zero, Submodule.pow_zero, IsTwoSided.mul_one]
· exact Submodule.pow_add _ h
protected theorem pow_succ : I ^ (n + 1) = I * I ^ n := by
rw [add_comm, IsTwoSided.pow_add, Submodule.pow_one]
end IsTwoSided
@[simp]
theorem mul_eq_bot [NoZeroDivisors R] : I * J = ⊥ ↔ I = ⊥ ∨ J = ⊥ :=
⟨fun hij =>
or_iff_not_imp_left.mpr fun I_ne_bot =>
J.eq_bot_iff.mpr fun j hj =>
let ⟨i, hi, ne0⟩ := I.ne_bot_iff.mp I_ne_bot
Or.resolve_left (mul_eq_zero.mp ((I * J).eq_bot_iff.mp hij _ (mul_mem_mul hi hj))) ne0,
fun h => by obtain rfl | rfl := h; exacts [bot_mul _, mul_bot _]⟩
instance [NoZeroDivisors R] : NoZeroDivisors (Ideal R) where
eq_zero_or_eq_zero_of_mul_eq_zero := mul_eq_bot.1
instance {S A : Type*} [Semiring S] [SMul R S] [AddCommMonoid A] [Module R A] [Module S A]
[IsScalarTower R S A] [NoZeroSMulDivisors R A] {I : Submodule S A} : NoZeroSMulDivisors R I :=
Submodule.noZeroSMulDivisors (Submodule.restrictScalars R I)
theorem span_mul_span (S T : Set R) [(span S).IsTwoSided] :
span S * span T = span (S * T) :=
Submodule.span_smul_span S T
theorem span_mul_span' (S T : Set R) [(span S).IsTwoSided] : span S * span T = span (S * T) :=
(span_mul_span S T).trans <| congr_arg span <| Set.ext <| by simp [Set.mem_mul, eq_comm]
theorem span_singleton_mul_span_singleton (r s : R) [(span {r}).IsTwoSided] :
span {r} * span {s} = (span {r * s} : Ideal R) := by
rw [span_mul_span', Set.singleton_mul_singleton]
theorem span_singleton_pow (s : R) [(span {s}).IsTwoSided] (n : ℕ) :
span {s} ^ n = (span {s ^ n} : Ideal R) := by
induction n with
| zero => simp [Submodule.pow_zero, Set.singleton_one]
| succ n ih =>
obtain rfl | ne := eq_or_ne n 0; · simp [Submodule.pow_one]
simp only [Submodule.pow_succ' _ ne, pow_succ', ih, span_singleton_mul_span_singleton]
theorem mem_mul_span_singleton {x y : R} {I : Ideal R} [I.IsTwoSided] :
x ∈ I * span {y} ↔ ∃ z ∈ I, z * y = x :=
Submodule.mem_smul_span_singleton
theorem span_singleton_mul_left_mono [IsDomain R] [I.IsTwoSided] [J.IsTwoSided]
{x : R} (hx : x ≠ 0) : I * span {x} ≤ J * span {x} ↔ I ≤ J := by
simp [SetLike.le_def, mem_mul_span_singleton, hx]
theorem span_singleton_mul_left_inj [IsDomain R] [I.IsTwoSided] [J.IsTwoSided]
{x : R} (hx : x ≠ 0) : I * span {x} = J * span {x} ↔ I = J := by
simp only [le_antisymm_iff, span_singleton_mul_left_mono hx]
theorem mul_le_inf [I.IsTwoSided] : I * J ≤ I ⊓ J :=
mul_le.2 fun r hri s hsj => ⟨I.mul_mem_right s hri, J.mul_mem_left r hsj⟩
theorem sup_mul_eq_of_coprime_left [I.IsTwoSided] (h : I ⊔ J = ⊤) : I ⊔ J * K = I ⊔ K :=
le_antisymm (sup_le_sup_left mul_le_left _) fun i hi => by
rw [eq_top_iff_one] at h; rw [Submodule.mem_sup] at h hi ⊢
obtain ⟨i1, hi1, j, hj, h⟩ := h; obtain ⟨i', hi', k, hk, rfl⟩ := hi
refine ⟨_, add_mem hi' (mul_mem_right k _ hi1), _, mul_mem_mul hj hk, ?_⟩
rw [add_assoc, ← add_mul, h, one_mul]
theorem sup_mul_eq_of_coprime_right [J.IsTwoSided] (h : I ⊔ K = ⊤) : I ⊔ J * K = I ⊔ J :=
le_antisymm (sup_le_sup_left mul_le_right _) fun i hi ↦ by
rw [eq_top_iff_one] at h; rw [Submodule.mem_sup] at h hi ⊢
obtain ⟨i1, hi1, k, hk, h⟩ := h; obtain ⟨i', hi', j, hj, rfl⟩ := hi
refine ⟨_, add_mem hi' (mul_mem_left _ j hi1), _, mul_mem_mul hj hk, ?_⟩
rw [add_assoc, ← mul_add, h, mul_one]
theorem mul_sup_eq_of_coprime_left [J.IsTwoSided] (h : I ⊔ J = ⊤) : I * K ⊔ J = K ⊔ J := by
rw [sup_comm] at h
rw [sup_comm, sup_mul_eq_of_coprime_left h, sup_comm]
theorem mul_sup_eq_of_coprime_right [I.IsTwoSided] (h : K ⊔ J = ⊤) : I * K ⊔ J = I ⊔ J := by
rw [sup_comm] at h
rw [sup_comm, sup_mul_eq_of_coprime_right h, sup_comm]
variable {ι : Type*}
theorem sup_iInf_eq_top {s : Finset ι} {J : ι → Ideal R} [∀ i, (J i).IsTwoSided]
(h : ∀ i, i ∈ s → I ⊔ J i = ⊤) : (I ⊔ ⨅ i ∈ s, J i) = ⊤ := by
classical
exact s.induction_on' (by simp) fun {i t} his hts hit eq_top ↦ top_unique <| by
rw [Finset.iInf_insert, inf_comm]
refine le_trans ?_ (sup_le_sup_left mul_le_inf _)
simpa only [sup_mul_eq_of_coprime_right (h _ his)] using eq_top.ge
theorem iInf_sup_eq_top {s : Finset ι} {J : ι → Ideal R} [∀ i, (J i).IsTwoSided]
(h : ∀ i, i ∈ s → J i ⊔ I = ⊤) : (⨅ i ∈ s, J i) ⊔ I = ⊤ := by
rw [sup_comm, sup_iInf_eq_top]; intro i hi; rw [sup_comm, h i hi]
theorem sup_pow_eq_top [I.IsTwoSided] {n : ℕ} (h : I ⊔ J = ⊤) : I ⊔ J ^ n = ⊤ := by
induction n with
| zero => simp [J.pow_zero]
| succ n ih => rwa [J.pow_succ, sup_mul_eq_of_coprime_left ih]
theorem sup_pow_eq_top' [J.IsTwoSided] {n : ℕ} (h : I ⊔ J = ⊤) : I ⊔ J ^ n = ⊤ := by
induction n with
| zero => simp [J.pow_zero]
| succ n ih =>
obtain rfl | hn := eq_or_ne n 0; · simpa [J.pow_one] using h
rwa [J.pow_succ' hn, sup_mul_eq_of_coprime_right ih]
theorem pow_sup_eq_top [I.IsTwoSided] {n : ℕ} (h : I ⊔ J = ⊤) : I ^ n ⊔ J = ⊤ := by
rw [sup_comm, sup_pow_eq_top' (sup_comm I J ▸ h)]
theorem pow_sup_eq_top' [J.IsTwoSided] {n : ℕ} (h : I ⊔ J = ⊤) : I ^ n ⊔ J = ⊤ := by
rw [sup_comm, sup_pow_eq_top (sup_comm I J ▸ h)]
theorem pow_sup_pow_eq_top [I.IsTwoSided] {m n : ℕ} (h : I ⊔ J = ⊤) : I ^ m ⊔ J ^ n = ⊤ :=
pow_sup_eq_top (sup_pow_eq_top h)
theorem pow_sup_pow_eq_top' [J.IsTwoSided] {m n : ℕ} (h : I ⊔ J = ⊤) : I ^ m ⊔ J ^ n = ⊤ :=
pow_sup_eq_top' (sup_pow_eq_top' h)
variable (I) in
@[simp]
theorem mul_top [I.IsTwoSided] : I * ⊤ = I :=
le_antisymm (mul_le.mpr fun _i hi _r _ ↦ mul_mem_right _ _ hi)
fun i hi ↦ mul_one i ▸ mul_mem_mul hi Submodule.mem_top
theorem span_pair_mul_span_pair (w x y z : R) [(span {w, x}).IsTwoSided] :
(span {w, x} : Ideal R) * span {y, z} = span {w * y, w * z, x * y, x * z} := by
rw [span_mul_span']; congr; ext r; simp [Set.mem_mul, or_assoc, eq_comm (a := r)]
variable (R) in
theorem top_pow (n : ℕ) : (⊤ ^ n : Ideal R) = ⊤ :=
Nat.recOn n one_eq_top fun n ih => by rw [Submodule.pow_succ, ih, top_mul]
@[simp]
theorem pow_eq_top_iff {n : ℕ} :
I ^ n = ⊤ ↔ I = ⊤ ∨ n = 0 := by
refine ⟨fun h ↦ or_iff_not_imp_right.mpr
fun hn ↦ (eq_top_iff_one _).mpr <| pow_le_self hn <| (eq_top_iff_one _).mp h, ?_⟩
rintro (h | h)
· rw [h, top_pow]
· rw [h, Submodule.pow_zero, one_eq_top]
theorem natCast_eq_top {n : ℕ} (hn : n ≠ 0) : (n : Ideal R) = ⊤ := by
induction n with
| zero => exact (hn rfl).elim
| succ n ih =>
obtain rfl | n := n; · rw [Nat.cast_one, one_eq_top]
rw [Nat.cast_succ, ih n.succ_ne_zero, add_eq_sup, top_sup_eq]
/-- `3 : Ideal R` is *not* the ideal generated by 3 (which would be spelt
`Ideal.span {3}`), it is simply `1 + 1 + 1 = ⊤`. -/
theorem ofNat_eq_top {n : ℕ} [n.AtLeastTwo] : (ofNat(n) : Ideal R) = ⊤ :=
natCast_eq_top (NeZero.ne _)
theorem pow_eq_zero_of_mem {I : Ideal R} {n m : ℕ} (hnI : I ^ n = 0) (hmn : n ≤ m) {x : R}
(hx : x ∈ I) : x ^ m = 0 := by
simpa [hnI] using pow_le_pow_right hmn <| pow_mem_pow hx m
end Semiring
section MulAndRadical
variable {R : Type u} {ι : Type*} [CommSemiring R]
variable {I J K L : Ideal R}
theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J :=
mul_comm r s ▸ mul_mem_mul hr hs
theorem prod_mem_prod {ι : Type*} {s : Finset ι} {I : ι → Ideal R} {x : ι → R} :
(∀ i ∈ s, x i ∈ I i) → (∏ i ∈ s, x i) ∈ ∏ i ∈ s, I i := by
classical
refine Finset.induction_on s ?_ ?_
· grind [Submodule.mem_top]
· grind [mul_mem_mul]
lemma sup_pow_add_le_pow_sup_pow {n m : ℕ} : (I ⊔ J) ^ (n + m) ≤ I ^ n ⊔ J ^ m := by
rw [← Ideal.add_eq_sup, ← Ideal.add_eq_sup, add_pow, Ideal.sum_eq_sup]
apply Finset.sup_le
intro i hi
by_cases hn : n ≤ i
· exact (Ideal.mul_le_right.trans (Ideal.mul_le_right.trans
((Ideal.pow_le_pow_right hn).trans le_sup_left)))
· refine (Ideal.mul_le_right.trans (Ideal.mul_le_left.trans
((Ideal.pow_le_pow_right ?_).trans le_sup_right)))
cutsat
variable (I J) in
protected theorem mul_comm : I * J = J * I :=
le_antisymm (mul_le.2 fun _ hrI _ hsJ => mul_mem_mul_rev hsJ hrI)
(mul_le.2 fun _ hrJ _ hsI => mul_mem_mul_rev hsI hrJ)
theorem mem_span_singleton_mul {x y : R} {I : Ideal R} : x ∈ span {y} * I ↔ ∃ z ∈ I, y * z = x := by
simp only [mul_comm, mem_mul_span_singleton]
@[simp]
lemma range_mul (A : Type*) [CommSemiring A] [Module R A]
[SMulCommClass R A A] [IsScalarTower R A A] (a : A) : LinearMap.range (LinearMap.mul R A a) =
(Ideal.span {a}).restrictScalars R := by
aesop (add simp Ideal.mem_span_singleton) (add simp dvd_def)
lemma range_mul' (a : R) : LinearMap.range (LinearMap.mul R R a) = Ideal.span {a} := range_mul ..
theorem le_span_singleton_mul_iff {x : R} {I J : Ideal R} :
I ≤ span {x} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI :=
show (∀ {zI} (_ : zI ∈ I), zI ∈ span {x} * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by
simp only [mem_span_singleton_mul]
theorem span_singleton_mul_le_iff {x : R} {I J : Ideal R} :
span {x} * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by
simp [SetLike.le_def, mem_span_singleton_mul]
theorem span_singleton_mul_le_span_singleton_mul {x y : R} {I J : Ideal R} :
span {x} * I ≤ span {y} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ := by
simp only [span_singleton_mul_le_iff, mem_span_singleton_mul, eq_comm]
theorem span_singleton_mul_right_mono [IsDomain R] {x : R} (hx : x ≠ 0) :
span {x} * I ≤ span {x} * J ↔ I ≤ J := by
simp_rw [span_singleton_mul_le_span_singleton_mul, mul_right_inj' hx,
exists_eq_right', SetLike.le_def]
theorem span_singleton_mul_right_inj [IsDomain R] {x : R} (hx : x ≠ 0) :
span {x} * I = span {x} * J ↔ I = J := by
simp only [le_antisymm_iff, span_singleton_mul_right_mono hx]
theorem span_singleton_mul_right_injective [IsDomain R] {x : R} (hx : x ≠ 0) :
Function.Injective ((span {x} : Ideal R) * ·) := fun _ _ =>
(span_singleton_mul_right_inj hx).mp
theorem span_singleton_mul_left_injective [IsDomain R] {x : R} (hx : x ≠ 0) :
Function.Injective fun I : Ideal R => I * span {x} := fun _ _ =>
(span_singleton_mul_left_inj hx).mp
theorem eq_span_singleton_mul {x : R} (I J : Ideal R) :
I = span {x} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI) ∧ ∀ z ∈ J, x * z ∈ I := by
simp only [le_antisymm_iff, le_span_singleton_mul_iff, span_singleton_mul_le_iff]
theorem span_singleton_mul_eq_span_singleton_mul {x y : R} (I J : Ideal R) :
span {x} * I = span {y} * J ↔
(∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ) ∧ ∀ zJ ∈ J, ∃ zI ∈ I, x * zI = y * zJ := by
simp only [le_antisymm_iff, span_singleton_mul_le_span_singleton_mul, eq_comm]
theorem prod_span {ι : Type*} (s : Finset ι) (I : ι → Set R) :
(∏ i ∈ s, Ideal.span (I i)) = Ideal.span (∏ i ∈ s, I i) :=
Submodule.prod_span s I
theorem prod_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) :
(∏ i ∈ s, Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} :=
Submodule.prod_span_singleton s I
@[simp]
theorem multiset_prod_span_singleton (m : Multiset R) :
(m.map fun x => Ideal.span {x}).prod = Ideal.span ({Multiset.prod m} : Set R) :=
Multiset.induction_on m (by simp) fun a m ih => by
simp only [Multiset.map_cons, Multiset.prod_cons, ih, ← Ideal.span_singleton_mul_span_singleton]
open scoped Function in -- required for scoped `on` notation
theorem finset_inf_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R)
(hI : Set.Pairwise (↑s) (IsCoprime on I)) :
(s.inf fun i => Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := by
ext x
simp only [Submodule.mem_finsetInf, Ideal.mem_span_singleton]
exact ⟨Finset.prod_dvd_of_coprime hI, fun h i hi => (Finset.dvd_prod_of_mem _ hi).trans h⟩
theorem iInf_span_singleton {ι : Type*} [Fintype ι] {I : ι → R}
(hI : ∀ (i j) (_ : i ≠ j), IsCoprime (I i) (I j)) :
⨅ i, span ({I i} : Set R) = span {∏ i, I i} := by
rw [← Finset.inf_univ_eq_iInf, finset_inf_span_singleton]
rwa [Finset.coe_univ, Set.pairwise_univ]
theorem iInf_span_singleton_natCast {R : Type*} [CommRing R] {ι : Type*} [Fintype ι]
{I : ι → ℕ} (hI : Pairwise fun i j => (I i).Coprime (I j)) :
⨅ (i : ι), span {(I i : R)} = span {((∏ i : ι, I i : ℕ) : R)} := by
rw [iInf_span_singleton, Nat.cast_prod]
exact fun i j h ↦ (hI h).cast
theorem sup_eq_top_iff_isCoprime {R : Type*} [CommSemiring R] (x y : R) :
span ({x} : Set R) ⊔ span {y} = ⊤ ↔ IsCoprime x y := by
rw [eq_top_iff_one, Submodule.mem_sup]
constructor
· rintro ⟨u, hu, v, hv, h1⟩
rw [mem_span_singleton'] at hu hv
rw [← hu.choose_spec, ← hv.choose_spec] at h1
exact ⟨_, _, h1⟩
· exact fun ⟨u, v, h1⟩ =>
⟨_, mem_span_singleton'.mpr ⟨_, rfl⟩, _, mem_span_singleton'.mpr ⟨_, rfl⟩, h1⟩
theorem multiset_prod_le_inf {s : Multiset (Ideal R)} : s.prod ≤ s.inf := by
classical
refine s.induction_on ?_ ?_
· rw [Multiset.inf_zero]
exact le_top
intro a s ih
rw [Multiset.prod_cons, Multiset.inf_cons]
exact le_trans mul_le_inf (inf_le_inf le_rfl ih)
theorem prod_le_inf {s : Finset ι} {f : ι → Ideal R} : s.prod f ≤ s.inf f :=
multiset_prod_le_inf
theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J :=
le_antisymm mul_le_inf fun r ⟨hri, hrj⟩ =>
let ⟨s, hsi, t, htj, hst⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 h)
mul_one r ▸
hst ▸
(mul_add r s t).symm ▸ Ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj)
theorem sup_prod_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → I ⊔ J i = ⊤) :
(I ⊔ ∏ i ∈ s, J i) = ⊤ :=
Finset.prod_induction _ (fun J => I ⊔ J = ⊤)
(fun _ _ hJ hK => (sup_mul_eq_of_coprime_left hJ).trans hK)
(by simp_rw [one_eq_top, sup_top_eq]) h
theorem sup_multiset_prod_eq_top {s : Multiset (Ideal R)} (h : ∀ p ∈ s, I ⊔ p = ⊤) :
I ⊔ s.prod = ⊤ :=
Multiset.prod_induction (I ⊔ · = ⊤) s (fun _ _ hp hq ↦ (sup_mul_eq_of_coprime_left hp).trans hq)
(by simp only [one_eq_top, le_top, sup_of_le_right]) h
theorem prod_sup_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → J i ⊔ I = ⊤) :
(∏ i ∈ s, J i) ⊔ I = ⊤ := by rw [sup_comm, sup_prod_eq_top]; intro i hi; rw [sup_comm, h i hi]
/-- A product of ideals in an integral domain is zero if and only if one of the terms is zero. -/
@[simp]
lemma multiset_prod_eq_bot {R : Type*} [CommSemiring R] [IsDomain R] {s : Multiset (Ideal R)} :
s.prod = ⊥ ↔ ⊥ ∈ s :=
Multiset.prod_eq_zero_iff
theorem isCoprime_iff_codisjoint : IsCoprime I J ↔ Codisjoint I J := by
rw [IsCoprime, codisjoint_iff]
constructor
· rintro ⟨x, y, hxy⟩
rw [eq_top_iff_one]
apply (show x * I + y * J ≤ I ⊔ J from
sup_le (mul_le_left.trans le_sup_left) (mul_le_left.trans le_sup_right))
rw [hxy]
simp only [one_eq_top, Submodule.mem_top]
· intro h
refine ⟨1, 1, ?_⟩
simpa only [one_eq_top, top_mul, Submodule.add_eq_sup]
theorem isCoprime_of_isMaximal [I.IsMaximal] [J.IsMaximal] (ne : I ≠ J) : IsCoprime I J := by
rw [isCoprime_iff_codisjoint, isMaximal_def] at *
exact IsCoatom.codisjoint_of_ne ‹_› ‹_› ne
theorem isCoprime_iff_add : IsCoprime I J ↔ I + J = 1 := by
rw [isCoprime_iff_codisjoint, codisjoint_iff, add_eq_sup, one_eq_top]
theorem isCoprime_iff_exists : IsCoprime I J ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by
rw [← add_eq_one_iff, isCoprime_iff_add]
theorem isCoprime_iff_sup_eq : IsCoprime I J ↔ I ⊔ J = ⊤ := by
rw [isCoprime_iff_codisjoint, codisjoint_iff]
theorem coprime_of_no_prime_ge {I J : Ideal R} (h : ∀ P, I ≤ P → J ≤ P → ¬IsPrime P) :
IsCoprime I J := by
rw [isCoprime_iff_sup_eq]
by_contra hIJ
obtain ⟨P, hP, hIJ⟩ := Ideal.exists_le_maximal _ hIJ
exact h P (le_trans le_sup_left hIJ) (le_trans le_sup_right hIJ) hP.isPrime
open List in
theorem isCoprime_tfae : TFAE [IsCoprime I J, Codisjoint I J, I + J = 1,
∃ i ∈ I, ∃ j ∈ J, i + j = 1, I ⊔ J = ⊤] := by
rw [← isCoprime_iff_codisjoint, ← isCoprime_iff_add, ← isCoprime_iff_exists,
← isCoprime_iff_sup_eq]
simp
theorem _root_.IsCoprime.codisjoint (h : IsCoprime I J) : Codisjoint I J :=
isCoprime_iff_codisjoint.mp h
theorem _root_.IsCoprime.add_eq (h : IsCoprime I J) : I + J = 1 := isCoprime_iff_add.mp h
theorem _root_.IsCoprime.exists (h : IsCoprime I J) : ∃ i ∈ I, ∃ j ∈ J, i + j = 1 :=
isCoprime_iff_exists.mp h
theorem _root_.IsCoprime.sup_eq (h : IsCoprime I J) : I ⊔ J = ⊤ := isCoprime_iff_sup_eq.mp h
theorem inf_eq_mul_of_isCoprime (coprime : IsCoprime I J) : I ⊓ J = I * J :=
(Ideal.mul_eq_inf_of_coprime coprime.sup_eq).symm
theorem isCoprime_span_singleton_iff (x y : R) :
IsCoprime (span <| singleton x) (span <| singleton y) ↔ IsCoprime x y := by
simp_rw [isCoprime_iff_codisjoint, codisjoint_iff, eq_top_iff_one, mem_span_singleton_sup,
mem_span_singleton]
constructor
· rintro ⟨a, _, ⟨b, rfl⟩, e⟩; exact ⟨a, b, mul_comm b y ▸ e⟩
· rintro ⟨a, b, e⟩; exact ⟨a, _, ⟨b, rfl⟩, mul_comm y b ▸ e⟩
theorem isCoprime_biInf {J : ι → Ideal R} {s : Finset ι}
(hf : ∀ j ∈ s, IsCoprime I (J j)) : IsCoprime I (⨅ j ∈ s, J j) := by
classical
simp_rw [isCoprime_iff_add] at *
induction s using Finset.induction with
| empty =>
simp
| insert i s _ hs =>
rw [Finset.iInf_insert, inf_comm, one_eq_top, eq_top_iff, ← one_eq_top]
set K := ⨅ j ∈ s, J j
calc
1 = I + K := (hs fun j hj ↦ hf j (Finset.mem_insert_of_mem hj)).symm
_ = I + K*(I + J i) := by rw [hf i (Finset.mem_insert_self i s), mul_one]
_ = (1+K)*I + K*J i := by ring
_ ≤ I + K ⊓ J i := add_le_add mul_le_left mul_le_inf
/-- The radical of an ideal `I` consists of the elements `r` such that `r ^ n ∈ I` for some `n`. -/
def radical (I : Ideal R) : Ideal R where
carrier := { r | ∃ n : ℕ, r ^ n ∈ I }
zero_mem' := ⟨1, (pow_one (0 : R)).symm ▸ I.zero_mem⟩
add_mem' := fun {_ _} ⟨m, hxmi⟩ ⟨n, hyni⟩ =>
⟨m + n - 1, add_pow_add_pred_mem_of_pow_mem I hxmi hyni⟩
smul_mem' {r s} := fun ⟨n, h⟩ ↦ ⟨n, (mul_pow r s n).symm ▸ I.mul_mem_left (r ^ n) h⟩
theorem mem_radical_iff {r : R} : r ∈ I.radical ↔ ∃ n : ℕ, r ^ n ∈ I := Iff.rfl
/-- An ideal is radical if it contains its radical. -/
def IsRadical (I : Ideal R) : Prop :=
I.radical ≤ I
theorem le_radical : I ≤ radical I := fun r hri => ⟨1, (pow_one r).symm ▸ hri⟩
/-- An ideal is radical iff it is equal to its radical. -/
theorem radical_eq_iff : I.radical = I ↔ I.IsRadical := by
rw [le_antisymm_iff, and_iff_left le_radical, IsRadical]
alias ⟨_, IsRadical.radical⟩ := radical_eq_iff
theorem isRadical_iff_pow_one_lt (k : ℕ) (hk : 1 < k) : I.IsRadical ↔ ∀ r, r ^ k ∈ I → r ∈ I :=
⟨fun h _r hr ↦ h ⟨k, hr⟩, fun h x ⟨n, hx⟩ ↦
k.pow_imp_self_of_one_lt hk _ (fun _ _ ↦ .inr ∘ I.smul_mem _) h n x hx⟩
variable (R) in
theorem radical_top : (radical ⊤ : Ideal R) = ⊤ :=
(eq_top_iff_one _).2 ⟨0, Submodule.mem_top⟩
theorem radical_mono (H : I ≤ J) : radical I ≤ radical J := fun _ ⟨n, hrni⟩ => ⟨n, H hrni⟩
variable (I)
theorem radical_isRadical : (radical I).IsRadical := fun r ⟨n, k, hrnki⟩ =>
⟨n * k, (pow_mul r n k).symm ▸ hrnki⟩
@[simp]
theorem radical_idem : radical (radical I) = radical I :=
(radical_isRadical I).radical
variable {I}
theorem IsRadical.radical_le_iff (hJ : J.IsRadical) : I.radical ≤ J ↔ I ≤ J :=
⟨le_trans le_radical, fun h => hJ.radical ▸ radical_mono h⟩
theorem radical_le_radical_iff : radical I ≤ radical J ↔ I ≤ radical J :=
(radical_isRadical J).radical_le_iff
theorem radical_eq_top : radical I = ⊤ ↔ I = ⊤ :=
⟨fun h =>
(eq_top_iff_one _).2 <|
let ⟨n, hn⟩ := (eq_top_iff_one _).1 h
@one_pow R _ n ▸ hn,
fun h => h.symm ▸ radical_top R⟩
theorem IsPrime.isRadical (H : IsPrime I) : I.IsRadical := fun _ ⟨n, hrni⟩ =>
H.mem_of_pow_mem n hrni
theorem IsPrime.radical (H : IsPrime I) : radical I = I :=
IsRadical.radical H.isRadical
theorem mem_radical_of_pow_mem {I : Ideal R} {x : R} {m : ℕ} (hx : x ^ m ∈ radical I) :
x ∈ radical I :=
radical_idem I ▸ ⟨m, hx⟩
theorem disjoint_powers_iff_notMem (y : R) (hI : I.IsRadical) :
Disjoint (Submonoid.powers y : Set R) ↑I ↔ y ∉ I.1 := by
refine ⟨fun h => Set.disjoint_left.1 h (Submonoid.mem_powers _),
fun h => disjoint_iff.mpr (eq_bot_iff.mpr ?_)⟩
rintro x ⟨⟨n, rfl⟩, hx'⟩
exact h (hI <| mem_radical_of_pow_mem <| le_radical hx')
@[deprecated (since := "2025-05-23")]
alias disjoint_powers_iff_not_mem := disjoint_powers_iff_notMem
variable (I J)
theorem radical_sup : radical (I ⊔ J) = radical (radical I ⊔ radical J) :=
le_antisymm (radical_mono <| sup_le_sup le_radical le_radical) <|
radical_le_radical_iff.2 <| sup_le (radical_mono le_sup_left) (radical_mono le_sup_right)
theorem radical_inf : radical (I ⊓ J) = radical I ⊓ radical J :=
le_antisymm (le_inf (radical_mono inf_le_left) (radical_mono inf_le_right))
fun r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩ =>
⟨m + n, (pow_add r m n).symm ▸ I.mul_mem_right _ hrm,
(pow_add r m n).symm ▸ J.mul_mem_left _ hrn⟩
variable {I J} in
theorem IsRadical.inf (hI : IsRadical I) (hJ : IsRadical J) : IsRadical (I ⊓ J) := by
rw [IsRadical, radical_inf]; exact inf_le_inf hI hJ
lemma isRadical_bot_iff :
(⊥ : Ideal R).IsRadical ↔ IsReduced R := by
simp only [IsRadical, SetLike.le_def, Ideal.mem_radical_iff, Ideal.mem_bot,
forall_exists_index, isReduced_iff, IsNilpotent]
lemma isRadical_bot [IsReduced R] : (⊥ : Ideal R).IsRadical := by rwa [Ideal.isRadical_bot_iff]
/-- `Ideal.radical` as an `InfTopHom`, bundling in that it distributes over `inf`. -/
def radicalInfTopHom : InfTopHom (Ideal R) (Ideal R) where
toFun := radical
map_inf' := radical_inf
map_top' := radical_top _
@[simp]
lemma radicalInfTopHom_apply (I : Ideal R) : radicalInfTopHom I = radical I := rfl
open Finset in
lemma radical_finset_inf {ι} {s : Finset ι} {f : ι → Ideal R} {i : ι} (hi : i ∈ s)
(hs : ∀ ⦃y⦄, y ∈ s → (f y).radical = (f i).radical) :
(s.inf f).radical = (f i).radical := by
rw [← radicalInfTopHom_apply, map_finset_inf, ← Finset.inf'_eq_inf ⟨_, hi⟩]
exact Finset.inf'_eq_of_forall _ _ hs
/-- The reverse inclusion does not hold for e.g. `I := fun n : ℕ ↦ Ideal.span {(2 ^ n : ℤ)}`. -/
theorem radical_iInf_le {ι} (I : ι → Ideal R) : radical (⨅ i, I i) ≤ ⨅ i, radical (I i) :=
le_iInf fun _ ↦ radical_mono (iInf_le _ _)
theorem isRadical_iInf {ι} (I : ι → Ideal R) (hI : ∀ i, IsRadical (I i)) : IsRadical (⨅ i, I i) :=
(radical_iInf_le I).trans (iInf_mono hI)
theorem radical_mul : radical (I * J) = radical I ⊓ radical J := by
refine le_antisymm ?_ fun r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩ =>
⟨m + n, (pow_add r m n).symm ▸ mul_mem_mul hrm hrn⟩
have := radical_mono <| mul_le_inf (I := I) (J := J)
simp_rw [radical_inf I J] at this
assumption
variable {I J}
theorem IsPrime.radical_le_iff (hJ : IsPrime J) : I.radical ≤ J ↔ I ≤ J :=
IsRadical.radical_le_iff hJ.isRadical
theorem radical_eq_sInf (I : Ideal R) : radical I = sInf { J : Ideal R | I ≤ J ∧ IsPrime J } :=
le_antisymm (le_sInf fun _ hJ ↦ hJ.2.radical_le_iff.2 hJ.1) fun r hr ↦
by_contradiction fun hri ↦
let ⟨m, hIm, hm⟩ :=
zorn_le_nonempty₀ { K : Ideal R | r ∉ radical K }
(fun c hc hcc y hyc =>
⟨sSup c, fun ⟨n, hrnc⟩ =>
let ⟨_, hyc, hrny⟩ := (Submodule.mem_sSup_of_directed ⟨y, hyc⟩ hcc.directedOn).1 hrnc
hc hyc ⟨n, hrny⟩,
fun _ => le_sSup⟩)
I hri
have hrm : r ∉ radical m := hm.prop
have : ∀ x ∉ m, r ∈ radical (m ⊔ span {x}) := fun x hxm =>
by_contradiction fun hrmx => hxm <| by
rw [hm.eq_of_le hrmx le_sup_left]
exact Submodule.mem_sup_right <| mem_span_singleton_self x
have : IsPrime m :=
⟨by rintro rfl; rw [radical_top] at hrm; exact hrm trivial, fun {x y} hxym =>
or_iff_not_imp_left.2 fun hxm =>
by_contradiction fun hym =>
let ⟨n, hrn⟩ := this _ hxm
let ⟨p, hpm, q, hq, hpqrn⟩ := Submodule.mem_sup.1 hrn
let ⟨c, hcxq⟩ := mem_span_singleton'.1 hq
let ⟨k, hrk⟩ := this _ hym
let ⟨f, hfm, g, hg, hfgrk⟩ := Submodule.mem_sup.1 hrk
let ⟨d, hdyg⟩ := mem_span_singleton'.1 hg
hrm
⟨n + k, by
rw [pow_add, ← hpqrn, ← hcxq, ← hfgrk, ← hdyg, add_mul, mul_add (c * x),
mul_assoc c x (d * y), mul_left_comm x, ← mul_assoc]
refine
m.add_mem (m.mul_mem_right _ hpm)
(m.add_mem (m.mul_mem_left _ hfm) (m.mul_mem_left _ hxym))⟩⟩
hrm <|
this.radical.symm ▸ (sInf_le ⟨hIm, this⟩ : sInf { J : Ideal R | I ≤ J ∧ IsPrime J } ≤ m) hr
theorem isRadical_bot_of_noZeroDivisors {R} [CommSemiring R] [NoZeroDivisors R] :
(⊥ : Ideal R).IsRadical := fun _ hx => hx.recOn fun _ hn => eq_zero_of_pow_eq_zero hn
@[simp]
theorem radical_bot_of_noZeroDivisors {R : Type u} [CommSemiring R] [NoZeroDivisors R] :
radical (⊥ : Ideal R) = ⊥ :=
eq_bot_iff.2 isRadical_bot_of_noZeroDivisors
instance : IdemCommSemiring (Ideal R) :=
inferInstance
variable (I)
lemma radical_pow : ∀ {n}, n ≠ 0 → radical (I ^ n) = radical I
| 1, _ => by simp
| n + 2, _ => by rw [pow_succ, radical_mul, radical_pow n.succ_ne_zero, inf_idem]
theorem IsPrime.mul_le {I J P : Ideal R} (hp : IsPrime P) : I * J ≤ P ↔ I ≤ P ∨ J ≤ P := by
rw [or_comm, Ideal.mul_le]
simp_rw [hp.mul_mem_iff_mem_or_mem, SetLike.le_def, ← forall_or_left, or_comm, forall_or_left]
theorem IsPrime.inf_le {I J P : Ideal R} (hp : IsPrime P) : I ⊓ J ≤ P ↔ I ≤ P ∨ J ≤ P :=
⟨fun h ↦ hp.mul_le.1 <| mul_le_inf.trans h, fun h ↦ h.elim inf_le_left.trans inf_le_right.trans⟩
theorem IsPrime.multiset_prod_le {s : Multiset (Ideal R)} {P : Ideal R} (hp : IsPrime P) :
s.prod ≤ P ↔ ∃ I ∈ s, I ≤ P :=
s.induction_on (by simp [hp.ne_top]) fun I s ih ↦ by simp [hp.mul_le, ih]
theorem IsPrime.multiset_prod_map_le {s : Multiset ι} (f : ι → Ideal R) {P : Ideal R}
(hp : IsPrime P) : (s.map f).prod ≤ P ↔ ∃ i ∈ s, f i ≤ P := by
simp_rw [hp.multiset_prod_le, Multiset.mem_map, exists_exists_and_eq_and]
theorem IsPrime.multiset_prod_mem_iff_exists_mem {I : Ideal R} (hI : I.IsPrime) (s : Multiset R) :
s.prod ∈ I ↔ ∃ p ∈ s, p ∈ I := by
simpa [span_singleton_le_iff_mem] using (hI.multiset_prod_map_le (span {·}))
theorem IsPrime.pow_le_iff {I P : Ideal R} [hP : P.IsPrime] {n : ℕ} (hn : n ≠ 0) :
I ^ n ≤ P ↔ I ≤ P := by
have h : (Multiset.replicate n I).prod ≤ P ↔ _ := hP.multiset_prod_le
simp_rw [Multiset.prod_replicate, Multiset.mem_replicate, ne_eq, hn, not_false_eq_true,
true_and, exists_eq_left] at h
exact h
theorem IsPrime.le_of_pow_le {I P : Ideal R} [hP : P.IsPrime] {n : ℕ} (h : I ^ n ≤ P) :
I ≤ P := by
by_cases hn : n = 0
· rw [hn, pow_zero, one_eq_top] at h
exact fun ⦃_⦄ _ ↦ h Submodule.mem_top
· exact (pow_le_iff hn).mp h
theorem IsPrime.prod_le {s : Finset ι} {f : ι → Ideal R} {P : Ideal R} (hp : IsPrime P) :
s.prod f ≤ P ↔ ∃ i ∈ s, f i ≤ P :=
hp.multiset_prod_map_le f
/-- The product of a finite number of elements in the commutative semiring `R` lies in the
prime ideal `p` if and only if at least one of those elements is in `p`. -/
theorem IsPrime.prod_mem_iff {s : Finset ι} {x : ι → R} {p : Ideal R} [hp : p.IsPrime] :
∏ i ∈ s, x i ∈ p ↔ ∃ i ∈ s, x i ∈ p := by
simp_rw [← span_singleton_le_iff_mem, ← prod_span_singleton]
exact hp.prod_le
theorem IsPrime.prod_mem_iff_exists_mem {I : Ideal R} (hI : I.IsPrime) (s : Finset R) :
s.prod (fun x ↦ x) ∈ I ↔ ∃ p ∈ s, p ∈ I := by
rw [Finset.prod_eq_multiset_prod, Multiset.map_id']
exact hI.multiset_prod_mem_iff_exists_mem s.val
theorem IsPrime.inf_le' {s : Finset ι} {f : ι → Ideal R} {P : Ideal R} (hp : IsPrime P) :
s.inf f ≤ P ↔ ∃ i ∈ s, f i ≤ P :=
⟨fun h ↦ hp.prod_le.1 <| prod_le_inf.trans h, fun ⟨_, his, hip⟩ ↦ (Finset.inf_le his).trans hip⟩
theorem subset_union {R : Type u} [Ring R] {I J K : Ideal R} :
(I : Set R) ⊆ J ∪ K ↔ I ≤ J ∨ I ≤ K :=
AddSubgroupClass.subset_union
theorem subset_union_prime' {R : Type u} [CommRing R] {s : Finset ι} {f : ι → Ideal R} {a b : ι}
(hp : ∀ i ∈ s, IsPrime (f i)) {I : Ideal R} :
((I : Set R) ⊆ f a ∪ f b ∪ ⋃ i ∈ (↑s : Set ι), f i) ↔ I ≤ f a ∨ I ≤ f b ∨ ∃ i ∈ s, I ≤ f i := by
suffices
((I : Set R) ⊆ f a ∪ f b ∪ ⋃ i ∈ (↑s : Set ι), f i) → I ≤ f a ∨ I ≤ f b ∨ ∃ i ∈ s, I ≤ f i from
⟨this, fun h =>
Or.casesOn h
(fun h =>
Set.Subset.trans h <|
Set.Subset.trans Set.subset_union_left Set.subset_union_left)
fun h =>
Or.casesOn h
(fun h =>
Set.Subset.trans h <|
Set.Subset.trans Set.subset_union_right Set.subset_union_left)
fun ⟨i, his, hi⟩ => by
refine Set.Subset.trans hi <| Set.Subset.trans ?_ Set.subset_union_right
exact Set.subset_biUnion_of_mem (u := fun x ↦ (f x : Set R)) (Finset.mem_coe.2 his)⟩
generalize hn : s.card = n; intro h
induction n generalizing a b s with
| zero =>
clear hp
rw [Finset.card_eq_zero] at hn
subst hn
rw [Finset.coe_empty, Set.biUnion_empty, Set.union_empty, subset_union] at h
simpa only [exists_prop, Finset.notMem_empty, false_and, exists_false, or_false]
| succ n ih =>
classical
replace hn : ∃ (i : ι) (t : Finset ι), i ∉ t ∧ insert i t = s ∧ t.card = n :=
Finset.card_eq_succ.1 hn
rcases hn with ⟨i, t, hit, rfl, hn⟩
replace hp : IsPrime (f i) ∧ ∀ x ∈ t, IsPrime (f x) := (t.forall_mem_insert _ _).1 hp
by_cases Ht : ∃ j ∈ t, f j ≤ f i
· obtain ⟨j, hjt, hfji⟩ : ∃ j ∈ t, f j ≤ f i := Ht
obtain ⟨u, hju, rfl⟩ : ∃ u, j ∉ u ∧ insert j u = t :=
⟨t.erase j, t.notMem_erase j, Finset.insert_erase hjt⟩
have hp' : ∀ k ∈ insert i u, IsPrime (f k) := by
rw [Finset.forall_mem_insert] at hp ⊢
exact ⟨hp.1, hp.2.2⟩
have hiu : i ∉ u := mt Finset.mem_insert_of_mem hit
have hn' : (insert i u).card = n := by
rwa [Finset.card_insert_of_notMem] at hn ⊢
exacts [hiu, hju]
have h' : (I : Set R) ⊆ f a ∪ f b ∪ ⋃ k ∈ (↑(insert i u) : Set ι), f k := by
rw [Finset.coe_insert] at h ⊢
rw [Finset.coe_insert] at h
simp only [Set.biUnion_insert] at h ⊢
rw [← Set.union_assoc (f i : Set R),
Set.union_eq_self_of_subset_right hfji] at h
exact h
specialize ih hp' hn' h'
refine ih.imp id (Or.imp id (Exists.imp fun k => ?_))
exact And.imp (fun hk => Finset.insert_subset_insert i (Finset.subset_insert j u) hk) id
by_cases Ha : f a ≤ f i
· have h' : (I : Set R) ⊆ f i ∪ f b ∪ ⋃ j ∈ (↑t : Set ι), f j := by
rw [Finset.coe_insert, Set.biUnion_insert, ← Set.union_assoc,
Set.union_right_comm (f a : Set R),
Set.union_eq_self_of_subset_left Ha] at h
exact h
specialize ih hp.2 hn h'
right
rcases ih with (ih | ih | ⟨k, hkt, ih⟩)
· exact Or.inr ⟨i, Finset.mem_insert_self i t, ih⟩
· exact Or.inl ih
· exact Or.inr ⟨k, Finset.mem_insert_of_mem hkt, ih⟩
by_cases Hb : f b ≤ f i
· have h' : (I : Set R) ⊆ f a ∪ f i ∪ ⋃ j ∈ (↑t : Set ι), f j := by
rw [Finset.coe_insert, Set.biUnion_insert, ← Set.union_assoc,
Set.union_assoc (f a : Set R),
Set.union_eq_self_of_subset_left Hb] at h
exact h
specialize ih hp.2 hn h'
rcases ih with (ih | ih | ⟨k, hkt, ih⟩)
· exact Or.inl ih
· exact Or.inr (Or.inr ⟨i, Finset.mem_insert_self i t, ih⟩)
· exact Or.inr (Or.inr ⟨k, Finset.mem_insert_of_mem hkt, ih⟩)
by_cases Hi : I ≤ f i
· exact Or.inr (Or.inr ⟨i, Finset.mem_insert_self i t, Hi⟩)
have : ¬I ⊓ f a ⊓ f b ⊓ t.inf f ≤ f i := by
simp only [hp.1.inf_le, hp.1.inf_le', not_or]
exact ⟨⟨⟨Hi, Ha⟩, Hb⟩, Ht⟩
rcases Set.not_subset.1 this with ⟨r, ⟨⟨⟨hrI, hra⟩, hrb⟩, hr⟩, hri⟩
by_cases HI : (I : Set R) ⊆ f a ∪ f b ∪ ⋃ j ∈ (↑t : Set ι), f j
· specialize ih hp.2 hn HI
rcases ih with (ih | ih | ⟨k, hkt, ih⟩)
· order
· order
· right
right
exact ⟨k, Finset.mem_insert_of_mem hkt, ih⟩
exfalso
rcases Set.not_subset.1 HI with ⟨s, hsI, hs⟩
rw [Finset.coe_insert, Set.biUnion_insert] at h
have hsi : s ∈ f i := ((h hsI).resolve_left (mt Or.inl hs)).resolve_right (mt Or.inr hs)
rcases h (I.add_mem hrI hsI) with (⟨ha | hb⟩ | hi | ht)
· exact hs (Or.inl <| Or.inl <| add_sub_cancel_left r s ▸ (f a).sub_mem ha hra)
· exact hs (Or.inl <| Or.inr <| add_sub_cancel_left r s ▸ (f b).sub_mem hb hrb)
· exact hri (add_sub_cancel_right r s ▸ (f i).sub_mem hi hsi)
· rw [Set.mem_iUnion₂] at ht
rcases ht with ⟨j, hjt, hj⟩
simp only [Finset.inf_eq_iInf, SetLike.mem_coe, Submodule.mem_iInf] at hr
exact hs <| Or.inr <| Set.mem_biUnion hjt <|
add_sub_cancel_left r s ▸ (f j).sub_mem hj <| hr j hjt
/-- Prime avoidance. Atiyah-Macdonald 1.11, Eisenbud 3.3, Matsumura Ex.1.6. -/
@[stacks 00DS]
theorem subset_union_prime {R : Type u} [CommRing R] {s : Finset ι} {f : ι → Ideal R} (a b : ι)
(hp : ∀ i ∈ s, i ≠ a → i ≠ b → IsPrime (f i)) {I : Ideal R} :
((I : Set R) ⊆ ⋃ i ∈ (↑s : Set ι), f i) ↔ ∃ i ∈ s, I ≤ f i :=
suffices ((I : Set R) ⊆ ⋃ i ∈ (↑s : Set ι), f i) → ∃ i, i ∈ s ∧ I ≤ f i by
have aux := fun h => (bex_def.2 <| this h)
simp_rw [exists_prop] at aux
refine ⟨aux, fun ⟨i, his, hi⟩ ↦ Set.Subset.trans hi ?_⟩
apply Set.subset_biUnion_of_mem (show i ∈ (↑s : Set ι) from his)
fun h : (I : Set R) ⊆ ⋃ i ∈ (↑s : Set ι), f i => by
classical
by_cases has : a ∈ s
· obtain ⟨t, hat, rfl⟩ : ∃ t, a ∉ t ∧ insert a t = s :=
⟨s.erase a, Finset.notMem_erase a s, Finset.insert_erase has⟩
by_cases hbt : b ∈ t
· obtain ⟨u, hbu, rfl⟩ : ∃ u, b ∉ u ∧ insert b u = t :=
⟨t.erase b, Finset.notMem_erase b t, Finset.insert_erase hbt⟩
have hp' : ∀ i ∈ u, IsPrime (f i) := by
intro i hiu
refine hp i (Finset.mem_insert_of_mem (Finset.mem_insert_of_mem hiu)) ?_ ?_ <;>
rintro rfl <;>
solve_by_elim only [Finset.mem_insert_of_mem, *]
rw [Finset.coe_insert, Finset.coe_insert, Set.biUnion_insert, Set.biUnion_insert, ←
Set.union_assoc, subset_union_prime' hp'] at h
rwa [Finset.exists_mem_insert, Finset.exists_mem_insert]
· have hp' : ∀ j ∈ t, IsPrime (f j) := by
intro j hj
refine hp j (Finset.mem_insert_of_mem hj) ?_ ?_ <;> rintro rfl <;>
solve_by_elim only [Finset.mem_insert_of_mem, *]
rw [Finset.coe_insert, Set.biUnion_insert, ← Set.union_self (f a : Set R),
subset_union_prime' hp', ← or_assoc, or_self_iff] at h
rwa [Finset.exists_mem_insert]
· by_cases hbs : b ∈ s
· obtain ⟨t, hbt, rfl⟩ : ∃ t, b ∉ t ∧ insert b t = s :=
⟨s.erase b, Finset.notMem_erase b s, Finset.insert_erase hbs⟩
have hp' : ∀ j ∈ t, IsPrime (f j) := by
intro j hj
refine hp j (Finset.mem_insert_of_mem hj) ?_ ?_ <;> rintro rfl <;>
solve_by_elim only [Finset.mem_insert_of_mem, *]
rw [Finset.coe_insert, Set.biUnion_insert, ← Set.union_self (f b : Set R),
subset_union_prime' hp', ← or_assoc, or_self_iff] at h
rwa [Finset.exists_mem_insert]
rcases s.eq_empty_or_nonempty with hse | hsne
· subst hse
rw [Finset.coe_empty, Set.biUnion_empty, Set.subset_empty_iff] at h
have : (I : Set R) ≠ ∅ := Set.Nonempty.ne_empty (Set.nonempty_of_mem I.zero_mem)
exact absurd h this
· obtain ⟨i, his⟩ := hsne
obtain ⟨t, _, rfl⟩ : ∃ t, i ∉ t ∧ insert i t = s :=
⟨s.erase i, Finset.notMem_erase i s, Finset.insert_erase his⟩
have hp' : ∀ j ∈ t, IsPrime (f j) := by
intro j hj
refine hp j (Finset.mem_insert_of_mem hj) ?_ ?_ <;> rintro rfl <;>
solve_by_elim only [Finset.mem_insert_of_mem, *]
rw [Finset.coe_insert, Set.biUnion_insert, ← Set.union_self (f i : Set R),
subset_union_prime' hp', ← or_assoc, or_self_iff] at h
rwa [Finset.exists_mem_insert]
/-- Another version of prime avoidance using `Set.Finite` instead of `Finset`. -/
lemma subset_union_prime_finite {R ι : Type*} [CommRing R] {s : Set ι}
(hs : s.Finite) {f : ι → Ideal R} (a b : ι)
(hp : ∀ i ∈ s, i ≠ a → i ≠ b → (f i).IsPrime) {I : Ideal R} :
((I : Set R) ⊆ ⋃ i ∈ s, f i) ↔ ∃ i ∈ s, I ≤ f i := by
rcases Set.Finite.exists_finset hs with ⟨t, ht⟩
have heq : ⋃ i ∈ s, f i = ⋃ i ∈ t, (f i : Set R) := by
ext
simpa using exists_congr (fun i ↦ (and_congr_left fun a ↦ ht i).symm)
have hmem_union : ((I : Set R) ⊆ ⋃ i ∈ s, f i) ↔ ((I : Set R) ⊆ ⋃ i ∈ (t : Set ι), f i) :=
(congrArg _ heq).to_iff
rw [hmem_union, Ideal.subset_union_prime a b (fun i hin ↦ hp i ((ht i).mp hin))]
exact exists_congr (fun i ↦ and_congr_left fun _ ↦ ht i)
section Dvd
/-- If `I` divides `J`, then `I` contains `J`.
In a Dedekind domain, to divide and contain are equivalent, see `Ideal.dvd_iff_le`.
-/
theorem le_of_dvd {I J : Ideal R} : I ∣ J → J ≤ I
| ⟨_, h⟩ => h.symm ▸ le_trans mul_le_inf inf_le_left
@[simp]
theorem dvd_bot {I : Ideal R} : I ∣ ⊥ :=
dvd_zero I
/-- See also `isUnit_iff_eq_one`. -/
@[simp high]
theorem isUnit_iff {I : Ideal R} : IsUnit I ↔ I = ⊤ :=
isUnit_iff_dvd_one.trans
((@one_eq_top R _).symm ▸
⟨fun h => eq_top_iff.mpr (Ideal.le_of_dvd h), fun h => ⟨⊤, by rw [mul_top, h]⟩⟩)
instance uniqueUnits : Unique (Ideal R)ˣ where
default := 1
uniq u := Units.ext (show (u : Ideal R) = 1 by rw [isUnit_iff.mp u.isUnit, one_eq_top])
end Dvd
end MulAndRadical
section Total
variable (ι : Type*)
variable (M : Type*) [AddCommGroup M] {R : Type*} [CommRing R] [Module R M] (I : Ideal R)
variable (v : ι → M) (hv : Submodule.span R (Set.range v) = ⊤)
/-- A variant of `Finsupp.linearCombination` that takes in vectors valued in `I`. -/
noncomputable def finsuppTotal : (ι →₀ I) →ₗ[R] M :=
(Finsupp.linearCombination R v).comp (Finsupp.mapRange.linearMap I.subtype)
variable {ι M v}
theorem finsuppTotal_apply (f : ι →₀ I) :
finsuppTotal ι M I v f = f.sum fun i x => (x : R) • v i := by
dsimp [finsuppTotal]
rw [Finsupp.linearCombination_apply, Finsupp.sum_mapRange_index]
exact fun _ => zero_smul _ _
theorem finsuppTotal_apply_eq_of_fintype [Fintype ι] (f : ι →₀ I) :
finsuppTotal ι M I v f = ∑ i, (f i : R) • v i := by
rw [finsuppTotal_apply, Finsupp.sum_fintype]
exact fun _ => zero_smul _ _
theorem range_finsuppTotal :
LinearMap.range (finsuppTotal ι M I v) = I • Submodule.span R (Set.range v) := by
ext
rw [Submodule.mem_ideal_smul_span_iff_exists_sum]
refine ⟨fun ⟨f, h⟩ => ⟨Finsupp.mapRange.linearMap I.subtype f, fun i => (f i).2, h⟩, ?_⟩
rintro ⟨a, ha, rfl⟩
classical
refine ⟨a.mapRange (fun r => if h : r ∈ I then ⟨r, h⟩ else 0)
(by simp only [Submodule.zero_mem, ↓reduceDIte]; rfl), ?_⟩
rw [finsuppTotal_apply, Finsupp.sum_mapRange_index]
· apply Finsupp.sum_congr
intro i _
rw [dif_pos (ha i)]
· exact fun _ => zero_smul _ _
end Total
end Ideal
section span_range
variable {α R : Type*} [Semiring R]
theorem Finsupp.mem_ideal_span_range_iff_exists_finsupp {x : R} {v : α → R} :
x ∈ Ideal.span (Set.range v) ↔ ∃ c : α →₀ R, (c.sum fun i a => a * v i) = x :=
Finsupp.mem_span_range_iff_exists_finsupp
/-- An element `x` lies in the span of `v` iff it can be written as sum `∑ cᵢ • vᵢ = x`.
-/
theorem Ideal.mem_span_range_iff_exists_fun [Fintype α] {x : R} {v : α → R} :
x ∈ Ideal.span (Set.range v) ↔ ∃ c : α → R, ∑ i, c i * v i = x :=
Submodule.mem_span_range_iff_exists_fun _
end span_range
theorem Associates.mk_ne_zero' {R : Type*} [CommSemiring R] {r : R} :
Associates.mk (Ideal.span {r} : Ideal R) ≠ 0 ↔ r ≠ 0 := by
rw [Associates.mk_ne_zero, Ideal.zero_eq_bot, Ne, Ideal.span_singleton_eq_bot]
open scoped nonZeroDivisors in
theorem Ideal.span_singleton_nonZeroDivisors {R : Type*} [CommSemiring R] [NoZeroDivisors R]
{r : R} : span {r} ∈ (Ideal R)⁰ ↔ r ∈ R⁰ := by
cases subsingleton_or_nontrivial R
· simp_rw [← nonZeroDivisorsRight_eq_nonZeroDivisors]
exact ⟨fun _ _ _ ↦ Subsingleton.eq_zero _, fun _ _ _ ↦ Subsingleton.eq_zero _⟩
· rw [mem_nonZeroDivisors_iff_ne_zero, mem_nonZeroDivisors_iff_ne_zero, ne_eq, zero_eq_bot,
span_singleton_eq_bot]
theorem Ideal.primeCompl_le_nonZeroDivisors {R : Type*} [CommSemiring R] [NoZeroDivisors R]
(P : Ideal R) [P.IsPrime] : P.primeCompl ≤ nonZeroDivisors R :=
le_nonZeroDivisors_of_noZeroDivisors <| not_not_intro P.zero_mem
namespace Submodule
variable {R : Type u} {M : Type v}
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
instance moduleSubmodule : Module (Ideal R) (Submodule R M) where
smul_add := smul_sup
add_smul := sup_smul
mul_smul := Submodule.mul_smul
one_smul := by simp
zero_smul := bot_smul
smul_zero := smul_bot
lemma span_smul_eq
(s : Set R) (N : Submodule R M) :
Ideal.span s • N = s • N := by
rw [← coe_set_smul, coe_span_smul]
@[simp]
theorem set_smul_top_eq_span (s : Set R) :
s • ⊤ = Ideal.span s :=
(span_smul_eq s ⊤).symm.trans (Ideal.span s).mul_top
lemma smul_le_span (s : Set R) (I : Ideal R) : s • I ≤ Ideal.span s := by
simp [← Submodule.set_smul_top_eq_span, smul_le_smul_left]
variable {A B} [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]
open Submodule
instance algebraIdeal : Algebra (Ideal R) (Submodule R A) where
__ := moduleSubmodule
algebraMap :=
{ toFun := map (Algebra.linearMap R A)
map_one' := by
rw [one_eq_span, map_span, Set.image_singleton, Algebra.linearMap_apply, map_one, one_eq_span]
map_mul' := (Submodule.map_mul · · <| Algebra.ofId R A)
map_zero' := map_bot _
map_add' := (map_sup · · _) }
commutes' I M := mul_comm_of_commute <| by rintro _ ⟨r, _, rfl⟩ a _; apply Algebra.commutes
smul_def' I M := le_antisymm (smul_le.mpr fun r hr a ha ↦ by
rw [Algebra.smul_def]; exact Submodule.mul_mem_mul ⟨r, hr, rfl⟩ ha) (Submodule.mul_le.mpr <| by
rintro _ ⟨r, hr, rfl⟩ a ha; rw [Algebra.linearMap_apply, ← Algebra.smul_def]
exact Submodule.smul_mem_smul hr ha)
/-- `Submonoid.map` as an `AlgHom`, when applied to an `AlgHom`. -/
@[simps!] def mapAlgHom (f : A →ₐ[R] B) : Submodule R A →ₐ[Ideal R] Submodule R B where
__ := mapHom f
commutes' I := (map_comp _ _ I).symm.trans (congr_arg (map · I) <| LinearMap.ext f.commutes)
/-- `Submonoid.map` as an `AlgEquiv`, when applied to an `AlgEquiv`. -/
-- TODO: when A, B noncommutative, still has `MulEquiv`.
@[simps!] def mapAlgEquiv (f : A ≃ₐ[R] B) : Submodule R A ≃ₐ[Ideal R] Submodule R B where
__ := mapAlgHom f
invFun := mapAlgHom f.symm
left_inv I := (map_comp _ _ I).symm.trans <|
(congr_arg (map · I) <| LinearMap.ext (f.left_inv ·)).trans (map_id I)
right_inv I := (map_comp _ _ I).symm.trans <|
(congr_arg (map · I) <| LinearMap.ext (f.right_inv ·)).trans (map_id I)
end Submodule
instance {R} [Semiring R] : NonUnitalSubsemiringClass (Ideal R) R where
mul_mem _ hb := Ideal.mul_mem_left _ _ hb
instance {R} [Ring R] : NonUnitalSubringClass (Ideal R) R where
lemma Ideal.exists_subset_radical_span_sup_of_subset_radical_sup {R : Type*} [CommSemiring R]
(s : Set R) (I J : Ideal R) (hs : s ⊆ (I ⊔ J).radical) :
∃ (t : s → R), Set.range t ⊆ I ∧ s ⊆ (span (Set.range t) ⊔ J).radical := by
replace hs : ∀ z : s, ∃ (m : ℕ) (a b : R) (ha : a ∈ I) (hb : b ∈ J), a + b = z ^ m := by
rintro ⟨z, hzs⟩
simp only [Ideal.radical, Submodule.mem_sup] at hs
obtain ⟨m, y, hyq, b, hb, hy⟩ := hs hzs
exact ⟨m, y, b, hyq, hb, hy⟩
choose m a b ha hb heq using hs
refine ⟨a, by rwa [Set.range_subset_iff], fun z hz ↦ ⟨m ⟨z, hz⟩, heq ⟨z, hz⟩ ▸ ?_⟩⟩
exact Ideal.add_mem _ (mem_sup_left (subset_span ⟨⟨z, hz⟩, rfl⟩)) (mem_sup_right <| hb _)
@[deprecated (since := "2025-05-13")]
alias Ideal.exists_subset_radical_span_sup_span_of_subset_radical_sup :=
Ideal.exists_subset_radical_span_sup_of_subset_radical_sup |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/IsPrincipalPowQuotient.lean | import Mathlib.LinearAlgebra.Isomorphisms
import Mathlib.RingTheory.Ideal.Operations
import Mathlib.RingTheory.Ideal.Quotient.Defs
/-!
# Quotients of powers of principal ideals
This file deals with taking quotients of powers of principal ideals.
## Main definitions and results
* `Ideal.quotEquivPowQuotPowSucc`: for a principal ideal `I`, `R ⧸ I ≃ₗ[R] I ^ n ⧸ I ^ (n + 1)`
## Implementation details
At site of usage, calling `LinearEquiv.toEquiv` can cause timeouts in the search for a complex
synthesis like `Module 𝒪[K] 𝓀[k]`, so the plain equiv versions are provided.
These equivs are defined here as opposed to in the quotients file since they cannot be
formed as ring equivs.
-/
namespace Ideal
section IsPrincipal
variable {R : Type*} [CommRing R] [IsDomain R] {I : Ideal R}
/-- For a principal ideal `I`, `R ⧸ I ≃ₗ[R] I ^ n ⧸ I ^ (n + 1)`. To convert into a form
that uses the ideal of `R ⧸ I ^ (n + 1)`, compose with
`Ideal.powQuotPowSuccLinearEquivMapMkPowSuccPow`. -/
noncomputable
def quotEquivPowQuotPowSucc (h : I.IsPrincipal) (h' : I ≠ ⊥) (n : ℕ) :
(R ⧸ I) ≃ₗ[R] (I ^ n : Ideal R) ⧸ (I • ⊤ : Submodule R (I ^ n : Ideal R)) := by
let f : (I ^ n : Ideal R) →ₗ[R] (I ^ n : Ideal R) ⧸ (I • ⊤ : Submodule R (I ^ n : Ideal R)) :=
Submodule.mkQ _
let ϖ := h.principal.choose
have hI : I = Ideal.span {ϖ} := h.principal.choose_spec
have hϖ : ϖ ^ n ∈ I ^ n := hI ▸ (Ideal.pow_mem_pow (Ideal.mem_span_singleton_self _) n)
let g : R →ₗ[R] (I ^ n : Ideal R) := (LinearMap.mulRight R ϖ ^ n).codRestrict _ fun x ↦ by
simp only [LinearMap.pow_mulRight, LinearMap.mulRight_apply]
-- TODO: change argument of Ideal.pow_mem_of_mem
exact Ideal.mul_mem_left _ _ hϖ
have : I = LinearMap.ker (f.comp g) := by
ext x
simp only [LinearMap.codRestrict, LinearMap.pow_mulRight, LinearMap.mulRight_apply,
LinearMap.mem_ker, LinearMap.coe_comp, LinearMap.coe_mk, AddHom.coe_mk, Function.comp_apply,
Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero, Submodule.mem_smul_top_iff, smul_eq_mul,
f, g]
constructor <;> intro hx
· exact Submodule.mul_mem_mul hx hϖ
· rw [← pow_succ', hI, Ideal.span_singleton_pow, Ideal.mem_span_singleton] at hx
obtain ⟨y, hy⟩ := hx
rw [mul_comm, pow_succ, mul_assoc, mul_right_inj' (pow_ne_zero _ _)] at hy
· rw [hI, Ideal.mem_span_singleton]
exact ⟨y, hy⟩
· contrapose! h'
rw [hI, h', Ideal.span_singleton_eq_bot]
let e : (R ⧸ I) ≃ₗ[R] R ⧸ (LinearMap.ker (f.comp g)) :=
Submodule.quotEquivOfEq I (LinearMap.ker (f ∘ₗ g)) this
refine e.trans ((f.comp g).quotKerEquivOfSurjective ?_)
refine (Submodule.mkQ_surjective _).comp ?_
rintro ⟨x, hx⟩
rw [hI, Ideal.span_singleton_pow, Ideal.mem_span_singleton] at hx
refine hx.imp ?_
simp [g, LinearMap.codRestrict, eq_comm, mul_comm]
/-- For a principal ideal `I`, `R ⧸ I ≃ I ^ n ⧸ I ^ (n + 1)`. Supplied as a plain equiv to bypass
typeclass synthesis issues on complex `Module` goals. To convert into a form
that uses the ideal of `R ⧸ I ^ (n + 1)`, compose with
`Ideal.powQuotPowSuccEquivMapMkPowSuccPow`. -/
noncomputable
def quotEquivPowQuotPowSuccEquiv (h : I.IsPrincipal) (h' : I ≠ ⊥) (n : ℕ) :
(R ⧸ I) ≃ (I ^ n : Ideal R) ⧸ (I • ⊤ : Submodule R (I ^ n : Ideal R)) :=
quotEquivPowQuotPowSucc h h' n
end IsPrincipal
end Ideal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Defs.lean | import Mathlib.Algebra.Module.Submodule.Defs
import Mathlib.Tactic.Abel
/-!
# Ideals over a ring
This file defines `Ideal R`, the type of (left) ideals over a ring `R`.
Note that over commutative rings, left ideals and two-sided ideals are equivalent.
## Implementation notes
`Ideal R` is implemented using `Submodule R R`, where `•` is interpreted as `*`.
## TODO
Support right ideals, and two-sided ideals over non-commutative rings.
-/
universe u v w
variable {α : Type u} {β : Type v} {F : Type w}
open Set Function
open Pointwise
/-- A (left) ideal in a semiring `R` is an additive submonoid `s` such that
`a * b ∈ s` whenever `b ∈ s`. If `R` is a ring, then `s` is an additive subgroup. -/
abbrev Ideal (R : Type u) [Semiring R] :=
Submodule R R
section Semiring
namespace Ideal
variable [Semiring α] (I : Ideal α) {a b : α}
/-- A left ideal `I : Ideal R` is two-sided if it is also a right ideal. -/
@[mk_iff] class IsTwoSided : Prop where
mul_mem_of_left {a : α} (b : α) : a ∈ I → a * b ∈ I
protected theorem zero_mem : (0 : α) ∈ I :=
Submodule.zero_mem I
protected theorem add_mem : a ∈ I → b ∈ I → a + b ∈ I :=
Submodule.add_mem I
variable (a)
theorem mul_mem_left : b ∈ I → a * b ∈ I :=
Submodule.smul_mem I a
theorem mul_mem_right {α} {a : α} (b : α) [Semiring α] (I : Ideal α) [I.IsTwoSided]
(h : a ∈ I) : a * b ∈ I :=
IsTwoSided.mul_mem_of_left b h
variable {a}
@[ext]
theorem ext {I J : Ideal α} (h : ∀ x, x ∈ I ↔ x ∈ J) : I = J :=
Submodule.ext h
@[simp]
theorem unit_mul_mem_iff_mem {x y : α} (hy : IsUnit y) : y * x ∈ I ↔ x ∈ I := by
refine ⟨fun h => ?_, fun h => I.mul_mem_left y h⟩
obtain ⟨y', hy'⟩ := hy.exists_left_inv
have := I.mul_mem_left y' h
rwa [← mul_assoc, hy', one_mul] at this
theorem pow_mem_of_mem (ha : a ∈ I) (n : ℕ) (hn : 0 < n) : a ^ n ∈ I :=
Nat.casesOn n (Not.elim (by decide))
(fun m _hm => (pow_succ a m).symm ▸ I.mul_mem_left (a ^ m) ha) hn
theorem pow_mem_of_pow_mem {m n : ℕ} (ha : a ^ m ∈ I) (h : m ≤ n) : a ^ n ∈ I := by
rw [← Nat.add_sub_of_le h, add_comm, pow_add]
exact I.mul_mem_left _ ha
end Ideal
/-- For two elements `m` and `m'` in an `R`-module `M`, the set of elements `r : R` with
equal scalar product with `m` and `m'` is an ideal of `R`. If `M` is a group, this coincides
with the kernel of `LinearMap.toSpanSingleton R M (m - m')`. -/
def Module.eqIdeal (R) {M} [Semiring R] [AddCommMonoid M] [Module R M] (m m' : M) : Ideal R where
carrier := {r : R | r • m = r • m'}
add_mem' h h' := by simpa [add_smul] using congr($h + $h')
zero_mem' := by simp_rw [Set.mem_setOf, zero_smul]
smul_mem' _ _ h := by simpa [mul_smul] using congr(_ • $h)
end Semiring
section CommSemiring
variable {a b : α}
-- A separate namespace definition is needed because the variables were historically in a different
-- order.
namespace Ideal
variable [CommSemiring α] (I : Ideal α)
instance : I.IsTwoSided := ⟨fun b ha ↦ mul_comm b _ ▸ I.smul_mem _ ha⟩
instance {α} [CommRing α] (I : Ideal α) : I.IsTwoSided := inferInstance
@[simp]
theorem mul_unit_mem_iff_mem {x y : α} (hy : IsUnit y) : x * y ∈ I ↔ x ∈ I :=
mul_comm y x ▸ unit_mul_mem_iff_mem I hy
lemma mem_of_dvd (hab : a ∣ b) (ha : a ∈ I) : b ∈ I := by
obtain ⟨c, rfl⟩ := hab; exact I.mul_mem_right _ ha
end Ideal
end CommSemiring
section Ring
namespace Ideal
variable [Ring α] (I : Ideal α) {a b c d : α}
protected theorem neg_mem_iff : -a ∈ I ↔ a ∈ I :=
Submodule.neg_mem_iff I
protected theorem add_mem_iff_left : b ∈ I → (a + b ∈ I ↔ a ∈ I) :=
Submodule.add_mem_iff_left I
protected theorem add_mem_iff_right : a ∈ I → (a + b ∈ I ↔ b ∈ I) :=
Submodule.add_mem_iff_right I
protected theorem sub_mem : a ∈ I → b ∈ I → a - b ∈ I :=
Submodule.sub_mem I
theorem mul_sub_mul_mem [I.IsTwoSided]
(h1 : a - b ∈ I) (h2 : c - d ∈ I) : a * c - b * d ∈ I := by
rw [show a * c - b * d = (a - b) * c + b * (c - d) by rw [sub_mul, mul_sub]; abel]
exact I.add_mem (I.mul_mem_right _ h1) (I.mul_mem_left _ h2)
end Ideal
end Ring |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Span.lean | import Mathlib.Algebra.GroupWithZero.Associated
import Mathlib.Algebra.Ring.Idempotent
import Mathlib.Algebra.Ring.Regular
import Mathlib.LinearAlgebra.Span.Basic
import Mathlib.RingTheory.Ideal.Lattice
/-!
# Ideals generated by a set of elements
This file defines `Ideal.span s` as the ideal generated by the subset `s` of the ring.
## TODO
Support right ideals, and two-sided ideals over non-commutative rings.
-/
universe u
variable {α : Type u}
open Set Pointwise
/-- A ring is a principal ideal ring if all (left) ideals are principal. -/
@[mk_iff]
class IsPrincipalIdealRing (R : Type u) [Semiring R] : Prop where
principal : ∀ S : Ideal R, S.IsPrincipal
attribute [instance] IsPrincipalIdealRing.principal
namespace Ideal
section Semiring
variable [Semiring α] (I : Ideal α)
/-- The ideal generated by a subset of a ring -/
def span (s : Set α) : Ideal α :=
Submodule.span α s
@[simp]
theorem submodule_span_eq {s : Set α} : Submodule.span α s = Ideal.span s :=
rfl
@[simp]
theorem span_empty : span (∅ : Set α) = ⊥ :=
Submodule.span_empty
@[simp]
theorem span_univ : span (Set.univ : Set α) = ⊤ :=
Submodule.span_univ
theorem span_union (s t : Set α) : span (s ∪ t) = span s ⊔ span t :=
Submodule.span_union _ _
theorem span_iUnion {ι} (s : ι → Set α) : span (⋃ i, s i) = ⨆ i, span (s i) :=
Submodule.span_iUnion _
theorem iSup_eq_span {ι} (p : ι → Ideal α) :
⨆ i, p i = span (⋃ i, ↑(p i)) :=
Submodule.iSup_eq_span p
theorem mem_span {s : Set α} (x) : x ∈ span s ↔ ∀ p : Ideal α, s ⊆ p → x ∈ p :=
mem_iInter₂
theorem subset_span {s : Set α} : s ⊆ span s :=
Submodule.subset_span
theorem span_le {s : Set α} {I} : span s ≤ I ↔ s ⊆ I :=
Submodule.span_le
@[gcongr]
theorem span_mono {s t : Set α} : s ⊆ t → span s ≤ span t :=
Submodule.span_mono
@[simp]
theorem span_eq : span (I : Set α) = I :=
Submodule.span_eq _
@[simp]
theorem span_singleton_one : span ({1} : Set α) = ⊤ :=
(eq_top_iff_one _).2 <| subset_span <| mem_singleton _
theorem isCompactElement_top : CompleteLattice.IsCompactElement (⊤ : Ideal α) := by
simpa only [← span_singleton_one] using Submodule.singleton_span_isCompactElement 1
theorem mem_span_insert {s : Set α} {x y} :
x ∈ span (insert y s) ↔ ∃ a, ∃ z ∈ span s, x = a * y + z :=
Submodule.mem_span_insert
theorem mem_span_range_self {β : Type*} {f : β → α} {x : β} : f x ∈ span (range f) :=
subset_span (mem_range_self x)
theorem mem_span_singleton' {x y : α} : x ∈ span ({y} : Set α) ↔ ∃ a, a * y = x :=
Submodule.mem_span_singleton
theorem mem_span_singleton_self (x : α) : x ∈ span ({x} : Set α) :=
Submodule.mem_span_singleton_self x
theorem span_singleton_le_iff_mem {x : α} : span {x} ≤ I ↔ x ∈ I :=
Submodule.span_singleton_le_iff_mem _ _
theorem span_singleton_mul_left_unit {a : α} (h2 : IsUnit a) (x : α) :
span ({a * x} : Set α) = span {x} :=
Submodule.span_singleton_smul_eq h2 x
theorem span_insert (x) (s : Set α) : span (insert x s) = span ({x} : Set α) ⊔ span s :=
Submodule.span_insert x s
theorem span_eq_bot {s : Set α} : span s = ⊥ ↔ ∀ x ∈ s, (x : α) = 0 :=
Submodule.span_eq_bot
@[simp]
theorem span_singleton_eq_bot {x} : span ({x} : Set α) = ⊥ ↔ x = 0 :=
Submodule.span_singleton_eq_bot
theorem span_singleton_ne_top {α : Type*} [CommSemiring α] {x : α} (hx : ¬IsUnit x) :
Ideal.span ({x} : Set α) ≠ ⊤ :=
(Ideal.ne_top_iff_one _).mpr fun h1 =>
let ⟨y, hy⟩ := Ideal.mem_span_singleton'.mp h1
hx ⟨⟨x, y, mul_comm y x ▸ hy, hy⟩, rfl⟩
@[simp]
theorem span_zero : span (0 : Set α) = ⊥ := by rw [← Set.singleton_zero, span_singleton_eq_bot]
@[simp]
lemma span_singleton_zero : span {(0 : α)} = ⊥ := Submodule.span_zero_singleton _
@[simp]
theorem span_insert_zero {s : Set α} : span (insert (0 : α) s) = span s :=
Submodule.span_insert_zero
@[simp]
lemma span_sdiff_singleton_zero {s : Set α} : span (s \ {0}) = span s :=
Submodule.span_sdiff_singleton_zero
@[simp]
theorem span_one : span (1 : Set α) = ⊤ := by rw [← Set.singleton_one, span_singleton_one]
theorem span_eq_top_iff_finite (s : Set α) :
span s = ⊤ ↔ ∃ s' : Finset α, ↑s' ⊆ s ∧ span (s' : Set α) = ⊤ := by
simp_rw [eq_top_iff_one]
exact ⟨Submodule.mem_span_finite_of_mem_span, fun ⟨s', h₁, h₂⟩ => span_mono h₁ h₂⟩
theorem mem_span_singleton_sup {x y : α} {I : Ideal α} :
x ∈ Ideal.span {y} ⊔ I ↔ ∃ a : α, ∃ b ∈ I, a * y + b = x := by
rw [Submodule.mem_sup]
constructor
· rintro ⟨ya, hya, b, hb, rfl⟩
obtain ⟨a, rfl⟩ := mem_span_singleton'.mp hya
exact ⟨a, b, hb, rfl⟩
· rintro ⟨a, b, hb, rfl⟩
exact ⟨a * y, Ideal.mem_span_singleton'.mpr ⟨a, rfl⟩, b, hb, rfl⟩
/-- The ideal generated by an arbitrary binary relation. -/
def ofRel (r : α → α → Prop) : Ideal α :=
Submodule.span α { x | ∃ a b, r a b ∧ x + b = a }
theorem zero_ne_one_of_proper {I : Ideal α} (h : I ≠ ⊤) : (0 : α) ≠ 1 := fun hz =>
I.ne_top_iff_one.1 h <| hz ▸ I.zero_mem
theorem span_pair_comm {x y : α} : (span {x, y} : Ideal α) = span {y, x} := by
simp only [span_insert, sup_comm]
theorem mem_span_pair {x y z : α} : z ∈ span ({x, y} : Set α) ↔ ∃ a b, a * x + b * y = z :=
Submodule.mem_span_pair
@[simp]
theorem span_pair_add_mul_left {R : Type u} [CommRing R] {x y : R} (z : R) :
(span {x + y * z, y} : Ideal R) = span {x, y} := by
ext
rw [mem_span_pair, mem_span_pair]
exact
⟨fun ⟨a, b, h⟩ =>
⟨a, b + a * z, by
rw [← h]
ring1⟩,
fun ⟨a, b, h⟩ =>
⟨a, b - a * z, by
rw [← h]
ring1⟩⟩
@[simp]
theorem span_pair_add_mul_right {R : Type u} [CommRing R] {x y : R} (z : R) :
(span {x, y + x * z} : Ideal R) = span {x, y} := by
rw [span_pair_comm, span_pair_add_mul_left, span_pair_comm]
end Semiring
section CommSemiring
variable [CommSemiring α] (I : Ideal α)
theorem mem_span_singleton {x y : α} : x ∈ span ({y} : Set α) ↔ y ∣ x :=
mem_span_singleton'.trans <| exists_congr fun _ => by rw [eq_comm, mul_comm]
theorem span_singleton_le_span_singleton {x y : α} :
span ({x} : Set α) ≤ span ({y} : Set α) ↔ y ∣ x :=
span_le.trans <| singleton_subset_iff.trans mem_span_singleton
theorem span_singleton_eq_span_singleton {α : Type u} [CommSemiring α] [IsDomain α] {x y : α} :
span ({x} : Set α) = span ({y} : Set α) ↔ Associated x y := by
rw [← dvd_dvd_iff_associated, le_antisymm_iff, and_comm]
apply and_congr <;> rw [span_singleton_le_span_singleton]
@[simp]
theorem span_pair_eq_span_left_iff_dvd {x y : α} : span {x, y} = span {x} ↔ x ∣ y := by
rw [Ideal.span_insert, sup_eq_left, span_singleton_le_span_singleton]
@[simp]
theorem span_pair_eq_span_right_iff_dvd {x y : α} : span {x, y} = span {y} ↔ y ∣ x := by
rw [Ideal.span_insert, sup_eq_right, span_singleton_le_span_singleton]
theorem span_singleton_mul_right_unit {a : α} (h2 : IsUnit a) (x : α) :
span ({x * a} : Set α) = span {x} := by rw [mul_comm, span_singleton_mul_left_unit h2]
@[simp]
theorem span_singleton_eq_top {x} : span ({x} : Set α) = ⊤ ↔ IsUnit x := by
rw [isUnit_iff_dvd_one, ← span_singleton_le_span_singleton, span_singleton_one, eq_top_iff]
theorem factors_decreasing [IsDomain α] (b₁ b₂ : α) (h₁ : b₁ ≠ 0) (h₂ : ¬IsUnit b₂) :
span ({b₁ * b₂} : Set α) < span {b₁} :=
lt_of_le_not_ge
(Ideal.span_le.2 <| singleton_subset_iff.2 <| Ideal.mem_span_singleton.2 ⟨b₂, rfl⟩) fun h =>
h₂ <| isUnit_of_dvd_one <|
(mul_dvd_mul_iff_left h₁).1 <| by rwa [mul_one, ← Ideal.span_singleton_le_span_singleton]
end CommSemiring
section Ring
variable [Ring α] (I : Ideal α)
theorem mem_span_insert' {s : Set α} {x y} : x ∈ span (insert y s) ↔ ∃ a, x + a * y ∈ span s :=
Submodule.mem_span_insert'
@[simp]
theorem span_singleton_neg (x : α) : (span {-x} : Ideal α) = span {x} := by
ext
simp only [mem_span_singleton']
exact ⟨fun ⟨y, h⟩ => ⟨-y, h ▸ neg_mul_comm y x⟩, fun ⟨y, h⟩ => ⟨-y, h ▸ neg_mul_neg y x⟩⟩
@[simp]
theorem span_singleton_abs [LinearOrder α] (x : α) :
span {|x|} = span {x} := by
obtain h | h := abs_choice x <;>
simp [h]
end Ring
end Ideal
namespace IsIdempotentElem
variable {R} [CommRing R] {e : R} (he : IsIdempotentElem e)
include he
theorem ker_toSpanSingleton_eq_span :
LinearMap.ker (LinearMap.toSpanSingleton R R e) = Ideal.span {1 - e} := SetLike.ext fun x ↦ by
rw [Ideal.mem_span_singleton']
refine ⟨fun h ↦ ⟨x, by rw [mul_sub, show x * e = 0 from h, mul_one, sub_zero]⟩, fun h ↦ ?_⟩
obtain ⟨x, rfl⟩ := h
change x * (1 - e) * e = 0
rw [mul_assoc, sub_mul, one_mul, he, sub_self, mul_zero]
theorem ker_toSpanSingleton_one_sub_eq_span :
LinearMap.ker (LinearMap.toSpanSingleton R R (1 - e)) = Ideal.span {e} := by
rw [ker_toSpanSingleton_eq_span he.one_sub, sub_sub_cancel]
end IsIdempotentElem
section PrincipalIdeal
instance {R : Type*} [Semiring R] {x : R} : (Ideal.span {x}).IsPrincipal :=
⟨x, rfl⟩
end PrincipalIdeal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/BigOperators.lean | import Mathlib.Algebra.Module.Submodule.Basic
import Mathlib.RingTheory.Ideal.Defs
/-!
# Big operators for ideals
This contains some results on the big operators `∑` and `∏` interacting with the `Ideal` type.
-/
universe u v w
variable {α : Type u} {β : Type v} {F : Type w}
namespace Ideal
variable [Semiring α] (I : Ideal α) {a b : α}
theorem sum_mem (I : Ideal α) {ι : Type*} {t : Finset ι} {f : ι → α} :
(∀ c ∈ t, f c ∈ I) → (∑ i ∈ t, f i) ∈ I :=
Submodule.sum_mem I
end Ideal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Prime.lean | import Mathlib.RingTheory.Ideal.Lattice
/-!
# Prime ideals
This file contains the definition of `Ideal.IsPrime` for prime ideals.
## TODO
Support right ideals, and two-sided ideals over non-commutative rings.
-/
universe u v w
variable {α : Type u} {β : Type v} {F : Type w}
open Set Function
open Pointwise
section Semiring
namespace Ideal
variable [Semiring α] (I : Ideal α) {a b : α}
/-- An ideal `P` of a ring `R` is prime if `P ≠ R` and `xy ∈ P → x ∈ P ∨ y ∈ P` -/
class IsPrime (I : Ideal α) : Prop where
/-- The prime ideal is not the entire ring. -/
ne_top' : I ≠ ⊤
/-- If a product lies in the prime ideal, then at least one element lies in the prime ideal. -/
mem_or_mem' : ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I
theorem isPrime_iff {I : Ideal α} : IsPrime I ↔ I ≠ ⊤ ∧ ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I :=
⟨fun h => ⟨h.1, h.2⟩, fun h => ⟨h.1, h.2⟩⟩
theorem IsPrime.ne_top {I : Ideal α} (hI : I.IsPrime) : I ≠ ⊤ :=
hI.1
theorem IsPrime.one_notMem {I : Ideal α} (hI : I.IsPrime) : 1 ∉ I :=
mt (eq_top_iff_one I).2 hI.1
theorem one_notMem (I : Ideal α) [hI : I.IsPrime] : 1 ∉ I :=
hI.one_notMem
theorem IsPrime.mem_or_mem {I : Ideal α} (hI : I.IsPrime) {x y : α} : x * y ∈ I → x ∈ I ∨ y ∈ I :=
hI.2
theorem IsPrime.mul_notMem {I : Ideal α} (hI : I.IsPrime) {x y : α} :
x ∉ I → y ∉ I → x * y ∉ I := fun hx hy h ↦
hy ((hI.mem_or_mem h).resolve_left hx)
@[deprecated (since := "2025-05-23")] alias IsPrime.mul_not_mem := IsPrime.mul_notMem
theorem IsPrime.mem_or_mem_of_mul_eq_zero {I : Ideal α} (hI : I.IsPrime) {x y : α} (h : x * y = 0) :
x ∈ I ∨ y ∈ I :=
hI.mem_or_mem (h.symm ▸ I.zero_mem)
theorem IsPrime.mem_of_pow_mem {I : Ideal α} (hI : I.IsPrime) {r : α} (n : ℕ) (H : r ^ n ∈ I) :
r ∈ I := by
induction n with
| zero =>
rw [pow_zero] at H
exact hI.one_notMem.elim H
| succ n ih =>
rw [pow_succ] at H
exact Or.casesOn (hI.mem_or_mem H) ih id
theorem not_isPrime_iff {I : Ideal α} :
¬I.IsPrime ↔ I = ⊤ ∨ ∃ (x : α) (_hx : x ∉ I) (y : α) (_hy : y ∉ I), x * y ∈ I := by
simp_rw [Ideal.isPrime_iff, not_and_or, Ne, Classical.not_not, not_forall, not_or]
exact
or_congr Iff.rfl
⟨fun ⟨x, y, hxy, hx, hy⟩ => ⟨x, hx, y, hy, hxy⟩, fun ⟨x, hx, y, hy, hxy⟩ =>
⟨x, y, hxy, hx, hy⟩⟩
theorem bot_prime [Nontrivial α] [NoZeroDivisors α] : (⊥ : Ideal α).IsPrime :=
⟨fun h => one_ne_zero (α := α) (by rwa [Ideal.eq_top_iff_one, Submodule.mem_bot] at h), fun h =>
mul_eq_zero.mp (by simpa only [Submodule.mem_bot] using h)⟩
theorem IsPrime.mul_mem_iff_mem_or_mem {I : Ideal α} [I.IsTwoSided] (hI : I.IsPrime) :
∀ {x y : α}, x * y ∈ I ↔ x ∈ I ∨ y ∈ I := @fun x y =>
⟨hI.mem_or_mem, by
rintro (h | h)
exacts [I.mul_mem_right y h, I.mul_mem_left x h]⟩
theorem IsPrime.pow_mem_iff_mem {I : Ideal α} (hI : I.IsPrime) {r : α} (n : ℕ) (hn : 0 < n) :
r ^ n ∈ I ↔ r ∈ I :=
⟨hI.mem_of_pow_mem n, fun hr => I.pow_mem_of_mem hr n hn⟩
/-- The complement of a prime ideal `P ⊆ R` is a submonoid of `R`. -/
def primeCompl (P : Ideal α) [hp : P.IsPrime] : Submonoid α where
carrier := (Pᶜ : Set α)
one_mem' := P.one_notMem
mul_mem' {_ _} hnx hny hxy := Or.casesOn (hp.mem_or_mem hxy) hnx hny
@[simp]
theorem mem_primeCompl_iff {P : Ideal α} [P.IsPrime] {x : α} :
x ∈ P.primeCompl ↔ x ∉ P := Iff.rfl
end Ideal
end Semiring
section Ring
theorem IsDomain.of_bot_isPrime (A : Type*) [Ring A] [hbp : (⊥ : Ideal A).IsPrime] : IsDomain A :=
@NoZeroDivisors.to_isDomain A _ ⟨1, 0, fun h => hbp.one_notMem h⟩ ⟨fun h => hbp.2 h⟩
end Ring
section DivisionSemiring
variable {K : Type u} [DivisionSemiring K] (I : Ideal K)
namespace Ideal
theorem eq_bot_of_prime [h : I.IsPrime] : I = ⊥ :=
or_iff_not_imp_right.mp I.eq_bot_or_top h.1
end Ideal
end DivisionSemiring |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Cotangent.lean | import Mathlib.Algebra.Module.Torsion.Basic
import Mathlib.Algebra.Ring.Idempotent
import Mathlib.LinearAlgebra.Dimension.Finite
import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition
import Mathlib.LinearAlgebra.FiniteDimensional.Defs
import Mathlib.RingTheory.Filtration
import Mathlib.RingTheory.Ideal.Operations
import Mathlib.RingTheory.LocalRing.ResidueField.Basic
import Mathlib.RingTheory.Nakayama
/-!
# The module `I ⧸ I ^ 2`
In this file, we provide special API support for the module `I ⧸ I ^ 2`. The official
definition is a quotient module of `I`, but the alternative definition as an ideal of `R ⧸ I ^ 2` is
also given, and the two are `R`-equivalent as in `Ideal.cotangentEquivIdeal`.
Additional support is also given to the cotangent space `m ⧸ m ^ 2` of a local ring.
-/
namespace Ideal
-- Universes need to be explicit to avoid bad universe levels in `quotCotangent`
universe u v w
variable {R : Type u} {S : Type v} {S' : Type w} [CommRing R] [CommSemiring S] [Algebra S R]
variable [CommSemiring S'] [Algebra S' R] [Algebra S S'] [IsScalarTower S S' R] (I : Ideal R)
/-- `I ⧸ I ^ 2` as a quotient of `I`. -/
def Cotangent : Type _ := I ⧸ (I • ⊤ : Submodule R I)
deriving Inhabited, AddCommGroup, Module (R ⧸ I)
deriving instance Module S, IsScalarTower S S' for Cotangent I
variable [IsNoetherian R I] in deriving instance IsNoetherian R for Cotangent I
/-- The quotient map from `I` to `I ⧸ I ^ 2`. -/
@[simps! -isSimp apply]
def toCotangent : I →ₗ[R] I.Cotangent := Submodule.mkQ _
theorem map_toCotangent_ker : (LinearMap.ker I.toCotangent).map I.subtype = I ^ 2 := by
rw [Ideal.toCotangent, Submodule.ker_mkQ, pow_two, Submodule.map_smul'' I ⊤ (Submodule.subtype I),
Algebra.id.smul_eq_mul, Submodule.map_subtype_top]
theorem mem_toCotangent_ker {x : I} : x ∈ LinearMap.ker I.toCotangent ↔ (x : R) ∈ I ^ 2 := by
rw [← I.map_toCotangent_ker]
simp
theorem toCotangent_eq {x y : I} : I.toCotangent x = I.toCotangent y ↔ (x - y : R) ∈ I ^ 2 := by
rw [← sub_eq_zero]
exact I.mem_toCotangent_ker
theorem toCotangent_eq_zero (x : I) : I.toCotangent x = 0 ↔ (x : R) ∈ I ^ 2 := I.mem_toCotangent_ker
theorem toCotangent_surjective : Function.Surjective I.toCotangent := Submodule.mkQ_surjective _
theorem toCotangent_range : LinearMap.range I.toCotangent = ⊤ := Submodule.range_mkQ _
theorem cotangent_subsingleton_iff : Subsingleton I.Cotangent ↔ IsIdempotentElem I := by
constructor
· intro H
refine (pow_two I).symm.trans (le_antisymm (Ideal.pow_le_self two_ne_zero) ?_)
exact fun x hx => (I.toCotangent_eq_zero ⟨x, hx⟩).mp (Subsingleton.elim _ _)
· exact fun e =>
⟨fun x y =>
Quotient.inductionOn₂' x y fun x y =>
I.toCotangent_eq.mpr <| ((pow_two I).trans e).symm ▸ I.sub_mem x.prop y.prop⟩
/-- The inclusion map `I ⧸ I ^ 2` to `R ⧸ I ^ 2`. -/
def cotangentToQuotientSquare : I.Cotangent →ₗ[R] R ⧸ I ^ 2 :=
Submodule.mapQ (I • ⊤) (I ^ 2) I.subtype
(by
rw [← Submodule.map_le_iff_le_comap, Submodule.map_smul'', Submodule.map_top,
Submodule.range_subtype, smul_eq_mul, pow_two] )
theorem to_quotient_square_comp_toCotangent :
I.cotangentToQuotientSquare.comp I.toCotangent = (I ^ 2).mkQ.comp (Submodule.subtype I) :=
LinearMap.ext fun _ => rfl
@[simp]
theorem toCotangent_to_quotient_square (x : I) :
I.cotangentToQuotientSquare (I.toCotangent x) = (I ^ 2).mkQ x := rfl
lemma Cotangent.smul_eq_zero_of_mem {I : Ideal R}
{x} (hx : x ∈ I) (m : I.Cotangent) : x • m = 0 := by
obtain ⟨m, rfl⟩ := Ideal.toCotangent_surjective _ m
rw [← map_smul, Ideal.toCotangent_eq_zero, pow_two]
exact Ideal.mul_mem_mul hx m.2
lemma isTorsionBySet_cotangent :
Module.IsTorsionBySet R I.Cotangent I :=
fun m x ↦ m.smul_eq_zero_of_mem x.2
/-- `I ⧸ I ^ 2` as an ideal of `R ⧸ I ^ 2`. -/
def cotangentIdeal (I : Ideal R) : Ideal (R ⧸ I ^ 2) :=
Submodule.map (Quotient.mk (I ^ 2)|>.toSemilinearMap) I
theorem cotangentIdeal_square (I : Ideal R) : I.cotangentIdeal ^ 2 = ⊥ := by
rw [eq_bot_iff, pow_two I.cotangentIdeal, ← smul_eq_mul]
intro x hx
refine Submodule.smul_induction_on hx ?_ ?_
· rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩; apply (Submodule.Quotient.eq _).mpr _
rw [sub_zero, pow_two]; exact Ideal.mul_mem_mul hx hy
· intro x y hx hy; exact add_mem hx hy
lemma mk_mem_cotangentIdeal {I : Ideal R} {x : R} :
Quotient.mk (I ^ 2) x ∈ I.cotangentIdeal ↔ x ∈ I := by
refine ⟨fun ⟨y, hy, e⟩ ↦ ?_, fun h ↦ ⟨x, h, rfl⟩⟩
simpa using sub_mem hy (Ideal.pow_le_self two_ne_zero
((Ideal.Quotient.mk_eq_mk_iff_sub_mem _ _).mp e))
lemma comap_cotangentIdeal (I : Ideal R) :
I.cotangentIdeal.comap (Quotient.mk (I ^ 2)) = I :=
Ideal.ext fun _ ↦ mk_mem_cotangentIdeal
theorem range_cotangentToQuotientSquare :
LinearMap.range I.cotangentToQuotientSquare = I.cotangentIdeal.restrictScalars R := by
trans LinearMap.range (I.cotangentToQuotientSquare.comp I.toCotangent)
· rw [LinearMap.range_comp, I.toCotangent_range, Submodule.map_top]
· rw [to_quotient_square_comp_toCotangent, LinearMap.range_comp, I.range_subtype]; ext; rfl
/-- The equivalence of the two definitions of `I / I ^ 2`, either as the quotient of `I` or the
ideal of `R / I ^ 2`. -/
noncomputable def cotangentEquivIdeal : I.Cotangent ≃ₗ[R] I.cotangentIdeal := by
refine
{ LinearMap.codRestrict (I.cotangentIdeal.restrictScalars R) I.cotangentToQuotientSquare
fun x => by rw [← range_cotangentToQuotientSquare]; exact LinearMap.mem_range_self _ _,
Equiv.ofBijective _ ⟨?_, ?_⟩ with }
· rintro x y e
replace e := congr_arg Subtype.val e
obtain ⟨x, rfl⟩ := I.toCotangent_surjective x
obtain ⟨y, rfl⟩ := I.toCotangent_surjective y
rw [I.toCotangent_eq]
dsimp only [toCotangent_to_quotient_square, Submodule.mkQ_apply] at e
rwa [Submodule.Quotient.eq] at e
· rintro ⟨_, x, hx, rfl⟩
exact ⟨I.toCotangent ⟨x, hx⟩, Subtype.ext rfl⟩
@[simp]
theorem cotangentEquivIdeal_apply (x : I.Cotangent) :
↑(I.cotangentEquivIdeal x) = I.cotangentToQuotientSquare x := rfl
theorem cotangentEquivIdeal_symm_apply (x : R) (hx : x ∈ I) :
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specify `(R₂ := R)` because `I.toCotangent` suggested `R ⧸ I^2` instead
I.cotangentEquivIdeal.symm ⟨(I ^ 2).mkQ x,
-- timeout (200000 heartbeats) without `by exact`
by exact Submodule.mem_map_of_mem (F := R →ₗ[R] R ⧸ I ^ 2) (f := (I ^ 2).mkQ) hx⟩ =
I.toCotangent (R := R) ⟨x, hx⟩ := by
apply I.cotangentEquivIdeal.injective
rw [I.cotangentEquivIdeal.apply_symm_apply]
ext
rfl
variable {A B : Type*} [CommRing A] [CommRing B] [Algebra R A] [Algebra R B]
/-- The lift of `f : A →ₐ[R] B` to `A ⧸ J ^ 2 →ₐ[R] B` with `J` being the kernel of `f`. -/
def _root_.AlgHom.kerSquareLift (f : A →ₐ[R] B) : A ⧸ RingHom.ker f.toRingHom ^ 2 →ₐ[R] B := by
refine { Ideal.Quotient.lift (RingHom.ker f.toRingHom ^ 2) f.toRingHom ?_ with commutes' := ?_ }
· intro a ha; exact Ideal.pow_le_self two_ne_zero ha
· intro r
rw [IsScalarTower.algebraMap_apply R A, RingHom.toFun_eq_coe, Ideal.Quotient.algebraMap_eq,
Ideal.Quotient.lift_mk]
exact f.map_algebraMap r
theorem _root_.AlgHom.ker_kerSquareLift (f : A →ₐ[R] B) :
RingHom.ker f.kerSquareLift.toRingHom = (RingHom.ker f.toRingHom).cotangentIdeal := by
apply le_antisymm
· intro x hx; obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x; exact ⟨x, hx, rfl⟩
· rintro _ ⟨x, hx, rfl⟩; exact hx
instance Algebra.kerSquareLift : Algebra (R ⧸ (RingHom.ker (algebraMap R A) ^ 2)) A :=
(Algebra.ofId R A).kerSquareLift.toAlgebra
instance [Algebra A B] [IsScalarTower R A B] :
IsScalarTower R (A ⧸ (RingHom.ker (algebraMap A B) ^ 2)) B :=
IsScalarTower.of_algebraMap_eq'
(IsScalarTower.toAlgHom R A B).kerSquareLift.comp_algebraMap.symm
/-- The quotient ring of `I ⧸ I ^ 2` is `R ⧸ I`. -/
def quotCotangent : (R ⧸ I ^ 2) ⧸ I.cotangentIdeal ≃+* R ⧸ I := by
refine (Ideal.quotEquivOfEq (Ideal.map_eq_submodule_map _ _).symm).trans ?_
refine (DoubleQuot.quotQuotEquivQuotSup _ _).trans ?_
exact Ideal.quotEquivOfEq (sup_eq_right.mpr <| Ideal.pow_le_self two_ne_zero)
/-- The map `I/I² → J/J²` if `I ≤ f⁻¹(J)`. -/
def mapCotangent (I₁ : Ideal A) (I₂ : Ideal B) (f : A →ₐ[R] B) (h : I₁ ≤ I₂.comap f) :
I₁.Cotangent →ₗ[R] I₂.Cotangent := by
refine Submodule.mapQ ((I₁ • ⊤ : Submodule A I₁).restrictScalars R)
((I₂ • ⊤ : Submodule B I₂).restrictScalars R) ?_ ?_
· exact f.toLinearMap.restrict (p := I₁.restrictScalars R) (q := I₂.restrictScalars R) h
· intro x hx
rw [Submodule.restrictScalars_mem] at hx
refine Submodule.smul_induction_on hx ?_ (fun _ _ ↦ add_mem)
rintro a ha ⟨b, hb⟩ -
simp only [SetLike.mk_smul_mk, smul_eq_mul, Submodule.mem_comap, Submodule.restrictScalars_mem]
convert (Submodule.smul_mem_smul (M := I₂) (r := f a)
(n := ⟨f b, h hb⟩) (h ha) (Submodule.mem_top)) using 1
ext
exact map_mul f a b
@[simp]
lemma mapCotangent_toCotangent
(I₁ : Ideal A) (I₂ : Ideal B) (f : A →ₐ[R] B) (h : I₁ ≤ I₂.comap f) (x : I₁) :
Ideal.mapCotangent I₁ I₂ f h (Ideal.toCotangent I₁ x) = Ideal.toCotangent I₂ ⟨f x, h x.2⟩ := rfl
end Ideal
namespace IsLocalRing
variable (R : Type*) [CommRing R] [IsLocalRing R]
/-- The `A ⧸ I`-vector space `I ⧸ I ^ 2`. -/
abbrev CotangentSpace : Type _ := (maximalIdeal R).Cotangent
instance : Module (ResidueField R) (CotangentSpace R) :=
inferInstanceAs <| Module (R ⧸ maximalIdeal R) _
instance : IsScalarTower R (ResidueField R) (CotangentSpace R) :=
inferInstanceAs <| IsScalarTower R (R ⧸ maximalIdeal R) _
instance [IsNoetherianRing R] : FiniteDimensional (ResidueField R) (CotangentSpace R) :=
Module.Finite.of_restrictScalars_finite R _ _
variable {R}
lemma subsingleton_cotangentSpace_iff [IsNoetherianRing R] :
Subsingleton (CotangentSpace R) ↔ IsField R := by
refine (maximalIdeal R).cotangent_subsingleton_iff.trans ?_
rw [IsLocalRing.isField_iff_maximalIdeal_eq,
Ideal.isIdempotentElem_iff_eq_bot_or_top_of_isLocalRing]
simp [(maximalIdeal.isMaximal R).ne_top]
lemma CotangentSpace.map_eq_top_iff [IsNoetherianRing R] {M : Submodule R (maximalIdeal R)} :
M.map (maximalIdeal R).toCotangent = ⊤ ↔ M = ⊤ := by
refine ⟨fun H ↦ eq_top_iff.mpr ?_, by rintro rfl; simp [Ideal.toCotangent_range]⟩
refine (Submodule.map_le_map_iff_of_injective (Submodule.injective_subtype _) _ _).mp ?_
rw [Submodule.map_top, Submodule.range_subtype]
apply Submodule.le_of_le_smul_of_le_jacobson_bot (IsNoetherian.noetherian _)
(IsLocalRing.jacobson_eq_maximalIdeal _ bot_ne_top).ge
rw [smul_eq_mul, ← pow_two, ← Ideal.map_toCotangent_ker, ← Submodule.map_sup,
← Submodule.comap_map_eq, H, Submodule.comap_top, Submodule.map_top, Submodule.range_subtype]
lemma CotangentSpace.span_image_eq_top_iff [IsNoetherianRing R] {s : Set (maximalIdeal R)} :
Submodule.span (ResidueField R) ((maximalIdeal R).toCotangent '' s) = ⊤ ↔
Submodule.span R s = ⊤ := by
rw [← map_eq_top_iff, ← (Submodule.restrictScalars_injective R ..).eq_iff,
Submodule.restrictScalars_span]
· simp only [Ideal.toCotangent_apply, Submodule.restrictScalars_top, Submodule.map_span]
· exact Ideal.Quotient.mk_surjective
open Module
lemma finrank_cotangentSpace_eq_zero_iff [IsNoetherianRing R] :
finrank (ResidueField R) (CotangentSpace R) = 0 ↔ IsField R := by
rw [finrank_zero_iff, subsingleton_cotangentSpace_iff]
lemma finrank_cotangentSpace_eq_zero (R) [Field R] :
finrank (ResidueField R) (CotangentSpace R) = 0 :=
finrank_cotangentSpace_eq_zero_iff.mpr (Field.toIsField R)
open Submodule in
theorem finrank_cotangentSpace_le_one_iff [IsNoetherianRing R] :
finrank (ResidueField R) (CotangentSpace R) ≤ 1 ↔ (maximalIdeal R).IsPrincipal := by
rw [Module.finrank_le_one_iff_top_isPrincipal, isPrincipal_iff,
(maximalIdeal R).toCotangent_surjective.exists, isPrincipal_iff]
simp_rw [← Set.image_singleton, eq_comm (a := ⊤), CotangentSpace.span_image_eq_top_iff,
← (map_injective_of_injective (injective_subtype _)).eq_iff, map_span, Set.image_singleton,
Submodule.map_top, range_subtype, eq_comm (a := maximalIdeal R)]
exact ⟨fun ⟨x, h⟩ ↦ ⟨_, h⟩, fun ⟨x, h⟩ ↦ ⟨⟨x, h ▸ subset_span (Set.mem_singleton x)⟩, h⟩⟩
end IsLocalRing |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Basis.lean | import Mathlib.Algebra.Algebra.Bilinear
import Mathlib.LinearAlgebra.Basis.Defs
import Mathlib.LinearAlgebra.Basis.Submodule
import Mathlib.RingTheory.Ideal.Span
/-!
# The basis of ideals
Some results involving `Ideal` and `Basis`.
-/
open Module
namespace Ideal
variable {ι R S : Type*} [CommSemiring R] [CommRing S] [IsDomain S] [Algebra R S]
/-- A basis on `S` gives a basis on `Ideal.span {x}`, by multiplying everything by `x`. -/
noncomputable def basisSpanSingleton (b : Basis ι R S) {x : S} (hx : x ≠ 0) :
Basis ι R (span ({x} : Set S)) :=
b.map <|
LinearEquiv.ofInjective (LinearMap.mulLeft R x) (mul_right_injective₀ hx) ≪≫ₗ
LinearEquiv.ofEq _ _
(by
ext
simp [mem_span_singleton', mul_comm]) ≪≫ₗ
(Submodule.restrictScalarsEquiv R S S (Ideal.span ({x} : Set S))).restrictScalars R
@[simp]
theorem basisSpanSingleton_apply (b : Basis ι R S) {x : S} (hx : x ≠ 0) (i : ι) :
(basisSpanSingleton b hx i : S) = x * b i := by
simp only [basisSpanSingleton, Basis.map_apply, LinearEquiv.trans_apply,
Submodule.restrictScalarsEquiv_apply, LinearEquiv.ofInjective_apply, LinearEquiv.coe_ofEq_apply,
LinearEquiv.restrictScalars_apply, LinearMap.mulLeft_apply]
@[simp]
theorem constr_basisSpanSingleton {N : Type*} [Semiring N] [Module N S] [SMulCommClass R N S]
(b : Basis ι R S) {x : S} (hx : x ≠ 0) :
(b.constr N).toFun (((↑) : _ → S) ∘ (basisSpanSingleton b hx)) = Algebra.lmul R S x :=
b.ext fun i => by simp
end Ideal
/-- If `I : Ideal S` has a basis over `R`,
`x ∈ I` iff it is a linear combination of basis vectors. -/
theorem Basis.mem_ideal_iff {ι R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S]
{I : Ideal S} (b : Basis ι R I) {x : S} :
x ∈ I ↔ ∃ c : ι →₀ R, x = Finsupp.sum c fun i x => x • (b i : S) :=
(b.map ((I.restrictScalarsEquiv R _ _).restrictScalars R).symm).mem_submodule_iff
/-- If `I : Ideal S` has a finite basis over `R`,
`x ∈ I` iff it is a linear combination of basis vectors. -/
theorem Basis.mem_ideal_iff' {ι R S : Type*} [Fintype ι] [CommSemiring R] [Semiring S] [Algebra R S]
{I : Ideal S} (b : Basis ι R I) {x : S} : x ∈ I ↔ ∃ c : ι → R, x = ∑ i, c i • (b i : S) :=
(b.map ((I.restrictScalarsEquiv R _ _).restrictScalars R).symm).mem_submodule_iff' |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Lattice.lean | import Mathlib.Algebra.Module.Submodule.Lattice
import Mathlib.RingTheory.Ideal.Defs
import Mathlib.Tactic.Ring
/-!
# The lattice of ideals in a ring
Some basic results on lattice operations on ideals: `⊥`, `⊤`, `⊔`, `⊓`.
## TODO
Support right ideals, and two-sided ideals over non-commutative rings.
-/
universe u v w
variable {α : Type u} {β : Type v} {F : Type w}
open Set Function
open Pointwise
section Semiring
namespace Ideal
variable [Semiring α] (I : Ideal α) {a b : α}
instance (priority := low) : IsTwoSided (⊥ : Ideal α) :=
⟨fun _ h ↦ by rw [h, zero_mul]; exact zero_mem _⟩
instance (priority := low) : IsTwoSided (⊤ : Ideal α) := ⟨fun _ _ ↦ trivial⟩
instance (priority := low) {ι} (I : ι → Ideal α) [∀ i, (I i).IsTwoSided] : (⨅ i, I i).IsTwoSided :=
⟨fun _ h ↦ (Submodule.mem_iInf _).mpr (mul_mem_right _ _ <| (Submodule.mem_iInf _).mp h ·)⟩
theorem eq_top_of_unit_mem (x y : α) (hx : x ∈ I) (h : y * x = 1) : I = ⊤ :=
eq_top_iff.2 fun z _ =>
calc
z * y * x ∈ I := I.mul_mem_left _ hx
_ = z * (y * x) := mul_assoc z y x
_ = z := by rw [h, mul_one]
theorem eq_top_of_isUnit_mem {x} (hx : x ∈ I) (h : IsUnit x) : I = ⊤ :=
let ⟨y, hy⟩ := h.exists_left_inv
eq_top_of_unit_mem I x y hx hy
theorem eq_top_iff_one : I = ⊤ ↔ (1 : α) ∈ I :=
⟨by rintro rfl; trivial, fun h => eq_top_of_unit_mem _ _ 1 h (by simp)⟩
theorem ne_top_iff_one : I ≠ ⊤ ↔ (1 : α) ∉ I :=
not_congr I.eq_top_iff_one
section Lattice
variable {R : Type u} [Semiring R]
theorem mem_sup_left {S T : Ideal R} : ∀ {x : R}, x ∈ S → x ∈ S ⊔ T :=
@le_sup_left _ _ S T
theorem mem_sup_right {S T : Ideal R} : ∀ {x : R}, x ∈ T → x ∈ S ⊔ T :=
@le_sup_right _ _ S T
theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Ideal R} (i : ι) : ∀ {x : R}, x ∈ S i → x ∈ iSup S :=
@le_iSup _ _ _ S _
theorem mem_sSup_of_mem {S : Set (Ideal R)} {s : Ideal R} (hs : s ∈ S) :
∀ {x : R}, x ∈ s → x ∈ sSup S :=
@le_sSup _ _ _ _ hs
theorem mem_sInf {s : Set (Ideal R)} {x : R} : x ∈ sInf s ↔ ∀ ⦃I⦄, I ∈ s → x ∈ I :=
⟨fun hx I his => hx I ⟨I, iInf_pos his⟩, fun H _I ⟨_J, hij⟩ => hij ▸ fun _S ⟨hj, hS⟩ => hS ▸ H hj⟩
theorem mem_inf {I J : Ideal R} {x : R} : x ∈ I ⊓ J ↔ x ∈ I ∧ x ∈ J :=
Iff.rfl
theorem mem_iInf {ι : Sort*} {I : ι → Ideal R} {x : R} : x ∈ iInf I ↔ ∀ i, x ∈ I i :=
Submodule.mem_iInf _
theorem mem_bot {x : R} : x ∈ (⊥ : Ideal R) ↔ x = 0 :=
Submodule.mem_bot _
end Lattice
end Ideal
end Semiring
section DivisionSemiring
variable {K : Type u} [DivisionSemiring K] (I : Ideal K)
namespace Ideal
/-- All ideals in a division (semi)ring are trivial. -/
theorem eq_bot_or_top : I = ⊥ ∨ I = ⊤ := by
rw [or_iff_not_imp_right]
change _ ≠ _ → _
rw [Ideal.ne_top_iff_one]
intro h1
rw [eq_bot_iff]
intro r hr
by_cases H : r = 0; · simpa
simpa [H, h1] using I.mul_mem_left r⁻¹ hr
end Ideal
end DivisionSemiring |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Height.lean | import Mathlib.Algebra.Module.SpanRank
import Mathlib.RingTheory.Spectrum.Prime.Noetherian
import Mathlib.RingTheory.Ideal.MinimalPrime.Localization
/-!
# The Height of an Ideal
In this file, we define the height of a prime ideal and the height of an ideal.
## Main definitions
* `Ideal.primeHeight` : The height of a prime ideal $\mathfrak{p}$. We define it as the supremum of
the lengths of strictly decreasing chains of prime ideals below it. This definition is implemented
via `Order.height`.
* `Ideal.height` : The height of an ideal. We defined it as the infimum of the `primeHeight` of the
minimal prime ideals of I.
-/
variable {R : Type*} [CommRing R] (I : Ideal R)
open Ideal
/-- The height of a prime ideal is defined as the supremum of the lengths of strictly decreasing
chains of prime ideals below it. -/
noncomputable def Ideal.primeHeight [hI : I.IsPrime] : ℕ∞ :=
Order.height (⟨I, hI⟩ : PrimeSpectrum R)
/-- The height of an ideal is defined as the infimum of the heights of its minimal prime ideals. -/
noncomputable def Ideal.height : ℕ∞ :=
⨅ J ∈ I.minimalPrimes, @Ideal.primeHeight _ _ J (minimalPrimes_isPrime ‹_›)
/-- For a prime ideal, its height equals its prime height. -/
lemma Ideal.height_eq_primeHeight [I.IsPrime] : I.height = I.primeHeight := by
unfold height primeHeight
simp_rw [Ideal.minimalPrimes_eq_subsingleton_self]
simp
/-- An ideal has finite height if it is either the unit ideal or its height is finite.
We include the unit ideal in order to have the instance `IsNoetherianRing R → FiniteHeight I`. -/
@[mk_iff]
class Ideal.FiniteHeight : Prop where
eq_top_or_height_ne_top : I = ⊤ ∨ I.height ≠ ⊤
lemma Ideal.finiteHeight_iff_lt {I : Ideal R} :
Ideal.FiniteHeight I ↔ I = ⊤ ∨ I.height < ⊤ := by
rw [Ideal.finiteHeight_iff, lt_top_iff_ne_top]
lemma Ideal.height_ne_top {I : Ideal R} (hI : I ≠ ⊤) [I.FiniteHeight] :
I.height ≠ ⊤ :=
(‹I.FiniteHeight›.eq_top_or_height_ne_top).resolve_left hI
lemma Ideal.height_lt_top {I : Ideal R} (hI : I ≠ ⊤) [I.FiniteHeight] :
I.height < ⊤ :=
(Ideal.height_ne_top hI).lt_top
lemma Ideal.primeHeight_ne_top (I : Ideal R) [I.FiniteHeight] [I.IsPrime] :
I.primeHeight ≠ ⊤ := by
rw [← I.height_eq_primeHeight]
exact Ideal.height_ne_top ‹I.IsPrime›.ne_top
lemma Ideal.primeHeight_lt_top (I : Ideal R) [I.FiniteHeight] [I.IsPrime] :
I.primeHeight < ⊤ := by
rw [← I.height_eq_primeHeight]
exact Ideal.height_lt_top ‹I.IsPrime›.ne_top
@[gcongr]
lemma Ideal.primeHeight_mono {I J : Ideal R} [I.IsPrime] [J.IsPrime] (h : I ≤ J) :
I.primeHeight ≤ J.primeHeight := by
unfold primeHeight
gcongr
exact h
lemma Ideal.primeHeight_add_one_le_of_lt {I J : Ideal R} [I.IsPrime] [J.IsPrime] (h : I < J) :
I.primeHeight + 1 ≤ J.primeHeight := by
unfold primeHeight
exact Order.height_add_one_le h
@[simp]
theorem Ideal.height_top : (⊤ : Ideal R).height = ⊤ := by
simp [height, minimalPrimes_top]
@[gcongr]
lemma Ideal.primeHeight_strict_mono {I J : Ideal R} [I.IsPrime] [J.IsPrime]
(h : I < J) [J.FiniteHeight] :
I.primeHeight < J.primeHeight := by
rw [primeHeight]
have : I.FiniteHeight := by
rw [Ideal.finiteHeight_iff, ← lt_top_iff_ne_top, Ideal.height_eq_primeHeight]
right
exact lt_of_le_of_lt (Ideal.primeHeight_mono h.le) (Ideal.primeHeight_lt_top J)
exact Order.height_strictMono h (Ideal.primeHeight_lt_top _)
@[gcongr]
theorem Ideal.height_mono {I J : Ideal R} (h : I ≤ J) : I.height ≤ J.height := by
simp only [height]
refine le_iInf₂ (fun p hp ↦ ?_)
have := Ideal.minimalPrimes_isPrime hp
obtain ⟨q, hq, e⟩ := Ideal.exists_minimalPrimes_le (h.trans hp.1.2)
haveI := Ideal.minimalPrimes_isPrime hq
exact (iInf₂_le q hq).trans (Ideal.primeHeight_mono e)
@[gcongr]
lemma Ideal.height_strict_mono_of_is_prime {I J : Ideal R} [I.IsPrime]
(h : I < J) [I.FiniteHeight] : I.height < J.height := by
rw [Ideal.height_eq_primeHeight I]
by_cases hJ : J = ⊤
· rw [hJ, height_top]
exact I.primeHeight_lt_top
· rw [← ENat.add_one_le_iff I.primeHeight_ne_top, Ideal.height]
refine le_iInf₂ (fun K hK ↦ ?_)
haveI := Ideal.minimalPrimes_isPrime hK
have : I < K := lt_of_lt_of_le h hK.1.2
exact Ideal.primeHeight_add_one_le_of_lt this
lemma Ideal.primeHeight_le_ringKrullDim {I : Ideal R} [I.IsPrime] :
I.primeHeight ≤ ringKrullDim R := Order.height_le_krullDim _
lemma Ideal.height_le_ringKrullDim_of_ne_top {I : Ideal R} (h : I ≠ ⊤) :
I.height ≤ ringKrullDim R := by
rw [Ideal.height]
obtain ⟨P, hP⟩ : Nonempty (I.minimalPrimes) := Ideal.nonempty_minimalPrimes h
have := Ideal.minimalPrimes_isPrime hP
refine le_trans ?_ (Ideal.primeHeight_le_ringKrullDim (I := P))
simpa using iInf₂_le _ hP
/-- If `R` has finite Krull dimension, there exists a maximal ideal `m` with `ht m = dim R`. -/
lemma Ideal.exists_isMaximal_height [FiniteRingKrullDim R] :
∃ (p : Ideal R), p.IsMaximal ∧ p.height = ringKrullDim R := by
let l := LTSeries.longestOf (PrimeSpectrum R)
obtain ⟨m, hm, hle⟩ := l.last.asIdeal.exists_le_maximal IsPrime.ne_top'
refine ⟨m, hm, le_antisymm (height_le_ringKrullDim_of_ne_top IsPrime.ne_top') ?_⟩
trans (l.last.asIdeal.height : WithBot ℕ∞)
· rw [Ideal.height_eq_primeHeight]
exact LTSeries.height_last_longestOf.symm.le
· norm_cast
exact height_mono hle
instance (priority := 900) Ideal.finiteHeight_of_finiteRingKrullDim {I : Ideal R}
[FiniteRingKrullDim R] : I.FiniteHeight := by
rw [finiteHeight_iff, or_iff_not_imp_left, ← lt_top_iff_ne_top, ← WithBot.coe_lt_coe]
intro h
have h1 := ringKrullDim_lt_top (R := R)
have h2 := Ideal.height_le_ringKrullDim_of_ne_top h
exact lt_of_le_of_lt h2 h1
/-- If J has finite height and I ≤ J, then I has finite height -/
lemma Ideal.finiteHeight_of_le {I J : Ideal R} (e : I ≤ J) (hJ : J ≠ ⊤) [FiniteHeight J] :
FiniteHeight I where
eq_top_or_height_ne_top := Or.inr <| by
rw [← lt_top_iff_ne_top]
exact (height_mono e).trans_lt (height_lt_top hJ)
/-- If J is a prime ideal containing I, and its height is less than or equal to the height of I,
then J is a minimal prime over I -/
lemma Ideal.mem_minimalPrimes_of_height_eq {I J : Ideal R} (e : I ≤ J) [J.IsPrime]
[FiniteHeight J] (e' : J.height ≤ I.height) : J ∈ I.minimalPrimes := by
obtain ⟨p, h₁, h₂⟩ := Ideal.exists_minimalPrimes_le e
convert h₁
refine (eq_of_le_of_not_lt h₂ fun h₃ ↦ ?_).symm
have := h₁.1.1
have := finiteHeight_of_le h₂ IsPrime.ne_top'
exact lt_irrefl _
((height_strict_mono_of_is_prime h₃).trans_le (e'.trans <| height_mono h₁.1.2))
/-- A prime ideal has height zero if and only if it is minimal -/
lemma Ideal.primeHeight_eq_zero_iff {I : Ideal R} [I.IsPrime] :
primeHeight I = 0 ↔ I ∈ minimalPrimes R := by
rw [Ideal.primeHeight, Order.height_eq_zero, minimalPrimes, Ideal.minimalPrimes]
simp only [bot_le, and_true, Set.mem_setOf_eq, Minimal, IsMin]
constructor
· intro h
by_contra! h'
obtain ⟨P, ⟨hP₁, ⟨hP₂, hP₃⟩⟩⟩ := h' (inferInstance)
exact hP₃ (h (b := ⟨P, hP₁⟩) hP₂)
· rintro ⟨hI, hI'⟩ b hb
exact hI' (y := b.asIdeal) b.isPrime hb
@[simp]
lemma Ideal.height_bot [Nontrivial R] : (⊥ : Ideal R).height = 0 := by
obtain ⟨p, hp⟩ := Ideal.nonempty_minimalPrimes (R := R) (I := ⊥) top_ne_bot.symm
simp only [Ideal.height, ENat.iInf_eq_zero]
exact ⟨p, hp, haveI := hp.1.1; primeHeight_eq_zero_iff.mpr hp⟩
/-- In a trivial commutative ring, the height of any ideal is `∞`. -/
@[simp, nontriviality]
lemma Ideal.height_of_subsingleton [Subsingleton R] : I.height = ⊤ := by
rw [Subsingleton.elim I ⊤, Ideal.height_top]
theorem Ideal.isMaximal_of_primeHeight_eq_ringKrullDim {I : Ideal R} [I.IsPrime]
[FiniteRingKrullDim R] (e : I.primeHeight = ringKrullDim R) : I.IsMaximal := by
have h : I ≠ ⊤ := by
intro h
simp only [h, ← Ideal.height_eq_primeHeight, Ideal.height_top, WithBot.coe_top] at e
exact ringKrullDim_ne_top e.symm
obtain ⟨M, hM, hM'⟩ := Ideal.exists_le_maximal I h
rcases lt_or_eq_of_le hM' with (hM' | hM')
· have h1 := Ideal.primeHeight_strict_mono hM'
have h2 := e ▸ M.primeHeight_le_ringKrullDim
simp [← not_lt, h1] at h2
· exact hM' ▸ hM
/-- The prime height of the maximal ideal equals the Krull dimension in a local ring -/
@[simp]
theorem IsLocalRing.maximalIdeal_primeHeight_eq_ringKrullDim [IsLocalRing R] :
(IsLocalRing.maximalIdeal R).primeHeight = ringKrullDim R := by
rw [ringKrullDim, Ideal.primeHeight, ← Order.height_top_eq_krullDim]
rfl
/-- The height of the maximal ideal equals the Krull dimension in a local ring. -/
@[simp]
theorem IsLocalRing.maximalIdeal_height_eq_ringKrullDim [IsLocalRing R] :
(IsLocalRing.maximalIdeal R).height = ringKrullDim R := by
rw [Ideal.height_eq_primeHeight, IsLocalRing.maximalIdeal_primeHeight_eq_ringKrullDim]
/-- For a local ring with finite Krull dimension, a prime ideal has height equal to the Krull
dimension if and only if it is the maximal ideal. -/
theorem Ideal.primeHeight_eq_ringKrullDim_iff [FiniteRingKrullDim R] [IsLocalRing R] {I : Ideal R}
[I.IsPrime] : Ideal.primeHeight I = ringKrullDim R ↔ I = IsLocalRing.maximalIdeal R := by
constructor
· intro h
exact IsLocalRing.eq_maximalIdeal (Ideal.isMaximal_of_primeHeight_eq_ringKrullDim h)
· rintro rfl
exact IsLocalRing.maximalIdeal_primeHeight_eq_ringKrullDim
lemma Ideal.height_le_iff {p : Ideal R} {n : ℕ} [p.IsPrime] :
p.height ≤ n ↔ ∀ q : Ideal R, q.IsPrime → q < p → q.height < n := by
rw [height_eq_primeHeight, primeHeight, Order.height_le_coe_iff,
(PrimeSpectrum.equivSubtype R).forall_congr_left, Subtype.forall]
congr!
rw [height_eq_primeHeight, primeHeight]
rfl
lemma Ideal.height_le_iff_covBy {p : Ideal R} {n : ℕ} [p.IsPrime] [IsNoetherianRing R] :
p.height ≤ n ↔ ∀ q : Ideal R, q.IsPrime → q < p →
(∀ q' : Ideal R, q'.IsPrime → q < q' → ¬ q' < p) → q.height < n := by
rw [Ideal.height_le_iff]
constructor
· intro H q hq e _
exact H q hq e
· intro H q hq e
obtain ⟨⟨x, hx⟩, hqx, hxp⟩ :=
@exists_le_covBy_of_lt { I : Ideal R // I.IsPrime } ⟨q, hq⟩ ⟨p, ‹_›⟩ _ _ e
exact (Ideal.height_mono hqx).trans_lt
(H _ hx hxp.1 (fun I hI e ↦ hxp.2 (show Subtype.mk x hx < ⟨I, hI⟩ from e)))
/-- Use `RingEquiv.height_comap` instead, which does not assume `IsPrime`. -/
private lemma RingEquiv.height_comap_of_isPrime {S : Type*} [CommRing S] (e : R ≃+* S)
(p : Ideal S) [p.IsPrime] : (p.comap e).height = p.height := by
rw [height_eq_primeHeight, height_eq_primeHeight, primeHeight, primeHeight,
← Order.height_orderIso (PrimeSpectrum.comapEquiv e.symm) ⟨p, ‹_›⟩]
have := p.map_comap_of_equiv e.symm
congr
@[simp]
lemma RingEquiv.height_comap {S : Type*} [CommRing S] (e : R ≃+* S) (I : Ideal S) :
(I.comap e).height = I.height := by
refine (Equiv.iInf_congr e.idealComapOrderIso fun J ↦ (Equiv.iInf_congr ?_ fun h ↦ ?_).symm).symm
· refine .ofIff ?_
rw [← Ideal.comap_coe,
Ideal.comap_minimalPrimes_eq_of_surjective (f := (↑e : R →+* S)) e.surjective]
exact e.idealComapOrderIso.injective.mem_set_image.symm
· have : J.IsPrime := h.1.1
simp only [EquivLike.coe_coe, RingEquiv.idealComapOrderIso_apply,
← Ideal.height_eq_primeHeight, RingEquiv.height_comap_of_isPrime]
@[simp]
lemma RingEquiv.height_map {S : Type*} [CommRing S] (e : R ≃+* S) (I : Ideal R) :
(I.map e).height = I.height := by
rw [← Ideal.comap_symm e, height_comap]
/-- `dim R ≤ n` if and only if the height of all prime ideals is less than `n`. -/
lemma ringKrullDim_le_iff_height_le {R : Type*} [CommRing R] (n : WithBot ℕ∞) :
ringKrullDim R ≤ n ↔ ∀ ⦃p : Ideal R⦄, p.IsPrime → p.height ≤ n := by
rw [ringKrullDim, Order.krullDim_eq_iSup_height, iSup_le_iff]
refine ⟨fun h p hp ↦ ?_, fun h p ↦ ?_⟩
· rw [Ideal.height_eq_primeHeight]
exact h ⟨p, hp⟩
· specialize h p.2
rwa [Ideal.height_eq_primeHeight] at h
/-- `dim R ≤ n` if and only if the height of all maximal ideals is less than `n`. -/
lemma ringKrullDim_le_iff_isMaximal_height_le {R : Type*} [CommRing R] (n : WithBot ℕ∞) :
ringKrullDim R ≤ n ↔ ∀ ⦃m : Ideal R⦄, m.IsMaximal → m.height ≤ n := by
rw [ringKrullDim_le_iff_height_le]
refine ⟨fun h m hm ↦ h hm.isPrime, fun h p hp ↦ ?_⟩
obtain ⟨m, hm, hle⟩ := p.exists_le_maximal hp.ne_top
refine le_trans ?_ (h hm)
norm_cast
exact Ideal.height_mono hle
theorem IsLocalization.primeHeight_comap (S : Submonoid R) {A : Type*} [CommRing A] [Algebra R A]
[IsLocalization S A] (J : Ideal A) [J.IsPrime] :
(J.comap (algebraMap R A)).primeHeight = J.primeHeight := by
rw [eq_comm, Ideal.primeHeight, Ideal.primeHeight, ← WithBot.coe_inj,
Order.height_eq_krullDim_Iic, Order.height_eq_krullDim_Iic]
let e := IsLocalization.orderIsoOfPrime S A
have H (p : Ideal R) (hp : p ≤ J.comap (algebraMap R A)) : Disjoint (S : Set R) p :=
Set.disjoint_of_subset_right hp (e ⟨_, ‹J.IsPrime›⟩).2.2
exact Order.krullDim_eq_of_orderIso
{ toFun I := ⟨⟨I.1.1.comap (algebraMap R A), (e ⟨_, I.1.2⟩).2.1⟩, Ideal.comap_mono I.2⟩
invFun I := ⟨⟨_, (e.symm ⟨_, I.1.2, H _ I.2⟩).2⟩, Ideal.map_le_iff_le_comap.mpr I.2⟩
left_inv I := Subtype.ext <| PrimeSpectrum.ext_iff.mpr <|
congrArg (fun I ↦ I.1) (e.left_inv ⟨_, I.1.2⟩)
right_inv I := Subtype.ext <| PrimeSpectrum.ext_iff.mpr <|
congrArg (fun I ↦ I.1) (e.right_inv ⟨_, I.1.2, H _ I.2⟩)
map_rel_iff' {I₁ I₂} := @RelIso.map_rel_iff _ _ _ _ e ⟨_, I₁.1.2⟩ ⟨_, I₂.1.2⟩ }
theorem IsLocalization.height_comap (S : Submonoid R) {A : Type*} [CommRing A] [Algebra R A]
[IsLocalization S A] (J : Ideal A) : (J.comap (algebraMap R A)).height = J.height := by
rw [Ideal.height, Ideal.height]
simp_rw [← IsLocalization.primeHeight_comap S, IsLocalization.minimalPrimes_comap S A,
← Ideal.height_eq_primeHeight, iInf_image]
theorem IsLocalization.AtPrime.ringKrullDim_eq_height (I : Ideal R) [I.IsPrime] (A : Type*)
[CommRing A] [Algebra R A] [IsLocalization.AtPrime A I] :
ringKrullDim A = I.height := by
have := IsLocalization.AtPrime.isLocalRing A I
rw [← IsLocalRing.maximalIdeal_primeHeight_eq_ringKrullDim,
← IsLocalization.primeHeight_comap I.primeCompl,
← IsLocalization.AtPrime.comap_maximalIdeal A I,
Ideal.height_eq_primeHeight]
lemma mem_minimalPrimes_of_primeHeight_eq_height {I J : Ideal R} [J.IsPrime] (e : I ≤ J)
(e' : J.primeHeight = I.height) [J.FiniteHeight] : J ∈ I.minimalPrimes := by
rw [← J.height_eq_primeHeight] at e'
exact mem_minimalPrimes_of_height_eq e (e' ▸ le_refl _)
lemma exists_spanRank_le_and_le_height_of_le_height [IsNoetherianRing R] (I : Ideal R) (r : ℕ)
(hr : r ≤ I.height) : ∃ J ≤ I, J.spanRank ≤ r ∧ r ≤ J.height := by
induction r with
| zero =>
refine ⟨⊥, bot_le, ?_, zero_le _⟩
rw [Submodule.spanRank_bot]
exact le_refl 0
| succ r ih =>
obtain ⟨J, h₁, h₂, h₃⟩ := ih ((WithTop.coe_le_coe.mpr r.le_succ).trans hr)
let S := { K | K ∈ J.minimalPrimes ∧ Ideal.height K = r }
have hS : Set.Finite S := Set.Finite.subset J.finite_minimalPrimes_of_isNoetherianRing
(fun _ h => h.1)
have : ¬(I : Set R) ⊆ ⋃ K ∈ hS.toFinset, (K : Set R) := by
refine (Ideal.subset_union_prime ⊥ ⊥ ?_).not.mpr ?_
· rintro K hK - -
rw [Set.Finite.mem_toFinset] at hK
exact hK.1.1.1
· push_neg
intro K hK e
have := hr.trans (Ideal.height_mono e)
rw [Set.Finite.mem_toFinset] at hK
rw [hK.2, ← not_lt] at this
norm_cast at this
exact this r.lt_succ_self
simp_rw [Set.not_subset, Set.mem_iUnion, not_exists, Set.Finite.mem_toFinset] at this
obtain ⟨x, hx₁, hx₂⟩ := this
refine ⟨J ⊔ Ideal.span {x}, sup_le h₁ ?_, ?_, ?_⟩
· rwa [Ideal.span_le, Set.singleton_subset_iff]
· apply Submodule.spanRank_sup_le_sum_spanRank.trans
push_cast
exact add_le_add h₂ ((Submodule.spanRank_span_le_card _).trans (by simp))
· refine le_iInf₂ (fun p hp ↦ ?_)
have := hp.1.1
by_cases h : p.height = ⊤
· rw [← p.height_eq_primeHeight, h]
exact le_top
have : p.FiniteHeight := ⟨Or.inr h⟩
have := Ideal.height_mono (le_sup_left.trans hp.1.2)
suffices h : (r : ℕ∞) ≠ p.primeHeight by
push_cast
have := h₃.trans this
rw [Ideal.height_eq_primeHeight] at this
exact Order.add_one_le_of_lt (lt_of_le_of_ne this h)
intro e
apply hx₂ p
· have : J.height = p.primeHeight := by
apply le_antisymm
· rwa [← p.height_eq_primeHeight]
· rwa [← e]
refine ⟨mem_minimalPrimes_of_primeHeight_eq_height (le_sup_left.trans hp.1.2) this.symm, ?_⟩
rwa [p.height_eq_primeHeight, eq_comm]
· exact hp.1.2 <| Ideal.mem_sup_right <| Ideal.subset_span <| Set.mem_singleton x
/-- In a nontrivial commutative ring `R`, the supremum of heights of all ideals is equal to the
Krull dimension of `R`. -/
lemma Ideal.sup_height_eq_ringKrullDim [Nontrivial R] :
↑(⨆ (I : Ideal R) (_ : I ≠ ⊤), I.height) = ringKrullDim R := by
apply le_antisymm
· rw [WithBot.coe_iSup ⟨⊤, fun _ _ => le_top⟩]
refine iSup_le fun I => ?_
by_cases h : I = ⊤
· simp [h, ringKrullDim_nonneg_of_nontrivial]
· simp [h, height_le_ringKrullDim_of_ne_top]
· refine iSup_le fun p => WithBot.coe_le_coe.mpr (le_trans (b := p.last.asIdeal.height) ?_ ?_)
· rw [height_eq_primeHeight]
apply le_trans (b := ⨆ (_ : p.last ≤ p.last), ↑p.length)
· exact le_iSup (fun _ => (↑p.length : ℕ∞)) le_rfl
· exact le_iSup (fun p' => (⨆ _, p'.length : ℕ∞)) p
· apply le_trans (b := ⨆ (_ : (p.last).asIdeal ≠ ⊤), p.last.asIdeal.height)
· exact le_iSup_of_le p.last.isPrime.ne_top' le_rfl
· exact le_iSup (fun I => ⨆ _, I.height) p.last.asIdeal
/-- In a nontrivial commutative ring `R`, the supremum of prime heights of all prime ideals is
equal to the Krull dimension of `R`. -/
lemma Ideal.sup_primeHeight_eq_ringKrullDim [Nontrivial R] :
↑(⨆ (I : Ideal R) (_ : I.IsPrime), I.primeHeight) = ringKrullDim R := by
rw [← sup_height_eq_ringKrullDim, WithBot.coe_inj]
apply le_antisymm
· exact iSup_mono fun I => iSup_mono' fun hI => ⟨hI.ne_top, by rw [← height_eq_primeHeight]⟩
· refine iSup_mono' fun I => ?_
by_cases I_top : I = ⊤
· exact ⟨⊥, by simp [I_top]⟩
· obtain ⟨P, hP⟩ : I.minimalPrimes.Nonempty :=
Set.nonempty_coe_sort.mp (nonempty_minimalPrimes I_top)
refine ⟨P, iSup_pos (α := ℕ∞) I_top ▸ le_iSup_of_le (hP.left.left) ?_⟩
exact iInf_le_of_le P (iInf_le_of_le hP le_rfl)
/-- In a nontrivial commutative ring `R`, the supremum of prime heights of all maximal ideals is
equal to the Krull dimension of `R`. -/
lemma Ideal.sup_primeHeight_of_maximal_eq_ringKrullDim [Nontrivial R] :
↑(⨆ (I : Ideal R) (_ : I.IsMaximal), I.primeHeight) = ringKrullDim R := by
rw [← Ideal.sup_primeHeight_eq_ringKrullDim, WithBot.coe_inj]
apply le_antisymm
· exact iSup_mono fun I => iSup_mono' fun hI => ⟨IsMaximal.isPrime hI, le_rfl⟩
· refine iSup_mono' fun I => ?_
obtain rfl | I_top := eq_or_ne I ⊤
· exact ⟨⊥, by grind [iSup_le_iff, Ideal.IsPrime.ne_top]⟩
· obtain ⟨M, hM, hIM⟩ := exists_le_maximal I I_top
exact ⟨M, iSup_mono' (fun hI ↦ ⟨hM, primeHeight_mono hIM⟩)⟩
section isLocalization
variable
(Rₚ : ∀ (P : Ideal R) [P.IsMaximal], Type*)
[∀ (P : Ideal R) [P.IsMaximal], CommRing (Rₚ P)]
[∀ (P : Ideal R) [P.IsMaximal], Algebra R (Rₚ P)]
[∀ (P : Ideal R) [P.IsMaximal], IsLocalization.AtPrime (Rₚ P) P]
lemma Ring.krullDimLE_of_isLocalization_maximal {n : ℕ}
(h : ∀ (P : Ideal R) [P.IsMaximal], Ring.KrullDimLE n (Rₚ P)) :
Ring.KrullDimLE n R := by
simp_rw [Ring.krullDimLE_iff] at h ⊢
nontriviality R
rw [← Ideal.sup_primeHeight_of_maximal_eq_ringKrullDim]
refine (WithBot.coe_le_coe).mpr (iSup₂_le_iff.mpr fun P hP ↦ ?_)
rw [← Ideal.height_eq_primeHeight, ← WithBot.coe_le_coe]
rw [← IsLocalization.AtPrime.ringKrullDim_eq_height P (Rₚ P)]
exact h P
end isLocalization |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/Maximal.lean | import Mathlib.RingTheory.Ideal.Prime
import Mathlib.RingTheory.Ideal.Span
/-!
# Ideals over a ring
This file contains an assortment of definitions and results for `Ideal R`,
the type of (left) ideals over a ring `R`.
Note that over commutative rings, left ideals and two-sided ideals are equivalent.
## Implementation notes
`Ideal R` is implemented using `Submodule R R`, where `•` is interpreted as `*`.
## TODO
Support right ideals, and two-sided ideals over non-commutative rings.
-/
universe u v w
variable {α : Type u} {β : Type v} {F : Type w}
open Set Function
open Pointwise
section Semiring
namespace Ideal
variable [Semiring α] (I : Ideal α) {a b : α}
/-- An ideal is maximal if it is maximal in the collection of proper ideals. -/
class IsMaximal (I : Ideal α) : Prop where
/-- The maximal ideal is a coatom in the ordering on ideals; that is, it is not the entire ring,
and there are no other proper ideals strictly containing it. -/
out : IsCoatom I
theorem isMaximal_def {I : Ideal α} : I.IsMaximal ↔ IsCoatom I :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
theorem IsMaximal.ne_top {I : Ideal α} (h : I.IsMaximal) : I ≠ ⊤ :=
(isMaximal_def.1 h).1
theorem isMaximal_iff {I : Ideal α} :
I.IsMaximal ↔ (1 : α) ∉ I ∧ ∀ (J : Ideal α) (x), I ≤ J → x ∉ I → x ∈ J → (1 : α) ∈ J := by
simp_rw [isMaximal_def, SetLike.isCoatom_iff, Ideal.ne_top_iff_one, ← Ideal.eq_top_iff_one]
theorem IsMaximal.eq_of_le {I J : Ideal α} (hI : I.IsMaximal) (hJ : J ≠ ⊤) (IJ : I ≤ J) : I = J :=
eq_iff_le_not_lt.2 ⟨IJ, fun h => hJ (hI.1.2 _ h)⟩
instance : IsCoatomic (Ideal α) := CompleteLattice.coatomic_of_top_compact isCompactElement_top
theorem IsMaximal.coprime_of_ne {M M' : Ideal α} (hM : M.IsMaximal) (hM' : M'.IsMaximal)
(hne : M ≠ M') : M ⊔ M' = ⊤ := by
contrapose! hne with h
exact hM.eq_of_le hM'.ne_top (le_sup_left.trans_eq (hM'.eq_of_le h le_sup_right).symm)
/-- **Krull's theorem**: if `I` is an ideal that is not the whole ring, then it is included in some
maximal ideal. -/
theorem exists_le_maximal (I : Ideal α) (hI : I ≠ ⊤) : ∃ M : Ideal α, M.IsMaximal ∧ I ≤ M :=
let ⟨m, hm⟩ := (eq_top_or_exists_le_coatom I).resolve_left hI
⟨m, ⟨⟨hm.1⟩, hm.2⟩⟩
variable (α) in
/-- Krull's theorem: a nontrivial ring has a maximal ideal. -/
theorem exists_maximal [Nontrivial α] : ∃ M : Ideal α, M.IsMaximal :=
let ⟨I, ⟨hI, _⟩⟩ := exists_le_maximal (⊥ : Ideal α) bot_ne_top
⟨I, hI⟩
theorem ne_top_iff_exists_maximal {I : Ideal α} : I ≠ ⊤ ↔ ∃ M : Ideal α, M.IsMaximal ∧ I ≤ M := by
refine ⟨exists_le_maximal I, ?_⟩
contrapose!
rintro rfl _ hMmax
rw [top_le_iff]
exact IsMaximal.ne_top hMmax
instance [Nontrivial α] : Nontrivial (Ideal α) := by
rcases@exists_maximal α _ _ with ⟨M, hM, _⟩
exact nontrivial_of_ne M ⊤ hM
/-- If P is not properly contained in any maximal ideal then it is not properly contained
in any proper ideal -/
theorem maximal_of_no_maximal {P : Ideal α}
(hmax : ∀ m : Ideal α, P < m → ¬IsMaximal m) (J : Ideal α) (hPJ : P < J) : J = ⊤ := by
by_contra hnonmax
rcases exists_le_maximal J hnonmax with ⟨M, hM1, hM2⟩
exact hmax M (lt_of_lt_of_le hPJ hM2) hM1
theorem IsMaximal.exists_inv {I : Ideal α} (hI : I.IsMaximal) {x} (hx : x ∉ I) :
∃ y, ∃ i ∈ I, y * x + i = 1 := by
obtain ⟨H₁, H₂⟩ := isMaximal_iff.1 hI
rcases mem_span_insert.1
(H₂ (span (insert x I)) x (Set.Subset.trans (subset_insert _ _) subset_span) hx
(subset_span (mem_insert _ _))) with
⟨y, z, hz, hy⟩
refine ⟨y, z, ?_, hy.symm⟩
rwa [← span_eq I]
theorem sInf_isPrime_of_isChain {s : Set (Ideal α)} (hs : s.Nonempty) (hs' : IsChain (· ≤ ·) s)
(H : ∀ p ∈ s, p.IsPrime) : (sInf s).IsPrime :=
⟨fun e =>
let ⟨x, hx⟩ := hs
(H x hx).ne_top (eq_top_iff.mpr (e.symm.trans_le (sInf_le hx))),
fun e =>
or_iff_not_imp_left.mpr fun hx => by
rw [Ideal.mem_sInf] at hx e ⊢
push_neg at hx
obtain ⟨I, hI, hI'⟩ := hx
intro J hJ
rcases hs'.total hI hJ with h | h
· exact h (((H I hI).mem_or_mem (e hI)).resolve_left hI')
· exact ((H J hJ).mem_or_mem (e hJ)).resolve_left fun x => hI' <| h x⟩
end Ideal
end Semiring
section CommSemiring
variable {a b : α}
-- A separate namespace definition is needed because the variables were historically in a different
-- order.
namespace Ideal
variable [CommSemiring α] (I : Ideal α)
theorem span_singleton_prime {p : α} (hp : p ≠ 0) : IsPrime (span ({p} : Set α)) ↔ Prime p := by
simp [isPrime_iff, Prime, span_singleton_eq_top, hp, mem_span_singleton]
theorem IsMaximal.isPrime {I : Ideal α} (H : I.IsMaximal) : I.IsPrime :=
⟨H.1.1, @fun x y hxy =>
or_iff_not_imp_left.2 fun hx => by
let J : Ideal α := Submodule.span α (insert x ↑I)
have IJ : I ≤ J := Set.Subset.trans (subset_insert _ _) subset_span
have xJ : x ∈ J := Ideal.subset_span (Set.mem_insert x I)
obtain ⟨_, oJ⟩ := isMaximal_iff.1 H
specialize oJ J x IJ hx xJ
rcases Submodule.mem_span_insert.mp oJ with ⟨a, b, h, oe⟩
obtain F : y * 1 = y * (a • x + b) := congr_arg (fun g : α => y * g) oe
rw [← mul_one y, F, mul_add, mul_comm, smul_eq_mul, mul_assoc]
refine Submodule.add_mem I (I.mul_mem_left a hxy) (Submodule.smul_mem I y ?_)
rwa [Submodule.span_eq] at h⟩
-- see Note [lower instance priority]
instance (priority := 100) IsMaximal.isPrime' (I : Ideal α) : ∀ [_H : I.IsMaximal], I.IsPrime :=
@IsMaximal.isPrime _ _ _
theorem exists_disjoint_powers_of_span_eq_top (s : Set α) (hs : span s = ⊤) (I : Ideal α)
(hI : I ≠ ⊤) : ∃ r ∈ s, Disjoint (I : Set α) (Submonoid.powers r) := by
have ⟨M, hM, le⟩ := exists_le_maximal I hI
have := hM.1.1
rw [Ne, eq_top_iff, ← hs, span_le, Set.not_subset] at this
have ⟨a, has, haM⟩ := this
exact ⟨a, has, Set.disjoint_left.mpr fun x hx ⟨n, hn⟩ ↦
haM (hM.isPrime.mem_of_pow_mem _ (le <| hn ▸ hx))⟩
theorem span_singleton_lt_span_singleton [IsDomain α] {x y : α} :
span ({x} : Set α) < span ({y} : Set α) ↔ DvdNotUnit y x := by
rw [lt_iff_le_not_ge, span_singleton_le_span_singleton, span_singleton_le_span_singleton,
dvd_and_not_dvd_iff]
lemma isPrime_of_maximally_disjoint (I : Ideal α)
(S : Submonoid α)
(disjoint : Disjoint (I : Set α) S)
(maximally_disjoint : ∀ (J : Ideal α), I < J → ¬ Disjoint (J : Set α) S) :
I.IsPrime where
ne_top' := by
rintro rfl
have : 1 ∈ (S : Set α) := S.one_mem
simp_all
mem_or_mem' {x y} hxy := by
by_contra! rid
have hx := maximally_disjoint (I ⊔ span {x}) (Submodule.lt_sup_iff_notMem.mpr rid.1)
have hy := maximally_disjoint (I ⊔ span {y}) (Submodule.lt_sup_iff_notMem.mpr rid.2)
simp only [Set.not_disjoint_iff, SetLike.mem_coe, Submodule.mem_sup,
mem_span_singleton] at hx hy
obtain ⟨s₁, ⟨i₁, hi₁, ⟨_, ⟨r₁, rfl⟩, hr₁⟩⟩, hs₁⟩ := hx
obtain ⟨s₂, ⟨i₂, hi₂, ⟨_, ⟨r₂, rfl⟩, hr₂⟩⟩, hs₂⟩ := hy
refine disjoint.ne_of_mem
(I.add_mem (I.mul_mem_left (i₁ + x * r₁) hi₂) <| I.add_mem (I.mul_mem_right (y * r₂) hi₁) <|
I.mul_mem_right (r₁ * r₂) hxy)
(S.mul_mem hs₁ hs₂) ?_
rw [← hr₁, ← hr₂]
ring
theorem exists_le_prime_disjoint (S : Submonoid α) (disjoint : Disjoint (I : Set α) S) :
∃ p : Ideal α, p.IsPrime ∧ I ≤ p ∧ Disjoint (p : Set α) S := by
have ⟨p, hIp, hp⟩ := zorn_le_nonempty₀ {p : Ideal α | Disjoint (p : Set α) S}
(fun c hc hc' x hx ↦ ?_) I disjoint
· exact ⟨p, isPrime_of_maximally_disjoint _ _ hp.1 (fun _ ↦ hp.not_prop_of_gt), hIp, hp.1⟩
cases isEmpty_or_nonempty c
· exact ⟨I, disjoint, fun J hJ ↦ isEmptyElim (⟨J, hJ⟩ : c)⟩
refine ⟨sSup c, Set.disjoint_left.mpr fun x hx ↦ ?_, fun _ ↦ le_sSup⟩
have ⟨p, hp⟩ := (Submodule.mem_iSup_of_directed _ hc'.directed).mp (sSup_eq_iSup' c ▸ hx)
exact Set.disjoint_left.mp (hc p.2) hp
theorem exists_le_prime_notMem_of_isIdempotentElem (a : α) (ha : IsIdempotentElem a) (haI : a ∉ I) :
∃ p : Ideal α, p.IsPrime ∧ I ≤ p ∧ a ∉ p :=
have : Disjoint (I : Set α) (Submonoid.powers a) := Set.disjoint_right.mpr <| by
rw [ha.coe_powers]
rintro _ (rfl | rfl)
exacts [I.ne_top_iff_one.mp (ne_of_mem_of_not_mem' Submodule.mem_top haI).symm, haI]
have ⟨p, h1, h2, h3⟩ := exists_le_prime_disjoint _ _ this
⟨p, h1, h2, Set.disjoint_right.mp h3 (Submonoid.mem_powers a)⟩
@[deprecated (since := "2025-05-24")]
alias exists_le_prime_nmem_of_isIdempotentElem := exists_le_prime_notMem_of_isIdempotentElem
section IsPrincipalIdealRing
variable [IsPrincipalIdealRing α]
theorem isPrime_iff_of_isPrincipalIdealRing {P : Ideal α} (hP : P ≠ ⊥) :
P.IsPrime ↔ ∃ p, Prime p ∧ P = span {p} where
mp h := by
obtain ⟨p, rfl⟩ := Submodule.IsPrincipal.principal P
exact ⟨p, (span_singleton_prime (by simp [·] at hP)).mp h, rfl⟩
mpr := by
rintro ⟨p, hp, rfl⟩
rwa [span_singleton_prime (by simp [hp.ne_zero])]
theorem isPrime_iff_of_isPrincipalIdealRing_of_noZeroDivisors [NoZeroDivisors α] [Nontrivial α]
{P : Ideal α} : P.IsPrime ↔ P = ⊥ ∨ ∃ p, Prime p ∧ P = span {p} := by
rw [or_iff_not_imp_left, ← forall_congr' isPrime_iff_of_isPrincipalIdealRing,
← or_iff_not_imp_left, or_iff_right_of_imp]
rintro rfl; exact bot_prime
end IsPrincipalIdealRing
end Ideal
end CommSemiring
section DivisionSemiring
variable {K : Type u} [DivisionSemiring K] (I : Ideal K)
namespace Ideal
theorem bot_isMaximal : IsMaximal (⊥ : Ideal K) :=
⟨⟨fun h => absurd ((eq_top_iff_one (⊤ : Ideal K)).mp rfl) (by rw [← h]; simp), fun I hI =>
or_iff_not_imp_left.mp (eq_bot_or_top I) (ne_of_gt hI)⟩⟩
end Ideal
end DivisionSemiring |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/IsPrincipal.lean | import Mathlib.RingTheory.PrincipalIdealDomain
/-!
# Principal Ideals
This file deals with the set of principal ideals of a `CommRing R`.
## Main definitions and results
* `Ideal.isPrincipalSubmonoid`: the submonoid of `Ideal R` formed by the principal ideals of `R`.
* `Ideal.isPrincipalNonZeroDivisorSubmonoid`: the submonoid of `(Ideal R)⁰` formed by the
non-zero-divisors principal ideals of `R`.
* `Ideal.associatesMulEquivIsPrincipal`: the `MulEquiv` between the monoid of `Associates R` and
the submonoid of principal ideals of `R`.
* `Ideal.associatesNonZeroDivisorsMulEquivIsPrincipal`: the `MulEquiv` between the monoid of
`Associates R⁰` and the submonoid of non-zero-divisors principal ideals of `R`.
-/
variable {R : Type*} [CommRing R]
namespace Ideal
open Submodule Associates
open scoped nonZeroDivisors
variable (R) in
/-- The principal ideals of `R` form a submonoid of `Ideal R`. -/
def isPrincipalSubmonoid : Submonoid (Ideal R) where
carrier := {I | IsPrincipal I}
mul_mem' := by
rintro _ _ ⟨x, rfl⟩ ⟨y, rfl⟩
exact ⟨x * y, span_singleton_mul_span_singleton x y⟩
one_mem' := ⟨1, one_eq_span⟩
theorem mem_isPrincipalSubmonoid_iff {I : Ideal R} :
I ∈ isPrincipalSubmonoid R ↔ IsPrincipal I := Iff.rfl
theorem span_singleton_mem_isPrincipalSubmonoid (a : R) :
span {a} ∈ isPrincipalSubmonoid R := mem_isPrincipalSubmonoid_iff.mpr ⟨a, rfl⟩
variable (R) in
/-- The non-zero-divisors principal ideals of `R` form a submonoid of `(Ideal R)⁰`. -/
def isPrincipalNonZeroDivisorsSubmonoid : Submonoid (Ideal R)⁰ where
carrier := {I | IsPrincipal I.val}
mul_mem' := by
rintro ⟨_, _⟩ ⟨_, _⟩ ⟨x, rfl⟩ ⟨y, rfl⟩
exact ⟨x * y, by
simp_rw [Submonoid.mk_mul_mk, submodule_span_eq, span_singleton_mul_span_singleton]⟩
one_mem' := ⟨1, by simp⟩
variable [IsDomain R]
variable (R) in
/-- The equivalence between `Associates R` and the principal ideals of `R` defined by sending the
class of `x` to the principal ideal generated by `x`. -/
noncomputable def associatesEquivIsPrincipal :
Associates R ≃ {I : Ideal R // IsPrincipal I} where
toFun := _root_.Quotient.lift (fun x ↦ ⟨span {x}, x, rfl⟩)
(fun _ _ _ ↦ by simpa [span_singleton_eq_span_singleton])
invFun I := .mk I.2.generator
left_inv := Quotient.ind fun _ ↦ by simpa using
Ideal.span_singleton_eq_span_singleton.mp (@Ideal.span_singleton_generator _ _ _ ⟨_, rfl⟩)
right_inv I := by simp only [_root_.Quotient.lift_mk, span_singleton_generator, Subtype.coe_eta]
@[simp]
theorem associatesEquivIsPrincipal_apply (x : R) :
associatesEquivIsPrincipal R (.mk x) = span {x} := rfl
@[simp]
theorem associatesEquivIsPrincipal_symm_apply {I : Ideal R} (hI : IsPrincipal I) :
(associatesEquivIsPrincipal R).symm ⟨I, hI⟩ = .mk hI.generator := rfl
theorem associatesEquivIsPrincipal_mul (x y : Associates R) :
(associatesEquivIsPrincipal R (x * y) : Ideal R) =
(associatesEquivIsPrincipal R x) * (associatesEquivIsPrincipal R y) := by
rw [← quot_out x, ← quot_out y]
simp_rw [mk_mul_mk, associatesEquivIsPrincipal_apply, span_singleton_mul_span_singleton]
@[simp]
theorem associatesEquivIsPrincipal_map_zero :
(associatesEquivIsPrincipal R 0 : Ideal R) = 0 := by
rw [← mk_zero, associatesEquivIsPrincipal_apply, Submodule.zero_eq_bot, span_singleton_eq_bot]
@[simp]
theorem associatesEquivIsPrincipal_map_one :
(associatesEquivIsPrincipal R 1 : Ideal R) = 1 := by
rw [one_eq_mk_one, associatesEquivIsPrincipal_apply, span_singleton_one, one_eq_top]
variable (R) in
/-- The `MulEquiv` version of `Ideal.associatesEquivIsPrincipal`. -/
noncomputable def associatesMulEquivIsPrincipal :
Associates R ≃* isPrincipalSubmonoid R where
__ := associatesEquivIsPrincipal R
map_mul' _ _ := by
rw [Subtype.ext_iff]
-- This `erw` is needed to see through `{I // IsPrincipal I} = ↑(isPrincipalSubmonoid R)`:
-- we can redefine `associatesEquivIsPrincipal` to get rid of this `erw` but then we'd need
-- to add one in `associatesNonZeroDivisorsEquivIsPrincipal`.
erw [associatesEquivIsPrincipal_mul]
rfl
variable (R) in
/-- A version of `Ideal.associatesEquivIsPrincipal` for non-zero-divisors generators. -/
noncomputable def associatesNonZeroDivisorsEquivIsPrincipal :
Associates R⁰ ≃ {I : (Ideal R)⁰ // IsPrincipal (I : Ideal R)} :=
calc Associates R⁰ ≃ (Associates R)⁰ := associatesNonZeroDivisorsEquiv.toEquiv.symm
_ ≃ {I : {I : Ideal R // IsPrincipal I} // I.1 ∈ (Ideal R)⁰} :=
Equiv.subtypeEquiv (associatesEquivIsPrincipal R)
(fun x ↦ by rw [← quot_out x, mk_mem_nonZeroDivisors_associates,
associatesEquivIsPrincipal_apply, span_singleton_nonZeroDivisors])
_ ≃ {I : Ideal R // IsPrincipal I ∧ I ∈ (Ideal R)⁰} :=
Equiv.subtypeSubtypeEquivSubtypeInter (fun I ↦ IsPrincipal I) (fun I ↦ I ∈ (Ideal R)⁰)
_ ≃ {I : Ideal R // I ∈ (Ideal R)⁰ ∧ IsPrincipal I} := Equiv.setCongr (by simp_rw [and_comm])
_ ≃ {I : (Ideal R)⁰ // IsPrincipal I.1} := (Equiv.subtypeSubtypeEquivSubtypeInter _ _).symm
@[simp]
theorem associatesNonZeroDivisorsEquivIsPrincipal_apply (x : R⁰) :
associatesNonZeroDivisorsEquivIsPrincipal R (.mk x) = Ideal.span {(x : R)} := rfl
theorem associatesNonZeroDivisorsEquivIsPrincipal_coe (x : Associates R⁰) :
(associatesNonZeroDivisorsEquivIsPrincipal R x : Ideal R) =
(associatesEquivIsPrincipal R (associatesNonZeroDivisorsEquiv.symm x)) := rfl
theorem associatesNonZeroDivisorsEquivIsPrincipal_mul (x y : Associates R⁰) :
(associatesNonZeroDivisorsEquivIsPrincipal R (x * y) : Ideal R) =
(associatesNonZeroDivisorsEquivIsPrincipal R x) *
(associatesNonZeroDivisorsEquivIsPrincipal R y) := by
simp_rw [associatesNonZeroDivisorsEquivIsPrincipal_coe, map_mul, Submonoid.coe_mul,
associatesEquivIsPrincipal_mul]
@[simp]
theorem associatesNonZeroDivisorsEquivIsPrincipal_map_one :
(associatesNonZeroDivisorsEquivIsPrincipal R 1 : Ideal R) = 1 := by
rw [associatesNonZeroDivisorsEquivIsPrincipal_coe, map_one, OneMemClass.coe_one,
associatesEquivIsPrincipal_map_one]
variable (R) in
/-- The `MulEquiv` version of `Ideal.associatesNonZeroDivisorsEquivIsPrincipal`. -/
noncomputable def associatesNonZeroDivisorsMulEquivIsPrincipal :
Associates R⁰ ≃* (isPrincipalNonZeroDivisorsSubmonoid R) where
__ := associatesNonZeroDivisorsEquivIsPrincipal R
map_mul' _ _ := by
rw [Subtype.ext_iff, Subtype.ext_iff, Equiv.toFun_as_coe,
associatesNonZeroDivisorsEquivIsPrincipal_mul]
rfl
/-- A nonzero principal ideal in an integral domain `R` is isomorphic to `R` as a module.
The isomorphism we choose here sends `1` to the generator chosen by `Ideal.generator`. -/
noncomputable def isoBaseOfIsPrincipal {I : Ideal R}
[hprinc : I.IsPrincipal] (hI : I ≠ ⊥) : R ≃ₗ[R] I :=
letI x := IsPrincipal.generator I
have hx : x ≠ 0 := by rwa [Ne, ← IsPrincipal.eq_bot_iff_generator_eq_zero]
(LinearEquiv.toSpanNonzeroSingleton R R x hx).trans
(LinearEquiv.ofEq (Submodule.span R {x}) I (IsPrincipal.span_singleton_generator I))
@[simp]
theorem isoBaseOfIsPrincipal_apply {I : Ideal R} [hprinc : I.IsPrincipal] (hI : I ≠ ⊥) (x : R) :
(Ideal.isoBaseOfIsPrincipal hI) x = x * IsPrincipal.generator I :=
rfl
theorem subtype_isoBaseOfIsPrincipal_eq_mul {I : Ideal R}
[hprinc : I.IsPrincipal] (h : I ≠ ⊥) :
Submodule.subtype I ∘ₗ ↑(Ideal.isoBaseOfIsPrincipal h) =
LinearMap.mul R R (IsPrincipal.generator I) := by
ext
simp
end Ideal |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/MinimalPrime/Basic.lean | import Mathlib.RingTheory.Ideal.IsPrimary
import Mathlib.Order.Minimal
/-!
# Minimal primes
We provide various results concerning the minimal primes above an ideal.
## Main results
- `Ideal.minimalPrimes`: `I.minimalPrimes` is the set of ideals that are minimal primes over `I`.
- `minimalPrimes`: `minimalPrimes R` is the set of minimal primes of `R`.
- `Ideal.exists_minimalPrimes_le`: Every prime ideal over `I` contains a minimal prime over `I`.
- `Ideal.radical_minimalPrimes`: The minimal primes over `I.radical` are precisely
the minimal primes over `I`.
- `Ideal.sInf_minimalPrimes`: The intersection of minimal primes over `I` is `I.radical`.
Further results that need the theory of localizations can be found in
`RingTheory/Ideal/Minimal/Localization.lean`.
-/
assert_not_exists Localization -- See `RingTheory/Ideal/Minimal/Localization.lean`
section
variable {R S : Type*} [CommSemiring R] [CommSemiring S] (I J : Ideal R)
/-- `I.minimalPrimes` is the set of ideals that are minimal primes over `I`. -/
protected def Ideal.minimalPrimes : Set (Ideal R) :=
{p | Minimal (fun q ↦ q.IsPrime ∧ I ≤ q) p}
variable (R) in
/-- `minimalPrimes R` is the set of minimal primes of `R`.
This is defined as `Ideal.minimalPrimes ⊥`. -/
def minimalPrimes : Set (Ideal R) :=
Ideal.minimalPrimes ⊥
lemma minimalPrimes_eq_minimals : minimalPrimes R = {x | Minimal Ideal.IsPrime x} :=
congr_arg Minimal (by simp)
variable {I J}
theorem Ideal.minimalPrimes_isPrime {p : Ideal R} (h : p ∈ I.minimalPrimes) : p.IsPrime :=
h.1.1
theorem Ideal.exists_minimalPrimes_le [J.IsPrime] (e : I ≤ J) : ∃ p ∈ I.minimalPrimes, p ≤ J := by
set S := { p : (Ideal R)ᵒᵈ | Ideal.IsPrime p ∧ I ≤ OrderDual.ofDual p }
suffices h : ∃ m, OrderDual.toDual J ≤ m ∧ Maximal (· ∈ S) m by
obtain ⟨p, hJp, hp⟩ := h
exact ⟨p, ⟨hp.prop, fun q hq hle ↦ hp.le_of_ge hq hle⟩, hJp⟩
apply zorn_le_nonempty₀
swap
· refine ⟨show J.IsPrime by infer_instance, e⟩
rintro (c : Set (Ideal R)) hc hc' J' hJ'
refine
⟨OrderDual.toDual (sInf c),
⟨Ideal.sInf_isPrime_of_isChain ⟨J', hJ'⟩ hc'.symm fun x hx => (hc hx).1, ?_⟩, ?_⟩
· rw [OrderDual.ofDual_toDual, le_sInf_iff]
exact fun _ hx => (hc hx).2
· rintro z hz
rw [OrderDual.le_toDual]
exact sInf_le hz
theorem Ideal.nonempty_minimalPrimes (h : I ≠ ⊤) : Nonempty I.minimalPrimes := by
obtain ⟨m, hm, hle⟩ := Ideal.exists_le_maximal I h
obtain ⟨p, hp, -⟩ := Ideal.exists_minimalPrimes_le hle
exact ⟨p, hp⟩
theorem Ideal.eq_bot_of_minimalPrimes_eq_empty (h : I.minimalPrimes = ∅) : I = ⊤ := by
by_contra hI
obtain ⟨p, hp⟩ := Ideal.nonempty_minimalPrimes hI
exact Set.notMem_empty p (h ▸ hp)
@[simp]
theorem Ideal.radical_minimalPrimes : I.radical.minimalPrimes = I.minimalPrimes := by
rw [Ideal.minimalPrimes, Ideal.minimalPrimes]
ext p
refine ⟨?_, ?_⟩ <;> rintro ⟨⟨a, ha⟩, b⟩
· refine ⟨⟨a, a.radical_le_iff.1 ha⟩, ?_⟩
simp only [and_imp] at *
exact fun _ h2 h3 h4 => b h2 (h2.radical_le_iff.2 h3) h4
· refine ⟨⟨a, a.radical_le_iff.2 ha⟩, ?_⟩
simp only [and_imp] at *
exact fun _ h2 h3 h4 => b h2 (h2.radical_le_iff.1 h3) h4
@[simp]
theorem Ideal.sInf_minimalPrimes : sInf I.minimalPrimes = I.radical := by
rw [I.radical_eq_sInf]
apply le_antisymm
· intro x hx
rw [Ideal.mem_sInf] at hx ⊢
rintro J ⟨e, hJ⟩
obtain ⟨p, hp, hp'⟩ := Ideal.exists_minimalPrimes_le e
exact hp' (hx hp)
· apply sInf_le_sInf _
intro I hI
exact hI.1.symm
end
section
variable {R S : Type*} [CommRing R] [CommRing S] {I J : Ideal R}
theorem Ideal.minimalPrimes_eq_subsingleton (hI : I.IsPrimary) : I.minimalPrimes = {I.radical} := by
ext J
constructor
· exact fun H =>
let e := H.1.1.radical_le_iff.mpr H.1.2
(H.2 ⟨Ideal.isPrime_radical hI, Ideal.le_radical⟩ e).antisymm e
· rintro (rfl : J = I.radical)
exact ⟨⟨Ideal.isPrime_radical hI, Ideal.le_radical⟩, fun _ H _ => H.1.radical_le_iff.mpr H.2⟩
theorem Ideal.minimalPrimes_eq_subsingleton_self [I.IsPrime] : I.minimalPrimes = {I} := by
ext J
constructor
· exact fun H => (H.2 ⟨inferInstance, rfl.le⟩ H.1.2).antisymm H.1.2
· rintro (rfl : J = I)
exact ⟨⟨inferInstance, rfl.le⟩, fun _ h _ => h.2⟩
variable (R) in
theorem IsDomain.minimalPrimes_eq_singleton_bot [IsDomain R] :
minimalPrimes R = {⊥} :=
have := Ideal.bot_prime (α := R)
Ideal.minimalPrimes_eq_subsingleton_self
end
section
variable {R : Type*} [CommSemiring R]
theorem Ideal.minimalPrimes_top : (⊤ : Ideal R).minimalPrimes = ∅ := by
ext p
simp only [Set.notMem_empty, iff_false]
intro h
exact h.1.1.ne_top (top_le_iff.mp h.1.2)
theorem Ideal.minimalPrimes_eq_empty_iff (I : Ideal R) :
I.minimalPrimes = ∅ ↔ I = ⊤ := by
constructor
· intro e
by_contra h
have ⟨M, hM, hM'⟩ := Ideal.exists_le_maximal I h
have ⟨p, hp⟩ := Ideal.exists_minimalPrimes_le hM'
rw [e] at hp
apply Set.notMem_empty _ hp.1
· rintro rfl
exact Ideal.minimalPrimes_top
end |
.lake/packages/mathlib/Mathlib/RingTheory/Ideal/MinimalPrime/Localization.lean | import Mathlib.RingTheory.Ideal.MinimalPrime.Basic
import Mathlib.RingTheory.Localization.AtPrime.Basic
/-!
# Minimal primes and localization
We provide various results concerning the minimal primes above an ideal that require the theory
of localizations.
## Main results
- `Ideal.exists_minimalPrimes_comap_eq` If `p` is a minimal prime over `f ⁻¹ I`, then it is the
preimage of some minimal prime over `I`.
- `Ideal.minimalPrimes_eq_comap`: The minimal primes over `I` are precisely the preimages of
minimal primes of `R ⧸ I`.
- `IsLocalization.minimalPrimes_comap`: If `A` is a localization of `R` with respect to the
submonoid `S`, `J` is an ideal of `A`, then the minimal primes over the preimage of `J`
(under `R →+* A`) are exactly the preimages of the minimal primes over `J`.
- `IsLocalization.minimalPrimes_map`: If `A` is a localization of `R` with respect to the
submonoid `S`, `J` is an ideal of `R`, then the minimal primes over the span of the image of `J`
(under `R →+* A`) are exactly the ideals of `A` such that the preimage of which is a minimal prime
over `J`.
- `Localization.AtPrime.prime_unique_of_minimal`: When localizing at a minimal prime ideal `I`,
the resulting ring only has a single prime ideal.
-/
section
variable {R S : Type*} [CommSemiring R] [CommSemiring S] {I J : Ideal R}
theorem Ideal.iUnion_minimalPrimes :
⋃ p ∈ I.minimalPrimes, p = { x | ∃ y ∉ I.radical, x * y ∈ I.radical } := by
classical
ext x
simp only [Set.mem_iUnion, SetLike.mem_coe, exists_prop, Set.mem_setOf_eq]
constructor
· rintro ⟨p, ⟨⟨hp₁, hp₂⟩, hp₃⟩, hxp⟩
have : p.map (algebraMap R (Localization.AtPrime p)) ≤ (I.map (algebraMap _ _)).radical := by
rw [Ideal.radical_eq_sInf, le_sInf_iff]
rintro q ⟨hq', hq⟩
obtain ⟨h₁, h₂⟩ := ((IsLocalization.AtPrime.orderIsoOfPrime _ p) ⟨q, hq⟩).2
rw [Ideal.map_le_iff_le_comap] at hq' ⊢
exact hp₃ ⟨h₁, hq'⟩ h₂
obtain ⟨n, hn⟩ := this (Ideal.mem_map_of_mem _ hxp)
rw [IsLocalization.mem_map_algebraMap_iff (M := p.primeCompl)] at hn
obtain ⟨⟨a, b⟩, hn⟩ := hn
rw [← map_pow, ← map_mul, IsLocalization.eq_iff_exists p.primeCompl] at hn
obtain ⟨t, ht⟩ := hn
refine ⟨t * b, fun h ↦ (t * b).2 (hp₁.radical_le_iff.mpr hp₂ h), n + 1, ?_⟩
simp only at ht
have : (x * (t.1 * b.1)) ^ (n + 1) = (t.1 ^ n * b.1 ^ n * x * t.1) * a := by
rw [mul_assoc, ← ht]; ring
rw [this]
exact I.mul_mem_left _ a.2
· rintro ⟨y, hy, hx⟩
obtain ⟨p, hp, hyp⟩ : ∃ p ∈ I.minimalPrimes, y ∉ p := by
simpa [← Ideal.sInf_minimalPrimes] using hy
refine ⟨p, hp, (hp.1.1.mem_or_mem ?_).resolve_right hyp⟩
exact hp.1.1.radical_le_iff.mpr hp.1.2 hx
theorem Ideal.exists_mul_mem_of_mem_minimalPrimes
{p : Ideal R} (hp : p ∈ I.minimalPrimes) {x : R} (hx : x ∈ p) :
∃ y ∉ I, x * y ∈ I := by
classical
obtain ⟨y, hy, n, hx⟩ := Ideal.iUnion_minimalPrimes.subset (Set.mem_biUnion hp hx)
have H : ∃ m, x ^ m * y ^ n ∈ I := ⟨n, mul_pow x y n ▸ hx⟩
have : Nat.find H ≠ 0 :=
fun h ↦ hy ⟨n, by simpa only [h, pow_zero, one_mul] using Nat.find_spec H⟩
refine ⟨x ^ (Nat.find H - 1) * y ^ n, Nat.find_min H (Nat.sub_one_lt this), ?_⟩
rw [← mul_assoc, ← pow_succ', tsub_add_cancel_of_le (Nat.one_le_iff_ne_zero.mpr this)]
exact Nat.find_spec H
theorem IsSMulRegular.notMem_of_mem_minimalPrimes
{M : Type*} [AddCommMonoid M] [Module R M] {x : R} (reg : IsSMulRegular M x)
{p : Ideal R} (hp : p ∈ (Module.annihilator R M).minimalPrimes) : x ∉ p := by
intro hx
rcases Ideal.exists_mul_mem_of_mem_minimalPrimes hp hx with ⟨y, hy, hxy⟩
rcases not_forall.mp (Module.mem_annihilator.not.mp hy) with ⟨m, hm⟩
exact hm (reg.right_eq_zero_of_smul ((smul_smul x y m).trans (Module.mem_annihilator.mp hxy m)))
/-- Minimal primes are contained in zero divisors. -/
lemma Ideal.disjoint_nonZeroDivisors_of_mem_minimalPrimes {p : Ideal R} (hp : p ∈ minimalPrimes R) :
Disjoint (p : Set R) (nonZeroDivisors R) := by
simp_rw [Set.disjoint_left, SetLike.mem_coe, mem_nonZeroDivisors_iff_right, not_forall,
exists_prop, @and_comm (_ * _ = _), ← mul_comm]
exact fun _ ↦ Ideal.exists_mul_mem_of_mem_minimalPrimes hp
theorem Ideal.exists_comap_eq_of_mem_minimalPrimes {I : Ideal S} (f : R →+* S) (p)
(H : p ∈ (I.comap f).minimalPrimes) : ∃ p' : Ideal S, p'.IsPrime ∧ I ≤ p' ∧ p'.comap f = p :=
have := H.1.1
have ⟨p', hIp', hp', le⟩ := exists_ideal_comap_le_prime p I H.1.2
⟨p', hp', hIp', le.antisymm (H.2 ⟨inferInstance, comap_mono hIp'⟩ le)⟩
@[stacks 00FK] theorem Ideal.exists_comap_eq_of_mem_minimalPrimes_of_injective {f : R →+* S}
(hf : Function.Injective f) (p) (H : p ∈ minimalPrimes R) :
∃ p' : Ideal S, p'.IsPrime ∧ p'.comap f = p :=
have ⟨p', hp', _, eq⟩ := exists_comap_eq_of_mem_minimalPrimes f (I := ⊥) p <| by
rwa [comap_bot_of_injective f hf]
⟨p', hp', eq⟩
theorem Ideal.exists_minimalPrimes_comap_eq {I : Ideal S} (f : R →+* S) (p)
(H : p ∈ (I.comap f).minimalPrimes) : ∃ p' ∈ I.minimalPrimes, Ideal.comap f p' = p := by
obtain ⟨p', h₁, h₂, h₃⟩ := Ideal.exists_comap_eq_of_mem_minimalPrimes f p H
obtain ⟨q, hq, hq'⟩ := Ideal.exists_minimalPrimes_le h₂
refine ⟨q, hq, Eq.symm ?_⟩
have := hq.1.1
have := (Ideal.comap_mono hq').trans_eq h₃
exact (H.2 ⟨inferInstance, Ideal.comap_mono hq.1.2⟩ this).antisymm this
theorem Ideal.minimalPrimes_comap_subset (f : R →+* S) (J : Ideal S) :
(J.comap f).minimalPrimes ⊆ Ideal.comap f '' J.minimalPrimes :=
fun p hp ↦ Ideal.exists_minimalPrimes_comap_eq f p hp
end
section
variable {R S : Type*} [CommRing R] [CommRing S] {I J : Ideal R}
theorem Ideal.minimal_primes_comap_of_surjective {f : R →+* S} (hf : Function.Surjective f)
{I J : Ideal S} (h : J ∈ I.minimalPrimes) : J.comap f ∈ (I.comap f).minimalPrimes := by
have := h.1.1
refine ⟨⟨inferInstance, Ideal.comap_mono h.1.2⟩, ?_⟩
rintro K ⟨hK, e₁⟩ e₂
have : RingHom.ker f ≤ K := (Ideal.comap_mono bot_le).trans e₁
rw [← sup_eq_left.mpr this, RingHom.ker_eq_comap_bot, ← Ideal.comap_map_of_surjective f hf]
apply Ideal.comap_mono _
apply h.2 _ _
· exact ⟨Ideal.map_isPrime_of_surjective hf this, Ideal.le_map_of_comap_le_of_surjective f hf e₁⟩
· exact Ideal.map_le_of_le_comap e₂
theorem Ideal.comap_minimalPrimes_eq_of_surjective {f : R →+* S} (hf : Function.Surjective f)
(I : Ideal S) : (I.comap f).minimalPrimes = Ideal.comap f '' I.minimalPrimes := by
ext J
constructor
· intro H
obtain ⟨p, h, rfl⟩ := Ideal.exists_minimalPrimes_comap_eq f J H
exact ⟨p, h, rfl⟩
· rintro ⟨J, hJ, rfl⟩
exact Ideal.minimal_primes_comap_of_surjective hf hJ
lemma Ideal.minimalPrimes_map_of_surjective {S : Type*} [CommRing S] {f : R →+* S}
(hf : Function.Surjective f) (I : Ideal R) :
(I.map f).minimalPrimes = Ideal.map f '' (I ⊔ (RingHom.ker f)).minimalPrimes := by
apply Set.image_injective.mpr (Ideal.comap_injective_of_surjective f hf)
rw [← Ideal.comap_minimalPrimes_eq_of_surjective hf, ← Set.image_comp,
Ideal.comap_map_of_surjective f hf, Set.image_congr, Set.image_id, RingHom.ker]
intro x hx
exact (Ideal.comap_map_of_surjective f hf _).trans (sup_eq_left.mpr <| le_sup_right.trans hx.1.2)
theorem Ideal.minimalPrimes_eq_comap :
I.minimalPrimes = Ideal.comap (Ideal.Quotient.mk I) '' minimalPrimes (R ⧸ I) := by
rw [minimalPrimes, ← Ideal.comap_minimalPrimes_eq_of_surjective Ideal.Quotient.mk_surjective,
← RingHom.ker_eq_comap_bot, Ideal.mk_ker]
end
section
variable {R : Type*} [CommSemiring R] (S : Submonoid R) (A : Type*) [CommSemiring A] [Algebra R A]
theorem IsLocalization.minimalPrimes_map [IsLocalization S A] (J : Ideal R) :
(J.map (algebraMap R A)).minimalPrimes = Ideal.comap (algebraMap R A) ⁻¹' J.minimalPrimes := by
ext p
constructor
· intro hp
haveI := hp.1.1
refine ⟨⟨Ideal.IsPrime.comap _, Ideal.map_le_iff_le_comap.mp hp.1.2⟩, ?_⟩
rintro I hI e
have hI' : Disjoint (S : Set R) I := Set.disjoint_of_subset_right e
((IsLocalization.isPrime_iff_isPrime_disjoint S A _).mp hp.1.1).2
refine (Ideal.comap_mono <|
hp.2 ⟨?_, Ideal.map_mono hI.2⟩ (Ideal.map_le_iff_le_comap.mpr e)).trans_eq ?_
· exact IsLocalization.isPrime_of_isPrime_disjoint S A I hI.1 hI'
· exact IsLocalization.comap_map_of_isPrime_disjoint S A _ hI.1 hI'
· intro hp
refine ⟨⟨?_, Ideal.map_le_iff_le_comap.mpr hp.1.2⟩, ?_⟩
· rw [IsLocalization.isPrime_iff_isPrime_disjoint S A, IsLocalization.disjoint_comap_iff S]
refine ⟨hp.1.1, ?_⟩
rintro rfl
exact hp.1.1.ne_top rfl
· intro I hI e
rw [← IsLocalization.map_comap S A I, ← IsLocalization.map_comap S A p]
haveI := hI.1
exact Ideal.map_mono (hp.2 ⟨Ideal.IsPrime.comap _, Ideal.map_le_iff_le_comap.mp hI.2⟩
(Ideal.comap_mono e))
theorem IsLocalization.minimalPrimes_comap [IsLocalization S A] (J : Ideal A) :
(J.comap (algebraMap R A)).minimalPrimes = Ideal.comap (algebraMap R A) '' J.minimalPrimes := by
conv_rhs => rw [← map_comap S A J, minimalPrimes_map S]
refine (Set.image_preimage_eq_iff.mpr ?_).symm
exact subset_trans (Ideal.minimalPrimes_comap_subset (algebraMap R A) J) (by simp)
end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.