0
|
1 module nat where
|
|
2
|
|
3 -- Monad
|
|
4 -- Category A
|
|
5 -- A = Category
|
|
6 -- Functor T : A -> A
|
|
7 --T(a) = t(a)
|
|
8 --T(f) = tf(f)
|
|
9
|
2
|
10 open import Category -- https://github.com/konn/category-agda
|
0
|
11 open import Level
|
|
12 open Functor
|
|
13
|
1
|
14 --T(g f) = T(g) T(f)
|
|
15
|
0
|
16 Lemma1 : {c₁ c₂ l : Level} {A : Category c₁ c₂ l} (T : Functor A A) -> {a b c : Obj A} {g : Hom A b c} { f : Hom A a b }
|
|
17 -> A [ ( FMap T (A [ g o f ] )) ≈ (A [ FMap T g o FMap T f ]) ]
|
|
18 Lemma1 = \t -> IsFunctor.distr ( isFunctor t )
|
|
19
|
|
20 -- F(f)
|
|
21 -- F(a) ----> F(b)
|
|
22 -- | |
|
|
23 -- |t(a) |t(b) G(f)t(a) = t(b)F(f)
|
|
24 -- | |
|
|
25 -- v v
|
|
26 -- G(a) ----> G(b)
|
|
27 -- G(f)
|
|
28
|
7
|
29 record IsNTrans {c₁ c₂ ℓ c₁′ c₂′ ℓ′ : Level} (D : Category c₁ c₂ ℓ) (C : Category c₁′ c₂′ ℓ′)
|
0
|
30 ( F G : Functor D C )
|
7
|
31 (Trans : (A : Obj D) → Hom C (FObj F A) (FObj G A))
|
0
|
32 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ ⊔ c₁′ ⊔ c₂′ ⊔ ℓ′)) where
|
|
33 field
|
|
34 naturality : {a b : Obj D} {f : Hom D a b}
|
7
|
35 → C [ C [ ( FMap G f ) o ( Trans a ) ] ≈ C [ (Trans b ) o (FMap F f) ] ]
|
0
|
36 -- uniqness : {d : Obj D}
|
7
|
37 -- → C [ Trans d ≈ Trans d ]
|
0
|
38
|
|
39
|
7
|
40 record NTrans {c₁ c₂ ℓ c₁′ c₂′ ℓ′ : Level} (domain : Category c₁ c₂ ℓ) (codomain : Category c₁′ c₂′ ℓ′) (F G : Functor domain codomain )
|
0
|
41 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ ⊔ c₁′ ⊔ c₂′ ⊔ ℓ′)) where
|
|
42 field
|
7
|
43 Trans : (A : Obj domain) → Hom codomain (FObj F A) (FObj G A)
|
|
44 isNTrans : IsNTrans domain codomain F G Trans
|
0
|
45
|
7
|
46 open NTrans
|
1
|
47 Lemma2 : {c₁ c₂ l : Level} {A : Category c₁ c₂ l} {F G : Functor A A}
|
7
|
48 -> (μ : NTrans A A F G) -> {a b : Obj A} { f : Hom A a b }
|
|
49 -> A [ A [ FMap G f o Trans μ a ] ≈ A [ Trans μ b o FMap F f ] ]
|
|
50 Lemma2 = \n -> IsNTrans.naturality ( isNTrans n )
|
0
|
51
|
|
52 open import Category.Cat
|
|
53
|
|
54 -- η : 1_A -> T
|
|
55 -- μ : TT -> T
|
|
56 -- μ(a)η(T(a)) = a
|
|
57 -- μ(a)T(η(a)) = a
|
|
58 -- μ(a)(μ(T(a))) = μ(a)T(μ(a))
|
|
59
|
1
|
60 record IsMonad {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ)
|
|
61 ( T : Functor A A )
|
7
|
62 ( η : NTrans A A identityFunctor T )
|
|
63 ( μ : NTrans A A (T ○ T) T)
|
1
|
64 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where
|
|
65 field
|
7
|
66 assoc : {a : Obj A} -> A [ A [ Trans μ a o Trans μ ( FObj T a ) ] ≈ A [ Trans μ a o FMap T (Trans μ a) ] ]
|
|
67 unity1 : {a : Obj A} -> A [ A [ Trans μ a o Trans η ( FObj T a ) ] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
|
68 unity2 : {a : Obj A} -> A [ A [ Trans μ a o (FMap T (Trans η a ))] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
0
|
69
|
7
|
70 record Monad {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) (T : Functor A A) (η : NTrans A A identityFunctor T) (μ : NTrans A A (T ○ T) T)
|
1
|
71 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where
|
7
|
72 eta : NTrans A A identityFunctor T
|
6
|
73 eta = η
|
7
|
74 mu : NTrans A A (T ○ T) T
|
6
|
75 mu = μ
|
1
|
76 field
|
|
77 isMonad : IsMonad A T η μ
|
0
|
78
|
2
|
79 open Monad
|
|
80 Lemma3 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
81 { T : Functor A A }
|
7
|
82 { η : NTrans A A identityFunctor T }
|
|
83 { μ : NTrans A A (T ○ T) T }
|
2
|
84 { a : Obj A } ->
|
|
85 ( M : Monad A T η μ )
|
7
|
86 -> A [ A [ Trans μ a o Trans μ ( FObj T a ) ] ≈ A [ Trans μ a o FMap T (Trans μ a) ] ]
|
2
|
87 Lemma3 = \m -> IsMonad.assoc ( isMonad m )
|
|
88
|
|
89
|
|
90 Lemma4 : {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) {a b : Obj A } { f : Hom A a b}
|
|
91 -> A [ A [ Id {_} {_} {_} {A} b o f ] ≈ f ]
|
|
92 Lemma4 = \a -> IsCategory.identityL ( Category.isCategory a )
|
0
|
93
|
3
|
94 Lemma5 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
95 { T : Functor A A }
|
7
|
96 { η : NTrans A A identityFunctor T }
|
|
97 { μ : NTrans A A (T ○ T) T }
|
3
|
98 { a : Obj A } ->
|
|
99 ( M : Monad A T η μ )
|
7
|
100 -> A [ A [ Trans μ a o Trans η ( FObj T a ) ] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
3
|
101 Lemma5 = \m -> IsMonad.unity1 ( isMonad m )
|
|
102
|
|
103 Lemma6 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
104 { T : Functor A A }
|
7
|
105 { η : NTrans A A identityFunctor T }
|
|
106 { μ : NTrans A A (T ○ T) T }
|
3
|
107 { a : Obj A } ->
|
|
108 ( M : Monad A T η μ )
|
7
|
109 -> A [ A [ Trans μ a o (FMap T (Trans η a )) ] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
3
|
110 Lemma6 = \m -> IsMonad.unity2 ( isMonad m )
|
|
111
|
|
112 -- T = M x A
|
0
|
113 -- nat of η
|
|
114 -- g ○ f = μ(c) T(g) f
|
|
115 -- h ○ (g ○ f) = (h ○ g) ○ f
|
|
116 -- η(b) ○ f = f
|
|
117 -- f ○ η(a) = f
|
|
118
|
4
|
119 record Kleisli { c₁ c₂ ℓ : Level} ( A : Category c₁ c₂ ℓ )
|
|
120 ( T : Functor A A )
|
7
|
121 ( η : NTrans A A identityFunctor T )
|
|
122 ( μ : NTrans A A (T ○ T) T )
|
4
|
123 ( M : Monad A T η μ ) : Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where
|
5
|
124 monad : Monad A T η μ
|
|
125 monad = M
|
4
|
126 join : { a b : Obj A } -> ( c : Obj A ) ->
|
|
127 ( Hom A b ( FObj T c )) -> ( Hom A a ( FObj T b)) -> Hom A a ( FObj T c )
|
7
|
128 join c g f = A [ Trans μ c o A [ FMap T g o f ] ]
|
|
129
|
|
130 open import Relation.Binary renaming (Trans to Trans1 )
|
|
131 open import Relation.Binary.Core renaming (Trans to Trans1 )
|
8
|
132 open import Relation.Binary.PropositionalEquality using (_≡_; refl)
|
7
|
133
|
|
134 module ≈-Reasoning where
|
|
135
|
|
136 -- The code in Relation.Binary.EqReasoning cannot handle
|
|
137 -- heterogeneous equalities, hence the code duplication here.
|
|
138
|
8
|
139 refl-hom : {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) {a b : Obj A }
|
|
140 { x y z : Hom A a b } →
|
|
141 A [ x ≈ x ]
|
|
142 refl-hom = \a -> IsEquivalence.refl (IsCategory.isEquivalence ( Category.isCategory a ))
|
|
143
|
|
144 trans-hom : {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) {a b : Obj A }
|
7
|
145 { x y z : Hom A a b } →
|
|
146 A [ x ≈ y ] → A [ y ≈ z ] → A [ x ≈ z ]
|
9
|
147 trans-hom a b c = ( IsEquivalence.trans (IsCategory.isEquivalence ( Category.isCategory a ))) b c
|
5
|
148
|
9
|
149 infixr 2 _∎_
|
|
150 infixr 2 _≈⟨_!_⟩_
|
7
|
151 infix 1 begin_
|
|
152
|
|
153 data IsRelatedTo {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) {a b : Obj A } ( x y : Hom A a b ) :
|
|
154 Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where
|
|
155 relTo : (x≈y : A [ x ≈ y ] ) → IsRelatedTo A x y
|
|
156
|
|
157 begin_ : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ} {a b : Obj A } { x y : Hom A a b} →
|
|
158 IsRelatedTo A x y → A [ x ≈ y ]
|
|
159 begin relTo x≈y = x≈y
|
|
160
|
9
|
161 _≈⟨_!_⟩_ : {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) -> {a b : Obj A }
|
|
162 ( x : Hom A a b ) → { y z : Hom A a b } →
|
|
163 A [ x ≈ y ] → IsRelatedTo A y z → IsRelatedTo A x z
|
|
164 a ≈⟨ _ ! x≈y ⟩ relTo y≈z = relTo ( trans-hom a x≈y y≈z )
|
8
|
165
|
9
|
166 _∎_ : {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) {a b : Obj A } (x : Hom A a b) → IsRelatedTo A x x
|
|
167 a ∎ _ = relTo ( refl-hom a )
|
4
|
168
|
|
169 open Kleisli
|
7
|
170 Lemma7 : {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) ->
|
3
|
171 { T : Functor A A }
|
7
|
172 { η : NTrans A A identityFunctor T }
|
|
173 { μ : NTrans A A (T ○ T) T }
|
5
|
174 { a b : Obj A }
|
|
175 { f : Hom A a ( FObj T b) }
|
|
176 { M : Monad A T η μ }
|
|
177 ( K : Kleisli A T η μ M)
|
7
|
178 -> A [ join K b (Trans η b) f ≈ f ]
|
|
179 Lemma7 c k = {!!}
|
|
180
|
|
181
|
|
182
|
5
|
183
|
|
184 Lemma8 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
185 { T : Functor A A }
|
7
|
186 { η : NTrans A A identityFunctor T }
|
|
187 { μ : NTrans A A (T ○ T) T }
|
4
|
188 { a b : Obj A }
|
|
189 { f : Hom A a ( FObj T b) }
|
|
190 { M : Monad A T η μ }
|
|
191 ( K : Kleisli A T η μ M)
|
7
|
192 -> A [ join K b f (Trans η a) ≈ f ]
|
|
193 Lemma8 k = {!!}
|
5
|
194
|
|
195 Lemma9 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
196 { T : Functor A A }
|
7
|
197 { η : NTrans A A identityFunctor T }
|
|
198 { μ : NTrans A A (T ○ T) T }
|
5
|
199 { a b c d : Obj A }
|
|
200 { f : Hom A a ( FObj T b) }
|
|
201 { g : Hom A b ( FObj T c) }
|
|
202 { h : Hom A c ( FObj T d) }
|
|
203 { M : Monad A T η μ }
|
|
204 ( K : Kleisli A T η μ M)
|
|
205 -> A [ join K d h (join K c g f) ≈ join K d ( join K d h g) f ]
|
6
|
206 Lemma9 k = {!!}
|
5
|
207
|
4
|
208
|
3
|
209
|
|
210
|
|
211
|
|
212 -- Kleisli :
|
|
213 -- Kleisli = record { Hom =
|
|
214 -- ; Hom = _⟶_
|
|
215 -- ; Id = IdProd
|
|
216 -- ; _o_ = _∘_
|
|
217 -- ; _≈_ = _≈_
|
|
218 -- ; isCategory = record { isEquivalence = record { refl = λ {φ} → ≈-refl {φ = φ}
|
|
219 -- ; sym = λ {φ ψ} → ≈-symm {φ = φ} {ψ}
|
|
220 -- ; trans = λ {φ ψ σ} → ≈-trans {φ = φ} {ψ} {σ}
|
|
221 -- }
|
|
222 -- ; identityL = identityL
|
|
223 -- ; identityR = identityR
|
|
224 -- ; o-resp-≈ = o-resp-≈
|
|
225 -- ; associative = associative
|
|
226 -- }
|
|
227 -- }
|