Skip to content

Commit

Permalink
added rules for sinh,cosh,tanh,coth
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22380 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Sep 21, 2014
1 parent d389137 commit aa6621c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Compiler/BackEnd/Differentiate.mo
Expand Up @@ -1627,6 +1627,16 @@ algorithm
exp_2 = Expression.makePureBuiltinCall("cosh", {exp}, tp);
then (DAE.BINARY(exp_1, DAE.DIV(tp),
DAE.BINARY(exp_2, DAE.POW(tp), DAE.RCONST(2.0))), funcs);
// der(coth(x)) = -der(x) / sinh(x)^2
case ("coth",_,_,_,_,_)
equation
tp = Expression.typeof(exp);
(exp_1, funcs) = differentiateExp(exp, inDiffwrtCref, inInputData,inDiffType, inFuncs);
exp_1 = DAE.UNARY(DAE.UMINUS(tp),exp_1);
exp_2 = Expression.makePureBuiltinCall("sinh", {exp}, tp);
then (DAE.BINARY(exp_1, DAE.DIV(tp),
DAE.BINARY(exp_2, DAE.POW(tp), DAE.RCONST(2.0))), funcs);


// diff(exp(x)) = der(x)*exp(x)
case ("exp",_,_,_,_,_)
Expand Down
54 changes: 50 additions & 4 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -3519,10 +3519,9 @@ algorithm
then DAE.BINARY(DAE.RCONST(0.5),DAE.MUL(DAE.T_REAL_DEFAULT),e);

/* sin^2(x)+cos^2(x) = 1 */
case (DAE.ADD(_),DAE.BINARY(DAE.CALL(path=Absyn.IDENT("sin"),expLst={e1}),DAE.POW(DAE.T_REAL(varLst = _)),DAE.RCONST(r1)),
DAE.BINARY(DAE.CALL(path=Absyn.IDENT("cos"),expLst={e2}),DAE.POW(DAE.T_REAL(varLst = _)),DAE.RCONST(r2)))
case (DAE.ADD(_),DAE.BINARY(DAE.CALL(path=Absyn.IDENT("sin"),expLst={e1}),DAE.POW(DAE.T_REAL(varLst = _)),DAE.RCONST(real = 2.0)),
DAE.BINARY(DAE.CALL(path=Absyn.IDENT("cos"),expLst={e2}),DAE.POW(DAE.T_REAL(varLst = _)),DAE.RCONST(real = 2.0)))
equation
true = realEq(r1,r2) and realEq(r1,2.0);
true = Expression.expEqual(e1,e2);
then DAE.RCONST(1.0);

Expand All @@ -3545,6 +3544,32 @@ algorithm
true = Expression.expEqual(e1,e2);
then Expression.makePureBuiltinCall("cos",{e1},tp);

/* sinh^2(x)+cosh^2(x) = 1 */
case (DAE.ADD(_),DAE.BINARY(DAE.CALL(path=Absyn.IDENT("sinh"),expLst={e1}),DAE.POW(DAE.T_REAL(varLst = _)),DAE.RCONST(real = 2.0)),
DAE.BINARY(DAE.CALL(path=Absyn.IDENT("cosh"),expLst={e2}),DAE.POW(DAE.T_REAL(varLst = _)),DAE.RCONST(real = 2.0)))
equation
true = Expression.expEqual(e1,e2);
then DAE.RCONST(1.0);

// tanh(e)*coth(e) = 1.0
case(DAE.MUL(tp),DAE.CALL(path=Absyn.IDENT("tanh"),expLst={e1}),DAE.CALL(path=Absyn.IDENT("coth"),expLst={e2}))
equation
true = Expression.expEqual(e1,e2);
e = Expression.makeConstOne(tp);
then e;

// tanh(e)*cosh(e) = sinh(e)
case(DAE.DIV(tp),DAE.CALL(path=Absyn.IDENT("tanh"),expLst={e1}),DAE.CALL(path=Absyn.IDENT("cosh"),expLst={e2}))
equation
true = Expression.expEqual(e1,e2);
then Expression.makePureBuiltinCall("sinh",{e1},tp);

// coth(e)*sinh(e) = cosh(e)
case(DAE.DIV(tp),DAE.CALL(path=Absyn.IDENT("coth"),expLst={e1}),DAE.CALL(path=Absyn.IDENT("sinh"),expLst={e2}))
equation
true = Expression.expEqual(e1,e2);
then Expression.makePureBuiltinCall("cosh",{e1},tp);

// a+(-b)
case (DAE.ADD(ty = tp),e1,DAE.UNARY(operator = DAE.UMINUS(ty = _),exp = e2))
equation
Expand Down Expand Up @@ -4222,9 +4247,30 @@ algorithm
then DAE.BINARY(e1,DAE.MUL(ty), e);
// e1/tan(e2) => e1*cot(e2)
case(_,DAE.DIV(ty),e1,DAE.CALL(path=Absyn.IDENT("tan"),expLst={e2}),_,_)
equation
equation
e= Expression.makePureBuiltinCall("cot",{e2},ty);
then DAE.BINARY(e1,DAE.MUL(ty), e);
// sinh(e)/cosh(e) => tan(e)
case(_,DAE.DIV(ty),DAE.CALL(path=Absyn.IDENT("sinh"),expLst={e1}),DAE.CALL(path=Absyn.IDENT("cosh"),expLst={e2}),_,_)
equation
true = Expression.expEqual(e1,e2);
then Expression.makePureBuiltinCall("tanh",{e1},ty);
// cosh(e)/sinh(e) => coth(e)
case(_,DAE.DIV(ty),DAE.CALL(path=Absyn.IDENT("cosh"),expLst={e1}),DAE.CALL(path=Absyn.IDENT("sinh"),expLst={e2}),_,_)
equation
true = Expression.expEqual(e1,e2);
then Expression.makePureBuiltinCall("coth",{e1},ty);
// e1/coth(e2) => e1*tanh(e2)
case(_,DAE.DIV(ty),e1,DAE.CALL(path=Absyn.IDENT("coth"),expLst={e2}),_,_)
equation
e = Expression.makePureBuiltinCall("tanh",{e2},ty);
then DAE.BINARY(e1,DAE.MUL(ty), e);
// e1/tanh(e2) => e1*coth(e2)
case(_,DAE.DIV(ty),e1,DAE.CALL(path=Absyn.IDENT("tanh"),expLst={e2}),_,_)
equation
e= Expression.makePureBuiltinCall("coth",{e2},ty);
then DAE.BINARY(e1,DAE.MUL(ty), e);


// e1 -e2 => -e1 e2
// Note: This rule is *not* commutative
Expand Down

0 comments on commit aa6621c

Please sign in to comment.