Proofs: Bisection method
These are the human proofs of Bisection method, at full length.
Bisection returns a point within the tolerance of a root, after a known number of steps full
This proof shows: correctness, termination, evaluations.worst.
We work in exact real arithmetic. Let be continuous on with and , and let . Write for the values of after passes of the loop of lines L4 to L11, and . In exact arithmetic the midpoint lies strictly between and , so line L6 never returns.
Invariant (B). After passes that did not return: ; and ; both are nonzero and have opposite signs; and .
Initialization. For , line L1 sets and . Line L2 returns if one is zero, and line L3 returns if they have the same sign. Otherwise (B) holds with .
Maintenance. Assume (B) after passes and that pass does not return. Line L5 sets , so and . Line L8 did not return, so . The signs of and differ, and has one of the two signs. If has the sign of , line L9 sets , , and . Then has the sign of , which is opposite to the sign of . Otherwise has the sign of , and line L10 sets , with the symmetric argument. In both cases the new width is , so (B) holds after passes.
Lemma (a root in the bracket). If (B) holds, then holds a root of .
Proof. is continuous on , and and have opposite signs. By the intermediate value theorem there is with .
Theorem. Let . If , then BISECT returns a point such that some root of in has . It makes at most passes and at most evaluations of . If no end and no midpoint is a root and , it makes exactly passes and evaluations.
Proof. There are four ways to return.
- Line L2 returns or , which is a root, so the error is 0.
- Line L8 returns a midpoint with , a root in .
- Line L11 returns the midpoint of when . By the lemma there is a root , and each point of this interval is within of .
- Line L12 is reached only if passes end without a return.
We show that case 4 does not happen when . If we have . Then the first pass either returns at line L8, or reaches line L11 with width and returns. If , then is the least integer with . By (B) the width after passes is , which is greater than for and at most for . So the test of line L11 fails in passes 1 to and holds in pass , unless line L8 returned earlier. This proves the bound of passes. Each pass evaluates once (line L7), and line L1 evaluates it twice, which gives . When no end and no midpoint is a root, no early return happens, so the counts are exact.
The error of each midpoint. After passes the midpoint of satisfies for a root in the bracket, by (B) and the lemma. This bound halves at each pass. The error itself need not decrease: it can grow from one step to the next when is close to and far from .
Floating point. In floating point, the computed midpoint satisfies when is computed with finite and rounding to nearest, because rounding is monotone. Line L6 returns when equals an end, which happens when and are adjacent numbers. A pass that does not return at line L6 replaces one end by a number strictly between and , so the number of floating-point numbers in falls by at least one. That number is finite, so the loop ends after finitely many passes for every , even when the test of line L11 never holds. The invariant (B) then holds for the computed values in place of , except for the exact width. If on the bracket and both and exceed , the computed signs are the true signs, and the lemma gives a true root in . Otherwise an end of the final bracket lies in the set .