Docsity

Proving a Predicate Transform using if-else statement, Study notes of Software Engineering

Toggle sidebar
bg1
Exercise from Predicate Transform Lecture Notes:
Prove the assertion below using the predicate transform based approach.
{Z=B} if A>B then Z := A {Z=Max(A,B)}
Idea: Show P => wp(S, Q)
oStep 1: compute wp(S,Q)
oStep 2: show P is stronger (implies this)
Step 1:
wp ( if A>B then Z := A, Z=Max(A,B))
= (A>B Л wp(Z := A, Z=Max(A,B) )) V
(A≤B Л Z=Max(A,B))
= (A>B Л A=Max(A,B))) V
(A≤B Л Z=Max(A,B) )
= (A>B Л A≥B )) V (A≤B Л Z=Max(A,B))
= (A>B) V (A≤B Л Z=Max(A,B))
Step 2:
Does Z=B => (A>B) V (A≤B Л Z=Max(A,B)) ?
Note that either A>B or A≤B MUST be true.
Case 1: Suppose A>B. Then the question above reduces to:
Does (Z=B Л A>B) => (A>B) V (A≤B Л Z=Max(A,B)) ?
Yes, Mon!
Case 2: Suppose A≤B . Then the question above reduces to:
Does (Z=B Л A≤B) => (A>B) V (A≤B Л Z=Max(A,B)) ?
= (A≤B Л Z=Max(A,B))
= (A≤B Л Z=B)
Yes, Mon!
Therefore, Does Z=B => (A>B) V (A≤B Л Z=Max(A,B))

Partial preview of the text

Download Proving a Predicate Transform using if-else statement and more Study notes Software Engineering in PDF only on Docsity!

Exercise from Predicate Transform Lecture Notes:

 Prove the assertion below using the predicate transform based approach.  {Z=B} if A>B then Z := A {Z=Max(A,B)}  Idea: Show P => wp(S, Q) o Step 1: compute wp(S,Q) o Step 2: show P is stronger (implies this) Step 1: wp ( if A>B then Z := A, Z=Max(A,B)) = (A>B Л wp(Z := A, Z=Max(A,B) )) V (A≤B Л Z=Max(A,B)) = (A>B Л A=Max(A,B))) V (A≤B Л Z=Max(A,B) ) = (A>B Л A≥B )) V (A≤B Л Z=Max(A,B)) = (A>B) V (A≤B Л Z=Max(A,B)) Step 2: Does Z=B => (A>B) V (A≤B Л Z=Max(A,B))? Note that either A>B or A≤B MUST be true. Case 1: Suppose A>B. Then the question above reduces to: Does (Z=B Л A>B) => (A>B) V (A≤B Л Z=Max(A,B))? Yes, Mon! Case 2: Suppose A≤B. Then the question above reduces to: Does (Z=B Л A≤B) => (A>B) V (A≤B Л Z=Max(A,B))? = (A≤B Л Z=Max(A,B)) = (A≤B Л Z=B) Yes, Mon! Therefore, Does Z=B => (A>B) V (A≤B Л Z=Max(A,B))