Group Abstract Group Abstract

Message Boards Message Boards

1
|
4K Views
|
5 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Inconsistent behavior and unexpected loss of units with Quantity

Posted 3 years ago
POSTED BY: Robben Migacz
5 Replies

This looks like a bug to me, maybe the simplest incarnation would be

In[10]:= Quantity[Log[x Quantity[1, "Liters"]], "Kilometers"] / Quantity[1, "Meters"]

Out[10]= 1000 (-3 Log[2] - 3 Log[5] + Log[x])

Where did the "Liters" go? You should report bugs here.

On a side note, you should try to use unit standard names when possible. Every time you type

In[11]:= Quantity[x, "volt"] // InputForm

Out[11]//InputForm= Quantity[x, "Volts"]

the system has to interpret the string "volt" to find the canonical unit "Volts". If you just use "Volts" from the start then computations will be faster, even if only a small amount.

POSTED BY: Jason Biggs
Posted 3 years ago

The expression testFunction[testArgument]/Quantity[1, "joule/coulomb"] is evaluated before the ReplaceAll is evaluated.

testFunction[Quantity[1, "molar"]]/Quantity[1, "joule/coulomb"]

and

testFunction[Quantity[1, "molar"]]/Quantity[1, "volt"]

both give 0.

POSTED BY: Eric Rimbey
Posted 3 years ago

Thank you for trying to reproduce the issue, and for your comment about the unit names. I think your example illustrates this well and shows that the issue is more universal. I have included it, along with an equivalent line where a division by Quantity[1, "Kilometers"] is performed and the correct output is given, in a message to Wolfram Technical Support.

POSTED BY: Robben Migacz
Posted 3 years ago

Well, without knowing the actual code you're working with, I can't provide an explanation or suggestion.

POSTED BY: Eric Rimbey
Posted 3 years ago

Thank you for the quick response. I encountered this issue in a notebook that does not use ReplaceAll, so there must be some other rule for the order of evaluation that I'm not aware of. I was able to work around this by replacing someQuantity[someValue, someUnits] with UnitConvert[someQuantity[someValue, someUnits], baseUnits]; everything seems to work as expected with this change.

POSTED BY: Robben Migacz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard