I am using the AutomaticUnits package in Mathematica 10, and I am writing some unit checking functions. However, I run into a problem when I have an Infinity, since Infinity*Meter = Infinity, unlike 0*Meter = 0 Meter. However, it seems to work when I do Unit[Infinity, "Meter"]. Is there a way I can get Mathematica to set Infinity*Meter = Unit[Infinity,"Meter"]?

I tried

Unprotect[Times]; Times[Infinity,x_Unit]=Unit[Infinity,Last[x]]

but the Times on the left hand side was evaluated first as shown by the DownValue

({HoldPattern[\[Infinity] x_Unit] :> Unit[Infinity, Last[x]]})

  • $\begingroup$ You may try Meter /: Infinity Meter := Unit[Infinity, "Meter"]. It seems to work but I have not tested it with the packages concerned. Do not try to modify core arithmetic functions like Times; they have special evaluation semantics and your own rules are likely to be ignored in certain contexts, or even to unexpectedly disappear altogether. $\endgroup$ – Oleksandr R. Jul 23 '15 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.