source stringlengths 17 118 | lean4 stringlengths 0 335k |
|---|---|
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/AB.lean | import Mathlib.Algebra.Category.Grp.AB
import Mathlib.Algebra.Category.ModuleCat.Colimits
import Mathlib.Algebra.Module.Shrink
import Mathlib.CategoryTheory.Abelian.GrothendieckCategory.Basic
/-!
# AB axioms in module categories
This file proves that the category of modules over a ring satisfies Grothendieck's axioms AB5, AB4,
and AB4*. Further, it proves that `R` is a separator in the category of modules over `R`, and
concludes that this category is Grothendieck abelian.
-/
universe u v
open CategoryTheory Limits
variable (R : Type u) [Ring R]
instance : AB5 (ModuleCat.{u} R) where
ofShape J _ _ :=
HasExactColimitsOfShape.domain_of_functor J (forget₂ (ModuleCat R) AddCommGrpCat)
attribute [local instance] Abelian.hasFiniteBiproducts
instance : AB4 (ModuleCat.{u} R) := AB4.of_AB5 _
instance : AB4Star (ModuleCat.{u} R) where
ofShape J :=
HasExactLimitsOfShape.domain_of_functor (Discrete J) (forget₂ (ModuleCat R) AddCommGrpCat.{u})
lemma ModuleCat.isSeparator [Small.{v} R] : IsSeparator (ModuleCat.of.{v} R (Shrink.{v} R)) :=
fun X Y f g h ↦ by
simp only [ObjectProperty.singleton_iff, ModuleCat.hom_ext_iff, hom_comp,
LinearMap.ext_iff, LinearMap.coe_comp, Function.comp_apply, forall_eq'] at h
ext x
simpa using h (ModuleCat.ofHom ((LinearMap.toSpanSingleton R X x).comp
(Shrink.linearEquiv R R : Shrink R →ₗ[R] R))) 1
instance [Small.{v} R] : HasSeparator (ModuleCat.{v} R) where
hasSeparator := ⟨ModuleCat.of R (Shrink.{v} R), ModuleCat.isSeparator R⟩
instance : IsGrothendieckAbelian.{u} (ModuleCat.{u} R) where |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Limits.lean | import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.Algebra.Category.Grp.Limits
import Mathlib.Algebra.Colimit.Module
import Mathlib.Algebra.Module.Shrink
/-!
# The category of R-modules has all limits
Further, these limits are preserved by the forgetful functor --- that is,
the underlying types are just the limits in the category of types.
-/
open CategoryTheory
open CategoryTheory.Limits
universe t v w u
-- `u` is determined by the ring, so can come later
noncomputable section
namespace ModuleCat
variable {R : Type u} [Ring R]
variable {J : Type v} [Category.{t} J] (F : J ⥤ ModuleCat.{w} R)
instance addCommGroupObj (j) :
AddCommGroup ((F ⋙ forget (ModuleCat R)).obj j) :=
inferInstanceAs <| AddCommGroup (F.obj j)
instance moduleObj (j) :
Module.{u, w} R ((F ⋙ forget (ModuleCat R)).obj j) :=
inferInstanceAs <| Module R (F.obj j)
/-- The flat sections of a functor into `ModuleCat R` form a submodule of all sections.
-/
def sectionsSubmodule : Submodule R (∀ j, F.obj j) :=
{ AddGrpCat.sectionsAddSubgroup.{v, w}
(F ⋙ forget₂ (ModuleCat R) AddCommGrpCat.{w} ⋙
forget₂ AddCommGrpCat AddGrpCat.{w}) with
carrier := (F ⋙ forget (ModuleCat R)).sections
smul_mem' := fun r s sh j j' f => by
simpa [Functor.sections, forget_map] using congr_arg (r • ·) (sh f) }
instance : AddCommMonoid (F ⋙ forget (ModuleCat R)).sections :=
inferInstanceAs <| AddCommMonoid (sectionsSubmodule F)
instance : Module R (F ⋙ forget (ModuleCat R)).sections :=
inferInstanceAs <| Module R (sectionsSubmodule F)
section
variable [Small.{w} (Functor.sections (F ⋙ forget (ModuleCat R)))]
instance : Small.{w} (sectionsSubmodule F) :=
inferInstanceAs <| Small.{w} (Functor.sections (F ⋙ forget (ModuleCat R)))
-- Adding the following instance speeds up `limitModule` noticeably,
-- by preventing a bad unfold of `limitAddCommGroup`.
instance limitAddCommMonoid :
AddCommMonoid (Types.Small.limitCone.{v, w} (F ⋙ forget (ModuleCat.{w} R))).pt :=
inferInstanceAs <| AddCommMonoid (Shrink (sectionsSubmodule F))
instance limitAddCommGroup :
AddCommGroup (Types.Small.limitCone.{v, w} (F ⋙ forget (ModuleCat.{w} R))).pt :=
inferInstanceAs <| AddCommGroup (Shrink.{w} (sectionsSubmodule F))
instance limitModule :
Module R (Types.Small.limitCone.{v, w} (F ⋙ forget (ModuleCat.{w} R))).pt :=
inferInstanceAs <| Module R (Shrink (sectionsSubmodule F))
/-- `limit.π (F ⋙ forget (ModuleCat.{w} R)) j` as an `R`-linear map. -/
def limitπLinearMap (j) :
(Types.Small.limitCone (F ⋙ forget (ModuleCat.{w} R))).pt →ₗ[R]
(F ⋙ forget (ModuleCat R)).obj j where
toFun := (Types.Small.limitCone (F ⋙ forget (ModuleCat R))).π.app j
map_smul' _ _ := by
simp only [Types.Small.limitCone_π_app,
← Shrink.linearEquiv_apply R (F ⋙ forget (ModuleCat R)).sections, map_smul]
simp only [Shrink.linearEquiv_apply]
rfl
map_add' _ _ := by
simp only [Types.Small.limitCone_π_app, ← Equiv.addEquiv_apply, map_add]
rfl
namespace HasLimits
-- The next two definitions are used in the construction of `HasLimits (ModuleCat R)`.
-- After that, the limits should be constructed using the generic limits API,
-- e.g. `limit F`, `limit.cone F`, and `limit.isLimit F`.
/-- Construction of a limit cone in `ModuleCat R`.
(Internal use only; use the limits API.)
-/
def limitCone : Cone F where
pt := ModuleCat.of R (Types.Small.limitCone.{v, w} (F ⋙ forget _)).pt
π :=
{ app := fun j => ofHom (limitπLinearMap F j)
naturality := fun _ _ f => hom_ext <| LinearMap.coe_injective <|
((Types.Small.limitCone (F ⋙ forget _)).π.naturality f) }
/-- Witness that the limit cone in `ModuleCat R` is a limit cone.
(Internal use only; use the limits API.)
-/
def limitConeIsLimit : IsLimit (limitCone.{t, v, w} F) := by
refine IsLimit.ofFaithful (forget (ModuleCat R)) (Types.Small.limitConeIsLimit.{v, w} _)
(fun s => ofHom ⟨⟨(Types.Small.limitConeIsLimit.{v, w} _).lift
((forget (ModuleCat R)).mapCone s), ?_⟩, ?_⟩)
(fun s => rfl)
· intro x y
simp only [Types.Small.limitConeIsLimit_lift, Functor.mapCone_π_app, forget_map, map_add]
rw [← equivShrink_add]
rfl
· intro r x
simp only [Types.Small.limitConeIsLimit_lift, Functor.mapCone_π_app, forget_map, map_smul]
rw [← equivShrink_smul]
rfl
end HasLimits
open HasLimits
/-- If `(F ⋙ forget (ModuleCat R)).sections` is `u`-small, `F` has a limit. -/
instance hasLimit : HasLimit F := HasLimit.mk {
cone := limitCone F
isLimit := limitConeIsLimit F
}
/-- If `J` is `u`-small, the category of `R`-modules has limits of shape `J`. -/
lemma hasLimitsOfShape [Small.{w} J] : HasLimitsOfShape J (ModuleCat.{w} R) where
/-- The category of R-modules has all limits. -/
lemma hasLimitsOfSize [UnivLE.{v, w}] : HasLimitsOfSize.{t, v} (ModuleCat.{w} R) where
has_limits_of_shape _ := hasLimitsOfShape
instance hasLimits : HasLimits (ModuleCat.{w} R) :=
ModuleCat.hasLimitsOfSize.{w, w, w, u}
instance (priority := high) hasLimits' : HasLimits (ModuleCat.{u} R) :=
ModuleCat.hasLimitsOfSize.{u, u, u}
/-- An auxiliary declaration to speed up typechecking.
-/
def forget₂AddCommGroup_preservesLimitsAux :
IsLimit ((forget₂ (ModuleCat R) AddCommGrpCat).mapCone (limitCone F)) :=
letI : Small.{w} (Functor.sections ((F ⋙ forget₂ _ AddCommGrpCat) ⋙ forget _)) :=
inferInstanceAs <| Small.{w} (Functor.sections (F ⋙ forget (ModuleCat R)))
AddCommGrpCat.limitConeIsLimit
(F ⋙ forget₂ (ModuleCat.{w} R) _ : J ⥤ AddCommGrpCat.{w})
/-- The forgetful functor from R-modules to abelian groups preserves all limits. -/
instance forget₂AddCommGroup_preservesLimit :
PreservesLimit F (forget₂ (ModuleCat R) AddCommGrpCat) :=
preservesLimit_of_preserves_limit_cone (limitConeIsLimit F)
(forget₂AddCommGroup_preservesLimitsAux F)
/-- The forgetful functor from R-modules to abelian groups preserves all limits.
-/
instance forget₂AddCommGroup_preservesLimitsOfSize [UnivLE.{v, w}] :
PreservesLimitsOfSize.{t, v}
(forget₂ (ModuleCat.{w} R) AddCommGrpCat.{w}) where
preservesLimitsOfShape := { preservesLimit := inferInstance }
instance forget₂AddCommGroup_preservesLimits :
PreservesLimits (forget₂ (ModuleCat R) AddCommGrpCat.{w}) :=
ModuleCat.forget₂AddCommGroup_preservesLimitsOfSize.{w, w}
/-- The forgetful functor from R-modules to types preserves all limits.
-/
instance forget_preservesLimitsOfSize [UnivLE.{v, w}] :
PreservesLimitsOfSize.{t, v} (forget (ModuleCat.{w} R)) where
preservesLimitsOfShape :=
{ preservesLimit := fun {K} ↦ preservesLimit_of_preserves_limit_cone (limitConeIsLimit K)
(Types.Small.limitConeIsLimit.{v} (_ ⋙ forget _)) }
instance forget_preservesLimits : PreservesLimits (forget (ModuleCat.{w} R)) :=
ModuleCat.forget_preservesLimitsOfSize.{w, w}
end
instance forget₂AddCommGroup_reflectsLimit :
ReflectsLimit F (forget₂ (ModuleCat.{w} R) AddCommGrpCat) where
reflects {c} hc := ⟨by
have : HasLimit (F ⋙ forget₂ (ModuleCat R) AddCommGrpCat) := ⟨_, hc⟩
have : Small.{w} (Functor.sections (F ⋙ forget (ModuleCat R))) := by
simpa only [AddCommGrpCat.hasLimit_iff_small_sections] using this
have := reflectsLimit_of_reflectsIsomorphisms F (forget₂ (ModuleCat R) AddCommGrpCat)
exact isLimitOfReflects _ hc⟩
instance forget₂AddCommGroup_reflectsLimitOfShape :
ReflectsLimitsOfShape J (forget₂ (ModuleCat.{w} R) AddCommGrpCat) where
instance forget₂AddCommGroup_reflectsLimitOfSize :
ReflectsLimitsOfSize.{t, v} (forget₂ (ModuleCat.{w} R) AddCommGrpCat) where
section DirectLimit
open Module
variable {ι : Type v}
variable [DecidableEq ι] [Preorder ι]
variable (G : ι → Type v)
variable [∀ i, AddCommGroup (G i)] [∀ i, Module R (G i)]
variable (f : ∀ i j, i ≤ j → G i →ₗ[R] G j) [DirectedSystem G fun i j h ↦ f i j h]
/-- The diagram (in the sense of `CategoryTheory`) of an unbundled `directLimit` of modules. -/
@[simps]
def directLimitDiagram : ι ⥤ ModuleCat R where
obj i := ModuleCat.of R (G i)
map hij := ofHom (f _ _ hij.le)
map_id i := by
ext
apply Module.DirectedSystem.map_self
map_comp hij hjk := by
ext
symm
apply Module.DirectedSystem.map_map f
variable [DecidableEq ι]
/-- The `Cocone` on `directLimitDiagram` corresponding to
the unbundled `directLimit` of modules.
In `directLimitIsColimit` we show that it is a colimit cocone. -/
@[simps]
def directLimitCocone : Cocone (directLimitDiagram G f) where
pt := ModuleCat.of R <| DirectLimit G f
ι :=
{ app := fun x => ofHom (Module.DirectLimit.of R ι G f x)
naturality := fun _ _ hij => by
ext
exact DirectLimit.of_f }
/-- The unbundled `directLimit` of modules is a colimit
in the sense of `CategoryTheory`. -/
@[simps]
def directLimitIsColimit : IsColimit (directLimitCocone G f) where
desc s := ofHom <|
Module.DirectLimit.lift R ι G f (fun i => (s.ι.app i).hom) fun i j h x => by
simp only [Functor.const_obj_obj]
rw [← s.w (homOfLE h)]
rfl
fac s i := by
ext
dsimp only [hom_comp, directLimitCocone, hom_ofHom, LinearMap.comp_apply]
apply DirectLimit.lift_of
uniq s m h := by
have :
s.ι.app = fun i =>
(ofHom (DirectLimit.of R ι (fun i => G i) (fun i j H => f i j H) i)) ≫ m := by
funext i
rw [← h]
rfl
ext
simp [this]
end DirectLimit
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Algebra.lean | import Mathlib.Algebra.Algebra.RestrictScalars
import Mathlib.CategoryTheory.Linear.Basic
import Mathlib.Algebra.Category.ModuleCat.Basic
/-!
# Additional typeclass for modules over an algebra
For an object in `M : ModuleCat A`, where `A` is a `k`-algebra,
we provide additional typeclasses on the underlying type `M`,
namely `Module k M` and `IsScalarTower k A M`.
These are not made into instances by default.
We provide the `Linear k (ModuleCat A)` instance.
## Note
If you begin with a `[Module k M] [Module A M] [IsScalarTower k A M]`,
and build a bundled module via `ModuleCat.of A M`,
these instances will not necessarily agree with the original ones.
It seems without making a parallel version `ModuleCat' k A`, for modules over a `k`-algebra `A`,
that carries these typeclasses, this seems hard to achieve.
(An alternative would be to always require these typeclasses, and remove the original `ModuleCat`,
requiring users to write `ModuleCat' ℤ A` when `A` is merely a ring.)
-/
universe v u w
open CategoryTheory
namespace ModuleCat
variable {k : Type u} [Field k]
variable {A : Type w} [Ring A] [Algebra k A]
/-- Type synonym for considering a module over a `k`-algebra as a `k`-module. -/
def moduleOfAlgebraModule (M : ModuleCat.{v} A) : Module k M :=
RestrictScalars.module k A M
attribute [scoped instance] ModuleCat.moduleOfAlgebraModule
theorem isScalarTower_of_algebra_moduleCat (M : ModuleCat.{v} A) : IsScalarTower k A M :=
RestrictScalars.isScalarTower k A M
attribute [scoped instance] ModuleCat.isScalarTower_of_algebra_moduleCat
-- We verify that the morphism spaces become `k`-modules.
example (M N : ModuleCat.{v} A) : Module k (M ⟶ N) := inferInstance
instance linearOverField : Linear k (ModuleCat.{v} A) where
homModule _ _ := inferInstance
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/ChangeOfRings.lean | import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Category.ModuleCat.Colimits
import Mathlib.Algebra.Category.ModuleCat.Limits
import Mathlib.Algebra.Algebra.RestrictScalars
import Mathlib.CategoryTheory.Adjunction.Mates
import Mathlib.CategoryTheory.Linear.LinearFunctor
import Mathlib.LinearAlgebra.TensorProduct.Tower
/-!
# Change Of Rings
## Main definitions
* `ModuleCat.restrictScalars`: given rings `R, S` and a ring homomorphism `R ⟶ S`,
then `restrictScalars : ModuleCat S ⥤ ModuleCat R` is defined by `M ↦ M` where an `S`-module `M`
is seen as an `R`-module by `r • m := f r • m` and `S`-linear map `l : M ⟶ M'` is `R`-linear as
well.
* `ModuleCat.extendScalars`: given **commutative** rings `R, S` and ring homomorphism
`f : R ⟶ S`, then `extendScalars : ModuleCat R ⥤ ModuleCat S` is defined by `M ↦ S ⨂ M` where the
module structure is defined by `s • (s' ⊗ m) := (s * s') ⊗ m` and `R`-linear map `l : M ⟶ M'`
is sent to `S`-linear map `s ⊗ m ↦ s ⊗ l m : S ⨂ M ⟶ S ⨂ M'`.
* `ModuleCat.coextendScalars`: given rings `R, S` and a ring homomorphism `R ⟶ S`
then `coextendScalars : ModuleCat R ⥤ ModuleCat S` is defined by `M ↦ (S →ₗ[R] M)` where `S` is
seen as an `R`-module by restriction of scalars and `l ↦ l ∘ _`.
## Main results
* `ModuleCat.extendRestrictScalarsAdj`: given commutative rings `R, S` and a ring
homomorphism `f : R →+* S`, the extension and restriction of scalars by `f` are adjoint functors.
* `ModuleCat.restrictCoextendScalarsAdj`: given rings `R, S` and a ring homomorphism
`f : R ⟶ S` then `coextendScalars f` is the right adjoint of `restrictScalars f`.
## Notation
Let `R, S` be rings and `f : R →+* S`
* if `M` is an `R`-module, `s : S` and `m : M`, then `s ⊗ₜ[R, f] m` is the pure tensor
`s ⊗ m : S ⊗[R, f] M`.
-/
suppress_compilation
open CategoryTheory Limits
namespace ModuleCat
universe v u₁ u₂ u₃ w
namespace RestrictScalars
variable {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S)
variable (M : ModuleCat.{v} S)
/-- Any `S`-module M is also an `R`-module via a ring homomorphism `f : R ⟶ S` by defining
`r • m := f r • m` (`Module.compHom`). This is called restriction of scalars. -/
def obj' : ModuleCat R :=
let _ := Module.compHom M f
of R M
/-- Given an `S`-linear map `g : M → M'` between `S`-modules, `g` is also `R`-linear between `M` and
`M'` by means of restriction of scalars.
-/
def map' {M M' : ModuleCat.{v} S} (g : M ⟶ M') : obj' f M ⟶ obj' f M' :=
-- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(X := ...)` and `(Y := ...)`.
-- This suggests `RestrictScalars.obj'` needs to be redesigned.
ofHom (X := obj' f M) (Y := obj' f M')
{ g.hom with map_smul' := fun r => g.hom.map_smul (f r) }
end RestrictScalars
/-- The restriction of scalars operation is functorial. For any `f : R →+* S` a ring homomorphism,
* an `S`-module `M` can be considered as `R`-module by `r • m = f r • m`
* an `S`-linear map is also `R`-linear
-/
def restrictScalars {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) :
ModuleCat.{v} S ⥤ ModuleCat.{v} R where
obj := RestrictScalars.obj' f
map := RestrictScalars.map' f
instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) :
(restrictScalars.{v} f).Faithful where
map_injective h := by
ext x
simpa only using DFunLike.congr_fun (ModuleCat.hom_ext_iff.mp h) x
instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) :
(restrictScalars.{v} f).PreservesMonomorphisms where
preserves _ h := by rwa [mono_iff_injective] at h ⊢
-- Porting note: this should be automatic
-- TODO: this instance gives diamonds if `f : S →+* S`, see `PresheafOfModules.pushforward₀`.
-- The correct solution is probably to define explicit maps between `M` and
-- `(restrictScalars f).obj M`.
instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] {f : R →+* S}
{M : ModuleCat.{v} S} : Module S <| (restrictScalars f).obj M :=
inferInstanceAs <| Module S M
@[simp]
theorem restrictScalars.map_apply {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S)
{M M' : ModuleCat.{v} S} (g : M ⟶ M') (x) : (restrictScalars f).map g x = g x :=
rfl
@[simp]
theorem restrictScalars.smul_def {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S)
{M : ModuleCat.{v} S} (r : R) (m : (restrictScalars f).obj M) : r • m = f r • show M from m :=
rfl
theorem restrictScalars.smul_def' {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S)
{M : ModuleCat.{v} S} (r : R) (m : M) :
r • (show (restrictScalars f).obj M from m) = f r • m :=
rfl
instance (priority := 100) sMulCommClass_mk {R : Type u₁} {S : Type u₂} [Ring R] [CommRing S]
(f : R →+* S) (M : Type v) [I : AddCommGroup M] [Module S M] :
haveI : SMul R M := (RestrictScalars.obj' f (ModuleCat.of S M)).isModule.toSMul
SMulCommClass R S M :=
@SMulCommClass.mk R S M (_) _
fun r s m => (by simp [← mul_smul, mul_comm] : f r • s • m = s • f r • m)
/-- Semilinear maps `M →ₛₗ[f] N` identify to
morphisms `M ⟶ (ModuleCat.restrictScalars f).obj N`. -/
@[simps]
def semilinearMapAddEquiv {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S)
(M : ModuleCat.{v} R) (N : ModuleCat.{v} S) :
(M →ₛₗ[f] N) ≃+ (M ⟶ (ModuleCat.restrictScalars f).obj N) where
-- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(Y := ...)`.
-- This suggests `restrictScalars` needs to be redesigned.
toFun g := ofHom (Y := (ModuleCat.restrictScalars f).obj N) <|
{ toFun := g
map_add' := by simp
map_smul' := by simp }
invFun g :=
{ toFun := g
map_add' := by simp
map_smul' := g.hom.map_smul }
map_add' _ _ := rfl
section
variable {R : Type u₁} [Ring R] (f : R →+* R)
/-- For a `R`-module `M`, the restriction of scalars of `M` by the identity morphism identifies
to `M`. -/
def restrictScalarsId'App (hf : f = RingHom.id R) (M : ModuleCat R) :
(restrictScalars f).obj M ≅ M :=
LinearEquiv.toModuleIso <|
@AddEquiv.toLinearEquiv _ _ _ _ _ _ (((restrictScalars f).obj M).isModule) _
(by rfl) (fun r x ↦ by subst hf; rfl)
variable (hf : f = RingHom.id R)
@[simp] lemma restrictScalarsId'App_hom_apply (M : ModuleCat R) (x : M) :
(restrictScalarsId'App f hf M).hom x = x :=
rfl
@[simp] lemma restrictScalarsId'App_inv_apply (M : ModuleCat R) (x : M) :
(restrictScalarsId'App f hf M).inv x = x :=
rfl
/-- The restriction of scalars by a ring morphism that is the identity identifies to the
identity functor. -/
@[simps! hom_app inv_app]
def restrictScalarsId' : ModuleCat.restrictScalars.{v} f ≅ 𝟭 _ :=
NatIso.ofComponents <| fun M ↦ restrictScalarsId'App f hf M
@[reassoc]
lemma restrictScalarsId'App_hom_naturality {M N : ModuleCat R} (φ : M ⟶ N) :
(restrictScalars f).map φ ≫ (restrictScalarsId'App f hf N).hom =
(restrictScalarsId'App f hf M).hom ≫ φ :=
(restrictScalarsId' f hf).hom.naturality φ
@[reassoc]
lemma restrictScalarsId'App_inv_naturality {M N : ModuleCat R} (φ : M ⟶ N) :
φ ≫ (restrictScalarsId'App f hf N).inv =
(restrictScalarsId'App f hf M).inv ≫ (restrictScalars f).map φ :=
(restrictScalarsId' f hf).inv.naturality φ
variable (R)
/-- The restriction of scalars by the identity morphism identifies to the
identity functor. -/
abbrev restrictScalarsId := restrictScalarsId'.{v} (RingHom.id R) rfl
end
section
variable {R₁ : Type u₁} {R₂ : Type u₂} {R₃ : Type u₃} [Ring R₁] [Ring R₂] [Ring R₃]
(f : R₁ →+* R₂) (g : R₂ →+* R₃) (gf : R₁ →+* R₃)
/-- For each `R₃`-module `M`, restriction of scalars of `M` by a composition of ring morphisms
identifies to successively restricting scalars. -/
def restrictScalarsComp'App (hgf : gf = g.comp f) (M : ModuleCat R₃) :
(restrictScalars gf).obj M ≅ (restrictScalars f).obj ((restrictScalars g).obj M) :=
(AddEquiv.toLinearEquiv
(M := ↑((restrictScalars gf).obj M))
(M₂ := ↑((restrictScalars f).obj ((restrictScalars g).obj M)))
(by rfl)
(fun r x ↦ by subst hgf; rfl)).toModuleIso
variable (hgf : gf = g.comp f)
@[simp] lemma restrictScalarsComp'App_hom_apply (M : ModuleCat R₃) (x : M) :
(restrictScalarsComp'App f g gf hgf M).hom x = x :=
rfl
@[simp] lemma restrictScalarsComp'App_inv_apply (M : ModuleCat R₃) (x : M) :
(restrictScalarsComp'App f g gf hgf M).inv x = x :=
rfl
/-- The restriction of scalars by a composition of ring morphisms identifies to the
composition of the restriction of scalars functors. -/
@[simps! hom_app inv_app]
def restrictScalarsComp' :
ModuleCat.restrictScalars.{v} gf ≅
ModuleCat.restrictScalars g ⋙ ModuleCat.restrictScalars f :=
NatIso.ofComponents <| fun M ↦ restrictScalarsComp'App f g gf hgf M
@[reassoc]
lemma restrictScalarsComp'App_hom_naturality {M N : ModuleCat R₃} (φ : M ⟶ N) :
(restrictScalars gf).map φ ≫ (restrictScalarsComp'App f g gf hgf N).hom =
(restrictScalarsComp'App f g gf hgf M).hom ≫
(restrictScalars f).map ((restrictScalars g).map φ) :=
(restrictScalarsComp' f g gf hgf).hom.naturality φ
@[reassoc]
lemma restrictScalarsComp'App_inv_naturality {M N : ModuleCat R₃} (φ : M ⟶ N) :
(restrictScalars f).map ((restrictScalars g).map φ) ≫
(restrictScalarsComp'App f g gf hgf N).inv =
(restrictScalarsComp'App f g gf hgf M).inv ≫ (restrictScalars gf).map φ :=
(restrictScalarsComp' f g gf hgf).inv.naturality φ
/-- The restriction of scalars by a composition of ring morphisms identifies to the
composition of the restriction of scalars functors. -/
abbrev restrictScalarsComp := restrictScalarsComp'.{v} f g _ rfl
end
/-- The equivalence of categories `ModuleCat S ≌ ModuleCat R` induced by `e : R ≃+* S`. -/
def restrictScalarsEquivalenceOfRingEquiv {R S} [Ring R] [Ring S] (e : R ≃+* S) :
ModuleCat S ≌ ModuleCat R where
functor := ModuleCat.restrictScalars e.toRingHom
inverse := ModuleCat.restrictScalars e.symm
unitIso := NatIso.ofComponents (fun M ↦ LinearEquiv.toModuleIso
(X₁ := M)
(X₂ := (restrictScalars e.symm.toRingHom).obj ((restrictScalars e.toRingHom).obj M))
{ __ := AddEquiv.refl M
map_smul' := fun s m ↦ congr_arg (· • m) (e.right_inv s).symm }) (by intros; rfl)
counitIso := NatIso.ofComponents (fun M ↦ LinearEquiv.toModuleIso
(X₁ := (restrictScalars e.toRingHom).obj ((restrictScalars e.symm.toRingHom).obj M))
(X₂ := M)
{ __ := AddEquiv.refl M
map_smul' := fun r _ ↦ congr_arg (· • (_ : M)) (e.left_inv r)}) (by intros; rfl)
functor_unitIso_comp := by intros; rfl
instance restrictScalars_isEquivalence_of_ringEquiv {R S} [Ring R] [Ring S] (e : R ≃+* S) :
(ModuleCat.restrictScalars e.toRingHom).IsEquivalence :=
(restrictScalarsEquivalenceOfRingEquiv e).isEquivalence_functor
instance {R S} [Ring R] [Ring S] (f : R →+* S) : (restrictScalars f).Additive where
instance restrictScalarsEquivalenceOfRingEquiv_additive {R S} [Ring R] [Ring S] (e : R ≃+* S) :
(restrictScalarsEquivalenceOfRingEquiv e).functor.Additive where
namespace Algebra
instance {R₀ R S} [CommSemiring R₀] [Ring R] [Ring S] [Algebra R₀ R] [Algebra R₀ S]
(f : R →ₐ[R₀] S) : (restrictScalars f.toRingHom).Linear R₀ where
map_smul {M N} g r₀ := by ext m; exact congr_arg (· • g.hom m) (f.commutes r₀).symm
instance restrictScalarsEquivalenceOfRingEquiv_linear
{R₀ R S} [CommSemiring R₀] [Ring R] [Ring S] [Algebra R₀ R] [Algebra R₀ S] (e : R ≃ₐ[R₀] S) :
(restrictScalarsEquivalenceOfRingEquiv e.toRingEquiv).functor.Linear R₀ :=
inferInstanceAs ((restrictScalars e.toAlgHom.toRingHom).Linear R₀)
end Algebra
open TensorProduct
variable {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S)
section ModuleCat.Unbundled
variable (M : Type v) [AddCommMonoid M] [Module R M]
/-- Tensor product of elements along a base change.
This notation is necessary because we need to reason about `s ⊗ₜ m` where `s : S` and `m : M`;
without this notation, one needs to work with `s : (restrictScalars f).obj ⟨S⟩`. -/
scoped[ChangeOfRings] notation:100 s:100 " ⊗ₜ[" R "," f "] " m:101 =>
@TensorProduct.tmul R _ _ _ _ _ (Module.compHom _ f) _ s m
end Unbundled
open ChangeOfRings
namespace ExtendScalars
variable (M : ModuleCat.{v} R)
/-- Extension of scalars turns an `R`-module into an `S`-module by M ↦ S ⨂ M
-/
def obj' : ModuleCat S :=
of _ (TensorProduct R ((restrictScalars f).obj (of _ S)) M)
/-- Extension of scalars is a functor where an `R`-module `M` is sent to `S ⊗ M` and
`l : M1 ⟶ M2` is sent to `s ⊗ m ↦ s ⊗ l m`
-/
def map' {M1 M2 : ModuleCat.{v} R} (l : M1 ⟶ M2) : obj' f M1 ⟶ obj' f M2 :=
ofHom (@LinearMap.baseChange R S M1 M2 _ _ ((algebraMap S _).comp f).toAlgebra _ _ _ _ l.hom)
theorem map'_id {M : ModuleCat.{v} R} : map' f (𝟙 M) = 𝟙 _ := by
simp [map', obj']
theorem map'_comp {M₁ M₂ M₃ : ModuleCat.{v} R} (l₁₂ : M₁ ⟶ M₂) (l₂₃ : M₂ ⟶ M₃) :
map' f (l₁₂ ≫ l₂₃) = map' f l₁₂ ≫ map' f l₂₃ := by
ext x
induction x using TensorProduct.induction_on with
| zero => rfl
| tmul => rfl
| add _ _ ihx ihy => grind
end ExtendScalars
/-- Extension of scalars is a functor where an `R`-module `M` is sent to `S ⊗ M` and
`l : M1 ⟶ M2` is sent to `s ⊗ m ↦ s ⊗ l m`
-/
def extendScalars {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) :
ModuleCat R ⥤ ModuleCat S where
obj M := ExtendScalars.obj' f M
map l := ExtendScalars.map' f l
map_id _ := ExtendScalars.map'_id f
map_comp := ExtendScalars.map'_comp f
namespace ExtendScalars
variable {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S)
@[simp]
protected theorem smul_tmul {M : ModuleCat.{v} R} (s s' : S) (m : M) :
s • (s' ⊗ₜ[R,f] m : (extendScalars f).obj M) = (s * s') ⊗ₜ[R,f] m :=
rfl
@[simp]
theorem map_tmul {M M' : ModuleCat.{v} R} (g : M ⟶ M') (s : S) (m : M) :
(extendScalars f).map g (s ⊗ₜ[R,f] m) = s ⊗ₜ[R,f] g m :=
rfl
variable {f}
@[ext]
lemma hom_ext {M : ModuleCat R} {N : ModuleCat S}
{α β : (extendScalars f).obj M ⟶ N}
(h : ∀ (m : M), α ((1 : S) ⊗ₜ m) = β ((1 : S) ⊗ₜ m)) : α = β := by
apply (restrictScalars f).map_injective
letI := f.toAlgebra
ext : 1
apply TensorProduct.ext'
intro (s : S) m
change α (s ⊗ₜ m) = β (s ⊗ₜ m)
have : s ⊗ₜ[R] (m : M) = s • (1 : S) ⊗ₜ[R] m := by
rw [ExtendScalars.smul_tmul, mul_one]
simp only [this, map_smul, h]
end ExtendScalars
namespace CoextendScalars
variable {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S)
section Unbundled
variable (M : Type v) [AddCommMonoid M] [Module R M]
-- We use `S'` to denote `S` viewed as `R`-module, via the map `f`.
-- Porting note: this seems to cause problems related to lack of reducibility
-- local notation "S'" => (restrictScalars f).obj ⟨S⟩
/-- Given an `R`-module M, consider Hom(S, M) -- the `R`-linear maps between S (as an `R`-module by
means of restriction of scalars) and M. `S` acts on Hom(S, M) by `s • g = x ↦ g (x • s)`
-/
instance hasSMul : SMul S <| (restrictScalars f).obj (of _ S) →ₗ[R] M where
smul s g :=
{ toFun := fun s' : S => g (s' * s : S)
map_add' := fun x y : S => by rw [add_mul, map_add]
map_smul' := fun r (t : S) => by
-- Porting note: needed some erw's even after dsimp to clean things up
dsimp
rw [← LinearMap.map_smul]
erw [smul_eq_mul, smul_eq_mul, mul_assoc] }
@[simp]
theorem smul_apply' (s : S) (g : (restrictScalars f).obj (of _ S) →ₗ[R] M) (s' : S) :
(s • g) s' = g (s' * s : S) :=
rfl
instance mulAction : MulAction S <| (restrictScalars f).obj (of _ S) →ₗ[R] M :=
{ CoextendScalars.hasSMul f _ with
one_smul := fun g => LinearMap.ext fun s : S => by simp
mul_smul := fun (s t : S) g => LinearMap.ext fun x : S => by simp [mul_assoc] }
instance distribMulAction : DistribMulAction S <| (restrictScalars f).obj (of _ S) →ₗ[R] M :=
{ CoextendScalars.mulAction f _ with
smul_add := fun s g h => LinearMap.ext fun _ : S => by simp
smul_zero := fun _ => LinearMap.ext fun _ : S => by simp }
/-- `S` acts on Hom(S, M) by `s • g = x ↦ g (x • s)`, this action defines an `S`-module structure on
Hom(S, M).
-/
instance isModule : Module S <| (restrictScalars f).obj (of _ S) →ₗ[R] M :=
{ CoextendScalars.distribMulAction f _ with
add_smul := fun s1 s2 g => LinearMap.ext fun x : S => by simp [mul_add, LinearMap.map_add]
zero_smul := fun g => LinearMap.ext fun x : S => by simp [LinearMap.map_zero] }
end Unbundled
variable (M : ModuleCat.{v} R)
/-- If `M` is an `R`-module, then the set of `R`-linear maps `S →ₗ[R] M` is an `S`-module with
scalar multiplication defined by `s • l := x ↦ l (x • s)` -/
def obj' : ModuleCat S :=
of _ ((restrictScalars f).obj (of _ S) →ₗ[R] M)
instance : CoeFun (obj' f M) fun _ => S → M :=
inferInstanceAs <| CoeFun ((restrictScalars f).obj (of _ S) →ₗ[R] M) _
/-- If `M, M'` are `R`-modules, then any `R`-linear map `g : M ⟶ M'` induces an `S`-linear map
`(S →ₗ[R] M) ⟶ (S →ₗ[R] M')` defined by `h ↦ g ∘ h` -/
@[simps!]
def map' {M M' : ModuleCat R} (g : M ⟶ M') : obj' f M ⟶ obj' f M' :=
ofHom
{ toFun := fun h => g.hom.comp h
map_add' := fun _ _ => LinearMap.comp_add _ _ _
map_smul' := fun s h => by ext; simp }
end CoextendScalars
/--
For any rings `R, S` and a ring homomorphism `f : R →+* S`, there is a functor from `R`-module to
`S`-module defined by `M ↦ (S →ₗ[R] M)` where `S` is considered as an `R`-module via restriction of
scalars and `g : M ⟶ M'` is sent to `h ↦ g ∘ h`.
-/
def coextendScalars {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) :
ModuleCat R ⥤ ModuleCat S where
obj := CoextendScalars.obj' f
map := CoextendScalars.map' f
map_id _ := by ext; rfl
map_comp _ _ := by ext; rfl
namespace CoextendScalars
variable {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S)
instance (M : ModuleCat R) : CoeFun ((coextendScalars f).obj M) fun _ => S → M :=
inferInstanceAs <| CoeFun (CoextendScalars.obj' f M) _
theorem smul_apply (M : ModuleCat R) (g : (coextendScalars f).obj M) (s s' : S) :
(s • g) s' = g (s' * s) :=
rfl
@[simp]
theorem map_apply {M M' : ModuleCat R} (g : M ⟶ M') (x) (s : S) :
(coextendScalars f).map g x s = g (x s) :=
rfl
end CoextendScalars
namespace RestrictionCoextensionAdj
variable {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S)
/-- Given `R`-module X and `S`-module Y, any `g : (restrictScalars f).obj Y ⟶ X`
corresponds to `Y ⟶ (coextendScalars f).obj X` by sending `y ↦ (s ↦ g (s • y))`
-/
def HomEquiv.fromRestriction {X : ModuleCat R} {Y : ModuleCat S}
(g : (restrictScalars f).obj Y ⟶ X) : Y ⟶ (coextendScalars f).obj X :=
ofHom
{ toFun := fun y : Y =>
{ toFun := fun s : S => g <| (s • y : Y)
map_add' := fun s1 s2 : S => by simp only [add_smul]; rw [LinearMap.map_add]
map_smul' := fun r (s : S) => by
-- Porting note: dsimp clears out some rw's but less eager to apply others with Lean 4
dsimp
rw [← g.hom.map_smul]
erw [smul_eq_mul, mul_smul]
rfl }
map_add' := fun y1 y2 : Y =>
LinearMap.ext fun s : S => by
simp [smul_add, map_add]
map_smul' := fun (s : S) (y : Y) => LinearMap.ext fun t : S => by
simp [mul_smul] }
/-- This should be autogenerated by `@[simps]` but we need to give `s` the correct type here. -/
@[simp] lemma HomEquiv.fromRestriction_hom_apply_apply {X : ModuleCat R} {Y : ModuleCat S}
(g : (restrictScalars f).obj Y ⟶ X) (y) (s : S) :
(HomEquiv.fromRestriction f g).hom y s = g (s • y) := rfl
/-- Given `R`-module X and `S`-module Y, any `g : Y ⟶ (coextendScalars f).obj X`
corresponds to `(restrictScalars f).obj Y ⟶ X` by `y ↦ g y 1`
-/
def HomEquiv.toRestriction {X Y} (g : Y ⟶ (coextendScalars f).obj X) :
(restrictScalars f).obj Y ⟶ X :=
-- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(X := ...)`.
-- This suggests `restrictScalars` needs to be redesigned.
ofHom (X := (restrictScalars f).obj Y)
{ toFun := fun y : Y => (g y) (1 : S)
map_add' := fun x y => by dsimp; rw [g.hom.map_add, LinearMap.add_apply]
map_smul' := fun r (y : Y) => by
dsimp
rw [← LinearMap.map_smul]
erw [smul_eq_mul, mul_one, LinearMap.map_smul]
rw [CoextendScalars.smul_apply (s := f r) (g := g y) (s' := 1), one_mul]
simp }
/-- This should be autogenerated by `@[simps]` but we need to give `1` the correct type here. -/
@[simp] lemma HomEquiv.toRestriction_hom_apply {X : ModuleCat R} {Y : ModuleCat S}
(g : Y ⟶ (coextendScalars f).obj X) (y) :
(HomEquiv.toRestriction f g).hom y = g.hom y (1 : S) := rfl
/-- Auxiliary definition for `unit'`, to address timeouts. -/
def app' (Y : ModuleCat S) : Y →ₗ[S] (restrictScalars f ⋙ coextendScalars f).obj Y :=
{ toFun := fun y : Y =>
{ toFun := fun s : S => (s • y : Y)
map_add' := fun _ _ => add_smul _ _ _
map_smul' := fun r (s : S) => by
dsimp only [AddHom.toFun_eq_coe, AddHom.coe_mk, RingHom.id_apply]
erw [smul_eq_mul, mul_smul]
simp }
map_add' := fun y1 y2 =>
LinearMap.ext fun s : S => by
-- Porting note: double dsimp seems odd
dsimp only [AddHom.toFun_eq_coe, AddHom.coe_mk, RingHom.id_apply,
RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe,
MonoidHom.coe_coe, ZeroHom.coe_mk, smul_eq_mul, id_eq, eq_mpr_eq_cast, cast_eq,
Functor.comp_obj]
rw [LinearMap.add_apply, LinearMap.coe_mk, LinearMap.coe_mk, LinearMap.coe_mk]
dsimp
rw [smul_add]
map_smul' := fun s (y : Y) => LinearMap.ext fun t : S => by
-- Porting note: used to be simp [mul_smul]
rw [RingHom.id_apply, LinearMap.coe_mk, CoextendScalars.smul_apply', LinearMap.coe_mk]
dsimp
rw [mul_smul] }
/--
The natural transformation from identity functor to the composition of restriction and coextension
of scalars.
-/
@[simps]
protected noncomputable def unit' : 𝟭 (ModuleCat S) ⟶ restrictScalars f ⋙ coextendScalars f where
app Y := ofHom (app' f Y)
naturality Y Y' g :=
hom_ext <| LinearMap.ext fun y : Y => LinearMap.ext fun s : S => by
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): previously simp [CoextendScalars.map_apply]
simp only [ModuleCat.hom_comp, Functor.id_map, Functor.id_obj, Functor.comp_obj,
Functor.comp_map, LinearMap.coe_comp, Function.comp, CoextendScalars.map_apply,
restrictScalars.map_apply f]
change s • (g y) = g (s • y)
rw [map_smul]
/-- The natural transformation from the composition of coextension and restriction of scalars to
identity functor.
-/
@[simps]
protected def counit' : coextendScalars f ⋙ restrictScalars f ⟶ 𝟭 (ModuleCat R) where
-- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(X := ...)`.
-- This suggests `restrictScalars` needs to be redesigned.
app X := ofHom (X := (restrictScalars f).obj ((coextendScalars f).obj X))
{ toFun := fun g => g.toFun (1 : S)
map_add' := fun x1 x2 => by
dsimp
rw [LinearMap.add_apply]
map_smul' := fun r (g : (restrictScalars f).obj ((coextendScalars f).obj X)) => by
dsimp
rw [CoextendScalars.smul_apply, one_mul, ← LinearMap.map_smul]
congr
change f r = f r • (1 : S)
rw [smul_eq_mul (f r) 1, mul_one] }
end RestrictionCoextensionAdj
-- Porting note: very fiddly universes
/-- Restriction of scalars is left adjoint to coextension of scalars. -/
-- @[simps] Porting note: not in normal form and not used
def restrictCoextendScalarsAdj {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) :
restrictScalars.{max v u₂, u₁, u₂} f ⊣ coextendScalars f :=
Adjunction.mk' {
homEquiv := fun X Y ↦
{ toFun := RestrictionCoextensionAdj.HomEquiv.fromRestriction.{u₁,u₂,v} f
invFun := RestrictionCoextensionAdj.HomEquiv.toRestriction.{u₁,u₂,v} f
left_inv := fun g => by ext; simp
right_inv := fun g => hom_ext <| LinearMap.ext fun x => LinearMap.ext fun s : S => by
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): once just simp
rw [RestrictionCoextensionAdj.HomEquiv.fromRestriction_hom_apply_apply,
RestrictionCoextensionAdj.HomEquiv.toRestriction_hom_apply, LinearMap.map_smulₛₗ,
RingHom.id_apply, CoextendScalars.smul_apply', one_mul] }
unit := RestrictionCoextensionAdj.unit'.{u₁,u₂,v} f
counit := RestrictionCoextensionAdj.counit'.{u₁,u₂,v} f
homEquiv_unit := hom_ext <| LinearMap.ext fun _ => rfl
homEquiv_counit := fun {X Y g} => by
ext
simp [RestrictionCoextensionAdj.counit'] }
instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) :
(restrictScalars.{max u₂ w} f).IsLeftAdjoint :=
(restrictCoextendScalarsAdj f).isLeftAdjoint
instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) :
(coextendScalars.{u₁, u₂, max u₂ w} f).IsRightAdjoint :=
(restrictCoextendScalarsAdj f).isRightAdjoint
namespace ExtendRestrictScalarsAdj
open TensorProduct
variable {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S)
/--
Given `R`-module X and `S`-module Y and a map `g : (extendScalars f).obj X ⟶ Y`, i.e. `S`-linear
map `S ⨂ X → Y`, there is a `X ⟶ (restrictScalars f).obj Y`, i.e. `R`-linear map `X ⟶ Y` by
`x ↦ g (1 ⊗ x)`.
-/
@[simps! hom_apply]
def HomEquiv.toRestrictScalars {X Y} (g : (extendScalars f).obj X ⟶ Y) :
X ⟶ (restrictScalars f).obj Y :=
-- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(Y := ...)`.
-- This suggests `restrictScalars` needs to be redesigned.
ofHom (Y := (restrictScalars f).obj Y)
{ toFun := fun x => g <| (1 : S) ⊗ₜ[R,f] x
map_add' := fun _ _ => by dsimp; rw [tmul_add, map_add]
map_smul' := fun r s => by
letI : Module R S := Module.compHom S f
letI : Module R Y := Module.compHom Y f
dsimp
rw [RestrictScalars.smul_def, ← LinearMap.map_smul]
erw [tmul_smul]
congr }
-- Porting note: forced to break apart fromExtendScalars due to timeouts
/--
The map `S → X →ₗ[R] Y` given by `fun s x => s • (g x)`
-/
@[simps]
def HomEquiv.evalAt {X : ModuleCat R} {Y : ModuleCat S} (s : S)
(g : X ⟶ (restrictScalars f).obj Y) : have : Module R Y := Module.compHom Y f
X →ₗ[R] Y :=
@LinearMap.mk _ _ _ _ (RingHom.id R) X Y _ _ _ (_)
{ toFun := fun x => s • (g x : Y)
map_add' := by
intros
dsimp only
rw [map_add, smul_add] }
(by
intro r x
rw [AddHom.toFun_eq_coe, AddHom.coe_mk, RingHom.id_apply,
LinearMap.map_smul, smul_comm r s (g x : Y)])
/--
Given `R`-module X and `S`-module Y and a map `X ⟶ (restrictScalars f).obj Y`, i.e `R`-linear map
`X ⟶ Y`, there is a map `(extend_scalars f).obj X ⟶ Y`, i.e `S`-linear map `S ⨂ X → Y` by
`s ⊗ x ↦ s • g x`.
-/
@[simps! hom_apply]
def HomEquiv.fromExtendScalars {X Y} (g : X ⟶ (restrictScalars f).obj Y) :
(extendScalars f).obj X ⟶ Y := by
letI m1 : Module R S := Module.compHom S f; letI m2 : Module R Y := Module.compHom Y f
refine ofHom
{toFun := fun z => TensorProduct.lift (σ₁₂ := .id _) ?_ z, map_add' := ?_, map_smul' := ?_}
· refine
{toFun := fun s => HomEquiv.evalAt f s g, map_add' := fun (s₁ s₂ : S) => ?_,
map_smul' := fun (r : R) (s : S) => ?_}
· ext
dsimp only [m2, evalAt_apply, LinearMap.add_apply]
rw [← add_smul]
· ext x
apply mul_smul (f r) s (g x)
· simp
· intro s z
change lift _ (s • z) = s • lift _ z
induction z using TensorProduct.induction_on with
| zero => rw [smul_zero, map_zero, smul_zero]
| tmul s' x =>
rw [LinearMap.coe_mk, ExtendScalars.smul_tmul]
erw [lift.tmul, lift.tmul]
set s' : S := s'
change (s * s') • (g x) = s • s' • (g x)
rw [mul_smul]
| add _ _ ih1 ih2 => rw [smul_add, map_add, ih1, ih2, map_add, smul_add]
/-- Given `R`-module X and `S`-module Y, `S`-linear maps `(extendScalars f).obj X ⟶ Y`
bijectively correspond to `R`-linear maps `X ⟶ (restrictScalars f).obj Y`.
-/
@[simps symm_apply]
def homEquiv {X Y} :
((extendScalars f).obj X ⟶ Y) ≃ (X ⟶ (restrictScalars.{max v u₂, u₁, u₂} f).obj Y) where
toFun := HomEquiv.toRestrictScalars.{u₁,u₂,v} f
invFun := HomEquiv.fromExtendScalars.{u₁,u₂,v} f
left_inv g := by
letI m1 : Module R S := Module.compHom S f; letI m2 : Module R Y := Module.compHom Y f
apply hom_ext
apply LinearMap.ext; intro z
induction z using TensorProduct.induction_on with
| zero => rw [map_zero, map_zero]
| tmul x s =>
erw [TensorProduct.lift.tmul]
simp only [LinearMap.coe_mk]
change S at x
dsimp
erw [← LinearMap.map_smul, ExtendScalars.smul_tmul, mul_one x]
rfl
| add _ _ ih1 ih2 => rw [map_add, map_add, ih1, ih2]
right_inv g := by
letI m1 : Module R S := Module.compHom S f; letI m2 : Module R Y := Module.compHom Y f
ext x
rw [HomEquiv.toRestrictScalars_hom_apply]
-- This needs to be `erw` because of some unfolding in `fromExtendScalars`
erw [HomEquiv.fromExtendScalars_hom_apply]
rw [lift.tmul, LinearMap.coe_mk, LinearMap.coe_mk]
dsimp
rw [one_smul]
/--
For any `R`-module X, there is a natural `R`-linear map from `X` to `X ⨂ S` by sending `x ↦ x ⊗ 1`
-/
-- @[simps] Porting note: not in normal form and not used
def Unit.map {X} : X ⟶ (extendScalars f ⋙ restrictScalars f).obj X :=
-- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(Y := ...)`.
-- This suggests `restrictScalars` needs to be redesigned.
ofHom (Y := (extendScalars f ⋙ restrictScalars f).obj X)
{ toFun := fun x => (1 : S) ⊗ₜ[R,f] x
map_add' := fun x x' => by dsimp; rw [TensorProduct.tmul_add]
map_smul' := fun r x => by
letI m1 : Module R S := Module.compHom S f
dsimp; rw [← TensorProduct.smul_tmul,TensorProduct.smul_tmul'] }
/--
The natural transformation from identity functor on `R`-module to the composition of extension and
restriction of scalars.
-/
@[simps]
def unit : 𝟭 (ModuleCat R) ⟶ extendScalars f ⋙ restrictScalars.{max v u₂, u₁, u₂} f where
app _ := Unit.map.{u₁,u₂,v} f
/-- For any `S`-module Y, there is a natural `R`-linear map from `S ⨂ Y` to `Y` by
`s ⊗ y ↦ s • y` -/
@[simps! hom_apply]
def Counit.map {Y} : (restrictScalars f ⋙ extendScalars f).obj Y ⟶ Y :=
ofHom
{ toFun :=
letI m1 : Module R S := Module.compHom S f
letI m2 : Module R Y := Module.compHom Y f
TensorProduct.lift
{ toFun := fun s : S =>
{ toFun := fun y : Y => s • y,
map_add' := smul_add _
map_smul' := fun r y => by
change s • f r • y = f r • s • y
rw [← mul_smul, mul_comm, mul_smul] },
map_add' := fun s₁ s₂ => by
ext y
change (s₁ + s₂) • y = s₁ • y + s₂ • y
rw [add_smul]
map_smul' := fun r s => by
ext y
change (f r • s) • y = (f r) • s • y
rw [smul_eq_mul, mul_smul] }
map_add' := fun _ _ => by rw [map_add]
map_smul' := fun s z => by
let m1 : Module R S := Module.compHom S f
let m2 : Module R Y := Module.compHom Y f
induction z using TensorProduct.induction_on with
| zero => rw [smul_zero, map_zero, smul_zero]
| tmul s' y =>
rw [ExtendScalars.smul_tmul, LinearMap.coe_mk]
erw [TensorProduct.lift.tmul, TensorProduct.lift.tmul]
set s' : S := s'
change (s * s') • y = s • s' • y
rw [mul_smul]
| add _ _ ih1 ih2 => rw [smul_add, map_add, map_add, ih1, ih2, smul_add] }
/-- The natural transformation from the composition of restriction and extension of scalars to the
identity functor on `S`-module.
-/
@[simps app]
def counit : restrictScalars.{max v u₂, u₁, u₂} f ⋙ extendScalars f ⟶ 𝟭 (ModuleCat S) where
app _ := Counit.map.{u₁,u₂,v} f
naturality Y Y' g := by
-- Porting note: this is very annoying; fix instances in concrete categories
letI m1 : Module R S := Module.compHom S f
letI m2 : Module R Y := Module.compHom Y f
letI m2 : Module R Y' := Module.compHom Y' f
ext z
induction z using TensorProduct.induction_on with
| zero => rw [map_zero, map_zero]
| tmul s' y =>
dsimp
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [Counit.map_hom_apply]
rw [lift.tmul, LinearMap.coe_mk, LinearMap.coe_mk]
set s' : S := s'
change s' • g y = g (s' • y)
rw [map_smul]
| add _ _ ih₁ ih₂ => rw [map_add, map_add]; congr 1
end ExtendRestrictScalarsAdj
/-- Given commutative rings `R, S` and a ring hom `f : R →+* S`, the extension and restriction of
scalars by `f` are adjoint to each other.
-/
def extendRestrictScalarsAdj {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) :
extendScalars.{u₁, u₂, max v u₂} f ⊣ restrictScalars.{max v u₂, u₁, u₂} f :=
Adjunction.mk' {
homEquiv := fun _ _ ↦ ExtendRestrictScalarsAdj.homEquiv.{v,u₁,u₂} f
unit := ExtendRestrictScalarsAdj.unit.{v,u₁,u₂} f
counit := ExtendRestrictScalarsAdj.counit.{v,u₁,u₂} f
homEquiv_unit := fun {X Y g} ↦ hom_ext <| LinearMap.ext fun x => by
dsimp
rfl
homEquiv_counit := fun {X Y g} ↦ hom_ext <| LinearMap.ext fun x => by
induction x using TensorProduct.induction_on with
| zero => rw [map_zero, map_zero]
| tmul =>
rw [ExtendRestrictScalarsAdj.homEquiv_symm_apply]
dsimp
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [ExtendRestrictScalarsAdj.Counit.map_hom_apply,
ExtendRestrictScalarsAdj.HomEquiv.fromExtendScalars_hom_apply]
| add => rw [map_add, map_add]; congr 1 }
lemma extendRestrictScalarsAdj_homEquiv_apply
{R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S]
{f : R →+* S} {M : ModuleCat.{max v u₂} R} {N : ModuleCat S}
(φ : (extendScalars f).obj M ⟶ N) (m : M) :
(extendRestrictScalarsAdj f).homEquiv _ _ φ m = φ ((1 : S) ⊗ₜ m) :=
rfl
lemma extendRestrictScalarsAdj_unit_app_apply
{R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S]
(f : R →+* S) (M : ModuleCat.{max v u₂} R) (m : M) :
(extendRestrictScalarsAdj f).unit.app M m = (1 : S) ⊗ₜ[R,f] m :=
rfl
instance {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) :
(extendScalars.{u₁, u₂, max u₂ w} f).IsLeftAdjoint :=
(extendRestrictScalarsAdj f).isLeftAdjoint
instance {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) :
(restrictScalars.{max u₂ w, u₁, u₂} f).IsRightAdjoint :=
(extendRestrictScalarsAdj f).isRightAdjoint
noncomputable instance preservesLimit_restrictScalars
{R : Type*} {S : Type*} [Ring R] [Ring S] (f : R →+* S) {J : Type*} [Category J]
(F : J ⥤ ModuleCat.{v} S) [Small.{v} (F ⋙ forget _).sections] :
PreservesLimit F (restrictScalars f) :=
⟨fun {c} hc => ⟨by
have hc' := isLimitOfPreserves (forget₂ _ AddCommGrpCat) hc
exact isLimitOfReflects (forget₂ _ AddCommGrpCat) hc'⟩⟩
instance preservesColimit_restrictScalars {R S : Type*} [Ring R] [Ring S]
(f : R →+* S) {J : Type*} [Category J] (F : J ⥤ ModuleCat.{v} S)
[HasColimit (F ⋙ forget₂ _ AddCommGrpCat)] :
PreservesColimit F (ModuleCat.restrictScalars.{v} f) := by
have : HasColimit ((F ⋙ restrictScalars f) ⋙ forget₂ (ModuleCat R) AddCommGrpCat) :=
inferInstanceAs (HasColimit (F ⋙ forget₂ _ AddCommGrpCat))
apply preservesColimit_of_preserves_colimit_cocone (HasColimit.isColimitColimitCocone F)
apply isColimitOfReflects (forget₂ _ AddCommGrpCat)
apply isColimitOfPreserves (forget₂ (ModuleCat.{v} S) AddCommGrpCat.{v})
exact HasColimit.isColimitColimitCocone F
variable (R) in
/-- The extension of scalars by the identity of a ring is isomorphic to the
identity functor. -/
noncomputable def extendScalarsId : extendScalars (RingHom.id R) ≅ 𝟭 _ :=
((conjugateIsoEquiv (extendRestrictScalarsAdj (RingHom.id R)) Adjunction.id).symm
(restrictScalarsId R)).symm
lemma extendScalarsId_inv_app_apply (M : ModuleCat R) (m : M) :
(extendScalarsId R).inv.app M m = (1 : R) ⊗ₜ m := rfl
lemma homEquiv_extendScalarsId (M : ModuleCat R) :
(extendRestrictScalarsAdj (RingHom.id R)).homEquiv _ _ ((extendScalarsId R).hom.app M) =
(restrictScalarsId R).inv.app M := by
ext m
rw [extendRestrictScalarsAdj_homEquiv_apply, ← extendScalarsId_inv_app_apply, ← comp_apply]
simp
lemma extendScalarsId_hom_app_one_tmul (M : ModuleCat R) (m : M) :
(extendScalarsId R).hom.app M ((1 : R) ⊗ₜ m) = m := by
rw [← extendRestrictScalarsAdj_homEquiv_apply,
homEquiv_extendScalarsId]
dsimp
section
variable {R₁ R₂ R₃ R₄ : Type u₁} [CommRing R₁] [CommRing R₂] [CommRing R₃] [CommRing R₄]
(f₁₂ : R₁ →+* R₂) (f₂₃ : R₂ →+* R₃) (f₃₄ : R₃ →+* R₄)
/-- The extension of scalars by a composition of commutative ring morphisms
identifies to the composition of the extension of scalars functors. -/
noncomputable def extendScalarsComp :
extendScalars (f₂₃.comp f₁₂) ≅ extendScalars f₁₂ ⋙ extendScalars f₂₃ :=
(conjugateIsoEquiv
((extendRestrictScalarsAdj f₁₂).comp (extendRestrictScalarsAdj f₂₃))
(extendRestrictScalarsAdj (f₂₃.comp f₁₂))).symm (restrictScalarsComp f₁₂ f₂₃).symm
lemma homEquiv_extendScalarsComp (M : ModuleCat R₁) :
(extendRestrictScalarsAdj (f₂₃.comp f₁₂)).homEquiv _ _
((extendScalarsComp f₁₂ f₂₃).hom.app M) =
(extendRestrictScalarsAdj f₁₂).unit.app M ≫
(restrictScalars f₁₂).map ((extendRestrictScalarsAdj f₂₃).unit.app _) ≫
(restrictScalarsComp f₁₂ f₂₃).inv.app _ := by
dsimp [extendScalarsComp, conjugateIsoEquiv, conjugateEquiv]
simp only [Category.assoc, Category.id_comp, Category.comp_id,
Adjunction.comp_unit_app, Adjunction.homEquiv_unit,
Functor.map_comp, Adjunction.unit_naturality_assoc,
Adjunction.right_triangle_components]
rfl
lemma extendScalarsComp_hom_app_one_tmul (M : ModuleCat R₁) (m : M) :
(extendScalarsComp f₁₂ f₂₃).hom.app M ((1 : R₃) ⊗ₜ m) =
(1 : R₃) ⊗ₜ[R₂,f₂₃] ((1 : R₂) ⊗ₜ[R₁,f₁₂] m) := by
rw [← extendRestrictScalarsAdj_homEquiv_apply, homEquiv_extendScalarsComp]
rfl
@[reassoc]
lemma extendScalars_assoc :
(extendScalarsComp (f₂₃.comp f₁₂) f₃₄).hom ≫
Functor.whiskerRight (extendScalarsComp f₁₂ f₂₃).hom _ =
(extendScalarsComp f₁₂ (f₃₄.comp f₂₃)).hom ≫
Functor.whiskerLeft _ (extendScalarsComp f₂₃ f₃₄).hom ≫
(Functor.associator _ _ _).inv := by
ext M m
have h₁ := extendScalarsComp_hom_app_one_tmul (f₂₃.comp f₁₂) f₃₄ M m
have h₂ := extendScalarsComp_hom_app_one_tmul f₁₂ (f₃₄.comp f₂₃) M m
have h₃ := extendScalarsComp_hom_app_one_tmul f₂₃ f₃₄
have h₄ := extendScalarsComp_hom_app_one_tmul f₁₂ f₂₃ M m
dsimp at h₁ h₂ h₃ h₄ ⊢
rw [h₁]
erw [h₂]
rw [h₃, ExtendScalars.map_tmul, h₄]
/-- The associativity compatibility for the extension of scalars, in the exact form
that is needed in the definition `CommRingCat.moduleCatExtendScalarsPseudofunctor`
in the file `Algebra.Category.ModuleCat.Pseudofunctor` -/
lemma extendScalars_assoc' :
(extendScalarsComp (f₂₃.comp f₁₂) f₃₄).hom ≫
Functor.whiskerRight (extendScalarsComp f₁₂ f₂₃).hom _ ≫
(Functor.associator _ _ _).hom ≫
Functor.whiskerLeft _ (extendScalarsComp f₂₃ f₃₄).inv ≫
(extendScalarsComp f₁₂ (f₃₄.comp f₂₃)).inv = 𝟙 _ := by
rw [extendScalars_assoc_assoc]
simp only [Iso.inv_hom_id_assoc, ← Functor.whiskerLeft_comp_assoc, Iso.hom_inv_id,
Functor.whiskerLeft_id', Category.id_comp]
@[reassoc]
lemma extendScalars_id_comp :
(extendScalarsComp (RingHom.id R₁) f₁₂).hom ≫ Functor.whiskerRight (extendScalarsId R₁).hom _ ≫
(Functor.leftUnitor _).hom = 𝟙 _ := by
ext M m
dsimp
erw [extendScalarsComp_hom_app_one_tmul (RingHom.id R₁) f₁₂ M m]
rw [ExtendScalars.map_tmul]
erw [extendScalarsId_hom_app_one_tmul]
rfl
@[reassoc]
lemma extendScalars_comp_id :
(extendScalarsComp f₁₂ (RingHom.id R₂)).hom ≫ Functor.whiskerLeft _ (extendScalarsId R₂).hom ≫
(Functor.rightUnitor _).hom = 𝟙 _ := by
ext M m
dsimp
erw [extendScalarsComp_hom_app_one_tmul f₁₂ (RingHom.id R₂) M m,
extendScalarsId_hom_app_one_tmul]
rfl
end
end ModuleCat
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Adjunctions.lean | import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic
import Mathlib.CategoryTheory.Monoidal.Types.Basic
import Mathlib.LinearAlgebra.DirectSum.Finsupp
import Mathlib.CategoryTheory.Linear.LinearFunctor
/-!
The functor of forming finitely supported functions on a type with values in a `[Ring R]`
is the left adjoint of
the forgetful functor from `R`-modules to types.
-/
assert_not_exists Cardinal
noncomputable section
open CategoryTheory
namespace ModuleCat
universe u
variable (R : Type u)
section
variable [Ring R]
/-- The free functor `Type u ⥤ ModuleCat R` sending a type `X` to the
free `R`-module with generators `x : X`, implemented as the type `X →₀ R`.
-/
def free : Type u ⥤ ModuleCat R where
obj X := ModuleCat.of R (X →₀ R)
map {_ _} f := ofHom <| Finsupp.lmapDomain _ _ f
map_id := by intros; ext : 1; exact Finsupp.lmapDomain_id _ _
map_comp := by intros; ext : 1; exact Finsupp.lmapDomain_comp _ _ _ _
variable {R}
/-- Constructor for elements in the module `(free R).obj X`. -/
noncomputable def freeMk {X : Type u} (x : X) : (free R).obj X := Finsupp.single x 1
@[ext 1200]
lemma free_hom_ext {X : Type u} {M : ModuleCat.{u} R} {f g : (free R).obj X ⟶ M}
(h : ∀ (x : X), f (freeMk x) = g (freeMk x)) :
f = g :=
ModuleCat.hom_ext (Finsupp.lhom_ext' (fun x ↦ LinearMap.ext_ring (h x)))
/-- The morphism of modules `(free R).obj X ⟶ M` corresponding
to a map `f : X ⟶ M`. -/
noncomputable def freeDesc {X : Type u} {M : ModuleCat.{u} R} (f : X ⟶ M) :
(free R).obj X ⟶ M :=
ofHom <| Finsupp.lift M R X f
@[simp]
lemma freeDesc_apply {X : Type u} {M : ModuleCat.{u} R} (f : X ⟶ M) (x : X) :
freeDesc f (freeMk x) = f x := by
dsimp [freeDesc]
erw [Finsupp.lift_apply, Finsupp.sum_single_index]
all_goals simp
@[simp]
lemma free_map_apply {X Y : Type u} (f : X → Y) (x : X) :
(free R).map f (freeMk x) = freeMk (f x) := by
apply Finsupp.mapDomain_single
/-- The bijection `((free R).obj X ⟶ M) ≃ (X → M)` when `X` is a type and `M` a module. -/
@[simps]
def freeHomEquiv {X : Type u} {M : ModuleCat.{u} R} :
((free R).obj X ⟶ M) ≃ (X → M) where
toFun φ x := φ (freeMk x)
invFun ψ := freeDesc ψ
left_inv _ := by ext; simp
right_inv _ := by ext; simp
variable (R)
/-- The free-forgetful adjunction for R-modules.
-/
def adj : free R ⊣ forget (ModuleCat.{u} R) :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun _ _ => freeHomEquiv
homEquiv_naturality_left_symm := fun {X Y M} f g ↦ by ext; simp [freeHomEquiv] }
@[simp]
lemma adj_homEquiv (X : Type u) (M : ModuleCat.{u} R) :
(adj R).homEquiv X M = freeHomEquiv := by
simp only [adj, Adjunction.mkOfHomEquiv_homEquiv]
instance : (forget (ModuleCat.{u} R)).IsRightAdjoint :=
(adj R).isRightAdjoint
end
section Free
open MonoidalCategory
variable [CommRing R]
namespace FreeMonoidal
/-- The canonical isomorphism `𝟙_ (ModuleCat R) ≅ (free R).obj (𝟙_ (Type u))`.
(This should not be used directly: it is part of the implementation of the
monoidal structure on the functor `free R`.) -/
def εIso : 𝟙_ (ModuleCat R) ≅ (free R).obj (𝟙_ (Type u)) where
hom := ofHom <| Finsupp.lsingle PUnit.unit
inv := ofHom <| Finsupp.lapply PUnit.unit
hom_inv_id := by
ext
simp [free]
inv_hom_id := by
ext ⟨⟩
dsimp [freeMk]
erw [Finsupp.lapply_apply, Finsupp.lsingle_apply]
rw [Finsupp.single_eq_same]
@[simp]
lemma εIso_hom_one : (εIso R).hom 1 = freeMk PUnit.unit := rfl
@[simp]
lemma εIso_inv_freeMk (x : PUnit) : (εIso R).inv (freeMk x) = 1 := by
dsimp [εIso, freeMk]
erw [Finsupp.lapply_apply]
rw [Finsupp.single_eq_same]
/-- The canonical isomorphism `(free R).obj X ⊗ (free R).obj Y ≅ (free R).obj (X ⊗ Y)`
for two types `X` and `Y`.
(This should not be used directly: it is part of the implementation of the
monoidal structure on the functor `free R`.) -/
def μIso (X Y : Type u) :
(free R).obj X ⊗ (free R).obj Y ≅ (free R).obj (X ⊗ Y) :=
(finsuppTensorFinsupp' R _ _).toModuleIso
@[simp]
lemma μIso_hom_freeMk_tmul_freeMk {X Y : Type u} (x : X) (y : Y) :
(μIso R X Y).hom (freeMk x ⊗ₜ freeMk y) = freeMk ⟨x, y⟩ := by
dsimp [μIso, freeMk]
erw [finsuppTensorFinsupp'_single_tmul_single]
rw [mul_one]
@[simp]
lemma μIso_inv_freeMk {X Y : Type u} (z : X ⊗ Y) :
(μIso R X Y).inv (freeMk z) = freeMk z.1 ⊗ₜ freeMk z.2 := by
dsimp [μIso, freeMk]
erw [finsuppTensorFinsupp'_symm_single_eq_single_one_tmul]
end FreeMonoidal
open FreeMonoidal in
/-- The free functor `Type u ⥤ ModuleCat R` is a monoidal functor. -/
instance : (free R).Monoidal :=
Functor.CoreMonoidal.toMonoidal
{ εIso := εIso R
μIso := μIso R
μIso_hom_natural_left := fun {X Y} f X' ↦ by
rw [← cancel_epi (μIso R X X').inv]
aesop
μIso_hom_natural_right := fun {X Y} X' f ↦ by
rw [← cancel_epi (μIso R X' X).inv]
aesop
associativity := fun X Y Z ↦ by
rw [← cancel_epi ((μIso R X Y).inv ▷ _), ← cancel_epi (μIso R _ _).inv]
ext ⟨⟨x, y⟩, z⟩
dsimp
rw [μIso_inv_freeMk, MonoidalCategory.whiskerRight_apply, μIso_inv_freeMk,
MonoidalCategory.whiskerRight_apply, μIso_hom_freeMk_tmul_freeMk,
μIso_hom_freeMk_tmul_freeMk, free_map_apply,
CategoryTheory.associator_hom_apply, MonoidalCategory.associator_hom_apply,
MonoidalCategory.whiskerLeft_apply, μIso_hom_freeMk_tmul_freeMk,
μIso_hom_freeMk_tmul_freeMk]
left_unitality := fun X ↦ by
rw [← cancel_epi (λ_ _).inv, Iso.inv_hom_id]
aesop
right_unitality := fun X ↦ by
rw [← cancel_epi (ρ_ _).inv, Iso.inv_hom_id]
aesop }
open Functor.LaxMonoidal Functor.OplaxMonoidal
@[simp]
lemma free_ε_one : ε (free R) 1 = freeMk PUnit.unit := rfl
@[simp]
lemma free_η_freeMk (x : PUnit) : η (free R) (freeMk x) = 1 := by
apply FreeMonoidal.εIso_inv_freeMk
@[simp]
lemma free_μ_freeMk_tmul_freeMk {X Y : Type u} (x : X) (y : Y) :
μ (free R) _ _ (freeMk x ⊗ₜ freeMk y) = freeMk ⟨x, y⟩ := by
apply FreeMonoidal.μIso_hom_freeMk_tmul_freeMk
@[simp]
lemma free_δ_freeMk {X Y : Type u} (z : X ⊗ Y) :
δ (free R) _ _ (freeMk z) = freeMk z.1 ⊗ₜ freeMk z.2 := by
apply FreeMonoidal.μIso_inv_freeMk
end Free
end ModuleCat
namespace CategoryTheory
universe v u
/-- `Free R C` is a type synonym for `C`, which, given `[CommRing R]` and `[Category C]`,
we will equip with a category structure where the morphisms are formal `R`-linear combinations
of the morphisms in `C`.
-/
@[nolint unusedArguments]
def Free (_ : Type*) (C : Type u) :=
C
/-- Consider an object of `C` as an object of the `R`-linear completion.
It may be preferable to use `(Free.embedding R C).obj X` instead;
this functor can also be used to lift morphisms.
-/
def Free.of (R : Type*) {C : Type u} (X : C) : Free R C :=
X
variable (R : Type*) [CommRing R] (C : Type u) [Category.{v} C]
open Finsupp
-- Conceptually, it would be nice to construct this via "transport of enrichment",
-- using the fact that `ModuleCat.Free R : Type ⥤ ModuleCat R` and `ModuleCat.forget` are both lax
-- monoidal. This still seems difficult, so we just do it by hand.
instance categoryFree : Category (Free R C) where
Hom := fun X Y : C => (X ⟶ Y) →₀ R
id := fun X : C => Finsupp.single (𝟙 X) 1
comp {X _ Z : C} f g :=
(f.sum (fun f' s => g.sum (fun g' t => Finsupp.single (f' ≫ g') (s * t))) : (X ⟶ Z) →₀ R)
assoc {W X Y Z} f g h := by
-- This imitates the proof of associativity for `MonoidAlgebra`.
simp only [sum_sum_index, sum_single_index, single_zero, single_add,
forall_true_iff, add_mul, mul_add, Category.assoc, mul_assoc,
zero_mul, mul_zero, sum_zero, sum_add]
namespace Free
section
instance : Preadditive (Free R C) where
homGroup _ _ := Finsupp.instAddCommGroup
add_comp X Y Z f f' g := by
dsimp [CategoryTheory.categoryFree]
rw [Finsupp.sum_add_index'] <;> · simp [add_mul]
comp_add X Y Z f g g' := by
dsimp [CategoryTheory.categoryFree]
rw [← Finsupp.sum_add]
congr; ext r h
rw [Finsupp.sum_add_index'] <;> · simp [mul_add]
instance : Linear R (Free R C) where
homModule _ _ := Finsupp.module _ R
smul_comp X Y Z r f g := by
dsimp [CategoryTheory.categoryFree]
rw [Finsupp.sum_smul_index] <;> simp [Finsupp.smul_sum, mul_assoc]
comp_smul X Y Z f r g := by
dsimp [CategoryTheory.categoryFree]
simp_rw [Finsupp.smul_sum]
congr; ext h s
rw [Finsupp.sum_smul_index] <;> simp [mul_left_comm]
theorem single_comp_single {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (r s : R) :
(single f r ≫ single g s : Free.of R X ⟶ Free.of R Z) = single (f ≫ g) (r * s) := by
dsimp [CategoryTheory.categoryFree]; simp
end
attribute [local simp] single_comp_single
/-- A category embeds into its `R`-linear completion.
-/
@[simps]
def embedding : C ⥤ Free R C where
obj X := X
map {_ _} f := Finsupp.single f 1
map_id _ := rfl
map_comp {X Y Z} f g := by
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10959): simp used to be able to close this goal
rw [single_comp_single, one_mul]
variable {C} {D : Type u} [Category.{v} D] [Preadditive D] [Linear R D]
open Preadditive Linear
/-- A functor to an `R`-linear category lifts to a functor from its `R`-linear completion.
-/
@[simps]
def lift (F : C ⥤ D) : Free R C ⥤ D where
obj X := F.obj X
map {_ _} f := f.sum fun f' r => r • F.map f'
map_id := by dsimp [CategoryTheory.categoryFree]; simp
map_comp {X Y Z} f g := by
induction f using Finsupp.induction_linear with
| zero => simp
| add f₁ f₂ w₁ w₂ =>
rw [add_comp]
rw [Finsupp.sum_add_index', Finsupp.sum_add_index']
· simp only [w₁, w₂, add_comp]
· intros; rw [zero_smul]
· intros; simp only [add_smul]
· intros; rw [zero_smul]
· intros; simp only [add_smul]
| single f' r =>
induction g using Finsupp.induction_linear with
| zero => simp
| add f₁ f₂ w₁ w₂ =>
rw [comp_add]
rw [Finsupp.sum_add_index', Finsupp.sum_add_index']
· simp only [w₁, w₂, comp_add]
· intros; rw [zero_smul]
· intros; simp only [add_smul]
· intros; rw [zero_smul]
· intros; simp only [add_smul]
| single g' s =>
rw [single_comp_single _ _ f' g' r s]
simp [mul_comm r s, mul_smul]
theorem lift_map_single (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) (r : R) :
(lift R F).map (single f r) = r • F.map f := by simp
instance lift_additive (F : C ⥤ D) : (lift R F).Additive where
map_add {X Y} f g := by
dsimp
rw [Finsupp.sum_add_index'] <;> simp [add_smul]
instance lift_linear (F : C ⥤ D) : (lift R F).Linear R where
map_smul {X Y} f r := by
dsimp
rw [Finsupp.sum_smul_index] <;> simp [Finsupp.smul_sum, mul_smul]
/-- The embedding into the `R`-linear completion, followed by the lift,
is isomorphic to the original functor.
-/
def embeddingLiftIso (F : C ⥤ D) : embedding R C ⋙ lift R F ≅ F :=
NatIso.ofComponents fun _ => Iso.refl _
/-- Two `R`-linear functors out of the `R`-linear completion are isomorphic iff their
compositions with the embedding functor are isomorphic.
-/
def ext {F G : Free R C ⥤ D} [F.Additive] [F.Linear R] [G.Additive] [G.Linear R]
(α : embedding R C ⋙ F ≅ embedding R C ⋙ G) : F ≅ G :=
NatIso.ofComponents (fun X => α.app X)
(by
intro X Y f
induction f using Finsupp.induction_linear with
| zero => simp
| add f₁ f₂ w₁ w₂ =>
rw [Functor.map_add, add_comp, w₁, w₂, Functor.map_add, comp_add]
| single f' r =>
rw [Iso.app_hom, Iso.app_hom, ← smul_single_one, F.map_smul, G.map_smul, smul_comp,
comp_smul]
change r • (embedding R C ⋙ F).map f' ≫ _ = r • _ ≫ (embedding R C ⋙ G).map f'
rw [α.hom.naturality f'])
/-- `Free.lift` is unique amongst `R`-linear functors `Free R C ⥤ D`
which compose with `embedding ℤ C` to give the original functor.
-/
def liftUnique (F : C ⥤ D) (L : Free R C ⥤ D) [L.Additive] [L.Linear R]
(α : embedding R C ⋙ L ≅ F) : L ≅ lift R F :=
ext R (α.trans (embeddingLiftIso R F).symm)
end Free
end CategoryTheory |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Free.lean | import Mathlib.LinearAlgebra.Dimension.Free
import Mathlib.Algebra.Homology.ShortComplex.ModuleCat
/-!
# Exact sequences with free modules
This file proves results about linear independence and span in exact sequences of modules.
## Main theorems
* `linearIndependent_shortExact`: Given a short exact sequence `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of
`R`-modules and linearly independent families `v : ι → X₁` and `w : ι' → X₃`, we get a linearly
independent family `ι ⊕ ι' → X₂`
* `span_rightExact`: Given an exact sequence `X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of `R`-modules and spanning
families `v : ι → X₁` and `w : ι' → X₃`, we get a spanning family `ι ⊕ ι' → X₂`
* Using `linearIndependent_shortExact` and `span_rightExact`, we prove `free_shortExact`: In a
short exact sequence `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` where `X₁` and `X₃` are free, `X₂` is free as well.
## Tags
linear algebra, module, free
-/
open CategoryTheory Module
namespace ModuleCat
variable {ι ι' R : Type*} [Ring R] {S : ShortComplex (ModuleCat R)}
(hS : S.Exact) (hS' : S.ShortExact) {v : ι → S.X₁}
open CategoryTheory Submodule Set
section LinearIndependent
variable (hv : LinearIndependent R v) {u : ι ⊕ ι' → S.X₂}
(hw : LinearIndependent R (S.g ∘ u ∘ Sum.inr))
(hm : Mono S.f) (huv : u ∘ Sum.inl = S.f ∘ v)
section
include hS hw huv
theorem disjoint_span_sum : Disjoint (span R (range (u ∘ Sum.inl)))
(span R (range (u ∘ Sum.inr))) := by
rw [huv, disjoint_comm]
refine Disjoint.mono_right (span_mono (range_comp_subset_range _ _)) ?_
rw [← LinearMap.coe_range, span_eq (LinearMap.range S.f.hom), hS.moduleCat_range_eq_ker]
exact range_ker_disjoint hw
include hv hm in
/-- In the commutative diagram
```
f g
0 --→ X₁ --→ X₂ --→ X₃
↑ ↑ ↑
v| u| w|
ι → ι ⊕ ι' ← ι'
```
where the top row is an exact sequence of modules and the maps on the bottom are `Sum.inl` and
`Sum.inr`. If `u` is injective and `v` and `w` are linearly independent, then `u` is linearly
independent. -/
theorem linearIndependent_leftExact : LinearIndependent R u := by
rw [linearIndependent_sum]
refine ⟨?_, LinearIndependent.of_comp S.g.hom hw, disjoint_span_sum hS hw huv⟩
rw [huv, LinearMap.linearIndependent_iff S.f.hom]; swap
· rw [LinearMap.ker_eq_bot, ← mono_iff_injective]
infer_instance
exact hv
end
include hS' hv in
/-- Given a short exact sequence `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of `R`-modules and linearly independent
families `v : ι → N` and `w : ι' → P`, we get a linearly independent family `ι ⊕ ι' → M` -/
theorem linearIndependent_shortExact {w : ι' → S.X₃} (hw : LinearIndependent R w) :
LinearIndependent R (Sum.elim (S.f ∘ v) (S.g.hom.toFun.invFun ∘ w)) := by
apply linearIndependent_leftExact hS'.exact hv _ hS'.mono_f rfl
dsimp
convert hw
ext
apply Function.rightInverse_invFun ((epi_iff_surjective _).mp hS'.epi_g)
end LinearIndependent
section Span
include hS in
/-- In the commutative diagram
```
f g
X₁ --→ X₂ --→ X₃
↑ ↑ ↑
v| u| w|
ι → ι ⊕ ι' ← ι'
```
where the top row is an exact sequence of modules and the maps on the bottom are `Sum.inl` and
`Sum.inr`. If `v` spans `X₁` and `w` spans `X₃`, then `u` spans `X₂`. -/
theorem span_exact {β : Type*} {u : ι ⊕ β → S.X₂} (huv : u ∘ Sum.inl = S.f ∘ v)
(hv : ⊤ ≤ span R (range v))
(hw : ⊤ ≤ span R (range (S.g ∘ u ∘ Sum.inr))) :
⊤ ≤ span R (range u) := by
intro m _
have hgm : S.g m ∈ span R (range (S.g ∘ u ∘ Sum.inr)) := hw mem_top
rw [Finsupp.mem_span_range_iff_exists_finsupp] at hgm
obtain ⟨cm, hm⟩ := hgm
let m' : S.X₂ := Finsupp.sum cm fun j a ↦ a • (u (Sum.inr j))
have hsub : m - m' ∈ LinearMap.range S.f.hom := by
rw [hS.moduleCat_range_eq_ker]
simp only [LinearMap.mem_ker, map_sub, sub_eq_zero]
rw [← hm, map_finsuppSum]
simp only [Function.comp_apply, map_smul]
obtain ⟨n, hnm⟩ := hsub
have hn : n ∈ span R (range v) := hv mem_top
rw [Finsupp.mem_span_range_iff_exists_finsupp] at hn
obtain ⟨cn, hn⟩ := hn
rw [← hn, map_finsuppSum] at hnm
rw [← sub_add_cancel m m', ← hnm,]
simp only [map_smul]
have hn' : (Finsupp.sum cn fun a b ↦ b • S.f (v a)) =
(Finsupp.sum cn fun a b ↦ b • u (Sum.inl a)) := by
congr; ext a b; rw [← Function.comp_apply (f := S.f), ← huv, Function.comp_apply]
rw [hn']
apply add_mem
· rw [Finsupp.mem_span_range_iff_exists_finsupp]
use cn.mapDomain (Sum.inl)
rw [Finsupp.sum_mapDomain_index_inj Sum.inl_injective]
· rw [Finsupp.mem_span_range_iff_exists_finsupp]
use cm.mapDomain (Sum.inr)
rw [Finsupp.sum_mapDomain_index_inj Sum.inr_injective]
include hS in
/-- Given an exact sequence `X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of `R`-modules and spanning
families `v : ι → X₁` and `w : ι' → X₃`, we get a spanning family `ι ⊕ ι' → X₂` -/
theorem span_rightExact {w : ι' → S.X₃} (hv : ⊤ ≤ span R (range v))
(hw : ⊤ ≤ span R (range w)) (hE : Epi S.g) :
⊤ ≤ span R (range (Sum.elim (S.f ∘ v) (S.g.hom.toFun.invFun ∘ w))) := by
refine span_exact hS ?_ hv ?_
· simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Sum.elim_comp_inl]
· convert hw
simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Sum.elim_comp_inr]
rw [ModuleCat.epi_iff_surjective] at hE
rw [← Function.comp_assoc, Function.RightInverse.comp_eq_id (Function.rightInverse_invFun hE),
Function.id_comp]
end Span
/-- In a short exact sequence `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0`, given bases for `X₁` and `X₃`
indexed by `ι` and `ι'` respectively, we get a basis for `X₂` indexed by `ι ⊕ ι'`. -/
noncomputable
def Basis.ofShortExact
(bN : Basis ι R S.X₁) (bP : Basis ι' R S.X₃) : Basis (ι ⊕ ι') R S.X₂ :=
Basis.mk (linearIndependent_shortExact hS' bN.linearIndependent bP.linearIndependent)
(span_rightExact hS'.exact (le_of_eq (bN.span_eq.symm)) (le_of_eq (bP.span_eq.symm)) hS'.epi_g)
include hS'
/-- In a short exact sequence `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0`, if `X₁` and `X₃` are free,
then `X₂` is free. -/
theorem free_shortExact [Module.Free R S.X₁] [Module.Free R S.X₃] :
Module.Free R S.X₂ :=
Module.Free.of_basis (Basis.ofShortExact hS' (Module.Free.chooseBasis R S.X₁)
(Module.Free.chooseBasis R S.X₃))
theorem free_shortExact_rank_add [Module.Free R S.X₁] [Module.Free R S.X₃]
[StrongRankCondition R] :
Module.rank R S.X₂ = Module.rank R S.X₁ + Module.rank R S.X₃ := by
haveI := free_shortExact hS'
rw [Module.Free.rank_eq_card_chooseBasisIndex, Module.Free.rank_eq_card_chooseBasisIndex R S.X₁,
Module.Free.rank_eq_card_chooseBasisIndex R S.X₃, Cardinal.add_def, Cardinal.eq]
exact ⟨Basis.indexEquiv (Module.Free.chooseBasis R S.X₂) (Basis.ofShortExact hS'
(Module.Free.chooseBasis R S.X₁) (Module.Free.chooseBasis R S.X₃))⟩
theorem free_shortExact_finrank_add {n p : ℕ} [Module.Free R S.X₁] [Module.Free R S.X₃]
[Module.Finite R S.X₁] [Module.Finite R S.X₃]
(hN : Module.finrank R S.X₁ = n)
(hP : Module.finrank R S.X₃ = p)
[StrongRankCondition R] :
finrank R S.X₂ = n + p := by
apply finrank_eq_of_rank_eq
rw [free_shortExact_rank_add hS', ← hN, ← hP]
simp only [Nat.cast_add, finrank_eq_rank]
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Images.lean | import Mathlib.Algebra.Category.ModuleCat.Abelian
import Mathlib.CategoryTheory.Limits.Shapes.Images
/-!
# The category of R-modules has images.
Note that we don't need to register any of the constructions here as instances, because we get them
from the fact that `ModuleCat R` is an abelian category.
-/
open CategoryTheory
open CategoryTheory.Limits
universe u v
namespace ModuleCat
variable {R : Type u} [Ring R]
variable {G H : ModuleCat.{v} R} (f : G ⟶ H)
attribute [local ext] Subtype.ext
section
-- implementation details of `HasImage` for ModuleCat; use the API, not these
/-- The image of a morphism in `ModuleCat R` is just the bundling of `LinearMap.range f` -/
def image : ModuleCat R :=
ModuleCat.of R (LinearMap.range f.hom)
/-- The inclusion of `image f` into the target -/
def image.ι : image f ⟶ H :=
ofHom (LinearMap.range f.hom).subtype
instance : Mono (image.ι f) :=
ConcreteCategory.mono_of_injective (image.ι f) Subtype.val_injective
/-- The corestriction map to the image -/
def factorThruImage : G ⟶ image f :=
ofHom f.hom.rangeRestrict
theorem image.fac : factorThruImage f ≫ image.ι f = f :=
rfl
attribute [local simp] image.fac
variable {f}
/-- The universal property for the image factorisation -/
noncomputable def image.lift (F' : MonoFactorisation f) : image f ⟶ F'.I :=
ofHom
{ toFun := (fun x => F'.e (Classical.indefiniteDescription _ x.2).1 : image f → F'.I)
map_add' := fun x y => by
apply (mono_iff_injective F'.m).1
· infer_instance
rw [LinearMap.map_add]
change (F'.e ≫ F'.m) _ = (F'.e ≫ F'.m) _ + (F'.e ≫ F'.m) _
simp_rw [F'.fac, (Classical.indefiniteDescription (fun z => f z = _) _).2]
rfl
map_smul' := fun c x => by
apply (mono_iff_injective F'.m).1
· infer_instance
rw [LinearMap.map_smul]
change (F'.e ≫ F'.m) _ = _ • (F'.e ≫ F'.m) _
simp_rw [F'.fac, (Classical.indefiniteDescription (fun z => f z = _) _).2]
rfl }
theorem image.lift_fac (F' : MonoFactorisation f) : image.lift F' ≫ F'.m = image.ι f := by
ext x
change (F'.e ≫ F'.m) _ = _
rw [F'.fac, (Classical.indefiniteDescription _ x.2).2]
rfl
end
/-- The factorisation of any morphism in `ModuleCat R` through a mono. -/
def monoFactorisation : MonoFactorisation f where
I := image f
m := image.ι f
e := factorThruImage f
/-- The factorisation of any morphism in `ModuleCat R` through a mono has the universal property of
the image. -/
noncomputable def isImage : IsImage (monoFactorisation f) where
lift := image.lift
lift_fac := image.lift_fac
/-- The categorical image of a morphism in `ModuleCat R` agrees with the linear algebraic range. -/
noncomputable def imageIsoRange {G H : ModuleCat.{v} R} (f : G ⟶ H) :
Limits.image f ≅ ModuleCat.of R (LinearMap.range f.hom) :=
IsImage.isoExt (Image.isImage f) (isImage f)
@[simp, reassoc, elementwise]
theorem imageIsoRange_inv_image_ι {G H : ModuleCat.{v} R} (f : G ⟶ H) :
(imageIsoRange f).inv ≫ Limits.image.ι f = ModuleCat.ofHom (LinearMap.range f.hom).subtype :=
IsImage.isoExt_inv_m _ _
@[simp, reassoc, elementwise]
theorem imageIsoRange_hom_subtype {G H : ModuleCat.{v} R} (f : G ⟶ H) :
(imageIsoRange f).hom ≫ ModuleCat.ofHom (LinearMap.range f.hom).subtype = Limits.image.ι f := by
rw [← imageIsoRange_inv_image_ι f, Iso.hom_inv_id_assoc]
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Topology/Basic.lean | import Mathlib.Algebra.Category.ModuleCat.Colimits
import Mathlib.Algebra.Category.ModuleCat.Limits
import Mathlib.Topology.Algebra.Module.ModuleTopology
import Mathlib.Topology.Category.TopCat.Limits.Basic
/-!
# The category `TopModuleCat R` of topological modules
We define `TopModuleCat R`, the category of topological modules, and show that
it has all limits and colimits.
We also provide various adjunctions:
- `TopModuleCat.withModuleTopologyAdj`:
equipping the module topology is left adjoint to the forgetful functor into `ModuleCat R`.
- `TopModuleCat.indiscreteAdj`:
equipping the indiscrete topology is right adjoint to the forgetful functor into `ModuleCat R`.
- `TopModuleCat.freeAdj`:
the free-forgetful adjunction between `TopModuleCat R` and `TopCat`.
## Future projects
Show that the forgetful functor to `TopCat` preserves filtered colimits.
-/
universe v u
variable (R : Type u) [Ring R] [TopologicalSpace R]
open CategoryTheory ConcreteCategory
/-- The category of topological modules. -/
structure TopModuleCat extends ModuleCat.{v} R where
/-- The underlying topological space. -/
[topologicalSpace : TopologicalSpace carrier]
[isTopologicalAddGroup : IsTopologicalAddGroup carrier]
[continuousSMul : ContinuousSMul R carrier]
namespace TopModuleCat
noncomputable instance : CoeSort (TopModuleCat.{v} R) (Type v) := ⟨fun M ↦ M.toModuleCat⟩
attribute [instance] topologicalSpace isTopologicalAddGroup continuousSMul
/-- Make an object in `TopModuleCat R` from an unbundled topological module. -/
abbrev of (M : Type v) [AddCommGroup M] [Module R M] [TopologicalSpace M] [ContinuousAdd M]
[ContinuousSMul R M] : TopModuleCat R :=
have : ContinuousNeg M := ⟨by convert continuous_const_smul (-1 : R) (T := M); ext; simp⟩
have : IsTopologicalAddGroup M := ⟨⟩
⟨.of R M⟩
lemma coe_of (M : Type v) [AddCommGroup M] [Module R M] [TopologicalSpace M] [ContinuousAdd M]
[ContinuousSMul R M] : (of R M) = M := rfl
variable {R} in
/-- Homs in `TopModuleCat` as one field structures over `ContinuousLinearMap`. -/
structure Hom (X Y : TopModuleCat.{v} R) where
-- use `ofHom` instead
private ofHom' ::
/-- The underlying continuous linear map. Use `hom` instead. -/
hom' : X →L[R] Y
instance : Category (TopModuleCat R) where
Hom := Hom
id M := ⟨ContinuousLinearMap.id R M⟩
comp φ ψ := ⟨ψ.hom' ∘L φ.hom'⟩
instance : ConcreteCategory (TopModuleCat R) (· →L[R] ·) where
hom := Hom.hom'
ofHom := Hom.ofHom'
variable {R} in
/-- Cast a hom in `TopModuleCat` into a continuous linear map. -/
abbrev Hom.hom {X Y : TopModuleCat R} (f : X.Hom Y) : X →L[R] Y :=
ConcreteCategory.hom (C := TopModuleCat R) f
variable {R} in
/-- Construct a hom in `TopModuleCat` from a continuous linear map. -/
abbrev ofHom {X Y : Type v}
[AddCommGroup X] [Module R X] [TopologicalSpace X] [ContinuousAdd X] [ContinuousSMul R X]
[AddCommGroup Y] [Module R Y] [TopologicalSpace Y] [ContinuousAdd Y] [ContinuousSMul R Y]
(f : X →L[R] Y) : of R X ⟶ of R Y :=
ConcreteCategory.ofHom f
@[simp] lemma hom_ofHom {X Y : Type v}
[AddCommGroup X] [Module R X] [TopologicalSpace X] [ContinuousAdd X] [ContinuousSMul R X]
[AddCommGroup Y] [Module R Y] [TopologicalSpace Y] [ContinuousAdd Y] [ContinuousSMul R Y]
(f : X →L[R] Y) :
(ofHom f).hom = f := rfl
@[simp] lemma ofHom_hom {X Y : TopModuleCat R} (f : X.Hom Y) : ofHom f.hom = f := rfl
@[simp] lemma hom_comp {X Y Z : TopModuleCat R} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
@[simp] lemma hom_id (X : TopModuleCat R) : hom (𝟙 X) = .id _ _ := rfl
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (A B : TopModuleCat.{v} R) (f : A.Hom B) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
variable {R} in
/-- Construct an iso in `TopModuleCat` from a continuous linear equiv. -/
def ofIso {X Y : TopModuleCat R} (e : X ≃L[R] Y) : X ≅ Y :=
⟨ofHom e.toContinuousLinearMap, ofHom e.symm.toContinuousLinearMap,
by ext; exact e.symm_apply_apply _, by ext; exact e.apply_symm_apply _⟩
variable {R} in
/-- Cast an iso in `TopModuleCat` into a continuous linear equiv. -/
def _root_.CategoryTheory.Iso.toContinuousLinearEquiv
{X Y : TopModuleCat R} (e : X ≅ Y) : X ≃L[R] Y where
__ := e.hom.hom
invFun := e.inv.hom
left_inv x := by cat_disch
right_inv x := by cat_disch
instance {X Y : TopModuleCat R} : AddCommGroup (X ⟶ Y) where
add f g := ofHom (f.hom + g.hom)
zero := ofHom 0
__ := Equiv.addCommGroup CategoryTheory.ConcreteCategory.homEquiv
instance : Preadditive (TopModuleCat R) where
add_comp _ _ _ _ _ _ := ConcreteCategory.ext (ContinuousLinearMap.comp_add _ _ _)
comp_add _ _ _ _ _ _ := ConcreteCategory.ext (ContinuousLinearMap.add_comp _ _ _)
section
variable {M₁ M₂ : TopModuleCat R}
@[simp] lemma hom_zero : (0 : M₁ ⟶ M₂).hom = 0 := rfl
@[simp] lemma hom_zero_apply (m : M₁) : (0 : M₁ ⟶ M₂).hom m = 0 := rfl
@[simp] lemma hom_add (φ₁ φ₂ : M₁ ⟶ M₂) : (φ₁ + φ₂).hom = φ₁.hom + φ₂.hom := rfl
@[simp] lemma hom_neg (φ : M₁ ⟶ M₂) : (- φ).hom = - φ.hom := rfl
@[simp] lemma hom_sub (φ₁ φ₂ : M₁ ⟶ M₂) : (φ₁ - φ₂).hom = φ₁.hom - φ₂.hom := rfl
@[simp] lemma hom_nsmul (n : ℕ) (φ : M₁ ⟶ M₂) : (n • φ).hom = n • φ.hom := rfl
@[simp] lemma hom_zsmul (n : ℤ) (φ : M₁ ⟶ M₂) : (n • φ).hom = n • φ.hom := rfl
end
section CommRing
variable {S : Type*} [CommRing S] [TopologicalSpace S]
instance {X Y : TopModuleCat S} : Module S (X ⟶ Y) where
smul r f := ofHom (r • f.hom)
__ := Equiv.module _ CategoryTheory.ConcreteCategory.homEquiv
instance [CommRing S] : Linear S (TopModuleCat S) where
smul_comp _ _ _ _ _ _ := ConcreteCategory.ext (ContinuousLinearMap.comp_smul _ _ _)
comp_smul _ _ _ _ _ _ := ConcreteCategory.ext (ContinuousLinearMap.smul_comp _ _ _)
@[simp]
lemma hom_smul {M₁ M₂ : TopModuleCat S} (s : S) (φ : M₁ ⟶ M₂) : (s • φ).hom = s • φ.hom := rfl
end CommRing
instance (M : TopModuleCat R) : TopologicalSpace M := M.2
instance (M : TopModuleCat R) : IsTopologicalAddGroup M := M.3
instance : HasForget₂ (TopModuleCat R) (ModuleCat R) where
forget₂ :=
{ obj M := ModuleCat.of R M
map φ := ModuleCat.ofHom φ.hom }
instance : HasForget₂ (TopModuleCat R) TopCat where
forget₂ :=
{ obj M := .of M
map φ := TopCat.ofHom ⟨φ, φ.1.2⟩ }
instance : (forget₂ (TopModuleCat R) TopCat).ReflectsIsomorphisms where
reflects {X Y} f hf := by
let e : X ≃L[R] Y :=
{ __ := f.hom, __ := TopCat.homeoOfIso (asIso ((forget₂ (TopModuleCat R) TopCat).map f)) }
change IsIso (ofIso e).hom
infer_instance
@[simp]
lemma hom_forget₂_TopCat_map {X Y : TopModuleCat R} (f : X ⟶ Y) :
((forget₂ _ TopCat).map f).hom = f.hom := rfl
@[simp]
lemma forget₂_TopCat_obj {X : TopModuleCat R} : ((forget₂ _ TopCat).obj X : Type _) = X := rfl
open Limits
section Colimit
variable {R}
variable {M : ModuleCat R} {I : Type*} {X : I → TopModuleCat R} (f : ∀ i, (X i).toModuleCat ⟶ M)
/-- The coinduced topology on `M` from a family of continuous linear maps into `M`, which is the
finest topology that makes it into a topological module and makes every map continuous. -/
def coinduced : TopModuleCat R :=
letI : TopologicalSpace M := sInf { t | @ContinuousSMul R M _ _ t ∧ @ContinuousAdd M t _ ∧
∀ i, (X i).topologicalSpace.coinduced (f i) ≤ t }
have : ContinuousAdd M := continuousAdd_sInf fun _ hs ↦ hs.2.1
have : ContinuousSMul R M := continuousSMul_sInf fun _ hs ↦ hs.1
.of R M
/-- The maps into the coinduced topology as homs in `TopModuleCat R`. -/
def toCoinduced (i) : X i ⟶ coinduced f :=
ofHom (Y := coinduced f)
⟨(f i).hom, continuous_iff_coinduced_le.mpr (le_sInf fun _ hτ ↦ hτ.2.2 i)⟩
/-- The cocone of topological modules associated to a cocone over the underlying modules, where
the cocone point is given the coinduced topology. This is colimiting when the given cocone is. -/
def ofCocone {J : Type*} [Category J] {F : J ⥤ TopModuleCat R}
(c : Cocone (F ⋙ forget₂ _ (ModuleCat R))) : Cocone F where
pt := coinduced c.ι.app
ι :=
{ app := toCoinduced c.ι.app,
naturality {X Y} f := by ext x; exact congr($(c.ι.naturality f).hom x) }
/-- Given a colimit cocone over the underlying modules, equipping the cocone point with
the coinduced topology gives a colimit cocone in `TopModuleCat R`. -/
def isColimit {J : Type*} [Category J] {F : J ⥤ TopModuleCat R}
{c : Cocone (F ⋙ forget₂ _ (ModuleCat R))} (hc : IsColimit c) :
IsColimit (ofCocone c) where
desc s := ofHom (X := (ofCocone c).pt) ⟨(hc.desc ((forget₂ _ _).mapCocone s)).hom, by
rw [continuous_iff_le_induced]
refine sInf_le ⟨continuousSMul_induced (M₂ := s.pt) (hc.desc ((forget₂ _ _).mapCocone s)).hom,
continuousAdd_induced (N := s.pt) (hc.desc ((forget₂ _ _).mapCocone s)).hom, fun i ↦ ?_⟩
rw [coinduced_le_iff_le_induced, induced_compose, ← continuous_iff_le_induced]
change Continuous (X := F.obj i) (Y := s.pt)
(c.ι.app i ≫ hc.desc ((forget₂ _ (ModuleCat R)).mapCocone s)).hom
rw [hc.fac]
exact (s.ι.app i).hom.2⟩
fac s i := by ext x; exact congr($(hc.fac ((forget₂ _ _).mapCocone s) i).hom x)
uniq s m H := by
ext x
refine congr($(hc.uniq ((forget₂ _ _).mapCocone s) ((forget₂ _ _).map m) fun j ↦ ?_).hom x)
ext y
exact congr($(H j).hom y)
instance {J : Type*} [Category J] {F : J ⥤ TopModuleCat R}
[HasColimit (F ⋙ forget₂ _ (ModuleCat R))] : HasColimit F :=
⟨_, isColimit (colimit.isColimit _)⟩
instance {J : Type*} [Category J] [HasColimitsOfShape J (ModuleCat.{v} R)] :
HasColimitsOfShape J (TopModuleCat.{v} R) where
instance : HasColimits (TopModuleCat.{v} R) where
end Colimit
section Limit
variable {R}
variable {M : ModuleCat R} {I : Type*} {X : I → TopModuleCat R} (f : ∀ i, M ⟶ (X i).toModuleCat)
/-- The induced topology on `M` from a family of continuous linear maps from `M`, which is the
coarsest topology that makes every map continuous. -/
def induced : TopModuleCat R :=
letI : TopologicalSpace M := ⨅ i, (X i).topologicalSpace.induced (f i)
have : ContinuousAdd M := continuousAdd_iInf fun _ ↦ continuousAdd_induced _
have : ContinuousSMul R M := continuousSMul_iInf fun _ ↦ continuousSMul_induced _
.of R M
/-- The maps from the induced topology as homs in `TopModuleCat R`. -/
def fromInduced (i) : induced f ⟶ X i :=
ofHom (X := induced f) ⟨(f i).hom, continuous_iff_le_induced.mpr (iInf_le _ i)⟩
open Limits
/-- The cone of topological modules associated to a cone over the underlying modules, where
the cone point is given the induced topology. This is limiting when the given cone is. -/
def ofCone {J : Type*} [Category J] {F : J ⥤ TopModuleCat R}
(c : Cone (F ⋙ forget₂ _ (ModuleCat R))) : Cone F where
pt := induced c.π.app
π :=
{ app := fromInduced c.π.app,
naturality {X Y} f := by ext x; exact congr($(c.π.naturality f).hom x) }
/-- Given a limit cone over the underlying modules, equipping the cone point with
the induced topology gives a limit cone in `TopModuleCat R`. -/
def isLimit {J : Type*} [Category J] {F : J ⥤ TopModuleCat R}
{c : Cone (F ⋙ forget₂ _ (ModuleCat R))} (hc : IsLimit c) :
IsLimit (ofCone c) where
lift s := ofHom (Y := (ofCone c).pt) ⟨(hc.lift ((forget₂ _ _).mapCone s)).hom, by
rw [continuous_iff_coinduced_le]
refine le_iInf fun i ↦ ?_
rw [coinduced_le_iff_le_induced, induced_compose, ← continuous_iff_le_induced]
change Continuous (X := s.pt) (Y := F.obj i)
(hc.lift ((forget₂ _ (ModuleCat R)).mapCone s) ≫ c.π.app i).hom
rw [hc.fac]
exact (s.π.app i).hom.2⟩
fac s i := by ext x; exact congr($(hc.fac ((forget₂ _ _).mapCone s) i).hom x)
uniq s m H := by
ext x
refine congr($(hc.uniq ((forget₂ _ _).mapCone s) ((forget₂ _ _).map m) fun j ↦ ?_).hom x)
ext y
exact congr($(H j).hom y)
instance hasLimit_of_hasLimit_forget₂ {J : Type*} [Category J] {F : J ⥤ TopModuleCat.{v} R}
[HasLimit (F ⋙ forget₂ _ (ModuleCat.{v} R))] : HasLimit F :=
⟨_, isLimit (limit.isLimit _)⟩
instance {J : Type*} [Category J] [HasLimitsOfShape J (ModuleCat.{v} R)] :
HasLimitsOfShape J (TopModuleCat.{v} R) where
has_limit _ := hasLimit_of_hasLimit_forget₂
instance : HasLimits (TopModuleCat.{v} R) where
has_limits_of_shape _ _ := ⟨fun _ ↦ hasLimit_of_hasLimit_forget₂⟩
instance {J : Type*} [Category J] {F : J ⥤ TopModuleCat.{v} R}
[HasLimit (F ⋙ forget₂ _ (ModuleCat.{v} R))]
[PreservesLimit (F ⋙ forget₂ _ (ModuleCat.{v} R)) (forget _)] :
PreservesLimit F (forget₂ _ TopCat) :=
preservesLimit_of_preserves_limit_cone (isLimit (limit.isLimit _))
(TopCat.isLimitConeOfForget (F := F ⋙ forget₂ _ TopCat)
((forget _).mapCone (getLimitCone (F ⋙ forget₂ _ (ModuleCat.{v} R))).1:)
(isLimitOfPreserves (forget (ModuleCat R)) (limit.isLimit _)))
instance {J : Type*} [Category J]
[HasLimitsOfShape J (ModuleCat.{v} R)]
[PreservesLimitsOfShape J (forget (ModuleCat.{v} R))] :
PreservesLimitsOfShape J (forget₂ (TopModuleCat.{v} R) TopCat) where
instance : PreservesLimits (forget₂ (TopModuleCat.{v} R) TopCat.{v}) where
end Limit
section Adjunction
/-- The functor equipping a module over a topological ring with the finest possible
topology making it into a topological module. This is left adjoint to the forgetful functor. -/
def withModuleTopology : ModuleCat R ⥤ TopModuleCat R where
obj X :=
letI := moduleTopology R X
letI := IsModuleTopology.topologicalAddGroup R X
.of R X
map {X Y} f :=
letI := moduleTopology R X
letI := moduleTopology R Y
letI := IsModuleTopology.topologicalAddGroup R Y
⟨f.hom, IsModuleTopology.continuous_of_linearMap f.hom⟩
/-- The adjunction between `withModuleTopology` and the forgetful functor. -/
def withModuleTopologyAdj : withModuleTopology R ⊣ forget₂ (TopModuleCat R) (ModuleCat R) where
unit := 𝟙 _
counit :=
{ app X := ofHom (X := (withModuleTopology R).obj (.of R X))
⟨.id, IsModuleTopology.continuous_of_linearMap _⟩ }
instance : (forget₂ (TopModuleCat R) (ModuleCat R)).IsRightAdjoint := ⟨_, ⟨withModuleTopologyAdj R⟩⟩
instance : (withModuleTopology R).IsLeftAdjoint := ⟨_, ⟨withModuleTopologyAdj R⟩⟩
/-- The functor equipping a module with the indiscrete topology.
This is right adjoint to the forgetful functor. -/
def indiscrete : ModuleCat.{v} R ⥤ TopModuleCat.{v} R where
obj X :=
letI : TopologicalSpace X := ⊤
haveI : ContinuousAdd X := ⟨by rw [continuous_iff_coinduced_le]; exact le_top⟩
haveI : ContinuousSMul R X := ⟨by rw [continuous_iff_coinduced_le]; exact le_top⟩
.of R X
map {X Y} f :=
letI : TopologicalSpace X := ⊤
letI : TopologicalSpace Y := ⊤
ConcreteCategory.ofHom (C := TopModuleCat R)
⟨f.hom, by rw [continuous_iff_coinduced_le]; exact le_top⟩
/-- The adjunction between the forgetful functor and the indiscrete topology functor. -/
def indiscreteAdj : forget₂ (TopModuleCat.{v} R) (ModuleCat.{v} R) ⊣ indiscrete.{v} R where
counit := 𝟙 _
unit := { app X := ConcreteCategory.ofHom (C := TopModuleCat R)
⟨.id, by rw [continuous_iff_coinduced_le]; exact le_top⟩ }
instance : (forget₂ (TopModuleCat.{v} R) (ModuleCat.{v} R)).IsLeftAdjoint := ⟨_, ⟨indiscreteAdj R⟩⟩
instance : (indiscrete.{v} R).IsRightAdjoint := ⟨_, ⟨indiscreteAdj R⟩⟩
/-- The free topological module over a topological space. -/
noncomputable
def freeObj (X : TopCat.{v}) : TopModuleCat.{max v u} R :=
letI : TopologicalSpace (X →₀ R) := sInf
{ t | @ContinuousSMul R _ _ _ t ∧ @ContinuousAdd _ t _ ∧
X.str.coinduced (Finsupp.single · 1) ≤ t }
letI : ContinuousAdd (X →₀ R) := continuousAdd_sInf fun _ h ↦ h.2.1
letI : ContinuousSMul R (X →₀ R) := continuousSMul_sInf fun _ h ↦ h.1
of R (X →₀ R)
lemma coe_freeObj (X : TopCat.{v}) : freeObj R X = (X →₀ R) := rfl
/-- The free topological module over a topological space is functorial. -/
noncomputable
def freeMap {X Y : TopCat.{v}} (f : X ⟶ Y) : freeObj R X ⟶ freeObj R Y :=
ConcreteCategory.ofHom ⟨Finsupp.lmapDomain _ _ f.hom, by
rw [continuous_iff_coinduced_le]
refine le_sInf fun (τ : TopologicalSpace (_ →₀ R)) ⟨hτ₁, hτ₂, hτ₃⟩ ↦ ?_
rw [coinduced_le_iff_le_induced]
refine sInf_le ⟨continuousSMul_induced (Finsupp.lmapDomain _ _ f.hom),
continuousAdd_induced (Finsupp.lmapDomain _ _ f.hom), ?_⟩
rw [← coinduced_le_iff_le_induced]
grw [← hτ₃, ← coinduced_mono (continuous_iff_coinduced_le.mp f.hom.2)]
rw [coinduced_compose, coinduced_compose]
congr! 1
ext x
simp [coe_freeObj]⟩
lemma freeMap_map {X Y : TopCat} (f : X ⟶ Y) (v : X →₀ R) :
(freeMap R f : (X →₀ R) → (Y →₀ R)) v = Finsupp.mapDomain f.hom v := rfl
/-- The free topological module over a topological space as a functor.
This is left adjoint to the forgetful functor. -/
@[simps] noncomputable
def free : TopCat.{v} ⥤ TopModuleCat.{max v u} R :=
{ obj := freeObj R
map f := freeMap R f
map_id M := by ext x; exact DFunLike.congr_fun (Finsupp.lmapDomain_id _ _) x
map_comp f g := by ext; exact DFunLike.congr_fun (Finsupp.lmapDomain_comp _ _ f.hom g.hom) _ }
/-- The free-forgetful adjoint for `TopModuleCat R`. -/
noncomputable
def freeAdj : free.{max v u} R ⊣ forget₂ (TopModuleCat.{max v u} R) TopCat.{max v u} where
unit :=
{ app X := TopCat.ofHom ⟨(Finsupp.single · 1),
continuous_iff_coinduced_le.mpr (le_sInf fun _ h ↦ h.2.2)⟩,
naturality {X Y} f := by ext x; simp [freeMap_map] }
counit :=
{ app X := ConcreteCategory.ofHom (C := TopModuleCat R) ⟨Finsupp.lift _ R X id, by
rw [continuous_iff_le_induced]
refine sInf_le ⟨continuousSMul_induced (Finsupp.lift _ R X id),
continuousAdd_induced (Finsupp.lift _ R X id), ?_⟩
rw [coinduced_le_iff_le_induced, induced_compose]
convert induced_id.symm.le
ext
simp [coe_freeObj]⟩,
naturality {X Y} f := by
ext1
apply ContinuousLinearMap.coe_injective
refine Finsupp.lhom_ext' fun a ↦ LinearMap.ext_ring ?_
dsimp [freeObj, freeMap]
simp }
left_triangle_components X := by
ext1
apply ContinuousLinearMap.coe_injective
refine Finsupp.lhom_ext' fun a ↦ LinearMap.ext_ring ?_
simp [freeMap, freeObj]
right_triangle_components X := by
ext
simp [freeObj]
instance : (forget₂ (TopModuleCat.{max v u} R) TopCat).IsRightAdjoint := ⟨_, ⟨freeAdj R⟩⟩
instance : (free.{max v u} R).IsLeftAdjoint := ⟨_, ⟨freeAdj R⟩⟩
end Adjunction
end TopModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Topology/Homology.lean | import Mathlib.Algebra.Category.ModuleCat.Abelian
import Mathlib.Algebra.Category.ModuleCat.Topology.Basic
import Mathlib.Algebra.Homology.ShortComplex.Abelian
import Mathlib.Algebra.Homology.ShortComplex.PreservesHomology
/-!
# `TopModuleCat` is a `CategoryWithHomology`
`TopModuleCat R`, the category of topological `R`-modules, is not an abelian category.
But since the topology on subquotients is well-defined, we can still talk about homology in this
category. See the `CategoryWithHomology (TopModuleCat R)` instance in this file.
-/
universe v u
open CategoryTheory Limits
namespace TopModuleCat
variable {R : Type u} [Ring R] [TopologicalSpace R]
variable {M N : TopModuleCat.{v} R} (φ : M ⟶ N)
section kernel
/-- Kernel in `TopModuleCat R` is the kernel of the linear map with the subspace topology. -/
abbrev ker : TopModuleCat R := .of R (LinearMap.ker φ.hom)
/-- The inclusion map from the kernel in `TopModuleCat R`. -/
def kerι : ker φ ⟶ M := ofHom ⟨Submodule.subtype _, continuous_subtype_val⟩
instance : Mono (kerι φ) := ConcreteCategory.mono_of_injective (kerι φ) <| Subtype.val_injective
@[simp] lemma kerι_comp : kerι φ ≫ φ = 0 := by ext ⟨_, hm⟩; exact hm
@[simp] lemma kerι_apply (x) : kerι φ x = x.1 := rfl
/-- `TopModuleCat.ker` is indeed the kernel in `TopModuleCat R`. -/
def isLimitKer : IsLimit (KernelFork.ofι (kerι φ) (kerι_comp φ)) :=
isLimitAux (KernelFork.ofι (kerι φ) (kerι_comp φ))
(fun s ↦ ofHom <| (Fork.ι s).hom.codRestrict (LinearMap.ker φ.hom) fun m ↦ by
rw [LinearMap.mem_ker, ← ConcreteCategory.comp_apply (Fork.ι s) φ,
KernelFork.condition, hom_zero_apply])
(fun s ↦ rfl)
(fun s m h ↦ by dsimp at h ⊢; rw [← cancel_mono (kerι φ), h]; rfl)
end kernel
section cokernel
/-- Cokernel in `TopModuleCat R` is the cokernel of the linear map with the quotient topology. -/
abbrev coker : TopModuleCat R := .of R (N ⧸ LinearMap.range φ.hom)
/-- The projection map to the cokernel in `TopModuleCat R`. -/
def cokerπ : N ⟶ coker φ := ofHom <| ⟨Submodule.mkQ _, by tauto⟩
@[simp]
lemma hom_cokerπ (x) : (cokerπ φ).hom x = Submodule.mkQ _ x := rfl
lemma cokerπ_surjective : Function.Surjective (cokerπ φ).hom := Submodule.mkQ_surjective _
instance : Epi (cokerπ φ) := ConcreteCategory.epi_of_surjective (cokerπ φ) (cokerπ_surjective φ)
@[simp] lemma comp_cokerπ : φ ≫ cokerπ φ = 0 := by
ext m
change Submodule.mkQ _ (φ m) = 0
simp
/-- `TopModuleCat.coker` is indeed the cokernel in `TopModuleCat R`. -/
def isColimitCoker : IsColimit (CokernelCofork.ofπ (cokerπ φ) (comp_cokerπ φ)) :=
isColimitAux (.ofπ (cokerπ φ) (comp_cokerπ φ))
(fun s ↦ ofHom <|
{ toLinearMap := (LinearMap.range φ.hom).liftQ s.π.hom.toLinearMap
(LinearMap.range_le_ker_iff.mpr <| show (φ ≫ s.π).hom.toLinearMap = 0 by
rw [s.condition, hom_zero, ContinuousLinearMap.coe_zero])
cont := Continuous.quotient_lift s.π.hom.2 _ })
(fun s ↦ rfl)
(fun s m h ↦ by dsimp at h ⊢; rw [← cancel_epi (cokerπ φ), h]; rfl)
end cokernel
instance : CategoryWithHomology (TopModuleCat R) := by
constructor
intro S
let D₁ : S.LeftHomologyData := ⟨_, _, _, _, _, isLimitKer _, by simp, isColimitCoker _⟩
let D₂ : S.RightHomologyData := ⟨_, _, _, _, by simp, isColimitCoker _, _, isLimitKer _⟩
let F := ShortComplex.leftRightHomologyComparison' D₁ D₂
suffices IsIso F from ⟨⟨.ofIsIsoLeftRightHomologyComparison' D₁ D₂⟩⟩
have hF : Function.Bijective F := by
change Function.Bijective ((forget₂ _ (ModuleCat R)).map F)
rw [← ConcreteCategory.isIso_iff_bijective, ShortComplex.map_leftRightHomologyComparison']
infer_instance
have hF' : Topology.IsEmbedding F := by
refine .of_comp F.1.2 D₂.ι.1.2 ?_
-- `isEmbedding_of_isOpenQuotientMap_of_isInducing` is the key lemma that shows the two
-- definitions of homology give the same topology.
refine isEmbedding_of_isOpenQuotientMap_of_isInducing
D₁.i (F ≫ D₂.ι) D₁.π D₂.p ?_ .subtypeVal
(Submodule.isOpenQuotientMap_mkQ _).isQuotientMap
(Submodule.isOpenQuotientMap_mkQ _)
(Subtype.val_injective.comp hF.1) ?_
· rw [← ContinuousLinearMap.coe_comp', ← ContinuousLinearMap.coe_comp',
← hom_comp, ← hom_comp, ShortComplex.π_leftRightHomologyComparison'_ι]
· suffices ∀ x y, S.g y = 0 → D₂.p y = D₂.p x → S.g x = 0 by
simpa [Set.subset_def, D₁, kerι_apply S.g] using this
intro x y hy e
obtain ⟨z, hz⟩ := (Submodule.Quotient.eq _).mp e
obtain rfl := eq_sub_iff_add_eq.mp hz
simpa [show S.g (S.f z) = 0 from ConcreteCategory.congr_hom S.zero z] using hy
rw [← isIso_iff_of_reflects_iso _ (forget₂ (TopModuleCat R) TopCat),
TopCat.isIso_iff_isHomeomorph, isHomeomorph_iff_isEmbedding_surjective]
exact ⟨hF', hF.2⟩
end TopModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Differentials/Presheaf.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf
import Mathlib.Algebra.Category.ModuleCat.Differentials.Basic
/-!
# The presheaf of differentials of a presheaf of modules
In this file, we define the type `M.Derivation φ` of derivations
with values in a presheaf of `R`-modules `M` relative to
a morphism of `φ : S ⟶ F.op ⋙ R` of presheaves of commutative rings
over categories `C` and `D` that are related by a functor `F : C ⥤ D`.
We formalize the notion of universal derivation.
Geometrically, if `f : X ⟶ S` is a morphism of schemes (or more generally
a morphism of commutative ringed spaces), we would like to apply
these definitions in the case where `F` is the pullback functor from
open subsets of `S` to open subsets of `X` and `φ` is the
morphism $O_S ⟶ f_* O_X$.
In order to prove that there exists a universal derivation, the target
of which shall be called the presheaf of relative differentials of `φ`,
we first study the case where `F` is the identity functor.
In this case where we have a morphism of presheaves of commutative
rings `φ' : S' ⟶ R`, we construct a derivation
`DifferentialsConstruction.derivation'` which is universal.
Then, the general case (TODO) shall be obtained by observing that
derivations for `S ⟶ F.op ⋙ R` identify to derivations
for `S' ⟶ R` where `S'` is the pullback by `F` of the presheaf of
commutative rings `S` (the data is the same: it suffices
to show that the two vanishing conditions `d_app` are equivalent).
-/
universe v u v₁ v₂ u₁ u₂
open CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
namespace PresheafOfModules
variable {S : Cᵒᵖ ⥤ CommRingCat.{u}} {F : C ⥤ D} {S' R : Dᵒᵖ ⥤ CommRingCat.{u}}
(M N : PresheafOfModules.{v} (R ⋙ forget₂ _ _))
(φ : S ⟶ F.op ⋙ R) (φ' : S' ⟶ R)
/-- Given a morphism of presheaves of commutative rings `φ : S ⟶ F.op ⋙ R`,
this is the type of relative `φ`-derivation of a presheaf of `R`-modules `M`. -/
@[ext]
structure Derivation where
/-- the underlying additive map `R.obj X →+ M.obj X` of a derivation -/
d {X : Dᵒᵖ} : R.obj X →+ M.obj X
d_mul {X : Dᵒᵖ} (a b : R.obj X) : d (a * b) = a • d b + b • d a := by cat_disch
d_map {X Y : Dᵒᵖ} (f : X ⟶ Y) (x : R.obj X) :
d (R.map f x) = M.map f (d x) := by cat_disch
d_app {X : Cᵒᵖ} (a : S.obj X) : d (φ.app X a) = 0 := by cat_disch
namespace Derivation
-- Note: `d_app` cannot be a simp lemma because `dsimp` would
-- simplify the composition of functors `R ⋙ forget₂ _ _`
attribute [simp] d_mul d_map
variable {M N φ}
lemma congr_d {d d' : M.Derivation φ} (h : d = d') {X : Dᵒᵖ} (b : R.obj X) :
d.d b = d'.d b := by rw [h]
variable (d : M.Derivation φ)
@[simp] lemma d_one (X : Dᵒᵖ) : d.d (X := X) 1 = 0 := by
simpa using d.d_mul (X := X) 1 1
/-- The postcomposition of a derivation by a morphism of presheaves of modules. -/
@[simps! d_apply]
def postcomp (f : M ⟶ N) : N.Derivation φ where
d := (f.app _).hom.toAddMonoidHom.comp d.d
d_map {X Y} g x := by simpa using naturality_apply f g (d.d x)
d_app {X} a := by
dsimp
erw [d_app]
rw [map_zero]
/-- The universal property that a derivation `d : M.Derivation φ` must
satisfy so that the presheaf of modules `M` can be considered as the presheaf of
(relative) differentials of a presheaf of commutative rings `φ : S ⟶ F.op ⋙ R`. -/
structure Universal where
/-- An absolute derivation of `M'` descends as a morphism `M ⟶ M'`. -/
desc {M' : PresheafOfModules (R ⋙ forget₂ CommRingCat RingCat)}
(d' : M'.Derivation φ) : M ⟶ M'
fac {M' : PresheafOfModules (R ⋙ forget₂ CommRingCat RingCat)}
(d' : M'.Derivation φ) : d.postcomp (desc d') = d' := by cat_disch
postcomp_injective {M' : PresheafOfModules (R ⋙ forget₂ CommRingCat RingCat)}
(φ φ' : M ⟶ M') (h : d.postcomp φ = d.postcomp φ') : φ = φ' := by cat_disch
attribute [simp] Universal.fac
instance : Subsingleton d.Universal where
allEq h₁ h₂ := by
suffices ∀ {M' : PresheafOfModules (R ⋙ forget₂ CommRingCat RingCat)}
(d' : M'.Derivation φ), h₁.desc d' = h₂.desc d' by
cases h₁
cases h₂
simp only [Universal.mk.injEq]
ext : 2
apply this
intro M' d'
apply h₁.postcomp_injective
simp
end Derivation
/-- The property that there exists a universal derivation for
a morphism of presheaves of commutative rings `S ⟶ F.op ⋙ R`. -/
class HasDifferentials : Prop where
exists_universal_derivation : ∃ (M : PresheafOfModules.{u} (R ⋙ forget₂ _ _))
(d : M.Derivation φ), Nonempty d.Universal
/-- Given a morphism of presheaves of commutative rings `φ : S ⟶ R`,
this is the type of relative `φ`-derivation of a presheaf of `R`-modules `M`. -/
abbrev Derivation' : Type _ := M.Derivation (F := 𝟭 D) φ'
namespace Derivation'
variable {M φ'}
@[simp]
lemma d_app (d : M.Derivation' φ') {X : Dᵒᵖ} (a : S'.obj X) :
d.d (φ'.app X a) = 0 :=
Derivation.d_app d _
/-- The derivation relative to the morphism of commutative rings `φ'.app X` induced by
a derivation relative to a morphism of presheaves of commutative rings. -/
noncomputable def app (d : M.Derivation' φ') (X : Dᵒᵖ) : (M.obj X).Derivation (φ'.app X) :=
ModuleCat.Derivation.mk (fun b ↦ d.d b)
@[simp]
lemma app_apply (d : M.Derivation' φ') {X : Dᵒᵖ} (b : R.obj X) :
(d.app X).d b = d.d b := rfl
section
variable (d : ∀ (X : Dᵒᵖ), (M.obj X).Derivation (φ'.app X))
/-- Given a morphism of presheaves of commutative rings `φ'`, this is the
in derivation `M.Derivation' φ'` that is given by a compatible family of derivations
with values in the modules `M.obj X` for all `X`. -/
def mk (d_map : ∀ ⦃X Y : Dᵒᵖ⦄ (f : X ⟶ Y) (x : R.obj X),
(d Y).d ((R.map f) x) = (M.map f) ((d X).d x)) : M.Derivation' φ' where
d {X} := AddMonoidHom.mk' (d X).d (by simp)
variable (d_map : ∀ ⦃X Y : Dᵒᵖ⦄ (f : X ⟶ Y) (x : R.obj X),
(d Y).d ((R.map f) x) = (M.map f) ((d X).d x))
@[simp]
lemma mk_app (X : Dᵒᵖ) : (mk d d_map).app X = d X := rfl
/-- Constructor for `Derivation.Universal` in the case `F` is the identity functor. -/
def Universal.mk {d : M.Derivation' φ'}
(desc : ∀ {M' : PresheafOfModules (R ⋙ forget₂ _ _)}
(_ : M'.Derivation' φ'), M ⟶ M')
(fac : ∀ {M' : PresheafOfModules (R ⋙ forget₂ _ _)}
(d' : M'.Derivation' φ'), d.postcomp (desc d') = d')
(postcomp_injective : ∀ {M' : PresheafOfModules (R ⋙ forget₂ _ _)}
(α β : M ⟶ M'), d.postcomp α = d.postcomp β → α = β) : d.Universal where
desc := desc
fac := fac
postcomp_injective := postcomp_injective
end
end Derivation'
namespace DifferentialsConstruction
/-- The presheaf of relative differentials of a morphism of presheaves of
commutative rings. -/
@[simps -isSimp]
noncomputable def relativeDifferentials' :
PresheafOfModules.{u} (R ⋙ forget₂ _ _) where
obj X := CommRingCat.KaehlerDifferential (φ'.app X)
-- Have to hint `g' := R.map f` below, or it gets unfolded weirdly.
map f := CommRingCat.KaehlerDifferential.map (g' := R.map f) (φ'.naturality f)
-- Without `dsimp`, `ext` doesn't pick up the right lemmas.
map_id _ := by dsimp; ext; simp
map_comp _ _ := by dsimp; ext; simp
attribute [simp] relativeDifferentials'_obj
@[simp]
lemma relativeDifferentials'_map_d {X Y : Dᵒᵖ} (f : X ⟶ Y) (x : R.obj X) :
DFunLike.coe (α := CommRingCat.KaehlerDifferential (φ'.app X))
(β := fun _ ↦ CommRingCat.KaehlerDifferential (φ'.app Y))
(ModuleCat.Hom.hom (R := ↑(R.obj X)) ((relativeDifferentials' φ').map f))
(CommRingCat.KaehlerDifferential.d x) =
CommRingCat.KaehlerDifferential.d (R.map f x) :=
CommRingCat.KaehlerDifferential.map_d (φ'.naturality f) _
/-- The universal derivation. -/
noncomputable def derivation' : (relativeDifferentials' φ').Derivation' φ' :=
Derivation'.mk (fun X ↦ CommRingCat.KaehlerDifferential.D (φ'.app X))
(fun _ _ f x ↦ (relativeDifferentials'_map_d φ' f x).symm)
/-- The derivation `Derivation' φ'` is universal. -/
noncomputable def isUniversal' : (derivation' φ').Universal :=
Derivation'.Universal.mk
(fun {M'} d' ↦
{ app := fun X ↦ (d'.app X).desc
naturality := fun {X Y} f ↦ CommRingCat.KaehlerDifferential.ext (fun b ↦ by
dsimp
rw [ModuleCat.Derivation.desc_d, Derivation'.app_apply]
erw [relativeDifferentials'_map_d φ' f]
simp) })
(fun {M'} d' ↦ by
ext X b
apply ModuleCat.Derivation.desc_d)
(fun {M} α β h ↦ by
ext1 X
exact CommRingCat.KaehlerDifferential.ext (Derivation.congr_d h))
instance : HasDifferentials (F := 𝟭 D) φ' := ⟨_, _, ⟨isUniversal' φ'⟩⟩
end DifferentialsConstruction
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Differentials/Basic.lean | import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings
import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.RingTheory.Kaehler.Basic
/-!
# The differentials of a morphism in the category of commutative rings
In this file, given a morphism `f : A ⟶ B` in the category `CommRingCat`,
and `M : ModuleCat B`, we define the type `M.Derivation f` of
derivations with values in `M` relative to `f`.
We also construct the module of differentials
`CommRingCat.KaehlerDifferential f : ModuleCat B` and the corresponding derivation.
-/
universe v u
open CategoryTheory
attribute [local instance] IsScalarTower.of_compHom SMulCommClass.of_commMonoid
namespace ModuleCat
variable {A B : CommRingCat.{u}} (M : ModuleCat.{v} B) (f : A ⟶ B)
/-- The type of derivations with values in a `B`-module `M` relative
to a morphism `f : A ⟶ B` in the category `CommRingCat`. -/
def Derivation : Type _ :=
letI := f.hom.toAlgebra
letI := Module.compHom M f.hom
_root_.Derivation A B M
namespace Derivation
variable {M f}
/-- Constructor for `ModuleCat.Derivation`. -/
def mk (d : B → M) (d_add : ∀ (b b' : B), d (b + b') = d b + d b' := by simp)
(d_mul : ∀ (b b' : B), d (b * b') = b • d b' + b' • d b := by simp)
(d_map : ∀ (a : A), d (f a) = 0 := by simp) :
M.Derivation f :=
letI := f.hom.toAlgebra
letI := Module.compHom M f.hom
{ toFun := d
map_add' := d_add
map_smul' := fun a b ↦ by
dsimp
rw [RingHom.smul_toAlgebra, d_mul, d_map, smul_zero, add_zero]
rfl
map_one_eq_zero' := by
dsimp
rw [← f.hom.map_one, d_map]
leibniz' := d_mul }
variable (D : M.Derivation f)
/-- The underlying map `B → M` of a derivation `M.Derivation f` when `M : ModuleCat B`
and `f : A ⟶ B` is a morphism in `CommRingCat`. -/
def d (b : B) : M :=
letI := f.hom.toAlgebra
letI := Module.compHom M f.hom
_root_.Derivation.toLinearMap D b
@[simp]
lemma d_add (b b' : B) : D.d (b + b') = D.d b + D.d b' := by simp [d]
@[simp]
lemma d_mul (b b' : B) : D.d (b * b') = b • D.d b' + b' • D.d b := by simp [d]
@[simp]
lemma d_map (a : A) : D.d (f a) = 0 :=
letI := f.hom.toAlgebra
letI := Module.compHom M f.hom
D.map_algebraMap a
end Derivation
end ModuleCat
namespace CommRingCat
variable {A B A' B' : CommRingCat.{u}} {f : A ⟶ B} {f' : A' ⟶ B'}
{g : A ⟶ A'} {g' : B ⟶ B'} (fac : g ≫ f' = f ≫ g')
variable (f) in
/-- The module of differentials of a morphism `f : A ⟶ B` in the category `CommRingCat`. -/
noncomputable def KaehlerDifferential : ModuleCat.{u} B :=
letI := f.hom.toAlgebra
ModuleCat.of B (_root_.KaehlerDifferential A B)
namespace KaehlerDifferential
variable (f) in
/-- The (universal) derivation in `(KaehlerDifferential f).Derivation f`
when `f : A ⟶ B` is a morphism in the category `CommRingCat`. -/
noncomputable def D : (KaehlerDifferential f).Derivation f :=
letI := f.hom.toAlgebra
ModuleCat.Derivation.mk
(fun b ↦ _root_.KaehlerDifferential.D A B b) (by simp) (by simp)
(_root_.KaehlerDifferential.D A B).map_algebraMap
/-- When `f : A ⟶ B` is a morphism in the category `CommRingCat`, this is the
differential map `B → KaehlerDifferential f`. -/
noncomputable abbrev d (b : B) : KaehlerDifferential f := (D f).d b
@[ext]
lemma ext {M : ModuleCat B} {α β : KaehlerDifferential f ⟶ M}
(h : ∀ (b : B), α (d b) = β (d b)) : α = β := by
rw [← sub_eq_zero]
have : ⊤ ≤ LinearMap.ker (α - β).hom := by
rw [← KaehlerDifferential.span_range_derivation, Submodule.span_le]
rintro _ ⟨y, rfl⟩
rw [SetLike.mem_coe, LinearMap.mem_ker, ModuleCat.hom_sub, LinearMap.sub_apply, sub_eq_zero]
apply h
rw [top_le_iff, LinearMap.ker_eq_top] at this
ext : 1
exact this
/-- The map `KaehlerDifferential f ⟶ (ModuleCat.restrictScalars g').obj (KaehlerDifferential f')`
induced by a commutative square (given by an equality `g ≫ f' = f ≫ g'`)
in the category `CommRingCat`. -/
noncomputable def map :
KaehlerDifferential f ⟶
(ModuleCat.restrictScalars g'.hom).obj (KaehlerDifferential f') :=
letI := f.hom.toAlgebra
letI := f'.hom.toAlgebra
letI := g.hom.toAlgebra
letI := g'.hom.toAlgebra
letI := (g ≫ f').hom.toAlgebra
have : IsScalarTower A A' B' := IsScalarTower.of_algebraMap_eq' rfl
have := IsScalarTower.of_algebraMap_eq' (congrArg Hom.hom fac)
-- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(Y := ...)`.
-- This suggests `restrictScalars` needs to be redesigned.
ModuleCat.ofHom (Y := (ModuleCat.restrictScalars g'.hom).obj (KaehlerDifferential f'))
{ toFun := fun x ↦ _root_.KaehlerDifferential.map A A' B B' x
map_add' := by simp
map_smul' := by simp }
@[simp]
lemma map_d (b : B) : map fac (d b) = d (g' b) := by
algebraize [f.hom, f'.hom, g.hom, g'.hom, f'.hom.comp g.hom]
have := IsScalarTower.of_algebraMap_eq' (congrArg Hom.hom fac)
exact _root_.KaehlerDifferential.map_D A A' B B' b
end KaehlerDifferential
end CommRingCat
namespace ModuleCat.Derivation
variable {A B : CommRingCat.{u}} {f : A ⟶ B}
{M : ModuleCat.{u} B} (D : M.Derivation f)
/-- Given `f : A ⟶ B` a morphism in the category `CommRingCat`, `M : ModuleCat B`,
and `D : M.Derivation f`, this is the induced
morphism `CommRingCat.KaehlerDifferential f ⟶ M`. -/
noncomputable def desc : CommRingCat.KaehlerDifferential f ⟶ M :=
letI := f.hom.toAlgebra
letI := Module.compHom M f.hom
ofHom D.liftKaehlerDifferential
@[simp]
lemma desc_d (b : B) : D.desc (CommRingCat.KaehlerDifferential.d b) = D.d b := by
letI := f.hom.toAlgebra
letI := Module.compHom M f.hom
apply D.liftKaehlerDifferential_comp_D
end ModuleCat.Derivation |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/EpiMono.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.Colimits
import Mathlib.Algebra.Category.ModuleCat.Presheaf.Limits
/-!
# Epimorphisms and monomorphisms in the category of presheaves of modules
In this file, we give characterizations of epimorphisms and monomorphisms
in the category of presheaves of modules.
-/
universe v v₁ u₁ u
open CategoryTheory
namespace PresheafOfModules
variable {C : Type u₁} [Category.{v₁} C] {R : Cᵒᵖ ⥤ RingCat.{u}}
{M₁ M₂ : PresheafOfModules.{v} R} {f : M₁ ⟶ M₂}
lemma epi_of_surjective (hf : ∀ ⦃X : Cᵒᵖ⦄, Function.Surjective (f.app X)) : Epi f where
left_cancellation g₁ g₂ hg := by
ext X m₂
obtain ⟨m₁, rfl⟩ := hf m₂
exact congr_fun ((evaluation R X ⋙ forget _).congr_map hg) m₁
lemma mono_of_injective (hf : ∀ ⦃X : Cᵒᵖ⦄, Function.Injective (f.app X)) : Mono f where
right_cancellation {M} g₁ g₂ hg := by
ext X m
exact hf (congr_fun ((evaluation R X ⋙ forget _).congr_map hg) m)
variable (f)
instance [Epi f] (X : Cᵒᵖ) : Epi (f.app X) :=
inferInstanceAs (Epi ((evaluation R X).map f))
instance [Mono f] (X : Cᵒᵖ) : Mono (f.app X) :=
inferInstanceAs (Mono ((evaluation R X).map f))
lemma surjective_of_epi [Epi f] (X : Cᵒᵖ) :
Function.Surjective (f.app X) := by
rw [← ModuleCat.epi_iff_surjective]
infer_instance
lemma injective_of_mono [Mono f] (X : Cᵒᵖ) :
Function.Injective (f.app X) := by
rw [← ModuleCat.mono_iff_injective]
infer_instance
lemma epi_iff_surjective :
Epi f ↔ ∀ ⦃X : Cᵒᵖ⦄, Function.Surjective (f.app X) :=
⟨fun _ ↦ surjective_of_epi f, epi_of_surjective⟩
lemma mono_iff_surjective :
Mono f ↔ ∀ ⦃X : Cᵒᵖ⦄, Function.Injective (f.app X) :=
⟨fun _ ↦ injective_of_mono f, mono_of_injective⟩
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/Monoidal.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic
/-!
# The monoidal category structure on presheaves of modules
Given a presheaf of commutative rings `R : Cᵒᵖ ⥤ CommRingCat`, we construct
the monoidal category structure on the category of presheaves of modules
`PresheafOfModules (R ⋙ forget₂ _ _)`. The tensor product `M₁ ⊗ M₂` is defined
as the presheaf of modules which sends `X : Cᵒᵖ` to `M₁.obj X ⊗ M₂.obj X`.
## Notes
This contribution was created as part of the AIM workshop
"Formalizing algebraic geometry" in June 2024.
-/
open CategoryTheory MonoidalCategory Category
universe v u v₁ u₁
variable {C : Type*} [Category C] {R : Cᵒᵖ ⥤ CommRingCat.{u}}
instance (X : Cᵒᵖ) : CommRing ((R ⋙ forget₂ _ RingCat).obj X) :=
inferInstanceAs (CommRing (R.obj X))
namespace PresheafOfModules
namespace Monoidal
variable (M₁ M₂ M₃ M₄ : PresheafOfModules.{u} (R ⋙ forget₂ _ _))
/-- Auxiliary definition for `tensorObj`. -/
noncomputable def tensorObjMap {X Y : Cᵒᵖ} (f : X ⟶ Y) : M₁.obj X ⊗ M₂.obj X ⟶
(ModuleCat.restrictScalars (R.map f).hom).obj (M₁.obj Y ⊗ M₂.obj Y) :=
ModuleCat.MonoidalCategory.tensorLift (fun m₁ m₂ ↦ M₁.map f m₁ ⊗ₜ M₂.map f m₂)
(by intro m₁ m₁' m₂; dsimp; rw [map_add, TensorProduct.add_tmul])
(by intro a m₁ m₂; dsimp; erw [M₁.map_smul]; rfl)
(by intro m₁ m₂ m₂'; dsimp; rw [map_add, TensorProduct.tmul_add])
(by intro a m₁ m₂; dsimp; erw [M₂.map_smul, TensorProduct.tmul_smul (r := R.map f a)]; rfl)
/-- The tensor product of two presheaves of modules. -/
@[simps obj]
noncomputable def tensorObj : PresheafOfModules (R ⋙ forget₂ _ _) where
obj X := M₁.obj X ⊗ M₂.obj X
map f := tensorObjMap M₁ M₂ f
map_id X := ModuleCat.MonoidalCategory.tensor_ext (by
intro m₁ m₂
dsimp [tensorObjMap]
simp
rfl) -- `ModuleCat.restrictScalarsId'App_inv_apply` doesn't get picked up due to type mismatch
map_comp f g := ModuleCat.MonoidalCategory.tensor_ext (by
intro m₁ m₂
dsimp [tensorObjMap]
simp)
variable {M₁ M₂ M₃ M₄}
@[simp]
lemma tensorObj_map_tmul {X Y : Cᵒᵖ} (f : X ⟶ Y) (m₁ : M₁.obj X) (m₂ : M₂.obj X) :
DFunLike.coe (α := (M₁.obj X ⊗ M₂.obj X :))
(β := fun _ ↦ (ModuleCat.restrictScalars (R.map f).hom).obj (M₁.obj Y ⊗ M₂.obj Y))
(ModuleCat.Hom.hom (R := ↑(R.obj X)) ((tensorObj M₁ M₂).map f)) (m₁ ⊗ₜ[R.obj X] m₂) =
M₁.map f m₁ ⊗ₜ[R.obj Y] M₂.map f m₂ := rfl
/-- The tensor product of two morphisms of presheaves of modules. -/
@[simps]
noncomputable def tensorHom (f : M₁ ⟶ M₂) (g : M₃ ⟶ M₄) : tensorObj M₁ M₃ ⟶ tensorObj M₂ M₄ where
app X := f.app X ⊗ₘ g.app X
naturality {X Y} φ := ModuleCat.MonoidalCategory.tensor_ext (fun m₁ m₃ ↦ by
dsimp
rw [tensorObj_map_tmul]
-- Need `erw` because of the type mismatch in `map` and the tensor product.
erw [ModuleCat.MonoidalCategory.tensorHom_tmul, tensorObj_map_tmul]
rw [naturality_apply, naturality_apply]
simp)
end Monoidal
open Monoidal
open ModuleCat.MonoidalCategory in
noncomputable instance monoidalCategoryStruct :
MonoidalCategoryStruct (PresheafOfModules.{u} (R ⋙ forget₂ _ _)) where
tensorObj := tensorObj
whiskerLeft _ _ _ g := tensorHom (𝟙 _) g
whiskerRight f _ := tensorHom f (𝟙 _)
tensorHom := tensorHom
tensorUnit := unit _
associator M₁ M₂ M₃ := isoMk (fun _ ↦ α_ _ _ _)
(fun _ _ _ ↦ ModuleCat.MonoidalCategory.tensor_ext₃' (by intros; rfl))
leftUnitor M := Iso.symm (isoMk (fun _ ↦ (λ_ _).symm) (fun X Y f ↦ by
ext m
dsimp [CommRingCat.forgetToRingCat_obj]
erw [leftUnitor_inv_apply, leftUnitor_inv_apply, tensorObj_map_tmul, (R.map f).hom.map_one]
rfl))
rightUnitor M := Iso.symm (isoMk (fun _ ↦ (ρ_ _).symm) (fun X Y f ↦ by
ext m
dsimp [CommRingCat.forgetToRingCat_obj]
erw [rightUnitor_inv_apply, rightUnitor_inv_apply, tensorObj_map_tmul, (R.map f).hom.map_one]
rfl))
noncomputable instance monoidalCategory :
MonoidalCategory (PresheafOfModules.{u} (R ⋙ forget₂ _ _)) where
tensorHom_def _ _ := by ext1; apply tensorHom_def
id_tensorHom_id _ _ := by ext1; apply id_tensorHom_id
tensorHom_comp_tensorHom _ _ _ _ := by ext1; apply tensorHom_comp_tensorHom
whiskerLeft_id M₁ M₂ := by
ext1 X
apply MonoidalCategory.whiskerLeft_id (C := ModuleCat (R.obj X))
id_whiskerRight _ _ := by
ext1 X
apply MonoidalCategory.id_whiskerRight (C := ModuleCat (R.obj X))
associator_naturality _ _ _ := by ext1; apply associator_naturality
leftUnitor_naturality _ := by ext1; apply leftUnitor_naturality
rightUnitor_naturality _ := by ext1; apply rightUnitor_naturality
pentagon _ _ _ _ := by ext1; apply pentagon
triangle _ _ := by ext1; apply triangle
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/Abelian.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.Colimits
import Mathlib.Algebra.Category.ModuleCat.Presheaf.Limits
import Mathlib.Algebra.Category.ModuleCat.Abelian
import Mathlib.CategoryTheory.Abelian.Basic
/-!
# The category of presheaves of modules is abelian
-/
universe v v₁ u₁ u
open CategoryTheory Category Limits
namespace PresheafOfModules
variable {C : Type u₁} [Category.{v₁} C] (R : Cᵒᵖ ⥤ RingCat.{u})
noncomputable instance : IsNormalEpiCategory (PresheafOfModules.{v} R) where
normalEpiOfEpi p _ := ⟨NormalEpi.mk _ (kernel.ι p) (kernel.condition _)
(evaluationJointlyReflectsColimits _ _ (fun _ =>
Abelian.isColimitMapCoconeOfCokernelCoforkOfπ _ _))⟩
noncomputable instance : IsNormalMonoCategory (PresheafOfModules.{v} R) where
normalMonoOfMono i _ := ⟨NormalMono.mk _ (cokernel.π i) (cokernel.condition _)
(evaluationJointlyReflectsLimits _ _ (fun _ =>
Abelian.isLimitMapConeOfKernelForkOfι _ _))⟩
noncomputable instance : Abelian (PresheafOfModules.{v} R) where
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/Sheafify.lean | import Mathlib.Algebra.Category.ModuleCat.Sheaf.ChangeOfRings
import Mathlib.CategoryTheory.Sites.LocallySurjective
/-!
# The associated sheaf of a presheaf of modules
In this file, given a presheaf of modules `M₀` over a presheaf of rings `R₀`,
we construct the associated sheaf of `M₀`. More precisely, if `R` is a sheaf of
rings and `α : R₀ ⟶ R.val` is locally bijective, and `A` is the sheafification
of the underlying presheaf of abelian groups of `M₀`, i.e. we have a locally bijective
map `φ : M₀.presheaf ⟶ A.val`, then we endow `A` with the structure of a
sheaf of modules over `R`: this is `PresheafOfModules.sheafify α φ`.
In many applications, the morphism `α` shall be the identity, but this more
general construction allows the sheafification of both the presheaf of rings
and the presheaf of modules.
-/
universe w v v₁ u₁ u
open CategoryTheory Functor
variable {C : Type u₁} [Category.{v₁} C] {J : GrothendieckTopology C}
namespace CategoryTheory
namespace Presieve.FamilyOfElements
section smul
variable {R : Cᵒᵖ ⥤ RingCat.{u}} {M : PresheafOfModules.{v} R} {X : C} {P : Presieve X}
(r : FamilyOfElements (R ⋙ forget _) P) (m : FamilyOfElements (M.presheaf ⋙ forget _) P)
/-- The scalar multiplication of family of elements of a presheaf of modules `M` over `R`
by a family of elements of `R`. -/
def smul : FamilyOfElements (M.presheaf ⋙ forget _) P := fun Y f hf =>
HSMul.hSMul (α := R.obj (Opposite.op Y)) (β := M.obj (Opposite.op Y)) (r f hf) (m f hf)
end smul
section
variable {R₀ R : Cᵒᵖ ⥤ RingCat.{u}} (α : R₀ ⟶ R) [Presheaf.IsLocallyInjective J α]
{M₀ : PresheafOfModules.{v} R₀} {A : Cᵒᵖ ⥤ AddCommGrpCat.{v}} (φ : M₀.presheaf ⟶ A)
[Presheaf.IsLocallyInjective J φ] (hA : Presheaf.IsSeparated J A)
{X : C} (r : R.obj (Opposite.op X)) (m : A.obj (Opposite.op X)) {P : Presieve X}
(r₀ : FamilyOfElements (R₀ ⋙ forget _) P) (m₀ : FamilyOfElements (M₀.presheaf ⋙ forget _) P)
include hA
lemma _root_.PresheafOfModules.Sheafify.app_eq_of_isLocallyInjective
{Y : C} (r₀ r₀' : R₀.obj (Opposite.op Y))
(m₀ m₀' : M₀.obj (Opposite.op Y))
(hr₀ : α.app _ r₀ = α.app _ r₀')
(hm₀ : φ.app _ m₀ = φ.app _ m₀') :
φ.app _ (r₀ • m₀) = φ.app _ (r₀' • m₀') := by
apply hA _ (Presheaf.equalizerSieve r₀ r₀' ⊓
Presheaf.equalizerSieve (F := M₀.presheaf) m₀ m₀')
· apply J.intersection_covering
· exact Presheaf.equalizerSieve_mem J α _ _ hr₀
· exact Presheaf.equalizerSieve_mem J φ _ _ hm₀
· intro Z g hg
rw [← NatTrans.naturality_apply (D := Ab), ← NatTrans.naturality_apply (D := Ab)]
erw [M₀.map_smul, M₀.map_smul, hg.1, hg.2]
rfl
lemma isCompatible_map_smul_aux {Y Z : C} (f : Y ⟶ X) (g : Z ⟶ Y)
(r₀ : R₀.obj (Opposite.op Y)) (r₀' : R₀.obj (Opposite.op Z))
(m₀ : M₀.obj (Opposite.op Y)) (m₀' : M₀.obj (Opposite.op Z))
(hr₀ : α.app _ r₀ = R.map f.op r) (hr₀' : α.app _ r₀' = R.map (f.op ≫ g.op) r)
(hm₀ : φ.app _ m₀ = A.map f.op m) (hm₀' : φ.app _ m₀' = A.map (f.op ≫ g.op) m) :
φ.app _ (M₀.map g.op (r₀ • m₀)) = φ.app _ (r₀' • m₀') := by
rw [← PresheafOfModules.Sheafify.app_eq_of_isLocallyInjective α φ hA (R₀.map g.op r₀) r₀'
(M₀.map g.op m₀) m₀', M₀.map_smul]
· rw [hr₀', R.map_comp, RingCat.comp_apply, ← hr₀, ← RingCat.comp_apply, NatTrans.naturality,
RingCat.comp_apply]
· rw [hm₀', A.map_comp, AddCommGrpCat.coe_comp, Function.comp_apply, ← hm₀]
erw [NatTrans.naturality_apply φ]
variable (hr₀ : (r₀.map (whiskerRight α (forget _))).IsAmalgamation r)
(hm₀ : (m₀.map (whiskerRight φ (forget _))).IsAmalgamation m)
include hr₀ hm₀ in
lemma isCompatible_map_smul : ((r₀.smul m₀).map (whiskerRight φ (forget _))).Compatible := by
intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ fac
let a₁ := r₀ f₁ h₁
let b₁ := m₀ f₁ h₁
let a₂ := r₀ f₂ h₂
let b₂ := m₀ f₂ h₂
let a₀ := R₀.map g₁.op a₁
let b₀ := M₀.map g₁.op b₁
have ha₁ : (α.app (Opposite.op Y₁)) a₁ = (R.map f₁.op) r := (hr₀ f₁ h₁).symm
have ha₂ : (α.app (Opposite.op Y₂)) a₂ = (R.map f₂.op) r := (hr₀ f₂ h₂).symm
have hb₁ : (φ.app (Opposite.op Y₁)) b₁ = (A.map f₁.op) m := (hm₀ f₁ h₁).symm
have hb₂ : (φ.app (Opposite.op Y₂)) b₂ = (A.map f₂.op) m := (hm₀ f₂ h₂).symm
have ha₀ : (α.app (Opposite.op Z)) a₀ = (R.map (f₁.op ≫ g₁.op)) r := by
rw [← RingCat.comp_apply, NatTrans.naturality, RingCat.comp_apply, ha₁, Functor.map_comp,
RingCat.comp_apply]
have hb₀ : (φ.app (Opposite.op Z)) b₀ = (A.map (f₁.op ≫ g₁.op)) m := by
dsimp [b₀]
erw [NatTrans.naturality_apply φ, hb₁, Functor.map_comp, ConcreteCategory.comp_apply]
have ha₀' : (α.app (Opposite.op Z)) a₀ = (R.map (f₂.op ≫ g₂.op)) r := by
rw [ha₀, ← op_comp, fac, op_comp]
have hb₀' : (φ.app (Opposite.op Z)) b₀ = (A.map (f₂.op ≫ g₂.op)) m := by
rw [hb₀, ← op_comp, fac, op_comp]
dsimp
erw [← NatTrans.naturality_apply φ, ← NatTrans.naturality_apply φ]
exact (isCompatible_map_smul_aux α φ hA r m f₁ g₁ a₁ a₀ b₁ b₀ ha₁ ha₀ hb₁ hb₀).trans
(isCompatible_map_smul_aux α φ hA r m f₂ g₂ a₂ a₀ b₂ b₀ ha₂ ha₀' hb₂ hb₀').symm
end
end Presieve.FamilyOfElements
end CategoryTheory
variable {R₀ : Cᵒᵖ ⥤ RingCat.{u}} {R : Sheaf J RingCat.{u}} (α : R₀ ⟶ R.val)
[Presheaf.IsLocallyInjective J α] [Presheaf.IsLocallySurjective J α]
namespace PresheafOfModules
variable {M₀ : PresheafOfModules.{v} R₀} {A : Sheaf J AddCommGrpCat.{v}}
(φ : M₀.presheaf ⟶ A.val)
[Presheaf.IsLocallyInjective J φ] [Presheaf.IsLocallySurjective J φ]
namespace Sheafify
variable {X Y : Cᵒᵖ} (π : X ⟶ Y) (r r' : R.val.obj X) (m m' : A.val.obj X)
/-- Assuming `α : R₀ ⟶ R.val` is the sheafification map of a presheaf of rings `R₀`
and `φ : M₀.presheaf ⟶ A.val` is the sheafification map of the underlying
sheaf of abelian groups of a presheaf of modules `M₀` over `R₀`, then given
`r : R.val.obj X` and `m : A.val.obj X`, this structure contains the data
of `x : A.val.obj X` along with the property which makes `x` a good candidate
for the definition of the scalar multiplication `r • m`. -/
structure SMulCandidate where
/-- The candidate for the scalar product `r • m`. -/
x : A.val.obj X
h ⦃Y : Cᵒᵖ⦄ (f : X ⟶ Y) (r₀ : R₀.obj Y) (hr₀ : α.app Y r₀ = R.val.map f r)
(m₀ : M₀.obj Y) (hm₀ : φ.app Y m₀ = A.val.map f m) : A.val.map f x = φ.app Y (r₀ • m₀)
/-- Constructor for `SMulCandidate`. -/
def SMulCandidate.mk' (S : Sieve X.unop) (hS : S ∈ J X.unop)
(r₀ : Presieve.FamilyOfElements (R₀ ⋙ forget _) S.arrows)
(m₀ : Presieve.FamilyOfElements (M₀.presheaf ⋙ forget _) S.arrows)
(hr₀ : (r₀.map (whiskerRight α (forget _))).IsAmalgamation r)
(hm₀ : (m₀.map (whiskerRight φ (forget _))).IsAmalgamation m)
(a : A.val.obj X)
(ha : ((r₀.smul m₀).map (whiskerRight φ (forget _))).IsAmalgamation a) :
SMulCandidate α φ r m where
x := a
h Y f a₀ ha₀ b₀ hb₀ := by
apply A.isSeparated _ _ (J.pullback_stable f.unop hS)
rintro Z g hg
dsimp at hg
rw [← ConcreteCategory.comp_apply, ← A.val.map_comp, ← NatTrans.naturality_apply (D := Ab)]
erw [M₀.map_smul] -- Mismatch between `M₀.map` and `M₀.presheaf.map`
refine (ha _ hg).trans (app_eq_of_isLocallyInjective α φ A.isSeparated _ _ _ _ ?_ ?_)
· rw [← RingCat.comp_apply, NatTrans.naturality, RingCat.comp_apply, ha₀]
apply (hr₀ _ hg).symm.trans
simp
· erw [NatTrans.naturality_apply φ, hb₀]
apply (hm₀ _ hg).symm.trans
dsimp
rw [Functor.map_comp]
rfl
instance : Nonempty (SMulCandidate α φ r m) := ⟨by
let S := (Presheaf.imageSieve α r ⊓ Presheaf.imageSieve φ m)
have hS : S ∈ J _ := by
apply J.intersection_covering
all_goals apply Presheaf.imageSieve_mem
have h₁ : S ≤ Presheaf.imageSieve α r := fun _ _ h => h.1
have h₂ : S ≤ Presheaf.imageSieve φ m := fun _ _ h => h.2
let r₀ := (Presieve.FamilyOfElements.localPreimage (whiskerRight α (forget _)) r).restrict h₁
let m₀ := (Presieve.FamilyOfElements.localPreimage (whiskerRight φ (forget _)) m).restrict h₂
have hr₀ : (r₀.map (whiskerRight α (forget _))).IsAmalgamation r := by
rw [Presieve.FamilyOfElements.restrict_map]
apply Presieve.isAmalgamation_restrict
apply Presieve.FamilyOfElements.isAmalgamation_map_localPreimage
have hm₀ : (m₀.map (whiskerRight φ (forget _))).IsAmalgamation m := by
rw [Presieve.FamilyOfElements.restrict_map]
apply Presieve.isAmalgamation_restrict
apply Presieve.FamilyOfElements.isAmalgamation_map_localPreimage
exact SMulCandidate.mk' α φ r m S hS r₀ m₀ hr₀ hm₀ _ (Presieve.IsSheafFor.isAmalgamation
(((sheafCompose J (forget _)).obj A).2.isSheafFor S hS)
(Presieve.FamilyOfElements.isCompatible_map_smul α φ A.isSeparated r m r₀ m₀ hr₀ hm₀))⟩
instance : Subsingleton (SMulCandidate α φ r m) where
allEq := by
rintro ⟨x₁, h₁⟩ ⟨x₂, h₂⟩
simp only [SMulCandidate.mk.injEq]
let S := (Presheaf.imageSieve α r ⊓ Presheaf.imageSieve φ m)
have hS : S ∈ J _ := by
apply J.intersection_covering
all_goals apply Presheaf.imageSieve_mem
apply A.isSeparated _ _ hS
intro Y f ⟨⟨r₀, hr₀⟩, ⟨m₀, hm₀⟩⟩
rw [h₁ f.op r₀ hr₀ m₀ hm₀, h₂ f.op r₀ hr₀ m₀ hm₀]
noncomputable instance : Unique (SMulCandidate α φ r m) :=
uniqueOfSubsingleton (Nonempty.some inferInstance)
/-- The (unique) element in `SMulCandidate α φ r m`. -/
noncomputable def smulCandidate : SMulCandidate α φ r m := default
/-- The scalar multiplication on the sheafification of a presheaf of modules. -/
noncomputable def smul : A.val.obj X := (smulCandidate α φ r m).x
lemma map_smul_eq {Y : Cᵒᵖ} (f : X ⟶ Y) (r₀ : R₀.obj Y) (hr₀ : α.app Y r₀ = R.val.map f r)
(m₀ : M₀.obj Y) (hm₀ : φ.app Y m₀ = A.val.map f m) :
A.val.map f (smul α φ r m) = φ.app Y (r₀ • m₀) :=
(smulCandidate α φ r m).h f r₀ hr₀ m₀ hm₀
protected lemma one_smul : smul α φ 1 m = m := by
apply A.isSeparated _ _ (Presheaf.imageSieve_mem J φ m)
rintro Y f ⟨m₀, hm₀⟩
rw [← hm₀, map_smul_eq α φ 1 m f.op 1 (by simp) m₀ hm₀, one_smul]
protected lemma zero_smul : smul α φ 0 m = 0 := by
apply A.isSeparated _ _ (Presheaf.imageSieve_mem J φ m)
rintro Y f ⟨m₀, hm₀⟩
rw [map_smul_eq α φ 0 m f.op 0 (by simp) m₀ hm₀, zero_smul, map_zero,
(A.val.map f.op).hom.map_zero]
protected lemma smul_zero : smul α φ r 0 = 0 := by
apply A.isSeparated _ _ (Presheaf.imageSieve_mem J α r)
rintro Y f ⟨r₀, hr₀⟩
rw [(A.val.map f.op).hom.map_zero, map_smul_eq α φ r 0 f.op r₀ hr₀ 0 (by simp),
smul_zero, map_zero]
protected lemma smul_add : smul α φ r (m + m') = smul α φ r m + smul α φ r m' := by
let S := Presheaf.imageSieve α r ⊓ Presheaf.imageSieve φ m ⊓ Presheaf.imageSieve φ m'
have hS : S ∈ J X.unop := by
refine J.intersection_covering (J.intersection_covering ?_ ?_) ?_
all_goals apply Presheaf.imageSieve_mem
apply A.isSeparated _ _ hS
rintro Y f ⟨⟨⟨r₀, hr₀⟩, ⟨m₀ : M₀.obj _, hm₀ : (φ.app _) _ = _⟩⟩,
⟨m₀' : M₀.obj _, hm₀' : (φ.app _) _ = _⟩⟩
rw [(A.val.map f.op).hom.map_add, map_smul_eq α φ r m f.op r₀ hr₀ m₀ hm₀,
map_smul_eq α φ r m' f.op r₀ hr₀ m₀' hm₀',
map_smul_eq α φ r (m + m') f.op r₀ hr₀ (m₀ + m₀')
(by rw [_root_.map_add, _root_.map_add, hm₀, hm₀']),
smul_add, _root_.map_add]
protected lemma add_smul : smul α φ (r + r') m = smul α φ r m + smul α φ r' m := by
let S := Presheaf.imageSieve α r ⊓ Presheaf.imageSieve α r' ⊓ Presheaf.imageSieve φ m
have hS : S ∈ J X.unop := by
refine J.intersection_covering (J.intersection_covering ?_ ?_) ?_
all_goals apply Presheaf.imageSieve_mem
apply A.isSeparated _ _ hS
rintro Y f ⟨⟨⟨r₀ : R₀.obj _, (hr₀ : (α.app (Opposite.op Y)) r₀ = (R.val.map f.op) r)⟩,
⟨r₀' : R₀.obj _, (hr₀' : (α.app (Opposite.op Y)) r₀' = (R.val.map f.op) r')⟩⟩, ⟨m₀, hm₀⟩⟩
rw [(A.val.map f.op).hom.map_add, map_smul_eq α φ r m f.op r₀ hr₀ m₀ hm₀,
map_smul_eq α φ r' m f.op r₀' hr₀' m₀ hm₀,
map_smul_eq α φ (r + r') m f.op (r₀ + r₀') (by rw [_root_.map_add, _root_.map_add, hr₀, hr₀'])
m₀ hm₀, add_smul, _root_.map_add]
protected lemma mul_smul : smul α φ (r * r') m = smul α φ r (smul α φ r' m) := by
let S := Presheaf.imageSieve α r ⊓ Presheaf.imageSieve α r' ⊓ Presheaf.imageSieve φ m
have hS : S ∈ J X.unop := by
refine J.intersection_covering (J.intersection_covering ?_ ?_) ?_
all_goals apply Presheaf.imageSieve_mem
apply A.isSeparated _ _ hS
rintro Y f ⟨⟨⟨r₀ : R₀.obj _, (hr₀ : (α.app (Opposite.op Y)) r₀ = (R.val.map f.op) r)⟩,
⟨r₀' : R₀.obj _, (hr₀' : (α.app (Opposite.op Y)) r₀' = (R.val.map f.op) r')⟩⟩,
⟨m₀ : M₀.obj _, hm₀⟩⟩
rw [map_smul_eq α φ (r * r') m f.op (r₀ * r₀')
(by rw [map_mul, map_mul, hr₀, hr₀']) m₀ hm₀, mul_smul,
map_smul_eq α φ r (smul α φ r' m) f.op r₀ hr₀ (r₀' • m₀)
(map_smul_eq α φ r' m f.op r₀' hr₀' m₀ hm₀).symm]
variable (X)
/-- The module structure on the sections of the sheafification of the underlying
presheaf of abelian groups of a presheaf of modules. -/
noncomputable def module : Module (R.val.obj X) (A.val.obj X) where
smul r m := smul α φ r m
one_smul := Sheafify.one_smul α φ
zero_smul := Sheafify.zero_smul α φ
smul_zero := Sheafify.smul_zero α φ
smul_add := Sheafify.smul_add α φ
add_smul := Sheafify.add_smul α φ
mul_smul := Sheafify.mul_smul α φ
protected lemma map_smul :
A.val.map π (smul α φ r m) = smul α φ (R.val.map π r) (A.val.map π m) := by
let S := Presheaf.imageSieve α (R.val.map π r) ⊓ Presheaf.imageSieve φ (A.val.map π m)
have hS : S ∈ J Y.unop := by
apply J.intersection_covering
all_goals apply Presheaf.imageSieve_mem
apply A.isSeparated _ _ hS
rintro Y f ⟨⟨r₀,
(hr₀ : (α.app (Opposite.op Y)).hom r₀ = (R.val.map f.op).hom ((R.val.map π).hom r))⟩,
⟨m₀, (hm₀ : (φ.app _) _ = _)⟩⟩
rw [← ConcreteCategory.comp_apply, ← Functor.map_comp,
map_smul_eq α φ r m (π ≫ f.op) r₀ (by rw [hr₀, Functor.map_comp, RingCat.comp_apply]) m₀
(by rw [hm₀, Functor.map_comp, ConcreteCategory.comp_apply]),
map_smul_eq α φ (R.val.map π r) (A.val.map π m) f.op r₀ hr₀ m₀ hm₀]
end Sheafify
/-- Assuming `α : R₀ ⟶ R.val` is the sheafification map of a presheaf of rings `R₀`
and `φ : M₀.presheaf ⟶ A.val` is the sheafification map of the underlying
sheaf of abelian groups of a presheaf of modules `M₀` over `R₀`, this is
the sheaf of modules over `R` which is obtained by endowing the sections of
`A.val` with a scalar multiplication. -/
noncomputable def sheafify : SheafOfModules.{v} R where
val := letI := Sheafify.module α φ; ofPresheaf A.val (Sheafify.map_smul _ _)
isSheaf := A.cond
/-- The canonical morphism from a presheaf of modules to its associated sheaf. -/
noncomputable def toSheafify : M₀ ⟶ (restrictScalars α).obj (sheafify α φ).val :=
homMk φ (fun X r₀ m₀ ↦ by
simpa using (Sheafify.map_smul_eq α φ (α.app _ r₀) (φ.app _ m₀) (𝟙 _)
r₀ (by simp) m₀ (by simp)).symm)
lemma toSheafify_app_apply (X : Cᵒᵖ) (x : M₀.obj X) :
((toSheafify α φ).app X).hom x = φ.app X x := rfl
/-- `@[simp]`-normal form of `toSheafify_app_apply`. -/
@[simp]
lemma toSheafify_app_apply' (X : Cᵒᵖ) (x : M₀.obj X) :
DFunLike.coe (F := (_ →ₗ[_] ↑((ModuleCat.restrictScalars (α.app X).hom).obj _)))
((toSheafify α φ).app X).hom x = φ.app X x := rfl
@[simp]
lemma toPresheaf_map_toSheafify : (toPresheaf R₀).map (toSheafify α φ) = φ := rfl
instance : IsLocallyInjective J (toSheafify α φ) := by
dsimp [IsLocallyInjective]; infer_instance
instance : IsLocallySurjective J (toSheafify α φ) := by
dsimp [IsLocallySurjective]; infer_instance
variable [J.WEqualsLocallyBijective AddCommGrpCat.{v}]
/-- The bijection `((sheafify α φ).val ⟶ F) ≃ (M₀ ⟶ (restrictScalars α).obj F)` which
is part of the universal property of the sheafification of the presheaf of modules `M₀`,
when `F` is a presheaf of modules which is a sheaf. -/
noncomputable def sheafifyHomEquiv' {F : PresheafOfModules.{v} R.val}
(hF : Presheaf.IsSheaf J F.presheaf) :
((sheafify α φ).val ⟶ F) ≃ (M₀ ⟶ (restrictScalars α).obj F) :=
(restrictHomEquivOfIsLocallySurjective α hF).trans
(homEquivOfIsLocallyBijective (f := toSheafify α φ)
(N := (restrictScalars α).obj F) hF)
lemma comp_toPresheaf_map_sheafifyHomEquiv'_symm_hom {F : PresheafOfModules.{v} R.val}
(hF : Presheaf.IsSheaf J F.presheaf) (f : M₀ ⟶ (restrictScalars α).obj F) :
φ ≫ (toPresheaf R.val).map ((sheafifyHomEquiv' α φ hF).symm f) = (toPresheaf R₀).map f :=
(toPresheaf _).congr_map ((sheafifyHomEquiv' α φ hF).apply_symm_apply f)
/-- The bijection
`(sheafify α φ ⟶ F) ≃ (M₀ ⟶ (restrictScalars α).obj ((SheafOfModules.forget _).obj F))`
which is part of the universal property of the sheafification of the presheaf of modules `M₀`,
for any sheaf of modules `F`, see `PresheafOfModules.sheafificationAdjunction` -/
noncomputable def sheafifyHomEquiv {F : SheafOfModules.{v} R} :
(sheafify α φ ⟶ F) ≃
(M₀ ⟶ (restrictScalars α).obj ((SheafOfModules.forget _).obj F)) :=
(SheafOfModules.fullyFaithfulForget R).homEquiv.trans
(sheafifyHomEquiv' α φ F.isSheaf)
section
variable {M₀' : PresheafOfModules.{v} R₀} {A' : Sheaf J AddCommGrpCat.{v}}
(φ' : M₀'.presheaf ⟶ A'.val)
[Presheaf.IsLocallyInjective J φ'] [Presheaf.IsLocallySurjective J φ']
(τ₀ : M₀ ⟶ M₀') (τ : A ⟶ A')
/-- The morphism of sheaves of modules `sheafify α φ ⟶ sheafify α φ'`
induced by morphisms `τ₀ : M₀ ⟶ M₀'` and `τ : A ⟶ A'`
which satisfy `τ₀.hom ≫ φ' = φ ≫ τ.val`. -/
@[simps]
noncomputable def sheafifyMap (fac : (toPresheaf R₀).map τ₀ ≫ φ' = φ ≫ τ.val) :
sheafify α φ ⟶ sheafify α φ' where
val := homMk τ.val (fun X r m ↦ by
let f := (sheafifyHomEquiv' α φ (by exact A'.cond)).symm (τ₀ ≫ toSheafify α φ')
suffices τ.val = (toPresheaf _).map f by simpa only [this] using (f.app X).hom.map_smul r m
apply ((J.W_of_isLocallyBijective φ).homEquiv _ A'.cond).injective
dsimp [f]
erw [comp_toPresheaf_map_sheafifyHomEquiv'_symm_hom]
rw [← fac, Functor.map_comp, toPresheaf_map_toSheafify])
end
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/Pushforward.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.ChangeOfRings
/-!
# Pushforward of presheaves of modules
If `F : C ⥤ D`, the precomposition `F.op ⋙ _` induces a functor from presheaves
over `D` to presheaves over `C`. When `R : Dᵒᵖ ⥤ RingCat`, we define the
induced functor `pushforward₀ : PresheafOfModules.{v} R ⥤ PresheafOfModules.{v} (F.op ⋙ R)`
on presheaves of modules.
In case we have a morphism of presheaves of rings `S ⟶ F.op ⋙ R`, we also construct
a functor `pushforward : PresheafOfModules.{v} R ⥤ PresheafOfModules.{v} S`, and
we show that they interact with the composition of morphisms similarly as pseudofunctors.
-/
universe v v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ u
open CategoryTheory Functor
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
{E : Type u₃} [Category.{v₃} E] {E' : Type u₄} [Category.{v₄} E']
namespace PresheafOfModules
variable (F : C ⥤ D)
/-- Implementation of `pushforward₀`. -/
@[simps]
def pushforward₀_obj (R : Dᵒᵖ ⥤ RingCat.{u}) (M : PresheafOfModules R) :
PresheafOfModules (F.op ⋙ R) :=
{ obj X := ModuleCat.of _ (M.obj (F.op.obj X))
map {X Y} f := M.map (F.op.map f)
map_id X := by
refine ModuleCat.hom_ext
-- Work around an instance diamond for `restrictScalarsId'`
(@LinearMap.ext _ _ _ _ _ _ _ _ (_) (_) _ _ _ (fun x => ?_))
exact (M.congr_map_apply (F.op.map_id X) x).trans (by simp)
map_comp := fun f g ↦ by
refine ModuleCat.hom_ext
-- Work around an instance diamond for `restrictScalarsId'`
(@LinearMap.ext _ _ _ _ _ _ _ _ (_) (_) _ _ _ (fun x => ?_))
exact (M.congr_map_apply (F.op.map_comp f g) x).trans (by simp) }
/-- The pushforward functor on presheaves of modules for a functor `F : C ⥤ D` and
`R : Dᵒᵖ ⥤ RingCat`. On the underlying presheaves of abelian groups, it is induced
by the precomposition with `F.op`. -/
def pushforward₀ (R : Dᵒᵖ ⥤ RingCat.{u}) :
PresheafOfModules.{v} R ⥤ PresheafOfModules.{v} (F.op ⋙ R) where
obj M := pushforward₀_obj F R M
map {M₁ M₂} φ := { app X := φ.app _ }
/-- The pushforward of presheaves of modules commutes with the forgetful functor
to presheaves of abelian groups. -/
noncomputable def pushforward₀CompToPresheaf (R : Dᵒᵖ ⥤ RingCat.{u}) :
pushforward₀.{v} F R ⋙ toPresheaf _ ≅ toPresheaf _ ⋙ (whiskeringLeft _ _ _).obj F.op :=
Iso.refl _
variable {F}
variable {R : Dᵒᵖ ⥤ RingCat.{u}} {S : Cᵒᵖ ⥤ RingCat.{u}} (φ : S ⟶ F.op ⋙ R)
attribute [local simp] pushforward₀ in
/-- The pushforward functor `PresheafOfModules R ⥤ PresheafOfModules S` induced by
a morphism of presheaves of rings `S ⟶ F.op ⋙ R`. -/
@[simps! obj_obj]
noncomputable def pushforward : PresheafOfModules.{v} R ⥤ PresheafOfModules.{v} S :=
pushforward₀ F R ⋙ restrictScalars φ
/-- The pushforward of presheaves of modules commutes with the forgetful functor
to presheaves of abelian groups. -/
noncomputable def pushforwardCompToPresheaf :
pushforward.{v} φ ⋙ toPresheaf _ ≅ toPresheaf _ ⋙ (whiskeringLeft _ _ _).obj F.op :=
Iso.refl _
lemma pushforward_obj_map_apply (M : PresheafOfModules.{v} R) {X Y : Cᵒᵖ} (f : X ⟶ Y)
(m : (ModuleCat.restrictScalars (φ.app X).hom).obj (M.obj (Opposite.op (F.obj X.unop)))) :
(((pushforward φ).obj M).map f).hom m = M.map (F.map f.unop).op m := rfl
/-- `@[simp]`-normal form of `pushforward_obj_map_apply`. -/
@[simp]
lemma pushforward_obj_map_apply' (M : PresheafOfModules.{v} R) {X Y : Cᵒᵖ} (f : X ⟶ Y)
(m : (ModuleCat.restrictScalars (φ.app X).hom).obj (M.obj (Opposite.op (F.obj X.unop)))) :
DFunLike.coe
(F := ↑((ModuleCat.restrictScalars _).obj _) →ₗ[_]
↑((ModuleCat.restrictScalars (S.map f).hom).obj ((ModuleCat.restrictScalars _).obj _)))
(((pushforward φ).obj M).map f).hom m = M.map (F.map f.unop).op m := rfl
lemma pushforward_map_app_apply {M N : PresheafOfModules.{v} R} (α : M ⟶ N) (X : Cᵒᵖ)
(m : (ModuleCat.restrictScalars (φ.app X).hom).obj (M.obj (Opposite.op (F.obj X.unop)))) :
(((pushforward φ).map α).app X).hom m = α.app (Opposite.op (F.obj X.unop)) m := rfl
/-- `@[simp]`-normal form of `pushforward_map_app_apply`. -/
@[simp]
lemma pushforward_map_app_apply' {M N : PresheafOfModules.{v} R} (α : M ⟶ N) (X : Cᵒᵖ)
(m : (ModuleCat.restrictScalars (φ.app X).hom).obj (M.obj (Opposite.op (F.obj X.unop)))) :
DFunLike.coe
(F := ↑((ModuleCat.restrictScalars _).obj _) →ₗ[_] ↑((ModuleCat.restrictScalars _).obj _))
(((pushforward φ).map α).app X).hom m = α.app (Opposite.op (F.obj X.unop)) m := rfl
section
variable (R) in
/-- The pushforward functor by the identity morphism identifies to
the identify functor of the category of presheaves of modules. -/
noncomputable def pushforwardId :
pushforward.{v} (S := R) (F := 𝟭 _) (𝟙 R) ≅ 𝟭 _ :=
Iso.refl _
section
variable {T : Eᵒᵖ ⥤ RingCat.{u}} {G : D ⥤ E} (ψ : R ⟶ G.op ⋙ T)
/-- The composition of two pushforward functors on categories of presheaves of modules
identify to the pushforward for the composition. -/
noncomputable def pushforwardComp :
pushforward.{v} ψ ⋙ pushforward.{v} φ ≅
pushforward.{v} (F := F ⋙ G) (φ ≫ whiskerLeft F.op ψ) :=
Iso.refl _
variable {T' : E'ᵒᵖ ⥤ RingCat.{u}} {G' : E ⥤ E'} (ψ' : T ⟶ G'.op ⋙ T')
lemma pushforward_assoc :
(pushforward ψ').isoWhiskerLeft (pushforwardComp φ ψ) ≪≫
pushforwardComp (F := F ⋙ G) (φ ≫ F.op.whiskerLeft ψ) ψ' =
((pushforward ψ').associator (pushforward ψ) (pushforward φ)).symm ≪≫
isoWhiskerRight (pushforwardComp ψ ψ') (pushforward φ) ≪≫
pushforwardComp (G := G ⋙ G') φ (ψ ≫ G.op.whiskerLeft ψ') := by ext; rfl
end
lemma pushforward_comp_id :
pushforwardComp.{v} (F := 𝟭 C) (𝟙 S) φ =
isoWhiskerLeft (pushforward.{v} φ) (pushforwardId S) ≪≫ rightUnitor _ := by ext; rfl
lemma pushforward_id_comp :
pushforwardComp.{v} (G := 𝟭 _) φ (𝟙 R) =
isoWhiskerRight (pushforwardId R) (pushforward.{v} φ) ≪≫ leftUnitor _ := by ext; rfl
end
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/Generator.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.Abelian
import Mathlib.Algebra.Category.ModuleCat.Presheaf.EpiMono
import Mathlib.Algebra.Category.ModuleCat.Presheaf.Free
import Mathlib.Algebra.Homology.ShortComplex.Exact
import Mathlib.CategoryTheory.Elements
import Mathlib.CategoryTheory.Generator.Basic
/-!
# Generators for the category of presheaves of modules
In this file, given a presheaf of rings `R` on a category `C`,
we study the set `freeYoneda R` of presheaves of modules
of form `(free R).obj (yoneda.obj X)` for `X : C`, i.e.
free presheaves of modules generated by the Yoneda
presheaf represented by some `X : C` (the functor
represented by such a presheaf of modules is the evaluation
functor `M ↦ M.obj (op X)`, see `freeYonedaEquiv`).
Lemmas `PresheafOfModules.freeYoneda.isSeparating` and
`PresheafOfModules.freeYoneda.isDetecting` assert that this
set `freeYoneda R` is separating and detecting.
We deduce that if `C : Type u` is a small category,
and `R : Cᵒᵖ ⥤ RingCat.{u}`, then `PresheafOfModules.{u} R`
is a well-powered category.
Finally, given `M : PresheafOfModules.{u} R`, we consider
the canonical epimorphism of presheaves of modules
`M.fromFreeYonedaCoproduct : M.freeYonedaCoproduct ⟶ M`
where `M.freeYonedaCoproduct` is a coproduct indexed
by elements of `M`, i.e. pairs `⟨X : Cᵒᵖ, a : M.obj X⟩`,
of the objects `(free R).obj (yoneda.obj X.unop)`.
This is used in the definition
`PresheafOfModules.isColimitFreeYonedaCoproductsCokernelCofork`
in order to obtain that any presheaf of modules is a cokernel
of a morphism between coproducts of objects in `freeYoneda R`.
-/
universe v v₁ u u₁
open CategoryTheory Limits
namespace PresheafOfModules
variable {C : Type u} [Category.{v} C] {R : Cᵒᵖ ⥤ RingCat.{v}}
/-- When `R : Cᵒᵖ ⥤ RingCat`, `M : PresheafOfModules R`, and `X : C`, this is the
bijection `((free R).obj (yoneda.obj X) ⟶ M) ≃ M.obj (Opposite.op X)`. -/
noncomputable def freeYonedaEquiv {M : PresheafOfModules.{v} R} {X : C} :
((free R).obj (yoneda.obj X) ⟶ M) ≃ M.obj (Opposite.op X) :=
freeHomEquiv.trans yonedaEquiv
lemma freeYonedaEquiv_symm_app (M : PresheafOfModules.{v} R) (X : C)
(x : M.obj (Opposite.op X)) :
(freeYonedaEquiv.symm x).app (Opposite.op X) (ModuleCat.freeMk (𝟙 _)) = x := by
dsimp [freeYonedaEquiv, freeHomEquiv, yonedaEquiv]
rw [ModuleCat.freeDesc_apply, op_id, M.presheaf.map_id]
rfl
lemma freeYonedaEquiv_comp {M N : PresheafOfModules.{v} R} {X : C}
(m : ((free R).obj (yoneda.obj X) ⟶ M)) (φ : M ⟶ N) :
freeYonedaEquiv (m ≫ φ) = φ.app _ (freeYonedaEquiv m) := rfl
variable (R) in
/-- The set of `PresheafOfModules.{v} R` consisting of objects of the
form `(free R).obj (yoneda.obj X)` for some `X`. -/
def freeYoneda : ObjectProperty (PresheafOfModules.{v} R) := .ofObj (yoneda ⋙ free R).obj
namespace freeYoneda
instance : ObjectProperty.Small.{u} (freeYoneda R) := by
dsimp [freeYoneda]
infer_instance
variable (R)
lemma isSeparating : ObjectProperty.IsSeparating (freeYoneda R) := by
intro M N f₁ f₂ h
ext ⟨X⟩ m
obtain ⟨g, rfl⟩ := freeYonedaEquiv.surjective m
exact congr_arg freeYonedaEquiv (h _ ⟨X⟩ g)
lemma isDetecting : ObjectProperty.IsDetecting (freeYoneda R) :=
(isSeparating R).isDetecting
end freeYoneda
instance wellPowered {C₀ : Type u} [SmallCategory C₀] (R₀ : C₀ᵒᵖ ⥤ RingCat.{u}) :
WellPowered.{u} (PresheafOfModules.{u} R₀) :=
wellPowered_of_isDetecting (freeYoneda.isDetecting R₀)
/-- The type of elements of a presheaf of modules. A term of this type is a pair
`⟨X, a⟩` with `X : Cᵒᵖ` and `a : M.obj X`. -/
abbrev Elements {C : Type u₁} [Category.{v₁} C] {R : Cᵒᵖ ⥤ RingCat.{u}}
(M : PresheafOfModules.{v} R) := ((toPresheaf R).obj M ⋙ forget Ab).Elements
/-- Given a presheaf of modules `M`, this is a constructor for the type `M.Elements`. -/
noncomputable abbrev elementsMk {C : Type u₁} [Category.{v₁} C] {R : Cᵒᵖ ⥤ RingCat.{u}}
(M : PresheafOfModules.{v} R) (X : Cᵒᵖ) (x : M.obj X) : M.Elements :=
Functor.elementsMk _ X x
namespace Elements
variable {C : Type u} [Category.{v} C] {R : Cᵒᵖ ⥤ RingCat.{v}} {M : PresheafOfModules.{v} R}
/-- Given an element `m : M.Elements` of a presheaf of modules `M`, this is the
free presheaf of modules on the Yoneda presheaf of types corresponding to the
underlying object of `m`. -/
noncomputable abbrev freeYoneda (m : M.Elements) :
PresheafOfModules.{v} R := (free R).obj (yoneda.obj m.1.unop)
/-- Given an element `m : M.Elements` of a presheaf of modules `M`, this is
the canonical morphism `m.freeYoneda ⟶ M`. -/
noncomputable abbrev fromFreeYoneda (m : M.Elements) :
m.freeYoneda ⟶ M :=
freeYonedaEquiv.symm m.2
lemma fromFreeYoneda_app_apply (m : M.Elements) :
m.fromFreeYoneda.app m.1 (ModuleCat.freeMk (𝟙 _)) = m.2 := by
apply freeYonedaEquiv_symm_app
end Elements
section
variable {C : Type u} [SmallCategory.{u} C] {R : Cᵒᵖ ⥤ RingCat.{u}} (M : PresheafOfModules.{u} R)
/-- Given a presheaf of modules `M`, this is the coproduct of
all free Yoneda presheaves `m.freeYoneda` for all `m : M.Elements`. -/
noncomputable abbrev freeYonedaCoproduct : PresheafOfModules.{u} R :=
∐ (Elements.freeYoneda (M := M))
/-- Given an element `m : M.Elements` of a presheaf of modules `M`, this is the
canonical inclusion `m.freeYoneda ⟶ M.freeYonedaCoproduct`. -/
noncomputable abbrev ιFreeYonedaCoproduct (m : M.Elements) :
m.freeYoneda ⟶ M.freeYonedaCoproduct :=
Sigma.ι _ m
/-- Given a presheaf of modules `M`, this is the
canonical morphism `M.freeYonedaCoproduct ⟶ M`. -/
noncomputable def fromFreeYonedaCoproduct :
M.freeYonedaCoproduct ⟶ M :=
Sigma.desc Elements.fromFreeYoneda
/-- Given an element `m` of a presheaf of modules `M`, this is the associated
canonical section of the presheaf `M.freeYonedaCoproduct` over the object `m.1`. -/
noncomputable def freeYonedaCoproductMk (m : M.Elements) :
M.freeYonedaCoproduct.obj m.1 :=
(M.ιFreeYonedaCoproduct m).app _ (ModuleCat.freeMk (𝟙 _))
@[reassoc (attr := simp)]
lemma ι_fromFreeYonedaCoproduct (m : M.Elements) :
M.ιFreeYonedaCoproduct m ≫ M.fromFreeYonedaCoproduct = m.fromFreeYoneda := by
apply Sigma.ι_desc
lemma ι_fromFreeYonedaCoproduct_apply (m : M.Elements) (X : Cᵒᵖ) (x : m.freeYoneda.obj X) :
M.fromFreeYonedaCoproduct.app X ((M.ιFreeYonedaCoproduct m).app X x) =
m.fromFreeYoneda.app X x :=
congr_fun ((evaluation R X ⋙ forget _).congr_map (M.ι_fromFreeYonedaCoproduct m)) x
@[simp]
lemma fromFreeYonedaCoproduct_app_mk (m : M.Elements) :
M.fromFreeYonedaCoproduct.app _ (M.freeYonedaCoproductMk m) = m.2 := by
dsimp [freeYonedaCoproductMk]
erw [M.ι_fromFreeYonedaCoproduct_apply m]
rw [m.fromFreeYoneda_app_apply]
instance : Epi M.fromFreeYonedaCoproduct :=
epi_of_surjective (fun X m ↦ ⟨M.freeYonedaCoproductMk (M.elementsMk X m),
M.fromFreeYonedaCoproduct_app_mk (M.elementsMk X m)⟩)
/-- Given a presheaf of modules `M`, this is a morphism between coproducts
of free presheaves of modules on Yoneda presheaves which gives a presentation
of the module `M`, see `isColimitFreeYonedaCoproductsCokernelCofork`. -/
noncomputable def toFreeYonedaCoproduct :
(kernel M.fromFreeYonedaCoproduct).freeYonedaCoproduct ⟶ M.freeYonedaCoproduct :=
(kernel M.fromFreeYonedaCoproduct).fromFreeYonedaCoproduct ≫ kernel.ι _
@[reassoc (attr := simp)]
lemma toFreeYonedaCoproduct_fromFreeYonedaCoproduct :
M.toFreeYonedaCoproduct ≫ M.fromFreeYonedaCoproduct = 0 := by
simp [toFreeYonedaCoproduct]
/-- (Colimit) cofork which gives a presentation of a presheaf of modules `M` using
coproducts of free presheaves of modules on Yoneda presheaves. -/
noncomputable abbrev freeYonedaCoproductsCokernelCofork :
CokernelCofork M.toFreeYonedaCoproduct :=
CokernelCofork.ofπ _ M.toFreeYonedaCoproduct_fromFreeYonedaCoproduct
/-- If `M` is a presheaf of modules, the cokernel cofork
`M.freeYonedaCoproductsCokernelCofork` is a colimit, which means that
`M` can be expressed as a cokernel of the morphism `M.toFreeYonedaCoproduct`
between coproducts of free presheaves of modules on Yoneda presheaves. -/
noncomputable def isColimitFreeYonedaCoproductsCokernelCofork :
IsColimit M.freeYonedaCoproductsCokernelCofork := by
let S := ShortComplex.mk _ _ M.toFreeYonedaCoproduct_fromFreeYonedaCoproduct
let T := ShortComplex.mk _ _ (kernel.condition M.fromFreeYonedaCoproduct)
let φ : S ⟶ T :=
{ τ₁ := fromFreeYonedaCoproduct _
τ₂ := 𝟙 _
τ₃ := 𝟙 _ }
exact ((ShortComplex.exact_iff_of_epi_of_isIso_of_mono φ).2
(T.exact_of_f_is_kernel (kernelIsKernel _))).gIsCokernel
end
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/Sheafification.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.Abelian
import Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafify
import Mathlib.Algebra.Category.ModuleCat.Presheaf.Limits
import Mathlib.Algebra.Category.ModuleCat.Sheaf.Limits
import Mathlib.CategoryTheory.Sites.LocallyBijective
import Mathlib.CategoryTheory.Sites.Sheafification
import Mathlib.CategoryTheory.Functor.ReflectsIso.Balanced
/-!
# The sheafification functor for presheaves of modules
In this file, we construct a functor
`PresheafOfModules.sheafification α : PresheafOfModules R₀ ⥤ SheafOfModules R`
for a locally bijective morphism `α : R₀ ⟶ R.val` where `R₀` is a presheaf of rings
and `R` a sheaf of rings.
In particular, if `α` is the identity of `R.val`, we obtain the
sheafification functor `PresheafOfModules R.val ⥤ SheafOfModules R`.
-/
universe v v' u u'
open CategoryTheory Category Limits
variable {C : Type u'} [Category.{v'} C] {J : GrothendieckTopology C}
{R₀ : Cᵒᵖ ⥤ RingCat.{u}} {R : Sheaf J RingCat.{u}} (α : R₀ ⟶ R.val)
[Presheaf.IsLocallyInjective J α] [Presheaf.IsLocallySurjective J α]
[J.WEqualsLocallyBijective AddCommGrpCat.{v}]
namespace PresheafOfModules
section
variable [HasWeakSheafify J AddCommGrpCat.{v}]
/-- Given a locally bijective morphism `α : R₀ ⟶ R.val` where `R₀` is a presheaf of rings
and `R` a sheaf of rings (i.e. `R` identifies to the sheafification of `R₀`), this is
the associated sheaf of modules functor `PresheafOfModules.{v} R₀ ⥤ SheafOfModules.{v} R`. -/
@[simps! -isSimp map]
noncomputable def sheafification : PresheafOfModules.{v} R₀ ⥤ SheafOfModules.{v} R where
obj M₀ := sheafify α (CategoryTheory.toSheafify J M₀.presheaf)
map f := sheafifyMap _ _ _ f
((toPresheaf R₀ ⋙ presheafToSheaf J AddCommGrpCat).map f)
(by apply toSheafify_naturality)
map_id M₀ := by
ext1
apply (toPresheaf _).map_injective
simp
rfl
map_comp _ _ := by
ext1
apply (toPresheaf _).map_injective
simp
rfl
/-- The sheafification of presheaves of modules commutes with the functor which
forgets the module structures. -/
noncomputable def sheafificationCompToSheaf :
sheafification.{v} α ⋙ SheafOfModules.toSheaf _ ≅
toPresheaf _ ⋙ presheafToSheaf J AddCommGrpCat :=
Iso.refl _
/-- The sheafification of presheaves of modules commutes with the functor which
forgets the module structures. -/
noncomputable def sheafificationCompForgetCompToPresheaf :
sheafification.{v} α ⋙ SheafOfModules.forget _ ⋙ toPresheaf _ ≅
toPresheaf _ ⋙ presheafToSheaf J AddCommGrpCat ⋙ sheafToPresheaf J AddCommGrpCat :=
Iso.refl _
/-- The bijection between types of morphisms which is part of the adjunction
`sheafificationAdjunction`. -/
noncomputable def sheafificationHomEquiv
{P : PresheafOfModules.{v} R₀} {F : SheafOfModules.{v} R} :
((sheafification α).obj P ⟶ F) ≃
(P ⟶ (restrictScalars α).obj ((SheafOfModules.forget _).obj F)) := by
apply sheafifyHomEquiv
lemma toPresheaf_map_sheafificationHomEquiv_def
{P : PresheafOfModules.{v} R₀} {F : SheafOfModules.{v} R}
(f : (sheafification α).obj P ⟶ F) :
(toPresheaf R₀).map (sheafificationHomEquiv α f) =
CategoryTheory.toSheafify J P.presheaf ≫ (toPresheaf R.val).map f.val := rfl
lemma toPresheaf_map_sheafificationHomEquiv
{P : PresheafOfModules.{v} R₀} {F : SheafOfModules.{v} R}
(f : (sheafification α).obj P ⟶ F) :
(toPresheaf R₀).map (sheafificationHomEquiv α f) =
(sheafificationAdjunction J AddCommGrpCat).homEquiv P.presheaf
((SheafOfModules.toSheaf _).obj F) ((SheafOfModules.toSheaf _).map f) := by
rw [toPresheaf_map_sheafificationHomEquiv_def, Adjunction.homEquiv_unit]
dsimp
lemma toSheaf_map_sheafificationHomEquiv_symm
{P : PresheafOfModules.{v} R₀} {F : SheafOfModules.{v} R}
(g : P ⟶ (restrictScalars α).obj ((SheafOfModules.forget _).obj F)) :
(SheafOfModules.toSheaf _).map ((sheafificationHomEquiv α).symm g) =
(((sheafificationAdjunction J AddCommGrpCat).homEquiv
P.presheaf ((SheafOfModules.toSheaf R).obj F)).symm ((toPresheaf R₀).map g)) := by
obtain ⟨f, rfl⟩ := (sheafificationHomEquiv α).surjective g
apply ((sheafificationAdjunction J AddCommGrpCat).homEquiv _ _).injective
rw [Equiv.apply_symm_apply, Adjunction.homEquiv_unit, Equiv.symm_apply_apply]
rfl
/-- Given a locally bijective morphism `α : R₀ ⟶ R.val` where `R₀` is a presheaf of rings
and `R` a sheaf of rings, this is the adjunction
`sheafification.{v} α ⊣ SheafOfModules.forget R ⋙ restrictScalars α`. -/
noncomputable def sheafificationAdjunction :
sheafification.{v} α ⊣ SheafOfModules.forget R ⋙ restrictScalars α :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun _ _ ↦ sheafificationHomEquiv α
homEquiv_naturality_left_symm := fun {P₀ Q₀ N} f g ↦ by
apply (SheafOfModules.toSheaf _).map_injective
rw [Functor.map_comp]
erw [toSheaf_map_sheafificationHomEquiv_symm,
toSheaf_map_sheafificationHomEquiv_symm α g]
rw [Functor.map_comp]
apply (CategoryTheory.sheafificationAdjunction J
AddCommGrpCat.{v}).homEquiv_naturality_left_symm
homEquiv_naturality_right := fun {P₀ M N} f g ↦ by
apply (toPresheaf _).map_injective
erw [toPresheaf_map_sheafificationHomEquiv] }
lemma sheafificationAdjunction_homEquiv_apply {P : PresheafOfModules.{v} R₀}
{F : SheafOfModules.{v} R} (f : (sheafification α).obj P ⟶ F) :
(sheafificationAdjunction α).homEquiv P F f = sheafificationHomEquiv α f := rfl
@[simp]
lemma toPresheaf_map_sheafificationAdjunction_unit_app (M₀ : PresheafOfModules.{v} R₀) :
(toPresheaf _).map ((sheafificationAdjunction α).unit.app M₀) =
CategoryTheory.toSheafify J M₀.presheaf := rfl
instance : (sheafification.{v} α).IsLeftAdjoint :=
(sheafificationAdjunction α).isLeftAdjoint
end
section
variable [HasSheafify J AddCommGrpCat.{v}]
noncomputable instance :
PreservesFiniteLimits (sheafification.{v} α ⋙ SheafOfModules.toSheaf.{v} R) :=
comp_preservesFiniteLimits (toPresheaf.{v} R₀) (presheafToSheaf J AddCommGrpCat)
instance : (SheafOfModules.toSheaf.{v} R ⋙ sheafToPresheaf _ _).ReflectsIsomorphisms :=
inferInstanceAs (SheafOfModules.forget.{v} R ⋙ toPresheaf _).ReflectsIsomorphisms
instance : (SheafOfModules.toSheaf.{v} R).ReflectsIsomorphisms :=
reflectsIsomorphisms_of_comp (SheafOfModules.toSheaf.{v} R) (sheafToPresheaf J _)
noncomputable instance : ReflectsFiniteLimits (SheafOfModules.toSheaf.{v} R) where
reflects _ _ _ := inferInstance
noncomputable instance : PreservesFiniteLimits (sheafification.{v} α) :=
preservesFiniteLimits_of_reflects_of_preserves
(sheafification.{v} α) (SheafOfModules.toSheaf.{v} R)
end
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/Pullback.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.Generator
import Mathlib.Algebra.Category.ModuleCat.Presheaf.Pushforward
import Mathlib.CategoryTheory.Adjunction.PartialAdjoint
import Mathlib.CategoryTheory.Adjunction.CompositionIso
/-!
# Pullback of presheaves of modules
Let `F : C ⥤ D` be a functor, `R : Dᵒᵖ ⥤ RingCat` and `S : Cᵒᵖ ⥤ RingCat` be presheaves
of rings, and `φ : S ⟶ F.op ⋙ R` be a morphism of presheaves of rings,
we introduce the pullback functor `pullback : PresheafOfModules S ⥤ PresheafOfModules R`
as the left adjoint of `pushforward : PresheafOfModules R ⥤ PresheafOfModules S`.
The existence of this left adjoint functor is obtained under suitable universe assumptions.
From the compatibility of `pushforward` with respect to composition, we deduce
similar pseudofunctor-like properties of the `pullback` functors.
-/
universe v v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ u
open CategoryTheory Limits Opposite Functor
namespace PresheafOfModules
section
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
{F : C ⥤ D} {R : Dᵒᵖ ⥤ RingCat.{u}} {S : Cᵒᵖ ⥤ RingCat.{u}} (φ : S ⟶ F.op ⋙ R)
[(pushforward.{v} φ).IsRightAdjoint]
/-- The pullback functor `PresheafOfModules S ⥤ PresheafOfModules R` induced by
a morphism of presheaves of rings `S ⟶ F.op ⋙ R`, defined as the left adjoint
functor to the pushforward, when it exists. -/
noncomputable def pullback : PresheafOfModules.{v} S ⥤ PresheafOfModules.{v} R :=
(pushforward.{v} φ).leftAdjoint
/-- Given a morphism of presheaves of rings `S ⟶ F.op ⋙ R`, this is the adjunction
between associated pullback and pushforward functors on the categories
of presheaves of modules. -/
noncomputable def pullbackPushforwardAdjunction : pullback.{v} φ ⊣ pushforward.{v} φ :=
Adjunction.ofIsRightAdjoint (pushforward φ)
/-- Given a morphism of presheaves of rings `φ : S ⟶ F.op ⋙ R`, this is the property
that the (partial) left adjoint functor of `pushforward φ` is defined
on a certain object `M : PresheafOfModules S`. -/
abbrev pullbackObjIsDefined : ObjectProperty (PresheafOfModules.{v} S) :=
(pushforward φ).leftAdjointObjIsDefined
end
section
variable {C D : Type u} [SmallCategory C] [SmallCategory D]
{F : C ⥤ D} {R : Dᵒᵖ ⥤ RingCat.{u}} {S : Cᵒᵖ ⥤ RingCat.{u}} (φ : S ⟶ F.op ⋙ R)
/-- Given a morphism of presheaves of rings `φ : S ⟶ F.op ⋙ R`, where `F : C ⥤ D`,
`S : Cᵒᵖ ⥤ RingCat`, `R : Dᵒᵖ ⥤ RingCat` and `X : C`, the (partial) left adjoint
functor of `pushforward φ` is defined on the object `(free S).obj (yoneda.obj X)`:
this object shall be mapped to `(free R).obj (yoneda.obj (F.obj X))`. -/
noncomputable def pushforwardCompCoyonedaFreeYonedaCorepresentableBy (X : C) :
(pushforward φ ⋙ coyoneda.obj (op ((free S).obj (yoneda.obj X)))).CorepresentableBy
((free R).obj (yoneda.obj (F.obj X))) where
homEquiv {M} := (freeYonedaEquiv).trans
(freeYonedaEquiv (M := (pushforward φ).obj M)).symm
homEquiv_comp {M N} g f := freeYonedaEquiv.injective (by
dsimp
erw [Equiv.apply_symm_apply, freeYonedaEquiv_comp]
conv_rhs => erw [freeYonedaEquiv_comp]
erw [Equiv.apply_symm_apply]
rfl)
lemma pullbackObjIsDefined_free_yoneda (X : C) :
pullbackObjIsDefined φ ((free S).obj (yoneda.obj X)) :=
(pushforwardCompCoyonedaFreeYonedaCorepresentableBy φ X).isCorepresentable
lemma pullbackObjIsDefined_eq_top :
pullbackObjIsDefined.{u} φ = ⊤ := by
ext M
simp only [Pi.top_apply, Prop.top_eq_true, iff_true]
apply leftAdjointObjIsDefined_of_isColimit
M.isColimitFreeYonedaCoproductsCokernelCofork
rintro (_ | _)
all_goals
apply leftAdjointObjIsDefined_colimit _
(fun _ ↦ pullbackObjIsDefined_free_yoneda _ _)
instance : (pushforward.{u} φ).IsRightAdjoint :=
isRightAdjoint_of_leftAdjointObjIsDefined_eq_top
(pullbackObjIsDefined_eq_top φ)
end
section
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
{E : Type u₃} [Category.{v₃} E] {E' : Type u₄} [Category.{v₄} E']
variable {F : C ⥤ D} {R : Dᵒᵖ ⥤ RingCat.{u}} {S : Cᵒᵖ ⥤ RingCat.{u}} (φ : S ⟶ F.op ⋙ R)
{G : D ⥤ E} {T : Eᵒᵖ ⥤ RingCat.{u}} (ψ : R ⟶ G.op ⋙ T)
instance : (pushforward.{v} (F := 𝟭 C) (𝟙 S)).IsRightAdjoint :=
isRightAdjoint_of_iso (pushforwardId.{v} S).symm
variable (S) in
/-- The pullback by the identity morphism identifies to the identity functor of the
category of presheaves of modules. -/
noncomputable def pullbackId : pullback.{v} (F := 𝟭 C) (𝟙 S) ≅ 𝟭 _ :=
((pullbackPushforwardAdjunction.{v} (F := 𝟭 C) (𝟙 S))).leftAdjointIdIso (pushforwardId S)
variable [(pushforward.{v} φ).IsRightAdjoint]
section
variable [(pushforward.{v} ψ).IsRightAdjoint]
instance : (pushforward.{v} (F := F ⋙ G) (φ ≫ whiskerLeft F.op ψ)).IsRightAdjoint :=
isRightAdjoint_of_iso (pushforwardComp.{v} φ ψ)
/-- The composition of two pullback functors on presheaves of modules identifies
to the pullback for the composition. -/
noncomputable def pullbackComp :
pullback.{v} φ ⋙ pullback.{v} ψ ≅
pullback.{v} (F := F ⋙ G) (φ ≫ whiskerLeft F.op ψ) :=
Adjunction.leftAdjointCompIso
(pullbackPushforwardAdjunction.{v} φ) (pullbackPushforwardAdjunction.{v} ψ)
(pullbackPushforwardAdjunction.{v} (F := F ⋙ G) (φ ≫ whiskerLeft F.op ψ))
(pushforwardComp φ ψ)
variable {T' : E'ᵒᵖ ⥤ RingCat.{u}} {G' : E ⥤ E'} (ψ' : T ⟶ G'.op ⋙ T')
[(pushforward.{v} ψ').IsRightAdjoint]
lemma pullback_assoc :
isoWhiskerLeft _ (pullbackComp.{v} ψ ψ') ≪≫
pullbackComp.{v} (G := G ⋙ G') φ (ψ ≫ whiskerLeft G.op ψ') =
(associator _ _ _).symm ≪≫ isoWhiskerRight (pullbackComp.{v} φ ψ) _ ≪≫
pullbackComp.{v} (F := F ⋙ G) (φ ≫ whiskerLeft F.op ψ) ψ' :=
Adjunction.leftAdjointCompIso_assoc _ _ _ _ _ _ _ _ _ _ (pushforward_assoc φ ψ ψ')
end
lemma pullback_id_comp :
pullbackComp.{v} (F := 𝟭 C) (𝟙 S) φ =
isoWhiskerRight (pullbackId S) (pullback φ) ≪≫ Functor.leftUnitor _ :=
Adjunction.leftAdjointCompIso_id_comp _ _ _ _ (pushforward_comp_id φ)
lemma pullback_comp_id :
pullbackComp.{v} (G := 𝟭 _) φ (𝟙 R) =
isoWhiskerLeft _ (pullbackId R) ≪≫ Functor.rightUnitor _ :=
Adjunction.leftAdjointCompIso_comp_id _ _ _ _ (pushforward_id_comp φ)
end
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/Colimits.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf
import Mathlib.Algebra.Category.ModuleCat.Colimits
/-! # Colimits in categories of presheaves of modules
In this file, it is shown that under suitable assumptions,
colimits exist in the category `PresheafOfModules R`.
-/
universe v v₁ v₂ u₁ u₂ u u'
open CategoryTheory Category Limits
namespace PresheafOfModules
variable {C : Type u₁} [Category.{v₁} C] {R : Cᵒᵖ ⥤ RingCat.{u}}
{J : Type u₂} [Category.{v₂} J]
(F : J ⥤ PresheafOfModules.{v} R)
section Colimits
variable [∀ {X Y : Cᵒᵖ} (f : X ⟶ Y), PreservesColimit (F ⋙ evaluation R Y)
(ModuleCat.restrictScalars (R.map f).hom)]
/-- A cocone in the category `PresheafOfModules R` is colimit if it is so after the application
of the functors `evaluation R X` for all `X`. -/
def evaluationJointlyReflectsColimits (c : Cocone F)
(hc : ∀ (X : Cᵒᵖ), IsColimit ((evaluation R X).mapCocone c)) : IsColimit c where
desc s :=
{ app := fun X => (hc X).desc ((evaluation R X).mapCocone s)
naturality := fun {X Y} f ↦ (hc X).hom_ext (fun j ↦ by
rw [(hc X).fac_assoc ((evaluation R X).mapCocone s) j]
have h₁ := (c.ι.app j).naturality f
have h₂ := (hc Y).fac ((evaluation R Y).mapCocone s)
dsimp at h₁ h₂ ⊢
simp only [← reassoc_of% h₁, ← Functor.map_comp, h₂, Hom.naturality]) }
fac s j := by
ext1 X
exact (hc X).fac ((evaluation R X).mapCocone s) j
uniq s m hm := by
ext1 X
apply (hc X).uniq ((evaluation R X).mapCocone s)
intro j
dsimp
rw [← hm]
rfl
variable [∀ X, HasColimit (F ⋙ evaluation R X)]
instance {X Y : Cᵒᵖ} (f : X ⟶ Y) :
HasColimit (F ⋙ evaluation R Y ⋙ (ModuleCat.restrictScalars (R.map f).hom)) :=
⟨_, isColimitOfPreserves (ModuleCat.restrictScalars (R.map f).hom)
(colimit.isColimit (F ⋙ evaluation R Y))⟩
/-- Given `F : J ⥤ PresheafOfModules.{v} R`, this is the presheaf of modules obtained by
taking a colimit in the category of modules over `R.obj X` for all `X`. -/
@[simps]
noncomputable def colimitPresheafOfModules : PresheafOfModules R where
obj X := colimit (F ⋙ evaluation R X)
map {_ Y} f := colimMap (Functor.whiskerLeft F (restriction R f)) ≫
(preservesColimitIso (ModuleCat.restrictScalars (R.map f).hom) (F ⋙ evaluation R Y)).inv
map_id X := colimit.hom_ext (fun j => by
dsimp
rw [ι_colimMap_assoc, Functor.whiskerLeft_app, restriction_app]
-- Here we should rewrite using `Functor.assoc` but that gives a "motive is type-incorrect"
erw [ι_preservesColimitIso_inv (G := ModuleCat.restrictScalars (R.map (𝟙 X)).hom)]
rw [ModuleCat.restrictScalarsId'App_inv_naturality, map_id]
dsimp)
map_comp {X Y Z} f g := colimit.hom_ext (fun j => by
dsimp
rw [ι_colimMap_assoc, Functor.whiskerLeft_app, restriction_app, assoc, ι_colimMap_assoc]
-- Here we should rewrite using `Functor.assoc` but that gives a "motive is type-incorrect"
erw [ι_preservesColimitIso_inv (G := ModuleCat.restrictScalars (R.map (f ≫ g)).hom),
ι_preservesColimitIso_inv_assoc (G := ModuleCat.restrictScalars (R.map f).hom)]
rw [← Functor.map_comp_assoc, ι_colimMap_assoc]
erw [ι_preservesColimitIso_inv (G := ModuleCat.restrictScalars (R.map g).hom)]
rw [map_comp, ModuleCat.restrictScalarsComp'_inv_app, assoc, assoc,
Functor.whiskerLeft_app, Functor.whiskerLeft_app, restriction_app, restriction_app]
simp only [Functor.map_comp, assoc]
rfl)
/-- The (colimit) cocone for `F : J ⥤ PresheafOfModules.{v} R` that is constructed from
the colimit of `F ⋙ evaluation R X` for all `X`. -/
@[simps]
noncomputable def colimitCocone : Cocone F where
pt := colimitPresheafOfModules F
ι :=
{ app := fun j ↦
{ app := fun X ↦ colimit.ι (F ⋙ evaluation R X) j
naturality := fun {X Y} f ↦ by
dsimp
erw [colimit.ι_desc_assoc, assoc, ← ι_preservesColimitIso_inv]
rfl }
naturality := fun {X Y} f ↦ by
ext1 X
simpa using colimit.w (F ⋙ evaluation R X) f }
/-- The cocone `colimitCocone F` is colimit for any `F : J ⥤ PresheafOfModules.{v} R`. -/
noncomputable def isColimitColimitCocone : IsColimit (colimitCocone F) :=
evaluationJointlyReflectsColimits _ _ (fun _ => colimit.isColimit _)
instance hasColimit : HasColimit F := ⟨_, isColimitColimitCocone F⟩
instance evaluation_preservesColimit (X : Cᵒᵖ) :
PreservesColimit F (evaluation R X) :=
preservesColimit_of_preserves_colimit_cocone (isColimitColimitCocone F) (colimit.isColimit _)
variable [∀ X, PreservesColimit F
(evaluation R X ⋙ forget₂ (ModuleCat (R.obj X)) AddCommGrpCat)]
instance toPresheaf_preservesColimit :
PreservesColimit F (toPresheaf R) :=
preservesColimit_of_preserves_colimit_cocone (isColimitColimitCocone F)
(Limits.evaluationJointlyReflectsColimits _
(fun X => isColimitOfPreserves (evaluation R X ⋙ forget₂ _ AddCommGrpCat)
(isColimitColimitCocone F)))
end Colimits
variable (R J)
section HasColimitsOfShape
variable [HasColimitsOfShape J AddCommGrpCat.{v}]
instance hasColimitsOfShape : HasColimitsOfShape J (PresheafOfModules.{v} R) where
noncomputable instance evaluation_preservesColimitsOfShape (X : Cᵒᵖ) :
PreservesColimitsOfShape J (evaluation R X : PresheafOfModules.{v} R ⥤ _) where
noncomputable instance toPresheaf_preservesColimitsOfShape :
PreservesColimitsOfShape J (toPresheaf.{v} R) where
end HasColimitsOfShape
namespace Finite
instance hasFiniteColimits : HasFiniteColimits (PresheafOfModules.{v} R) :=
⟨fun _ => inferInstance⟩
noncomputable instance evaluation_preservesFiniteColimits (X : Cᵒᵖ) :
PreservesFiniteColimits (evaluation.{v} R X) where
noncomputable instance toPresheaf_preservesFiniteColimits :
PreservesFiniteColimits (toPresheaf R) where
end Finite
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/Limits.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf
import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings
import Mathlib.CategoryTheory.Limits.Preserves.Limits
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic
/-! # Limits in categories of presheaves of modules
In this file, it is shown that under suitable assumptions,
limits exist in the category `PresheafOfModules R`.
-/
universe v v₁ v₂ u₁ u₂ u u'
open CategoryTheory Category Limits
namespace PresheafOfModules
variable {C : Type u₁} [Category.{v₁} C] {R : Cᵒᵖ ⥤ RingCat.{u}}
{J : Type u₂} [Category.{v₂} J]
(F : J ⥤ PresheafOfModules.{v} R)
section Limits
variable [∀ X, Small.{v} ((F ⋙ evaluation R X) ⋙ forget _).sections]
/-- A cone in the category `PresheafOfModules R` is limit if it is so after the application
of the functors `evaluation R X` for all `X`. -/
def evaluationJointlyReflectsLimits (c : Cone F)
(hc : ∀ (X : Cᵒᵖ), IsLimit ((evaluation R X).mapCone c)) : IsLimit c where
lift s :=
{ app := fun X => (hc X).lift ((evaluation R X).mapCone s)
naturality := fun {X Y} f ↦ by
apply (isLimitOfPreserves (ModuleCat.restrictScalars (R.map f).hom) (hc Y)).hom_ext
intro j
have h₁ := (c.π.app j).naturality f
have h₂ := (hc X).fac ((evaluation R X).mapCone s) j
rw [Functor.mapCone_π_app, assoc, assoc, ← Functor.map_comp, IsLimit.fac]
dsimp at h₁ h₂ ⊢
rw [h₁, reassoc_of% h₂, Hom.naturality] }
fac s j := by
ext1 X
exact (hc X).fac ((evaluation R X).mapCone s) j
uniq s m hm := by
ext1 X
apply (hc X).uniq ((evaluation R X).mapCone s)
intro j
dsimp
rw [← hm, comp_app]
instance {X Y : Cᵒᵖ} (f : X ⟶ Y) :
HasLimit (F ⋙ evaluation R Y ⋙ ModuleCat.restrictScalars (R.map f).hom) := by
change HasLimit ((F ⋙ evaluation R Y) ⋙ ModuleCat.restrictScalars (R.map f).hom)
infer_instance
/-- Given `F : J ⥤ PresheafOfModules.{v} R`, this is the presheaf of modules obtained by
taking a limit in the category of modules over `R.obj X` for all `X`. -/
@[simps]
noncomputable def limitPresheafOfModules : PresheafOfModules R where
obj X := limit (F ⋙ evaluation R X)
map {_ Y} f := limMap (Functor.whiskerLeft F (restriction R f)) ≫
(preservesLimitIso (ModuleCat.restrictScalars (R.map f).hom) (F ⋙ evaluation R Y)).inv
map_id X := by
dsimp
rw [← cancel_mono (preservesLimitIso _ _).hom, assoc, Iso.inv_hom_id, comp_id]
apply limit.hom_ext
intro j
dsimp
simp only [limMap_π, Functor.comp_obj, evaluation_obj, Functor.whiskerLeft_app,
restriction_app, assoc]
-- Here we should rewrite using `Functor.assoc` but that gives a "motive is type-incorrect"
erw [preservesLimitIso_hom_π]
rw [← ModuleCat.restrictScalarsId'App_inv_naturality, map_id,
ModuleCat.restrictScalarsId'_inv_app]
dsimp
map_comp {X Y Z} f g := by
dsimp
rw [← cancel_mono (preservesLimitIso _ _).hom, assoc, assoc, assoc, assoc, Iso.inv_hom_id,
comp_id]
apply limit.hom_ext
intro j
simp only [Functor.comp_obj, evaluation_obj, limMap_π, Functor.whiskerLeft_app, restriction_app,
map_comp, ModuleCat.restrictScalarsComp'_inv_app, Functor.map_comp, assoc]
-- Here we should rewrite using `Functor.assoc` but that gives a "motive is type-incorrect"
erw [preservesLimitIso_hom_π]
rw [← ModuleCat.restrictScalarsComp'App_inv_naturality]
dsimp
rw [← Functor.map_comp_assoc, ← Functor.map_comp_assoc, assoc,
preservesLimitIso_inv_π]
-- Here we should rewrite using `Functor.assoc` but that gives a "motive is type-incorrect"
erw [limMap_π]
dsimp
simp only [Functor.map_comp, assoc, preservesLimitIso_inv_π_assoc]
-- Here we should rewrite using `Functor.assoc` but that gives a "motive is type-incorrect"
erw [limMap_π_assoc]
dsimp
/-- The (limit) cone for `F : J ⥤ PresheafOfModules.{v} R` that is constructed from the limit
of `F ⋙ evaluation R X` for all `X`. -/
@[simps]
noncomputable def limitCone : Cone F where
pt := limitPresheafOfModules F
π :=
{ app := fun j ↦
{ app := fun X ↦ limit.π (F ⋙ evaluation R X) j
naturality := fun {X Y} f ↦ by
dsimp
simp only [assoc, preservesLimitIso_inv_π]
apply limMap_π }
naturality := fun {j j'} f ↦ by
ext1 X
simpa using (limit.w (F ⋙ evaluation R X) f).symm }
/-- The cone `limitCone F` is limit for any `F : J ⥤ PresheafOfModules.{v} R`. -/
noncomputable def isLimitLimitCone : IsLimit (limitCone F) :=
evaluationJointlyReflectsLimits _ _ (fun _ => limit.isLimit _)
instance hasLimit : HasLimit F := ⟨_, isLimitLimitCone F⟩
noncomputable instance evaluation_preservesLimit (X : Cᵒᵖ) :
PreservesLimit F (evaluation R X) :=
preservesLimit_of_preserves_limit_cone (isLimitLimitCone F) (limit.isLimit _)
noncomputable instance toPresheaf_preservesLimit :
PreservesLimit F (toPresheaf R) :=
preservesLimit_of_preserves_limit_cone (isLimitLimitCone F)
(Limits.evaluationJointlyReflectsLimits _
(fun X => isLimitOfPreserves (evaluation R X ⋙ forget₂ _ AddCommGrpCat)
(isLimitLimitCone F)))
end Limits
variable (R J)
section Small
variable [Small.{v} J]
instance hasLimitsOfShape : HasLimitsOfShape J (PresheafOfModules.{v} R) where
instance hasLimitsOfSize : HasLimitsOfSize.{v, v} (PresheafOfModules.{v} R) where
noncomputable instance evaluation_preservesLimitsOfShape (X : Cᵒᵖ) :
PreservesLimitsOfShape J (evaluation R X : PresheafOfModules.{v} R ⥤ _) where
noncomputable instance toPresheaf_preservesLimitsOfShape :
PreservesLimitsOfShape J (toPresheaf.{v} R) where
end Small
section Finite
instance hasFiniteLimits : HasFiniteLimits (PresheafOfModules.{v} R) :=
⟨fun _ => inferInstance⟩
noncomputable instance evaluation_preservesFiniteLimits (X : Cᵒᵖ) :
PreservesFiniteLimits (evaluation.{v} R X) where
noncomputable instance toPresheaf_preservesFiniteLimits :
PreservesFiniteLimits (toPresheaf.{v} R) where
end Finite
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/ChangeOfRings.lean | import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings
import Mathlib.Algebra.Category.ModuleCat.Presheaf
/-!
# Change of presheaf of rings
In this file, we define the restriction of scalars functor
`restrictScalars α : PresheafOfModules.{v} R' ⥤ PresheafOfModules.{v} R`
attached to a morphism of presheaves of rings `α : R ⟶ R'`.
-/
universe v v' u u'
open CategoryTheory
namespace PresheafOfModules
variable {C : Type u'} [Category.{v'} C] {R R' : Cᵒᵖ ⥤ RingCat.{u}}
/-- The restriction of scalars of presheaves of modules, on objects. -/
@[simps]
noncomputable def restrictScalarsObj (M' : PresheafOfModules.{v} R') (α : R ⟶ R') :
PresheafOfModules R where
obj := fun X ↦ (ModuleCat.restrictScalars (α.app X).hom).obj (M'.obj X)
-- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(X := ...)` and `(Y := ...)`.
-- This suggests `restrictScalars` needs to be redesigned.
map := fun {X Y} f ↦ ModuleCat.ofHom
(X := (ModuleCat.restrictScalars (α.app X).hom).obj (M'.obj X))
(Y := (ModuleCat.restrictScalars (R.map f).hom).obj
((ModuleCat.restrictScalars (α.app Y).hom).obj (M'.obj Y)))
{ toFun := M'.map f
map_add' := map_add _
map_smul' := fun r x ↦ (M'.map_smul f (α.app _ r) x).trans (by
have eq := RingHom.congr_fun (congrArg RingCat.Hom.hom <| α.naturality f) r
dsimp at eq
rw [← eq]
rfl ) }
/-- The restriction of scalars functor `PresheafOfModules R' ⥤ PresheafOfModules R`
induced by a morphism of presheaves of rings `R ⟶ R'`. -/
@[simps]
noncomputable def restrictScalars (α : R ⟶ R') :
PresheafOfModules.{v} R' ⥤ PresheafOfModules.{v} R where
obj M' := M'.restrictScalarsObj α
map φ' :=
{ app := fun X ↦ (ModuleCat.restrictScalars (α.app X).hom).map (Hom.app φ' X)
naturality := fun {X Y} f ↦ by
ext x
exact naturality_apply φ' f x }
instance (α : R ⟶ R') : (restrictScalars.{v} α).Additive where
instance : (restrictScalars (𝟙 R)).Full := inferInstanceAs (𝟭 _).Full
instance (α : R ⟶ R') : (restrictScalars α).Faithful where
map_injective h := (toPresheaf R').map_injective ((toPresheaf R).congr_map h)
/-- The isomorphism `restrictScalars α ⋙ toPresheaf R ≅ toPresheaf R'` for any
morphism of presheaves of rings `α : R ⟶ R'`. -/
noncomputable def restrictScalarsCompToPresheaf (α : R ⟶ R') :
restrictScalars.{v} α ⋙ toPresheaf R ≅ toPresheaf R' := Iso.refl _
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Presheaf/Free.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf
import Mathlib.Algebra.Category.ModuleCat.Adjunctions
/-!
# The free presheaf of modules on a presheaf of sets
In this file, given a presheaf of rings `R` on a category `C`,
we construct the functor
`PresheafOfModules.free : (Cᵒᵖ ⥤ Type u) ⥤ PresheafOfModules.{u} R`
which sends a presheaf of types to the corresponding presheaf of free modules.
`PresheafOfModules.freeAdjunction` shows that this functor is the left
adjoint to the forget functor.
## Notes
This contribution was created as part of the AIM workshop
"Formalizing algebraic geometry" in June 2024.
-/
universe u v₁ u₁
open CategoryTheory
namespace PresheafOfModules
variable {C : Type u₁} [Category.{v₁} C] (R : Cᵒᵖ ⥤ RingCat.{u})
variable {R} in
/-- Given a presheaf of types `F : Cᵒᵖ ⥤ Type u`, this is the presheaf
of modules over `R` which sends `X : Cᵒᵖ` to the free `R.obj X`-module on `F.obj X`. -/
@[simps]
noncomputable def freeObj (F : Cᵒᵖ ⥤ Type u) : PresheafOfModules.{u} R where
obj X := (ModuleCat.free (R.obj X)).obj (F.obj X)
map {X Y} f := ModuleCat.freeDesc (fun x ↦ ModuleCat.freeMk (F.map f x))
map_id := by aesop
/-- The free presheaf of modules functor `(Cᵒᵖ ⥤ Type u) ⥤ PresheafOfModules.{u} R`. -/
@[simps]
noncomputable def free : (Cᵒᵖ ⥤ Type u) ⥤ PresheafOfModules.{u} R where
obj := freeObj
map {F G} φ :=
{ app := fun X ↦ (ModuleCat.free (R.obj X)).map (φ.app X)
naturality := fun {X Y} f ↦ by
dsimp
ext x
simp [FunctorToTypes.naturality] }
section
variable {R}
variable {F : Cᵒᵖ ⥤ Type u} {G : PresheafOfModules.{u} R}
attribute [local instance] Types.instFunLike Types.instConcreteCategory in
/-- The morphism of presheaves of modules `freeObj F ⟶ G` corresponding to
a morphism `F ⟶ G.presheaf ⋙ forget _` of presheaves of types. -/
@[simps]
noncomputable def freeObjDesc (φ : F ⟶ G.presheaf ⋙ forget _) : freeObj F ⟶ G where
app X := ModuleCat.freeDesc (φ.app X)
naturality {X Y} f := by
dsimp
ext x
simpa using NatTrans.naturality_apply φ f x
variable (F R) in
/-- The unit of `PresheafOfModules.freeAdjunction`. -/
@[simps]
noncomputable def freeAdjunctionUnit : F ⟶ (freeObj (R := R) F).presheaf ⋙ forget _ where
app X x := ModuleCat.freeMk x
naturality X Y f := by ext; simp [presheaf]
/-- The bijection `(freeObj F ⟶ G) ≃ (F ⟶ G.presheaf ⋙ forget _)` when
`F` is a presheaf of types and `G` a presheaf of modules. -/
noncomputable def freeHomEquiv : (freeObj F ⟶ G) ≃ (F ⟶ G.presheaf ⋙ forget _) where
toFun ψ := freeAdjunctionUnit R F ≫ Functor.whiskerRight ((toPresheaf _).map ψ) _
invFun φ := freeObjDesc φ
left_inv ψ := by ext1 X; dsimp; ext x; simp [toPresheaf]
right_inv φ := by ext; simp [toPresheaf]
lemma free_hom_ext {ψ ψ' : freeObj F ⟶ G}
(h : freeAdjunctionUnit R F ≫ Functor.whiskerRight ((toPresheaf _).map ψ) _ =
freeAdjunctionUnit R F ≫ Functor.whiskerRight ((toPresheaf _).map ψ') _) : ψ = ψ' :=
freeHomEquiv.injective h
variable (R) in
/-- The free presheaf of modules functor is left adjoint to the forget functor
`PresheafOfModules.{u} R ⥤ Cᵒᵖ ⥤ Type u`. -/
noncomputable def freeAdjunction :
free.{u} R ⊣ (toPresheaf R ⋙ (Functor.whiskeringRight _ _ _).obj (forget Ab)) :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun _ _ ↦ freeHomEquiv
homEquiv_naturality_left_symm := fun {F₁ F₂ G} f g ↦
free_hom_ext (by ext; simp [freeHomEquiv, toPresheaf])
homEquiv_naturality_right := fun {F G₁ G₂} f g ↦ rfl }
variable (F G) in
@[simp]
lemma freeAdjunction_homEquiv : (freeAdjunction R).homEquiv F G = freeHomEquiv := by
simp [freeAdjunction, Adjunction.mkOfHomEquiv_homEquiv]
variable (R F) in
@[simp]
lemma freeAdjunction_unit_app :
(freeAdjunction R).unit.app F = freeAdjunctionUnit R F := rfl
end
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Monoidal/Basic.lean | import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.LinearAlgebra.TensorProduct.Associator
import Mathlib.CategoryTheory.Monoidal.Linear
import Mathlib.CategoryTheory.Monoidal.Transport
/-!
# The monoidal category structure on R-modules
Mostly this uses existing machinery in `LinearAlgebra.TensorProduct`.
We just need to provide a few small missing pieces to build the
`MonoidalCategory` instance.
The `SymmetricCategory` instance is in `Algebra.Category.ModuleCat.Monoidal.Symmetric`
to reduce imports.
Note the universe level of the modules must be at least the universe level of the ring,
so that we have a monoidal unit.
For now, we simplify by insisting both universe levels are the same.
We construct the monoidal closed structure on `ModuleCat R` in
`Algebra.Category.ModuleCat.Monoidal.Closed`.
If you're happy using the bundled `ModuleCat R`, it may be possible to mostly
use this as an interface and not need to interact much with the implementation details.
-/
universe v w x u
open CategoryTheory
namespace SemimoduleCat
variable {R : Type u} [CommSemiring R]
namespace MonoidalCategory
-- The definitions inside this namespace are essentially private.
-- After we build the `MonoidalCategory (Module R)` instance,
-- you should use that API.
open TensorProduct
attribute [local ext] TensorProduct.ext
/-- (implementation) tensor product of R-modules -/
def tensorObj (M N : SemimoduleCat R) : SemimoduleCat R :=
SemimoduleCat.of R (M ⊗[R] N)
/-- (implementation) tensor product of morphisms R-modules -/
def tensorHom {M N M' N' : SemimoduleCat R} (f : M ⟶ N) (g : M' ⟶ N') :
tensorObj M M' ⟶ tensorObj N N' :=
ofHom <| TensorProduct.map f.hom g.hom
/-- (implementation) left whiskering for R-modules -/
def whiskerLeft (M : SemimoduleCat R) {N₁ N₂ : SemimoduleCat R} (f : N₁ ⟶ N₂) :
tensorObj M N₁ ⟶ tensorObj M N₂ :=
ofHom <| f.hom.lTensor M
/-- (implementation) right whiskering for R-modules -/
def whiskerRight {M₁ M₂ : SemimoduleCat R} (f : M₁ ⟶ M₂) (N : SemimoduleCat R) :
tensorObj M₁ N ⟶ tensorObj M₂ N :=
ofHom <| f.hom.rTensor N
theorem id_tensorHom_id (M N : SemimoduleCat R) :
tensorHom (𝟙 M) (𝟙 N) = 𝟙 (SemimoduleCat.of R (M ⊗ N)) := by
ext : 1
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): even with high priority `ext` fails to find this.
apply TensorProduct.ext
rfl
@[deprecated (since := "2025-07-14")] alias tensor_id := id_tensorHom_id
theorem tensorHom_comp_tensorHom {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : SemimoduleCat R} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂)
(g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂) :
tensorHom f₁ f₂ ≫ tensorHom g₁ g₂ = tensorHom (f₁ ≫ g₁) (f₂ ≫ g₂) := by
ext : 1
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): even with high priority `ext` fails to find this.
apply TensorProduct.ext
rfl
/-- (implementation) the associator for R-modules -/
def associator (M : SemimoduleCat.{v} R) (N : SemimoduleCat.{w} R) (K : SemimoduleCat.{x} R) :
tensorObj (tensorObj M N) K ≅ tensorObj M (tensorObj N K) :=
(TensorProduct.assoc R M N K).toModuleIsoₛ
/-- (implementation) the left unitor for R-modules -/
def leftUnitor (M : SemimoduleCat.{u} R) : SemimoduleCat.of R (R ⊗[R] M) ≅ M :=
(TensorProduct.lid R M).toModuleIsoₛ
/-- (implementation) the right unitor for R-modules -/
def rightUnitor (M : SemimoduleCat.{u} R) : SemimoduleCat.of R (M ⊗[R] R) ≅ M :=
(TensorProduct.rid R M).toModuleIsoₛ
@[simps -isSimp]
instance instMonoidalCategoryStruct : MonoidalCategoryStruct (SemimoduleCat.{u} R) where
tensorObj := tensorObj
whiskerLeft := whiskerLeft
whiskerRight := whiskerRight
tensorHom := tensorHom
tensorUnit := SemimoduleCat.of R R
associator := associator
leftUnitor := leftUnitor
rightUnitor := rightUnitor
theorem associator_naturality {X₁ X₂ X₃ Y₁ Y₂ Y₃ : SemimoduleCat R} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂)
(f₃ : X₃ ⟶ Y₃) :
tensorHom (tensorHom f₁ f₂) f₃ ≫ (associator Y₁ Y₂ Y₃).hom =
(associator X₁ X₂ X₃).hom ≫ tensorHom f₁ (tensorHom f₂ f₃) := by
ext : 1
apply TensorProduct.ext_threefold
intro x y z
rfl
theorem pentagon (W X Y Z : SemimoduleCat R) :
whiskerRight (associator W X Y).hom Z ≫
(associator W (tensorObj X Y) Z).hom ≫ whiskerLeft W (associator X Y Z).hom =
(associator (tensorObj W X) Y Z).hom ≫ (associator W X (tensorObj Y Z)).hom := by
ext : 1
apply TensorProduct.ext_fourfold
intro w x y z
rfl
theorem leftUnitor_naturality {M N : SemimoduleCat R} (f : M ⟶ N) :
tensorHom (𝟙 (SemimoduleCat.of R R)) f ≫ (leftUnitor N).hom = (leftUnitor M).hom ≫ f := by
ext : 1
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): broken ext
apply TensorProduct.ext
ext x
dsimp
erw [TensorProduct.lid_tmul, TensorProduct.lid_tmul]
rw [LinearMap.map_smul]
rfl
theorem rightUnitor_naturality {M N : SemimoduleCat R} (f : M ⟶ N) :
tensorHom f (𝟙 (SemimoduleCat.of R R)) ≫ (rightUnitor N).hom = (rightUnitor M).hom ≫ f := by
ext : 1
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): broken ext
apply TensorProduct.ext
ext x
dsimp
erw [TensorProduct.rid_tmul, TensorProduct.rid_tmul]
rw [LinearMap.map_smul]
rfl
theorem triangle (M N : SemimoduleCat.{u} R) :
(associator M (SemimoduleCat.of R R) N).hom ≫ tensorHom (𝟙 M) (leftUnitor N).hom =
tensorHom (rightUnitor M).hom (𝟙 N) := by
ext : 1
apply TensorProduct.ext_threefold
intro x y
exact TensorProduct.tmul_smul _ _
end MonoidalCategory
open MonoidalCategory
instance monoidalCategory : MonoidalCategory (SemimoduleCat.{u} R) := MonoidalCategory.ofTensorHom
(id_tensorHom_id := fun M N ↦ id_tensorHom_id M N)
(tensorHom_comp_tensorHom := fun f g h ↦ MonoidalCategory.tensorHom_comp_tensorHom f g h)
(associator_naturality := fun f g h ↦ MonoidalCategory.associator_naturality f g h)
(leftUnitor_naturality := fun f ↦ MonoidalCategory.leftUnitor_naturality f)
(rightUnitor_naturality := fun f ↦ rightUnitor_naturality f)
(pentagon := fun M N K L ↦ pentagon M N K L)
(triangle := fun M N ↦ triangle M N)
/-- Remind ourselves that the monoidal unit, being just `R`, is still a commutative semiring. -/
instance : CommSemiring ((𝟙_ (SemimoduleCat.{u} R) : SemimoduleCat.{u} R) : Type u) :=
inferInstanceAs <| CommSemiring R
theorem hom_tensorHom {K L M N : SemimoduleCat.{u} R} (f : K ⟶ L) (g : M ⟶ N) :
(f ⊗ₘ g).hom = TensorProduct.map f.hom g.hom :=
rfl
theorem hom_whiskerLeft (L : SemimoduleCat.{u} R) {M N : SemimoduleCat.{u} R} (f : M ⟶ N) :
(L ◁ f).hom = f.hom.lTensor L :=
rfl
theorem hom_whiskerRight {L M : SemimoduleCat.{u} R} (f : L ⟶ M) (N : SemimoduleCat.{u} R) :
(f ▷ N).hom = f.hom.rTensor N :=
rfl
theorem hom_hom_leftUnitor {M : SemimoduleCat.{u} R} :
(λ_ M).hom.hom = (TensorProduct.lid _ _).toLinearMap :=
rfl
theorem hom_inv_leftUnitor {M : SemimoduleCat.{u} R} :
(λ_ M).inv.hom = (TensorProduct.lid _ _).symm.toLinearMap :=
rfl
theorem hom_hom_rightUnitor {M : SemimoduleCat.{u} R} :
(ρ_ M).hom.hom = (TensorProduct.rid _ _).toLinearMap :=
rfl
theorem hom_inv_rightUnitor {M : SemimoduleCat.{u} R} :
(ρ_ M).inv.hom = (TensorProduct.rid _ _).symm.toLinearMap :=
rfl
theorem hom_hom_associator {M N K : SemimoduleCat.{u} R} :
(α_ M N K).hom.hom = (TensorProduct.assoc _ _ _ _).toLinearMap :=
rfl
theorem hom_inv_associator {M N K : SemimoduleCat.{u} R} :
(α_ M N K).inv.hom = (TensorProduct.assoc _ _ _ _).symm.toLinearMap :=
rfl
namespace MonoidalCategory
@[simp]
theorem tensorHom_tmul {K L M N : SemimoduleCat.{u} R} (f : K ⟶ L) (g : M ⟶ N) (k : K) (m : M) :
(f ⊗ₘ g) (k ⊗ₜ m) = f k ⊗ₜ g m :=
rfl
@[simp]
theorem whiskerLeft_apply (L : SemimoduleCat.{u} R) {M N : SemimoduleCat.{u} R} (f : M ⟶ N)
(l : L) (m : M) :
(L ◁ f) (l ⊗ₜ m) = l ⊗ₜ f m :=
rfl
@[simp]
theorem whiskerRight_apply {L M : SemimoduleCat.{u} R} (f : L ⟶ M) (N : SemimoduleCat.{u} R)
(l : L) (n : N) :
(f ▷ N) (l ⊗ₜ n) = f l ⊗ₜ n :=
rfl
@[simp]
theorem leftUnitor_hom_apply {M : SemimoduleCat.{u} R} (r : R) (m : M) :
((λ_ M).hom : 𝟙_ (SemimoduleCat R) ⊗ M ⟶ M) (r ⊗ₜ[R] m) = r • m :=
TensorProduct.lid_tmul m r
@[simp]
theorem leftUnitor_inv_apply {M : SemimoduleCat.{u} R} (m : M) :
((λ_ M).inv : M ⟶ 𝟙_ (SemimoduleCat.{u} R) ⊗ M) m = 1 ⊗ₜ[R] m :=
TensorProduct.lid_symm_apply m
@[simp]
theorem rightUnitor_hom_apply {M : SemimoduleCat.{u} R} (m : M) (r : R) :
((ρ_ M).hom : M ⊗ 𝟙_ (SemimoduleCat R) ⟶ M) (m ⊗ₜ r) = r • m :=
TensorProduct.rid_tmul m r
@[simp]
theorem rightUnitor_inv_apply {M : SemimoduleCat.{u} R} (m : M) :
((ρ_ M).inv : M ⟶ M ⊗ 𝟙_ (SemimoduleCat.{u} R)) m = m ⊗ₜ[R] 1 :=
TensorProduct.rid_symm_apply m
@[simp]
theorem associator_hom_apply {M N K : SemimoduleCat.{u} R} (m : M) (n : N) (k : K) :
((α_ M N K).hom : (M ⊗ N) ⊗ K ⟶ M ⊗ N ⊗ K) (m ⊗ₜ n ⊗ₜ k) = m ⊗ₜ (n ⊗ₜ k) :=
rfl
@[simp]
theorem associator_inv_apply {M N K : SemimoduleCat.{u} R} (m : M) (n : N) (k : K) :
((α_ M N K).inv : M ⊗ N ⊗ K ⟶ (M ⊗ N) ⊗ K) (m ⊗ₜ (n ⊗ₜ k)) = m ⊗ₜ n ⊗ₜ k :=
rfl
variable {M₁ M₂ M₃ M₄ : SemimoduleCat.{u} R}
section
variable (f : M₁ → M₂ → M₃) (h₁ : ∀ m₁ m₂ n, f (m₁ + m₂) n = f m₁ n + f m₂ n)
(h₂ : ∀ (a : R) m n, f (a • m) n = a • f m n)
(h₃ : ∀ m n₁ n₂, f m (n₁ + n₂) = f m n₁ + f m n₂)
(h₄ : ∀ (a : R) m n, f m (a • n) = a • f m n)
/-- Construct for morphisms from the tensor product of two objects in `SemimoduleCat`. -/
def tensorLift : M₁ ⊗ M₂ ⟶ M₃ :=
ofHom <| TensorProduct.lift (LinearMap.mk₂ R f h₁ h₂ h₃ h₄)
@[simp]
lemma tensorLift_tmul (m : M₁) (n : M₂) :
tensorLift f h₁ h₂ h₃ h₄ (m ⊗ₜ n) = f m n := rfl
end
lemma tensor_ext {f g : M₁ ⊗ M₂ ⟶ M₃} (h : ∀ m n, f.hom (m ⊗ₜ n) = g.hom (m ⊗ₜ n)) :
f = g :=
hom_ext <| TensorProduct.ext (by ext; apply h)
/-- Extensionality lemma for morphisms from a module of the form `(M₁ ⊗ M₂) ⊗ M₃`. -/
lemma tensor_ext₃' {f g : (M₁ ⊗ M₂) ⊗ M₃ ⟶ M₄}
(h : ∀ m₁ m₂ m₃, f (m₁ ⊗ₜ m₂ ⊗ₜ m₃) = g (m₁ ⊗ₜ m₂ ⊗ₜ m₃)) :
f = g :=
hom_ext <| TensorProduct.ext_threefold h
/-- Extensionality lemma for morphisms from a module of the form `M₁ ⊗ (M₂ ⊗ M₃)`. -/
lemma tensor_ext₃ {f g : M₁ ⊗ (M₂ ⊗ M₃) ⟶ M₄}
(h : ∀ m₁ m₂ m₃, f (m₁ ⊗ₜ (m₂ ⊗ₜ m₃)) = g (m₁ ⊗ₜ (m₂ ⊗ₜ m₃))) :
f = g := by
rw [← cancel_epi (α_ _ _ _).hom]
exact tensor_ext₃' h
end MonoidalCategory
end SemimoduleCat
namespace ModuleCat
variable {R : Type u} [CommRing R]
@[simps -isSimp]
instance MonoidalCategory.instMonoidalCategoryStruct :
MonoidalCategoryStruct (ModuleCat.{u} R) where
tensorObj M N := of R (TensorProduct R M N)
whiskerLeft M _ _ f := ofHom <| f.hom.lTensor M
whiskerRight f M := ofHom <| f.hom.rTensor M
tensorHom f g := ofHom <| TensorProduct.map f.hom g.hom
tensorUnit := of R R
associator M N K := (TensorProduct.assoc R M N K).toModuleIso
leftUnitor M := (TensorProduct.lid R M).toModuleIso
rightUnitor M := (TensorProduct.rid R M).toModuleIso
instance monoidalCategory : MonoidalCategory (ModuleCat.{u} R) :=
Monoidal.induced equivalenceSemimoduleCat.functor
{ μIso _ _ := .refl _
εIso := .refl _
associator_eq _ _ _ := by ext1; exact TensorProduct.ext (TensorProduct.ext rfl)
leftUnitor_eq _ := by ext1; exact TensorProduct.ext rfl
rightUnitor_eq _ := by ext1; exact TensorProduct.ext rfl }
open MonoidalCategory
/-- Remind ourselves that the monoidal unit, being just `R`, is still a commutative ring. -/
instance : CommRing ((𝟙_ (ModuleCat.{u} R) : ModuleCat.{u} R) : Type u) :=
inferInstanceAs <| CommRing R
theorem hom_tensorHom {K L M N : ModuleCat.{u} R} (f : K ⟶ L) (g : M ⟶ N) :
(f ⊗ₘ g).hom = TensorProduct.map f.hom g.hom :=
rfl
theorem hom_whiskerLeft (L : ModuleCat.{u} R) {M N : ModuleCat.{u} R} (f : M ⟶ N) :
(L ◁ f).hom = f.hom.lTensor L :=
rfl
theorem hom_whiskerRight {L M : ModuleCat.{u} R} (f : L ⟶ M) (N : ModuleCat.{u} R) :
(f ▷ N).hom = f.hom.rTensor N :=
rfl
theorem hom_hom_leftUnitor {M : ModuleCat.{u} R} :
(λ_ M).hom.hom = (TensorProduct.lid _ _).toLinearMap :=
rfl
theorem hom_inv_leftUnitor {M : ModuleCat.{u} R} :
(λ_ M).inv.hom = (TensorProduct.lid _ _).symm.toLinearMap :=
rfl
theorem hom_hom_rightUnitor {M : ModuleCat.{u} R} :
(ρ_ M).hom.hom = (TensorProduct.rid _ _).toLinearMap :=
rfl
theorem hom_inv_rightUnitor {M : ModuleCat.{u} R} :
(ρ_ M).inv.hom = (TensorProduct.rid _ _).symm.toLinearMap :=
rfl
theorem hom_hom_associator {M N K : ModuleCat.{u} R} :
(α_ M N K).hom.hom = (TensorProduct.assoc _ _ _ _).toLinearMap :=
rfl
theorem hom_inv_associator {M N K : ModuleCat.{u} R} :
(α_ M N K).inv.hom = (TensorProduct.assoc _ _ _ _).symm.toLinearMap :=
rfl
namespace MonoidalCategory
@[deprecated (since := "2025-10-29")] alias tensorObj := tensorObj_carrier
@[deprecated (since := "2025-10-29")] alias tensorObj_def := tensorObj_carrier
@[simp]
theorem tensorHom_tmul {K L M N : ModuleCat.{u} R} (f : K ⟶ L) (g : M ⟶ N) (k : K) (m : M) :
(f ⊗ₘ g) (k ⊗ₜ m) = f k ⊗ₜ g m :=
rfl
@[simp]
theorem whiskerLeft_apply (L : ModuleCat.{u} R) {M N : ModuleCat.{u} R} (f : M ⟶ N)
(l : L) (m : M) :
(L ◁ f) (l ⊗ₜ m) = l ⊗ₜ f m :=
rfl
@[simp]
theorem whiskerRight_apply {L M : ModuleCat.{u} R} (f : L ⟶ M) (N : ModuleCat.{u} R)
(l : L) (n : N) :
(f ▷ N) (l ⊗ₜ n) = f l ⊗ₜ n :=
rfl
@[simp]
theorem leftUnitor_hom_apply {M : ModuleCat.{u} R} (r : R) (m : M) :
((λ_ M).hom : 𝟙_ (ModuleCat R) ⊗ M ⟶ M) (r ⊗ₜ[R] m) = r • m :=
TensorProduct.lid_tmul m r
@[simp]
theorem leftUnitor_inv_apply {M : ModuleCat.{u} R} (m : M) :
((λ_ M).inv : M ⟶ 𝟙_ (ModuleCat.{u} R) ⊗ M) m = 1 ⊗ₜ[R] m :=
TensorProduct.lid_symm_apply m
@[simp]
theorem rightUnitor_hom_apply {M : ModuleCat.{u} R} (m : M) (r : R) :
((ρ_ M).hom : M ⊗ 𝟙_ (ModuleCat R) ⟶ M) (m ⊗ₜ r) = r • m :=
TensorProduct.rid_tmul m r
@[simp]
theorem rightUnitor_inv_apply {M : ModuleCat.{u} R} (m : M) :
((ρ_ M).inv : M ⟶ M ⊗ 𝟙_ (ModuleCat.{u} R)) m = m ⊗ₜ[R] 1 :=
TensorProduct.rid_symm_apply m
@[simp]
theorem associator_hom_apply {M N K : ModuleCat.{u} R} (m : M) (n : N) (k : K) :
((α_ M N K).hom : (M ⊗ N) ⊗ K ⟶ M ⊗ N ⊗ K) (m ⊗ₜ n ⊗ₜ k) = m ⊗ₜ (n ⊗ₜ k) :=
rfl
@[simp]
theorem associator_inv_apply {M N K : ModuleCat.{u} R} (m : M) (n : N) (k : K) :
((α_ M N K).inv : M ⊗ N ⊗ K ⟶ (M ⊗ N) ⊗ K) (m ⊗ₜ (n ⊗ₜ k)) = m ⊗ₜ n ⊗ₜ k :=
rfl
variable {M₁ M₂ M₃ M₄ : ModuleCat.{u} R}
section
variable (f : M₁ → M₂ → M₃) (h₁ : ∀ m₁ m₂ n, f (m₁ + m₂) n = f m₁ n + f m₂ n)
(h₂ : ∀ (a : R) m n, f (a • m) n = a • f m n)
(h₃ : ∀ m n₁ n₂, f m (n₁ + n₂) = f m n₁ + f m n₂)
(h₄ : ∀ (a : R) m n, f m (a • n) = a • f m n)
/-- Construct for morphisms from the tensor product of two objects in `ModuleCat`. -/
def tensorLift : M₁ ⊗ M₂ ⟶ M₃ :=
ofHom <| TensorProduct.lift (LinearMap.mk₂ R f h₁ h₂ h₃ h₄)
@[simp]
lemma tensorLift_tmul (m : M₁) (n : M₂) :
tensorLift f h₁ h₂ h₃ h₄ (m ⊗ₜ n) = f m n := rfl
end
lemma tensor_ext {f g : M₁ ⊗ M₂ ⟶ M₃} (h : ∀ m n, f.hom (m ⊗ₜ n) = g.hom (m ⊗ₜ n)) :
f = g :=
hom_ext <| TensorProduct.ext (by ext; apply h)
/-- Extensionality lemma for morphisms from a module of the form `(M₁ ⊗ M₂) ⊗ M₃`. -/
lemma tensor_ext₃' {f g : (M₁ ⊗ M₂) ⊗ M₃ ⟶ M₄}
(h : ∀ m₁ m₂ m₃, f (m₁ ⊗ₜ m₂ ⊗ₜ m₃) = g (m₁ ⊗ₜ m₂ ⊗ₜ m₃)) :
f = g :=
hom_ext <| TensorProduct.ext_threefold h
/-- Extensionality lemma for morphisms from a module of the form `M₁ ⊗ (M₂ ⊗ M₃)`. -/
lemma tensor_ext₃ {f g : M₁ ⊗ (M₂ ⊗ M₃) ⟶ M₄}
(h : ∀ m₁ m₂ m₃, f (m₁ ⊗ₜ (m₂ ⊗ₜ m₃)) = g (m₁ ⊗ₜ (m₂ ⊗ₜ m₃))) :
f = g := by
rw [← cancel_epi (α_ _ _ _).hom]
exact tensor_ext₃' h
end MonoidalCategory
open Opposite
instance : MonoidalPreadditive (ModuleCat.{u} R) := by
refine ⟨?_, ?_, ?_, ?_⟩
· intros
ext : 1
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂ₛₗ_apply, TensorProduct.mk_apply, hom_zero, LinearMap.zero_apply]
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [MonoidalCategory.whiskerLeft_apply]
simp
· intros
ext : 1
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂ₛₗ_apply, TensorProduct.mk_apply, hom_zero, LinearMap.zero_apply, ]
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [MonoidalCategory.whiskerRight_apply]
simp
· intros
ext : 1
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂ₛₗ_apply, TensorProduct.mk_apply, hom_add, LinearMap.add_apply]
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [MonoidalCategory.whiskerLeft_apply, MonoidalCategory.whiskerLeft_apply]
erw [MonoidalCategory.whiskerLeft_apply]
simp [TensorProduct.tmul_add]
· intros
ext : 1
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂ₛₗ_apply, TensorProduct.mk_apply, hom_add, LinearMap.add_apply]
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [MonoidalCategory.whiskerRight_apply, MonoidalCategory.whiskerRight_apply]
erw [MonoidalCategory.whiskerRight_apply]
simp [TensorProduct.add_tmul]
instance : MonoidalLinear R (ModuleCat.{u} R) := by
refine ⟨?_, ?_⟩
· intros
ext : 1
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂ₛₗ_apply, TensorProduct.mk_apply, hom_smul, LinearMap.smul_apply]
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [MonoidalCategory.whiskerLeft_apply, MonoidalCategory.whiskerLeft_apply]
simp
· intros
ext : 1
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂ₛₗ_apply, TensorProduct.mk_apply, hom_smul, LinearMap.smul_apply]
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [MonoidalCategory.whiskerRight_apply, MonoidalCategory.whiskerRight_apply]
simp [TensorProduct.smul_tmul, TensorProduct.tmul_smul]
@[simp] lemma ofHom₂_compr₂ {M N P Q : ModuleCat.{u} R} (f : M →ₗ[R] N →ₗ[R] P) (g : P →ₗ[R] Q) :
ofHom₂ (f.compr₂ g) = ofHom₂ f ≫ ofHom (Linear.rightComp R _ (ofHom g)) := rfl
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Monoidal/Symmetric.lean | import Mathlib.CategoryTheory.Monoidal.Braided.Basic
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic
/-!
# The symmetric monoidal structure on `Module R`.
-/
universe v w x u
open CategoryTheory MonoidalCategory
namespace SemimoduleCat
variable {R : Type u} [CommSemiring R]
/-- (implementation) the braiding for R-modules -/
def braiding (M N : SemimoduleCat.{u} R) : M ⊗ N ≅ N ⊗ M :=
LinearEquiv.toModuleIsoₛ (TensorProduct.comm R M N)
namespace MonoidalCategory
@[simp]
theorem braiding_naturality {X₁ X₂ Y₁ Y₂ : SemimoduleCat.{u} R} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) :
(f ⊗ₘ g) ≫ (Y₁.braiding Y₂).hom = (X₁.braiding X₂).hom ≫ (g ⊗ₘ f) := by
ext : 1
apply TensorProduct.ext'
intro x y
rfl
@[simp]
theorem braiding_naturality_left {X Y : SemimoduleCat R} (f : X ⟶ Y) (Z : SemimoduleCat R) :
f ▷ Z ≫ (braiding Y Z).hom = (braiding X Z).hom ≫ Z ◁ f := by
simp_rw [← id_tensorHom]
apply braiding_naturality
@[simp]
theorem braiding_naturality_right (X : SemimoduleCat R) {Y Z : SemimoduleCat R} (f : Y ⟶ Z) :
X ◁ f ≫ (braiding X Z).hom = (braiding X Y).hom ≫ f ▷ X := by
simp_rw [← id_tensorHom]
apply braiding_naturality
@[simp]
theorem hexagon_forward (X Y Z : SemimoduleCat.{u} R) :
(α_ X Y Z).hom ≫ (braiding X _).hom ≫ (α_ Y Z X).hom =
(braiding X Y).hom ▷ Z ≫ (α_ Y X Z).hom ≫ Y ◁ (braiding X Z).hom := by
ext : 1
apply TensorProduct.ext_threefold
intro x y z
rfl
@[simp]
theorem hexagon_reverse (X Y Z : SemimoduleCat.{u} R) :
(α_ X Y Z).inv ≫ (braiding _ Z).hom ≫ (α_ Z X Y).inv =
X ◁ (Y.braiding Z).hom ≫ (α_ X Z Y).inv ≫ (X.braiding Z).hom ▷ Y := by
apply (cancel_epi (α_ X Y Z).hom).1
ext : 1
apply TensorProduct.ext_threefold
intro x y z
rfl
attribute [local ext] TensorProduct.ext
/-- The symmetric monoidal structure on `Module R`. -/
instance symmetricCategory : SymmetricCategory (SemimoduleCat.{u} R) where
braiding := braiding
braiding_naturality_left := braiding_naturality_left
braiding_naturality_right := braiding_naturality_right
hexagon_forward := hexagon_forward
hexagon_reverse := hexagon_reverse
-- Porting note: this proof was automatic in Lean3
-- now `aesop` is applying `SemimoduleCat.ext` in favour of `TensorProduct.ext`.
symmetry _ _ := by
ext : 1
apply TensorProduct.ext'
cat_disch
@[simp]
theorem braiding_hom_apply {M N : SemimoduleCat.{u} R} (m : M) (n : N) :
((β_ M N).hom : M ⊗ N ⟶ N ⊗ M) (m ⊗ₜ n) = n ⊗ₜ m :=
rfl
@[simp]
theorem braiding_inv_apply {M N : SemimoduleCat.{u} R} (m : M) (n : N) :
((β_ M N).inv : N ⊗ M ⟶ M ⊗ N) (n ⊗ₜ m) = m ⊗ₜ n :=
rfl
theorem tensorμ_eq_tensorTensorTensorComm {A B C D : SemimoduleCat R} :
tensorμ A B C D = ofHom (TensorProduct.tensorTensorTensorComm R A B C D).toLinearMap :=
SemimoduleCat.hom_ext <| TensorProduct.ext <| TensorProduct.ext <| LinearMap.ext₂ fun _ _ =>
TensorProduct.ext <| LinearMap.ext₂ fun _ _ => rfl
@[simp]
theorem tensorμ_apply
{A B C D : SemimoduleCat R} (x : A) (y : B) (z : C) (w : D) :
tensorμ A B C D ((x ⊗ₜ y) ⊗ₜ (z ⊗ₜ w)) = (x ⊗ₜ z) ⊗ₜ (y ⊗ₜ w) := rfl
end MonoidalCategory
end SemimoduleCat
namespace ModuleCat.MonoidalCategory
variable {R : Type u} [CommRing R]
instance : BraidedCategory (ModuleCat.{u} R) :=
.ofFaithful equivalenceSemimoduleCat.functor (fun M N ↦ (TensorProduct.comm R M N).toModuleIso)
instance : equivalenceSemimoduleCat (R := R).functor.Braided where
instance symmetricCategory : SymmetricCategory (ModuleCat.{u} R) :=
.ofFaithful equivalenceSemimoduleCat.functor
@[simp]
theorem braiding_hom_apply {M N : ModuleCat.{u} R} (m : M) (n : N) :
((β_ M N).hom : M ⊗ N ⟶ N ⊗ M) (m ⊗ₜ n) = n ⊗ₜ m :=
rfl
@[simp]
theorem braiding_inv_apply {M N : ModuleCat.{u} R} (m : M) (n : N) :
((β_ M N).inv : N ⊗ M ⟶ M ⊗ N) (n ⊗ₜ m) = m ⊗ₜ n :=
rfl
theorem tensorμ_eq_tensorTensorTensorComm {A B C D : ModuleCat R} :
tensorμ A B C D = ofHom (TensorProduct.tensorTensorTensorComm R A B C D).toLinearMap :=
ModuleCat.hom_ext <| TensorProduct.ext <| TensorProduct.ext <| LinearMap.ext₂ fun _ _ =>
TensorProduct.ext <| LinearMap.ext₂ fun _ _ => rfl
@[simp]
theorem tensorμ_apply
{A B C D : ModuleCat R} (x : A) (y : B) (z : C) (w : D) :
tensorμ A B C D ((x ⊗ₜ y) ⊗ₜ (z ⊗ₜ w)) = (x ⊗ₜ z) ⊗ₜ (y ⊗ₜ w) := rfl
end ModuleCat.MonoidalCategory |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Monoidal/Closed.lean | import Mathlib.CategoryTheory.Closed.Monoidal
import Mathlib.CategoryTheory.Linear.Yoneda
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Symmetric
/-!
# The monoidal closed structure on `Module R`.
-/
universe v w x u
open CategoryTheory Opposite
namespace ModuleCat
variable {R : Type u} [CommRing R]
/-- Auxiliary definition for the `MonoidalClosed` instance on `Module R`.
(This is only a separate definition in order to speed up typechecking.)
-/
def monoidalClosedHomEquiv (M N P : ModuleCat.{u} R) :
((MonoidalCategory.tensorLeft M).obj N ⟶ P) ≃
(N ⟶ ((linearCoyoneda R (ModuleCat R)).obj (op M)).obj P) where
toFun f := ofHom₂ <| LinearMap.compr₂ (TensorProduct.mk R N M) ((β_ N M).hom ≫ f).hom
invFun f := (β_ M N).hom ≫ ofHom (TensorProduct.lift f.hom₂)
left_inv f := by
ext : 1
apply TensorProduct.ext'
solve_by_elim
instance : MonoidalClosed (ModuleCat.{u} R) where
closed M :=
{ rightAdj := (linearCoyoneda R (ModuleCat.{u} R)).obj (op M)
adj := Adjunction.mkOfHomEquiv
{ homEquiv := fun N P => monoidalClosedHomEquiv M N P
-- Porting note: this proof was automatic in mathlib3
homEquiv_naturality_left_symm := by
intros
ext : 1
apply TensorProduct.ext'
intro m n
rfl } }
theorem ihom_map_apply {M N P : ModuleCat.{u} R} (f : N ⟶ P) (g : ModuleCat.of R (M ⟶ N)) :
(ihom M).map f g = g ≫ f :=
rfl
open MonoidalCategory
theorem monoidalClosed_curry {M N P : ModuleCat.{u} R} (f : M ⊗ N ⟶ P) (x : M) (y : N) :
((MonoidalClosed.curry f).hom y).hom x = f (x ⊗ₜ[R] y) :=
rfl
@[simp]
theorem monoidalClosed_uncurry
{M N P : ModuleCat.{u} R} (f : N ⟶ M ⟶[ModuleCat.{u} R] P) (x : M) (y : N) :
MonoidalClosed.uncurry f (x ⊗ₜ[R] y) = (f y).hom x :=
rfl
/-- Describes the counit of the adjunction `M ⊗ - ⊣ Hom(M, -)`. Given an `R`-module `N` this
should give a map `M ⊗ Hom(M, N) ⟶ N`, so we flip the order of the arguments in the identity map
`Hom(M, N) ⟶ (M ⟶ N)` and uncurry the resulting map `M ⟶ Hom(M, N) ⟶ N.` -/
theorem ihom_ev_app (M N : ModuleCat.{u} R) :
(ihom.ev M).app N = ModuleCat.ofHom (TensorProduct.uncurry (.id R) M ((ihom M).obj N) N
(LinearMap.lcomp _ _ homLinearEquiv.toLinearMap ∘ₗ LinearMap.id.flip)) := by
rw [← MonoidalClosed.uncurry_id_eq_ev]
ext : 1
apply TensorProduct.ext'
apply monoidalClosed_uncurry
/-- Describes the unit of the adjunction `M ⊗ - ⊣ Hom(M, -)`. Given an `R`-module `N` this should
define a map `N ⟶ Hom(M, M ⊗ N)`, which is given by flipping the arguments in the natural
`R`-bilinear map `M ⟶ N ⟶ M ⊗ N`. -/
theorem ihom_coev_app (M N : ModuleCat.{u} R) :
(ihom.coev M).app N = ModuleCat.ofHom₂ (TensorProduct.mk _ _ _).flip :=
rfl
theorem monoidalClosed_pre_app {M N : ModuleCat.{u} R} (P : ModuleCat.{u} R) (f : N ⟶ M) :
(MonoidalClosed.pre f).app P = ofHom (homLinearEquiv.symm.toLinearMap ∘ₗ
LinearMap.lcomp _ _ f.hom ∘ₗ homLinearEquiv.toLinearMap) :=
rfl
end ModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Sheaf/PullbackContinuous.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.Pullback
import Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafification
import Mathlib.Algebra.Category.ModuleCat.Sheaf.PushforwardContinuous
/-!
# Pullback of sheaves of modules
Let `S` and `R` be sheaves of rings over sites `(C, J)` and `(D, K)` respectively.
Let `F : C ⥤ D` be a continuous functor between these sites, and
let `φ : S ⟶ (F.sheafPushforwardContinuous RingCat.{u} J K).obj R` be a morphism
of sheaves of rings.
In this file, we define the pullback functor for sheaves of modules
`pullback.{v} φ : SheafOfModules.{v} S ⥤ SheafOfModules.{v} R`
that is left adjoint to `pushforward.{v} φ`. We show that it exists
under suitable assumptions, and prove that the pullback of (pre)sheaves of
modules commutes with the sheafification.
-/
universe v v₁ v₂ u₁ u₂ u
open CategoryTheory
namespace SheafOfModules
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
{J : GrothendieckTopology C} {K : GrothendieckTopology D} {F : C ⥤ D}
{S : Sheaf J RingCat.{u}} {R : Sheaf K RingCat.{u}}
[Functor.IsContinuous.{u} F J K] [Functor.IsContinuous.{v} F J K]
(φ : S ⟶ (F.sheafPushforwardContinuous RingCat.{u} J K).obj R)
section
variable [(pushforward.{v} φ).IsRightAdjoint]
/-- The pullback functor `SheafOfModules S ⥤ SheafOfModules R` induced by
a morphism of sheaves of rings `S ⟶ (F.sheafPushforwardContinuous RingCat.{u} J K).obj R`,
defined as the left adjoint functor to the pushforward, when it exists. -/
noncomputable def pullback : SheafOfModules.{v} S ⥤ SheafOfModules.{v} R :=
(pushforward.{v} φ).leftAdjoint
/-- Given a continuous functor between sites `F`, and a morphism of sheaves of rings
`S ⟶ (F.sheafPushforwardContinuous RingCat.{u} J K).obj R`, this is the adjunction
between the corresponding pullback and pushforward functors on the categories
of sheaves of modules. -/
noncomputable def pullbackPushforwardAdjunction : pullback.{v} φ ⊣ pushforward.{v} φ :=
Adjunction.ofIsRightAdjoint (pushforward φ)
instance : (pullback.{v} φ).IsLeftAdjoint :=
(pullbackPushforwardAdjunction φ).isLeftAdjoint
end
section
variable [(PresheafOfModules.pushforward.{v} φ.val).IsRightAdjoint]
[HasWeakSheafify K AddCommGrpCat.{v}] [K.WEqualsLocallyBijective AddCommGrpCat.{v}]
namespace PullbackConstruction
/-- Construction of a left adjoint to the functor `pushforward.{v} φ` by using the
pullback of presheaves of modules and the sheafification. -/
noncomputable def adjunction :
(forget S ⋙ PresheafOfModules.pullback.{v} φ.val ⋙
PresheafOfModules.sheafification (𝟙 R.val)) ⊣ pushforward.{v} φ :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun F G ↦
((PresheafOfModules.sheafificationAdjunction (𝟙 R.val)).homEquiv _ _).trans
(((PresheafOfModules.pullbackPushforwardAdjunction φ.val).homEquiv F.val G.val).trans
((fullyFaithfulForget S).homEquiv (Y := (pushforward φ).obj G)).symm)
homEquiv_naturality_left_symm := by
intros
dsimp [Functor.FullyFaithful.homEquiv]
-- these erw seem difficult to remove
erw [Adjunction.homEquiv_naturality_left_symm,
Adjunction.homEquiv_naturality_left_symm]
dsimp
simp only [Functor.map_comp, Category.assoc]
homEquiv_naturality_right := by
tauto }
end PullbackConstruction
instance : (pushforward.{v} φ).IsRightAdjoint :=
(PullbackConstruction.adjunction.{v} φ).isRightAdjoint
/-- The pullback functor on sheaves of modules can be described as a composition
of the forget functor to presheaves, the pullback on presheaves of modules, and
the sheafification functor. -/
noncomputable def pullbackIso :
pullback.{v} φ ≅
forget S ⋙ PresheafOfModules.pullback.{v} φ.val ⋙
PresheafOfModules.sheafification (𝟙 R.val) :=
Adjunction.leftAdjointUniq (pullbackPushforwardAdjunction φ)
(PullbackConstruction.adjunction φ)
section
variable [HasWeakSheafify J AddCommGrpCat.{v}] [J.WEqualsLocallyBijective AddCommGrpCat.{v}]
/-- The pullback of (pre)sheaves of modules commutes with the sheafification. -/
noncomputable def sheafificationCompPullback :
PresheafOfModules.sheafification (𝟙 S.val) ⋙ pullback.{v} φ ≅
PresheafOfModules.pullback.{v} φ.val ⋙
PresheafOfModules.sheafification (𝟙 R.val) :=
Adjunction.leftAdjointUniq
((PresheafOfModules.sheafificationAdjunction (𝟙 S.val)).comp
(pullbackPushforwardAdjunction φ))
((PresheafOfModules.pullbackPushforwardAdjunction φ.val).comp
(PresheafOfModules.sheafificationAdjunction (𝟙 R.val)))
end
end
end SheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Sheaf/Abelian.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafification
import Mathlib.CategoryTheory.Abelian.Transfer
/-!
# The category of sheaves of modules is abelian
In this file, it is shown that the category of sheaves of modules over
a sheaf of rings `R` is an abelian category. More precisely,
if `J` is a Grothendieck topology on a category `C` and `R : Sheaf J RingCat.{u}`,
then `SheafOfModules.{v} R` is abelian if the conditions `HasSheafify J AddCommGrpCat.{v}`
and `J.WEqualsLocallyBijective AddCommGrpCat.{v}` are satisfied.
In particular, if `u = v` and `C : Type u` is a small category,
then `SheafOfModules.{u} R` is abelian: this instance shall be
found automatically if this file and `Algebra.Category.Grp.FilteredColimits`
are imported.
-/
universe v v' u u'
open CategoryTheory Limits
variable {C : Type u'} [Category.{v'} C] {J : GrothendieckTopology C}
namespace SheafOfModules
variable (R : Sheaf J RingCat.{u}) [HasSheafify J AddCommGrpCat.{v}]
[J.WEqualsLocallyBijective AddCommGrpCat.{v}]
noncomputable instance : Abelian (SheafOfModules.{v} R) := by
let adj := PresheafOfModules.sheafificationAdjunction (𝟙 R.val)
exact abelianOfAdjunction _ _ (asIso (adj.counit)) adj
end SheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Sheaf/PushforwardContinuous.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.Pushforward
import Mathlib.Algebra.Category.ModuleCat.Sheaf
import Mathlib.CategoryTheory.Sites.Over
/-!
# Pushforward of sheaves of modules
Assume that categories `C` and `D` are equipped with Grothendieck topologies, and
that `F : C ⥤ D` is a continuous functor.
Then, if `φ : S ⟶ (F.sheafPushforwardContinuous RingCat.{u} J K).obj R` is
a morphism of sheaves of rings, we construct the pushforward functor
`pushforward φ : SheafOfModules.{v} R ⥤ SheafOfModules.{v} S`.
-/
universe v v₁ v₂ u₁ u₂ u
open CategoryTheory
namespace SheafOfModules
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
{J : GrothendieckTopology C} {K : GrothendieckTopology D} {F : C ⥤ D}
{S : Sheaf J RingCat.{u}} {R : Sheaf K RingCat.{u}}
[Functor.IsContinuous.{u} F J K] [Functor.IsContinuous.{v} F J K]
(φ : S ⟶ (F.sheafPushforwardContinuous RingCat.{u} J K).obj R)
/-- The pushforward of sheaves of modules that is induced by a continuous functor `F`
and a morphism of sheaves of rings `φ : S ⟶ (F.sheafPushforwardContinuous RingCat J K).obj R`. -/
@[simps]
noncomputable def pushforward : SheafOfModules.{v} R ⥤ SheafOfModules.{v} S where
obj M :=
{ val := (PresheafOfModules.pushforward φ.val).obj M.val
isSheaf := ((F.sheafPushforwardContinuous _ J K).obj ⟨_, M.isSheaf⟩).cond }
map f :=
{ val := (PresheafOfModules.pushforward φ.val).map f.val }
/-- Given `M : SheafOfModules R` and `X : D`, this is the restriction of `M`
over the sheaf of rings `R.over X` on the category `Over X`. -/
noncomputable abbrev over (M : SheafOfModules.{v} R) (X : D) : SheafOfModules.{v} (R.over X) :=
(pushforward.{v} (𝟙 _)).obj M
end SheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Sheaf/Generators.lean | import Mathlib.Algebra.Category.ModuleCat.Sheaf.Free
import Mathlib.Algebra.Category.ModuleCat.Sheaf.PushforwardContinuous
import Mathlib.CategoryTheory.Sites.CoversTop
/-!
# Generating sections of sheaves of modules
In this file, given a sheaf of modules `M` over a sheaf of rings `R`, we introduce
the structure `M.GeneratingSections` which consists of a family of (global)
sections `s : I → M.sections` which generate `M`.
We also introduce the structure `M.LocalGeneratorsData` which contains the data
of a covering `X i` of the terminal object and the data of a
`(M.over (X i)).GeneratingSections` for all `i`. This is used in order to
define sheaves of modules of finite type.
## References
* https://stacks.math.columbia.edu/tag/01B4
-/
universe u v' u'
open CategoryTheory Limits
variable {C : Type u'} [Category.{v'} C] {J : GrothendieckTopology C} {R : Sheaf J RingCat.{u}}
[HasWeakSheafify J AddCommGrpCat.{u}] [J.WEqualsLocallyBijective AddCommGrpCat.{u}]
[J.HasSheafCompose (forget₂ RingCat.{u} AddCommGrpCat.{u})]
namespace SheafOfModules
variable (M N P : SheafOfModules.{u} R)
/-- The type of sections which generate a sheaf of modules. -/
structure GeneratingSections where
/-- the index type for the sections -/
I : Type u
/-- a family of sections which generate the sheaf of modules -/
s : I → M.sections
epi : Epi (M.freeHomEquiv.symm s) := by infer_instance
namespace GeneratingSections
attribute [instance] epi
variable {M N P}
/-- The epimorphism `free σ.I ⟶ M` given by `σ : M.GeneratingSections`. -/
noncomputable abbrev π (σ : M.GeneratingSections) : free σ.I ⟶ M := M.freeHomEquiv.symm σ.s
/-- If `M ⟶ N` is an epimorphism and that `M` is generated by some sections,
then `N` is generated by the images of these sections. -/
@[simps]
def ofEpi (σ : M.GeneratingSections) (p : M ⟶ N) [Epi p] :
N.GeneratingSections where
I := σ.I
s i := sectionsMap p (σ.s i)
epi := by
rw [← freeHomEquiv_symm_comp]
apply epi_comp
lemma opEpi_id (σ : M.GeneratingSections) :
σ.ofEpi (𝟙 M) = σ := rfl
lemma opEpi_comp (σ : M.GeneratingSections) (p : M ⟶ N) (q : N ⟶ P) [Epi p] [Epi q] :
σ.ofEpi (p ≫ q) = (σ.ofEpi p).ofEpi q := rfl
/-- Two isomorphic sheaves of modules have equivalent families of generating sections. -/
def equivOfIso (e : M ≅ N) :
M.GeneratingSections ≃ N.GeneratingSections where
toFun σ := σ.ofEpi e.hom
invFun σ := σ.ofEpi e.inv
left_inv σ := by
dsimp
simp only [← opEpi_comp, e.hom_inv_id, opEpi_id]
right_inv σ := by
dsimp
simp only [← opEpi_comp, e.inv_hom_id, opEpi_id]
/-- `σ : M.GeneratingSections` is finite type if the index type `σ.I` is finite. -/
class IsFiniteType (σ : M.GeneratingSections) : Prop where
finite : Finite σ.I := by infer_instance
attribute [instance] IsFiniteType.finite
end GeneratingSections
variable [∀ (X : C), HasWeakSheafify (J.over X) AddCommGrpCat.{u}]
[∀ (X : C), (J.over X).WEqualsLocallyBijective AddCommGrpCat.{u}]
[∀ (X : C), (J.over X).HasSheafCompose (forget₂ RingCat AddCommGrpCat.{u})]
/-- The data of generating sections of the restriction of a sheaf of modules
over a covering of the terminal object. -/
structure LocalGeneratorsData where
/-- the index type of the covering -/
I : Type u'
/-- a family of objects which cover the terminal object -/
X : I → C
coversTop : J.CoversTop X
/-- the data of sections of `M` over `X i` which generate `M.over (X i)` -/
generators (i : I) : (M.over (X i)).GeneratingSections
variable {M} in
/-- The data of local generators of a sheaf of modules is finite type if
each family of generators is finite type. -/
class LocalGeneratorsData.IsFiniteType (p : M.LocalGeneratorsData) : Prop where
isFiniteType (i : p.I) : (p.generators i).IsFiniteType := by infer_instance
/-- A sheaf of modules is of finite type if locally, it is generated by finitely
many sections. -/
class IsFiniteType (M : SheafOfModules.{u} R) : Prop where
exists_localGeneratorsData (M) :
∃ (σ : M.LocalGeneratorsData), σ.IsFiniteType
/-- A choice of local generators when `M` is a sheaf of modules of finite type. -/
@[deprecated "Use the lemma `IsFiniteType.exists_localGeneratorsData` instead."
(since := "2025-10-28")]
noncomputable def localGeneratorsDataOfIsFiniteType (M : SheafOfModules.{u} R)
[M.IsFiniteType] :
M.LocalGeneratorsData :=
(IsFiniteType.exists_localGeneratorsData M).choose
end SheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Sheaf/Colimits.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafification
/-!
# Colimits in categories of sheaves of modules
In this file, we show that colimits of shape `J` exist in a category
of sheaves of modules if it exists in the corresponding category
of presheaves of modules.
-/
universe w' w v v' u' u
namespace SheafOfModules
open CategoryTheory Limits
variable {C : Type u'} [Category.{v'} C] {J : GrothendieckTopology C}
variable (R : Sheaf J RingCat.{u}) [HasWeakSheafify J AddCommGrpCat.{v}]
[J.WEqualsLocallyBijective AddCommGrpCat.{v}] (K : Type w) [Category.{w'} K]
instance [HasColimitsOfShape K (PresheafOfModules.{v} R.val)] :
HasColimitsOfShape K (SheafOfModules.{v} R) where
has_colimit F := by
let e : F ≅ (F ⋙ forget R) ⋙ PresheafOfModules.sheafification (𝟙 R.val) :=
Functor.isoWhiskerLeft F
(asIso (PresheafOfModules.sheafificationAdjunction (𝟙 R.val)).counit).symm
exact hasColimit_of_iso e
end SheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Sheaf/Limits.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.Limits
import Mathlib.Algebra.Category.ModuleCat.Sheaf
import Mathlib.CategoryTheory.Sites.Limits
/-! # Limits in categories of sheaves of modules
In this file, it is shown that under suitable assumptions,
limits exist in the category `SheafOfModules R`.
## TODO
* do the same for colimits (which requires constructing the associated sheaf of modules functor)
-/
universe v v₁ v₂ u₁ u₂ u
open CategoryTheory Category Limits
variable {C : Type u₁} [Category.{v₁} C] {J : GrothendieckTopology C}
{D : Type u₂} [Category.{v₂} D]
namespace PresheafOfModules
variable {R : Cᵒᵖ ⥤ RingCat.{u}}
{F : D ⥤ PresheafOfModules.{v} R}
[∀ X, Small.{v} ((F ⋙ evaluation R X) ⋙ forget _).sections]
{c : Cone F}
[HasLimitsOfShape D AddCommGrpCat.{v}]
lemma isSheaf_of_isLimit (hc : IsLimit c) (hF : ∀ j, Presheaf.IsSheaf J (F.obj j).presheaf) :
Presheaf.IsSheaf J (c.pt.presheaf) := by
let G : D ⥤ Sheaf J AddCommGrpCat.{v} :=
{ obj := fun j => ⟨(F.obj j).presheaf, hF j⟩
map := fun φ => ⟨(PresheafOfModules.toPresheaf R).map (F.map φ)⟩ }
exact Sheaf.isSheaf_of_isLimit G _ (isLimitOfPreserves (toPresheaf R) hc)
end PresheafOfModules
namespace SheafOfModules
variable {R : Sheaf J RingCat.{u}}
section Limits
variable (F : D ⥤ SheafOfModules.{v} R)
[∀ X, Small.{v} ((F ⋙ evaluation R X) ⋙ CategoryTheory.forget _).sections]
[HasLimitsOfShape D AddCommGrpCat.{v}]
instance (X : Cᵒᵖ) : Small.{v} (((F ⋙ forget _) ⋙ PresheafOfModules.evaluation _ X) ⋙
CategoryTheory.forget _).sections := by
solve_by_elim
noncomputable instance createsLimit : CreatesLimit F (forget _) :=
createsLimitOfFullyFaithfulOfIso' (limit.isLimit (F ⋙ forget _))
(mk (limit (F ⋙ forget _))
(PresheafOfModules.isSheaf_of_isLimit (limit.isLimit (F ⋙ forget _))
(fun j => (F.obj j).isSheaf))) (Iso.refl _)
instance hasLimit : HasLimit F := hasLimit_of_created F (forget _)
noncomputable instance evaluationPreservesLimit (X : Cᵒᵖ) :
PreservesLimit F (evaluation R X) := by
dsimp [evaluation]
infer_instance
end Limits
variable (R D)
section Small
variable [Small.{v} D]
instance hasLimitsOfShape : HasLimitsOfShape D (SheafOfModules.{v} R) where
noncomputable instance evaluationPreservesLimitsOfShape (X : Cᵒᵖ) :
PreservesLimitsOfShape D (evaluation R X : SheafOfModules.{v} R ⥤ _) where
noncomputable instance forgetPreservesLimitsOfShape :
PreservesLimitsOfShape D (forget.{v} R) where
end Small
namespace Finite
instance hasFiniteLimits : HasFiniteLimits (SheafOfModules.{v} R) :=
⟨fun _ => inferInstance⟩
noncomputable instance evaluationPreservesFiniteLimits (X : Cᵒᵖ) :
PreservesFiniteLimits (evaluation.{v} R X) where
noncomputable instance forgetPreservesFiniteLimits :
PreservesFiniteLimits (forget.{v} R) where
end Finite
instance hasLimitsOfSize : HasLimitsOfSize.{v₂, v} (SheafOfModules.{v} R) where
noncomputable instance evaluationPreservesLimitsOfSize (X : Cᵒᵖ) :
PreservesLimitsOfSize.{v₂, v} (evaluation R X : SheafOfModules.{v} R ⥤ _) where
noncomputable instance forgetPreservesLimitsOfSize :
PreservesLimitsOfSize.{v₂, v} (forget.{v} R) where
noncomputable instance :
PreservesFiniteLimits (SheafOfModules.toSheaf.{v} R ⋙ sheafToPresheaf _ _) :=
comp_preservesFiniteLimits (SheafOfModules.forget.{v} R) (PresheafOfModules.toPresheaf R.val)
noncomputable instance : PreservesFiniteLimits (SheafOfModules.toSheaf.{v} R) :=
preservesFiniteLimits_of_reflects_of_preserves _ (sheafToPresheaf _ _)
end SheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Sheaf/Quasicoherent.lean | import Mathlib.Algebra.Category.ModuleCat.Sheaf.Generators
/-!
# Quasicoherent sheaves
A sheaf of modules is quasi-coherent if it admits locally a presentation as the
cokernel of a morphism between coproducts of copies of the sheaf of rings.
When these coproducts are finite, we say that the sheaf is of finite presentation.
## References
* https://stacks.math.columbia.edu/tag/01BD
-/
universe u v' u'
open CategoryTheory Limits
variable {C : Type u'} [Category.{v'} C] {J : GrothendieckTopology C}
{R : Sheaf J RingCat.{u}}
namespace SheafOfModules
section
variable [HasWeakSheafify J AddCommGrpCat.{u}] [J.WEqualsLocallyBijective AddCommGrpCat.{u}]
[J.HasSheafCompose (forget₂ RingCat.{u} AddCommGrpCat.{u})]
/-- A global presentation of a sheaf of modules `M` consists of a family `generators.s`
of sections `s` which generate `M`, and a family of sections which generate
the kernel of the morphism `generators.π : free (generators.I) ⟶ M`. -/
structure Presentation (M : SheafOfModules.{u} R) where
/-- generators -/
generators : M.GeneratingSections
/-- relations -/
relations : (kernel generators.π).GeneratingSections
/-- A global presentation of a sheaf of module if finite if the type
of generators and relations are finite. -/
class Presentation.IsFinite {M : SheafOfModules.{u} R} (p : M.Presentation) : Prop where
isFiniteType_generators : p.generators.IsFiniteType := by infer_instance
finite_relations : Finite p.relations.I := by infer_instance
attribute [instance] Presentation.IsFinite.isFiniteType_generators
Presentation.IsFinite.finite_relations
end
variable [∀ X, (J.over X).HasSheafCompose (forget₂ RingCat.{u} AddCommGrpCat.{u})]
[∀ X, HasWeakSheafify (J.over X) AddCommGrpCat.{u}]
[∀ X, (J.over X).WEqualsLocallyBijective AddCommGrpCat.{u}]
/-- This structure contains the data of a family of objects `X i` which cover
the terminal object, and of a presentation of `M.over (X i)` for all `i`. -/
structure QuasicoherentData (M : SheafOfModules.{u} R) where
/-- the index type of the covering -/
I : Type u'
/-- a family of objects which cover the terminal object -/
X : I → C
coversTop : J.CoversTop X
/-- a presentation of the sheaf of modules `M.over (X i)` for any `i : I` -/
presentation (i : I) : (M.over (X i)).Presentation
namespace QuasicoherentData
/-- If `M` is quasicoherent, it is locally generated by sections. -/
@[simps]
def localGeneratorsData {M : SheafOfModules.{u} R} (q : M.QuasicoherentData) :
M.LocalGeneratorsData where
I := q.I
X := q.X
coversTop := q.coversTop
generators i := (q.presentation i).generators
/-- A (local) presentation of a sheaf of module `M` is a finite presentation
if each given presentation of `M.over (X i)` is a finite presentation. -/
class IsFinitePresentation {M : SheafOfModules.{u} R} (q : M.QuasicoherentData) : Prop where
isFinite_presentation (i : q.I) : (q.presentation i).IsFinite := by infer_instance
attribute [instance] IsFinitePresentation.isFinite_presentation
instance {M : SheafOfModules.{u} R} (q : M.QuasicoherentData) [q.IsFinitePresentation] :
q.localGeneratorsData.IsFiniteType where
isFiniteType := by dsimp; infer_instance
end QuasicoherentData
/-- A sheaf of modules is quasi-coherent if it is locally the cokernel of a
morphism between coproducts of copies of the sheaf of rings. -/
class IsQuasicoherent (M : SheafOfModules.{u} R) : Prop where
nonempty_quasicoherentData : Nonempty M.QuasicoherentData := by infer_instance
variable (R) in
@[inherit_doc IsQuasicoherent]
abbrev isQuasicoherent : ObjectProperty (SheafOfModules.{u} R) :=
IsQuasicoherent
/-- A sheaf of modules is finitely presented if it is locally the cokernel of a
morphism between coproducts of finitely many copies of the sheaf of rings. -/
class IsFinitePresentation (M : SheafOfModules.{u} R) : Prop where
exists_quasicoherentData (M) :
∃ (σ : M.QuasicoherentData), σ.IsFinitePresentation
variable (R) in
@[inherit_doc IsFinitePresentation]
abbrev isFinitePresentation : ObjectProperty (SheafOfModules.{u} R) :=
IsFinitePresentation
instance (M : SheafOfModules.{u} R) [M.IsFinitePresentation] :
M.IsQuasicoherent where
nonempty_quasicoherentData :=
⟨(IsFinitePresentation.exists_quasicoherentData M).choose⟩
instance (M : SheafOfModules.{u} R) [M.IsFinitePresentation] :
M.IsFiniteType where
exists_localGeneratorsData := by
obtain ⟨σ, _⟩ := IsFinitePresentation.exists_quasicoherentData M
exact ⟨σ.localGeneratorsData, inferInstance⟩
/-- A choice of local presentations when `M` is a sheaf of modules of finite presentation. -/
@[deprecated "Use the lemma `IsFinitePresentation.exists_quasicoherentData` instead."
(since := "2025-10-28")]
noncomputable def quasicoherentDataOfIsFinitePresentation
(M : SheafOfModules.{u} R) [M.IsFinitePresentation] : M.QuasicoherentData :=
(IsFinitePresentation.exists_quasicoherentData M).choose
end SheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Sheaf/ChangeOfRings.lean | import Mathlib.Algebra.Category.ModuleCat.Sheaf
import Mathlib.Algebra.Category.ModuleCat.Presheaf.ChangeOfRings
import Mathlib.CategoryTheory.Sites.LocallySurjective
/-!
# Change of sheaf of rings
In this file, we define the restriction of scalars functor
`restrictScalars α : SheafOfModules.{v} R' ⥤ SheafOfModules.{v} R`
attached to a morphism of sheaves of rings `α : R ⟶ R'`.
-/
universe v v' u u'
open CategoryTheory
variable {C : Type u'} [Category.{v'} C] {J : GrothendieckTopology C}
namespace SheafOfModules
variable {R R' : Sheaf J RingCat.{u}} (α : R ⟶ R')
/-- The restriction of scalars functor `SheafOfModules R' ⥤ SheafOfModules R`
induced by a morphism of sheaves of rings `R ⟶ R'`. -/
@[simps]
noncomputable def restrictScalars :
SheafOfModules.{v} R' ⥤ SheafOfModules.{v} R where
obj M' :=
{ val := (PresheafOfModules.restrictScalars α.val).obj M'.val
isSheaf := M'.isSheaf }
map φ := { val := (PresheafOfModules.restrictScalars α.val).map φ.val }
instance : (restrictScalars.{v} α).Additive where
end SheafOfModules
namespace PresheafOfModules
variable {R R' : Cᵒᵖ ⥤ RingCat.{u}} (α : R ⟶ R')
{M₁ M₂ : PresheafOfModules.{v} R'}
/-- The functor `PresheafOfModules.restrictScalars α` induces bijections on
morphisms if `α` is locally surjective and the target presheaf is a sheaf. -/
noncomputable def restrictHomEquivOfIsLocallySurjective
(hM₂ : Presheaf.IsSheaf J M₂.presheaf) [Presheaf.IsLocallySurjective J α] :
(M₁ ⟶ M₂) ≃ ((restrictScalars α).obj M₁ ⟶ (restrictScalars α).obj M₂) where
toFun f := (restrictScalars α).map f
invFun g := homMk ((toPresheaf R).map g) (fun X r' m ↦ by
apply hM₂.isSeparated _ _ (Presheaf.imageSieve_mem J α r')
rintro Y p ⟨r : R.obj _, hr⟩
have hg : ∀ (z : M₁.obj X), g.app _ (M₁.map p.op z) = M₂.map p.op (g.app X z) :=
fun z ↦ CategoryTheory.congr_fun (g.naturality p.op) z
change M₂.map p.op (g.app X (r' • m)) = M₂.map p.op (r' • show M₂.obj X from g.app X m)
dsimp at hg ⊢
rw [← hg, M₂.map_smul, ← hg, ← hr]
erw [← (g.app _).hom.map_smul]
rw [M₁.map_smul, ← hr]
rfl)
end PresheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Sheaf/Free.lean | import Mathlib.Algebra.Category.ModuleCat.Presheaf.Colimits
import Mathlib.Algebra.Category.ModuleCat.Sheaf.Colimits
/-!
# Free sheaves of modules
In this file, we construct the functor
`SheafOfModules.freeFunctor : Type u ⥤ SheafOfModules.{u} R` which sends
a type `I` to the coproduct of copies indexed by `I` of `unit R`.
## TODO
* In case the category `C` has a terminal object `X`, promote `freeHomEquiv`
into an adjunction between `freeFunctor` and the evaluation functor at `X`.
(Alternatively, assuming specific universe parameters, we could show that
`freeFunctor` is a left adjoint to `SheafOfModules.sectionsFunctor`.)
-/
universe u v' u'
open CategoryTheory Limits
variable {C : Type u'} [Category.{v'} C] {J : GrothendieckTopology C} {R : Sheaf J RingCat.{u}}
[HasWeakSheafify J AddCommGrpCat.{u}] [J.WEqualsLocallyBijective AddCommGrpCat.{u}]
[J.HasSheafCompose (forget₂ RingCat.{u} AddCommGrpCat.{u})]
namespace SheafOfModules
/-- The free sheaf of modules on a certain type `I`. -/
noncomputable def free (I : Type u) : SheafOfModules.{u} R := ∐ (fun (_ : I) ↦ unit R)
/-- The inclusions `unit R ⟶ free I`. -/
noncomputable def ιFree {I : Type u} (i : I) : unit R ⟶ free I :=
Sigma.ι (fun (_ : I) ↦ unit R) i
/-- The tautological cofan with point `free I : SheafOfModules R`. -/
noncomputable def freeCofan (I : Type u) : Cofan (fun (_ : I) ↦ unit R) :=
Cofan.mk (P := free I) ιFree
@[simp]
lemma freeCofan_inj {I : Type u} (i : I) :
(freeCofan (R := R) I).inj i = ιFree i := rfl
/-- `free I` is the colimit of copies of `unit R` indexed by `I`. -/
noncomputable def isColimitFreeCofan (I : Type u) :
IsColimit (freeCofan (R := R) I) :=
coproductIsCoproduct _
/-- The data of a morphism `free I ⟶ M` from a free sheaf of modules is
equivalent to the data of a family `I → M.sections` of sections of `M`. -/
noncomputable def freeHomEquiv (M : SheafOfModules.{u} R) {I : Type u} :
(free I ⟶ M) ≃ (I → M.sections) where
toFun f i := M.unitHomEquiv (ιFree i ≫ f)
invFun s := Cofan.IsColimit.desc (isColimitFreeCofan I) (fun i ↦ M.unitHomEquiv.symm (s i))
left_inv s := Cofan.IsColimit.hom_ext (isColimitFreeCofan I) _ _
(fun i ↦ by simp [← freeCofan_inj])
right_inv f := by ext1 i; simp [← freeCofan_inj]
lemma freeHomEquiv_comp_apply {M N : SheafOfModules.{u} R} {I : Type u}
(f : free I ⟶ M) (p : M ⟶ N) (i : I) :
N.freeHomEquiv (f ≫ p) i = sectionsMap p (M.freeHomEquiv f i) := rfl
lemma freeHomEquiv_symm_comp {M N : SheafOfModules.{u} R} {I : Type u} (s : I → M.sections)
(p : M ⟶ N) :
M.freeHomEquiv.symm s ≫ p = N.freeHomEquiv.symm (fun i ↦ sectionsMap p (s i)) :=
N.freeHomEquiv.injective (by ext; simp [freeHomEquiv_comp_apply])
/-- The tautological section of `free I : SheafOfModules R` corresponding to `i : I`. -/
noncomputable abbrev freeSection {I : Type u} (i : I) : (free (R := R) I).sections :=
(free (R := R) I).freeHomEquiv (𝟙 (free I)) i
lemma unitHomEquiv_symm_freeHomEquiv_apply
{I : Type u} {M : SheafOfModules.{u} R} (f : free I ⟶ M) (i : I) :
M.unitHomEquiv.symm (M.freeHomEquiv f i) = ιFree i ≫ f := by
simp [freeHomEquiv]
section
variable {I J : Type u} (f : I → J)
/-- The morphism of presheaves of `R`-modules `free I ⟶ free J` induced by
a map `f : I → J`. -/
noncomputable def freeMap : free (R := R) I ⟶ free J :=
(freeHomEquiv _).symm (fun i ↦ freeSection (f i))
@[simp]
lemma freeHomEquiv_freeMap :
(freeHomEquiv _ (freeMap (R := R) f)) = freeSection.comp f :=
(freeHomEquiv _).symm.injective (by simp; rfl)
@[simp]
lemma sectionMap_freeMap_freeSection (i : I) :
sectionsMap (freeMap (R := R) f) (freeSection i) = freeSection (f i) := by
simp [← freeHomEquiv_comp_apply]
@[reassoc (attr := simp)]
lemma ιFree_freeMap (i : I) :
ιFree (R := R) i ≫ freeMap f = ιFree (f i) := by
rw [← unitHomEquiv_symm_freeHomEquiv_apply, freeHomEquiv_freeMap]
dsimp [freeSection]
rw [unitHomEquiv_symm_freeHomEquiv_apply, Category.comp_id]
end
/-- The functor `Type u ⥤ SheafOfModules.{u} R` which sends a type `I` to
`free I` which is a coproduct indexed by `I` of copies of `R` (thought of as a
presheaf of modules over itself). -/
@[simps]
noncomputable def freeFunctor : Type u ⥤ SheafOfModules.{u} R where
obj := free
map f := freeMap f
map_id X := (freeHomEquiv _).injective (by ext1 i; simp)
map_comp {I J K} f g := (freeHomEquiv _).injective (by ext1; simp [freeHomEquiv_comp_apply])
end SheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/ModuleCat/Sheaf/PullbackFree.lean | import Mathlib.Algebra.Category.ModuleCat.Sheaf.Free
import Mathlib.Algebra.Category.ModuleCat.Sheaf.PullbackContinuous
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products
import Mathlib.CategoryTheory.Limits.Final.Type
/-!
# Pullbacks of free sheaves of modules
Let `S` (resp.`R`) be a sheaf of rings on a category `C` (resp. `D`)
equipped with a Grothendieck topology `J` (resp. `K`).
Let `F : C ⥤ D` be a continuous functor.
Let `φ` be a morphism from `S` to the direct image of `R`.
We introduce `unitToPushforwardObjUnit φ` which is the morphism
in the category `SheafOfModules S` which corresponds to `φ`, and
show that the adjoint morphism
`pullbackObjUnitToUnit φ : (pullback.{u} φ).obj (unit S) ⟶ unit R`
is an isomorphism when `F` is a final functor.
More generally, the functor `pullback φ` sends the free sheaf
of modules `free I` to `free I`, see `pullbackObjFreeIso` and
`freeFunctorCompPullbackIso`.
-/
universe v v₁ v₂ u₁ u₂ u
open CategoryTheory Limits
namespace SheafOfModules
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
{J : GrothendieckTopology C} {K : GrothendieckTopology D} {F : C ⥤ D}
{S : Sheaf J RingCat.{u}} {R : Sheaf K RingCat.{u}}
[Functor.IsContinuous.{u} F J K]
(φ : S ⟶ (F.sheafPushforwardContinuous RingCat.{u} J K).obj R)
/-- The canonical map from the (global) sections of a sheaf of modules
to the (global) sections of its pushforward. -/
@[simps]
def pushforwardSections [Functor.IsContinuous.{v} F J K]
{M : SheafOfModules.{v} R} (s : M.sections) :
((pushforward φ).obj M).sections where
val _ := s.val _
property _ := s.property _
variable (M) in
lemma bijective_pushforwardSections [Functor.IsContinuous.{v} F J K] [F.Final] :
Function.Bijective (pushforwardSections φ (M := M)) :=
Functor.bijective_sectionsPrecomp _ _
variable [J.HasSheafCompose (forget₂ RingCat.{u} AddCommGrpCat.{u})]
[K.HasSheafCompose (forget₂ RingCat.{u} AddCommGrpCat.{u})]
/-- The canonical morphism `unit S ⟶ (pushforward.{u} φ).obj (unit R)`
of sheaves of modules corresponding to a continuous map between ringed sites. -/
def unitToPushforwardObjUnit : unit S ⟶ (pushforward.{u} φ).obj (unit R) where
val.app X := ModuleCat.homMk ((forget₂ RingCat AddCommGrpCat).map (φ.val.app X)) (fun r ↦ by
ext m
exact ((φ.val.app X).hom.map_mul _ _).symm)
val.naturality f := by
ext
exact ConcreteCategory.congr_hom (φ.val.naturality f) _
lemma unitToPushforwardObjUnit_val_app_apply {X : Cᵒᵖ} (a : S.val.obj X) :
(unitToPushforwardObjUnit φ).val.app X a = φ.val.app X a := rfl
lemma pushforwardSections_unitHomEquiv
{M : SheafOfModules.{u} R} (f : unit R ⟶ M) :
pushforwardSections φ (M.unitHomEquiv f) =
((pushforward φ).obj M).unitHomEquiv
(unitToPushforwardObjUnit φ ≫ (pushforward φ).map f) := by
ext X
have := unitToPushforwardObjUnit_val_app_apply φ (X := X) 1
dsimp at this ⊢
simp [this, map_one]
rfl
variable [(pushforward.{u} φ).IsRightAdjoint]
/-- The canonical morphism `(pullback.{u} φ).obj (unit S) ⟶ unit R`
of sheaves of modules corresponding to a continuous map between ringed sites. -/
noncomputable def pullbackObjUnitToUnit :
(pullback.{u} φ).obj (unit S) ⟶ unit R :=
((pullbackPushforwardAdjunction.{u} φ).homEquiv _ _).symm (unitToPushforwardObjUnit φ)
@[simp]
lemma pullbackPushforwardAdjunction_homEquiv_symm_unitToPushforwardObjUnit :
((pullbackPushforwardAdjunction.{u} φ).homEquiv _ _).symm (unitToPushforwardObjUnit φ) =
pullbackObjUnitToUnit φ := rfl
@[simp]
lemma pullbackPushforwardAdjunction_homEquiv_pullbackObjUnitToUnit :
(pullbackPushforwardAdjunction.{u} φ).homEquiv _ _ (pullbackObjUnitToUnit φ) =
unitToPushforwardObjUnit φ :=
Equiv.apply_symm_apply _ _
instance [F.Final] : IsIso (pullbackObjUnitToUnit φ) := by
rw [isIso_iff_coyoneda_map_bijective]
intro M
rw [← ((pullbackPushforwardAdjunction.{u} φ).homEquiv _ _).bijective.of_comp_iff',
← (unitHomEquiv _).bijective.of_comp_iff']
convert (bijective_pushforwardSections φ M).comp (unitHomEquiv _).bijective
ext f : 1
dsimp
rw [pushforwardSections_unitHomEquiv, EmbeddingLike.apply_eq_iff_eq,
Adjunction.homEquiv_naturality_right,
pullbackPushforwardAdjunction_homEquiv_pullbackObjUnitToUnit]
variable [HasWeakSheafify J AddCommGrpCat.{u}] [HasWeakSheafify K AddCommGrpCat.{u}]
[J.WEqualsLocallyBijective AddCommGrpCat.{u}]
[K.WEqualsLocallyBijective AddCommGrpCat.{u}] [F.Final]
/-- The pullback of a free sheaf of modules is a free sheaf of modules. -/
noncomputable def pullbackObjFreeIso (I : Type u) :
(pullback φ).obj (free I) ≅ free I :=
(asIso (sigmaComparison _ _)).symm ≪≫
Sigma.mapIso (fun _ ↦ asIso (pullbackObjUnitToUnit φ))
@[reassoc (attr := simp)]
lemma pullback_map_ιFree_comp_pullbackObjFreeIso_hom {I : Type u} (i : I) :
(pullback φ).map (ιFree i) ≫ (pullbackObjFreeIso φ I).hom =
pullbackObjUnitToUnit φ ≫ ιFree i := by
simp [pullbackObjFreeIso, ιFree]
@[reassoc (attr := simp)]
lemma pullbackObjFreeIso_hom_naturality {I J : Type u} (f : I → J) :
(pullback φ).map (freeMap f) ≫ (pullbackObjFreeIso φ J).hom =
(pullbackObjFreeIso φ I).hom ≫ freeMap f :=
Cofan.IsColimit.hom_ext (isColimitCofanMkObjOfIsColimit (pullback φ) _ _
(isColimitFreeCofan (R := S) I)) _ _ (fun i ↦ by simp [← Functor.map_comp_assoc])
/-- The canonical isomorphism `freeFunctor ⋙ pullback φ ≅ freeFunctor` for a
continuous map between ringed sites, when the underlying functor between the sites
is final. -/
noncomputable def freeFunctorCompPullbackIso : freeFunctor ⋙ pullback φ ≅ freeFunctor :=
NatIso.ofComponents (pullbackObjFreeIso φ)
end SheafOfModules |
.lake/packages/mathlib/Mathlib/Algebra/Category/CommAlgCat/Monoidal.lean | import Mathlib.Algebra.Category.CommAlgCat.Basic
import Mathlib.CategoryTheory.Monoidal.Cartesian.Basic
/-!
# The co-Cartesian monoidal category structure on commutative `R`-algebras
This file provides the co-Cartesian-monoidal category structure on `CommAlgCat R` constructed
explicitly using the tensor product.
-/
open CategoryTheory MonoidalCategory CartesianMonoidalCategory Limits TensorProduct Opposite
open Algebra.TensorProduct
open Algebra.TensorProduct (lid rid assoc comm)
noncomputable section
namespace CommAlgCat
universe u v
variable {R : Type u} [CommRing R] {A B C D : CommAlgCat.{u} R}
variable (A B)
/-- The explicit cocone with tensor products as the fibered coproduct in `CommAlgCat`. -/
def binaryCofan : BinaryCofan A B := .mk (ofHom includeLeft) (ofHom <| includeRight (A := A))
@[simp] lemma binaryCofan_inl : (binaryCofan A B).inl = ofHom includeLeft := rfl
@[simp] lemma binaryCofan_inr : (binaryCofan A B).inr = ofHom includeRight := rfl
@[simp] lemma binaryCofan_pt : (binaryCofan A B).pt = .of R (A ⊗[R] B) := rfl
/-- Verify that the pushout cocone is indeed the colimit. -/
def binaryCofanIsColimit : IsColimit (binaryCofan A B) :=
BinaryCofan.IsColimit.mk _
(fun f g ↦ ofHom (lift f.hom g.hom fun _ _ ↦ .all _ _))
(fun f g ↦ by ext1; exact lift_comp_includeLeft _ _ fun _ _ ↦ .all _ _)
(fun f g ↦ by ext1; exact lift_comp_includeRight _ _ fun _ _ ↦ .all _ _)
(fun f g m hm₁ hm₂ ↦ by
ext1
refine liftEquiv.symm_apply_eq (y := ⟨⟨_, _⟩, fun _ _ ↦ .all _ _⟩).mp ?_
exact Subtype.ext (Prod.ext congr(($hm₁).hom) congr(($hm₂).hom)))
/-- The initial object of `CommAlgCat R` is `R` as an algebra over itself. -/
def isInitialSelf : IsInitial (of R R) :=
.ofUniqueHom (fun A ↦ ofHom (Algebra.ofId R A)) fun _ _ ↦ hom_ext (Algebra.ext_id _ _ _)
attribute [local simp] one_def in
instance : MonoidalCategory (CommAlgCat.{u} R) where
tensorObj S T := of R (S ⊗[R] T)
whiskerLeft _ {_ _} f := ofHom (map (.id _ _) f.hom)
whiskerRight f T := ofHom (map f.hom (.id _ _))
tensorHom f g := ofHom (map f.hom g.hom)
tensorUnit := .of R R
associator _ _ _ := isoMk (assoc R R _ _ _)
leftUnitor _ := isoMk (lid R _)
rightUnitor _ := isoMk (rid R R _)
@[simp] lemma coe_tensorUnit : 𝟙_ (CommAlgCat.{u} R) = R := rfl
@[simp] lemma coe_tensorObj : A ⊗ B = A ⊗[R] B := rfl
variable {A B}
@[simp] lemma tensorHom_hom (f : A ⟶ C) (g : B ⟶ D) : (f ⊗ₘ g).hom = map f.hom g.hom := rfl
variable (C) in
@[simp] lemma whiskerRight_hom (f : A ⟶ B) : (f ▷ C).hom = map f.hom (.id _ _) := rfl
variable (C) in
@[simp] lemma whiskerLeft_hom (f : A ⟶ B) : (C ◁ f).hom = map (.id _ _) f.hom := rfl
variable (A B C) in
@[simp] lemma associator_hom_hom : (α_ A B C).hom.hom = (assoc R R A B C).toAlgHom := rfl
variable (A B C) in
@[simp] lemma associator_inv_hom : (α_ A B C).inv.hom = (assoc R R A B C).symm.toAlgHom := rfl
instance : BraidedCategory (CommAlgCat.{u} R) where
braiding S T := isoMk (comm R _ _)
braiding_naturality_right := by intros; ext : 1; dsimp; ext <;> rfl
braiding_naturality_left := by intros; ext : 1; dsimp; ext <;> rfl
hexagon_forward S T U := by ext : 1; dsimp; ext <;> rfl
hexagon_reverse S T U := by ext : 1; dsimp; ext <;> rfl
variable (A B) in
@[simp] lemma braiding_hom_hom : (β_ A B).hom.hom = (comm R A B).toAlgHom := rfl
variable (A B) in
@[simp] lemma braiding_inv_hom : (β_ A B).inv.hom = (comm R B A).toAlgHom := rfl
attribute [local ext] Quiver.Hom.unop_inj in
instance : CartesianMonoidalCategory (CommAlgCat.{u} R)ᵒᵖ where
isTerminalTensorUnit := terminalOpOfInitial isInitialSelf
fst := _
snd := _
tensorProductIsBinaryProduct S T := BinaryCofan.IsColimit.op <| binaryCofanIsColimit S.unop T.unop
fst_def S T := by ext x; change x ⊗ₜ 1 = x ⊗ₜ algebraMap R T.unop 1; simp
snd_def S T := by ext x; change 1 ⊗ₜ x = algebraMap R S.unop 1 ⊗ₜ x; simp
variable {A B C D : (CommAlgCat.{u} R)ᵒᵖ}
@[simp] lemma fst_unop_hom (A B : (CommAlgCat.{u} R)ᵒᵖ) : (fst A B).unop.hom = includeLeft := rfl
@[simp] lemma snd_unop_hom (A B : (CommAlgCat.{u} R)ᵒᵖ) : (snd A B).unop.hom = includeRight := rfl
variable (A B) in
@[simp] lemma toUnit_unop_hom : (toUnit A).unop.hom = Algebra.ofId R A.unop := rfl
@[simp] lemma lift_unop_hom (f : C ⟶ A) (g : C ⟶ B) :
(lift f g).unop.hom = lift f.unop.hom g.unop.hom fun _ _ ↦ .all _ _ := rfl
end CommAlgCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/CommAlgCat/Basic.lean | import Mathlib.Algebra.Category.AlgCat.Basic
import Mathlib.Algebra.Category.Ring.Under.Basic
import Mathlib.CategoryTheory.Limits.Over
import Mathlib.CategoryTheory.WithTerminal.Cone
/-!
# The category of commutative algebras over a commutative ring
This file defines the bundled category `CommAlgCat` of commutative algebras over a fixed commutative
ring `R` along with the forgetful functors to `CommRingCat` and `AlgCat`.
-/
open CategoryTheory Limits
universe w v u
variable {R : Type u} [CommRing R]
variable (R) in
/-- The category of R-algebras and their morphisms. -/
structure CommAlgCat where
private mk ::
/-- The underlying type. -/
carrier : Type v
[commRing : CommRing carrier]
[algebra : Algebra R carrier]
namespace CommAlgCat
variable {A B C : CommAlgCat.{v} R} {X Y Z : Type v} [CommRing X] [Algebra R X]
[CommRing Y] [Algebra R Y] [CommRing Z] [Algebra R Z]
attribute [instance] commRing algebra
initialize_simps_projections CommAlgCat (-commRing, -algebra)
instance : CoeSort (CommAlgCat R) (Type v) := ⟨carrier⟩
attribute [coe] carrier
variable (R) in
/-- The object in the category of R-algebras associated to a type equipped with the appropriate
typeclasses. This is the preferred way to construct a term of `CommAlgCat R`. -/
abbrev of (X : Type v) [CommRing X] [Algebra R X] : CommAlgCat.{v} R := ⟨X⟩
variable (R) in
lemma coe_of (X : Type v) [CommRing X] [Algebra R X] : (of R X : Type v) = X := rfl
/-- The type of morphisms in `CommAlgCat R`. -/
@[ext]
structure Hom (A B : CommAlgCat.{v} R) where
private mk ::
/-- The underlying algebra map. -/
hom' : A →ₐ[R] B
instance : Category (CommAlgCat.{v} R) where
Hom A B := Hom A B
id A := ⟨AlgHom.id R A⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
instance : ConcreteCategory (CommAlgCat.{v} R) (· →ₐ[R] ·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `CommAlgCat` back into an `AlgHom`. -/
abbrev Hom.hom (f : Hom A B) := ConcreteCategory.hom (C := CommAlgCat R) f
/-- Typecheck an `AlgHom` as a morphism in `CommAlgCat`. -/
abbrev ofHom (f : X →ₐ[R] Y) : of R X ⟶ of R Y := ConcreteCategory.ofHom (C := CommAlgCat R) f
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (A B : CommAlgCat.{v} R) (f : Hom A B) := f.hom
initialize_simps_projections Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[simp] lemma hom_id : (𝟙 A : A ⟶ A).hom = AlgHom.id R A := rfl
/- Provided for rewriting. -/
lemma id_apply (A : CommAlgCat.{v} R) (a : A) : (𝟙 A : A ⟶ A) a = a := by simp
@[simp] lemma hom_comp (f : A ⟶ B) (g : B ⟶ C) : (f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
lemma comp_apply (f : A ⟶ B) (g : B ⟶ C) (a : A) : (f ≫ g) a = g (f a) := by simp
@[ext] lemma hom_ext {f g : A ⟶ B} (hf : f.hom = g.hom) : f = g := Hom.ext hf
@[simp] lemma hom_ofHom (f : X →ₐ[R] Y) : (ofHom f).hom = f := rfl
@[simp] lemma ofHom_hom (f : A ⟶ B) : ofHom f.hom = f := rfl
@[simp] lemma ofHom_id : ofHom (.id R X) = 𝟙 (of R X) := rfl
@[simp]
lemma ofHom_comp (f : X →ₐ[R] Y) (g : Y →ₐ[R] Z) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl
lemma ofHom_apply (f : X →ₐ[R] Y) (x : X) : ofHom f x = f x := rfl
lemma inv_hom_apply (e : A ≅ B) (x : A) : e.inv (e.hom x) = x := by simp
lemma hom_inv_apply (e : A ≅ B) (x : B) : e.hom (e.inv x) = x := by simp
instance : Inhabited (CommAlgCat R) := ⟨of R R⟩
lemma forget_obj (A : CommAlgCat.{v} R) : (forget (CommAlgCat.{v} R)).obj A = A := rfl
lemma forget_map (f : A ⟶ B) : (forget (CommAlgCat.{v} R)).map f = f := rfl
instance : CommRing ((forget (CommAlgCat R)).obj A) := inferInstanceAs <| CommRing A
instance : Algebra R ((forget (CommAlgCat R)).obj A) := inferInstanceAs <| Algebra R A
instance hasForgetToCommRingCat : HasForget₂ (CommAlgCat.{v} R) CommRingCat.{v} where
forget₂.obj A := .of A
forget₂.map f := CommRingCat.ofHom f.hom.toRingHom
instance hasForgetToAlgCat : HasForget₂ (CommAlgCat.{v} R) (AlgCat.{v} R) where
forget₂.obj A := .of R A
forget₂.map f := AlgCat.ofHom f.hom
@[simp] lemma forget₂_commRingCat_obj (A : CommAlgCat.{v} R) :
(forget₂ (CommAlgCat.{v} R) CommRingCat.{v}).obj A = .of A := rfl
@[simp] lemma forget₂_commRingCat_map (f : A ⟶ B) :
(forget₂ (CommAlgCat.{v} R) CommRingCat.{v}).map f = CommRingCat.ofHom f.hom := rfl
@[simp] lemma forget₂_algCat_obj (A : CommAlgCat.{v} R) :
(forget₂ (CommAlgCat.{v} R) (AlgCat.{v} R)).obj A = .of R A := rfl
@[simp] lemma forget₂_algCat_map (f : A ⟶ B) :
(forget₂ (CommAlgCat.{v} R) (AlgCat.{v} R)).map f = AlgCat.ofHom f.hom := rfl
/-- Build an isomorphism in the category `CommAlgCat R` from an `AlgEquiv` between commutative
`Algebra`s. -/
@[simps]
def isoMk {X Y : Type v} {_ : CommRing X} {_ : CommRing Y} {_ : Algebra R X} {_ : Algebra R Y}
(e : X ≃ₐ[R] Y) : of R X ≅ of R Y where
hom := ofHom (e : X →ₐ[R] Y)
inv := ofHom (e.symm : Y →ₐ[R] X)
/-- Build an `AlgEquiv` from an isomorphism in the category `CommAlgCat R`. -/
@[simps]
def algEquivOfIso (i : A ≅ B) : A ≃ₐ[R] B where
__ := i.hom.hom
toFun := i.hom
invFun := i.inv
left_inv x := by simp
right_inv x := by simp
@[deprecated (since := "2025-08-22")] alias ofIso := algEquivOfIso
/-- Algebra equivalences between `Algebra`s are the same as isomorphisms in `CommAlgCat`. -/
@[simps]
def isoEquivAlgEquiv : (of R X ≅ of R Y) ≃ (X ≃ₐ[R] Y) where
toFun := algEquivOfIso
invFun := isoMk
instance reflectsIsomorphisms_forget : (forget (CommAlgCat.{u} R)).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget (CommAlgCat.{u} R)).map f)
let e : X ≃ₐ[R] Y := { f.hom, i.toEquiv with }
exact (isoMk e).isIso_hom
variable (R)
/-- Universe lift functor for commutative algebras. -/
def uliftFunctor : CommAlgCat.{v} R ⥤ CommAlgCat.{max v w} R where
obj A := .of R <| ULift A
map {A B} f := CommAlgCat.ofHom <|
ULift.algEquiv.symm.toAlgHom.comp <| f.hom.comp ULift.algEquiv.toAlgHom
/-- The universe lift functor for commutative algebras is fully faithful. -/
def fullyFaithfulUliftFunctor : (uliftFunctor R).FullyFaithful where
preimage {A B} f :=
CommAlgCat.ofHom <| ULift.algEquiv.toAlgHom.comp <| f.hom.comp ULift.algEquiv.symm.toAlgHom
instance : (uliftFunctor R).Full :=
(fullyFaithfulUliftFunctor R).full
instance : (uliftFunctor R).Faithful :=
(fullyFaithfulUliftFunctor R).faithful
end CommAlgCat
/-- The category of commutative algebras over a commutative ring `R` is the same as commutative
rings under `R`. -/
@[simps]
def commAlgCatEquivUnder (R : CommRingCat) : CommAlgCat R ≌ Under R where
functor.obj A := R.mkUnder A
functor.map {A B} f := f.hom.toUnder
inverse.obj A := .of _ A
inverse.map {A B} f := CommAlgCat.ofHom <| CommRingCat.toAlgHom f
unitIso := NatIso.ofComponents fun A ↦
CommAlgCat.isoMk { toRingEquiv := .refl A, commutes' _ := rfl }
counitIso := .refl _
-- TODO: Generalize to `UnivLE.{u, v}` once `commAlgCatEquivUnder` is generalized.
instance : HasColimits (CommAlgCat.{u} R) :=
Adjunction.has_colimits_of_equivalence (commAlgCatEquivUnder (.of R)).functor
-- TODO: Generalize to `UnivLE.{u, v}` once `commAlgCatEquivUnder` is generalized.
instance : HasLimits (CommAlgCat.{u} R) :=
Adjunction.has_limits_of_equivalence (commAlgCatEquivUnder (.of R)).functor |
.lake/packages/mathlib/Mathlib/Algebra/Category/CommAlgCat/FiniteType.lean | import Mathlib.Algebra.Category.CommAlgCat.Basic
import Mathlib.CategoryTheory.MorphismProperty.Comma
import Mathlib.RingTheory.FinitePresentation
import Mathlib.RingTheory.RingHomProperties
/-!
# The category of finitely generated `R`-algebras
We define the category of finitely generated `R`-algebras and show it is essentially small.
-/
universe w v u
open CategoryTheory Limits
variable (R : Type u) [CommRing R]
/-- The category of finitely generated `R`-algebras. -/
abbrev FGAlgCat := ObjectProperty.FullSubcategory
fun A : CommAlgCat.{v, u} R ↦ Algebra.FiniteType R A
instance (A : FGAlgCat R) : Algebra.FiniteType R A.1 := A.2
/-- (Implementation detail): A small skeleton of `FGAlgCat`. -/
structure FGAlgCatSkeleton : Type u where
/-- The number of generators. -/
n : ℕ
/-- The defining ideal. -/
I : Ideal (MvPolynomial (Fin n) R)
/-- (Implementation detail): Realisation of a `FGAlgCatSkeleton`. -/
noncomputable def FGAlgCatSkeleton.eval (A : FGAlgCatSkeleton R) : FGAlgCat.{u} R :=
⟨CommAlgCat.of R (MvPolynomial (Fin A.n) R ⧸ A.I), inferInstanceAs <| Algebra.FiniteType _ _⟩
lemma Algebra.FiniteType.exists_fgAlgCatSkeleton (A : Type v) [CommRing A] [Algebra R A]
[h : Algebra.FiniteType R A] :
∃ (P : FGAlgCatSkeleton R), Nonempty (A ≃ₐ[R] P.eval.obj) := by
obtain ⟨n, f, hf⟩ := Algebra.FiniteType.iff_quotient_mvPolynomial''.mp h
exact ⟨⟨n, RingHom.ker f⟩, ⟨(Ideal.quotientKerAlgEquivOfSurjective hf).symm⟩⟩
/-- Universe lift functor for finitely generated algebras. -/
def FGAlgCat.uliftFunctor : FGAlgCat.{v} R ⥤ FGAlgCat.{max v w} R where
obj A := ⟨.of R <| ULift A.1, .equiv inferInstance ULift.algEquiv.symm⟩
map {A B} f := CommAlgCat.ofHom <|
ULift.algEquiv.symm.toAlgHom.comp <| f.hom.comp ULift.algEquiv.toAlgHom
/-- The universe lift functor for finitely generated algebras is fully faithful. -/
def FGAlgCat.fullyFaithfulUliftFunctor : (FGAlgCat.uliftFunctor R).FullyFaithful where
preimage {A B} f :=
CommAlgCat.ofHom <| ULift.algEquiv.toAlgHom.comp <| f.hom.comp ULift.algEquiv.symm.toAlgHom
instance : (FGAlgCat.uliftFunctor R).Full :=
(FGAlgCat.fullyFaithfulUliftFunctor R).full
instance : (FGAlgCat.uliftFunctor R).Faithful :=
(FGAlgCat.fullyFaithfulUliftFunctor R).faithful
/-- The category of finitely generated algebras is essentially small. -/
instance : EssentiallySmall.{u} (FGAlgCat.{v} R) := by
suffices h : EssentiallySmall.{u} (FGAlgCat.{max u v} R) by
exact essentiallySmall_of_fully_faithful (FGAlgCat.uliftFunctor R)
rw [essentiallySmall_iff]
refine ⟨?_, ?_⟩
· let f := toSkeleton ∘ (FGAlgCat.uliftFunctor R).obj ∘ FGAlgCatSkeleton.eval R
refine small_of_surjective (f := f) fun A ↦ ?_
simp only [Function.comp_apply, f, toSkeleton_eq_iff]
obtain ⟨P, ⟨e⟩⟩ := Algebra.FiniteType.exists_fgAlgCatSkeleton R
((fromSkeleton (FGAlgCat R)).obj A).obj
exact ⟨P, ⟨ObjectProperty.isoMk _ (CommAlgCat.isoMk <| ULift.algEquiv.trans e.symm)⟩⟩
· refine ⟨fun A B ↦ ?_⟩
obtain ⟨PA, ⟨eA⟩⟩ := Algebra.FiniteType.exists_fgAlgCatSkeleton R A.obj
obtain ⟨PB, ⟨eB⟩⟩ := Algebra.FiniteType.exists_fgAlgCatSkeleton R B.obj
let f (g : A ⟶ B) (x : PA.eval.obj) : PB.eval.obj := eB (g.hom (eA.symm x))
refine small_of_injective (f := f) fun u v h ↦ ?_
ext a
obtain ⟨a, rfl⟩ := eA.symm.surjective a
exact eB.injective (congr_fun h a)
section Under
open RingHom
/-- The category of finitely generated `R`-algebras is equivalent to the category of
finite type ring homomorphisms from `R`. -/
def FGAlgCat.equivUnder (R : CommRingCat.{u}) :
FGAlgCat R ≌ MorphismProperty.Under (toMorphismProperty FiniteType) ⊤ R where
functor.obj A := ⟨(commAlgCatEquivUnder R).functor.obj A.obj,
(RingHom.finiteType_algebraMap (A := R) (B := A.obj)).mpr A.2⟩
functor.map {A B} f := ⟨(commAlgCatEquivUnder R).functor.map f, trivial, trivial⟩
inverse.obj A := ⟨(commAlgCatEquivUnder R).inverse.obj A.1, A.2⟩
inverse.map {A B} f := (commAlgCatEquivUnder R).inverse.map f.hom
unitIso := NatIso.ofComponents fun A ↦
ObjectProperty.isoMk _ (CommAlgCat.isoMk { toRingEquiv := .refl A.1, commutes' _ := rfl })
counitIso := .refl _
variable {Q : MorphismProperty CommRingCat.{u}}
lemma essentiallySmall_of_le (hQ : Q ≤ toMorphismProperty FiniteType) (R : CommRingCat.{u}) :
EssentiallySmall.{u} (MorphismProperty.Under Q ⊤ R) :=
essentiallySmall_of_fully_faithful
(MorphismProperty.Comma.changeProp _ _ hQ
le_rfl le_rfl ⋙ (FGAlgCat.equivUnder R).inverse)
end Under |
.lake/packages/mathlib/Mathlib/Algebra/Category/ContinuousCohomology/Basic.lean | import Mathlib.Algebra.Category.ModuleCat.Topology.Homology
import Mathlib.Algebra.Homology.Embedding.Restriction
import Mathlib.Algebra.Homology.Functor
import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex
import Mathlib.CategoryTheory.Action.Limits
import Mathlib.Topology.ContinuousMap.Algebra
/-!
# Continuous cohomology
We define continuous cohomology as the homology of homogeneous cochains.
## Implementation details
We define homogeneous cochains as `g`-invariant continuous function in `C(G, C(G,...,C(G, M)))`
instead of the usual `C(Gⁿ, M)` to allow more general topological groups other than locally compact
ones. For this to work, we also work in `Action (TopModuleCat R) G`, where the `G` action on `M`
is only continuous on `M`, and not necessarily continuous in both variables, because the `G` action
on `C(G, M)` might not be continuous on both variables even if it is on `M`.
For the differential map, instead of a finite sum we use the inductive definition
`d₋₁ : M → C(G, M) := const : m ↦ g ↦ m` and
`dₙ₊₁ : C(G, _) → C(G, C(G, _)) := const - C(G, dₙ) : f ↦ g ↦ f - dₙ (f (g))`
See `ContinuousCohomology.MultiInd.d`.
## Main definition
- `ContinuousCohomology.homogeneousCochains`:
The functor taking an `R`-linear `G`-representation to the complex of homogeneous cochains.
- `continuousCohomology`:
The functor taking an `R`-linear `G`-representation to its `n`-th continuous cohomology.
## TODO
- Show that it coincides with `groupCohomology` for discrete groups.
- Give the usual description of cochains in terms of `n`-ary functions for locally compact groups.
- Show that short exact sequences induce long exact sequences in certain scenarios.
-/
open CategoryTheory Functor ContinuousMap
variable (R G : Type*) [CommRing R] [Group G] [TopologicalSpace R]
namespace ContinuousCohomology
variable [TopologicalSpace G] [IsTopologicalGroup G]
variable {R G} in
/-- The `G` representation `C(G, rep)` given a representation `rep`.
The `G` action is defined by `g • f := x ↦ g • f (g⁻¹ * x)`. -/
abbrev Iobj (rep : Action (TopModuleCat R) G) : Action (TopModuleCat R) G where
V := .of R C(G, rep.V)
ρ :=
{ toFun g := TopModuleCat.ofHom
{ toFun f := .comp (rep.ρ g).hom (f.comp (Homeomorph.mulLeft g⁻¹))
map_add' _ _ := by ext; simp
map_smul' _ _ := by ext; simp
cont := (continuous_postcomp _).comp (continuous_precomp _) }
map_one' := ConcreteCategory.ext (by ext; simp)
map_mul' _ _ := ConcreteCategory.ext (by ext; simp [mul_assoc]) }
lemma Iobj_ρ_apply (rep : Action (TopModuleCat R) G) (g f x) :
((Iobj rep).ρ g).hom f x = (rep.ρ g).hom (f (g⁻¹ * x)) := rfl
/-- The functor taking a representation `rep` to the representation `C(G, rep)`. -/
@[simps]
def I : Action (TopModuleCat R) G ⥤ Action (TopModuleCat R) G where
obj := Iobj
map {M N} φ :=
{ hom := TopModuleCat.ofHom (ContinuousLinearMap.compLeftContinuous _ _ φ.hom.hom)
comm g := by
ext f g'
change (M.ρ g ≫ φ.hom).hom (f (g⁻¹ * g')) = (φ.hom ≫ N.ρ g).hom (f (g⁻¹ * g'))
rw [φ.comm] }
map_id _ := rfl
map_comp _ _ := rfl
instance : (I R G).Additive where
instance : (I R G).Linear R where
/-- The constant function `rep ⟶ C(G, rep)` as a natural transformation. -/
@[simps]
def const : 𝟭 _ ⟶ I R G where
app _ := { hom := TopModuleCat.ofHom (.const _ _), comm _ := rfl }
naturality _ _ _ := rfl
namespace MultiInd
/-- The n-th functor taking `M` to `C(G, C(G,...,C(G, M)))` (with n `G`s).
These functors form a complex, see `MultiInd.complex`. -/
def functor : ℕ → Action (TopModuleCat R) G ⥤ Action (TopModuleCat R) G
| 0 => 𝟭 _
| n + 1 => functor n ⋙ I R G
/-- The differential map in `MultiInd.complex`. -/
def d : ∀ n : ℕ, functor R G n ⟶ functor R G (n + 1)
| 0 => const R G
| n + 1 => whiskerLeft (functor R G (n + 1)) (const R G) - (by exact whiskerRight (d n) (I R G))
lemma d_zero : d R G 0 = const R G := rfl
lemma d_succ (n : ℕ) :
d R G (n + 1) = whiskerLeft (functor R G (n + 1)) (const R G) -
(by exact whiskerRight (d R G n) (I R G)) := rfl
@[reassoc (attr := simp)]
lemma d_comp_d (n : ℕ) :
d R G n ≫ d R G (n + 1) = 0 := by
induction n with
| zero =>
rw [d_succ, Preadditive.comp_sub, sub_eq_zero]
rfl
| succ n ih =>
rw [d_succ R G (n + 1), Preadditive.comp_sub]
nth_rw 2 [d_succ]
rw [Preadditive.sub_comp, ← whiskerRight_comp, ih,
Functor.whiskerRight_zero, sub_zero, sub_eq_zero]
rfl
/-- The complex of functors whose behaviour pointwise takes an `R`-linear `G`-representation `M`
to the complex `M → C(G, M) → ⋯ → C(G, C(G,...,C(G, M))) → ⋯`
The `G`-invariant submodules of it is the homogeneous cochains (shifted by one). -/
def complex : CochainComplex (Action (TopModuleCat R) G ⥤ Action (TopModuleCat R) G) ℕ :=
CochainComplex.of (functor R G) (d R G) (d_comp_d R G)
end MultiInd
/-- The functor taking an `R`-linear `G`-representation to its `G`-invariant submodule. -/
def invariants : Action (TopModuleCat R) G ⥤ TopModuleCat R where
obj M := .of R
{ carrier := { x | ∀ g : G, (M.ρ g).hom x = x }
add_mem' hx hy g := by simp [hx g, hy g]
zero_mem' := by simp
smul_mem' r x hx g := by simp [hx g] : Submodule R M.V }
map f := TopModuleCat.ofHom
{ toLinearMap := f.hom.hom.restrict fun x hx g ↦
congr($(f.comm g) x).symm.trans congr(f.hom.hom $(hx g))
cont := continuous_induced_rng.mpr (f.hom.hom.2.comp continuous_subtype_val) }
instance : (invariants R G).Linear R where
instance : (invariants R G).Additive where
/-- `homogeneousCochains R G` is the functor taking
an `R`-linear `G`-representation to the complex of homogeneous cochains. -/
def homogeneousCochains : Action (TopModuleCat R) G ⥤ CochainComplex (TopModuleCat R) ℕ :=
(MultiInd.complex R G).asFunctor ⋙ (invariants R G).mapHomologicalComplex _ ⋙
(ComplexShape.embeddingUp'Add 1 1).restrictionFunctor _
/-- `continuousCohomology R G n` is the functor taking
an `R`-linear `G`-representation to its `n`-th continuous cohomology. -/
noncomputable
def _root_.continuousCohomology (n : ℕ) : Action (TopModuleCat R) G ⥤ TopModuleCat R :=
homogeneousCochains R G ⋙ HomologicalComplex.homologyFunctor _ _ n
/-- The `0`-homogeneous cochains are isomorphic to `Xᴳ`. -/
def kerHomogeneousCochainsZeroEquiv
(X : Action (TopModuleCat R) G) (n : ℕ) (hn : n = 1) :
LinearMap.ker (((homogeneousCochains R G).obj X).d 0 n).hom ≃L[R] (invariants R G).obj X where
toFun x :=
{ val := DFunLike.coe (F := C(G, _)) x.1.1 1
property g := by
subst hn
obtain ⟨⟨x : C(G, _), hx⟩, hx'⟩ := x
have : (X.ρ g).hom (x (g⁻¹ * 1)) = x 1 := congr(DFunLike.coe (F := C(G, _)) $(hx g) 1)
have hx' : x (g⁻¹ * 1) - x 1 = 0 :=
congr(DFunLike.coe (F := C(G, _)) (DFunLike.coe (F := C(G, _)) ($hx').1 1) (g⁻¹ * 1))
rw [sub_eq_zero] at hx'
exact congr((X.ρ g).hom $hx').symm.trans this }
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun x := by
refine ⟨⟨ContinuousLinearMap.const R _ x.1, fun g ↦ ContinuousMap.ext fun a ↦
by subst hn; exact x.2 g⟩, ?_⟩
subst hn
exact Subtype.ext (ContinuousMap.ext fun a ↦
ContinuousMap.ext fun b ↦ show x.1 - x.1 = (0 : X.V) by simp)
left_inv x := by
subst hn
obtain ⟨⟨x : C(G, _), hx⟩, hx'⟩ := x
refine Subtype.ext (Subtype.ext <| ContinuousMap.ext fun a ↦ ?_)
have hx' : x 1 - x a = 0 :=
congr(DFunLike.coe (F := C(G, _)) (DFunLike.coe (F := C(G, _)) ($hx').1 a) 1)
rwa [sub_eq_zero] at hx'
right_inv _ := rfl
continuous_toFun := continuous_induced_rng.mpr ((continuous_eval_const (F := C(G, _)) 1).comp
(continuous_subtype_val.comp continuous_subtype_val))
continuous_invFun := continuous_induced_rng.mpr
(continuous_induced_rng.mpr ((ContinuousLinearMap.const R G).cont.comp continuous_subtype_val))
open ShortComplex HomologyData in
/-- `H⁰_cont(G, X) ≅ Xᴳ`. -/
noncomputable
def continuousCohomologyZeroIso : (continuousCohomology R G 0) ≅ invariants R G :=
NatIso.ofComponents (fun X ↦ (ofIsLimitKernelFork _ (by simp) _
(TopModuleCat.isLimitKer _)).left.homologyIso ≪≫ TopModuleCat.ofIso
(kerHomogeneousCochainsZeroEquiv R G X _ (by simp))) fun {X Y} f ↦ by
dsimp [continuousCohomology, HomologicalComplex.homologyMap]
rw [Category.assoc, ← Iso.inv_comp_eq]
rw [LeftHomologyData.leftHomologyIso_inv_naturality_assoc, Iso.inv_hom_id_assoc,
← cancel_epi (LeftHomologyData.π _), leftHomologyπ_naturality'_assoc]
rfl
end ContinuousCohomology |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/Instances.lean | import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.RingTheory.Localization.Away.Basic
import Mathlib.RingTheory.LocalRing.RingHom.Basic
/-!
# Ring-theoretic results in terms of categorical language
-/
universe u
open CategoryTheory
instance localization_unit_isIso (R : CommRingCat) :
IsIso (CommRingCat.ofHom <| algebraMap R (Localization.Away (1 : R))) :=
Iso.isIso_hom (IsLocalization.atOne R (Localization.Away (1 : R))).toRingEquiv.toCommRingCatIso
instance localization_unit_isIso' (R : CommRingCat) :
@IsIso CommRingCat _ R _ (CommRingCat.ofHom <| algebraMap R (Localization.Away (1 : R))) := by
cases R
exact localization_unit_isIso _
theorem IsLocalization.epi {R : Type*} [CommRing R] (M : Submonoid R) (S : Type _) [CommRing S]
[Algebra R S] [IsLocalization M S] : Epi (CommRingCat.ofHom <| algebraMap R S) :=
⟨fun _ _ h => CommRingCat.hom_ext <| ringHom_ext M congr(($h).hom)⟩
instance Localization.epi {R : Type*} [CommRing R] (M : Submonoid R) :
Epi (CommRingCat.ofHom <| algebraMap R <| Localization M) :=
IsLocalization.epi M _
instance Localization.epi' {R : CommRingCat} (M : Submonoid R) :
@Epi CommRingCat _ R _ (CommRingCat.ofHom <| algebraMap R <| Localization M :) := by
rcases R with ⟨α, str⟩
exact IsLocalization.epi M _
@[instance]
theorem CommRingCat.isLocalHom_comp {R S T : CommRingCat} (f : R ⟶ S) (g : S ⟶ T)
[IsLocalHom g.hom] [IsLocalHom f.hom] : IsLocalHom (f ≫ g).hom :=
RingHom.isLocalHom_comp _ _
theorem isLocalHom_of_iso {R S : CommRingCat} (f : R ≅ S) : IsLocalHom f.hom.hom :=
{ map_nonunit := fun a ha => by
convert f.inv.hom.isUnit_map ha
simp }
-- see Note [lower instance priority]
@[instance 100]
theorem isLocalHom_of_isIso {R S : CommRingCat} (f : R ⟶ S) [IsIso f] :
IsLocalHom f.hom :=
isLocalHom_of_iso (asIso f) |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/Topology.lean | import Mathlib.Algebra.Category.Ring.Colimits
import Mathlib.Algebra.Category.Ring.Constructions
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.Topology.Algebra.Ring.Basic
/-!
# Topology on `Hom(R, S)`
In this file, we define topology on `Hom(A, R)` for a topological ring `R`,
given by the coarsest topology that makes `f ↦ f x` continuous for all `x : A`.
Alternatively, given a presentation `A = ℤ[xᵢ]/I`,
this is the subspace topology `Hom(A, R) ↪ Hom(ℤ[xᵢ], R) = Rᶥ`.
## Main results
- `CommRingCat.HomTopology.isClosedEmbedding_precomp_of_surjective`:
`Hom(A/I, R)` is a closed subspace of `Hom(A, R)` if `R` is Hausdorff.
- `CommRingCat.HomTopology.mvPolynomialHomeomorph`:
`Hom(A[Xᵢ], R)` is homeomorphic to `Hom(A, R) × Rᶥ`.
- `CommRingCat.HomTopology.isEmbedding_pushout`:
`Hom(B ⊗[A] C, R)` has the subspace topology from `Hom(B, R) × Hom(C, R)`.
-/
universe u v
open CategoryTheory Topology
namespace CommRingCat.HomTopology
variable {R A B C : CommRingCat.{u}} [TopologicalSpace R]
/--
The topology on `Hom(A, R)` for a topological ring `R`, given by the coarsest topology that
makes `f ↦ f x` continuous for all `x : A` (see `continuous_apply`).
Alternatively, given a presentation `A = ℤ[xᵢ]/I`,
this is the subspace topology `Hom(A, R) ↪ Hom(ℤ[xᵢ], R) = Rᶥ` (see `mvPolynomialHomeomorph`).
This is a scoped instance in `CommRingCat.HomTopology`.
-/
scoped instance : TopologicalSpace (A ⟶ R) :=
.induced (fun f ↦ f.hom : _ → A → R) inferInstance
@[fun_prop]
nonrec lemma continuous_apply (x : A) :
Continuous (fun f : A ⟶ R ↦ f.hom x) :=
(continuous_apply x).comp continuous_induced_dom
variable (R A) in
lemma isEmbedding_hom :
IsEmbedding (fun f : A ⟶ R ↦ (f.hom : A → R)) :=
⟨.induced _, fun _ _ e ↦ by ext; rw [e]⟩
@[fun_prop]
lemma continuous_precomp (f : A ⟶ B) :
Continuous ((f ≫ ·) : (B ⟶ R) → (A ⟶ R)) :=
continuous_induced_rng.mpr ((Pi.continuous_precomp f.hom).comp continuous_induced_dom)
/-- If `A ≅ B`, then `Hom(A, R)` is homeomorphic to `Hom(B, R)`. -/
@[simps]
def precompHomeomorph (f : A ≅ B) :
(B ⟶ R) ≃ₜ (A ⟶ R) where
toFun φ := _
invFun φ := _
continuous_toFun := continuous_precomp f.hom
continuous_invFun := continuous_precomp f.inv
left_inv _ := by simp
right_inv _ := by simp
lemma isHomeomorph_precomp (f : A ⟶ B) [IsIso f] :
IsHomeomorph ((f ≫ ·) : (B ⟶ R) → (A ⟶ R)) :=
(precompHomeomorph (asIso f)).isHomeomorph
/-- `Hom(A/I, R)` has the subspace topology of `Hom(A, R)`.
More generally, a surjection `A ⟶ B` gives rise to an embedding `Hom(B, R) ⟶ Hom(A, R)` -/
lemma isEmbedding_precomp_of_surjective
(f : A ⟶ B) (hf : Function.Surjective f) :
Topology.IsEmbedding ((f ≫ ·) : (B ⟶ R) → (A ⟶ R)) := by
refine IsEmbedding.of_comp (continuous_precomp _) (IsInducing.induced _).continuous ?_
suffices IsEmbedding ((· ∘ f.hom) : (B → R) → (A → R)) from
this.comp (.induced (fun f g e ↦ by ext a; exact congr($e a)))
exact Function.Surjective.isEmbedding_comp _ hf
/-- `Hom(A/I, R)` is a closed subspace of `Hom(A, R)` if `R` is T1. -/
lemma isClosedEmbedding_precomp_of_surjective
[T1Space R] (f : A ⟶ B) (hf : Function.Surjective f) :
Topology.IsClosedEmbedding ((f ≫ ·) : (B ⟶ R) → (A ⟶ R)) := by
refine ⟨isEmbedding_precomp_of_surjective f hf, ?_⟩
have : IsClosed (⋂ i : RingHom.ker f.hom, { f : A ⟶ R | f i = 0 }) :=
isClosed_iInter fun x ↦ (isClosed_singleton (x := 0)).preimage (continuous_apply (R := R) x.1)
convert this
ext x
simp only [Set.mem_range, Set.mem_iInter, Set.mem_setOf_eq, Subtype.forall, RingHom.mem_ker]
constructor
· rintro ⟨g, rfl⟩ a ha; simp [ha]
· exact fun H ↦ ⟨CommRingCat.ofHom (RingHom.liftOfSurjective f.hom hf ⟨x.hom, H⟩),
by ext; simp [RingHom.liftOfRightInverse_comp_apply]⟩
/-- `Hom(A[Xᵢ], R)` is homeomorphic to `Hom(A, R) × Rⁱ`. -/
@[simps! apply_fst apply_snd symm_apply_hom]
noncomputable
def mvPolynomialHomeomorph (σ : Type v) (R A : CommRingCat.{max u v})
[TopologicalSpace R] [IsTopologicalRing R] :
(CommRingCat.of (MvPolynomial σ A) ⟶ R) ≃ₜ ((A ⟶ R) × (σ → R)) where
toFun f := ⟨CommRingCat.ofHom MvPolynomial.C ≫ f, fun i ↦ f (.X i)⟩
invFun fx := CommRingCat.ofHom (MvPolynomial.eval₂Hom fx.1.hom fx.2)
left_inv f := by ext <;> simp
right_inv fx := by ext <;> simp
continuous_toFun := by fun_prop
continuous_invFun := by
refine continuous_induced_rng.mpr ?_
refine continuous_pi fun p ↦ ?_
simp only [Function.comp_apply, hom_ofHom, MvPolynomial.coe_eval₂Hom, MvPolynomial.eval₂_eq]
fun_prop
open Limits
variable (R A) in
lemma isClosedEmbedding_hom [IsTopologicalRing R] [T1Space R] :
IsClosedEmbedding (fun f : A ⟶ R ↦ (f.hom : A → R)) := by
let f : CommRingCat.of (MvPolynomial A (⊥_ CommRingCat)) ⟶ A :=
CommRingCat.ofHom (MvPolynomial.eval₂Hom (initial.to A).hom id)
have : Function.Surjective f := Function.LeftInverse.surjective (g := .X) fun x ↦ by simp [f]
convert ((mvPolynomialHomeomorph A R (.of _)).trans
(.uniqueProd (⊥_ CommRingCat ⟶ R) _)).isClosedEmbedding.comp
(isClosedEmbedding_precomp_of_surjective f this) using 2 with g
ext x
simp [f]
instance [T2Space R] : T2Space (A ⟶ R) :=
(isEmbedding_hom R A).t2Space
instance [IsTopologicalRing R] [T1Space R] [CompactSpace R] :
CompactSpace (A ⟶ R) :=
(isClosedEmbedding_hom R A).compactSpace
open Limits
/-- `Hom(B ⊗[A] C, R)` has the subspace topology from `Hom(B, R) × Hom(C, R)`. -/
lemma isEmbedding_pushout [IsTopologicalRing R] (φ : A ⟶ B) (ψ : A ⟶ C) :
IsEmbedding fun f : pushout φ ψ ⟶ R ↦ (pushout.inl φ ψ ≫ f, pushout.inr φ ψ ≫ f) := by
-- The key idea: Let `X = Spec B` and `Y = Spec C`.
-- We want to show `(X × Y)(R)` has the subspace topology from `X(R) × Y(R)`.
-- We already know that `X(R) × Y(R)` is a subspace of `𝔸ᴮ(R) × 𝔸ᶜ(R)` and by explicit calculation
-- this is isomorphic to `𝔸ᴮ⁺ᶜ(R)` which `(X × Y)(R)` embeds into.
let PB := CommRingCat.of (MvPolynomial B A)
let PC := CommRingCat.of (MvPolynomial C A)
let fB : PB ⟶ B := CommRingCat.ofHom (MvPolynomial.eval₂Hom φ.hom id)
have hfB : Function.Surjective fB.hom := fun x ↦ ⟨.X x, by simp [PB, fB]⟩
let fC : PC ⟶ C := CommRingCat.ofHom (MvPolynomial.eval₂Hom ψ.hom id)
have hfC : Function.Surjective fC.hom := fun x ↦ ⟨.X x, by simp [PC, fC]⟩
have := (isEmbedding_precomp_of_surjective (R := R) fB hfB).prodMap
(isEmbedding_precomp_of_surjective (R := R) fC hfC)
rw [← IsEmbedding.of_comp_iff this]
let PBC := CommRingCat.of (MvPolynomial (B ⊕ C) A)
let fBC : PBC ⟶ pushout φ ψ :=
CommRingCat.ofHom (MvPolynomial.eval₂Hom (φ ≫ pushout.inl φ ψ).hom
(Sum.elim (pushout.inl φ ψ).hom (pushout.inr φ ψ).hom))
have hfBC : Function.Surjective fBC := by
rw [← RingHom.range_eq_top, ← top_le_iff,
← closure_range_union_range_eq_top_of_isPushout (.of_hasPushout _ _), Subring.closure_le]
simp only [Set.union_subset_iff, RingHom.coe_range, Set.range_subset_iff, Set.mem_range]
exact ⟨fun x ↦ ⟨.X (.inl x), by simp [fBC, PBC]⟩, fun x ↦ ⟨.X (.inr x), by simp [fBC, PBC]⟩⟩
let F : ((A ⟶ R) × ((B ⊕ C) → R)) → ((A ⟶ R) × (B → R)) × ((A ⟶ R) × (C → R)) :=
fun x ↦ ⟨⟨x.1, x.2 ∘ Sum.inl⟩, ⟨x.1, x.2 ∘ Sum.inr⟩⟩
have hF : IsEmbedding F := (Homeomorph.prodProdProdComm _ _ _ _).isEmbedding.comp
((isEmbedding_graph continuous_id).prodMap Homeomorph.sumArrowHomeomorphProdArrow.isEmbedding)
have H := (mvPolynomialHomeomorph B R A).symm.isEmbedding.prodMap
(mvPolynomialHomeomorph C R A).symm.isEmbedding
convert ((H.comp hF).comp (mvPolynomialHomeomorph _ R A).isEmbedding).comp
(isEmbedding_precomp_of_surjective (R := R) fBC hfBC)
have (s : _) : (pushout.inr φ ψ).hom (ψ.hom s) = (pushout.inl φ ψ).hom (φ.hom s) :=
congr($(pushout.condition (f := φ)).hom s).symm
ext f s <;> simp [fB, fC, fBC, PB, PC, PBC, F, this]
end CommRingCat.HomTopology |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/LinearAlgebra.lean | import Mathlib.Algebra.Category.Ring.Constructions
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.RingTheory.Flat.FaithfullyFlat.Basic
/-!
# Results on the category of rings requiring linear algebra
## Results
- `CommRingCat.nontrivial_of_isPushout_of_isField`: the pushout of non-trivial rings over a field
is non-trivial.
-/
universe u
open CategoryTheory Limits TensorProduct
namespace CommRingCat
lemma nontrivial_of_isPushout_of_isField {A B C D : CommRingCat.{u}}
(hA : IsField A) {f : A ⟶ B} {g : A ⟶ C} {inl : B ⟶ D} {inr : C ⟶ D}
[Nontrivial B] [Nontrivial C]
(h : IsPushout f g inl inr) : Nontrivial D := by
letI : Field A := hA.toField
algebraize [f.hom, g.hom]
let e : D ≅ .of (B ⊗[A] C) :=
IsColimit.coconePointUniqueUpToIso h.isColimit (CommRingCat.pushoutCoconeIsColimit A B C)
let e' : D ≃ B ⊗[A] C := e.commRingCatIsoToRingEquiv.toEquiv
exact e'.nontrivial
end CommRingCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/Basic.lean | import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.Algebra.Ring.Equiv
import Mathlib.Algebra.Ring.PUnit
import Mathlib.CategoryTheory.ConcreteCategory.ReflectsIso
/-!
# Category instances for `Semiring`, `Ring`, `CommSemiring`, and `CommRing`.
We introduce the bundled categories:
* `SemiRingCat`
* `RingCat`
* `CommSemiRingCat`
* `CommRingCat`
along with the relevant forgetful functors between them.
-/
universe u v
open CategoryTheory
/-- The category of semirings. -/
structure SemiRingCat where
/-- The object in the category of semirings associated to a type equipped with the appropriate
typeclasses. -/
of ::
/-- The underlying type. -/
carrier : Type u
[semiring : Semiring carrier]
attribute [instance] SemiRingCat.semiring
initialize_simps_projections SemiRingCat (-semiring)
namespace SemiRingCat
instance : CoeSort (SemiRingCat) (Type u) :=
⟨SemiRingCat.carrier⟩
attribute [coe] SemiRingCat.carrier
lemma coe_of (R : Type u) [Semiring R] : (of R : Type u) = R :=
rfl
lemma of_carrier (R : SemiRingCat.{u}) : of R = R := rfl
variable {R} in
/-- The type of morphisms in `SemiRingCat`. -/
@[ext]
structure Hom (R S : SemiRingCat.{u}) where
private mk ::
/-- The underlying ring hom. -/
hom' : R →+* S
instance : Category SemiRingCat where
Hom R S := Hom R S
id R := ⟨RingHom.id R⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
instance : ConcreteCategory.{u} SemiRingCat (fun R S => R →+* S) where
hom := Hom.hom'
ofHom f := ⟨f⟩
/-- Turn a morphism in `SemiRingCat` back into a `RingHom`. -/
abbrev Hom.hom {R S : SemiRingCat.{u}} (f : Hom R S) :=
ConcreteCategory.hom (C := SemiRingCat) f
/-- Typecheck a `RingHom` as a morphism in `SemiRingCat`. -/
abbrev ofHom {R S : Type u} [Semiring R] [Semiring S] (f : R →+* S) : of R ⟶ of S :=
ConcreteCategory.ofHom (C := SemiRingCat) f
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (R S : SemiRingCat) (f : Hom R S) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[simp]
lemma hom_id {R : SemiRingCat} : (𝟙 R : R ⟶ R).hom = RingHom.id R := rfl
/- Provided for rewriting. -/
lemma id_apply (R : SemiRingCat) (r : R) :
(𝟙 R : R ⟶ R) r = r := by simp
@[simp]
lemma hom_comp {R S T : SemiRingCat} (f : R ⟶ S) (g : S ⟶ T) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
lemma comp_apply {R S T : SemiRingCat} (f : R ⟶ S) (g : S ⟶ T) (r : R) :
(f ≫ g) r = g (f r) := by simp
@[ext]
lemma hom_ext {R S : SemiRingCat} {f g : R ⟶ S} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[simp]
lemma hom_ofHom {R S : Type u} [Semiring R] [Semiring S] (f : R →+* S) : (ofHom f).hom = f := rfl
@[simp]
lemma ofHom_hom {R S : SemiRingCat} (f : R ⟶ S) :
ofHom (Hom.hom f) = f := rfl
@[simp]
lemma ofHom_id {R : Type u} [Semiring R] : ofHom (RingHom.id R) = 𝟙 (of R) := rfl
@[simp]
lemma ofHom_comp {R S T : Type u} [Semiring R] [Semiring S] [Semiring T]
(f : R →+* S) (g : S →+* T) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
lemma ofHom_apply {R S : Type u} [Semiring R] [Semiring S]
(f : R →+* S) (r : R) : ofHom f r = f r := rfl
lemma inv_hom_apply {R S : SemiRingCat} (e : R ≅ S) (r : R) : e.inv (e.hom r) = r := by
simp
lemma hom_inv_apply {R S : SemiRingCat} (e : R ≅ S) (s : S) : e.hom (e.inv s) = s := by
simp
instance : Inhabited SemiRingCat :=
⟨of PUnit⟩
/-- This unification hint helps with problems of the form `(forget ?C).obj R =?= carrier R'`. -/
unif_hint forget_obj_eq_coe (R R' : SemiRingCat) where
R ≟ R' ⊢
(forget SemiRingCat).obj R ≟ SemiRingCat.carrier R'
lemma forget_obj {R : SemiRingCat} : (forget SemiRingCat).obj R = R := rfl
lemma forget_map {R S : SemiRingCat} (f : R ⟶ S) :
(forget SemiRingCat).map f = f :=
rfl
instance {R : SemiRingCat} : Semiring ((forget SemiRingCat).obj R) :=
(inferInstance : Semiring R.carrier)
instance hasForgetToMonCat : HasForget₂ SemiRingCat MonCat where
forget₂ :=
{ obj := fun R ↦ MonCat.of R
map := fun f ↦ MonCat.ofHom f.hom.toMonoidHom }
instance hasForgetToAddCommMonCat : HasForget₂ SemiRingCat AddCommMonCat where
forget₂ :=
{ obj := fun R ↦ AddCommMonCat.of R
map := fun f ↦ AddCommMonCat.ofHom f.hom.toAddMonoidHom }
/-- Ring equivalences are isomorphisms in category of semirings -/
@[simps]
def _root_.RingEquiv.toSemiRingCatIso {R S : Type u} [Semiring R] [Semiring S] (e : R ≃+* S) :
of R ≅ of S where
hom := ofHom e
inv := ofHom e.symm
instance forgetReflectIsos : (forget SemiRingCat).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget SemiRingCat).map f)
let ff : X →+* Y := f.hom
let e : X ≃+* Y := { ff, i.toEquiv with }
exact e.toSemiRingCatIso.isIso_hom
end SemiRingCat
/-- The category of rings. -/
structure RingCat where
/-- The object in the category of rings associated to a type equipped with the appropriate
typeclasses. -/
of ::
/-- The underlying type. -/
carrier : Type u
[ring : Ring carrier]
attribute [instance] RingCat.ring
initialize_simps_projections RingCat (-ring)
namespace RingCat
instance : CoeSort (RingCat) (Type u) :=
⟨RingCat.carrier⟩
attribute [coe] RingCat.carrier
lemma coe_of (R : Type u) [Ring R] : (of R : Type u) = R :=
rfl
lemma of_carrier (R : RingCat.{u}) : of R = R := rfl
variable {R} in
/-- The type of morphisms in `RingCat`. -/
@[ext]
structure Hom (R S : RingCat.{u}) where
private mk ::
/-- The underlying ring hom. -/
hom' : R →+* S
instance : Category RingCat where
Hom R S := Hom R S
id R := ⟨RingHom.id R⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
instance : ConcreteCategory.{u} RingCat (fun R S => R →+* S) where
hom := Hom.hom'
ofHom f := ⟨f⟩
/-- Turn a morphism in `RingCat` back into a `RingHom`. -/
abbrev Hom.hom {R S : RingCat.{u}} (f : Hom R S) :=
ConcreteCategory.hom (C := RingCat) f
/-- Typecheck a `RingHom` as a morphism in `RingCat`. -/
abbrev ofHom {R S : Type u} [Ring R] [Ring S] (f : R →+* S) : of R ⟶ of S :=
ConcreteCategory.ofHom (C := RingCat) f
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (R S : RingCat) (f : Hom R S) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[simp]
lemma hom_id {R : RingCat} : (𝟙 R : R ⟶ R).hom = RingHom.id R := rfl
/- Provided for rewriting. -/
lemma id_apply (R : RingCat) (r : R) :
(𝟙 R : R ⟶ R) r = r := by simp
@[simp]
lemma hom_comp {R S T : RingCat} (f : R ⟶ S) (g : S ⟶ T) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
lemma comp_apply {R S T : RingCat} (f : R ⟶ S) (g : S ⟶ T) (r : R) :
(f ≫ g) r = g (f r) := by simp
@[ext]
lemma hom_ext {R S : RingCat} {f g : R ⟶ S} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[simp]
lemma hom_ofHom {R S : Type u} [Ring R] [Ring S] (f : R →+* S) : (ofHom f).hom = f := rfl
@[simp]
lemma ofHom_hom {R S : RingCat} (f : R ⟶ S) :
ofHom (Hom.hom f) = f := rfl
@[simp]
lemma ofHom_id {R : Type u} [Ring R] : ofHom (RingHom.id R) = 𝟙 (of R) := rfl
@[simp]
lemma ofHom_comp {R S T : Type u} [Ring R] [Ring S] [Ring T]
(f : R →+* S) (g : S →+* T) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
lemma ofHom_apply {R S : Type u} [Ring R] [Ring S]
(f : R →+* S) (r : R) : ofHom f r = f r := rfl
lemma inv_hom_apply {R S : RingCat} (e : R ≅ S) (r : R) : e.inv (e.hom r) = r := by
simp
lemma hom_inv_apply {R S : RingCat} (e : R ≅ S) (s : S) : e.hom (e.inv s) = s := by
simp
instance : Inhabited RingCat :=
⟨of PUnit⟩
/-- This unification hint helps with problems of the form `(forget ?C).obj R =?= carrier R'`.
An example where this is needed is in applying
`PresheafOfModules.Sheafify.app_eq_of_isLocallyInjective`.
-/
unif_hint forget_obj_eq_coe (R R' : RingCat) where
R ≟ R' ⊢
(forget RingCat).obj R ≟ RingCat.carrier R'
lemma forget_obj {R : RingCat} : (forget RingCat).obj R = R := rfl
lemma forget_map {R S : RingCat} (f : R ⟶ S) :
(forget RingCat).map f = f :=
rfl
instance {R : RingCat} : Ring ((forget RingCat).obj R) :=
(inferInstance : Ring R.carrier)
instance hasForgetToSemiRingCat : HasForget₂ RingCat SemiRingCat where
forget₂ :=
{ obj := fun R ↦ SemiRingCat.of R
map := fun f ↦ SemiRingCat.ofHom f.hom }
/-- The forgetful functor from `RingCat` to `SemiRingCat` is fully faithful. -/
def fullyFaithfulForget₂ToSemiRingCat :
(forget₂ RingCat SemiRingCat).FullyFaithful where
preimage f := ofHom f.hom
instance : (forget₂ RingCat SemiRingCat).Full :=
fullyFaithfulForget₂ToSemiRingCat.full
instance hasForgetToAddCommGrp : HasForget₂ RingCat AddCommGrpCat where
forget₂ :=
{ obj := fun R ↦ AddCommGrpCat.of R
map := fun f ↦ AddCommGrpCat.ofHom f.hom.toAddMonoidHom }
/-- Ring equivalences are isomorphisms in category of rings -/
@[simps]
def _root_.RingEquiv.toRingCatIso {R S : Type u} [Ring R] [Ring S] (e : R ≃+* S) :
of R ≅ of S where
hom := ofHom e
inv := ofHom e.symm
instance forgetReflectIsos : (forget RingCat).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget RingCat).map f)
let ff : X →+* Y := f.hom
let e : X ≃+* Y := { ff, i.toEquiv with }
exact e.toRingCatIso.isIso_hom
end RingCat
/-- The category of commutative semirings. -/
structure CommSemiRingCat where
/-- The object in the category of commutative semirings associated to a type equipped with the
appropriate typeclasses. -/
of ::
/-- The underlying type. -/
carrier : Type u
[commSemiring : CommSemiring carrier]
attribute [instance] CommSemiRingCat.commSemiring
initialize_simps_projections CommSemiRingCat (-commSemiring)
namespace CommSemiRingCat
instance : CoeSort (CommSemiRingCat) (Type u) :=
⟨CommSemiRingCat.carrier⟩
attribute [coe] CommSemiRingCat.carrier
lemma coe_of (R : Type u) [CommSemiring R] : (of R : Type u) = R :=
rfl
lemma of_carrier (R : CommSemiRingCat.{u}) : of R = R := rfl
variable {R} in
/-- The type of morphisms in `CommSemiRingCat`. -/
@[ext]
structure Hom (R S : CommSemiRingCat.{u}) where
private mk ::
/-- The underlying ring hom. -/
hom' : R →+* S
instance : Category CommSemiRingCat where
Hom R S := Hom R S
id R := ⟨RingHom.id R⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
instance : ConcreteCategory.{u} CommSemiRingCat (fun R S => R →+* S) where
hom := Hom.hom'
ofHom f := ⟨f⟩
/-- Turn a morphism in `CommSemiRingCat` back into a `RingHom`. -/
abbrev Hom.hom {R S : CommSemiRingCat.{u}} (f : Hom R S) :=
ConcreteCategory.hom (C := CommSemiRingCat) f
/-- Typecheck a `RingHom` as a morphism in `CommSemiRingCat`. -/
abbrev ofHom {R S : Type u} [CommSemiring R] [CommSemiring S] (f : R →+* S) : of R ⟶ of S :=
ConcreteCategory.ofHom (C := CommSemiRingCat) f
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (R S : CommSemiRingCat) (f : Hom R S) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[simp]
lemma hom_id {R : CommSemiRingCat} : (𝟙 R : R ⟶ R).hom = RingHom.id R := rfl
/- Provided for rewriting. -/
lemma id_apply (R : CommSemiRingCat) (r : R) :
(𝟙 R : R ⟶ R) r = r := by simp
@[simp]
lemma hom_comp {R S T : CommSemiRingCat} (f : R ⟶ S) (g : S ⟶ T) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
lemma comp_apply {R S T : CommSemiRingCat} (f : R ⟶ S) (g : S ⟶ T) (r : R) :
(f ≫ g) r = g (f r) := by simp
@[ext]
lemma hom_ext {R S : CommSemiRingCat} {f g : R ⟶ S} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[simp]
lemma hom_ofHom {R S : Type u} [CommSemiring R] [CommSemiring S] (f : R →+* S) :
(ofHom f).hom = f := rfl
@[simp]
lemma ofHom_hom {R S : CommSemiRingCat} (f : R ⟶ S) :
ofHom (Hom.hom f) = f := rfl
@[simp]
lemma ofHom_id {R : Type u} [CommSemiring R] : ofHom (RingHom.id R) = 𝟙 (of R) := rfl
@[simp]
lemma ofHom_comp {R S T : Type u} [CommSemiring R] [CommSemiring S] [CommSemiring T]
(f : R →+* S) (g : S →+* T) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
lemma ofHom_apply {R S : Type u} [CommSemiring R] [CommSemiring S]
(f : R →+* S) (r : R) : ofHom f r = f r := rfl
lemma inv_hom_apply {R S : CommSemiRingCat} (e : R ≅ S) (r : R) : e.inv (e.hom r) = r := by
simp
lemma hom_inv_apply {R S : CommSemiRingCat} (e : R ≅ S) (s : S) : e.hom (e.inv s) = s := by
simp
instance : Inhabited CommSemiRingCat :=
⟨of PUnit⟩
/-- This unification hint helps with problems of the form `(forget ?C).obj R =?= carrier R'`. -/
unif_hint forget_obj_eq_coe (R R' : CommSemiRingCat) where
R ≟ R' ⊢
(forget CommSemiRingCat).obj R ≟ CommSemiRingCat.carrier R'
lemma forget_obj {R : CommSemiRingCat} : (forget CommSemiRingCat).obj R = R := rfl
lemma forget_map {R S : CommSemiRingCat} (f : R ⟶ S) :
(forget CommSemiRingCat).map f = f :=
rfl
instance {R : CommSemiRingCat} : CommSemiring ((forget CommSemiRingCat).obj R) :=
(inferInstance : CommSemiring R.carrier)
instance hasForgetToSemiRingCat : HasForget₂ CommSemiRingCat SemiRingCat where
forget₂ :=
{ obj := fun R ↦ ⟨R⟩
map := fun f ↦ ⟨f.hom⟩ }
/-- The forgetful functor from `CommSemiRingCat` to `SemiRingCat` is fully faithful. -/
def fullyFaithfulForget₂ToSemiRingCat :
(forget₂ CommSemiRingCat SemiRingCat).FullyFaithful where
preimage f := ofHom f.hom
instance : (forget₂ CommSemiRingCat SemiRingCat).Full :=
fullyFaithfulForget₂ToSemiRingCat.full
/-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/
instance hasForgetToCommMonCat : HasForget₂ CommSemiRingCat CommMonCat where
forget₂ :=
{ obj := fun R ↦ CommMonCat.of R
map := fun f ↦ CommMonCat.ofHom f.hom.toMonoidHom }
/-- Ring equivalences are isomorphisms in category of commutative semirings -/
@[simps]
def _root_.RingEquiv.toCommSemiRingCatIso
{R S : Type u} [CommSemiring R] [CommSemiring S] (e : R ≃+* S) :
of R ≅ of S where
hom := ofHom e
inv := ofHom e.symm
instance forgetReflectIsos : (forget CommSemiRingCat).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget CommSemiRingCat).map f)
let ff : X →+* Y := f.hom
let e : X ≃+* Y := { ff, i.toEquiv with }
exact e.toCommSemiRingCatIso.isIso_hom
end CommSemiRingCat
/-- The category of commutative rings. -/
structure CommRingCat where
/-- The object in the category of commutative rings associated to a type equipped with the
appropriate typeclasses. -/
of ::
/-- The underlying type. -/
carrier : Type u
[commRing : CommRing carrier]
attribute [instance] CommRingCat.commRing
initialize_simps_projections CommRingCat (-commRing)
namespace CommRingCat
instance : CoeSort (CommRingCat) (Type u) :=
⟨CommRingCat.carrier⟩
attribute [coe] CommRingCat.carrier
lemma coe_of (R : Type u) [CommRing R] : (of R : Type u) = R :=
rfl
lemma of_carrier (R : CommRingCat.{u}) : of R = R := rfl
variable {R} in
/-- The type of morphisms in `CommRingCat`. -/
@[ext]
structure Hom (R S : CommRingCat.{u}) where
private mk ::
/-- The underlying ring hom. -/
hom' : R →+* S
instance : Category CommRingCat where
Hom R S := Hom R S
id R := ⟨RingHom.id R⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
instance : ConcreteCategory.{u} CommRingCat (fun R S => R →+* S) where
hom := Hom.hom'
ofHom f := ⟨f⟩
/-- The underlying ring hom. -/
abbrev Hom.hom {R S : CommRingCat.{u}} (f : Hom R S) :=
ConcreteCategory.hom (C := CommRingCat) f
/-- Typecheck a `RingHom` as a morphism in `CommRingCat`. -/
abbrev ofHom {R S : Type u} [CommRing R] [CommRing S] (f : R →+* S) : of R ⟶ of S :=
ConcreteCategory.ofHom (C := CommRingCat) f
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (R S : CommRingCat) (f : Hom R S) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[simp]
lemma hom_id {R : CommRingCat} : (𝟙 R : R ⟶ R).hom = RingHom.id R := rfl
/- Provided for rewriting. -/
lemma id_apply (R : CommRingCat) (r : R) :
(𝟙 R : R ⟶ R) r = r := by simp
@[simp]
lemma hom_comp {R S T : CommRingCat} (f : R ⟶ S) (g : S ⟶ T) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
lemma comp_apply {R S T : CommRingCat} (f : R ⟶ S) (g : S ⟶ T) (r : R) :
(f ≫ g) r = g (f r) := by simp
@[ext]
lemma hom_ext {R S : CommRingCat} {f g : R ⟶ S} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[simp]
lemma hom_ofHom {R S : Type u} [CommRing R] [CommRing S] (f : R →+* S) : (ofHom f).hom = f := rfl
@[simp]
lemma ofHom_hom {R S : CommRingCat} (f : R ⟶ S) :
ofHom (Hom.hom f) = f := rfl
@[simp]
lemma ofHom_id {R : Type u} [CommRing R] : ofHom (RingHom.id R) = 𝟙 (of R) := rfl
@[simp]
lemma ofHom_comp {R S T : Type u} [CommRing R] [CommRing S] [CommRing T]
(f : R →+* S) (g : S →+* T) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
lemma ofHom_apply {R S : Type u} [CommRing R] [CommRing S]
(f : R →+* S) (r : R) : ofHom f r = f r := rfl
lemma inv_hom_apply {R S : CommRingCat} (e : R ≅ S) (r : R) : e.inv (e.hom r) = r := by
simp
lemma hom_inv_apply {R S : CommRingCat} (e : R ≅ S) (s : S) : e.hom (e.inv s) = s := by
simp
instance : Inhabited CommRingCat :=
⟨of PUnit⟩
lemma forget_obj {R : CommRingCat} : (forget CommRingCat).obj R = R := rfl
/-- This unification hint helps with problems of the form `(forget ?C).obj R =?= carrier R'`.
An example where this is needed is in applying `TopCat.Presheaf.restrictOpen` to commutative rings.
-/
unif_hint forget_obj_eq_coe (R R' : CommRingCat) where
R ≟ R' ⊢
(forget CommRingCat).obj R ≟ CommRingCat.carrier R'
lemma forget_map {R S : CommRingCat} (f : R ⟶ S) :
(forget CommRingCat).map f = f :=
rfl
instance {R : CommRingCat} : CommRing ((forget CommRingCat).obj R) :=
(inferInstance : CommRing R.carrier)
instance hasForgetToRingCat : HasForget₂ CommRingCat RingCat where
forget₂ :=
{ obj := fun R ↦ RingCat.of R
map := fun f ↦ RingCat.ofHom f.hom }
/-- The forgetful functor from `CommRingCat` to `RingCat` is fully faithful. -/
def fullyFaithfulForget₂ToRingCat :
(forget₂ CommRingCat RingCat).FullyFaithful where
preimage f := ofHom f.hom
instance : (forget₂ CommRingCat RingCat).Full :=
fullyFaithfulForget₂ToRingCat.full
@[simp] lemma forgetToRingCat_map_hom {R S : CommRingCat} (f : R ⟶ S) :
((forget₂ CommRingCat RingCat).map f).hom = f.hom :=
rfl
@[simp] lemma forgetToRingCat_obj {R : CommRingCat} :
(((forget₂ CommRingCat RingCat).obj R) : Type u) = R :=
rfl
instance hasForgetToAddCommMonCat : HasForget₂ CommRingCat CommSemiRingCat where
forget₂ :=
{ obj := fun R ↦ CommSemiRingCat.of R
map := fun f ↦ CommSemiRingCat.ofHom f.hom }
@[simps]
instance : HasForget₂ CommRingCat CommMonCat where
forget₂ := { obj M := .of M, map f := CommMonCat.ofHom f.hom }
forget_comp := rfl
/-- Ring equivalences are isomorphisms in category of commutative rings -/
@[simps]
def _root_.RingEquiv.toCommRingCatIso
{R S : Type u} [CommRing R] [CommRing S] (e : R ≃+* S) :
of R ≅ of S where
hom := ofHom e
inv := ofHom e.symm
instance forgetReflectIsos : (forget CommRingCat).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget CommRingCat).map f)
let ff : X →+* Y := f.hom
let e : X ≃+* Y := { ff, i.toEquiv with }
exact e.toCommRingCatIso.isIso_hom
end CommRingCat
namespace CategoryTheory.Iso
/-- Build a `RingEquiv` from an isomorphism in the category `SemiRingCat`. -/
def semiRingCatIsoToRingEquiv {R S : SemiRingCat.{u}} (e : R ≅ S) : R ≃+* S :=
RingEquiv.ofHomInv e.hom.hom e.inv.hom (by ext; simp) (by ext; simp)
/-- Build a `RingEquiv` from an isomorphism in the category `RingCat`. -/
def ringCatIsoToRingEquiv {R S : RingCat.{u}} (e : R ≅ S) : R ≃+* S :=
RingEquiv.ofHomInv e.hom.hom e.inv.hom (by ext; simp) (by ext; simp)
/-- Build a `RingEquiv` from an isomorphism in the category `CommSemiRingCat`. -/
def commSemiRingCatIsoToRingEquiv {R S : CommSemiRingCat.{u}} (e : R ≅ S) : R ≃+* S :=
RingEquiv.ofHomInv e.hom.hom e.inv.hom (by ext; simp) (by ext; simp)
/-- Build a `RingEquiv` from an isomorphism in the category `CommRingCat`. -/
def commRingCatIsoToRingEquiv {R S : CommRingCat.{u}} (e : R ≅ S) : R ≃+* S :=
RingEquiv.ofHomInv e.hom.hom e.inv.hom (by ext; simp) (by ext; simp)
@[simp] lemma semiRingCatIsoToRingEquiv_toRingHom {R S : SemiRingCat.{u}} (e : R ≅ S) :
(e.semiRingCatIsoToRingEquiv : R →+* S) = e.hom.hom := rfl
@[simp] lemma ringCatIsoToRingEquiv_toRingHom {R S : RingCat.{u}} (e : R ≅ S) :
(e.ringCatIsoToRingEquiv : R →+* S) = e.hom.hom := rfl
@[simp] lemma commSemiRingCatIsoToRingEquiv_toRingHom {R S : CommSemiRingCat.{u}} (e : R ≅ S) :
(e.commSemiRingCatIsoToRingEquiv : R →+* S) = e.hom.hom := rfl
@[simp] lemma commRingCatIsoToRingEquiv_toRingHom {R S : CommRingCat.{u}} (e : R ≅ S) :
(e.commRingCatIsoToRingEquiv : R →+* S) = e.hom.hom := rfl
end CategoryTheory.Iso
lemma RingCat.forget_map_apply {R S : RingCat} (f : R ⟶ S)
(x : (CategoryTheory.forget RingCat).obj R) :
(forget _).map f x = f x :=
rfl
lemma CommRingCat.forget_map_apply {R S : CommRingCat} (f : R ⟶ S)
(x : (CategoryTheory.forget CommRingCat).obj R) :
(forget _).map f x = f x :=
rfl |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/FilteredColimits.lean | import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.Algebra.Category.Grp.FilteredColimits
import Mathlib.Algebra.Ring.ULift
/-!
# The forgetful functor from (commutative) (semi-) rings preserves filtered colimits.
Forgetful functors from algebraic categories usually don't preserve colimits. However, they tend
to preserve _filtered_ colimits.
In this file, we start with a small filtered category `J` and a functor `F : J ⥤ SemiRingCat`.
We show that the colimit of `F ⋙ forget₂ SemiRingCat MonCat` (in `MonCat`)
carries the structure of a semiring, thereby showing that the forgetful functor
`forget₂ SemiRingCat MonCat` preserves filtered colimits.
In particular, this implies that `forget SemiRingCat` preserves filtered colimits.
Similarly for `CommSemiRingCat`, `RingCat` and `CommRingCat`.
-/
universe v u
noncomputable section
open CategoryTheory Limits
open IsFiltered renaming max → max' -- avoid name collision with `_root_.max`.
open AddMonCat.FilteredColimits (colimit_zero_eq colimit_add_mk_eq)
open MonCat.FilteredColimits (colimit_one_eq colimit_mul_mk_eq)
namespace SemiRingCat.FilteredColimits
section
-- We use parameters here, mainly so we can have the abbreviations `R` and `R.mk` below, without
-- passing around `F` all the time.
variable {J : Type v} [SmallCategory J] (F : J ⥤ SemiRingCat.{max v u})
-- This instance is needed below in `colimitSemiring`, during the verification of the
-- semiring axioms.
instance semiringObj (j : J) :
Semiring (((F ⋙ forget₂ SemiRingCat.{max v u} MonCat) ⋙ forget MonCat).obj j) :=
show Semiring (F.obj j) by infer_instance
variable [IsFiltered J]
/-- The colimit of `F ⋙ forget₂ SemiRingCat MonCat` in the category `MonCat`.
In the following, we will show that this has the structure of a semiring.
-/
abbrev R : MonCat.{max v u} :=
MonCat.FilteredColimits.colimit.{v, u} (F ⋙ forget₂ SemiRingCat.{max v u} MonCat)
instance colimitSemiring : Semiring.{max v u} <| R.{v, u} F :=
{ (R.{v, u} F).str,
AddCommMonCat.FilteredColimits.colimitAddCommMonoid.{v, u}
(F ⋙ forget₂ SemiRingCat AddCommMonCat.{max v u}) with
mul_zero := fun x => by
refine Quot.inductionOn x ?_; clear x; intro x
obtain ⟨j, x⟩ := x
erw [colimit_zero_eq _ j, colimit_mul_mk_eq _ ⟨j, _⟩ ⟨j, _⟩ j (𝟙 j) (𝟙 j)]
rw [CategoryTheory.Functor.map_id]
dsimp
rw [mul_zero x]
rfl
zero_mul := fun x => by
refine Quot.inductionOn x ?_; clear x; intro x
obtain ⟨j, x⟩ := x
erw [colimit_zero_eq _ j, colimit_mul_mk_eq _ ⟨j, _⟩ ⟨j, _⟩ j (𝟙 j) (𝟙 j)]
rw [CategoryTheory.Functor.map_id]
dsimp
rw [zero_mul x]
rfl
left_distrib := fun x y z => by
refine Quot.induction_on₃ x y z ?_; clear x y z; intro x y z
obtain ⟨j₁, x⟩ := x; obtain ⟨j₂, y⟩ := y; obtain ⟨j₃, z⟩ := z
let k := IsFiltered.max₃ j₁ j₂ j₃
let f := IsFiltered.firstToMax₃ j₁ j₂ j₃
let g := IsFiltered.secondToMax₃ j₁ j₂ j₃
let h := IsFiltered.thirdToMax₃ j₁ j₂ j₃
erw [colimit_add_mk_eq _ ⟨j₂, _⟩ ⟨j₃, _⟩ k g h, colimit_mul_mk_eq _ ⟨j₁, _⟩ ⟨k, _⟩ k f (𝟙 k),
colimit_mul_mk_eq _ ⟨j₁, _⟩ ⟨j₂, _⟩ k f g, colimit_mul_mk_eq _ ⟨j₁, _⟩ ⟨j₃, _⟩ k f h,
colimit_add_mk_eq _ ⟨k, _⟩ ⟨k, _⟩ k (𝟙 k) (𝟙 k)]
simp only [CategoryTheory.Functor.map_id]
erw [left_distrib (F.map f x) (F.map g y) (F.map h z)]
rfl
right_distrib := fun x y z => by
refine Quot.induction_on₃ x y z ?_; clear x y z; intro x y z
obtain ⟨j₁, x⟩ := x; obtain ⟨j₂, y⟩ := y; obtain ⟨j₃, z⟩ := z
let k := IsFiltered.max₃ j₁ j₂ j₃
let f := IsFiltered.firstToMax₃ j₁ j₂ j₃
let g := IsFiltered.secondToMax₃ j₁ j₂ j₃
let h := IsFiltered.thirdToMax₃ j₁ j₂ j₃
erw [colimit_add_mk_eq _ ⟨j₁, _⟩ ⟨j₂, _⟩ k f g, colimit_mul_mk_eq _ ⟨k, _⟩ ⟨j₃, _⟩ k (𝟙 k) h,
colimit_mul_mk_eq _ ⟨j₁, _⟩ ⟨j₃, _⟩ k f h, colimit_mul_mk_eq _ ⟨j₂, _⟩ ⟨j₃, _⟩ k g h,
colimit_add_mk_eq _ ⟨k, _⟩ ⟨k, _⟩ k (𝟙 k) (𝟙 k)]
simp only [CategoryTheory.Functor.map_id]
erw [right_distrib (F.map f x) (F.map g y) (F.map h z)]
rfl }
/-- The bundled semiring giving the filtered colimit of a diagram. -/
def colimit : SemiRingCat.{max v u} :=
SemiRingCat.of <| R.{v, u} F
/-- The cocone over the proposed colimit semiring. -/
def colimitCocone : Cocone F where
pt := colimit.{v, u} F
ι :=
{ app := fun j => ofHom
{ ((MonCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ SemiRingCat.{max v u} MonCat)).ι.app j).hom,
((AddCommMonCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ SemiRingCat.{max v u} AddCommMonCat)).ι.app j).hom with }
naturality := fun {_ _} f => hom_ext <|
RingHom.coe_inj ((Types.TypeMax.colimitCocone (F ⋙ forget SemiRingCat)).ι.naturality f) }
namespace colimitCoconeIsColimit
variable {F} (t : Cocone F)
/-- Auxiliary definition for `colimitCoconeIsColimit`. -/
def descAddMonoidHom : R F →+ t.1 :=
((AddCommMonCat.FilteredColimits.colimitCoconeIsColimit.{v, u}
(F ⋙ forget₂ SemiRingCat AddCommMonCat)).desc
((forget₂ SemiRingCat AddCommMonCat).mapCocone t)).hom
lemma descAddMonoidHom_quotMk {j : J} (x : F.obj j) :
descAddMonoidHom t (Quot.mk _ ⟨j, x⟩) = t.ι.app j x :=
congr_fun ((forget _).congr_map
((AddCommMonCat.FilteredColimits.colimitCoconeIsColimit.{v, u}
(F ⋙ forget₂ SemiRingCat AddCommMonCat)).fac
((forget₂ SemiRingCat AddCommMonCat).mapCocone t) j)) x
/-- Auxiliary definition for `colimitCoconeIsColimit`. -/
def descMonoidHom : R F →* t.1 :=
((MonCat.FilteredColimits.colimitCoconeIsColimit.{v, u}
(F ⋙ forget₂ _ _)).desc ((forget₂ _ _).mapCocone t)).hom
lemma descMonoidHom_quotMk {j : J} (x : F.obj j) :
descMonoidHom t (Quot.mk _ ⟨j, x⟩) = t.ι.app j x :=
congr_fun ((forget _).congr_map
((MonCat.FilteredColimits.colimitCoconeIsColimit.{v, u}
(F ⋙ forget₂ _ _)).fac ((forget₂ _ _).mapCocone t) j)) x
lemma descMonoidHom_apply_eq (x : R F) :
descMonoidHom t x = descAddMonoidHom t x := by
obtain ⟨j, x⟩ := x
rw [descMonoidHom_quotMk t x, descAddMonoidHom_quotMk t x]
end colimitCoconeIsColimit
open colimitCoconeIsColimit in
/-- The proposed colimit cocone is a colimit in `SemiRingCat`. -/
def colimitCoconeIsColimit : IsColimit <| colimitCocone.{v, u} F where
desc t := ofHom
{ descAddMonoidHom t with
map_one' := (descMonoidHom_apply_eq t 1).symm.trans (by simp)
map_mul' x y := by
change descAddMonoidHom t (x * y) =
descAddMonoidHom t x * descAddMonoidHom t y
simp [← descMonoidHom_apply_eq] }
fac t j := by ext x; exact descAddMonoidHom_quotMk t x
uniq t m hm := by
ext ⟨j, x⟩
exact (congr_fun ((forget _).congr_map (hm j)) x).trans
(descAddMonoidHom_quotMk t x).symm
instance forget₂Mon_preservesFilteredColimits :
PreservesFilteredColimits (forget₂ SemiRingCat MonCat.{u}) where
preserves_filtered_colimits {J hJ1 _} :=
letI : Category J := hJ1
{ preservesColimit := fun {F} =>
preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit.{u, u} F)
(MonCat.FilteredColimits.colimitCoconeIsColimit (F ⋙ forget₂ SemiRingCat MonCat.{u})) }
instance forget_preservesFilteredColimits : PreservesFilteredColimits (forget SemiRingCat.{u}) :=
Limits.comp_preservesFilteredColimits (forget₂ SemiRingCat MonCat) (forget MonCat.{u})
end
end SemiRingCat.FilteredColimits
namespace CommSemiRingCat.FilteredColimits
section
-- We use parameters here, mainly so we can have the abbreviation `R` below, without
-- passing around `F` all the time.
variable {J : Type v} [SmallCategory J] [IsFiltered J] (F : J ⥤ CommSemiRingCat.{max v u})
/-- The colimit of `F ⋙ forget₂ CommSemiRingCat SemiRingCat` in the category `SemiRingCat`.
In the following, we will show that this has the structure of a _commutative_ semiring.
-/
abbrev R : SemiRingCat.{max v u} :=
SemiRingCat.FilteredColimits.colimit (F ⋙ forget₂ CommSemiRingCat SemiRingCat.{max v u})
instance colimitCommSemiring : CommSemiring.{max v u} <| R.{v, u} F :=
{ (R F).semiring,
CommMonCat.FilteredColimits.colimitCommMonoid
(F ⋙ forget₂ CommSemiRingCat CommMonCat.{max v u}) with }
/-- The bundled commutative semiring giving the filtered colimit of a diagram. -/
def colimit : CommSemiRingCat.{max v u} :=
CommSemiRingCat.of <| R.{v, u} F
/-- The cocone over the proposed colimit commutative semiring. -/
def colimitCocone : Cocone F where
pt := colimit.{v, u} F
ι :=
{ app := fun X ↦ ofHom <| ((SemiRingCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ CommSemiRingCat SemiRingCat.{max v u})).ι.app X).hom
naturality := fun _ _ f ↦ hom_ext <|
RingHom.coe_inj ((Types.TypeMax.colimitCocone
(F ⋙ forget CommSemiRingCat)).ι.naturality f) }
/-- The proposed colimit cocone is a colimit in `CommSemiRingCat`. -/
def colimitCoconeIsColimit : IsColimit <| colimitCocone.{v, u} F :=
isColimitOfReflects (forget₂ _ SemiRingCat)
(SemiRingCat.FilteredColimits.colimitCoconeIsColimit
(F ⋙ forget₂ CommSemiRingCat SemiRingCat))
instance forget₂SemiRing_preservesFilteredColimits :
PreservesFilteredColimits (forget₂ CommSemiRingCat SemiRingCat.{u}) where
preserves_filtered_colimits {J hJ1 _} :=
letI : Category J := hJ1
{ preservesColimit := fun {F} =>
preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit.{u, u} F)
(SemiRingCat.FilteredColimits.colimitCoconeIsColimit
(F ⋙ forget₂ CommSemiRingCat SemiRingCat.{u})) }
instance forget_preservesFilteredColimits :
PreservesFilteredColimits (forget CommSemiRingCat.{u}) :=
Limits.comp_preservesFilteredColimits (forget₂ CommSemiRingCat SemiRingCat)
(forget SemiRingCat.{u})
end
end CommSemiRingCat.FilteredColimits
namespace RingCat.FilteredColimits
section
-- We use parameters here, mainly so we can have the abbreviation `R` below, without
-- passing around `F` all the time.
variable {J : Type v} [SmallCategory J] [IsFiltered J] (F : J ⥤ RingCat.{max v u})
/-- The colimit of `F ⋙ forget₂ RingCat SemiRingCat` in the category `SemiRingCat`.
In the following, we will show that this has the structure of a ring.
-/
abbrev R : SemiRingCat.{max v u} :=
SemiRingCat.FilteredColimits.colimit.{v, u} (F ⋙ forget₂ RingCat SemiRingCat.{max v u})
instance colimitRing : Ring.{max v u} <| R.{v, u} F :=
{ (R F).semiring,
AddCommGrpCat.FilteredColimits.colimitAddCommGroup.{v, u}
(F ⋙ forget₂ RingCat AddCommGrpCat.{max v u}) with }
/-- The bundled ring giving the filtered colimit of a diagram. -/
def colimit : RingCat.{max v u} :=
RingCat.of <| R.{v, u} F
/-- The cocone over the proposed colimit ring. -/
def colimitCocone : Cocone F where
pt := colimit.{v, u} F
ι :=
{ app := fun X ↦ ofHom <| ((SemiRingCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ RingCat SemiRingCat.{max v u})).ι.app X).hom
naturality := fun _ _ f ↦ hom_ext <|
RingHom.coe_inj ((Types.TypeMax.colimitCocone (F ⋙ forget RingCat)).ι.naturality f) }
/-- The proposed colimit cocone is a colimit in `Ring`. -/
def colimitCoconeIsColimit : IsColimit <| colimitCocone.{v, u} F :=
isColimitOfReflects (forget₂ _ _)
(SemiRingCat.FilteredColimits.colimitCoconeIsColimit
(F ⋙ forget₂ RingCat SemiRingCat))
instance forget₂SemiRing_preservesFilteredColimits :
PreservesFilteredColimits (forget₂ RingCat SemiRingCat.{u}) where
preserves_filtered_colimits {J hJ1 _} :=
letI : Category J := hJ1
{ preservesColimit := fun {F} =>
preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit.{u, u} F)
(SemiRingCat.FilteredColimits.colimitCoconeIsColimit
(F ⋙ forget₂ RingCat SemiRingCat.{u})) }
instance forget_preservesFilteredColimits : PreservesFilteredColimits (forget RingCat.{u}) :=
Limits.comp_preservesFilteredColimits (forget₂ RingCat SemiRingCat) (forget SemiRingCat.{u})
end
end RingCat.FilteredColimits
namespace CommRingCat.FilteredColimits
section
-- We use parameters here, mainly so we can have the abbreviation `R` below, without
-- passing around `F` all the time.
variable {J : Type v} [SmallCategory J] [IsFiltered J] (F : J ⥤ CommRingCat.{max v u})
/-- The colimit of `F ⋙ forget₂ CommRingCat RingCat` in the category `RingCat`.
In the following, we will show that this has the structure of a _commutative_ ring.
-/
abbrev R : RingCat.{max v u} :=
RingCat.FilteredColimits.colimit.{v, u} (F ⋙ forget₂ CommRingCat RingCat.{max v u})
instance colimitCommRing : CommRing.{max v u} <| R.{v, u} F :=
{ (R.{v, u} F).ring,
CommSemiRingCat.FilteredColimits.colimitCommSemiring
(F ⋙ forget₂ CommRingCat CommSemiRingCat.{max v u}) with }
/-- The bundled commutative ring giving the filtered colimit of a diagram. -/
def colimit : CommRingCat.{max v u} :=
CommRingCat.of <| R.{v, u} F
/-- The cocone over the proposed colimit commutative ring. -/
def colimitCocone : Cocone F where
pt := colimit.{v, u} F
ι :=
{ app := fun X ↦ ofHom <| ((RingCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ CommRingCat RingCat.{max v u})).ι.app X).hom
naturality := fun _ _ f ↦ hom_ext <|
RingHom.coe_inj ((Types.TypeMax.colimitCocone (F ⋙ forget CommRingCat)).ι.naturality f) }
/-- The proposed colimit cocone is a colimit in `CommRingCat`. -/
def colimitCoconeIsColimit : IsColimit <| colimitCocone.{v, u} F :=
isColimitOfReflects (forget₂ _ _)
(RingCat.FilteredColimits.colimitCoconeIsColimit
(F ⋙ forget₂ CommRingCat RingCat))
instance forget₂Ring_preservesFilteredColimits :
PreservesFilteredColimits (forget₂ CommRingCat RingCat.{u}) where
preserves_filtered_colimits {J hJ1 _} :=
letI : Category J := hJ1
{ preservesColimit := fun {F} =>
preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit.{u, u} F)
(RingCat.FilteredColimits.colimitCoconeIsColimit (F ⋙ forget₂ CommRingCat RingCat.{u})) }
instance forget_preservesFilteredColimits : PreservesFilteredColimits (forget CommRingCat.{u}) :=
Limits.comp_preservesFilteredColimits (forget₂ CommRingCat RingCat) (forget RingCat.{u})
omit [IsFiltered J] in
protected lemma nontrivial {F : J ⥤ CommRingCat.{v}} [IsFilteredOrEmpty J]
[∀ i, Nontrivial (F.obj i)] {c : Cocone F} (hc : IsColimit c) : Nontrivial c.pt := by
classical
cases isEmpty_or_nonempty J
· exact ((isColimitEquivIsInitialOfIsEmpty _ _ hc).to (.of (ULift ℤ))).hom.domain_nontrivial
have i := ‹Nonempty J›.some
refine ⟨c.ι.app i 0, c.ι.app i 1, fun h ↦ ?_⟩
have : IsFiltered J := ⟨⟩
obtain ⟨k, f, e⟩ :=
(Types.FilteredColimit.isColimit_eq_iff' (isColimitOfPreserves (forget _) hc) _ _).mp h
exact zero_ne_one (((F.map f).hom.map_zero.symm.trans e).trans (F.map f).hom.map_one)
omit [IsFiltered J] in
instance {F : J ⥤ CommRingCat.{v}} [IsFilteredOrEmpty J]
[HasColimit F] [∀ i, Nontrivial (F.obj i)] : Nontrivial ↑(Limits.colimit F) :=
FilteredColimits.nontrivial (getColimitCocone F).2
end
end CommRingCat.FilteredColimits |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/Constructions.lean | import Mathlib.Algebra.Category.Ring.Instances
import Mathlib.Algebra.Category.Ring.Limits
import Mathlib.Algebra.Category.Ring.Colimits
import Mathlib.Tactic.Algebraize
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq
import Mathlib.CategoryTheory.Limits.Shapes.StrictInitial
import Mathlib.RingTheory.TensorProduct.Basic
import Mathlib.RingTheory.IsTensorProduct
/-!
# Constructions of (co)limits in `CommRingCat`
In this file we provide the explicit (co)cones for various (co)limits in `CommRingCat`, including
* tensor product is the pushout
* tensor product over `ℤ` is the binary coproduct
* `ℤ` is the initial object
* `0` is the strict terminal object
* Cartesian product is the product
* arbitrary direct product of a family of rings is the product object (Pi object)
* `RingHom.eqLocus` is the equalizer
-/
universe u u'
open CategoryTheory Limits TensorProduct
namespace CommRingCat
section Pushout
variable (R A B : Type u) [CommRing R] [CommRing A] [CommRing B]
variable [Algebra R A] [Algebra R B]
/-- The explicit cocone with tensor products as the fibered product in `CommRingCat`. -/
def pushoutCocone : Limits.PushoutCocone
(CommRingCat.ofHom (algebraMap R A)) (CommRingCat.ofHom (algebraMap R B)) := by
fapply Limits.PushoutCocone.mk
· exact CommRingCat.of (A ⊗[R] B)
· exact ofHom <| Algebra.TensorProduct.includeLeftRingHom (A := A)
· exact ofHom <| Algebra.TensorProduct.includeRight.toRingHom (A := B)
· ext r
trans algebraMap R (A ⊗[R] B) r
· exact Algebra.TensorProduct.includeLeft.commutes (R := R) r
· exact (Algebra.TensorProduct.includeRight.commutes (R := R) r).symm
@[simp]
theorem pushoutCocone_inl :
(pushoutCocone R A B).inl = ofHom (Algebra.TensorProduct.includeLeftRingHom (A := A)) :=
rfl
@[simp]
theorem pushoutCocone_inr :
(pushoutCocone R A B).inr = ofHom (Algebra.TensorProduct.includeRight.toRingHom (A := B)) :=
rfl
@[simp]
theorem pushoutCocone_pt :
(pushoutCocone R A B).pt = CommRingCat.of (A ⊗[R] B) :=
rfl
/-- Verify that the `pushout_cocone` is indeed the colimit. -/
def pushoutCoconeIsColimit : Limits.IsColimit (pushoutCocone R A B) :=
Limits.PushoutCocone.isColimitAux' _ fun s => by
letI := RingHom.toAlgebra (s.inl.hom.comp (algebraMap R A))
let f' : A →ₐ[R] s.pt :=
{ s.inl.hom with
commutes' := fun r => rfl }
let g' : B →ₐ[R] s.pt :=
{ s.inr.hom with
commutes' := DFunLike.congr_fun <| congrArg Hom.hom
((s.ι.naturality Limits.WalkingSpan.Hom.snd).trans
(s.ι.naturality Limits.WalkingSpan.Hom.fst).symm) }
letI : Algebra R (pushoutCocone R A B).pt := show Algebra R (A ⊗[R] B) by infer_instance
-- The factor map is a ⊗ b ↦ f(a) * g(b).
use ofHom (AlgHom.toRingHom (Algebra.TensorProduct.productMap f' g'))
simp only [pushoutCocone_inl, pushoutCocone_inr]
constructor
· ext x
exact Algebra.TensorProduct.productMap_left_apply (A := A) _ _ x
constructor
· ext x
exact Algebra.TensorProduct.productMap_right_apply (B := B) _ _ x
intro h eq1 eq2
let h' : A ⊗[R] B →ₐ[R] s.pt :=
{ h.hom with
commutes' := fun r => by
change h (algebraMap R A r ⊗ₜ[R] 1) = s.inl (algebraMap R A r)
rw [← eq1]
simp only [pushoutCocone_pt, coe_of]
rfl }
suffices h' = Algebra.TensorProduct.productMap f' g' by
ext x
change h' x = Algebra.TensorProduct.productMap f' g' x
rw [this]
apply Algebra.TensorProduct.ext'
intro a b
simp only [f', g', ← eq1, pushoutCocone_pt, ← eq2, AlgHom.toRingHom_eq_coe,
Algebra.TensorProduct.productMap_apply_tmul, AlgHom.coe_mk]
change _ = h (a ⊗ₜ 1) * h (1 ⊗ₜ b)
rw [← h.hom.map_mul, Algebra.TensorProduct.tmul_mul_tmul, mul_one, one_mul]
rfl
lemma isPushout_tensorProduct (R A B : Type u) [CommRing R] [CommRing A] [CommRing B]
[Algebra R A] [Algebra R B] :
IsPushout (ofHom <| algebraMap R A) (ofHom <| algebraMap R B)
(ofHom (S := A ⊗[R] B) <| Algebra.TensorProduct.includeLeftRingHom)
(ofHom (S := A ⊗[R] B) <| Algebra.TensorProduct.includeRight.toRingHom) where
w := by
ext
simp
isColimit' := ⟨pushoutCoconeIsColimit R A B⟩
lemma isPushout_of_isPushout (R S A B : Type u) [CommRing R] [CommRing S]
[CommRing A] [CommRing B] [Algebra R S] [Algebra S B] [Algebra R A] [Algebra A B] [Algebra R B]
[IsScalarTower R A B] [IsScalarTower R S B] [Algebra.IsPushout R S A B] :
IsPushout (ofHom (algebraMap R S)) (ofHom (algebraMap R A))
(ofHom (algebraMap S B)) (ofHom (algebraMap A B)) :=
(isPushout_tensorProduct R S A).of_iso (Iso.refl _) (Iso.refl _) (Iso.refl _)
(Algebra.IsPushout.equiv R S A B).toCommRingCatIso (by simp) (by simp)
(by ext; simp [Algebra.IsPushout.equiv_tmul]) (by ext; simp [Algebra.IsPushout.equiv_tmul])
attribute [local instance] Algebra.TensorProduct.rightAlgebra in
lemma isPushout_iff_isPushout {R S : Type u} [CommRing R] [CommRing S] [Algebra R S]
{R' S' : Type u} [CommRing R'] [CommRing S'] [Algebra R R'] [Algebra S S'] [Algebra R' S']
[Algebra R S'] [IsScalarTower R R' S'] [IsScalarTower R S S'] :
IsPushout (ofHom <| algebraMap R R') (ofHom <| algebraMap R S)
(ofHom <| algebraMap R' S') (ofHom <| algebraMap S S') ↔ Algebra.IsPushout R R' S S' := by
refine ⟨fun h ↦ ?_, fun h ↦ isPushout_of_isPushout ..⟩
let e : R' ⊗[R] S ≃+* S' := ((CommRingCat.isPushout_tensorProduct R R' S).isoPushout ≪≫
h.isoPushout.symm).commRingCatIsoToRingEquiv
have h2 (r : R') : (CommRingCat.isPushout_tensorProduct R R' S).isoPushout.hom
(r ⊗ₜ 1) = (pushout.inl (ofHom _) (ofHom _)) r :=
congr($((CommRingCat.isPushout_tensorProduct R R' S).inl_isoPushout_hom).hom r)
have h3 (x : R') := congr($(h.inl_isoPushout_inv) x)
dsimp only [hom_comp, RingHom.coe_comp, Function.comp_apply, hom_ofHom] at h3
let e' : R' ⊗[R] S ≃ₐ[R'] S' := {
__ := e
commutes' r := by simp [Iso.commRingCatIsoToRingEquiv, h2, e, h3] }
refine Algebra.IsPushout.of_equiv e' ?_
ext s
have h1 : (CommRingCat.isPushout_tensorProduct R R' S).isoPushout.hom
(algebraMap S (R' ⊗[R] S) s) = (pushout.inr (ofHom _) (ofHom _)) s :=
congr($((CommRingCat.isPushout_tensorProduct R R' S).inr_isoPushout_hom).hom s)
have h4 (x : S) := congr($(h.inr_isoPushout_inv) x)
dsimp only [hom_comp, RingHom.coe_comp, Function.comp_apply, hom_ofHom] at h4
simp [Iso.commRingCatIsoToRingEquiv, h1, e', e, h4]
lemma closure_range_union_range_eq_top_of_isPushout
{R A B X : CommRingCat.{u}} {f : R ⟶ A} {g : R ⟶ B} {a : A ⟶ X} {b : B ⟶ X}
(H : IsPushout f g a b) :
Subring.closure (Set.range a ∪ Set.range b) = ⊤ := by
algebraize [f.hom, g.hom]
let e := ((isPushout_tensorProduct R A B).isoIsPushout _ _ H).commRingCatIsoToRingEquiv
rw [← Subring.comap_map_eq_self_of_injective e.symm.injective (.closure _), RingHom.map_closure,
← top_le_iff, ← Subring.map_le_iff_le_comap, Set.image_union]
simp only [AlgHom.toRingHom_eq_coe, ← Set.range_comp, ← RingHom.coe_comp]
rw [← hom_comp, ← hom_comp, IsPushout.inl_isoIsPushout_inv, IsPushout.inr_isoIsPushout_inv,
hom_ofHom, hom_ofHom]
exact le_top.trans (Algebra.TensorProduct.closure_range_union_range_eq_top R A B).ge
end Pushout
section BinaryCoproduct
variable (A B : CommRingCat.{u})
/-- The tensor product `A ⊗[ℤ] B` forms a cocone for `A` and `B`. -/
@[simps! pt ι]
def coproductCocone : BinaryCofan A B :=
BinaryCofan.mk
(ofHom (Algebra.TensorProduct.includeLeft (S := ℤ)).toRingHom : A ⟶ of (A ⊗[ℤ] B))
(ofHom (Algebra.TensorProduct.includeRight (R := ℤ)).toRingHom : B ⟶ of (A ⊗[ℤ] B))
@[simp]
theorem coproductCocone_inl :
(coproductCocone A B).inl = ofHom (Algebra.TensorProduct.includeLeft (S := ℤ)).toRingHom := rfl
@[simp]
theorem coproductCocone_inr :
(coproductCocone A B).inr = ofHom (Algebra.TensorProduct.includeRight (R := ℤ)).toRingHom := rfl
/-- The tensor product `A ⊗[ℤ] B` is a coproduct for `A` and `B`. -/
@[simps]
def coproductCoconeIsColimit : IsColimit (coproductCocone A B) where
desc (s : BinaryCofan A B) :=
ofHom (Algebra.TensorProduct.lift s.inl.hom.toIntAlgHom s.inr.hom.toIntAlgHom
(fun _ _ => by apply Commute.all)).toRingHom
fac (s : BinaryCofan A B) := fun ⟨j⟩ => by cases j <;> ext a <;> simp
uniq (s : BinaryCofan A B) := by
rintro ⟨m : A ⊗[ℤ] B →+* s.pt⟩ hm
apply CommRingCat.hom_ext
apply RingHom.toIntAlgHom_injective
apply Algebra.TensorProduct.liftEquiv.symm.injective
apply Subtype.ext
rw [Algebra.TensorProduct.liftEquiv_symm_apply_coe, Prod.mk.injEq]
constructor
· ext a
simp [map_one, mul_one, ←hm (Discrete.mk WalkingPair.left)]
· ext b
simp [map_one, ←hm (Discrete.mk WalkingPair.right)]
/-- The limit cone of the tensor product `A ⊗[ℤ] B` in `CommRingCat`. -/
def coproductColimitCocone : Limits.ColimitCocone (pair A B) :=
⟨_, coproductCoconeIsColimit A B⟩
end BinaryCoproduct
section Terminal
instance (X : CommRingCat.{u}) : Unique (X ⟶ CommRingCat.of.{u} PUnit) :=
⟨⟨ofHom <| ⟨1, rfl, by simp⟩⟩, fun f ↦ by ext⟩
/-- The trivial ring is the (strict) terminal object of `CommRingCat`. -/
def punitIsTerminal : IsTerminal (CommRingCat.of.{u} PUnit) :=
IsTerminal.ofUnique _
instance commRingCat_hasStrictTerminalObjects : HasStrictTerminalObjects CommRingCat.{u} := by
apply hasStrictTerminalObjects_of_terminal_is_strict (CommRingCat.of PUnit)
intro X f
refine ⟨ofHom ⟨1, rfl, by simp⟩, ?_, ?_⟩
· ext
· ext x
have e : (0 : X) = 1 := by
rw [← f.hom.map_one, ← f.hom.map_zero]
replace e : 0 * x = 1 * x := congr_arg (· * x) e
rw [one_mul, zero_mul, ← f.hom.map_zero] at e
exact e
theorem subsingleton_of_isTerminal {X : CommRingCat} (hX : IsTerminal X) : Subsingleton X :=
(hX.uniqueUpToIso punitIsTerminal).commRingCatIsoToRingEquiv.toEquiv.subsingleton_congr.mpr
(show Subsingleton PUnit by infer_instance)
/-- `ℤ` is the initial object of `CommRingCat`. -/
def zIsInitial : IsInitial (CommRingCat.of ℤ) :=
IsInitial.ofUnique (h := fun R => ⟨⟨ofHom <| Int.castRingHom R⟩,
fun a => hom_ext <| a.hom.ext_int _⟩)
/-- `ULift.{u} ℤ` is initial in `CommRingCat`. -/
def isInitial : IsInitial (CommRingCat.of (ULift.{u} ℤ)) :=
IsInitial.ofUnique (h := fun R ↦ ⟨⟨ofHom <| (Int.castRingHom R).comp ULift.ringEquiv.toRingHom⟩,
fun _ ↦ by
ext : 1
rw [← RingHom.cancel_right (f := (ULift.ringEquiv.{0, u} (R := ℤ)).symm.toRingHom)
(hf := ULift.ringEquiv.symm.surjective)]
apply RingHom.ext_int⟩)
end Terminal
section Product
variable (A B : CommRingCat.{u})
/-- The product in `CommRingCat` is the Cartesian product. This is the binary fan. -/
@[simps! pt]
def prodFan : BinaryFan A B :=
BinaryFan.mk (CommRingCat.ofHom <| RingHom.fst A B) (CommRingCat.ofHom <| RingHom.snd A B)
/-- The product in `CommRingCat` is the Cartesian product. -/
def prodFanIsLimit : IsLimit (prodFan A B) where
lift c := ofHom <| RingHom.prod (c.π.app ⟨WalkingPair.left⟩).hom (c.π.app ⟨WalkingPair.right⟩).hom
fac c j := by
ext
rcases j with ⟨⟨⟩⟩ <;>
simp only [pair_obj_left, prodFan_pt, BinaryFan.π_app_left, BinaryFan.π_app_right] <;> rfl
uniq s m h := by
ext x
change m x = (BinaryFan.fst s x, BinaryFan.snd s x)
have eq1 : (m ≫ (A.prodFan B).fst) x = (BinaryFan.fst s) x :=
congr_hom (h ⟨WalkingPair.left⟩) x
have eq2 : (m ≫ (A.prodFan B).snd) x = (BinaryFan.snd s) x :=
congr_hom (h ⟨WalkingPair.right⟩) x
rw [← eq1, ← eq2]
simp [prodFan]
end Product
section Pi
variable {ι : Type u} (R : ι → CommRingCat.{u})
/--
The categorical product of rings is the Cartesian product of rings. This is its `Fan`.
-/
@[simps! pt]
def piFan : Fan R :=
Fan.mk (CommRingCat.of ((i : ι) → R i)) (fun i ↦ ofHom <| Pi.evalRingHom _ i)
/--
The categorical product of rings is the Cartesian product of rings.
-/
def piFanIsLimit : IsLimit (piFan R) where
lift s := ofHom <| Pi.ringHom fun i ↦ (s.π.1 ⟨i⟩).hom
fac s i := by rfl
uniq _ _ h := hom_ext <| DFunLike.ext _ _ fun x ↦ funext fun i ↦
DFunLike.congr_fun (congrArg Hom.hom <| h ⟨i⟩) x
/--
The categorical product and the usual product agree
-/
noncomputable def piIsoPi : ∏ᶜ R ≅ CommRingCat.of ((i : ι) → R i) :=
limit.isoLimitCone ⟨_, piFanIsLimit R⟩
/--
The categorical product and the usual product agree
-/
noncomputable def _root_.RingEquiv.piEquivPi (R : ι → Type u) [∀ i, CommRing (R i)] :
(∏ᶜ (fun i : ι ↦ CommRingCat.of (R i)) : CommRingCat.{u}) ≃+* ((i : ι) → R i) :=
(piIsoPi (CommRingCat.of <| R ·)).commRingCatIsoToRingEquiv
end Pi
section Equalizer
variable {A B : CommRingCat.{u}} (f g : A ⟶ B)
/-- The equalizer in `CommRingCat` is the equalizer as sets. This is the equalizer fork. -/
def equalizerFork : Fork f g :=
Fork.ofι (CommRingCat.ofHom (RingHom.eqLocus f.hom g.hom).subtype) <| by
ext ⟨x, e⟩
simpa using e
/-- The equalizer in `CommRingCat` is the equalizer as sets. -/
def equalizerForkIsLimit : IsLimit (equalizerFork f g) := by
fapply Fork.IsLimit.mk'
intro s
use ofHom <| s.ι.hom.codRestrict _ fun x => (ConcreteCategory.congr_hom s.condition x :)
constructor
· ext
rfl
· intro m hm
ext x
exact Subtype.ext <| RingHom.congr_fun (congrArg Hom.hom hm) x
instance : IsLocalHom (equalizerFork f g).ι.hom := by
constructor
rintro ⟨a, h₁ : _ = _⟩ (⟨⟨x, y, h₃, h₄⟩, rfl : x = _⟩ : IsUnit a)
have : y ∈ RingHom.eqLocus f.hom g.hom := by
apply (f.hom.isUnit_map ⟨⟨x, y, h₃, h₄⟩, rfl⟩ : IsUnit (f x)).mul_left_inj.mp
conv_rhs => rw [h₁]
rw [← f.hom.map_mul, ← g.hom.map_mul, h₄, f.hom.map_one, g.hom.map_one]
rw [isUnit_iff_exists_inv]
exact ⟨⟨y, this⟩, Subtype.eq h₃⟩
@[instance]
theorem equalizer_ι_isLocalHom (F : WalkingParallelPair ⥤ CommRingCat.{u}) :
IsLocalHom (limit.π F WalkingParallelPair.zero).hom := by
have := limMap_π (diagramIsoParallelPair F).hom WalkingParallelPair.zero
rw [← IsIso.comp_inv_eq] at this
rw [← this]
rw [← limit.isoLimitCone_hom_π
⟨_,
equalizerForkIsLimit (F.map WalkingParallelPairHom.left)
(F.map WalkingParallelPairHom.right)⟩
WalkingParallelPair.zero]
change IsLocalHom ((lim.map _ ≫ _ ≫ (equalizerFork _ _).ι) ≫ _).hom
infer_instance
open CategoryTheory.Limits.WalkingParallelPair Opposite
open CategoryTheory.Limits.WalkingParallelPairHom
instance equalizer_ι_isLocalHom' (F : WalkingParallelPairᵒᵖ ⥤ CommRingCat.{u}) :
IsLocalHom (limit.π F (Opposite.op WalkingParallelPair.one)).hom := by
have := limit.isoLimitCone_inv_π
⟨_, IsLimit.whiskerEquivalence (limit.isLimit F) walkingParallelPairOpEquiv⟩
WalkingParallelPair.zero
dsimp at this
rw [← this]
-- note: this was not needed before https://github.com/leanprover-community/mathlib4/pull/19757
have : IsLocalHom (limit.π (walkingParallelPairOp ⋙ F) zero).hom := by infer_instance
infer_instance
end Equalizer
section Pullback
/-- In the category of `CommRingCat`, the pullback of `f : A ⟶ C` and `g : B ⟶ C` is the `eqLocus`
of the two maps `A × B ⟶ C`. This is the constructed pullback cone.
-/
def pullbackCone {A B C : CommRingCat.{u}} (f : A ⟶ C) (g : B ⟶ C) : PullbackCone f g :=
PullbackCone.mk
(CommRingCat.ofHom <|
(RingHom.fst A B).comp
(RingHom.eqLocus (f.hom.comp (RingHom.fst A B)) (g.hom.comp (RingHom.snd A B))).subtype)
(CommRingCat.ofHom <|
(RingHom.snd A B).comp
(RingHom.eqLocus (f.hom.comp (RingHom.fst A B)) (g.hom.comp (RingHom.snd A B))).subtype)
(by
ext ⟨x, e⟩
simpa [CommRingCat.ofHom] using e)
/-- The constructed pullback cone is indeed the limit. -/
def pullbackConeIsLimit {A B C : CommRingCat.{u}} (f : A ⟶ C) (g : B ⟶ C) :
IsLimit (pullbackCone f g) := by
fapply PullbackCone.IsLimit.mk
· intro s
refine ofHom ((s.fst.hom.prod s.snd.hom).codRestrict _ ?_)
intro x
exact congr_arg (fun f : s.pt →+* C => f x) (congrArg Hom.hom s.condition)
· intro s
ext x
rfl
· intro s
ext x
rfl
· intro s m e₁ e₂
refine hom_ext <| RingHom.ext fun (x : s.pt) => Subtype.ext ?_
change (m x).1 = (_, _)
have eq1 := (congr_arg (fun f : s.pt →+* A => f x) (congrArg Hom.hom e₁) :)
have eq2 := (congr_arg (fun f : s.pt →+* B => f x) (congrArg Hom.hom e₂) :)
rw [← eq1, ← eq2]
rfl
end Pullback
end CommRingCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/FinitePresentation.lean | import Mathlib.Algebra.Category.Ring.FilteredColimits
import Mathlib.CategoryTheory.Limits.Preserves.Over
import Mathlib.CategoryTheory.Limits.Shapes.FiniteMultiequalizer
import Mathlib.CategoryTheory.Presentable.Finite
import Mathlib.RingTheory.EssentialFiniteness
import Mathlib.RingTheory.FinitePresentation
/-!
# Finitely presentable objects in `Under R` with `R : CommRingCat`
In this file, we show that finitely presented algebras are finitely presentable in `Under R`,
i.e. `Hom_R(S, -)` preserves filtered colimits.
-/
open CategoryTheory Limits
universe vJ uJ u
variable {J : Type uJ} [Category.{vJ} J] [IsFiltered J]
variable (R : CommRingCat.{u}) (F : J ⥤ CommRingCat.{u}) (α : (Functor.const _).obj R ⟶ F)
variable {S : CommRingCat.{u}} (f : R ⟶ S) (c : Cocone F) (hc : IsColimit c)
variable [PreservesColimit F (forget CommRingCat)]
include hc in
/--
Given a filtered diagram `F` of rings over `R`, `S` an (essentially) of finite type `R`-algebra,
and two ring homs `a : S ⟶ Fᵢ` and `b : S ⟶ Fⱼ` over `R`.
If `a` and `b` agree at `S ⟶ colimit F`,
then there exists `k` such that `a` and `b` are equal at `S ⟶ F_k`.
In other words, the map `colimᵢ Hom_R(S, Fᵢ) ⟶ Hom_R(S, colim F)` is injective.
-/
lemma RingHom.EssFiniteType.exists_comp_map_eq_of_isColimit (hf : f.hom.EssFiniteType)
{i : J} (a : S ⟶ F.obj i) (ha : f ≫ a = α.app i)
{j : J} (b : S ⟶ F.obj j) (hb : f ≫ b = α.app j)
(hab : a ≫ c.ι.app i = b ≫ c.ι.app j) :
∃ (k : J) (hik : i ⟶ k) (hjk : j ⟶ k),
a ≫ F.map hik = b ≫ F.map hjk := by
classical
have hc' := isColimitOfPreserves (forget _) hc
choose k f₁ f₂ h using fun x : S ↦
(Types.FilteredColimit.isColimit_eq_iff _ hc').mp congr(($hab).hom x)
let J' : MulticospanShape := ⟨Unit ⊕ Unit, hf.finset, fun _ ↦ .inl .unit, fun _ ↦ .inr .unit⟩
let D : MulticospanIndex J' J :=
{ left := Sum.elim (fun _ ↦ i) (fun _ ↦ j)
right x := k x.1
fst x := f₁ x
snd x := f₂ x }
obtain ⟨c'⟩ := IsFiltered.cocone_nonempty D.multicospan
refine ⟨c'.pt, c'.ι.app (.left (.inl .unit)), c'.ι.app (.left (.inr .unit)), ?_⟩
ext1
apply hf.ext
· rw [← CommRingCat.hom_comp, ← CommRingCat.hom_comp, reassoc_of% ha, reassoc_of% hb]
simp [← α.naturality]
· intro x hx
rw [← c'.w (.fst (by exact ⟨x, hx⟩)), ← c'.w (.snd (by exact ⟨x, hx⟩))]
have (x : _) : F.map (f₁ x) (a x) = F.map (f₂ x) (b x) := h x
simp [D, this]
include hc in
/--
Given a filtered diagram `F` of rings over `R`, `S` a finitely presented `R`-algebra,
and a ring hom `g : S ⟶ colimit F` over `R`.
then there exists `i` such that `g` factors through `Fᵢ`.
In other words, the map `colimᵢ Hom_R(S, Fᵢ) ⟶ Hom_R(S, colim F)` is surjective.
-/
lemma RingHom.EssFiniteType.exists_eq_comp_ι_app_of_isColimit (hf : f.hom.FinitePresentation)
(g : S ⟶ c.pt) (hg : ∀ i, f ≫ g = α.app i ≫ c.ι.app i) :
∃ (i : J) (g' : S ⟶ F.obj i), f ≫ g' = α.app i ∧ g = g' ≫ c.ι.app i := by
classical
have hc' := isColimitOfPreserves (forget _) hc
letI := f.hom.toAlgebra
obtain ⟨n, hn⟩ := hf
let P := CommRingCat.of (MvPolynomial (Fin n) R)
let iP : R ⟶ P := CommRingCat.ofHom MvPolynomial.C
obtain ⟨π, rfl, hπ, s, hs⟩ :
∃ π : P ⟶ S, iP ≫ π = f ∧ Function.Surjective π ∧ (RingHom.ker π.hom).FG := by
obtain ⟨π, h₁, h₂⟩ := hn
exact ⟨CommRingCat.ofHom π, by ext1; exact π.comp_algebraMap, h₁, h₂⟩
obtain ⟨i, g', hg', hg''⟩ : ∃ (i : J) (g' : P ⟶ F.obj i),
π ≫ g = g' ≫ c.ι.app i ∧ iP ≫ g' = α.app i := by
choose j x h using fun i ↦ Types.jointly_surjective_of_isColimit hc' ((π ≫ g) (.X i))
obtain ⟨i, ⟨hi⟩⟩ : ∃ i, Nonempty (∀ a, (j a ⟶ i)) := by
have : ∃ i, ∀ a, Nonempty (j a ⟶ i) := by
simpa using IsFiltered.sup_objs_exists (Finset.univ.image j)
simpa [← exists_true_iff_nonempty, Classical.skolem, -exists_const_iff] using this
refine ⟨i, CommRingCat.ofHom (MvPolynomial.eval₂Hom
(α.app i).hom (F.map (hi _) <| x ·)), ?_, ?_⟩
· ext1
apply MvPolynomial.ringHom_ext
· simpa using fun x ↦ congr($(hg i).hom x)
· intro i
simp only [CommRingCat.hom_comp, RingHom.coe_comp, Function.comp_apply,
Functor.const_obj_obj, CommRingCat.hom_ofHom, MvPolynomial.coe_eval₂Hom,
MvPolynomial.eval₂_X]
exact (congr($(c.w (hi i)).hom (x i)).trans (h i)).symm
· ext x
simp [P, iP]
have : ∀ r : s, ∃ (i' : J) (hi' : i ⟶ i'), F.map hi' (g' r) = 0 := by
intro r
have := Types.FilteredColimit.isColimit_eq_iff _ hc' (xi := g' r) (j := i) (xj := (0 : F.obj i))
suffices H : (g' ≫ c.ι.app i) r = 0 by
obtain ⟨k, f, g, e⟩ := this.mp (by simpa using H)
exact ⟨k, f, by simpa using e⟩
rw [← hg']
simp [show π r = 0 from hs.le (Ideal.subset_span r.2)]
choose i' hi' hi'' using this
obtain ⟨c'⟩ := IsFiltered.cocone_nonempty (WidePushoutShape.wideSpan i i' hi')
refine ⟨c'.pt, CommRingCat.ofHom (RingHom.liftOfSurjective π.hom hπ
⟨(g' ≫ F.map (c'.ι.app none)).hom, ?_⟩), ?_, ?_⟩
· rw [← hs, Ideal.span_le]
intro r hr
rw [← c'.w (.init ⟨r, hr⟩)]
simp [hi'']
· ext x
suffices (iP ≫ g' ≫ F.map (c'.ι.app none)) x = α.app c'.pt x by
simpa [RingHom.liftOfRightInverse_comp_apply] using this
rw [← Category.assoc, hg'', ← NatTrans.naturality]
simp only [Functor.const_obj_obj, Functor.const_obj_map, Category.id_comp]
· ext x
obtain ⟨x, rfl⟩ := hπ x
suffices (π ≫ g) x = (g' ≫ F.map (c'.ι.app none) ≫ c.ι.app _) x by
simpa [RingHom.liftOfRightInverse_comp_apply, -NatTrans.naturality] using this
rw [c.w, hg']
rfl
/-- If `S` is a finitely presented `R`-algebra, then `Hom_R(S, -)` preserves filtered colimits. -/
lemma preservesColimit_coyoneda_of_finitePresentation
(S : Under R) (hS : S.hom.hom.FinitePresentation) (F : J ⥤ Under R)
[PreservesColimit (F ⋙ Under.forget R) (forget CommRingCat)] :
PreservesColimit F (coyoneda.obj (.op S)) := by
constructor
intro c hc
refine ⟨Types.FilteredColimit.isColimitOf _ _ ?_ ?_⟩
· intro f
obtain ⟨i, g, h₁, h₂⟩ := RingHom.EssFiniteType.exists_eq_comp_ι_app_of_isColimit
R (F ⋙ Under.forget R) { app i := (F.obj i).hom } S.hom ((Under.forget R).mapCocone c)
(PreservesColimit.preserves hc).some hS f.right (by simp)
exact ⟨i, Under.homMk g h₁, Under.UnderMorphism.ext h₂⟩
· intro i j f₁ f₂ e
obtain ⟨k, hik, hjk, e⟩ := RingHom.EssFiniteType.exists_comp_map_eq_of_isColimit
R (F ⋙ Under.forget R) { app i := (F.obj i).hom } S.hom ((Under.forget R).mapCocone c)
(PreservesColimit.preserves hc).some
(RingHom.FiniteType.of_finitePresentation hS).essFiniteType
f₁.right (Under.w f₁) f₂.right (Under.w f₂) congr($(e).right)
exact ⟨k, hik, hjk, Under.UnderMorphism.ext e⟩
/-- If `S` is a finitely presented `R`-algebra, then `Hom_R(S, -)` preserves filtered colimits. -/
lemma preservesFilteredColimits_coyoneda (S : Under R) (hS : S.hom.hom.FinitePresentation) :
PreservesFilteredColimits (coyoneda.obj (.op S)) :=
⟨fun _ _ _ ↦ ⟨preservesColimit_coyoneda_of_finitePresentation R S hS _⟩⟩
/-- If `S` is a finitely presented `R`-algebra, `S : Under R` is finitely presentable. -/
lemma isFinitelyPresentable (S : Under R) (hS : S.hom.hom.FinitePresentation) :
IsFinitelyPresentable.{u} S := by
rw [isFinitelyPresentable_iff_preservesFilteredColimits]
exact preservesFilteredColimits_coyoneda R S hS |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/Colimits.lean | import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.CategoryTheory.Limits.HasLimits
/-!
# The category of commutative rings has all colimits.
This file uses a "pre-automated" approach, just as for
`Mathlib/Algebra/Category/MonCat/Colimits.lean`.
It is a very uniform approach, that conceivably could be synthesised directly
by a tactic that analyses the shape of `CommRing` and `RingHom`.
-/
universe u v
open CategoryTheory Limits
namespace RingCat.Colimits
/-!
We build the colimit of a diagram in `RingCat` by constructing the
free ring on the disjoint union of all the rings in the diagram,
then taking the quotient by the ring laws within each ring,
and the identifications given by the morphisms in the diagram.
-/
variable {J : Type v} [SmallCategory J] (F : J ⥤ RingCat.{v})
/-- An inductive type representing all ring expressions (without Relations)
on a collection of types indexed by the objects of `J`.
-/
inductive Prequotient
-- There's always `of`
| of : ∀ (j : J) (_ : F.obj j), Prequotient
-- Then one generator for each operation
| zero : Prequotient
| one : Prequotient
| neg : Prequotient → Prequotient
| add : Prequotient → Prequotient → Prequotient
| mul : Prequotient → Prequotient → Prequotient
instance : Inhabited (Prequotient F) :=
⟨Prequotient.zero⟩
open Prequotient
/-- The Relation on `Prequotient` saying when two expressions are equal
because of the ring laws, or
because one element is mapped to another by a morphism in the diagram.
-/
inductive Relation : Prequotient F → Prequotient F → Prop -- Make it an equivalence Relation:
| refl : ∀ x, Relation x x
| symm : ∀ (x y) (_ : Relation x y), Relation y x
| trans : ∀ (x y z) (_ : Relation x y) (_ : Relation y z), Relation x z
-- There's always a `map` Relation
| map : ∀ (j j' : J) (f : j ⟶ j') (x : F.obj j),
Relation (Prequotient.of j' (F.map f x))
(Prequotient.of j x)
-- Then one Relation per operation, describing the interaction with `of`
| zero : ∀ j, Relation (Prequotient.of j 0) zero
| one : ∀ j, Relation (Prequotient.of j 1) one
| neg : ∀ (j) (x : F.obj j), Relation (Prequotient.of j (-x)) (neg (Prequotient.of j x))
| add : ∀ (j) (x y : F.obj j), Relation (Prequotient.of j (x + y))
(add (Prequotient.of j x) (Prequotient.of j y))
| mul : ∀ (j) (x y : F.obj j),
Relation (Prequotient.of j (x * y))
(mul (Prequotient.of j x) (Prequotient.of j y))
-- Then one Relation per argument of each operation
| neg_1 : ∀ (x x') (_ : Relation x x'), Relation (neg x) (neg x')
| add_1 : ∀ (x x' y) (_ : Relation x x'), Relation (add x y) (add x' y)
| add_2 : ∀ (x y y') (_ : Relation y y'), Relation (add x y) (add x y')
| mul_1 : ∀ (x x' y) (_ : Relation x x'), Relation (mul x y) (mul x' y)
| mul_2 : ∀ (x y y') (_ : Relation y y'), Relation (mul x y) (mul x y')
-- And one Relation per axiom
| zero_add : ∀ x, Relation (add zero x) x
| add_zero : ∀ x, Relation (add x zero) x
| one_mul : ∀ x, Relation (mul one x) x
| mul_one : ∀ x, Relation (mul x one) x
| neg_add_cancel : ∀ x, Relation (add (neg x) x) zero
| add_comm : ∀ x y, Relation (add x y) (add y x)
| add_assoc : ∀ x y z, Relation (add (add x y) z) (add x (add y z))
| mul_assoc : ∀ x y z, Relation (mul (mul x y) z) (mul x (mul y z))
| left_distrib : ∀ x y z, Relation (mul x (add y z)) (add (mul x y) (mul x z))
| right_distrib : ∀ x y z, Relation (mul (add x y) z) (add (mul x z) (mul y z))
| zero_mul : ∀ x, Relation (mul zero x) zero
| mul_zero : ∀ x, Relation (mul x zero) zero
/-- The setoid corresponding to commutative expressions modulo monoid Relations and identifications.
-/
def colimitSetoid : Setoid (Prequotient F) where
r := Relation F
iseqv := ⟨Relation.refl, Relation.symm _ _, Relation.trans _ _ _⟩
attribute [instance] colimitSetoid
/-- The underlying type of the colimit of a diagram in `CommRingCat`.
-/
def ColimitType : Type v :=
Quotient (colimitSetoid F)
instance ColimitType.instZero : Zero (ColimitType F) where zero := Quotient.mk _ zero
instance ColimitType.instAdd : Add (ColimitType F) where
add := Quotient.map₂ add <| fun _x x' rx y _y' ry =>
Setoid.trans (Relation.add_1 _ _ y rx) (Relation.add_2 x' _ _ ry)
instance ColimitType.instNeg : Neg (ColimitType F) where
neg := Quotient.map neg Relation.neg_1
instance ColimitType.AddGroup : AddGroup (ColimitType F) where
neg := Quotient.map neg Relation.neg_1
zero_add := Quotient.ind <| fun _ => Quotient.sound <| Relation.zero_add _
add_zero := Quotient.ind <| fun _ => Quotient.sound <| Relation.add_zero _
neg_add_cancel := Quotient.ind <| fun _ => Quotient.sound <| Relation.neg_add_cancel _
add_assoc := Quotient.ind <| fun _ => Quotient.ind₂ <| fun _ _ =>
Quotient.sound <| Relation.add_assoc _ _ _
nsmul := nsmulRec
zsmul := zsmulRec
instance InhabitedColimitType : Inhabited <| ColimitType F where
default := 0
instance ColimitType.AddGroupWithOne : AddGroupWithOne (ColimitType F) :=
{ ColimitType.AddGroup F with one := Quotient.mk _ one }
instance : Ring (ColimitType.{v} F) :=
{ ColimitType.AddGroupWithOne F with
mul := Quot.map₂ Prequotient.mul Relation.mul_2 Relation.mul_1
one_mul := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.one_mul _
mul_one := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.mul_one _
add_comm := fun x y => Quot.induction_on₂ x y fun _ _ => Quot.sound <| Relation.add_comm _ _
mul_assoc := fun x y z => Quot.induction_on₃ x y z fun x y z => by
simp only [(· * ·)]
exact Quot.sound (Relation.mul_assoc _ _ _)
mul_zero := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.mul_zero _
zero_mul := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.zero_mul _
left_distrib := fun x y z => Quot.induction_on₃ x y z fun x y z => by
simp only [(· + ·), (· * ·), Add.add]
exact Quot.sound (Relation.left_distrib _ _ _)
right_distrib := fun x y z => Quot.induction_on₃ x y z fun x y z => by
simp only [(· + ·), (· * ·), Add.add]
exact Quot.sound (Relation.right_distrib _ _ _) }
@[simp]
theorem quot_zero : Quot.mk Setoid.r zero = (0 : ColimitType F) :=
rfl
@[simp]
theorem quot_one : Quot.mk Setoid.r one = (1 : ColimitType F) :=
rfl
@[simp]
theorem quot_neg (x : Prequotient F) :
Quot.mk Setoid.r (neg x) = -(show ColimitType F from Quot.mk Setoid.r x) :=
rfl
@[simp]
theorem quot_add (x y) :
Quot.mk Setoid.r (add x y) =
(show ColimitType F from Quot.mk _ x) + (show ColimitType F from Quot.mk _ y) :=
rfl
@[simp]
theorem quot_mul (x y) :
Quot.mk Setoid.r (mul x y) =
(show ColimitType F from Quot.mk _ x) * (show ColimitType F from Quot.mk _ y) :=
rfl
/-- The bundled ring giving the colimit of a diagram. -/
def colimit : RingCat :=
RingCat.of (ColimitType F)
/-- The function from a given ring in the diagram to the colimit ring. -/
def coconeFun (j : J) (x : F.obj j) : ColimitType F :=
Quot.mk _ (Prequotient.of j x)
/-- The ring homomorphism from a given ring in the diagram to the colimit
ring. -/
def coconeMorphism (j : J) : F.obj j ⟶ colimit F := ofHom
{ toFun := coconeFun F j
map_one' := by apply Quot.sound; apply Relation.one
map_mul' := by intros; apply Quot.sound; apply Relation.mul
map_zero' := by apply Quot.sound; apply Relation.zero
map_add' := by intros; apply Quot.sound; apply Relation.add }
@[simp]
theorem cocone_naturality {j j' : J} (f : j ⟶ j') :
F.map f ≫ coconeMorphism F j' = coconeMorphism F j := by
ext
apply Quot.sound
apply Relation.map
@[simp]
theorem cocone_naturality_components (j j' : J) (f : j ⟶ j') (x : F.obj j) :
(coconeMorphism F j') (F.map f x) = (coconeMorphism F j) x := by
rw [← cocone_naturality F f, comp_apply]
/-- The cocone over the proposed colimit ring. -/
def colimitCocone : Cocone F where
pt := colimit F
ι := { app := coconeMorphism F }
/-- The function from the free ring on the diagram to the cone point of any other
cocone. -/
@[simp]
def descFunLift (s : Cocone F) : Prequotient F → s.pt
| Prequotient.of j x => (s.ι.app j) x
| zero => 0
| one => 1
| neg x => -descFunLift s x
| add x y => descFunLift s x + descFunLift s y
| mul x y => descFunLift s x * descFunLift s y
/-- The function from the colimit ring to the cone point of any other cocone. -/
def descFun (s : Cocone F) : ColimitType F → s.pt := by
fapply Quot.lift
· exact descFunLift F s
· intro x y r
induction r with
| refl => rfl
| symm x y _ ih => exact ih.symm
| trans x y z _ _ ih1 ih2 => exact ih1.trans ih2
| map j j' f x => exact RingHom.congr_fun (congrArg Hom.hom <| s.ι.naturality f) x
| zero j => simp
| one j => simp
| neg j x => simp
| add j x y => simp
| mul j x y => simp
| neg_1 x x' r ih => dsimp; rw [ih]
| add_1 x x' y r ih => dsimp; rw [ih]
| add_2 x y y' r ih => dsimp; rw [ih]
| mul_1 x x' y r ih => dsimp; rw [ih]
| mul_2 x y y' r ih => dsimp; rw [ih]
| zero_add x => dsimp; rw [zero_add]
| add_zero x => dsimp; rw [add_zero]
| one_mul x => dsimp; rw [one_mul]
| mul_one x => dsimp; rw [mul_one]
| neg_add_cancel x => dsimp; rw [neg_add_cancel]
| add_comm x y => dsimp; rw [add_comm]
| add_assoc x y z => dsimp; rw [add_assoc]
| mul_assoc x y z => dsimp; rw [mul_assoc]
| left_distrib x y z => dsimp; rw [mul_add]
| right_distrib x y z => dsimp; rw [add_mul]
| zero_mul x => dsimp; rw [zero_mul]
| mul_zero x => dsimp; rw [mul_zero]
/-- The ring homomorphism from the colimit ring to the cone point of any other
cocone. -/
def descMorphism (s : Cocone F) : colimit F ⟶ s.pt := ofHom
{ toFun := descFun F s
map_one' := rfl
map_zero' := rfl
map_add' := fun x y ↦ by
refine Quot.induction_on₂ x y fun a b => ?_
dsimp [descFun]
rw [← quot_add]
rfl
map_mul' := fun x y ↦ by exact Quot.induction_on₂ x y fun a b => rfl }
/-- Evidence that the proposed colimit is the colimit. -/
def colimitIsColimit : IsColimit (colimitCocone F) where
desc s := descMorphism F s
uniq s m w := hom_ext <| RingHom.ext fun x => by
refine Quot.inductionOn x ?_
intro x
induction x with
| zero => simp
| one => simp
| neg x ih => simp [ih]
| of j x =>
exact congr_fun (congr_arg (fun f : F.obj j ⟶ s.pt => (f : F.obj j → s.pt)) (w j)) x
| add x y ih_x ih_y => simp [ih_x, ih_y]
| mul x y ih_x ih_y => simp [ih_x, ih_y]
instance hasColimits_ringCat : HasColimits RingCat where
has_colimits_of_shape _ _ :=
{ has_colimit := fun F =>
HasColimit.mk
{ cocone := colimitCocone F
isColimit := colimitIsColimit F } }
end RingCat.Colimits
-- [ROBOT VOICE]:
-- You should pretend for now that this file was automatically generated.
-- It follows the same template as colimits in Mon.
/-
`#print comm_ring` in Lean 3 used to say:
structure comm_ring : Type u → Type u
fields:
comm_ring.zero : Π (α : Type u) [c : comm_ring α], α
comm_ring.one : Π (α : Type u) [c : comm_ring α], α
comm_ring.neg : Π {α : Type u} [c : comm_ring α], α → α
comm_ring.add : Π {α : Type u} [c : comm_ring α], α → α → α
comm_ring.mul : Π {α : Type u} [c : comm_ring α], α → α → α
comm_ring.zero_add : ∀ {α : Type u} [c : comm_ring α] (a : α), 0 + a = a
comm_ring.add_zero : ∀ {α : Type u} [c : comm_ring α] (a : α), a + 0 = a
comm_ring.one_mul : ∀ {α : Type u} [c : comm_ring α] (a : α), 1 * a = a
comm_ring.mul_one : ∀ {α : Type u} [c : comm_ring α] (a : α), a * 1 = a
comm_ring.add_left_neg : ∀ {α : Type u} [c : comm_ring α] (a : α), -a + a = 0
comm_ring.add_comm : ∀ {α : Type u} [c : comm_ring α] (a b : α), a + b = b + a
comm_ring.mul_comm : ∀ {α : Type u} [c : comm_ring α] (a b : α), a * b = b * a
comm_ring.add_assoc : ∀ {α : Type u} [c : comm_ring α] (a b c_1 : α), a + b + c_1 = a + (b + c_1)
comm_ring.mul_assoc : ∀ {α : Type u} [c : comm_ring α] (a b c_1 : α), a * b * c_1 = a * (b * c_1)
comm_ring.left_distrib : ∀ {α : Type u} [c : comm_ring α] (a b c_1 : α),
a * (b + c_1) = a * b + a * c_1
comm_ring.right_distrib : ∀ {α : Type u} [c : comm_ring α] (a b c_1 : α),
(a + b) * c_1 = a * c_1 + b * c_1
-/
namespace CommRingCat.Colimits
/-!
We build the colimit of a diagram in `CommRingCat` by constructing the
free commutative ring on the disjoint union of all the commutative rings in the diagram,
then taking the quotient by the commutative ring laws within each commutative ring,
and the identifications given by the morphisms in the diagram.
-/
variable {J : Type v} [SmallCategory J] (F : J ⥤ CommRingCat.{v})
/-- An inductive type representing all commutative ring expressions (without Relations)
on a collection of types indexed by the objects of `J`.
-/
inductive Prequotient -- There's always `of`
| of : ∀ (j : J) (_ : F.obj j), Prequotient -- Then one generator for each operation
| zero : Prequotient
| one : Prequotient
| neg : Prequotient → Prequotient
| add : Prequotient → Prequotient → Prequotient
| mul : Prequotient → Prequotient → Prequotient
instance : Inhabited (Prequotient F) :=
⟨Prequotient.zero⟩
open Prequotient
/-- The Relation on `Prequotient` saying when two expressions are equal
because of the commutative ring laws, or
because one element is mapped to another by a morphism in the diagram.
-/
inductive Relation : Prequotient F → Prequotient F → Prop -- Make it an equivalence Relation:
| refl : ∀ x, Relation x x
| symm : ∀ (x y) (_ : Relation x y), Relation y x
| trans : ∀ (x y z) (_ : Relation x y) (_ : Relation y z), Relation x z
-- There's always a `map` Relation
| map : ∀ (j j' : J) (f : j ⟶ j') (x : F.obj j),
Relation (Prequotient.of j' (F.map f x))
(Prequotient.of j x)
-- Then one Relation per operation, describing the interaction with `of`
| zero : ∀ j, Relation (Prequotient.of j 0) zero
| one : ∀ j, Relation (Prequotient.of j 1) one
| neg : ∀ (j) (x : F.obj j), Relation (Prequotient.of j (-x)) (neg (Prequotient.of j x))
| add : ∀ (j) (x y : F.obj j), Relation (Prequotient.of j (x + y))
(add (Prequotient.of j x) (Prequotient.of j y))
| mul : ∀ (j) (x y : F.obj j),
Relation (Prequotient.of j (x * y))
(mul (Prequotient.of j x) (Prequotient.of j y))
-- Then one Relation per argument of each operation
| neg_1 : ∀ (x x') (_ : Relation x x'), Relation (neg x) (neg x')
| add_1 : ∀ (x x' y) (_ : Relation x x'), Relation (add x y) (add x' y)
| add_2 : ∀ (x y y') (_ : Relation y y'), Relation (add x y) (add x y')
| mul_1 : ∀ (x x' y) (_ : Relation x x'), Relation (mul x y) (mul x' y)
| mul_2 : ∀ (x y y') (_ : Relation y y'), Relation (mul x y) (mul x y')
-- And one Relation per axiom
| zero_add : ∀ x, Relation (add zero x) x
| add_zero : ∀ x, Relation (add x zero) x
| one_mul : ∀ x, Relation (mul one x) x
| mul_one : ∀ x, Relation (mul x one) x
| neg_add_cancel : ∀ x, Relation (add (neg x) x) zero
| add_comm : ∀ x y, Relation (add x y) (add y x)
| mul_comm : ∀ x y, Relation (mul x y) (mul y x)
| add_assoc : ∀ x y z, Relation (add (add x y) z) (add x (add y z))
| mul_assoc : ∀ x y z, Relation (mul (mul x y) z) (mul x (mul y z))
| left_distrib : ∀ x y z, Relation (mul x (add y z)) (add (mul x y) (mul x z))
| right_distrib : ∀ x y z, Relation (mul (add x y) z) (add (mul x z) (mul y z))
| zero_mul : ∀ x, Relation (mul zero x) zero
| mul_zero : ∀ x, Relation (mul x zero) zero
/-- The setoid corresponding to commutative expressions modulo monoid Relations and identifications.
-/
def colimitSetoid : Setoid (Prequotient F) where
r := Relation F
iseqv := ⟨Relation.refl, Relation.symm _ _, Relation.trans _ _ _⟩
attribute [instance] colimitSetoid
/-- The underlying type of the colimit of a diagram in `CommRingCat`.
-/
def ColimitType : Type v :=
Quotient (colimitSetoid F)
instance ColimitType.instZero : Zero (ColimitType F) where zero := Quotient.mk _ zero
instance ColimitType.instAdd : Add (ColimitType F) where
add := Quotient.map₂ add <| fun _x x' rx y _y' ry =>
Setoid.trans (Relation.add_1 _ _ y rx) (Relation.add_2 x' _ _ ry)
instance ColimitType.instNeg : Neg (ColimitType F) where
neg := Quotient.map neg Relation.neg_1
instance ColimitType.AddGroup : AddGroup (ColimitType F) where
neg := Quotient.map neg Relation.neg_1
zero_add := Quotient.ind <| fun _ => Quotient.sound <| Relation.zero_add _
add_zero := Quotient.ind <| fun _ => Quotient.sound <| Relation.add_zero _
neg_add_cancel := Quotient.ind <| fun _ => Quotient.sound <| Relation.neg_add_cancel _
add_assoc := Quotient.ind <| fun _ => Quotient.ind₂ <| fun _ _ =>
Quotient.sound <| Relation.add_assoc _ _ _
nsmul := nsmulRec
zsmul := zsmulRec
instance InhabitedColimitType : Inhabited <| ColimitType F where
default := 0
instance ColimitType.AddGroupWithOne : AddGroupWithOne (ColimitType F) :=
{ ColimitType.AddGroup F with one := Quotient.mk _ one }
instance : CommRing (ColimitType.{v} F) :=
{ ColimitType.AddGroupWithOne F with
mul := Quot.map₂ Prequotient.mul Relation.mul_2 Relation.mul_1
one_mul := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.one_mul _
mul_one := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.mul_one _
add_comm := fun x y => Quot.induction_on₂ x y fun _ _ => Quot.sound <| Relation.add_comm _ _
mul_comm := fun x y => Quot.induction_on₂ x y fun _ _ => Quot.sound <| Relation.mul_comm _ _
mul_assoc := fun x y z => Quot.induction_on₃ x y z fun x y z => by
simp only [(· * ·)]
exact Quot.sound (Relation.mul_assoc _ _ _)
mul_zero := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.mul_zero _
zero_mul := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.zero_mul _
left_distrib := fun x y z => Quot.induction_on₃ x y z fun x y z => by
simp only [(· + ·), (· * ·), Add.add]
exact Quot.sound (Relation.left_distrib _ _ _)
right_distrib := fun x y z => Quot.induction_on₃ x y z fun x y z => by
simp only [(· + ·), (· * ·), Add.add]
exact Quot.sound (Relation.right_distrib _ _ _) }
@[simp]
theorem quot_zero : Quot.mk Setoid.r zero = (0 : ColimitType F) :=
rfl
@[simp]
theorem quot_one : Quot.mk Setoid.r one = (1 : ColimitType F) :=
rfl
@[simp]
theorem quot_neg (x : Prequotient F) :
Quot.mk Setoid.r (neg x) = -(show ColimitType F from Quot.mk Setoid.r x) :=
rfl
-- Porting note: Lean can't see `Quot.mk Setoid.r x` is a `ColimitType F` even with type annotation
-- unless we use `by exact` to change the elaboration order.
@[simp]
theorem quot_add (x y) :
Quot.mk Setoid.r (add x y) =
(show ColimitType F from Quot.mk _ x) + (show ColimitType F from Quot.mk _ y) :=
rfl
-- Porting note: Lean can't see `Quot.mk Setoid.r x` is a `ColimitType F` even with type annotation
-- unless we use `by exact` to change the elaboration order.
@[simp]
theorem quot_mul (x y) :
Quot.mk Setoid.r (mul x y) =
(show ColimitType F from Quot.mk _ x) * (show ColimitType F from Quot.mk _ y) :=
rfl
/-- The bundled commutative ring giving the colimit of a diagram. -/
def colimit : CommRingCat :=
CommRingCat.of (ColimitType F)
/-- The function from a given commutative ring in the diagram to the colimit commutative ring. -/
def coconeFun (j : J) (x : F.obj j) : ColimitType F :=
Quot.mk _ (Prequotient.of j x)
/-- The ring homomorphism from a given commutative ring in the diagram to the colimit commutative
ring. -/
def coconeMorphism (j : J) : F.obj j ⟶ colimit F := ofHom <|
{ toFun := coconeFun F j
map_one' := by apply Quot.sound; apply Relation.one
map_mul' := by intros; apply Quot.sound; apply Relation.mul
map_zero' := by apply Quot.sound; apply Relation.zero
map_add' := by intros; apply Quot.sound; apply Relation.add }
@[simp]
theorem cocone_naturality {j j' : J} (f : j ⟶ j') :
F.map f ≫ coconeMorphism F j' = coconeMorphism F j := by
ext
apply Quot.sound
apply Relation.map
@[simp]
theorem cocone_naturality_components (j j' : J) (f : j ⟶ j') (x : F.obj j) :
(coconeMorphism F j') (F.map f x) = (coconeMorphism F j) x := by
rw [← cocone_naturality F f, comp_apply]
/-- The cocone over the proposed colimit commutative ring. -/
def colimitCocone : Cocone F where
pt := colimit F
ι := { app := coconeMorphism F }
/-- The function from the free commutative ring on the diagram to the cone point of any other
cocone. -/
@[simp]
def descFunLift (s : Cocone F) : Prequotient F → s.pt
| Prequotient.of j x => (s.ι.app j) x
| zero => 0
| one => 1
| neg x => -descFunLift s x
| add x y => descFunLift s x + descFunLift s y
| mul x y => descFunLift s x * descFunLift s y
/-- The function from the colimit commutative ring to the cone point of any other cocone. -/
def descFun (s : Cocone F) : ColimitType F → s.pt := by
fapply Quot.lift
· exact descFunLift F s
· intro x y r
induction r with
| refl => rfl
| symm x y _ ih => exact ih.symm
| trans x y z _ _ ih1 ih2 => exact ih1.trans ih2
| map j j' f x => exact RingHom.congr_fun (congrArg Hom.hom <| s.ι.naturality f) x
| zero j => simp
| one j => simp
| neg j x => simp
| add j x y => simp
| mul j x y => simp
| neg_1 x x' r ih => dsimp; rw [ih]
| add_1 x x' y r ih => dsimp; rw [ih]
| add_2 x y y' r ih => dsimp; rw [ih]
| mul_1 x x' y r ih => dsimp; rw [ih]
| mul_2 x y y' r ih => dsimp; rw [ih]
| zero_add x => dsimp; rw [zero_add]
| add_zero x => dsimp; rw [add_zero]
| one_mul x => dsimp; rw [one_mul]
| mul_one x => dsimp; rw [mul_one]
| neg_add_cancel x => dsimp; rw [neg_add_cancel]
| add_comm x y => dsimp; rw [add_comm]
| mul_comm x y => dsimp; rw [mul_comm]
| add_assoc x y z => dsimp; rw [add_assoc]
| mul_assoc x y z => dsimp; rw [mul_assoc]
| left_distrib x y z => dsimp; rw [mul_add]
| right_distrib x y z => dsimp; rw [add_mul]
| zero_mul x => dsimp; rw [zero_mul]
| mul_zero x => dsimp; rw [mul_zero]
/-- The ring homomorphism from the colimit commutative ring to the cone point of any other
cocone. -/
def descMorphism (s : Cocone F) : colimit F ⟶ s.pt := ofHom
{ toFun := descFun F s
map_one' := rfl
map_zero' := rfl
map_add' := fun x y ↦ by
refine Quot.induction_on₂ x y fun a b => ?_
dsimp [descFun]
rw [← quot_add]
rfl
map_mul' := fun x y ↦ by exact Quot.induction_on₂ x y fun a b => rfl }
/-- Evidence that the proposed colimit is the colimit. -/
def colimitIsColimit : IsColimit (colimitCocone F) where
desc := fun s ↦ descMorphism F s
uniq := fun s m w ↦ hom_ext <| RingHom.ext fun x => by
refine Quot.inductionOn x ?_
intro x
induction x with
| zero => simp
| one => simp
| neg x ih => simp [ih]
| of j x =>
exact congr_fun (congr_arg (fun f : F.obj j ⟶ s.pt => (f : F.obj j → s.pt)) (w j)) x
| add x y ih_x ih_y => simp [ih_x, ih_y]
| mul x y ih_x ih_y => simp [ih_x, ih_y]
instance hasColimits_commRingCat : HasColimits CommRingCat where
has_colimits_of_shape _ _ :=
{ has_colimit := fun F =>
HasColimit.mk
{ cocone := colimitCocone F
isColimit := colimitIsColimit F } }
end CommRingCat.Colimits |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/Epi.lean | import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.RingTheory.TensorProduct.Finite
import Mathlib.CategoryTheory.ConcreteCategory.EpiMono
/-!
# Epimorphisms in `CommRingCat`
## Main results
- `RingHom.surjective_iff_epi_and_finite`: surjective <=> epi + finite
-/
open CategoryTheory TensorProduct
universe u
lemma CommRingCat.epi_iff_tmul_eq_tmul {R S : Type u} [CommRing R] [CommRing S] [Algebra R S] :
Epi (CommRingCat.ofHom (algebraMap R S)) ↔
∀ s : S, s ⊗ₜ[R] 1 = 1 ⊗ₜ s := by
constructor
· intro H
have := H.1 (CommRingCat.ofHom <| Algebra.TensorProduct.includeLeftRingHom)
(CommRingCat.ofHom <| (Algebra.TensorProduct.includeRight (R := R) (A := S)).toRingHom)
(by ext r; change algebraMap R S r ⊗ₜ 1 = 1 ⊗ₜ algebraMap R S r;
simp only [Algebra.algebraMap_eq_smul_one, smul_tmul])
exact RingHom.congr_fun (congrArg Hom.hom this)
· refine fun H ↦ ⟨fun {T} f g e ↦ ?_⟩
letI : Algebra R T := (ofHom (algebraMap R S) ≫ g).hom.toAlgebra
let f' : S →ₐ[R] T := ⟨f.hom, RingHom.congr_fun (congrArg Hom.hom e)⟩
let g' : S →ₐ[R] T := ⟨g.hom, fun _ ↦ rfl⟩
ext s
simpa using congr(Algebra.TensorProduct.lift f' g' (fun _ _ ↦ .all _ _) $(H s))
lemma RingHom.surjective_of_epi_of_finite {R S : CommRingCat} (f : R ⟶ S) [Epi f]
(h₂ : RingHom.Finite f.hom) : Function.Surjective f := by
algebraize [f.hom]
apply RingHom.surjective_of_tmul_eq_tmul_of_finite
rwa [← CommRingCat.epi_iff_tmul_eq_tmul]
lemma RingHom.surjective_iff_epi_and_finite {R S : CommRingCat} {f : R ⟶ S} :
Function.Surjective f ↔ Epi f ∧ RingHom.Finite f.hom where
mp h := ⟨ConcreteCategory.epi_of_surjective f h, .of_surjective f.hom h⟩
mpr := fun ⟨_, h⟩ ↦ surjective_of_epi_of_finite f h |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/Limits.lean | import Mathlib.Algebra.Category.Grp.Limits
import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.Algebra.Ring.Pi
import Mathlib.Algebra.Ring.Shrink
import Mathlib.Algebra.Ring.Subring.Defs
/-!
# The category of (commutative) rings has all limits
Further, these limits are preserved by the forgetful functor --- that is,
the underlying types are just the limits in the category of types.
-/
-- We use the following trick a lot of times in this file.
library_note2 «change elaboration strategy with `by apply`» /--
Some definitions may be extremely slow to elaborate, when the target type to be constructed
is complicated and when the type of the term given in the definition is also complicated and does
not obviously match the target type. In this case, instead of just giving the term, prefixing it
with `by apply` may speed up things considerably as the types are not elaborated in the same order.
-/
open CategoryTheory
open CategoryTheory.Limits
universe v u w
noncomputable section
namespace SemiRingCat
variable {J : Type v} [Category.{w} J] (F : J ⥤ SemiRingCat.{u})
instance semiringObj (j) : Semiring ((F ⋙ forget SemiRingCat).obj j) :=
inferInstanceAs <| Semiring (F.obj j)
/-- The flat sections of a functor into `SemiRingCat` form a subsemiring of all sections. -/
def sectionsSubsemiring : Subsemiring (∀ j, F.obj j) :=
{ (MonCat.sectionsSubmonoid (J := J) (F ⋙ forget₂ SemiRingCat.{u} MonCat.{u})),
(AddMonCat.sectionsAddSubmonoid (J := J) (F ⋙ forget₂ SemiRingCat.{u} AddCommMonCat.{u} ⋙
forget₂ AddCommMonCat AddMonCat)) with
carrier := (F ⋙ forget SemiRingCat).sections }
instance sectionsSemiring : Semiring (F ⋙ forget SemiRingCat.{u}).sections :=
(sectionsSubsemiring F).toSemiring
variable [Small.{u} (Functor.sections (F ⋙ forget SemiRingCat.{u}))]
instance limitSemiring :
Semiring (Types.Small.limitCone.{v, u} (F ⋙ forget SemiRingCat.{u})).pt :=
let _ : Semiring (F ⋙ forget SemiRingCat).sections := (sectionsSubsemiring F).toSemiring
inferInstanceAs <| Semiring (Shrink (F ⋙ forget SemiRingCat).sections)
/-- `limit.π (F ⋙ forget SemiRingCat) j` as a `RingHom`. -/
def limitπRingHom (j) :
(Types.Small.limitCone.{v, u} (F ⋙ forget SemiRingCat)).pt →+* (F ⋙ forget SemiRingCat).obj j :=
let f : J ⥤ AddMonCat.{u} := F ⋙ forget₂ SemiRingCat.{u} AddCommMonCat.{u} ⋙
forget₂ AddCommMonCat AddMonCat
let _ : Small.{u} (Functor.sections ((F ⋙ forget₂ _ MonCat) ⋙ forget MonCat)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget SemiRingCat.{u}))
let _ : Small.{u} (Functor.sections (f ⋙ forget AddMonCat)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget SemiRingCat.{u}))
{ AddMonCat.limitπAddMonoidHom f j,
MonCat.limitπMonoidHom (F ⋙ forget₂ SemiRingCat MonCat.{u}) j with
toFun := (Types.Small.limitCone (F ⋙ forget SemiRingCat)).π.app j }
namespace HasLimits
-- The next two definitions are used in the construction of `HasLimits SemiRingCat`.
-- After that, the limits should be constructed using the generic limits API,
-- e.g. `limit F`, `limit.cone F`, and `limit.isLimit F`.
/-- Construction of a limit cone in `SemiRingCat`.
(Internal use only; use the limits API.)
-/
def limitCone : Cone F where
pt := SemiRingCat.of (Types.Small.limitCone (F ⋙ forget _)).pt
π :=
{ app := fun j ↦ SemiRingCat.ofHom <| limitπRingHom.{v, u} F j
naturality := fun {_ _} f ↦ hom_ext <| RingHom.coe_inj
((Types.Small.limitCone (F ⋙ forget _)).π.naturality f) }
/-- Witness that the limit cone in `SemiRingCat` is a limit cone.
(Internal use only; use the limits API.)
-/
def limitConeIsLimit : IsLimit (limitCone F) := by
refine IsLimit.ofFaithful (forget SemiRingCat.{u}) (Types.Small.limitConeIsLimit.{v, u} _)
(fun s => ofHom { toFun := _, map_one' := ?_, map_mul' := ?_, map_zero' := ?_, map_add' := ?_})
(fun s => rfl)
· simp only [Functor.mapCone_π_app, forget_map, map_one]
rfl
· intro x y
simp only [Functor.comp_obj, Functor.mapCone_pt, Functor.mapCone_π_app,
forget_map, map_mul, EquivLike.coe_apply]
rw [← equivShrink_mul]
rfl
· simp only [Functor.mapCone_π_app, forget_map, map_zero]
rfl
· intro x y
simp only [Functor.comp_obj, Functor.mapCone_pt, Functor.mapCone_π_app,
forget_map, map_add, EquivLike.coe_apply]
rw [← equivShrink_add]
rfl
end HasLimits
open HasLimits
/-- If `(F ⋙ forget SemiRingCat).sections` is `u`-small, `F` has a limit. -/
instance hasLimit : HasLimit F := ⟨limitCone.{v, u} F, limitConeIsLimit.{v, u} F⟩
/-- If `J` is `u`-small, `SemiRingCat.{u}` has limits of shape `J`. -/
instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J SemiRingCat.{u} where
/-- The category of rings has all limits. -/
instance hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} SemiRingCat.{u} where
has_limits_of_shape _ _ := { }
instance hasLimits : HasLimits SemiRingCat.{u} :=
SemiRingCat.hasLimitsOfSize.{u, u}
/--
Auxiliary lemma to prove the cone induced by `limitCone` is a limit cone.
-/
def forget₂AddCommMonPreservesLimitsAux :
IsLimit ((forget₂ SemiRingCat AddCommMonCat).mapCone (limitCone F)) := by
let _ : Small.{u} (Functor.sections ((F ⋙ forget₂ _ AddCommMonCat) ⋙ forget _)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget SemiRingCat))
apply AddCommMonCat.limitConeIsLimit.{v, u}
/-- The forgetful functor from semirings to additive commutative monoids preserves all limits.
-/
instance forget₂AddCommMon_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ SemiRingCat AddCommMonCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone (limitConeIsLimit.{v, u} F)
(forget₂AddCommMonPreservesLimitsAux F) }
instance forget₂AddCommMon_preservesLimits :
PreservesLimits (forget₂ SemiRingCat AddCommMonCat.{u}) :=
SemiRingCat.forget₂AddCommMon_preservesLimitsOfSize.{u, u}
/-- An auxiliary declaration to speed up typechecking.
-/
def forget₂MonPreservesLimitsAux :
IsLimit ((forget₂ SemiRingCat MonCat).mapCone (limitCone F)) := by
let _ : Small.{u} (Functor.sections ((F ⋙ forget₂ _ MonCat) ⋙ forget MonCat)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget SemiRingCat))
apply MonCat.HasLimits.limitConeIsLimit (F ⋙ forget₂ SemiRingCat MonCat.{u})
/-- The forgetful functor from semirings to monoids preserves all limits.
-/
instance forget₂Mon_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ SemiRingCat MonCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone (limitConeIsLimit F)
(forget₂MonPreservesLimitsAux.{v, u} F) }
instance forget₂Mon_preservesLimits : PreservesLimits (forget₂ SemiRingCat MonCat.{u}) :=
SemiRingCat.forget₂Mon_preservesLimitsOfSize.{u, u}
/-- The forgetful functor from semirings to types preserves all limits.
-/
instance forget_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget SemiRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone (limitConeIsLimit F)
(Types.Small.limitConeIsLimit.{v, u} (F ⋙ forget _)) }
instance forget_preservesLimits : PreservesLimits (forget SemiRingCat.{u}) :=
SemiRingCat.forget_preservesLimitsOfSize.{u, u}
end SemiRingCat
namespace CommSemiRingCat
variable {J : Type v} [Category.{w} J] (F : J ⥤ CommSemiRingCat.{u})
instance commSemiringObj (j) :
CommSemiring ((F ⋙ forget CommSemiRingCat).obj j) :=
inferInstanceAs <| CommSemiring (F.obj j)
variable [Small.{u} (Functor.sections (F ⋙ forget CommSemiRingCat))]
instance limitCommSemiring :
CommSemiring (Types.Small.limitCone.{v, u} (F ⋙ forget CommSemiRingCat.{u})).pt :=
let _ : CommSemiring (F ⋙ forget CommSemiRingCat.{u}).sections :=
@Subsemiring.toCommSemiring (∀ j, F.obj j) _
(SemiRingCat.sectionsSubsemiring.{v, u} (F ⋙ forget₂ CommSemiRingCat.{u} SemiRingCat.{u}))
inferInstanceAs <| CommSemiring (Shrink (F ⋙ forget CommSemiRingCat.{u}).sections)
/-- We show that the forgetful functor `CommSemiRingCat ⥤ SemiRingCat` creates limits.
All we need to do is notice that the limit point has a `CommSemiring` instance available,
and then reuse the existing limit.
-/
instance :
CreatesLimit F (forget₂ CommSemiRingCat.{u} SemiRingCat.{u}) :=
-- Porting note: Lean cannot see `CommSemiRingCat ⥤ SemiRingCat` reflects isomorphism, so this
-- instance is added.
let _ : (forget₂ CommSemiRingCat.{u} SemiRingCat.{u}).ReflectsIsomorphisms :=
CategoryTheory.reflectsIsomorphisms_forget₂ CommSemiRingCat.{u} SemiRingCat.{u}
let _ : Small.{u} (Functor.sections ((F ⋙ forget₂ _ SemiRingCat) ⋙ forget _)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget CommSemiRingCat))
let c : Cone F :=
{ pt := CommSemiRingCat.of (Types.Small.limitCone (F ⋙ forget _)).pt
π :=
{ app := fun j => CommSemiRingCat.ofHom <| SemiRingCat.limitπRingHom.{v, u} (J := J)
(F ⋙ forget₂ CommSemiRingCat.{u} SemiRingCat.{u}) j
naturality := fun _ _ f ↦ hom_ext <| congrArg SemiRingCat.Hom.hom <|
(SemiRingCat.HasLimits.limitCone.{v, u}
(F ⋙ forget₂ CommSemiRingCat.{u} SemiRingCat.{u})).π.naturality f } }
createsLimitOfReflectsIso fun c' t =>
{ liftedCone := c
validLift := IsLimit.uniqueUpToIso (SemiRingCat.HasLimits.limitConeIsLimit.{v, u} _) t
makesLimit := by
refine IsLimit.ofFaithful (forget₂ CommSemiRingCat.{u} SemiRingCat.{u})
(SemiRingCat.HasLimits.limitConeIsLimit.{v, u} _) (fun s => _) fun s => rfl }
/-- A choice of limit cone for a functor into `CommSemiRingCat`.
(Generally, you'll just want to use `limit F`.)
-/
def limitCone : Cone F :=
let _ : Small.{u} (Functor.sections ((F ⋙ forget₂ _ SemiRingCat.{u}) ⋙ forget _)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget _))
liftLimit (limit.isLimit (F ⋙ forget₂ CommSemiRingCat.{u} SemiRingCat.{u}))
/-- The chosen cone is a limit cone.
(Generally, you'll just want to use `limit.cone F`.)
-/
def limitConeIsLimit : IsLimit (limitCone F) :=
liftedLimitIsLimit _
/-- If `(F ⋙ forget CommSemiRingCat).sections` is `u`-small, `F` has a limit. -/
instance hasLimit : HasLimit F := ⟨limitCone.{v, u} F, limitConeIsLimit.{v, u} F⟩
/-- If `J` is `u`-small, `CommSemiRingCat.{u}` has limits of shape `J`. -/
instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J CommSemiRingCat.{u} where
/-- The category of rings has all limits. -/
instance hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} CommSemiRingCat.{u} where
instance hasLimits : HasLimits CommSemiRingCat.{u} :=
CommSemiRingCat.hasLimitsOfSize.{u, u}
/-- The forgetful functor from rings to semirings preserves all limits.
-/
instance forget₂SemiRing_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ CommSemiRingCat SemiRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone (limitConeIsLimit.{v, u} F)
(SemiRingCat.HasLimits.limitConeIsLimit (F ⋙ forget₂ _ SemiRingCat)) }
instance forget₂SemiRing_preservesLimits :
PreservesLimits (forget₂ CommSemiRingCat SemiRingCat.{u}) :=
CommSemiRingCat.forget₂SemiRing_preservesLimitsOfSize.{u, u}
/-- The forgetful functor from rings to types preserves all limits. (That is, the underlying
types could have been computed instead as limits in the category of types.)
-/
instance forget_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget CommSemiRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone (limitConeIsLimit.{v, u} F)
(Types.Small.limitConeIsLimit.{v, u} _) }
instance forget_preservesLimits : PreservesLimits (forget CommSemiRingCat.{u}) :=
CommSemiRingCat.forget_preservesLimitsOfSize.{u, u}
end CommSemiRingCat
namespace RingCat
variable {J : Type v} [Category.{w} J] (F : J ⥤ RingCat.{u})
instance ringObj (j) : Ring ((F ⋙ forget RingCat).obj j) :=
inferInstanceAs <| Ring (F.obj j)
/-- The flat sections of a functor into `RingCat` form a subring of all sections.
-/
def sectionsSubring : Subring (∀ j, F.obj j) :=
let f : J ⥤ AddGrpCat.{u} :=
F ⋙ forget₂ RingCat.{u} AddCommGrpCat.{u} ⋙
forget₂ AddCommGrpCat.{u} AddGrpCat.{u}
let g : J ⥤ SemiRingCat.{u} := F ⋙ forget₂ RingCat.{u} SemiRingCat.{u}
{ AddGrpCat.sectionsAddSubgroup (J := J) f,
SemiRingCat.sectionsSubsemiring (J := J) g with
carrier := (F ⋙ forget RingCat.{u}).sections }
variable [Small.{u} (Functor.sections (F ⋙ forget RingCat.{u}))]
instance limitRing : Ring.{u} (Types.Small.limitCone.{v, u} (F ⋙ forget RingCat.{u})).pt :=
let _ : Ring (F ⋙ forget RingCat.{u}).sections := (sectionsSubring F).toRing
inferInstanceAs <| Ring (Shrink _)
/-- We show that the forgetful functor `CommRingCat ⥤ RingCat` creates limits.
All we need to do is notice that the limit point has a `Ring` instance available,
and then reuse the existing limit.
-/
instance : CreatesLimit F (forget₂ RingCat.{u} SemiRingCat.{u}) :=
have : (forget₂ RingCat SemiRingCat).ReflectsIsomorphisms :=
CategoryTheory.reflectsIsomorphisms_forget₂ _ _
have : Small.{u} (Functor.sections ((F ⋙ forget₂ _ SemiRingCat) ⋙ forget _)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget _))
let c : Cone F :=
{ pt := RingCat.of (Types.Small.limitCone (F ⋙ forget _)).pt
π :=
{ app := fun x => ofHom <| SemiRingCat.limitπRingHom.{v, u} (F ⋙ forget₂ _ SemiRingCat) x
naturality := fun _ _ f => hom_ext <| RingHom.coe_inj
((Types.Small.limitCone (F ⋙ forget _)).π.naturality f) } }
createsLimitOfReflectsIso fun c' t =>
{ liftedCone := c
validLift := by apply IsLimit.uniqueUpToIso (SemiRingCat.HasLimits.limitConeIsLimit _) t
makesLimit :=
IsLimit.ofFaithful (forget₂ RingCat SemiRingCat.{u})
(by apply SemiRingCat.HasLimits.limitConeIsLimit _) (fun _ => _) fun _ => rfl }
/-- A choice of limit cone for a functor into `RingCat`.
(Generally, you'll just want to use `limit F`.)
-/
def limitCone : Cone F :=
let _ : Small.{u} (Functor.sections ((F ⋙ forget₂ _ SemiRingCat) ⋙ forget _)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget _))
liftLimit (limit.isLimit (F ⋙ forget₂ RingCat.{u} SemiRingCat.{u}))
/-- The chosen cone is a limit cone.
(Generally, you'll just want to use `limit.cone F`.)
-/
def limitConeIsLimit : IsLimit (limitCone F) :=
liftedLimitIsLimit _
/-- If `(F ⋙ forget RingCat).sections` is `u`-small, `F` has a limit. -/
instance hasLimit : HasLimit F :=
let _ : Small.{u} (Functor.sections ((F ⋙ forget₂ _ SemiRingCat) ⋙ forget _)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget _))
hasLimit_of_created F (forget₂ RingCat.{u} SemiRingCat.{u})
/-- If `J` is `u`-small, `RingCat.{u}` has limits of shape `J`. -/
instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J RingCat.{u} where
/-- The category of rings has all limits. -/
instance hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} RingCat.{u} where
instance hasLimits : HasLimits RingCat.{u} :=
RingCat.hasLimitsOfSize.{u, u}
/-- The forgetful functor from rings to semirings preserves all limits.
-/
instance forget₂SemiRing_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ RingCat SemiRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone (limitConeIsLimit.{v, u} F)
(SemiRingCat.HasLimits.limitConeIsLimit.{v, u} _) }
instance forget₂SemiRing_preservesLimits : PreservesLimits (forget₂ RingCat SemiRingCat.{u}) :=
RingCat.forget₂SemiRing_preservesLimitsOfSize.{u, u}
/-- An auxiliary declaration to speed up typechecking.
-/
def forget₂AddCommGroupPreservesLimitsAux :
IsLimit ((forget₂ RingCat.{u} AddCommGrpCat).mapCone (limitCone.{v, u} F)) := by
let _ : Small.{u} (Functor.sections ((F ⋙ forget₂ RingCat.{u} AddCommGrpCat.{u}) ⋙ forget _)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget _))
apply AddCommGrpCat.limitConeIsLimit.{v, u} _
/-- The forgetful functor from rings to additive commutative groups preserves all limits.
-/
instance forget₂AddCommGroup_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{v, v} (forget₂ RingCat.{u} AddCommGrpCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone (limitConeIsLimit.{v, u} F)
(forget₂AddCommGroupPreservesLimitsAux F) }
instance forget₂AddCommGroup_preservesLimits :
PreservesLimits (forget₂ RingCat AddCommGrpCat.{u}) :=
RingCat.forget₂AddCommGroup_preservesLimitsOfSize.{u, u}
/-- The forgetful functor from rings to types preserves all limits. (That is, the underlying
types could have been computed instead as limits in the category of types.)
-/
instance forget_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{v, v} (forget RingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone (limitConeIsLimit.{v, u} F)
(Types.Small.limitConeIsLimit.{v, u} _) }
instance forget_preservesLimits : PreservesLimits (forget RingCat.{u}) :=
RingCat.forget_preservesLimitsOfSize.{u, u}
end RingCat
namespace CommRingCat
variable {J : Type v} [Category.{w} J] (F : J ⥤ CommRingCat.{u})
instance commRingObj (j) : CommRing ((F ⋙ forget CommRingCat).obj j) :=
inferInstanceAs <| CommRing (F.obj j)
variable [Small.{u} (Functor.sections (F ⋙ forget CommRingCat))]
instance limitCommRing :
CommRing.{u} (Types.Small.limitCone.{v, u} (F ⋙ forget CommRingCat.{u})).pt :=
let _ : CommRing (F ⋙ forget CommRingCat).sections := @Subring.toCommRing (∀ j, F.obj j) _
(RingCat.sectionsSubring.{v, u} (F ⋙ forget₂ CommRingCat RingCat.{u}))
inferInstanceAs <| CommRing (Shrink _)
/-- We show that the forgetful functor `CommRingCat ⥤ RingCat` creates limits.
All we need to do is notice that the limit point has a `CommRing` instance available,
and then reuse the existing limit.
-/
instance : CreatesLimit F (forget₂ CommRingCat.{u} RingCat.{u}) :=
/-
A terse solution here would be
```
createsLimitOfFullyFaithfulOfIso (CommRingCat.of (limit (F ⋙ forget _))) (Iso.refl _)
```
but it seems this would introduce additional identity morphisms in `limit.π`.
-/
-- Porting note: need to add these instances manually
have : (forget₂ CommRingCat.{u} RingCat.{u}).ReflectsIsomorphisms :=
CategoryTheory.reflectsIsomorphisms_forget₂ _ _
have : Small.{u} (Functor.sections ((F ⋙ forget₂ CommRingCat RingCat) ⋙ forget RingCat)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget _))
let F' := F ⋙ forget₂ CommRingCat.{u} RingCat.{u} ⋙ forget₂ RingCat.{u} SemiRingCat.{u}
have : Small.{u} (Functor.sections (F' ⋙ forget _)) :=
inferInstanceAs <| Small.{u} (F ⋙ forget _).sections
let c : Cone F :=
{ pt := CommRingCat.of (Types.Small.limitCone (F ⋙ forget _)).pt
π :=
{ app := fun x => ofHom <| SemiRingCat.limitπRingHom.{v, u} F' x
naturality :=
fun _ _ f => hom_ext <| RingHom.coe_inj
((Types.Small.limitCone (F ⋙ forget _)).π.naturality f) } }
createsLimitOfReflectsIso fun _ t =>
{ liftedCone := c
validLift := IsLimit.uniqueUpToIso (RingCat.limitConeIsLimit.{v, u} _) t
makesLimit :=
IsLimit.ofFaithful (forget₂ _ RingCat.{u})
(RingCat.limitConeIsLimit.{v, u} (F ⋙ forget₂ CommRingCat.{u} RingCat.{u}))
(fun s : Cone F => CommRingCat.ofHom <|
(RingCat.limitConeIsLimit.{v, u}
(F ⋙ forget₂ CommRingCat.{u} RingCat.{u})).lift
((forget₂ _ RingCat.{u}).mapCone s) |>.hom) fun _ => rfl }
/-- A choice of limit cone for a functor into `CommRingCat`.
(Generally, you'll just want to use `limit F`.)
-/
def limitCone : Cone F :=
let _ : Small.{u} (Functor.sections ((F ⋙ forget₂ CommRingCat RingCat) ⋙ forget RingCat)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget _))
liftLimit (limit.isLimit (F ⋙ forget₂ CommRingCat.{u} RingCat.{u}))
/-- The chosen cone is a limit cone. (Generally, you'll just want to use `limit.cone F`.) -/
def limitConeIsLimit : IsLimit (limitCone.{v, u} F) :=
liftedLimitIsLimit _
/-- If `(F ⋙ forget CommRingCat).sections` is `u`-small, `F` has a limit. -/
instance hasLimit : HasLimit F :=
let _ : Small.{u} (Functor.sections ((F ⋙ forget₂ CommRingCat RingCat) ⋙ forget RingCat)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget _))
hasLimit_of_created F (forget₂ CommRingCat.{u} RingCat.{u})
/-- If `J` is `u`-small, `CommRingCat.{u}` has limits of shape `J`. -/
instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J CommRingCat.{u} where
/-- The category of commutative rings has all limits. -/
instance hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} CommRingCat.{u} where
instance hasLimits : HasLimits CommRingCat.{u} :=
CommRingCat.hasLimitsOfSize.{u, u}
/-- The forgetful functor from commutative rings to rings preserves all limits.
(That is, the underlying rings could have been computed instead as limits in the category of rings.)
-/
instance forget₂Ring_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ CommRingCat RingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone.{w, v} (limitConeIsLimit.{v, u} F)
(RingCat.limitConeIsLimit.{v, u} _) }
instance forget₂Ring_preservesLimits : PreservesLimits (forget₂ CommRingCat RingCat.{u}) :=
CommRingCat.forget₂Ring_preservesLimitsOfSize.{u, u}
/-- An auxiliary declaration to speed up typechecking.
-/
def forget₂CommSemiRingPreservesLimitsAux :
IsLimit ((forget₂ CommRingCat CommSemiRingCat).mapCone (limitCone F)) := by
let _ : Small.{u} ((F ⋙ forget₂ _ CommSemiRingCat) ⋙ forget _).sections :=
inferInstanceAs <| Small.{u} (F ⋙ forget _).sections
apply CommSemiRingCat.limitConeIsLimit (F ⋙ forget₂ CommRingCat CommSemiRingCat.{u})
/-- The forgetful functor from commutative rings to commutative semirings preserves all limits.
(That is, the underlying commutative semirings could have been computed instead as limits
in the category of commutative semirings.)
-/
instance forget₂CommSemiRing_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ CommRingCat CommSemiRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone (limitConeIsLimit.{v, u} F)
(forget₂CommSemiRingPreservesLimitsAux.{v, u} F) }
instance forget₂CommSemiRing_preservesLimits :
PreservesLimits (forget₂ CommRingCat CommSemiRingCat.{u}) :=
CommRingCat.forget₂CommSemiRing_preservesLimitsOfSize.{u, u}
/-- The forgetful functor from commutative rings to types preserves all limits.
(That is, the underlying types could have been computed instead as limits in the category of types.)
-/
instance forget_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget CommRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone.{w, v} (limitConeIsLimit.{v, u} F)
(Types.Small.limitConeIsLimit.{v, u} _) }
instance forget_preservesLimits : PreservesLimits (forget CommRingCat.{u}) :=
CommRingCat.forget_preservesLimitsOfSize.{u, u}
end CommRingCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/Adjunctions.lean | import Mathlib.Algebra.Category.Ring.Colimits
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.CategoryTheory.Comma.Over.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Terminal
/-!
# Adjunctions in `CommRingCat`
## Main results
- `CommRingCat.adj`: `σ ↦ ℤ[σ]` is left adjoint to the forgetful functor `CommRingCat ⥤ Type`.
- `CommRingCat.coyonedaAdj`: `Fun(-, R)` is left adjoint to `Hom_{CRing}(R, -)`.
- `CommRingCat.monoidAlgebraAdj`: `G ↦ R[G]` as `CommGrpCat ⥤ R-Alg` is left adjoint to `S ↦ Sˣ`.
- `CommRingCat.unitsAdj`: `G ↦ ℤ[G]` is left adjoint to `S ↦ Sˣ`.
-/
noncomputable section
universe v u
open MvPolynomial Opposite
open CategoryTheory
namespace CommRingCat
/-- The free functor `Type u ⥤ CommRingCat` sending a type `X` to the multivariable (commutative)
polynomials with variables `x : X`.
-/
def free : Type u ⥤ CommRingCat.{u} where
obj α := of (MvPolynomial α ℤ)
map {X Y} f := ofHom (↑(rename f : _ →ₐ[ℤ] _) : MvPolynomial X ℤ →+* MvPolynomial Y ℤ)
@[simp]
theorem free_obj_coe {α : Type u} : (free.obj α : Type u) = MvPolynomial α ℤ :=
rfl
-- This is not a `@[simp]` lemma as the left-hand side simplifies via `dsimp`.
theorem free_map_coe {α β : Type u} {f : α → β} : ⇑(free.map f) = ⇑(rename f) :=
rfl
/-- The free-forgetful adjunction for commutative rings. -/
def adj : free ⊣ forget CommRingCat.{u} :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun _ _ ↦
{ toFun := fun f ↦ homEquiv f.hom
invFun := fun f ↦ ofHom <| homEquiv.symm f
left_inv := fun f ↦ congrArg ofHom (homEquiv.left_inv f.hom)
right_inv := fun f ↦ homEquiv.right_inv f }
homEquiv_naturality_left_symm := fun {_ _ Y} f g =>
hom_ext <| RingHom.ext fun x ↦ eval₂_cast_comp f (Int.castRingHom Y) g x }
instance : (forget CommRingCat.{u}).IsRightAdjoint :=
⟨_, ⟨adj⟩⟩
/-- `Fun(-, -)` as a functor `Type vᵒᵖ ⥤ CommRingCat ⥤ CommRingCat`. -/
@[simps]
def coyoneda : Type vᵒᵖ ⥤ CommRingCat.{u} ⥤ CommRingCat.{max u v} where
obj n :=
{ obj R := CommRingCat.of ((unop n) → R)
map {R S} φ := CommRingCat.ofHom (Pi.ringHom (φ.hom.comp <| Pi.evalRingHom _ ·)) }
map {m n} f :=
{ app R := CommRingCat.ofHom (Pi.ringHom (Pi.evalRingHom _ <| f.unop ·)) }
/-- The adjunction `Hom_{CRing}(Fun(n, R), S) ≃ Fun(n, Hom_{CRing}(R, S))`. -/
def coyonedaAdj (R : CommRingCat.{u}) :
(coyoneda.flip.obj R).rightOp ⊣ yoneda.obj R where
unit := { app n i := CommRingCat.ofHom (Pi.evalRingHom _ i) }
counit := { app S := (CommRingCat.ofHom (Pi.ringHom fun f ↦ f.hom)).op }
instance (R : CommRingCat.{u}) : (yoneda.obj R).IsRightAdjoint := ⟨_, ⟨coyonedaAdj R⟩⟩
/-- If `n` is a singleton, `Hom(n, -)` is the identity in `CommRingCat`. -/
@[simps!]
def coyonedaUnique {n : Type v} [Unique n] : coyoneda.obj (op n) ≅ 𝟭 CommRingCat.{max u v} :=
NatIso.ofComponents (fun X ↦ (RingEquiv.piUnique _).toCommRingCatIso) (fun f ↦ by ext; simp)
/-- The monoid algebra functor `CommGrpCat ⥤ R-Alg` given by `G ↦ R[G]`. -/
@[simps]
def monoidAlgebra (R : CommRingCat.{max u v}) : CommMonCat.{v} ⥤ Under R where
obj G := Under.mk (CommRingCat.ofHom MonoidAlgebra.singleOneRingHom)
map f := Under.homMk (CommRingCat.ofHom <| MonoidAlgebra.mapDomainRingHom R f.hom)
map_comp f g := by ext : 2; apply MonoidAlgebra.ringHom_ext <;> intro <;> simp
@[simps (nameStem := "commMon")]
instance : HasForget₂ CommRingCat CommMonCat where
forget₂ := { obj M := .of M, map f := CommMonCat.ofHom f.hom }
forget_comp := rfl
/-- The adjunction `G ↦ R[G]` and `S ↦ Sˣ` between `CommGrpCat` and `R-Alg`. -/
def monoidAlgebraAdj (R : CommRingCat.{u}) :
monoidAlgebra R ⊣ Under.forget R ⋙ forget₂ _ _ where
unit := { app G := CommMonCat.ofHom (MonoidAlgebra.of R G) }
counit :=
{ app S := Under.homMk (CommRingCat.ofHom (MonoidAlgebra.liftNCRingHom S.hom.hom
(.id _) fun _ _ ↦ .all _ _)) (by ext; simp [MonoidAlgebra.liftNCRingHom]),
naturality S T f := by
ext : 2
apply MonoidAlgebra.ringHom_ext <;>
intro <;> simp [MonoidAlgebra.liftNCRingHom, ← Under.w f, - Under.w] }
left_triangle_components G := by
ext : 2
apply MonoidAlgebra.ringHom_ext <;> intro <;> simp [MonoidAlgebra.liftNCRingHom]
right_triangle_components S := by dsimp; ext; simp [MonoidAlgebra.liftNCRingHom]
/-- The adjunction `G ↦ ℤ[G]` and `R ↦ Rˣ` between `CommGrpCat` and `CommRing`. -/
def forget₂Adj {R : CommRingCat.{u}} (hR : Limits.IsInitial R) :
monoidAlgebra R ⋙ Under.forget R ⊣ forget₂ _ _ :=
(monoidAlgebraAdj R).comp (Under.equivalenceOfIsInitial hR).toAdjunction
instance (R : CommRingCat) : (monoidAlgebra.{u, u} R).IsLeftAdjoint :=
⟨_, ⟨CommRingCat.monoidAlgebraAdj R⟩⟩
instance : (forget₂ CommRingCat CommMonCat).IsRightAdjoint :=
⟨_, ⟨CommRingCat.forget₂Adj Limits.initialIsInitial⟩⟩
end CommRingCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/Under/Basic.lean | import Mathlib.Algebra.Category.Ring.Colimits
import Mathlib.Algebra.Category.Ring.Constructions
import Mathlib.CategoryTheory.Comma.Over.Pullback
/-!
# Under `CommRingCat`
In this file we provide basic API for `Under R` when `R : CommRingCat`. `Under R` is
(equivalent to) the category of commutative `R`-algebras. For not necessarily commutative
algebras, use `AlgCat R` instead.
-/
noncomputable section
universe u
open TensorProduct CategoryTheory Limits
variable {R S : CommRingCat.{u}}
namespace CommRingCat
instance : CoeSort (Under R) (Type u) where
coe A := A.right
instance (A : Under R) : Algebra R A := RingHom.toAlgebra A.hom.hom
/-- Turn a morphism in `Under R` into an algebra homomorphism. -/
def toAlgHom {A B : Under R} (f : A ⟶ B) : A →ₐ[R] B where
__ := f.right.hom
commutes' a := by
have : (A.hom ≫ f.right) a = B.hom a := by simp
simpa only [Functor.const_obj_obj, Functor.id_obj, CommRingCat.comp_apply] using this
@[simp]
lemma toAlgHom_id (A : Under R) : toAlgHom (𝟙 A) = AlgHom.id R A := rfl
@[simp]
lemma toAlgHom_comp {A B C : Under R} (f : A ⟶ B) (g : B ⟶ C) :
toAlgHom (f ≫ g) = (toAlgHom g).comp (toAlgHom f) := rfl
@[simp]
lemma toAlgHom_apply {A B : Under R} (f : A ⟶ B) (a : A) :
toAlgHom f a = f.right a :=
rfl
variable (R) in
/-- Make an object of `Under R` from an `R`-algebra. -/
@[simps! hom, simps! -isSimp right]
def mkUnder (A : Type u) [CommRing A] [Algebra R A] : Under R :=
Under.mk (CommRingCat.ofHom <| algebraMap R A)
@[ext]
lemma mkUnder_ext {A : Type u} [CommRing A] [Algebra R A] {B : Under R}
{f g : mkUnder R A ⟶ B} (h : ∀ a : A, f.right a = g.right a) :
f = g := by
ext x
exact h x
end CommRingCat
namespace AlgHom
/-- Make a morphism in `Under R` from an algebra map. -/
def toUnder {A B : Type u} [CommRing A] [CommRing B] [Algebra R A] [Algebra R B]
(f : A →ₐ[R] B) : CommRingCat.mkUnder R A ⟶ CommRingCat.mkUnder R B :=
Under.homMk (CommRingCat.ofHom f.toRingHom) <| by
ext a
exact f.commutes' a
@[simp]
lemma toUnder_right {A B : Type u} [CommRing A] [CommRing B] [Algebra R A]
[Algebra R B] (f : A →ₐ[R] B) (a : A) :
f.toUnder.right a = f a :=
rfl
@[simp]
lemma toUnder_comp {A B C : Type u} [CommRing A] [CommRing B] [CommRing C]
[Algebra R A] [Algebra R B] [Algebra R C] (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(g.comp f).toUnder = f.toUnder ≫ g.toUnder :=
rfl
end AlgHom
namespace AlgEquiv
/-- Make an isomorphism in `Under R` from an algebra isomorphism. -/
def toUnder {A B : Type u} [CommRing A] [CommRing B] [Algebra R A] [Algebra R B]
(f : A ≃ₐ[R] B) :
CommRingCat.mkUnder R A ≅ CommRingCat.mkUnder R B where
hom := f.toAlgHom.toUnder
inv := f.symm.toAlgHom.toUnder
hom_inv_id := by
ext (a : (CommRingCat.mkUnder R A).right)
simp
inv_hom_id := by
ext a
simp
@[simp]
lemma toUnder_hom_right_apply {A B : Type u} [CommRing A] [CommRing B] [Algebra R A]
[Algebra R B] (f : A ≃ₐ[R] B) (a : A) :
f.toUnder.hom.right a = f a := rfl
@[simp]
lemma toUnder_inv_right_apply {A B : Type u} [CommRing A] [CommRing B] [Algebra R A]
[Algebra R B] (f : A ≃ₐ[R] B) (b : B) :
f.toUnder.inv.right b = f.symm b := rfl
@[simp]
lemma toUnder_trans {A B C : Type u} [CommRing A] [CommRing B] [CommRing C]
[Algebra R A] [Algebra R B] [Algebra R C] (f : A ≃ₐ[R] B) (g : B ≃ₐ[R] C) :
(f.trans g).toUnder = f.toUnder ≪≫ g.toUnder :=
rfl
end AlgEquiv
namespace CommRingCat
variable [Algebra R S]
variable (R S) in
/-- The base change functor `A ↦ S ⊗[R] A`. -/
@[simps! map_right]
def tensorProd : Under R ⥤ Under S where
obj A := mkUnder S (S ⊗[R] A)
map f := Algebra.TensorProduct.map (AlgHom.id S S) (toAlgHom f) |>.toUnder
map_comp {X Y Z} f g := by simp [Algebra.TensorProduct.map_id_comp]
variable (S) in
/-- The natural isomorphism `S ⊗[R] A ≅ pushout A.hom (algebraMap R S)` in `Under S`. -/
def tensorProdObjIsoPushoutObj (A : Under R) :
mkUnder S (S ⊗[R] A) ≅ (Under.pushout (ofHom <| algebraMap R S)).obj A :=
Under.isoMk (CommRingCat.isPushout_tensorProduct R S A).flip.isoPushout <| by
simp only [Functor.const_obj_obj, Under.pushout_obj, Functor.id_obj, Under.mk_right,
mkUnder_hom, AlgHom.toRingHom_eq_coe, IsPushout.inr_isoPushout_hom, Under.mk_hom]
rfl
@[reassoc (attr := simp)]
lemma pushout_inl_tensorProdObjIsoPushoutObj_inv_right (A : Under R) :
pushout.inl A.hom (ofHom <| algebraMap R S) ≫ (tensorProdObjIsoPushoutObj S A).inv.right =
(ofHom <| Algebra.TensorProduct.includeRight.toRingHom) := by
simp [tensorProdObjIsoPushoutObj]
@[reassoc (attr := simp)]
lemma pushout_inr_tensorProdObjIsoPushoutObj_inv_right (A : Under R) :
pushout.inr A.hom (ofHom <| algebraMap R S) ≫
(tensorProdObjIsoPushoutObj S A).inv.right =
(CommRingCat.ofHom <| Algebra.TensorProduct.includeLeftRingHom) := by
simp [tensorProdObjIsoPushoutObj]
variable (R S) in
/-- `A ↦ S ⊗[R] A` is naturally isomorphic to `A ↦ pushout A.hom (algebraMap R S)`. -/
def tensorProdIsoPushout : tensorProd R S ≅ Under.pushout (ofHom <| algebraMap R S) :=
NatIso.ofComponents (fun A ↦ tensorProdObjIsoPushoutObj S A) <| by
intro A B f
dsimp
rw [← cancel_epi (tensorProdObjIsoPushoutObj S A).inv]
ext : 1
apply pushout.hom_ext
· rw [← cancel_mono (tensorProdObjIsoPushoutObj S B).inv.right]
ext x
simp [mkUnder_right]
· rw [← cancel_mono (tensorProdObjIsoPushoutObj S B).inv.right]
ext (x : S)
simp [mkUnder_right]
@[simp]
lemma tensorProdIsoPushout_app (A : Under R) :
(tensorProdIsoPushout R S).app A = tensorProdObjIsoPushoutObj S A :=
rfl
end CommRingCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/Ring/Under/Limits.lean | import Mathlib.Algebra.Category.Ring.Under.Basic
import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers
import Mathlib.CategoryTheory.Limits.Over
import Mathlib.RingTheory.TensorProduct.Pi
import Mathlib.RingTheory.RingHom.Flat
import Mathlib.RingTheory.Flat.Equalizer
/-!
# Limits in `Under R` for a commutative ring `R`
We show that `Under.pushout f` is left-exact, i.e. preserves finite limits, if `f : R ⟶ S` is
flat.
-/
noncomputable section
universe v u
open TensorProduct CategoryTheory Limits
variable {R S : CommRingCat.{u}}
namespace CommRingCat.Under
section Algebra
variable [Algebra R S]
section Pi
variable {ι : Type u} (P : ι → Under R)
/-- The canonical fan on `P : ι → Under R` given by `∀ i, P i`. -/
def piFan : Fan P :=
Fan.mk (Under.mk <| ofHom <| Pi.ringHom (fun i ↦ (P i).hom.hom))
(fun i ↦ Under.homMk (ofHom <| Pi.evalRingHom _ i))
/-- The canonical fan is limiting. -/
def piFanIsLimit : IsLimit (piFan P) :=
isLimitOfReflects (Under.forget R) <|
(isLimitMapConeFanMkEquiv (Under.forget R) P _).symm <|
CommRingCat.piFanIsLimit (fun i ↦ (P i).right)
variable (S) in
/-- The fan on `i ↦ S ⊗[R] P i` given by `S ⊗[R] ∀ i, P i` -/
def tensorProductFan : Fan (fun i ↦ mkUnder S (S ⊗[R] (P i).right)) :=
Fan.mk (mkUnder S <| S ⊗[R] ∀ i, (P i).right)
(fun i ↦ AlgHom.toUnder <|
Algebra.TensorProduct.map (AlgHom.id S S) (Pi.evalAlgHom R (fun j ↦ (P j).right) i))
variable (S) in
/-- The fan on `i ↦ S ⊗[R] P i` given by `∀ i, S ⊗[R] P i` -/
def tensorProductFan' : Fan (fun i ↦ mkUnder S (S ⊗[R] (P i).right)) :=
Fan.mk (mkUnder S <| ∀ i, S ⊗[R] (P i).right)
(fun i ↦ AlgHom.toUnder <| Pi.evalAlgHom S _ i)
/-- The two fans on `i ↦ S ⊗[R] P i` agree if `ι` is finite. -/
def tensorProductFanIso [Fintype ι] [DecidableEq ι] :
tensorProductFan S P ≅ tensorProductFan' S P :=
Fan.ext (Algebra.TensorProduct.piRight R S _ _).toUnder <| fun i ↦ by
dsimp only [tensorProductFan, Fan.mk_pt, fan_mk_proj, tensorProductFan']
apply CommRingCat.mkUnder_ext
intro c
induction c
· simp only [map_zero, Under.comp_right]
· simp only [AlgHom.toUnder_right, Algebra.TensorProduct.map_tmul, AlgHom.coe_id, id_eq,
Pi.evalAlgHom_apply, Under.comp_right, comp_apply, AlgEquiv.toUnder_hom_right_apply,
Algebra.TensorProduct.piRight_tmul]
· simp_all
open Classical in
/-- The fan on `i ↦ S ⊗[R] P i` given by `S ⊗[R] ∀ i, P i` is limiting if `ι` is finite. -/
def tensorProductFanIsLimit [Finite ι] : IsLimit (tensorProductFan S P) :=
letI : Fintype ι := Fintype.ofFinite ι
(IsLimit.equivIsoLimit (tensorProductFanIso P)).symm (Under.piFanIsLimit _)
/-- `tensorProd R S` preserves the limit of the canonical fan on `P`. -/
noncomputable -- marked noncomputable for performance (only)
def piFanTensorProductIsLimit [Finite ι] : IsLimit ((tensorProd R S).mapCone (Under.piFan P)) :=
(isLimitMapConeFanMkEquiv (tensorProd R S) P _).symm <| tensorProductFanIsLimit P
instance (J : Type u) [Finite J] (f : J → Under R) :
PreservesLimit (Discrete.functor f) (tensorProd R S) :=
let c : Fan _ := Under.piFan f
have hc : IsLimit c := Under.piFanIsLimit f
preservesLimit_of_preserves_limit_cone hc (piFanTensorProductIsLimit f)
instance : PreservesFiniteProducts (tensorProd R S) where
preserves n :=
let J : Type u := ULift.{u} (Fin n)
have : PreservesLimitsOfShape (Discrete J) (tensorProd R S) :=
preservesLimitsOfShape_of_discrete (tensorProd R S)
preservesLimitsOfShape_of_equiv (Discrete.equivalence Equiv.ulift) (R.tensorProd S)
end Pi
section Equalizer
lemma equalizer_comp {A B : Under R} (f g : A ⟶ B) :
(AlgHom.equalizer (toAlgHom f) (toAlgHom g)).val.toUnder ≫ f =
(AlgHom.equalizer (toAlgHom f) (toAlgHom g)).val.toUnder ≫ g := by
ext (a : AlgHom.equalizer (toAlgHom f) (toAlgHom g))
exact a.property
/-- The canonical fork on `f g : A ⟶ B` given by the equalizer. -/
def equalizerFork {A B : Under R} (f g : A ⟶ B) :
Fork f g :=
Fork.ofι ((AlgHom.equalizer (toAlgHom f) (toAlgHom g)).val.toUnder)
(by rw [equalizer_comp])
@[simp]
lemma equalizerFork_ι {A B : Under R} (f g : A ⟶ B) :
(Under.equalizerFork f g).ι = (AlgHom.equalizer (toAlgHom f) (toAlgHom g)).val.toUnder := rfl
/-- Variant of `Under.equalizerFork'` for algebra maps. This is definitionally equal to
`Under.equalizerFork` but this is costly in applications. -/
def equalizerFork' {A B : Type u} [CommRing A] [CommRing B] [Algebra R A] [Algebra R B]
(f g : A →ₐ[R] B) :
Fork f.toUnder g.toUnder :=
Fork.ofι ((AlgHom.equalizer f g).val.toUnder) <| by ext a; exact a.property
@[simp]
lemma equalizerFork'_ι {A B : Type u} [CommRing A] [CommRing B] [Algebra R A] [Algebra R B]
(f g : A →ₐ[R] B) :
(Under.equalizerFork' f g).ι = (AlgHom.equalizer f g).val.toUnder := rfl
/-- The canonical fork on `f g : A ⟶ B` is limiting. -/
-- marked noncomputable for performance (only)
noncomputable def equalizerForkIsLimit {A B : Under R} (f g : A ⟶ B) :
IsLimit (Under.equalizerFork f g) :=
isLimitOfReflects (Under.forget R) <|
(isLimitMapConeForkEquiv (Under.forget R) (equalizer_comp f g)).invFun <|
CommRingCat.equalizerForkIsLimit f.right g.right
/-- Variant of `Under.equalizerForkIsLimit` for algebra maps. -/
def equalizerFork'IsLimit {A B : Type u} [CommRing A] [CommRing B] [Algebra R A]
[Algebra R B] (f g : A →ₐ[R] B) :
IsLimit (Under.equalizerFork' f g) :=
Under.equalizerForkIsLimit f.toUnder g.toUnder
/-- The fork on `𝟙 ⊗[R] f` and `𝟙 ⊗[R] g` given by `S ⊗[R] eq(f, g)`. -/
def tensorProdEqualizer {A B : Under R} (f g : A ⟶ B) :
Fork ((tensorProd R S).map f) ((tensorProd R S).map g) :=
Fork.ofι
((tensorProd R S).map ((AlgHom.equalizer (toAlgHom f) (toAlgHom g)).val.toUnder)) <| by
rw [← Functor.map_comp, equalizer_comp, Functor.map_comp]
@[simp]
lemma tensorProdEqualizer_ι {A B : Under R} (f g : A ⟶ B) :
(tensorProdEqualizer f g).ι = (tensorProd R S).map
((AlgHom.equalizer (toAlgHom f) (toAlgHom g)).val.toUnder) :=
rfl
/-- If `S` is `R`-flat, `S ⊗[R] eq(f, g)` is isomorphic to `eq(𝟙 ⊗[R] f, 𝟙 ⊗[R] g)`. -/
-- marked noncomputable for performance (only)
noncomputable def equalizerForkTensorProdIso [Module.Flat R S] {A B : Under R} (f g : A ⟶ B) :
tensorProdEqualizer f g ≅ Under.equalizerFork'
(Algebra.TensorProduct.map (AlgHom.id S S) (toAlgHom f))
(Algebra.TensorProduct.map (AlgHom.id S S) (toAlgHom g)) :=
Fork.ext (AlgHom.tensorEqualizerEquiv S S (toAlgHom f) (toAlgHom g)).toUnder <| by
ext
apply AlgHom.coe_tensorEqualizer
/-- If `S` is `R`-flat, `tensorProd R S` preserves the equalizer of `f` and `g`. -/
noncomputable -- marked noncomputable for performance (only)
def tensorProdMapEqualizerForkIsLimit [Module.Flat R S] {A B : Under R} (f g : A ⟶ B) :
IsLimit ((tensorProd R S).mapCone <| Under.equalizerFork f g) :=
(isLimitMapConeForkEquiv (tensorProd R S) _).symm <|
(IsLimit.equivIsoLimit (equalizerForkTensorProdIso f g).symm) <|
Under.equalizerFork'IsLimit _ _
instance [Module.Flat R S] {A B : Under R} (f g : A ⟶ B) :
PreservesLimit (parallelPair f g) (tensorProd R S) :=
let c : Fork f g := Under.equalizerFork f g
let hc : IsLimit c := Under.equalizerForkIsLimit f g
let hc' : IsLimit ((tensorProd R S).mapCone c) :=
tensorProdMapEqualizerForkIsLimit f g
preservesLimit_of_preserves_limit_cone hc hc'
instance [Module.Flat R S] : PreservesLimitsOfShape WalkingParallelPair (tensorProd R S) where
preservesLimit {K} :=
preservesLimit_of_iso_diagram _ (diagramIsoParallelPair K).symm
instance [Module.Flat R S] : PreservesFiniteLimits (tensorProd R S) :=
preservesFiniteLimits_of_preservesEqualizers_and_finiteProducts (tensorProd R S)
end Equalizer
end Algebra
variable (f : R ⟶ S)
/-- `Under.pushout f` preserves finite products. -/
instance : PreservesFiniteProducts (Under.pushout f) where
preserves _ :=
letI : Algebra R S := f.hom.toAlgebra
preservesLimitsOfShape_of_natIso (tensorProdIsoPushout R S)
/-- `Under.pushout f` preserves finite limits if `f` is flat. -/
lemma preservesFiniteLimits_of_flat (hf : RingHom.Flat f.hom) :
PreservesFiniteLimits (Under.pushout f) where
preservesFiniteLimits _ :=
letI : Algebra R S := f.hom.toAlgebra
haveI : Module.Flat R S := hf
preservesLimitsOfShape_of_natIso (tensorProdIsoPushout R S)
end CommRingCat.Under |
.lake/packages/mathlib/Mathlib/Algebra/Category/CoalgCat/Monoidal.lean | import Mathlib.Algebra.Category.CoalgCat.Basic
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic
import Mathlib.CategoryTheory.Monoidal.Transport
import Mathlib.RingTheory.Coalgebra.TensorProduct
/-!
# The monoidal category structure on `R`-coalgebras
In `Mathlib/RingTheory/Coalgebra/TensorProduct.lean`, given two `R`-coalgebras `M, N`, we define a
coalgebra instance on `M ⊗[R] N`, as well as the tensor product of two `CoalgHom`s as a
`CoalgHom`, and the associator and left/right unitors for coalgebras as `CoalgEquiv`s.
In this file, we declare a `MonoidalCategory` instance on the category of coalgebras, with data
fields given by the definitions in `Mathlib/RingTheory/Coalgebra/TensorProduct.lean`, and Prop
fields proved by pulling back the `MonoidalCategory` instance on the category of modules,
using `Monoidal.induced`.
-/
universe v u
namespace CoalgCat
variable (R : Type u) [CommRing R]
open CategoryTheory Coalgebra
open scoped TensorProduct MonoidalCategory
@[simps]
noncomputable instance instMonoidalCategoryStruct :
MonoidalCategoryStruct.{u} (CoalgCat R) where
tensorObj X Y := of R (X ⊗[R] Y)
whiskerLeft X _ _ f := ofHom (f.1.lTensor X)
whiskerRight f X := ofHom (f.1.rTensor X)
tensorHom f g := ofHom (Coalgebra.TensorProduct.map f.1 g.1)
tensorUnit := CoalgCat.of R R
associator X Y Z := (Coalgebra.TensorProduct.assoc R R X Y Z).toCoalgIso
leftUnitor X := (Coalgebra.TensorProduct.lid R X).toCoalgIso
rightUnitor X := (Coalgebra.TensorProduct.rid R R X).toCoalgIso
/-- The data needed to induce a `MonoidalCategory` structure via
`CoalgCat.instMonoidalCategoryStruct` and the forgetful functor to modules. -/
@[simps]
noncomputable def MonoidalCategory.inducingFunctorData :
Monoidal.InducingFunctorData (forget₂ (CoalgCat R) (ModuleCat R)) where
μIso _ _ := Iso.refl _
whiskerLeft_eq X Y Z f := by ext; rfl
whiskerRight_eq X f := by ext; rfl
tensorHom_eq f g := by ext; rfl
εIso := Iso.refl _
associator_eq X Y Z := ModuleCat.hom_ext <| TensorProduct.ext <| TensorProduct.ext <| by ext; rfl
leftUnitor_eq X := ModuleCat.hom_ext <| TensorProduct.ext <| by ext; rfl
rightUnitor_eq X := ModuleCat.hom_ext <| TensorProduct.ext <| by ext; rfl
noncomputable instance instMonoidalCategory : MonoidalCategory (CoalgCat R) :=
Monoidal.induced (forget₂ _ (ModuleCat R)) (MonoidalCategory.inducingFunctorData R)
end CoalgCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/CoalgCat/Basic.lean | import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.RingTheory.Coalgebra.Equiv
/-!
# The category of coalgebras over a commutative ring
We introduce the bundled category `CoalgCat` of coalgebras over a fixed commutative ring `R`
along with the forgetful functor to `ModuleCat`.
This file mimics `Mathlib/LinearAlgebra/QuadraticForm/QuadraticModuleCat.lean`.
-/
open CategoryTheory
universe v u
variable (R : Type u) [CommRing R]
/-- The category of `R`-coalgebras. -/
structure CoalgCat extends ModuleCat.{v} R where
instCoalgebra : Coalgebra R carrier
attribute [instance] CoalgCat.instCoalgebra
variable {R}
namespace CoalgCat
open Coalgebra
instance : CoeSort (CoalgCat.{v} R) (Type v) :=
⟨(·.carrier)⟩
@[simp] theorem moduleCat_of_toModuleCat (X : CoalgCat.{v} R) :
ModuleCat.of R X.toModuleCat = X.toModuleCat :=
rfl
variable (R) in
/-- The object in the category of `R`-coalgebras associated to an `R`-coalgebra. -/
abbrev of (X : Type v) [AddCommGroup X] [Module R X] [Coalgebra R X] :
CoalgCat R :=
{ ModuleCat.of R X with
instCoalgebra := (inferInstance : Coalgebra R X) }
@[simp]
lemma of_comul {X : Type v} [AddCommGroup X] [Module R X] [Coalgebra R X] :
Coalgebra.comul (A := of R X) = Coalgebra.comul (R := R) (A := X) := rfl
@[simp]
lemma of_counit {X : Type v} [AddCommGroup X] [Module R X] [Coalgebra R X] :
Coalgebra.counit (A := of R X) = Coalgebra.counit (R := R) (A := X) := rfl
/-- A type alias for `CoalgHom` to avoid confusion between the categorical and
algebraic spellings of composition. -/
@[ext]
structure Hom (V W : CoalgCat.{v} R) where
/-- The underlying `CoalgHom` -/
toCoalgHom' : V →ₗc[R] W
instance category : Category (CoalgCat.{v} R) where
Hom M N := Hom M N
id M := ⟨CoalgHom.id R M⟩
comp f g := ⟨CoalgHom.comp g.toCoalgHom' f.toCoalgHom'⟩
instance concreteCategory : ConcreteCategory (CoalgCat.{v} R) (· →ₗc[R] ·) where
hom f := f.toCoalgHom'
ofHom f := ⟨f⟩
/-- Turn a morphism in `CoalgCat` back into a `CoalgHom`. -/
abbrev Hom.toCoalgHom {X Y : CoalgCat.{v} R} (f : Hom X Y) : X →ₗc[R] Y :=
ConcreteCategory.hom (C := CoalgCat.{v} R) f
/-- Typecheck a `CoalgHom` as a morphism in `CoalgCat R`. -/
abbrev ofHom {X Y : Type v} [AddCommGroup X] [Module R X] [AddCommGroup Y] [Module R Y]
[Coalgebra R X] [Coalgebra R Y] (f : X →ₗc[R] Y) :
of R X ⟶ of R Y :=
ConcreteCategory.ofHom f
lemma Hom.toCoalgHom_injective (V W : CoalgCat.{v} R) :
Function.Injective (Hom.toCoalgHom' : Hom V W → _) :=
fun ⟨f⟩ ⟨g⟩ _ => by congr
@[ext]
lemma hom_ext {M N : CoalgCat.{v} R} (f g : M ⟶ N) (h : f.toCoalgHom = g.toCoalgHom) :
f = g :=
Hom.ext h
@[simp] theorem toCoalgHom_comp {M N U : CoalgCat.{v} R} (f : M ⟶ N) (g : N ⟶ U) :
(f ≫ g).toCoalgHom = g.toCoalgHom.comp f.toCoalgHom :=
rfl
@[simp] theorem toCoalgHom_id {M : CoalgCat.{v} R} :
Hom.toCoalgHom (𝟙 M) = CoalgHom.id _ _ :=
rfl
instance hasForgetToModule : HasForget₂ (CoalgCat R) (ModuleCat R) where
forget₂ :=
{ obj := fun M => ModuleCat.of R M
map := fun f => ModuleCat.ofHom f.toCoalgHom.toLinearMap }
@[simp]
theorem forget₂_obj (X : CoalgCat R) :
(forget₂ (CoalgCat R) (ModuleCat R)).obj X = ModuleCat.of R X :=
rfl
@[simp]
theorem forget₂_map (X Y : CoalgCat R) (f : X ⟶ Y) :
(forget₂ (CoalgCat R) (ModuleCat R)).map f = ModuleCat.ofHom (f.toCoalgHom : X →ₗ[R] Y) :=
rfl
end CoalgCat
namespace CoalgEquiv
open CoalgCat
variable {X Y Z : Type v}
variable [AddCommGroup X] [Module R X] [AddCommGroup Y] [Module R Y] [AddCommGroup Z] [Module R Z]
variable [Coalgebra R X] [Coalgebra R Y] [Coalgebra R Z]
/-- Build an isomorphism in the category `CoalgCat R` from a
`CoalgEquiv`. -/
@[simps]
def toCoalgIso (e : X ≃ₗc[R] Y) : CoalgCat.of R X ≅ CoalgCat.of R Y where
hom := CoalgCat.ofHom e
inv := CoalgCat.ofHom e.symm
hom_inv_id := Hom.ext <| DFunLike.ext _ _ e.left_inv
inv_hom_id := Hom.ext <| DFunLike.ext _ _ e.right_inv
@[simp] theorem toCoalgIso_refl :
toCoalgIso (CoalgEquiv.refl R X) = .refl _ :=
rfl
@[simp] theorem toCoalgIso_symm (e : X ≃ₗc[R] Y) :
toCoalgIso e.symm = (toCoalgIso e).symm :=
rfl
@[simp] theorem toCoalgIso_trans (e : X ≃ₗc[R] Y) (f : Y ≃ₗc[R] Z) :
toCoalgIso (e.trans f) = toCoalgIso e ≪≫ toCoalgIso f :=
rfl
end CoalgEquiv
namespace CategoryTheory.Iso
open Coalgebra
variable {X Y Z : CoalgCat.{v} R}
/-- Build a `CoalgEquiv` from an isomorphism in the category
`CoalgCat R`. -/
def toCoalgEquiv (i : X ≅ Y) : X ≃ₗc[R] Y :=
{ i.hom.toCoalgHom with
invFun := i.inv.toCoalgHom
left_inv := fun x => CoalgHom.congr_fun (congr_arg CoalgCat.Hom.toCoalgHom i.3) x
right_inv := fun x => CoalgHom.congr_fun (congr_arg CoalgCat.Hom.toCoalgHom i.4) x }
@[simp] theorem toCoalgEquiv_toCoalgHom (i : X ≅ Y) :
i.toCoalgEquiv = i.hom.toCoalgHom := rfl
@[simp] theorem toCoalgEquiv_refl : toCoalgEquiv (.refl X) = .refl _ _ :=
rfl
@[simp] theorem toCoalgEquiv_symm (e : X ≅ Y) :
toCoalgEquiv e.symm = (toCoalgEquiv e).symm :=
rfl
@[simp] theorem toCoalgEquiv_trans (e : X ≅ Y) (f : Y ≅ Z) :
toCoalgEquiv (e ≪≫ f) = e.toCoalgEquiv.trans f.toCoalgEquiv :=
rfl
end CategoryTheory.Iso
instance CoalgCat.forget_reflects_isos :
(forget (CoalgCat.{v} R)).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget (CoalgCat.{v} R)).map f)
let e : X ≃ₗc[R] Y := { f.toCoalgHom, i.toEquiv with }
exact ⟨e.toCoalgIso.isIso_hom.1⟩ |
.lake/packages/mathlib/Mathlib/Algebra/Category/CoalgCat/ComonEquivalence.lean | import Mathlib.Algebra.Category.CoalgCat.Basic
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Symmetric
import Mathlib.CategoryTheory.Monoidal.Braided.Opposite
import Mathlib.CategoryTheory.Monoidal.Comon_
import Mathlib.LinearAlgebra.TensorProduct.Tower
import Mathlib.RingTheory.Coalgebra.TensorProduct
/-!
# The category equivalence between `R`-coalgebras and comonoid objects in `R-Mod`
Given a commutative ring `R`, this file defines the equivalence of categories between
`R`-coalgebras and comonoid objects in the category of `R`-modules.
We then use this to set up boilerplate for the `Coalgebra` instance on a tensor product of
coalgebras defined in `Mathlib/RingTheory/Coalgebra/TensorProduct.lean`.
## Implementation notes
We make the definition `CoalgCat.instMonoidalCategoryAux` in this file, which is the
monoidal structure on `CoalgCat` induced by the equivalence with `Comon(R-Mod)`. We
use this to show the comultiplication and counit on a tensor product of coalgebras satisfy
the coalgebra axioms, but our actual `MonoidalCategory` instance on `CoalgCat` is
constructed in `Mathlib/Algebra/Category/CoalgCat/Monoidal.lean` to have better
definitional equalities.
-/
suppress_compilation
universe v u
namespace CoalgCat
open CategoryTheory MonoidalCategory ComonObj
variable {R : Type u} [CommRing R]
@[simps counit comul]
noncomputable instance (X : CoalgCat R) : ComonObj (ModuleCat.of R X) where
counit := ModuleCat.ofHom Coalgebra.counit
comul := ModuleCat.ofHom Coalgebra.comul
counit_comul := ModuleCat.hom_ext <| by simpa using Coalgebra.rTensor_counit_comp_comul
comul_counit := ModuleCat.hom_ext <| by simpa using Coalgebra.lTensor_counit_comp_comul
comul_assoc := ModuleCat.hom_ext <| by simp_rw [ModuleCat.of_coe]; exact Coalgebra.coassoc.symm
/-- An `R`-coalgebra is a comonoid object in the category of `R`-modules. -/
@[simps X]
noncomputable def toComonObj (X : CoalgCat R) : Comon (ModuleCat R) := ⟨ModuleCat.of R X⟩
variable (R) in
/-- The natural functor from `R`-coalgebras to comonoid objects in the category of `R`-modules. -/
@[simps]
def toComon : CoalgCat R ⥤ Comon (ModuleCat R) where
obj X := toComonObj X
map f :=
{ hom := ModuleCat.ofHom f.1
isComonHom_hom :=
{ hom_counit := ModuleCat.hom_ext f.1.counit_comp
hom_comul := ModuleCat.hom_ext f.1.map_comp_comul.symm } }
/-- A comonoid object in the category of `R`-modules has a natural comultiplication
and counit. -/
@[simps]
noncomputable instance ofComonObjCoalgebraStruct (X : ModuleCat R) [ComonObj X] :
CoalgebraStruct R X where
comul := Δ[X].hom
counit := ε[X].hom
/-- A comonoid object in the category of `R`-modules has a natural `R`-coalgebra
structure. -/
noncomputable def ofComonObj (X : ModuleCat R) [ComonObj X] : CoalgCat R :=
{ ModuleCat.of R X with
instCoalgebra :=
{ ofComonObjCoalgebraStruct X with
coassoc := ModuleCat.hom_ext_iff.mp (comul_assoc X).symm
rTensor_counit_comp_comul := ModuleCat.hom_ext_iff.mp (counit_comul X)
lTensor_counit_comp_comul := ModuleCat.hom_ext_iff.mp (comul_counit X) } }
variable (R)
/-- The natural functor from comonoid objects in the category of `R`-modules to `R`-coalgebras. -/
noncomputable def ofComon : Comon (ModuleCat R) ⥤ CoalgCat R where
obj X := ofComonObj X.X
map f :=
{ toCoalgHom' :=
{ f.hom.hom with
counit_comp := ModuleCat.hom_ext_iff.mp (IsComonHom.hom_counit f.hom)
map_comp_comul := ModuleCat.hom_ext_iff.mp ((IsComonHom.hom_comul f.hom).symm) } }
/-- The natural category equivalence between `R`-coalgebras and comonoid objects in the
category of `R`-modules. -/
@[simps]
def comonEquivalence : CoalgCat R ≌ Comon (ModuleCat R) where
functor := toComon R
inverse := ofComon R
unitIso := NatIso.ofComponents (fun _ => Iso.refl _) fun _ => by rfl
counitIso := NatIso.ofComponents (fun _ => Iso.refl _) fun _ => by rfl
variable {R}
/-- The monoidal category structure on the category of `R`-coalgebras induced by the
equivalence with `Comon(R-Mod)`. This is just an auxiliary definition; the `MonoidalCategory`
instance we make in `Mathlib/Algebra/Category/CoalgCat/Monoidal.lean` has better
definitional equalities. -/
noncomputable def instMonoidalCategoryAux : MonoidalCategory (CoalgCat R) :=
Monoidal.transport (comonEquivalence R).symm
namespace MonoidalCategoryAux
variable {M N P Q : Type u} [AddCommGroup M] [AddCommGroup N] [AddCommGroup P] [AddCommGroup Q]
[Module R M] [Module R N] [Module R P] [Module R Q] [Coalgebra R M] [Coalgebra R N]
[Coalgebra R P] [Coalgebra R Q]
attribute [local instance] instMonoidalCategoryAux
open MonoidalCategory ModuleCat.MonoidalCategory
theorem tensorObj_comul (K L : CoalgCat R) :
Coalgebra.comul (R := R) (A := (K ⊗ L : CoalgCat R))
= (TensorProduct.tensorTensorTensorComm R K K L L).toLinearMap
∘ₗ TensorProduct.map Coalgebra.comul Coalgebra.comul := by
rw [ofComonObjCoalgebraStruct_comul]
simp only [Comon.monoidal_tensorObj_comon_comul, Equivalence.symm_inverse,
comonEquivalence_functor, toComon_obj, toComonObj_X, ModuleCat.of_coe,
MonObj.tensorObj.mul_def, unop_comp, unop_tensorObj, unop_tensorHom,
BraidedCategory.unop_tensorμ, tensorμ_eq_tensorTensorTensorComm, ModuleCat.hom_comp,
ModuleCat.hom_ofHom, LinearEquiv.comp_toLinearMap_eq_iff]
rfl
theorem tensorHom_toLinearMap (f : M →ₗc[R] N) (g : P →ₗc[R] Q) :
(CoalgCat.ofHom f ⊗ₘ CoalgCat.ofHom g).1.toLinearMap
= TensorProduct.map f.toLinearMap g.toLinearMap := rfl
theorem associator_hom_toLinearMap :
(α_ (CoalgCat.of R M) (CoalgCat.of R N) (CoalgCat.of R P)).hom.1.toLinearMap
= (TensorProduct.assoc R M N P).toLinearMap :=
TensorProduct.ext <| TensorProduct.ext <| by ext; rfl
theorem leftUnitor_hom_toLinearMap :
(λ_ (CoalgCat.of R M)).hom.1.toLinearMap = (TensorProduct.lid R M).toLinearMap :=
TensorProduct.ext <| by ext; rfl
theorem rightUnitor_hom_toLinearMap :
(ρ_ (CoalgCat.of R M)).hom.1.toLinearMap = (TensorProduct.rid R M).toLinearMap :=
TensorProduct.ext <| by ext; rfl
open TensorProduct
attribute [local simp] MonObj.tensorObj.one_def MonObj.tensorObj.mul_def in
theorem comul_tensorObj :
Coalgebra.comul (R := R) (A := (CoalgCat.of R M ⊗ CoalgCat.of R N : CoalgCat R))
= Coalgebra.comul (A := M ⊗[R] N) := by
rw [ofComonObjCoalgebraStruct_comul]
simp [tensorμ_eq_tensorTensorTensorComm, TensorProduct.comul_def,
AlgebraTensorModule.tensorTensorTensorComm_eq]
rfl
attribute [local simp] MonObj.tensorObj.one_def MonObj.tensorObj.mul_def in
theorem comul_tensorObj_tensorObj_right :
Coalgebra.comul (R := R) (A := (CoalgCat.of R M ⊗
(CoalgCat.of R N ⊗ CoalgCat.of R P) : CoalgCat R))
= Coalgebra.comul (A := M ⊗[R] (N ⊗[R] P)) := by
rw [ofComonObjCoalgebraStruct_comul]
simp only [Comon.monoidal_tensorObj_comon_comul]
simp [tensorμ_eq_tensorTensorTensorComm, TensorProduct.comul_def,
AlgebraTensorModule.tensorTensorTensorComm_eq]
rfl
attribute [local simp] MonObj.tensorObj.one_def MonObj.tensorObj.mul_def in
theorem comul_tensorObj_tensorObj_left :
Coalgebra.comul (R := R)
(A := ((CoalgCat.of R M ⊗ CoalgCat.of R N) ⊗ CoalgCat.of R P : CoalgCat R))
= Coalgebra.comul (A := M ⊗[R] N ⊗[R] P) := by
rw [ofComonObjCoalgebraStruct_comul]
dsimp
simp only [toComonObj]
simp [tensorμ_eq_tensorTensorTensorComm, TensorProduct.comul_def,
AlgebraTensorModule.tensorTensorTensorComm_eq]
rfl
theorem counit_tensorObj :
Coalgebra.counit (R := R) (A := (CoalgCat.of R M ⊗ CoalgCat.of R N : CoalgCat R))
= Coalgebra.counit (A := M ⊗[R] N) := by
rw [ofComonObjCoalgebraStruct_counit]
simp [TensorProduct.counit_def, TensorProduct.AlgebraTensorModule.rid_eq_rid, ← lid_eq_rid]
rfl
theorem counit_tensorObj_tensorObj_right :
Coalgebra.counit (R := R)
(A := (CoalgCat.of R M ⊗ (CoalgCat.of R N ⊗ CoalgCat.of R P) : CoalgCat R))
= Coalgebra.counit (A := M ⊗[R] (N ⊗[R] P)) := by
rw [ofComonObjCoalgebraStruct_counit]
simp [TensorProduct.counit_def, TensorProduct.AlgebraTensorModule.rid_eq_rid, ← lid_eq_rid]
rfl
theorem counit_tensorObj_tensorObj_left :
Coalgebra.counit (R := R)
(A := ((CoalgCat.of R M ⊗ CoalgCat.of R N) ⊗ CoalgCat.of R P : CoalgCat R))
= Coalgebra.counit (A := (M ⊗[R] N) ⊗[R] P) := by
rw [ofComonObjCoalgebraStruct_counit]
simp [TensorProduct.counit_def, TensorProduct.AlgebraTensorModule.rid_eq_rid, ← lid_eq_rid]
rfl
end CoalgCat.MonoidalCategoryAux |
.lake/packages/mathlib/Mathlib/Algebra/Category/MonCat/Yoneda.lean | import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.CategoryTheory.Yoneda
/-!
# Yoneda embeddings
This file defines a few Yoneda embeddings for the category of commutative monoids.
-/
open CategoryTheory
universe u
/-- The `CommMonCat`-valued coyoneda embedding. -/
@[to_additive (attr := simps) /-- The `AddCommMonCat`-valued coyoneda embedding. -/]
def CommMonCat.coyoneda : CommMonCatᵒᵖ ⥤ CommMonCat ⥤ CommMonCat where
obj M := { obj N := of (M.unop →* N), map f := ofHom (.compHom f.hom) }
map f := { app N := ofHom (.compHom' f.unop.hom) }
/-- The `CommMonCat`-valued coyoneda embedding composed with the forgetful functor is the usual
coyoneda embedding. -/
@[to_additive (attr := simps!)
/-- The `AddCommMonCat`-valued coyoneda embedding composed with the forgetful functor is the usual
coyoneda embedding. -/]
def CommMonCat.coyonedaForget :
coyoneda ⋙ (Functor.whiskeringRight _ _ _).obj (forget _) ≅ CategoryTheory.coyoneda :=
NatIso.ofComponents fun X ↦ NatIso.ofComponents fun Y ↦ { hom f := ofHom f, inv f := f.hom }
/-- The Hom bifunctor sending a type `X` and a commutative monoid `M` to the commutative monoid
`X → M` with pointwise operations.
This is also the coyoneda embedding of `Type` into `CommMonCat`-valued presheaves of commutative
monoids. -/
@[to_additive (attr := simps)
/-- The Hom bifunctor sending a type `X` and a commutative monoid `M` to the commutative monoid
`X → M` with pointwise operations.
This is also the coyoneda embedding of `Type` into `AddCommMonCat`-valued presheaves of commutative
monoids. -/]
def CommMonCat.coyonedaType : (Type u)ᵒᵖ ⥤ CommMonCat.{u} ⥤ CommMonCat.{u} where
obj X := { obj M := of <| X.unop → M
map f := ofHom <| Pi.monoidHom fun i ↦ f.hom.comp <| Pi.evalMonoidHom _ i }
map f := { app N := ofHom <| Pi.monoidHom fun i ↦ Pi.evalMonoidHom _ <| f.unop i } |
.lake/packages/mathlib/Mathlib/Algebra/Category/MonCat/Basic.lean | import Mathlib.Algebra.Group.PUnit
import Mathlib.Algebra.Group.TypeTags.Hom
import Mathlib.Algebra.Group.ULift
import Mathlib.CategoryTheory.Elementwise
import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic
/-!
# Category instances for `Monoid`, `AddMonoid`, `CommMonoid`, and `AddCommMonoid`.
We introduce the bundled categories:
* `MonCat`
* `AddMonCat`
* `CommMonCat`
* `AddCommMonCat`
along with the relevant forgetful functors between them.
-/
assert_not_exists MonoidWithZero
universe u v
open CategoryTheory
/-- The category of additive monoids and monoid morphisms. -/
structure AddMonCat : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : AddMonoid carrier]
/-- The category of monoids and monoid morphisms. -/
@[to_additive AddMonCat]
structure MonCat : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : Monoid carrier]
attribute [instance] AddMonCat.str MonCat.str
initialize_simps_projections AddMonCat (carrier → coe, -str)
initialize_simps_projections MonCat (carrier → coe, -str)
namespace MonCat
@[to_additive]
instance : CoeSort MonCat (Type u) :=
⟨MonCat.carrier⟩
attribute [coe] AddMonCat.carrier MonCat.carrier
/-- Construct a bundled `MonCat` from the underlying type and typeclass. -/
@[to_additive /-- Construct a bundled `AddMonCat` from the underlying type and typeclass. -/]
abbrev of (M : Type u) [Monoid M] : MonCat := ⟨M⟩
end MonCat
/-- The type of morphisms in `AddMonCat`. -/
@[ext]
structure AddMonCat.Hom (A B : AddMonCat.{u}) where
private mk ::
/-- The underlying monoid homomorphism. -/
hom' : A →+ B
/-- The type of morphisms in `MonCat`. -/
@[to_additive, ext]
structure MonCat.Hom (A B : MonCat.{u}) where
private mk ::
/-- The underlying monoid homomorphism. -/
hom' : A →* B
namespace MonCat
@[to_additive]
instance : Category MonCat.{u} where
Hom X Y := Hom X Y
id X := ⟨MonoidHom.id X⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
@[to_additive]
instance : ConcreteCategory MonCat (· →* ·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `MonCat` back into a `MonoidHom`. -/
@[to_additive /-- Turn a morphism in `AddMonCat` back into an `AddMonoidHom`. -/]
abbrev Hom.hom {X Y : MonCat.{u}} (f : Hom X Y) :=
ConcreteCategory.hom (C := MonCat) f
/-- Typecheck a `MonoidHom` as a morphism in `MonCat`. -/
@[to_additive /-- Typecheck an `AddMonoidHom` as a morphism in `AddMonCat`. -/]
abbrev ofHom {X Y : Type u} [Monoid X] [Monoid Y] (f : X →* Y) : of X ⟶ of Y :=
ConcreteCategory.ofHom (C := MonCat) f
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (X Y : MonCat.{u}) (f : Hom X Y) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
initialize_simps_projections AddMonCat.Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[to_additive (attr := simp)]
lemma coe_id {X : MonCat} : (𝟙 X : X → X) = id := rfl
@[to_additive (attr := simp)]
lemma coe_comp {X Y Z : MonCat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
@[to_additive (attr := simp)]
lemma forget_map {X Y : MonCat} (f : X ⟶ Y) :
(forget MonCat).map f = f := rfl
@[to_additive (attr := ext)]
lemma ext {X Y : MonCat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g :=
ConcreteCategory.hom_ext _ _ w
@[to_additive]
-- This is not `simp` to avoid rewriting in types of terms.
theorem coe_of (M : Type u) [Monoid M] : (MonCat.of M : Type u) = M := rfl
@[to_additive (attr := simp)]
lemma hom_id {M : MonCat} : (𝟙 M : M ⟶ M).hom = MonoidHom.id M := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma id_apply (M : MonCat) (x : M) :
(𝟙 M : M ⟶ M) x = x := by simp
@[to_additive (attr := simp)]
lemma hom_comp {M N T : MonCat} (f : M ⟶ N) (g : N ⟶ T) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma comp_apply {M N T : MonCat} (f : M ⟶ N) (g : N ⟶ T) (x : M) :
(f ≫ g) x = g (f x) := by simp
@[to_additive (attr := ext)]
lemma hom_ext {M N : MonCat} {f g : M ⟶ N} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[to_additive (attr := simp)]
lemma hom_ofHom {M N : Type u} [Monoid M] [Monoid N] (f : M →* N) : (ofHom f).hom = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_hom {M N : MonCat} (f : M ⟶ N) :
ofHom (Hom.hom f) = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_id {M : Type u} [Monoid M] : ofHom (MonoidHom.id M) = 𝟙 (of M) := rfl
@[to_additive (attr := simp)]
lemma ofHom_comp {M N P : Type u} [Monoid M] [Monoid N] [Monoid P]
(f : M →* N) (g : N →* P) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
@[to_additive]
lemma ofHom_apply {X Y : Type u} [Monoid X] [Monoid Y] (f : X →* Y) (x : X) :
(ofHom f) x = f x := rfl
@[to_additive]
lemma inv_hom_apply {M N : MonCat} (e : M ≅ N) (x : M) : e.inv (e.hom x) = x := by
simp
@[to_additive]
lemma hom_inv_apply {M N : MonCat} (e : M ≅ N) (s : N) : e.hom (e.inv s) = s := by
simp
@[to_additive]
instance : Inhabited MonCat :=
-- The default instance for `Monoid PUnit` is derived via `CommRing` which breaks to_additive
⟨@of PUnit (@DivInvMonoid.toMonoid _ (@Group.toDivInvMonoid _
(@CommGroup.toGroup _ PUnit.commGroup)))⟩
@[to_additive]
instance (X Y : MonCat.{u}) : One (X ⟶ Y) := ⟨ofHom 1⟩
@[to_additive (attr := simp)]
lemma hom_one (X Y : MonCat.{u}) : (1 : X ⟶ Y).hom = 1 := rfl
@[to_additive]
lemma oneHom_apply (X Y : MonCat.{u}) (x : X) : (1 : X ⟶ Y).hom x = 1 := rfl
@[to_additive (attr := simp)]
lemma one_of {A : Type*} [Monoid A] : (1 : MonCat.of A) = (1 : A) := rfl
@[to_additive (attr := simp)]
lemma mul_of {A : Type*} [Monoid A] (a b : A) :
@HMul.hMul (MonCat.of A) (MonCat.of A) (MonCat.of A) _ a b = a * b := rfl
/-- Universe lift functor for monoids. -/
@[to_additive (attr := simps)
/-- Universe lift functor for additive monoids. -/]
def uliftFunctor : MonCat.{v} ⥤ MonCat.{max v u} where
obj X := MonCat.of (ULift.{u, v} X)
map {_ _} f := MonCat.ofHom <|
MulEquiv.ulift.symm.toMonoidHom.comp <| f.hom.comp MulEquiv.ulift.toMonoidHom
map_id X := by rfl
map_comp {X Y Z} f g := by rfl
end MonCat
/-- The category of additive commutative monoids and monoid morphisms. -/
structure AddCommMonCat : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : AddCommMonoid carrier]
/-- The category of commutative monoids and monoid morphisms. -/
@[to_additive AddCommMonCat]
structure CommMonCat : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : CommMonoid carrier]
attribute [instance] AddCommMonCat.str CommMonCat.str
initialize_simps_projections AddCommMonCat (carrier → coe, -str)
initialize_simps_projections CommMonCat (carrier → coe, -str)
namespace CommMonCat
@[to_additive]
instance : CoeSort CommMonCat (Type u) :=
⟨CommMonCat.carrier⟩
attribute [coe] AddCommMonCat.carrier CommMonCat.carrier
/-- Construct a bundled `CommMonCat` from the underlying type and typeclass. -/
@[to_additive /-- Construct a bundled `AddCommMonCat` from the underlying type and typeclass. -/]
abbrev of (M : Type u) [CommMonoid M] : CommMonCat := ⟨M⟩
end CommMonCat
/-- The type of morphisms in `AddCommMonCat`. -/
@[ext]
structure AddCommMonCat.Hom (A B : AddCommMonCat.{u}) where
private mk ::
/-- The underlying monoid homomorphism. -/
hom' : A →+ B
/-- The type of morphisms in `CommMonCat`. -/
@[to_additive, ext]
structure CommMonCat.Hom (A B : CommMonCat.{u}) where
private mk ::
/-- The underlying monoid homomorphism. -/
hom' : A →* B
namespace CommMonCat
@[to_additive]
instance : Category CommMonCat.{u} where
Hom X Y := Hom X Y
id X := ⟨MonoidHom.id X⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
@[to_additive]
instance : ConcreteCategory CommMonCat (· →* ·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `CommMonCat` back into a `MonoidHom`. -/
@[to_additive /-- Turn a morphism in `AddCommMonCat` back into an `AddMonoidHom`. -/]
abbrev Hom.hom {X Y : CommMonCat.{u}} (f : Hom X Y) :=
ConcreteCategory.hom (C := CommMonCat) f
/-- Typecheck a `MonoidHom` as a morphism in `CommMonCat`. -/
@[to_additive /-- Typecheck an `AddMonoidHom` as a morphism in `AddCommMonCat`. -/]
abbrev ofHom {X Y : Type u} [CommMonoid X] [CommMonoid Y] (f : X →* Y) : of X ⟶ of Y :=
ConcreteCategory.ofHom (C := CommMonCat) f
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
@[to_additive /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/]
def Hom.Simps.hom (X Y : CommMonCat.{u}) (f : Hom X Y) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
initialize_simps_projections AddCommMonCat.Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[to_additive (attr := simp)]
lemma coe_id {X : CommMonCat} : (𝟙 X : X → X) = id := rfl
@[to_additive (attr := simp)]
lemma coe_comp {X Y Z : CommMonCat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
@[to_additive (attr := simp)]
lemma forget_map {X Y : CommMonCat} (f : X ⟶ Y) :
(forget CommMonCat).map f = (f : X → Y) :=
rfl
@[to_additive (attr := ext)]
lemma ext {X Y : CommMonCat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g :=
ConcreteCategory.hom_ext _ _ w
@[to_additive (attr := simp)]
lemma hom_id {M : CommMonCat} : (𝟙 M : M ⟶ M).hom = MonoidHom.id M := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma id_apply (M : CommMonCat) (x : M) :
(𝟙 M : M ⟶ M) x = x := by simp
@[to_additive (attr := simp)]
lemma hom_comp {M N T : CommMonCat} (f : M ⟶ N) (g : N ⟶ T) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma comp_apply {M N T : CommMonCat} (f : M ⟶ N) (g : N ⟶ T) (x : M) :
(f ≫ g) x = g (f x) := by simp
@[to_additive (attr := ext)]
lemma hom_ext {M N : CommMonCat} {f g : M ⟶ N} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[to_additive (attr := simp)]
lemma hom_ofHom {M N : Type u} [CommMonoid M] [CommMonoid N] (f : M →* N) : (ofHom f).hom = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_hom {M N : CommMonCat} (f : M ⟶ N) :
ofHom (Hom.hom f) = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_id {M : Type u} [CommMonoid M] : ofHom (MonoidHom.id M) = 𝟙 (of M) := rfl
@[to_additive (attr := simp)]
lemma ofHom_comp {M N P : Type u} [CommMonoid M] [CommMonoid N] [CommMonoid P]
(f : M →* N) (g : N →* P) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
@[to_additive]
lemma ofHom_apply {X Y : Type u} [CommMonoid X] [CommMonoid Y] (f : X →* Y) (x : X) :
(ofHom f) x = f x := rfl
@[to_additive]
lemma inv_hom_apply {M N : CommMonCat} (e : M ≅ N) (x : M) : e.inv (e.hom x) = x := by
simp
@[to_additive]
lemma hom_inv_apply {M N : CommMonCat} (e : M ≅ N) (s : N) : e.hom (e.inv s) = s := by
simp
@[to_additive]
instance : Inhabited CommMonCat :=
-- The default instance for `CommMonoid PUnit` is derived via `CommRing` which breaks to_additive
⟨@of PUnit (@CommGroup.toCommMonoid _ PUnit.commGroup)⟩
@[to_additive]
theorem coe_of (R : Type u) [CommMonoid R] : (CommMonCat.of R : Type u) = R :=
rfl
@[to_additive hasForgetToAddMonCat]
instance hasForgetToMonCat : HasForget₂ CommMonCat MonCat where
forget₂ :=
{ obj R := MonCat.of R
map f := MonCat.ofHom f.hom }
@[to_additive (attr := simp)] lemma coe_forget₂_obj (X : CommMonCat) :
((forget₂ CommMonCat MonCat).obj X : Type _) = X := rfl
@[to_additive (attr := simp)] lemma hom_forget₂_map {X Y : CommMonCat}
(f : X ⟶ Y) :
((forget₂ CommMonCat MonCat).map f).hom = f.hom := rfl
@[to_additive (attr := simp)] lemma forget₂_map_ofHom {X Y : Type u} [CommMonoid X] [CommMonoid Y]
(f : X →* Y) :
(forget₂ CommMonCat MonCat).map (ofHom f) = MonCat.ofHom f := rfl
/-- The forgetful functor from `CommMonCat` to `MonCat` is fully faithful. -/
@[to_additive fullyFaithfulForgetToAddMonCat
/-- The forgetful functor from `AddCommMonCat` to `AddMonCat` is fully faithful. -/]
def fullyFaithfulForgetToMonCat : (forget₂ CommMonCat.{u} MonCat.{u}).FullyFaithful where
preimage f := ofHom f.hom
@[to_additive]
instance : (forget₂ CommMonCat.{u} MonCat.{u}).Full :=
fullyFaithfulForgetToMonCat.full
@[to_additive]
instance : Coe CommMonCat.{u} MonCat.{u} where coe := (forget₂ CommMonCat MonCat).obj
/-- Universe lift functor for commutative monoids. -/
@[to_additive (attr := simps)
/-- Universe lift functor for additive commutative monoids. -/]
def uliftFunctor : CommMonCat.{v} ⥤ CommMonCat.{max v u} where
obj X := CommMonCat.of (ULift.{u, v} X)
map {_ _} f := CommMonCat.ofHom <|
MulEquiv.ulift.symm.toMonoidHom.comp <| f.hom.comp MulEquiv.ulift.toMonoidHom
map_id X := by rfl
map_comp {X Y Z} f g := by rfl
end CommMonCat
variable {X Y : Type u}
section
variable [Monoid X] [Monoid Y]
/-- Build an isomorphism in the category `MonCat` from a `MulEquiv` between `Monoid`s. -/
@[to_additive (attr := simps) AddEquiv.toAddMonCatIso
/-- Build an isomorphism in the category `AddMonCat` from
an `AddEquiv` between `AddMonoid`s. -/]
def MulEquiv.toMonCatIso (e : X ≃* Y) : MonCat.of X ≅ MonCat.of Y where
hom := MonCat.ofHom e.toMonoidHom
inv := MonCat.ofHom e.symm.toMonoidHom
end
section
variable [CommMonoid X] [CommMonoid Y]
/-- Build an isomorphism in the category `CommMonCat` from a `MulEquiv` between `CommMonoid`s. -/
@[to_additive (attr := simps) AddEquiv.toAddCommMonCatIso]
def MulEquiv.toCommMonCatIso (e : X ≃* Y) : CommMonCat.of X ≅ CommMonCat.of Y where
hom := CommMonCat.ofHom e.toMonoidHom
inv := CommMonCat.ofHom e.symm.toMonoidHom
/-- Build an isomorphism in the category `AddCommMonCat`
from an `AddEquiv` between `AddCommMonoid`s. -/
add_decl_doc AddEquiv.toAddCommMonCatIso
end
namespace CategoryTheory.Iso
/-- Build a `MulEquiv` from an isomorphism in the category `MonCat`. -/
@[to_additive addMonCatIsoToAddEquiv
/-- Build an `AddEquiv` from an isomorphism in the category
`AddMonCat`. -/]
def monCatIsoToMulEquiv {X Y : MonCat} (i : X ≅ Y) : X ≃* Y :=
MonoidHom.toMulEquiv i.hom.hom i.inv.hom (by ext; simp) (by ext; simp)
/-- Build a `MulEquiv` from an isomorphism in the category `CommMonCat`. -/
@[to_additive /-- Build an `AddEquiv` from an isomorphism in the category
`AddCommMonCat`. -/]
def commMonCatIsoToMulEquiv {X Y : CommMonCat} (i : X ≅ Y) : X ≃* Y :=
MonoidHom.toMulEquiv i.hom.hom i.inv.hom (by ext; simp) (by ext; simp)
end CategoryTheory.Iso
/-- multiplicative equivalences between `Monoid`s are the same as (isomorphic to) isomorphisms
in `MonCat` -/
@[to_additive addEquivIsoAddMonCatIso]
def mulEquivIsoMonCatIso {X Y : Type u} [Monoid X] [Monoid Y] :
X ≃* Y ≅ MonCat.of X ≅ MonCat.of Y where
hom e := e.toMonCatIso
inv i := i.monCatIsoToMulEquiv
/-- additive equivalences between `AddMonoid`s are the same
as (isomorphic to) isomorphisms in `AddMonCat` -/
add_decl_doc addEquivIsoAddMonCatIso
/-- multiplicative equivalences between `CommMonoid`s are the same as (isomorphic to) isomorphisms
in `CommMonCat` -/
@[to_additive addEquivIsoAddCommMonCatIso]
def mulEquivIsoCommMonCatIso {X Y : Type u} [CommMonoid X] [CommMonoid Y] :
X ≃* Y ≅ CommMonCat.of X ≅ CommMonCat.of Y where
hom e := e.toCommMonCatIso
inv i := i.commMonCatIsoToMulEquiv
/-- additive equivalences between `AddCommMonoid`s are
the same as (isomorphic to) isomorphisms in `AddCommMonCat` -/
add_decl_doc addEquivIsoAddCommMonCatIso
@[to_additive]
instance MonCat.forget_reflects_isos : (forget MonCat.{u}).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget MonCat).map f)
let e : X ≃* Y := { f.hom, i.toEquiv with }
exact e.toMonCatIso.isIso_hom
@[to_additive]
instance CommMonCat.forget_reflects_isos : (forget CommMonCat.{u}).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget CommMonCat).map f)
let e : X ≃* Y := { f.hom, i.toEquiv with }
exact e.toCommMonCatIso.isIso_hom
/-- Ensure that `forget₂ CommMonCat MonCat` automatically reflects isomorphisms.
We could have used `CategoryTheory.HasForget.ReflectsIso` alternatively.
-/
@[to_additive]
instance CommMonCat.forget₂_full : (forget₂ CommMonCat MonCat).Full where
map_surjective f := ⟨ofHom f.hom, rfl⟩
example : (forget₂ CommMonCat MonCat).ReflectsIsomorphisms := inferInstance
/-!
`@[simp]` lemmas for `MonoidHom.comp` and categorical identities.
-/
/-- The equivalence between `AddMonCat` and `MonCat`. -/
@[simps]
def AddMonCat.equivalence : AddMonCat ≌ MonCat where
functor := { obj X := .of (Multiplicative X), map f := MonCat.ofHom f.hom.toMultiplicative }
inverse := { obj X := .of (Additive X), map f := ofHom f.hom.toAdditive }
unitIso := Iso.refl _
counitIso := Iso.refl _
/-- The equivalence between `AddCommMonCat` and `CommMonCat`. -/
@[simps]
def AddCommMonCat.equivalence : AddCommMonCat ≌ CommMonCat where
functor := { obj X := .of (Multiplicative X), map f := CommMonCat.ofHom f.hom.toMultiplicative }
inverse := { obj X := .of (Additive X), map f := ofHom f.hom.toAdditive }
unitIso := Iso.refl _
counitIso := Iso.refl _ |
.lake/packages/mathlib/Mathlib/Algebra/Category/MonCat/FilteredColimits.lean | import Mathlib.CategoryTheory.Limits.Preserves.Filtered
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
import Mathlib.CategoryTheory.Limits.Types.Filtered
import Mathlib.Algebra.Category.MonCat.Basic
/-!
# The forgetful functor from (commutative) (additive) monoids preserves filtered colimits.
Forgetful functors from algebraic categories usually don't preserve colimits. However, they tend
to preserve _filtered_ colimits.
In this file, we start with a small filtered category `J` and a functor `F : J ⥤ MonCat`.
We then construct a monoid structure on the colimit of `F ⋙ forget MonCat` (in `Type`), thereby
showing that the forgetful functor `forget MonCat` preserves filtered colimits. Similarly for
`AddMonCat`, `CommMonCat` and `AddCommMonCat`.
-/
universe v u
noncomputable section
open CategoryTheory Limits
open IsFiltered renaming max → max' -- avoid name collision with `_root_.max`.
namespace MonCat.FilteredColimits
section
-- Porting note: mathlib 3 used `parameters` here, mainly so we can have the abbreviations `M` and
-- `M.mk` below, without passing around `F` all the time.
variable {J : Type v} [SmallCategory J] (F : J ⥤ MonCat.{max v u})
/-- The colimit of `F ⋙ forget MonCat` in the category of types.
In the following, we will construct a monoid structure on `M`.
-/
@[to_additive
/-- The colimit of `F ⋙ forget AddMon` in the category of types.
In the following, we will construct an additive monoid structure on `M`. -/]
abbrev M := (F ⋙ forget MonCat).ColimitType
/-- The canonical projection into the colimit, as a quotient type. -/
@[to_additive /-- The canonical projection into the colimit, as a quotient type. -/]
noncomputable abbrev M.mk : (Σ j, F.obj j) → M.{v, u} F :=
fun x ↦ (F ⋙ forget MonCat).ιColimitType x.1 x.2
@[to_additive]
lemma M.mk_surjective (m : M.{v, u} F) :
∃ (j : J) (x : F.obj j), M.mk F ⟨j, x⟩ = m :=
(F ⋙ forget MonCat).ιColimitType_jointly_surjective m
@[to_additive]
theorem M.mk_eq (x y : Σ j, F.obj j)
(h : ∃ (k : J) (f : x.1 ⟶ k) (g : y.1 ⟶ k), F.map f x.2 = F.map g y.2) :
M.mk.{v, u} F x = M.mk F y :=
Quot.eqvGen_sound (Types.FilteredColimit.eqvGen_colimitTypeRel_of_rel (F ⋙ forget MonCat) x y h)
@[to_additive]
lemma M.map_mk {j k : J} (f : j ⟶ k) (x : F.obj j) :
M.mk F ⟨k, F.map f x⟩ = M.mk F ⟨j, x⟩ :=
M.mk_eq _ _ _ ⟨k, 𝟙 _, f, by simp⟩
variable [IsFiltered J]
/-- As `J` is nonempty, we can pick an arbitrary object `j₀ : J`. We use this object to define the
"one" in the colimit as the equivalence class of `⟨j₀, 1 : F.obj j₀⟩`.
-/
@[to_additive
/-- As `J` is nonempty, we can pick an arbitrary object `j₀ : J`. We use this object to
define the "zero" in the colimit as the equivalence class of `⟨j₀, 0 : F.obj j₀⟩`. -/]
noncomputable instance colimitOne : One (M.{v, u} F) where
one := M.mk F ⟨IsFiltered.nonempty.some,1⟩
/-- The definition of the "one" in the colimit is independent of the chosen object of `J`.
In particular, this lemma allows us to "unfold" the definition of `colimit_one` at a custom chosen
object `j`.
-/
@[to_additive
/-- The definition of the "zero" in the colimit is independent of the chosen object
of `J`. In particular, this lemma allows us to "unfold" the definition of `colimit_zero` at
a custom chosen object `j`. -/]
theorem colimit_one_eq (j : J) : (1 : M.{v, u} F) = M.mk F ⟨j, 1⟩ := by
apply M.mk_eq
refine ⟨max' _ j, IsFiltered.leftToMax _ j, IsFiltered.rightToMax _ j, ?_⟩
simp
/-- The "unlifted" version of multiplication in the colimit. To multiply two dependent pairs
`⟨j₁, x⟩` and `⟨j₂, y⟩`, we pass to a common successor of `j₁` and `j₂` (given by `IsFiltered.max`)
and multiply them there.
-/
@[to_additive
/-- The "unlifted" version of addition in the colimit. To add two dependent pairs
`⟨j₁, x⟩` and `⟨j₂, y⟩`, we pass to a common successor of `j₁` and `j₂`
(given by `IsFiltered.max`) and add them there. -/]
noncomputable def colimitMulAux (x y : Σ j, F.obj j) : M.{v, u} F :=
M.mk F ⟨IsFiltered.max x.fst y.fst, F.map (IsFiltered.leftToMax x.1 y.1) x.2 *
F.map (IsFiltered.rightToMax x.1 y.1) y.2⟩
/-- Multiplication in the colimit is well-defined in the left argument. -/
@[to_additive /-- Addition in the colimit is well-defined in the left argument. -/]
theorem colimitMulAux_eq_of_rel_left {x x' y : Σ j, F.obj j}
(hxx' : Types.FilteredColimit.Rel (F ⋙ forget MonCat) x x') :
colimitMulAux.{v, u} F x y = colimitMulAux.{v, u} F x' y := by
obtain ⟨j₁, x⟩ := x; obtain ⟨j₂, y⟩ := y; obtain ⟨j₃, x'⟩ := x'
obtain ⟨l, f, g, hfg⟩ := hxx'
replace hfg : F.map f x = F.map g x' := by simpa
obtain ⟨s, α, β, γ, h₁, h₂, h₃⟩ :=
IsFiltered.tulip (IsFiltered.leftToMax j₁ j₂) (IsFiltered.rightToMax j₁ j₂)
(IsFiltered.rightToMax j₃ j₂) (IsFiltered.leftToMax j₃ j₂) f g
apply M.mk_eq
use s, α, γ
simp_rw [MonoidHom.map_mul, ← ConcreteCategory.comp_apply, ← F.map_comp, h₁, h₂, h₃, F.map_comp,
ConcreteCategory.comp_apply, hfg]
/-- Multiplication in the colimit is well-defined in the right argument. -/
@[to_additive /-- Addition in the colimit is well-defined in the right argument. -/]
theorem colimitMulAux_eq_of_rel_right {x y y' : Σ j, F.obj j}
(hyy' : Types.FilteredColimit.Rel (F ⋙ forget MonCat) y y') :
colimitMulAux.{v, u} F x y = colimitMulAux.{v, u} F x y' := by
obtain ⟨j₁, y⟩ := y; obtain ⟨j₂, x⟩ := x; obtain ⟨j₃, y'⟩ := y'
obtain ⟨l, f, g, hfg⟩ := hyy'
simp only [Functor.comp_obj, Functor.comp_map, forget_map] at hfg
obtain ⟨s, α, β, γ, h₁, h₂, h₃⟩ :=
IsFiltered.tulip (IsFiltered.rightToMax j₂ j₁) (IsFiltered.leftToMax j₂ j₁)
(IsFiltered.leftToMax j₂ j₃) (IsFiltered.rightToMax j₂ j₃) f g
apply M.mk_eq
use s, α, γ
dsimp
simp_rw [MonoidHom.map_mul, ← ConcreteCategory.comp_apply, ← F.map_comp, h₁, h₂, h₃, F.map_comp,
ConcreteCategory.comp_apply, hfg]
/-- Multiplication in the colimit. See also `colimitMulAux`. -/
@[to_additive /-- Addition in the colimit. See also `colimitAddAux`. -/]
noncomputable instance colimitMul : Mul (M.{v, u} F) :=
{ mul := fun x y => by
refine Quot.lift₂ (colimitMulAux F) ?_ ?_ x y
· intro x y y' h
apply colimitMulAux_eq_of_rel_right
apply Types.FilteredColimit.rel_of_colimitTypeRel
exact h
· intro x x' y h
apply colimitMulAux_eq_of_rel_left
apply Types.FilteredColimit.rel_of_colimitTypeRel
exact h }
/-- Multiplication in the colimit is independent of the chosen "maximum" in the filtered category.
In particular, this lemma allows us to "unfold" the definition of the multiplication of `x` and `y`,
using a custom object `k` and morphisms `f : x.1 ⟶ k` and `g : y.1 ⟶ k`.
-/
@[to_additive
/-- Addition in the colimit is independent of the chosen "maximum" in the filtered
category. In particular, this lemma allows us to "unfold" the definition of the addition of
`x` and `y`, using a custom object `k` and morphisms `f : x.1 ⟶ k` and `g : y.1 ⟶ k`. -/]
theorem colimit_mul_mk_eq (x y : Σ j, F.obj j) (k : J) (f : x.1 ⟶ k) (g : y.1 ⟶ k) :
M.mk.{v, u} F x * M.mk F y = M.mk F ⟨k, F.map f x.2 * F.map g y.2⟩ := by
obtain ⟨j₁, x⟩ := x; obtain ⟨j₂, y⟩ := y
obtain ⟨s, α, β, h₁, h₂⟩ := IsFiltered.bowtie (IsFiltered.leftToMax j₁ j₂) f
(IsFiltered.rightToMax j₁ j₂) g
refine M.mk_eq F _ _ ?_
use s, α, β
dsimp
simp_rw [MonoidHom.map_mul, ← ConcreteCategory.comp_apply, ← F.map_comp, h₁, h₂]
@[to_additive]
lemma colimit_mul_mk_eq' {j : J} (x y : F.obj j) :
M.mk.{v, u} F ⟨j, x⟩ * M.mk.{v, u} F ⟨j, y⟩ = M.mk.{v, u} F ⟨j, x * y⟩ := by
simpa using colimit_mul_mk_eq F ⟨j, x⟩ ⟨j, y⟩ j (𝟙 _) (𝟙 _)
@[to_additive]
noncomputable instance colimitMulOneClass : MulOneClass (M.{v, u} F) :=
{ colimitOne F,
colimitMul F with
one_mul := fun x => by
obtain ⟨j, x, rfl⟩ := x.mk_surjective
rw [colimit_one_eq F j, colimit_mul_mk_eq', one_mul]
mul_one := fun x => by
obtain ⟨j, x, rfl⟩ := x.mk_surjective
rw [colimit_one_eq F j, colimit_mul_mk_eq', mul_one] }
@[to_additive]
noncomputable instance colimitMonoid : Monoid (M.{v, u} F) :=
{ colimitMulOneClass F with
mul_assoc := fun x y z => by
obtain ⟨j₁, x₁, rfl⟩ := x.mk_surjective
obtain ⟨j₂, y₂, rfl⟩ := y.mk_surjective
obtain ⟨j₃, z₃, rfl⟩ := z.mk_surjective
obtain ⟨j, f₁, f₂, f₃, x, y, z, h₁, h₂, h₃⟩ :
∃ (j : J) (f₁ : j₁ ⟶ j) (f₂ : j₂ ⟶ j) (f₃ : j₃ ⟶ j) (x y z : F.obj j),
F.map f₁ x₁ = x ∧ F.map f₂ y₂ = y ∧ F.map f₃ z₃ = z :=
⟨IsFiltered.max₃ j₁ j₂ j₃, IsFiltered.firstToMax₃ _ _ _,
IsFiltered.secondToMax₃ _ _ _, IsFiltered.thirdToMax₃ _ _ _,
_, _, _, rfl, rfl, rfl⟩
simp only [← M.map_mk F f₁, ← M.map_mk F f₂, ← M.map_mk F f₃, h₁, h₂, h₃,
colimit_mul_mk_eq', mul_assoc] }
/-- The bundled monoid giving the filtered colimit of a diagram. -/
@[to_additive
/-- The bundled additive monoid giving the filtered colimit of a diagram. -/]
noncomputable def colimit : MonCat.{max v u} :=
MonCat.of (M.{v, u} F)
/-- The monoid homomorphism from a given monoid in the diagram to the colimit monoid. -/
@[to_additive
/-- The additive monoid homomorphism from a given additive monoid in the diagram to the
colimit additive monoid. -/]
noncomputable def coconeMorphism (j : J) : F.obj j ⟶ colimit F :=
ofHom
{ toFun := (Types.TypeMax.colimitCocone.{v, max v u, v} (F ⋙ forget MonCat)).ι.app j
map_one' := (colimit_one_eq F j).symm
map_mul' x y := by symm; apply colimit_mul_mk_eq' }
@[to_additive (attr := simp)]
theorem cocone_naturality {j j' : J} (f : j ⟶ j') :
F.map f ≫ coconeMorphism.{v, u} F j' = coconeMorphism F j :=
MonCat.ext fun x =>
congr_fun ((Types.TypeMax.colimitCocone (F ⋙ forget MonCat)).ι.naturality f) x
/-- The cocone over the proposed colimit monoid. -/
@[to_additive /-- The cocone over the proposed colimit additive monoid. -/]
noncomputable def colimitCocone : Cocone F where
pt := colimit.{v, u} F
ι := { app := coconeMorphism F }
/-- Given a cocone `t` of `F`, the induced monoid homomorphism from the colimit to the cocone point.
As a function, this is simply given by the induced map of the corresponding cocone in `Type`.
The only thing left to see is that it is a monoid homomorphism.
-/
@[to_additive
/-- Given a cocone `t` of `F`, the induced additive monoid homomorphism from the colimit
to the cocone point. As a function, this is simply given by the induced map of the
corresponding cocone in `Type`. The only thing left to see is that it is an additive monoid
homomorphism. -/]
noncomputable def colimitDesc (t : Cocone F) : colimit.{v, u} F ⟶ t.pt :=
ofHom
{ toFun := (F ⋙ forget MonCat).descColimitType
((F ⋙ forget MonCat).coconeTypesEquiv.symm ((forget MonCat).mapCocone t))
map_one' := by
rw [colimit_one_eq F IsFiltered.nonempty.some]
exact MonoidHom.map_one _
map_mul' x y := by
obtain ⟨i, x, rfl⟩ := x.mk_surjective
obtain ⟨j, y, rfl⟩ := y.mk_surjective
rw [colimit_mul_mk_eq F ⟨i, x⟩ ⟨j, y⟩ (max' i j) (IsFiltered.leftToMax i j)
(IsFiltered.rightToMax i j)]
dsimp
rw [MonoidHom.map_mul, t.w_apply, t.w_apply]
rfl }
/-- The proposed colimit cocone is a colimit in `MonCat`. -/
@[to_additive /-- The proposed colimit cocone is a colimit in `AddMonCat`. -/]
noncomputable def colimitCoconeIsColimit : IsColimit (colimitCocone.{v, u} F) where
desc := colimitDesc.{v, u} F
fac t j := rfl
uniq t m h := MonCat.ext fun y ↦ by
obtain ⟨j, y, rfl⟩ := Functor.ιColimitType_jointly_surjective _ y
exact ConcreteCategory.congr_hom (h j) y
@[to_additive]
instance forget_preservesFilteredColimits :
PreservesFilteredColimits (forget MonCat.{u}) where
preserves_filtered_colimits _ _ _ :=
⟨fun {F} => preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit.{u, u} F)
(Types.TypeMax.colimitCoconeIsColimit (F ⋙ forget MonCat.{u}))⟩
end
end MonCat.FilteredColimits
namespace CommMonCat.FilteredColimits
open MonCat.FilteredColimits (colimit_mul_mk_eq)
section
-- We use parameters here, mainly so we can have the abbreviation `M` below, without
-- passing around `F` all the time.
variable {J : Type v} [SmallCategory J] [IsFiltered J] (F : J ⥤ CommMonCat.{max v u})
/-- The colimit of `F ⋙ forget₂ CommMonCat MonCat` in the category `MonCat`.
In the following, we will show that this has the structure of a _commutative_ monoid.
-/
@[to_additive
/-- The colimit of `F ⋙ forget₂ AddCommMonCat AddMonCat` in the category `AddMonCat`. In the
following, we will show that this has the structure of a _commutative_ additive monoid. -/]
noncomputable abbrev M : MonCat.{max v u} :=
MonCat.FilteredColimits.colimit.{v, u} (F ⋙ forget₂ CommMonCat MonCat.{max v u})
@[to_additive]
noncomputable instance colimitCommMonoid : CommMonoid.{max v u} (M.{v, u} F) :=
{ (M.{v, u} F) with
mul_comm := fun x y => by
obtain ⟨i, x, rfl⟩ := x.mk_surjective
obtain ⟨j, y, rfl⟩ := y.mk_surjective
let k := max' i j
let f := IsFiltered.leftToMax i j
let g := IsFiltered.rightToMax i j
rw [colimit_mul_mk_eq.{v, u} (F ⋙ forget₂ CommMonCat MonCat) ⟨i, x⟩ ⟨j, y⟩ k f g,
colimit_mul_mk_eq.{v, u} (F ⋙ forget₂ CommMonCat MonCat) ⟨j, y⟩ ⟨i, x⟩ k g f]
dsimp
rw [mul_comm] }
/-- The bundled commutative monoid giving the filtered colimit of a diagram. -/
@[to_additive
/-- The bundled additive commutative monoid giving the filtered colimit of a diagram. -/]
noncomputable def colimit : CommMonCat.{max v u} :=
CommMonCat.of (M.{v, u} F)
/-- The cocone over the proposed colimit commutative monoid. -/
@[to_additive /-- The cocone over the proposed colimit additive commutative monoid. -/]
noncomputable def colimitCocone : Cocone F where
pt := colimit.{v, u} F
ι.app j := ofHom ((MonCat.FilteredColimits.colimitCocone.{v, u}
(F ⋙ forget₂ CommMonCat MonCat.{max v u})).ι.app j).hom
ι.naturality _ _ f := hom_ext <| congr_arg (MonCat.Hom.hom)
((MonCat.FilteredColimits.colimitCocone.{v, u}
(F ⋙ forget₂ CommMonCat MonCat.{max v u})).ι.naturality f)
/-- The proposed colimit cocone is a colimit in `CommMonCat`. -/
@[to_additive /-- The proposed colimit cocone is a colimit in `AddCommMonCat`. -/]
noncomputable def colimitCoconeIsColimit : IsColimit (colimitCocone.{v, u} F) :=
isColimitOfReflects (forget₂ CommMonCat MonCat)
(MonCat.FilteredColimits.colimitCoconeIsColimit (F ⋙ forget₂ _ _))
@[to_additive forget₂AddMonPreservesFilteredColimits]
noncomputable instance forget₂Mon_preservesFilteredColimits :
PreservesFilteredColimits (forget₂ CommMonCat MonCat.{u}) where
preserves_filtered_colimits _ _ _ :=
⟨fun {F} => preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit.{u, u} F)
(MonCat.FilteredColimits.colimitCoconeIsColimit (F ⋙ forget₂ CommMonCat MonCat.{u}))⟩
@[to_additive]
noncomputable instance forget_preservesFilteredColimits :
PreservesFilteredColimits (forget CommMonCat.{u}) :=
Limits.comp_preservesFilteredColimits (forget₂ CommMonCat MonCat) (forget MonCat)
end
end CommMonCat.FilteredColimits |
.lake/packages/mathlib/Mathlib/Algebra/Category/MonCat/ForgetCorepresentable.lean | import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Algebra.Group.Nat.Hom
import Mathlib.CategoryTheory.Yoneda
/-!
# The forgetful functor is corepresentable
The forgetful functor `AddCommMonCat.{u} ⥤ Type u` is corepresentable
by `ULift ℕ`. Similar results are obtained for the variants `CommMonCat`, `AddMonCat`
and `MonCat`.
-/
assert_not_exists MonoidWithZero
universe u
open CategoryTheory Opposite
/-!
### `(ULift ℕ →+ G) ≃ G`
These universe-monomorphic variants of `multiplesHom`/`powersHom` are put here since they
shouldn't be useful outside of category theory.
-/
/-- Monoid homomorphisms from `ULift ℕ` are defined by the image of `1`. -/
@[simps!]
def uliftMultiplesHom (M : Type u) [AddMonoid M] : M ≃ (ULift.{u} ℕ →+ M) :=
(multiplesHom _).trans AddEquiv.ulift.symm.addMonoidHomCongrLeftEquiv
/-- Monoid homomorphisms from `ULift (Multiplicative ℕ)` are defined by the image
of `Multiplicative.ofAdd 1`. -/
@[simps!]
def uliftPowersHom (M : Type u) [Monoid M] : M ≃ (ULift.{u} (Multiplicative ℕ) →* M) :=
(powersHom _).trans MulEquiv.ulift.symm.monoidHomCongrLeftEquiv
namespace MonoidHom
/-- The equivalence `(Multiplicative ℕ →* α) ≃ α` for any monoid `α`. -/
@[deprecated powersHom (since := "2025-05-11")]
def fromMultiplicativeNatEquiv (α : Type u) [Monoid α] : (Multiplicative ℕ →* α) ≃ α :=
(powersHom _).symm
/-- The equivalence `(ULift (Multiplicative ℕ) →* α) ≃ α` for any monoid `α`. -/
@[deprecated uliftPowersHom (since := "2025-05-11")]
def fromULiftMultiplicativeNatEquiv (α : Type u) [Monoid α] :
(ULift.{u} (Multiplicative ℕ) →* α) ≃ α :=
(uliftPowersHom _).symm
end MonoidHom
namespace AddMonoidHom
/-- The equivalence `(ℕ →+ α) ≃ α` for any additive monoid `α`. -/
@[deprecated multiplesHom (since := "2025-05-11")]
def fromNatEquiv (α : Type u) [AddMonoid α] : (ℕ →+ α) ≃ α := (multiplesHom _).symm
/-- The equivalence `(ULift ℕ →+ α) ≃ α` for any additive monoid `α`. -/
@[deprecated uliftMultiplesHom (since := "2025-05-11")]
def fromULiftNatEquiv (α : Type u) [AddMonoid α] : (ULift.{u} ℕ →+ α) ≃ α :=
(uliftMultiplesHom _).symm
end AddMonoidHom
/-- The forgetful functor `MonCat.{u} ⥤ Type u` is corepresentable. -/
def MonCat.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} (Multiplicative ℕ)))) ≅ forget MonCat.{u} :=
NatIso.ofComponents fun M ↦
(ConcreteCategory.homEquiv.trans (uliftPowersHom M.carrier).symm).toIso
/-- The forgetful functor `CommMonCat.{u} ⥤ Type u` is corepresentable. -/
def CommMonCat.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} (Multiplicative ℕ)))) ≅ forget CommMonCat.{u} :=
NatIso.ofComponents fun M ↦
(ConcreteCategory.homEquiv.trans (uliftPowersHom M.carrier).symm).toIso
/-- The forgetful functor `AddMonCat.{u} ⥤ Type u` is corepresentable. -/
def AddMonCat.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} ℕ))) ≅ forget AddMonCat.{u} :=
NatIso.ofComponents fun M ↦
(ConcreteCategory.homEquiv.trans (uliftMultiplesHom M.carrier).symm).toIso
/-- The forgetful functor `AddCommMonCat.{u} ⥤ Type u` is corepresentable. -/
def AddCommMonCat.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} ℕ))) ≅ forget AddCommMonCat.{u} :=
NatIso.ofComponents fun M ↦
(ConcreteCategory.homEquiv.trans (uliftMultiplesHom M.carrier).symm).toIso
instance MonCat.forget_isCorepresentable :
(forget MonCat.{u}).IsCorepresentable :=
Functor.IsCorepresentable.mk' MonCat.coyonedaObjIsoForget
instance CommMonCat.forget_isCorepresentable :
(forget CommMonCat.{u}).IsCorepresentable :=
Functor.IsCorepresentable.mk' CommMonCat.coyonedaObjIsoForget
instance AddMonCat.forget_isCorepresentable :
(forget AddMonCat.{u}).IsCorepresentable :=
Functor.IsCorepresentable.mk' AddMonCat.coyonedaObjIsoForget
instance AddCommMonCat.forget_isCorepresentable :
(forget AddCommMonCat.{u}).IsCorepresentable :=
Functor.IsCorepresentable.mk' AddCommMonCat.coyonedaObjIsoForget |
.lake/packages/mathlib/Mathlib/Algebra/Category/MonCat/Colimits.lean | import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.CategoryTheory.Limits.HasLimits
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
/-!
# The category of monoids has all colimits.
We do this construction knowing nothing about monoids.
In particular, I want to claim that this file could be produced by a python script
that just looks at what Lean 3's `#print monoid` printed a long time ago (it no longer looks like
this due to the addition of `npow` fields):
```
structure monoid : Type u → Type u
fields:
monoid.mul : Π {M : Type u} [self : monoid M], M → M → M
monoid.mul_assoc : ∀ {M : Type u} [self : monoid M] (a b c : M), a * b * c = a * (b * c)
monoid.one : Π {M : Type u} [self : monoid M], M
monoid.one_mul : ∀ {M : Type u} [self : monoid M] (a : M), 1 * a = a
monoid.mul_one : ∀ {M : Type u} [self : monoid M] (a : M), a * 1 = a
```
and if we'd fed it the output of Lean 3's `#print comm_ring`, this file would instead build
colimits of commutative rings.
A slightly bolder claim is that we could do this with tactics, as well.
Note: `Monoid` and `CommRing` are no longer flat structures in Mathlib4, and so `#print Monoid`
gives the less clear
```
inductive Monoid.{u} : Type u → Type u
number of parameters: 1
constructors:
Monoid.mk : {M : Type u} →
[toSemigroup : Semigroup M] →
[toOne : One M] →
(∀ (a : M), 1 * a = a) →
(∀ (a : M), a * 1 = a) →
(npow : ℕ → M → M) →
autoParam (∀ (x : M), npow 0 x = 1) _auto✝ →
autoParam (∀ (n : ℕ) (x : M), npow (n + 1) x = x * npow n x) _auto✝¹ → Monoid M
```
-/
assert_not_exists MonoidWithZero
universe v u
open CategoryTheory
open CategoryTheory.Limits
namespace MonCat.Colimits
/-!
We build the colimit of a diagram in `MonCat` by constructing the
free monoid on the disjoint union of all the monoids in the diagram,
then taking the quotient by the monoid laws within each monoid,
and the identifications given by the morphisms in the diagram.
-/
variable {J : Type v} [Category.{u} J] (F : J ⥤ MonCat.{v})
/-- An inductive type representing all monoid expressions (without relations)
on a collection of types indexed by the objects of `J`.
-/
inductive Prequotient
-- There's always `of`
| of : ∀ (j : J) (_ : F.obj j), Prequotient
-- Then one generator for each operation
| one : Prequotient
| mul : Prequotient → Prequotient → Prequotient
instance : Inhabited (Prequotient F) :=
⟨Prequotient.one⟩
open Prequotient
/-- The relation on `Prequotient` saying when two expressions are equal
because of the monoid laws, or
because one element is mapped to another by a morphism in the diagram.
-/
inductive Relation : Prequotient F → Prequotient F → Prop-- Make it an equivalence relation:
| refl : ∀ x, Relation x x
| symm : ∀ (x y) (_ : Relation x y), Relation y x
| trans : ∀ (x y z) (_ : Relation x y) (_ : Relation y z),
Relation x z-- There's always a `map` relation
| map :
∀ (j j' : J) (f : j ⟶ j') (x : F.obj j),
Relation (Prequotient.of j' ((F.map f) x))
(Prequotient.of j x)-- Then one relation per operation, describing the interaction with `of`
| mul : ∀ (j) (x y : F.obj j), Relation (Prequotient.of j (x * y))
(mul (Prequotient.of j x) (Prequotient.of j y))
| one : ∀ j, Relation (Prequotient.of j 1) one-- Then one relation per argument of each operation
| mul_1 : ∀ (x x' y) (_ : Relation x x'), Relation (mul x y) (mul x' y)
| mul_2 : ∀ (x y y') (_ : Relation y y'), Relation (mul x y) (mul x y')
-- And one relation per axiom
| mul_assoc : ∀ x y z, Relation (mul (mul x y) z) (mul x (mul y z))
| one_mul : ∀ x, Relation (mul one x) x
| mul_one : ∀ x, Relation (mul x one) x
/-- The setoid corresponding to monoid expressions modulo monoid relations and identifications.
-/
def colimitSetoid : Setoid (Prequotient F) where
r := Relation F
iseqv := ⟨Relation.refl, Relation.symm _ _, Relation.trans _ _ _⟩
attribute [instance] colimitSetoid
/-- The underlying type of the colimit of a diagram in `MonCat`.
-/
def ColimitType : Type v :=
Quotient (colimitSetoid F)
instance : Inhabited (ColimitType F) := by
dsimp [ColimitType]
infer_instance
instance monoidColimitType : Monoid (ColimitType F) where
one := Quotient.mk _ one
mul := Quotient.map₂ mul fun _ x' rx y _ ry =>
Setoid.trans (Relation.mul_1 _ _ y rx) (Relation.mul_2 x' _ _ ry)
one_mul := Quotient.ind fun _ => Quotient.sound <| Relation.one_mul _
mul_one := Quotient.ind fun _ => Quotient.sound <| Relation.mul_one _
mul_assoc := Quotient.ind fun _ => Quotient.ind₂ fun _ _ =>
Quotient.sound <| Relation.mul_assoc _ _ _
@[simp]
theorem quot_one : Quot.mk Setoid.r one = (1 : ColimitType F) :=
rfl
@[simp]
theorem quot_mul (x y : Prequotient F) : Quot.mk Setoid.r (mul x y) =
@HMul.hMul (ColimitType F) (ColimitType F) (ColimitType F) _
(Quot.mk Setoid.r x) (Quot.mk Setoid.r y) :=
rfl
/-- The bundled monoid giving the colimit of a diagram. -/
def colimit : MonCat :=
of (ColimitType F)
/-- The function from a given monoid in the diagram to the colimit monoid. -/
def coconeFun (j : J) (x : F.obj j) : ColimitType F :=
Quot.mk _ (Prequotient.of j x)
/-- The monoid homomorphism from a given monoid in the diagram to the colimit monoid. -/
def coconeMorphism (j : J) : F.obj j ⟶ colimit F :=
ofHom
{ toFun := coconeFun F j
map_one' := Quot.sound (Relation.one _)
map_mul' _ _ := Quot.sound (Relation.mul _ _ _) }
@[simp]
theorem cocone_naturality {j j' : J} (f : j ⟶ j') :
F.map f ≫ coconeMorphism F j' = coconeMorphism F j := by
ext
apply Quot.sound
apply Relation.map
@[simp]
theorem cocone_naturality_components (j j' : J) (f : j ⟶ j') (x : F.obj j) :
(coconeMorphism F j') (F.map f x) = (coconeMorphism F j) x := by
rw [← cocone_naturality F f]
rfl
/-- The cocone over the proposed colimit monoid. -/
def colimitCocone : Cocone F where
pt := colimit F
ι := { app := coconeMorphism F }
/-- The function from the free monoid on the diagram to the cone point of any other cocone. -/
@[simp]
def descFunLift (s : Cocone F) : Prequotient F → s.pt
| Prequotient.of j x => (s.ι.app j) x
| one => 1
| mul x y => descFunLift _ x * descFunLift _ y
/-- The function from the colimit monoid to the cone point of any other cocone. -/
def descFun (s : Cocone F) : ColimitType F → s.pt := by
fapply Quot.lift
· exact descFunLift F s
· intro x y r
induction r with
| refl x => rfl
| symm x y _ h => exact h.symm
| trans x y z _ _ h₁ h₂ => exact h₁.trans h₂
| map j j' f x => exact s.w_apply f x
| mul j x y => exact map_mul (s.ι.app j).hom x y
| one j => exact map_one (s.ι.app j).hom
| mul_1 x x' y _ h => exact congr_arg (· * _) h
| mul_2 x y y' _ h => exact congr_arg (_ * ·) h
| mul_assoc x y z => exact mul_assoc _ _ _
| one_mul x => exact one_mul _
| mul_one x => exact mul_one _
/-- The monoid homomorphism from the colimit monoid to the cone point of any other cocone. -/
def descMorphism (s : Cocone F) : colimit F ⟶ s.pt :=
ofHom
{ toFun := descFun F s
map_one' := rfl
map_mul' x y := by
induction x using Quot.inductionOn
induction y using Quot.inductionOn
solve_by_elim }
/-- Evidence that the proposed colimit is the colimit. -/
def colimitIsColimit : IsColimit (colimitCocone F) where
desc s := descMorphism F s
uniq s m w := by
ext x
induction x using Quot.inductionOn with | h x => ?_
induction x with
| of j =>
change _ = s.ι.app j _
rw [← w j]
rfl
| one =>
rw [quot_one, map_one]
rfl
| mul x y hx hy =>
rw [quot_mul, map_mul, hx, hy]
solve_by_elim
instance hasColimits_monCat : HasColimits MonCat where
has_colimits_of_shape _ _ :=
{ has_colimit := fun F =>
HasColimit.mk
{ cocone := colimitCocone F
isColimit := colimitIsColimit F } }
end MonCat.Colimits |
.lake/packages/mathlib/Mathlib/Algebra/Category/MonCat/Limits.lean | import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Algebra.Group.Shrink
import Mathlib.Algebra.Group.Submonoid.Defs
import Mathlib.CategoryTheory.Limits.Creates
import Mathlib.CategoryTheory.Limits.Types.Limits
/-!
# The category of (commutative) (additive) monoids has all limits
Further, these limits are preserved by the forgetful functor --- that is,
the underlying types are just the limits in the category of types.
-/
assert_not_exists MonoidWithZero
noncomputable section
open CategoryTheory
open CategoryTheory.Limits
universe v u w
namespace MonCat
variable {J : Type v} [Category.{w} J] (F : J ⥤ MonCat.{u})
@[to_additive]
instance monoidObj (j) : Monoid ((F ⋙ forget MonCat).obj j) :=
inferInstanceAs <| Monoid (F.obj j)
/-- The flat sections of a functor into `MonCat` form a submonoid of all sections. -/
@[to_additive
/-- The flat sections of a functor into `AddMonCat` form an additive submonoid of all sections. -/]
def sectionsSubmonoid : Submonoid (∀ j, F.obj j) where
carrier := (F ⋙ forget MonCat).sections
one_mem' {j} {j'} f := by simp
mul_mem' {a} {b} ah bh {j} {j'} f := by
simp only [Functor.comp_map, Pi.mul_apply]
dsimp [Functor.sections] at ah bh
rw [← ah f, ← bh f, forget_map, map_mul]
@[to_additive]
instance sectionsMonoid : Monoid (F ⋙ forget MonCat.{u}).sections :=
(sectionsSubmonoid F).toMonoid
variable [Small.{u} (Functor.sections (F ⋙ forget MonCat))]
@[to_additive]
noncomputable instance limitMonoid :
Monoid (Types.Small.limitCone.{v, u} (F ⋙ forget MonCat.{u})).pt :=
inferInstanceAs <| Monoid (Shrink (F ⋙ forget MonCat.{u}).sections)
/-- `limit.π (F ⋙ forget MonCat) j` as a `MonoidHom`. -/
@[to_additive /-- `limit.π (F ⋙ forget AddMonCat) j` as an `AddMonoidHom`. -/]
noncomputable def limitπMonoidHom (j : J) :
(Types.Small.limitCone.{v, u} (F ⋙ forget MonCat.{u})).pt →*
((F ⋙ forget MonCat.{u}).obj j) where
toFun := (Types.Small.limitCone.{v, u} (F ⋙ forget MonCat.{u})).π.app j
map_one' := by
simp only [Types.Small.limitCone_pt, Types.Small.limitCone_π_app, equivShrink_symm_one]
rfl
map_mul' _ _ := by
simp only [Types.Small.limitCone_pt, Types.Small.limitCone_π_app, equivShrink_symm_mul]
rfl
namespace HasLimits
-- The next two definitions are used in the construction of `HasLimits MonCat`.
-- After that, the limits should be constructed using the generic limits API,
-- e.g. `limit F`, `limit.cone F`, and `limit.isLimit F`.
/-- Construction of a limit cone in `MonCat`.
(Internal use only; use the limits API.)
-/
@[to_additive /-- (Internal use only; use the limits API.) -/]
noncomputable def limitCone : Cone F :=
{ pt := MonCat.of (Types.Small.limitCone (F ⋙ forget _)).pt
π :=
{ app j := ofHom (limitπMonoidHom F j)
naturality := fun _ _ f => MonCat.ext fun x =>
CategoryTheory.congr_hom ((Types.Small.limitCone (F ⋙ forget _)).π.naturality f) x } }
/-- Witness that the limit cone in `MonCat` is a limit cone.
(Internal use only; use the limits API.)
-/
@[to_additive /-- (Internal use only; use the limits API.) -/]
noncomputable def limitConeIsLimit : IsLimit (limitCone F) := by
refine IsLimit.ofFaithful (forget MonCat) (Types.Small.limitConeIsLimit.{v, u} _)
(fun s => ofHom { toFun := _, map_one' := ?_, map_mul' := ?_ }) (fun s => rfl)
· simp only [Functor.mapCone_π_app, forget_map, map_one]
rfl
· intro x y
simp only [EquivLike.coe_apply, Functor.mapCone_π_app, forget_map, map_mul]
rw [← equivShrink_mul]
rfl
/-- If `(F ⋙ forget MonCat).sections` is `u`-small, `F` has a limit. -/
@[to_additive /-- If `(F ⋙ forget AddMonCat).sections` is `u`-small, `F` has a limit. -/]
instance hasLimit : HasLimit F :=
HasLimit.mk {
cone := limitCone F
isLimit := limitConeIsLimit F
}
/-- If `J` is `u`-small, `MonCat.{u}` has limits of shape `J`. -/
@[to_additive /-- If `J` is `u`-small, `AddMonCat.{u}` has limits of shape `J`. -/]
instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J MonCat.{u} where
has_limit _ := inferInstance
end HasLimits
open HasLimits
/-- The category of monoids has all limits. -/
@[to_additive (relevant_arg := 100) /-- The category of additive monoids has all limits. -/]
instance hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} MonCat.{u} where
has_limits_of_shape _ _ := { }
@[to_additive]
instance hasLimits : HasLimits MonCat.{u} :=
MonCat.hasLimitsOfSize.{u, u}
/-- If `J` is `u`-small, the forgetful functor from `MonCat.{u}` preserves limits of shape `J`. -/
@[to_additive /-- If `J` is `u`-small, the forgetful functor from `AddMonCat.{u}` preserves limits
of shape `J`. -/]
noncomputable instance forget_preservesLimitsOfShape [Small.{u} J] :
PreservesLimitsOfShape J (forget MonCat.{u}) where
preservesLimit {F} := preservesLimit_of_preserves_limit_cone (limitConeIsLimit F)
(Types.Small.limitConeIsLimit (F ⋙ forget _))
/-- The forgetful functor from monoids to types preserves all limits.
This means the underlying type of a limit can be computed as a limit in the category of types. -/
@[to_additive (relevant_arg := 100)
/-- The forgetful functor from additive monoids to types preserves all limits.
This means the underlying type of a limit can be computed as a limit in the category of types. -/]
noncomputable instance forget_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget MonCat.{u}) where
preservesLimitsOfShape := { }
@[to_additive]
noncomputable instance forget_preservesLimits : PreservesLimits (forget MonCat.{u}) :=
MonCat.forget_preservesLimitsOfSize.{u, u}
@[to_additive]
noncomputable instance forget_createsLimit :
CreatesLimit F (forget MonCat.{u}) := by
apply createsLimitOfReflectsIso
intro c t
have : Small.{u} (Functor.sections (F ⋙ forget MonCat)) :=
(Types.hasLimit_iff_small_sections _).mp (HasLimit.mk {cone := c, isLimit := t})
refine LiftsToLimit.mk (LiftableCone.mk
{ pt := MonCat.of (Types.Small.limitCone (F ⋙ forget MonCat)).pt,
π := NatTrans.mk
(fun j => ofHom (limitπMonoidHom F j))
(MonCat.HasLimits.limitCone F).π.naturality }
(Cones.ext
((Types.isLimitEquivSections t).trans (equivShrink _)).symm.toIso
(fun _ ↦ funext (fun _ ↦ by simp; rfl)))) ?_
refine IsLimit.ofFaithful (forget MonCat.{u}) (Types.Small.limitConeIsLimit.{v, u} _) ?_ ?_
· intro _
refine ofHom
{ toFun := (Types.Small.limitConeIsLimit.{v,u} _).lift ((forget MonCat).mapCone _),
map_one' := by simp; rfl, map_mul' := ?_ }
· intro x y
simp only [Types.Small.limitConeIsLimit_lift, Functor.comp_obj, Functor.mapCone_pt,
Functor.mapCone_π_app, forget_map, map_mul]
congr
simp only [Functor.comp_obj, Equiv.symm_apply_apply]
rfl
· exact fun _ ↦ rfl
@[to_additive]
noncomputable instance forget_createsLimitsOfShape :
CreatesLimitsOfShape J (forget MonCat.{u}) where
CreatesLimit := inferInstance
/-- The forgetful functor from monoids to types preserves all limits. -/
@[to_additive /-- The forgetful functor from additive monoids to types preserves all limits. -/]
noncomputable instance forget_createsLimitsOfSize :
CreatesLimitsOfSize.{w, v} (forget MonCat.{u}) where
CreatesLimitsOfShape := inferInstance
@[to_additive]
noncomputable instance forget_createsLimits : CreatesLimits (forget MonCat.{u}) :=
MonCat.forget_createsLimitsOfSize.{u, u}
end MonCat
open MonCat
namespace CommMonCat
variable {J : Type v} [Category.{w} J] (F : J ⥤ CommMonCat.{u})
@[to_additive]
instance commMonoidObj (j) : CommMonoid ((F ⋙ forget CommMonCat.{u}).obj j) :=
inferInstanceAs <| CommMonoid (F.obj j)
variable [Small.{u} (Functor.sections (F ⋙ forget CommMonCat))]
@[to_additive]
noncomputable instance limitCommMonoid :
CommMonoid (Types.Small.limitCone (F ⋙ forget CommMonCat.{u})).pt :=
letI : CommMonoid (F ⋙ forget CommMonCat.{u}).sections :=
@Submonoid.toCommMonoid (∀ j, F.obj j) _
(MonCat.sectionsSubmonoid (F ⋙ forget₂ CommMonCat.{u} MonCat.{u}))
inferInstanceAs <| CommMonoid (Shrink (F ⋙ forget CommMonCat.{u}).sections)
@[to_additive]
instance : Small.{u} (Functor.sections ((F ⋙ forget₂ CommMonCat MonCat) ⋙ forget MonCat)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget CommMonCat))
/-- We show that the forgetful functor `CommMonCat ⥤ MonCat` creates limits.
All we need to do is notice that the limit point has a `CommMonoid` instance available,
and then reuse the existing limit. -/
@[to_additive /-- We show that the forgetful functor `AddCommMonCat ⥤ AddMonCat` creates limits.
All we need to do is notice that the limit point has an `AddCommMonoid` instance available,
and then reuse the existing limit. -/]
noncomputable instance forget₂CreatesLimit : CreatesLimit F (forget₂ CommMonCat MonCat.{u}) :=
createsLimitOfReflectsIso fun c' t =>
{ liftedCone :=
{ pt := CommMonCat.of (Types.Small.limitCone (F ⋙ forget CommMonCat)).pt
π :=
{ app j := ofHom (MonCat.limitπMonoidHom (F ⋙ forget₂ CommMonCat.{u} MonCat.{u}) j)
naturality _ _ j := ext <| fun x => congr_hom
((MonCat.HasLimits.limitCone
(F ⋙ forget₂ CommMonCat MonCat.{u})).π.naturality j) x } }
validLift := by apply IsLimit.uniqueUpToIso (MonCat.HasLimits.limitConeIsLimit _) t
makesLimit :=
IsLimit.ofFaithful (forget₂ CommMonCat MonCat.{u})
(MonCat.HasLimits.limitConeIsLimit _) (fun _ => _) fun _ => rfl }
/-- A choice of limit cone for a functor into `CommMonCat`.
(Generally, you'll just want to use `limit F`.)
-/
@[to_additive /-- A choice of limit cone for a functor into `AddCommMonCat`.
(Generally, you'll just want to use `limit F`.) -/]
noncomputable def limitCone : Cone F :=
liftLimit (limit.isLimit (F ⋙ forget₂ CommMonCat.{u} MonCat.{u}))
/-- The chosen cone is a limit cone.
(Generally, you'll just want to use `limit.cone F`.)
-/
@[to_additive
/-- The chosen cone is a limit cone.
(Generally, you'll just want to use `limit.cone F`.) -/]
noncomputable def limitConeIsLimit : IsLimit (limitCone F) :=
liftedLimitIsLimit _
/-- If `(F ⋙ forget CommMonCat).sections` is `u`-small, `F` has a limit. -/
@[to_additive /-- If `(F ⋙ forget AddCommMonCat).sections` is `u`-small, `F` has a limit. -/]
instance hasLimit : HasLimit F :=
HasLimit.mk {
cone := limitCone F
isLimit := limitConeIsLimit F
}
/-- If `J` is `u`-small, `CommMonCat.{u}` has limits of shape `J`. -/
@[to_additive /-- If `J` is `u`-small, `AddCommMonCat.{u}` has limits of shape `J`. -/]
instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J CommMonCat.{u} where
has_limit _ := inferInstance
/-- The category of commutative monoids has all limits. -/
@[to_additive (relevant_arg := 100)
/-- The category of additive commutative monoids has all limits. -/]
instance hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} CommMonCat.{u} where
has_limits_of_shape _ _ := { }
@[to_additive]
instance hasLimits : HasLimits CommMonCat.{u} :=
CommMonCat.hasLimitsOfSize.{u, u}
/-- The forgetful functor from commutative monoids to monoids preserves all limits.
This means the underlying type of a limit can be computed as a limit in the category of monoids. -/
@[to_additive (relevant_arg := 100) AddCommMonCat.forget₂AddMonPreservesLimitsOfSize
/-- The forgetful functor from
additive commutative monoids to additive monoids preserves all limits.
This means the underlying type of a limit can be computed as a limit in the category of additive
monoids. -/]
instance forget₂Mon_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ CommMonCat.{u} MonCat.{u}) where
preservesLimitsOfShape {J} 𝒥 := { }
@[to_additive]
instance forget₂Mon_preservesLimits :
PreservesLimits (forget₂ CommMonCat.{u} MonCat.{u}) :=
CommMonCat.forget₂Mon_preservesLimitsOfSize.{u, u}
/-- If `J` is `u`-small, the forgetful functor from `CommMonCat.{u}` preserves limits of
shape `J`. -/
@[to_additive /-- If `J` is `u`-small, the forgetful functor from `AddCommMonCat.{u}`
preserves limits of shape `J`. -/]
instance forget_preservesLimitsOfShape [Small.{u} J] :
PreservesLimitsOfShape J (forget CommMonCat.{u}) where
preservesLimit {F} := preservesLimit_of_preserves_limit_cone (limitConeIsLimit F)
(Types.Small.limitConeIsLimit (F ⋙ forget _))
/-- The forgetful functor from commutative monoids to types preserves all limits.
This means the underlying type of a limit can be computed as a limit in the category of types. -/
@[to_additive /-- The forgetful functor from additive commutative monoids to types preserves all
limits.
This means the underlying type of a limit can be computed as a limit in the category of types. -/]
instance forget_preservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{v, v} (forget CommMonCat.{u}) where
preservesLimitsOfShape {_} _ := { }
instance _root_.AddCommMonCat.forget_preservesLimits :
PreservesLimits (forget AddCommMonCat.{u}) :=
AddCommMonCat.forget_preservesLimitsOfSize.{u, u}
@[to_additive existing]
instance forget_preservesLimits : PreservesLimits (forget CommMonCat.{u}) :=
CommMonCat.forget_preservesLimitsOfSize.{u, u}
@[to_additive]
noncomputable instance forget_createsLimit :
CreatesLimit F (forget CommMonCat.{u}) := by
set e : forget CommMonCat.{u} ≅ forget₂ CommMonCat.{u} MonCat.{u} ⋙ forget MonCat.{u} :=
NatIso.ofComponents (fun _ ↦ Iso.refl _) (fun _ ↦ rfl)
exact createsLimitOfNatIso e.symm
@[to_additive]
noncomputable instance forget_createsLimitsOfShape :
CreatesLimitsOfShape J (forget MonCat.{u}) where
CreatesLimit := inferInstance
/-- The forgetful functor from commutative monoids to types preserves all limits. -/
@[to_additive
/-- The forgetful functor from commutative additive monoids to types preserves all limits. -/]
noncomputable instance forget_createsLimitsOfSize :
CreatesLimitsOfSize.{w, v} (forget MonCat.{u}) where
CreatesLimitsOfShape := inferInstance
@[to_additive]
noncomputable instance forget_createsLimits : CreatesLimits (forget MonCat.{u}) :=
CommMonCat.forget_createsLimitsOfSize.{u, u}
end CommMonCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/MonCat/Adjunctions.lean | import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.Algebra.Category.Semigrp.Basic
import Mathlib.Algebra.FreeMonoid.Basic
import Mathlib.Algebra.Group.WithOne.Basic
import Mathlib.Data.Finsupp.Basic
import Mathlib.Data.Finsupp.SMulWithZero
import Mathlib.CategoryTheory.Adjunction.Basic
/-!
# Adjunctions regarding the category of monoids
This file proves the adjunction between adjoining a unit to a semigroup and the forgetful functor
from monoids to semigroups.
## TODO
* free-forgetful adjunction for monoids
* adjunctions related to commutative monoids
-/
universe u
open CategoryTheory
namespace MonCat
/-- The functor of adjoining a neutral element `one` to a semigroup. -/
@[to_additive (attr := simps)
/-- The functor of adjoining a neutral element `zero` to a semigroup -/]
def adjoinOne : Semigrp.{u} ⥤ MonCat.{u} where
obj S := MonCat.of (WithOne S)
map f := ofHom (WithOne.mapMulHom f.hom)
map_id _ := MonCat.hom_ext WithOne.mapMulHom_id
map_comp _ _ := MonCat.hom_ext (WithOne.mapMulHom_comp _ _)
@[to_additive]
instance hasForgetToSemigroup : HasForget₂ MonCat Semigrp where
forget₂ :=
{ obj := fun M => Semigrp.of M
map f := Semigrp.ofHom f.hom.toMulHom }
/-- The `adjoinOne`-forgetful adjunction from `Semigrp` to `MonCat`. -/
@[to_additive /-- The `adjoinZero`-forgetful adjunction from `AddSemigrp` to `AddMonCat` -/]
def adjoinOneAdj : adjoinOne ⊣ forget₂ MonCat.{u} Semigrp.{u} :=
Adjunction.mkOfHomEquiv
{ homEquiv X Y :=
ConcreteCategory.homEquiv.trans (WithOne.lift.symm.trans
(ConcreteCategory.homEquiv (X := X) (Y := (forget₂ _ _).obj Y)).symm)
homEquiv_naturality_left_symm := by
intros
ext ⟨_ | _⟩ <;> simp <;> rfl }
/-- The free functor `Type u ⥤ MonCat` sending a type `X` to the free monoid on `X`. -/
@[to_additive
/-- The free functor `Type u ⥤ AddMonCat` sending a type `X` to the free additive monoid on `X`. -/]
def free : Type u ⥤ MonCat.{u} where
obj α := MonCat.of (FreeMonoid α)
map f := ofHom (FreeMonoid.map f)
map_id _ := MonCat.hom_ext (FreeMonoid.hom_eq fun _ => rfl)
map_comp _ _ := MonCat.hom_ext (FreeMonoid.hom_eq fun _ => rfl)
/-- The free-forgetful adjunction for monoids. -/
@[to_additive /-- The free-forgetful adjunction for additive monoids. -/]
def adj : free ⊣ forget MonCat.{u} :=
Adjunction.mkOfHomEquiv
-- The hint `(C := MonCat)` below speeds up the declaration by 10 times.
{ homEquiv X Y := (ConcreteCategory.homEquiv (C := MonCat)).trans FreeMonoid.lift.symm
homEquiv_naturality_left_symm _ _ := MonCat.hom_ext (FreeMonoid.hom_eq fun _ => rfl) }
instance : (forget MonCat.{u}).IsRightAdjoint :=
⟨_, ⟨adj⟩⟩
end MonCat
namespace AddCommMonCat
/-- The free functor `Type u ⥤ AddCommMonCat`
sending a type `X` to the free commutative monoid on `X`. -/
@[simps]
noncomputable
def free : Type u ⥤ AddCommMonCat.{u} where
obj α := .of (α →₀ ℕ)
map f := ofHom (Finsupp.mapDomain.addMonoidHom f)
/-- The free-forgetful adjunction for commutative monoids. -/
noncomputable
def adj : free ⊣ forget AddCommMonCat.{u} where
unit := { app X i := Finsupp.single i 1 }
counit :=
{ app M := ofHom (Finsupp.liftAddHom (multiplesHom M))
naturality {M N} f := by dsimp; ext1; apply Finsupp.liftAddHom.symm.injective; ext; simp }
instance : free.IsLeftAdjoint := ⟨_, ⟨adj⟩⟩
instance : (forget AddCommMonCat.{u}).IsRightAdjoint := ⟨_, ⟨adj⟩⟩
end AddCommMonCat
namespace CommMonCat
instance : (forget CommMonCat.{u}).IsRightAdjoint :=
⟨_, ⟨AddCommMonCat.adj.comp AddCommMonCat.equivalence.toAdjunction⟩⟩
end CommMonCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/FGModuleCat/EssentiallySmall.lean | import Mathlib.Algebra.Category.FGModuleCat.Basic
import Mathlib.RingTheory.Finiteness.Cardinality
/-!
# The category of finitely generated modules over a ring is essentially small
This file proves that `FGModuleCat R`, the category of finitely generated modules over a ring `R`,
is essentially small, by providing an explicit small model. However, for applications, it is
recommended to use the standard `CategoryTheory.SmallModel (FGModuleCat R)` instead.
-/
universe v w u
variable (R : Type u) [CommRing R]
open CategoryTheory
/-- A (category-theoretically) small version of `FGModuleCat R`. This is used to prove that
`FGModuleCat R` is essentially small. For actual use, it might be recommended to use the canonical
`CategoryTheory.SmallModel` instead of this construction. -/
structure FGModuleRepr : Type u where
/-- The natural number `n` that defines the module as a quotient of `Fin n → R` (i.e. `R^n`). -/
(n : ℕ)
/-- The kernel of the surjective map from `Fin n → R` (i.e. `R^n`) to the module represented. -/
(S : Submodule R (Fin n → R))
namespace FGModuleRepr
variable (M : Type v) [AddCommGroup M] [Module R M] [Module.Finite R M]
variable {R} in
/-- The finite module represented by an object of the type `FGModuleRepr R`, which is the quotient
of `Fin n → R` (i.e. $$R^n$$) by the submodule `S` provided. -/
def repr (x : FGModuleRepr R) : Type u :=
_ ⧸ x.S
instance : CoeSort (FGModuleRepr R) (Type u) :=
⟨repr⟩
instance (x : FGModuleRepr R) : AddCommGroup x := by
unfold repr; infer_instance
instance (x : FGModuleRepr R) : Module R x := by
unfold repr; infer_instance
instance (x : FGModuleRepr R) : Module.Finite R x := by
unfold repr; infer_instance
/-- A non-canonical representation of a finite module (as a quotient of $$R^n$$). -/
noncomputable def ofFinite : FGModuleRepr R where
n := (Module.Finite.exists_fin_quot_equiv R M).choose
S := (Module.Finite.exists_fin_quot_equiv R M).choose_spec.choose
/-- The non-canonical representation `ofFinite` of a finite module is actually isomorphic to
the given module. -/
noncomputable def ofFiniteEquiv : ofFinite R M ≃ₗ[R] M :=
Classical.choice (Module.Finite.exists_fin_quot_equiv R M).choose_spec.choose_spec
instance : Category (FGModuleRepr R) :=
InducedCategory.category fun x : FGModuleRepr R ↦ FGModuleCat.of R x
instance : SmallCategory (FGModuleRepr R) where
/-- The canonical embedding of this small category to the canonical (large) category
`FGModuleCat R`. -/
def embed : FGModuleRepr.{u} R ⥤ FGModuleCat.{max u v} R :=
inducedFunctor _ ⋙ FGModuleCat.ulift R
instance : (embed R).IsEquivalence where
faithful := (fullyFaithfulInducedFunctor _).faithful.comp _ _
full := (fullyFaithfulInducedFunctor _).full.comp _ _
essSurj := ⟨fun M ↦ ⟨ofFinite R M,
⟨(ULift.moduleEquiv.trans <| ofFiniteEquiv R M).toFGModuleCatIso⟩⟩⟩
end FGModuleRepr
instance : EssentiallySmall.{u} (FGModuleCat.{v} R) :=
letI : EssentiallySmall.{u} (FGModuleCat.{max u v} R) :=
⟨_, _, ⟨(FGModuleRepr.embed R).asEquivalence.symm⟩⟩
essentiallySmall_of_fully_faithful (FGModuleCat.ulift.{v, max u v} R)
open FGModuleRepr in
-- There is probably a proof using `embedIsEquivalence` or `EssentiallySmall`.
instance : (FGModuleCat.ulift.{max u v, w} R).IsEquivalence where
essSurj := ⟨fun M ↦ ⟨(embed R).obj (ofFinite R M),
⟨(ULift.moduleEquiv.trans <| ULift.moduleEquiv.trans <| ofFiniteEquiv R M).toFGModuleCatIso⟩⟩⟩ |
.lake/packages/mathlib/Mathlib/Algebra/Category/FGModuleCat/Abelian.lean | import Mathlib.Algebra.Category.FGModuleCat.Colimits
import Mathlib.Algebra.Category.FGModuleCat.Limits
import Mathlib.Algebra.Category.ModuleCat.Abelian
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.AbelianImages
/-!
# `FGModuleCat K` is an abelian category.
-/
noncomputable section
universe v u
open CategoryTheory Limits
namespace FGModuleCat
variable {k : Type u} [Ring k] [IsNoetherianRing k]
instance {X Y : FGModuleCat k} (f : X ⟶ Y) : IsIso (Abelian.coimageImageComparison f) :=
have := IsIso.of_isIso_fac_right (Abelian.PreservesCoimage.hom_coimageImageComparison
(forget₂ (FGModuleCat k) (ModuleCat k)) f).symm
Functor.FullyFaithful.isIso_of_isIso_map (ModuleCat.isFG k).fullyFaithfulι _
instance : Abelian (FGModuleCat k) := Abelian.ofCoimageImageComparisonIsIso
end FGModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/FGModuleCat/Basic.lean | import Mathlib.Algebra.Category.ModuleCat.Monoidal.Closed
import Mathlib.CategoryTheory.Monoidal.Rigid.Basic
import Mathlib.CategoryTheory.Monoidal.Subcategory
import Mathlib.LinearAlgebra.Coevaluation
import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix
import Mathlib.RingTheory.TensorProduct.Finite
/-!
# The category of finitely generated modules over a ring
This introduces `FGModuleCat R`, the category of finitely generated modules over a ring `R`.
It is implemented as a full subcategory on a subtype of `ModuleCat R`.
When `K` is a field,
`FGModuleCat K` is the category of finite-dimensional vector spaces over `K`.
We first create the instance as a preadditive category.
When `R` is commutative we then give the structure as an `R`-linear monoidal category.
When `R` is a field we give it the structure of a closed monoidal category
and then as a right-rigid monoidal category.
## Future work
* Show that `FGModuleCat R` is abelian when `R` is (left)-Noetherian.
-/
noncomputable section
open CategoryTheory Module
universe v w u
section Ring
variable (R : Type u) [Ring R]
/-- Finitely generated modules, as a property of objects of `ModuleCat R`. -/
def ModuleCat.isFG : ObjectProperty (ModuleCat.{v} R) :=
fun V ↦ Module.Finite R V
variable {R} in
lemma ModuleCat.isFG_iff (V : ModuleCat.{v} R) :
isFG R V ↔ Module.Finite R V := Iff.rfl
/-- The category of finitely generated modules. -/
abbrev FGModuleCat := (ModuleCat.isFG.{v} R).FullSubcategory
variable {R}
/-- A synonym for `M.obj.carrier`, which we can mark with `@[coe]`. -/
def FGModuleCat.carrier (M : FGModuleCat.{v} R) : Type v := M.obj.carrier
instance : CoeSort (FGModuleCat.{v} R) (Type v) :=
⟨FGModuleCat.carrier⟩
attribute [coe] FGModuleCat.carrier
@[simp] lemma FGModuleCat.obj_carrier (M : FGModuleCat.{v} R) : M.obj.carrier = M.carrier := rfl
instance (M : FGModuleCat.{v} R) : AddCommGroup M := by
change AddCommGroup M.obj
infer_instance
instance (M : FGModuleCat.{v} R) : Module R M := by
change Module R M.obj
infer_instance
instance (M : FGModuleCat.{v} R) : Module.Finite R M :=
M.property
instance (M : FGModuleCat.{v} R) : Module.Finite R M.1 :=
M.property
end Ring
namespace FGModuleCat
section Ring
variable (R : Type u) [Ring R]
@[simp] lemma hom_comp (A B C : FGModuleCat.{v} R) (f : A ⟶ B) (g : B ⟶ C) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
@[simp] lemma hom_id (A : FGModuleCat.{v} R) : (𝟙 A : A ⟶ A).hom = LinearMap.id := rfl
instance : Inhabited (FGModuleCat.{v} R) :=
⟨⟨ModuleCat.of R PUnit, by unfold ModuleCat.isFG; infer_instance⟩⟩
/-- Lift an unbundled finitely generated module to `FGModuleCat R`. -/
abbrev of (V : Type v) [AddCommGroup V] [Module R V] [Module.Finite R V] : FGModuleCat R :=
⟨ModuleCat.of R V, by change Module.Finite R V; infer_instance⟩
@[simp]
lemma of_carrier (V : Type v) [AddCommGroup V] [Module R V] [Module.Finite R V] :
of R V = V := rfl
variable {R} in
/-- Lift a linear map between finitely generated modules to `FGModuleCat R`. -/
abbrev ofHom {V W : Type v} [AddCommGroup V] [Module R V] [Module.Finite R V]
[AddCommGroup W] [Module R W] [Module.Finite R W]
(f : V →ₗ[R] W) : of R V ⟶ of R W :=
ModuleCat.ofHom f
variable {R} in
@[ext] lemma hom_ext {V W : FGModuleCat.{v} R} {f g : V ⟶ W} (h : f.hom = g.hom) : f = g :=
ModuleCat.hom_ext h
instance (V : FGModuleCat.{v} R) : Module.Finite R V :=
V.property
instance : (forget₂ (FGModuleCat.{v} R) (ModuleCat.{v} R)).Full where
map_surjective f := ⟨f, rfl⟩
variable {R} in
/-- Converts an isomorphism in the category `FGModuleCat R` to
a `LinearEquiv` between the underlying modules. -/
def isoToLinearEquiv {V W : FGModuleCat.{v} R} (i : V ≅ W) : V ≃ₗ[R] W :=
((forget₂ (FGModuleCat.{v} R) (ModuleCat.{v} R)).mapIso i).toLinearEquiv
variable {R} in
/-- Converts a `LinearEquiv` to an isomorphism in the category `FGModuleCat R`. -/
@[simps]
def _root_.LinearEquiv.toFGModuleCatIso
{V W : Type v} [AddCommGroup V] [Module R V] [Module.Finite R V]
[AddCommGroup W] [Module R W] [Module.Finite R W] (e : V ≃ₗ[R] W) :
FGModuleCat.of R V ≅ FGModuleCat.of R W where
hom := ModuleCat.ofHom e.toLinearMap
inv := ModuleCat.ofHom e.symm.toLinearMap
hom_inv_id := by ext x; exact e.left_inv x
inv_hom_id := by ext x; exact e.right_inv x
/-- Universe lifting as a functor on `FGModuleCat`. -/
def ulift : FGModuleCat.{v} R ⥤ FGModuleCat.{max v w} R where
obj M := .of R <| ULift M
map f := ofHom <| ULift.moduleEquiv.symm.toLinearMap ∘ₗ f.hom ∘ₗ ULift.moduleEquiv.toLinearMap
/-- Universe lifting is fully faithful. -/
def fullyFaithfulULift : (ulift R).FullyFaithful where
preimage f := ofHom <| ULift.moduleEquiv.toLinearMap ∘ₗ f.hom ∘ₗ
ULift.moduleEquiv.symm.toLinearMap
instance : (ulift R).Faithful :=
(fullyFaithfulULift R).faithful
instance : (ulift R).Full :=
(fullyFaithfulULift R).full
end Ring
section CommRing
variable (R : Type u) [CommRing R]
instance : (ModuleCat.isFG R).IsMonoidal where
prop_unit := Module.Finite.self R
prop_tensor X Y (_ : Module.Finite _ _) (_ : Module.Finite _ _) :=
Module.Finite.tensorProduct R X Y
open MonoidalCategory
@[simp] lemma tensorUnit_obj : (𝟙_ (FGModuleCat R)).obj = 𝟙_ (ModuleCat R) := rfl
@[simp] lemma tensorObj_obj (M N : FGModuleCat.{u} R) : (M ⊗ N).obj = (M.obj ⊗ N.obj) := rfl
instance : (forget₂ (FGModuleCat.{u} R) (ModuleCat.{u} R)).Additive where
instance : (forget₂ (FGModuleCat.{u} R) (ModuleCat.{u} R)).Linear R where
theorem Iso.conj_eq_conj {V W : FGModuleCat R} (i : V ≅ W) (f : End V) :
Iso.conj i f = FGModuleCat.ofHom (LinearEquiv.conj (isoToLinearEquiv i) f.hom) :=
rfl
theorem Iso.conj_hom_eq_conj {V W : FGModuleCat R} (i : V ≅ W) (f : End V) :
(Iso.conj i f).hom = (LinearEquiv.conj (isoToLinearEquiv i) f.hom) :=
rfl
end CommRing
section Field
variable (K : Type u) [Field K]
instance (V W : FGModuleCat.{v} K) : Module.Finite K (V ⟶ W) :=
(inferInstanceAs <| Module.Finite K (V →ₗ[K] W)).equiv ModuleCat.homLinearEquiv.symm
instance : (ModuleCat.isFG K).IsMonoidalClosed where
prop_ihom {X Y} (_ : Module.Finite _ _) (_ : Module.Finite _ _) :=
(inferInstanceAs <| Module.Finite K (X →ₗ[K] Y)).equiv ModuleCat.homLinearEquiv.symm
variable (V W : FGModuleCat K)
@[simp]
theorem ihom_obj : (ihom V).obj W = FGModuleCat.of K (V ⟶ W) :=
rfl
/-- The dual module is the dual in the rigid monoidal category `FGModuleCat K`. -/
def FGModuleCatDual : FGModuleCat K :=
⟨ModuleCat.of K (Module.Dual K V), Subspace.instModuleDualFiniteDimensional⟩
@[simp] lemma FGModuleCatDual_obj : (FGModuleCatDual K V).obj = ModuleCat.of K (Module.Dual K V) :=
rfl
@[simp] lemma FGModuleCatDual_coe : (FGModuleCatDual K V : Type u) = Module.Dual K V := rfl
open CategoryTheory.MonoidalCategory
/-- The coevaluation map is defined in `LinearAlgebra.coevaluation`. -/
def FGModuleCatCoevaluation : 𝟙_ (FGModuleCat K) ⟶ V ⊗ FGModuleCatDual K V :=
ModuleCat.ofHom <| coevaluation K V
theorem FGModuleCatCoevaluation_apply_one :
(FGModuleCatCoevaluation K V).hom (1 : K) =
∑ i : Basis.ofVectorSpaceIndex K V,
(Basis.ofVectorSpace K V) i ⊗ₜ[K] (Basis.ofVectorSpace K V).coord i :=
coevaluation_apply_one K V
/-- The evaluation morphism is given by the contraction map. -/
def FGModuleCatEvaluation : FGModuleCatDual K V ⊗ V ⟶ 𝟙_ (FGModuleCat K) :=
ModuleCat.ofHom <| contractLeft K V
theorem FGModuleCatEvaluation_apply (f : FGModuleCatDual K V) (x : V) :
(FGModuleCatEvaluation K V).hom (f ⊗ₜ x) = f.toFun x :=
contractLeft_apply f x
/-- `@[simp]`-normal form of `FGModuleCatEvaluation_apply`, where the carriers have been unfolded.
-/
@[simp]
theorem FGModuleCatEvaluation_apply' (f : FGModuleCatDual K V) (x : V) :
DFunLike.coe
(F := ((ModuleCat.of K (Module.Dual K V) ⊗ V.obj).carrier →ₗ[K] (𝟙_ (ModuleCat K))))
(FGModuleCatEvaluation K V).hom (f ⊗ₜ x) = f.toFun x :=
contractLeft_apply f x
private theorem coevaluation_evaluation :
letI V' : FGModuleCat K := FGModuleCatDual K V
V' ◁ FGModuleCatCoevaluation K V ≫ (α_ V' V V').inv ≫ FGModuleCatEvaluation K V ▷ V' =
(ρ_ V').hom ≫ (λ_ V').inv := by
ext : 1
apply contractLeft_assoc_coevaluation K V
private theorem evaluation_coevaluation :
FGModuleCatCoevaluation K V ▷ V ≫
(α_ V (FGModuleCatDual K V) V).hom ≫ V ◁ FGModuleCatEvaluation K V =
(λ_ V).hom ≫ (ρ_ V).inv := by
ext : 1
apply contractLeft_assoc_coevaluation' K V
instance exactPairing : ExactPairing V (FGModuleCatDual K V) where
coevaluation' := FGModuleCatCoevaluation K V
evaluation' := FGModuleCatEvaluation K V
coevaluation_evaluation' := coevaluation_evaluation K V
evaluation_coevaluation' := evaluation_coevaluation K V
instance rightDual : HasRightDual V :=
⟨FGModuleCatDual K V⟩
instance rightRigidCategory : RightRigidCategory (FGModuleCat K) where
end Field
end FGModuleCat
/-!
`@[simp]` lemmas for `LinearMap.comp` and categorical identities.
-/
@[simp] theorem LinearMap.comp_id_fgModuleCat
{R} [Ring R] {G : FGModuleCat.{v} R} {H : Type v} [AddCommGroup H] [Module R H]
(f : G →ₗ[R] H) : f.comp (ModuleCat.Hom.hom (𝟙 G)) = f :=
ModuleCat.hom_ext_iff.mp <| Category.id_comp (ModuleCat.ofHom f)
@[simp] theorem LinearMap.id_fgModuleCat_comp
{R} [Ring R] {G : Type v} [AddCommGroup G] [Module R G] {H : FGModuleCat.{v} R}
(f : G →ₗ[R] H) : LinearMap.comp (ModuleCat.Hom.hom (𝟙 H)) f = f :=
ModuleCat.hom_ext_iff.mp <| Category.comp_id (ModuleCat.ofHom f) |
.lake/packages/mathlib/Mathlib/Algebra/Category/FGModuleCat/Colimits.lean | import Mathlib.Algebra.Category.FGModuleCat.Basic
import Mathlib.Algebra.Category.ModuleCat.Colimits
import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Category.ModuleCat.Products
import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers
import Mathlib.LinearAlgebra.DirectSum.Finite
/-!
# `forget₂ (FGModuleCat K) (ModuleCat K)` creates all finite colimits.
And hence `FGModuleCat K` has all finite colimits.
-/
noncomputable section
universe v u
open CategoryTheory Limits
namespace FGModuleCat
variable {J : Type} [SmallCategory J] [FinCategory J] {k : Type u} [Ring k]
instance {J : Type} [Finite J] (Z : J → ModuleCat.{v} k) [∀ j, Module.Finite k (Z j)] :
Module.Finite k (∐ fun j => Z j : ModuleCat.{v} k) := by
classical
exact (Module.Finite.equiv_iff (ModuleCat.coprodIsoDirectSum Z).toLinearEquiv).mpr inferInstance
/-- Finite colimits of finite modules are finite, because we can realise them as quotients
of a finite coproduct. -/
instance (F : J ⥤ FGModuleCat k) :
Module.Finite k (colimit (F ⋙ forget₂ (FGModuleCat k) (ModuleCat.{v} k)) : ModuleCat.{v} k) :=
have (j : J) : Module.Finite k ((F ⋙ forget₂ (FGModuleCat k) (ModuleCat.{v} k)).obj j) := by
change Module.Finite k (F.obj j); infer_instance
Module.Finite.of_surjective
(colimitQuotientCoproduct (F ⋙ forget₂ (FGModuleCat k) (ModuleCat.{v} k))).hom
((ModuleCat.epi_iff_surjective _).1 inferInstance)
/-- The forgetful functor from `FGModuleCat k` to `ModuleCat k` creates all finite colimits. -/
def forget₂CreatesColimit (F : J ⥤ FGModuleCat k) :
CreatesColimit F (forget₂ (FGModuleCat k) (ModuleCat.{v} k)) :=
createsColimitOfFullyFaithfulOfIso
⟨(colimit (F ⋙ forget₂ (FGModuleCat k) (ModuleCat.{v} k)) : ModuleCat.{v} k),
by rw [ModuleCat.isFG_iff]; infer_instance⟩
(Iso.refl _)
instance : CreatesColimitsOfShape J (forget₂ (FGModuleCat k) (ModuleCat.{v} k)) where
CreatesColimit {F} := forget₂CreatesColimit F
instance (J : Type) [Category J] [FinCategory J] :
HasColimitsOfShape J (FGModuleCat.{v} k) :=
hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape
(forget₂ (FGModuleCat k) (ModuleCat.{v} k))
instance : HasFiniteColimits (FGModuleCat.{v} k) where
out _ _ _ := inferInstance
instance : PreservesFiniteColimits (forget₂ (FGModuleCat k) (ModuleCat.{v} k)) where
preservesFiniteColimits _ _ _ := inferInstance
end FGModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/FGModuleCat/Limits.lean | import Mathlib.Algebra.Category.FGModuleCat.Basic
import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Category.ModuleCat.Limits
import Mathlib.Algebra.Category.ModuleCat.Products
import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers
/-!
# `forget₂ (FGModuleCat K) (ModuleCat K)` creates all finite limits.
And hence `FGModuleCat K` has all finite limits.
## Future work
After generalising `FGModuleCat` to allow the ring and the module to live in different universes,
generalize this construction so we can take limits over smaller diagrams,
as is done for the other algebraic categories.
Analogous constructions for Noetherian modules.
-/
noncomputable section
universe v u
open CategoryTheory Limits
namespace FGModuleCat
variable {J : Type} [SmallCategory J] [FinCategory J]
variable {k : Type u} [Ring k]
instance {J : Type} [Finite J] (Z : J → ModuleCat.{v} k) [∀ j, Module.Finite k (Z j)] :
Module.Finite k (∏ᶜ fun j => Z j : ModuleCat.{v} k) :=
haveI : Module.Finite k (ModuleCat.of k (∀ j, Z j)) := by unfold ModuleCat.of; infer_instance
(Module.Finite.equiv_iff (ModuleCat.piIsoPi Z).toLinearEquiv).mpr inferInstance
variable [IsNoetherianRing k]
/-- Finite limits of finite-dimensional vector spaces are finite dimensional,
because we can realise them as subobjects of a finite product. -/
instance (F : J ⥤ FGModuleCat k) :
Module.Finite k (limit (F ⋙ forget₂ (FGModuleCat k) (ModuleCat.{v} k)) : ModuleCat.{v} k) :=
haveI : ∀ j, Module.Finite k ((F ⋙ forget₂ (FGModuleCat k) (ModuleCat.{v} k)).obj j) := by
intro j; change Module.Finite k (F.obj j); infer_instance
Module.Finite.of_injective
(limitSubobjectProduct (F ⋙ forget₂ (FGModuleCat k) (ModuleCat.{v} k))).hom
((ModuleCat.mono_iff_injective _).1 inferInstance)
/-- The forgetful functor from `FGModuleCat k` to `ModuleCat k` creates all finite limits. -/
def forget₂CreatesLimit (F : J ⥤ FGModuleCat k) :
CreatesLimit F (forget₂ (FGModuleCat k) (ModuleCat.{v} k)) :=
createsLimitOfFullyFaithfulOfIso
⟨(limit (F ⋙ forget₂ (FGModuleCat k) (ModuleCat.{v} k)) : ModuleCat.{v} k),
by rw [ModuleCat.isFG_iff]; infer_instance⟩
(Iso.refl _)
instance : CreatesLimitsOfShape J (forget₂ (FGModuleCat k) (ModuleCat.{v} k)) where
CreatesLimit {F} := forget₂CreatesLimit F
instance (J : Type) [Category J] [FinCategory J] :
HasLimitsOfShape J (FGModuleCat.{v} k) :=
hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape
(forget₂ (FGModuleCat k) (ModuleCat.{v} k))
instance : HasFiniteLimits (FGModuleCat.{v} k) where
out _ _ _ := inferInstance
instance : PreservesFiniteLimits (forget₂ (FGModuleCat k) (ModuleCat.{v} k)) where
preservesFiniteLimits _ _ _ := inferInstance
end FGModuleCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/HopfAlgCat/Monoidal.lean | import Mathlib.Algebra.Category.BialgCat.Monoidal
import Mathlib.Algebra.Category.HopfAlgCat.Basic
import Mathlib.RingTheory.HopfAlgebra.TensorProduct
/-!
# The monoidal structure on the category of Hopf algebras
In `Mathlib/RingTheory/HopfAlgebra/TensorProduct.lean`, given two Hopf `R`-algebras `A, B`, we
define a Hopf `R`-algebra instance on `A ⊗[R] B`.
Here, we use this to declare a `MonoidalCategory` instance on the category of Hopf algebras, via
the existing monoidal structure on `BialgCat`.
-/
universe u
namespace HopfAlgCat
open CategoryTheory MonoidalCategory TensorProduct
variable (R : Type u) [CommRing R]
@[simps] noncomputable instance instMonoidalCategoryStruct :
MonoidalCategoryStruct.{u} (HopfAlgCat R) where
tensorObj X Y := of R (X ⊗[R] Y)
whiskerLeft X _ _ f := ofHom (f.1.lTensor X)
whiskerRight f X := ofHom (f.1.rTensor X)
tensorHom f g := ofHom (Bialgebra.TensorProduct.map f.1 g.1)
tensorUnit := of R R
associator X Y Z := (Bialgebra.TensorProduct.assoc R R X Y Z).toHopfAlgIso
leftUnitor X := (Bialgebra.TensorProduct.lid R X).toHopfAlgIso
rightUnitor X := (Bialgebra.TensorProduct.rid R R X).toHopfAlgIso
/-- The data needed to induce a `MonoidalCategory` structure via
`HopfAlgCat.instMonoidalCategoryStruct` and the forgetful functor to bialgebras. -/
@[simps]
noncomputable def MonoidalCategory.inducingFunctorData :
Monoidal.InducingFunctorData (forget₂ (HopfAlgCat R) (BialgCat R)) where
μIso _ _ := Iso.refl _
whiskerLeft_eq _ _ _ _ := by ext; rfl
whiskerRight_eq _ _ := by ext; rfl
tensorHom_eq _ _ := by ext; rfl
εIso := Iso.refl _
associator_eq _ _ _ := BialgCat.Hom.ext <| BialgHom.coe_linearMap_injective <|
TensorProduct.ext <| TensorProduct.ext (by ext; rfl)
leftUnitor_eq _ := BialgCat.Hom.ext <| BialgHom.coe_linearMap_injective <|
TensorProduct.ext (by ext; rfl)
rightUnitor_eq _ := BialgCat.Hom.ext <| BialgHom.coe_linearMap_injective <|
TensorProduct.ext (by ext; rfl)
noncomputable instance instMonoidalCategory : MonoidalCategory (HopfAlgCat R) :=
Monoidal.induced (forget₂ _ (BialgCat R)) (MonoidalCategory.inducingFunctorData R)
/-- `forget₂ (HopfAlgCat R) (BialgCat R)` is a monoidal functor. -/
noncomputable instance : (forget₂ (HopfAlgCat R) (BialgCat R)).Monoidal where
end HopfAlgCat |
.lake/packages/mathlib/Mathlib/Algebra/Category/HopfAlgCat/Basic.lean | import Mathlib.Algebra.Category.BialgCat.Basic
import Mathlib.RingTheory.HopfAlgebra.Basic
/-!
# The category of Hopf algebras over a commutative ring
We introduce the bundled category `HopfAlgCat` of Hopf algebras over a fixed commutative ring
`R` along with the forgetful functor to `BialgCat`.
This file mimics `Mathlib/LinearAlgebra/QuadraticForm/QuadraticModuleCat.lean`.
-/
open CategoryTheory
universe v u
variable (R : Type u) [CommRing R]
/-- The category of `R`-Hopf algebras. -/
structure HopfAlgCat where
private mk ::
/-- The underlying type. -/
carrier : Type v
[instRing : Ring carrier]
[instHopfAlgebra : HopfAlgebra R carrier]
attribute [instance] HopfAlgCat.instHopfAlgebra HopfAlgCat.instRing
variable {R}
namespace HopfAlgCat
open HopfAlgebra
instance : CoeSort (HopfAlgCat.{v} R) (Type v) :=
⟨(·.carrier)⟩
variable (R) in
/-- The object in the category of `R`-Hopf algebras associated to an `R`-Hopf algebra. -/
abbrev of (X : Type v) [Ring X] [HopfAlgebra R X] :
HopfAlgCat R where
carrier := X
@[simp]
lemma of_comul {X : Type v} [Ring X] [HopfAlgebra R X] :
Coalgebra.comul (A := of R X) = Coalgebra.comul (R := R) (A := X) := rfl
@[simp]
lemma of_counit {X : Type v} [Ring X] [HopfAlgebra R X] :
Coalgebra.counit (A := of R X) = Coalgebra.counit (R := R) (A := X) := rfl
/-- A type alias for `BialgHom` to avoid confusion between the categorical and
algebraic spellings of composition. -/
@[ext]
structure Hom (V W : HopfAlgCat.{v} R) where
/-- The underlying `BialgHom`. -/
toBialgHom' : V →ₐc[R] W
instance category : Category (HopfAlgCat.{v} R) where
Hom X Y := Hom X Y
id X := ⟨BialgHom.id R X⟩
comp f g := ⟨BialgHom.comp g.toBialgHom' f.toBialgHom'⟩
instance concreteCategory : ConcreteCategory (HopfAlgCat.{v} R) (· →ₐc[R] ·) where
hom f := f.toBialgHom'
ofHom f := ⟨f⟩
/-- Turn a morphism in `HopfAlgCat` back into a `BialgHom`. -/
abbrev Hom.toBialgHom {X Y : HopfAlgCat R} (f : Hom X Y) :=
ConcreteCategory.hom (C := HopfAlgCat R) f
/-- Typecheck a `BialgHom` as a morphism in `HopfAlgCat R`. -/
abbrev ofHom {X Y : Type v} [Ring X] [Ring Y]
[HopfAlgebra R X] [HopfAlgebra R Y] (f : X →ₐc[R] Y) :
of R X ⟶ of R Y :=
ConcreteCategory.ofHom f
lemma Hom.toBialgHom_injective (V W : HopfAlgCat.{v} R) :
Function.Injective (Hom.toBialgHom : Hom V W → _) :=
fun ⟨f⟩ ⟨g⟩ _ => by congr
@[ext]
lemma hom_ext {X Y : HopfAlgCat.{v} R} (f g : X ⟶ Y) (h : f.toBialgHom = g.toBialgHom) :
f = g :=
Hom.ext h
@[simp] theorem toBialgHom_comp {X Y Z : HopfAlgCat.{v} R} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).toBialgHom = g.toBialgHom.comp f.toBialgHom :=
rfl
@[simp] theorem toBialgHom_id {M : HopfAlgCat.{v} R} :
Hom.toBialgHom (𝟙 M) = BialgHom.id _ _ :=
rfl
instance hasForgetToBialgebra : HasForget₂ (HopfAlgCat R) (BialgCat R) where
forget₂ :=
{ obj := fun X => BialgCat.of R X
map := fun {_ _} f => BialgCat.ofHom f.toBialgHom }
@[simp]
theorem forget₂_bialgebra_obj (X : HopfAlgCat R) :
(forget₂ (HopfAlgCat R) (BialgCat R)).obj X = BialgCat.of R X :=
rfl
@[simp]
theorem forget₂_bialgebra_map (X Y : HopfAlgCat R) (f : X ⟶ Y) :
(forget₂ (HopfAlgCat R) (BialgCat R)).map f = BialgCat.ofHom f.toBialgHom :=
rfl
end HopfAlgCat
namespace BialgEquiv
open HopfAlgCat
variable {X Y Z : Type v}
variable [Ring X] [Ring Y] [Ring Z]
variable [HopfAlgebra R X] [HopfAlgebra R Y] [HopfAlgebra R Z]
/-- Build an isomorphism in the category `HopfAlgCat R` from a
`BialgEquiv`. -/
@[simps]
def toHopfAlgIso (e : X ≃ₐc[R] Y) : HopfAlgCat.of R X ≅ HopfAlgCat.of R Y where
hom := HopfAlgCat.ofHom e
inv := HopfAlgCat.ofHom e.symm
hom_inv_id := Hom.ext <| DFunLike.ext _ _ e.left_inv
inv_hom_id := Hom.ext <| DFunLike.ext _ _ e.right_inv
@[simp] theorem toHopfAlgIso_refl :
toHopfAlgIso (BialgEquiv.refl R X) = .refl _ :=
rfl
@[simp] theorem toHopfAlgIso_symm (e : X ≃ₐc[R] Y) :
toHopfAlgIso e.symm = (toHopfAlgIso e).symm :=
rfl
@[simp] theorem toHopfAlgIso_trans (e : X ≃ₐc[R] Y) (f : Y ≃ₐc[R] Z) :
toHopfAlgIso (e.trans f) = toHopfAlgIso e ≪≫ toHopfAlgIso f :=
rfl
end BialgEquiv
namespace CategoryTheory.Iso
open HopfAlgebra
variable {X Y Z : HopfAlgCat.{v} R}
/-- Build a `BialgEquiv` from an isomorphism in the category
`HopfAlgCat R`. -/
def toHopfAlgEquiv (i : X ≅ Y) : X ≃ₐc[R] Y :=
{ i.hom.toBialgHom with
invFun := i.inv.toBialgHom
left_inv := fun x => BialgHom.congr_fun (congr_arg HopfAlgCat.Hom.toBialgHom i.3) x
right_inv := fun x => BialgHom.congr_fun (congr_arg HopfAlgCat.Hom.toBialgHom i.4) x }
@[simp] theorem toHopfAlgEquiv_toBialgHom (i : X ≅ Y) :
(i.toHopfAlgEquiv : X →ₐc[R] Y) = i.hom.1 := rfl
@[simp] theorem toHopfAlgEquiv_refl : toHopfAlgEquiv (.refl X) = .refl _ _ :=
rfl
@[simp] theorem toHopfAlgEquiv_symm (e : X ≅ Y) :
toHopfAlgEquiv e.symm = (toHopfAlgEquiv e).symm :=
rfl
@[simp] theorem toHopfAlgEquiv_trans (e : X ≅ Y) (f : Y ≅ Z) :
toHopfAlgEquiv (e ≪≫ f) = e.toHopfAlgEquiv.trans f.toHopfAlgEquiv :=
rfl
end CategoryTheory.Iso
instance HopfAlgCat.forget_reflects_isos :
(forget (HopfAlgCat.{v} R)).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget (HopfAlgCat.{v} R)).map f)
let e : X ≃ₐc[R] Y := { f.toBialgHom, i.toEquiv with }
exact ⟨e.toHopfAlgIso.isIso_hom.1⟩ |
.lake/packages/mathlib/Mathlib/Algebra/Category/Semigrp/Basic.lean | import Mathlib.Algebra.PEmptyInstances
import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.CategoryTheory.Elementwise
import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic
/-!
# Category instances for `Mul`, `Add`, `Semigroup` and `AddSemigroup`
We introduce the bundled categories:
* `MagmaCat`
* `AddMagmaCat`
* `Semigrp`
* `AddSemigrp`
along with the relevant forgetful functors between them.
This closely follows `Mathlib/Algebra/Category/MonCat/Basic.lean`.
## TODO
* Limits in these categories
* free/forgetful adjunctions
-/
universe u v
open CategoryTheory
/-- The category of additive magmas and additive magma morphisms. -/
structure AddMagmaCat : Type (u + 1) where
/-- The underlying additive magma. -/
(carrier : Type u)
[str : Add carrier]
/-- The category of magmas and magma morphisms. -/
@[to_additive]
structure MagmaCat : Type (u + 1) where
/-- The underlying magma. -/
(carrier : Type u)
[str : Mul carrier]
attribute [instance] AddMagmaCat.str MagmaCat.str
initialize_simps_projections AddMagmaCat (carrier → coe, -str)
initialize_simps_projections MagmaCat (carrier → coe, -str)
namespace MagmaCat
@[to_additive]
instance : CoeSort MagmaCat (Type u) :=
⟨MagmaCat.carrier⟩
attribute [coe] AddMagmaCat.carrier MagmaCat.carrier
/-- Construct a bundled `MagmaCat` from the underlying type and typeclass. -/
@[to_additive /-- Construct a bundled `AddMagmaCat` from the underlying type and typeclass. -/]
abbrev of (M : Type u) [Mul M] : MagmaCat := ⟨M⟩
end MagmaCat
/-- The type of morphisms in `AddMagmaCat R`. -/
@[ext]
structure AddMagmaCat.Hom (A B : AddMagmaCat.{u}) where
private mk ::
/-- The underlying `AddHom`. -/
hom' : A →ₙ+ B
/-- The type of morphisms in `MagmaCat R`. -/
@[to_additive, ext]
structure MagmaCat.Hom (A B : MagmaCat.{u}) where
private mk ::
/-- The underlying `MulHom`. -/
hom' : A →ₙ* B
namespace MagmaCat
@[to_additive]
instance : Category MagmaCat.{u} where
Hom X Y := Hom X Y
id X := ⟨MulHom.id X⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
@[to_additive]
instance : ConcreteCategory MagmaCat (· →ₙ* ·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `MagmaCat` back into a `MulHom`. -/
@[to_additive /-- Turn a morphism in `AddMagmaCat` back into an `AddHom`. -/]
abbrev Hom.hom {X Y : MagmaCat.{u}} (f : Hom X Y) :=
ConcreteCategory.hom (C := MagmaCat) f
/-- Typecheck a `MulHom` as a morphism in `MagmaCat`. -/
@[to_additive /-- Typecheck an `AddHom` as a morphism in `AddMagmaCat`. -/]
abbrev ofHom {X Y : Type u} [Mul X] [Mul Y] (f : X →ₙ* Y) : of X ⟶ of Y :=
ConcreteCategory.ofHom (C := MagmaCat) f
variable {R} in
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (X Y : MagmaCat.{u}) (f : Hom X Y) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
initialize_simps_projections AddMagmaCat.Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[to_additive (attr := simp)]
lemma coe_id {X : MagmaCat} : (𝟙 X : X → X) = id := rfl
@[to_additive (attr := simp)]
lemma coe_comp {X Y Z : MagmaCat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
@[to_additive (attr := simp)]
lemma forget_map {X Y : MagmaCat} (f : X ⟶ Y) :
(forget MagmaCat).map f = f := rfl
@[to_additive (attr := ext)]
lemma ext {X Y : MagmaCat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g :=
ConcreteCategory.hom_ext _ _ w
@[to_additive]
-- This is not `simp` to avoid rewriting in types of terms.
theorem coe_of (M : Type u) [Mul M] : (MagmaCat.of M : Type u) = M := rfl
@[to_additive (attr := simp)]
lemma hom_id {M : MagmaCat} : (𝟙 M : M ⟶ M).hom = MulHom.id M := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma id_apply (M : MagmaCat) (x : M) :
(𝟙 M : M ⟶ M) x = x := by simp
@[to_additive (attr := simp)]
lemma hom_comp {M N T : MagmaCat} (f : M ⟶ N) (g : N ⟶ T) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma comp_apply {M N T : MagmaCat} (f : M ⟶ N) (g : N ⟶ T) (x : M) :
(f ≫ g) x = g (f x) := by simp
@[to_additive (attr := ext)]
lemma hom_ext {M N : MagmaCat} {f g : M ⟶ N} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[to_additive (attr := simp)]
lemma hom_ofHom {M N : Type u} [Mul M] [Mul N] (f : M →ₙ* N) : (ofHom f).hom = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_hom {M N : MagmaCat} (f : M ⟶ N) :
ofHom (Hom.hom f) = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_id {M : Type u} [Mul M] : ofHom (MulHom.id M) = 𝟙 (of M) := rfl
@[to_additive (attr := simp)]
lemma ofHom_comp {M N P : Type u} [Mul M] [Mul N] [Mul P]
(f : M →ₙ* N) (g : N →ₙ* P) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
@[to_additive]
lemma ofHom_apply {X Y : Type u} [Mul X] [Mul Y] (f : X →ₙ* Y) (x : X) :
(ofHom f) x = f x := rfl
@[to_additive]
lemma inv_hom_apply {M N : MagmaCat} (e : M ≅ N) (x : M) : e.inv (e.hom x) = x := by
simp
@[to_additive]
lemma hom_inv_apply {M N : MagmaCat} (e : M ≅ N) (s : N) : e.hom (e.inv s) = s := by
simp
@[to_additive (attr := simp)]
lemma mulEquiv_coe_eq {X Y : Type _} [Mul X] [Mul Y] (e : X ≃* Y) :
(ofHom (e : X →ₙ* Y)).hom = ↑e :=
rfl
@[to_additive]
instance : Inhabited MagmaCat :=
⟨MagmaCat.of PEmpty⟩
end MagmaCat
/-- The category of additive semigroups and semigroup morphisms. -/
structure AddSemigrp : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : AddSemigroup carrier]
/-- The category of semigroups and semigroup morphisms. -/
@[to_additive]
structure Semigrp : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : Semigroup carrier]
attribute [instance] AddSemigrp.str Semigrp.str
initialize_simps_projections AddSemigrp (carrier → coe, -str)
initialize_simps_projections Semigrp (carrier → coe, -str)
namespace Semigrp
@[to_additive]
instance : CoeSort Semigrp (Type u) :=
⟨Semigrp.carrier⟩
attribute [coe] AddSemigrp.carrier Semigrp.carrier
/-- Construct a bundled `Semigrp` from the underlying type and typeclass. -/
@[to_additive /-- Construct a bundled `AddSemigrp` from the underlying type and typeclass. -/]
abbrev of (M : Type u) [Semigroup M] : Semigrp := ⟨M⟩
end Semigrp
/-- The type of morphisms in `AddSemigrp R`. -/
@[ext]
structure AddSemigrp.Hom (A B : AddSemigrp.{u}) where
private mk ::
/-- The underlying `AddHom`. -/
hom' : A →ₙ+ B
/-- The type of morphisms in `Semigrp R`. -/
@[to_additive, ext]
structure Semigrp.Hom (A B : Semigrp.{u}) where
private mk ::
/-- The underlying `MulHom`. -/
hom' : A →ₙ* B
namespace Semigrp
@[to_additive]
instance : Category Semigrp.{u} where
Hom X Y := Hom X Y
id X := ⟨MulHom.id X⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
@[to_additive]
instance : ConcreteCategory Semigrp (· →ₙ* ·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `Semigrp` back into a `MulHom`. -/
@[to_additive /-- Turn a morphism in `AddSemigrp` back into an `AddHom`. -/]
abbrev Hom.hom {X Y : Semigrp.{u}} (f : Hom X Y) :=
ConcreteCategory.hom (C := Semigrp) f
/-- Typecheck a `MulHom` as a morphism in `Semigrp`. -/
@[to_additive /-- Typecheck an `AddHom` as a morphism in `AddSemigrp`. -/]
abbrev ofHom {X Y : Type u} [Semigroup X] [Semigroup Y] (f : X →ₙ* Y) : of X ⟶ of Y :=
ConcreteCategory.ofHom (C := Semigrp) f
variable {R} in
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (X Y : Semigrp.{u}) (f : Hom X Y) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
initialize_simps_projections AddSemigrp.Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[to_additive (attr := simp)]
lemma coe_id {X : Semigrp} : (𝟙 X : X → X) = id := rfl
@[to_additive (attr := simp)]
lemma coe_comp {X Y Z : Semigrp} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
@[simp] lemma forget_map {X Y : Semigrp} (f : X ⟶ Y) : (forget Semigrp).map f = (f : X → Y) := rfl
@[to_additive (attr := ext)]
lemma ext {X Y : Semigrp} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g :=
ConcreteCategory.hom_ext _ _ w
@[to_additive]
-- This is not `simp` to avoid rewriting in types of terms.
theorem coe_of (R : Type u) [Semigroup R] : ↑(Semigrp.of R) = R :=
rfl
@[to_additive (attr := simp)]
lemma hom_id {X : Semigrp} : (𝟙 X : X ⟶ X).hom = MulHom.id X := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma id_apply (X : Semigrp) (x : X) :
(𝟙 X : X ⟶ X) x = x := by simp
@[to_additive (attr := simp)]
lemma hom_comp {X Y T : Semigrp} (f : X ⟶ Y) (g : Y ⟶ T) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma comp_apply {X Y T : Semigrp} (f : X ⟶ Y) (g : Y ⟶ T) (x : X) :
(f ≫ g) x = g (f x) := by simp
@[to_additive (attr := ext)]
lemma hom_ext {X Y : Semigrp} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[to_additive (attr := simp)]
lemma hom_ofHom {X Y : Type u} [Semigroup X] [Semigroup Y] (f : X →ₙ* Y) : (ofHom f).hom = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_hom {X Y : Semigrp} (f : X ⟶ Y) :
ofHom (Hom.hom f) = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_id {X : Type u} [Semigroup X] : ofHom (MulHom.id X) = 𝟙 (of X) := rfl
@[to_additive (attr := simp)]
lemma ofHom_comp {X Y Z : Type u} [Semigroup X] [Semigroup Y] [Semigroup Z]
(f : X →ₙ* Y) (g : Y →ₙ* Z) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
@[to_additive]
lemma ofHom_apply {X Y : Type u} [Semigroup X] [Semigroup Y] (f : X →ₙ* Y) (x : X) :
(ofHom f) x = f x := rfl
@[to_additive]
lemma inv_hom_apply {X Y : Semigrp} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by
simp
@[to_additive]
lemma hom_inv_apply {X Y : Semigrp} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by
simp
@[to_additive (attr := simp)]
lemma mulEquiv_coe_eq {X Y : Type _} [Semigroup X] [Semigroup Y] (e : X ≃* Y) :
(ofHom (e : X →ₙ* Y)).hom = ↑e :=
rfl
@[to_additive]
instance : Inhabited Semigrp :=
⟨Semigrp.of PEmpty⟩
@[to_additive]
instance hasForgetToMagmaCat : HasForget₂ Semigrp MagmaCat where
forget₂ :=
{ obj R := MagmaCat.of R
map f := MagmaCat.ofHom f.hom }
end Semigrp
variable {X Y : Type u}
section
variable [Mul X] [Mul Y]
/-- Build an isomorphism in the category `MagmaCat` from a `MulEquiv` between `Mul`s. -/
@[to_additive (attr := simps)
/-- Build an isomorphism in the category `AddMagmaCat` from an `AddEquiv` between `Add`s. -/]
def MulEquiv.toMagmaCatIso (e : X ≃* Y) : MagmaCat.of X ≅ MagmaCat.of Y where
hom := MagmaCat.ofHom e.toMulHom
inv := MagmaCat.ofHom e.symm.toMulHom
end
section
variable [Semigroup X] [Semigroup Y]
/-- Build an isomorphism in the category `Semigroup` from a `MulEquiv` between `Semigroup`s. -/
@[to_additive (attr := simps)
/-- Build an isomorphism in the category
`AddSemigroup` from an `AddEquiv` between `AddSemigroup`s. -/]
def MulEquiv.toSemigrpIso (e : X ≃* Y) : Semigrp.of X ≅ Semigrp.of Y where
hom := Semigrp.ofHom e.toMulHom
inv := Semigrp.ofHom e.symm.toMulHom
end
namespace CategoryTheory.Iso
/-- Build a `MulEquiv` from an isomorphism in the category `MagmaCat`. -/
@[to_additive
/-- Build an `AddEquiv` from an isomorphism in the category `AddMagmaCat`. -/]
def magmaCatIsoToMulEquiv {X Y : MagmaCat} (i : X ≅ Y) : X ≃* Y :=
MulHom.toMulEquiv i.hom.hom i.inv.hom (by ext; simp) (by ext; simp)
/-- Build a `MulEquiv` from an isomorphism in the category `Semigroup`. -/
@[to_additive
/-- Build an `AddEquiv` from an isomorphism in the category `AddSemigroup`. -/]
def semigrpIsoToMulEquiv {X Y : Semigrp} (i : X ≅ Y) : X ≃* Y :=
MulHom.toMulEquiv i.hom.hom i.inv.hom (by ext; simp) (by ext; simp)
end CategoryTheory.Iso
/-- multiplicative equivalences between `Mul`s are the same as (isomorphic to) isomorphisms
in `MagmaCat` -/
@[to_additive
/-- additive equivalences between `Add`s are the same
as (isomorphic to) isomorphisms in `AddMagmaCat` -/]
def mulEquivIsoMagmaIso {X Y : Type u} [Mul X] [Mul Y] :
X ≃* Y ≅ MagmaCat.of X ≅ MagmaCat.of Y where
hom e := e.toMagmaCatIso
inv i := i.magmaCatIsoToMulEquiv
/-- multiplicative equivalences between `Semigroup`s are the same as (isomorphic to) isomorphisms
in `Semigroup` -/
@[to_additive
/-- additive equivalences between `AddSemigroup`s are
the same as (isomorphic to) isomorphisms in `AddSemigroup` -/]
def mulEquivIsoSemigrpIso {X Y : Type u} [Semigroup X] [Semigroup Y] :
X ≃* Y ≅ Semigrp.of X ≅ Semigrp.of Y where
hom e := e.toSemigrpIso
inv i := i.semigrpIsoToMulEquiv
@[to_additive]
instance MagmaCat.forgetReflectsIsos : (forget MagmaCat.{u}).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget MagmaCat).map f)
let e : X ≃* Y := { f.hom, i.toEquiv with }
exact e.toMagmaCatIso.isIso_hom
@[to_additive]
instance Semigrp.forgetReflectsIsos : (forget Semigrp.{u}).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget Semigrp).map f)
let e : X ≃* Y := { f.hom, i.toEquiv with }
exact e.toSemigrpIso.isIso_hom
/--
Ensure that `forget₂ CommMonCat MonCat` automatically reflects isomorphisms.
We could have used `CategoryTheory.HasForget.ReflectsIso` alternatively.
-/
@[to_additive]
instance Semigrp.forget₂_full : (forget₂ Semigrp MagmaCat).Full where
map_surjective f := ⟨ofHom f.hom, rfl⟩
/-!
Once we've shown that the forgetful functors to type reflect isomorphisms,
we automatically obtain that the `forget₂` functors between our concrete categories
reflect isomorphisms.
-/
example : (forget₂ Semigrp MagmaCat).ReflectsIsomorphisms := inferInstance |
.lake/packages/mathlib/Mathlib/Algebra/QuadraticAlgebra/Basic.lean | import Mathlib.Algebra.QuadraticAlgebra.Defs
import Mathlib.Algebra.Star.Unitary
import Mathlib.Tactic.FieldSimp
/-! # Quadratic algebras : involution and norm.
Let `R` be a commutative ring. We define:
* `QuadraticAlgebra.star` : the quadratic involution
* `QuadraticAlgebra.norm` : the norm
We prove :
* `QuadraticAlgebra.isUnit_iff_norm_isUnit`:
`w : QuadraticAlgebra R a b` is a unit iff `w.norm` is a unit in `R`.
* `QuadraticAlgebra.norm_mem_nonZero_divisors_iff`:
`w : QuadraticAlgebra R a b` isn't a zero divisor iff
`w.norm` isn't a zero divisor in `R`.
* If `R` is a field, and `∀ r, r ^ 2 ≠ a + b * r`, then `QuadraticAlgebra R a b` is a field.
-/
namespace QuadraticAlgebra
variable {R : Type*} {a b : R}
section omega
section
variable [Zero R] [One R]
/-- The representative of the root in the quadratic algebra -/
def omega : QuadraticAlgebra R a b :=
⟨0, 1⟩
/-- the canonical element `⟨0, 1⟩` in a quadratic algebra `QuadraticAlgebra R a b`. -/
scoped notation "ω" => omega
@[simp]
theorem omega_re : (ω : QuadraticAlgebra R a b).re = 0 :=
rfl
@[simp]
theorem omega_im : (ω : QuadraticAlgebra R a b).im = 1 :=
rfl
end
variable [CommSemiring R]
theorem omega_mul_omega_eq_mk : (ω : QuadraticAlgebra R a b) * ω = ⟨a, b⟩ := by
ext <;> simp
theorem omega_mul_omega_eq_add :
(ω : QuadraticAlgebra R a b) * ω = a • 1 + b • ω := by
ext <;> simp
@[simp]
theorem omega_mul_mk (x y : R) : (ω : QuadraticAlgebra R a b) * ⟨x, y⟩ = ⟨a * y, x + b * y⟩ := by
ext <;> simp
@[simp]
theorem omega_mul_coe_mul_mk (n x y : R) :
(ω : QuadraticAlgebra R a b) * n * ⟨x, y⟩ = ⟨a * n * y, n * x + n * b * y⟩ := by
ext <;> simp only [re_mul, omega_re, re_coe, zero_mul, omega_im, mul_one, im_coe, mul_zero,
add_zero, im_mul, one_mul, zero_add]; ring
theorem mk_eq_add_smul_omega (x y : R) :
(⟨x, y⟩ : QuadraticAlgebra R a b) = x + y • (ω : QuadraticAlgebra R a b) := by
ext <;> simp
variable {A : Type*} [Ring A] [Algebra R A]
@[ext]
theorem algHom_ext {f g : QuadraticAlgebra R a b →ₐ[R] A}
(h : f ω = g ω) : f = g := by
ext ⟨x, y⟩
simp [mk_eq_add_smul_omega, h, ← coe_algebraMap]
/-- The unique `AlgHom` from `QuadraticAlgebra R a b` to an `R`-algebra `A`,
constructed by replacing `ω` with the provided root.
Conversely, this associates to every algebra morphism `QuadraticAlgebra R a b →ₐ[R] A`
a value of `ω` in `A`. -/
@[simps]
def lift : { u : A // u * u = a • 1 + b • u } ≃ (QuadraticAlgebra R a b →ₐ[R] A) where
toFun u :=
{ toFun z := z.re • 1 + z.im • u
map_zero' := by simp
map_add' z w := by
simp only [re_add, im_add, add_smul, ← add_assoc]
congr 1
simp only [add_assoc]
congr 1
rw [add_comm]
map_one' := by simp
map_mul' z w := by
symm
calc
(z.re • (1 : A) + z.im • ↑u) * (w.re • 1 + w.im • ↑u) =
(z.re * w.re) • (1 : A) + (z.re * w.im) • u +
(z.im * w.re) • u + (z.im * w.im) • (u * u) := by
simp only [mul_add, mul_one, add_mul, one_mul, ← add_assoc, smul_mul_smul]
apply add_add_add_comm'
_ = (z.re * w.re) • (1 : A) + (z.re * w.im+ z.im * w.re) • u +
(z.im * w.im) • (u * u) := by
congr 1
simp only [add_assoc]
rw [← add_smul]
_ = (z.re * w.re) • 1 + (z.re * w.im + z.im * w.re) • u +
(z.im * w.im) • (a • 1 + b • u) := by
simp [u.prop]
_ = (z.re * w.re + a * z.im * w.im) • 1 +
(z.re * w.im + z.im * w.re + b * z.im * w.im) • u := by
simp only [smul_add]
module
_ = (z * w).re • 1 + (z * w).im • u := by
simp
commutes' r := by
simp [← Algebra.algebraMap_eq_smul_one] }
invFun f := ⟨f (ω), by
simp [← map_mul, omega_mul_omega_eq_add]
⟩
left_inv r := by
simp
right_inv f := by
ext
simp
end omega
section star
variable [CommRing R]
/-- Conjugation in `QuadraticAlgebra R a b`.
The conjugate of `x + y ω` is `x + y ω' = (x - a * y) - y ω`. -/
instance : Star (QuadraticAlgebra R a b) where
star z := ⟨z.re + b * z.im, -z.im⟩
@[simp]
theorem star_mk (x y : R) :
star (⟨x, y⟩ : QuadraticAlgebra R a b) = ⟨x + b * y, -y⟩ :=
rfl
@[simp]
theorem re_star (z : QuadraticAlgebra R a b) :
(star z).re = z.re + b * z.im :=
rfl
@[simp]
theorem im_star (z : QuadraticAlgebra R a b) :
(star z).im = -z.im :=
rfl
theorem mul_star (x y : R) :
(⟨x, y⟩ * star ⟨x, y⟩ : QuadraticAlgebra R a b) =
x * x + b * x * y - a * y * y := by
ext <;>
simp only [star_mk, mk_mul_mk, mul_neg, im_sub, im_add, im_mul, re_coe, im_coe, mul_zero,
zero_mul, add_zero, re_mul, sub_self, re_sub, re_add] <;> ring
instance : StarRing (QuadraticAlgebra R a b) where
star_involutive _ := by
refine QuadraticAlgebra.ext (by simp) (neg_neg _)
star_mul a b := by ext <;>
simp only [re_star, re_mul, im_mul, im_star, mul_neg, neg_mul, neg_neg] <;> ring
star_add _ _ := QuadraticAlgebra.ext (by simp only [re_star, re_add, im_add]; ring) (neg_add _ _)
end star
section norm
variable [CommRing R]
/-- the norm in a quadratic algebra, as a `MonoidHom`. -/
def norm : QuadraticAlgebra R a b →* R where
toFun z := z.re * z.re + b * z.re * z.im - a * z.im * z.im
map_mul' z w := by simp only [re_mul, im_mul]; ring
map_one' := by simp
theorem norm_def (z : QuadraticAlgebra R a b) :
z.norm = z.re * z.re + b * z.re * z.im - a * z.im * z.im :=
rfl
@[simp]
theorem norm_zero : norm (0 : QuadraticAlgebra R a b) = 0 := by simp [norm]
@[simp]
theorem norm_one : norm (1 : QuadraticAlgebra R a b) = 1 := by simp [norm]
@[simp]
theorem norm_coe (r : R) : norm (r : QuadraticAlgebra R a b) = r ^ 2 := by simp [norm_def, pow_two]
@[simp]
theorem norm_natCast (n : ℕ) : norm (n : QuadraticAlgebra R a b) = n ^ 2 :=
by simp [norm_def, pow_two]
@[simp]
theorem norm_intCast (n : ℤ) : norm (n : QuadraticAlgebra R a b) = n ^ 2 :=
by simp [norm_def, pow_two]
theorem coe_norm_eq_mul_star (z : QuadraticAlgebra R a b) :
((norm z : R) : QuadraticAlgebra R a b) = z * star z := by
ext <;> simp [norm, star, mul_comm] <;> ring
@[simp]
theorem norm_neg (x : QuadraticAlgebra R a b) : (-x).norm = x.norm := by
simp [norm]
@[simp]
theorem norm_star (x : QuadraticAlgebra R a b) : (star x).norm = x.norm := by
simp only [norm, MonoidHom.coe_mk, OneHom.coe_mk, re_star, im_star, mul_neg, neg_mul, neg_neg,
sub_left_inj]
ring
theorem isUnit_iff_norm_isUnit {x : QuadraticAlgebra R a b} :
IsUnit x ↔ IsUnit (x.norm) := by
constructor
· exact IsUnit.map norm
· simp only [isUnit_iff_exists]
rintro ⟨r, hr, hr'⟩
rw [← coe_inj (R := R) (a := a) (b := b), coe_mul,
coe_norm_eq_mul_star , mul_assoc, coe_one] at hr
refine ⟨_, hr, ?_⟩
rw [mul_comm, hr]
/-- An element of `QuadraticAlgebra R a b` has norm equal to `1`
if and only if it is contained in the submonoid of unitary elements. -/
theorem norm_eq_one_iff_mem_unitary {z : QuadraticAlgebra R a b} :
z.norm = 1 ↔ z ∈ unitary (QuadraticAlgebra R a b) := by
rw [Unitary.mem_iff_self_mul_star, ← coe_norm_eq_mul_star, coe_eq_one_iff]
alias ⟨mem_unitary, norm_eq_one⟩ := norm_eq_one_iff_mem_unitary
/-- The kernel of the norm map on `QuadraticAlgebra R a b` equals
the submonoid of unitary elements. -/
theorem mker_norm_eq_unitary :
MonoidHom.mker (@norm R a b _) = unitary (QuadraticAlgebra R a b) :=
Submonoid.ext fun _ => norm_eq_one_iff_mem_unitary
open nonZeroDivisors
theorem coe_mem_nonZeroDivisors_iff {r : R} :
(r : QuadraticAlgebra R a b) ∈ (QuadraticAlgebra R a b)⁰ ↔ r ∈ R⁰ := by
simp only [mem_nonZeroDivisors_iff_right]
constructor
· intro H x hxr
rw [← coe_inj, coe_zero]
apply H
rw [← coe_mul, hxr, coe_zero]
· intro h z hz
rw [QuadraticAlgebra.ext_iff, re_zero, im_zero] at hz
simp only [re_mul, re_coe, im_coe, mul_zero, add_zero, im_mul, zero_add] at hz
simp [QuadraticAlgebra.ext_iff, re_zero, im_zero, h _ hz.left, h _ hz.right]
theorem star_mem_nonZeroDivisors {z : QuadraticAlgebra R a b}
(hz : z ∈ (QuadraticAlgebra R a b)⁰) :
star z ∈ (QuadraticAlgebra R a b)⁰ := by
rw [mem_nonZeroDivisors_iff_right] at hz ⊢
intro w hw
apply star_involutive.injective
rw [star_zero]
apply hz
rw [← star_involutive z, ← star_mul, mul_comm, hw, star_zero]
theorem star_mem_nonZeroDivisors_iff {z : QuadraticAlgebra R a b} :
star z ∈ (QuadraticAlgebra R a b)⁰ ↔ z ∈ (QuadraticAlgebra R a b)⁰ := by
refine ⟨fun h ↦ ?_, star_mem_nonZeroDivisors⟩
rw [← star_involutive z]
exact star_mem_nonZeroDivisors h
theorem norm_mem_nonZeroDivisors_iff {z : QuadraticAlgebra R a b} :
z.norm ∈ R⁰ ↔ z ∈ (QuadraticAlgebra R a b)⁰ := by
constructor
· simp only [mem_nonZeroDivisors_iff_right]
intro h w hw
have : norm z • w = 0 := by
rw [← coe_mul_eq_smul, coe_norm_eq_mul_star, mul_comm, ← mul_assoc, hw, zero_mul]
simp only [QuadraticAlgebra.ext_iff, re_smul, smul_eq_mul, mul_comm, re_zero, im_smul,
im_zero] at this
ext <;> simp [h _ this.left, h _ this.right]
· intro hz
rw [← coe_mem_nonZeroDivisors_iff, coe_norm_eq_mul_star]
exact Submonoid.mul_mem _ hz (star_mem_nonZeroDivisors hz)
end norm
section field
variable [Field R] [Hab : Fact (∀ r, r ^ 2 ≠ a + b * r)]
lemma norm_eq_zero_iff_eq_zero {z : QuadraticAlgebra R a b} :
norm z = 0 ↔ z = 0 := by
constructor
· intro hz
rw [norm_def] at hz
by_cases h : z.im = 0
· simp [h] at hz
aesop
· exfalso
rw [← pow_two, sub_eq_zero, ← eq_sub_iff_add_eq] at hz
apply Hab.out (- z.re / z.im)
grind
· intro hz
simp [hz]
/-- If `R` is a field and there is no `r : R` such that `r ^ 2 = a + b * r`,
then `QuadraticAlgebra R a b` is a field. -/
instance : Field (QuadraticAlgebra R a b) where
inv z := (norm z)⁻¹ • star z
mul_inv_cancel z hz := by
rw [ne_eq, ← norm_eq_zero_iff_eq_zero] at hz
simp only [Algebra.mul_smul_comm]
rw [← coe_mul_eq_smul, ← coe_norm_eq_mul_star, ← coe_mul, coe_eq_one_iff]
exact inv_mul_cancel₀ hz
inv_zero := by simp
nnqsmul := _
nnqsmul_def := fun _ _ => rfl
qsmul := _
qsmul_def := fun _ _ => rfl
end field
end QuadraticAlgebra |
.lake/packages/mathlib/Mathlib/Algebra/QuadraticAlgebra/Defs.lean | import Mathlib.LinearAlgebra.Dimension.StrongRankCondition
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
/-!
# Quadratic Algebra
In this file we define the quadratic algebra `QuadraticAlgebra R a b` over a commutative ring `R`,
and define some algebraic structures on it.
## Main definitions
* `QuadraticAlgebra R a b`:
[Bourbaki, *Algebra I*][bourbaki1989] with coefficients `a`, `b` in `R`.
## Tags
Quadratic algebra, quadratic extension
-/
universe u
/-- Quadratic algebra over a type with fixed coefficient where $i^2 = a + bi$, implemented as
a structure with two fields, `re` and `im`. When `R` is a commutative ring, this is isomorphic to
`R[X]/(X^2-b*X-a)`. -/
@[ext]
structure QuadraticAlgebra (R : Type u) (a b : R) : Type u where
/-- Real part of an element in quadratic algebra -/
re : R
/-- Imaginary part of an element in quadratic algebra -/
im : R
deriving DecidableEq
initialize_simps_projections QuadraticAlgebra (as_prefix re, as_prefix im)
variable {R : Type*}
namespace QuadraticAlgebra
/-- The equivalence between quadratic algebra over `R` and `R × R`. -/
@[simps symm_apply]
def equivProd (a b : R) : QuadraticAlgebra R a b ≃ R × R where
toFun z := (z.re, z.im)
invFun p := ⟨p.1, p.2⟩
@[simp]
theorem mk_eta {a b} (z : QuadraticAlgebra R a b) :
mk z.re z.im = z := rfl
variable {S T : Type*} {a b} (r : R) (x y : QuadraticAlgebra R a b)
instance [Subsingleton R] : Subsingleton (QuadraticAlgebra R a b) := (equivProd a b).subsingleton
instance [Nontrivial R] : Nontrivial (QuadraticAlgebra R a b) := (equivProd a b).nontrivial
section Zero
variable [Zero R]
/-- Coercion `R → QuadraticAlgebra R a b`. -/
@[coe] def coe (x : R) : QuadraticAlgebra R a b := ⟨x, 0⟩
instance : Coe R (QuadraticAlgebra R a b) := ⟨coe⟩
@[simp, norm_cast]
theorem re_coe : (r : QuadraticAlgebra R a b).re = r := rfl
@[simp, norm_cast]
theorem im_coe : (r : QuadraticAlgebra R a b).im = 0 := rfl
theorem coe_injective : Function.Injective (coe : R → QuadraticAlgebra R a b) :=
fun _ _ h => congr_arg re h
@[simp]
theorem coe_inj {x y : R} : (x : QuadraticAlgebra R a b) = y ↔ x = y :=
coe_injective.eq_iff
instance : Zero (QuadraticAlgebra R a b) := ⟨⟨0, 0⟩⟩
@[simp] theorem re_zero : (0 : QuadraticAlgebra R a b).re = 0 := rfl
@[simp] theorem im_zero : (0 : QuadraticAlgebra R a b).im = 0 := rfl
@[simp, norm_cast]
theorem coe_zero : ((0 : R) : QuadraticAlgebra R a b) = 0 := rfl
@[simp]
theorem coe_eq_zero_iff {r : R} : (r : QuadraticAlgebra R a b) = 0 ↔ r = 0 := by
rw [← coe_zero, coe_inj]
instance : Inhabited (QuadraticAlgebra R a b) := ⟨0⟩
section One
variable [One R]
instance : One (QuadraticAlgebra R a b) := ⟨⟨1, 0⟩⟩
@[scoped simp] theorem re_one : (1 : QuadraticAlgebra R a b).re = 1 := rfl
@[scoped simp] theorem im_one : (1 : QuadraticAlgebra R a b).im = 0 := rfl
@[simp, norm_cast]
theorem coe_one : ((1 : R) : QuadraticAlgebra R a b) = 1 := rfl
@[simp]
theorem coe_eq_one_iff {r : R} : (r : QuadraticAlgebra R a b) = 1 ↔ r = 1 := by
rw [← coe_one, coe_inj]
end One
end Zero
section Add
variable [Add R]
instance : Add (QuadraticAlgebra R a b) where
add z w := ⟨z.re + w.re, z.im + w.im⟩
@[simp] theorem re_add (z w : QuadraticAlgebra R a b) :
(z + w).re = z.re + w.re := rfl
@[simp] theorem im_add (z w : QuadraticAlgebra R a b) :
(z + w).im = z.im + w.im := rfl
@[simp]
theorem mk_add_mk (z w : QuadraticAlgebra R a b) :
mk z.re z.im + mk w.re w.im = (mk (z.re + w.re) (z.im + w.im) : QuadraticAlgebra R a b) := rfl
end Add
section AddZeroClass
variable [AddZeroClass R]
@[simp]
theorem coe_add (x y : R) : ((x + y : R) : QuadraticAlgebra R a b) = x + y := by ext <;> simp
end AddZeroClass
section Neg
variable [Neg R]
instance : Neg (QuadraticAlgebra R a b) where neg z := ⟨-z.re, -z.im⟩
@[simp] theorem re_neg (z : QuadraticAlgebra R a b) : (-z).re = -z.re := rfl
@[simp] theorem im_neg (z : QuadraticAlgebra R a b) : (-z).im = -z.im := rfl
@[simp]
theorem neg_mk (x y : R) :
- (mk x y : QuadraticAlgebra R a b) = ⟨-x, -y⟩ := rfl
end Neg
section AddGroup
@[simp]
theorem coe_neg [NegZeroClass R] (x : R) :
((-x : R) : QuadraticAlgebra R a b) = -x := by ext <;> simp
instance [Sub R] : Sub (QuadraticAlgebra R a b) where
sub z w := ⟨z.re - w.re, z.im - w.im⟩
@[simp] theorem re_sub [Sub R] (z w : QuadraticAlgebra R a b) :
(z - w).re = z.re - w.re := rfl
@[simp] theorem im_sub [Sub R] (z w : QuadraticAlgebra R a b) :
(z - w).im = z.im - w.im := rfl
@[simp]
theorem mk_sub_mk [Sub R] (x1 y1 x2 y2 : R) :
(mk x1 y1 : QuadraticAlgebra R a b) - mk x2 y2 = mk (x1 - x2) (y1 - y2) := rfl
@[norm_cast, simp]
theorem coe_sub (r1 r2 : R) [SubNegZeroMonoid R] :
((r1 - r2 : R) : QuadraticAlgebra R a b) = r1 - r2 :=
QuadraticAlgebra.ext rfl zero_sub_zero.symm
end AddGroup
section Mul
variable [Mul R] [Add R]
instance : Mul (QuadraticAlgebra R a b) where
mul z w := ⟨z.1 * w.1 + a * z.2 * w.2, z.1 * w.2 + z.2 * w.1 + b * z.2 * w.2⟩
@[simp] theorem re_mul (z w : QuadraticAlgebra R a b) :
(z * w).re = z.re * w.re + a * z.im * w.im := rfl
@[simp] theorem im_mul (z w : QuadraticAlgebra R a b) :
(z * w).im = z.re * w.im + z.im * w.re + b * z.im * w.im := rfl
@[simp]
theorem mk_mul_mk (x1 y1 x2 y2 : R) :
(mk x1 y1 : QuadraticAlgebra R a b) * mk x2 y2 =
mk (x1 * x2 + a * y1 * y2) (x1 * y2 + y1 * x2 + b * y1 * y2) := rfl
end Mul
section SMul
variable [SMul S R] [SMul T R] (s : S)
instance : SMul S (QuadraticAlgebra R a b) where smul s z := ⟨s • z.re, s • z.im⟩
instance [SMul S T] [IsScalarTower S T R] : IsScalarTower S T (QuadraticAlgebra R a b) where
smul_assoc s t z := by ext <;> exact smul_assoc _ _ _
instance [SMulCommClass S T R] : SMulCommClass S T (QuadraticAlgebra R a b) where
smul_comm s t z := by ext <;> exact smul_comm _ _ _
instance [SMul Sᵐᵒᵖ R] [IsCentralScalar S R] : IsCentralScalar S (QuadraticAlgebra R a b) where
op_smul_eq_smul s z := by ext <;> exact op_smul_eq_smul _ _
@[simp] theorem re_smul (s : S) (z : QuadraticAlgebra R a b) : (s • z).re = s • z.re := rfl
@[simp] theorem im_smul (s : S) (z : QuadraticAlgebra R a b) : (s • z).im = s • z.im := rfl
@[simp]
theorem smul_mk (s : S) (x y : R) :
s • (mk x y : QuadraticAlgebra R a b) = mk (s • x) (s • y) := rfl
end SMul
section MulAction
instance [Monoid S] [MulAction S R] : MulAction S (QuadraticAlgebra R a b) where
one_smul _ := by ext <;> simp
mul_smul _ _ _ := by ext <;> simp [mul_smul]
end MulAction
@[simp, norm_cast]
theorem coe_smul [Zero R] [SMulZeroClass S R] (s : S) (r : R) :
(↑(s • r) : QuadraticAlgebra R a b) = s • (r : QuadraticAlgebra R a b) :=
QuadraticAlgebra.ext rfl (smul_zero _).symm
instance [AddMonoid R] : AddMonoid (QuadraticAlgebra R a b) := fast_instance% by
refine (equivProd a b).injective.addMonoid _ rfl ?_ ?_ <;> intros <;> rfl
instance [Monoid S] [AddMonoid R] [DistribMulAction S R] :
DistribMulAction S (QuadraticAlgebra R a b) where
smul_zero _ := by ext <;> simp
smul_add _ _ _ := by ext <;> simp
instance [AddCommMonoid R] : AddCommMonoid (QuadraticAlgebra R a b) := fast_instance% by
refine (equivProd a b).injective.addCommMonoid _ rfl ?_ ?_ <;> intros <;> rfl
instance [Semiring S] [AddCommMonoid R] [Module S R] : Module S (QuadraticAlgebra R a b) where
add_smul r s x := by ext <;> simp [add_smul]
zero_smul x := by ext <;> simp
instance [AddGroup R] : AddGroup (QuadraticAlgebra R a b) := fast_instance% by
refine (equivProd a b).injective.addGroup _ rfl ?_ ?_ ?_ ?_ ?_ <;> intros <;> rfl
instance [AddCommGroup R] : AddCommGroup (QuadraticAlgebra R a b) where
section AddCommMonoidWithOne
variable [AddCommMonoidWithOne R]
instance : AddCommMonoidWithOne (QuadraticAlgebra R a b) where
natCast n := ((n : R) : QuadraticAlgebra R a b)
natCast_zero := by ext <;> simp
natCast_succ n := by ext <;> simp
@[simp, norm_cast]
theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] :
((ofNat(n) : R) : QuadraticAlgebra R a b) = (ofNat(n) : QuadraticAlgebra R a b) := by
ext <;> rfl
@[simp, norm_cast]
theorem re_natCast (n : ℕ) : (n : QuadraticAlgebra R a b).re = n := rfl
@[simp, norm_cast]
theorem im_natCast (n : ℕ) : (n : QuadraticAlgebra R a b).im = 0 := rfl
@[norm_cast]
theorem coe_natCast (n : ℕ) : ↑(↑n : R) = (↑n : QuadraticAlgebra R a b) := rfl
@[scoped simp]
theorem re_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : QuadraticAlgebra R a b).re = ofNat(n) := rfl
@[scoped simp]
theorem im_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : QuadraticAlgebra R a b).im = 0 := rfl
end AddCommMonoidWithOne
section AddCommGroupWithOne
variable [AddCommGroupWithOne R]
instance : AddCommGroupWithOne (QuadraticAlgebra R a b) where
intCast n := ((n : R) : QuadraticAlgebra R a b)
intCast_ofNat n := by norm_cast
intCast_negSucc n := by rw [Int.negSucc_eq, Int.cast_neg, coe_neg]; norm_cast
@[simp, norm_cast]
theorem re_intCast (n : ℤ) : (n : QuadraticAlgebra R a b).re = n := rfl
@[simp, norm_cast]
theorem im_intCast (n : ℤ) : (n : QuadraticAlgebra R a b).im = 0 := rfl
@[norm_cast]
theorem coe_intCast (n : ℤ) : ↑(n : R) = (n : QuadraticAlgebra R a b) := rfl
end AddCommGroupWithOne
section NonUnitalNonAssocSemiring
variable [NonUnitalNonAssocSemiring R]
instance instNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (QuadraticAlgebra R a b) where
left_distrib _ _ _ := by ext <;> simpa using by simp [mul_add]; abel
right_distrib _ _ _ := by ext <;> simpa using by simp [mul_add, add_mul]; abel
zero_mul _ := by ext <;> simp
mul_zero _ := by ext <;> simp
theorem coe_mul_eq_smul (r : R) (x : QuadraticAlgebra R a b) :
(r * x : QuadraticAlgebra R a b) = r • x := by ext <;> simp
@[simp, norm_cast]
theorem coe_mul (x y : R) : ↑(x * y) = (↑x * ↑y : QuadraticAlgebra R a b) := by ext <;> simp
end NonUnitalNonAssocSemiring
section NonAssocSemiring
variable [NonAssocSemiring R]
instance instNonAssocSemiring : NonAssocSemiring (QuadraticAlgebra R a b) where
one_mul _ := by ext <;> simp
mul_one _ := by ext <;> simp
@[simp]
theorem nsmul_mk (n : ℕ) (x y : R) :
(n : QuadraticAlgebra R a b) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by
ext <;> simp
end NonAssocSemiring
section Semiring
variable (a b) [Semiring R]
/-- `QuadraticAlgebra.re` as a `LinearMap` -/
@[simps]
def reₗ : QuadraticAlgebra R a b →ₗ[R] R where
toFun := re
map_add' _ _ := rfl
map_smul' _ _ := rfl
/-- `QuadraticAlgebra.im` as a `LinearMap` -/
@[simps]
def imₗ : QuadraticAlgebra R a b →ₗ[R] R where
toFun := im
map_add' _ _ := rfl
map_smul' _ _ := rfl
/-- `QuadraticAlgebra.equivTuple` as a `LinearEquiv` -/
def linearEquivTuple : QuadraticAlgebra R a b ≃ₗ[R] (Fin 2 → R) where
__ := equivProd a b |>.trans <| finTwoArrowEquiv _ |>.symm
map_add' _ _ := funext <| Fin.forall_fin_two.2 ⟨rfl, rfl⟩
map_smul' _ _ := funext <| Fin.forall_fin_two.2 ⟨rfl, rfl⟩
@[simp]
lemma linearEquivTuple_apply (z : QuadraticAlgebra R a b) :
(linearEquivTuple a b) z = ![z.re, z.im] := rfl
@[simp]
lemma linearEquivTuple_symm_apply (x : Fin 2 → R) :
(linearEquivTuple a b).symm x = ⟨x 0, x 1⟩ := rfl
/-- `QuadraticAlgebra R a b` has a basis over `R` given by `1` and `i` -/
noncomputable def basis : Module.Basis (Fin 2) R (QuadraticAlgebra R a b) :=
.ofEquivFun <| linearEquivTuple a b
@[simp]
theorem basis_repr_apply (x : QuadraticAlgebra R a b) :
(basis a b).repr x = ![x.re, x.im] := rfl
instance : Module.Finite R (QuadraticAlgebra R a b) := .of_basis (basis a b)
instance : Module.Free R (QuadraticAlgebra R a b) := .of_basis (basis a b)
theorem rank_eq_two [StrongRankCondition R] : Module.rank R (QuadraticAlgebra R a b) = 2 := by
simp [rank_eq_card_basis (basis a b)]
theorem finrank_eq_two [StrongRankCondition R] :
Module.finrank R (QuadraticAlgebra R a b) = 2 := by
simp [Module.finrank, rank_eq_two]
end Semiring
section CommSemiring
variable [CommSemiring R]
instance instCommSemiring : CommSemiring (QuadraticAlgebra R a b) where
mul_assoc _ _ _ := by ext <;> simpa using by ring
mul_comm _ _ := by ext <;> simpa using by ring
instance [CommSemiring S] [CommSemiring R] [Algebra S R] :
Algebra S (QuadraticAlgebra R a b) where
algebraMap.toFun s := coe (algebraMap S R s)
algebraMap.map_one' := by ext <;> simp
algebraMap.map_mul' x y:= by ext <;> simp
algebraMap.map_zero' := by ext <;> simp
algebraMap.map_add' x y:= by ext <;> simp
commutes' s z := by ext <;> simp [Algebra.commutes]
smul_def' s x := by ext <;> simp [Algebra.smul_def]
theorem algebraMap_eq (r : R) : algebraMap R (QuadraticAlgebra R a b) r = ⟨r, 0⟩ := rfl
theorem algebraMap_injective : (algebraMap R (QuadraticAlgebra R a b) : _ → _).Injective :=
fun _ _ ↦ by simp [algebraMap_eq]
instance [Zero S] [SMulWithZero S R] [NoZeroSMulDivisors S R] :
NoZeroSMulDivisors S (QuadraticAlgebra R a b) :=
⟨by simp [QuadraticAlgebra.ext_iff, or_and_left]⟩
@[norm_cast, simp]
theorem coe_pow (n : ℕ) (r : R) : ((r ^ n : R) : QuadraticAlgebra R a b) =
(r : QuadraticAlgebra R a b) ^ n :=
(algebraMap R (QuadraticAlgebra R a b)).map_pow r n
theorem mul_coe_eq_smul (r : R) (x : QuadraticAlgebra R a b) :
(x * r : QuadraticAlgebra R a b) = r • x := by
rw [mul_comm, coe_mul_eq_smul r x]
@[norm_cast, simp]
theorem coe_algebraMap : ⇑(algebraMap R (QuadraticAlgebra R a b)) = coe := rfl
theorem smul_coe (r1 r2 : R) :
r1 • (r2 : QuadraticAlgebra R a b) = ↑(r1 * r2) := by rw [coe_mul, coe_mul_eq_smul]
theorem coe_dvd_iff {r : R} {z : QuadraticAlgebra R a b} :
(r : QuadraticAlgebra R a b) ∣ z ↔ r ∣ z.re ∧ r ∣ z.im := by
constructor
· rintro ⟨x, rfl⟩
simp [dvd_mul_right]
· rintro ⟨⟨r, hr⟩, ⟨i, hi⟩⟩
use ⟨r, i⟩
simp [QuadraticAlgebra.ext_iff, hr, hi]
@[simp, norm_cast]
theorem coe_dvd_iff_dvd {z w : R} :
(z : QuadraticAlgebra R a b) ∣ w ↔ z ∣ w := by
rw [coe_dvd_iff]
constructor
· rintro ⟨hx, -⟩
simpa using hx
· simp
end CommSemiring
section CommRing
variable [CommRing R]
instance instCommRing : CommRing (QuadraticAlgebra R a b) where
instance [CharZero R] : CharZero (QuadraticAlgebra R a b) where
cast_injective m n := by
simp [QuadraticAlgebra.ext_iff]
@[simp]
theorem zsmul_val (n : ℤ) (x y : R) :
(n : QuadraticAlgebra R a b) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by
ext <;> simp
end CommRing
end QuadraticAlgebra |
.lake/packages/mathlib/Mathlib/Algebra/Group/Idempotent.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Commute.Defs
import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Algebra.Group.Units.Defs
import Mathlib.Data.Subtype
import Mathlib.Tactic.Conv
/-!
# Idempotents
This file defines idempotents for an arbitrary multiplication and proves some basic results,
including:
* `IsIdempotentElem.mul_of_commute`: In a semigroup, the product of two commuting idempotents is
an idempotent;
* `IsIdempotentElem.pow_succ_eq`: In a monoid `a ^ (n+1) = a` for `a` an idempotent and `n` a
natural number.
## Tags
projection, idempotent
-/
assert_not_exists GroupWithZero
variable {M N S : Type*}
/-- An element `a` is said to be idempotent if `a * a = a`. -/
def IsIdempotentElem [Mul M] (a : M) : Prop := a * a = a
namespace IsIdempotentElem
section Mul
variable [Mul M] {a : M}
lemma of_isIdempotent [Std.IdempotentOp (α := M) (· * ·)] (a : M) : IsIdempotentElem a :=
Std.IdempotentOp.idempotent a
lemma eq (ha : IsIdempotentElem a) : a * a = a := ha
end Mul
section Semigroup
variable [Semigroup S] {a b : S}
lemma mul_of_commute (hab : Commute a b) (ha : IsIdempotentElem a) (hb : IsIdempotentElem b) :
IsIdempotentElem (a * b) := by rw [IsIdempotentElem, hab.symm.mul_mul_mul_comm, ha.eq, hb.eq]
end Semigroup
section CommSemigroup
variable [CommSemigroup S] {a b : S}
lemma mul (ha : IsIdempotentElem a) (hb : IsIdempotentElem b) : IsIdempotentElem (a * b) :=
ha.mul_of_commute (.all ..) hb
end CommSemigroup
section MulOneClass
variable [MulOneClass M] {a : M}
lemma one : IsIdempotentElem (1 : M) := mul_one _
instance : One {a : M // IsIdempotentElem a} where one := ⟨1, one⟩
@[simp, norm_cast] lemma coe_one : ↑(1 : {a : M // IsIdempotentElem a}) = (1 : M) := rfl
end MulOneClass
section Monoid
variable [Monoid M] {a : M}
lemma pow (n : ℕ) (h : IsIdempotentElem a) : IsIdempotentElem (a ^ n) :=
Nat.recOn n ((pow_zero a).symm ▸ one) fun n _ =>
show a ^ n.succ * a ^ n.succ = a ^ n.succ by
conv_rhs => rw [← h.eq]
rw [← sq, ← sq, ← pow_mul, ← pow_mul']
lemma pow_succ_eq (n : ℕ) (h : IsIdempotentElem a) : a ^ (n + 1) = a :=
Nat.recOn n ((Nat.zero_add 1).symm ▸ pow_one a) fun n ih => by rw [pow_succ, ih, h.eq]
theorem pow_eq (h : IsIdempotentElem a) {n : ℕ} (hn : n ≠ 0) : a ^ n = a := by
obtain ⟨i, rfl⟩ := Nat.exists_eq_add_one_of_ne_zero hn
exact h.pow_succ_eq _
theorem iff_eq_one_of_isUnit (h : IsUnit a) : IsIdempotentElem a ↔ a = 1 where
mp idem := by
have ⟨q, eq⟩ := h.exists_left_inv
rw [← eq, ← idem.eq, ← mul_assoc, eq, one_mul, idem.eq]
mpr := by rintro rfl; exact .one
end Monoid
section CancelMonoid
variable [CancelMonoid M] {a : M}
@[simp] lemma iff_eq_one : IsIdempotentElem a ↔ a = 1 := by simp [IsIdempotentElem]
end CancelMonoid
lemma map {M N F} [Mul M] [Mul N] [FunLike F M N] [MulHomClass F M N] {e : M}
(he : IsIdempotentElem e) (f : F) : IsIdempotentElem (f e) := by
rw [IsIdempotentElem, ← map_mul, he.eq]
lemma mul_mul_self {M : Type*} [Semigroup M] {x : M}
(hx : IsIdempotentElem x) (y : M) : y * x * x = y * x :=
mul_assoc y x x ▸ congrArg (y * ·) hx.eq
lemma mul_self_mul {M : Type*} [Semigroup M] {x : M}
(hx : IsIdempotentElem x) (y : M) : x * (x * y) = x * y :=
mul_assoc x x y ▸ congrArg (· * y) hx.eq
end IsIdempotentElem |
.lake/packages/mathlib/Mathlib/Algebra/Group/Opposite.lean | import Mathlib.Algebra.Group.Commute.Defs
import Mathlib.Algebra.Group.InjSurj
import Mathlib.Algebra.Group.Torsion
import Mathlib.Algebra.Opposites
/-!
# Group structures on the multiplicative and additive opposites
-/
assert_not_exists MonoidWithZero DenselyOrdered Units
variable {α : Type*}
namespace MulOpposite
/-!
### Additive structures on `αᵐᵒᵖ`
-/
instance instAddSemigroup [AddSemigroup α] : AddSemigroup αᵐᵒᵖ :=
unop_injective.addSemigroup _ fun _ _ => rfl
instance instAddLeftCancelSemigroup [AddLeftCancelSemigroup α] : AddLeftCancelSemigroup αᵐᵒᵖ :=
unop_injective.addLeftCancelSemigroup _ fun _ _ => rfl
instance instAddRightCancelSemigroup [AddRightCancelSemigroup α] : AddRightCancelSemigroup αᵐᵒᵖ :=
unop_injective.addRightCancelSemigroup _ fun _ _ => rfl
instance instAddCommMagma [AddCommMagma α] : AddCommMagma αᵐᵒᵖ :=
unop_injective.addCommMagma _ fun _ _ => rfl
instance instAddCommSemigroup [AddCommSemigroup α] : AddCommSemigroup αᵐᵒᵖ :=
unop_injective.addCommSemigroup _ fun _ _ => rfl
instance instAddZeroClass [AddZeroClass α] : AddZeroClass αᵐᵒᵖ :=
unop_injective.addZeroClass _ (by exact rfl) fun _ _ => rfl
instance instAddMonoid [AddMonoid α] : AddMonoid αᵐᵒᵖ :=
unop_injective.addMonoid _ (by exact rfl) (fun _ _ => rfl) fun _ _ => rfl
instance instAddCommMonoid [AddCommMonoid α] : AddCommMonoid αᵐᵒᵖ :=
unop_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl
instance instSubNegMonoid [SubNegMonoid α] : SubNegMonoid αᵐᵒᵖ :=
unop_injective.subNegMonoid _ (by exact rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
instance instAddGroup [AddGroup α] : AddGroup αᵐᵒᵖ :=
unop_injective.addGroup _ (by exact rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
instance instAddCommGroup [AddCommGroup α] : AddCommGroup αᵐᵒᵖ :=
unop_injective.addCommGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
/-!
### Multiplicative structures on `αᵐᵒᵖ`
We also generate additive structures on `αᵃᵒᵖ` using `to_additive`
-/
@[to_additive]
instance instIsRightCancelMul [Mul α] [IsLeftCancelMul α] : IsRightCancelMul αᵐᵒᵖ where
mul_right_cancel _ _ _ h := unop_injective <| mul_left_cancel <| op_injective h
@[to_additive]
instance instIsLeftCancelMul [Mul α] [IsRightCancelMul α] : IsLeftCancelMul αᵐᵒᵖ where
mul_left_cancel _ _ _ h := unop_injective <| mul_right_cancel <| op_injective h
@[to_additive] instance instIsCancelMul [Mul α] [IsCancelMul α] : IsCancelMul αᵐᵒᵖ where
@[to_additive]
instance instSemigroup [Semigroup α] : Semigroup αᵐᵒᵖ where
mul_assoc x y z := unop_injective <| Eq.symm <| mul_assoc (unop z) (unop y) (unop x)
@[to_additive]
instance instLeftCancelSemigroup [RightCancelSemigroup α] : LeftCancelSemigroup αᵐᵒᵖ where
mul_left_cancel _ _ _ := mul_left_cancel
@[to_additive]
instance instRightCancelSemigroup [LeftCancelSemigroup α] : RightCancelSemigroup αᵐᵒᵖ where
mul_right_cancel _ _ _ := mul_right_cancel
@[to_additive]
instance instCommSemigroup [CommSemigroup α] : CommSemigroup αᵐᵒᵖ where
mul_comm x y := unop_injective <| mul_comm (unop y) (unop x)
@[to_additive]
instance instMulOneClass [MulOneClass α] : MulOneClass αᵐᵒᵖ where
toMul := instMul
toOne := instOne
one_mul _ := unop_injective <| mul_one _
mul_one _ := unop_injective <| one_mul _
@[to_additive]
instance instMonoid [Monoid α] : Monoid αᵐᵒᵖ where
toSemigroup := instSemigroup
__ := instMulOneClass
npow n a := op <| a.unop ^ n
npow_zero _ := unop_injective <| pow_zero _
npow_succ _ _ := unop_injective <| pow_succ' _ _
@[to_additive]
instance instLeftCancelMonoid [RightCancelMonoid α] : LeftCancelMonoid αᵐᵒᵖ where
toMonoid := instMonoid
__ := instLeftCancelSemigroup
@[to_additive]
instance instRightCancelMonoid [LeftCancelMonoid α] : RightCancelMonoid αᵐᵒᵖ where
toMonoid := instMonoid
__ := instRightCancelSemigroup
@[to_additive]
instance instCancelMonoid [CancelMonoid α] : CancelMonoid αᵐᵒᵖ where
toLeftCancelMonoid := instLeftCancelMonoid
__ := instRightCancelMonoid
@[to_additive]
instance instCommMonoid [CommMonoid α] : CommMonoid αᵐᵒᵖ where
toMonoid := instMonoid
__ := instCommSemigroup
@[to_additive]
instance instCancelCommMonoid [CancelCommMonoid α] : CancelCommMonoid αᵐᵒᵖ where
toCommMonoid := instCommMonoid
__ := instLeftCancelMonoid
@[to_additive AddOpposite.instSubNegMonoid]
instance instDivInvMonoid [DivInvMonoid α] : DivInvMonoid αᵐᵒᵖ where
toMonoid := instMonoid
toInv := instInv
zpow n a := op <| a.unop ^ n
zpow_zero' _ := unop_injective <| zpow_zero _
zpow_succ' _ _ := unop_injective <| by
rw [unop_op, zpow_natCast, pow_succ', unop_mul, unop_op, zpow_natCast]
zpow_neg' _ _ := unop_injective <| DivInvMonoid.zpow_neg' _ _
@[to_additive]
instance instDivisionMonoid [DivisionMonoid α] : DivisionMonoid αᵐᵒᵖ where
toDivInvMonoid := instDivInvMonoid
__ := instInvolutiveInv
mul_inv_rev _ _ := unop_injective <| mul_inv_rev _ _
inv_eq_of_mul _ _ h := unop_injective <| inv_eq_of_mul_eq_one_left <| congr_arg unop h
@[to_additive AddOpposite.instSubtractionCommMonoid]
instance instDivisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid αᵐᵒᵖ where
toDivisionMonoid := instDivisionMonoid
__ := instCommSemigroup
@[to_additive]
instance instGroup [Group α] : Group αᵐᵒᵖ where
toDivInvMonoid := instDivInvMonoid
inv_mul_cancel _ := unop_injective <| mul_inv_cancel _
@[to_additive]
instance instCommGroup [CommGroup α] : CommGroup αᵐᵒᵖ where
toGroup := instGroup
__ := instCommSemigroup
section Monoid
variable [Monoid α]
@[simp] lemma op_pow (x : α) (n : ℕ) : op (x ^ n) = op x ^ n := rfl
@[simp] lemma unop_pow (x : αᵐᵒᵖ) (n : ℕ) : unop (x ^ n) = unop x ^ n := rfl
end Monoid
section DivInvMonoid
variable [DivInvMonoid α]
@[simp] lemma op_zpow (x : α) (z : ℤ) : op (x ^ z) = op x ^ z := rfl
@[simp] lemma unop_zpow (x : αᵐᵒᵖ) (z : ℤ) : unop (x ^ z) = unop x ^ z := rfl
end DivInvMonoid
@[to_additive (attr := simp)]
theorem unop_div [DivInvMonoid α] (x y : αᵐᵒᵖ) : unop (x / y) = (unop y)⁻¹ * unop x :=
rfl
@[to_additive (attr := simp)]
theorem op_div [DivInvMonoid α] (x y : α) : op (x / y) = (op y)⁻¹ * op x := by simp [div_eq_mul_inv]
@[to_additive (attr := simp)]
theorem semiconjBy_op [Mul α] {a x y : α} : SemiconjBy (op a) (op y) (op x) ↔ SemiconjBy a x y := by
simp only [SemiconjBy, ← op_mul, op_inj, eq_comm]
@[to_additive (attr := simp, nolint simpComm)]
theorem semiconjBy_unop [Mul α] {a x y : αᵐᵒᵖ} :
SemiconjBy (unop a) (unop y) (unop x) ↔ SemiconjBy a x y := by
conv_rhs => rw [← op_unop a, ← op_unop x, ← op_unop y, semiconjBy_op]
attribute [nolint simpComm] AddOpposite.addSemiconjBy_unop
@[to_additive]
theorem _root_.SemiconjBy.op [Mul α] {a x y : α} (h : SemiconjBy a x y) :
SemiconjBy (op a) (op y) (op x) :=
semiconjBy_op.2 h
@[to_additive]
theorem _root_.SemiconjBy.unop [Mul α] {a x y : αᵐᵒᵖ} (h : SemiconjBy a x y) :
SemiconjBy (unop a) (unop y) (unop x) :=
semiconjBy_unop.2 h
@[to_additive]
theorem _root_.Commute.op [Mul α] {x y : α} (h : Commute x y) : Commute (op x) (op y) :=
SemiconjBy.op h
@[to_additive]
nonrec theorem _root_.Commute.unop [Mul α] {x y : αᵐᵒᵖ} (h : Commute x y) :
Commute (unop x) (unop y) :=
h.unop
@[to_additive (attr := simp)]
theorem commute_op [Mul α] {x y : α} : Commute (op x) (op y) ↔ Commute x y :=
semiconjBy_op
@[to_additive (attr := simp, nolint simpComm)]
theorem commute_unop [Mul α] {x y : αᵐᵒᵖ} : Commute (unop x) (unop y) ↔ Commute x y :=
semiconjBy_unop
attribute [nolint simpComm] AddOpposite.addCommute_unop
end MulOpposite
/-!
### Multiplicative structures on `αᵃᵒᵖ`
-/
namespace AddOpposite
instance instSemigroup [Semigroup α] : Semigroup αᵃᵒᵖ := unop_injective.semigroup _ fun _ _ ↦ rfl
instance instLeftCancelSemigroup [LeftCancelSemigroup α] : LeftCancelSemigroup αᵃᵒᵖ :=
unop_injective.leftCancelSemigroup _ fun _ _ => rfl
instance instRightCancelSemigroup [RightCancelSemigroup α] : RightCancelSemigroup αᵃᵒᵖ :=
unop_injective.rightCancelSemigroup _ fun _ _ => rfl
instance instCommSemigroup [CommSemigroup α] : CommSemigroup αᵃᵒᵖ :=
unop_injective.commSemigroup _ fun _ _ => rfl
instance instMulOneClass [MulOneClass α] : MulOneClass αᵃᵒᵖ :=
unop_injective.mulOneClass _ (by exact rfl) fun _ _ => rfl
instance pow {β} [Pow α β] : Pow αᵃᵒᵖ β where pow a b := op (unop a ^ b)
@[simp]
theorem op_pow {β} [Pow α β] (a : α) (b : β) : op (a ^ b) = op a ^ b :=
rfl
@[simp]
theorem unop_pow {β} [Pow α β] (a : αᵃᵒᵖ) (b : β) : unop (a ^ b) = unop a ^ b :=
rfl
instance instMonoid [Monoid α] : Monoid αᵃᵒᵖ :=
unop_injective.monoid _ (by exact rfl) (fun _ _ => rfl) fun _ _ => rfl
instance instCommMonoid [CommMonoid α] : CommMonoid αᵃᵒᵖ :=
unop_injective.commMonoid _ (by exact rfl) (fun _ _ => rfl) fun _ _ => rfl
instance instDivInvMonoid [DivInvMonoid α] : DivInvMonoid αᵃᵒᵖ :=
unop_injective.divInvMonoid _ (by exact rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
instance instGroup [Group α] : Group αᵃᵒᵖ :=
unop_injective.group _ (by exact rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
instance instCommGroup [CommGroup α] : CommGroup αᵃᵒᵖ :=
unop_injective.commGroup _ (by exact rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
@[to_additive]
instance instMulTorsionFree [Monoid α] [IsMulTorsionFree α] : IsMulTorsionFree αᵐᵒᵖ :=
⟨fun _ h ↦ op_injective.comp <| (pow_left_injective h).comp <| unop_injective⟩
end AddOpposite |
.lake/packages/mathlib/Mathlib/Algebra/Group/Indicator.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Algebra.Notation.Indicator
/-!
# Indicator function
In this file, we prove basic results about the indicator of a set.
- `Set.indicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `0` otherwise.
- `Set.mulIndicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `1` otherwise.
## Implementation note
In mathematics, an indicator function or a characteristic function is a function
used to indicate membership of an element in a set `s`,
having the value `1` for all elements of `s` and the value `0` otherwise.
But since it is usually used to restrict a function to a certain set `s`,
we let the indicator function take the value `f x` for some function `f`, instead of `1`.
If the usual indicator function is needed, just set `f` to be the constant function `fun _ ↦ 1`.
The indicator function is implemented non-computably, to avoid having to pass around `Decidable`
arguments. This is in contrast with the design of `Pi.single` or `Set.piecewise`.
## Tags
indicator, characteristic
-/
assert_not_exists MonoidWithZero
open Function
variable {α β M N : Type*}
namespace Set
section Monoid
variable [MulOneClass M] {s t : Set α} {a : α}
@[to_additive]
theorem mulIndicator_union_mul_inter_apply (f : α → M) (s t : Set α) (a : α) :
mulIndicator (s ∪ t) f a * mulIndicator (s ∩ t) f a
= mulIndicator s f a * mulIndicator t f a := by
by_cases hs : a ∈ s <;> by_cases ht : a ∈ t <;> simp [*]
@[to_additive]
theorem mulIndicator_union_mul_inter (f : α → M) (s t : Set α) :
mulIndicator (s ∪ t) f * mulIndicator (s ∩ t) f = mulIndicator s f * mulIndicator t f :=
funext <| mulIndicator_union_mul_inter_apply f s t
@[to_additive]
theorem mulIndicator_union_of_notMem_inter (h : a ∉ s ∩ t) (f : α → M) :
mulIndicator (s ∪ t) f a = mulIndicator s f a * mulIndicator t f a := by
rw [← mulIndicator_union_mul_inter_apply f s t, mulIndicator_of_notMem h, mul_one]
@[deprecated (since := "2025-05-23")]
alias indicator_union_of_not_mem_inter := indicator_union_of_notMem_inter
@[to_additive existing, deprecated (since := "2025-05-23")]
alias mulIndicator_union_of_not_mem_inter := mulIndicator_union_of_notMem_inter
@[to_additive]
theorem mulIndicator_union_of_disjoint (h : Disjoint s t) (f : α → M) :
mulIndicator (s ∪ t) f = fun a => mulIndicator s f a * mulIndicator t f a :=
funext fun _ => mulIndicator_union_of_notMem_inter (fun ha => h.le_bot ha) _
open scoped symmDiff in
@[to_additive]
theorem mulIndicator_symmDiff (s t : Set α) (f : α → M) :
mulIndicator (s ∆ t) f = mulIndicator (s \ t) f * mulIndicator (t \ s) f :=
mulIndicator_union_of_disjoint (disjoint_sdiff_self_right.mono_left sdiff_le) _
@[to_additive]
theorem mulIndicator_mul (s : Set α) (f g : α → M) :
(mulIndicator s fun a => f a * g a) = fun a => mulIndicator s f a * mulIndicator s g a := by
funext
simp only [mulIndicator]
split_ifs
· rfl
rw [mul_one]
@[to_additive]
theorem mulIndicator_mul' (s : Set α) (f g : α → M) :
mulIndicator s (f * g) = mulIndicator s f * mulIndicator s g :=
mulIndicator_mul s f g
@[to_additive (attr := simp)]
theorem mulIndicator_compl_mul_self_apply (s : Set α) (f : α → M) (a : α) :
mulIndicator sᶜ f a * mulIndicator s f a = f a :=
by_cases (fun ha : a ∈ s => by simp [ha]) fun ha => by simp [ha]
@[to_additive (attr := simp)]
theorem mulIndicator_compl_mul_self (s : Set α) (f : α → M) :
mulIndicator sᶜ f * mulIndicator s f = f :=
funext <| mulIndicator_compl_mul_self_apply s f
@[to_additive (attr := simp)]
theorem mulIndicator_self_mul_compl_apply (s : Set α) (f : α → M) (a : α) :
mulIndicator s f a * mulIndicator sᶜ f a = f a :=
by_cases (fun ha : a ∈ s => by simp [ha]) fun ha => by simp [ha]
@[to_additive (attr := simp)]
theorem mulIndicator_self_mul_compl (s : Set α) (f : α → M) :
mulIndicator s f * mulIndicator sᶜ f = f :=
funext <| mulIndicator_self_mul_compl_apply s f
@[to_additive]
theorem mulIndicator_mul_eq_left {f g : α → M} (h : Disjoint (mulSupport f) (mulSupport g)) :
(mulSupport f).mulIndicator (f * g) = f := by
refine (mulIndicator_congr fun x hx => ?_).trans mulIndicator_mulSupport
have : g x = 1 := notMem_mulSupport.1 (disjoint_left.1 h hx)
rw [Pi.mul_apply, this, mul_one]
@[to_additive]
theorem mulIndicator_mul_eq_right {f g : α → M} (h : Disjoint (mulSupport f) (mulSupport g)) :
(mulSupport g).mulIndicator (f * g) = g := by
refine (mulIndicator_congr fun x hx => ?_).trans mulIndicator_mulSupport
have : f x = 1 := notMem_mulSupport.1 (disjoint_right.1 h hx)
rw [Pi.mul_apply, this, one_mul]
@[to_additive]
theorem mulIndicator_mul_compl_eq_piecewise [DecidablePred (· ∈ s)] (f g : α → M) :
s.mulIndicator f * sᶜ.mulIndicator g = s.piecewise f g := by
ext x
by_cases h : x ∈ s
· rw [piecewise_eq_of_mem _ _ _ h, Pi.mul_apply, Set.mulIndicator_of_mem h,
Set.mulIndicator_of_notMem (Set.notMem_compl_iff.2 h), mul_one]
· rw [piecewise_eq_of_notMem _ _ _ h, Pi.mul_apply, Set.mulIndicator_of_notMem h,
Set.mulIndicator_of_mem (Set.mem_compl h), one_mul]
/-- `Set.mulIndicator` as a `monoidHom`. -/
@[to_additive /-- `Set.indicator` as an `addMonoidHom`. -/]
noncomputable def mulIndicatorHom {α} (M) [MulOneClass M] (s : Set α) : (α → M) →* α → M where
toFun := mulIndicator s
map_one' := mulIndicator_one M s
map_mul' := mulIndicator_mul s
end Monoid
section Group
variable {G : Type*} [Group G] {s t : Set α}
@[to_additive]
theorem mulIndicator_inv' (s : Set α) (f : α → G) : mulIndicator s f⁻¹ = (mulIndicator s f)⁻¹ :=
(mulIndicatorHom G s).map_inv f
@[to_additive]
theorem mulIndicator_inv (s : Set α) (f : α → G) :
(mulIndicator s fun a => (f a)⁻¹) = fun a => (mulIndicator s f a)⁻¹ :=
mulIndicator_inv' s f
@[to_additive]
theorem mulIndicator_div (s : Set α) (f g : α → G) :
(mulIndicator s fun a => f a / g a) = fun a => mulIndicator s f a / mulIndicator s g a :=
(mulIndicatorHom G s).map_div f g
@[to_additive]
theorem mulIndicator_div' (s : Set α) (f g : α → G) :
mulIndicator s (f / g) = mulIndicator s f / mulIndicator s g :=
mulIndicator_div s f g
@[to_additive indicator_compl']
theorem mulIndicator_compl (s : Set α) (f : α → G) :
mulIndicator sᶜ f = f * (mulIndicator s f)⁻¹ :=
eq_mul_inv_of_mul_eq <| s.mulIndicator_compl_mul_self f
@[to_additive indicator_compl]
theorem mulIndicator_compl' (s : Set α) (f : α → G) :
mulIndicator sᶜ f = f / mulIndicator s f := by rw [div_eq_mul_inv, mulIndicator_compl]
@[to_additive indicator_diff']
theorem mulIndicator_diff (h : s ⊆ t) (f : α → G) :
mulIndicator (t \ s) f = mulIndicator t f * (mulIndicator s f)⁻¹ :=
eq_mul_inv_of_mul_eq <| by
rw [Pi.mul_def, ← mulIndicator_union_of_disjoint, diff_union_self,
union_eq_self_of_subset_right h]
exact disjoint_sdiff_self_left
@[to_additive indicator_diff]
theorem mulIndicator_diff' (h : s ⊆ t) (f : α → G) :
mulIndicator (t \ s) f = mulIndicator t f / mulIndicator s f := by
rw [mulIndicator_diff h, div_eq_mul_inv]
open scoped symmDiff in
@[to_additive]
theorem apply_mulIndicator_symmDiff {g : G → β} (hg : ∀ x, g x⁻¹ = g x)
(s t : Set α) (f : α → G) (x : α) :
g (mulIndicator (s ∆ t) f x) = g (mulIndicator s f x / mulIndicator t f x) := by
by_cases hs : x ∈ s <;> by_cases ht : x ∈ t <;> simp [mem_symmDiff, *]
end Group
end Set
@[to_additive]
theorem MonoidHom.map_mulIndicator {M N : Type*} [MulOneClass M] [MulOneClass N] (f : M →* N)
(s : Set α) (g : α → M) (x : α) : f (s.mulIndicator g x) = s.mulIndicator (f ∘ g) x := by
simp [Set.mulIndicator_comp_of_one] |
.lake/packages/mathlib/Mathlib/Algebra/Group/Support.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Notation.Support
/-!
# Support of a function
In this file we prove basic properties of `Function.support f = {x | f x ≠ 0}`, and similarly for
`Function.mulSupport f = {x | f x ≠ 1}`.
-/
assert_not_exists CompleteLattice MonoidWithZero
open Set
variable {α M G : Type*}
namespace Function
@[to_additive]
theorem mulSupport_mul [MulOneClass M] (f g : α → M) :
(mulSupport fun x ↦ f x * g x) ⊆ mulSupport f ∪ mulSupport g :=
mulSupport_binop_subset (· * ·) (one_mul _) f g
@[to_additive]
theorem mulSupport_pow [Monoid M] (f : α → M) (n : ℕ) :
(mulSupport fun x => f x ^ n) ⊆ mulSupport f := by
induction n with
| zero => simp [pow_zero]
| succ n hfn =>
simpa only [pow_succ'] using (mulSupport_mul f _).trans (union_subset Subset.rfl hfn)
section DivisionMonoid
variable [DivisionMonoid G] (f g : α → G)
@[to_additive (attr := simp)]
theorem mulSupport_fun_inv : (mulSupport fun x => (f x)⁻¹) = mulSupport f :=
ext fun _ => inv_ne_one
@[to_additive (attr := simp)]
theorem mulSupport_inv : mulSupport f⁻¹ = mulSupport f :=
mulSupport_fun_inv f
@[deprecated (since := "2025-07-31")] alias support_neg' := support_neg
@[deprecated (since := "2025-07-31")] alias mulSupport_inv' := mulSupport_inv
@[to_additive]
theorem mulSupport_mul_inv : (mulSupport fun x => f x * (g x)⁻¹) ⊆ mulSupport f ∪ mulSupport g :=
mulSupport_binop_subset (fun a b => a * b⁻¹) (by simp) f g
@[to_additive]
theorem mulSupport_div : (mulSupport fun x => f x / g x) ⊆ mulSupport f ∪ mulSupport g :=
mulSupport_binop_subset (· / ·) one_div_one f g
end DivisionMonoid
end Function |
.lake/packages/mathlib/Mathlib/Algebra/Group/TransferInstance.lean | import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Group.InjSurj
import Mathlib.Data.Fintype.Basic
/-!
# Transfer algebraic structures across `Equiv`s
In this file we prove lemmas of the following form: if `β` has a group structure and `α ≃ β`
then `α` has a group structure, and similarly for monoids, semigroups and so on.
### Implementation details
When adding new definitions that transfer type-classes across an equivalence, please use
`abbrev`. See note [reducible non-instances].
-/
assert_not_exists MonoidWithZero MulAction
namespace Equiv
variable {M α β : Type*} (e : α ≃ β)
/-- Transfer `One` across an `Equiv` -/
@[to_additive /-- Transfer `Zero` across an `Equiv` -/]
protected abbrev one [One β] : One α where one := e.symm 1
@[to_additive]
lemma one_def [One β] :
letI := e.one
1 = e.symm 1 := rfl
/-- Transfer `Mul` across an `Equiv` -/
@[to_additive /-- Transfer `Add` across an `Equiv` -/]
protected abbrev mul [Mul β] : Mul α where mul x y := e.symm (e x * e y)
@[to_additive]
lemma mul_def [Mul β] (x y : α) :
letI := Equiv.mul e
x * y = e.symm (e x * e y) := rfl
/-- Transfer `Div` across an `Equiv` -/
@[to_additive /-- Transfer `Sub` across an `Equiv` -/]
protected abbrev div [Div β] : Div α :=
⟨fun x y => e.symm (e x / e y)⟩
@[to_additive]
lemma div_def [Div β] (x y : α) :
letI := Equiv.div e
x / y = e.symm (e x / e y) := rfl
-- Porting note: this should be called `inv`,
-- but we already have an `Equiv.inv` (which perhaps should move to `Perm.inv`?)
/-- Transfer `Inv` across an `Equiv` -/
@[to_additive /-- Transfer `Neg` across an `Equiv` -/]
protected abbrev Inv [Inv β] : Inv α where inv x := e.symm (e x)⁻¹
@[to_additive]
lemma inv_def [Inv β] (x : α) :
letI := e.Inv
x⁻¹ = e.symm (e x)⁻¹ := rfl
variable (M) in
/-- Transfer `SMul` across an `Equiv` -/
@[to_additive /-- Transfer `VAdd` across an `Equiv` -/]
protected abbrev smul [SMul M β] : SMul M α where smul r x := e.symm (r • e x)
@[to_additive]
lemma smul_def [SMul M β] (r : M) (x : α) :
letI := e.smul M
r • x = e.symm (r • e x) := rfl
variable (M) in
/-- Transfer `Pow` across an `Equiv` -/
@[to_additive existing smul]
protected abbrev pow [Pow β M] : Pow α M where pow x n := e.symm (e x ^ n)
@[to_additive existing smul_def]
lemma pow_def [Pow β M] (n : M) (x : α) :
letI := e.pow M
x ^ n = e.symm (e x ^ n) := rfl
/-- An equivalence `e : α ≃ β` gives a multiplicative equivalence `α ≃* β` where
the multiplicative structure on `α` is the one obtained by transporting a multiplicative structure
on `β` back along `e`. -/
@[to_additive /-- An equivalence `e : α ≃ β` gives an additive equivalence `α ≃+ β` where
the additive structure on `α` is the one obtained by transporting an additive structure
on `β` back along `e`. -/]
def mulEquiv (e : α ≃ β) [Mul β] :
let _ := Equiv.mul e
α ≃* β := by
intros
exact
{ e with
map_mul' := fun x y => by
simp [mul_def] }
@[to_additive (attr := simp)]
lemma mulEquiv_apply (e : α ≃ β) [Mul β] (a : α) : (mulEquiv e) a = e a := rfl
@[to_additive]
lemma mulEquiv_symm_apply (e : α ≃ β) [Mul β] (b : β) :
letI := Equiv.mul e
(mulEquiv e).symm b = e.symm b := rfl
/-- Transfer `Semigroup` across an `Equiv` -/
@[to_additive /-- Transfer `add_semigroup` across an `Equiv` -/]
protected abbrev semigroup [Semigroup β] : Semigroup α := by
let mul := e.mul
apply e.injective.semigroup _; intros; exact e.apply_symm_apply _
/-- Transfer `CommSemigroup` across an `Equiv` -/
@[to_additive /-- Transfer `AddCommSemigroup` across an `Equiv` -/]
protected abbrev commSemigroup [CommSemigroup β] : CommSemigroup α := by
let mul := e.mul
apply e.injective.commSemigroup _; intros; exact e.apply_symm_apply _
/-- Transfer `IsLeftCancelMul` across an `Equiv` -/
@[to_additive /-- Transfer `IsLeftCancelAdd` across an `Equiv` -/]
protected lemma isLeftCancelMul [Mul β] [IsLeftCancelMul β] :
letI := e.mul
IsLeftCancelMul α := by
letI := e.mul; exact e.injective.isLeftCancelMul _ fun _ _ ↦ e.apply_symm_apply _
/-- Transfer `IsRightCancelMul` across an `Equiv` -/
@[to_additive /-- Transfer `IsRightCancelAdd` across an `Equiv` -/]
protected lemma isRightCancelMul [Mul β] [IsRightCancelMul β] :
letI := e.mul
IsRightCancelMul α := by
letI := e.mul; exact e.injective.isRightCancelMul _ fun _ _ ↦ e.apply_symm_apply _
/-- Transfer `IsCancelMul` across an `Equiv` -/
@[to_additive /-- Transfer `IsCancelAdd` across an `Equiv` -/]
protected lemma isCancelMul [Mul β] [IsCancelMul β] :
letI := e.mul
IsCancelMul α := by
letI := e.mul; exact e.injective.isCancelMul _ fun _ _ ↦ e.apply_symm_apply _
/-- Transfer `MulOneClass` across an `Equiv` -/
@[to_additive /-- Transfer `AddZeroClass` across an `Equiv` -/]
protected abbrev mulOneClass [MulOneClass β] : MulOneClass α := by
let one := e.one
let mul := e.mul
apply e.injective.mulOneClass _ <;> intros <;> exact e.apply_symm_apply _
/-- Transfer `Monoid` across an `Equiv` -/
@[to_additive /-- Transfer `AddMonoid` across an `Equiv` -/]
protected abbrev monoid [Monoid β] : Monoid α := by
let one := e.one
let mul := e.mul
let pow := e.pow ℕ
apply e.injective.monoid _ <;> intros <;> exact e.apply_symm_apply _
/-- Transfer `CommMonoid` across an `Equiv` -/
@[to_additive /-- Transfer `AddCommMonoid` across an `Equiv` -/]
protected abbrev commMonoid [CommMonoid β] : CommMonoid α := by
let one := e.one
let mul := e.mul
let pow := e.pow ℕ
apply e.injective.commMonoid _ <;> intros <;> exact e.apply_symm_apply _
/-- Transfer `Group` across an `Equiv` -/
@[to_additive /-- Transfer `AddGroup` across an `Equiv` -/]
protected abbrev group [Group β] : Group α := by
let one := e.one
let mul := e.mul
let inv := e.Inv
let div := e.div
let npow := e.pow ℕ
let zpow := e.pow ℤ
apply e.injective.group _ <;> intros <;> exact e.apply_symm_apply _
/-- Transfer `CommGroup` across an `Equiv` -/
@[to_additive /-- Transfer `AddCommGroup` across an `Equiv` -/]
protected abbrev commGroup [CommGroup β] : CommGroup α := by
let one := e.one
let mul := e.mul
let inv := e.Inv
let div := e.div
let npow := e.pow ℕ
let zpow := e.pow ℤ
apply e.injective.commGroup _ <;> intros <;> exact e.apply_symm_apply _
end Equiv
namespace Finite
/-- Any finite group in universe `u` is equivalent to some finite group in universe `v`. -/
@[to_additive
/-- Any finite group in universe `u` is equivalent to some finite group in universe `v`. -/]
lemma exists_type_univ_nonempty_mulEquiv.{u, v} (G : Type u) [Group G] [Finite G] :
∃ (G' : Type v) (_ : Group G') (_ : Fintype G'), Nonempty (G ≃* G') := by
obtain ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin G
let f : Fin n ≃ ULift (Fin n) := Equiv.ulift.symm
let e : G ≃ ULift (Fin n) := e.trans f
letI groupH : Group (ULift (Fin n)) := e.symm.group
exact ⟨ULift (Fin n), groupH, inferInstance, ⟨MulEquiv.symm <| e.symm.mulEquiv⟩⟩
end Finite |
.lake/packages/mathlib/Mathlib/Algebra/Group/PUnit.lean | import Mathlib.Algebra.Group.Defs
/-!
# `PUnit` is a commutative group
This file collects facts about algebraic structures on the one-element type, e.g. that it is a
commutative ring.
-/
assert_not_exists MonoidWithZero
namespace PUnit
@[to_additive]
instance commGroup : CommGroup PUnit where
mul _ _ := unit
one := unit
inv _ := unit
div _ _ := unit
npow _ _ := unit
zpow _ _ := unit
mul_assoc _ _ _ := rfl
one_mul _ := rfl
mul_one _ := rfl
inv_mul_cancel _ := rfl
mul_comm _ _ := rfl
-- shortcut instances
@[to_additive] instance : One PUnit where one := unit
@[to_additive] instance : Mul PUnit where mul _ _ := unit
@[to_additive] instance : Div PUnit where div _ _ := unit
@[to_additive] instance : Inv PUnit where inv _ := unit
@[to_additive (attr := simp)] lemma one_eq : (1 : PUnit) = unit := rfl
-- note simp can prove this when the Boolean ring structure is introduced
@[to_additive] lemma mul_eq (x y : PUnit) : x * y = unit := rfl
@[to_additive (attr := simp)] lemma div_eq (x y : PUnit) : x / y = unit := rfl
@[to_additive (attr := simp)] lemma inv_eq (x : PUnit) : x⁻¹ = unit := rfl
end PUnit |
.lake/packages/mathlib/Mathlib/Algebra/Group/Graph.lean | import Mathlib.Algebra.Group.Subgroup.Ker
/-!
# Vertical line test for group homs
This file proves the vertical line test for monoid homomorphisms/isomorphisms.
Let `f : G → H × I` be a homomorphism to a product of monoids. Assume that `f` is surjective on the
first factor and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` at most
once. Then the image of `f` is the graph of some monoid homomorphism `f' : H → I`.
Furthermore, if `f` is also surjective on the second factor and its image intersects every
"horizontal line" `{(h, i) | h : H}` at most once, then `f'` is actually an isomorphism
`f' : H ≃ I`.
We also prove specialised versions when `f` is the inclusion of a subgroup of the direct product.
(The version for general homomorphisms can easily be reduced to this special case, but the
homomorphism version is more flexible in applications.)
-/
open Function Set
variable {G H I : Type*}
section Monoid
variable [Monoid G] [Monoid H] [Monoid I]
namespace MonoidHom
/-- The graph of a monoid homomorphism as a submonoid.
See also `MonoidHom.graph` for the graph as a subgroup. -/
@[to_additive
/-- The graph of a monoid homomorphism as a submonoid.
See also `AddMonoidHom.graph` for the graph as a subgroup. -/]
def mgraph (f : G →* H) : Submonoid (G × H) where
carrier := {x | f x.1 = x.2}
one_mem' := map_one f
mul_mem' {x y} := by simp +contextual
-- TODO: Can `to_additive` be smarter about `simps`?
attribute [simps! coe] mgraph
attribute [simps! coe] AddMonoidHom.mgraph
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] coe_mgraph
@[to_additive (attr := simp)]
lemma mem_mgraph {f : G →* H} {x : G × H} : x ∈ f.mgraph ↔ f x.1 = x.2 := .rfl
@[to_additive mgraph_eq_mrange_prod]
lemma mgraph_eq_mrange_prod (f : G →* H) : f.mgraph = mrange ((id _).prod f) := by aesop
/-- **Vertical line test** for monoid homomorphisms.
Let `f : G → H × I` be a homomorphism to a product of monoids. Assume that `f` is surjective on the
first factor and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` at most
once. Then the image of `f` is the graph of some monoid homomorphism `f' : H → I`. -/
@[to_additive /-- **Vertical line test** for monoid homomorphisms.
Let `f : G → H × I` be a homomorphism to a product of monoids. Assume that `f` is surjective on the
first factor and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` at most
once. Then the image of `f` is the graph of some monoid homomorphism `f' : H → I`. -/]
lemma exists_mrange_eq_mgraph {f : G →* H × I} (hf₁ : Surjective (Prod.fst ∘ f))
(hf : ∀ g₁ g₂, (f g₁).1 = (f g₂).1 → (f g₁).2 = (f g₂).2) :
∃ f' : H →* I, mrange f = f'.mgraph := by
obtain ⟨f', hf'⟩ := exists_range_eq_graphOn_univ hf₁ hf
simp only [Set.ext_iff, Set.mem_range, mem_graphOn, mem_univ, true_and, Prod.forall] at hf'
use
{ toFun := f'
map_one' := (hf' _ _).1 ⟨1, map_one _⟩
map_mul' := by
simp_rw [hf₁.forall]
rintro g₁ g₂
exact (hf' _ _).1 ⟨g₁ * g₂, by simp [Prod.ext_iff, (hf' (f _).1 _).1 ⟨_, rfl⟩]⟩ }
simpa [SetLike.ext_iff] using hf'
/-- **Line test** for monoid isomorphisms.
Let `f : G → H × I` be a homomorphism to a product of monoids. Assume that `f` is surjective on both
factors and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` and every
"horizontal line" `{(h, i) | h : H}` at most once. Then the image of `f` is the graph of some monoid
isomorphism `f' : H ≃ I`. -/
@[to_additive /-- **Line test** for monoid isomorphisms.
Let `f : G → H × I` be a homomorphism to a product of monoids. Assume that `f` is surjective on both
factors and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` and every
"horizontal line" `{(h, i) | h : H}` at most once. Then the image of `f` is the graph of some
monoid isomorphism `f' : H ≃ I`. -/]
lemma exists_mulEquiv_mrange_eq_mgraph {f : G →* H × I} (hf₁ : Surjective (Prod.fst ∘ f))
(hf₂ : Surjective (Prod.snd ∘ f)) (hf : ∀ g₁ g₂, (f g₁).1 = (f g₂).1 ↔ (f g₁).2 = (f g₂).2) :
∃ e : H ≃* I, mrange f = e.toMonoidHom.mgraph := by
obtain ⟨e₁, he₁⟩ := f.exists_mrange_eq_mgraph hf₁ fun _ _ ↦ (hf _ _).1
obtain ⟨e₂, he₂⟩ := (MulEquiv.prodComm.toMonoidHom.comp f).exists_mrange_eq_mgraph (by simpa) <|
by simp [hf]
have he₁₂ h i : e₁ h = i ↔ e₂ i = h := by
rw [SetLike.ext_iff] at he₁ he₂
aesop (add simp [Prod.swap_eq_iff_eq_swap])
exact ⟨
{ toFun := e₁
map_mul' := e₁.map_mul'
invFun := e₂
left_inv := fun h ↦ by rw [← he₁₂]
right_inv := fun i ↦ by rw [he₁₂] }, he₁⟩
end MonoidHom
/-- **Vertical line test** for monoid homomorphisms.
Let `G ≤ H × I` be a submonoid of a product of monoids. Assume that `G` maps bijectively to the
first factor. Then `G` is the graph of some monoid homomorphism `f : H → I`. -/
@[to_additive /-- **Vertical line test** for additive monoid homomorphisms.
Let `G ≤ H × I` be a submonoid of a product of monoids. Assume that `G` surjects onto the first
factor and `G` intersects every "vertical line" `{(h, i) | i : I}` at most once. Then `G` is the
graph of some monoid homomorphism `f : H → I`. -/]
lemma Submonoid.exists_eq_mgraph {G : Submonoid (H × I)} (hG₁ : Bijective (Prod.fst ∘ G.subtype)) :
∃ f : H →* I, G = f.mgraph := by
simpa using MonoidHom.exists_mrange_eq_mgraph hG₁.surjective
fun a b h ↦ congr_arg (Prod.snd ∘ G.subtype) (hG₁.injective h)
/-- **Goursat's lemma** for monoid isomorphisms.
Let `G ≤ H × I` be a submonoid of a product of monoids. Assume that the natural maps from `G` to
both factors are bijective. Then `G` is the graph of some isomorphism `f : H ≃* I`. -/
@[to_additive /-- **Goursat's lemma** for additive monoid isomorphisms.
Let `G ≤ H × I` be a submonoid of a product of additive monoids. Assume that the natural maps from
`G` to both factors are bijective. Then `G` is the graph of some isomorphism `f : H ≃+ I`. -/]
lemma Submonoid.exists_mulEquiv_eq_mgraph {G : Submonoid (H × I)}
(hG₁ : Bijective (Prod.fst ∘ G.subtype)) (hG₂ : Bijective (Prod.snd ∘ G.subtype)) :
∃ e : H ≃* I, G = e.toMonoidHom.mgraph := by
simpa using MonoidHom.exists_mulEquiv_mrange_eq_mgraph hG₁.surjective hG₂.surjective
fun _ _ ↦ hG₁.injective.eq_iff.trans hG₂.injective.eq_iff.symm
end Monoid
section Group
variable [Group G] [Group H] [Group I]
namespace MonoidHom
/-- The graph of a group homomorphism as a subgroup.
See also `MonoidHom.mgraph` for the graph as a submonoid. -/
@[to_additive
/-- The graph of a group homomorphism as a subgroup.
See also `AddMonoidHom.mgraph` for the graph as a submonoid. -/]
def graph (f : G →* H) : Subgroup (G × H) where
toSubmonoid := f.mgraph
inv_mem' {x} := by simp +contextual
-- TODO: Can `to_additive` be smarter about `simps`?
attribute [simps! coe toSubmonoid] graph
attribute [simps! coe toAddSubmonoid] AddMonoidHom.graph
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] coe_graph graph_toSubmonoid
@[to_additive]
lemma mem_graph {f : G →* H} {x : G × H} : x ∈ f.graph ↔ f x.1 = x.2 := .rfl
@[to_additive graph_eq_range_prod]
lemma graph_eq_range_prod (f : G →* H) : f.graph = range ((id _).prod f) := by aesop
/-- **Vertical line test** for group homomorphisms.
Let `f : G → H × I` be a homomorphism to a product of groups. Assume that `f` is surjective on the
first factor and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` at most
once. Then the image of `f` is the graph of some group homomorphism `f' : H → I`. -/
@[to_additive /-- **Vertical line test** for group homomorphisms.
Let `f : G → H × I` be a homomorphism to a product of groups. Assume that `f` is surjective on the
first factor and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` at most
once. Then the image of `f` is the graph of some group homomorphism `f' : H → I`. -/]
lemma exists_range_eq_graph {f : G →* H × I} (hf₁ : Surjective (Prod.fst ∘ f))
(hf : ∀ g₁ g₂, (f g₁).1 = (f g₂).1 → (f g₁).2 = (f g₂).2) :
∃ f' : H →* I, range f = f'.graph := by
simpa [SetLike.ext_iff] using exists_mrange_eq_mgraph hf₁ hf
/-- **Line test** for group isomorphisms.
Let `f : G → H × I` be a homomorphism to a product of groups. Assume that `f` is surjective on both
factors and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` and every
"horizontal line" `{(h, i) | h : H}` at most once. Then the image of `f` is the graph of some group
isomorphism `f' : H ≃ I`. -/
@[to_additive /-- **Line test** for monoid isomorphisms.
Let `f : G → H × I` be a homomorphism to a product of groups. Assume that `f` is surjective on both
factors and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` and every
"horizontal line" `{(h, i) | h : H}` at most once. Then the image of `f` is the graph of some
group isomorphism `f' : H ≃ I`. -/]
lemma exists_mulEquiv_range_eq_graph {f : G →* H × I} (hf₁ : Surjective (Prod.fst ∘ f))
(hf₂ : Surjective (Prod.snd ∘ f)) (hf : ∀ g₁ g₂, (f g₁).1 = (f g₂).1 ↔ (f g₁).2 = (f g₂).2) :
∃ e : H ≃* I, range f = e.toMonoidHom.graph := by
simpa [SetLike.ext_iff] using exists_mulEquiv_mrange_eq_mgraph hf₁ hf₂ hf
end MonoidHom
/-- **Vertical line test** for group homomorphisms.
Let `G ≤ H × I` be a subgroup of a product of monoids. Assume that `G` maps bijectively to the
first factor. Then `G` is the graph of some monoid homomorphism `f : H → I`. -/
@[to_additive /-- **Vertical line test** for additive monoid homomorphisms.
Let `G ≤ H × I` be a submonoid of a product of monoids. Assume that `G` surjects onto the first
factor and `G` intersects every "vertical line" `{(h, i) | i : I}` at most once. Then `G` is the
graph of some monoid homomorphism `f : H → I`. -/]
lemma Subgroup.exists_eq_graph {G : Subgroup (H × I)} (hG₁ : Bijective (Prod.fst ∘ G.subtype)) :
∃ f : H →* I, G = f.graph := by
simpa [SetLike.ext_iff] using Submonoid.exists_eq_mgraph hG₁
/-- **Goursat's lemma** for monoid isomorphisms.
Let `G ≤ H × I` be a submonoid of a product of monoids. Assume that the natural maps from `G` to
both factors are bijective. Then `G` is the graph of some isomorphism `f : H ≃* I`. -/
@[to_additive /-- **Goursat's lemma** for additive monoid isomorphisms.
Let `G ≤ H × I` be a submonoid of a product of additive monoids. Assume that the natural maps from
`G` to both factors are bijective. Then `G` is the graph of some isomorphism `f : H ≃+ I`. -/]
lemma Subgroup.exists_mulEquiv_eq_graph {G : Subgroup (H × I)}
(hG₁ : Bijective (Prod.fst ∘ G.subtype)) (hG₂ : Bijective (Prod.snd ∘ G.subtype)) :
∃ e : H ≃* I, G = e.toMonoidHom.graph := by
simpa [SetLike.ext_iff] using Submonoid.exists_mulEquiv_eq_mgraph hG₁ hG₂
end Group |
.lake/packages/mathlib/Mathlib/Algebra/Group/ConjFinite.lean | import Mathlib.Algebra.Group.Conj
import Mathlib.Data.Fintype.Units
/-!
# Conjugacy of elements of finite groups
-/
assert_not_exists Field
-- TODO: the following `assert_not_exists` should work, but does not
-- assert_not_exists MonoidWithZero
variable {α : Type*} [Monoid α]
attribute [local instance] IsConj.setoid
instance [Fintype α] [DecidableRel (IsConj : α → α → Prop)] : Fintype (ConjClasses α) :=
Quotient.fintype (IsConj.setoid α)
instance [Finite α] : Finite (ConjClasses α) :=
Quotient.finite _
instance [DecidableEq α] [Fintype α] : DecidableRel (IsConj : α → α → Prop) := fun a b =>
inferInstanceAs (Decidable (∃ c : αˣ, c.1 * a = b * c.1))
instance conjugatesOf.fintype [Fintype α] [DecidableRel (IsConj : α → α → Prop)] {a : α} :
Fintype (conjugatesOf a) :=
@Subtype.fintype _ _ (‹DecidableRel IsConj› a) _
namespace ConjClasses
variable [Fintype α] [DecidableRel (IsConj : α → α → Prop)]
instance {x : ConjClasses α} : Fintype (carrier x) :=
Quotient.recOnSubsingleton x fun _ => conjugatesOf.fintype
end ConjClasses |
.lake/packages/mathlib/Mathlib/Algebra/Group/Prod.lean | import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Group.Hom.Basic
import Mathlib.Algebra.Group.Opposite
import Mathlib.Algebra.Group.Torsion
import Mathlib.Algebra.Group.Units.Hom
import Mathlib.Algebra.Notation.Pi.Defs
import Mathlib.Algebra.Notation.Prod
import Mathlib.Logic.Equiv.Prod
import Mathlib.Tactic.TermCongr
/-!
# Monoid, group etc. structures on `M × N`
In this file we define one-binop (`Monoid`, `Group` etc) structures on `M × N`.
We also prove trivial `simp` lemmas, and define the following operations on `MonoidHom`s:
* `fst M N : M × N →* M`, `snd M N : M × N →* N`: projections `Prod.fst` and `Prod.snd`
as `MonoidHom`s;
* `inl M N : M →* M × N`, `inr M N : N →* M × N`: inclusions of first/second monoid
into the product;
* `f.prod g` : `M →* N × P`: sends `x` to `(f x, g x)`;
* When `P` is commutative, `f.coprod g : M × N →* P` sends `(x, y)` to `f x * g y`
(without the commutativity assumption on `P`, see `MonoidHom.noncommPiCoprod`);
* `f.prodMap g : M × N → M' × N'`: `Prod.map f g` as a `MonoidHom`,
sends `(x, y)` to `(f x, g y)`.
## Main declarations
* `mulMulHom`/`mulMonoidHom`: Multiplication bundled as a
multiplicative/monoid homomorphism.
* `divMonoidHom`: Division bundled as a monoid homomorphism.
-/
assert_not_exists MonoidWithZero DenselyOrdered AddMonoidWithOne
variable {G : Type*} {H : Type*} {M : Type*} {N : Type*} {P : Type*}
namespace Prod
@[to_additive]
theorem one_mk_mul_one_mk [MulOneClass M] [Mul N] (b₁ b₂ : N) :
((1 : M), b₁) * (1, b₂) = (1, b₁ * b₂) := by
rw [mk_mul_mk, mul_one]
@[to_additive]
theorem mk_one_mul_mk_one [Mul M] [MulOneClass N] (a₁ a₂ : M) :
(a₁, (1 : N)) * (a₂, 1) = (a₁ * a₂, 1) := by
rw [mk_mul_mk, mul_one]
@[to_additive]
theorem fst_mul_snd [MulOneClass M] [MulOneClass N] (p : M × N) : (p.fst, 1) * (1, p.snd) = p :=
Prod.ext (mul_one p.1) (one_mul p.2)
@[to_additive]
instance [InvolutiveInv M] [InvolutiveInv N] : InvolutiveInv (M × N) :=
{ inv_inv := fun _ => Prod.ext (inv_inv _) (inv_inv _) }
@[to_additive]
instance instSemigroup [Semigroup M] [Semigroup N] : Semigroup (M × N) where
mul_assoc _ _ _ := by ext <;> exact mul_assoc ..
@[to_additive]
instance instCommSemigroup [CommSemigroup G] [CommSemigroup H] : CommSemigroup (G × H) where
mul_comm _ _ := by ext <;> exact mul_comm ..
@[to_additive]
instance instMulOneClass [MulOneClass M] [MulOneClass N] : MulOneClass (M × N) where
one_mul _ := by ext <;> exact one_mul _
mul_one _ := by ext <;> exact mul_one _
@[to_additive]
instance instMonoid [Monoid M] [Monoid N] : Monoid (M × N) :=
{ npow := fun z a => ⟨Monoid.npow z a.1, Monoid.npow z a.2⟩,
npow_zero := fun _ => Prod.ext (Monoid.npow_zero _) (Monoid.npow_zero _),
npow_succ := fun _ _ => Prod.ext (Monoid.npow_succ _ _) (Monoid.npow_succ _ _),
one_mul := by simp,
mul_one := by simp }
@[to_additive]
instance instIsMulTorsionFree [Monoid M] [Monoid N] [IsMulTorsionFree M] [IsMulTorsionFree N] :
IsMulTorsionFree (M × N) where
pow_left_injective n hn a b hab := by
ext <;> apply pow_left_injective hn; exacts [congr(($hab).1), congr(($hab).2)]
@[to_additive Prod.subNegMonoid]
instance [DivInvMonoid G] [DivInvMonoid H] : DivInvMonoid (G × H) where
div_eq_mul_inv _ _ := by ext <;> exact div_eq_mul_inv ..
zpow z a := ⟨DivInvMonoid.zpow z a.1, DivInvMonoid.zpow z a.2⟩
zpow_zero' _ := by ext <;> exact DivInvMonoid.zpow_zero' _
zpow_succ' _ _ := by ext <;> exact DivInvMonoid.zpow_succ' ..
zpow_neg' _ _ := by ext <;> exact DivInvMonoid.zpow_neg' ..
@[to_additive]
instance [DivisionMonoid G] [DivisionMonoid H] : DivisionMonoid (G × H) :=
{ mul_inv_rev := fun _ _ => Prod.ext (mul_inv_rev _ _) (mul_inv_rev _ _),
inv_eq_of_mul := fun _ _ h =>
Prod.ext (inv_eq_of_mul_eq_one_right <| congr_arg fst h)
(inv_eq_of_mul_eq_one_right <| congr_arg snd h),
inv_inv := by simp }
@[to_additive SubtractionCommMonoid]
instance [DivisionCommMonoid G] [DivisionCommMonoid H] : DivisionCommMonoid (G × H) :=
{ mul_comm := fun ⟨g₁, h₁⟩ ⟨_, _⟩ => by rw [mk_mul_mk, mul_comm g₁, mul_comm h₁]; rfl }
@[to_additive]
instance instGroup [Group G] [Group H] : Group (G × H) where
inv_mul_cancel _ := by ext <;> exact inv_mul_cancel _
@[to_additive]
instance [Mul G] [Mul H] [IsLeftCancelMul G] [IsLeftCancelMul H] : IsLeftCancelMul (G × H) where
mul_left_cancel _ _ _ h :=
Prod.ext (mul_left_cancel (Prod.ext_iff.1 h).1) (mul_left_cancel (Prod.ext_iff.1 h).2)
@[to_additive]
instance [Mul G] [Mul H] [IsRightCancelMul G] [IsRightCancelMul H] : IsRightCancelMul (G × H) where
mul_right_cancel _ _ _ h :=
Prod.ext (mul_right_cancel (Prod.ext_iff.1 h).1) (mul_right_cancel (Prod.ext_iff.1 h).2)
@[to_additive]
instance [Mul G] [Mul H] [IsCancelMul G] [IsCancelMul H] : IsCancelMul (G × H) where
@[to_additive]
instance [LeftCancelSemigroup G] [LeftCancelSemigroup H] : LeftCancelSemigroup (G × H) :=
{ mul_left_cancel := fun _ _ _ => mul_left_cancel }
@[to_additive]
instance [RightCancelSemigroup G] [RightCancelSemigroup H] : RightCancelSemigroup (G × H) :=
{ mul_right_cancel := fun _ _ _ => mul_right_cancel }
@[to_additive]
instance [LeftCancelMonoid M] [LeftCancelMonoid N] : LeftCancelMonoid (M × N) :=
{ mul_one := by simp,
one_mul := by simp
mul_left_cancel _ _ := by simp }
@[to_additive]
instance [RightCancelMonoid M] [RightCancelMonoid N] : RightCancelMonoid (M × N) :=
{ mul_one := by simp,
one_mul := by simp
mul_right_cancel _ _ := by simp }
@[to_additive]
instance [CancelMonoid M] [CancelMonoid N] : CancelMonoid (M × N) :=
{ mul_right_cancel _ _ := by simp only [mul_left_inj, imp_self, forall_const] }
@[to_additive]
instance instCommMonoid [CommMonoid M] [CommMonoid N] : CommMonoid (M × N) :=
{ mul_comm := fun ⟨m₁, n₁⟩ ⟨_, _⟩ => by rw [mk_mul_mk, mk_mul_mk, mul_comm m₁, mul_comm n₁] }
@[to_additive]
instance [CancelCommMonoid M] [CancelCommMonoid N] : CancelCommMonoid (M × N) :=
{ mul_left_cancel _ _ := by simp }
@[to_additive]
instance instCommGroup [CommGroup G] [CommGroup H] : CommGroup (G × H) :=
{ mul_comm := fun ⟨g₁, h₁⟩ ⟨_, _⟩ => by rw [mk_mul_mk, mk_mul_mk, mul_comm g₁, mul_comm h₁] }
end Prod
section
variable [Mul M] [Mul N]
@[to_additive AddSemiconjBy.prod]
theorem SemiconjBy.prod {x y z : M × N}
(hm : SemiconjBy x.1 y.1 z.1) (hn : SemiconjBy x.2 y.2 z.2) : SemiconjBy x y z :=
Prod.ext hm hn
@[to_additive]
theorem Prod.semiconjBy_iff {x y z : M × N} :
SemiconjBy x y z ↔ SemiconjBy x.1 y.1 z.1 ∧ SemiconjBy x.2 y.2 z.2 := Prod.ext_iff
@[to_additive AddCommute.prod]
theorem Commute.prod {x y : M × N} (hm : Commute x.1 y.1) (hn : Commute x.2 y.2) : Commute x y :=
SemiconjBy.prod hm hn
@[to_additive]
theorem Prod.commute_iff {x y : M × N} :
Commute x y ↔ Commute x.1 y.1 ∧ Commute x.2 y.2 := semiconjBy_iff
end
namespace MulHom
section Prod
variable (M N) [Mul M] [Mul N] [Mul P]
/-- Given magmas `M`, `N`, the natural projection homomorphism from `M × N` to `M`. -/
@[to_additive
/-- Given additive magmas `A`, `B`, the natural projection homomorphism
from `A × B` to `A` -/]
def fst : M × N →ₙ* M :=
⟨Prod.fst, fun _ _ => rfl⟩
/-- Given magmas `M`, `N`, the natural projection homomorphism from `M × N` to `N`. -/
@[to_additive
/-- Given additive magmas `A`, `B`, the natural projection homomorphism
from `A × B` to `B` -/]
def snd : M × N →ₙ* N :=
⟨Prod.snd, fun _ _ => rfl⟩
variable {M N}
@[to_additive (attr := simp)]
theorem coe_fst : ⇑(fst M N) = Prod.fst :=
rfl
@[to_additive (attr := simp)]
theorem coe_snd : ⇑(snd M N) = Prod.snd :=
rfl
/-- Combine two `MonoidHom`s `f : M →ₙ* N`, `g : M →ₙ* P` into
`f.prod g : M →ₙ* (N × P)` given by `(f.prod g) x = (f x, g x)`. -/
@[to_additive prod
/-- Combine two `AddMonoidHom`s `f : AddHom M N`, `g : AddHom M P` into
`f.prod g : AddHom M (N × P)` given by `(f.prod g) x = (f x, g x)` -/]
protected def prod (f : M →ₙ* N) (g : M →ₙ* P) :
M →ₙ* N × P where
toFun := Pi.prod f g
map_mul' x y := Prod.ext (f.map_mul x y) (g.map_mul x y)
@[to_additive coe_prod]
theorem coe_prod (f : M →ₙ* N) (g : M →ₙ* P) : ⇑(f.prod g) = Pi.prod f g :=
rfl
@[to_additive (attr := simp) prod_apply]
theorem prod_apply (f : M →ₙ* N) (g : M →ₙ* P) (x) : f.prod g x = (f x, g x) :=
rfl
@[to_additive (attr := simp) fst_comp_prod]
theorem fst_comp_prod (f : M →ₙ* N) (g : M →ₙ* P) : (fst N P).comp (f.prod g) = f :=
ext fun _ => rfl
@[to_additive (attr := simp) snd_comp_prod]
theorem snd_comp_prod (f : M →ₙ* N) (g : M →ₙ* P) : (snd N P).comp (f.prod g) = g :=
ext fun _ => rfl
@[to_additive (attr := simp) prod_unique]
theorem prod_unique (f : M →ₙ* N × P) : ((fst N P).comp f).prod ((snd N P).comp f) = f :=
ext fun x => by simp only [prod_apply, coe_fst, coe_snd, comp_apply]
end Prod
section prodMap
variable {M' : Type*} {N' : Type*} [Mul M] [Mul N] [Mul M'] [Mul N'] [Mul P] (f : M →ₙ* M')
(g : N →ₙ* N')
/-- `Prod.map` as a `MonoidHom`. -/
@[to_additive prodMap /-- `Prod.map` as an `AddMonoidHom` -/]
def prodMap : M × N →ₙ* M' × N' :=
(f.comp (fst M N)).prod (g.comp (snd M N))
@[to_additive prodMap_def]
theorem prodMap_def : prodMap f g = (f.comp (fst M N)).prod (g.comp (snd M N)) :=
rfl
@[to_additive (attr := simp) coe_prodMap]
theorem coe_prodMap : ⇑(prodMap f g) = Prod.map f g :=
rfl
@[to_additive prod_comp_prodMap]
theorem prod_comp_prodMap (f : P →ₙ* M) (g : P →ₙ* N) (f' : M →ₙ* M') (g' : N →ₙ* N') :
(f'.prodMap g').comp (f.prod g) = (f'.comp f).prod (g'.comp g) :=
rfl
end prodMap
section Coprod
variable [Mul M] [Mul N] [CommSemigroup P] (f : M →ₙ* P) (g : N →ₙ* P)
/-- Coproduct of two `MulHom`s with the same codomain:
`f.coprod g (p : M × N) = f p.1 * g p.2`.
(Commutative codomain; for the general case, see `MulHom.noncommCoprod`) -/
@[to_additive
/-- Coproduct of two `AddHom`s with the same codomain:
`f.coprod g (p : M × N) = f p.1 + g p.2`.
(Commutative codomain; for the general case, see `AddHom.noncommCoprod`) -/]
def coprod : M × N →ₙ* P :=
f.comp (fst M N) * g.comp (snd M N)
@[to_additive (attr := simp)]
theorem coprod_apply (p : M × N) : f.coprod g p = f p.1 * g p.2 :=
rfl
@[to_additive]
theorem comp_coprod {Q : Type*} [CommSemigroup Q] (h : P →ₙ* Q) (f : M →ₙ* P) (g : N →ₙ* P) :
h.comp (f.coprod g) = (h.comp f).coprod (h.comp g) :=
ext fun x => by simp
end Coprod
end MulHom
namespace MonoidHom
variable (M N) [MulOneClass M] [MulOneClass N]
/-- Given monoids `M`, `N`, the natural projection homomorphism from `M × N` to `M`. -/
@[to_additive
/-- Given additive monoids `A`, `B`, the natural projection homomorphism
from `A × B` to `A` -/]
def fst : M × N →* M :=
{ toFun := Prod.fst,
map_one' := rfl,
map_mul' := fun _ _ => rfl }
/-- Given monoids `M`, `N`, the natural projection homomorphism from `M × N` to `N`. -/
@[to_additive
/-- Given additive monoids `A`, `B`, the natural projection homomorphism
from `A × B` to `B` -/]
def snd : M × N →* N :=
{ toFun := Prod.snd,
map_one' := rfl,
map_mul' := fun _ _ => rfl }
/-- Given monoids `M`, `N`, the natural inclusion homomorphism from `M` to `M × N`. -/
@[to_additive
/-- Given additive monoids `A`, `B`, the natural inclusion homomorphism
from `A` to `A × B`. -/]
def inl : M →* M × N :=
{ toFun := fun x => (x, 1),
map_one' := rfl,
map_mul' := fun _ _ => Prod.ext rfl (one_mul 1).symm }
/-- Given monoids `M`, `N`, the natural inclusion homomorphism from `N` to `M × N`. -/
@[to_additive
/-- Given additive monoids `A`, `B`, the natural inclusion homomorphism
from `B` to `A × B`. -/]
def inr : N →* M × N :=
{ toFun := fun y => (1, y),
map_one' := rfl,
map_mul' := fun _ _ => Prod.ext (one_mul 1).symm rfl }
variable {M N}
@[to_additive (attr := simp)]
theorem coe_fst : ⇑(fst M N) = Prod.fst :=
rfl
@[to_additive (attr := simp)]
theorem coe_snd : ⇑(snd M N) = Prod.snd :=
rfl
@[to_additive (attr := simp)]
theorem inl_apply (x) : inl M N x = (x, 1) :=
rfl
@[to_additive (attr := simp)]
theorem inr_apply (y) : inr M N y = (1, y) :=
rfl
@[to_additive (attr := simp)]
theorem fst_comp_inl : (fst M N).comp (inl M N) = id M :=
rfl
@[to_additive (attr := simp)]
theorem snd_comp_inl : (snd M N).comp (inl M N) = 1 :=
rfl
@[to_additive (attr := simp)]
theorem fst_comp_inr : (fst M N).comp (inr M N) = 1 :=
rfl
@[to_additive (attr := simp)]
theorem snd_comp_inr : (snd M N).comp (inr M N) = id N :=
rfl
@[to_additive]
theorem commute_inl_inr (m : M) (n : N) : Commute (inl M N m) (inr M N n) :=
Commute.prod (.one_right m) (.one_left n)
section Prod
variable [MulOneClass P]
/-- Combine two `MonoidHom`s `f : M →* N`, `g : M →* P` into `f.prod g : M →* N × P`
given by `(f.prod g) x = (f x, g x)`. -/
@[to_additive prod
/-- Combine two `AddMonoidHom`s `f : M →+ N`, `g : M →+ P` into
`f.prod g : M →+ N × P` given by `(f.prod g) x = (f x, g x)` -/]
protected def prod (f : M →* N) (g : M →* P) :
M →* N × P where
toFun := Pi.prod f g
map_one' := Prod.ext f.map_one g.map_one
map_mul' x y := Prod.ext (f.map_mul x y) (g.map_mul x y)
@[to_additive coe_prod]
theorem coe_prod (f : M →* N) (g : M →* P) : ⇑(f.prod g) = Pi.prod f g :=
rfl
@[to_additive (attr := simp) prod_apply]
theorem prod_apply (f : M →* N) (g : M →* P) (x) : f.prod g x = (f x, g x) :=
rfl
@[to_additive (attr := simp) fst_comp_prod]
theorem fst_comp_prod (f : M →* N) (g : M →* P) : (fst N P).comp (f.prod g) = f :=
ext fun _ => rfl
@[to_additive (attr := simp) snd_comp_prod]
theorem snd_comp_prod (f : M →* N) (g : M →* P) : (snd N P).comp (f.prod g) = g :=
ext fun _ => rfl
@[to_additive (attr := simp) prod_unique]
theorem prod_unique (f : M →* N × P) : ((fst N P).comp f).prod ((snd N P).comp f) = f :=
ext fun x => by simp only [prod_apply, coe_fst, coe_snd, comp_apply]
end Prod
section prodMap
variable {M' : Type*} {N' : Type*} [MulOneClass M'] [MulOneClass N'] [MulOneClass P]
(f : M →* M') (g : N →* N')
/-- `Prod.map` as a `MonoidHom`. -/
@[to_additive prodMap /-- `Prod.map` as an `AddMonoidHom`. -/]
def prodMap : M × N →* M' × N' :=
(f.comp (fst M N)).prod (g.comp (snd M N))
@[to_additive prodMap_def]
theorem prodMap_def : prodMap f g = (f.comp (fst M N)).prod (g.comp (snd M N)) :=
rfl
@[to_additive (attr := simp) coe_prodMap]
theorem coe_prodMap : ⇑(prodMap f g) = Prod.map f g :=
rfl
@[to_additive prod_comp_prodMap]
theorem prod_comp_prodMap (f : P →* M) (g : P →* N) (f' : M →* M') (g' : N →* N') :
(f'.prodMap g').comp (f.prod g) = (f'.comp f).prod (g'.comp g) :=
rfl
end prodMap
section Coprod
variable [CommMonoid P] (f : M →* P) (g : N →* P)
/-- Coproduct of two `MonoidHom`s with the same codomain:
`f.coprod g (p : M × N) = f p.1 * g p.2`.
(Commutative case; for the general case, see `MonoidHom.noncommCoprod`.) -/
@[to_additive
/-- Coproduct of two `AddMonoidHom`s with the same codomain:
`f.coprod g (p : M × N) = f p.1 + g p.2`.
(Commutative case; for the general case, see `AddHom.noncommCoprod`.) -/]
def coprod : M × N →* P :=
f.comp (fst M N) * g.comp (snd M N)
@[to_additive (attr := simp)]
theorem coprod_apply (p : M × N) : f.coprod g p = f p.1 * g p.2 :=
rfl
@[to_additive (attr := simp)]
theorem coprod_comp_inl : (f.coprod g).comp (inl M N) = f :=
ext fun x => by simp [coprod_apply]
@[to_additive (attr := simp)]
theorem coprod_comp_inr : (f.coprod g).comp (inr M N) = g :=
ext fun x => by simp [coprod_apply]
@[to_additive (attr := simp)]
theorem coprod_unique (f : M × N →* P) : (f.comp (inl M N)).coprod (f.comp (inr M N)) = f :=
ext fun x => by simp [coprod_apply, inl_apply, inr_apply, ← map_mul]
@[to_additive (attr := simp)]
theorem coprod_inl_inr {M N : Type*} [CommMonoid M] [CommMonoid N] :
(inl M N).coprod (inr M N) = id (M × N) :=
coprod_unique (id <| M × N)
@[to_additive]
theorem comp_coprod {Q : Type*} [CommMonoid Q] (h : P →* Q) (f : M →* P) (g : N →* P) :
h.comp (f.coprod g) = (h.comp f).coprod (h.comp g) :=
ext fun x => by simp
end Coprod
end MonoidHom
namespace MulEquiv
section
variable [MulOneClass M] [MulOneClass N]
/-- The equivalence between `M × N` and `N × M` given by swapping the components
is multiplicative. -/
@[to_additive prodComm
/-- The equivalence between `M × N` and `N × M` given by swapping the
components is additive. -/]
def prodComm : M × N ≃* N × M :=
{ Equiv.prodComm M N with map_mul' := fun ⟨_, _⟩ ⟨_, _⟩ => rfl }
@[to_additive (attr := simp) coe_prodComm]
theorem coe_prodComm : ⇑(prodComm : M × N ≃* N × M) = Prod.swap :=
rfl
@[to_additive (attr := simp) coe_prodComm_symm]
theorem coe_prodComm_symm : ⇑(prodComm : M × N ≃* N × M).symm = Prod.swap :=
rfl
variable [MulOneClass P]
/-- The equivalence between `(M × N) × P` and `M × (N × P)` is multiplicative. -/
@[to_additive prodAssoc
/-- The equivalence between `(M × N) × P` and `M × (N × P)` is additive. -/]
def prodAssoc : (M × N) × P ≃* M × (N × P) :=
{ Equiv.prodAssoc M N P with map_mul' := fun ⟨_, _⟩ ⟨_, _⟩ => rfl }
@[to_additive (attr := simp) coe_prodAssoc]
theorem coe_prodAssoc : ⇑(prodAssoc : (M × N) × P ≃* M × (N × P)) = Equiv.prodAssoc M N P :=
rfl
@[to_additive (attr := simp) coe_prodAssoc_symm]
theorem coe_prodAssoc_symm :
⇑(prodAssoc : (M × N) × P ≃* M × (N × P)).symm = (Equiv.prodAssoc M N P).symm :=
rfl
variable {M' : Type*} {N' : Type*} [MulOneClass N'] [MulOneClass M']
section
variable (M N M' N')
/-- Four-way commutativity of `Prod`. The name matches `mul_mul_mul_comm`. -/
@[to_additive (attr := simps apply) prodProdProdComm
/-- Four-way commutativity of `Prod`.
The name matches `mul_mul_mul_comm` -/]
def prodProdProdComm : (M × N) × M' × N' ≃* (M × M') × N × N' :=
{ Equiv.prodProdProdComm M N M' N' with
toFun := fun mnmn => ((mnmn.1.1, mnmn.2.1), (mnmn.1.2, mnmn.2.2))
invFun := fun mmnn => ((mmnn.1.1, mmnn.2.1), (mmnn.1.2, mmnn.2.2))
map_mul' := fun _mnmn _mnmn' => rfl }
@[to_additive (attr := simp) prodProdProdComm_toEquiv]
theorem prodProdProdComm_toEquiv :
(prodProdProdComm M N M' N' : _ ≃ _) = Equiv.prodProdProdComm M N M' N' :=
rfl
@[simp]
theorem prodProdProdComm_symm : (prodProdProdComm M N M' N').symm = prodProdProdComm M M' N N' :=
rfl
end
/-- Product of multiplicative isomorphisms; the maps come from `Equiv.prodCongr`. -/
@[to_additive prodCongr
/-- Product of additive isomorphisms; the maps come from `Equiv.prodCongr`. -/]
def prodCongr (f : M ≃* M') (g : N ≃* N') : M × N ≃* M' × N' :=
{ f.toEquiv.prodCongr g.toEquiv with
map_mul' := fun _ _ => Prod.ext (map_mul f _ _) (map_mul g _ _) }
/-- Multiplying by the trivial monoid doesn't change the structure.
This is the `MulEquiv` version of `Equiv.uniqueProd`. -/
@[to_additive uniqueProd /-- Multiplying by the trivial monoid doesn't change the structure.
This is the `AddEquiv` version of `Equiv.uniqueProd`. -/]
def uniqueProd [Unique N] : N × M ≃* M :=
{ Equiv.uniqueProd M N with map_mul' := fun _ _ => rfl }
/-- Multiplying by the trivial monoid doesn't change the structure.
This is the `MulEquiv` version of `Equiv.prodUnique`. -/
@[to_additive prodUnique /-- Multiplying by the trivial monoid doesn't change the structure.
This is the `AddEquiv` version of `Equiv.prodUnique`. -/]
def prodUnique [Unique N] : M × N ≃* M :=
{ Equiv.prodUnique M N with map_mul' := fun _ _ => rfl }
end
section
variable [Monoid M] [Monoid N]
/-- The monoid equivalence between units of a product of two monoids, and the product of the
units of each monoid. -/
@[to_additive prodAddUnits
/-- The additive monoid equivalence between additive units of a product
of two additive monoids, and the product of the additive units of each additive monoid. -/]
def prodUnits : (M × N)ˣ ≃* Mˣ × Nˣ where
toFun := (Units.map (MonoidHom.fst M N)).prod (Units.map (MonoidHom.snd M N))
invFun u := ⟨(u.1, u.2), (↑u.1⁻¹, ↑u.2⁻¹), by simp, by simp⟩
left_inv u := by
simp only [MonoidHom.prod_apply, Units.coe_map, MonoidHom.coe_fst, MonoidHom.coe_snd,
Prod.mk.eta, Units.coe_map_inv, Units.mk_val]
right_inv := fun ⟨u₁, u₂⟩ => by
simp only [Units.map, MonoidHom.coe_fst, Units.inv_eq_val_inv,
MonoidHom.coe_snd, MonoidHom.prod_apply, Prod.mk.injEq]
exact ⟨rfl, rfl⟩
map_mul' := MonoidHom.map_mul _
@[to_additive]
lemma _root_.Prod.isUnit_iff {x : M × N} : IsUnit x ↔ IsUnit x.1 ∧ IsUnit x.2 where
mp h := ⟨(prodUnits h.unit).1.isUnit, (prodUnits h.unit).2.isUnit⟩
mpr h := (prodUnits.symm (h.1.unit, h.2.unit)).isUnit
end
end MulEquiv
namespace Units
open MulOpposite
/-- Canonical homomorphism of monoids from `αˣ` into `α × αᵐᵒᵖ`.
Used mainly to define the natural topology of `αˣ`. -/
@[to_additive (attr := simps)
/-- Canonical homomorphism of additive monoids from `AddUnits α` into `α × αᵃᵒᵖ`.
Used mainly to define the natural topology of `AddUnits α`. -/]
def embedProduct (α : Type*) [Monoid α] : αˣ →* α × αᵐᵒᵖ where
toFun x := ⟨x, op ↑x⁻¹⟩
map_one' := by
simp only [inv_one, Units.val_one, op_one, Prod.mk_eq_one, and_self_iff]
map_mul' x y := by simp only [mul_inv_rev, op_mul, Units.val_mul, Prod.mk_mul_mk]
@[to_additive]
theorem embedProduct_injective (α : Type*) [Monoid α] : Function.Injective (embedProduct α) :=
fun _ _ h => Units.ext <| (congr_arg Prod.fst h :)
end Units
/-! ### Multiplication and division as homomorphisms -/
section BundledMulDiv
variable {α : Type*}
/-- Multiplication as a multiplicative homomorphism. -/
@[to_additive (attr := simps) /-- Addition as an additive homomorphism. -/]
def mulMulHom [CommSemigroup α] :
α × α →ₙ* α where
toFun a := a.1 * a.2
map_mul' _ _ := mul_mul_mul_comm _ _ _ _
/-- Multiplication as a monoid homomorphism. -/
@[to_additive (attr := simps) /-- Addition as an additive monoid homomorphism. -/]
def mulMonoidHom [CommMonoid α] : α × α →* α :=
{ mulMulHom with map_one' := mul_one _ }
/-- Division as a monoid homomorphism. -/
@[to_additive (attr := simps) /-- Subtraction as an additive monoid homomorphism. -/]
def divMonoidHom [DivisionCommMonoid α] : α × α →* α where
toFun a := a.1 / a.2
map_one' := div_one _
map_mul' _ _ := mul_div_mul_comm _ _ _ _
end BundledMulDiv |
.lake/packages/mathlib/Mathlib/Algebra/Group/Commutator.lean | import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Bracket
/-!
# The bracket on a group given by commutator.
-/
assert_not_exists MonoidWithZero DenselyOrdered
/-- The commutator of two elements `g₁` and `g₂`. -/
instance commutatorElement {G : Type*} [Group G] : Bracket G G :=
⟨fun g₁ g₂ ↦ g₁ * g₂ * g₁⁻¹ * g₂⁻¹⟩
theorem commutatorElement_def {G : Type*} [Group G] (g₁ g₂ : G) :
⁅g₁, g₂⁆ = g₁ * g₂ * g₁⁻¹ * g₂⁻¹ :=
rfl |
.lake/packages/mathlib/Mathlib/Algebra/Group/PNatPowAssoc.lean | import Mathlib.Data.PNat.Basic
import Mathlib.Algebra.Notation.Prod
/-!
# Typeclasses for power-associative structures
In this file we define power-associativity for algebraic structures with a multiplication operation.
The class is a Prop-valued mixin named `PNatPowAssoc`, where `PNat` means only strictly positive
powers are considered.
## Results
- `ppow_add` a defining property: `x ^ (k + n) = x ^ k * x ^ n`
- `ppow_one` a defining property: `x ^ 1 = x`
- `ppow_assoc` strictly positive powers of an element have associative multiplication.
- `ppow_comm` `x ^ m * x ^ n = x ^ n * x ^ m` for strictly positive `m` and `n`.
- `ppow_mul` `x ^ (m * n) = (x ^ m) ^ n` for strictly positive `m` and `n`.
- `ppow_eq_pow` monoid exponentiation coincides with semigroup exponentiation.
## Instances
- PNatPowAssoc for products and Pi types
## TODO
* `NatPowAssoc` for `MulOneClass` - more or less the same flow
* It seems unlikely that anyone will want `NatSMulAssoc` and `PNatSMulAssoc` as additive versions of
power-associativity, but we have found that it is not hard to write.
-/
-- TODO:
-- assert_not_exists MonoidWithZero
variable {M : Type*}
/-- A `Prop`-valued mixin for power-associative multiplication in the non-unital setting. -/
class PNatPowAssoc (M : Type*) [Mul M] [Pow M ℕ+] : Prop where
/-- Multiplication is power-associative. -/
protected ppow_add : ∀ (k n : ℕ+) (x : M), x ^ (k + n) = x ^ k * x ^ n
/-- Exponent one is identity. -/
protected ppow_one : ∀ (x : M), x ^ (1 : ℕ+) = x
section Mul
variable [Mul M] [Pow M ℕ+] [PNatPowAssoc M]
theorem ppow_add (k n : ℕ+) (x : M) : x ^ (k + n) = x ^ k * x ^ n :=
PNatPowAssoc.ppow_add k n x
@[simp]
theorem ppow_one (x : M) : x ^ (1 : ℕ+) = x :=
PNatPowAssoc.ppow_one x
theorem ppow_mul_assoc (k m n : ℕ+) (x : M) :
(x ^ k * x ^ m) * x ^ n = x ^ k * (x ^ m * x ^ n) := by
simp only [← ppow_add, add_assoc]
theorem ppow_mul_comm (m n : ℕ+) (x : M) :
x ^ m * x ^ n = x ^ n * x ^ m := by simp only [← ppow_add, add_comm]
theorem ppow_mul (x : M) (m n : ℕ+) : x ^ (m * n) = (x ^ m) ^ n := by
induction n with
| one => rw [ppow_one, mul_one]
| succ k hk => rw [ppow_add, ppow_one, mul_add, ppow_add, mul_one, hk]
theorem ppow_mul' (x : M) (m n : ℕ+) : x ^ (m * n) = (x ^ n) ^ m := by
rw [mul_comm]
exact ppow_mul x n m
end Mul
instance Pi.instPNatPowAssoc {ι : Type*} {α : ι → Type*} [∀ i, Mul <| α i] [∀ i, Pow (α i) ℕ+]
[∀ i, PNatPowAssoc <| α i] : PNatPowAssoc (∀ i, α i) where
ppow_add _ _ _ := by ext; simp [ppow_add]
ppow_one _ := by ext; simp
instance Prod.instPNatPowAssoc {N : Type*} [Mul M] [Pow M ℕ+] [PNatPowAssoc M] [Mul N] [Pow N ℕ+]
[PNatPowAssoc N] : PNatPowAssoc (M × N) where
ppow_add _ _ _ := by ext <;> simp [ppow_add]
ppow_one _ := by ext <;> simp
theorem ppow_eq_pow [Monoid M] [Pow M ℕ+] [PNatPowAssoc M] (x : M) (n : ℕ+) :
x ^ n = x ^ (n : ℕ) := by
induction n with
| one => rw [ppow_one, PNat.one_coe, pow_one]
| succ k hk => rw [ppow_add, ppow_one, PNat.add_coe, pow_add, PNat.one_coe, pow_one, ← hk] |
.lake/packages/mathlib/Mathlib/Algebra/Group/Center.lean | import Mathlib.Algebra.Group.Invertible.Basic
import Mathlib.Algebra.Notation.Prod
import Mathlib.Data.Set.Basic
/-!
# Centers of magmas and semigroups
## Main definitions
* `Set.center`: the center of a magma
* `Set.addCenter`: the center of an additive magma
* `Set.centralizer`: the centralizer of a subset of a magma
* `Set.addCentralizer`: the centralizer of a subset of an additive magma
## See also
See `Mathlib/GroupTheory/Subsemigroup/Center.lean` for the definition of the center as a
subsemigroup:
* `Subsemigroup.center`: the center of a semigroup
* `AddSubsemigroup.center`: the center of an additive semigroup
We provide `Submonoid.center`, `AddSubmonoid.center`, `Subgroup.center`, `AddSubgroup.center`,
`Subsemiring.center`, and `Subring.center` in other files.
See `Mathlib/GroupTheory/Subsemigroup/Centralizer.lean` for the definition of the centralizer
as a subsemigroup:
* `Subsemigroup.centralizer`: the centralizer of a subset of a semigroup
* `AddSubsemigroup.centralizer`: the centralizer of a subset of an additive semigroup
We provide `Monoid.centralizer`, `AddMonoid.centralizer`, `Subgroup.centralizer`, and
`AddSubgroup.centralizer` in other files.
-/
assert_not_exists HeytingAlgebra RelIso Finset MonoidWithZero Subsemigroup
variable {M : Type*} {S T : Set M}
/-- Conditions for an element to be additively central -/
structure IsAddCentral [Add M] (z : M) : Prop where
/-- addition commutes -/
comm (a : M) : AddCommute z a
/-- associative property for left addition -/
left_assoc (b c : M) : z + (b + c) = (z + b) + c
/-- associative property for right addition -/
right_assoc (a b : M) : (a + b) + z = a + (b + z)
/-- Conditions for an element to be multiplicatively central -/
@[to_additive]
structure IsMulCentral [Mul M] (z : M) : Prop where
/-- multiplication commutes -/
comm (a : M) : Commute z a
/-- associative property for left multiplication -/
left_assoc (b c : M) : z * (b * c) = (z * b) * c
/-- associative property for right multiplication -/
right_assoc (a b : M) : (a * b) * z = a * (b * z)
attribute [mk_iff] IsMulCentral IsAddCentral
attribute [to_additive existing] isMulCentral_iff
namespace IsMulCentral
variable {a c : M} [Mul M]
@[to_additive]
protected theorem mid_assoc {z : M} (h : IsMulCentral z) (a c) : a * z * c = a * (z * c) := by
rw [h.comm, ← h.right_assoc, ← h.comm, ← h.left_assoc, h.comm]
-- cf. `Commute.left_comm`
@[to_additive]
protected theorem left_comm (h : IsMulCentral a) (b c) : a * (b * c) = b * (a * c) := by
simp only [(h.comm _).eq, h.right_assoc]
-- cf. `Commute.right_comm`
@[to_additive]
protected theorem right_comm (h : IsMulCentral c) (a b) : a * b * c = a * c * b := by
simp only [h.right_assoc, h.mid_assoc, (h.comm _).eq]
end IsMulCentral
namespace Set
/-! ### Center -/
section Mul
variable [Mul M]
variable (M) in
/-- The center of a magma. -/
@[to_additive addCenter /-- The center of an additive magma. -/]
def center : Set M :=
{ z | IsMulCentral z }
variable (S) in
/-- The centralizer of a subset of a magma. -/
@[to_additive addCentralizer /-- The centralizer of a subset of an additive magma. -/]
def centralizer : Set M := {c | ∀ m ∈ S, m * c = c * m}
@[to_additive mem_addCenter_iff]
theorem mem_center_iff {z : M} : z ∈ center M ↔ IsMulCentral z :=
Iff.rfl
@[to_additive mem_addCentralizer]
lemma mem_centralizer_iff {c : M} : c ∈ centralizer S ↔ ∀ m ∈ S, m * c = c * m := Iff.rfl
@[to_additive (attr := simp) add_mem_addCenter]
theorem mul_mem_center {z₁ z₂ : M} (hz₁ : z₁ ∈ Set.center M) (hz₂ : z₂ ∈ Set.center M) :
z₁ * z₂ ∈ Set.center M where
comm a := calc
z₁ * z₂ * a = z₂ * z₁ * a := by rw [hz₁.comm]
_ = z₂ * (z₁ * a) := by rw [hz₁.mid_assoc z₂]
_ = (a * z₁) * z₂ := by rw [hz₁.comm, hz₂.comm]
_ = a * (z₁ * z₂) := by rw [hz₂.right_assoc a z₁]
left_assoc (b c : M) := calc
z₁ * z₂ * (b * c) = z₁ * (z₂ * (b * c)) := by rw [hz₂.mid_assoc]
_ = z₁ * ((z₂ * b) * c) := by rw [hz₂.left_assoc]
_ = (z₁ * (z₂ * b)) * c := by rw [hz₁.left_assoc]
_ = z₁ * z₂ * b * c := by rw [hz₂.mid_assoc]
right_assoc (a b : M) := calc
a * b * (z₁ * z₂) = ((a * b) * z₁) * z₂ := by rw [hz₂.right_assoc]
_ = (a * (b * z₁)) * z₂ := by rw [hz₁.right_assoc]
_ = a * ((b * z₁) * z₂) := by rw [hz₂.right_assoc]
_ = a * (b * (z₁ * z₂)) := by rw [hz₁.mid_assoc]
@[to_additive addCenter_subset_addCentralizer]
lemma center_subset_centralizer (S : Set M) : Set.center M ⊆ S.centralizer :=
fun _ hx m _ ↦ (hx.comm m).symm
@[to_additive addCentralizer_union]
lemma centralizer_union : centralizer (S ∪ T) = centralizer S ∩ centralizer T := by
simp [centralizer, or_imp, forall_and, setOf_and]
@[to_additive (attr := gcongr) addCentralizer_subset]
lemma centralizer_subset (h : S ⊆ T) : centralizer T ⊆ centralizer S := fun _ ht s hs ↦ ht s (h hs)
@[to_additive subset_addCentralizer_addCentralizer]
lemma subset_centralizer_centralizer : S ⊆ S.centralizer.centralizer := by
intro x hx
simp only [Set.mem_centralizer_iff]
exact fun y hy => (hy x hx).symm
@[to_additive (attr := simp) addCentralizer_addCentralizer_addCentralizer]
lemma centralizer_centralizer_centralizer (S : Set M) :
S.centralizer.centralizer.centralizer = S.centralizer := by
refine Set.Subset.antisymm ?_ Set.subset_centralizer_centralizer
intro x hx
rw [Set.mem_centralizer_iff]
intro y hy
rw [Set.mem_centralizer_iff] at hx
exact hx y <| Set.subset_centralizer_centralizer hy
@[to_additive decidableMemAddCentralizer]
instance decidableMemCentralizer [∀ a : M, Decidable <| ∀ b ∈ S, b * a = a * b] :
DecidablePred (· ∈ centralizer S) := fun _ ↦ decidable_of_iff' _ mem_centralizer_iff
@[to_additive addCentralizer_addCentralizer_comm_of_comm]
lemma centralizer_centralizer_comm_of_comm (h_comm : ∀ x ∈ S, ∀ y ∈ S, x * y = y * x) :
∀ x ∈ S.centralizer.centralizer, ∀ y ∈ S.centralizer.centralizer, x * y = y * x :=
fun _ h₁ _ h₂ ↦ h₂ _ fun _ h₃ ↦ h₁ _ fun _ h₄ ↦ h_comm _ h₄ _ h₃
@[to_additive addCentralizer_empty]
theorem centralizer_empty : (∅ : Set M).centralizer = ⊤ := by
simp only [centralizer, mem_empty_iff_false, IsEmpty.forall_iff, implies_true, setOf_true,
top_eq_univ]
/-- The centralizer of the product of non-empty sets is equal to the product of the centralizers. -/
@[to_additive addCentralizer_prod]
theorem centralizer_prod {N : Type*} [Mul N] {S : Set M} {T : Set N}
(hS : S.Nonempty) (hT : T.Nonempty) :
(S ×ˢ T).centralizer = S.centralizer ×ˢ T.centralizer := by
ext
simp_rw [mem_prod, mem_centralizer_iff, mem_prod, and_imp, Prod.forall,
Prod.mul_def, Prod.eq_iff_fst_eq_snd_eq]
obtain ⟨b, hb⟩ := hS
obtain ⟨c, hc⟩ := hT
exact ⟨fun h => ⟨fun y hy => (h y c hy hc).1, fun y hy => (h b y hb hy).2⟩,
fun h y z hy hz => ⟨h.1 _ hy, h.2 _ hz⟩⟩
@[to_additive prod_addCentralizer_subset_addCentralizer_prod]
theorem prod_centralizer_subset_centralizer_prod {N : Type*} [Mul N] (S : Set M) (T : Set N) :
S.centralizer ×ˢ T.centralizer ⊆ (S ×ˢ T).centralizer := by
rw [subset_def]
simp only [mem_prod, and_imp, Prod.forall, mem_centralizer_iff, Prod.mk_mul_mk, Prod.mk.injEq]
exact fun a b ha hb c d hc hd => ⟨ha c hc, hb d hd⟩
@[to_additive addCenter_prod]
theorem center_prod {N : Type*} [Mul N] :
center (M × N) = center M ×ˢ center N := by
ext x
simp only [mem_prod, mem_center_iff, isMulCentral_iff, commute_iff_eq, Prod.ext_iff]
exact ⟨
fun ⟨h1, h2, h3⟩ => ⟨
⟨ fun a => (h1 (a, x.2)).1,
fun b c => (h2 (b, x.2) (c, x.2)).1,
fun a b => (h3 (a, x.2) (b, x.2)).1⟩,
⟨ fun a => (h1 (x.1, a)).2,
fun a b => (h2 (x.1, a) (x.1, b)).2,
fun a b => (h3 (x.1, a) (x.1, b)).2⟩⟩,
fun ⟨⟨h1, h2, h3⟩, ⟨h4, h5, h6⟩⟩ => ⟨
fun _ => ⟨h1 _, h4 _⟩,
fun _ _ => ⟨h2 _ _, h5 _ _⟩,
fun _ _ => ⟨h3 _ _, h6 _ _⟩⟩⟩
open Function in
@[to_additive addCenter_pi]
theorem center_pi {ι : Type*} {A : ι → Type*} [Π i, Mul (A i)] :
center (Π i, A i) = univ.pi (fun i => center (A i)) := by
classical
ext x
simp only [mem_pi, mem_center_iff, isMulCentral_iff, mem_univ, forall_true_left,
commute_iff_eq, funext_iff, Pi.mul_def]
exact ⟨
fun ⟨h1, h2, h3⟩ i => ⟨
fun a => by simpa using h1 (update x i a) i,
fun b c => by simpa using h2 (update x i b) (update x i c) i,
fun a b => by simpa using h3 (update x i a) (update x i b) i⟩,
fun h => ⟨
fun a i => (h i).1 (a i),
fun b c i => (h i).2.1 (b i) (c i),
fun a b i => (h i).2.2 (a i) (b i)⟩⟩
end Mul
section Semigroup
variable [Semigroup M] {a b : M}
@[to_additive]
theorem _root_.Semigroup.mem_center_iff {z : M} :
z ∈ Set.center M ↔ ∀ g, g * z = z * g := ⟨fun a g ↦ by rw [IsMulCentral.comm a g],
fun h ↦ ⟨fun _ ↦ (h _).symm, fun _ _ ↦ (mul_assoc z _ _).symm, fun _ _ ↦ mul_assoc _ _ z⟩ ⟩
@[to_additive (attr := simp) add_mem_addCentralizer]
lemma mul_mem_centralizer (ha : a ∈ centralizer S) (hb : b ∈ centralizer S) :
a * b ∈ centralizer S := fun g hg ↦ by
rw [mul_assoc, ← hb g hg, ← mul_assoc, ha g hg, mul_assoc]
@[to_additive (attr := simp) addCentralizer_eq_top_iff_subset]
theorem centralizer_eq_top_iff_subset : centralizer S = Set.univ ↔ S ⊆ center M :=
eq_top_iff.trans <| ⟨
fun h _ hx ↦ Semigroup.mem_center_iff.mpr fun _ ↦ by rw [h trivial _ hx],
fun h _ _ _ hm ↦ (h hm).comm _⟩
variable (M) in
@[to_additive (attr := simp) addCentralizer_univ]
lemma centralizer_univ : centralizer univ = center M :=
Subset.antisymm (fun _ ha ↦ Semigroup.mem_center_iff.mpr fun b ↦ ha b (Set.mem_univ b))
fun _ ha b _ ↦ (ha.comm b).symm
-- TODO Add `instance : Decidable (IsMulCentral a)` for `instance decidableMemCenter [Mul M]`
@[to_additive decidableMemAddCenter]
instance decidableMemCenter [∀ a : M, Decidable <| ∀ b : M, b * a = a * b] :
DecidablePred (· ∈ center M) := fun _ => decidable_of_iff' _ (Semigroup.mem_center_iff)
end Semigroup
section CommSemigroup
variable [CommSemigroup M]
variable (M)
@[to_additive (attr := simp) addCenter_eq_univ]
theorem center_eq_univ : center M = univ :=
(Subset.antisymm (subset_univ _)) fun _ _ => Semigroup.mem_center_iff.mpr (fun _ => mul_comm _ _)
@[to_additive (attr := simp) addCentralizer_eq_univ]
lemma centralizer_eq_univ : centralizer S = univ :=
eq_univ_of_forall fun _ _ _ ↦ mul_comm _ _
end CommSemigroup
section MulOneClass
variable [MulOneClass M]
@[to_additive (attr := simp) zero_mem_addCenter]
theorem one_mem_center : (1 : M) ∈ Set.center M where
comm _ := by rw [commute_iff_eq, one_mul, mul_one]
left_assoc _ _ := by rw [one_mul, one_mul]
right_assoc _ _ := by rw [mul_one, mul_one]
@[to_additive (attr := simp) zero_mem_addCentralizer]
lemma one_mem_centralizer : (1 : M) ∈ centralizer S := by simp [mem_centralizer_iff]
end MulOneClass
section Monoid
variable [Monoid M]
@[to_additive subset_addCenter_add_units]
theorem subset_center_units : ((↑) : Mˣ → M) ⁻¹' center M ⊆ Set.center Mˣ :=
fun _ ha => by
rw [_root_.Semigroup.mem_center_iff]
intro _
rw [← Units.val_inj, Units.val_mul, Units.val_mul, ha.comm]
@[to_additive (attr := simp)]
theorem units_inv_mem_center {a : Mˣ} (ha : ↑a ∈ Set.center M) : ↑a⁻¹ ∈ Set.center M := by
rw [Semigroup.mem_center_iff] at *
exact (Commute.units_inv_right <| ha ·)
@[simp]
theorem invOf_mem_center {a : M} [Invertible a] (ha : a ∈ Set.center M) : ⅟a ∈ Set.center M := by
rw [Semigroup.mem_center_iff] at *
exact (Commute.invOf_right <| ha ·)
end Monoid
section DivisionMonoid
variable [DivisionMonoid M] {a b : M}
@[to_additive (attr := simp) neg_mem_addCenter]
theorem inv_mem_center (ha : a ∈ Set.center M) : a⁻¹ ∈ Set.center M := by
rw [_root_.Semigroup.mem_center_iff]
intro _
rw [← inv_inj, mul_inv_rev, inv_inv, ha.comm, mul_inv_rev, inv_inv]
@[to_additive (attr := simp) sub_mem_addCenter]
theorem div_mem_center (ha : a ∈ Set.center M) (hb : b ∈ Set.center M) : a / b ∈ Set.center M := by
rw [div_eq_mul_inv]
exact mul_mem_center ha (inv_mem_center hb)
end DivisionMonoid
section Group
variable [Group M] {a b : M}
@[to_additive (attr := simp) neg_mem_addCentralizer]
lemma inv_mem_centralizer (ha : a ∈ centralizer S) : a⁻¹ ∈ centralizer S :=
fun g hg ↦ by rw [mul_inv_eq_iff_eq_mul, mul_assoc, eq_inv_mul_iff_mul_eq, ha g hg]
@[to_additive (attr := simp) sub_mem_addCentralizer]
lemma div_mem_centralizer (ha : a ∈ centralizer S) (hb : b ∈ centralizer S) :
a / b ∈ centralizer S := by
simpa only [div_eq_mul_inv] using mul_mem_centralizer ha (inv_mem_centralizer hb)
end Group
end Set |
.lake/packages/mathlib/Mathlib/Algebra/Group/Basic.lean | import Aesop
import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Int.Init
import Mathlib.Logic.Function.Iterate
import Mathlib.Tactic.SimpRw
/-!
# Basic lemmas about semigroups, monoids, and groups
This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are
one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see
`Mathlib/Algebra/Group/Defs.lean`.
-/
assert_not_exists MonoidWithZero DenselyOrdered
open Function
variable {α β G M : Type*}
section ite
variable [Pow α β]
@[to_additive (attr := simp) dite_smul]
lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) :
a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl
@[to_additive (attr := simp) smul_dite]
lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) :
(if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl
@[to_additive (attr := simp) ite_smul]
lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) :
a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _
@[to_additive (attr := simp) smul_ite]
lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) :
(if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _
set_option linter.existingAttributeWarning false in
attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite
end ite
section Semigroup
variable [Semigroup α]
@[to_additive]
instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩
/-- Composing two multiplications on the left by `y` then `x`
is equal to a multiplication on the left by `x * y`.
-/
@[to_additive (attr := simp) /-- Composing two additions on the left by `y` then `x`
is equal to an addition on the left by `x + y`. -/]
theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by
ext z
simp [mul_assoc]
/-- Composing two multiplications on the right by `y` and `x`
is equal to a multiplication on the right by `y * x`.
-/
@[to_additive (attr := simp) /-- Composing two additions on the right by `y` and `x`
is equal to an addition on the right by `y + x`. -/]
theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by
ext z
simp [mul_assoc]
end Semigroup
@[to_additive]
instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩
section MulOneClass
variable [MulOneClass M]
@[to_additive]
instance Semigroup.to_isLawfulIdentity : Std.LawfulIdentity (α := M) (· * ·) 1 where
left_id := one_mul
right_id := mul_one
@[to_additive]
theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} :
ite P (a * b) 1 = ite P a 1 * ite P b 1 := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} :
ite P 1 (a * b) = ite P 1 a * ite P 1 b := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by
constructor <;> (rintro rfl; simpa using h)
@[to_additive]
theorem one_mul_eq_id : ((1 : M) * ·) = id :=
funext one_mul
@[to_additive]
theorem mul_one_eq_id : (· * (1 : M)) = id :=
funext mul_one
end MulOneClass
section CommSemigroup
variable [CommSemigroup G]
@[to_additive]
theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by
rw [← mul_assoc, mul_comm a, mul_assoc]
@[to_additive]
theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by
rw [mul_assoc, mul_comm b, mul_assoc]
@[to_additive]
theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by
simp only [mul_left_comm, mul_assoc]
@[to_additive]
theorem mul_mul_mul_comm' (a b c d : G) : a * b * c * d = a * c * b * d := by
grind
@[to_additive]
theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by
simp only [mul_left_comm, mul_comm]
@[to_additive]
theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by
simp only [mul_left_comm, mul_comm]
end CommSemigroup
attribute [local simp] mul_assoc sub_eq_add_neg
section Monoid
variable [Monoid M] {a b : M} {m n : ℕ}
@[to_additive boole_nsmul]
lemma pow_boole (P : Prop) [Decidable P] (a : M) :
(a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero]
@[to_additive nsmul_add_sub_nsmul]
lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by
rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h]
@[to_additive sub_nsmul_nsmul_add]
lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by
rw [← pow_add, Nat.sub_add_cancel h]
@[to_additive sub_one_nsmul_add]
lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by
rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
@[to_additive add_sub_one_nsmul]
lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by
rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
/-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/
@[to_additive nsmul_eq_mod_nsmul /-- If `n • x = 0`, then `m • x` is the same as `(m % n) • x` -/]
lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by
calc
a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div]
_ = a ^ (m % n) := by simp [pow_add, pow_mul, ha]
@[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1
| 0, _ => by simp
| n + 1, h =>
calc
a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ']
_ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc]
_ = 1 := by simp [h, pow_mul_pow_eq_one]
@[to_additive (attr := simp)]
lemma mul_left_iterate (a : M) : ∀ n : ℕ, (a * ·)^[n] = (a ^ n * ·)
| 0 => by ext; simp
| n + 1 => by simp [pow_succ, mul_left_iterate]
@[to_additive (attr := simp)]
lemma mul_right_iterate (a : M) : ∀ n : ℕ, (· * a)^[n] = (· * a ^ n)
| 0 => by ext; simp
| n + 1 => by simp [pow_succ', mul_right_iterate]
/-- Version of `mul_left_iterate` that is fully applied, for `rw`. -/
@[to_additive /-- Version of `add_left_iterate` that is fully applied, for `rw`. -/]
lemma mul_left_iterate_apply (a b : M) : (a * ·)^[n] b = a ^ n * b := by simp
/-- Version of `mul_right_iterate` that is fully applied, for `rw`. -/
@[to_additive /-- Version of `add_right_iterate` that is fully applied, for `rw`. -/ ]
lemma mul_right_iterate_apply (a b : M) : (· * a)^[n] b = b * a ^ n := by simp
@[to_additive]
lemma mul_left_iterate_apply_one (a : M) : (a * ·)^[n] 1 = a ^ n := by simp
@[to_additive]
lemma mul_right_iterate_apply_one (a : M) : (· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive (attr := simp)]
lemma pow_iterate (k : ℕ) : ∀ n : ℕ, (fun x : M ↦ x ^ k)^[n] = (· ^ k ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul]
end Monoid
section CommMonoid
variable [CommMonoid M] {x y z : M}
@[to_additive]
theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z :=
left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz
@[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n
| 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul]
| n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm]
end CommMonoid
section LeftCancelMonoid
variable [Monoid M] [IsLeftCancelMul M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_left : a * b = a ↔ b = 1 := calc
a * b = a ↔ a * b = a * 1 := by rw [mul_one]
_ ↔ b = 1 := mul_left_cancel_iff
@[to_additive (attr := simp)]
theorem left_eq_mul : a = a * b ↔ b = 1 :=
eq_comm.trans mul_eq_left
@[to_additive]
theorem mul_ne_left : a * b ≠ a ↔ b ≠ 1 := mul_eq_left.not
@[to_additive]
theorem left_ne_mul : a ≠ a * b ↔ b ≠ 1 := left_eq_mul.not
end LeftCancelMonoid
section RightCancelMonoid
variable [Monoid M] [IsRightCancelMul M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_right : a * b = b ↔ a = 1 := calc
a * b = b ↔ a * b = 1 * b := by rw [one_mul]
_ ↔ a = 1 := mul_right_cancel_iff
@[to_additive (attr := simp)]
theorem right_eq_mul : b = a * b ↔ a = 1 :=
eq_comm.trans mul_eq_right
@[to_additive]
theorem mul_ne_right : a * b ≠ b ↔ a ≠ 1 := mul_eq_right.not
@[to_additive]
theorem right_ne_mul : b ≠ a * b ↔ a ≠ 1 := right_eq_mul.not
end RightCancelMonoid
section CancelCommMonoid
variable [CancelCommMonoid α] {a b c d : α}
@[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop
@[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a ≠ c ↔ b ≠ d := by aesop
end CancelCommMonoid
section InvolutiveInv
variable [InvolutiveInv G] {a b : G}
@[to_additive (attr := simp)]
theorem inv_involutive : Function.Involutive (Inv.inv : G → G) :=
inv_inv
@[to_additive (attr := simp)]
theorem inv_surjective : Function.Surjective (Inv.inv : G → G) :=
inv_involutive.surjective
@[to_additive]
theorem inv_injective : Function.Injective (Inv.inv : G → G) :=
inv_involutive.injective
@[to_additive (attr := simp)]
theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b :=
inv_injective.eq_iff
@[to_additive]
theorem inv_eq_iff_eq_inv : a⁻¹ = b ↔ a = b⁻¹ :=
⟨fun h => h ▸ (inv_inv a).symm, fun h => h.symm ▸ inv_inv b⟩
variable (G)
@[to_additive]
theorem inv_comp_inv : Inv.inv ∘ Inv.inv = @id G :=
inv_involutive.comp_self
@[to_additive]
theorem leftInverse_inv : LeftInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ :=
inv_inv
@[to_additive]
theorem rightInverse_inv : RightInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ :=
inv_inv
end InvolutiveInv
section DivInvMonoid
variable [DivInvMonoid G]
@[to_additive]
theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by
rw [div_eq_mul_inv, one_mul, div_eq_mul_inv]
@[to_additive]
theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c :=
(mul_div_assoc _ _ _).symm
@[to_additive]
theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv]
@[to_additive]
theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div]
end DivInvMonoid
section DivInvOneMonoid
variable [DivInvOneMonoid G]
@[to_additive (attr := simp)]
theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv]
@[to_additive]
theorem one_div_one : (1 : G) / 1 = 1 :=
div_one _
end DivInvOneMonoid
section DivisionMonoid
variable [DivisionMonoid α] {a b c d : α}
attribute [local simp] mul_assoc div_eq_mul_inv
@[to_additive]
theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = a⁻¹ :=
(inv_eq_of_mul_eq_one_right h).symm
@[to_additive]
theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_left h, one_div]
@[to_additive]
theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_right h, one_div]
@[to_additive]
theorem eq_of_div_eq_one (h : a / b = 1) : a = b :=
inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [← div_eq_mul_inv]
@[to_additive]
lemma eq_of_inv_mul_eq_one (h : a⁻¹ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
lemma eq_of_mul_inv_eq_one (h : a * b⁻¹ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
theorem div_ne_one_of_ne : a ≠ b → a / b ≠ 1 :=
mt eq_of_div_eq_one
variable (a b c)
@[to_additive]
theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp
@[to_additive]
theorem inv_div_left : a⁻¹ / b = (b * a)⁻¹ := by simp
@[to_additive (attr := simp)]
theorem inv_div : (a / b)⁻¹ = b / a := by simp
@[to_additive]
theorem one_div_div : 1 / (a / b) = b / a := by simp
@[to_additive]
theorem one_div_one_div : 1 / (1 / a) = a := by simp
@[to_additive]
theorem div_eq_div_iff_comm : a / b = c / d ↔ b / a = d / c :=
inv_inj.symm.trans <| by simp only [inv_div]
@[to_additive]
instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid α :=
{ DivisionMonoid.toDivInvMonoid with
inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : α) 1).symm }
@[to_additive (attr := simp)]
lemma inv_pow (a : α) : ∀ n : ℕ, a⁻¹ ^ n = (a ^ n)⁻¹
| 0 => by rw [pow_zero, pow_zero, inv_one]
| n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev]
-- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`.
@[to_additive zsmul_zero, simp]
lemma one_zpow : ∀ n : ℤ, (1 : α) ^ n = 1
| (n : ℕ) => by rw [zpow_natCast, one_pow]
| .negSucc n => by rw [zpow_negSucc, one_pow, inv_one]
@[to_additive (attr := simp) neg_zsmul]
lemma zpow_neg (a : α) : ∀ n : ℤ, a ^ (-n) = (a ^ n)⁻¹
| (_ + 1 : ℕ) => DivInvMonoid.zpow_neg' _ _
| 0 => by simp
| Int.negSucc n => by
rw [zpow_negSucc, inv_inv, ← zpow_natCast]
rfl
@[to_additive neg_one_zsmul_add]
lemma mul_zpow_neg_one (a b : α) : (a * b) ^ (-1 : ℤ) = b ^ (-1 : ℤ) * a ^ (-1 : ℤ) := by
simp only [zpow_neg, zpow_one, mul_inv_rev]
@[to_additive zsmul_neg]
lemma inv_zpow (a : α) : ∀ n : ℤ, a⁻¹ ^ n = (a ^ n)⁻¹
| (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow]
| .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow]
@[to_additive (attr := simp) zsmul_neg']
lemma inv_zpow' (a : α) (n : ℤ) : a⁻¹ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg]
@[to_additive nsmul_zero_sub]
lemma one_div_pow (a : α) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow]
@[to_additive zsmul_zero_sub]
lemma one_div_zpow (a : α) (n : ℤ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow]
variable {a b c}
@[to_additive (attr := simp)]
theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 :=
inv_injective.eq_iff' inv_one
@[to_additive (attr := simp)]
theorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 :=
eq_comm.trans inv_eq_one
@[to_additive]
theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 :=
inv_eq_one.not
@[to_additive]
theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by
rw [← one_div_one_div a, h, one_div_one_div]
-- Note that `mul_zsmul` and `zpow_mul` have the primes swapped
-- when additivised since their argument order,
-- and therefore the more "natural" choice of lemma, is reversed.
@[to_additive mul_zsmul'] lemma zpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n
| (m : ℕ), (n : ℕ) => by
rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast]
rfl
| (m : ℕ), .negSucc n => by
rw [zpow_natCast, zpow_negSucc, ← pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj,
← zpow_natCast]
| .negSucc m, (n : ℕ) => by
rw [zpow_natCast, zpow_negSucc, ← inv_pow, ← pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow,
inv_inj, ← zpow_natCast]
| .negSucc m, .negSucc n => by
rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, ← pow_mul, ←
zpow_natCast]
rfl
@[to_additive mul_zsmul]
lemma zpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul]
@[to_additive]
theorem zpow_comm (a : α) (m n : ℤ) : (a ^ m) ^ n = (a ^ n) ^ m := by rw [← zpow_mul, zpow_mul']
variable (a b c)
@[to_additive]
theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp
@[to_additive (attr := simp)]
theorem div_inv_eq_mul : a / b⁻¹ = a * b := by simp
@[to_additive]
theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by
simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv]
end DivisionMonoid
section DivisionCommMonoid
variable [DivisionCommMonoid α] (a b c d : α)
attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv
@[to_additive neg_add]
theorem mul_inv : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by simp
@[to_additive]
theorem inv_div' : (a / b)⁻¹ = a⁻¹ / b⁻¹ := by simp
@[to_additive]
theorem div_eq_inv_mul : a / b = b⁻¹ * a := by simp
@[to_additive]
theorem inv_mul_eq_div : a⁻¹ * b = b / a := by simp
@[to_additive] lemma inv_div_comm (a b : α) : a⁻¹ / b = b⁻¹ / a := by simp
@[to_additive]
theorem inv_mul' : (a * b)⁻¹ = a⁻¹ / b := by simp
@[to_additive]
theorem inv_div_inv : a⁻¹ / b⁻¹ = b / a := by simp
@[to_additive]
theorem inv_inv_div_inv : (a⁻¹ / b⁻¹)⁻¹ = a / b := by simp
@[to_additive]
theorem one_div_mul_one_div : 1 / a * (1 / b) = 1 / (a * b) := by simp
@[to_additive]
theorem div_right_comm : a / b / c = a / c / b := by simp
@[to_additive]
theorem div_div : a / b / c = a / (b * c) := by simp
@[to_additive]
theorem div_mul : a / b * c = a / (b / c) := by simp
@[to_additive]
theorem mul_div_left_comm : a * (b / c) = b * (a / c) := by simp
@[to_additive]
theorem mul_div_right_comm : a * b / c = a / c * b := by simp
@[to_additive]
theorem div_mul_eq_div_div : a / (b * c) = a / b / c := by simp
@[to_additive]
theorem div_mul_eq_mul_div : a / b * c = a * c / b := by simp
@[to_additive]
theorem one_div_mul_eq_div : 1 / a * b = b / a := by simp
@[to_additive]
theorem mul_comm_div : a / b * c = a * (c / b) := by simp
@[to_additive]
theorem div_mul_comm : a / b * c = c / b * a := by simp
@[to_additive]
theorem div_mul_eq_div_mul_one_div : a / (b * c) = a / b * (1 / c) := by simp
@[to_additive]
theorem div_div_div_eq : a / b / (c / d) = a * d / (b * c) := by simp
@[to_additive]
theorem div_div_div_comm : a / b / (c / d) = a / c / (b / d) := by simp
@[to_additive]
theorem div_mul_div_comm : a / b * (c / d) = a * c / (b * d) := by simp
@[to_additive]
theorem mul_div_mul_comm : a * b / (c * d) = a / c * (b / d) := by simp
@[to_additive zsmul_add] lemma mul_zpow : ∀ n : ℤ, (a * b) ^ n = a ^ n * b ^ n
| (n : ℕ) => by simp_rw [zpow_natCast, mul_pow]
| .negSucc n => by simp_rw [zpow_negSucc, ← inv_pow, mul_inv, mul_pow]
@[to_additive nsmul_sub]
lemma div_pow (a b : α) (n : ℕ) : (a / b) ^ n = a ^ n / b ^ n := by
simp only [div_eq_mul_inv, mul_pow, inv_pow]
@[to_additive zsmul_sub]
lemma div_zpow (a b : α) (n : ℤ) : (a / b) ^ n = a ^ n / b ^ n := by
simp only [div_eq_mul_inv, mul_zpow, inv_zpow]
end DivisionCommMonoid
section Group
variable [Group G] {a b c d : G} {n : ℤ}
@[to_additive (attr := simp)]
theorem div_eq_inv_self : a / b = b⁻¹ ↔ a = 1 := by rw [div_eq_mul_inv, mul_eq_right]
@[to_additive]
theorem mul_left_surjective (a : G) : Surjective (a * ·) :=
fun x ↦ ⟨a⁻¹ * x, mul_inv_cancel_left a x⟩
@[to_additive]
theorem mul_right_surjective (a : G) : Function.Surjective fun x ↦ x * a := fun x ↦
⟨x * a⁻¹, inv_mul_cancel_right x a⟩
@[to_additive]
theorem eq_mul_inv_of_mul_eq (h : a * c = b) : a = b * c⁻¹ := by simp [h.symm]
@[to_additive]
theorem eq_inv_mul_of_mul_eq (h : b * a = c) : a = b⁻¹ * c := by simp [h.symm]
@[to_additive]
theorem inv_mul_eq_of_eq_mul (h : b = a * c) : a⁻¹ * b = c := by simp [h]
@[to_additive]
theorem mul_inv_eq_of_eq_mul (h : a = c * b) : a * b⁻¹ = c := by simp [h]
@[to_additive]
theorem eq_mul_of_mul_inv_eq (h : a * c⁻¹ = b) : a = b * c := by simp [h.symm]
@[to_additive]
theorem eq_mul_of_inv_mul_eq (h : b⁻¹ * a = c) : a = b * c := by simp [h.symm, mul_inv_cancel_left]
@[to_additive]
theorem mul_eq_of_eq_inv_mul (h : b = a⁻¹ * c) : a * b = c := by rw [h, mul_inv_cancel_left]
@[to_additive]
theorem mul_eq_of_eq_mul_inv (h : a = c * b⁻¹) : a * b = c := by simp [h]
@[to_additive]
theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ :=
⟨eq_inv_of_mul_eq_one_left, fun h ↦ by rw [h, inv_mul_cancel]⟩
@[to_additive]
theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b := by
rw [mul_eq_one_iff_eq_inv, inv_eq_iff_eq_inv]
/-- Variant of `mul_eq_one_iff_eq_inv` with swapped equality. -/
@[to_additive]
theorem mul_eq_one_iff_eq_inv' : a * b = 1 ↔ b = a⁻¹ := by
rw [mul_eq_one_iff_inv_eq, eq_comm]
/-- Variant of `mul_eq_one_iff_inv_eq` with swapped equality. -/
@[to_additive]
theorem mul_eq_one_iff_inv_eq' : a * b = 1 ↔ b⁻¹ = a := by
rw [mul_eq_one_iff_eq_inv, eq_comm]
@[to_additive]
theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 :=
mul_eq_one_iff_eq_inv.symm
@[to_additive]
theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 :=
mul_eq_one_iff_inv_eq.symm
@[to_additive]
theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b :=
⟨fun h ↦ by rw [h, inv_mul_cancel_right], fun h ↦ by rw [← h, mul_inv_cancel_right]⟩
@[to_additive]
theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c :=
⟨fun h ↦ by rw [h, mul_inv_cancel_left], fun h ↦ by rw [← h, inv_mul_cancel_left]⟩
@[to_additive]
theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c :=
⟨fun h ↦ by rw [← h, mul_inv_cancel_left], fun h ↦ by rw [h, inv_mul_cancel_left]⟩
@[to_additive]
theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b :=
⟨fun h ↦ by rw [← h, inv_mul_cancel_right], fun h ↦ by rw [h, mul_inv_cancel_right]⟩
@[to_additive]
theorem mul_inv_eq_one : a * b⁻¹ = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv]
@[to_additive]
theorem inv_mul_eq_one : a⁻¹ * b = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inj]
@[to_additive (attr := simp)]
theorem conj_eq_one_iff : a * b * a⁻¹ = 1 ↔ b = 1 := by
rw [mul_inv_eq_one, mul_eq_left]
@[to_additive]
theorem div_left_injective : Function.Injective fun a ↦ a / b := by
-- FIXME this could be by `simpa`, but it fails. This is probably a bug in `simpa`.
simp only [div_eq_mul_inv]
exact fun a a' h ↦ mul_left_injective b⁻¹ h
@[to_additive]
theorem div_right_injective : Function.Injective fun a ↦ b / a := by
-- FIXME see above
simp only [div_eq_mul_inv]
exact fun a a' h ↦ inv_injective (mul_right_injective b h)
@[to_additive (attr := simp)]
lemma div_mul_cancel_right (a b : G) : a / (b * a) = b⁻¹ := by rw [← inv_div, mul_div_cancel_right]
@[to_additive (attr := simp)]
theorem mul_div_mul_right_eq_div (a b c : G) : a * c / (b * c) = a / b := by
rw [div_mul_eq_div_div_swap]; simp only [mul_div_cancel_right]
@[to_additive eq_sub_of_add_eq]
theorem eq_div_of_mul_eq' (h : a * c = b) : a = b / c := by simp [← h]
@[to_additive sub_eq_of_eq_add]
theorem div_eq_of_eq_mul'' (h : a = c * b) : a / b = c := by simp [h]
@[to_additive]
theorem eq_mul_of_div_eq (h : a / c = b) : a = b * c := by simp [← h]
@[to_additive]
theorem mul_eq_of_eq_div (h : a = c / b) : a * b = c := by simp [h]
@[to_additive (attr := simp)]
theorem div_right_inj : a / b = a / c ↔ b = c :=
div_right_injective.eq_iff
@[to_additive (attr := simp)]
theorem div_left_inj : b / a = c / a ↔ b = c := by
rw [div_eq_mul_inv, div_eq_mul_inv]
exact mul_left_inj _
@[to_additive (attr := simp)]
theorem div_mul_div_cancel (a b c : G) : a / b * (b / c) = a / c := by
rw [← mul_div_assoc, div_mul_cancel]
@[to_additive (attr := simp)]
theorem div_div_div_cancel_right (a b c : G) : a / c / (b / c) = a / b := by
rw [← inv_div c b, div_inv_eq_mul, div_mul_div_cancel]
@[to_additive]
theorem div_eq_one : a / b = 1 ↔ a = b :=
⟨eq_of_div_eq_one, fun h ↦ by rw [h, div_self']⟩
alias ⟨_, div_eq_one_of_eq⟩ := div_eq_one
alias ⟨_, sub_eq_zero_of_eq⟩ := sub_eq_zero
@[to_additive]
theorem div_ne_one : a / b ≠ 1 ↔ a ≠ b :=
not_congr div_eq_one
@[to_additive (attr := simp)]
theorem div_eq_self : a / b = a ↔ b = 1 := by rw [div_eq_mul_inv, mul_eq_left, inv_eq_one]
@[to_additive eq_sub_iff_add_eq]
theorem eq_div_iff_mul_eq' : a = b / c ↔ a * c = b := by rw [div_eq_mul_inv, eq_mul_inv_iff_mul_eq]
@[to_additive]
theorem div_eq_iff_eq_mul : a / b = c ↔ a = c * b := by rw [div_eq_mul_inv, mul_inv_eq_iff_eq_mul]
@[to_additive]
theorem eq_iff_eq_of_div_eq_div (H : a / b = c / d) : a = b ↔ c = d := by
rw [← div_eq_one, H, div_eq_one]
@[to_additive]
theorem leftInverse_div_mul_left (c : G) : Function.LeftInverse (fun x ↦ x / c) fun x ↦ x * c :=
fun x ↦ mul_div_cancel_right x c
@[to_additive]
theorem leftInverse_mul_left_div (c : G) : Function.LeftInverse (fun x ↦ x * c) fun x ↦ x / c :=
fun x ↦ div_mul_cancel x c
@[to_additive]
theorem leftInverse_mul_right_inv_mul (c : G) :
Function.LeftInverse (fun x ↦ c * x) fun x ↦ c⁻¹ * x :=
fun x ↦ mul_inv_cancel_left c x
@[to_additive]
theorem leftInverse_inv_mul_mul_right (c : G) :
Function.LeftInverse (fun x ↦ c⁻¹ * x) fun x ↦ c * x :=
fun x ↦ inv_mul_cancel_left c x
@[to_additive (attr := simp) natAbs_nsmul_eq_zero]
lemma pow_natAbs_eq_one : a ^ n.natAbs = 1 ↔ a ^ n = 1 := by cases n <;> simp
@[to_additive sub_nsmul]
lemma pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ :=
eq_mul_inv_of_mul_eq <| by rw [← pow_add, Nat.sub_add_cancel h]
@[to_additive sub_nsmul_neg]
theorem inv_pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a⁻¹ ^ (m - n) = (a ^ m)⁻¹ * a ^ n := by
rw [pow_sub a⁻¹ h, inv_pow, inv_pow, inv_inv]
@[to_additive add_one_zsmul]
lemma zpow_add_one (a : G) : ∀ n : ℤ, a ^ (n + 1) = a ^ n * a
| (n : ℕ) => by simp only [← Int.natCast_succ, zpow_natCast, pow_succ]
| -1 => by simp [Int.add_left_neg]
| .negSucc (n + 1) => by
rw [zpow_negSucc, pow_succ', mul_inv_rev, inv_mul_cancel_right]
rw [Int.negSucc_eq, Int.neg_add, Int.neg_add_cancel_right]
exact zpow_negSucc _ _
@[to_additive sub_one_zsmul]
lemma zpow_sub_one (a : G) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ :=
calc
a ^ (n - 1) = a ^ (n - 1) * a * a⁻¹ := (mul_inv_cancel_right _ _).symm
_ = a ^ n * a⁻¹ := by rw [← zpow_add_one, Int.sub_add_cancel]
@[to_additive add_zsmul]
lemma zpow_add (a : G) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n := by
induction n with
| zero => simp
| succ n ihn => simp only [← Int.add_assoc, zpow_add_one, ihn, mul_assoc]
| pred n ihn => rw [zpow_sub_one, ← mul_assoc, ← ihn, ← zpow_sub_one, Int.add_sub_assoc]
@[to_additive one_add_zsmul]
lemma zpow_one_add (a : G) (n : ℤ) : a ^ (1 + n) = a * a ^ n := by rw [zpow_add, zpow_one]
@[to_additive add_zsmul_self]
lemma mul_self_zpow (a : G) (n : ℤ) : a * a ^ n = a ^ (n + 1) := by
rw [Int.add_comm, zpow_add, zpow_one]
@[to_additive add_self_zsmul]
lemma mul_zpow_self (a : G) (n : ℤ) : a ^ n * a = a ^ (n + 1) := (zpow_add_one ..).symm
@[to_additive sub_zsmul] lemma zpow_sub (a : G) (m n : ℤ) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by
rw [Int.sub_eq_add_neg, zpow_add, zpow_neg]
@[to_additive natCast_sub_natCast_zsmul]
lemma zpow_natCast_sub_natCast (a : G) (m n : ℕ) : a ^ (m - n : ℤ) = a ^ m / a ^ n := by
simpa [div_eq_mul_inv] using zpow_sub a m n
@[to_additive natCast_sub_one_zsmul]
lemma zpow_natCast_sub_one (a : G) (n : ℕ) : a ^ (n - 1 : ℤ) = a ^ n / a := by
simpa [div_eq_mul_inv] using zpow_sub a n 1
@[to_additive one_sub_natCast_zsmul]
lemma zpow_one_sub_natCast (a : G) (n : ℕ) : a ^ (1 - n : ℤ) = a / a ^ n := by
simpa [div_eq_mul_inv] using zpow_sub a 1 n
@[to_additive] lemma zpow_mul_comm (a : G) (m n : ℤ) : a ^ m * a ^ n = a ^ n * a ^ m := by
rw [← zpow_add, Int.add_comm, zpow_add]
@[to_additive] lemma mul_zpow_mul (a b : G) : ∀ n : ℤ, (a * b) ^ n * a = a * (b * a) ^ n
| (n : ℕ) => by simp [mul_pow_mul]
| .negSucc n => by simp [inv_mul_eq_iff_eq_mul, eq_mul_inv_iff_mul_eq, mul_assoc, mul_pow_mul]
theorem zpow_eq_zpow_emod {x : G} (m : ℤ) {n : ℤ} (h : x ^ n = 1) :
x ^ m = x ^ (m % n) :=
calc
x ^ m = x ^ (m % n + n * (m / n)) := by rw [Int.emod_add_mul_ediv]
_ = x ^ (m % n) := by simp [zpow_add, zpow_mul, h]
theorem zpow_eq_zpow_emod' {x : G} (m : ℤ) {n : ℕ} (h : x ^ n = 1) :
x ^ m = x ^ (m % (n : ℤ)) := zpow_eq_zpow_emod m (by simpa)
@[to_additive (attr := simp)]
lemma zpow_iterate (k : ℤ) : ∀ n : ℕ, (fun x : G ↦ x ^ k)^[n] = (· ^ k ^ n)
| 0 => by ext; simp [Int.pow_zero]
| n + 1 => by ext; simp [zpow_iterate, Int.pow_succ', zpow_mul]
/-- To show a property of all powers of `g` it suffices to show it is closed under multiplication
by `g` and `g⁻¹` on the left. For subgroups generated by more than one element, see
`Subgroup.closure_induction_left`. -/
@[to_additive /-- To show a property of all multiples of `g` it suffices to show it is closed under
addition by `g` and `-g` on the left. For additive subgroups generated by more than one element, see
`AddSubgroup.closure_induction_left`. -/]
lemma zpow_induction_left {g : G} {P : G → Prop} (h_one : P (1 : G))
(h_mul : ∀ a, P a → P (g * a)) (h_inv : ∀ a, P a → P (g⁻¹ * a)) (n : ℤ) : P (g ^ n) := by
induction n with
| zero => rwa [zpow_zero]
| succ n ih =>
rw [Int.add_comm, zpow_add, zpow_one]
exact h_mul _ ih
| pred n ih =>
rw [Int.sub_eq_add_neg, Int.add_comm, zpow_add, zpow_neg_one]
exact h_inv _ ih
/-- To show a property of all powers of `g` it suffices to show it is closed under multiplication
by `g` and `g⁻¹` on the right. For subgroups generated by more than one element, see
`Subgroup.closure_induction_right`. -/
@[to_additive /-- To show a property of all multiples of `g` it suffices to show it is closed under
addition by `g` and `-g` on the right. For additive subgroups generated by more than one element,
see `AddSubgroup.closure_induction_right`. -/]
lemma zpow_induction_right {g : G} {P : G → Prop} (h_one : P (1 : G))
(h_mul : ∀ a, P a → P (a * g)) (h_inv : ∀ a, P a → P (a * g⁻¹)) (n : ℤ) : P (g ^ n) := by
induction n with
| zero => rwa [zpow_zero]
| succ n ih =>
rw [zpow_add_one]
exact h_mul _ ih
| pred n ih =>
rw [zpow_sub_one]
exact h_inv _ ih
end Group
section CommGroup
variable [CommGroup G] {a b c d : G}
attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv
@[to_additive]
theorem div_eq_of_eq_mul' {a b c : G} (h : a = b * c) : a / b = c := by
rw [h, div_eq_mul_inv, mul_comm, inv_mul_cancel_left]
@[to_additive (attr := simp)]
theorem mul_div_mul_left_eq_div (a b c : G) : c * a / (c * b) = a / b := by
rw [div_eq_mul_inv, mul_inv_rev, mul_comm b⁻¹ c⁻¹, mul_comm c a, mul_assoc, ← mul_assoc c,
mul_inv_cancel, one_mul, div_eq_mul_inv]
@[to_additive eq_sub_of_add_eq']
theorem eq_div_of_mul_eq'' (h : c * a = b) : a = b / c := by simp [h.symm]
@[to_additive]
theorem eq_mul_of_div_eq' (h : a / b = c) : a = b * c := by simp [h.symm]
@[to_additive]
theorem mul_eq_of_eq_div' (h : b = c / a) : a * b = c := by
rw [h, div_eq_mul_inv, mul_comm c, mul_inv_cancel_left]
@[to_additive sub_sub_self]
theorem div_div_self' (a b : G) : a / (a / b) = b := by simp
@[to_additive]
theorem div_eq_div_mul_div (a b c : G) : a / b = c / b * (a / c) := by simp [mul_left_comm c]
@[to_additive (attr := simp)]
theorem div_div_cancel (a b : G) : a / (a / b) = b :=
div_div_self' a b
@[to_additive (attr := simp)]
theorem div_div_cancel_left (a b : G) : a / b / a = b⁻¹ := by simp
@[to_additive eq_sub_iff_add_eq']
theorem eq_div_iff_mul_eq'' : a = b / c ↔ c * a = b := by rw [eq_div_iff_mul_eq', mul_comm]
@[to_additive]
theorem div_eq_iff_eq_mul' : a / b = c ↔ a = b * c := by rw [div_eq_iff_eq_mul, mul_comm]
@[to_additive (attr := simp)]
theorem mul_div_cancel_left (a b : G) : a * b / a = b := by rw [div_eq_inv_mul, inv_mul_cancel_left]
@[to_additive (attr := simp)]
theorem mul_div_cancel (a b : G) : a * (b / a) = b := by
rw [← mul_div_assoc, mul_div_cancel_left]
@[to_additive (attr := simp)]
theorem div_mul_cancel_left (a b : G) : a / (a * b) = b⁻¹ := by rw [← inv_div, mul_div_cancel_left]
-- This lemma is in the `simp` set under the name `mul_inv_cancel_comm_assoc`,
-- along with the additive version `add_neg_cancel_comm_assoc`,
-- defined in `Algebra.Group.Commute`
@[to_additive]
theorem mul_mul_inv_cancel'_right (a b : G) : a * (b * a⁻¹) = b := by
rw [← div_eq_mul_inv, mul_div_cancel a b]
@[to_additive (attr := simp)]
theorem mul_mul_div_cancel (a b c : G) : a * c * (b / c) = a * b := by
rw [mul_assoc, mul_div_cancel]
@[to_additive (attr := simp)]
theorem div_mul_mul_cancel (a b c : G) : a / c * (b * c) = a * b := by
rw [mul_left_comm, div_mul_cancel, mul_comm]
@[to_additive (attr := simp)]
theorem div_mul_div_cancel' (a b c : G) : a / b * (c / a) = c / b := by
rw [mul_comm]; apply div_mul_div_cancel
@[to_additive (attr := simp)]
theorem mul_div_div_cancel (a b c : G) : a * b / (a / c) = b * c := by
rw [← div_mul, mul_div_cancel_left]
@[to_additive (attr := simp)]
theorem div_div_div_cancel_left (a b c : G) : c / a / (c / b) = b / a := by
rw [← inv_div b c, div_inv_eq_mul, mul_comm, div_mul_div_cancel]
@[to_additive]
theorem div_eq_div_iff_mul_eq_mul : a / b = c / d ↔ a * d = c * b := by
rw [div_eq_iff_eq_mul, div_mul_eq_mul_div, eq_comm, div_eq_iff_eq_mul']
simp only [mul_comm, eq_comm]
@[to_additive]
theorem mul_inv_eq_mul_inv_iff_mul_eq_mul : a * b⁻¹ = c * d⁻¹ ↔ a * d = c * b := by
rw [← div_eq_mul_inv, ← div_eq_mul_inv, div_eq_div_iff_mul_eq_mul]
@[to_additive]
theorem inv_mul_eq_inv_mul_iff_mul_eq_mul : b⁻¹ * a = d⁻¹ * c ↔ a * d = c * b := by
rw [← div_eq_inv_mul, ← div_eq_inv_mul, div_eq_div_iff_mul_eq_mul]
@[to_additive]
theorem div_eq_div_iff_div_eq_div : a / b = c / d ↔ a / c = b / d := by
rw [div_eq_iff_eq_mul, div_mul_eq_mul_div, div_eq_iff_eq_mul', mul_div_assoc]
@[to_additive (attr := simp)]
lemma const_div_involutive (a : G) : Function.Involutive (a / ·) :=
fun _ ↦ div_div_cancel ..
end CommGroup
section multiplicative
variable [Monoid β] (p r : α → α → Prop) [IsTotal α r] (f : α → α → β)
@[to_additive additive_of_symmetric_of_isTotal]
lemma multiplicative_of_symmetric_of_isTotal
(hsymm : Symmetric p) (hf_swap : ∀ {a b}, p a b → f a b * f b a = 1)
(hmul : ∀ {a b c}, r a b → r b c → p a b → p b c → p a c → f a c = f a b * f b c)
{a b c : α} (pab : p a b) (pbc : p b c) (pac : p a c) : f a c = f a b * f b c := by
have hmul' : ∀ {b c}, r b c → p a b → p b c → p a c → f a c = f a b * f b c := by
intro b c rbc pab pbc pac
obtain rab | rba := total_of r a b
· exact hmul rab rbc pab pbc pac
rw [← one_mul (f a c), ← hf_swap pab, mul_assoc]
obtain rac | rca := total_of r a c
· rw [hmul rba rac (hsymm pab) pac pbc]
· rw [hmul rbc rca pbc (hsymm pac) (hsymm pab), mul_assoc, hf_swap (hsymm pac), mul_one]
obtain rbc | rcb := total_of r b c
· exact hmul' rbc pab pbc pac
· rw [hmul' rcb pac (hsymm pbc) pab, mul_assoc, hf_swap (hsymm pbc), mul_one]
/-- If a binary function from a type equipped with a total relation `r` to a monoid is
anti-symmetric (i.e. satisfies `f a b * f b a = 1`), in order to show it is multiplicative
(i.e. satisfies `f a c = f a b * f b c`), we may assume `r a b` and `r b c` are satisfied.
We allow restricting to a subset specified by a predicate `p`. -/
@[to_additive additive_of_isTotal /-- If a binary function from a type equipped with a total
relation `r` to an additive monoid is anti-symmetric (i.e. satisfies `f a b + f b a = 0`), in
order to show it is additive (i.e. satisfies `f a c = f a b + f b c`), we may assume `r a b` and
`r b c` are satisfied. We allow restricting to a subset specified by a predicate `p`. -/]
theorem multiplicative_of_isTotal (p : α → Prop) (hswap : ∀ {a b}, p a → p b → f a b * f b a = 1)
(hmul : ∀ {a b c}, r a b → r b c → p a → p b → p c → f a c = f a b * f b c) {a b c : α}
(pa : p a) (pb : p b) (pc : p c) : f a c = f a b * f b c := by
apply multiplicative_of_symmetric_of_isTotal (fun a b => p a ∧ p b) r f fun _ _ => And.symm
· simp_rw [and_imp]; exact @hswap
· exact fun rab rbc pab _pbc pac => hmul rab rbc pab.1 pab.2 pac.2
exacts [⟨pa, pb⟩, ⟨pb, pc⟩, ⟨pa, pc⟩]
end multiplicative
/-- An auxiliary lemma that can be used to prove `⇑(f ^ n) = ⇑f^[n]`. -/
@[to_additive]
lemma hom_coe_pow {F : Type*} [Monoid F] (c : F → M → M) (h1 : c 1 = id)
(hmul : ∀ f g, c (f * g) = c f ∘ c g) (f : F) : ∀ n, c (f ^ n) = (c f)^[n]
| 0 => by
rw [pow_zero, h1]
rfl
| n + 1 => by rw [pow_succ, iterate_succ, hmul, hom_coe_pow c h1 hmul f n]
/-!
### Instances for `grind`.
-/
open Lean
variable (α : Type*)
instance AddCommMonoid.toGrindNatModule [s : AddCommMonoid α] :
Grind.NatModule α :=
{ s with
nsmul := ⟨s.nsmul⟩
zero_nsmul := AddMonoid.nsmul_zero
add_one_nsmul n a := by change (n + 1) • a = n • a + a; rw [add_nsmul, one_nsmul] }
instance AddCommGroup.toGrindIntModule [s : AddCommGroup α] :
Grind.IntModule α :=
{ s with
nsmul := ⟨s.nsmul⟩
zsmul := ⟨s.zsmul⟩
zero_zsmul := SubNegMonoid.zsmul_zero'
one_zsmul := one_zsmul
add_zsmul n m a := add_zsmul a n m
zsmul_natCast_eq_nsmul n a := by simp }
instance IsRightCancelAdd.toGrindAddRightCancel [AddSemigroup α] [IsRightCancelAdd α] :
Grind.AddRightCancel α where
add_right_cancel _ _ _ := add_right_cancel |
.lake/packages/mathlib/Mathlib/Algebra/Group/ULift.lean | import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Group.InjSurj
import Mathlib.Logic.Nontrivial.Basic
/-!
# `ULift` instances for groups and monoids
This file defines instances for group, monoid, semigroup and related structures on `ULift` types.
(Recall `ULift α` is just a "copy" of a type `α` in a higher universe.)
We also provide `MulEquiv.ulift : ULift R ≃* R` (and its additive analogue).
-/
assert_not_exists MonoidWithZero DenselyOrdered
universe u v w
variable {α : Type u} {β : Type v} {x y : ULift.{w} α}
namespace ULift
@[to_additive]
instance one [One α] : One (ULift α) :=
⟨⟨1⟩⟩
@[to_additive (attr := simp)]
theorem one_down [One α] : (1 : ULift α).down = 1 :=
rfl
@[to_additive]
instance mul [Mul α] : Mul (ULift α) :=
⟨fun f g => ⟨f.down * g.down⟩⟩
@[to_additive (attr := simp)]
theorem mul_down [Mul α] : (x * y).down = x.down * y.down :=
rfl
@[to_additive]
instance div [Div α] : Div (ULift α) :=
⟨fun f g => ⟨f.down / g.down⟩⟩
@[to_additive (attr := simp)]
theorem div_down [Div α] : (x / y).down = x.down / y.down :=
rfl
@[to_additive]
instance inv [Inv α] : Inv (ULift α) :=
⟨fun f => ⟨f.down⁻¹⟩⟩
@[to_additive (attr := simp)]
theorem inv_down [Inv α] : x⁻¹.down = x.down⁻¹ :=
rfl
@[to_additive]
instance smul [SMul α β] : SMul α (ULift β) :=
⟨fun n x => up (n • x.down)⟩
@[to_additive (attr := simp)]
theorem smul_down [SMul α β] (a : α) (b : ULift.{w} β) : (a • b).down = a • b.down :=
rfl
@[to_additive existing (reorder := 1 2) smul]
instance pow [Pow α β] : Pow (ULift α) β :=
⟨fun x n => up (x.down ^ n)⟩
@[to_additive existing (attr := simp) (reorder := 1 2, 4 5) smul_down]
theorem pow_down [Pow α β] (a : ULift.{w} α) (b : β) : (a ^ b).down = a.down ^ b :=
rfl
/-- The multiplicative equivalence between `ULift α` and `α`.
-/
@[to_additive /-- The additive equivalence between `ULift α` and `α`. -/]
def _root_.MulEquiv.ulift [Mul α] : ULift α ≃* α :=
{ Equiv.ulift with map_mul' := fun _ _ => rfl }
@[to_additive]
instance semigroup [Semigroup α] : Semigroup (ULift α) :=
(MulEquiv.ulift.injective.semigroup _) fun _ _ => rfl
@[to_additive]
instance commSemigroup [CommSemigroup α] : CommSemigroup (ULift α) :=
(Equiv.ulift.injective.commSemigroup _) fun _ _ => rfl
@[to_additive]
instance mulOneClass [MulOneClass α] : MulOneClass (ULift α) :=
Equiv.ulift.injective.mulOneClass _ rfl (by intros; rfl)
@[to_additive]
instance monoid [Monoid α] : Monoid (ULift α) :=
Equiv.ulift.injective.monoid _ rfl (fun _ _ => rfl) fun _ _ => rfl
@[to_additive]
instance commMonoid [CommMonoid α] : CommMonoid (ULift α) :=
Equiv.ulift.injective.commMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl
@[to_additive]
instance divInvMonoid [DivInvMonoid α] : DivInvMonoid (ULift α) :=
Equiv.ulift.injective.divInvMonoid _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
@[to_additive]
instance group [Group α] : Group (ULift α) :=
Equiv.ulift.injective.group _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
@[to_additive]
instance commGroup [CommGroup α] : CommGroup (ULift α) :=
Equiv.ulift.injective.commGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
@[to_additive]
instance leftCancelSemigroup [LeftCancelSemigroup α] : LeftCancelSemigroup (ULift α) :=
Equiv.ulift.injective.leftCancelSemigroup _ fun _ _ => rfl
@[to_additive]
instance rightCancelSemigroup [RightCancelSemigroup α] : RightCancelSemigroup (ULift α) :=
Equiv.ulift.injective.rightCancelSemigroup _ fun _ _ => rfl
@[to_additive]
instance leftCancelMonoid [LeftCancelMonoid α] : LeftCancelMonoid (ULift α) :=
Equiv.ulift.injective.leftCancelMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl
@[to_additive]
instance rightCancelMonoid [RightCancelMonoid α] : RightCancelMonoid (ULift α) :=
Equiv.ulift.injective.rightCancelMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl
@[to_additive]
instance cancelMonoid [CancelMonoid α] : CancelMonoid (ULift α) :=
Equiv.ulift.injective.cancelMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl
@[to_additive]
instance cancelCommMonoid [CancelCommMonoid α] : CancelCommMonoid (ULift α) :=
Equiv.ulift.injective.cancelCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl
instance nontrivial [Nontrivial α] : Nontrivial (ULift α) :=
Equiv.ulift.symm.injective.nontrivial
-- TODO we don't do `OrderedCancelCommMonoid` or `OrderedCommGroup`
-- We'd need to add instances for `ULift` in `Order.Basic`.
end ULift |
.lake/packages/mathlib/Mathlib/Algebra/Group/Translate.lean | import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.GroupTheory.GroupAction.DomAct.Basic
/-!
# Translation operator
This file defines the translation of a function from a group by an element of that group.
## Notation
`τ a f` is notation for `translate a f`.
## See also
Generally, translation is the same as acting on the domain by subtraction. This setting is
abstracted by `DomAddAct` in such a way that `τ a f = DomAddAct.mk (-a) +ᵥ f` (see
`translate_eq_domAddActMk_vadd`). Using `DomAddAct` is irritating in applications because of this
negation appearing inside `DomAddAct.mk`. Although mathematically equivalent, the pen and paper
convention is that translating is an action by subtraction, not by addition.
-/
open Function Set
open scoped Pointwise
variable {ι α β M G H : Type*} [AddCommGroup G]
/-- Translation of a function in a group by an element of that group.
`τ a f` is defined as `x ↦ f (x - a)`. -/
def translate (a : G) (f : G → α) : G → α := fun x ↦ f (x - a)
@[inherit_doc] scoped[translate] notation "τ " => translate
open scoped translate
@[simp] lemma translate_apply (a : G) (f : G → α) (x : G) : τ a f x = f (x - a) := rfl
@[simp] lemma translate_zero (f : G → α) : τ 0 f = f := by ext; simp
lemma translate_translate (a b : G) (f : G → α) : τ a (τ b f) = τ (a + b) f := by
ext; simp [sub_sub]
lemma translate_add (a b : G) (f : G → α) : τ (a + b) f = τ a (τ b f) := by ext; simp [sub_sub]
/-- See `translate_add` -/
lemma translate_add' (a b : G) (f : G → α) : τ (a + b) f = τ b (τ a f) := by
rw [add_comm, translate_add]
lemma translate_comm (a b : G) (f : G → α) : τ a (τ b f) = τ b (τ a f) := by
rw [← translate_add, translate_add']
-- We make `simp` push the `τ` outside
@[simp] lemma comp_translate (a : G) (f : G → α) (g : α → β) : g ∘ τ a f = τ a (g ∘ f) := rfl
lemma translate_eq_domAddActMk_vadd (a : G) (f : G → α) : τ a f = DomAddAct.mk (-a) +ᵥ f := by
ext; simp [DomAddAct.vadd_apply, sub_eq_neg_add]
@[simp]
lemma translate_smul_right [SMul H α] (a : G) (f : G → α) (c : H) : τ a (c • f) = c • τ a f := rfl
@[simp] lemma translate_zero_right [Zero α] (a : G) : τ a (0 : G → α) = 0 := rfl
lemma translate_add_right [Add α] (a : G) (f g : G → α) : τ a (f + g) = τ a f + τ a g := rfl
lemma translate_sub_right [Sub α] (a : G) (f g : G → α) : τ a (f - g) = τ a f - τ a g := rfl
lemma translate_neg_right [Neg α] (a : G) (f : G → α) : τ a (-f) = -τ a f := rfl
section AddCommMonoid
variable [AddCommMonoid M]
lemma translate_sum_right (a : G) (f : ι → G → M) (s : Finset ι) :
τ a (∑ i ∈ s, f i) = ∑ i ∈ s, τ a (f i) := by ext; simp
lemma sum_translate [Fintype G] (a : G) (f : G → M) : ∑ b, τ a f b = ∑ b, f b :=
Fintype.sum_equiv (Equiv.subRight _) _ _ fun _ ↦ rfl
end AddCommMonoid
section AddCommGroup
variable [AddCommGroup H]
@[simp] lemma support_translate (a : G) (f : G → H) : support (τ a f) = a +ᵥ support f := by
ext; simp [mem_vadd_set_iff_neg_vadd_mem, sub_eq_neg_add]
end AddCommGroup
variable [CommMonoid M]
lemma translate_prod_right (a : G) (f : ι → G → M) (s : Finset ι) :
τ a (∏ i ∈ s, f i) = ∏ i ∈ s, τ a (f i) := by ext; simp |
.lake/packages/mathlib/Mathlib/Algebra/Group/Ideal.lean | import Mathlib.GroupTheory.GroupAction.SubMulAction.Closure
/-!
# Semigroup ideals
This file defines (left) semigroup ideals (also called monoid ideals sometimes), which are sets `s`
in a semigroup such that `a * b ∈ s` whenever `b ∈ s`. Note that semigroup ideals are different from
ring ideals (`Ideal` in Mathlib): a ring ideal is a semigroup ideal that is also an additive
submonoid of the ring.
## References
* [Samuel Eilenberg and M. P. Schützenberger, *Rational Sets in Commutative Monoids*][eilenberg1969]
-/
open Set Pointwise
/-- A (left) semigroup ideal in a semigroup `M` is a set `s` such that `a * b ∈ s` whenever
`b ∈ s`. -/
@[to_additive /-- A (left) additive semigroup ideal in an additive semigroup `M` is a set `s` such
that `a + b ∈ s` whenever `b ∈ s`. -/]
abbrev SemigroupIdeal (M : Type*) [Mul M] :=
SubMulAction M M
namespace SemigroupIdeal
variable {M : Type*}
section Mul
variable [Mul M] {s t : Set M} {x : M}
@[to_additive]
protected theorem mul_mem (I : SemigroupIdeal M) (x : M) {y : M} : y ∈ I → x * y ∈ I :=
SubMulAction.smul_mem I x
/-- The semigroup ideal generated by a set `s`. -/
@[to_additive /-- The additive semigroup ideal generated by a set `s`. -/]
abbrev closure (s : Set M) : SemigroupIdeal M :=
SubMulAction.closure M s
@[to_additive]
theorem mem_closure : x ∈ closure s ↔ ∀ p : SemigroupIdeal M, s ⊆ p → x ∈ p :=
SubMulAction.mem_closure
@[to_additive]
theorem subset_closure : s ⊆ closure s :=
SubMulAction.subset_closure
@[to_additive]
theorem mem_closure_of_mem (hx : x ∈ s) : x ∈ closure s :=
SubMulAction.mem_closure_of_mem hx
@[to_additive]
theorem closure_le {I} : closure s ≤ I ↔ s ⊆ I :=
SubMulAction.closure_le
@[to_additive (attr := gcongr)]
theorem closure_mono (h : s ⊆ t) : closure s ≤ closure t :=
SubMulAction.closure_mono h
end Mul
/-- The semigroup ideal generated by `s` is `s ∪ Set.univ * s`. -/
@[to_additive /-- The additive semigroup ideal generated by `s` is `s ∪ Set.univ + s`. -/]
theorem coe_closure [Semigroup M] {s : Set M} :
(closure s : Set M) = s ∪ univ * s := by
let I : SemigroupIdeal M :=
{ carrier := s ∪ univ * s
smul_mem' x y := by
rintro (hy | ⟨y, -, z, hz, rfl⟩)
· exact .inr <| mul_mem_mul (mem_univ _) hy
· simpa [← mul_assoc] using .inr <| mul_mem_mul (mem_univ _) hz }
suffices closure s = I by rw [this]; rfl
refine (closure_le.2 fun x => Or.inl).antisymm fun x hx => hx.elim mem_closure_of_mem ?_
rintro ⟨y, -, z, hz, rfl⟩
exact SemigroupIdeal.mul_mem _ _ (mem_closure_of_mem hz)
@[to_additive, inherit_doc coe_closure]
theorem mem_closure' [Semigroup M] {s : Set M} {x : M} :
x ∈ closure s ↔ x ∈ s ∨ ∃ y, ∃ z ∈ s, y * z = x := by
rw [← SetLike.mem_coe, coe_closure]
simp [mem_mul]
attribute [inherit_doc AddSemigroupIdeal.coe_closure] AddSemigroupIdeal.mem_closure'
/-- In a monoid, the semigroup ideal generated by `s` is `Set.univ * s`. -/
@[to_additive /-- In an additive monoid, the semigroup ideal generated by `s` is `Set.univ + s`. -/]
theorem coe_closure' [Monoid M] {s : Set M} :
(closure s : Set M) = univ * s := by
rw [coe_closure, union_eq_right]
exact fun x hx => ⟨1, mem_univ 1, x, hx, by simp⟩
@[to_additive, inherit_doc coe_closure']
theorem mem_closure'' [Monoid M] {s : Set M} {x : M} :
x ∈ closure s ↔ ∃ y, ∃ z ∈ s, y * z = x := by
rw [← SetLike.mem_coe, coe_closure']
simp [mem_mul]
attribute [inherit_doc AddSemigroupIdeal.coe_closure'] AddSemigroupIdeal.mem_closure''
/-- A semigroup ideal is finitely generated if it is generated by a finite set.
This is defeq to `SubMulAction.FG`, but unfolds more nicely. -/
@[to_additive /-- An additive semigroup ideal is finitely generated if it is generated by a finite
set.
This is defeq to `SubAddAction.FG`, but unfolds more nicely. -/]
def FG [Mul M] (I : SemigroupIdeal M) :=
∃ (s : Set M), s.Finite ∧ I = closure s
@[to_additive]
theorem fg_iff [Mul M] {I : SemigroupIdeal M} : I.FG ↔ ∃ (s : Finset M), I = closure s :=
SubMulAction.fg_iff
end SemigroupIdeal |
.lake/packages/mathlib/Mathlib/Algebra/Group/End.lean | import Mathlib.Algebra.Group.Equiv.TypeTags
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Algebra.Group.Prod
import Mathlib.Algebra.Group.Units.Equiv
import Mathlib.Data.Set.Basic
import Mathlib.Tactic.Common
/-!
# Monoids of endomorphisms, groups of automorphisms
This file defines
* the endomorphism monoid structure on `Function.End α := α → α`
* the endomorphism monoid structure on `Monoid.End M := M →* M` and `AddMonoid.End M := M →+ M`
* the automorphism group structure on `Equiv.Perm α := α ≃ α`
* the automorphism group structure on `MulAut M := M ≃* M` and `AddAut M := M ≃+ M`.
## Implementation notes
The definition of multiplication in the endomorphism monoids and automorphism groups agrees with
function composition, and multiplication in `CategoryTheory.End`, but not with
`CategoryTheory.comp`.
## Tags
end monoid, aut group
-/
assert_not_exists HeytingAlgebra MonoidWithZero MulAction RelIso
variable {A M G α β γ : Type*}
/-! ### Type endomorphisms -/
variable (α) in
/-- The monoid of endomorphisms.
Note that this is generalized by `CategoryTheory.End` to categories other than `Type u`. -/
protected def Function.End := α → α
instance : Monoid (Function.End α) where
one := id
mul := (· ∘ ·)
mul_assoc _ _ _ := rfl
mul_one _ := rfl
one_mul _ := rfl
npow n f := f^[n]
npow_succ _ _ := Function.iterate_succ _ _
instance : Inhabited (Function.End α) := ⟨1⟩
/-! ### Monoid endomorphisms -/
namespace Equiv.Perm
instance instOne : One (Perm α) where one := Equiv.refl _
instance instMul : Mul (Perm α) where mul f g := Equiv.trans g f
instance instInv : Inv (Perm α) where inv := Equiv.symm
instance instPowNat : Pow (Perm α) ℕ where
pow f n := ⟨f^[n], f.symm^[n], f.left_inv.iterate _, f.right_inv.iterate _⟩
instance permGroup : Group (Perm α) where
mul_assoc _ _ _ := (trans_assoc _ _ _).symm
one_mul := trans_refl
mul_one := refl_trans
inv_mul_cancel := self_trans_symm
npow n f := f ^ n
npow_succ _ _ := coe_fn_injective <| Function.iterate_succ _ _
zpow := zpowRec fun n f ↦ f ^ n
zpow_succ' _ _ := coe_fn_injective <| Function.iterate_succ _ _
@[simp]
theorem default_eq : (default : Perm α) = 1 :=
rfl
/-- The permutation of a type is equivalent to the units group of the endomorphisms monoid of this
type. -/
@[simps]
def equivUnitsEnd : Perm α ≃* Units (Function.End α) where
toFun e := ⟨⇑e, ⇑e.symm, e.self_comp_symm, e.symm_comp_self⟩
invFun u :=
⟨(u : Function.End α), (↑u⁻¹ : Function.End α), congr_fun u.inv_val, congr_fun u.val_inv⟩
map_mul' _ _ := rfl
/-- Lift a monoid homomorphism `f : G →* Function.End α` to a monoid homomorphism
`f : G →* Equiv.Perm α`. -/
@[simps!]
def _root_.MonoidHom.toHomPerm {G : Type*} [Group G] (f : G →* Function.End α) : G →* Perm α :=
equivUnitsEnd.symm.toMonoidHom.comp f.toHomUnits
theorem mul_apply (f g : Perm α) (x) : (f * g) x = f (g x) :=
rfl
theorem one_apply (x) : (1 : Perm α) x = x :=
rfl
@[simp]
theorem inv_apply_self (f : Perm α) (x) : f⁻¹ (f x) = x :=
f.symm_apply_apply x
@[simp]
theorem apply_inv_self (f : Perm α) (x) : f (f⁻¹ x) = x :=
f.apply_symm_apply x
theorem one_def : (1 : Perm α) = Equiv.refl α :=
rfl
theorem mul_def (f g : Perm α) : f * g = g.trans f :=
rfl
theorem inv_def (f : Perm α) : f⁻¹ = f.symm :=
rfl
@[simp, norm_cast] lemma coe_one : ⇑(1 : Perm α) = id := rfl
@[simp, norm_cast] lemma coe_mul (f g : Perm α) : ⇑(f * g) = f ∘ g := rfl
@[norm_cast] lemma coe_pow (f : Perm α) (n : ℕ) : ⇑(f ^ n) = f^[n] := rfl
@[simp] lemma iterate_eq_pow (f : Perm α) (n : ℕ) : f^[n] = ⇑(f ^ n) := rfl
theorem eq_inv_iff_eq {f : Perm α} {x y : α} : x = f⁻¹ y ↔ f x = y :=
f.eq_symm_apply
theorem inv_eq_iff_eq {f : Perm α} {x y : α} : f⁻¹ x = y ↔ x = f y :=
f.symm_apply_eq
theorem zpow_apply_comm {α : Type*} (σ : Perm α) (m n : ℤ) {x : α} :
(σ ^ m) ((σ ^ n) x) = (σ ^ n) ((σ ^ m) x) := by
rw [← Equiv.Perm.mul_apply, ← Equiv.Perm.mul_apply, zpow_mul_comm]
/-! Lemmas about mixing `Perm` with `Equiv`. Because we have multiple ways to express
`Equiv.refl`, `Equiv.symm`, and `Equiv.trans`, we want simp lemmas for every combination.
The assumption made here is that if you're using the group structure, you want to preserve it after
simp. -/
@[simp]
theorem trans_one {α : Sort*} {β : Type*} (e : α ≃ β) : e.trans (1 : Perm β) = e :=
Equiv.trans_refl e
@[simp]
theorem mul_refl (e : Perm α) : e * Equiv.refl α = e :=
Equiv.trans_refl e
@[simp]
theorem one_symm : (1 : Perm α).symm = 1 :=
rfl
@[simp]
theorem refl_inv : (Equiv.refl α : Perm α)⁻¹ = 1 :=
rfl
@[simp]
theorem one_trans {α : Type*} {β : Sort*} (e : α ≃ β) : (1 : Perm α).trans e = e :=
rfl
@[simp]
theorem refl_mul (e : Perm α) : Equiv.refl α * e = e :=
rfl
@[simp]
theorem inv_trans_self (e : Perm α) : e⁻¹.trans e = 1 :=
Equiv.symm_trans_self e
@[simp]
theorem mul_symm (e : Perm α) : e * e.symm = 1 :=
Equiv.symm_trans_self e
@[simp]
theorem self_trans_inv (e : Perm α) : e.trans e⁻¹ = 1 :=
Equiv.self_trans_symm e
@[simp]
theorem symm_mul (e : Perm α) : e.symm * e = 1 :=
Equiv.self_trans_symm e
/-! Lemmas about `Equiv.Perm.sumCongr` re-expressed via the group structure. -/
@[simp]
theorem sumCongr_mul {α β : Type*} (e : Perm α) (f : Perm β) (g : Perm α) (h : Perm β) :
sumCongr e f * sumCongr g h = sumCongr (e * g) (f * h) :=
sumCongr_trans g h e f
@[simp]
theorem sumCongr_inv {α β : Type*} (e : Perm α) (f : Perm β) :
(sumCongr e f)⁻¹ = sumCongr e⁻¹ f⁻¹ :=
rfl
@[simp]
theorem sumCongr_one {α β : Type*} : sumCongr (1 : Perm α) (1 : Perm β) = 1 :=
sumCongr_refl
/-- `Equiv.Perm.sumCongr` as a `MonoidHom`, with its two arguments bundled into a single `Prod`.
This is particularly useful for its `MonoidHom.range` projection, which is the subgroup of
permutations which do not exchange elements between `α` and `β`. -/
@[simps]
def sumCongrHom (α β : Type*) : Perm α × Perm β →* Perm (α ⊕ β) where
toFun a := sumCongr a.1 a.2
map_one' := sumCongr_one
map_mul' _ _ := (sumCongr_mul _ _ _ _).symm
theorem sumCongrHom_injective {α β : Type*} : Function.Injective (sumCongrHom α β) := by
rintro ⟨⟩ ⟨⟩ h
rw [Prod.mk_inj]
constructor <;> ext i
· simpa using Equiv.congr_fun h (Sum.inl i)
· simpa using Equiv.congr_fun h (Sum.inr i)
@[simp]
theorem sumCongr_swap_one {α β : Type*} [DecidableEq α] [DecidableEq β] (i j : α) :
sumCongr (Equiv.swap i j) (1 : Perm β) = Equiv.swap (Sum.inl i) (Sum.inl j) :=
sumCongr_swap_refl i j
@[simp]
theorem sumCongr_one_swap {α β : Type*} [DecidableEq α] [DecidableEq β] (i j : β) :
sumCongr (1 : Perm α) (Equiv.swap i j) = Equiv.swap (Sum.inr i) (Sum.inr j) :=
sumCongr_refl_swap i j
/-! Lemmas about `Equiv.Perm.sigmaCongrRight` re-expressed via the group structure. -/
@[simp]
theorem sigmaCongrRight_mul {α : Type*} {β : α → Type*} (F : ∀ a, Perm (β a))
(G : ∀ a, Perm (β a)) : sigmaCongrRight F * sigmaCongrRight G = sigmaCongrRight (F * G) :=
rfl
@[simp]
theorem sigmaCongrRight_inv {α : Type*} {β : α → Type*} (F : ∀ a, Perm (β a)) :
(sigmaCongrRight F)⁻¹ = sigmaCongrRight fun a => (F a)⁻¹ :=
rfl
@[simp]
theorem sigmaCongrRight_one {α : Type*} {β : α → Type*} :
sigmaCongrRight (1 : ∀ a, Equiv.Perm <| β a) = 1 :=
rfl
/-- `Equiv.Perm.sigmaCongrRight` as a `MonoidHom`.
This is particularly useful for its `MonoidHom.range` projection, which is the subgroup of
permutations which do not exchange elements between fibers. -/
@[simps]
def sigmaCongrRightHom {α : Type*} (β : α → Type*) : (∀ a, Perm (β a)) →* Perm (Σ a, β a) where
toFun := sigmaCongrRight
map_one' := sigmaCongrRight_one
map_mul' _ _ := (sigmaCongrRight_mul _ _).symm
theorem sigmaCongrRightHom_injective {α : Type*} {β : α → Type*} :
Function.Injective (sigmaCongrRightHom β) := by
intro x y h
ext a b
simpa using Equiv.congr_fun h ⟨a, b⟩
/-- `Equiv.Perm.subtypeCongr` as a `MonoidHom`. -/
@[simps]
def subtypeCongrHom (p : α → Prop) [DecidablePred p] :
Perm { a // p a } × Perm { a // ¬p a } →* Perm α where
toFun pair := Perm.subtypeCongr pair.fst pair.snd
map_one' := Perm.subtypeCongr.refl
map_mul' _ _ := (Perm.subtypeCongr.trans _ _ _ _).symm
theorem subtypeCongrHom_injective (p : α → Prop) [DecidablePred p] :
Function.Injective (subtypeCongrHom p) := by
rintro ⟨⟩ ⟨⟩ h
rw [Prod.mk_inj]
constructor <;> ext i <;> simpa using Equiv.congr_fun h i
/-- If `e` is also a permutation, we can write `permCongr`
completely in terms of the group structure. -/
@[simp]
theorem _root_.Equiv.permCongr_eq_mul (e p : Perm α) : e.permCongr p = e * p * e⁻¹ :=
rfl
@[deprecated (since := "2025-08-29")] alias permCongr_eq_mul := Equiv.permCongr_eq_mul
@[simp]
lemma _root_.Equiv.permCongr_mul (e : α ≃ β) (p q : Perm α) :
e.permCongr (p * q) = e.permCongr p * e.permCongr q :=
permCongr_trans e q p |>.symm
def _root_.Equiv.permCongrHom (e : α ≃ β) : Perm α ≃* Perm β where
toEquiv := e.permCongr
map_mul' p q := e.permCongr_mul p q
attribute [inherit_doc Equiv.permCongr] Equiv.permCongrHom
extend_docs Equiv.permCongrHom after "This is `Equiv.permCongr` as a `MulEquiv`."
@[deprecated (since := "2025-08-23")] alias permCongrHom := Equiv.permCongrHom
@[simp]
theorem _root_.Equiv.permCongrHom_symm (e : α ≃ β) :
e.permCongrHom.symm = e.symm.permCongrHom :=
rfl
@[simp]
theorem _root_.Equiv.permCongrHom_trans (e : α ≃ β) (e' : β ≃ γ) :
e.permCongrHom.trans e'.permCongrHom = (e.trans e').permCongrHom :=
rfl
@[simp]
lemma _root_.Equiv.permCongrHom_coe_equiv (e : α ≃ β) :
(↑e.permCongrHom : Perm α ≃ Perm β) = e.permCongr :=
rfl
@[simp]
lemma _root_.Equiv.permCongrHom_coe (e : α ≃ β) : ⇑e.permCongrHom = ⇑e.permCongr :=
rfl
section ExtendDomain
/-! Lemmas about `Equiv.Perm.extendDomain` re-expressed via the group structure. -/
variable (e : Perm α) {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p)
@[simp]
theorem extendDomain_one : extendDomain 1 f = 1 :=
extendDomain_refl f
@[simp]
theorem extendDomain_inv : (e.extendDomain f)⁻¹ = e⁻¹.extendDomain f :=
rfl
@[simp]
theorem extendDomain_mul (e e' : Perm α) :
e.extendDomain f * e'.extendDomain f = (e * e').extendDomain f :=
extendDomain_trans _ _ _
/-- `extendDomain` as a group homomorphism -/
@[simps]
def extendDomainHom : Perm α →* Perm β where
toFun e := extendDomain e f
map_one' := extendDomain_one f
map_mul' e e' := (extendDomain_mul f e e').symm
theorem extendDomainHom_injective : Function.Injective (extendDomainHom f) :=
(injective_iff_map_eq_one (extendDomainHom f)).mpr fun e he =>
ext fun x => f.injective <|
Subtype.ext ((extendDomain_apply_image e f x).symm.trans (Perm.ext_iff.mp he (f x)))
@[simp]
theorem extendDomain_eq_one_iff {e : Perm α} {f : α ≃ Subtype p} : e.extendDomain f = 1 ↔ e = 1 :=
(injective_iff_map_eq_one' (extendDomainHom f)).mp (extendDomainHom_injective f) e
@[simp]
lemma extendDomain_pow (n : ℕ) : (e ^ n).extendDomain f = e.extendDomain f ^ n :=
map_pow (extendDomainHom f) _ _
@[simp]
lemma extendDomain_zpow (n : ℤ) : (e ^ n).extendDomain f = e.extendDomain f ^ n :=
map_zpow (extendDomainHom f) _ _
end ExtendDomain
section Subtype
variable {p : α → Prop} {f : Perm α}
/-- If the permutation `f` fixes the subtype `{x // p x}`, then this returns the permutation
on `{x // p x}` induced by `f`. -/
def subtypePerm (f : Perm α) (h : ∀ x, p (f x) ↔ p x) : Perm { x // p x } where
toFun := fun x => ⟨f x, (h _).2 x.2⟩
invFun := fun x => ⟨f⁻¹ x, (h (f⁻¹ x)).1 <| by simpa using x.2⟩
left_inv _ := by simp
right_inv _ := by simp
@[simp]
theorem subtypePerm_apply (f : Perm α) (h : ∀ x, p (f x) ↔ p x) (x : { x // p x }) :
subtypePerm f h x = ⟨f x, (h _).2 x.2⟩ :=
rfl
@[simp]
theorem subtypePerm_one (p : α → Prop) (h := fun _ => Iff.rfl) : @subtypePerm α p 1 h = 1 :=
rfl
@[simp]
theorem subtypePerm_mul (f g : Perm α) (hf hg) :
(f.subtypePerm hf * g.subtypePerm hg : Perm { x // p x }) =
(f * g).subtypePerm fun _ => (hf _).trans <| hg _ :=
rfl
private theorem inv_aux : (∀ x, p (f x) ↔ p x) ↔ ∀ x, p (f⁻¹ x) ↔ p x :=
f⁻¹.surjective.forall.trans <| by simp [Iff.comm]
/-- See `Equiv.Perm.inv_subtypePerm`. -/
theorem subtypePerm_inv (f : Perm α) (hf) :
f⁻¹.subtypePerm hf = (f.subtypePerm <| inv_aux.2 hf : Perm { x // p x })⁻¹ :=
rfl
/-- See `Equiv.Perm.subtypePerm_inv`. -/
@[simp]
theorem inv_subtypePerm (f : Perm α) (hf) :
(f.subtypePerm hf : Perm { x // p x })⁻¹ = f⁻¹.subtypePerm (inv_aux.1 hf) :=
rfl
private theorem pow_aux (hf : ∀ x, p (f x) ↔ p x) : ∀ {n : ℕ} (x), p ((f ^ n) x) ↔ p x
| 0, _ => Iff.rfl
| _ + 1, _ => (pow_aux hf (f _)).trans (hf _)
@[simp]
theorem subtypePerm_pow (f : Perm α) (n : ℕ) (hf) :
(f.subtypePerm hf : Perm { x // p x }) ^ n = (f ^ n).subtypePerm (pow_aux hf) := by
induction n with
| zero => simp
| succ n ih => simp_rw [pow_succ', ih, subtypePerm_mul]
private theorem zpow_aux (hf : ∀ x, p (f x) ↔ p x) : ∀ {n : ℤ} (x), p ((f ^ n) x) ↔ p x
| Int.ofNat _ => pow_aux hf
| Int.negSucc n => by
rw [zpow_negSucc]
exact pow_aux (inv_aux.1 hf)
@[simp]
theorem subtypePerm_zpow (f : Perm α) (n : ℤ) (hf) :
(f.subtypePerm hf ^ n : Perm { x // p x }) = (f ^ n).subtypePerm (zpow_aux hf) := by
cases n with
| ofNat n => exact subtypePerm_pow _ _ _
| negSucc n => simp only [zpow_negSucc, subtypePerm_pow, subtypePerm_inv]
variable [DecidablePred p] {a : α}
/-- The inclusion map of permutations on a subtype of `α` into permutations of `α`,
fixing the other points. -/
def ofSubtype : Perm (Subtype p) →* Perm α where
toFun f := extendDomain f (Equiv.refl (Subtype p))
map_one' := Equiv.Perm.extendDomain_one _
map_mul' f g := (Equiv.Perm.extendDomain_mul _ f g).symm
theorem ofSubtype_subtypePerm {f : Perm α} (h₁ : ∀ x, p (f x) ↔ p x) (h₂ : ∀ x, f x ≠ x → p x) :
ofSubtype (subtypePerm f h₁) = f :=
Equiv.ext fun x => by
by_cases hx : p x
· exact (subtypePerm f h₁).extendDomain_apply_subtype _ hx
· rw [ofSubtype, MonoidHom.coe_mk, OneHom.coe_mk,
Equiv.Perm.extendDomain_apply_not_subtype _ _ hx]
exact not_not.mp fun h => hx (h₂ x (Ne.symm h))
theorem ofSubtype_apply_of_mem (f : Perm (Subtype p)) (ha : p a) : ofSubtype f a = f ⟨a, ha⟩ :=
extendDomain_apply_subtype _ _ ha
@[simp]
theorem ofSubtype_apply_coe (f : Perm (Subtype p)) (x : Subtype p) : ofSubtype f x = f x :=
Subtype.casesOn x fun _ => ofSubtype_apply_of_mem f
theorem ofSubtype_apply_of_not_mem (f : Perm (Subtype p)) (ha : ¬p a) : ofSubtype f a = a :=
extendDomain_apply_not_subtype _ _ ha
theorem ofSubtype_apply_mem_iff_mem (f : Perm (Subtype p)) (x : α) :
p ((ofSubtype f : α → α) x) ↔ p x :=
if h : p x then by
simpa only [h, iff_true, MonoidHom.coe_mk, ofSubtype_apply_of_mem f h] using (f ⟨x, h⟩).2
else by simp [h, ofSubtype_apply_of_not_mem f h]
theorem ofSubtype_injective : Function.Injective (ofSubtype : Perm (Subtype p) → Perm α) := by
intro x y h
rw [Perm.ext_iff] at h ⊢
intro a
specialize h a
rwa [ofSubtype_apply_coe, ofSubtype_apply_coe, SetCoe.ext_iff] at h
@[simp]
theorem subtypePerm_ofSubtype (f : Perm (Subtype p)) :
subtypePerm (ofSubtype f) (ofSubtype_apply_mem_iff_mem f) = f :=
Equiv.ext fun x => Subtype.coe_injective (ofSubtype_apply_coe f x)
theorem ofSubtype_subtypePerm_of_mem {p : α → Prop} [DecidablePred p]
{g : Perm α} (hg : ∀ (x : α), p (g x) ↔ p x)
{a : α} (ha : p a) : (ofSubtype (g.subtypePerm hg)) a = g a :=
ofSubtype_apply_of_mem (g.subtypePerm hg) ha
theorem ofSubtype_subtypePerm_of_not_mem {p : α → Prop} [DecidablePred p]
{g : Perm α} (hg : ∀ (x : α), p (g x) ↔ p x)
{a : α} (ha : ¬ p a) : (ofSubtype (g.subtypePerm hg)) a = a :=
ofSubtype_apply_of_not_mem (g.subtypePerm hg) ha
/-- Permutations on a subtype are equivalent to permutations on the original type that fix pointwise
the rest. -/
@[simps]
protected def subtypeEquivSubtypePerm (p : α → Prop) [DecidablePred p] :
Perm (Subtype p) ≃ { f : Perm α // ∀ a, ¬p a → f a = a } where
toFun f := ⟨ofSubtype f, fun _ => f.ofSubtype_apply_of_not_mem⟩
invFun f :=
(f : Perm α).subtypePerm fun _ =>
⟨Decidable.not_imp_not.1 fun hfa => (f.prop _ hfa).symm ▸ hfa,
Decidable.not_imp_not.1 fun hfa ha => hfa <| f.val.injective (f.prop _ hfa).symm ▸ ha⟩
left_inv := Equiv.Perm.subtypePerm_ofSubtype
right_inv f :=
Subtype.ext ((Equiv.Perm.ofSubtype_subtypePerm _) fun a => Not.decidable_imp_symm <| f.prop a)
theorem subtypeEquivSubtypePerm_apply_of_mem (f : Perm (Subtype p)) (h : p a) :
(Perm.subtypeEquivSubtypePerm p f).1 a = f ⟨a, h⟩ :=
f.ofSubtype_apply_of_mem h
theorem subtypeEquivSubtypePerm_apply_of_not_mem (f : Perm (Subtype p)) (h : ¬p a) :
((Perm.subtypeEquivSubtypePerm p) f).1 a = a :=
f.ofSubtype_apply_of_not_mem h
end Subtype
end Perm
section Swap
variable [DecidableEq α]
@[simp]
theorem swap_inv (x y : α) : (swap x y)⁻¹ = swap x y :=
rfl
@[simp]
theorem swap_mul_self (i j : α) : swap i j * swap i j = 1 :=
swap_swap i j
theorem swap_mul_eq_mul_swap (f : Perm α) (x y : α) : swap x y * f = f * swap (f⁻¹ x) (f⁻¹ y) :=
Equiv.ext fun z => by
simp only [Perm.mul_apply, swap_apply_def]; split_ifs <;> simp_all [Perm.eq_inv_iff_eq]
theorem mul_swap_eq_swap_mul (f : Perm α) (x y : α) : f * swap x y = swap (f x) (f y) * f := by
simp [swap_mul_eq_mul_swap]
theorem swap_apply_apply (f : Perm α) (x y : α) : swap (f x) (f y) = f * swap x y * f⁻¹ := by
rw [mul_swap_eq_swap_mul, mul_inv_cancel_right]
/-- Left-multiplying a permutation with `swap i j` twice gives the original permutation.
This specialization of `swap_mul_self` is useful when using cosets of permutations.
-/
@[simp]
theorem swap_mul_self_mul (i j : α) (σ : Perm α) : Equiv.swap i j * (Equiv.swap i j * σ) = σ := by
simp [← mul_assoc]
/-- Right-multiplying a permutation with `swap i j` twice gives the original permutation.
This specialization of `swap_mul_self` is useful when using cosets of permutations.
-/
@[simp]
theorem mul_swap_mul_self (i j : α) (σ : Perm α) : σ * Equiv.swap i j * Equiv.swap i j = σ := by
rw [mul_assoc, swap_mul_self, mul_one]
/-- A stronger version of `mul_right_injective` -/
@[simp]
theorem swap_mul_involutive (i j : α) : Function.Involutive (Equiv.swap i j * ·) :=
swap_mul_self_mul i j
/-- A stronger version of `mul_left_injective` -/
@[simp]
theorem mul_swap_involutive (i j : α) : Function.Involutive (· * Equiv.swap i j) :=
mul_swap_mul_self i j
@[simp]
theorem swap_eq_one_iff {i j : α} : swap i j = (1 : Perm α) ↔ i = j :=
swap_eq_refl_iff
theorem swap_mul_eq_iff {i j : α} {σ : Perm α} : swap i j * σ = σ ↔ i = j := by
rw [mul_eq_right, swap_eq_one_iff]
theorem mul_swap_eq_iff {i j : α} {σ : Perm α} : σ * swap i j = σ ↔ i = j := by
rw [mul_eq_left, swap_eq_one_iff]
theorem swap_mul_swap_mul_swap {x y z : α} (hxy : x ≠ y) (hxz : x ≠ z) :
swap y z * swap x y * swap y z = swap z x := by
nth_rewrite 3 [← swap_inv]
rw [← swap_apply_apply, swap_apply_left, swap_apply_of_ne_of_ne hxy hxz, swap_comm]
end Swap
section AddGroup
variable [AddGroup α] (a b : α)
-- we can't use `to_additive`, because it tries to translate `1` into `0`
@[simp] lemma addLeft_zero : Equiv.addLeft (0 : α) = 1 := ext zero_add
@[simp] lemma addRight_zero : Equiv.addRight (0 : α) = 1 := ext add_zero
@[simp] lemma addLeft_add : Equiv.addLeft (a + b) = Equiv.addLeft a * Equiv.addLeft b :=
ext <| add_assoc _ _
@[simp] lemma addRight_add : Equiv.addRight (a + b) = Equiv.addRight b * Equiv.addRight a :=
ext fun _ ↦ (add_assoc _ _ _).symm
@[simp] lemma inv_addLeft : (Equiv.addLeft a)⁻¹ = Equiv.addLeft (-a) := Equiv.coe_inj.1 rfl
@[simp] lemma inv_addRight : (Equiv.addRight a)⁻¹ = Equiv.addRight (-a) := Equiv.coe_inj.1 rfl
@[simp] lemma pow_addLeft (n : ℕ) : Equiv.addLeft a ^ n = Equiv.addLeft (n • a) := by
ext; simp [Perm.coe_pow]
@[simp] lemma pow_addRight (n : ℕ) : Equiv.addRight a ^ n = Equiv.addRight (n • a) := by
ext; simp [Perm.coe_pow]
@[simp] lemma zpow_addLeft (n : ℤ) : Equiv.addLeft a ^ n = Equiv.addLeft (n • a) :=
(map_zsmul ({ toFun := Equiv.addLeft, map_zero' := addLeft_zero, map_add' := addLeft_add } :
α →+ Additive (Perm α)) _ _).symm
@[simp] lemma zpow_addRight : ∀ (n : ℤ), Equiv.addRight a ^ n = Equiv.addRight (n • a)
| Int.ofNat n => by simp
| Int.negSucc n => by simp
end AddGroup
section Group
variable [Group α] (a b : α)
@[simp] lemma mulLeft_one : Equiv.mulLeft (1 : α) = 1 := ext one_mul
@[simp] lemma mulRight_one : Equiv.mulRight (1 : α) = 1 := ext mul_one
@[simp] lemma mulLeft_mul : Equiv.mulLeft (a * b) = Equiv.mulLeft a * Equiv.mulLeft b :=
ext <| mul_assoc _ _
@[simp] lemma mulRight_mul : Equiv.mulRight (a * b) = Equiv.mulRight b * Equiv.mulRight a :=
ext fun _ ↦ (mul_assoc _ _ _).symm
@[simp] lemma inv_mulLeft : (Equiv.mulLeft a)⁻¹ = Equiv.mulLeft a⁻¹ := Equiv.coe_inj.1 rfl
@[simp] lemma inv_mulRight : (Equiv.mulRight a)⁻¹ = Equiv.mulRight a⁻¹ := Equiv.coe_inj.1 rfl
@[simp] lemma pow_mulLeft (n : ℕ) : Equiv.mulLeft a ^ n = Equiv.mulLeft (a ^ n) := by
ext; simp [Perm.coe_pow]
@[simp] lemma pow_mulRight (n : ℕ) : Equiv.mulRight a ^ n = Equiv.mulRight (a ^ n) := by
ext; simp [Perm.coe_pow]
@[simp] lemma zpow_mulLeft (n : ℤ) : Equiv.mulLeft a ^ n = Equiv.mulLeft (a ^ n) :=
(map_zpow ({ toFun := Equiv.mulLeft, map_one' := mulLeft_one, map_mul' := mulLeft_mul } :
α →* Perm α) _ _).symm
@[simp] lemma zpow_mulRight : ∀ n : ℤ, Equiv.mulRight a ^ n = Equiv.mulRight (a ^ n)
| Int.ofNat n => by simp
| Int.negSucc n => by simp
end Group
end Equiv
/-- The group of multiplicative automorphisms. -/
@[reducible, to_additive /-- The group of additive automorphisms. -/]
def MulAut (M : Type*) [Mul M] :=
M ≃* M
-- Note that `(attr := reducible)` in `to_additive` currently doesn't work,
-- so we add the reducible attribute manually.
attribute [reducible] AddAut
namespace MulAut
variable (M) [Mul M]
/-- The group operation on multiplicative automorphisms is defined by `g h => MulEquiv.trans h g`.
This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`.
-/
instance : Group (MulAut M) where
mul g h := MulEquiv.trans h g
one := MulEquiv.refl _
inv := MulEquiv.symm
mul_assoc _ _ _ := rfl
one_mul _ := rfl
mul_one _ := rfl
inv_mul_cancel := MulEquiv.self_trans_symm
instance : Inhabited (MulAut M) :=
⟨1⟩
@[simp]
theorem coe_mul (e₁ e₂ : MulAut M) : ⇑(e₁ * e₂) = e₁ ∘ e₂ :=
rfl
@[simp]
theorem coe_one : ⇑(1 : MulAut M) = id :=
rfl
@[simp]
theorem coe_inv (e : MulAut M) : ⇑e⁻¹ = e.symm := rfl
theorem mul_def (e₁ e₂ : MulAut M) : e₁ * e₂ = e₂.trans e₁ :=
rfl
theorem one_def : (1 : MulAut M) = MulEquiv.refl _ :=
rfl
theorem inv_def (e₁ : MulAut M) : e₁⁻¹ = e₁.symm :=
rfl
@[simp]
theorem inv_symm (e : MulAut M) : e⁻¹.symm = e := rfl
@[simp]
theorem symm_inv (e : MulAut M) : (e.symm)⁻¹ = e := rfl
@[simp]
theorem inv_apply (e : MulAut M) (m : M) : e⁻¹ m = e.symm m := by
rw [inv_def]
@[simp]
theorem mul_apply (e₁ e₂ : MulAut M) (m : M) : (e₁ * e₂) m = e₁ (e₂ m) :=
rfl
@[simp]
theorem one_apply (m : M) : (1 : MulAut M) m = m :=
rfl
theorem apply_inv_self (e : MulAut M) (m : M) : e (e⁻¹ m) = m :=
MulEquiv.apply_symm_apply _ _
theorem inv_apply_self (e : MulAut M) (m : M) : e⁻¹ (e m) = m :=
MulEquiv.apply_symm_apply _ _
/-- Monoid hom from the group of multiplicative automorphisms to the group of permutations. -/
def toPerm : MulAut M →* Equiv.Perm M where
toFun := MulEquiv.toEquiv
map_one' := rfl
map_mul' _ _ := rfl
/-- Group conjugation, `MulAut.conj g h = g * h * g⁻¹`, as a monoid homomorphism
mapping multiplication in `G` into multiplication in the automorphism group `MulAut G`.
See also the type `ConjAct G` for any group `G`, which has a `MulAction (ConjAct G) G` instance
where `conj G` acts on `G` by conjugation. -/
def conj [Group G] : G →* MulAut G where
toFun g :=
{ toFun := fun h => g * h * g⁻¹
invFun := fun h => g⁻¹ * h * g
left_inv := fun _ => by simp only [mul_assoc, inv_mul_cancel_left, inv_mul_cancel, mul_one]
right_inv := fun _ => by simp only [mul_assoc, mul_inv_cancel_left, mul_inv_cancel, mul_one]
map_mul' := by simp only [mul_assoc, inv_mul_cancel_left, forall_const] }
map_mul' g₁ g₂ := by
ext h
change g₁ * g₂ * h * (g₁ * g₂)⁻¹ = g₁ * (g₂ * h * g₂⁻¹) * g₁⁻¹
simp only [mul_assoc, mul_inv_rev]
map_one' := by ext; simp only [one_mul, inv_one, mul_one, one_apply]; rfl
@[simp]
theorem conj_apply [Group G] (g h : G) : conj g h = g * h * g⁻¹ :=
rfl
@[simp]
theorem conj_symm_apply [Group G] (g h : G) : (conj g).symm h = g⁻¹ * h * g :=
rfl
theorem conj_inv_apply [Group G] (g h : G) : (conj g)⁻¹ h = g⁻¹ * h * g :=
rfl
/-- Isomorphic groups have isomorphic automorphism groups. -/
@[simps]
def congr [Group G] {H : Type*} [Group H] (ϕ : G ≃* H) :
MulAut G ≃* MulAut H where
toFun f := ϕ.symm.trans (f.trans ϕ)
invFun f := ϕ.trans (f.trans ϕ.symm)
left_inv _ := by simp [DFunLike.ext_iff]
right_inv _ := by simp [DFunLike.ext_iff]
map_mul' := by simp [DFunLike.ext_iff]
end MulAut
namespace AddAut
variable (A) [Add A]
/-- The group operation on additive automorphisms is defined by `g h => AddEquiv.trans h g`.
This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`.
-/
instance group : Group (AddAut A) where
mul g h := AddEquiv.trans h g
one := AddEquiv.refl _
inv := AddEquiv.symm
mul_assoc _ _ _ := rfl
one_mul _ := rfl
mul_one _ := rfl
inv_mul_cancel := AddEquiv.self_trans_symm
attribute [to_additive AddAut.instGroup] MulAut.instGroup
instance : Inhabited (AddAut A) :=
⟨1⟩
@[simp]
theorem coe_mul (e₁ e₂ : AddAut A) : ⇑(e₁ * e₂) = e₁ ∘ e₂ :=
rfl
@[simp]
theorem coe_one : ⇑(1 : AddAut A) = id :=
rfl
@[simp]
theorem coe_inv (e : AddAut A) : ⇑e⁻¹ = e.symm := rfl
theorem mul_def (e₁ e₂ : AddAut A) : e₁ * e₂ = e₂.trans e₁ :=
rfl
theorem one_def : (1 : AddAut A) = AddEquiv.refl _ :=
rfl
theorem inv_def (e₁ : AddAut A) : e₁⁻¹ = e₁.symm :=
rfl
@[simp]
theorem mul_apply (e₁ e₂ : AddAut A) (a : A) : (e₁ * e₂) a = e₁ (e₂ a) :=
rfl
@[simp]
theorem one_apply (a : A) : (1 : AddAut A) a = a :=
rfl
@[simp]
theorem inv_symm (e : AddAut A) : e⁻¹.symm = e := rfl
@[simp]
theorem symm_inv (e : AddAut A) : e.symm⁻¹ = e := rfl
@[simp]
theorem inv_apply (e : AddAut A) (a : A) : e⁻¹ a = e.symm a := rfl
theorem apply_inv_self (e : AddAut A) (a : A) : e⁻¹ (e a) = a :=
AddEquiv.apply_symm_apply _ _
theorem inv_apply_self (e : AddAut A) (a : A) : e (e⁻¹ a) = a :=
AddEquiv.apply_symm_apply _ _
/-- Monoid hom from the group of multiplicative automorphisms to the group of permutations. -/
def toPerm : AddAut A →* Equiv.Perm A where
toFun := AddEquiv.toEquiv
map_one' := rfl
map_mul' _ _ := rfl
/-- Additive group conjugation, `AddAut.conj g h = g + h - g`, as an additive monoid
homomorphism mapping addition in `G` into multiplication in the automorphism group `AddAut G`
(written additively in order to define the map). -/
def conj [AddGroup G] : G →+ Additive (AddAut G) where
toFun g :=
@Additive.ofMul (AddAut G)
{ toFun := fun h => g + h + -g
-- this definition is chosen to match `MulAut.conj`
invFun := fun h => -g + h + g
left_inv := fun _ => by
simp only [add_assoc, neg_add_cancel_left, neg_add_cancel, add_zero]
right_inv := fun _ => by
simp only [add_assoc, add_neg_cancel_left, add_neg_cancel, add_zero]
map_add' := by simp only [add_assoc, neg_add_cancel_left, forall_const] }
map_add' g₁ g₂ := by
apply Additive.toMul.injective; ext h
change g₁ + g₂ + h + -(g₁ + g₂) = g₁ + (g₂ + h + -g₂) + -g₁
simp only [add_assoc, neg_add_rev]
map_zero' := by
apply Additive.toMul.injective; ext
simp only [zero_add, neg_zero, add_zero, toMul_ofMul, toMul_zero, one_apply]
rfl
@[simp]
theorem conj_apply [AddGroup G] (g h : G) : (conj g).toMul h = g + h + -g :=
rfl
@[simp]
theorem conj_symm_apply [AddGroup G] (g h : G) : (conj g).toMul.symm h = -g + h + g :=
rfl
theorem conj_inv_apply [AddGroup G] (g h : G) : (conj g).toMul⁻¹ h = -g + h + g :=
rfl
theorem neg_conj_apply [AddGroup G] (g h : G) : (-conj g).toMul h = -g + h + g := by
simp
/-- Isomorphic additive groups have isomorphic automorphism groups. -/
@[simps]
def congr [AddGroup G] {H : Type*} [AddGroup H] (ϕ : G ≃+ H) :
AddAut G ≃* AddAut H where
toFun f := ϕ.symm.trans (f.trans ϕ)
invFun f := ϕ.trans (f.trans ϕ.symm)
left_inv _ := by simp [DFunLike.ext_iff]
right_inv _ := by simp [DFunLike.ext_iff]
map_mul' := by simp [DFunLike.ext_iff]
end AddAut
variable (G)
/-- `Multiplicative G` and `G` have isomorphic automorphism groups. -/
@[simps!]
def MulAutMultiplicative [AddGroup G] : MulAut (Multiplicative G) ≃* AddAut G :=
{ AddEquiv.toMultiplicative.symm with map_mul' := fun _ _ ↦ rfl }
/-- `Additive G` and `G` have isomorphic automorphism groups. -/
@[simps!]
def AddAutAdditive [Group G] : AddAut (Additive G) ≃* MulAut G :=
{ MulEquiv.toAdditive.symm with map_mul' := fun _ _ ↦ rfl } |
.lake/packages/mathlib/Mathlib/Algebra/Group/Conj.lean | import Mathlib.Algebra.Group.End
import Mathlib.Algebra.Group.Semiconj.Units
/-!
# Conjugacy of group elements
See also `MulAut.conj` and `Quandle.conj`.
-/
assert_not_exists MonoidWithZero Multiset MulAction
universe u v
variable {α : Type u} {β : Type v}
section Monoid
variable [Monoid α] [Monoid β]
/-- We say that `a` is conjugate to `b` if for some unit `c` we have `c * a * c⁻¹ = b`. -/
def IsConj (a b : α) :=
∃ c : αˣ, SemiconjBy (↑c) a b
@[refl]
theorem IsConj.refl (a : α) : IsConj a a :=
⟨1, SemiconjBy.one_left a⟩
@[symm]
theorem IsConj.symm {a b : α} : IsConj a b → IsConj b a
| ⟨c, hc⟩ => ⟨c⁻¹, hc.units_inv_symm_left⟩
theorem isConj_comm {g h : α} : IsConj g h ↔ IsConj h g :=
⟨IsConj.symm, IsConj.symm⟩
@[trans]
theorem IsConj.trans {a b c : α} : IsConj a b → IsConj b c → IsConj a c
| ⟨c₁, hc₁⟩, ⟨c₂, hc₂⟩ => ⟨c₂ * c₁, hc₂.mul_left hc₁⟩
theorem IsConj.pow {a b : α} (n : ℕ) : IsConj a b → IsConj (a ^ n) (b ^ n)
| ⟨c, hc⟩ => ⟨c, hc.pow_right n⟩
@[simp]
theorem isConj_iff_eq {α : Type*} [CommMonoid α] {a b : α} : IsConj a b ↔ a = b :=
⟨fun ⟨c, hc⟩ => by
rw [SemiconjBy, mul_comm, ← Units.mul_inv_eq_iff_eq_mul, mul_assoc, c.mul_inv, mul_one] at hc
exact hc, fun h => by rw [h]⟩
protected theorem MonoidHom.map_isConj (f : α →* β) {a b : α} : IsConj a b → IsConj (f a) (f b)
| ⟨c, hc⟩ => ⟨Units.map f c, by rw [Units.coe_map, SemiconjBy, ← f.map_mul, hc.eq, f.map_mul]⟩
@[simp]
theorem isConj_one_right {a : α} : IsConj 1 a ↔ a = 1 := by
refine ⟨fun ⟨c, h⟩ => ?_, fun h => by rw [h]⟩
rw [SemiconjBy, mul_one] at h
exact c.isUnit.mul_eq_right.mp h.symm
@[simp]
theorem isConj_one_left {a : α} : IsConj a 1 ↔ a = 1 :=
calc
IsConj a 1 ↔ IsConj 1 a := ⟨IsConj.symm, IsConj.symm⟩
_ ↔ a = 1 := isConj_one_right
end Monoid
section Group
variable [Group α]
@[simp]
theorem isConj_iff {a b : α} : IsConj a b ↔ ∃ c : α, c * a * c⁻¹ = b :=
⟨fun ⟨c, hc⟩ => ⟨c, mul_inv_eq_iff_eq_mul.2 hc⟩, fun ⟨c, hc⟩ =>
⟨⟨c, c⁻¹, mul_inv_cancel c, inv_mul_cancel c⟩, mul_inv_eq_iff_eq_mul.1 hc⟩⟩
theorem conj_inv {a b : α} : (b * a * b⁻¹)⁻¹ = b * a⁻¹ * b⁻¹ :=
(map_inv (MulAut.conj b) a).symm
@[simp]
theorem conj_mul {a b c : α} : b * a * b⁻¹ * (b * c * b⁻¹) = b * (a * c) * b⁻¹ :=
(map_mul (MulAut.conj b) a c).symm
@[simp]
theorem conj_pow {i : ℕ} {a b : α} : (a * b * a⁻¹) ^ i = a * b ^ i * a⁻¹ := by
induction i with
| zero => simp
| succ i hi => simp [pow_succ, hi]
@[simp]
theorem conj_zpow {i : ℤ} {a b : α} : (a * b * a⁻¹) ^ i = a * b ^ i * a⁻¹ := by
cases i
· simp
· simp only [zpow_negSucc, conj_pow, mul_inv_rev, inv_inv]
rw [mul_assoc]
theorem conj_injective {x : α} : Function.Injective fun g : α => x * g * x⁻¹ :=
(MulAut.conj x).injective
end Group
namespace IsConj
/- This small quotient API is largely copied from the API of `Associates`;
where possible, try to keep them in sync -/
/-- The setoid of the relation `IsConj` iff there is a unit `u` such that `u * x = y * u` -/
protected def setoid (α : Type*) [Monoid α] : Setoid α where
r := IsConj
iseqv := ⟨IsConj.refl, IsConj.symm, IsConj.trans⟩
end IsConj
attribute [local instance] IsConj.setoid
/-- The quotient type of conjugacy classes of a group. -/
def ConjClasses (α : Type*) [Monoid α] : Type _ :=
Quotient (IsConj.setoid α)
namespace ConjClasses
section Monoid
variable [Monoid α] [Monoid β]
/-- The canonical quotient map from a monoid `α` into the `ConjClasses` of `α` -/
protected def mk {α : Type*} [Monoid α] (a : α) : ConjClasses α := ⟦a⟧
instance : Inhabited (ConjClasses α) := ⟨⟦1⟧⟩
theorem mk_eq_mk_iff_isConj {a b : α} : ConjClasses.mk a = ConjClasses.mk b ↔ IsConj a b :=
Iff.intro Quotient.exact Quot.sound
theorem quotient_mk_eq_mk (a : α) : ⟦a⟧ = ConjClasses.mk a :=
rfl
theorem quot_mk_eq_mk (a : α) : Quot.mk Setoid.r a = ConjClasses.mk a :=
rfl
theorem forall_isConj {p : ConjClasses α → Prop} : (∀ a, p a) ↔ ∀ a, p (ConjClasses.mk a) :=
Iff.intro (fun h _ => h _) fun h a => Quotient.inductionOn a h
theorem mk_surjective : Function.Surjective (@ConjClasses.mk α _) :=
forall_isConj.2 fun a => ⟨a, rfl⟩
instance : One (ConjClasses α) :=
⟨⟦1⟧⟩
theorem one_eq_mk_one : (1 : ConjClasses α) = ConjClasses.mk 1 :=
rfl
theorem exists_rep (a : ConjClasses α) : ∃ a0 : α, ConjClasses.mk a0 = a :=
Quot.exists_rep a
/-- A `MonoidHom` maps conjugacy classes of one group to conjugacy classes of another. -/
def map (f : α →* β) : ConjClasses α → ConjClasses β :=
Quotient.lift (ConjClasses.mk ∘ f) fun _ _ ab => mk_eq_mk_iff_isConj.2 (f.map_isConj ab)
theorem map_surjective {f : α →* β} (hf : Function.Surjective f) :
Function.Surjective (ConjClasses.map f) := by
intro b
obtain ⟨b, rfl⟩ := ConjClasses.mk_surjective b
obtain ⟨a, rfl⟩ := hf b
exact ⟨ConjClasses.mk a, rfl⟩
library_note2 «slow-failing instance priority» /--
Certain instances trigger further searches when they are considered as candidate instances;
these instances should be assigned a priority lower than the default of 1000 (for example, 900).
The conditions for this rule are as follows:
* a class `C` has instances `instT : C T` and `instT' : C T'`
* types `T` and `T'` are both reducible specializations of another type `S`
* the parameters supplied to `S` to produce `T` are not (fully) determined by `instT`,
instead they have to be found by instance search
If those conditions hold, the instance `instT` should be assigned lower priority.
Note that there is no issue unless `T` and `T'` are reducibly equal to `S`, Otherwise the instance
discrimination tree can distinguish them, and the note does not apply.
If the type involved is a free variable (rather than an instantiation of some type `S`),
the instance priority should be even lower, see Note [lower instance priority].
-/
instance [DecidableRel (IsConj : α → α → Prop)] : DecidableEq (ConjClasses α) :=
inferInstanceAs <| DecidableEq <| Quotient (IsConj.setoid α)
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem mk_injective : Function.Injective (@ConjClasses.mk α _) := fun _ _ =>
(mk_eq_mk_iff_isConj.trans isConj_iff_eq).1
theorem mk_bijective : Function.Bijective (@ConjClasses.mk α _) :=
⟨mk_injective, mk_surjective⟩
/-- The bijection between a `CommGroup` and its `ConjClasses`. -/
def mkEquiv : α ≃ ConjClasses α :=
⟨ConjClasses.mk, Quotient.lift id fun (_ : α) _ => isConj_iff_eq.1, Quotient.lift_mk _ _, by
rw [Function.RightInverse, Function.LeftInverse, forall_isConj]
solve_by_elim⟩
end CommMonoid
end ConjClasses
section Monoid
variable [Monoid α]
/-- Given an element `a`, `conjugatesOf a` is the set of conjugates. -/
def conjugatesOf (a : α) : Set α :=
{ b | IsConj a b }
theorem mem_conjugatesOf_self {a : α} : a ∈ conjugatesOf a :=
IsConj.refl _
theorem IsConj.conjugatesOf_eq {a b : α} (ab : IsConj a b) : conjugatesOf a = conjugatesOf b :=
Set.ext fun _ => ⟨fun ag => ab.symm.trans ag, fun bg => ab.trans bg⟩
theorem isConj_iff_conjugatesOf_eq {a b : α} : IsConj a b ↔ conjugatesOf a = conjugatesOf b :=
⟨IsConj.conjugatesOf_eq, fun h => by
have ha := mem_conjugatesOf_self (a := b)
rwa [← h] at ha⟩
end Monoid
namespace ConjClasses
variable [Monoid α]
attribute [local instance] IsConj.setoid
/-- Given a conjugacy class `a`, `carrier a` is the set it represents. -/
def carrier : ConjClasses α → Set α :=
Quotient.lift conjugatesOf fun (_ : α) _ ab => IsConj.conjugatesOf_eq ab
theorem mem_carrier_mk {a : α} : a ∈ carrier (ConjClasses.mk a) :=
IsConj.refl _
theorem mem_carrier_iff_mk_eq {a : α} {b : ConjClasses α} :
a ∈ carrier b ↔ ConjClasses.mk a = b := by
revert b
rw [forall_isConj]
intro b
rw [carrier, eq_comm, mk_eq_mk_iff_isConj, ← quotient_mk_eq_mk, Quotient.lift_mk]
rfl
theorem carrier_eq_preimage_mk {a : ConjClasses α} : a.carrier = ConjClasses.mk ⁻¹' {a} :=
Set.ext fun _ => mem_carrier_iff_mk_eq
end ConjClasses |
.lake/packages/mathlib/Mathlib/Algebra/Group/Ext.lean | import Mathlib.Algebra.Group.Hom.Defs
/-!
# Extensionality lemmas for monoid and group structures
In this file we prove extensionality lemmas for `Monoid` and higher algebraic structures with one
binary operation. Extensionality lemmas for structures that are lower in the hierarchy can be found
in `Algebra.Group.Defs`.
## Implementation details
To get equality of `npow` etc, we define a monoid homomorphism between two monoid structures on the
same type, then apply lemmas like `MonoidHom.map_div`, `MonoidHom.map_pow` etc.
To refer to the `*` operator of a particular instance `i`, we use
`(letI := i; HMul.hMul : M → M → M)` instead of `i.mul` (which elaborates to `Mul.mul`), as the
former uses `HMul.hMul` which is the canonical spelling.
## Tags
monoid, group, extensionality
-/
assert_not_exists MonoidWithZero DenselyOrdered
open Function
universe u
@[to_additive (attr := ext)]
theorem Monoid.ext {M : Type u} ⦃m₁ m₂ : Monoid M⦄
(h_mul : (letI := m₁; HMul.hMul : M → M → M) = (letI := m₂; HMul.hMul : M → M → M)) :
m₁ = m₂ := by
have : m₁.toMulOneClass = m₂.toMulOneClass := MulOneClass.ext h_mul
have h₁ : m₁.one = m₂.one := congr_arg (·.one) this
let f : @MonoidHom M M m₁.toMulOne m₂.toMulOne :=
@MonoidHom.mk _ _ (_) _ (@OneHom.mk _ _ (_) _ id h₁)
(fun x y => congr_fun (congr_fun h_mul x) y)
have : m₁.npow = m₂.npow := by
ext n x
exact @MonoidHom.map_pow M M m₁ m₂ f x n
rcases m₁ with @⟨@⟨⟨_⟩⟩, ⟨_⟩⟩
congr
@[to_additive]
theorem CommMonoid.toMonoid_injective {M : Type u} :
Function.Injective (@CommMonoid.toMonoid M) := by
rintro ⟨⟩ ⟨⟩ h
congr
@[to_additive (attr := ext)]
theorem CommMonoid.ext {M : Type*} ⦃m₁ m₂ : CommMonoid M⦄
(h_mul : (letI := m₁; HMul.hMul : M → M → M) = (letI := m₂; HMul.hMul : M → M → M)) : m₁ = m₂ :=
CommMonoid.toMonoid_injective <| Monoid.ext h_mul
@[to_additive]
theorem LeftCancelMonoid.toMonoid_injective {M : Type u} :
Function.Injective (@LeftCancelMonoid.toMonoid M) := by
rintro @⟨@⟨⟩⟩ @⟨@⟨⟩⟩ h
congr <;> injection h
@[to_additive (attr := ext)]
theorem LeftCancelMonoid.ext {M : Type u} ⦃m₁ m₂ : LeftCancelMonoid M⦄
(h_mul : (letI := m₁; HMul.hMul : M → M → M) = (letI := m₂; HMul.hMul : M → M → M)) :
m₁ = m₂ :=
LeftCancelMonoid.toMonoid_injective <| Monoid.ext h_mul
@[to_additive]
theorem RightCancelMonoid.toMonoid_injective {M : Type u} :
Function.Injective (@RightCancelMonoid.toMonoid M) := by
rintro @⟨@⟨⟩⟩ @⟨@⟨⟩⟩ h
congr <;> injection h
@[to_additive (attr := ext)]
theorem RightCancelMonoid.ext {M : Type u} ⦃m₁ m₂ : RightCancelMonoid M⦄
(h_mul : (letI := m₁; HMul.hMul : M → M → M) = (letI := m₂; HMul.hMul : M → M → M)) :
m₁ = m₂ :=
RightCancelMonoid.toMonoid_injective <| Monoid.ext h_mul
@[to_additive]
theorem CancelMonoid.toLeftCancelMonoid_injective {M : Type u} :
Function.Injective (@CancelMonoid.toLeftCancelMonoid M) := by
rintro ⟨⟩ ⟨⟩ h
congr
@[to_additive (attr := ext)]
theorem CancelMonoid.ext {M : Type*} ⦃m₁ m₂ : CancelMonoid M⦄
(h_mul : (letI := m₁; HMul.hMul : M → M → M) = (letI := m₂; HMul.hMul : M → M → M)) :
m₁ = m₂ :=
CancelMonoid.toLeftCancelMonoid_injective <| LeftCancelMonoid.ext h_mul
@[to_additive]
theorem CancelCommMonoid.toCommMonoid_injective {M : Type u} :
Function.Injective (@CancelCommMonoid.toCommMonoid M) := by
rintro @⟨@⟨@⟨⟩⟩⟩ @⟨@⟨@⟨⟩⟩⟩ h
grind
@[to_additive (attr := ext)]
theorem CancelCommMonoid.ext {M : Type*} ⦃m₁ m₂ : CancelCommMonoid M⦄
(h_mul : (letI := m₁; HMul.hMul : M → M → M) = (letI := m₂; HMul.hMul : M → M → M)) :
m₁ = m₂ :=
CancelCommMonoid.toCommMonoid_injective <| CommMonoid.ext h_mul
@[to_additive (attr := ext)]
theorem DivInvMonoid.ext {M : Type*} ⦃m₁ m₂ : DivInvMonoid M⦄
(h_mul : (letI := m₁; HMul.hMul : M → M → M) = (letI := m₂; HMul.hMul : M → M → M))
(h_inv : (letI := m₁; Inv.inv : M → M) = (letI := m₂; Inv.inv : M → M)) : m₁ = m₂ := by
have h_mon := Monoid.ext h_mul
have h₁ : m₁.one = m₂.one := congr_arg (·.one) h_mon
let f : @MonoidHom M M m₁.toMulOne m₂.toMulOne :=
@MonoidHom.mk _ _ (_) _ (@OneHom.mk _ _ (_) _ id h₁)
(fun x y => congr_fun (congr_fun h_mul x) y)
have : m₁.zpow = m₂.zpow := by
ext m x
exact @MonoidHom.map_zpow' M M m₁ m₂ f (congr_fun h_inv) x m
have : m₁.div = m₂.div := by
ext a b
exact @map_div' _ _
(F := @MonoidHom _ _ (_) _) _ (id _) _ inferInstance f (congr_fun h_inv) a b
rcases m₁ with @⟨_, ⟨_⟩, ⟨_⟩⟩
congr
@[to_additive]
lemma Group.toDivInvMonoid_injective {G : Type*} : Injective (@Group.toDivInvMonoid G) := by
rintro ⟨⟩ ⟨⟩ ⟨⟩; rfl
@[to_additive (attr := ext)]
theorem Group.ext {G : Type*} ⦃g₁ g₂ : Group G⦄
(h_mul : (letI := g₁; HMul.hMul : G → G → G) = (letI := g₂; HMul.hMul : G → G → G)) :
g₁ = g₂ := by
have h₁ : g₁.one = g₂.one := congr_arg (·.one) (Monoid.ext h_mul)
let f : @MonoidHom G G g₁.toMulOne g₂.toMulOne :=
@MonoidHom.mk _ _ (_) _ (@OneHom.mk _ _ (_) _ id h₁)
(fun x y => congr_fun (congr_fun h_mul x) y)
exact
Group.toDivInvMonoid_injective
(DivInvMonoid.ext h_mul
(funext <| @MonoidHom.map_inv G G g₁ g₂.toDivisionMonoid f))
@[to_additive]
lemma CommGroup.toGroup_injective {G : Type*} : Injective (@CommGroup.toGroup G) := by
rintro ⟨⟩ ⟨⟩ ⟨⟩; rfl
@[to_additive (attr := ext)]
theorem CommGroup.ext {G : Type*} ⦃g₁ g₂ : CommGroup G⦄
(h_mul : (letI := g₁; HMul.hMul : G → G → G) = (letI := g₂; HMul.hMul : G → G → G)) : g₁ = g₂ :=
CommGroup.toGroup_injective <| Group.ext h_mul |
.lake/packages/mathlib/Mathlib/Algebra/Group/InjSurj.lean | import Mathlib.Algebra.Group.Defs
import Mathlib.Logic.Function.Basic
import Mathlib.Tactic.Spread
/-!
# Lifting algebraic data classes along injective/surjective maps
This file provides definitions that are meant to deal with
situations such as the following:
Suppose that `G` is a group, and `H` is a type endowed with
`One H`, `Mul H`, and `Inv H`.
Suppose furthermore, that `f : G → H` is a surjective map
that respects the multiplication, and the unit elements.
Then `H` satisfies the group axioms.
The relevant definition in this case is `Function.Surjective.group`.
Dually, there is also `Function.Injective.group`.
And there are versions for (additive) (commutative) semigroups/monoids.
Note that the `nsmul` and `zsmul` hypotheses in the declarations in this file are declared as
`∀ x n, f (n • x) = n • f x`, with the binders in a slightly unnatural order, as they are
`to_additive`ized from the versions for `^`.
-/
namespace Function
/-!
### Injective
-/
assert_not_exists MonoidWithZero DenselyOrdered AddMonoidWithOne
namespace Injective
variable {M₁ : Type*} {M₂ : Type*} [Mul M₁]
/-- A type endowed with `*` is a semigroup, if it admits an injective map that preserves `*` to
a semigroup. See note [reducible non-instances]. -/
@[to_additive /-- A type endowed with `+` is an additive semigroup, if it admits an
injective map that preserves `+` to an additive semigroup. -/]
protected abbrev semigroup [Semigroup M₂] (f : M₁ → M₂) (hf : Injective f)
(mul : ∀ x y, f (x * y) = f x * f y) : Semigroup M₁ :=
{ ‹Mul M₁› with mul_assoc := fun x y z => hf <| by rw [mul, mul, mul, mul, mul_assoc] }
/-- A type endowed with `*` is a commutative magma, if it admits a surjective map that preserves
`*` from a commutative magma. -/
@[to_additive -- See note [reducible non-instances]
/-- A type endowed with `+` is an additive commutative semigroup, if it admits
a surjective map that preserves `+` from an additive commutative semigroup. -/]
protected abbrev commMagma [CommMagma M₂] (f : M₁ → M₂) (hf : Injective f)
(mul : ∀ x y, f (x * y) = f x * f y) : CommMagma M₁ where
mul_comm x y := hf <| by rw [mul, mul, mul_comm]
/-- A type endowed with `*` is a commutative semigroup, if it admits an injective map that
preserves `*` to a commutative semigroup. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `+` is an additive commutative semigroup,if it admits
an injective map that preserves `+` to an additive commutative semigroup. -/]
protected abbrev commSemigroup [CommSemigroup M₂] (f : M₁ → M₂) (hf : Injective f)
(mul : ∀ x y, f (x * y) = f x * f y) : CommSemigroup M₁ where
toSemigroup := hf.semigroup f mul
__ := hf.commMagma f mul
/-- A type has left-cancellative multiplication, if it admits an injective map that
preserves `*` to another type with left-cancellative multiplication. -/
@[to_additive /-- A type has left-cancellative addition, if it admits an injective map that
preserves `+` to another type with left-cancellative addition. -/]
protected theorem isLeftCancelMul [Mul M₂] [IsLeftCancelMul M₂] (f : M₁ → M₂) (hf : Injective f)
(mul : ∀ x y, f (x * y) = f x * f y) : IsLeftCancelMul M₁ where
mul_left_cancel x y z H := hf <| mul_left_cancel <| by simpa only [mul] using congrArg f H
/-- A type has right-cancellative multiplication, if it admits an injective map that
preserves `*` to another type with right-cancellative multiplication. -/
@[to_additive /-- A type has right-cancellative addition, if it admits an injective map that
preserves `+` to another type with right-cancellative addition. -/]
protected theorem isRightCancelMul [Mul M₂] [IsRightCancelMul M₂] (f : M₁ → M₂) (hf : Injective f)
(mul : ∀ x y, f (x * y) = f x * f y) : IsRightCancelMul M₁ where
mul_right_cancel x y z H := hf <| mul_right_cancel <| by simpa only [mul] using congrArg f H
/-- A type has cancellative multiplication, if it admits an injective map that
preserves `*` to another type with cancellative multiplication. -/
@[to_additive /-- A type has cancellative addition, if it admits an injective map that
preserves `+` to another type with cancellative addition. -/]
protected theorem isCancelMul [Mul M₂] [IsCancelMul M₂] (f : M₁ → M₂) (hf : Injective f)
(mul : ∀ x y, f (x * y) = f x * f y) : IsCancelMul M₁ where
__ := hf.isLeftCancelMul f mul
__ := hf.isRightCancelMul f mul
/-- A type endowed with `*` is a left cancel semigroup, if it admits an injective map that
preserves `*` to a left cancel semigroup. See note [reducible non-instances]. -/
@[to_additive /-- A type endowed with `+` is an additive left cancel semigroup, if it admits an
injective map that preserves `+` to an additive left cancel semigroup. -/]
protected abbrev leftCancelSemigroup [LeftCancelSemigroup M₂] (f : M₁ → M₂) (hf : Injective f)
(mul : ∀ x y, f (x * y) = f x * f y) : LeftCancelSemigroup M₁ :=
{ hf.semigroup f mul, hf.isLeftCancelMul f mul with }
/-- A type endowed with `*` is a right cancel semigroup, if it admits an injective map that
preserves `*` to a right cancel semigroup. See note [reducible non-instances]. -/
@[to_additive /-- A type endowed with `+` is an additive right
cancel semigroup, if it admits an injective map that preserves `+` to an additive right cancel
semigroup. -/]
protected abbrev rightCancelSemigroup [RightCancelSemigroup M₂] (f : M₁ → M₂) (hf : Injective f)
(mul : ∀ x y, f (x * y) = f x * f y) : RightCancelSemigroup M₁ :=
{ hf.semigroup f mul, hf.isRightCancelMul f mul with }
variable [One M₁]
/-- A type endowed with `1` and `*` is a `MulOneClass`, if it admits an injective map that
preserves `1` and `*` to a `MulOneClass`. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an `AddZeroClass`, if it admits an
injective map that preserves `0` and `+` to an `AddZeroClass`. -/]
protected abbrev mulOneClass [MulOneClass M₂] (f : M₁ → M₂) (hf : Injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) : MulOneClass M₁ :=
{ ‹One M₁›, ‹Mul M₁› with
one_mul := fun x => hf <| by rw [mul, one, one_mul],
mul_one := fun x => hf <| by rw [mul, one, mul_one] }
variable [Pow M₁ ℕ]
/-- A type endowed with `1` and `*` is a monoid, if it admits an injective map that preserves `1`
and `*` to a monoid. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an additive monoid, if it admits an
injective map that preserves `0` and `+` to an additive monoid. See note
[reducible non-instances]. -/]
protected abbrev monoid [Monoid M₂] (f : M₁ → M₂) (hf : Injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : Monoid M₁ :=
{ hf.mulOneClass f one mul, hf.semigroup f mul with
npow := fun n x => x ^ n,
npow_zero := fun x => hf <| by rw [npow, one, pow_zero],
npow_succ := fun n x => hf <| by rw [npow, pow_succ, mul, npow] }
/-- A type endowed with `1` and `*` is a left cancel monoid, if it admits an injective map that
preserves `1` and `*` to a left cancel monoid. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an additive left cancel monoid, if it
admits an injective map that preserves `0` and `+` to an additive left cancel monoid. -/]
protected abbrev leftCancelMonoid [LeftCancelMonoid M₂] (f : M₁ → M₂) (hf : Injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y)
(npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : LeftCancelMonoid M₁ :=
{ hf.leftCancelSemigroup f mul, hf.monoid f one mul npow with }
/-- A type endowed with `1` and `*` is a right cancel monoid, if it admits an injective map that
preserves `1` and `*` to a right cancel monoid. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an additive left cancel monoid,if it
admits an injective map that preserves `0` and `+` to an additive left cancel monoid. -/]
protected abbrev rightCancelMonoid [RightCancelMonoid M₂] (f : M₁ → M₂) (hf : Injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y)
(npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : RightCancelMonoid M₁ :=
{ hf.rightCancelSemigroup f mul, hf.monoid f one mul npow with }
/-- A type endowed with `1` and `*` is a cancel monoid, if it admits an injective map that preserves
`1` and `*` to a cancel monoid. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an additive left cancel monoid,if it
admits an injective map that preserves `0` and `+` to an additive left cancel monoid. -/]
protected abbrev cancelMonoid [CancelMonoid M₂] (f : M₁ → M₂) (hf : Injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) :
CancelMonoid M₁ :=
{ hf.leftCancelMonoid f one mul npow, hf.rightCancelMonoid f one mul npow with }
/-- A type endowed with `1` and `*` is a commutative monoid, if it admits an injective map that
preserves `1` and `*` to a commutative monoid. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an additive commutative monoid, if it
admits an injective map that preserves `0` and `+` to an additive commutative monoid. -/]
protected abbrev commMonoid [CommMonoid M₂] (f : M₁ → M₂) (hf : Injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) :
CommMonoid M₁ :=
{ hf.monoid f one mul npow, hf.commSemigroup f mul with }
/-- A type endowed with `1` and `*` is a cancel commutative monoid if it admits an injective map
that preserves `1` and `*` to a cancel commutative monoid. See note [reducible non-instances]. -/
@[to_additive /-- A type endowed with `0` and `+` is an additive cancel commutative monoid if it
admits an injective map that preserves `0` and `+` to an additive cancel commutative monoid. -/]
protected abbrev cancelCommMonoid [CancelCommMonoid M₂] (f : M₁ → M₂) (hf : Injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y)
(npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : CancelCommMonoid M₁ :=
{ hf.leftCancelSemigroup f mul, hf.commMonoid f one mul npow with }
/-- A type has an involutive inversion if it admits a surjective map that preserves `⁻¹` to a type
which has an involutive inversion. See note [reducible non-instances] -/
@[to_additive
/-- A type has an involutive negation if it admits a surjective map that
preserves `-` to a type which has an involutive negation. -/]
protected abbrev involutiveInv {M₁ : Type*} [Inv M₁] [InvolutiveInv M₂] (f : M₁ → M₂)
(hf : Injective f) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) : InvolutiveInv M₁ where
inv_inv x := hf <| by rw [inv, inv, inv_inv]
variable [Inv M₁]
/-- A type endowed with `1` and `⁻¹` is a `InvOneClass`, if it admits an injective map that
preserves `1` and `⁻¹` to a `InvOneClass`. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and unary `-` is an `NegZeroClass`, if it admits an
injective map that preserves `0` and unary `-` to an `NegZeroClass`. -/]
protected abbrev invOneClass [InvOneClass M₂] (f : M₁ → M₂) (hf : Injective f) (one : f 1 = 1)
(inv : ∀ x, f (x⁻¹) = (f x)⁻¹) : InvOneClass M₁ :=
{ ‹One M₁›, ‹Inv M₁› with
inv_one := hf <| by rw [inv, one, inv_one] }
variable [Div M₁] [Pow M₁ ℤ]
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `DivInvMonoid` if it admits an injective map
that preserves `1`, `*`, `⁻¹`, and `/` to a `DivInvMonoid`. See note [reducible non-instances]. -/
@[to_additive subNegMonoid
/-- A type endowed with `0`, `+`, unary `-`, and binary `-` is a
`SubNegMonoid` if it admits an injective map that preserves `0`, `+`, unary `-`, and binary `-` to
a `SubNegMonoid`. This version takes custom `nsmul` and `zsmul` as `[SMul ℕ M₁]` and `[SMul ℤ M₁]`
arguments. -/]
protected abbrev divInvMonoid [DivInvMonoid M₂] (f : M₁ → M₂) (hf : Injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : DivInvMonoid M₁ :=
{ hf.monoid f one mul npow, ‹Inv M₁›, ‹Div M₁› with
zpow := fun n x => x ^ n,
zpow_zero' := fun x => hf <| by rw [zpow, zpow_zero, one],
zpow_succ' := fun n x => hf <| by rw [zpow, mul, zpow_natCast, pow_succ, zpow, zpow_natCast],
zpow_neg' := fun n x => hf <| by rw [zpow, zpow_negSucc, inv, zpow, zpow_natCast],
div_eq_mul_inv := fun x y => hf <| by rw [div, mul, inv, div_eq_mul_inv] }
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `DivInvOneMonoid` if it admits an injective
map that preserves `1`, `*`, `⁻¹`, and `/` to a `DivInvOneMonoid`. See note
[reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0`, `+`, unary `-`, and binary `-` is a
`SubNegZeroMonoid` if it admits an injective map that preserves `0`, `+`, unary `-`, and binary
`-` to a `SubNegZeroMonoid`. This version takes custom `nsmul` and `zsmul` as `[SMul ℕ M₁]` and
`[SMul ℤ M₁]` arguments. -/]
protected abbrev divInvOneMonoid [DivInvOneMonoid M₂] (f : M₁ → M₂) (hf : Injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : DivInvOneMonoid M₁ :=
{ hf.divInvMonoid f one mul inv div npow zpow, hf.invOneClass f one inv with }
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `DivisionMonoid` if it admits an injective map
that preserves `1`, `*`, `⁻¹`, and `/` to a `DivisionMonoid`. See note [reducible non-instances] -/
@[to_additive
/-- A type endowed with `0`, `+`, unary `-`, and binary `-`
is a `SubtractionMonoid` if it admits an injective map that preserves `0`, `+`, unary `-`, and
binary `-` to a `SubtractionMonoid`. This version takes custom `nsmul` and `zsmul` as `[SMul ℕ M₁]`
and `[SMul ℤ M₁]` arguments. -/]
protected abbrev divisionMonoid [DivisionMonoid M₂] (f : M₁ → M₂) (hf : Injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : DivisionMonoid M₁ :=
{ hf.divInvMonoid f one mul inv div npow zpow, hf.involutiveInv f inv with
mul_inv_rev := fun x y => hf <| by rw [inv, mul, mul_inv_rev, mul, inv, inv],
inv_eq_of_mul := fun x y h => hf <| by
rw [inv, inv_eq_of_mul_eq_one_right (by rw [← mul, h, one])] }
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `DivisionCommMonoid` if it admits an
injective map that preserves `1`, `*`, `⁻¹`, and `/` to a `DivisionCommMonoid`.
See note [reducible non-instances]. -/
@[to_additive subtractionCommMonoid
/-- A type endowed with `0`, `+`, unary `-`, and binary
`-` is a `SubtractionCommMonoid` if it admits an injective map that preserves `0`, `+`, unary `-`,
and binary `-` to a `SubtractionCommMonoid`. This version takes custom `nsmul` and `zsmul` as
`[SMul ℕ M₁]` and `[SMul ℤ M₁]` arguments. -/]
protected abbrev divisionCommMonoid [DivisionCommMonoid M₂] (f : M₁ → M₂) (hf : Injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : DivisionCommMonoid M₁ :=
{ hf.divisionMonoid f one mul inv div npow zpow, hf.commSemigroup f mul with }
/-- A type endowed with `1`, `*` and `⁻¹` is a group, if it admits an injective map that preserves
`1`, `*` and `⁻¹` to a group. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an additive group, if it admits an
injective map that preserves `0` and `+` to an additive group. -/]
protected abbrev group [Group M₂] (f : M₁ → M₂) (hf : Injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : Group M₁ :=
{ hf.divInvMonoid f one mul inv div npow zpow with
inv_mul_cancel := fun x => hf <| by rw [mul, inv, inv_mul_cancel, one] }
/-- A type endowed with `1`, `*` and `⁻¹` is a commutative group, if it admits an injective map that
preserves `1`, `*` and `⁻¹` to a commutative group. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an additive commutative group, if it
admits an injective map that preserves `0` and `+` to an additive commutative group. -/]
protected abbrev commGroup [CommGroup M₂] (f : M₁ → M₂) (hf : Injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : CommGroup M₁ :=
{ hf.commMonoid f one mul npow, hf.group f one mul inv div npow zpow with }
end Injective
/-!
### Surjective
-/
namespace Surjective
variable {M₁ : Type*} {M₂ : Type*} [Mul M₂]
/-- A type endowed with `*` is a semigroup, if it admits a surjective map that preserves `*` from a
semigroup. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `+` is an additive semigroup, if it admits a
surjective map that preserves `+` from an additive semigroup. -/]
protected abbrev semigroup [Semigroup M₁] (f : M₁ → M₂) (hf : Surjective f)
(mul : ∀ x y, f (x * y) = f x * f y) : Semigroup M₂ :=
{ ‹Mul M₂› with mul_assoc := hf.forall₃.2 fun x y z => by simp only [← mul, mul_assoc] }
/-- A type endowed with `*` is a commutative semigroup, if it admits a surjective map that preserves
`*` from a commutative semigroup. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `+` is an additive commutative semigroup, if it admits
a surjective map that preserves `+` from an additive commutative semigroup. -/]
protected abbrev commMagma [CommMagma M₁] (f : M₁ → M₂) (hf : Surjective f)
(mul : ∀ x y, f (x * y) = f x * f y) : CommMagma M₂ where
mul_comm := hf.forall₂.2 fun x y => by rw [← mul, ← mul, mul_comm]
/-- A type endowed with `*` is a commutative semigroup, if it admits a surjective map that preserves
`*` from a commutative semigroup. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `+` is an additive commutative semigroup, if it admits
a surjective map that preserves `+` from an additive commutative semigroup. -/]
protected abbrev commSemigroup [CommSemigroup M₁] (f : M₁ → M₂) (hf : Surjective f)
(mul : ∀ x y, f (x * y) = f x * f y) : CommSemigroup M₂ where
toSemigroup := hf.semigroup f mul
__ := hf.commMagma f mul
variable [One M₂]
/-- A type endowed with `1` and `*` is a `MulOneClass`, if it admits a surjective map that preserves
`1` and `*` from a `MulOneClass`. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an `AddZeroClass`, if it admits a
surjective map that preserves `0` and `+` to an `AddZeroClass`. -/]
protected abbrev mulOneClass [MulOneClass M₁] (f : M₁ → M₂) (hf : Surjective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) : MulOneClass M₂ :=
{ ‹One M₂›, ‹Mul M₂› with
one_mul := hf.forall.2 fun x => by rw [← one, ← mul, one_mul],
mul_one := hf.forall.2 fun x => by rw [← one, ← mul, mul_one] }
variable [Pow M₂ ℕ]
/-- A type endowed with `1` and `*` is a monoid, if it admits a surjective map that preserves `1`
and `*` to a monoid. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an additive monoid, if it admits a
surjective map that preserves `0` and `+` to an additive monoid. This version takes a custom `nsmul`
as a `[SMul ℕ M₂]` argument. -/]
protected abbrev monoid [Monoid M₁] (f : M₁ → M₂) (hf : Surjective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : Monoid M₂ :=
{ hf.semigroup f mul, hf.mulOneClass f one mul with
npow := fun n x => x ^ n,
npow_zero := hf.forall.2 fun x => by rw [← npow, pow_zero, ← one],
npow_succ := fun n => hf.forall.2 fun x => by
rw [← npow, pow_succ, ← npow, ← mul] }
/-- A type endowed with `1` and `*` is a commutative monoid, if it admits a surjective map that
preserves `1` and `*` from a commutative monoid. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an additive commutative monoid, if it
admits a surjective map that preserves `0` and `+` to an additive commutative monoid. -/]
protected abbrev commMonoid [CommMonoid M₁] (f : M₁ → M₂) (hf : Surjective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) :
CommMonoid M₂ :=
{ hf.commSemigroup f mul, hf.monoid f one mul npow with }
/-- A type has an involutive inversion if it admits a surjective map that preserves `⁻¹` to a type
which has an involutive inversion. See note [reducible non-instances] -/
@[to_additive
/-- A type has an involutive negation if it admits a surjective map that
preserves `-` to a type which has an involutive negation. -/]
protected abbrev involutiveInv {M₂ : Type*} [Inv M₂] [InvolutiveInv M₁] (f : M₁ → M₂)
(hf : Surjective f) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) : InvolutiveInv M₂ where
inv_inv := hf.forall.2 fun x => by rw [← inv, ← inv, inv_inv]
variable [Inv M₂] [Div M₂] [Pow M₂ ℤ]
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `DivInvMonoid` if it admits a surjective map
that preserves `1`, `*`, `⁻¹`, and `/` to a `DivInvMonoid`. See note [reducible non-instances]. -/
@[to_additive subNegMonoid
/-- A type endowed with `0`, `+`, unary `-`, and binary `-` is a
`SubNegMonoid` if it admits a surjective map that preserves `0`, `+`, unary `-`, and binary `-` to
a `SubNegMonoid`. -/]
protected abbrev divInvMonoid [DivInvMonoid M₁] (f : M₁ → M₂) (hf : Surjective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : DivInvMonoid M₂ :=
{ hf.monoid f one mul npow, ‹Div M₂›, ‹Inv M₂› with
zpow := fun n x => x ^ n,
zpow_zero' := hf.forall.2 fun x => by rw [← zpow, zpow_zero, ← one],
zpow_succ' := fun n => hf.forall.2 fun x => by
rw [← zpow, ← zpow, zpow_natCast, zpow_natCast, pow_succ, ← mul],
zpow_neg' := fun n => hf.forall.2 fun x => by
rw [← zpow, ← zpow, zpow_negSucc, zpow_natCast, inv],
div_eq_mul_inv := hf.forall₂.2 fun x y => by rw [← inv, ← mul, ← div, div_eq_mul_inv] }
/-- A type endowed with `1`, `*` and `⁻¹` is a group, if it admits a surjective map that preserves
`1`, `*` and `⁻¹` to a group. See note [reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an additive group, if it admits a
surjective map that preserves `0` and `+` to an additive group. -/]
protected abbrev group [Group M₁] (f : M₁ → M₂) (hf : Surjective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : Group M₂ :=
{ hf.divInvMonoid f one mul inv div npow zpow with
inv_mul_cancel := hf.forall.2 fun x => by rw [← inv, ← mul, inv_mul_cancel, one] }
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a commutative group, if it admits a surjective
map that preserves `1`, `*`, `⁻¹`, and `/` from a commutative group. See note
[reducible non-instances]. -/
@[to_additive
/-- A type endowed with `0` and `+` is an additive commutative group, if it
admits a surjective map that preserves `0` and `+` to an additive commutative group. -/]
protected abbrev commGroup [CommGroup M₁] (f : M₁ → M₂) (hf : Surjective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : CommGroup M₂ :=
{ hf.commMonoid f one mul npow, hf.group f one mul inv div npow zpow with }
end Surjective
end Function |
.lake/packages/mathlib/Mathlib/Algebra/Group/Defs.lean | import Batteries.Logic
import Mathlib.Algebra.Notation.Defs
import Mathlib.Algebra.Regular.Defs
import Mathlib.Data.Int.Notation
import Mathlib.Data.Nat.BinaryRec
import Mathlib.Tactic.MkIffOfInductiveProp
import Mathlib.Tactic.OfNat
import Mathlib.Tactic.Basic
/-!
# Typeclasses for (semi)groups and monoids
In this file we define typeclasses for algebraic structures with one binary operation.
The classes are named `(Add)?(Comm)?(Semigroup|Monoid|Group)`, where `Add` means that
the class uses additive notation and `Comm` means that the class assumes that the binary
operation is commutative.
The file does not contain any lemmas except for
* axioms of typeclasses restated in the root namespace;
* lemmas required for instances.
For basic lemmas about these classes see `Mathlib/Algebra/Group/Basic.lean`.
We register the following instances:
- `Pow M ℕ`, for monoids `M`, and `Pow G ℤ` for groups `G`;
- `SMul ℕ M` for additive monoids `M`, and `SMul ℤ G` for additive groups `G`.
## Notation
- `+`, `-`, `*`, `/`, `^` : the usual arithmetic operations; the underlying functions are
`Add.add`, `Neg.neg`/`Sub.sub`, `Mul.mul`, `Div.div`, and `HPow.hPow`.
-/
assert_not_exists MonoidWithZero DenselyOrdered Function.const_injective
universe u v w
open Function
variable {G : Type*}
section Mul
variable [Mul G]
/-- A mixin for left cancellative multiplication. -/
@[mk_iff] class IsLeftCancelMul (G : Type u) [Mul G] : Prop where
/-- Multiplication is left cancellative (i.e. left regular). -/
protected mul_left_cancel (a : G) : IsLeftRegular a
/-- A mixin for right cancellative multiplication. -/
@[mk_iff] class IsRightCancelMul (G : Type u) [Mul G] : Prop where
/-- Multiplication is right cancellative (i.e. right regular). -/
protected mul_right_cancel (a : G) : IsRightRegular a
/-- A mixin for cancellative multiplication. -/
@[mk_iff]
class IsCancelMul (G : Type u) [Mul G] : Prop extends IsLeftCancelMul G, IsRightCancelMul G
/-- A mixin for left cancellative addition. -/
class IsLeftCancelAdd (G : Type u) [Add G] : Prop where
/-- Addition is left cancellative (i.e. left regular). -/
protected add_left_cancel (a : G) : IsAddLeftRegular a
attribute [to_additive] IsLeftCancelMul
attribute [to_additive] isLeftCancelMul_iff
/-- A mixin for right cancellative addition. -/
class IsRightCancelAdd (G : Type u) [Add G] : Prop where
/-- Addition is right cancellative (i.e. right regular). -/
protected add_right_cancel (a : G) : IsAddRightRegular a
attribute [to_additive] IsRightCancelMul
attribute [to_additive] isRightCancelMul_iff
/-- A mixin for cancellative addition. -/
@[mk_iff]
class IsCancelAdd (G : Type u) [Add G] : Prop extends IsLeftCancelAdd G, IsRightCancelAdd G
attribute [to_additive] IsCancelMul
attribute [to_additive existing] isCancelMul_iff
section Regular
variable {R : Type*}
@[to_additive] theorem isCancelMul_iff_forall_isRegular [Mul R] :
IsCancelMul R ↔ ∀ r : R, IsRegular r := by
rw [isCancelMul_iff, isLeftCancelMul_iff, isRightCancelMul_iff, ← forall_and]
exact forall_congr' fun _ ↦ isRegular_iff.symm
/-- If all multiplications cancel on the left then every element is left-regular. -/
@[to_additive /-- If all additions cancel on the left then every element is add-left-regular. -/]
theorem IsLeftRegular.all [Mul R] [IsLeftCancelMul R] (g : R) : IsLeftRegular g :=
(isLeftCancelMul_iff R).mp ‹_› _
/-- If all multiplications cancel on the right then every element is right-regular. -/
@[to_additive /-- If all additions cancel on the right then every element is add-right-regular. -/]
theorem IsRightRegular.all [Mul R] [IsRightCancelMul R] (g : R) : IsRightRegular g :=
(isRightCancelMul_iff R).mp ‹_› _
/-- If all multiplications cancel then every element is regular. -/
@[to_additive /-- If all additions cancel then every element is add-regular. -/]
theorem IsRegular.all [Mul R] [IsCancelMul R] (g : R) : IsRegular g := ⟨.all g, .all g⟩
end Regular
section IsLeftCancelMul
variable [IsLeftCancelMul G] {a b c : G}
@[to_additive]
theorem mul_left_cancel : a * b = a * c → b = c :=
(IsLeftCancelMul.mul_left_cancel a ·)
@[to_additive]
theorem mul_left_cancel_iff : a * b = a * c ↔ b = c :=
⟨mul_left_cancel, congrArg _⟩
@[to_additive]
theorem mul_right_injective (a : G) : Injective (a * ·) := fun _ _ ↦ mul_left_cancel
@[to_additive (attr := simp)]
theorem mul_right_inj (a : G) {b c : G} : a * b = a * c ↔ b = c :=
(mul_right_injective a).eq_iff
@[to_additive]
theorem mul_ne_mul_right (a : G) {b c : G} : a * b ≠ a * c ↔ b ≠ c :=
(mul_right_injective a).ne_iff
end IsLeftCancelMul
section IsRightCancelMul
variable [IsRightCancelMul G] {a b c : G}
@[to_additive]
theorem mul_right_cancel : a * b = c * b → a = c :=
(IsRightCancelMul.mul_right_cancel b ·)
@[to_additive]
theorem mul_right_cancel_iff : b * a = c * a ↔ b = c :=
⟨mul_right_cancel, congrArg (· * a)⟩
@[to_additive]
theorem mul_left_injective (a : G) : Function.Injective (· * a) := fun _ _ ↦ mul_right_cancel
@[to_additive (attr := simp)]
theorem mul_left_inj (a : G) {b c : G} : b * a = c * a ↔ b = c :=
(mul_left_injective a).eq_iff
@[to_additive]
theorem mul_ne_mul_left (a : G) {b c : G} : b * a ≠ c * a ↔ b ≠ c :=
(mul_left_injective a).ne_iff
end IsRightCancelMul
end Mul
/-- A semigroup is a type with an associative `(*)`. -/
@[ext]
class Semigroup (G : Type u) extends Mul G where
/-- Multiplication is associative -/
protected mul_assoc : ∀ a b c : G, a * b * c = a * (b * c)
/-- An additive semigroup is a type with an associative `(+)`. -/
@[ext]
class AddSemigroup (G : Type u) extends Add G where
/-- Addition is associative -/
protected add_assoc : ∀ a b c : G, a + b + c = a + (b + c)
attribute [to_additive] Semigroup
section Semigroup
variable [Semigroup G]
@[to_additive]
theorem mul_assoc : ∀ a b c : G, a * b * c = a * (b * c) :=
Semigroup.mul_assoc
end Semigroup
/-- A commutative additive magma is a type with an addition which commutes. -/
@[ext]
class AddCommMagma (G : Type u) extends Add G where
/-- Addition is commutative in an commutative additive magma. -/
protected add_comm : ∀ a b : G, a + b = b + a
/-- A commutative multiplicative magma is a type with a multiplication which commutes. -/
@[ext]
class CommMagma (G : Type u) extends Mul G where
/-- Multiplication is commutative in a commutative multiplicative magma. -/
protected mul_comm : ∀ a b : G, a * b = b * a
attribute [to_additive] CommMagma
/-- A commutative semigroup is a type with an associative commutative `(*)`. -/
@[ext]
class CommSemigroup (G : Type u) extends Semigroup G, CommMagma G where
/-- A commutative additive semigroup is a type with an associative commutative `(+)`. -/
@[ext]
class AddCommSemigroup (G : Type u) extends AddSemigroup G, AddCommMagma G where
attribute [to_additive] CommSemigroup
section CommMagma
variable [CommMagma G] {a : G}
@[to_additive]
theorem mul_comm : ∀ a b : G, a * b = b * a := CommMagma.mul_comm
@[simp] lemma isLeftRegular_iff_isRegular : IsLeftRegular a ↔ IsRegular a := by
simp [isRegular_iff, IsLeftRegular, IsRightRegular, mul_comm]
@[simp] lemma isRightRegular_iff_isRegular : IsRightRegular a ↔ IsRegular a := by
simp [isRegular_iff, IsLeftRegular, IsRightRegular, mul_comm]
/-- Any `CommMagma G` that satisfies `IsRightCancelMul G` also satisfies `IsLeftCancelMul G`. -/
@[to_additive AddCommMagma.IsRightCancelAdd.toIsLeftCancelAdd /-- Any `AddCommMagma G` that
satisfies `IsRightCancelAdd G` also satisfies `IsLeftCancelAdd G`. -/]
lemma CommMagma.IsRightCancelMul.toIsLeftCancelMul (G : Type u) [CommMagma G] [IsRightCancelMul G] :
IsLeftCancelMul G :=
⟨fun _ _ _ h => mul_right_cancel <| (mul_comm _ _).trans (h.trans (mul_comm _ _))⟩
/-- Any `CommMagma G` that satisfies `IsLeftCancelMul G` also satisfies `IsRightCancelMul G`. -/
@[to_additive AddCommMagma.IsLeftCancelAdd.toIsRightCancelAdd /-- Any `AddCommMagma G` that
satisfies `IsLeftCancelAdd G` also satisfies `IsRightCancelAdd G`. -/]
lemma CommMagma.IsLeftCancelMul.toIsRightCancelMul (G : Type u) [CommMagma G] [IsLeftCancelMul G] :
IsRightCancelMul G :=
⟨fun _ _ _ h => mul_left_cancel <| (mul_comm _ _).trans (h.trans (mul_comm _ _))⟩
/-- Any `CommMagma G` that satisfies `IsLeftCancelMul G` also satisfies `IsCancelMul G`. -/
@[to_additive AddCommMagma.IsLeftCancelAdd.toIsCancelAdd /-- Any `AddCommMagma G` that satisfies
`IsLeftCancelAdd G` also satisfies `IsCancelAdd G`. -/]
lemma CommMagma.IsLeftCancelMul.toIsCancelMul (G : Type u) [CommMagma G] [IsLeftCancelMul G] :
IsCancelMul G := { CommMagma.IsLeftCancelMul.toIsRightCancelMul G with }
/-- Any `CommMagma G` that satisfies `IsRightCancelMul G` also satisfies `IsCancelMul G`. -/
@[to_additive AddCommMagma.IsRightCancelAdd.toIsCancelAdd /-- Any `AddCommMagma G` that satisfies
`IsRightCancelAdd G` also satisfies `IsCancelAdd G`. -/]
lemma CommMagma.IsRightCancelMul.toIsCancelMul (G : Type u) [CommMagma G] [IsRightCancelMul G] :
IsCancelMul G := { CommMagma.IsRightCancelMul.toIsLeftCancelMul G with }
end CommMagma
/-- A `LeftCancelSemigroup` is a semigroup such that `a * b = a * c` implies `b = c`. -/
@[ext]
class LeftCancelSemigroup (G : Type u) extends Semigroup G, IsLeftCancelMul G
library_note2 «lower cancel priority» /--
We lower the priority of inheriting from cancellative structures.
This attempts to avoid expensive checks involving bundling and unbundling with the `IsDomain` class.
since `IsDomain` already depends on `Semiring`, we can synthesize that one first.
Zulip discussion: https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Why.20is.20.60simpNF.60.20complaining.20here.3F
-/
attribute [instance 75] LeftCancelSemigroup.toSemigroup -- See note [lower cancel priority]
/-- An `AddLeftCancelSemigroup` is an additive semigroup such that
`a + b = a + c` implies `b = c`. -/
@[ext]
class AddLeftCancelSemigroup (G : Type u) extends AddSemigroup G, IsLeftCancelAdd G
attribute [instance 75] AddLeftCancelSemigroup.toAddSemigroup -- See note [lower cancel priority]
attribute [to_additive] LeftCancelSemigroup
/-- Any `LeftCancelSemigroup` satisfies `IsLeftCancelMul`. -/
add_decl_doc LeftCancelSemigroup.toIsLeftCancelMul
/-- Any `AddLeftCancelSemigroup` satisfies `IsLeftCancelAdd`. -/
add_decl_doc AddLeftCancelSemigroup.toIsLeftCancelAdd
/-- A `RightCancelSemigroup` is a semigroup such that `a * b = c * b` implies `a = c`. -/
@[ext]
class RightCancelSemigroup (G : Type u) extends Semigroup G, IsRightCancelMul G
attribute [instance 75] RightCancelSemigroup.toSemigroup -- See note [lower cancel priority]
/-- An `AddRightCancelSemigroup` is an additive semigroup such that
`a + b = c + b` implies `a = c`. -/
@[ext]
class AddRightCancelSemigroup (G : Type u) extends AddSemigroup G, IsRightCancelAdd G
attribute [instance 75] AddRightCancelSemigroup.toAddSemigroup -- See note [lower cancel priority]
attribute [to_additive] RightCancelSemigroup
/-- Any `RightCancelSemigroup` satisfies `IsRightCancelMul`. -/
add_decl_doc RightCancelSemigroup.toIsRightCancelMul
/-- Any `AddRightCancelSemigroup` satisfies `IsRightCancelAdd`. -/
add_decl_doc AddRightCancelSemigroup.toIsRightCancelAdd
/-- Bundling an `Add` and `Zero` structure together without any axioms about their
compatibility. See `AddZeroClass` for the additional assumption that 0 is an identity. -/
class AddZero (M : Type*) extends Zero M, Add M
/-- Bundling a `Mul` and `One` structure together without any axioms about their
compatibility. See `MulOneClass` for the additional assumption that 1 is an identity. -/
@[to_additive, ext]
class MulOne (M : Type*) extends One M, Mul M
/-- Typeclass for expressing that a type `M` with addition and a zero satisfies
`0 + a = a` and `a + 0 = a` for all `a : M`. -/
class AddZeroClass (M : Type u) extends AddZero M where
/-- Zero is a left neutral element for addition -/
protected zero_add : ∀ a : M, 0 + a = a
/-- Zero is a right neutral element for addition -/
protected add_zero : ∀ a : M, a + 0 = a
/-- Typeclass for expressing that a type `M` with multiplication and a one satisfies
`1 * a = a` and `a * 1 = a` for all `a : M`. -/
@[to_additive]
class MulOneClass (M : Type u) extends MulOne M where
/-- One is a left neutral element for multiplication -/
protected one_mul : ∀ a : M, 1 * a = a
/-- One is a right neutral element for multiplication -/
protected mul_one : ∀ a : M, a * 1 = a
@[to_additive (attr := ext)]
theorem MulOneClass.ext {M : Type u} : ∀ ⦃m₁ m₂ : MulOneClass M⦄, m₁.mul = m₂.mul → m₁ = m₂ := by
rintro @⟨@⟨⟨one₁⟩, ⟨mul₁⟩⟩, one_mul₁, mul_one₁⟩ @⟨@⟨⟨one₂⟩, ⟨mul₂⟩⟩, one_mul₂, mul_one₂⟩ ⟨rfl⟩
-- FIXME (See https://github.com/leanprover/lean4/issues/1711)
-- congr
suffices one₁ = one₂ by cases this; rfl
exact (one_mul₂ one₁).symm.trans (mul_one₁ one₂)
section MulOneClass
variable {M : Type u} [MulOneClass M]
@[to_additive (attr := simp)]
theorem one_mul : ∀ a : M, 1 * a = a :=
MulOneClass.one_mul
@[to_additive (attr := simp)]
theorem mul_one : ∀ a : M, a * 1 = a :=
MulOneClass.mul_one
end MulOneClass
section
variable {M : Type u}
attribute [to_additive existing] npowRec
variable [One M] [Semigroup M] (m n : ℕ) (hn : n ≠ 0) (a : M) (ha : 1 * a = a)
include hn ha
@[to_additive] theorem npowRec_add : npowRec (m + n) a = npowRec m a * npowRec n a := by
obtain _ | n := n; · exact (hn rfl).elim
induction n with
| zero => simp only [npowRec, ha]
| succ n ih => rw [← Nat.add_assoc, npowRec, ih n.succ_ne_zero]; simp only [npowRec, mul_assoc]
@[to_additive] theorem npowRec_succ : npowRec (n + 1) a = a * npowRec n a := by
rw [Nat.add_comm, npowRec_add 1 n hn a ha, npowRec, npowRec, ha]
end
library_note2 «forgetful inheritance» /--
Suppose that one can put two mathematical structures on a type, a rich one `R` and a poor one
`P`, and that one can deduce the poor structure from the rich structure through a map `F` (called a
forgetful functor) (think `R = MetricSpace` and `P = TopologicalSpace`). A possible
implementation would be to have a type class `rich` containing a field `R`, a type class `poor`
containing a field `P`, and an instance from `rich` to `poor`. However, this creates diamond
problems, and a better approach is to let `rich` extend `poor` and have a field saying that
`F R = P`.
To illustrate this, consider the pair `MetricSpace` / `TopologicalSpace`. Consider the topology
on a product of two metric spaces. With the first approach, it could be obtained by going first from
each metric space to its topology, and then taking the product topology. But it could also be
obtained by considering the product metric space (with its sup distance) and then the topology
coming from this distance. These would be the same topology, but not definitionally, which means
that from the point of view of Lean's kernel, there would be two different `TopologicalSpace`
instances on the product. This is not compatible with the way instances are designed and used:
there should be at most one instance of a kind on each type. This approach has created an instance
diamond that does not commute definitionally.
The second approach solves this issue. Now, a metric space contains both a distance, a topology, and
a proof that the topology coincides with the one coming from the distance. When one defines the
product of two metric spaces, one uses the sup distance and the product topology, and one has to
give the proof that the sup distance induces the product topology. Following both sides of the
instance diamond then gives rise (definitionally) to the product topology on the product space.
Another approach would be to have the rich type class take the poor type class as an instance
parameter. It would solve the diamond problem, but it would lead to a blow up of the number
of type classes one would need to declare to work with complicated classes, say a real inner
product space, and would create exponential complexity when working with products of
such complicated spaces, that are avoided by bundling things carefully as above.
Note that this description of this specific case of the product of metric spaces is oversimplified
compared to mathlib, as there is an intermediate typeclass between `MetricSpace` and
`TopologicalSpace` called `UniformSpace`. The above scheme is used at both levels, embedding a
topology in the uniform space structure, and a uniform structure in the metric space structure.
Note also that, when `P` is a proposition, there is no such issue as any two proofs of `P` are
definitionally equivalent in Lean.
To avoid boilerplate, there are some designs that can automatically fill the poor fields when
creating a rich structure if one doesn't want to do something special about them. For instance,
in the definition of metric spaces, default tactics fill the uniform space fields if they are
not given explicitly. One can also have a helper function creating the rich structure from a
structure with fewer fields, where the helper function fills the remaining fields. See for instance
`UniformSpace.ofCore` or `RealInnerProduct.ofCore`.
For more details on this question, called the forgetful inheritance pattern, see [Competing
inheritance paths in dependent type theory: a case study in functional
analysis](https://hal.inria.fr/hal-02463336).
-/
/-!
### Design note on `AddMonoid` and `Monoid`
An `AddMonoid` has a natural `ℕ`-action, defined by `n • a = a + ... + a`, that we want to declare
as an instance as it makes it possible to use the language of linear algebra. However, there are
often other natural `ℕ`-actions. For instance, for any semiring `R`, the space of polynomials
`Polynomial R` has a natural `R`-action defined by multiplication on the coefficients. This means
that `Polynomial ℕ` would have two natural `ℕ`-actions, which are equal but not defeq. The same
goes for linear maps, tensor products, and so on (and even for `ℕ` itself).
To solve this issue, we embed an `ℕ`-action in the definition of an `AddMonoid` (which is by
default equal to the naive action `a + ... + a`, but can be adjusted when needed), and declare
a `SMul ℕ α` instance using this action. See Note [forgetful inheritance] for more
explanations on this pattern.
For example, when we define `Polynomial R`, then we declare the `ℕ`-action to be by multiplication
on each coefficient (using the `ℕ`-action on `R` that comes from the fact that `R` is
an `AddMonoid`). In this way, the two natural `SMul ℕ (Polynomial ℕ)` instances are defeq.
The tactic `to_additive` transfers definitions and results from multiplicative monoids to additive
monoids. To work, it has to map fields to fields. This means that we should also add corresponding
fields to the multiplicative structure `Monoid`, which could solve defeq problems for powers if
needed. These problems do not come up in practice, so most of the time we will not need to adjust
the `npow` field when defining multiplicative objects.
-/
/-- Exponentiation by repeated squaring. -/
@[to_additive /-- Scalar multiplication by repeated self-addition,
the additive version of exponentiation by repeated squaring. -/]
def npowBinRec {M : Type*} [One M] [Mul M] (k : ℕ) : M → M :=
npowBinRec.go k 1
where
/-- Auxiliary tail-recursive implementation for `npowBinRec`. -/
@[to_additive nsmulBinRec.go /-- Auxiliary tail-recursive implementation for `nsmulBinRec`. -/]
go (k : ℕ) : M → M → M :=
k.binaryRec (fun y _ ↦ y) fun bn _n fn y x ↦ fn (cond bn (y * x) y) (x * x)
/--
A variant of `npowRec` which is a semigroup homomorphism from `ℕ₊` to `M`.
-/
def npowRec' {M : Type*} [One M] [Mul M] : ℕ → M → M
| 0, _ => 1
| 1, m => m
| k + 2, m => npowRec' (k + 1) m * m
/--
A variant of `nsmulRec` which is a semigroup homomorphism from `ℕ₊` to `M`.
-/
def nsmulRec' {M : Type*} [Zero M] [Add M] : ℕ → M → M
| 0, _ => 0
| 1, m => m
| k + 2, m => nsmulRec' (k + 1) m + m
attribute [to_additive existing] npowRec'
@[to_additive]
theorem npowRec'_succ {M : Type*} [Mul M] [One M] {k : ℕ} (_ : k ≠ 0) (m : M) :
npowRec' (k + 1) m = npowRec' k m * m :=
match k with
| _ + 1 => rfl
@[to_additive]
theorem npowRec'_two_mul {M : Type*} [Semigroup M] [One M] (k : ℕ) (m : M) :
npowRec' (2 * k) m = npowRec' k (m * m) := by
induction k using Nat.strongRecOn with
| ind k' ih =>
match k' with
| 0 => rfl
| 1 => simp [npowRec']
| k + 2 => simp [npowRec', ← mul_assoc, Nat.mul_add, ← ih]
@[to_additive]
theorem npowRec'_mul_comm {M : Type*} [Semigroup M] [One M] {k : ℕ} (k0 : k ≠ 0) (m : M) :
m * npowRec' k m = npowRec' k m * m := by
induction k using Nat.strongRecOn with
| ind k' ih =>
match k' with
| 1 => simp [npowRec']
| k + 2 => simp [npowRec', ← mul_assoc, ih]
@[to_additive]
theorem npowRec_eq {M : Type*} [Semigroup M] [One M] (k : ℕ) (m : M) :
npowRec (k + 1) m = 1 * npowRec' (k + 1) m := by
induction k using Nat.strongRecOn with
| ind k' ih =>
match k' with
| 0 => rfl
| k + 1 =>
rw [npowRec, npowRec'_succ k.succ_ne_zero, ← mul_assoc]
congr
simp [ih]
@[to_additive]
theorem npowBinRec.go_spec {M : Type*} [Semigroup M] [One M] (k : ℕ) (m n : M) :
npowBinRec.go (k + 1) m n = m * npowRec' (k + 1) n := by
unfold go
generalize hk : k + 1 = k'
replace hk : k' ≠ 0 := by omega
induction k' using Nat.binaryRecFromOne generalizing n m with
| zero => simp at hk
| one => simp [npowRec']
| bit b k' k'0 ih =>
rw [Nat.binaryRec_eq _ _ (Or.inl rfl), ih _ _ k'0]
cases b <;> simp only [Nat.bit, cond_false, cond_true, npowRec'_two_mul]
rw [npowRec'_succ (by cutsat), npowRec'_two_mul, ← npowRec'_two_mul,
← npowRec'_mul_comm (by cutsat), mul_assoc]
/--
An abbreviation for `npowRec` with an additional typeclass assumption on associativity
so that we can use `@[csimp]` to replace it with an implementation by repeated squaring
in compiled code.
-/
@[to_additive
/-- An abbreviation for `nsmulRec` with an additional typeclass assumptions on associativity
so that we can use `@[csimp]` to replace it with an implementation by repeated doubling in compiled
code as an automatic parameter. -/]
abbrev npowRecAuto {M : Type*} [Semigroup M] [One M] (k : ℕ) (m : M) : M :=
npowRec k m
/--
An abbreviation for `npowBinRec` with an additional typeclass assumption on associativity
so that we can use it in `@[csimp]` for more performant code generation.
-/
@[to_additive
/-- An abbreviation for `nsmulBinRec` with an additional typeclass assumption on associativity
so that we can use it in `@[csimp]` for more performant code generation
as an automatic parameter. -/]
abbrev npowBinRecAuto {M : Type*} [Semigroup M] [One M] (k : ℕ) (m : M) : M :=
npowBinRec k m
@[to_additive (attr := csimp)]
theorem npowRec_eq_npowBinRec : @npowRecAuto = @npowBinRecAuto := by
funext M _ _ k m
rw [npowBinRecAuto, npowRecAuto, npowBinRec]
match k with
| 0 => rw [npowRec, npowBinRec.go, Nat.binaryRec_zero]
| k + 1 => rw [npowBinRec.go_spec, npowRec_eq]
/-- An `AddMonoid` is an `AddSemigroup` with an element `0` such that `0 + a = a + 0 = a`. -/
class AddMonoid (M : Type u) extends AddSemigroup M, AddZeroClass M where
/-- Multiplication by a natural number.
Set this to `nsmulRec` unless `Module` diamonds are possible. -/
protected nsmul : ℕ → M → M
/-- Multiplication by `(0 : ℕ)` gives `0`. -/
protected nsmul_zero : ∀ x, nsmul 0 x = 0 := by intros; rfl
/-- Multiplication by `(n + 1 : ℕ)` behaves as expected. -/
protected nsmul_succ : ∀ (n : ℕ) (x), nsmul (n + 1) x = nsmul n x + x := by intros; rfl
attribute [instance 150] AddSemigroup.toAdd
attribute [instance 50] AddZero.toAdd
/-- A `Monoid` is a `Semigroup` with an element `1` such that `1 * a = a * 1 = a`. -/
@[to_additive]
class Monoid (M : Type u) extends Semigroup M, MulOneClass M where
/-- Raising to the power of a natural number. -/
protected npow : ℕ → M → M := npowRecAuto
/-- Raising to the power `(0 : ℕ)` gives `1`. -/
protected npow_zero : ∀ x, npow 0 x = 1 := by intros; rfl
/-- Raising to the power `(n + 1 : ℕ)` behaves as expected. -/
protected npow_succ : ∀ (n : ℕ) (x), npow (n + 1) x = npow n x * x := by intros; rfl
@[default_instance high] instance Monoid.toNatPow {M : Type*} [Monoid M] : Pow M ℕ :=
⟨fun x n ↦ Monoid.npow n x⟩
instance AddMonoid.toNatSMul {M : Type*} [AddMonoid M] : SMul ℕ M :=
⟨AddMonoid.nsmul⟩
attribute [to_additive existing toNatSMul] Monoid.toNatPow
section Monoid
variable {M : Type*} [Monoid M] {a b c : M}
@[to_additive (attr := simp) nsmul_eq_smul]
theorem npow_eq_pow (n : ℕ) (x : M) : Monoid.npow n x = x ^ n :=
rfl
@[to_additive] lemma left_inv_eq_right_inv (hba : b * a = 1) (hac : a * c = 1) : b = c := by
rw [← one_mul c, ← hba, mul_assoc, hac, mul_one b]
-- This lemma is higher priority than later `zero_smul` so that the `simpNF` is happy
@[to_additive (attr := simp high) zero_nsmul]
theorem pow_zero (a : M) : a ^ 0 = 1 :=
Monoid.npow_zero _
@[to_additive succ_nsmul]
theorem pow_succ (a : M) (n : ℕ) : a ^ (n + 1) = a ^ n * a :=
Monoid.npow_succ n a
@[to_additive (attr := simp) one_nsmul]
lemma pow_one (a : M) : a ^ 1 = a := by rw [pow_succ, pow_zero, one_mul]
@[to_additive succ_nsmul'] lemma pow_succ' (a : M) : ∀ n, a ^ (n + 1) = a * a ^ n
| 0 => by simp
| n + 1 => by rw [pow_succ _ n, pow_succ, pow_succ', mul_assoc]
@[to_additive] lemma mul_pow_mul (a b : M) (n : ℕ) :
(a * b) ^ n * a = a * (b * a) ^ n := by
induction n with
| zero => simp
| succ n ih => simp [pow_succ', ← ih, mul_assoc]
@[to_additive]
lemma pow_mul_comm' (a : M) (n : ℕ) : a ^ n * a = a * a ^ n := by rw [← pow_succ, pow_succ']
/-- Note that most of the lemmas about powers of two refer to it as `sq`. -/
@[to_additive two_nsmul] lemma pow_two (a : M) : a ^ 2 = a * a := by rw [pow_succ, pow_one]
-- TODO: Should `alias` automatically transfer `to_additive` statements?
@[to_additive existing two_nsmul] alias sq := pow_two
@[to_additive three'_nsmul]
lemma pow_three' (a : M) : a ^ 3 = a * a * a := by rw [pow_succ, pow_two]
@[to_additive three_nsmul]
lemma pow_three (a : M) : a ^ 3 = a * (a * a) := by rw [pow_succ', pow_two]
-- This lemma is higher priority than later `smul_zero` so that the `simpNF` is happy
@[to_additive (attr := simp high) nsmul_zero] lemma one_pow : ∀ n, (1 : M) ^ n = 1
| 0 => pow_zero _
| n + 1 => by rw [pow_succ, one_pow, one_mul]
@[to_additive add_nsmul]
lemma pow_add (a : M) (m : ℕ) : ∀ n, a ^ (m + n) = a ^ m * a ^ n
| 0 => by rw [Nat.add_zero, pow_zero, mul_one]
| n + 1 => by rw [pow_succ, ← mul_assoc, ← pow_add, ← pow_succ, Nat.add_assoc]
@[to_additive] lemma pow_mul_comm (a : M) (m n : ℕ) : a ^ m * a ^ n = a ^ n * a ^ m := by
rw [← pow_add, ← pow_add, Nat.add_comm]
@[to_additive mul_nsmul] lemma pow_mul (a : M) (m : ℕ) : ∀ n, a ^ (m * n) = (a ^ m) ^ n
| 0 => by rw [Nat.mul_zero, pow_zero, pow_zero]
| n + 1 => by rw [Nat.mul_succ, pow_add, pow_succ, pow_mul]
@[to_additive mul_nsmul']
lemma pow_mul' (a : M) (m n : ℕ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Nat.mul_comm, pow_mul]
@[to_additive nsmul_left_comm]
lemma pow_right_comm (a : M) (m n : ℕ) : (a ^ m) ^ n = (a ^ n) ^ m := by
rw [← pow_mul, Nat.mul_comm, pow_mul]
end Monoid
/-- An additive monoid is torsion-free if scalar multiplication by every non-zero element `n : ℕ` is
injective. -/
@[mk_iff]
class IsAddTorsionFree (M : Type*) [AddMonoid M] where
protected nsmul_right_injective ⦃n : ℕ⦄ (hn : n ≠ 0) : Injective fun a : M ↦ n • a
/-- A monoid is torsion-free if power by every non-zero element `n : ℕ` is injective. -/
@[to_additive, mk_iff]
class IsMulTorsionFree (M : Type*) [Monoid M] where
protected pow_left_injective ⦃n : ℕ⦄ (hn : n ≠ 0) : Injective fun a : M ↦ a ^ n
attribute [to_additive existing] isMulTorsionFree_iff
/-- An additive commutative monoid is an additive monoid with commutative `(+)`. -/
class AddCommMonoid (M : Type u) extends AddMonoid M, AddCommSemigroup M
/-- A commutative monoid is a monoid with commutative `(*)`. -/
@[to_additive]
class CommMonoid (M : Type u) extends Monoid M, CommSemigroup M
section LeftCancelMonoid
/-- An additive monoid in which addition is left-cancellative.
Main examples are `ℕ` and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so `AddLeftCancelSemigroup` is not enough. -/
class AddLeftCancelMonoid (M : Type u) extends AddMonoid M, AddLeftCancelSemigroup M
attribute [instance 75] AddLeftCancelMonoid.toAddMonoid -- See note [lower cancel priority]
/-- A monoid in which multiplication is left-cancellative. -/
@[to_additive]
class LeftCancelMonoid (M : Type u) extends Monoid M, LeftCancelSemigroup M
attribute [instance 75] LeftCancelMonoid.toMonoid -- See note [lower cancel priority]
end LeftCancelMonoid
section RightCancelMonoid
/-- An additive monoid in which addition is right-cancellative.
Main examples are `ℕ` and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so `AddRightCancelSemigroup` is not enough. -/
class AddRightCancelMonoid (M : Type u) extends AddMonoid M, AddRightCancelSemigroup M
attribute [instance 75] AddRightCancelMonoid.toAddMonoid -- See note [lower cancel priority]
/-- A monoid in which multiplication is right-cancellative. -/
@[to_additive]
class RightCancelMonoid (M : Type u) extends Monoid M, RightCancelSemigroup M
attribute [instance 75] RightCancelMonoid.toMonoid -- See note [lower cancel priority]
end RightCancelMonoid
section CancelMonoid
/-- An additive monoid in which addition is cancellative on both sides.
Main examples are `ℕ` and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so `AddRightCancelMonoid` is not enough. -/
class AddCancelMonoid (M : Type u) extends AddLeftCancelMonoid M, AddRightCancelMonoid M
/-- A monoid in which multiplication is cancellative. -/
@[to_additive]
class CancelMonoid (M : Type u) extends LeftCancelMonoid M, RightCancelMonoid M
/-- Commutative version of `AddCancelMonoid`. -/
class AddCancelCommMonoid (M : Type u) extends AddCommMonoid M, AddLeftCancelMonoid M
attribute [instance 75] AddCancelCommMonoid.toAddCommMonoid -- See note [lower cancel priority]
/-- Commutative version of `CancelMonoid`. -/
@[to_additive]
class CancelCommMonoid (M : Type u) extends CommMonoid M, LeftCancelMonoid M
attribute [instance 75] CancelCommMonoid.toCommMonoid -- See note [lower cancel priority]
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) CancelCommMonoid.toCancelMonoid (M : Type u) [CancelCommMonoid M] :
CancelMonoid M :=
{ CommMagma.IsLeftCancelMul.toIsRightCancelMul M with }
/-- Any `CancelMonoid G` satisfies `IsCancelMul G`. -/
@[to_additive /-- Any `AddCancelMonoid G` satisfies `IsCancelAdd G`. -/]
instance (priority := 100) CancelMonoid.toIsCancelMul (M : Type u) [CancelMonoid M] :
IsCancelMul M where
end CancelMonoid
/-- The fundamental power operation in a group. `zpowRec n a = a*a*...*a` n times, for integer `n`.
Use instead `a ^ n`, which has better definitional behavior. -/
def zpowRec [One G] [Mul G] [Inv G] (npow : ℕ → G → G := npowRec) : ℤ → G → G
| Int.ofNat n, a => npow n a
| Int.negSucc n, a => (npow n.succ a)⁻¹
/-- The fundamental scalar multiplication in an additive group. `zpowRec n a = a+a+...+a` n
times, for integer `n`. Use instead `n • a`, which has better definitional behavior. -/
def zsmulRec [Zero G] [Add G] [Neg G] (nsmul : ℕ → G → G := nsmulRec) : ℤ → G → G
| Int.ofNat n, a => nsmul n a
| Int.negSucc n, a => -nsmul n.succ a
attribute [to_additive existing] zpowRec
section InvolutiveInv
/-- Auxiliary typeclass for types with an involutive `Neg`. -/
class InvolutiveNeg (A : Type*) extends Neg A where
protected neg_neg : ∀ x : A, - -x = x
/-- Auxiliary typeclass for types with an involutive `Inv`. -/
@[to_additive]
class InvolutiveInv (G : Type*) extends Inv G where
protected inv_inv : ∀ x : G, x⁻¹⁻¹ = x
variable [InvolutiveInv G]
@[to_additive (attr := simp)]
theorem inv_inv (a : G) : a⁻¹⁻¹ = a :=
InvolutiveInv.inv_inv _
end InvolutiveInv
/-!
### Design note on `DivInvMonoid`/`SubNegMonoid` and `DivisionMonoid`/`SubtractionMonoid`
Those two pairs of made-up classes fulfill slightly different roles.
`DivInvMonoid`/`SubNegMonoid` provides the minimum amount of information to define the
`ℤ` action (`zpow` or `zsmul`). Further, it provides a `div` field, matching the forgetful
inheritance pattern. This is useful to shorten extension clauses of stronger structures (`Group`,
`GroupWithZero`, `DivisionRing`, `Field`) and for a few structures with a rather weak
pseudo-inverse (`Matrix`).
`DivisionMonoid`/`SubtractionMonoid` is targeted at structures with stronger pseudo-inverses. It
is an ad hoc collection of axioms that are mainly respected by three things:
* Groups
* Groups with zero
* The pointwise monoids `Set α`, `Finset α`, `Filter α`
It acts as a middle ground for structures with an inversion operator that plays well with
multiplication, except for the fact that it might not be a true inverse (`a / a ≠ 1` in general).
The axioms are pretty arbitrary (many other combinations are equivalent to it), but they are
independent:
* Without `DivisionMonoid.div_eq_mul_inv`, you can define `/` arbitrarily.
* Without `DivisionMonoid.inv_inv`, you can consider `WithTop Unit` with `a⁻¹ = ⊤` for all `a`.
* Without `DivisionMonoid.mul_inv_rev`, you can consider `WithTop α` with `a⁻¹ = a` for all `a`
where `α` noncommutative.
* Without `DivisionMonoid.inv_eq_of_mul`, you can consider any `CommMonoid` with `a⁻¹ = a` for all
`a`.
As a consequence, a few natural structures do not fit in this framework. For example, `ENNReal`
respects everything except for the fact that `(0 * ∞)⁻¹ = 0⁻¹ = ∞` while `∞⁻¹ * 0⁻¹ = 0 * ∞ = 0`.
-/
/-- In a class equipped with instances of both `Monoid` and `Inv`, this definition records what the
default definition for `Div` would be: `a * b⁻¹`. This is later provided as the default value for
the `Div` instance in `DivInvMonoid`.
We keep it as a separate definition rather than inlining it in `DivInvMonoid` so that the `Div`
field of individual `DivInvMonoid`s constructed using that default value will not be unfolded at
`.instance` transparency. -/
def DivInvMonoid.div' {G : Type u} [Monoid G] [Inv G] (a b : G) : G := a * b⁻¹
/-- A `DivInvMonoid` is a `Monoid` with operations `/` and `⁻¹` satisfying
`div_eq_mul_inv : ∀ a b, a / b = a * b⁻¹`.
This deduplicates the name `div_eq_mul_inv`.
The default for `div` is such that `a / b = a * b⁻¹` holds by definition.
Adding `div` as a field rather than defining `a / b := a * b⁻¹` allows us to
avoid certain classes of unification failures, for example:
Let `Foo X` be a type with a `∀ X, Div (Foo X)` instance but no
`∀ X, Inv (Foo X)`, e.g. when `Foo X` is a `EuclideanDomain`. Suppose we
also have an instance `∀ X [Cromulent X], GroupWithZero (Foo X)`. Then the
`(/)` coming from `GroupWithZero.div` cannot be definitionally equal to
the `(/)` coming from `Foo.Div`.
In the same way, adding a `zpow` field makes it possible to avoid definitional failures
in diamonds. See the definition of `Monoid` and Note [forgetful inheritance] for more
explanations on this.
-/
class DivInvMonoid (G : Type u) extends Monoid G, Inv G, Div G where
protected div := DivInvMonoid.div'
/-- `a / b := a * b⁻¹` -/
protected div_eq_mul_inv : ∀ a b : G, a / b = a * b⁻¹ := by intros; rfl
/-- The power operation: `a ^ n = a * ··· * a`; `a ^ (-n) = a⁻¹ * ··· a⁻¹` (`n` times) -/
protected zpow : ℤ → G → G := zpowRec npowRec
/-- `a ^ 0 = 1` -/
protected zpow_zero' : ∀ a : G, zpow 0 a = 1 := by intros; rfl
/-- `a ^ (n + 1) = a ^ n * a` -/
protected zpow_succ' (n : ℕ) (a : G) : zpow n.succ a = zpow n a * a := by
intros; rfl
/-- `a ^ -(n + 1) = (a ^ (n + 1))⁻¹` -/
protected zpow_neg' (n : ℕ) (a : G) : zpow (Int.negSucc n) a = (zpow n.succ a)⁻¹ := by intros; rfl
/-- In a class equipped with instances of both `AddMonoid` and `Neg`, this definition records what
the default definition for `Sub` would be: `a + -b`. This is later provided as the default value
for the `Sub` instance in `SubNegMonoid`.
We keep it as a separate definition rather than inlining it in `SubNegMonoid` so that the `Sub`
field of individual `SubNegMonoid`s constructed using that default value will not be unfolded at
`.instance` transparency. -/
def SubNegMonoid.sub' {G : Type u} [AddMonoid G] [Neg G] (a b : G) : G := a + -b
attribute [to_additive existing SubNegMonoid.sub'] DivInvMonoid.div'
/-- A `SubNegMonoid` is an `AddMonoid` with unary `-` and binary `-` operations
satisfying `sub_eq_add_neg : ∀ a b, a - b = a + -b`.
The default for `sub` is such that `a - b = a + -b` holds by definition.
Adding `sub` as a field rather than defining `a - b := a + -b` allows us to
avoid certain classes of unification failures, for example:
Let `foo X` be a type with a `∀ X, Sub (Foo X)` instance but no
`∀ X, Neg (Foo X)`. Suppose we also have an instance
`∀ X [Cromulent X], AddGroup (Foo X)`. Then the `(-)` coming from
`AddGroup.sub` cannot be definitionally equal to the `(-)` coming from
`Foo.Sub`.
In the same way, adding a `zsmul` field makes it possible to avoid definitional failures
in diamonds. See the definition of `AddMonoid` and Note [forgetful inheritance] for more
explanations on this.
-/
class SubNegMonoid (G : Type u) extends AddMonoid G, Neg G, Sub G where
protected sub := SubNegMonoid.sub'
protected sub_eq_add_neg : ∀ a b : G, a - b = a + -b := by intros; rfl
/-- Multiplication by an integer.
Set this to `zsmulRec` unless `Module` diamonds are possible. -/
protected zsmul : ℤ → G → G
protected zsmul_zero' : ∀ a : G, zsmul 0 a = 0 := by intros; rfl
protected zsmul_succ' (n : ℕ) (a : G) :
zsmul n.succ a = zsmul n a + a := by
intros; rfl
protected zsmul_neg' (n : ℕ) (a : G) : zsmul (Int.negSucc n) a = -zsmul n.succ a := by
intros; rfl
attribute [to_additive SubNegMonoid] DivInvMonoid
instance DivInvMonoid.toZPow {M} [DivInvMonoid M] : Pow M ℤ :=
⟨fun x n ↦ DivInvMonoid.zpow n x⟩
instance SubNegMonoid.toZSMul {M} [SubNegMonoid M] : SMul ℤ M :=
⟨SubNegMonoid.zsmul⟩
attribute [to_additive existing] DivInvMonoid.toZPow
/-- A group is called *cyclic* if it is generated by a single element. -/
class IsAddCyclic (G : Type u) [SMul ℤ G] : Prop where
protected exists_zsmul_surjective : ∃ g : G, Function.Surjective (· • g : ℤ → G)
/-- A group is called *cyclic* if it is generated by a single element. -/
@[to_additive]
class IsCyclic (G : Type u) [Pow G ℤ] : Prop where
protected exists_zpow_surjective : ∃ g : G, Function.Surjective (g ^ · : ℤ → G)
@[to_additive]
theorem exists_zpow_surjective (G : Type*) [Pow G ℤ] [IsCyclic G] :
∃ g : G, Function.Surjective (g ^ · : ℤ → G) :=
IsCyclic.exists_zpow_surjective
section DivInvMonoid
variable [DivInvMonoid G]
@[to_additive (attr := simp) zsmul_eq_smul] theorem zpow_eq_pow (n : ℤ) (x : G) :
DivInvMonoid.zpow n x = x ^ n :=
rfl
@[to_additive (attr := simp) zero_zsmul] theorem zpow_zero (a : G) : a ^ (0 : ℤ) = 1 :=
DivInvMonoid.zpow_zero' a
@[to_additive (attr := simp, norm_cast) natCast_zsmul]
theorem zpow_natCast (a : G) : ∀ n : ℕ, a ^ (n : ℤ) = a ^ n
| 0 => (zpow_zero _).trans (pow_zero _).symm
| n + 1 => calc
a ^ (↑(n + 1) : ℤ) = a ^ (n : ℤ) * a := DivInvMonoid.zpow_succ' _ _
_ = a ^ n * a := congrArg (· * a) (zpow_natCast a n)
_ = a ^ (n + 1) := (pow_succ _ _).symm
@[to_additive ofNat_zsmul]
lemma zpow_ofNat (a : G) (n : ℕ) : a ^ (ofNat(n) : ℤ) = a ^ OfNat.ofNat n :=
zpow_natCast ..
theorem zpow_negSucc (a : G) (n : ℕ) : a ^ (Int.negSucc n) = (a ^ (n + 1))⁻¹ := by
rw [← zpow_natCast]
exact DivInvMonoid.zpow_neg' n a
theorem negSucc_zsmul {G} [SubNegMonoid G] (a : G) (n : ℕ) :
Int.negSucc n • a = -((n + 1) • a) := by
rw [← natCast_zsmul]
exact SubNegMonoid.zsmul_neg' n a
attribute [to_additive existing (attr := simp) negSucc_zsmul] zpow_negSucc
/-- Dividing by an element is the same as multiplying by its inverse.
This is a duplicate of `DivInvMonoid.div_eq_mul_inv` ensuring that the types unfold better.
-/
@[to_additive /-- Subtracting an element is the same as adding by its negative.
This is a duplicate of `SubNegMonoid.sub_eq_add_neg` ensuring that the types unfold better. -/]
theorem div_eq_mul_inv (a b : G) : a / b = a * b⁻¹ :=
DivInvMonoid.div_eq_mul_inv _ _
alias division_def := div_eq_mul_inv
@[to_additive]
theorem inv_eq_one_div (x : G) : x⁻¹ = 1 / x := by rw [div_eq_mul_inv, one_mul]
@[to_additive]
theorem mul_div_assoc (a b c : G) : a * b / c = a * (b / c) := by
rw [div_eq_mul_inv, div_eq_mul_inv, mul_assoc _ _ _]
@[to_additive (attr := simp)]
theorem one_div (a : G) : 1 / a = a⁻¹ :=
(inv_eq_one_div a).symm
@[to_additive (attr := simp) one_zsmul]
lemma zpow_one (a : G) : a ^ (1 : ℤ) = a := by rw [zpow_ofNat, pow_one]
@[to_additive two_zsmul] lemma zpow_two (a : G) : a ^ (2 : ℤ) = a * a := by rw [zpow_ofNat, pow_two]
@[to_additive neg_one_zsmul]
lemma zpow_neg_one (x : G) : x ^ (-1 : ℤ) = x⁻¹ :=
(zpow_negSucc x 0).trans <| congr_arg Inv.inv (pow_one x)
@[to_additive]
lemma zpow_neg_coe_of_pos (a : G) : ∀ {n : ℕ}, 0 < n → a ^ (-(n : ℤ)) = (a ^ n)⁻¹
| _ + 1, _ => zpow_negSucc _ _
end DivInvMonoid
section InvOneClass
/-- Typeclass for expressing that `-0 = 0`. -/
class NegZeroClass (G : Type*) extends Zero G, Neg G where
protected neg_zero : -(0 : G) = 0
/-- A `SubNegMonoid` where `-0 = 0`. -/
class SubNegZeroMonoid (G : Type*) extends SubNegMonoid G, NegZeroClass G
/-- Typeclass for expressing that `1⁻¹ = 1`. -/
@[to_additive]
class InvOneClass (G : Type*) extends One G, Inv G where
protected inv_one : (1 : G)⁻¹ = 1
/-- A `DivInvMonoid` where `1⁻¹ = 1`. -/
@[to_additive]
class DivInvOneMonoid (G : Type*) extends DivInvMonoid G, InvOneClass G
variable [InvOneClass G]
@[to_additive (attr := simp)]
theorem inv_one : (1 : G)⁻¹ = 1 :=
InvOneClass.inv_one
end InvOneClass
/-- A `SubtractionMonoid` is a `SubNegMonoid` with involutive negation and such that
`-(a + b) = -b + -a` and `a + b = 0 → -a = b`. -/
class SubtractionMonoid (G : Type u) extends SubNegMonoid G, InvolutiveNeg G where
protected neg_add_rev (a b : G) : -(a + b) = -b + -a
/-- Despite the asymmetry of `neg_eq_of_add`, the symmetric version is true thanks to the
involutivity of negation. -/
protected neg_eq_of_add (a b : G) : a + b = 0 → -a = b
/-- A `DivisionMonoid` is a `DivInvMonoid` with involutive inversion and such that
`(a * b)⁻¹ = b⁻¹ * a⁻¹` and `a * b = 1 → a⁻¹ = b`.
This is the immediate common ancestor of `Group` and `GroupWithZero`. -/
@[to_additive]
class DivisionMonoid (G : Type u) extends DivInvMonoid G, InvolutiveInv G where
protected mul_inv_rev (a b : G) : (a * b)⁻¹ = b⁻¹ * a⁻¹
/-- Despite the asymmetry of `inv_eq_of_mul`, the symmetric version is true thanks to the
involutivity of inversion. -/
protected inv_eq_of_mul (a b : G) : a * b = 1 → a⁻¹ = b
section DivisionMonoid
variable [DivisionMonoid G] {a b : G}
@[to_additive (attr := simp) neg_add_rev]
theorem mul_inv_rev (a b : G) : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=
DivisionMonoid.mul_inv_rev _ _
@[to_additive]
theorem inv_eq_of_mul_eq_one_right : a * b = 1 → a⁻¹ = b :=
DivisionMonoid.inv_eq_of_mul _ _
@[to_additive]
theorem inv_eq_of_mul_eq_one_left (h : a * b = 1) : b⁻¹ = a := by
rw [← inv_eq_of_mul_eq_one_right h, inv_inv]
@[to_additive]
theorem eq_inv_of_mul_eq_one_left (h : a * b = 1) : a = b⁻¹ :=
(inv_eq_of_mul_eq_one_left h).symm
end DivisionMonoid
/-- Commutative `SubtractionMonoid`. -/
class SubtractionCommMonoid (G : Type u) extends SubtractionMonoid G, AddCommMonoid G
/-- Commutative `DivisionMonoid`.
This is the immediate common ancestor of `CommGroup` and `CommGroupWithZero`. -/
@[to_additive SubtractionCommMonoid]
class DivisionCommMonoid (G : Type u) extends DivisionMonoid G, CommMonoid G
/-- A `Group` is a `Monoid` with an operation `⁻¹` satisfying `a⁻¹ * a = 1`.
There is also a division operation `/` such that `a / b = a * b⁻¹`,
with a default so that `a / b = a * b⁻¹` holds by definition.
Use `Group.ofLeftAxioms` or `Group.ofRightAxioms` to define a group structure
on a type with the minimum proof obligations.
-/
class Group (G : Type u) extends DivInvMonoid G where
protected inv_mul_cancel : ∀ a : G, a⁻¹ * a = 1
/-- An `AddGroup` is an `AddMonoid` with a unary `-` satisfying `-a + a = 0`.
There is also a binary operation `-` such that `a - b = a + -b`,
with a default so that `a - b = a + -b` holds by definition.
Use `AddGroup.ofLeftAxioms` or `AddGroup.ofRightAxioms` to define an
additive group structure on a type with the minimum proof obligations.
-/
class AddGroup (A : Type u) extends SubNegMonoid A where
protected neg_add_cancel : ∀ a : A, -a + a = 0
attribute [to_additive] Group
section Group
variable [Group G] {a b : G}
@[to_additive (attr := simp)]
theorem inv_mul_cancel (a : G) : a⁻¹ * a = 1 :=
Group.inv_mul_cancel a
@[to_additive]
private theorem inv_eq_of_mul (h : a * b = 1) : a⁻¹ = b :=
left_inv_eq_right_inv (inv_mul_cancel a) h
@[to_additive (attr := simp)]
theorem mul_inv_cancel (a : G) : a * a⁻¹ = 1 := by
rw [← inv_mul_cancel a⁻¹, inv_eq_of_mul (inv_mul_cancel a)]
@[to_additive (attr := simp) sub_self]
theorem div_self' (a : G) : a / a = 1 := by rw [div_eq_mul_inv, mul_inv_cancel a]
@[to_additive (attr := simp)]
theorem inv_mul_cancel_left (a b : G) : a⁻¹ * (a * b) = b := by
rw [← mul_assoc, inv_mul_cancel, one_mul]
@[to_additive (attr := simp)]
theorem mul_inv_cancel_left (a b : G) : a * (a⁻¹ * b) = b := by
rw [← mul_assoc, mul_inv_cancel, one_mul]
@[to_additive (attr := simp)]
theorem mul_inv_cancel_right (a b : G) : a * b * b⁻¹ = a := by
rw [mul_assoc, mul_inv_cancel, mul_one]
@[to_additive (attr := simp)]
theorem mul_div_cancel_right (a b : G) : a * b / b = a := by
rw [div_eq_mul_inv, mul_inv_cancel_right a b]
@[to_additive (attr := simp)]
theorem inv_mul_cancel_right (a b : G) : a * b⁻¹ * b = a := by
rw [mul_assoc, inv_mul_cancel, mul_one]
@[to_additive (attr := simp)]
theorem div_mul_cancel (a b : G) : a / b * b = a := by
rw [div_eq_mul_inv, inv_mul_cancel_right a b]
@[to_additive]
instance (priority := 100) Group.toDivisionMonoid : DivisionMonoid G :=
{ inv_inv := fun a ↦ inv_eq_of_mul (inv_mul_cancel a)
mul_inv_rev :=
fun a b ↦ inv_eq_of_mul <| by rw [mul_assoc, mul_inv_cancel_left, mul_inv_cancel]
inv_eq_of_mul := fun _ _ ↦ inv_eq_of_mul }
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) Group.toCancelMonoid : CancelMonoid G where
mul_right_cancel := fun a b c h ↦ by
rw [← mul_inv_cancel_right b a, show b * a = c * a from h, mul_inv_cancel_right]
mul_left_cancel := fun a {b c} h ↦ by
rw [← inv_mul_cancel_left a b, show a * b = a * c from h, inv_mul_cancel_left]
end Group
/-- An additive commutative group is an additive group with commutative `(+)`. -/
class AddCommGroup (G : Type u) extends AddGroup G, AddCommMonoid G
/-- A commutative group is a group with commutative `(*)`. -/
@[to_additive]
class CommGroup (G : Type u) extends Group G, CommMonoid G
section CommGroup
variable [CommGroup G]
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) CommGroup.toCancelCommMonoid : CancelCommMonoid G :=
{ ‹CommGroup G›, Group.toCancelMonoid with }
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) CommGroup.toDivisionCommMonoid : DivisionCommMonoid G :=
{ ‹CommGroup G›, Group.toDivisionMonoid with }
@[to_additive (attr := simp)] lemma inv_mul_cancel_comm (a b : G) : a⁻¹ * b * a = b := by
rw [mul_comm, mul_inv_cancel_left]
@[to_additive (attr := simp)]
lemma mul_inv_cancel_comm (a b : G) : a * b * a⁻¹ = b := by rw [mul_comm, inv_mul_cancel_left]
@[to_additive (attr := simp)] lemma inv_mul_cancel_comm_assoc (a b : G) : a⁻¹ * (b * a) = b := by
rw [mul_comm, mul_inv_cancel_right]
@[to_additive (attr := simp)] lemma mul_inv_cancel_comm_assoc (a b : G) : a * (b * a⁻¹) = b := by
rw [mul_comm, inv_mul_cancel_right]
end CommGroup
section IsCommutative
/-- A Prop stating that the addition is commutative. -/
class IsAddCommutative (M : Type*) [Add M] : Prop where
is_comm : Std.Commutative (α := M) (· + ·)
/-- A Prop stating that the multiplication is commutative. -/
@[to_additive]
class IsMulCommutative (M : Type*) [Mul M] : Prop where
is_comm : Std.Commutative (α := M) (· * ·)
@[to_additive]
instance (priority := 100) CommMonoid.ofIsMulCommutative {M : Type*} [Monoid M]
[IsMulCommutative M] :
CommMonoid M where
mul_comm := IsMulCommutative.is_comm.comm
@[to_additive]
instance (priority := 100) CommGroup.ofIsMulCommutative {G : Type*} [Group G] [IsMulCommutative G] :
CommGroup G where
end IsCommutative
/-! We initialize all projections for `@[simps]` here, so that we don't have to do it in later
files.
Note: the lemmas generated for the `npow`/`zpow` projections will *not* apply to `x ^ y`, since the
argument order of these projections doesn't match the argument order of `^`.
The `nsmul`/`zsmul` lemmas will be correct. -/
initialize_simps_projections Semigroup
initialize_simps_projections AddSemigroup
initialize_simps_projections CommSemigroup
initialize_simps_projections AddCommSemigroup
initialize_simps_projections LeftCancelSemigroup
initialize_simps_projections AddLeftCancelSemigroup
initialize_simps_projections RightCancelSemigroup
initialize_simps_projections AddRightCancelSemigroup
initialize_simps_projections Monoid
initialize_simps_projections AddMonoid
initialize_simps_projections CommMonoid
initialize_simps_projections AddCommMonoid
initialize_simps_projections LeftCancelMonoid
initialize_simps_projections AddLeftCancelMonoid
initialize_simps_projections RightCancelMonoid
initialize_simps_projections AddRightCancelMonoid
initialize_simps_projections CancelMonoid
initialize_simps_projections AddCancelMonoid
initialize_simps_projections CancelCommMonoid
initialize_simps_projections AddCancelCommMonoid
initialize_simps_projections DivInvMonoid
initialize_simps_projections SubNegMonoid
initialize_simps_projections DivInvOneMonoid
initialize_simps_projections SubNegZeroMonoid
initialize_simps_projections DivisionMonoid
initialize_simps_projections SubtractionMonoid
initialize_simps_projections DivisionCommMonoid
initialize_simps_projections SubtractionCommMonoid
initialize_simps_projections Group
initialize_simps_projections AddGroup
initialize_simps_projections CommGroup
initialize_simps_projections AddCommGroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Shrink.lean | import Mathlib.Algebra.Group.Action.TransferInstance
import Mathlib.Logic.Small.Defs
import Mathlib.Tactic.SuppressCompilation
/-!
# Transfer group structures from `α` to `Shrink α`
-/
-- FIXME: `to_additive` is incompatible with `noncomputable section`.
-- See https://github.com/leanprover-community/mathlib4/issues/1074.
suppress_compilation
universe v
variable {M α : Type*} [Small.{v} α]
namespace Shrink
@[to_additive] instance [One α] : One (Shrink.{v} α) := (equivShrink α).symm.one
@[to_additive] instance [Mul α] : Mul (Shrink.{v} α) := (equivShrink α).symm.mul
@[to_additive] instance [Div α] : Div (Shrink.{v} α) := (equivShrink α).symm.div
@[to_additive] instance [Inv α] : Inv (Shrink.{v} α) := (equivShrink α).symm.Inv
@[to_additive] instance [Pow α M] : Pow (Shrink.{v} α) M := (equivShrink α).symm.pow M
end Shrink
@[to_additive (attr := simp)]
lemma equivShrink_symm_one [One α] : (equivShrink α).symm 1 = 1 :=
(equivShrink α).symm_apply_apply 1
@[to_additive (attr := simp)]
lemma equivShrink_symm_mul [Mul α] (x y : Shrink α) :
(equivShrink α).symm (x * y) = (equivShrink α).symm x * (equivShrink α).symm y := by
simp [Equiv.mul_def]
@[to_additive (attr := simp)]
lemma equivShrink_mul [Mul α] (x y : α) :
equivShrink α (x * y) = equivShrink α x * equivShrink α y := by
simp [Equiv.mul_def]
@[simp]
lemma equivShrink_symm_smul {M : Type*} [SMul M α] (m : M) (x : Shrink α) :
(equivShrink α).symm (m • x) = m • (equivShrink α).symm x := by
simp [Equiv.smul_def]
@[simp]
lemma equivShrink_smul {M : Type*} [SMul M α] (m : M) (x : α) :
equivShrink α (m • x) = m • equivShrink α x := by
simp [Equiv.smul_def]
@[to_additive (attr := simp)]
lemma equivShrink_symm_div [Div α] (x y : Shrink α) :
(equivShrink α).symm (x / y) = (equivShrink α).symm x / (equivShrink α).symm y := by
simp [Equiv.div_def]
@[to_additive (attr := simp)]
lemma equivShrink_div [Div α] (x y : α) :
equivShrink α (x / y) = equivShrink α x / equivShrink α y := by
simp [Equiv.div_def]
@[to_additive (attr := simp)]
lemma equivShrink_symm_inv [Inv α] (x : Shrink α) :
(equivShrink α).symm x⁻¹ = ((equivShrink α).symm x)⁻¹ := by
simp [Equiv.inv_def]
@[to_additive (attr := simp)]
lemma equivShrink_inv [Inv α] (x : α) : equivShrink α x⁻¹ = (equivShrink α x)⁻¹ := by
simp [Equiv.inv_def]
namespace Shrink
/-- Shrink `α` to a smaller universe preserves multiplication. -/
@[to_additive /-- Shrink `α` to a smaller universe preserves addition. -/]
def mulEquiv [Mul α] : Shrink.{v} α ≃* α := (equivShrink α).symm.mulEquiv
@[to_additive]
instance [Semigroup α] : Semigroup (Shrink.{v} α) := (equivShrink α).symm.semigroup
@[to_additive]
instance [CommSemigroup α] : CommSemigroup (Shrink.{v} α) := (equivShrink α).symm.commSemigroup
@[to_additive]
instance [Mul α] [IsLeftCancelMul α] : IsLeftCancelMul (Shrink.{v} α) :=
(equivShrink α).symm.isLeftCancelMul
@[to_additive]
instance [Mul α] [IsRightCancelMul α] : IsRightCancelMul (Shrink.{v} α) :=
(equivShrink α).symm.isRightCancelMul
@[to_additive]
instance [Mul α] [IsCancelMul α] : IsCancelMul (Shrink.{v} α) := (equivShrink α).symm.isCancelMul
@[to_additive]
instance [MulOneClass α] : MulOneClass (Shrink.{v} α) := (equivShrink α).symm.mulOneClass
@[to_additive]
instance [Monoid α] : Monoid (Shrink.{v} α) := (equivShrink α).symm.monoid
@[to_additive]
instance [CommMonoid α] : CommMonoid (Shrink.{v} α) := (equivShrink α).symm.commMonoid
@[to_additive]
instance [Group α] : Group (Shrink.{v} α) := (equivShrink α).symm.group
@[to_additive]
instance [CommGroup α] : CommGroup (Shrink.{v} α) := (equivShrink α).symm.commGroup
@[to_additive]
instance [Monoid M] [MulAction M α] : MulAction M (Shrink.{v} α) := (equivShrink α).symm.mulAction M
end Shrink |
.lake/packages/mathlib/Mathlib/Algebra/Group/Finsupp.lean | import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Data.Finset.Max
import Mathlib.Data.Finsupp.Single
/-!
# Additive monoid structure on `ι →₀ M`
-/
assert_not_exists MonoidWithZero
open Finset
noncomputable section
variable {ι F M N O G H : Type*}
namespace Finsupp
section Zero
variable [Zero M] [Zero N] [Zero O]
lemma apply_single [FunLike F M N] [ZeroHomClass F M N] (e : F) (i : ι) (m : M) (b : ι) :
e (single i m b) = single i (e m) b := apply_single' e (map_zero e) i m b
/-- Composition with a fixed zero-preserving homomorphism is itself a zero-preserving homomorphism
on functions. -/
@[simps]
def mapRange.zeroHom (f : ZeroHom M N) : ZeroHom (ι →₀ M) (ι →₀ N) where
toFun := Finsupp.mapRange f f.map_zero
map_zero' := mapRange_zero
@[simp] lemma mapRange.zeroHom_id : mapRange.zeroHom (.id M) = .id (ι →₀ M) := by ext; simp
lemma mapRange.zeroHom_comp (f : ZeroHom N O) (f₂ : ZeroHom M N) :
mapRange.zeroHom (ι := ι) (f.comp f₂) = (mapRange.zeroHom f).comp (mapRange.zeroHom f₂) := by
ext; simp
end Zero
section AddZeroClass
variable [AddZeroClass M] [AddZeroClass N] {f : M → N} {g₁ g₂ : ι →₀ M}
instance instAdd : Add (ι →₀ M) where add := zipWith (· + ·) (add_zero 0)
@[simp, norm_cast] lemma coe_add (f g : ι →₀ M) : ⇑(f + g) = f + g := rfl
lemma add_apply (g₁ g₂ : ι →₀ M) (a : ι) : (g₁ + g₂) a = g₁ a + g₂ a := rfl
lemma support_add [DecidableEq ι] : (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support := support_zipWith
lemma support_add_eq [DecidableEq ι] (h : Disjoint g₁.support g₂.support) :
(g₁ + g₂).support = g₁.support ∪ g₂.support :=
le_antisymm support_zipWith fun a ha => by
cases (Finset.mem_union_of_disjoint h).mp ha <;> simp_all
instance instAddZeroClass : AddZeroClass (ι →₀ M) :=
fast_instance% DFunLike.coe_injective.addZeroClass _ coe_zero coe_add
instance instIsLeftCancelAdd [IsLeftCancelAdd M] : IsLeftCancelAdd (ι →₀ M) where
add_left_cancel _ _ _ h := ext fun x => add_left_cancel <| DFunLike.congr_fun h x
/-- When ι is finite and M is an AddMonoid,
then Finsupp.equivFunOnFinite gives an AddEquiv -/
noncomputable def addEquivFunOnFinite {ι : Type*} [Finite ι] :
(ι →₀ M) ≃+ (ι → M) where
__ := Finsupp.equivFunOnFinite
map_add' _ _ := rfl
/-- AddEquiv between (ι →₀ M) and M, when ι has a unique element -/
noncomputable def _root_.AddEquiv.finsuppUnique {ι : Type*} [Unique ι] :
(ι →₀ M) ≃+ M where
__ := Equiv.finsuppUnique
map_add' _ _ := rfl
@[simp]
lemma _root_.AddEquiv.finsuppUnique_apply {ι : Type*} [Unique ι] (v : ι →₀ M) :
AddEquiv.finsuppUnique v = Equiv.finsuppUnique v := rfl
instance instIsRightCancelAdd [IsRightCancelAdd M] : IsRightCancelAdd (ι →₀ M) where
add_right_cancel _ _ _ h := ext fun x => add_right_cancel <| DFunLike.congr_fun h x
instance instIsCancelAdd [IsCancelAdd M] : IsCancelAdd (ι →₀ M) where
/-- Evaluation of a function `f : ι →₀ M` at a point as an additive monoid homomorphism.
See `Finsupp.lapply` in `Mathlib/LinearAlgebra/Finsupp/Defs.lean` for the stronger version as a
linear map. -/
@[simps apply]
def applyAddHom (a : ι) : (ι →₀ M) →+ M where
toFun g := g a
map_zero' := zero_apply
map_add' _ _ := add_apply _ _ _
/-- Coercion from a `Finsupp` to a function type is an `AddMonoidHom`. -/
@[simps]
noncomputable def coeFnAddHom : (ι →₀ M) →+ ι → M where
toFun := (⇑)
map_zero' := coe_zero
map_add' := coe_add
lemma mapRange_add {hf : f 0 = 0} (hf' : ∀ x y, f (x + y) = f x + f y) (v₁ v₂ : ι →₀ M) :
mapRange f hf (v₁ + v₂) = mapRange f hf v₁ + mapRange f hf v₂ :=
ext fun _ => by simp only [hf', add_apply, mapRange_apply]
lemma mapRange_add' [FunLike F M N] [AddMonoidHomClass F M N] {f : F} (g₁ g₂ : ι →₀ M) :
mapRange f (map_zero f) (g₁ + g₂) = mapRange f (map_zero f) g₁ + mapRange f (map_zero f) g₂ :=
mapRange_add (map_add f) g₁ g₂
/-- Bundle `Finsupp.embDomain f` as an additive map from `ι →₀ M` to `F →₀ M`. -/
@[simps]
def embDomain.addMonoidHom (f : ι ↪ F) : (ι →₀ M) →+ F →₀ M where
toFun v := embDomain f v
map_zero' := by simp
map_add' v w := by
ext b
by_cases h : b ∈ Set.range f
· rcases h with ⟨a, rfl⟩
simp
· simp only [coe_add, Pi.add_apply, embDomain_notin_range _ _ _ h, add_zero]
@[simp]
lemma embDomain_add (f : ι ↪ F) (v w : ι →₀ M) :
embDomain f (v + w) = embDomain f v + embDomain f w := (embDomain.addMonoidHom f).map_add v w
@[simp]
lemma single_add (a : ι) (b₁ b₂ : M) : single a (b₁ + b₂) = single a b₁ + single a b₂ :=
(zipWith_single_single _ _ _ _ _).symm
lemma single_add_apply (a : ι) (m₁ m₂ : M) (b : ι) :
single a (m₁ + m₂) b = single a m₁ b + single a m₂ b := by simp
lemma support_single_add {a : ι} {b : M} {f : ι →₀ M} (ha : a ∉ f.support) (hb : b ≠ 0) :
support (single a b + f) = cons a f.support ha := by
classical
have H := support_single_ne_zero a hb
rw [support_add_eq, H, cons_eq_insert, insert_eq]
rwa [H, disjoint_singleton_left]
lemma support_add_single {a : ι} {b : M} {f : ι →₀ M} (ha : a ∉ f.support) (hb : b ≠ 0) :
support (f + single a b) = cons a f.support ha := by
classical
have H := support_single_ne_zero a hb
rw [support_add_eq, H, union_comm, cons_eq_insert, insert_eq]
rwa [H, disjoint_singleton_right]
lemma support_single_add_single [DecidableEq ι] {f₁ f₂ : ι} {g₁ g₂ : M}
(H : f₁ ≠ f₂) (hg₁ : g₁ ≠ 0) (hg₂ : g₂ ≠ 0) :
(single f₁ g₁ + single f₂ g₂).support = {f₁, f₂} := by
rw [support_add_eq, support_single_ne_zero _ hg₁, support_single_ne_zero _ hg₂]
· simp [pair_comm f₂ f₁]
· simp [support_single_ne_zero _ hg₁, support_single_ne_zero _ hg₂, H.symm]
lemma support_single_add_single_subset [DecidableEq ι] {f₁ f₂ : ι} {g₁ g₂ : M} :
(single f₁ g₁ + single f₂ g₂).support ⊆ {f₁, f₂} := by
refine subset_trans Finsupp.support_add <| union_subset_iff.mpr ⟨?_, ?_⟩ <;>
exact subset_trans Finsupp.support_single_subset (by simp)
lemma _root_.AddEquiv.finsuppUnique_symm {M : Type*} [AddZeroClass M] (d : M) :
AddEquiv.finsuppUnique.symm d = single () d := by
rw [Finsupp.unique_single (AddEquiv.finsuppUnique.symm d), Finsupp.unique_single_eq_iff]
simp [AddEquiv.finsuppUnique]
theorem addCommute_iff_inter [DecidableEq ι] {f g : ι →₀ M} :
AddCommute f g ↔ ∀ x ∈ f.support ∩ g.support, AddCommute (f x) (g x) where
mp h := fun x _ ↦ Finsupp.ext_iff.1 h x
mpr h := by
ext x
by_cases hf : x ∈ f.support
· by_cases hg : x ∈ g.support
· exact h _ (mem_inter_of_mem hf hg)
· simp_all
· simp_all
theorem addCommute_of_disjoint {f g : ι →₀ M} (h : Disjoint f.support g.support) :
AddCommute f g := by
classical simp_all [addCommute_iff_inter, Finset.disjoint_iff_inter_eq_empty]
/-- `Finsupp.single` as an `AddMonoidHom`.
See `Finsupp.lsingle` in `Mathlib/LinearAlgebra/Finsupp/Defs.lean` for the stronger version as a
linear map. -/
@[simps]
def singleAddHom (a : ι) : M →+ ι →₀ M where
toFun := single a
map_zero' := single_zero a
map_add' := single_add a
lemma update_eq_single_add_erase (f : ι →₀ M) (a : ι) (b : M) :
f.update a b = single a b + f.erase a := by
classical
ext j
rcases eq_or_ne j a with (rfl | h)
· simp
· simp [h, erase_ne]
lemma update_eq_erase_add_single (f : ι →₀ M) (a : ι) (b : M) :
f.update a b = f.erase a + single a b := by
classical
ext j
rcases eq_or_ne j a with (rfl | h)
· simp
· simp [h, erase_ne]
lemma update_eq_single_add {f : ι →₀ M} {a : ι} (h : f a = 0) (b : M) :
f.update a b = single a b + f := by
rw [update_eq_single_add_erase, erase_of_notMem_support (by simpa)]
lemma update_eq_add_single {f : ι →₀ M} {a : ι} (h : f a = 0) (b : M) :
f.update a b = f + single a b := by
rw [update_eq_erase_add_single, erase_of_notMem_support (by simpa)]
lemma single_add_erase (a : ι) (f : ι →₀ M) : single a (f a) + f.erase a = f := by
rw [← update_eq_single_add_erase, update_self]
lemma erase_add_single (a : ι) (f : ι →₀ M) : f.erase a + single a (f a) = f := by
rw [← update_eq_erase_add_single, update_self]
@[simp]
lemma erase_add (a : ι) (f f' : ι →₀ M) : erase a (f + f') = erase a f + erase a f' := by
ext s; by_cases hs : s = a
· rw [hs, add_apply, erase_same, erase_same, erase_same, add_zero]
rw [add_apply, erase_ne hs, erase_ne hs, erase_ne hs, add_apply]
/-- `Finsupp.erase` as an `AddMonoidHom`. -/
@[simps]
def eraseAddHom (a : ι) : (ι →₀ M) →+ ι →₀ M where
toFun := erase a
map_zero' := erase_zero a
map_add' := erase_add a
@[elab_as_elim]
protected lemma induction {motive : (ι →₀ M) → Prop} (f : ι →₀ M) (zero : motive 0)
(single_add : ∀ (a b) (f : ι →₀ M),
a ∉ f.support → b ≠ 0 → motive f → motive (single a b + f)) : motive f :=
suffices ∀ (s) (f : ι →₀ M), f.support = s → motive f from this _ _ rfl
fun s =>
Finset.cons_induction_on s (fun f hf => by rwa [support_eq_empty.1 hf]) fun a s has ih f hf => by
suffices motive (single a (f a) + f.erase a) by rwa [single_add_erase] at this
classical
apply single_add
· rw [support_erase, mem_erase]
exact fun H => H.1 rfl
· rw [← mem_support_iff, hf]
exact mem_cons_self _ _
· apply ih _ _
rw [support_erase, hf, Finset.erase_cons]
@[elab_as_elim]
lemma induction₂ {motive : (ι →₀ M) → Prop} (f : ι →₀ M) (zero : motive 0)
(add_single : ∀ (a b) (f : ι →₀ M),
a ∉ f.support → b ≠ 0 → motive f → motive (f + single a b)) : motive f := by
classical
refine f.induction zero ?_
convert add_single using 7
apply (addCommute_of_disjoint _).eq
simp_all [disjoint_iff_inter_eq_empty, eq_empty_iff_forall_notMem, single_apply]
@[elab_as_elim]
lemma induction_linear {motive : (ι →₀ M) → Prop} (f : ι →₀ M) (zero : motive 0)
(add : ∀ f g : ι →₀ M, motive f → motive g → motive (f + g))
(single : ∀ a b, motive (single a b)) : motive f :=
induction₂ f zero fun _a _b _f _ _ w => add _ _ w (single _ _)
section LinearOrder
variable [LinearOrder ι] {p : (ι →₀ M) → Prop}
/-- A finitely supported function can be built by adding up `single a b` for increasing `a`.
The lemma `induction_on_max₂` swaps the argument order in the sum. -/
lemma induction_on_max (f : ι →₀ M) (zero : p 0)
(single_add : ∀ a b (f : ι →₀ M), (∀ c ∈ f.support, c < a) → b ≠ 0 → p f → p (single a b + f)) :
p f := by
suffices ∀ (s) (f : ι →₀ M), f.support = s → p f from this _ _ rfl
refine fun s => s.induction_on_max (fun f h => ?_) (fun a s hm hf f hs => ?_)
· rwa [support_eq_empty.1 h]
· have hs' : (erase a f).support = s := by
rw [support_erase, hs, erase_insert (fun ha => (hm a ha).false)]
rw [← single_add_erase a f]
refine single_add _ _ _ (fun c hc => hm _ <| hs'.symm ▸ hc) ?_ (hf _ hs')
rw [← mem_support_iff, hs]
exact mem_insert_self a s
/-- A finitely supported function can be built by adding up `single a b` for decreasing `a`.
The lemma `induction_on_min₂` swaps the argument order in the sum. -/
lemma induction_on_min (f : ι →₀ M) (zero : p 0)
(single_add : ∀ a b (f : ι →₀ M), (∀ c ∈ f.support, a < c) → b ≠ 0 → p f → p (single a b + f)) :
p f :=
induction_on_max (ι := ιᵒᵈ) f zero single_add
/-- A finitely supported function can be built by adding up `single a b` for increasing `a`.
The lemma `induction_on_max` swaps the argument order in the sum. -/
lemma induction_on_max₂ (f : ι →₀ M) (zero : p 0)
(add_single : ∀ a b (f : ι →₀ M), (∀ c ∈ f.support, c < a) → b ≠ 0 → p f → p (f + single a b)) :
p f := by
classical
refine f.induction_on_max zero ?_
convert add_single using 7 with _ _ _ H
have := fun c hc ↦ (H c hc).ne
apply (addCommute_of_disjoint _).eq
simp_all [disjoint_iff_inter_eq_empty, eq_empty_iff_forall_notMem, single_apply, not_imp_not]
/-- A finitely supported function can be built by adding up `single a b` for decreasing `a`.
The lemma `induction_on_min` swaps the argument order in the sum. -/
lemma induction_on_min₂ (f : ι →₀ M) (h0 : p 0)
(ha : ∀ (a b) (f : ι →₀ M), (∀ c ∈ f.support, a < c) → b ≠ 0 → p f → p (f + single a b)) :
p f :=
induction_on_max₂ (ι := ιᵒᵈ) f h0 ha
end LinearOrder
end AddZeroClass
section AddMonoid
variable [AddMonoid M]
/-- Note the general `SMul` instance for `Finsupp` doesn't apply as `ℕ` is not distributive
unless `F i`'s addition is commutative. -/
instance instNatSMul : SMul ℕ (ι →₀ M) where smul n v := v.mapRange (n • ·) (nsmul_zero _)
@[simp, norm_cast] lemma coe_nsmul (n : ℕ) (f : ι →₀ M) : ⇑(n • f) = n • ⇑f := rfl
lemma nsmul_apply (n : ℕ) (f : ι →₀ M) (x : ι) : (n • f) x = n • f x := rfl
instance instAddMonoid : AddMonoid (ι →₀ M) :=
fast_instance% DFunLike.coe_injective.addMonoid _ coe_zero coe_add fun _ _ => rfl
instance instIsAddTorsionFree [IsAddTorsionFree M] : IsAddTorsionFree (ι →₀ M) :=
DFunLike.coe_injective.isAddTorsionFree coeFnAddHom
end AddMonoid
section AddCommMonoid
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid O]
instance instAddCommMonoid : AddCommMonoid (ι →₀ M) :=
fast_instance% DFunLike.coe_injective.addCommMonoid
DFunLike.coe coe_zero coe_add (fun _ _ => rfl)
lemma single_add_single_eq_single_add_single {k l m n : ι} {u v : M} (hu : u ≠ 0) (hv : v ≠ 0) :
single k u + single l v = single m u + single n v ↔
(k = m ∧ l = n) ∨ (u = v ∧ k = n ∧ l = m) ∨ (u + v = 0 ∧ k = l ∧ m = n) := by
classical
simp_rw [DFunLike.ext_iff, coe_add, single_eq_pi_single, ← funext_iff]
exact Pi.single_add_single_eq_single_add_single hu hv
/-- Composition with a fixed additive homomorphism is itself an additive homomorphism on functions.
-/
@[simps]
def mapRange.addMonoidHom (f : M →+ N) : (ι →₀ M) →+ ι →₀ N where
toFun := mapRange f f.map_zero
map_zero' := mapRange_zero
map_add' := mapRange_add f.map_add
@[simp]
lemma mapRange.addMonoidHom_id :
mapRange.addMonoidHom (AddMonoidHom.id M) = AddMonoidHom.id (ι →₀ M) :=
AddMonoidHom.ext mapRange_id
lemma mapRange.addMonoidHom_comp (f : N →+ O) (g : M →+ N) :
mapRange.addMonoidHom (ι := ι) (f.comp g) =
(mapRange.addMonoidHom f).comp (mapRange.addMonoidHom g) := by ext; simp
@[simp]
lemma mapRange.addMonoidHom_toZeroHom (f : M →+ N) :
(mapRange.addMonoidHom f).toZeroHom = mapRange.zeroHom (ι := ι) f.toZeroHom := rfl
/-- `Finsupp.mapRange.AddMonoidHom` as an equiv. -/
@[simps! apply]
def mapRange.addEquiv (em' : M ≃+ N) : (ι →₀ M) ≃+ (ι →₀ N) where
toEquiv := mapRange.equiv em' em'.map_zero
__ := mapRange.addMonoidHom em'.toAddMonoidHom
@[simp]
lemma mapRange.addEquiv_refl : mapRange.addEquiv (.refl M) = .refl (ι →₀ M) := by ext; simp
lemma mapRange.addEquiv_trans (e₁ : M ≃+ N) (e₂ : N ≃+ O) :
mapRange.addEquiv (ι := ι) (e₁.trans e₂) =
(mapRange.addEquiv e₁).trans (mapRange.addEquiv e₂) := by ext; simp
@[simp]
lemma mapRange.addEquiv_symm (e : M ≃+ N) :
(mapRange.addEquiv (ι := ι) e).symm = mapRange.addEquiv e.symm := rfl
@[simp]
lemma mapRange.addEquiv_toAddMonoidHom (e : M ≃+ N) :
mapRange.addEquiv (ι := ι) e = mapRange.addMonoidHom (ι := ι) e.toAddMonoidHom := rfl
@[simp]
lemma mapRange.addEquiv_toEquiv (e : M ≃+ N) :
mapRange.addEquiv (ι := ι) e = mapRange.equiv (ι := ι) (e : M ≃ N) e.map_zero := rfl
end AddCommMonoid
instance instNeg [NegZeroClass G] : Neg (ι →₀ G) where neg := mapRange Neg.neg neg_zero
@[simp, norm_cast] lemma coe_neg [NegZeroClass G] (g : ι →₀ G) : ⇑(-g) = -g := rfl
lemma neg_apply [NegZeroClass G] (g : ι →₀ G) (a : ι) : (-g) a = -g a :=
rfl
lemma mapRange_neg [NegZeroClass G] [NegZeroClass H] {f : G → H} {hf : f 0 = 0}
(hf' : ∀ x, f (-x) = -f x) (v : ι →₀ G) : mapRange f hf (-v) = -mapRange f hf v :=
ext fun _ => by simp only [hf', neg_apply, mapRange_apply]
instance instSub [SubNegZeroMonoid G] : Sub (ι →₀ G) :=
⟨zipWith Sub.sub (sub_zero _)⟩
@[simp, norm_cast] lemma coe_sub [SubNegZeroMonoid G] (g₁ g₂ : ι →₀ G) : ⇑(g₁ - g₂) = g₁ - g₂ := rfl
lemma sub_apply [SubNegZeroMonoid G] (g₁ g₂ : ι →₀ G) (a : ι) : (g₁ - g₂) a = g₁ a - g₂ a := rfl
lemma mapRange_sub [SubNegZeroMonoid G] [SubNegZeroMonoid H] {f : G → H} {hf : f 0 = 0}
(hf' : ∀ x y, f (x - y) = f x - f y) (v₁ v₂ : ι →₀ G) :
mapRange f hf (v₁ - v₂) = mapRange f hf v₁ - mapRange f hf v₂ :=
ext fun _ => by simp only [hf', sub_apply, mapRange_apply]
section AddGroup
variable [AddGroup G] {p : ι → Prop} {v v' : ι →₀ G}
lemma mapRange_neg' [SubtractionMonoid H] [FunLike F G H] [AddMonoidHomClass F G H]
{f : F} (v : ι →₀ G) :
mapRange f (map_zero f) (-v) = -mapRange f (map_zero f) v :=
mapRange_neg (map_neg f) v
lemma mapRange_sub' [SubtractionMonoid H] [FunLike F G H] [AddMonoidHomClass F G H]
{f : F} (v₁ v₂ : ι →₀ G) :
mapRange f (map_zero f) (v₁ - v₂) = mapRange f (map_zero f) v₁ - mapRange f (map_zero f) v₂ :=
mapRange_sub (map_sub f) v₁ v₂
/-- Note the general `SMul` instance for `Finsupp` doesn't apply as `ℤ` is not distributive
unless `F i`'s addition is commutative. -/
instance instIntSMul : SMul ℤ (ι →₀ G) :=
⟨fun n v => v.mapRange (n • ·) (zsmul_zero _)⟩
instance instAddGroup : AddGroup (ι →₀ G) :=
fast_instance% DFunLike.coe_injective.addGroup DFunLike.coe coe_zero coe_add coe_neg coe_sub
(fun _ _ => rfl) fun _ _ => rfl
@[simp]
lemma support_neg (f : ι →₀ G) : support (-f) = support f :=
Finset.Subset.antisymm support_mapRange
(calc
support f = support (- -f) := congr_arg support (neg_neg _).symm
_ ⊆ support (-f) := support_mapRange
)
lemma support_sub [DecidableEq ι] {f g : ι →₀ G} : support (f - g) ⊆ support f ∪ support g := by
rw [sub_eq_add_neg, ← support_neg g]
exact support_add
lemma erase_eq_sub_single (f : ι →₀ G) (a : ι) : f.erase a = f - single a (f a) := by
ext a'
rcases eq_or_ne a' a with (rfl | h)
· simp
· simp [h]
lemma update_eq_sub_add_single (f : ι →₀ G) (a : ι) (b : G) :
f.update a b = f - single a (f a) + single a b := by
rw [update_eq_erase_add_single, erase_eq_sub_single]
@[simp]
lemma single_neg (a : ι) (b : G) : single a (-b) = -single a b :=
(singleAddHom a : G →+ _).map_neg b
@[simp]
lemma single_sub (a : ι) (b₁ b₂ : G) : single a (b₁ - b₂) = single a b₁ - single a b₂ :=
(singleAddHom a : G →+ _).map_sub b₁ b₂
@[simp]
lemma erase_neg (a : ι) (f : ι →₀ G) : erase a (-f) = -erase a f :=
(eraseAddHom a : (_ →₀ G) →+ _).map_neg f
@[simp]
lemma erase_sub (a : ι) (f₁ f₂ : ι →₀ G) : erase a (f₁ - f₂) = erase a f₁ - erase a f₂ :=
(eraseAddHom a : (_ →₀ G) →+ _).map_sub f₁ f₂
end AddGroup
instance instAddCommGroup [AddCommGroup G] : AddCommGroup (ι →₀ G) :=
fast_instance% DFunLike.coe_injective.addCommGroup DFunLike.coe coe_zero coe_add coe_neg coe_sub
(fun _ _ => rfl) fun _ _ => rfl
end Finsupp |
.lake/packages/mathlib/Mathlib/Algebra/Group/Even.lean | import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Algebra.Group.Equiv.Opposite
import Mathlib.Algebra.Group.TypeTags.Basic
import Mathlib.Data.Set.Operations
/-!
# Squares and even elements
This file defines square and even elements in a monoid.
## Main declarations
* `IsSquare a` means that there is some `r` such that `a = r * r`
* `Even a` means that there is some `r` such that `a = r + r`
## Note
* Many lemmas about `Even` / `IsSquare`, including important `simp` lemmas,
are in `Mathlib/Algebra/Ring/Parity.lean`.
## TODO
* Try to generalize `IsSquare/Even` lemmas further. For example, there are still a few lemmas in
`Algebra.Ring.Parity` whose `Semiring` assumptions I (DT) am not convinced are necessary.
* The "old" definition of `Even a` asked for the existence of an element `c` such that `a = 2 * c`.
For this reason, several fixes introduce an extra `two_mul` or `← two_mul`.
It might be the case that by making a careful choice of `simp` lemma, this can be avoided.
## See also
`Mathlib/Algebra/Ring/Parity.lean` for the definition of odd elements as well as facts about
`Even` / `IsSquare` in rings.
-/
assert_not_exists MonoidWithZero DenselyOrdered
open MulOpposite
variable {F α β : Type*}
section Mul
variable [Mul α]
/-- An element `a` of a type `α` with multiplication satisfies `IsSquare a` if `a = r * r`,
for some root `r : α`. -/
@[to_additive /-- An element `a` of a type `α` with addition satisfies `Even a` if `a = r + r`,
for some `r : α`. -/]
def IsSquare (a : α) : Prop := ∃ r, a = r * r
@[to_additive]
lemma isSquare_iff_exists_mul_self (a : α) : IsSquare a ↔ ∃ r, a = r * r := .rfl
alias ⟨IsSquare.exists_mul_self, _⟩ := isSquare_iff_exists_mul_self
attribute [to_additive (attr := aesop unsafe 5% forward)] IsSquare.exists_mul_self
@[to_additive (attr := simp, aesop safe)]
lemma IsSquare.mul_self (r : α) : IsSquare (r * r) := ⟨r, rfl⟩
@[to_additive]
lemma isSquare_op_iff {a : α} : IsSquare (op a) ↔ IsSquare a :=
⟨fun ⟨r, hr⟩ ↦ ⟨unop r, congr_arg unop hr⟩, fun ⟨r, hr⟩ ↦ ⟨op r, congr_arg op hr⟩⟩
@[to_additive]
lemma isSquare_unop_iff {a : αᵐᵒᵖ} : IsSquare (unop a) ↔ IsSquare a := isSquare_op_iff.symm
@[to_additive]
instance [DecidablePred (IsSquare : α → Prop)] : DecidablePred (IsSquare : αᵐᵒᵖ → Prop) :=
fun _ ↦ decidable_of_iff _ isSquare_unop_iff
@[simp]
lemma even_ofMul_iff {a : α} : Even (Additive.ofMul a) ↔ IsSquare a := Iff.rfl
@[simp]
lemma isSquare_toMul_iff {a : Additive α} : IsSquare (a.toMul) ↔ Even a := Iff.rfl
instance Additive.instDecidablePredEven [DecidablePred (IsSquare : α → Prop)] :
DecidablePred (Even : Additive α → Prop) :=
fun _ ↦ decidable_of_iff _ isSquare_toMul_iff
end Mul
section Add
variable [Add α]
@[simp] lemma isSquare_ofAdd_iff {a : α} : IsSquare (Multiplicative.ofAdd a) ↔ Even a := Iff.rfl
@[simp]
lemma even_toAdd_iff {a : Multiplicative α} : Even a.toAdd ↔ IsSquare a := Iff.rfl
instance Multiplicative.instDecidablePredIsSquare [DecidablePred (Even : α → Prop)] :
DecidablePred (IsSquare : Multiplicative α → Prop) :=
fun _ ↦ decidable_of_iff _ even_toAdd_iff
end Add
@[to_additive (attr := simp)]
lemma IsSquare.one [MulOneClass α] : IsSquare (1 : α) := ⟨1, (mul_one _).symm⟩
grind_pattern IsSquare.one => IsSquare (1 : α)
grind_pattern Even.zero => Even (0 : α)
section MonoidHom
variable [MulOneClass α] [MulOneClass β] [FunLike F α β] [MonoidHomClass F α β]
@[to_additive (attr := aesop unsafe 90%)]
lemma IsSquare.map {a : α} (f : F) : IsSquare a → IsSquare (f a) :=
fun ⟨r, _⟩ => ⟨f r, by simp [*]⟩
@[to_additive]
lemma isSquare_subset_image_isSquare {f : F} (hf : Function.Surjective f) :
{b | IsSquare b} ⊆ f '' {a | IsSquare a} := fun b ⟨s, _⟩ => by
rcases hf s with ⟨r, rfl⟩
exact ⟨r * r, by simp [*]⟩
end MonoidHom
section Monoid
variable [Monoid α] {n : ℕ} {a : α}
@[to_additive even_iff_exists_two_nsmul]
lemma isSquare_iff_exists_sq (a : α) : IsSquare a ↔ ∃ r, a = r ^ 2 := by simp [IsSquare, pow_two]
@[to_additive Even.exists_two_nsmul
/-- Alias of the forwards direction of `even_iff_exists_two_nsmul`. -/]
alias ⟨IsSquare.exists_sq, _⟩ := isSquare_iff_exists_sq
-- provable by simp in `Algebra.Ring.Parity`
@[to_additive (attr := aesop safe) Even.two_nsmul]
lemma IsSquare.sq (r : α) : IsSquare (r ^ 2) := ⟨r, pow_two _⟩
@[to_additive (attr := aesop unsafe 80%) Even.nsmul_right]
lemma IsSquare.pow (n : ℕ) (ha : IsSquare a) : IsSquare (a ^ n) := by
aesop (add simp Commute.mul_pow)
@[to_additive (attr := aesop unsafe 90%) Even.nsmul_left]
lemma Even.isSquare_pow (hn : Even n) : ∀ a : α, IsSquare (a ^ n) := by aesop (add simp pow_add)
end Monoid
@[to_additive (attr := aesop unsafe 90%)]
lemma IsSquare.mul [CommSemigroup α] {a b : α} : IsSquare a → IsSquare b → IsSquare (a * b) :=
fun ⟨r, _⟩ ⟨s, _⟩ => ⟨r * s, by simp_all [mul_mul_mul_comm]⟩
section DivisionMonoid
variable [DivisionMonoid α] {a : α}
@[to_additive (attr := simp)] lemma isSquare_inv : IsSquare a⁻¹ ↔ IsSquare a := by
constructor <;> intro h <;> simpa using (isSquare_op_iff.mpr h).map (MulEquiv.inv' α).symm
@[to_additive] alias ⟨_, IsSquare.inv⟩ := isSquare_inv
@[to_additive (attr := aesop unsafe 80%) Even.zsmul_right]
lemma IsSquare.zpow (n : ℤ) : IsSquare a → IsSquare (a ^ n) := by
aesop (add simp Commute.mul_zpow)
end DivisionMonoid
@[to_additive (attr := aesop unsafe 90%)]
lemma IsSquare.div [DivisionCommMonoid α] {a b : α} (ha : IsSquare a) (hb : IsSquare b) :
IsSquare (a / b) := by aesop (add simp div_eq_mul_inv)
@[to_additive (attr := simp, aesop unsafe 90%) Even.zsmul_left]
lemma Even.isSquare_zpow [Group α] {n : ℤ} : Even n → ∀ a : α, IsSquare (a ^ n) := by
aesop (add simp zpow_add)
example {G : Type*} [CommGroup G] {a b c d e : G} (ha : IsSquare a) {n : ℕ} {k : ℤ} (hk : Even k) :
IsSquare <| a * (b * b) / (c ^ 2) * (d ^ k) * (e ^ (n + n)) := by aesop
example {G : Type*} [AddCommGroup G] {a b c d e : G} (ha : Even a) {n : ℕ} {k : ℤ} (hk : Even k) :
Even <| a + (b + b) - 2 • c + k • d + (n + n) • e := by aesop |
.lake/packages/mathlib/Mathlib/Algebra/Group/Torsion.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Tactic.MkIffOfInductiveProp
/-!
# Torsion-free monoids and groups
This file proves lemmas about torsion-free monoids.
A monoid `M` is *torsion-free* if `n • · : M → M` is injective for all non-zero natural numbers `n`.
-/
open Function
variable {M G : Type*}
section Monoid
variable [Monoid M]
instance [AddCommMonoid M] [IsAddTorsionFree M] : Lean.Grind.NoNatZeroDivisors M where
no_nat_zero_divisors _ _ _ hk habk := IsAddTorsionFree.nsmul_right_injective hk habk
@[to_additive] instance Subsingleton.to_isMulTorsionFree [Subsingleton M] : IsMulTorsionFree M where
pow_left_injective _ _ := injective_of_subsingleton _
variable [IsMulTorsionFree M] {n : ℕ} {a b : M}
@[to_additive nsmul_right_injective]
lemma pow_left_injective (hn : n ≠ 0) : Injective fun a : M ↦ a ^ n :=
IsMulTorsionFree.pow_left_injective hn
@[to_additive nsmul_right_inj]
lemma pow_left_inj (hn : n ≠ 0) : a ^ n = b ^ n ↔ a = b := (pow_left_injective hn).eq_iff
@[to_additive IsAddTorsionFree.nsmul_eq_zero_iff_right]
lemma IsMulTorsionFree.pow_eq_one_iff_left (hn : n ≠ 0) : a ^ n = 1 ↔ a = 1 := by
rw [← pow_left_inj (a := a) hn, one_pow]
-- We want to use `IsAddTorsion.nsmul_eq_zero_iff` earlier than `smul_eq_zero`.
@[to_additive (attr := simp high)]
lemma IsMulTorsionFree.pow_eq_one_iff : a ^ n = 1 ↔ a = 1 ∨ n = 0 := by
obtain rfl | hn := eq_or_ne n 0 <;> simp [pow_eq_one_iff_left, *]
@[to_additive IsAddTorsionFree.nsmul_eq_zero_iff_left]
lemma IsMulTorsionFree.pow_eq_one_iff_right (ha : a ≠ 1) : a ^ n = 1 ↔ n = 0 := by simp [*]
@[deprecated (since := "2025-10-19")]
alias IsAddTorsionFree.nsmul_eq_zero_iff' := IsAddTorsionFree.nsmul_eq_zero_iff_left
@[deprecated (since := "2025-10-19")]
alias IsMulTorsionFree.pow_eq_one_iff' := IsMulTorsionFree.pow_eq_one_iff_right
/-- See `sq_eq_one_iff` for a version that holds in rings. -/
@[to_additive two_nsmul_eq_zero]
lemma sq_eq_one : a ^ 2 = 1 ↔ a = 1 := IsMulTorsionFree.pow_eq_one_iff_left (by cutsat)
end Monoid
section Group
variable [Group G] [IsMulTorsionFree G] {n : ℤ} {a b : G}
@[to_additive zsmul_right_injective]
lemma zpow_left_injective : ∀ {n : ℤ}, n ≠ 0 → Injective fun a : G ↦ a ^ n
| (n + 1 : ℕ), _ => by
simpa [← Int.natCast_one, ← Int.natCast_add] using pow_left_injective n.succ_ne_zero
| .negSucc n, _ => by simpa using inv_injective.comp (pow_left_injective n.succ_ne_zero)
@[to_additive zsmul_right_inj]
lemma zpow_left_inj (hn : n ≠ 0) : a ^ n = b ^ n ↔ a = b := (zpow_left_injective hn).eq_iff
/-- Alias of `zpow_left_inj`, for ease of discovery alongside `zsmul_le_zsmul_iff'` and
`zsmul_lt_zsmul_iff'`. -/
@[to_additive /-- Alias of `zsmul_right_inj`, for ease of discovery alongside `zsmul_le_zsmul_iff'`
and `zsmul_lt_zsmul_iff'`. -/]
lemma zpow_eq_zpow_iff' (hn : n ≠ 0) : a ^ n = b ^ n ↔ a = b := zpow_left_inj hn
@[to_additive IsAddTorsionFree.zsmul_eq_zero_iff_right]
lemma IsMulTorsionFree.zpow_eq_one_iff_left (hn : n ≠ 0) : a ^ n = 1 ↔ a = 1 := by
rw [← zpow_left_inj (a := a) hn, one_zpow]
-- We want to use `IsAddTorsion.zsmul_eq_zero_iff` earlier than `smul_eq_zero`.
@[to_additive (attr := simp high)]
lemma IsMulTorsionFree.zpow_eq_one_iff : a ^ n = 1 ↔ a = 1 ∨ n = 0 := by
obtain rfl | hn := eq_or_ne n 0 <;> simp [zpow_eq_one_iff_left, *]
@[to_additive IsAddTorsionFree.zsmul_eq_zero_iff_left]
lemma IsMulTorsionFree.zpow_eq_one_iff_right (ha : a ≠ 1) : a ^ n = 1 ↔ n = 0 := by simp [*]
@[to_additive] lemma self_eq_inv : a = a⁻¹ ↔ a = 1 := by rw [← sq_eq_one, sq, mul_eq_one_iff_eq_inv]
@[to_additive] lemma inv_eq_self : a⁻¹ = a ↔ a = 1 := by rw [eq_comm, self_eq_inv]
@[to_additive] lemma self_ne_inv : a ≠ a⁻¹ ↔ a ≠ 1 := self_eq_inv.ne
@[to_additive] lemma inv_ne_self : a⁻¹ ≠ a ↔ a ≠ 1 := inv_eq_self.ne
end Group |
.lake/packages/mathlib/Mathlib/Algebra/Group/Embedding.lean | import Mathlib.Logic.Embedding.Basic
import Mathlib.Algebra.Group.Defs
/-!
# The embedding of a cancellative semigroup into itself by multiplication by a fixed element.
-/
assert_not_exists MonoidWithZero DenselyOrdered
variable {G : Type*}
section LeftOrRightCancelSemigroup
/-- If left-multiplication by any element is cancellative, left-multiplication by `g` is an
embedding. -/
@[to_additive (attr := simps (attr := grind =))
/-- If left-addition by any element is cancellative, left-addition by `g` is an embedding. -/]
def mulLeftEmbedding [Mul G] [IsLeftCancelMul G] (g : G) : G ↪ G where
toFun h := g * h
inj' := mul_right_injective g
/-- If right-multiplication by any element is cancellative, right-multiplication by `g` is an
embedding. -/
@[to_additive (attr := simps (attr := grind =))
/-- If right-addition by any element is cancellative, right-addition by `g` is an embedding. -/]
def mulRightEmbedding [Mul G] [IsRightCancelMul G] (g : G) : G ↪ G where
toFun h := h * g
inj' := mul_left_injective g
@[to_additive]
theorem mulLeftEmbedding_eq_mulRightEmbedding [CommMagma G] [IsCancelMul G] (g : G) :
mulLeftEmbedding g = mulRightEmbedding g := by
ext
exact mul_comm _ _
end LeftOrRightCancelSemigroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/EvenFunction.lean | import Mathlib.Algebra.BigOperators.Group.Finset.Basic
import Mathlib.Algebra.Group.Action.Pi
import Mathlib.Algebra.Module.Defs
/-!
# Even and odd functions
We define even functions `α → β` assuming `α` has a negation, and odd functions assuming both `α`
and `β` have negation.
These definitions are `Function.Even` and `Function.Odd`; and they are `protected`, to avoid
conflicting with the root-level definitions `Even` and `Odd` (which, for functions, mean that the
function takes even resp. odd _values_, a wholly different concept).
-/
assert_not_exists Module.IsTorsionFree NoZeroSMulDivisors
namespace Function
variable {α β : Type*} [Neg α]
/-- A function `f` is _even_ if it satisfies `f (-x) = f x` for all `x`. -/
protected def Even (f : α → β) : Prop := ∀ a, f (-a) = f a
/-- A function `f` is _odd_ if it satisfies `f (-x) = -f x` for all `x`. -/
protected def Odd [Neg β] (f : α → β) : Prop := ∀ a, f (-a) = -(f a)
/-- Any constant function is even. -/
lemma Even.const (b : β) : Function.Even (fun _ : α ↦ b) := fun _ ↦ rfl
/-- The zero function is even. -/
lemma Even.zero [Zero β] : Function.Even (fun (_ : α) ↦ (0 : β)) := Even.const 0
/-- The zero function is odd. -/
lemma Odd.zero [NegZeroClass β] : Function.Odd (fun (_ : α) ↦ (0 : β)) := fun _ ↦ neg_zero.symm
section composition
variable {γ : Type*}
/-- If `f` is arbitrary and `g` is even, then `f ∘ g` is even. -/
lemma Even.left_comp {g : α → β} (hg : g.Even) (f : β → γ) : (f ∘ g).Even :=
(congr_arg f <| hg ·)
/-- If `f` is even and `g` is odd, then `f ∘ g` is even. -/
lemma Even.comp_odd [Neg β] {f : β → γ} (hf : f.Even) {g : α → β} (hg : g.Odd) :
(f ∘ g).Even := by
intro a
simp only [comp_apply, hg a, hf _]
/-- If `f` and `g` are odd, then `f ∘ g` is odd. -/
lemma Odd.comp_odd [Neg β] [Neg γ] {f : β → γ} (hf : f.Odd) {g : α → β} (hg : g.Odd) :
(f ∘ g).Odd := by
intro a
simp only [comp_apply, hg a, hf _]
end composition
lemma Even.add [Add β] {f g : α → β} (hf : f.Even) (hg : g.Even) : (f + g).Even := by
intro a
simp only [hf a, hg a, Pi.add_apply]
lemma Odd.add [SubtractionCommMonoid β] {f g : α → β} (hf : f.Odd) (hg : g.Odd) : (f + g).Odd := by
intro a
simp only [hf a, hg a, Pi.add_apply, neg_add]
section smul
variable {γ : Type*} {f : α → β} {g : α → γ}
lemma Even.smul_even [SMul β γ] (hf : f.Even) (hg : g.Even) : (f • g).Even := by
intro a
simp only [Pi.smul_apply', hf a, hg a]
lemma Even.smul_odd [Monoid β] [AddGroup γ] [DistribMulAction β γ] (hf : f.Even) (hg : g.Odd) :
(f • g).Odd := by
intro a
simp only [Pi.smul_apply', hf a, hg a, smul_neg]
lemma Odd.smul_even [Ring β] [AddCommGroup γ] [Module β γ] (hf : f.Odd) (hg : g.Even) :
(f • g).Odd := by
intro a
simp only [Pi.smul_apply', hf a, hg a, neg_smul]
lemma Odd.smul_odd [Ring β] [AddCommGroup γ] [Module β γ] (hf : f.Odd) (hg : g.Odd) :
(f • g).Even := by
intro a
simp only [Pi.smul_apply', hf a, hg a, smul_neg, neg_smul, neg_neg]
lemma Even.const_smul [SMul β γ] (hg : g.Even) (r : β) : (r • g).Even := by
intro a
simp only [Pi.smul_apply, hg a]
lemma Odd.const_smul [Monoid β] [AddGroup γ] [DistribMulAction β γ] (hg : g.Odd) (r : β) :
(r • g).Odd := by
intro a
simp only [Pi.smul_apply, hg a, smul_neg]
end smul
section mul
variable {R : Type*} [Mul R] {f g : α → R}
lemma Even.mul_even (hf : f.Even) (hg : g.Even) : (f * g).Even := by
intro a
simp only [Pi.mul_apply, hf a, hg a]
lemma Even.mul_odd [HasDistribNeg R] (hf : f.Even) (hg : g.Odd) : (f * g).Odd := by
intro a
simp only [Pi.mul_apply, hf a, hg a, mul_neg]
lemma Odd.mul_even [HasDistribNeg R] (hf : f.Odd) (hg : g.Even) : (f * g).Odd := by
intro a
simp only [Pi.mul_apply, hf a, hg a, neg_mul]
lemma Odd.mul_odd [HasDistribNeg R] (hf : f.Odd) (hg : g.Odd) : (f * g).Even := by
intro a
simp only [Pi.mul_apply, hf a, hg a, mul_neg, neg_mul, neg_neg]
end mul
section torsionfree
-- need to redeclare variables since `InvolutiveNeg α` conflicts with `Neg α`
variable {α β : Type*} [AddCommGroup β] [IsAddTorsionFree β] {f : α → β}
/--
If `f` is both even and odd, and its target is a torsion-free commutative additive group,
then `f = 0`.
-/
lemma zero_of_even_and_odd [Neg α] (he : f.Even) (ho : f.Odd) : f = 0 := by
ext r
rw [Pi.zero_apply, ← neg_eq_self, ← ho, he]
/-- The sum of the values of an odd function is 0. -/
lemma Odd.sum_eq_zero [Fintype α] [InvolutiveNeg α] {f : α → β} (hf : f.Odd) : ∑ a, f a = 0 := by
simpa [neg_eq_self, Finset.sum_neg_distrib, funext hf] using Equiv.sum_comp (.neg α) f
/-- An odd function vanishes at zero. -/
lemma Odd.map_zero [NegZeroClass α] (hf : f.Odd) : f 0 = 0 := by simp [← neg_eq_self, ← hf 0]
end torsionfree
end Function |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.