Saturday, September 5, 2020

Kleisli categories and matrices

Our goal is to express (some of the most basic ideas of linear algebra (LA)) using (the concepts and terminology of Kleisli categories).
$\newcommand\Vect{{\mathbf{Vect}}}$
Linear algebra of course is a basic subject on the route from high school mathematics to university mathematics.
On the other hand, Kleisli categories are to many a rather abstract and arcane (but potentially powerful and useful) subject.

By closely examining how (three basic results of LA) are precisely instances of
(three of the axioms which hold in any Kleisli category derived from a monad), 
we can obtain useful and fruitful insights into both situations, 
the one specific and concrete, the other abstract and very general.

-------------------------------

On the strictly linear algebra side, consider the following classic two entities and three equations in LA:

\[\begin{gather} AE = A \\ AX \\ EX = X \\ \\ \target B \source A \\ \target B \source A \source X = (\target B \source A) \source X = \target B( source A \source X) \end{gather}\]

Here $A$, $B$, and $X$ are the not very surprising entities described below.

------------------------------ 

The three equations correspond to the following three VIDs (Very Important Diagrams :-) in $\Set$.

In the following $A$ starts as an $R$-matrix 
$$A : n\times m \to R$$
but then we use the same letter $A$ to denote both that original matrix, and its exponential transpose (i.e. its "curried form"): 
$$A : m \to R^n = [n,R].$$
This is what appears as a diagonal arrow (missing Its head) in the Ascii $\Set$-diagrams.
And likewise for $B : o\times n \to R.$

By the familiar basic argument, $R^m$ is a free real vector space on $m$; likewise for $n, R^n$.
(See, e.g., Mac Lane-Birkhoff, Algebra 3/e, Thm. V.9.)
The vertical arrows are the corresponding embeddings giving the basis of unit vectors in $R^m$ and $R^n$. (By the way, these are Yoneda embeddings.)

The horizontal arrows $\source{ A^\star =  L_A = A\star - }$ and $\target{ B^\star = L_B = B\star - }$ are the linear transformations which extend $\source A$ and $\target B$ respectively.
This the top horizontal arrows actually lie in $\Vect$, the category of vector spaces and linear transformations, while the lower arrows lie in $\Set$.
--------------------------------------------------------
The first axiom/result, corresponding to the equation $AE=A$, 
is that $A^\star$  is an extension of $A$ over the embedding $E$ of the generators into the free object $R^m$.
This is expressed diagramatically by the commutativity of:

<i>MathJax version:</i>

$$\begin{array}{cccccc} \target{R^n} & \xleftarrow[\Vect]{\textstyle{A^\star \equiv L_A \equiv A \star -}} & \source{R^m} \\ & \llap {\text{matrix : } R \leftarrow n\times m : A } \nwarrow \rlap\Set & \source { \Bigg\uparrow \rlap{\eta_m \equiv E_m \equiv Y_m \text{ : unit vectors}} }   \\   \target n & \xleftarrow[\Set_L]{A^\flat} & \source m \end{array}$$

Ascii version:
         A* = L_A = A*-
R^n <----------------------- R^m
     \                                ^
       \                              |
     A \                             | \eta_m = Y_m = E_m
           \                          |
                                .    m


------------------------------------------------------------
The second diagram corresponds to the equation $EX=X$ :

MathJax version:

$$\begin{array}{cccccc} R^m & \xleftarrow[\Vect]{\textstyle{\eta_m^\star \equiv 1_{R^m}}} & R^m \\ & \llap {\text{identity matrix : } \eta_m \equiv E_m \equiv Y_m } \nwarrow \rlap\Set &  \Bigg\uparrow \rlap{\eta_m \equiv E_m \equiv Y_m \text{ : unit vectors}} \\ m & \xleftarrow[\Set_L]{\eta_m{}^\flat} & \source m\end{array}$$

                                     (\eta_m)* = 1_{R^m}
                             R^m <----------------------- R^m 
                                 \                                ^
                   ..              \                              |
\eta_m = Y_m = E_m \                            | \eta_m = Y_m = E_m
                                       \                          |
                                                            .    m
--------------------------------------------------------------
The third diagram corresponds to the equation $\target B (\source A \source X)=(\target B \source A ) \source X$ for all $\source X$.

