Video 1: Rounding errors -0 A number system can be represented as ! - - PowerPoint PPT Presentation

video 1 rounding errors 0
SMART_READER_LITE
LIVE PREVIEW

Video 1: Rounding errors -0 A number system can be represented as ! - - PowerPoint PPT Presentation

Video 1: Rounding errors -0 A number system can be represented as ! = 1. & ! & " & # & $ 2 % for ! [6,6] and ( ! {0,1} . = Lets say you want to represent the decimal number 19.625 using the binary number


slide-1
SLIDE 1

Video 1: Rounding errors

slide-2
SLIDE 2 A number system can be represented as ! = ±1. &!&"&#&$×2% for ! ∈ [−6,6] and (! ∈ {0,1}. Let’s say you want to represent the decimal number 19.625 using the binary number system above. Can you represent this number exactly?

=

(19.62540--40011.10112=4.00111014×2

"
  • 1. 0011×24
= 19 1.0100×24=20
slide-3
SLIDE 3

Machine floating point number

  • Not all real numbers can be exactly represented as a machine floating-point
number.
  • Consider a real number in the normalized floating-point form:
  • = ±1. ("(#($ … (% …× 2&
  • The real number - will be approximated by either -' or -(, the nearest two
machine floating point numbers. ! !& !' +∞ /#

bhtlbhtz

  • -
  • I

DO

g-

mnauchminwer X - = t.bibzbz-bnx2m-fasth.it

Xt=IntO.O0OOj0②x2m

④ 2m=Emx2m

slide-4
SLIDE 4 ! !& !' +∞ = q x 2M

Xt

= X - t Emt 2M

/ Ht

)- E

= Em x 2M

!

<gap=Em

larger #

→ larger gap

slide-5
SLIDE 5

Rounding

The process of replacing ! by a nearby machine number is called rounding, and the error involved is called roundoff error. ! !& !' +∞ ! !' !& −∞ Round towards + ∞ Round towards − ∞ Round towards zero Round towards zero Round by chopping: + is positive number + is negative number Round up (ceil) ,- + = +! Rounding towards +∞ ,- + = +" Rounding towards zero Round down (floor) ,- + = +" Rounding towards zero ,- + = +! Rounding towards −∞ Round to nearest: either round up or round down, whichever is closer × - flex) =/flex) -Xl

De

Ies

s

00

↳ -OO

slide-6
SLIDE 6

Rounding (roundoff) errors

Consider rounding by chopping:
  • Absolute error:
  • Relative error:
!& !' !

fl

q

thx)

Heat

  • xkEm×Ig ¥µ¥FE¥

I

EmX2Mw

He¥gE:÷¥→mA=¥:÷n

tf

HE

slide-7
SLIDE 7

Rounding (roundoff) errors

)*(!) − ! |!| ≤ 0% The relative error due to rounding (the process of representing a real number as a machine number) is always bounded by machine epsilon.

1075

slide-8
SLIDE 8

IEEE Single Precision

)*(!) − ! |!| ≤ 2&"#≈ 1.2×10&/

IEEE Double Precision

)*(!) − ! |!| ≤ 2&0"≈ 2.2×10&!1

I

#

O =

÷÷÷:

'' "

I:÷÷÷÷

7-
slide-9
SLIDE 9

Gap between two machine numbers

Erskine

grneadmberrmamohimnwerfllx-XI.mx

  • I
= fxx)

flcxto) - few) a-

  • gap

8sgap

slide-10
SLIDE 10

Gap between two machine numbers

Rule ofthlehnbs

Binary x=q×2m

Decimal : x -qxlom

8 × =4.5×10 "

X=2

m
  • 23
double

ftp.?ngE%3fI#gap...osio'

" lo "

ftlxto) - flex)

8510 @ L2 's → fffxto)=flG)

gelo

  • "
→ fllxto)# G)
  • r > 2-
'5 → felxto) #flex

)

  • r> D-
" → ftlxto)#flex

)

slide-11
SLIDE 11

Gap between two machine numbers

8

8 =gap

k→1

m

¥¥*÷¥÷'

fe (

x) = I = (II =oftenHE

fflxto) =I

= flG)

If

what is the smallest

8 such that

flat8)

  • felt
⇒8L gap b
slide-12
SLIDE 12

Show Ipython notebook demos

In

practice :(Rule of Thumb)

Binary base x=qx2m

Decimal base

fflxto)

= fee) + = of

xD

'm n Example x -4.5×104 8 SEMI

¥

:÷÷.⇒*⇒§:÷÷÷

:*

.

if

852
  • '5→fffxt8)=feK

)

  • therwise feats) #ffcx)
slide-13
SLIDE 13

Video 2: Arithmetic with machine numbers

slide-14
SLIDE 14

Mathematical properties of FP operations

Not necessarily associative: For some ! , #, $ the result below is possible: ! + # + $ ≠ ! + (# + $) Not necessarily distributive: For some ! , #, $ the result below is possible: $ ! + # ≠ $ ! + $ # Not necessarily cumulative: Repeatedly adding a very small number to a large number may do nothing
slide-15
SLIDE 15

