Skip to content

Commit

Permalink
Added missing case in ExpressionSimplify (see #2268 idea of Martin)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16506 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Jun 27, 2013
1 parent b62572e commit 5e57ef3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Expression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -8048,7 +8048,7 @@ algorithm
end matchcontinue;
end isExpCrefOrIfExp;

protected function operatorEqual
public function operatorEqual
"function: operatorEqual
Helper function to expEqual."
input Operator inOperator1;
Expand Down
21 changes: 20 additions & 1 deletion Compiler/FrontEnd/ExpressionSimplify.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3776,7 +3776,7 @@ algorithm
outExp := matchcontinue (inOperator2,inExp3,inExp4)
local
DAE.Exp e1_1,e3,e,e1,e2,e4,res,one;
Operator oper, op1 ,op2;
Operator oper, op1 ,op2, op3;
Type ty,ty2,tp,tp2,ty1;
list<DAE.Exp> exp_lst,exp_lst_1;
DAE.ComponentRef cr1,cr2;
Expand Down Expand Up @@ -3860,6 +3860,25 @@ algorithm
res = DAE.BINARY(e1,DAE.MUL(ty2),DAE.BINARY(e2,DAE.POW(ty2),DAE.RCONST(r)));
then res;

// (e1 op2 e2) op1 (e3 op3 e4) => (e1 op1 e3) op2 e2
// e2 = e4; op2=op3 \in {*, /, +, -}; op1 \in {+, -}
case (op1,DAE.BINARY(e1,op2,e2),DAE.BINARY(e3,op3,e4))
equation
false = Expression.isConst(e2);
true = Expression.expEqual(e2,e4);
true = Expression.operatorEqual(op2,op3);
ty = Expression.typeof(e1);

true = Expression.operatorEqual(op1,DAE.SUB(ty)) or
Expression.operatorEqual(op1,DAE.ADD(ty));

true = Expression.operatorEqual(op2,DAE.DIV(ty)) or
Expression.operatorEqual(op2,DAE.MUL(ty)) or
Expression.operatorEqual(op2,DAE.SUB(ty)) or
Expression.operatorEqual(op2,DAE.ADD(ty));
then
DAE.BINARY(DAE.BINARY(e1,op1,e3),op2,e4);

// (a+b)/c1 => a/c1+b/c1, for constant c1
case (DAE.DIV(ty = ty),DAE.BINARY(exp1 = e1,operator = DAE.ADD(ty = ty2),exp2 = e2),e3)
equation
Expand Down

0 comments on commit 5e57ef3

Please sign in to comment.