Loops and Termination
CS 536, Mon Nov 1, 2010
Version 1.1, Nov 28: Colored solutions red; cleaned up Activity 9.2 Question 2.
Activity 9.1: Expanding Proof Outlines for Loops
A. Why?
•
Loops are ubiquitous, so it’s useful to see examples of proving them correct.
B. Outcomes
At the end of this activity you should:
•
Be able to expand partial proof outlines for simple loops.
C. Questions
1.
Give a fully expanded proof outline for the following program (the downgoing
summation loop):
{
n
≥
0
}
j := n; s := n;
{
inv
0
≤
j
≤
n
∧
s = sum(j, n)
}
while
j
≠
0
do
s := s+j1;
j := j1
od
{
s = sum(0, n)
}
Expanded outline:
{
n
≥
0
}
j := n;
{
n
≥
0
∧
j = n
}
s := n;
{
n
≥
0
∧
j = n
∧
s = n
}
{
inv
0
≤
j
≤
n
∧
s = sum(j, n)
}
while
j
≠
0
do {0
≤
j
≤
n
∧
s = sum(j, n)
∧
j
≠
0}
{0
≤
j1
≤
n
∧
s+j1 = sum(j1, n)}
s := s+j1;
{0
≤
j1
≤
n
∧
s = sum(j1, n)}
j := j1
{0
≤
j
≤
n
∧
s = sum(j, n)}
od
{
s = sum(0, n)
}
Illinois Institute of Technology
Activities for Lecture 9
CS 536: Science of Programming
 1 of 3 
© James Sasaki, 2010
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document2.
Give a fully expanded proof outline for the alternate binsearch (version 2) loop body.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 cs536
 Illinois Institute of Technology, Science of Programming, James Sasaki, bound function, fully expanded proof

Click to edit the document details