Skip to content

Commit

Permalink
revert r15456, other tests fail because one function was changed to b…
Browse files Browse the repository at this point in the history
…e tailrecursive

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15463 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Mar 4, 2013
1 parent 22c02d9 commit a2156b9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 176 deletions.
119 changes: 30 additions & 89 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -53,7 +53,6 @@ public type Type = DAE.Type;
public type Subscript = DAE.Subscript;

// protected imports
protected import BaseHashTable;
protected import ComponentReference;
protected import Config;
protected import DAEUtil;
Expand All @@ -63,7 +62,6 @@ protected import ErrorExt;
protected import Expression;
protected import ExpressionDump;
protected import Flags;
protected import HashTableExpToReal;
protected import List;
protected import Prefix;
protected import Static;
Expand Down Expand Up @@ -2701,11 +2699,11 @@ algorithm
local
list<tuple<DAE.Exp, Real>> exp_const,exp_const_1;
list<DAE.Exp> expl_1,expl;
Integer n;

case (expl)
equation
(exp_const,n) = simplifyAdd2(expl,{},0);
exp_const_1 = simplifyAddJoinTerms(exp_const,/* intLt(n,50), this was commented out because is works good for large models but not for slow. A more general solution is needed */ true,n);
exp_const = simplifyAdd2(expl);
exp_const_1 = simplifyAddJoinTerms(exp_const);
expl_1 = simplifyAddMakeMul(exp_const_1);
then
expl_1;
Expand All @@ -2723,26 +2721,25 @@ protected function simplifyAdd2
author: PA
Helper function to simplifyAdd"
input list<DAE.Exp> inExpLst;
input list<tuple<DAE.Exp, Real>> inTplExpRealLst;
input Integer iN;
output list<tuple<DAE.Exp, Real>> outTplExpRealLst;
output Integer oN;
algorithm
(outTplExpRealLst,oN) := matchcontinue (inExpLst,inTplExpRealLst,iN)
outTplExpRealLst := matchcontinue (inExpLst)
local
DAE.Exp e;
tuple<DAE.Exp, Real> tpl;
DAE.Exp e_1,e;
Real coeff;
list<tuple<DAE.Exp, Real>> rest;
list<DAE.Exp> es;

case ({},_,_) then (inTplExpRealLst,iN);
case ({}) then {};

case ((e :: es),_,_)
case ((e :: es))
equation
tpl = simplifyBinaryAddCoeff2(e);
(outTplExpRealLst,oN) = simplifyAdd2(es,tpl::inTplExpRealLst,iN+1);
(e_1,coeff) = simplifyBinaryAddCoeff2(e);
rest = simplifyAdd2(es);
then
(outTplExpRealLst,oN);
else
((e_1,coeff) :: rest);

case (_)
equation
Debug.fprint(Flags.FAILTRACE,"- ExpressionSimplify.simplifyAdd2 failed\n");
then
Expand All @@ -2752,61 +2749,6 @@ end simplifyAdd2;

protected function simplifyAddJoinTerms
"function: simplifyAddJoinTerms
author: Frenkel TUD
Helper function to simplifyAdd.
check if listLength(inTplExpRealLst) is small ore huge and use
appropriate join functions."
input list<tuple<DAE.Exp, Real>> inTplExpRealLst;
input Boolean small;
input Integer n;
output list<tuple<DAE.Exp, Real>> outTplExpRealLst;
algorithm
outTplExpRealLst := match (inTplExpRealLst,small,n)
local
HashTableExpToReal.HashTable ht;

case (_,false,_)
equation
ht = HashTableExpToReal.emptyHashTableSized(2*n);
ht = List.fold(inTplExpRealLst,simplifyAddJoinTermsHuge,ht);
then
BaseHashTable.hashTableList(ht);
else
then
simplifyAddJoinTermsSmall(inTplExpRealLst);
end match;
end simplifyAddJoinTerms;

