Skip to content

Commit fb131a4

Browse files
committed
chore(TrivSqZeroExt): clean up instances (leanprover-community#37137)
Clean up `TrivSqZeroExt` instances using `inferInstanceAs`
1 parent a1ec97c commit fb131a4

2 files changed

Lines changed: 94 additions & 119 deletions

File tree

Mathlib/Algebra/TrivSqZeroExt/Basic.lean

Lines changed: 83 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -177,76 +177,76 @@ section Additive
177177
variable {T : Type*} {S : Type*} {R : Type u} {M : Type v}
178178

179179
instance inhabited [Inhabited R] [Inhabited M] : Inhabited (tsze R M) :=
180-
instInhabitedProd
180+
inferInstanceAs <| Inhabited (R × M)
181181

182182
instance zero [Zero R] [Zero M] : Zero (tsze R M) :=
183-
Prod.instZero
183+
inferInstanceAs <| Zero (R × M)
184184

185185
instance add [Add R] [Add M] : Add (tsze R M) :=
186-
Prod.instAdd
186+
inferInstanceAs <| Add (R × M)
187187

188188
instance sub [Sub R] [Sub M] : Sub (tsze R M) :=
189-
Prod.instSub
189+
inferInstanceAs <| Sub (R × M)
190190

191191
instance neg [Neg R] [Neg M] : Neg (tsze R M) :=
192-
Prod.instNeg
192+
inferInstanceAs <| Neg (R × M)
193193

194194
instance addSemigroup [AddSemigroup R] [AddSemigroup M] : AddSemigroup (tsze R M) :=
195-
Prod.instAddSemigroup
195+
inferInstanceAs <| AddSemigroup (R × M)
196196

197197
instance addZeroClass [AddZeroClass R] [AddZeroClass M] : AddZeroClass (tsze R M) :=
198-
Prod.instAddZeroClass
198+
inferInstanceAs <| AddZeroClass (R × M)
199199

200200
instance addMonoid [AddMonoid R] [AddMonoid M] : AddMonoid (tsze R M) :=
201-
Prod.instAddMonoid
201+
inferInstanceAs <| AddMonoid (R × M)
202202

203203
instance addGroup [AddGroup R] [AddGroup M] : AddGroup (tsze R M) :=
204-
Prod.instAddGroup
204+
inferInstanceAs <| AddGroup (R × M)
205205

206206
instance addCommSemigroup [AddCommSemigroup R] [AddCommSemigroup M] : AddCommSemigroup (tsze R M) :=
207-
Prod.instAddCommSemigroup
207+
inferInstanceAs <| AddCommSemigroup (R × M)
208208

209209
instance addCommMonoid [AddCommMonoid R] [AddCommMonoid M] : AddCommMonoid (tsze R M) :=
210-
Prod.instAddCommMonoid
210+
inferInstanceAs <| AddCommMonoid (R × M)
211211

212212
instance addCommGroup [AddCommGroup R] [AddCommGroup M] : AddCommGroup (tsze R M) :=
213-
Prod.instAddCommGroup
213+
inferInstanceAs <| AddCommGroup (R × M)
214214

215215
instance smul [SMul S R] [SMul S M] : SMul S (tsze R M) :=
216-
Prod.instSMul
216+
inferInstanceAs <| SMul S (R × M)
217217

218218
instance isScalarTower [SMul T R] [SMul T M] [SMul S R] [SMul S M] [SMul T S]
219219
[IsScalarTower T S R] [IsScalarTower T S M] : IsScalarTower T S (tsze R M) :=
220-
Prod.isScalarTower
220+
inferInstanceAs <| IsScalarTower T S (R × M)
221221

222222
instance smulCommClass [SMul T R] [SMul T M] [SMul S R] [SMul S M]
223223
[SMulCommClass T S R] [SMulCommClass T S M] : SMulCommClass T S (tsze R M) :=
224-
Prod.smulCommClass
224+
inferInstanceAs <| SMulCommClass T S (R × M)
225225

226226
instance isCentralScalar [SMul S R] [SMul S M] [SMul Sᵐᵒᵖ R] [SMul Sᵐᵒᵖ M] [IsCentralScalar S R]
227227
[IsCentralScalar S M] : IsCentralScalar S (tsze R M) :=
228-
Prod.isCentralScalar
228+
inferInstanceAs <| IsCentralScalar S (R × M)
229229

230230
instance mulAction [Monoid S] [MulAction S R] [MulAction S M] : MulAction S (tsze R M) :=
231-
Prod.mulAction
231+
inferInstanceAs <| MulAction S (R × M)
232232

233233
instance distribMulAction [Monoid S] [AddMonoid R] [AddMonoid M]
234234
[DistribMulAction S R] [DistribMulAction S M] : DistribMulAction S (tsze R M) :=
235-
Prod.distribMulAction
235+
inferInstanceAs <| DistribMulAction S (R × M)
236236

237237
instance module [Semiring S] [AddCommMonoid R] [AddCommMonoid M] [Module S R] [Module S M] :
238238
Module S (tsze R M) :=
239-
Prod.instModule
239+
inferInstanceAs <| Module S (R × M)
240240

241241
/-- The trivial square-zero extension is nontrivial if it is over a nontrivial ring. -/
242242
instance instNontrivial_of_left {R M : Type*} [Nontrivial R] [Nonempty M] :
243-
Nontrivial (TrivSqZeroExt R M) :=
244-
fst_surjective.nontrivial
243+
Nontrivial (tsze R M) :=
244+
inferInstanceAs <| Nontrivial (R × M)
245245

246246
/-- The trivial square-zero extension is nontrivial if it is over a nontrivial module. -/
247247
instance instNontrivial_of_right {R M : Type*} [Nonempty R] [Nontrivial M] :
248-
Nontrivial (TrivSqZeroExt R M) :=
249-
snd_surjective.nontrivial
248+
Nontrivial (tsze R M) :=
249+
inferInstanceAs <| Nontrivial (R × M)
250250

251251
@[simp]
252252
theorem fst_zero [Zero R] [Zero M] : (0 : tsze R M).fst = 0 :=
@@ -477,20 +477,18 @@ theorem mul_inl_eq_op_smul [Monoid R] [AddMonoid M] [DistribMulAction R M] [Dist
477477
ext rfl (by dsimp; rw [smul_zero, zero_add])
478478

479479
instance mulOneClass [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] :
480-
MulOneClass (tsze R M) :=
481-
{ TrivSqZeroExt.one, TrivSqZeroExt.mul with
482-
one_mul := fun x =>
483-
ext (one_mul x.1) <|
484-
show (1 : R) •> x.2 + (0 : M) <• x.1 = x.2 by rw [one_smul, smul_zero, add_zero]
485-
mul_one := fun x =>
486-
ext (mul_one x.1) <|
487-
show x.1 • (0 : M) + x.2 <• (1 : R) = x.2 by rw [smul_zero, zero_add, op_one, one_smul] }
488-
489-
instance addMonoidWithOne [AddMonoidWithOne R] [AddMonoid M] : AddMonoidWithOne (tsze R M) :=
490-
{ TrivSqZeroExt.addMonoid, TrivSqZeroExt.one with
491-
natCast := fun n => inl n
492-
natCast_zero := by simp [Nat.cast]
493-
natCast_succ := fun _ => by ext <;> simp [Nat.cast] }
480+
MulOneClass (tsze R M) where
481+
one_mul := fun x =>
482+
ext (one_mul x.1) <|
483+
show (1 : R) •> x.2 + (0 : M) <• x.1 = x.2 by rw [one_smul, smul_zero, add_zero]
484+
mul_one := fun x =>
485+
ext (mul_one x.1) <|
486+
show x.1 • (0 : M) + x.2 <• (1 : R) = x.2 by rw [smul_zero, zero_add, op_one, one_smul]
487+
488+
instance addMonoidWithOne [AddMonoidWithOne R] [AddMonoid M] : AddMonoidWithOne (tsze R M) where
489+
natCast := fun n => inl n
490+
natCast_zero := by simp [Nat.cast]
491+
natCast_succ := fun _ => by ext <;> simp [Nat.cast]
494492

495493
@[simp]
496494
theorem fst_natCast [AddMonoidWithOne R] [AddMonoid M] (n : ℕ) : (n : tsze R M).fst = n :=
@@ -504,11 +502,10 @@ theorem snd_natCast [AddMonoidWithOne R] [AddMonoid M] (n : ℕ) : (n : tsze R M
504502
theorem inl_natCast [AddMonoidWithOne R] [AddMonoid M] (n : ℕ) : (inl n : tsze R M) = n :=
505503
rfl
506504

507-
instance addGroupWithOne [AddGroupWithOne R] [AddGroup M] : AddGroupWithOne (tsze R M) :=
508-
{ TrivSqZeroExt.addGroup, TrivSqZeroExt.addMonoidWithOne with
509-
intCast := fun z => inl z
510-
intCast_ofNat := fun _n => ext (Int.cast_natCast _) rfl
511-
intCast_negSucc := fun _n => ext (Int.cast_negSucc _) neg_zero.symm }
505+
instance addGroupWithOne [AddGroupWithOne R] [AddGroup M] : AddGroupWithOne (tsze R M) where
506+
intCast := fun z => inl z
507+
intCast_ofNat := fun _n => ext (Int.cast_natCast _) rfl
508+
intCast_negSucc := fun _n => ext (Int.cast_negSucc _) neg_zero.symm
512509

513510
@[simp]
514511
theorem fst_intCast [AddGroupWithOne R] [AddGroup M] (z : ℤ) : (z : tsze R M).fst = z :=
@@ -523,30 +520,28 @@ theorem inl_intCast [AddGroupWithOne R] [AddGroup M] (z : ℤ) : (inl z : tsze R
523520
rfl
524521

525522
instance nonAssocSemiring [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] :
526-
NonAssocSemiring (tsze R M) :=
527-
{ TrivSqZeroExt.addMonoidWithOne, TrivSqZeroExt.mulOneClass, TrivSqZeroExt.addCommMonoid with
528-
zero_mul := fun x =>
529-
ext (zero_mul x.1) <|
530-
show (0 : R) •> x.2 + (0 : M) <• x.1 = 0 by rw [zero_smul, zero_add, smul_zero]
531-
mul_zero := fun x =>
532-
ext (mul_zero x.1) <|
533-
show x.1 • (0 : M) + (0 : Rᵐᵒᵖ) • x.2 = 0 by rw [smul_zero, zero_add, zero_smul]
534-
left_distrib := fun x₁ x₂ x₃ =>
535-
ext (mul_add x₁.1 x₂.1 x₃.1) <|
536-
show
537-
x₁.1 •> (x₂.2 + x₃.2) + x₁.2 <• (x₂.1 + x₃.1) =
538-
x₁.1 •> x₂.2 + x₁.2 <• x₂.1 + (x₁.1 •> x₃.2 + x₁.2 <• x₃.1)
539-
by simp_rw [smul_add, MulOpposite.op_add, add_smul, add_add_add_comm]
540-
right_distrib := fun x₁ x₂ x₃ =>
541-
ext (add_mul x₁.1 x₂.1 x₃.1) <|
542-
show
543-
(x₁.1 + x₂.1) •> x₃.2 + (x₁.2 + x₂.2) <• x₃.1 =
544-
x₁.1 •> x₃.2 + x₁.2 <• x₃.1 + (x₂.1 •> x₃.2 + x₂.2 <• x₃.1)
545-
by simp_rw [add_smul, smul_add, add_add_add_comm] }
523+
NonAssocSemiring (tsze R M) where
524+
zero_mul := fun x =>
525+
ext (zero_mul x.1) <|
526+
show (0 : R) •> x.2 + (0 : M) <• x.1 = 0 by rw [zero_smul, zero_add, smul_zero]
527+
mul_zero := fun x =>
528+
ext (mul_zero x.1) <|
529+
show x.1 • (0 : M) + (0 : Rᵐᵒᵖ) • x.2 = 0 by rw [smul_zero, zero_add, zero_smul]
530+
left_distrib := fun x₁ x₂ x₃ =>
531+
ext (mul_add x₁.1 x₂.1 x₃.1) <|
532+
show
533+
x₁.1 •> (x₂.2 + x₃.2) + x₁.2 <• (x₂.1 + x₃.1) =
534+
x₁.1 •> x₂.2 + x₁.2 <• x₂.1 + (x₁.1 •> x₃.2 + x₁.2 <• x₃.1)
535+
by simp_rw [smul_add, MulOpposite.op_add, add_smul, add_add_add_comm]
536+
right_distrib := fun x₁ x₂ x₃ =>
537+
ext (add_mul x₁.1 x₂.1 x₃.1) <|
538+
show
539+
(x₁.1 + x₂.1) •> x₃.2 + (x₁.2 + x₂.2) <• x₃.1 =
540+
x₁.1 •> x₃.2 + x₁.2 <• x₃.1 + (x₂.1 •> x₃.2 + x₂.2 <• x₃.1)
541+
by simp_rw [add_smul, smul_add, add_add_add_comm]
546542

547543
instance nonAssocRing [Ring R] [AddCommGroup M] [Module R M] [Module Rᵐᵒᵖ M] :
548-
NonAssocRing (tsze R M) :=
549-
{ TrivSqZeroExt.addGroupWithOne, TrivSqZeroExt.nonAssocSemiring with }
544+
NonAssocRing (tsze R M) where
550545

551546
/-- In the general non-commutative case, the power operator is
552547
@@ -606,35 +601,33 @@ theorem inl_pow [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulActio
606601
ext rfl <| by simp [snd_pow_eq_sum, List.map_const']
607602

608603
instance monoid [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
609-
[SMulCommClass R Rᵐᵒᵖ M] : Monoid (tsze R M) :=
610-
{ TrivSqZeroExt.mulOneClass with
611-
mul_assoc := fun x y z =>
612-
ext (mul_assoc x.1 y.1 z.1) <|
613-
show
614-
(x.1 * y.1) •> z.2 + (x.1 •> y.2 + x.2 <• y.1) <• z.1 =
615-
x.1 •> (y.1 •> z.2 + y.2 <• z.1) + x.2 <• (y.1 * z.1)
616-
by simp_rw [smul_add, ← mul_smul, add_assoc, smul_comm, op_mul]
617-
npow := fun n x => x ^ n
618-
npow_zero := fun x => ext (pow_zero x.fst) (by simp [snd_pow_eq_sum])
619-
npow_succ := fun n x =>
620-
ext (pow_succ _ _)
621-
(by
622-
simp_rw [snd_mul, snd_pow_eq_sum, Nat.pred_succ]
623-
cases n
624-
· simp [List.range_succ]
625-
rw [List.sum_range_succ']
626-
simp only [pow_zero, op_one, Nat.sub_zero, one_smul, Nat.succ_sub_succ_eq_sub, fst_pow,
627-
Nat.pred_succ, List.smul_sum, List.map_map, Function.comp_def]
628-
simp_rw [← smul_comm (_ : R) (_ : Rᵐᵒᵖ), smul_smul, pow_succ]
629-
rfl) }
604+
[SMulCommClass R Rᵐᵒᵖ M] : Monoid (tsze R M) where
605+
mul_assoc := fun x y z =>
606+
ext (mul_assoc x.1 y.1 z.1) <|
607+
show
608+
(x.1 * y.1) •> z.2 + (x.1 •> y.2 + x.2 <• y.1) <• z.1 =
609+
x.1 •> (y.1 •> z.2 + y.2 <• z.1) + x.2 <• (y.1 * z.1)
610+
by simp_rw [smul_add, ← mul_smul, add_assoc, smul_comm, op_mul]
611+
npow := fun n x => x ^ n
612+
npow_zero := fun x => ext (pow_zero x.fst) (by simp [snd_pow_eq_sum])
613+
npow_succ := fun n x =>
614+
ext (pow_succ _ _)
615+
(by
616+
simp_rw [snd_mul, snd_pow_eq_sum, Nat.pred_succ]
617+
cases n
618+
· simp [List.range_succ]
619+
rw [List.sum_range_succ']
620+
simp only [pow_zero, op_one, Nat.sub_zero, one_smul, Nat.succ_sub_succ_eq_sub, fst_pow,
621+
Nat.pred_succ, List.smul_sum, List.map_map, Function.comp_def]
622+
simp_rw [← smul_comm (_ : R) (_ : Rᵐᵒᵖ), smul_smul, pow_succ]
623+
rfl)
630624

631625
theorem fst_list_prod [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M]
632626
[SMulCommClass R Rᵐᵒᵖ M] (l : List (tsze R M)) : l.prod.fst = (l.map fst).prod :=
633627
map_list_prod ({ toFun := fst, map_one' := fst_one, map_mul' := fst_mul } : tsze R M →* R) _
634628

635629
instance semiring [Semiring R] [AddCommMonoid M]
636-
[Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] : Semiring (tsze R M) :=
637-
{ TrivSqZeroExt.monoid, TrivSqZeroExt.nonAssocSemiring with }
630+
[Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] : Semiring (tsze R M) where
638631

639632
/-- The second element of a product $\prod_{i=0}^n (r_i + m_i)$ is a sum of terms of the form
640633
$r_0\cdots r_{i-1}m_ir_{i+1}\cdots r_n$. -/
@@ -654,8 +647,7 @@ theorem snd_list_prod [Monoid R] [AddCommMonoid M] [DistribMulAction R M] [Distr
654647
exact add_comm _ _
655648

656649
instance ring [Ring R] [AddCommGroup M] [Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] :
657-
Ring (tsze R M) :=
658-
{ TrivSqZeroExt.semiring, TrivSqZeroExt.nonAssocRing with }
650+
Ring (tsze R M) where
659651

660652
instance commMonoid [CommMonoid R] [AddCommMonoid M] [DistribMulAction R M]
661653
[DistribMulAction Rᵐᵒᵖ M] [IsCentralScalar R M] : CommMonoid (tsze R M) :=
@@ -666,12 +658,10 @@ instance commMonoid [CommMonoid R] [AddCommMonoid M] [DistribMulAction R M]
666658
rw [op_smul_eq_smul, op_smul_eq_smul, add_comm] }
667659

668660
instance commSemiring [CommSemiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M]
669-
[IsCentralScalar R M] : CommSemiring (tsze R M) :=
670-
{ TrivSqZeroExt.commMonoid, TrivSqZeroExt.nonAssocSemiring with }
661+
[IsCentralScalar R M] : CommSemiring (tsze R M) where
671662

672663
instance commRing [CommRing R] [AddCommGroup M] [Module R M] [Module Rᵐᵒᵖ M] [IsCentralScalar R M] :
673-
CommRing (tsze R M) :=
674-
{ TrivSqZeroExt.nonAssocRing, TrivSqZeroExt.commSemiring with }
664+
CommRing (tsze R M) where
675665

676666
variable (R M)
677667

@@ -934,7 +924,6 @@ theorem algHom_ext' {A} [Semiring A] [Algebra S A] ⦃f g : tsze R M →ₐ[S] A
934924

935925
variable {A : Type*} [Semiring A] [Algebra S A] [Algebra R' A]
936926

937-
set_option backward.isDefEq.respectTransparency false in
938927
/--
939928
Assemble an algebra morphism `TrivSqZeroExt R M →ₐ[S] A` from separate morphisms on `R` and `M`.
940929
@@ -1083,17 +1072,14 @@ def map (f : M →ₗ[R'] N) : TrivSqZeroExt R' M →ₐ[R'] TrivSqZeroExt R' N
10831072
theorem map_inl (f : M →ₗ[R'] N) (r : R') : map f (inl r) = inl r := by
10841073
rw [map, liftEquivOfComm_apply, lift_apply_inl, Algebra.ofId_apply, algebraMap_eq_inl]
10851074

1086-
set_option backward.isDefEq.respectTransparency false in
10871075
@[simp]
10881076
theorem map_inr (f : M →ₗ[R'] N) (x : M) : map f (inr x) = inr (f x) := by
10891077
rw [map, liftEquivOfComm_apply, lift_apply_inr, LinearMap.comp_apply, inrHom_apply]
10901078

1091-
set_option backward.isDefEq.respectTransparency false in
10921079
@[simp]
10931080
theorem fst_map (f : M →ₗ[R'] N) (x : TrivSqZeroExt R' M) : fst (map f x) = fst x := by
10941081
simp [map, lift_def, Algebra.ofId_apply, algebraMap_eq_inl]
10951082

1096-
set_option backward.isDefEq.respectTransparency false in
10971083
@[simp]
10981084
theorem snd_map (f : M →ₗ[R'] N) (x : TrivSqZeroExt R' M) : snd (map f x) = f (snd x) := by
10991085
simp [map, lift_def, Algebra.ofId_apply, algebraMap_eq_inl]

0 commit comments

Comments
 (0)