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