protected function simplifyAddJoinTermsHuge
"function: simplifyAddJoinTermsHuge
author: Frenkel TUD 2013-02
Helper function to simplifyAdd.
Join all terms with the same expression.
i.e. 2a+4a gives an element (a,6) in the list."
input tuple<DAE.Exp, Real> inTplExpReal;
input HashTableExpToReal.HashTable iHt;
output HashTableExpToReal.HashTable oHt;
algorithm
oHt := matchcontinue (inTplExpReal,iHt)
local
Real coeff,coeff1,coeff2;
DAE.Exp e;

case ((e,coeff),_)
equation
coeff1 = BaseHashTable.get(e,iHt);
coeff2 = coeff +. coeff1;
then
BaseHashTable.add((e,coeff2),iHt);

case ((e,coeff),_)
then
BaseHashTable.add((e,coeff),iHt);
end matchcontinue;
end simplifyAddJoinTermsHuge;

protected function simplifyAddJoinTermsSmall
"function: simplifyAddJoinTermsSmall
author: PA
Helper function to simplifyAdd.
Join all terms with the same expression.
Expand All @@ -2825,12 +2767,12 @@ algorithm
case (((e,coeff) :: rest))
equation
(coeff2,rest_1) = simplifyAddJoinTermsFind(e, rest);
res = simplifyAddJoinTermsSmall(rest_1);
res = simplifyAddJoinTerms(rest_1);
coeff3 = coeff +. coeff2;
then
((e,coeff3) :: res);
end match;
end simplifyAddJoinTermsSmall;
end simplifyAddJoinTerms;

protected function simplifyAddJoinTermsFind
"function: simplifyAddJoinTermsFind
Expand Down Expand Up @@ -2910,52 +2852,51 @@ protected function simplifyBinaryAddCoeff2
"function: simplifyBinaryAddCoeff2
This function checks for x+x+x+x and returns (x,4.0)"
input DAE.Exp inExp;
output tuple<DAE.Exp,Real> outExp;
output DAE.Exp outExp;
output Real outReal;
algorithm
outExp := match (inExp)
(outExp,outReal) := matchcontinue (inExp)
local
DAE.Exp exp,e1,e2,e;
Real coeff,coeff_1;
Integer icoeff;
Type tp;
Boolean b;

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

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

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

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

case (DAE.BINARY(exp1 = e1,operator = DAE.MUL(ty = _),exp2 = DAE.ICONST(integer = icoeff)))
equation
coeff_1 = intReal(icoeff);
then
((e1,coeff_1));
(e1,coeff_1);

case (DAE.BINARY(exp1 = DAE.ICONST(integer = icoeff),operator = DAE.MUL(ty = _),exp2 = e1))
equation
coeff_1 = intReal(icoeff);
then
((e1,coeff_1));
(e1,coeff_1);

case (DAE.BINARY(exp1 = e1,operator = DAE.ADD(ty = tp),exp2 = e2))
equation
b = Expression.expEqual(e1, e2);
coeff_1 = Util.if_(b,2.0,1.0);
true = Expression.expEqual(e1, e2);
then
((e1,coeff_1));
(e1,2.0);

else then ((inExp,1.0));
case (e) then (e,1.0);

end match;
end matchcontinue;
end simplifyBinaryAddCoeff2;

protected function simplifyBinaryMulCoeff2
Expand Down
1 change: 0 additions & 1 deletion Compiler/Makefile.common
Expand Up @@ -216,7 +216,6 @@ HashTablePathToFunction.mo \
HashTableStringToPath.mo \
HashTableExpToExp.mo \
HashTableExpToIndex.mo \
HashTableExpToReal.mo \
IOStream.mo \
List.mo \
Util.mo \
Expand Down
86 changes: 0 additions & 86 deletions Compiler/Util/HashTableExpToReal.mo

This file was deleted.

0 comments on commit a2156b9

Please sign in to comment.