Skip to content

Commit

Permalink
Move some expressions around when you do simplifications only if this…
Browse files Browse the repository at this point in the history
… improves the complexity of the expression

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16216 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jun 4, 2013
1 parent 3f3ec02 commit a16a4e7
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3651,12 +3651,11 @@ algorithm
then
e2;

// (e1/e2)e3 => (e1e3)/e2
// e1*(e2/e3) => (e1e2)/e3
case (DAE.MUL(ty = tp),e1,DAE.BINARY(exp1 = e2,operator = DAE.DIV(ty = tp2),exp2 = e3))
equation
res = DAE.BINARY(DAE.BINARY(e1,DAE.MUL(tp),e2),DAE.DIV(tp2),e3);
then
res;
(e,true) = simplify1(DAE.BINARY(e1,DAE.MUL(tp),e2));
then DAE.BINARY(e,DAE.DIV(tp2),e3);

// 0 * a = 0
case (DAE.MUL(ty = ty),_,e2)
Expand Down Expand Up @@ -4035,23 +4034,22 @@ algorithm
then
DAE.BINARY(e1_1,DAE.DIV(ty),e2);

// e2*e3 / e1 => e3/e1 * e2
// (e2*e3)/e1 => (e3/e1)*e2
case (DAE.DIV(ty = tp2),DAE.BINARY(exp1 = e2,operator = DAE.MUL(ty = tp),exp2 = e3),e1)
equation
true = Expression.isConst(e3) "(c1x)/c2" ;
true = Expression.isConst(e1);
e = DAE.BINARY(e3,DAE.DIV(tp2),e1);
true = Expression.isConst(e3);
(e,true) = simplify1(DAE.BINARY(e3,DAE.DIV(tp2),e1));
then
DAE.BINARY(e,DAE.MUL(tp),e2);

// e2*e3 / e1 => e2 / e1 * e3
case (DAE.DIV(ty = tp2),DAE.BINARY(exp1 = e2,operator = DAE.MUL(ty = tp),exp2 = e3),e1)
equation
true = Expression.isConst(e2) ;
true = Expression.isConst(e1);
e = DAE.BINARY(e2,DAE.DIV(tp2),e1);
then
DAE.BINARY(e,DAE.MUL(tp),e3);
true = Expression.isConst(e2);
(e,true) = simplify1(DAE.BINARY(e2,DAE.DIV(tp2),e1));
then DAE.BINARY(e,DAE.MUL(tp),e3);

// e ^ 1 => e
case (DAE.POW(ty = _),e1,e)
Expand Down

0 comments on commit a16a4e7

Please sign in to comment.