Symbolic Computation and Theorem Proving in Program Analysis Laura - - PowerPoint PPT Presentation

symbolic computation and theorem proving in program
SMART_READER_LITE
LIVE PREVIEW

Symbolic Computation and Theorem Proving in Program Analysis Laura - - PowerPoint PPT Presentation

Symbolic Computation and Theorem Proving in Program Analysis Laura Kov acs Chalmers Outline Part 1: Weakest Precondition for Program Analysis and Verification Part 2: Polynomial Invariant Generation (TACAS08, LPAR10) Part 3:


slide-1
SLIDE 1

Symbolic Computation and Theorem Proving in Program Analysis

Laura Kov´ acs

Chalmers

slide-2
SLIDE 2

Outline

Part 1: Weakest Precondition for Program Analysis and Verification Part 2: Polynomial Invariant Generation (TACAS’08, LPAR’10) Part 3: Quantified Invariant Generation (FASE’09, MICAI’11) Part 4: Invariants, Interpolants and Symbol Elimination

(CADE’09, POPL ’12, APLAS’12)

slide-3
SLIDE 3

Part 1: Program Analysis and Verification

Preliminaries Weakest Precondition (WP) and Loop Invariants Examples of Verification by WP

slide-4
SLIDE 4

Preliminaries

Program Verification:

program satisfies its requirements (specification)

Precondition P: (x ≥ 0) ∧ (y > 0) initial states Postcondition Q: (quo ∗ y + rem = x) ∧ (0 ≤ rem < y) final states Program (code) S: quo := 0; rem := x; while y ≤ rem do rem := rem − y; quo := quo + 1 end while How

Hoare triple (correctness formula): {P} S {Q}

slide-5
SLIDE 5

Preliminaries

Program Verification:

program satisfies its requirements (specification)

Example.

Given two natural numbers x and y, with y being non zero, compute the quotient (quo) and the remainder (rem) of the integer division of x by y. Precondition P: (x ≥ 0) ∧ (y > 0) initial states Postcondition Q: (quo ∗ y + rem = x) ∧ (0 ≤ rem < y) final states Program (code) S: quo := 0; rem := x; while y ≤ rem do rem := rem − y; quo := quo + 1 end while How

Hoare triple (correctness formula): {P} S {Q}

slide-6
SLIDE 6

Preliminaries

Program Verification:

program satisfies its requirements (specification)

Example.

Given two natural numbers x and y, with y being non zero, compute the quotient (quo) and the remainder (rem) of the integer division of x by y. Precondition P: (x ≥ 0) ∧ (y > 0) initial states Postcondition Q: (quo ∗ y + rem = x) ∧ (0 ≤ rem < y) final states Program (code) S: quo := 0; rem := x; while y ≤ rem do rem := rem − y; quo := quo + 1 end while How

Hoare triple (correctness formula): {P} S {Q}

slide-7
SLIDE 7

Preliminaries

Program Verification:

program satisfies its requirements (specification)

Example.

Given two natural numbers x and y, with y being non zero, compute the quotient (quo) and the remainder (rem) of the integer division of x by y. Precondition P: (x ≥ 0) ∧ (y > 0) initial states Postcondition Q: (quo ∗ y + rem = x) ∧ (0 ≤ rem < y) final states Program (code) S: quo := 0; rem := x; while y ≤ rem do rem := rem − y; quo := quo + 1 end while How

Hoare triple (correctness formula): {P} S {Q}

slide-8
SLIDE 8

Preliminaries

Program Verification:

program satisfies its requirements (specification)

Example.

Given two natural numbers x and y, with y being non zero, compute the quotient (quo) and the remainder (rem) of the integer division of x by y. Precondition P: (x ≥ 0) ∧ (y > 0) initial states Postcondition Q: (quo ∗ y + rem = x) ∧ (0 ≤ rem < y) final states Program (code) S: quo := 0; rem := x; while y ≤ rem do rem := rem − y; quo := quo + 1 end while How

Hoare triple (correctness formula): {P} S {Q}

slide-9
SLIDE 9

Preliminaries

Program Verification:

