Docsity

Exercise Solutions: Functional Verification - Software Testing and Verification - Prof. St, Study notes of Engineering

Partial preview of the text

Download Exercise Solutions: Functional Verification - Software Testing and Verification - Prof. St and more Study notes Engineering in PDF only on Docsity!

Exercise Solutions: Functional

Verification

Software Testing and Verification

Prepared by

Stephen M. Thebaut, Ph.D.

University of Florida

Exercise •^

Given

P^

= if x>=y then x,y := y,x f^1

= (x>y

x,y := y,x | true

I

f^2

= (x>y

x,y := y,x | x<y

I

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

Exercise •^

Prove

f

= [

P] where

f^ = (x=

x,y := 17,20 |

true

x,y := x,-x)

and

P

is:

if x= 17 then

y := x+ else

y := -x end_if_else

if_then_else Correctness Conditions •^

Complete correctness conditions for

f^ = [if

p

then

G

else

H

]

where

g

= [

G

] and

h

= [

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

  • When

p

is

false,

does

f equal

h

Proof that

f^

= [

P

]

f^ = (x=

x,y := 17,20 | true

x,y := x,-x)

P:

if x=17 then

y := x+

G

elseelse

y := -x

H

end_if_else

By observation,

g

= x,y := x,x+3 h^ = x,y := x,-x

Proof that

f^

= [

P

] (cont’d)

•^

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))

Exercise •^

For program

P

below, where all variables are

integers, hypothesize a function

f for [

P] and

prove

f

= [

P].

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

I)

Alternative

f : (i≤n

i,t := n,tx

n-i

| i>n

I)

Does it make any difference which we use?

while_do Correctness Conditions •^

Complete correctness conditions for

f^ = [while

p

do

g

]

where

g

= [

G

] has been shown:

Prove:Prove:

term

(f,P)

p^

(f

f o

g

p^

(f

I

Proof that

f^

= [

P

]

f^

= (i<n

i,t := n,tx

n-i

| i≥n

I)

P:

while i<n do

t := t

∗x

i := i+1i := i+

end_while

Proof that

f^

= [

P

]

f^

= (i<n

i,t := n,tx

n-i

| i≥n

I)

P:

while i<n do

t := t

∗x

i := i+

G

p

i := i+

end_while

By observation,

g

= [

G

] = (i,t := i+1,tx)

•^

Is loop termination guaranteed for anyargument of

f

(Show this using the Method of

Well-Founded Sets.)

G

Proof that

f^

= [

P

] (cont’d)

•^

Does (i≥n)

f

I

•^

Does (i<n)

f

f o

g

(i<n)

f

i,t := n,tx

n-i

(i<n)

f o

g

f o

(i,t := i+1,tx)

(i<n)

f o

g

f o

(i,t := i+1,tx)

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

(i<n

i,t := n,tx

n-i

| i≥n

I)

Proof that

f^

= [

P

] (cont’d)

•^

Does (i<n)

f

f o

g

(i<n)

f

i,t := n,tx

n-i

(i<n)

f o

g

f o

(i,t := i+1,tx) )

case a:

(i=n-1)

f o

g

I

o

(i,t := i+1,tx)

I

o

(i,t := n-1+1,tx)

I

o

(i,t := n,tx

I

o

(i,t := n,tx

n-i

(i,t := n,tx

n-i

f

Exercise •^

For program

R

below, where all variables

are integers, hypothesize a function

r

for

[R

] and prove

r

= [

R

].

repeat:repeat:

x := x−1y := y+ until x=

Exercise •^

For program

R

below, where all variables

are integers, hypothesize a function

r

for

[R

] and prove

r

= [

R

].

repeat:repeat:

x := x−1y := y+ until x=

Hypothesized

r:

(x>

x,y := 0,y+2x)