Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rounding error bug in UCBLogo?

11 views
Skip to first unread message

rot...@googlemail.com

unread,
Nov 23, 2009, 10:36:21 AM11/23/09
to
Hello

I'm currently reading 'Approaching Precalculus Mathematics Discretely'
by Philip G. Lewis[1] and I seem to be experiencing a rounding error
bug in UCBLogo 6.0 built on Ubuntu 9.10 (Karmic) GNU/Linux.

If I define the summation of two vectors (represented by Logo lists):

to vsum :v1 :v2
op list sum first :v1 first :v2 ~
sum last :v1 last :v2
end

And then I define scalar multiplication:

to scalar :num :vect
op list product :num first :vect ~
product :num last :vect
end

And then I try to perform linear combination:

? show vsum scalar 0.6 [1 -1] scalar 0.2 [2 3]

I get the answer

[1 1.11022302462516e-16]

It should, of course, be [1 0].

Doing

? trace [vsum scalar sum]
? show vsum scalar 0.6 [1 -1] scalar 0.2 [2 3]

Returns

( scalar 0.6 [1 -1] )
scalar outputs [0.6 -0.6]
( scalar 0.2 [2 3] )
scalar outputs [0.4 0.6]
( vsum [0.6 -0.6] [0.4 0.6] )
( sum 0.6 0.4 )
sum outputs 1
( sum -0.6 0.6 )
sum outputs 1.11022302462516e-16
vsum outputs [1 1.11022302462516e-16]
[1 1.11022302462516e-16]

Running both sum and vsum on the appropriate literal input works fine.

Sadly I don't know enough about number representation or C to even
begin to determine why this is. Is it a bug? Did I compile UCBLogo
wrong?

Thanks.

[1] http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=7162

--
Rothril

winston19842005

unread,
Nov 23, 2009, 4:00:24 PM11/23/09
to
On 11/23/09 10:36 AM, in article
7cd124d6-31f5-4cd4...@j9g2000vbp.googlegroups.com,
"rot...@googlemail.com" <rot...@googlemail.com> wrote:

No! Not a bug, but a limitation of the number representation utilized in the
computer.

I'd suggest going to Wikipedia and reading about number representation with
computers.

Waldek Hebisch

unread,
Dec 10, 2009, 5:05:56 PM12/10/09
to

This is limitation of _all_ systems using floating point numbers.
If you want exact calculation you need something which supports
true rational numbers -- I am not aware of any Logo that do.
For exact computations you may consider using a computer algebra
system like Maxima or FriCAS (both will take you _quite_ far into
mathematical computations). Or maybe a programming language
like Lisp or Pop11 (both can do rationals, but have little math
support beyond that).

--
Waldek Hebisch
heb...@math.uni.wroc.pl

0 new messages