1#ifndef STAN_MATH_PRIM_FUN_HYPERGEOMETRIC_2F1_HPP
2#define STAN_MATH_PRIM_FUN_HYPERGEOMETRIC_2F1_HPP
20#include <boost/optional.hpp>
45template <
typename Ta1,
typename Ta2,
typename Tb,
typename Tz,
46 typename RtnT = boost::optional<return_type_t<Ta1, Ta1, Tb, Tz>>,
47 require_all_arithmetic_t<Ta1, Ta2, Tb, Tz>* =
nullptr>
59 return inv(
pow(1.0 - z, a2));
64 if (b == (a2 - 1.0)) {
65 return (
pow((1.0 - z), -a1 - 1.0) * (a2 + z * (a1 - a2 + 1.0) - 1.0))
72 if (a1 == 1.0 && b == 2.0 && z < 0) {
74 return log1p(pos_z) / pos_z;
77 if (a1 == 0.5 && b == 1.5 && z < 1.0) {
87 return numerator / sqrt_z;
92 if (b == (a1 + 1) && z == 0.5) {
93 return pow(2, a1 - 1) * a1
101 if (b == (a1 + a2 + 2)) {
106 }
else if (b > (a1 + a2)) {
115 if (a1 == 1.5 && a2 == 2.0 && b == 3.0 && z < 0.0) {
117 auto sqrt_1pz =
sqrt(1 + abs_z);
118 return -4 * (2 * sqrt_1pz + z - 2) / (sqrt_1pz *
square(z));
150template <
typename Ta1,
typename Ta2,
typename Tb,
typename Tz,
152 typename OptT = boost::optional<ScalarT>,
171 if (special_case_a1a2.is_initialized()) {
172 return special_case_a1a2.get();
178 if (special_case_a2a1.is_initialized()) {
179 return special_case_a2a1.get();
182 Eigen::Matrix<double, 2, 1> a_args(2);
183 Eigen::Matrix<double, 1, 1> b_args(1);
191 }
catch (
const std::exception&
e) {
194 ScalarT a1_t = b - a1;
197 ScalarT z_t = z / (z - 1);
201 a_args << a1_t, a2_t;
require_all_t< std::is_arithmetic< std::decay_t< Types > >... > require_all_arithmetic_t
Require all of the types satisfy std::is_arithmetic.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
RtnT hyper_2F1_special_cases(const Ta1 &a1, const Ta2 &a2, const Tb &b, const Tz &z)
Calculate the Gauss Hypergeometric (2F1) function for special-case combinations of parameters which c...
fvar< T > abs(const fvar< T > &x)
static constexpr double e()
Return the base of the natural logarithm.
fvar< T > asinh(const fvar< T > &x)
auto pow(const T1 &x1, const T2 &x2)
return_type_t< Ta1, Ta1, Tb, Tz > hypergeometric_2F1(const Ta1 &a1, const Ta2 &a2, const Tb &b, const Tz &z)
Returns the Gauss hypergeometric function applied to the input arguments: .
fvar< T > sqrt(const fvar< T > &x)
fvar< T > log1p(const fvar< T > &x)
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
FvarT hypergeometric_pFq(const Ta &a, const Tb &b, const Tz &z)
Returns the generalized hypergeometric (pFq) function applied to the input arguments.
void check_2F1_converges(const char *function, const T_a1 &a1, const T_a2 &a2, const T_b1 &b1, const T_z &z)
Check if the hypergeometric function (2F1) called with supplied arguments will converge,...
fvar< T > asin(const fvar< T > &x)
fvar< T > inv(const fvar< T > &x)
fvar< T > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
fvar< T > square(const fvar< T > &x)
fvar< T > exp(const fvar< T > &x)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...