Docsity

Finite Precision and Stability in Floating Point Arithmetic, Study notes of Criminal Justice

Toggle sidebar
bg1
Finite Precision
Floating Point Arithmetic
Stability
Numerical Matrix Analysis
Lecture Notes #10
— Conditioning and Stability —
Floating Point Arithmetic / Stability
Peter Blomgren,
Department of Mathematics and Statistics
Dynamical Systems Group
Computational Sciences Research Center
San Diego State University
San Diego, CA 92182-7720
http://terminus.sdsu.edu/
Spring 2010
Peter Blomgren, h[email protected]iFloating Point Arithmetic / Stability — (1/23)
Finite Precision
Floating Point Arithmetic
Stability
Outline
1Finite Precision
IEEE Binary Floating Point (from Math 541)
Non-representable Values — a Source of Errors
2Floating Point Arithmetic
“Theorem” and Notation
Fundamental Axiom of Floating Point Arithmetic
Example
3Stability
Introduction: What is the “correct” answer?
Accuracy — Absolute and Relative Error
Stability, and Backward Stability
Peter Blomgren, h[email protected]iFloating Point Arithmetic / Stability — (2/23)
Finite Precision
Floating Point Arithmetic
Stability
IEEE Binary Floating Point (from Math 541)
Non-representable Values — a Source of Errors
Finite Precision A 64-bit real number, double
The Binary Floating Point Arithmetic Standard 754-1985
(IEEE — The Institute for Electrical and Electronics Engineers)
standard specified the following layout for a 64-bit real number:
s c10 c9... c1c0m51 m50 ... m1m0
Where
Symbol Bits Description
s1 The sign bit — 0=positive, 1=negative
c11 The characteristic (exponent)
m52 The mantissa
r= (−1)s2c−1023 (1 + f),c=
10
X
k=0
cn2n,f=
51
X
k=0
mk
252−k
Peter Blomgren, h[email protected]iFloating Point Arithmetic / Stability — (3/23)
Finite Precision
Floating Point Arithmetic
Stability
IEEE Binary Floating Point (from Math 541)
Non-representable Values — a Source of Errors
IEEE-754-1985 Special Signals
In order to be able to represent zero,±∞, and NaN
(not-a-number), the following special signals are defined in the
IEEE-754-1985 standard:
Type S (1 bit) C (11 bits) M (52 bits)
signaling NaN u 2047 (max) .0uuuuu—u (*)
quiet NaN u 2047 (max) .1uuuuu—u
negative infinity 1 2047 (max) .000000—0
positive infinity 0 2047 (max) .000000—0
negative zero 1 0 .000000—0
positive zero 0 0 .000000—0
(*) with at least one 1 bit.
From http://www.freesoft.org/CIE/RFC/1832/32.htm
Peter Blomgren, h[email protected]iFloating Point Arithmetic / Stability — (4/23)
pf3
pf4
pf5

Partial preview of the text

Download Finite Precision and Stability in Floating Point Arithmetic and more Study notes Criminal Justice in PDF only on Docsity!

Finite Precision

Floating Point Arithmetic

Stability

Numerical Matrix Analysis

Lecture Notes #

— Conditioning and Stability —

Floating Point Arithmetic / Stability

Peter Blomgren,

[email protected]

Department of Mathematics and Statistics

Dynamical Systems Group

Computational Sciences Research Center

San Diego State University San Diego, CA 92182-

http://terminus.sdsu.edu/

Spring 2010

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (1/23)

Finite Precision

Floating Point Arithmetic

Stability

Outline

1

Finite Precision

IEEE Binary Floating Point (from Math 541) Non-representable Values — a Source of Errors

2

Floating Point Arithmetic

“Theorem” and Notation Fundamental Axiom of Floating Point Arithmetic Example

3

Stability

Introduction: What is the “correct” answer? Accuracy — Absolute and Relative Error Stability, and Backward Stability

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (2/23)

Finite Precision

Floating Point Arithmetic

Stability

IEEE Binary Floating Point (from Math 541)Non-representable Values — a Source of Errors

Finite Precision

A 64-bit real number,

double

The

Binary Floating Point Arithmetic Standard

(IEEE — The Institute for Electrical and Electronics Engineers)standard specified the following layout for a 64-bit real number:

s c

10

c

9

c

1

c

0

m

51

m

50

m

1

m

0

Where

Symbol

Bits

Description

s

The sign bit — 0=positive, 1=negative

c

The characteristic (exponent)

m