program satisfies its requirements (specification P, Q)

  • program correctness

Example.

Given two natural numbers x and y, with y being non zero, compute the quotient (quo) and the remainder (rem) of the integer division of x by y. Precondition P: (x ≥ 0) ∧ (y > 0) initial states Postcondition Q: (quo ∗ y + rem = x) ∧ (0 ≤ rem < y) final states Program (code) S: quo := 0; rem := x; while y ≤ rem do rem := rem − y; quo := quo + 1 end while How

Hoare triple (correctness formula): {P} S {Q}

slide-10
SLIDE 10

Considerations

Program statements:

◮ Assignments: x := expression ◮ Sequencing: s1; s2 ◮ Conditionals: if (cond) then s1 else s2 ◮ Loops: while (cond) do s end while

Program: S = s1; s2; . . . ; sn−1; sn Partial correctness of {P} S {Q}:

Every computation of S that:

◮ starts in a state satisfying P and ◮ is terminating,

ends in a state satisfying Q.

slide-11
SLIDE 11

Considerations

Program statements:

◮ Assignments: x := expression ◮ Sequencing: s1; s2 ◮ Conditionals: if (cond) then s1 else s2 ◮ Loops: while (cond) do s end while

Program: S = s1; s2; . . . ; sn−1; sn Partial correctness of {P} S {Q}:

Every computation of S that:

◮ starts in a state satisfying P and ◮ is terminating,

ends in a state satisfying Q.

slide-12
SLIDE 12

Considerations

Program statements:

◮ Assignments: x := expression ◮ Sequencing: s1; s2 ◮ Conditionals: if (cond) then s1 else s2 ◮ Loops: while (cond) do s end while

Program: S = s1; s2; . . . ; sn−1; sn Partial correctness of {P} S {Q}:

Every computation of S that:

◮ starts in a state satisfying P and ◮ is terminating,

ends in a state satisfying Q.

slide-13
SLIDE 13

Specification Program Weakest Precondition Verification Conditions Proving

slide-14
SLIDE 14

Specification Program Weakest Precondition Verification Conditions Proving

slide-15
SLIDE 15

Weakest Precondition Strategy

P is weaker than R iff R = ⇒ P. Weakest Precondition wp(S, Q) for S with Q:

for any {R} S {Q} we have R = ⇒ wp(S, Q).

Note: {wp(S, Q)} S {Q}.

Verification of {P} S {Q}:

S = s1; . . . ; sn−1; sn

  • 1. Compute wp(S, Q);
  • 2. Prove P =

⇒ wp(S, Q)

slide-16
SLIDE 16

Weakest Precondition Strategy

P is weaker than R iff R = ⇒ P. Weakest Precondition wp(S, Q) for S with Q:

for any {R} S {Q} we have R = ⇒ wp(S, Q).

Note: {wp(S, Q)} S {Q}.

Verification of {P} S {Q}:

S = s1; . . . ; sn−1; sn

  • 1. Compute wp(S, Q);
  • 2. Prove P =

⇒ wp(S, Q)

slide-17
SLIDE 17

Weakest Precondition Strategy

P is weaker than R iff R = ⇒ P. Weakest Precondition wp(S, Q) for S with Q:

for any {R} S {Q} we have R = ⇒ wp(S, Q).

Note: {wp(S, Q)} S {Q}.

Verification of {P} S {Q}:

S = s1; . . . ; sn−1; sn

  • 1. Compute wp(S, Q);
  • 2. Prove P =

⇒ wp(S, Q) {P} ← wp(s1, wp(. . . , wp(sn, Q)))

  • wp(S,Q)

s1; . . . ← wp(sn−1, wp(sn, Q)) sn−1; ← wp(sn, Q) sn {Q}

slide-18
SLIDE 18

Weakest Precondition Strategy

P is weaker than R iff R = ⇒ P. Weakest Precondition wp(S, Q) for S with Q:

for any {R} S {Q} we have R = ⇒ wp(S, Q).

Note: {wp(S, Q)} S {Q}.

Verification of {P} S {Q}:

S = s1; . . . ; sn−1; sn

  • 1. Compute wp(S, Q);
  • 2. Prove P =

