path
stringlengths 11
71
| content
stringlengths 75
124k
|
---|---|
Algebra\Category\Grp\Biproducts.lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.CategoryTheory.Preadditive.Biproducts
import Mathlib.Algebra.Category.Grp.Limits
import Mathlib.Tactic.CategoryTheory.Elementwise
/-!
# The category of abelian groups has finite biproducts
-/
open CategoryTheory
open CategoryTheory.Limits
universe w u
namespace AddCommGrp
-- As `AddCommGrp` is preadditive, and has all limits, it automatically has biproducts.
instance : HasBinaryBiproducts AddCommGrp :=
HasBinaryBiproducts.of_hasBinaryProducts
instance : HasFiniteBiproducts AddCommGrp :=
HasFiniteBiproducts.of_hasFiniteProducts
-- We now construct explicit limit data,
-- so we can compare the biproducts to the usual unbundled constructions.
/-- Construct limit data for a binary product in `AddCommGrp`, using
`AddCommGrp.of (G × H)`.
-/
@[simps cone_pt isLimit_lift]
def binaryProductLimitCone (G H : AddCommGrp.{u}) : Limits.LimitCone (pair G H) where
cone :=
{ pt := AddCommGrp.of (G × H)
π :=
{ app := fun j =>
Discrete.casesOn j fun j =>
WalkingPair.casesOn j (AddMonoidHom.fst G H) (AddMonoidHom.snd G H)
naturality := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟨⟩⟩⟩ <;> rfl } }
isLimit :=
{ lift := fun s => AddMonoidHom.prod (s.π.app ⟨WalkingPair.left⟩) (s.π.app ⟨WalkingPair.right⟩)
fac := by rintro s (⟨⟩ | ⟨⟩) <;> rfl
uniq := fun s m w => by
simp_rw [← w ⟨WalkingPair.left⟩, ← w ⟨WalkingPair.right⟩]
rfl }
@[simp]
theorem binaryProductLimitCone_cone_π_app_left (G H : AddCommGrp.{u}) :
(binaryProductLimitCone G H).cone.π.app ⟨WalkingPair.left⟩ = AddMonoidHom.fst G H :=
rfl
@[simp]
theorem binaryProductLimitCone_cone_π_app_right (G H : AddCommGrp.{u}) :
(binaryProductLimitCone G H).cone.π.app ⟨WalkingPair.right⟩ = AddMonoidHom.snd G H :=
rfl
/-- We verify that the biproduct in `AddCommGrp` is isomorphic to
the cartesian product of the underlying types:
-/
@[simps! hom_apply]
noncomputable def biprodIsoProd (G H : AddCommGrp.{u}) :
(G ⊞ H : AddCommGrp) ≅ AddCommGrp.of (G × H) :=
IsLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit G H) (binaryProductLimitCone G H).isLimit
-- These lemmas have always been bad (#7657), but lean4#2644 made `simp` start noticing
attribute [nolint simpNF] AddCommGrp.biprodIsoProd_hom_apply
@[simp, elementwise]
theorem biprodIsoProd_inv_comp_fst (G H : AddCommGrp.{u}) :
(biprodIsoProd G H).inv ≫ biprod.fst = AddMonoidHom.fst G H :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.left)
@[simp, elementwise]
theorem biprodIsoProd_inv_comp_snd (G H : AddCommGrp.{u}) :
(biprodIsoProd G H).inv ≫ biprod.snd = AddMonoidHom.snd G H :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.right)
namespace HasLimit
variable {J : Type w} (f : J → AddCommGrp.{max w u})
/-- The map from an arbitrary cone over an indexed family of abelian groups
to the cartesian product of those groups.
-/
-- This was marked `@[simps]` until we made `AddCommGrp.coe_of` a simp lemma,
-- after which the simp normal form linter complains.
-- The generated simp lemmas were not used in Mathlib.
-- Possible solution: higher priority function coercions that remove the `of`?
-- @[simps]
def lift (s : Fan f) : s.pt ⟶ AddCommGrp.of (∀ j, f j) where
toFun x j := s.π.app ⟨j⟩ x
map_zero' := by
simp only [Functor.const_obj_obj, map_zero]
rfl
map_add' x y := by
simp only [Functor.const_obj_obj, map_add]
rfl
/-- Construct limit data for a product in `AddCommGrp`, using
`AddCommGrp.of (∀ j, F.obj j)`.
-/
@[simps]
def productLimitCone : Limits.LimitCone (Discrete.functor f) where
cone :=
{ pt := AddCommGrp.of (∀ j, f j)
π := Discrete.natTrans fun j => Pi.evalAddMonoidHom (fun j => f j) j.as }
isLimit :=
{ lift := lift.{_, u} f
fac := fun s j => rfl
uniq := fun s m w => by
ext x
funext j
exact congr_arg (fun g : s.pt ⟶ f j => (g : s.pt → f j) x) (w ⟨j⟩) }
end HasLimit
open HasLimit
variable {J : Type} [Finite J]
/-- We verify that the biproduct we've just defined is isomorphic to the `AddCommGrp` structure
on the dependent function type.
-/
@[simps! hom_apply]
noncomputable def biproductIsoPi (f : J → AddCommGrp.{u}) :
(⨁ f : AddCommGrp) ≅ AddCommGrp.of (∀ j, f j) :=
IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (productLimitCone f).isLimit
-- These lemmas have always been bad (#7657), but lean4#2644 made `simp` start noticing
attribute [nolint simpNF] AddCommGrp.biproductIsoPi_hom_apply
@[simp, elementwise]
theorem biproductIsoPi_inv_comp_π (f : J → AddCommGrp.{u}) (j : J) :
(biproductIsoPi f).inv ≫ biproduct.π f j = Pi.evalAddMonoidHom (fun j => f j) j :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk j)
end AddCommGrp
|
Algebra\Category\Grp\Colimits.lean
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.GroupTheory.QuotientGroup
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
/-!
# The category of additive commutative groups has all colimits.
This file uses a "pre-automated" approach, just as for `Algebra.Category.MonCat.Colimits`.
It is a very uniform approach, that conceivably could be synthesised directly
by a tactic that analyses the shape of `AddCommGroup` and `MonoidHom`.
TODO:
In fact, in `AddCommGrp` there is a much nicer model of colimits as quotients
of finitely supported functions, and we really should implement this as well (or instead).
-/
universe w u v
open CategoryTheory Limits
-- [ROBOT VOICE]:
-- You should pretend for now that this file was automatically generated.
-- It follows the same template as colimits in Mon.
namespace AddCommGrp
variable {J : Type u} [Category.{v} J] (F : J ⥤ AddCommGrp.{max u v w})
namespace Colimits
/-!
We build the colimit of a diagram in `AddCommGrp` by constructing the
free group on the disjoint union of all the abelian groups in the diagram,
then taking the quotient by the abelian group laws within each abelian group,
and the identifications given by the morphisms in the diagram.
-/
/-- An inductive type representing all group 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
| neg : Prequotient → Prequotient
| add : Prequotient → Prequotient → Prequotient
instance : Inhabited (Prequotient.{w} F) :=
⟨Prequotient.zero⟩
open Prequotient
/-- The relation on `Prequotient` saying when two expressions are equal
because of the abelian group laws, or
because one element is mapped to another by a morphism in the diagram.
-/
inductive Relation : Prequotient.{w} F → Prequotient.{w} 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
| 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))
-- 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')
-- And one relation per axiom
| zero_add : ∀ x, Relation (add zero x) x
| add_zero : ∀ x, Relation (add x zero) x
| add_left_neg : ∀ 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))
/--
The setoid corresponding to group expressions modulo abelian group relations and identifications.
-/
def colimitSetoid : Setoid (Prequotient.{w} F) where
r := Relation F
iseqv := ⟨Relation.refl, fun r => Relation.symm _ _ r, fun r => Relation.trans _ _ _ r⟩
attribute [instance] colimitSetoid
/-- The underlying type of the colimit of a diagram in `AddCommGrp`.
-/
def ColimitType : Type max u v w :=
Quotient (colimitSetoid.{w} F)
instance : Zero (ColimitType.{w} F) where
zero := Quotient.mk _ zero
instance : Neg (ColimitType.{w} F) where
neg := Quotient.map neg Relation.neg_1
instance : Add (ColimitType.{w} 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 : AddCommGroup (ColimitType.{w} F) where
zero_add := Quotient.ind <| fun _ => Quotient.sound <| Relation.zero_add _
add_zero := Quotient.ind <| fun _ => Quotient.sound <| Relation.add_zero _
add_left_neg := Quotient.ind <| fun _ => Quotient.sound <| Relation.add_left_neg _
add_comm := Quotient.ind₂ <| fun _ _ => Quotient.sound <| Relation.add_comm _ _
add_assoc := Quotient.ind <| fun _ => Quotient.ind₂ <| fun _ _ =>
Quotient.sound <| Relation.add_assoc _ _ _
nsmul := nsmulRec
zsmul := zsmulRec
instance ColimitTypeInhabited : Inhabited (ColimitType.{w} F) := ⟨0⟩
@[simp]
theorem quot_zero : Quot.mk Setoid.r zero = (0 : ColimitType.{w} F) :=
rfl
@[simp]
theorem quot_neg (x) :
-- Porting note: force Lean to treat `ColimitType F` no as `Quot _`
(by exact Quot.mk Setoid.r (neg x) : ColimitType.{w} F) =
-(by exact Quot.mk Setoid.r x) :=
rfl
@[simp]
theorem quot_add (x y) :
(by exact Quot.mk Setoid.r (add x y) : ColimitType.{w} F) =
-- Porting note: force Lean to treat `ColimitType F` no as `Quot _`
(by exact Quot.mk Setoid.r x) + (by exact Quot.mk Setoid.r y) :=
rfl
/-- The bundled abelian group giving the colimit of a diagram. -/
def colimit : AddCommGrp :=
AddCommGrp.of (ColimitType.{w} F)
/-- The function from a given abelian group in the diagram to the colimit abelian group. -/
def coconeFun (j : J) (x : F.obj j) : ColimitType.{w} F :=
Quot.mk _ (Prequotient.of j x)
/-- The group homomorphism from a given abelian group in the diagram to the colimit abelian
group. -/
def coconeMorphism (j : J) : F.obj j ⟶ colimit.{w} F where
toFun := coconeFun F j
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.{w} 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.{w} F j') (F.map f x) = (coconeMorphism F j) x := by
rw [← cocone_naturality F f]
rfl
/-- The cocone over the proposed colimit abelian group. -/
def colimitCocone : Cocone F where
pt := colimit.{w} F
ι := { app := coconeMorphism F }
/-- The function from the free abelian group on the diagram to the cone point of any other
cocone. -/
@[simp]
def descFunLift (s : Cocone F) : Prequotient.{w} F → s.pt
| Prequotient.of j x => (s.ι.app j) x
| zero => 0
| neg x => -descFunLift s x
| add x y => descFunLift s x + descFunLift s y
/-- The function from the colimit abelian group to the cone point of any other cocone. -/
def descFun (s : Cocone F) : ColimitType.{w} F → s.pt := by
fapply Quot.lift
· exact descFunLift F s
· intro x y r
induction r with
| refl => rfl
| symm _ _ _ r_ih => exact r_ih.symm
| trans _ _ _ _ _ r_ih_h r_ih_k => exact Eq.trans r_ih_h r_ih_k
| map j j' f x => simpa only [descFunLift, Functor.const_obj_obj] using
DFunLike.congr_fun (s.ι.naturality f) x
| zero => simp
| neg => simp
| add => simp
| neg_1 _ _ _ r_ih => dsimp; rw [r_ih]
| add_1 _ _ _ _ r_ih => dsimp; rw [r_ih]
| add_2 _ _ _ _ r_ih => dsimp; rw [r_ih]
| zero_add => dsimp; rw [zero_add]
| add_zero => dsimp; rw [add_zero]
| add_left_neg => dsimp; rw [add_left_neg]
| add_comm => dsimp; rw [add_comm]
| add_assoc => dsimp; rw [add_assoc]
/-- The group homomorphism from the colimit abelian group to the cone point of any other cocone. -/
def descMorphism (s : Cocone F) : colimit.{w} F ⟶ s.pt where
toFun := descFun F s
map_zero' := rfl
-- Porting note: in `mathlib3`, nothing needs to be done after `induction`
map_add' x y := Quot.induction_on₂ x y fun _ _ => by dsimp; rw [← quot_add F]; rfl
/-- Evidence that the proposed colimit is the colimit. -/
def colimitCoconeIsColimit : IsColimit (colimitCocone.{w} F) where
desc s := descMorphism F s
uniq s m w := DFunLike.ext _ _ fun x => Quot.inductionOn x fun x => by
change (m : ColimitType F →+ s.pt) _ = (descMorphism F s : ColimitType F →+ s.pt) _
induction x using Prequotient.recOn with
| of j x => exact DFunLike.congr_fun (w j) x
| zero =>
dsimp only [quot_zero]
rw [map_zero, map_zero]
| neg x ih =>
dsimp only [quot_neg]
rw [map_neg, map_neg, ih]
| add x y ihx ihy =>
simp only [quot_add]
erw [m.map_add, (descMorphism F s).map_add, ihx, ihy]
end Colimits
lemma hasColimit : HasColimit F := ⟨_, Colimits.colimitCoconeIsColimit.{w} F⟩
variable (J)
lemma hasColimitsOfShape : HasColimitsOfShape J AddCommGrp.{max u v w} where
has_colimit F := hasColimit.{w} F
lemma hasColimitsOfSize : HasColimitsOfSize.{v, u} AddCommGrp.{max u v w} :=
⟨fun _ => hasColimitsOfShape.{w} _⟩
instance hasColimits : HasColimits AddCommGrp.{w} := hasColimitsOfSize.{w}
instance : HasColimitsOfSize.{v, v} (AddCommGrpMax.{u, v}) := hasColimitsOfSize.{u}
instance : HasColimitsOfSize.{u, u} (AddCommGrpMax.{u, v}) := hasColimitsOfSize.{v}
instance : HasColimitsOfSize.{u, v} (AddCommGrpMax.{u, v}) := hasColimitsOfSize.{u}
instance : HasColimitsOfSize.{v, u} (AddCommGrpMax.{u, v}) := hasColimitsOfSize.{u}
instance : HasColimitsOfSize.{0, 0} (AddCommGrp.{u}) := hasColimitsOfSize.{u, 0, 0}
example : HasColimits AddCommGrpMax.{v, u} :=
inferInstance
example : HasColimits AddCommGrpMax.{u, v} :=
inferInstance
example : HasColimits AddCommGrp.{u} :=
inferInstance
end AddCommGrp
namespace AddCommGrp
open QuotientAddGroup
/-- The categorical cokernel of a morphism in `AddCommGrp`
agrees with the usual group-theoretical quotient.
-/
noncomputable def cokernelIsoQuotient {G H : AddCommGrp.{u}} (f : G ⟶ H) :
cokernel f ≅ AddCommGrp.of (H ⧸ AddMonoidHom.range f) where
hom := cokernel.desc f (mk' _) <| by
ext x
apply Quotient.sound
apply leftRel_apply.mpr
fconstructor
· exact -x
· simp only [add_zero, AddMonoidHom.map_neg]
inv :=
QuotientAddGroup.lift _ (cokernel.π f) <| by
rintro _ ⟨x, rfl⟩
exact cokernel.condition_apply f x
hom_inv_id := by
refine coequalizer.hom_ext ?_
simp only [coequalizer_as_cokernel, cokernel.π_desc_assoc, Category.comp_id]
rfl
inv_hom_id := by
ext x
exact QuotientAddGroup.induction_on x <| cokernel.π_desc_apply f _ _
end AddCommGrp
|
Algebra\Category\Grp\EnoughInjectives.lean
|
/-
Copyright (c) 2023 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Junyan Xu
-/
import Mathlib.Algebra.Module.CharacterModule
import Mathlib.Algebra.Category.Grp.EquivalenceGroupAddGroup
import Mathlib.Algebra.Category.Grp.EpiMono
/-!
# Category of abelian groups has enough injectives
Given an abelian group `A`, then `i : A ⟶ ∏_{A⋆} ℚ ⧸ ℤ` defined by `i : a ↦ c ↦ c a` is an
injective presentation for `A`, hence category of abelian groups has enough injectives.
## Implementation notes
This file is split from `Mathlib.Algebra.Grp.Injective` is to prevent import loop.
This file's dependency imports `Mathlib.Algebra.Grp.Injective`.
-/
open CategoryTheory
universe u
namespace AddCommGrp
open CharacterModule
instance enoughInjectives : EnoughInjectives AddCommGrp.{u} where
presentation A_ := Nonempty.intro
{ J := of <| (CharacterModule A_) → ULift.{u} (AddCircle (1 : ℚ))
injective := injective_of_divisible _
f := ⟨⟨fun a i ↦ ULift.up (i a), by aesop⟩, by aesop⟩
mono := (AddCommGrp.mono_iff_injective _).mpr <| (injective_iff_map_eq_zero _).mpr
fun a h0 ↦ eq_zero_of_character_apply (congr_arg ULift.down <| congr_fun h0 ·) }
end AddCommGrp
namespace CommGrp
instance enoughInjectives : EnoughInjectives CommGrp.{u} :=
EnoughInjectives.of_equivalence commGroupAddCommGroupEquivalence.functor
end CommGrp
|
Algebra\Category\Grp\EpiMono.lean
|
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.Algebra.Category.Grp.EquivalenceGroupAddGroup
import Mathlib.GroupTheory.QuotientGroup
import Mathlib.CategoryTheory.ConcreteCategory.EpiMono
import Mathlib.CategoryTheory.Limits.Constructions.EpiMono
/-!
# Monomorphisms and epimorphisms in `Group`
In this file, we prove monomorphisms in the category of groups are injective homomorphisms and
epimorphisms are surjective homomorphisms.
-/
noncomputable section
open scoped Pointwise
universe u v
namespace MonoidHom
open QuotientGroup
variable {A : Type u} {B : Type v}
section
variable [Group A] [Group B]
@[to_additive]
theorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) :
f.ker = ⊥ := by simpa using congr_arg range (h f.ker.subtype 1 (by aesop_cat))
end
section
variable [CommGroup A] [CommGroup B]
@[to_additive]
theorem range_eq_top_of_cancel {f : A →* B}
(h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by
specialize h 1 (QuotientGroup.mk' _) _
· ext1 x
simp only [one_apply, coe_comp, coe_mk', Function.comp_apply]
rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one,
one_mul]
exact ⟨x, rfl⟩
replace h : (QuotientGroup.mk' f.range).ker = (1 : B →* B ⧸ f.range).ker := by rw [h]
rwa [ker_one, QuotientGroup.ker_mk'] at h
end
end MonoidHom
section
open CategoryTheory
namespace Grp
-- Porting note: already have Group G but Lean can't use that
@[to_additive]
instance (G : Grp) : Group G.α :=
G.str
variable {A B : Grp.{u}} (f : A ⟶ B)
@[to_additive]
theorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=
MonoidHom.ker_eq_bot_of_cancel fun u _ =>
(@cancel_mono _ _ _ _ _ f _ (show Grp.of f.ker ⟶ A from u) _).1
@[to_additive]
theorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=
⟨fun _ => ker_eq_bot_of_mono f, fun h =>
ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩
@[to_additive]
theorem mono_iff_injective : Mono f ↔ Function.Injective f :=
Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f
namespace SurjectiveOfEpiAuxs
set_option quotPrecheck false in
local notation "X" => Set.range (· • (f.range : Set B) : B → Set B)
/-- Define `X'` to be the set of all left cosets with an extra point at "infinity".
-/
inductive XWithInfinity
| fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity
| infinity : XWithInfinity
open XWithInfinity Equiv.Perm
local notation "X'" => XWithInfinity f
local notation "∞" => XWithInfinity.infinity
local notation "SX'" => Equiv.Perm X'
instance : SMul B X' where
smul b x :=
match x with
| fromCoset y => fromCoset ⟨b • y, by
rw [← y.2.choose_spec, leftCoset_assoc]
-- Porting note: should we make `Bundled.α` reducible?
let b' : B := y.2.choose
use b * b'⟩
| ∞ => ∞
theorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x :=
match x with
| fromCoset y => by
change fromCoset _ = fromCoset _
simp only [leftCoset_assoc]
| ∞ => rfl
theorem one_smul (x : X') : (1 : B) • x = x :=
match x with
| fromCoset y => by
change fromCoset _ = fromCoset _
simp only [one_leftCoset, Subtype.ext_iff_val]
| ∞ => rfl
theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) :
fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by
congr
let b : B.α := b
change b • (f.range : Set B) = f.range
nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm]
rw [leftCoset_eq_iff, mul_one]
exact Subgroup.inv_mem _ hb
example (G : Type) [Group G] (S : Subgroup G) : Set G := S
theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) :
fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by
intro r
simp only [fromCoset.injEq, Subtype.mk.injEq] at r
-- Porting note: annoying dance between types CoeSort.coe B, B.α, and B
let b' : B.α := b
change b' • (f.range : Set B) = f.range at r
nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r
rw [leftCoset_eq_iff, mul_one] at r
exact hb (inv_inv b ▸ Subgroup.inv_mem _ r)
instance : DecidableEq X' :=
Classical.decEq _
/-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity.
-/
noncomputable def tau : SX' :=
Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞
local notation "τ" => tau f
theorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ :=
Equiv.swap_apply_right _ _
theorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ :=
Equiv.swap_apply_left _ _
theorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) :
τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ :=
(fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _
theorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by
rw [tau, Equiv.symm_swap, Equiv.swap_apply_left]
theorem τ_symm_apply_infinity :
Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by
rw [tau, Equiv.symm_swap, Equiv.swap_apply_right]
/-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending
point at infinity to point at infinity and sending coset `y` to `β • y`.
-/
def g : B →* SX' where
toFun β :=
{ toFun := fun x => β • x
invFun := fun x => β⁻¹ • x
left_inv := fun x => by
dsimp only
rw [← mul_smul, mul_left_inv, one_smul]
right_inv := fun x => by
dsimp only
rw [← mul_smul, mul_right_inv, one_smul] }
map_one' := by
ext
simp [one_smul]
map_mul' b1 b2 := by
ext
simp [mul_smul]
local notation "g" => g f
/-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹`
-/
def h : B →* SX' where
-- Porting note: mathport removed () from (τ) which are needed
toFun β := ((τ).symm.trans (g β)).trans τ
map_one' := by
ext
simp
map_mul' b1 b2 := by
ext
simp
local notation "h" => h f
/-!
The strategy is the following: assuming `epi f`
* prove that `f.range = {x | h x = g x}`;
* thus `f ≫ h = f ≫ g` so that `h = g`;
* but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`.
-/
theorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) :
g x (fromCoset y) = fromCoset ⟨x • ↑y,
by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl
theorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl
theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by
change ((τ).symm.trans (g x)).trans τ _ = _
simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]
rw [τ_symm_apply_infinity, g_apply_fromCoset]
simpa only using τ_apply_fromCoset' f x hx
theorem h_apply_fromCoset (x : B) :
(h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =
fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by
change ((τ).symm.trans (g x)).trans τ _ = _
simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]
theorem h_apply_fromCoset' (x : B) (b : B) (hb : b ∈ f.range) :
h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ :=
(fromCoset_eq_of_mem_range _ hb).symm ▸ h_apply_fromCoset f x
theorem h_apply_fromCoset_nin_range (x : B) (hx : x ∈ f.range) (b : B) (hb : b ∉ f.range) :
h x (fromCoset ⟨b • f.range, b, rfl⟩) = fromCoset ⟨(x * b) • ↑f.range, x * b, rfl⟩ := by
change ((τ).symm.trans (g x)).trans τ _ = _
simp only [tau, MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply]
rw [Equiv.symm_swap,
@Equiv.swap_apply_of_ne_of_ne X' _ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) ∞
(fromCoset ⟨b • ↑f.range, b, rfl⟩) (fromCoset_ne_of_nin_range _ hb) (by simp)]
simp only [g_apply_fromCoset, leftCoset_assoc]
refine Equiv.swap_apply_of_ne_of_ne (fromCoset_ne_of_nin_range _ fun r => hb ?_) (by simp)
convert Subgroup.mul_mem _ (Subgroup.inv_mem _ hx) r
rw [← mul_assoc, mul_left_inv, one_mul]
theorem agree : f.range = { x | h x = g x } := by
refine Set.ext fun b => ⟨?_, fun hb : h b = g b => by_contradiction fun r => ?_⟩
· rintro ⟨a, rfl⟩
change h (f a) = g (f a)
ext ⟨⟨_, ⟨y, rfl⟩⟩⟩
· rw [g_apply_fromCoset]
by_cases m : y ∈ f.range
· rw [h_apply_fromCoset' _ _ _ m, fromCoset_eq_of_mem_range _ m]
change fromCoset _ = fromCoset ⟨f a • (y • _), _⟩
simp only [← fromCoset_eq_of_mem_range _ (Subgroup.mul_mem _ ⟨a, rfl⟩ m), smul_smul]
· rw [h_apply_fromCoset_nin_range f (f a) ⟨_, rfl⟩ _ m]
simp only [leftCoset_assoc]
· rw [g_apply_infinity, h_apply_infinity f (f a) ⟨_, rfl⟩]
· have eq1 : (h b) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) =
fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by
change ((τ).symm.trans (g b)).trans τ _ = _
dsimp [tau]
simp [g_apply_infinity f]
have eq2 :
g b (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨b • ↑f.range, b, rfl⟩ := rfl
exact (fromCoset_ne_of_nin_range _ r).symm (by rw [← eq1, ← eq2, DFunLike.congr_fun hb])
theorem comp_eq : (f ≫ show B ⟶ Grp.of SX' from g) = f ≫ show B ⟶ Grp.of SX' from h := by
ext a
change g (f a) = h (f a)
have : f a ∈ { b | h b = g b } := by
rw [← agree]
use a
rw [this]
theorem g_ne_h (x : B) (hx : x ∉ f.range) : g ≠ h := by
intro r
replace r :=
DFunLike.congr_fun (DFunLike.congr_fun r x) (fromCoset ⟨f.range, ⟨1, one_leftCoset _⟩⟩)
change _ = ((τ).symm.trans (g x)).trans τ _ at r
rw [g_apply_fromCoset, MonoidHom.coe_mk] at r
simp only [MonoidHom.coe_range, Subtype.coe_mk, Equiv.symm_swap, Equiv.toFun_as_coe,
Equiv.coe_trans, Function.comp_apply] at r
erw [Equiv.swap_apply_left, g_apply_infinity, Equiv.swap_apply_right] at r
exact fromCoset_ne_of_nin_range _ hx r
end SurjectiveOfEpiAuxs
theorem surjective_of_epi [Epi f] : Function.Surjective f := by
by_contra r
dsimp [Function.Surjective] at r
push_neg at r
rcases r with ⟨b, hb⟩
exact
SurjectiveOfEpiAuxs.g_ne_h f b (fun ⟨c, hc⟩ => hb _ hc)
((cancel_epi f).1 (SurjectiveOfEpiAuxs.comp_eq f))
theorem epi_iff_surjective : Epi f ↔ Function.Surjective f :=
⟨fun _ => surjective_of_epi f, ConcreteCategory.epi_of_surjective f⟩
theorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=
Iff.trans (epi_iff_surjective _) (Subgroup.eq_top_iff' f.range).symm
end Grp
namespace AddGrp
variable {A B : AddGrp.{u}} (f : A ⟶ B)
theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by
have i1 : Epi f ↔ Epi (groupAddGroupEquivalence.inverse.map f) := by
refine ⟨?_, groupAddGroupEquivalence.inverse.epi_of_epi_map⟩
intro e'
apply groupAddGroupEquivalence.inverse.map_epi
rwa [Grp.epi_iff_surjective] at i1
theorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=
Iff.trans (epi_iff_surjective _) (AddSubgroup.eq_top_iff' f.range).symm
end AddGrp
namespace Grp
variable {A B : Grp.{u}} (f : A ⟶ B)
@[to_additive AddGrp.forget_grp_preserves_mono]
instance forget_grp_preserves_mono : (forget Grp).PreservesMonomorphisms where
preserves f e := by rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e
@[to_additive AddGrp.forget_grp_preserves_epi]
instance forget_grp_preserves_epi : (forget Grp).PreservesEpimorphisms where
preserves f e := by rwa [epi_iff_surjective, ← CategoryTheory.epi_iff_surjective] at e
end Grp
namespace CommGrp
variable {A B : CommGrp.{u}} (f : A ⟶ B)
-- Porting note: again to help with non-transparency
private instance (A : CommGrp) : CommGroup A.α := A.str
private instance (A : CommGrp) : Group A.α := A.str.toGroup
@[to_additive]
theorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ :=
MonoidHom.ker_eq_bot_of_cancel fun u _ =>
(@cancel_mono _ _ _ _ _ f _ (show CommGrp.of f.ker ⟶ A from u) _).1
@[to_additive]
theorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ :=
⟨fun _ => ker_eq_bot_of_mono f, fun h =>
ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩
@[to_additive]
theorem mono_iff_injective : Mono f ↔ Function.Injective f :=
Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f
@[to_additive]
theorem range_eq_top_of_epi [Epi f] : f.range = ⊤ :=
MonoidHom.range_eq_top_of_cancel fun u v h =>
(@cancel_epi _ _ _ _ _ f _ (show B ⟶ ⟨B ⧸ MonoidHom.range f, inferInstance⟩ from u) v).1 h
-- Porting note: again lack of transparency
@[to_additive]
instance (G : CommGrp) : CommGroup <| (forget CommGrp).obj G :=
G.str
@[to_additive]
theorem epi_iff_range_eq_top : Epi f ↔ f.range = ⊤ :=
⟨fun _ => range_eq_top_of_epi _, fun hf =>
ConcreteCategory.epi_of_surjective _ <| MonoidHom.range_top_iff_surjective.mp hf⟩
@[to_additive]
theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by
rw [epi_iff_range_eq_top, MonoidHom.range_top_iff_surjective]
@[to_additive AddCommGrp.forget_commGrp_preserves_mono]
instance forget_commGrp_preserves_mono : (forget CommGrp).PreservesMonomorphisms where
preserves f e := by rwa [mono_iff_injective, ← CategoryTheory.mono_iff_injective] at e
@[to_additive AddCommGrp.forget_commGrp_preserves_epi]
instance forget_commGrp_preserves_epi : (forget CommGrp).PreservesEpimorphisms where
preserves f e := by rwa [epi_iff_surjective, ← CategoryTheory.epi_iff_surjective] at e
end CommGrp
end
|
Algebra\Category\Grp\EquivalenceGroupAddGroup.lean
|
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.Algebra.Group.Equiv.TypeTags
/-!
# Equivalence between `Group` and `AddGroup`
This file contains two equivalences:
* `groupAddGroupEquivalence` : the equivalence between `Grp` and `AddGrp` by sending
`X : Grp` to `Additive X` and `Y : AddGrp` to `Multiplicative Y`.
* `commGroupAddCommGroupEquivalence` : the equivalence between `CommGrp` and `AddCommGrp`
by sending `X : CommGrp` to `Additive X` and `Y : AddCommGrp` to `Multiplicative Y`.
-/
open CategoryTheory
namespace Grp
-- Porting note: Lean cannot find these now
private instance (X : Grp) : MulOneClass X.α := X.str.toMulOneClass
private instance (X : CommGrp) : MulOneClass X.α := X.str.toMulOneClass
private instance (X : AddGrp) : AddZeroClass X.α := X.str.toAddZeroClass
private instance (X : AddCommGrp) : AddZeroClass X.α := X.str.toAddZeroClass
/-- The functor `Group ⥤ AddGroup` by sending `X ↦ Additive X` and `f ↦ f`.
-/
@[simps]
def toAddGrp : Grp ⥤ AddGrp where
obj X := AddGrp.of (Additive X)
map {X} {Y} := MonoidHom.toAdditive
end Grp
namespace CommGrp
/-- The functor `CommGroup ⥤ AddCommGroup` by sending `X ↦ Additive X` and `f ↦ f`.
-/
@[simps]
def toAddCommGrp : CommGrp ⥤ AddCommGrp where
obj X := AddCommGrp.of (Additive X)
map {X} {Y} := MonoidHom.toAdditive
end CommGrp
namespace AddGrp
/-- The functor `AddGroup ⥤ Group` by sending `X ↦ Multiplicative Y` and `f ↦ f`.
-/
@[simps]
def toGrp : AddGrp ⥤ Grp where
obj X := Grp.of (Multiplicative X)
map {X} {Y} := AddMonoidHom.toMultiplicative
end AddGrp
namespace AddCommGrp
/-- The functor `AddCommGroup ⥤ CommGroup` by sending `X ↦ Multiplicative Y` and `f ↦ f`.
-/
@[simps]
def toCommGrp : AddCommGrp ⥤ CommGrp where
obj X := CommGrp.of (Multiplicative X)
map {X} {Y} := AddMonoidHom.toMultiplicative
end AddCommGrp
/-- The equivalence of categories between `Group` and `AddGroup`
-/
def groupAddGroupEquivalence : Grp ≌ AddGrp :=
CategoryTheory.Equivalence.mk Grp.toAddGrp AddGrp.toGrp
(NatIso.ofComponents fun X => MulEquiv.toGrpIso (MulEquiv.multiplicativeAdditive X))
(NatIso.ofComponents fun X => AddEquiv.toAddGrpIso (AddEquiv.additiveMultiplicative X))
/-- The equivalence of categories between `CommGroup` and `AddCommGroup`.
-/
def commGroupAddCommGroupEquivalence : CommGrp ≌ AddCommGrp :=
CategoryTheory.Equivalence.mk CommGrp.toAddCommGrp AddCommGrp.toCommGrp
(NatIso.ofComponents fun X => MulEquiv.toCommGrpIso (MulEquiv.multiplicativeAdditive X))
(NatIso.ofComponents fun X => AddEquiv.toAddCommGrpIso (AddEquiv.additiveMultiplicative X))
|
Algebra\Category\Grp\FilteredColimits.lean
|
/-
Copyright (c) 2021 Justus Springer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Justus Springer
-/
import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.Algebra.Category.MonCat.FilteredColimits
/-!
# The forgetful functor from (commutative) (additive) groups 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 ⥤ Grp`.
We show that the colimit of `F ⋙ forget₂ Grp MonCat` (in `MonCat`) carries the structure of a
group,
thereby showing that the forgetful functor `forget₂ Grp MonCat` preserves filtered colimits.
In particular, this implies that `forget Grp` preserves filtered colimits.
Similarly for `AddGrp`, `CommGrp` and `AddCommGrp`.
-/
universe v u
noncomputable section
open CategoryTheory Limits
open IsFiltered renaming max → max' -- avoid name collision with `_root_.max`.
namespace Grp.FilteredColimits
section
open MonCat.FilteredColimits (colimit_one_eq colimit_mul_mk_eq)
-- Mathlib3 used parameters here, mainly so we could have the abbreviations `G` and `G.mk` below,
-- without passing around `F` all the time.
variable {J : Type v} [SmallCategory J] [IsFiltered J] (F : J ⥤ Grp.{max v u})
/-- The colimit of `F ⋙ forget₂ Grp MonCat` in the category `MonCat`.
In the following, we will show that this has the structure of a group.
-/
@[to_additive
"The colimit of `F ⋙ forget₂ AddGrp AddMonCat` in the category `AddMonCat`.
In the following, we will show that this has the structure of an additive group."]
noncomputable abbrev G : MonCat :=
MonCat.FilteredColimits.colimit.{v, u} (F ⋙ forget₂ Grp MonCat.{max v u})
/-- The canonical projection into the colimit, as a quotient type. -/
@[to_additive "The canonical projection into the colimit, as a quotient type."]
abbrev G.mk : (Σ j, F.obj j) → G.{v, u} F :=
Quot.mk (Types.Quot.Rel (F ⋙ forget Grp.{max v u}))
@[to_additive]
theorem G.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) :
G.mk.{v, u} F x = G.mk F y :=
Quot.EqvGen_sound (Types.FilteredColimit.eqvGen_quot_rel_of_rel (F ⋙ forget Grp) x y h)
/-- The "unlifted" version of taking inverses in the colimit. -/
@[to_additive "The \"unlifted\" version of negation in the colimit."]
def colimitInvAux (x : Σ j, F.obj j) : G.{v, u} F :=
G.mk F ⟨x.1, x.2⁻¹⟩
@[to_additive]
theorem colimitInvAux_eq_of_rel (x y : Σ j, F.obj j)
(h : Types.FilteredColimit.Rel (F ⋙ forget Grp) x y) :
colimitInvAux.{v, u} F x = colimitInvAux F y := by
apply G.mk_eq
obtain ⟨k, f, g, hfg⟩ := h
use k, f, g
rw [MonoidHom.map_inv, MonoidHom.map_inv, inv_inj]
exact hfg
/-- Taking inverses in the colimit. See also `colimitInvAux`. -/
@[to_additive "Negation in the colimit. See also `colimitNegAux`."]
instance colimitInv : Inv (G.{v, u} F) where
inv x := by
refine Quot.lift (colimitInvAux.{v, u} F) ?_ x
intro x y h
apply colimitInvAux_eq_of_rel
apply Types.FilteredColimit.rel_of_quot_rel
exact h
@[to_additive (attr := simp)]
theorem colimit_inv_mk_eq (x : Σ j, F.obj j) : (G.mk.{v, u} F x)⁻¹ = G.mk F ⟨x.1, x.2⁻¹⟩ :=
rfl
@[to_additive]
noncomputable instance colimitGroup : Group (G.{v, u} F) :=
{ colimitInv.{v, u} F, (G.{v, u} F).str with
mul_left_inv := fun x => by
refine Quot.inductionOn x ?_; clear x; intro x
cases' x with j x
erw [colimit_inv_mk_eq,
colimit_mul_mk_eq (F ⋙ forget₂ Grp MonCat.{max v u}) ⟨j, _⟩ ⟨j, _⟩ j (𝟙 j) (𝟙 j),
colimit_one_eq (F ⋙ forget₂ Grp MonCat.{max v u}) j]
dsimp
erw [CategoryTheory.Functor.map_id, mul_left_inv] }
/-- The bundled group giving the filtered colimit of a diagram. -/
@[to_additive "The bundled additive group giving the filtered colimit of a diagram."]
noncomputable def colimit : Grp.{max v u} :=
Grp.of (G.{v, u} F)
/-- The cocone over the proposed colimit group. -/
@[to_additive "The cocone over the proposed colimit additive group."]
noncomputable def colimitCocone : Cocone F where
pt := colimit.{v, u} F
ι := { (MonCat.FilteredColimits.colimitCocone (F ⋙ forget₂ Grp MonCat.{max v u})).ι with }
/-- The proposed colimit cocone is a colimit in `Grp`. -/
@[to_additive "The proposed colimit cocone is a colimit in `AddGroup`."]
def colimitCoconeIsColimit : IsColimit (colimitCocone.{v, u} F) where
desc t :=
MonCat.FilteredColimits.colimitDesc.{v, u} (F ⋙ forget₂ Grp MonCat.{max v u})
((forget₂ Grp MonCat).mapCocone t)
fac t j :=
DFunLike.coe_injective <|
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget Grp)).fac
((forget Grp).mapCocone t) j
uniq t _ h :=
DFunLike.coe_injective' <|
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget Grp)).uniq
((forget Grp).mapCocone t) _
fun j => funext fun x => DFunLike.congr_fun (h j) x
@[to_additive forget₂AddMonPreservesFilteredColimits]
noncomputable instance forget₂MonPreservesFilteredColimits :
PreservesFilteredColimits.{u} (forget₂ Grp.{u} MonCat.{u}) where
preserves_filtered_colimits x hx1 _ :=
letI : Category.{u, u} x := hx1
⟨fun {F} => preservesColimitOfPreservesColimitCocone (colimitCoconeIsColimit.{u, u} F)
(MonCat.FilteredColimits.colimitCoconeIsColimit.{u, u} _)⟩
@[to_additive]
noncomputable instance forgetPreservesFilteredColimits :
PreservesFilteredColimits (forget Grp.{u}) :=
Limits.compPreservesFilteredColimits (forget₂ Grp MonCat) (forget MonCat.{u})
end
end Grp.FilteredColimits
namespace CommGrp.FilteredColimits
section
-- We use parameters here, mainly so we can have the abbreviation `G` below, without
-- passing around `F` all the time.
variable {J : Type v} [SmallCategory J] [IsFiltered J] (F : J ⥤ CommGrp.{max v u})
/-- The colimit of `F ⋙ forget₂ CommGrp Grp` in the category `Grp`.
In the following, we will show that this has the structure of a _commutative_ group.
-/
@[to_additive
"The colimit of `F ⋙ forget₂ AddCommGrp AddGrp` in the category `AddGrp`.
In the following, we will show that this has the structure of a _commutative_ additive group."]
noncomputable abbrev G : Grp.{max v u} :=
Grp.FilteredColimits.colimit.{v, u} (F ⋙ forget₂ CommGrp.{max v u} Grp.{max v u})
@[to_additive]
noncomputable instance colimitCommGroup : CommGroup.{max v u} (G.{v, u} F) :=
{ (G F).str,
CommMonCat.FilteredColimits.colimitCommMonoid
(F ⋙ forget₂ CommGrp CommMonCat.{max v u}) with }
/-- The bundled commutative group giving the filtered colimit of a diagram. -/
@[to_additive "The bundled additive commutative group giving the filtered colimit of a diagram."]
noncomputable def colimit : CommGrp :=
CommGrp.of (G.{v, u} F)
/-- The cocone over the proposed colimit commutative group. -/
@[to_additive "The cocone over the proposed colimit additive commutative group."]
noncomputable def colimitCocone : Cocone F where
pt := colimit.{v, u} F
ι :=
{ (Grp.FilteredColimits.colimitCocone
(F ⋙ forget₂ CommGrp Grp.{max v u})).ι with }
/-- The proposed colimit cocone is a colimit in `CommGrp`. -/
@[to_additive "The proposed colimit cocone is a colimit in `AddCommGroup`."]
def colimitCoconeIsColimit : IsColimit (colimitCocone.{v, u} F) where
desc t :=
(Grp.FilteredColimits.colimitCoconeIsColimit.{v, u}
(F ⋙ forget₂ CommGrp Grp.{max v u})).desc
((forget₂ CommGrp Grp.{max v u}).mapCocone t)
fac t j :=
DFunLike.coe_injective <|
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget CommGrp)).fac
((forget CommGrp).mapCocone t) j
uniq t _ h :=
DFunLike.coe_injective <|
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget CommGrp)).uniq
((forget CommGrp).mapCocone t) _ fun j => funext fun x => DFunLike.congr_fun (h j) x
@[to_additive]
noncomputable instance forget₂GroupPreservesFilteredColimits :
PreservesFilteredColimits (forget₂ CommGrp Grp.{u}) where
preserves_filtered_colimits J hJ1 _ :=
letI : Category J := hJ1
{ preservesColimit := fun {F} =>
preservesColimitOfPreservesColimitCocone (colimitCoconeIsColimit.{u, u} F)
(Grp.FilteredColimits.colimitCoconeIsColimit.{u, u}
(F ⋙ forget₂ CommGrp Grp.{u})) }
@[to_additive]
noncomputable instance forgetPreservesFilteredColimits :
PreservesFilteredColimits (forget CommGrp.{u}) :=
Limits.compPreservesFilteredColimits (forget₂ CommGrp Grp) (forget Grp.{u})
end
end CommGrp.FilteredColimits
|
Algebra\Category\Grp\ForgetCorepresentable.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.Algebra.Group.ULift
import Mathlib.CategoryTheory.Yoneda
/-!
# The forget functor is corepresentable
It is shown that the forget functor `AddCommGrp.{u} ⥤ Type u` is corepresentable
by `ULift ℤ`. Similar results are obtained for the variants `CommGrp`, `AddGrp`
and `Grp`.
-/
universe u
open CategoryTheory Opposite
namespace MonoidHom
/-- The equivalence `(β →* γ) ≃ (α →* γ)` obtained by precomposition with
a multiplicative equivalence `e : α ≃* β`. -/
@[simps]
def precompEquiv {α β : Type*} [Monoid α] [Monoid β] (e : α ≃* β) (γ : Type*) [Monoid γ] :
(β →* γ) ≃ (α →* γ) where
toFun f := f.comp e
invFun g := g.comp e.symm
left_inv _ := by ext; simp
right_inv _ := by ext; simp
/-- The equivalence `(Multiplicative ℤ →* α) ≃ α` for any group `α`. -/
@[simps]
def fromMultiplicativeIntEquiv (α : Type u) [Group α] : (Multiplicative ℤ →* α) ≃ α where
toFun φ := φ (Multiplicative.ofAdd 1)
invFun x := zpowersHom α x
left_inv φ := by ext; simp
right_inv x := by simp
/-- The equivalence `(ULift (Multiplicative ℤ) →* α) ≃ α` for any group `α`. -/
@[simps!]
def fromULiftMultiplicativeIntEquiv (α : Type u) [Group α] :
(ULift.{u} (Multiplicative ℤ) →* α) ≃ α :=
(precompEquiv (MulEquiv.ulift.symm) _).trans (fromMultiplicativeIntEquiv α)
end MonoidHom
namespace AddMonoidHom
/-- The equivalence `(β →+ γ) ≃ (α →+ γ)` obtained by precomposition with
an additive equivalence `e : α ≃+ β`. -/
@[simps]
def precompEquiv {α β : Type*} [AddMonoid α] [AddMonoid β] (e : α ≃+ β) (γ : Type*) [AddMonoid γ] :
(β →+ γ) ≃ (α →+ γ) where
toFun f := f.comp e
invFun g := g.comp e.symm
left_inv _ := by ext; simp
right_inv _ := by ext; simp
/-- The equivalence `(ℤ →+ α) ≃ α` for any additive group `α`. -/
@[simps]
def fromIntEquiv (α : Type u) [AddGroup α] : (ℤ →+ α) ≃ α where
toFun φ := φ 1
invFun x := zmultiplesHom α x
left_inv φ := by ext; simp
right_inv x := by simp
/-- The equivalence `(ULift ℤ →+ α) ≃ α` for any additive group `α`. -/
@[simps!]
def fromULiftIntEquiv (α : Type u) [AddGroup α] : (ULift.{u} ℤ →+ α) ≃ α :=
(precompEquiv (AddEquiv.ulift.symm) _).trans (fromIntEquiv α)
end AddMonoidHom
/-- The forget functor `Grp.{u} ⥤ Type u` is corepresentable. -/
def Grp.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} (Multiplicative ℤ)))) ≅ forget Grp.{u} :=
(NatIso.ofComponents (fun M => (MonoidHom.fromULiftMultiplicativeIntEquiv M.α).toIso))
/-- The forget functor `CommGrp.{u} ⥤ Type u` is corepresentable. -/
def CommGrp.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} (Multiplicative ℤ)))) ≅ forget CommGrp.{u} :=
(NatIso.ofComponents (fun M => (MonoidHom.fromULiftMultiplicativeIntEquiv M.α).toIso))
/-- The forget functor `AddGrp.{u} ⥤ Type u` is corepresentable. -/
def AddGrp.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} ℤ))) ≅ forget AddGrp.{u} :=
(NatIso.ofComponents (fun M => (AddMonoidHom.fromULiftIntEquiv M.α).toIso))
/-- The forget functor `AddCommGrp.{u} ⥤ Type u` is corepresentable. -/
def AddCommGrp.coyonedaObjIsoForget :
coyoneda.obj (op (of (ULift.{u} ℤ))) ≅ forget AddCommGrp.{u} :=
(NatIso.ofComponents (fun M => (AddMonoidHom.fromULiftIntEquiv M.α).toIso))
instance Grp.forget_corepresentable :
(forget Grp.{u}).Corepresentable where
has_corepresentation := ⟨_, ⟨Grp.coyonedaObjIsoForget⟩⟩
instance CommGrp.forget_corepresentable :
(forget CommGrp.{u}).Corepresentable where
has_corepresentation := ⟨_, ⟨CommGrp.coyonedaObjIsoForget⟩⟩
instance AddGrp.forget_corepresentable :
(forget AddGrp.{u}).Corepresentable where
has_corepresentation := ⟨_, ⟨AddGrp.coyonedaObjIsoForget⟩⟩
instance AddCommGrp.forget_corepresentable :
(forget AddCommGrp.{u}).Corepresentable where
has_corepresentation := ⟨_, ⟨AddCommGrp.coyonedaObjIsoForget⟩⟩
|
Algebra\Category\Grp\Images.lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Category.Grp.Abelian
import Mathlib.CategoryTheory.Limits.Shapes.Images
/-!
# The category of commutative additive groups 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 `AddCommGrp` is an abelian category.
-/
open CategoryTheory
open CategoryTheory.Limits
universe u
namespace AddCommGrp
-- Note that because `injective_of_mono` is currently only proved in `Type 0`,
-- we restrict to the lowest universe here for now.
variable {G H : AddCommGrp.{0}} (f : G ⟶ H)
attribute [local ext] Subtype.ext_val
section
-- implementation details of `IsImage` for `AddCommGrp`; use the API, not these
/-- the image of a morphism in `AddCommGrp` is just the bundling of `AddMonoidHom.range f` -/
def image : AddCommGrp :=
AddCommGrp.of (AddMonoidHom.range f)
/-- the inclusion of `image f` into the target -/
def image.ι : image f ⟶ H :=
f.range.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 :=
f.rangeRestrict
theorem image.fac : factorThruImage f ≫ image.ι f = f := by
ext
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 where
toFun := (fun x => F'.e (Classical.indefiniteDescription _ x.2).1 : image f → F'.I)
map_zero' := by
haveI := F'.m_mono
apply injective_of_mono F'.m
change (F'.e ≫ F'.m) _ = _
rw [F'.fac, AddMonoidHom.map_zero]
exact (Classical.indefiniteDescription (fun y => f y = 0) _).2
map_add' := by
intro x y
haveI := F'.m_mono
apply injective_of_mono F'.m
rw [AddMonoidHom.map_add]
change (F'.e ≫ F'.m) _ = (F'.e ≫ F'.m) _ + (F'.e ≫ F'.m) _
rw [F'.fac]
rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]
rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]
rw [(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 `AddCommGrp` through a mono. -/
def monoFactorisation : MonoFactorisation f where
I := image f
m := image.ι f
e := factorThruImage f
/-- the factorisation of any morphism in `AddCommGrp` 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 `AddCommGrp`
agrees with the usual group-theoretical range.
-/
noncomputable def imageIsoRange {G H : AddCommGrp.{0}} (f : G ⟶ H) :
Limits.image f ≅ AddCommGrp.of f.range :=
IsImage.isoExt (Image.isImage f) (isImage f)
end AddCommGrp
|
Algebra\Category\Grp\Injective.lean
|
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.Algebra.Category.Grp.ZModuleEquivalence
import Mathlib.Algebra.EuclideanDomain.Int
import Mathlib.Algebra.Module.Injective
import Mathlib.RingTheory.PrincipalIdealDomain
import Mathlib.Topology.Instances.AddCircle
/-!
# Injective objects in the category of abelian groups
In this file we prove that divisible groups are injective object in category of (additive) abelian
groups and that the category of abelian groups has enough injective objects.
## Main results
- `AddCommGrp.injective_of_divisible` : a divisible group is also an injective object.
- `AddCommGrp.enoughInjectives` : the category of abelian groups (written additively) has
enough injectives.
- `CommGrp.enoughInjectives` : the category of abelian group (written multiplicatively) has
enough injectives.
## Implementation notes
The details of the proof that the category of abelian groups has enough injectives is hidden
inside the namespace `AddCommGroup.enough_injectives_aux_proofs`. These are not marked `private`,
but are not supposed to be used directly.
-/
open CategoryTheory
open Pointwise
universe u
variable (A : Type u) [AddCommGroup A]
theorem Module.Baer.of_divisible [DivisibleBy A ℤ] : Module.Baer ℤ A := fun I g ↦ by
rcases IsPrincipalIdealRing.principal I with ⟨m, rfl⟩
obtain rfl | h0 := eq_or_ne m 0
· refine ⟨0, fun n hn ↦ ?_⟩
rw [Submodule.span_zero_singleton] at hn
subst hn
exact (map_zero g).symm
let gₘ := g ⟨m, Submodule.subset_span (Set.mem_singleton _)⟩
refine ⟨LinearMap.toSpanSingleton ℤ A (DivisibleBy.div gₘ m), fun n hn ↦ ?_⟩
rcases Submodule.mem_span_singleton.mp hn with ⟨n, rfl⟩
rw [map_zsmul, LinearMap.toSpanSingleton_apply, DivisibleBy.div_cancel gₘ h0, ← map_zsmul g,
SetLike.mk_smul_mk]
namespace AddCommGrp
theorem injective_as_module_iff : Injective (⟨A⟩ : ModuleCat ℤ) ↔
Injective (⟨A,inferInstance⟩ : AddCommGrp) :=
((forget₂ (ModuleCat ℤ) AddCommGrp).asEquivalence.map_injective_iff ⟨A⟩).symm
instance injective_of_divisible [DivisibleBy A ℤ] :
Injective (⟨A,inferInstance⟩ : AddCommGrp) :=
(injective_as_module_iff A).mp <|
Module.injective_object_of_injective_module (inj := (Module.Baer.of_divisible A).injective)
instance injective_ratCircle : Injective <| of <| ULift.{u} <| AddCircle (1 : ℚ) :=
injective_of_divisible _
end AddCommGrp
|
Algebra\Category\Grp\Kernels.lean
|
/-
Copyright (c) 2023 Moritz Firsching. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata, Moritz Firsching, Nikolas Kuhn
-/
import Mathlib.Algebra.Category.Grp.EpiMono
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
/-!
# The concrete (co)kernels in the category of abelian groups are categorical (co)kernels.
-/
namespace AddCommGrp
open AddMonoidHom CategoryTheory Limits QuotientAddGroup
universe u
variable {G H : AddCommGrp.{u}} (f : G ⟶ H)
/-- The kernel cone induced by the concrete kernel. -/
def kernelCone : KernelFork f :=
KernelFork.ofι (Z := of f.ker) f.ker.subtype <| ext fun x => x.casesOn fun _ hx => hx
/-- The kernel of a group homomorphism is a kernel in the categorical sense. -/
def kernelIsLimit : IsLimit <| kernelCone f :=
Fork.IsLimit.mk _
(fun s => (by exact Fork.ι s : _ →+ G).codRestrict _ fun c => f.mem_ker.mpr <|
by exact DFunLike.congr_fun s.condition c)
(fun _ => by rfl)
(fun _ _ h => ext fun x => Subtype.ext_iff_val.mpr <| by exact DFunLike.congr_fun h x)
/-- The cokernel cocone induced by the projection onto the quotient. -/
def cokernelCocone : CokernelCofork f :=
CokernelCofork.ofπ (Z := of <| H ⧸ f.range) (mk' f.range) <| ext fun x =>
(eq_zero_iff _).mpr ⟨x, rfl⟩
/-- The projection onto the quotient is a cokernel in the categorical sense. -/
def cokernelIsColimit : IsColimit <| cokernelCocone f :=
Cofork.IsColimit.mk _
(fun s => lift _ _ <| (range_le_ker_iff _ _).mpr <| CokernelCofork.condition s)
(fun _ => rfl)
(fun _ _ h => have : Epi (cokernelCocone f).π := (epi_iff_surjective _).mpr <| mk'_surjective _
(cancel_epi (cokernelCocone f).π).mp <| by simpa only [parallelPair_obj_one] using h)
end AddCommGrp
|
Algebra\Category\Grp\Limits.lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Category.MonCat.Limits
import Mathlib.Algebra.Category.Grp.ForgetCorepresentable
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.CategoryTheory.Comma.Over
import Mathlib.CategoryTheory.Limits.ConcreteCategory.Basic
import Mathlib.CategoryTheory.ConcreteCategory.ReflectsIso
/-!
# The category of (commutative) (additive) groups 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 CategoryTheory.Limits
universe v u w
noncomputable section
variable {J : Type v} [Category.{w} J]
namespace Grp
variable (F : J ⥤ Grp.{u})
@[to_additive]
instance groupObj (j) : Group ((F ⋙ forget Grp).obj j) :=
inferInstanceAs <| Group (F.obj j)
/-- The flat sections of a functor into `Grp` form a subgroup of all sections.
-/
@[to_additive
"The flat sections of a functor into `AddGrp` form an additive subgroup of all sections."]
def sectionsSubgroup : Subgroup (∀ j, F.obj j) :=
{ MonCat.sectionsSubmonoid (F ⋙ forget₂ Grp MonCat) with
carrier := (F ⋙ forget Grp).sections
inv_mem' := fun {a} ah j j' f => by
simp only [Functor.comp_map, Pi.inv_apply, MonoidHom.map_inv, inv_inj]
dsimp [Functor.sections] at ah ⊢
rw [(F.map f).map_inv (a j), ah f] }
@[to_additive]
instance sectionsGroup : Group (F ⋙ forget Grp.{u}).sections :=
(sectionsSubgroup F).toGroup
/-- The projection from `Functor.sections` to a factor as a `MonoidHom`. -/
@[to_additive "The projection from `Functor.sections` to a factor as an `AddMonoidHom`."]
def sectionsπMonoidHom (j : J) : (F ⋙ forget Grp.{u}).sections →* F.obj j where
toFun x := x.val j
map_one' := rfl
map_mul' _ _ := rfl
section
variable [Small.{u} (Functor.sections (F ⋙ forget Grp))]
@[to_additive]
noncomputable instance limitGroup :
Group (Types.Small.limitCone.{v, u} (F ⋙ forget Grp.{u})).pt :=
inferInstanceAs <| Group (Shrink (F ⋙ forget Grp.{u}).sections)
@[to_additive]
instance : Small.{u} (Functor.sections ((F ⋙ forget₂ Grp MonCat) ⋙ forget MonCat)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget Grp))
/-- We show that the forgetful functor `Grp ⥤ MonCat` creates limits.
All we need to do is notice that the limit point has a `Group` instance available, and then reuse
the existing limit. -/
@[to_additive "We show that the forgetful functor `AddGrp ⥤ AddMonCat` creates limits.
All we need to do is notice that the limit point has an `AddGroup` instance available, and then
reuse the existing limit."]
noncomputable instance Forget₂.createsLimit :
CreatesLimit F (forget₂ Grp.{u} MonCat.{u}) :=
-- Porting note: need to add `forget₂ GrpCat MonCat` reflects isomorphism
letI : (forget₂ Grp.{u} MonCat.{u}).ReflectsIsomorphisms :=
CategoryTheory.reflectsIsomorphisms_forget₂ _ _
createsLimitOfReflectsIso (K := F) (F := (forget₂ Grp.{u} MonCat.{u}))
fun c' t =>
{ liftedCone :=
{ pt := Grp.of (Types.Small.limitCone (F ⋙ forget Grp)).pt
π :=
{ app := MonCat.limitπMonoidHom (F ⋙ forget₂ Grp MonCat)
naturality :=
(MonCat.HasLimits.limitCone
(F ⋙ forget₂ Grp MonCat.{u})).π.naturality } }
validLift := by apply IsLimit.uniqueUpToIso (MonCat.HasLimits.limitConeIsLimit.{v, u} _) t
makesLimit :=
IsLimit.ofFaithful (forget₂ Grp MonCat.{u}) (MonCat.HasLimits.limitConeIsLimit _)
(fun s => _) fun s => rfl }
/-- A choice of limit cone for a functor into `Grp`.
(Generally, you'll just want to use `limit F`.)
-/
@[to_additive "A choice of limit cone for a functor into `Grp`.
(Generally, you'll just want to use `limit F`.)"]
noncomputable def limitCone : Cone F :=
liftLimit (limit.isLimit (F ⋙ forget₂ Grp.{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 Grp).sections` is `u`-small, `F` has a limit. -/
@[to_additive "If `(F ⋙ forget AddGrp).sections` is `u`-small, `F` has a limit."]
instance hasLimit : HasLimit F :=
HasLimit.mk {
cone := limitCone F
isLimit := limitConeIsLimit F
}
end
/-- A functor `F : J ⥤ Grp.{u}` has a limit iff `(F ⋙ forget Grp).sections` is
`u`-small. -/
@[to_additive "A functor `F : J ⥤ AddGrp.{u}` has a limit iff
`(F ⋙ forget AddGrp).sections` is `u`-small."]
lemma hasLimit_iff_small_sections :
HasLimit F ↔ Small.{u} (F ⋙ forget Grp).sections := by
constructor
· apply Concrete.small_sections_of_hasLimit
· intro
infer_instance
/-- If `J` is `u`-small, `Grp.{u}` has limits of shape `J`. -/
@[to_additive "If `J` is `u`-small, `AddGrp.{u}` has limits of shape `J`."]
instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J Grp.{u} where
has_limit _ := inferInstance
/-- The category of groups has all limits. -/
@[to_additive "The category of additive groups has all limits.",
to_additive_relevant_arg 2]
instance hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} Grp.{u} where
has_limits_of_shape J _ := { }
@[to_additive]
instance hasLimits : HasLimits Grp.{u} :=
Grp.hasLimitsOfSize.{u, u}
/-- The forgetful functor from groups to monoids preserves all limits.
This means the underlying monoid of a limit can be computed as a limit in the category of monoids.
-/
@[to_additive AddGrp.forget₂AddMonPreservesLimitsOfSize
"The forgetful functor from additive groups to additive monoids preserves all limits.
This means the underlying additive monoid of a limit can be computed as a limit in the category of
additive monoids.",
to_additive_relevant_arg 2]
noncomputable instance forget₂MonPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ Grp.{u} MonCat.{u}) where
preservesLimitsOfShape {J _} := { }
@[to_additive]
noncomputable instance forget₂MonPreservesLimits :
PreservesLimits (forget₂ Grp.{u} MonCat.{u}) :=
Grp.forget₂MonPreservesLimitsOfSize.{u, u}
/-- If `J` is `u`-small, the forgetful functor from `Grp.{u}` preserves limits of shape `J`. -/
@[to_additive "If `J` is `u`-small, the forgetful functor from `AddGrp.{u}`\n
preserves limits of shape `J`."]
noncomputable instance forgetPreservesLimitsOfShape [Small.{u} J] :
PreservesLimitsOfShape J (forget Grp.{u}) where
preservesLimit {F} := preservesLimitOfPreservesLimitCone (limitConeIsLimit F)
(Types.Small.limitConeIsLimit (F ⋙ forget _))
/-- The forgetful functor from groups 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 groups 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 2]
noncomputable instance forgetPreservesLimitsOfSize :
PreservesLimitsOfSize.{w, v} (forget Grp.{u}) := inferInstance
@[to_additive]
noncomputable instance forgetPreservesLimits : PreservesLimits (forget Grp.{u}) :=
Grp.forgetPreservesLimitsOfSize.{u, u}
end Grp
namespace CommGrp
variable (F : J ⥤ CommGrp.{u})
@[to_additive]
instance commGroupObj (j) : CommGroup ((F ⋙ forget CommGrp).obj j) :=
inferInstanceAs <| CommGroup (F.obj j)
@[to_additive]
noncomputable instance limitCommGroup
[Small.{u} (Functor.sections (F ⋙ forget CommGrp))] :
CommGroup (Types.Small.limitCone.{v, u} (F ⋙ forget CommGrp.{u})).pt :=
letI : CommGroup (F ⋙ forget CommGrp.{u}).sections :=
@Subgroup.toCommGroup (∀ j, F.obj j) _
(Grp.sectionsSubgroup (F ⋙ forget₂ CommGrp.{u} Grp.{u}))
inferInstanceAs <| CommGroup (Shrink (F ⋙ forget CommGrp.{u}).sections)
@[to_additive]
instance : (forget₂ CommGrp.{u} Grp.{u}).ReflectsIsomorphisms :=
reflectsIsomorphisms_forget₂ _ _
/-- We show that the forgetful functor `CommGrp ⥤ Grp` creates limits.
All we need to do is notice that the limit point has a `CommGroup` instance available,
and then reuse the existing limit.
-/
@[to_additive "We show that the forgetful functor `AddCommGrp ⥤ AddGrp` creates limits.
All we need to do is notice that the limit point has an `AddCommGroup` instance available,
and then reuse the existing limit."]
noncomputable instance Forget₂.createsLimit :
CreatesLimit F (forget₂ CommGrp Grp.{u}) :=
createsLimitOfReflectsIso (fun c hc => by
have : HasLimit _ := ⟨_, hc⟩
have : Small.{u} (F ⋙ forget CommGrp).sections :=
Concrete.small_sections_of_hasLimit (F ⋙ forget₂ CommGrp Grp)
have : Small.{u} ((F ⋙ forget₂ CommGrp Grp ⋙ forget₂ Grp MonCat) ⋙
forget MonCat).sections := this
have : Small.{u} ((F ⋙ forget₂ CommGrp Grp) ⋙ forget Grp).sections := this
exact
{ liftedCone :=
{ pt := CommGrp.of (Types.Small.limitCone.{v, u} (F ⋙ forget CommGrp)).pt
π :=
{ app := MonCat.limitπMonoidHom
(F ⋙ forget₂ CommGrp Grp.{u} ⋙ forget₂ Grp MonCat.{u})
naturality := (MonCat.HasLimits.limitCone _).π.naturality } }
validLift := by apply IsLimit.uniqueUpToIso (Grp.limitConeIsLimit _) hc
makesLimit :=
IsLimit.ofFaithful (forget₂ _ Grp.{u} ⋙ forget₂ _ MonCat.{u})
(by apply MonCat.HasLimits.limitConeIsLimit _) (fun s => _) fun s => rfl })
section
variable [Small.{u} (Functor.sections (F ⋙ forget CommGrp))]
/-- A choice of limit cone for a functor into `CommGrp`.
(Generally, you'll just want to use `limit F`.)
-/
@[to_additive
"A choice of limit cone for a functor into `AddCommGrp`.
(Generally, you'll just want to use `limit F`.)"]
noncomputable def limitCone : Cone F :=
letI : Small.{u} (Functor.sections ((F ⋙ forget₂ CommGrp Grp) ⋙ forget Grp)) :=
inferInstanceAs <| Small (Functor.sections (F ⋙ forget CommGrp))
liftLimit (limit.isLimit (F ⋙ forget₂ CommGrp.{u} Grp.{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.{v, u} F) :=
liftedLimitIsLimit _
/-- If `(F ⋙ forget CommGrp).sections` is `u`-small, `F` has a limit. -/
@[to_additive "If `(F ⋙ forget AddCommGrp).sections` is `u`-small, `F` has a limit."]
instance hasLimit : HasLimit F :=
HasLimit.mk {
cone := limitCone F
isLimit := limitConeIsLimit F
}
end
/-- A functor `F : J ⥤ CommGrp.{u}` has a limit iff `(F ⋙ forget CommGrp).sections` is
`u`-small. -/
@[to_additive "A functor `F : J ⥤ AddCommGrp.{u}` has a limit iff
`(F ⋙ forget AddCommGrp).sections` is `u`-small."]
lemma hasLimit_iff_small_sections :
HasLimit F ↔ Small.{u} (F ⋙ forget CommGrp).sections := by
constructor
· apply Concrete.small_sections_of_hasLimit
· intro
infer_instance
/-- If `J` is `u`-small, `CommGrp.{u}` has limits of shape `J`. -/
@[to_additive "If `J` is `u`-small, `AddCommGrp.{u}` has limits of shape `J`."]
instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J CommGrp.{u} where
has_limit _ := inferInstance
/-- The category of commutative groups has all limits. -/
@[to_additive "The category of additive commutative groups has all limits.",
to_additive_relevant_arg 2]
instance hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} CommGrp.{u}
where has_limits_of_shape _ _ := { }
@[to_additive]
instance hasLimits : HasLimits CommGrp.{u} :=
CommGrp.hasLimitsOfSize.{u, u}
@[to_additive]
noncomputable instance forget₂GroupPreservesLimit :
PreservesLimit F (forget₂ CommGrp.{u} Grp.{u}) where
preserves {c} hc := by
have : HasLimit (F ⋙ forget₂ CommGrp Grp) := by
rw [Grp.hasLimit_iff_small_sections]
change Small.{u} (F ⋙ forget CommGrp).sections
rw [← CommGrp.hasLimit_iff_small_sections]
exact ⟨_, hc⟩
exact isLimitOfPreserves _ hc
@[to_additive]
noncomputable instance forget₂GroupPreservesLimitsOfShape :
PreservesLimitsOfShape J (forget₂ CommGrp.{u} Grp.{u}) where
/-- The forgetful functor from commutative groups to groups preserves all limits.
(That is, the underlying group could have been computed instead as limits in the category
of groups.)
-/
@[to_additive
"The forgetful functor from additive commutative groups to additive groups preserves all limits.
(That is, the underlying group could have been computed instead as limits in the category
of additive groups.)",
to_additive_relevant_arg 2]
noncomputable instance forget₂GroupPreservesLimitsOfSize :
PreservesLimitsOfSize.{w, v} (forget₂ CommGrp.{u} Grp.{u}) where
@[to_additive]
noncomputable instance forget₂GroupPreservesLimits :
PreservesLimits (forget₂ CommGrp Grp.{u}) :=
CommGrp.forget₂GroupPreservesLimitsOfSize.{u, u}
/-- An auxiliary declaration to speed up typechecking.
-/
@[to_additive AddCommGrp.forget₂AddCommMonPreservesLimitsAux
"An auxiliary declaration to speed up typechecking."]
noncomputable def forget₂CommMonPreservesLimitsAux
[Small.{u} (F ⋙ forget CommGrp).sections] :
IsLimit ((forget₂ CommGrp.{u} CommMonCat.{u}).mapCone (limitCone.{v, u} F)) :=
letI : Small.{u} (Functor.sections ((F ⋙ forget₂ _ CommMonCat) ⋙ forget CommMonCat)) :=
inferInstanceAs <| Small (Functor.sections (F ⋙ forget CommGrp))
CommMonCat.limitConeIsLimit.{v, u} (F ⋙ forget₂ CommGrp.{u} CommMonCat.{u})
/-- If `J` is `u`-small, the forgetful functor from `CommGrp.{u}` to `CommMonCat.{u}`
preserves limits of shape `J`. -/
@[to_additive AddCommGrp.forget₂AddCommMonPreservesLimitsOfShape
"If `J` is `u`-small, the forgetful functor from `AddCommGrp.{u}`
to `AddCommMonCat.{u}` preserves limits of shape `J`."]
noncomputable instance forget₂CommMonPreservesLimitsOfShape [Small.{u} J] :
PreservesLimitsOfShape J (forget₂ CommGrp.{u} CommMonCat.{u}) where
preservesLimit {F} := preservesLimitOfPreservesLimitCone (limitConeIsLimit.{v, u} F)
(forget₂CommMonPreservesLimitsAux.{v, u} F)
/-- The forgetful functor from commutative groups to commutative monoids preserves all limits.
(That is, the underlying commutative monoids could have been computed instead as limits
in the category of commutative monoids.)
-/
@[to_additive AddCommGrp.forget₂AddCommMonPreservesLimitsOfSize
"The forgetful functor from additive commutative groups to additive commutative monoids
preserves all limits. (That is, the underlying additive commutative monoids could have been
computed instead as limits in the category of additive commutative monoids.)"]
noncomputable instance forget₂CommMonPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ CommGrp CommMonCat.{u}) where
preservesLimitsOfShape := { }
/-- If `J` is `u`-small, the forgetful functor from `CommGrp.{u}` preserves limits of
shape `J`. -/
@[to_additive "If `J` is `u`-small, the forgetful functor from `AddCommGrp.{u}`\n
preserves limits of shape `J`."]
noncomputable instance forgetPreservesLimitsOfShape [Small.{u} J] :
PreservesLimitsOfShape J (forget CommGrp.{u}) where
preservesLimit {F} := preservesLimitOfPreservesLimitCone (limitConeIsLimit F)
(Types.Small.limitConeIsLimit (F ⋙ forget _))
/-- The forgetful functor from commutative groups to types preserves all limits. (That is, the
underlying types could have been computed instead as limits in the category of types.)
-/
@[to_additive
"The forgetful functor from additive commutative groups to types preserves all limits.
(That is, the underlying types could have been computed instead as limits in the category of
types.)"]
noncomputable instance forgetPreservesLimitsOfSize :
PreservesLimitsOfSize.{w, v} (forget CommGrp.{u}) := inferInstance
noncomputable instance _root_.AddCommGrp.forgetPreservesLimits :
PreservesLimits (forget AddCommGrp.{u}) :=
AddCommGrp.forgetPreservesLimitsOfSize.{u, u}
@[to_additive existing]
noncomputable instance forgetPreservesLimits : PreservesLimits (forget CommGrp.{u}) :=
CommGrp.forgetPreservesLimitsOfSize.{u, u}
-- Verify we can form limits indexed over smaller categories.
example (f : ℕ → AddCommGrp) : HasProduct f := by infer_instance
end CommGrp
namespace AddCommGrp
/-- The categorical kernel of a morphism in `AddCommGrp`
agrees with the usual group-theoretical kernel.
-/
def kernelIsoKer {G H : AddCommGrp.{u}} (f : G ⟶ H) :
kernel f ≅ AddCommGrp.of f.ker where
hom :=
{ toFun := fun g => ⟨kernel.ι f g, DFunLike.congr_fun (kernel.condition f) g⟩
map_zero' := by
refine Subtype.ext ?_
simp [(AddSubgroup.coe_zero _).symm]
map_add' := fun g g' => by
refine Subtype.ext ?_
change _ = _ + _
dsimp
simp }
inv := kernel.lift f (AddSubgroup.subtype f.ker) <| by ext x; exact x.2
hom_inv_id := by
-- Porting note (#11041): it would be nice to do the next two steps by a single `ext`,
-- but this will require thinking carefully about the relative priorities of `@[ext]` lemmas.
refine equalizer.hom_ext ?_
ext x
dsimp
apply DFunLike.congr_fun (kernel.lift_ι f _ _)
inv_hom_id := by
apply AddCommGrp.ext
simp only [AddMonoidHom.coe_mk, coe_id, coe_comp]
rintro ⟨x, mem⟩
refine Subtype.ext ?_
simp only [ZeroHom.coe_mk, Function.comp_apply, id_eq]
apply DFunLike.congr_fun (kernel.lift_ι f _ _)
@[simp]
theorem kernelIsoKer_hom_comp_subtype {G H : AddCommGrp.{u}} (f : G ⟶ H) :
(kernelIsoKer f).hom ≫ AddSubgroup.subtype f.ker = kernel.ι f := by ext; rfl
@[simp]
theorem kernelIsoKer_inv_comp_ι {G H : AddCommGrp.{u}} (f : G ⟶ H) :
(kernelIsoKer f).inv ≫ kernel.ι f = AddSubgroup.subtype f.ker := by
ext
simp [kernelIsoKer]
-- Porting note: explicitly add what to be synthesized under `simps!`, because other lemmas
-- automatically generated is not in normal form
/-- The categorical kernel inclusion for `f : G ⟶ H`, as an object over `G`,
agrees with the `AddSubgroup.subtype` map.
-/
@[simps! hom_left_apply_coe inv_left_apply]
def kernelIsoKerOver {G H : AddCommGrp.{u}} (f : G ⟶ H) :
Over.mk (kernel.ι f) ≅ @Over.mk _ _ G (AddCommGrp.of f.ker) (AddSubgroup.subtype f.ker) :=
Over.isoMk (kernelIsoKer f)
-- These lemmas have always been bad (#7657), but lean4#2644 made `simp` start noticing
attribute [nolint simpNF] AddCommGrp.kernelIsoKerOver_inv_left_apply
AddCommGrp.kernelIsoKerOver_hom_left_apply_coe
end AddCommGrp
|
Algebra\Category\Grp\Preadditive.lean
|
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.CategoryTheory.Preadditive.Basic
/-!
# The category of additive commutative groups is preadditive.
-/
open CategoryTheory
universe u
namespace AddCommGrp
-- porting note (#10670): this instance was not necessary in mathlib
instance (P Q : AddCommGrp) : AddCommGroup (P ⟶ Q) :=
(inferInstance : AddCommGroup (AddMonoidHom P Q))
-- porting note (#10688): this lemma was not necessary in mathlib
@[simp]
lemma hom_add_apply {P Q : AddCommGrp} (f g : P ⟶ Q) (x : P) : (f + g) x = f x + g x := rfl
section
-- Porting note: the simp attribute was locally deactivated here,
-- otherwise Lean would try to infer `Preadditive AddCommGrp`
-- in order to prove the axioms `add_comp` and `comp_add` in the
-- next instance declaration
attribute [-simp] Preadditive.add_comp Preadditive.comp_add
instance : Preadditive AddCommGrp where
end
end AddCommGrp
|
Algebra\Category\Grp\Subobject.lean
|
/-
Copyright (c) 2021 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.Algebra.Category.Grp.ZModuleEquivalence
import Mathlib.Algebra.Category.ModuleCat.Subobject
/-!
# The category of abelian groups is well-powered
-/
open CategoryTheory
universe u
namespace AddCommGrp
instance wellPowered_addCommGrp : WellPowered AddCommGrp.{u} :=
wellPowered_of_equiv (forget₂ (ModuleCat.{u} ℤ) AddCommGrp.{u}).asEquivalence
end AddCommGrp
|
Algebra\Category\Grp\Zero.lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.CategoryTheory.Limits.Shapes.ZeroObjects
/-!
# The category of (commutative) (additive) groups has a zero object.
`AddCommGroup` also has zero morphisms. For definitional reasons, we infer this from preadditivity
rather than from the existence of a zero object.
-/
open CategoryTheory
open CategoryTheory.Limits
universe u
namespace Grp
@[to_additive]
theorem isZero_of_subsingleton (G : Grp) [Subsingleton G] : IsZero G := by
refine ⟨fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩⟩
· ext x
have : x = 1 := Subsingleton.elim _ _
rw [this, map_one, map_one]
· ext
subsingleton
@[to_additive AddGrp.hasZeroObject]
instance : HasZeroObject Grp :=
⟨⟨of PUnit, isZero_of_subsingleton _⟩⟩
end Grp
namespace CommGrp
@[to_additive]
theorem isZero_of_subsingleton (G : CommGrp) [Subsingleton G] : IsZero G := by
refine ⟨fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩⟩
· ext x
have : x = 1 := Subsingleton.elim _ _
rw [this, map_one, map_one]
· ext
subsingleton
@[to_additive AddCommGrp.hasZeroObject]
instance : HasZeroObject CommGrp :=
⟨⟨of PUnit, isZero_of_subsingleton _⟩⟩
end CommGrp
|
Algebra\Category\Grp\ZModuleEquivalence.lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Category.ModuleCat.Basic
/-!
The forgetful functor from ℤ-modules to additive commutative groups is
an equivalence of categories.
TODO:
either use this equivalence to transport the monoidal structure from `Module ℤ` to `Ab`,
or, having constructed that monoidal structure directly, show this functor is monoidal.
-/
open CategoryTheory
open CategoryTheory.Equivalence
universe u
namespace ModuleCat
/-- The forgetful functor from `ℤ` modules to `AddCommGrp` is full. -/
instance forget₂_addCommGroup_full : (forget₂ (ModuleCat ℤ) AddCommGrp.{u}).Full where
map_surjective {A B}
-- `AddMonoidHom.toIntLinearMap` doesn't work here because `A` and `B` are not
-- definitionally equal to the canonical `AddCommGroup.toIntModule` module
-- instances it expects.
f := ⟨@LinearMap.mk _ _ _ _ _ _ _ _ _ A.isModule B.isModule
{ toFun := f,
map_add' := AddMonoidHom.map_add (show A.carrier →+ B.carrier from f) }
(fun n x => by
convert AddMonoidHom.map_zsmul (show A.carrier →+ B.carrier from f) x n <;>
ext <;> apply int_smul_eq_zsmul), rfl⟩
/-- The forgetful functor from `ℤ` modules to `AddCommGrp` is essentially surjective. -/
instance forget₂_addCommGrp_essSurj : (forget₂ (ModuleCat ℤ) AddCommGrp.{u}).EssSurj where
mem_essImage A :=
⟨ModuleCat.of ℤ A,
⟨{ hom := 𝟙 A
inv := 𝟙 A }⟩⟩
noncomputable instance forget₂AddCommGroupIsEquivalence :
(forget₂ (ModuleCat ℤ) AddCommGrp.{u}).IsEquivalence where
end ModuleCat
|
Algebra\Category\HopfAlgebraCat\Basic.lean
|
/-
Copyright (c) 2024 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import Mathlib.Algebra.Category.BialgebraCat.Basic
import Mathlib.RingTheory.HopfAlgebra
/-!
# The category of Hopf algebras over a commutative ring
We introduce the bundled category `HopfAlgebraCat` of Hopf algebras over a fixed commutative ring
`R` along with the forgetful functor to `BialgebraCat`.
This file mimics `Mathlib.LinearAlgebra.QuadraticForm.QuadraticModuleCat`.
-/
open CategoryTheory
universe v u
variable (R : Type u) [CommRing R]
/-- The category of `R`-Hopf algebras. -/
structure HopfAlgebraCat extends Bundled Ring.{v} where
[instHopfAlgebra : HopfAlgebra R α]
attribute [instance] HopfAlgebraCat.instHopfAlgebra
variable {R}
namespace HopfAlgebraCat
open HopfAlgebra
instance : CoeSort (HopfAlgebraCat.{v} R) (Type v) :=
⟨(·.α)⟩
variable (R)
/-- The object in the category of `R`-Hopf algebras associated to an `R`-Hopf algebra. -/
@[simps]
def of (X : Type v) [Ring X] [HopfAlgebra R X] :
HopfAlgebraCat R where
instHopfAlgebra := (inferInstance : HopfAlgebra R X)
variable {R}
@[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 : HopfAlgebraCat.{v} R) :=
/-- The underlying `BialgHom`. -/
toBialgHom : V →ₐc[R] W
lemma Hom.toBialgHom_injective (V W : HopfAlgebraCat.{v} R) :
Function.Injective (Hom.toBialgHom : Hom V W → _) :=
fun ⟨f⟩ ⟨g⟩ _ => by congr
instance category : Category (HopfAlgebraCat.{v} R) where
Hom X Y := Hom X Y
id X := ⟨BialgHom.id R X⟩
comp f g := ⟨BialgHom.comp g.toBialgHom f.toBialgHom⟩
-- TODO: if `Quiver.Hom` and the instance above were `reducible`, this wouldn't be needed.
@[ext]
lemma hom_ext {X Y : HopfAlgebraCat.{v} R} (f g : X ⟶ Y) (h : f.toBialgHom = g.toBialgHom) :
f = g :=
Hom.ext h
/-- Typecheck a `BialgHom` as a morphism in `HopfAlgebraCat 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 :=
⟨f⟩
@[simp] theorem toBialgHom_comp {X Y Z : HopfAlgebraCat.{v} R} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).toBialgHom = g.toBialgHom.comp f.toBialgHom :=
rfl
@[simp] theorem toBialgHom_id {M : HopfAlgebraCat.{v} R} :
Hom.toBialgHom (𝟙 M) = BialgHom.id _ _ :=
rfl
instance concreteCategory : ConcreteCategory.{v} (HopfAlgebraCat.{v} R) where
forget :=
{ obj := fun M => M
map := fun f => f.toBialgHom }
forget_faithful :=
{ map_injective := fun {M N} => DFunLike.coe_injective.comp <| Hom.toBialgHom_injective _ _ }
instance hasForgetToBialgebra : HasForget₂ (HopfAlgebraCat R) (BialgebraCat R) where
forget₂ :=
{ obj := fun X => BialgebraCat.of R X
map := fun {X Y} f => BialgebraCat.ofHom f.toBialgHom }
@[simp]
theorem forget₂_bialgebra_obj (X : HopfAlgebraCat R) :
(forget₂ (HopfAlgebraCat R) (BialgebraCat R)).obj X = BialgebraCat.of R X :=
rfl
@[simp]
theorem forget₂_bialgebra_map (X Y : HopfAlgebraCat R) (f : X ⟶ Y) :
(forget₂ (HopfAlgebraCat R) (BialgebraCat R)).map f = BialgebraCat.ofHom f.toBialgHom :=
rfl
end HopfAlgebraCat
namespace BialgEquiv
open HopfAlgebraCat
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 `HopfAlgebraCat R` from a
`BialgEquiv`. -/
@[simps]
def toHopfAlgebraCatIso (e : X ≃ₐc[R] Y) : HopfAlgebraCat.of R X ≅ HopfAlgebraCat.of R Y where
hom := HopfAlgebraCat.ofHom e
inv := HopfAlgebraCat.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 toHopfAlgebraCatIso_refl :
toHopfAlgebraCatIso (BialgEquiv.refl R X) = .refl _ :=
rfl
@[simp] theorem toHopfAlgebraCatIso_symm (e : X ≃ₐc[R] Y) :
toHopfAlgebraCatIso e.symm = (toHopfAlgebraCatIso e).symm :=
rfl
@[simp] theorem toHopfAlgebraCatIso_trans (e : X ≃ₐc[R] Y) (f : Y ≃ₐc[R] Z) :
toHopfAlgebraCatIso (e.trans f) = toHopfAlgebraCatIso e ≪≫ toHopfAlgebraCatIso f :=
rfl
end BialgEquiv
namespace CategoryTheory.Iso
open HopfAlgebra
variable {X Y Z : HopfAlgebraCat.{v} R}
/-- Build a `BialgEquiv` from an isomorphism in the category
`HopfAlgebraCat 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 HopfAlgebraCat.Hom.toBialgHom i.3) x
right_inv := fun x => BialgHom.congr_fun (congr_arg HopfAlgebraCat.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 HopfAlgebraCat.forget_reflects_isos :
(forget (HopfAlgebraCat.{v} R)).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget (HopfAlgebraCat.{v} R)).map f)
let e : X ≃ₐc[R] Y := { f.toBialgHom, i.toEquiv with }
exact ⟨e.toHopfAlgebraCatIso.isIso_hom.1⟩
|
Algebra\Category\ModuleCat\Abelian.lean
|
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.LinearAlgebra.Isomorphisms
import Mathlib.Algebra.Category.ModuleCat.Kernels
import Mathlib.Algebra.Category.ModuleCat.Limits
import Mathlib.CategoryTheory.Abelian.Basic
/-!
# The category of left R-modules is abelian.
Additionally, two linear maps are exact in the categorical sense iff `range f = ker g`.
-/
open CategoryTheory
open CategoryTheory.Limits
noncomputable section
universe w v u
namespace ModuleCat
variable {R : Type u} [Ring R] {M N : ModuleCat.{v} R} (f : M ⟶ N)
/-- In the category of modules, every monomorphism is normal. -/
def normalMono (hf : Mono f) : NormalMono f where
Z := of R (N ⧸ LinearMap.range f)
g := f.range.mkQ
w := LinearMap.range_mkQ_comp _
isLimit :=
/- The following [invalid Lean code](https://github.com/leanprover-community/lean/issues/341)
might help you understand what's going on here:
```
calc
M ≃ₗ[R] f.ker.quotient : (Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm
... ≃ₗ[R] f.range : LinearMap.quotKerEquivRange f
... ≃ₗ[R] r.range.mkq.ker : LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm
```
-/
IsKernel.isoKernel _ _ (kernelIsLimit _)
(LinearEquiv.toModuleIso'
((Submodule.quotEquivOfEqBot _ (ker_eq_bot_of_mono _)).symm ≪≫ₗ
(LinearMap.quotKerEquivRange f ≪≫ₗ
LinearEquiv.ofEq _ _ (Submodule.ker_mkQ _).symm))) <| by ext; rfl
/-- In the category of modules, every epimorphism is normal. -/
def normalEpi (hf : Epi f) : NormalEpi f where
W := of R (LinearMap.ker f)
g := (LinearMap.ker f).subtype
w := LinearMap.comp_ker_subtype _
isColimit :=
/- The following invalid Lean code might help you understand what's going on here:
```
calc f.ker.subtype.range.quotient
≃ₗ[R] f.ker.quotient : Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _)
... ≃ₗ[R] f.range : LinearMap.quotKerEquivRange f
... ≃ₗ[R] N : LinearEquiv.ofTop _ (range_eq_top_of_epi _)
```
-/
IsCokernel.cokernelIso _ _ (cokernelIsColimit _)
(LinearEquiv.toModuleIso'
(Submodule.quotEquivOfEq _ _ (Submodule.range_subtype _) ≪≫ₗ
LinearMap.quotKerEquivRange f ≪≫ₗ
LinearEquiv.ofTop _ (range_eq_top_of_epi _))) <| by ext; rfl
/-- The category of R-modules is abelian. -/
instance abelian : Abelian (ModuleCat.{v} R) where
has_cokernels := hasCokernels_moduleCat
normalMonoOfMono := normalMono
normalEpiOfEpi := normalEpi
section ReflectsLimits
-- Porting note: added to make the following definitions work
instance : HasLimitsOfSize.{v,v} (ModuleCatMax.{v, w} R) :=
ModuleCat.hasLimitsOfSize.{v, v, max v w}
/- We need to put this in this weird spot because we need to know that the category of modules
is balanced. -/
instance forgetReflectsLimitsOfSize :
ReflectsLimitsOfSize.{v, v} (forget (ModuleCatMax.{v, w} R)) :=
reflectsLimitsOfReflectsIsomorphisms
instance forget₂ReflectsLimitsOfSize :
ReflectsLimitsOfSize.{v, v} (forget₂ (ModuleCatMax.{v, w} R) AddCommGrp.{max v w}) :=
reflectsLimitsOfReflectsIsomorphisms
instance forgetReflectsLimits : ReflectsLimits (forget (ModuleCat.{v} R)) :=
ModuleCat.forgetReflectsLimitsOfSize.{v, v}
instance forget₂ReflectsLimits : ReflectsLimits (forget₂ (ModuleCat.{v} R) AddCommGrp.{v}) :=
ModuleCat.forget₂ReflectsLimitsOfSize.{v, v}
end ReflectsLimits
end ModuleCat
|
Algebra\Category\ModuleCat\Adjunctions.lean
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johan Commelin
-/
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic
import Mathlib.CategoryTheory.Monoidal.Functorial
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.
-/
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`.
-/
@[simps]
def free : Type u ⥤ ModuleCat R where
obj X := ModuleCat.of R (X →₀ R)
map {X Y} f := Finsupp.lmapDomain _ _ f
map_id := by intros; exact Finsupp.lmapDomain_id _ _
map_comp := by intros; exact Finsupp.lmapDomain_comp _ _ _ _
/-- The free-forgetful adjunction for R-modules.
-/
def adj : free R ⊣ forget (ModuleCat.{u} R) :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X M => (Finsupp.lift M R X).toEquiv.symm
homEquiv_naturality_left_symm := fun {_ _} M f g =>
Finsupp.lhom_ext' fun x =>
LinearMap.ext_ring
(Finsupp.sum_mapDomain_index_addMonoidHom fun y => (smulAddHom R M).flip (g y)).symm }
instance : (forget (ModuleCat.{u} R)).IsRightAdjoint :=
(adj R).isRightAdjoint
end
namespace Free
open MonoidalCategory
variable [CommRing R]
attribute [local ext] TensorProduct.ext
/-- (Implementation detail) The unitor for `Free R`. -/
def ε : 𝟙_ (ModuleCat.{u} R) ⟶ (free R).obj (𝟙_ (Type u)) :=
Finsupp.lsingle PUnit.unit
-- This lemma has always been bad, but lean4#2644 made `simp` start noticing
@[simp, nolint simpNF]
theorem ε_apply (r : R) : ε R r = Finsupp.single PUnit.unit r :=
rfl
/-- (Implementation detail) The tensorator for `Free R`. -/
def μ (α β : Type u) : (free R).obj α ⊗ (free R).obj β ≅ (free R).obj (α ⊗ β) :=
(finsuppTensorFinsupp' R α β).toModuleIso
theorem μ_natural {X Y X' Y' : Type u} (f : X ⟶ Y) (g : X' ⟶ Y') :
((free R).map f ⊗ (free R).map g) ≫ (μ R Y Y').hom = (μ R X X').hom ≫ (free R).map (f ⊗ g) := by
-- Porting note (#11041): broken ext
apply TensorProduct.ext
apply Finsupp.lhom_ext'
intro x
apply LinearMap.ext_ring
apply Finsupp.lhom_ext'
intro x'
apply LinearMap.ext_ring
apply Finsupp.ext
intro ⟨y, y'⟩
-- Porting note (#10934): used to be dsimp [μ]
change (finsuppTensorFinsupp' R Y Y')
(Finsupp.mapDomain f (Finsupp.single x 1) ⊗ₜ[R] Finsupp.mapDomain g (Finsupp.single x' 1)) _
= (Finsupp.mapDomain (f ⊗ g) (finsuppTensorFinsupp' R X X'
(Finsupp.single x 1 ⊗ₜ[R] Finsupp.single x' 1))) _
-- extra `rfl` after leanprover/lean4#2466
simp_rw [Finsupp.mapDomain_single, finsuppTensorFinsupp'_single_tmul_single, mul_one,
Finsupp.mapDomain_single, CategoryTheory.tensor_apply]; rfl
theorem left_unitality (X : Type u) :
(λ_ ((free R).obj X)).hom =
(ε R ⊗ 𝟙 ((free R).obj X)) ≫ (μ R (𝟙_ (Type u)) X).hom ≫ map (free R).obj (λ_ X).hom := by
-- Porting note (#11041): broken ext
apply TensorProduct.ext
apply LinearMap.ext_ring
apply Finsupp.lhom_ext'
intro x
apply LinearMap.ext_ring
apply Finsupp.ext
intro x'
-- Porting note (#10934): used to be dsimp [ε, μ]
let q : X →₀ R := ((λ_ (of R (X →₀ R))).hom) (1 ⊗ₜ[R] Finsupp.single x 1)
change q x' = Finsupp.mapDomain (λ_ X).hom (finsuppTensorFinsupp' R (𝟙_ (Type u)) X
(Finsupp.single PUnit.unit 1 ⊗ₜ[R] Finsupp.single x 1)) x'
simp_rw [q, finsuppTensorFinsupp'_single_tmul_single,
ModuleCat.MonoidalCategory.leftUnitor_hom_apply, mul_one,
Finsupp.mapDomain_single, CategoryTheory.leftUnitor_hom_apply, one_smul]
theorem right_unitality (X : Type u) :
(ρ_ ((free R).obj X)).hom =
(𝟙 ((free R).obj X) ⊗ ε R) ≫ (μ R X (𝟙_ (Type u))).hom ≫ map (free R).obj (ρ_ X).hom := by
-- Porting note (#11041): broken ext
apply TensorProduct.ext
apply Finsupp.lhom_ext'
intro x
apply LinearMap.ext_ring
apply LinearMap.ext_ring
apply Finsupp.ext
intro x'
-- Porting note (#10934): used to be dsimp [ε, μ]
let q : X →₀ R := ((ρ_ (of R (X →₀ R))).hom) (Finsupp.single x 1 ⊗ₜ[R] 1)
change q x' = Finsupp.mapDomain (ρ_ X).hom (finsuppTensorFinsupp' R X (𝟙_ (Type u))
(Finsupp.single x 1 ⊗ₜ[R] Finsupp.single PUnit.unit 1)) x'
simp_rw [q, finsuppTensorFinsupp'_single_tmul_single,
ModuleCat.MonoidalCategory.rightUnitor_hom_apply, mul_one,
Finsupp.mapDomain_single, CategoryTheory.rightUnitor_hom_apply, one_smul]
theorem associativity (X Y Z : Type u) :
((μ R X Y).hom ⊗ 𝟙 ((free R).obj Z)) ≫ (μ R (X ⊗ Y) Z).hom ≫ map (free R).obj (α_ X Y Z).hom =
(α_ ((free R).obj X) ((free R).obj Y) ((free R).obj Z)).hom ≫
(𝟙 ((free R).obj X) ⊗ (μ R Y Z).hom) ≫ (μ R X (Y ⊗ Z)).hom := by
-- Porting note (#11041): broken ext
apply TensorProduct.ext
apply TensorProduct.ext
apply Finsupp.lhom_ext'
intro x
apply LinearMap.ext_ring
apply Finsupp.lhom_ext'
intro y
apply LinearMap.ext_ring
apply Finsupp.lhom_ext'
intro z
apply LinearMap.ext_ring
apply Finsupp.ext
intro a
-- Porting note (#10934): used to be dsimp [μ]
change Finsupp.mapDomain (α_ X Y Z).hom (finsuppTensorFinsupp' R (X ⊗ Y) Z
(finsuppTensorFinsupp' R X Y
(Finsupp.single x 1 ⊗ₜ[R] Finsupp.single y 1) ⊗ₜ[R] Finsupp.single z 1)) a =
finsuppTensorFinsupp' R X (Y ⊗ Z)
(Finsupp.single x 1 ⊗ₜ[R]
finsuppTensorFinsupp' R Y Z (Finsupp.single y 1 ⊗ₜ[R] Finsupp.single z 1)) a
-- extra `rfl` after leanprover/lean4#2466
simp_rw [finsuppTensorFinsupp'_single_tmul_single, Finsupp.mapDomain_single, mul_one,
CategoryTheory.associator_hom_apply]; rfl
-- In fact, it's strong monoidal, but we don't yet have a typeclass for that.
/-- The free R-module functor is lax monoidal. -/
@[simps]
instance : LaxMonoidal.{u} (free R).obj := .ofTensorHom
-- Send `R` to `PUnit →₀ R`
(ε := ε R)
-- Send `(α →₀ R) ⊗ (β →₀ R)` to `α × β →₀ R`
(μ := fun X Y => (μ R X Y).hom)
(μ_natural := fun {_} {_} {_} {_} f g ↦ μ_natural R f g)
(left_unitality := left_unitality R)
(right_unitality := right_unitality R)
(associativity := associativity R)
instance : IsIso (@LaxMonoidal.ε _ _ _ _ _ _ (free R).obj _ _) := by
refine ⟨⟨Finsupp.lapply PUnit.unit, ⟨?_, ?_⟩⟩⟩
· -- Porting note (#11041): broken ext
apply LinearMap.ext_ring
-- Porting note (#10959): simp used to be able to close this goal
dsimp
erw [ModuleCat.comp_def, LinearMap.comp_apply, ε_apply, Finsupp.lapply_apply,
Finsupp.single_eq_same, id_apply]
· -- Porting note (#11041): broken ext
apply Finsupp.lhom_ext'
intro ⟨⟩
apply LinearMap.ext_ring
apply Finsupp.ext
intro ⟨⟩
-- Porting note (#10959): simp used to be able to close this goal
dsimp
erw [ModuleCat.comp_def, LinearMap.comp_apply, ε_apply, Finsupp.lapply_apply,
Finsupp.single_eq_same]
end Free
open MonoidalCategory
variable [CommRing R]
/-- The free functor `Type u ⥤ ModuleCat R`, as a monoidal functor. -/
def monoidalFree : MonoidalFunctor (Type u) (ModuleCat.{u} R) :=
{ LaxMonoidalFunctor.of (free R).obj with
-- Porting note (#10934): used to be dsimp
ε_isIso := (by infer_instance : IsIso (@LaxMonoidal.ε _ _ _ _ _ _ (free R).obj _ _))
μ_isIso := fun X Y => by dsimp; infer_instance }
example (X Y : Type u) : (free R).obj (X × Y) ≅ (free R).obj X ⊗ (free R).obj Y :=
((monoidalFree R).μIso X Y).symm
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`.
-/
-- Porting note(#5171): Removed has_nonempty_instance nolint; linter not ported yet
@[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 Y 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
dsimp
-- This imitates the proof of associativity for `MonoidAlgebra`.
simp only [sum_sum_index, sum_single_index, single_zero, single_add, eq_self_iff_true,
forall_true_iff, forall₃_true_iff, add_mul, mul_add, Category.assoc, mul_assoc,
zero_mul, mul_zero, sum_zero, sum_add]
namespace Free
section
-- Porting note: removed local reducible attribute for categoryFree, adjusted dsimp invocations
-- accordingly
instance : Preadditive (Free R C) where
homGroup X Y := 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 X Y := 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 [Finsupp.smul_sum, 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 {X Y} f := Finsupp.single f 1
map_id X := rfl
map_comp {X Y Z} f g := by
-- Porting note (#10959): simp used to be able to close this goal
dsimp only []
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 {X Y} 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
apply Finsupp.induction_linear f
· -- Porting note (#10959): simp used to be able to close this goal
dsimp
rw [Limits.zero_comp, sum_zero_index, Limits.zero_comp]
· intro f₁ f₂ w₁ w₂
rw [add_comp]
dsimp at *
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]
· intro f' r
apply Finsupp.induction_linear g
· -- Porting note (#10959): simp used to be able to close this goal
dsimp
rw [Limits.comp_zero, sum_zero_index, Limits.comp_zero]
· intro f₁ f₂ w₁ w₂
rw [comp_add]
dsimp at *
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]
· intro 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 X => Iso.refl _
/-- Two `R`-linear functors out of the `R`-linear completion are isomorphic iff their
compositions with the embedding functor are isomorphic.
-/
-- Porting note: used to be @[ext]
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
apply Finsupp.induction_linear f
· -- Porting note (#10959): simp used to be able to close this goal
rw [Functor.map_zero, Limits.zero_comp, Functor.map_zero, Limits.comp_zero]
· intro f₁ f₂ w₁ w₂
-- Porting note: Using rw instead of simp
rw [Functor.map_add, add_comp, w₁, w₂, Functor.map_add, comp_add]
· intro 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
|
Algebra\Category\ModuleCat\Algebra.lean
|
/-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
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) := LinearMap.module
-- Porting note: used to be `by infer_instance` instead of `LinearMap.module`
instance linearOverField : Linear k (ModuleCat.{v} A) where
-- Porting note: used to be `by infer_instance` instead of `LinearMap.module`
homModule M N := LinearMap.module
smul_comp := by
-- Porting note: this was automatic by `aesop_cat`
intros
ext
dsimp only [coe_comp, Function.comp_apply]
rw [LinearMap.smul_apply, LinearMap.map_smul_of_tower]
rfl
end ModuleCat
|
Algebra\Category\ModuleCat\Basic.lean
|
/-
Copyright (c) 2019 Robert A. Spencer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert A. Spencer, Markus Himmel
-/
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.Algebra.Module.Equiv.Basic
import Mathlib.Algebra.PUnitInstances.Module
import Mathlib.CategoryTheory.Conj
import Mathlib.CategoryTheory.Linear.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
/-!
# The category of `R`-modules
`ModuleCat.{v} R` is the category of bundled `R`-modules with carrier in the universe `v`. We show
that it is preadditive and show that being an isomorphism, monomorphism and epimorphism is
equivalent to being a linear equivalence, an injective linear map and a surjective linear map,
respectively.
## Implementation details
To construct an object in the category of `R`-modules from a type `M` with an instance of the
`Module` typeclass, write `of R M`. There is a coercion in the other direction.
Similarly, there is a coercion from morphisms in `Module R` to linear maps.
Porting note: the next two paragraphs should be revised.
Unfortunately, Lean is not smart enough to see that, given an object `M : ModuleCat R`,
the expression `of R M`, where we coerce `M` to the carrier type,
is definitionally equal to `M` itself.
This means that to go the other direction, i.e., from linear maps/equivalences to (iso)morphisms
in the category of `R`-modules, we have to take care not to inadvertently end up with an
`of R M` where `M` is already an object. Hence, given `f : M →ₗ[R] N`,
* if `M N : ModuleCat R`, simply use `f`;
* if `M : ModuleCat R` and `N` is an unbundled `R`-module, use `↿f` or `asHomLeft f`;
* if `M` is an unbundled `R`-module and `N : ModuleCat R`, use `↾f` or `asHomRight f`;
* if `M` and `N` are unbundled `R`-modules, use `↟f` or `asHom f`.
Similarly, given `f : M ≃ₗ[R] N`, use `toModuleIso`, `toModuleIso'Left`, `toModuleIso'Right`
or `toModuleIso'`, respectively.
The arrow notations are localized, so you may have to `open ModuleCat` (or `open scoped ModuleCat`)
to use them. Note that the notation for `asHomLeft` clashes with the notation used to promote
functions between types to morphisms in the category `Type`, so to avoid confusion, it is probably a
good idea to avoid having the locales `ModuleCat` and `CategoryTheory.Type` open at the same time.
If you get an error when trying to apply a theorem and the `convert` tactic produces goals of the
form `M = of R M`, then you probably used an incorrect variant of `asHom` or `toModuleIso`.
-/
open CategoryTheory
open CategoryTheory.Limits
open CategoryTheory.Limits.WalkingParallelPair
universe v u
variable (R : Type u) [Ring R]
/-- The category of R-modules and their morphisms.
Note that in the case of `R = ℤ`, we can not
impose here that the `ℤ`-multiplication field from the module structure is defeq to the one coming
from the `isAddCommGroup` structure (contrary to what we do for all module structures in
mathlib), which creates some difficulties down the road. -/
structure ModuleCat where
/-- the underlying type of an object in `ModuleCat R` -/
carrier : Type v
[isAddCommGroup : AddCommGroup carrier]
[isModule : Module R carrier]
attribute [instance] ModuleCat.isAddCommGroup ModuleCat.isModule
/-- An alias for `ModuleCat.{max u₁ u₂}`, to deal around unification issues.
Since the universe the ring lives in can be inferred, we put that last. -/
@[nolint checkUnivs]
abbrev ModuleCatMax.{v₁, v₂, u₁} (R : Type u₁) [Ring R] := ModuleCat.{max v₁ v₂, u₁} R
namespace ModuleCat
instance : CoeSort (ModuleCat.{v} R) (Type v) :=
⟨ModuleCat.carrier⟩
attribute [coe] ModuleCat.carrier
instance moduleCategory : Category.{v, max (v+1) u} (ModuleCat.{v} R) where
Hom M N := M →ₗ[R] N
id _ := LinearMap.id
comp f g := g.comp f
id_comp _ := LinearMap.id_comp _
comp_id _ := LinearMap.comp_id _
assoc f g h := LinearMap.comp_assoc (f := f) (g := g) (h := h)
instance {M N : ModuleCat.{v} R} : FunLike (M ⟶ N) M N :=
LinearMap.instFunLike
instance {M N : ModuleCat.{v} R} : LinearMapClass (M ⟶ N) R M N :=
LinearMap.semilinearMapClass
instance moduleConcreteCategory : ConcreteCategory.{v} (ModuleCat.{v} R) where
forget :=
{ obj := fun R => R
map := fun f => f.toFun }
forget_faithful := ⟨fun h => LinearMap.ext (fun x => by
dsimp at h
rw [h])⟩
-- Porting note:
-- One might hope these two instances would not be needed,
-- as we already have `AddCommGroup M` and `Module R M`,
-- but sometimes we seem to need these when rewriting by lemmas about generic concrete categories.
instance {M : ModuleCat.{v} R} : AddCommGroup ((forget (ModuleCat R)).obj M) :=
(inferInstance : AddCommGroup M)
instance {M : ModuleCat.{v} R} : Module R ((forget (ModuleCat R)).obj M) :=
(inferInstance : Module R M)
@[ext]
lemma ext {M N : ModuleCat.{v} R} {f₁ f₂ : M ⟶ N} (h : ∀ (x : M), f₁ x = f₂ x) : f₁ = f₂ :=
DFunLike.ext _ _ h
instance hasForgetToAddCommGroup : HasForget₂ (ModuleCat R) AddCommGrp where
forget₂ :=
{ obj := fun M => AddCommGrp.of M
map := fun f => AddCommGrp.ofHom f.toAddMonoidHom }
/-- The object in the category of R-modules associated to an R-module -/
def of (X : Type v) [AddCommGroup X] [Module R X] : ModuleCat R :=
⟨X⟩
@[simp]
theorem forget₂_obj (X : ModuleCat R) :
(forget₂ (ModuleCat R) AddCommGrp).obj X = AddCommGrp.of X :=
rfl
-- Porting note: the simpNF linter correctly doesn't like this.
-- I'm not sure what this is for, actually.
-- If it is really needed, better might be a simp lemma that says
-- `AddCommGrp.of (ModuleCat.of R X) = AddCommGrp.of X`.
-- @[simp 900]
theorem forget₂_obj_moduleCat_of (X : Type v) [AddCommGroup X] [Module R X] :
(forget₂ (ModuleCat R) AddCommGrp).obj (of R X) = AddCommGrp.of X :=
rfl
@[simp]
theorem forget₂_map (X Y : ModuleCat R) (f : X ⟶ Y) :
(forget₂ (ModuleCat R) AddCommGrp).map f = LinearMap.toAddMonoidHom f :=
rfl
-- Porting note (#11215): TODO: `ofHom` and `asHom` are duplicates!
/-- Typecheck a `LinearMap` as a morphism in `Module R`. -/
def ofHom {R : Type u} [Ring R] {X Y : Type v} [AddCommGroup X] [Module R X] [AddCommGroup Y]
[Module R Y] (f : X →ₗ[R] Y) : of R X ⟶ of R Y :=
f
@[simp 1100]
theorem ofHom_apply {R : Type u} [Ring R] {X Y : Type v} [AddCommGroup X] [Module R X]
[AddCommGroup Y] [Module R Y] (f : X →ₗ[R] Y) (x : X) : ofHom f x = f x :=
rfl
instance : Inhabited (ModuleCat R) :=
⟨of R PUnit⟩
instance ofUnique {X : Type v} [AddCommGroup X] [Module R X] [i : Unique X] : Unique (of R X) :=
i
@[simp] theorem of_coe (X : ModuleCat R) : of R X = X := rfl
-- Porting note: the simpNF linter complains, but we really need this?!
-- @[simp, nolint simpNF]
theorem coe_of (X : Type v) [AddCommGroup X] [Module R X] : (of R X : Type v) = X :=
rfl
variable {R}
/-- Forgetting to the underlying type and then building the bundled object returns the original
module. -/
@[simps]
def ofSelfIso (M : ModuleCat R) : ModuleCat.of R M ≅ M where
hom := 𝟙 M
inv := 𝟙 M
theorem isZero_of_subsingleton (M : ModuleCat R) [Subsingleton M] : IsZero M where
unique_to X := ⟨⟨⟨(0 : M →ₗ[R] X)⟩, fun f => by
ext x
rw [Subsingleton.elim x (0 : M)]
dsimp
simp⟩⟩
unique_from X := ⟨⟨⟨(0 : X →ₗ[R] M)⟩, fun f => by
ext x
subsingleton⟩⟩
instance : HasZeroObject (ModuleCat.{v} R) :=
⟨⟨of R PUnit, isZero_of_subsingleton _⟩⟩
variable {M N U : ModuleCat.{v} R}
@[simp]
theorem id_apply (m : M) : (𝟙 M : M → M) m = m :=
rfl
@[simp]
theorem coe_comp (f : M ⟶ N) (g : N ⟶ U) : (f ≫ g : M → U) = g ∘ f :=
rfl
theorem comp_def (f : M ⟶ N) (g : N ⟶ U) : f ≫ g = g.comp f :=
rfl
@[simp] lemma forget_map (f : M ⟶ N) : (forget (ModuleCat R)).map f = (f : M → N) := rfl
end ModuleCat
variable {R}
variable {X₁ X₂ : Type v}
/-- Reinterpreting a linear map in the category of `R`-modules. -/
def ModuleCat.asHom [AddCommGroup X₁] [Module R X₁] [AddCommGroup X₂] [Module R X₂] :
(X₁ →ₗ[R] X₂) → (ModuleCat.of R X₁ ⟶ ModuleCat.of R X₂) :=
id
/-- Reinterpreting a linear map in the category of `R`-modules -/
scoped[ModuleCat] notation "↟" f:1024 => ModuleCat.asHom f
/-- Reinterpreting a linear map in the category of `R`-modules. -/
def ModuleCat.asHomRight [AddCommGroup X₁] [Module R X₁] {X₂ : ModuleCat.{v} R} :
(X₁ →ₗ[R] X₂) → (ModuleCat.of R X₁ ⟶ X₂) :=
id
/-- Reinterpreting a linear map in the category of `R`-modules. -/
scoped[ModuleCat] notation "↾" f:1024 => ModuleCat.asHomRight f
/-- Reinterpreting a linear map in the category of `R`-modules. -/
def ModuleCat.asHomLeft {X₁ : ModuleCat.{v} R} [AddCommGroup X₂] [Module R X₂] :
(X₁ →ₗ[R] X₂) → (X₁ ⟶ ModuleCat.of R X₂) :=
id
/-- Reinterpreting a linear map in the category of `R`-modules. -/
scoped[ModuleCat] notation "↿" f:1024 => ModuleCat.asHomLeft f
section
/-- Build an isomorphism in the category `Module R` from a `LinearEquiv` between `Module`s. -/
@[simps]
def LinearEquiv.toModuleIso {g₁ : AddCommGroup X₁} {g₂ : AddCommGroup X₂} {m₁ : Module R X₁}
{m₂ : Module R X₂} (e : X₁ ≃ₗ[R] X₂) : ModuleCat.of R X₁ ≅ ModuleCat.of R X₂ where
hom := (e : X₁ →ₗ[R] X₂)
inv := (e.symm : X₂ →ₗ[R] X₁)
hom_inv_id := by ext; apply e.left_inv
inv_hom_id := by ext; apply e.right_inv
/-- Build an isomorphism in the category `Module R` from a `LinearEquiv` between `Module`s. -/
abbrev LinearEquiv.toModuleIso' {M N : ModuleCat.{v} R} (i : M ≃ₗ[R] N) : M ≅ N :=
i.toModuleIso
/-- Build an isomorphism in the category `ModuleCat R` from a `LinearEquiv` between `Module`s. -/
abbrev LinearEquiv.toModuleIso'Left {X₁ : ModuleCat.{v} R} [AddCommGroup X₂] [Module R X₂]
(e : X₁ ≃ₗ[R] X₂) : X₁ ≅ ModuleCat.of R X₂ :=
e.toModuleIso
/-- Build an isomorphism in the category `ModuleCat R` from a `LinearEquiv` between `Module`s. -/
abbrev LinearEquiv.toModuleIso'Right [AddCommGroup X₁] [Module R X₁] {X₂ : ModuleCat.{v} R}
(e : X₁ ≃ₗ[R] X₂) : ModuleCat.of R X₁ ≅ X₂ :=
e.toModuleIso
namespace CategoryTheory.Iso
/-- Build a `LinearEquiv` from an isomorphism in the category `ModuleCat R`. -/
def toLinearEquiv {X Y : ModuleCat R} (i : X ≅ Y) : X ≃ₗ[R] Y :=
LinearEquiv.ofLinear i.hom i.inv i.inv_hom_id i.hom_inv_id
end CategoryTheory.Iso
/-- linear equivalences between `Module`s are the same as (isomorphic to) isomorphisms
in `ModuleCat` -/
@[simps]
def linearEquivIsoModuleIso {X Y : Type u} [AddCommGroup X] [AddCommGroup Y] [Module R X]
[Module R Y] : (X ≃ₗ[R] Y) ≅ ModuleCat.of R X ≅ ModuleCat.of R Y where
hom e := e.toModuleIso
inv i := i.toLinearEquiv
end
namespace ModuleCat
instance {M N : ModuleCat.{v} R} : AddCommGroup (M ⟶ N) := LinearMap.addCommGroup
instance : Preadditive (ModuleCat.{v} R) where
add_comp P Q R f f' g := by
ext
dsimp
erw [map_add]
rfl
instance forget₂_addCommGrp_additive :
(forget₂ (ModuleCat.{v} R) AddCommGrp).Additive where
section
variable {S : Type u} [CommRing S]
instance : Linear S (ModuleCat.{v} S) where
homModule X Y := LinearMap.module
smul_comp := by
intros
ext
dsimp
rw [LinearMap.smul_apply, LinearMap.smul_apply, map_smul]
rfl
variable {X Y X' Y' : ModuleCat.{v} S}
theorem Iso.homCongr_eq_arrowCongr (i : X ≅ X') (j : Y ≅ Y') (f : X ⟶ Y) :
Iso.homCongr i j f = LinearEquiv.arrowCongr i.toLinearEquiv j.toLinearEquiv f :=
rfl
theorem Iso.conj_eq_conj (i : X ≅ X') (f : End X) :
Iso.conj i f = LinearEquiv.conj i.toLinearEquiv f :=
rfl
end
variable (M N : ModuleCat.{v} R)
/-- The scalar multiplication on an object of `ModuleCat R` considered as
a morphism of rings from `R` to the endomorphisms of the underlying abelian group. -/
def smul : R →+* End ((forget₂ (ModuleCat R) AddCommGrp).obj M) where
toFun r :=
{ toFun := fun (m : M) => r • m
map_zero' := by dsimp; rw [smul_zero]
map_add' := fun x y => by dsimp; rw [smul_add] }
map_one' := AddMonoidHom.ext (fun x => by dsimp; rw [one_smul])
map_zero' := AddMonoidHom.ext (fun x => by dsimp; rw [zero_smul]; rfl)
map_mul' r s := AddMonoidHom.ext (fun (x : M) => (smul_smul r s x).symm)
map_add' r s := AddMonoidHom.ext (fun (x : M) => add_smul r s x)
lemma smul_naturality {M N : ModuleCat.{v} R} (f : M ⟶ N) (r : R) :
(forget₂ (ModuleCat R) AddCommGrp).map f ≫ N.smul r =
M.smul r ≫ (forget₂ (ModuleCat R) AddCommGrp).map f := by
ext x
exact (f.map_smul r x).symm
variable (R)
/-- The scalar multiplication on `ModuleCat R` considered as a morphism of rings
to the endomorphisms of the forgetful functor to `AddCommGrp)`. -/
@[simps]
def smulNatTrans : R →+* End (forget₂ (ModuleCat R) AddCommGrp) where
toFun r :=
{ app := fun M => M.smul r
naturality := fun _ _ _ => smul_naturality _ r }
map_one' := NatTrans.ext (by aesop_cat)
map_zero' := NatTrans.ext (by aesop_cat)
map_mul' _ _ := NatTrans.ext (by aesop_cat)
map_add' _ _ := NatTrans.ext (by aesop_cat)
variable {R}
/-- Given `A : AddCommGrp` and a ring morphism `R →+* End A`, this is a type synonym
for `A`, on which we shall define a structure of `R`-module. -/
@[nolint unusedArguments]
def mkOfSMul' {A : AddCommGrp} (_ : R →+* End A) := A
section
variable {A : AddCommGrp} (φ : R →+* End A)
instance : AddCommGroup (mkOfSMul' φ) := by
dsimp only [mkOfSMul']
infer_instance
instance : SMul R (mkOfSMul' φ) := ⟨fun r (x : A) => (show A ⟶ A from φ r) x⟩
@[simp]
lemma mkOfSMul'_smul (r : R) (x : mkOfSMul' φ) :
r • x = (show A ⟶ A from φ r) x := rfl
instance : Module R (mkOfSMul' φ) where
smul_zero _ := map_zero (N := A) _
smul_add _ _ _ := map_add (N := A) _ _ _
one_smul := by simp
mul_smul := by simp
add_smul _ _ _ := by simp; rfl
zero_smul := by simp
/-- Given `A : AddCommGrp` and a ring morphism `R →+* End A`, this is an object in
`ModuleCat R`, whose underlying abelian group is `A` and whose scalar multiplication is
given by `R`. -/
abbrev mkOfSMul := ModuleCat.of R (mkOfSMul' φ)
-- This lemma has always been bad, but lean4#2644 made `simp` start noticing
@[simp, nolint simpNF]
lemma mkOfSMul_smul (r : R) : (mkOfSMul φ).smul r = φ r := rfl
end
section
variable {M N}
(φ : (forget₂ (ModuleCat R) AddCommGrp).obj M ⟶
(forget₂ (ModuleCat R) AddCommGrp).obj N)
(hφ : ∀ (r : R), φ ≫ N.smul r = M.smul r ≫ φ)
/-- Constructor for morphisms in `ModuleCat R` which takes as inputs
a morphism between the underlying objects in `AddCommGrp` and the compatibility
with the scalar multiplication. -/
@[simps]
def homMk : M ⟶ N where
toFun := φ
map_add' _ _ := φ.map_add _ _
map_smul' r x := (congr_hom (hφ r) x).symm
lemma forget₂_map_homMk :
(forget₂ (ModuleCat R) AddCommGrp).map (homMk φ hφ) = φ := rfl
end
instance : (forget (ModuleCat.{v} R)).ReflectsIsomorphisms where
reflects f _ :=
(inferInstance : IsIso ((LinearEquiv.mk f
(asIso ((forget (ModuleCat R)).map f)).toEquiv.invFun
(Equiv.left_inv _) (Equiv.right_inv _)).toModuleIso).hom)
instance : (forget₂ (ModuleCat.{v} R) AddCommGrp.{v}).ReflectsIsomorphisms where
reflects f _ := by
have : IsIso ((forget _).map f) := by
change IsIso ((forget _).map ((forget₂ _ AddCommGrp).map f))
infer_instance
apply isIso_of_reflects_iso _ (forget _)
end ModuleCat
/-!
`@[simp]` lemmas for `LinearMap.comp` and categorical identities.
-/
@[simp] theorem LinearMap.comp_id_moduleCat
{R} [Ring R] {G : ModuleCat.{u} R} {H : Type u} [AddCommGroup H] [Module R H] (f : G →ₗ[R] H) :
f.comp (𝟙 G) = f :=
Category.id_comp (ModuleCat.ofHom f)
@[simp] theorem LinearMap.id_moduleCat_comp
{R} [Ring R] {G : Type u} [AddCommGroup G] [Module R G] {H : ModuleCat.{u} R} (f : G →ₗ[R] H) :
LinearMap.comp (𝟙 H) f = f :=
Category.comp_id (ModuleCat.ofHom f)
|
Algebra\Category\ModuleCat\Biproducts.lean
|
/-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.Algebra.Category.ModuleCat.Abelian
import Mathlib.Algebra.Homology.ShortComplex.ModuleCat
/-!
# The category of `R`-modules has finite biproducts
-/
open CategoryTheory
open CategoryTheory.Limits
universe w v u
namespace ModuleCat
variable {R : Type u} [Ring R]
-- As `ModuleCat R` is preadditive, and has all limits, it automatically has biproducts.
instance : HasBinaryBiproducts (ModuleCat.{v} R) :=
HasBinaryBiproducts.of_hasBinaryProducts
instance : HasFiniteBiproducts (ModuleCat.{v} R) :=
HasFiniteBiproducts.of_hasFiniteProducts
-- We now construct explicit limit data,
-- so we can compare the biproducts to the usual unbundled constructions.
/-- Construct limit data for a binary product in `ModuleCat R`, using `ModuleCat.of R (M × N)`.
-/
@[simps cone_pt isLimit_lift]
def binaryProductLimitCone (M N : ModuleCat.{v} R) : Limits.LimitCone (pair M N) where
cone :=
{ pt := ModuleCat.of R (M × N)
π :=
{ app := fun j =>
Discrete.casesOn j fun j =>
WalkingPair.casesOn j (LinearMap.fst R M N) (LinearMap.snd R M N)
naturality := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟨⟩⟩⟩ <;> rfl } }
isLimit :=
{ lift := fun s => LinearMap.prod (s.π.app ⟨WalkingPair.left⟩) (s.π.app ⟨WalkingPair.right⟩)
fac := by rintro s (⟨⟩ | ⟨⟩) <;> rfl
uniq := fun s m w => by
simp_rw [← w ⟨WalkingPair.left⟩, ← w ⟨WalkingPair.right⟩]
rfl }
@[simp]
theorem binaryProductLimitCone_cone_π_app_left (M N : ModuleCat.{v} R) :
(binaryProductLimitCone M N).cone.π.app ⟨WalkingPair.left⟩ = LinearMap.fst R M N :=
rfl
@[simp]
theorem binaryProductLimitCone_cone_π_app_right (M N : ModuleCat.{v} R) :
(binaryProductLimitCone M N).cone.π.app ⟨WalkingPair.right⟩ = LinearMap.snd R M N :=
rfl
/-- We verify that the biproduct in `ModuleCat R` is isomorphic to
the cartesian product of the underlying types:
-/
@[simps! hom_apply]
noncomputable def biprodIsoProd (M N : ModuleCat.{v} R) :
(M ⊞ N : ModuleCat.{v} R) ≅ ModuleCat.of R (M × N) :=
IsLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit M N) (binaryProductLimitCone M N).isLimit
-- These lemmas have always been bad (#7657), but lean4#2644 made `simp` start noticing
attribute [nolint simpNF] ModuleCat.biprodIsoProd_hom_apply
@[simp, elementwise]
theorem biprodIsoProd_inv_comp_fst (M N : ModuleCat.{v} R) :
(biprodIsoProd M N).inv ≫ biprod.fst = LinearMap.fst R M N :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.left)
@[simp, elementwise]
theorem biprodIsoProd_inv_comp_snd (M N : ModuleCat.{v} R) :
(biprodIsoProd M N).inv ≫ biprod.snd = LinearMap.snd R M N :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.right)
namespace HasLimit
variable {J : Type w} (f : J → ModuleCat.{max w v} R)
/-- The map from an arbitrary cone over an indexed family of abelian groups
to the cartesian product of those groups.
-/
@[simps]
def lift (s : Fan f) : s.pt ⟶ ModuleCat.of R (∀ j, f j) where
toFun x j := s.π.app ⟨j⟩ x
map_add' x y := by
simp only [Functor.const_obj_obj, map_add]
rfl
map_smul' r x := by
simp only [Functor.const_obj_obj, map_smul]
rfl
/-- Construct limit data for a product in `ModuleCat R`, using `ModuleCat.of R (∀ j, F.obj j)`.
-/
@[simps]
def productLimitCone : Limits.LimitCone (Discrete.functor f) where
cone :=
{ pt := ModuleCat.of R (∀ j, f j)
π := Discrete.natTrans fun j => (LinearMap.proj j.as : (∀ j, f j) →ₗ[R] f j.as) }
isLimit :=
{ lift := lift.{_, v} f
fac := fun s j => rfl
uniq := fun s m w => by
ext x
funext j
exact congr_arg (fun g : s.pt ⟶ f j => (g : s.pt → f j) x) (w ⟨j⟩) }
end HasLimit
open HasLimit
variable {J : Type} (f : J → ModuleCat.{v} R)
/-- We verify that the biproduct we've just defined is isomorphic to the `ModuleCat R` structure
on the dependent function type.
-/
@[simps! hom_apply]
noncomputable def biproductIsoPi [Finite J] (f : J → ModuleCat.{v} R) :
((⨁ f) : ModuleCat.{v} R) ≅ ModuleCat.of R (∀ j, f j) :=
IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (productLimitCone f).isLimit
-- These lemmas have always been bad (#7657), but lean4#2644 made `simp` start noticing
attribute [nolint simpNF] ModuleCat.biproductIsoPi_hom_apply
@[simp, elementwise]
theorem biproductIsoPi_inv_comp_π [Finite J] (f : J → ModuleCat.{v} R) (j : J) :
(biproductIsoPi f).inv ≫ biproduct.π f j = (LinearMap.proj j : (∀ j, f j) →ₗ[R] f j) :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk j)
end ModuleCat
section SplitExact
variable {R : Type u} {A M B : Type v} [Ring R] [AddCommGroup A] [Module R A] [AddCommGroup B]
[Module R B] [AddCommGroup M] [Module R M]
variable {j : A →ₗ[R] M} {g : M →ₗ[R] B}
open ModuleCat
/-- The isomorphism `A × B ≃ₗ[R] M` coming from a right split exact sequence `0 ⟶ A ⟶ M ⟶ B ⟶ 0`
of modules. -/
noncomputable def lequivProdOfRightSplitExact {f : B →ₗ[R] M} (hj : Function.Injective j)
(exac : LinearMap.range j = LinearMap.ker g) (h : g.comp f = LinearMap.id) : (A × B) ≃ₗ[R] M :=
((ShortComplex.Splitting.ofExactOfSection _
(ShortComplex.Exact.moduleCat_of_range_eq_ker (ModuleCat.ofHom j)
(ModuleCat.ofHom g) exac) (asHom f) h
(by simpa only [ModuleCat.mono_iff_injective])).isoBinaryBiproduct ≪≫
biprodIsoProd _ _ ).symm.toLinearEquiv
/-- The isomorphism `A × B ≃ₗ[R] M` coming from a left split exact sequence `0 ⟶ A ⟶ M ⟶ B ⟶ 0`
of modules. -/
noncomputable def lequivProdOfLeftSplitExact {f : M →ₗ[R] A} (hg : Function.Surjective g)
(exac : LinearMap.range j = LinearMap.ker g) (h : f.comp j = LinearMap.id) : (A × B) ≃ₗ[R] M :=
((ShortComplex.Splitting.ofExactOfRetraction _
(ShortComplex.Exact.moduleCat_of_range_eq_ker (ModuleCat.ofHom j)
(ModuleCat.ofHom g) exac) (ModuleCat.ofHom f) h
(by simpa only [ModuleCat.epi_iff_surjective] using hg)).isoBinaryBiproduct ≪≫
biprodIsoProd _ _).symm.toLinearEquiv
end SplitExact
|
Algebra\Category\ModuleCat\ChangeOfRings.lean
|
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Category.ModuleCat.Colimits
import Mathlib.Algebra.Category.ModuleCat.Limits
import Mathlib.RingTheory.TensorProduct.Basic
/-!
# 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`.
## List of notations
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 where
carrier := M
isModule := Module.compHom M f
/-- 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' :=
{ g with map_smul' := fun r => g.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
map_id _ := LinearMap.ext fun _ => rfl
map_comp _ _ := LinearMap.ext fun _ => rfl
instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) :
(restrictScalars.{v} f).Faithful where
map_injective h :=
LinearMap.ext fun x => by simpa only using DFunLike.congr_fun 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
instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] {f : R →+* S}
{M : ModuleCat.{v} S} : Module R <| (restrictScalars f).obj M :=
inferInstanceAs <| Module R <| RestrictScalars.obj' f M
-- Porting note: this should be automatic
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 • m : 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) :
-- Porting note: clumsy way to coerce
let m' : (restrictScalars f).obj M := m
(r • m' : (restrictScalars f).obj M) = (f r • m : 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.mk 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
toFun g :=
{ toFun := g
map_add' := by simp
map_smul' := by simp }
invFun g :=
{ toFun := g
map_add' := by simp
map_smul' := g.map_smul }
left_inv g := rfl
right_inv g := rfl
map_add' g₁ g₂ := rfl
section
variable {R : Type u₁} [Ring R] (f : R →+* R) (hf : f = RingHom.id R)
/-- For a `R`-module `M`, the restriction of scalars of `M` by the identity morphisms identifies
to `M`. -/
def restrictScalarsId'App (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)
lemma restrictScalarsId'App_hom_apply (M : ModuleCat R) (x : M) :
(restrictScalarsId'App f hf M).hom x = x :=
rfl
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 identify 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 morphisms identify 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₃) (hgf : gf = g.comp f)
/-- For each `R₃`-module `M`, restriction of scalars of `M` by a composition of ring morphisms
identifies to successively restricting scalars. -/
def restrictScalarsComp'App (M : ModuleCat R₃) :
(restrictScalars gf).obj M ≅ (restrictScalars f).obj ((restrictScalars g).obj M) :=
(AddEquiv.toLinearEquiv (by rfl) (fun r x ↦ by subst hgf; rfl)).toModuleIso'
lemma restrictScalarsComp'App_hom_apply (M : ModuleCat R₃) (x : M) :
(restrictScalarsComp'App f g gf hgf M).hom x = x :=
rfl
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 identify 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 identify 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'
{ __ := 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'
{ __ := AddEquiv.refl M
map_smul' := fun r m ↦ 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
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]
-- This notation is necessary because we need to reason about `s ⊗ₜ m` where `s : S` and `m : M`;
-- without this notation, one need to work with `s : (restrictScalars f).obj ⟨S⟩`.
scoped[ChangeOfRings]
notation s "⊗ₜ[" R "," f "]" m => @TensorProduct.tmul R _ _ _ _ _ (Module.compHom _ f) _ s m
end Unbundled
namespace ExtendScalars
open ChangeOfRings
variable (M : ModuleCat.{v} R)
/-- Extension of scalars turn an `R`-module into `S`-module by M ↦ S ⨂ M
-/
def obj' : ModuleCat S :=
⟨TensorProduct R ((restrictScalars f).obj ⟨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 :=
by-- The "by apply" part makes this require 75% fewer heartbeats to process (#16371).
apply @LinearMap.baseChange R S M1 M2 _ _ ((algebraMap S _).comp f).toAlgebra _ _ _ _ l
theorem map'_id {M : ModuleCat.{v} R} : map' f (𝟙 M) = 𝟙 _ :=
LinearMap.ext fun x : obj' f M => by
dsimp only [map']
-- Porting note: this got put in the dsimp by mathport
rw [ModuleCat.id_apply]
induction' x using TensorProduct.induction_on with _ _ m s ihx ihy
· rw [map_zero] -- Porting note: simp only [map_zero] failed
· -- Porting note: issues with synthesizing Algebra R S
erw [@LinearMap.baseChange_tmul R S M M _ _ (_), ModuleCat.id_apply]
· rw [map_add, ihx, ihy]
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₂₃ :=
LinearMap.ext fun x : obj' f M₁ => by
dsimp only [map']
induction' x using TensorProduct.induction_on with _ _ x y ihx ihy
· rfl
· rfl
· rw [map_add, map_add, ihx, ihy] -- Porting note: simp again failing where rw succeeds
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
open ChangeOfRings
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
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 ⟨S⟩ →ₗ[R] M where
smul s g :=
{ toFun := fun s' : S => g (s' * s : S)
map_add' := fun x y : S => by dsimp; 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 ⟨S⟩ →ₗ[R] M) (s' : S) :
(s • g) s' = g (s' * s : S) :=
rfl
instance mulAction : MulAction S <| (restrictScalars f).obj ⟨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 ⟨S⟩ →ₗ[R] M :=
{ CoextendScalars.mulAction f _ with
smul_add := fun s g h => LinearMap.ext fun _ : S => by simp
smul_zero := fun s => 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 ⟨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 :=
⟨(restrictScalars f).obj ⟨S⟩ →ₗ[R] M⟩
instance : CoeFun (obj' f M) fun _ => S → M where coe g := g.toFun
/-- 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' where
toFun h := g.comp h
map_add' _ _ := LinearMap.comp_add _ _ _
map_smul' s h := LinearMap.ext fun t : S => by dsimp; rw [smul_apply',smul_apply']; simp
-- Porting note: smul_apply' not working in 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 _ := LinearMap.ext fun _ => LinearMap.ext fun _ => rfl
map_comp _ _ := LinearMap.ext fun _ => LinearMap.ext fun _ => rfl
namespace CoextendScalars
variable {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S)
-- Porting note: this coercion doesn't line up well with task below
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))`
-/
@[simps apply_apply]
def HomEquiv.fromRestriction {X : ModuleCat R} {Y : ModuleCat S}
(g : (restrictScalars f).obj Y ⟶ X) : Y ⟶ (coextendScalars f).obj X where
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.map_smul]
erw [smul_eq_mul, mul_smul]
rfl}
map_add' := fun y1 y2 : Y =>
LinearMap.ext fun s : S => by
-- Porting note: double dsimp seems odd
dsimp only [id_eq, eq_mpr_eq_cast, 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, cast_eq,
LinearMap.coe_mk]
rw [LinearMap.add_apply, LinearMap.coe_mk, LinearMap.coe_mk]
dsimp only [AddHom.coe_mk]
rw [smul_add, map_add]
map_smul' := fun (s : S) (y : Y) => LinearMap.ext fun t : S => by
-- Porting note: used to be simp [mul_smul]
simp only [LinearMap.coe_mk, AddHom.coe_mk, RingHom.id_apply]
rw [ModuleCat.CoextendScalars.smul_apply', LinearMap.coe_mk]
dsimp
rw [mul_smul]
/-- 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`
-/
@[simps apply]
def HomEquiv.toRestriction {X Y} (g : Y ⟶ (coextendScalars f).obj X) :
(restrictScalars f).obj Y ⟶ X where
toFun := fun y : Y => (g y) (1 : S)
map_add' x y := by dsimp; rw [g.map_add, LinearMap.add_apply]
map_smul' r (y : Y) := by
dsimp
rw [← LinearMap.map_smul]
erw [smul_eq_mul, mul_one, LinearMap.map_smul]
-- Porting note: should probably change CoeFun for obj above
rw [← LinearMap.coe_toAddHom, ← AddHom.toFun_eq_coe]
rw [CoextendScalars.smul_apply (s := f r) (g := g y) (s' := 1), one_mul]
simp
-- Porting note: add to address timeout in unit'
/-- Auxiliary definition for `unit'` -/
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 s s' => 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] Porting note: not in normal form and not used
protected def unit' : 𝟭 (ModuleCat S) ⟶ restrictScalars f ⋙ coextendScalars f where
app Y := app' f Y
naturality Y Y' g :=
LinearMap.ext fun y : Y => LinearMap.ext fun s : S => by
-- Porting note (#10745): previously simp [CoextendScalars.map_apply]
simp only [ModuleCat.coe_comp, Functor.id_map, Functor.id_obj, Functor.comp_obj,
Functor.comp_map]
rw [coe_comp, coe_comp, Function.comp, Function.comp]
conv_rhs => rw [← LinearMap.coe_toAddHom, ← AddHom.toFun_eq_coe]
erw [CoextendScalars.map_apply, AddHom.toFun_eq_coe, LinearMap.coe_toAddHom,
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] Porting note: not in normal form and not used
protected def counit' : coextendScalars f ⋙ restrictScalars f ⟶ 𝟭 (ModuleCat R) where
app 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 [← LinearMap.coe_toAddHom, ← AddHom.toFun_eq_coe]
rw [CoextendScalars.smul_apply (s := f r) (g := g) (s' := 1), one_mul, ← LinearMap.map_smul]
rw [← LinearMap.coe_toAddHom, ← AddHom.toFun_eq_coe]
congr
change f r = (f r) • (1 : S)
rw [smul_eq_mul (a := f r) (a' := 1), mul_one] }
naturality X X' g := LinearMap.ext fun h => by
rw [ModuleCat.coe_comp]
rfl
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 where
homEquiv X Y :=
{ toFun := RestrictionCoextensionAdj.HomEquiv.fromRestriction.{u₁,u₂,v} f
invFun := RestrictionCoextensionAdj.HomEquiv.toRestriction.{u₁,u₂,v} f
left_inv := fun g => LinearMap.ext fun x : X => by
-- Porting note (#10745): once just simp
rw [RestrictionCoextensionAdj.HomEquiv.toRestriction_apply, AddHom.toFun_eq_coe,
LinearMap.coe_toAddHom, RestrictionCoextensionAdj.HomEquiv.fromRestriction_apply_apply,
one_smul]
right_inv := fun g => LinearMap.ext fun x => LinearMap.ext fun s : S => by
-- Porting note (#10745): once just simp
rw [RestrictionCoextensionAdj.HomEquiv.fromRestriction_apply_apply,
RestrictionCoextensionAdj.HomEquiv.toRestriction_apply, AddHom.toFun_eq_coe,
LinearMap.coe_toAddHom, 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 := LinearMap.ext fun y => rfl
homEquiv_counit := fun {X Y g} => LinearMap.ext <| by
-- Porting note (#10745): previously simp [RestrictionCoextensionAdj.counit']
intro x; dsimp
rw [coe_comp, Function.comp]
change _ = (((restrictScalars f).map g) x).toFun (1 : S)
rw [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, restrictScalars.map_apply]
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 ChangeOfRings
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 apply]
def HomEquiv.toRestrictScalars {X Y} (g : (extendScalars f).obj X ⟶ Y) :
X ⟶ (restrictScalars f).obj Y where
toFun x := g <| (1 : S)⊗ₜ[R,f]x
map_add' _ _ := by dsimp; rw [tmul_add, map_add]
map_smul' r x := by
letI : Module R S := Module.compHom S f
letI : Module R Y := Module.compHom Y f
dsimp
erw [RestrictScalars.smul_def, ← LinearMap.map_smul, 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
intros 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 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 {toFun := fun z => TensorProduct.lift ?_ 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 [evalAt_apply, LinearMap.add_apply]
rw [← add_smul]
· ext x
apply mul_smul (f r) s (g x)
· intros z₁ z₂
change lift _ (z₁ + z₂) = lift _ z₁ + lift _ z₂
rw [map_add]
· intro s z
change lift _ (s • z) = s • lift _ z
induction' z using TensorProduct.induction_on with s' x x y ih1 ih2
· rw [smul_zero, map_zero, smul_zero]
· 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]
· rw [smul_add, map_add, ih1, ih2, map_add, smul_add]
/-- Given `R`-module X and `S`-module Y, `S`-linear 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 LinearMap.ext; intro z
induction' z using TensorProduct.induction_on with x s z1 z2 ih1 ih2
· rw [map_zero, map_zero]
· 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
· 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
apply LinearMap.ext; intro x
rw [HomEquiv.toRestrictScalars_apply, HomEquiv.fromExtendScalars_apply, 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 where
toFun x := (1 : S)⊗ₜ[R,f]x
map_add' x x' := by dsimp; rw [TensorProduct.tmul_add]
map_smul' r x := by
letI m1 : Module R S := Module.compHom S f
-- Porting note: used to be rfl
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 apply]
def Counit.map {Y} : (restrictScalars f ⋙ extendScalars f).obj Y ⟶ Y where
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' _ _ := by rw [map_add]
map_smul' s z := by
letI m1 : Module R S := Module.compHom S f
letI m2 : Module R Y := Module.compHom Y f
dsimp only
induction' z using TensorProduct.induction_on with s' y z1 z2 ih1 ih2
· rw [smul_zero, map_zero, smul_zero]
· 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]
· rw [smul_add, map_add, map_add, ih1, ih2, smul_add]
-- Porting note: this file has to probably be reworked when
-- coercions and instance synthesis are fixed for concrete categories
-- so I say nolint now and move on
attribute [nolint simpNF] Counit.map_apply
/-- 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
apply LinearMap.ext; intro z
induction' z using TensorProduct.induction_on with s' y z₁ z₂ ih₁ ih₂
· rw [map_zero, map_zero]
· dsimp
rw [ModuleCat.coe_comp, ModuleCat.coe_comp, Function.comp_apply, Function.comp_apply,
ExtendScalars.map_tmul, restrictScalars.map_apply]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [Counit.map_apply]
rw [lift.tmul, LinearMap.coe_mk, LinearMap.coe_mk]
set s' : S := s'
change s' • g y = g (s' • y)
rw [map_smul]
· 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.
-/
-- @[simps] -- Porting note: removed not in normal form and not used
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 where
homEquiv _ _ := ExtendRestrictScalarsAdj.homEquiv.{v,u₁,u₂} f
unit := ExtendRestrictScalarsAdj.unit.{v,u₁,u₂} f
counit := ExtendRestrictScalarsAdj.counit.{v,u₁,u₂} f
homEquiv_unit {X Y g} := LinearMap.ext fun x => by
dsimp
rw [ModuleCat.coe_comp, Function.comp_apply, restrictScalars.map_apply]
rfl
homEquiv_counit {X Y g} := LinearMap.ext fun x => by
-- Porting note: once again reminding Lean of the instances
letI m1 : Module R S := Module.compHom S f
letI m2 : Module R Y := Module.compHom Y f
induction' x using TensorProduct.induction_on with s x _ _ _ _
· rw [map_zero, map_zero]
· rw [ExtendRestrictScalarsAdj.homEquiv_symm_apply]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [ModuleCat.coe_comp]
rw [Function.comp_apply, ExtendRestrictScalarsAdj.counit_app]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [ExtendRestrictScalarsAdj.Counit.map_apply]
set_option tactic.skipAssignedInstances false in dsimp
rw [TensorProduct.lift.tmul]
rfl
· rw [map_add,map_add]
congr 1
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 preservesLimitRestrictScalars
{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₂ _ AddCommGrp) hc
exact isLimitOfReflects (forget₂ _ AddCommGrp) hc'⟩
instance preservesColimitRestrictScalars {R S : Type*} [Ring R] [Ring S]
(f : R →+* S) {J : Type*} [Category J] (F : J ⥤ ModuleCat.{v} S)
[HasColimit (F ⋙ forget₂ _ AddCommGrp)] :
PreservesColimit F (ModuleCat.restrictScalars.{v} f) := by
have : HasColimit ((F ⋙ restrictScalars f) ⋙ forget₂ (ModuleCat R) AddCommGrp) :=
inferInstanceAs (HasColimit (F ⋙ forget₂ _ AddCommGrp))
apply preservesColimitOfPreservesColimitCocone (HasColimit.isColimitColimitCocone F)
apply isColimitOfReflects (forget₂ _ AddCommGrp)
apply isColimitOfPreserves (forget₂ (ModuleCat.{v} S) AddCommGrp.{v})
exact HasColimit.isColimitColimitCocone F
end ModuleCat
end ModuleCat
|
Algebra\Category\ModuleCat\Colimits.lean
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Joël Riou
-/
import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
import Mathlib.Algebra.Category.Grp.Colimits
/-!
# The category of R-modules has all colimits.
From the existence of colimits in `AddCommGrp`, we deduce the existence of colimits
in `ModuleCat R`. This way, we get for free that the functor
`forget₂ (ModuleCat R) AddCommGrp` commutes with colimits.
Note that finite colimits can already be obtained from the instance `Abelian (Module R)`.
TODO:
In fact, in `ModuleCat R` there is a much nicer model of colimits as quotients
of finitely supported functions, and we really should implement this as well.
-/
universe w' w u v
open CategoryTheory Category Limits
variable {R : Type w} [Ring R]
namespace ModuleCat
variable {J : Type u} [Category.{v} J] (F : J ⥤ ModuleCat.{w'} R)
namespace HasColimit
variable [HasColimit (F ⋙ forget₂ _ AddCommGrp)]
/-- The induced scalar multiplication on
`colimit (F ⋙ forget₂ _ AddCommGrp)`. -/
@[simps]
noncomputable def coconePointSMul :
R →+* End (colimit (F ⋙ forget₂ _ AddCommGrp)) where
toFun r := colimMap
{ app := fun j => (F.obj j).smul r
naturality := fun X Y f => smul_naturality _ _ }
map_zero' := colimit.hom_ext (by simp)
map_one' := colimit.hom_ext (by simp)
map_add' r s := colimit.hom_ext (fun j => by
simp only [Functor.comp_obj, forget₂_obj, map_add, ι_colimMap]
rw [Preadditive.add_comp, Preadditive.comp_add]
simp only [ι_colimMap, Functor.comp_obj, forget₂_obj])
map_mul' r s := colimit.hom_ext (fun j => by simp)
/-- The cocone for `F` constructed from the colimit of
`(F ⋙ forget₂ (ModuleCat R) AddCommGrp)`. -/
@[simps]
noncomputable def colimitCocone : Cocone F where
pt := mkOfSMul (coconePointSMul F)
ι :=
{ app := fun j => homMk (colimit.ι (F ⋙ forget₂ _ AddCommGrp) j) (fun r => by
dsimp
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [mkOfSMul_smul]
simp)
naturality := fun i j f => by
apply (forget₂ _ AddCommGrp).map_injective
simp only [Functor.map_comp, forget₂_map_homMk]
dsimp
erw [colimit.w (F ⋙ forget₂ _ AddCommGrp), comp_id] }
/-- The cocone for `F` constructed from the colimit of
`(F ⋙ forget₂ (ModuleCat R) AddCommGrp)` is a colimit cocone. -/
noncomputable def isColimitColimitCocone : IsColimit (colimitCocone F) where
desc s := homMk (colimit.desc _ ((forget₂ _ AddCommGrp).mapCocone s)) (fun r => by
apply colimit.hom_ext
intro j
dsimp
rw [colimit.ι_desc_assoc]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [mkOfSMul_smul]
dsimp
simp only [ι_colimMap_assoc, Functor.comp_obj, forget₂_obj, colimit.ι_desc,
Functor.mapCocone_pt, Functor.mapCocone_ι_app, forget₂_map]
exact smul_naturality (s.ι.app j) r)
fac s j := by
apply (forget₂ _ AddCommGrp).map_injective
exact colimit.ι_desc ((forget₂ _ AddCommGrp).mapCocone s) j
uniq s m hm := by
apply (forget₂ _ AddCommGrp).map_injective
apply colimit.hom_ext
intro j
erw [colimit.ι_desc ((forget₂ _ AddCommGrp).mapCocone s) j]
dsimp
rw [← hm]
rfl
instance : HasColimit F := ⟨_, isColimitColimitCocone F⟩
noncomputable instance : PreservesColimit F (forget₂ _ AddCommGrp) :=
preservesColimitOfPreservesColimitCocone (isColimitColimitCocone F) (colimit.isColimit _)
noncomputable instance reflectsColimit :
ReflectsColimit F (forget₂ (ModuleCat.{w'} R) AddCommGrp) :=
reflectsColimitOfReflectsIsomorphisms _ _
end HasColimit
variable (J R)
instance hasColimitsOfShape [HasColimitsOfShape J AddCommGrp.{w'}] :
HasColimitsOfShape J (ModuleCat.{w'} R) where
noncomputable instance reflectsColimitsOfShape [HasColimitsOfShape J AddCommGrp.{w'}] :
ReflectsColimitsOfShape J (forget₂ (ModuleCat.{w'} R) AddCommGrp) where
instance hasColimitsOfSize [HasColimitsOfSize.{v, u} AddCommGrp.{w'}] :
HasColimitsOfSize.{v, u} (ModuleCat.{w'} R) where
noncomputable instance forget₂PreservesColimitsOfShape
[HasColimitsOfShape J AddCommGrp.{w'}] :
PreservesColimitsOfShape J (forget₂ (ModuleCat.{w'} R) AddCommGrp) where
noncomputable instance forget₂PreservesColimitsOfSize
[HasColimitsOfSize.{u, v} AddCommGrp.{w'}] :
PreservesColimitsOfSize.{u, v} (forget₂ (ModuleCat.{w'} R) AddCommGrp) where
noncomputable instance
[HasColimitsOfSize.{u, v} AddCommGrpMax.{w, w'}] :
PreservesColimitsOfSize.{u, v} (forget₂ (ModuleCatMax.{w, w'} R) AddCommGrp) where
instance : HasFiniteColimits (ModuleCat.{w'} R) := inferInstance
-- Sanity checks, just to make sure typeclass search can find the instances we want.
example (R : Type u) [Ring R] : HasColimits (ModuleCatMax.{v, u} R) :=
inferInstance
example (R : Type u) [Ring R] : HasColimits (ModuleCatMax.{u, v} R) :=
inferInstance
example (R : Type u) [Ring R] : HasColimits (ModuleCat.{u} R) :=
inferInstance
example (R : Type u) [Ring R] : HasCoequalizers (ModuleCat.{u} R) := by
infer_instance
-- for some reason, this instance is not found automatically later on
instance : HasCoequalizers (ModuleCat.{v} R) where
noncomputable example (R : Type u) [Ring R] :
PreservesColimits (forget₂ (ModuleCat.{u} R) AddCommGrp) := inferInstance
end ModuleCat
|
Algebra\Category\ModuleCat\EpiMono.lean
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.LinearAlgebra.Quotient
import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.CategoryTheory.ConcreteCategory.EpiMono
/-!
# Monomorphisms in `Module R`
This file shows that an `R`-linear map is a monomorphism in the category of `R`-modules
if and only if it is injective, and similarly an epimorphism if and only if it is surjective.
-/
universe v u
open CategoryTheory
namespace ModuleCat
variable {R : Type u} [Ring R] {X Y : ModuleCat.{v} R} (f : X ⟶ Y)
variable {M : Type v} [AddCommGroup M] [Module R M]
theorem ker_eq_bot_of_mono [Mono f] : LinearMap.ker f = ⊥ :=
LinearMap.ker_eq_bot_of_cancel fun u v => (@cancel_mono _ _ _ _ _ f _ (↟u) (↟v)).1
theorem range_eq_top_of_epi [Epi f] : LinearMap.range f = ⊤ :=
LinearMap.range_eq_top_of_cancel fun u v => (@cancel_epi _ _ _ _ _ f _ (↟u) (↟v)).1
theorem mono_iff_ker_eq_bot : Mono f ↔ LinearMap.ker f = ⊥ :=
⟨fun hf => ker_eq_bot_of_mono _, fun hf =>
ConcreteCategory.mono_of_injective _ <| by convert LinearMap.ker_eq_bot.1 hf⟩
theorem mono_iff_injective : Mono f ↔ Function.Injective f := by
rw [mono_iff_ker_eq_bot, LinearMap.ker_eq_bot]
theorem epi_iff_range_eq_top : Epi f ↔ LinearMap.range f = ⊤ :=
⟨fun _ => range_eq_top_of_epi _, fun hf =>
ConcreteCategory.epi_of_surjective _ <| LinearMap.range_eq_top.1 hf⟩
theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by
rw [epi_iff_range_eq_top, LinearMap.range_eq_top]
/-- If the zero morphism is an epi then the codomain is trivial. -/
def uniqueOfEpiZero (X) [h : Epi (0 : X ⟶ of R M)] : Unique M :=
uniqueOfSurjectiveZero X ((ModuleCat.epi_iff_surjective _).mp h)
instance mono_as_hom'_subtype (U : Submodule R X) : Mono (ModuleCat.asHomRight U.subtype) :=
(mono_iff_ker_eq_bot _).mpr (Submodule.ker_subtype U)
instance epi_as_hom''_mkQ (U : Submodule R X) : Epi (↿U.mkQ) :=
(epi_iff_range_eq_top _).mpr <| Submodule.range_mkQ _
instance forget_preservesEpimorphisms : (forget (ModuleCat.{v} R)).PreservesEpimorphisms where
preserves f hf := by
erw [CategoryTheory.epi_iff_surjective, ← epi_iff_surjective]
exact hf
instance forget_preservesMonomorphisms : (forget (ModuleCat.{v} R)).PreservesMonomorphisms where
preserves f hf := by
erw [CategoryTheory.mono_iff_injective, ← mono_iff_injective]
exact hf
end ModuleCat
|
Algebra\Category\ModuleCat\FilteredColimits.lean
|
/-
Copyright (c) 2021 Justus Springer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Justus Springer
-/
import Mathlib.Algebra.Category.Grp.FilteredColimits
import Mathlib.Algebra.Category.ModuleCat.Basic
/-!
# The forgetful functor from `R`-modules 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 ring `R`, a small filtered category `J` and a functor
`F : J ⥤ ModuleCat R`. We show that the colimit of `F ⋙ forget₂ (ModuleCat R) AddCommGrp`
(in `AddCommGrp`) carries the structure of an `R`-module, thereby showing that the forgetful
functor `forget₂ (ModuleCat R) AddCommGrp` preserves filtered colimits. In particular, this
implies that `forget (ModuleCat R)` preserves filtered colimits.
-/
universe v u
noncomputable section
open CategoryTheory CategoryTheory.Limits
open CategoryTheory.IsFiltered renaming max → max' -- avoid name collision with `_root_.max`.
open AddMonCat.FilteredColimits (colimit_zero_eq colimit_add_mk_eq)
namespace ModuleCat.FilteredColimits
section
variable {R : Type u} [Ring R] {J : Type v} [SmallCategory J] [IsFiltered J]
variable (F : J ⥤ ModuleCatMax.{v, u, u} R)
/-- The colimit of `F ⋙ forget₂ (ModuleCat R) AddCommGrp` in the category `AddCommGrp`.
In the following, we will show that this has the structure of an `R`-module.
-/
abbrev M : AddCommGrp :=
AddCommGrp.FilteredColimits.colimit.{v, u}
(F ⋙ forget₂ (ModuleCat R) AddCommGrp.{max v u})
/-- The canonical projection into the colimit, as a quotient type. -/
abbrev M.mk : (Σ j, F.obj j) → M F :=
Quot.mk (Types.Quot.Rel (F ⋙ forget (ModuleCat R)))
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 F x = M.mk F y :=
Quot.EqvGen_sound (Types.FilteredColimit.eqvGen_quot_rel_of_rel (F ⋙ forget (ModuleCat R)) x y h)
/-- The "unlifted" version of scalar multiplication in the colimit. -/
def colimitSMulAux (r : R) (x : Σ j, F.obj j) : M F :=
M.mk F ⟨x.1, r • x.2⟩
theorem colimitSMulAux_eq_of_rel (r : R) (x y : Σ j, F.obj j)
(h : Types.FilteredColimit.Rel (F ⋙ forget (ModuleCat R)) x y) :
colimitSMulAux F r x = colimitSMulAux F r y := by
apply M.mk_eq
obtain ⟨k, f, g, hfg⟩ := h
use k, f, g
simp only [Functor.comp_obj, Functor.comp_map, forget_map] at hfg
simp [hfg]
/-- Scalar multiplication in the colimit. See also `colimitSMulAux`. -/
instance colimitHasSMul : SMul R (M F) where
smul r x := by
refine Quot.lift (colimitSMulAux F r) ?_ x
intro x y h
apply colimitSMulAux_eq_of_rel
apply Types.FilteredColimit.rel_of_quot_rel
exact h
@[simp]
theorem colimit_smul_mk_eq (r : R) (x : Σ j, F.obj j) : r • M.mk F x = M.mk F ⟨x.1, r • x.2⟩ :=
rfl
private theorem colimitModule.one_smul (x : (M F)) : (1 : R) • x = x := by
refine Quot.inductionOn x ?_; clear x; intro x; cases' x with j x
erw [colimit_smul_mk_eq F 1 ⟨j, x⟩]
simp
rfl
-- Porting note (#11083): writing directly the `Module` instance makes things very slow.
instance colimitMulAction : MulAction R (M F) where
one_smul x := by
refine Quot.inductionOn x ?_; clear x; intro x; cases' x with j x
erw [colimit_smul_mk_eq F 1 ⟨j, x⟩, one_smul]
rfl
mul_smul r s x := by
refine Quot.inductionOn x ?_; clear x; intro x; cases' x with j x
erw [colimit_smul_mk_eq F (r * s) ⟨j, x⟩, colimit_smul_mk_eq F s ⟨j, x⟩,
colimit_smul_mk_eq F r ⟨j, _⟩, mul_smul]
instance colimitSMulWithZero : SMulWithZero R (M F) :=
{ colimitMulAction F with
smul_zero := fun r => by
erw [colimit_zero_eq _ (IsFiltered.nonempty.some : J), colimit_smul_mk_eq, smul_zero]
rfl
zero_smul := fun x => by
refine Quot.inductionOn x ?_; clear x; intro x; cases' x with j x
erw [colimit_smul_mk_eq, zero_smul, colimit_zero_eq _ j]
rfl }
private theorem colimitModule.add_smul (r s : R) (x : (M F)) : (r + s) • x = r • x + s • x := by
refine Quot.inductionOn x ?_; clear x; intro x; cases' x with j x
erw [colimit_smul_mk_eq, _root_.add_smul, colimit_smul_mk_eq, colimit_smul_mk_eq,
colimit_add_mk_eq _ ⟨j, _⟩ ⟨j, _⟩ j (𝟙 j) (𝟙 j)]
simp only [Functor.comp_obj, forget₂_obj, Functor.comp_map, CategoryTheory.Functor.map_id,
forget₂_map]
rfl
instance colimitModule : Module R (M F) :=
{ colimitMulAction F,
colimitSMulWithZero F with
smul_add := fun r x y => by
refine Quot.induction_on₂ x y ?_; clear x y; intro x y; cases' x with i x; cases' y with j y
erw [colimit_add_mk_eq _ ⟨i, _⟩ ⟨j, _⟩ (max' i j) (IsFiltered.leftToMax i j)
(IsFiltered.rightToMax i j), colimit_smul_mk_eq, smul_add, colimit_smul_mk_eq,
colimit_smul_mk_eq, colimit_add_mk_eq _ ⟨i, _⟩ ⟨j, _⟩ (max' i j) (IsFiltered.leftToMax i j)
(IsFiltered.rightToMax i j), LinearMap.map_smul, LinearMap.map_smul]
rfl
add_smul := colimitModule.add_smul F }
/-- The bundled `R`-module giving the filtered colimit of a diagram. -/
def colimit : ModuleCatMax.{v, u, u} R :=
ModuleCat.of R (M F)
/-- The linear map from a given `R`-module in the diagram to the colimit module. -/
def coconeMorphism (j : J) : F.obj j ⟶ colimit F :=
{ (AddCommGrp.FilteredColimits.colimitCocone
(F ⋙ forget₂ (ModuleCat R) AddCommGrp.{max v u})).ι.app j with
map_smul' := fun r x => by erw [colimit_smul_mk_eq F r ⟨j, x⟩]; rfl }
/-- The cocone over the proposed colimit module. -/
def colimitCocone : Cocone F where
pt := colimit F
ι :=
{ app := coconeMorphism F
naturality := fun _ _' f =>
LinearMap.coe_injective
((Types.TypeMax.colimitCocone (F ⋙ forget (ModuleCat R))).ι.naturality f) }
/-- Given a cocone `t` of `F`, the induced monoid linear map from the colimit to the cocone point.
We already know that this is a morphism between additive groups. The only thing left to see is that
it is a linear map, i.e. preserves scalar multiplication.
-/
def colimitDesc (t : Cocone F) : colimit F ⟶ t.pt :=
{ (AddCommGrp.FilteredColimits.colimitCoconeIsColimit
(F ⋙ forget₂ (ModuleCatMax.{v, u} R) AddCommGrp.{max v u})).desc
((forget₂ (ModuleCat R) AddCommGrp.{max v u}).mapCocone t) with
map_smul' := fun r x => by
refine Quot.inductionOn x ?_; clear x; intro x; cases' x with j x
erw [colimit_smul_mk_eq]
exact LinearMap.map_smul (t.ι.app j) r x }
/-- The proposed colimit cocone is a colimit in `ModuleCat R`. -/
def colimitCoconeIsColimit : IsColimit (colimitCocone F) where
desc := colimitDesc F
fac t j :=
LinearMap.coe_injective <|
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget (ModuleCat R))).fac
((forget (ModuleCat R)).mapCocone t) j
uniq t _ h :=
LinearMap.coe_injective <|
(Types.TypeMax.colimitCoconeIsColimit (F ⋙ forget (ModuleCat R))).uniq
((forget (ModuleCat R)).mapCocone t) _ fun j => funext fun x => LinearMap.congr_fun (h j) x
instance forget₂AddCommGroupPreservesFilteredColimits :
PreservesFilteredColimits (forget₂ (ModuleCat.{u} R) AddCommGrp.{u}) where
preserves_filtered_colimits J _ _ :=
{ -- Porting note: without the curly braces for `F`
-- here we get a confusing error message about universes.
preservesColimit := fun {F : J ⥤ ModuleCat.{u} R} =>
preservesColimitOfPreservesColimitCocone (colimitCoconeIsColimit F)
(AddCommGrp.FilteredColimits.colimitCoconeIsColimit
(F ⋙ forget₂ (ModuleCat.{u} R) AddCommGrp.{u})) }
instance forgetPreservesFilteredColimits : PreservesFilteredColimits (forget (ModuleCat.{u} R)) :=
Limits.compPreservesFilteredColimits (forget₂ (ModuleCat R) AddCommGrp)
(forget AddCommGrp)
end
end ModuleCat.FilteredColimits
|
Algebra\Category\ModuleCat\Free.lean
|
/-
Copyright (c) 2023 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
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
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)
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.range_coe, span_eq (LinearMap.range S.f), hS.moduleCat_range_eq_ker]
exact range_ker_disjoint hw
/-- 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 hw, disjoint_span_sum hS hw huv⟩
rw [huv, LinearMap.linearIndependent_iff S.f]; swap
· rw [LinearMap.ker_eq_bot, ← mono_iff_injective]
infer_instance
exact hv
/-- 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.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
/-- 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 := by
rw [hS.moduleCat_range_eq_ker]
simp only [LinearMap.mem_ker, map_sub, sub_eq_zero]
rw [← hm, map_finsupp_sum]
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_finsupp_sum] 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]
/-- 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.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)
/-- 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 : FiniteDimensional.finrank R S.X₁ = n)
(hP : FiniteDimensional.finrank R S.X₃ = p)
[StrongRankCondition R] :
FiniteDimensional.finrank R S.X₂ = n + p := by
apply FiniteDimensional.finrank_eq_of_rank_eq
rw [free_shortExact_rank_add hS', ← hN, ← hP]
simp only [Nat.cast_add, finrank_eq_rank]
end ModuleCat
|
Algebra\Category\ModuleCat\Images.lean
|
/-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
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_val
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)
/-- The inclusion of `image f` into the target -/
def image.ι : image f ⟶ H :=
f.range.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 :=
f.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 where
toFun := (fun x => F'.e (Classical.indefiniteDescription _ x.2).1 : image f → F'.I)
map_add' 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' 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) :=
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 f.range.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 f.range.subtype = Limits.image.ι f := by
erw [← imageIsoRange_inv_image_ι f, Iso.hom_inv_id_assoc]
end ModuleCat
|
Algebra\Category\ModuleCat\Injective.lean
|
/-
Copyright (c) 2023 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings
import Mathlib.Algebra.Category.Grp.EnoughInjectives
import Mathlib.Algebra.Category.Grp.ZModuleEquivalence
import Mathlib.Logic.Equiv.TransferInstance
/-!
# Category of $R$-modules has enough injectives
we lift enough injectives of abelian groups to arbitrary $R$-modules by adjoint functors
`restrictScalars ⊣ coextendScalars`
## Implementation notes
This file is not part of `Algebra/Module/Injective.lean` to prevent import loop: enough-injectives
of abelian groups needs `Algebra/Module/Injective.lean` and this file needs enough-injectives of
abelian groups.
-/
open CategoryTheory
universe v u
variable (R : Type u) [Ring R]
instance : EnoughInjectives (ModuleCat.{v} ℤ) :=
EnoughInjectives.of_equivalence (forget₂ (ModuleCat ℤ) AddCommGrp)
lemma ModuleCat.enoughInjectives : EnoughInjectives (ModuleCat.{max v u} R) :=
EnoughInjectives.of_adjunction (ModuleCat.restrictCoextendScalarsAdj.{max v u} (algebraMap ℤ R))
open ModuleCat in
instance [UnivLE.{u,v}] : EnoughInjectives (ModuleCat.{v} R) :=
letI := (equivShrink.{v} R).symm.ring
letI := enoughInjectives.{v} (Shrink.{v} R)
EnoughInjectives.of_equivalence (restrictScalars (equivShrink R).symm.ringEquiv.toRingHom)
|
Algebra\Category\ModuleCat\Kernels.lean
|
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
/-!
# The concrete (co)kernels in the category of modules are (co)kernels in the categorical sense.
-/
open CategoryTheory CategoryTheory.Limits
universe u v
namespace ModuleCat
variable {R : Type u} [Ring R]
section
variable {M N : ModuleCat.{v} R} (f : M ⟶ N)
/-- The kernel cone induced by the concrete kernel. -/
def kernelCone : KernelFork f :=
-- Porting note: previously proven by tidy
KernelFork.ofι (asHom f.ker.subtype) <| by ext x; cases x; assumption
/-- The kernel of a linear map is a kernel in the categorical sense. -/
def kernelIsLimit : IsLimit (kernelCone f) :=
Fork.IsLimit.mk _
(fun s =>
-- Porting note (#11036): broken dot notation on LinearMap.ker
LinearMap.codRestrict (LinearMap.ker f) (Fork.ι s) fun c =>
LinearMap.mem_ker.2 <| by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [← @Function.comp_apply _ _ _ f (Fork.ι s) c, ← coe_comp]
rw [Fork.condition, HasZeroMorphisms.comp_zero (Fork.ι s) N]
rfl)
(fun s => LinearMap.subtype_comp_codRestrict _ _ _) fun s m h =>
LinearMap.ext fun x => Subtype.ext_iff_val.2 (by simp [← h]; rfl)
/-- The cokernel cocone induced by the projection onto the quotient. -/
def cokernelCocone : CokernelCofork f :=
CokernelCofork.ofπ (asHom f.range.mkQ) <| LinearMap.range_mkQ_comp _
/-- The projection onto the quotient is a cokernel in the categorical sense. -/
def cokernelIsColimit : IsColimit (cokernelCocone f) :=
Cofork.IsColimit.mk _
(fun s =>
f.range.liftQ (Cofork.π s) <| LinearMap.range_le_ker_iff.2 <| CokernelCofork.condition s)
(fun s => f.range.liftQ_mkQ (Cofork.π s) _) fun s m h => by
-- Porting note (#11036): broken dot notation
haveI : Epi (asHom (LinearMap.range f).mkQ) :=
(epi_iff_range_eq_top _).mpr (Submodule.range_mkQ _)
-- Porting note (#11036): broken dot notation
apply (cancel_epi (asHom (LinearMap.range f).mkQ)).1
convert h
-- Porting note: no longer necessary
-- exact Submodule.liftQ_mkQ _ _ _
end
/-- The category of R-modules has kernels, given by the inclusion of the kernel submodule. -/
theorem hasKernels_moduleCat : HasKernels (ModuleCat R) :=
⟨fun f => HasLimit.mk ⟨_, kernelIsLimit f⟩⟩
/-- The category of R-modules has cokernels, given by the projection onto the quotient. -/
theorem hasCokernels_moduleCat : HasCokernels (ModuleCat R) :=
⟨fun f => HasColimit.mk ⟨_, cokernelIsColimit f⟩⟩
open ModuleCat
attribute [local instance] hasKernels_moduleCat
attribute [local instance] hasCokernels_moduleCat
variable {G H : ModuleCat.{v} R} (f : G ⟶ H)
/-- The categorical kernel of a morphism in `ModuleCat`
agrees with the usual module-theoretical kernel.
-/
noncomputable def kernelIsoKer {G H : ModuleCat.{v} R} (f : G ⟶ H) :
-- Porting note (#11036): broken dot notation
kernel f ≅ ModuleCat.of R (LinearMap.ker f) :=
limit.isoLimitCone ⟨_, kernelIsLimit f⟩
-- We now show this isomorphism commutes with the inclusion of the kernel into the source.
@[simp, elementwise]
-- Porting note (#11036): broken dot notation
theorem kernelIsoKer_inv_kernel_ι : (kernelIsoKer f).inv ≫ kernel.ι f =
(LinearMap.ker f).subtype :=
limit.isoLimitCone_inv_π _ _
@[simp, elementwise]
theorem kernelIsoKer_hom_ker_subtype :
-- Porting note (#11036): broken dot notation
(kernelIsoKer f).hom ≫ (LinearMap.ker f).subtype = kernel.ι f :=
IsLimit.conePointUniqueUpToIso_inv_comp _ (limit.isLimit _) WalkingParallelPair.zero
/-- The categorical cokernel of a morphism in `ModuleCat`
agrees with the usual module-theoretical quotient.
-/
noncomputable def cokernelIsoRangeQuotient {G H : ModuleCat.{v} R} (f : G ⟶ H) :
-- Porting note (#11036): broken dot notation
cokernel f ≅ ModuleCat.of R (H ⧸ LinearMap.range f) :=
colimit.isoColimitCocone ⟨_, cokernelIsColimit f⟩
-- We now show this isomorphism commutes with the projection of target to the cokernel.
@[simp, elementwise]
theorem cokernel_π_cokernelIsoRangeQuotient_hom :
cokernel.π f ≫ (cokernelIsoRangeQuotient f).hom = f.range.mkQ :=
colimit.isoColimitCocone_ι_hom _ _
@[simp, elementwise]
theorem range_mkQ_cokernelIsoRangeQuotient_inv :
↿f.range.mkQ ≫ (cokernelIsoRangeQuotient f).inv = cokernel.π f :=
colimit.isoColimitCocone_ι_inv ⟨_, cokernelIsColimit f⟩ WalkingParallelPair.one
theorem cokernel_π_ext {M N : ModuleCat.{u} R} (f : M ⟶ N) {x y : N} (m : M) (w : x = y + f m) :
cokernel.π f x = cokernel.π f y := by
subst w
simpa only [map_add, add_right_eq_self] using cokernel.condition_apply f m
end ModuleCat
|
Algebra\Category\ModuleCat\Limits.lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.Algebra.Category.Grp.Limits
import Mathlib.Algebra.DirectLimit
/-!
# 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) :=
{ AddGrp.sectionsAddSubgroup.{v, w}
(F ⋙ forget₂ (ModuleCat R) AddCommGrp.{w} ⋙
forget₂ AddCommGrp AddGrp.{w}) with
carrier := (F ⋙ forget (ModuleCat R)).sections
smul_mem' := fun r s sh j j' f => by
simp only [forget_map, Functor.comp_map, Pi.smul_apply, map_smul]
dsimp [Functor.sections] at sh
rw [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 (F ⋙ forget (ModuleCat R)).sections R, 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 := limitπLinearMap F
naturality := fun _ _ f =>
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 => ⟨⟨(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]
erw [← map_add (AddEquiv.symm Shrink.addEquiv)]
rfl
· intro r x
simp only [Types.Small.limitConeIsLimit_lift, Functor.mapCone_π_app, forget_map, map_smul]
erw [← map_smul (LinearEquiv.symm <| Shrink.linearEquiv _ _)]
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
-- Porting note: mathport translated this as `irreducible_def`, but as `HasLimitsOfSize`
-- is a `Prop`, declaring this as `irreducible` should presumably have no effect
/-- 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₂AddCommGroupPreservesLimitsAux :
IsLimit ((forget₂ (ModuleCat R) AddCommGrp).mapCone (limitCone F)) :=
letI : Small.{w} (Functor.sections ((F ⋙ forget₂ _ AddCommGrp) ⋙ forget _)) :=
inferInstanceAs <| Small.{w} (Functor.sections (F ⋙ forget (ModuleCat R)))
AddCommGrp.limitConeIsLimit
(F ⋙ forget₂ (ModuleCat.{w} R) _ : J ⥤ AddCommGrp.{w})
/-- The forgetful functor from R-modules to abelian groups preserves all limits. -/
instance forget₂AddCommGroupPreservesLimit :
PreservesLimit F (forget₂ (ModuleCat R) AddCommGrp) :=
preservesLimitOfPreservesLimitCone (limitConeIsLimit F)
(forget₂AddCommGroupPreservesLimitsAux F)
/-- The forgetful functor from R-modules to abelian groups preserves all limits.
-/
instance forget₂AddCommGroupPreservesLimitsOfSize [UnivLE.{v, w}] :
PreservesLimitsOfSize.{t, v}
(forget₂ (ModuleCat.{w} R) AddCommGrp.{w}) where
preservesLimitsOfShape := { preservesLimit := inferInstance }
instance forget₂AddCommGroupPreservesLimits :
PreservesLimits (forget₂ (ModuleCat R) AddCommGrp.{w}) :=
ModuleCat.forget₂AddCommGroupPreservesLimitsOfSize.{w, w}
/-- The forgetful functor from R-modules to types preserves all limits.
-/
instance forgetPreservesLimitsOfSize [UnivLE.{v, w}] :
PreservesLimitsOfSize.{t, v} (forget (ModuleCat.{w} R)) where
preservesLimitsOfShape :=
{ preservesLimit := fun {K} ↦ preservesLimitOfPreservesLimitCone (limitConeIsLimit K)
(Types.Small.limitConeIsLimit.{v} (_ ⋙ forget _)) }
instance forgetPreservesLimits : PreservesLimits (forget (ModuleCat.{w} R)) :=
ModuleCat.forgetPreservesLimitsOfSize.{w, w}
end
instance forget₂AddCommGroupReflectsLimit :
ReflectsLimit F (forget₂ (ModuleCat.{w} R) AddCommGrp) where
reflects {c} hc := by
have : HasLimit (F ⋙ forget₂ (ModuleCat R) AddCommGrp) := ⟨_, hc⟩
have : Small.{w} (Functor.sections (F ⋙ forget (ModuleCat R))) := by
simpa only [AddCommGrp.hasLimit_iff_small_sections] using this
have := reflectsLimitOfReflectsIsomorphisms F (forget₂ (ModuleCat R) AddCommGrp)
exact isLimitOfReflects _ hc
instance forget₂AddCommGroupReflectsLimitOfShape :
ReflectsLimitsOfShape J (forget₂ (ModuleCat.{w} R) AddCommGrp) where
instance forget₂AddCommGroupReflectsLimitOfSize :
ReflectsLimitsOfSize.{t, v} (forget₂ (ModuleCat.{w} R) AddCommGrp) where
section DirectLimit
open Module
variable {ι : Type v}
variable [dec_ι : 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 := f _ _ hij.le
map_id i := by
apply LinearMap.ext
intro x
apply Module.DirectedSystem.map_self
map_comp hij hjk := by
apply LinearMap.ext
intro x
symm
apply Module.DirectedSystem.map_map
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 := Module.DirectLimit.of R ι G f
naturality := fun _ _ hij => by
apply LinearMap.ext
intro x
exact DirectLimit.of_f }
/-- The unbundled `directLimit` of modules is a colimit
in the sense of `CategoryTheory`. -/
@[simps]
def directLimitIsColimit [IsDirected ι (· ≤ ·)] : IsColimit (directLimitCocone G f) where
desc s :=
DirectLimit.lift R ι G f s.ι.app fun i j h x => by
rw [← s.w (homOfLE h)]
rfl
fac s i := by
apply LinearMap.ext
intro x
dsimp only [directLimitCocone, CategoryStruct.comp]
rw [LinearMap.comp_apply]
apply DirectLimit.lift_of
uniq s m h := by
have :
s.ι.app = fun i =>
LinearMap.comp m (DirectLimit.of R ι (fun i => G i) (fun i j H => f i j H) i) := by
funext i
rw [← h]
rfl
apply LinearMap.ext
intro x
simp only [this]
apply Module.DirectLimit.lift_unique
end DirectLimit
end ModuleCat
|
Algebra\Category\ModuleCat\Presheaf.lean
|
/-
Copyright (c) 2023 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings
import Mathlib.Algebra.Category.Ring.Basic
/-!
# Presheaves of modules over a presheaf of rings.
We give a hands-on description of a presheaf of modules over a fixed presheaf of rings `R`,
as a presheaf of abelian groups with additional data.
We also provide two alternative constructors :
* When `M : CorePresheafOfModules R` consists of a family of unbundled modules over `R.obj X`
for all `X`, the corresponding presheaf of modules is `M.toPresheafOfModules`.
* When `M : BundledCorePresheafOfModules R` consists of a family of objects in
`ModuleCat (R.obj X)` for all `X`, the corresponding presheaf of modules
is `M.toPresheafOfModules`.
## Future work
* Compare this to the definition as a presheaf of pairs `(R, M)` with specified first part.
* Compare this to the definition as a module object of the presheaf of rings
thought of as a monoid object.
* (Pre)sheaves of modules over a given sheaf of rings are an abelian category.
* Presheaves of modules over a presheaf of commutative rings form a monoidal category.
* Pushforward and pullback.
-/
universe v v₁ u₁ u
open CategoryTheory LinearMap Opposite
variable {C : Type u₁} [Category.{v₁} C]
/-- A presheaf of modules over a given presheaf of rings,
described as a presheaf of abelian groups, and the extra data of the action at each object,
and a condition relating functoriality and scalar multiplication. -/
structure PresheafOfModules (R : Cᵒᵖ ⥤ RingCat.{u}) where
presheaf : Cᵒᵖ ⥤ AddCommGrp.{v}
module : ∀ X : Cᵒᵖ, Module (R.obj X) (presheaf.obj X) := by infer_instance
map_smul : ∀ {X Y : Cᵒᵖ} (f : X ⟶ Y) (r : R.obj X) (x : presheaf.obj X),
presheaf.map f (r • x) = R.map f r • presheaf.map f x := by aesop_cat
variable {R : Cᵒᵖ ⥤ RingCat.{u}}
namespace PresheafOfModules
attribute [instance] PresheafOfModules.module
/-- The bundled module over an object `X`. -/
def obj (P : PresheafOfModules R) (X : Cᵒᵖ) : ModuleCat (R.obj X) :=
ModuleCat.of _ (P.presheaf.obj X)
/--
If `P` is a presheaf of modules over a presheaf of rings `R`, both over some category `C`,
and `f : X ⟶ Y` is a morphism in `Cᵒᵖ`, we construct the `R.map f`-semilinear map
from the `R.obj X`-module `P.presheaf.obj X` to the `R.obj Y`-module `P.presheaf.obj Y`.
-/
def map (P : PresheafOfModules R) {X Y : Cᵒᵖ} (f : X ⟶ Y) :
P.obj X →ₛₗ[R.map f] P.obj Y :=
{ toAddHom := (P.presheaf.map f).toAddHom,
map_smul' := P.map_smul f, }
theorem map_apply (P : PresheafOfModules R) {X Y : Cᵒᵖ} (f : X ⟶ Y) (x) :
P.map f x = (P.presheaf.map f) x :=
rfl
instance (X : Cᵒᵖ) : RingHomId (R.map (𝟙 X)) where
eq_id := R.map_id X
instance {X Y Z : Cᵒᵖ} (f : X ⟶ Y) (g : Y ⟶ Z) :
RingHomCompTriple (R.map f) (R.map g) (R.map (f ≫ g)) where
comp_eq := (R.map_comp f g).symm
@[simp]
theorem map_id (P : PresheafOfModules R) (X : Cᵒᵖ) :
P.map (𝟙 X) = LinearMap.id' := by
ext
simp [map_apply]
@[simp]
theorem map_comp (P : PresheafOfModules R) {X Y Z : Cᵒᵖ} (f : X ⟶ Y) (g : Y ⟶ Z) :
P.map (f ≫ g) = (P.map g).comp (P.map f) := by
ext
simp [map_apply]
/-- A morphism of presheaves of modules. -/
structure Hom (P Q : PresheafOfModules R) where
hom : P.presheaf ⟶ Q.presheaf
map_smul : ∀ (X : Cᵒᵖ) (r : R.obj X) (x : P.presheaf.obj X), hom.app X (r • x) = r • hom.app X x
namespace Hom
/-- The identity morphism on a presheaf of modules. -/
def id (P : PresheafOfModules R) : Hom P P where
hom := 𝟙 _
map_smul _ _ _ := rfl
/-- Composition of morphisms of presheaves of modules. -/
def comp {P Q R : PresheafOfModules R} (f : Hom P Q) (g : Hom Q R) : Hom P R where
hom := f.hom ≫ g.hom
map_smul _ _ _ := by simp [Hom.map_smul]
end Hom
instance : Category (PresheafOfModules R) where
Hom := Hom
id := Hom.id
comp f g := Hom.comp f g
namespace Hom
variable {P Q T : PresheafOfModules R}
variable (P) in
@[simp]
lemma id_hom : Hom.hom (𝟙 P) = 𝟙 _ := rfl
@[simp, reassoc]
lemma comp_hom (f : P ⟶ Q) (g : Q ⟶ T) : (f ≫ g).hom = f.hom ≫ g.hom := rfl
/--
The `(X : Cᵒᵖ)`-component of morphism between presheaves of modules
over a presheaf of rings `R`, as an `R.obj X`-linear map. -/
def app (f : Hom P Q) (X : Cᵒᵖ) : P.obj X →ₗ[R.obj X] Q.obj X :=
{ toAddHom := (f.hom.app X).toAddHom
map_smul' := f.map_smul X }
@[simp]
lemma comp_app (f : P ⟶ Q) (g : Q ⟶ T) (X : Cᵒᵖ) :
(f ≫ g).app X = (g.app X).comp (f.app X) := rfl
@[ext]
theorem ext {f g : P ⟶ Q} (w : ∀ X, f.app X = g.app X) : f = g := by
cases f; cases g
congr
ext X x
exact LinearMap.congr_fun (w X) x
instance : Zero (P ⟶ Q) := ⟨mk 0 (by
intros
simp only [Limits.zero_app, AddMonoidHom.zero_apply, smul_zero])⟩
variable (P Q)
@[simp]
lemma zero_app (X : Cᵒᵖ) : (0 : P ⟶ Q).app X = 0 := rfl
variable {P Q}
instance : Add (P ⟶ Q) := ⟨fun f g => mk (f.hom + g.hom) (by
intros
simp only [NatTrans.app_add, AddCommGrp.hom_add_apply, map_smul, smul_add])⟩
@[simp]
lemma add_app (f g : P ⟶ Q) (X : Cᵒᵖ) : (f + g).app X = f.app X + g.app X := rfl
instance : Sub (P ⟶ Q) := ⟨fun f g => mk (f.hom - g.hom) (by
intros
rw [NatTrans.app_sub, AddMonoidHom.sub_apply, AddMonoidHom.sub_apply,
smul_sub, map_smul, map_smul])⟩
@[simp]
lemma sub_app (f g : P ⟶ Q) (X : Cᵒᵖ) : (f - g).app X = f.app X - g.app X := rfl
instance : Neg (P ⟶ Q) := ⟨fun f => mk (-f.hom) (by
intros
rw [NatTrans.app_neg, AddMonoidHom.neg_apply, AddMonoidHom.neg_apply,
map_smul, smul_neg])⟩
@[simp]
lemma neg_app (f : P ⟶ Q) (X : Cᵒᵖ) : (-f).app X = -f.app X := rfl
instance : AddCommGroup (P ⟶ Q) where
add_assoc := by intros; ext1; simp only [add_app, add_assoc]
zero_add := by intros; ext1; simp only [add_app, zero_app, zero_add]
add_left_neg := by intros; ext1; simp only [add_app, neg_app, add_left_neg, zero_app]
add_zero := by intros; ext1; simp only [add_app, zero_app, add_zero]
add_comm := by intros; ext1; simp only [add_app]; apply add_comm
sub_eq_add_neg := by intros; ext1; simp only [add_app, sub_app, neg_app, sub_eq_add_neg]
nsmul := nsmulRec
zsmul := zsmulRec
instance : Preadditive (PresheafOfModules R) where
add_comp := by intros; ext1; simp only [comp_app, add_app, comp_add]
comp_add := by intros; ext1; simp only [comp_app, add_app, add_comp]
end Hom
lemma naturality_apply {P Q : PresheafOfModules R} (f : P ⟶ Q)
{X Y : Cᵒᵖ} (g : X ⟶ Y) (x : P.obj X) :
f.app Y (P.map g x) = Q.map g (f.app X x) :=
congr_fun ((forget _).congr_map (f.hom.naturality g)) x
variable (R)
/-- The functor from presheaves of modules over a specified presheaf of rings,
to presheaves of abelian groups.
-/
@[simps obj]
def toPresheaf : PresheafOfModules.{v} R ⥤ (Cᵒᵖ ⥤ AddCommGrp.{v}) where
obj P := P.presheaf
map f := f.hom
variable {R}
@[simp]
lemma toPresheaf_map_app {P Q : PresheafOfModules R}
(f : P ⟶ Q) (X : Cᵒᵖ) :
((toPresheaf R).map f).app X = (f.app X).toAddMonoidHom := rfl
instance : (toPresheaf R).Additive where
instance : (toPresheaf R).Faithful where
map_injective {P Q} f g h := by
ext X x
have eq := congr_app h X
simp only [toPresheaf_obj, toPresheaf_map_app] at eq
simp only [← toAddMonoidHom_coe, eq]
variable (R)
/-- Evaluation on an object `X` gives a functor
`PresheafOfModules R ⥤ ModuleCat (R.obj X)`. -/
@[simps]
def evaluation (X : Cᵒᵖ) : PresheafOfModules.{v} R ⥤ ModuleCat (R.obj X) where
obj M := M.obj X
map f := f.app X
instance (X : Cᵒᵖ) : (evaluation R X).Additive where
variable {R}
/-- Given a presheaf of modules `M` on a category `C` and `f : X ⟶ Y` in `Cᵒᵖ`, this
is the restriction map `M.obj X ⟶ M.obj Y`, considered as a linear map to
the restriction of scalars of `M.obj Y`. -/
noncomputable def restrictionApp {X Y : Cᵒᵖ} (f : X ⟶ Y) (M : PresheafOfModules.{v} R) :
M.obj X ⟶ (ModuleCat.restrictScalars (R.map f)).obj (M.obj Y) :=
ModuleCat.semilinearMapAddEquiv (R.map f) _ _ (M.map f)
lemma restrictionApp_apply {X Y : Cᵒᵖ} (f : X ⟶ Y) (M : PresheafOfModules R) (x : M.obj X) :
restrictionApp f M x = M.map f x := by
rfl
variable (R)
/-- The restriction natural transformation on presheaves of modules, considered as linear maps
to restriction of scalars. -/
@[simps]
noncomputable def restriction {X Y : Cᵒᵖ} (f : X ⟶ Y) :
evaluation R X ⟶ evaluation R Y ⋙ ModuleCat.restrictScalars (R.map f) where
app := restrictionApp f
naturality := fun M N φ => by
ext x
exact (congr_hom (φ.hom.naturality f) x).symm
variable {R}
@[reassoc (attr := simp)]
lemma restrictionApp_naturality {X Y : Cᵒᵖ} (f : X ⟶ Y)
{M N : PresheafOfModules R} (φ : M ⟶ N) :
restrictionApp f M ≫ (ModuleCat.restrictScalars (R.map f)).map (Hom.app φ Y) =
ModuleCat.ofHom (Hom.app φ X) ≫ restrictionApp f N :=
((restriction R f).naturality φ).symm
attribute [local simp] restrictionApp_apply
lemma restrictionApp_id (M : PresheafOfModules R) (X : Cᵒᵖ) :
restrictionApp (𝟙 X) M =
(ModuleCat.restrictScalarsId' (R.map (𝟙 X)) (R.map_id X)).inv.app (M.obj X) := by aesop
lemma restrictionApp_comp (M : PresheafOfModules R) {X Y Z : Cᵒᵖ} (f : X ⟶ Y) (g : Y ⟶ Z) :
restrictionApp (f ≫ g) M =
restrictionApp f M ≫
(ModuleCat.restrictScalars (R.map f)).map (restrictionApp g M) ≫
(ModuleCat.restrictScalarsComp' _ _ _ (R.map_comp f g)).inv.app (M.obj Z) := by aesop
namespace Hom
variable {P Q : PresheafOfModules R} (app : ∀ X, P.obj X →ₗ[R.obj X] Q.obj X)
section
variable (naturality : ∀ ⦃X Y : Cᵒᵖ⦄ (f : X ⟶ Y) (x : P.obj X),
app Y (P.map f x) = Q.map f (app X x))
/-- A constructor for morphisms in `PresheafOfModules R` that is based on the data
of a family of linear maps over the various rings `R.obj X`. -/
def mk' : P ⟶ Q where
hom :=
{ app := fun X => (app X).toAddMonoidHom
naturality := fun X Y f => by ext x; apply naturality }
map_smul X := (app X).map_smul
@[simp]
lemma mk'_app : (mk' app naturality).app = app := rfl
end
/-- A constructor for morphisms in `PresheafOfModules R` that is based on the data
of a family of linear maps over the various rings `R.obj X`, and for which the
naturality condition is stated using the restriction of scalars. -/
abbrev mk''
(naturality : ∀ ⦃X Y : Cᵒᵖ⦄ (f : X ⟶ Y),
restrictionApp f P ≫ (ModuleCat.restrictScalars (R.map f)).map (app Y) =
ModuleCat.ofHom (app X) ≫ restrictionApp f Q) :
P ⟶ Q :=
mk' app (fun _ _ f x => congr_hom (naturality f) x)
end Hom
end PresheafOfModules
variable (R) in
/-- This structure contains the data and axioms in order to
produce a `PresheafOfModules R` from a collection of types
equipped with module structures over the various rings `R.obj X`.
(See the constructor `PresheafOfModules.mk'`.) -/
structure CorePresheafOfModules where
/-- the datum of a type for each object in `Cᵒᵖ` -/
obj (X : Cᵒᵖ) : Type v
/-- the abelian group structure on the types `obj X` -/
addCommGroup (X : Cᵒᵖ) : AddCommGroup (obj X) := by infer_instance
/-- the module structure on the types `obj X` over the various rings `R.obj X` -/
module (X : Cᵒᵖ) : Module (R.obj X) (obj X) := by infer_instance
/-- the semi-linear restriction maps -/
map {X Y : Cᵒᵖ} (f : X ⟶ Y) : obj X →ₛₗ[R.map f] obj Y
/-- `map` is compatible with the identities -/
map_id (X : Cᵒᵖ) (x : obj X) : map (𝟙 X) x = x := by aesop_cat
/-- `map` is compatible with the composition -/
map_comp {X Y Z : Cᵒᵖ} (f : X ⟶ Y) (g : Y ⟶ Z) (x : obj X) :
map (f ≫ g) x = map g (map f x) := by aesop_cat
-- this example is meant to test automation: the axioms for `CorePresheafOfModules` are
-- automatically found if we use the data from `M : PresheafOfModules R`
example (M : PresheafOfModules R) : CorePresheafOfModules R where
obj X := M.obj X
map f := M.map f
namespace CorePresheafOfModules
attribute [instance] addCommGroup module
attribute [simp] map_id map_comp
variable (M : CorePresheafOfModules R)
/-- The presheaf of abelian groups attached to a `CorePresheafOfModules R`. -/
@[simps]
def presheaf : Cᵒᵖ ⥤ AddCommGrp.{v} where
obj X := AddCommGrp.of (M.obj X)
map f := AddCommGrp.ofHom (M.map f).toAddMonoidHom
instance (X : Cᵒᵖ) : Module (R.obj X) (M.presheaf.obj X) := M.module X
/-- Constructor for `PresheafOfModules R` based on a collection of types
equipped with module structures over the various rings `R.obj X`, see
the structure `CorePresheafOfModules`. -/
def toPresheafOfModules : PresheafOfModules R where
presheaf := M.presheaf
@[simp]
lemma toPresheafOfModules_obj (X : Cᵒᵖ) :
M.toPresheafOfModules.obj X = ModuleCat.of _ (M.obj X) := rfl
@[simp]
lemma toPresheafOfModules_presheaf_map_apply {X Y : Cᵒᵖ} (f : X ⟶ Y) (x : M.obj X) :
M.toPresheafOfModules.presheaf.map f x = M.map f x := rfl
end CorePresheafOfModules
variable (R) in
/-- This structure contains the data and axioms in order to
produce a `PresheafOfModules R` from a collection of objects
of type `ModuleCat (R.obj X)` for all `X`, and restriction
maps expressed as linear maps to restriction of scalars.
(See the constructor `PresheafOfModules.mk''`.) -/
structure BundledCorePresheafOfModules where
/-- the datum of a `ModuleCat (R.obj X)` for each object in `Cᵒᵖ` -/
obj (X : Cᵒᵖ) : ModuleCat.{v} (R.obj X)
/-- the restriction maps as linear maps to restriction of scalars -/
map {X Y : Cᵒᵖ} (f : X ⟶ Y) : obj X ⟶ (ModuleCat.restrictScalars (R.map f)).obj (obj Y)
/-- `map` is compatible with the identities -/
map_id (X : Cᵒᵖ) :
map (𝟙 X) = (ModuleCat.restrictScalarsId' (R.map (𝟙 X)) (R.map_id X)).inv.app (obj X) := by
aesop
/-- `map` is compatible with the composition -/
map_comp {X Y Z : Cᵒᵖ} (f : X ⟶ Y) (g : Y ⟶ Z) :
map (f ≫ g) = map f ≫ (ModuleCat.restrictScalars (R.map f)).map (map g) ≫
(ModuleCat.restrictScalarsComp' (R.map f) (R.map g) (R.map (f ≫ g))
(R.map_comp f g)).inv.app (obj Z) := by aesop
namespace BundledCorePresheafOfModules
variable (M : BundledCorePresheafOfModules R)
attribute [local simp] map_id map_comp
/-- The obvious map `BundledCorePresheafOfModules R → CorePresheafOfModules R`. -/
noncomputable def toCorePresheafOfModules : CorePresheafOfModules R where
obj X := (M.obj X).carrier
map {X Y} f := (ModuleCat.semilinearMapAddEquiv (R.map f) (M.obj X) (M.obj Y)).symm (M.map f)
/-- Constructor for `PresheafOfModules R` based on a collection of objects
of type `ModuleCat (R.obj X)` for all `X`, and restriction maps expressed
as linear maps to restriction of scalars, see
the structure `BundledCorePresheafOfModules`. -/
noncomputable def toPresheafOfModules : PresheafOfModules R :=
M.toCorePresheafOfModules.toPresheafOfModules
@[simp]
lemma toPresheafOfModules_obj (X : Cᵒᵖ) :
M.toPresheafOfModules.obj X = (M.obj X).carrier := rfl
@[simp]
lemma toPresheafOfModules_presheaf_map_apply {X Y : Cᵒᵖ} (f : X ⟶ Y) (x : M.obj X) :
M.toPresheafOfModules.presheaf.map f x = M.map f x := rfl
@[simp]
lemma restrictionApp_toPresheafOfModules {X Y : Cᵒᵖ} (f : X ⟶ Y) :
PresheafOfModules.restrictionApp f M.toPresheafOfModules = M.map f := rfl
end BundledCorePresheafOfModules
namespace PresheafOfModules
variable (R)
/-- Auxiliary definition for `unit`. -/
def unitCore : CorePresheafOfModules R where
obj X := R.obj X
map {X Y} f := by
exact
{ toFun := (R.map f).toFun
map_add' := by simp
map_smul' := by simp }
/-- The obvious free presheaf of modules of rank `1`. -/
abbrev unit : PresheafOfModules R := (unitCore R).toPresheafOfModules
lemma unit_map_one {X Y : Cᵒᵖ} (f : X ⟶ Y) : (unit R).map f (1 : R.obj X) = (1 : R.obj Y) :=
(R.map f).map_one
variable {R}
/-- The type of sections of a presheaf of modules. -/
def sections (M : PresheafOfModules.{v} R) : Type _ := (M.presheaf ⋙ forget _).sections
@[simp]
lemma sections_property {M : PresheafOfModules.{v} R} (s : M.sections)
{X Y : Cᵒᵖ} (f : X ⟶ Y) : M.map f (s.1 X) = s.1 Y := s.2 f
/-- Constructor for sections of a presheaf of modules. -/
@[simps]
def sectionsMk {M : PresheafOfModules.{v} R} (s : ∀ X, M.obj X)
(hs : ∀ ⦃X Y : Cᵒᵖ⦄ (f : X ⟶ Y), M.map f (s X) = s Y) : M.sections where
val := s
property f := hs f
@[ext]
lemma sections_ext {M : PresheafOfModules.{v} R} (s t : M.sections)
(h : ∀ (X : Cᵒᵖ), s.val X = t.val X) : s = t :=
Subtype.ext (by ext; apply h)
/-- The map `M.sections → N.sections` induced by a morphisms `M ⟶ N` of presheaves of modules. -/
@[simps!]
def sectionsMap {M N : PresheafOfModules.{v} R} (f : M ⟶ N) (s : M.sections) : N.sections :=
N.sectionsMk (fun X ↦ f.app X (s.1 _))
(fun X Y g ↦ by rw [← naturality_apply, sections_property])
@[simp]
lemma sectionsMap_comp {M N P : PresheafOfModules.{v} R} (f : M ⟶ N) (g : N ⟶ P) (s : M.sections) :
sectionsMap (f ≫ g) s = sectionsMap g (sectionsMap f s) := rfl
@[simp]
lemma sectionsMap_id {M : PresheafOfModules.{v} R} (s : M.sections) :
sectionsMap (𝟙 M) s = s := rfl
/-- The bijection `(unit R ⟶ M) ≃ M.sections` for `M : PresheafOfModules R`. -/
@[simps! apply_coe]
def unitHomEquiv (M : PresheafOfModules R) :
(unit R ⟶ M) ≃ M.sections where
toFun f := sectionsMk (fun X ↦ Hom.app f X (1 : R.obj X))
(by intros; rw [← naturality_apply, unit_map_one])
invFun s := Hom.mk'
(fun X => (LinearMap.ringLmapEquivSelf (R.obj X) ℤ (M.obj X)).symm (s.val X)) (by
intro X Y p (x : R.obj X)
dsimp
rw [map_apply, M.map_smul, ← s.2 p]
rfl)
left_inv f := by
ext1 X
exact (LinearMap.ringLmapEquivSelf (R.obj X) ℤ (M.obj X)).symm_apply_apply (f.app X)
right_inv s := by
ext X
exact (LinearMap.ringLmapEquivSelf (R.obj X) ℤ (M.obj X)).apply_symm_apply (s.val X)
section module_over_initial
/-!
## `PresheafOfModules R ⥤ Cᵒᵖ ⥤ ModuleCat (R.obj X)` when `X` is initial
When `X` is initial, we have `Module (R.obj X) (M.obj c)` for any `c : Cᵒᵖ`.
-/
/--
Implementation of the functor `PresheafOfModules R ⥤ Cᵒᵖ ⥤ ModuleCat (R.obj X)`
when `X` is initial.
The functor is implemented as, on object level `M ↦ (c ↦ M(c))` where the `R(X)`-module structure
on `M(c)` is given by restriction of scalars along the unique morphism `R(c) ⟶ R(X)`; and on
morphism level `(f : M ⟶ N) ↦ (c ↦ f(c))`.
-/
@[simps]
noncomputable def forgetToPresheafModuleCatObj
(X : Cᵒᵖ) (hX : Limits.IsInitial X) (M : PresheafOfModules.{v} R) :
Cᵒᵖ ⥤ ModuleCat (R.1.obj X) where
obj c :=
ModuleCat.restrictScalars (R.1.map (hX.to c)) |>.obj <| M.obj c
map := fun {c₁ c₂} f =>
{ toFun := fun x => M.presheaf.map f x
map_add' := M.presheaf.map f |>.map_add
map_smul' := fun r (m : ModuleCat.restrictScalars _ |>.obj _) => by
simp only [ModuleCat.restrictScalars.smul_def, RingHom.id_apply, M.map_smul]
rw [← CategoryTheory.comp_apply, ← R.map_comp]
congr
apply hX.hom_ext }
map_id := fun c => by ext; simp_rw [M.presheaf.map_id]; rfl
map_comp := fun {c₁ c₂ c₃} f g => by
ext x; simp_rw [M.presheaf.map_comp]; rfl
/--
Implementation of the functor `PresheafOfModules R ⥤ Cᵒᵖ ⥤ ModuleCat (R.obj X)`
when `X` is initial.
The functor is implemented as, on object level `M ↦ (c ↦ M(c))` where the `R(X)`-module structure
on `M(c)` is given by restriction of scalars along the unique morphism `R(c) ⟶ R(X)`; and on
morphism level `(f : M ⟶ N) ↦ (c ↦ f(c))`.
-/
noncomputable def forgetToPresheafModuleCatMap
(X : Cᵒᵖ) (hX : Limits.IsInitial X) {M N : PresheafOfModules.{v} R}
(f : M ⟶ N) :
forgetToPresheafModuleCatObj X hX M ⟶
forgetToPresheafModuleCatObj X hX N :=
{ app := fun c =>
{ toFun := f.app c
map_add' := (f.app c).map_add
map_smul' := fun r (m : M.presheaf.obj c) => (f.app c).map_smul (R.1.map (hX.to c) _) m }
naturality := fun {c₁ c₂} i => by ext x; exact congr($(f.hom.naturality i) x) }
/--
The forgetful functor from presheaves of modules over a presheaf of rings `R` to presheaves of
`R(X)`-modules where `X` is an initial object.
The functor is implemented as, on object level `M ↦ (c ↦ M(c))` where the `R(X)`-module structure
on `M(c)` is given by restriction of scalars along the unique morphism `R(c) ⟶ R(X)`; and on
morphism level `(f : M ⟶ N) ↦ (c ↦ f(c))`.
-/
@[simps]
noncomputable def forgetToPresheafModuleCat (X : Cᵒᵖ) (hX : Limits.IsInitial X) :
PresheafOfModules.{v} R ⥤ Cᵒᵖ ⥤ ModuleCat (R.1.obj X) where
obj M := forgetToPresheafModuleCatObj X hX M
map f := forgetToPresheafModuleCatMap X hX f
end module_over_initial
end PresheafOfModules
|
Algebra\Category\ModuleCat\Products.lean
|
/-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.LinearAlgebra.Pi
import Mathlib.Tactic.CategoryTheory.Elementwise
/-!
# The concrete products in the category of modules are products in the categorical sense.
-/
open CategoryTheory
open CategoryTheory.Limits
universe u v w
namespace ModuleCat
variable {R : Type u} [Ring R]
variable {ι : Type v} (Z : ι → ModuleCatMax.{v, w} R)
/-- The product cone induced by the concrete product. -/
def productCone : Fan Z :=
Fan.mk (ModuleCat.of R (∀ i : ι, Z i)) fun i => (LinearMap.proj i : (∀ i : ι, Z i) →ₗ[R] Z i)
/-- The concrete product cone is limiting. -/
def productConeIsLimit : IsLimit (productCone Z) where
lift s := (LinearMap.pi fun j => s.π.app ⟨j⟩ : s.pt →ₗ[R] ∀ i : ι, Z i)
fac s j := by
cases j
aesop
uniq s m w := by
ext x
funext i
exact LinearMap.congr_fun (w ⟨i⟩) x
-- While we could use this to construct a `HasProducts (ModuleCat R)` instance,
-- we already have `HasLimits (ModuleCat R)` in `Algebra.Category.ModuleCat.Limits`.
variable [HasProduct Z]
/-- The categorical product of a family of objects in `ModuleCat`
agrees with the usual module-theoretical product.
-/
noncomputable def piIsoPi : ∏ᶜ Z ≅ ModuleCat.of R (∀ i, Z i) :=
limit.isoLimitCone ⟨_, productConeIsLimit Z⟩
-- We now show this isomorphism commutes with the inclusion of the kernel into the source.
@[simp, elementwise]
theorem piIsoPi_inv_kernel_ι (i : ι) :
(piIsoPi Z).inv ≫ Pi.π Z i = (LinearMap.proj i : (∀ i : ι, Z i) →ₗ[R] Z i) :=
limit.isoLimitCone_inv_π _ _
@[simp, elementwise]
theorem piIsoPi_hom_ker_subtype (i : ι) :
(piIsoPi Z).hom ≫ (LinearMap.proj i : (∀ i : ι, Z i) →ₗ[R] Z i) = Pi.π Z i :=
IsLimit.conePointUniqueUpToIso_inv_comp _ (limit.isLimit _) (Discrete.mk i)
end ModuleCat
|
Algebra\Category\ModuleCat\Projective.lean
|
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Scott Morrison
-/
import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Module.Projective
import Mathlib.CategoryTheory.Preadditive.Projective
import Mathlib.LinearAlgebra.FinsuppVectorSpace
import Mathlib.Data.Finsupp.Basic
/-!
# The category of `R`-modules has enough projectives.
-/
universe v u u'
open CategoryTheory
open CategoryTheory.Limits
open LinearMap
open ModuleCat
open scoped Module
/-- The categorical notion of projective object agrees with the explicit module-theoretic notion. -/
theorem IsProjective.iff_projective {R : Type u} [Ring R] {P : Type max u v} [AddCommGroup P]
[Module R P] : Module.Projective R P ↔ Projective (ModuleCat.of R P) := by
refine ⟨fun h => ?_, fun h => ?_⟩
· letI : Module.Projective R (ModuleCat.of R P) := h
exact ⟨fun E X epi => Module.projective_lifting_property _ _
((ModuleCat.epi_iff_surjective _).mp epi)⟩
· refine Module.Projective.of_lifting_property.{u,v} ?_
intro E X mE mX sE sX f g s
haveI : Epi (↟f) := (ModuleCat.epi_iff_surjective (↟f)).mpr s
letI : Projective (ModuleCat.of R P) := h
exact ⟨Projective.factorThru (↟g) (↟f), Projective.factorThru_comp (↟g) (↟f)⟩
namespace ModuleCat
variable {R : Type u} [Ring R] {M : ModuleCat.{max u v} R}
-- We transport the corresponding result from `Module.Projective`.
/-- Modules that have a basis are projective. -/
theorem projective_of_free {ι : Type u'} (b : Basis ι R M) : Projective M :=
Projective.of_iso (ModuleCat.ofSelfIso M)
(IsProjective.iff_projective.{v,u}.mp (Module.Projective.of_basis b))
/-- The category of modules has enough projectives, since every module is a quotient of a free
module. -/
instance moduleCat_enoughProjectives : EnoughProjectives (ModuleCat.{max u v} R) where
presentation M :=
⟨{ p := ModuleCat.of R (M →₀ R)
projective :=
projective_of_free.{v,u} (ι := M) (M := ModuleCat.of R (M →₀ R)) <|
Finsupp.basisSingleOne
f := Finsupp.basisSingleOne.constr ℕ _root_.id
epi := (epi_iff_range_eq_top _).mpr
(range_eq_top.2 fun m => ⟨Finsupp.single m (1 : R), by
-- Porting note: simp [Finsupp.total_single] fails but rw succeeds
dsimp [Basis.constr]
simp only [Finsupp.lmapDomain_id, comp_id]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [Finsupp.total_single]
rw [one_smul]
rfl ⟩) }⟩
end ModuleCat
|
Algebra\Category\ModuleCat\Sheaf.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Category.ModuleCat.Presheaf
import Mathlib.Algebra.Category.ModuleCat.Limits
import Mathlib.CategoryTheory.Sites.LocallyBijective
import Mathlib.CategoryTheory.Sites.Whiskering
/-!
# Sheaves of modules over a sheaf of rings
In this file, we define the category `SheafOfModules R` when `R : Sheaf J RingCat`
is a sheaf of rings on a category `C` equipped with a Grothendieck topology `J`.
## TODO
* construct the associated sheaf: more precisely, given a morphism of `α : P ⟶ R.val`
where `P` is a presheaf of rings and `R` a sheaf of rings such that `α` identifies
`R` to the associated sheaf of `P`, then construct a sheafification functor
`PresheafOfModules P ⥤ SheafOfModules R`.
-/
universe v v₁ u₁ u w
open CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] {J : GrothendieckTopology C}
(R : Sheaf J RingCat.{u})
/-- A sheaf of modules is a presheaf of modules such that the underlying presheaf
of abelian groups is a sheaf. -/
structure SheafOfModules where
/-- the underlying presheaf of modules of a sheaf of modules -/
val : PresheafOfModules.{v} R.val
isSheaf : Presheaf.IsSheaf J val.presheaf
namespace SheafOfModules
variable {R}
/-- A morphism between sheaves of modules is a morphism between the underlying
presheaves of modules. -/
@[ext]
structure Hom (X Y : SheafOfModules.{v} R) where
/-- a morphism between the underlying presheaves of modules -/
val : X.val ⟶ Y.val
instance : Category (SheafOfModules.{v} R) where
Hom := Hom
id _ := ⟨𝟙 _⟩
comp f g := ⟨f.val ≫ g.val⟩
@[ext]
lemma hom_ext {X Y : SheafOfModules.{v} R} {f g : X ⟶ Y} (h : f.val = g.val) : f = g :=
Hom.ext h
@[simp]
lemma id_val (X : SheafOfModules.{v} R) : Hom.val (𝟙 X) = 𝟙 X.val := rfl
@[simp, reassoc]
lemma comp_val {X Y Z : SheafOfModules.{v} R} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).val = f.val ≫ g.val := rfl
variable (R)
/-- The forgetful functor `SheafOfModules.{v} R ⥤ PresheafOfModules R.val`. -/
@[simps]
def forget : SheafOfModules.{v} R ⥤ PresheafOfModules R.val where
obj F := F.val
map φ := φ.val
/-- The forget functor `SheafOfModules R ⥤ PresheafOfModules R.val` is fully faithful. -/
@[simps]
def fullyFaithfulForget : (forget.{v} R).FullyFaithful where
preimage φ := ⟨φ⟩
instance : (forget.{v} R).Faithful := (fullyFaithfulForget R).faithful
instance : (forget.{v} R).Full := (fullyFaithfulForget R).full
instance : (forget.{v} R).ReflectsIsomorphisms := (fullyFaithfulForget R).reflectsIsomorphisms
/-- Evaluation on an object `X` gives a functor
`SheafOfModules R ⥤ ModuleCat (R.val.obj X)`. -/
def evaluation (X : Cᵒᵖ) : SheafOfModules.{v} R ⥤ ModuleCat.{v} (R.val.obj X) :=
forget _ ⋙ PresheafOfModules.evaluation _ X
/-- The forget functor `SheafOfModules R ⥤ Sheaf J AddCommGrp`. -/
@[simps]
def toSheaf : SheafOfModules.{v} R ⥤ Sheaf J AddCommGrp.{v} where
obj M := ⟨_, M.isSheaf⟩
map f := { val := f.val.hom }
/--
The forgetful functor from sheaves of modules over sheaf of ring `R` to sheaves of `R(X)`-module
when `X` is initial.
-/
@[simps]
noncomputable def forgetToSheafModuleCat
(X : Cᵒᵖ) (hX : Limits.IsInitial X) :
SheafOfModules.{w} R ⥤ Sheaf J (ModuleCat.{w} (R.1.obj X)) where
obj M := ⟨(PresheafOfModules.forgetToPresheafModuleCat X hX).obj M.1,
Presheaf.isSheaf_of_isSheaf_comp _ _
(forget₂ (ModuleCat.{w} (R.1.obj X)) AddCommGrp.{w}) M.isSheaf⟩
map f := { val := (PresheafOfModules.forgetToPresheafModuleCat X hX).map f.1 }
/-- The canonical isomorphism between
`SheafOfModules.toSheaf R ⋙ sheafToPresheaf J AddCommGrp.{v}`
and `SheafOfModules.forget R ⋙ PresheafOfModules.toPresheaf R.val`. -/
def toSheafCompSheafToPresheafIso :
toSheaf R ⋙ sheafToPresheaf J AddCommGrp.{v} ≅
forget R ⋙ PresheafOfModules.toPresheaf R.val := Iso.refl _
instance : (toSheaf.{v} R).Faithful :=
Functor.Faithful.of_comp_iso (toSheafCompSheafToPresheafIso.{v} R)
instance (M N : SheafOfModules.{v} R) : AddCommGroup (M ⟶ N) :=
(fullyFaithfulForget R).homEquiv.addCommGroup
@[simp]
lemma add_val {M N : SheafOfModules.{v} R} (f g : M ⟶ N) :
(f + g).val = f.val + g.val := rfl
instance : Preadditive (SheafOfModules.{v} R) where
add_comp := by intros; ext1; dsimp; simp only [Preadditive.add_comp]
comp_add := by intros; ext1; dsimp; simp only [Preadditive.comp_add]
instance : (forget R).Additive where
instance : (toSheaf R).Additive where
variable {R}
/-- The type of sections of a sheaf of modules. -/
abbrev sections (M : SheafOfModules.{v} R) : Type _ := M.val.sections
/-- The map `M.sections → N.sections` induced by a morphisms `M ⟶ N` of sheaves of modules. -/
abbrev sectionsMap {M N : SheafOfModules.{v} R} (f : M ⟶ N) (s : M.sections) : N.sections :=
PresheafOfModules.sectionsMap f.val s
@[simp]
lemma sectionsMap_comp {M N P : SheafOfModules.{v} R} (f : M ⟶ N) (g : N ⟶ P) (s : M.sections) :
sectionsMap (f ≫ g) s = sectionsMap g (sectionsMap f s) := rfl
@[simp]
lemma sectionsMap_id {M : SheafOfModules.{v} R} (s : M.sections) :
sectionsMap (𝟙 M) s = s := rfl
variable (R) in
/-- The functor which sends a sheaf of modules to its type of sections. -/
@[simps]
def sectionsFunctor : SheafOfModules.{v} R ⥤ Type _ where
obj := sections
map f := sectionsMap f
variable [J.HasSheafCompose (forget₂ RingCat.{u} AddCommGrp.{u})]
variable (R) in
/-- The obvious free sheaf of modules of rank `1`. -/
@[simps]
def unit : SheafOfModules R where
val := PresheafOfModules.unit R.val
isSheaf := ((sheafCompose J (forget₂ RingCat.{u} AddCommGrp.{u})).obj R).cond
/-- The bijection `(unit R ⟶ M) ≃ M.sections` for `M : SheafOfModules R`. -/
def unitHomEquiv (M : SheafOfModules R) :
(unit R ⟶ M) ≃ M.sections :=
(fullyFaithfulForget R).homEquiv.trans M.val.unitHomEquiv
@[simp]
lemma unitHomEquiv_apply_coe (M : SheafOfModules R) (f : unit R ⟶ M) (X : Cᵒᵖ) :
(M.unitHomEquiv f).val X = f.val.app X (1 : R.val.obj X) := rfl
lemma unitHomEquiv_comp_apply {M N : SheafOfModules.{u} R}
(f : unit R ⟶ M) (p : M ⟶ N) :
N.unitHomEquiv (f ≫ p) = sectionsMap p (M.unitHomEquiv f) := rfl
lemma unitHomEquiv_symm_comp {M N : SheafOfModules.{u} R} (s : M.sections) (p : M ⟶ N) :
M.unitHomEquiv.symm s ≫ p = N.unitHomEquiv.symm (sectionsMap p s) :=
N.unitHomEquiv.injective (by simp [unitHomEquiv_comp_apply])
end SheafOfModules
namespace PresheafOfModules
variable {R : Cᵒᵖ ⥤ RingCat.{u}} {M₁ M₂ : PresheafOfModules.{v} R}
(f : M₁ ⟶ M₂) {N : PresheafOfModules.{v} R}
(hN : Presheaf.IsSheaf J N.presheaf)
[J.WEqualsLocallyBijective AddCommGrp.{v}]
[Presheaf.IsLocallySurjective J f.hom]
[Presheaf.IsLocallyInjective J f.hom]
/-- The bijection `(M₂ ⟶ N) ≃ (M₁ ⟶ N)` induced by a locally bijective morphism
`f : M₁ ⟶ M₂` of presheaves of modules, when `N` is a sheaf. -/
@[simps]
noncomputable def homEquivOfIsLocallyBijective : (M₂ ⟶ N) ≃ (M₁ ⟶ N) where
toFun φ := f ≫ φ
invFun ψ :=
{ hom := ((J.W_of_isLocallyBijective f.hom).homEquiv _ hN).symm ψ.hom
map_smul := by
obtain ⟨φ, hφ⟩ := ((J.W_of_isLocallyBijective f.hom).homEquiv _ hN).surjective ψ.hom
simp only [← hφ, Equiv.symm_apply_apply]
dsimp at hφ
intro X r y
apply hN.isSeparated _ _ (Presheaf.imageSieve_mem J f.hom y)
rintro Y p ⟨x, hx⟩
have eq := ψ.map_smul _ (R.map p.op r) x
simp only [← hφ] at eq
dsimp at eq
erw [← NatTrans.naturality_apply φ p.op (r • y), N.map_smul, M₂.map_smul,
← NatTrans.naturality_apply φ p.op y, ← hx, ← eq, f.map_smul]
rfl }
left_inv φ := (toPresheaf _).map_injective
(((J.W_of_isLocallyBijective f.hom).homEquiv _ hN).left_inv φ.hom)
right_inv ψ := (toPresheaf _).map_injective
(((J.W_of_isLocallyBijective f.hom).homEquiv _ hN).right_inv ψ.hom)
end PresheafOfModules
|
Algebra\Category\ModuleCat\Simple.lean
|
/-
Copyright (c) 2022 Pierre-Alexandre Bazin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Pierre-Alexandre Bazin, Scott Morrison
-/
import Mathlib.CategoryTheory.Simple
import Mathlib.Algebra.Category.ModuleCat.Subobject
import Mathlib.Algebra.Category.ModuleCat.Algebra
import Mathlib.RingTheory.SimpleModule
import Mathlib.LinearAlgebra.FiniteDimensional
/-!
# Simple objects in the category of `R`-modules
We prove simple modules are exactly simple objects in the category of `R`-modules.
-/
variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M]
open CategoryTheory ModuleCat
theorem simple_iff_isSimpleModule : Simple (of R M) ↔ IsSimpleModule R M :=
(simple_iff_subobject_isSimpleOrder _).trans (subobjectModule (of R M)).isSimpleOrder_iff
theorem simple_iff_isSimpleModule' (M : ModuleCat R) : Simple M ↔ IsSimpleModule R M :=
(Simple.iff_of_iso (ofSelfIso M).symm).trans simple_iff_isSimpleModule
/-- A simple module is a simple object in the category of modules. -/
instance simple_of_isSimpleModule [IsSimpleModule R M] : Simple (of R M) :=
simple_iff_isSimpleModule.mpr ‹_›
/-- A simple object in the category of modules is a simple module. -/
instance isSimpleModule_of_simple (M : ModuleCat R) [Simple M] : IsSimpleModule R M :=
simple_iff_isSimpleModule.mp (Simple.of_iso (ofSelfIso M))
open FiniteDimensional
attribute [local instance] moduleOfAlgebraModule isScalarTower_of_algebra_moduleCat
/-- Any `k`-algebra module which is 1-dimensional over `k` is simple. -/
theorem simple_of_finrank_eq_one {k : Type*} [Field k] [Algebra k R] {V : ModuleCat R}
(h : finrank k V = 1) : Simple V :=
(simple_iff_isSimpleModule' V).mpr (is_simple_module_of_finrank_eq_one h)
|
Algebra\Category\ModuleCat\Subobject.lean
|
/-
Copyright (c) 2021 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Category.ModuleCat.Kernels
import Mathlib.CategoryTheory.Subobject.WellPowered
import Mathlib.CategoryTheory.Subobject.Limits
/-!
# Subobjects in the category of `R`-modules
We construct an explicit order isomorphism between the categorical subobjects of an `R`-module `M`
and its submodules. This immediately implies that the category of `R`-modules is well-powered.
-/
open CategoryTheory
open CategoryTheory.Subobject
open CategoryTheory.Limits
open ModuleCat
universe v u
namespace ModuleCat
variable {R : Type u} [Ring R] (M : ModuleCat.{v} R)
/-- The categorical subobjects of a module `M` are in one-to-one correspondence with its
submodules. -/
noncomputable def subobjectModule : Subobject M ≃o Submodule R M :=
OrderIso.symm
{ invFun := fun S => LinearMap.range S.arrow
toFun := fun N => Subobject.mk (↾N.subtype)
right_inv := fun S => Eq.symm (by
fapply eq_mk_of_comm
· apply LinearEquiv.toModuleIso'Left
apply LinearEquiv.ofBijective (LinearMap.codRestrict (LinearMap.range S.arrow) S.arrow _)
constructor
· simp [← LinearMap.ker_eq_bot, LinearMap.ker_codRestrict]
rw [ker_eq_bot_of_mono]
· rw [← LinearMap.range_eq_top, LinearMap.range_codRestrict, Submodule.comap_subtype_self]
exact LinearMap.mem_range_self _
· apply LinearMap.ext
intro x
rfl)
left_inv := fun N => by
-- Porting note: The type of `↾N.subtype` was ambiguous. Not entirely sure, I made the right
-- choice here
convert congr_arg LinearMap.range
(underlyingIso_arrow (↾N.subtype : of R { x // x ∈ N } ⟶ M)) using 1
· have :
-- Porting note: added the `.toLinearEquiv.toLinearMap`
(underlyingIso (↾N.subtype : of R _ ⟶ M)).inv =
(underlyingIso (↾N.subtype : of R _ ⟶ M)).symm.toLinearEquiv.toLinearMap := by
apply LinearMap.ext
intro x
rfl
rw [this, comp_def, LinearEquiv.range_comp]
· exact (Submodule.range_subtype _).symm
map_rel_iff' := fun {S T} => by
refine ⟨fun h => ?_, fun h => mk_le_mk_of_comm (↟(Submodule.inclusion h)) rfl⟩
convert LinearMap.range_comp_le_range (ofMkLEMk _ _ h) (↾T.subtype)
· simpa only [← comp_def, ofMkLEMk_comp] using (Submodule.range_subtype _).symm
· exact (Submodule.range_subtype _).symm }
instance wellPowered_moduleCat : WellPowered (ModuleCat.{v} R) :=
⟨fun M => ⟨⟨_, ⟨(subobjectModule M).toEquiv⟩⟩⟩⟩
attribute [local instance] hasKernels_moduleCat
/-- Bundle an element `m : M` such that `f m = 0` as a term of `kernelSubobject f`. -/
noncomputable def toKernelSubobject {M N : ModuleCat.{v} R} {f : M ⟶ N} :
LinearMap.ker f →ₗ[R] kernelSubobject f :=
(kernelSubobjectIso f ≪≫ ModuleCat.kernelIsoKer f).inv
@[simp]
theorem toKernelSubobject_arrow {M N : ModuleCat R} {f : M ⟶ N} (x : LinearMap.ker f) :
(kernelSubobject f).arrow (toKernelSubobject x) = x.1 := by
-- Porting note: The whole proof was just `simp [toKernelSubobject]`.
suffices ((arrow ((kernelSubobject f))) ∘ (kernelSubobjectIso f ≪≫ kernelIsoKer f).inv) x = x by
convert this
rw [Iso.trans_inv, ← coe_comp, Category.assoc]
simp only [Category.assoc, kernelSubobject_arrow', kernelIsoKer_inv_kernel_ι]
aesop_cat
/-- An extensionality lemma showing that two elements of a cokernel by an image
are equal if they differ by an element of the image.
The application is for homology:
two elements in homology are equal if they differ by a boundary.
-/
-- Porting note (#11215): TODO compiler complains that this is marked with `@[ext]`.
-- Should this be changed?
-- @[ext] this is no longer an ext lemma under the current interpretation see eg
-- the conversation beginning at
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/
-- Goal.20state.20not.20updating.2C.20bugs.2C.20etc.2E/near/338456803
theorem cokernel_π_imageSubobject_ext {L M N : ModuleCat.{v} R} (f : L ⟶ M) [HasImage f]
(g : (imageSubobject f : ModuleCat.{v} R) ⟶ N) [HasCokernel g] {x y : N} (l : L)
(w : x = y + g (factorThruImageSubobject f l)) : cokernel.π g x = cokernel.π g y := by
subst w
-- Porting note: The proof from here used to just be `simp`.
simp only [map_add, add_right_eq_self]
change ((cokernel.π g) ∘ (g) ∘ (factorThruImageSubobject f)) l = 0
rw [← coe_comp, ← coe_comp, Category.assoc]
simp only [cokernel.condition, comp_zero]
rfl
end ModuleCat
|
Algebra\Category\ModuleCat\Tannaka.lean
|
/-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.LinearAlgebra.Span
/-!
# Tannaka duality for rings
A ring `R` is equivalent to
the endomorphisms of the additive forgetful functor `Module R ⥤ AddCommGroup`.
-/
universe u
open CategoryTheory
/-- An ingredient of Tannaka duality for rings:
A ring `R` is equivalent to
the endomorphisms of the additive forgetful functor `Module R ⥤ AddCommGroup`.
-/
def ringEquivEndForget₂ (R : Type u) [Ring R] :
R ≃+* End (AdditiveFunctor.of (forget₂ (ModuleCat.{u} R) AddCommGrp.{u})) where
toFun r :=
{ app := fun M =>
@AddCommGrp.ofHom M.carrier M.carrier _ _ (DistribMulAction.toAddMonoidHom M r)
naturality := fun M N f => by
ext
exact (f.map_smul _ _).symm }
invFun φ := φ.app (ModuleCat.of R R) (1 : R)
left_inv := by
intro r
simp
right_inv := by
intro φ
apply NatTrans.ext
ext M (x : M)
have w := congr_fun ((forget _).congr_map
(φ.naturality (ModuleCat.asHomRight (LinearMap.toSpanSingleton R M x)))) (1 : R)
exact w.symm.trans (congr_arg (φ.app M) (one_smul R x))
map_add' := by
intros
apply NatTrans.ext
ext
dsimp
simp only [AddCommGrp.ofHom_apply, DistribMulAction.toAddMonoidHom_apply, add_smul]
rfl
map_mul' := by
intros
apply NatTrans.ext
ext
dsimp
simp only [AddCommGrp.ofHom_apply, DistribMulAction.toAddMonoidHom_apply, mul_smul]
rfl
|
Algebra\Category\ModuleCat\Differentials\Basic.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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`. -/
nonrec def Derivation : Type _ :=
letI := f.toAlgebra
letI := Module.compHom M f
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.toAlgebra
letI := Module.compHom M f
{ toFun := d
map_add' := d_add
map_smul' := fun a b ↦ by
dsimp
erw [d_mul, d_map, smul_zero, add_zero]
rfl
map_one_eq_zero' := by
dsimp
rw [← f.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.toAlgebra
letI := Module.compHom M f
_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.toAlgebra
letI := Module.compHom M f
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.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.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 (α - β) := by
rw [← KaehlerDifferential.span_range_derivation, Submodule.span_le]
rintro _ ⟨y, rfl⟩
rw [SetLike.mem_coe, LinearMap.mem_ker, LinearMap.sub_apply, sub_eq_zero]
apply h
rw [top_le_iff, LinearMap.ker_eq_top] at this
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').obj (KaehlerDifferential f') :=
letI := f.toAlgebra
letI := f'.toAlgebra
letI := g.toAlgebra
letI := g'.toAlgebra
letI := (g ≫ f').toAlgebra
have : IsScalarTower A A' B' := IsScalarTower.of_algebraMap_eq' rfl
have := IsScalarTower.of_algebraMap_eq' fac
{ 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
letI := f.toAlgebra
letI := f'.toAlgebra
letI := g.toAlgebra
letI := g'.toAlgebra
letI := (f'.comp g).toAlgebra
have : IsScalarTower A A' B' := IsScalarTower.of_algebraMap_eq' rfl
have := IsScalarTower.of_algebraMap_eq' 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.toAlgebra
letI := Module.compHom M f
D.liftKaehlerDifferential
@[simp]
lemma desc_d (b : B) : D.desc (CommRingCat.KaehlerDifferential.d b) = D.d b := by
letI := f.toAlgebra
letI := Module.compHom M f
apply D.liftKaehlerDifferential_comp_D
end ModuleCat.Derivation
|
Algebra\Category\ModuleCat\Differentials\Presheaf.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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 morphisms 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 functors 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 aesop_cat
d_map {X Y : Dᵒᵖ} (f : X ⟶ Y) (x : R.obj X) :
d (R.map f x) = M.map f (d x) := by aesop_cat
d_app {X : Cᵒᵖ} (a : S.obj X) : d (φ.app X a) = 0 := by aesop_cat
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 _).toAddMonoidHom.comp d.d
d_map _ _ := by simp [naturality_apply]
d_app {X} a := by
dsimp
erw [d_app, 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 absolyte 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 aesop_cat
postcomp_injective {M' : PresheafOfModules (R ⋙ forget₂ CommRingCat RingCat)}
(φ φ' : M ⟶ M') (h : d.postcomp φ = d.postcomp φ') : φ = φ' := by aesop_cat
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]
nonrec lemma d_app (d : M.Derivation' φ') {X : Dᵒᵖ} (a : S'.obj X) :
d.d (φ'.app X a) = 0 :=
d.d_app _
/-- 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))
(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))
/-- 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 : M.Derivation' φ' where
d {X} := AddMonoidHom.mk' (d X).d (by simp)
@[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
/-- Auxiliary definition for `relativeDifferentials'`. -/
noncomputable def relativeDifferentials'BundledCore :
BundledCorePresheafOfModules.{u} (R ⋙ forget₂ _ _) where
obj X := CommRingCat.KaehlerDifferential (φ'.app X)
map f := CommRingCat.KaehlerDifferential.map (φ'.naturality f)
/-- The presheaf of relative differentials of a morphism of presheaves of
commutative rings. -/
noncomputable def relativeDifferentials' :
PresheafOfModules.{u} (R ⋙ forget₂ _ _) :=
(relativeDifferentials'BundledCore φ').toPresheafOfModules
@[simp]
lemma relativeDifferentials'_obj (X : Dᵒᵖ) :
(relativeDifferentials' φ').obj X =
CommRingCat.KaehlerDifferential (φ'.app X) := rfl
-- Note: this cannot be a simp lemma because `dsimp` would
-- simplify the composition of functors `R ⋙ forget₂ _ _`
lemma relativeDifferentials'_map_apply {X Y : Dᵒᵖ} (f : X ⟶ Y)
(x : CommRingCat.KaehlerDifferential (φ'.app X)) :
(relativeDifferentials' φ').map f x =
CommRingCat.KaehlerDifferential.map (φ'.naturality f) x := rfl
lemma relativeDifferentials'_map_d {X Y : Dᵒᵖ} (f : X ⟶ Y)
(x : R.obj X) :
(relativeDifferentials' φ').map f (CommRingCat.KaehlerDifferential.d x) =
CommRingCat.KaehlerDifferential.d (R.map f x) := by
rw [relativeDifferentials'_map_apply, CommRingCat.KaehlerDifferential.map_d]
/-- The universal derivation. -/
noncomputable def derivation' : (relativeDifferentials' φ').Derivation' φ' :=
Derivation'.mk (fun X ↦ CommRingCat.KaehlerDifferential.D (φ'.app X)) (fun X Y f x ↦ by
rw [relativeDifferentials'_map_apply, CommRingCat.KaehlerDifferential.map_d])
/-- The derivation `Derivation' φ'` is universal. -/
noncomputable def isUniversal' : (derivation' φ').Universal :=
Derivation'.Universal.mk
(fun {M'} d' ↦ Hom.mk'' (fun X ↦ (d'.app X).desc) (fun X Y f ↦
CommRingCat.KaehlerDifferential.ext (fun b ↦ by
dsimp [ModuleCat.ofHom]
erw [restrictionApp_apply, restrictionApp_apply]
simp only [relativeDifferentials'_map_d, ModuleCat.Derivation.desc_d,
d'.app_apply, d'.d_map])))
(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
|
Algebra\Category\ModuleCat\Monoidal\Basic.lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Scott Morrison, Jakob von Raumer
-/
import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.LinearAlgebra.TensorProduct.Basic
import Mathlib.CategoryTheory.Monoidal.Linear
/-!
# 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.
-/
suppress_compilation
universe v w x u
open CategoryTheory
namespace ModuleCat
variable {R : Type u} [CommRing 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 : ModuleCat R) : ModuleCat R :=
ModuleCat.of R (M ⊗[R] N)
/-- (implementation) tensor product of morphisms R-modules -/
def tensorHom {M N M' N' : ModuleCat R} (f : M ⟶ N) (g : M' ⟶ N') :
tensorObj M M' ⟶ tensorObj N N' :=
TensorProduct.map f g
/-- (implementation) left whiskering for R-modules -/
def whiskerLeft (M : ModuleCat R) {N₁ N₂ : ModuleCat R} (f : N₁ ⟶ N₂) :
tensorObj M N₁ ⟶ tensorObj M N₂ :=
f.lTensor M
/-- (implementation) right whiskering for R-modules -/
def whiskerRight {M₁ M₂ : ModuleCat R} (f : M₁ ⟶ M₂) (N : ModuleCat R) :
tensorObj M₁ N ⟶ tensorObj M₂ N :=
f.rTensor N
theorem tensor_id (M N : ModuleCat R) : tensorHom (𝟙 M) (𝟙 N) = 𝟙 (ModuleCat.of R (M ⊗ N)) := by
-- Porting note (#11041): even with high priority `ext` fails to find this.
apply TensorProduct.ext
rfl
theorem tensor_comp {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : ModuleCat R} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁)
(g₂ : Y₂ ⟶ Z₂) : tensorHom (f₁ ≫ g₁) (f₂ ≫ g₂) = tensorHom f₁ f₂ ≫ tensorHom g₁ g₂ := by
-- Porting note (#11041): even with high priority `ext` fails to find this.
apply TensorProduct.ext
rfl
/-- (implementation) the associator for R-modules -/
def associator (M : ModuleCat.{v} R) (N : ModuleCat.{w} R) (K : ModuleCat.{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 : ModuleCat.{u} R) : ModuleCat.of R (R ⊗[R] M) ≅ M :=
(LinearEquiv.toModuleIso (TensorProduct.lid R M) : of R (R ⊗ M) ≅ of R M).trans (ofSelfIso M)
/-- (implementation) the right unitor for R-modules -/
def rightUnitor (M : ModuleCat.{u} R) : ModuleCat.of R (M ⊗[R] R) ≅ M :=
(LinearEquiv.toModuleIso (TensorProduct.rid R M) : of R (M ⊗ R) ≅ of R M).trans (ofSelfIso M)
@[simps (config := .lemmasOnly)]
instance instMonoidalCategoryStruct : MonoidalCategoryStruct (ModuleCat.{u} R) where
tensorObj := tensorObj
whiskerLeft := whiskerLeft
whiskerRight := whiskerRight
tensorHom f g := TensorProduct.map f g
tensorUnit := ModuleCat.of R R
associator := associator
leftUnitor := leftUnitor
rightUnitor := rightUnitor
section
/-! The `associator_naturality` and `pentagon` lemmas below are very slow to elaborate.
We give them some help by expressing the lemmas first non-categorically, then using
`convert _aux using 1` to have the elaborator work as little as possible. -/
open TensorProduct (assoc map)
private theorem associator_naturality_aux {X₁ X₂ X₃ : Type*} [AddCommMonoid X₁] [AddCommMonoid X₂]
[AddCommMonoid X₃] [Module R X₁] [Module R X₂] [Module R X₃] {Y₁ Y₂ Y₃ : Type*}
[AddCommMonoid Y₁] [AddCommMonoid Y₂] [AddCommMonoid Y₃] [Module R Y₁] [Module R Y₂]
[Module R Y₃] (f₁ : X₁ →ₗ[R] Y₁) (f₂ : X₂ →ₗ[R] Y₂) (f₃ : X₃ →ₗ[R] Y₃) :
↑(assoc R Y₁ Y₂ Y₃) ∘ₗ map (map f₁ f₂) f₃ = map f₁ (map f₂ f₃) ∘ₗ ↑(assoc R X₁ X₂ X₃) := by
apply TensorProduct.ext_threefold
intro x y z
rfl
variable (R)
private theorem pentagon_aux (W X Y Z : Type*) [AddCommMonoid W] [AddCommMonoid X]
[AddCommMonoid Y] [AddCommMonoid Z] [Module R W] [Module R X] [Module R Y] [Module R Z] :
(((assoc R X Y Z).toLinearMap.lTensor W).comp
(assoc R W (X ⊗[R] Y) Z).toLinearMap).comp
((assoc R W X Y).toLinearMap.rTensor Z) =
(assoc R W X (Y ⊗[R] Z)).toLinearMap.comp (assoc R (W ⊗[R] X) Y Z).toLinearMap := by
apply TensorProduct.ext_fourfold
intro w x y z
rfl
end
theorem associator_naturality {X₁ X₂ X₃ Y₁ Y₂ Y₃ : ModuleCat 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
convert associator_naturality_aux f₁ f₂ f₃ using 1
theorem pentagon (W X Y Z : ModuleCat 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
convert pentagon_aux R W X Y Z using 1
theorem leftUnitor_naturality {M N : ModuleCat R} (f : M ⟶ N) :
tensorHom (𝟙 (ModuleCat.of R R)) f ≫ (leftUnitor N).hom = (leftUnitor M).hom ≫ f := by
-- Porting note (#11041): broken ext
apply TensorProduct.ext
apply LinearMap.ext_ring
apply LinearMap.ext; intro x
-- Porting note (#10934): used to be dsimp
change ((leftUnitor N).hom) ((tensorHom (𝟙 (of R R)) f) ((1 : R) ⊗ₜ[R] x)) =
f (((leftUnitor M).hom) (1 ⊗ₜ[R] x))
erw [TensorProduct.lid_tmul, TensorProduct.lid_tmul]
rw [LinearMap.map_smul]
rfl
theorem rightUnitor_naturality {M N : ModuleCat R} (f : M ⟶ N) :
tensorHom f (𝟙 (ModuleCat.of R R)) ≫ (rightUnitor N).hom = (rightUnitor M).hom ≫ f := by
-- Porting note (#11041): broken ext
apply TensorProduct.ext
apply LinearMap.ext; intro x
apply LinearMap.ext_ring
-- Porting note (#10934): used to be dsimp
change ((rightUnitor N).hom) ((tensorHom f (𝟙 (of R R))) (x ⊗ₜ[R] (1 : R))) =
f (((rightUnitor M).hom) (x ⊗ₜ[R] 1))
erw [TensorProduct.rid_tmul, TensorProduct.rid_tmul]
rw [LinearMap.map_smul]
rfl
theorem triangle (M N : ModuleCat.{u} R) :
(associator M (ModuleCat.of R R) N).hom ≫ tensorHom (𝟙 M) (leftUnitor N).hom =
tensorHom (rightUnitor M).hom (𝟙 N) := by
apply TensorProduct.ext_threefold
intro x y z
change R at y
-- Porting note (#10934): used to be dsimp [tensorHom, associator]
change x ⊗ₜ[R] ((leftUnitor N).hom) (y ⊗ₜ[R] z) = ((rightUnitor M).hom) (x ⊗ₜ[R] y) ⊗ₜ[R] z
erw [TensorProduct.lid_tmul, TensorProduct.rid_tmul]
exact (TensorProduct.smul_tmul _ _ _).symm
end MonoidalCategory
open MonoidalCategory
instance monoidalCategory : MonoidalCategory (ModuleCat.{u} R) := MonoidalCategory.ofTensorHom
(tensor_id := fun M N ↦ tensor_id M N)
(tensor_comp := fun f g h ↦ MonoidalCategory.tensor_comp 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 ring. -/
instance : CommRing ((𝟙_ (ModuleCat.{u} R) : ModuleCat.{u} R) : Type u) :=
inferInstanceAs <| CommRing R
namespace MonoidalCategory
@[simp]
theorem hom_apply {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
end MonoidalCategory
open Opposite
-- Porting note: simp wasn't firing but rw was, annoying
instance : MonoidalPreadditive (ModuleCat.{u} R) := by
refine ⟨?_, ?_, ?_, ?_⟩
· dsimp only [autoParam]; intros
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂_apply, TensorProduct.mk_apply]
rw [LinearMap.zero_apply]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [MonoidalCategory.whiskerLeft_apply]
rw [LinearMap.zero_apply, TensorProduct.tmul_zero]
· dsimp only [autoParam]; intros
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂_apply, TensorProduct.mk_apply]
rw [LinearMap.zero_apply]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [MonoidalCategory.whiskerRight_apply]
rw [LinearMap.zero_apply, TensorProduct.zero_tmul]
· dsimp only [autoParam]; intros
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂_apply, TensorProduct.mk_apply]
rw [LinearMap.add_apply]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [MonoidalCategory.whiskerLeft_apply, MonoidalCategory.whiskerLeft_apply]
erw [MonoidalCategory.whiskerLeft_apply]
rw [LinearMap.add_apply, TensorProduct.tmul_add]
· dsimp only [autoParam]; intros
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂_apply, TensorProduct.mk_apply]
rw [LinearMap.add_apply]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [MonoidalCategory.whiskerRight_apply, MonoidalCategory.whiskerRight_apply]
erw [MonoidalCategory.whiskerRight_apply]
rw [LinearMap.add_apply, TensorProduct.add_tmul]
-- Porting note: simp wasn't firing but rw was, annoying
instance : MonoidalLinear R (ModuleCat.{u} R) := by
refine ⟨?_, ?_⟩
· dsimp only [autoParam]; intros
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂_apply, TensorProduct.mk_apply]
rw [LinearMap.smul_apply]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [MonoidalCategory.whiskerLeft_apply, MonoidalCategory.whiskerLeft_apply]
rw [LinearMap.smul_apply, TensorProduct.tmul_smul]
· dsimp only [autoParam]; intros
refine TensorProduct.ext (LinearMap.ext fun x => LinearMap.ext fun y => ?_)
simp only [LinearMap.compr₂_apply, TensorProduct.mk_apply]
rw [LinearMap.smul_apply]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [MonoidalCategory.whiskerRight_apply, MonoidalCategory.whiskerRight_apply]
rw [LinearMap.smul_apply, TensorProduct.smul_tmul, TensorProduct.tmul_smul]
end ModuleCat
|
Algebra\Category\ModuleCat\Monoidal\Closed.lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Scott Morrison, Jakob von Raumer
-/
import Mathlib.CategoryTheory.Closed.Monoidal
import Mathlib.CategoryTheory.Linear.Yoneda
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Symmetric
/-!
# The monoidal closed structure on `Module R`.
-/
suppress_compilation
universe v w x u
open CategoryTheory Opposite
namespace ModuleCat
variable {R : Type u} [CommRing R]
-- Porting note: removed @[simps] as the simpNF linter complains
/-- 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 := LinearMap.compr₂ (TensorProduct.mk R N M) ((β_ N M).hom ≫ f)
invFun f := (β_ M N).hom ≫ TensorProduct.lift f
left_inv f := by
apply TensorProduct.ext'
intro m n
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [coe_comp]
rw [Function.comp_apply]
-- This used to be `rw` and was longer (?), but we need `erw` after leanprover/lean4#2644
erw [MonoidalCategory.braiding_hom_apply, TensorProduct.lift.tmul]
right_inv f := rfl
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
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
-- Porting note: `CoeFun` was replaced by `DFunLike`
-- I can't seem to express the function coercion here without writing `@DFunLike.coe`.
theorem monoidalClosed_curry {M N P : ModuleCat.{u} R} (f : M ⊗ N ⟶ P) (x : M) (y : N) :
@DFunLike.coe _ _ _ LinearMap.instFunLike
((MonoidalClosed.curry f : N →ₗ[R] M →ₗ[R] P) y) 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) =
@DFunLike.coe _ _ _ LinearMap.instFunLike (f y) 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 = TensorProduct.uncurry _ _ _ _ LinearMap.id.flip := by
apply TensorProduct.ext'
apply ModuleCat.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 = (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 = LinearMap.lcomp R _ f :=
rfl
end ModuleCat
|
Algebra\Category\ModuleCat\Monoidal\Symmetric.lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Scott Morrison, Jakob von Raumer
-/
import Mathlib.CategoryTheory.Monoidal.Braided.Basic
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic
/-!
# The symmetric monoidal structure on `Module R`.
-/
suppress_compilation
universe v w x u
open CategoryTheory MonoidalCategory
namespace ModuleCat
variable {R : Type u} [CommRing R]
/-- (implementation) the braiding for R-modules -/
def braiding (M N : ModuleCat.{u} R) : M ⊗ N ≅ N ⊗ M :=
LinearEquiv.toModuleIso (TensorProduct.comm R M N)
namespace MonoidalCategory
@[simp]
theorem braiding_naturality {X₁ X₂ Y₁ Y₂ : ModuleCat.{u} R} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) :
(f ⊗ g) ≫ (Y₁.braiding Y₂).hom = (X₁.braiding X₂).hom ≫ (g ⊗ f) := by
apply TensorProduct.ext'
intro x y
rfl
@[simp]
theorem braiding_naturality_left {X Y : ModuleCat R} (f : X ⟶ Y) (Z : ModuleCat 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 : ModuleCat R) {Y Z : ModuleCat 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 : ModuleCat.{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
apply TensorProduct.ext_threefold
intro x y z
rfl
@[simp]
theorem hexagon_reverse (X Y Z : ModuleCat.{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
apply TensorProduct.ext_threefold
intro x y z
rfl
attribute [local ext] TensorProduct.ext
/-- The symmetric monoidal structure on `Module R`. -/
instance symmetricCategory : SymmetricCategory (ModuleCat.{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 `ModuleCat.ext` in favour of `TensorProduct.ext`.
symmetry _ _ := by
apply TensorProduct.ext'
aesop_cat
@[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) = (TensorProduct.tensorTensorTensorComm R A B C D).toLinearMap :=
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 MonoidalCategory
end ModuleCat
|
Algebra\Category\ModuleCat\Presheaf\Abelian.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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 : NormalEpiCategory (PresheafOfModules.{v} R) where
normalEpiOfEpi p _ := NormalEpi.mk _ (kernel.ι p) (kernel.condition _)
(evaluationJointlyReflectsColimits _ _ (fun _ =>
Abelian.isColimitMapCoconeOfCokernelCoforkOfπ _ _))
noncomputable instance : NormalMonoCategory (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
|
Algebra\Category\ModuleCat\Presheaf\ChangeOfRings.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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 restrictScalarsBundledCore (M' : PresheafOfModules R') (α : R ⟶ R') :
BundledCorePresheafOfModules R where
obj X := (ModuleCat.restrictScalars (α.app X)).obj (M'.obj X)
map {X Y} f :=
{ toFun := M'.map f
map_add' := map_add _
map_smul' := fun r x ↦ by
have eq := RingHom.congr_fun (α.naturality f) r
apply (M'.map_smul f (α.app _ r) x).trans
dsimp at eq ⊢
rw [← eq]
rfl }
map_id X := by
ext x
exact LinearMap.congr_fun (M'.map_id X) x
map_comp f g := by
ext x
exact LinearMap.congr_fun (M'.map_comp f g) x
/-- 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'.restrictScalarsBundledCore α).toPresheafOfModules
map {M₁' M₂'} φ :=
{ hom := φ.hom
map_smul := fun X r ↦ φ.map_smul X (α.app _ r) }
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)
end PresheafOfModules
|
Algebra\Category\ModuleCat\Presheaf\Colimits.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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))]
/-- 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 := Hom.mk'' (fun X => (hc X).desc ((evaluation R X).mapCocone s)) (fun X Y f => by
apply (hc X).hom_ext
intro j
erw [(hc X).fac_assoc ((evaluation R X).mapCocone s) j, ← restrictionApp_naturality_assoc]
rw [← Functor.map_comp]
erw [(hc Y).fac ((evaluation R Y).mapCocone s), restrictionApp_naturality]
rfl)
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))) :=
⟨_, isColimitOfPreserves (ModuleCat.restrictScalars (R.map f))
(colimit.isColimit (F ⋙ evaluation R Y))⟩
/-- Given `F : J ⥤ PresheafOfModules.{v} R`, this is the `BundledCorePresheafOfModules R` which
corresponds to the presheaf of modules which sends `X` to the colimit of `F ⋙ evaluation R X`. -/
@[simps]
noncomputable def colimitBundledCore : BundledCorePresheafOfModules R where
obj X := colimit (F ⋙ evaluation R X)
map {X Y} f := colimMap (whiskerLeft F (restriction R f)) ≫
(preservesColimitIso (ModuleCat.restrictScalars (R.map f)) (F ⋙ evaluation R Y)).inv
map_id X := colimit.hom_ext (fun j => by
dsimp
rw [ι_colimMap_assoc, whiskerLeft_app, restriction_app]
erw [ι_preservesColimitsIso_inv (G := ModuleCat.restrictScalars (R.map (𝟙 X))),
ModuleCat.restrictScalarsId'App_inv_naturality]
rw [restrictionApp_id]
rfl)
map_comp {X Y Z} f g := colimit.hom_ext (fun j => by
dsimp
rw [ι_colimMap_assoc, whiskerLeft_app, restriction_app, assoc, ι_colimMap_assoc]
erw [ι_preservesColimitsIso_inv (G := ModuleCat.restrictScalars (R.map (f ≫ g))),
ι_preservesColimitsIso_inv_assoc (G := ModuleCat.restrictScalars (R.map f))]
rw [← Functor.map_comp_assoc, ι_colimMap_assoc]
erw [ι_preservesColimitsIso_inv (G := ModuleCat.restrictScalars (R.map g))]
rw [restrictionApp_comp, ModuleCat.restrictScalarsComp'_inv_app, assoc, assoc,
whiskerLeft_app, whiskerLeft_app, restriction_app, restriction_app]
simp only [Functor.map_comp, assoc]
rfl)
/-- Given `F : J ⥤ PresheafOfModules.{v} R`, this is the canonical map
`F.obj j ⟶ (colimitBundledCore F).toPresheafOfModules` for all `j : J`. -/
noncomputable def colimitCoconeιApp (j : J) :
F.obj j ⟶ (colimitBundledCore F).toPresheafOfModules :=
PresheafOfModules.Hom.mk'' (fun X => colimit.ι (F ⋙ evaluation R X) j) (fun X Y f => by
dsimp
erw [colimit.ι_desc_assoc, assoc, ← ι_preservesColimitsIso_inv]
rfl)
@[reassoc (attr := simp)]
lemma colimitCoconeιApp_naturality {i j : J} (f : i ⟶ j) :
F.map f ≫ colimitCoconeιApp F j = colimitCoconeιApp F i := by
ext1 X
exact colimit.w (F ⋙ evaluation R X) f
/-- 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 := (colimitBundledCore F).toPresheafOfModules
ι := { app := colimitCoconeιApp 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⟩
noncomputable instance evaluationPreservesColimit (X : Cᵒᵖ) :
PreservesColimit F (evaluation R X) :=
preservesColimitOfPreservesColimitCocone (isColimitColimitCocone F) (colimit.isColimit _)
variable [∀ X, PreservesColimit F
(evaluation R X ⋙ forget₂ (ModuleCat (R.obj X)) AddCommGrp)]
noncomputable instance toPresheafPreservesColimit :
PreservesColimit F (toPresheaf R) :=
preservesColimitOfPreservesColimitCocone (isColimitColimitCocone F)
(Limits.evaluationJointlyReflectsColimits _
(fun X => isColimitOfPreserves (evaluation R X ⋙ forget₂ _ AddCommGrp)
(isColimitColimitCocone F)))
end Colimits
variable (R J)
section HasColimitsOfShape
variable [HasColimitsOfShape J AddCommGrp.{v}]
instance hasColimitsOfShape : HasColimitsOfShape J (PresheafOfModules.{v} R) where
noncomputable instance evaluationPreservesColimitsOfShape (X : Cᵒᵖ) :
PreservesColimitsOfShape J (evaluation R X : PresheafOfModules.{v} R ⥤ _) where
noncomputable instance toPresheafPreservesColimitsOfShape :
PreservesColimitsOfShape J (toPresheaf.{v} R) where
end HasColimitsOfShape
namespace Finite
instance hasFiniteColimits : HasFiniteColimits (PresheafOfModules.{v} R) :=
⟨fun _ => inferInstance⟩
noncomputable instance evaluationPreservesFiniteColimits (X : Cᵒᵖ) :
PreservesFiniteColimits (evaluation.{v} R X) where
noncomputable instance toPresheafPreservesFiniteColimits :
PreservesFiniteColimits (toPresheaf R) where
end Finite
end PresheafOfModules
|
Algebra\Category\ModuleCat\Presheaf\Limits.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Category.ModuleCat.Presheaf
import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings
import Mathlib.CategoryTheory.Limits.Preserves.Limits
import Mathlib.CategoryTheory.Limits.FunctorCategory
/-! # 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 := Hom.mk'' (fun X => (hc X).lift ((evaluation R X).mapCone s)) (fun X Y f => by
apply (isLimitOfPreserves (ModuleCat.restrictScalars (R.map f)) (hc Y)).hom_ext
intro j
rw [Functor.mapCone_π_app, assoc, assoc, ← Functor.map_comp]
erw [restrictionApp_naturality, IsLimit.fac, restrictionApp_naturality, IsLimit.fac_assoc]
rfl)
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]
rfl
instance {X Y : Cᵒᵖ} (f : X ⟶ Y) :
HasLimit (F ⋙ evaluation R Y ⋙ ModuleCat.restrictScalars (R.map f)) := by
change HasLimit ((F ⋙ evaluation R Y) ⋙ ModuleCat.restrictScalars (R.map f))
infer_instance
set_option backward.isDefEq.lazyWhnfCore false in -- See https://github.com/leanprover-community/mathlib4/issues/12534
/-- Given `F : J ⥤ PresheafOfModules.{v} R`, this is the `BundledCorePresheafOfModules R` which
corresponds to the presheaf of modules which sends `X` to the limit of `F ⋙ evaluation R X`. -/
@[simps]
noncomputable def limitBundledCore : BundledCorePresheafOfModules R where
obj X := limit (F ⋙ evaluation R X)
map {X Y} f := limMap (whiskerLeft F (restriction R f)) ≫
(preservesLimitIso (ModuleCat.restrictScalars (R.map f)) (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, whiskerLeft_app,
restriction_app, assoc]
erw [preservesLimitsIso_hom_π]
rw [← ModuleCat.restrictScalarsId'App_inv_naturality, restrictionApp_id]
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_π, whiskerLeft_app, restriction_app,
Functor.map_comp, assoc, restrictionApp_comp]
erw [preservesLimitsIso_hom_π, ← ModuleCat.restrictScalarsComp'App_inv_naturality]
dsimp
rw [← Functor.map_comp_assoc, ← Functor.map_comp_assoc, assoc,
preservesLimitsIso_inv_π]
erw [limMap_π]
dsimp
simp only [Functor.map_comp, assoc, preservesLimitsIso_inv_π_assoc]
erw [limMap_π_assoc]
dsimp
/-- Given `F : J ⥤ PresheafOfModules.{v} R`, this is the canonical map
`(limitBundledCore F).toPresheafOfModules ⟶ F.obj j` for all `j : J`. -/
noncomputable def limitConeπApp (j : J) :
(limitBundledCore F).toPresheafOfModules ⟶ F.obj j :=
PresheafOfModules.Hom.mk'' (fun X => limit.π (F ⋙ evaluation R X) j) (fun X Y f => by
dsimp
simp only [assoc, preservesLimitsIso_inv_π]
apply limMap_π)
@[reassoc (attr := simp)]
lemma limitConeπApp_naturality {i j : J} (f : i ⟶ j) :
limitConeπApp F i ≫ F.map f = limitConeπApp F j := by
ext1 X
exact limit.w (F ⋙ evaluation R X) f
/-- The (limit) cone for `F : J ⥤ PresheafOfModules.{v} R` that is constructed for the limit
of `F ⋙ evaluation R X` for all `X`. -/
@[simps]
noncomputable def limitCone : Cone F where
pt := (limitBundledCore F).toPresheafOfModules
π := { app := limitConeπApp F }
/-- 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 evaluationPreservesLimit (X : Cᵒᵖ) :
PreservesLimit F (evaluation R X) :=
preservesLimitOfPreservesLimitCone (isLimitLimitCone F) (limit.isLimit _)
noncomputable instance toPresheafPreservesLimit :
PreservesLimit F (toPresheaf R) :=
preservesLimitOfPreservesLimitCone (isLimitLimitCone F)
(Limits.evaluationJointlyReflectsLimits _
(fun X => isLimitOfPreserves (evaluation R X ⋙ forget₂ _ AddCommGrp)
(isLimitLimitCone F)))
end Limits
variable (R J)
section Small
variable [Small.{v} J]
instance hasLimitsOfShape : HasLimitsOfShape J (PresheafOfModules.{v} R) where
noncomputable instance evaluationPreservesLimitsOfShape (X : Cᵒᵖ) :
PreservesLimitsOfShape J (evaluation R X : PresheafOfModules.{v} R ⥤ _) where
noncomputable instance toPresheafPreservesLimitsOfShape :
PreservesLimitsOfShape J (toPresheaf.{v} R) where
end Small
section Finite
instance hasFiniteLimits : HasFiniteLimits (PresheafOfModules.{v} R) :=
⟨fun _ => inferInstance⟩
noncomputable instance evaluationPreservesFiniteLimits (X : Cᵒᵖ) :
PreservesFiniteLimits (evaluation.{v} R X) where
noncomputable instance toPresheafPreservesFiniteLimits :
PreservesFiniteLimits (toPresheaf.{v} R) where
end Finite
end PresheafOfModules
|
Algebra\Category\ModuleCat\Presheaf\Pushforward.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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`.
-/
universe v v₁ v₂ u₁ u₂ u
open CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
namespace PresheafOfModules
instance {R : Dᵒᵖ ⥤ RingCat.{u}} (P : PresheafOfModules.{v} R) (F : C ⥤ D) (X : Cᵒᵖ) :
Module ((F.op ⋙ R).obj X) ((F.op ⋙ P.presheaf).obj X) :=
inferInstanceAs (Module (R.obj (F.op.obj X)) (P.presheaf.obj (F.op.obj X)))
variable (F : C ⥤ D)
/-- 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 P :=
{ presheaf := F.op ⋙ P.presheaf
map_smul := by intros; apply P.map_smul }
map {P Q} φ :=
{ hom := whiskerLeft F.op φ.hom
map_smul := by intros; apply φ.map_smul }
/-- The pushforward of presheaves of modules commutes with the forgetful functor
to presheaves of abelian groups. -/
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)
/-- The pushforward functor `PresheafOfModules R ⥤ PresheafOfModules S` induced by
a morphism of presheaves of rings `S ⟶ F.op ⋙ R`. -/
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 _
-- unfortunately, `pushforward_obj_obj` and `pushforward_obj_map` cannot be both simp lemmas
lemma pushforward_obj_obj (M : PresheafOfModules.{v} R) (X : Cᵒᵖ) :
((pushforward φ).obj M).obj X =
(ModuleCat.restrictScalars (φ.app X)).obj (M.obj (Opposite.op (F.obj X.unop))) := rfl
@[simp]
lemma pushforward_obj_map_apply (M : PresheafOfModules.{v} R) {X Y : Cᵒᵖ} (f : X ⟶ Y)
(m : (ModuleCat.restrictScalars (φ.app X)).obj (M.obj (Opposite.op (F.obj X.unop)))) :
((pushforward φ).obj M).map f m = M.map (F.map f.unop).op m := by
rfl
@[simp]
lemma pushforward_map_app_apply {M N : PresheafOfModules.{v} R} (α : M ⟶ N) (X : Cᵒᵖ)
(m : (ModuleCat.restrictScalars (φ.app X)).obj (M.obj (Opposite.op (F.obj X.unop)))) :
((pushforward φ).map α).app X m = α.app (Opposite.op (F.obj X.unop)) m := by
rfl
end PresheafOfModules
|
Algebra\Category\ModuleCat\Presheaf\Sheafification.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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
/-!
# 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 AddCommGrp.{v}]
namespace PresheafOfModules
section
variable [HasWeakSheafify J AddCommGrp.{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! (config := .lemmasOnly) map]
noncomputable def sheafification : PresheafOfModules.{v} R₀ ⥤ SheafOfModules.{v} R where
obj M₀ := sheafify α (CategoryTheory.toSheafify J M₀.presheaf)
map f := sheafifyMap _ _ _ f ((presheafToSheaf J AddCommGrp).map f.hom) (by simp)
map_id M₀ := by
ext1
apply (toPresheaf _).map_injective
simp [toPresheaf, sheafify]
map_comp _ _ := by
ext1
apply (toPresheaf _).map_injective
simp [toPresheaf, sheafify]
/-- 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 AddCommGrp :=
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 AddCommGrp ⋙ sheafToPresheaf J AddCommGrp :=
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 sheafificationHomEquiv_hom'
{P : PresheafOfModules.{v} R₀} {F : SheafOfModules.{v} R}
(f : (sheafification α).obj P ⟶ F) :
(sheafificationHomEquiv α f).hom =
CategoryTheory.toSheafify J P.presheaf ≫ f.val.hom := rfl
lemma sheafificationHomEquiv_hom
{P : PresheafOfModules.{v} R₀} {F : SheafOfModules.{v} R}
(f : (sheafification α).obj P ⟶ F) :
(sheafificationHomEquiv α f).hom =
(sheafificationAdjunction J AddCommGrp).homEquiv P.presheaf
((SheafOfModules.toSheaf _).obj F) ((SheafOfModules.toSheaf _).map f) := by
rw [sheafificationHomEquiv_hom', 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 AddCommGrp).homEquiv
P.presheaf ((SheafOfModules.toSheaf R).obj F)).symm g.hom) := by
obtain ⟨f, rfl⟩ := (sheafificationHomEquiv α).surjective g
apply ((sheafificationAdjunction J AddCommGrp).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 α`. -/
@[simps! (config := .lemmasOnly) homEquiv_apply]
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]
apply Adjunction.homEquiv_naturality_left_symm
homEquiv_naturality_right := fun {P₀ M N} f g ↦ by
apply (toPresheaf _).map_injective
dsimp [toPresheaf]
erw [sheafificationHomEquiv_hom, sheafificationHomEquiv_hom]
rw [Functor.map_comp]
apply Adjunction.homEquiv_naturality_right }
@[simp]
lemma sheafificationAdjunction_unit_app_hom (M₀ : PresheafOfModules.{v} R₀) :
((sheafificationAdjunction α).unit.app M₀).hom = CategoryTheory.toSheafify J M₀.presheaf := by
rfl
instance : (sheafification.{v} α).IsLeftAdjoint :=
(sheafificationAdjunction α).isLeftAdjoint
end
section
variable [HasSheafify J AddCommGrp.{v}]
noncomputable instance :
PreservesFiniteLimits (sheafification.{v} α ⋙ SheafOfModules.toSheaf.{v} R) :=
compPreservesFiniteLimits (toPresheaf.{v} R₀) (presheafToSheaf J AddCommGrp)
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} α) :=
preservesFiniteLimitsOfReflectsOfPreserves
(sheafification.{v} α) (SheafOfModules.toSheaf.{v} R)
end
end PresheafOfModules
|
Algebra\Category\ModuleCat\Presheaf\Sheafify.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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 application, 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
variable {C : Type u₁} [Category.{v₁} C] {J : GrothendieckTopology C}
namespace CategoryTheory
namespace Presieve.FamilyOfElements
attribute [local instance] ConcreteCategory.hasCoeToSort ConcreteCategory.instFunLike
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.presheaf.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ᵒᵖ ⥤ AddCommGrp.{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)
(hr₀ : (r₀.map (whiskerRight α (forget _))).IsAmalgamation r)
(hm₀ : (m₀.map (whiskerRight φ (forget _))).IsAmalgamation m)
lemma _root_.PresheafOfModules.Sheafify.app_eq_of_isLocallyInjective
{Y : C} (r₀ r₀' : R₀.obj (Opposite.op Y))
(m₀ m₀' : M₀.presheaf.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
erw [← NatTrans.naturality_apply, ← NatTrans.naturality_apply, 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₀.presheaf.obj (Opposite.op Y)) (m₀' : M₀.presheaf.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₀.presheaf.map g.op (r₀ • m₀)) = φ.app _ (r₀' • m₀') := by
rw [← PresheafOfModules.Sheafify.app_eq_of_isLocallyInjective α φ hA (R₀.map g.op r₀) r₀'
(M₀.presheaf.map g.op m₀) m₀', M₀.map_smul]
· rw [hr₀', R.map_comp, comp_apply, ← hr₀, NatTrans.naturality_apply]
· rw [hm₀', A.map_comp, AddCommGrp.coe_comp, Function.comp_apply, ← hm₀]
erw [NatTrans.naturality_apply]
rfl
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
dsimp [a₀]
rw [NatTrans.naturality_apply, ha₁, Functor.map_comp, 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, comp_apply]
rfl
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 AddCommGrp.{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
erw [← comp_apply, ← A.val.map_comp, ← NatTrans.naturality_apply, M₀.map_smul]
refine (ha _ hg).trans (app_eq_of_isLocallyInjective α φ A.isSeparated _ _ _ _ ?_ ?_)
· rw [NatTrans.naturality_apply, ha₀]
apply (hr₀ _ hg).symm.trans
dsimp
rw [Functor.map_comp, comp_apply]
· 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₀⟩⟩
erw [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₀]
erw [map_smul_eq α φ 1 m f.op 1 (by simp) m₀ hm₀, one_smul]
rfl
protected lemma zero_smul : smul α φ 0 m = 0 := by
apply A.isSeparated _ _ (Presheaf.imageSieve_mem J φ m)
rintro Y f ⟨m₀, hm₀⟩
erw [map_smul_eq α φ 0 m f.op 0 (by simp) m₀ hm₀, zero_smul, map_zero,
(A.val.map f.op).map_zero]
protected lemma smul_zero : smul α φ r 0 = 0 := by
apply A.isSeparated _ _ (Presheaf.imageSieve_mem J α r)
rintro Y f ⟨r₀, hr₀⟩
erw [(A.val.map f.op).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₀.presheaf.obj _, hm₀⟩⟩, ⟨m₀' : M₀.presheaf.obj _, hm₀'⟩⟩
erw [(A.val.map f.op).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 erw [map_add, map_add, hm₀, hm₀']; rfl),
smul_add, 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₀⟩, ⟨r₀' : R₀.obj _, hr₀'⟩⟩, ⟨m₀, hm₀⟩⟩
erw [(A.val.map f.op).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 [map_add, map_add, hr₀, hr₀'])
m₀ hm₀, add_smul, 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₀⟩, ⟨r₀' : R₀.obj _, hr₀'⟩⟩, ⟨m₀ : M₀.presheaf.obj _, hm₀⟩⟩
erw [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 α φ
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₀⟩, ⟨m₀, hm₀⟩⟩
erw [← comp_apply, ← Functor.map_comp,
map_smul_eq α φ r m (π ≫ f.op) r₀ (by rw [hr₀, Functor.map_comp, comp_apply]) m₀
(by erw [hm₀, Functor.map_comp, comp_apply]; rfl),
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 :=
{ presheaf := A.val
module := Sheafify.module α φ
map_smul := fun _ _ _ => by apply Sheafify.map_smul }
isSheaf := A.cond
/-- The canonical morphism from a presheaf of modules to its associated sheaf. -/
@[simps]
def toSheafify : M₀ ⟶ (restrictScalars α).obj (sheafify α φ).val where
hom := φ
map_smul X r₀ m₀ := by
simpa using (Sheafify.map_smul_eq α φ (α.app _ r₀) (φ.app _ m₀) (𝟙 _)
r₀ (by aesop) m₀ (by simp)).symm
instance : Presheaf.IsLocallyInjective J (toSheafify α φ).hom := by
dsimp; infer_instance
instance : Presheaf.IsLocallySurjective J (toSheafify α φ).hom := by
dsimp; infer_instance
variable [J.WEqualsLocallyBijective AddCommGrp.{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_sheafifyHomEquiv'_symm_hom {F : PresheafOfModules.{v} R.val}
(hF : Presheaf.IsSheaf J F.presheaf) (f : M₀ ⟶ (restrictScalars α).obj F) :
φ ≫ ((sheafifyHomEquiv' α φ hF).symm f).hom = f.hom :=
congr_arg Hom.hom ((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 AddCommGrp.{v}}
(φ' : M₀'.presheaf ⟶ A'.val)
[Presheaf.IsLocallyInjective J φ'] [Presheaf.IsLocallySurjective J φ']
(τ₀ : M₀ ⟶ M₀') (τ : A ⟶ A')
(fac : τ₀.hom ≫ φ' = φ ≫ τ.val)
/-- The morphism of sheaves of modules `sheafify α φ ⟶ sheafify α φ'`
induced by morphisms `τ₀ : M₀ ⟶ M₀'` and `τ : A ⟶ A'`
which satisfy `τ₀.hom ≫ φ' = φ ≫ τ.val`. -/
@[simps]
def sheafifyMap : sheafify α φ ⟶ sheafify α φ' where
val :=
{ hom := τ.val
map_smul := by
let f := (sheafifyHomEquiv' α φ (by exact A'.cond)).symm (τ₀ ≫ toSheafify α φ')
have eq : τ.val = f.hom := ((J.W_of_isLocallyBijective φ).homEquiv _ A'.cond).injective
(by
dsimp [f]
erw [comp_sheafifyHomEquiv'_symm_hom]
simp only [← fac, toSheafify_hom, Hom.comp_hom])
convert f.map_smul }
end
end PresheafOfModules
|
Algebra\Category\ModuleCat\Sheaf\Abelian.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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 AddCommGrp.{v}]`
and `J.WEqualsLocallyBijective AddCommGrp.{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 AddCommGrp.{v}]
[J.WEqualsLocallyBijective AddCommGrp.{v}]
noncomputable instance : Abelian (SheafOfModules.{v} R) := by
let adj := PresheafOfModules.sheafificationAdjunction (𝟙 R.val)
exact abelianOfAdjunction _ _ (asIso (adj.counit)) adj
end SheafOfModules
|
Algebra\Category\ModuleCat\Sheaf\ChangeOfRings.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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'} (hM₂ : Presheaf.IsSheaf J M₂.presheaf)
[Presheaf.IsLocallySurjective J α]
/-- The functor `PresheafOfModules.restrictScalars α` induces bijection on
morphisms if `α` is locally surjective and the target presheaf is a sheaf. -/
noncomputable def restrictHomEquivOfIsLocallySurjective :
(M₁ ⟶ M₂) ≃ ((restrictScalars α).obj M₁ ⟶ (restrictScalars α).obj M₂) where
toFun f := (restrictScalars α).map f
invFun g :=
{ hom := g.hom
map_smul := fun X r' m => by
apply hM₂.isSeparated _ _ (Presheaf.imageSieve_mem J α r')
rintro Y p ⟨r : R.obj _, hr⟩
erw [M₂.map_smul, ← NatTrans.naturality_apply g.hom p.op m,
← hr, ← g.map_smul _ r (M₁.presheaf.map p.op m),
← NatTrans.naturality_apply g.hom p.op (r' • m),
M₁.map_smul p.op r' m, ← hr]
rfl }
left_inv _ := rfl
right_inv _ := rfl
end PresheafOfModules
|
Algebra\Category\ModuleCat\Sheaf\Colimits.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafification
/-!
# Colimits in categories of sheaves of modules
In this file, we show that colimits of shape `J` exists 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 AddCommGrp.{v}]
[J.WEqualsLocallyBijective AddCommGrp.{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) :=
isoWhiskerLeft F (asIso (PresheafOfModules.sheafificationAdjunction (𝟙 R.val)).counit).symm
exact hasColimitOfIso e
end SheafOfModules
|
Algebra\Category\ModuleCat\Sheaf\Free.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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
`freeHomEquiv` 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 AddCommGrp.{u}] [J.WEqualsLocallyBijective AddCommGrp.{u}]
[J.HasSheafCompose (forget₂ RingCat.{u} AddCommGrp.{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 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 (Sigma.ι (fun (_ : I) ↦ unit R) i ≫ f)
invFun s := Sigma.desc (fun i ↦ M.unitHomEquiv.symm (s i))
left_inv s := Sigma.hom_ext _ _ (by simp)
right_inv f := by ext1 i; simp
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
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]
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 as a
presheaf of modules over itself). --/
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
|
Algebra\Category\ModuleCat\Sheaf\Generators.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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 AddCommGrp.{u}] [J.WEqualsLocallyBijective AddCommGrp.{u}]
[J.HasSheafCompose (forget₂ RingCat.{u} AddCommGrp.{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 epimorphisms 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
attribute [local instance] 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]
end GeneratingSections
variable [∀ (X : C), HasWeakSheafify (J.over X) AddCommGrp.{u}]
[∀ (X : C), (J.over X).WEqualsLocallyBijective AddCommGrp.{u}]
[∀ (X : C), (J.over X).HasSheafCompose (forget₂ RingCat AddCommGrp.{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
/-- A sheaf of modules is of finite type if locally, it is generated by finitely
many sections. -/
class IsFiniteType : Prop where
exists_localGeneratorsData :
∃ (σ : M.LocalGeneratorsData), ∀ (i : σ.I), Finite (σ.generators i).I
section
variable [h : M.IsFiniteType]
/-- A choice of local generators when `M` is a sheaf of modules of finite type. -/
noncomputable def localGeneratorsDataOfIsFiniteType : M.LocalGeneratorsData :=
h.exists_localGeneratorsData.choose
instance (i : M.localGeneratorsDataOfIsFiniteType.I) :
Finite (M.localGeneratorsDataOfIsFiniteType.generators i).I :=
h.exists_localGeneratorsData.choose_spec i
end
end SheafOfModules
|
Algebra\Category\ModuleCat\Sheaf\Limits.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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 AddCommGrp.{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 AddCommGrp.{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 AddCommGrp.{v}]
instance (X : Cᵒᵖ) : Small.{v} (((F ⋙ forget _) ⋙ PresheafOfModules.evaluation _ X) ⋙
CategoryTheory.forget _).sections := by
change Small.{v} ((F ⋙ evaluation R X) ⋙ CategoryTheory.forget _).sections
infer_instance
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 _ _) :=
compPreservesFiniteLimits (SheafOfModules.forget.{v} R) (PresheafOfModules.toPresheaf R.val)
noncomputable instance : PreservesFiniteLimits (SheafOfModules.toSheaf.{v} R) :=
preservesFiniteLimitsOfReflectsOfPreserves _ (sheafToPresheaf _ _)
end SheafOfModules
|
Algebra\Category\ModuleCat\Sheaf\PushforwardContinuous.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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
|
Algebra\Category\ModuleCat\Sheaf\Quasicoherent.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
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}
variable {R : Sheaf J RingCat.{u}}
namespace SheafOfModules
variable (M : SheafOfModules.{u} R)
section
variable [HasWeakSheafify J AddCommGrp.{u}] [J.WEqualsLocallyBijective AddCommGrp.{u}]
[J.HasSheafCompose (forget₂ RingCat.{u} AddCommGrp.{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 where
/-- generators -/
generators : M.GeneratingSections
/-- relations -/
relations : (kernel generators.π).GeneratingSections
end
variable [∀ X, (J.over X).HasSheafCompose (forget₂ RingCat.{u} AddCommGrp.{u})]
[∀ X, HasWeakSheafify (J.over X) AddCommGrp.{u}]
[∀ X, (J.over X).WEqualsLocallyBijective AddCommGrp.{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 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
variable {M}
/-- If `M` is quasicoherent, it is locally generated by sections. -/
@[simps]
def localGeneratorsData (q : M.QuasicoherentData) : M.LocalGeneratorsData where
I := q.I
X := q.X
coversTop := q.coversTop
generators i := (q.presentation i).generators
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 : Prop where
nonempty_quasicoherentData : Nonempty M.QuasicoherentData
/-- 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 : Prop where
exists_quasicoherentData :
∃ (σ : M.QuasicoherentData), ∀ (i : σ.I), (Finite (σ.presentation i).generators.I ∧
Finite (σ.presentation i).relations.I)
section
variable [h : M.IsFinitePresentation]
/-- A choice of local presentations when `M` is a sheaf of modules of finite presentation. -/
noncomputable def quasicoherentDataOfIsFinitePresentation : M.QuasicoherentData :=
h.exists_quasicoherentData.choose
instance (i : M.quasicoherentDataOfIsFinitePresentation.I) :
Finite (M.quasicoherentDataOfIsFinitePresentation.presentation i).generators.I :=
have : _ ∧ Finite (M.quasicoherentDataOfIsFinitePresentation.presentation i).relations.I :=
h.exists_quasicoherentData.choose_spec i
this.1
instance (i : M.quasicoherentDataOfIsFinitePresentation.I) :
Finite (M.quasicoherentDataOfIsFinitePresentation.presentation i).relations.I :=
have : _ ∧ Finite (M.quasicoherentDataOfIsFinitePresentation.presentation i).relations.I :=
h.exists_quasicoherentData.choose_spec i
this.2
end
instance [M.IsFinitePresentation] : M.IsFiniteType where
exists_localGeneratorsData :=
⟨M.quasicoherentDataOfIsFinitePresentation.localGeneratorsData,
by intro; dsimp; infer_instance⟩
end SheafOfModules
|
Algebra\Category\MonCat\Adjunctions.lean
|
/-
Copyright (c) 2021 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.Algebra.Category.Semigrp.Basic
import Mathlib.Algebra.Group.WithOne.Basic
import Mathlib.Algebra.FreeMonoid.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 := WithOne.map
map_id _ := WithOne.map_id
map_comp := WithOne.map_comp
@[to_additive]
instance hasForgetToSemigroup : HasForget₂ MonCat Semigrp where
forget₂ :=
{ obj := fun M => Semigrp.of M
map := MonoidHom.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 := fun S M => WithOne.lift.symm
homEquiv_naturality_left_symm := by
intro S T M f g
ext x
simp only [Equiv.symm_symm, adjoinOne_map, coe_comp]
simp_rw [WithOne.map]
cases x
· rfl
· simp
rfl }
/-- The free functor `Type u ⥤ MonCat` sending a type `X` to the free monoid on `X`. -/
def free : Type u ⥤ MonCat.{u} where
obj α := MonCat.of (FreeMonoid α)
map := FreeMonoid.map
map_id _ := FreeMonoid.hom_eq (fun _ => rfl)
map_comp _ _ := FreeMonoid.hom_eq (fun _ => rfl)
/-- The free-forgetful adjunction for monoids. -/
def adj : free ⊣ forget MonCat.{u} :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X G => FreeMonoid.lift.symm
homEquiv_naturality_left_symm := fun _ _ => FreeMonoid.hom_eq (fun _ => rfl) }
instance : (forget MonCat.{u}).IsRightAdjoint :=
⟨_, ⟨adj⟩⟩
end MonCat
|
Algebra\Category\MonCat\Basic.lean
|
/-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.ConcreteCategory.BundledHom
import Mathlib.Algebra.PUnitInstances.Algebra
import Mathlib.Algebra.Group.ULift
import Mathlib.CategoryTheory.Functor.ReflectsIso
import Mathlib.Algebra.Ring.Action.Group
/-!
# Category instances for `Monoid`, `AddMonoid`, `CommMonoid`, and `AddCommMmonoid`.
We introduce the bundled categories:
* `MonCat`
* `AddMonCat`
* `CommMonCat`
* `AddCommMonCat`
along with the relevant forgetful functors between them.
-/
universe u v
open CategoryTheory
/-- The category of monoids and monoid morphisms. -/
@[to_additive AddMonCat]
def MonCat : Type (u + 1) :=
Bundled Monoid
/-- The category of additive monoids and monoid morphisms. -/
add_decl_doc AddMonCat
namespace MonCat
/-- `MonoidHom` doesn't actually assume associativity. This alias is needed to make the category
theory machinery work. -/
@[to_additive]
abbrev AssocMonoidHom (M N : Type*) [Monoid M] [Monoid N] :=
MonoidHom M N
/-- `AddMonoidHom` doesn't actually assume associativity. This alias is needed to make
the category theory machinery work. -/
add_decl_doc AddMonCat.AssocAddMonoidHom
@[to_additive]
instance bundledHom : BundledHom AssocMonoidHom where
toFun {X Y} _ _ f := ⇑f
id _ := MonoidHom.id _
comp _ _ _ := MonoidHom.comp
deriving instance LargeCategory for MonCat
attribute [to_additive instAddMonCatLargeCategory] instMonCatLargeCategory
-- Porting note: https://github.com/leanprover-community/mathlib4/issues/5020
@[to_additive]
instance concreteCategory : ConcreteCategory MonCat :=
BundledHom.concreteCategory _
@[to_additive]
instance : CoeSort MonCat Type* where
coe X := X.α
@[to_additive]
instance (X : MonCat) : Monoid X := X.str
-- porting note (#10670): this instance was not necessary in mathlib
@[to_additive]
instance {X Y : MonCat} : CoeFun (X ⟶ Y) fun _ => X → Y where
coe (f : X →* Y) := f
@[to_additive]
instance instFunLike (X Y : MonCat) : FunLike (X ⟶ Y) X Y :=
inferInstanceAs <| FunLike (X →* Y) X Y
@[to_additive]
instance instMonoidHomClass (X Y : MonCat) : MonoidHomClass (X ⟶ Y) X Y :=
inferInstanceAs <| MonoidHomClass (X →* Y) X Y
@[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 :=
MonoidHom.ext w
/-- Construct a bundled `MonCat` from the underlying type and typeclass. -/
@[to_additive]
def of (M : Type u) [Monoid M] : MonCat :=
Bundled.of M
/-- Construct a bundled `AddMonCat` from the underlying type and typeclass. -/
add_decl_doc AddMonCat.of
-- Porting note: removed `@[simp]` here, as it makes it harder to tell when to apply
-- bundled or unbundled lemmas.
-- (This change seems dangerous!)
@[to_additive]
theorem coe_of (R : Type u) [Monoid R] : (MonCat.of R : Type u) = R := rfl
@[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)))⟩
/-- Typecheck a `MonoidHom` as a morphism in `MonCat`. -/
@[to_additive]
def ofHom {X Y : Type u} [Monoid X] [Monoid Y] (f : X →* Y) : of X ⟶ of Y := f
/-- Typecheck an `AddMonoidHom` as a morphism in `AddMonCat`. -/
add_decl_doc AddMonCat.ofHom
@[to_additive (attr := simp)]
lemma ofHom_apply {X Y : Type u} [Monoid X] [Monoid Y] (f : X →* Y) (x : X) :
(ofHom f) x = f x := rfl
---- Porting note: added to ease the port of `RepresentationTheory.Action.Basic`
@[to_additive]
instance (X Y : MonCat.{u}) : One (X ⟶ Y) := ⟨ofHom 1⟩
@[to_additive (attr := simp)]
lemma oneHom_apply (X Y : MonCat.{u}) (x : X) : (1 : X ⟶ Y) x = 1 := rfl
---- Porting note: added to ease the port of `RepresentationTheory.Action.Basic`
@[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
@[to_additive]
instance {G : Type*} [Group G] : Group (MonCat.of G) := by assumption
/-- Universe lift functor for monoids. -/
@[to_additive (attr := simps)
"Universe lift functor for additive monoids."]
def uliftFunctor : MonCat.{u} ⥤ MonCat.{max u v} where
obj X := MonCat.of (ULift.{v, u} X)
map {X Y} f := MonCat.ofHom <|
MulEquiv.ulift.symm.toMonoidHom.comp <| f.comp MulEquiv.ulift.toMonoidHom
map_id X := by rfl
map_comp {X Y Z} f g := by rfl
end MonCat
/-- The category of commutative monoids and monoid morphisms. -/
@[to_additive AddCommMonCat]
def CommMonCat : Type (u + 1) :=
Bundled CommMonoid
/-- The category of additive commutative monoids and monoid morphisms. -/
add_decl_doc AddCommMonCat
namespace CommMonCat
@[to_additive]
instance : BundledHom.ParentProjection @CommMonoid.toMonoid := ⟨⟩
deriving instance LargeCategory for CommMonCat
attribute [to_additive instAddCommMonCatLargeCategory] instCommMonCatLargeCategory
-- Porting note: https://github.com/leanprover-community/mathlib4/issues/5020
@[to_additive]
instance concreteCategory : ConcreteCategory CommMonCat := by
dsimp only [CommMonCat]
infer_instance
@[to_additive]
instance : CoeSort CommMonCat Type* where
coe X := X.α
@[to_additive]
instance (X : CommMonCat) : CommMonoid X := X.str
-- porting note (#10670): this instance was not necessary in mathlib
@[to_additive]
instance {X Y : CommMonCat} : CoeFun (X ⟶ Y) fun _ => X → Y where
coe (f : X →* Y) := f
@[to_additive]
instance instFunLike (X Y : CommMonCat) : FunLike (X ⟶ Y) X Y :=
show FunLike (X →* Y) X Y by infer_instance
@[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 :=
MonoidHom.ext w
/-- Construct a bundled `CommMonCat` from the underlying type and typeclass. -/
@[to_additive]
def of (M : Type u) [CommMonoid M] : CommMonCat :=
Bundled.of M
/-- Construct a bundled `AddCommMonCat` from the underlying type and typeclass. -/
add_decl_doc AddCommMonCat.of
@[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)⟩
-- Porting note: removed `@[simp]` here, as it makes it harder to tell when to apply
-- bundled or unbundled lemmas.
-- (This change seems dangerous!)
@[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 :=
BundledHom.forget₂ _ _
@[to_additive]
instance : Coe CommMonCat.{u} MonCat.{u} where coe := (forget₂ CommMonCat MonCat).obj
-- Porting note: this was added to make automation work (it already exists for MonCat)
/-- Typecheck a `MonoidHom` as a morphism in `CommMonCat`. -/
@[to_additive]
def ofHom {X Y : Type u} [CommMonoid X] [CommMonoid Y] (f : X →* Y) : of X ⟶ of Y := f
/-- Typecheck an `AddMonoidHom` as a morphism in `AddCommMonCat`. -/
add_decl_doc AddCommMonCat.ofHom
@[to_additive (attr := simp)]
lemma ofHom_apply {X Y : Type u} [CommMonoid X] [CommMonoid Y] (f : X →* Y) (x : X) :
(ofHom f) x = f x := rfl
/-- Universe lift functor for commutative monoids. -/
@[to_additive (attr := simps)
"Universe lift functor for additive commutative monoids."]
def uliftFunctor : CommMonCat.{u} ⥤ CommMonCat.{max u v} where
obj X := CommMonCat.of (ULift.{v, u} X)
map {X Y} f := CommMonCat.ofHom <|
MulEquiv.ulift.symm.toMonoidHom.comp <| f.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\nan `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\n`AddMonCat`."]
def monCatIsoToMulEquiv {X Y : MonCat} (i : X ≅ Y) : X ≃* Y :=
MonoidHom.toMulEquiv i.hom i.inv i.hom_inv_id i.inv_hom_id
/-- Build a `MulEquiv` from an isomorphism in the category `CommMonCat`. -/
@[to_additive "Build an `AddEquiv` from an isomorphism in the category\n`AddCommMonCat`."]
def commMonCatIsoToMulEquiv {X Y : CommMonCat} (i : X ≅ Y) : X ≃* Y :=
MonoidHom.toMulEquiv i.hom i.inv i.hom_inv_id i.inv_hom_id
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)
-- Again a problem that exists already creeps into other things leanprover/lean4#2644
-- this used to be `by aesop`; see next declaration
let e : X ≃* Y := MulEquiv.mk i.toEquiv (MonoidHom.map_mul (show MonoidHom X Y from f))
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 := MulEquiv.mk i.toEquiv
-- Porting FIXME: this would ideally be `by aesop`, as in `MonCat.forget_reflects_isos`
(MonoidHom.map_mul (show MonoidHom X Y from f))
exact e.toCommMonCatIso.isIso_hom
-- Porting note: this was added in order to ensure that `forget₂ CommMonCat MonCat`
-- automatically reflects isomorphisms
-- we could have used `CategoryTheory.ConcreteCategory.ReflectsIso` alternatively
@[to_additive]
instance CommMonCat.forget₂_full : (forget₂ CommMonCat MonCat).Full where
map_surjective f := ⟨f, rfl⟩
example : (forget₂ CommMonCat MonCat).ReflectsIsomorphisms := inferInstance
/-!
`@[simp]` lemmas for `MonoidHom.comp` and categorical identities.
-/
@[to_additive (attr := simp)] theorem MonoidHom.comp_id_monCat
{G : MonCat.{u}} {H : Type u} [Monoid H] (f : G →* H) : f.comp (𝟙 G) = f :=
Category.id_comp (MonCat.ofHom f)
@[to_additive (attr := simp)] theorem MonoidHom.id_monCat_comp
{G : Type u} [Monoid G] {H : MonCat.{u}} (f : G →* H) : MonoidHom.comp (𝟙 H) f = f :=
Category.comp_id (MonCat.ofHom f)
@[to_additive (attr := simp)] theorem MonoidHom.comp_id_commMonCat
{G : CommMonCat.{u}} {H : Type u} [CommMonoid H] (f : G →* H) : f.comp (𝟙 G) = f :=
Category.id_comp (CommMonCat.ofHom f)
@[to_additive (attr := simp)] theorem MonoidHom.id_commMonCat_comp
{G : Type u} [CommMonoid G] {H : CommMonCat.{u}} (f : G →* H) : MonoidHom.comp (𝟙 H) f = f :=
Category.comp_id (CommMonCat.ofHom f)
|
Algebra\Category\MonCat\Colimits.lean
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
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
```
-/
universe v
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} [SmallCategory 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 x' rx y 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 :=
⟨ColimitType F, by infer_instance⟩
/-- 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 where
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) x y
| one j => exact map_one (s.ι.app j)
| 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 where
toFun := descFun F s
map_one' := rfl
map_mul' x y := by
induction x using Quot.inductionOn
induction y using Quot.inductionOn
dsimp [descFun]
rw [← quot_mul]
simp only [descFunLift]
/-- 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 x
induction' x with j x x y hx hy
· change _ = s.ι.app j _
rw [← w j]
rfl
· rw [quot_one, map_one]
rfl
· rw [quot_mul, map_mul, hx, hy]
dsimp [descMorphism, DFunLike.coe, descFun]
simp only [← quot_mul, descFunLift]
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
|
Algebra\Category\MonCat\FilteredColimits.lean
|
/-
Copyright (c) 2021 Justus Springer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Justus Springer
-/
import Mathlib.Algebra.Category.MonCat.Limits
import Mathlib.CategoryTheory.Limits.Preserves.Filtered
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
import Mathlib.CategoryTheory.Limits.TypesFiltered
/-!
# 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 ⥤ MonCatMax.{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 :=
Types.Quot (F ⋙ forget MonCat)
/-- 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 :=
Quot.mk _
@[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_quot_rel_of_rel (F ⋙ forget MonCat) x y h)
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
cases' x with j₁ x; cases' y with j₂ y; cases' x' with j₃ x'
obtain ⟨l, f, g, hfg⟩ := hxx'
simp? at hfg says simp only [Functor.comp_obj, Functor.comp_map, forget_map] at hfg
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, α, γ
dsimp
simp_rw [MonoidHom.map_mul]
-- Porting note: Lean cannot seem to use lemmas from concrete categories directly
change (F.map _ ≫ F.map _) _ * (F.map _ ≫ F.map _) _ =
(F.map _ ≫ F.map _) _ * (F.map _ ≫ F.map _) _
simp_rw [← F.map_comp, h₁, h₂, h₃, F.map_comp]
congr 1
change F.map _ (F.map _ _) = F.map _ (F.map _ _)
rw [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
cases' y with j₁ y; cases' x with j₂ x; cases' y' with j₃ 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]
-- Porting note: Lean cannot seem to use lemmas from concrete categories directly
change (F.map _ ≫ F.map _) _ * (F.map _ ≫ F.map _) _ =
(F.map _ ≫ F.map _) _ * (F.map _ ≫ F.map _) _
simp_rw [← F.map_comp, h₁, h₂, h₃, F.map_comp]
congr 1
change F.map _ (F.map _ _) = F.map _ (F.map _ _)
rw [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_quot_rel
exact h
· intro x x' y h
apply colimitMulAux_eq_of_rel_left
apply Types.FilteredColimit.rel_of_quot_rel
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
cases' x with j₁ x; cases' y with j₂ 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]
-- Porting note: Lean cannot seem to use lemmas from concrete categories directly
change (F.map _ ≫ F.map _) _ * (F.map _ ≫ F.map _) _ =
(F.map _ ≫ F.map _) _ * (F.map _ ≫ F.map _) _
simp_rw [← F.map_comp, h₁, h₂]
@[to_additive]
noncomputable instance colimitMulOneClass : MulOneClass (M.{v, u} F) :=
{ colimitOne F,
colimitMul F with
one_mul := fun x => by
refine Quot.inductionOn x ?_
intro x
cases' x with j x
rw [colimit_one_eq F j, colimit_mul_mk_eq F ⟨j, 1⟩ ⟨j, x⟩ j (𝟙 j) (𝟙 j), MonoidHom.map_one,
one_mul, F.map_id]
-- Porting note: `id_apply` does not work here, but the two sides are def-eq
rfl
mul_one := fun x => by
refine Quot.inductionOn x ?_
intro x
cases' x with j x
rw [colimit_one_eq F j, colimit_mul_mk_eq F ⟨j, x⟩ ⟨j, 1⟩ j (𝟙 j) (𝟙 j), MonoidHom.map_one,
mul_one, F.map_id]
-- Porting note: `id_apply` does not work here, but the two sides are def-eq
rfl }
@[to_additive]
noncomputable instance colimitMonoid : Monoid (M.{v, u} F) :=
{ colimitMulOneClass F with
mul_assoc := fun x y z => by
refine Quot.induction_on₃ x y z ?_
clear x y z
intro x y z
cases' x with j₁ x
cases' y with j₂ y
cases' z with j₃ z
change M.mk F _ * M.mk F _ * M.mk F _ = M.mk F _ * M.mk F _
dsimp
rw [colimit_mul_mk_eq F ⟨j₁, x⟩ ⟨j₂, y⟩ (IsFiltered.max j₁ (IsFiltered.max j₂ j₃))
(IsFiltered.leftToMax j₁ (IsFiltered.max j₂ j₃))
(IsFiltered.leftToMax j₂ j₃ ≫ IsFiltered.rightToMax _ _),
colimit_mul_mk_eq F ⟨(IsFiltered.max j₁ (IsFiltered.max j₂ j₃)), _⟩ ⟨j₃, z⟩
(IsFiltered.max j₁ (IsFiltered.max j₂ j₃)) (𝟙 _)
(IsFiltered.rightToMax j₂ j₃ ≫ IsFiltered.rightToMax _ _),
colimit_mul_mk_eq.{v, u} F ⟨j₁, x⟩ ⟨IsFiltered.max j₂ j₃, _⟩ _
(IsFiltered.leftToMax _ _) (IsFiltered.rightToMax _ _)]
congr 2
dsimp only
rw [F.map_id, show ∀ x, (𝟙 (F.obj (IsFiltered.max j₁ (IsFiltered.max j₂ j₃)))) x = x
from fun _ => rfl, mul_assoc, MonoidHom.map_mul, F.map_comp, F.map_comp]
rfl }
/-- 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."]
def coconeMorphism (j : J) : F.obj j ⟶ colimit F where
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
convert (colimit_mul_mk_eq F ⟨j, x⟩ ⟨j, y⟩ j (𝟙 j) (𝟙 j)).symm
rw [F.map_id]
rfl
@[to_additive (attr := simp)]
theorem cocone_naturality {j j' : J} (f : j ⟶ j') :
F.map f ≫ coconeMorphism.{v, u} F j' = coconeMorphism F j :=
MonoidHom.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."]
def colimitDesc (t : Cocone F) : colimit.{v, u} F ⟶ t.pt where
toFun := (Types.TypeMax.colimitCoconeIsColimit.{v, max v u, v} (F ⋙ forget MonCat)).desc
((forget MonCat).mapCocone t)
map_one' := by
rw [colimit_one_eq F IsFiltered.nonempty.some]
exact MonoidHom.map_one _
map_mul' x y := by
refine Quot.induction_on₂ x y ?_
clear x y
intro x y
cases' x with i x
cases' y with j y
rw [colimit_mul_mk_eq F ⟨i, x⟩ ⟨j, y⟩ (max' i j) (IsFiltered.leftToMax i j)
(IsFiltered.rightToMax i j)]
dsimp [Types.TypeMax.colimitCoconeIsColimit]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [MonoidHom.map_mul]
-- Porting note: `rw` can't see through coercion is actually forgetful functor,
-- so can't rewrite `t.w_apply`
congr 1 <;>
exact t.w_apply _ _
/-- The proposed colimit cocone is a colimit in `MonCat`. -/
@[to_additive "The proposed colimit cocone is a colimit in `AddMonCat`."]
def colimitCoconeIsColimit : IsColimit (colimitCocone.{v, u} F) where
desc := colimitDesc.{v, u} F
fac t j := MonoidHom.ext fun x => congr_fun ((Types.TypeMax.colimitCoconeIsColimit.{v, u}
(F ⋙ forget MonCat)).fac ((forget MonCat).mapCocone t) j) x
uniq t m h := MonoidHom.ext fun y => congr_fun
((Types.TypeMax.colimitCoconeIsColimit (F ⋙ forget MonCat)).uniq ((forget MonCat).mapCocone t)
((forget MonCat).map m)
fun j => funext fun x => DFunLike.congr_fun (i := MonCat.instFunLike _ _) (h j) x) y
@[to_additive]
noncomputable instance forgetPreservesFilteredColimits :
PreservesFilteredColimits (forget MonCat.{u}) :=
⟨fun J hJ1 _ => letI hJ1' : Category J := hJ1
⟨fun {F} => preservesColimitOfPreservesColimitCocone (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
refine Quot.induction_on₂ x y ?_
clear x y
intro x y
let k := max' x.1 y.1
let f := IsFiltered.leftToMax x.1 y.1
let g := IsFiltered.rightToMax x.1 y.1
rw [colimit_mul_mk_eq.{v, u} (F ⋙ forget₂ CommMonCat MonCat) x y k f g,
colimit_mul_mk_eq.{v, u} (F ⋙ forget₂ CommMonCat MonCat) y 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
ι := { (MonCat.FilteredColimits.colimitCocone.{v, u}
(F ⋙ forget₂ CommMonCat MonCat.{max v u})).ι with }
/-- The proposed colimit cocone is a colimit in `CommMonCat`. -/
@[to_additive "The proposed colimit cocone is a colimit in `AddCommMonCat`."]
def colimitCoconeIsColimit : IsColimit (colimitCocone.{v, u} F) where
desc t :=
MonCat.FilteredColimits.colimitDesc.{v, u} (F ⋙ forget₂ CommMonCat MonCat.{max v u})
((forget₂ CommMonCat MonCat.{max v u}).mapCocone t)
fac t j :=
DFunLike.coe_injective (i := CommMonCat.instFunLike _ _) <|
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget CommMonCat.{max v u})).fac
((forget CommMonCat).mapCocone t) j
uniq t m h :=
DFunLike.coe_injective (i := CommMonCat.instFunLike _ _) <|
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget CommMonCat.{max v u})).uniq
((forget CommMonCat.{max v u}).mapCocone t)
((forget CommMonCat.{max v u}).map m) fun j => funext fun x =>
DFunLike.congr_fun (i := CommMonCat.instFunLike _ _) (h j) x
@[to_additive forget₂AddMonPreservesFilteredColimits]
noncomputable instance forget₂MonPreservesFilteredColimits :
PreservesFilteredColimits (forget₂ CommMonCat MonCat.{u}) :=
⟨fun J hJ1 _ => letI hJ3 : Category J := hJ1
⟨fun {F} => preservesColimitOfPreservesColimitCocone (colimitCoconeIsColimit.{u, u} F)
(MonCat.FilteredColimits.colimitCoconeIsColimit (F ⋙ forget₂ CommMonCat MonCat.{u}))⟩⟩
@[to_additive]
noncomputable instance forgetPreservesFilteredColimits :
PreservesFilteredColimits (forget CommMonCat.{u}) :=
Limits.compPreservesFilteredColimits (forget₂ CommMonCat MonCat) (forget MonCat)
end
end CommMonCat.FilteredColimits
|
Algebra\Category\MonCat\Limits.lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.CategoryTheory.Limits.Creates
import Mathlib.CategoryTheory.Limits.Types
import Mathlib.Logic.Equiv.TransferInstance
/-!
# 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.
-/
noncomputable section
open CategoryTheory
open CategoryTheory.Limits
universe v u w
-- Porting note: typemax hack to fix universe complaints
/-- An alias for `MonCat.{max u v}`, to deal around unification issues. -/
@[to_additive (attr := nolint checkUnivs) AddMonCatMax
"An alias for `AddMonCat.{max u v}`, to deal around unification issues."]
abbrev MonCatMax.{u1, u2} := MonCat.{max u1 u2}
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, MonoidHom.map_mul, 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_π_app, ← Equiv.mulEquiv_apply, map_one]
rfl
map_mul' _ _ := by
simp only [Types.Small.limitCone_π_app, ← Equiv.mulEquiv_apply, map_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 := limitπMonoidHom F
naturality := fun _ _ f =>
DFunLike.coe_injective ((Types.Small.limitCone (F ⋙ forget _)).π.naturality f) } }
/-- 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 => { toFun := _, map_one' := ?_, map_mul' := ?_ }) (fun s => rfl)
· simp only [Functor.mapCone_π_app, forget_map, map_one]
rfl
· intro x y
simp only [Functor.mapCone_π_app, forget_map, map_mul]
erw [← map_mul (MulEquiv.symm Shrink.mulEquiv)]
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 "The category of additive monoids has all limits.",
to_additive_relevant_arg 2]
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}`\n
preserves limits of shape `J`."]
noncomputable instance forgetPreservesLimitsOfShape [Small.{u} J] :
PreservesLimitsOfShape J (forget MonCat.{u}) where
preservesLimit {F} := preservesLimitOfPreservesLimitCone (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
"The forgetful functor from additive monoids to types preserves all limits.\n\n
This means the underlying type of a limit can be computed as a limit in the category of types.",
to_additive_relevant_arg 2]
noncomputable instance forgetPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget MonCat.{u}) where
preservesLimitsOfShape := { }
@[to_additive]
noncomputable instance forgetPreservesLimits : PreservesLimits (forget MonCat.{u}) :=
MonCat.forgetPreservesLimitsOfSize.{u, u}
end MonCat
open MonCat
/-- An alias for `CommMonCat.{max u v}`, to deal around unification issues. -/
@[to_additive (attr := nolint checkUnivs) AddCommMonCatMax
"An alias for `AddCommMonCat.{max u v}`, to deal around unification issues."]
abbrev CommMonCatMax.{u1, u2} := CommMonCat.{max u1 u2}
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.\n\n
All we need to do is notice that the limit point has an `AddCommMonoid` instance available,\n
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 := MonCat.limitπMonoidHom (F ⋙ forget₂ CommMonCat.{u} MonCat.{u})
naturality :=
(MonCat.HasLimits.limitCone
(F ⋙ forget₂ CommMonCat MonCat.{u})).π.naturality } }
validLift := by apply IsLimit.uniqueUpToIso (MonCat.HasLimits.limitConeIsLimit _) t
makesLimit :=
IsLimit.ofFaithful (forget₂ CommMonCat MonCat.{u})
(MonCat.HasLimits.limitConeIsLimit _) (fun s => _) fun s => 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\n`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 "The category of additive commutative monoids has all limits.",
to_additive_relevant_arg 2]
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 AddCommMonCat.forget₂AddMonPreservesLimitsOfSize "The forgetful functor from
additive commutative monoids to additive monoids preserves all limits.\n\n
This means the underlying type of a limit can be computed as a limit in the category of additive\n
monoids.",
to_additive_relevant_arg 2]
noncomputable instance forget₂MonPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ CommMonCat.{u} MonCat.{u}) where
preservesLimitsOfShape {J} 𝒥 := { }
@[to_additive]
noncomputable instance forget₂MonPreservesLimits :
PreservesLimits (forget₂ CommMonCat.{u} MonCat.{u}) :=
CommMonCat.forget₂MonPreservesLimitsOfSize.{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}`\n
preserves limits of shape `J`."]
noncomputable instance forgetPreservesLimitsOfShape [Small.{u} J] :
PreservesLimitsOfShape J (forget CommMonCat.{u}) where
preservesLimit {F} := preservesLimitOfPreservesLimitCone (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\n
limits.\n\n
This means the underlying type of a limit can be computed as a limit in the category of types."]
noncomputable instance forgetPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{v, v} (forget CommMonCat.{u}) where
preservesLimitsOfShape {_} _ := { }
noncomputable instance _root_.AddCommMonCat.forgetPreservesLimits :
PreservesLimits (forget AddCommMonCat.{u}) :=
AddCommMonCat.forgetPreservesLimitsOfSize.{u, u}
@[to_additive existing]
noncomputable instance forgetPreservesLimits : PreservesLimits (forget CommMonCat.{u}) :=
CommMonCat.forgetPreservesLimitsOfSize.{u, u}
end CommMonCat
|
Algebra\Category\Ring\Adjunctions.lean
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johannes Hölzl
-/
import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.Algebra.MvPolynomial.CommRing
/-!
Multivariable polynomials on a type is the left adjoint of the
forgetful functor from commutative rings to types.
-/
noncomputable section
universe u
open MvPolynomial
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 := (↑(rename f : _ →ₐ[ℤ] _) : MvPolynomial X ℤ →+* MvPolynomial Y ℤ)
-- TODO these next two fields can be done by `tidy`, but the calls in `dsimp` and `simp` it
-- generates are too slow.
map_id _ := RingHom.ext <| rename_id
map_comp f g := RingHom.ext fun p => (rename_rename f g p).symm
@[simp]
theorem free_obj_coe {α : Type u} : (free.obj α : Type u) = MvPolynomial α ℤ :=
rfl
-- Porting note: `simpNF` should not trigger on `rfl` lemmas.
-- see https://github.com/leanprover/std4/issues/86
@[simp, nolint simpNF]
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 X R => homEquiv
homEquiv_naturality_left_symm := fun {_ _ Y} f g =>
RingHom.ext fun x => eval₂_cast_comp f (Int.castRingHom Y) g x }
instance : (forget CommRingCat.{u}).IsRightAdjoint :=
⟨_, ⟨adj⟩⟩
end CommRingCat
|
Algebra\Category\Ring\Basic.lean
|
/-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.CategoryTheory.ConcreteCategory.ReflectsIso
import Mathlib.Algebra.Ring.Equiv
/-!
# 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. -/
abbrev SemiRingCat : Type (u + 1) :=
Bundled Semiring
-- Porting note: typemax hack to fix universe complaints
/-- An alias for `Semiring.{max u v}`, to deal around unification issues. -/
@[nolint checkUnivs]
abbrev SemiRingCatMax.{u1, u2} := SemiRingCat.{max u1 u2}
namespace SemiRingCat
/-- `RingHom` doesn't actually assume associativity. This alias is needed to make the category
theory machinery work. We use the same trick in `MonCat.AssocMonoidHom`. -/
abbrev AssocRingHom (M N : Type*) [Semiring M] [Semiring N] :=
RingHom M N
instance bundledHom : BundledHom AssocRingHom where
toFun _ _ f := f
id _ := RingHom.id _
comp _ _ _ f g := f.comp g
-- Porting note: deriving fails for ConcreteCategory, adding instance manually.
--deriving instance LargeCategory, ConcreteCategory for SemiRingCat
-- see https://github.com/leanprover-community/mathlib4/issues/5020
-- Porting note: Hinting to Lean that `forget R` and `R` are the same
unif_hint forget_obj_eq_coe (R : SemiRingCat) where ⊢
(forget SemiRingCat).obj R ≟ R
instance instSemiring (X : SemiRingCat) : Semiring X := X.str
instance instFunLike {X Y : SemiRingCat} : FunLike (X ⟶ Y) X Y :=
ConcreteCategory.instFunLike
-- Porting note (#10754): added instance
instance instRingHomClass {X Y : SemiRingCat} : RingHomClass (X ⟶ Y) X Y :=
RingHom.instRingHomClass
lemma coe_id {X : SemiRingCat} : (𝟙 X : X → X) = id := rfl
lemma coe_comp {X Y Z : SemiRingCat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
@[simp] lemma forget_map {X Y : SemiRingCat} (f : X ⟶ Y) :
(forget SemiRingCat).map f = (f : X → Y) := rfl
lemma ext {X Y : SemiRingCat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g :=
RingHom.ext w
/-- Construct a bundled SemiRing from the underlying type and typeclass. -/
def of (R : Type u) [Semiring R] : SemiRingCat :=
Bundled.of R
@[simp]
theorem coe_of (R : Type u) [Semiring R] : (SemiRingCat.of R : Type u) = R :=
rfl
-- Coercing the identity morphism, as a ring homomorphism, gives the identity function.
@[simp] theorem coe_ringHom_id {X : SemiRingCat} :
@DFunLike.coe (X →+* X) X (fun _ ↦ X) _ (𝟙 X) = id :=
rfl
-- Coercing `𝟙 (of X)` to a function should be expressed as the coercion of `RingHom.id X`.
@[simp] theorem coe_id_of {X : Type u} [Semiring X] :
@DFunLike.coe no_index (SemiRingCat.of X ⟶ SemiRingCat.of X) X
(fun _ ↦ X) _
(𝟙 (of X)) =
@DFunLike.coe (X →+* X) X (fun _ ↦ X) _ (RingHom.id X) :=
rfl
-- Coercing `f ≫ g`, where `f : of X ⟶ of Y` and `g : of Y ⟶ of Z`, to a function should be
-- expressed in terms of the coercion of `g.comp f`.
@[simp] theorem coe_comp_of {X Y Z : Type u} [Semiring X] [Semiring Y] [Semiring Z]
(f : X →+* Y) (g : Y →+* Z) :
@DFunLike.coe no_index (SemiRingCat.of X ⟶ SemiRingCat.of Z) X
(fun _ ↦ Z) _
(CategoryStruct.comp (X := SemiRingCat.of X) (Y := SemiRingCat.of Y) (Z := SemiRingCat.of Z)
f g) =
@DFunLike.coe (X →+* Z) X (fun _ ↦ Z) _ (RingHom.comp g f) :=
rfl
-- Sometimes neither the `ext` lemma for `SemiRingCat` nor for `RingHom` is applicable,
-- because of incomplete unfolding of `SemiRingCat.of X ⟶ SemiRingCat.of Y := X →+* Y`,
-- but this one will fire.
@[ext] theorem ext_of {X Y : Type u} [Semiring X] [Semiring Y] (f g : X →+* Y)
(h : ∀ x, f x = g x) :
@Eq (SemiRingCat.of X ⟶ SemiRingCat.of Y) f g :=
RingHom.ext h
@[simp]
lemma RingEquiv_coe_eq {X Y : Type _} [Semiring X] [Semiring Y] (e : X ≃+* Y) :
(@DFunLike.coe (SemiRingCat.of X ⟶ SemiRingCat.of Y) _ (fun _ => (forget SemiRingCat).obj _)
ConcreteCategory.instFunLike (e : X →+* Y) : X → Y) = ↑e :=
rfl
instance : Inhabited SemiRingCat :=
⟨of PUnit⟩
instance hasForgetToMonCat : HasForget₂ SemiRingCat MonCat :=
BundledHom.mkHasForget₂
(fun R hR => @MonoidWithZero.toMonoid R (@Semiring.toMonoidWithZero R hR))
(fun {_ _} => RingHom.toMonoidHom)
(fun _ => rfl)
instance hasForgetToAddCommMonCat : HasForget₂ SemiRingCat AddCommMonCat where
-- can't use BundledHom.mkHasForget₂, since AddCommMon is an induced category
forget₂ :=
{ obj := fun R => AddCommMonCat.of R
-- Porting note: This doesn't work without the `(_ := _)` trick.
map := fun {R₁ R₂} f => RingHom.toAddMonoidHom (α := R₁) (β := R₂) f }
/-- Typecheck a `RingHom` as a morphism in `SemiRingCat`. -/
def ofHom {R S : Type u} [Semiring R] [Semiring S] (f : R →+* S) : of R ⟶ of S :=
f
-- Porting note: `simpNF` should not trigger on `rfl` lemmas.
-- see https://github.com/leanprover/std4/issues/86
@[simp, nolint simpNF]
theorem ofHom_apply {R S : Type u} [Semiring R] [Semiring S] (f : R →+* S) (x : R) :
ofHom f x = f x :=
rfl
/--
Ring equivalence are isomorphisms in category of semirings
-/
@[simps]
def _root_.RingEquiv.toSemiRingCatIso {X Y : Type u} [Semiring X] [Semiring Y] (e : X ≃+* Y) :
SemiRingCat.of X ≅ SemiRingCat.of Y where
hom := e.toRingHom
inv := e.symm.toRingHom
instance forgetReflectIsos : (forget SemiRingCat).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget SemiRingCat).map f)
let ff : X →+* Y := f
let e : X ≃+* Y := { ff, i.toEquiv with }
exact e.toSemiRingCatIso.isIso_hom
end SemiRingCat
/-- The category of rings. -/
abbrev RingCat : Type (u + 1) :=
Bundled Ring
namespace RingCat
instance : BundledHom.ParentProjection @Ring.toSemiring :=
⟨⟩
-- Porting note: Another place where mathlib had derived a concrete category
-- but this does not work here, so we add the instance manually.
-- see https://github.com/leanprover-community/mathlib4/issues/5020
instance (X : RingCat) : Ring X := X.str
-- Porting note: Hinting to Lean that `forget R` and `R` are the same
unif_hint forget_obj_eq_coe (R : RingCat) where ⊢
(forget RingCat).obj R ≟ R
instance instRing (X : RingCat) : Ring X := X.str
instance instFunLike {X Y : RingCat} : FunLike (X ⟶ Y) X Y :=
-- Note: this is apparently _not_ defeq to RingHom.instFunLike with reducible transparency
ConcreteCategory.instFunLike
-- Porting note (#10754): added instance
instance instRingHomClass {X Y : RingCat} : RingHomClass (X ⟶ Y) X Y :=
RingHom.instRingHomClass
lemma coe_id {X : RingCat} : (𝟙 X : X → X) = id := rfl
lemma coe_comp {X Y Z : RingCat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
@[simp] lemma forget_map {X Y : RingCat} (f : X ⟶ Y) : (forget RingCat).map f = (f : X → Y) := rfl
lemma ext {X Y : RingCat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g :=
RingHom.ext w
/-- Construct a bundled `RingCat` from the underlying type and typeclass. -/
def of (R : Type u) [Ring R] : RingCat :=
Bundled.of R
/-- Typecheck a `RingHom` as a morphism in `RingCat`. -/
def ofHom {R S : Type u} [Ring R] [Ring S] (f : R →+* S) : of R ⟶ of S :=
f
-- Porting note: I think this is now redundant.
-- @[simp]
-- theorem ofHom_apply {R S : Type u} [Ring R] [Ring S] (f : R →+* S) (x : R) : ofHom f x = f x :=
-- rfl
instance : Inhabited RingCat :=
⟨of PUnit⟩
instance (R : RingCat) : Ring R :=
R.str
@[simp]
theorem coe_of (R : Type u) [Ring R] : (RingCat.of R : Type u) = R :=
rfl
-- Coercing the identity morphism, as a ring homomorphism, gives the identity function.
@[simp] theorem coe_ringHom_id {X : RingCat} :
@DFunLike.coe (X →+* X) X (fun _ ↦ X) _ (𝟙 X) = id :=
rfl
-- Coercing `𝟙 (of X)` to a function should be expressed as the coercion of `RingHom.id X`.
@[simp] theorem coe_id_of {X : Type u} [Ring X] :
@DFunLike.coe no_index (RingCat.of X ⟶ RingCat.of X) X
(fun _ ↦ X) _
(𝟙 (of X)) =
@DFunLike.coe (X →+* X) X (fun _ ↦ X) _ (RingHom.id X) :=
rfl
-- Coercing `f ≫ g`, where `f : of X ⟶ of Y` and `g : of Y ⟶ of Z`, to a function should be
-- expressed in terms of the coercion of `g.comp f`.
@[simp] theorem coe_comp_of {X Y Z : Type u} [Ring X] [Ring Y] [Ring Z]
(f : X →+* Y) (g : Y →+* Z) :
@DFunLike.coe no_index (RingCat.of X ⟶ RingCat.of Z) X
(fun _ ↦ Z) _
(CategoryStruct.comp (X := RingCat.of X) (Y := RingCat.of Y) (Z := RingCat.of Z)
f g) =
@DFunLike.coe (X →+* Z) X (fun _ ↦ Z) _ (RingHom.comp g f) :=
rfl
-- Sometimes neither the `ext` lemma for `RingCat` nor for `RingHom` is applicable,
-- because of incomplete unfolding of `RingCat.of X ⟶ RingCat.of Y := X →+* Y`,
-- but this one will fire.
@[ext] theorem ext_of {X Y : Type u} [Ring X] [Ring Y] (f g : X →+* Y)
(h : ∀ x, f x = g x) :
@Eq (RingCat.of X ⟶ RingCat.of Y) f g :=
RingHom.ext h
@[simp]
lemma RingEquiv_coe_eq {X Y : Type _} [Ring X] [Ring Y] (e : X ≃+* Y) :
(@DFunLike.coe (RingCat.of X ⟶ RingCat.of Y) _ (fun _ => (forget RingCat).obj _)
ConcreteCategory.instFunLike (e : X →+* Y) : X → Y) = ↑e :=
rfl
instance hasForgetToSemiRingCat : HasForget₂ RingCat SemiRingCat :=
BundledHom.forget₂ _ _
instance hasForgetToAddCommGrp : HasForget₂ RingCat AddCommGrp where
-- can't use BundledHom.mkHasForget₂, since AddCommGroup is an induced category
forget₂ :=
{ obj := fun R => AddCommGrp.of R
-- Porting note: use `(_ := _)` similar to above.
map := fun {R₁ R₂} f => RingHom.toAddMonoidHom (α := R₁) (β := R₂) f }
end RingCat
/-- The category of commutative semirings. -/
def CommSemiRingCat : Type (u + 1) :=
Bundled CommSemiring
namespace CommSemiRingCat
instance : BundledHom.ParentProjection @CommSemiring.toSemiring :=
⟨⟩
-- Porting note: again, deriving fails for concrete category instances.
-- see https://github.com/leanprover-community/mathlib4/issues/5020
deriving instance LargeCategory for CommSemiRingCat
instance : ConcreteCategory CommSemiRingCat := by
dsimp [CommSemiRingCat]
infer_instance
instance : CoeSort CommSemiRingCat Type* where
coe X := X.α
instance (X : CommSemiRingCat) : CommSemiring X := X.str
-- Porting note: Hinting to Lean that `forget R` and `R` are the same
unif_hint forget_obj_eq_coe (R : CommSemiRingCat) where ⊢
(forget CommSemiRingCat).obj R ≟ R
instance instCommSemiring (X : CommSemiRingCat) : CommSemiring X := X.str
instance instCommSemiring' (X : CommSemiRingCat) : CommSemiring <| (forget CommSemiRingCat).obj X :=
X.str
instance instFunLike {X Y : CommSemiRingCat} : FunLike (X ⟶ Y) X Y :=
-- Note: this is apparently _not_ defeq to RingHom.instFunLike with reducible transparency
ConcreteCategory.instFunLike
-- Porting note (#10754): added instance
instance instRingHomClass {X Y : CommSemiRingCat} : RingHomClass (X ⟶ Y) X Y :=
RingHom.instRingHomClass
lemma coe_id {X : CommSemiRingCat} : (𝟙 X : X → X) = id := rfl
lemma coe_comp {X Y Z : CommSemiRingCat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
@[simp] lemma forget_map {X Y : CommSemiRingCat} (f : X ⟶ Y) :
(forget CommSemiRingCat).map f = (f : X → Y) := rfl
lemma ext {X Y : CommSemiRingCat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g :=
RingHom.ext w
/-- Construct a bundled `CommSemiRingCat` from the underlying type and typeclass. -/
def of (R : Type u) [CommSemiring R] : CommSemiRingCat :=
Bundled.of R
/-- Typecheck a `RingHom` as a morphism in `CommSemiRingCat`. -/
def ofHom {R S : Type u} [CommSemiring R] [CommSemiring S] (f : R →+* S) : of R ⟶ of S :=
f
@[simp]
lemma RingEquiv_coe_eq {X Y : Type _} [CommSemiring X] [CommSemiring Y] (e : X ≃+* Y) :
(@DFunLike.coe (CommSemiRingCat.of X ⟶ CommSemiRingCat.of Y) _
(fun _ => (forget CommSemiRingCat).obj _)
ConcreteCategory.instFunLike (e : X →+* Y) : X → Y) = ↑e :=
rfl
-- Porting note: I think this is now redundant.
-- @[simp]
-- theorem ofHom_apply {R S : Type u} [CommSemiring R] [CommSemiring S] (f : R →+* S) (x : R) :
-- ofHom f x = f x :=
-- rfl
instance : Inhabited CommSemiRingCat :=
⟨of PUnit⟩
instance (R : CommSemiRingCat) : CommSemiring R :=
R.str
@[simp]
theorem coe_of (R : Type u) [CommSemiring R] : (CommSemiRingCat.of R : Type u) = R :=
rfl
-- Coercing the identity morphism, as a ring homomorphism, gives the identity function.
@[simp] theorem coe_ringHom_id {X : CommSemiRingCat} :
@DFunLike.coe (X →+* X) X (fun _ ↦ X) _ (𝟙 X) = id :=
rfl
-- Coercing `𝟙 (of X)` to a function should be expressed as the coercion of `RingHom.id X`.
@[simp] theorem coe_id_of {X : Type u} [CommSemiring X] :
@DFunLike.coe no_index (CommSemiRingCat.of X ⟶ CommSemiRingCat.of X) X
(fun _ ↦ X) _
(𝟙 (of X)) =
@DFunLike.coe (X →+* X) X (fun _ ↦ X) _ (RingHom.id X) :=
rfl
-- Coercing `f ≫ g`, where `f : of X ⟶ of Y` and `g : of Y ⟶ of Z`, to a function should be
-- expressed in terms of the coercion of `g.comp f`.
@[simp] theorem coe_comp_of {X Y Z : Type u} [CommSemiring X] [CommSemiring Y] [CommSemiring Z]
(f : X →+* Y) (g : Y →+* Z) :
@DFunLike.coe no_index (CommSemiRingCat.of X ⟶ CommSemiRingCat.of Z) X
(fun _ ↦ Z) _
(CategoryStruct.comp (X := CommSemiRingCat.of X) (Y := CommSemiRingCat.of Y)
(Z := CommSemiRingCat.of Z) f g) =
@DFunLike.coe (X →+* Z) X (fun _ ↦ Z) _ (RingHom.comp g f) :=
rfl
-- Sometimes neither the `ext` lemma for `CommSemiRingCat` nor for `RingHom` is applicable,
-- because of incomplete unfolding of `CommSemiRingCat.of X ⟶ CommSemiRingCat.of Y := X →+* Y`,
-- but this one will fire.
@[ext] theorem ext_of {X Y : Type u} [CommSemiring X] [CommSemiring Y] (f g : X →+* Y)
(h : ∀ x, f x = g x) :
@Eq (CommSemiRingCat.of X ⟶ CommSemiRingCat.of Y) f g :=
RingHom.ext h
instance hasForgetToSemiRingCat : HasForget₂ CommSemiRingCat SemiRingCat :=
BundledHom.forget₂ _ _
/-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/
instance hasForgetToCommMonCat : HasForget₂ CommSemiRingCat CommMonCat :=
HasForget₂.mk' (fun R : CommSemiRingCat => CommMonCat.of R) (fun R => rfl)
-- Porting note: `(_ := _)` trick
(fun {R₁ R₂} f => RingHom.toMonoidHom (α := R₁) (β := R₂) f) (by rfl)
/--
Ring equivalence are isomorphisms in category of commutative semirings
-/
@[simps]
def _root_.RingEquiv.toCommSemiRingCatIso {X Y : Type u} [CommSemiring X] [CommSemiring Y]
(e : X ≃+* Y) : CommSemiRingCat.of X ≅ CommSemiRingCat.of Y where
hom := e.toRingHom
inv := e.symm.toRingHom
instance forgetReflectIsos : (forget CommSemiRingCat).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget CommSemiRingCat).map f)
let ff : X →+* Y := f
let e : X ≃+* Y := { ff, i.toEquiv with }
exact ⟨e.toSemiRingCatIso.isIso_hom.1⟩
end CommSemiRingCat
/-- The category of commutative rings. -/
def CommRingCat : Type (u + 1) :=
Bundled CommRing
namespace CommRingCat
instance : BundledHom.ParentProjection @CommRing.toRing :=
⟨⟩
-- Porting note: deriving fails for concrete category.
-- see https://github.com/leanprover-community/mathlib4/issues/5020
deriving instance LargeCategory for CommRingCat
instance : ConcreteCategory CommRingCat := by
dsimp [CommRingCat]
infer_instance
instance : CoeSort CommRingCat Type* where
coe X := X.α
-- Porting note: Hinting to Lean that `forget R` and `R` are the same
unif_hint forget_obj_eq_coe (R : CommRingCat) where ⊢
(forget CommRingCat).obj R ≟ R
instance instCommRing (X : CommRingCat) : CommRing X := X.str
instance instCommRing' (X : CommRingCat) : CommRing <| (forget CommRingCat).obj X := X.str
instance instFunLike {X Y : CommRingCat} : FunLike (X ⟶ Y) X Y :=
-- Note: this is apparently _not_ defeq to RingHom.instFunLike with reducible transparency
ConcreteCategory.instFunLike
-- Porting note (#10754): added instance
instance instRingHomClass {X Y : CommRingCat} : RingHomClass (X ⟶ Y) X Y :=
RingHom.instRingHomClass
lemma coe_id {X : CommRingCat} : (𝟙 X : X → X) = id := rfl
lemma coe_comp {X Y Z : CommRingCat} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
/-- Specialization of `ConcreteCategory.id_apply` because `simp` can't see through the defeq. -/
@[simp] lemma id_apply (R : CommRingCat) (x : R) : 𝟙 R x = x := rfl
@[simp]
theorem comp_apply {R S T : CommRingCat} (f : R ⟶ S) (g : S ⟶ T) (x : R) :
(f ≫ g) x = g (f x) := rfl
@[simp] theorem forget_obj (R : CommRingCat) : (forget _).obj R = R := rfl
@[simp] lemma forget_map {X Y : CommRingCat} (f : X ⟶ Y) :
(forget CommRingCat).map f = (f : X → Y) := rfl
lemma ext {X Y : CommRingCat} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g :=
RingHom.ext w
/-- Construct a bundled `CommRingCat` from the underlying type and typeclass. -/
def of (R : Type u) [CommRing R] : CommRingCat :=
Bundled.of R
instance instFunLike' {X : Type*} [CommRing X] {Y : CommRingCat} :
FunLike (CommRingCat.of X ⟶ Y) X Y :=
-- Note: this is apparently _not_ defeq to RingHom.instFunLike with reducible transparency
ConcreteCategory.instFunLike
instance instFunLike'' {X : CommRingCat} {Y : Type*} [CommRing Y] :
FunLike (X ⟶ CommRingCat.of Y) X Y :=
-- Note: this is apparently _not_ defeq to RingHom.instFunLike with reducible transparency
ConcreteCategory.instFunLike
instance instFunLike''' {X Y : Type _} [CommRing X] [CommRing Y] :
FunLike (CommRingCat.of X ⟶ CommRingCat.of Y) X Y :=
-- Note: this is apparently _not_ defeq to RingHom.instFunLike with reducible transparency
ConcreteCategory.instFunLike
/-- Typecheck a `RingHom` as a morphism in `CommRingCat`. -/
def ofHom {R S : Type u} [CommRing R] [CommRing S] (f : R →+* S) : of R ⟶ of S :=
f
@[simp]
lemma RingEquiv_coe_eq {X Y : Type _} [CommRing X] [CommRing Y] (e : X ≃+* Y) :
(@DFunLike.coe (CommRingCat.of X ⟶ CommRingCat.of Y) X (fun _ => Y)
ConcreteCategory.instFunLike (e : X →+* Y) : X → Y) = ↑e :=
rfl
-- Porting note: I think this is now redundant.
-- @[simp]
-- theorem ofHom_apply {R S : Type u} [CommRing R] [CommRing S] (f : R →+* S) (x : R) :
-- ofHom f x = f x :=
-- rfl
instance : Inhabited CommRingCat :=
⟨of PUnit⟩
instance (R : CommRingCat) : CommRing R :=
R.str
@[simp]
theorem coe_of (R : Type u) [CommRing R] : (CommRingCat.of R : Type u) = R :=
rfl
-- Coercing the identity morphism, as a ring homomorphism, gives the identity function.
@[simp] theorem coe_ringHom_id {X : CommRingCat} :
@DFunLike.coe (X →+* X) X (fun _ ↦ X) _ (𝟙 X) = id :=
rfl
-- Coercing `𝟙 (of X)` to a function should be expressed as the coercion of `RingHom.id X`.
@[simp] theorem coe_id_of {X : Type u} [CommRing X] :
@DFunLike.coe no_index (CommRingCat.of X ⟶ CommRingCat.of X) X
(fun _ ↦ X) _
(𝟙 (of X)) =
@DFunLike.coe (X →+* X) X (fun _ ↦ X) _ (RingHom.id X) :=
rfl
-- Coercing `f ≫ g`, where `f : of X ⟶ of Y` and `g : of Y ⟶ of Z`, to a function should be
-- expressed in terms of the coercion of `g.comp f`.
@[simp] theorem coe_comp_of {X Y Z : Type u} [CommRing X] [CommRing Y] [CommRing Z]
(f : X →+* Y) (g : Y →+* Z) :
@DFunLike.coe no_index (CommRingCat.of X ⟶ CommRingCat.of Z) X
(fun _ ↦ Z) _
(CategoryStruct.comp (X := CommRingCat.of X) (Y := CommRingCat.of Y) (Z := CommRingCat.of Z)
f g) =
@DFunLike.coe (X →+* Z) X (fun _ ↦ Z) _ (RingHom.comp g f) :=
rfl
-- Sometimes neither the `ext` lemma for `CommRingCat` nor for `RingHom` is applicable,
-- because of incomplete unfolding of `CommRingCat.of X ⟶ CommRingCat.of Y := X →+* Y`,
-- but this one will fire.
@[ext] theorem ext_of {X Y : Type u} [CommRing X] [CommRing Y] (f g : X →+* Y)
(h : ∀ x, f x = g x) :
@Eq (CommRingCat.of X ⟶ CommRingCat.of Y) f g :=
RingHom.ext h
instance hasForgetToRingCat : HasForget₂ CommRingCat RingCat :=
BundledHom.forget₂ _ _
/-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/
instance hasForgetToCommSemiRingCat : HasForget₂ CommRingCat CommSemiRingCat :=
HasForget₂.mk' (fun R : CommRingCat => CommSemiRingCat.of R) (fun R => rfl)
(fun {R₁ R₂} f => f) (by rfl)
instance : (forget₂ CommRingCat CommSemiRingCat).Full where map_surjective f := ⟨f, rfl⟩
end CommRingCat
-- We verify that simp lemmas apply when coercing morphisms to functions.
example {R S : CommRingCat} (i : R ⟶ S) (r : R) (h : r = 0) : i r = 0 := by simp [h]
namespace RingEquiv
variable {X Y : Type u}
/-- Build an isomorphism in the category `RingCat` from a `RingEquiv` between `RingCat`s. -/
@[simps]
def toRingCatIso [Ring X] [Ring Y] (e : X ≃+* Y) : RingCat.of X ≅ RingCat.of Y where
hom := e.toRingHom
inv := e.symm.toRingHom
/-- Build an isomorphism in the category `CommRingCat` from a `RingEquiv` between `CommRingCat`s. -/
@[simps]
def toCommRingCatIso [CommRing X] [CommRing Y] (e : X ≃+* Y) :
CommRingCat.of X ≅ CommRingCat.of Y where
hom := e.toRingHom
inv := e.symm.toRingHom
end RingEquiv
namespace CategoryTheory.Iso
/-- Build a `RingEquiv` from an isomorphism in the category `RingCat`. -/
def ringCatIsoToRingEquiv {X Y : RingCat} (i : X ≅ Y) : X ≃+* Y :=
RingEquiv.ofHomInv i.hom i.inv i.hom_inv_id i.inv_hom_id
/-- Build a `RingEquiv` from an isomorphism in the category `CommRingCat`. -/
def commRingCatIsoToRingEquiv {X Y : CommRingCat} (i : X ≅ Y) : X ≃+* Y :=
RingEquiv.ofHomInv i.hom i.inv i.hom_inv_id i.inv_hom_id
-- Porting note: make this high priority to short circuit simplifier
@[simp (high)]
theorem commRingIsoToRingEquiv_toRingHom {X Y : CommRingCat} (i : X ≅ Y) :
i.commRingCatIsoToRingEquiv.toRingHom = i.hom := by
ext
rfl
-- Porting note: make this high priority to short circuit simplifier
@[simp (high)]
theorem commRingIsoToRingEquiv_symm_toRingHom {X Y : CommRingCat} (i : X ≅ Y) :
i.commRingCatIsoToRingEquiv.symm.toRingHom = i.inv := by
ext
rfl
end CategoryTheory.Iso
/-- Ring equivalences between `RingCat`s are the same as (isomorphic to) isomorphisms in
`RingCat`. -/
def ringEquivIsoRingIso {X Y : Type u} [Ring X] [Ring Y] :
X ≃+* Y ≅ RingCat.of X ≅ RingCat.of Y where
hom e := e.toRingCatIso
inv i := i.ringCatIsoToRingEquiv
/-- Ring equivalences between `CommRingCat`s are the same as (isomorphic to) isomorphisms
in `CommRingCat`. -/
def ringEquivIsoCommRingIso {X Y : Type u} [CommRing X] [CommRing Y] :
X ≃+* Y ≅ CommRingCat.of X ≅ CommRingCat.of Y where
hom e := e.toCommRingCatIso
inv i := i.commRingCatIsoToRingEquiv
instance RingCat.forget_reflects_isos : (forget RingCat.{u}).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget RingCat).map f)
let ff : X →+* Y := f
let e : X ≃+* Y := { ff, i.toEquiv with }
exact e.toRingCatIso.isIso_hom
instance CommRingCat.forget_reflects_isos : (forget CommRingCat.{u}).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget CommRingCat).map f)
let ff : X →+* Y := f
let e : X ≃+* Y := { ff, i.toEquiv with }
exact e.toCommRingCatIso.isIso_hom
theorem CommRingCat.comp_eq_ring_hom_comp {R S T : CommRingCat} (f : R ⟶ S) (g : S ⟶ T) :
f ≫ g = g.comp f :=
rfl
theorem CommRingCat.ringHom_comp_eq_comp {R S T : Type _} [CommRing R] [CommRing S] [CommRing T]
(f : R →+* S) (g : S →+* T) : g.comp f = CommRingCat.ofHom f ≫ CommRingCat.ofHom g :=
rfl
-- It would be nice if we could have the following,
-- but it requires making `reflectsIsomorphisms_forget₂` an instance,
-- which can cause typeclass loops:
-- Porting note: This was the case in mathlib3, perhaps it is different now?
attribute [local instance] reflectsIsomorphisms_forget₂
example : (forget₂ RingCat AddCommGrp).ReflectsIsomorphisms := by infer_instance
/-!
`@[simp]` lemmas for `RingHom.comp` and categorical identities.
-/
@[simp] theorem RingHom.comp_id_semiringCat
{G : SemiRingCat.{u}} {H : Type u} [Semiring H] (f : G →+* H) : f.comp (𝟙 G) = f :=
Category.id_comp (SemiRingCat.ofHom f)
@[simp] theorem RingHom.id_semiringCat_comp
{G : Type u} [Semiring G] {H : SemiRingCat.{u}} (f : G →+* H) : RingHom.comp (𝟙 H) f = f :=
Category.comp_id (SemiRingCat.ofHom f)
@[simp] theorem RingHom.comp_id_commSemiringCat
{G : CommSemiRingCat.{u}} {H : Type u} [CommSemiring H] (f : G →+* H) : f.comp (𝟙 G) = f :=
Category.id_comp (CommSemiRingCat.ofHom f)
@[simp] theorem RingHom.id_commSemiringCat_comp
{G : Type u} [CommSemiring G] {H : CommSemiRingCat.{u}} (f : G →+* H) :
RingHom.comp (𝟙 H) f = f :=
Category.comp_id (CommSemiRingCat.ofHom f)
@[simp] theorem RingHom.comp_id_ringCat
{G : RingCat.{u}} {H : Type u} [Ring H] (f : G →+* H) : f.comp (𝟙 G) = f :=
Category.id_comp (RingCat.ofHom f)
@[simp] theorem RingHom.id_ringCat_comp
{G : Type u} [Ring G] {H : RingCat.{u}} (f : G →+* H) : RingHom.comp (𝟙 H) f = f :=
Category.comp_id (RingCat.ofHom f)
@[simp] theorem RingHom.comp_id_commRingCat
{G : CommRingCat.{u}} {H : Type u} [CommRing H] (f : G →+* H) : f.comp (𝟙 G) = f :=
Category.id_comp (CommRingCat.ofHom f)
@[simp] theorem RingHom.id_commRingCat_comp
{G : Type u} [CommRing G] {H : CommRingCat.{u}} (f : G →+* H) : RingHom.comp (𝟙 H) f = f :=
Category.comp_id (CommRingCat.ofHom f)
|
Algebra\Category\Ring\Colimits.lean
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
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
| add_left_neg : ∀ 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 _
add_left_neg := Quotient.ind <| fun _ => Quotient.sound <| Relation.add_left_neg _
add_assoc := Quotient.ind <| fun _ => Quotient.ind₂ <| fun _ _ =>
Quotient.sound <| Relation.add_assoc _ _ _
nsmul := nsmulRec
zsmul := zsmulRec
-- Porting note: failed to derive `Inhabited` instance
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 x => Quot.sound <| Relation.one_mul _
mul_one := fun x => Quot.inductionOn x fun x => Quot.sound <| Relation.mul_one _
add_comm := fun x y => Quot.induction_on₂ x y fun x y => 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 x => Quot.sound <| Relation.mul_zero _
zero_mul := fun x => Quot.inductionOn x fun x => 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) :
-- 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.
(by exact Quot.mk Setoid.r (neg x) : ColimitType F) = -(by exact 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) :
(by exact Quot.mk Setoid.r (add x y) : ColimitType F) =
(by exact Quot.mk _ x) + (by exact 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) :
(by exact Quot.mk Setoid.r (mul x y) : ColimitType F) =
(by exact Quot.mk _ x) * (by exact 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 where
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 (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]
| add_left_neg x => dsimp; rw [add_left_neg]
| 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 where
toFun := descFun F s
map_one' := rfl
map_zero' := rfl
map_add' x y := by
refine Quot.induction_on₂ x y fun a b => ?_
dsimp [descFun]
rw [← quot_add]
rfl
map_mul' 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 := RingHom.ext fun x => by
change (colimitCocone F).pt →+* s.pt at m
refine Quot.inductionOn x ?_
intro x
induction x with
| zero => erw [quot_zero, map_zero (f := m), (descMorphism F s).map_zero]
| one => erw [quot_one, map_one (f := m), (descMorphism F s).map_one]
-- extra rfl with leanprover/lean4#2644
| neg x ih => erw [quot_neg, map_neg (f := m), (descMorphism F s).map_neg, ih]; rfl
| 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 =>
-- extra rfl with leanprover/lean4#2644
erw [quot_add, map_add (f := m), (descMorphism F s).map_add, ih_x, ih_y]; rfl
| mul x y ih_x ih_y =>
-- extra rfl with leanprover/lean4#2644
erw [quot_mul, map_mul (f := m), (descMorphism F s).map_mul, ih_x, ih_y]; rfl
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
| add_left_neg : ∀ 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 _
add_left_neg := Quotient.ind <| fun _ => Quotient.sound <| Relation.add_left_neg _
add_assoc := Quotient.ind <| fun _ => Quotient.ind₂ <| fun _ _ =>
Quotient.sound <| Relation.add_assoc _ _ _
nsmul := nsmulRec
zsmul := zsmulRec
-- Porting note: failed to derive `Inhabited` instance
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 x => Quot.sound <| Relation.one_mul _
mul_one := fun x => Quot.inductionOn x fun x => Quot.sound <| Relation.mul_one _
add_comm := fun x y => Quot.induction_on₂ x y fun x y => Quot.sound <| Relation.add_comm _ _
mul_comm := fun x y => Quot.induction_on₂ x y fun x y => 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 x => Quot.sound <| Relation.mul_zero _
zero_mul := fun x => Quot.inductionOn x fun x => 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) :
-- 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.
(by exact Quot.mk Setoid.r (neg x) : ColimitType F) = -(by exact 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) :
(by exact Quot.mk Setoid.r (add x y) : ColimitType F) =
(by exact Quot.mk _ x) + (by exact 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) :
(by exact Quot.mk Setoid.r (mul x y) : ColimitType F) =
(by exact Quot.mk _ x) * (by exact 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 where
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 (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]
| add_left_neg x => dsimp; rw [add_left_neg]
| 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 where
toFun := descFun F s
map_one' := rfl
map_zero' := rfl
map_add' x y := by
refine Quot.induction_on₂ x y fun a b => ?_
dsimp [descFun]
rw [← quot_add]
rfl
map_mul' 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 := RingHom.ext fun x => by
change (colimitCocone F).pt →+* s.pt at m
refine Quot.inductionOn x ?_
intro x
induction x with
| zero => erw [quot_zero, map_zero (f := m), (descMorphism F s).map_zero]
| one => erw [quot_one, map_one (f := m), (descMorphism F s).map_one]
-- extra rfl with leanprover/lean4#2644
| neg x ih => erw [quot_neg, map_neg (f := m), (descMorphism F s).map_neg, ih]; rfl
| 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 =>
-- extra rfl with leanprover/lean4#2644
erw [quot_add, map_add (f := m), (descMorphism F s).map_add, ih_x, ih_y]; rfl
| mul x y ih_x ih_y =>
-- extra rfl with leanprover/lean4#2644
erw [quot_mul, map_mul (f := m), (descMorphism F s).map_mul, ih_x, ih_y]; rfl
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
|
Algebra\Category\Ring\Constructions.lean
|
/-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.TensorProduct.Basic
import Mathlib.Algebra.Category.Ring.Limits
import Mathlib.Algebra.Category.Ring.Instances
import Mathlib.CategoryTheory.Limits.Shapes.StrictInitial
import Mathlib.Algebra.Ring.Subring.Basic
/-!
# 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
* `Z` 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
-/
suppress_compilation
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 Algebra.TensorProduct.includeLeftRingHom (A := A)
· exact 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 = Algebra.TensorProduct.includeLeftRingHom (A := A) :=
rfl
@[simp]
theorem pushoutCocone_inr :
(pushoutCocone R A B).inr = 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.comp (algebraMap R A))
let f' : A →ₐ[R] s.pt :=
{ s.inl with
commutes' := fun r => rfl }
let g' : B →ₐ[R] s.pt :=
{ s.inr with
commutes' := DFunLike.congr_fun ((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 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 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, AlgHom.toRingHom_eq_coe]
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.map_mul, Algebra.TensorProduct.tmul_mul_tmul, mul_one, one_mul]
rfl
end Pushout
section Terminal
/-- The trivial ring is the (strict) terminal object of `CommRingCat`. -/
def punitIsTerminal : IsTerminal (CommRingCat.of.{u} PUnit) := by
refine IsTerminal.ofUnique (h := fun X => ⟨⟨⟨⟨1, rfl⟩, fun _ _ => rfl⟩, ?_, ?_⟩, ?_⟩)
· rfl
· intros; simp only [coe_of, Pi.one_apply, self_eq_add_right]; ext
· intros f; ext; rfl
instance commRingCat_hasStrictTerminalObjects : HasStrictTerminalObjects CommRingCat.{u} := by
apply hasStrictTerminalObjects_of_terminal_is_strict (CommRingCat.of PUnit)
intro X f
refine ⟨⟨⟨1, rfl, fun _ _ => rfl⟩, by ext; rfl, ?_⟩⟩
ext x
have e : (0 : X) = 1 := by
rw [← f.map_one, ← f.map_zero]
congr
replace e : 0 * x = 1 * x := congr_arg (· * x) e
rw [one_mul, zero_mul, ← f.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 => ⟨⟨Int.castRingHom R⟩, fun a => a.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 := RingHom.prod (c.π.app ⟨WalkingPair.left⟩) (c.π.app ⟨WalkingPair.right⟩)
fac c j := by
ext
rcases j with ⟨⟨⟩⟩ <;>
simp only [pair_obj_left, prodFan_pt, BinaryFan.π_app_left, BinaryFan.π_app_right,
FunctorToTypes.map_comp_apply, forget_map, coe_of, RingHom.prod_apply] <;>
rfl
uniq s m h := by
ext x
change m x = (BinaryFan.fst s x, BinaryFan.snd s x)
have eq1 := congr_hom (h ⟨WalkingPair.left⟩) x
have eq2 := congr_hom (h ⟨WalkingPair.right⟩) x
dsimp at eq1 eq2
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [← eq1, ← eq2]
rfl
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)) (Pi.evalRingHom _)
/--
The categorical product of rings is the cartesian product of rings.
-/
def piFanIsLimit : IsLimit (piFan R) where
lift s := Pi.ringHom fun i ↦ s.π.1 ⟨i⟩
fac s i := by rfl
uniq s g h := DFunLike.ext _ _ fun x ↦ funext fun i ↦ DFunLike.congr_fun (h ⟨i⟩) x
/--
The categorical product and the usual product agrees
-/
def piIsoPi : ∏ᶜ R ≅ CommRingCat.of ((i : ι) → R i) :=
limit.isoLimitCone ⟨_, piFanIsLimit R⟩
/--
The categorical product and the usual product agrees
-/
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 g).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
-- Porting note: Lean can't see through `(parallelPair f g).obj zero`
haveI : SubsemiringClass (Subring A) ((parallelPair f g).obj WalkingParallelPair.zero) :=
show SubsemiringClass (Subring A) A by infer_instance
use s.ι.codRestrict _ fun x => (ConcreteCategory.congr_hom s.condition x : _)
constructor
· ext
rfl
· intro m hm
exact RingHom.ext fun x => Subtype.ext <| ConcreteCategory.congr_hom hm x
instance : IsLocalRingHom (equalizerFork f g).ι := by
constructor
rintro ⟨a, h₁ : _ = _⟩ (⟨⟨x, y, h₃, h₄⟩, rfl : x = _⟩ : IsUnit a)
have : y ∈ RingHom.eqLocus f g := by
apply (f.isUnit_map ⟨⟨x, y, h₃, h₄⟩, rfl⟩ : IsUnit (f x)).mul_left_inj.mp
conv_rhs => rw [h₁]
rw [← f.map_mul, ← g.map_mul, h₄, f.map_one, g.map_one]
rw [isUnit_iff_exists_inv]
exact ⟨⟨y, this⟩, Subtype.eq h₃⟩
instance equalizer_ι_isLocalRingHom (F : WalkingParallelPair ⥤ CommRingCat.{u}) :
IsLocalRingHom (limit.π F WalkingParallelPair.zero) := 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 IsLocalRingHom ((lim.map _ ≫ _ ≫ (equalizerFork _ _).ι) ≫ _)
infer_instance
open CategoryTheory.Limits.WalkingParallelPair Opposite
open CategoryTheory.Limits.WalkingParallelPairHom
instance equalizer_ι_is_local_ring_hom' (F : WalkingParallelPairᵒᵖ ⥤ CommRingCat.{u}) :
IsLocalRingHom (limit.π F (Opposite.op WalkingParallelPair.one)) := by
have : _ = limit.π F (walkingParallelPairOpEquiv.functor.obj _) :=
(limit.isoLimitCone_inv_π
⟨_, IsLimit.whiskerEquivalence (limit.isLimit F) walkingParallelPairOpEquiv⟩
WalkingParallelPair.zero : _)
erw [← this]
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.comp (RingHom.fst A B)) (g.comp (RingHom.snd A B))).subtype)
(CommRingCat.ofHom <|
(RingHom.snd A B).comp
(RingHom.eqLocus (f.comp (RingHom.fst A B)) (g.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
apply (s.fst.prod s.snd).codRestrict
intro x
exact congr_arg (fun f : s.pt →+* C => f x) s.condition
· intro s
ext x
rfl
· intro s
ext x
rfl
· intro s m e₁ e₂
refine RingHom.ext fun (x : s.pt) => Subtype.ext ?_
change (m x).1 = (_, _)
have eq1 := (congr_arg (fun f : s.pt →+* A => f x) e₁ : _)
have eq2 := (congr_arg (fun f : s.pt →+* B => f x) e₂ : _)
rw [← eq1, ← eq2]
rfl
end Pullback
end CommRingCat
|
Algebra\Category\Ring\FilteredColimits.lean
|
/-
Copyright (c) 2021 Justus Springer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Justus Springer
-/
import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.Algebra.Category.Grp.FilteredColimits
/-!
# 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 ⥤ SemiRingCatMax`.
We show that the colimit of `F ⋙ forget₂ SemiRingCatMax MonCat` (in `MonCat`)
carries the structure of a semiring, thereby showing that the forgetful functor
`forget₂ SemiRingCatMax MonCat` preserves filtered colimits.
In particular, this implies that `forget SemiRingCatMax` 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 ⥤ SemiRingCatMax.{v, u})
-- This instance is needed below in `colimitSemiring`, during the verification of the
-- semiring axioms.
instance semiringObj (j : J) :
Semiring (((F ⋙ forget₂ SemiRingCatMax.{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 : MonCatMax.{v, u} :=
MonCat.FilteredColimits.colimit.{v, u} (F ⋙ forget₂ SemiRingCatMax.{v, u} MonCatMax.{v, u})
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
cases' x with j 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
cases' x with j 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
cases' x with j₁ x; cases' y with j₂ y; cases' z with j₃ 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, id_apply]
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
cases' x with j₁ x; cases' y with j₂ y; cases' z with j₃ 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, id_apply]
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 : SemiRingCatMax.{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 =>
{ (MonCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ SemiRingCatMax.{v, u} MonCat)).ι.app j,
(AddCommMonCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ SemiRingCatMax.{v, u} AddCommMonCat)).ι.app j with }
naturality := fun {_ _} f =>
RingHom.coe_inj ((Types.TypeMax.colimitCocone (F ⋙ forget SemiRingCat)).ι.naturality f) }
/-- The proposed colimit cocone is a colimit in `SemiRingCat`. -/
def colimitCoconeIsColimit : IsColimit <| colimitCocone.{v, u} F where
desc t :=
{ (MonCat.FilteredColimits.colimitCoconeIsColimit.{v, u}
(F ⋙ forget₂ SemiRingCatMax.{v, u} MonCat)).desc
((forget₂ SemiRingCatMax.{v, u} MonCat).mapCocone t),
(AddCommMonCat.FilteredColimits.colimitCoconeIsColimit.{v, u}
(F ⋙ forget₂ SemiRingCatMax.{v, u} AddCommMonCat)).desc
((forget₂ SemiRingCatMax.{v, u} AddCommMonCat).mapCocone t) with }
fac t j :=
RingHom.coe_inj <|
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget SemiRingCatMax.{v, u})).fac
((forget SemiRingCatMax.{v, u}).mapCocone t) j
uniq t _ h :=
RingHom.coe_inj <|
(Types.TypeMax.colimitCoconeIsColimit (F ⋙ forget SemiRingCat)).uniq
((forget SemiRingCat).mapCocone t) _ fun j => funext fun x => RingHom.congr_fun (h j) x
instance forget₂MonPreservesFilteredColimits :
PreservesFilteredColimits (forget₂ SemiRingCat MonCat.{u}) where
preserves_filtered_colimits {J hJ1 _} :=
letI : Category J := hJ1
{ preservesColimit := fun {F} =>
preservesColimitOfPreservesColimitCocone (colimitCoconeIsColimit.{u, u} F)
(MonCat.FilteredColimits.colimitCoconeIsColimit (F ⋙ forget₂ SemiRingCat MonCat.{u})) }
instance forgetPreservesFilteredColimits : PreservesFilteredColimits (forget SemiRingCat.{u}) :=
Limits.compPreservesFilteredColimits (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 : SemiRingCatMax.{v, u} :=
SemiRingCat.FilteredColimits.colimit (F ⋙ forget₂ CommSemiRingCat SemiRingCat.{max v u})
instance colimitCommSemiring : CommSemiring.{max v u} <| R.{v, u} F :=
{ (R F).str,
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
ι :=
{ (SemiRingCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ CommSemiRingCat SemiRingCat.{max v u})).ι with }
/-- The proposed colimit cocone is a colimit in `CommSemiRingCat`. -/
def colimitCoconeIsColimit : IsColimit <| colimitCocone.{v, u} F where
desc t :=
(SemiRingCat.FilteredColimits.colimitCoconeIsColimit.{v, u}
(F ⋙ forget₂ CommSemiRingCat SemiRingCat.{max v u})).desc
((forget₂ CommSemiRingCat SemiRingCat).mapCocone t)
fac t j :=
RingHom.coe_inj <|
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget CommSemiRingCat)).fac
((forget CommSemiRingCat).mapCocone t) j
uniq t _ h :=
RingHom.coe_inj <|
(Types.TypeMax.colimitCoconeIsColimit (F ⋙ forget CommSemiRingCat)).uniq
((forget CommSemiRingCat).mapCocone t) _ fun j => funext fun x => RingHom.congr_fun (h j) x
instance forget₂SemiRingPreservesFilteredColimits :
PreservesFilteredColimits (forget₂ CommSemiRingCat SemiRingCat.{u}) where
preserves_filtered_colimits {J hJ1 _} :=
letI : Category J := hJ1
{ preservesColimit := fun {F} =>
preservesColimitOfPreservesColimitCocone (colimitCoconeIsColimit.{u, u} F)
(SemiRingCat.FilteredColimits.colimitCoconeIsColimit
(F ⋙ forget₂ CommSemiRingCat SemiRingCat.{u})) }
instance forgetPreservesFilteredColimits : PreservesFilteredColimits (forget CommSemiRingCat.{u}) :=
Limits.compPreservesFilteredColimits (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).str,
AddCommGrp.FilteredColimits.colimitAddCommGroup.{v, u}
(F ⋙ forget₂ RingCat AddCommGrp.{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
ι :=
{ (SemiRingCat.FilteredColimits.colimitCocone
(F ⋙ forget₂ RingCat SemiRingCat.{max v u})).ι with }
/-- The proposed colimit cocone is a colimit in `Ring`. -/
def colimitCoconeIsColimit : IsColimit <| colimitCocone.{v, u} F where
desc t :=
(SemiRingCat.FilteredColimits.colimitCoconeIsColimit.{v, u}
(F ⋙ forget₂ RingCat SemiRingCat.{max v u})).desc
((forget₂ RingCat SemiRingCat).mapCocone t)
fac t j :=
RingHom.coe_inj <|
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget RingCat)).fac
((forget RingCat).mapCocone t) j
uniq t _ h :=
RingHom.coe_inj <|
(Types.TypeMax.colimitCoconeIsColimit (F ⋙ forget RingCat)).uniq
((forget RingCat).mapCocone t) _ fun j => funext fun x => RingHom.congr_fun (h j) x
instance forget₂SemiRingPreservesFilteredColimits :
PreservesFilteredColimits (forget₂ RingCat SemiRingCat.{u}) where
preserves_filtered_colimits {J hJ1 _} :=
letI : Category J := hJ1
{ preservesColimit := fun {F} =>
preservesColimitOfPreservesColimitCocone (colimitCoconeIsColimit.{u, u} F)
(SemiRingCat.FilteredColimits.colimitCoconeIsColimit
(F ⋙ forget₂ RingCat SemiRingCat.{u})) }
instance forgetPreservesFilteredColimits : PreservesFilteredColimits (forget RingCat.{u}) :=
Limits.compPreservesFilteredColimits (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).str,
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
ι :=
{ (RingCat.FilteredColimits.colimitCocone (F ⋙ forget₂ CommRingCat RingCat.{max v u})).ι with }
/-- The proposed colimit cocone is a colimit in `CommRingCat`. -/
def colimitCoconeIsColimit : IsColimit <| colimitCocone.{v, u} F where
desc t :=
(RingCat.FilteredColimits.colimitCoconeIsColimit.{v, u}
(F ⋙ forget₂ CommRingCat RingCat.{max v u})).desc
((forget₂ CommRingCat RingCat).mapCocone t)
fac t j :=
RingHom.coe_inj <|
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget CommRingCat)).fac
((forget CommRingCat).mapCocone t) j
uniq t _ h :=
RingHom.coe_inj <|
(Types.TypeMax.colimitCoconeIsColimit (F ⋙ forget CommRingCat)).uniq
((forget CommRingCat).mapCocone t) _ fun j => funext fun x => RingHom.congr_fun (h j) x
instance forget₂RingPreservesFilteredColimits :
PreservesFilteredColimits (forget₂ CommRingCat RingCat.{u}) where
preserves_filtered_colimits {J hJ1 _} :=
letI : Category J := hJ1
{ preservesColimit := fun {F} =>
preservesColimitOfPreservesColimitCocone (colimitCoconeIsColimit.{u, u} F)
(RingCat.FilteredColimits.colimitCoconeIsColimit (F ⋙ forget₂ CommRingCat RingCat.{u})) }
instance forgetPreservesFilteredColimits : PreservesFilteredColimits (forget CommRingCat.{u}) :=
Limits.compPreservesFilteredColimits (forget₂ CommRingCat RingCat) (forget RingCat.{u})
end
end CommRingCat.FilteredColimits
|
Algebra\Category\Ring\Instances.lean
|
/-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
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 languages
-/
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 {T} _ _ => @IsLocalization.ringHom_ext R _ M S _ _ T _ _ _ _⟩
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 CommRingCat.isLocalRingHom_comp {R S T : CommRingCat} (f : R ⟶ S) (g : S ⟶ T)
[IsLocalRingHom g] [IsLocalRingHom f] : IsLocalRingHom (f ≫ g) :=
_root_.isLocalRingHom_comp _ _
theorem isLocalRingHom_of_iso {R S : CommRingCat} (f : R ≅ S) : IsLocalRingHom f.hom :=
{ map_nonunit := fun a ha => by
convert f.inv.isUnit_map ha
exact (RingHom.congr_fun f.hom_inv_id _).symm }
-- see Note [lower instance priority]
instance (priority := 100) isLocalRingHom_of_isIso {R S : CommRingCat} (f : R ⟶ S) [IsIso f] :
IsLocalRingHom f :=
isLocalRingHom_of_iso (asIso f)
|
Algebra\Category\Ring\Limits.lean
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Ring.Pi
import Mathlib.Algebra.Category.Ring.Basic
import Mathlib.Algebra.Category.Grp.Limits
import Mathlib.Algebra.Ring.Subring.Basic
/-!
# 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_note "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) :=
-- Porting note: if `f` and `g` were inlined, it does not compile
letI f : J ⥤ AddMonCat.{u} := F ⋙ forget₂ SemiRingCat.{u} AddCommMonCat.{u} ⋙
forget₂ AddCommMonCat AddMonCat
letI g : J ⥤ MonCat.{u} := F ⋙ forget₂ SemiRingCat.{u} MonCat.{u}
{ (MonCat.sectionsSubmonoid (J := J) g),
(AddMonCat.sectionsAddSubmonoid (J := J) f) 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 :=
letI : 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 :=
-- Porting note: if `f` and `g` were inlined, it does not compile
letI f : J ⥤ AddMonCat.{u} := F ⋙ forget₂ SemiRingCat.{u} AddCommMonCat.{u} ⋙
forget₂ AddCommMonCat AddMonCat
letI : Small.{u} (Functor.sections ((F ⋙ forget₂ _ MonCat) ⋙ forget MonCat)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget SemiRingCat.{u}))
letI : 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 := limitπRingHom.{v, u} F
naturality := fun {_ _} f => 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 => { 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.mapCone_π_app, forget_map, map_mul]
erw [← map_mul (MulEquiv.symm Shrink.mulEquiv)]
rfl
· simp only [Functor.mapCone_π_app, forget_map, map_zero]
rfl
· intro x y
simp only [Functor.mapCone_π_app, forget_map, map_add]
erw [← map_add (AddEquiv.symm Shrink.addEquiv)]
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
letI : 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₂AddCommMonPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ SemiRingCat AddCommMonCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimitOfPreservesLimitCone (limitConeIsLimit.{v, u} F)
(forget₂AddCommMonPreservesLimitsAux F) }
instance forget₂AddCommMonPreservesLimits :
PreservesLimits (forget₂ SemiRingCat AddCommMonCat.{u}) :=
SemiRingCat.forget₂AddCommMonPreservesLimitsOfSize.{u, u}
/-- An auxiliary declaration to speed up typechecking.
-/
def forget₂MonPreservesLimitsAux :
IsLimit ((forget₂ SemiRingCat MonCat).mapCone (limitCone F)) := by
letI : 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₂MonPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ SemiRingCat MonCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimitOfPreservesLimitCone (limitConeIsLimit F)
(forget₂MonPreservesLimitsAux.{v, u} F) }
instance forget₂MonPreservesLimits : PreservesLimits (forget₂ SemiRingCat MonCat.{u}) :=
SemiRingCat.forget₂MonPreservesLimitsOfSize.{u, u}
/-- The forgetful functor from semirings to types preserves all limits.
-/
instance forgetPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget SemiRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimitOfPreservesLimitCone (limitConeIsLimit F)
(Types.Small.limitConeIsLimit.{v, u} (F ⋙ forget _)) }
instance forgetPreservesLimits : PreservesLimits (forget SemiRingCat.{u}) :=
SemiRingCat.forgetPreservesLimitsOfSize.{u, u}
end SemiRingCat
-- Porting note: typemax hack to fix universe complaints
/-- An alias for `CommSemiring.{max u v}`, to deal with unification issues. -/
@[nolint checkUnivs]
abbrev CommSemiRingCatMax.{u1, u2} := CommSemiRingCat.{max u1 u2}
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 :=
letI : 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: `CommSemiRingCat ⥤ Type` reflecting isomorphism is needed to make Lean see that
-- `CommSemiRingCat ⥤ SemiRingCat` reflects isomorphism. `CommSemiRingCat ⥤ Type` reflecting
-- isomorphism is added manually since Lean can't see it, but even with this addition Lean can not
-- see `CommSemiRingCat ⥤ SemiRingCat` reflects isomorphism, so this instance is also added.
letI : (forget CommSemiRingCat.{u}).ReflectsIsomorphisms :=
CommSemiRingCat.forgetReflectIsos.{u}
letI : (forget₂ CommSemiRingCat.{u} SemiRingCat.{u}).ReflectsIsomorphisms :=
CategoryTheory.reflectsIsomorphisms_forget₂ CommSemiRingCat.{u} SemiRingCat.{u}
letI : 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 := (SemiRingCat.HasLimits.limitCone.{v, u}
(F ⋙ forget₂ CommSemiRingCat.{u} SemiRingCat.{u})).π.naturality } }
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 :=
letI : 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₂SemiRingPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ CommSemiRingCat SemiRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimitOfPreservesLimitCone (limitConeIsLimit.{v, u} F)
(SemiRingCat.HasLimits.limitConeIsLimit (F ⋙ forget₂ _ SemiRingCat)) }
instance forget₂SemiRingPreservesLimits :
PreservesLimits (forget₂ CommSemiRingCat SemiRingCat.{u}) :=
CommSemiRingCat.forget₂SemiRingPreservesLimitsOfSize.{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 forgetPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget CommSemiRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimitOfPreservesLimitCone (limitConeIsLimit.{v, u} F)
(Types.Small.limitConeIsLimit.{v, u} _) }
instance forgetPreservesLimits : PreservesLimits (forget CommSemiRingCat.{u}) :=
CommSemiRingCat.forgetPreservesLimitsOfSize.{u, u}
end CommSemiRingCat
-- Porting note: typemax hack to fix universe complaints
/-- An alias for `RingCat.{max u v}`, to deal around unification issues. -/
@[nolint checkUnivs]
abbrev RingCatMax.{u1, u2} := RingCat.{max u1 u2}
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) :=
letI f : J ⥤ AddGrp.{u} :=
F ⋙ forget₂ RingCat.{u} AddCommGrp.{u} ⋙
forget₂ AddCommGrp.{u} AddGrp.{u}
letI g : J ⥤ SemiRingCat.{u} := F ⋙ forget₂ RingCat.{u} SemiRingCat.{u}
{ AddGrp.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 :=
letI : 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 => 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 s => _) fun s => rfl }
/-- A choice of limit cone for a functor into `RingCat`.
(Generally, you'll just want to use `limit F`.)
-/
def limitCone : Cone F :=
letI : 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 :=
letI : 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₂SemiRingPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ RingCat SemiRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimitOfPreservesLimitCone (limitConeIsLimit.{v, u} F)
(SemiRingCat.HasLimits.limitConeIsLimit.{v, u} _) }
instance forget₂SemiRingPreservesLimits : PreservesLimits (forget₂ RingCat SemiRingCat.{u}) :=
RingCat.forget₂SemiRingPreservesLimitsOfSize.{u, u}
/-- An auxiliary declaration to speed up typechecking.
-/
def forget₂AddCommGroupPreservesLimitsAux :
IsLimit ((forget₂ RingCat.{u} AddCommGrp).mapCone (limitCone.{v, u} F)) := by
-- Porting note: inline `f` would not compile
letI f := F ⋙ forget₂ RingCat.{u} AddCommGrp.{u}
letI : Small.{u} (Functor.sections (f ⋙ forget _)) :=
inferInstanceAs <| Small.{u} (Functor.sections (F ⋙ forget _))
apply AddCommGrp.limitConeIsLimit.{v, u} f
/-- The forgetful functor from rings to additive commutative groups preserves all limits.
-/
instance forget₂AddCommGroupPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{v, v} (forget₂ RingCat.{u} AddCommGrp.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimitOfPreservesLimitCone (limitConeIsLimit.{v, u} F)
(forget₂AddCommGroupPreservesLimitsAux F) }
instance forget₂AddCommGroupPreservesLimits :
PreservesLimits (forget₂ RingCat AddCommGrp.{u}) :=
RingCat.forget₂AddCommGroupPreservesLimitsOfSize.{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 forgetPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{v, v} (forget RingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimitOfPreservesLimitCone (limitConeIsLimit.{v, u} F)
(Types.Small.limitConeIsLimit.{v, u} _) }
instance forgetPreservesLimits : PreservesLimits (forget RingCat.{u}) :=
RingCat.forgetPreservesLimitsOfSize.{u, u}
end RingCat
-- Porting note: typemax hack to fix universe complaints
/-- An alias for `CommRingCat.{max u v}`, to deal around unification issues. -/
@[nolint checkUnivs]
abbrev CommRingCatMax.{u1, u2} := CommRingCat.{max u1 u2}
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 :=
letI : 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 => 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 => ofHom <|
(RingCat.limitConeIsLimit.{v, u}
(F ⋙ forget₂ CommRingCat.{u} RingCat.{u})).lift
((forget₂ _ RingCat.{u}).mapCone s)) 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 :=
letI : 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 :=
letI : 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₂RingPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ CommRingCat RingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimitOfPreservesLimitCone.{w, v} (limitConeIsLimit.{v, u} F)
(RingCat.limitConeIsLimit.{v, u} _) }
instance forget₂RingPreservesLimits : PreservesLimits (forget₂ CommRingCat RingCat.{u}) :=
CommRingCat.forget₂RingPreservesLimitsOfSize.{u, u}
/-- An auxiliary declaration to speed up typechecking.
-/
def forget₂CommSemiRingPreservesLimitsAux :
IsLimit ((forget₂ CommRingCat CommSemiRingCat).mapCone (limitCone F)) := by
letI : 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₂CommSemiRingPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget₂ CommRingCat CommSemiRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimitOfPreservesLimitCone (limitConeIsLimit.{v, u} F)
(forget₂CommSemiRingPreservesLimitsAux.{v, u} F) }
instance forget₂CommSemiRingPreservesLimits :
PreservesLimits (forget₂ CommRingCat CommSemiRingCat.{u}) :=
CommRingCat.forget₂CommSemiRingPreservesLimitsOfSize.{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 forgetPreservesLimitsOfSize [UnivLE.{v, u}] :
PreservesLimitsOfSize.{w, v} (forget CommRingCat.{u}) where
preservesLimitsOfShape {_ _} :=
{ preservesLimit := fun {F} =>
preservesLimitOfPreservesLimitCone.{w, v} (limitConeIsLimit.{v, u} F)
(Types.Small.limitConeIsLimit.{v, u} _) }
instance forgetPreservesLimits : PreservesLimits (forget CommRingCat.{u}) :=
CommRingCat.forgetPreservesLimitsOfSize.{u, u}
end CommRingCat
|
Algebra\Category\Semigrp\Basic.lean
|
/-
Copyright (c) 2021 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import Mathlib.Algebra.PEmptyInstances
import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.CategoryTheory.ConcreteCategory.BundledHom
import Mathlib.CategoryTheory.Functor.ReflectsIso
/-!
# 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`.
## TODO
* Limits in these categories
* free/forgetful adjunctions
-/
universe u v
open CategoryTheory
/-- The category of magmas and magma morphisms. -/
@[to_additive]
def MagmaCat : Type (u + 1) :=
Bundled Mul
/-- The category of additive magmas and additive magma morphisms. -/
add_decl_doc AddMagmaCat
namespace MagmaCat
@[to_additive]
instance bundledHom : BundledHom @MulHom :=
⟨@MulHom.toFun, @MulHom.id, @MulHom.comp,
-- Porting note: was `@MulHom.coe_inj` which is deprecated
by intros; apply @DFunLike.coe_injective, by aesop_cat, by aesop_cat⟩
-- Porting note: deriving failed for `ConcreteCategory`,
-- "default handlers have not been implemented yet"
-- https://github.com/leanprover-community/mathlib4/issues/5020
deriving instance LargeCategory for MagmaCat
instance instConcreteCategory : ConcreteCategory MagmaCat := BundledHom.concreteCategory MulHom
attribute [to_additive] instMagmaCatLargeCategory instConcreteCategory
@[to_additive]
instance : CoeSort MagmaCat Type* where
coe X := X.α
-- Porting note: Hinting to Lean that `forget R` and `R` are the same
unif_hint forget_obj_eq_coe (R : MagmaCat) where ⊢
(forget MagmaCat).obj R ≟ R
unif_hint _root_.AddMagmaCat.forget_obj_eq_coe (R : AddMagmaCat) where ⊢
(forget AddMagmaCat).obj R ≟ R
@[to_additive]
instance (X : MagmaCat) : Mul X := X.str
@[to_additive]
instance instFunLike (X Y : MagmaCat) : FunLike (X ⟶ Y) X Y :=
inferInstanceAs <| FunLike (X →ₙ* Y) X Y
@[to_additive]
instance instMulHomClass (X Y : MagmaCat) : MulHomClass (X ⟶ Y) X Y :=
inferInstanceAs <| MulHomClass (X →ₙ* Y) X Y
/-- Construct a bundled `MagmaCat` from the underlying type and typeclass. -/
@[to_additive]
def of (M : Type u) [Mul M] : MagmaCat :=
Bundled.of M
/-- Construct a bundled `AddMagmaCat` from the underlying type and typeclass. -/
add_decl_doc AddMagmaCat.of
@[to_additive (attr := simp)]
theorem coe_of (R : Type u) [Mul R] : (MagmaCat.of R : Type u) = R :=
rfl
@[to_additive (attr := simp)]
lemma mulEquiv_coe_eq {X Y : Type _} [Mul X] [Mul Y] (e : X ≃* Y) :
(@DFunLike.coe (MagmaCat.of X ⟶ MagmaCat.of Y) _ (fun _ => (forget MagmaCat).obj _)
ConcreteCategory.instFunLike (e : X →ₙ* Y) : X → Y) = ↑e :=
rfl
/-- Typecheck a `MulHom` as a morphism in `MagmaCat`. -/
@[to_additive]
def ofHom {X Y : Type u} [Mul X] [Mul Y] (f : X →ₙ* Y) : of X ⟶ of Y := f
/-- Typecheck an `AddHom` as a morphism in `AddMagmaCat`. -/
add_decl_doc AddMagmaCat.ofHom
@[to_additive] -- Porting note: simp removed, simpNF says LHS simplifies to itself
theorem ofHom_apply {X Y : Type u} [Mul X] [Mul Y] (f : X →ₙ* Y) (x : X) : ofHom f x = f x :=
rfl
@[to_additive]
instance : Inhabited MagmaCat :=
⟨MagmaCat.of PEmpty⟩
end MagmaCat
/-- The category of semigroups and semigroup morphisms. -/
@[to_additive]
def Semigrp : Type (u + 1) :=
Bundled Semigroup
/-- The category of additive semigroups and semigroup morphisms. -/
add_decl_doc AddSemigrp
namespace Semigrp
@[to_additive]
instance : BundledHom.ParentProjection @Semigroup.toMul := ⟨⟩
deriving instance LargeCategory for Semigrp
-- Porting note: deriving failed for `ConcreteCategory`,
-- "default handlers have not been implemented yet"
-- https://github.com/leanprover-community/mathlib4/issues/5020
instance instConcreteCategory : ConcreteCategory Semigrp :=
BundledHom.concreteCategory (fun _ _ => _)
attribute [to_additive] instSemigrpLargeCategory Semigrp.instConcreteCategory
@[to_additive]
instance : CoeSort Semigrp Type* where
coe X := X.α
-- Porting note: Hinting to Lean that `forget R` and `R` are the same
unif_hint forget_obj_eq_coe (R : Semigrp) where ⊢
(forget Semigrp).obj R ≟ R
unif_hint _root_.AddSemigrp.forget_obj_eq_coe (R : AddSemigrp) where ⊢
(forget AddSemigrp).obj R ≟ R
@[to_additive]
instance (X : Semigrp) : Semigroup X := X.str
@[to_additive]
instance instFunLike (X Y : Semigrp) : FunLike (X ⟶ Y) X Y :=
inferInstanceAs <| FunLike (X →ₙ* Y) X Y
@[to_additive]
instance instMulHomClass (X Y : Semigrp) : MulHomClass (X ⟶ Y) X Y :=
inferInstanceAs <| MulHomClass (X →ₙ* Y) X Y
/-- Construct a bundled `Semigrp` from the underlying type and typeclass. -/
@[to_additive]
def of (M : Type u) [Semigroup M] : Semigrp :=
Bundled.of M
/-- Construct a bundled `AddSemigrp` from the underlying type and typeclass. -/
add_decl_doc AddSemigrp.of
@[to_additive (attr := simp)]
theorem coe_of (R : Type u) [Semigroup R] : (Semigrp.of R : Type u) = R :=
rfl
@[to_additive (attr := simp)]
lemma mulEquiv_coe_eq {X Y : Type _} [Semigroup X] [Semigroup Y] (e : X ≃* Y) :
(@DFunLike.coe (Semigrp.of X ⟶ Semigrp.of Y) _ (fun _ => (forget Semigrp).obj _)
ConcreteCategory.instFunLike (e : X →ₙ* Y) : X → Y) = ↑e :=
rfl
/-- Typecheck a `MulHom` as a morphism in `Semigrp`. -/
@[to_additive]
def ofHom {X Y : Type u} [Semigroup X] [Semigroup Y] (f : X →ₙ* Y) : of X ⟶ of Y :=
f
/-- Typecheck an `AddHom` as a morphism in `AddSemigrp`. -/
add_decl_doc AddSemigrp.ofHom
@[to_additive] -- Porting note: simp removed, simpNF says LHS simplifies to itself
theorem ofHom_apply {X Y : Type u} [Semigroup X] [Semigroup Y] (f : X →ₙ* Y) (x : X) :
ofHom f x = f x :=
rfl
@[to_additive]
instance : Inhabited Semigrp :=
⟨Semigrp.of PEmpty⟩
@[to_additive]
instance hasForgetToMagmaCat : HasForget₂ Semigrp MagmaCat :=
BundledHom.forget₂ _ _
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 := e.toMulHom
inv := e.symm.toMulHom
hom_inv_id := by
ext
simp_rw [comp_apply, toMulHom_eq_coe, MagmaCat.mulEquiv_coe_eq, symm_apply_apply, id_apply]
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 := e.toMulHom
inv := 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 i.inv i.hom_inv_id i.inv_hom_id
/-- 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 i.inv i.hom_inv_id i.inv_hom_id
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, 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, i.toEquiv with }
exact e.toSemigrpIso.isIso_hom
-- Porting note: this was added in order to ensure that `forget₂ CommMonCat MonCat`
-- automatically reflects isomorphisms
-- we could have used `CategoryTheory.ConcreteCategory.ReflectsIso` alternatively
@[to_additive]
instance Semigrp.forget₂_full : (forget₂ Semigrp MagmaCat).Full where
map_surjective f := ⟨f, 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
|
Algebra\CharP\Algebra.lean
|
/-
Copyright (c) 2021 Jon Eugster. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Eugster, Eric Wieser
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.FreeAlgebra
import Mathlib.RingTheory.Localization.FractionRing
/-!
# Characteristics of algebras
In this file we describe the characteristic of `R`-algebras.
In particular we are interested in the characteristic of free algebras over `R`
and the fraction field `FractionRing R`.
## Main results
- `charP_of_injective_algebraMap` If `R →+* A` is an injective algebra map
then `A` has the same characteristic as `R`.
Instances constructed from this result:
- Any `FreeAlgebra R X` has the same characteristic as `R`.
- The `FractionRing R` of an integral domain `R` has the same characteristic as `R`.
-/
/-- If a ring homomorphism `R →+* A` is injective then `A` has the same characteristic as `R`. -/
theorem charP_of_injective_ringHom {R A : Type*} [NonAssocSemiring R] [NonAssocSemiring A]
{f : R →+* A} (h : Function.Injective f) (p : ℕ) [CharP R p] : CharP A p where
cast_eq_zero_iff' x := by
rw [← CharP.cast_eq_zero_iff R p x, ← map_natCast f x, map_eq_zero_iff f h]
/-- If the algebra map `R →+* A` is injective then `A` has the same characteristic as `R`. -/
theorem charP_of_injective_algebraMap {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]
(h : Function.Injective (algebraMap R A)) (p : ℕ) [CharP R p] : CharP A p :=
charP_of_injective_ringHom h p
theorem charP_of_injective_algebraMap' (R A : Type*) [Field R] [Semiring A] [Algebra R A]
[Nontrivial A] (p : ℕ) [CharP R p] : CharP A p :=
charP_of_injective_algebraMap (algebraMap R A).injective p
/-- If a ring homomorphism `R →+* A` is injective and `R` has characteristic zero
then so does `A`. -/
theorem charZero_of_injective_ringHom {R A : Type*} [NonAssocSemiring R] [NonAssocSemiring A]
{f : R →+* A} (h : Function.Injective f) [CharZero R] : CharZero A where
cast_injective _ _ _ := CharZero.cast_injective <| h <| by simpa only [map_natCast f]
/-- If the algebra map `R →+* A` is injective and `R` has characteristic zero then so does `A`. -/
theorem charZero_of_injective_algebraMap {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]
(h : Function.Injective (algebraMap R A)) [CharZero R] : CharZero A :=
charZero_of_injective_ringHom h
/-- If `R →+* A` is injective, and `A` is of characteristic `p`, then `R` is also of
characteristic `p`. Similar to `RingHom.charZero`. -/
theorem RingHom.charP {R A : Type*} [NonAssocSemiring R] [NonAssocSemiring A] (f : R →+* A)
(H : Function.Injective f) (p : ℕ) [CharP A p] : CharP R p := by
obtain ⟨q, h⟩ := CharP.exists R
exact CharP.eq _ (charP_of_injective_ringHom H q) ‹CharP A p› ▸ h
/-- If `R →+* A` is injective, then `R` is of characteristic `p` if and only if `A` is also of
characteristic `p`. Similar to `RingHom.charZero_iff`. -/
theorem RingHom.charP_iff {R A : Type*} [NonAssocSemiring R] [NonAssocSemiring A] (f : R →+* A)
(H : Function.Injective f) (p : ℕ) : CharP R p ↔ CharP A p :=
⟨fun _ ↦ charP_of_injective_ringHom H p, fun _ ↦ f.charP H p⟩
/-!
As an application, a `ℚ`-algebra has characteristic zero.
-/
-- `CharP.charP_to_charZero A _ (charP_of_injective_algebraMap h 0)` does not work
-- here as it would require `Ring A`.
section QAlgebra
variable (R : Type*) [Nontrivial R]
/-- A nontrivial `ℚ`-algebra has `CharP` equal to zero.
This cannot be a (local) instance because it would immediately form a loop with the
instance `DivisionRing.toRatAlgebra`. It's probably easier to go the other way: prove `CharZero R`
and automatically receive an `Algebra ℚ R` instance.
-/
theorem algebraRat.charP_zero [Semiring R] [Algebra ℚ R] : CharP R 0 :=
charP_of_injective_algebraMap (algebraMap ℚ R).injective 0
/-- A nontrivial `ℚ`-algebra has characteristic zero.
This cannot be a (local) instance because it would immediately form a loop with the
instance `DivisionRing.toRatAlgebra`. It's probably easier to go the other way: prove `CharZero R`
and automatically receive an `Algebra ℚ R` instance.
-/
theorem algebraRat.charZero [Ring R] [Algebra ℚ R] : CharZero R :=
@CharP.charP_to_charZero R _ (algebraRat.charP_zero R)
end QAlgebra
/-!
An algebra over a field has the same characteristic as the field.
-/
section
variable (K L : Type*) [Field K] [CommSemiring L] [Nontrivial L] [Algebra K L]
theorem Algebra.charP_iff (p : ℕ) : CharP K p ↔ CharP L p :=
(algebraMap K L).charP_iff_charP p
theorem Algebra.ringChar_eq : ringChar K = ringChar L := by
rw [ringChar.eq_iff, Algebra.charP_iff K L]
apply ringChar.charP
end
namespace FreeAlgebra
variable {R X : Type*} [CommSemiring R] (p : ℕ)
/-- If `R` has characteristic `p`, then so does `FreeAlgebra R X`. -/
instance charP [CharP R p] : CharP (FreeAlgebra R X) p :=
charP_of_injective_algebraMap FreeAlgebra.algebraMap_leftInverse.injective p
/-- If `R` has characteristic `0`, then so does `FreeAlgebra R X`. -/
instance charZero [CharZero R] : CharZero (FreeAlgebra R X) :=
charZero_of_injective_algebraMap FreeAlgebra.algebraMap_leftInverse.injective
end FreeAlgebra
namespace IsFractionRing
variable (R : Type*) {K : Type*} [CommRing R] [Field K] [Algebra R K] [IsFractionRing R K]
variable (p : ℕ)
/-- If `R` has characteristic `p`, then so does Frac(R). -/
theorem charP_of_isFractionRing [CharP R p] : CharP K p :=
charP_of_injective_algebraMap (IsFractionRing.injective R K) p
/-- If `R` has characteristic `0`, then so does Frac(R). -/
theorem charZero_of_isFractionRing [CharZero R] : CharZero K :=
@CharP.charP_to_charZero K _ (charP_of_isFractionRing R 0)
variable [IsDomain R]
/-- If `R` has characteristic `p`, then so does `FractionRing R`. -/
instance charP [CharP R p] : CharP (FractionRing R) p :=
charP_of_isFractionRing R p
/-- If `R` has characteristic `0`, then so does `FractionRing R`. -/
instance charZero [CharZero R] : CharZero (FractionRing R) :=
charZero_of_isFractionRing R
end IsFractionRing
|
Algebra\CharP\Basic.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Joey van Langen, Casper Putz
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Data.Nat.Multiplicity
import Mathlib.Data.Nat.Choose.Sum
/-!
# Characteristic of semirings
-/
assert_not_exists orderOf
universe u v
open Finset
variable {R : Type*}
namespace Commute
variable [Semiring R] {p : ℕ} {x y : R}
protected theorem add_pow_prime_pow_eq (hp : p.Prime) (h : Commute x y) (n : ℕ) :
(x + y) ^ p ^ n =
x ^ p ^ n + y ^ p ^ n +
p * ∑ k ∈ Ioo 0 (p ^ n), x ^ k * y ^ (p ^ n - k) * ↑((p ^ n).choose k / p) := by
trans x ^ p ^ n + y ^ p ^ n + ∑ k ∈ Ioo 0 (p ^ n), x ^ k * y ^ (p ^ n - k) * (p ^ n).choose k
· simp_rw [h.add_pow, ← Nat.Ico_zero_eq_range, Nat.Ico_succ_right, Icc_eq_cons_Ico (zero_le _),
Finset.sum_cons, Ico_eq_cons_Ioo (pow_pos hp.pos _), Finset.sum_cons, tsub_self, tsub_zero,
pow_zero, Nat.choose_zero_right, Nat.choose_self, Nat.cast_one, mul_one, one_mul, ← add_assoc]
· congr 1
simp_rw [Finset.mul_sum, Nat.cast_comm, mul_assoc _ _ (p : R), ← Nat.cast_mul]
refine Finset.sum_congr rfl fun i hi => ?_
rw [mem_Ioo] at hi
rw [Nat.div_mul_cancel (hp.dvd_choose_pow hi.1.ne' hi.2.ne)]
protected theorem add_pow_prime_eq (hp : p.Prime) (h : Commute x y) :
(x + y) ^ p =
x ^ p + y ^ p + p * ∑ k ∈ Finset.Ioo 0 p, x ^ k * y ^ (p - k) * ↑(p.choose k / p) := by
simpa using h.add_pow_prime_pow_eq hp 1
protected theorem exists_add_pow_prime_pow_eq (hp : p.Prime) (h : Commute x y) (n : ℕ) :
∃ r, (x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n + p * r :=
⟨_, h.add_pow_prime_pow_eq hp n⟩
protected theorem exists_add_pow_prime_eq (hp : p.Prime) (h : Commute x y) :
∃ r, (x + y) ^ p = x ^ p + y ^ p + p * r :=
⟨_, h.add_pow_prime_eq hp⟩
end Commute
section CommSemiring
variable [CommSemiring R] {p : ℕ} {x y : R}
theorem add_pow_prime_pow_eq (hp : p.Prime) (x y : R) (n : ℕ) :
(x + y) ^ p ^ n =
x ^ p ^ n + y ^ p ^ n +
p * ∑ k ∈ Finset.Ioo 0 (p ^ n), x ^ k * y ^ (p ^ n - k) * ↑((p ^ n).choose k / p) :=
(Commute.all x y).add_pow_prime_pow_eq hp n
theorem add_pow_prime_eq (hp : p.Prime) (x y : R) :
(x + y) ^ p =
x ^ p + y ^ p + p * ∑ k ∈ Finset.Ioo 0 p, x ^ k * y ^ (p - k) * ↑(p.choose k / p) :=
(Commute.all x y).add_pow_prime_eq hp
theorem exists_add_pow_prime_pow_eq (hp : p.Prime) (x y : R) (n : ℕ) :
∃ r, (x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n + p * r :=
(Commute.all x y).exists_add_pow_prime_pow_eq hp n
theorem exists_add_pow_prime_eq (hp : p.Prime) (x y : R) :
∃ r, (x + y) ^ p = x ^ p + y ^ p + p * r :=
(Commute.all x y).exists_add_pow_prime_eq hp
end CommSemiring
variable (R)
theorem add_pow_char_of_commute [Semiring R] {p : ℕ} [hp : Fact p.Prime] [CharP R p] (x y : R)
(h : Commute x y) : (x + y) ^ p = x ^ p + y ^ p := by
let ⟨r, hr⟩ := h.exists_add_pow_prime_eq hp.out
simp [hr]
theorem add_pow_char_pow_of_commute [Semiring R] {p n : ℕ} [hp : Fact p.Prime] [CharP R p]
(x y : R) (h : Commute x y) : (x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n := by
let ⟨r, hr⟩ := h.exists_add_pow_prime_pow_eq hp.out n
simp [hr]
theorem sub_pow_char_of_commute [Ring R] {p : ℕ} [Fact p.Prime] [CharP R p] (x y : R)
(h : Commute x y) : (x - y) ^ p = x ^ p - y ^ p := by
rw [eq_sub_iff_add_eq, ← add_pow_char_of_commute _ _ _ (Commute.sub_left h rfl)]
simp
theorem sub_pow_char_pow_of_commute [Ring R] {p : ℕ} [Fact p.Prime] [CharP R p] {n : ℕ} (x y : R)
(h : Commute x y) : (x - y) ^ p ^ n = x ^ p ^ n - y ^ p ^ n := by
induction n with
| zero => simp
| succ n n_ih =>
rw [pow_succ, pow_mul, pow_mul, pow_mul, n_ih]
apply sub_pow_char_of_commute; apply Commute.pow_pow h
theorem add_pow_char [CommSemiring R] {p : ℕ} [Fact p.Prime] [CharP R p] (x y : R) :
(x + y) ^ p = x ^ p + y ^ p :=
add_pow_char_of_commute _ _ _ (Commute.all _ _)
theorem add_pow_char_pow [CommSemiring R] {p : ℕ} [Fact p.Prime] [CharP R p] {n : ℕ} (x y : R) :
(x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n :=
add_pow_char_pow_of_commute _ _ _ (Commute.all _ _)
theorem add_pow_eq_add_pow_mod_mul_pow_add_pow_div
[CommSemiring R] {p : ℕ} [Fact p.Prime] [CharP R p] {n : ℕ} (x y : R) :
(x + y) ^ n = (x + y) ^ (n % p) * (x ^ p + y ^ p) ^ (n / p) := by
rw [← add_pow_char, ← pow_mul, ← pow_add, Nat.mod_add_div]
theorem sub_pow_char [CommRing R] {p : ℕ} [Fact p.Prime] [CharP R p] (x y : R) :
(x - y) ^ p = x ^ p - y ^ p :=
sub_pow_char_of_commute _ _ _ (Commute.all _ _)
theorem sub_pow_char_pow [CommRing R] {p : ℕ} [Fact p.Prime] [CharP R p] {n : ℕ} (x y : R) :
(x - y) ^ p ^ n = x ^ p ^ n - y ^ p ^ n :=
sub_pow_char_pow_of_commute _ _ _ (Commute.all _ _)
theorem sub_pow_eq_sub_pow_mod_mul_pow_sub_pow_div
[CommRing R] {p : ℕ} [Fact p.Prime] [CharP R p] {n : ℕ} (x y : R) :
(x - y) ^ n = (x - y) ^ (n % p) * (x ^ p - y ^ p) ^ (n / p) := by
rw [← sub_pow_char, ← pow_mul, ← pow_add, Nat.mod_add_div]
theorem CharP.neg_one_pow_char [Ring R] (p : ℕ) [CharP R p] [Fact p.Prime] :
(-1 : R) ^ p = -1 := by
rw [eq_neg_iff_add_eq_zero]
nth_rw 2 [← one_pow p]
rw [← add_pow_char_of_commute R _ _ (Commute.one_right _), add_left_neg,
zero_pow (Fact.out (p := Nat.Prime p)).ne_zero]
theorem CharP.neg_one_pow_char_pow [Ring R] (p n : ℕ) [CharP R p] [Fact p.Prime] :
(-1 : R) ^ p ^ n = -1 := by
rw [eq_neg_iff_add_eq_zero]
nth_rw 2 [← one_pow (p ^ n)]
rw [← add_pow_char_pow_of_commute R _ _ (Commute.one_right _), add_left_neg,
zero_pow (pow_ne_zero _ (Fact.out (p := Nat.Prime p)).ne_zero)]
namespace CharP
section
variable [NonAssocRing R]
/-- The characteristic of a finite ring cannot be zero. -/
theorem char_ne_zero_of_finite (p : ℕ) [CharP R p] [Finite R] : p ≠ 0 := by
rintro rfl
haveI : CharZero R := charP_to_charZero R
cases nonempty_fintype R
exact absurd Nat.cast_injective (not_injective_infinite_finite ((↑) : ℕ → R))
theorem ringChar_ne_zero_of_finite [Finite R] : ringChar R ≠ 0 :=
char_ne_zero_of_finite R (ringChar R)
end
section Ring
variable [Ring R] [NoZeroDivisors R] [Nontrivial R] [Finite R]
theorem char_is_prime (p : ℕ) [CharP R p] : p.Prime :=
Or.resolve_right (char_is_prime_or_zero R p) (char_ne_zero_of_finite R p)
end Ring
end CharP
|
Algebra\CharP\CharAndCard.lean
|
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.GroupTheory.Perm.Cycle.Type
import Mathlib.RingTheory.Coprime.Lemmas
/-!
# Characteristic and cardinality
We prove some results relating characteristic and cardinality of finite rings
## Tags
characteristic, cardinality, ring
-/
/-- A prime `p` is a unit in a commutative ring `R` of nonzero characteristic iff it does not divide
the characteristic. -/
theorem isUnit_iff_not_dvd_char_of_ringChar_ne_zero (R : Type*) [CommRing R] (p : ℕ) [Fact p.Prime]
(hR : ringChar R ≠ 0) : IsUnit (p : R) ↔ ¬p ∣ ringChar R := by
have hch := CharP.cast_eq_zero R (ringChar R)
have hp : p.Prime := Fact.out
constructor
· rintro h₁ ⟨q, hq⟩
rcases IsUnit.exists_left_inv h₁ with ⟨a, ha⟩
have h₃ : ¬ringChar R ∣ q := by
rintro ⟨r, hr⟩
rw [hr, ← mul_assoc, mul_comm p, mul_assoc] at hq
nth_rw 1 [← mul_one (ringChar R)] at hq
exact Nat.Prime.not_dvd_one hp ⟨r, mul_left_cancel₀ hR hq⟩
have h₄ := mt (CharP.intCast_eq_zero_iff R (ringChar R) q).mp
apply_fun ((↑) : ℕ → R) at hq
apply_fun (· * ·) a at hq
rw [Nat.cast_mul, hch, mul_zero, ← mul_assoc, ha, one_mul] at hq
norm_cast at h₄
exact h₄ h₃ hq.symm
· intro h
rcases (hp.coprime_iff_not_dvd.mpr h).isCoprime with ⟨a, b, hab⟩
apply_fun ((↑) : ℤ → R) at hab
push_cast at hab
rw [hch, mul_zero, add_zero, mul_comm] at hab
exact isUnit_of_mul_eq_one (p : R) a hab
/-- A prime `p` is a unit in a finite commutative ring `R`
iff it does not divide the characteristic. -/
theorem isUnit_iff_not_dvd_char (R : Type*) [CommRing R] (p : ℕ) [Fact p.Prime] [Finite R] :
IsUnit (p : R) ↔ ¬p ∣ ringChar R :=
isUnit_iff_not_dvd_char_of_ringChar_ne_zero R p <| CharP.char_ne_zero_of_finite R (ringChar R)
/-- The prime divisors of the characteristic of a finite commutative ring are exactly
the prime divisors of its cardinality. -/
theorem prime_dvd_char_iff_dvd_card {R : Type*} [CommRing R] [Fintype R] (p : ℕ) [Fact p.Prime] :
p ∣ ringChar R ↔ p ∣ Fintype.card R := by
refine
⟨fun h =>
h.trans <|
Int.natCast_dvd_natCast.mp <|
(CharP.intCast_eq_zero_iff R (ringChar R) (Fintype.card R)).mp <|
mod_cast Nat.cast_card_eq_zero R,
fun h => ?_⟩
by_contra h₀
rcases exists_prime_addOrderOf_dvd_card p h with ⟨r, hr⟩
have hr₁ := addOrderOf_nsmul_eq_zero r
rw [hr, nsmul_eq_mul] at hr₁
rcases IsUnit.exists_left_inv ((isUnit_iff_not_dvd_char R p).mpr h₀) with ⟨u, hu⟩
apply_fun (· * ·) u at hr₁
rw [mul_zero, ← mul_assoc, hu, one_mul] at hr₁
exact mt AddMonoid.addOrderOf_eq_one_iff.mpr (ne_of_eq_of_ne hr (Nat.Prime.ne_one Fact.out)) hr₁
/-- A prime that does not divide the cardinality of a finite commutative ring `R`
is a unit in `R`. -/
theorem not_isUnit_prime_of_dvd_card {R : Type*} [CommRing R] [Fintype R] (p : ℕ) [Fact p.Prime]
(hp : p ∣ Fintype.card R) : ¬IsUnit (p : R) :=
mt (isUnit_iff_not_dvd_char R p).mp
(Classical.not_not.mpr ((prime_dvd_char_iff_dvd_card p).mpr hp))
lemma charP_of_card_eq_prime {R : Type*} [NonAssocRing R] [Fintype R] (p : ℕ) [hp : Fact p.Prime]
(hR : Fintype.card R = p) : CharP R p :=
have := Fintype.one_lt_card_iff_nontrivial.1 (hR ▸ hp.1.one_lt)
(CharP.charP_iff_prime_eq_zero hp.1).2 (hR ▸ Nat.cast_card_eq_zero R)
|
Algebra\CharP\Defs.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Joey van Langen, Casper Putz
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.Group.Fin.Basic
import Mathlib.Algebra.Group.ULift
import Mathlib.Data.Int.ModEq
import Mathlib.Data.Nat.Cast.Prod
import Mathlib.Data.Nat.Find
import Mathlib.Data.Nat.Prime.Defs
import Mathlib.Data.ULift
/-!
# Characteristic of semirings
-/
assert_not_exists Finset
variable (R : Type*)
namespace CharP
section AddMonoidWithOne
variable [AddMonoidWithOne R] (p : ℕ)
/-- The generator of the kernel of the unique homomorphism ℕ → R for a semiring R.
*Warning*: for a semiring `R`, `CharP R 0` and `CharZero R` need not coincide.
* `CharP R 0` asks that only `0 : ℕ` maps to `0 : R` under the map `ℕ → R`;
* `CharZero R` requires an injection `ℕ ↪ R`.
For instance, endowing `{0, 1}` with addition given by `max` (i.e. `1` is absorbing), shows that
`CharZero {0, 1}` does not hold and yet `CharP {0, 1} 0` does.
This example is formalized in `Counterexamples/CharPZeroNeCharZero.lean`.
-/
@[mk_iff]
class _root_.CharP : Prop where
cast_eq_zero_iff' : ∀ x : ℕ, (x : R) = 0 ↔ p ∣ x
variable [CharP R p] {a b : ℕ}
-- Porting note: the field of the structure had implicit arguments where they were
-- explicit in Lean 3
lemma cast_eq_zero_iff (a : ℕ) : (a : R) = 0 ↔ p ∣ a := cast_eq_zero_iff' a
variable {R} in
lemma congr {q : ℕ} (h : p = q) : CharP R q := h ▸ ‹CharP R p›
lemma natCast_eq_natCast' (h : a ≡ b [MOD p]) : (a : R) = b := by
wlog hle : a ≤ b
· exact (this R p h.symm (le_of_not_le hle)).symm
rw [Nat.modEq_iff_dvd' hle] at h
rw [← Nat.sub_add_cancel hle, Nat.cast_add, (cast_eq_zero_iff R p _).mpr h, zero_add]
@[simp] lemma cast_eq_zero : (p : R) = 0 := (cast_eq_zero_iff R p p).2 dvd_rfl
-- See note [no_index around OfNat.ofNat]
--
-- TODO: This lemma needs to be `@[simp]` for confluence in the presence of `CharP.cast_eq_zero` and
-- `Nat.cast_ofNat`, but with `no_index` on its entire LHS, it matches literally every expression so
-- is too expensive. If lean4#2867 is fixed in a performant way, this can be made `@[simp]`.
--
-- @[simp]
lemma ofNat_eq_zero [p.AtLeastTwo] : no_index (OfNat.ofNat p : R) = 0 := cast_eq_zero R p
lemma natCast_eq_natCast_mod (a : ℕ) : (a : R) = a % p :=
natCast_eq_natCast' R p (Nat.mod_modEq a p).symm
lemma eq {p q : ℕ} (_hp : CharP R p) (_hq : CharP R q) : p = q :=
Nat.dvd_antisymm ((cast_eq_zero_iff R p q).1 (cast_eq_zero _ _))
((cast_eq_zero_iff R q p).1 (cast_eq_zero _ _))
instance ofCharZero [CharZero R] : CharP R 0 where
cast_eq_zero_iff' x := by rw [zero_dvd_iff, ← Nat.cast_zero, Nat.cast_inj]
variable [IsRightCancelAdd R]
lemma natCast_eq_natCast : (a : R) = b ↔ a ≡ b [MOD p] := by
wlog hle : a ≤ b
· rw [eq_comm, this R p (le_of_not_le hle), Nat.ModEq.comm]
rw [Nat.modEq_iff_dvd' hle, ← cast_eq_zero_iff R p (b - a),
← add_right_cancel_iff (G := R) (a := a) (b := b - a), zero_add, ← Nat.cast_add,
Nat.sub_add_cancel hle, eq_comm]
lemma natCast_injOn_Iio : (Set.Iio p).InjOn ((↑) : ℕ → R) :=
fun _a ha _b hb hab ↦ ((natCast_eq_natCast _ _).1 hab).eq_of_lt_of_lt ha hb
end AddMonoidWithOne
section AddGroupWithOne
variable [AddGroupWithOne R] (p : ℕ) [CharP R p] {a b : ℤ}
lemma intCast_eq_zero_iff (a : ℤ) : (a : R) = 0 ↔ (p : ℤ) ∣ a := by
rcases lt_trichotomy a 0 with (h | rfl | h)
· rw [← neg_eq_zero, ← Int.cast_neg, ← dvd_neg]
lift -a to ℕ using neg_nonneg.mpr (le_of_lt h) with b
rw [Int.cast_natCast, CharP.cast_eq_zero_iff R p, Int.natCast_dvd_natCast]
· simp only [Int.cast_zero, eq_self_iff_true, dvd_zero]
· lift a to ℕ using le_of_lt h with b
rw [Int.cast_natCast, CharP.cast_eq_zero_iff R p, Int.natCast_dvd_natCast]
lemma intCast_eq_intCast : (a : R) = b ↔ a ≡ b [ZMOD p] := by
rw [eq_comm, ← sub_eq_zero, ← Int.cast_sub, CharP.intCast_eq_zero_iff R p, Int.modEq_iff_dvd]
lemma intCast_eq_intCast_mod : (a : R) = a % (p : ℤ) :=
(CharP.intCast_eq_intCast R p).mpr (Int.mod_modEq a p).symm
lemma charP_to_charZero [CharP R 0] : CharZero R :=
charZero_of_inj_zero fun n h0 => eq_zero_of_zero_dvd ((cast_eq_zero_iff R 0 n).mp h0)
lemma charP_zero_iff_charZero : CharP R 0 ↔ CharZero R :=
⟨fun _ ↦ charP_to_charZero R, fun _ ↦ ofCharZero R⟩
end AddGroupWithOne
section NonAssocSemiring
variable [NonAssocSemiring R]
lemma «exists» : ∃ p, CharP R p :=
letI := Classical.decEq R
by_cases
(fun H : ∀ p : ℕ, (p : R) = 0 → p = 0 =>
⟨0, ⟨fun x => by rw [zero_dvd_iff]; exact ⟨H x, by rintro rfl; simp⟩⟩⟩)
fun H =>
⟨Nat.find (not_forall.1 H),
⟨fun x =>
⟨fun H1 =>
Nat.dvd_of_mod_eq_zero
(by_contradiction fun H2 =>
Nat.find_min (not_forall.1 H)
(Nat.mod_lt x <|
Nat.pos_of_ne_zero <| not_of_not_imp <| Nat.find_spec (not_forall.1 H))
(not_imp_of_and_not
⟨by
rwa [← Nat.mod_add_div x (Nat.find (not_forall.1 H)), Nat.cast_add,
Nat.cast_mul,
of_not_not (not_not_of_not_imp <| Nat.find_spec (not_forall.1 H)),
zero_mul, add_zero] at H1,
H2⟩)),
fun H1 => by
rw [← Nat.mul_div_cancel' H1, Nat.cast_mul,
of_not_not (not_not_of_not_imp <| Nat.find_spec (not_forall.1 H)),
zero_mul]⟩⟩⟩
lemma exists_unique : ∃! p, CharP R p :=
let ⟨c, H⟩ := CharP.exists R
⟨c, H, fun _y H2 => CharP.eq R H2 H⟩
end NonAssocSemiring
end CharP
/-- Noncomputable function that outputs the unique characteristic of a semiring. -/
noncomputable def ringChar [NonAssocSemiring R] : ℕ := Classical.choose (CharP.exists_unique R)
namespace ringChar
variable [NonAssocSemiring R]
lemma spec : ∀ x : ℕ, (x : R) = 0 ↔ ringChar R ∣ x := by
letI : CharP R (ringChar R) := (Classical.choose_spec (CharP.exists_unique R)).1
exact CharP.cast_eq_zero_iff R (ringChar R)
lemma eq (p : ℕ) [C : CharP R p] : ringChar R = p :=
((Classical.choose_spec (CharP.exists_unique R)).2 p C).symm
instance charP : CharP R (ringChar R) :=
⟨spec R⟩
variable {R}
lemma of_eq {p : ℕ} (h : ringChar R = p) : CharP R p :=
CharP.congr (ringChar R) h
lemma eq_iff {p : ℕ} : ringChar R = p ↔ CharP R p :=
⟨of_eq, @eq R _ p⟩
lemma dvd {x : ℕ} (hx : (x : R) = 0) : ringChar R ∣ x :=
(spec R x).1 hx
@[simp]
lemma eq_zero [CharZero R] : ringChar R = 0 :=
eq R 0
-- @[simp] -- Porting note (#10618): simp can prove this
lemma Nat.cast_ringChar : (ringChar R : R) = 0 := by rw [ringChar.spec]
end ringChar
lemma CharP.neg_one_ne_one [Ring R] (p : ℕ) [CharP R p] [Fact (2 < p)] : (-1 : R) ≠ (1 : R) := by
suffices (2 : R) ≠ 0 by
intro h
symm at h
rw [← sub_eq_zero, sub_neg_eq_add] at h
norm_num at h
exact this h
-- Porting note: this could probably be golfed
intro h
rw [show (2 : R) = (2 : ℕ) by norm_cast] at h
have := (CharP.cast_eq_zero_iff R p 2).mp h
have := Nat.le_of_dvd (by decide) this
rw [fact_iff] at *
omega
lemma RingHom.charP_iff_charP {K L : Type*} [DivisionRing K] [Semiring L] [Nontrivial L]
(f : K →+* L) (p : ℕ) : CharP K p ↔ CharP L p := by
simp only [charP_iff, ← f.injective.eq_iff, map_natCast f, map_zero f]
namespace CharP
section
variable [NonAssocRing R]
lemma cast_eq_mod (p : ℕ) [CharP R p] (k : ℕ) : (k : R) = (k % p : ℕ) :=
calc
(k : R) = ↑(k % p + p * (k / p)) := by rw [Nat.mod_add_div]
_ = ↑(k % p) := by simp [cast_eq_zero]
lemma ringChar_zero_iff_CharZero : ringChar R = 0 ↔ CharZero R := by
rw [ringChar.eq_iff, charP_zero_iff_charZero]
end
section Semiring
variable [NonAssocSemiring R]
lemma char_ne_one [Nontrivial R] (p : ℕ) [hc : CharP R p] : p ≠ 1 := fun hp : p = 1 =>
have : (1 : R) = 0 := by simpa using (cast_eq_zero_iff R p 1).mpr (hp ▸ dvd_refl p)
absurd this one_ne_zero
section NoZeroDivisors
variable [NoZeroDivisors R]
lemma char_is_prime_of_two_le (p : ℕ) [hc : CharP R p] (hp : 2 ≤ p) : Nat.Prime p :=
suffices ∀ (d) (_ : d ∣ p), d = 1 ∨ d = p from Nat.prime_def_lt''.mpr ⟨hp, this⟩
fun (d : ℕ) (hdvd : ∃ e, p = d * e) =>
let ⟨e, hmul⟩ := hdvd
have : (p : R) = 0 := (cast_eq_zero_iff R p p).mpr (dvd_refl p)
have : (d : R) * e = 0 := @Nat.cast_mul R _ d e ▸ hmul ▸ this
Or.elim (eq_zero_or_eq_zero_of_mul_eq_zero this)
(fun hd : (d : R) = 0 =>
have : p ∣ d := (cast_eq_zero_iff R p d).mp hd
show d = 1 ∨ d = p from Or.inr (this.antisymm' ⟨e, hmul⟩))
fun he : (e : R) = 0 =>
have : p ∣ e := (cast_eq_zero_iff R p e).mp he
have : e ∣ p := dvd_of_mul_left_eq d (Eq.symm hmul)
have : e = p := ‹e ∣ p›.antisymm ‹p ∣ e›
have h₀ : 0 < p := by omega
have : d * p = 1 * p := by rw [‹e = p›] at hmul; rw [one_mul]; exact Eq.symm hmul
show d = 1 ∨ d = p from Or.inl (mul_right_cancel₀ h₀.ne' this)
section Nontrivial
variable [Nontrivial R]
lemma char_is_prime_or_zero (p : ℕ) [hc : CharP R p] : Nat.Prime p ∨ p = 0 :=
match p, hc with
| 0, _ => Or.inr rfl
| 1, hc => absurd (Eq.refl (1 : ℕ)) (@char_ne_one R _ _ (1 : ℕ) hc)
| m + 2, hc => Or.inl (@char_is_prime_of_two_le R _ _ (m + 2) hc (Nat.le_add_left 2 m))
lemma exists' (R : Type*) [NonAssocRing R] [NoZeroDivisors R] [Nontrivial R] :
CharZero R ∨ ∃ p : ℕ, Fact p.Prime ∧ CharP R p := by
obtain ⟨p, hchar⟩ := CharP.exists R
rcases char_is_prime_or_zero R p with h | rfl
exacts [Or.inr ⟨p, Fact.mk h, hchar⟩, Or.inl (charP_to_charZero R)]
lemma char_is_prime_of_pos (p : ℕ) [NeZero p] [CharP R p] : Fact p.Prime :=
⟨(CharP.char_is_prime_or_zero R _).resolve_right <| NeZero.ne p⟩
end Nontrivial
end NoZeroDivisors
end Semiring
section NonAssocSemiring
variable {R} [NonAssocSemiring R]
-- This lemma is not an instance, to make sure that trying to prove `α` is a subsingleton does
-- not try to find a ring structure on `α`, which can be expensive.
lemma CharOne.subsingleton [CharP R 1] : Subsingleton R :=
Subsingleton.intro <|
suffices ∀ r : R, r = 0 from fun a b => show a = b by rw [this a, this b]
fun r =>
calc
r = 1 * r := by rw [one_mul]
_ = (1 : ℕ) * r := by rw [Nat.cast_one]
_ = 0 * r := by rw [CharP.cast_eq_zero]
_ = 0 := by rw [zero_mul]
lemma false_of_nontrivial_of_char_one [Nontrivial R] [CharP R 1] : False := by
have : Subsingleton R := CharOne.subsingleton
exact false_of_nontrivial_of_subsingleton R
lemma ringChar_ne_one [Nontrivial R] : ringChar R ≠ 1 := by
intro h
apply zero_ne_one' R
symm
rw [← Nat.cast_one, ringChar.spec, h]
lemma nontrivial_of_char_ne_one {v : ℕ} (hv : v ≠ 1) [hr : CharP R v] : Nontrivial R :=
⟨⟨(1 : ℕ), 0, fun h =>
hv <| by rwa [CharP.cast_eq_zero_iff _ v, Nat.dvd_one] at h⟩⟩
lemma ringChar_of_prime_eq_zero [Nontrivial R] {p : ℕ} (hprime : Nat.Prime p)
(hp0 : (p : R) = 0) : ringChar R = p :=
Or.resolve_left ((Nat.dvd_prime hprime).1 (ringChar.dvd hp0)) ringChar_ne_one
lemma charP_iff_prime_eq_zero [Nontrivial R] {p : ℕ} (hp : p.Prime) :
CharP R p ↔ (p : R) = 0 :=
⟨fun _ => cast_eq_zero R p,
fun hp0 => (ringChar_of_prime_eq_zero hp hp0) ▸ inferInstance⟩
end NonAssocSemiring
end CharP
section
/-- We have `2 ≠ 0` in a nontrivial ring whose characteristic is not `2`. -/
protected lemma Ring.two_ne_zero {R : Type*} [NonAssocSemiring R] [Nontrivial R]
(hR : ringChar R ≠ 2) : (2 : R) ≠ 0 := by
rw [Ne, (by norm_cast : (2 : R) = (2 : ℕ)), ringChar.spec, Nat.dvd_prime Nat.prime_two]
exact mt (or_iff_left hR).mp CharP.ringChar_ne_one
-- We have `CharP.neg_one_ne_one`, which assumes `[Ring R] (p : ℕ) [CharP R p] [Fact (2 < p)]`.
-- This is a version using `ringChar` instead.
/-- Characteristic `≠ 2` and nontrivial implies that `-1 ≠ 1`. -/
lemma Ring.neg_one_ne_one_of_char_ne_two {R : Type*} [NonAssocRing R] [Nontrivial R]
(hR : ringChar R ≠ 2) : (-1 : R) ≠ 1 := fun h =>
Ring.two_ne_zero hR (one_add_one_eq_two (R := R) ▸ neg_eq_iff_add_eq_zero.mp h)
/-- Characteristic `≠ 2` in a domain implies that `-a = a` iff `a = 0`. -/
lemma Ring.eq_self_iff_eq_zero_of_char_ne_two {R : Type*} [NonAssocRing R] [Nontrivial R]
[NoZeroDivisors R] (hR : ringChar R ≠ 2) {a : R} : -a = a ↔ a = 0 :=
⟨fun h =>
(mul_eq_zero.mp <| (two_mul a).trans <| neg_eq_iff_add_eq_zero.mp h).resolve_left
(Ring.two_ne_zero hR),
fun h => ((congr_arg (fun x => -x) h).trans neg_zero).trans h.symm⟩
end
section Prod
variable (S : Type*) [AddMonoidWithOne R] [AddMonoidWithOne S] (p q : ℕ) [CharP R p]
/-- The characteristic of the product of rings is the least common multiple of the
characteristics of the two rings. -/
instance Nat.lcm.charP [CharP S q] : CharP (R × S) (Nat.lcm p q) where
cast_eq_zero_iff' := by
simp [Prod.ext_iff, CharP.cast_eq_zero_iff R p, CharP.cast_eq_zero_iff S q, Nat.lcm_dvd_iff]
/-- The characteristic of the product of two rings of the same characteristic
is the same as the characteristic of the rings -/
instance Prod.charP [CharP S p] : CharP (R × S) p := by
convert Nat.lcm.charP R S p p; simp
instance Prod.charZero_of_left [CharZero R] : CharZero (R × S) where
cast_injective _ _ h := CharZero.cast_injective congr(Prod.fst $h)
instance Prod.charZero_of_right [CharZero S] : CharZero (R × S) where
cast_injective _ _ h := CharZero.cast_injective congr(Prod.snd $h)
end Prod
instance ULift.charP [AddMonoidWithOne R] (p : ℕ) [CharP R p] : CharP (ULift R) p where
cast_eq_zero_iff' n := Iff.trans ULift.ext_iff <| CharP.cast_eq_zero_iff R p n
instance MulOpposite.charP [AddMonoidWithOne R] (p : ℕ) [CharP R p] : CharP Rᵐᵒᵖ p where
cast_eq_zero_iff' n := MulOpposite.unop_inj.symm.trans <| CharP.cast_eq_zero_iff R p n
section
/-- If two integers from `{0, 1, -1}` result in equal elements in a ring `R`
that is nontrivial and of characteristic not `2`, then they are equal. -/
lemma Int.cast_injOn_of_ringChar_ne_two {R : Type*} [NonAssocRing R] [Nontrivial R]
(hR : ringChar R ≠ 2) : ({0, 1, -1} : Set ℤ).InjOn ((↑) : ℤ → R) := by
rintro _ (rfl | rfl | rfl) _ (rfl | rfl | rfl) h <;>
simp only
[cast_neg, cast_one, cast_zero, neg_eq_zero, one_ne_zero, zero_ne_one, zero_eq_neg] at h ⊢
· exact ((Ring.neg_one_ne_one_of_char_ne_two hR).symm h).elim
· exact ((Ring.neg_one_ne_one_of_char_ne_two hR) h).elim
end
namespace NeZero
variable [AddMonoidWithOne R] {r : R} {n p : ℕ}
lemma of_not_dvd [CharP R p] (h : ¬p ∣ n) : NeZero (n : R) :=
⟨(CharP.cast_eq_zero_iff R p n).not.mpr h⟩
lemma not_char_dvd (p : ℕ) [CharP R p] (k : ℕ) [h : NeZero (k : R)] : ¬p ∣ k := by
rwa [← CharP.cast_eq_zero_iff R p k, ← Ne, ← neZero_iff]
end NeZero
namespace CharZero
lemma charZero_iff_forall_prime_ne_zero [NonAssocRing R] [NoZeroDivisors R] [Nontrivial R] :
CharZero R ↔ ∀ p : ℕ, p.Prime → (p : R) ≠ 0 := by
refine ⟨fun h p hp => by simp [hp.ne_zero], fun h => ?_⟩
let p := ringChar R
cases CharP.char_is_prime_or_zero R p with
| inl hp => simpa using h p hp
| inr h => have : CharP R 0 := h ▸ inferInstance; exact CharP.charP_to_charZero R
end CharZero
namespace Fin
instance charP (n : ℕ) : CharP (Fin (n + 1)) (n + 1) where
cast_eq_zero_iff' := by simp [Fin.ext_iff, Nat.dvd_iff_mod_eq_zero]
end Fin
|
Algebra\CharP\ExpChar.lean
|
/-
Copyright (c) 2021 Jakob Scholbach. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob Scholbach
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.CharP.Algebra
import Mathlib.Data.Nat.Prime.Defs
/-!
# Exponential characteristic
This file defines the exponential characteristic, which is defined to be 1 for a ring with
characteristic 0 and the same as the ordinary characteristic, if the ordinary characteristic is
prime. This concept is useful to simplify some theorem statements.
This file establishes a few basic results relating it to the (ordinary characteristic).
The definition is stated for a semiring, but the actual results are for nontrivial rings
(as far as exponential characteristic one is concerned), respectively a ring without zero-divisors
(for prime characteristic).
## Main results
- `ExpChar`: the definition of exponential characteristic
- `expChar_is_prime_or_one`: the exponential characteristic is a prime or one
- `char_eq_expChar_iff`: the characteristic equals the exponential characteristic iff the
characteristic is prime
## Tags
exponential characteristic, characteristic
-/
universe u
variable (R : Type u)
section Semiring
variable [Semiring R]
/-- The definition of the exponential characteristic of a semiring. -/
class inductive ExpChar (R : Type u) [Semiring R] : ℕ → Prop
| zero [CharZero R] : ExpChar R 1
| prime {q : ℕ} (hprime : q.Prime) [hchar : CharP R q] : ExpChar R q
instance expChar_prime (p) [CharP R p] [Fact p.Prime] : ExpChar R p := ExpChar.prime Fact.out
instance expChar_zero [CharZero R] : ExpChar R 1 := ExpChar.zero
instance (S : Type*) [Semiring S] (p) [ExpChar R p] [ExpChar S p] : ExpChar (R × S) p := by
obtain hp | ⟨hp⟩ := ‹ExpChar R p›
· have := Prod.charZero_of_left R S; exact .zero
obtain _ | _ := ‹ExpChar S p›
· exact (Nat.not_prime_one hp).elim
· have := Prod.charP R S p; exact .prime hp
variable {R} in
/-- The exponential characteristic is unique. -/
theorem ExpChar.eq {p q : ℕ} (hp : ExpChar R p) (hq : ExpChar R q) : p = q := by
cases' hp with hp _ hp' hp
· cases' hq with hq _ hq' hq
exacts [rfl, False.elim (Nat.not_prime_zero (CharP.eq R hq (CharP.ofCharZero R) ▸ hq'))]
· cases' hq with hq _ hq' hq
exacts [False.elim (Nat.not_prime_zero (CharP.eq R hp (CharP.ofCharZero R) ▸ hp')),
CharP.eq R hp hq]
theorem ExpChar.congr {p : ℕ} (q : ℕ) [hq : ExpChar R q] (h : q = p) : ExpChar R p := h ▸ hq
/-- Noncomputable function that outputs the unique exponential characteristic of a semiring. -/
noncomputable def ringExpChar (R : Type*) [NonAssocSemiring R] : ℕ := max (ringChar R) 1
theorem ringExpChar.eq (q : ℕ) [h : ExpChar R q] : ringExpChar R = q := by
cases' h with _ _ h _
· haveI := CharP.ofCharZero R
rw [ringExpChar, ringChar.eq R 0]; rfl
rw [ringExpChar, ringChar.eq R q]
exact Nat.max_eq_left h.one_lt.le
@[simp]
theorem ringExpChar.eq_one (R : Type*) [NonAssocSemiring R] [CharZero R] : ringExpChar R = 1 := by
rw [ringExpChar, ringChar.eq_zero, max_eq_right zero_le_one]
/-- The exponential characteristic is one if the characteristic is zero. -/
theorem expChar_one_of_char_zero (q : ℕ) [hp : CharP R 0] [hq : ExpChar R q] : q = 1 := by
cases' hq with q hq_one hq_prime hq_hchar
· rfl
· exact False.elim <| hq_prime.ne_zero <| hq_hchar.eq R hp
/-- The characteristic equals the exponential characteristic iff the former is prime. -/
theorem char_eq_expChar_iff (p q : ℕ) [hp : CharP R p] [hq : ExpChar R q] : p = q ↔ p.Prime := by
cases' hq with q hq_one hq_prime hq_hchar
· rw [(CharP.eq R hp inferInstance : p = 0)]
decide
· exact ⟨fun hpq => hpq.symm ▸ hq_prime, fun _ => CharP.eq R hp hq_hchar⟩
/-- The exponential characteristic is a prime number or one.
See also `CharP.char_is_prime_or_zero`. -/
theorem expChar_is_prime_or_one (q : ℕ) [hq : ExpChar R q] : Nat.Prime q ∨ q = 1 := by
cases hq with
| zero => exact .inr rfl
| prime hp => exact .inl hp
/-- The exponential characteristic is positive. -/
theorem expChar_pos (q : ℕ) [ExpChar R q] : 0 < q := by
rcases expChar_is_prime_or_one R q with h | rfl
exacts [Nat.Prime.pos h, Nat.one_pos]
/-- Any power of the exponential characteristic is positive. -/
theorem expChar_pow_pos (q : ℕ) [ExpChar R q] (n : ℕ) : 0 < q ^ n :=
Nat.pos_pow_of_pos n (expChar_pos R q)
section Nontrivial
variable [Nontrivial R]
/-- The exponential characteristic is one if the characteristic is zero. -/
theorem char_zero_of_expChar_one (p : ℕ) [hp : CharP R p] [hq : ExpChar R 1] : p = 0 := by
cases hq
· exact CharP.eq R hp inferInstance
· exact False.elim (CharP.char_ne_one R 1 rfl)
-- This could be an instance, but there are no `ExpChar R 1` instances in mathlib.
/-- The characteristic is zero if the exponential characteristic is one. -/
theorem charZero_of_expChar_one' [hq : ExpChar R 1] : CharZero R := by
cases hq
· assumption
· exact False.elim (CharP.char_ne_one R 1 rfl)
/-- The exponential characteristic is one iff the characteristic is zero. -/
theorem expChar_one_iff_char_zero (p q : ℕ) [CharP R p] [ExpChar R q] : q = 1 ↔ p = 0 := by
constructor
· rintro rfl
exact char_zero_of_expChar_one R p
· rintro rfl
exact expChar_one_of_char_zero R q
section NoZeroDivisors
variable [NoZeroDivisors R]
/-- A helper lemma: the characteristic is prime if it is non-zero. -/
theorem char_prime_of_ne_zero {p : ℕ} [hp : CharP R p] (p_ne_zero : p ≠ 0) : Nat.Prime p := by
cases' CharP.char_is_prime_or_zero R p with h h
· exact h
· contradiction
end NoZeroDivisors
end Nontrivial
end Semiring
theorem ExpChar.exists [Ring R] [IsDomain R] : ∃ q, ExpChar R q := by
obtain _ | ⟨p, ⟨hp⟩, _⟩ := CharP.exists' R
exacts [⟨1, .zero⟩, ⟨p, .prime hp⟩]
theorem ExpChar.exists_unique [Ring R] [IsDomain R] : ∃! q, ExpChar R q :=
let ⟨q, H⟩ := ExpChar.exists R
⟨q, H, fun _ H2 ↦ ExpChar.eq H2 H⟩
instance ringExpChar.expChar [Ring R] [IsDomain R] : ExpChar R (ringExpChar R) := by
obtain ⟨q, _⟩ := ExpChar.exists R
rwa [ringExpChar.eq R q]
variable {R} in
theorem ringExpChar.of_eq [Ring R] [IsDomain R] {q : ℕ} (h : ringExpChar R = q) : ExpChar R q :=
h ▸ ringExpChar.expChar R
variable {R} in
theorem ringExpChar.eq_iff [Ring R] [IsDomain R] {q : ℕ} : ringExpChar R = q ↔ ExpChar R q :=
⟨ringExpChar.of_eq, fun _ ↦ ringExpChar.eq R q⟩
/-- If a ring homomorphism `R →+* A` is injective then `A` has the same exponential characteristic
as `R`. -/
theorem expChar_of_injective_ringHom {R A : Type*}
[Semiring R] [Semiring A] {f : R →+* A} (h : Function.Injective f)
(q : ℕ) [hR : ExpChar R q] : ExpChar A q := by
cases' hR with _ _ hprime _
· haveI := charZero_of_injective_ringHom h; exact .zero
haveI := charP_of_injective_ringHom h q; exact .prime hprime
/-- If `R →+* A` is injective, and `A` is of exponential characteristic `p`, then `R` is also of
exponential characteristic `p`. Similar to `RingHom.charZero`. -/
theorem RingHom.expChar {R A : Type*} [Semiring R] [Semiring A] (f : R →+* A)
(H : Function.Injective f) (p : ℕ) [ExpChar A p] : ExpChar R p := by
cases ‹ExpChar A p› with
| zero => haveI := f.charZero; exact .zero
| prime hp => haveI := f.charP H p; exact .prime hp
/-- If `R →+* A` is injective, then `R` is of exponential characteristic `p` if and only if `A` is
also of exponential characteristic `p`. Similar to `RingHom.charZero_iff`. -/
theorem RingHom.expChar_iff {R A : Type*} [Semiring R] [Semiring A] (f : R →+* A)
(H : Function.Injective f) (p : ℕ) : ExpChar R p ↔ ExpChar A p :=
⟨fun _ ↦ expChar_of_injective_ringHom H p, fun _ ↦ f.expChar H p⟩
/-- If the algebra map `R →+* A` is injective then `A` has the same exponential characteristic
as `R`. -/
theorem expChar_of_injective_algebraMap {R A : Type*}
[CommSemiring R] [Semiring A] [Algebra R A] (h : Function.Injective (algebraMap R A))
(q : ℕ) [ExpChar R q] : ExpChar A q := expChar_of_injective_ringHom h q
theorem add_pow_expChar_of_commute [Semiring R] {q : ℕ} [hR : ExpChar R q]
(x y : R) (h : Commute x y) : (x + y) ^ q = x ^ q + y ^ q := by
cases' hR with _ _ hprime _
· simp only [pow_one]
haveI := Fact.mk hprime; exact add_pow_char_of_commute R x y h
theorem add_pow_expChar_pow_of_commute [Semiring R] {q : ℕ} [hR : ExpChar R q]
{n : ℕ} (x y : R) (h : Commute x y) : (x + y) ^ q ^ n = x ^ q ^ n + y ^ q ^ n := by
cases' hR with _ _ hprime _
· simp only [one_pow, pow_one]
haveI := Fact.mk hprime; exact add_pow_char_pow_of_commute R x y h
theorem sub_pow_expChar_of_commute [Ring R] {q : ℕ} [hR : ExpChar R q]
(x y : R) (h : Commute x y) : (x - y) ^ q = x ^ q - y ^ q := by
cases' hR with _ _ hprime _
· simp only [pow_one]
haveI := Fact.mk hprime; exact sub_pow_char_of_commute R x y h
theorem sub_pow_expChar_pow_of_commute [Ring R] {q : ℕ} [hR : ExpChar R q]
{n : ℕ} (x y : R) (h : Commute x y) : (x - y) ^ q ^ n = x ^ q ^ n - y ^ q ^ n := by
cases' hR with _ _ hprime _
· simp only [one_pow, pow_one]
haveI := Fact.mk hprime; exact sub_pow_char_pow_of_commute R x y h
theorem add_pow_expChar [CommSemiring R] {q : ℕ} [hR : ExpChar R q]
(x y : R) : (x + y) ^ q = x ^ q + y ^ q := by
cases' hR with _ _ hprime _
· simp only [pow_one]
haveI := Fact.mk hprime; exact add_pow_char R x y
theorem add_pow_expChar_pow [CommSemiring R] {q : ℕ} [hR : ExpChar R q]
{n : ℕ} (x y : R) : (x + y) ^ q ^ n = x ^ q ^ n + y ^ q ^ n := by
cases' hR with _ _ hprime _
· simp only [one_pow, pow_one]
haveI := Fact.mk hprime; exact add_pow_char_pow R x y
theorem sub_pow_expChar [CommRing R] {q : ℕ} [hR : ExpChar R q]
(x y : R) : (x - y) ^ q = x ^ q - y ^ q := by
cases' hR with _ _ hprime _
· simp only [pow_one]
haveI := Fact.mk hprime; exact sub_pow_char R x y
theorem sub_pow_expChar_pow [CommRing R] {q : ℕ} [hR : ExpChar R q]
{n : ℕ} (x y : R) : (x - y) ^ q ^ n = x ^ q ^ n - y ^ q ^ n := by
cases' hR with _ _ hprime _
· simp only [one_pow, pow_one]
haveI := Fact.mk hprime; exact sub_pow_char_pow R x y
theorem ExpChar.neg_one_pow_expChar [Ring R] (q : ℕ) [hR : ExpChar R q] :
(-1 : R) ^ q = -1 := by
cases' hR with _ _ hprime _
· simp only [pow_one]
haveI := Fact.mk hprime; exact CharP.neg_one_pow_char R q
theorem ExpChar.neg_one_pow_expChar_pow [Ring R] (q n : ℕ) [hR : ExpChar R q] :
(-1 : R) ^ q ^ n = -1 := by
cases' hR with _ _ hprime _
· simp only [one_pow, pow_one]
haveI := Fact.mk hprime; exact CharP.neg_one_pow_char_pow R q n
section frobenius
section CommSemiring
variable [CommSemiring R] {S : Type*} [CommSemiring S] (f : R →* S) (g : R →+* S) (p m n : ℕ)
[ExpChar R p] [ExpChar S p] (x y : R)
/-- The frobenius map that sends x to x^p -/
def frobenius : R →+* R where
__ := powMonoidHom p
map_zero' := zero_pow (expChar_pos R p).ne'
map_add' := add_pow_expChar R
/-- The iterated frobenius map sending x to x^p^n -/
def iterateFrobenius : R →+* R where
__ := powMonoidHom (p ^ n)
map_zero' := zero_pow (expChar_pow_pos R p n).ne'
map_add' := add_pow_expChar_pow R
variable {R}
theorem frobenius_def : frobenius R p x = x ^ p := rfl
theorem iterateFrobenius_def : iterateFrobenius R p n x = x ^ p ^ n := rfl
theorem iterate_frobenius : (frobenius R p)^[n] x = x ^ p ^ n := congr_fun (pow_iterate p n) x
variable (R)
theorem coe_iterateFrobenius : iterateFrobenius R p n = (frobenius R p)^[n] :=
(pow_iterate p n).symm
theorem iterateFrobenius_one_apply : iterateFrobenius R p 1 x = x ^ p := by
rw [iterateFrobenius_def, pow_one]
@[simp]
theorem iterateFrobenius_one : iterateFrobenius R p 1 = frobenius R p :=
RingHom.ext (iterateFrobenius_one_apply R p)
theorem iterateFrobenius_zero_apply : iterateFrobenius R p 0 x = x := by
rw [iterateFrobenius_def, pow_zero, pow_one]
@[simp]
theorem iterateFrobenius_zero : iterateFrobenius R p 0 = RingHom.id R :=
RingHom.ext (iterateFrobenius_zero_apply R p)
theorem iterateFrobenius_add_apply :
iterateFrobenius R p (m + n) x = iterateFrobenius R p m (iterateFrobenius R p n x) := by
simp_rw [iterateFrobenius_def, add_comm m n, pow_add, pow_mul]
theorem iterateFrobenius_add :
iterateFrobenius R p (m + n) = (iterateFrobenius R p m).comp (iterateFrobenius R p n) :=
RingHom.ext (iterateFrobenius_add_apply R p m n)
theorem iterateFrobenius_mul_apply :
iterateFrobenius R p (m * n) x = (iterateFrobenius R p m)^[n] x := by
simp_rw [coe_iterateFrobenius, Function.iterate_mul]
theorem coe_iterateFrobenius_mul : iterateFrobenius R p (m * n) = (iterateFrobenius R p m)^[n] :=
funext (iterateFrobenius_mul_apply R p m n)
variable {R}
theorem frobenius_mul : frobenius R p (x * y) = frobenius R p x * frobenius R p y :=
map_mul (frobenius R p) x y
theorem frobenius_one : frobenius R p 1 = 1 :=
one_pow _
theorem MonoidHom.map_frobenius : f (frobenius R p x) = frobenius S p (f x) :=
map_pow f x p
theorem RingHom.map_frobenius : g (frobenius R p x) = frobenius S p (g x) :=
map_pow g x p
theorem MonoidHom.map_iterate_frobenius (n : ℕ) :
f ((frobenius R p)^[n] x) = (frobenius S p)^[n] (f x) :=
Function.Semiconj.iterate_right (f.map_frobenius p) n x
theorem RingHom.map_iterate_frobenius (n : ℕ) :
g ((frobenius R p)^[n] x) = (frobenius S p)^[n] (g x) :=
g.toMonoidHom.map_iterate_frobenius p x n
theorem MonoidHom.iterate_map_frobenius (f : R →* R) (p : ℕ) [ExpChar R p] (n : ℕ) :
f^[n] (frobenius R p x) = frobenius R p (f^[n] x) :=
iterate_map_pow f _ _ _
theorem RingHom.iterate_map_frobenius (f : R →+* R) (p : ℕ) [ExpChar R p] (n : ℕ) :
f^[n] (frobenius R p x) = frobenius R p (f^[n] x) :=
iterate_map_pow f _ _ _
variable (R S)
/-- The frobenius map of an algebra as a frobenius-semilinear map. -/
nonrec def LinearMap.frobenius [Algebra R S] : S →ₛₗ[frobenius R p] S where
__ := frobenius S p
map_smul' r s := show frobenius S p _ = _ by
simp_rw [Algebra.smul_def, map_mul, ← (algebraMap R S).map_frobenius]; rfl
/-- The iterated frobenius map of an algebra as a iterated-frobenius-semilinear map. -/
nonrec def LinearMap.iterateFrobenius [Algebra R S] : S →ₛₗ[iterateFrobenius R p n] S where
__ := iterateFrobenius S p n
map_smul' f s := show iterateFrobenius S p n _ = _ by
simp_rw [iterateFrobenius_def, Algebra.smul_def, mul_pow, ← map_pow]; rfl
theorem LinearMap.frobenius_def [Algebra R S] (x : S) : frobenius R S p x = x ^ p := rfl
theorem LinearMap.iterateFrobenius_def [Algebra R S] (n : ℕ) (x : S) :
iterateFrobenius R S p n x = x ^ p ^ n := rfl
theorem frobenius_zero : frobenius R p 0 = 0 :=
(frobenius R p).map_zero
theorem frobenius_add : frobenius R p (x + y) = frobenius R p x + frobenius R p y :=
(frobenius R p).map_add x y
theorem frobenius_natCast (n : ℕ) : frobenius R p n = n :=
map_natCast (frobenius R p) n
@[deprecated (since := "2024-04-17")]
alias frobenius_nat_cast := frobenius_natCast
variable {R}
theorem list_sum_pow_char (l : List R) : l.sum ^ p = (l.map (· ^ p : R → R)).sum :=
map_list_sum (frobenius R p) _
theorem multiset_sum_pow_char (s : Multiset R) : s.sum ^ p = (s.map (· ^ p : R → R)).sum :=
map_multiset_sum (frobenius R p) _
theorem sum_pow_char {ι : Type*} (s : Finset ι) (f : ι → R) :
(∑ i ∈ s, f i) ^ p = ∑ i ∈ s, f i ^ p :=
map_sum (frobenius R p) _ _
variable (n : ℕ)
theorem list_sum_pow_char_pow (l : List R) : l.sum ^ p ^ n = (l.map (· ^ p ^ n : R → R)).sum :=
map_list_sum (iterateFrobenius R p n) _
theorem multiset_sum_pow_char_pow (s : Multiset R) :
s.sum ^ p ^ n = (s.map (· ^ p ^ n : R → R)).sum :=
map_multiset_sum (iterateFrobenius R p n) _
theorem sum_pow_char_pow {ι : Type*} (s : Finset ι) (f : ι → R) :
(∑ i ∈ s, f i) ^ p ^ n = ∑ i ∈ s, f i ^ p ^ n :=
map_sum (iterateFrobenius R p n) _ _
end CommSemiring
section CommRing
variable [CommRing R] (p : ℕ) [ExpChar R p] (x y : R)
theorem frobenius_neg : frobenius R p (-x) = -frobenius R p x :=
map_neg ..
theorem frobenius_sub : frobenius R p (x - y) = frobenius R p x - frobenius R p y :=
map_sub ..
end CommRing
end frobenius
|
Algebra\CharP\IntermediateField.lean
|
/-
Copyright (c) 2024 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.FieldTheory.IntermediateField
import Mathlib.Algebra.CharP.ExpChar
/-!
# Characteristic of intermediate fields
This file contains some convenient instances for determining the characteristic of
intermediate fields. Some char zero instances are not provided, since they are already
covered by `SubsemiringClass.instCharZero`.
-/
variable {F E : Type*} [Field F] [Field E] [Algebra F E]
namespace Subfield
variable (L : Subfield F) (p : ℕ)
instance charP [CharP F p] : CharP L p := RingHom.charP _ (algebraMap _ F).injective p
instance expChar [ExpChar F p] : ExpChar L p := RingHom.expChar _ (algebraMap _ F).injective p
end Subfield
namespace IntermediateField
variable (L : IntermediateField F E) (p : ℕ)
instance charZero [CharZero F] : CharZero L :=
charZero_of_injective_algebraMap (algebraMap F _).injective
instance charP [CharP F p] : CharP L p :=
charP_of_injective_algebraMap (algebraMap F _).injective p
instance expChar [ExpChar F p] : ExpChar L p :=
expChar_of_injective_algebraMap (algebraMap F _).injective p
instance charP' [CharP E p] : CharP L p := Subfield.charP L.toSubfield p
instance expChar' [ExpChar E p] : ExpChar L p := Subfield.expChar L.toSubfield p
end IntermediateField
|
Algebra\CharP\Invertible.lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.CharP.Defs
/-!
# Invertibility of elements given a characteristic
This file includes some instances of `Invertible` for specific numbers in
characteristic zero. Some more cases are given as a `def`, to be included only
when needed. To construct instances for concrete numbers,
`invertibleOfNonzero` is a useful definition.
-/
variable {K : Type*}
section Field
variable [Field K]
/-- A natural number `t` is invertible in a field `K` if the characteristic of `K` does not divide
`t`. -/
def invertibleOfRingCharNotDvd {t : ℕ} (not_dvd : ¬ringChar K ∣ t) : Invertible (t : K) :=
invertibleOfNonzero fun h => not_dvd ((ringChar.spec K t).mp h)
theorem not_ringChar_dvd_of_invertible {t : ℕ} [Invertible (t : K)] : ¬ringChar K ∣ t := by
rw [← ringChar.spec, ← Ne]
exact nonzero_of_invertible (t : K)
/-- A natural number `t` is invertible in a field `K` of characteristic `p` if `p` does not divide
`t`. -/
def invertibleOfCharPNotDvd {p : ℕ} [CharP K p] {t : ℕ} (not_dvd : ¬p ∣ t) : Invertible (t : K) :=
invertibleOfNonzero fun h => not_dvd ((CharP.cast_eq_zero_iff K p t).mp h)
-- warning: this could potentially loop with `Invertible.ne_zero` - if there is weird type-class
-- loops, watch out for that.
instance invertibleOfPos [CharZero K] (n : ℕ) [NeZero n] : Invertible (n : K) :=
invertibleOfNonzero <| NeZero.out
end Field
section DivisionRing
variable [DivisionRing K] [CharZero K]
instance invertibleSucc (n : ℕ) : Invertible (n.succ : K) :=
invertibleOfNonzero (Nat.cast_ne_zero.mpr (Nat.succ_ne_zero _))
/-!
A few `Invertible n` instances for small numerals `n`. Feel free to add your own
number when you need its inverse.
-/
instance invertibleTwo : Invertible (2 : K) :=
invertibleOfNonzero (mod_cast (by decide : 2 ≠ 0))
instance invertibleThree : Invertible (3 : K) :=
invertibleOfNonzero (mod_cast (by decide : 3 ≠ 0))
end DivisionRing
|
Algebra\CharP\LocalRing.lean
|
/-
Copyright (c) 2022 Jon Eugster. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Eugster
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.IsPrimePow
import Mathlib.Data.Nat.Factorization.Basic
import Mathlib.RingTheory.LocalRing.ResidueField.Defs
/-!
# Characteristics of local rings
## Main result
- `charP_zero_or_prime_power`: In a commutative local ring the characteristics is either
zero or a prime power.
-/
/-- In a local ring the characteristics is either zero or a prime power. -/
theorem charP_zero_or_prime_power (R : Type*) [CommRing R] [LocalRing R] (q : ℕ)
[char_R_q : CharP R q] : q = 0 ∨ IsPrimePow q := by
-- Assume `q := char(R)` is not zero.
apply or_iff_not_imp_left.2
intro q_pos
let K := LocalRing.ResidueField R
haveI RM_char := ringChar.charP K
let r := ringChar K
let n := q.factorization r
-- `r := char(R/m)` is either prime or zero:
cases' CharP.char_is_prime_or_zero K r with r_prime r_zero
· let a := q / r ^ n
-- If `r` is prime, we can write it as `r = a * q^n` ...
have q_eq_a_mul_rn : q = r ^ n * a := by rw [Nat.mul_div_cancel' (Nat.ord_proj_dvd q r)]
have r_ne_dvd_a := Nat.not_dvd_ord_compl r_prime q_pos
have rn_dvd_q : r ^ n ∣ q := ⟨a, q_eq_a_mul_rn⟩
rw [mul_comm] at q_eq_a_mul_rn
-- ... where `a` is a unit.
have a_unit : IsUnit (a : R) := by
by_contra g
rw [← mem_nonunits_iff] at g
rw [← LocalRing.mem_maximalIdeal] at g
have a_cast_zero := Ideal.Quotient.eq_zero_iff_mem.2 g
rw [map_natCast] at a_cast_zero
have r_dvd_a := (ringChar.spec K a).1 a_cast_zero
exact absurd r_dvd_a r_ne_dvd_a
-- Let `b` be the inverse of `a`.
cases' a_unit.exists_left_inv with a_inv h_inv_mul_a
have rn_cast_zero : ↑(r ^ n) = (0 : R) := by
rw [← @mul_one R _ ↑(r ^ n), mul_comm, ← Classical.choose_spec a_unit.exists_left_inv,
mul_assoc, ← Nat.cast_mul, ← q_eq_a_mul_rn, CharP.cast_eq_zero R q]
simp
have q_eq_rn := Nat.dvd_antisymm ((CharP.cast_eq_zero_iff R q (r ^ n)).mp rn_cast_zero) rn_dvd_q
have n_pos : n ≠ 0 := fun n_zero =>
absurd (by simpa [n_zero] using q_eq_rn) (CharP.char_ne_one R q)
-- Definition of prime power: `∃ r n, Prime r ∧ 0 < n ∧ r ^ n = q`.
exact ⟨r, ⟨n, ⟨r_prime.prime, ⟨pos_iff_ne_zero.mpr n_pos, q_eq_rn.symm⟩⟩⟩⟩
· haveI K_char_p_0 := ringChar.of_eq r_zero
haveI K_char_zero : CharZero K := CharP.charP_to_charZero K
haveI R_char_zero := RingHom.charZero (LocalRing.residue R)
-- Finally, `r = 0` would lead to a contradiction:
have q_zero := CharP.eq R char_R_q (CharP.ofCharZero R)
exact absurd q_zero q_pos
|
Algebra\CharP\MixedCharZero.lean
|
/-
Copyright (c) 2022 Jon Eugster. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Eugster
-/
import Mathlib.Algebra.CharP.LocalRing
import Mathlib.RingTheory.Ideal.Quotient
import Mathlib.Tactic.FieldSimp
/-!
# Equal and mixed characteristic
In commutative algebra, some statements are simpler when working over a `ℚ`-algebra `R`, in which
case one also says that the ring has "equal characteristic zero". A ring that is not a
`ℚ`-algebra has either positive characteristic or there exists a prime ideal `I ⊂ R` such that
the quotient `R ⧸ I` has positive characteristic `p > 0`. In this case one speaks of
"mixed characteristic `(0, p)`", where `p` is only unique if `R` is local.
Examples of mixed characteristic rings are `ℤ` or the `p`-adic integers/numbers.
This file provides the main theorem `split_by_characteristic` that splits any proposition `P` into
the following three cases:
1) Positive characteristic: `CharP R p` (where `p ≠ 0`)
2) Equal characteristic zero: `Algebra ℚ R`
3) Mixed characteristic: `MixedCharZero R p` (where `p` is prime)
## Main definitions
- `MixedCharZero` : A ring has mixed characteristic `(0, p)` if it has characteristic zero
and there exists an ideal such that the quotient `R ⧸ I` has characteristic `p`.
## Main results
- `split_equalCharZero_mixedCharZero` : Split a statement into equal/mixed characteristic zero.
This main theorem has the following three corollaries which include the positive
characteristic case for convenience:
- `split_by_characteristic` : Generally consider positive char `p ≠ 0`.
- `split_by_characteristic_domain` : In a domain we can assume that `p` is prime.
- `split_by_characteristic_localRing` : In a local ring we can assume that `p` is a prime power.
## Implementation Notes
We use the terms `EqualCharZero` and `AlgebraRat` despite not being such definitions in mathlib.
The former refers to the statement `∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)`, the latter
refers to the existence of an instance `[Algebra ℚ R]`. The two are shown to be
equivalent conditions.
## TODO
- Relate mixed characteristic in a local ring to p-adic numbers [NumberTheory.PAdics].
-/
variable (R : Type*) [CommRing R]
/-!
### Mixed characteristic
-/
/--
A ring of characteristic zero is of "mixed characteristic `(0, p)`" if there exists an ideal
such that the quotient `R ⧸ I` has characteristic `p`.
**Remark:** For `p = 0`, `MixedChar R 0` is a meaningless definition (i.e. satisfied by any ring)
as `R ⧸ ⊥ ≅ R` has by definition always characteristic zero.
One could require `(I ≠ ⊥)` in the definition, but then `MixedChar R 0` would mean something
like `ℤ`-algebra of extension degree `≥ 1` and would be completely independent from
whether something is a `ℚ`-algebra or not (e.g. `ℚ[X]` would satisfy it but `ℚ` wouldn't).
-/
class MixedCharZero (p : ℕ) : Prop where
[toCharZero : CharZero R]
charP_quotient : ∃ I : Ideal R, I ≠ ⊤ ∧ CharP (R ⧸ I) p
namespace MixedCharZero
/--
Reduction to `p` prime: When proving any statement `P` about mixed characteristic rings we
can always assume that `p` is prime.
-/
theorem reduce_to_p_prime {P : Prop} :
(∀ p > 0, MixedCharZero R p → P) ↔ ∀ p : ℕ, p.Prime → MixedCharZero R p → P := by
constructor
· intro h q q_prime q_mixedChar
exact h q (Nat.Prime.pos q_prime) q_mixedChar
· intro h q q_pos q_mixedChar
rcases q_mixedChar.charP_quotient with ⟨I, hI_ne_top, _⟩
-- Krull's Thm: There exists a prime ideal `P` such that `I ≤ P`
rcases Ideal.exists_le_maximal I hI_ne_top with ⟨M, hM_max, h_IM⟩
let r := ringChar (R ⧸ M)
have r_pos : r ≠ 0 := by
have q_zero :=
congr_arg (Ideal.Quotient.factor I M h_IM) (CharP.cast_eq_zero (R ⧸ I) q)
simp only [map_natCast, map_zero] at q_zero
apply ne_zero_of_dvd_ne_zero (ne_of_gt q_pos)
exact (CharP.cast_eq_zero_iff (R ⧸ M) r q).mp q_zero
have r_prime : Nat.Prime r :=
or_iff_not_imp_right.1 (CharP.char_is_prime_or_zero (R ⧸ M) r) r_pos
apply h r r_prime
have : CharZero R := q_mixedChar.toCharZero
exact ⟨⟨M, hM_max.ne_top, ringChar.of_eq rfl⟩⟩
/--
Reduction to `I` prime ideal: When proving statements about mixed characteristic rings,
after we reduced to `p` prime, we can assume that the ideal `I` in the definition is maximal.
-/
theorem reduce_to_maximal_ideal {p : ℕ} (hp : Nat.Prime p) :
(∃ I : Ideal R, I ≠ ⊤ ∧ CharP (R ⧸ I) p) ↔ ∃ I : Ideal R, I.IsMaximal ∧ CharP (R ⧸ I) p := by
constructor
· intro g
rcases g with ⟨I, ⟨hI_not_top, _⟩⟩
-- Krull's Thm: There exists a prime ideal `M` such that `I ≤ M`.
rcases Ideal.exists_le_maximal I hI_not_top with ⟨M, ⟨hM_max, hM_ge⟩⟩
use M
constructor
· exact hM_max
· cases CharP.exists (R ⧸ M) with
| intro r hr =>
convert hr
have r_dvd_p : r ∣ p := by
rw [← CharP.cast_eq_zero_iff (R ⧸ M) r p]
convert congr_arg (Ideal.Quotient.factor I M hM_ge) (CharP.cast_eq_zero (R ⧸ I) p)
symm
apply (Nat.Prime.eq_one_or_self_of_dvd hp r r_dvd_p).resolve_left
exact CharP.char_ne_one (R ⧸ M) r
· intro ⟨I, hI_max, h_charP⟩
use I
exact ⟨Ideal.IsMaximal.ne_top hI_max, h_charP⟩
end MixedCharZero
/-!
### Equal characteristic zero
A commutative ring `R` has "equal characteristic zero" if it satisfies one of the following
equivalent properties:
1) `R` is a `ℚ`-algebra.
2) The quotient `R ⧸ I` has characteristic zero for any proper ideal `I ⊂ R`.
3) `R` has characteristic zero and does not have mixed characteristic for any prime `p`.
We show `(1) ↔ (2) ↔ (3)`, and most of the following is concerned with constructing
an explicit algebra map `ℚ →+* R` (given by `x ↦ (x.num : R) /ₚ ↑x.pnatDen`)
for the direction `(1) ← (2)`.
Note: Property `(2)` is denoted as `EqualCharZero` in the statement names below.
-/
namespace EqualCharZero
/-- `ℚ`-algebra implies equal characteristic. -/
theorem of_algebraRat [Algebra ℚ R] : ∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I) := by
intro I hI
constructor
intro a b h_ab
contrapose! hI
-- `↑a - ↑b` is a unit contained in `I`, which contradicts `I ≠ ⊤`.
refine I.eq_top_of_isUnit_mem ?_ (IsUnit.map (algebraMap ℚ R) (IsUnit.mk0 (a - b : ℚ) ?_))
· simpa only [← Ideal.Quotient.eq_zero_iff_mem, map_sub, sub_eq_zero, map_natCast]
simpa only [Ne, sub_eq_zero] using (@Nat.cast_injective ℚ _ _).ne hI
section ConstructionAlgebraRat
variable {R}
/-- Internal: Not intended to be used outside this local construction. -/
theorem PNat.isUnit_natCast [h : Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))]
(n : ℕ+) : IsUnit (n : R) := by
-- `n : R` is a unit iff `(n)` is not a proper ideal in `R`.
rw [← Ideal.span_singleton_eq_top]
-- So by contrapositive, we should show the quotient does not have characteristic zero.
apply not_imp_comm.mp (h.elim (Ideal.span {↑n}))
intro h_char_zero
-- In particular, the image of `n` in the quotient should be nonzero.
apply h_char_zero.cast_injective.ne n.ne_zero
-- But `n` generates the ideal, so its image is clearly zero.
rw [← map_natCast (Ideal.Quotient.mk _), Nat.cast_zero, Ideal.Quotient.eq_zero_iff_mem]
exact Ideal.subset_span (Set.mem_singleton _)
@[coe]
noncomputable def pnatCast [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : ℕ+ → Rˣ :=
fun n => (PNat.isUnit_natCast n).unit
/-- Internal: Not intended to be used outside this local construction. -/
noncomputable instance coePNatUnits
[Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : Coe ℕ+ Rˣ :=
⟨EqualCharZero.pnatCast⟩
/-- Internal: Not intended to be used outside this local construction. -/
@[simp]
theorem pnatCast_one [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : ((1 : ℕ+) : Rˣ) = 1 := by
apply Units.ext
rw [Units.val_one]
change ((PNat.isUnit_natCast (R := R) 1).unit : R) = 1
rw [IsUnit.unit_spec (PNat.isUnit_natCast 1)]
rw [PNat.one_coe, Nat.cast_one]
/-- Internal: Not intended to be used outside this local construction. -/
@[simp]
theorem pnatCast_eq_natCast [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] (n : ℕ+) :
((n : Rˣ) : R) = ↑n := by
change ((PNat.isUnit_natCast (R := R) n).unit : R) = ↑n
simp only [IsUnit.unit_spec]
/-- Equal characteristic implies `ℚ`-algebra. -/
noncomputable def algebraRat (h : ∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)) :
Algebra ℚ R :=
haveI : Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)) := ⟨h⟩
RingHom.toAlgebra
{ toFun := fun x => x.num /ₚ ↑x.pnatDen
map_zero' := by simp [divp]
map_one' := by simp
map_mul' := by
intro a b
field_simp
trans (↑((a * b).num * a.den * b.den) : R)
· simp_rw [Int.cast_mul, Int.cast_natCast]
ring
rw [Rat.mul_num_den' a b]
simp
map_add' := by
intro a b
field_simp
trans (↑((a + b).num * a.den * b.den) : R)
· simp_rw [Int.cast_mul, Int.cast_natCast]
ring
rw [Rat.add_num_den' a b]
simp }
end ConstructionAlgebraRat
/-- Not mixed characteristic implies equal characteristic. -/
theorem of_not_mixedCharZero [CharZero R] (h : ∀ p > 0, ¬MixedCharZero R p) :
∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I) := by
intro I hI_ne_top
suffices CharP (R ⧸ I) 0 from CharP.charP_to_charZero _
cases CharP.exists (R ⧸ I) with
| intro p hp =>
cases p with
| zero => exact hp
| succ p =>
have h_mixed : MixedCharZero R p.succ := ⟨⟨I, ⟨hI_ne_top, hp⟩⟩⟩
exact absurd h_mixed (h p.succ p.succ_pos)
/-- Equal characteristic implies not mixed characteristic. -/
theorem to_not_mixedCharZero (h : ∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)) :
∀ p > 0, ¬MixedCharZero R p := by
intro p p_pos
by_contra hp_mixedChar
rcases hp_mixedChar.charP_quotient with ⟨I, hI_ne_top, hI_p⟩
replace hI_zero : CharP (R ⧸ I) 0 := @CharP.ofCharZero _ _ (h I hI_ne_top)
exact absurd (CharP.eq (R ⧸ I) hI_p hI_zero) (ne_of_gt p_pos)
/--
A ring of characteristic zero has equal characteristic iff it does not
have mixed characteristic for any `p`.
-/
theorem iff_not_mixedCharZero [CharZero R] :
(∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)) ↔ ∀ p > 0, ¬MixedCharZero R p :=
⟨to_not_mixedCharZero R, of_not_mixedCharZero R⟩
/-- A ring is a `ℚ`-algebra iff it has equal characteristic zero. -/
theorem nonempty_algebraRat_iff :
Nonempty (Algebra ℚ R) ↔ ∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I) := by
constructor
· intro h_alg
haveI h_alg' : Algebra ℚ R := h_alg.some
apply of_algebraRat
· intro h
apply Nonempty.intro
exact algebraRat h
end EqualCharZero
/--
A ring of characteristic zero is not a `ℚ`-algebra iff it has mixed characteristic for some `p`.
-/
theorem isEmpty_algebraRat_iff_mixedCharZero [CharZero R] :
IsEmpty (Algebra ℚ R) ↔ ∃ p > 0, MixedCharZero R p := by
rw [← not_iff_not]
push_neg
rw [not_isEmpty_iff, ← EqualCharZero.iff_not_mixedCharZero]
apply EqualCharZero.nonempty_algebraRat_iff
/-!
# Splitting statements into different characteristic
Statements to split a proof by characteristic. There are 3 theorems here that are very
similar. They only differ in the assumptions we can make on the positive characteristic
case:
Generally we need to consider all `p ≠ 0`, but if `R` is a local ring, we can assume
that `p` is a prime power. And if `R` is a domain, we can even assume that `p` is prime.
-/
section MainStatements
variable {P : Prop}
/-- Split a `Prop` in characteristic zero into equal and mixed characteristic. -/
theorem split_equalCharZero_mixedCharZero [CharZero R] (h_equal : Algebra ℚ R → P)
(h_mixed : ∀ p : ℕ, Nat.Prime p → MixedCharZero R p → P) : P := by
by_cases h : ∃ p > 0, MixedCharZero R p
· rcases h with ⟨p, ⟨H, hp⟩⟩
rw [← MixedCharZero.reduce_to_p_prime] at h_mixed
exact h_mixed p H hp
· apply h_equal
rw [← isEmpty_algebraRat_iff_mixedCharZero, not_isEmpty_iff] at h
exact h.some
example (n : ℕ) (h : n ≠ 0) : 0 < n :=
zero_lt_iff.mpr h
/--
Split any `Prop` over `R` into the three cases:
- positive characteristic.
- equal characteristic zero.
- mixed characteristic `(0, p)`.
-/
theorem split_by_characteristic (h_pos : ∀ p : ℕ, p ≠ 0 → CharP R p → P) (h_equal : Algebra ℚ R → P)
(h_mixed : ∀ p : ℕ, Nat.Prime p → MixedCharZero R p → P) : P := by
cases CharP.exists R with
| intro p p_charP =>
by_cases h : p = 0
· rw [h] at p_charP
haveI h0 : CharZero R := CharP.charP_to_charZero R
exact split_equalCharZero_mixedCharZero R h_equal h_mixed
· exact h_pos p h p_charP
/--
In an `IsDomain R`, split any `Prop` over `R` into the three cases:
- *prime* characteristic.
- equal characteristic zero.
- mixed characteristic `(0, p)`.
-/
theorem split_by_characteristic_domain [IsDomain R] (h_pos : ∀ p : ℕ, Nat.Prime p → CharP R p → P)
(h_equal : Algebra ℚ R → P) (h_mixed : ∀ p : ℕ, Nat.Prime p → MixedCharZero R p → P) : P := by
refine split_by_characteristic R ?_ h_equal h_mixed
intro p p_pos p_char
have p_prime : Nat.Prime p := or_iff_not_imp_right.mp (CharP.char_is_prime_or_zero R p) p_pos
exact h_pos p p_prime p_char
/--
In a `LocalRing R`, split any `Prop` over `R` into the three cases:
- *prime power* characteristic.
- equal characteristic zero.
- mixed characteristic `(0, p)`.
-/
theorem split_by_characteristic_localRing [LocalRing R]
(h_pos : ∀ p : ℕ, IsPrimePow p → CharP R p → P) (h_equal : Algebra ℚ R → P)
(h_mixed : ∀ p : ℕ, Nat.Prime p → MixedCharZero R p → P) : P := by
refine split_by_characteristic R ?_ h_equal h_mixed
intro p p_pos p_char
have p_ppow : IsPrimePow (p : ℕ) := or_iff_not_imp_left.mp (charP_zero_or_prime_power R p) p_pos
exact h_pos p p_ppow p_char
end MainStatements
|
Algebra\CharP\Pi.lean
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Ring.Pi
/-!
# Characteristic of semirings of functions
-/
universe u v
namespace CharP
instance pi (ι : Type u) [hi : Nonempty ι] (R : Type v) [Semiring R] (p : ℕ) [CharP R p] :
CharP (ι → R) p :=
⟨fun x =>
let ⟨i⟩ := hi
Iff.symm <|
(CharP.cast_eq_zero_iff R p x).symm.trans
⟨fun h =>
funext fun j =>
show Pi.evalRingHom (fun _ => R) j (↑x : ι → R) = 0 by rw [map_natCast, h],
fun h => map_natCast (Pi.evalRingHom (fun _ : ι => R) i) x ▸ by rw [h, RingHom.map_zero]⟩⟩
-- diamonds
instance pi' (ι : Type u) [Nonempty ι] (R : Type v) [CommRing R] (p : ℕ) [CharP R p] :
CharP (ι → R) p :=
CharP.pi ι R p
end CharP
|
Algebra\CharP\Quotient.lean
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Eric Wieser
-/
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.RingTheory.Ideal.Quotient
/-!
# Characteristic of quotients rings
-/
universe u v
namespace CharP
theorem quotient (R : Type u) [CommRing R] (p : ℕ) [hp1 : Fact p.Prime] (hp2 : ↑p ∈ nonunits R) :
CharP (R ⧸ (Ideal.span ({(p : R)} : Set R) : Ideal R)) p :=
have hp0 : (p : R ⧸ (Ideal.span {(p : R)} : Ideal R)) = 0 :=
map_natCast (Ideal.Quotient.mk (Ideal.span {(p : R)} : Ideal R)) p ▸
Ideal.Quotient.eq_zero_iff_mem.2 (Ideal.subset_span <| Set.mem_singleton _)
ringChar.of_eq <|
Or.resolve_left ((Nat.dvd_prime hp1.1).1 <| ringChar.dvd hp0) fun h1 =>
hp2 <|
isUnit_iff_dvd_one.2 <|
Ideal.mem_span_singleton.1 <|
Ideal.Quotient.eq_zero_iff_mem.1 <|
@Subsingleton.elim _ (@CharOne.subsingleton _ _ (ringChar.of_eq h1)) _ _
/-- If an ideal does not contain any coercions of natural numbers other than zero, then its quotient
inherits the characteristic of the underlying ring. -/
theorem quotient' {R : Type*} [CommRing R] (p : ℕ) [CharP R p] (I : Ideal R)
(h : ∀ x : ℕ, (x : R) ∈ I → (x : R) = 0) : CharP (R ⧸ I) p :=
⟨fun x => by
rw [← cast_eq_zero_iff R p x, ← map_natCast (Ideal.Quotient.mk I)]
refine Ideal.Quotient.eq.trans (?_ : ↑x - 0 ∈ I ↔ _)
rw [sub_zero]
exact ⟨h x, fun h' => h'.symm ▸ I.zero_mem⟩⟩
/-- `CharP.quotient'` as an `Iff`. -/
theorem quotient_iff {R : Type*} [CommRing R] (n : ℕ) [CharP R n] (I : Ideal R) :
CharP (R ⧸ I) n ↔ ∀ x : ℕ, ↑x ∈ I → (x : R) = 0 := by
refine ⟨fun _ x hx => ?_, CharP.quotient' n I⟩
rw [CharP.cast_eq_zero_iff R n, ← CharP.cast_eq_zero_iff (R ⧸ I) n _]
exact (Submodule.Quotient.mk_eq_zero I).mpr hx
/-- `CharP.quotient_iff`, but stated in terms of inclusions of ideals. -/
theorem quotient_iff_le_ker_natCast {R : Type*} [CommRing R] (n : ℕ) [CharP R n] (I : Ideal R) :
CharP (R ⧸ I) n ↔ I.comap (Nat.castRingHom R) ≤ RingHom.ker (Nat.castRingHom R) := by
rw [CharP.quotient_iff, RingHom.ker_eq_comap_bot]; rfl
end CharP
theorem Ideal.Quotient.index_eq_zero {R : Type*} [CommRing R] (I : Ideal R) :
(↑I.toAddSubgroup.index : R ⧸ I) = 0 := by
rw [AddSubgroup.index, Nat.card_eq]
split_ifs with hq; swap
· simp
letI : Fintype (R ⧸ I) := @Fintype.ofFinite _ hq
exact Nat.cast_card_eq_zero (R ⧸ I)
|
Algebra\CharP\Reduced.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Joey van Langen, Casper Putz
-/
import Mathlib.Algebra.CharP.ExpChar
import Mathlib.RingTheory.Nilpotent.Defs
/-!
# Results about characteristic p reduced rings
-/
open Finset
section
variable (R : Type*) [CommRing R] [IsReduced R] (p n : ℕ) [ExpChar R p]
theorem iterateFrobenius_inj : Function.Injective (iterateFrobenius R p n) := fun x y H ↦ by
rw [← sub_eq_zero] at H ⊢
simp_rw [iterateFrobenius_def, ← sub_pow_expChar_pow] at H
exact IsReduced.eq_zero _ ⟨_, H⟩
theorem frobenius_inj : Function.Injective (frobenius R p) :=
iterateFrobenius_one (R := R) p ▸ iterateFrobenius_inj R p 1
end
/-- If `ringChar R = 2`, where `R` is a finite reduced commutative ring,
then every `a : R` is a square. -/
theorem isSquare_of_charTwo' {R : Type*} [Finite R] [CommRing R] [IsReduced R] [CharP R 2]
(a : R) : IsSquare a := by
cases nonempty_fintype R
exact
Exists.imp (fun b h => pow_two b ▸ Eq.symm h)
(((Fintype.bijective_iff_injective_and_card _).mpr ⟨frobenius_inj R 2, rfl⟩).surjective a)
variable {R : Type*} [CommRing R] [IsReduced R]
@[simp]
theorem ExpChar.pow_prime_pow_mul_eq_one_iff (p k m : ℕ) [ExpChar R p] (x : R) :
x ^ (p ^ k * m) = 1 ↔ x ^ m = 1 := by
rw [pow_mul']
convert ← (iterateFrobenius_inj R p k).eq_iff
apply map_one
@[deprecated (since := "2024-02-02")]
alias CharP.pow_prime_pow_mul_eq_one_iff := ExpChar.pow_prime_pow_mul_eq_one_iff
|
Algebra\CharP\Subring.lean
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Ring.Subring.Basic
/-!
# Characteristic of subrings
-/
universe u v
namespace CharP
instance subsemiring (R : Type u) [Semiring R] (p : ℕ) [CharP R p] (S : Subsemiring R) :
CharP S p :=
⟨fun x =>
Iff.symm <|
(CharP.cast_eq_zero_iff R p x).symm.trans
⟨fun h => Subtype.eq <| show S.subtype x = 0 by rw [map_natCast, h], fun h =>
map_natCast S.subtype x ▸ by rw [h, RingHom.map_zero]⟩⟩
instance subring (R : Type u) [Ring R] (p : ℕ) [CharP R p] (S : Subring R) : CharP S p :=
⟨fun x =>
Iff.symm <|
(CharP.cast_eq_zero_iff R p x).symm.trans
⟨fun h => Subtype.eq <| show S.subtype x = 0 by rw [map_natCast, h], fun h =>
map_natCast S.subtype x ▸ by rw [h, RingHom.map_zero]⟩⟩
instance subring' (R : Type u) [CommRing R] (p : ℕ) [CharP R p] (S : Subring R) : CharP S p :=
CharP.subring R p S
end CharP
|
Algebra\CharP\Two.lean
|
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.CharP.ExpChar
import Mathlib.GroupTheory.OrderOfElement
/-!
# Lemmas about rings of characteristic two
This file contains results about `CharP R 2`, in the `CharTwo` namespace.
The lemmas in this file with a `_sq` suffix are just special cases of the `_pow_char` lemmas
elsewhere, with a shorter name for ease of discovery, and no need for a `[Fact (Prime 2)]` argument.
-/
variable {R ι : Type*}
namespace CharTwo
section Semiring
variable [Semiring R] [CharP R 2]
theorem two_eq_zero : (2 : R) = 0 := by rw [← Nat.cast_two, CharP.cast_eq_zero]
@[simp]
theorem add_self_eq_zero (x : R) : x + x = 0 := by rw [← two_smul R x, two_eq_zero, zero_smul]
end Semiring
section Ring
variable [Ring R] [CharP R 2]
@[simp]
theorem neg_eq (x : R) : -x = x := by
rw [neg_eq_iff_add_eq_zero, ← two_smul R x, two_eq_zero, zero_smul]
theorem neg_eq' : Neg.neg = (id : R → R) :=
funext neg_eq
@[simp]
theorem sub_eq_add (x y : R) : x - y = x + y := by rw [sub_eq_add_neg, neg_eq]
theorem sub_eq_add' : HSub.hSub = ((· + ·) : R → R → R) :=
funext fun x => funext fun y => sub_eq_add x y
end Ring
section CommSemiring
variable [CommSemiring R] [CharP R 2]
theorem add_sq (x y : R) : (x + y) ^ 2 = x ^ 2 + y ^ 2 :=
add_pow_char _ _ _
theorem add_mul_self (x y : R) : (x + y) * (x + y) = x * x + y * y := by
rw [← pow_two, ← pow_two, ← pow_two, add_sq]
theorem list_sum_sq (l : List R) : l.sum ^ 2 = (l.map (· ^ 2)).sum :=
list_sum_pow_char _ _
theorem list_sum_mul_self (l : List R) : l.sum * l.sum = (List.map (fun x => x * x) l).sum := by
simp_rw [← pow_two, list_sum_sq]
theorem multiset_sum_sq (l : Multiset R) : l.sum ^ 2 = (l.map (· ^ 2)).sum :=
multiset_sum_pow_char _ _
theorem multiset_sum_mul_self (l : Multiset R) :
l.sum * l.sum = (Multiset.map (fun x => x * x) l).sum := by simp_rw [← pow_two, multiset_sum_sq]
theorem sum_sq (s : Finset ι) (f : ι → R) : (∑ i ∈ s, f i) ^ 2 = ∑ i ∈ s, f i ^ 2 :=
sum_pow_char _ _ _
theorem sum_mul_self (s : Finset ι) (f : ι → R) :
((∑ i ∈ s, f i) * ∑ i ∈ s, f i) = ∑ i ∈ s, f i * f i := by simp_rw [← pow_two, sum_sq]
end CommSemiring
end CharTwo
section ringChar
variable [Ring R]
theorem neg_one_eq_one_iff [Nontrivial R] : (-1 : R) = 1 ↔ ringChar R = 2 := by
refine ⟨fun h => ?_, fun h => @CharTwo.neg_eq _ _ (ringChar.of_eq h) 1⟩
rw [eq_comm, ← sub_eq_zero, sub_neg_eq_add, ← Nat.cast_one, ← Nat.cast_add] at h
exact ((Nat.dvd_prime Nat.prime_two).mp (ringChar.dvd h)).resolve_left CharP.ringChar_ne_one
@[simp]
theorem orderOf_neg_one [Nontrivial R] : orderOf (-1 : R) = if ringChar R = 2 then 1 else 2 := by
split_ifs with h
· rw [neg_one_eq_one_iff.2 h, orderOf_one]
apply orderOf_eq_prime
· simp
simpa [neg_one_eq_one_iff] using h
end ringChar
|
Algebra\CharZero\Defs.lean
|
/-
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Int.Cast.Defs
import Mathlib.Tactic.Cases
import Mathlib.Algebra.NeZero
import Mathlib.Logic.Function.Basic
/-!
# Characteristic zero
A ring `R` is called of characteristic zero if every natural number `n` is non-zero when considered
as an element of `R`. Since this definition doesn't mention the multiplicative structure of `R`
except for the existence of `1` in this file characteristic zero is defined for additive monoids
with `1`.
## Main definition
`CharZero` is the typeclass of an additive monoid with one such that the natural homomorphism
from the natural numbers into it is injective.
## TODO
* Unify with `CharP` (possibly using an out-parameter)
-/
/-- Typeclass for monoids with characteristic zero.
(This is usually stated on fields but it makes sense for any additive monoid with 1.)
*Warning*: for a semiring `R`, `CharZero R` and `CharP R 0` need not coincide.
* `CharZero R` requires an injection `ℕ ↪ R`;
* `CharP R 0` asks that only `0 : ℕ` maps to `0 : R` under the map `ℕ → R`.
For instance, endowing `{0, 1}` with addition given by `max` (i.e. `1` is absorbing), shows that
`CharZero {0, 1}` does not hold and yet `CharP {0, 1} 0` does.
This example is formalized in `Counterexamples/CharPZeroNeCharZero.lean`.
-/
class CharZero (R) [AddMonoidWithOne R] : Prop where
/-- An additive monoid with one has characteristic zero if the canonical map `ℕ → R` is
injective. -/
cast_injective : Function.Injective (Nat.cast : ℕ → R)
variable {R : Type*}
theorem charZero_of_inj_zero [AddGroupWithOne R] (H : ∀ n : ℕ, (n : R) = 0 → n = 0) :
CharZero R :=
⟨@fun m n h => by
induction' m with m ih generalizing n
· rw [H n]
rw [← h, Nat.cast_zero]
cases' n with n
· apply H
rw [h, Nat.cast_zero]
simp only [Nat.cast_succ, add_right_cancel_iff] at h
rwa [ih]⟩
namespace Nat
variable [AddMonoidWithOne R] [CharZero R]
theorem cast_injective : Function.Injective (Nat.cast : ℕ → R) :=
CharZero.cast_injective
@[simp, norm_cast]
theorem cast_inj {m n : ℕ} : (m : R) = n ↔ m = n :=
cast_injective.eq_iff
@[simp, norm_cast]
theorem cast_eq_zero {n : ℕ} : (n : R) = 0 ↔ n = 0 := by rw [← cast_zero, cast_inj]
@[norm_cast]
theorem cast_ne_zero {n : ℕ} : (n : R) ≠ 0 ↔ n ≠ 0 :=
not_congr cast_eq_zero
theorem cast_add_one_ne_zero (n : ℕ) : (n + 1 : R) ≠ 0 :=
mod_cast n.succ_ne_zero
@[simp, norm_cast]
theorem cast_eq_one {n : ℕ} : (n : R) = 1 ↔ n = 1 := by rw [← cast_one, cast_inj]
@[norm_cast]
theorem cast_ne_one {n : ℕ} : (n : R) ≠ 1 ↔ n ≠ 1 :=
cast_eq_one.not
instance (priority := 100) AtLeastTwo.toNeZero (n : ℕ) [n.AtLeastTwo] : NeZero n :=
⟨Nat.ne_of_gt (Nat.le_of_lt one_lt)⟩
end Nat
namespace OfNat
variable [AddMonoidWithOne R] [CharZero R]
@[simp] lemma ofNat_ne_zero (n : ℕ) [n.AtLeastTwo] : (no_index (ofNat n) : R) ≠ 0 :=
Nat.cast_ne_zero.2 (NeZero.ne n)
@[simp] lemma zero_ne_ofNat (n : ℕ) [n.AtLeastTwo] : 0 ≠ (no_index (ofNat n) : R) :=
(ofNat_ne_zero n).symm
@[simp] lemma ofNat_ne_one (n : ℕ) [n.AtLeastTwo] : (no_index (ofNat n) : R) ≠ 1 :=
Nat.cast_ne_one.2 (Nat.AtLeastTwo.ne_one)
@[simp] lemma one_ne_ofNat (n : ℕ) [n.AtLeastTwo] : (1 : R) ≠ no_index (ofNat n) :=
(ofNat_ne_one n).symm
@[simp] lemma ofNat_eq_ofNat {m n : ℕ} [m.AtLeastTwo] [n.AtLeastTwo] :
(no_index (ofNat m) : R) = no_index (ofNat n) ↔ (ofNat m : ℕ) = ofNat n :=
Nat.cast_inj
end OfNat
namespace NeZero
instance charZero {M} {n : ℕ} [NeZero n] [AddMonoidWithOne M] [CharZero M] : NeZero (n : M) :=
⟨Nat.cast_ne_zero.mpr out⟩
instance charZero_one {M} [AddMonoidWithOne M] [CharZero M] : NeZero (1 : M) where
out := by
rw [← Nat.cast_one, Nat.cast_ne_zero]
trivial
instance charZero_ofNat {M} {n : ℕ} [n.AtLeastTwo] [AddMonoidWithOne M] [CharZero M] :
NeZero (OfNat.ofNat n : M) :=
⟨OfNat.ofNat_ne_zero n⟩
end NeZero
|
Algebra\CharZero\Infinite.lean
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.CharZero.Defs
import Mathlib.Data.Fintype.Card
/-! # A characteristic-zero semiring is infinite -/
open Set
variable (M : Type*) [AddMonoidWithOne M] [CharZero M]
-- see Note [lower instance priority]
instance (priority := 100) CharZero.infinite : Infinite M :=
Infinite.of_injective Nat.cast Nat.cast_injective
|
Algebra\CharZero\Lemmas.lean
|
/-
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.Group.Support
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Data.Nat.Cast.Field
/-!
# Characteristic zero (additional theorems)
A ring `R` is called of characteristic zero if every natural number `n` is non-zero when considered
as an element of `R`. Since this definition doesn't mention the multiplicative structure of `R`
except for the existence of `1` in this file characteristic zero is defined for additive monoids
with `1`.
## Main statements
* Characteristic zero implies that the additive monoid is infinite.
-/
open Function Set
namespace Nat
variable {R : Type*} [AddMonoidWithOne R] [CharZero R]
/-- `Nat.cast` as an embedding into monoids of characteristic `0`. -/
@[simps]
def castEmbedding : ℕ ↪ R :=
⟨Nat.cast, cast_injective⟩
@[simp]
theorem cast_pow_eq_one {R : Type*} [Semiring R] [CharZero R] (q : ℕ) (n : ℕ) (hn : n ≠ 0) :
(q : R) ^ n = 1 ↔ q = 1 := by
rw [← cast_pow, cast_eq_one]
exact pow_eq_one_iff hn
@[simp, norm_cast]
theorem cast_div_charZero {k : Type*} [DivisionSemiring k] [CharZero k] {m n : ℕ} (n_dvd : n ∣ m) :
((m / n : ℕ) : k) = m / n := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
· exact cast_div n_dvd (cast_ne_zero.2 hn)
end Nat
section AddMonoidWithOne
variable {α M : Type*} [AddMonoidWithOne M] [CharZero M] {n : ℕ}
instance CharZero.NeZero.two : NeZero (2 : M) :=
⟨by
have : ((2 : ℕ) : M) ≠ 0 := Nat.cast_ne_zero.2 (by decide)
rwa [Nat.cast_two] at this⟩
namespace Function
lemma support_natCast (hn : n ≠ 0) : support (n : α → M) = univ :=
support_const <| Nat.cast_ne_zero.2 hn
@[deprecated (since := "2024-04-17")]
alias support_nat_cast := support_natCast
lemma mulSupport_natCast (hn : n ≠ 1) : mulSupport (n : α → M) = univ :=
mulSupport_const <| Nat.cast_ne_one.2 hn
@[deprecated (since := "2024-04-17")]
alias mulSupport_nat_cast := mulSupport_natCast
end Function
end AddMonoidWithOne
section
variable {R : Type*} [NonAssocSemiring R] [NoZeroDivisors R] [CharZero R] {a : R}
@[simp]
theorem add_self_eq_zero {a : R} : a + a = 0 ↔ a = 0 := by
simp only [(two_mul a).symm, mul_eq_zero, two_ne_zero, false_or_iff]
end
section
variable {R : Type*} [NonAssocRing R] [NoZeroDivisors R] [CharZero R]
@[simp] theorem neg_eq_self_iff {a : R} : -a = a ↔ a = 0 :=
neg_eq_iff_add_eq_zero.trans add_self_eq_zero
@[simp] theorem eq_neg_self_iff {a : R} : a = -a ↔ a = 0 :=
eq_neg_iff_add_eq_zero.trans add_self_eq_zero
theorem nat_mul_inj {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) : n = 0 ∨ a = b := by
rw [← sub_eq_zero, ← mul_sub, mul_eq_zero, sub_eq_zero] at h
exact mod_cast h
theorem nat_mul_inj' {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) (w : n ≠ 0) : a = b := by
simpa [w] using nat_mul_inj h
end
section
variable {R : Type*} [DivisionSemiring R] [NeZero (2 : R)]
@[simp] lemma add_self_div_two (a : R) : (a + a) / 2 = a := by
rw [← mul_two, mul_div_cancel_right₀ a two_ne_zero]
@[deprecated (since := "2024-07-16")] alias half_add_self := add_self_div_two
@[simp]
theorem add_halves (a : R) : a / 2 + a / 2 = a := by rw [← add_div, add_self_div_two]
@[deprecated (since := "2024-07-16")] alias add_halves' := add_halves
end
section
variable {R : Type*} [DivisionRing R] [CharZero R]
theorem sub_half (a : R) : a - a / 2 = a / 2 := by rw [sub_eq_iff_eq_add, add_halves]
theorem half_sub (a : R) : a / 2 - a = -(a / 2) := by rw [← neg_sub, sub_half]
end
namespace WithTop
instance {R : Type*} [AddMonoidWithOne R] [CharZero R] :
CharZero (WithTop R) where
cast_injective m n h := by
rwa [← coe_natCast, ← coe_natCast n, coe_eq_coe, Nat.cast_inj] at h
end WithTop
namespace WithBot
instance {R : Type*} [AddMonoidWithOne R] [CharZero R] :
CharZero (WithBot R) where
cast_injective m n h := by
rwa [← coe_natCast, ← coe_natCast n, coe_eq_coe, Nat.cast_inj] at h
end WithBot
section RingHom
variable {R S : Type*} [NonAssocSemiring R] [NonAssocSemiring S]
theorem RingHom.charZero (ϕ : R →+* S) [CharZero S] : CharZero R :=
⟨fun a b h => CharZero.cast_injective (R := S) (by rw [← map_natCast ϕ, ← map_natCast ϕ, h])⟩
theorem RingHom.charZero_iff {ϕ : R →+* S} (hϕ : Function.Injective ϕ) : CharZero R ↔ CharZero S :=
⟨fun hR =>
⟨by intro a b h; rwa [← @Nat.cast_inj R, ← hϕ.eq_iff, map_natCast ϕ, map_natCast ϕ]⟩,
fun hS => ϕ.charZero⟩
theorem RingHom.injective_nat (f : ℕ →+* R) [CharZero R] : Function.Injective f :=
Subsingleton.elim (Nat.castRingHom _) f ▸ Nat.cast_injective
end RingHom
section Units
variable {R : Type*} [Ring R] [CharZero R]
@[simp]
theorem units_ne_neg_self (u : Rˣ) : u ≠ -u := by
simp_rw [ne_eq, Units.ext_iff, Units.val_neg, eq_neg_iff_add_eq_zero, ← two_mul,
Units.mul_left_eq_zero, two_ne_zero, not_false_iff]
@[simp]
theorem neg_units_ne_self (u : Rˣ) : -u ≠ u := (units_ne_neg_self u).symm
end Units
|
Algebra\CharZero\Quotient.lean
|
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.GroupTheory.QuotientGroup
/-!
# Lemmas about quotients in characteristic zero
-/
variable {R : Type*} [DivisionRing R] [CharZero R] {p : R}
namespace AddSubgroup
/-- `z • r` is a multiple of `p` iff `r` is `pk/z` above a multiple of `p`, where `0 ≤ k < |z|`. -/
theorem zsmul_mem_zmultiples_iff_exists_sub_div {r : R} {z : ℤ} (hz : z ≠ 0) :
z • r ∈ AddSubgroup.zmultiples p ↔
∃ k : Fin z.natAbs, r - (k : ℕ) • (p / z : R) ∈ AddSubgroup.zmultiples p := by
rw [AddSubgroup.mem_zmultiples_iff]
simp_rw [AddSubgroup.mem_zmultiples_iff, div_eq_mul_inv, ← smul_mul_assoc, eq_sub_iff_add_eq]
have hz' : (z : R) ≠ 0 := Int.cast_ne_zero.mpr hz
conv_rhs => simp (config := { singlePass := true }) only [← (mul_right_injective₀ hz').eq_iff]
simp_rw [← zsmul_eq_mul, smul_add, ← mul_smul_comm, zsmul_eq_mul (z : R)⁻¹, mul_inv_cancel hz',
mul_one, ← natCast_zsmul, smul_smul, ← add_smul]
constructor
· rintro ⟨k, h⟩
simp_rw [← h]
refine ⟨⟨(k % z).toNat, ?_⟩, k / z, ?_⟩
· rw [← Int.ofNat_lt, Int.toNat_of_nonneg (Int.emod_nonneg _ hz)]
exact (Int.emod_lt _ hz).trans_eq (Int.abs_eq_natAbs _)
rw [Fin.val_mk, Int.toNat_of_nonneg (Int.emod_nonneg _ hz)]
nth_rewrite 3 [← Int.ediv_add_emod k z]
rfl
· rintro ⟨k, n, h⟩
exact ⟨_, h⟩
theorem nsmul_mem_zmultiples_iff_exists_sub_div {r : R} {n : ℕ} (hn : n ≠ 0) :
n • r ∈ AddSubgroup.zmultiples p ↔
∃ k : Fin n, r - (k : ℕ) • (p / n : R) ∈ AddSubgroup.zmultiples p := by
rw [← natCast_zsmul r, zsmul_mem_zmultiples_iff_exists_sub_div (Int.natCast_ne_zero.mpr hn),
Int.cast_natCast]
rfl
end AddSubgroup
namespace QuotientAddGroup
theorem zmultiples_zsmul_eq_zsmul_iff {ψ θ : R ⧸ AddSubgroup.zmultiples p} {z : ℤ} (hz : z ≠ 0) :
z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + ((k : ℕ) • (p / z) : R) := by
induction ψ using Quotient.inductionOn'
induction θ using Quotient.inductionOn'
-- Porting note: Introduced Zp notation to shorten lines
let Zp := AddSubgroup.zmultiples p
have : (Quotient.mk'' : R → R ⧸ Zp) = ((↑) : R → R ⧸ Zp) := rfl
simp only [this]
simp_rw [← QuotientAddGroup.mk_zsmul, ← QuotientAddGroup.mk_add,
QuotientAddGroup.eq_iff_sub_mem, ← smul_sub, ← sub_sub]
exact AddSubgroup.zsmul_mem_zmultiples_iff_exists_sub_div hz
theorem zmultiples_nsmul_eq_nsmul_iff {ψ θ : R ⧸ AddSubgroup.zmultiples p} {n : ℕ} (hz : n ≠ 0) :
n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (p / n : R) := by
rw [← natCast_zsmul ψ, ← natCast_zsmul θ,
zmultiples_zsmul_eq_zsmul_iff (Int.natCast_ne_zero.mpr hz), Int.cast_natCast]
rfl
end QuotientAddGroup
|
Algebra\ContinuedFractions\Basic.lean
|
/-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Data.Seq.Seq
import Mathlib.Algebra.Field.Defs
/-!
# Basic Definitions/Theorems for Continued Fractions
## Summary
We define generalised, simple, and regular continued fractions and functions to evaluate their
convergents. We follow the naming conventions from Wikipedia and [wall2018analytic], Chapter 1.
## Main definitions
1. Generalised continued fractions (gcfs)
2. Simple continued fractions (scfs)
3. (Regular) continued fractions ((r)cfs)
4. Computation of convergents using the recurrence relation in `convs`.
5. Computation of convergents by directly evaluating the fraction described by the gcf in `convs'`.
## Implementation notes
1. The most commonly used kind of continued fractions in the literature are regular continued
fractions. We hence just call them `ContFract` in the library.
2. We use sequences from `Data.Seq` to encode potentially infinite sequences.
## References
- <https://en.wikipedia.org/wiki/Generalized_continued_fraction>
- [Wall, H.S., *Analytic Theory of Continued Fractions*][wall2018analytic]
## Tags
numerics, number theory, approximations, fractions
-/
-- Fix a carrier `α`.
variable (α : Type*)
/-!### Definitions-/
-- Porting note: Originally `protected structure GenContFract.Pair`
/-- We collect a partial numerator `aᵢ` and partial denominator `bᵢ` in a pair `⟨aᵢ, bᵢ⟩`. -/
structure GenContFract.Pair where
/-- Partial numerator -/
a : α
/-- Partial denominator -/
b : α
deriving Inhabited
open GenContFract
/-! Interlude: define some expected coercions and instances. -/
namespace GenContFract.Pair
variable {α}
/-- Make a `GenContFract.Pair` printable. -/
instance [Repr α] : Repr (Pair α) :=
⟨fun p _ ↦ "(a : " ++ repr p.a ++ ", b : " ++ repr p.b ++ ")"⟩
/-- Maps a function `f` on both components of a given pair. -/
def map {β : Type*} (f : α → β) (gp : Pair α) : Pair β :=
⟨f gp.a, f gp.b⟩
section coe
-- Fix another type `β` which we will convert to.
variable {β : Type*} [Coe α β]
-- Porting note: added so we can add the `@[coe]` attribute
/-- The coercion between numerator-denominator pairs happens componentwise. -/
@[coe]
def coeFn : Pair α → Pair β := map (↑)
/-- Coerce a pair by elementwise coercion. -/
instance : Coe (Pair α) (Pair β) :=
⟨coeFn⟩
@[simp, norm_cast]
theorem coe_toPair {a b : α} : (↑(Pair.mk a b) : Pair β) = Pair.mk (a : β) (b : β) := rfl
end coe
end GenContFract.Pair
/-- A *generalised continued fraction* (gcf) is a potentially infinite expression of the form
$$
h + \dfrac{a_0}
{b_0 + \dfrac{a_1}
{b_1 + \dfrac{a_2}
{b_2 + \dfrac{a_3}
{b_3 + \dots}}}}
$$
where `h` is called the *head term* or *integer part*, the `aᵢ` are called the
*partial numerators* and the `bᵢ` the *partial denominators* of the gcf.
We store the sequence of partial numerators and denominators in a sequence of `GenContFract.Pair`s
`s`.
For convenience, one often writes `[h; (a₀, b₀), (a₁, b₁), (a₂, b₂),...]`.
-/
@[ext]
structure GenContFract where
/-- Head term -/
h : α
/-- Sequence of partial numerator and denominator pairs. -/
s : Stream'.Seq <| Pair α
variable {α}
namespace GenContFract
/-- Constructs a generalized continued fraction without fractional part. -/
def ofInteger (a : α) : GenContFract α :=
⟨a, Stream'.Seq.nil⟩
instance [Inhabited α] : Inhabited (GenContFract α) :=
⟨ofInteger default⟩
/-- Returns the sequence of partial numerators `aᵢ` of `g`. -/
def partNums (g : GenContFract α) : Stream'.Seq α :=
g.s.map Pair.a
/-- Returns the sequence of partial denominators `bᵢ` of `g`. -/
def partDens (g : GenContFract α) : Stream'.Seq α :=
g.s.map Pair.b
/-- A gcf terminated at position `n` if its sequence terminates at position `n`. -/
def TerminatedAt (g : GenContFract α) (n : ℕ) : Prop :=
g.s.TerminatedAt n
/-- It is decidable whether a gcf terminated at a given position. -/
instance terminatedAtDecidable (g : GenContFract α) (n : ℕ) :
Decidable (g.TerminatedAt n) := by
unfold TerminatedAt
infer_instance
/-- A gcf terminates if its sequence terminates. -/
def Terminates (g : GenContFract α) : Prop :=
g.s.Terminates
section coe
/-! Interlude: define some expected coercions. -/
-- Fix another type `β` which we will convert to.
variable {β : Type*} [Coe α β]
-- Porting note: Added to put `@[coe]` attr on it.
/-- The coercion between `GenContFract` happens on the head term
and all numerator-denominator pairs componentwise. -/
@[coe]
def coeFn : GenContFract α → GenContFract β :=
fun g ↦ ⟨(g.h : β), (g.s.map (↑) : Stream'.Seq <| Pair β)⟩
/-- Coerce a gcf by elementwise coercion. -/
instance : Coe (GenContFract α) (GenContFract β) :=
⟨coeFn⟩
@[simp, norm_cast]
theorem coe_toGenContFract {g : GenContFract α} :
(g : GenContFract β) =
⟨(g.h : β), (g.s.map (↑) : Stream'.Seq <| Pair β)⟩ := rfl
end coe
end GenContFract
/-- A generalized continued fraction is a *simple continued fraction* if all partial numerators are
equal to one.
$$
h + \dfrac{1}
{b_0 + \dfrac{1}
{b_1 + \dfrac{1}
{b_2 + \dfrac{1}
{b_3 + \dots}}}}
$$
-/
def GenContFract.IsSimpContFract (g : GenContFract α)
[One α] : Prop :=
∀ (n : ℕ) (aₙ : α), g.partNums.get? n = some aₙ → aₙ = 1
variable (α)
/-- A *simple continued fraction* (scf) is a generalized continued fraction (gcf) whose partial
numerators are equal to one.
$$
h + \dfrac{1}
{b_0 + \dfrac{1}
{b_1 + \dfrac{1}
{b_2 + \dfrac{1}
{b_3 + \dots}}}}
$$
For convenience, one often writes `[h; b₀, b₁, b₂,...]`.
It is encoded as the subtype of gcfs that satisfy `GenContFract.IsSimpContFract`.
-/
def SimpContFract [One α] :=
{ g : GenContFract α // g.IsSimpContFract }
variable {α}
-- Interlude: define some expected coercions.
namespace SimpContFract
variable [One α]
/-- Constructs a simple continued fraction without fractional part. -/
def ofInteger (a : α) : SimpContFract α :=
⟨GenContFract.ofInteger a, fun n aₙ h ↦ by cases h⟩
instance : Inhabited (SimpContFract α) :=
⟨ofInteger 1⟩
/-- Lift a scf to a gcf using the inclusion map. -/
instance : Coe (SimpContFract α) (GenContFract α) :=
-- Porting note: originally `by unfold SimpContFract; infer_instance`
⟨Subtype.val⟩
-- Porting note: Syntactic tautology due to change in `Coe` above.
-- theorem coe_toGenContFract {s : SimpContFract α} :
-- (↑s : GenContFract α) = s.val := rfl
end SimpContFract
/--
A simple continued fraction is a *(regular) continued fraction* ((r)cf) if all partial denominators
`bᵢ` are positive, i.e. `0 < bᵢ`.
-/
def SimpContFract.IsContFract [One α] [Zero α] [LT α]
(s : SimpContFract α) : Prop :=
∀ (n : ℕ) (bₙ : α),
(↑s : GenContFract α).partDens.get? n = some bₙ → 0 < bₙ
variable (α)
/-- A *(regular) continued fraction* ((r)cf) is a simple continued fraction (scf) whose partial
denominators are all positive. It is the subtype of scfs that satisfy `SimpContFract.IsContFract`.
-/
def ContFract [One α] [Zero α] [LT α] :=
{ s : SimpContFract α // s.IsContFract }
variable {α}
/-! Interlude: define some expected coercions. -/
namespace ContFract
variable [One α] [Zero α] [LT α]
/-- Constructs a continued fraction without fractional part. -/
def ofInteger (a : α) : ContFract α :=
⟨SimpContFract.ofInteger a, fun n bₙ h ↦ by cases h⟩
instance : Inhabited (ContFract α) :=
⟨ofInteger 0⟩
/-- Lift a cf to a scf using the inclusion map. -/
instance : Coe (ContFract α) (SimpContFract α) :=
-- Porting note: originally `by unfold ContFract; infer_instance`
⟨Subtype.val⟩
-- Porting note: Syntactic tautology due to change of `Coe` above.
-- theorem coe_to_simpleContFract {c : ContFract α} :
-- (↑c : SimpContFract α) = c.val := rfl
/-- Lift a cf to a scf using the inclusion map. -/
instance : Coe (ContFract α) (GenContFract α) :=
⟨fun c ↦ c.val⟩
-- Porting note: was `fun c ↦ ↑(↑c : SimpContFract α)`
-- Porting note: Syntactic tautology due to change of `Coe` above.
-- theorem coe_toGenContFract {c : ContFract α} :
-- (↑c : GenContFract α) = c.val := rfl
end ContFract
namespace GenContFract
/-!
### Computation of Convergents
We now define how to compute the convergents of a gcf. There are two standard ways to do this:
directly evaluating the (infinite) fraction described by the gcf or using a recurrence relation.
For (r)cfs, these computations are equivalent as shown in
`Algebra.ContinuedFractions.ConvergentsEquiv`.
-/
-- Fix a division ring for the computations.
variable {K : Type*} [DivisionRing K]
/-!
We start with the definition of the recurrence relation. Given a gcf `g`, for all `n ≥ 1`, we define
- `A₋₁ = 1, A₀ = h, Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, and
- `B₋₁ = 0, B₀ = 1, Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂`.
`Aₙ, Bₙ` are called the *nth continuants*, `Aₙ` the *nth numerator*, and `Bₙ` the
*nth denominator* of `g`. The *nth convergent* of `g` is given by `Aₙ / Bₙ`.
-/
/-- Returns the next numerator `Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, where `predA` is `Aₙ₋₁`,
`ppredA` is `Aₙ₋₂`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`.
-/
def nextNum (a b ppredA predA : K) : K :=
b * predA + a * ppredA
/-- Returns the next denominator `Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂`, where `predB` is `Bₙ₋₁` and
`ppredB` is `Bₙ₋₂`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`.
-/
def nextDen (aₙ bₙ ppredB predB : K) : K :=
bₙ * predB + aₙ * ppredB
/--
Returns the next continuants `⟨Aₙ, Bₙ⟩` using `nextNum` and `nextDen`, where `pred`
is `⟨Aₙ₋₁, Bₙ₋₁⟩`, `ppred` is `⟨Aₙ₋₂, Bₙ₋₂⟩`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`.
-/
def nextConts (a b : K) (ppred pred : Pair K) : Pair K :=
⟨nextNum a b ppred.a pred.a, nextDen a b ppred.b pred.b⟩
/-- Returns the continuants `⟨Aₙ₋₁, Bₙ₋₁⟩` of `g`. -/
def contsAux (g : GenContFract K) : Stream' (Pair K)
| 0 => ⟨1, 0⟩
| 1 => ⟨g.h, 1⟩
| n + 2 =>
match g.s.get? n with
| none => contsAux g (n + 1)
| some gp => nextConts gp.a gp.b (contsAux g n) (contsAux g (n + 1))
/-- Returns the continuants `⟨Aₙ, Bₙ⟩` of `g`. -/
def conts (g : GenContFract K) : Stream' (Pair K) :=
g.contsAux.tail
/-- Returns the numerators `Aₙ` of `g`. -/
def nums (g : GenContFract K) : Stream' K :=
g.conts.map Pair.a
/-- Returns the denominators `Bₙ` of `g`. -/
def dens (g : GenContFract K) : Stream' K :=
g.conts.map Pair.b
/-- Returns the convergents `Aₙ / Bₙ` of `g`, where `Aₙ, Bₙ` are the nth continuants of `g`. -/
def convs (g : GenContFract K) : Stream' K :=
fun n : ℕ ↦ g.nums n / g.dens n
/--
Returns the approximation of the fraction described by the given sequence up to a given position n.
For example, `convs'Aux [(1, 2), (3, 4), (5, 6)] 2 = 1 / (2 + 3 / 4)` and
`convs'Aux [(1, 2), (3, 4), (5, 6)] 0 = 0`.
-/
def convs'Aux : Stream'.Seq (Pair K) → ℕ → K
| _, 0 => 0
| s, n + 1 =>
match s.head with
| none => 0
| some gp => gp.a / (gp.b + convs'Aux s.tail n)
/-- Returns the convergents of `g` by evaluating the fraction described by `g` up to a given
position `n`. For example, `convs' [9; (1, 2), (3, 4), (5, 6)] 2 = 9 + 1 / (2 + 3 / 4)` and
`convs' [9; (1, 2), (3, 4), (5, 6)] 0 = 9`
-/
def convs' (g : GenContFract K) (n : ℕ) : K :=
g.h + convs'Aux g.s n
end GenContFract
|
Algebra\ContinuedFractions\ContinuantsRecurrence.lean
|
/-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Translations
/-!
# Recurrence Lemmas for the Continuants (`conts`) Function of Continued Fractions
## Summary
Given a generalized continued fraction `g`, for all `n ≥ 1`, we prove that the continuants (`conts`)
function indeed satisfies the following recurrences:
- `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`, and
- `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`.
-/
namespace GenContFract
variable {K : Type*} {g : GenContFract K} {n : ℕ} [DivisionRing K]
theorem contsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_contsAux_eq : g.contsAux n = ppred)
(succ_nth_contsAux_eq : g.contsAux (n + 1) = pred) :
g.contsAux (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by
simp [*, contsAux, nextConts, nextDen, nextNum]
theorem conts_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_contsAux_eq : g.contsAux n = ppred)
(succ_nth_contsAux_eq : g.contsAux (n + 1) = pred) :
g.conts (n + 1) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by
simp [nth_cont_eq_succ_nth_contAux,
contsAux_recurrence nth_s_eq nth_contsAux_eq succ_nth_contsAux_eq]
/-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂` and `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/
theorem conts_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.conts n = ppred) (succ_nth_conts_eq : g.conts (n + 1) = pred) :
g.conts (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by
rw [nth_cont_eq_succ_nth_contAux] at nth_conts_eq succ_nth_conts_eq
exact conts_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq
/-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`. -/
theorem nums_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.nums n = ppredA)
(succ_nth_num_eq : g.nums (n + 1) = predA) :
g.nums (n + 2) = gp.b * predA + gp.a * ppredA := by
obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.conts n = conts ∧ conts.a = ppredA :=
exists_conts_a_of_num nth_num_eq
obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ :
∃ conts, g.conts (n + 1) = conts ∧ conts.a = predA :=
exists_conts_a_of_num succ_nth_num_eq
rw [num_eq_conts_a, conts_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq]
/-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/
theorem dens_recurrence {gp : Pair K} {ppredB predB : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_den_eq : g.dens n = ppredB)
(succ_nth_den_eq : g.dens (n + 1) = predB) :
g.dens (n + 2) = gp.b * predB + gp.a * ppredB := by
obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.conts n = conts ∧ conts.b = ppredB :=
exists_conts_b_of_den nth_den_eq
obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ :
∃ conts, g.conts (n + 1) = conts ∧ conts.b = predB :=
exists_conts_b_of_den succ_nth_den_eq
rw [den_eq_conts_b, conts_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq]
end GenContFract
|
Algebra\ContinuedFractions\ConvergentsEquiv.lean
|
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence
import Mathlib.Algebra.ContinuedFractions.TerminatedStable
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Ring
/-!
# Equivalence of Recursive and Direct Computations of Convergents of Generalized Continued Fractions
## Summary
We show the equivalence of two computations of convergents (recurrence relation (`convs`) vs.
direct evaluation (`convs'`)) for generalized continued fractions
(`GenContFract`s) on linear ordered fields. We follow the proof from
[hardy2008introduction], Chapter 10. Here's a sketch:
Let `c` be a continued fraction `[h; (a₀, b₀), (a₁, b₁), (a₂, b₂),...]`, visually:
$$
c = h + \dfrac{a_0}
{b_0 + \dfrac{a_1}
{b_1 + \dfrac{a_2}
{b_2 + \dfrac{a_3}
{b_3 + \dots}}}}
$$
One can compute the convergents of `c` in two ways:
1. Directly evaluating the fraction described by `c` up to a given `n` (`convs'`)
2. Using the recurrence (`convs`):
- `A₋₁ = 1, A₀ = h, Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, and
- `B₋₁ = 0, B₀ = 1, Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂`.
To show the equivalence of the computations in the main theorem of this file
`convs_eq_convs'`, we proceed by induction. The case `n = 0` is trivial.
For `n + 1`, we first "squash" the `n + 1`th position of `c` into the `n`th position to obtain
another continued fraction
`c' := [h; (a₀, b₀),..., (aₙ-₁, bₙ-₁), (aₙ, bₙ + aₙ₊₁ / bₙ₊₁), (aₙ₊₁, bₙ₊₁),...]`.
This squashing process is formalised in section `Squash`. Note that directly evaluating `c` up to
position `n + 1` is equal to evaluating `c'` up to `n`. This is shown in lemma
`succ_nth_conv'_eq_squashGCF_nth_conv'`.
By the inductive hypothesis, the two computations for the `n`th convergent of `c` coincide.
So all that is left to show is that the recurrence relation for `c` at `n + 1` and `c'` at
`n` coincide. This can be shown by another induction.
The corresponding lemma in this file is `succ_nth_conv_eq_squashGCF_nth_conv`.
## Main Theorems
- `GenContFract.convs_eq_convs'` shows the equivalence under a strict positivity restriction
on the sequence.
- `ContFract.convs_eq_convs'` shows the equivalence for regular continued fractions.
## References
- https://en.wikipedia.org/wiki/Generalized_continued_fraction
- [*Hardy, GH and Wright, EM and Heath-Brown, Roger and Silverman, Joseph*][hardy2008introduction]
## Tags
fractions, recurrence, equivalence
-/
variable {K : Type*} {n : ℕ}
namespace GenContFract
variable {g : GenContFract K} {s : Stream'.Seq <| Pair K}
section Squash
/-!
We will show the equivalence of the computations by induction. To make the induction work, we need
to be able to *squash* the nth and (n + 1)th value of a sequence. This squashing itself and the
lemmas about it are not very interesting. As a reader, you hence might want to skip this section.
-/
section WithDivisionRing
variable [DivisionRing K]
/-- Given a sequence of `GenContFract.Pair`s `s = [(a₀, bₒ), (a₁, b₁), ...]`, `squashSeq s n`
combines `⟨aₙ, bₙ⟩` and `⟨aₙ₊₁, bₙ₊₁⟩` at position `n` to `⟨aₙ, bₙ + aₙ₊₁ / bₙ₊₁⟩`. For example,
`squashSeq s 0 = [(a₀, bₒ + a₁ / b₁), (a₁, b₁),...]`.
If `s.TerminatedAt (n + 1)`, then `squashSeq s n = s`.
-/
def squashSeq (s : Stream'.Seq <| Pair K) (n : ℕ) : Stream'.Seq (Pair K) :=
match Prod.mk (s.get? n) (s.get? (n + 1)) with
| ⟨some gp_n, some gp_succ_n⟩ =>
Stream'.Seq.nats.zipWith
-- return the squashed value at position `n`; otherwise, do nothing.
(fun n' gp => if n' = n then ⟨gp_n.a, gp_n.b + gp_succ_n.a / gp_succ_n.b⟩ else gp) s
| _ => s
/-! We now prove some simple lemmas about the squashed sequence -/
/-- If the sequence already terminated at position `n + 1`, nothing gets squashed. -/
theorem squashSeq_eq_self_of_terminated (terminatedAt_succ_n : s.TerminatedAt (n + 1)) :
squashSeq s n = s := by
change s.get? (n + 1) = none at terminatedAt_succ_n
cases s_nth_eq : s.get? n <;> simp only [*, squashSeq]
/-- If the sequence has not terminated before position `n + 1`, the value at `n + 1` gets
squashed into position `n`. -/
theorem squashSeq_nth_of_not_terminated {gp_n gp_succ_n : Pair K} (s_nth_eq : s.get? n = some gp_n)
(s_succ_nth_eq : s.get? (n + 1) = some gp_succ_n) :
(squashSeq s n).get? n = some ⟨gp_n.a, gp_n.b + gp_succ_n.a / gp_succ_n.b⟩ := by
simp [*, squashSeq]
/-- The values before the squashed position stay the same. -/
theorem squashSeq_nth_of_lt {m : ℕ} (m_lt_n : m < n) : (squashSeq s n).get? m = s.get? m := by
cases s_succ_nth_eq : s.get? (n + 1) with
| none => rw [squashSeq_eq_self_of_terminated s_succ_nth_eq]
| some =>
obtain ⟨gp_n, s_nth_eq⟩ : ∃ gp_n, s.get? n = some gp_n :=
s.ge_stable n.le_succ s_succ_nth_eq
obtain ⟨gp_m, s_mth_eq⟩ : ∃ gp_m, s.get? m = some gp_m :=
s.ge_stable (le_of_lt m_lt_n) s_nth_eq
simp [*, squashSeq, m_lt_n.ne]
/-- Squashing at position `n + 1` and taking the tail is the same as squashing the tail of the
sequence at position `n`. -/
theorem squashSeq_succ_n_tail_eq_squashSeq_tail_n :
(squashSeq s (n + 1)).tail = squashSeq s.tail n := by
cases s_succ_succ_nth_eq : s.get? (n + 2) with
| none =>
cases s_succ_nth_eq : s.get? (n + 1) <;>
simp only [squashSeq, Stream'.Seq.get?_tail, s_succ_nth_eq, s_succ_succ_nth_eq]
| some gp_succ_succ_n =>
obtain ⟨gp_succ_n, s_succ_nth_eq⟩ : ∃ gp_succ_n, s.get? (n + 1) = some gp_succ_n :=
s.ge_stable (n + 1).le_succ s_succ_succ_nth_eq
-- apply extensionality with `m` and continue by cases `m = n`.
ext1 m
cases' Decidable.em (m = n) with m_eq_n m_ne_n
· simp [*, squashSeq]
· cases s_succ_mth_eq : s.get? (m + 1)
· simp only [*, squashSeq, Stream'.Seq.get?_tail, Stream'.Seq.get?_zipWith,
Option.map₂_none_right]
· simp [*, squashSeq]
/-- The auxiliary function `convs'Aux` returns the same value for a sequence and the
corresponding squashed sequence at the squashed position. -/
theorem succ_succ_nth_conv'Aux_eq_succ_nth_conv'Aux_squashSeq :
convs'Aux s (n + 2) = convs'Aux (squashSeq s n) (n + 1) := by
cases s_succ_nth_eq : s.get? <| n + 1 with
| none =>
rw [squashSeq_eq_self_of_terminated s_succ_nth_eq,
convs'Aux_stable_step_of_terminated s_succ_nth_eq]
| some gp_succ_n =>
induction n generalizing s gp_succ_n with
| zero =>
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head :=
s.ge_stable zero_le_one s_succ_nth_eq
have : (squashSeq s 0).head = some ⟨gp_head.a, gp_head.b + gp_succ_n.a / gp_succ_n.b⟩ :=
squashSeq_nth_of_not_terminated s_head_eq s_succ_nth_eq
simp_all [convs'Aux, Stream'.Seq.head, Stream'.Seq.get?_tail]
| succ m IH =>
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head :=
s.ge_stable (m + 2).zero_le s_succ_nth_eq
suffices
gp_head.a / (gp_head.b + convs'Aux s.tail (m + 2)) =
convs'Aux (squashSeq s (m + 1)) (m + 2)
by simpa only [convs'Aux, s_head_eq]
have : convs'Aux s.tail (m + 2) = convs'Aux (squashSeq s.tail m) (m + 1) := by
refine IH gp_succ_n ?_
simpa [Stream'.Seq.get?_tail] using s_succ_nth_eq
have : (squashSeq s (m + 1)).head = some gp_head :=
(squashSeq_nth_of_lt m.succ_pos).trans s_head_eq
simp_all [convs'Aux, squashSeq_succ_n_tail_eq_squashSeq_tail_n]
/-! Let us now lift the squashing operation to gcfs. -/
/-- Given a gcf `g = [h; (a₀, bₒ), (a₁, b₁), ...]`, we have
- `squashGCF g 0 = [h + a₀ / b₀); (a₀, bₒ), ...]`,
- `squashGCF g (n + 1) = ⟨g.h, squashSeq g.s n⟩`
-/
def squashGCF (g : GenContFract K) : ℕ → GenContFract K
| 0 =>
match g.s.get? 0 with
| none => g
| some gp => ⟨g.h + gp.a / gp.b, g.s⟩
| n + 1 => ⟨g.h, squashSeq g.s n⟩
/-! Again, we derive some simple lemmas that are not really of interest. This time for the
squashed gcf. -/
/-- If the gcf already terminated at position `n`, nothing gets squashed. -/
theorem squashGCF_eq_self_of_terminated (terminatedAt_n : TerminatedAt g n) :
squashGCF g n = g := by
cases n with
| zero =>
change g.s.get? 0 = none at terminatedAt_n
simp only [convs', squashGCF, convs'Aux, terminatedAt_n]
| succ =>
cases g
simp only [squashGCF, mk.injEq, true_and]
exact squashSeq_eq_self_of_terminated terminatedAt_n
/-- The values before the squashed position stay the same. -/
theorem squashGCF_nth_of_lt {m : ℕ} (m_lt_n : m < n) :
(squashGCF g (n + 1)).s.get? m = g.s.get? m := by
simp only [squashGCF, squashSeq_nth_of_lt m_lt_n, Nat.add_eq, add_zero]
/-- `convs'` returns the same value for a gcf and the corresponding squashed gcf at the
squashed position. -/
theorem succ_nth_conv'_eq_squashGCF_nth_conv' :
g.convs' (n + 1) = (squashGCF g n).convs' n := by
cases n with
| zero =>
cases g_s_head_eq : g.s.get? 0 <;>
simp [g_s_head_eq, squashGCF, convs', convs'Aux, Stream'.Seq.head]
| succ =>
simp only [succ_succ_nth_conv'Aux_eq_succ_nth_conv'Aux_squashSeq, convs',
squashGCF]
/-- The auxiliary continuants before the squashed position stay the same. -/
theorem contsAux_eq_contsAux_squashGCF_of_le {m : ℕ} :
m ≤ n → contsAux g m = (squashGCF g n).contsAux m :=
Nat.strong_induction_on m
(by
clear m
intro m IH m_le_n
cases' m with m'
· rfl
· cases' n with n'
· exact (m'.not_succ_le_zero m_le_n).elim
-- 1 ≰ 0
· cases' m' with m''
· rfl
· -- get some inequalities to instantiate the IH for m'' and m'' + 1
have m'_lt_n : m'' + 1 < n' + 1 := m_le_n
have succ_m''th_contsAux_eq := IH (m'' + 1) (lt_add_one (m'' + 1)) m'_lt_n.le
have : m'' < m'' + 2 := lt_add_of_pos_right m'' zero_lt_two
have m''th_contsAux_eq := IH m'' this (le_trans this.le m_le_n)
have : (squashGCF g (n' + 1)).s.get? m'' = g.s.get? m'' :=
squashGCF_nth_of_lt (Nat.succ_lt_succ_iff.mp m'_lt_n)
simp [contsAux, succ_m''th_contsAux_eq, m''th_contsAux_eq, this])
end WithDivisionRing
/-- The convergents coincide in the expected way at the squashed position if the partial denominator
at the squashed position is not zero. -/
theorem succ_nth_conv_eq_squashGCF_nth_conv [Field K]
(nth_partDen_ne_zero : ∀ {b : K}, g.partDens.get? n = some b → b ≠ 0) :
g.convs (n + 1) = (squashGCF g n).convs n := by
cases' Decidable.em (g.TerminatedAt n) with terminatedAt_n not_terminatedAt_n
· have : squashGCF g n = g := squashGCF_eq_self_of_terminated terminatedAt_n
simp only [this, convs_stable_of_terminated n.le_succ terminatedAt_n]
· obtain ⟨⟨a, b⟩, s_nth_eq⟩ : ∃ gp_n, g.s.get? n = some gp_n :=
Option.ne_none_iff_exists'.mp not_terminatedAt_n
have b_ne_zero : b ≠ 0 := nth_partDen_ne_zero (partDen_eq_s_b s_nth_eq)
cases n with
| zero =>
suffices (b * g.h + a) / b = g.h + a / b by
simpa [squashGCF, s_nth_eq, conv_eq_conts_a_div_conts_b,
conts_recurrenceAux s_nth_eq zeroth_contAux_eq_one_zero first_contAux_eq_h_one]
calc
(b * g.h + a) / b = b * g.h / b + a / b := by ring
-- requires `Field`, not `DivisionRing`
_ = g.h + a / b := by rw [mul_div_cancel_left₀ _ b_ne_zero]
| succ n' =>
obtain ⟨⟨pa, pb⟩, s_n'th_eq⟩ : ∃ gp_n', g.s.get? n' = some gp_n' :=
g.s.ge_stable n'.le_succ s_nth_eq
-- Notations
let g' := squashGCF g (n' + 1)
set pred_conts := g.contsAux (n' + 1) with succ_n'th_contsAux_eq
set ppred_conts := g.contsAux n' with n'th_contsAux_eq
let pA := pred_conts.a
let pB := pred_conts.b
let ppA := ppred_conts.a
let ppB := ppred_conts.b
set pred_conts' := g'.contsAux (n' + 1) with succ_n'th_contsAux_eq'
set ppred_conts' := g'.contsAux n' with n'th_contsAux_eq'
let pA' := pred_conts'.a
let pB' := pred_conts'.b
let ppA' := ppred_conts'.a
let ppB' := ppred_conts'.b
-- first compute the convergent of the squashed gcf
have : g'.convs (n' + 1) =
((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB') := by
have : g'.s.get? n' = some ⟨pa, pb + a / b⟩ :=
squashSeq_nth_of_not_terminated s_n'th_eq s_nth_eq
rw [conv_eq_conts_a_div_conts_b,
conts_recurrenceAux this n'th_contsAux_eq'.symm succ_n'th_contsAux_eq'.symm]
rw [this]
-- then compute the convergent of the original gcf by recursively unfolding the continuants
-- computation twice
have : g.convs (n' + 2) =
(b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB) := by
-- use the recurrence once
have : g.contsAux (n' + 2) = ⟨pb * pA + pa * ppA, pb * pB + pa * ppB⟩ :=
contsAux_recurrence s_n'th_eq n'th_contsAux_eq.symm succ_n'th_contsAux_eq.symm
-- and a second time
rw [conv_eq_conts_a_div_conts_b,
conts_recurrenceAux s_nth_eq succ_n'th_contsAux_eq.symm this]
rw [this]
suffices
((pb + a / b) * pA + pa * ppA) / ((pb + a / b) * pB + pa * ppB) =
(b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB) by
obtain ⟨eq1, eq2, eq3, eq4⟩ : pA' = pA ∧ pB' = pB ∧ ppA' = ppA ∧ ppB' = ppB := by
simp [*, pA', pB', ppA', ppB',
(contsAux_eq_contsAux_squashGCF_of_le <| le_refl <| n' + 1).symm,
(contsAux_eq_contsAux_squashGCF_of_le n'.le_succ).symm]
symm
simpa only [eq1, eq2, eq3, eq4, mul_div_cancel_right₀ _ b_ne_zero]
field_simp
congr 1 <;> ring
end Squash
/-- Shows that the recurrence relation (`convs`) and direct evaluation (`convs'`) of the
generalized continued fraction coincide at position `n` if the sequence of fractions contains
strictly positive values only.
Requiring positivity of all values is just one possible condition to obtain this result.
For example, the dual - sequences with strictly negative values only - would also work.
In practice, one most commonly deals with regular continued fractions, which satisfy the
positivity criterion required here. The analogous result for them
(see `ContFract.convs_eq_convs`) hence follows directly from this theorem.
-/
theorem convs_eq_convs' [LinearOrderedField K]
(s_pos : ∀ {gp : Pair K} {m : ℕ}, m < n → g.s.get? m = some gp → 0 < gp.a ∧ 0 < gp.b) :
g.convs n = g.convs' n := by
induction n generalizing g with
| zero => simp
| succ n IH =>
let g' := squashGCF g n
-- first replace the rhs with the squashed computation
suffices g.convs (n + 1) = g'.convs' n by
rwa [succ_nth_conv'_eq_squashGCF_nth_conv']
cases' Decidable.em (TerminatedAt g n) with terminatedAt_n not_terminatedAt_n
· have g'_eq_g : g' = g := squashGCF_eq_self_of_terminated terminatedAt_n
rw [convs_stable_of_terminated n.le_succ terminatedAt_n, g'_eq_g, IH _]
intro _ _ m_lt_n s_mth_eq
exact s_pos (Nat.lt.step m_lt_n) s_mth_eq
· suffices g.convs (n + 1) = g'.convs n by
-- invoke the IH for the squashed gcf
rwa [← IH]
intro gp' m m_lt_n s_mth_eq'
-- case distinction on m + 1 = n or m + 1 < n
cases' m_lt_n with n succ_m_lt_n
· -- the difficult case at the squashed position: we first obtain the values from
-- the sequence
obtain ⟨gp_succ_m, s_succ_mth_eq⟩ : ∃ gp_succ_m, g.s.get? (m + 1) = some gp_succ_m :=
Option.ne_none_iff_exists'.mp not_terminatedAt_n
obtain ⟨gp_m, mth_s_eq⟩ : ∃ gp_m, g.s.get? m = some gp_m :=
g.s.ge_stable m.le_succ s_succ_mth_eq
-- we then plug them into the recurrence
suffices 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b by
have ot : g'.s.get? m = some ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ :=
squashSeq_nth_of_not_terminated mth_s_eq s_succ_mth_eq
have : gp' = ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ := by
simp_all only [Option.some.injEq]
rwa [this]
have m_lt_n : m < m.succ := Nat.lt_succ_self m
refine ⟨(s_pos (Nat.lt.step m_lt_n) mth_s_eq).left, ?_⟩
refine add_pos (s_pos (Nat.lt.step m_lt_n) mth_s_eq).right ?_
have : 0 < gp_succ_m.a ∧ 0 < gp_succ_m.b := s_pos (lt_add_one <| m + 1) s_succ_mth_eq
exact div_pos this.left this.right
· -- the easy case: before the squashed position, nothing changes
refine s_pos (Nat.lt.step <| Nat.lt.step succ_m_lt_n) ?_
exact Eq.trans (squashGCF_nth_of_lt succ_m_lt_n).symm s_mth_eq'
-- now the result follows from the fact that the convergents coincide at the squashed position
-- as established in `succ_nth_conv_eq_squashGCF_nth_conv`.
have : ∀ ⦃b⦄, g.partDens.get? n = some b → b ≠ 0 := by
intro b nth_partDen_eq
obtain ⟨gp, s_nth_eq, ⟨refl⟩⟩ : ∃ gp, g.s.get? n = some gp ∧ gp.b = b :=
exists_s_b_of_partDen nth_partDen_eq
exact (ne_of_lt (s_pos (lt_add_one n) s_nth_eq).right).symm
exact succ_nth_conv_eq_squashGCF_nth_conv @this
end GenContFract
open GenContFract
namespace ContFract
/-- Shows that the recurrence relation (`convs`) and direct evaluation (`convs'`) of a
(regular) continued fraction coincide. -/
nonrec theorem convs_eq_convs' [LinearOrderedField K] {c : ContFract K} :
(↑c : GenContFract K).convs = (↑c : GenContFract K).convs' := by
ext n
apply convs_eq_convs'
intro gp m _ s_nth_eq
exact ⟨zero_lt_one.trans_le ((c : SimpContFract K).property m gp.a
(partNum_eq_s_a s_nth_eq)).symm.le, c.property m gp.b <| partDen_eq_s_b s_nth_eq⟩
end ContFract
|
Algebra\ContinuedFractions\Determinant.lean
|
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence
import Mathlib.Algebra.ContinuedFractions.TerminatedStable
import Mathlib.Tactic.Ring
/-!
# Determinant Formula for Simple Continued Fraction
## Summary
We derive the so-called *determinant formula* for `SimpContFract`:
`Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-1)^(n + 1)`.
## TODO
Generalize this for `GenContFract` version:
`Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-a₀) * (-a₁) * .. * (-aₙ₊₁)`.
## References
- https://en.wikipedia.org/wiki/Generalized_continued_fraction#The_determinant_formula
-/
open GenContFract
namespace SimpContFract
variable {K : Type*} [Field K] {s : SimpContFract K} {n : ℕ}
theorem determinant_aux (hyp : n = 0 ∨ ¬(↑s : GenContFract K).TerminatedAt (n - 1)) :
((↑s : GenContFract K).contsAux n).a * ((↑s : GenContFract K).contsAux (n + 1)).b -
((↑s : GenContFract K).contsAux n).b * ((↑s : GenContFract K).contsAux (n + 1)).a =
(-1) ^ n := by
induction n with
| zero => simp [contsAux]
| succ n IH =>
-- set up some shorthand notation
let g := (↑s : GenContFract K)
let conts := contsAux g (n + 2)
set pred_conts := contsAux g (n + 1) with pred_conts_eq
set ppred_conts := contsAux g n with ppred_conts_eq
let pA := pred_conts.a
let pB := pred_conts.b
let ppA := ppred_conts.a
let ppB := ppred_conts.b
-- let's change the goal to something more readable
change pA * conts.b - pB * conts.a = (-1) ^ (n + 1)
have not_terminated_at_n : ¬TerminatedAt g n := Or.resolve_left hyp n.succ_ne_zero
obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp :=
Option.ne_none_iff_exists'.1 not_terminated_at_n
-- unfold the recurrence relation for `conts` once and simplify to derive the following
suffices pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1) by
simp only [conts, contsAux_recurrence s_nth_eq ppred_conts_eq pred_conts_eq]
have gp_a_eq_one : gp.a = 1 := s.property _ _ (partNum_eq_s_a s_nth_eq)
rw [gp_a_eq_one, this.symm]
ring
suffices pA * ppB - pB * ppA = (-1) ^ (n + 1) by calc
pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) =
pA * ppB + pA * gp.b * pB - pB * ppA - pB * gp.b * pA := by ring
_ = pA * ppB - pB * ppA := by ring
_ = (-1) ^ (n + 1) := by assumption
suffices ppA * pB - ppB * pA = (-1) ^ n by
have pow_succ_n : (-1 : K) ^ (n + 1) = -1 * (-1) ^ n := pow_succ' (-1) n
rw [pow_succ_n, ← this]
ring
exact IH <| Or.inr <| mt (terminated_stable <| n.sub_le 1) not_terminated_at_n
/-- The determinant formula `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-1)^(n + 1)`. -/
theorem determinant (not_terminatedAt_n : ¬(↑s : GenContFract K).TerminatedAt n) :
(↑s : GenContFract K).nums n * (↑s : GenContFract K).dens (n + 1) -
(↑s : GenContFract K).dens n * (↑s : GenContFract K).nums (n + 1) = (-1) ^ (n + 1) :=
determinant_aux <| Or.inr <| not_terminatedAt_n
end SimpContFract
|
Algebra\ContinuedFractions\TerminatedStable.lean
|
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Translations
/-!
# Stabilisation of gcf Computations Under Termination
## Summary
We show that the continuants and convergents of a gcf stabilise once the gcf terminates.
-/
namespace GenContFract
variable {K : Type*} {g : GenContFract K} {n m : ℕ}
/-- If a gcf terminated at position `n`, it also terminated at `m ≥ n`. -/
theorem terminated_stable (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) :
g.TerminatedAt m :=
g.s.terminated_stable n_le_m terminatedAt_n
variable [DivisionRing K]
theorem contsAux_stable_step_of_terminated (terminatedAt_n : g.TerminatedAt n) :
g.contsAux (n + 2) = g.contsAux (n + 1) := by
rw [terminatedAt_iff_s_none] at terminatedAt_n
simp only [contsAux, Nat.add_eq, Nat.add_zero, terminatedAt_n]
theorem contsAux_stable_of_terminated (n_lt_m : n < m) (terminatedAt_n : g.TerminatedAt n) :
g.contsAux m = g.contsAux (n + 1) := by
refine Nat.le_induction rfl (fun k hnk hk => ?_) _ n_lt_m
rcases Nat.exists_eq_add_of_lt hnk with ⟨k, rfl⟩
refine (contsAux_stable_step_of_terminated ?_).trans hk
exact terminated_stable (Nat.le_add_right _ _) terminatedAt_n
theorem convs'Aux_stable_step_of_terminated {s : Stream'.Seq <| Pair K}
(terminatedAt_n : s.TerminatedAt n) : convs'Aux s (n + 1) = convs'Aux s n := by
change s.get? n = none at terminatedAt_n
induction n generalizing s with
| zero => simp only [convs'Aux, terminatedAt_n, Stream'.Seq.head]
| succ n IH =>
cases s_head_eq : s.head with
| none => simp only [convs'Aux, s_head_eq]
| some gp_head =>
have : s.tail.TerminatedAt n := by
simp only [Stream'.Seq.TerminatedAt, s.get?_tail, terminatedAt_n]
have := IH this
rw [convs'Aux] at this
simp [this, Nat.add_eq, add_zero, convs'Aux, s_head_eq]
theorem convs'Aux_stable_of_terminated {s : Stream'.Seq <| Pair K} (n_le_m : n ≤ m)
(terminatedAt_n : s.TerminatedAt n) : convs'Aux s m = convs'Aux s n := by
induction' n_le_m with m n_le_m IH
· rfl
· refine (convs'Aux_stable_step_of_terminated ?_).trans IH
exact s.terminated_stable n_le_m terminatedAt_n
theorem conts_stable_of_terminated (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) :
g.conts m = g.conts n := by
simp only [nth_cont_eq_succ_nth_contAux,
contsAux_stable_of_terminated (Nat.pred_le_iff.mp n_le_m) terminatedAt_n]
theorem nums_stable_of_terminated (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) :
g.nums m = g.nums n := by
simp only [num_eq_conts_a, conts_stable_of_terminated n_le_m terminatedAt_n]
theorem dens_stable_of_terminated (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) :
g.dens m = g.dens n := by
simp only [den_eq_conts_b, conts_stable_of_terminated n_le_m terminatedAt_n]
theorem convs_stable_of_terminated (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) :
g.convs m = g.convs n := by
simp only [convs, dens_stable_of_terminated n_le_m terminatedAt_n,
nums_stable_of_terminated n_le_m terminatedAt_n]
theorem convs'_stable_of_terminated (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) :
g.convs' m = g.convs' n := by
simp only [convs', convs'Aux_stable_of_terminated n_le_m terminatedAt_n]
end GenContFract
|
Algebra\ContinuedFractions\Translations.lean
|
/-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Basic
import Mathlib.Algebra.GroupWithZero.Basic
/-!
# Basic Translation Lemmas Between Functions Defined for Continued Fractions
## Summary
Some simple translation lemmas between the different definitions of functions defined in
`Algebra.ContinuedFractions.Basic`.
-/
namespace GenContFract
section General
/-!
### Translations Between General Access Functions
Here we give some basic translations that hold by definition between the various methods that allow
us to access the numerators and denominators of a continued fraction.
-/
variable {α : Type*} {g : GenContFract α} {n : ℕ}
theorem terminatedAt_iff_s_terminatedAt : g.TerminatedAt n ↔ g.s.TerminatedAt n := by rfl
theorem terminatedAt_iff_s_none : g.TerminatedAt n ↔ g.s.get? n = none := by rfl
theorem partNum_none_iff_s_none : g.partNums.get? n = none ↔ g.s.get? n = none := by
cases s_nth_eq : g.s.get? n <;> simp [partNums, s_nth_eq]
theorem terminatedAt_iff_partNum_none : g.TerminatedAt n ↔ g.partNums.get? n = none := by
rw [terminatedAt_iff_s_none, partNum_none_iff_s_none]
theorem partDen_none_iff_s_none : g.partDens.get? n = none ↔ g.s.get? n = none := by
cases s_nth_eq : g.s.get? n <;> simp [partDens, s_nth_eq]
theorem terminatedAt_iff_partDen_none : g.TerminatedAt n ↔ g.partDens.get? n = none := by
rw [terminatedAt_iff_s_none, partDen_none_iff_s_none]
theorem partNum_eq_s_a {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) :
g.partNums.get? n = some gp.a := by simp [partNums, s_nth_eq]
theorem partDen_eq_s_b {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) :
g.partDens.get? n = some gp.b := by simp [partDens, s_nth_eq]
theorem exists_s_a_of_partNum {a : α} (nth_partNum_eq : g.partNums.get? n = some a) :
∃ gp, g.s.get? n = some gp ∧ gp.a = a := by
simpa [partNums, Stream'.Seq.map_get?] using nth_partNum_eq
theorem exists_s_b_of_partDen {b : α}
(nth_partDen_eq : g.partDens.get? n = some b) :
∃ gp, g.s.get? n = some gp ∧ gp.b = b := by
simpa [partDens, Stream'.Seq.map_get?] using nth_partDen_eq
end General
section WithDivisionRing
/-!
### Translations Between Computational Functions
Here we give some basic translations that hold by definition for the computational methods of a
continued fraction.
-/
variable {K : Type*} {g : GenContFract K} {n : ℕ} [DivisionRing K]
theorem nth_cont_eq_succ_nth_contAux : g.conts n = g.contsAux (n + 1) :=
rfl
theorem num_eq_conts_a : g.nums n = (g.conts n).a :=
rfl
theorem den_eq_conts_b : g.dens n = (g.conts n).b :=
rfl
theorem conv_eq_num_div_den : g.convs n = g.nums n / g.dens n :=
rfl
theorem conv_eq_conts_a_div_conts_b :
g.convs n = (g.conts n).a / (g.conts n).b :=
rfl
theorem exists_conts_a_of_num {A : K} (nth_num_eq : g.nums n = A) :
∃ conts, g.conts n = conts ∧ conts.a = A := by simpa
theorem exists_conts_b_of_den {B : K} (nth_denom_eq : g.dens n = B) :
∃ conts, g.conts n = conts ∧ conts.b = B := by simpa
@[simp]
theorem zeroth_contAux_eq_one_zero : g.contsAux 0 = ⟨1, 0⟩ :=
rfl
@[simp]
theorem first_contAux_eq_h_one : g.contsAux 1 = ⟨g.h, 1⟩ :=
rfl
@[simp]
theorem zeroth_cont_eq_h_one : g.conts 0 = ⟨g.h, 1⟩ :=
rfl
@[simp]
theorem zeroth_num_eq_h : g.nums 0 = g.h :=
rfl
@[simp]
theorem zeroth_den_eq_one : g.dens 0 = 1 :=
rfl
@[simp]
theorem zeroth_conv_eq_h : g.convs 0 = g.h := by
simp [conv_eq_num_div_den, num_eq_conts_a, den_eq_conts_b, div_one]
theorem second_contAux_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) :
g.contsAux 2 = ⟨gp.b * g.h + gp.a, gp.b⟩ := by
simp [zeroth_s_eq, contsAux, nextConts, nextDen, nextNum]
theorem first_cont_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) :
g.conts 1 = ⟨gp.b * g.h + gp.a, gp.b⟩ := by
simp [nth_cont_eq_succ_nth_contAux]
-- Porting note (#10959): simp used to work here, but now it can't figure out that 1 + 1 = 2
convert second_contAux_eq zeroth_s_eq
theorem first_num_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) :
g.nums 1 = gp.b * g.h + gp.a := by simp [num_eq_conts_a, first_cont_eq zeroth_s_eq]
theorem first_den_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) :
g.dens 1 = gp.b := by simp [den_eq_conts_b, first_cont_eq zeroth_s_eq]
@[simp]
theorem zeroth_conv'Aux_eq_zero {s : Stream'.Seq <| Pair K} :
convs'Aux s 0 = (0 : K) :=
rfl
@[simp]
theorem zeroth_conv'_eq_h : g.convs' 0 = g.h := by simp [convs']
theorem convs'Aux_succ_none {s : Stream'.Seq (Pair K)} (h : s.head = none) (n : ℕ) :
convs'Aux s (n + 1) = 0 := by simp [convs'Aux, h]
theorem convs'Aux_succ_some {s : Stream'.Seq (Pair K)} {p : Pair K} (h : s.head = some p)
(n : ℕ) : convs'Aux s (n + 1) = p.a / (p.b + convs'Aux s.tail n) := by
simp [convs'Aux, h]
end WithDivisionRing
end GenContFract
|
Algebra\ContinuedFractions\Computation\ApproximationCorollaries.lean
|
/-
Copyright (c) 2021 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Computation.Approximations
import Mathlib.Algebra.ContinuedFractions.ConvergentsEquiv
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Tactic.GCongr
import Mathlib.Topology.Order.LeftRightNhds
/-!
# Corollaries From Approximation Lemmas (`Algebra.ContinuedFractions.Computation.Approximations`)
## Summary
Using the equivalence of the convergents computations
(`GenContFract.convs` and `GenContFract.convs'`) for
continued fractions (see `Algebra.ContinuedFractions.ConvergentsEquiv`), it follows that the
convergents computations for `GenContFract.of` are equivalent.
Moreover, we show the convergence of the continued fractions computations, that is
`(GenContFract.of v).convs` indeed computes `v` in the limit.
## Main Definitions
- `ContFract.of` returns the (regular) continued fraction of a value.
## Main Theorems
- `GenContFract.of_convs_eq_convs'` shows that the convergents computations for
`GenContFract.of` are equivalent.
- `GenContFract.of_convergence` shows that `(GenContFract.of v).convs` converges to `v`.
## Tags
convergence, fractions
-/
variable {K : Type*} (v : K) [LinearOrderedField K] [FloorRing K]
open GenContFract (of)
open GenContFract
open scoped Topology
namespace GenContFract
theorem of_convs_eq_convs' : (of v).convs = (of v).convs' :=
@ContFract.convs_eq_convs' _ _ (ContFract.of v)
/-- The recurrence relation for the convergents of the continued fraction expansion
of an element `v` of `K` in terms of the convergents of the inverse of its fractional part.
-/
theorem convs_succ (n : ℕ) :
(of v).convs (n + 1) = ⌊v⌋ + 1 / (of (Int.fract v)⁻¹).convs n := by
rw [of_convs_eq_convs', convs'_succ, of_convs_eq_convs']
section Convergence
/-!
### Convergence
We next show that `(GenContFract.of v).convs v` converges to `v`.
-/
variable [Archimedean K]
open Nat
theorem of_convergence_epsilon :
∀ ε > (0 : K), ∃ N : ℕ, ∀ n ≥ N, |v - (of v).convs n| < ε := by
intro ε ε_pos
-- use the archimedean property to obtain a suitable N
rcases (exists_nat_gt (1 / ε) : ∃ N' : ℕ, 1 / ε < N') with ⟨N', one_div_ε_lt_N'⟩
let N := max N' 5
-- set minimum to 5 to have N ≤ fib N work
exists N
intro n n_ge_N
let g := of v
cases' Decidable.em (g.TerminatedAt n) with terminatedAt_n not_terminatedAt_n
· have : v = g.convs n := of_correctness_of_terminatedAt terminatedAt_n
have : v - g.convs n = 0 := sub_eq_zero.mpr this
rw [this]
exact mod_cast ε_pos
· let B := g.dens n
let nB := g.dens (n + 1)
have abs_v_sub_conv_le : |v - g.convs n| ≤ 1 / (B * nB) :=
abs_sub_convs_le not_terminatedAt_n
suffices 1 / (B * nB) < ε from lt_of_le_of_lt abs_v_sub_conv_le this
-- show that `0 < (B * nB)` and then multiply by `B * nB` to get rid of the division
have nB_ineq : (fib (n + 2) : K) ≤ nB :=
haveI : ¬g.TerminatedAt (n + 1 - 1) := not_terminatedAt_n
succ_nth_fib_le_of_nth_den (Or.inr this)
have B_ineq : (fib (n + 1) : K) ≤ B :=
haveI : ¬g.TerminatedAt (n - 1) := mt (terminated_stable n.pred_le) not_terminatedAt_n
succ_nth_fib_le_of_nth_den (Or.inr this)
have zero_lt_B : 0 < B := B_ineq.trans_lt' <| mod_cast fib_pos.2 n.succ_pos
have nB_pos : 0 < nB := nB_ineq.trans_lt' <| mod_cast fib_pos.2 <| succ_pos _
have zero_lt_mul_conts : 0 < B * nB := by positivity
suffices 1 < ε * (B * nB) from (div_lt_iff zero_lt_mul_conts).mpr this
-- use that `N' ≥ n` was obtained from the archimedean property to show the following
calc 1 < ε * (N' : K) := (div_lt_iff' ε_pos).mp one_div_ε_lt_N'
_ ≤ ε * (B * nB) := ?_
-- cancel `ε`
gcongr
calc
(N' : K) ≤ (N : K) := by exact_mod_cast le_max_left _ _
_ ≤ n := by exact_mod_cast n_ge_N
_ ≤ fib n := by exact_mod_cast le_fib_self <| le_trans (le_max_right N' 5) n_ge_N
_ ≤ fib (n + 1) := by exact_mod_cast fib_le_fib_succ
_ ≤ fib (n + 1) * fib (n + 1) := by exact_mod_cast (fib (n + 1)).le_mul_self
_ ≤ fib (n + 1) * fib (n + 2) := by gcongr; exact_mod_cast fib_le_fib_succ
_ ≤ B * nB := by gcongr
theorem of_convergence [TopologicalSpace K] [OrderTopology K] :
Filter.Tendsto (of v).convs Filter.atTop <| 𝓝 v := by
simpa [LinearOrderedAddCommGroup.tendsto_nhds, abs_sub_comm] using of_convergence_epsilon v
end Convergence
end GenContFract
|
Algebra\ContinuedFractions\Computation\Approximations.lean
|
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Determinant
import Mathlib.Algebra.ContinuedFractions.Computation.CorrectnessTerminating
import Mathlib.Algebra.Order.Group.Basic
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.Data.Nat.Fib.Basic
import Mathlib.Tactic.Monotonicity
/-!
# Approximations for Continued Fraction Computations (`GenContFract.of`)
## Summary
This file contains useful approximations for the values involved in the continued fractions
computation `GenContFract.of`. In particular, we show that the generalized continued fraction given
by `GenContFract.of` in fact is a (regular) continued fraction.
Moreover, we derive some upper bounds for the error term when computing a continued fraction up a
given position, i.e. bounds for the term
`|v - (GenContFract.of v).convs n|`. The derived bounds will show us that the error term indeed gets
smaller. As a corollary, we will be able to show that `(GenContFract.of v).convs` converges to `v`
in `Algebra.ContinuedFractions.Computation.ApproximationCorollaries`.
## Main Theorems
- `GenContFract.of_partNum_eq_one`: shows that all partial numerators `aᵢ` are
equal to one.
- `GenContFract.exists_int_eq_of_partDen`: shows that all partial denominators
`bᵢ` correspond to an integer.
- `GenContFract.of_one_le_get?_partDen`: shows that `1 ≤ bᵢ`.
- `ContFract.of` returns the regular continued fraction of a value.
- `GenContFract.succ_nth_fib_le_of_nthDen`: shows that the `n`th denominator
`Bₙ` is greater than or equal to the `n + 1`th fibonacci number `Nat.fib (n + 1)`.
- `GenContFract.le_of_succ_get?_den`: shows that `bₙ * Bₙ ≤ Bₙ₊₁`, where `bₙ` is
the `n`th partial denominator of the continued fraction.
- `GenContFract.abs_sub_convs_le`: shows that
`|v - Aₙ / Bₙ| ≤ 1 / (Bₙ * Bₙ₊₁)`, where `Aₙ` is the `n`th partial numerator.
## References
- [*Hardy, GH and Wright, EM and Heath-Brown, Roger and Silverman, Joseph*][hardy2008introduction]
-/
open GenContFract
open GenContFract (of)
open Int
variable {K : Type*} {v : K} {n : ℕ} [LinearOrderedField K] [FloorRing K]
namespace GenContFract
namespace IntFractPair
/-!
We begin with some lemmas about the stream of `IntFractPair`s, which presumably are not
of great interest for the end user.
-/
/-- Shows that the fractional parts of the stream are in `[0,1)`. -/
theorem nth_stream_fr_nonneg_lt_one {ifp_n : IntFractPair K}
(nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1 := by
cases n with
| zero =>
have : IntFractPair.of v = ifp_n := by injection nth_stream_eq
rw [← this, IntFractPair.of]
exact ⟨fract_nonneg _, fract_lt_one _⟩
| succ =>
rcases succ_nth_stream_eq_some_iff.1 nth_stream_eq with ⟨_, _, _, ifp_of_eq_ifp_n⟩
rw [← ifp_of_eq_ifp_n, IntFractPair.of]
exact ⟨fract_nonneg _, fract_lt_one _⟩
/-- Shows that the fractional parts of the stream are nonnegative. -/
theorem nth_stream_fr_nonneg {ifp_n : IntFractPair K}
(nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 ≤ ifp_n.fr :=
(nth_stream_fr_nonneg_lt_one nth_stream_eq).left
/-- Shows that the fractional parts of the stream are smaller than one. -/
theorem nth_stream_fr_lt_one {ifp_n : IntFractPair K}
(nth_stream_eq : IntFractPair.stream v n = some ifp_n) : ifp_n.fr < 1 :=
(nth_stream_fr_nonneg_lt_one nth_stream_eq).right
/-- Shows that the integer parts of the stream are at least one. -/
theorem one_le_succ_nth_stream_b {ifp_succ_n : IntFractPair K}
(succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) : 1 ≤ ifp_succ_n.b := by
obtain ⟨ifp_n, nth_stream_eq, stream_nth_fr_ne_zero, ⟨-⟩⟩ :
∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0
∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n :=
succ_nth_stream_eq_some_iff.1 succ_nth_stream_eq
suffices 1 ≤ ifp_n.fr⁻¹ by rwa [IntFractPair.of, le_floor, cast_one]
suffices ifp_n.fr ≤ 1 by
have h : 0 < ifp_n.fr :=
lt_of_le_of_ne (nth_stream_fr_nonneg nth_stream_eq) stream_nth_fr_ne_zero.symm
apply one_le_inv h this
simp only [le_of_lt (nth_stream_fr_lt_one nth_stream_eq)]
/--
Shows that the `n + 1`th integer part `bₙ₊₁` of the stream is smaller or equal than the inverse of
the `n`th fractional part `frₙ` of the stream.
This result is straight-forward as `bₙ₊₁` is defined as the floor of `1 / frₙ`.
-/
theorem succ_nth_stream_b_le_nth_stream_fr_inv {ifp_n ifp_succ_n : IntFractPair K}
(nth_stream_eq : IntFractPair.stream v n = some ifp_n)
(succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) :
(ifp_succ_n.b : K) ≤ ifp_n.fr⁻¹ := by
suffices (⌊ifp_n.fr⁻¹⌋ : K) ≤ ifp_n.fr⁻¹ by
cases' ifp_n with _ ifp_n_fr
have : ifp_n_fr ≠ 0 := by
intro h
simp [h, IntFractPair.stream, nth_stream_eq] at succ_nth_stream_eq
have : IntFractPair.of ifp_n_fr⁻¹ = ifp_succ_n := by
simpa [this, IntFractPair.stream, nth_stream_eq, Option.coe_def] using succ_nth_stream_eq
rwa [← this]
exact floor_le ifp_n.fr⁻¹
end IntFractPair
/-!
Next we translate above results about the stream of `IntFractPair`s to the computed continued
fraction `GenContFract.of`.
-/
/-- Shows that the integer parts of the continued fraction are at least one. -/
theorem of_one_le_get?_partDen {b : K}
(nth_partDen_eq : (of v).partDens.get? n = some b) : 1 ≤ b := by
obtain ⟨gp_n, nth_s_eq, ⟨-⟩⟩ : ∃ gp_n, (of v).s.get? n = some gp_n ∧ gp_n.b = b :=
exists_s_b_of_partDen nth_partDen_eq
obtain ⟨ifp_n, succ_nth_stream_eq, ifp_n_b_eq_gp_n_b⟩ :
∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ (ifp.b : K) = gp_n.b :=
IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some nth_s_eq
rw [← ifp_n_b_eq_gp_n_b]
exact mod_cast IntFractPair.one_le_succ_nth_stream_b succ_nth_stream_eq
/--
Shows that the partial numerators `aᵢ` of the continued fraction are equal to one and the partial
denominators `bᵢ` correspond to integers.
-/
theorem of_partNum_eq_one_and_exists_int_partDen_eq {gp : GenContFract.Pair K}
(nth_s_eq : (of v).s.get? n = some gp) : gp.a = 1 ∧ ∃ z : ℤ, gp.b = (z : K) := by
obtain ⟨ifp, stream_succ_nth_eq, -⟩ : ∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ _ :=
IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some nth_s_eq
have : gp = ⟨1, ifp.b⟩ := by
have : (of v).s.get? n = some ⟨1, ifp.b⟩ :=
get?_of_eq_some_of_succ_get?_intFractPair_stream stream_succ_nth_eq
have : some gp = some ⟨1, ifp.b⟩ := by rwa [nth_s_eq] at this
injection this
simp [this]
/-- Shows that the partial numerators `aᵢ` are equal to one. -/
theorem of_partNum_eq_one {a : K} (nth_partNum_eq : (of v).partNums.get? n = some a) :
a = 1 := by
obtain ⟨gp, nth_s_eq, gp_a_eq_a_n⟩ : ∃ gp, (of v).s.get? n = some gp ∧ gp.a = a :=
exists_s_a_of_partNum nth_partNum_eq
have : gp.a = 1 := (of_partNum_eq_one_and_exists_int_partDen_eq nth_s_eq).left
rwa [gp_a_eq_a_n] at this
/-- Shows that the partial denominators `bᵢ` correspond to an integer. -/
theorem exists_int_eq_of_partDen {b : K}
(nth_partDen_eq : (of v).partDens.get? n = some b) : ∃ z : ℤ, b = (z : K) := by
obtain ⟨gp, nth_s_eq, gp_b_eq_b_n⟩ : ∃ gp, (of v).s.get? n = some gp ∧ gp.b = b :=
exists_s_b_of_partDen nth_partDen_eq
have : ∃ z : ℤ, gp.b = (z : K) := (of_partNum_eq_one_and_exists_int_partDen_eq nth_s_eq).right
rwa [gp_b_eq_b_n] at this
end GenContFract
variable (v)
theorem GenContFract.of_isSimpContFract :
(of v).IsSimpContFract := fun _ _ nth_partNum_eq =>
of_partNum_eq_one nth_partNum_eq
/-- Creates the simple continued fraction of a value. -/
nonrec def SimpContFract.of : SimpContFract K :=
⟨of v, GenContFract.of_isSimpContFract v⟩
theorem SimpContFract.of_isContFract :
(SimpContFract.of v).IsContFract := fun _ _ nth_partDen_eq =>
lt_of_lt_of_le zero_lt_one (of_one_le_get?_partDen nth_partDen_eq)
/-- Creates the continued fraction of a value. -/
def ContFract.of : ContFract K :=
⟨SimpContFract.of v, SimpContFract.of_isContFract v⟩
variable {v}
namespace GenContFract
/-!
One of our next goals is to show that `bₙ * Bₙ ≤ Bₙ₊₁`. For this, we first show that the partial
denominators `Bₙ` are bounded from below by the fibonacci sequence `Nat.fib`. This then implies that
`0 ≤ Bₙ` and hence `Bₙ₊₂ = bₙ₊₁ * Bₙ₊₁ + Bₙ ≥ bₙ₊₁ * Bₙ₊₁ + 0 = bₙ₊₁ * Bₙ₊₁`.
-/
-- open `Nat` as we will make use of fibonacci numbers.
open Nat
theorem fib_le_of_contsAux_b :
n ≤ 1 ∨ ¬(of v).TerminatedAt (n - 2) → (fib n : K) ≤ ((of v).contsAux n).b :=
Nat.strong_induction_on n
(by
intro n IH hyp
rcases n with (_ | _ | n)
· simp [fib_add_two, contsAux] -- case n = 0
· simp [fib_add_two, contsAux] -- case n = 1
· let g := of v -- case 2 ≤ n
have : ¬n + 2 ≤ 1 := by omega
have not_terminatedAt_n : ¬g.TerminatedAt n := Or.resolve_left hyp this
obtain ⟨gp, s_ppred_nth_eq⟩ : ∃ gp, g.s.get? n = some gp :=
Option.ne_none_iff_exists'.mp not_terminatedAt_n
set pconts := g.contsAux (n + 1) with pconts_eq
set ppconts := g.contsAux n with ppconts_eq
-- use the recurrence of `contsAux`
simp only [Nat.succ_eq_add_one, Nat.add_assoc, Nat.reduceAdd]
suffices (fib n : K) + fib (n + 1) ≤ gp.a * ppconts.b + gp.b * pconts.b by
simpa [fib_add_two, add_comm, contsAux_recurrence s_ppred_nth_eq ppconts_eq pconts_eq]
-- make use of the fact that `gp.a = 1`
suffices (fib n : K) + fib (n + 1) ≤ ppconts.b + gp.b * pconts.b by
simpa [of_partNum_eq_one <| partNum_eq_s_a s_ppred_nth_eq]
have not_terminatedAt_pred_n : ¬g.TerminatedAt (n - 1) :=
mt (terminated_stable <| Nat.sub_le n 1) not_terminatedAt_n
have not_terminatedAt_ppred_n : ¬TerminatedAt g (n - 2) :=
mt (terminated_stable (n - 1).pred_le) not_terminatedAt_pred_n
-- use the IH to get the inequalities for `pconts` and `ppconts`
have ppred_nth_fib_le_ppconts_B : (fib n : K) ≤ ppconts.b :=
IH n (lt_trans (Nat.lt.base n) <| Nat.lt.base <| n + 1) (Or.inr not_terminatedAt_ppred_n)
suffices (fib (n + 1) : K) ≤ gp.b * pconts.b by
solve_by_elim [_root_.add_le_add ppred_nth_fib_le_ppconts_B]
-- finally use the fact that `1 ≤ gp.b` to solve the goal
suffices 1 * (fib (n + 1) : K) ≤ gp.b * pconts.b by rwa [one_mul] at this
have one_le_gp_b : (1 : K) ≤ gp.b :=
of_one_le_get?_partDen (partDen_eq_s_b s_ppred_nth_eq)
have : (0 : K) ≤ fib (n + 1) := mod_cast (fib (n + 1)).zero_le
have : (0 : K) ≤ gp.b := le_trans zero_le_one one_le_gp_b
mono
· norm_num
· tauto)
/-- Shows that the `n`th denominator is greater than or equal to the `n + 1`th fibonacci number,
that is `Nat.fib (n + 1) ≤ Bₙ`. -/
theorem succ_nth_fib_le_of_nth_den (hyp : n = 0 ∨ ¬(of v).TerminatedAt (n - 1)) :
(fib (n + 1) : K) ≤ (of v).dens n := by
rw [den_eq_conts_b, nth_cont_eq_succ_nth_contAux]
have : n + 1 ≤ 1 ∨ ¬(of v).TerminatedAt (n - 1) := by
cases n with
| zero => exact Or.inl <| le_refl 1
| succ n => exact Or.inr (Or.resolve_left hyp n.succ_ne_zero)
exact fib_le_of_contsAux_b this
/-! As a simple consequence, we can now derive that all denominators are nonnegative. -/
theorem zero_le_of_contsAux_b : 0 ≤ ((of v).contsAux n).b := by
let g := of v
induction n with
| zero => rfl
| succ n IH =>
cases' Decidable.em <| g.TerminatedAt (n - 1) with terminated not_terminated
· -- terminating case
cases' n with n
· simp [zero_le_one]
· have : g.contsAux (n + 2) = g.contsAux (n + 1) :=
contsAux_stable_step_of_terminated terminated
simp only [this, IH]
· -- non-terminating case
calc
(0 : K) ≤ fib (n + 1) := mod_cast (n + 1).fib.zero_le
_ ≤ ((of v).contsAux (n + 1)).b := fib_le_of_contsAux_b (Or.inr not_terminated)
/-- Shows that all denominators are nonnegative. -/
theorem zero_le_of_den : 0 ≤ (of v).dens n := by
rw [den_eq_conts_b, nth_cont_eq_succ_nth_contAux]; exact zero_le_of_contsAux_b
theorem le_of_succ_succ_get?_contsAux_b {b : K}
(nth_partDen_eq : (of v).partDens.get? n = some b) :
b * ((of v).contsAux <| n + 1).b ≤ ((of v).contsAux <| n + 2).b := by
obtain ⟨gp_n, nth_s_eq, rfl⟩ : ∃ gp_n, (of v).s.get? n = some gp_n ∧ gp_n.b = b :=
exists_s_b_of_partDen nth_partDen_eq
simp [of_partNum_eq_one (partNum_eq_s_a nth_s_eq), zero_le_of_contsAux_b,
GenContFract.contsAux_recurrence nth_s_eq rfl rfl]
/-- Shows that `bₙ * Bₙ ≤ Bₙ₊₁`, where `bₙ` is the `n`th partial denominator and `Bₙ₊₁` and `Bₙ` are
the `n + 1`th and `n`th denominator of the continued fraction. -/
theorem le_of_succ_get?_den {b : K}
(nth_partDenom_eq : (of v).partDens.get? n = some b) :
b * (of v).dens n ≤ (of v).dens (n + 1) := by
rw [den_eq_conts_b, nth_cont_eq_succ_nth_contAux]
exact le_of_succ_succ_get?_contsAux_b nth_partDenom_eq
/-- Shows that the sequence of denominators is monotone, that is `Bₙ ≤ Bₙ₊₁`. -/
theorem of_den_mono : (of v).dens n ≤ (of v).dens (n + 1) := by
let g := of v
cases' Decidable.em <| g.partDens.TerminatedAt n with terminated not_terminated
· have : g.partDens.get? n = none := by rwa [Stream'.Seq.TerminatedAt] at terminated
have : g.TerminatedAt n :=
terminatedAt_iff_partDen_none.2 (by rwa [Stream'.Seq.TerminatedAt] at terminated)
have : g.dens (n + 1) = g.dens n :=
dens_stable_of_terminated n.le_succ this
rw [this]
· obtain ⟨b, nth_partDen_eq⟩ : ∃ b, g.partDens.get? n = some b :=
Option.ne_none_iff_exists'.mp not_terminated
have : 1 ≤ b := of_one_le_get?_partDen nth_partDen_eq
calc
g.dens n ≤ b * g.dens n := by
simpa using mul_le_mul_of_nonneg_right this zero_le_of_den
_ ≤ g.dens (n + 1) := le_of_succ_get?_den nth_partDen_eq
section ErrorTerm
/-!
### Approximation of Error Term
Next we derive some approximations for the error term when computing a continued fraction up a given
position, i.e. bounds for the term `|v - (GenContFract.of v).convs n|`.
-/
/-- This lemma follows from the finite correctness proof, the determinant equality, and
by simplifying the difference. -/
theorem sub_convs_eq {ifp : IntFractPair K}
(stream_nth_eq : IntFractPair.stream v n = some ifp) :
let g := of v
let B := (g.contsAux (n + 1)).b
let pB := (g.contsAux n).b
v - g.convs n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) := by
-- set up some shorthand notation
let g := of v
let conts := g.contsAux (n + 1)
let pred_conts := g.contsAux n
have g_finite_correctness :
v = GenContFract.compExactValue pred_conts conts ifp.fr :=
compExactValue_correctness_of_stream_eq_some stream_nth_eq
obtain (ifp_fr_eq_zero | ifp_fr_ne_zero) := eq_or_ne ifp.fr 0
· suffices v - g.convs n = 0 by simpa [ifp_fr_eq_zero]
replace g_finite_correctness : v = g.convs n := by
simpa [GenContFract.compExactValue, ifp_fr_eq_zero] using g_finite_correctness
exact sub_eq_zero.2 g_finite_correctness
· -- more shorthand notation
let A := conts.a
let B := conts.b
let pA := pred_conts.a
let pB := pred_conts.b
-- first, let's simplify the goal as `ifp.fr ≠ 0`
suffices v - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) by simpa [ifp_fr_ne_zero]
-- now we can unfold `g.compExactValue` to derive the following equality for `v`
replace g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) := by
simpa [GenContFract.compExactValue, ifp_fr_ne_zero, nextConts, nextNum, nextDen, add_comm]
using g_finite_correctness
-- let's rewrite this equality for `v` in our goal
suffices
(pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) by
rwa [g_finite_correctness]
-- To continue, we need use the determinant equality. So let's derive the needed hypothesis.
have n_eq_zero_or_not_terminatedAt_pred_n : n = 0 ∨ ¬g.TerminatedAt (n - 1) := by
cases' n with n'
· simp
· have : IntFractPair.stream v (n' + 1) ≠ none := by simp [stream_nth_eq]
have : ¬g.TerminatedAt n' :=
(not_congr of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none).2 this
exact Or.inr this
have determinant_eq : pA * B - pB * A = (-1) ^ n :=
(SimpContFract.of v).determinant_aux n_eq_zero_or_not_terminatedAt_pred_n
-- now all we got to do is to rewrite this equality in our goal and re-arrange terms;
-- however, for this, we first have to derive quite a few tedious inequalities.
have pB_ineq : (fib n : K) ≤ pB :=
haveI : n ≤ 1 ∨ ¬g.TerminatedAt (n - 2) := by
cases' n_eq_zero_or_not_terminatedAt_pred_n with n_eq_zero not_terminatedAt_pred_n
· simp [n_eq_zero]
· exact Or.inr <| mt (terminated_stable (n - 1).pred_le) not_terminatedAt_pred_n
fib_le_of_contsAux_b this
have B_ineq : (fib (n + 1) : K) ≤ B :=
haveI : n + 1 ≤ 1 ∨ ¬g.TerminatedAt (n + 1 - 2) := by
cases' n_eq_zero_or_not_terminatedAt_pred_n with n_eq_zero not_terminatedAt_pred_n
· simp [n_eq_zero, le_refl]
· exact Or.inr not_terminatedAt_pred_n
fib_le_of_contsAux_b this
have zero_lt_B : 0 < B := B_ineq.trans_lt' <| cast_pos.2 <| fib_pos.2 n.succ_pos
have : 0 ≤ pB := (cast_nonneg _).trans pB_ineq
have : 0 < ifp.fr :=
ifp_fr_ne_zero.lt_of_le' <| IntFractPair.nth_stream_fr_nonneg stream_nth_eq
have : pB + ifp.fr⁻¹ * B ≠ 0 := by positivity
-- finally, let's do the rewriting
calc
(pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B =
((pA + ifp.fr⁻¹ * A) * B - (pB + ifp.fr⁻¹ * B) * A) / ((pB + ifp.fr⁻¹ * B) * B) := by
rw [div_sub_div _ _ this zero_lt_B.ne']
_ = (pA * B + ifp.fr⁻¹ * A * B - (pB * A + ifp.fr⁻¹ * B * A)) / _ := by repeat' rw [add_mul]
_ = (pA * B - pB * A) / ((pB + ifp.fr⁻¹ * B) * B) := by ring
_ = (-1) ^ n / ((pB + ifp.fr⁻¹ * B) * B) := by rw [determinant_eq]
_ = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) := by ac_rfl
/-- Shows that `|v - Aₙ / Bₙ| ≤ 1 / (Bₙ * Bₙ₊₁)`. -/
theorem abs_sub_convs_le (not_terminatedAt_n : ¬(of v).TerminatedAt n) :
|v - (of v).convs n| ≤ 1 / ((of v).dens n * ((of v).dens <| n + 1)) := by
-- shorthand notation
let g := of v
let nextConts := g.contsAux (n + 2)
set conts := contsAux g (n + 1) with conts_eq
set pred_conts := contsAux g n with pred_conts_eq
-- change the goal to something more readable
change |v - convs g n| ≤ 1 / (conts.b * nextConts.b)
obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp :=
Option.ne_none_iff_exists'.1 not_terminatedAt_n
have gp_a_eq_one : gp.a = 1 := of_partNum_eq_one (partNum_eq_s_a s_nth_eq)
-- unfold the recurrence relation for `nextConts.b`
have nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b := by
simp [nextConts, contsAux_recurrence s_nth_eq pred_conts_eq conts_eq, gp_a_eq_one,
pred_conts_eq.symm, conts_eq.symm, add_comm]
let den := conts.b * (pred_conts.b + gp.b * conts.b)
suffices |v - g.convs n| ≤ 1 / den by rw [nextConts_b_eq]; congr 1
obtain ⟨ifp_succ_n, succ_nth_stream_eq, ifp_succ_n_b_eq_gp_b⟩ :
∃ ifp_succ_n, IntFractPair.stream v (n + 1) = some ifp_succ_n ∧ (ifp_succ_n.b : K) = gp.b :=
IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some s_nth_eq
obtain ⟨ifp_n, stream_nth_eq, stream_nth_fr_ne_zero, if_of_eq_ifp_succ_n⟩ :
∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0
∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n :=
IntFractPair.succ_nth_stream_eq_some_iff.1 succ_nth_stream_eq
let den' := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b)
-- now we can use `sub_convs_eq` to simplify our goal
suffices |(-1) ^ n / den'| ≤ 1 / den by
have : v - g.convs n = (-1) ^ n / den' := by
-- apply `sub_convs_eq` and simplify the result
have tmp := sub_convs_eq stream_nth_eq
simp only [stream_nth_fr_ne_zero, conts_eq.symm, pred_conts_eq.symm, if_false] at tmp
rw [tmp]
ring
rwa [this]
-- derive some tedious inequalities that we need to rewrite our goal
have nextConts_b_ineq : (fib (n + 2) : K) ≤ pred_conts.b + gp.b * conts.b := by
have : (fib (n + 2) : K) ≤ nextConts.b :=
fib_le_of_contsAux_b (Or.inr not_terminatedAt_n)
rwa [nextConts_b_eq] at this
have conts_b_ineq : (fib (n + 1) : K) ≤ conts.b :=
haveI : ¬g.TerminatedAt (n - 1) := mt (terminated_stable n.pred_le) not_terminatedAt_n
fib_le_of_contsAux_b <| Or.inr this
have zero_lt_conts_b : 0 < conts.b :=
conts_b_ineq.trans_lt' <| mod_cast fib_pos.2 n.succ_pos
-- `den'` is positive, so we can remove `|⬝|` from our goal
suffices 1 / den' ≤ 1 / den by
have : |(-1) ^ n / den'| = 1 / den' := by
suffices 1 / |den'| = 1 / den' by rwa [abs_div, abs_neg_one_pow n]
have : 0 < den' := by
have : 0 ≤ pred_conts.b :=
haveI : (fib n : K) ≤ pred_conts.b :=
haveI : ¬g.TerminatedAt (n - 2) :=
mt (terminated_stable (n.sub_le 2)) not_terminatedAt_n
fib_le_of_contsAux_b <| Or.inr this
le_trans (mod_cast (fib n).zero_le) this
have : 0 < ifp_n.fr⁻¹ :=
haveI zero_le_ifp_n_fract : 0 ≤ ifp_n.fr :=
IntFractPair.nth_stream_fr_nonneg stream_nth_eq
inv_pos.2 (lt_of_le_of_ne zero_le_ifp_n_fract stream_nth_fr_ne_zero.symm)
-- Porting note: replaced complicated positivity proof with tactic.
positivity
rw [abs_of_pos this]
rwa [this]
suffices 0 < den ∧ den ≤ den' from div_le_div_of_nonneg_left zero_le_one this.1 this.2
constructor
· have : 0 < pred_conts.b + gp.b * conts.b :=
nextConts_b_ineq.trans_lt' <| mod_cast fib_pos.2 <| succ_pos _
solve_by_elim [mul_pos]
· -- we can cancel multiplication by `conts.b` and addition with `pred_conts.b`
suffices gp.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b from
(mul_le_mul_left zero_lt_conts_b).2 <| (add_le_add_iff_left pred_conts.b).2 this
suffices (ifp_succ_n.b : K) * conts.b ≤ ifp_n.fr⁻¹ * conts.b by rwa [← ifp_succ_n_b_eq_gp_b]
have : (ifp_succ_n.b : K) ≤ ifp_n.fr⁻¹ :=
IntFractPair.succ_nth_stream_b_le_nth_stream_fr_inv stream_nth_eq succ_nth_stream_eq
have : 0 ≤ conts.b := le_of_lt zero_lt_conts_b
gcongr; exact this
/-- Shows that `|v - Aₙ / Bₙ| ≤ 1 / (bₙ * Bₙ * Bₙ)`. This bound is worse than the one shown in
`GenContFract.abs_sub_convs_le`, but sometimes it is easier to apply and
sufficient for one's use case.
-/
theorem abs_sub_convergents_le' {b : K}
(nth_partDen_eq : (of v).partDens.get? n = some b) :
|v - (of v).convs n| ≤ 1 / (b * (of v).dens n * (of v).dens n) := by
have not_terminatedAt_n : ¬(of v).TerminatedAt n := by
simp [terminatedAt_iff_partDen_none, nth_partDen_eq]
refine (abs_sub_convs_le not_terminatedAt_n).trans ?_
-- One can show that `0 < (GenContFract.of v).dens n` but it's easier
-- to consider the case `(GenContFract.of v).dens n = 0`.
rcases (zero_le_of_den (K := K)).eq_or_gt with
((hB : (GenContFract.of v).dens n = 0) | hB)
· simp only [hB, mul_zero, zero_mul, div_zero, le_refl]
· apply one_div_le_one_div_of_le
· have : 0 < b := zero_lt_one.trans_le (of_one_le_get?_partDen nth_partDen_eq)
apply_rules [mul_pos]
· conv_rhs => rw [mul_comm]
exact mul_le_mul_of_nonneg_right (le_of_succ_get?_den nth_partDen_eq) hB.le
end ErrorTerm
end GenContFract
|
Algebra\ContinuedFractions\Computation\Basic.lean
|
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.Order.Floor
import Mathlib.Algebra.ContinuedFractions.Basic
/-!
# Computable Continued Fractions
## Summary
We formalise the standard computation of (regular) continued fractions for linear ordered floor
fields. The algorithm is rather simple. Here is an outline of the procedure adapted from Wikipedia:
Take a value `v`. We call `⌊v⌋` the *integer part* of `v` and `v - ⌊v⌋` the *fractional part* of
`v`. A continued fraction representation of `v` can then be given by `[⌊v⌋; b₀, b₁, b₂,...]`, where
`[b₀; b₁, b₂,...]` recursively is the continued fraction representation of `1 / (v - ⌊v⌋)`. This
process stops when the fractional part hits 0.
In other words: to calculate a continued fraction representation of a number `v`, write down the
integer part (i.e. the floor) of `v`. Subtract this integer part from `v`. If the difference is 0,
stop; otherwise find the reciprocal of the difference and repeat. The procedure will terminate if
and only if `v` is rational.
For an example, refer to `IntFractPair.stream`.
## Main definitions
- `GenContFract.IntFractPair.stream`: computes the stream of integer and fractional parts of a given
value as described in the summary.
- `GenContFract.of`: computes the generalised continued fraction of a value `v`.
In fact, it computes a regular continued fraction that terminates if and only if `v` is rational.
## Implementation Notes
There is an intermediate definition `GenContFract.IntFractPair.seq1` between
`GenContFract.IntFractPair.stream` and `GenContFract.of` to wire up things. Users should not
(need to) directly interact with it.
The computation of the integer and fractional pairs of a value can elegantly be
captured by a recursive computation of a stream of option pairs. This is done in
`IntFractPair.stream`. However, the type then does not guarantee the first pair to always be
`some` value, as expected by a continued fraction.
To separate concerns, we first compute a single head term that always exists in
`GenContFract.IntFractPair.seq1` followed by the remaining stream of option pairs. This sequence
with a head term (`seq1`) is then transformed to a generalized continued fraction in
`GenContFract.of` by extracting the wanted integer parts of the head term and the stream.
## References
- https://en.wikipedia.org/wiki/Continued_fraction
## Tags
numerics, number theory, approximations, fractions
-/
namespace GenContFract
-- Fix a carrier `K`.
variable (K : Type*)
/-- We collect an integer part `b = ⌊v⌋` and fractional part `fr = v - ⌊v⌋` of a value `v` in a pair
`⟨b, fr⟩`.
-/
structure IntFractPair where
b : ℤ
fr : K
variable {K}
/-! Interlude: define some expected coercions and instances. -/
namespace IntFractPair
/-- Make an `IntFractPair` printable. -/
instance [Repr K] : Repr (IntFractPair K) :=
⟨fun p _ => "(b : " ++ repr p.b ++ ", fract : " ++ repr p.fr ++ ")"⟩
instance inhabited [Inhabited K] : Inhabited (IntFractPair K) :=
⟨⟨0, default⟩⟩
/-- Maps a function `f` on the fractional components of a given pair.
-/
def mapFr {β : Type*} (f : K → β) (gp : IntFractPair K) : IntFractPair β :=
⟨gp.b, f gp.fr⟩
section coe
/-! Interlude: define some expected coercions. -/
-- Fix another type `β` which we will convert to.
variable {β : Type*} [Coe K β]
-- Porting note: added so we can add the `@[coe]` attribute
/-- The coercion between integer-fraction pairs happens componentwise. -/
@[coe]
def coeFn : IntFractPair K → IntFractPair β := mapFr (↑)
/-- Coerce a pair by coercing the fractional component. -/
instance coe : Coe (IntFractPair K) (IntFractPair β) where
coe := coeFn
@[simp, norm_cast]
theorem coe_to_intFractPair {b : ℤ} {fr : K} :
(↑(IntFractPair.mk b fr) : IntFractPair β) = IntFractPair.mk b (↑fr : β) :=
rfl
end coe
-- Note: this could be relaxed to something like `LinearOrderedDivisionRing` in the future.
-- Fix a discrete linear ordered field with `floor` function.
variable [LinearOrderedField K] [FloorRing K]
/-- Creates the integer and fractional part of a value `v`, i.e. `⟨⌊v⌋, v - ⌊v⌋⟩`. -/
protected def of (v : K) : IntFractPair K :=
⟨⌊v⌋, Int.fract v⟩
/-- Creates the stream of integer and fractional parts of a value `v` needed to obtain the continued
fraction representation of `v` in `GenContFract.of`. More precisely, given a value `v : K`, it
recursively computes a stream of option `ℤ × K` pairs as follows:
- `stream v 0 = some ⟨⌊v⌋, v - ⌊v⌋⟩`
- `stream v (n + 1) = some ⟨⌊frₙ⁻¹⌋, frₙ⁻¹ - ⌊frₙ⁻¹⌋⟩`,
if `stream v n = some ⟨_, frₙ⟩` and `frₙ ≠ 0`
- `stream v (n + 1) = none`, otherwise
For example, let `(v : ℚ) := 3.4`. The process goes as follows:
- `stream v 0 = some ⟨⌊v⌋, v - ⌊v⌋⟩ = some ⟨3, 0.4⟩`
- `stream v 1 = some ⟨⌊0.4⁻¹⌋, 0.4⁻¹ - ⌊0.4⁻¹⌋⟩ = some ⟨⌊2.5⌋, 2.5 - ⌊2.5⌋⟩ = some ⟨2, 0.5⟩`
- `stream v 2 = some ⟨⌊0.5⁻¹⌋, 0.5⁻¹ - ⌊0.5⁻¹⌋⟩ = some ⟨⌊2⌋, 2 - ⌊2⌋⟩ = some ⟨2, 0⟩`
- `stream v n = none`, for `n ≥ 3`
-/
protected def stream (v : K) : Stream' <| Option (IntFractPair K)
| 0 => some (IntFractPair.of v)
| n + 1 =>
(IntFractPair.stream v n).bind fun ap_n =>
if ap_n.fr = 0 then none else some (IntFractPair.of ap_n.fr⁻¹)
/-- Shows that `IntFractPair.stream` has the sequence property, that is once we return `none` at
position `n`, we also return `none` at `n + 1`.
-/
theorem stream_isSeq (v : K) : (IntFractPair.stream v).IsSeq := by
intro _ hyp
simp [IntFractPair.stream, hyp]
/--
Uses `IntFractPair.stream` to create a sequence with head (i.e. `seq1`) of integer and fractional
parts of a value `v`. The first value of `IntFractPair.stream` is never `none`, so we can safely
extract it and put the tail of the stream in the sequence part.
This is just an intermediate representation and users should not (need to) directly interact with
it. The setup of rewriting/simplification lemmas that make the definitions easy to use is done in
`Algebra.ContinuedFractions.Computation.Translations`.
-/
protected def seq1 (v : K) : Stream'.Seq1 <| IntFractPair K :=
⟨IntFractPair.of v, -- the head
-- take the tail of `IntFractPair.stream` since the first element is already in the head
Stream'.Seq.tail
-- create a sequence from `IntFractPair.stream`
⟨IntFractPair.stream v, -- the underlying stream
@stream_isSeq _ _ _ v⟩⟩ -- the proof that the stream is a sequence
end IntFractPair
/-- Returns the `GenContFract` of a value. In fact, the returned gcf is also a `ContFract` that
terminates if and only if `v` is rational
(see `Algebra.ContinuedFractions.Computation.TerminatesIffRat`).
The continued fraction representation of `v` is given by `[⌊v⌋; b₀, b₁, b₂,...]`, where
`[b₀; b₁, b₂,...]` recursively is the continued fraction representation of `1 / (v - ⌊v⌋)`. This
process stops when the fractional part `v - ⌊v⌋` hits 0 at some step.
The implementation uses `IntFractPair.stream` to obtain the partial denominators of the continued
fraction. Refer to said function for more details about the computation process.
-/
protected def of [LinearOrderedField K] [FloorRing K] (v : K) : GenContFract K :=
let ⟨h, s⟩ := IntFractPair.seq1 v -- get the sequence of integer and fractional parts.
⟨h.b, -- the head is just the first integer part
s.map fun p => ⟨1, p.b⟩⟩ -- the sequence consists of the remaining integer parts as the partial
-- denominators; all partial numerators are simply 1
end GenContFract
|
Algebra\ContinuedFractions\Computation\CorrectnessTerminating.lean
|
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Computation.Translations
import Mathlib.Algebra.ContinuedFractions.TerminatedStable
import Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence
import Mathlib.Order.Filter.AtTopBot
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Ring
/-!
# Correctness of Terminating Continued Fraction Computations (`GenContFract.of`)
## Summary
We show the correctness of the algorithm computing continued fractions (`GenContFract.of`)
in case of termination in the following sense:
At every step `n : ℕ`, we can obtain the value `v` by adding a specific residual term to the last
denominator of the fraction described by `(GenContFract.of v).convs' n`.
The residual term will be zero exactly when the continued fraction terminated; otherwise, the
residual term will be given by the fractional part stored in `GenContFract.IntFractPair.stream v n`.
For an example, refer to
`GenContFract.compExactValue_correctness_of_stream_eq_some` and for more
information about the computation process, refer to `Algebra.ContinuedFractions.Computation.Basic`.
## Main definitions
- `GenContFract.compExactValue` can be used to compute the exact value approximated by the
continued fraction `GenContFract.of v` by adding a residual term as described in the summary.
## Main Theorems
- `GenContFract.compExactValue_correctness_of_stream_eq_some` shows that
`GenContFract.compExactValue` indeed returns the value `v` when given the convergent and
fractional part as described in the summary.
- `GenContFract.of_correctness_of_terminatedAt` shows the equality
`v = (GenContFract.of v).convs n` if `GenContFract.of v` terminated at position `n`.
-/
namespace GenContFract
open GenContFract (of)
variable {K : Type*} [LinearOrderedField K] {v : K} {n : ℕ}
/-- Given two continuants `pconts` and `conts` and a value `fr`, this function returns
- `conts.a / conts.b` if `fr = 0`
- `exactConts.a / exactConts.b` where `exactConts = nextConts 1 fr⁻¹ pconts conts`
otherwise.
This function can be used to compute the exact value approximated by a continued fraction
`GenContFract.of v` as described in lemma `compExactValue_correctness_of_stream_eq_some`.
-/
protected def compExactValue (pconts conts : Pair K) (fr : K) : K :=
-- if the fractional part is zero, we exactly approximated the value by the last continuants
if fr = 0 then
conts.a / conts.b
else -- otherwise, we have to include the fractional part in a final continuants step.
let exactConts := nextConts 1 fr⁻¹ pconts conts
exactConts.a / exactConts.b
variable [FloorRing K]
/-- Just a computational lemma we need for the next main proof. -/
protected theorem compExactValue_correctness_of_stream_eq_some_aux_comp {a : K} (b c : K)
(fract_a_ne_zero : Int.fract a ≠ 0) :
((⌊a⌋ : K) * b + c) / Int.fract a + b = (b * a + c) / Int.fract a := by
field_simp [fract_a_ne_zero]
rw [Int.fract]
ring
open GenContFract
(compExactValue compExactValue_correctness_of_stream_eq_some_aux_comp)
/-- Shows the correctness of `compExactValue` in case the continued fraction
`GenContFract.of v` did not terminate at position `n`. That is, we obtain the
value `v` if we pass the two successive (auxiliary) continuants at positions `n` and `n + 1` as well
as the fractional part at `IntFractPair.stream n` to `compExactValue`.
The correctness might be seen more readily if one uses `convs'` to evaluate the continued
fraction. Here is an example to illustrate the idea:
Let `(v : ℚ) := 3.4`. We have
- `GenContFract.IntFractPair.stream v 0 = some ⟨3, 0.4⟩`, and
- `GenContFract.IntFractPair.stream v 1 = some ⟨2, 0.5⟩`.
Now `(GenContFract.of v).convs' 1 = 3 + 1/2`, and our fractional term at position `2` is `0.5`.
We hence have `v = 3 + 1/(2 + 0.5) = 3 + 1/2.5 = 3.4`.
This computation corresponds exactly to the one using the recurrence equation in `compExactValue`.
-/
theorem compExactValue_correctness_of_stream_eq_some :
∀ {ifp_n : IntFractPair K}, IntFractPair.stream v n = some ifp_n →
v = compExactValue ((of v).contsAux n) ((of v).contsAux <| n + 1) ifp_n.fr := by
let g := of v
induction' n with n IH
· intro ifp_zero stream_zero_eq
-- Nat.zero
have : IntFractPair.of v = ifp_zero := by
have : IntFractPair.stream v 0 = some (IntFractPair.of v) := rfl
simpa only [Nat.zero_eq, this, Option.some.injEq] using stream_zero_eq
cases this
cases' Decidable.em (Int.fract v = 0) with fract_eq_zero fract_ne_zero
-- Int.fract v = 0; we must then have `v = ⌊v⌋`
· suffices v = ⌊v⌋ by
-- Porting note: was `simpa [contsAux, fract_eq_zero, compExactValue]`
field_simp [nextConts, nextNum, nextDen, compExactValue]
have : (IntFractPair.of v).fr = Int.fract v := rfl
rwa [this, if_pos fract_eq_zero]
calc
v = Int.fract v + ⌊v⌋ := by rw [Int.fract_add_floor]
_ = ⌊v⌋ := by simp [fract_eq_zero]
-- Int.fract v ≠ 0; the claim then easily follows by unfolding a single computation step
· field_simp [contsAux, nextConts, nextNum, nextDen, of_h_eq_floor, compExactValue]
-- Porting note: this and the if_neg rewrite are needed
have : (IntFractPair.of v).fr = Int.fract v := rfl
rw [this, if_neg fract_ne_zero, Int.floor_add_fract]
· intro ifp_succ_n succ_nth_stream_eq
-- Nat.succ
obtain ⟨ifp_n, nth_stream_eq, nth_fract_ne_zero, -⟩ :
∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧
ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n :=
IntFractPair.succ_nth_stream_eq_some_iff.1 succ_nth_stream_eq
-- introduce some notation
let conts := g.contsAux (n + 2)
set pconts := g.contsAux (n + 1) with pconts_eq
set ppconts := g.contsAux n with ppconts_eq
cases' Decidable.em (ifp_succ_n.fr = 0) with ifp_succ_n_fr_eq_zero ifp_succ_n_fr_ne_zero
-- ifp_succ_n.fr = 0
· suffices v = conts.a / conts.b by simpa [compExactValue, ifp_succ_n_fr_eq_zero]
-- use the IH and the fact that ifp_n.fr⁻¹ = ⌊ifp_n.fr⁻¹⌋ to prove this case
obtain ⟨ifp_n', nth_stream_eq', ifp_n_fract_inv_eq_floor⟩ :
∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr⁻¹ = ⌊ifp_n.fr⁻¹⌋ :=
IntFractPair.exists_succ_nth_stream_of_fr_zero succ_nth_stream_eq ifp_succ_n_fr_eq_zero
have : ifp_n' = ifp_n := by injection Eq.trans nth_stream_eq'.symm nth_stream_eq
cases this
have s_nth_eq : g.s.get? n = some ⟨1, ⌊ifp_n.fr⁻¹⌋⟩ :=
get?_of_eq_some_of_get?_intFractPair_stream_fr_ne_zero nth_stream_eq nth_fract_ne_zero
rw [← ifp_n_fract_inv_eq_floor] at s_nth_eq
suffices v = compExactValue ppconts pconts ifp_n.fr by
simpa [conts, contsAux, s_nth_eq, compExactValue, nth_fract_ne_zero] using this
exact IH nth_stream_eq
-- ifp_succ_n.fr ≠ 0
· -- use the IH to show that the following equality suffices
suffices
compExactValue ppconts pconts ifp_n.fr = compExactValue pconts conts ifp_succ_n.fr by
have : v = compExactValue ppconts pconts ifp_n.fr := IH nth_stream_eq
conv_lhs => rw [this]
assumption
-- get the correspondence between ifp_n and ifp_succ_n
obtain ⟨ifp_n', nth_stream_eq', ifp_n_fract_ne_zero, ⟨refl⟩⟩ :
∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧
ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n :=
IntFractPair.succ_nth_stream_eq_some_iff.1 succ_nth_stream_eq
have : ifp_n' = ifp_n := by injection Eq.trans nth_stream_eq'.symm nth_stream_eq
cases this
-- get the correspondence between ifp_n and g.s.nth n
have s_nth_eq : g.s.get? n = some ⟨1, (⌊ifp_n.fr⁻¹⌋ : K)⟩ :=
get?_of_eq_some_of_get?_intFractPair_stream_fr_ne_zero nth_stream_eq ifp_n_fract_ne_zero
-- the claim now follows by unfolding the definitions and tedious calculations
-- some shorthand notation
let ppA := ppconts.a
let ppB := ppconts.b
let pA := pconts.a
let pB := pconts.b
have : compExactValue ppconts pconts ifp_n.fr =
(ppA + ifp_n.fr⁻¹ * pA) / (ppB + ifp_n.fr⁻¹ * pB) := by
-- unfold compExactValue and the convergent computation once
field_simp [ifp_n_fract_ne_zero, compExactValue, nextConts, nextNum, nextDen, ppA, ppB]
ac_rfl
rw [this]
-- two calculations needed to show the claim
have tmp_calc :=
compExactValue_correctness_of_stream_eq_some_aux_comp pA ppA ifp_succ_n_fr_ne_zero
have tmp_calc' :=
compExactValue_correctness_of_stream_eq_some_aux_comp pB ppB ifp_succ_n_fr_ne_zero
let f := Int.fract (1 / ifp_n.fr)
have f_ne_zero : f ≠ 0 := by simpa [f] using ifp_succ_n_fr_ne_zero
rw [inv_eq_one_div] at tmp_calc tmp_calc'
-- Porting note: the `tmp_calc`s need to be massaged, and some processing after `ac_rfl` done,
-- because `field_simp` is not as powerful
have hA : (↑⌊1 / ifp_n.fr⌋ * pA + ppA) + pA * f = pA * (1 / ifp_n.fr) + ppA := by
have := congrFun (congrArg HMul.hMul tmp_calc) f
rwa [right_distrib, div_mul_cancel₀ (h := f_ne_zero),
div_mul_cancel₀ (h := f_ne_zero)] at this
have hB : (↑⌊1 / ifp_n.fr⌋ * pB + ppB) + pB * f = pB * (1 / ifp_n.fr) + ppB := by
have := congrFun (congrArg HMul.hMul tmp_calc') f
rwa [right_distrib, div_mul_cancel₀ (h := f_ne_zero),
div_mul_cancel₀ (h := f_ne_zero)] at this
-- now unfold the recurrence one step and simplify both sides to arrive at the conclusion
dsimp only [conts, pconts, ppconts]
field_simp [compExactValue, contsAux_recurrence s_nth_eq ppconts_eq pconts_eq,
nextConts, nextNum, nextDen]
have hfr : (IntFractPair.of (1 / ifp_n.fr)).fr = f := rfl
rw [one_div, if_neg _, ← one_div, hfr]
· field_simp [hA, hB]
ac_rfl
· rwa [inv_eq_one_div, hfr]
open GenContFract (of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none)
/-- The convergent of `GenContFract.of v` at step `n - 1` is exactly `v` if the
`IntFractPair.stream` of the corresponding continued fraction terminated at step `n`. -/
theorem of_correctness_of_nth_stream_eq_none (nth_stream_eq_none : IntFractPair.stream v n = none) :
v = (of v).convs (n - 1) := by
induction n with
| zero => contradiction
-- IntFractPair.stream v 0 ≠ none
| succ n IH =>
let g := of v
change v = g.convs n
have :
IntFractPair.stream v n = none ∨ ∃ ifp, IntFractPair.stream v n = some ifp ∧ ifp.fr = 0 :=
IntFractPair.succ_nth_stream_eq_none_iff.1 nth_stream_eq_none
rcases this with (⟨nth_stream_eq_none⟩ | ⟨ifp_n, nth_stream_eq, nth_stream_fr_eq_zero⟩)
· cases' n with n'
· contradiction
-- IntFractPair.stream v 0 ≠ none
· have : g.TerminatedAt n' :=
of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none.2
nth_stream_eq_none
have : g.convs (n' + 1) = g.convs n' :=
convs_stable_of_terminated n'.le_succ this
rw [this]
exact IH nth_stream_eq_none
· simpa [nth_stream_fr_eq_zero, compExactValue] using
compExactValue_correctness_of_stream_eq_some nth_stream_eq
/-- If `GenContFract.of v` terminated at step `n`, then the `n`th convergent is exactly `v`. -/
theorem of_correctness_of_terminatedAt (terminatedAt_n : (of v).TerminatedAt n) :
v = (of v).convs n :=
have : IntFractPair.stream v (n + 1) = none :=
of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none.1 terminatedAt_n
of_correctness_of_nth_stream_eq_none this
/-- If `GenContFract.of v` terminates, then there is `n : ℕ` such that the `n`th convergent is
exactly `v`.
-/
theorem of_correctness_of_terminates (terminates : (of v).Terminates) :
∃ n : ℕ, v = (of v).convs n :=
Exists.elim terminates fun n terminatedAt_n =>
Exists.intro n (of_correctness_of_terminatedAt terminatedAt_n)
open Filter
/-- If `GenContFract.of v` terminates, then its convergents will eventually always be `v`. -/
theorem of_correctness_atTop_of_terminates (terminates : (of v).Terminates) :
∀ᶠ n in atTop, v = (of v).convs n := by
rw [eventually_atTop]
obtain ⟨n, terminatedAt_n⟩ : ∃ n, (of v).TerminatedAt n := terminates
use n
intro m m_geq_n
rw [convs_stable_of_terminated m_geq_n terminatedAt_n]
exact of_correctness_of_terminatedAt terminatedAt_n
end GenContFract
|
Algebra\ContinuedFractions\Computation\TerminatesIffRat.lean
|
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Computation.Approximations
import Mathlib.Algebra.ContinuedFractions.Computation.CorrectnessTerminating
import Mathlib.Data.Rat.Floor
/-!
# Termination of Continued Fraction Computations (`GenContFract.of`)
## Summary
We show that the continued fraction for a value `v`, as defined in
`Mathlib.Algebra.ContinuedFractions.Basic`, terminates if and only if `v` corresponds to a
rational number, that is `↑v = q` for some `q : ℚ`.
## Main Theorems
- `GenContFract.coe_of_rat_eq` shows that
`GenContFract.of v = GenContFract.of q` for `v : α` given that `↑v = q` and `q : ℚ`.
- `GenContFract.terminates_iff_rat` shows that
`GenContFract.of v` terminates if and only if `↑v = q` for some `q : ℚ`.
## Tags
rational, continued fraction, termination
-/
namespace GenContFract
open GenContFract (of)
variable {K : Type*} [LinearOrderedField K] [FloorRing K]
/-
We will have to constantly coerce along our structures in the following proofs using their provided
map functions.
-/
attribute [local simp] Pair.map IntFractPair.mapFr
section RatOfTerminates
/-!
### Terminating Continued Fractions Are Rational
We want to show that the computation of a continued fraction `GenContFract.of v`
terminates if and only if `v ∈ ℚ`. In this section, we show the implication from left to right.
We first show that every finite convergent corresponds to a rational number `q` and then use the
finite correctness proof (`of_correctness_of_terminates`) of `GenContFract.of` to show that
`v = ↑q`.
-/
variable (v : K) (n : ℕ)
nonrec theorem exists_gcf_pair_rat_eq_of_nth_contsAux :
∃ conts : Pair ℚ, (of v).contsAux n = (conts.map (↑) : Pair K) :=
Nat.strong_induction_on n
(by
clear n
let g := of v
intro n IH
rcases n with (_ | _ | n)
-- n = 0
· suffices ∃ gp : Pair ℚ, Pair.mk (1 : K) 0 = gp.map (↑) by simpa [contsAux]
use Pair.mk 1 0
simp
-- n = 1
· suffices ∃ conts : Pair ℚ, Pair.mk g.h 1 = conts.map (↑) by simpa [contsAux]
use Pair.mk ⌊v⌋ 1
simp [g]
-- 2 ≤ n
· cases' IH (n + 1) <| lt_add_one (n + 1) with pred_conts pred_conts_eq
-- invoke the IH
cases' s_ppred_nth_eq : g.s.get? n with gp_n
-- option.none
· use pred_conts
have : g.contsAux (n + 2) = g.contsAux (n + 1) :=
contsAux_stable_of_terminated (n + 1).le_succ s_ppred_nth_eq
simp only [this, pred_conts_eq]
-- option.some
· -- invoke the IH a second time
cases' IH n <| lt_of_le_of_lt n.le_succ <| lt_add_one <| n + 1 with ppred_conts
ppred_conts_eq
obtain ⟨a_eq_one, z, b_eq_z⟩ : gp_n.a = 1 ∧ ∃ z : ℤ, gp_n.b = (z : K) :=
of_partNum_eq_one_and_exists_int_partDen_eq s_ppred_nth_eq
-- finally, unfold the recurrence to obtain the required rational value.
simp only [a_eq_one, b_eq_z,
contsAux_recurrence s_ppred_nth_eq ppred_conts_eq pred_conts_eq]
use nextConts 1 (z : ℚ) ppred_conts pred_conts
cases ppred_conts; cases pred_conts
simp [nextConts, nextNum, nextDen])
theorem exists_gcf_pair_rat_eq_nth_conts :
∃ conts : Pair ℚ, (of v).conts n = (conts.map (↑) : Pair K) := by
rw [nth_cont_eq_succ_nth_contAux]; exact exists_gcf_pair_rat_eq_of_nth_contsAux v <| n + 1
theorem exists_rat_eq_nth_num : ∃ q : ℚ, (of v).nums n = (q : K) := by
rcases exists_gcf_pair_rat_eq_nth_conts v n with ⟨⟨a, _⟩, nth_cont_eq⟩
use a
simp [num_eq_conts_a, nth_cont_eq]
theorem exists_rat_eq_nth_den : ∃ q : ℚ, (of v).dens n = (q : K) := by
rcases exists_gcf_pair_rat_eq_nth_conts v n with ⟨⟨_, b⟩, nth_cont_eq⟩
use b
simp [den_eq_conts_b, nth_cont_eq]
/-- Every finite convergent corresponds to a rational number. -/
theorem exists_rat_eq_nth_conv : ∃ q : ℚ, (of v).convs n = (q : K) := by
rcases exists_rat_eq_nth_num v n with ⟨Aₙ, nth_num_eq⟩
rcases exists_rat_eq_nth_den v n with ⟨Bₙ, nth_den_eq⟩
use Aₙ / Bₙ
simp [nth_num_eq, nth_den_eq, conv_eq_num_div_den]
variable {v}
/-- Every terminating continued fraction corresponds to a rational number. -/
theorem exists_rat_eq_of_terminates (terminates : (of v).Terminates) : ∃ q : ℚ, v = ↑q := by
obtain ⟨n, v_eq_conv⟩ : ∃ n, v = (of v).convs n := of_correctness_of_terminates terminates
obtain ⟨q, conv_eq_q⟩ : ∃ q : ℚ, (of v).convs n = (↑q : K) := exists_rat_eq_nth_conv v n
have : v = (↑q : K) := Eq.trans v_eq_conv conv_eq_q
use q, this
end RatOfTerminates
section RatTranslation
/-!
### Technical Translation Lemmas
Before we can show that the continued fraction of a rational number terminates, we have to prove
some technical translation lemmas. More precisely, in this section, we show that, given a rational
number `q : ℚ` and value `v : K` with `v = ↑q`, the continued fraction of `q` and `v` coincide.
In particular, we show that
```lean
(↑(GenContFract.of q : GenContFract ℚ) : GenContFract K) = GenContFract.of v`
```
in `GenContFract.coe_of_rat_eq`.
To do this, we proceed bottom-up, showing the correspondence between the basic functions involved in
the Computation first and then lift the results step-by-step.
-/
-- The lifting works for arbitrary linear ordered fields with a floor function.
variable {v : K} {q : ℚ}
/-! First, we show the correspondence for the very basic functions in
`GenContFract.IntFractPair`. -/
namespace IntFractPair
theorem coe_of_rat_eq (v_eq_q : v = (↑q : K)) :
((IntFractPair.of q).mapFr (↑) : IntFractPair K) = IntFractPair.of v := by
simp [IntFractPair.of, v_eq_q]
theorem coe_stream_nth_rat_eq (v_eq_q : v = (↑q : K)) (n : ℕ) :
((IntFractPair.stream q n).map (mapFr (↑)) : Option <| IntFractPair K) =
IntFractPair.stream v n := by
induction n with
| zero =>
-- Porting note: was
-- simp [IntFractPair.stream, coe_of_rat_eq v_eq_q]
simp only [IntFractPair.stream, Option.map_some', coe_of_rat_eq v_eq_q]
| succ n IH =>
rw [v_eq_q] at IH
cases stream_q_nth_eq : IntFractPair.stream q n with
| none => simp [IntFractPair.stream, IH.symm, v_eq_q, stream_q_nth_eq]
| some ifp_n =>
cases' ifp_n with b fr
cases' Decidable.em (fr = 0) with fr_zero fr_ne_zero
· simp [IntFractPair.stream, IH.symm, v_eq_q, stream_q_nth_eq, fr_zero]
· replace IH : some (IntFractPair.mk b (fr : K)) = IntFractPair.stream (↑q) n := by
rwa [stream_q_nth_eq] at IH
have : (fr : K)⁻¹ = ((fr⁻¹ : ℚ) : K) := by norm_cast
have coe_of_fr := coe_of_rat_eq this
simpa [IntFractPair.stream, IH.symm, v_eq_q, stream_q_nth_eq, fr_ne_zero]
theorem coe_stream'_rat_eq (v_eq_q : v = (↑q : K)) :
((IntFractPair.stream q).map (Option.map (mapFr (↑))) : Stream' <| Option <| IntFractPair K) =
IntFractPair.stream v := by
funext n; exact IntFractPair.coe_stream_nth_rat_eq v_eq_q n
end IntFractPair
/-! Now we lift the coercion results to the continued fraction computation. -/
theorem coe_of_h_rat_eq (v_eq_q : v = (↑q : K)) : (↑((of q).h : ℚ) : K) = (of v).h := by
unfold of IntFractPair.seq1
rw [← IntFractPair.coe_of_rat_eq v_eq_q]
simp
theorem coe_of_s_get?_rat_eq (v_eq_q : v = (↑q : K)) (n : ℕ) :
(((of q).s.get? n).map (Pair.map (↑)) : Option <| Pair K) = (of v).s.get? n := by
simp only [of, IntFractPair.seq1, Stream'.Seq.map_get?, Stream'.Seq.get?_tail]
simp only [Stream'.Seq.get?]
rw [← IntFractPair.coe_stream'_rat_eq v_eq_q]
rcases succ_nth_stream_eq : IntFractPair.stream q (n + 1) with (_ | ⟨_, _⟩) <;>
simp [Stream'.map, Stream'.get, succ_nth_stream_eq]
theorem coe_of_s_rat_eq (v_eq_q : v = (↑q : K)) :
((of q).s.map (Pair.map ((↑))) : Stream'.Seq <| Pair K) = (of v).s := by
ext n; rw [← coe_of_s_get?_rat_eq v_eq_q]; rfl
/-- Given `(v : K), (q : ℚ), and v = q`, we have that `of q = of v` -/
theorem coe_of_rat_eq (v_eq_q : v = (↑q : K)) :
(⟨(of q).h, (of q).s.map (Pair.map (↑))⟩ : GenContFract K) = of v := by
cases' gcf_v_eq : of v with h s; subst v
-- Porting note: made coercion target explicit
obtain rfl : ↑⌊(q : K)⌋ = h := by injection gcf_v_eq
-- Porting note: was
-- simp [coe_of_h_rat_eq rfl, coe_of_s_rat_eq rfl, gcf_v_eq]
simp only [gcf_v_eq, Int.cast_inj, Rat.floor_cast, of_h_eq_floor, eq_self_iff_true,
Rat.cast_intCast, and_self, coe_of_h_rat_eq rfl, coe_of_s_rat_eq rfl]
theorem of_terminates_iff_of_rat_terminates {v : K} {q : ℚ} (v_eq_q : v = (q : K)) :
(of v).Terminates ↔ (of q).Terminates := by
constructor <;> intro h <;> cases' h with n h <;> use n <;>
simp only [Stream'.Seq.TerminatedAt, (coe_of_s_get?_rat_eq v_eq_q n).symm] at h ⊢ <;>
cases h' : (of q).s.get? n <;>
simp only [h'] at h <;> -- Porting note: added
trivial
end RatTranslation
section TerminatesOfRat
/-!
### Continued Fractions of Rationals Terminate
Finally, we show that the continued fraction of a rational number terminates.
The crucial insight is that, given any `q : ℚ` with `0 < q < 1`, the numerator of `Int.fract q` is
smaller than the numerator of `q`. As the continued fraction computation recursively operates on
the fractional part of a value `v` and `0 ≤ Int.fract v < 1`, we infer that the numerator of the
fractional part in the computation decreases by at least one in each step. As `0 ≤ Int.fract v`,
this process must stop after finite number of steps, and the computation hence terminates.
-/
namespace IntFractPair
variable {q : ℚ} {n : ℕ}
/-- Shows that for any `q : ℚ` with `0 < q < 1`, the numerator of the fractional part of
`IntFractPair.of q⁻¹` is smaller than the numerator of `q`.
-/
theorem of_inv_fr_num_lt_num_of_pos (q_pos : 0 < q) : (IntFractPair.of q⁻¹).fr.num < q.num :=
Rat.fract_inv_num_lt_num_of_pos q_pos
/-- Shows that the sequence of numerators of the fractional parts of the stream is strictly
antitone. -/
theorem stream_succ_nth_fr_num_lt_nth_fr_num_rat {ifp_n ifp_succ_n : IntFractPair ℚ}
(stream_nth_eq : IntFractPair.stream q n = some ifp_n)
(stream_succ_nth_eq : IntFractPair.stream q (n + 1) = some ifp_succ_n) :
ifp_succ_n.fr.num < ifp_n.fr.num := by
obtain ⟨ifp_n', stream_nth_eq', ifp_n_fract_ne_zero, IntFractPair.of_eq_ifp_succ_n⟩ :
∃ ifp_n',
IntFractPair.stream q n = some ifp_n' ∧
ifp_n'.fr ≠ 0 ∧ IntFractPair.of ifp_n'.fr⁻¹ = ifp_succ_n :=
succ_nth_stream_eq_some_iff.mp stream_succ_nth_eq
have : ifp_n = ifp_n' := by injection Eq.trans stream_nth_eq.symm stream_nth_eq'
cases this
rw [← IntFractPair.of_eq_ifp_succ_n]
cases' nth_stream_fr_nonneg_lt_one stream_nth_eq with zero_le_ifp_n_fract ifp_n_fract_lt_one
have : 0 < ifp_n.fr := lt_of_le_of_ne zero_le_ifp_n_fract <| ifp_n_fract_ne_zero.symm
exact of_inv_fr_num_lt_num_of_pos this
theorem stream_nth_fr_num_le_fr_num_sub_n_rat :
∀ {ifp_n : IntFractPair ℚ},
IntFractPair.stream q n = some ifp_n → ifp_n.fr.num ≤ (IntFractPair.of q).fr.num - n := by
induction n with
| zero =>
intro ifp_zero stream_zero_eq
have : IntFractPair.of q = ifp_zero := by injection stream_zero_eq
simp [le_refl, this.symm]
| succ n IH =>
intro ifp_succ_n stream_succ_nth_eq
suffices ifp_succ_n.fr.num + 1 ≤ (IntFractPair.of q).fr.num - n by
rw [Int.ofNat_succ, sub_add_eq_sub_sub]
solve_by_elim [le_sub_right_of_add_le]
rcases succ_nth_stream_eq_some_iff.mp stream_succ_nth_eq with ⟨ifp_n, stream_nth_eq, -⟩
have : ifp_succ_n.fr.num < ifp_n.fr.num :=
stream_succ_nth_fr_num_lt_nth_fr_num_rat stream_nth_eq stream_succ_nth_eq
have : ifp_succ_n.fr.num + 1 ≤ ifp_n.fr.num := Int.add_one_le_of_lt this
exact le_trans this (IH stream_nth_eq)
theorem exists_nth_stream_eq_none_of_rat (q : ℚ) : ∃ n : ℕ, IntFractPair.stream q n = none := by
let fract_q_num := (Int.fract q).num; let n := fract_q_num.natAbs + 1
cases' stream_nth_eq : IntFractPair.stream q n with ifp
· use n, stream_nth_eq
· -- arrive at a contradiction since the numerator decreased num + 1 times but every fractional
-- value is nonnegative.
have ifp_fr_num_le_q_fr_num_sub_n : ifp.fr.num ≤ fract_q_num - n :=
stream_nth_fr_num_le_fr_num_sub_n_rat stream_nth_eq
have : fract_q_num - n = -1 := by
have : 0 ≤ fract_q_num := Rat.num_nonneg.mpr (Int.fract_nonneg q)
-- Porting note: was
-- simp [Int.natAbs_of_nonneg this, sub_add_eq_sub_sub_swap, sub_right_comm]
simp only [n, Nat.cast_add, Int.natAbs_of_nonneg this, Nat.cast_one,
sub_add_eq_sub_sub_swap, sub_right_comm, sub_self, zero_sub]
have : 0 ≤ ifp.fr := (nth_stream_fr_nonneg_lt_one stream_nth_eq).left
have : 0 ≤ ifp.fr.num := Rat.num_nonneg.mpr this
omega
end IntFractPair
/-- The continued fraction of a rational number terminates. -/
theorem terminates_of_rat (q : ℚ) : (of q).Terminates :=
Exists.elim (IntFractPair.exists_nth_stream_eq_none_of_rat q) fun n stream_nth_eq_none =>
Exists.intro n
(have : IntFractPair.stream q (n + 1) = none := IntFractPair.stream_isSeq q stream_nth_eq_none
of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none.mpr this)
end TerminatesOfRat
/-- The continued fraction `GenContFract.of v` terminates if and only if `v ∈ ℚ`. -/
theorem terminates_iff_rat (v : K) : (of v).Terminates ↔ ∃ q : ℚ, v = (q : K) :=
Iff.intro
(fun terminates_v : (of v).Terminates =>
show ∃ q : ℚ, v = (q : K) from exists_rat_eq_of_terminates terminates_v)
fun exists_q_eq_v : ∃ q : ℚ, v = (↑q : K) =>
Exists.elim exists_q_eq_v fun q => fun v_eq_q : v = ↑q =>
have : (of q).Terminates := terminates_of_rat q
(of_terminates_iff_of_rat_terminates v_eq_q).mpr this
end GenContFract
|
Algebra\ContinuedFractions\Computation\Translations.lean
|
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Computation.Basic
import Mathlib.Algebra.ContinuedFractions.Translations
/-!
# Basic Translation Lemmas Between Structures Defined for Computing Continued Fractions
## Summary
This is a collection of simple lemmas between the different structures used for the computation
of continued fractions defined in `Algebra.ContinuedFractions.Computation.Basic`. The file consists
of three sections:
1. Recurrences and inversion lemmas for `IntFractPair.stream`: these lemmas give us inversion
rules and recurrences for the computation of the stream of integer and fractional parts of
a value.
2. Translation lemmas for the head term: these lemmas show us that the head term of the computed
continued fraction of a value `v` is `⌊v⌋` and how this head term is moved along the structures
used in the computation process.
3. Translation lemmas for the sequence: these lemmas show how the sequences of the involved
structures (`IntFractPair.stream`, `IntFractPair.seq1`, and `GenContFract.of`) are connected,
i.e. how the values are moved along the structures and the termination of one sequence implies
the termination of another sequence.
## Main Theorems
- `succ_nth_stream_eq_some_iff` gives as a recurrence to compute the `n + 1`th value of the sequence
of integer and fractional parts of a value in case of non-termination.
- `succ_nth_stream_eq_none_iff` gives as a recurrence to compute the `n + 1`th value of the sequence
of integer and fractional parts of a value in case of termination.
- `get?_of_eq_some_of_succ_get?_intFractPair_stream` and
`get?_of_eq_some_of_get?_intFractPair_stream_fr_ne_zero` show how the entries of the sequence
of the computed continued fraction can be obtained from the stream of integer and fractional
parts.
-/
namespace GenContFract
open GenContFract (of)
-- Fix a discrete linear ordered floor field and a value `v`.
variable {K : Type*} [LinearOrderedField K] [FloorRing K] {v : K}
namespace IntFractPair
/-!
### Recurrences and Inversion Lemmas for `IntFractPair.stream`
Here we state some lemmas that give us inversion rules and recurrences for the computation of the
stream of integer and fractional parts of a value.
-/
theorem stream_zero (v : K) : IntFractPair.stream v 0 = some (IntFractPair.of v) :=
rfl
variable {n : ℕ}
theorem stream_eq_none_of_fr_eq_zero {ifp_n : IntFractPair K}
(stream_nth_eq : IntFractPair.stream v n = some ifp_n) (nth_fr_eq_zero : ifp_n.fr = 0) :
IntFractPair.stream v (n + 1) = none := by
cases' ifp_n with _ fr
change fr = 0 at nth_fr_eq_zero
simp [IntFractPair.stream, stream_nth_eq, nth_fr_eq_zero]
/-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional
parts of a value in case of termination.
-/
theorem succ_nth_stream_eq_none_iff :
IntFractPair.stream v (n + 1) = none ↔
IntFractPair.stream v n = none ∨ ∃ ifp, IntFractPair.stream v n = some ifp ∧ ifp.fr = 0 := by
rw [IntFractPair.stream]
cases IntFractPair.stream v n <;> simp [imp_false]
/-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional
parts of a value in case of non-termination.
-/
theorem succ_nth_stream_eq_some_iff {ifp_succ_n : IntFractPair K} :
IntFractPair.stream v (n + 1) = some ifp_succ_n ↔
∃ ifp_n : IntFractPair K,
IntFractPair.stream v n = some ifp_n ∧
ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n := by
simp [IntFractPair.stream, ite_eq_iff, Option.bind_eq_some]
/-- An easier to use version of one direction of
`GenContFract.IntFractPair.succ_nth_stream_eq_some_iff`. -/
theorem stream_succ_of_some {p : IntFractPair K} (h : IntFractPair.stream v n = some p)
(h' : p.fr ≠ 0) : IntFractPair.stream v (n + 1) = some (IntFractPair.of p.fr⁻¹) :=
succ_nth_stream_eq_some_iff.mpr ⟨p, h, h', rfl⟩
/-- The stream of `IntFractPair`s of an integer stops after the first term.
-/
theorem stream_succ_of_int (a : ℤ) (n : ℕ) : IntFractPair.stream (a : K) (n + 1) = none := by
induction' n with n ih
· refine IntFractPair.stream_eq_none_of_fr_eq_zero (IntFractPair.stream_zero (a : K)) ?_
simp only [IntFractPair.of, Int.fract_intCast]
· exact IntFractPair.succ_nth_stream_eq_none_iff.mpr (Or.inl ih)
theorem exists_succ_nth_stream_of_fr_zero {ifp_succ_n : IntFractPair K}
(stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n)
(succ_nth_fr_eq_zero : ifp_succ_n.fr = 0) :
∃ ifp_n : IntFractPair K, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr⁻¹ = ⌊ifp_n.fr⁻¹⌋ := by
-- get the witness from `succ_nth_stream_eq_some_iff` and prove that it has the additional
-- properties
rcases succ_nth_stream_eq_some_iff.mp stream_succ_nth_eq with
⟨ifp_n, seq_nth_eq, _, rfl⟩
refine ⟨ifp_n, seq_nth_eq, ?_⟩
simpa only [IntFractPair.of, Int.fract, sub_eq_zero] using succ_nth_fr_eq_zero
/-- A recurrence relation that expresses the `(n+1)`th term of the stream of `IntFractPair`s
of `v` for non-integer `v` in terms of the `n`th term of the stream associated to
the inverse of the fractional part of `v`.
-/
theorem stream_succ (h : Int.fract v ≠ 0) (n : ℕ) :
IntFractPair.stream v (n + 1) = IntFractPair.stream (Int.fract v)⁻¹ n := by
induction' n with n ih
· have H : (IntFractPair.of v).fr = Int.fract v := rfl
rw [stream_zero, stream_succ_of_some (stream_zero v) (ne_of_eq_of_ne H h), H]
· rcases eq_or_ne (IntFractPair.stream (Int.fract v)⁻¹ n) none with hnone | hsome
· rw [hnone] at ih
rw [succ_nth_stream_eq_none_iff.mpr (Or.inl hnone),
succ_nth_stream_eq_none_iff.mpr (Or.inl ih)]
· obtain ⟨p, hp⟩ := Option.ne_none_iff_exists'.mp hsome
rw [hp] at ih
rcases eq_or_ne p.fr 0 with hz | hnz
· rw [stream_eq_none_of_fr_eq_zero hp hz, stream_eq_none_of_fr_eq_zero ih hz]
· rw [stream_succ_of_some hp hnz, stream_succ_of_some ih hnz]
end IntFractPair
section Head
/-!
### Translation of the Head Term
Here we state some lemmas that show us that the head term of the computed continued fraction of a
value `v` is `⌊v⌋` and how this head term is moved along the structures used in the computation
process.
-/
/-- The head term of the sequence with head of `v` is just the integer part of `v`. -/
@[simp]
theorem IntFractPair.seq1_fst_eq_of : (IntFractPair.seq1 v).fst = IntFractPair.of v :=
rfl
theorem of_h_eq_intFractPair_seq1_fst_b : (of v).h = (IntFractPair.seq1 v).fst.b := by
cases aux_seq_eq : IntFractPair.seq1 v
simp [of, aux_seq_eq]
/-- The head term of the gcf of `v` is `⌊v⌋`. -/
@[simp]
theorem of_h_eq_floor : (of v).h = ⌊v⌋ := by
simp [of_h_eq_intFractPair_seq1_fst_b, IntFractPair.of]
end Head
section sequence
/-!
### Translation of the Sequences
Here we state some lemmas that show how the sequences of the involved structures
(`IntFractPair.stream`, `IntFractPair.seq1`, and `GenContFract.of`) are connected, i.e. how the
values are moved along the structures and how the termination of one sequence implies the
termination of another sequence.
-/
variable {n : ℕ}
theorem IntFractPair.get?_seq1_eq_succ_get?_stream :
(IntFractPair.seq1 v).snd.get? n = (IntFractPair.stream v) (n + 1) :=
rfl
section Termination
/-!
#### Translation of the Termination of the Sequences
Let's first show how the termination of one sequence implies the termination of another sequence.
-/
theorem of_terminatedAt_iff_intFractPair_seq1_terminatedAt :
(of v).TerminatedAt n ↔ (IntFractPair.seq1 v).snd.TerminatedAt n :=
Option.map_eq_none
theorem of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none :
(of v).TerminatedAt n ↔ IntFractPair.stream v (n + 1) = none := by
rw [of_terminatedAt_iff_intFractPair_seq1_terminatedAt, Stream'.Seq.TerminatedAt,
IntFractPair.get?_seq1_eq_succ_get?_stream]
end Termination
section Values
/-!
#### Translation of the Values of the Sequence
Now let's show how the values of the sequences correspond to one another.
-/
theorem IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some {gp_n : Pair K}
(s_nth_eq : (of v).s.get? n = some gp_n) :
∃ ifp : IntFractPair K, IntFractPair.stream v (n + 1) = some ifp ∧ (ifp.b : K) = gp_n.b := by
obtain ⟨ifp, stream_succ_nth_eq, gp_n_eq⟩ :
∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ Pair.mk 1 (ifp.b : K) = gp_n := by
unfold of IntFractPair.seq1 at s_nth_eq
simpa [Stream'.Seq.get?_tail, Stream'.Seq.map_get?] using s_nth_eq
cases gp_n_eq
simp_all only [Option.some.injEq, exists_eq_left']
/-- Shows how the entries of the sequence of the computed continued fraction can be obtained by the
integer parts of the stream of integer and fractional parts.
-/
theorem get?_of_eq_some_of_succ_get?_intFractPair_stream {ifp_succ_n : IntFractPair K}
(stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) :
(of v).s.get? n = some ⟨1, ifp_succ_n.b⟩ := by
unfold of IntFractPair.seq1
simp [Stream'.Seq.map_tail, Stream'.Seq.get?_tail, Stream'.Seq.map_get?, stream_succ_nth_eq]
/-- Shows how the entries of the sequence of the computed continued fraction can be obtained by the
fractional parts of the stream of integer and fractional parts.
-/
theorem get?_of_eq_some_of_get?_intFractPair_stream_fr_ne_zero {ifp_n : IntFractPair K}
(stream_nth_eq : IntFractPair.stream v n = some ifp_n) (nth_fr_ne_zero : ifp_n.fr ≠ 0) :
(of v).s.get? n = some ⟨1, (IntFractPair.of ifp_n.fr⁻¹).b⟩ :=
have : IntFractPair.stream v (n + 1) = some (IntFractPair.of ifp_n.fr⁻¹) := by
cases ifp_n
simp only [IntFractPair.stream, Nat.add_eq, add_zero, stream_nth_eq, Option.some_bind,
ite_eq_right_iff]
intro; contradiction
get?_of_eq_some_of_succ_get?_intFractPair_stream this
open Int IntFractPair
theorem of_s_head_aux (v : K) : (of v).s.get? 0 = (IntFractPair.stream v 1).bind (some ∘ fun p =>
{ a := 1
b := p.b }) := by
rw [of, IntFractPair.seq1]
simp only [of, Stream'.Seq.map_tail, Stream'.Seq.map, Stream'.Seq.tail, Stream'.Seq.head,
Stream'.Seq.get?, Stream'.map]
rw [← Stream'.get_succ, Stream'.get, Option.map]
split <;> simp_all only [Option.some_bind, Option.none_bind, Function.comp_apply]
/-- This gives the first pair of coefficients of the continued fraction of a non-integer `v`.
-/
theorem of_s_head (h : fract v ≠ 0) : (of v).s.head = some ⟨1, ⌊(fract v)⁻¹⌋⟩ := by
change (of v).s.get? 0 = _
rw [of_s_head_aux, stream_succ_of_some (stream_zero v) h, Option.bind]
rfl
variable (K)
/-- If `a` is an integer, then the coefficient sequence of its continued fraction is empty.
-/
theorem of_s_of_int (a : ℤ) : (of (a : K)).s = Stream'.Seq.nil :=
haveI h : ∀ n, (of (a : K)).s.get? n = none := by
intro n
induction' n with n ih
· rw [of_s_head_aux, stream_succ_of_int, Option.bind]
· exact (of (a : K)).s.prop ih
Stream'.Seq.ext fun n => (h n).trans (Stream'.Seq.get?_nil n).symm
variable {K} (v)
/-- Recurrence for the `GenContFract.of` an element `v` of `K` in terms of that of the inverse of
the fractional part of `v`.
-/
theorem of_s_succ (n : ℕ) : (of v).s.get? (n + 1) = (of (fract v)⁻¹).s.get? n := by
rcases eq_or_ne (fract v) 0 with h | h
· obtain ⟨a, rfl⟩ : ∃ a : ℤ, v = a := ⟨⌊v⌋, eq_of_sub_eq_zero h⟩
rw [fract_intCast, inv_zero, of_s_of_int, ← cast_zero, of_s_of_int,
Stream'.Seq.get?_nil, Stream'.Seq.get?_nil]
rcases eq_or_ne ((of (fract v)⁻¹).s.get? n) none with h₁ | h₁
· rwa [h₁, ← terminatedAt_iff_s_none,
of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none, stream_succ h, ←
of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none, terminatedAt_iff_s_none]
· obtain ⟨p, hp⟩ := Option.ne_none_iff_exists'.mp h₁
obtain ⟨p', hp'₁, _⟩ := exists_succ_get?_stream_of_gcf_of_get?_eq_some hp
have Hp := get?_of_eq_some_of_succ_get?_intFractPair_stream hp'₁
rw [← stream_succ h] at hp'₁
rw [Hp, get?_of_eq_some_of_succ_get?_intFractPair_stream hp'₁]
/-- This expresses the tail of the coefficient sequence of the `GenContFract.of` an element `v` of
`K` as the coefficient sequence of that of the inverse of the fractional part of `v`.
-/
theorem of_s_tail : (of v).s.tail = (of (fract v)⁻¹).s :=
Stream'.Seq.ext fun n => Stream'.Seq.get?_tail (of v).s n ▸ of_s_succ v n
variable (K) (n)
/-- If `a` is an integer, then the `convs'` of its continued fraction expansion
are all equal to `a`.
-/
theorem convs'_of_int (a : ℤ) : (of (a : K)).convs' n = a := by
induction' n with n
· simp only [zeroth_conv'_eq_h, of_h_eq_floor, floor_intCast, Nat.zero_eq]
· rw [convs', of_h_eq_floor, floor_intCast, add_right_eq_self]
exact convs'Aux_succ_none ((of_s_of_int K a).symm ▸ Stream'.Seq.get?_nil 0) _
variable {K}
/-- The recurrence relation for the `convs'` of the continued fraction expansion
of an element `v` of `K` in terms of the convergents of the inverse of its fractional part.
-/
theorem convs'_succ :
(of v).convs' (n + 1) = ⌊v⌋ + 1 / (of (fract v)⁻¹).convs' n := by
rcases eq_or_ne (fract v) 0 with h | h
· obtain ⟨a, rfl⟩ : ∃ a : ℤ, v = a := ⟨⌊v⌋, eq_of_sub_eq_zero h⟩
rw [convs'_of_int, fract_intCast, inv_zero, ← cast_zero, convs'_of_int, cast_zero,
div_zero, add_zero, floor_intCast]
· rw [convs', of_h_eq_floor, add_right_inj, convs'Aux_succ_some (of_s_head h)]
exact congr_arg (1 / ·) (by rw [convs', of_h_eq_floor, add_right_inj, of_s_tail])
end Values
end sequence
end GenContFract
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.