-
Notifications
You must be signed in to change notification settings - Fork 44
Description
MLS Section 3.5 states
In relations of the form
v1 == v2orv1 <> v2,v1 or v2shall, unless used in a function, not be a subtype of Real.[The reason for this rule is that relations with Real arguments are transformed to state events (see section 8.5) and this transformation becomes unnecessarily complicated for the == and <> relational operators (e.g., two crossing functions instead of one crossing function needed, epsilon strategy needed even at event instants). Furthermore, testing on equality of Real variables is questionable on machines where the number length in registers is different to number length in main memory.]
"Shall" looks pretty prescriptive to me. Yet, if I try this model on Dymola and OpenModelica (not sure about other tools)
model CheckInequality
Real x(start = 0, fixed = true);
Real y;
equation
der(x) = 0;
y = if x == 0 then 2 else 4;
end CheckInequality;I get some warning along the lines that "Hey, you shoulnd't really do that, but we'll compile your model anyway" and then the model is compiled. In this case it actually behaves correctly, but that's by pure chance.
Here, we have a typical scenario of a MLS rule that has been ignored for ages (at least by some tools), so that people write models ignoring it and then we get into all kind of trouble.
My first question is: should this rule really be enforced, even if it means breaking code that actually runs? If the answer is no, we should rewrite it as
In relations of the form
v1 == v2orv1 <> v2,v1 or v2should, unless used in a function, not be a subtype of Real.[If you use such constructs, you may end up having numerically fragile simulation code]
If the answer is yes, then we should really mean it.
Comments?