Skip to content

Commit

Permalink
- improved solver rule x = y^n
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21364 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Jul 1, 2014
1 parent 6393170 commit bc13138
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions Compiler/BackEnd/ExpressionSolve.mo
Expand Up @@ -261,31 +261,32 @@ algorithm
(res, asserts) = solve(e1,e2,inExp3);
then (res, asserts);

// a^n = c => a = c^-n
// f(a)^n = c => f(a) = c^-n
// where n is odd
case (DAE.BINARY(DAE.CREF(componentRef = cr1),DAE.POW(tp),DAE.RCONST(r)), _, DAE.CREF(componentRef = cr))
case (DAE.BINARY(e1,DAE.POW(tp),DAE.RCONST(r)), _, DAE.CREF(componentRef = cr))
equation
1.0 = realMod(r,2.0);
true = ComponentReference.crefEqual(cr, cr1);
false = Expression.expHasDerCref(inExp2, cr);
false = Expression.expHasCref(inExp2, cr);
true = Expression.expHasCref(e1, cr);
r = realNeg(r);
e1 = DAE.RCONST(r);
e2 = DAE.BINARY(inExp2,DAE.POW(tp),e1);
res = DAE.RCONST(r);
e2 = DAE.BINARY(inExp2,DAE.POW(tp),res);
(res, asserts) = solve(e1,e2,inExp3);
then
(e2,{});

// c = a^n => a = c^-n
(res,asserts);
// f(a)^n = c => f(a) = c^-n
// where n is odd
case (_, DAE.BINARY(DAE.CREF(componentRef = cr1),DAE.POW(tp),DAE.RCONST(r)), DAE.CREF(componentRef = cr))
case (_,DAE.BINARY(e1,DAE.POW(tp),DAE.RCONST(r)), DAE.CREF(componentRef = cr))
equation
1.0 = realMod(r,2.0);
true = ComponentReference.crefEqual(cr, cr1);
false = Expression.expHasDerCref(inExp1, cr);
false = Expression.expHasCref(inExp1, cr);
true = Expression.expHasCref(e1, cr);
r = realNeg(r);
e1 = DAE.RCONST(r);
e2 = DAE.BINARY(inExp1,DAE.POW(tp),e1);
res = DAE.RCONST(r);
e2 = DAE.BINARY(inExp2,DAE.POW(tp),res);
(res, asserts) = solve(e1,e2,inExp3);
then
(e2,{});
(res,asserts);

// -cr = exp
case (DAE.UNARY(operator = DAE.UMINUS(ty=_), exp = DAE.CREF(componentRef = cr1)),_,DAE.CREF(componentRef = cr))
Expand Down

0 comments on commit bc13138

Please sign in to comment.