Hoare Triples and Partial Correctness
Read a specification as a relationship between pre-state and post-state, and use a loop invariant to connect the two.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Preconditions fix which runs are in scope
The triple \(\{P\}\,C\,\{Q\}\) asserts that a run of command \(C\) starting in a state satisfying \(P\) ends in one satisfying \(Q\) whenever it terminates. For integers, \(\{x\ge0\}\,x:=x+1\,\{x>0\}\) follows by reasoning about the assigned value. The command may still have behavior outside the precondition. The triple makes no claim there.
At loop exit, combine the invariant with the false guard
To prove a loop correct, show initialization of invariant \(I\), preservation by one body execution under \(I\) and the guard, and that \(I\) with the negated guard implies the postcondition. For a decrementing counter initially nonnegative, invariance of nonnegativity and exit when it is no longer positive imply zero. Add a termination measure to obtain total correctness. Weakest preconditions calculate assertions for several common command shapes.[1][2]