-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjectsmorphisms.tex
More file actions
1101 lines (991 loc) · 37.2 KB
/
objectsmorphisms.tex
File metadata and controls
1101 lines (991 loc) · 37.2 KB
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
%% -*- coding:utf-8 -*-
\chapter{Objects and morphisms}
\section{Equality}
The important question is how we can decide whenever an
object/morphism is equal to another object/morphism. The trivial
answer is possible if the \mynameref{def:object} is a
\mynameref{def:set}. In the case we can say that 2 objects are equal
if they contain the equivalent collection of elements. Unfortunately
we cannot do the same trick for categorical \mynameref{def:object}s as
soon as they don't have any internal
structure but can use a \mynameref{def:categorical_approach} (see \cref{ch:categorical_approach}) i.e. if we cannot use a ``microscope'' lets
use a ``telescope'' and define the equality of objects and morphisms of
a category $\cat{C}$ in the terms of whole $\cathom{C}$.
\begin{definition}[Objects equality]
\label{def:object_equality}
Two \mynameref{def:object}s $a$ and $b$ in \mynameref{def:category}
$\cat{C}$ are equal if there exists an unique
\mynameref{def:isomorphism} $a \cong_f b$. This also means that
there exists an unique isomorphism $b \cong_g a$. These two
\mynameref{def:morphism}s ($f$ and $g$) are related each other via
the following equations: $f \circ g = \idm{a}$ and $g \circ f
= \idm{b}$.
\end{definition}
Unlike \mynameref{def:function}s between \mynameref{def:set}s we don't
have any additional info
\footnote{
for instance info about sets internals. i.e. which elements of the sets
are connected by the considered functions
}
about \mynameref{def:morphism}s except
category theory axioms which the morphisms satisfy
\cite{bib:stackexchange:morphism:equality}. This leads us to the
following definition of morphims equality:
\begin{definition}[Morphisms equality]
\label{def:morphism_equality}
Two \mynameref{def:morphism}s $f$ and $g$ in \mynameref{def:category}
$\cat{C}$ are equal if the equality can be derived from the base axioms:
\begin{itemize}
\item \mynameref{axm:composition}
\item \mynameref{axm:associativity}
\item \mynameref{def:id}: \eqref{eq:leftid}, \eqref{eq:rightid}
\end{itemize}
or \mynameref{def:commutative_diagram}s which postulate the equality.
\end{definition}
As an example lets proof the following theorem
\begin{theorem}[Identity is unique]
\label{thm:identity_unique}
The \mynameref{def:id} is unique.
\begin{proof}
Consider an \mynameref{def:object} $a$ and it's \mynameref{def:id}
$\idm{a}$. Assume existence of a function $f: a \to a$ such that $f$ is also
identity. \eqref{eq:leftid}, for $f$ as identity, gives us
\[
f \circ \idm{a} = \idm{a}.
\]
From other side \eqref{eq:rightid} for $\idm{a}$ satisfied
\[
f \circ \idm{a} = f
\]
i.e.
\[
f = f \circ \idm{a} = \idm{a}
\]
or
$f = \idm{a}$.
\end{proof}
\end{theorem}
\section{Initial and terminal objects}
\subsection{Initial object}
\begin{definition}[Initial object]
\label{def:initial_object}
Let $\cat{C}$ is a \mynameref{def:category}, the
\mynameref{def:object} $i \in \catob{C}$ is called
\textit{initial object} if $\forall x \in \catob{C}
\exists! f_x: i \to x \in \cathom{C}$.
\end{definition}
\begin{example}[Initial object][$\cat{Set}$]
\label{ex:set_initial_object}
Note that there is only one function from empty set to any other sets
\cite{bib:proofwiki:Empty_Mapping_is_Unique} that makes the empty set
as the \mynameref{def:initial_object} in \mynameref{def:setcategory}.
\end{example}
\begin{theorem}[Initial object is unique]
\label{thm:initial_object_unique}
Let $\cat{C}$ is a category and $i, i' \in \catob{C}$ two
\mynameref{def:initial_object}s then there exists an unique
\mynameref{def:isomorphism} $u: i \to i'$ (see
\mynameref{def:object_equality})
\begin{proof}
Consider the following \mynameref{def:commutative_diagram} (see
\cref{fig:initial_object_unique}). As soon as $i$ initial object
$\exists! \, u: i \to i'$. From other side $i'$ is also initial object
and therefore $\exists! \, u^{-1}: i' \to i$. Combining them together
via composition we can get $u^{-1} \circ u: i \to i$ and $u \circ
u^{-1}: i' \to i'$. From the fact that $i$ is initial object one can
get that there exists
only one morphism $\idm{i}: i \to i$. The same is the truth for $i'$.
Therefore $u^{-1} \circ u = \idm{i}$ and $u \circ u^{-1} = \idm{i'}$.
These complete the commutative diagram build and finishes the proof.
\begin{figure}
\centering
\begin{tikzpicture}[ele/.style={fill=black,circle,minimum
width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner
sep=-2pt}]
% the texts
\node[ele,label=above:$i$] (i1) at (0,3) {};
\node[ele,label=above:$i'$] (i2) at (3,3) {};
\node[ele,label=below:$i$] (i12) at (3,0) {};
\node[ele,label=below:$i'$] (i22) at (6,0) {};
\draw[->,thick,shorten <=2pt,shorten >=2pt] (i1) to
node[sloped,above]{$u$} (i2);
\draw[->,thick,shorten <=2pt,shorten >=2] (i12) to
node[sloped,above]{$u$} (i22);
\draw[->,thick,shorten <=2pt,shorten >=2] (i1) to
node[sloped,above]{$\idm{i}$} (i12);
\draw[->,thick,shorten <=2pt,shorten >=2] (i2) to
node[sloped,above]{$\idm{i'}$} (i22);
\draw[->,thick,shorten <=2pt,shorten >=2] (i2) to
node[right]{$u^{-1}$} (i12);
\end{tikzpicture}
\caption{Commutative diagram for initial object uniqueness proof}
\label{fig:initial_object_unique}
\end{figure}
\end{proof}
\end{theorem}
\subsection{Terminal object}
\begin{definition}[Terminal object]
\label{def:terminal_object}
Let $\cat{C}$ is a \mynameref{def:category}, the
\mynameref{def:object} $t \in \catob{C}$ is called
\textit{terminal object} if $\forall x \in \catob{C}
\exists! g_x: x \to t \in \cathom{C}$.
\end{definition}
\begin{example}[Terminal object][$\cat{Set}$]
\label{ex:set_terminal_object}
\mynameref{def:terminal_object} in \mynameref{def:setcategory} is a set
with one element i.e \mynameref{def:singleton_set}.
\end{example}
As you can see the initial and terminal objects are opposite each
other. I.e. if $i$ is an \mynameref{def:initial_object} in $\cat{C}$
then it will be \mynameref{def:terminal_object} in
the \mynameref{def:op_category} $\cat{C^{op}}$.
\begin{theorem}[Terminal object is unique]
\label{thm:terminal_object_unique}
Let $\cat{C}$ is a category and $t, t' \in \catob{C}$ two
\mynameref{def:terminal_object}s then there exists an unique
\mynameref{def:isomorphism} $v: t' \to t$ (see
\mynameref{def:object_equality})
\begin{proof}
Just got to the \mynameref{def:op_category} and revert
\mynameref{def:arrow}s in
\cref{fig:initial_object_unique}. The result shown on
\cref{fig:terminal_object_unique} and it proofs the theorem statement.
\begin{figure}
\centering
\begin{tikzpicture}[ele/.style={fill=black,circle,minimum
width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner
sep=-2pt}]
% the texts
\node[ele,label=above:$t$] (t1) at (0,3) {};
\node[ele,label=above:$t'$] (t2) at (3,3) {};
\node[ele,label=below:$t$] (t12) at (3,0) {};
\node[ele,label=below:$t'$] (t22) at (6,0) {};
\draw[->,thick,shorten <=2pt,shorten >=2pt] (t2) to
node[sloped,above]{$v$} (t1);
\draw[->,thick,shorten <=2pt,shorten >=2] (t22) to
node[sloped,above]{$v^{-1}$} (t12);
\draw[->,thick,shorten <=2pt,shorten >=2] (t12) to
node[sloped,above]{$\idm{t}$} (t1);
\draw[->,thick,shorten <=2pt,shorten >=2] (t22) to
node[sloped,above]{$\idm{t'}$} (t2);
\draw[->,thick,shorten <=2pt,shorten >=2] (t12) to
node[right]{$v^{-1}$} (t2);
\end{tikzpicture}
\caption{Commutative diagram for terminal object uniqueness proof}
\label{fig:terminal_object_unique}
\end{figure}
\end{proof}
\end{theorem}
\subsection{Toy example}
\begin{example}[Toy example]
In our toy example \cref{fig:pl_example} the type String is
\mynameref{def:initial_object} and type Bool is the
\mynameref{def:terminal_object}.
\end{example}
\section{Product and sum}
\label{sec:product_and_sum}
\subsection{Product}
The pair of 2 objects is defined via the \mynameref{def:universalproperty} in
the following way:
\begin{definition}[Product]
\label{def:product}
Let we have a category $\cat{C}$ and $c_1, c_2 \in \catob{C}$ -two
\mynameref{def:object}s then the product of the objects $c_1, c_2$ is
another object in $\cat{C}$ $c = c_1 \times c_2$ with 2
\mynameref{def:morphism}s $\pi_1, \pi_2$ such that $c_1 = \pi_1(c),
c_2 = \pi(c)$ and the
following universal property is satisfied: $\forall c' \in \catob{C}$
and morphisms $\pi'_1: c' \to c_1, \pi'_2: c' \to c_2$, exists unique
morphism $h$ such that the following diagram (see \cref{fig:product})
commutes, i.e.
\begin{eqnarray}
\pi'_1 = \pi_1 \circ h,
\nonumber \\
\pi'_2 = \pi_2 \circ h.
\label{eq:product}
\end{eqnarray}
\begin{figure}[H]
\centering
\begin{tikzpicture}[ele/.style={fill=black,circle,minimum
width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner
sep=-2pt}]
% the texts
\node[ele,label=left:$c_1$] (a) at (0,0) {};
\node[ele,label=right:$c_2$] (b) at (4,0) {};
\node[ele,label=below:$c$] (c) at (2,0) {};
\node[ele,label=above:$c'$] (c') at (2,3) {};
\draw[->,thick,shorten <=2pt,shorten >=2pt] (c) to
node[sloped,above]{$\pi_1$} (a);
\draw[->,thick,shorten <=2pt,shorten >=2] (c) to
node[sloped,above]{$\pi_2$} (b);
\draw[->,thick,shorten <=2pt,shorten >=2] (c') to
node[sloped,above]{$\pi'_1$} (a);
\draw[->,thick,shorten <=2pt,shorten >=2] (c') to
node[sloped,above]{$\pi'_2$} (b);
\draw[->,thick,shorten <=2pt,shorten >=2] (c') to
node[right]{$h$} (c);
\end{tikzpicture}
\caption{Product $c = c_1 \times c_2$. $\forall c, \exists! h \in
\cathom{C}: \pi'_1 = \pi_1 \circ h, \pi'_2 = \pi_2 \circ h$.}
\label{fig:product}
\end{figure}
In other words $h$ factorizes $\pi'_{1,2}$.
\end{definition}
\begin{example}[Product][$\cat{Set}$]
\label{ex:set_product}
\mynameref{def:cartesian_product}: $C = A \times B = \{(a,b)| a \in
A, b \in B\}$ is the \mynameref{def:product} of two sets $A$ and $B$ in
\mynameref{def:setcategory}.
We have only one option for $\pi_{1,2}$:
\begin{eqnarray}
\pi_1 : (a,b) \to a \in A,
\nonumber \\
\pi_2 : (a,b) \to b \in B.
\nonumber
\end{eqnarray}
Consider also another candidate: $C' = A \times A
\times B \times B =
\{(a_1,a_2,b_1, b_2)| a_{1,2} \in A, b_{1,2} \in B\}$.
There are different options for $\pi'_1$ and $\pi'_2$. Lets choose the
following ones:
\begin{eqnarray}
\pi'_1 : (a_1,a_2,b_1, b_2) \to a_1 \in A,
\nonumber \\
\pi'_2 : (a_1,a_2,b_1, b_2) \to b_2 \in B.
\nonumber
\end{eqnarray}
We have only one morphism $h$ that satisfied conditions
\eqref{eq:product}:
\[
h: (a_1,a_2,b_1, b_2) \to (a_1, b_2) \in A \times B
\]
that is accordingly with the \mynameref{def:product} definition for $C = A
\times B$.
If $C'$ had been the \mynameref{def:product} then it would have
satisfied the following factorization conditions:
\begin{eqnarray}
\pi_1 = \pi'_1 \circ h',
\nonumber \\
\pi_2 = \pi'_2 \circ h',
\label{eq:productex}
\end{eqnarray}
where $h'$ would have been an unique morphism.
From other side there are a lot of morphisms $h'$ which factorize
$\pi_{1,2}$ accordingly \eqref{eq:productex}:
\[
h' : (a,b) \to (a, \bar{a}, \bar{b}, b),
\]
where $\bar{a}$ can be replaced with any element from $A$ and
$\bar{b}$ can be replaced with any element of $B$. Therefore $C'$ can
not be considered as the \mynameref{def:product} of $A$ and $B$.
\end{example}
The \mynameref{def:product} of objects will provide also a definition
for product of morphisms
\begin{definition}[Product of morphisms]
\label{def:product_of_morphisms}
Let $\cat{C}$ is a category and $a,a' \in \catob{C}$ and
$b, b' \in \catob{C}$ are 2 pairs of \mynameref{def:object}s that admit
\cref{def:product}. Consider 2 morphisms that connects the objects:
$f: a \to b, f': a' \to b'$ then we can create a new unique morphism that
connects the products: $f \times f': a \times a' \to b \times b'$ and
makes the diagram commute (see \cref{fig:product_of_morphisms}).
\begin{figure}[H]
\centering
\begin{tikzpicture}[ele/.style={fill=black,circle,minimum
width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner
sep=-2pt}]
% the texts
\node[ele,label=above:$a$] (a) at (0,2) {};
\node[ele,label=above:$a \times a'$] (aa') at (2,2) {};
\node[ele,label=above:$a'$] (a') at (4,2) {};
\node[ele,label=below:$b$] (b) at (0,0) {};
\node[ele,label=below:$b \times b'$] (bb') at (2,0) {};
\node[ele,label=below:$b'$] (b') at (4,0) {};
\draw[->,thick,shorten <=2pt,shorten >=2pt] (a) to
node[sloped,above]{$f$} (b);
\draw[->,thick,shorten <=2pt,shorten >=2pt] (a') to
node[sloped,above]{$f'$} (b');
\draw[->,thick,shorten <=2pt,shorten >=2pt] (aa') to
node[sloped,above]{$f \times f'$} (bb');
\draw[->,thick,shorten <=2pt,shorten >=2pt] (aa') to
node[sloped,above]{$\pi_a$} (a);
\draw[->,thick,shorten <=2pt,shorten >=2] (aa') to
node[sloped,above]{$\pi_{a'}$} (a');
\draw[->,thick,shorten <=2pt,shorten >=2pt] (bb') to
node[sloped,above]{$\pi_b$} (b);
\draw[->,thick,shorten <=2pt,shorten >=2] (bb') to
node[sloped,above]{$\pi_{b'}$} (b');
\end{tikzpicture}
\caption{Product of morphisms.}
\label{fig:product_of_morphisms}
\end{figure}
\end{definition}
\subsection{Sum}
If we invert \mynameref{def:arrow}s in \mynameref{def:product} we shall
got another
object definition that is called sum
\begin{definition}[Sum]
\label{def:sum}
Let we have a category $\cat{C}$ and $c_1, c_2 \in \catob{C}$ -two
\mynameref{def:object}s then the sum of the objects $c_1, c_2$ is
another object in $\cat{C}$ $c = c_1 \oplus c_2$ with 2
\mynameref{def:morphism}s $i_1, i_2$ such that $c = i_1(c_1), c = i_2
(c_2)$ and the
following \mynameref{def:universalproperty} is satisfied: $\forall c'
\in \catob{C}$
and morphisms $i'_1: c_1 \to c', i'_2: c_2 \to c'$, exists unique
morphism $h$ such that the following diagram (see \cref{fig:sum})
commutes, i.e. $i'_1 = h \circ i_1, i'_2 = h \circ i_2$.
\begin{figure}[H]
\centering
\begin{tikzpicture}[ele/.style={fill=black,circle,minimum
width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner
sep=-2pt}]
% the texts
\node[ele,label=left:$c_1$] (a) at (0,0) {};
\node[ele,label=right:$c_2$] (b) at (4,0) {};
\node[ele,label=below:$c$] (c) at (2,0) {};
\node[ele,label=above:$c'$] (c') at (2,3) {};
\draw[->,thick,shorten <=2pt,shorten >=2pt] (a) to
node[sloped,above]{$i_1$} (c);
\draw[->,thick,shorten <=2pt,shorten >=2] (b) to
node[sloped,above]{$i_2$} (c);
\draw[->,thick,shorten <=2pt,shorten >=2] (a) to
node[sloped,above]{$i'_1$} (c');
\draw[->,thick,shorten <=2pt,shorten >=2] (b) to
node[sloped,above]{$i'_2$} (c');
\draw[->,thick,shorten <=2pt,shorten >=2] (c) to
node[right]{$h$} (c');
\end{tikzpicture}
\caption{Sum $c = c_1 \oplus c_2$. $\forall c, \exists! h \in
\cathom{C}: i'_1 = h \circ i_1, i'_2 = h \circ i_2 $.}
\label{fig:sum}
\end{figure}
In other words $h$ factorizes $i'_{1,2}$.
The categorical sum is also called as \textit{coproduct}.
\index{coproduct}
\end{definition}
\begin{definition}[Disjoint union]
\label{def:disjoint_union}
Let $\{A_i: i \in I\}$ be a family of sets
indexed by $I$. The
\textit{disjoint union} \cite{wiki:disjointunion} of this family is
the set
\[
\sqcup_{i \in I} A_i = \cup_{i \in I}\left\{
\left(x, i\right): x \in A_i
\right\}.
\]
The elements of the disjoint union are ordered pairs $(x, i)$. Here $i$
serves as an auxiliary index that indicates which $A_i$ the element $x$
came from.
\end{definition}
\begin{example}[Sum][$\cat{Set}$]
\label{ex:set_sum}
\mynameref{def:disjoint_union} is the \mynameref{def:sum} of two sets $A$ and $B$ in
\mynameref{def:setcategory}.
\end{example}
\begin{remark}[Sum sign]
In the book we shall use $\oplus$ as the sign for the categorical
\mynameref{def:sum}. The \mynameref{def:disjoint_union} sign $\sqcup$
is also used
\footnote{but not in the book} as the sign for categorical sum
\cite{wiki:coproduct}.
\end{remark}
\section{Category as a monoid}
\label{sec:category_as_monoid}
Consider the following definition from abstract algebra
\begin{definition}[Monoid]
\label{def:monoid}
The set of elements $M$ with defined binary operation $\circ$ we shall call
as a monoid if the following conditions are satisfied.
\begin{enumerate}
\item Closure: $\forall a, b \in M$: $a \circ b \in M$
\item Associativity: $\forall a, b, c \in M:$
\begin{equation}
\label{eq:monoid_associativity}
a \circ \left( b \circ c \right) =
\left( a \circ b \right) \circ c
\end{equation}
\item Identity element: $\exists e \in M$ such that $\forall a \in M$:
\begin{equation}
\label{eq:monoid_identity_element}
e \circ a = a \circ e = a
\end{equation}
\end{enumerate}
\end{definition}
\begin{example}[Monoid]
\mynameref{def:monoid} concept is widely spread in math. Especially
integer numbers form a monoid under summation operation. They also
form another monoid under multiplication operation. The element
\textbf{0} is used as identity in summation and \textbf{1} is used as
the identity in multiplication.
\end{example}
\begin{example}[Monoid][$\cat{Hask}$]
There is an declaration of Monoid in $\cat{Hask}$ category
\begin{minted}{haskell}
class Monoid m where
mappend :: m -> m -> m
mempty :: m
\end{minted}
There is a binary operation \textbf{mappend} and the identity
\textbf{mempty}. As it was mentioned in the \mynameref{def:monoid}
definition (see \cref{def:monoid}), the binary operation should
satisfy the associativity \eqref{eq:monoid_associativity} and identity
element \eqref{eq:monoid_identity_element} properties. This is a
responsibility of a particular implementation to satisfy the
properties. For instance the standard list implementation satisfies
them:
\begin{minted}{haskell}
instance Monoid [a] where
mappend = (++)
mempty = []
\end{minted}
\end{example}
\begin{remark}[Monoid]
The given definition of monoid is based on its internal structure i.
e. there is a \mynameref{def:non_categorical_approach}. In
\cref{ch:monoid_categorically} we shall continue the
\mynameref{def:monoid} concept investigation and will give a
\mynameref{def:categorical_approach} of the concept. You can also find
there
some notes about the concept importance in different areas
such as programming languages and math (see
\cref{ch:monoid_importance_monad}).
\end{remark}
We can consider 2 \mynameref{def:monoid}s. The first one has
\mynameref{def:product} as the binary operation and
\mynameref{def:terminal_object} as the identity element. As result we
just got an analog of multiplication in the category theory. This is why
the terminal object is often denoted as $\mathbf{1}$ and the operation
is called as the product.
Another one is additional \mynameref{def:monoid} that has
\mynameref{def:initial_object} as the identity element and the
\mynameref{def:sum} as the binary operation. The initial object in
that case is often denoted as $\mathbf{0}$. I.e. we can see a direct
connection with addition in algebra.
If we do such consideration then we can make a step forward and look
at the distributive law that sum and multiplication satisfy.
\begin{definition}[Distributive category]
\label{def:distributive_category}
A category $\cat{C}$ is \textit{distributive} if
\cite{wiki:distributive_category}
it has finite
\mynameref{def:product}s and \mynameref{def:sum}s such that
$\forall a,b,c \in \catob{C}$:
\[
(a \times b) \oplus (a \times c) \cong a \times ( b \oplus c )
\]
and
\[
a \times 0 \cong 0
\]
where $\mathbf{0}$ is the \mynameref{def:initial_object}.
\end{definition}
\begin{example}[Distributive category]
\label{ex:distributive_category}
\mynameref{def:setcategory} is an example
\cite{wiki:distributive_category}
of \mynameref{def:distributive_category}
From other hand not all categories which have both product and sum are
distributive. One of such example is a category of all groups
$\cat{Grp}$ \cite{wiki:distributive_category} where groups are
considered as objects and group homomorphisms as morphisms.
\end{example}
\section{Exponential}
We are going to talk about functions (aka morphisms) as
\mynameref{def:object}s.
\subsection{Definition and examples}
\begin{example}[Homset]
\label{ex:homset}
Consider 2 sets $A$ and $B$ then the set of functions between the 2 sets
forms a new set that is called as \mynameref{def:homset} and denoted
as $\catmset{A}{B}$. Thus if $A,B \in \catob{Set}$ then
$\catmset{A}{B} \in \catob{Set}$.
\end{example}
The construction of \mynameref{def:homset} is applied to
the \mynameref{def:setcategory} but not to an arbitrary category because
the \mynameref{def:homset} is a \mynameref{def:set} and therefore the
object in the \mynameref{def:setcategory}. I.e. if $\cat{C}$ is a
category and $a, b \in \catob{C}$
then the \mynameref{def:homset} $\catmset{a}{b} \in \catob{Set}$ but
we now want to construct something like to the \mynameref{def:homset}
but that is an object in $\cat{C}$. This will be called as the
function object. we shall use the universal construction
(\mynameref{def:universalproperty}) for the object definition.
\begin{definition}[Exponential]
\label{def:exponential}
\begin{figure}
\centering
\begin{tikzpicture}[ele/.style={fill=black,circle,minimum
width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner
sep=-2pt}]
% the texts
\node[ele,label=above:$y'$] (z1) at (0,3) {};
\node[ele,label=below:$y^x$] (zy) at (0,0) {};
\node[ele,label=above:$y' \times x$] (z1y) at (3,3) {};
\node[ele,label=below:$y^x \times x$] (zyy) at (3,0) {};
\node[ele,label=below:$y$] (z) at (6,0) {};
\draw[->,thick,shorten <=2pt,shorten >=2pt] (z1) to
node[left]{$h$} (zy);
\draw[->,thick,shorten <=2pt,shorten >=2] (z1y) to
node[left]{$h \times \idm{x}$} (zyy);
\draw[->,thick,shorten <=2pt,shorten >=2] (z1y) to
node[sloped,above]{$e'$} (z);
\draw[->,thick,shorten <=2pt,shorten >=2] (zyy) to
node[sloped,above]{$e$} (z);
\end{tikzpicture}
\caption{Exponential object}
\label{fig:exponential}
\end{figure}
Let $\cat{C}$ is a category and $x, y \in \catob{C}$. We also assume
that $\cat{C}$ allows all \mynameref{def:product}s with $x$, i.e.
$\forall y' \in \catob{C}, \exists y' \times x$. An object $y^x$
together with a \mynameref{def:morphism} $e: y^x \times x \to y$ is
an \textit{exponential object} if $\forall e' \in \cathom{C}$ and
$\forall y' \in \catob{C}$ exists an
unique morphism $h: y' \to y$ such that the
\mynameref{def:commutative_diagram} shown in \cref{fig:exponential}
commutes:
\[
e' = e \circ \left(h \times \idm{x} \right)
\]
\end{definition}
\begin{example}[Exponential][$\cat{Set}$]
\label{ex:exponential_set}
Lets look at the \mynameref{def:exponential} in $\cat{Set}$. We want
to show that the object corresponds to the function. Really if we want
to define a function $f: X \to Y$ then we should look at the
\mynameref{def:homset} $F = \catmset{X}{Y}$. $f \in F$ - is an element of the
\mynameref{def:homset}. For the function application we have to take
the argument $x
\in X$ and the function we want to apply $f \in F$. Then we construct
the pair $(f,x) \in F \times X$. For the function application we have
to call a \mynameref{def:morphism} $e: F \times X \to Y$.
\footnote{$e$ from the word ``eval''}
I.e. the
application $e(f, x)$ gives us $e(f, x) = y \in Y$ - the function
value.
\end{example}
The notation is used for ``morphisms (functions) as objects'' in the
category theory has an explanation provided in the following remark.
\begin{remark}[Exponential notation]
The \mynameref{def:homset} $\catmset{X}{Y}$ is often denoted as $Y^X$.
Why the strange notation is used?
Lets $X$ is a \mynameref{def:singleton_set} i.e. its
\mynameref{def:cardinality} is $1$: $\left|X\right| = 1$.
The set $Y$ has only 2
elements, i.e. its \mynameref{def:cardinality} is $2$:
$\left|Y\right|= 2$.
Consider a function $f: X \to Y$. How many such functions do we have?
There are really 2 functions (see \cref{fig:exponential_set_remark_x_y}).
One of them $f_1$ return the first element
from $Y$ ($y_1$) and the other $f_2$ returns the second one ($y_2$).
The number of functions can be written as
$2^1$. I.e. one can write for \mynameref{def:cardinality} of a set of
all functions between $X$ and $Y$ as follows
\begin{equation}
\label{eq:exponential_size}
\left|Y^X\right| = \left|Y\right|^{\left|X\right|}.
\end{equation}
\begin{figure}[H]
\centering
\begin{tikzpicture}[ele/.style={fill=black,circle,minimum
width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner
sep=-2pt}]
% the texts
\node at (0,5) {$X$};
\node at (4,5) {$Y$};
\node[ele,label=left:$x$] (x) at (0,4) {};
\node[ele,,label=right:$y_1$] (y1) at (4,4) {};
\node[ele,,label=right:$y_2$] (y2) at (4,3) {};
\node[draw,fit= (x),minimum width=1.5cm, minimum height= 1.5cm] {} ;
\node[draw,fit= (y1) (y2),minimum width=2cm, minimum height= 2cm] {} ;
\draw[->,thick,shorten <=2pt,shorten >=2pt] (x) to
node[sloped,above]{$f_1$} (y1);
\draw[->,thick,shorten <=2pt,shorten >=2] (x) to
node[sloped,below]{$f_2$} (y2);
\end{tikzpicture}
\caption{$\catmset{X}{Y}$ consists of 2 elements: $\{f_1, f_2\}$.
Thus the cardinality of the homset is $2$}
\label{fig:exponential_set_remark_x_y}
\end{figure}
Otherwise if we consider a function $g: Y \to X$ then we have only one
possible choice for it (see \cref{fig:exponential_set_remark_y_x}) : just return the only possible element from
$X$. I.e. $\left|X^Y\right| = 1$ that correlates with
\eqref{eq:exponential_size}.
\begin{figure}[H]
\centering
\begin{tikzpicture}[ele/.style={fill=black,circle,minimum
width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner
sep=-2pt}]
% the texts
\node at (0,5) {$X$};
\node at (4,5) {$Y$};
\node[ele,label=left:$x$] (x) at (0,4) {};
\node[ele,label=right:$y_{1,2}$] (y) at (4,4) {};
\node[draw,fit= (x),minimum width=1.5cm, minimum height= 1.5cm] {} ;
\node[draw,fit= (y),minimum width=1.5cm, minimum height= 1.5cm] {} ;
\draw[->,thick,shorten <=2pt,shorten >=2pt] (y) to
node[sloped,above]{$g$} (x);
\end{tikzpicture}
\caption{$\catmset{Y}{X}$ consists of 1 element: $\{g\}$.
Thus the cardinality of the homset is $1$}
\label{fig:exponential_set_remark_y_x}
\end{figure}
\end{remark}
\subsection{Currying in $\cat{Set}$}
In the section we shall be in the \mynameref{def:setcategory}.
The definition of \mynameref{def:exponential} object is closely
related to notion of currying that is defined for \mynameref{def:set}s
as follows.
\begin{definition}[Currying]
\label{def:currying_set}
Consider a function of 2 arguments:
\[
f:(X\times Y) \to Z
\]
that maps a pair (\mynameref{def:product}) of 2 sets $X$ and $Y$ into
another set $Z$.
The \textit{currying} constructs a new function
\[
h : X \to (Y \to Z)
\]
such that the following equation holds
\[
h(x)(y) = f(x,y),
\]
where $x \in X, y \in Y$. The \textit{currying} will be denoted as
$h = curry(f)$.
\end{definition}
\begin{remark}[Currying]
If we consider $Y^X$ is a set of functions $f : X \to Y$ then the
currying is the \mynameref{def:bijection}
\[
Y^{X_1 \times X_2} \cong \left(Y^{X_1}\right)^{X_2}.
\]
\end{remark}
\begin{remark}[Currying and Exponential]
If we look in \cref{fig:exponential} then we can notice that
\[
curry(e): y^x \to (x \to y),
\]
i.e. currying is used to construct a morphisms from exponential
object.
\end{remark}
\subsection{Cartesian closed category}
\begin{definition}[Cartesian closed category]
\label{def:cartesian_closed_category}
If a category $\cat{C}$ satisfies the following conditions then it is
called \textit{Cartesian closed category}
\begin{enumerate}
\item It has \mynameref{def:terminal_object}
\item $\forall a,b \in \catob{C}$ exists \mynameref{def:product} $a
\times b \in \catob{C}$.
\item $\forall a,b \in \catob{C}$ exists \mynameref{def:exponential}
$a^b \in \catob{C}$
\end{enumerate}
\end{definition}
\begin{theorem}[Cartesian closed category]
\label{thm:ccc}
If $\cat{C}$ is a \mynameref{def:cartesian_closed_category} with
finite \mynameref{def:sum} then it is a
\mynameref{def:distributive_category}.
\begin{proof}
TBD
\end{proof}
\end{theorem}
\section{Programming language examples. Type algebra}
\subsection{$\cat{Hask}$ category}
\begin{example}[Initial object][$\cat{Hask}$]
If we avoid lazy evaluations in Haskell (see
\mynameref{rem:hask_lazy_eval}) then we can found several types
as candidates for initial and terminal object in Haskell.
\label{ex:hask_initial_object}
\mynameref{def:initial_object} in \mynameref{def:haskcategory} is a
type without values
\begin{minted}{haskell}
data Void
\end{minted}
i.e. you cannot construct a object of the type.
There is only one function from the initial object:
\begin{minted}{haskell}
absurd :: Void -> a
\end{minted}
The function is called absurd because it does absurd action. Nobody
can proof that it does not exist. For the existence proof the
following absurd argument can be used: ``Just provide me an object type
\textbf{Void} and I will provide you the result of
evaluation''.
There is no function in opposite direction because it would had been
used for the \textbf{Void} object creation.
\end{example}
\begin{example}[Terminal object][$\cat{Hask}$]
\label{ex:hask_terminal_object}
Terminal object (unit) in \mynameref{def:haskcategory} keeps only one element
\begin{minted}{haskell}
data () = ()
\end{minted}
i.e. you can create only one element of the type. You can use the
following function for the creation:
\begin{minted}{haskell}
unit :: a -> ()
unit _ = ()
\end{minted}
\end{example}
\begin{example}[Product][$\cat{Hask}$]
\label{ex:hask_product}
The \mynameref{def:product} in \mynameref{def:haskcategory} keeps a
pair and the constructor defined as follows
\begin{minted}{haskell}
(,) :: a -> b -> (a, b)
(,) x y = (x, y)
\end{minted}
There are 2 projectors:
\begin{minted}{haskell}
fst :: (a, b) -> a
fst (x, _) = x
snd :: (a, b) -> b
snd (_, y) = y
\end{minted}
\end{example}
\begin{example}[Sum][$\cat{Hask}$]
\label{ex:hask_sum}
The \mynameref{def:sum} in \mynameref{def:haskcategory} defined as
follows
\begin{minted}{haskell}
data Either a b = Left a | Right b
\end{minted}
The typical usage is via pattern matching for instance
\begin{minted}{haskell}
factor :: (a -> c) -> (b -> c) -> Either a b -> c
factor f _ (Left x) = f x
factor _ g (Right y) = g y
\end{minted}
\end{example}
\begin{example}[Distributive category][$\cat{Hask}$]
As soon as $\cat{Hask}$ is a \mynameref{def:cartesian_closed_category}
then by \cref{thm:ccc} it is a \mynameref{def:distributive_category}
i.e. one can conclude that
\begin{minted}{haskell}
(a,Either b c)
\end{minted}
is the same to
\begin{minted}{haskell}
Either (a, b) (a, c)
\end{minted}
\end{example}
\begin{example}[Exponential][$\cat{Hask}$]
\label{ex:exponential_hask}
It's not surprisingly that the \mynameref{def:exponential} in
$\cat{Hask}$ is a function object i.e. $b^a$ can be written as
\textbf{a -> b}.
\end{example}
\begin{example}[Type algebra]
\cref{ex:exponential_hask} gives interesting results with types
manipulations. For instance the type $a^{b+c}$ can be written as
\begin{minted}{haskell}
Either b c -> a
\end{minted}
for the function we should have both functions
\textbf{b -> a} and \textbf{b -> c}. I.e.
the code is equivalent to the following one
\begin{minted}{haskell}
(b -> a, c -> a)
\end{minted}
These transformations correspond to the following simple algebraic
equation
\[
a^{b+c} = a^b a^c.
\]
This is also called as \textit{type algebra}.
\end{example}
\subsection{$\cat{C\texttt{++}}$ category}
\begin{example}[Initial object][$\cat{C\texttt{++}}$]
\label{ex:cpp_initial_object}
In C\texttt{++} exists a special type that does not hold any values and as
result cannot be created: \textbf{void}.
You cannot create an object of that type i.e. you will get a compiler
error if you try.
\end{example}
\begin{example}[Terminal object][$\cat{C\texttt{++}}$]
\label{ex:cpp_terminal_object}
C\texttt{++} 17 introduced a special type that keeps only one value -
\textbf{std::monostate}:
\begin{minted}{c++}
namespace std {
struct monostate {};
}
\end{minted}
\end{example}
\begin{example}[Product][$\cat{C\texttt{++}}$]
\label{ex:cpp_product}
The \mynameref{def:product} in \mynameref{def:cppcategory} keeps a
pair and the constructor defined as follows
\begin{minted}{c++}
namespace std {
template< class A, class B > struct pair {
A first;
B second;
};
}
\end{minted}
There is a simple usage example
\begin{minted}{c++}
std::pair<int, bool> p(0, false);
std::cout << "First projector: " << p.first << std::endl;
std::cout << "Second projector: " << p.second << std::endl;
\end{minted}
Really any \textbf{struct} or \textbf{class} can be
considered as a product.
\end{example}
\begin{example}[Sum][$\cat{C\texttt{++}}$]
\label{ex:cpp_sum}
If we consider \mynameref{def:object}s as types then
\mynameref{def:sum} is an object that can be either one or another
type. The corresponding C/C\texttt{++} construction that provides an ability
to keep one of two types is \textbf{union}.
%% There is an \textbf{Either} implementation from
%% \mynameref{ex:hask_sum}
%% \begin{minted}{c++}
%% template <typename A, typename B> class Either
%% {
%% public:
%% Either(const Either& e) : is_left_(e.is_left_){
%% if (is_left_){
%% data.l = e.data.l;
%% } else {
%% data.r = e.data.r;
%% }
%% }
%% ~Either(){
%% if (is_left_){
%% data.l.~A();
%% } else {
%% data.r.~B();
%% }
%% }
%% Either(const A& l) : data(l), is_left_(true){
%% }
%% Either(const B& r) : data(r), is_left_(false){
%% }
%% const A& left() const {
%% if (!is_left_){
%% throw std::logic_error("no left");
%% }
%% return data.l;
%% }
%% const B& right() const {
%% if (is_left_){
%% throw std::logic_error("no right");
%% }
%% return data.r;
%% }
%% private:
%% union Data {
%% Data() {}
%% Data( const A& a) : l(a) {}
%% Data (const B& b) : r(b) {}
%% ~Data() {}
%% A l;
%% B r;
%% } data;
%% bool is_left_;
%% };
%% \end{minted}
%% The usage example:
%% \begin{minted}{c++}
%% template <typename A, typename B, typename C, typename D>
%% auto factor(A f, B g, const Either<C, D>& either) {
%% try {
%% return f(either.left());