Documentation

Mathlib.CategoryTheory.Types.Basic

The category Type. #

In this section we define a LargeCategory structure on Type u, in such a way that it becomes a ConcreteCategory.

Implementation #

We define the one-field structure TypeCat.Fun to wrap a function between types, and a FunLike instance on it. Then we define a one-field structure TypeCat.Hom which wraps a Fun. The morphisms in the category Type u are defined to be TypeCat.Hom, and the FC parameter of the ConcreteCategory instance is TypeCat.Fun. TypeCat.Fun serves as a layer of separation between the FC parameter of the ConcreteCategory instance and bare functions, to avoid defining a FunLike instance on the latter (which would give two non-reducibly defeq coercions from morphisms in Type to functions), and the outer nesting TypeCat.Hom gives a layer of separation between morphisms and FC, as is done for all concrete categories in mathlib.

To promote a function to a morphism in this category, we provide the abbreviation ↾f, as well as a corresponding notation ↾f. (Entered as \upr .)

Main definitions #

We define uliftFunctor, from Type u to Type (max u v), and show that it is fully faithful (but not, of course, essentially surjective).

We prove some basic facts about the category Type:

structure TypeCat.Fun (X : Type u_1) (Y : Type u_2) :
Type (max u_1 u_2)

A one-field structure wrapping a function between types.

  • toFun : X → Y

    The underlying function.

