Download presentation
Presentation is loading. Please wait.
Published byBruce Potter Modified over 9 years ago
1
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 A B 8 6 4 2 1357
2
Discrete Math for CS Binary Relation Exercise: If R = { (a,b): a < b}. Show R on the diagram below. A B 8 6 4 2 1357
3
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.
4
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) }
5
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 3 5 7 2 4 6 8 We call this graph a directed graph.
6
Discrete Math for CS Example: A = {1, 2, 3, 4, 5, 6}. R is a relation on A defined by the following directed graph. Exercise: Give a rule-based definition of R R = {(a,b): a divides b} 1 6 2 3 45
7
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(a i,b j ) = 1 if (a i,b j ) belongs to R; 0 otherwise 1 3 5 7 A 2 4 6 8 B 0 1 1 1 0 0 1 1 0 0 0 1 0 0 Exercise: Give a rule-based definition of R R = {(a,b): a + 1 < b}
8
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.
9
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 all x, y, z ε A.
10
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
11
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 x y z
12
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 m ij == 1 the m ji != 1. The text says transitivity is not readily apparent. We'll see!
13
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.
14
Discrete Math for CS The Closure of a Relation: Suppose R is a relation on a set A. Then R A x A. If R does not possess a relation property P, say being reflexive, then there exists another relation R* on A with the three properties 1)R R* – R* possesses the desired property. – If any other relation, say R', satisfies 1) and 2) then R* R'. We call R* the closure of R with respect to the property P on the set A. UUU
15
Discrete Math for CS Example: A = {1, 2, 3} and R is the relation {(1,1),(1,2),(1,3),(3,1),(2,3)}. Find the closure of R with respect to the reflexive property. Find the closure of R with respect to the symmetric property. Find the closure of R with respect to the transitive property. R* = R U {(2,2), (3,3)} R* = R U {(2,1), (3,2)} R* = R U {(2,1),(3,2),(3,3),(2,2)}
16
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. Exercise: Show that x R y if xy > 0 for all x, y ε R. Exercise: Give a name to the relation R in the previous exercise.
17
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 A 1, A 2,... of a set A such that – A 1 U A 2 U... = A – A i A j = O for every pair i, j where i != j. We call each A i a block of the partition. U
18
Discrete Math for CS Example: A1A1 A5A5 A4A4 A3A3 A2A2 A
19
Discrete Math for CS Equivalence Class: If R is an equivalence relation on a set E, then is called the equivalence class of x. An easy way to represent an equivalence class of an element x is [x]. E x = { y ε E: y R x }
20
Discrete Math for CS Here it comes !
21
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 ε E x. Second, if xRy, then E x = E y. Suppose xRz, then z ε E x. However zRx since R is symmetric and so zRy by transitivity and so z ε E y. Hence E x E y. Similarly E y E x. Hence E x = E y. 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 E x A since the relation is defined over A. UUU U
22
Discrete Math for CS Proof (cont): So Since every x in A belongs to an E x (remember xRx) we can say Hence U E x A U x U x A U E x U x U x A = U E x x
23
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
24
Discrete Math for CS Proof (cont): Suppose So there is a z in both E x and E y. 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 E x and E y are equal. Thus the equivalence classes of an equivalence relation satisfy both properties of being blocks of a partition and so form a partition. QED. E x E y = O U
25
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,...}
26
Discrete Math for CS 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 “preceed” one another but not necessarily. Examples: subsets of a set are ordered partially UU
27
Discrete Math for CS Partial Orders: Example: subsets of a set are ordered partially U {1,2,3} { } {3} {2}{1} {1,3}{2,3} {1,2} v Reflexive: Anti-symmetric: Transitive: Hasse Diagram
28
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?
29
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 pedecessors 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.
30
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. 1 23 6 1812 aRb as long as there is a path up the diagram from a to b.
31
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.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.