Download presentation
Presentation is loading. Please wait.
Published byGarry Gary Cross Modified over 8 years ago
1
1 Partial Orderings Epp, section 10.5
2
2 Introduction An equivalence relation is a relation that is reflexive, symmetric, and transitive A partial ordering (or partial order) is a relation that is reflexive, antisymmetric, and transitive –Recall that antisymmetric means that if (a,b) R, then (b,a) R unless b = a –Thus, (a,a) is allowed to be in R –But since it’s reflexive, all possible (a,a) must be in R A set S with a partial ordering R is called a partially ordered set, or poset –Denoted by (S,R)
3
3 Partial ordering examples Show that ≥ is a partial order on the set of integers –It is reflexive: a ≥ a for all a Z –It is antisymmetric: if a ≥ b then the only way that b ≥ a is when b = a –It is transitive: if a ≥ b and b ≥ c, then a ≥ c Note that ≥ is the partial ordering on the set of integers (Z, ≥) is the partially ordered set, or poset
4
4 Symbol usage The symbol is used to represent any relation when discussing partial orders –Not just the less than or equals to relation –Can represent ≤, ≥, , etc –Thus, a b denotes that (a,b) R –The poset is (S, ) The symbol is used to denote a b but a ≠ b –If represents ≥, then represents > Fonts for this lecture set (specifically for the and symbols) are available on the course website
5
5 Lexicographic ordering Consider two posets: (S, 1 ) and (T, 2 ) We can order Cartesian products of these two posets via lexicographic ordering –Let s 1 S and s 2 S –Let t 1 T and t 2 T –(s 1,t 1 ) (s 2,t 2 ) if either: s 1 1 s 2 s 1 = s 2 and t 1 2 t 2 Lexicographic ordering is used to order dictionaries
6
6 Lexicographic ordering Let S be the set of word strings (i.e. no spaces) Let T be the set of strings with spaces Both the relations are alphabetic sorting –We will formalize alphabetic sorting later Thus, our posets are: (S, ) and (T, ) Order (“run”, “noun: a…”) and (“set”, “verb: to…”) –As “run” “set”, the “run” Cartesian product comes before the “set” one Order (“run”, “noun: a…”) and (“run”, “verb: to…”) –Both the first part of the Cartesian products are equal –“noun” is first (alphabetically) than “verb”, so it is ordered first
7
7 Lexicographic ordering We can do this on more than 2-tuples (1,2,3,5) (1,2,4,3) –When is ≤
8
8 Lexicographic ordering Consider the two strings a 1 a 2 a 3 …a m, and b 1 b 2 b 3 …b n Here follows the formal definition for lexicographic ordering of strings If m = n (i.e. the strings are equal in length) –(a 1, a 2, a 3, …, a m ) (b 1, b 2, b 3, …, b n ) using the comparisons just discussed –Example: “run” “set” If m ≠ n, then let t be the minimum of m and n –Then a 1 a 2 a 3 …a m, is less than b 1 b 2 b 3 …b n if and only if either of the following are true: –(a 1, a 2, a 3, …, a t ) (b 1, b 2, b 3, …, b t ) Example: “run” “sets” (t = 3) –(a 1, a 2, a 3, …, a t ) = (b 1, b 2, b 3, …, b t ) and m < n Example: “run” “running”
9
9 Hasse Diagrams Consider the graph for a finite poset ({1,2,3,4},≤) When we KNOW it’s a poset, we can simplify the graph 43214321 43214321 43214321 43214321 Called the Hasse diagram
10
10 Hasse Diagram For the poset ({1,2,3,4,6,8,12}, |)
11
11 Comparability The elements a and b of a poset (S, ) are called comparable if either a b or b a. –Meaning if (a,b) R or (b,a) R –It can’t be both because is antisymmetric Unless a = b, of course –If neither a b nor b a, then a and b are incomparable Meaning they are not related to each other If all elements in S are comparable, the relation is a total ordering
12
12 Comparability examples Let be the “divides” operator | In the poset (Z +,|), are the integers 3 and 9 comparable? –Yes, as 3 | 9 Are 7 and 5 comparable? –No, as 7 | 5 and 5 | 7 Thus, as there are pairs of elements in Z + that are not comparable, the poset (Z +,|) is a partial order
13
13 Comparability examples Let be the less than or equals operator ≤ In the poset (Z +, ≤ ), are the integers 3 and 9 comparable? –Yes, as 3 ≤ 9 Are 7 and 5 comparable? –Yes, as 5 ≤ 7 As all pairs of elements in Z + are comparable, the poset (Z +, ≤ ) is a total order –a.k.a. totally ordered poset, linear order, chain, etc. –and can be drawn as a single vertical chain Hasse diagram
14
14 Maximal and Minimal For poset (S, ): –a S is a maximal element of S if and only if for all b S, either b a or b and a are not comparable –a S is a minimal element of S if and only if for all b S, either a b or b and a are not comparable –a S is the greatest element of S if and only if for all b S, either b a –a S is the least element of S if and only if for all b S, either a b
15
15 a e c d b a d b c c b d a
16
16 Well-ordered sets (S, ) is a well-ordered set if: –(S, ) is a totally ordered poset –Every non-empty subset of S has a least element Example: (Z,≤) –Is a total ordered poset (every element is comparable to every other element) –It has no least element –Thus, it is not a well-ordered set Example: (S,≤) where S = { 1, 2, 3, 4, 5 } –Is a total ordered poset (every element is comparable to every other element) –Has a least element (1) –Thus, it is a well-ordered set
17
17 Topological Sorting A partial order related set can be compatible with a total order set via a topological sorting –Given a partial order relation on a nonempty finite set A Select a minimal element x from A Remove x from A Pick another minimal element y from A Define x y Repeat until A is empty
18
18 Task Scheduling Consider a set of tasks T = {1,2,3,4,5}: 1.Remove lens cap 2.Focus lens 3.Turn off safety lock 4.Turn on flash 5.Push photo button Now define a poset (T, R) where: –i R j if i = j or task i must be done before task j –R = {(1,1),(2,2),(3,3),(4,4),(5,5),(1,2),(1,5),(2,5),(3,5),(4,5) –Possible solutions?
19
19 Critical Path Management –turn the Hasse diagram sideways, assign a duration for each task
20
20 P is the set of all people who have ever lived. R is a relation on P. r R s r is an ancestor of s or r = s –Is {P, R} is a poset? –Reflexive: by definition –Antisymmetric: if r is ancestor of s, then s cannot be a ancestor of r –Transitive: if r is ancestor of s, and s is ancestor of t, then r is ancestor of t Example problems
21
21 More examples For all x,y R, x R y x 2 y 2 Is (R, R) a poset? –Reflexive: yes –Antisymmetric: no. (-1, 1) and (1, -1)
22
22 Program Correctness How do we know if our algorithm is correct? –A correct program produces correct output for every possible input –Partial correctness: Prove that if a program terminates, it is correct –Given p as inputs, q as output, and S as a program segment: p{S}q indicates partial correctness of S
23
23 Composition rule Show partial correctness of consecutive segments
24
24 If … then … else … if condition then S 1 else S 2
25
25 Loops while condition S
26
26 procedure multiply(m,n: integers) if n < 0 then a := -n else a := n k := 0 x := 0 while k < a begin x := x + m k := k + 1 end if n < 0 then product := -x else product := x
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.