Skip to content
Open
2 changes: 2 additions & 0 deletions Mathlib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -8250,6 +8251,7 @@ public import Mathlib.Topology.Category.TopCat.Basic
public import Mathlib.Topology.Category.TopCat.EffectiveEpi
public import Mathlib.Topology.Category.TopCat.EpiMono
public import Mathlib.Topology.Category.TopCat.GrothendieckTopology
public import Mathlib.Topology.Category.TopCat.Limits.AlexandrovDiscrete
public import Mathlib.Topology.Category.TopCat.Limits.Basic
public import Mathlib.Topology.Category.TopCat.Limits.Cofiltered
public import Mathlib.Topology.Category.TopCat.Limits.Konig
Expand Down
123 changes: 123 additions & 0 deletions Mathlib/CategoryTheory/ChosenRepresentation.lean
Original file line number Diff line number Diff line change
@@ -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 (𝟙 _)

Check failure on line 44 in Mathlib/CategoryTheory/ChosenRepresentation.lean

View workflow job for this annotation

GitHub Actions / ci (fork) / Test and lint

@CategoryTheory.Functor.univ definition missing documentation string
def homFromElement {Z : C} (z : F.obj (op Z)) : Z ⟶ F.reprObj := c.reprBy.homEquiv.symm z

Check failure on line 45 in Mathlib/CategoryTheory/ChosenRepresentation.lean

View workflow job for this annotation

GitHub Actions / ci (fork) / Test and lint

@CategoryTheory.Functor.homFromElement definition missing documentation string

@[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 (𝟙 _)

Check failure on line 93 in Mathlib/CategoryTheory/ChosenRepresentation.lean

View workflow job for this annotation

GitHub Actions / ci (fork) / Test and lint

@CategoryTheory.Functor.couniv definition missing documentation string
def homOfElement {Z : C} (z : F.obj Z) : F.coreprObj ⟶ Z := c.coreprBy.homEquiv.symm z

Check failure on line 94 in Mathlib/CategoryTheory/ChosenRepresentation.lean

View workflow job for this annotation

GitHub Actions / ci (fork) / Test and lint

@CategoryTheory.Functor.homOfElement definition missing documentation string

@[reassoc (attr := simp), elementwise (attr := simp)]

Check failure on line 96 in Mathlib/CategoryTheory/ChosenRepresentation.lean

View workflow job for this annotation

GitHub Actions / ci (fork) / Test and lint

@CategoryTheory.Functor.homOfElement_comp_assoc simp can prove this:
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
68 changes: 68 additions & 0 deletions Mathlib/CategoryTheory/ConcreteCategory/Representable.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-/
module

public import Mathlib.CategoryTheory.ChosenRepresentation
public import Mathlib.CategoryTheory.ConcreteCategory.Forget
public import Mathlib.CategoryTheory.Yoneda

Expand All @@ -31,3 +32,70 @@
α.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 (𝟙 _)

Check failure on line 47 in Mathlib/CategoryTheory/ConcreteCategory/Representable.lean

View workflow job for this annotation

GitHub Actions / ci (fork) / Test and lint

@CategoryTheory.ConcreteCategory.couniv definition missing documentation string
def homOfElement (x : CC Z) : (forget C).coreprObj ⟶ Z := c.coreprBy.homEquiv.symm x

Check failure on line 48 in Mathlib/CategoryTheory/ConcreteCategory/Representable.lean

View workflow job for this annotation

GitHub Actions / ci (fork) / Test and lint

@CategoryTheory.ConcreteCategory.homOfElement definition missing documentation string

@[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
3 changes: 3 additions & 0 deletions Mathlib/Data/Set/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ alias exists_mem_of_nonempty := exists_mem_univ_of_nonempty
theorem ne_univ_iff_exists_notMem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by
rw [← not_forall, ← eq_univ_iff_forall]

lemma ne_univ_of_notMem {α : Type*} {s : Set α} {a : α} (ha : a ∉ s) : s ≠ univ :=
ne_univ_iff_exists_notMem s |>.mpr ⟨a, ha⟩

theorem not_subset_iff_exists_mem_notMem {α : Type*} {s t : Set α} :
¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def]

Expand Down
Loading
Loading