Download presentation
Presentation is loading. Please wait.
1
Programming Language Semantics Inductive Definitions Mooly SagivEran Yahav msagiv@postmsagiv@postyahave@post Schrirber 317Open space 03-640-760603-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 instances R 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 –({d 1, …, d n }/y) R y if ({x 1, …, x n }/y) R and d 1 R x 1 & … & d n R x n
4
Derivations Expressions R= {( / n) | n N, } {( / (X)) : X Loc, } {({ n 0, n 1 }/ m) | n 0, n 1, m N, m= n 0 +n 1, } {({ n 0, n 1 }/ m) | n 0, n 1, m N, m= n 0 -n 1, } {({ n 0, n 1 }/ m) | n 0, n 1, m N, m= n 0 n 1, } ( / 5) R 5 ( / <X, [ X 8, Y 7] 8) R X, [ X 8, Y 7] 8 ({ / 5), ( / <X, [ X 8, Y 7] 8)}) R (5+X), [ X 8, Y 7] 13 ({( / 5)}) R (5+5), [ X 8, Y 7] 10
5
Rule induction A special induction Define a set by rules I R ={x | R x} Examples – of Aexp N such that n – of Bexp T such that t – of Com such that ’ Show that the property is true for all elements by induction on the rule application
6
The general principle of rule induction Let I R ={x | R x} Let P be a property x I R P(X) for all the rule instances (X/y) in R for which X I R 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/y X Q y Q Proposition 4.1: –I R is closed and –If Q is an R-closed set then I R Q Application –Q = { x I R | P(x) } Examples –R = {( /0)} {{n}/{n+1) | n } –Referential transparency for expressions
8
Expressing Syntax using Rules a ::= … | a 0 + a 1 | … a 0 : Aexp a 1 : Aexp a 0 +a 1 : Aexp
9
Special Rule Induction Handles rules of different types BNF –c ::= … | X := a | …| if b then c 0 else c 1 | … Rules –X : Loc a : Exp X:=a: Com –b : Bexp c 0 : Com c 1 : Com if b then c 0 else c 1 : Com
10
The special principle of rule induction Let I R ={x | R x} A I R Let Q be a property a A. Q(a) for all the rule instances (X/y) in R for which X I R and y A x X A.Q(x) Q(y)
11
Proof rule for operational semantics Arithmetic Expressions P(a, , n) is true of all evaluations n if it is preserved by the expression rules
12
Proof rule for operational semantics Arithmetic Expressions P(a, , n) is true of all evaluations n if it is preserved by the expression rules
13
Rule Induction for Arithmetic Expressions a Aexp, , n N. n P(a, , n) iff n N, . P(n, , n) & X Loc, . P(X, , (X)) & a 0, a 1 Aexp, , n 0, n 1 N. n 0 & P(a0, , n0) & n 1 & P(a 1, , n 1 ) P(a0+a1, , n 0 +n 1 ) & …
14
Proof rule for operational semantics Boolean Expressions P(b, , t) is true of all evaluations 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. t P(b, , t) iff . P(false, , false) & . P(true, , true) & a 0, a 1 Aexp, , n 0, n 1 N. m& n & m=n P(a 0 =a 1, , true) & a 0, a 1 Aexp, , n 0, n 1 N. m& n & m n P(a 0 =a 1, ,false) … & b Bexp, , t T. t & P(b, , t) P( b, , t) &…
16
Proof rule for operational semantics Commands P(c, , ’) is true of all evaluations ’ 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, , ’ . ’ P(c, , ’) iff . P(skip, , ) & X Loc, a Bexp, . m P(X:=a, , [m/X]) & c 0, c 1 Com, , ’, ’’ . ’’& P(c 0, , ’) & ’ &P(c 1, ’’, ’) P(c 0 ;c 1, , ’) & …
18
Proposition 4.7 Define Loc L (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 Loc L (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 –A 0 = R 0 ( ) = –A 1 = R 1 ( ) =R( ) –A 2 = R 2 ( ) =R(R( )) –…–… –A n = R n ( ) Define A = n A n
20
Proposition 4.12 (i)A is R-closed (ii)R(A) = A (iii)A is the least R-closed set Let fix(R) denote the least fixed point of R fix(R)= n R n ( )
21
Summary Induction allows to prove properties of the programming language Example properties –Deterministic –Referential transparency –Equivalent of small step and natural semantics
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.