|
|
|
|
Quelle Comp.lean
Sprache: Lean
|
|
/-
Copyright (c) 2026 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
module
public import Mathlib.CategoryTheory.Limits.Types.End
public import Mathlib.CategoryTheory.Profunctor.Basic
/-!
# Composition of Profunctors
This file defines composition of profunctors. Given profunctors `P : C ⥤ Dᵒᵖ ⥤ Type` and
`Q : D ⥤ Eᵒᵖ ⥤ Type`, the composite `P.comp Q` is the profunctor `C ⥤ Eᵒᵖ ⥤ Type` given on objects
`X : C` and `Y : E` by the coend `∫ d, P X d × Q d Y`, where `d` ranges over objects of `D`.
## Main Definitions
(All in the namespace `CategoryTheory.Profunctor`)
* `comp` : Composition of profunctors.
* `whiskerLeft` : Left whiskering of a natural transformation of profunctors.
* `whiskerRight` : Right whiskering of a natural transformation of profunctors.
* `leftUnitor` : The left unitor isomorphism `Profunctor.id.comp P ≅ P`.
* `rightUnitor` : The right unitor isomorphism `P.comp Profunctor.id ≅ P`.
* `associator` : The associator isomorphism `(P.comp Q).comp R ≅ P.comp (Q.comp R)`.
These satisfy the coherence laws for a bicategory, see the file
`Mathlib.CategoryTheory.Profunctor.Bicategory`.
-/
@[expose] public section
universe w w' v u
open Opposite
namespace CategoryTheory
namespace Profunctor
section Composition
section Definition
variable {C : Type*} [Category* C] {D : Type u} [Category.{v} D] {E : Type*} [Category* E]
/-- The bifunctor whose coend defines the composite of two profunctors. -/
@[implicit_reducible, simps! obj_obj obj_map map_app]
def compDiagram (P : Profunctor.{w} C D) (Q : Profunctor.{w'} D E) (X : C) (Y : E) :
Dᵒᵖ ⥤ D ⥤ Type max w w' where
obj U := {
obj V := ((P.obj X).obj U) × ((Q.obj V).obj (Opposite.op Y))
map f := TypeCat.ofHom (Prod.map id ((Q.map f).app _)) }
map g := { app U := TypeCat.ofHom (Prod.map ((P.obj _).map g) id) }
/-- The map on composition diagrams induced by morphisms in the outer variables. -/
@[simps]
def compDiagramMap (P : Profunctor.{w} C D) (Q : Profunctor.{w'} D E)
{X X' : C} {Y Y' : E} (f : X ⟶ X') (g : Y ⟶ Y') :
compDiagram P Q X Y' ⟶ compDiagram P Q X' Y where
app d := { app d' := TypeCat.ofHom (Prod.map ((P.map f).app d) ((Q.obj d').map g.op)) }
@[simp]
lemma compDiagramMap_id (P : Profunctor.{w} C D) (Q : Profunctor.{w'} D E) (X : C) (Y : E) :
P.compDiagramMap Q ( X) ( Y) = _ := by
cat_disch
@[simp]
lemma compDiagramMap_comp (P : Profunctor.{w} C D) (Q : Profunctor.{w'} D E)
{X₁ X₂ X₃ : C} {Y₁ Y₂ Y₃ : E} (f : X₁ ⟶ X₂) (f' : X₂ ⟶ X₃) (g : Y₁ ⟶ Y₂) (g' : Y₂ ⟶ Y₃) :
P.compDiagramMap Q (f ≫ f') (g ≫ g') = P.compDiagramMap Q f g' ≫ P.compDiagramMap Q f' g := by
cat_disch
open Limits
/-- Composition of profunctors using a chosen coend construction. -/
@[implicit_reducible, simps! obj_obj obj_map map_app]
def univComp [Limits.ChosenCoends.{v, u} (Type (max w w'))]
(P : Profunctor.{w} C D) (Q : Profunctor.{w'} D E) : Profunctor.{max w w'} C E :=
.ofCore {
obj X Y := chosenCoend <| compDiagram P Q X Y
map f g := chosenCoend.map <| compDiagramMap P Q f g }
/-- Composition of profunctors in the standard universe configuration. -/
@[implicit_reducible, simps! obj_obj obj_map map_app]
def comp (P : Profunctor.{max u w} C D) (Q : Profunctor.{max u w} D E) : Profunctor.{max u w} C E :=
Profunctor.univComp.{max u w, max u w} P Q
end Definition
section Whisker
open TypeCat Limits Types
variable {C D E : Type u} [Category* C] [Category* D] [Category* E]
section Left
variable (P : Profunctor.{max u w} C D) {Q R : Profunctor.{max u w} D E} (f : Q ⟶ R)
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
/-- Left whiskering of a natural transformation of profunctors. -/
@[simps app_app]
def whiskerLeft : P.comp Q ⟶ P.comp R where
app X := {
app Y := chosenCoend.map { app d := {
app d' := ↾Prod.map id ((f.app d').app Y)
naturality _ _ _ := by
ext
dsimp
apply Prod.ext <;>
simp [← comp_apply, -types_comp_apply] } }
naturality _ _ _ := by ext ⟨_, _, _⟩; simp [chosenCoend_def, chosenCoend.map_apply] }
naturality _ _ _ := by ext _ ⟨_, _, _⟩; simp [chosenCoend_def, chosenCoend.map_apply]
variable (Q) in
@[simp]
lemma whiskerLeft_id : P.whiskerLeft ( Q) = (P.comp Q) := by
ext _ _ ⟨_, _, _⟩
rfl
@[simp]
lemma whiskerLeft_comp {S : Profunctor.{max u w} D E} (f : Q ⟶ R) (g : R ⟶ S) :
P.whiskerLeft (f ≫ g) = P.whiskerLeft f ≫ P.whiskerLeft g := by
ext _ _ ⟨_, _, _⟩
rfl
end Left
section Right
variable {P Q : Profunctor.{max u w} C D} (R : Profunctor.{max u w} D E) (f : P ⟶ Q)
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
attribute [local simp] chosenCoend_def chosenCoend.map_apply in
/-- Right whiskering of a natural transformation of profunctors. -/
@[simps app_app]
def whiskerRight : P.comp R ⟶ Q.comp R where
app X := { app Y := chosenCoend.map { app d := { app d' := ↾Prod.map ((f.app _).app _) id } } }
naturality _ _ _ := by
ext _ ⟨_, _, _⟩
dsimp
apply Quot.sound
rw [coendRel_iff]
exact ⟨ _, by simp [← comp_apply, -types_comp_apply]⟩
@[simp]
lemma id_whiskerRight : whiskerRight R ( P) = (P.comp R) := by
ext _ _ ⟨_, _, _⟩
rfl
@[simp]
lemma comp_whiskerRight {R : Profunctor.{max u w} C D} (f : P ⟶ Q) (g : Q ⟶ R)
(S : Profunctor.{max u w} D E) :
whiskerRight S (f ≫ g) = whiskerRight S f ≫ whiskerRight S g := by
ext _ _ ⟨_, _, _⟩
rfl
end Right
@[reassoc (attr := simp)]
lemma whisker_exchange {P Q : Profunctor.{max u w} C D} {R S : Profunctor.{max u w} D E}
(f : P ⟶ Q) (g : R ⟶ S) :
P.whiskerLeft g ≫ whiskerRight S f = whiskerRight R f ≫ Q.whiskerLeft g := by
ext _ _ ⟨_, _, _⟩
rfl
end Whisker
section LeftUnitor
variable {C : Type u} [Category.{u} C] {D : Type u} [Category* D]
open Limits TypeCat
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
/-- The left unitor isomorphism `Profunctor.id.comp P ≅ P` for composition of profunctors. -/
@[simps! inv_app_app]
def leftUnitor (P : Profunctor.{u} C D) : Profunctor.id.comp P ≅ P :=
NatIso.ofComponents (fun X ↦ NatIso.ofComponents (fun Y ↦ {
hom := ↾Quot.lift (fun ⟨d, f, x⟩ ↦ (P.map f).app _ x) fun _ _ ↦ by rintro ⟨f, x⟩; simp
inv := ↾fun x ↦ Quot.mk _ ⟨X, X, x⟩
hom_inv_id := by
ext ⟨_, f, x⟩
symm
apply Quot.sound
rw [Types.coendRel_iff]
exact ⟨f, ⟨ X, x⟩, by cat_disch⟩ })
(fun f ↦ by dsimp; ext; simp [compDiagram, chosenCoend.ι_apply _]))
(fun f ↦ by ext _ ⟨_, _⟩; simp [Types.chosenCoend_def, chosenCoend.map_apply])
attribute [local simp] Types.chosenCoend_def in
@[simp]
lemma leftUnitor_hom_app_app_mk (P : Profunctor.{u} C D) (X : C) (Y : Dᵒᵖ)
(d : C) (f : d ⟶ X) (x : (P.obj d).obj Y) :
dsimp% ((P.leftUnitor).hom.app X).app Y (Quot.mk _ ⟨d, f, x⟩) = (P.map f).app Y x := rfl
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
attribute [local simp] Types.chosenCoend_def in
@[simp]
lemma id_whiskerLeft {P Q : Profunctor.{u} C D} (f : P ⟶ Q) :
(Profunctor.id (C := C)).whiskerLeft f =
(P.leftUnitor).hom ≫ f ≫ (Q.leftUnitor).inv := by
rw [← cancel_epi (P.leftUnitor).inv]
ext
simp [chosenCoend.map_apply]
end LeftUnitor
section RightUnitor
open Limits TypeCat
variable {C : Type u} [Category* C] {D : Type u} [Category.{u} D]
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
/-- The right unitor isomorphism `P.comp Profunctor.id ≅ P` for composition of profunctors. -/
@[simps! inv_app_app]
def rightUnitor (P : Profunctor.{u} C D) : P.comp .id ≅ P :=
NatIso.ofComponents (fun X ↦ NatIso.ofComponents (fun Y ↦ {
hom := ↾Quot.lift (fun ⟨d, x, f⟩ ↦ (P.obj X).map f.op x) fun _ _ h ↦ by cases h; simp
inv := ↾fun x ↦ Quot.mk _ ⟨Y.unop, x, Y.unop⟩
hom_inv_id := by
ext ⟨_, x, f⟩
apply Quot.sound
rw [Types.coendRel_iff]
exact ⟨f, ⟨x, (unop Y)⟩, by cat_disch⟩ })
(fun f ↦ by dsimp; ext; simp [compDiagram, chosenCoend.ι_apply _]))
(fun f ↦ by ext _ ⟨_, _⟩; simp [Types.chosenCoend_def, chosenCoend.map_apply])
set_option backward.defeqAttrib.useBackward true in
attribute [local simp] Types.chosenCoend_def in
@[simp]
lemma rightUnitor_hom_app_app_mk (P : Profunctor.{u} C D) (X : C) (Y : Dᵒᵖ)
(d : D) (x : (P.obj X).obj (op d)) (f : Y.unop ⟶ d) :
dsimp% ((P.rightUnitor).hom.app X).app Y (Quot.mk _ ⟨d, x, f⟩) = (P.obj X).map f.op x := rfl
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
attribute [local simp] Types.chosenCoend_def in
@[simp]
lemma whiskerRight_id {P Q : Profunctor.{u} C D} (f : P ⟶ Q) :
whiskerRight (Profunctor.id (C := D)) f =
(P.rightUnitor).hom ≫ f ≫ (Q.rightUnitor).inv := by
rw [← cancel_mono (Q.rightUnitor).hom]
ext _ _ ⟨_, _, g⟩
simp [chosenCoend.map_apply]
end RightUnitor
section Associator
variable {C D E F : Type u} [Category* C] [Category* D] [Category* E] [Category* F]
(P : Profunctor.{max w u} C D) (Q : Profunctor.{max w u} D E) (R : Profunctor.{max w u} E F)
open TypeCat Limits Types
/-- The map on representatives underlying `associatorHom`. -/
def associatorHomFun (X : C) (Y : Fᵒᵖ) (e : E) (r : (R.obj e).obj (op (unop Y))) :
((j : D) × ((P.compDiagram Q X e).obj (op j)).obj j) →
((j : D) × ((P.compDiagram (Q.comp R) X (unop Y)).obj (op j)).obj j) :=
fun ⟨d, p, q⟩ ↦ ⟨d, p, Quot.mk _ ⟨e, q, r⟩⟩
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
attribute [local simp] Types.chosenCoend_def chosenCoend.map_apply in
/-- `associatorHomFun` respects the coend relation. -/
lemma associatorHomFun_rel (X : C) (Y : Fᵒᵖ) (e : E) (r : (R.obj e).obj (op (unop Y))) :
∀ ⦃a b : (j : D) × ((P.compDiagram Q X e).obj (op j)).obj j⦄,
coendRel (P.compDiagram Q X e) a b →
coendRel (P.compDiagram (Q.comp R) X (unop Y))
(associatorHomFun P Q R X Y e r a) (associatorHomFun P Q R X Y e r b) := by
rintro ⟨d, p, q⟩ ⟨d', p', q'⟩ ⟨f, x⟩
rw [coendRel_iff]
exact ⟨f, by simp [associatorHomFun]⟩
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
attribute [local simp] Types.chosenCoend_def chosenCoend.map_apply in
/-- The forward map of the objectwise associator for composition of profunctors. -/
def associatorHom (X : C) (Y : Fᵒᵖ) :
(((P.comp Q).comp R).obj X).obj Y ⟶ ((P.comp (Q.comp R)).obj X).obj Y := by
refine ↾Quot.lift (fun ⟨e, x, r⟩ ↦
Quot.map (associatorHomFun P Q R X Y e r) (associatorHomFun_rel P Q R X Y e r) x) ?_
rintro ⟨e, _, _⟩ ⟨e', _, _⟩ ⟨f, ⟨x, r⟩⟩
refine Quot.inductionOn x ?_
rintro ⟨d, p, q⟩
dsimp [Quot.map, associatorHomFun]
simp only [Functor.map_id, NatTrans.id_app, types_id_apply]
-- First use the inner coend condition, then apply the outer quotient constructor.
let outer (x : ((Q.comp R).obj d).obj Y) :=
chosenCoend.ι (P.compDiagram (Q.comp R) X (unop Y)) d (p, x)
exact congrArg outer
(types_congr_hom (chosenCoend.condition (F := Q.compDiagram R d (unop Y)) f) (q, r))
/-- The map on representatives underlying `associatorInv`. -/
def associatorInvFun (X : C) (Y : Fᵒᵖ) (d : D) (p : (P.obj X).obj (op d)) :
((j : E) × ((Q.compDiagram R d (unop Y)).obj (op j)).obj j) →
((j : E) × (((P.comp Q).compDiagram R X (unop Y)).obj (op j)).obj j) :=
fun ⟨e, q, r⟩ ↦ ⟨e, Quot.mk _ ⟨d, p, q⟩, r⟩
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
attribute [local simp] Types.chosenCoend_def chosenCoend.map_apply in
/-- `associatorInvFun` respects the coend relation. -/
lemma associatorInvFun_rel (X : C) (Y : Fᵒᵖ) (d : D) (p : (P.obj X).obj (op d)) :
∀ ⦃a b : (j : E) × ((Q.compDiagram R d (unop Y)).obj (op j)).obj j⦄,
coendRel (Q.compDiagram R d (unop Y)) a b →
coendRel ((P.comp Q).compDiagram R X (unop Y))
(associatorInvFun P Q R X Y d p a) (associatorInvFun P Q R X Y d p b) := by
rintro ⟨e, q, r⟩ ⟨e', q', r'⟩ ⟨f, x⟩
rw [coendRel_iff]
use f
simp [associatorInvFun]
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
attribute [local simp] Types.chosenCoend_def chosenCoend.map_apply in
/-- The inverse map of the objectwise associator for composition of profunctors. -/
def associatorInv (X : C) (Y : Fᵒᵖ) :
((P.comp (Q.comp R)).obj X).obj Y ⟶ (((P.comp Q).comp R).obj X).obj Y := by
refine ↾Quot.lift (fun ⟨d, p, x⟩ ↦
Quot.map (associatorInvFun P Q R X Y d p) (associatorInvFun_rel P Q R X Y d p) x) ?_
rintro ⟨d, _, _⟩ ⟨d', _, _⟩ ⟨f, ⟨p, x⟩⟩
refine Quot.inductionOn x ?_
rintro ⟨e, q, r⟩
dsimp [Quot.map, associatorInvFun]
simp only [Functor.map_id, types_id_apply]
-- First use the inner coend condition, then apply the outer quotient constructor.
let outer (x : ((P.comp Q).obj X).obj (op e)) :=
chosenCoend.ι ((P.comp Q).compDiagram R X (unop Y)) e (x, r)
exact congrArg outer
(types_congr_hom (chosenCoend.condition (F := P.compDiagram Q X e) f) (p, q))
set_option backward.defeqAttrib.useBackward true in
attribute [local simp] Types.chosenCoend_def chosenCoend.map_apply in
/-- The objectwise components of the associator isomorphism
`(P.comp Q).comp R ≅ P.comp (Q.comp R)`. -/
def associatorComponents (X : C) (Y : Fᵒᵖ) :
(P.comp Q |>.comp R |>.obj X |>.obj Y) ≅ P.comp (Q.comp R) |>.obj X |>.obj Y where
hom := associatorHom P Q R X Y
inv := associatorInv P Q R X Y
hom_inv_id := by
ext ⟨_, ⟨_, _, _⟩, _⟩
dsimp [associatorHom, associatorInv, associatorHomFun, associatorInvFun, Quot.map]
inv_hom_id := by
ext ⟨_, _, ⟨_, _, _⟩⟩
dsimp [associatorHom, associatorInv, associatorHomFun, associatorInvFun, Quot.map]
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
/-- The associator isomorphism `(P.comp Q).comp R ≅ P.comp (Q.comp R)` for composition of
profunctors. -/
def associator : (P.comp Q).comp R ≅ P.comp (Q.comp R) :=
NatIso.ofComponents (fun X ↦ NatIso.ofComponents (fun Y ↦ associatorComponents P Q R X Y)
fun _ ↦ by
ext ⟨_, ⟨_, _, _⟩, _⟩
simp [associatorComponents, associatorHom, associatorHomFun, chosenCoend_def,
chosenCoend.map_apply, Quot.map])
fun _ ↦ by
ext _ ⟨_, ⟨_, _, _⟩, _⟩
simp [associatorComponents, associatorHom, associatorHomFun, chosenCoend_def,
chosenCoend.map_apply, Quot.map]
attribute [local simp] Types.chosenCoend_def in
@[simp]
lemma associator_hom_app_app_mk (X : C) (Y : Fᵒᵖ) (d : D) (e : E)
(p : (P.obj X).obj (op d)) (q : (Q.obj d).obj (op e)) (r : (R.obj e).obj Y) :
dsimp% (((associator.{w} P Q R).hom.app X).app Y
(Quot.mk _ ⟨e, Quot.mk _ ⟨d, p, q⟩, r⟩)) =
Quot.mk _ ⟨d, p, Quot.mk _ ⟨e, q, r⟩⟩ := rfl
attribute [local simp] Types.chosenCoend_def in
@[simp]
lemma associator_inv_app_app_mk (X : C) (Y : Fᵒᵖ) (d : D) (e : E)
(p : (P.obj X).obj (op d)) (q : (Q.obj d).obj (op e)) (r : (R.obj e).obj Y) :
dsimp% (((associator.{w} P Q R).inv.app X).app Y
(Quot.mk _ ⟨d, p, Quot.mk _ ⟨e, q, r⟩⟩)) =
Quot.mk _ ⟨e, Quot.mk _ ⟨d, p, q⟩, r⟩ := rfl
@[simp]
lemma comp_whiskerLeft {S : Profunctor.{max u w} E F} (f : R ⟶ S) :
(P.comp Q).whiskerLeft f =
(P.associator Q R).hom ≫ P.whiskerLeft (Q.whiskerLeft f) ≫ (P.associator Q S).inv := by
ext _ _ ⟨_, ⟨_, _, _⟩, _⟩
rfl
variable {P} in
@[simp]
lemma whiskerRight_comp {Q : Profunctor.{max u w} C D} (f : P ⟶ Q)
(R : Profunctor.{max u w} D E) (S : Profunctor.{max u w} E F) :
whiskerRight (R.comp S) f =
(P.associator R S).inv ≫ whiskerRight S (whiskerRight R f) ≫ (Q.associator R S).hom := by
ext _ _ ⟨_, _, _, _, _⟩
rfl
variable {Q} in
@[simp]
lemma whisker_assoc {R : Profunctor.{max u w} D E}
(f : Q ⟶ R) (S : Profunctor.{max u w} E F) :
whiskerRight S (P.whiskerLeft f) =
(P.associator Q S).hom ≫ P.whiskerLeft (whiskerRight S f) ≫ (P.associator R S).inv := by
ext _ _ ⟨_, ⟨_, _, _⟩, _⟩
rfl
end Associator
end Composition
end Profunctor
end CategoryTheory
¤ Dauer der Verarbeitung: 0.11 Sekunden
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|
|
|
|
|