Packet 5

advertisement
CSC224/226 – Packet 5 – Binary Relations
Packet #5: Binary Relations
Applied Discrete Mathematics
Table of Contents
Binary Relations Summary
Binary Relations Examples
Properties of Relations
Examples
Representations
Page 1
Page 2
Page 3
Pages 4-5
Page 6
Composites
Closures
Equivalence Relations
Posets & Hasse Diagrams
Page 8
Pages 10-11
Pages 12-13
Pages 14-17
CSC224 – Packet 5 – Binary Relations
CSC224/226 – Packet 5 – Binary Relations
Binary Relations Summary
I.
Definition: A binary relation is a set of points, or ordered pairs. The ordered
pairs are of the form (a,b) where a is a member of a set A (a  A) and b is
a member of a set B (b  B). Any subset R  A x B is a binary relation.
(Remember that A x B is the set of ordered pairs {(a,b) | aA  b  B})
II.
Properties: Consider the binary relation R  A x A.
A.
Reflexive:R is reflexive if
 a  A, (a,a)  R
B.
Irreflexive: R is irreflexive if
 a  A, (a,a)  R.
Is  (R is reflexive)  (R is irreflexive)?
C.
D.
Non-reflexive:  (R is reflexive)
Symmetric: R is symmetric if  a, b  A, [ ((a,b)  R)  ((b,a)  R) ]
E.
Antisymmetric: R is antisymmetric if
 a, b  A, [(a,b)  R  (b,a)  R]  (b = a)
F.
Asymmetric: R is asymmetric if
 a, b  A, [(a,b)  R]  [(b,a)  R]
G.
III.
Asymmetric = irreflexive AND antisymmetric
Transitive: R is transitive if
 a, b  A, [(a,b)  R  (b,c)  R]  (a,c)  R
