1 #ifndef STAN_MATH_FWD_SCAL_FUN_RISING_FACTORIAL_HPP 2 #define STAN_MATH_FWD_SCAL_FUN_RISING_FACTORIAL_HPP 3 4 #include <stan/math/fwd/core.hpp> 5 #include <stan/math/prim/scal/fun/rising_factorial.hpp> 6 #include <stan/math/prim/scal/fun/digamma.hpp> 7 8 namespace stan { 9 namespace math { 10 11 /** 12 * Return autodiff variable with the gradient and 13 * result of the rising factorial function applied 14 * to the inputs. 15 * Will throw for NaN x and for negative n, as 16 * implemented in primitive function. 17 * 18 * @tparam T Scalar type of autodiff variable. 19 * @param x Argument. 20 * @param n Argument 21 * @return tangent of rising factorial at arguments. 22 */ 23 24 template <typename T> rising_factorial(const fvar<T> & x,int n)25inline fvar<T> rising_factorial(const fvar<T>& x, int n) { 26 T rising_fact(rising_factorial(x.val_, n)); 27 return fvar<T>(rising_fact, 28 rising_fact * x.d_ * (digamma(x.val_ + n) - digamma(x.val_))); 29 } 30 } // namespace math 31 } // namespace stan 32 #endif 33