Docsity

Homework XI: Proving Partial Correctness of Wren Program Fragments, Assignments of Programming Languages

Toggle sidebar
bg1
22C:185 — Fall 2004
Homework XI
1. [15 points]
Prove the Hoare while normal form theorem (i.e., provide a construction to replace
if–then– with sequential execution and while–do–), and justify its correctness.
2 (repeated from Homework X). [25 points]
Provide an axiomatic proof of partial correctness for the Wren program fragment using
integer variables:
{true}
if A=B or A=-B
then if A>B then C:= A else C:= B-A+1 end if
else if A*B>0 then C:= A*B else C:= 1-A*B end if
end if
{C>0)
3. [25 points]
Provide an axiomatic proof of partial correctness for the Wren program fragment with
pre/post-conditions below (computing the “square root”), using integer variables:
{N≥1}
R:= 0;
while R*R < N do R:= R+1 end while
{(R-1)2 < N ≤ R2)
4. [25 points]
Provide an axiomatic proof of partial correctness for the Wren program fragment with
pre/post-conditions below (computing the “binary logarithm”), using integer variables:
{N>0}
P:= 0; M:= 1;
while M < N do P:= P+1; M:= 2*M end while
{2P-1< N Ÿ 2P≥N}

Partial preview of the text

Download Homework XI: Proving Partial Correctness of Wren Program Fragments and more Assignments Programming Languages in PDF only on Docsity!

22C:185 — Fall 2004 Homework XI

1. [15 points] Prove the Hoare while normal form theorem (i.e., provide a construction to replace if – then – with sequential execution and while – do –), and justify its correctness. 2 (repeated from Homework X). [25 points] Provide an axiomatic proof of partial correctness for the Wren program fragment using integer variables: {true} if A=B or A=-B then if A>B then C:= A else C:= B-A+1 end if else if AB>0 then C:= AB else C:= 1-AB end if end if {C>0) 3. [25 points] Provide an axiomatic proof of partial correctness for the Wren program fragment with pre/post-conditions below (computing the “square root”), using integer variables: {N≥1} R:= 0; while RR < N do R:= R+1 end while {(R-1)^2 < N ≤ R^2 ) 4. [25 points] Provide an axiomatic proof of partial correctness for the Wren program fragment with pre/post-conditions below (computing the “binary logarithm”), using integer variables: {N>0} P:= 0; M:= 1; while M < N do P:= P+1; M:= 2*M end while {2P-1< N Ÿ 2 P≥N}