A Hoare triple {P}S{Q} is valid when every run of S from a state satisfying P that terminates ends in a state satisfying Q. Hoare logic derives triples by the rules below, where Q[e/x] is Q with e substituted for x.
- The assignment axiom: {Q[e/x]}x=e{Q}.
- Sequence: from {P}S1{R} and {R}S2{Q}, derive {P}S1;S2{Q}.
- If: from {P∧b}S1{Q} and {P∧¬b}S2{Q}, derive {P}
if b: S1 else: S2 {Q}.
- While: from {I∧b}S{I}, derive {I}
while b: S {I∧¬b}.
- The rule of consequence: from P⇒P′, {P′}S{Q′} and Q′⇒Q, derive {P}S{Q}.