modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Other
95 stars 41 forks source link

Clarification for unit expressions #3482

Closed gwr69 closed 3 months ago

gwr69 commented 3 months ago

Just a short clarification for section 19.1: Is there a good reason for allowing J.kg-1.K-1 but not 1.s-1?

Edit: Ok, I guess it makes sense to already restrict unit expressions before parsing instead of putting them into some kind of “normal form” afterwards.

henrikt-ma commented 2 months ago

Your question actually touches upon a bigger limitation. Given two unit expressions a and b, it is surprisingly difficult to create the unit expression for their product. It isn't even allowed to work around the problem by putting an exponent on a parenthesized expression, as in "a/(b)-1".

gwr69 commented 2 months ago

But a/(b-1) and even a/b-1 should work, shouldn’t it?

henrikt-ma commented 2 months ago

Only if b is a unit-operand. For something like "m/s" it isn't allowed.

gwr69 commented 2 months ago

Indeed, you are of course right. That is what I meant with a more relaxed “input form” (which then might accept “m/s” or even “1” as factor) that a tool shout bring into a more strict “normal form”, e.g., as specified by section 19.1.

henrikt-ma commented 2 months ago

Considering the current role of units, I think it is right that the specification only specifies the valid input forms, and leave it up to tools to normalize or use other forms. Even if we would have had a less strict form of unit expressions in the Modelica specification, I don't think we would have benefited from using a more strict form in the tool – except from the completely canonicalized base unit factorizations we use to determine unit equivalence and convertibility.