We have discussed two of the many possible ways of representing a relation, namely as a digraph or as a set of ordered pairs. In this section we will discuss the representation of relations by matrices.

Definition6.4.1Adjacency Matrix

Let \(A = \{a_1,a_2,\ldots , a_m\}\) and \(B= \{b_1,b_2,\ldots , b_n\}\) be finite sets of cardinality \(m\) and \(n\text{,}\) respectively. Let \(r\) be a relation from \(A\) into \(B\text{.}\) Then \(r\) can be represented by the \(m\times n\) matrix \(R\) defined by
\begin{equation*}
R_{ij}= \left\{
\begin{array}{cc}
1 & \textrm{ if } a_i r b_j \\
0 & \textrm{ otherwise} \\
\end{array}\right.
\end{equation*}
\(R\) is called the adjacency matrix (or the relation matrix) of \(r\text{.}\)

For example, let \(A = \{2, 5, 6\}\) and let \(r\) be the relation \(\{(2, 2), (2, 5), (5, 6), (6, 6)\}\) on \(A\text{.}\) Since \(r\) is a relation from \(A\) into the same set \(A\) (the \(B\) of the definition), we have \(a_1= 2\), \(a_2=5\), and \(a_3=6\), while \(b_1= 2\), \(b_2=5\), and \(b_3=6\). Next, since

\(2 r 2\), we have \(R_{11}= 1\)

\(2 r 5\), we have \(R_{12}= 1\)

\(5 r 6\), we have \(R_{23}= 1\)

\(6 r 6\), we have \(R_{33}= 1\)

All other entries of \(R\) are zero, so \[R =\left( \begin{array}{ccc} 1 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 1 \\ \end{array} \right)\]

From the definition of \(r\) and of composition, we note that
\begin{equation*}
r^2 = \{(2, 2), (2, 5), (2, 6), (5, 6), (6, 6)\}
\end{equation*}
The adjacency matrix of \(r^2\) is
\begin{equation*}
R^2 =\left(
\begin{array}{ccc}
1 & 1 & 1 \\
0 & 0 & 1 \\
0 & 0 & 1 \\
\end{array}
\right)\text{.}
\end{equation*}

We do not write \(R^2\) only for notational purposes. In fact, \(R^2\) can be obtained from the matrix product \(R R\); however, we must use a slightly different form of arithmetic.

Definition6.4.2Boolean Arithmetic

Boolean arithmetic is the arithmetic defined on \(\{0,1\}\) using Boolean addition and Boolean multiplication, defined by

\(0 + 0 = 0\)

\(0+1 = 1 + 0=1\)

\(1 + 1 = 1\)

\(0\cdot 0=0\)

\(0 \cdot 1 = 1 \cdot 0 = 0\)

\(1 \cdot 1 = 1\)

Notice that from Chapter 3, this is the “arithmetic of logic,” where \(+\) replaces “or” and \(\cdot\) replaces “and.”

Let \(A_1\), \(A_2\), and \(A_3\) be finite sets where \(r_1\) is a relation from \(A_1\) into \(A_2\) and \(r_2\) is a relation from \(A_2\) into \(A_3\). If \(R_1\) and \(R_2\) are the adjacency matrices of \(r_1\) and \(r_2\), respectively, then the product \(R_1R_2\) using Boolean arithmetic is the adjacency matrix of the composition \(r_1r_2\).

Remark: A convenient help in constructing the adjacency matrix of a relation from a set \(A\) into a set \(B\) is to write the elements from \(A\) in a column preceding the first column of the adjacency matrix, and the elements of \(B\) in a row above the first row. Initially, \(R\) in Example 6.4.1 would be
\begin{equation*}
\begin{array}{cc}
&
\begin{array}{ccc}
2 & 5 & 6 \\
\end{array}
\\
\begin{array}{c}
2 \\
5 \\
6 \\
\end{array}
& \left(
\begin{array}{ccc}
& & \\
& & \\
& & \\
\end{array}
\right) \\
\end{array}
\end{equation*}
To fill in the matrix, \(R_{ij}\) is 1 if and only if \(\left(a_i,b_j\right) \in r\). So that, since the pair \((2, 5) \in r\), the entry of \(R\) corresponding to the row labeled 2 and the column labeled 5 in the matrix is a 1.

Example6.4.5Relations and Information

This final example gives an insight into how relational data base programs can systematically answer questions pertaining to large masses of information. Matrices \(R\) (on the left) and \(S\) (on the right) define the relations \(r\) and \(s\) where \(a r b\) if software \(a\) can be run with operating system \(b\text{,}\) and \(b s c\) if operating system \(b\) can run on computer \(c\text{.}\)
\begin{equation*}
\begin{array}{cc}
\begin{array}{cc}
&
\begin{array}{cccc}
\text{OS1} & \text{OS2} & \text{OS3} & \text{OS4}
\end{array} \\
\begin{array}{c}
\text{P1} \\
\text{P2} \\
\text{P3} \\
\text{P4}
\end{array}
&
\left(
\begin{array}{cccc}
1 & 0 & 1 & 0 \\
1 & 1 & 0 & 0 \\
0 & 0 & 0 & 1 \\
0 & 0 & 1 & 1
\end{array}
\right)
\end{array}
\begin{array}{cc}
&
\begin{array}{ccc}
\text{C1} & \text{C2} & \text{C3}
\end{array} \\
\begin{array}{c}
\text{OS1} \\
\text{OS2} \\
\text{OS3} \\
\text{OS4} \\
\end{array}
& \left(
\begin{array}{ccc}
1 & 1 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
0 & 1 & 1
\end{array}
\right)
\end{array}
\end{array}
\end{equation*}
Although the relation between the software and computers is not implicit from the data given, we can easily compute this information. The matrix of \(rs\) is \(RS\text{,}\) which is
\begin{equation*}
\begin{array}{cc}
&
\begin{array}{ccc}
\text{C1} & \text{C2} & \text{C3}
\end{array}
\\
\begin{array}{c}
\text{P1} \\
\text{P2} \\
\text{P3} \\
\text{P4}
\end{array}
& \left(
\begin{array}{ccc}
1 & 1 & 1 \\
1 & 1 & 0 \\
1 & 1 & 1 \\
0 & 1 & 1
\end{array}
\right)
\end{array}
\end{equation*}
This matrix tells us at a glance which software will run on the computers listed. In this case, all software will run on all computers with the exception of program P2, which will not run on the computer C3, and program P4, which will not run on the computer C1.

Let \(A_1 = \{1,2, 3, 4\}\), \(A_2 = \{4, 5, 6\}\), and \(A_3 = \{6, 7, 8\}\). Let \(r_1\) be the relation from \(A_1\) into \(A_2\) defined by \(r_1 = \{(x, y) \mid y - x = 2\}\), and let \(r_2\) be the relation from \(A_2\) into \(A_3\) defined by \(r_2 = \{(x, y) \mid y - x = 1\}\).

Determine the adjacency matrices of \(r_1\) and \(r_2\).

Use the definition of composition to find \(r_1r_2\).

Verify the result in part by finding the product of the adjacency matrices of \(r_1\) and \(r_2\).

R : \(x r y\) if and only if \( \lvert x -y \rvert = 1\)

S : \(x s y\) if and only if \(x\) is less than \(y\).

4

Let \(D\) be the set of weekdays, Monday through Friday, let \(W\) be a set of employees \(\{1, 2, 3\}\) of a tutoring center, and let \(V\) be a set of computer languages for which tutoring is offered, \(\{A(PL), B(asic), C(++), J(ava), L(isp), P(ython)\}\). We define \(s\) (schedule) from \(D\) into \(W\) by \(d s w\) if \(w\) is scheduled to work on day \(d\text{.}\) We also define \(r\) from \(W\) into \(V\) by \(w r l\) if \(w\) can tutor students in language \(l\text{.}\) If \(s\) and \(r\) are defined by matrices

The diagonal entries of the matrix for such a relation must be 1. When the three entries above the diagonal are determined, the entries below are also determined. Therefore, there are \(2^3\) fitting the description.

6

Let \(A = \{a, b, c, d\}\). Let \(r\) be the relation on \(A\) with adjacency matrix \(\begin{array}{cc} & \begin{array}{cccc} a & b & c & d \\ \end{array} \\ \begin{array}{c} a \\ b \\ c \\ c \\ \end{array} & \left( \begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 1 & 1 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ \end{array} \right) \\ \end{array}\)

Explain why \(r\) is a partial ordering on \(A\text{.}\)

Draw its Hasse diagram.

7

Define relations \(p\) and \(q\) on \(\{1, 2, 3, 4\}\) by \(p = \{(a, b) \mid \lvert a-b\rvert=1\}\) and \(q=\{(a,b) \mid a-b \textrm{ is even}\}\).

Represent \(p\) and \(q\) as both graphs and matrices.

Determine \(p q\), \(p^2\), and \(q^2\); and represent them clearly in any way.

Prove that if \(r\) is a transitive relation on a set \(A\text{,}\) then \(r^2 \subseteq r\).

Find an example of a transitive relation for which \(r^2\neq r\).

9

We define \(\leq\) on the set of all \(n\times n\) relation matrices by the rule that if \(R\) and \(S\) are any two \(n\times n\) relation matrices, \(R \leq S\) if and only if \(R_{ij} \leq S_{ij}\) for all \(1 \leq i, j \leq n\).

Prove that \(\leq\) is a partial ordering on all \(n\times n\) relation matrices.

Prove that \(R \leq S \Rightarrow R^2\leq S^2\) , but the converse is not true.

If \(R\) and \(S\) are matrices of equivalence relations and \(R \leq S\), how are the equivalence classes defined by \(R\) related to the equivalence classes defined by \(S\text{?}\)

Reflexive: \(R_{ij}=R_{ij}\) for all \(i,j\), therefore \(R_{ij}\leq R_{ij}\)

Antisymmetric: Assume \(R_{ij}\leq S_{ij}\) and \(S_{ij}\leq R_{ij}\) for all \(1\leq i,j\leq n\). Therefore, \(R_{ij} = S_{ij}\) for all \(1\leq i,j\leq n\) and so \(R=S\)

Transitive: Assume \(R, S,\) and \(T\) are matrices where \(R_{ij}\leq S_{ij}\) and \(S_{ij}\leq T_{ij}\), for all \(1\leq i,j\leq n\). Then \(R_{ij}\leq T_{ij}\) for all \(1\leq i,j\leq n\), and so \(R\leq T\).

To verify that the converse is not true we need only one example. For \(n=2\), let \(R_{12}=1\) and all other entries equal \(0\), and let \(S\) be the zero matrix. Since \(R^2\) and \(S^2\) are both the zero matrix, \(R^2\leq S^2\), but since \(R_{12}>S_{12}, R\leq S\) is false.

The matrices are defined on the same set \(A=\left\{a_1,a_2,\ldots ,a_n\right\}\). Let \(c\left(a_i\right), i=1,2,\ldots ,n\) be the equivalence classes defined by \(R\) and let \(d\left(a_i\right)\) be those defined by \(S\). Claim: \(c\left(a_i\right)\subseteq d\left(a_i\right)\).
\begin{equation*}
\begin{split}
a_j\in c\left(a_i\right)&\Rightarrow a_i r a_j\\
&\Rightarrow R_{ij}=1 \Rightarrow S_{ij}=1\\
&\Rightarrow a_i s a_j\\
& \Rightarrow a_j \in d\left(a_i\right)\\
\end{split}
\end{equation*}