Also: R2  R if and only if R is transitive.
Representations
A.
Matrix: Form a matrix with the rows labeled with elements of A and
the columns labeled with elements of B. Then place a 1 in position (a,b) if
(a,b)  R and a 0 in position (a,b) if (a,b)  R.
B.
Digraph: Make a column of dots, label one for each element of A.
Make another column of dots for the elements of B. Now, for
every element (a,b) in R, draw an arrow from point a to point b.
IV.
Inverse Relation
V.
Composite Relations
VI.
Closure Properties (Reflexive, Symmetric, & Transitive closures)
VII.
Special Types
A. Equivalence Relations are reflexive, symmetric and transitive (RST)
B. Partially Ordered Sets are reflexive, antisymmetric and transitive (RAT)
1
CSC224/226 – Packet 5 – Binary Relations
Binary Relations
Definition
1.
2.
3.
4.
A binary relation is a set of ordered pairs.
Each ordered pair consists of elements taken from two sets.
The relation xRy is an ordered pair, <x,y> R, with x taken from
the set S1, and y taken from the set S 2 .
S1 and S 2 can be finite or infinite. They do not have to be equal.
Examples of Binary Relations
A binary relation R on the set SxT.
Example:
S = {a, b, c}
T = {1, 2, 3}
R = {(a, 1), (a, 3), (b, 2), (c, 3)}
A special binary relation R is a subset of SxS.
Example:
S = {a,b,c,d}
R = {<a,a>, <a,b>, <a,c>, <b,a>, <b,d>, <c,a>, <c,b>, <d,b>}
R is a factor relation on , where for x,y  , xRy  x is a factor of y
True or False? 3R6, 5R6, 6R3, 8R24, 5R5, 12R16
Define R on  by xRy  x < y
True or False? 2R3, 2R2, 5R10, 3R2, -1R1, 0R-1
Let R be the "congruent mod 5" relation on  x  for x,y  ,
xRy  (x-y) is divisible by 5 x  y (mod 5)
True or False? 2R7, -2R2, 2R2, 23R3, 3R23, -1R4, 0R10, -1R5
Let R be the subset relation,
P({1,2,3}), where for A,B  P({1,2,3}), ARB  A  B
True or False? R{1,2}, {1}R{2}, {1}R{1,2,3}, {2,3}R{2,3}, {1,2}R
CSC224 – Packet 5 – Binary Relations
2
CSC224/226 – Packet 5 – Binary Relations
Properties of Binary Relations
Relation R on set S (Universe of Discourse = S)
Reflexive:
if, for all x in S, xRx exists, then R is said to be reflexive.
x[xRx]
Example:
S = {1,2,3,4}
if <1,1>;<2,2>;<3,3>;<4,4>  R, then R is reflexive.
if S = , then R is also empty. Is R reflexive?
Irreflexive:
Note:
Symmetric:
if, for all x in S, there is no xRx, then R is said to be irreflexive.
x[(xRx)]
To be irreflexive is different from being non-reflexive.
x[ (xRx)] irreflexive
¬x(xRx) = x[(xRx)] non-reflexive
If xy[xRy  yRx] then R is said to be symmetric.
Antisymmetric:
Note:
Transitive:
If xy[(xRy  yRx)  (x = y)] then R is said to be
antisymmetric.
To be antisymmetric is different from being asymmetric.
xy[xRy  (yRx)] asymmetric
If xy[(xRy yRz)  xRz] then R is said to be transitive.
Also: R2  R if and only if R is transitive.
CSC224 – Packet 5 – Binary Relations
3
CSC224/226 – Packet 5 – Binary Relations
Examples of Binary Relations
Example 1: The real plane (R x R) is a binary relation, where points are of the
form (x,y) where x  R is on the real x-axis and y  R is on the real y-axis.
Example 2: The set of points on the graph y = x2 forms a subset of R x R, so it is a
binary relation. It can be written as a set as well as by a graph. The set notation
is: {(x,f(x)) | x  R and f(x) = x2 }. Some points in this binary relation are: (0,0), (1,1), (1,1), (2,4), (3,9). What are some points that are not in this binary relation?
Example 3: Define a relation R  A x B where A is the set of all dogs on the
planet, and B is the set of all humans, and (a,b)  R if dog a belongs to person b.
If Tony is a boy and Sparky is a dog, can (Tony, Sparky) be in R? Notice that not
all dogs have owners and not all people have dogs, so R  A x B.
Example 4: Let A = {1,3,4,6,7}. Here are some binary relations on A x A. For each
of them, determine which properties the relations have.
R1 = {(1,3),(7,4)} is a binary relation.
R2 is defined by: a  A) b  A) a  b  (a,b)  R
R2 = {(1,1),(1,3),(1,4),(1,6),(1,7),
(3,3),(3,4),(3,6),(3,7),(4,4),(4,6),(4,7),(6,6),(6,7),(7,7)}
R3 is defined by: a  A) b  A) a > b  (a,b)  R
R3 = ?
R4 is defined by: a  A) b  A) a  b (mod 3)  (a,b)  R
(Remember that a  b (mod 3) means that a and b have the
same remainder if you divide both of them by 3.)
R4 = { (1,1),(1,4),(1,7),(3,3),(3,6),(4,1),(4,4),(4,7),(6,3),(6,6),
(7,1),(7,4),(7,7)}
CSC224 – Packet 5 – Binary Relations
4
CSC224/226 – Packet 5 – Binary Relations
Examples (Illustrated Under Examples of Binary Relations)
CSC224 – Packet 5 – Binary Relations
5
CSC224/226 – Packet 5 – Binary Relations
Representations of Binary Relations
A matrix can be used to represent the binary relation by using a 1 to indicate the
pairs in the relationship and 0 elsewhere. If S1 = S 2 , a digraph (also called a
directed graph) can be also used to represent the relation, xRy. A digraph
consists of vertices (elements of the set S) and directional branches indicating
the connection in the ordered pair.
example:
S1 = S 2 = S = {1,2,3,4}
xRy = {<1,2>,<1,4>,<2,3>,<4,4>}
Matrix Representation:
1 2 3 4
1 0
2 0
3 0
4 
0
1
0
0
0
0
1
0
0
1
0
0
1

Digraph Representation
1
2
3
4
It is easy to see if a relation is reflexive from the matrix representing the relation.
If the relation is reflexive, M will have all 1's in its major diagonal. If the relation is
irreflexive, M will have all 0's in its major diagonal. If the relation is non-reflexive,
M will have a mixture of 0's and 1's in its major diagonal.
1
0
0

0
0 0 0 
1 0 0 
This matrix is reflexive.
0 1 0 
0 0 1 

