Dimensionless values VS symbols with unknown physical dimensions (bug?)

I’ve been playing a lot with new Mathematica 9 units support. It is very useful and so on…
But I’ve gone into one trouble. Initially I had a problem with plotting functions with some units.
The detailed story is here.
In short:

Plot[Evaluate@UnitConvert[e Quantity[0.001, "Meters"^3], "L"], {e, 0, 1}]

doesn’t work.
But these two variants work well:

Plot[Evaluate@UnitConvert[Quantity[0.001 e, "Meters"^3], "L"], {e, 0, 1}]
Plot[Evaluate@UnitConvert[Quantity[e, "m/m"] Quantity[0.001, "Meters"^3], "L"], {e, 0, 1}]

(By the way, does anybody know if Plot officially support units? In documentation and tutorials there are List*Plot functions everywhere, but nothing is said about Plot. Empirical investigation shows that “it supports, but not very much”.)

The behavior of Plot function is interesting, but it isn’t the most.
The most interesting thing is the fact that Mathematica lacks support of dimensionless symbolical expressions. Everything that is not numerical is “of unknown dimension”.
I’ll try to illustrate.
Numbers are dimensionless

In[]:= QuantityUnit[1]
Out[]= "DimensionlessUnit"

Meters are meters

In[]:= QuantityUnit[Quantity[1, "m"]]
Out[]= "Meters"

Unknown values are unknown

In[]:= Clear[a]

In[]:= QuantityUnit[a]
Out[]= QuantityUnit[a]

And everything seems OK so far.
But let’s try to make something more dimensionless :slight_smile:

In[]:= QuantityUnit[Quantity[1, "m"]/Quantity[1, "m"]]
Out[]= "DimensionlessUnit"

OK!

In[]:= QuantityUnit[Quantity[a, "m"]/Quantity[1, "m"]]
Out[]= QuantityUnit[a]

Oops. This should be a dimensionless “a”! But it’s not dimensionless now, It’s of unknown dimension.
Trying to force

In[]:= QuantityUnit@Quantity[a, "DimensionlessUnit"]
Out[]= QuantityUnit[a]

Failure again. “Quantity” was evaluated, but it was rendered to nothing.
This may seem correct from some point of view, but it is not.
This weak distinguishing leads to “strange” problems, like with plot, as it was shown earlier.
Stronger distinguishing would make dimensional analysis much more strict. No more problems with guessing if some value is really dimensionless, or I’ve just forgot to substitute some variable…
And more.
For dessert is the really ugly thing, that arises from the same origin:

In[]:= Quantity[Quantity[1, "m"], "m"]
Out[]= Quantity[1, ("Meters")^2]"

In real life… According to physics… According to common sense! “one meter of meters” is nonsense. This should rise an error. No way it can be a square meter. It’s impossible.

I always held in high respect the Wolfram stuff for their ability to make complex things simple without making them incorrect. But it seems like sometimes they make mistakes too. Or may be there is a good reason for this behavior? (except “it was easier to implement it this way”)

I think that adding a strict distinction between dimensionless values and values with unknown dimension will make Mathematica more strict, logical, correct and robust. And what do you think?

1 Like

And one more inconsistency that arises from a bit raw Mathematica’s attempts to become “Physica”.

In[]:= 0 Quantity[1, "m"]
Out[]= Quantity[0, "Meters"]

In[]:= 0 a /. a -> Quantity[1, "m"]
Out[]= 0

This can make troubles also. And I don’t know if it is possible to correct this without making deep and incompatible changes in the system. But may be it is.

Hi,

About the Plot function, the first argument needs to be in the form f Quantity[mag,
unit] after evaluation, where f is a “plottable” expression. mag may contain the variable of Plot, e.g., e in the following example.

e Quantity[0.001, "Meters"^3]
Plot[Evaluate[%], {e, 0, 1}]

works, but not

UnitConvert[e Quantity[0.001, "Meters"^3], "L"]
Plot[Evaluate[%], {e, 0, 1}]

UnitConvert failed in this case since the unit of e is not known. The working version is

e UnitConvert[Quantity[0.001, "Meters"^3], "L"]
Plot[Evaluate[%], {e, 0, 1}]

It is to be noticed, however, that the MKS unit is used for actual plotting. This means that UnitConvert does not affect the Plot function.

In your example

In[] := QuantityUnit[Quantity[a, "m"]/Quantity[1, "m"]]
Out[] = QuantityUnit[a]

Quantity[a, “m”]/Quantity[1,
“m”] is evaluated to a first before being passed to QuantityUnit. Please note that a can be also a Quantity expression here. QuantityUnit returns the unit from Quantity[magnitude,unit] (see Mathematica Documentation). This means that magnitude must be dimensionless for the result to be correct. Evaluation is not done if a is neither numeric nor a Quantity expression. Please also refer to “The Standard Evaluation Sequence” in Mathematica documentation.

In a similar context, it would help to consider the behavior of Quantity similar to that of Times, the basic multiplication operator. In Quantity[mag,
unit], mag can also be another Quantity expression. Consider

In[47]:= Quantity[Quantity[a, "Centimeters"], "Meters"]
QuantityUnit[%]

Out[47]= Quantity[a/100, ("Meters")^2]
Out[48]= ("Meters")^2

In Out[47], a may or may not be dimensionsless. Quantity does not yet make any assumption about a. However, QuantityUnit assumes a is dimensionless (Out[48]).

As for your last example, all numeric quantities including zero are absorbed into Quantity. However, in

0 a /. a -> Quantity[1, "m"]

0 a evaluates to 0 first before ReplaceAll (/.), and therefore, the output is 0.

Youngjoo Chung