Final answer:
To compute the weakest precondition, we start with the postcondition and work backwards, substituting the variables with their corresponding values in the assignment.
Step-by-step explanation:
To compute the weakest precondition for an assignment statement, we can start by evaluating the condition in the postcondition and substituting the variables with their corresponding values in the assignment. Let's go through each case:
a) a = 2 * b; b = a – 3; {b < 0}
In this case, the weakest precondition would be a = 2 * b - 3;. We start with the postcondition and work backwards, substituting the variables with their corresponding values in the assignment.
b) if (a == b) b = 2 * a; else b = 2 * a; {b > 1}
In this case, since the condition always evaluates to true, we only need to consider the true branch. The weakest precondition would be a == b; b = 2 * a;. Again, we start with the postcondition and work backwards, substituting the variables with their corresponding values in the assignment.