Automatic Differentiation
 
Loading...
Searching...
No Matches
log_falling_factorial.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_LOG_FALLING_FACTORIAL_HPP
2#define STAN_MATH_FWD_FUN_LOG_FALLING_FACTORIAL_HPP
3
9
10namespace stan {
11namespace math {
12
13template <typename T>
14inline fvar<T> log_falling_factorial(const fvar<T>& x, const fvar<T>& n) {
16 (digamma(x.val_ + 1) - digamma(x.val_ - n.val_ + 1)) * x.d_
17 + digamma(x.val_ - n.val_ + 1) * n.d_);
18}
19
20template <typename T>
21inline fvar<T> log_falling_factorial(double x, const fvar<T>& n) {
23 digamma(x - n.val_ + 1) * n.d_);
24}
25
26template <typename T>
27inline fvar<T> log_falling_factorial(const fvar<T>& x, double n) {
29 (digamma(x.val_ + 1) - digamma(x.val_ - n + 1)) * x.d_);
30}
31} // namespace math
32} // namespace stan
33#endif
fvar< T > log_falling_factorial(const fvar< T > &x, const fvar< T > &n)
fvar< T > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
Definition digamma.hpp:23
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Scalar val_
The value of this variable.
Definition fvar.hpp:49
Scalar d_
The tangent (derivative) of this variable.
Definition fvar.hpp:61
This template class represents scalars used in forward-mode automatic differentiation,...
Definition fvar.hpp:40