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

Commit 3d24b09

Browse files
committed
feat(algebra/ring/basic): define non-unital ring homs (#13430)
This defines a new bundled hom type and associated class for non-unital (even non-associative) (semi)rings. The associated notation introduced for these homs is `α →ₙ+* β` to parallel the `ring_hom` notation `α →+* β`, where `ₙ` stands for "non-unital".
1 parent 394dec3 commit 3d24b09

File tree

1 file changed

+203
-1
lines changed

1 file changed

+203
-1
lines changed

src/algebra/ring/basic.lean

Lines changed: 203 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Neil Strickland
66
-/
77
import algebra.divisibility
88
import algebra.regular.basic
9+
import data.pi
910

1011
/-!
1112
# Properties and homomorphisms of semirings and rings
@@ -23,7 +24,8 @@ ring_hom, nonzero, domain, is_domain
2324
2425
## Notations
2526
26-
→+* for bundled ring homs (also use for semiring homs)
27+
* `→+*` for bundled ring homs (also use for semiring homs)
28+
* `→ₙ+*` for bundled non-unital ring homs (also use for non-unital semiring homs)
2729
2830
## Implementation notes
2931
@@ -335,6 +337,202 @@ lemma mul_right_apply {R : Type*} [non_unital_non_assoc_semiring R] (a r : R) :
335337

336338
end add_monoid_hom
337339

340+
/-- Bundled non-unital semiring homomorphisms `R →ₙ+* S`; use this for bundled non-unital ring
341+
homomorphisms too.
342+
343+
When possible, instead of parametrizing results over `(f : R →ₙ+* S)`,
344+
you should parametrize over `(F : Type*) [non_unital_ring_hom_class F R S] (f : F)`.
345+
346+
When you extend this structure, make sure to extend `non_unital_ring_hom_class`. -/
347+
structure non_unital_ring_hom (R : Type*) (S : Type*) [non_unital_non_assoc_semiring R]
348+
[non_unital_non_assoc_semiring S] extends R →ₙ* S, R →+ S
349+
350+
infixr ` →ₙ+* `:25 := non_unital_ring_hom
351+
352+
/-- Reinterpret a non-unital ring homomorphism `f : R →ₙ+* S` as a semigroup
353+
homomorphism `R →ₙ* S`. The `simp`-normal form is `(f : R →ₙ* S)`. -/
354+
add_decl_doc non_unital_ring_hom.to_mul_hom
355+
356+
/-- Reinterpret a non-unital ring homomorphism `f : R →ₙ+* S` as an additive
357+
monoid homomorphism `R →+ S`. The `simp`-normal form is `(f : R →+ S)`. -/
358+
add_decl_doc non_unital_ring_hom.to_add_monoid_hom
359+
360+
section non_unital_ring_hom_class
361+
362+
/-- `non_unital_ring_hom_class F R S` states that `F` is a type of non-unital (semi)ring
363+
homomorphisms. You should extend this class when you extend `non_unital_ring_hom`. -/
364+
class non_unital_ring_hom_class (F : Type*) (R S : out_param Type*)
365+
[non_unital_non_assoc_semiring R] [non_unital_non_assoc_semiring S]
366+
extends mul_hom_class F R S, add_monoid_hom_class F R S
367+
368+
variables {F : Type*} [non_unital_non_assoc_semiring α] [non_unital_non_assoc_semiring β]
369+
[non_unital_ring_hom_class F α β]
370+
371+
instance : has_coe_t F (α →ₙ+* β) :=
372+
⟨λ f, { to_fun := f, map_zero' := map_zero f, map_mul' := map_mul f, map_add' := map_add f }⟩
373+
374+
end non_unital_ring_hom_class
375+
376+
namespace non_unital_ring_hom
377+
378+
section coe
379+
380+
/-!
381+
Throughout this section, some `semiring` arguments are specified with `{}` instead of `[]`.
382+
See note [implicit instance arguments].
383+
-/
384+
variables {rα : non_unital_non_assoc_semiring α} {rβ : non_unital_non_assoc_semiring β}
385+
386+
include rα rβ
387+
388+
instance : non_unital_ring_hom_class (α →ₙ+* β) α β :=
389+
{ coe := non_unital_ring_hom.to_fun,
390+
coe_injective' := λ f g h, by cases f; cases g; congr',
391+
map_add := non_unital_ring_hom.map_add',
392+
map_zero := non_unital_ring_hom.map_zero',
393+
map_mul := non_unital_ring_hom.map_mul' }
394+
395+
/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`
396+
directly.
397+
-/
398+
instance : has_coe_to_fun (α →ₙ+* β) (λ _, α → β) := ⟨non_unital_ring_hom.to_fun⟩
399+
400+
@[simp] lemma to_fun_eq_coe (f : α →ₙ+* β) : f.to_fun = f := rfl
401+
402+
@[simp] lemma coe_mk (f : α → β) (h₁ h₂ h₃) : ⇑(⟨f, h₁, h₂, h₃⟩ : α →ₙ+* β) = f := rfl
403+
404+
@[simp] lemma coe_coe {F : Type*} [non_unital_ring_hom_class F α β] (f : F) :
405+
((f : α →ₙ+* β) : α → β) = f := rfl
406+
407+
@[simp] lemma coe_to_mul_hom (f : α →ₙ+* β) : ⇑f.to_mul_hom = f := rfl
408+
409+
@[simp] lemma coe_mul_hom_mk (f : α → β) (h₁ h₂ h₃) :
410+
((⟨f, h₁, h₂, h₃⟩ : α →ₙ+* β) : α →ₙ* β) = ⟨f, h₁⟩ :=
411+
rfl
412+
413+
@[simp] lemma coe_to_add_monoid_hom (f : α →ₙ+* β) : ⇑f.to_add_monoid_hom = f := rfl
414+
415+
@[simp] lemma coe_add_monoid_hom_mk (f : α → β) (h₁ h₂ h₃) :
416+
((⟨f, h₁, h₂, h₃⟩ : α →ₙ+* β) : α →+ β) = ⟨f, h₂, h₃⟩ :=
417+
rfl
418+
419+
/-- Copy of a `ring_hom` with a new `to_fun` equal to the old one. Useful to fix definitional
420+
equalities. -/
421+
protected def copy (f : α →ₙ+* β) (f' : α → β) (h : f' = f) : α →ₙ+* β :=
422+
{ ..f.to_mul_hom.copy f' h, ..f.to_add_monoid_hom.copy f' h }
423+
424+
end coe
425+
426+
variables [rα : non_unital_non_assoc_semiring α] [rβ : non_unital_non_assoc_semiring β]
427+
428+
section
429+
include rα rβ
430+
431+
variables (f : α →ₙ+* β) {x y : α} {rα rβ}
432+
433+
@[ext] theorem ext ⦃f g : α →ₙ+* β⦄ (h : ∀ x, f x = g x) : f = g :=
434+
fun_like.ext _ _ h
435+
436+
theorem ext_iff {f g : α →ₙ+* β} : f = g ↔ ∀ x, f x = g x :=
437+
fun_like.ext_iff
438+
439+
@[simp] lemma mk_coe (f : α →ₙ+* β) (h₁ h₂ h₃) : non_unital_ring_hom.mk f h₁ h₂ h₃ = f :=
440+
ext $ λ _, rfl
441+
442+
theorem coe_add_monoid_hom_injective : function.injective (coe : (α →ₙ+* β) → (α →+ β)) :=
443+
λ f g h, ext (λ x, add_monoid_hom.congr_fun h x)
444+
445+
theorem coe_mul_hom_injective : function.injective (coe : (α →ₙ+* β) → (α →ₙ* β)) :=
446+
λ f g h, ext (λ x, mul_hom.congr_fun h x)
447+
448+
end
449+
450+
/-- The identity non-unital ring homomorphism from a non-unital semiring to itself. -/
451+
protected def id (α : Type*) [non_unital_non_assoc_semiring α] : α →ₙ+* α :=
452+
by refine {to_fun := id, ..}; intros; refl
453+
454+
include rα rβ
455+
456+
instance : has_zero (α →ₙ+* β) :=
457+
has_zero.mk
458+
{ to_fun := 0,
459+
map_mul' := λ x y, (mul_zero (0 : β)).symm,
460+
map_zero' := rfl,
461+
map_add' := λ x y, (add_zero (0 : β)).symm }
462+
463+
instance : inhabited (α →ₙ+* β) := ⟨0
464+
465+
@[simp] lemma coe_zero : ⇑(0 : α →ₙ+* β) = 0 := rfl
466+
@[simp] lemma zero_apply (x : α) : (0 : α →ₙ+* β) x = 0 := rfl
467+
468+
omit
469+
470+
@[simp] lemma id_apply (x : α) : non_unital_ring_hom.id α x = x := rfl
471+
@[simp] lemma coe_add_monoid_hom_id :
472+
(non_unital_ring_hom.id α : α →+ α) = add_monoid_hom.id α := rfl
473+
@[simp] lemma coe_mul_hom_id : (non_unital_ring_hom.id α : α →ₙ* α) = mul_hom.id α := rfl
474+
475+
variable {rγ : non_unital_non_assoc_semiring γ}
476+
include rβ rγ
477+
478+
/-- Composition of non-unital ring homomorphisms is a non-unital ring homomorphism. -/
479+
def comp (g : β →ₙ+* γ) (f : α →ₙ+* β) : α →ₙ+* γ :=
480+
{ ..g.to_mul_hom.comp f.to_mul_hom, ..g.to_add_monoid_hom.comp f.to_add_monoid_hom }
481+
482+
/-- Composition of non-unital ring homomorphisms is associative. -/
483+
lemma comp_assoc {δ} {rδ : non_unital_non_assoc_semiring δ} (f : α →ₙ+* β) (g : β →ₙ+* γ)
484+
(h : γ →ₙ+* δ) : (h.comp g).comp f = h.comp (g.comp f) := rfl
485+
486+
@[simp] lemma coe_comp (g : β →ₙ+* γ) (f : α →ₙ+* β) : ⇑(g.comp f) = g ∘ f := rfl
487+
@[simp] lemma comp_apply (g : β →ₙ+* γ) (f : α →ₙ+* β) (x : α) : g.comp f x = g (f x) := rfl
488+
489+
@[simp] lemma coe_comp_add_monoid_hom (g : β →ₙ+* γ) (f : α →ₙ+* β) :
490+
(g.comp f : α →+ γ) = (g : β →+ γ).comp f := rfl
491+
@[simp] lemma coe_comp_mul_hom (g : β →ₙ+* γ) (f : α →ₙ+* β) :
492+
(g.comp f : α →ₙ* γ) = (g : β →ₙ* γ).comp f := rfl
493+
494+
@[simp] lemma comp_zero (g : β →ₙ+* γ) : g.comp (0 : α →ₙ+* β) = 0 := by { ext, simp }
495+
@[simp] lemma zero_comp (f : α →ₙ+* β) : (0 : β →ₙ+* γ).comp f = 0 := by { ext, refl }
496+
497+
omit
498+
499+
@[simp] lemma comp_id (f : α →ₙ+* β) : f.comp (non_unital_ring_hom.id α) = f := ext $ λ x, rfl
500+
@[simp] lemma id_comp (f : α →ₙ+* β) : (non_unital_ring_hom.id β).comp f = f := ext $ λ x, rfl
501+
502+
omit
503+
504+
instance : monoid_with_zero (α →ₙ+* α) :=
505+
{ one := non_unital_ring_hom.id α,
506+
mul := comp,
507+
mul_one := comp_id,
508+
one_mul := id_comp,
509+
mul_assoc := λ f g h, comp_assoc _ _ _,
510+
zero := 0,
511+
mul_zero := comp_zero,
512+
zero_mul := zero_comp }
513+
514+
lemma one_def : (1 : α →ₙ+* α) = non_unital_ring_hom.id α := rfl
515+
516+
@[simp] lemma coe_one : ⇑(1 : α →ₙ+* α) = id := rfl
517+
518+
lemma mul_def (f g : α →ₙ+* α) : f * g = f.comp g := rfl
519+
520+
@[simp] lemma coe_mul (f g : α →ₙ+* α) : ⇑(f * g) = f ∘ g := rfl
521+
522+
include rβ rγ
523+
524+
lemma cancel_right {g₁ g₂ : β →ₙ+* γ} {f : α →ₙ+* β} (hf : surjective f) :
525+
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
526+
⟨λ h, ext $ hf.forall.2 (ext_iff.1 h), λ h, h ▸ rfl⟩
527+
528+
lemma cancel_left {g : β →ₙ+* γ} {f₁ f₂ : α →ₙ+* β} (hg : injective g) :
529+
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
530+
⟨λ h, ext $ λ x, hg $ by rw [← comp_apply, h, comp_apply], λ h, h ▸ rfl⟩
531+
532+
omit rα rβ rγ
533+
534+
end non_unital_ring_hom
535+
338536
/-- Bundled semiring homomorphisms; use this for bundled ring homomorphisms too.
339537
340538
This extends from both `monoid_hom` and `monoid_with_zero_hom` in order to put the fields in a
@@ -382,6 +580,10 @@ instance : has_coe_t F (α →+* β) :=
382580
⟨λ f, { to_fun := f, map_zero' := map_zero f, map_one' := map_one f, map_mul' := map_mul f,
383581
map_add' := map_add f }⟩
384582

583+
@[priority 100]
584+
instance ring_hom_class.to_non_unital_ring_hom_class : non_unital_ring_hom_class F α β :=
585+
{ .. ‹ring_hom_class F α β› }
586+
385587
end ring_hom_class
386588

387589
namespace ring_hom

0 commit comments

Comments
 (0)