1 #ifndef STAN_MATH_PRIM_SCAL_FUN_RISING_FACTORIAL_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_RISING_FACTORIAL_HPP
3 
4 #include <boost/math/special_functions/factorials.hpp>
5 #include <stan/math/prim/scal/fun/boost_policy.hpp>
6 #include <stan/math/prim/scal/err/check_not_nan.hpp>
7 #include <stan/math/prim/scal/err/check_nonnegative.hpp>
8 #include <limits>
9 
10 namespace stan {
11 namespace math {
12 
13 /**
14  * Return the rising factorial function evaluated
15  * at the inputs.
16  * Will throw for NaN x and for negative n
17  *
18  * @tparam T Type of x argument.
19  * @param x Argument.
20  * @param n Argument
21  * @return Result of rising factorial function.
22  * @throw std::domain_error if x is NaN
23  * @throw std::domain_error if n is negative
24  *
25  \f[
26  \mbox{rising\_factorial}(x, n) =
27  \begin{cases}
28  \textrm{error} & \mbox{if } x \leq 0\\
29  x^{(n)} & \mbox{if } x > 0 \textrm{ and } -\infty \leq n \leq \infty \\[6pt]
30  \textrm{NaN} & \mbox{if } x = \textrm{NaN or } n = \textrm{NaN}
31  \end{cases}
32  \f]
33 
34  \f[
35  \frac{\partial\, \mbox{rising\_factorial}(x, n)}{\partial x} =
36  \begin{cases}
37  \textrm{error} & \mbox{if } x \leq 0\\
38  \frac{\partial\, x^{(n)}}{\partial x} & \mbox{if } x > 0 \textrm{ and } -\infty
39  \leq n \leq \infty \\[6pt] \textrm{NaN} & \mbox{if } x = \textrm{NaN or } n =
40  \textrm{NaN} \end{cases} \f]
41 
42  \f[
43  \frac{\partial\, \mbox{rising\_factorial}(x, n)}{\partial n} =
44  \begin{cases}
45  \textrm{error} & \mbox{if } x \leq 0\\
46  \frac{\partial\, x^{(n)}}{\partial n} & \mbox{if } x > 0 \textrm{ and } -\infty
47  \leq n \leq \infty \\[6pt] \textrm{NaN} & \mbox{if } x = \textrm{NaN or } n =
48  \textrm{NaN} \end{cases} \f]
49 
50  \f[
51  x^{(n)}=\frac{\Gamma(x+n)}{\Gamma(x)}
52  \f]
53 
54  \f[
55  \frac{\partial \, x^{(n)}}{\partial x} = x^{(n)}(\Psi(x+n)-\Psi(x))
56  \f]
57 
58  \f[
59  \frac{\partial \, x^{(n)}}{\partial n} = (x)_n\Psi(x+n)
60  \f]
61  *
62  */
63 template <typename T>
rising_factorial(const T & x,int n)64 inline typename boost::math::tools::promote_args<T>::type rising_factorial(
65     const T& x, int n) {
66   static const char* function = "rising_factorial";
67   check_not_nan(function, "first argument", x);
68   check_nonnegative(function, "second argument", n);
69   return boost::math::rising_factorial(x, n, boost_policy_t());
70 }
71 }  // namespace math
72 }  // namespace stan
73 #endif
74