From beae901f5f6972acac53cd026cefdb07e2c223ef Mon Sep 17 00:00:00 2001 From: Robert Maxton Date: Sat, 21 Nov 2026 03:12:39 -0800 Subject: [PATCH 1/8] feat(CategoryTheory): chosen (co)representations, and `ConcreteCategory.homOfElement` The content was written by Robert Maxton; it was moved here (from his working files) and adapted to current Mathlib and its linters with Claude. Co-Authored-By: Claude Opus 5.5 --- Mathlib.lean | 1 + .../CategoryTheory/ChosenRepresentation.lean | 123 ++++++++++++++++++ .../ConcreteCategory/Representable.lean | 68 ++++++++++ Mathlib/Topology/Category/TopCat/Basic.lean | 20 +++ 4 files changed, 212 insertions(+) create mode 100644 Mathlib/CategoryTheory/ChosenRepresentation.lean diff --git a/Mathlib.lean b/Mathlib.lean index 6cba0dd3854c8c..071bfd5da81ca9 100644 --- a/Mathlib.lean +++ b/Mathlib.lean @@ -1,5 +1,6 @@ module -- shake: keep-all -- deprecated_module: ignore +public import Mathlib.CategoryTheory.ChosenRepresentation public import Std public import Batteries public import Mathlib.Algebra.AddConstMap.Basic diff --git a/Mathlib/CategoryTheory/ChosenRepresentation.lean b/Mathlib/CategoryTheory/ChosenRepresentation.lean new file mode 100644 index 00000000000000..2cd0f1a812d637 --- /dev/null +++ b/Mathlib/CategoryTheory/ChosenRepresentation.lean @@ -0,0 +1,123 @@ +/- +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` + +TODO(docstring) +-/ + +@[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)) + +def univ : F.obj (op F.reprObj) := c.reprBy.homEquiv (𝟙 _) +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] + +@[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) + +def couniv : F.obj F.coreprObj := c.coreprBy.homEquiv (𝟙 _) +def homOfElement {Z : C} (z : F.obj Z) : F.coreprObj ⟶ Z := c.coreprBy.homEquiv.symm z + +@[reassoc (attr := simp), 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] + +@[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..93ef0db5863a34 100644 --- a/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean +++ b/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean @@ -5,6 +5,7 @@ Authors: Dagur Asgeirsson -/ module +public import Mathlib.CategoryTheory.ChosenRepresentation public import Mathlib.CategoryTheory.ConcreteCategory.Forget public import Mathlib.CategoryTheory.Yoneda @@ -31,3 +32,70 @@ 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} + +def couniv : CC (forget C).coreprObj := c.coreprBy.homEquiv (𝟙 _) +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 + +@[reassoc (attr := simp), 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..5fc3667dc25abb 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,22 @@ 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 + +@[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 From f4f3e85564ac5c93917502fa78e74a135d1e1ad9 Mon Sep 17 00:00:00 2001 From: Robert Maxton Date: Sat, 21 Nov 2026 14:38:04 -0800 Subject: [PATCH 2/8] feat(CategoryTheory/ChosenRepresentation): add module- and def-level documentation --- .../CategoryTheory/ChosenRepresentation.lean | 41 ++++++++++++++++++- .../ConcreteCategory/Representable.lean | 7 ++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/Mathlib/CategoryTheory/ChosenRepresentation.lean b/Mathlib/CategoryTheory/ChosenRepresentation.lean index 2cd0f1a812d637..e149ba7cc39d6d 100644 --- a/Mathlib/CategoryTheory/ChosenRepresentation.lean +++ b/Mathlib/CategoryTheory/ChosenRepresentation.lean @@ -10,7 +10,35 @@ public import Mathlib.CategoryTheory.Yoneda /-! # Chosen (co)representations of functors to `Type` -TODO(docstring) +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 @@ -41,7 +69,10 @@ 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)] @@ -65,6 +96,8 @@ lemma map_homFromElement_apply : F.map (op (F.homFromElement z)) F.univ = z := b rw [← homFromElement_comp, homFromElement_univ, Category.comp_id] @[simp] +/-- Convenience version of `map_homFromElement_apply` in the case when `F.reprObj` is +a unique type. -/ 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] @@ -90,7 +123,10 @@ 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 @[reassoc (attr := simp), elementwise (attr := simp)] @@ -114,6 +150,9 @@ lemma map_homOfElement_apply : F.map (F.homOfElement z) F.couniv = z := by rw [← homOfElement_comp, homOfElement_univ, Category.id_comp] @[simp] +/-- 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. -/ 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] diff --git a/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean b/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean index 93ef0db5863a34..6659507ec3244b 100644 --- a/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean +++ b/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean @@ -1,7 +1,7 @@ /- 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 @@ -12,7 +12,8 @@ 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 @@ -89,8 +90,6 @@ lemma hom_apply_eq_iff {X Y : C} (f g : X ⟶ Y) (x : CC X) : 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) From 7142b1e5c5709c1b815fbd5c1be6721c1ae96c87 Mon Sep 17 00:00:00 2001 From: Robert Maxton Date: Sat, 21 Nov 2026 14:51:26 -0800 Subject: [PATCH 3/8] add documentation for the chosen corepresentation of the forgetful functor in `TopCat` --- Mathlib/Topology/Category/TopCat/Basic.lean | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Mathlib/Topology/Category/TopCat/Basic.lean b/Mathlib/Topology/Category/TopCat/Basic.lean index 5fc3667dc25abb..e13a535a5171fb 100644 --- a/Mathlib/Topology/Category/TopCat/Basic.lean +++ b/Mathlib/Topology/Category/TopCat/Basic.lean @@ -267,11 +267,12 @@ namespace TopCat lemma Hom.continuous {X Y : TopCat} (f : X ⟶ Y) : Continuous f := f.hom.continuous @[simps -isSimp] +/-- We choose `of PUnit` as the canonical corepresenting object of the forgetful functor in +`TopCat`. -/ 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 From 07ad552825d2ccc6681c9798c032a0ac498c4b9d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Sat, 21 Nov 2026 22:57:21 +0000 Subject: [PATCH 4/8] [pre-commit.ci lite] `lake exe mk_all` These commands made the changes in this commit. To make the same fixes yourself, run them in your mathlib4 checkout. --- Mathlib.lean | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mathlib.lean b/Mathlib.lean index 071bfd5da81ca9..8c07f1faf3a438 100644 --- a/Mathlib.lean +++ b/Mathlib.lean @@ -1,6 +1,5 @@ module -- shake: keep-all -- deprecated_module: ignore -public import Mathlib.CategoryTheory.ChosenRepresentation public import Std public import Batteries public import Mathlib.Algebra.AddConstMap.Basic @@ -2755,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 From 5de588f2e5edfac23b93ab4bb1313087f66a343f Mon Sep 17 00:00:00 2001 From: Robert Maxton Date: Sat, 21 Nov 2026 15:06:09 -0800 Subject: [PATCH 5/8] comments go before attributes --- Mathlib/CategoryTheory/ChosenRepresentation.lean | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mathlib/CategoryTheory/ChosenRepresentation.lean b/Mathlib/CategoryTheory/ChosenRepresentation.lean index e149ba7cc39d6d..d3210218276048 100644 --- a/Mathlib/CategoryTheory/ChosenRepresentation.lean +++ b/Mathlib/CategoryTheory/ChosenRepresentation.lean @@ -95,9 +95,9 @@ lemma map_homFromElement_apply : F.map (op (F.homFromElement z)) F.univ = z := b apply homFromElement_injective rw [← homFromElement_comp, homFromElement_univ, Category.comp_id] -@[simp] /-- 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] @@ -149,10 +149,10 @@ lemma map_homOfElement_apply : F.map (F.homOfElement z) F.couniv = z := by apply homOfElement_injective rw [← homOfElement_comp, homOfElement_univ, Category.id_comp] -@[simp] /-- 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] From 50ee42e09bef3f30bd67a122263519a3861a7302 Mon Sep 17 00:00:00 2001 From: Robert Maxton Date: Sat, 21 Nov 2026 15:10:36 -0800 Subject: [PATCH 6/8] doc-comments before attributes --- Mathlib/Topology/Category/TopCat/Basic.lean | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mathlib/Topology/Category/TopCat/Basic.lean b/Mathlib/Topology/Category/TopCat/Basic.lean index e13a535a5171fb..272e4c5c8b52bf 100644 --- a/Mathlib/Topology/Category/TopCat/Basic.lean +++ b/Mathlib/Topology/Category/TopCat/Basic.lean @@ -266,9 +266,9 @@ namespace TopCat lemma Hom.continuous {X Y : TopCat} (f : X ⟶ Y) : Continuous f := f.hom.continuous -@[simps -isSimp] /-- 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 } From 88fedc9715c1fca9aeb9ce08c93ad439f00d9663 Mon Sep 17 00:00:00 2001 From: Robert Maxton Date: Sat, 21 Nov 2026 15:31:54 -0800 Subject: [PATCH 7/8] linters --- Mathlib/CategoryTheory/ChosenRepresentation.lean | 2 +- Mathlib/CategoryTheory/ConcreteCategory/Representable.lean | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Mathlib/CategoryTheory/ChosenRepresentation.lean b/Mathlib/CategoryTheory/ChosenRepresentation.lean index d3210218276048..e9e6ea9f89439e 100644 --- a/Mathlib/CategoryTheory/ChosenRepresentation.lean +++ b/Mathlib/CategoryTheory/ChosenRepresentation.lean @@ -129,7 +129,7 @@ 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 -@[reassoc (attr := simp), elementwise (attr := simp)] +@[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 .. diff --git a/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean b/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean index 6659507ec3244b..d1f7c03df2199f 100644 --- a/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean +++ b/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean @@ -45,7 +45,11 @@ variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type [∀ 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 := @@ -55,7 +59,7 @@ def homOfElement (x : CC Z) : (forget C).coreprObj ⟶ Z := c.coreprBy.homEquiv. (x : CC Z) (u : CC (forget C).coreprObj) : homOfElement x u = x := (forget C).map_homOfElement_apply' x u -@[reassoc (attr := simp), elementwise (attr := simp)] +@[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 .. From 76e8f7d8776eeced6213b38db7748111f3c76a43 Mon Sep 17 00:00:00 2001 From: Robert Maxton Date: Sat, 21 Nov 2026 16:12:53 -0800 Subject: [PATCH 8/8] linter --- Mathlib/CategoryTheory/ConcreteCategory/Representable.lean | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean b/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean index d1f7c03df2199f..48eeeee567f4f3 100644 --- a/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean +++ b/Mathlib/CategoryTheory/ConcreteCategory/Representable.lean @@ -49,7 +49,7 @@ variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type 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`. -/ +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 :=