⇒ wp(S, Q) {P} ← wp(s1, wp(. . . , wp(sn, Q)))

  • wp(S,Q)

s1; . . . ← wp(sn−1, wp(sn, Q)) sn−1; ← wp(sn, Q) sn {Q}

slide-19
SLIDE 19

Weakest Precondition Strategy

P is weaker than R iff R = ⇒ P. Weakest Precondition wp(S, Q) for S with Q:

for any {R} S {Q} we have R = ⇒ wp(S, Q).

Note: {wp(S, Q)} S {Q}.

Verification of {P} S {Q}:

S = s1; . . . ; sn−1; sn

  • 1. Compute wp(S, Q);
  • 2. Prove P =

⇒ wp(S, Q) {P} ← wp(s1, wp(. . . , wp(sn, Q)))

  • wp(S,Q)

s1; . . . ← wp(sn−1, wp(sn, Q)) sn−1; ← wp(sn, Q) sn {Q}

slide-20
SLIDE 20

Weakest Precondition Strategy

P is weaker than R iff R = ⇒ P. Weakest Precondition wp(S, Q) for S with Q:

for any {R} S {Q} we have R = ⇒ wp(S, Q).

Note: {wp(S, Q)} S {Q}.

Verification of {P} S {Q}:

S = s1; . . . ; sn−1; sn

  • 1. Compute wp(S, Q);
  • 2. Prove P =

⇒ wp(S, Q) {P} ← wp(s1, wp(. . . , wp(sn, Q)))

  • wp(S,Q)

s1; . . . ← wp(sn−1, wp(sn, Q)) sn−1; ← wp(sn, Q) sn {Q}

slide-21
SLIDE 21

WP Inference Rules

◮ Assignments:

wp(x := expression, Q) = Qx←expression wp(x := 5, x + y = 6) = 5 + y = 6 wp(x := x + 1, x + y = 6) = x + 1 + y = 6

◮ Sequencing:

wp(s1; s2, Q) = wp(s1, wp(s2, Q)) wp(x := x + 1; y := y + x, 2 ∗ y > 10) = wp(x := x + 1, wp(y := y + x, 2 ∗ y > 10)) = wp(x := x + 1, 2 ∗ (y + x) > 10) = 2 ∗ (y + x + 1) > 10)

slide-22
SLIDE 22

WP Inference Rules

◮ Assignments:

wp(x := expression, Q) = Qx←expression wp(x := 5, x + y = 6) = 5 + y = 6 wp(x := x + 1, x + y = 6) = x + 1 + y = 6

◮ Sequencing:

wp(s1; s2, Q) = wp(s1, wp(s2, Q)) wp(x := x + 1; y := y + x, 2 ∗ y > 10) = wp(x := x + 1, wp(y := y + x, 2 ∗ y > 10)) = wp(x := x + 1, 2 ∗ (y + x) > 10) = 2 ∗ (y + x + 1) > 10)

slide-23
SLIDE 23

WP Inference Rules

◮ Assignments:

wp(x := expression, Q) = Qx←expression wp(x := 5, x + y = 6) = 5 + y = 6 wp(x := x + 1, x + y = 6) = x + 1 + y = 6

◮ Sequencing:

wp(s1; s2, Q) = wp(s1, wp(s2, Q)) wp(x := x + 1; y := y + x, 2 ∗ y > 10) = wp(x := x + 1, wp(y := y + x, 2 ∗ y > 10)) = wp(x := x + 1, 2 ∗ (y + x) > 10) = 2 ∗ (y + x + 1) > 10)

slide-24
SLIDE 24

WP Inference Rules

◮ Assignments:

wp(x := expression, Q) = Qx←expression wp(x := 5, x + y = 6) = 5 + y = 6 wp(x := x + 1, x + y = 6) = x + 1 + y = 6

◮ Sequencing:

wp(s1; s2, Q) = wp(s1, wp(s2, Q)) wp(x := x + 1; y := y + x, 2 ∗ y > 10) = wp(x := x + 1, wp(y := y + x, 2 ∗ y > 10)) = wp(x := x + 1, 2 ∗ (y + x) > 10) = 2 ∗ (y + x + 1) > 10)

