610 likes | 1.1k Vues
Partial Order Relations. Lecture 50 Section 10.5 Wed, Apr 20, 2005. Antisymmetry. A relation R on a set A is antisymmetric if for all a , b  A , ( a , b )  R and ( b , a )  R  a = b . This is equivalent to ( a , b )  R and a  b  ( b , a )  R .
                
                E N D
Partial Order Relations Lecture 50 Section 10.5 Wed, Apr 20, 2005
Antisymmetry • A relation R on a set A is antisymmetric if for all a, bA, (a, b) R and (b, a) Ra = b. • This is equivalent to (a, b) R and a b  (b, a)  R.
Examples: Antisymmetry • The following relations are antisymmetric. • a b, on Z+. • A  B, on (U). • x  y, on R. • A  B = A, on (U). • f(x)g(x) = f(x) on the set of all functions from R to R.
Partial Order Relations • A relation R on a set A is a partial order relation if • R is reflexive. • R is antisymmetric. • R is transitive. • We use  as the generic symbol for a partial order relation.
Examples: Partial Order Relations • The following relations are partial order relations. • a b, on Z+. • A  B, on (U). • x  y, on R. • Is the relation f(x)g(x) = f(x) on functions a partial order relation?
Lexicographic Order • Given a finite set of symbols, let them be listed in a specific order. • For example, a < b < c. • Let S be the set of all finite strings over the set of symbols. • Then we may define the lexicographic order relation  on S.
Lexicographic Order • Let s, tS and let s = a1a2…am and t = b1b2…bn. • Then st if • s = , or • |s|  |t| and ai = bi, for all 1  i  m, or • There exists k  1 with k  m and k  n and ai = bi for all 1  i < k, but ak < bk.
Lexicographic Order • The first condition says that   s for all strings s  S. • The second condition says that s is no longer than t and all of s matches the first part of t. • The third condition says that s and t differ at some common position.
Lexicographic Order • Theorem: The lexicographic order relation is a partial order. • Proof: • Reflexive: Obvious (?) • Antisymmetric: • Suppose s t and t  s for some s, t  S. • There are potentially 9 combinations of reasons for this.
Lexicographic Order • Maybe both are true because of the first condition. Then s =  and t = , so s = t. • Maybe both are true because of the second condition. Then |s|  |t| and |t|  |s|, implying that s and t have the same length. But also s matches “the first part” of t and t matches “the first part” of s. Therefore, s = t. • The second and third conditions are incompatible. • Etc.
Lexicographic Order • Transitivity: • Suppose that s t and t u, for some s, t, u  S. • There are potentially 27 combinations of reasons for this. (!!!) • Maybe s =  and t = . Then s  u. • Etc.
Hasse Diagrams • A Hasse diagram is a drawing that represents a partial order relation. • Draw a diagram in which • a b is represented by a  b. • a is drawn below b. • If there exists c such that a  c and c  b, then we represent only a  c and c  b; a  b is implied by transitivity.
Example: Hasse Diagram • Let the relation be  on ({a, b, c}). {a, b, c} {a, b} {a, c} {b, c} {a} {b} {c} {}
4 2 1 Example: Hasse Diagram • Let the relation be  on {1, 2, 3, 4, 6, 12} 12 6 3
Example: Partial Order Relation • Let F be the set of all functions f : R+ R+. • Let E be the set of equivalence classes [f] of F, under the equivalence relation f ~ g if f(x) is (g(x)). • Define  on E by [f]  [g] if f(x) is O(g(x)).
[f]  [g] is Well Defined • First, we must show that  is well defined on E. • Let f1, f2 [f] and g1, g2 [g]. • Then f1~ f2 and g1 ~ g2. • To show that  is well defined, we must show that if [f1]  [g1], then [f2]  [g2], meaning that it does not matter which function we select to represent the class.
[f]  [g] is Well Defined • So suppose that [f1]  [g1]. • Then • f2(x) is O(f1(x)), and • f1(x) is O(g1(x)) and • g1(x) is O(g2(x)). • So, f2(x) is O(g2(x)). • Therefore, [f2]  [g2].
Example: Partial Order Relation • Theorem:  is a partial order relation on E. • Proof: • Reflexivity • It is clear that [f]  [f] . (Use M = 1, x0 = 0.)
Example: Partial Order Relation • Antisymmetry • Suppose that [f]  [g] and [g]  [f] . • Then f(x) is O(g(x)) and g(x) is O(f(x)). • Then f(x) is (g(x)). • Therefore, f ~ g. • Therefore, [f] = [g].
Example: Partial Order Relation • Transitivity • Suppose that [f]  [g] and [g]  [h]. • Then f(x) is O(g(x)) and g(x) is O(h(x)). • We have already shown that this implies that f(x) is O(h(x)). • Therefore, [f]  [h]. • Thus,  is a partial order relation on E.
Comparable Elements and Total Orders • Given a partial order  on a set A, two elements a, b  A are comparable if a  b or b  a. • A partial order relation is a total order relation if any two elements are comparable under that relation.
Total Order Relations • Which of the following partial orders are total orders? • x y, on R. • A  B, on (U). • a  b, on Z+.
Total Order Relations • Define [f]  [g] to mean f(x) is O(g(x)). Is this a total order relation on the set of equivalence classes of functions? • Which are total orders on R  R. • (a, b)  (c, d) if a  c and b  d. • (a, b)  (c, d) if a  c or b  d. • (a, b)  (c, d) if a + b  c + d. • (a, b)  (c, d) if a < c or (a = c and b  d).
Example: Total Ordering and Sorting • In order to sort the list {(2, 3), (3, 3), (3, 2), (2, 2)}. it is necessary that  be a total ordering of the Point class. • If  is not a total order relation, then the results of any sorting algorithm are unpredictable. • Why?
Example: Total Ordering and Sorting • Define a Point object to consist of two doubles. class Point { double x; double y; };
Example: Total Ordering and Sorting • Define operator<() on the Point class as follows. • Then define operator<=() to mean that a < b or a == b. booloperator<(const Point& p, const Point& q) { if (p.x != q.x) return p.x < q.x; else return p.y < q.y; }
C Library Functions • There are two standard library functions, bsearch() and qsort(), that perform a binary search and a quicksort on an array, respectively. • For each function, one parameter is a function compare(a, b) that returns • < 0 if a < b • = 0 if a == b • > 0 if a > b
C Library Functions • Those three requirements are not sufficient to guarantee that operator<=() is a total order relation. • It is the programmer’s responsibility to be sure that it is. • Otherwise, neither bsearch() nor qsort() is guaranteed to work properly.
Chains of Elements • Let a partial order  be defined on a set A. • A subset B  A is called a chain if any two elements of B are comparable. That is,  is a total order on B (although not on A).
Chains of Elements • Find a chain of subsets in ({a, b, c}) under the subset relation. • What is the longest possible chain? • Find a chain of integers in Z+ under the divides relation. • What is the longest possible chain?
Maximal and Greatest Elements • Let A be a partially ordered set under . • An element a  A is a maximal element if, for all b  A, either b  a or a and b are not comparable. • An element a  A is a greatest element if, for all b  A, b  a.
Example • Let A = {1, 2, 3, …, 20} and let the relation be a b. • Are there any maximal elements? • If so, what are they? • Are there any greatest elements? • If so, what are they?
Example • Let B = {1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60} and let the relation be a b. • Are there any maximal elements? • If so, what are they? • Are there any greatest elements? • If so, what are they?
Maximal and Greatest Elements • Must maximal elements be exist? • Must greatest elements be exist? • If maximal elements exist, must they be unique? • If greatest elements exist, must they be unique?
Minimal and Least Elements • Minimal and least elements are similar to maximal and greatest elements, respectively. • An element a  A is a minimal element if, for all b  A, either a  b or a and b are not comparable. • An element a  A is a least element if, for all b  A, a  b.
Examples • What are the minimal and least elements (if any) of the sets A = {1, 2, 3, …, 20} and B = {1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60} under the relation a  b?
Compatible Order Relations • Let 1 and 2 be partial order relations defined on a set A. • We call 2compatible with 1 if, whenever a 1b, it is also the case that a 2b. • In other words, a, b  A, a 1b  a 2b.
Topological Sorting • Given a partial order relation 1defined on a set A, a topological sorting for 1is a total order relation 2that is compatible with 1. • For example, the ordinary “less than or equal to” relation  is a topological sorting for the “divides” relation because •  is a total order, and • If a b, then a  b.
Application: Computer Graphics • In the “old days,” a difficult problem in computer graphics was to draw the objects of a scene in such a way that when two objects were on the same line of sight, the closer object obscured the farther object. • One solution was the Painter’s Algorithm: sort the shapes from front to back, and then draw them from back to front.
Application: Computer Graphics • Define the relation a1b on the shapes to mean that shape a hides part of shape b. • Define the relation a2b on the shapes to mean that shape a is closer to the viewer than is shape b. • Clearly, 2is a topological sorting for 1.
Application: Computer Graphics • Therefore, the Painter’s Algorithm was to • Determine which shapes hide which shapes (relation 1). • Find a topological sorting for 1(relation 2). • Draw the shapes in reverse order according to the total ordering 2.
Example • Consider the following scene, with the viewpoint inside the house, looking out at the tree.
Example • The scene might be rendered like this:
Topological Sorting • Theorem: If A is a finite set with a partial order 1 defined on it, then there exists a topological sorting for 1. • The proof is the following algorithm. • A partially ordered finite set must have a minimal element. • Let x0 be a minimal element of A. • Let A1 = A – {x0}.
Topological Sorting • A1 is again a partially ordered finite set, so it must have a minimal element. • Let x1 be a minimal element of A1 and define A2 = A1 – {x1}. • Continue in this manner, defining x3, x4, x5, and so on, until no elements remain. • Then define 2 as follows: xi2xj if and only if ij.
Example • Let A = {1, 2, 3, …, 10} under the “divides” relation. 8 10 9 4 6 2 3 5 7 1
Example • Let x0 = 1 and remove 1 from the set. 8 10 9 4 6 2 3 5 7
Example • Let x1 = 7 and remove 7 from the set. 8 10 9 4 6 2 3 5
Example • Let x2 = 5 and remove 5 from the set. 8 10 9 4 6 2 3
Example • Let x3 = 3 and remove 3 from the set. 8 10 9 4 6 2