Unit 8, lesson 57

Numerical conditioning and root finding

How the conditioning of an equation differs from the stability of an algorithm, why floating-point cancellation loses digits, and when bisection and Newton's method converge, quadratically or not at all.

  • Video 57
  • Root finding, Monte Carlo and discretization

An implied volatility is the root of an equation, the volatility at which a model price matches a quote. A solver can print it to sixteen digits, but how many of them does the quote actually determine, and how many can the arithmetic deliver? The first question is about the equation, the second about the algorithm and the floating-point numbers it works with. This lesson separates conditioning from stability, shows how subtracting nearly equal numbers destroys digits, derives the error bound of bisection and the local quadratic convergence of Newton’s method, and gives a cubic on which Newton’s method cycles forever.

Key terms

Problem conditioning

Definition Let ff be continuously differentiable on an open interval containing a root x∗x_* of the equation f(x)=bf(x) = b, and suppose f′(x∗)≠0f'(x_*) \ne 0. By the inverse function theorem, for data b~\tilde b near bb the equation f(x)=b~f(x) = \tilde b has a unique solution x(b~)x(\tilde b) near x∗x_*, and

dxdb=1f′(x∗).\frac{dx}{db} = \frac{1}{f'(x_*)} .

The absolute condition number of the root is κabs=1/∣f′(x∗)∣\kappa_{\text{abs}} = 1/\lvert f'(x_*) \rvert. When b≠0b \ne 0 and x∗≠0x_* \ne 0, the relative condition number is

κrel=∣bx∗ f′(x∗)∣.\kappa_{\text{rel}} = \left\lvert \frac{b}{x_* \, f'(x_*)} \right\rvert .

To first order a change Δb\Delta b in the data moves the root by Δx≈Δb/f′(x∗)\Delta x \approx \Delta b / f'(x_*), so ∣Δx∣≈κabs∣Δb∣\lvert \Delta x \rvert \approx \kappa_{\text{abs}} \lvert \Delta b \rvert and ∣Δx/x∗∣≈κrel∣Δb/b∣\lvert \Delta x / x_* \rvert \approx \kappa_{\text{rel}} \lvert \Delta b / b \rvert. Conditioning is a property of the problem, the map from data to solution, and it is defined in exact arithmetic before any algorithm is chosen. Which of the two numbers is informative depends on how the uncertainty in the data is measured.

In plain words The condition number is the factor by which an error in the data is amplified in the answer, even when every calculation is exact. Where the function is flat at the root, a small change in the target slides the root a long way.

Example For x2=2x^2 = 2 the root is x∗=2x_* = \sqrt{2} and f′(x∗)=22f'(x_*) = 2\sqrt{2}, so dx/db=1/(22)≈0.353553dx/db = 1/(2\sqrt{2}) \approx 0.353553 and κrel=2/(2⋅22)=1/2\kappa_{\text{rel}} = 2/(\sqrt{2} \cdot 2\sqrt{2}) = 1/2. A relative error of 10−610^{-6} in the target moves the root by a relative amount of about 5×10−75 \times 10^{-7}. For an implied volatility the data is a call price CC, the function is the Black-Scholes price σ↦C(σ)\sigma \mapsto C(\sigma), and its derivative is the vega ∂C/∂σ\partial C / \partial \sigma, so dσ/dC=1/vegad\sigma/dC = 1/\text{vega}. Take constructed inputs S=100S = 100, r=q=0r = q = 0 and σ=0.2\sigma = 0.2. A one-year call with K=100K = 100 has price about 7.96567.9656 and vega about 39.7039.70 currency units per unit of volatility, so a price uncertainty of 0.010.01 moves σ\sigma by about 0.000250.00025. A three-month call with K=130K = 130 has price about 0.01550.0155 and vega about 0.7270.727, so the same 0.010.01 moves σ\sigma by about 0.01380.0138 to first order, and solving exactly at the prices C−0.01C - 0.01 and C+0.01C + 0.01 gives implied volatilities of about 0.18060.1806 and 0.21140.2114. The relative condition number of this second root is only about 0.1060.106, but an uncertainty of 0.010.01 is about 6565 percent of its price, so here the absolute number is the informative one.

Numerical stability

Definition An algorithm returns a computed value x^\hat x for the data bb. Its forward error is ∣x^−x∗∣\lvert \hat x - x_* \rvert, and its residual is f(x^)−bf(\hat x) - b, the mismatch in the equation. Since x^\hat x solves f(x)=b+(f(x^)−b)f(x) = b + \bigl(f(\hat x) - b\bigr) exactly, the size of the residual is the absolute backward error of x^\hat x, the change in the data for which x^\hat x is an exact root. An algorithm is backward stable when every answer it computes is the exact answer for data that differ from the given data by a relative amount of the order of the unit roundoff, the largest relative rounding error of the arithmetic. Stability is a property of the algorithm. To first order, a backward-stable algorithm applied to a problem with relative condition number κrel\kappa_{\text{rel}} has a relative forward error of at most about κrel\kappa_{\text{rel}} times its relative backward error. A rigorous link between residual and forward error comes from the mean value theorem. If ff is differentiable on an interval II that contains x^\hat x and x∗x_*, and ∣f′(x)∣≥m>0\lvert f'(x) \rvert \ge m > 0 for every xx in II, then

∣x^−x∗∣≤∣f(x^)−b∣m,\lvert \hat x - x_* \rvert \le \frac{\lvert f(\hat x) - b \rvert}{m} ,

because f(x^)−b=f(x^)−f(x∗)=f′(ξ)(x^−x∗)f(\hat x) - b = f(\hat x) - f(x_*) = f'(\xi)(\hat x - x_*) for some ξ\xi between them. Without a lower bound on the derivative, a small residual says nothing about the forward error.

In plain words Stability belongs to the algorithm and conditioning to the problem. A stable algorithm answers a slightly different question exactly, and conditioning decides whether that answer is close to the answer of the question that was asked. A small residual means the equation is nearly satisfied, which is not the same as the root being nearly found.

Example For x2=2x^2 = 2 and x^=1.4142\hat x = 1.4142 the residual is 1.41422−2=−0.000038361.4142^2 - 2 = -0.00003836. On I=[1,2]I = [1, 2], which contains both x^\hat x and 2\sqrt{2}, the derivative 2x2x is at least 22, so ∣x^−2∣≤0.00001918\lvert \hat x - \sqrt{2} \rvert \le 0.00001918, and the actual error is about 0.000013560.00001356. For f(x)=(x−1)3f(x) = (x - 1)^3 with root 11, the value x^=1.01\hat x = 1.01 has residual 10−610^{-6} but forward error 0.010.01, because f′f' vanishes at the root and no positive mm exists on an interval around it. For the three-month call of the previous card, a stable solver returns the root of the stated equation to many digits, yet if the quote itself is known only to within 0.010.01, the volatility it implies is uncertain by about 0.0140.014.

Floating-point cancellation

Definition In IEEE double precision with rounding to nearest, a real number aa in the normal range is stored as a^=a(1+δa)\hat a = a(1 + \delta_a) with ∣δa∣≤u=2−53≈1.11×10−16\lvert \delta_a \rvert \le u = 2^{-53} \approx 1.11 \times 10^{-16}, and each basic operation returns its exact result rounded in the same way. If aa and cc are stored with such relative errors, then

∣(a^−c^)−(a−c)∣≤u(∣a∣+∣c∣),\begin{aligned} &\lvert (\hat a - \hat c) - (a - c) \rvert \\[0.4em] &\quad \le u \bigl(\lvert a \rvert + \lvert c \rvert\bigr), \end{aligned}

so the relative error of the difference can be as large as u(∣a∣+∣c∣)/∣a−c∣u(\lvert a \rvert + \lvert c \rvert)/\lvert a - c \rvert. This loss of relative accuracy when nearly equal rounded numbers are subtracted is called cancellation. The subtraction adds at most one rounding of its own. The damage comes from the errors already present in its inputs, which the subtraction exposes. The cure is to rewrite the formula so that the small quantity is computed without the subtraction. Multiplying by the conjugate gives the identity

x2+1−x=1x2+1+x,\begin{aligned} &\sqrt{x^2 + 1} - x \\[0.4em] &\quad = \frac{1}{\sqrt{x^2 + 1} + x}, \end{aligned}

valid for every real xx, whose right side involves no cancellation when x≥0x \ge 0.

In plain words Two large numbers that agree in their leading digits each carry a rounding error in their last digits. Their difference keeps those errors while losing the agreeing digits, so what remains can be mostly error. Algebra can often reach the same value by a route that never subtracts nearly equal numbers.

Example Take the constructed value x=108x = 10^8. Doubles near 101610^{16} are spaced 22 apart, so x2+1=1016+1x^2 + 1 = 10^{16} + 1 is rounded to 101610^{16}, its square root is exactly 10810^8, and the left side evaluates to 00. The true value is about 4.99999999999999987×10−94.99999999999999987 \times 10^{-9}, and the right side evaluates to 5×10−95 \times 10^{-9} with a relative error of about 5×10−175 \times 10^{-17}, below uu. At x=107x = 10^7 the left side already returns about 5.029×10−85.029 \times 10^{-8} against the true 5.000×10−85.000 \times 10^{-8}, wrong in the third digit. The rewrite fixes this cancellation and nothing else. For xx above about 1.34×101541.34 \times 10^{154} the square x2x^2 overflows, and a scaled computation of x2+1\sqrt{x^2 + 1}, such as the library function hypot, is needed as well. The same effect appears in finance when erτ−1e^{r\tau} - 1 or ln⁡(1+y)\ln(1 + y) is evaluated for a tiny rate. For rτ=10−10r\tau = 10^{-10} the direct difference erτ−1e^{r\tau} - 1 has a relative error of about 8×10−88 \times 10^{-8}, which is why numerical libraries provide expm1 and log1p.

Bisection method

Definition Let ff be continuous on [a0,b0][a_0, b_0] with f(a0) f(b0)<0f(a_0)\, f(b_0) < 0. For n=0,1,2,…n = 0, 1, 2, \dots compute the midpoint cn=(an+bn)/2c_n = (a_n + b_n)/2. If f(cn)=0f(c_n) = 0, stop. Otherwise keep the half on which the sign changes, setting [an+1,bn+1]=[an,cn][a_{n+1}, b_{n+1}] = [a_n, c_n] when f(an) f(cn)<0f(a_n)\, f(c_n) < 0 and [an+1,bn+1]=[cn,bn][a_{n+1}, b_{n+1}] = [c_n, b_n] otherwise. By the intermediate value theorem every bracket contains a root. The brackets are nested with widths (b0−a0)/2n(b_0 - a_0)/2^n, so they shrink to a single point x∗x_*, which is a root by continuity, and in exact arithmetic

∣cn−x∗∣≤b0−a02n+1.\lvert c_n - x_* \rvert \le \frac{b_0 - a_0}{2^{n+1}} .

Hence n≥log⁡2((b0−a0)/ε)−1n \ge \log_2\bigl((b_0 - a_0)/\varepsilon\bigr) - 1 halvings guarantee an error of at most ε\varepsilon, one binary digit per step. The method needs no derivative. A sign change proves that a root exists, not that it is unique, and uniqueness needs another argument such as strict monotonicity. In floating point the bracket stops shrinking once its endpoints are neighboring doubles, because their midpoint then rounds to one of them.

In plain words Bisection keeps a bracket on which the function changes sign and halves it at every step. It cannot get lost, and after nn steps it has located a root to within half the remaining width, but it gains only one binary digit per step.

Example For f(x)=x2−2f(x) = x^2 - 2 on [1,2][1, 2] the function is continuous and strictly increasing, so the root 2\sqrt{2} is unique. The brackets after one to six halvings are [1,1.5][1, 1.5], [1.25,1.5][1.25, 1.5], [1.375,1.5][1.375, 1.5], [1.375,1.4375][1.375, 1.4375], [1.40625,1.4375][1.40625, 1.4375] and [1.40625,1.421875][1.40625, 1.421875]. The midpoint 1.41406251.4140625 of the last one is within 0.0001510.000151 of the root, inside the bound 2−7=0.00781252^{-7} = 0.0078125. In double precision, after 5252 halvings the bracket width is 2−522^{-52}, the spacing of doubles between 11 and 22, the endpoints are the neighboring doubles 1.4142135623730951.414213562373095 and 1.41421356237309511.4142135623730951 on either side of 2\sqrt{2}, and further halvings change nothing. Continuity cannot be dropped. The function equal to −1-1 for x<0.3x < 0.3 and to 11 for x≥0.3x \ge 0.3 changes sign on [0,1][0, 1] and has no root, yet bisection closes in on its jump at 0.30.3.

Newton’s method and quadratic convergence

Definition For a differentiable ff and an iterate with f′(xn)≠0f'(x_n) \ne 0, Newton’s method sets the tangent line f(xn)+f′(xn)(x−xn)f(x_n) + f'(x_n)(x - x_n) equal to zero, which gives

xn+1=xn−f(xn)f′(xn).x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} .

A sequence converges to x∗x_* quadratically when its errors en=xn−x∗e_n = x_n - x_* satisfy ∣en+1∣≤Men2\lvert e_{n+1} \rvert \le M e_n^2 for some constant MM and all large nn, so that once M∣en∣M \lvert e_n \rvert is small the number of correct digits roughly doubles at each step. The basic local result follows from Taylor’s theorem. Let ff be twice continuously differentiable on an open interval containing a simple root x∗x_*, meaning f(x∗)=0f(x_*) = 0 and f′(x∗)≠0f'(x_*) \ne 0. Expanding ff about xnx_n with the Lagrange remainder and evaluating at x∗x_*, where f(x∗)=0f(x_*) = 0, gives

0=f(xn)−f′(xn) en+12f′′(ξn) en2\begin{aligned} 0 &= f(x_n) - f'(x_n)\, e_n \\[0.4em] &\quad + \tfrac12 f''(\xi_n)\, e_n^2 \end{aligned}

for some ξn\xi_n between xnx_n and x∗x_*, and dividing by f′(xn)f'(x_n) gives

en+1=f′′(ξn)2f′(xn) en2.e_{n+1} = \frac{f''(\xi_n)}{2 f'(x_n)}\, e_n^2 .

Choose δ>0\delta > 0 so that f′≠0f' \ne 0 on I=[x∗−δ,x∗+δ]I = [x_* - \delta, x_* + \delta] and Mδ<1M\delta < 1, where MM is the maximum of ∣f′′∣\lvert f'' \rvert on II divided by twice the minimum of ∣f′∣\lvert f' \rvert on II. Then every start in II gives ∣en+1∣≤Men2≤Mδ∣en∣\lvert e_{n+1} \rvert \le M e_n^2 \le M\delta \lvert e_n \rvert, so the iterates stay in II and converge to x∗x_* quadratically, with en+1/en2→f′′(x∗)/(2f′(x∗))e_{n+1}/e_n^2 \to f''(x_*)/\bigl(2 f'(x_*)\bigr) as long as no iterate lands exactly on the root. The theorem is local. It says nothing about a distant start, and its hypothesis f′(x∗)≠0f'(x_*) \ne 0 excludes repeated roots.

In plain words Newton’s method replaces the function by its tangent line and jumps to the zero of the tangent. Near a simple root the tangent is an excellent model, the error is squared at each step, and correct digits accumulate very quickly. Far from the root the tangent can point anywhere.

Example For f(x)=x2−2f(x) = x^2 - 2 the step is xn+1=xn−(xn2−2)/(2xn)x_{n+1} = x_n - (x_n^2 - 2)/(2x_n). From x0=1x_0 = 1 the iterates are 1.51.5, 1.4166671.416667, 1.41421571.4142157 and 1.414213562374691.41421356237469, with errors of about 0.08580.0858, 0.002450.00245, 2.12×10−62.12 \times 10^{-6} and 1.59×10−121.59 \times 10^{-12}. The ratios en+1/en2e_{n+1}/e_n^2 are 0.50.5, 0.3330.333, 0.35290.3529 and 0.353550.35355, approaching f′′(2)/(2f′(2))=1/(22)≈0.353553f''(\sqrt{2})/\bigl(2f'(\sqrt{2})\bigr) = 1/(2\sqrt{2}) \approx 0.353553. Every error from e1e_1 on is positive, as the error formula predicts, because f′′=2f'' = 2 and f′(xn)=2xn>0f'(x_n) = 2x_n > 0 make its right side positive for every positive iterate. Four Newton steps reach an accuracy that the bisection bound on [1,2][1, 2] guarantees only after 3939 halvings.

Newton cycle

Definition Write N(x)=x−f(x)/f′(x)N(x) = x - f(x)/f'(x) for the Newton map. A Newton cycle of period p≥2p \ge 2 is a set of distinct points z0,…,zp−1z_0, \dots, z_{p-1}, none of them a root and each with f′(zk)≠0f'(z_k) \ne 0, such that N(zk)=zk+1N(z_k) = z_{k+1} for k<p−1k < p - 1 and N(zp−1)=z0N(z_{p-1}) = z_0. An iteration started on a cycle never converges. For twice continuously differentiable ff,

N′(x)=f(x) f′′(x)f′(x)2,N'(x) = \frac{f(x)\, f''(x)}{f'(x)^2},

and a cycle is attracting when the product of the values ∣N′(zk)∣\lvert N'(z_k) \rvert over the cycle is less than 11. Starts near an attracting cycle are drawn into it rather than to a root. A safeguarded method keeps a sign-change bracket, accepts a Newton step only when it lands inside the current bracket, and bisects otherwise. It keeps the containment of bisection, and near a simple root it typically regains the speed of Newton’s method.

In plain words The local theorem promises speed near a simple root and nothing elsewhere. Away from the root, tangent steps can bounce between the same points forever, and a nearby start can be pulled into the same loop.

Example Take f(x)=x3−2x+2f(x) = x^3 - 2x + 2, with f′(x)=3x2−2f'(x) = 3x^2 - 2, and start at x0=0x_0 = 0. Since f(0)=2f(0) = 2 and f′(0)=−2f'(0) = -2, the step gives x1=1x_1 = 1. Since f(1)=1f(1) = 1 and f′(1)=1f'(1) = 1, the next step gives x2=0x_2 = 0, and the iteration repeats 0,1,0,1,…0, 1, 0, 1, \dots forever. Moreover f′′(0)=0f''(0) = 0, so N′(0)=0N'(0) = 0 and the cycle is attracting. In exact arithmetic the start 0.10.1 produces about 1.01421.0142, 0.07970.0797, 1.00911.0091 and 0.05220.0522, and the iterates close in on the cycle. The cubic has a single real root, about −1.7693-1.7693, because its discriminant −4(−2)3−27⋅22=−76-4(-2)^3 - 27 \cdot 2^2 = -76 is negative. Since f(−2)=−2<0<3=f(−1)f(-2) = -2 < 0 < 3 = f(-1), bisection on [−2,−1][-2, -1] finds it, and Newton’s method started at −2-2 reaches it to full double precision in five steps, because f′f' is about 7.397.39 at the root, far from zero.

Check yourself

  1. With S>0S > 0, K>0K > 0 and T>0T > 0, the Black-Scholes call price is continuous and strictly increasing in σ\sigma, and a quote lies strictly between the model prices at σ=0.01\sigma = 0.01 and σ=1\sigma = 1. How many bisection halvings of [0.01,1][0.01, 1] guarantee that the midpoint is within 10−610^{-6} of the implied volatility, and what does that guarantee leave out?
Show the answer

The function C(σ)−CquoteC(\sigma) - C_{\text{quote}} is continuous and changes sign on the bracket, and strict monotonicity makes its root unique. The bound requires

0.992n+1≤10−6,\frac{0.99}{2^{n+1}} \le 10^{-6},

that is 2n+1≥9900002^{n+1} \ge 990000. Since 219=5242882^{19} = 524288 is too small and 220=10485762^{20} = 1048576 is enough, n+1=20n + 1 = 20 and n=19n = 19 halvings suffice. Indeed 0.99/220≈9.44×10−70.99/2^{20} \approx 9.44 \times 10^{-7}, while 1818 halvings only give 1.89×10−61.89 \times 10^{-6}. The guarantee is about the root of the equation with this quote in exact arithmetic. It leaves out the uncertainty of the quote itself, which conditioning turns into volatility uncertainty of about ∣ΔC∣/vega\lvert \Delta C \rvert / \text{vega}, and the limit set by double precision once the bracket endpoints become neighboring doubles.

  1. For the constructed one-year call with S=K=100S = K = 100 and r=q=0r = q = 0, the quote 7.9655677.965567 is the Black-Scholes price at σ=0.2\sigma = 0.2. At σ0=0.3\sigma_0 = 0.3 the model price is 11.92353811.923538 and the vega is 39.44793339.447933. Compute the Newton step σ1\sigma_1, then use the error formula to predict the size and sign of the next error, given that at σ=0.2\sigma = 0.2 the vega is 39.69525539.695255 and ∂2C/∂σ2≈−1.984763\partial^2 C / \partial \sigma^2 \approx -1.984763.
Show the answer

The function is f(σ)=C(σ)−7.965567f(\sigma) = C(\sigma) - 7.965567, so f(0.3)=3.957971f(0.3) = 3.957971 and

σ1=0.3−3.95797139.447933≈0.3−0.100334=0.199666.\begin{aligned} \sigma_1 &= 0.3 - \frac{3.957971}{39.447933} \\[0.4em] &\approx 0.3 - 0.100334 \\[0.4em] &= 0.199666 . \end{aligned}

Its error is e1≈−0.000334e_1 \approx -0.000334. Near the root the error formula gives e2≈f′′(0.2) e12/(2f′(0.2))e_2 \approx f''(0.2)\, e_1^2 / \bigl(2 f'(0.2)\bigr), and the coefficient is

−1.9847632⋅39.695255≈−0.0250,\begin{aligned} &\frac{-1.984763}{2 \cdot 39.695255} \\[0.4em] &\quad \approx -0.0250 , \end{aligned}

so e2≈−0.0250⋅1.116×10−7≈−2.79×10−9e_2 \approx -0.0250 \cdot 1.116 \times 10^{-7} \approx -2.79 \times 10^{-9}. The second iterate should lie just below 0.20.2, at about 0.19999999720.1999999972, and a direct second Newton step gives 0.199999997210.19999999721. The sign is negative because the second derivative is negative here. The error went from about 3×10−43 \times 10^{-4} to about 3×10−93 \times 10^{-9} in one step, as quadratic convergence predicts.

  1. Apply Newton’s method to f(x)=(x−1)2f(x) = (x - 1)^2 from x0=2x_0 = 2. Find the iterates and the rate of convergence, name the hypothesis of the local theorem that fails, and compare the residual with the error after ten steps.
Show the answer

The step is

xn+1=xn−(xn−1)22(xn−1)=xn−xn−12,\begin{aligned} x_{n+1} &= x_n - \frac{(x_n - 1)^2}{2(x_n - 1)} \\[0.4em] &= x_n - \frac{x_n - 1}{2}, \end{aligned}

so en+1=en/2e_{n+1} = e_n/2. The iterates are 1.51.5, 1.251.25, 1.1251.125 and so on, with e10=2−10≈0.000977e_{10} = 2^{-10} \approx 0.000977. The convergence is linear with ratio 12\tfrac12, not quadratic. The failed hypothesis is f′(x∗)≠0f'(x_*) \ne 0, since 11 is a double root and f′(1)=0f'(1) = 0. After ten steps the residual is (2−10)2≈9.5×10−7(2^{-10})^2 \approx 9.5 \times 10^{-7}, about a thousand times smaller than the error, so a stopping rule that asks for a residual below 10−610^{-6} would stop here with only about three correct digits. No positive lower bound on ∣f′∣\lvert f' \rvert exists near the root, so the residual bound cannot repair this. Bisection cannot even start, because f≥0f \ge 0 never changes sign.

How this lesson connects