1 #ifndef STAN_MATH_REV_FUN_ASINH_HPP 2 #define STAN_MATH_REV_FUN_ASINH_HPP 3 4 #include <stan/math/prim/core.hpp> 5 #include <stan/math/prim/meta.hpp> 6 #include <stan/math/prim/fun/asinh.hpp> 7 #include <stan/math/prim/fun/isinf.hpp> 8 #include <stan/math/prim/fun/is_inf.hpp> 9 #include <stan/math/rev/core.hpp> 10 #include <stan/math/rev/meta.hpp> 11 #include <stan/math/rev/fun/value_of_rec.hpp> 12 #include <stan/math/rev/fun/abs.hpp> 13 #include <stan/math/rev/fun/arg.hpp> 14 #include <stan/math/rev/fun/cosh.hpp> 15 #include <stan/math/rev/fun/is_inf.hpp> 16 #include <stan/math/rev/fun/is_nan.hpp> 17 #include <stan/math/rev/fun/log.hpp> 18 #include <stan/math/rev/fun/polar.hpp> 19 #include <stan/math/rev/fun/sqrt.hpp> 20 #include <cmath> 21 #include <complex> 22 23 namespace stan { 24 namespace math { 25 26 /** 27 * The inverse hyperbolic sine function for variables (C99). 28 * 29 * The derivative is defined by 30 * 31 * \f$\frac{d}{dx} \mbox{asinh}(x) = \frac{x}{x^2 + 1}\f$. 32 * 33 * 34 \f[ 35 \mbox{asinh}(x) = 36 \begin{cases} 37 \sinh^{-1}(x) & \mbox{if } -\infty\leq x \leq \infty \\[6pt] 38 \textrm{NaN} & \mbox{if } x = \textrm{NaN} 39 \end{cases} 40 \f] 41 42 \f[ 43 \frac{\partial\, \mbox{asinh}(x)}{\partial x} = 44 \begin{cases} 45 \frac{\partial\, \sinh^{-1}(x)}{\partial x} & \mbox{if } -\infty\leq x\leq 46 \infty \\[6pt] \textrm{NaN} & \mbox{if } x = \textrm{NaN} \end{cases} \f] 47 48 \f[ 49 \sinh^{-1}(x)=\ln\left(x+\sqrt{x^2+1}\right) 50 \f] 51 52 \f[ 53 \frac{\partial \, \sinh^{-1}(x)}{\partial x} = \frac{1}{\sqrt{x^2+1}} 54 \f] 55 * 56 * @param x The variable. 57 * @return Inverse hyperbolic sine of the variable. 58 */ asinh(const var & x)59inline var asinh(const var& x) { 60 return make_callback_var(std::asinh(x.val()), [x](const auto& vi) mutable { 61 x.adj() += vi.adj() / std::sqrt(x.val() * x.val() + 1.0); 62 }); 63 } 64 65 /** 66 * The inverse hyperbolic sine function for variables (C99). 67 * 68 * @tparam Varmat a `var_value` with inner Eigen type 69 * @param x The variable. 70 * @return Inverse hyperbolic sine of the variable. 71 */ 72 template <typename VarMat, require_var_matrix_t<VarMat>* = nullptr> asinh(const VarMat & x)73inline auto asinh(const VarMat& x) { 74 return make_callback_var( 75 x.val().unaryExpr([](const auto x) { return asinh(x); }), 76 [x](const auto& vi) mutable { 77 x.adj().array() 78 += vi.adj().array() / (x.val().array().square() + 1.0).sqrt(); 79 }); 80 } 81 82 /** 83 * Return the hyperbolic arcsine of the complex argument. 84 * 85 * @param[in] z argument 86 * @return hyperbolic arcsine of the argument 87 */ asinh(const std::complex<var> & z)88inline std::complex<var> asinh(const std::complex<var>& z) { 89 return stan::math::internal::complex_asinh(z); 90 } 91 92 } // namespace math 93 } // namespace stan 94 #endif 95