Skip to content

Commit 15bbbc4

Browse files
committed
feat(Algebra/Ring/Subring): drop associativity condition for Subrings (#36735)
cf. Item 4 in #7987.
1 parent 817fb21 commit 15bbbc4

File tree

11 files changed

+142
-65
lines changed

11 files changed

+142
-65
lines changed

Counterexamples/DimensionPolynomial.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ theorem ringKrullDim_polynomial_A_eq_three : ringKrullDim (A k)[X] = 3 := by
7878
(PowerSeries.constantCoeff.comp (A k).subtype).rangeRestrict
7979
exact fun _ ⟨⟨_, ⟨u, _⟩⟩, _⟩ ↦ ⟨u, ⟨by simp, by simp_all⟩⟩
8080
have h_phi : RatFunc.C.comp φ = PowerSeries.constantCoeff.comp (A k).subtype := RingHom.ext
81-
fun x ↦ by simp [φ, ← Subring.coe_equivMapOfInjective_apply (hf := RatFunc.C_injective)]
81+
fun x ↦ by simp [φ, ← Subring.coe_equivMapOfInjective_apply
82+
(S := RatFunc k) (hf := RatFunc.C_injective)]
8283
let f : (A k)[X] →+* (RatFunc k)⟦X⟧ := eval₂RingHom (A k).subtype (PowerSeries.C RatFunc.X)
8384
let Q : PrimeSpectrum (A k)[X] := ⟨RingHom.ker f, RingHom.ker_isPrime f⟩
8485
let g : (A k)[X] →+* k[X] := mapRingHom φ

Mathlib/Algebra/Ring/InjSurj.lean

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected abbrev distrib [Distrib R] (add : ∀ x y, f (x + y) = f x + f y)
5656

5757
/-- A type endowed with `-` and `*` has distributive negation, if it admits an injective map that
5858
preserves `-` and `*` to a type which has distributive negation. -/
59-
-- -- See note [reducible non-instances]
59+
-- See note [reducible non-instances]
6060
protected abbrev hasDistribNeg (f : S → R) (hf : Injective f) [Mul R] [HasDistribNeg R]
6161
(neg : ∀ a, f (-a) = -f a)
6262
(mul : ∀ a b, f (a * b) = f a * f b) : HasDistribNeg S :=
@@ -215,7 +215,14 @@ protected abbrev nonUnitalCommSemiring [NonUnitalCommSemiring R] (f : S → R)
215215
toNonUnitalSemiring := hf.nonUnitalSemiring f zero add mul nsmul
216216
__ := hf.commSemigroup f mul
217217

218-
-- `NonAssocCommSemiring` currently doesn't exist
218+
/-- Pullback a `NonAssocCommSemiring` instance along an injective function. -/
219+
-- See note [reducible non-instances]
220+
protected abbrev nonAssocCommSemiring [NonAssocCommSemiring R] (f : S → R)
221+
(hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y)
222+
(mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x)
223+
(natCast : ∀ n : ℕ, f n = n) : NonAssocCommSemiring S where
224+
toNonAssocSemiring := hf.nonAssocSemiring f zero one add mul nsmul natCast
225+
__ := hf.commMagma f mul
219226

220227
/-- Pullback a `CommSemiring` instance along an injective function. -/
221228
-- See note [reducible non-instances]
@@ -238,7 +245,7 @@ protected abbrev nonUnitalNonAssocCommRing [NonUnitalNonAssocCommRing R] (f : S
238245
__ := hf.nonUnitalNonAssocCommSemiring f zero add mul nsmul
239246

240247
/-- Pullback a `NonUnitalCommRing` instance along an injective function. -/
241-
-- -- See note [reducible non-instances]
248+
-- See note [reducible non-instances]
242249
protected abbrev nonUnitalCommRing [NonUnitalCommRing R] (f : S → R)
243250
(hf : Injective f) (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y)
244251
(mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x)
@@ -247,8 +254,19 @@ protected abbrev nonUnitalCommRing [NonUnitalCommRing R] (f : S → R)
247254
toNonUnitalRing := hf.nonUnitalRing f zero add mul neg sub nsmul zsmul
248255
__ := hf.nonUnitalNonAssocCommRing f zero add mul neg sub nsmul zsmul
249256

257+
/-- Pullback a `NonAssocCommRing` instance along an injective function. -/
258+
-- See note [reducible non-instances]
259+
protected abbrev nonAssocCommRing [NonAssocCommRing R] (f : S → R)
260+
(hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y)
261+
(mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x)
262+
(sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x)
263+
(zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x)
264+
(natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : NonAssocCommRing S where
265+
toNonAssocRing := hf.nonAssocRing f zero one add mul neg sub nsmul zsmul natCast intCast
266+
__ := hf.nonUnitalNonAssocCommRing f zero add mul neg sub nsmul zsmul
267+
250268
/-- Pullback a `CommRing` instance along an injective function. -/
251-
-- -- See note [reducible non-instances]
269+
-- See note [reducible non-instances]
252270
protected abbrev commRing [CommRing R]
253271
(zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y)
254272
(mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x)
@@ -438,6 +456,15 @@ protected abbrev nonUnitalCommSemiring [NonUnitalCommSemiring R] (zero : f 0 = 0
438456
toNonUnitalSemiring := hf.nonUnitalSemiring f zero add mul nsmul
439457
__ := hf.commSemigroup f mul
440458

459+
/-- Pushforward a `NonAssocCommSemiring` instance along a surjective function. -/
460+
-- See note [reducible non-instances]
461+
protected abbrev nonAssocCommSemiring [NonAssocCommSemiring R] (zero : f 0 = 0) (one : f 1 = 1)
462+
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
463+
(nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x)
464+
(natCast : ∀ n : ℕ, f n = n) : NonAssocCommSemiring S where
465+
toNonAssocSemiring := hf.nonAssocSemiring f zero one add mul nsmul natCast
466+
__ := hf.commMagma f mul
467+
441468
/-- Pushforward a `CommSemiring` instance along a surjective function. -/
442469
-- See note [reducible non-instances]
443470
protected abbrev commSemiring [CommSemiring R] (zero : f 0 = 0) (one : f 1 = 1)
@@ -467,6 +494,16 @@ protected abbrev nonUnitalCommRing [NonUnitalCommRing R] (zero : f 0 = 0)
467494
toNonUnitalRing := hf.nonUnitalRing f zero add mul neg sub nsmul zsmul
468495
__ := hf.nonUnitalNonAssocCommRing f zero add mul neg sub nsmul zsmul
469496

497+
/-- Pushforward a `NonAssocCommRing` instance along a surjective function. -/
498+
-- See note [reducible non-instances]
499+
protected abbrev nonAssocCommRing [NonAssocCommRing R] (zero : f 0 = 0) (one : f 1 = 1)
500+
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
501+
(neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y)
502+
(nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x)
503+
(natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : NonAssocCommRing S where
504+
toNonAssocRing := hf.nonAssocRing f zero one add mul neg sub nsmul zsmul natCast intCast
505+
__ := hf.nonAssocCommSemiring f zero one add mul nsmul natCast
506+
470507
/-- Pushforward a `CommRing` instance along a surjective function. -/
471508
-- See note [reducible non-instances]
472509
protected abbrev commRing [CommRing R] (zero : f 0 = 0) (one : f 1 = 1)

Mathlib/Algebra/Ring/Subring/Basic.lean

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ assert_not_exists IsOrderedRing
6666

6767
universe u v w
6868

69-
variable {R : Type u} {S : Type v} {T : Type w} [Ring R]
69+
variable {R : Type u} {S : Type v} {T : Type w} [NonAssocRing R]
7070

71-
variable [Ring S] [Ring T]
71+
variable [NonAssocRing S] [NonAssocRing T]
7272

7373
namespace Subring
7474
variable {s t : Subring R}
@@ -115,8 +115,8 @@ namespace Subring
115115
variable (s : Subring R)
116116

117117
/-- Product of a list of elements in a subring is in the subring. -/
118-
protected theorem list_prod_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.prod ∈ s :=
119-
list_prod_mem
118+
protected theorem list_prod_mem {R} [Ring R] (s : Subring R) {l : List R} :
119+
(∀ x ∈ l, x ∈ s) → l.prod ∈ s := list_prod_mem
120120

121121
/-- Sum of a list of elements in a subring is in the subring. -/
122122
protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s :=
@@ -174,17 +174,17 @@ theorem coe_top : ((⊤ : Subring R) : Set R) = Set.univ :=
174174
def topEquiv : (⊤ : Subring R) ≃+* R :=
175175
Subsemiring.topEquiv
176176

177-
instance {R : Type*} [Ring R] [Fintype R] : Fintype (⊤ : Subring R) :=
177+
instance {R : Type*} [NonAssocRing R] [Fintype R] : Fintype (⊤ : Subring R) :=
178178
(inferInstance : Fintype (⊤ : Set R))
179179

180-
theorem card_top (R) [Ring R] [Fintype R] : Fintype.card (⊤ : Subring R) = Fintype.card R :=
180+
theorem card_top (R) [NonAssocRing R] [Fintype R] : Fintype.card (⊤ : Subring R) = Fintype.card R :=
181181
Fintype.card_congr topEquiv.toEquiv
182182

183183
/-! ## comap -/
184184

185185

186186
/-- The preimage of a subring along a ring homomorphism is a subring. -/
187-
def comap {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) (s : Subring S) : Subring R :=
187+
def comap (f : R →+* S) (s : Subring S) : Subring R :=
188188
{ s.toSubmonoid.comap (f : R →* S), s.toAddSubgroup.comap (f : R →+ S) with
189189
carrier := f ⁻¹' s.carrier }
190190

@@ -204,7 +204,7 @@ theorem comap_comap (s : Subring T) (g : S →+* T) (f : R →+* S) :
204204

205205

206206
/-- The image of a subring along a ring homomorphism is a subring. -/
207-
def map {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) (s : Subring R) : Subring S :=
207+
def map (f : R →+* S) (s : Subring R) : Subring S :=
208208
{ s.toSubmonoid.map (f : R →* S), s.toAddSubgroup.map (f : R →+ S) with
209209
carrier := f '' s.carrier }
210210

@@ -250,7 +250,7 @@ variable (g : S →+* T) (f : R →+* S)
250250

251251

252252
/-- The range of a ring homomorphism, as a subring of the target. See Note [range copy pattern]. -/
253-
def range {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) : Subring S :=
253+
def range (f : R →+* S) : Subring S :=
254254
((⊤ : Subring R).map f).copy (Set.range f) Set.image_univ.symm
255255

256256
@[simp]
@@ -384,18 +384,18 @@ theorem center_toSubsemiring : (center R).toSubsemiring = Subsemiring.center R :
384384

385385
variable {R}
386386

387-
theorem mem_center_iff {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g :=
387+
theorem mem_center_iff {R : Type*} [Ring R] {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g :=
388388
Subsemigroup.mem_center_iff
389389

390-
instance decidableMemCenter [DecidableEq R] [Fintype R] : DecidablePred (· ∈ center R) := fun _ =>
391-
decidable_of_iff' _ mem_center_iff
390+
instance decidableMemCenter {R} [Ring R] [DecidableEq R] [Fintype R] :
391+
DecidablePred (· ∈ center R) := fun _ => decidable_of_iff' _ mem_center_iff
392392

393393
@[simp]
394394
theorem center_eq_top (R) [CommRing R] : center R = ⊤ :=
395395
SetLike.coe_injective (Set.center_eq_univ R)
396396

397397
/-- The center is commutative. -/
398-
instance : CommRing (center R) :=
398+
instance {R} [Ring R] : CommRing (center R) :=
399399
{ (inferInstance : CommSemiring (Subsemiring.center R)), (center R).toRing with }
400400

401401
/-- The center of isomorphic (not necessarily associative) rings are isomorphic. -/
@@ -438,40 +438,40 @@ end DivisionRing
438438
section Centralizer
439439

440440
/-- The centralizer of a set inside a ring as a `Subring`. -/
441-
def centralizer (s : Set R) : Subring R :=
441+
def centralizer {R} [Ring R] (s : Set R) : Subring R :=
442442
{ Subsemiring.centralizer s with neg_mem' := Set.neg_mem_centralizer }
443443

444444
@[simp, norm_cast]
445-
theorem coe_centralizer (s : Set R) : (centralizer s : Set R) = s.centralizer :=
445+
theorem coe_centralizer {R} [Ring R] (s : Set R) : (centralizer s : Set R) = s.centralizer :=
446446
rfl
447447

448-
theorem centralizer_toSubmonoid (s : Set R) :
448+
theorem centralizer_toSubmonoid {R} [Ring R] (s : Set R) :
449449
(centralizer s).toSubmonoid = Submonoid.centralizer s :=
450450
rfl
451451

452-
theorem centralizer_toSubsemiring (s : Set R) :
452+
theorem centralizer_toSubsemiring {R} [Ring R] (s : Set R) :
453453
(centralizer s).toSubsemiring = Subsemiring.centralizer s :=
454454
rfl
455455

456-
theorem centralizer_toNonUnitalSubring (s : Set R) :
456+
theorem centralizer_toNonUnitalSubring {R} [Ring R] (s : Set R) :
457457
(centralizer s).toNonUnitalSubring = NonUnitalSubring.centralizer s :=
458458
rfl
459459

460-
theorem mem_centralizer_iff {s : Set R} {z : R} : z ∈ centralizer s ↔ ∀ g ∈ s, g * z = z * g :=
461-
Iff.rfl
460+
theorem mem_centralizer_iff {R} [Ring R] {s : Set R} {z : R} :
461+
z ∈ centralizer s ↔ ∀ g ∈ s, g * z = z * g := Iff.rfl
462462

463-
theorem center_le_centralizer (s) : center R ≤ centralizer s :=
463+
theorem center_le_centralizer {R} [Ring R] (s) : center R ≤ centralizer s :=
464464
s.center_subset_centralizer
465465

466-
theorem centralizer_le (s t : Set R) (h : s ⊆ t) : centralizer t ≤ centralizer s :=
466+
theorem centralizer_le {R} [Ring R] (s t : Set R) (h : s ⊆ t) : centralizer t ≤ centralizer s :=
467467
Set.centralizer_subset h
468468

469469
@[simp]
470-
theorem centralizer_eq_top_iff_subset {s : Set R} : centralizer s = ⊤ ↔ s ⊆ center R :=
470+
theorem centralizer_eq_top_iff_subset {R} [Ring R] {s : Set R} : centralizer s = ⊤ ↔ s ⊆ center R :=
471471
SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset
472472

473473
@[simp]
474-
theorem centralizer_univ : centralizer Set.univ = center R :=
474+
theorem centralizer_univ {R} [Ring R] : centralizer Set.univ = center R :=
475475
SetLike.ext' (Set.centralizer_univ R)
476476

477477
end Centralizer
@@ -589,19 +589,19 @@ theorem mem_closure_iff {s : Set R} {x} :
589589
| add _ _ _ _ h₁ h₂ => exact add_mem h₁ h₂
590590
| neg _ _ h => exact neg_mem h⟩
591591

592-
lemma closure_le_centralizer_centralizer (s : Set R) :
592+
lemma closure_le_centralizer_centralizer {R} [Ring R] (s : Set R) :
593593
closure s ≤ centralizer (centralizer s) :=
594594
closure_le.mpr Set.subset_centralizer_centralizer
595595

596596
/-- If all elements of `s : Set A` commute pairwise, then `closure s` is a commutative ring. -/
597-
abbrev closureCommRingOfComm {s : Set R} (hcomm : ∀ x ∈ s, ∀ y ∈ s, x * y = y * x) :
597+
abbrev closureCommRingOfComm {R} [Ring R] {s : Set R} (hcomm : ∀ x ∈ s, ∀ y ∈ s, x * y = y * x) :
598598
CommRing (closure s) :=
599599
{ (closure s).toRing with
600600
mul_comm := fun ⟨_, h₁⟩ ⟨_, h₂⟩ ↦
601601
have := closure_le_centralizer_centralizer s
602602
Subtype.ext <| Set.centralizer_centralizer_comm_of_comm hcomm _ (this h₁) _ (this h₂) }
603603

604-
theorem exists_list_of_mem_closure {s : Set R} {x : R} (hx : x ∈ closure s) :
604+
theorem exists_list_of_mem_closure {R} [Ring R] {s : Set R} {x : R} (hx : x ∈ closure s) :
605605
∃ L : List (List R), (∀ t ∈ L, ∀ y ∈ t, y ∈ s ∨ y = (-1 : R)) ∧ (L.map List.prod).sum = x := by
606606
rw [mem_closure_iff] at hx
607607
induction hx using AddSubgroup.closure_induction with
@@ -962,7 +962,8 @@ namespace Subring
962962
variable {s : Set R}
963963

964964
@[elab_as_elim]
965-
protected theorem InClosure.recOn {C : R → Prop} {x : R} (hx : x ∈ closure s) (h1 : C 1)
965+
protected theorem InClosure.recOn {R} [Ring R] {s : Set R}
966+
{C : R → Prop} {x : R} (hx : x ∈ closure s) (h1 : C 1)
966967
(hneg1 : C (-1)) (hs : ∀ z ∈ s, ∀ n, C n → C (z * n)) (ha : ∀ {x y}, C x → C y → C (x + y)) :
967968
C x := by
968969
have h0 : C 0 := add_neg_cancel (1 : R) ▸ ha h1 hneg1
@@ -1055,48 +1056,48 @@ instance [SMul R α] [FaithfulSMul R α] (S : Subring R) : FaithfulSMul S α :=
10551056
(inferInstance : FaithfulSMul S.toSubsemiring α)
10561057

10571058
/-- The action by a subring is the action by the underlying ring. -/
1058-
instance [MulAction R α] (S : Subring R) : MulAction S α :=
1059+
instance {R} [Ring R] [MulAction R α] (S : Subring R) : MulAction S α :=
10591060
(inferInstance : MulAction S.toSubsemiring α)
10601061

10611062
/-- The action by a subring is the action by the underlying ring. -/
1062-
instance [AddMonoid α] [DistribMulAction R α] (S : Subring R) : DistribMulAction S α :=
1063-
(inferInstance : DistribMulAction S.toSubsemiring α)
1063+
instance {R} [Ring R] [AddMonoid α] [DistribMulAction R α] (S : Subring R) :
1064+
DistribMulAction S α := (inferInstance : DistribMulAction S.toSubsemiring α)
10641065

10651066
/-- The action by a subring is the action by the underlying ring. -/
1066-
instance [Monoid α] [MulDistribMulAction R α] (S : Subring R) : MulDistribMulAction S α :=
1067-
(inferInstance : MulDistribMulAction S.toSubsemiring α)
1067+
instance {R} [Ring R] [Monoid α] [MulDistribMulAction R α] (S : Subring R) :
1068+
MulDistribMulAction S α := (inferInstance : MulDistribMulAction S.toSubsemiring α)
10681069

10691070
/-- The action by a subring is the action by the underlying ring. -/
10701071
instance [Zero α] [SMulWithZero R α] (S : Subring R) : SMulWithZero S α :=
10711072
(inferInstance : SMulWithZero S.toSubsemiring α)
10721073

10731074
/-- The action by a subring is the action by the underlying ring. -/
1074-
instance [Zero α] [MulActionWithZero R α] (S : Subring R) : MulActionWithZero S α :=
1075+
instance {R} [Ring R] [Zero α] [MulActionWithZero R α] (S : Subring R) : MulActionWithZero S α :=
10751076
(inferInstance : MulActionWithZero S.toSubsemiring α)
10761077

10771078
/-- The action by a subring is the action by the underlying ring. -/
1078-
instance [AddCommMonoid α] [Module R α] (S : Subring R) : Module S α :=
1079+
instance {R} [Ring R] [AddCommMonoid α] [Module R α] (S : Subring R) : Module S α :=
10791080
(inferInstance : Module S.toSubsemiring α)
10801081

10811082
/-- The action by a subsemiring is the action by the underlying ring. -/
1082-
instance [Semiring α] [MulSemiringAction R α] (S : Subring R) : MulSemiringAction S α :=
1083-
(inferInstance : MulSemiringAction S.toSubmonoid α)
1083+
instance {R} [Ring R] [Semiring α] [MulSemiringAction R α] (S : Subring R) :
1084+
MulSemiringAction S α := (inferInstance : MulSemiringAction S.toSubmonoid α)
10841085

10851086
/-- The center of a semiring acts commutatively on that semiring. -/
1086-
instance center.smulCommClass_left : SMulCommClass (center R) R R :=
1087+
instance center.smulCommClass_left {R} [Ring R] : SMulCommClass (center R) R R :=
10871088
Subsemiring.center.smulCommClass_left
10881089

10891090
/-- The center of a semiring acts commutatively on that semiring. -/
1090-
instance center.smulCommClass_right : SMulCommClass R (center R) R :=
1091+
instance center.smulCommClass_right {R} [Ring R] : SMulCommClass R (center R) R :=
10911092
Subsemiring.center.smulCommClass_right
10921093

10931094
/-- The center of a semiring acts commutatively on any `R`-module -/
1094-
instance {M : Type*} [MulAction R M] :
1095+
instance {R M : Type*} [Ring R] [MulAction R M] :
10951096
SMulCommClass R (Subring.center R) M :=
10961097
(inferInstance : SMulCommClass R (Submonoid.center R) M)
10971098

10981099
/-- The center of a semiring acts commutatively on any `R`-module -/
1099-
instance {M : Type*} [MulAction R M] :
1100+
instance {R M : Type*} [Ring R] [MulAction R M] :
11001101
SMulCommClass (Subring.center R) R M :=
11011102
(inferInstance : SMulCommClass (Submonoid.center R) R M)
11021103

0 commit comments

Comments
 (0)