@@ -554,8 +554,8 @@ algorithm
554554
555555 eWithX = Expression . expandFactors(inExp1);
556556 (factorWithX, factorWithoutX) = List . split1OnTrue(eWithX, expHasCref, inExp3);
557- pWithX = makeProductLstIf (factorWithX);
558- pWithoutX = makeProductLstIf (factorWithoutX);
557+ pWithX = makeProductLstSort (factorWithX);
558+ pWithoutX = makeProductLstSort (factorWithoutX);
559559
560560 e = Expression . makeDiv(rhs, pWithoutX);
561561
@@ -878,13 +878,13 @@ algorithm
878878
879879 f1 := Expression . expandFactors(e1);
880880 (factorWithX1, factorWithoutX1) := List . split1OnTrue(f1, expHasCref, inExp3);
881- pWithX1 := makeProductLstIf (factorWithX1);
882- pWithoutX1 := makeProductLstIf (factorWithoutX1);
881+ pWithX1 := makeProductLstSort (factorWithX1);
882+ pWithoutX1 := makeProductLstSort (factorWithoutX1);
883883
884884 f2 := Expression . expandFactors(inExp2);
885885 (factorWithX2, factorWithoutX2) := List . split1OnTrue(f2, expHasCref, inExp3);
886- (pWithX2,_) := ExpressionSimplify . simplify1(makeProductLstIf (factorWithX2));
887- pWithoutX2 := makeProductLstIf (factorWithoutX2);
886+ (pWithX2,_) := ExpressionSimplify . simplify1(makeProductLstSort (factorWithX2));
887+ pWithoutX2 := makeProductLstSort (factorWithoutX2);
888888 // print("\nf1 =");print(ExpressionDump.printExpListStr(f1));
889889 // print("\nf2 =");print(ExpressionDump.printExpListStr(f2));
890890
@@ -1041,8 +1041,6 @@ protected function unifyFunCallsWork
10411041end unifyFunCallsWork;
10421042
10431043
1044-
1045-
10461044protected function solveFunCalls
10471045"
10481046 - inline modelica functions
@@ -1498,7 +1496,7 @@ protected function isCrefInIFEXPwork " helper for isCrefInIFEXP"
14981496 end match;
14991497end isCrefInIFEXPwork;
15001498
1501- protected function makeProductLstIf
1499+ protected function makeProductLstSort
15021500 "Takes a list of expressions an makes a product
15031501 expression multiplying all elements in the list.
15041502
@@ -1509,29 +1507,65 @@ protected function makeProductLstIf
15091507 output DAE . Exp outExp;
15101508protected
15111509 DAE . Type tp;
1510+ list< DAE . Exp > expLstDiv, expLst, expLst2;
1511+ DAE . Exp e, e1, e2;
1512+ DAE . Operator op;
15121513algorithm
15131514 if List . isEmpty(inExpLst) then
15141515 outExp := DAE . RCONST (1 . 0 );
15151516 return ;
15161517 end if ;
15171518
15181519 tp := Expression . typeof(listGet(inExpLst,1 ));
1519- outExp := Expression . makeConstOne(tp);
15201520
1521- for elem in inExpLst loop
1521+ (expLstDiv, expLst) := List . splitOnTrue(inExpLst, Expression . isDivBinary);
1522+ outExp := makeProductLstSort2(expLst, tp);
1523+ if not List . isEmpty(expLstDiv) then
1524+ expLst2 := {};
1525+ expLst := {};
1526+
1527+ for elem in expLstDiv loop
1528+ DAE . BINARY (e1,op,e2) := elem;
1529+ expLst := e1::expLst;
1530+ expLst2 := e2::expLst2;
1531+ end for ;
1532+
1533+ if not List . isEmpty(expLst2) then
1534+ e := makeProductLstSort(expLst2);
1535+ if not Expression . isOne(e) then
1536+ outExp := Expression . makeDiv(outExp,e);
1537+ end if ;
1538+ end if ;
1539+
1540+ if not List . isEmpty(expLst) then
1541+ e := makeProductLstSort(expLst);
1542+ outExp := Expression . expMul(outExp,e);
1543+ end if ;
1544+
1545+ end if ;
1546+
1547+ end makeProductLstSort;
1548+
1549+ protected function makeProductLstSort2
1550+ input list< DAE . Exp > inExpLst;
1551+ input DAE . Type tp;
1552+ output DAE . Exp outExp := Expression . makeConstOne(tp);
1553+ protected
1554+ list< DAE . Exp > rest;
1555+ algorithm
1556+ rest := ExpressionSimplify . simplifyList(inExpLst, {});
1557+ for elem in rest loop
15221558 if not Expression . isOne(elem) then
15231559 outExp := match(elem)
15241560 local DAE . Exp e1,e2,e3;
15251561 case (DAE . IFEXP (e1,e2,e3))
15261562 then DAE . IFEXP (e1, Expression . expMul(outExp,e2), Expression . expMul(outExp,e3));
1527- case (DAE . BINARY (e1,DAE . DIV (),e2)) then Expression . makeDiv(Expression . expMul(outExp,e1),e2);
15281563 else Expression . expMul(outExp, elem);
15291564 end match;
15301565 end if ;
15311566 end for ;
15321567
1533- end makeProductLstIf;
1534-
1568+ end makeProductLstSort2;
15351569
15361570annotation(__OpenModelica_Interface= "backend" );
15371571end ExpressionSolve ;
0 commit comments