Mathematica Asked by Francis Bush on March 23, 2021
When I enter this in Wolfram Mathematica V12:
0 Dogs + 5 Cats
Mathematica sensibly returns this:
5 Cats
BUT, if I using the Units and Quantity features
in Mathematica V12, and enter this:
0 m + 37 m/s
Or in long form:
Quantity[0, "Meters"] + Quantity[37, "Meters"/"Seconds"]
I get:
Quantity::compat: Meters/Seconds and Meters are incompatible units
I know the units are not compatible, but ZERO "Meters" is just 0
and should logically disappear from the equation just as "0 Dogs"
disappears from the first example.
This bug breaks most symbol differentiation and integration.
I guess Wolfram really screwed up by not making Units part of V1
back in the 1980’s, and instead added it as a glued on bag, in
V12. Talk about "creeping featurism" 😉
BTW, the only means I have found of controlling this horrible
Mathematica functionality is with pages of ugly substitution rules
like this:
removeUnitsOfZeroMagnitude[myExpression_] := Module[{},
myExpression /. Quantity[0, "Meters"] -> 0 /.
Quantity[0, "Meters"/"Seconds"] -> 0 /.
Quantity[0, "Meters"/"Seconds"^2] -> 0 /.
Quantity[0, "Meters"/"Seconds"^3] -> 0
]
Of course, this ugly hack makes simple one line calculations,
that were so beautiful and elegant in V4, now many lines of
nasty, unreadable code.
Am I doing something wrong?
Is Mathematica V4 still for sale?
Thanks,
Here is a more detailed image of the errors I am receiving in Mathematica V12 when trying to evaluate a simple integral. It seems to me in an evaluation like Times or Plus, or whatever, expressions of Units with ZERO magnitude should be removed, as one would do with simple pen and paper.
Is Mathematica V4 still for sale?
This answer proposes less drastic solutions than moving back for Version 4.
For the problems you encounter and approach you take one -- not that good -- proposal is to redefine Quantity
:
Unprotect[Quantity];
(*Quantity[x_,___]:=x;*)
Quantity[0, ___] := 0;
Protect[Quantity];
Remark 1: I have not checked or used the code above extensively -- it put it more as a "I share your pains" statement, and, sort of, to encourage other posts proposing solutions in that style.
Remark 2: With Quantity[x_,___]:=x;
you can "remove" the Quantity
functionalities from most computations. But that is also dangerous, because some built-in functions do rely on Quantity
working properly. For example, WeatherData
or FinancialData
. Personally, 95% of the time after ingesting data
with those functions I use data /. Quantity[x_, _] :> x
.
Quantity
re-defintionConsider using this function instead of the "global" approach above (and/or your removeUnitsOfZeroMagnitude
):
Clear[RemoveQuantity]
SetAttributes[RemoveQuantity, {HoldFirst}];
RemoveQuantity[myExpression_] := Block[{Quantity = #1 &}, myExpression];
Answered by Anton Antonov on March 23, 2021
Not a solution but an extended comment.
You misunderstand the physical underpinnings of quantities and units.
Every physical quantity has an inherent margin of error, even if it is very small (negligible) and thus tacitly suppressed. The quantity 1 meter truly means approximately 1 meter, give or take a few millimeters/nanometers/Planck distances.
The quantity 0 meters means a distance that is consistent with zero within the margin of my measurement's error. This error margin carries units, even if the mean value is precisely zero. So we cannot cancel out the units, and 0 meters is not equal to 0 apples or 0 seconds. Democritus had already pretty much figured this out 2500 years ago.
Mathematically, we observe that the point 0 is of zero measure on the real axis, and is the only point $x$ where $x$ meters could be said to be equal to nothing. But physical quantities refer to intervals, not points, on the real axis, and therefore the unit can never be cancelled out in the way you suggest.
Mathematica's behavior in this matter is thus completely expected and normal.
Answered by Roman on March 23, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP