CS 641 Lecture -*- Outline -*- * Relations (Chapter 9) ** motivation relations allow better modeling of programs than just functional assignment, because they allow for: - nondeterminism, a relation may "return" several values/states - partiality, a relation may "return" the empty set ** relation spaces (9.1) ------------------------------------------ RELATION SPACES (9.1) Def: the *relation space from S to G* is ^ S <-> G = S -> P(G) i.e., S <-> G = S -> (G -> Bool) Predicate/Set isomorphism for Relations: Relation r \subseteq S x G determines P_r where P_r.a.b == (a,b) \in r Predicate P: S -> P(G) determines r_P where (a,b) \in r_P == P.a.b i.e., r_P = {(a,b) | P.a.b} r_P can be thought of a as a: - set of pairs - set-valued function - a predicate-valued function - curried, Boolean-valued function ------------------------------------------ *** lattice of relations ------------------------------------------ ORDERING PROPERTIES OF RELATIONS Def: if P, Q \in S <-> G, then ^ P \subseteq Q = (\forall s \in S :: P.s \subseteq Q.s) ------------------------------------------ Q: how would you express the ordering using implications? Q: is the relation space ordered by this ordering a lattice? Q: is it complete? Boolean? bounded? yes, all by the pointwise extension theorem Q: What's the top element of this lattice? The bottom element? True == (\ s . true) False == (\ s . false) Q: What are these in terms of the sets? Q: Why does this make sense by the pointwise extension theorem? Q: What are the meet can join in this lattice? Pointwise extended meet and join from predicates, written, using the predicate notation, as intersection and union. Q: What is the complement in this lattice? (!P).s.g == !(P.s.g). Is that the complement for the sets? Q: What are the indexed meet and joins in this lattice? Pointwise extended from predicates, written, using the predicate notation, as intersection and union. Q: Why can't we use universal and existential quantifier notation? that seems to stretch the analogy past one's intuition *** other operations on relations ------------------------------------------ OTHER OPERATIONS ON RELATIONS Def: The identity relation, Id, is ^ Id.s.g = s == g Def: Composition of relations, P and Q is ^ (P@Q).s.d = (\exists g :: P.s.g /\ Q.g.d) Def: Inverse of relation, R^{-1} is ^ R^{-1}.s.g = R.g.s ------------------------------------------ The inverse of of a relation is sometimes called its *converse*. Q: Suppose P,Q : S <-> S. Does P;Q == Q;P ? ** State relation category (9.2) ------------------------------------------ STATE RELATION CATEGORY (9.2) Def: A *state relation category*, Rel, has - state spaces as objects, - relations as morphisms. ^ 1 = Id ^ P;Q = P@Q ------------------------------------------ Rel_X has as objects the types in X. Q: Can you prove that composition is associative? Has Id as its unit? Q: is composition monotoic in the relation ordering? yes Summary is theorem 9.2 and table 9.1. Q: Can you prove that ; distributes over \union and vice versa? Q: Why doesn't composition distributed over meets? Q: We have P ; False == False False ; P == False does anything similar hold for the composition over relation and True? (exercise 9.6)