slide-25
SLIDE 25

WP Inference Rules

◮ Assignments:

wp(x := expression, Q) = Qx←expression wp(x := 5, x + y = 6) = 5 + y = 6 wp(x := x + 1, x + y = 6) = x + 1 + y = 6

◮ Sequencing:

wp(s1; s2, Q) = wp(s1, wp(s2, Q)) wp(x := x + 1; y := y + x, 2 ∗ y > 10) = wp(x := x + 1, wp(y := y + x, 2 ∗ y > 10)) = wp(x := x + 1, 2 ∗ (y + x) > 10) = 2 ∗ (y + x + 1) > 10)

slide-26
SLIDE 26

WP Inference Rules

◮ Conditionals:

wp(if cond then s1 else s2, Q) = (cond = ⇒ wp(s1, Q)) ∧ (¬cond = ⇒ wp(s2, Q)) and, if s1, s2 contain loops, the verification conditions: ¬cond = ⇒ VerifConditions[s1, Q] ¬cond = ⇒ VerifConditions[s2, Q] wp(if x ≥ y then m := x else m := y, m = Max[x, y]) =

  • x ≥ y =

⇒ wp(m := x, m = Max[x, y])

  • x < y =

⇒ wp(m := y, m = Max[x, y])

  • =
  • x ≥ y =

⇒ x = Max[x, y]

  • x < y =

⇒ y = Max[x, y]

slide-27
SLIDE 27

WP Inference Rules

◮ Conditionals:

wp(if cond then s1 else s2, Q) = (cond = ⇒ wp(s1, Q)) ∧ (¬cond = ⇒ wp(s2, Q)) and, if s1, s2 contain loops, the verification conditions: ¬cond = ⇒ VerifConditions[s1, Q] ¬cond = ⇒ VerifConditions[s2, Q] wp(if x ≥ y then m := x else m := y, m = Max[x, y]) =

  • x ≥ y =

⇒ wp(m := x, m = Max[x, y])

  • x < y =

⇒ wp(m := y, m = Max[x, y])

  • =
  • x ≥ y =

⇒ x = Max[x, y]

  • x < y =

⇒ y = Max[x, y]

slide-28
SLIDE 28

WP Inference Rules

◮ Conditionals:

wp(if cond then s1 else s2, Q) = (cond = ⇒ wp(s1, Q)) ∧ (¬cond = ⇒ wp(s2, Q)) and, if s1, s2 contain loops, the verification conditions: ¬cond = ⇒ VerifConditions[s1, Q] ¬cond = ⇒ VerifConditions[s2, Q] wp(if x ≥ y then m := x else m := y, m = Max[x, y]) =

  • x ≥ y =

⇒ wp(m := x, m = Max[x, y])

  • x < y =

⇒ wp(m := y, m = Max[x, y])

  • =
  • x ≥ y =

⇒ x = Max[x, y]

  • x < y =

⇒ y = Max[x, y]

slide-29
SLIDE 29

WP Inference Rules

◮ Conditionals:

wp(if cond then s1 else s2, Q) = (cond = ⇒ wp(s1, Q)) ∧ (¬cond = ⇒ wp(s2, Q)) and, if s1, s2 contain loops, the verification conditions: ¬cond = ⇒ VerifConditions[s1, Q] ¬cond = ⇒ VerifConditions[s2, Q] wp(if x ≥ y then m := x else m := y, m = Max[x, y]) =

  • x ≥ y =

⇒ wp(m := x, m = Max[x, y])

  • x < y =

⇒ wp(m := y, m = Max[x, y])

  • =
  • x ≥ y =

⇒ x = Max[x, y]

  • x < y =

⇒ y = Max[x, y]

slide-30
SLIDE 30

WP Inference Rules

◮ Conditionals:

wp(if cond then s1 else s2, Q) = (cond = ⇒ wp(s1, Q)) ∧ (¬cond = ⇒ wp(s2, Q)) and, if s1, s2 contain loops, the verification conditions: ¬cond = ⇒ VerifConditions[s1, Q] ¬cond = ⇒ VerifConditions[s2, Q] wp(if x ≥ y then m := x else m := y, m = Max[x, y]) =

  • x ≥ y =

