CS 641 Lecture -*- Outline -*- * Coercion Operators (9.3) The coercion operators map from predicates and functions to relations. Q: Does coercion from relations to predicates and functions work? not in general, because relations can be partial and nondeterministic Q: So which is the supertype of the other? relations are a supertype of functions in this sense ** definition Q: How could we regard a function of type S -> G as a relation in S <-> G? ------------------------------------------ COERCION OPERATORS (9.3) Mapping |.| : (S -> G) -> (S <-> G) ^ |f|.s.g = f.s == g Test |.| : (S -> Bool) -> (S <-> S) ^ |p|.s.g = s == g /\ p.s ------------------------------------------ Q: What do these mean? Q: For example, what is |(x := 1)|.s, where s maps x to 0? {s'}, where s' maps x to 1 and is otherwise like s Q: What is |x >= 3|.s.g ? s == g /\ (x >= 3).s which means ... Q: Is |x >= 3| like "assert x >= 3" or "assume x >= 3"? Think of s as pre-state, and g as post-state... Rather like both when p.s is true, since then |p|.s == {s}. Also like both when p.s is false, since then |p|.s == {}. The question is, how we interpret {} (total vs. partial correctness, us vs. them, see section 9.5) ** utility these are useful for expressing assertions at the relational level which is convenient because of the richness of relational algebra Q: What's |true|? |false|? Id (not True!) calculate |true|.s.g, and compare to True.s.g. |false|.s.g == { def } s == g /\ false.s == { def of false } s == g /\ F == { F /\ rule } F So |false| == False Q: How would you express conjunction of predicates using test? |p \intersect q| == |p|;|q| prove this Q: So can one express Q.s.g /\ p.s without using /\ ? ** properties Q: Is test, |.|: (S -> Bool) -> (S <-> S) monotonic? Yes, also a bottom, postive meet, and universal join homomorphism (prove one of these?, we did bottom above!) Q: Does test, |.|: (S -> Bool) -> (S <-> S) preserve top? why? see the previous calculations! Q: Does test, |.|: (S -> Bool) -> (S <-> S) preserve negation? why? |!p|.s.g == {definition} (s == g) /\ (!p).s == {pointwise extension} (s == g) /\ !(p.s) This isn't the same as !(|p|.s.g) == {definition} !((s == g) /\ p.s) == {de Morgan} (s != g) \/ p.s for example, take p.s == val.x.s > 3, s maps x to 4, and s == g ------------------------------------------ DOMAIN AND RANGE dom.R.s = (\exists g :: R.s.g) ran.R.g = (\exists s :: R.s.g) What are the types of these? ------------------------------------------ ** partial functions ------------------------------------------ PARTIAL FUNCTIONS Modeled as deterministic relations. Def: R: S <-> G is deterministic iff (\forall s g g' : R.s.g /\ R.s.g' : g' == g) ------------------------------------------ Q: Is False deterministic? Is True deterministic? Are these partial? Q: When is |p| partial?