Formal methods use mathematical proofs to establish that code satisfies a specification across all cases, unlike testing, which samples inputs. A proof validates the code-spec relationship—not whether the specification captures intent. section 8.6
The assurance comes at a cost: writing specifications, learning tools, and constructing proofs can outweigh the bugs they catch. Most projects can rely on less costly verification. section 8.6 section 8.6.5
Consider formal methods when:
- A bug could cause a security vulnerability, financial error, or safety failure. section 8.6.5
- The system has a natural mathematical specification, as with parsers, state machines, or protocols. section 8.6.5
- Subtle bugs persist despite other evaluation, or regulatory requirements demand verification. section 8.6.5
Match verification effort to system criticality: use standard checks for most production features and reserve intensive verification for code where failures are catastrophic. section 8.8.2
