Directed graphs and paths [00JT]
- January 20, 2024
- Jon Sterling, with contributions from Marcelo Fiore
Definition Directed graph [00JC]
- January 18, 2024
- Jon Sterling, with contributions from Marcelo Fiore
A directed graph {\mathopen {}\left (A,R\right )\mathclose {}} consists of a set A and a binary relation R\colon A\mathbin {\nrightarrow } A from A to itself; such a relation from a set to itself is called an endo-relation.
Corollary Monoid structure of endo-relations [00JD]
- January 18, 2024
- Jon Sterling, with contributions from Marcelo Fiore
For every set A, the structure {\mathopen {}\left (\mathrm {Rel}{\mathopen {}\left (A,A\right )\mathclose {}},\mathsf {id}_{A},\circ \right )\mathclose {}} given by endo-relations is a monoid.
Proof.
- January 18, 2024
- Jon Sterling
We have seen in Lemma [00IP] that relational composition is associative and has identity relations \mathsf {id}_{A} as neutral elements.
Definition Iteration of endo-relations [00JE]
- January 18, 2024
- Jon Sterling, with contributions from Marcelo Fiore
For R\colon A\mathbin {\nrightarrow } A and n:\mathbb {N}, we define the n-fold iteration of R to be the following endo-relation R^{\circ n}\colon A\mathbin {\nrightarrow } A:
R^{\circ n} = \underbrace {R\circ \cdots \circ R}_{n\text { times}}More precisely, we define R^{\circ n} by recursion on n:
\begin {aligned} R^{\circ 0} &= \mathsf {id}_{A}\\ R^{\circ {\mathopen {}\left (n+1\right )\mathclose {}}} &= R\circ R^{\circ n} \end {aligned}Definition Path in a directed graph [00JF]
- January 18, 2024
- Jon Sterling, with contributions from Marcelo Fiore
Let {\mathopen {}\left (A,R\right )\mathclose {}} be a directed graph. For s,t:A, a path of length n: \mathbb {N} in R with source s and target t is a tuple {\mathopen {}\left (a_0,\ldots ,a_n\right )\mathclose {}}:A^{n+1} such that a_0=s, a_n=t, and a_i\mathrel {R}a_{i+1} for all 0\leq i <n.
We will later see in Theorem [00JZ] that the path relation is the reflexive-transitive closure.
Definition The path relation for an endo-relation [00JH]
- January 18, 2024
- Jon Sterling, with contributions from Marcelo Fiore
For R\colon A\mathbin {\nrightarrow } A, we define R^{\circ *}\colon A\mathbin {\nrightarrow } A to be the smallest relation closed under all finite paths in R.
R^{\circ *} = \bigcup _{n:\mathbb {N}} R^{\circ n}Observation Path relation of finite endo-relations [00JU]
- January 21, 2024
- Jon Sterling
In the case of an endo-relation R:\mathrm {Rel}{\mathopen {}\left ({\mathopen {}\left [n\right ]\mathclose {}}\right )\mathclose {}}, the path relation R^{\circ *} can be computed using a finite union rather over m \leq n rather than an infinite union over all of \mathbb {N}; in particular, we have R^{\circ *} = \bigcup _{k \leq n} R^{\circ k}.
Proof.
- January 21, 2024
- Jon Sterling
There are only n distinct elements that could be related, so there cannot be a chain of distinct elements with length o>n, and any finite path in R from s to t can be replaced by one that has no repetitions.
Definition Adjacency matrix of a finite directed graph [00JN]
- January 20, 2024
- Jon Sterling, with contributions from Marcelo Fiore
We have seen in Lecture 13 (Definition [00IY]) how to turn any relation R\colon {\mathopen {}\left [m\right ]\mathclose {}}\mathbin {\nrightarrow }{\mathopen {}\left [n\right ]\mathclose {}} into a matrix \operatorname {\underline {mat}}_{\mathbb {B}}R:\mathrm {Mat}_{\mathbb {B}}{\mathopen {}\left (m,n\right )\mathclose {}} over the boolean semiring. When R\colon {\mathopen {}\left [n\right ]\mathclose {}}\mathbin {\nrightarrow }{\mathopen {}\left [n\right ]\mathclose {}} is the edge relation in a graph with vertices in the finite set {\mathopen {}\left [n\right ]\mathclose {}}, we refer to \operatorname {\underline {mat}}_{\mathbb {B}}R:\mathrm {Mat}_{\mathbb {B}}{\mathopen {}\left (n,n\right )\mathclose {}} as the adjacency matrix of R.
Algorithm The adjacency matrix of the path relation [00JV]
- January 21, 2024
- Jon Sterling, with contributions from Marcelo Fiore
Let M = \operatorname {\underline {mat}}_{\mathbb {B}}R be the adjacency matrix of a finite directed graph {\mathopen {}\left ({\mathopen {}\left [n\right ]\mathclose {}},R\right )\mathclose {}}. We will show that the adjacency matrix M^* of the path relation R^{\circ *} can be computed recursively using the additive and multiplicative structure of matrices. In particular, we can define M^* = M_n where M_k is computed recursively as below:
\begin {aligned} M_0 &= I^n\\ M_{k+1} &= I^n \oplus {\mathopen {}\left (M\otimes M_k\right )\mathclose {}} \end {aligned}Thus we have a recursive algorithm that can decide whether there is a path between two elements in a finite directed graph: indeed, there is a path from s to t in R if and only if M^*_{s,t} =\mathsf {true}.
Proof.
- January 21, 2024
- Jon Sterling
We first unravel the first few M_k’s to get a better understanding.
\begin {aligned} M_1 &= I^n \oplus {\mathopen {}\left (M\otimes M_0\right )\mathclose {}} \\ &= I^n\oplus {\mathopen {}\left (M\otimes I^n\right )\mathclose {}} \\ &= I^n \oplus M \\ M_2 &= I^n \oplus {\mathopen {}\left (M\otimes M_1\right )\mathclose {}} \\ &= I^n \oplus {\mathopen {}\left (M\otimes {\mathopen {}\left (I^n \oplus M\right )\mathclose {}}\right )\mathclose {}} \\ &= I^n \oplus {\mathopen {}\left (M\otimes I^n\right )\mathclose {}} \oplus {\mathopen {}\left (M\otimes M\right )\mathclose {}} \\ &= I^n \oplus M \oplus M^2 \end {aligned}By induction, we can extend the pattern above to a closed form for each M_k. In particular, we deduce that M_k = \bigoplus _{l\leq k} M^l by recalling from Lemma [00J3] that the identity matrix is the neutral element for matrix multiplication. Therefore, we have M_n =\bigoplus _{k \leq n}M^k.
Our goal is to show that M_n = \operatorname {\underline {mat}}_{\mathbb {B}} R^{\circ *}; we have already seen in Lemma [00JR] and Lemma [00J2] that matrix addition corresponds to union of relations and matrix multiplication corresponds to relational composition.
By Observation [00JU] (Path relation of finite endo-relations), we have R^{\circ *} = \bigcup _{k\leq n} R^{\circ k}. Therefore:
\operatorname {\underline {mat}}_{\mathbb {B}}R^{\circ *} = \operatorname {\underline {mat}}_{\mathbb {B}}\bigcup _{k\leq n} R^{\circ k}By Lemma [00JR] (Matrix addition and union of relations), we have:
\operatorname {\underline {mat}}_{\mathbb {B}}\bigcup _{k\leq n} R^{\circ k} = \bigoplus _{k\leq n} \operatorname {\underline {mat}}_{\mathbb {B}}R^{\circ k} By Lemma [00J2] (Matrix product is relational composition), we have: \bigoplus _{k\leq n} \operatorname {\underline {mat}}_{\mathbb {B}}R^{\circ k} = \bigoplus _{k\leq n} {\mathopen {}\left (\operatorname {\underline {mat}}_{\mathbb {B}}R\right )\mathclose {}}^k = \bigoplus _{k\leq n} M^k = M_n