# Simplifying expressions containing unit of zero magnitude

I have obtained the following form as a part of a computation:

k (Quantity[0, "Kilohertz"]) + Quantity[1/500, "Kilohertz"]


This is typeset as Here, k is an atom (representing an integer in my computation). Obviously I would like this to simplify to Quantity[2, "Hertz"], but I cannot figure out how to cause the term with k to vanish. Neither FullSimplify nor UnitSimplify have any effect here: My best guess is that Mathematica doesn't want to assume things about k, but given that the magnitude of the unit is 0, it should still simplify away.

How can I simplify this as I would expect?

• try Simplify[....,Assumptions->Element[k,Reals]] – george2079 Apr 5 '16 at 2:45
• @george2079 no dice. Same effect as without the Assumptions -- the form is untouched. – thirtythreeforty Apr 5 '16 at 4:11
• Related: (34967) – Mr.Wizard Jun 8 '17 at 2:12

You can do this:

Unprotect[Quantity]
Quantity /: Times[Quantity[mag_, unit_], seq__] :=
Quantity[Times[mag, seq], unit]


This will leads to your desired result, and also works for symbolic Times in Quantity

• That's a good idea. Is it wise to edit builtin rules like Quantity? Also, would Quantity[0, __] := 0 be a better rule or worse? (I don't know general conventions, thanks.) – thirtythreeforty Apr 5 '16 at 5:23
• @thirtythreeforty your idea also "edits" the built-in function (requires Unprotect[ Quantity]) . Which to do depends on your need. – vapor Apr 5 '16 at 5:40

Had the same problem and solved it by simply using a replacement rule.

k (Quantity[0, "Kilohertz"]) + Quantity[1/500, "Kilohertz"]

UnitConvert[Out /. Quantity[0, "Kilohertz"] -> 0, "Hertz"]


Here's what it looks like in a notebook: • People here generally like users to post code as Mathematica code instead of images or TeX, so they can copy-paste it. It makes it convenient. – user9660 Jun 5 '16 at 8:35
• Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – user9660 Jun 5 '16 at 8:35
• Louis, thanks for the formatting suggestion. – T. Zilla Jun 5 '16 at 17:37