Predicate Transforms II: Proving Termination of While Loops - Prof. Stephen M. Thebaut, Study notes of Engineering

An in-depth explanation of predicate transforms for while loops, including the rules for proving strong correctness and the concept of loop invariants. It includes examples and exercises to help students understand the concepts.

Typology: Study notes

Pre 2010

Uploaded on 03/18/2009

koofers-user-oec-1
koofers-user-oec-1 🇺🇸

10 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Predicate Transforms II
Prepared by
Stephen M. Thebaut, Ph.D.
University of Florida
Software Testing and Verification
Lecture 20
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Predicate Transforms II: Proving Termination of While Loops - Prof. Stephen M. Thebaut and more Study notes Engineering in PDF only on Docsity!

Predicate Transforms II

Prepared by

Stephen M. Thebaut, Ph.D.

University of Florida

Software Testing and Verification

Lecture 20

Predicate Transforms I and II^ 1.

Introduction

Proving strong correctness

Assignment statements

Sequencing

Selection statements --------------------------- 6.

Iteration

Rule for while_do Statement (cont’d)^ Thus, we can write

wp(while b do S, Q)

H
V 0
H

1

V
H

2

V…

where

H

0

≡^

¬b

Q
H

1

≡^

b^

wp(S, ¬b

Q)
H

2

≡^

b^

wp(S, b

wp(S, ¬b

Q))

Rule for while_do Statement (cont’d)^ Equivalently, we can write

wp(while b do S, Q)

H

0

V^
H

1

V
H

2

V…

where

H

0

≡^

¬b

Q
H

1

≡^

b^

wp(S,

H
H

2

≡^

b^

wp(S,

H
H

≡i b

wp(S,

H

i-

Example^ •^

For what initial values of i, n, and t willthe following program terminate witht=x

n?

while i <= n do

t := t

∗x

i := i+ end_while

How about i=1, n=2, and t=1?

Can

you think of any others?

Example (cont’d)^ •^

Find the wp of this program with respectto the post-condition

{t=x

n}.

(Attempt

to find a regularity in terms that allows aclosed-form expression.)

Example (cont’d)

while i <= n do

t := t

∗x

i := i+ end_while

H

3

≡^

b^

wp(S,

H

i≤n

wp(S, i=n-

t=x

n-

i≤n

i+1=n-

tx=x

n-

i=n-

t=x

n-

H

k^

≡^

b^

wp(S, H

k-

i=n-(k-1)

t=x

n-k

i=n-k+

t=x

n-k

Example (cont’d)^ Thus, we have:

H

0

i>n

t=x

n

H

k^

i=n-k+

t=x

n-k

(for all k>0)

i≤n

t=x

i-

since i=n-k+

n-k=i-

Therefore, wp

H

0

V^
H

1

V
H

2

V ...

(i>n

t=x

n) V (i≤n

t=x

i-

Loop Invariants and wp’s^ •^

In general, will loops terminate whenP^

wp?

•^

For while loops, does {wp

b} S {wp}?

•^

Does (wp

¬b)

Q?

___________________________ wp

weakest

loop invariant which

guarantees termination!

Predicate Transforms II

Prepared by

Stephen M. Thebaut, Ph.D.

University of Florida

Software Testing and Verification

Lecture 20