Skip to content

Commit 8759c84

Browse files
author
vruge
committed
imrpoved simplifyMulJoinFactors
1 parent 49a533c commit 8759c84

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

Compiler/FrontEnd/ExpressionSimplify.mo

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,24 +2639,22 @@ protected function simplifyMulJoinFactors
26392639
Joins expressions that have the same base.
26402640
E.g. {(a,2), (a,4), (b,2)} => {(a,6), (b,2)}"
26412641
input list<tuple<DAE.Exp, Real>> inTplExpRealLst;
2642-
output list<tuple<DAE.Exp, Real>> outTplExpRealLst;
2642+
output list<tuple<DAE.Exp, Real>> outTplExpRealLst = {};
2643+
protected
2644+
list<tuple<DAE.Exp, Real>> tplExpRealLst = inTplExpRealLst;
2645+
DAE.Exp e;
2646+
Real coeff, coeff2;
26432647
algorithm
2644-
outTplExpRealLst := match (inTplExpRealLst)
2645-
local
2646-
Real coeff2,coeff_1,coeff;
2647-
list<tuple<DAE.Exp, Real>> rest_1,res,rest;
2648-
DAE.Exp e;
26492648

2650-
case ({}) then {};
2649+
while not listEmpty(tplExpRealLst) loop
2650+
(e, coeff) :: tplExpRealLst := tplExpRealLst;
2651+
(coeff2, tplExpRealLst) := simplifyMulJoinFactorsFind(e, tplExpRealLst);
2652+
coeff := coeff + coeff2;
2653+
outTplExpRealLst := (e, coeff) :: outTplExpRealLst;
2654+
end while;
2655+
2656+
outTplExpRealLst := listReverse(outTplExpRealLst);
26512657

2652-
case (((e,coeff) :: rest))
2653-
equation
2654-
(coeff2,rest_1) = simplifyMulJoinFactorsFind(e, rest);
2655-
res = simplifyMulJoinFactors(rest_1);
2656-
coeff_1 = coeff + coeff2;
2657-
then
2658-
((e,coeff_1) :: res);
2659-
end match;
26602658
end simplifyMulJoinFactors;
26612659

26622660
protected function simplifyMulJoinFactorsFind
@@ -2914,7 +2912,7 @@ protected function simplifyBinaryMulCoeff2
29142912
input DAE.Exp inExp;
29152913
output tuple<DAE.Exp, Real> outRes;
29162914
algorithm
2917-
outRes := matchcontinue (inExp)
2915+
outRes := match (inExp)
29182916
local
29192917
DAE.Exp e,e1,e2;
29202918
ComponentRef cr;
@@ -2947,14 +2945,13 @@ algorithm
29472945
((e1,coeff_1));
29482946

29492947
case (DAE.BINARY(exp1 = e1,operator = DAE.MUL(),exp2 = e2))
2950-
equation
2951-
true = Expression.expEqual(e1, e2);
2948+
guard Expression.expEqual(e1, e2)
29522949
then
29532950
((e1,2.0));
29542951

29552952
else ((inExp,1.0));
29562953

2957-
end matchcontinue;
2954+
end match;
29582955
end simplifyBinaryMulCoeff2;
29592956

29602957
public function simplifySumOperatorExpression

0 commit comments

Comments
 (0)