# Mathematica won't simplify multiplication by zero

I'm getting a huge output, but it appears that almost every term should actually be zero, unless I'm misunderstanding the expression.

For example, part of the output reads

a (0.25 + 0. b) + b^2 (0. + 0./c) + b (-1. + 0. c) - 0.5 c + (b (-1. b - 0.5 c) c)/a^2


Simplify and FullSimplify won't get rid of these zero terms even with assumptions that a,b and c are real and non-zero. Suggestions ?

• expr /. {x_Real /; x==0 -> 0} – ssch Oct 28 '13 at 17:32
• Examine the FullForm of the result. You may be surprised. Chop is useful too. – Sjoerd C. de Vries Oct 28 '13 at 17:33
• SetOptions[Simplify, TransformationFunctions :> Function[x, x //. {0. -> 0, 1. y_ :> y, -1. y_ :> y}]] and then Simplify simplifies as you want. – Rolf Mertig Oct 28 '13 at 18:29
• @RolfMertig. I think you meant to write -1. y_ :> -y – RunnyKine Oct 28 '13 at 20:15
• @RunnyKine : sure. thanx. – Rolf Mertig Oct 28 '13 at 22:27

To get what was said in the comments on record as an answer.

Chop is probably what you are looking for.

expr =
a (0.25 + 0. b) + b^2 (0. + 0./c) + b (-1. + 0. c) - 0.5 c +
(b (-1. b - 0.5 c) c)/a^2 // Chop

0.25 a - 1. b - 0.5 c + (b (-1. b - 0.5 c) c)/a^2


You might want to go further

expr = expr /. {1. x_ :> x, -1. x_ :> -x}

0.25 a - b - 0.5 c + (b (- b - 0.5 c) c)/a^2


### Update

In general expressions with inexact coefficients can contain the forms 0.x, 1.x, and -1.x. None of these cause computation difficulties, but they are unattractive, and often we want to eliminate them.

With a help from Mr.Wizard, I offer the following pattern to do this task.

fixerPattern = u_ /; Sign[u] == u :> Sign[u]


With this we can clean up

expr =
a (0.25 + 0. b) + b^2 (0. + 0./c) + 1.b (-1. + 0. c) - 0.5 c +
(b (-1. b - 0.5 c) c)/a^2


without using Chop and it takes care of the instances of both 1.b and -1.b.

expr /. fixerPattern • I think you'll want something like /. {c_ x_ /; c == 1 :> x, c_ x_ /; c == -1 :> -x} for generality? (As you used in a more recent answer...) – Mr.Wizard Jun 8 '17 at 2:17
• @Mr.Wizard. What do you think of /. c_ x_ /; Abs[c ] == 1 :> Sign[c] x as a more concise alternative? – m_goldberg Jun 8 '17 at 6:16
• Might not that affect complex values in a strange way? A contrived example: (0.5 + 0.8660254037844386 I) /. c_ /; Abs[c] == 1 :> foo – Mr.Wizard Jun 8 '17 at 6:47
• @Mr.Wizard. Good point, What about this? /. c_Real x_ /; Abs[c] == 1 :> Sign[c] x – m_goldberg Jun 8 '17 at 6:51
• I believe we could handle all three cases (including zero) with one rule: x_ /; Sign[x] == x :> Sign[x] – Mr.Wizard Jun 8 '17 at 7:08