Title: Programming Language Semantics Denotational Semantics
1Programming Language SemanticsDenotational
Semantics
2Outline
- Least fixed points on relations
- Motivation
- Denotational Semantics
- Least fixed points
- Equivalence of Semantics
- Complete partial orders and continuous functions
3Operators 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
4Proposition 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) ?n?? Rn(?)A
5Motivation for Denotational Semantics
- Equivalence of commands
- c1 ? c2 ? ??,??? ltc1, ?gt ? ? ? ltc2, ?gt ? ?
- The meaning of a command is a (partial) state
transformer - C? c1 ? (?,?) ltc1, ?gt ? ?
- C? c2 ? (?,?) ltc2, ?gt ? ?
- c1 ? c2 ? C? c1 ? C? c2 ?
- Denotational semantics
- A?a ? ??N
- B?b ? ??T
- C?c ? ???
6Denotational semantics
- A Aexp ? (??N)
- B Bexp ?(??T)
- C Com ?(???)
- Defined by structural induction
7Denotational semantics of Aexp
- A Aexp ? (??N)
- A ?n? (?, n) ? ??
- A ?X? (?, ?(X)) ? ??
- A ?a0a1? (?, n0n1) (?, n0)?A?a0?,
(?,n1)?A?a1? - A ?a0-a1? (?, n0-n1) (?, n0)?A?a0?,
(?,n1)?A?a1? - A ?a0?a1? (?, n0 ? n1) (?, n0)?A?a0?,
(?,n1)?A?a1?
Lemma A ?a ? is a function
8Denotational semantics of Aexp with ?
- A Aexp ? (??N)
- A ?n? ????.n
- A ?X? ????.?(X)
- A ?a0a1? ????.(?a0??A?a1??)
- A ?a0-a1? ????.(?a0??-A?a1??)
- A ?a0?a1? ????.(?a0?? ? A?a1??)
9Denotational semantics of Bexp
- B Bexp ? (??T)
- B ?true? (?, true) ? ??
- B ?false? (?, false) ? ??
- B ?a0a1? (?, true) ? ?? A?a0??A?a1? ??
(?, false) ? ??
A?a0???A?a1? ? - B ?a0?a1? (?, true) ? ?? A?a0?? ? A?a1?
?? (?, false) ? ??
A?a0???A?a1? ? - B ??b? (?, ?T t) ? ??, (?, t) ?B?b?
- B ?b0?b1? (?, t0 ?Tt1) ? ??, (?, t0) ?B?b0?,
(?, t1) ?B?b1? - B ?b0?b1? (?, t0 ?Tt1) ? ??, (?, t0) ?B?b0?,
(?, t1) ?B?b1?
Lemma B?b? is a function
10Denotational semantics of Com
- C Com ? (???)
- C ?skip? (?, ?) ? ??
- C ?Xa? (?, ?n/X) ? ?? nA?a??
- C ?c0c1? C ?c1? ? C ?c0?
- C ?if b then c0 else c1? (?, ?) B?b??true
(?, ?)? C?c0??(?, ?) B?b??false (?,
?)? C?c1? - C ?while b do c? ?
11Denotational semantics of Com
- C Com ? (???)
- C ?if b then c0 else c1? (?, ?) B?b??true
(?, ?)? C?c0??(?, ?) B?b??false (?,
?)? C?c1? - w while b do c
- w ? if b then cw else skip
- C ?w? (?, ?) B?b??true (?, ?)?
C?cw??(?, ?) B?b??false (?, ?)
B?b??true (?, ?)? C?w??C?c? ?(?, ?)
B?b??false - ? (?, ?) ??(?)true (?, ?)? ? ? ?
?(?, ?) ??(?) false
12Denotational semantics of Com
- C Com ? (???)
- ? (?, ?) ??(?)true (?, ?)? ? ? ?
?(?, ?) ??(?) false - ? (?) (?, ?) ??(?)true (?, ?)? ? ? ?
?(?, ?) ??(?) false(?, ?) ?? ?
?(?)true (?, ?)? ?, (?, ?)? ? ?(?, ?)
??(?) false - ? (?) ?
13Denotational semantics of Com
- C Com ? (???)
- ? (?) (?, ?) ??(?)true (?, ?)? ? ? ?
?(?, ?) ??(?) false(?, ?) ?? ?
?(?)true (?, ?)? ?, (?, ?)? ? ?(?, ?)
??(?) false - ? (?) ?
- ? R
- R((?, ?)/ (?, ?)) ?(?)true (?, ?)?
? ? (?/ (?, ?)) ??(?) false - ? fix(R)
14Denotational semantics of Com
- C?skip?(?, ?) ???
- C ?Xa? (?, ?n/X) ? ?? nA?a??
- C ?c0c1? C ?c1? ? C ?c0?
- C ?if b then c0 else c1? (?, ?) B?b??true
(?, ?)? C?c0??(?, ?) B?b??false (?,
?)? C?c1? - C ?while b do c? fix(?) where?(?) (?, ?)
B?b??true (?, ?)? ? ?C?c? ?(?, ?) ?
B?b??false
15Proposition 5.1
w while b do c C ?w? C ?if b then cw else
skip?
16Equivalence of Semantics
- Lemma 5.3 For all a ? Aexp
- A?a?(?, n) lt ?, agt? n
17Equivalence of Semantics
- Lemma 5.4 For all b ? Bexp
- B?b?(?, t) lt ?, bgt? t
18Equivalence of Semantics
- Lemma 5.6 For all c ? Com
- lt?, cgt? ? ? ( ?, ?) ? C?c?
- Theorem 5.7 For all c ? Com
- C?c? ( ?, ?) lt?, cgt? ?
19Partial Orders
- A partial order (p.o.) is a set P with a binary
relation ? - reflexive ?p p ?P. p?p
- transitive ?p, q, r ?P. p ?q q ?r ?p ?r
- antisymmetric ?p, q ?P. p ?q q ?p ?pq
- For a partial order (P, ?) and a subset X?P
- 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
20Complete Partial Orders
- Let (D, ?) be a partial order
- An ?-chain is an increasing chain
- d0 ?d1 ?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 ?
21Monotonic and Continus Functions
- A function f D?E 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 chains
d0 ?d1 ?dn ? in D ?n?? f(dn) f(? n?? dn)
22Fixed Points
- Let f D ?D be a continuous function on a cpo
with ? D - A fixed point of f is an element d ?D such that
f(d) d - A pre fixed point of f is an element d ?D such
that f(d) ?d - Thm fix(f) ?n?? fn(?)
23Missing
- Greatest lower bounds
- Knaster-Tarski Theorem
- Conclusion