Definition
Total Correctness
A program is totally correct with respect to a precondition and a postcondition if it is partially correct and guaranteed to terminate for all inputs satisfying .
In Hoare notation, this is sometimes denoted using square brackets:
Formal Semantics
A triple is totally correct if for all states :
Verification
Proving total correctness is generally more difficult than proving partial correctness because it requires an additional proof of termination.
- Partial Correctness: Proven using standard Hoare calculus rules and invariants.
- Termination: Proven by identifying a loop variant (or termination function)—a mapping from the program state to a well-founded set (typically the natural numbers ) that strictly decreases with each iteration.
Non-Determinism
For non-deterministic programs, total correctness requires that all possible execution paths terminate and satisfy the postcondition.