Programming Language Semantics a Rewriting Approach
Total Page:16
File Type:pdf, Size:1020Kb
Programming Language Semantics A Rewriting Approach Grigore Ros, u University of Illinois at Urbana-Champaign Chapter 2 Background and Preliminaries 15 2.6 Complete Partial Orders and the Fixed-Point Theorem This section introduces a fixed-point theorem for complete partial orders. Our main use of this theorem is to give denotational semantics to iterative (in Section 3.4) and to recursive (in Section 4.8) language constructs. Complete partial orders with bottom elements are at the core of both domain theory and denotational semantics, often identified with the notion of “domain” itself. 2.6.1 Posets, Upper Bounds and Least Upper Bounds Here we recall basic notions of partial and total orders, such as upper bounds and least upper bounds, and discuss several examples and counter-examples. Definition 14. A partial order, or a poset (from partial order set) (D, ) consists of a set D and a binary v relation on D, written as an infix operation, which is v reflexive, that is, x x for any x D; • v ∈ transitive, that is, for any x, y, z D, x y and y z imply x z; and • ∈ v v v anti-symmetric, that is, if x y and y x for some x, y D then x = y. • v v ∈ A partial order (D, ) is called a total order when x y or y x for any x, y D. v v v ∈ Here are some examples of partial or total orders: ( (S ), ) is a partial order, where (S ) is the powerset of a set S , that is, the set of subsets of S . • P ⊆ P (Nat, ), the set of natural numbers ordered by “less than or equal to”, is a total order. • ≤ (Nat, ), the set of natural numbers ordered by “larger than or equal to”, is a total order. • ≥ (Nat , ), the naturals plus infinity, where infinity is larger than any number, is a total order. • ∪ {∞} ≤ (Int, ), the set of integer numbers, is a total order. • ≤ (Real, ), the set of real numbers, is a total order. • ≤ (S, =), a flat set S where the only partial ordering is the identity, is a partial order. • (S , S ), a set S extended with a bottom element with the property that for any a, b S , • ∪ {⊥} ≤ ⊥ ∈ ∪ {⊥} a S b if and⊥ only if a = b or a = , is a partial order. Such extensions of sets with bottom elements ≤ ⊥ are⊥ common in denotational semantics (Section 3.4), where the intuition for the is undefined. They ⊥ are commonly written more simply as S and are often called primitive or flat domains. ⊥ A partial order which is particularly important for denotational semantics (Section 3.4) is (A + B, ), • the set of partial functions from A to B partially ordered by the informativeness relation : given partial functions f, g : A + B, f is “less informative than or as informative as” g, written f g, iff for any a A, it is either the case that f (a) is not defined or both f (a) and g(a) are defined and f (a) = g(a). ∈ 85 If (S , ) and (S , ) are partial or total orders and S S = then (S S , ) is a partial • 1 ≤1 2 ≤2 1 ∩ 2 ∅ 1 ∪ 2 ≤1 ∪ ≤2 order, where a( )b if and only if there is some i 1, 2 such that a, b S and a b. This ≤1 ∪ ≤2 ∈ { } ∈ i ≤i union partial order is typically not a total order; it is a total order only when (S , ) is total and 1 ≤1 S 2 = , or the other way around. More generally, if (S i, i) i I is a family of partial orders such ∅ def{ ≤ } ∈ that S i S j = for any i , j I, then i I(S i, i) = ( i I S i, i I ) is a partial order, where ∩ ∅ ∈ ∈ ≤ ∈ ∈ ≤ a ( i I i) b if and only if there is some i I such that a, b S i and a i b. ∈ ≤ ∈S S∈ S ≤ S def If (S i, i) i I is a family of partial orders then i I(S i, i) = ( i I S i, i I i) is also a partial • { ≤ } ∈ ∈ ≤ ∈ ∈ ≤ order, where ai i I ( i I i) bi i I iff ai i bi for all i I (i.e., the product partial order is defined { } ∈ ∈ ≤ { } ∈ ≤ ∈ component-wise). Q Q Q Q Definition 15. Given partial order (D, ) and a set of elements X D, an element p D is called an upper v ⊆ ∈ bound of X iff x p for any x X. Furthermore, p D is called the least upper bound (LUB) of X, written v ∈ ∈ X, iff p is an upper bound and for any other upper bound q of X it is the case that p q. t v Upper bounds and least upper bounds may not always exist. For example, if D = X = x, y and is the { } v identity relation, then X has no upper bounds. Least upper bounds may not exist even though upper bounds exist. For example, if D = a, b, c, d, e and is defined by a c, a d, b c, b d, c e, d e, then any { } v v v v v v v subset of D admits upper bounds, but the set a, b does not have a LUB. Due to the anti-symmetry property, { } least upper bounds are unique when they exist, which justifies the notation X in Definition 15. t As an analogy with mathematical analysis, we can think of the LUB of a set of elements as their limit. For example, in (Real, ) the LUB of the set n/(n + 1) n Nat coincides with its limit in the mathematical ≤ { | ∈ } analysis sense, namely 1. Note that ([0, 1), ) does not admit LUBs for all its subsets, e.g., n/(n+1) n Nat ≤ { | ∈ } does not have a LUB. One might think that this happens because ([0, 1), ) does not even admit upper bounds ≤ for all its subsets. If we add the interval (4, 5] to the set above, for example, then the resulting (total) order admits upper bounds for any of its subsets (e.g., 5 is such an upper bound) but the set n/(n + 1) n Nat still { | ∈ } does not have a LUB. However, if we add the interval [4, 5] to the original interval [0, 1) then the resulting (total) order admits LUBs for all its subsets; for example, the LUB of n/(n + 1) n Nat is 4. { | ∈ } 2.6.2 Complete Partial Orders In the decimal representation of real numbers, completeness means that any infinite string of decimal digits is actually the decimal representation for some real number. In mathematical analysis in general, a set of real numbers is complete iff the limit of any converging sequence of real numbers is also in the set. For example, the interval [0, 1) open in 1 is not complete, because the sequence 1 1/n for n > 0 converges to 1 but 1 is − not in the set. On the other hand, the interval [0, 1] is complete. Many particular variants of completeness that appear in the literature are in fact instances a general notion or completeness for partial orders. Definition 16. Given a poset (D, ), a chain in D is an infinite sequence d d d d ... of v 0 v 1 v 2 v · · · v n v elements in D, also written using the set notation as d n Nat . Such a chain is called stationary when { n | ∈ } there is some n Nat such that d = d for all m n. ∈ m m+1 ≥ If D is finite then any chain is stationary. More generally, if for a given x D there are only finitely many ∈ elements y D such that x y, then any chain containing x is stationary. ∈ v Definition 17. A poset (D, ) is called a complete partial order (CPO) iff any of its chains has a LUB. (D, ) v v is said to have bottom iff it has a minimal element. Such an element is typically written , and the poset ⊥ 86 with bottom is written (D, , ). CPOs with bottom are also called bottomed complete partial orders. If ⊥ v ⊥ d n Nat is a chain in (D, ), then we also let d , or simply d , denote its LUB, d n Nat . { n | ∈ } v n t n t{ n | ∈ } n Nat G∈ Let us follow up on the examples underneath Definition 14 and discuss which of them are CPOs with botom and which are not: ( (S ), , ) is a bottomed CPO. • P ⊆ ∅ (Nat, ) has bottom 0 but is not complete: the chain 0 1 2 n has no upper bound. • ≤ ≤ ≤ ≤ · · · ≤ ≤ · · · (Nat, ) is a CPO but has no bottom. • ≥ (Nat , , 0) is a CPO with bottom 0: it is a CPO because any chain is either stationary, in which • ∪ {∞} ≤ case its LUB is obvious, or is unbounded by any natural number, in which case is its LUB. ∞ (Int, ) is not a CPO and has no bottom. • ≤ (S, =) is always a CPO, and it has bottom if and only if S has only one element. • (S , S , ) is a bottomed CPO. It is common to use the same notation S , used for the partial • ∪ {⊥} ≤ ⊥ ⊥ order (S ⊥ , S ), to also denote its corresponding bottomed CPO (S , S , ). It is interesting ∪ {⊥} ≤ ∪ {⊥} ≤ ⊥ and particularly important⊥ in denotational semantics to note that the primitive domain⊥ S is equivalent ⊥ to the set of partial functions + S , where is the singleton set. {∗} {∗} (A + B, , ), the set of partial functions A + B ordered by the informativeness relation , is a CPO • ⊥ with bottom : A + B, the partial function which is undefined in each element of A.