Automatic Differentiation
 
Loading...
Searching...
No Matches
check_2F1_converges.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_ERR_CHECK_2F1_CONVERGES_HPP
2#define STAN_MATH_PRIM_ERR_CHECK_2F1_CONVERGES_HPP
3
10#include <cmath>
11#include <sstream>
12#include <stdexcept>
13
14namespace stan {
15namespace math {
16
34template <typename T_a1, typename T_a2, typename T_b1, typename T_z>
35inline void check_2F1_converges(const char* function, const T_a1& a1,
36 const T_a2& a2, const T_b1& b1, const T_z& z) {
37 using std::fabs;
38 using std::floor;
39
40 check_not_nan("check_3F2_converges", "a1", a1);
41 check_not_nan("check_3F2_converges", "a2", a2);
42 check_not_nan("check_3F2_converges", "b1", b1);
43 check_not_nan("check_3F2_converges", "z", z);
44
45 int num_terms = 0;
46 bool is_polynomial = false;
47
48 if (is_nonpositive_integer(a1) && fabs(a1) >= num_terms) {
49 is_polynomial = true;
50 num_terms = floor(fabs(value_of_rec(a1)));
51 }
52 if (is_nonpositive_integer(a2) && fabs(a2) >= num_terms) {
53 is_polynomial = true;
54 num_terms = floor(fabs(value_of_rec(a2)));
55 }
56
57 bool is_undefined = is_nonpositive_integer(b1) && fabs(b1) <= num_terms;
58
59 if (!is_undefined
60 && (is_polynomial || fabs(z) < 1 || (fabs(z) == 1 && b1 > a1 + a2))) {
61 return;
62 }
63
64 std::stringstream msg;
65 msg << "called from function '" << function << "', "
66 << "hypergeometric function 2F1 does not meet convergence "
67 << "conditions with given arguments. "
68 << "a1: " << a1 << ", a2: " << a2 << ", "
69 << "b1: " << b1 << ", z: " << z;
70 throw std::domain_error(msg.str());
71}
72
73} // namespace math
74} // namespace stan
75#endif
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > floor(const fvar< T > &x)
Definition floor.hpp:12
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
bool is_nonpositive_integer(T x)
Returns true if the input is a nonpositive integer and false otherwise.
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 > fabs(const fvar< T > &x)
Definition fabs.hpp:15
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9