Generation of Verification Conditions Andreas Podelski November 15, - - PowerPoint PPT Presentation

generation of verification conditions
SMART_READER_LITE
LIVE PREVIEW

Generation of Verification Conditions Andreas Podelski November 15, - - PowerPoint PPT Presentation

Generation of Verification Conditions Andreas Podelski November 15, 2011 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) or


slide-1
SLIDE 1

Generation of Verification Conditions

Andreas Podelski November 15, 2011

slide-2
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
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
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
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
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
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
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
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
SLIDE 10

System H (2)

◮ sequential command C ≡ C1 ; C2

{φ} C1 {φ′} {φ′} C {ψ} {φ} C {ψ}

slide-11
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
SLIDE 12

System H (3)

◮ while command C ≡ while b do {θ} C0

{θ ∧ b} C0 {θ} {θ} C {θ ∧ ¬b}

slide-13
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
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
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
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
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
SLIDE 18

mechanize backward inference

◮ given Hoare triple {φ} C {ψ},

from what Hoare triples could we have inferred it? . . . using what inference rule?

slide-19
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
SLIDE 20

backward inference

??? {φ} skip {ψ}

slide-21
SLIDE 21

backward inference

??? {φ} skip {ψ}

◮ derivation can use what axiom and what inference rule?

slide-22
SLIDE 22

backward inference

??? {φ} skip {ψ}

◮ derivation can use what axiom and what inference rule? ◮ axiom for skip

{φ} skip {φ}

slide-23
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
SLIDE 24

backward inference

??? {φ} skip {ψ}

slide-25
SLIDE 25

backward inference

??? {φ} skip {ψ}

◮ possible derivation sequence: axiom for (skip), followed by

weaking of postcondition

{φ} skip {φ} {φ} skip {ψ}

slide-26
SLIDE 26

backward inference

??? {φ} skip {ψ}

◮ possible derivation sequence: axiom for (skip), followed by

weaking of postcondition

{φ} skip {φ} {φ} skip {ψ} ◮ side condition: φ → ψ

slide-27
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
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
SLIDE 29

new axiom for skip

{φ} skip {ψ} if φ → ψ

slide-30
SLIDE 30

new axiom for skip

{φ} skip {ψ} if φ → ψ

◮ old axiom & strengthening of precondition

slide-31
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
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
SLIDE 33

new axiom for update

{φ} x := e {ψ} if φ → ψ[e/x]

slide-34
SLIDE 34

new axiom for update

{φ} x := e {ψ} if φ → ψ[e/x]

◮ old axiom & strengthening of precondition

slide-35
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
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
SLIDE 37

new rule for seq

◮ old rule:

{φ} C1 {θ} {θ} C2 {ψ} {φ} C1 ; C2 {ψ}

slide-38
SLIDE 38

new rule for seq

◮ old rule:

{φ} C1 {θ} {θ} C2 {ψ} {φ} C1 ; C2 {ψ}

◮ new rule:

{φ1} C1 {φ2} {φ2} C2 {ψ} {φ} C1 ; C2 {ψ} φ → φ1

slide-39
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
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
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
SLIDE 42

new rule for cond

◮ old rule:

{φ ∧ b} C1 {ψ} {φ ∧ ¬b} C2 {ψ} {φ} if b then C1 else C2 {ψ}

slide-43
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
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
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
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
SLIDE 47

new rule for while

◮ old rule:

{θ ∧ b} C0 {θ} {θ} while b do {θ} C0 {θ ∧ ¬b}

slide-48
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
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
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
SLIDE 51

weakest precondition wp(C, ψ)

◮ wp(skip, ψ) = ψ

slide-52
SLIDE 52

weakest precondition wp(C, ψ)

◮ wp(skip, ψ) = ψ ◮ wp(x := e, ψ) = ψ[e/x]

slide-53
SLIDE 53

weakest precondition wp(C, ψ)

◮ wp(skip, ψ) = ψ ◮ wp(x := e, ψ) = ψ[e/x] ◮ wp(C1 ; C2, ψ) = wp(C1, wp(C2, ψ))

slide-54
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
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
SLIDE 56

verification condition

◮ for command C of form: skip, update, seq, cond,

slide-57
SLIDE 57

verification condition

◮ for command C of form: skip, update, seq, cond, ◮ to check Hoare triple {φ} C {ψ},

slide-58
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
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
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
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 → ψ