Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Language Semantics Denotational Semantics Chapter 5.

Similar presentations


Presentation on theme: "Programming Language Semantics Denotational Semantics Chapter 5."— Presentation transcript:

1 Programming Language Semantics Denotational Semantics Chapter 5

2 Outline Least fixed points on relations Motivation Denotational Semantics –Least fixed points Equivalence of Semantics Complete partial orders and continuous functions

3 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 –A 0 = R 0 (  ) =  –A 1 = R 1 (  ) =R(  ) –A 2 = R 2 (  ) =R(R(  )) –…–… –A n = R n (  ) Define A =  n  A n

4 Proposition 4.12 (i)A is R-closed (ii)R(A) = A (iii)A is the least R-closed set Let fix(R) denotes the least fixed point of R Claim: fix(R)=  n  R n (  )=A 1.R(fix(R)) = fix(R) 2.  X. R(X) = X  fix(R)  X Alternative Formulation

5 Motivation for Denotational Semantics Equivalence of commands –c 1  c 2  ,  ’  :   ’    ’ The meaning of a command is a (partial) state transformer –C  c 1  = { ( ,  ’) |   ’ } –C  c 2  = { ( ,  ’) |   ’ } – c 1  c 2  C  c 1  = C  c 2  Denotational semantics –A  a  :  N –B  b  :  T –C  c  :   

6 Denotational semantics A: Aexp  (  N) B: Bexp  (  T) C: Com  (    ) Defined by structural induction

7 Denotational semantics of Aexp A: Aexp  (  N) A  n  = {( , n) |   } A  X  = {( ,  (X)) |   } A  a 0 +a 1  = {( , n 0 +n 1 ) | ( , n 0 )  A  a 0 , ( ,n 1 )  A  a 1  } A  a 0 -a 1  = {( , n 0 -n 1 ) | ( , n 0 )  A  a 0 , ( ,n 1 )  A  a 1  } A  a 0  a 1  = {( , n 0  n 1 ) | ( , n 0 )  A  a 0 , ( ,n 1 )  A  a 1  } Lemma: A  a  is a function

8 Denotational semantics of Aexp with A: Aexp  (  N) A  n  = .n A  X  = .  (X) A  a 0 +a 1  = .(  a 0   +A  a 1   ) A  a 0 -a 1  = .(  a 0   -A  a 1   ) A  a 0  a 1  = .(  a 0    A  a 1   )

9 Denotational semantics of Bexp B: Bexp  (  T) B  true  = {( , true) |   } B  false  = {( , false) |   } B  a 0 =a 1  = {( , true) |   & A  a 0   =A  a 1   }  {( , false) |   & A  a 0   A  a 1   } B  a 0  a 1  = {( , true) |   & A  a 0    A  a 1   }  {( , false) |   & A  a 0    A  a 1   } B  b  = {( ,  T t) |  , ( , t)  B  b  } B  b 0  b 1  = {( , t 0  T t 1 ) |  , ( , t 0 )  B  b 0 , ( , t 1 )  B  b 1  } B  b 0  b 1  = {( , t 0  T t 1 ) |  , ( , t 0 )  B  b 0 , ( , t 1 )  B  b 1  } Lemma: B  b  is a function

10 Denotational semantics of Com C: Com  (    ) C  skip  = {( ,  ) |   } C  X:=a  = {( ,  [n/X]) |   & n=A  a   } C  c 0 ;c 1  = C  c 1   C  c 0  C  if b then c 0 else c 1  = {( ,  ’) | B  b   =true & ( ,  ’)  C  c 0  }  {( ,  ’) | B  b   =false & ( ,  ’)  C  c 1  } C  while b do c  = ?

11 Denotational semantics of Com C: Com  (    ) C  if b then c 0 else c 1  = {( ,  ’) | B  b   =true & ( ,  ’)  C  c 0  }  {( ,  ’) | B  b   =false & ( ,  ’)  C  c 1  } w = while b do c w  if b then c;w else skip C  w  = {( ,  ’) | B  b   =true & ( ,  ’)  C  c;w  }  {( ,  ) | B  b   =false} = {( ,  ’) | B  b   =true & ( ,  ’)  C  w  C  c  }  {( ,  ) | B  b   =false}  = {( ,  ’) |  (  )=true & ( ,  ’)     }  {( ,  ) |  (  ) =false}

12 Denotational semantics of Com C: Com  (    )  = {( ,  ’) |  (  )=true & ( ,  ’)     }  {( ,  ) |  (  ) =false}  (  ) = {( ,  ’) |  (  )=true & ( ,  ’)     }  {( ,  ) |  (  ) =false}= {( ,  ’)|   ’’:  (  )=true & ( ,  ’’)  , (  ’’,  ’)   }  {( ,  ) |  (  ) =false}  (  ) = 

13 Denotational semantics of Com C: Com  (    )  (  ) = {( ,  ’) |  (  )=true & ( ,  ’)     }  {( ,  ) |  (  ) =false}= {( ,  ’)|   ’’:  (  )=true & ( ,  ’’)  , (  ’’,  ’)   }  {( ,  ) |  (  ) =false}  (  ) =   = R R={({ (  ’’,  ’)}/ ( ,  ’)) |  (  )=true & ( ,  ’’)   }  {(  / ( ,  )) |  (  ) =false}  = fix(R)

14 Denotational semantics of Com C  skip  ={( ,  )|  } C  X:=a  = {( ,  [n/X]) |   & n=A  a   } C  c 0 ;c 1  = C  c 1   C  c 0  C  if b then c 0 else c 1  = {( ,  ’) | B  b   =true & ( ,  ’)  C  c 0  }  {( ,  ’) | B  b   =false & ( ,  ’)  C  c 1  } C  while b do c  = fix(  ) where  (  ) = {( ,  ’) | B  b   =true & ( ,  ’)    C  c  }  {( ,  ) |  B  b   =false}

15 Proposition 5.1 w = while b do c C  w  = C  if b then c;w else skip 

16 Equivalence of Semantics Lemma 5.3: For all a  Aexp –A  a  ={( , n) |  n}

17 Equivalence of Semantics Lemma 5.4: For all b  Bexp –B  b  ={( , t) |  t}

18 Equivalence of Semantics Lemma 5.6: For all c  Com –   ’  ( ,  ’)  C  c  Theorem 5.7 For all c  Com –C  c  = {( ,  ’) |   ’ }

19 Partial 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  p=q 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 d 1  d 2  … d n =  {d 1, d 2, …, d n }

20 Complete Partial Orders Let (D,  ) be a partial order –An  -chain is an increasing chain d 0  d 1  …d n .. –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 

21 Monotonic 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 d 0  d 1  …d n  … in D:  n  f(d n ) = f(  n  d n )

22 Fixed 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  f n (  )

23 Missing Greatest lower bounds Knaster-Tarski Theorem Conclusion


Download ppt "Programming Language Semantics Denotational Semantics Chapter 5."

Similar presentations


Ads by Google