Hoare logic proves properties of programs through Hoare triples . A precondition constrains initial states and a postcondition constrains returned states. The basic rules establish partial correctness; termination requires a further argument.[ref]
For a program expression whose evaluation is defined and has no side effects, the assignment rule isThe substitution replaces the free occurrences of in the desired postcondition. For example, obtaining after
x := x+1 requires beforehand, so suffices. Integer overflow must be excluded or handled by the stated arithmetic model.Sequential composition joins a first postcondition to the next precondition. For a while loop, proving establishesHere is the loop invariant. For
while x > 0 do x := x-1, starting with an exact nonnegative integer, is preserved and the false exit guard yields . The decreasing nonnegative integer is also a loop variant, establishing total correctness for this example.[ref]A partial correctness claim connecting a precondition , a program and a postcondition : every terminating execution begun with ends with . State separately whether total correctness is intended.
Articles by others on the same topic
There are currently no matching articles.