1#ifndef STAN_MATH_PRIM_FUN_LBETA_HPP
2#define STAN_MATH_PRIM_FUN_LBETA_HPP
64template <
typename T1,
typename T2, require_all_arithmetic_t<T1, T2>* =
nullptr>
72 static constexpr const char* function =
"lbeta";
103 T_ret x_over_xy = x / (x + y);
107 T_ret stirling = (y - 0.5) *
log1m(x_over_xy) + x * (1 -
log(x + y));
108 return stirling +
lgamma(x) + stirling_diff;
114 T_ret stirling = (x - 0.5) *
log(x_over_xy) + y *
log1m(x_over_xy)
116 return stirling + stirling_diff;
129template <
typename T1,
typename T2, require_any_container_t<T1, T2>* =
nullptr>
130inline auto lbeta(
const T1& a,
const T2& b) {
132 a, b, [&](
const auto& c,
const auto& d) {
return lbeta(c, d); });
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
static constexpr double NOT_A_NUMBER
(Quiet) not-a-number value.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
fvar< T > lbeta(const fvar< T > &x1, const fvar< T > &x2)
fvar< T > log(const fvar< T > &x)
static constexpr double NEGATIVE_INFTY
Negative infinity.
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
return_type_t< T > lgamma_stirling_diff(const T x)
Return the difference between log of the gamma function and its Stirling approximation.
int is_inf(const fvar< T > &x)
Returns 1 if the input's value is infinite and 0 otherwise.
constexpr double lgamma_stirling_diff_useful
static constexpr double HALF_LOG_TWO_PI
The value of half the natural logarithm , .
auto apply_scalar_binary(const T1 &x, const T2 &y, const F &f)
Base template function for vectorization of binary scalar functions defined by applying a functor to ...
fvar< T > log1m(const fvar< T > &x)
bool is_any_nan(const T &x)
Returns true if the input is NaN and false otherwise.
static constexpr double INFTY
Positive infinity.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...