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

The solutions to homework xi for a fall 2004 computer science course. Students are required to prove the hoare while normal form theorem, provide axiomatic proofs of partial correctness for three wren program fragments using integer variables, and compute the square root and binary logarithm. Essential for students studying formal verification and programming theory.

Typology: Assignments

Pre 2010

Uploaded on 03/10/2009

koofers-user-d41
koofers-user-d41 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
22C:185 — Fall 2004
Homework XI
1. [15 points]
Prove the Hoare while normal form theorem (i.e., provide a construction to replace
ifthen– with sequential execution and whiledo–), 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:
{N1}
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 Ÿ 2PN}

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 ifthen – with sequential execution and whiledo –), 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}