forked from BartoszMilewski/Publications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FreeMono.tex
2473 lines (2070 loc) · 80.7 KB
/
FreeMono.tex
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[letterpaper, 10 pt, conference]{ieeeconf}
% \overrideIEEEmargins
% The following packages can be found on http:\\www.ctan.org
%\usepackage{graphics} % for pdf, bitmapped graphics files
%\usepackage{epsfig} % for postscript graphics files
%\usepackage{mathptmx} % assumes new font selection scheme installed
%\usepackage{times} % assumes new font selection scheme installed
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz-cd}
\usepackage{mathrsfs}
\usepackage{listings}
\usepackage{float}
\usepackage{minted}
\newcommand{\hask}[1]{\mintinline{Haskell}{#1}}
\newenvironment{haskell}
{\VerbatimEnvironment
\begin{minted}[escapeinside=??, mathescape=true,frame=single, framesep=5pt, tabsize=1]{Haskell}}
{\end{minted}}
\usetikzlibrary{positioning,intersections}
\newtheorem{theorem}{Theorem}
\newtheorem{definition}{Definition}[section]
\newtheorem{proposition}{Proposition}[section]
\title{\LARGE \bf
Free Monoids as Initial Algebras
}
\author{Bartosz Milewski}
\begin{document}
\maketitle
\thispagestyle{empty}
\pagestyle{empty}
\subsection{Preface}
In on of my blog posts I used, without proof, the fact that the initial algebra of the functor $I + h \otimes -$ is a free monoid. The proof of this statement is not at all trivial and, frankly, I would never have been able to work it out by myself. I was lucky enough to get help from a mathematician, Alex Campbell, who sent me the proof he extracted from the paper by G. M. Kelly \cite{Kelly}.
I worked my way through this proof, filling some of the steps that might have been obvious to a mathematician, but not to an outsider. I even learned how to draw diagrams using the TikZ package for \LaTeX.
What I realized was that category theorists have developed a unique language to manipulate mathematical formulas: the language of 2-dimensional diagrams. For a programmer interested in languages this is a fascinating topic. We are used to working with grammars that essentially deal with string substitutions. Although diagrams can be serialized---TikZ lets you do it---you can't really operate on diagrams without laying them out on a page. The most common operation---diagram pasting---involves combining two or more diagrams along common edges. I am amazed that, to my knowledge, there is no tool to mechanize this process.
In this post you'll also see lots of examples of using the same diagram shape (the free-construction diagram, or the algebra-morphism diagram), substituting new expressions for some of the nodes and edges. Not all substitutions are valid and I'm sure one could develop some kind of type system to verify their correctness.
Because of proliferation of diagrams, this blog post started growing out of proportion, so I decided to split it into two parts. If you are serious about studying this proof, I strongly suggest you download (or even print out) the PDF version of this blog.
\section{Part I: Free Algebras}
\subsection{Introduction}
Here's the broad idea: The initial algebra that defines a free monoid is a fixed point of the functor $I + h \otimes -$, which I will call the list functor. Roughly speaking, it's the result of replacing the dash in the definition of the functor with the result of the replacement. For instance, in the first iteration we would get:
\[I + h \otimes (I + h \otimes -) \cong I + h + h \otimes h \otimes - \]
I used the fact that $I$ is the unit of the tensor product, the associativity of $\otimes$ (all up to isomorphism), and the distributivity of tensor product over coproduct.
Continuing this process, we would arrive at an infinite sum of powers of $h$:
\[m = I + h + h \otimes h + h \otimes h \otimes h + ...\]
Intuitively, a free monoid is a list of $h$s, and this representation expresses the fact that a list is either trivial (corresponding to the unit $I$), or a single $h$, or a product of two $h$s, and so on...
Let's have a look at the structure map of the initial algebra of the list functor:
\[I + h \otimes m \to m\]
Mapping out of a coproduct (sum) is equivalent to defining a pair of morphisms $\langle \pi, \sigma \rangle$:
\[\pi \colon I \to m\]
\[\sigma \colon h \otimes m \to m\]
the second of which may, in itself, be considered an algebra for the product functor $h \otimes -$.
Our goal is to show that the initial algebra of the list functor is a monoid so, in particular, it supports multiplication:
\[\mu \colon m \otimes m \to m\]
Following our intuition about lists, this multiplication corresponds to list concatenation. One way of concatenating two lists is to keep multiplying the second list by elements taken from the first list. This operation is described by the application of our product functor $h \otimes -$. Such repetitive application of a functor is described by a \textit{free algebra}.
There is just one tricky part: when concatenating two lists, we have to disassemble the left list starting from the tail (alternatively, we could disassemble the right list from the head, but then we'd have to append elements to the tail of the left list, which is the same problem). And here's the ingenious idea: you disassemble the left list from the head, but instead of applying the elements directly to the right list, you turn them into functions that prepend an element. In other words you convert a list of elements into a (reversed) list of functions. Then you apply this list of functions to the right list one by one.
This conversion is only possible if you can trade product for function -- the process we know as currying. Currying is possible if there is an adjunction between the product and the exponential, a.k.a, the internal hom, $[k, n]$ (which generalizes the set of functions from $k$ to $n$):
\[C(m \otimes k, n) \cong C(m, [k, n])\]
We'll assume that the underlying category $C$ is monoidal \textit{closed}, so that we can curry morphisms that map out from the tensor product:
\[g \colon m \otimes k \to n\]
\[\bar{g} \colon m \to [k, n]\]
(In what follows I'll be using the overbar to denote the curried version of a morphism.)
The internal hom can also be defined using a universal construction, see Fig. \ref{fig-uhom}. The morphism $eval$ corresponds to the counit of the adjunction (although the universal construction is more general than the adjunction).
\begin{figure}[h]
\centering
\begin{tikzcd}
m
\arrow[d, dashed, "\bar{g}"']
& m \otimes k
\arrow[d, "\bar{g} \otimes k"']
\arrow[dr, "g"] \\
{[k, n]}
& {[k, n]} \otimes k
\arrow[r, "eval"']
& n
\end{tikzcd}
\caption{Universal construction of the internal hom $[k, n]$. For any object $m$ and a morphism $g \colon m \otimes k \to n$ there is a unique morphism $\bar{g}$ (the \textit{curried} version of $g$) which makes the triangle commute.}
\label{fig-uhom}
\end{figure}
The hard part of the proof is to show that the initial algebra produces a \textit{free} monoid, which is a free object in the category of monoids. I'll start by defining the notion of a free object.
\subsection{Free Objects}
You might be familiar with the definition of a free construction as the left adjoint to the forgetful functor. Fig \ref{fig-ffadj} illustrates the essence of such an adjunction.
\begin{figure}[h]
\centering
\begin{tikzcd}
F x
\arrow[r, "F", leftarrow, dotted] \arrow[d, "g"]
& x
\arrow[d, "f"] \\
z
\arrow[r, "U", dotted]
& U z
\end{tikzcd}
\caption{Free/forgetful adjunction}
\label{fig-ffadj}
\end{figure}
The left hand side is in some category $D$ of structured objects: algebras, monoids, monads, etc. The right hand side is in the underlying category $C$, often the category of sets. The adjunction establishes a one-to-one correspondence between sets of morphisms, of which $g$ and $f$ are examples. If $U$ is the forgetful functor, then $F$ is the free functor, and the object $F x$ is called the free object generated by $x$. The adjunction is an isomorphism of hom-sets, natural in both $x$ and $z$:
\[D(F x, z) \cong C(x, U z)\]
Unfortunately, this description doesn't quite work for some important cases, like free monads. In the case of free monads, the right category is the category of endofunctors, and the left category is the category of monads. Because of size issues, not every endofunctor on the right generates a free monad on the left.
It turns out that there is a weaker definition of a free object that doesn't require a full blown adjunction; and which reduces to it, when the adjunction can be defined globally.
Let's start with the object $x$ on the right, and try to define the corresponding free object $F x$ on the left (by abuse of notation I will call this object $F x$, even if there is no functor $F$). For our definition, we need a condition that would work universally for any object $z$, and any morphism $f$ from $x$ to $U z$.
We are still missing one important ingredient: something that would tell us that $x$ acts as a set of generators for $F x$. This property can be expressed by providing a morphism that inserts $x$ into $U (F x)$---the object underlying the free object. In the case of an adjunction, this morphism happens to be the component of the unit natural transformation:
\[\eta \colon Id \to U \circ F\]
where $Id$ is the identity functor (see Fig. \ref{fig-uadj}).
\begin{figure}[h]
\centering
\begin{tikzcd}
& U (F x)
\arrow[dl, "U"', leftarrow, dotted] \arrow[d, leftarrow, "\eta_x"] \\
F x
\arrow[r, "F", leftarrow, dotted]
& x
\end{tikzcd}
\caption{Unit of adjunction}
\label{fig-uadj}
\end{figure}
The important property of the unit of adjunction $\eta$ is that it can be used to recover the mapping from the left hom-set to the right hom-set in Fig. \ref{fig-ffadj}. Take a morphism $g \colon F x \to z$, lift it using $U$, and compose it with $\eta_x$. You get a morphism $f \colon x \to U z$:
\[ f = U g \circ \eta_x \]
In the absence of an adjunction, we'll make the existence of the morphism $\eta_x$ part of the definition of the free object.
\begin{definition}{Free object.}
A free object on $x$ consists of an object $F x$ and a morphism $\eta_x \colon x \to U (F x)$ such that, for every object $z$ and a morphism $f \colon x \to U z$, there is a unique morphism $g \colon F x \to z$ such that:
\[U g \circ \eta_x = f \]
\end{definition}
The diagram in Fig. \ref{fig-freeobj} illustrates this definition. It is essentially a composition of the two previous diagrams, except that we don't require the existence of a global mapping, let alone a functor, $F$.
\begin{figure}[h]
\centering
\begin{tikzcd}
& U (F x)
\arrow[dd, bend left=30, "U g"]
\arrow[dl, "U"', leftarrow, dotted] \arrow[d, leftarrow, "\eta_x"'] \\
F x
\arrow[d, "g", dashed]
& x
\arrow[d, "f"'] \\
z
\arrow[r, "U", dotted]
& U z
\end{tikzcd}
\caption{Definition of a free object $F x$}
\label{fig-freeobj}
\end{figure}
The morphism $\eta_x$ is called the universal mapping, because it's independent of $z$ and $f$. The equation:
\[U g \circ \eta_x = f \]
is called the universal condition, because it works universally for every $z$ and $f$. We say that $g$ is \textit{induced} by the morphism $f$.
There is a standard trick that uses the universal condition: Suppose you have two morphisms $g$ and $g'$ from the universal object to some $z$. To prove that they are equal, it's enough to show that they are both induced by the same $f$. Showing the equality:
\[U g \circ \eta_x = U g' \circ \eta_x\]
is often easier because it lets you work in the simpler, underlying category.
\subsection{Free Algebras}
As I mentioned in the introduction, we are interested in algebras for the product functor: $h \otimes -$, which we'll call $h$-algebras. Such an algebra consists of a carrier $n$ and a structure map:
\[\nu \colon h \otimes n \to n\]
For every $h$, $h$-algebras form a category; and there is a forgetful functor $U$ that maps an $h$-algebra to its carrier object $n$. We can therefore define a free algebra as a \textit{free object} in the category of $h$-algebras, which may or may not be generalizable to a full-blown free/forgetful adjunction. Fig. \ref{fig-freea} shows the universal condition that defines such a free algebra $(m_k, \sigma)$ generated by an object $k$.
\begin{figure}[h]
\centering
\begin{tikzcd}
& m_k
\arrow[dd, bend left=30, "g"]
\arrow[dl, "U"', leftarrow, dotted] \arrow[d, leftarrow, "\eta_k"'] \\
(m_k, \sigma)
\arrow[d, "g", dashed]
& k
\arrow[d, "f"'] \\
(n, \nu)
\arrow[r, "U", dotted]
& n
\end{tikzcd}
\caption{Free $h$-algebra $(m_k, \sigma)$ generated by $k$}
\label{fig-freea}
\end{figure}
In particular, we can define an important free $h$-algebra generated by the identity object $I$. This algebra $(m, \sigma)$ has the structure map:
\[\sigma \colon h \otimes m \to m\]
and is described by the diagram in Fig. \ref{fig-freei}:
\begin{figure}[h]
\centering
\begin{tikzcd}
& m
\arrow[dd, bend left=30, "g"]
\arrow[dl, "U"', leftarrow, dotted] \arrow[d, leftarrow, "\pi"'] \\
(m, \sigma)
\arrow[d, "g", dashed]
& I
\arrow[d, "f"'] \\
(n, \nu)
\arrow[r, "U", dotted]
& n
\end{tikzcd}
\caption{Free $h$-algebra $(m, \sigma)$ generated by $I$}
\label{fig-freeai}
\end{figure}
Its universal condition reads:
\[g \circ \pi = f \]
By definition, since $g$ is an algebra morphism, it makes the diagram in Fig. \ref{fig-algmor} commute:
\begin{figure}[h]
\centering
\begin{tikzcd}
h \otimes m
\arrow[r, "\sigma"]
\arrow[d, "h \otimes g"]
& m
\arrow[d, "g"] \\
h \otimes n
\arrow[r, "\nu"]
& n
\end{tikzcd}
\caption{$g$ is an $h$-algebra morphism}
\label{fig-algmor}
\end{figure}
We use a notational convenience: $h \otimes g$ is the lifting of the morphism $g$ by the product functor $h \otimes -$. This might be confusing at first, because it looks like we are multiplying an object $h$ by a morphism $g$. One way to parse it is to consider that, if we keep the first argument to the tensor product constant, then it's a functor in the second component, symbolically $h \otimes -$. Since it's a functor, we can use it to lift a morphism $g$, which can be notated as $h \otimes g$.
Alternatively, we can exploit the fact that tensor product is a bifunctor, and therefore it may lift a pair of morphism, as in $id_h \otimes g$; and $h \otimes g$ is just a shorthand notation for this.
Bifunctoriality also means that the tensor product preserves composition and identity in both arguments. We'll use these facts extensively later, especially as the basis for string diagrams.
The important property of $m$ is that it also happens to be the initial algebra for the functor $I + h \otimes -$. Indeed, for any other algebra with the carrier $n$ and the structure map a pair $\langle f, \nu \rangle$, there exists a unique $g$ given by Fig \ref{fig-freeai}, such that the diagram in Fig. \ref{fig-inita} commutes:
\begin{figure}[h]
\centering
\begin{tikzcd}
I + h \otimes m
\arrow[r, "{\langle \pi , \sigma \rangle}"]
\arrow[d, "{\langle inl ,\, inr \circ (h \otimes g) \rangle}"']
& m
\arrow[d, "g"] \\
I + h \otimes n
\arrow[r, "{\langle f , \nu \rangle}"]
& n
\end{tikzcd}
\caption{Initiality of the algebra $(m, \langle \pi, \sigma \rangle)$ for the functor $I + h \otimes -$.}
\label{fig-inita}
\end{figure}
Here, $inl$ and $inr$ are the two injections into the coproduct.
If you visualize $m$ as the sum of all powers of $h$, $\pi$ inserts the unit $I$ (zeroth power) into it, and $\sigma$ inserts the sum of non-zero powers.
\[\langle \pi, \sigma \rangle \colon I + h \otimes m \to m \]
The advantage of this result is that we can concentrate on studying the simpler problem of free $h$-algebras rather than the problem of initial algebras for the more complex list functor.
\subsection{Example}
Here's some useful intuition behind $h$-algebras. Think of the functor $(h \otimes -)$ as a means of forming formal expressions. These are very simple expressions: you take a variable and pair it (using the tensor product) with $h$. To define an algebra for this functor you pick a particular type $n$ for your variable (i.e., the carrier object) and a recipe for evaluating any expression of type $h \otimes n$ (i.e., the structure map).
Let's try a simple example in Haskell. We'll use pairs (and tuples) as our tensor product, with the empty tuple \hask{()} as unit (up to isomorphism). An algebra for a functor \hask{f} is defined as:
\begin{haskell}
type Algebra f a = f a -> a
\end{haskell}
Consider $h$-algebras for a particular choice of $h$: the type of real numbers \hask{Double}. In other words, these are algebras for the functor \hask{((,) Double)}. Pick, as your carrier, the type of vectors:
\begin{haskell}
data Vector = Vector { x :: Double
, y :: Double
} deriving Show
\end{haskell}
and the structure map that scales a vector by multiplying it by a number:
\begin{haskell}
vecAlg :: Algebra ((,) Double) Vector
vecAlg (a, v) = Vector { x = a * x v
, y = a * y v }
\end{haskell}
Define another algebra with the carrier the set of real numbers, and the structure map multiplication by a number.
\begin{haskell}
mulAlg :: Algebra ((,) Double) Double
mulAlg (a, x) = a * x
\end{haskell}
There is an algebra morphism from \hask{vecAlg} to \hask{mulAlg}, which takes a vector and maps it to its length.
\begin{haskell}
algMorph :: Vector -> Double
algMorph v = sqrt((x v)^2 + (y v)^2)
\end{haskell}
This is an algebra morphism, because it doesn't matter if you first calculate the length of a vector and then multiply it by \hask{a}, or first multiply the vector by \hask{a} and then calculate its length (modulo floating-point rounding).
A \textit{free} algebra has, as its carrier, the set of all possible expressions, and an evaluator that tells you how to convert a functor-ful of such expressions to another valid expression. A good analogy is to think of the functor as defining a grammar (as in BNF grammar) and a free algebra as a language generated by this grammar.
You can generate free $h$-expressions recursively. The starting point is the set of generators $k$ as the source of variables. Applying the functor to it produces $h \otimes k$. Applying it again, produces $h \otimes h \otimes k$, and so on. The whole set of expressions is the infinite coproduct (sum):
\[k + h \otimes k + h \otimes h \otimes k + ...\]
An element of this coproduct is either an element of $k$, or an element of the product $h \otimes k$, and so on...
The universal mapping injects the set of generators $k$ into the set of expressions (here, it would be the leftmost injection into the coproduct).
In the special case of an algebra generated by the unit $I$, the free algebra simplifies to the power series:
\[I + h + h \otimes h + ...\]
and $\pi$ injects $I$ into it.
Continuing with our example, let's consider the free algebra for the functor \hask{((,) Double)} generated by the unit \hask{()}. The free algebra is, symbolically, an infinite sum (coproduct) of tuples:
\begin{haskell}
data Expr =
()
| Double
| (Double, Double)
| (Double, Double, Double)
| ...
\end{haskell}
Here's an example of an expression:
\begin{haskell}
e = (1.1, 2.2, 3.3)
\end{haskell}
As you can see, free expressions are just lists of numbers. There is a function that inserts the unit into the set of expressions:
\begin{haskell}
pi :: () -> Expr
pi () = ()
\end{haskell}
The free evaluator is a function (not actual Haskell):
\begin{haskell}
sigma (a, ()) = a
sigma (a, x) = (a, x)
sigma (a, (x, y)) = (a, x, y)
sigma (a, (x, y, z)) = (a, x, y, z)
...
\end{haskell}
Let's see how the universal property works in our example. Let's try, as the target $(n, \nu)$, our earlier vector algebra:
\begin{haskell}
vecAlg :: Algebra ((,) Double) Vector
vecAlg (a, v) = Vector { x = a * x v
, y = a * y v }
\end{haskell}
The morphism \hask{f} picks some vector, for instance:
\begin{haskell}
f :: () -> Vector
f () = Vector 3 4
\end{haskell}
There should be a unique morphism of algebras \hask{g} that takes an arbitrary expression (a list of \hask{Double}s) to a vector, such that \hask{g . pi = f} picks our special vector:
\begin{haskell}
Vector 3 4
\end{haskell}
In other words, \hask{g} must take the empty tuple (the result of \hask{pi}) to \hask{Vector 3 4}. The question is, how is \hask{g} defined for an arbitrary expression? Look at the diagram in Fig. \ref{fig-algmor} and the commuting condition it implies:
\[g \circ \sigma = \nu \circ (h \otimes g)\]
Let's apply it to an expression \hask{(a, ())} (the action of the functor \hask{(h, -)} on \hask{()}). Applying \hask{sigma} to it produces \hask{a}, followed by the action of \hask{g} resulting in \hask{g a}. This should be the same as first applying the lifted \hask{(id, g)} acting on \hask{(a, ())}, which gives us \hask{(a, Vector 3 4)}; followed by \hask{vecAlg}, which produces \hask{Vector (a * 3) (a * 4)}. Together, we get:
\begin{haskell}
g a = Vector (a * 3) (a * 4)
\end{haskell}
Repeating this process gives us:
\begin{haskell}
g :: Expr -> Vector
g () = Vector 3 4
g a = Vector (a * 3) (a * 4)
g (a, b) = Vector (a * b * 3)(a * b * 4)
...
\end{haskell}
This is the unique \hask{g} induced by our \hask{f}.
\subsection{Properties of Free Algebras}
Here are some interesting properties that will help us later: $h$-algebras are closed under multiplication and exponentiation. If $(n, \nu)$ is an $h$-algebra, then there are also $h$-algebras with the carriers $n \otimes k$ and $[k, n]$, for an arbitrary object $k$. Let's find their structure maps.
The first one should be a mapping:
\[h \otimes n \otimes k \to n \otimes k\]
which we can simply take as the lifting of $\nu$ by the tensor product: $\nu \otimes k$.
The second one is:
\[\tau_{k} \colon h \otimes [k, n] \to [k, n]\]
which can be uncurried to:
\[h \otimes [k, n] \otimes k \to n\]
We have at our disposal the counit of the hom-adjunction:
\[eval \colon [k, n] \otimes k \to n\]
which we can use in combination with $\nu$:
\[\nu \circ (h \otimes eval)\]
to implement the (uncurried) structure map.
Here's the same construction for Haskell programmers. Given an algebra:
\begin{haskell}
nu :: Algebra ((,) h) n
\end{haskell}
we can create two algebras:
\begin{haskell}
alpha :: Algebra ((,) h) (n, k)
alpha (a, (n, k)) = (nu (a, n), k)
\end{haskell}
and:
\begin{haskell}
tau :: Algebra ((,) h) (k -> n)
tau (a, kton) = \k -> nu (a, kton k)
\end{haskell}
These two algebras are related through an adjunction in the category of $h$-algebras:
\[Alg\big((n \otimes k, \nu \otimes k), (l, \lambda)\big) \cong Alg\big((n, \nu), ([k, l], \tau_{k})\big)\]
which follows directly from hom-adjunction acting on carriers.
\[C(n \otimes k, l) \cong C(n, [k, l])\]
Finally, we can show how to generate free algebras from arbitrary generators. Intuitively, this is obvious, since it can be described as the application of distributivity of tensor product over coproduct:
\[k + h \otimes k + h \otimes h \otimes k + ... =
(I + h + h \otimes h + ...) \otimes k\]
More formally, we have:
\begin{proposition}
If $(m, \sigma)$ is is the free $h$-algebra generated by $I$, then $(m \otimes k, \sigma \otimes k)$ is the free $h$-algebra generated by $k$ with the universal map given by $\pi \otimes k$.
\end{proposition}
\begin{proof}
Let's show the universal property of $(m \otimes k, \sigma \otimes k)$. Take any $h$-algebra $(n, \nu)$ and a morphism:
\[f \colon k \to n\]
We want to show that there is a unique $g \colon m \otimes k \to n$ that closes the diagram in Fig. \ref{fig-freeik}.
\begin{figure}[h]
\centering
\begin{tikzcd}
& m \otimes k
\arrow[dd, bend left=40, "g"]
\arrow[dl, "U"', leftarrow, dotted] \arrow[d, leftarrow, "\pi \otimes k"'] \\
(m \otimes k, \sigma \otimes k)
\arrow[d, "g", dashed]
& I \otimes k
\arrow[d, "f"'] \\
(n, \nu)
\arrow[r, "U", dotted]
& n
\end{tikzcd}
\caption{Free $h$-algebra generated by $k \cong I \otimes k$}
\label{fig-freeik}
\end{figure}
I have rewritten $f$ (taking advantage of the isomorphism $I \otimes k \cong k$), as:
\[f \colon I \otimes k \to n\]
We can curry it to get:
\[\bar{f} \colon I \to [k, n]\]
The intuition is that the morphism $\bar{f}$ selects an element of the internal hom $[k, n]$ that corresponds to the original morphism $f \colon k \to n$.
We've seen earlier that there exists an $h$-algebra with the carrier $[k, n]$ and the structure map $\tau_k$. But since $m$ is the free $h$-algebra, there must be a unique algebra morphism $\bar{g}$ (see Fig. \ref{fig-uniq}):
\[ \bar{g} \colon (m, \sigma) \to ([k, n], \tau_k)\]
such that:
\[\bar{g} \circ \pi = \bar{f}\]
\begin{figure}[h]
\centering
\begin{tikzcd}
& m
\arrow[dd, bend left=30, "\bar{g}"]
\arrow[dl, "U"', leftarrow, dotted] \arrow[d, leftarrow, "\pi"'] \\
(m, \sigma)
\arrow[d, "\bar{g}", dashed]
& I
\arrow[d, "\bar{f}"'] \\
{([k, n], \tau_k)}
\arrow[r, "U", dotted]
& {[k, n]}
\end{tikzcd}
\caption{The construction of the unique morphism $\bar{g}$}
\label{fig-uniq}
\end{figure}
Uncurying this $\bar{g}$ gives us the sought after $g$.
The universal condition in Fig. \ref{fig-freeik}:
\[g \circ (\pi \otimes k) = f\]
follows from pasting together two diagrams that define the relevant hom-adjunctions in Fig \ref{fig-adjadj} (c.f., Fig. \ref{fig-uhom}).
\begin{figure}[h]
\centering
\begin{tikzcd}
I
\arrow[d, "\pi"']
\arrow[dd, bend right=40, "\bar{f}"']
& I \otimes k
\arrow[ddrr, bend left=40, "f"]
\arrow[dd, "\bar{f} \otimes k"']
\arrow[rd, "\pi \otimes k"] \\
m
\arrow[d, "\bar{g}"']
&
& m \otimes k
\arrow[dl, "\bar{g} \otimes k"']
\arrow[dr, "g"] \\
{[k, n]}
& {[k, n]} \otimes k
\arrow[rr, "eval"']
&
& n
\end{tikzcd}
\caption{The diagram defining the currying of both $g$ and $g \circ (\pi \otimes k)$. This is the pasting together of two diagrams that define the universal property of the internal hom $[k, n]$, one for the object $I$ and one for the object $m$.}
\label{fig-adjadj}
\end{figure}
\end{proof}
The immediate consequence of this proposition is that, in order to show that two $h$-algebra morphisms $g, g' \colon m \otimes k \to n$ are equal, it's enough to show the equality of two regular morphisms:
\[g \circ (\pi \otimes k) = g' \circ (\pi \otimes k) \colon k \to n\]
(modulo isomorphism between $k$ and $I \otimes k$). We'll use this property later.
It's instructive to pick apart this proof in the simpler Haskell setting. We have the target algebra:
\begin{haskell}
nu :: Algebra ((,) h) n
\end{haskell}
There is a related algebra $[k, n]$ of the form:
\begin{haskell}
tau :: Algebra ((,) h) (k -> n)
tau (a, kton) = \k -> nu (a, kton k)
\end{haskell}
We've analyzed, previously, a version of the universal construction of $g$, which we can now generalize to Fig. \ref{fig-uniq}. We can build up the definition of $\bar{g}$, starting with the condition $\bar{g} \circ \pi = \bar{f}$. Here, $\bar{f}$ selects a function from the hom-set: this function is our $f$. That gives us the action of $g$ on the unit:
\begin{haskell}
g :: Expr -> (k -> n)
g () = f
\end{haskell}
Next, we make use of the fact that $\bar{g}$ is an algebra morphism that satisfies the commuting condition:
\[ \bar{g} \circ \sigma = \tau \circ (h \otimes \bar{g})\]
As before, we apply this equation to the expression \hask{(a, ())}. The left hand side produces \hask{g a}, while the right hand side produces \hask{tau (a, f)}. Next, we
apply the same equation to \hask{(a, (b, ()))}. The left hand side produces \hask{g (a, b)}. The right hand produces \hask{tau (a, tau (b, f))}, and so on. Applying the definition of \hask{tau}, we get:
\begin{haskell}
g :: Expr -> (k -> n)
g () = f
g a = \k -> nu (a, f k)
g (a, b) = \k -> nu (a, nu (b, f k))
...
\end{haskell}
Notice the order reversal in function application. The list that is the argument to \hask{g} is converted to a series of applications of \hask{nu}, with list elements in reverse order. We first apply \hask{nu (b, -)} and then \hask{nu (a, -)}. This reversal is crucial to implementing list concatenation, where \hask{nu} will prepend elements of the first list to the second list. We'll see this in the second installment of this blog post.
\section{Part II: Free Monoids}
\subsection{String Diagrams}
The utility of diagrams in formulating and proving theorems in category theory cannot be overemphasized. While working my way through the construction of free monoids, I noticed that there was a particular set of manipulations that had to be done algebraically, with little help from diagrams. These were operations involving a mix of tensor products and composition of morphisms. Tensor product is a bifunctor, so it preserves composition; which means you can often slide products through junctions of arrows---but the rules are not immediately obvious. Diagrams in which objects are nodes and morphisms are arrows have no immediate graphical representation for tensor products. A thought occurred to me that maybe a dual representation, where morphisms are nodes and objects are edges would be more accommodating. And indeed, a quick search for "string diagrams in monoidal categories" produced a paper by Joyal and Street, "The geometry of tensor calculus."
The idea is very simple: if you represent morphisms as points on a plane, you have two additional dimensions to play with composition and tensoring. Two morphism---represented as points---can be composed if they share an object, which can be represented as a line connecting them. By convention, we read composition from the bottom of the diagram up. We follow lines as they go through points---that's composition. Two lines ascending in parallel represent a tensor product. The geometry of the diagram just works!
Let me explain it on a simple example---the left unit law for a monoid $(m, \pi, \mu)$:
\[ \mu \circ (\pi \otimes m) = id \]
The left hand side is a composition of two morphisms. The first morphism $\pi \otimes m$ starts from the object $I \otimes m$ (see Fig. \ref{fig-lunit}).
\begin{figure}[H]
\centering
\begin{tikzpicture}
\def\xa{0};
\def\xb{0.7};
\def\xc{\xb * 2};
\def \ya{0.8};
\def \yb{1.7};
\def \yc{2.6};
\node(a) at (\xa, \ya) {};
\node(b) at (\xb, \yb) {};
\node(c) at (\xc, 0) {};
\node(d) at (\xb, \yc) {};
\filldraw[black] (a) circle (1 pt);
\node [below] at (a) {$\pi$};
\filldraw[black] (b) circle (1 pt);
\node [below] at (b) {$\mu$};
\draw (a) to [out=90, in=180] node[left] {$m$}(b);
\draw (c) to [out=90, in=0] node[right] {$m$} (b);
\draw (b) -- node[right] {$m$} (d);
\def\xd{3.5}
\def\xe{2.5}
\node(e) at (\xd, 0) {};
\node(f) at (\xd, \yc) {};
\node at (\xe, 1.5) {$=$};
\draw (e) -- node[right] {$m$} (f);
\end{tikzpicture}
\caption{Left unit law}
\label{fig-lunit}
\end{figure}
In principle, there should be two parallel lines at the bottom, one for $I$ and one for $m$; but $I \otimes m$ is isomorphic to $m$, so the $I$ line is redundant and can be omitted. Scanning the diagram from the bottom up, we encounter the morphism $\pi$ in parallel with the $m$ line. That's exactly the graphical representation of $\pi \otimes m$. The output of $\pi$ is also $m$, so we now have two upward moving $m$ lines, corresponding to $m \otimes m$. That's the input of the next morphism $\mu$. Its output is the single upward moving $m$. The unit law may be visualized as pulling the two $m$ strings in opposite direction until the whole diagram is straightened to one vertical $m$ string corresponding to $id_m$.
Here's the right unit law:
\[\mu \circ (m \otimes \pi) = id \]
It works like a mirror image of the left unit law:
\begin{figure}[H]
\centering
\begin{tikzpicture}
\def\xa{0};
\def\xb{0.7};
\def\xc{\xb * 2};
\def \ya{0.8};
\def \yb{1.7};
\def \yc{2.6};
\node(a) at (\xa, 0) {};
\node(b) at (\xb, \yb) {};
\node(c) at (\xc, \ya) {};
\node(d) at (\xb, \yc) {};
\filldraw[black] (b) circle (1 pt);
\node [below] at (c) {$\pi$};
\filldraw[black] (c) circle (1 pt);
\node [below] at (b) {$\mu$};
\draw (a) to [out=90, in=180] node[left] {$m$}(b);
\draw (c) to [out=90, in=0] node[right] {$m$} (b);
\draw (b) -- node[right] {$m$} (d);
\def\xd{3.5}
\def\xe{2.5}
\node(e) at (\xd, 0) {};
\node(f) at (\xd, \yc) {};
\node at (\xe, 1.5) {$=$};
\draw (e) -- node[right] {$m$} (f);
\end{tikzpicture}
\caption{Right unit law}
\label{fig-runit}
\end{figure}
The associativity law can be illustrated by the following diagram:
\begin{figure}[H]
\centering
\begin{tikzpicture}
\def\delta{0.7}
\def\xa{0};
\def\xb{\delta};
\def\xc{\delta * 2};
\def\xd{\delta * 3};
\def \ya{0.8};
\def \yb{1.7};
\def \yc{2.6};
\node(a) at (\xa, 0) {};
\node(b) at (\xb, \yb) {};
\node(c) at (\xc, \ya) {};
\node(d) at (\xb, \yc) {};
\node(e) at (\xb, 0) {};
\node(f) at (\xd, 0) {};
\filldraw[black] (b) circle (1 pt);
\filldraw[black] (c) circle (1 pt);
\node [below] at (b) {$\mu$};
\draw (a) to [out=90, in=180] node[left] {}(b);
\draw (c) to [out=90, in=0] node[right] {} (b);
\draw (b) -- node[right] {} (d);
\draw (e) to [out=90, in=180] node[left] {}(c);
\draw (f) to [out=90, in=0] node[right] {}(c);
\node [below] at (c) {$\mu$};
\node [below] at (a) {$m$};
\node [above] at (d) {$m$};
\node [below] at (e) {$m$};
\node [below] at (f) {$m$};
\def\xe{2.5}
\node at (\xe, 1.5) {$=$};
\def\off{3}
\def\xa{\off + \delta * 0};
\def\xb{\off + \delta * 1};
\def\xc{\off + \delta * 2};
\def\xd{\off + \delta * 3};
\node(a) at (\xa, 0) {};
\node(b) at (\xc, 0) {};
\node(c) at (\xd, 0) {};
\node(d) at (\xb, \ya) {};
\node(e) at (\xc, \yb) {};
\node(f) at (\xc, \yc) {};
\filldraw[black] (d) circle (1 pt);
\filldraw[black] (e) circle (1 pt);
\node [below] at (d) {$\mu$};
\draw (a) to [out=90, in=180] node[left] {}(d);
\draw (b) to [out=90, in=0] node[right] {} (d);
\draw (e) -- node[right] {} (f);
\draw (d) to [out=90, in=180] node[left] {}(e);
\draw (c) to [out=90, in=0] node[right] {}(e);
\node [below] at (e) {$\mu$};
\node [below] at (a) {$m$};
\node [below] at (b) {$m$};
\node [below] at (c) {$m$};
\node [above] at (f) {$m$};
\end{tikzpicture}
\caption{Associativity law}
\label{fig-assoc}
\end{figure}
The important property of a string diagram is that, because of functoriality, its value---the compound morphism it represents---doesn't change under continuous transformations.
\subsection{Monoid}
First we'd like to show that the carrier of the free $h$-algebra $(m, \sigma)$ which, as we've seen before, is also the initial algebra for the list functor $I + h \otimes -$, is automatically a monoid. To show that, we need to define its unit and multiplication---two morphisms that satisfy monoid laws. The obvious candidate for unit is the universal mapping $\pi \colon I \to m$. It's the morphism in the definition of the free algebra from the previous post (see Fig \ref{fig-freei}).
\begin{figure}[h]
\centering
\begin{tikzcd}
& m
\arrow[dd, bend left=30, "g"]
\arrow[dl, "U"', leftarrow, dotted] \arrow[d, leftarrow, "\pi"'] \\
(m, \sigma)
\arrow[d, "g", dashed]
& I
\arrow[d, "f"'] \\
(n, \nu)
\arrow[r, "U", dotted]
& n
\end{tikzcd}
\caption{Free $h$-algebra $(m, \sigma)$ generated by $I$}
\label{fig-freei}
\end{figure}
Multiplication is a morphism:
\[\mu \colon m \otimes m \to m\]
which, if you think of a free monoid as a list, is the generalization of list concatenation.
The trick is to show that $m \otimes m$ is also a free $h$-algebra whose generator is $m$ itself. We could then use the universality of $m \otimes m$ to generate the unique algebra morphism from it to $m$ (which is also an $h$-algebra). That will be our $\mu$.
\begin{proposition}{Monoid.}
The free $h$-algebra $(m, \sigma)$ generated by the unit object $I$ is a monoid whose unit is:
\[\pi \colon I \to m\]
and whose multiplication:
\[\mu \colon m \otimes m \to m\]
is the unique $h$-algebra morphism
\[(m \otimes m, \sigma \otimes m) \to (m, \sigma)\]
induced by the identity morphism $id_m$.
\end{proposition}
\begin{proof}
In the previous post we've shown that, if $(m, \sigma)$ is a free algebra generated by the unit object $I$ with the universal map $\pi$, then $(m \otimes k, \sigma \otimes k)$ is a free algebra generated by $k$ with the universal map $\pi \otimes k$ (see Fig. \ref{fig-freek}).
\begin{figure}[H]
\centering
\begin{tikzcd}
& m \otimes k
\arrow[dd, bend left=40, "g"]
\arrow[dl, "U"', leftarrow, dotted] \arrow[d, leftarrow, "\pi \otimes k"'] \\
(m \otimes k, \sigma \otimes k)
\arrow[d, "g", dashed]
& k
\arrow[d, "f"'] \\
(n, \nu)
\arrow[r, "U", dotted]
& n
\end{tikzcd}
\caption{Free $h$-algebra generated by $k \cong I \otimes k$}
\label{fig-freek}
\end{figure}
We get $\mu$ by redrawing this diagram: using $m$ as both the generator and the target algebra, and replacing $f$ with $id_m$ (see Fig. \ref{fig-monmul}):
\begin{figure}[H]
\centering
\begin{tikzcd}
& m \otimes m
\arrow[dd, bend left=40, "\mu"]
\arrow[dl, "U"', leftarrow, dotted] \arrow[d, leftarrow, "\pi \otimes m"'] \\
(m \otimes m, \sigma \otimes m)
\arrow[d, "\mu", dashed]
& m
\arrow[d, "id_m"'] \\
(m, \sigma)
\arrow[r, "U", dotted]
& m
\end{tikzcd}
\caption{Monoid multiplication as an $h$-algebra morphism}
\label{fig-monmul}
\end{figure}
Since so defined $\mu$ is an $h$-algebra morphism, it makes the following diagram, Fig. \ref{fig-mualg}, commute.
\begin{figure}[H]
\centering
\begin{tikzcd}
h \otimes m \otimes m
\arrow[d, "h \otimes \mu"']
\arrow[r, "\sigma \otimes m"]
& m \otimes m
\arrow[d, "\mu"] \\
h \otimes m
\arrow[r, "\sigma"]
& m
\end{tikzcd}
\caption{$\mu$ is an $h$-algebra morphism}
\label{fig-mualg}
\end{figure}
This commuting condition can be redrawn as the identity of two string diagrams (Fig. \ref{fig-mualgmor}) corresponding to the two paths through the original diagram.
\begin{figure}[H]
\centering
\begin{tikzpicture}
\def\dx{0.6}
\def\xa{0};
\def\xb{\dx};
\def\xc{\dx * 2};
\def\xd{\dx * 3};
\def \ya{0.8};
\def \yb{1.5};
\def \yc{2.2};
\node(h) at (\xa, 0) {};
\node(m1) at (\xb, 0) {};
\node(m2) at (\xd, 0) {};
\node(sig) at (\xb, \ya) {};
\node(mu) at (\xc, \yb) {};
\node(mt) at (\xc, \yc) {};
\filldraw[black] (sig) circle (1 pt);
\filldraw[black] (mu) circle (1 pt);
\node [below] at (m1) {$m$};
\node [below] at (mu) {$\mu$};
\node [below left] at (sig) {$\sigma$};
\draw (h) to [out=90, in=180] (sig);
\draw (m1) -- (sig);
\draw (m2) to [out=90, in=0] (mu);
\draw (sig) to [out=90, in=180] (mu);
\draw (mu) -- (mt);
\node[below] at (h) {$h$};
\node[below] at (m1) {$m$};
\node[below] at (m2) {$m$};
\node[above] at (mt) {$m$};
\def\off{3.0}
\def\xxa{\off + \xa};
\def\xxb{\off + \xb};
\def\xxc{\off + \xc};
\def\xxd{\off + \xd};
\node(hr) at (\xxa, 0) {};
\node(m1r) at (\xxb, 0) {};
\node(m2r) at (\xxd, 0) {};
\node(mur) at (\xxc, \ya) {};
\node(sigr) at (\xxc, \yb) {};
\node(mrt) at (\xxc, \yc) {};
\node at (\off - 0.5, 1.5) {$=$};
\filldraw[black] (mur) circle (1 pt);
\filldraw[black] (sigr) circle (1 pt);
\node [below] at (mur) {$\mu$};
\node [below left] at (sigr) {$\sigma$};
\draw (hr) to [out=90, in=180] (sigr);
\draw (m1r) to [out=90, in=180] (mur);
\draw (m2r) to [out=90, in=0] (mur);
\node[below] at (hr) {$h$};
\node[below] at (m1r) {$m$};
\node[below] at (m2r) {$m$};
\node[above] at (mrt) {$m$};
\draw (mur) -- (sigr);
\draw (mur) -- (mrt);
\end{tikzpicture}
\caption{String diagram showing that $\mu$ is an algebra morphism}
\label{fig-mualgmor}
\end{figure}
The universal condition in Fig. \ref{fig-monmul}:
\[ \mu \circ (\pi \otimes m) = id_m \]
gives us immediately the left unit law for the monoid.
The right unit law:
\[\mu \circ (m \otimes \pi) = id_m \]
requires a little more work.
There is a standard trick that we can use to show that two morphisms, whose source (in this case $m$) is a free algebra, are equal. It's enough to prove that they are algebra morphisms, and that they are both induced by the same morphism (in this case $\pi$). Their equality then follows from the uniqueness of the universal construction.
We know that $\mu$ is an algebra morphism so, if we can show that $m \otimes \pi$ is also an algebra morphism, their composition will be an algebra morphism too. Trivially, $id_m$ is an algebra morphism so, if we can show that the two are induced by the same regular morphism $\pi$, then they must be equal.
To show that $m \otimes \pi$ is an $h$-algebra morphism, we have to show that the diagram in Fig. \ref{fig-aalgmorpi} commutes.
\begin{figure}[H]
\centering
\begin{tikzcd}
h \otimes m
\arrow[r, "\sigma"]
\arrow[d, "h \otimes m \otimes \pi"]
& m
\arrow[d, "m \otimes \pi"] \\
h \otimes m \otimes m
\arrow[r, "\sigma \otimes m"]
& m \otimes m
\end{tikzcd}
\caption{$m \otimes \pi$ as an $h$-algebra morphism}
\label{fig-aalgmorpi}
\end{figure}
We can redraw the two paths through Fig. \ref{fig-aalgmorpi} as two string diagrams in Fig. \ref{fig-mpialgmor}. They are equal because they can be deformed into each other.
\begin{figure}[H]
\centering
\begin{tikzpicture}
\def\dx{0.6}
\def\xa{0};
\def\xb{\dx};
\def\xc{\dx * 2};
\def \ya{0.8};
\def \yb{1.5};
\def \yc{2.2};
\node(a) at (\xa, 0) {};
\node(b) at (\xb, \ya) {};
\node(c) at (\xb, 0) {};
\node(d) at (\xb, \yc) {};
\node(e) at (\xc, \yb) {};
\node(f) at (\xc, \yc) {};
\filldraw[black] (e) circle (1 pt);
\node [below] at (e) {$\pi$};
\filldraw[black] (b) circle (1 pt);
\node [below left] at (b) {$\sigma$};
\draw (a) to [out=90, in=180] (b);
\draw (c) -- (b);
\draw (b) -- (d);
\draw (e) -- (f);
\node[below] at (a) {$h$};
\node[below] at (c) {$m$};
\node[above] at (d) {$m$};
\node[above] at (f) {$m$};
\def\off{3.0}
\def\xxa{\off + \xa};
\def\xxb{\off + \xb};
\def\xxc{\off + \xc};
\node(aa) at (\xxa, 0) {};
\node(bb) at (\xxb, \yb) {};
\node(cc) at (\xxb, 0) {};
\node(dd) at (\xxb, \yc) {};
\node(ee) at (\xxc, \ya) {};
\node(ff) at (\xxc, \yc) {};
\node at (\off - 0.5, 1.5) {$=$};
\filldraw[black] (ee) circle (1 pt);
\filldraw[black] (bb) circle (1 pt);
\node [below] at (ee) {$\pi$};
\node [below left] at (bb) {$\sigma$};
\draw (aa) to [out=90, in=180] (bb);
\node[below] at (aa) {$h$};
\node[below] at (cc) {$m$};
\node[above] at (dd) {$m$};
\node[above] at (ff) {$m$};
\draw (cc) -- (bb);
\draw (bb) -- (dd);
\draw (ee) -- (ff);
\end{tikzpicture}
\caption{String diagram showing that $m \otimes \pi$ is an algebra morphism}
\label{fig-mpialgmor}
\end{figure}
Therefore the composition $\mu \circ (m \otimes \pi)$ is also an $h$-algebra morphism. The string diagram that illustrates this fact is shown in Fig. \ref{fig-mumpi}.
\begin{figure}[H]
\centering
\begin{tikzpicture}
\def\dx{0.6}
\def\xa{0};
\def\xb{\dx};
\def\xc{\dx * 2};
\def\xd{\dx * 3};
\def \ya{0.8};