# Is it reasonable to have both TemperatureUnit and TemperatureDifferenceUnit?

When adding the bugs header to the question "Kelvin per Kelvin Difference" I was confused by the fact that I cannot determine for sure whether the described bug is fixed in version 10.2 or not: from the one hand the code in the question now produces what was expected by the OP, but from the other hand the underlying problem described in the answer by Xerxes (which has 16 upvotes and no contradictory comments or answers) is still here.

I always felt suspicious the fact that we have two different unit systems for temperature in Mathematica: temperature and temperature difference. The corresponding Documentation page where the motivation for introducing them seems to be explained does not convince me and I feel that the developers just "thrown the baby out with the bathwater" and introduction of these two unit systems creates more difficulties than adds benefits.

Could one provide an explanation why actually introducing of temperature difference units is necessary? What are benefits and drawbacks in practice?

And in the context of the referenced question: does Boltzmann Constant should be defined via "Kelvins" or "KelvinsDifference" in Mathematica?

I expect well-reasoned answers, not just opinions.

## My conclusions from the discussion in the comments

The temperature difference units should NEVER arise automatically in Mathematica when performing physically reasonable arithmetic operations with physical units. If you get such units in the output you are doing something wrong or encounter a bug.

The temperature difference units actually are not intended for what we know in physics as calculations with quantities, their purpose is very simple and utilitarian: just to allow the conversions between Celsius, Fahrenheit and Kelvins in the way shown on the linked Documentation page. So Boltzmann Constant must be defined via "Kelvins" (as it takes place to be) and Xerxes' complain about bug is incorrect: no physical constant should be defined via "KelvinsDifference" because this unit is a special-purpose unit with very narrow field of applications and is not intended to be used as a base unit.

The temperature difference units were introduced for resolving ambiguous cases of conversion between Celsius, Fahrenheit and Kelvins which are described on the linked Documentation page. One can notice that the "KelvinsDifference" unit is not strictly necessary for this purpose (the same can be achieved with only "Kelvins"). The reason for introduction of "KelvinsDifference" seems to be an attempt to unify the language. The fact that we have this unit proves that all the temperature difference units are artificial and were introduced with single-purpose goal to allow transparent conversion between temperature units. They do not play well with other parts of the Wolfram's "system-wide units" system and cause confusion when one tries to use the units system for performing the convenient in physics calculations with quantities (what is a different matter than just the conversion between temperature units!). The immediately obvious inconsistently can be illustrated using the classical example of calculation of efficiency of the Carnot cycle:

Suppose that we wish to calculate the efficiency of the Carnot cycle starting from the known temperature difference $ΔT$ between the hot reservoir and and the cold reservoir expressed via °F units and known temperature of the hot reservoir $T_H$ expressed via °F units using the proper formula: $η=ΔT/T_H$. The straightforward and conceptually correct implementation of this formula for the case of °F units in Mathematica is as follows:

η[TH_, ΔT_] := UnitConvert[Quantity[ΔT, "DegreesFahrenheitDifference"]]/
UnitConvert[Quantity[TH, "DegreesFahrenheit"]]


what returns the "kelvins difference per kelvin" units which do not make sense.

