Skip to content

Commit 6eb0c57

Browse files
author
Vitalij Ruge
committed
added rule in ExpressionSolve for sqrt
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21381 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 516d80e commit 6eb0c57

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Compiler/BackEnd/ExpressionSolve.mo

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,26 @@ algorithm
260260
e2 = Expression.makePureBuiltinCall("log",{inExp1},DAE.T_REAL_DEFAULT);
261261
(res, asserts) = solve(e1,e2,inExp3);
262262
then (res, asserts);
263-
263+
// sqrt(f(a)) = g(b) => f(a) = (g(b))^2
264+
case (DAE.CALL(path = Absyn.IDENT(name = "sqrt"),expLst = {e1}),_,DAE.CREF(componentRef = cr))
265+
equation
266+
true = Expression.expHasCref(e1, cr);
267+
false = Expression.expHasCref(inExp2, cr);
268+
tp = DAE.T_REAL_DEFAULT;
269+
res = DAE.RCONST(2.0);
270+
e2 = DAE.BINARY(inExp2,DAE.POW(tp),res);
271+
(res, asserts) = solve(e1,e2,inExp3);
272+
then (res, asserts);
273+
// g(b) = sqrt(f(a)) => f(a) = (g(b))^2
274+
case (_,DAE.CALL(path = Absyn.IDENT(name = "sqrt"),expLst = {e1}),DAE.CREF(componentRef = cr))
275+
equation
276+
true = Expression.expHasCref(inExp2, cr);
277+
false = Expression.expHasCref(inExp1, cr);
278+
tp = DAE.T_REAL_DEFAULT;
279+
res = DAE.RCONST(2.0);
280+
e2 = DAE.BINARY(inExp1,DAE.POW(tp),res);
281+
(res, asserts) = solve(e1,e2,inExp3);
282+
then (res, asserts);
264283
// f(a)^n = c => f(a) = c^-n
265284
// where n is odd
266285
case (DAE.BINARY(e1,DAE.POW(tp),DAE.RCONST(r)), _, DAE.CREF(componentRef = cr))

0 commit comments

Comments
 (0)