
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























Software Testing and Verification
Prepared by
Stephen M. Thebaut, Ph.D.
University of Florida
Given
= if x>=y then x,y := y,x f^1
= (x>y
x,y := y,x | true
f^2
= (x>y
x,y := y,x | x<y
f^
= (x
≠y
x,y := y,x)
“Identity” function:
x,y := x,y
f^3
= (x
≠y
x,y := y,x)
Fill in the following “correctness table”:
f^1 f^2
P f^3
C=CompleteS=SufficientN=Neither
Prove
f
P] where
f^ = (x=
x,y := 17,20 |
true
x,y := x,-x)
and
is:
if x= 17 then
y := x+ else
y := -x end_if_else
Complete correctness conditions for
f^ = [if
p
then
else
where
g
] and
h
] have been shown:
Prove:
p^
(f
g
Prove:
p^
(f
g
¬p
(f
h
Working correctness questions:^ – When
p
is
true,
does
f equal
g
p
is
false,
does
f equal
h
f^ = (x=
x,y := 17,20 | true
x,y := x,-x)
if x=17 then
y := x+
elseelse
y := -x
end_if_else
By observation,
g
= x,y := x,x+3 h^ = x,y := x,-x
Therefore, by the Axiom of Replacement, it issufficient to show: f^ = (x=
x,y := 17,20 | true
x,y := x,-x)
= [if
p
then
(x,y := x,x+3)
else
(x,y := x,-x)
When
p
is
true
does
f equal
g
g^
h
(x=17) When
p
is
true
does
f equal
g
(x=17)
f =
(x,y := 17,20))
(x=17)
g^
= (x,y := x,x+3)
= (x,y := 17,20))
When
p
is
false
does
f equal h?
(x≠17)
(f
= (x,y := x,-x))
(x≠17)
h^
= (x,y := x,-x))
For program
below, where all variables are
integers, hypothesize a function
f for [
P] and
prove
f
while i<n do
t := t
∗x
i := i+1i := i+ end_while
Hypothesized
f:
(i<n
i,t := n,tx
n-i
| i≥n
Alternative
f : (i≤n
i,t := n,tx
n-i
| i>n
Does it make any difference which we use?
Complete correctness conditions for
f^ = [while
p
do
g
where
g
] has been shown:
Prove:Prove:
term
(f,P)
p^
(f
f o
g
p^
(f
n-i
n-i
p
Is loop termination guaranteed for anyargument of
f
(Show this using the Method of
Well-Founded Sets.)
Does (i≥n)
f
Does (i<n)
f
f o
g
(i<n)
f
n-i
(i<n)
f o
g
f o
(i<n)
f o
g
f o
What is
f when applied after
g
changes the
initial value of
i?
There are two cases to consider:
i=n-
i<n-
( Recall:
f
n-i
Does (i<n)
f
f o
g
(i<n)
f
n-i
(i<n)
f o
g
f o
case a:
(i=n-1)
f o
g
o
o
o
o
n-i
n-i
For program
below, where all variables
are integers, hypothesize a function
r
for
] and prove
r
repeat:repeat:
x := x−1y := y+ until x=
For program
below, where all variables
are integers, hypothesize a function
r
for
] and prove
r
repeat:repeat:
x := x−1y := y+ until x=
Hypothesized
r:
(x>
x,y := 0,y+2x)