Weakest Preconditions for Assignments and Sequences
Calculate a necessary and sufficient precondition for a straight-line program by propagating the desired postcondition backward.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Substitute the assigned expression for the new variable
For integer assignment \(x:=e\) with a total expression, the weakest precondition for \(Q\) substitutes \(e\) into the free occurrences of \(x\) in \(Q\). For \(x:=x+1\) and postcondition \(x<8\), the condition before assignment is \(x+1<8\), equivalently \(x<7\). It includes every start for which the desired result holds.
A sequence is composed from the end
Take \(x:=x+1\) followed by \(y:=2x\) and require \(y\le10\). The second assignment needs \(2x\le10\). Pulling that through the first requires \(2(x+1)\le10\), or \(x\le4\). Conditional commands use branch guards to restrict which preconditions must hold. General loops may need separate invariants and termination proofs, as in Hoare logic. Deductive program verification combines these steps into verification conditions that can be proved independently.[1][2]