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