⇒ wp(m := x, m = Max[x, y])

  • x < y =

⇒ wp(m := y, m = Max[x, y])

  • =
  • x ≥ y =

⇒ x = Max[x, y]

  • x < y =

⇒ y = Max[x, y]

slide-31
SLIDE 31

WP Inference Rules

◮ Loops:

wp(while cond do s end while, Q) = I

slide-32
SLIDE 32

WP Inference Rules

◮ Loops:

wp(while cond do s end while, Q) = I

where I is a loop invariant

  • 1. I ∧ cond

= ⇒ I′, where I′ = wp(S, I);

  • 2. I ∧ ¬cond

= ⇒ Q.

slide-33
SLIDE 33

WP Inference Rules

◮ Loops:

wp(while cond do s end while, Q) = I

where I is a loop invariant

  • 1. I ∧ cond

= ⇒ I′, where I′ = wp(S, I);

  • 2. I ∧ ¬cond

= ⇒ Q.

LOOP INVARIANTS (INDUCTIVE ASSERTIONS):

evaluate to true before and after each loop iteration

I is an invariant for {P} while cond do S end while {Q} iff:

  • 0. initial condition: P =

⇒ I;

  • 1. iterative (inductive) condition: {I ∧ cond} S {I};
  • 2. final condition: I ∧ ¬cond

= ⇒ Q

slide-34
SLIDE 34

WP Inference Rules

◮ Loops:

wp(while cond do s end while, Q) = I

where I is a loop invariant

  • 1. I ∧ cond

= ⇒ I′, where I′ = wp(S, I);

  • 2. I ∧ ¬cond

= ⇒ Q.

LOOP INVARIANTS (INDUCTIVE ASSERTIONS):

evaluate to true before and after each loop iteration

I is an invariant for {P} while cond do S end while {Q} iff:

  • 0. initial condition: P =

⇒ I;

  • 1. iterative (inductive) condition: {I ∧ cond} S {I};
  • 2. final condition: I ∧ ¬cond

= ⇒ Q

slide-35
SLIDE 35

WP Inference Rules

◮ Loops:

wp(while cond do s end while, Q) = I

and verification conditions:

  • 1. I ∧ cond

= ⇒ I′, where I′ = wp(S, I);

  • 2. I ∧ ¬cond

= ⇒ Q.

LOOP INVARIANTS (INDUCTIVE ASSERTIONS):

evaluate to true before and after each loop iteration

I is an invariant for {P} while cond do S end while {Q} iff:

  • 0. initial condition: P =

⇒ I;

  • 1. iterative (inductive) condition: {I ∧ cond} S {I};
  • 2. final condition: I ∧ ¬cond

= ⇒ Q

slide-36
SLIDE 36

WP Inference Rules

◮ Loops:

wp(while cond do s end while, Q) = I

and verification conditions:

  • 1. I ∧ cond

= ⇒ I′, where I′ = wp(S, I);

  • 2. I ∧ ¬cond

= ⇒ Q. Division Example (revisited): Postcondition Q: (quo ∗ y + rem = x) ∧ (0 ≤ rem < y) Loop DivLoop: assume (quo ∗ y + rem = x) ∧ (0 ≤ rem) ∧ (0 < y) ∧ (x ≥ 0) while y ≤ rem do rem := rem − y; quo := quo + 1 end while wp(DivLoop, Q) = (quo ∗ y + rem = x) ∧ (0 ≤ rem) ∧ (0 < y) ∧ (x ≥ 0)

  • I

I ∧ (y ≤ rem) = ⇒ ((quo + 1) ∗ y + (rem − y) = x) ∧ (0 ≤ rem − y) ∧ (0 < y) ∧ (x ≥ 0) I ∧ (y > rem) = ⇒ Q

slide-37
SLIDE 37

WP Inference Rules

◮ Loops:

wp(while cond do s end while, Q) = I

and verification conditions:

  • 1. I ∧ cond

