/
Functor.lagda.md
277 lines (230 loc) · 8.27 KB
/
Functor.lagda.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!--
```agda
open import Cat.Functor.Naturality
open import Cat.Monoidal.Diagonals
open import Cat.Instances.Product
open import Cat.Monoidal.Braided
open import Cat.Monoidal.Base
open import Cat.Prelude
import Cat.Functor.Reasoning
import Cat.Reasoning
```
-->
```agda
module Cat.Monoidal.Functor {oc ℓc od ℓd}
{C : Precategory oc ℓc} (Cᵐ : Monoidal-category C)
{D : Precategory od ℓd} (Dᵐ : Monoidal-category D)
where
```
# Monoidal functors {defines="monoidal-functor lax-monoidal-functor oplax-monoidal-functor strong-monoidal-functor"}
<!--
```agda
open Cat.Reasoning D
private
module C = Monoidal-category Cᵐ
module D = Monoidal-category Dᵐ
```
-->
Categorifying the fact that a morphism between [[monoids]] is expected
to preserve the unit and multiplication, a [[functor]] between [[monoidal
categories]] should come *equipped* with [[natural isomorphisms]]
$$
\begin{align*}
FA \otimes FB &\cong F(A \otimes B) \\
1 &\cong F1
\end{align*}
$$
witnessing that it preserves the tensor product and unit.
However, just like for [[lax functors]] between [[bicategories]], we have
the option of requiring only a natural *transformation* in one direction
or the other.
If we choose the forward direction $FA \otimes FB \to F(A \otimes B)$,
we obtain the notion of a **lax monoidal functor**; choosing the
opposite direction instead would yield an **oplax monoidal functor**.
We begin by defining the *structure* of a lax monoidal functor on a given
functor $F$: this consists of the aforementioned morphisms, as well
as some coherence conditions similar to the ones for a [[lax functor]].
```agda
record Lax-monoidal-functor-on (F : Functor C D) : Type (oc ⊔ ℓc ⊔ od ⊔ ℓd) where
private module F = Cat.Functor.Reasoning F
field
ε : Hom D.Unit (F.₀ C.Unit)
F-mult : D.-⊗- F∘ (F F× F) => F F∘ C.-⊗-
module φ = _=>_ F-mult
φ : ∀ {A B} → Hom (F.₀ A D.⊗ F.₀ B) (F.₀ (A C.⊗ B))
φ = φ.η _
field
F-α→ : ∀ {A B C}
→ F.₁ (C.α→ A B C) ∘ φ ∘ (φ D.⊗₁ id) ≡ φ ∘ (id D.⊗₁ φ) ∘ D.α→ _ _ _
F-λ← : ∀ {A} → F.₁ (C.λ← {A}) ∘ φ ∘ (ε D.⊗₁ id) ≡ D.λ←
F-ρ← : ∀ {A} → F.₁ (C.ρ← {A}) ∘ φ ∘ (id D.⊗₁ ε) ≡ D.ρ←
```
<!--
```agda
F-α← : ∀ {A B C}
→ F.₁ (C.α← A B C) ∘ φ ∘ (id D.⊗₁ φ) ≡ φ ∘ (φ D.⊗₁ id) ∘ D.α← _ _ _
F-α← = swizzle (sym (F-α→ ∙ assoc _ _ _)) (D.α≅ .invl) (F.F-map-iso C.α≅ .invr)
∙ sym (assoc _ _ _)
private unquoteDecl eqv = declare-record-iso eqv (quote Lax-monoidal-functor-on)
Lax-monoidal-functor-on-path
: ∀ {F} {l l' : Lax-monoidal-functor-on F}
→ l .Lax-monoidal-functor-on.ε ≡ l' .Lax-monoidal-functor-on.ε
→ l .Lax-monoidal-functor-on.F-mult ≡ l' .Lax-monoidal-functor-on.F-mult
→ l ≡ l'
Lax-monoidal-functor-on-path p q = Iso.injective eqv
(Σ-pathp p (Σ-prop-pathp (λ _ _ → hlevel 1) q))
```
-->
```agda
Lax-monoidal-functor : Type (oc ⊔ ℓc ⊔ od ⊔ ℓd)
Lax-monoidal-functor = Σ (Functor C D) Lax-monoidal-functor-on
```
A **monoidal functor**, or **strong monoidal functor**[^strong], is
then simply a lax monoidal functor whose structure morphisms are
[[invertible]].
[^strong]: Not to be confused with a [[strong|strong functor]] monoidal
functor, in the sense of a monoidal functor equipped with a [[strength]].
```agda
record Monoidal-functor-on (F : Functor C D) : Type (oc ⊔ ℓc ⊔ od ⊔ ℓd) where
field
lax : Lax-monoidal-functor-on F
open Lax-monoidal-functor-on lax public
field
ε-inv : is-invertible ε
F-mult-inv : is-invertibleⁿ F-mult
Monoidal-functor : Type (oc ⊔ ℓc ⊔ od ⊔ ℓd)
Monoidal-functor = Σ (Functor C D) Monoidal-functor-on
```
## Braided and symmetric monoidal functors {defines="braided-monoidal-functor symmetric-monoidal-functor"}
A monoidal functor between [[braided monoidal categories]] can additionally
preserve the braiding in the sense that the following diagram commutes,
yielding the notion of a **braided monoidal functor**.
~~~{.quiver}
\[\begin{tikzcd}
{FA \otimes FB} & {F(A \otimes B)} \\
{FB \otimes FA} & {F(B \otimes A)}
\arrow["\varphi", from=1-1, to=1-2]
\arrow["\beta"', from=1-1, to=2-1]
\arrow["\varphi"', from=2-1, to=2-2]
\arrow["F\beta", from=1-2, to=2-2]
\end{tikzcd}\]
~~~
<!--
```agda
module _
(Cᵇ : Braided-monoidal Cᵐ)
(Dᵇ : Braided-monoidal Dᵐ)
where
module Cᵇ = Braided-monoidal Cᵇ
module Dᵇ = Braided-monoidal Dᵇ
```
-->
```agda
is-braided-functor : Lax-monoidal-functor → Type (oc ⊔ ℓd)
is-braided-functor (F , lax) = ∀ {A B} → φ ∘ Dᵇ.β→ ≡ F.₁ Cᵇ.β→ ∘ φ {A} {B}
where
module F = Functor F
open Lax-monoidal-functor-on lax
```
A **symmetric monoidal functor** between [[symmetric monoidal categories]]
is just a braided monoidal functor, since there is no extra structure to
preserve.
<!--
```agda
module _
(Cˢ : Symmetric-monoidal Cᵐ)
(Dˢ : Symmetric-monoidal Dᵐ)
where
open Symmetric-monoidal Cˢ using (Cᵇ)
open Symmetric-monoidal Dˢ using () renaming (Cᵇ to Dᵇ)
```
-->
```agda
is-symmetric-functor : Lax-monoidal-functor → Type (oc ⊔ ℓd)
is-symmetric-functor = is-braided-functor Cᵇ Dᵇ
```
## Diagonal monoidal functors {defines="diagonal-monoidal-functor idempotent-monoidal-functor"}
If the source and target categories are equipped with [[diagonal
morphisms|monoidal category with diagonals]], then a **diagonal
monoidal functor**, or **idempotent monoidal functor** is a monoidal
functor that makes the following diagram commute:
~~~{.quiver}
\[\begin{tikzcd}
FA \\
{FA \otimes FA} & {F(A \otimes A)}
\arrow["\delta"', from=1-1, to=2-1]
\arrow["\varphi"', from=2-1, to=2-2]
\arrow["F\delta", from=1-1, to=2-2]
\end{tikzcd}\]
~~~
<!--
```agda
module _
(Cᵈ : Diagonals Cᵐ)
(Dᵈ : Diagonals Dᵐ)
where
module Cᵈ = Diagonals Cᵈ
module Dᵈ = Diagonals Dᵈ
```
-->
```agda
is-diagonal-functor : Lax-monoidal-functor → Type (oc ⊔ ℓd)
is-diagonal-functor (F , lax) = ∀ {A} → φ ∘ Dᵈ.δ ≡ F.₁ (Cᵈ.δ {A})
where
module F = Functor F
open Lax-monoidal-functor-on lax
```
The "idempotent" terminology comes from the semantics of programming
languages, where lax monoidal functors are used to model certain kinds
of effectful computations, as a "static" alternative to [[monads]].
In that setting, an idempotent monoidal functor (or "idempotent
applicative functor") represents an effect that can be executed
multiple times with the same effect as executing it once: for example,
reading from an immutable data source or throwing an exception.
# Monoidal natural transformations {defines="monoidal-natural-transformation"}
The notion of [[natural transformation]] between functors can also be
refined in the case of monoidal functors: a **monoidal natural
transformation** $\alpha : F \To G$ is one such that the following
diagrams commute.
<div class="mathpar">
~~~{.quiver}
\[\begin{tikzcd}
{FA \otimes FB} & {GA \otimes GB} \\
{F(A \otimes B)} & {G(A \otimes B)}
\arrow[from=1-1, to=2-1]
\arrow["{\alpha_A \otimes \alpha_B}", from=1-1, to=1-2]
\arrow[from=1-2, to=2-2]
\arrow["{\alpha_{A\otimes B}}"', from=2-1, to=2-2]
\end{tikzcd}\]
~~~
~~~{.quiver}
\[\begin{tikzcd}
1 \\
F1 & G1
\arrow[from=1-1, to=2-1]
\arrow["{\alpha_1}"', from=2-1, to=2-2]
\arrow[from=1-1, to=2-2]
\end{tikzcd}\]
~~~
</div>
<!--
```agda
module _ ((F , F-monoidal) (G , G-monoidal) : Lax-monoidal-functor) where
module FM = Lax-monoidal-functor-on F-monoidal
module GM = Lax-monoidal-functor-on G-monoidal
open _=>_
```
-->
```agda
record is-monoidal-transformation (α : F => G) : Type (oc ⊔ ℓc ⊔ ℓd) where
field
nat-ε : α .η C.Unit ∘ FM.ε ≡ GM.ε
nat-φ : ∀ {A B} → α .η _ ∘ FM.φ {A} {B} ≡ GM.φ ∘ (α .η _ D.⊗₁ α .η _)
```
Note that, since monoidal categories can be thought of as one-object
[[bicategories]], we may expect to also have [[modifications]] between
monoidal natural transformations, but this is not the case: the
categorical ladder ends here. This is analogous to the fact that
[[monoids]] only form a category and not a bicategory, even when
viewed as one-object categories: there simply aren't enough objects
to have interesting 3-cells (resp. 2-cells)!