Relations and matrices [00IR]
- January 17, 2024
- Jon Sterling, with contributions from Marcelo Fiore
Relations between finite sets can be desribed in a more computationally friendly way by their tabulation as matrices. In particular, we shall see in § [00J1] that an {\mathopen {}\left (m\times n\right )\mathclose {}}-matrix over the boolean semiring is precisely the same thing as a relation from {\mathopen {}\left [m\right ]\mathclose {}} to {\mathopen {}\left [n\right ]\mathclose {}}, where {\mathopen {}\left [l\right ]\mathclose {}}={\mathopen {}\left \{i\mid 0\leq i < l\right \}\mathclose {}} is the set of natural numbers strictly smaller than l. Then we will see that relational composition is, under this correspondence, the same as matrix multiplication.
Definition Matrix over a semiring [00IS]
- January 17, 2024
- Jon Sterling, with contributions from Marcelo Fiore
For natural numbers m and n, an {\mathopen {}\left (m\times n\right )\mathclose {}}-matrix over a semiring {\mathopen {}\left (S,0,\oplus ,1,\odot \right )\mathclose {}} is given by entries M_{i,j}: S for all i:{\mathopen {}\left [m\right ]\mathclose {}} and j: {\mathopen {}\left [n\right ]\mathclose {}}. We will write \mathrm {Mat}_{S}{\mathopen {}\left (m,n\right )\mathclose {}} for the set of {\mathopen {}\left (m\times n\right )\mathclose {}}-matrices.
Notation Matrices as tables [00J4]
- January 17, 2024
- Jon Sterling, with contributions from Marcelo Fiore
{\mathopen {}\left (m\times n\right )\mathclose {}}-matrices can be depicted in tables or grids with rows in the first dimension and columns in the second dimension. For example, let M:\mathrm {Mat}_{\mathbb {B}}{\mathopen {}\left (3,2\right )\mathclose {}} be the matrix over the booleans defined by the following equation:
M_{i,j} = \begin {cases} \mathsf {true} &\text {if } \mathsf {parity}{\mathopen {}\left (i\right )\mathclose {}} = \mathsf {parity}{\mathopen {}\left (j\right )\mathclose {}} \\ \mathsf {false} &\text {otherwise} \end {cases}Then M is depicted by the following table with three rows and two columns:
M = \begin {bmatrix} \mathsf {true} & \mathsf {false}\\ \mathsf {false} & \mathsf {true}\\ \mathsf {true} & \mathsf {false} \end {bmatrix}Definition The identity matrix [00IT]
- January 17, 2024
- Jon Sterling
For any m: \mathbb {N}, we define the identity {\mathopen {}\left (m\times m\right )\mathclose {}}-matrix over a given semiring S as follows:
I^m_{i,j} = \begin {cases} 1&\text {if } i=j\\ 0&\text {otherwise} \end {cases}The identity matrix is sometimes called the diagonal matrix, for reasons that become apparent when visualising it according to Notation [00J4]:
I^4 = \begin {bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1 \end {bmatrix}Correspondence between matrices and finite relations [00J1]
- January 17, 2024
- Jon Sterling
Definition The matrix associated to a finite relation [00IY]
- January 17, 2024
- Jon Sterling
Let R\colon {\mathopen {}\left [m\right ]\mathclose {}}\mathbin {\nrightarrow }{\mathopen {}\left [n\right ]\mathclose {}} be a relation; for any semiring S, we may form the {\mathopen {}\left (n\times n\right )\mathclose {}}-matrix over S associated to R as follows:
{\mathopen {}\left (\operatorname {\underline {mat}}_S{R}\right )\mathclose {}}_{i:{\mathopen {}\left [m\right ]\mathclose {}},j:{\mathopen {}\left [n\right ]\mathclose {}}} = \begin {cases} 1&\text {if } i\mathrel {R}j \\ 0&\text {otherwise} \end {cases}We have defined a function \operatorname {\underline {mat}}_S\colon \mathrm {Rel}{\mathopen {}\left ({\mathopen {}\left [m\right ]\mathclose {}},{\mathopen {}\left [n\right ]\mathclose {}}\right )\mathclose {}} \to \mathrm {Mat}_{S}{\mathopen {}\left (m,n\right )\mathclose {}}.
Definition The relation associated to a matrix [00IZ]
- January 17, 2024
- Jon Sterling
Let M be an {\mathopen {}\left (n\times n\right )\mathclose {}}-matrix over a semiring S. We define the relation associated to M below:
\begin {aligned} \operatorname {\underline {rel}}_S{M} &\colon {\mathopen {}\left [m\right ]\mathclose {}}\mathbin {\nrightarrow }{\mathopen {}\left [n\right ]\mathclose {}} \\ i\mathrel {{\mathopen {}\left (\operatorname {\underline {rel}}_S{M}\right )\mathclose {}}} j &\Longleftrightarrow M_{i,j} = 1 \end {aligned}We have defined a function \operatorname {\underline {rel}}_S\colon \mathrm {Mat}_{S}{\mathopen {}\left (m,n\right )\mathclose {}}\to \mathrm {Rel}{\mathopen {}\left ({\mathopen {}\left [m\right ]\mathclose {}},{\mathopen {}\left [n\right ]\mathclose {}}\right )\mathclose {}}.
Lemma A retraction from matrices to finite relations [00J0]
- January 17, 2024
- Jon Sterling
The associated matrix function \operatorname {\underline {mat}}_S\colon \mathrm {Rel}{\mathopen {}\left ({\mathopen {}\left [m\right ]\mathclose {}},{\mathopen {}\left [n\right ]\mathclose {}}\right )\mathclose {}} \to \mathrm {Mat}_{S}{\mathopen {}\left (m,n\right )\mathclose {}} is a section of the associated relation function \operatorname {\underline {rel}}_S\colon \mathrm {Mat}_{S}{\mathopen {}\left (m,n\right )\mathclose {}}\to \mathrm {Rel}{\mathopen {}\left ({\mathopen {}\left [m\right ]\mathclose {}},{\mathopen {}\left [n\right ]\mathclose {}}\right )\mathclose {}} for any semiring S.
Proof.
- January 17, 2024
- Jon Sterling
We must check that \operatorname {\underline {rel}}_S\circ \operatorname {\underline {mat}}_S = \mathsf {id}_{\mathrm {Rel}{\mathopen {}\left ({\mathopen {}\left [m\right ]\mathclose {}},{\mathopen {}\left [n\right ]\mathclose {}}\right )\mathclose {}}}. Fixing a relation R\colon {\mathopen {}\left [m\right ]\mathclose {}}\mathbin {\nrightarrow }{\mathopen {}\left [n\right ]\mathclose {}}, we compute:
\begin {aligned} i\mathrel {{\mathopen {}\left (\operatorname {\underline {rel}}_S{\mathopen {}\left (\operatorname {\underline {mat}}_SR\right )\mathclose {}}\right )\mathclose {}}} j &\Longleftrightarrow {\mathopen {}\left (\operatorname {\underline {mat}}_SR\right )\mathclose {}}_{i,j} = 1 \\ &\Longleftrightarrow i\mathrel {R}j \end {aligned}The other composite \operatorname {\underline {mat}}_S\circ \operatorname {\underline {rel}}_S\colon \mathrm {Mat}_{S}{\mathopen {}\left (m,n\right )\mathclose {}}\to \mathrm {Mat}_{S}{\mathopen {}\left (m,n\right )\mathclose {}} is not in general the identity function, but is (necessarily) an idempotent on the set of matrices over S. We will see that this idempotent, in some sense, measures the degree to which the base semiring S is not boolean.
Lemma Finite relations as matrices over the booleans [00IX]
- January 17, 2024
- Jon Sterling
The idempotent {\operatorname {\underline {mat}}_\mathbb {B}\circ \operatorname {\underline {rel}}_\mathbb {B}\colon \mathrm {Mat}_{\mathbb {B}}{\mathopen {}\left (m,n\right )\mathclose {}}\to \mathrm {Mat}_{\mathbb {B}}{\mathopen {}\left (m,n\right )\mathclose {}}} is in fact the identity function on matrices over the boolean semiring \mathbb {B}.
Proof.
- January 17, 2024
- Jon Sterling
We fix a matrix M:\mathrm {Mat}_{\mathbb {B}}{\mathopen {}\left (m,n\right )\mathclose {}} and compute:
\begin {aligned} {\mathopen {}\left (\operatorname {\underline {mat}}_\mathbb {B}{\mathopen {}\left (\operatorname {\underline {rel}}_\mathbb {B} M\right )\mathclose {}}\right )\mathclose {}}_{i,j} &= \begin {cases} 1 &\text {if } i \mathrel {{\mathopen {}\left (\operatorname {\underline {rel}}_\mathbb {B} M\right )\mathclose {}}} j\\ 0 &\text {otherwise} \end {cases} \\ &= \begin {cases} 1 &\text {if } M_{i,j} = 1\\ 0 &\text {otherwise} \end {cases} \end {aligned}Because \mathbb {B} is the boolean semiring, any scalar s: S is either 0 or 1. Therefore, we conclude:
{\mathopen {}\left (\operatorname {\underline {mat}}_\mathbb {B}{\mathopen {}\left (\operatorname {\underline {rel}}_\mathbb {B} M\right )\mathclose {}}\right )\mathclose {}}_{i,j} = M_{i,j}Thus we conclude that an {\mathopen {}\left (m\times n\right )\mathclose {}}-matrix over the booleans is the same thing as a relation from {\mathopen {}\left [m\right ]\mathclose {}} to {\mathopen {}\left [n\right ]\mathclose {}}.
Multiplication of matrices [00IW]
- January 17, 2024
- Jon Sterling, with contributions from Marcelo Fiore
Remark Matrix multiplication in geometry [00IU]
- January 17, 2024
- Jon Sterling
Although we do not explore it in this course, the viewpoint of matrix multiplication as relational composition generalises to a correct explanation of the role of matrices in geometry as presentations of linear maps between vector spaces in terms of an (uncanonical) choice of basis.
Definition Product of matrices [00IV]
- January 17, 2024
- Jon Sterling
Let M be an {\mathopen {}\left (l\times m\right )\mathclose {}}-matrix and let N be a {\mathopen {}\left (m\times n\right )\mathclose {}}-matrix. The product of M and N, written M\otimes N, is the following {\mathopen {}\left (l\times n\right )\mathclose {}}-matrix:
{\mathopen {}\left (N\otimes M\right )\mathclose {}}_{i: {\mathopen {}\left [l\right ]\mathclose {}},j:{\mathopen {}\left [n\right ]\mathclose {}}} = \bigoplus _{k: {\mathopen {}\left [m\right ]\mathclose {}}} N_{k,j}\odot M_{i,k}Lemma Associativity and unit laws of matrix products [00J3]
- January 17, 2024
- Jon Sterling, with contributions from Marcelo Fiore
The product of matrices is associative and has the identity matrix as neutral element.
Proof.
- January 17, 2024
- Jon Sterling
For associativity, fix matrices L:\mathrm {Mat}_{S}{\mathopen {}\left (k,l\right )\mathclose {}}, M:\mathrm {Mat}_{S}{\mathopen {}\left (l,m\right )\mathclose {}} and N:\mathrm {Mat}_{S}{\mathopen {}\left (m,n\right )\mathclose {}} to check that {\mathopen {}\left (N\otimes M\right )\mathclose {}}\otimes L = N\otimes {\mathopen {}\left (M\otimes L\right )\mathclose {}}. Below we use the associativity of multiplication, commutativity of addition, and distributivity of multiplication over addition in the semiring S:
\begin {aligned} {\mathopen {}\left ({\mathopen {}\left (N\otimes M\right )\mathclose {}}\otimes L\right )\mathclose {}}_{a,d} &= \bigoplus _{b:{\mathopen {}\left [l\right ]\mathclose {}}} {\mathopen {}\left (N\otimes M\right )\mathclose {}}_{b,d}\odot L_{a,b} \\ &= \bigoplus _{b:{\mathopen {}\left [l\right ]\mathclose {}}} {\mathopen {}\left ( \bigoplus _{c:{\mathopen {}\left [m\right ]\mathclose {}}} N_{c,d}\odot M_{b,c} \right )\mathclose {}} \odot L_{a,b} \\ &= \bigoplus _{b:{\mathopen {}\left [l\right ]\mathclose {}}} \bigoplus _{c: {\mathopen {}\left [m\right ]\mathclose {}}} N_{c,d}\odot M_{b,c}\odot L_{a,b} \\ &= \bigoplus _{c: {\mathopen {}\left [m\right ]\mathclose {}}} N_{c,d}\odot \bigoplus _{b:{\mathopen {}\left [l\right ]\mathclose {}}} M_{b,c}\odot L_{a,b} \\ &= \bigoplus _{c: {\mathopen {}\left [m\right ]\mathclose {}}} N_{c,d}\odot {\mathopen {}\left (M\otimes L\right )\mathclose {}}_{a,c} \\ &= {\mathopen {}\left (N\otimes {\mathopen {}\left (M\otimes L\right )\mathclose {}}\right )\mathclose {}}_{a,d} \end {aligned}For one unit law, we fix M:\mathrm {Mat}_{S}{\mathopen {}\left (m,n\right )\mathclose {}} and recall the definition of the identity matrix to check that M\otimes I^m = M.
\begin {aligned} {\mathopen {}\left (M\otimes I^m\right )\mathclose {}}_{i,j} &= \bigoplus _{k: {\mathopen {}\left [m\right ]\mathclose {}}} M_{k, j} \odot I^m_{i,k} \end {aligned}Unfolding the definition of I^m_{i,j} as given in Definition [00IT], we see that the iterated sum above expands to m-1 copies of 0\odot M_{k,j} for various k \not = i and one copy of 1\odot M_{i,j}. Thus, we conclude that M\otimes I^m_{i,j} = M_{i,j} using the absorption and unit laws for multiplication as well as the unit laws for addition in S.
The other unit law follows in an analogous way.
Lemma Matrix product is relational composition [00J2]
- January 17, 2024
- Jon Sterling, with contributions from Marcelo Fiore
Under the correspondence between boolean matrices and finite relations (§ [00J1], Lemma [00IX]), matrix products of boolean matrices correspond to relational composites. In particular, given M:\mathrm {Mat}_{\mathbb {B}}{\mathopen {}\left (l,m\right )\mathclose {}} and N:\mathrm {Mat}_{\mathbb {B}}{\mathopen {}\left (m,n\right )\mathclose {}}, we have:
\operatorname {\underline {rel}}_\mathbb {B}{\mathopen {}\left (N\otimes M\right )\mathclose {}} = \operatorname {\underline {rel}}_\mathbb {B} N\circ \operatorname {\underline {rel}}_\mathbb {B} MProof.
- January 17, 2024
- Jon Sterling
We use the fact that the additive operation of the boolean semiring is disjunction and the multiplicative operation is conjunction:
\begin {aligned} {\mathopen {}\left (N\otimes M\right )\mathclose {}}_{i,j} &= \bigoplus _{k:{\mathopen {}\left [m\right ]\mathclose {}}} N_{k,j}\odot M_{i,k} \\ &= \bigvee _{k:{\mathopen {}\left [m\right ]\mathclose {}}} N_{k,j}\land M_{i,k} \\ &= \exists k:{\mathopen {}\left [m\right ]\mathclose {}}\mathpunct {.} M_{i,k}\land N_{k,j} \end {aligned}