Proving Programs Examples Prove each of the following code segments are correct by backing up the postcondition to get an appropriate precondition 1. read(x); x := x * x; x := x * x; x := x * x; write(x); { output = input ^ 8 } 2. read(x); if (x < 0) then x := 0 - x write(x); { output >= 0 and (output = input or output = 0 - input} 3. read(x); res := 1; while (x > 0) do BEGIN res := res * 2; x := x - 1; END; write(res); { output = 2^input } 4. read(x); read(y); res := 0; while (y > 0) do BEGIN res := res + x; y := y - 1; END; write(res); { output = input1 * input2 } 5. This one is a little tricky ... You can assume that all variables are integers. read(x); res := 0; y := 0 while (x > y) do BEGIN y := y + 1; res := res + y; END; write(res); { output = input * (input + 1) / 2 }