diff --git a/Mathlib.lean b/Mathlib.lean index 6cba0dd3854c8c..8c07f1faf3a438 100644 --- a/Mathlib.lean +++ b/Mathlib.lean @@ -2754,6 +2754,7 @@ public import Mathlib.CategoryTheory.Center.Linear public import Mathlib.CategoryTheory.Center.Localization public import Mathlib.CategoryTheory.Center.NegOnePow public import Mathlib.CategoryTheory.Center.Preadditive +public import Mathlib.CategoryTheory.ChosenRepresentation public import Mathlib.CategoryTheory.CodiscreteCategory public import Mathlib.CategoryTheory.CofilteredSystem public import Mathlib.CategoryTheory.CommSq diff --git a/Mathlib/CategoryTheory/ChosenRepresentation.lean b/Mathlib/CategoryTheory/ChosenRepresentation.lean new file mode 100644 index 00000000000000..e9e6ea9f89439e --- /dev/null +++ b/Mathlib/CategoryTheory/ChosenRepresentation.lean @@ -0,0 +1,162 @@ +/- +Copyright (c) 2026 Robert Maxton. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Maxton +-/ +module + +public import Mathlib.CategoryTheory.Yoneda + +/-! +# Chosen (co)representations of functors to `Type` + +This file defines typeclasses for chosen (co)representations of functors to `Type*`. + +In **Type**, every element `x : X` of every type `X` can be uniquely represented as a morphism +`homOfElement x : PUnit ⟶ X`. This can be thought of as a canonical choice of corepresenting object +for the forgetful functor, which in the case of `Type*` is just the identity. Generalizing, we can +define such a `homOfElement` any time we have a `ChosenCorepresentation` of a functor, and dually, +we can define a `homFromElement` any time we have a `ChosenRepresentation` of a functor. + +This file provides typeclasses and convenience API for working with chosen (co)representations of +arbitrary functors. See `Mathlib.CategoryTheory.ConcreteCategory.Representable` for a +specialization to the important case where the category is concrete and the functor is the +canonical forgetful functor to `Type*`. + +### Main definitions: +* `Chosen(Co)Representation`: a data-carrying typeclass holding a canonical choice of +(co)-representing object and its corresponding canonical assignment of elements to morphisms. +* `F.(co)reprObj` and `F.(co)univ` : the chosen (co)-representing object and the corresponding +universal element. +* `F.homFromElement` and `F.homOfElement` : the canonical morphisms induced by elements via the +chosen (co)representation. + +### Future work +* Reimplement `CategoryTheory.homOfElement` using `(𝟭 TypeCat).homOfElement`. + * Provide instances for common categories, such as `Type*`, `TopCat`, `Cat`. +* Refactor `Mathlib.Algebra.Category.Grp.ForgetCorepresentable` and the work that depends on it + to use `ChosenCorepresentation`. +* Once the upstream `CategoryTheory` files have been `to_dual`-ified, we can refactor this file + to use `to_dual` as well. + +-/ + +@[expose] public section + +universe w v u + +namespace CategoryTheory.Functor +open Opposite + +variable {C : Type*} [Category* C] + +/-- Data typeclass for a chosen representation of a functor. -/ +class ChosenRepresentation (F : Cᵒᵖ ⥤ Type*) where + /-- The representing object of the chosen representation. -/ + obj : C + /-- The natural equivalence of hom-types witnessing that `F` is representable by `obj`. -/ + reprBy : F.RepresentableBy obj + +@[inherit_doc ChosenRepresentation.obj] +abbrev reprObj (F : Cᵒᵖ ⥤ Type*) [c : ChosenRepresentation F] : C := c.obj + +@[inherit_doc ChosenRepresentation.obj] +def ChosenRepresentation.Simps.reprObj (F : Cᵒᵖ ⥤ Type*) [c : ChosenRepresentation F] : C := + F.reprObj + +initialize_simps_projections ChosenRepresentation (obj → reprObj) + +section +variable (F : Cᵒᵖ ⥤ Type*) [c : ChosenRepresentation F] {Z : C} (z z₁ z₂ : F.obj (op Z)) + +/-- The chosen universal element, that represents `𝟙 F.reprObj`. -/ +def univ : F.obj (op F.reprObj) := c.reprBy.homEquiv (𝟙 _) + +/-- The unique morphism `F.obj (op Z) ⟶ F.reprObj` induced by an `z : F.obj (op Z)`. -/ +def homFromElement {Z : C} (z : F.obj (op Z)) : Z ⟶ F.reprObj := c.reprBy.homEquiv.symm z + +@[reassoc (attr := simp), elementwise (attr := simp)] +lemma homFromElement_comp {X Y : C} (y : F.obj (op Y)) (f : X ⟶ Y) : + f ≫ F.homFromElement y = F.homFromElement (F.map (op f) y) := + c.reprBy.comp_homEquiv_symm .. + +lemma homFromElement_injective : + Function.Injective (F.homFromElement : F.obj (op Z) → (Z ⟶ F.reprObj)) := + c.reprBy.homEquiv.symm.injective + +lemma homFromElement_inj : F.homFromElement z₁ = F.homFromElement z₂ ↔ z₁ = z₂ := + c.reprBy.homEquiv.symm.injective.eq_iff + +@[simp] lemma homFromElement_univ : F.homFromElement F.univ = 𝟙 _ := by + simp [homFromElement, univ] + +@[simp] +lemma map_homFromElement_apply : F.map (op (F.homFromElement z)) F.univ = z := by + apply homFromElement_injective + rw [← homFromElement_comp, homFromElement_univ, Category.comp_id] + +/-- Convenience version of `map_homFromElement_apply` in the case when `F.reprObj` is +a unique type. -/ +@[simp] +lemma map_homFromElement_apply' [Unique (F.obj (op F.reprObj))] + (a : F.obj (op F.reprObj)) : F.map (op (F.homFromElement z)) a = z := by + rw [Unique.eq_default a, Unique.default_eq F.univ, map_homFromElement_apply] + +end + +/-- Data typeclass for a chosen corepresentation of a functor. -/ +class ChosenCorepresentation (F : C ⥤ Type*) where + /-- The corepresenting object of the chosen corepresentation. -/ + obj : C + /-- The natural equivalence of hom-types witnessing that `F` is corepresentable by `obj`. -/ + coreprBy : F.CorepresentableBy obj + +@[inherit_doc ChosenCorepresentation.obj] +abbrev coreprObj (F : C ⥤ Type*) [c : ChosenCorepresentation F] : C := c.obj + +@[inherit_doc ChosenCorepresentation.obj] +def ChosenCorepresentation.Simps.coreprObj (F : C ⥤ Type*) [c : ChosenCorepresentation F] : C := + F.coreprObj + +initialize_simps_projections ChosenCorepresentation (obj → coreprObj) + +section +variable (F : C ⥤ Type*) [c : ChosenCorepresentation F] {Z : C} (z z₁ z₂ : F.obj Z) + +/-- The chosen universal element, that co-represents `𝟙 F.coreprObj`. -/ +def couniv : F.obj F.coreprObj := c.coreprBy.homEquiv (𝟙 _) + +/-- The unique morphism `F.coreprObj ⟶ Z` induced by an element `z : F.obj Z`. -/ +def homOfElement {Z : C} (z : F.obj Z) : F.coreprObj ⟶ Z := c.coreprBy.homEquiv.symm z + +@[simp, reassoc, elementwise (attr := simp)] +lemma homOfElement_comp {X Y : C} (x : F.obj X) (f : X ⟶ Y) : + F.homOfElement x ≫ f = F.homOfElement (F.map f x) := + c.coreprBy.homEquiv_symm_comp .. + +lemma homOfElement_injective : + Function.Injective (F.homOfElement : F.obj Z → (F.coreprObj ⟶ Z)) := + c.coreprBy.homEquiv.symm.injective + +lemma homOfElement_inj : F.homOfElement z₁ = F.homOfElement z₂ ↔ z₁ = z₂ := + c.coreprBy.homEquiv.symm.injective.eq_iff + +@[simp] lemma homOfElement_univ : F.homOfElement F.couniv = 𝟙 _ := by + simp [homOfElement, couniv] + +@[simp] +lemma map_homOfElement_apply : F.map (F.homOfElement z) F.couniv = z := by + apply homOfElement_injective + rw [← homOfElement_comp, homOfElement_univ, Category.id_comp] + +/-- Convenience version of `map_homOfElement_apply` in the common case when `F.coreprObj` is +a unique type. In particular, this is true of `forget C` for many concrete categories `C`, +including `Type` itself. -/ +@[simp] +lemma map_homOfElement_apply' [Unique (F.obj F.coreprObj)] + (a : F.obj F.coreprObj) : F.map (F.homOfElement z) a = z := by + rw [Unique.eq_default a, Unique.default_eq F.couniv, map_homOfElement_apply] + +end + +end CategoryTheory.Functor diff --git a/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean b/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean index 1bd8cebda5f4c5..48eeeee567f4f3 100644 --- a/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean +++ b/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean @@ -1,17 +1,19 @@ /- Copyright (c) 2026 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. -Authors: Dagur Asgeirsson +Authors: Dagur Asgeirsson, Robert Maxton -/ module +public import Mathlib.CategoryTheory.ChosenRepresentation public import Mathlib.CategoryTheory.ConcreteCategory.Forget public import Mathlib.CategoryTheory.Yoneda /-! # Representable functors in concrete categories -This file provides some API for the situation `(F ⋙ forget D).RepresentableBy Y`. +This file provides some API for the situation `(F ⋙ forget D).RepresentableBy Y`, and in particular +the case of `(forget D).RepresentableBy Y` itself. -/ @[expose] public section @@ -31,3 +33,72 @@ lemma homEquiv'_comp {X X' : C} (f : X ⟶ X') (g : X' ⟶ Y) : α.homEquiv' (f ≫ g) = F.map f.op (α.homEquiv' g) := α.homEquiv_comp _ _ end CategoryTheory.Functor.RepresentableBy + +-- For now, we just repeat everything derived from `ChosenCorepresentation` for the special case +-- when the functor is the forgetful functor, because `CC` and `FC` are not always reducibly def-eq +-- to `(forget C).obj`, `.map`. +universe w v u + +namespace CategoryTheory.ConcreteCategory + +variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type w} + [∀ X Y : C, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory C FC] + [c : (forget C).ChosenCorepresentation] {Z Y : C} + +/-- The chosen universal element, that co-represents `𝟙 (forget C).coreprObj`. -/ +def couniv : CC (forget C).coreprObj := c.coreprBy.homEquiv (𝟙 _) + +/-- The unique morphism `(forget C).coreprObj ⟶ Z` corresponding to an element `z : ↥Z`. This +generalizes the function `fun ⟨⟩ ↦ z` for the case of `PUnit` in `TypeCat`. -/ +def homOfElement (x : CC Z) : (forget C).coreprObj ⟶ Z := c.coreprBy.homEquiv.symm x + +@[simp] lemma homOfElement_apply (x : CC Z) : homOfElement x couniv = x := + (forget C).map_homOfElement_apply .. + +@[simp] lemma homOfElement_apply' [Unique (CC (forget C).coreprObj)] + (x : CC Z) (u : CC (forget C).coreprObj) : homOfElement x u = x := + (forget C).map_homOfElement_apply' x u + +@[simp, reassoc, elementwise (attr := simp)] +lemma homOfElement_comp (x : CC Z) (g : Z ⟶ Y) : homOfElement x ≫ g = homOfElement (g x) := + c.coreprBy.homEquiv_symm_comp .. + +lemma homOfElement_injective : + Function.Injective (homOfElement : CC Z → ((forget C).coreprObj ⟶ Z)) := + c.coreprBy.homEquiv.symm.injective + +lemma homOfElement_inj {x y : CC Z} : homOfElement x = homOfElement y ↔ x = y := by + rw [← c.coreprBy.homEquiv.symm.injective.eq_iff]; rfl + +@[simp] lemma homOfElement_couniv : homOfElement (couniv : CC (forget C).coreprObj) = 𝟙 _ := by + simp [homOfElement, couniv] + +@[ext] +lemma homOfElement_ext {f g : (forget C).coreprObj ⟶ Z} (h : f couniv = g couniv) : f = g := by + replace h := congrArg homOfElement h + simpa [← homOfElement_comp, homOfElement_couniv] using h + +/-- When the forgetful functor of a concrete category is corepresentable, pointwise equality of +morphisms can be tested by composition with `homOfElement`. -/ +lemma hom_ext_iff' {X Y : C} (f g : X ⟶ Y) : + f = g ↔ ∀ x : CC X, homOfElement x ≫ f = homOfElement x ≫ g where + mp h := by simp [h] + mpr h := by + simp_rw [homOfElement_comp, homOfElement_inj] at h + rwa [ConcreteCategory.hom_ext_iff] + +/-- When the forgetful functor of a concrete category is corepresentable, equality of morphisms at +a point can be tested via `homOfElement`. -/ +lemma hom_apply_eq_iff {X Y : C} (f g : X ⟶ Y) (x : CC X) : + f x = g x ↔ homOfElement x ≫ f = homOfElement x ≫ g where + mp h := by simp [h] + mpr h := by simp_rw [homOfElement_comp, homOfElement_inj] at h; exact h + +alias ⟨_, hom_ext'⟩ := hom_ext_iff' + +lemma apply_eq_iff_homOfElement_comp {X Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) + (x : CC X) (y : CC Y) : f x = g y ↔ + ConcreteCategory.homOfElement x ≫ f = ConcreteCategory.homOfElement y ≫ g := by + simp_rw [ConcreteCategory.homOfElement_comp, ConcreteCategory.homOfElement_inj] + +end CategoryTheory.ConcreteCategory diff --git a/Mathlib/Topology/Category/TopCat/Basic.lean b/Mathlib/Topology/Category/TopCat/Basic.lean index 19b2d48a80cfbc..272e4c5c8b52bf 100644 --- a/Mathlib/Topology/Category/TopCat/Basic.lean +++ b/Mathlib/Topology/Category/TopCat/Basic.lean @@ -7,6 +7,7 @@ module public import Mathlib.CategoryTheory.ConcreteCategory.Forget public import Mathlib.CategoryTheory.ConcreteCategory.Notation +public import Mathlib.CategoryTheory.ConcreteCategory.Representable public import Mathlib.Topology.ContinuousMap.Basic set_option doc.verso true @@ -260,3 +261,23 @@ lemma const_apply {X Y : TopCat.{u}} (y : Y) (x : X) : const y x = y := rfl end TopCat + +namespace TopCat + +lemma Hom.continuous {X Y : TopCat} (f : X ⟶ Y) : Continuous f := f.hom.continuous + +/-- We choose `of PUnit` as the canonical corepresenting object of the forgetful functor in +`TopCat`. -/ +@[simps -isSimp] +instance : (forget TopCat).ChosenCorepresentation where + obj := ↧PUnit + coreprBy.homEquiv := { toFun f := f ⟨⟩, invFun y := TopCat.ofHom <| .const _ y } + +instance : Unique ((forget TopCat.{u}).coreprObj) where + default := PUnit.unit + uniq := by rintro ⟨⟩; rfl + +lemma couniv_eq : + (ConcreteCategory.couniv : (forget TopCat).coreprObj) = PUnit.unit := rfl + +end TopCat