CS FundamentalsVery hardGATE CS

For integer variables, what is the weakest precondition wp(x := x + 1; y := 2 * x, y > 10)?

  1. A. x > 5
  2. B. x > 4
  3. C. x > 9
  4. D. y > 10

Correct answer: B. x > 4

Work backwards: wp(y := 2x, y > 10) is 2x > 10, then substituting x + 1 for x gives 2(x + 1) > 10, i.e. x > 4. x > 5 forgets the increment, and y > 10 just repeats the postcondition, which mentions a variable the assignments overwrite.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic