210 likes | 366 Views
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
E N D
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 • Directed graphs provide pictorial representations of relations, and are useful in determining some of their properties
Matrices • A 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 aij • The entire matrix A is often represented with the abbreviation [aij]
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
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 diagonal of the matrix.
Transpose of a matrix • If A = [aij] is an m x n matrix, then the transpose of A is the n x m matrix AT = [aTij] • We can obtain AT by interchanging the rows and columns of A • The transpose of a transpose is the original matix: (AT)T = A
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
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)}
Operations on Boolean matrices • Suppose A=[aij] and B=[bij] are Boolean matrices and are the same size • The join 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 meet 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
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
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
Matrix of a relation on a set • … is a square matrix • … can be used to determine certain properties of the relation
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
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
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)
Example …see the blackboard; see also exercise 7, p 495
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
Example See, again, the blackboard …