• Given its appearance in things such as the ideal gas law, the Planck distribution, and the stat-mech definition of entropy, it seems to me that the Boltzmann constant should be in units of "absolute" kelvins. – march Sep 14 '15 at 16:19
• But why "KelvinsDifference" is necessary? Is it reasonable to introduce this "differential" unit system for temperature? Especially considering the fact that we can easily add "absolute" temperature units in Mathematica and obtain absolute temperature units in the output: please try Quantity[1,"Kelvins"]+Quantity[1,"Kelvins"]//InputForm what gives Quantity[2, "Kelvins"]. And the difference is also the "absolute temperature": try Quantity[2, "Kelvins"] - Quantity[1, "Kelvins"] // InputForm. – Alexey Popkov Sep 14 '15 at 16:30
• @AlexeyPopkov , you are totally mixed-up. The reason of "KelvinDifference" unit is not to assign that unit when you subtract two temperatures. That is your fabrication. The real reason is that there must be a way for Mathematica to distinguish if a quantity (in Mathematica's sense, not sense of physic) is a temperature or a temperature difference quantity. – VividD Sep 14 '15 at 18:49
• the real inconsistency lies in heuristically interpreting the base-name unit as a difference (sometimes..). UnitConvert[Quantity[1, "DegreesFahrenheit"]] gives "256K", while 1/UnitConvert[Quantity[1, "1/DegreesFahrenheit"]] treats the quantity is a difference and gives 5/9K. (But Kelvin not KelvinDifference which is really what it is) Without resorting to some knowledge of physics there is no evident reason why a different formula should apply in the two cases. – george2079 Sep 15 '15 at 15:53
• Just a note because the question makes it look like Mathematica would be doing something very special here: the use of extra units for TemperatureDifferences seems to be used elsewhere as well, e.g. modelica. I don't even want to enter the discussion about whether that is necessary/good/bad, but it certainly isn't a Mathematica specific question. I bet you'll find good explanations why the modelica community decided to use such units if you search for them... – Albert Retey Sep 17 '15 at 15:05

## 2 Answers

The difference between 0 °C and 100 °C in Fahrenheit is 180 °F. The difference between 0 K and 100 K in Fahrenheit is 180 °F.

But 100 °C is 212 °F, while 100 K is 279.688 °F.

The underlying reason are, of course, the differing scale origins (zero points); the conversions are therefore not direct proportions (not homogeneous functions). Instead they are affine: f(t) = k·t + d.

The "difference" units are intended to be used for adding to and subtracting from "fixed" temperature units; in the same manner and for similar reasons, you can add "3 days 6 hours" (a difference unit) to the date "Dec 12th, 1964", but you cannot add two dates: "Dec 12th, 1964" + "Oct 10th, 1961" gives garbage.

Anybody who mixes units from scales with different zero-points is, of course, living in a state of sin. Whether Mathematica complains about this or not is entirely irrelevant; it only influences whether you should file a bug report or not.

• All good points! I am just surprised by confusion of some of fellow participants. Yes, there are many illogical consequences of the Mathematica's approach to this, but no sofware tool or software design is without limitations. Mathematica could have been different regarding this, but the current solutions looks pretty reasonable to me. IMHO, it is a little sad that such concepts like absolute zero, temperature scales, difference between time and interval are discussed at all at this site. – VividD Sep 14 '15 at 22:33
• @Felix Following your logic, we should also have "GramsDifference" in addition to "Grams" but we haven't. – Alexey Popkov Sep 15 '15 at 1:31
• You have missed my point about zero-points denoting the same absolute weight vs. not denoting the same temperature. Weight units are converted via homogeneous functions; zero scruples equal zero tons equal zero pounds. Temperature units do not follow this rule, hence the need for absolute (point on a scale) and relative (additive/subtractive) units. [continued] – Felix Kasza Sep 15 '15 at 5:56
• [Continued form previous comment] I'll grant an exception for Kelvin difference units; technically they are unnecessary. But since all other temperature units have corresponding difference units, I would have been surprised had WRI permitted such a huge wart as not having Kelvin difference units; MMA is nothing if not regular, organised and predictable in its use of language elements. – Felix Kasza Sep 15 '15 at 5:56

It is reasonable, and I will tell you why.

In the world of physics, obviously, there is no need for two different units. There are many many (and, of course, not only temperature-related) real-world examples of several physical quantities sharing the same unit.

However, Mathematica operates with Mathematica's quantities:

Quantity[magnitude, unit]

Notice here that the only way of distinguishing the type of a quantity is looking at its second argument, unit. This could have been designed/implemented in a different way, but it is not, and, in a moment, you'll see the connection of this fact to this question.

Mathematica is an inteligent system, and Mathematica's quantities are created for the purpose of intelligent manipulation of such quantities with respect to the operations of addition, subtraction, conversion, etc.

Keeping that in mind, Mathematica must differentiate temperature and temperature difference quantities, for the following reason: they behave differently related to multiplication and conversion. See here for examples of such different behavior. (Actually, you referenced this documentation page in the question, so you certainly read it.) The root cause of described multiplication/conversion behavior are different values of absolute zero in different temperature units. In other words, if both Celsius and Fahrenheit (and other) scales had had the same "coordinate origin", this question and this answer would not have existed!

This also explains why there are no both USDollar and USDollarDifference units. Zero is zero, and one is broke, no matter if it is in Euros, UsDollars, SwedishKronas or Dinars.

Hence the need for two different units for temperature and temperature difference in Mathematica.

• You give the Documentation link which I already referenced in the question as unconvincing: the different behavior of temperature and temperature difference on multiplication and conversion is understandable from the physical sense and is expected, and intuitively obvious. It does not prove that we need to introduce the artificial "differential temperature" (so-called temperature difference) which actually a duplicate of the usual temperature with counter-intuitive properties. Please see my comments under the original question. – Alexey Popkov Sep 14 '15 at 17:38
• @AlexeyPopkov But, I referenced the same page explaining the idea that is not explicitly within that page. The page itself is not the "philosophical" or "logical" source of my answer. I just did not feel like copying/pasting info from it. :) – VividD Sep 14 '15 at 17:43
• Quote from the edited answer: "If both Celsius and Fahrenheit scales had had the same "coordinate origin", this question and this answer would not have existed." <- I do not agree. My main point is: why we need both "Kelvins" and "KelvinsDifference"? Note also that we have also "DegreesFahrenheitDifference" and "DegreesCelsiusDifference"! – Alexey Popkov Sep 14 '15 at 17:49
• @AlexeyPopkov For any absolute temperature unit, one needs "difference" version in Mathematica. Only one temperature scale that does not have 0 at absolute zero causes this. I took Celsius and Fahrenheit just as the most known examples. I could have said Celsius and Kelvin. – VividD Sep 14 '15 at 17:53
• You simply say: "For any absolute temperature unit, one needs "difference" version in Mathematica." Do you actually think that it answers my question on WHY we need the "differential temperature"? I add the quotes on the purpose: I stress that current temperature difference units do not differ much from "simple" temperature units: the difference of "absolute temperatures" is absolute temperature - Isn't it absurd? Try Quantity[2, "Kelvins"] - Quantity[1, "Kelvins"] // InputForm what gives Quantity[1, "Kelvins"] (the absolute temperature units). – Alexey Popkov Sep 14 '15 at 18:01