Question: For each block of code, fill in the intermediate conditions, then use them to state whether the precondition is sufficient to guarantee the postcondition. If

For each block of code, fill in the intermediate conditions, then use them to state whether the precondition is sufficient to guarantee the postcondition. If the precondition is insufficient, explain why. Hint: Use backward reasoning to find the weakest precondition that guarantees the postcondition and see if the given precondition is too weak to guarantee the postcondition. In other words, is the given precondition weaker than the weakest precondition? Remember that if a variable is assigned to somewhere in the code, you might need to use some notation to distinguish between the values before and after assignment, e.g., Ypre and ypost (or Yo-Y, ...). If a variable is never assigned to its pre and post" values are guaranteed to be the same, i.e., for y it would be y = ypre = y post. If subscripts are not given, any variable in the precondition assumes the value "pre", any variable in the postcodition assumes the value "post" Copy all code to your answer file and fill in the blanks. Answers must be expressed in the format wp (expression, condition) = precondition. Show all work. Assume all variables are integers. 1. { *pre Ypre ) W = Yi N = x + y W; XW: { Xpost Ypre A Ypost Sufficient or Insufficient: pre ) 2. [ (x y) V (x + y Ay > 0) } if (x = X = 0; else * Yi (xsy Sufficient or Insufficient: For each block of code, fill in the intermediate conditions, then use them to state whether the precondition is sufficient to guarantee the postcondition. If the precondition is insufficient, explain why. Hint: Use backward reasoning to find the weakest precondition that guarantees the postcondition and see if the given precondition is too weak to guarantee the postcondition. In other words, is the given precondition weaker than the weakest precondition? Remember that if a variable is assigned to somewhere in the code, you might need to use some notation to distinguish between the values before and after assignment, e.g., Ypre and ypost (or Yo-Y, ...). If a variable is never assigned to its pre and post" values are guaranteed to be the same, i.e., for y it would be y = ypre = y post. If subscripts are not given, any variable in the precondition assumes the value "pre", any variable in the postcodition assumes the value "post" Copy all code to your answer file and fill in the blanks. Answers must be expressed in the format wp (expression, condition) = precondition. Show all work. Assume all variables are integers. 1. { *pre Ypre ) W = Yi N = x + y W; XW: { Xpost Ypre A Ypost Sufficient or Insufficient: pre ) 2. [ (x y) V (x + y Ay > 0) } if (x = X = 0; else * Yi (xsy Sufficient or Insufficient
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
