Docsity

Problem Set 3 for Programming Languages | ECS 240, Assignments of Programming Languages

Toggle sidebar
bg1
ECS 240: Homework Assignment 3
(Due: Thursday, May 21, 2009)
May 7, 2009
(Exercise 1) Two Hoare rule-based proofs
1. Prove using Hoare rules the following property:
{xis even}while bdo x:= x+ 2 {xis even}for any boolean command b
2. Prove using Hoare rules the correctness of Euclid’s GCD algorithm:
{a > 0∧b > 0}
x:= a;y:= b
while x6=ydo
if x > y then
x:= x−y
else
y:= y−x
end if
end while
{gcd(a, b) = x}
(Exercise 2) Alternative rules for while
1. Consider the following alternative Hoare rule for while:
` {A}c{b⇒A∧ ¬b⇒B}
` {b⇒A∧ ¬b⇒B}while bdo c{B}
Show that the system of axioms remains complete if we replace the old rule for while with this one. You
must show that any derivation that uses the old rule for while can be written with this rule instead.
2. Consider the following alternative Hoare rule for while
` {A∧b}c{A}
` {A}while bdo c{A}
This rule is not complete. Give a counterexample and a short justification.
3. Consider now another Hoare rule for while:
` {A}c{A}
` {A}while bdo c{A∧ ¬b}
This rule is also incomplete. Give a counterexample and a short justification.
(Exercise 3) In the abstract interpretation example with the factorial, you can see that the analysis was
rather imprecise. How can you improve the result of this analysis by:
1. Changing the factorial program but not changing the analysis, and
2. Changing the abstract interpretation setup but without changing the factorial program.
Give separate solutions for each of the above ways to address the problem.
1

Partial preview of the text

Download Problem Set 3 for Programming Languages | ECS 240 and more Assignments Programming Languages in PDF only on Docsity!

ECS 240: Homework Assignment 3

(Due: Thursday, May 21, 2009)

May 7, 2009

(Exercise 1) Two Hoare rule-based proofs

  1. Prove using Hoare rules the following property: {x is even} while b do x := x + 2 {x is even} for any boolean command b
  2. Prove using Hoare rules the correctness of Euclid’s GCD algorithm: {a > 0 ∧ b > 0 } x := a; y := b while x 6 = y do if x > y then x := x − y else y := y − x end if end while {gcd(a, b) = x}

(Exercise 2) Alternative rules for while

  1. Consider the following alternative Hoare rule for while: {A} c {b ⇒ A ∧ ¬b ⇒ B} {b ⇒ A ∧ ¬b ⇒ B} while b do c {B}

Show that the system of axioms remains complete if we replace the old rule for while with this one. You must show that any derivation that uses the old rule for while can be written with this rule instead.

  1. Consider the following alternative Hoare rule for while {A ∧ b} c {A} {A}while b do c {A}

This rule is not complete. Give a counterexample and a short justification.

  1. Consider now another Hoare rule for while: ` {A} c {A}

` {A}while b do c {A ∧ ¬b}

This rule is also incomplete. Give a counterexample and a short justification.

(Exercise 3) In the abstract interpretation example with the factorial, you can see that the analysis was rather imprecise. How can you improve the result of this analysis by:

  1. Changing the factorial program but not changing the analysis, and
  2. Changing the abstract interpretation setup but without changing the factorial program. Give separate solutions for each of the above ways to address the problem.