CSC224 – Packet 5 – Binary Relations
6
CSC224/226 – Packet 5 – Binary Relations
If the relation is symmetric, M is symmetric about the major diagonal. If the
relation is antisymmetric, M will not have any symmetry about the major
diagonal. If the relation is non-symmetric, M will have at least one set of
elements that are symmetric about the major diagonal. (The matrix given below
is symmetric.)
0
1
0

0
1
0
1
0
0
1
1
0
0 
0 
0 
0 

Transitivity is a little more difficult to check. One can check element by element
xRy, yRz, and xRz for all x, y, and z. You must check EVERY pair xRy and yRz and
make sure that xRz is in the relation. Alternatively, you can compute R2 and
check: if R2  R then R is transitive.
Definition of R
R
-1
-1
is obtained by interchanging the x,y pair for each element in R. So if
R  A x B, then R
-1
 B x A.
Example 1: R = {<1,2>, <3,4>, <2,3>, <4,1>}
-1
R = {<2,1>, <4,3>, <3,2>, <1,4>}
Using the Matrix to check for properties:
If M is the matrix for R, then R
-1
is represented by the transpose of M, where we
T
interchange the rows and columns of M to get M .
-1
T
if R  M then R  M .
T
If R is symmetric: M = M .
T
If R is antisymmetric: (M M ) is a subset of the identity matrix: i.e. the only 1s are
on the major diagonal.
If R is transitive: then R2  R. Compute this using M  M, the matrix composition.
CSC224 – Packet 5 – Binary Relations
7
CSC224/226 – Packet 5 – Binary Relations
Example 2:
R for this case is antisymmetric since: xy[(xRy  yRx)  (x = y)]
(only elements along major
diagonal)
Composite Relations
Two relations (R1 and R 2 ) might be composed with each other. However, the
inner set between R1 and R 2 must be the same set.
R1  R 2 is read as R1 composed with R 2 . Order is important. One starts with R 2
and looks for the connection to R1.
If R1 is a relation from S1S 2 then R 2 must be a relation from S x S1where S
a
a
can be any set. The resulting relation comes from S x S 2 .
a
Example 1:
R1 = {<1,a>, <3,b>, <3,c>, <4,c>} S1 = {1,2,3,4}
R 2 = {<a,1>, <a,2>, <b,3>, <c,2>} S 2 = {a,b,c}
R 2 composed with R1:
S 3 = {1,2,3}
R 2  R1 = {<1,1>, <1,2>, <3,3>, <3,2>, <4,2>}
R1
<1,a>
<3,b>
<3,c>, <4,c>
R2
R 2  R1
<a,1>, <a,2> <1,1>, <1,2>
<b,3>
<3,3>
<c,2>
<3,2>, <4,2>
CSC224 – Packet 5 – Binary Relations
8
CSC224/226 – Packet 5 – Binary Relations
This function R 2  R1 can be obtained from the matrices of R1 and R 2 , i.e. M1
and M 2 . M of R 2  R1 = M1
M 2 . M1 and M 2 are matrices of 1's and 0's
only. M1
M 2 is simply to multiply M1  M 2 except multiply is , and add is .
NOTE: R 2  R1 = M1
M 2 !!!!
Example: (R 2  R1)
M1
M 2 is the same as the matrix of R 2  R1.
Note that R 2  R1 gives all of the linkages between S1 and S 3 through S 2 of
exactly length 2. If S1 = S 2 = S 3 (special relations), then R  R gives all the
linkages of exactly length 2 in S. Notice the comparison of that to the statement
xRy  yRz (link y of length 2 between x and z).
Therefore, if R is transitive, xy[(xRy yRz)  xRz]
then x  (R  R) x  R. Therefore the matrix of R  R must be a subset of R.
If R is reflexive, symmetric, and transitive, then R is an equivalence relation.
(Discussed later.)
If R is reflexive, antisymmetric, and transitive, then R is a partially ordered set (or
poset for short). (Discussed later.)
(R1  R 2 )  R 3 = R1  (R 2  R 3 )
(R1  R 2 )
-1
= R2
-1
 R1
-1
Associative Law holds
Inverse
CSC224 – Packet 5 – Binary Relations
9
CSC224/226 – Packet 5 – Binary Relations
Class Lemma: If R1 and R 2 are relations in ST and R 3 and R 4 are relations in
TV, the following holds:
if R1  R 2 and R 3  R 4 then R 3  R1  R 4  R 2
Proof:
<x,y> in R 3  R1 =
<x,y> in R 4  R 2 =
n
j 1
 x, j
