# Changes in Handling of Real Zeros

I recently upgraded from Mathematica 5 to Mathematica 8 and I have a number of notebooks that no longer work correctly. The problems relate to the use of units. I don't need complicated unit conversions so I typically just tag values with symbols for the units. Under Mathematica 5, I could write the following (I understand that this example isn't physically meaningful):

3. in + 4. in - 7. in + 5. lb


And Mathematica would return

5. lb


Now, under Mathematica 8, I get

0. + 5. lb


This breaks a large number of notebooks. Can someone explain what is happening, and what if anything I can do to get the old behavior back?

Thanks!

Only precise zero coefficients are eliminated. Use Chop:

3. in + 4. in - 7. in + 5. lb // Chop

5. lb


Leonid admonished me for posting a method overloading Times. I didn't honestly expect anyone to use that and I think I made that pretty clear in the original post.

Nevertheless, here is a safer method that only affects uses of specified units:

units = {in, lb};

(# /: 0. # := 0 #) & /@ units;

3. in + 4. in - 7. in + 5. lb

5. lb

• You have just committed a deadly sin (and you know about it): nothing can excuse overloading Times (or similar commands) globally. Why don't you use a local dynamic environment? I am afraid that your answer in its present form will lead to many lost souls. Mar 31, 2012 at 2:24
• I would actually propose this: \$Post = (# /. HoldPattern[Times[0., x : __ : 1]] :> Times[0, x]) &. Mar 31, 2012 at 2:32
• @Leonid naughty, aren't I? :-> The problem with Post is that it only affects the output. If I remove the overloading method will you vote for Chop? Mar 31, 2012 at 2:57
• @LeonidShifrin Though I completely agree that it is bad practice to overload arithmetic functions like Times the fan boy in me loves the fact that we can. Mathematica is like putty in the hands, leaving us free to experiment with it in ways that just aren't possible in most places. Mar 31, 2012 at 4:05
• Thanks for the answers. I can't try anything until Monday, but I really appreciate the quick response! Mar 31, 2012 at 15:44