Docsity

Errors in Computing: Understanding Roundoff and Truncation Errors in Numerical Software - , Study notes of Computer Science

Partial preview of the text

Download Errors in Computing: Understanding Roundoff and Truncation Errors in Numerical Software - and more Study notes Computer Science in PDF only on Docsity!

Lecture 4

Errors in Computing

L. Olson

Department of Computer Science University of Illinois at Urbana-Champaign

Numerical "bugs"

Obvious

Software has bugs

Not-SO-Obvious

Numerical software has two unique bugs: (^1) roundoff error (^2) truncation error

Uncertainty: well- or ill-conditioned?

Errors in input data can cause uncertain results input data can be experimental or rounded. leads to a certain variation in the results well-conditioned: numerical results are insensitive to small variations in the input ill-conditioned: small variations lead to drastically different numerical calculations (a.k.a. poorly conditioned)

Our Job

As numerical analysts, we need to (^1) solve a problem so that the calculation is not susceptible to large roundoff error (^2) solve a problem so that the approximation has a tolerable truncation error

How? incorporate roundoff-truncation knowledge into I (^) the mathematical model I (^) the method I (^) the algorithm I (^) the software design awareness → correct interpretation of results

Intel

Intel

Intel Timeline

from emery.com FROM: Dr. Thomas R. Nicely Professor of Mathematics Lynchburg 1501 Lakeside College Drive Lynchburg, Virginia 24501- Phone: 804-522- Fax: 804-522- Internet: [email protected] TO: Whom it may concern RE: Bug in the Pentium FPU DATE: 30 October 1994 It appears that there is a bug in the floating point unit (numeric coprocessor) of many, and perhaps all, Pentium processors. In short, the Pentium FPU is returning erroneous values for certain0001/824633702441.0 division operations. For example, is calculated incorrectly (all digits beyond the eighth significant digit are in error). This can be verified in compiled code,or Excel, or even an ordinarythe Windows spreadsheet calculator such (use as theQuattro Pro scientific mode), by computing which00(824633702441.0)*(1/824633702441.0), should equal 1 exactly (within some extremely small rounding error; in general, coprocessor results should contain 19Pentiums tested significant return decimal digits). However, the

.. .

Intel Timeline

from emery.com

Nov 1, 1994 Software company Phar Lap Software receives Nicely’s email. Sends to collegues at Microsoft, Borland, Watcom, etc. decide the error will not impact many people. Keep the issue internal. Nov 2, 1994 Email with description goes global. Nov 15, 1994 USC reverse-engineers the chip to expose the problem. Intell still denies a problem. Stock falls. Nov 22, 1994 CNN Moneyline interviews Intel. Says the problem is minor. Nov 23, 1994 The MathWorks develops a fix. Nov 24, 1994 New York Times story. Intel still sending out flawed chips. Will replace chips only if it caused a problem in an important application. Dec 12, 1994 IBM halts shipment of Pentium based PCs Dec 16, 1994 Intel stock falls again. Dec 19, 1994 More reports in the NYT: lawsuits, etc. Dec 20, 1994 Intel admits. Sets aside $420 million to fix.

Pentium Bug

Consider A −

A

B

∗ B = 0 (1)

Zero or non-zero? A = 4 , 295 , 835 .0 and B = 3 , 145 , 727. 0 A − AB ∗ B = 256 on a Pentium

Q: How many Pentium engineers does it take to screw in a light bulb? A: 0.

Digital Representation

Can only use a finite number of digits to represent a number

  • reduces cost
  • reduces memory
  • errors bit: binary (0 or 1) byte: 8 bits word: smallest addressable unit of memory for a certain computer

Goal

represent numbers with a finite number of bits (1-4 words)

Integer Algorithm

An algorithm to compute the base 2 representation of a base 10 integer (N) 10 = (bj bj− 1... b 2 b 0 ) 2 = bj · 2 j^ + · · · + b 1 · 21 + b 0 · 20 Compute (N) 10 / 2 = Q + R: N 2 =^ bj^ ·^2

j− (^1) + · · · + b 1 · 20 ︸ ︷︷ ︸ =Q

b 0 ︸︷︷︸^2 =R/ 2

Example Example: compute ( 11 ) 10 base 2 11 / 2 = 5 R 1 ⇒ b 0 = 1 5 / 2 = 2 R 1 ⇒ b 1 = 1 2 / 2 = 1 R 0 ⇒ b 2 = 0 1 / 2 = 0 R 1 ⇒ b 3 = 1

So ( 11 ) 10 = ( 1011 ) 2

Integers

A = ones(3,3,’uint8’); B = ones(3,3,’uint16’); C = ones(3,3); whos Name Size Bytes Class A 3x3 9 uint8 array B 3x3 18 uint16 array C 3x3 72 double array

uint8 range from 0 to 255 int8 range from -127 to 128

a= a = 129 b=uint8(a) b = 129 c=int8(a) c = 127 whos a b c Name Size Bytes Class a 1x1 8 double array b 1x1 1 uint8 array c 1x1 1 int8 array

Floating Point Algorithm

An algorithm to compute the binary representation of a fraction P:

P = 0 .b− 1 b− 2 b− 3... = b− 1 · 2 −^1 +...

Multiply P by 2. The integer part of 2P is b− 1

2 P = b− 1 · 20 + b− 2 · 2 −^1 + b− 3 · 2 −^2 +...

Example

Example:Compute the binary representation of 0.

2 · 0. 625 = 1. 25 ⇒ b− 1 = 1 2 · 0. 25 = 0. 5 ⇒ b− 2 = 0 2 · 0. 5 = 1. 0 ⇒ b− 3 = 1

So ( 0. 625 ) 10 = ( 0. 101 ) 2

Floating Point Representation

We write the floating points as

± 0 .d 1 d 2 d 3... dn × 10 s

d 1... dn are the (base 10) matissa s is the exponent Or in binary: ± 0 .b 1 b 2 b 3... bn × 10 t Precision: single-precision: 32-bit values for the sign, mantissa, exponent double-precision: 64-bit values for the sign, mantissa,