





















Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!






















§1. Diversity of Numbers Lecture 2 Page 1
To understand numerical nonrobustness, we need to understand computer arithmetic. But there are several distinctive modes of nu- merical computation: symbolic mode, floating point (FP) mode, ar- bitrary precision mode, etc. Numbers are remarkably complex objects in computing, embodying two distinct sets of properties: quantitative properties and algebraic properties. Each mode has its distinctive number representations which reflect the properties needed for com- putating in that mode. Our main focus is on the FP mode that is dominant in scientific and engineering computing, and in the corre- sponding representation popularly known as the IEEE Standard.
Numerical computing involves numbers. For our purposes, numbers are elements of the set C of complex numbers. But in each area of application, we are only interested in some subset of C. This subset may be N as in number theory and cryptographic applications. The subset may be R as in most scientific and engineering computations. In algebraic computations, the subset might be Q or its algebraic closure Q. These examples show that “numbers” can be very diverse in manifestation. Numbers have two complementary sets of properties: quantitative (“numeri- cal”) properties and algebraic properties. It is not practical to provide a single representation of numbers to cover the full range of these properties. Otherwise, computer systems might as well provide a single number type, “the” complex number type. Depending on the application, different aspects of quantitative properties or algebraic properties would be more important. Over the years, different computing fields have developed suitable number representation to provide just the needed properties. Corresponding to these number representa- tions, there also evolved corresponding modes of numerical computation. We briefly review a few of these modes:
§1. Diversity of Numbers Lecture 2 Page 2
polynomial-interval pair (A(X), I) where α is the only root of A(X) inside the interval I. For instance, if α =
2 then we could choose A(X) = X^2 − 2 and I = [1, 2]. We can perform the arithmetic operations on such isolated interval representations. The quantitative properties of numbers are cap- tured by the interval I, which can of course be arbitrarily narrowed. Both representations are exact.
2 is typically represented by 64 bits in some floating point format, and converts to the printed decimal value of 1.4142135623731. In modern hardware, this format invariably conforms to the IEEE Standard [16]. The FP mode is very fast because of such hardware support. It is the “gold standard” whereby other numerical modes are measured against. One goal of numerical algorithm design in the FP mode is to achieve the highest numerical accuracy possible using machine arithmetic directly on the number representation alone (perhaps after some re-arrangement of computation steps). The characterization “fixed precision” needs clarification since all FP al- gorithms can be regarded as parameterized by a precision number θ (0 ≤ θ < 1). Most algorithms will produce answers that converge to the exact answer as θ → 0 (see Chaitin-Chatelin and Frayss´e [7, p. 9]). In practice, FP algorithms are “precision oblivious” in the sense that their operations do not adapt to the θ parameter.
§2. Floating Point Arithmetic Lecture 2 Page 4
and continued fractions, the number of components are unbounded. For general information about about number systems, see Knuth [19]. All these alternative number systems ultimately need a representation of the natural numbers N. Besides the standard β-ary representation of N, we mention an alternative called β-adic numbers. A digit in β-adic number is an element of { 1 , 2 ,... , β}, and a sequence of such digits dndn− 1 ,... , d 1 d 0 represents the number
∑n i=0 diβ i. This equation is identical to the one for β-
ary numbers; but since the di’s are non-zero, every natural number has a unique β-adic representation. In particular, 0 is represented by the empty sequence.
Floating Point Systems. Given natural numbers β ≥ 2 and t ≥ 1, the floating point system F (β, t) comprises all numbers of the form
r = m × βe−t+1^ = m βt−^1
βe^ (2)
where m, e ∈ Z and |m| < βt. We call β the base and t the significance of the system. The pair (m, e) is a representation of the number r, where m is the mantissa and e the exponent of the representation. When exponents are restricted to lie in the range
emin ≤ e ≤ emax,
we denote the corresponding subsystem of F (β, t) by
F (β, t, emin, emax). (3)
Note that F (β, t) is essentially the system F (β, t, −∞, +∞). When r is repre- sented by (m, e), we may write
float(m, e) = r.
For instance, float(2t−^1 , 0) = 1 and float(2t−^1 , 2) = 4 in F (2, t). Sometimes, e is called the biased exponent in (2) because we might justifi- ably^1 call e − t + 1 the “exponent”. Using the biased exponent will facilitate the description of the IEEE Standard, to be discussed shortly. Another advantage of using a biased exponent is that the role of the t parameter (which controls precision) and the role of emin, emax (which controls range) are clearly separated. The expression m/βt−^1 in (2) can be written as ±d 1 .d 2 d 3 · · · dt where m is a t- digit number m = ±d 1 d 2 · · · dt in β-ary notation. As usual, di ∈ { 0 , 1 ,... , β − 1 } are β-ary digits. The equation (2) then becomes
r = ±βe^ × d 1 .d 2 d 3 · · · dt = float(m, e). (4)
In this context, d 1 and^ dt are (respectively) called the^ leading^ and^ trailing digits of m. The number ±d 1 .d 2 d 3 · · ·^ dt =^ m/βt−^1 is also called the^ signifi- cand of r. In modern computers, β is invariably 2. We might make a case for β = 10 and some older computers do use this base. In any case, all our examples will assume β = 2. We classify the representations (m, e) into three mutually disjoint types: (i) If |m| ≥ βt−^1 or if (m, e) = (0, 0), then (m, e) is a normal representation. When m = 0, we just have a representation of zero. Thus, the normal represen- tation of non-zero numbers amounts to requiring d 1 6 = 0 in (4).
(^1) It is less clear why we use “e − t + 1” instead of “e − t”. Mathematically, “e − t” seems preferable but “e − t + 1” is a better fit for the IEEE standard.
§2. Floating Point Arithmetic Lecture 2 Page 5
(ii) If e = emin and 0 < |m| < βt−^1 then (m, e) is a subnormal representa- tion. Note that when emin = −∞, there are no subnormal representations since e and m are finite values (by assumption). (iii) All other (m, e) are denormalized representations. In the following discussion, we assume some F = F (β, t, emin, emax). Num- bers in F are said to be representable or floats. Normal and subnormal numbers refers to numbers with normal and subnormal representations (re- spectively). We claim that every representable number is either normal or subnormal, but not both. In proof, first note that the normal numbers and subnormal numbers are different: assuming emin > −∞, the smallest non-zero normal number is float(βt−^1 , emin) = βemin^ , which is larger than the largest subnormal number float(βt−^1 − 1 , emin). Next, consider any denormalized representation (m, e). There are two possibilities: (a) If m = 0 then f loat(m, e) = 0 which is normal. (b) If m 6 = 0 then |m| < βt−^1. So the leading digit of m is 0. Let di = 0 for i = 1,... , k and dk+1 6 = 0 for some k ≥ 1. Consider the representation (mβ, e −) where = min{k, e − emin}. It is easy to see that this is either normal ( = k) or subnormal (` < k). This shows that float(m, e) is either normal or subnormal, as claimed. The transformation
(m, e) −→ (mβ, e −), (5)
which is used in the above proof, is called normalization (even though the result might actually be subnormal). We claim that normal and subnormal representations are unique and they can easily be compared. Subnormal representations are clearly unique. They are also smaller than normal numbers. To compare two subnormal representations, we just compare their mantissas. Next consider two normal representations, (m, e) 6 = (m′, e′). We may assume that mm′^ > 0 since otherwise the compar- ison can be based on the signs of m and m′^ alone. If e = e′^ then clearly the comparison is reduced to comparing m with m′. Otherwise, say e > e′. If m > 0 then we conclude that float(m, e) > float(m′, e′) as shown in the following:
float(m, e) =
m βt−^1
βe^ ≥ βe^ ≥ βe
′ (^) +
m′ βt−^1
βe
′ = float(m′, e′).
If m < 0, we similarly conclude that float(m, e) < float(m′, e′).
Resolution and Range. In the system F = F (β, t, emin, emax), there are two related measures of the “finest resolution possible”. One is the machine epsilon, εM := β^1 −t, which may be defined to be be the distance from 1.0 and the next larger representable number, i.e., float(βt−^1 + 1, 0). More important for error analysis is the unit roundoff, defined as
u := εM /2 =
β^1 −t. (6)
We wish to define the “range of F ”. If y is normal then
βemin^ ≤ |y| ≤ βemax^
β − β^1 −t
Thus we define the normal range of F to be
(−β1+emax^ , −βemin^ ] ∪ [βemin^ , β1+emax^ ).
The subnormal range is the open interval (βemin^ , βemin^ ). Note that 0 is normal but lies in the subnormal range. The range of F is the union of the normal and subnormal ranges of S.
§2. Floating Point Arithmetic Lecture 2 Page 7
But we still need to prove that this function is well-defined, i.e., there is a unique even number in the set {bxc , dxe} when x 6 ∈ F. Without loss of generality, assume 0 ≤ bxc < dx where bxc = float(m, e) and dxe = float(m′, e′). If e = e′^ then clearly m is even iff m′^ is odd. If e = e′^ − 1 then m = βt^ − 1 and m′^ = βt−^1. Again, m is even iff m′^ is odd. There are two other possibilities: bxc = −∞ or dxe = +∞. To handle them, we declare ±∞ to be even iff β is even. For instance, if bxc = −∞ then dxe = − b(c βt^ − 1 , emax) and exactly one of these two values are even. This concludes our proof. The five tie-breaking rules can actually be elevated into complete rounding rules: that is, each rule defines a corresponding “rounding” function in its own right. Used in this way, these rules will be called rounding modes; moreover, we introduce the notation “fl(x)” for the rounding functions defined using one of these modes. In general, we have
fl(x) ∈ {dxe , bxc} ⊆ F ∪ {±∞}.
Two of these rounding modes, round up and round down, give us nothing new: they yield fl(x) = dxe and fl(x) = bxc, respectively. Consider the other three rounding modes:
Round to 0
fl(x) =
bxc x ≥ 0 dxe x < 0 Observe that the resulting function is just “truncation”.
Round away from 0
fl(x) =
dxe x ≥ 0 bxc x < 0
Round to even If x ∈ F then fl(x) = x; otherwise, fl(x) is the even value in {bxc , dxe}.
The last rounding mode should not be confused with “round to nearest/even”. Let us prove a basic result about rounding to a floating point system F :
Theorem 1 Assume x ∈ R lies in the range of F and fl(x) is finite. (i) Then fl(x) = x(1 + δ), |δ| < 2 u (8)
and fl(x) = x 1 + δ′^
, |δ′| < 2 u. (9)
(ii) If fl(x) is rounding to nearest, then we have
fl(x) = x(1 + δ), |δ| < u (10)
and fl(x) =
x 1 + δ′^
, |δ′| ≤ u. (11)
Proof. (i) Suppose x ∈ Ie for some e. If x = βe^ then fl(x) = x and the theorem is clearly true. So assume |x| > βe. The space between consecutive representable numbers in Ie is βe−t+1. Writing ∆ = fl(x) − x, we obtain fl(x) = x + ∆ = x(1 + ∆/x) = x(1 + δ) where
|δ| =
x
βe−t+ |x|
< β−t+1. (12)
§2. Floating Point Arithmetic Lecture 2 Page 8
This proves (8) since u = β^1 −t/2. Note this bound holds even if fl(x) is the right endpoint of the interval Ie. Similarly, if ∆′^ = x − fl(x) then x = fl(x) + ∆′^ = fl(x)(1 + ∆′/ fl(x)) = x(1 + δ′) where
|δ′| =
fl(x)
βe−t+ | fl(x)|
≤ β−t+1. (13)
(ii) This is similar to (i) applies except that |∆| ≤ u (not strict inequality). The analogue of (12) is |δ| < u, but the analogue of (13) is |δ′| ≤ u (not strict inequality). Q.E.D.
Example 1 (The IEEE Floating Point Systems) The IEEE single precision numbers is essentially^2 the system
F (β, t, emin, emax) = F (2, 24 , − 127 , 127)
with range 10±^38. The IEEE double precision numbers is essentially the system
F (β, t, emin, emax) = F (2, 53 , − 1023 , 1023)
with range is 10±^308. Note that emin = −emax in both systems. The unit roundoffs for these two systems are
u = 2 −^24 ≈ 5. 96 × 10 −^8 (single); (14) u = 2 −^53 ≈ 1. 11 × 10 −^16 (double). (15)
The formats (i.e., the bit representation) of numbers in these two systems are quite interesting because it is carefully optimized. The number of bits used to represent the single and double precision numbers are 32 and 64 bits, respec- tively. In the double precision format, 53 bits are dedicated to the mantissa (“significand”) and 11 bits for the exponent. In single precision, these are 24 and 8 bits, respectively. We will return later to discuss how this bit budget is used to achieve the representation of F (2, t, emin, emax) and other features of the IEEE standard.
Floating Point Arithmetic. Let ◦ be any basic floating point operation (usually, this refers to the 4 arithmetic operations, although square-root is some- times included). Let ◦′^ be the corresponding operation for the numbers in F. The fundamental property of fixed precision floating point arithmetic is this: if x, y ∈ F then x ◦′^ y = fl(x ◦ y). (16)
This assumes ◦ is binary, but the same principle applies for unary operations. Let us call any model of machine arithmetic that satisfies (16) the strict model Thus, the strict model together with Theorem 1 implies the following property
x ◦′^ y =
(x ◦ y)(1 + δ), |δ| < u, (x◦y) (1+δ′^ ) ,^ |δ
′| ≤ u, (17)
where u is the unit roundoff (see (6) and (14)). Any model of machine arithmetic that satisfies (17) is called a standard model (with unit roundoff u). Note that if x ◦ y ∈ F , then the strict model requires that δ = 0; but this is not required by the standard model. All our error analysis will be conducted under
(^2) The next section will clarify why we say this correspondence is only in “essence”, not in full detail.
§2. Floating Point Arithmetic Lecture 2 Page 10
0 .b 1 b 2 · · · bt ≤ 0 .b 1 b 2 · · · bt. This proves c 0 = 0. Note that a − b might be a subnormal number. The other possibility is e(a) = e(b). But this case is slightly simpler to analyze. Q.E.D.
Note that we cannot guarantee exact results when forming the sum a + b, under the assumptions of Sterbenz’s Lemma. Complementing Sterbenz’s lemma is another “exact” result from Dekker (1971): let ˜s be the floating point result of adding a and b where we make no assumptions about a/b. Dekker shows, in base β = 2, the sum a + b can be expressed exactly as ˜s + ˜e where ˜e is another floating point number computed from a, b. See Chapter 4.
Exercises
Exercise 2.1: Unless otherwise noted, assume the F (2, t) system. (i) Give the normal representations of − 1 , 0 , 1. (ii) Give the representations of the next representable number after 1, and the one just before 1. (iii) Give the IEEE double formats of the numbers in (i) and (ii). (iv) Give the binary representation of machine epsilon in the IEEE double format. (v) True or False: for any x, dxe and bxc are the two closest representable to x. ♦
Exercise 2.2: Determine all the numbers in F = F (2, 3 , − 1 , 2). What are the subnormal numbers? What is u and the range of F? ♦
Exercise 2.3: Consider arithmetic in the system F (β, t). (i) Show that the standard model (17) holds for multiplication or division when the scaled operand is truncated to t digits (just before performing the actual operation). (ii) Show that the standard model (17) fails for addition or subtraction when we truncate to t digits. (iii) Give the worst case error bound in (ii). (iv) Show that the standard model holds for addition and subtraction if we have a guard digit. ♦
Exercise 2.4: (i) Give an actual numerical example to show why the guard digit in the scaled operands is essential for addition or subtraction. (ii) State the error bound guaranteed by addition or subtraction when there is no guard bit. This should be weaker than the standard model. ♦
Exercise 2.5: (Ferguson) Generalize the lemma of Sterbenz so that the hy- pothesis of the lemma is that e(a−b) ≤ min{e(a), e(b)} where e(a) denotes the exponent of a in normal representation. ♦
Exercise 2.6: The area of a triangle with side-lengths of a, b, c is given by a formula
∆ =
s(s − a)(s − b)(s − c), s = (a + b + c)/ 2.
This formula was derived in Book I of Metrica, by Heron who lived in Alexandria, Egypt, from approximately 10 to 75 A.D.. If the triangle is needle-like (say, c is very small compared to a, b) the straightforward evaluation of this formula using machine arithmetic can be very inaccurate. (i) Give a straight forward C++ implementation of this formula. Use the input data found in the first three columns of the following table:
§3. The IEEE Standard Lecture 2 Page 11
No. a b c Naive Kahan’s 1 10 10 10 43.30127019 43. 2 − 3 5 2 2.905 Error 3 100000 99999.99979 0.00029 17.6 9. 4 100000 100000 1.00005 500 10.0 50002. 5 99999.99996 99999.99994 0.00003 Error 1. 6 99999.99996 0.00003 99999.99994 Error 1. 7 10000 50000.000001 15000 0 612.372435 8 8 99999.99999 99999.99999 200000 0 Error 9 5278.64055 94721.35941 99999.99996 Error 0 10 100002 100002 200004 0 0 11 31622.77662 0.000023 31622.77661 0. 447 0. 12 31622.77662 0.0155555 31622.77661 246. 18 245.
Values in bold font indicate substantial error. Your results should be comparable to the results in the first 4th column. (ii) Now implement Kahan’s prescription: first sort the lengths so that a ≥ b ≥ c. If c − (a − b) < 0 then the data is invalid. Otherwise use the following formula
(a + (b + c))(c − (a − b))(c + (a − b))(a + (b − c)).
In these formulas, the parethesis are significant. Compare your results with the 5th column of the above table. (iii) Convert your programs in both parts (i) and (ii) into CORE programs and run at level III, with guaranteed precision of 64 bits. What conclusions do you draw? NOTE: This problem is derived from^4 Kahan’s paper “Miscalculating Area and Angles of a Needle-like Triangle”, July 19, 1999. ♦
End Exercises
The official name for this standard is the “IEEE Standard 754 for Binary Floating-Point Arithmetic” [16, 10]. There is a generalization called the IEEE Standard 854 (1987) which applies to any base and to any word length. It is im- portant to understand some basic properties of this standard because all modern computer arithmetic subscribes to it. This standard was precipitated by a grow- ing problem in numerical computation in the 1980s. As FP computation grew in importance, hardware implementations of floating point arithmetic began to proliferate. The divergence among these architectures caused confusion in the computing community, and numerical software became largely non-portable across platforms. In 1985, the IEEE established the said standard for hardware designers. See the book of Patterson and Hennessy [28] for some of this history. We should properly understand the true significance of this standard vis-´a-vis our robustness goal.
(^4) Available from http://cs.berkeley.edu/~wkahan/Triangle.pdf. The CORE version of this program may be found with the CORE distribution. The above table contains a small correction of the original table in Kahan. The bug was discovered by the CORE program, and confirmed by Kahan.
§3. Floating Point Arithmetic Lecture 2 Page 13
Format and Encoding. Let us focus on the IEEE double precision format: how can we represent the system F (2, 53 , − 1023 , 1023) using 64 bits? The first decision is to allocate 11 bits for the exponent and 53 bits for the mantissa. To make this allocation concrete, we need to recall that modern computer memory is divided into 32-bit chunks called (computer) words; this is illustrated in Figure 2.
±
(^63 62 52 51 )
(^31 )
f [51 : 32]
f [31 : 0]
e[52 : 62]
Figure 2: Format of a Double Precision IEEE Float
This physical layout will be important to understand if one were to program and manipulate such representations; So two consecutive words are used to represent a double precision number. The bits of a floating point number f are indexed by 0, 1 ,... , 63. The 11 exponent bits are in f [52 : 62]. The remaining bits, f [0 : 51] and f [63] are allocated to the mantissa. Bit f [63] represents the sign of the mantissa. Although the sign bit logically belongs to the mantissa, it is thus physically separated from the rest of the mantissa. We do not allocate any bits for sign in the exponent. So the 11 exponent bits represent an unsigned integer f between 0 and 2047, but we view f as encoding the signed exponent e = f − 1023 (here 1023 is called^5 the exponent bias). By avoiding a sign for the exponent, we have saved a “half-bit” using this exponent bias trick (Exercise). So e ranges from −1023 to +1024. We shall reserve the value e = 1024 for special indications (e.g., representing infinity – see below). Hence emin = −1023 and emax = 1023. Since one of the 53 bits in the mantissa is used for sign, we have only 52 bits to represent the absolute value of the mantissa. Here, we use another trick to gain one extra bit: for normal numbers, the leading bit of a 53-bit mantissa is always 1. So this leading bit does not need to be explicitly represented! But what about subnormal numbers? In this case we declare the implicit bit to be 0. How shall we know whether a number is normal or subnormal? IEEE standard declares that this is determined by the exponent e. A number with exponent e is normal if e > −1023, and it is subnormal if e = −1023. The preceding discussion can be directly transferred to the representation of F (2, 24 , − 127 , 127) by the IEEE single precision format: with a 32-bit budget, we allocate 8 bits to the exponent and 24 bits to the mantissa. The unsigned exponent bits represents a number between 0 and 255. Using an exponent bias of 127, it encodes an exponent value e between −127 and 128. Again, the exponent e = −127 indicates subnormal numbers, and the value e = 128 is used for special indication, so emin = −127 and emax = 127.
Let us briefly mention how bits are allocated in quad-precision floating point numbers: 15 bits for the exponent and 113 bits for the mantissa. is the system F (2, 113 , − 16382 , 16383). The IEEE Standard also provide for extensions of the above types, but we shall not discuss such extensions. (^5) This is distinct from the “biased exponent” idea discussed in the representation (m, e) where e is called the biased exponent.
§4. Error Analysis Lecture 2 Page 14
Is the IEEE doubles really F (2, 53 , − 1023 , 1023)? We had hinted that the IEEE double precision may not correspond exactly to F (2, 53 , − 1023 , 1023). In- deed, it is only a proper subset of F (2, 53 , − 1023 , 1023). To see this, we note that there are 2^53 numbers in F (2, 53 , − 1023 , 1023) with exponent −1023. How- ever, there are only 2^52 numbers with exponent −1023 in the IEEE standard. What are the missing numbers? These are numbers of the form float(m, −1023) where |m| ≥ 2 −^52. Why are these missing? That is because of the implicit leading bit of the 53-bit mantissa is 0 when e = −1023. This means m must have the form m = 0.b 1 b 2 · · · b 52. For instance, float(2−^52 , −1023) = 2−^1023 is not representable. In general, all the normal numbers with exponent emin are necessarily missing using the IEEE’s convention. This creates an undesirable non-uniformity among the representable numbers; specifically, there is a conspicuous gap between the normal and subnormal numbers. But consider the alternative, where we get rid of the special rule concerning the implicit bit in case e = emin. That is, we use the rule that the implicit is always 1 even when e = emin. The problem is that gap between 0 and the next representable number is 2emin^ ; the special rule for implicit leading bit gives us 2−t+1^ values to fill this gap. So, this is where the missing numbers go! This tradeoff is apparently worthwhile, and is known as the graceful degradation towards 0 feature of IEEE arithmetic.
Exercises
Exercise 3.1: (i) What are the numbers in in F (2, 24 , − 127 , 127) that are missing from the IEEE single precision floats? (ii) In general, what are the missing numbers in the IEEE version of F (2, t, emin, emax)? (iii) Discuss the pros and cons of this graceful degradation towards 0 policy. (iv) How would you would design and implementation F (2, t, emin, emax) where no numbers are missing? ♦
Exercise 3.2: Refer to the example in Figure 1. The “missing numbers” un- der the IEEE scheme are those in the interval I− 2. The gradual underflow feature is achieved at the expense of moving these numbers into the inter- val I−∞. The result does not look pretty! Work out a scheme for more uniform floating-point grid near 0: the idea is to distribute 2−t+1^ values uniformly in I−∞ ∪ Imin (say, filling in only the even values) ♦
Exercise 3.3: By using the biased exponent trick instead of allocating a sign bit to the exponent, what have we gained? ♦
End Exercises
The ostensible goal of error analysis is to obtain an error bound. But [14, p. 71] (“The purpose of rounding error analysis”) notes that the actual bound is often less important than the insights from the analysis. The quantity de- noted u from the previous section will an important parameter in such analysis. Without the right tool, bounding the error on the simplest computation could be formidable. The art in error analysis includes maintaining the error bounds in a form that is reasonably tight, yet easy to understand and manipulate.
§4. Error Analysis Lecture 2 Page 16
(2) If ρn+1 = −1, we have
1 + θn 1 + δn+ = 1 + θn+
or θn+1 = θ 1+n−δδnn+1+1. Thus
|θn+1| ≤
θn + u 1 − u
=
(n + 1)u (1 − nu)(1 − u) < γn+1.
Q.E.D. The hypothesis nu < 1 is not too restrictive in typical applications. For instance, with the IEEE single precision numbers, it means n < 224 which is about 16 billion. If we assume nu < 1 /2, then we have the estimate γn < 2 nu. Using this lemma, it is now easy to show:
Lemma 4 (i) ˜sn =
∑n i=1 xi(1 +^ θn−i+1)^ where^ |θi| ≤^ γi. (ii) If all xi’s have the same sign then ˜sn = sn(1 + θ) where |θ| ≤ γn.
Proof. (i) easily follows by induction from (19). To see (ii), we note that when xy ≥ 0 and α ≤ β, then αx + βy = γ(x + y) (20)
for some α ≤ γ ≤ β. Thus x 1 (1 + θ 1 ) + x 2 (1 + θ 2 ) = (x 1 + x 2 )(1 + θ) for some min{θ 1 , θ 2 } ≤ θ ≤ max{θ 1 , θ 2 }. The result follows by induction. Q.E.D.
We noted above that the purpose of error analysis is just as important for the insight as for the actual error bound. In the present case, our proof of Lemma 4(i) shows that the backward error associated with each xi is propor- tional to its depth in the expression for sn. We can reduce the error considerably by reorganizing our computation: In particular, if the summation of the num- bers x 1 ,... , xn is organized in the form of a balanced binary tree, then we can improve Lemma 4(i) to
˜sn =
∑^ n
i=
xi(1 + θi) (21)
where each |θi| ≤ γ1+dlg ne. We leave this as an exercise.
Forward and Backward Error Analysis. Let y be a numerical variable. As a general notation, we like to write ˜y for an approximation to y, and also δy for their absolute difference ˜y − y. Typically, ˜y is some computed floating point number. There are two main kinds of error measures: absolute or relative. Absolute error in ˜y as an approximation to y is simply |δy|. Relative error is defined by
ε(˜y, y) = |δy| |y|
This is defined to be 0 if y = ˜y = 0 and ∞ if y = 0 6 = ˜y. Generally speaking, numerical analysis prefers to use relative error measures. One reason is that relative error for floating point numbers is built-in; this is clear from Theorem 1. In error analysis, we also recognized two kinds of algorithmic errors: forward and backward errors. Let f : X → Y be a function with X, Y ⊆ C. Suppose ˜y
§4. Error Analysis Lecture 2 Page 17
is the computed value of f at x ∈ Y and y = f (x). How shall we measure the error in this computation? Conceptually, forward error is simple to understand
is a n × n-matrix. Let A˜ = (˜aij ) be the product computed by the obvious trivial algorithm. The forward analysis is easy because ˜aij = aij (1 + θ) where |θ| ≤ u.
But there is no backwards error result because A˜ cannot be written as x˜˜yT^ for any choice of ˜x, ˜y, since we cannot guarantee that A˜ is a rank-one matrix. In general, we see that for problems f : X → Y in which the range f (X) is a lower dimensional subset of Y , no backward error analysis is possible. Standard problems of numerical analysis are usually not of this type. There is also a notion of “mixed forward-backward stable” if both ε(˜x, x) and ε(˜y, y) are “small”. In Lecture 3, we return to this issue.
Exercises
Exercise 4.1: The inequality |θn| ≤ γn in Lemma 3 is actually strict, with one possible exception. What is this? ♦
Exercise 4.2: Extend the error analysis for summation to the scalar product problem: s =
∑n i=1 xiyi.^ ♦
Exercise 4.3: Write a recursive program for summing the entries in the array x[1..n] so that the error bound (21) is attained. Also, prove the bound (21) for your scheme. ♦
Exercise 4.4:∑ We have noted that the relative forward error analysis for s = n i=1 xi^ is not possible in general. Do the absolute forward error analysis. ♦
Exercise 4.5: Suppose we introduce a “composite” error combining relative with absolute. More precisely, let ε(y, y˜ ) = min{|y − y˜|, |y − y˜|/|y|}. Thus,
§5. Condition Number and Stability Lecture 2 Page 19
where x range over those elements of X satisfying ‖x‖X = 1. Then the absolute and relative condition numbers are given by
̂ κf (x) = ‖Jf (x)‖ (24)
and
κf (x) =
‖Jf (x)‖ · ‖x‖ ‖f (x)‖
EXAMPLE 1. Let us give a proof of (25) for the case f : Cm^ → C. By Taylor’s theorem with remainder,
f (x + δx) − f (x) = Jf (x) ◦ δx + R(x, δx)
where Jf (x) ◦ δx denotes dot product with Jf (x) = [∂f /∂x 1 ,... , ∂f /∂xn], and |R(x,δx)| ‖δx‖ →^ 0 as^ ‖δx‖ →^ 0. Taking absolute values and multiplying by^
‖x‖ |f (x)|·‖δx‖ , we get
|f (x + δx) − f (x)| ‖δx‖
‖x‖ |f (x)|
‖x‖ |f (x)|
∣Jf^ (x)^ ◦^
δx ‖δx‖
|R(x, δx)| ‖δx‖
Taking the limsup of the lefthand side as ‖δx‖ → 0, we obtain κf (x). But the
righthand side equals (^) |f‖ x(x‖)| ‖Jf (x)‖, by definition of ‖Jf (x)‖. This completes our demonstration. EXAMPLE 2. Let us compute these condition numbers for the problem f : C^2 → C where f (x) = x 1 + x 2 and x = (x 1 , x 2 )T^. The Jacobian is
Jf (x) =
∂f ∂x 1
∂f ∂x 2
Assume the norm on X = C^2 is the ∞-norm, so ‖x‖ = max{|x 1 |, |x 2 |}. Thus ‖Jf (x)‖ = 2. From (24), we obtain ̂κf (x) = 2. From (25), we obtain
κ =
2 max{|x 1 |, |x 2 |} |x 1 + x 2 |
Thus κ = ∞ when x 1 + x 2 = 0. EXAMPLE 3. Condition numbers of matrix. EXAMPLE 4. Condition numbers of polynomial root.
Stability of Algorithms. Condition numbers are inherent to a given prob- lem, the concept of stability is a function of algorithms for the problem. We may view an algorithm for the problem (22) as another function f˜ : X′^ → Y ′^ where X′^ ⊆ X and Y ′^ ⊆ Y. In fact, we might as well take X′^ = fl(X) and Y ′^ = fl(Y ), i.e., the representable elements of X, Y. The stability of f˜ is the measure of how much f˜ deviates from f. Intuitively, we want to define ˜κf (x), the relative
condition number of f˜ at x; we need to be careful with this definition since X′^ = fl(X), Y ′^ = fl(Y ) are discrete sets. The stability of an algorithm is clearly limited by the condition numbers for the problem. Ideally, a stable algorithm should have the property that ˜κf (x) = O(κf (x)). We now come to the key definition of Trefethen and Bau: an algorithm f˜ for f is stable if there exists positive constants C 0 , C 1 , u 0 such that for all u (0 < u < u 0 ) and all x ∈ X, there is some x˜ ∈ X′^ such that
‖x˜ − x‖ ‖x‖
≤ C 0 u, and (26)
‖ f˜ (x) − f (˜x)‖ ‖f (x˜)‖
≤ C 1 u. (27)
§5. Condition Number and Stability Lecture 2 Page 20
According to Trefethen and Bau, the constants C 0 , C 1 may not depend on x but may depend on f. In practice, the requirement that u must be smaller than some u 0 is not an issue. To understand this definition of stability, let us explore some related concepts:
≤ C 1 u. (28)
This would not involve ˜x, so the requirement (26) can be omitted. Of course, (28) is the relative forward error in f˜ (x); in fact, this constitutes our definition of forward stability.
= O(u),
‖ f˜(x) − f (x˜)‖ ‖f (x˜)‖
= O(u).
In the big-Oh notations of equations (26) and (27), we view u as varying and approaching 0. As noted above, the implicit constants C 0 , C 1 in these big-Oh notations do not depend on x but may depend on f. Typically, X ⊆ Cm^ for some fixed m. Thus the implicit constants C 0 , C 1 are allowed to depend on m. When X = ∪m≥ 1 Cm, then it seems that we should allow the constant C 0 , C 1 to have a weak dependence of x: in particular, we would like C 0 , C 1 to depend on size(x) where size(x)=m when x ∈ Cm.
EXAMPLE 5: From theorem 1, we conclude that the standard algorithms for performing arithmetic operations (+, −, ×, ÷) are all stable. EXAMPLE 6: Consider the problem of computing eigenvalues of a matrix A. One algorithm is to compute the characteristic polynomial P (λ) = det(A − λI), and then find roots of P (λ). Trefethan and Bau noted that this algorithm is not stable. There is a rule of thumb in numerical analysis that says
Forward Error ≤ Condition Number × Backward Error.
Here is one precise formulation of this insight.
Theorem 5 ([30, p. 151]) If f˜ is a backward stable algorithm for f then the relative forward error satisfy
‖ f˜(x) − f (x)‖ ‖f (x)‖
= O(κf (x)u).