## #324 Inconsistent simplification of 1.0*x etc.

closed
nobody
5
2009-06-25
2003-06-10
No

Maxima is sloppy about simplifications involving floating-
point numbers.
Notation: ==&gt; means simplifies to
(OK) means I think this is correct
(No!) means I think this is incorrect

1.0*x ==&gt; x (No!) Prefer: 1.0*x
though
2.0*x ==&gt; 2.0*x (OK)
0.0*x ==&gt; 0.0 (OK)

2.0*x-2.0*x ==&gt; 0 (No!) Prefer: 0.0
though
2.0-2.0 ==&gt; 0.0 (OK)
(2.0-2.0)*x ==&gt; 0.0 (OK)

x^1.0 ==&gt; x (No!) Prefer: x^1.0
though
x^2.0 ==&gt; x^2.0 (OK)
x^-1.0 ==&gt; x^-1.0 (OK) (normally displays as 1/
(x^1.0))

x+0.0 ==&gt; 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.

## Discussion

• Robert Dodier - 2006-07-07
• labels: --> 460522

• Robert Dodier - 2006-08-27
• labels: 460522 --> Lisp Core - Simplification

• Dieter Kaiser - 2009-06-24

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.
(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

• Dieter Kaiser - 2009-06-25

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

• Dieter Kaiser - 2009-06-25
• status: open --> closed