








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 14
This page cannot be seen from the preview
Don't miss anything!









Prepared by
Stephen M. Thebaut, Ph.D.
University of Florida
Software Testing and Verification
Lecture 20
Introduction
Proving strong correctness
Assignment statements
Sequencing
Selection statements --------------------------- 6.
Iteration
wp(while b do S, Q)
1
2
where
0
¬b
1
b^
wp(S, ¬b
2
b^
wp(S, b
wp(S, ¬b
wp(while b do S, Q)
0
1
2
where
0
¬b
1
b^
wp(S,
2
b^
wp(S,
≡i b
wp(S,
i-
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?
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.)
while i <= n do
t := t
∗x
i := i+ end_while
3
b^
wp(S,
i≤n
wp(S, i=n-
t=x
n-
i≤n
i+1=n-
tx=x
n-
i=n-
t=x
n-
k^
b^
wp(S, H
k-
i=n-(k-1)
t=x
n-k
i=n-k+
t=x
n-k
0
i>n
t=x
n
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
0
1
2
(i>n
t=x
n) V (i≤n
t=x
i-
In general, will loops terminate whenP^
wp?
For while loops, does {wp
b} S {wp}?
Does (wp
¬b)
___________________________ wp
weakest
loop invariant which
guarantees termination!
Prepared by
Stephen M. Thebaut, Ph.D.
University of Florida
Software Testing and Verification
Lecture 20