Skip to content

Commit

Permalink
added rule for abs(-x) = abs(x) and pow(-x,2) = pow(x,2)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22741 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Oct 14, 2014
1 parent bd55949 commit c030536
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -404,6 +404,11 @@ algorithm
// atan2(0,x) = 0
case (DAE.CALL(path=Absyn.IDENT("atan2"),expLst={e1 as DAE.RCONST(0.0),_}))
then e1;
// abs(-x) = abs(x)
case(DAE.CALL(path=Absyn.IDENT("abs"),expLst={DAE.UNARY(operator = DAE.UMINUS(ty = tp),exp = e1)}))
equation
e = Expression.makePureBuiltinCall("abs", {e1}, tp);
then e;

// MetaModelica builtin operators are calls
case _
Expand Down Expand Up @@ -4061,7 +4066,9 @@ algorithm
// a/(-b-c) = (-a)/(c + b)
case (_,op2 as DAE.DIV(ty = _),e1,DAE.BINARY(DAE.UNARY(operator = op3 as DAE.UMINUS(ty = _),exp = e2), DAE.SUB(ty = ty), e3),_,_)
then DAE.BINARY(DAE.UNARY(op3,e1),op2,DAE.BINARY(e2, DAE.ADD(ty),e3));

// (-x)^2 = x^2
case (_,op2 as DAE.POW(ty = _), DAE.UNARY(operator = op3 as DAE.UMINUS(ty = _),exp = e1), e2 as DAE.RCONST(2.0),_,_)
then DAE.BINARY(e1, op2, e2);
// e1 / -e2 => -e1 / e2
case (_,DAE.DIV(ty = ty),e1,DAE.UNARY(operator = DAE.UMINUS(ty = _),exp = e2),_,_)
equation
Expand Down

0 comments on commit c030536

Please sign in to comment.