Skip to article frontmatterSkip to article content

Problems and conditioning

Let’s think a bit about what must be the easiest math problem you’ve dealt with in quite some time: adding 1 to a number. Formally, we describe this problem as a function f(x)=x+1f(x)=x+1, where xx is any real number.

On a computer, xx will be represented by its floating-point counterpart, fl(x)\fl(x). Given the property (1.1.5), we have fl(x)=x(1+ϵ)\fl(x)=x(1+\epsilon) for some ε satisfying ϵ<ϵmach/2|\epsilon| < \macheps/2. There is no error in representing the value 1.

Let’s suppose that we are fortunate and that the addition proceeds exactly, with no additional errors. Then the machine result is just

y=x(1+ϵ)+1. {y} = x(1+\epsilon)+1.

We can derive the relative error in this result:

yf(x)f(x)=(x+ϵx+1)(x+1)x+1=ϵxx+1. \frac{ |{y}-f(x)| }{ |f(x)| } = \frac{ |(x+\epsilon x+1) - (x+1)| }{ |x+1| } = \frac{ |\epsilon x| }{ |x+1| } .

This error could be quite large if the denominator is small. In fact, we can make the relative error as large as we please by taking xx very close to -1. This is essentially what happened in Demo 1.1.4.

You may have encountered this situation before when using significant digits for scientific calculations. Suppose we round all results to five decimal digits, and we add -1.0012 to 1.0000. The result is -0.0012, or 1.2×103-1.2\times 10^{-3} in scientific notation. Notice that even though both operands are specified to five digits, it makes no sense to write more than two digits in the answer because there is no information in the problem beyond their decimal places.

This phenomenon is known as subtractive cancellation, or loss of significance. We may say that three digits were “lost” in the mapping from -1.0012 to -0.0012. There’s no way the loss could be avoided, regardless of the algorithm, once we decided to round off everything to a fixed number of digits.

In double precision, all the values are represented to about 16 significant decimal digits of precision, but it’s understood that subtractive cancellation may render some of those digits essentially meaningless.

1.2.1Condition numbers

Now we consider problems more generally. As above, we represent a problem as a function ff that maps a real data value xx to a real result f(x)f(x). We abbreviate this situation by the notation f:RRf:\real \mapsto \real, where R\real represents the real number set.

When the problem ff is approximated in floating point on a computer, the data xx is represented as a floating-point value x~=fl(x)\tilde{x}=\fl(x). Ignoring all other sources of error, we define the quantitative measure

f(x)f(x~)f(x)xx~x, \frac{ \vphantom{\dfrac{\bigl|}{\bigl|}}\dfrac{|f(x)-f(\tilde{x})|}{|f(x)|} }{% \vphantom{\dfrac{\bigl|}{\bigl|}}\dfrac{|x-\tilde{x}|}{|x|} },

which is the ratio of the relative changes in result and data. We make this expression more convenient if we recall that floating-point arithmetic gives x~=x(1+ϵ)\tilde{x}=x(1+\epsilon) for some value ϵϵmach/2|\epsilon|\le \macheps/2. Hence

f(x)f(x+ϵx)ϵf(x). \dfrac{\left|f(x)-f(x+\epsilon x)\right| } {|\epsilon f(x)|}.

Finally, we idealize what happens in a perfect computer by taking a limit as ϵmach0\macheps\to 0.

The condition number is a ratio of the relative error of the output to the relative error of the input. It depends only on the problem and the data, not the computer or the algorithm.

Assuming that ff has at least one continuous derivative, we can simplify the expression (1.2.5) through some straightforward manipulations:

