Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The code generator changes semantics by introducing parentheses #78

Open
lschuetze opened this issue Feb 4, 2021 · 2 comments
Open
Assignees
Labels
bug Something isn't working m2m Related to the model-to-model transformation

Comments

@lschuetze
Copy link
Collaborator

During m2m transformation, the generator adds parentheses to arithmetic expression that had not been in the former OpenPME expression. As a result, the semantics of the arithmetic expression is changed.

This can be seen in OpenPME example of Lennard Jones.
Screen Shot 2021-02-04 at 12 28 32
which has no parentheses and the resulting generated code
image

As you can see, the 2.0 is applied to both operands of the inner minus expression.

@lschuetze lschuetze added bug Something isn't working m2m Related to the model-to-model transformation labels Feb 4, 2021
@svenkarol
Copy link
Collaborator

I found the same problem several times. Maybe it's not related to the code generator but the node tree created by the view. See the equation below:

grafik

If you now look into the node explorer you get this:

grafik

Seems that the tree was created without considering the operator precedences.

@lschuetze
Copy link
Collaborator Author

lschuetze commented Feb 10, 2021

Actually, it is the opposite. The tree is created according to an equation that would use parentheses. Thus, the corresponding model is correct w.r.t. that equation that would use parentheses. If you would not create the tree according to the operator precedence the result will be different.

The problem is that the user perception is a different one as the view does not represent the resulting model if you take ordinary operator precedence and association into account.

To fix this:

  • the equation must include parenthesis
  • there must be a mapping from parenthesis of openpme.core to openpme.cpp
  • reduction rules for binary expressions in the generator of openpme.cpp must not create parenthesised expressions

There is a bigger usability problem which should be introduced in a different issue as you (for the time being) cannot just start writing your equation from left-to-right and the model is not constructed following the precedence rules of the operators in the whole equation. The user currently has to be carefully writing the expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working m2m Related to the model-to-model transformation
Projects
None yet
Development

No branches or pull requests

3 participants