section 7.3

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

Upload: ezra

Post on 07-Feb-2016

35 views

Category:

Documents


0 download

DESCRIPTION

Section 7.3. Representing relations (part 1: matrices). Representing relations. We have already seen that relations between finite sets can be represented using lists of ordered pairs To represent relations in computer programs, zero-one matrices are usually employed - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Section 7.3

1

Section 7.3

Representing relations

(part 1: matrices)

Page 2: Section 7.3

2

Representing relations

• We have already seen that relations between finite sets can be represented using lists of ordered pairs

• To represent relations in computer programs, zero-one matriceszero-one matrices are usually employed

• Directed graphsDirected graphs provide pictorial representations of relations, and are useful in determining some of their properties

Page 3: Section 7.3

3

Matrices

• A matrixmatrix is a rectangular array of numbers arranged in horizontal rowsrows and vertical columnscolumns

• 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 aij

• The entire matrix A is often represented with the abbreviation [aij]

Page 4: Section 7.3

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

Page 5: Section 7.3

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 a23 is 7.

In the square matrix at the right, the elements a11, a22 and a33 form the main main

diagonaldiagonal of the matrix.

Page 6: Section 7.3

6

Transpose of a matrix

• If A = [aij] is an m x n matrix, then the transposetranspose of A is the n x m matrix AT = [aT

ij]

• We can obtain AT by interchanging the rows and columns of A

• The transpose of a transpose is the original matix: (AT)T = A

Page 7: Section 7.3

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 MR = [mij] where

– mij = 1 if (ai, bj) R

– mij = 0 if (ai, bj) R

Page 8: Section 7.3

8

Example

Suppose set A = {a, b, c, d} and set B = {a, c, d} and relations from A to B R1 = {(a,a), (a,c), (b,d), (d,d)} and R2 = {(a,c), (b,d), (c,a), (c,d), (d,a), (d,c)}

Page 9: Section 7.3

9

Operations on Boolean matrices

• Suppose A=[aij] and B=[bij] are Boolean matrices and are the same size

• The joinjoin of A and B is matrix C=[cij], represented by A V B:– cij = 1 if aij = 1 or bij =1

– cij = 0 if both aij and bij are 0

• The meetmeet of A and B is matrix D=[dij], represented by A ^ B:– dij = 1 if aij = bij = 1

– dij = 0 if either aij or bij = 0

Page 10: Section 7.3

10

Join and meet: example

Page 11: Section 7.3

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 = [cij] defined by:

– cij = 1 if aik = 1 and bkj =1 for some k between

1 and p

– cij = 0 otherwise

Page 12: Section 7.3

12

Finding the Boolean product

• For any i and j, cij 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 cij = 1 – if not, then cij = 0

Page 13: Section 7.3

13

Finding Boolean product

Page 14: Section 7.3

14

Example

Page 15: Section 7.3

15

Matrix of a relation on a set

• … is a square matrix

• … can be used to determine certain properties of the relation

Page 16: Section 7.3

16

Reflexivity

• A relation R on set A is reflexive if (a,a)R whenever a A

• So R is reflexive if m11=1, m22=1 … mnn=1

• In other words, R is reflexive if all elements on the main diagonal of MR = 1

Page 17: Section 7.3

17

Symmetry

• Any relation R is symmetric if (a,b)R implies that (b,a)R

• A relation R on set A = [aij] is symmetric if and only if (aj,ai)R whenever (ai,aj)R

• In matrix MR, we can determine R is symmetric if and only if mij = mji for all pairs i, j, with i = 1 … n and j = 1 … n

• In other words, R is symmetric if and only if MR = (MR)T

Page 18: Section 7.3

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 mij = 1, then mji = 0 if ij

– Or, if ij, then either mij or mji = 0 (the other could be 0 or 1)

Page 19: Section 7.3

19

Example

…see the blackboard; see also exercise 7, p 495

Page 20: Section 7.3

20

Representing unions and intersections

• The Boolean matrix operations join and meet can be used to find matrices representing the union and intersection of two relations

• Suppose R1 and R2 are relations on set A; then they are represented by matrices MR1 and MR2

• The matrix representing the intersection of R1 and R2 has a 1 in the positions where both MR1 and MR2

have a 1; the matrix representing their union would have a 1 where either has a 1:MR1 R2 = MR1 MR2

MR1 R2 = MR1 MR2

Page 21: Section 7.3

21

Example

See, again, the blackboard …