Skip to content

Commit

Permalink
- missing rule
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19750 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Mar 25, 2014
1 parent 198232b commit f72a266
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -3611,10 +3611,22 @@ algorithm
// a + ((-b) op2 c) = a - (b op2 c)
case (DAE.ADD(ty = tp),e1,DAE.BINARY(DAE.UNARY(operator = DAE.UMINUS(ty = tp2),exp = e2), op2, e3))
equation
true = Expression.operatorEqual(op2,DAE.DIV(tp));
//or Expression.operatorEqual(op2,MUL.DIV(tp));
true = Expression.operatorEqual(op2,DAE.DIV(tp));
//or Expression.operatorEqual(op2,DAE.MUL(tp));
e = DAE.BINARY(e1, DAE.SUB(tp), DAE.BINARY(e2,op2,e3));
then e;
then e;

// a + (r op2 c) => a - (r1 op2 c)
// for r < 0 with r = -r1
case (DAE.ADD(ty = tp),e1,DAE.BINARY(e2 as DAE.RCONST(r1), op2, e3))
equation
true = r1 <=. 0.0;
true = Expression.operatorEqual(op2,DAE.DIV(tp))
or Expression.operatorEqual(op2,DAE.DIV(tp));
r2 = realNeg(r1);
e = DAE.BINARY(e1, DAE.SUB(tp), DAE.BINARY(DAE.RCONST(r2),op2,e3));
then e;


// Commutative
// (-a)+b = b + (-a)
Expand Down Expand Up @@ -3887,15 +3899,13 @@ algorithm
Expression.operatorEqual(op2,DAE.MUL(ty));
res = DAE.BINARY(e1, op2, e2);
then Expression.makeBuiltinCall("abs",{res},ty);
/*
// e1 / exp(e2) => e1*exp(-e2)
case(_,DAE.DIV(ty),e1,DAE.CALL(path=Absyn.IDENT("exp"),expLst={e2}),_,_)
equation
e = DAE.UNARY(DAE.UMINUS(ty),e2);
e3 = Expression.makeBuiltinCall("exp",{e},ty);
res = DAE.BINARY(e,DAE.MUL(ty),e3);
then res;
*/
// exp(e1) * exp(e2) => exp(e1 + e2)
case(_,DAE.MUL(ty),DAE.CALL(path=Absyn.IDENT("exp"),expLst={e1}),DAE.CALL(path=Absyn.IDENT("exp"),expLst={e2}),_,_)
equation
Expand Down Expand Up @@ -4012,6 +4022,22 @@ algorithm
case (_,DAE.SUB(ty = ty),e1,DAE.UNARY(operator = DAE.UMINUS(ty = ty2),exp = e2),_,_)
then DAE.BINARY(e1,DAE.ADD(ty),e2);

// a-(-b op2 c) = a + b op2 c
case (_,DAE.SUB(ty),e1,DAE.BINARY(DAE.UNARY(DAE.UMINUS(ty2), e2),op2,e3),_,_)
equation
true = Expression.operatorEqual(op2,DAE.DIV(ty)) or
Expression.operatorEqual(op2,DAE.MUL(ty));
res = DAE.BINARY(e1, DAE.ADD(ty), DAE.BINARY(e2,op2,e3));
then res;

// b op2 -(-a) = b op2 c + a
case (_,DAE.SUB(ty),DAE.BINARY(e2,op2,e3),DAE.UNARY(DAE.UMINUS(ty2), e1),_,_)
equation
true = Expression.operatorEqual(op2,DAE.DIV(ty)) or
Expression.operatorEqual(op2,DAE.MUL(ty));
res = DAE.BINARY(DAE.BINARY(e2,op2,e3), DAE.ADD(ty),e1);
then res;

// 0 / x = 0
case (_,DAE.DIV(ty = ty),e1,e2,true,false)
equation
Expand Down

0 comments on commit f72a266

Please sign in to comment.