2
$\begingroup$

Is this behavior long-standing? Expected?

Simplify[0. + 1. z, z > 0] (*-> 0.+1.z *) 

I'm using Mma 11.1. I do not recalling seeing this behavior before. (Bad memory?) It shows up all over the place. E.g.,

eq1 = 2.0 x == y eq2 = x + y == z Solve[eq1 && eq2, {x, y}, Reals] 

produces

{{x -> 0. + 0.333333 z, y -> 0. + 0.666667 z}} 

Why are the zero terms (often) not simplified away?

$\endgroup$
2
  • 2
    $\begingroup$ Approximate zero 0. is not simplified away because it does not represent an exact zero 0. It keeps the Precision of the equation MachinePrecision, no matter what happens to the other terms. You can use Chop to get rid of it, if desired. (Take care to use an appropriate tolerance.) $\endgroup$ Commented Jun 7, 2017 at 22:47
  • $\begingroup$ Related: (6994) $\endgroup$ Commented Jun 8, 2017 at 2:01

1 Answer 1

3
$\begingroup$

Edit

The behavior you discuss in your question has been around as long as I have been using Mathematica. As Michael E2 writes in his comment to the question it results from using inexact quantities in expressions.

Perhaps the following simple function would be of use to you.

fixup[expr_] := expr /. u_ /; Sign[u] == u :> Sign[u] 

Example of use

fixup[0. + 1. z] 

z

fixup[(0. + 1. z)/(0. + 2. z)^2] 

0.25/z

 fixup[{{x -> 0. + 0.333333 z, y -> 0. + 0.666667 z}}] 

{{x -> 0.333333 z, y -> 0.666667 z}}

$\endgroup$
1
  • $\begingroup$ Shorter: fixup[expr_] := expr /. u_ /; u == 0 || u == 1 :> Round[u] $\endgroup$ Commented Jun 8, 2017 at 1:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.