Opened 11 years ago
Closed 11 years ago
#2610 closed defect (invalid)
ExpressionSimplify can not handle y - x + x.
Reported by: | Owned by: | somebody | |
---|---|---|---|
Priority: | high | Milestone: | 1.9.1 |
Component: | Frontend | Version: | trunk |
Keywords: | Cc: | Vitalij Ruge |
Description
I have recently had issues with ExpressionSimplify not simplifying expressions on the form y - x + x to y.
To be explicit, the expressions were on the form:
DAE.BINARY( DAE.BINARY(y,DAE.SUB(type),x), DAE.ADD(type), x )
I have fixed this by adding the following case to ExpressionSimplify.simplifyBinaryCommutativeWork:
case(DAE.ADD(ty = tp),DAE.BINARY(e1,DAE.SUB(_),e2),e3) equation true = Expression.expEqual(e2,e3); then e1;
However, since the module is largely undocumented, I leave it to you to decide if this is the proper way to do it.
Change History (10)
comment:1 by , 11 years ago
Cc: | added |
---|
comment:2 by , 11 years ago
follow-up: 4 comment:3 by , 11 years ago
You can't recreate the issue? Give ExpressionSimplify an expression on the form above and you will see that it will not be simplified.
comment:4 by , 11 years ago
Replying to carlj@…:
You can't recreate the issue? Give ExpressionSimplify an expression on the form above and you will see that it will not be simplified.
Running the following model through the compiler:
model M Real x, y; Real z = y - x + x; equation z = y - x + x; end M;
gives the flattened model:
class M Real x; Real y; Real z = y; equation z = y; end M;
If you do not get the same output I would guess that your compiler is broken. This sometimes happens when compiling with RML, when some depencies doesn't get recompiled when they shouldn't. make clean and a rebuild usually solves such issues.
comment:5 by , 11 years ago
This is not about the flattening not working, it is about ExpressionSimplify not doing what it should.
comment:6 by , 11 years ago
Sorry. I don't follow. What do you mean ExpressionSimplify doesn't do what it should?
As far as I can see from the model above, it does simplify y - x + x
to y
.
Can you explain better what the problem is?
comment:7 by , 11 years ago
Are you by any chance calling ExpressionSimplify.simplify1 instead of ExpressionSimplify.simplify? simplify1 only does basic simplification, simplify2 does more advanced stuff. simplify calls both simplify1 and simplify2.
comment:8 by , 11 years ago
runScript("LoadCompilerSources.mos");getErrorString(); setCommandLineOptions("+d=rml"); x := DAE.CREF(DAE.CREF_IDENT("x",DAE.T_REAL_DEFAULT,{}),DAE.T_REAL_DEFAULT); y := DAE.CREF(DAE.CREF_IDENT("y",DAE.T_REAL_DEFAULT,{}),DAE.T_REAL_DEFAULT); sub := DAE.SUB(DAE.T_REAL_DEFAULT);getErrorString(); add := DAE.ADD(DAE.T_REAL_DEFAULT);getErrorString(); exp1 := DAE.BINARY(x,sub,y);getErrorString(); exp := DAE.BINARY(exp1,add,y);getErrorString(); res := ExpressionSimplify.simplify2(exp);getErrorString(); ExpressionDump.printExpStr(exp);getErrorString(); ExpressionDump.printExpStr(res);getErrorString();
Prints:
"x - y + y" "" "x + 0.0 * y" ""
comment:9 by , 11 years ago
And
(res,changed) := ExpressionSimplify.simplify(exp);getErrorString(); ExpressionDump.printExpStr(exp);getErrorString(); ExpressionDump.printExpStr(res);getErrorString();
Prints:
"x - y + y" "" "x" ""
comment:10 by , 11 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
perost, yes that was certainly the issue. I now see that a simplification of this kind is not considered a simple simplification.
Sjoelund, very convincing.
I was wrong, you were right.
adrpo, the model might convince you, but it does not convince me (since I am not familiar with how the instantiation handles these things).
Could you please give a small model that shows this issue? The compiler will normally simplify such expressions, so it would be good if you can give an example of when it doesn't.