test_1F1.hpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. // Copyright John Maddock 2006.
  2. // Copyright Paul A. Bristow 2007, 2009
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
  7. #include <boost/math/concepts/real_concept.hpp>
  8. #include <boost/math/special_functions/math_fwd.hpp>
  9. #define BOOST_TEST_MAIN
  10. #include <boost/test/unit_test.hpp>
  11. #include <boost/test/tools/floating_point_comparison.hpp>
  12. #include <boost/math/tools/stats.hpp>
  13. #include <boost/math/tools/test.hpp>
  14. #include <boost/math/tools/big_constant.hpp>
  15. #include <boost/math/constants/constants.hpp>
  16. #include <boost/type_traits/is_floating_point.hpp>
  17. #include <boost/array.hpp>
  18. #include "functor.hpp"
  19. #include "handle_test_result.hpp"
  20. #include "table_type.hpp"
  21. #include <boost/math/special_functions/hypergeometric_1F1.hpp>
  22. #include <boost/math/quadrature/exp_sinh.hpp>
  23. #ifdef BOOST_MSVC
  24. #pragma warning(disable:4127)
  25. #endif
  26. template <class Real, class T>
  27. void do_test_1F1(const T& data, const char* type_name, const char* test_name)
  28. {
  29. typedef Real value_type;
  30. typedef value_type(*pg)(value_type, value_type, value_type);
  31. #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  32. pg funcp = boost::math::hypergeometric_0F1<value_type, value_type>;
  33. #else
  34. pg funcp = boost::math::hypergeometric_1F1;
  35. #endif
  36. boost::math::tools::test_result<value_type> result;
  37. std::cout << "Testing " << test_name << " with type " << type_name
  38. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  39. //
  40. // test hypergeometric_2F0 against data:
  41. //
  42. result = boost::math::tools::test_hetero<Real>(
  43. data,
  44. bind_func<Real>(funcp, 0, 1, 2),
  45. extract_result<Real>(3));
  46. handle_test_result(result, data[result.worst()], result.worst(), type_name, "hypergeometric_1F1", test_name);
  47. std::cout << std::endl;
  48. }
  49. #ifndef SC_
  50. #define SC_(x) BOOST_MATH_BIG_CONSTANT(T, 1000000, x)
  51. #endif
  52. template <class T>
  53. void test_spots1(T, const char* type_name)
  54. {
  55. #include "hypergeometric_1F1.ipp"
  56. do_test_1F1<T>(hypergeometric_1F1, type_name, "Integer a values");
  57. #include "hypergeometric_1F1_small_random.ipp"
  58. do_test_1F1<T>(hypergeometric_1F1_small_random, type_name, "Small random values");
  59. }
  60. template <class T>
  61. void test_spots2(T, const char* type_name)
  62. {
  63. #include "hypergeometric_1F1_big.ipp"
  64. do_test_1F1<T>(hypergeometric_1F1_big, type_name, "Large random values");
  65. }
  66. template <class T>
  67. void test_spots3(T, const char* type_name)
  68. {
  69. #include "hypergeometric_1F1_big_double_limited.ipp"
  70. do_test_1F1<T>(hypergeometric_1F1_big_double_limited, type_name, "Large random values - double limited precision");
  71. }
  72. template <class T>
  73. void test_spots4(T, const char* type_name)
  74. {
  75. #include "hypergeometric_1F1_big_unsolved.ipp"
  76. do_test_1F1<T>(hypergeometric_1F1_big, type_name, "Large random values - unsolved domains");
  77. }
  78. template <class T>
  79. void test_spots5(T, const char* type_name)
  80. {
  81. std::cout << "Testing special cases for type " << type_name << std::endl;
  82. BOOST_MATH_STD_USING
  83. //
  84. // Special cases:
  85. //
  86. using boost::math::hypergeometric_1F1;
  87. T tol = boost::math::tools::epsilon<T>() * 200;
  88. if (std::numeric_limits<T>::digits > std::numeric_limits<double>::digits)
  89. tol *= 2;
  90. if (boost::is_class<T>::value)
  91. tol *= 4;
  92. // b = 2a
  93. T computed = hypergeometric_1F1(T(-12.25), T(2 * -12.25), T(6.75));
  94. T expected = boost::lexical_cast<T>("22.995348157760091167706081204212893687052775606591209203948675272473773725021024450870565197330528784707135828761");
  95. BOOST_CHECK_CLOSE(computed, expected, tol);
  96. computed = hypergeometric_1F1(T(12.25), T(2 * 12.25), T(6.75));
  97. expected = boost::lexical_cast<T>("36.47281964229300610642392880149257389834650024065756742702265701321933782423217084029882132197130099355867287657");
  98. BOOST_CHECK_CLOSE(computed, expected, tol);
  99. computed = hypergeometric_1F1(T(-11), T(-12), T(6.75));
  100. expected = boost::lexical_cast<T>("376.3166426246459656334542608880377435064935064935064935064935064935064935064935064935064935064935064935064935064");
  101. BOOST_CHECK_CLOSE(computed, expected, tol);
  102. computed = hypergeometric_1F1(T(-2), T(-12), T(6.75));
  103. expected = boost::lexical_cast<T>("2.470170454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545");
  104. BOOST_CHECK_CLOSE(computed, expected, tol);
  105. computed = hypergeometric_1F1(T(-224), T(-1205), T(6.75));
  106. expected = boost::lexical_cast<T>("3.497033449657595724636676193024114597507981035316405619832857546161530808157860391434240068189887198094611519953");
  107. BOOST_CHECK_CLOSE(computed, expected, tol);
  108. computed = hypergeometric_1F1(T(0.5), T(-1205.5), T(-6.75));
  109. expected = boost::lexical_cast<T>("1.00281149043026925155096279505879868076290060374397866773878698584557482321961231721407215665017657501846692575");
  110. BOOST_CHECK_CLOSE(computed, expected, tol);
  111. computed = hypergeometric_1F1(T(-0.5), T(-1205.5), T(-6.75));
  112. expected = boost::lexical_cast<T>("0.99719639844965644594352920596780535220516138060108955206195178371227403775248888108818326220977962797312690");
  113. BOOST_CHECK_CLOSE(computed, expected, tol);
  114. computed = hypergeometric_1F1(T(-12), T(16.25), T(1043.75));
  115. expected = boost::lexical_cast<T>("1.26527673505477678311707565502355407505496430400394171269315320194708537626079491650410923064978320042481912e20");
  116. BOOST_CHECK_CLOSE(computed, expected, tol * 3);
  117. computed = hypergeometric_1F1(T(3.5), T(3.5), T(36.25));
  118. expected = exp(T(36.25));
  119. BOOST_CHECK_CLOSE(computed, expected, tol);
  120. computed = hypergeometric_1F1(T(-3.5), T(-3.5), T(36.25));
  121. expected = exp(T(36.25));
  122. BOOST_CHECK_CLOSE(computed, expected, tol);
  123. computed = hypergeometric_1F1(T(1), T(2), T(36.25));
  124. expected = boost::math::expm1(T(36.25)) / T(36.25);
  125. BOOST_CHECK_CLOSE(computed, expected, tol * 3);
  126. computed = hypergeometric_1F1(T(10.25), T(9.25), T(36.25));
  127. expected = exp(T(36.25)) * (T(9.25) + T(36.25)) / T(9.25);
  128. BOOST_CHECK_CLOSE(computed, expected, tol);
  129. computed = hypergeometric_1F1(T(-10.25), T(-11.25), T(36.25));
  130. expected = exp(T(36.25)) * (T(-11.25) + T(36.25)) / T(-11.25);
  131. BOOST_CHECK_CLOSE(computed, expected, tol);
  132. computed = hypergeometric_1F1(T(-10.25), T(-11.25), T(-36.25));
  133. expected = exp(T(-36.25)) * (T(-11.25) + T(-36.25)) / T(-11.25);
  134. BOOST_CHECK_CLOSE(computed, expected, tol);
  135. }
  136. template <class T>
  137. void test_spots6(T, const char* type_name)
  138. {
  139. static const boost::array<boost::array<T, 4>, 91> hypergeometric_1F1_bugs = { {
  140. { { static_cast<double>(17955.561660766602), static_cast<double>(9.6968994205831605e-09), static_cast<double>(-82.406154185533524), SC_(6.98056008378736714088730927132364938220428678e-11) }},
  141. { { static_cast<double>(17955.561660766602), static_cast<double>(-9.6968994205831605e-09), static_cast<double>(-82.406154185533524), SC_(-6.98055306629610746072607353939306734740549551e-11) }},
  142. { { static_cast<double>(-17955.561660766602), static_cast<double>(-9.6968994205831605e-09), static_cast<double>(82.406154185533524), SC_(-42897094853118832762870100.8669248353530950866) }} ,
  143. { { static_cast<double>(17955.561660766602), static_cast<double>(17956.061660766602), static_cast<double>(82.406154185533524), SC_(613117565438499794408370861624072730.553215432) }},
  144. { { static_cast<double>(2.9127331452327709e-07), static_cast<double>(-0.99999970872668542), static_cast<double>(0.15018942760070786), SC_(0.987526018990506843793601092932108059727149508) }},
  145. { { static_cast<double>(-2.9127331452327709e-07), static_cast<double>(-1.0000002912733146), static_cast<double>(0.15018942760070786), SC_(0.987526120661366412484942089372497015837368389) }},
  146. { { static_cast<double>(6.7191087900739423e-13), static_cast<double>(-0.99999999999932809), static_cast<double>(0.0011913633891253994), SC_(0.999999289758605006762757201699750974296453229) }},
  147. { { static_cast<double>(6.7191087900739423e-13), static_cast<double>(-0.99999999999932809), static_cast<double>(-0.0011913633891253994), SC_(0.999999290885918468326416221021126912154021802) }},
  148. { { static_cast<double>(-6.7191087900739423e-13), static_cast<double>(-1.0000000000006719), static_cast<double>(0.0011913633891253994), SC_(0.999999289758606609651292394510404091049823243) }},
  149. { { static_cast<double>(-6.7191087900739423e-13), static_cast<double>(-1.0000000000006719), static_cast<double>(-0.0011913633891253994), SC_(0.999999290885916869252591036674587894145399498) }},
  150. { { static_cast<double>(1.2860067365774887e-17), static_cast<double>(6.2442285664031425e-16), static_cast<double>(-2539.60133934021), SC_(0.979404874070484696999110600576068012417904384) }},
  151. { { static_cast<double>(1.2860067365774887e-17), static_cast<double>(-6.2442285664031425e-16), static_cast<double>(-2539.60133934021), SC_(1.0205951259295150865252112924093487321207727) }},
  152. { { static_cast<double>(-1.2860067365774887e-17), static_cast<double>(6.2442285664031425e-16), static_cast<double>(-2539.60133934021), SC_(1.02059512592951530745923325071510441026202975) }},
  153. { { static_cast<double>(-1.2860067365774887e-17), static_cast<double>(-6.2442285664031425e-16), static_cast<double>(-2539.60133934021), SC_(0.979404874070484909016444856299500644331897735) }},
  154. { { static_cast<double>(1.2860067365774887e-17), static_cast<double>(1), static_cast<double>(-2539.60133934021), SC_(0.999999999999999891757095137551552220860540801) }},
  155. { { static_cast<double>(-1.2860067365774887e-17), static_cast<double>(1), static_cast<double>(-2539.60133934021), SC_(1.00000000000000010824290486244845922375479178) }},
  156. { { static_cast<double>(1.2860067365774887e-17), static_cast<double>(0.5), static_cast<double>(-2539.60133934021), SC_(0.999999999999999873931788919689096760455570214) }},
  157. { { static_cast<double>(-1.2860067365774887e-17), static_cast<double>(0.5), static_cast<double>(-2539.60133934021), SC_(1.0000000000000001260682110803109183167444166) }},
  158. { { static_cast<double>(1.2860067365774887e-17), static_cast<double>(-0.5), static_cast<double>(-2539.60133934021), SC_(0.999999999999999899656990458526368219886894767) }},
  159. { { static_cast<double>(-1.2860067365774887e-17), static_cast<double>(-0.5), static_cast<double>(-2539.60133934021), SC_(1.00000000000000010034300954147364037131355735) }},
  160. { { static_cast<double>(1.9561377367172441e-13), static_cast<double>(-0.99999999999980438), static_cast<double>(0.53720525559037924), SC_(0.791950585963666119273677451162365759080483409) }},
  161. { { static_cast<double>(1.9561377367172441e-13), static_cast<double>(-0.99999999999980438), static_cast<double>(-0.53720525559037924), SC_(0.898314630992769591673208399706587643905527327) }},
  162. { { static_cast<double>(-1.9561377367172441e-13), static_cast<double>(-1.0000000000001956), static_cast<double>(0.53720525559037924), SC_(0.791950585964025761367113514279915403442035074) }},
  163. { { static_cast<double>(-1.9561377367172441e-13), static_cast<double>(-1.0000000000001956), static_cast<double>(-0.53720525559037924), SC_(0.898314630992646771749564140770704893561753597) }},
  164. { { static_cast<double>(5.1851756946064858e-12), static_cast<double>(-0.99999999999481481), static_cast<double>(-774.06985878944397), SC_(1.91306610467163858324476828831735612399803649e-06) }},
  165. { { static_cast<double>(-5.1851756946064858e-12), static_cast<double>(-1.0000000000051852), static_cast<double>(-774.06985878944397), SC_(1.91306610479516297551035931150910859922270467e-06) }},
  166. {{ static_cast<double>(4.782769898853794e-15), static_cast<double>(1.0000000000000049), static_cast<double>(43.289540141820908), SC_(715.678254892476818206948251991084031658534788) }},
  167. { { static_cast<double>(-4.782769898853794e-15), static_cast<double>(0.99999999999999523), static_cast<double>(43.289540141820908), SC_(-713.67825489247727251051792450091274703212426) }},
  168. { { static_cast<double>(4.782769898853794e-15), static_cast<double>(0.50000000000000477), static_cast<double>(43.289540141820908), SC_(8235.578376364917373771471380274179857713986) }},
  169. { { static_cast<double>(-4.782769898853794e-15), static_cast<double>(0.49999999999999523), static_cast<double>(43.289540141820908), SC_(-8233.57837636502669085205930058992320862281194) }},
  170. { { static_cast<double>(4.782769898853794e-15), static_cast<double>(-0.49999999999999523), static_cast<double>(43.289540141820908), SC_(-696269.800378137841948029488304613132151506346) }},
  171. { { static_cast<double>(-4.782769898853794e-15), static_cast<double>(-0.50000000000000477), static_cast<double>(43.289540141820908), SC_(696271.8003781336298001417038674968935893361) }},
  172. { { static_cast<double>(8.1104991963343309e-05), static_cast<double>(-0.99991889500803666), static_cast<double>(-289.12455415725708), SC_(7.89625448009377635153307897651433007437615965e-124) }},
  173. { { static_cast<double>(-8.1104991963343309e-05), static_cast<double>(-1.0000811049919633), static_cast<double>(-289.12455415725708), SC_(7.8949781467741574268884621364833028722017032e-124) }},
  174. {{ static_cast<double>(-1.98018241448205767), static_cast<double>(1.98450573845762079), static_cast<double>(54.4977916804564302), SC_(2972026581564772.790187123046255523239732028) }},
  175. { { static_cast<double>(-7.8238229420435346e-05), static_cast<double>(-0.50007823822942044), static_cast<double>(-1896.0561106204987), SC_(1.00058778866237037053151236215058095904086972) }},
  176. // Unexpected high error : 2.48268e+91 Found : -9.61305e+268 Expected : -1.74382e+193
  177. { { static_cast<double>(5.9981750131794866e-15), static_cast<double>(-230.70702263712883), static_cast<double>(240.42092034220695), SC_(-1.74381782591884817018404492963109914357365958e+193) }},
  178. // Unexpected high error : 1.79769313486231570814527423731704356798070568e+308 Found : -9.61305077326281580724540507004198316499661687e+268 Expected : 1.74381782591870724567837900957146707932623893e+193
  179. { { static_cast<double>(-5.9981750131794866e-15), static_cast<double>(-230.70702263712883), static_cast<double>(240.42092034220695), SC_(1.74381782591870734495565763481520223752372107e+193) }},
  180. //Unexpected exception : Error in function boost::math::hypergeometric_pFq<long double> : Cancellation is so severe that no bits in the reuslt are correct, last result was - 13497.312248525042
  181. { { static_cast<double>(-0.00023636552788275367), static_cast<double>(0.49976363447211725), static_cast<double>(-55.448519088327885), SC_(1.00141219419064760011631555641142295011268795) }},
  182. // Unexpected exception: Error in function boost::math::hypergeometric_pFq<long double>: Cancellation is so severe that no bits in the reuslt are correct, last result was -13497.312248525042
  183. {{ static_cast<double>(-0.00023636552788275367), static_cast<double>(-0.50023636552788275), static_cast<double>(-55.448519088327885), SC_(1.00093463146763986302362749764017215184711625) }},
  184. // Unexpected exception : Error in function boost::math::hypergeometric_pFq<long double> : Cancellation is so severe that no bits in the reuslt are correct, last result was - 1.3871133003351527e+47
  185. { { static_cast<double>(-1.6548533913638905e-10), static_cast<double>(0.49999999983451465), static_cast<double>(-169.20843148231506), SC_(1.00000000117356793527360151094991866549128017) }},
  186. // Unexpected exception: Error in function boost::math::hypergeometric_pFq<long double>: Cancellation is so severe that no bits in the reuslt are correct, last result was -1.3871133003351527e+47
  187. {{ static_cast<double>(-1.6548533913638905e-10), static_cast<double>(-0.50000000016548529), static_cast<double>(-169.20843148231506), SC_(1.00000000084161045914716192484600809610013447) }},
  188. // Unexpected high error : 17825.7893791562892147339880466461181640625 Found : -0.000253525216373273569459012577453904668800532818 Expected : -0.000253525216374277052779756536082800266740377992
  189. { { static_cast<double>(-2.0211181797563725e-14), static_cast<double>(-1.0000000000000202), static_cast<double>(-25.653068032115698), SC_(-0.000253525216374277055047768086884693917115210113) }},
  190. // Unexpected high error: 1.79769e+308 Found: -inf Expected: -2.63233e-197
  191. {{ static_cast<double>(235.44106131792068), static_cast<double>(-2.250966744069919e-13), static_cast<double>(-974.28781914710999), SC_(-2.63233018990922939037251029961929844581862228e-197) }},
  192. // Unexpected high error : 1.79769313486231570814527423731704356798070568e+308 Found : -inf Expected : -3.53316570137147325345279499243339692001224196e+226
  193. { { static_cast<double>(-235.44106131792068), static_cast<double>(-2.250966744069919e-13), static_cast<double>(974.28781914710999), SC_(-3.53316570137147343919975579872097464691424847e+226) }},
  194. // Unexpected high error : 2.48268e+91 Found : -9.61305e+268 Expected : -1.74382e+193
  195. { { static_cast<double>(5.9981750131794866e-15), static_cast<double>(-230.70702263712883), static_cast<double>(240.42092034220695), SC_(-1.74381782591884817018404492963109914357365958e+193) }},
  196. // Unexpected high error : 1.79769313486231570814527423731704356798070568e+308 Found : -9.61305077326281580724540507004198316499661687e+268 Expected : 1.74381782591870724567837900957146707932623893e+193
  197. { { static_cast<double>(-5.9981750131794866e-15), static_cast<double>(-230.70702263712883), static_cast<double>(240.42092034220695), SC_(1.74381782591870734495565763481520223752372107e+193) }},
  198. // Unexpected exception : Error in function boost::math::hypergeometric_pFq<long double> : Cancellation is so severe that no bits in the reuslt are correct, last result was 3.0871891698197084e+73
  199. { { static_cast<double>(-5.9981750131794866e-15), static_cast<double>(0.499999999999994), static_cast<double>(-240.42092034220695), SC_(1.00000000000004464930530925572237133417488137) }},
  200. // Unexpected exception : Error in function boost::math::hypergeometric_pFq<long double> : Cancellation is so severe that no bits in the reuslt are correct, last result was 3.0871891698197084e+73
  201. { { static_cast<double>(-5.9981750131794866e-15), static_cast<double>(-0.500000000000006), static_cast<double>(-240.42092034220695), SC_(1.00000000000003262784934420226963147689063665) }},
  202. // Unexpected high error : 18466.4373304979599197395145893096923828125 Found : 1.32865406167486480872551302123696359558380209e-08 Expected : 1.3286540616694168317751162703647255236560909e-08
  203. { { static_cast<double>(6.772927684190258e-10), static_cast<double>(-0.99999999932270722), static_cast<double>(-483.69576895236969), SC_(1.32865406166941679958876322759721528297325713e-08) }},
  204. // Unexpected high error: 1.79769e+308 Found: -nan(ind) Expected: 5.31173e-38
  205. {{ static_cast<double>(6763.4877452850342), static_cast<double>(3.6834977949762315e-08), static_cast<double>(-210.20976513624191), SC_(5.31173132667573457976877380237496445775181141e-38) }},
  206. // Unexpected high error : 1.79769313486231570814527423731704356798070568e+308 Found : -nan(ind) Expected : 1.04274264437409856500364465136386556989276338e+54
  207. { { static_cast<double>(-6763.4877452850342), static_cast<double>(3.6834977949762315e-08), static_cast<double>(210.20976513624191), SC_(1.04274264437409861991447530452939035771734596e+54) }},
  208. // Unexpected high error: 3.17219226436543247206316287281668161679098192e+185 Found: 1.00012411189051491970538746574092795078602734e+201 Expected: 14198882672502154063215954231296
  209. {{ static_cast<double>(76763.042617797852), static_cast<double>(-21.722407214343548), static_cast<double>(-0.60326536209322512), SC_(14198882672502153010712531896984.8126667697959) }},
  210. // Unexpected high error: 1.79769313486231570814527423731704356798070568e+308 Found: -2.39521645877904927856730119998375850409649219e+124 Expected: 2.3952164587795095929135248712964248422934629e+124
  211. {{ static_cast<double>(-1.8857404964801872e-09), static_cast<double>(-226.52341184020042), static_cast<double>(160.86221924424171), SC_(2.39521645877950946848639784331327651190093595e+124) }},
  212. // Unexpected high error : 73027.246763920571538619697093963623046875 Found : 0.000111810625893715248580992382976262433658121154 Expected : 0.000111810625895528292111404111697225971511215903
  213. { { static_cast<double>(-7.5220323642510769e-13), static_cast<double>(-1.0000000000007523), static_cast<double>(-17.948102783411741), SC_(0.00011181062589552829441403260197223627311023229) }},
  214. // Unexpected high error: 111726.15160028330865316092967987060546875 Found: 0.00856985181006919560786627698689699172973632813 Expected: 0.00856985180985659310282098743982714950107038021
  215. {{ static_cast<double>(5.6136137469239618e-15), static_cast<double>(-0.99999999999999434), static_cast<double>(-1989.8742001056671), SC_(0.00856985180985659334965068576732515544478559175) }},
  216. // Unexpected high error : 10431.000000023717802832834422588348388671875 Found : 0.99999999999772626324556767940521240234375 Expected : 1.00000000000004241051954068097984418272972107
  217. { { static_cast<double>(-5.6136137469239618e-15), static_cast<double>(-0.50000000000000566), static_cast<double>(-1989.8742001056671), SC_(1.00000000000004243096226509338784935080089269) }},
  218. // And more from error rate testing:
  219. {{ (T)std::ldexp((double)-17079780487168000, -44), (T)std::ldexp((double)9462273998848000, -46), (T)std::ldexp((double)9928190459904000, -48), SC_(7.7358754011357422722746277257633664799903803239195e-72) }},
  220. {{ (T)std::ldexp((double)-16238757384192000, -44), (T)std::ldexp((double)17248812490752000, -44), (T)std::ldexp((double)12549255331840000, -49), SC_(4.7354970214088286546733909450191631190700414608975e-10) }},
  221. {{ static_cast<double>(-6.8543290253728628), static_cast<double>(607.72073245607316), static_cast<double>(253.26409819535911), SC_(0.024418741483258497441042709681531519387974841769189) }},
  222. {{ (T)std::ldexp((double)-15569844699136000, -52), (T)std::ldexp((double)12855440629760000, -44), (T)std::ldexp((double)12563412279296000, -45), SC_(0.097879401070280078654536987721507669872679020399179) }},
  223. {{ (T)std::ldexp((double)-13521484578816000, -48), (T)std::ldexp((double)11813014388736000, -46), (T)std::ldexp((double)12736881098752000, -48), SC_(9.1262751214688536871555425535678062558805718157237e-08) }},
  224. {{ (T)std::ldexp((double)-13125670141952000, -44), (T)std::ldexp((double)16524914262016000, -44), (T)std::ldexp((double)12270166867968000, -49), SC_(2.0809215788388623809065210261671764534436583442155e-08) }},
  225. {{ (T)std::ldexp((double)-9012443406336000, -45), (T)std::ldexp((double)12293411340288000, -46), (T)std::ldexp((double)15162862993408000, -52), SC_(0.00634911418172408957356631082162378669273898042) }},
  226. {{ (T)std::ldexp((double)10907252916224000, -46), (T)std::ldexp((double)10872033234944000, -44), (T)std::ldexp((double)14845267734528000, -44), SC_(3.35597139167246486559762237420776458756928282e+152) }},
  227. {{ (T)std::ldexp((double)10206210322432000, -44), (T)std::ldexp((double)-16798514331648000, -45), (T)std::ldexp((double)21261284909056000, -48), SC_(3.8172723666678171743099642722909945977624468e+207) }},
  228. //{{ (T)std::ldexp((double)9125305942016000, -46), (T)std::ldexp((double)-15115828240384000, -45), (T)std::ldexp((double)9662868946944000, -47), SC_(4175579218962.24466854749118518544065513059142) }},
  229. //
  230. // These next few are the result of probing the boundary cases in hypergeometric_1F1_negative_b_recurrence_region
  231. //
  232. {{ (T)std::ldexp((double)10860755407856640, -40), (T)std::ldexp((double)-15992550230222440, -47), (T)std::ldexp((double)11953621172224000, -51), SC_(1.77767974631716859575450750736407296713916302e+278) }},
  233. {{ (T)std::ldexp((double)10788477424245760, -40), (T)std::ldexp((double)-17098099940288104, -45), (T)std::ldexp((double)9309879533568000, -50), SC_(3.30879597828065234949261835734767876076477669e+268) }},
  234. {{ (T)std::ldexp((double)10938221827471360, -40), (T)std::ldexp((double)-13207828614139084, -46), (T)std::ldexp((double)14276471291904000, -57), SC_(0.00563892736925233243283328398477659041011689599) }},
  235. { { (T)std::ldexp((double)10886339790484480, -40), (T)std::ldexp((double)-15267677514969908, -46), (T)std::ldexp((double)11568125313024000, -56), SC_(0.000743168361387021436166355590813648069510383979) } },
  236. { { (T)std::ldexp((double)10486036094119936, -40), (T)std::ldexp((double)-15535492710109184, -41), (T)std::ldexp((double)17014293405696000, -45), SC_(-2.61817515260939017621443182916266462279292638e+230) } },
  237. { { (T)std::ldexp((double)10485257266971648, -40), (T)std::ldexp((double)-17826711054409018, -35), (T)std::ldexp((double)17138334978048000, -44), SC_(1.70138735099219741672706572460585684251928784e-08) } },
  238. { { (T)std::ldexp((double)10485122560373760, -40), (T)std::ldexp((double)-11098279821997376, -39), (T)std::ldexp((double)16925852270592000, -45), SC_(9.77378642649349178995585980824930703376759021e-98) } },
  239. { { (T)std::ldexp((double)10485292967829248, -40), (T)std::ldexp((double)-14859721380002656, -35), (T)std::ldexp((double)13729956970496000, -44), SC_(3.41094899910311302761937103011397882987669395e-08) } },
  240. { { (T)std::ldexp((double)10485037389193216, -40), (T)std::ldexp((double)-10840488483391544, -35), (T)std::ldexp((double)17577061875712000, -45), SC_(2.8030884395368690164859926372380406504460219e-07) } },
  241. //
  242. // Negative a and b worst cases:
  243. { { (T)std::ldexp((double)-9281686323200000, -44), (T)std::ldexp((double)-14062138056704000, -44), (T)std::ldexp((double)13563284652032000, -44), SC_(2.8338102961174890442403751063892055396228341374378e+265) } },
  244. { { (T)std::ldexp((double)-17049048150016000, -44), (T)std::ldexp((double)-16971363917824000, -45), (T)std::ldexp((double)11759598960640000, -49), SC_(4636596575297708282.1539119952275597833292408543916) }},
  245. { { (T)std::ldexp((double)-14233964060672000, -45), (T)std::ldexp((double)-12648356216832000, -47), (T)std::ldexp((double)9597206757376000, -46), SC_(-1.2995296554447445191533190670521132012426135496934e+104) }},
  246. { { (T)std::ldexp((double)-16705334214656000, -45), (T)std::ldexp((double)-15447756718080000, -46), (T)std::ldexp((double)16395884134400000, -47), SC_(5.4068014134661635929301319845768046995946557071618e+113) }},
  247. { { (T)std::ldexp((double)-13991530405888000, -45), (T)std::ldexp((double)-10196587347968000, -46), (T)std::ldexp((double)13331347734528000, -46), SC_(1.2861275297661534781908508971693782447411136476694e+138) }},
  248. { { (T)std::ldexp((double)-15134950760448000, -45), (T)std::ldexp((double)-14587193786368000, -48), (T)std::ldexp((double)17022855921664000, -46), SC_(-8.8168904087758007346518546320759101059296394741359e+115) }},
  249. { { (T)std::ldexp((double)-14854672039936000, -45), (T)std::ldexp((double)-10436558200832000, -45), (T)std::ldexp((double)11370918969344000, -47), SC_(8.8553524727253411744552846056891456360191660433059e+54) } },
  250. { { (T)std::ldexp((double)-16711069286400000, -46), (T)std::ldexp((double)-14809815056384000, -46), (T)std::ldexp((double)10469312954368000, -47), SC_(50343352353398198766339890377687038177.388095267191) } },
  251. { { (T)std::ldexp((double)-15026786402304000, -45), (T)std::ldexp((double)-16687356968960000, -46), (T)std::ldexp((double)14895621603328000, -47), SC_(2.8532956042460265690059969666558072704044483623242e+95) } },
  252. { { (T)std::ldexp((double)-15519073435648000, -45), (T)std::ldexp((double)-14162009718784000, -45), (T)std::ldexp((double)9997818855424000, -48), SC_(95767987018108517.763999577428194082282035178055037) } },
  253. { { (T)std::ldexp((double)-15317481275392000, -46), (T)std::ldexp((double)-16531865931776000, -44), (T)std::ldexp((double)17586268880896000, -45), SC_(1.4701248047083724279783071194324315286789986738882e+104) }},
  254. { { (T)std::ldexp((double)-11335669673984000, -44), (T)std::ldexp((double)-13146047094784000, -44), (T)std::ldexp((double)13671437864960000, -44), SC_(-2.1887607284987089539904337941443591993019781369247e+288) }},
  255. { { (T)std::ldexp((double)-16877985234944000, -46), (T)std::ldexp((double)-14384006086656000, -46), (T)std::ldexp((double)9074349342720000, -47), SC_(15376193613462463541358751744530105.412429016705833) }},
  256. { { (T)std::ldexp((double)-9751199809536000, -45), (T)std::ldexp((double)-17654191685632000, -47), (T)std::ldexp((double)10587451850752000, -47), SC_(-1.9601415510439595625538337964298353914980331018955e+68) }},
  257. { { (T)std::ldexp((double)-15233620754432000, -45), (T)std::ldexp((double)-12708283072512000, -46), (T)std::ldexp((double)10255461007360000, -46), SC_(-5.4344106361679075861859567858016187271235441673635e+125) }},
  258. { { (T)std::ldexp((double)-11241354149888000, -45), (T)std::ldexp((double)-9580579905536000, -45), (T)std::ldexp((double)12224976846848000, -47), SC_(12046856548470067405870726490464935201150430438.035) }},
  259. } };
  260. static const boost::array<boost::array<T, 4>, 2> hypergeometric_1F1_big_bugs = { {
  261. #if DBL_MAX_EXP == LDBL_MAX_EXP
  262. {{ static_cast<double>(7.8238229420435346e-05), static_cast<double>(-5485.3222503662109), static_cast<double>(1896.0561106204987), BOOST_MATH_HUGE_CONSTANT(T, 1000, 4.33129800901478785957996719992774682013355926e+668) }},
  263. {{ static_cast<double>(-7.8238229420435346e-05), static_cast<double>(-5485.3222503662109), static_cast<double>(1896.0561106204987), BOOST_MATH_HUGE_CONSTANT(T, 1000, -4.3248750673398590673783317624407455467680038e+668) }},
  264. #else
  265. { { static_cast<double>(7.8238229420435346e-05), static_cast<double>(-5485.3222503662109), static_cast<double>(1896.0561106204987), SC_(4.33129800901478785957996719992774682013355926e+668) } },
  266. { { static_cast<double>(-7.8238229420435346e-05), static_cast<double>(-5485.3222503662109), static_cast<double>(1896.0561106204987), SC_(-4.3248750673398590673783317624407455467680038e+668) } },
  267. #endif
  268. } };
  269. do_test_1F1<T>(hypergeometric_1F1_bugs, type_name, "Bug cases");
  270. if(std::numeric_limits<T>::max_exponent10 > 800)
  271. do_test_1F1<T>(hypergeometric_1F1_big_bugs, type_name, "Bug cases - oversized");
  272. else
  273. {
  274. for (unsigned i = 0; i < hypergeometric_1F1_big_bugs.size(); ++i)
  275. {
  276. T val = boost::math::hypergeometric_1F1(hypergeometric_1F1_big_bugs[i][0], hypergeometric_1F1_big_bugs[i][1], hypergeometric_1F1_big_bugs[i][2]);
  277. BOOST_CHECK((boost::math::isinf)(val));
  278. }
  279. }
  280. }
  281. template <class T>
  282. void test_spots(T z, const char* type_name)
  283. {
  284. test_spots1(z, type_name);
  285. test_spots2(z, type_name);
  286. //
  287. // Test ranges that are limited to double precision, these contain test cases
  288. // which require full double precision for the inputs, so we don't test
  289. // at float precision as well as higher precisions:
  290. //
  291. if (std::numeric_limits<T>::digits10 == std::numeric_limits<double>::digits10)
  292. test_spots3(z, type_name);
  293. #ifdef TEST_UNSOLVED
  294. test_spots4(z, type_name);
  295. #endif
  296. test_spots5(z, type_name);
  297. //
  298. // Try as we might, we can't get better than quad precision on some of these:
  299. //
  300. if(std::numeric_limits<T>::digits >= std::numeric_limits<double>::digits && std::numeric_limits<T>::digits <= 128)
  301. test_spots6(z, type_name);
  302. }
  303. // Tests the Mellin transform formula given here: https://dlmf.nist.gov/13.10, Equation 13.10.10
  304. template <class Real>
  305. void test_hypergeometric_mellin_transform()
  306. {
  307. using boost::math::hypergeometric_1F1;
  308. using boost::math::quadrature::exp_sinh;
  309. using boost::math::tgamma;
  310. using std::pow;
  311. // Constraint: 0 < lambda < a.
  312. Real lambda = 0.5;
  313. Real a = 1;
  314. Real b = 3;
  315. auto f = [&](Real t)->Real { return pow(t, lambda - 1)*hypergeometric_1F1(a, b, -t); };
  316. auto integrator = exp_sinh<double>();
  317. Real computed = integrator.integrate(f, boost::math::tools::epsilon<Real>());
  318. Real expected = tgamma(b)*tgamma(lambda)*tgamma(a - lambda) / (tgamma(a)*tgamma(b - lambda));
  319. Real tol = boost::math::tools::epsilon<Real>() * 5;
  320. BOOST_CHECK_CLOSE_FRACTION(computed, expected, tol);
  321. }
  322. // Tests the Laplace transform formula given here: https://dlmf.nist.gov/13.10, Equation 13.10.4
  323. template <class Real>
  324. void test_hypergeometric_laplace_transform()
  325. {
  326. using boost::math::hypergeometric_1F1;
  327. using boost::math::quadrature::exp_sinh;
  328. using boost::math::tgamma;
  329. using std::pow;
  330. using std::exp;
  331. // Set a = 1 blows up for some reason . . .
  332. Real a = -1;
  333. Real b = 3;
  334. Real z = 1.5;
  335. auto f = [&](Real t)->Real { return exp(-z * t)*pow(t, b - 1)*hypergeometric_1F1(a, b, t); };
  336. auto integrator = exp_sinh<double>();
  337. Real computed = integrator.integrate(f, boost::math::tools::epsilon<Real>());
  338. Real expected = tgamma(b) / (pow(z, b)*pow(1 - 1 / z, a));
  339. Real tol = boost::math::tools::epsilon<Real>() * 200;
  340. BOOST_CHECK_CLOSE(computed, expected, tol);
  341. }