Deductive Program Verification
Deductive verification turns control flow into logical obligations. A loop invariant bridges one-step reasoning and a claim about all executions reaching the exit.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 3
- Reading time
- 1 min
In this article3 chapters
Work backward from the required state
For a deterministic assignment in an idealized language with total expressions, the weakest precondition of a postcondition is substitution.
\[ \operatorname{wp}(x:=e,Q)=Q[e/x]. \]
Sequential composition applies transformers in reverse order. A conditional generates requirements for each branch under the corresponding guard. In a language where expressions may fault or arithmetic is bounded, the generated condition must include these effects. Substitution must also avoid capturing bound variables.
Weakest preconditions calculate assertion changes through straight-line code. An inductive invariant supplies the intermediate claim connecting separate loop iterations.
An invariant deserves a preservation calculation
To sum the integers from zero through one less than a fixed limit \(n\), start \(i=s=0\). The body adds the current index to the sum and increments the index while it is below the limit. Use \(2s=i(i-1)\) together with \(0\le i\le n\). Writing the new state with primes gives
\[ 2s'=2(s+i)=i(i-1)+2i =i(i+1)=i'(i'-1). \]
The initial state satisfies the relation, preservation follows from the calculation, and at exit the bounds and false guard force \(i=n\). Total correctness additionally follows from the strictly decreasing nonnegative variant \(n-i\) on enabled steps.
From one proof to a verification workflow
A verification-condition generator separates initialization, preservation and exit into solver goals. A failed proof can indicate an actual counterexample or an invariant too weak to draw the required conclusion. Abstract interpretation can infer candidate invariants, SMT solving can discharge arithmetic entailments, and separation logic adds local specifications when program state includes dynamically allocated memory.[1][2]