Packet #5: Binary Relations Applied Discrete Mathematics Table of Contents Binary Relations Summary Page 1 Binary Relations Examples Page 2 Properties of Relations Page 3 Examples Pages 4-5 Representations Page 6 Composites Page 8 Closures Pages 10-11 Equivalence Relations Pages 12-13 Posets & Hasse Diagrams Pages 14-17 CSC224 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. Non-reflexive: (R is reflexive) D. 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] Asymmetric = irreflexive AND antisymmetric G. Transitive: R is transitive if a, b A, [(a,b) R (b,c) R] (a,c) R Also: R 2 R if and only if R is transitive. III. IV. 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. Inverse Relation V. Composite Relations VI. VII. Closure Properties (Reflexive, Symmetric, & Transitive closures) Special Types A. Equivalence Relations are reflexive, symmetric and transitive (RST) B. Partially Ordered Sets are reflexive, antisymmetric and transitive (RAT) 1
Binary Relations Definition 1. A binary relation is a set of ordered pairs. 2. Each ordered pair consists of elements taken from two sets. 3. The relation xry is an ordered pair, <x,y> R, with x taken from the set S 1, and y taken from the set S 2. 4. S 1 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
Properties of Binary Relations Relation R on set S (Universe of Discourse = S) Reflexive: Example: if, for all x in S, xrx exists, then R is said to be reflexive. x[xrx] 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: 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 Transitive: If x y[(xry yrz) xrz] then R is said to be transitive. Also: R 2 R if and only if R is transitive. CSC224 Packet 5 Binary Relations 3
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 = x 2 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) = x 2 }. 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
Examples (Illustrated Under Examples of Binary Relations) CSC224 Packet 5 Binary Relations 5
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 S 1 = 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: S 1 = S 2 = S = {1,2,3,4} xry = {<1,2>,<1,4>,<2,3>,<4,4>} Matrix Representation: 1 2 3 4 1 0 1 0 1 2 0 0 1 0 3 0 0 0 0 4 0 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 1 0 0 0 0 1 0 0 0 0 1 This matrix is reflexive. CSC224 Packet 5 Binary Relations 6
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 R 2 and check: if R 2 R then R is transitive. Definition of R -1 R -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>} R -1 = {<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 interchange the rows and columns of M to get M T. if R M then R -1 M T. If R is symmetric: M = M T. If R is antisymmetric: (M M T ) is a subset of the identity matrix: i.e. the only 1s are on the major diagonal. If R is transitive: then R 2 R. Compute this using M ο M, the matrix composition. CSC224 Packet 5 Binary Relations 7
Example 2: R for this case is antisymmetric since: x y[(xry yrx) (x = y)] (only elements along major diagonal) Composite Relations Two relations (R 1 and R 2 ) might be composed with each other. However, the inner set between R 1 and R 2 must be the same set. R 1 ο R 2 is read as R 1 composed with R 2. Order is important. One starts with R 2 and looks for the connection to R 1. If R 1 is a relation from S 1 S 2 then R 2 must be a relation from S a x S 1 where S a can be any set. The resulting relation comes from S a x S 2. Example 1: R 1 = {<1,a>, <3,b>, <3,c>, <4,c>} S 1 = {1,2,3,4} R 2 = {<a,1>, <a,2>, <b,3>, <c,2>} S 2 = {a,b,c} S 3 = {1,2,3} R 2 composed with R 1 : R 2 = {<1,1>, <1,2>, <3,3>, <3,2>, <4,2>} R 1 R 2 R 2 <1,a> <a,1>, <a,2> <1,1>, <1,2> <3,b> <b,3> <3,3> <3,c>, <4,c> <c,2> <3,2>, <4,2> CSC224 Packet 5 Binary Relations 8
This function R 2 can be obtained from the matrices of R 1 and R 2, i.e. M 1 and M 2. M of R 2 = M 1 M 2. M 1 and M 2 are matrices of 1's and 0's only. M 1 M 2 is simply to multiply M 1 M 2 except multiply is, and add is. NOTE: R 2 = M 1 M 2!!!! Example: (R 2 ) M 1 M 2 is the same as the matrix of R 2. Note that R 2 gives all of the linkages between S 1 and S 3 through S 2 of exactly length 2. If S 1 = 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.) (R 1 ο R 2 ) ο R 3 = R 1 ο (R 2 ο R 3 ) Associative Law holds (R 1 ο R 2 ) -1 = R 2-1 -1 Inverse CSC224 Packet 5 Binary Relations 9
Class Lemma: If R 1 and R 2 are relations in S T and R 3 and R 4 are relations in T V, the following holds: if R 1 R 2 and R 3 R 4 then R 3 R 4 ο R 2 Proof: U ( ) <x,y> in R 3 = x, j R 1 Λ j,y R 3 n j =1 U ( ) <x,y> in R 4 ο R 2 = x, j R 2 Λ j,y R 4 n j =1 Since R 1 R 2 and R 3 R 4 all <x,j> in R 1 <x,j> in R 2 and <j,y> in R 3 <j,y> in R 4 Therefore, <x,y> in R 3 <x,y> in R 4 ο R 2 Therefore, R 3 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: Rs = R R -1 Transitive closure: R t = U R i i=1 Reflexive and symmetric closures are easy to see. We shall now prove the transitive closure. CSC224 Packet 5 Binary Relations 10
Transitive closure of R is R t = R i U. Proof: i=1 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 = R i U i=1 it contains R 1 = R. To see if R t is transitive: x y[(xry yrz) xrz] if there is an xr t y, then <x,y> is an element in some R k since R t is R t = U R i i=1 and if there is an yr t z, <y,z> is an element in some R j. R k ο R j = R k+ j will have the element <x,z> from the definition of the composite of two relations, but the elements of R k+ j are also elements of R t. Therefore, R t = U R i is transitive. i=1 To show that R t is the minimal relation containing R that is transitive, assume that there is another relation R 1 that is (1) transitive, and (2) contains R. We will show by induction that R t R 1. We will do this by showing that R i R 1 for all i, since R t = U R i i=1 For i = 1, R R 1, true since R 1 contains R. Assume true for R i, ie R i R 1 Prove true for R i+1, must show that R i+1 R 1. R i+1 = R i R R i R 1 by assumption and R R 1 by basis R i ο R R 1 by class lemma proven earlier but R i ο R R 1 since R 1 is transitive. Therefore, R i ο R R 1 R 1 Therefore, R i ο R R 1 is true for all i. CSC224 Packet 5 Binary Relations 11
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 T 1 RT 2 triangles T 1 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 M 1 RM 2 triangles M 1 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]?) For any x,y in S, if xry then f(x) = f(y). Thus f(y) = f(x), so yrx. 3. 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), so xrz. 5. 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? 2 (evens and odds) CSC224 Packet 5 Binary Relations 12
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 R 1? [0] = [1] = [2] =... (one equivalence class) 6. Define R on R 2 by <x,y>r<u,v> x 2 + y 2 = u 2 + v 2 Show R is an equivalence relation: (S = R 2 ) 1. Reflexive: For any <x,y> S, <x,y>r<x,y> since x 2 + y 2 = x 2 + y 2. 2. Symmetric: For any <x,y>, <u,v> S, if <x,y>r<u,v>, then x 2 + y 2 = u 2 + v 2. So, u 2 + v 2 = x 2 + y 2. Thus, <u,v>r<x,y>. 3. Transitive: For any <x,y>, <u,v>, <w,z> S, if <x,y>r<u,v> and <u,v>r<w,z>, then x 2 + y 2 = u 2 + v 2 and u 2 + v 2 = w 2 + z 2. So, x 2 + y 2 = w 2 + z 2. Thus, <x,y>r<w,z>. Equivalence classes of R? [<0,0>] =? {<0,0>} [<0,1>] =? [<-2,3>] =? {<x,y> R 2 x 2 + y 2 = 13} How many equivalence classes? infinitely many CSC224 Packet 5 Binary Relations 13
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
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
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