bug in rational arithmetic ?



I think the confusion here is that someone has changed the semantics of bigfloats to make it "work" on some simple examples, and ignored the fact that this change is illusory and the change has broken it, in general.

In particular the single-float number 2.1
when converted to 100 bits, and printed in decimal again is

2.09999942779541015625b0

And bfloat(2.1)-21/10  should be about 5.722b-7

maxima 5.12.99  gets this wrong.


bfloat(2.1d0) should be

2.100000000000000088817841970012523233890533447265625b0

I suspect that someone introduced a gratuitous rounding in bigfloat conversion.  The only way one can justify this is if one assumes that it is OK for Maxima to    randomly perturb binary floating-point numbers to a nearby decimal number before converting to a binary number.

I suggest this be changed back.

RJF 




----- Original Message -----
From: Harald Geyer <Harald.Geyer at gmx.at>
Date: Sunday, August 5, 2007 2:45 pm
Subject: Re: [Maxima] bug in rational arithmetic ?

> > (%i1) r(x):= rationalize(x);
> > (%o1)                       r(x) := rationalize(x)
> > (%i2) r(2 + 3) - r(2) - r(3);
> > (%o2)                                  0
> > (%i3) r(2.1 + 3) - r(2.1) - r(3);
> > (%o3)                                  0
> > (%i4) r(2.1 + 3.2) - r(2.1) - r(3.2);
> >                                         1
> > (%o4)                           ---------------
> >                                  866076851417430
> > 
> > 
> > Is this a bug in arithmetic? 
> 
> No.
> 
> > Does maxima "assume" that 2.1 and 3.2 are floating point numbers
> > by default?
> 
> That's not an assumption that maxima makes but just the syntax.
> Any number written with a decimal point is read as float unless it
> is a bfloat.
> 
> > If so, how do I declare all numbers and variables to be rational
> > throughout a session?
> 
> If you want a rational then type 21/10 not 2.1.
> 
> You could also do stuff like the following macro, but if you need
> that, you most likely do something in an unnecessarily complicated
> way ...
> 
> (%i47) display2d:false;
> (%o47) false
> (%i48) r(x)::=(x::rationalize(ev(x)));
> (%o48) r(x)::=x::rationalize(ev(x))
> (%i49) a:2.1;
> (%o49) 2.1
> (%i50) r(a);
> (%o50) 21/10
> (%i51) a;
> (%o51) 21/10
> 
> With a sufficiently new version of maxima r([a,b,c]) works too.
> 
> Hope that explains,
> Harald
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>