• No results found

3.5 ➜ Matrices of Relations

A matrix is a convenient way to represent a relation R from X to Y . Such a representation can be used by a computer to analyze a relation. We label the rows with the elements of X (in some arbitrary order), and we label the columns with the elements of Y (again, in some arbitrary order). We then ,set the entry in row x and column y to 1 if x R y and to 0 otherwise. This matrix is called the matrix of the relation R (relative to the orderings of X and Y ).

Example 3.5.1 The matrix of the relation

R= {(1, b), (1, d), (2, c), (3, c), (3, b), (4, a)}

Example 3.5.2 The matrix of the relation R of Example 3.5.1 relative to the orderings 2, 3, 4, 1 and d, b, a, c is

Obviously, the matrix of a relation from X to Y is dependent on the orderings of X and Y .

Example 3.5.3 The matrix of the relation R from{2, 3, 4} to {5, 6, 7, 8}, relative to the orderings 2, 3, 4 and 5, 6, 7, 8, defined by

3.5 ◆ Matrices of Relations

169

When we write the matrix of a relation R on a set X (i.e., from X to X ), we use the same ordering for the rows as we do for the columns.

Example 3.5.4 The matrix of the relation

R= {(a, a), (b, b), (c, c), (d, d), (b, c), (c, b)}

on{a, b, c, d}, relative to the ordering a, b, c, d, is

a b c d

a b c d

⎜⎜

1 0 0 0

0 1 1 0

0 1 1 0

0 0 0 1

⎟⎟

⎠ .

Notice that the matrix of a relation on a set X is always a square matrix.

We can quickly determine whether a relation R on a set X is reflexive by examining the matrix A of R (relative to some ordering). The relation R is reflexive if and only if A has 1’s on the main diagonal. (The main diagonal of a square matrix consists of the entries on a line from the upper left to the lower right.) The relation R is reflexive if and only if (x, x)∈ R for all x ∈ X. But this last condition holds precisely when the main diagonal consists of 1’s. Notice that the relation R of Example 3.5.4 is reflexive and that the main diagonal of the matrix of R consists of 1’s.

We can also quickly determine whether a relation R on a set X is symmetric by examining the matrix A of R (relative to some ordering). The relation R is symmetric if and only if for all i and j , the i j th entry of A is equal to the ji th entry of A. (Less formally, R is symmetric if and only if A is symmetric about the main diagonal.) The reason is that R is symmetric if and only if whenever (x, y) is in R, ( y, x) is also in R.

But this last condition holds precisely when A is symmetric about the main diagonal.

Notice that the relation R of Example 3.5.4 is symmetric and that the matrix of R is symmetric about the main diagonal.

We can also quickly determine whether a relation R is antisymmetric by examining the matrix of R (relative to some ordering) (see Exercise 11).

We conclude by showing how matrix multiplication relates to composition of relations and how we can use the matrix of a relation to test for transitivity.

Example 3.5.5 Let R1be the relation from X = {1, 2, 3} to Y = {a, b} defined by R1= {(1, a), (2, b), (3, a), (3, b)}, and let R2be the relation from Y to Z = {x, y, z} defined by R2 = {(a, x), (a, y), (b, y), (b, z)}.

The matrix of R1relative to the orderings 1, 2, 3 and a, b is

A1= 1 2 3

a b

⎝1 0 0 1 1 1

⎠ ,

and the matrix of R2relative to the orderings a, b and x, y, z is

A2= a b

x y z

1 1 0

0 1 1

 .

The product of these matrices is

A1A2=

⎝1 1 0

0 1 1

1 2 1

⎠ . Let us interpret this product.

The i kth entry in A1A2is computed as

i

a b

!s t" k u v



= su + tv.

If this value is nonzero, then either su or tv is nonzero. Suppose that su = 0. (The argument is similar if tv = 0.) Then s = 0 and u = 0. This means that (i, a) ∈ R1and (a, k)∈ R2. This implies that (i, k)∈ R2◦ R1. We have shown that if the i kth entry in A1A2is nonzero, then (i, k)∈ R2◦ R1. The converse is also true, as we now show.

Assume that (i, k)∈ R2◦ R1. Then, either 1. (i, a)∈ R1and (a, k)∈ R2

or

2. (i, b)∈ R1and (b, k)∈ R2.

If 1 holds, then s= 1 and u = 1, so su = 1 and su + tv is nonzero. Similarly, if 2 holds, tv = 1 and again we have su + tv nonzero. We have shown that if (i, k) ∈ R2◦ R1, then the i kth entry in A1A2is nonzero.

We have shown that (i, k) ∈ R2◦ R1 if and only if the i kth entry in A1A2 is nonzero; thus A1A2is “almost” the matrix of the relation R2◦ R1. To obtain the matrix of the relation R2◦ R1, we need only change all nonzero entries in A1A2to 1. Thus the matrix of the relation R2◦ R1, relative to the previously chosen orderings 1, 2, 3 and x, y, z, is

