Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 6e3516d

Browse files
kim-emmergify[bot]
authored andcommitted
feat(category_theory/monad): monadic adjunctions (#1176)
* feat(category_theory/limits): equivalences create limits * equivalence lemma * feat(category_theory/monad): monadic adjunctions * move file * fix * add @[simp] * use right_adjoint_preserves_limits * fix * fix * undo weird changes in topology files * formatting * do colimits too * missing proofs * convert monad to a typeclass decorating a functor * changing name * cleaning up * oops * minor
1 parent 9505e5b commit 6e3516d

File tree

9 files changed

+495
-1
lines changed

9 files changed

+495
-1
lines changed

src/category_theory/adjunction/basic.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class is_right_adjoint (right : D ⥤ C) :=
3737
(left : C ⥤ D)
3838
(adj : left ⊣ right)
3939

40+
def left_adjoint (R : D ⥤ C) [is_right_adjoint R] : C ⥤ D :=
41+
is_right_adjoint.left R
42+
def right_adjoint (L : C ⥤ D) [is_left_adjoint L] : D ⥤ C :=
43+
is_left_adjoint.right L
44+
4045
namespace adjunction
4146

4247
restate_axiom hom_equiv_unit'
@@ -113,6 +118,10 @@ by { rw [←assoc], dsimp, simp }
113118

114119
end
115120

121+
end adjunction
122+
123+
namespace adjunction
124+
116125
structure core_hom_equiv (F : C ⥤ D) (G : D ⥤ C) :=
117126
(hom_equiv : Π (X Y), (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y))
118127
(hom_equiv_naturality_left_symm' : Π {X' X Y} (f : X' ⟶ X) (g : X ⟶ G.obj Y),
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
-- Copyright (c) 2019 Scott Morrison. All rights reserved.
2+
-- Released under Apache 2.0 license as described in the file LICENSE.
3+
-- Authors: Scott Morrison
4+
5+
import category_theory.adjunction.basic
6+
import category_theory.yoneda
7+
8+
open category_theory
9+
10+
namespace category_theory
11+
universes v₁ v₂ u₁ u₂
12+
13+
open category
14+
open opposite
15+
16+
variables {C : Type u₁} [𝒞 : category.{v₁} C]
17+
variables {D : Type u₂} [𝒟 : category.{v₂} D]
18+
include 𝒞 𝒟
19+
variables {L : C ⥤ D} {R : D ⥤ C} (h : L ⊣ R)
20+
21+
-- Lemma 4.5.13 from Riehl
22+
-- Proof in https://stacks.math.columbia.edu/tag/0036
23+
-- or at https://math.stackexchange.com/a/2727177
24+
instance unit_is_iso_of_L_fully_faithful [full L] [faithful L] : is_iso (adjunction.unit h) :=
25+
@nat_iso.is_iso_of_is_iso_app _ _ _ _ _ _ (adjunction.unit h) $ λ X,
26+
@yoneda.is_iso _ _ _ _ ((adjunction.unit h).app X)
27+
{ inv := { app := λ Y f, L.preimage ((h.hom_equiv (unop Y) (L.obj X)).symm f) },
28+
inv_hom_id' :=
29+
begin
30+
ext1, ext1, dsimp,
31+
simp only [adjunction.hom_equiv_counit, preimage_comp, preimage_map, category.assoc],
32+
rw ←h.unit_naturality,
33+
simp,
34+
end,
35+
hom_inv_id' :=
36+
begin
37+
ext1, ext1, dsimp,
38+
apply L.injectivity,
39+
simp,
40+
end }.
41+
42+
instance counit_is_iso_of_R_fully_faithful [full R] [faithful R] : is_iso (adjunction.counit h) :=
43+
@nat_iso.is_iso_of_is_iso_app _ _ _ _ _ _ (adjunction.counit h) $ λ X,
44+
@is_iso_of_op _ _ _ _ _ $
45+
@coyoneda.is_iso _ _ _ _ ((adjunction.counit h).app X).op
46+
{ inv := { app := λ Y f, R.preimage ((h.hom_equiv (R.obj X) Y) f) },
47+
inv_hom_id' :=
48+
begin
49+
ext1, ext1, dsimp,
50+
simp only [adjunction.hom_equiv_unit, preimage_comp, preimage_map],
51+
rw ←h.counit_naturality,
52+
simp,
53+
end,
54+
hom_inv_id' :=
55+
begin
56+
ext1, ext1, dsimp,
57+
apply R.injectivity,
58+
simp,
59+
end }
60+
61+
-- TODO also prove the converses?
62+
-- def L_full_of_unit_is_iso [is_iso (adjunction.unit h)] : full L := sorry
63+
-- def L_faithful_of_unit_is_iso [is_iso (adjunction.unit h)] : faithful L := sorry
64+
-- def R_full_of_counit_is_iso [is_iso (adjunction.counit h)] : full R := sorry
65+
-- def R_faithful_of_counit_is_iso [is_iso (adjunction.counit h)] : faithful R := sorry
66+
67+
-- TODO also do the statements from Riehl 4.5.13 for full and faithful separately?
68+
69+
70+
end category_theory
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/-
2+
Copyright (c) 2019 Scott Morrison. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Scott Morrison
5+
-/
6+
import category_theory.monad.algebra
7+
import category_theory.adjunction.fully_faithful
8+
9+
namespace category_theory
10+
open category
11+
12+
universes v₁ v₂ u₁ u₂ -- declare the `v`'s first; see `category_theory.category` for an explanation
13+
14+
variables {C : Type u₁} [𝒞 : category.{v₁} C] {D : Type u₂} [𝒟 : category.{v₂} D]
15+
include 𝒞 𝒟
16+
variables (R : D ⥤ C)
17+
18+
namespace adjunction
19+
20+
instance monad (R : D ⥤ C) [is_right_adjoint R] : monad.{v₁} ((left_adjoint R) ⋙ R) :=
21+
let L := left_adjoint R in
22+
let h := (is_right_adjoint.adj R) in
23+
{ η := h.unit,
24+
μ := whisker_right (whisker_left L h.counit) R,
25+
assoc' := λ X, by { dsimp, erw [←R.map_comp, h.counit.naturality, R.map_comp], refl },
26+
right_unit' := λ X, by { dsimp, rw [←R.map_comp], simp }, }
27+
28+
@[simp] lemma monad_η_app [is_right_adjoint R] (X) : (η_ ((left_adjoint R) ⋙ R)).app X = (is_right_adjoint.adj R).unit.app X := rfl
29+
@[simp] lemma monad_μ_app [is_right_adjoint R] (X) : (μ_ ((left_adjoint R) ⋙ R)).app X = R.map ((is_right_adjoint.adj R).counit.app ((left_adjoint R).obj X)) := rfl
30+
31+
end adjunction
32+
33+
namespace monad
34+
35+
def comparison [is_right_adjoint R] : D ⥤ algebra ((left_adjoint R) ⋙ R) :=
36+
let h := (is_right_adjoint.adj R) in
37+
{ obj := λ X,
38+
{ A := R.obj X,
39+
a := R.map (h.counit.app X),
40+
assoc' := by { dsimp, conv { to_rhs, erw [←R.map_comp, h.counit.naturality, R.map_comp], }, refl } },
41+
map := λ X Y f,
42+
{ f := R.map f,
43+
h' := begin dsimp, erw [←R.map_comp, h.counit.naturality, R.map_comp, functor.id_map], refl, end } }.
44+
45+
@[simp] lemma comparison_map_f [is_right_adjoint R] {X Y} (f : X ⟶ Y) : ((comparison R).map f).f = R.map f := rfl
46+
@[simp] lemma comparison_obj_a [is_right_adjoint R] (X) : ((comparison R).obj X).a = R.map ((is_right_adjoint.adj R).counit.app X) := rfl
47+
48+
def comparison_forget [is_right_adjoint R] : comparison R ⋙ forget ((left_adjoint R) ⋙ R) ≅ R :=
49+
{ hom := { app := λ X, 𝟙 _, },
50+
inv := { app := λ X, 𝟙 _, } }
51+
52+
end monad
53+
54+
class reflective (R : D ⥤ C) extends is_right_adjoint R, full R, faithful R.
55+
56+
instance μ_iso_of_reflective [reflective R] : is_iso (μ_ ((left_adjoint R) ⋙ R)) :=
57+
by { dsimp [adjunction.monad], apply_instance }
58+
59+
class monadic_right_adjoint (R : D ⥤ C) extends is_right_adjoint R :=
60+
(eqv : is_equivalence (monad.comparison R))
61+
62+
attribute [instance] monadic_right_adjoint.eqv
63+
64+
-- PROJECT prove Beck's monadicity theorem, e.g. from Section 5.5 of Riehl
65+
66+
namespace reflective
67+
68+
lemma comparison_ess_surj_aux [reflective R] (X : monad.algebra ((left_adjoint R) ⋙ R)) :
69+
((is_right_adjoint.adj R).unit).app (R.obj ((left_adjoint R).obj (X.A))) = R.map ((left_adjoint R).map ((is_right_adjoint.adj R).unit.app X.A)) :=
70+
begin
71+
-- both are left inverses to μ_X.
72+
apply (cancel_mono ((μ_ ((left_adjoint R) ⋙ R)).app _)).1,
73+
{ dsimp, erw [adjunction.right_triangle_components, ←R.map_comp], simp, },
74+
{ apply is_iso.mono_of_iso _,
75+
apply nat_iso.is_iso_app_of_is_iso }
76+
end
77+
78+
instance [reflective R] (X : monad.algebra ((left_adjoint R) ⋙ R)) :
79+
is_iso ((is_right_adjoint.adj R).unit.app X.A) :=
80+
let L := left_adjoint R in
81+
let h := (is_right_adjoint.adj R) in
82+
{ inv := X.a,
83+
hom_inv_id' := X.unit,
84+
inv_hom_id' :=
85+
begin
86+
dsimp,
87+
erw [h.unit.naturality, comparison_ess_surj_aux,
88+
←R.map_comp, ←L.map_comp, X.unit, L.map_id, R.map_id],
89+
refl
90+
end }
91+
92+
instance comparison_ess_surj [reflective R]: ess_surj (monad.comparison R) :=
93+
let L := left_adjoint R in
94+
let h := (is_right_adjoint.adj R) in
95+
{ obj_preimage := λ X, L.obj X.A,
96+
iso' := λ X,
97+
{ hom :=
98+
{ f := (as_iso (h.unit.app X.A)).inv,
99+
h' :=
100+
begin
101+
dsimp,
102+
apply (cancel_epi (R.map (L.map ((h.unit).app (X.A))))).1,
103+
rw [is_iso.hom_inv_id_assoc, ←category.assoc, ←R.map_comp,adjunction.left_triangle_components],
104+
erw [functor.map_id, category.id_comp],
105+
apply (cancel_epi ((h.unit).app (X.A))).1,
106+
rw is_iso.hom_inv_id,
107+
exact X.unit,
108+
end },
109+
inv :=
110+
{ f := (as_iso (h.unit.app X.A)).hom,
111+
h' :=
112+
begin
113+
dsimp,
114+
erw [←R.map_comp, adjunction.left_triangle_components, R.map_id],
115+
apply (cancel_epi ((h.unit).app (X.A))).1,
116+
conv { to_rhs, erw [←category.assoc, X.unit] },
117+
erw [comp_id, id_comp],
118+
end },
119+
hom_inv_id' := by { ext, exact (as_iso (h.unit.app X.A)).inv_hom_id, },
120+
inv_hom_id' := by { ext, exact (as_iso (h.unit.app X.A)).hom_inv_id, }, } }
121+
122+
instance comparison_full [full R] [is_right_adjoint R] : full (monad.comparison R) :=
123+
{ preimage := λ X Y f, R.preimage f.f }
124+
instance comparison_faithful [faithful R] [is_right_adjoint R] : faithful (monad.comparison R) :=
125+
{ injectivity' := λ X Y f g w, by { have w' := (congr_arg monad.algebra.hom.f w), exact R.injectivity w' } }
126+
127+
end reflective
128+
129+
-- Proposition 5.3.3 of Riehl
130+
instance monadic_of_reflective [reflective R] : monadic_right_adjoint R :=
131+
{ eqv := equivalence.equivalence_of_fully_faithfully_ess_surj _ }
132+
133+
end category_theory
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/-
2+
Copyright (c) 2019 Scott Morrison. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Scott Morrison
5+
-/
6+
import category_theory.monad.basic
7+
import category_theory.adjunction.basic
8+
9+
namespace category_theory
10+
open category
11+
12+
universes v₁ u₁ -- declare the `v`'s first; see `category_theory.category` for an explanation
13+
14+
variables {C : Type u₁} [𝒞 : category.{v₁} C]
15+
include 𝒞
16+
17+
namespace monad
18+
19+
structure algebra (T : C ⥤ C) [monad.{v₁} T] : Type (max u₁ v₁) :=
20+
(A : C)
21+
(a : T.obj A ⟶ A)
22+
(unit' : (η_ T).app A ≫ a = 𝟙 A . obviously)
23+
(assoc' : ((μ_ T).app A ≫ a) = (T.map a ≫ a) . obviously)
24+
25+
restate_axiom algebra.unit'
26+
restate_axiom algebra.assoc'
27+
28+
namespace algebra
29+
variables {T : C ⥤ C} [monad.{v₁} T]
30+
31+
structure hom (A B : algebra T) :=
32+
(f : A.A ⟶ B.A)
33+
(h' : T.map f ≫ B.a = A.a ≫ f . obviously)
34+
35+
restate_axiom hom.h'
36+
attribute [simp] hom.h
37+
38+
namespace hom
39+
@[extensionality] lemma ext {A B : algebra T} (f g : hom A B) (w : f.f = g.f) : f = g :=
40+
by { cases f, cases g, congr, assumption }
41+
42+
def id (A : algebra T) : hom A A :=
43+
{ f := 𝟙 A.A }
44+
45+
@[simp] lemma id_f (A : algebra T) : (id A).f = 𝟙 A.A := rfl
46+
47+
def comp {P Q R : algebra T} (f : hom P Q) (g : hom Q R) : hom P R :=
48+
{ f := f.f ≫ g.f,
49+
h' := by rw [functor.map_comp, category.assoc, g.h, ←category.assoc, f.h, category.assoc] }
50+
51+
@[simp] lemma comp_f {P Q R : algebra T} (f : hom P Q) (g : hom Q R) : (comp f g).f = f.f ≫ g.f := rfl
52+
end hom
53+
54+
instance EilenbergMoore : category (algebra T) :=
55+
{ hom := hom,
56+
id := hom.id,
57+
comp := @hom.comp _ _ _ _ }
58+
59+
@[simp] lemma id_f (P : algebra T) : hom.f (𝟙 P) = 𝟙 P.A := rfl
60+
@[simp] lemma comp_f {P Q R : algebra T} (f : P ⟶ Q) (g : Q ⟶ R) : (f ≫ g).f = f.f ≫ g.f := rfl
61+
62+
end algebra
63+
64+
variables (T : C ⥤ C) [monad.{v₁} T]
65+
66+
def forget : algebra T ⥤ C :=
67+
{ obj := λ A, A.A,
68+
map := λ A B f, f.f }
69+
70+
@[simp] lemma forget_map {X Y : algebra T} (f : X ⟶ Y) : (forget T).map f = f.f := rfl
71+
72+
def free : C ⥤ algebra T :=
73+
{ obj := λ X,
74+
{ A := T.obj X,
75+
a := (μ_ T).app X,
76+
assoc' := (monad.assoc T _).symm },
77+
map := λ X Y f,
78+
{ f := T.map f,
79+
h' := by erw (μ_ T).naturality } }
80+
81+
@[simp] lemma free_obj_a (X) : ((free T).obj X).a = (μ_ T).app X := rfl
82+
@[simp] lemma free_map_f {X Y : C} (f : X ⟶ Y) : ((free T).map f).f = T.map f := rfl
83+
84+
def adj : free T ⊣ forget T :=
85+
adjunction.mk_of_hom_equiv
86+
{ hom_equiv := λ X Y,
87+
{ to_fun := λ f, (η_ T).app X ≫ f.f,
88+
inv_fun := λ f,
89+
{ f := T.map f ≫ Y.a,
90+
h' :=
91+
begin
92+
dsimp, simp,
93+
conv { to_rhs, rw [←category.assoc, ←(μ_ T).naturality, category.assoc], erw algebra.assoc },
94+
refl,
95+
end },
96+
left_inv := λ f,
97+
begin
98+
ext1, dsimp,
99+
simp only [free_obj_a, functor.map_comp, algebra.hom.h, category.assoc],
100+
erw [←category.assoc, monad.right_unit, id_comp],
101+
end,
102+
right_inv := λ f,
103+
begin
104+
dsimp,
105+
erw [←category.assoc, ←(η_ T).naturality, functor.id_map,
106+
category.assoc, Y.unit, comp_id],
107+
end }}
108+
109+
end monad
110+
111+
end category_theory
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/-
2+
Copyright (c) 2019 Scott Morrison. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Scott Morrison
5+
-/
6+
import category_theory.functor_category
7+
8+
namespace category_theory
9+
open category
10+
11+
universes v₁ u₁ -- declare the `v`'s first; see `category_theory.category` for an explanation
12+
13+
variables {C : Type u₁} [𝒞 : category.{v₁} C]
14+
include 𝒞
15+
16+
class monad (T : C ⥤ C) :=
17+
(η : functor.id _ ⟶ T)
18+
(μ : T ⋙ T ⟶ T)
19+
(assoc' : ∀ X : C, T.map (nat_trans.app μ X) ≫ μ.app _ = μ.app (T.obj X) ≫ μ.app _ . obviously)
20+
(left_unit' : ∀ X : C, η.app (T.obj X) ≫ μ.app _ = 𝟙 _ . obviously)
21+
(right_unit' : ∀ X : C, T.map (η.app X) ≫ μ.app _ = 𝟙 _ . obviously)
22+
23+
restate_axiom monad.assoc'
24+
restate_axiom monad.left_unit'
25+
restate_axiom monad.right_unit'
26+
attribute [simp] monad.left_unit monad.right_unit
27+
28+
notation `η_` := monad.η
29+
notation `μ_` := monad.μ
30+
31+
end category_theory
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import category_theory.monad.limits

0 commit comments

Comments
 (0)