Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#2633 closed defect (fixed)

0/0 is handled as 0

Reported by: Lennart Ochel Owned by: Lennart Ochel
Priority: high Milestone: 1.9.1
Component: Run-time Version: trunk
Keywords: Cc: Jens Frenkel, Willi Braun, Martin Sjölund

Description

0/0 is handled as 0 since r14719.

model test
  parameter Real p = -1.0;
  Real a = (p + time * time) / (p + time);
  annotation(experiment(StartTime = 0, StopTime = 2, Tolerance = 1e-006, Interval = 0.004));
end test;

Change History (16)

comment:1 by Lennart Ochel, 11 years ago

Status: newaccepted

comment:2 by Lennart Ochel, 11 years ago

Resolution: fixed
Status: acceptedclosed

fixed in r19667

comment:3 by Adrian Pop, 11 years ago

Why was this a problem? 0/0 is 0.

in reply to:  3 comment:4 by Lennart Ochel, 11 years ago

Replying to adrpo:

Why was this a problem? 0/0 is 0.

No, it is not. It depends on the expressions is not determinable by only knowing the evaluated values of the denominator and devisor. In the example above 0/0 should become 2. But because we cannot evaluate limits in our runtime, we have to trigger an error.

Version 0, edited 11 years ago by Lennart Ochel (next)

comment:5 by Vitalij Ruge, 11 years ago

Cc: Martin Sjölund added

Replying to lochel:

in this sense you have to modify
ExpressionSimplify.mo->simplifyBinaryCommutativeWork->
case 0 * a = 0
because there are not checking for "a" != expression/0

I prefer 0/0 = 0 with a warning!!

in reply to:  5 comment:6 by Lennart Ochel, 11 years ago

Replying to vitalij:

Replying to lochel:

in this sense you have to modify
ExpressionSimplify.mo->simplifyBinaryCommutativeWork->
case 0 * a = 0
because there are not checking for "a" != expression/0

I prefer 0/0 = 0 with a warning!!

Sorry, I didn't get your point.
It is not possible to evaluate a 0/0 expression in the runtime to zero, even if a warning is issued.
Besides that, feel free to change symbolic transformations in ExpressionSimplify.mo.

comment:7 by Vitalij Ruge, 11 years ago

In ExpressionSimplify we would simplify 0*(x/0) to 0.
If we don't use the same rules in the runtime ... the results became more nondeterministic depend from style...

comment:8 by Vitalij Ruge, 11 years ago

consequently if you handling 0/0 as undefined
then you need a case for 00

Last edited 11 years ago by Vitalij Ruge (previous) (diff)

comment:9 by Lennart Ochel, 11 years ago

Replying to vitalij:

In ExpressionSimplify we would simplify 0*(x/0) to 0.
If we don't use the same rules in the runtime ... the results became more nondeterministic depend from style...

What rules do you mean? There are no symbolic transformations during runtime.
This ticket is about handling 0/0 during runtime. Because it is indeterminate, an error is issued.
I agree, 0^0 should also issue an error. You can easily fix it.

comment:10 by Martin Sjölund, 11 years ago

Why should 00 issue an error? It is 1... By far less controversial than 0/0.

comment:11 by Vitalij Ruge, 11 years ago

Replying to lochel:

What rules do you mean? There are no symbolic transformations during runtime.

we had 0/0 => 0 and now 0/0 => error
It's was not better or right but uniformly with simplify

I agree, 0^0 should also issue an error. You can easily fix it.

I am sure we don't want this rule.

Replying to sjoelund.se:

Why should 00 issue an error?

in scant special case is indeterminate
http://www.wolframalpha.com/input/?i=0^0

Last edited 11 years ago by Vitalij Ruge (previous) (diff)

comment:12 by Martin Sjölund, 11 years ago

Python, C, Matlab, Dymola, OM all give 00 == 1... Also, see m:#605 for that discussion. Don't go changing things until that ticket tells you to.

comment:15 by Lennart Ochel, 11 years ago

It seems that the 0/0 issue covered some other problems. I discussed this with Willi, and it is maybe connected to nonlinear solver issues that are not handled immediately.

comment:16 by Willi Braun, 11 years ago

I've just looked into this 3 OpenHydraulic examples.
For the example OpenHydraulics.DevelopmentTests.ThrottleValveTest I can't reproduce the behaviour, since it just works for me.
For the example OpenHydraulics.DevelopmentTests.ThrottleValveTest2 it's really connected to non-linear solver, that fails to solve a system before and that leads to the division by zero.

But for the example OpenHydraulics.DevelopmentTests.ThrottleValveTest2 it seems to be an initializations issue, since the variable leakage.d_b:

assert            | debug   | division by zero at time 0, (a=0) / (b=0), where divisor b expression is: leakage.d_b

is initialized in Dymola with a non-zero value and the model does not have any non-linear or linear algebraic loop.

Last edited 11 years ago by Willi Braun (previous) (diff)
Note: See TracTickets for help on using tickets.