{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Act04_Semantics_of_pgms_and_triples

# Act04_Semantics_of_pgms_and_triples - Illinois Institute of...

This preview shows pages 1–2. Sign up to view the full content.

CS 536 Activities: Program Semantics; Correctness Triples Activity 4.1: Program Semantics A. Why? The meaning of a program is that it transforms states. B. Outcomes At the end of this activity you should: Be able to calculate the meaning of a program in a state. C. Questions 1. Let S ! be x:=x+1; y:=x*y and S # be y:=x*y; x:=x+1 . Let ! be a state with ! ( x ) = c and ! ( y ) = d . What are M ( S ! , ! ) and M ( S # , ! )? M ( S ! , ! ) " x=c+1 # y= ( c+1 ) d M ( S # , ! ) " x=c+1 # y=c d 2. Let \$ \$ " x=0 # y=1 , let S be the statement x:=x+1; y:=y+y , and de ne \$ ! = M ( S , \$ \$ ), \$ # = M ( S , \$ ! ), \$ % = M ( S , \$ # ), and so on. Calculate the states \$ ! , \$ # , and \$ % . \$ ! " x=1 # y=2 \$ # " x=2 # y=4 \$ % " x=3 # y=8 3. For the states of the previous problem, in general, if \$ k ( x ) = c ! and \$ k ( y ) = c # , what does \$ k +1 look like? M ( S , \$ k ) = M ( x:=x+1; y:=y+y , \$ k ) = M ( y:=y+y, M ( x:=x+1 , \$ k )) = M ( y:=y+y , { \$ k [ x ! d ! ]}) where d ! is the value of c ! +1 = { \$ k [ x ! d ! ][ y ! d # ]} where d # is the value of 2 × c # . For Questions 4 – 6, use the \$ \$ of Question 2: \$ \$ " x=0 # y=1 . 4. Let W ! be while x ! 3 do S od . What is M ( W ! , \$ \$ )? De ne \$ & = M ( S , \$ % ) " x=4 # y= 16. Then M ( W ! , \$ \$ ) = { \$ & }. 5. Let W # be while x<0 do S od . What is M ( W # , \$ \$ )? The loop halts immediately, so M ( W # , \$ \$ ) = { \$ \$ }. 6. Let W % be n:=3 ; while x ! n do S od . What is M ( W % , \$ \$ )?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

Act04_Semantics_of_pgms_and_triples - Illinois Institute of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online