- labels: --> 460522
Maxima is sloppy about simplifications involving floating-
point numbers.
Notation: ==> means simplifies to
(OK) means I think this is correct
(No!) means I think this is incorrect
1.0*x ==> x (No!) Prefer: 1.0*x
though
2.0*x ==> 2.0*x (OK)
0.0*x ==> 0.0 (OK)
2.0*x-2.0*x ==> 0 (No!) Prefer: 0.0
though
2.0-2.0 ==> 0.0 (OK)
(2.0-2.0)*x ==> 0.0 (OK)
x^1.0 ==> x (No!) Prefer: x^1.0
though
x^2.0 ==> x^2.0 (OK)
x^-1.0 ==> x^-1.0 (OK) (normally displays as 1/
(x^1.0))
x+0.0 ==> x (???)
I am not sure whether this is correct.
All the above cases also happen with mixed float/fixed
and with bfloats.
----------------
Whenever the result depends on the floating-point
precision, the float must be maintained.
Because of the the changes with revision 1.80 to TMS, TIMESIN and PLUSIN in simp.lisp some more examples simplifies correctly.
When we add the following code to PLUSIN, even more examples simplify as expected.
;; (cadadr fm) is zero, add it to the first term of fm to preserve the type.
(rplaca fm (add (car fm) (cadadr fm)))
(return (rplacd fm (cddr fm)))
These are some results. First for floating point numbers;
(%i28) 0.0*x;
(%o28) 0.0
(%i29) 1.0*x;
(%o29) 1.0*x
(%i30) 2.0*x-2.0*x;
(%o30) 0.0
The simplification with bigfloat numbers:
(%i31) 0.0b0*x;
(%o31) 0.0b0
(%i32) 1.0b0*x;
(%o32) 1.0b0*x
(%i33) 2.0b0*x-2.0b0*x;
(%o33) 0.0b0
And some examples with mixed numbers:
(%i34) 2*x-2.0*x;
(%o34) 0.0
(%i35) 2.0*x-2*x;
(%o35) 0.0
(%i36) 2.0b0*x-2*x;
(%o36) 0.0b0
(%i37) 2.0b0*x-2.0*x;
(%o37) 0.0b0
Only the example x^1.0 --> x^1.0 is missing. This can be changed in simpexpt.
Dieter Kaiser
The suggested change to PLUSIN has been committed with revision 1.81 of simp.lisp. Furthermore code to preserve the type of the numbers 1.0 and 1.0b0 has been added to the function EXPTRL.
We get the expected results of the last posting and in addition:
(%i3) x^1.0;
(%o3) x^1.0
(%i4) x^1.0b0;
(%o4) x^1.0b0
Closing this bug report as fixed.
Hint: It is possible to construct more complicated expressions, where we lose the type of the number again. Perhaps we should open a new bug report for such cases.
Dieter Kaiser