x y z

1 2 3

⎝1 1 0

0 1 1

1 1 1

⎠ .

The argument given in Example 3.5.5 holds for any relations. We summarize this result as Theorem 3.5.6.

Theorem 3.5.6 Let R1 be a relation from X to Y and let R2 be a relation from Y to Z . Choose orderings of X , Y , and Z . Let A1be the matrix of R1and let A2be the matrix of R2

with respect to the orderings selected. The matrix of the relation R2◦ R1with respect to the orderings selected is obtained by replacing each nonzero term in the matrix product A1A2by 1.

Proof The proof is sketched before the statement of the theorem.

3.5 ◆ Matrices of Relations

171

Theorem 3.5.6 provides a quick test for determining whether a relation is transitive.

If A is the matrix of R (relative to some ordering), we compute A2. We then compare A and A2. The relation R is transitive if and only if whenever entry i, j in A2is nonzero, entry i, j in A is also nonzero. The reason is that entry i, j in A2is nonzero if and only if there are elements (i, k) and (k, j ) in R (see the proof of Theorem 3.5.6). Now R is transitive if and only if whenever (i, k) and (k, j ) are in R, then (i, j ) is in R. But (i, j ) is in R if and only if entry i, j in A is nonzero. Therefore, R is transitive if and only if whenever entry i, j in A2is nonzero, entry i, j in A is also nonzero.

Example 3.5.7 The matrix of the relation

R= {(a, a), (b, b), (c, c), (d, d), (b, c), (c, b)}

We see that whenever entry i, j in A2is nonzero, entry i, j in A is also nonzero. There-fore, R is transitive.

Example 3.5.8 The matrix of the relation

R= {(a, a), (b, b), (c, c), (d, d), (a, c), (c, b)}

The entry in row 1, column 2 of A2is nonzero, but the corresponding entry in A is zero.

Therefore, R is not transitive.

Problem-Solving Tips

The matrix of a relation R is another way to represent or specify a relation from X to Y . The entry in row x and column y is 1 if x R y, or 0 if xRy.

A relation is reflexive if and only if the main diagonal of its matrix representation consists of all 1’s.

A relation is symmetric if and only if its matrix is symmetric (i.e., entry i, j always equals entry j, i ).

Let R1be a relation from X to Y and let R2be a relation from Y to Z . Let A1be the matrix of R1 and let A2be the matrix of R2. The matrix of the relation R2◦ R1 is obtained by replacing each nonzero term in the matrix product A1A2by 1.

To test whether a relation is transitive, let A be its matrix. Compute A2. The relation is transitive if and only if whenever entry i, j in A2is nonzero, entry i, j in A is also nonzero.

Section Review Exercises

1. What is the matrix of a relation?

2. Given the matrix of a relation, how can we determine whether the relation is reflexive?

3. Given the matrix of a relation, how can we determine whether the relation is symmetric?

4. Given the matrix of a relation, how can we determine whether the relation is transitive?

5. Given the matrix A1of the relation R1 and the matrix A2 of the relation R2, explain how to obtain the matrix of the relation R2◦ R1.

Exercises

In Exercises 1–3, find the matrix of the relation R from X to Y relative to the orderings given.

In Exercises 4– 6, find the matrix of the relation R on X relative to the ordering given.

4. R= {(1, 2), (2, 3), (3, 4), (4, 5)}; ordering of X: 1, 2, 3, 4, 5 5. R as in Exercise 4; ordering of X : 5, 3, 1, 2, 4

6. R= {(x, y) | x < y}; ordering of X: 1, 2, 3, 4

7. Find matrices that represent the relations of Exercises 13 –16, Section 3.3.

In Exercises 8–10, write the relation R, given by the matrix, as a set of ordered pairs.

11. How can we quickly determine whether a relation R is an-tisymmetric by examining the matrix of R (relative to some ordering)?

12. Tell whether the relation of Exercise 10 is reflexive, symmetric, transitive, antisymmetric, a partial order, and/or an equivalence relation.

13. Given the matrix of a relation R from X to Y , how can we find the matrix of the inverse relation R−1?

14. Find the matrix of the inverse of each of the relations of Exer-cises 8 and 9.

15. Use the matrix of the relation to test for transitivity (see Ex-amples 3.5.7 and 3.5.8) for the relations of Exercises 4, 6, and 10.

In Exercises 16 –18, find

(a) The matrix A1 of the relation R1 (relative to the given orderings).

(b) The matrix A2 of the relation R2 (relative to the given orderings).

(c) The matrix product A1A2.

(d) Use the result of part (c) to find the matrix of the relation R2◦ R1.