Skip to content

Commit

Permalink
- Added rule to simplify x+x+x-x-x=x
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9069 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed May 22, 2011
1 parent 42ef95b commit 2ba6ed7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -535,18 +535,18 @@ algorithm
case(DAE.UNARY(DAE.UMINUS(t),e)) then e;
case(DAE.UNARY(DAE.UMINUS_ARR(t),e)) then e;

case(DAE.ICONST(i))
case (DAE.ICONST(i))
equation
i_1 = 0 - i;
then DAE.ICONST(i_1);
case(DAE.RCONST(r))
case (DAE.RCONST(r))
equation
r_1 = 0.0 -. r;
then DAE.RCONST(r_1);
case(DAE.BCONST(b))
case (DAE.BCONST(b))
equation
b_1 = not b;
then DAE.BCONST(b_1);
then DAE.BCONST(b_1);

// -0 = 0
case(e)
Expand Down
22 changes: 20 additions & 2 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -92,10 +92,11 @@ algorithm
case (e)
equation
//print("SIMPLIFY BEFORE->" +& ExpressionDump.printExpStr(e) +& "\n");
(eNew,b) = simplify1(e); // Basic local simplifications
(eNew,_) = simplify1(e); // Basic local simplifications
//print("SIMPLIFY INTERMEDIATE->" +& ExpressionDump.printExpStr(eNew) +& "\n");
eNew = simplify2(eNew); // Advanced (global) simplifications
b = not Debug.bcallret2(b,Expression.expEqual,e,eNew,not b);
(eNew,_) = simplify1(eNew); // Basic local simplifications
b = not Expression.expEqual(e,eNew);
//print("SIMPLIFY FINAL->" +& ExpressionDump.printExpStr(eNew) +& "\n");
then (eNew,b);
end matchcontinue;
Expand Down Expand Up @@ -1912,6 +1913,17 @@ algorithm
then
res;

case ((e as DAE.BINARY(exp1 = e1,operator = DAE.SUB(ty = tp),exp2 = e2)))
equation
e1_lst = Expression.terms(e1);
e2_lst = Expression.terms(e2);
e2_lst = Util.listMap(e2_lst, Expression.negate);
e_lst = listAppend(e1_lst, e2_lst);
e_lst_1 = simplifyAdd(e_lst);
res = Expression.makeSum(e_lst_1);
then
res;

case (e) then e;

end matchcontinue;
Expand Down Expand Up @@ -2293,6 +2305,12 @@ algorithm

case ((exp as DAE.CREF(componentRef = _))) then (exp,1.0);

case (DAE.UNARY(operator = DAE.UMINUS(ty = DAE.ET_REAL()), exp = exp))
equation
(exp,coeff) = simplifyBinaryAddCoeff2(exp);
coeff = realMul(-1.0,coeff);
then (exp,coeff);

case (DAE.BINARY(exp1 = DAE.RCONST(real = coeff),operator = DAE.MUL(ty = _),exp2 = e1))
then (e1,coeff);

Expand Down

0 comments on commit 2ba6ed7

Please sign in to comment.