27
1. Determine the following weakest pre- conditions. a. wp(paint the living room ceiling, the house is all painted)

1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

Embed Size (px)

Citation preview

Page 1: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

1. Determine the following weakest pre-conditions.

a. wp(paint the living room ceiling, the house is all painted)

Page 2: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

1. Determine the following weakest pre-conditions.

a. wp(paint the living room ceiling, the house is all painted)

= The whole house, except for the living

room ceiling, is all painted.

Page 3: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

1. Determine the following weakest pre-conditions.

a. wp(paint the living room ceiling, the house is all painted)

= The whole house, except for the living

room ceiling, is all painted.

Page 4: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

1. Determine the following weakest pre-conditions.

a. wp(paint the living room ceiling, the house is all painted)

= The whole house, except POSSIBLY for the living

room ceiling, is all painted. (The living room

ceiling may or may not be all painted!)

Page 5: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

1. Determine the following weakest pre-conditions.

a. wp(paint the living room ceiling, the house is all painted)

= The whole house, except POSSIBLY for the living

room ceiling, is all painted. (The living room

ceiling may or may not be all painted!)

(Compare this with: wp(A := true, A Л B Л C Л D )

= true Л B Л C Л D = B Л C Л D (A may be true or false)

where “parts of the house” are A, B, C, and D, and

(X = true) “part X is painted.”)

Page 6: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

Page 7: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

= A[j-1] is the smallest element in A[1], A[2], ..., A[j-1]

Page 8: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

= A[j-1] is the smallest element in A[1], A[2], ..., A[j-1]

c. wp(k := 5; x := 2*y; y := x-4, wy = z+x)

Page 9: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

= A[j-1] is the smallest element in A[1], A[2], ..., A[j-1]

c. wp(k := 5; x := 2*y; y := x-4, wy = z+x)

Page 10: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

= A[j-1] is the smallest element in A[1], A[2], ..., A[j-1]

c. wp(k := 5; x := 2*y; y := x-4, wy = z+x)

= wp(k := 5; x := 2*y, w(x-4) = z+x)

Page 11: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

= A[j-1] is the smallest element in A[1], A[2], ..., A[j-1]

c. wp(k := 5; x := 2*y; y := x-4, wy = z+x)

= wp(k := 5; x := 2*y, w(x-4) = z+x)

Page 12: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

= A[j-1] is the smallest element in A[1], A[2], ..., A[j-1]

c. wp(k := 5; x := 2*y; y := x-4, wy = z+x)

= wp(k := 5; x := 2*y, w(x-4) = z+x)= wp(k := 5, w(2y-4) = z+2y)

Page 13: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

= A[j-1] is the smallest element in A[1], A[2], ..., A[j-1]

c. wp(k := 5; x := 2*y; y := x-4, wy = z+x)

= wp(k := 5; x := 2*y, w(x-4) = z+x)= wp(k := 5, w(2y-4) = z+2y)

Page 14: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

= A[j-1] is the smallest element in A[1], A[2], ..., A[j-1]

c. wp(k := 5; x := 2*y; y := x-4, wy = z+x)

= wp(k := 5; x := 2*y, w(x-4) = z+x)= wp(k := 5, w(2y-4) = z+2y)= w(2y-4) = z+2y

Page 15: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

= A[j-1] is the smallest element in A[1], A[2], ..., A[j-1]

c. wp(k := 5; x := 2*y; y := x-4, wy = z+x)

= wp(k := 5; x := 2*y, w(x-4) = z+x)= wp(k := 5, w(2y-4) = z+2y)= w(2y-4) = z+2y

d. wp(if x is even then x := x+1, x = 9)

Page 16: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

= A[j-1] is the smallest element in A[1], A[2], ..., A[j-1]

c. wp(k := 5; x := 2*y; y := x-4, wy = z+x)

= wp(k := 5; x := 2*y, w(x-4) = z+x)= wp(k := 5, w(2y-4) = z+2y)= w(2y-4) = z+2y

d. wp(if x is even then x := x+1, x = 9)

= (x is even Л x=8) V (x is odd Л x=9)

Page 17: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

b. wp(i := j-1, A[i] is the smallest element in A[1], A[2], ..., A[i])

