530 likes | 1.36k Views
Binary Relation:. A binary relation between sets A and B is a subset of the Cartesian Product A x B . If A = B we say that the relation is a relation on A . Suppose A = {1, 3, 5, 7} and B = {2, 4, 6, 8}.
E N D
Discrete Math for CS Binary Relation: • A binary relation between sets A and B is a subset of the Cartesian Product A x B. If A = B we say that the relation is a relation on A. • Suppose A = {1, 3, 5, 7} and B = {2, 4, 6, 8}. • Further suppose R = { (1,2), (3,4), (5,6), (7,8)}. This is a subset of A x B so is a binary relation between A and B B 8 6 4 2 A 1 3 5 7
Discrete Math for CS Binary Relation Exercise: • If R = { (a,b): a < b}. Show R on the diagram below. B 8 6 4 2 A 1 3 5 7
Discrete Math for CS Binary Relations as Sets of Ordered Pairs: • Because we mention one set before another in a Cartesian Product, A x B, the element, (a,b), in any relation, R, over A and B must have its first element from A and its second element from B. • So we say that the elements of R form ordered pairs.
Discrete Math for CS Exercise: • If X = {1, 2, 3, 4, 5, 6}, find R = { (x,y): x is a divisor of y} R = { (1,1), (1,2), (1,3), (1,4), (1,5), (1,6), (2,2), (2,4), (2,6), (3,3), (3,6) }
Discrete Math for CS Graph Representation of a Binary Relation: • If A and B are two finite sets and R is a binary relation between A and B we can represent this relation as a graph (set of vertices and edges). A = {1, 3, 5 ,7}, B = {2, 4, 6, 8} R = {(a,b): a < b} 1 2 We call this graph a directed graph. 3 4 5 6 7 8
Discrete Math for CS Example: • A = {1, 2, 3, 4, 5, 6}. R is a relation on A defined by the following directed graph. 1 2 Exercise: Give a rule-based definition of R 6 3 R = {(a,b): a divides b} 5 4
Discrete Math for CS Matrix Representation of a Binary Relation: • If A and B are finite sets and R is a binary relation between A and B then create a matrix, M, with the following properties: • the rows of the matrix are indexed by the elements of A • the columns of the matrix are indexed by elements of B • M(ai,bj) = 1 if (ai,bj) belongs to R; 0 otherwise B 2 4 6 8 Exercise: Give a rule-based definition of R 1 0 1 1 1 0 0 1 1 3 R = {(a,b): a + 1 < b} A 0 0 0 1 5 0 0 0 0 7
Discrete Math for CS Notation: • If R is a binary relation on a set, X, we write x R y whenever (x,y) ε R. Example: sister_of relationship on girls in a school can be expressed as x is_sister_of y.
Discrete Math for CS RelationProperties: • Suppose R is a relation on a set A. • We say • R is reflexive if a R a for all a ε A. • R is symmetric if x R y ==> y R x for all x, y ε A. • R is antisymmetric when (x R y and y R x ==> x == y) for all x, y ε A. • R is transitive when (x R y and y R z ==> x R z) for allx, y, z ε A.
Discrete Math for CS Understanding Relations as Ordered Pairs: • R is reflexive if (x,x) ε R for all x ε A. • R is symmetric if when (x,y) ε R then (y,x) ε R for all x,y ε A. • R is antisymmetric if when (x,y) ε R and x != y then (y,x) ε R. • R is transitive if when (x,y) ε R and (y,z) ε R then (x,z) ε R
Discrete Math for CS Understanding Relations as digraphs. • If R is a relation represented as a di-graph then • R is reflexive if every node has a loop to itself attached. • R is symmetric if every directed edge is directed in both directions. • R is antisymmetric if there is no bi-directional edge. • If there is a directed edge from x to y and another from y to z then there is a directed edge from x to z y x z
Discrete Math for CS Understanding Relations as Matrices: • Given a binary relation R on a finite set X. • Let M be the matrix whose rows and columns are indexed by the elements of X. • R is reflexive if the elements on the leading diagonal are all 1(T). • R is symmetric if the matrix is symmetric about the main diagonal. • R is antisymmetric if there are no symmetrical elements. Hence if mij == 1 the mji != 1. • The text says transitivity is not readily apparent. We'll see!
Discrete Math for CS Exercise: • Evaluate the following relations for the previously mentioned properties: • x divides y on the natural numbers • x != y on the integers. • x is the same age as y in the set of all people. • a/b has the same value as c/d in the set of all rationals, Q.
Discrete Math for CS Equivalence Relation: • A relation R on a set A that is reflexive, symmetric and transitive is said to be an equivalence relation. • Equivalence relations generalize the concept of equality. • Exercise: Show = is an equivalence relation. • Exercise: Show a/b has the same value as c/d in the set of all rationals, Q is an equivalence relation. • Exercise: Show “has the same angles” is an equivalence relation on the set of all triangles.
Discrete Math for CS Equivalence Relations and Partitions: • The examples on the previous slide show there is a strong relationship between equivalence relations and partitions. • A partition is a set of non-empty subsets A1, A2, ... of a set A such that • A1 U A2 U ... = A • Ai Aj = O for every pair i, j where i != j. • We call each Ai a block of the partition. U
Discrete Math for CS Example: A A2 A1 A4 A5 A3
Discrete Math for CS Equivalence Class: • If R is an equivalence relation on a set E, thenis called the equivalence class of x. • An easy way to represent an equivalence class of an element x is [x]. Ex = { y ε E: y R x }
Discrete Math for CS Here it comes!
Discrete Math for CS Theorem: • Let R be an equivalence relation on a set A, then the equivalence classes of R form a partition of A. • Proof: All equivalence classes are non-empty subsets of A. This is because for every x ε A, xRx and so x ε Ex.Second, if xRy, then Ex = Ey. Suppose xRz, then z ε Ex. However zRx since R is symmetric and so zRy by transitivity and so z ε Ey. Hence Ex Ey. Similarly Ey Ex. Hence Ex = Ey.Now we must show that equivalence classes satisfy the first property of a partition. Namely, that the union of all the equivalence classes is the entire set. First Ex A since the relation is defined over A. U U U U
Discrete Math for CS U U U U Proof (cont): So Since every x in A belongs to an Ex (remember xRx) we can say Hence U Ex A U Ex A x x A U Ex A U Ex x x A = U Ex x
Discrete Math for CS Proof (cont): • We are left having to prove the second part of the definition of a partition. Namely that any two equivalence classes that are not equal are disjoint. • The contrapositive is actually easier to prove. Namely that if two equivalence classes are not disjoint, they must be equal. P: Two equivalence classes are not equal Q: Two equivalence classes are disjoint To prove: P --> Q P: Two equivalence classes are not equal Q: Two equivalence classes are disjoint To prove: P --> Q ~P: Two equivalence classes are equal ~Q: Two equivalence classes are not disjoint To prove: ~Q --> ~P
Discrete Math for CS Ex Ey = O U Proof (cont): • SupposeSo there is a z in both Exand Ey. This means xRz and yRz. However if yRz then zRy because R is symmetric. Finally, since xRz and zRy we can use transitivity to say xRy.From this we can conclude that Exand Eyare equal.Thus the equivalence classes of an equivalence relation satisfy both properties of being blocks of a partition and so form a partition. QED.
Discrete Math for CS Example: • Let R be a relation on R satisfying xRy iff x – y is an integer. Show R is an equivalence relation and find the equivalence classes – [0], [½] and [sqrt(2)]. Reflexive: xRx iff x-x is an integer. Since x-x = 0 and this is an integer, R is reflexive Symmetric: if xRy then x-y is an integer. Hence y-x is also an integer so yRx. Hence the relation is symmetric. Transitive: if xRy and yRz then x-y is an integer and y-z is an integer. Therefore (x-y)+(y-z) is also an integer. But this is x-z and so xRz. Hence the relation is transitive. [0] = { x ε R: x-0 is an integer} = Z. [½] = { ±0.5, ±1.5, ±2.5, ...} [sqrt(2)] = {sqrt(2), sqrt(2)±1, sqrt(2)±2, ...}
Discrete Math for CS U U Partial Orders: • A binary relation on a set A that is reflexive, anti-symmetric and transitive is called a partial order and the set is called a partially ordered set with respect to the relation or a poset for short. • Partial orders allow elements to “precede” one another but not necessarily. • Examples: • subsets of a set are ordered partially
Discrete Math for CS U Partial Orders: • Example: • subsets of a set are ordered partially {1,2,3} {1,2} {2,3} {1,3} Reflexive: Anti-symmetric: Transitive: v {3} {1} {2} { } Hasse Diagram
Discrete Math for CS Partial Orders: • Example: • is a divisor of in the set of natural numbers. Reflexive: Anti-symmetric: Transitive: n is a divisor of n? n is a divisor of m and m a divisor of n implies n == m? n is a divisor of m and m a divisor of p implies n is a divisor of p?
Discrete Math for CS Posets: • A set on which a partial order is defined is called a poset. • If R is a partial order on a set A and xRy we say that x is a predecessor of y and y is a successor of x. • An element of A can have many predecessors but if xRy and there is no z such that xRz and zRy we say x is an immediate predecessor of y (written x ≺ y). • We use a Hasse Diagram to represent immediate predecessors. • The vertices of a Hasse Diagram represent the elements of A and if they are directly connected then the lower vertex is the immediate predecessor of the upper vertex.
Discrete Math for CS Example: • Let A = {1,2,3,6,12,18}. Let R be the relation “is a divisor of”. • R is reflexive (a is a divisor of a), anti-symmetric (a is a divisor of b and b is a divisor of a implies a == b) and transitive (a is a divisor of b and b is a divisor of c implies a is a divisor of c). • R is a partial order. 12 18 aRb as long as there is a path up the diagram from a to b. 6 2 3 1
Discrete Math for CS Total Order: • A total order is a partial order in which every two elements of the set are related. Hence if a, b A, either aRb or bRa. Examples: - <= on the real numbers. - lexicographical ordering of a dictionary. - {1,2,6,12} is a totally ordered subset of A using “is a divisor of” relation. NOTE: In Computer Science we often need to sort elements. In order to do this the comparison operator needs to be a total order.