From c0ea8d72038cd6c57e48aca26d2d29866848ae0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Tue, 7 Dec 2021 17:33:53 +0100 Subject: [PATCH] Add hyperbolic primitives (cosh, sinh, tanh, acosh, asinh, atanh) Everything was already in place (since ages!), except that the parser interface was missing. Also fix the derivation formula for atanh, which was incorrect. --- src/DynareBison.yy | 26 +++++++++++++++++++++++++- src/DynareFlex.ll | 6 ++++++ src/ExprNode.cc | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/DynareBison.yy b/src/DynareBison.yy index 46d14253..8e42c8aa 100644 --- a/src/DynareBison.yy +++ b/src/DynareBison.yy @@ -136,7 +136,7 @@ class ParsingDriver; %left TIMES DIVIDE %precedence UNARY %nonassoc POWER -%token EXP LOG LN LOG10 SIN COS TAN ASIN ACOS ATAN ERF ERFC DIFF ADL AUXILIARY_MODEL_NAME +%token EXP LOG LN LOG10 SIN COS TAN ASIN ACOS ATAN SINH COSH TANH ASINH ACOSH ATANH ERF ERFC DIFF ADL AUXILIARY_MODEL_NAME %token SQRT CBRT NORMCDF NORMPDF STEADY_STATE EXPECTATION /* GSA analysis */ %token DYNARE_SENSITIVITY MORRIS STAB REDFORM PPRIOR PRIOR_RANGE PPOST ILPTAU MORRIS_NLIV @@ -736,6 +736,18 @@ expression : '(' expression ')' { $$ = driver.add_acos($3); } | ATAN '(' expression ')' { $$ = driver.add_atan($3); } + | SINH '(' expression ')' + { $$ = driver.add_sinh($3); } + | COSH '(' expression ')' + { $$ = driver.add_cosh($3); } + | TANH '(' expression ')' + { $$ = driver.add_tanh($3); } + | ASINH '(' expression ')' + { $$ = driver.add_asinh($3); } + | ACOSH '(' expression ')' + { $$ = driver.add_acosh($3); } + | ATANH '(' expression ')' + { $$ = driver.add_atanh($3); } | SQRT '(' expression ')' { $$ = driver.add_sqrt($3); } | CBRT '(' expression ')' @@ -1046,6 +1058,18 @@ hand_side : '(' hand_side ')' { $$ = driver.add_acos($3); } | ATAN '(' hand_side ')' { $$ = driver.add_atan($3); } + | SINH '(' hand_side ')' + { $$ = driver.add_sinh($3); } + | COSH '(' hand_side ')' + { $$ = driver.add_cosh($3); } + | TANH '(' hand_side ')' + { $$ = driver.add_tanh($3); } + | ASINH '(' hand_side ')' + { $$ = driver.add_asinh($3); } + | ACOSH '(' hand_side ')' + { $$ = driver.add_acosh($3); } + | ATANH '(' hand_side ')' + { $$ = driver.add_atanh($3); } | SQRT '(' hand_side ')' { $$ = driver.add_sqrt($3); } | CBRT '(' hand_side ')' diff --git a/src/DynareFlex.ll b/src/DynareFlex.ll index 438dfcdc..e19aa7ea 100644 --- a/src/DynareFlex.ll +++ b/src/DynareFlex.ll @@ -920,6 +920,12 @@ DATE -?[0-9]+([ya]|m([1-9]|1[0-2])|q[1-4]) <DYNARE_STATEMENT,DYNARE_BLOCK>asin {return token::ASIN;} <DYNARE_STATEMENT,DYNARE_BLOCK>acos {return token::ACOS;} <DYNARE_STATEMENT,DYNARE_BLOCK>atan {return token::ATAN;} +<DYNARE_STATEMENT,DYNARE_BLOCK>sinh {return token::SINH;} +<DYNARE_STATEMENT,DYNARE_BLOCK>cosh {return token::COSH;} +<DYNARE_STATEMENT,DYNARE_BLOCK>tanh {return token::TANH;} +<DYNARE_STATEMENT,DYNARE_BLOCK>asinh {return token::ASINH;} +<DYNARE_STATEMENT,DYNARE_BLOCK>acosh {return token::ACOSH;} +<DYNARE_STATEMENT,DYNARE_BLOCK>atanh {return token::ATANH;} <DYNARE_STATEMENT,DYNARE_BLOCK>sqrt {return token::SQRT;} <DYNARE_STATEMENT,DYNARE_BLOCK>cbrt {return token::CBRT;} <DYNARE_STATEMENT,DYNARE_BLOCK>max {return token::MAX;} diff --git a/src/ExprNode.cc b/src/ExprNode.cc index 6f2a95af..83136997 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -2048,7 +2048,7 @@ UnaryOpNode::composeDerivatives(expr_t darg, int deriv_id) case UnaryOpcode::atanh: t11 = datatree.AddTimes(arg, arg); t12 = datatree.AddMinus(datatree.One, t11); - return datatree.AddTimes(darg, t12); + return datatree.AddDivide(darg, t12); case UnaryOpcode::sqrt: t11 = datatree.AddPlus(this, this); return datatree.AddDivide(darg, t11); -- GitLab