help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a-b+b != a


From: Tim Pierce
Subject: Re: a-b+b != a
Date: Mon, 4 Sep 2017 20:41:55 +0100

TL DR; addition, subtraction, mult and div do not hold with mathematical identities

Addition, subtraction, mult and div all run the risk of 'losing accuracy' 

So every one of those operations can 'break' an identity contrasted with pure maths

Put another way, 

Try this to illustrate to yourself

        > 1e-20 + 1e20

or 

        > 2e-20 + 2e20 - 2e20

or if you really want to 'blow your mind'

        > -0

        > 0

This is worth knowing, so if you need to perform  

        ( x /10000 )* 8

 for example it will 9 times out of 10 be more 'accurate' to compute

        ( x * 8 ) / 10000

because div by a large amount is more likely to 'truncate' detail than mult ...




On Mon, Sep 4, 2017 at 5:56 PM, Tim Pierce <address@hidden> wrote:
No way! It's correct

in pure mathematics b - a + a = b

in computing it is not true that b -a + a = b

floating points and doubles and rounding mean that it is definitely NOT the case that mathematical identities hold

On Mon, Sep 4, 2017 at 3:53 PM, stn021 <address@hidden> wrote:
Hi,

this is weird:

r1 = round( 1e3*randn(5) ) / 1e3 ;
r2 = round( 1e3*randn(5) ) / 1e3 ;
r3 = r1 - r2 + r2 ;
not_zero = r1 - r3

not_zero =

   0.0000e+00   0.0000e+00   5.5511e-17   0.0000e+00   1.1102e-16
   5.5511e-17   0.0000e+00   0.0000e+00   0.0000e+00   0.0000e+00
   0.0000e+00   0.0000e+00   0.0000e+00   0.0000e+00  -2.0817e-16
  -5.5511e-17   0.0000e+00   0.0000e+00  -1.1102e-16   0.0000e+00
   2.7756e-17   0.0000e+00   0.0000e+00   0.0000e+00   0.0000e+00

So a-b+b != a

The difference to zero is small, around 1e-17. But iterations can
cause this error to increase.

I use leasqr() and in each iteration the last line is
  retval = retval - someval + someval

With that additional line I get quite different results compared to
the same program without this line even though they should be
identical.

Is there a way to avoid this phenomenon ?

THX
Stefan

_______________________________________________
Help-octave mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-octave



reply via email to

[Prev in Thread] Current Thread [Next in Thread]