= ⇒ I′, where I′ = wp(S, I);

  • 2. I ∧ ¬cond

= ⇒ Q. Division Example (revisited): Postcondition Q: (quo ∗ y + rem = x) ∧ (0 ≤ rem < y) Loop DivLoop: assume (quo ∗ y + rem = x) ∧ (0 ≤ rem) ∧ (0 < y) ∧ (x ≥ 0) while y ≤ rem do rem := rem − y; quo := quo + 1 end while wp(DivLoop, Q) = (quo ∗ y + rem = x) ∧ (0 ≤ rem) ∧ (0 < y) ∧ (x ≥ 0)

  • I

I ∧ (y ≤ rem) = ⇒ ((quo + 1) ∗ y + (rem − y) = x) ∧ (0 ≤ rem − y) ∧ (0 < y) ∧ (x ≥ 0) I ∧ (y > rem) = ⇒ Q

slide-38
SLIDE 38

WP Inference Rules

◮ Loops:

wp(while cond do s end while, Q) = I

and verification conditions:

  • 1. I ∧ cond

= ⇒ I′, where I′ = wp(S, I);

  • 2. I ∧ ¬cond

= ⇒ Q. Division Example (revisited): Postcondition Q: (quo ∗ y + rem = x) ∧ (0 ≤ rem < y) Loop DivLoop: assume (quo ∗ y + rem = x) ∧ (0 ≤ rem) ∧ (0 < y) ∧ (x ≥ 0) while y ≤ rem do rem := rem − y; quo := quo + 1 end while wp(DivLoop, Q) = (quo ∗ y + rem = x) ∧ (0 ≤ rem) ∧ (0 < y) ∧ (x ≥ 0)

  • I

I ∧ (y ≤ rem) = ⇒ ((quo + 1) ∗ y + (rem − y) = x) ∧ (0 ≤ rem − y) ∧ (0 < y) ∧ (x ≥ 0) I ∧ (y > rem) = ⇒ Q

slide-39
SLIDE 39

Weakest Precondition Strategy (revised)

Verification of {P} S {Q}:

S = s1; . . . ; sn−1; sn

  • 1. Compute wp(S, Q);
  • 2. Prove P =

⇒ wp(S, Q) and additional verification conditions {P} ← wp(s1, wp(. . . , wp(sn, Q)))

  • wp(S,Q)

s1; . . . ← wp(sn−1, wp(sn, Q)) sn−1; ← wp(sn, Q) sn {Q} ↑ verification conditions

slide-40
SLIDE 40

Examples of Verification by WP (1)

Example (Division.)

Verify the partial correctness of the annotated {P} S {Q}, where: P: (x ≥ 0) ∧ (y > 0) Q: (quo ∗ y + rem = x) ∧ (0 ≤ rem < y) Annotated S: quo := 0; rem := x; invariant (quo ∗ y + rem = x) ∧ (0 ≤ rem) ∧ (0 < y) ∧ (x ≥ 0) while y ≤ rem do rem := rem − y; quo := quo + 1 end while

Verification Conditions:

(x ≥ 0) ∧ (y > 0) = ⇒ (x = x) ∧ x ≥ 0 ∧ x ≥ 0 ∧ y > 0 (x = rem + y ∗ quo) ∧ x ≥ 0 ∧ rem ≥ 0 ∧ y > 0 ∧ y ≤ rem = ⇒ (x = (rem − y) + y ∗ (quo + 1)) ∧ x ≥ 0 ∧ rem − y ≥ 0 ∧ y > 0 (x = rem + y ∗ quo) ∧ x ≥ 0 ∧ rem ≥ 0 ∧ y > 0 ∧ y > rem = ⇒ (x = rem + y ∗ quo) ∧ 0 ≤ rem < y

slide-41
SLIDE 41

Examples of Verification by WP (1)

Example (Division.)

Verify the partial correctness of the annotated {P} S {Q}, where: P: (x ≥ 0) ∧ (y > 0) Q: (quo ∗ y + rem = x) ∧ (0 ≤ rem < y) Annotated S: quo := 0; rem := x; invariant (quo ∗ y + rem = x) ∧ (0 ≤ rem) ∧ (0 < y) ∧ (x ≥ 0) while y ≤ rem do rem := rem − y; quo := quo + 1 end while

