help-octave
[Top][All Lists]
Advanced

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

Re: Negative zeros?


From: Vic Norton
Subject: Re: Negative zeros?
Date: Wed, 14 Sep 2005 13:50:00 -0400

That does it, Ted! Thanks so much! I put the single line
   x += 0;
at the appropriate point in my code, and all of the ridiculous -0.0%'s in the output disappeared.

Regards,

Vic

At 2:51 AM +0100 9/14/05, Ted Harding wrote:
On 14-Sep-05 Vic Norton wrote:
 OK, so there isn't easy way. So I'll just have Perl strip all the
 minus signs from my -0.0's.

 Regards,

 Vic

Or you could simply add 0:

octave:6> (-0)
ans = -0
octave:7> (-0)+0
ans = 0
octave:8> 0+0
ans = 0

(be careful with parentheses though ... )

Regarding your other post ("I am a matheatician and zero is zero is
zero"):

I'm one too, and I agree that that is the case in the real number
system.

However, the binary represntations of numbers in digital computers
are not real numbers nor even isomorphic to them. They are neurotic
little entities with minds of their own, especially when they interact.
The articles by Goldberg and others depict the struggle to get their
behaviour to reasonably mimic the behaviour of real real numbers.

There are certain things which will never work in a finite-length
representation. One of my favourites is the following iterative
system:

  x(n+1) = 2*x(n) if 0 <= x(n) <= 1/2
  x(n+1) = 2*(1 - x(n)) if 0.5 <= x(n) <= 1

This is a chaotic system. It has two equilibrium points: x=0
and x=2/3, and the latter is unstable. Implement this in octave
as:

  function y = Next(x)
  if( x<=1/2) y=2*x else y=2*(1-x)
  endif
  endfunction

Clearly, if x=2/3 then Next(x)=2/3:

  x=2/3;Next(x)
  ans = 0.66667

Now try:

  x=2/3; for i = 1:60 x=Next(x) endfor

As you can see, it drifts off and then reaches the stable equilibrium
at x=0, which it does on the 58th iteration. In fact, as you can see,
each multiplication by 2 shifts the binary representation of the
fraction to the left by 1 place, filling in with 0s from the right.
So it stops after at most (n+1) steps where n is the number of bits
in the binary representation of the mantissa of a real number.

Apart from these two equilibria (of "period 1"), there are mathematical
points which have period 2, 3, ... , k, ... where a pointof period k
is of the form s/(2^k +/- 1), with s an integer; and all such
points are also unstable. This is quite easily proved mathematically.

However, experimentation will show that in octave they all collapse
onto 0 exactly as 2/3 did.

This behavious, as explained above, is due to the finite represntation
in binary format, and the fact that none of the equilibrium points
s/(2^k +/- 1) has an exact binary represntation.

The only reals with an exact binary represntation in [0,1] are
of the form s/2^k, and none of these is an equilibrium nor periodic
and indeed mathematically all collapse to 0 under multiplcation by 2.

Then there are all the points which are not of the form s/2^k
or s/(2^k +/- 1). Evolution from any of these should be chaotic.
But you will never observe this in a simulation, since they
all collapse to 0 too in at most (n+1) steps.

So here we have a simple case where the computer simply disobeys
mathematics, at the "high finger" level. In the face of that, I can
live with "-0 != 0"!

Ah well ... !!

Best wishes,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 094 0861
Date: 14-Sep-05                                       Time: 02:45:25
------------------------------ XFMail ------------------------------


--
*---* http://www.ridehsta.com
|     Vic Norton
|     Bowling Green, OH
|     BMW R1200GS (2005)
*---* http://vic.norton.name/moto



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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