Proving a Function by Cases
A case proof covers the legal input domain with cases and shows that the contract holds for every case.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Check absolute value
For an integer \(x\), when \(x\ge0\), output x. When \(x<0\), output \(-x\). Each output is nonnegative, and both together cover all ordinary mathematical integers. Absolute value and signed calculations discuss representable limits.
Confirm each case matches execution
A fixed-width implementation may need a separate rule for its minimum value because the positive counterpart does not fit. Boundary tests help ensure the proof's mathematical cases correspond to the actual representation.[1]
Verify the boundary falls into one of the chosen cases
For \(f(x)=|x|\), the cases \(x\ge0\) and \(x<0\) cover all real inputs and do not overlap. In the first case the result equals the nonnegative input. In the second it equals its negation, which is positive. See exhaustive conditions.
x = -3 → second case → 3
x = 0 → first case → 0
x = 4 → first case → 4
Keep proof claims limited to the actual number model
On a fixed-width signed machine, the absolute value of the smallest representable integer may be outside that same signed range. A proof over real numbers cannot establish a same-type result for every machine integer. Check that the implementation models the domain assumed by the proof.