Group Abstract Group Abstract

Message Boards Message Boards

0
|
239 Views
|
8 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Issue with the output of units

POSTED BY: Ian Williams
8 Replies

UPDATE

I've received the following response from Wolfram Technical Support.

  • Right now, Quantity relies on Wolfram Alpha's ordering system, which is strictly alphabetical. There also isn't an option to specify which order Quantity should return results in. However, we do have an open suggestion report for having compound units follow standard ordering conventions; I have added your contact information to this suggestion report so that you can be notified if this suggestion is implemented. Please let me know if you have any additional questions or if I have misunderstood your issue.

I feel that imposing a strictly alphabetical ordering system for Quantity units is a seriously flawed approach. Not least because, in some cases, it returns unit notations that can be inconsistent with convention and user expectation. Which, for presentation purposes, I consider to be bad practice. This is very much out-of-step with Wolfram’s usual high standards and generally flexible approach to formatting outputs. And, whilst it’s good to hear that they have an open suggestion report for having compound units follow standard ordering conventions, it’s disappointing that they go on to say that I’ll be notified ‘if’ the suggestion is implemented. I feel this issue should be given high priority and would like to see it addressed at the next release.

My suggestion would be to order compound units in output cells such that the set order – as might be defined in the corresponding input cell – is preserved. This would place control in the hands of the user. And would circumvent any possible ambiguities in standard ordering conventions (which may vary in different contexts).

In case Wolfram staff monitor these posts, perhaps other users could comment if they would also like this issue to be addressed. If enough users ask, then hopefully Wolfram will prioritise.

Many thanks

POSTED BY: Ian Williams

You may try with a replacement rule for display purposes only:

Quantity[3, "Kilonewtons" "Meters"] /.
 Quantity[n_, "Kilonewtons" "Meters"] :> Row[{n, "kN"*"m"}]
POSTED BY: Gianluca Gorni

Thanks for the suggestion. But, as you say, this is suitable for display purposes only. The Head of the output expression is Row and cannot be used for calculation. Furthermore, I don't relish the prospect of having to apply a replacement rule whenever I use certain units.

POSTED BY: Ian Williams

kN m or m kN is in fact the unit kJ or kiloJoule. If you demand the answers in kJ, there is no problem, and you are always in normal unit notation.

POSTED BY: Malcolm Woodruff

Yep. But, in my experience, kNm are the units most Engineers use for bending moments. There should be a simple way of preserving the unit input order in the output cell. And, arguably, preserving the input order should be the default behavior.

POSTED BY: Ian Williams
Posted 5 days ago

This isn't much of an answer, just a small clarification. Quantity does, in fact, hold the units argument, including the order in which you supply units. You can see this if you use FullForm. The display is being created as a special little display object in the front end. It's a bit like evaluating Red and seeing the little square. The actual result of evaluating Red is RGBColor[1, 0, 0], but what you see is a display object. Of course, none of that is helpful, because you probably don't want to look at raw Quantity expressions either.

I'm assuming that Mathematica is displaying units in some canonical order, and maybe standard units precede derived units. I'm guessing that you probably can change this by "pulling back the covers" and providing your own formatting code to make the boxes that represent Quantitys as display "objects". I don't know how to do that, but I've seen others do similar things. If you don't get an answer here, you might post (or search first) at the stack exchange for Mathematica: https://mathematica.stackexchange.com .

POSTED BY: Eric Rimbey

Agreed. But it shouldn’t be necessary to need to drill down into the display object.

POSTED BY: Ian Williams
Posted 4 days ago

Actually, I was mistaken. Quantity does reorder units. I'm talking about the raw expression, not the display boxes form, (we already agreed the display form does reorder). Not sure why I didn't notice this before, but as I look at it now, it's what I would expect, since an expression like "kN" "m" is really just a Times expression.

By the way, that doesn't really contradict with the statement that Quantity has the HoldRest attribute. HoldRest just means that the arguments will be passed to Quantity unevaluated, but that doesn't mean that Quantity can't do its own evaluation/manipulation. It's not immediately obvious to me why Quantity needs the HoldRest attribute, but whatever.

One more slight nit. The response from Wolfram said: "Quantity ... ordering system ... is strictly alphabetical." I think that's confusing, since it describes the raw expression, not the display form. Consider the following:

enter image description here

So, in the raw expression, units are alphabetized, but that's probably just a result of the behavior of Times. In the display object, m comes before kN, which does not seem alphabetized. So, the display object is deliberately imposing an ordering based on something other than simple alphabetic order. Not sure if this matters at all in terms of any plans Wolfram might have for affording presentation flexibility with regard to units, but there might have been a slight miscommunication.

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