κf(x)=limϵ0f(x+ϵx)f(x)ϵf(x)=limϵ0f(x+ϵx)f(x)ϵxxf(x)=xf(x)f(x).\begin{split} \kappa_f(x) &= \lim_{\epsilon\to 0} \left| \dfrac{ f(x+\epsilon x) - f(x) }{ \epsilon f(x)} \right| \\ &= \lim_{\epsilon\to 0} \left| \dfrac{ f(x+\epsilon x) - f(x) }{ \epsilon x} \cdot \frac{x}{f(x)} \right| \\ &= \left| \dfrac{ x f'(x)} {f(x)} \right|. \end{split}

In retrospect, it should come as no surprise that the change in values of f(x)f(x) due to small changes in xx involves the derivative of ff. In fact, if we were making measurements of changes in absolute rather than relative terms, the condition number would be simply f(x)|f'(x)|.

Condition numbers of the major elementary functions are given in Table 1.2.1.

Table 1.2.1:Relative condition numbers of elementary functions

FunctionCondition number
f(x)=x+cf(x) = x + cκf(x)=xx+c\kappa_f(x) = \dfrac{\lvert x \rvert}{\lvert x+c\rvert}
f(x)=cxf(x) = cxκf(x)=1\kappa_f(x) = 1
f(x)=xpf(x) = x^pκf(x)=p\kappa_f(x) = \lvert p \rvert
f(x)=exf(x) = e^xκf(x)=x\kappa_f(x) = \lvert x \rvert
f(x)=sin(x)f(x) = \sin(x)κf(x)=xcot(x)\kappa_f(x) = \lvert x\cot(x) \rvert
f(x)=cos(x)f(x) = \cos(x)κf(x)=xtan(x)\kappa_f(x) = \lvert x\tan(x) \rvert
f(x)=log(x)f(x) = \log(x)κf(x)=1log(x)\kappa_f(x) = \dfrac{1}{\lvert \log(x) \rvert}

As you are asked to show in Exercise 4, when two functions ff and gg are combined in a chain as h(x)=f(g(x))h(x)=f(g(x)), the composite condition number is

κh(x)=κf(g(x))κg(x).\kappa_h(x) = \kappa_f(g(x)) \cdot \kappa_g(x).

1.2.2Estimating errors

Refer back to the definition of κf\kappa_f as a limit in (1.2.5). Approximately speaking, if ϵ|\epsilon| is small, we expect

f(x+ϵx)f(x)f(x)κf(x)ϵ.\left| \dfrac{ f(x+\epsilon x) - f(x) }{ f(x)} \right| \approx \kappa_f(x)\, |\epsilon|.

That is, whenever the data xx is perturbed by a small amount, we expect that relative perturbation to be magnified by a factor of κf(x)\kappa_f(x) in the result.

Large condition numbers signal when errors cannot be expected to remain comparable in size to roundoff error. We call a problem poorly conditioned or ill-conditioned when κf(x)\kappa_f(x) is large, although there is no fixed threshold for the term.

If κf1/ϵmach\kappa_f \approx 1/\macheps, then we can expect the result to have a relative error of as much as 100% simply by expressing the data xx in finite precision. Such a function is essentially not computable at this machine epsilon.

You may have noticed that for some functions, such as the square root, the condition number can be less than 1. This means that relative changes get smaller in the passage from input to output. However, every result in floating-point arithmetic is still subject to rounding error at the relative level of ϵmach\macheps. In practice, κf<1\kappa_f<1 is no different from κf=1\kappa_f=1.

1.2.3Polynomial roots

Most problems have multiple input and output values. These introduce complications into the formal definition of the condition number. Rather than worry over those details here, we can still look at variations in only one output value with respect to one data value at a time.

The calculation in Example 1.2.4 generalizes to polynomials of higher degree.

The condition number of a root can be arbitrarily large. In the extreme case of a repeated root, the condition number is formally infinite, which implies that the ratio of changes in the root to changes in the coefficients cannot be bounded.

1.2.4Exercises

  1. ✍ Use (1.2.6) to derive the relative condition numbers of the following functions appearing in Table 1.2.1.

    (a) f(x)=xp,f(x) = x^p,\quad (b) f(x)=log(x),f(x) = \log(x),\quad (c) f(x)=cos(x),f(x) = \cos(x),\quad (d) f(x)=exf(x) = e^x.

  2. ✍ Use the chain rule (1.2.9) to find the relative condition number of the given function. Then check your result by applying (1.2.6) directly.

    (a) f(x)=x+5,f(x) = \sqrt{x+5},\quad (b) f(x)=cos(2πx),f(x) = \cos(2\pi x),\quad (c) f(x)=ex2.f(x) = e^{-x^2}.

  3. ✍ Calculate the relative condition number of each function, and identify all values of xx at which κf(x)\kappa_{f}(x)\to\infty (including limits as x±x\to\pm\infty).

    (a) f(x)=tanh(x),f(x) = \tanh(x),\quad (b) f(x)=ex1x,f(x) = \dfrac{e^x-1}{x},\quad (c) f(x)=1cos(x)x.f(x) = \dfrac{1-\cos(x)}{x}.

  4. ✍ Suppose that ff and gg are real-valued functions that have relative condition numbers κf\kappa_f and κg\kappa_g, respectively. Define a new function h(x)=f(g(x))h(x)=f\bigl(g(x)\bigr). Show that for xx in the domain of hh, the relative condition number of hh satisfies (1.2.9).

  5. ✍ Suppose that ff is a function with relative condition number κf\kappa_f, and that f1f^{-1} is its inverse function. Show that the relative condition number of f1f^{-1} satisfies

    κf1(x)=1κf(f1(x)),\kappa_{f^{-1}}(x) = \frac{1}{\kappa_f\Bigl( f^{-1}(x) \Bigr)},

    provided the denominator is nonzero.

  6. ✍ Referring to the derivation of (1.2.13), derive an expression for the relative condition number of a root of ax2+bx+c=0ax^2+bx+c=0 due to perturbations in bb only.

  7. The polynomial x22x+1x^2-2x+1 has a double root at 1. Let r1(ϵ)r_1(\epsilon) and r2(ϵ)r_2(\epsilon) be the roots of the perturbed polynomial x2(2+ϵ)x+1x^2-(2+\epsilon)x+1.

    (a) ✍/⌨ Using a computer or calculator, make a table with rows for ϵ=102\epsilon = 10^{-2}, 10-4, 10-6, \ldots, 10-12 and columns for ε, r1(ϵ)r_1(\epsilon), r2(ϵ)r_2(\epsilon), r1(ϵ)1|r_1(\epsilon)-1|, and r2(ϵ)1|r_2(\epsilon)-1|.

    (b) ✍ Show that the observations of part (a) satisfy

    max{r1(ϵ)1,r2(ϵ)1}Cϵq\max\{\, |r_1(\epsilon)-1|, |r_2(\epsilon)-1| \,\} \approx C \epsilon^q

    for some 0<q<10<q<1. (This supports the conclusion that κ=\kappa=\infty at the double root.)

  8. ✍ Generalize (1.2.13) to finding a root of the nnth degree polynomial p(x)=anxn++a1x+a0p(x) = a_nx^n + \cdots + a_1 x + a_0, and show that the relative condition number of a root rr with respect to perturbations only in aka_k is

    κr(ak)=akrk1p(r).\kappa_r(a_k) = \left| \frac{a_k r^{k-1}}{p'(r)} \right|.