Skip to content

Commit 2bffb70

Browse files
committed
chore: replace anonymous morphism constructors with named fields (#7015)
This makes it easier to refactor the order or inheritance structure of morphisms without having to change all of the anonymous constructors. This is far from exhaustive.
1 parent ae1eb5e commit 2bffb70

File tree

21 files changed

+85
-67
lines changed

21 files changed

+85
-67
lines changed

Mathlib/Algebra/Category/GroupCat/Basic.lean

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,7 @@ end CategoryTheory.Aut
491491
instance GroupCat.forget_reflects_isos : ReflectsIsomorphisms (forget GroupCat.{u}) where
492492
reflects {X Y} f _ := by
493493
let i := asIso ((forget GroupCat).map f)
494-
let e : X ≃* Y := MulEquiv.mk i.toEquiv
495-
-- Porting note: this would ideally be `by aesop`, as in `MonCat.forget_reflects_isos`
496-
(MonoidHom.map_mul (show MonoidHom X Y from f))
494+
let e : X ≃* Y := { i.toEquiv with map_mul' := by aesop }
497495
exact IsIso.of_iso e.toGroupCatIso
498496
set_option linter.uppercaseLean3 false in
499497
#align Group.forget_reflects_isos GroupCat.forget_reflects_isos
@@ -504,9 +502,7 @@ set_option linter.uppercaseLean3 false in
504502
instance CommGroupCat.forget_reflects_isos : ReflectsIsomorphisms (forget CommGroupCat.{u}) where
505503
reflects {X Y} f _ := by
506504
let i := asIso ((forget CommGroupCat).map f)
507-
let e : X ≃* Y := MulEquiv.mk i.toEquiv
508-
-- Porting note: this would ideally be `by aesop`, as in `MonCat.forget_reflects_isos`
509-
(MonoidHom.map_mul (show MonoidHom X Y from f))
505+
let e : X ≃* Y := { i.toEquiv with map_mul' := by aesop }
510506
exact IsIso.of_iso e.toCommGroupCatIso
511507
set_option linter.uppercaseLean3 false in
512508
#align CommGroup.forget_reflects_isos CommGroupCat.forget_reflects_isos

Mathlib/Algebra/Category/MonCat/Limits.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ noncomputable def limitCone (F : J ⥤ MonCatMax.{u,v}) : Cone F :=
103103
@[to_additive "(Internal use only; use the limits API.)"]
104104
noncomputable def limitConeIsLimit (F : J ⥤ MonCatMax.{u,v}) : IsLimit (limitCone F) := by
105105
refine IsLimit.ofFaithful (forget MonCatMax) (Types.limitConeIsLimit.{v,u} _)
106-
(fun s => ⟨⟨_, ?_⟩, ?_⟩) (fun s => rfl) <;>
106+
(fun s => { toFun := _, map_one' := ?_, map_mul' := ?_ }) (fun s => rfl) <;>
107107
aesop_cat
108108
#align Mon.has_limits.limit_cone_is_limit MonCat.HasLimits.limitConeIsLimit
109109
#align AddMon.has_limits.limit_cone_is_limit AddMonCat.HasLimits.limitConeIsLimit

Mathlib/Algebra/Category/Ring/Limits.lean

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ set_option linter.uppercaseLean3 false in
9999
-/
100100
def limitConeIsLimit (F : J ⥤ SemiRingCatMax.{v, u}) : IsLimit (limitCone F) := by
101101
refine IsLimit.ofFaithful (forget SemiRingCatMax.{v, u}) (Types.limitConeIsLimit.{v, u} _)
102-
(fun s : Cone F => ofHom ⟨⟨⟨_, Subtype.ext <| funext fun j => by exact (s.π.app j).map_one⟩,
103-
fun x y => Subtype.ext <| funext fun j => by exact (s.π.app j).map_mul x y⟩,
104-
Subtype.ext <| funext fun j => by exact (s.π.app j).map_zero,
105-
fun x y => Subtype.ext <| funext fun j => by exact (s.π.app j).map_add x y⟩)
102+
(fun s : Cone F => ofHom
103+
{ toFun := _
104+
map_one' := Subtype.ext <| funext fun j => by exact (s.π.app j).map_one
105+
map_mul' := fun x y => Subtype.ext <| funext fun j => by exact (s.π.app j).map_mul x y
106+
map_zero' := Subtype.ext <| funext fun j => by exact (s.π.app j).map_zero
107+
map_add' := fun x y => Subtype.ext <| funext fun j => by exact (s.π.app j).map_add x y })
106108
fun s => rfl
107109
set_option linter.uppercaseLean3 false in
108110
#align SemiRing.has_limits.limit_cone_is_limit SemiRingCat.HasLimits.limitConeIsLimit
@@ -245,10 +247,12 @@ instance (F : J ⥤ CommSemiRingCatMax.{v, u}) :
245247
refine IsLimit.ofFaithful (forget₂ CommSemiRingCatMax.{v, u} SemiRingCatMax.{v, u})
246248
(SemiRingCat.HasLimits.limitConeIsLimit.{v, u} _)
247249
(fun s : Cone F => CommSemiRingCat.ofHom
248-
⟨⟨⟨_, Subtype.ext <| funext fun j => by exact (s.π.app j).map_one⟩,
249-
fun x y => Subtype.ext <| funext fun j => by exact (s.π.app j).map_mul x y⟩,
250-
Subtype.ext <| funext fun j => by exact (s.π.app j).map_zero,
251-
fun x y => Subtype.ext <| funext fun j => by exact (s.π.app j).map_add x y⟩)
250+
{ toFun := _
251+
map_one' := Subtype.ext <| funext fun j => by exact (s.π.app j).map_one
252+
map_mul' := fun x y => Subtype.ext <| funext fun j => by exact (s.π.app j).map_mul x y
253+
map_zero' := Subtype.ext <| funext fun j => by exact (s.π.app j).map_zero
254+
map_add' := fun x y => Subtype.ext <| funext fun j => by exact (s.π.app j).map_add x y
255+
})
252256
fun s => rfl }
253257

254258
/-- A choice of limit cone for a functor into `CommSemiRingCat`.

Mathlib/Algebra/Free.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ instance : Semigroup (AssocQuotient α) where
373373

374374
/-- Embedding from magma to its free semigroup. -/
375375
@[to_additive "Embedding from additive magma to its free additive semigroup."]
376-
def of : α →ₙ* AssocQuotient α := Quot.mk _, fun _x _y rfl
376+
def of : α →ₙ* AssocQuotient α where toFun := Quot.mk _; map_mul' _x _y := rfl
377377
#align magma.assoc_quotient.of Magma.AssocQuotient.of
378378

379379
@[to_additive]

Mathlib/Algebra/Hom/Units.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ theorem map_id : map (MonoidHom.id M) = MonoidHom.id Mˣ := by ext; rfl
102102

103103
/-- Coercion `Mˣ → M` as a monoid homomorphism. -/
104104
@[to_additive "Coercion `AddUnits M → M` as an AddMonoid homomorphism."]
105-
def coeHom : Mˣ →* M :=
106-
⟨⟨Units.val, val_one⟩, val_mul
105+
def coeHom : Mˣ →* M where
106+
toFun := Units.val; map_one' := val_one; map_mul' := val_mul
107107
#align units.coe_hom Units.coeHom
108108
#align add_units.coe_hom AddUnits.coeHom
109109

Mathlib/Algebra/Lie/Basic.lean

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,30 @@ theorem lie_sub : ⁅x, m - n⁆ = ⁅x, m⁆ - ⁅x, n⁆ := by simp [sub_eq_ad
187187

188188
@[simp]
189189
theorem nsmul_lie (n : ℕ) : ⁅n • x, m⁆ = n • ⁅x, m⁆ :=
190-
AddMonoidHom.map_nsmul ⟨⟨fun x : L => ⁅x, m⁆, zero_lie m⟩, fun _ _ => add_lie _ _ _⟩ _ _
190+
AddMonoidHom.map_nsmul
191+
{ toFun := fun x : L => ⁅x, m⁆, map_zero' := zero_lie m, map_add' := fun _ _ => add_lie _ _ _ }
192+
_ _
191193
#align nsmul_lie nsmul_lie
192194

193195
@[simp]
194196
theorem lie_nsmul (n : ℕ) : ⁅x, n • m⁆ = n • ⁅x, m⁆ :=
195-
AddMonoidHom.map_nsmul ⟨⟨fun m : M => ⁅x, m⁆, lie_zero x⟩, fun _ _ => lie_add _ _ _⟩ _ _
197+
AddMonoidHom.map_nsmul
198+
{ toFun := fun m : M => ⁅x, m⁆, map_zero' := lie_zero x, map_add' := fun _ _ => lie_add _ _ _}
199+
_ _
196200
#align lie_nsmul lie_nsmul
197201

198202
@[simp]
199203
theorem zsmul_lie (a : ℤ) : ⁅a • x, m⁆ = a • ⁅x, m⁆ :=
200-
AddMonoidHom.map_zsmul ⟨⟨fun x : L => ⁅x, m⁆, zero_lie m⟩, fun _ _ => add_lie _ _ _⟩ _ _
204+
AddMonoidHom.map_zsmul
205+
{ toFun := fun x : L => ⁅x, m⁆, map_zero' := zero_lie m, map_add' := fun _ _ => add_lie _ _ _ }
206+
_ _
201207
#align zsmul_lie zsmul_lie
202208

203209
@[simp]
204210
theorem lie_zsmul (a : ℤ) : ⁅x, a • m⁆ = a • ⁅x, m⁆ :=
205-
AddMonoidHom.map_zsmul ⟨⟨fun m : M => ⁅x, m⁆, lie_zero x⟩, fun _ _ => lie_add _ _ _⟩ _ _
211+
AddMonoidHom.map_zsmul
212+
{ toFun := fun m : M => ⁅x, m⁆, map_zero' := lie_zero x, map_add' := fun _ _ => lie_add _ _ _ }
213+
_ _
206214
#align lie_zsmul lie_zsmul
207215

208216
@[simp]
@@ -935,7 +943,9 @@ theorem smul_apply (t : R) (f : M →ₗ⁅R,L⁆ N) (m : M) : (t • f) m = t
935943
#align lie_module_hom.smul_apply LieModuleHom.smul_apply
936944

937945
instance : Module R (M →ₗ⁅R,L⁆ N) :=
938-
Function.Injective.module R ⟨⟨fun f => f.toLinearMap.toFun, rfl⟩, coe_add⟩ coe_injective coe_smul
946+
Function.Injective.module R
947+
{ toFun := fun f => f.toLinearMap.toFun, map_zero' := rfl, map_add' := coe_add }
948+
coe_injective coe_smul
939949

940950
end LieModuleHom
941951

Mathlib/Algebra/Order/AbsoluteValue.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ theorem abv_one' : abv 1 = 1 :=
460460
#align is_absolute_value.abv_one' IsAbsoluteValue.abv_one'
461461

462462
/-- An absolute value as a monoid with zero homomorphism, assuming the target is a semifield. -/
463-
def abvHom' : R →*₀ S :=
464-
⟨⟨abv, abv_zero abv⟩, abv_one' abv, abv_mul abv
463+
def abvHom' : R →*₀ S where
464+
toFun := abv; map_zero' := abv_zero abv; map_one' := abv_one' abv; map_mul' := abv_mul abv
465465
#align is_absolute_value.abv_hom' IsAbsoluteValue.abvHom'
466466

467467
end Semiring

Mathlib/Algebra/Order/Interval.lean

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ namespace NonemptyInterval
305305
@[to_additive]
306306
theorem coe_pow_interval [OrderedCommMonoid α] (s : NonemptyInterval α) (n : ℕ) :
307307
(s ^ n : Interval α) = (s : Interval α) ^ n :=
308-
map_pow (⟨⟨(↑), coe_one_interval⟩, coe_mul_interval⟩ : NonemptyInterval α →* Interval α) _ _
308+
map_pow ({ toFun := (↑), map_one' := coe_one_interval, map_mul' := coe_mul_interval }
309+
: NonemptyInterval α →* Interval α) _ _
309310
#align nonempty_interval.coe_pow_interval NonemptyInterval.coe_pow_interval
310311
#align nonempty_interval.coe_nsmul_interval NonemptyInterval.coe_nsmul_interval
311312

@@ -666,7 +667,8 @@ theorem length_sub : (s - t).length = s.length + t.length := by simp [sub_eq_add
666667
@[simp]
667668
theorem length_sum (f : ι → NonemptyInterval α) (s : Finset ι) :
668669
(∑ i in s, f i).length = ∑ i in s, (f i).length :=
669-
map_sum (⟨⟨length, length_zero⟩, length_add⟩ : NonemptyInterval α →+ α) _ _
670+
map_sum ({ toFun := length, map_zero' := length_zero, map_add' := length_add}
671+
: NonemptyInterval α →+ α) _ _
670672
#align nonempty_interval.length_sum NonemptyInterval.length_sum
671673

672674
end NonemptyInterval

Mathlib/Algebra/Ring/Basic.lean

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ namespace AddHom
3030

3131
/-- Left multiplication by an element of a type with distributive multiplication is an `AddHom`. -/
3232
@[simps (config := { fullyApplied := false })]
33-
def mulLeft [Distrib R] (r : R) : AddHom R R :=
34-
⟨(· * ·) r, mul_add r⟩
33+
def mulLeft [Distrib R] (r : R) : AddHom R R where
34+
toFun := (· * ·) r
35+
map_add' := mul_add r
3536
#align add_hom.mul_left AddHom.mulLeft
3637
#align add_hom.mul_left_apply AddHom.mulLeft_apply
3738

3839
/-- Left multiplication by an element of a type with distributive multiplication is an `AddHom`. -/
3940
@[simps (config := { fullyApplied := false })]
40-
def mulRight [Distrib R] (r : R) : AddHom R R :=
41-
fun a => a * r, fun _ _ => add_mul _ _ r⟩
41+
def mulRight [Distrib R] (r : R) : AddHom R R where
42+
toFun a := a * r
43+
map_add' _ _ := add_mul _ _ r
4244
#align add_hom.mul_right AddHom.mulRight
4345
#align add_hom.mul_right_apply AddHom.mulRight_apply
4446

Mathlib/Data/Finset/Pointwise.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ theorem card_one : (1 : Finset α).card = 1 :=
146146

147147
/-- The singleton operation as a `OneHom`. -/
148148
@[to_additive "The singleton operation as a `ZeroHom`."]
149-
def singletonOneHom : OneHom α (Finset α) :=
150-
singleton, singleton_one
149+
def singletonOneHom : OneHom α (Finset α) where
150+
toFun := singleton; map_one' := singleton_one
151151
#align finset.singleton_one_hom Finset.singletonOneHom
152152
#align finset.singleton_zero_hom Finset.singletonZeroHom
153153

@@ -487,8 +487,8 @@ theorem image_mul : (s * t).image (f : α → β) = s.image f * t.image f :=
487487

488488
/-- The singleton operation as a `MulHom`. -/
489489
@[to_additive "The singleton operation as an `AddHom`."]
490-
def singletonMulHom : α →ₙ* Finset α :=
491-
singleton, fun _ _ => (singleton_mul_singleton _ _).symm
490+
def singletonMulHom : α →ₙ* Finset α where
491+
toFun := singleton; map_mul' _ _ := (singleton_mul_singleton _ _).symm
492492
#align finset.singleton_mul_hom Finset.singletonMulHom
493493
#align finset.singleton_add_hom Finset.singletonAddHom
494494

@@ -1776,13 +1776,13 @@ scoped[Pointwise]
17761776
multiplicative action on `Finset β`. -/
17771777
protected def distribMulActionFinset [Monoid α] [AddMonoid β] [DistribMulAction α β] :
17781778
DistribMulAction α (Finset β) :=
1779-
Function.Injective.distribMulAction ⟨⟨(↑), coe_zero⟩, coe_add⟩ coe_injective coe_smul_finset
1779+
Function.Injective.distribMulAction coeAddMonoidHom coe_injective coe_smul_finset
17801780
#align finset.distrib_mul_action_finset Finset.distribMulActionFinset
17811781

17821782
/-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `Set β`. -/
17831783
protected def mulDistribMulActionFinset [Monoid α] [Monoid β] [MulDistribMulAction α β] :
17841784
MulDistribMulAction α (Finset β) :=
1785-
Function.Injective.mulDistribMulAction ⟨⟨(↑), coe_one⟩, coe_mul⟩ coe_injective coe_smul_finset
1785+
Function.Injective.mulDistribMulAction coeMonoidHom coe_injective coe_smul_finset
17861786
#align finset.mul_distrib_mul_action_finset Finset.mulDistribMulActionFinset
17871787

17881788
scoped[Pointwise]

0 commit comments

Comments
 (0)