102 Views

Download Presentation
## Programming Language Semantics Denotational Semantics

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Programming Language SemanticsDenotational Semantics**Chapter 5**Operators and their least fixed points**• For a set of rule instances R • R(B)={y | X B, X/y R} • Proposition 4.11 A set B is closed under R if R(B) B • R is monotonic • A B R(A) R(B) • Define the sequence of sets • A0 = R0() = • A1 = R1() =R() • A2 = R2() =R(R()) • … • An = Rn() • Define A = n An**Proposition 4.12**• A is R-closed • R(A) = A • A is the least R-closed set Alternative Formulation Let fix(R) denotes the least fixed point of R • R(fix(R)) = fix(R) • X. R(X) = X fix(R) X Claim: fix(R)= nRn()=A**Motivation for Denotational Semantics**• Equivalence of commands • c1 c2 ,’: <c1, > ’ <c2, > ’ • The meaning of a command is a (partial) state transformer • C c1 = { (,’) | <c1, > ’ } • C c2 = { (,’) | <c2, > ’ } • c1 c2 C c1 = C c2 • Denotational semantics • Aa : N • Bb : T • Cc : **Denotational semantics**• A: Aexp (N) • B: Bexp (T) • C: Com() • Defined by structural induction**Denotational semantics of Aexp**• A: Aexp (N) • An = {(, n) | } • AX = {(, (X)) | } • Aa0+a1 = {(, n0+n1) | (, n0)Aa0, (,n1)Aa1} • Aa0-a1 = {(, n0-n1) | (, n0)Aa0, (,n1)Aa1} • Aa0a1 = {(, n0 n1) | (, n0)Aa0, (,n1)Aa1} Lemma: A a is a function**Denotational semantics of Aexp with **• A: Aexp (N) • An = .n • AX = .(X) • Aa0+a1 = .(a0+Aa1) • Aa0-a1 = .(a0-Aa1) • Aa0a1 = .(a0 Aa1)**Denotational semantics of Bexp**• B: Bexp (T) • Btrue = {(, true) | } • Bfalse = {(, false) | } • Ba0=a1 = {(, true) | & Aa0=Aa1 }{(, false) | & Aa0Aa1 } • Ba0a1 = {(, true) | & Aa0 Aa1 }{(, false) | & Aa0Aa1 } • Bb = {(, T t) | , (, t) Bb} • Bb0b1 = {(, t0 Tt1) | , (, t0) Bb0, (, t1) Bb1 } • Bb0b1 = {(, t0 Tt1) | , (, t0) Bb0, (, t1) Bb1 } Lemma: Bb is a function**Denotational semantics of Com**• C: Com () • Cskip = {(, ) | } • CX:=a = {(, [n/X]) | & n=Aa} • Cc0;c1 = Cc1 Cc0 • Cif b then c0 else c1 = {(, ’) | Bb=true & (, ’) Cc0}{(, ’) | Bb=false & (, ’) Cc1} • Cwhile b do c = ?**Denotational semantics of Com**• C: Com () • Cif b then c0 else c1 = {(, ’) | Bb=true & (, ’) Cc0}{(, ’) | Bb=false & (, ’) Cc1} • w = while b do c • w if b then c;w else skip • Cw ={(, ’) | Bb=true & (, ’) Cc;w}{(, ) | Bb=false} ={(, ’) | Bb=true & (, ’) CwCc} {(, ) | Bb=false} • = {(, ’) | ()=true & (, ’) } {(, ) | () =false}**Denotational semantics of Com**• C: Com () • = {(, ’) | ()=true & (, ’) } {(, ) | () =false} • () = {(, ’) | ()=true & (, ’) } {(, ) | () =false}={(, ’)| ’’: ()=true & (, ’’) , (’’, ’) } {(, ) | () =false} • () = **Denotational semantics of Com**• C: Com () • () = {(, ’) | ()=true & (, ’) } {(, ) | () =false}={(, ’)| ’’: ()=true & (, ’’) , (’’, ’) } {(, ) | () =false} • () = • = R • R={({(’’, ’)}/ (, ’)) | ()=true & (, ’’) } {(/ (, )) |() =false} • = fix(R)**Denotational semantics of Com**• Cskip={(, )| } • CX:=a = {(, [n/X]) | & n=Aa} • Cc0;c1 = Cc1 Cc0 • Cif b then c0 else c1 = {(, ’) | Bb=true & (, ’) Cc0}{(, ’) | Bb=false & (, ’) Cc1} • Cwhile b do c = fix() where() = {(, ’) | Bb=true & (, ’) Cc} {(, ) | Bb=false}**Proposition 5.1**w = while b do c Cw = Cif b then c;w else skip**Equivalence of Semantics**• Lemma 5.3: For all a Aexp • Aa={(, n) | < , a> n}**Equivalence of Semantics**• Lemma 5.4: For all b Bexp • Bb={(, t) | < , b> t}**Equivalence of Semantics**• Lemma 5.6: For all c Com • <, c> ’ ( , ’) Cc • Theorem 5.7 For all c Com • Cc = {( , ’) | <, c> ’ }**Partial Orders**• A partial order (p.o.) is a set P with a binary relation • reflexive p: p P. pp • transitive: p, q, r P. p q & q r p r • antisymmetric: p, q P. p q & q p p=q • For a partial order (P, ) and a subset XP • p is an upper bound of X • q X. q p • p is a least upper bound of X (denoted by X) if • p is an upper bound of X • For all upper bounds q of X: p q d1 d2 … dn = {d1, d2, …, dn}**Complete Partial Orders**• Let (D, ) be a partial order • An -chain is an increasing chain • d0d1 …dn .. • D is a complete partial order (c.p.o) if every -chain has a least upper bound • D is a complete partial order with if is a c.p.o. with a minimum element **Monotonic and Continus Functions**• A function f: DE between cpos D and E is monotonic if • d,d’ D.d d’ f(d) f(d’) • Such a function is continuous if for all chainsd0d1 …dn … in D: n f(dn) = f( n dn)**Fixed Points**• Let f: D D be a continuous function on a cpo with D • A fixed point of fis an element d Dsuch that f(d) =d • A pre fixed point of fis an element d Dsuch that f(d) d • Thm: fix(f) = n fn()**Missing**• Greatest lower bounds • Knaster-Tarski Theorem • Conclusion