Floating point arithmetic (basic idea)

  • First compute the exact result
  • Then round the result to make it fit into the desired

precision

  • ! + # = %& ! + #
  • ! × # = %& ! × #
! = (−1)! 1. ( × 2"
slide-16
SLIDE 16

Floating point arithmetic

Consider a number system such that ! = ±1. ,!,",#×2% for ! ∈ [−4,4] and (! ∈ {0,1}. Rough algorithm for addition and subtraction:
  • 1. Bring both numbers onto a common exponent
  • 2. Do “grade-school” operation
  • 3. Round result
  • Example 1: No rounding needed
  • = 1.101 " ×2!
, = 1.001 " ×2! / = - + , = 10.110 " ×2! = 1.011 " ×2"

On

,

a .

O too

O es

slide-17
SLIDE 17

Floating point arithmetic

Consider a number system such that ! = ±1. ,!,",#×2% for ! ∈ [−4,4] and (! ∈ {0,1}.
  • = 1.101 " ×24
, = 1.000 " ×24 / = - + , = 10.101 " ×24
  • Example 2: Require rounding
  • = 1.100 " ×2!
, = 1.100 " ×2&! / = - + , = 1.100 " ×2! + 0.011 " ×2! = 1.111 " ×2!
  • Example 3:

in

{

O

✓- 1.0101×2

'

{

g

tllatb)-1.010×24

  • -
slide-18
SLIDE 18

Floating point arithmetic

Consider a number system such that ! = ±1. ,!,",#,$×2% for ! ∈ [−4,4] and (! ∈ {0,1}.
  • = 1.1011 " ×2!
, = 1.1010 " ×2!
  • Example 4:
/ = - − , = 0.0001 " ×2!

tF→p=5

{

}

I:i% :3:

  • 0.0001×2
'
  • i. ¥42
'

not sign

bits

fffa

  • b)=L .
2 '
slide-19
SLIDE 19

Floating point arithmetic

Consider a number system such that ! = ±1. ,!,",#,$×2% for ! ∈ [−4,4] and (! ∈ {0,1}.
  • = 1.1011 " ×2!
, = 1.1010 " ×2!
  • Example 4:
/ = - − , = 0.0001 " ×2! Or after normalization: / = 1. ? ? ? ? " ×2&#
  • There is not data to indicate what the missing digits should be.
  • Machine fills them with its best guess, which is often not good (usually
what is called spurious zeros).
  • Number of significant digits in the result is reduced.
  • This phenomenon is called Catastrophic Cancellation.
  • p=5

✓pill

a

slide-20
SLIDE 20

Loss of significance

Assume - and , are real numbers with - ≫ ,. For example
  • = 1. -!-"-#-$-0-1 … -5 …×24
, = 1. ,!,",#,$,0,1 … ,5 …×2&6 In Single Precision, compute - + ,
  • 1. -!-"-#-$-0-1-/-6-7 … -""-"#×24
f- 23

frat

0.00000001 bib . .- by b,sx2°

fllatb) ⇒

b- bits of

b=

slide-21
SLIDE 21

Cancellation

Assume - and , are real numbers with - ≈ ,.
  • = 1. -!-"-#-$-0-1 … -5 …×2%
, = 1. ,!,",#,$,0,1 … ,5 …×2% In single precision (without loss of generality), consider this example:
  • = 1. -!-"-#-$-0-1 … -"4-"!10-"$-"0-"1-"/ … ×2%
, = 1. -!-"-#-$-0-1 … -"4-"!11,"$,"0,"1,"/ …×2% , − - = 0.0000 … 0001×2%

O

=

FE#%

tub-a)= I .

2-23×2

m not sig .
slide-22
SLIDE 22

Examples:

1) 1) 2 and 3 are real numbers with same order of magnitude (4 ≈ 6). They have the following representation in a decimal floating point system with 16 decimal digits of accuracy: 78 4 = 3004.45 78 6 = 3004.46 How many accurate digits does your answer have when you compute 6 − 4?
  • g

.

O

lldigits

  • 11 digits
slide-23
SLIDE 23

Loss of Significance

How can we avoid this loss of significance? For example, consider the function 5 ! = !" + 1 − 1 If we want to evaluate the function for values ! near zero, there is a potential loss of significance in the subtraction. Assume you are performing this computation using a machine with 5 decimal accurate digits. Compute 5(10&#) f-(10-3)=110-7 - I 1.000000
  • to.QO.O.IO#

I

  • I

1.000001

=p

slide-24
SLIDE 24

Loss of Significance

Re-write the function 5 ! = !" + 1 − 1 to avoid subtraction of two numbers with similar order of magnitude

(

A -b)(atb) -
  • E
  • b
'

D

fastnet - D

e- GET '
  • C 15

HIT + I

N¥t

=

fH=n¥+⇒

tho-3 ;o÷=o÷¢

slide-25
SLIDE 25

Example:

If x = 0.3721448693 and y = 0.3720214371 what is the relative error in the computation of (x − y) in a computer with five decimal digits of accuracy? round - down

"

In't:I¥HEEzoox

  • X -y
= O. 0001234 322

:÷¥:÷÷at¥