The mantissa

r

s

c

−

1023

f

c

10

∑ k

=

c

n

n

f

51

∑ k

=

m

k

52

−

k

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (3/23)

Finite Precision

Floating Point Arithmetic

Stability

IEEE Binary Floating Point (from Math 541)Non-representable Values — a Source of Errors

IEEE-754-1985 Special Signals

In order to be able to represent

zero

, and

NaN

(not-a-number), the following special signals are defined in theIEEE-754-1985 standard:

Type

S (1 bit)

C (11 bits)

M (52 bits)

signaling NaN

u

2047 (max)

.0uuuuu—u (*)

quiet NaN

u

2047 (max)

.1uuuuu—u

negative infinity

1

2047 (max)

.000000—

positive infinity

0

2047 (max)

.000000—

negative zero

1

0

.000000—

positive zero

0

0

.000000—

(*) with at least one 1 bit.

From

http://www.freesoft.org/CIE/RFC/1832/32.htm

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (4/23)

Finite Precision

Floating Point Arithmetic

Stability

IEEE Binary Floating Point (from Math 541)Non-representable Values — a Source of Errors

Examples: Finite Precision

r

s

c

−

1023

f

c

10

∑ k

=

c

n

n

f

51

∑ k

=

m

k

52

−

k

Example #

0

,

10000000000

,

100000000000000000000000000000000000000000000000000

r

1

