Hoare Logic

Rules

Assignment rule

\Hoare⁒P⁒[E/x]⁒x:=E⁒Pabsentassign\Hoare𝑃delimited-[]𝐸π‘₯π‘₯𝐸𝑃\par\frac{}{\Hoare{{P}[E/x]}{x:=E}{P}}

If rule

\HoareP∧⟦b⟧c1Q\HoareP∧¬⟦b⟧c2Q\Hoare⁒P⁒𝗂𝖿⁒b⁒𝗍𝗁𝖾𝗇⁒c1β’π–Ύπ—…π—Œπ–Ύβ’c2⁒Q\par\frac{\Hoare{P\land\llbracket{b}\rrbracket}{c_{1}}{Q}\qquad\Hoare{P\land% \lnot\llbracket{b}\rrbracket}{c_{2}}{Q}}{\Hoare{P}{\mathsf{if}\;b\;\mathsf{% then}\;c_{1}\mathsf{else}\;c_{2}}{Q}}

While Rule

The Partial Correctness rule for while loops is the following, where Ο• italic-Ο• \phi is the loop invariant.

Pβ‡’Ο•\HoareΟ•βˆ§βŸ¦e⟧cΟ•Ο•βˆ§Β¬βŸ¦eβŸ§β‡’Q\Hoare⁒P⁒𝗐𝗁𝗂𝗅𝖾⁒eβ’π–½π—ˆβ’c⁒Q\par\frac{P\Rightarrow\phi\qquad\Hoare{\phi\land\llbracket{e}\rrbracket}{c}{% \phi}\qquad{\phi\land\lnot\llbracket{e}\rrbracket}\Rightarrow{Q}}{\Hoare{P}{% \mathsf{while}\;e\;\mathsf{do}\;c}{Q}}

For total correctness, we need to add a variant alongside our loop invariant; this is some Well-Founded Relation that we need to ensure strictly decreases on every iteration, and also add conditions that ensure that evaluating the loop body and loop guard dont crash.