Skip to content

Commit 1830f90

Browse files
author
Vitalij Ruge
committed
improved rules for pow in ExpressionSolve.mo
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21443 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent bff32a8 commit 1830f90

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

Compiler/BackEnd/ExpressionSolve.mo

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ algorithm
190190
local
191191
DAE.ComponentRef cr,cr1;
192192
DAE.Type tp;
193-
DAE.Exp e1,e2,res;
193+
DAE.Exp e1,e2,e3,res;
194194
Real r;
195195
list<DAE.Statement> asserts;
196196

@@ -254,19 +254,34 @@ algorithm
254254
e2 = DAE.BINARY(inExp2,DAE.POW(tp),res);
255255
(res, asserts) = solve(e1,e2,inExp3);
256256
then (res, asserts);
257-
// f(a)^n = c => f(a) = c^-n
257+
// f(a)^n = c => f(a) = c^(1/n)
258258
// where n is odd
259-
case (DAE.BINARY(e1,DAE.POW(tp),DAE.RCONST(r)), _, DAE.CREF(componentRef = cr))
259+
case (DAE.BINARY(e1,DAE.POW(tp),e2 as DAE.RCONST(r)), _, DAE.CREF(componentRef = cr))
260260
equation
261261
1.0 = realMod(r,2.0);
262262
false = Expression.expHasCref(inExp2, cr);
263263
true = Expression.expHasCref(e1, cr);
264-
r = realNeg(r);
265-
res = DAE.RCONST(r);
266-
e2 = Expression.expPow(inExp2,res);
264+
false = Expression.expHasCref(e2, cr);
265+
e2 = Expression.expDiv(DAE.RCONST(1.0),e2);
266+
e2 = Expression.expPow(inExp2,e2);
267267
(res, asserts) = solve(e1,e2,inExp3);
268268
then
269269
(res,asserts);
270+
// b^(f(a)) = c => f(a) = log(|c|)/log(|b|)
271+
case (DAE.BINARY(e1,DAE.POW(tp),e2), _, DAE.CREF(componentRef = cr))
272+
equation
273+
false = Expression.expHasCref(inExp2, cr);
274+
true = Expression.expHasCref(e1, cr);
275+
true = Expression.expHasCref(e2, cr);
276+
e1 = Expression.makePureBuiltinCall("abs",{e1},tp);
277+
e1 = Expression.makePureBuiltinCall("log",{e1},tp);
278+
e3 = Expression.makePureBuiltinCall("abs",{inExp2},tp);
279+
e3 = Expression.makePureBuiltinCall("log",{e3},tp);
280+
e3 = Expression.expDiv(e3,e1);
281+
(res, asserts) = solve(e2,e3,inExp3);
282+
then
283+
(res,asserts);
284+
270285
// -cr = exp
271286
case (DAE.UNARY(operator = DAE.UMINUS(ty=_), exp = DAE.CREF(componentRef = cr1)),_,DAE.CREF(componentRef = cr))
272287
equation

0 commit comments

Comments
 (0)