1 / 21

Programming Language Semantics Inductive Definitions

Programming Language Semantics Inductive Definitions. Mooly Sagiv Eran Yahav msagiv@post yahave@post Schrirber 317 Open space 03-640-7606 03-640-5358 html://www.cs.tau.ac.il/~msagiv/courses/sem03.html Textbook:Winskel The Formal Semantics of Programming Languages

cosmo
Télécharger la présentation

Programming Language Semantics Inductive Definitions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Language SemanticsInductive Definitions Mooly Sagiv Eran Yahav msagiv@post yahave@post Schrirber 317 Open space 03-640-7606 03-640-5358 html://www.cs.tau.ac.il/~msagiv/courses/sem03.html Textbook:Winskel The Formal Semantics of Programming Languages CS 0368-4348-01@listserv.tau.ac.il

  2. Outline • Rule induction • Special rule induction • Proof rules of the operational semantics • Least fixed points

  3. Derivations • A set of rule instancesR consists pairs X/y where X is a finite set and y is an element • X/y – rule instance • X – premises • y – conclusion • d R y – d is an R-derivation of y • (/y) R y if (/y)  R • ({d1, …, dn}/y) R y if ({x1, …, xn}/y) R andd1 R x1 & … & dn R xn

  4. Derivations Expressions R={(/ <n, >  n) | n  N,   } {(/ <X, > (X)) : X  Loc,   } {({<a0, > n0, <a1, > n1}/<a0+a1, > m) | n0, n1, m  N, m= n0+n1,   } {({<a0, > n0, <a1, > n1}/<a0-a1, > m) | n0, n1, m  N, m= n0-n1,   }{({<a0, > n0, <a1, > n1}/<a0a1, > m) | n0, n1, m  N, m= n0n1,   } (/ <5, [ X  8, Y  7] >  5) R<5, [ X  8, Y  7] >  5 (/ <X, [ X  8, Y  7]  8) RX, [ X  8, Y  7]  8 ({/ <5,[ X  8, Y  7] >  5) , (/ <X, [ X  8, Y  7]  8)}) R(5+X), [ X  8, Y  7]  13 ({(/ <5, [ X  8, Y  7] >  5)}) R (5+5), [ X  8, Y  7]  10

  5. Rule induction • A special induction • Define a set by rules • IR={x | Rx} • Examples • <a, , n> of Aexp    N such that <a, >  n • <b, , t> of Bexp    T such that <b, >  t • <c, , ’> of Com     such that <c, >  ’ • Show that the property is true for all elements by induction on the rule application

  6. The general principle of rule induction • LetIR={x | Rx} • Let P be a property • x  IR P(X)  for all the rule instances (X/y) in R for which X  IR z X. P(z)  P(y)

  7. Justifying the principle of induction • A set Q is closed under rule instances or simply R-closed if for all rule instances X/yX Q  y  Q • Proposition 4.1: • IR is closed and • If Q is an R-closed set then IR  Q • Application • Q = { x  IR | P(x) } • Examples • R = {(/0)} {{n}/{n+1) | n  } • Referential transparency for expressions

  8. Expressing Syntax using Rules • a ::= … | a0 + a1| … • a0: Aexp a1: Aexp a0+a1: Aexp

  9. Special Rule Induction • Handles rules of different types • BNF • c ::= … | X := a | …| if b then c0 else c1 | … • Rules • X : Loc a : Exp X:=a: Com • b : Bexp c0 : Com c1: Com if b then c0 else c1: Com

  10. The special principle of rule induction • LetIR={x | Rx} • A  IR • Let Q be a property • a  A. Q(a)  for all the rule instances (X/y) in R for which X  IR and yAx XA.Q(x)  Q(y)

  11. Proof rule for operational semanticsArithmetic Expressions • P(a, , n) is true of all evaluations <a, > n if it is preserved by the expression rules

  12. Proof rule for operational semanticsArithmetic Expressions • P(a, , n) is true of all evaluations <a, > n if it is preserved by the expression rules

  13. Rule Induction for Arithmetic Expressions aAexp, , n N. <a, > n P(a, , n) iff n N, . P(n, , n) & XLoc, . P(X, , (X)) & a0, a1 Aexp, , n0, n1 N.<a0, >  n0 & P(a0, , n0) &<a1, >  n1& P(a1, , n1) P(a0+a1, , n0+n1) & …

  14. Proof rule for operational semanticsBoolean Expressions • P(b, , t) is true of all evaluations <b, > t if it is preserved by the Boolean expression rules • Define a subset of • (AexpN) (BexpT) • Obtained from the special principle of induction for properties P(b, , t) on the subset BexpT

  15. Rule Induction for Booleans bBexp, , t T. <b, > t  P(b, , t) iff . P(false, , false) & . P(true, , true) & a0, a1 Aexp, , n0, n1 N.<a0, >  m& <a1, >  n & m=n P(a0=a1, , true) & a0, a1 Aexp, , n0, n1 N.<a0, >  m& <a1, >  n & mn P(a0=a1, ,false) … & b Bexp,  , t T. <b, > t & P(b, , t) P(b, ,  t) &…

  16. Proof rule for operational semanticsCommands • P(c,,’) is true of all evaluations <c, >’if it is preserved by the command rules • Define a subset of • (AexpN) (BexpT) (Com) • Obtained from the special principle of induction for properties P(c, , ’) on the subset Com

  17. Rule Induction for Commands cCom, , ’. <c, > ’  P(c, , ’) iff . P(skip, , ) & X Loc, a Bexp, . <a0, >  m P(X:=a, , [m/X]) & c0, c1 Com, , ’, ’’.<c0, >  ’’& P(c0, , ’) & <c1, ’’>  ’ &P(c1, ’’, ’) P(c0;c1, , ’) & …

  18. Proposition 4.7 Define LocL(c) to be the variables which appear on the left side of some assignment in c Let y  Loc For all commands c and states , ’ Y  LocL(c). <c, ,>  ’  (Y) = ’(Y)

  19. 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

  20. Proposition 4.12 • A is R-closed • R(A) = A • A is the least R-closed set Let fix(R) denote the least fixed point of R fix(R)= nRn()

  21. Summary • Induction allows to prove properties of the programming language • Example properties • Deterministic • Referential transparency • Equivalent of small step and natural semantics

More Related