8 3 Representing Relations Connection Matrices Let R













- Slides: 13
8. 3 Representing Relations Connection Matrices • Let R be a relation from A = {a 1, a 2, . . . , am} to B = {b 1, b 2, . . . , bn}. • Definition: An m n connection matrix M for R is defined by Mij = 1 if <ai, bj> is in R, = 0 otherwise. • Example: We assume the rows are labeled with the elements of A and the columns are labeled with the elements of B. Let A = {a, b, c} , B = {e, f, g, h}; R = {<a, e>, <c, g>} • Then the connection matrix M for R is • Note: the order of the elements of A and B matters 1
Representing Relations • Theorem: Let R be a binary relation on a set A and let M be its connection matrix. Then • R is reflexive iff Mii = 1 for all i. • R is symmetric iff M is a symmetric matrix: M = MT • R is antisymetric if Mij = 0 or Mji = 0 for all i ≠ j. FIGURE 1 The Zero-One Matrix for a Reflexive Relation. FIGURE 2 The Zero-One Matrices for Symmetric and Antisymmetric Relations. 2
Combining Connection Matrices • Example 3: Suppose that the relation R on a set is represented by the matrix • Is R reflexive, symmetric and/or antisymmetric? • Definition: the join of two matrices M 1, M 2, denoted M 1 Ú M 2 , is the component wise boolean ‘or’ of the two matrices. • Fact: If M 1 is the connection matrix for R 1 and M 2 is the connection matrix for R 2 then the join of M 1 and M 2 , M 1 Ú M 2 is the connection matrix for R 1∪R 2. 3
Combining Connection Matrices • Definition: the meet of two matrices M 1, M 2, denoted M 1 Ù M 2 is the componentwise boolean ‘and’ of the two matrices. • Fact: If M 1 is the connection matrix for R 1 and M 2 is the connection matrix for R 2 then the meet of M 1 and M 2, M 1 Ù M 2 is the connection matrix for R 1∩R 2. • Example 4: Suppose that the relations R 1 and R 2 on a set A are represented by the matrices. and , What are the matrices representing R 1∪R 2 and R 1∩R 2 ? 4
The Composition • Definition: Let M 1 be the connection matrix for R 1 M 2 be the connection matrix for R 2. • The boolean product of two connection matrices M 1 and M 2, denoted M 1 Ä M 2 , is the connection matrix for the composition of R 2 with R 1 , R 2。R 1. n • Why? (M 1 Ä M 2 )ij = Úk=1 [(M 1 )ik Ù (M 2 )kj ] 5
The Composition • In order for there to be an arc <x, z> in the composition there must be and arc <x, y> in R 1 and an arc <y, z> in R 2 for some y ! • The Boolean product checkes all possible y’s. If at least one such path exists, that is sufficient. • Note: the matrices M 1 and M 2 must be conformable: the number of columns of M 1 must equal the number of rows of M 2. • If M 1 is m n and M 2 is n p then M 1 Ä M 2 is m p. 6
The Composition Example : (M 1 Ä M 2 )12 = [(M 1 )11 Ù (M 2 )12 ]Ú[(M 1 )12 Ù(M 2 )22 ] Ú[(M 1 )13 Ù (M 2 )32 ]Ú[(M 1)14 Ù (M 2 )42 ] = [0 Ù 0] Ú [1Ù 1]Ú [0 Ù 0] Ú [0 Ù 1] = 1 7
The Composition • • Note: there is an arc in R 1 from node 1 in A to node 2 in B there is an arc in R 2 from node 2 in B to node 2 in C. Hence there is an arc in R 2。R 1 from node 1 in A to node 2 in C. 8
Representing Relations Using Digraphs • Definition 1: A directed graph, or digraph, consists of a set V of vertices (or nodes ) together with a set E of ordered pairs of elements of V called edges (or arcs). • The vertex a is called the initial vertex of the edge (a, b), and the vertex b is called the terminal vertex of this edge. • An edge of the form (a, a) is represented using an arc from the vertex a back to itself. Such an edge is called a loop. 9
Representing Relations Using Digraphs • Example 7: The directed graph with vertices a, b, c, and d, and edges (a, b), (a, d), (b, b), (b, d), (c, a), (c, b), and (d, b) is displayed in Figure 3. FIGURE 3 The Directed Graph. 10
Representing Relations Using Digraphs • Example 8: The directed graph of the relation R={(1, 1), (1, 3), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (4, 1)} on the set {1, 2, 3, 4} is shown in figure 4. FIGURE 4 The Directed Graph of the Relations R. 11
Representing Relations Using Digraphs • Example 9: What are the ordered pairs in the relation R represented by the directed graph shown in figure 5? FIGURE 5 The Directed Graph of the Relations R. 12
Representing Relations Using Digraphs • Example 10: Determine whether the relations for the directed graphs shown in figure 6 are reflexive, symmetric, antisymmetric, and/or transitive. FIGURE 6 The Directed Graph of the Relations R and S. 13