












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













Dr. Mattox Beckman
University of Illinois at Urbana-Champaign Department of Computer Science
You should be able to ...
I (^) Explain the syntax of Hoare triples and relate them to small step semantics. I (^) Use a Hoare triple to show the correctness of a simple program. I (^) Explain the properties of the weakest precondition.
< skip , σ >→< E, σ > < u := t, σ >→< E, σ[u := σ(t)] > < S 1 , σ >→< S 2 , τ > < S 1 ; S, σ >→< S 2 ; S, τ >
< if B then S 1 else S 2 fi , σ >→< S 1 , σ > where σ |= B < if B then S 1 else S 2 fi , σ >→< S 2 , σ > where σ |= ¬B < while B do S 1 od , σ >→< S 1 ; while B do S 1 od , σ > where σ |= B < while B do S 1 od , σ >→< E, σ > where σ |= ¬B
I (^) The → semantics gives us exact transformations, but sometimes we want something more general. I (^) Define {p}S{q}, where p and q are assertions, and S is a program: I (^) |= {p}S{q} – if p is true before the program runs, q will be true afterwards; if the program terminates. “Partial Correctness” I (^) |=tot {p}S{q} – if p is true before the program runs, q will be true afterwards. Termination guaranteed. “Total Correctness” I (^) These are sometimes called correctness formulas.
{p} skip {p}
{p[u := t]}u := t{p}
I (^) Is this what you expected?
{y > 10 }x := y{x > 10 }
{p ∧ B}S 1 {q}, {p ∧ ¬B}S 2 {q} {p} if B then S 1 else S 2 fi {q}
I (^) See Dijkstra’s paper EWD 264.
{p ∧ B}S{p} {p} while B do S od {p ∧ ¬B}
{p} skip {p} {p[u := t]}u := t{p}
{p}S∗ 1 {r}, {r}S∗ 2 {q} {p}S∗ 1 ; {r}S∗ 2 {q}
I (^) Example
{y = 20, x = 10} t := x; {y = 20, t = 10} x := y; {x = 20, t = 10} y := t {x = 20, y = 10}
{p ∧ B}S∗ 1 {q}, {p ∧ ¬B}S∗ 2 {q} {p} if B then {p ∧ B}S∗ 1 {q} else {p ∧ ¬B}S∗ 2 {q} fi {q}
p → p 1 , {p 1 }S∗{q 1 }, q 1 → q {p}{p 1 }S∗{q 1 }{q}
{true} if x > y then m := x fi ; if x < y then m := y fi {m = max(x, y)}
{true} if x > y then m := x fi ; if x < y then {y = max(x, y)}m := y{m = max(x, y)} else {m = max(x, y)} skip {m = max(x, y)} fi {m = max(x, y)}
{true} if x > y then {P[x = max(x, y)]}m := x{P} else {P} skip {P} fi ; {P ≡ x < y ∧ y = max(x, y) ∨ x > y ∧ m = max(x, y)} if x < y then {y = max(x, y)}m := y{m = max(x, y)} else {m = max(x, y)} skip {m = max(x, y)} fi {m = max(x, y)}
{true} {x > y ∧ x = max(x, y) ∨ x < y ∧ y = max(x, y) ∨ x = y ∧ m = max(x, y)} if x > y then {P[x = max(x, y)]}m := x{P} else {P} skip {P} fi ; {P ≡ x < y ∧ y = max(x, y) ∨ x ≥ y ∧ m = max(x, y)} if x < y then {y = max(x, y)}m := y{m = max(x, y)} else {m = max(x, y)} skip {m = max(x, y)} fi {m = max(x, y)}