Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit c10efa6

Browse files
committed
refactor(algebra/hom/group): generalize basic API of monoid_hom to monoid_hom_class (#14997)
This PR generalizes part of the basic API of monoid homs to monoid_hom_class. This notably includes things like monoid_hom.mker, submonoid.map and submonoid.comap. I left the namespaces unchanged, for example `monoid_hom.mker` remains the same even though it is now defined for any `monoid_hom_class` morphism; this way dot notation still (mostly) works for actual monoid homs.
1 parent eb85260 commit c10efa6

File tree

12 files changed

+110
-82
lines changed

12 files changed

+110
-82
lines changed

src/algebra/algebra/operations.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ theorem mul_le : M * N ≤ P ↔ ∀ (m ∈ M) (n ∈ N), m * n ∈ P := map₂_
103103
lemma mul_to_add_submonoid : (M * N).to_add_submonoid = M.to_add_submonoid * N.to_add_submonoid :=
104104
begin
105105
dsimp [has_mul.mul],
106-
simp_rw [←algebra.lmul_left_to_add_monoid_hom R, algebra.lmul_left, ←map_to_add_submonoid, map₂],
106+
simp_rw [←algebra.lmul_left_to_add_monoid_hom R, algebra.lmul_left, ←map_to_add_submonoid _ N,
107+
map₂],
107108
rw supr_to_add_submonoid,
108109
refl,
109110
end

src/algebra/hom/group.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ instance : monoid (monoid.End M) :=
919919

920920
instance : inhabited (monoid.End M) := ⟨1
921921

922-
instance : has_coe_to_fun (monoid.End M) (λ _, M → M) := monoid_hom.to_fun⟩
922+
instance : monoid_hom_class (monoid.End M) M M := monoid_hom.monoid_hom_class
923923

924924
end End
925925

@@ -946,7 +946,7 @@ instance : monoid (add_monoid.End A) :=
946946

947947
instance : inhabited (add_monoid.End A) := ⟨1
948948

949-
instance : has_coe_to_fun (add_monoid.End A) (λ _, A → A) := add_monoid_hom.to_fun⟩
949+
instance : add_monoid_hom_class (add_monoid.End A) A A := add_monoid_hom.add_monoid_hom_class
950950

951951
end End
952952

src/group_theory/subgroup/basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@ the `add_subgroup` generated by the image of the set."]
21812181
lemma map_closure (f : G →* N) (s : set G) :
21822182
(closure s).map f = closure (f '' s) :=
21832183
set.image_preimage.l_comm_of_u_comm
2184-
(gc_map_comap f) (subgroup.gi N).gc (subgroup.gi G).gc (λ t, rfl)
2184+
(subgroup.gc_map_comap f) (subgroup.gi N).gc (subgroup.gi G).gc (λ t, rfl)
21852185

21862186
-- this instance can't go just after the definition of `mrange` because `fintype` is
21872187
-- not imported at that stage

src/group_theory/submonoid/membership.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ lemma log_mul [decidable_eq M] {n : M} (h : function.injective (λ m : ℕ, n ^
376376
theorem log_pow_int_eq_self {x : ℤ} (h : 1 < x.nat_abs) (m : ℕ) : log (pow x m) = m :=
377377
(pow_log_equiv (int.pow_right_injective h)).symm_apply_apply _
378378

379-
@[simp] lemma map_powers {N : Type*} [monoid N] (f : M →* N) (m : M) :
380-
(powers m).map f = powers (f m) :=
381-
by simp only [powers_eq_closure, f.map_mclosure, set.image_singleton]
379+
@[simp] lemma map_powers {N : Type*} {F : Type*} [monoid N] [monoid_hom_class F M N]
380+
(f : F) (m : M) : (powers m).map f = powers (f m) :=
381+
by simp only [powers_eq_closure, map_mclosure f, set.image_singleton]
382382

383383
/-- If all the elements of a set `s` commute, then `closure s` is a commutative monoid. -/
384384
@[to_additive "If all the elements of a set `s` commute, then `closure s` forms an additive

src/group_theory/submonoid/operations.lean

Lines changed: 74 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -145,143 +145,150 @@ le_antisymm
145145
end
146146

147147
namespace submonoid
148+
variables {F : Type*} [mc : monoid_hom_class F M N]
148149

149150
open set
150151

151152
/-!
152153
### `comap` and `map`
153154
-/
154155

156+
include mc
155157
/-- The preimage of a submonoid along a monoid homomorphism is a submonoid. -/
156158
@[to_additive "The preimage of an `add_submonoid` along an `add_monoid` homomorphism is an
157159
`add_submonoid`."]
158-
def comap (f : M →* N) (S : submonoid N) : submonoid M :=
160+
def comap (f : F) (S : submonoid N) : submonoid M :=
159161
{ carrier := (f ⁻¹' S),
160-
one_mem' := show f 1 ∈ S, by rw f.map_one; exact S.one_mem,
162+
one_mem' := show f 1 ∈ S, by rw map_one; exact S.one_mem,
161163
mul_mem' := λ a b ha hb,
162-
show f (a * b) ∈ S, by rw f.map_mul; exact S.mul_mem ha hb }
164+
show f (a * b) ∈ S, by rw map_mul; exact S.mul_mem ha hb }
163165

164166
@[simp, to_additive]
165-
lemma coe_comap (S : submonoid N) (f : M →* N) : (S.comap f : set M) = f ⁻¹' S := rfl
167+
lemma coe_comap (S : submonoid N) (f : F) : (S.comap f : set M) = f ⁻¹' S := rfl
166168

167169
@[simp, to_additive]
168-
lemma mem_comap {S : submonoid N} {f : M →* N} {x : M} : x ∈ S.comap f ↔ f x ∈ S := iff.rfl
170+
lemma mem_comap {S : submonoid N} {f : F} {x : M} : x ∈ S.comap f ↔ f x ∈ S := iff.rfl
171+
omit mc
169172

170173
@[to_additive]
171174
lemma comap_comap (S : submonoid P) (g : N →* P) (f : M →* N) :
172175
(S.comap g).comap f = S.comap (g.comp f) :=
173176
rfl
174177

175178
@[simp, to_additive]
176-
lemma comap_id (S : submonoid P) : S.comap (monoid_hom.id _) = S :=
179+
lemma comap_id (S : submonoid P) : S.comap (monoid_hom.id P) = S :=
177180
ext (by simp)
178181

182+
include mc
179183
/-- The image of a submonoid along a monoid homomorphism is a submonoid. -/
180184
@[to_additive "The image of an `add_submonoid` along an `add_monoid` homomorphism is
181185
an `add_submonoid`."]
182-
def map (f : M →* N) (S : submonoid M) : submonoid N :=
186+
def map (f : F) (S : submonoid M) : submonoid N :=
183187
{ carrier := (f '' S),
184-
one_mem' := ⟨1, S.one_mem, f.map_one⟩,
188+
one_mem' := ⟨1, S.one_mem, map_one f⟩,
185189
mul_mem' := begin rintros _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩, exact ⟨x * y, S.mul_mem hx hy,
186-
by rw f.map_mul; refl⟩ end }
190+
by rw map_mul; refl⟩ end }
187191

188192
@[simp, to_additive]
189-
lemma coe_map (f : M →* N) (S : submonoid M) :
193+
lemma coe_map (f : F) (S : submonoid M) :
190194
(S.map f : set N) = f '' S := rfl
191195

192196
@[simp, to_additive]
193-
lemma mem_map {f : M →* N} {S : submonoid M} {y : N} :
197+
lemma mem_map {f : F} {S : submonoid M} {y : N} :
194198
y ∈ S.map f ↔ ∃ x ∈ S, f x = y :=
195199
mem_image_iff_bex
196200

197201
@[to_additive]
198-
lemma mem_map_of_mem (f : M →* N) {S : submonoid M} {x : M} (hx : x ∈ S) : f x ∈ S.map f :=
202+
lemma mem_map_of_mem (f : F) {S : submonoid M} {x : M} (hx : x ∈ S) : f x ∈ S.map f :=
199203
mem_image_of_mem f hx
200204

201205
@[to_additive]
202-
lemma apply_coe_mem_map (f : M →* N) (S : submonoid M) (x : S) : f x ∈ S.map f :=
206+
lemma apply_coe_mem_map (f : F) (S : submonoid M) (x : S) : f x ∈ S.map f :=
203207
mem_map_of_mem f x.prop
208+
omit mc
204209

205210
@[to_additive]
206211
lemma map_map (g : N →* P) (f : M →* N) : (S.map f).map g = S.map (g.comp f) :=
207212
set_like.coe_injective $ image_image _ _ _
208213

214+
include mc
209215
@[to_additive]
210-
lemma mem_map_iff_mem {f : M →* N} (hf : function.injective f) {S : submonoid M} {x : M} :
216+
lemma mem_map_iff_mem {f : F} (hf : function.injective f) {S : submonoid M} {x : M} :
211217
f x ∈ S.map f ↔ x ∈ S :=
212218
hf.mem_set_image
213219

214220
@[to_additive]
215-
lemma map_le_iff_le_comap {f : M →* N} {S : submonoid M} {T : submonoid N} :
221+
lemma map_le_iff_le_comap {f : F} {S : submonoid M} {T : submonoid N} :
216222
S.map f ≤ T ↔ S ≤ T.comap f :=
217223
image_subset_iff
218224

219225
@[to_additive]
220-
lemma gc_map_comap (f : M →* N) : galois_connection (map f) (comap f) :=
226+
lemma gc_map_comap (f : F) : galois_connection (map f) (comap f) :=
221227
λ S T, map_le_iff_le_comap
222228

223229
@[to_additive]
224-
lemma map_le_of_le_comap {T : submonoid N} {f : M →* N} : S ≤ T.comap f → S.map f ≤ T :=
230+
lemma map_le_of_le_comap {T : submonoid N} {f : F} : S ≤ T.comap f → S.map f ≤ T :=
225231
(gc_map_comap f).l_le
226232

227233
@[to_additive]
228-
lemma le_comap_of_map_le {T : submonoid N} {f : M →* N} : S.map f ≤ T → S ≤ T.comap f :=
234+
lemma le_comap_of_map_le {T : submonoid N} {f : F} : S.map f ≤ T → S ≤ T.comap f :=
229235
(gc_map_comap f).le_u
230236

231237
@[to_additive]
232-
lemma le_comap_map {f : M →* N} : S ≤ (S.map f).comap f :=
238+
lemma le_comap_map {f : F} : S ≤ (S.map f).comap f :=
233239
(gc_map_comap f).le_u_l _
234240

235241
@[to_additive]
236-
lemma map_comap_le {S : submonoid N} {f : M →* N} : (S.comap f).map f ≤ S :=
242+
lemma map_comap_le {S : submonoid N} {f : F} : (S.comap f).map f ≤ S :=
237243
(gc_map_comap f).l_u_le _
238244

239245
@[to_additive]
240-
lemma monotone_map {f : M →* N} : monotone (map f) :=
246+
lemma monotone_map {f : F} : monotone (map f) :=
241247
(gc_map_comap f).monotone_l
242248

243249
@[to_additive]
244-
lemma monotone_comap {f : M →* N} : monotone (comap f) :=
250+
lemma monotone_comap {f : F} : monotone (comap f) :=
245251
(gc_map_comap f).monotone_u
246252

247253
@[simp, to_additive]
248-
lemma map_comap_map {f : M →* N} : ((S.map f).comap f).map f = S.map f :=
254+
lemma map_comap_map {f : F} : ((S.map f).comap f).map f = S.map f :=
249255
(gc_map_comap f).l_u_l_eq_l _
250256

251257
@[simp, to_additive]
252-
lemma comap_map_comap {S : submonoid N} {f : M →* N} : ((S.comap f).map f).comap f = S.comap f :=
258+
lemma comap_map_comap {S : submonoid N} {f : F} : ((S.comap f).map f).comap f = S.comap f :=
253259
(gc_map_comap f).u_l_u_eq_u _
254260

255261
@[to_additive]
256-
lemma map_sup (S T : submonoid M) (f : M →* N) : (S ⊔ T).map f = S.map f ⊔ T.map f :=
257-
(gc_map_comap f).l_sup
262+
lemma map_sup (S T : submonoid M) (f : F) : (S ⊔ T).map f = S.map f ⊔ T.map f :=
263+
(gc_map_comap f : galois_connection (map f) (comap f)).l_sup
258264

259265
@[to_additive]
260-
lemma map_supr {ι : Sort*} (f : M →* N) (s : ι → submonoid M) :
266+
lemma map_supr {ι : Sort*} (f : F) (s : ι → submonoid M) :
261267
(supr s).map f = ⨆ i, (s i).map f :=
262-
(gc_map_comap f).l_supr
268+
(gc_map_comap f : galois_connection (map f) (comap f)).l_supr
263269

264270
@[to_additive]
265-
lemma comap_inf (S T : submonoid N) (f : M →* N) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f :=
266-
(gc_map_comap f).u_inf
271+
lemma comap_inf (S T : submonoid N) (f : F) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f :=
272+
(gc_map_comap f : galois_connection (map f) (comap f)).u_inf
267273

268274
@[to_additive]
269-
lemma comap_infi {ι : Sort*} (f : M →* N) (s : ι → submonoid N) :
275+
lemma comap_infi {ι : Sort*} (f : F) (s : ι → submonoid N) :
270276
(infi s).comap f = ⨅ i, (s i).comap f :=
271-
(gc_map_comap f).u_infi
277+
(gc_map_comap f : galois_connection (map f) (comap f)).u_infi
272278

273-
@[simp, to_additive] lemma map_bot (f : M →* N) : (⊥ : submonoid M).map f = ⊥ :=
279+
@[simp, to_additive] lemma map_bot (f : F) : (⊥ : submonoid M).map f = ⊥ :=
274280
(gc_map_comap f).l_bot
275281

276-
@[simp, to_additive] lemma comap_top (f : M →* N) : (⊤ : submonoid N).comap f = ⊤ :=
282+
@[simp, to_additive] lemma comap_top (f : F) : (⊤ : submonoid N).comap f = ⊤ :=
277283
(gc_map_comap f).u_top
284+
omit mc
278285

279286
@[simp, to_additive] lemma map_id (S : submonoid M) : S.map (monoid_hom.id M) = S :=
280287
ext (λ x, ⟨λ ⟨_, h, rfl⟩, h, λ h, ⟨_, h, rfl⟩⟩)
281288

282289
section galois_coinsertion
283290

284-
variables {ι : Type*} {f : M →* N} (hf : function.injective f)
291+
variables {ι : Type*} {f : F} (hf : function.injective f)
285292

286293
include hf
287294

@@ -331,7 +338,7 @@ end galois_coinsertion
331338

332339
section galois_insertion
333340

334-
variables {ι : Type*} {f : M →* N} (hf : function.surjective f)
341+
variables {ι : Type*} {f : F} (hf : function.surjective f)
335342

336343
include hf
337344

@@ -720,6 +727,7 @@ end
720727
end submonoid
721728

722729
namespace monoid_hom
730+
variables {F : Type*} [mc : monoid_hom_class F M N]
723731

724732
open submonoid
725733

@@ -754,53 +762,57 @@ def mrange (f : M →* N) : submonoid N :=
754762
-/
755763
library_note "range copy pattern"
756764

765+
include mc
757766
/-- The range of a monoid homomorphism is a submonoid. See Note [range copy pattern]. -/
758767
@[to_additive "The range of an `add_monoid_hom` is an `add_submonoid`."]
759-
def mrange (f : M →* N) : submonoid N :=
768+
def mrange (f : F) : submonoid N :=
760769
((⊤ : submonoid M).map f).copy (set.range f) set.image_univ.symm
761770

762771
@[simp, to_additive]
763-
lemma coe_mrange (f : M →* N) :
764-
(f.mrange : set N) = set.range f :=
772+
lemma coe_mrange (f : F) :
773+
(mrange f : set N) = set.range f :=
765774
rfl
766775

767-
@[simp, to_additive] lemma mem_mrange {f : M →* N} {y : N} :
768-
y ∈ f.mrange ↔ ∃ x, f x = y :=
776+
@[simp, to_additive] lemma mem_mrange {f : F} {y : N} :
777+
y ∈ mrange f ↔ ∃ x, f x = y :=
769778
iff.rfl
770779

771-
@[to_additive] lemma mrange_eq_map (f : M →* N) : f.mrange = (⊤ : submonoid M).map f :=
780+
@[to_additive] lemma mrange_eq_map (f : F) : mrange f = (⊤ : submonoid M).map f :=
772781
copy_eq _
782+
omit mc
773783

774784
@[to_additive]
775785
lemma map_mrange (g : N →* P) (f : M →* N) : f.mrange.map g = (g.comp f).mrange :=
776786
by simpa only [mrange_eq_map] using (⊤ : submonoid M).map_map g f
777787

788+
include mc
778789
@[to_additive]
779-
lemma mrange_top_iff_surjective {N} [mul_one_class N] {f : M →* N} :
780-
f.mrange = (⊤ : submonoid N) ↔ function.surjective f :=
790+
lemma mrange_top_iff_surjective {f : F} :
791+
mrange f = (⊤ : submonoid N) ↔ function.surjective f :=
781792
set_like.ext'_iff.trans $ iff.trans (by rw [coe_mrange, coe_top]) set.range_iff_surjective
782793

783794
/-- The range of a surjective monoid hom is the whole of the codomain. -/
784795
@[to_additive "The range of a surjective `add_monoid` hom is the whole of the codomain."]
785-
lemma mrange_top_of_surjective {N} [mul_one_class N] (f : M →* N) (hf : function.surjective f) :
786-
f.mrange = (⊤ : submonoid N) :=
796+
lemma mrange_top_of_surjective (f : F) (hf : function.surjective f) :
797+
mrange f = (⊤ : submonoid N) :=
787798
mrange_top_iff_surjective.2 hf
788799

789800
@[to_additive]
790-
lemma mclosure_preimage_le (f : M →* N) (s : set N) :
801+
lemma mclosure_preimage_le (f : F) (s : set N) :
791802
closure (f ⁻¹' s) ≤ (closure s).comap f :=
792803
closure_le.2 $ λ x hx, set_like.mem_coe.2 $ mem_comap.2 $ subset_closure hx
793804

794805
/-- The image under a monoid hom of the submonoid generated by a set equals the submonoid generated
795806
by the image of the set. -/
796807
@[to_additive "The image under an `add_monoid` hom of the `add_submonoid` generated by a set equals
797808
the `add_submonoid` generated by the image of the set."]
798-
lemma map_mclosure (f : M →* N) (s : set M) :
809+
lemma map_mclosure (f : F) (s : set M) :
799810
(closure s).map f = closure (f '' s) :=
800811
le_antisymm
801812
(map_le_iff_le_comap.2 $ le_trans (closure_mono $ set.subset_preimage_image _ _)
802813
(mclosure_preimage_le _ _))
803814
(closure_le.2 $ set.image_subset _ subset_closure)
815+
omit mc
804816

805817
/-- Restriction of a monoid hom to a submonoid of the domain. -/
806818
@[to_additive "Restriction of an add_monoid hom to an `add_submonoid` of the domain."]
@@ -836,28 +848,32 @@ rfl
836848
lemma mrange_restrict_surjective (f : M →* N) : function.surjective f.mrange_restrict :=
837849
λ ⟨_, ⟨x, rfl⟩⟩, ⟨x, rfl⟩
838850

851+
include mc
839852
/-- The multiplicative kernel of a monoid homomorphism is the submonoid of elements `x : G` such
840853
that `f x = 1` -/
841854
@[to_additive "The additive kernel of an `add_monoid` homomorphism is the `add_submonoid` of
842855
elements such that `f x = 0`"]
843-
def mker (f : M →* N) : submonoid M := (⊥ : submonoid N).comap f
856+
def mker (f : F) : submonoid M := (⊥ : submonoid N).comap f
844857

845858
@[to_additive]
846-
lemma mem_mker (f : M →* N) {x : M} : x ∈ f.mker ↔ f x = 1 := iff.rfl
859+
lemma mem_mker (f : F) {x : M} : x ∈ mker f ↔ f x = 1 := iff.rfl
847860

848861
@[to_additive]
849-
lemma coe_mker (f : M →* N) : (f.mker : set M) = (f : M → N) ⁻¹' {1} := rfl
862+
lemma coe_mker (f : F) : (mker f : set M) = (f : M → N) ⁻¹' {1} := rfl
850863

851864
@[to_additive]
852-
instance decidable_mem_mker [decidable_eq N] (f : M →* N) :
853-
decidable_pred (∈ f.mker) :=
854-
λ x, decidable_of_iff (f x = 1) f.mem_mker
865+
instance decidable_mem_mker [decidable_eq N] (f : F) :
866+
decidable_pred (∈ mker f) :=
867+
λ x, decidable_of_iff (f x = 1) (mem_mker f)
868+
omit mc
855869

856870
@[to_additive]
857871
lemma comap_mker (g : N →* P) (f : M →* N) : g.mker.comap f = (g.comp f).mker := rfl
858872

859-
@[simp, to_additive] lemma comap_bot' (f : M →* N) :
860-
(⊥ : submonoid N).comap f = f.mker := rfl
873+
include mc
874+
@[simp, to_additive] lemma comap_bot' (f : F) :
875+
(⊥ : submonoid N).comap f = mker f := rfl
876+
omit mc
861877

862878
@[to_additive] lemma range_restrict_mker (f : M →* N) : mker (mrange_restrict f) = mker f :=
863879
begin
@@ -931,11 +947,11 @@ lemma mrange_inr' : (inr M N).mrange = comap (fst M N) ⊥ := mrange_inr.trans (
931947

932948
@[simp, to_additive]
933949
lemma mrange_fst : (fst M N).mrange = ⊤ :=
934-
(fst M N).mrange_top_of_surjective $ @prod.fst_surjective _ _ ⟨1
950+
mrange_top_of_surjective (fst M N) $ @prod.fst_surjective _ _ ⟨1
935951

936952
@[simp, to_additive]
937953
lemma mrange_snd : (snd M N).mrange = ⊤ :=
938-
(snd M N).mrange_top_of_surjective $ @prod.snd_surjective _ _ ⟨1
954+
mrange_top_of_surjective (snd M N) $ @prod.snd_surjective _ _ ⟨1
939955

940956
@[to_additive]
941957
lemma prod_eq_bot_iff {s : submonoid M} {t : submonoid N} :

0 commit comments

Comments
 (0)