M 2

advertisement
8.3 Representing Relations
Connection Matrices
• Let R be a relation from
A = {a1, a2, . . . , am} to B = {b1, b2, . . . , 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} ,
1 0 0 0 
B = {e, f, g, h}; R = {<a, e>, <c, g>}
0 0 0 0 

• Then the connection matrix M for R is 
0 0 1 0
• 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
1 1 0 
M R  1 1 1
0 1 1
• Is R reflexive, symmetric and/or antisymmetric?
• Definition: the join of two matrices M1, M2, denoted
M1 M2 , is the component wise boolean ‘or’ of the two
matrices.
• Fact: If M1 is the connection matrix for R1 and M2 is the
connection matrix for R2 then the join of M1 and M2 ,
M1  M2 is the connection matrix for R1∪R2 .
3
Combining Connection Matrices
• Definition: the meet of two matrices M1, M2, denoted
M1  M2 is the componentwise boolean ‘and’ of the
two matrices.
• Fact: If M1 is the connection matrix for R1 and M2 is
the connection matrix for R2 then the meet of M1 and
M2, M1  M2 is the connection matrix for R1∩R2 .
• Example 4: Suppose that the relations R1 and R2 on a
set A are represented by the matrices.
M R1
1
 1
0
0
0
1
1
0
0
and , M R
2
1
 0
1
0
1
0
1
1 
0
What are the matrices representing R1∪R2 and R1∩R2 ? 4
The Composition
• Definition: Let
M1 be the connection matrix for R1
M2 be the connection matrix for R2.
• The boolean product of two connection matrices M1
and M2, denoted M1 M2 , is the connection matrix
for the composition of R2 with R1 , R2。R1.
(M1 M2 )ij =
• Why?
n
k=1
[(M1 )ik (M2 )kj ]
5
The Composition
• In order for there to be an arc <x, z> in the composition
then there must be and arc <x, y> in R1 and an arc <y, z>
in R2 for some y !
• The Boolean product checkes all possible y’s. If at least
one such path exists, that is sufficient.
• Note: the matrices M1 and M2 must be conformable: the
number of columns of M1 must equal the number of rows
of M2.
• If M1 is m n and M2 is n  p then M1  M2 is m p.
6
The Composition
Example :
(M1 M2 )12 [(M1 )11 (M2 )12 ][(M1 )12 (M2 )22 ]
[(M1 )13 (M2 )32 ][(M1)14 (M2 )42 ]
= [0 0] [11][0 0] [0 1] 1
7
The Composition
•
•
•
•
Note:
there is an arc in R1 from node 1 in A to node 2 in B
there is an arc in R2 from node 2 in B to node 2 in C.
Hence there is an arc in R2。R1 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
Download