SLIDE 1
Generation of Verification Conditions
Andreas Podelski November 15, 2011
SLIDE 2 mechanization of correctness proof
◮ given a Hoare triple {φ} C {ψ},
a derivation is a sequence of Hoare triples, each Hoare triple is an axiom (skip, update)
- r it is inferred by one of the inference rules (seq, cond, while)
SLIDE 3 mechanization of correctness proof
◮ given a Hoare triple {φ} C {ψ},
a derivation is a sequence of Hoare triples, each Hoare triple is an axiom (skip, update)
- r it is inferred by one of the inference rules (seq, cond, while)
◮ mechanization:
SLIDE 4 mechanization of correctness proof
◮ given a Hoare triple {φ} C {ψ},
a derivation is a sequence of Hoare triples, each Hoare triple is an axiom (skip, update)
- r it is inferred by one of the inference rules (seq, cond, while)
◮ mechanization: ◮ construct a derivation assuming that side conditions hold, ◮ and then check side conditions
“discharge the verification condition”
SLIDE 5 mechanization of correctness proof
◮ given a Hoare triple {φ} C {ψ},
a derivation is a sequence of Hoare triples, each Hoare triple is an axiom (skip, update)
- r it is inferred by one of the inference rules (seq, cond, while)
◮ mechanization: ◮ construct a derivation assuming that side conditions hold, ◮ and then check side conditions
“discharge the verification condition”
◮ if check does not succeed: try another derivation
SLIDE 6 mechanization of correctness proof
◮ given a Hoare triple {φ} C {ψ},
a derivation is a sequence of Hoare triples, each Hoare triple is an axiom (skip, update)
- r it is inferred by one of the inference rules (seq, cond, while)
◮ mechanization: ◮ construct a derivation assuming that side conditions hold, ◮ and then check side conditions
“discharge the verification condition”
◮ if check does not succeed: try another derivation ◮ next:
deterministic strategy to construct unique derivation
SLIDE 7
System H (1)
◮ Hoare triple {φ} C {ψ} derivable in H if
exists a derivation using the axioms and inference rules of H
SLIDE 8
System H (1)
◮ Hoare triple {φ} C {ψ} derivable in H if
exists a derivation using the axioms and inference rules of H
◮ skip
{φ} skip {φ}
SLIDE 9
System H (1)
◮ Hoare triple {φ} C {ψ} derivable in H if
exists a derivation using the axioms and inference rules of H
◮ skip
{φ} skip {φ}
◮ assignment
{ψ[e/x]} x := e {ψ}
SLIDE 10
System H (2)
◮ sequential command C ≡ C1 ; C2
{φ} C1 {φ′} {φ′} C {ψ} {φ} C {ψ}
SLIDE 11
System H (2)
◮ sequential command C ≡ C1 ; C2
{φ} C1 {φ′} {φ′} C {ψ} {φ} C {ψ}
◮ conditional command C ≡ if b then C1 else C2
{φ ∧ b} C1 {ψ} {φ ∧ ¬b} C {ψ} {φ} C {ψ}
SLIDE 12
System H (3)
◮ while command C ≡ while b do {θ} C0
{θ ∧ b} C0 {θ} {θ} C {θ ∧ ¬b}
SLIDE 13
System H (3)
◮ while command C ≡ while b do {θ} C0
{θ ∧ b} C0 {θ} {θ} C {θ ∧ ¬b}
◮ strengthen precondition, weaken postcondition
{φ} C {ψ} {φ′} C {ψ′} if φ′ → φ and ψ → ψ′
SLIDE 14
System H (3)
◮ while command C ≡ while b do {θ} C0
{θ ∧ b} C0 {θ} {θ} C {θ ∧ ¬b}
◮ strengthen precondition, weaken postcondition
{φ} C {ψ} {φ′} C {ψ′} if φ′ → φ and ψ → ψ′
SLIDE 15
System H (3)
◮ while command C ≡ while b do {θ} C0
{θ ∧ b} C0 {θ} {θ} C {θ ∧ ¬b}
◮ strengthen precondition, weaken postcondition
{φ} C {ψ} {φ′} C {ψ′} if φ′ → φ and ψ → ψ′
◮ Hoare triple derivable in all logicals models in which
implications in side condition are valid
SLIDE 16
backward construction of derivation
◮ given Hoare triple {φ} C {ψ},
“guess inference rule and guess assumptions” generate Hoare triples from which we could infer {φ} C {ψ} . . . and collect side conditions of inference rule (if any)
SLIDE 17
backward construction of derivation
◮ given Hoare triple {φ} C {ψ},
“guess inference rule and guess assumptions” generate Hoare triples from which we could infer {φ} C {ψ} . . . and collect side conditions of inference rule (if any)
◮ repeat on generated Hoare triples
to generate new Hoare triples until every Hoare triple is an axiom
SLIDE 18
mechanize backward inference
◮ given Hoare triple {φ} C {ψ},
from what Hoare triples could we have inferred it? . . . using what inference rule?
SLIDE 19
mechanize backward inference
◮ given Hoare triple {φ} C {ψ},
from what Hoare triples could we have inferred it? . . . using what inference rule?
◮ next:
go through each form of command C (skip, update, seq, cond, while)
SLIDE 20
backward inference
◮
??? {φ} skip {ψ}
SLIDE 21
backward inference
◮
??? {φ} skip {ψ}
◮ derivation can use what axiom and what inference rule?
SLIDE 22
backward inference
◮
??? {φ} skip {ψ}
◮ derivation can use what axiom and what inference rule? ◮ axiom for skip
{φ} skip {φ}
SLIDE 23
backward inference
◮
??? {φ} skip {ψ}
◮ derivation can use what axiom and what inference rule? ◮ axiom for skip
{φ} skip {φ}
◮ ‘strengthen precondition, weaken postcondition’ inference rule
{φ} C {ψ} {φ′} C {ψ′} if φ′ → φ and ψ → ψ′
SLIDE 24
backward inference
◮
??? {φ} skip {ψ}
SLIDE 25
backward inference
◮
??? {φ} skip {ψ}
◮ possible derivation sequence: axiom for (skip), followed by
weaking of postcondition
{φ} skip {φ} {φ} skip {ψ}
SLIDE 26
backward inference
◮
??? {φ} skip {ψ}
◮ possible derivation sequence: axiom for (skip), followed by
weaking of postcondition
{φ} skip {φ} {φ} skip {ψ} ◮ side condition: φ → ψ
SLIDE 27
backward inference
◮
??? {φ} skip {ψ}
◮ possible derivation sequence: axiom for (skip), followed by
weaking of postcondition
{φ} skip {φ} {φ} skip {ψ} ◮ side condition: φ → ψ ◮ possible derivation sequence:
axiom for (skip), followed by strengthening of precondition
{ψ} skip {ψ} {φ} skip {ψ}
SLIDE 28
backward inference
◮
??? {φ} skip {ψ}
◮ possible derivation sequence: axiom for (skip), followed by
weaking of postcondition
{φ} skip {φ} {φ} skip {ψ} ◮ side condition: φ → ψ ◮ possible derivation sequence:
axiom for (skip), followed by strengthening of precondition
{ψ} skip {ψ} {φ} skip {ψ} ◮ same side condition: φ → ψ
SLIDE 29
new axiom for skip
◮
{φ} skip {ψ} if φ → ψ
SLIDE 30
new axiom for skip
◮
{φ} skip {ψ} if φ → ψ
◮ old axiom & strengthening of precondition
SLIDE 31
new axiom for skip
◮
{φ} skip {ψ} if φ → ψ
◮ old axiom & strengthening of precondition ◮ φ is a precondition for ψ under skip
if and only if φ → ψ is valid
SLIDE 32
new axiom for skip
◮
{φ} skip {ψ} if φ → ψ
◮ old axiom & strengthening of precondition ◮ φ is a precondition for ψ under skip
if and only if φ → ψ is valid
◮ ψ is the weakest precondition for ψ under skip
SLIDE 33
new axiom for update
◮
{φ} x := e {ψ} if φ → ψ[e/x]
SLIDE 34
new axiom for update
◮
{φ} x := e {ψ} if φ → ψ[e/x]
◮ old axiom & strengthening of precondition
SLIDE 35
new axiom for update
◮
{φ} x := e {ψ} if φ → ψ[e/x]
◮ old axiom & strengthening of precondition ◮ φ is a precondition for ψ under x := e
if and only if φ → ψ[e/x] is valid
SLIDE 36
new axiom for update
◮
{φ} x := e {ψ} if φ → ψ[e/x]
◮ old axiom & strengthening of precondition ◮ φ is a precondition for ψ under x := e
if and only if φ → ψ[e/x] is valid
◮ ψ[e/x] is the weakest precondition for ψ under x := e
SLIDE 37
new rule for seq
◮ old rule:
{φ} C1 {θ} {θ} C2 {ψ} {φ} C1 ; C2 {ψ}
SLIDE 38
new rule for seq
◮ old rule:
{φ} C1 {θ} {θ} C2 {ψ} {φ} C1 ; C2 {ψ}
◮ new rule:
{φ1} C1 {φ2} {φ2} C2 {ψ} {φ} C1 ; C2 {ψ} φ → φ1
SLIDE 39
new rule for seq
◮ old rule:
{φ} C1 {θ} {θ} C2 {ψ} {φ} C1 ; C2 {ψ}
◮ new rule:
{φ1} C1 {φ2} {φ2} C2 {ψ} {φ} C1 ; C2 {ψ} φ → φ1
◮ let φ2 be the weakest precondition of ψ under C2 and
let φ1 be the weakest precondition of φ2 under C1
SLIDE 40
new rule for seq
◮ old rule:
{φ} C1 {θ} {θ} C2 {ψ} {φ} C1 ; C2 {ψ}
◮ new rule:
{φ1} C1 {φ2} {φ2} C2 {ψ} {φ} C1 ; C2 {ψ} φ → φ1
◮ let φ2 be the weakest precondition of ψ under C2 and
let φ1 be the weakest precondition of φ2 under C1
◮ φ is a precondition for ψ under C1 ; C2
if and only if φ → φ1 is valid
SLIDE 41
new rule for seq
◮ old rule:
{φ} C1 {θ} {θ} C2 {ψ} {φ} C1 ; C2 {ψ}
◮ new rule:
{φ1} C1 {φ2} {φ2} C2 {ψ} {φ} C1 ; C2 {ψ} φ → φ1
◮ let φ2 be the weakest precondition of ψ under C2 and
let φ1 be the weakest precondition of φ2 under C1
◮ φ is a precondition for ψ under C1 ; C2
if and only if φ → φ1 is valid
◮ the weakest precondition of ψ under C1 ; C2 is
the weakest precondition of (the weakest precondition of ψ under C2) under C1
SLIDE 42
new rule for cond
◮ old rule:
{φ ∧ b} C1 {ψ} {φ ∧ ¬b} C2 {ψ} {φ} if b then C1 else C2 {ψ}
SLIDE 43
new rule for cond
◮ old rule:
{φ ∧ b} C1 {ψ} {φ ∧ ¬b} C2 {ψ} {φ} if b then C1 else C2 {ψ}
◮ new rule:
{φ1} C1 {ψ} {φ2} C2 {ψ} {φ} if b then C1 else C2 {ψ} φ → (¬b∨φ1) and φ → (b∨φ2)
SLIDE 44
new rule for cond
◮ old rule:
{φ ∧ b} C1 {ψ} {φ ∧ ¬b} C2 {ψ} {φ} if b then C1 else C2 {ψ}
◮ new rule:
{φ1} C1 {ψ} {φ2} C2 {ψ} {φ} if b then C1 else C2 {ψ} φ → (¬b∨φ1) and φ → (b∨φ2)
◮ let φ1 be the weakest precondition of ψ under C1 and
let φ2 be the weakest precondition of ψ under C2
SLIDE 45
new rule for cond
◮ old rule:
{φ ∧ b} C1 {ψ} {φ ∧ ¬b} C2 {ψ} {φ} if b then C1 else C2 {ψ}
◮ new rule:
{φ1} C1 {ψ} {φ2} C2 {ψ} {φ} if b then C1 else C2 {ψ} φ → (¬b∨φ1) and φ → (b∨φ2)
◮ let φ1 be the weakest precondition of ψ under C1 and
let φ2 be the weakest precondition of ψ under C2
◮ φ is a precondition for ψ under if b then C1 else C2
if and only if φ → ((¬b ∨ φ1) ∧ (b ∨ φ2)) is valid
SLIDE 46
new rule for cond
◮ old rule:
{φ ∧ b} C1 {ψ} {φ ∧ ¬b} C2 {ψ} {φ} if b then C1 else C2 {ψ}
◮ new rule:
{φ1} C1 {ψ} {φ2} C2 {ψ} {φ} if b then C1 else C2 {ψ} φ → (¬b∨φ1) and φ → (b∨φ2)
◮ let φ1 be the weakest precondition of ψ under C1 and
let φ2 be the weakest precondition of ψ under C2
◮ φ is a precondition for ψ under if b then C1 else C2
if and only if φ → ((¬b ∨ φ1) ∧ (b ∨ φ2)) is valid
◮ the weakest precondition of ψ under if b then C1 else C2 is
the conjunction of ¬b ∨ φ1 and b ∨ φ2
SLIDE 47
new rule for while
◮ old rule:
{θ ∧ b} C0 {θ} {θ} while b do {θ} C0 {θ ∧ ¬b}
SLIDE 48
new rule for while
◮ old rule:
{θ ∧ b} C0 {θ} {θ} while b do {θ} C0 {θ ∧ ¬b}
◮ new rule = old rule & strengthening & weakening
{θ ∧ b} C0 {θ} {φ} while b do {θ} C0 {ψ} φ → θ and θ ∧ ¬b → ψ
SLIDE 49
new rule for while
◮ old rule:
{θ ∧ b} C0 {θ} {θ} while b do {θ} C0 {θ ∧ ¬b}
◮ new rule = old rule & strengthening & weakening
{θ ∧ b} C0 {θ} {φ} while b do {θ} C0 {ψ} φ → θ and θ ∧ ¬b → ψ
◮ ◮ φ is a precondition for ψ under while b do {θ} C0
if and only if φ → θ and θ ∧ ¬b → ψ are valid and {θ ∧ b} C0 {θ}
SLIDE 50
new rule for while
◮ old rule:
{θ ∧ b} C0 {θ} {θ} while b do {θ} C0 {θ ∧ ¬b}
◮ new rule = old rule & strengthening & weakening
{θ ∧ b} C0 {θ} {φ} while b do {θ} C0 {ψ} φ → θ and θ ∧ ¬b → ψ
◮ ◮ φ is a precondition for ψ under while b do {θ} C0
if and only if φ → θ and θ ∧ ¬b → ψ are valid and {θ ∧ b} C0 {θ}
◮ θ is the weakest precondition for ψ under while b do {θ} C0
SLIDE 51
weakest precondition wp(C, ψ)
◮ wp(skip, ψ) = ψ
SLIDE 52
weakest precondition wp(C, ψ)
◮ wp(skip, ψ) = ψ ◮ wp(x := e, ψ) = ψ[e/x]
SLIDE 53
weakest precondition wp(C, ψ)
◮ wp(skip, ψ) = ψ ◮ wp(x := e, ψ) = ψ[e/x] ◮ wp(C1 ; C2, ψ) = wp(C1, wp(C2, ψ))
SLIDE 54
weakest precondition wp(C, ψ)
◮ wp(skip, ψ) = ψ ◮ wp(x := e, ψ) = ψ[e/x] ◮ wp(C1 ; C2, ψ) = wp(C1, wp(C2, ψ)) ◮ wp(if b then C1 else C2, ψ) = (¬b ∨ φ1) ∧ (b ∨ φ2)
where φ1 = wp(C1, ψ) φ2 = wp(C2, ψ)
SLIDE 55
weakest precondition wp(C, ψ)
◮ wp(skip, ψ) = ψ ◮ wp(x := e, ψ) = ψ[e/x] ◮ wp(C1 ; C2, ψ) = wp(C1, wp(C2, ψ)) ◮ wp(if b then C1 else C2, ψ) = (¬b ∨ φ1) ∧ (b ∨ φ2)
where φ1 = wp(C1, ψ) φ2 = wp(C2, ψ)
◮ wp(while b do {θ} C0, ψ) = θ
SLIDE 56
verification condition
◮ for command C of form: skip, update, seq, cond,
SLIDE 57
verification condition
◮ for command C of form: skip, update, seq, cond, ◮ to check Hoare triple {φ} C {ψ},
SLIDE 58
verification condition
◮ for command C of form: skip, update, seq, cond, ◮ to check Hoare triple {φ} C {ψ}, ◮ check validity of verification condition
φ → wp(C, ψ)
SLIDE 59
verification condition
◮ for command C of form: skip, update, seq, cond, ◮ to check Hoare triple {φ} C {ψ}, ◮ check validity of verification condition
φ → wp(C, ψ)
◮ for command C of form: while b do {θ} C0 ,
SLIDE 60
verification condition
◮ for command C of form: skip, update, seq, cond, ◮ to check Hoare triple {φ} C {ψ}, ◮ check validity of verification condition
φ → wp(C, ψ)
◮ for command C of form: while b do {θ} C0 , ◮ to check Hoare triple {φ} C {ψ},
SLIDE 61
verification condition
◮ for command C of form: skip, update, seq, cond, ◮ to check Hoare triple {φ} C {ψ}, ◮ check validity of verification condition
φ → wp(C, ψ)
◮ for command C of form: while b do {θ} C0 , ◮ to check Hoare triple {φ} C {ψ}, ◮ check Hoare triple {θ ∧ b} C0 {θ}
and check validity of two implications φ → θ θ ∧ ¬b → ψ