Title: Predicate Transforms I
1Predicate Transforms I
Software Testing and Verification Lecture 19
- Prepared by
- Stephen M. Thebaut, Ph.D.
- University of Florida
2Predicate Transforms I and II
- Introduction
- Proving strong correctness
- Assignment statements
- Sequencing
- Selection statements
- ---------------------------
- Iteration
3Introduction
- What are Predicate Transforms?
- An extension of axiomatic verification. Rules
are provided for transforming post-conditions
into weakest pre-conditions with respect to
various program constructs.
4Introduction (contd)
- What is a weakest pre-condition?
- It is the necessary pre-condition for program S
to terminate in state Q. - It is denoted wp(S,Q) and read, the weakest
pre-condition of S with respect to Q.
5Proving Strong Correctness
- To prove P S Q and to prove that P implies
that S will terminate, show that - P ? wp(S,Q)
- We now consider rules for computing weakest
pre-conditions for structured programs comprised
of assignment statements, if-then (-else)
statements, and while loops.
6Rule for Assignment Statements
- Rule
- wp(xE, Q(x,y,z)) ? Q(E,y,z)
7Rule for Assignment Statements
- Rule
- wp(xE, Q(x,y,z)) ? Q(E,y,z)
- Examples
- wp(xy3, xgt0)
8Rule for Assignment Statements
- Rule
- wp(xE, Q(x,y,z)) ? Q(E,y,z)
- Examples
- wp(xy3, xgt0)
-
- wp(xx1, x?n1)
9Rule for Assignment Statements
- Rule
- wp(xE, Q(x,y,z)) ? Q(E,y,z)
- Examples
- wp(xy3, xgt0)
-
- wp(xx1, x?n1)
-
- wp(x7, x7)
10Rule for Assignment Statements
- Rule
- wp(xE, Q(x,y,z)) ? Q(E,y,z)
- Examples (contd)
- wp(x7, x6)
11Rule for Assignment Statements
- Rule
- wp(xE, Q(x,y,z)) ? Q(E,y,z)
- Examples (contd)
- wp(x7, x6)
-
- wp(x7, y7)
12Rule for Assignment Statements
- Rule
- wp(xE, Q(x,y,z)) ? Q(E,y,z)
- Examples (contd)
- wp(x7, x6)
-
- wp(x7, y7)
- wp(y-x, yx)
13Rule for Sequencing
- Rule
- wp(S1S2...Sn-1Sn, Q) ?
- wp(S1, wp(S2,...wp(Sn-1, wp(Sn, Q))))
-
14Rule for Sequencing (contd)
- Example
- wp(CD1 BC?2 AB??2, A36)
15Rule for Sequencing (contd)
- Example
- wp(CD1 BC?2 AB??2, A36)
16Rule for Sequencing (contd)
- Example
- wp(CD1 BC?2 AB??2, A36)
17Rule for if-then-else Statement
- Rule
- wp(if b then S1 else S2, Q) ?
- (b ? wp(S1, Q)) V (b ? wp(S2, Q))
18Rule for if-then-else Statement
- Rule
- wp(if b then S1 else S2, Q) ?
- (b ? wp(S1, Q)) V (b ? wp(S2, Q))
T
F
b
S2
S1
Q
19Rule for if-then-else Statement
- Rule
- wp(if b then S1 else S2, Q) ?
- (b ? wp(S1, Q)) V (b ? wp(S2, Q))
T
F
b
b ? wp(S1, Q))
S2
S1
Q
20Rule for if-then-else Statement
- Rule
- wp(if b then S1 else S2, Q) ?
- (b ? wp(S1, Q)) V (b ? wp(S2, Q))
T
F
b
b ? wp(S1, Q))
b ? wp(S2, Q))
S2
S1
Q
21Rule for if-then-else Statement (contd)
- Example
- wp(if xlt0 then y-x else yx, yx)
-
22Rule for if-then Statement
- Rule
- wp(if b then S, Q) ?
- (b ? wp(S, Q)) V (b ? Q)
23Rule for if-then Statement
- Rule
- wp(if b then S, Q) ?
- (b ? wp(S, Q)) V (b ? Q)
T
b
F
S
Q
24Rule for if-then Statement
- Rule
- wp(if b then S, Q) ?
- (b ? wp(S, Q)) V (b ? Q)
T
b
b ? wp(S, Q))
F
S
Q
25Rule for if-then Statement
- Rule
- wp(if b then S, Q) ?
- (b ? wp(S, Q)) V (b ? Q)
T
b
b ? wp(S, Q))
F
S
b ? Q
Q
26Rule for if-then Statement (contd)
- Example
- wp(if xlt0 then y-x, yx)
27Exercise
- Prove the assertion below using the predicate
transform based approach. - ZB if AgtB then Z A ZMax(A,B)
28Exercise
- Prove the assertion below using the predicate
transform based approach. - ZB if AgtB then Z A ZMax(A,B)
P
S
Q
29Exercise
- Prove the assertion below using the predicate
transform based approach. - ZB if AgtB then Z A ZMax(A,B)
- Hint
- Compute the wp(S,Q)
- Show that P ? wp(S,Q)
P
S
Q
30Predicate Transforms I
Software Testing and Verification Lecture 19
- Prepared by
- Stephen M. Thebaut, Ph.D.
- University of Florida