MA 214 Lecture 4
MA 214 Lecture 4
Spring 2022-23 1 / 38
Arithmetic Errors
Spring 2022-23 2 / 38
Floating-Point Representation
Let β ∈ N and β ≥ 2.
Spring 2022-23 3 / 38
Floating-Point Representation
Let β ∈ N and β ≥ 2.
Any real number can be represented exactly in base β as
Spring 2022-23 3 / 38
Floating-Point Representation
Let β ∈ N and β ≥ 2.
Any real number can be represented exactly in base β as
Spring 2022-23 3 / 38
Floating-Point Representation
Let β ∈ N and β ≥ 2.
Any real number can be represented exactly in base β as
Spring 2022-23 3 / 38
Floating-Point Representation
Let β ∈ N and β ≥ 2.
Any real number can be represented exactly in base β as
Spring 2022-23 3 / 38
Floating-Point Representation
Let β ∈ N and β ≥ 2.
Any real number can be represented exactly in base β as
Spring 2022-23 4 / 38
Error Analysis: Floating-Point Representation (contd.)
Example:
When β = 2, the floating-point representation
Spring 2022-23 4 / 38
Error Analysis: Floating-Point Approximation
Spring 2022-23 5 / 38
Error Analysis: Floating-Point Approximation
Definition (n-Digit Floating-point Number)
Let β ∈ N and β ≥ 2. An n-digit floating-point number in base β is
of the form
(−1)s × (.d1 d2 · · · dn )β × β e
where
d1 d2 dn
(.d1 d2 · · · dn )β = + 2 + ··· + n
β β β
with di ∈ { 0, 1, · · · , β − 1 }, d1 6= 0 or d2 = d3 = · · · = 0, s = 0 or 1,
and an appropriate exponent e.
Spring 2022-23 5 / 38
Error Analysis: Floating-Point Approximation (contd.)
Example: The following are examples of real numbers in the decimal
floating point representation.
The real number x = 6.238 can be represented as
6.238 = (−1)0 × 0.6238 × 101 ,
in which case, we have s = 0, β = 10, e = 1, d1 = 6, d2 = 2,
d3 = 3 and d4 = 8.
Spring 2022-23 6 / 38
Error Analysis: Floating-Point Approximation (contd.)
Example: The following are examples of real numbers in the decimal
floating point representation.
The real number x = 6.238 can be represented as
6.238 = (−1)0 × 0.6238 × 101 ,
in which case, we have s = 0, β = 10, e = 1, d1 = 6, d2 = 2,
d3 = 3 and d4 = 8.
The real number x = −0.0014 can be represented in the decimal
floating-point representation as
x = (−1)1 × 0.14 × 10−2 .
Here s = 1, β = 10, e = −2, d1 = 1 and d2 = 4.
Spring 2022-23 6 / 38
Error Analysis: Floating-Point Approximation (contd.)
Remark:
Note that there are only finite number of digits in the n-digit floating-point
representation.
Spring 2022-23 7 / 38
Error Analysis: Floating-Point Approximation (contd.)
Remark:
Note that there are only finite number of digits in the n-digit floating-point
representation.
But a real number may have infinitely many digits and therefore infinitely
many digits in mantissa.
Spring 2022-23 7 / 38
Error Analysis: Floating-Point Approximation (contd.)
Remark:
Note that there are only finite number of digits in the n-digit floating-point
representation.
But a real number may have infinitely many digits and therefore infinitely
many digits in mantissa.
For instance,
1
= 0.33333 · · · = (−1)0 × (0.33333 · · · )10 × 100 .
3
Spring 2022-23 7 / 38
Error Analysis: Floating-Point Approximation (contd.)
Remark:
Note that there are only finite number of digits in the n-digit floating-point
representation.
But a real number may have infinitely many digits and therefore infinitely
many digits in mantissa.
For instance,
1
= 0.33333 · · · = (−1)0 × (0.33333 · · · )10 × 100 .
3
Therefore, the representation
(−1)s × (.d1 d2 · · · dn )β × β e
is (in general) only an approximation to a real number.
Spring 2022-23 7 / 38
Error Analysis: Underflow and Overflow of Memory
Spring 2022-23 8 / 38
Error Analysis: Underflow and Overflow of Memory
m ≤ e ≤ M.
Spring 2022-23 8 / 38
Error Analysis: Underflow and Overflow of Memory
m ≤ e ≤ M.
Spring 2022-23 8 / 38
Error Analysis: Underflow and Overflow of Memory
m ≤ e ≤ M.
Spring 2022-23 8 / 38
Error Analysis: Chopping and Rounding a Number
Definition (Precision)
The number of digits n in the mantissa as given in the definition of the
n-digit floating point representation is called the precision or length of
the floating-point number.
Spring 2022-23 9 / 38
Error Analysis: Chopping and Rounding a Number (contd.)
Spring 2022-23 10 / 38
Error Analysis: Chopping and Rounding a Number (contd.)
Spring 2022-23 10 / 38
Error Analysis: Chopping and Rounding a Number (contd.)
Spring 2022-23 10 / 38
Error Analysis: Chopping and Rounding a Number (contd.)
Definition (Rounded Numbers)
Let x be a real number given in the floating-point representation as
x = (−1)s × (.d1 d2 · · · dn dn+1 · · · )β × β e .
Spring 2022-23 11 / 38
Error Analysis: Chopping and Rounding a Number (contd.)
Definition (Rounded Numbers)
Let x be a real number given in the floating-point representation as
x = (−1)s × (.d1 d2 · · · dn dn+1 · · · )β × β e .
The rounded approximation of x is given by
, 0 ≤ dn+1 < β2
(−1)s × (.d1 d2 · · · dn )β × β e
fl(x) =
(−1)s × (.d1 d2 · · · (dn + 1))β × β e , β2 ≤ dn+1 < β
s e
× (.d1 d2 · · · (dn + 1))β × β :=
where (−1)
(−1)s × (.d1 d2 · · · dn )β + (. 0| 0 {z
· · · 0} 1)β × β e .
(n−1)−times
Spring 2022-23 11 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
Spring 2022-23 12 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
Spring 2022-23 12 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
Spring 2022-23 12 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
Spring 2022-23 12 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
Step 1
Get the n-digit floating-point approximation fl(x) and fl(y ) of the numbers
x and y , respectively.
Spring 2022-23 12 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
Step 2
Perform the calculation fl(x) fl(y ) using exact arithmetic.
Spring 2022-23 13 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
Step 3
Get the n-digit floating-point approximation fl(fl(x) fl(y )) of fl(x) fl(y ).
Spring 2022-23 14 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
Step 3
Get the n-digit floating-point approximation fl(fl(x) fl(y )) of fl(x) fl(y ).
The result from step 3 is the value of x y using n-digit rounding.
Spring 2022-23 14 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
(contd.)
√ √
Example: Consider the function f (x) = x( x + 1 − x).
Spring 2022-23 15 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
(contd.)
√ √
Example: Consider the function f (x) = x( x + 1 − x).
Let us evaluate f (100000) using a six-digit rounding.
Spring 2022-23 15 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
(contd.)
√ √
Example: Consider the function f (x) = x( x + 1 − x).
Let us evaluate f (100000) using a six-digit rounding.
√ √
f (100000) = 100000 100001 − 100000 .
Spring 2022-23 15 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
(contd.)
√ √
Example: Consider the function f (x) = x( x + 1 − x).
Let us evaluate f (100000) using a six-digit rounding.
√ √
f (100000) = 100000 100001 − 100000 .
√
100001 ≈ 316.229347 = 0.316229347 × 103 .
Spring 2022-23 15 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
(contd.)
√ √
Example: Consider the function f (x) = x( x + 1 − x).
Let us evaluate f (100000) using a six-digit rounding.
√ √
f (100000) = 100000 100001 − 100000 .
√
100001 ≈ 316.229347 = 0.316229347 × 103 .
The 6-digit rounded approximation of 0.316229347 × 103 is
0.316229 × 103 .
Spring 2022-23 15 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
(contd.)
√ √
Example: Consider the function f (x) = x( x + 1 − x).
Let us evaluate f (100000) using a six-digit rounding.
√ √
f (100000) = 100000 100001 − 100000 .
√
100001 ≈ 316.229347 = 0.316229347 × 103 .
The 6-digit rounded approximation of 0.316229347 × 103 is
0.316229 × 103 .
√
=⇒ fl( 100001) = 0.316229 × 103 .
Spring 2022-23 15 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
(contd.)
Example:
√
Similarly, fl( 100000) = 0.316228 × 103 . (Here we use rounding,
not chopping)
Spring 2022-23 16 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
(contd.)
Example:
√
Similarly, fl( 100000) = 0.316228 × 103 . (Here we use rounding,
not chopping)
√ √
Therefore, fl(fl( 100001) − fl( 100000)) = 0.1 × 10−2 .
Spring 2022-23 16 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
(contd.)
Example:
√
Similarly, fl( 100000) = 0.316228 × 103 . (Here we use rounding,
not chopping)
√ √
Therefore, fl(fl( 100001) − fl( 100000)) = 0.1 × 10−2 .
Finally, we have
Spring 2022-23 16 / 38
Error Analysis: Arithmetic Using n-Digit Rounding and Chopping
(contd.)
Example:
√
Similarly, fl( 100000) = 0.316228 × 103 . (Here we use rounding,
not chopping)
√ √
Therefore, fl(fl( 100001) − fl( 100000)) = 0.1 × 10−2 .
Finally, we have
Spring 2022-23 16 / 38
Using six-digit chopping, the value of fl(f (100000)) is 200.
Justification:
√ √
100001√− 100000√= 0.0002 using 6 digit chopping. Thus
100000( 100001 − 100000) equals 200 after 6 digit chopping.
Spring 2022-23 17 / 38
Using six-digit chopping, the value of fl(f (100000)) is 200.
Justification:
√ √
100001√− 100000√= 0.0002 using 6 digit chopping. Thus
100000( 100001 − 100000) equals 200 after 6 digit chopping.
Spring 2022-23 17 / 38
Error Analysis: Machine Epsilon
Spring 2022-23 18 / 38
Error Analysis: Types of Errors
Definition (Errors)
1 The error in a computed quantity is defined as
Error = True Value - Approximate Value.
Spring 2022-23 19 / 38
Error Analysis: Types of Errors
Definition (Errors)
1 The error in a computed quantity is defined as
Error = True Value - Approximate Value.
2 Absolute value of an error is called the absolute error.
Spring 2022-23 19 / 38
Error Analysis: Types of Errors
Definition (Errors)
1 The error in a computed quantity is defined as
Error = True Value - Approximate Value.
2 Absolute value of an error is called the absolute error.
3 The relative error is a measure of the error in relation to the size of
the true value as given by
Error
Relative Error = ; True Value 6= 0
True Value
Spring 2022-23 19 / 38
Error Analysis: Types of Errors
Definition (Errors)
1 The error in a computed quantity is defined as
Error = True Value - Approximate Value.
2 Absolute value of an error is called the absolute error.
3 The relative error is a measure of the error in relation to the size of
the true value as given by
Error
Relative Error = ; True Value 6= 0
True Value
4 The percentage error is defined as
Percentage Error = 100 × |Relative Error|.
Spring 2022-23 19 / 38
Error Analysis: Types of Errors (contd.)
E (xA ) := Error(xA ) = x − xA .
Ea (xA ) := Absolute Error(xA ) = |E (xA )|
E (xA )
Er (xA ) := Relative Error(xA ) = , x 6= 0.
x
Spring 2022-23 20 / 38
Error Analysis: Significant Digits
Example:
Consider the number x = 1/3 = 0.3333 · · · .
The number xA = 0.333 has three significant digits when compared to x.
Spring 2022-23 21 / 38
Error Analysis: Significant Digits
Example:
Consider the number x = 1/3 = 0.3333 · · · .
The number xA = 0.333 has three significant digits when compared to x.
Definition (Significant β-Digits)
Let β be a radix.
If xA is an approximation to x, then we say that xA approximates x to r
significant β-digits if r is the largest non-negative integer such that
|x − xA | 1 −r +1
≤ β .
|x| 2
Here we assume that x 6= 0.
Spring 2022-23 21 / 38
Error Analysis: Loss of Significant Digits
Example:
Consider two real numbers
x = 7.6545428 = 0.76545428 × 101 , y = 7.6544201 = 0.76544201 × 101 .
Spring 2022-23 22 / 38
Error Analysis: Loss of Significant Digits
Example:
Consider two real numbers
x = 7.6545428 = 0.76545428 × 101 , y = 7.6544201 = 0.76544201 × 101 .
The numbers
xA = 7.6545421 = 0.76545421×101 , yA = 7.6544200 = 0.76544200×101
are approximation to x and y , correct to seven and eight significant digits,
respectively.
Spring 2022-23 22 / 38
Error Analysis: Loss of Significant Digits
Example:
Consider two real numbers
x = 7.6545428 = 0.76545428 × 101 , y = 7.6544201 = 0.76544201 × 101 .
The numbers
xA = 7.6545421 = 0.76545421×101 , yA = 7.6544200 = 0.76544200×101
are approximation to x and y , correct to seven and eight significant digits,
respectively.
zA = xA − yA = 0.12210000 × 10−3 , z = x − y = 0.12270000 × 10−3 .
Spring 2022-23 22 / 38
Error Analysis: Loss of Significant Digits
Example:
Consider two real numbers
x = 7.6545428 = 0.76545428 × 101 , y = 7.6544201 = 0.76544201 × 101 .
The numbers
xA = 7.6545421 = 0.76545421×101 , yA = 7.6544200 = 0.76544200×101
are approximation to x and y , correct to seven and eight significant digits,
respectively.
zA = xA − yA = 0.12210000 × 10−3 , z = x − y = 0.12270000 × 10−3 .
|z − zA |
=⇒ ≈ 0.0049 < 0.5 × 10−2 .
|z|
Spring 2022-23 22 / 38
Error Analysis: Loss of Significant Digits
Example:
Consider two real numbers
x = 7.6545428 = 0.76545428 × 101 , y = 7.6544201 = 0.76544201 × 101 .
The numbers
xA = 7.6545421 = 0.76545421×101 , yA = 7.6544200 = 0.76544200×101
are approximation to x and y , correct to seven and eight significant digits,
respectively.
zA = xA − yA = 0.12210000 × 10−3 , z = x − y = 0.12270000 × 10−3 .
|z − zA |
=⇒ ≈ 0.0049 < 0.5 × 10−2 .
|z|
Thus, zA has only three significant digits with respect to z.
Spring 2022-23 22 / 38
Error Analysis: Loss of Significant Digits (contd.)
Spring 2022-23 23 / 38
Error Analysis: Loss of Significant Digits (contd.)
Spring 2022-23 23 / 38
Error Analysis: Loss of Significant Digits (contd.)
Spring 2022-23 23 / 38
Error Analysis: Loss of Significant Digits (contd.)
Spring 2022-23 23 / 38
Error Analysis: Loss of Significant Digits (contd.)
Spring 2022-23 24 / 38
Error Analysis: Loss of Significant Digits (contd.)
Spring 2022-23 24 / 38
Error Analysis: Loss of Significant Digits (contd.)
Spring 2022-23 24 / 38
Error Analysis: Loss of Significant Digits (contd.)
Spring 2022-23 25 / 38
Error Analysis: Loss of Significant Digits (contd.)
Spring 2022-23 25 / 38
Error Analysis: Loss of Significant Digits (contd.)
There is a drastic error in the value of the function, which is due to the
loss of significant digits.
Spring 2022-23 25 / 38
Error Analysis: Loss of Significant Digits (contd.)
Spring 2022-23 26 / 38
Error Analysis: Loss of Significant Digits (contd.)
Spring 2022-23 26 / 38
Error Analysis: Loss of Significant Digits (contd.)
f (100000) = 158.114
on a six-digit rounding.
Spring 2022-23 26 / 38
Disasters Caused by Numerical Errors
Reference: https://apps.dtic.mil/sti/citations/ADA344865
Spring 2022-23 27 / 38
More details can also be found here :
https://www-users.cse.umn.edu/ arnold/disasters/patriot.html
Spring 2022-23 28 / 38
Total Error (contd.)
Spring 2022-23 29 / 38
Total Error (contd.)
Spring 2022-23 29 / 38
Total Error (contd.)
Spring 2022-23 29 / 38
Total Error (contd.)
Spring 2022-23 29 / 38
Total Error (contd.)
in which the first term on the right hand side is called the propagated error
Spring 2022-23 29 / 38
Total Error (contd.)
in which the first term on the right hand side is called the propagated error
and the second term is called the floating-point error.
Spring 2022-23 29 / 38
Condition Number
For a function f : R → R, consider the problem of evaluating f (x) at an
approximate value xA rather than at x and estimating the error.
Spring 2022-23 30 / 38
Condition Number
For a function f : R → R, consider the problem of evaluating f (x) at an
approximate value xA rather than at x and estimating the error.
The question is how well does f (xA ) approximate f (x)?
Spring 2022-23 30 / 38
Condition Number
For a function f : R → R, consider the problem of evaluating f (x) at an
approximate value xA rather than at x and estimating the error.
The question is how well does f (xA ) approximate f (x)?
Using the mean-value theorem, we get
f (x) − f (xA ) = f 0 (ξ)(x − xA ),
where ξ is an unknown point between x and xA .
Spring 2022-23 30 / 38
Condition Number
For a function f : R → R, consider the problem of evaluating f (x) at an
approximate value xA rather than at x and estimating the error.
The question is how well does f (xA ) approximate f (x)?
Using the mean-value theorem, we get
f (x) − f (xA ) = f 0 (ξ)(x − xA ),
where ξ is an unknown point between x and xA .
The relative error of f (x) with respect to f (xA ) is given by
f 0 (ξ)
0
f (ξ)
Er (f (xA )) = (x − xA ) = x Er (xA ).
f (x) f (x)
Spring 2022-23 30 / 38
Condition Number (contd.)
Since xA and x are assumed to be very close to each other and ξ lies
between x and xA , we may make the approximation
f (x) − f (xA ) ≈ f 0 (x)(x − xA ).
Spring 2022-23 31 / 38
Condition Number (contd.)
Since xA and x are assumed to be very close to each other and ξ lies
between x and xA , we may make the approximation
f (x) − f (xA ) ≈ f 0 (x)(x − xA ).
Using this, we have 0
f (x)
Er (f (xA )) ≈ x Er (xA ).
f (x)
Spring 2022-23 31 / 38
Condition Number (contd.)
Since xA and x are assumed to be very close to each other and ξ lies
between x and xA , we may make the approximation
f (x) − f (xA ) ≈ f 0 (x)(x − xA ).
Using this, we have 0
f (x)
Er (f (xA )) ≈ x Er (xA ).
f (x)
Definition (Condition number of a function)
The condition number of a continuously differentiable function f at a
point x = c is given by
f 0 (c)
c .
f (c)
Spring 2022-23 31 / 38
Condition Number (contd.)
f 0 (c)
c
f (c)
at c is small.
The process of evaluating a function at x = c is said to be
ill-conditioned if it is not well-conditioned.
Spring 2022-23 32 / 38
Condition Number (contd.)
f 0 (c)
c
f (c)
at c is small.
The process of evaluating a function at x = c is said to be
ill-conditioned if it is not well-conditioned.
Spring 2022-23 33 / 38
Condition Number (contd.)
√
Example: Consider the function f (x) = x, for all x ∈ [0, ∞). Then
1
f 0 (x) = √ , for all x ∈ [0, ∞).
2 x
Spring 2022-23 33 / 38
Condition Number (contd.)
√
Example: Consider the function f (x) = x, for all x ∈ [0, ∞). Then
1
f 0 (x) = √ , for all x ∈ [0, ∞).
2 x
The condition number of f is
f 0 (x) 1
x = , for all x ∈ [0, ∞).
f (x) 2
Spring 2022-23 33 / 38
Condition Number (contd.)
√
Example: Consider the function f (x) = x, for all x ∈ [0, ∞). Then
1
f 0 (x) = √ , for all x ∈ [0, ∞).
2 x
The condition number of f is
f 0 (x) 1
x = , for all x ∈ [0, ∞).
f (x) 2
Thus, we have 1
|Er (f (xA ))| ≈ |Er (xA )|.
2
Spring 2022-23 33 / 38
Condition Number (contd.)
√
Example: Consider the function f (x) = x, for all x ∈ [0, ∞). Then
1
f 0 (x) = √ , for all x ∈ [0, ∞).
2 x
The condition number of f is
f 0 (x) 1
x = , for all x ∈ [0, ∞).
f (x) 2
Thus, we have 1
|Er (f (xA ))| ≈ |Er (xA )|.
2
Thus, we see that taking square roots is a well-conditioned process.
Spring 2022-23 33 / 38
Example :
Spring 2022-23 34 / 38
Condition Number (contd.)
Example: Consider the function
10
f (x) = , for all x ∈ R.
1 − x2
Spring 2022-23 35 / 38
Condition Number (contd.)
Example: Consider the function
10
f (x) = , for all x ∈ R.
1 − x2
Then f 0 (x) = 20x/(1 − x 2 )2 , so that
f 0 (x) (20x/(1 − x 2 )2 )x 2x 2
x = =
f (x) 10/(1 − x 2 ) |1 − x 2 |
Spring 2022-23 35 / 38
Condition Number (contd.)
Example: Consider the function
10
f (x) = , for all x ∈ R.
1 − x2
Then f 0 (x) = 20x/(1 − x 2 )2 , so that
f 0 (x) (20x/(1 − x 2 )2 )x 2x 2
x = =
f (x) 10/(1 − x 2 ) |1 − x 2 |
Spring 2022-23 35 / 38
Condition Number (contd.)
Example: Consider the function
10
f (x) = , for all x ∈ R.
1 − x2
Then f 0 (x) = 20x/(1 − x 2 )2 , so that
f 0 (x) (20x/(1 − x 2 )2 )x 2x 2
x = =
f (x) 10/(1 − x 2 ) |1 − x 2 |
Thus, for x near 1 or -1, the process of evaluating this function is ill-
conditioned, as the relative error is magnifies.
Spring 2022-23 35 / 38
Condition Number (contd.)
Spring 2022-23 36 / 38
Condition Number (contd.)