$$\begin{array}{}  \hom {\target k} { \big( \target B (\source{AX}) \big) } {} & \target{\xlongequal{\textstyle \text{defn $\target{B^\star \equiv L_B}$}}} & \sum\limits_{j\in n} \hom {\target k} {\target B} j \, \hom j {(\source{AX})} {} & \source{\xlongequal{\textstyle \text{defn $A^\star \equiv L_A$}}} & \sum\limits_{j\in n} \hom {\target k} {\target B} j \, ( \source{\sum\limits_{i\in m}} \hom j {\source A} {\source i} \, \source{\hom i X {}} ) \\  &&&& \Vert \rlap {\text{ dist.}} \\ &&&&  \sum\limits_{j\in n} \source{\sum\limits_{i\in m}} \hom {\target k} {\target B} j \, \hom j {\source A} {\source i} \,  \source{\hom i X {}} \\   &&&& \Vert \rlap {\text{ Fubini}} \\  &&&&  \source{\sum\limits_{i\in m}} \sum\limits_{j\in n} \hom {\target k} {\target B} j \, \hom j {\source A} {\source i} \, \source{\hom i X {}}  \\   &&&& \Vert \rlap {\text{ dist.}} \\ \hom {\target k} { \big( (\target B \source A) \source X \big) } {} & \xlongequal{\textstyle \text{defn $(\target B \source A)^\star \equiv L_{(\target B \source A)}$}} & \source{\sum\limits_{i\in m}} \hom {\target k} {(\target B \source A)} {\source i} \, \source{\hom i X {}} & \xlongequal{\textstyle \text{defn $\target B \source A$}}  &  \source{\sum\limits_{i\in m}} (\sum\limits_{j\in n} \hom {\target k} {\target B} j \, \hom j {\source A} {\source i} ) \, \source{\hom i X {}} \\ \end{array}$$

$$\begin{array}{cccccc} && {}\rlap{ \kern-14em \target B Y \target\equiv \target{\Big(} \hom {\target k} {\target{\big(}\target B Y\target{\big)}} {} \target{\Big)}_{\target{k\in o}} \target\equiv \target{\Big(} \sum\limits_{j\in n} \hom {\target k} {\target B} j \, \hom j Y {} \target{\Big)}_{\target{k\in o}} } &  {} \rlap{\kern-1em\leftarrow\!\shortmid} & {} \rlap{ \kern-2em Y \equiv (\hom j Y {})_{j\in n} }    \\    && {} \rlap { \kern-16em \target B \source{(AX)} \target\equiv \target{\Big(} \hom {\target k} {\target{\big(} \target B \source{(AX)} \target{\big)}} {} \target{\Big)}_{\target{k\in o}}  \target\equiv \target{\Big( \text{see above} \Big)_{k\in o}}  } & \kern-4em \leftarrow\!\shortmid &  {}\rlap{ \kern-6em  \source{AX} \equiv  \big( \hom j {\source{(AX)}} {} \big)_{j\in n} \equiv \big( \source{\sum\limits_{i\in m}} \hom j {\source A} {\source i} \, \hom {\source i} {\source X} {} \big)_{j\in n}  }  & \kern8em\leftarrow\!\shortmid & {} \rlap { \kern-1em \source{ X \equiv (\hom i X {})_{i\in m} } }    \\   \target{B^\star}\source{A^\star} \equiv \target{L_B}\source{L_A} & \mskip2em & \target{R^o} & \target{\xleftarrow[\Vect]{\textstyle{B^\star \equiv L_B \equiv B \star -}}} & R^n & \source{\xleftarrow[\Vect]{\textstyle{A^\star \equiv L_A \equiv A \star -}}} & \source{R^m}    \\    \llap { \text{(for this computation, see the above) } } \Bigg\Vert && & \target{ \llap {\text{matrix : } R \leftarrow o\times n : B } \nwarrow \rlap\Set } & \Bigg\uparrow \rlap{\eta_n} & \source{ \llap {A} \nwarrow \rlap\Set } & \source { \Bigg\uparrow \rlap{\eta_m \equiv E_m \equiv Y_m \text{ : unit vectors}} }   \\   (\target{B^\star}\source A)^\star = (\target B \source A)^\star \equiv L_{\target B \source A} && \target o & \target{ \xleftarrow[\Set_L]{\textstyle B^\flat} } & n & \source{ \xleftarrow[\Set_L]{\textstyle A^\flat} } & \source m  \end{array}$$

         B* = L_B          A* = L_A 
R^o <------------- R^n  <------------- R^m                B*A* = L_BL_A
       \                   ^    \                ^        \ X
       B\                 |    A\              |    ≠     1            ||
            \               |        \            |        / i
                            n                    m                   (B*A)* = L_{BA}

-----------------------------------
In conclusion, let me mention that the above description of the Kleisli category is another example of 
what Ernest Manes described on page 1 of his "Algebraic Theories".
------------------------------------

References

https://en.wikipedia.org/wiki/Kleisli_category
Ernie Manes, Algebraic Theories


----------

Note:
if you are viewing this in an Android phone, 
in order for the MathJax to be interpreted 
you must use the"View web version" option.

----------------
$ \flat \sharp \natural$


-----------------

The following is merely an instructive example of matrix composition:


$$ \begin{array}{} && 1   \\   & \llap { \text {row sum = horizontal composition } {a+b \choose c+d} } \swarrow & \Bigg\downarrow \rlap { {1 \choose 1} = {x^1 \choose x^2} = \mathbf x = X, \text{ vector} }    \\   \llap{ (a+b)+(c+d) \kern2em}  2 & \xleftarrow{ \left( \begin{smallmatrix} a & b \\ c & d \\ \end{smallmatrix} \right) } & 2  \rlap { \kern2em (a+c)+(b+d) }  \\    \llap {  \text{covector } \mathbf a = (a_1, a_2) = (1 \kern8mu 1) \, } \Bigg\downarrow  & \swarrow \rlap { ( a+c \kern12mu b+d ) \text{ column sum = vertical composition} }  \\     1   \\  \end{array} $$