= (

−

0

·

2

2

10

−

1023

·

(

1 +

1 2

)

= 1

·

2

1

·

3 2

= 3

.

0

Example #2 (The Smallest Positive Real Number)

0

,

00000000000

,

000000000000000000000000000000000000000000000000001

r

2

= (

−

0

·

2

0

−

1023

·

(

1 + 2

−

52

)

≈

1

.

113

×

10

−

308

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (5/23)

Finite Precision

Floating Point Arithmetic

Stability

IEEE Binary Floating Point (from Math 541)Non-representable Values — a Source of Errors

Examples: Finite Precision

r

s

c

−

1023

f

c

10

k

=

c

n

n

f

51

∑ k

=

m

k

52

−

k

Example #3 (The Largest Positive Real Number)

0

,

11111111110

,

111111111111111111111111111111111111111111111111111

r

3

=

(

−

0

·

2

1023

·

(

1 +

1 2

1

2

2

· · ·

1

2

51

1

2

52

)

=

2

1023

·

(

2

−

1

2

52

)

≈

1

.

798

×

10

308

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (6/23)

Finite Precision

Floating Point Arithmetic

Stability

IEEE Binary Floating Point (from Math 541)Non-representable Values — a Source of Errors

That’s Quite a Range!

In summary, we can represent

×

−

308

×

308

NaN

and a whole bunch of numbers in(

×

308

×

−

308

×

−

308

×

308

Bottom line:

Over- or under-flowing is usually not a problem inIEEE floating point arithmetic.

The problem in

scientific computing

is what we

cannot

represent.

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (7/23)

Finite Precision

Floating Point Arithmetic

Stability

IEEE Binary Floating Point (from Math 541)Non-representable Values — a Source of Errors

Fun with Matlab...

...Integers

53

53

53

53

53

53

53

53

realmax = 1

308

realmin = 2

−

308

eps = 2

−

16

The smallest not-exactly-representable integer is

53

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (8/23)

Finite Precision

Floating Point Arithmetic

Stability

“Theorem” and NotationFundamental Axiom of Floating Point ArithmeticExample

The Floating Point “Theorem”

ǫ

mach

“Theorem” Floating point “numbers” represent intervals! Notation:

We let

fl

x

) denote the floating point representation

of

x

R

The relative gap defines

ǫ

mach

x

R

, there exists

ǫ

with

ǫ

ǫ

mach

such that

fl

x

x

ǫ

In 64-bit floating point arithmetic

ǫ

mach

×

−

16

. In matlab,

the command

eps

returns this value.

Let the symbols

and

denote the floating-point

operations: addition, subtraction, multiplication, and division.

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (13/23)

Finite Precision

Floating Point Arithmetic

Stability

“Theorem” and NotationFundamental Axiom of Floating Point ArithmeticExample

Floating Point Arithmetic

ǫ

mach

All floating-point operations are performed up to some precision, i.e.

x

y

fl

x

y

x

y

fl

x

y

x

y

fl

x

y

x

y

fl

x

y

This paired with our definition of

ǫ

mach

gives us

Axiom (The Fundamental Axiom of Floating Point Arithmetic) For all

x

y

F

(where

F

is the set of floating point numbers),

there exists

ǫ

with

ǫ

ǫ

mach

, such that

x

y

x

y

ǫ

x

y

x

y

ǫ

x

y

x

y

ǫ

x

y

x

y

ǫ

That is

every operation of floating point arithmetic is exact

up to a relative error of size at most

ǫ

mach

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (14/23)

Finite Precision

Floating Point Arithmetic

Stability

“Theorem” and NotationFundamental Axiom of Floating Point ArithmeticExample

Example: Floating Point Error

Scaled by 10

10

Consider the following polynomial on the interval [

08]:

p

(

x

)

=

(

x

−

9

=

x

9

−

18

x

8

  • 144

x

7

−

672

x

6

  • 2016

x

5

−

4032

x

4

  • 5376

x

3

−

4608

x

2

  • 2304

x

−

512

2

−1.

−

−0.

0

1

p(x) = x

9

−18x

8

+144x

7

−672x

6

+2016x

5

−4032x

4

+5376x

3

−4608x

2

+2304x−

p(x) as abovep(x) = (x−2)

9

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (15/23)

Finite Precision

Floating Point Arithmetic

Stability

Introduction: What is the “correct” answer?Accuracy — Absolute and Relative ErrorStability, and Backward Stability

Stability

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (16/23)

Finite Precision

Floating Point Arithmetic

Stability

Introduction: What is the “correct” answer?Accuracy — Absolute and Relative ErrorStability, and Backward Stability

Stability: Introduction

1 of 3

With the knowledge that

“(floating point) errors happen,”

we

have to re-define the concept of the

“right answer.”

Previously, in the context of

conditioning

we defined a

mathematical problem as a map

f

X

Y

where

X

C

n

is the set of data (input), and

Y

C

m

is the set of

solutions.

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (17/23)

Finite Precision

Floating Point Arithmetic

Stability

Introduction: What is the “correct” answer?Accuracy — Absolute and Relative ErrorStability, and Backward Stability

Stability: Introduction

2 of 3

We now define an implementation of an

algorithm

— on a floating-point

device, where

F

satisfies the fundamental axiom of floating point

arithmetic — as another map

˜f

:

X

→

Y

i.e.

˜f

(

˜x

)

∈

Y

is a numerical solution of the problem.

Wiki-History: Pentium FDIV bug The Pentium FDIV bug was a bug in Intel’s original Pentium FPU.Certain FP division operations performed with these processors wouldproduce incorrect results. According to Intel, there were a few missingentries in the lookup table used by the divide operation algorithm.Although encountering the flaw was extremely rare in practice (

Byte

Magazine

estimated that 1 in 9 billion FP divides with random

parameters would produce inaccurate results), both the flaw and Intel’sinitial handling of the matter were heavily criticized. Intel ultimatelyrecalled the defective processors.

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (18/23)

Finite Precision

Floating Point Arithmetic

Stability

Introduction: What is the “correct” answer?Accuracy — Absolute and Relative ErrorStability, and Backward Stability

Stability: Introduction

3 of 3

The task at hand is to make

useful

statements about ˜

f

˜x

Even though ˜

f

x

) is affected by many factors — roundoff errors,

convergence tolerances, competing processes on the computer

∗

etc; we will be able to make (maybe surprisingly) clear statementsabout ˜

f

˜x

∗

Note that depending on the memory model, the previous stateof a memory location

may

affect the result in

e.g.

the case of

cancellation errors: If we subtract two 16-digit numbers with 13common leading digits, we are left with 3 digits of valid infor-mation. We tend to view the remaining 13 digits as “random.”But really, there is nothing random about what happens insidethe computer (we hope!) — the “randomness” will depend onwhat happened previously... Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (19/23)

Finite Precision

Floating Point Arithmetic

Stability

Introduction: What is the “correct” answer?Accuracy — Absolute and Relative ErrorStability, and Backward Stability

Accuracy

The

absolute error

of a computation is

˜f

˜x

f

˜x

and the

relative error

is

˜f

˜x

f

˜x

f

x

this latter quantity will be our standard measure of error.If ˜

f

is a good algorithm, we expect the relative error to be small, of

the order

ǫ

mach

. We say that ˜

f

is

accurate

if

˜x

X

f

˜x

f

˜x

f

˜x

O

ǫ

mach

Peter Blomgren,

〈

[email protected]

〉

Floating Point Arithmetic / Stability

— (20/23)