Skip to content

Commit 546cfa0

Browse files
ericrbgjjdishere
andcommitted
refactor: generalise IsLocalRingHom to monoids (#6045)
This lets `IsLocalRingHom` take two monoids instead of rings. Furthermore, it moves lemmas to be available a bit earlier where they are relevant to other theories, and tries to adapt those theories to use them a bit better. Co-authored-by: jjdishere <emailboxofjjd@163.com> Co-authored-by: Jiang Jiedong <107380768+jjdishere@users.noreply.github.com> Co-authored-by: Eric Rodriguez <37984851+ericrbg@users.noreply.github.com>
1 parent 71f45a5 commit 546cfa0

File tree

32 files changed

+185
-96
lines changed

32 files changed

+185
-96
lines changed

Mathlib.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3968,7 +3968,6 @@ import Mathlib.RingTheory.LocalRing.Module
39683968
import Mathlib.RingTheory.LocalRing.ResidueField.Basic
39693969
import Mathlib.RingTheory.LocalRing.ResidueField.Defs
39703970
import Mathlib.RingTheory.LocalRing.RingHom.Basic
3971-
import Mathlib.RingTheory.LocalRing.RingHom.Defs
39723971
import Mathlib.RingTheory.Localization.Algebra
39733972
import Mathlib.RingTheory.Localization.AsSubring
39743973
import Mathlib.RingTheory.Localization.AtPrime

Mathlib/Algebra/Associated/Basic.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ theorem Irreducible.dvd_comm [Monoid M] {p q : M} (hp : Irreducible p) (hq : Irr
248248
p ∣ q ↔ q ∣ p :=
249249
⟨hp.dvd_symm hq, hq.dvd_symm hp⟩
250250

251+
theorem Irreducible.of_map {F : Type*} [Monoid M] [Monoid N] [FunLike F M N] [MonoidHomClass F M N]
252+
{f : F} [IsLocalRingHom f] {x} (hfx : Irreducible (f x)) : Irreducible x :=
253+
fun hu ↦ hfx.not_unit <| hu.map f,
254+
by rintro p q rfl
255+
exact (hfx.isUnit_or_isUnit <| map_mul f p q).imp (.of_map f _) (.of_map f _)⟩
256+
251257
section
252258

253259
variable [Monoid M]

Mathlib/Algebra/Category/Ring/Instances.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ instance Localization.epi' {R : CommRingCat} (M : Submonoid R) :
3838

3939
instance CommRingCat.isLocalRingHom_comp {R S T : CommRingCat} (f : R ⟶ S) (g : S ⟶ T)
4040
[IsLocalRingHom g] [IsLocalRingHom f] : IsLocalRingHom (f ≫ g) :=
41-
_root_.isLocalRingHom_comp _ _
41+
RingHom.isLocalRingHom_comp _ _
4242

4343
theorem isLocalRingHom_of_iso {R S : CommRingCat} (f : R ≅ S) : IsLocalRingHom f.hom :=
4444
{ map_nonunit := fun a ha => by

Mathlib/Algebra/Group/Units/Equiv.lean

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,10 @@ def MulEquiv.inv (G : Type*) [DivisionCommMonoid G] : G ≃* G :=
192192
theorem MulEquiv.inv_symm (G : Type*) [DivisionCommMonoid G] :
193193
(MulEquiv.inv G).symm = MulEquiv.inv G :=
194194
rfl
195-
-- Porting note: no `add_equiv.neg_symm` in `mathlib3`
196195

197-
@[to_additive]
198-
protected
199-
theorem MulEquiv.map_isUnit_iff {M N} [Monoid M] [Monoid N] [EquivLike F M N] [MonoidHomClass F M N]
200-
(f : F) {m : M} : IsUnit (f m) ↔ IsUnit m :=
201-
isUnit_map_of_leftInverse (MonoidHom.inverse (f : M →* N) (EquivLike.inv f)
202-
(EquivLike.left_inv f) <| EquivLike.right_inv f) (EquivLike.left_inv f)
196+
instance isLocalRingHom_equiv [Monoid M] [Monoid N] [EquivLike F M N]
197+
[MulEquivClass F M N] (f : F) : IsLocalRingHom f where
198+
map_nonunit a ha := by
199+
convert ha.map (f : M ≃* N).symm
200+
rw [MulEquiv.eq_symm_apply]
201+
rfl -- note to reviewers: ugly `rfl`

Mathlib/Algebra/Group/Units/Hom.lean

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ also contains unrelated results about `Units` that depend on `MonoidHom`.
1717
* `Units.map`: Turn a homomorphism from `α` to `β` monoids into a homomorphism from `αˣ` to `βˣ`.
1818
* `MonoidHom.toHomUnits`: Turn a homomorphism from a group `α` to `β` into a homomorphism from
1919
`α` to `βˣ`.
20+
* `IsLocalRingHom`: A predicate on monoid maps, requiring that it maps nonunits
21+
to nonunits. For local rings, this means that the image of the unique maximal ideal is again
22+
contained in the unique maximal ideal. This is developed earlier, and in the generality of
23+
monoids, as it allows its use in non-local-ring related contexts, but it does have the
24+
strange consequence that it does not require local rings, or even rings.
25+
26+
## TODO
27+
28+
The results that don't mention homomorphisms should be proved (earlier?) in a different file and be
29+
used to golf the basic `Group` lemmas.
30+
31+
Add a `@[to_additive]` version of `IsLocalRingHom`.
2032
-/
2133

2234
assert_not_exists MonoidWithZero
@@ -167,6 +179,7 @@ theorem of_leftInverse [MonoidHomClass G N M] {f : F} {x : M} (g : G)
167179
(hfg : Function.LeftInverse g f) (h : IsUnit (f x)) : IsUnit x := by
168180
simpa only [hfg x] using h.map g
169181

182+
/-- Prefer `IsLocalRingHom.of_leftInverse`, but we can't get rid of this because of `ToAdditive`. -/
170183
@[to_additive]
171184
theorem _root_.isUnit_map_of_leftInverse [MonoidHomClass F M N] [MonoidHomClass G N M]
172185
{f : F} {x : M} (g : G) (hfg : Function.LeftInverse g f) :
@@ -194,3 +207,49 @@ theorem liftRight_inv_mul (f : M →* N) (h : ∀ x, IsUnit (f x)) (x) :
194207

195208
end Monoid
196209
end IsUnit
210+
211+
section IsLocalRingHom
212+
213+
variable {G R S T F : Type*}
214+
215+
variable [Monoid R] [Monoid S] [Monoid T] [FunLike F R S]
216+
217+
/-- A local ring homomorphism is a map `f` between monoids such that `a` in the domain
218+
is a unit if `f a` is a unit for any `a`. See `LocalRing.local_hom_TFAE` for other equivalent
219+
definitions in the local ring case - from where this concept originates, but it is useful in
220+
other contexts, so we allow this generalisation in mathlib. -/
221+
class IsLocalRingHom (f : F) : Prop where
222+
/-- A local ring homomorphism `f : R ⟶ S` will send nonunits of `R` to nonunits of `S`. -/
223+
map_nonunit : ∀ a, IsUnit (f a) → IsUnit a
224+
225+
@[simp]
226+
theorem IsUnit.of_map (f : F) [IsLocalRingHom f] (a : R) (h : IsUnit (f a)) : IsUnit a :=
227+
IsLocalRingHom.map_nonunit a h
228+
229+
-- TODO : remove alias, change the parenthesis of `f` and `a`
230+
alias isUnit_of_map_unit := IsUnit.of_map
231+
232+
variable [MonoidHomClass F R S]
233+
234+
@[simp]
235+
theorem isUnit_map_iff (f : F) [IsLocalRingHom f] (a : R) : IsUnit (f a) ↔ IsUnit a :=
236+
⟨IsLocalRingHom.map_nonunit a, IsUnit.map f⟩
237+
238+
theorem isLocalRingHom_of_leftInverse [FunLike G S R] [MonoidHomClass G S R]
239+
{f : F} (g : G) (hfg : Function.LeftInverse g f) : IsLocalRingHom f where
240+
map_nonunit a ha := by rwa [isUnit_map_of_leftInverse g hfg] at ha
241+
242+
instance MonoidHom.isLocalRingHom_comp (g : S →* T) (f : R →* S) [IsLocalRingHom g]
243+
[IsLocalRingHom f] : IsLocalRingHom (g.comp f) where
244+
map_nonunit a := IsLocalRingHom.map_nonunit a ∘ IsLocalRingHom.map_nonunit (f := g) (f a)
245+
246+
-- see note [lower instance priority]
247+
instance (priority := 100) isLocalRingHom_toMonoidHom (f : F) [IsLocalRingHom f] :
248+
IsLocalRingHom (f : R →* S) :=
249+
⟨IsLocalRingHom.map_nonunit (f := f)⟩
250+
251+
theorem MonoidHom.isLocalRingHom_of_comp (f : R →* S) (g : S →* T) [IsLocalRingHom (g.comp f)] :
252+
IsLocalRingHom f :=
253+
fun _ ha => (isUnit_map_iff (g.comp f) _).mp (ha.map g)⟩
254+
255+
end IsLocalRingHom

Mathlib/Algebra/GroupWithZero/Units/Basic.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ noncomputable def inverse : M₀ → M₀ := fun x => if h : IsUnit x then ((h.u
8787
theorem inverse_unit (u : M₀ˣ) : inverse (u : M₀) = (u⁻¹ : M₀ˣ) := by
8888
rw [inverse, dif_pos u.isUnit, IsUnit.unit_of_val_units]
8989

90+
theorem IsUnit.ringInverse {x : M₀} (h : IsUnit x) : IsUnit (inverse x) :=
91+
match h with
92+
| ⟨u, hu⟩ => hu ▸ ⟨u⁻¹, (inverse_unit u).symm⟩
93+
94+
theorem inverse_of_isUnit {x : M₀} (h : IsUnit x) : inverse x = ((h.unit⁻¹ : M₀ˣ) : M₀) := dif_pos h
95+
9096
/-- By definition, if `x` is not invertible then `inverse x = 0`. -/
9197
@[simp]
9298
theorem inverse_non_unit (x : M₀) (h : ¬IsUnit x) : inverse x = 0 :=

Mathlib/Algebra/GroupWithZero/Units/Lemmas.lean

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,35 @@ import Mathlib.Algebra.GroupWithZero.Hom
1515

1616
assert_not_exists DenselyOrdered
1717

18-
variable {α M₀ G₀ M₀' G₀' F F' : Type*}
18+
variable {α M M₀ G₀ M₀' G₀' F F' : Type*}
19+
1920
variable [MonoidWithZero M₀]
2021

22+
section Monoid
23+
24+
variable [Monoid M] [GroupWithZero G₀]
25+
26+
lemma isLocalRingHom_of_exists_map_ne_one [FunLike F G₀ M] [MonoidHomClass F G₀ M] {f : F}
27+
(hf : ∃ x : G₀, f x ≠ 1) : IsLocalRingHom f where
28+
map_nonunit a h := by
29+
rcases eq_or_ne a 0 with (rfl | h)
30+
· obtain ⟨t, ht⟩ := hf
31+
refine (ht ?_).elim
32+
have := map_mul f t 0
33+
rw [← one_mul (f (t * 0)), mul_zero] at this
34+
exact (h.mul_right_cancel this).symm
35+
· exact ⟨⟨a, a⁻¹, mul_inv_cancel₀ h, inv_mul_cancel₀ h⟩, rfl⟩
36+
37+
instance [GroupWithZero G₀] [FunLike F G₀ M₀] [MonoidWithZeroHomClass F G₀ M₀] [Nontrivial M₀]
38+
(f : F) : IsLocalRingHom f :=
39+
isLocalRingHom_of_exists_map_ne_one ⟨0, by simp⟩
40+
41+
end Monoid
42+
43+
section GroupWithZero
44+
2145
namespace Commute
46+
2247
variable [GroupWithZero G₀] {a b c d : G₀}
2348

2449
/-- The `MonoidWithZero` version of `div_eq_div_iff_mul_eq_mul`. -/
@@ -107,3 +132,5 @@ end Units
107132
theorem map_zpow₀ {F G₀ G₀' : Type*} [GroupWithZero G₀] [GroupWithZero G₀'] [FunLike F G₀ G₀']
108133
[MonoidWithZeroHomClass F G₀ G₀'] (f : F) (x : G₀) (n : ℤ) : f (x ^ n) = f x ^ n :=
109134
map_zpow' f (map_inv₀ f) x n
135+
136+
end GroupWithZero

Mathlib/Algebra/Polynomial/Expand.lean

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Kenny Lau
55
-/
66
import Mathlib.RingTheory.Polynomial.Basic
7-
import Mathlib.RingTheory.LocalRing.RingHom.Basic
87

98
/-!
109
# Expand a polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`.
@@ -269,9 +268,8 @@ section IsDomain
269268

270269
variable (R : Type u) [CommRing R] [IsDomain R]
271270

272-
theorem isLocalRingHom_expand {p : ℕ} (hp : 0 < p) :
273-
IsLocalRingHom (↑(expand R p) : R[X] →+* R[X]) := by
274-
refine ⟨fun f hf1 => ?_⟩; norm_cast at hf1
271+
theorem isLocalRingHom_expand {p : ℕ} (hp : 0 < p) : IsLocalRingHom (expand R p) := by
272+
refine ⟨fun f hf1 => ?_⟩
275273
have hf2 := eq_C_of_degree_eq_zero (degree_eq_zero_of_isUnit hf1)
276274
rw [coeff_expand hp, if_pos (dvd_zero _), p.zero_div] at hf2
277275
rw [hf2, isUnit_C] at hf1; rw [expand_eq_C hp] at hf2; rwa [hf2, isUnit_C]
@@ -281,7 +279,7 @@ variable {R}
281279
theorem of_irreducible_expand {p : ℕ} (hp : p ≠ 0) {f : R[X]} (hf : Irreducible (expand R p f)) :
282280
Irreducible f :=
283281
let _ := isLocalRingHom_expand R hp.bot_lt
284-
of_irreducible_map (↑(expand R p)) hf
282+
hf.of_map
285283

286284
theorem of_irreducible_expand_pow {p : ℕ} (hp : p ≠ 0) {f : R[X]} {n : ℕ} :
287285
Irreducible (expand R (p ^ n) f) → Irreducible f :=

Mathlib/Algebra/Ring/Equiv.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Authors: Johannes Hölzl, Callum Sutton, Yury Kudryashov
55
-/
66
import Mathlib.Algebra.Group.Prod
77
import Mathlib.Algebra.Group.Opposite
8-
import Mathlib.Algebra.Group.Units.Equiv
98
import Mathlib.Algebra.GroupWithZero.InjSurj
109
import Mathlib.Algebra.Ring.Hom.Defs
1110
import Mathlib.Logic.Equiv.Set
@@ -805,9 +804,6 @@ protected theorem map_pow (f : R ≃+* S) (a) : ∀ n : ℕ, f (a ^ n) = f a ^ n
805804

806805
end GroupPower
807806

808-
protected theorem isUnit_iff (f : R ≃+* S) {a} : IsUnit (f a) ↔ IsUnit a :=
809-
MulEquiv.map_isUnit_iff f
810-
811807
end RingEquiv
812808

813809
namespace MulEquiv

Mathlib/AlgebraicGeometry/GammaSpecAdjunction.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ def identityToΓSpec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.rightOp ⋙ Spec.toLoc
282282
= toΓSpecFun X x := by rw [ContinuousMap.coe_mk]
283283
erw [this]
284284
dsimp [toΓSpecFun]
285+
-- TODO: this instance was found automatically before #6045
286+
have := @AlgebraicGeometry.LocallyRingedSpace.isLocalRingHomStalkMap X Y
285287
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
286288
erw [← LocalRing.comap_closedPoint (f.stalkMap x), ←
287289
PrimeSpectrum.comap_comp_apply, ← PrimeSpectrum.comap_comp_apply]

0 commit comments

Comments
 (0)