iets3.opensource icon indicating copy to clipboard operation
iets3.opensource copied to clipboard

Type of DivExpression

Open ftomassetti opened this issue 5 years ago • 8 comments

We are encountering this issue with KernelF for MPS 2019.2. The precision of a division seems to be always set to infinite, which is a problem for us, as we have cases where we have divisions such as 5/2, in which we would expect the result to have precision 1

ftomassetti avatar Jan 20 '20 15:01 ftomassetti

We cannot compute precision based on the divisor in general. But if you expect it to match a specific number in your case, you can always use precision convert on the result, i.e. precision<truncate to 1>(a / 2).

wsafonov avatar Jan 27 '20 22:01 wsafonov

One thing I have been thinking about is to be able to explicitly set the precision (in the inspector of) the division. But as Wladi says, this would basically replicate what precision<> already does. I don't think it's worth it.

markusvoelter avatar Jan 29 '20 11:01 markusvoelter

I also thought about this, maybe one can optionally shows it in the main editor with something like /000 (with three small zeros, in pedix position, to indicate we want three decimal digits. Alternatively, could we have a division that infer the number of the decimals from the position where it is used? What I am afraid is that users could have to have to use the precision to wrap most divisions, which could be annoying

ftomassetti avatar Jan 29 '20 11:01 ftomassetti

"Inferring from context" is hard to do generically with the way KernelF computes its types (bottom up, basically).

markusvoelter avatar Jan 29 '20 11:01 markusvoelter

One idea I had a while ago is that you could scope the precision:

with precision(2) {
   divistions automatically with 2 precision
}

Then the type system could just "look up" to see what it is expected to do.

markusvoelter avatar Jan 29 '20 11:01 markusvoelter

"Inferring from context" is hard to do generically with the way KernelF computes its types (bottom up, basically).

Just a thought, but I was thinking of producing a number type with "context dependant precision". When assigning a value of this type to a variable there would be an implicit conversion to the type expected from the variable.

ftomassetti avatar Jan 29 '20 11:01 ftomassetti

I don't think this works because there's not just "assignment", there is all kinds of other places where the same would have to happen, eg in function calls. Did you see my other comment above?

markusvoelter avatar Jan 29 '20 11:01 markusvoelter

yes, maybe it makes sense to specify that entire calculations or maybe applications have a certain precision, it just feels a bit cumbersome to do it in many places. Perhaps certain operations (like assignment or others) could then during generation (with shadow models) add these "with precision" wrappers around certain operations, so that users have not do insert too many of them manually

ftomassetti avatar Jan 29 '20 12:01 ftomassetti