n
j 1
 x, j
 R1  j,y  R3 
 R2  j,y  R4 
Since R1  R 2 and R 3  R 4
all <x,j> in R1  <x,j> in R 2
and <j,y> in R 3  <j,y> in R 4
Therefore, <x,y> in R 3  R1  <x,y> in R 4  R 2
Therefore, R 3  R1  R 4  R 2
Closure Properties
The closure of a binary relation, R, with respect to a property, is the minimal
relation that contains the relation R and exhibits the given property.
Reflexive closure:
R f = R  E where E = {<x,x>  x  S}
Symmetric closure:
-1
Rs = R  R
Transitive closure:
 i
Rt = R
i1
Reflexive and symmetric closures are easy to see. We shall now prove the
transitive closure.
CSC224 – Packet 5 – Binary Relations
10
CSC224/226 – Packet 5 – Binary Relations
Transitive closure of R is R t =
1.
 i
R . Proof:
i1
R t must contain R and be transitive.
2.
R t must be the minimal relation of that type.
Since R t is as follows:

R t = Ri
i1
it contains R1 = R.
To see if R t is transitive:
xy[(xRy yRz)  xRz]
k
if there is an xR t y, then <x,y> is an element in some R since R t is

R t = Ri
i1
j
and if there is an yR t z, <y,z> is an element in some R .
j
k
k j
R R =R
will have the element <x,z> from the definition of the composite
k j
of two relations, but the elements of R
are also elements of R t .

Therefore, R t = Ri is transitive.
i1
To show that R t is the minimal relation containing R that is transitive, assume that
there is another relation R1 that is (1) transitive, and (2) contains R.
We will show by induction that R t  R1. We will do this by showing that R
for all i, since

R t = Ri
i1
i
For i = 1, R  R1, true since R1 contains R.
Assume true for R , ie R
i
Prove true for R
R
R
R
i1
i
i
i1
i
 R1
, must show that R
i1
 R1.
= R R
 R1 by assumption and R  R1 by basis
i
 R  R1  R1 by class lemma proven earlier
but R
i
 R  R1 since R1 is transitive.
Therefore, R
i
 R  R 1  R 1  R1
Therefore, R
i
 R  R1 is true for all i.
CSC224 – Packet 5 – Binary Relations
11
 R1
