LOGO-L> floating point errors in MSWLogo 
Author Message
 LOGO-L> floating point errors in MSWLogo

Quote:
>    I recently wrote a Molecular dynamics simulation in MSW LOGO and
> ran into a problem in how LOGO handles floating points numbers. One
> of the calculations in the program was

>     make "time sum :delta_t :time

> Adding a delta_t of  0.02 to a time of  0  1640 times gave me a
> value of time that was 32.7799999999995 , that is a small error but
> an error none the less. The problem is that with more iterations of
> the
> program  the error grows exponential and after  a hour or so
> of running the simulations the values walk straight into the
> ether.
>  This poses a severe limitations on the type
> and scale of models that can be constructed in LOGO. I realize that
> I'm probably pushing LOGO beyond it intended domain but you except
> the correct answer from a computer

>   As a test of this error, I wrote the following program

> to  atest
> (local "times "number)
> make "number 0
> for [j 1 6 1 ]~
>   [ make "times power 10 :j
>     type [times -> ]
>     print :times
>     for[i 1 :times 1]~
>         [make "number sum :number 0.01]
>     type [result -> ]
>     print :number
>     make "number 0
>   ]
> end

>   Running the program produces the same wrong results on two different

> machines (one WIN95, the other WINNT).

This is no problem of LOGO but a problem of computer mathematics. 0.02
cannot be translated into binary code without rounding. So if you add
this number several times the error gets really important.
Kind regards
Anthony Haase
(This list has helped me so much during the few days that I can read it.
I'm glad that I could help too a little bit.)

---------------------------------------------------------------





Thu, 11 May 2000 03:00:00 GMT  
 LOGO-L> floating point errors in MSWLogo

OOps - where is a tail of my mail ??

Do not blame Logo for bad addition....

We may also see additions, which give no effect. For example 1000000000.1+0.0000001 give as the result 1000000000.1
We can use this effect to make some trick. Let's take a look on following procedure
(In this example global *makes* are applied intentionally, Yehuda - please don't extract them this time)

to xsum
 make "a0 :a
 make "a :a0 + :delta
 make "b1 :a0 - :a
 make "b2 :b1 + :delta
 make "b :b2 + :b
end

You may say, that :a0 + :delta - :a0 - :delta  equals 0. This is true in arithmetic, but not on floating point computation. Small difference will be gathered in variable :b. Please repeat xsum 1640 times with :a0=0 :delta=0.02 (all other variables should start with 0 also) and take :a+:b as the result. You will get 32.8 exactly. With :delta about 0.000000001

Best regards
Andrzej B.

---------------------------------------------------------------





Thu, 11 May 2000 03:00:00 GMT  
 LOGO-L> floating point errors in MSWLogo

Quote:
> Adding a delta_t of  0.02 to a time of  0  1640 times gave me a
> value of time that was 32.7799999999995 , that is a small error but
> an error none the less.

Are you sure it was 32.7799999999995 and not 32.799999999995?  If so, it
cannot be explained by the limited floating point accuracy of the machine.

Chuck
---------------------------------------------------------------





Fri, 12 May 2000 03:00:00 GMT  
 LOGO-L> floating point errors in MSWLogo

I hope you received the many replies.

In addition you can try working in integer mode to minimize
floating point errors. This of course may not always be applicable
to your porblem. It is an "art" learning how to manage floating point
errors.

to  atest
(local "times "number)
make "number 0
for [j 1 6 1 ]~
  [ make "times power 10 :j
    type [times -> ]
    print :times
    for[i 1 :times 1]~
        [make "number sum :number 1]
    type [result -> ]
    print :number / 100
    make "number 0
  ]
end

Quote:


> just re-posting Tony Gauvin's bounced message.

> -John

> Date - Fri, 21 Nov 1997 16:15:34 -0800

> To - logo-l-mod


> Received: from gandalf.umcs.maine.edu (GANDALF.umcs.maine.edu [130.111.112.21])
>         by gsn.org (8.8.8/8.8.8) with SMTP id QAA07681






> Date: Fri, 21 Nov 1997 19:15:54 -0500
> MIME-Version: 1.0
> Content-type: text/plain; charset=US-ASCII
> Content-transfer-encoding: 7BIT
> Subject: Help - floating point errors in MSWlogo


> X-pmrqc: 1
> Priority: normal
> X-mailer: Pegasus Mail for Windows (v2.42a)

>    I recently wrote a Molecular dynamics simulation in MSW LOGO and
> ran into a problem in how LOGO handles floating points numbers. One
> of the calculations in the program was

>     make "time sum :delta_t :time

> Adding a delta_t of  0.02 to a time of  0  1640 times gave me a
> value of time that was 32.7799999999995 , that is a small error but
> an error none the less. The problem is that with more iterations of the
> program  the error grows exponential and after  a hour or so
> of running the simulations the values walk straight into the
> ether.
>  This poses a severe limitations on the type
> and scale of models that can be constructed in LOGO. I realize that
> I'm probably pushing LOGO beyond it intended domain but you except
> the correct answer from a computer

>   As a test of this error, I wrote the following program

> to  atest
> (local "times "number)
> make "number 0
> for [j 1 6 1 ]~
>   [ make "times power 10 :j
>     type [times -> ]
>     print :times
>     for[i 1 :times 1]~
>         [make "number sum :number 0.01]
>     type [result -> ]
>     print :number
>     make "number 0
>   ]
> end

>   Running the program produces the same wrong results on two different
> machines (one WIN95, the other WINNT).
> ********************************************************************

>   Tony Gauvin                       (207) 581-1367

>   109 Neville Hall
>   Dept of Computer Science
>   University of Maine
>   Orono Me 04469

>           HTTP://www.umfk.maine.edu/hpage/tony/menu.htm

> ******************************************************************************

> ---------------------------------------------------------------




--
===============================================================
George Mills

http://www.softronix.com
The www page contains some very powerful educational software.
Our single most important investment is our kids.
---------------------------------------------------------------





Fri, 12 May 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. LOGO-L> Floating point errors

2. LOGO-L> Floating point trick once more

3. LOGO-L> Re - floating point errors in MSWLogo

4. LOGO-L> Re: floating point errors in MSWLogo

5. LOGO-L> PC-LOGO syntax in MSWLogo

6. An alternative to floating point (was Re: Floating point non-exactness)

7. IBM 370 Floating point to IEEE floating point

8. Runtime Error M6104, Floating point error:overflow

9. LOGO-L> Re: MSWLogo

10. LOGO-L> MSWlogo for D. Barnett

11. LOGO-L> Web page + MSWLogo GUI Builder

12. LOGO-L> Bola magica (MSWLogo)

 

 
Powered by phpBB® Forum Software