marco-compiler / marco

Modelica Advanced Research COmpiler
GNU Lesser General Public License v3.0
20 stars 5 forks source link

Trivial cycle resolution #1

Open mscuttari opened 2 years ago

mscuttari commented 2 years ago

Considering the system of equations:

x + y + z = 1 // eq1: matched x
x + y - z = 2 // eq2: matched y
x - y + z = 3 // eq3: matched z

Explicitating eq1 with respect to x would give x = - y - z + 1 But the substitution within eq2 would yield to - y - z + 1 + y - z = 2 Which is equivalent to 0y - 2z + 1 = 0 And would lead to the division by 0 y = (2z - 1) / 0

The system, however, is trivially solvable with x = 5/2, y = -1, z = -1/2

mscuttari commented 2 years ago

Commit 7df812318a8b64343987956ab3dbb68e6e68e4ea introduces the detection of division by zero. This allows to stop the compilation process if the issue is detected.

An implementation of the Cramer's rule can now be introduced to solve this issue without relying to external solvers.

casella commented 1 year ago

@mscuttari is this issue still open?

If so, do we wait for @StefanoAzzone to finish his job in order to have a proper solution?

mscuttari commented 1 year ago

Yes, the solution is part of Stefano's work.