CS 4110 – Programming Languages and Logics Lecture #8: Denotational Semantics Examples

CS 4110 – Programming Languages and Logics Lecture #8: Denotational Semantics Examples

CS 4110 – Programming Languages and Logics Lecture #8: Denotational Semantics Examples Last time we defined the denotational semantics of IMP: A[[n]] = f(σ; n)g A[[x]] = f(σ; σ(x))g A[[a1 + a2]] = f(σ; n) j (σ; n1) 2 A[[a1]] ^ (σ; n2) 2 A[[a2]] ^ n = n1 + n2g B[[true]] = f(σ; true)g B[[false]] = f(σ; false)g B[[a1 < a2]] = f(σ; true) j (σ; n1) 2 A[[a1]] ^ (σ; n2) 2 A[[a2]] ^ n1 < n2g [ f(σ; false) j (σ; n1) 2 A[[a1]] ^ (σ; n2) 2 A[[a2]] ^ n1 ≥ n2g C[[skip]] = f(σ; σ)g C[[x := a]] = f(σ; σ[x 7! n]) j (σ; n) 2 A[[a]]g 0 00 00 00 0 C[[c1; c2]] = f(σ; σ ) j 9σ : ((σ; σ ) 2 C[[c1]] ^ (σ ; σ ) 2 C[[c2]])g 0 0 C[[if b then c1 else c2]] = f(σ; σ ) j (σ; true) 2 B[[b]] ^ (σ; σ ) 2 C[[c1]]g [ 0 0 f(σ; σ ) j (σ; false) 2 B[[b]] ^ (σ; σ ) 2 C[[c2]]g C[[while b do c]] = fix(F ) where F (f) = f(σ; σ) j (σ; false) 2 B[[b]]g [ f(σ; σ0) j (σ; true) 2 B[[b]] ^ 9σ0; σ00: (σ; σ0) 2 C[[c]] ^ (σ0; σ00) 2 fg In this lecture we’ll prove Kleene’s fixpoint theorem, which shows that the fixed point used to define the semantics of while commands exists, and work through examples of reasoning using the denotational semantics. 1 Kleene’s Fixpoint Theorem Definition (Scott Continuity). AS function SF from U to U is said to be Scott-continuous if for every ⊆ ⊆ chain X1 X2 ::: we have F ( i Xi) = i F (Xi). It is not hard to show that if F is Scott continuous, then it is also monotonic—that is, X ⊆ Y implies F (X) ⊆ F (Y ). The proof of this fact is left as an exercise. S i ; Theorem (Kleene Fixpoint). Let F be a Scott-continuous function. The least fixed point of F is i F ( ). S i ; Proof. Let X = i F ( ). 1 First, we will prove that X is a fixed point of F —that is, F (X) = X. We calculate as follows: S i ; F (X) = SF ( i F ( )) By definition of X i ; = Si F (F ( )) By Scott continuity i+1 ; = i FS ( ) ;[ i+1 ; = i FS ( ) 0 ; [ i+1 ; = SF ( ) i F ( ) i ; = i F ( ) = X Second, we will show that X is the least fixed point of F . Suppose that Y is some other arbitrary fixed point of F . By induction, we can easily show that F i(;) ⊆ Y for all i. For the base case, i is 0 and we trivially have F 0(;) = ; ⊆ Y . For the inductive case, we assume that F i(;) ⊆ Y and prove that F i+1(;) ⊆ Y . By our inductive hypothesis and the fact that F is monotone, we have that F (F i+1(;)) ⊆ F (Y ). As Y is a fixed point we also have F (Y ) = Y and so F i+1(;) ⊆ Y . Then, since every element of the chain F 0; ⊆ F 1; ⊆ ::: S i ; ⊆ is a subset of Y immediately we have that their union, X = i F ( ) Y . Hence, X is the least (with respect to ⊆) fixed point of F . 2 Reasoning One of the key advantages of using denotational semantics compared to operational semantics is that proofs of equivalence can be carried out directly by simply calculating the denotations of programs and then arguing that they are identical. This is in contrast to operational techniques, where one must reason explicitly about low-level transitions and derivations involving ad hoc abstract machines. As an example, to show that skip; c and c; skip are equivalent, we can calcuate as follows, C[[skip; c]] = f(σ; σ00) j 9σ0:(σ; σ0) 2 C[[skip]] ^ (σ0; σ00) 2 C[[c]]g = f(σ; σ00) j (σ; σ00) 2 C[[c]]g = f(σ; σ00) j 9σ0:(σ; σ0) 2 C[[c]] ^ (σ0; σ00) 2 C[[skip]]g = C[[c; skip]] using standard facts about partial functions, relations, and sets as convenient in the proof itself. Next, consider the command C[[while false do c]]. By the definition of the denotational seman- tics, this is equal to fix(F ) where F (f) = f(σ; σ) j (σ; false) 2 B[[b]]g [ = f(σ; σ00) j (σ; true) 2 B[[b]] ^ (σ; σ0) 2 C[[c]] ^ (σ0; σ00) 2 fg S i ; By the Kleene fixpoint theorem we have that fixF = i F ( ). It is straightforward to show by induction that since the guard is false, for all i we have F i(;) = f(σ; σ)g. It follows that fixF = f(σ; σ)g, which is just C[[skip]]. As an exercise, calcuate C[[while true do skip]] using the same technique. 2.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us