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.
pac-components
Sébastien Villemot 2021-12-07 17:33:53 +01:00
parent d15b2110a0
commit c0ea8d7203
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
3 changed files with 32 additions and 2 deletions

View File

@ -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 ')'

View File

@ -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;}

View File

@ -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);