= A[j-1] is the smallest element in A[1], A[2], ..., A[j-1]

c. wp(k := 5; x := 2*y; y := x-4, wy = z+x)

= wp(k := 5; x := 2*y, w(x-4) = z+x)= wp(k := 5, w(2y-4) = z+2y)= w(2y-4) = z+2y

d. wp(if x is even then x := x+1, x = 9)

= (x is even Л x=8) V (x is odd Л x=9) = (x=8 V x=9)

Page 18: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

2. Consider the assertion: {Z=B}  if A>B then Z := A end_if

{Z=Max(A,B)} 

Use the WEAKEST PRECONDITION-BASED METHOD to prove the assertion. Show all steps.

Page 19: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

2. Consider the assertion: {Z=B}  if A>B then Z := A end_if

{Z=Max(A,B)} 

Use the WEAKEST PRECONDITION-BASED METHOD to prove the assertion. Show all steps.

We need to show P => wp(S,Q).

Page 20: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

2. Consider the assertion: {Z=B}  if A>B then Z := A end_if

{Z=Max(A,B)} 

Use the WEAKEST PRECONDITION-BASED METHOD to prove the assertion. Show all steps.

We need to show P => wp(S,Q).

wp(S,Q) = wp(if A>B then Z := A end_if, Z=Max(A,B))

Page 21: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

2. Consider the assertion: {Z=B}  if A>B then Z := A end_if

{Z=Max(A,B)} 

Use the WEAKEST PRECONDITION-BASED METHOD to prove the assertion. Show all steps.

We need to show P => wp(S,Q).

wp(S,Q) = wp(if A>B then Z := A end_if, Z=Max(A,B)) = (A>B Л wp(Z := A, Z=Max(A,B)) V (A≤B Л

Z=Max(A,B))

Page 22: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

2. Consider the assertion: {Z=B}  if A>B then Z := A end_if

{Z=Max(A,B)} 

Use the WEAKEST PRECONDITION-BASED METHOD to prove the assertion. Show all steps.

We need to show P => wp(S,Q).

wp(S,Q) = wp(if A>B then Z := A end_if, 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))

Page 23: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

2. Consider the assertion: {Z=B}  if A>B then Z := A end_if

{Z=Max(A,B)} 

Use the WEAKEST PRECONDITION-BASED METHOD to prove the assertion. Show all steps.

We need to show P => wp(S,Q).

wp(S,Q) = wp(if A>B then Z := A end_if, 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) V (A≤B Л Z=B)

Page 24: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

2. Consider the assertion: {Z=B}  if A>B then Z := A end_if

{Z=Max(A,B)} 

Use the WEAKEST PRECONDITION-BASED METHOD to prove the assertion. Show all steps.

Does Z=B => [(A>B) V (A≤B Л Z=B)] ?

Page 25: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

2. Consider the assertion: {Z=B}  if A>B then Z := A end_if

{Z=Max(A,B)} 

Use the WEAKEST PRECONDITION-BASED METHOD to prove the assertion. Show all steps.

Does Z=B => [(A>B) V (A≤B Л Z=B)] ?

Z=B => { [(A>B) V (A≤B Л Z=B)]= [(A>B) V (A≤B Л true)] }

Page 26: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

2. Consider the assertion: {Z=B}  if A>B then Z := A end_if

{Z=Max(A,B)} 

Use the WEAKEST PRECONDITION-BASED METHOD to prove the assertion. Show all steps.

Does Z=B => [(A>B) V (A≤B Л Z=B)] ? 

Z=B => { [(A>B) V (A≤B Л Z=B)]= [(A>B) V (A≤B Л true)]= [(A>B) V (A≤B)] }

Page 27: 1.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)

2. Consider the assertion: {Z=B}  if A>B then Z := A end_if

{Z=Max(A,B)} 

Use the WEAKEST PRECONDITION-BASED METHOD to prove the assertion. Show all steps.

Does Z=B => [(A>B) V (A≤B Л Z=B)] ?  

Z=B => { [(A>B) V (A≤B Л Z=B)]= [(A>B) V (A≤B Л true)]= [(A>B) V (A≤B)]

= true }