Instances For
    theorem TypeCat.Fun.ext_iff {X : Type u_1} {Y : Type u_2} {x y : Fun X Y} :
    x = y ↔ x.toFun = y.toFun
    theorem TypeCat.Fun.ext {X : Type u_1} {Y : Type u_2} {x y : Fun X Y} (toFun : x.toFun = y.toFun) :
    x = y
    @[instance_reducible, macro_inline]
    instance TypeCat.instFunLikeFun {X : Type u_1} {Y : Type u_2} :
    FunLike (Fun X Y) X Y
    Equations
    theorem TypeCat.Fun.mk_apply {X : Type u_1} {Y : Type u_2} (f : X → Y) (x : X) :
    { toFun := f } x = f x
    @[simp]
    theorem TypeCat.Fun.coe_mk {X : Type u_1} {Y : Type u_2} (f : X → Y) :
    ⇑{ toFun := f } = f
    @[implicit_reducible]
    def TypeCat.Fun.id (X : Type u_1) :
    Fun X X

    The identity function as a Fun.

    Equations
    Instances For
      @[simp]
      theorem TypeCat.Fun.id_apply (X : Type u_1) (a : X) :
      (id X) a = a
      @[implicit_reducible]
      def TypeCat.Fun.comp {X : Type u_1} {Y : Type u_2} {Z : Type u_3} (f : Fun Y Z) (g : Fun X Y) :
      Fun X Z

      Composition of Funs.

      Equations
      Instances For
        @[simp]
        theorem TypeCat.Fun.comp_apply {X : Type u_1} {Y : Type u_2} {Z : Type u_3} (f : Fun Y Z) (g : Fun X Y) (a✝ : X) :
        (f.comp g) a✝ = f.toFun (g.toFun a✝)
        def TypeCat.Fun.homEquiv (X Y : Type u) :
        Fun X Y ≃ (X → Y)

        The equivalence between Funs and functions between types.

        Equations
        Instances For
          structure TypeCat.Hom (X Y : Type u) :

          The type of morphisms in Type.

          • _mkInternal :: (
            • hom' : Fun X Y

              The underlying function

          • )
          Instances For
            theorem TypeCat.Hom.ext {X Y : Type u} {x y : Hom X Y} (hom' : x.hom' = y.hom') :
            x = y
            theorem TypeCat.Hom.ext_iff {X Y : Type u} {x y : Hom X Y} :
            x = y ↔ x.hom' = y.hom'
            @[instance_reducible]
            Equations
            • One or more equations did not get rendered due to their size.
            @[instance_reducible]

            The concrete category instance on Type u.

            Note: sometimes one needs to specify explicitly (CC := fun X ↦ X) to help typeclass inference.

            Equations
            • One or more equations did not get rendered due to their size.
            @[reducible, inline]
            abbrev TypeCat.Hom.hom {X Y : Type u} (f : Hom X Y) :
            Fun X Y

            Turn a morphism in Type back into a function.

            Equations
            Instances For
              @[reducible, inline]
              abbrev TypeCat.ofHom {X Y : Type u} (f : X → Y) :
              X ⟶ Y

              Typecheck a function as a morphism in Type.

              Equations
              Instances For

                Typecheck a function as a morphism in Type.

                Equations
                Instances For
                  def TypeCat.Hom.Simps.hom (X Y : Type u) (f : X ⟶ Y) :
                  Fun X Y

                  Use the ConcreteCategory.hom projection for @[simps] lemmas.

                  Equations
                  Instances For
                    @[simp]
                    theorem TypeCat.Fun.toFun_apply {X Y : Type u} (f : Fun X Y) (x : X) :
                    f.toFun x = f x
                    @[simp]
                    theorem TypeCat.ofHom_eq {X Y : Type u} (f : X ⟶ Y) :
                    @[simp]
                    theorem TypeCat.hom_ofHom {X Y : Type u} (f : X → Y) :
                    Hom.hom (ofHom f) = { toFun := f }
                    @[simp]
                    theorem TypeCat.ofHom_hom {X Y : Type u} (f : X ⟶ Y) :
                    ofHom ⇑(Hom.hom f) = f
                    @[simp]
                    theorem TypeCat.ofHom_apply {X Y : Type u} (f : X → Y) (x : X) :
                    @[simp]
                    theorem TypeCat.homEquiv_symm_apply {X Y : Type u} (f : X → Y) :
                    theorem TypeCat.congr_arg {X Y : Type u} (f : X ⟶ Y) {x x' : X} (h : x = x') :
                    @[simp]
                    theorem CategoryTheory.types_congr_hom {X Y : Type u} {f g : X ⟶ Y} (h : f = g) (x : X) :
                    def CategoryTheory.Functor.sections {J : Type u} [Category.{v, u} J] (F : Functor J (Type w)) :
                    Set ((j : J) → F.obj j)

                    The sections of a functor F : J ⥤ Type are the choices of a point u j : F.obj j for each j, such that F.map f (u j) = u j' for every morphism f : j ⟶ j'.

                    We later use these to define limits in Type and in many concrete categories.

                    Equations
                    Instances For
                      @[simp]
                      theorem CategoryTheory.Functor.sections_property {J : Type u} [Category.{v, u} J] {F : Functor J (Type w)} (s : ↑F.sections) {j j' : J} (f : j ⟶ j') :
                      (ConcreteCategory.hom (F.map f)) (↑s j) = ↑s j'
                      theorem CategoryTheory.Functor.sections_ext_iff {J : Type u} [Category.{v, u} J] {F : Functor J (Type w)} {x y : ↑F.sections} :
                      x = y ↔ ∀ (j : J), ↑x j = ↑y j

                      The functor which sends a functor to types to its sections.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        @[simp]
                        theorem CategoryTheory.Functor.sectionsFunctor_map (J : Type u) [Category.{v, u} J] {F G : Functor J (Type w)} (φ : F ⟶ G) :
                        (sectionsFunctor J).map φ = TypeCat.ofHom fun (x : ↑F.sections) => ⟨fun (j : J) => (ConcreteCategory.hom (φ.app j)) (↑x j), ⋯⟩
                        theorem CategoryTheory.Functor.map_comp_apply {C : Type u₁} [Category.{v₁, u₁} C] {D : Type u₂} [Category.{v₂, u₂} D] (self : Functor C D) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) {F : D → D → Type uF} {carrier : D → Type w} {instFunLike : (X Y : D) → FunLike (F X Y) (carrier X) (carrier Y)} [inst : ConcreteCategory D F] (x : carrier (self.obj X)) :
                        theorem CategoryTheory.NatTrans.comp_app_apply {C : Type u₁} [Category.{v₁, u₁} C] {D : Type u₂} [Category.{v₂, u₂} D] {F G H : Functor C D} (α : F ⟶ G) (β : G ⟶ H) (X : C) {F✝ : D → D → Type uF} {carrier : D → Type w} {instFunLike : (X Y : D) → FunLike (F✝ X Y) (carrier X) (carrier Y)} [inst : ConcreteCategory D F✝] (x : carrier (F.obj X)) :
                        theorem CategoryTheory.Functor.map_id_apply {C : Type u₁} [Category.{v₁, u₁} C] {D : Type u₂} [Category.{v₂, u₂} D] (self : Functor C D) (X : C) {F : D → D → Type uF} {carrier : D → Type w} {instFunLike : (X Y : D) → FunLike (F X Y) (carrier X) (carrier Y)} [inst : ConcreteCategory D F] (x : carrier (self.obj X)) :
                        @[deprecated CategoryTheory.Functor.map_comp_apply (since := "2026-03-09")]
                        theorem CategoryTheory.FunctorToTypes.map_comp_apply {C : Type u} [Category.{v, u} C] (F : Functor C (Type w)) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (a : F.obj X) :
                        @[deprecated CategoryTheory.Functor.map_id_apply (since := "2026-03-09")]
                        @[deprecated CategoryTheory.NatTrans.comp_app_apply (since := "2026-03-09")]
                        theorem CategoryTheory.FunctorToTypes.comp {C : Type u} [Category.{v, u} C] (F G H : Functor C (Type w)) {X : C} (σ : F ⟶ G) (τ : G ⟶ H) (x : F.obj X) :
                        @[simp]
                        theorem CategoryTheory.eqToHom_map_comp_apply {C : Type u₁} [Category.{v₁, u₁} C] {D : Type u₂} [Category.{v₂, u₂} D] (F : Functor C D) {X Y Z : C} (p : X = Y) (q : Y = Z) {F✝ : D → D → Type uF} {carrier : D → Type w} {instFunLike : (X Y : D) → FunLike (F✝ X Y) (carrier X) (carrier Y)} [inst : ConcreteCategory D F✝] (x : carrier (F.obj X)) :
                        theorem CategoryTheory.Functor.map_hom_inv'_apply {C : Type u} [Category.{v, u} C] {D : Type u₂} [Category.{v₂, u₂} D] (F : Functor C D) {X Y : C} (f : X ≅ Y) {F✝ : D → D → Type uF} {carrier : D → Type w} {instFunLike : (X Y : D) → FunLike (F✝ X Y) (carrier X) (carrier Y)} [inst : ConcreteCategory D F✝] (x : carrier (F.obj X)) :
                        theorem CategoryTheory.Functor.map_hom_inv_apply {C : Type u} [Category.{v, u} C] {D : Type u₂} [Category.{v₂, u₂} D] (F : Functor C D) {X Y : C} (f : X ⟶ Y) [IsIso f] {F✝ : D → D → Type uF} {carrier : D → Type w} {instFunLike : (X Y : D) → FunLike (F✝ X Y) (carrier X) (carrier Y)} [inst : ConcreteCategory D F✝] (x : carrier (F.obj X)) :
                        theorem CategoryTheory.Functor.map_inv_hom'_apply {C : Type u} [Category.{v, u} C] {D : Type u₂} [Category.{v₂, u₂} D] (F : Functor C D) {X Y : C} (f : X ≅ Y) {F✝ : D → D → Type uF} {carrier : D → Type w} {instFunLike : (X Y : D) → FunLike (F✝ X Y) (carrier X) (carrier Y)} [inst : ConcreteCategory D F✝] (x : carrier (F.obj Y)) :
                        theorem CategoryTheory.Functor.map_inv_hom_apply {C : Type u} [Category.{v, u} C] {D : Type u₂} [Category.{v₂, u₂} D] (F : Functor C D) {X Y : C} (f : Y ⟶ X) [IsIso f] {F✝ : D → D → Type uF} {carrier : D → Type w} {instFunLike : (X Y : D) → FunLike (F✝ X Y) (carrier X) (carrier Y)} [inst : ConcreteCategory D F✝] (x : carrier (F.obj X)) :
                        @[simp]
                        theorem CategoryTheory.Iso.inv_hom_id_app_apply {C : Type u₁} [Category.{v₁, u₁} C] {D : Type u₂} [Category.{v₂, u₂} D] {F G : Functor C D} (α : F ≅ G) (X : C) {F✝ : D → D → Type uF} {carrier : D → Type w} {instFunLike : (X Y : D) → FunLike (F✝ X Y) (carrier X) (carrier Y)} [inst : ConcreteCategory D F✝] (x : carrier (G.obj X)) :
                        @[simp]
                        theorem CategoryTheory.Iso.hom_inv_id_app_apply {C : Type u₁} [Category.{v₁, u₁} C] {D : Type u₂} [Category.{v₂, u₂} D] {F G : Functor C D} (α : F ≅ G) (X : C) {F✝ : D → D → Type uF} {carrier : D → Type w} {instFunLike : (X Y : D) → FunLike (F✝ X Y) (carrier X) (carrier Y)} [inst : ConcreteCategory D F✝] (x : carrier (F.obj X)) :
                        theorem CategoryTheory.FunctorToTypes.naturality_symm {C : Type u} [Category.{v, u} C] {F : Functor C (Type u_1)} {G : Functor C (Type u_2)} (e : (j : C) → F.obj j ≃ G.obj j) (naturality : ∀ {j j' : C} (f : j ⟶ j'), ⇑(e j') ∘ ⇑(ConcreteCategory.hom (F.map f)) = ⇑(ConcreteCategory.hom (G.map f)) ∘ ⇑(e j)) {j j' : C} (f : j ⟶ j') :
                        ⇑(e j').symm ∘ ⇑(ConcreteCategory.hom (G.map f)) = ⇑(ConcreteCategory.hom (F.map f)) ∘ ⇑(e j).symm

                        The isomorphism between a Type which has been ULifted to the same universe, and the original type.

                        Equations
                        Instances For

                          The functor embedding Type u into Type (max u v). Write this as uliftFunctor.{5, 2} to get Type 2 ⥤ Type 5.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            @[simp]
                            theorem CategoryTheory.uliftFunctor_map {X x✝ : Type u} (f : X ⟶ x✝) :

                            uliftFunctor : Type u ⥤ Type max u v is fully faithful.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For

                              Any term x of a type X corresponds to a morphism PUnit ⟶ X.

                              Equations
                              Instances For

                                A morphism in Type is a monomorphism if and only if it is injective.

                                A morphism in Type is a monomorphism if and only if it is injective.

                                A morphism in Type _ is an epimorphism if and only if it is surjective.

                                A morphism in Type is an epimorphism if and only if it is surjective.

                                ofTypeFunctor m converts from Lean's Type-based Category to CategoryTheory. This allows us to use these functors in category theory.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  @[simp]
                                  @[simp]
                                  def Equiv.toIso {X Y : Type u} (e : X ≃ Y) :
                                  X ≅ Y

                                  Any equivalence between types in the same universe gives a categorical isomorphism between those types.

                                  Equations
                                  Instances For
                                    @[simp]
                                    theorem Equiv.toIso_hom_hom_apply {X Y : Type u} (e : X ≃ Y) (x : X) :
                                    @[simp]
                                    theorem Equiv.toIso_inv_hom_apply {X Y : Type u} (e : X ≃ Y) (x : Y) :
                                    @[deprecated Equiv.toIso_hom_hom_apply (since := "2026-03-20")]
                                    theorem Equiv.toIso_hom {X Y : Type u} (e : X ≃ Y) (x : X) :

                                    Alias of Equiv.toIso_hom_hom_apply.

                                    @[deprecated Equiv.toIso_inv_hom_apply (since := "2026-03-20")]
                                    theorem Equiv.toIso_inv {X Y : Type u} (e : X ≃ Y) (x : Y) :

                                    Alias of Equiv.toIso_inv_hom_apply.

                                    @[implicit_reducible]
                                    def CategoryTheory.Iso.toEquiv {X Y : Type u} (i : X ≅ Y) :
                                    X ≃ Y

                                    Any isomorphism between types gives an equivalence.

                                    Equations
                                    Instances For
                                      @[simp]
                                      theorem CategoryTheory.Iso.toEquiv_apply {X Y : Type u} (i : X ≅ Y) (a : X) :
                                      @[simp]
                                      theorem CategoryTheory.Iso.toEquiv_symm_apply {X Y : Type u} (i : X ≅ Y) (a : Y) :
                                      @[simp]
                                      theorem CategoryTheory.Iso.toEquiv_comp {X Y Z : Type u} (f : X ≅ Y) (g : Y ≅ Z) :

                                      A morphism in Type u is an isomorphism if and only if it is bijective.

                                      def equivIsoIso {X Y : Type u} :
                                      X ≃ Y ≅ X ≅ Y

                                      Equivalences (between types in the same universe) are the same as (isomorphic to) isomorphisms of types.

                                      Equations
                                      Instances For
                                        @[simp]
                                        theorem equivIsoIso_hom {X Y : Type u} :
                                        equivIsoIso.hom = TypeCat.ofHom fun (e : X ≃ Y) => e.toIso
                                        @[simp]
                                        theorem equivIsoIso_inv {X Y : Type u} :
                                        def equivEquivIso {X Y : Type u} :
                                        X ≃ Y ≃ (X ≅ Y)

                                        Equivalences (between types in the same universe) are the same as (equivalent to) isomorphisms of types.

                                        Equations
                                        Instances For
                                          @[simp]
                                          theorem equivEquivIso_hom {X Y : Type u} (e : X ≃ Y) :
                                          @[simp]
                                          theorem equivEquivIso_inv {X Y : Type u} (e : X ≅ Y) :