# 1 Section 7.3 Representing relations (part 1: matrices)

## Presentation on theme: "1 Section 7.3 Representing relations (part 1: matrices)"— Presentation transcript:

1 Section 7.3 Representing relations (part 1: matrices)

2 Representing relations We have already seen that relations between finite sets can be represented using lists of ordered pairs zero-one matricesTo represent relations in computer programs, zero-one matrices are usually employed Directed graphsDirected graphs provide pictorial representations of relations, and are useful in determining some of their properties

3 Matrices matrix rows columnsA matrix is a rectangular array of numbers arranged in horizontal rows and vertical columns Each entry in a matrix can be designated using subscripts representing the entry’s row and column: the element at row i, column j of matrix A would be designated a ij The entire matrix A is often represented with the abbreviation [a ij ]

4 Square matrices The size of a matrix is usually represented as m x n, with m representing the number of rows and n the number of columns If m=n, then matrix A is a square matrix

5 Examples The matrix at the right is a 4x3 matrix; the values in row 1 are 1 (at column 1), through 4 (at column 4). The value of a 23 is 7. main diagonal In the square matrix at the right, the elements a 11, a 22 and a 33 form the main diagonal of the matrix.

6 Transpose of a matrix transposeIf A = [a ij ] is an m x n matrix, then the transpose of A is the n x m matrix A T = [a T ij ] We can obtain A T by interchanging the rows and columns of A The transpose of a transpose is the original matix: (A T ) T = A

7 Boolean matrix A zero-one, or Boolean matrix, is a matrix consisting of binary digits Such a matrix can be used to represent a relation between finite sets A relation R from set A to set B can be represented by M R = [m ij ] where –m ij = 1 if (a i, b j )  R –m ij = 0 if (a i, b j )  R

8 Example Suppose set A = {a, b, c, d} and set B = {a, c, d} and relations from A to B R 1 = {(a,a), (a,c), (b,d), (d,d)} and R 2 = {(a,c), (b,d), (c,a), (c,d), (d,a), (d,c)}

9 Operations on Boolean matrices Suppose A=[a ij ] and B=[b ij ] are Boolean matrices and are the same size joinThe join of A and B is matrix C=[c ij ], represented by A V B: –c ij = 1 if a ij = 1 or b ij =1 –c ij = 0 if both a ij and b ij are 0 meetThe meet of A and B is matrix D=[d ij ], represented by A ^ B: –d ij = 1 if a ij = b ij = 1 –d ij = 0 if either a ij or b ij = 0

10 Join and meet: example

11 Boolean product of matrices The Boolean product of m x p matrix A and p x n matrix B, denoted A B, is the m x n matrix C = [c ij ] defined by: –c ij = 1 if a ik = 1 and b kj =1 for some k between 1 and p –c ij = 0 otherwise

12 Finding the Boolean product For any i and j, c ij  C = A B can be computed as follows: –Select row i of A and column j of B and arrange them side by side –Compare corresponding entries; if even a single pair of corresponding entries consists of 2 1’s, then c ij = 1 – if not, then c ij = 0

13 Finding Boolean product

14 Example

15 Matrix of a relation on a set … is a square matrix … can be used to determine certain properties of the relation

16 Reflexivity A relation R on set A is reflexive if (a,a)  R whenever a  A So R is reflexive if m 11 =1, m 22 =1 … m nn =1 In other words, R is reflexive if all elements on the main diagonal of M R = 1

17 Symmetry Any relation R is symmetric if (a,b)  R implies that (b,a)  R A relation R on set A = [a ij ] is symmetric if and only if (a j,a i )  R whenever (a i,a j )  R In matrix M R, we can determine R is symmetric if and only if m ij = m ji for all pairs i, j, with i = 1 … n and j = 1 … n In other words, R is symmetric if and only if M R = (M R ) T

18 Antisymmetry A relation R is antisymmetric if and only if (a,b)  R and (b,a)  R imply that a=b A matrix of an antisymmetric relation has the property that: –If m ij = 1, then m ji = 0 if i  j –Or, if i  j, then either m ij or m ji = 0 (the other could be 0 or 1)