Verification Conditions:

(x ≥ 0) ∧ (y > 0) = ⇒ (x = x) ∧ x ≥ 0 ∧ x ≥ 0 ∧ y > 0 (x = rem + y ∗ quo) ∧ x ≥ 0 ∧ rem ≥ 0 ∧ y > 0 ∧ y ≤ rem = ⇒ (x = (rem − y) + y ∗ (quo + 1)) ∧ x ≥ 0 ∧ rem − y ≥ 0 ∧ y > 0 (x = rem + y ∗ quo) ∧ x ≥ 0 ∧ rem ≥ 0 ∧ y > 0 ∧ y > rem = ⇒ (x = rem + y ∗ quo) ∧ 0 ≤ rem < y

slide-42
SLIDE 42

Examples of Verification by WP(2)

Example (Cubic Root.)

Verify the partial correctness of the annotated {P} S {Q}, where: P: a ≥ 1 Q:

  • r − 1

2

3 < a ∧

  • r + 1

2)3 > a

Annotated S: x := a; r := q; s := 13/4; invariant (x ≥ 1) ∧ (s = 3r 2 + 1

4) ∧ (2x = 1 2 + 2a − 3 2r + 3r 2 − 2r 3)

while x − s > 0 do x := x − s; s := s + 6 ∗ r + 3; r := r + 1 end while Verification Conditions: a ≥ 1 = ⇒ ( 13

4 = 1 4 + 3) ∧ (2a = 1 2 + 2a − 3 2 + 3 − 2) ∧ a ≥ 1

(x ≥ 1) ∧ (s = 3r 2 + 1

4) ∧ (2x = 1 2 + 2a − 3 2r + 3r 2 − 2r 3) ∧ x − s > 0 =

⇒ (x − s ≥ 1) ∧ (s + 6r + 3 = 3(r + 1)2 + 1

4) ∧

(2(x − s) = 1

2 + 2q − 3 2(r + 1) + 3(r + 1)2 − 2(r + 1)3)

(x ≥ 1) ∧ (s = 3r 2 + 1

4) ∧ (2x = 1 2 + 2a − 3 2r + 3r 2 − 2r 3) ∧ (x − s) ≤ 0 =

  • r − 1

2

3 < a ∧

  • r + 1

2)3 > a

slide-43
SLIDE 43

Examples of Verification by WP(2)

Example (Cubic Root.)

Verify the partial correctness of the annotated {P} S {Q}, where: P: a ≥ 1 Q:

  • r − 1

2

3 < a ∧

  • r + 1

2)3 > a

Annotated S: x := a; r := q; s := 13/4; invariant (x ≥ 1) ∧ (s = 3r 2 + 1

4) ∧ (2x = 1 2 + 2a − 3 2r + 3r 2 − 2r 3)

while x − s > 0 do x := x − s; s := s + 6 ∗ r + 3; r := r + 1 end while Verification Conditions: a ≥ 1 = ⇒ ( 13

4 = 1 4 + 3) ∧ (2a = 1 2 + 2a − 3 2 + 3 − 2) ∧ a ≥ 1

(x ≥ 1) ∧ (s = 3r 2 + 1

4) ∧ (2x = 1 2 + 2a − 3 2r + 3r 2 − 2r 3) ∧ x − s > 0 =

⇒ (x − s ≥ 1) ∧ (s + 6r + 3 = 3(r + 1)2 + 1

4) ∧

(2(x − s) = 1

2 + 2q − 3 2(r + 1) + 3(r + 1)2 − 2(r + 1)3)

(x ≥ 1) ∧ (s = 3r 2 + 1

4) ∧ (2x = 1 2 + 2a − 3 2r + 3r 2 − 2r 3) ∧ (x − s) ≤ 0 =

  • r − 1

2

3 < a ∧

  • r + 1

2)3 > a

slide-44
SLIDE 44

End of Session 1

Slides for session 1 ended here . . .