Questions: Hoare Logic

4 questions to test your understanding

Score: 0 / 4
Question 1 Multiple Choice

What does the Hoare triple {x > 0} x := x - 1 {x >= 0} assert?

AIf x > 0 before execution and x := x - 1 terminates, then x >= 0 afterward
BThe program x := x - 1 always terminates with x >= 0
CIf x >= 0 before execution, then x > 0 afterward
DThe assignment x := x - 1 is only valid when x > 0
Question 2 True / False

Hoare logic's rule for assignment is {Q[x/E]} x := E {Q}, where Q[x/E] substitutes E for x in Q. This rule works backward from the postcondition, not forward from the precondition.

TTrue
FFalse
Question 3 Short Answer

What is the difference between partial correctness and total correctness in Hoare logic, and which does the standard Hoare triple {P} C {Q} assert?

Think about your answer, then reveal below.
Question 4 Short Answer

In Hoare logic, the rule of consequence allows strengthening the precondition and weakening the postcondition. Why is this sound?

Think about your answer, then reveal below.