| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

binomial_coefficient_log.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_BINOMIAL_COEFFICIENT_LOG_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_BINOMIAL_COEFFICIENT_LOG_HPP
3
4 #include <boost/math/special_functions/gamma.hpp>
5 #include <boost/math/tools/promotion.hpp>
6
7 namespace stan {
8 namespace math {
59 template <typename T_N, typename T_n>
60 inline typename boost::math::tools::promote_args<T_N, T_n>::type
61 binomial_coefficient_log(const T_N N, const T_n n) {
62 using std::log;
63 using boost::math::lgamma;
64 const double CUTOFF = 1000;
65 if (N - n < CUTOFF) {
66 T_N N_plus_1 = N + 1;
67 return lgamma(N_plus_1) - lgamma(n + 1) - lgamma(N_plus_1 - n);
68 } else {
69 typename boost::math::tools::promote_args<T_N, T_n>::type N_minus_n
70 = N - n;
71 double one_twelfth = 1.0 / 12;
72 return n * log(N_minus_n)
73 + (N + 0.5) * log(N / N_minus_n)
74 + one_twelfth / N
75 - n
76 - one_twelfth / N_minus_n
77 - lgamma(n + 1);
78 }
79 }
80
81 }
82 }
83 #endif
stan::math::binomial_coefficient_log
fvar< T > binomial_coefficient_log(const fvar< T > &x1, const fvar< T > &x2)
Definition: binomial_coefficient_log.hpp:15
stan::math::lgamma
fvar< T > lgamma(const fvar< T > &x)
Definition: lgamma.hpp:14
stan
Definition: log_sum_exp.hpp:8
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:14

[ Stan Home Page ] © 2011–2016, Stan Development Team.