Ken Levasseur, Al Doerr, Michiel Smid, Oscar Levin, Charles M. Grinstead, J. Laurie Snell, Eric Lehman, F. Thomson Leighton, Albert R Meyer, Jeff Erickson, Kenneth P. Bogart, Carol Chritchlow, David Eck, OpenDSA Project, L.J. Miller
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.
Subsection10.4.1Representing a Relation with a Matrix
Definition10.4.1.Adjacency 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 \(M\) defined by
\begin{equation*}
M_{ij}= \left\{
\begin{array}{cc}
1 & \textrm{ if } a_i R b_j \\
0 & \textrm{ otherwise} \\
\end{array}\right.
\end{equation*}
\(M\) is called the adjacency matrix (or the relation matrix) of \(R\) .
Example10.4.2.A simple 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\text{,}\)\(a_2=5\text{,}\) and \(a_3=6\text{,}\) while \(b_1= 2\text{,}\)\(b_2=5\text{,}\) and \(b_3=6\text{.}\) Next, since
We do not write \(M^2\) only for notational purposes. In fact, \(M^2\) can be obtained from the matrix product \(M M\text{;}\) however, we must use a slightly different form of arithmetic.
Definition10.4.3.Boolean Arithmetic.
Boolean arithmetic is the arithmetic defined on \(\{0,1\}\) using Boolean addition and Boolean multiplication, defined by
Table10.4.4.
\(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 4, this is the “arithmetic of logic,” where \(+\) replaces “or” and \(\cdot\) replaces “and.”
Theorem10.4.6.Composition is Matrix Multiplication.
Let \(A_1\text{,}\)\(A_2\text{,}\) 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\text{.}\) If \(M_1\) and \(M_2\) are the adjacency matrices of \(R_1\) and \(R_2\text{,}\) respectively, then the product \(M_1M_2\) using Boolean arithmetic is the adjacency matrix of the composition \(R_1R_2\text{.}\)
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, \(M\) in Example 2 would be
To fill in the matrix, \(M_{ij}\) is 1 if and only if \(\left(a_i,b_j\right) \in R\text{.}\) So that, since the pair \((2, 5) \in R\text{,}\) the entry of \(M\) corresponding to the row labeled 2 and the column labeled 5 in the matrix is a 1.
Example10.4.7.Relations 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 \(M\) (on the left) and \(N\) (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{.}\)
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 \(MN\text{,}\) which is
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.
Exercises10.4.3Exercises
1.
Let \(A_1 = \{1,2, 3, 4\}\text{,}\)\(A_2 = \{4, 5, 6\}\text{,}\) and \(A_3 = \{6, 7, 8\}\text{.}\) Let \(R_1\) be the relation from \(A_1\) into \(A_2\) defined by \(R_1 = \{(x, y) \mid y - x = 2\}\text{,}\) and let \(R_2\) be the relation from \(A_2\) into \(A_3\) defined by \(R_2 = \{(x, y) \mid y - x = 1\}\text{.}\)
Determine the adjacency matrices of \(R_1\) and \(R_2\text{.}\)
Use the definition of composition to find \(R_1R_2\text{.}\)
Verify the result in part b by finding the product of the adjacency matrices of \(R_1\) and \(R_2\text{.}\)
Determine the adjacency matrix of each relation given via the digraphs in Exercise 3 of Section 10.3.
Using the matrices found in part (a) above, find \(R^2\) of each relation in Exercise 3 of Section 10.3.
Find the digraph of \(R^2\) directly from the given digraph and compare your results with those of part (b).
3.
Suppose that the matrices in Example 10.4.5 are relations on \(\{1, 2, 3, 4\}\text{.}\) What relations do \(M\) and \(N\) describe?
Answer.
Table10.4.8.
M : \(x R y\) if and only if \(\lvert x -y \rvert = 1\)
N : \(x S y\) if and only if \(x\) is less than \(y\text{.}\)
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)\}\text{.}\) 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
compute \(MN\) using Boolean arithmetic and give an interpretation of the relation it defines, and
compute \(MN\) using regular arithmetic and give an interpretation of what the result describes.
5.
How many different reflexive, symmetric relations are there on a set with three elements?
Hint.
Consider the possible matrices.
Answer.
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\}\text{.}\) 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 \\
d \\
\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 \(R\) and \(S\) on \(\{1, 2, 3, 4\}\) by \(R = \{(a, b) \mid \lvert a-b\rvert=1\}\) and \(S=\{(a,b) \mid a-b \textrm{ is even}\}\text{.}\)
Represent \(R\) and \(S\) as both graphs and matrices.
Determine \(RS\text{,}\)\(R^2\text{,}\) and \(S^2\text{;}\) 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\text{.}\)
Find an example of a transitive relation for which \(R^2\neq R\text{.}\)
9.
We define \(\leq\) on the set of all \(n\times n\) relation matrices by the rule that if \(M\) and \(N\) are any two \(n\times n\) relation matrices, \(M \leq N\) if and only if \(M_{ij} \leq N_{ij}\) for all \(1 \leq i, j \leq n\text{.}\)
Prove that \(\leq\) is a partial ordering on all \(n\times n\) relation matrices.
Prove that \(M \leq N \Rightarrow M^2\leq N^2\) , but the converse is not true.
If \(M\) and \(N\) are matrices of equivalence relations and \(M \leq N\text{,}\) how are the equivalence classes defined by \(M\) related to the equivalence classes defined by \(N\text{?}\)
Answer.
Reflexive: \(M_{ij}=M_{ij}\) for all \(i,j\text{,}\) therefore \(M_{ij}\leq M_{ij}\)
Antisymmetric: Assume \(M_{ij}\leq N_{ij}\) and \(N_{ij}\leq M_{ij}\) for all \(1\leq i,j\leq n\text{.}\) Therefore, \(M_{ij} = N_{ij}\) for all \(1\leq i,j\leq n\) and so \(M=N\)
Transitive: Assume \(M, N,\) and \(T\) are matrices where \(M_{ij}\leq N_{ij}\) and \(N_{ij}\leq T_{ij}\text{,}\) for all \(1\leq i,j\leq n\text{.}\) Then \(M_{ij}\leq T_{ij}\) for all \(1\leq i,j\leq n\text{,}\) and so \(M\leq T\text{.}\)
To verify that the converse is not true we need only one example. For \(n=2\text{,}\) let \(M_{12}=1\) and all other entries equal \(0\text{,}\) and let \(N\) be the zero matrix. Since \(M^2\) and \(N^2\) are both the zero matrix, \(M^2\leq N^2\text{,}\) but since \(M_{12}>N_{12}, M\leq N\) is false.
The matrices are defined on the same set \(A=\left\{a_1,a_2,\ldots ,a_n\right\}\text{.}\) Let \(c\left(a_i\right), i=1,2,\ldots ,n\) be the equivalence classes defined by \(M\) and let \(d\left(a_i\right)\) be those defined by \(N\text{.}\) Claim: \(c\left(a_i\right)\subseteq d\left(a_i\right)\text{.}\)