1#ifndef STAN_MATH_PRIM_FUN_HYPERGEOMETRIC_3F2_HPP
2#define STAN_MATH_PRIM_FUN_HYPERGEOMETRIC_3F2_HPP
19template <
typename Ta,
typename Tb,
typename Tz,
20 require_all_vector_t<Ta, Tb>* =
nullptr,
21 require_stan_scalar_t<Tz>* =
nullptr>
23 const Ta& a,
const Tb& b,
const Tz& z,
double precision = 1
e-6,
24 int max_steps = 1e5) {
27 Eigen::Array<scalar_type_t<Tb>, 3, 1> b_array
30 b_array[0], b_array[1], z);
38 int t_sign = z_sign * a_signs.prod() * b_signs.prod();
41 const double log_precision =
log(precision);
42 while (k <= max_steps && log_t >= log_precision) {
53 t_acc += t_sign *
exp(log_t);
57 "overflow hypergeometric function did not converge.");
64 t_sign = a_signs.prod() * b_signs.prod() * t_sign;
68 "exceeded iterations, hypergeometric function did not ",
113template <
typename Ta,
typename Tb,
typename Tz,
120 if (z == 1.0 && (
sum(b) -
sum(a)) < 0.0) {
142template <
typename Ta,
typename Tb,
typename Tz,
145 const std::initializer_list<Tb>& b,
select_< as_operation_cl_t< T_condition >, as_operation_cl_t< T_then >, as_operation_cl_t< T_else > > select(T_condition &&condition, T_then &&then, T_else &&els)
Selection operation on kernel generator expressions.
auto append_row(Ta &&a, Tb &&b)
Stack the rows of the first argument on top of the second argument.
auto to_vector(T_x &&x)
Returns input matrix reshaped into a vector.
require_all_t< is_stan_scalar< std::decay_t< Types > >... > require_all_stan_scalar_t
Require all of the types satisfy is_stan_scalar.
require_t< is_stan_scalar< std::decay_t< T > > > require_stan_scalar_t
Require type satisfies is_stan_scalar.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
require_all_t< is_vector< std::decay_t< Types > >... > require_all_vector_t
Require all of the types satisfy is_vector.
return_type_t< Ta, Tb, Tz > hypergeometric_3F2_infsum(const Ta &a, const Tb &b, const Tz &z, double precision=1e-6, int max_steps=1e5)
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
auto hypergeometric_3F2(const Ta &a, const Tb &b, const Tz &z)
Hypergeometric function (3F2).
void check_3F2_converges(const char *function, const T_a1 &a1, const T_a2 &a2, const T_a3 &a3, const T_b1 &b1, const T_b2 &b2, const T_z &z)
Check if the hypergeometric function (3F2) called with supplied arguments will converge,...
T as_array_or_scalar(T &&v)
Returns specified input value.
static constexpr double e()
Return the base of the natural logarithm.
auto sign(const T &x)
Returns signs of the arguments.
fvar< T > log(const fvar< T > &x)
static constexpr double NEGATIVE_INFTY
Negative infinity.
void throw_domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
FvarT hypergeometric_pFq(const Ta &a, const Tb &b, const Tz &z)
Returns the generalized hypergeometric (pFq) function applied to the input arguments.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
int is_inf(const fvar< T > &x)
Returns 1 if the input's value is infinite and 0 otherwise.
fvar< T > fabs(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 ...