CSC224/226 – Packet 5 – Binary Relations
Equivalence Relations
A relation is an equivalence relation if it is (reflexive, symmetric, transitive)
Examples:
1.
Define R on N by xRy  x = y.
2.
Let S be the set of all triangles.
Define R on S by T1RT 2  triangles T1 and T 2 are similar.
3.
Let S be the set of all finite state machines with input alphabet {0,1}.
Define R on S by M1RM 2  triangles M1 and M 2 accept the same
language.
4.
Let f be a function f: S  T.
Define R on S by xRy  f(x) = f(y).
Show R is an equivalence relation:
1.
Reflexive: (x[xRx]?)
Since f(x) = f(x) for all x  S, xRx for all x  S.
2.
Symmetric: (xy[xRy  yRx]?)
3.
For any x,y in S, if xRy then f(x) = f(y). Thus f(y) = f(x), so yRx.
Transitive: (xy[(xRy  yRz)  xRz]?)
For any x,y,z  S, if xRy and yRz then f(x) = f(y) and f(y) = f(z).
Thus f(x) = f(z),
5.
so xRz.
Let p  . (Congruence mod p)
Define R p on Z by x R p y  (x-y) is divisible by p
Can show R p is an equivalence relation.
If R is an equivalence relation on a set S, then R partitions S into
equivalence classes.
For any s  S, [s] denotes the equivalence class containing s.
[s] = {x  S  xRs}
Consider R 2 :
[7] = {...-5,-3,-1,1,3,5,7,9,11,13,...}
[5] = {...-5,-3,-1,1,3,5,7,9,11,13,...}
[2] = {...-4,-2,0,2,4,6,8,...}
How many equivalence classes?
CSC224 – Packet 5 – Binary Relations
2 (evens and odds)
12
CSC224/226 – Packet 5 – Binary Relations
Consider R 3 : What are the equivalence classes?
[0] = [3] = multiples of three
[1] = [4] = {...-8,-5,-2,1,4,7,10...}
[2] = [5] = {...-4,-1,2,5,8,11,...}
What about R1?
[0] = [1] = [2] = ...
(one equivalence class)
6.
Define R on  2 by <x,y>R<u,v> x 2 + y 2 = u 2 + v 2
2
Show R is an equivalence relation: (S =  )
2
2
2
2
1.
Reflexive: For any <x,y>  S, <x,y>R<x,y> since x + y = x + y .
2.
Symmetric: For any <x,y>, <u,v>  S, if <x,y>R<u,v>, then
2
2
2
2
2
2
2
2
x + y = u + v . So, u + v = x + y . Thus, <u,v>R<x,y>.
3.
Transitive: For any <x,y>, <u,v>, <w,z>  S, if <x,y>R<u,v> and
2
2
2
2
2
2
2
2
<u,v>R<w,z>, then x + y = u + v and u + v = w + z .
2
2
2
2
So, x + y = w + z . Thus, <x,y>R<w,z>.
Equivalence classes of R?
[<0,0>] = ?
{<0,0>}
[<0,1>] = ?
[<-2,3>] = ?
2
2
2
{<x,y>    x + y = 13}
How many equivalence classes? infinitely many
CSC224 – Packet 5 – Binary Relations
13
CSC224/226 – Packet 5 – Binary Relations
Partially Ordered Sets (Usually called a Poset)
A relation is called a poset if it is reflexive, antisymmetric, and transitive.
A subset of a poset P is a poset called a subposet of P.
Hasse Diagrams
Suppose R is a partial order on S. For elements s,t  S, say "t covers s" if sRt and
there is no u S satisfying: sRuRt but u  s and u  t.
A Hasse Diagram follows the rules given below:
1.
has a point for each element of S.
2.
whenever t covers s, point t should be higher than point s, and t and s
should be joined by a line segment.
Note: Do not connect an element to itself and do not connect transitive
elements.
An element x is maximal if there is no y in the poset so that xRy. An element x is
maximum if yRx for all y in poset. Note that maximum elements are also
maximal. (Think about this). Maximal elements and maximums are covered by
nothing. There is at most one maximum element in a poset. There can be many
maximal elements in a poset.
An element x is minimal if there is no y in the poset so that yRx. An element x is
minimum if xRy for all y in poset. Note that minimum elements are also minimal.
(Think about this). Minimal elements and minimums cover nothing. There is at
most one minimum in a poset. There can be many minimal elements in a poset.
Examples
Example 1: Define R as "is a factor of" with S = {1,2,3,4,...,16}.
What covers 1? 2,3,5,7,11,13
3? 6,9,15
9? Nothing
What is covered by 12? 4,6
Hasse Diagram: (Minimal elements are boxed and maximal elements are
circled.)
CSC224 – Packet 5 – Binary Relations
14
CSC224/226 – Packet 5 – Binary Relations
Example 1: Hasse diagram for the relation R=({1,2,3,4, ... , 16}, |)
(|= divides, or "is a factor of")
Example 2: Hasse Diagram for the relation "" on P({1,2,3})
CSC224 – Packet 5 – Binary Relations
15
CSC224/226 – Packet 5 – Binary Relations
Upper Bounds and Lower Bounds
ub({a}) = {z| aRz }, the set of elements z so that a relates to z.
ub({a,b,c}) = the intersection of ub({a}), ub({b}), and ub({c}).
lb({a}) = {z| zRa}, the set of elements z so that z relates to a.
lb({a,b,c}) = the intersection of lb({a}), lb({b}), lb({c}).
lub(x,y) is the least upper bound = "lowest" element z with xRz and yRz.
glb(x,y) is the greatest lower bound = "highest" element w with wRx and wRy.
Examples
Example 1: Hasse Diagram:
lub(e,d) = a
lub(h,c) = a
lub(i,h) = h
lub(e,h,g) = a
lub(a,b) = does not exist
glb(f,g) = h
glb(a,b,d) = d
glb(e,d) = i
glb(i,h) = i
Example 2: If R is the "is a divisor of" relation on , then for x,y 
lub(x,y) = least common multiple of x and y
glb(x,y) = greatest common divisor of x and y.
Lattice: A poset is a lattice if for every pair of elements x,y in the poset, both
lub(x,y) and glb(x,y) exist and are in the poset.
CSC224 – Packet 5 – Binary Relations
16
Download