test_bessel_y_prime.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // Copyright (c) 2013 Anton Bikineev
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
  6. #include <boost/math/concepts/real_concept.hpp>
  7. #define BOOST_TEST_MAIN
  8. #include <boost/test/unit_test.hpp>
  9. #include <boost/test/tools/floating_point_comparison.hpp>
  10. #include <boost/math/special_functions/math_fwd.hpp>
  11. #include <boost/math/constants/constants.hpp>
  12. #include <boost/type_traits/is_floating_point.hpp>
  13. #include <boost/array.hpp>
  14. #include "functor.hpp"
  15. #include <boost/math/concepts/real_concept.hpp>
  16. #include "handle_test_result.hpp"
  17. #include "table_type.hpp"
  18. #ifndef SC_
  19. # define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
  20. #endif
  21. template <class Real, class T>
  22. void do_test_cyl_neumann_y_prime(const T& data, const char* type_name, const char* test_name)
  23. {
  24. #if !(defined(ERROR_REPORTING_MODE) && !defined(BESSEL_YP_FUNCTION_TO_TEST))
  25. typedef Real value_type;
  26. typedef value_type (*pg)(value_type, value_type);
  27. #ifdef BESSEL_YP_FUNCTION_TO_TEST
  28. pg funcp = BESSEL_YP_FUNCTION_TO_TEST;
  29. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  30. pg funcp = boost::math::cyl_neumann_prime<value_type, value_type>;
  31. #else
  32. pg funcp = boost::math::cyl_neumann_prime;
  33. #endif
  34. boost::math::tools::test_result<value_type> result;
  35. std::cout << "Testing " << test_name << " with type " << type_name
  36. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  37. #include <boost/math/concepts/real_concept.hpp>
  38. //
  39. // test cyl_neumann against data:
  40. //
  41. result = boost::math::tools::test_hetero<Real>(
  42. data,
  43. bind_func<Real>(funcp, 0, 1),
  44. extract_result<Real>(2));
  45. handle_test_result(result, data[result.worst()], result.worst(), type_name, "cyl_neumann_prime", test_name);
  46. std::cout << std::endl;
  47. #endif
  48. }
  49. template <class T>
  50. T cyl_neumann_prime_int_wrapper(T v, T x)
  51. {
  52. #ifdef BESSEL_YNP_FUNCTION_TO_TEST
  53. return static_cast<T>(BESSEL_YNP_FUNCTION_TO_TEST(boost::math::itrunc(v), x));
  54. #else
  55. return static_cast<T>(boost::math::cyl_neumann_prime(boost::math::itrunc(v), x));
  56. #endif
  57. }
  58. template <class Real, class T>
  59. void do_test_cyl_neumann_y_prime_int(const T& data, const char* type_name, const char* test_name)
  60. {
  61. #if !(defined(ERROR_REPORTING_MODE) && !defined(BESSEL_YNP_FUNCTION_TO_TEST))
  62. typedef Real value_type;
  63. typedef value_type (*pg)(value_type, value_type);
  64. #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  65. pg funcp = cyl_neumann_prime_int_wrapper<value_type>;
  66. #else
  67. pg funcp = cyl_neumann_prime_int_wrapper;
  68. #endif
  69. boost::math::tools::test_result<value_type> result;
  70. std::cout << "Testing " << test_name << " with type " << type_name
  71. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  72. //
  73. // test cyl_neumann derivative against data:
  74. //
  75. result = boost::math::tools::test_hetero<Real>(
  76. data,
  77. bind_func<Real>(funcp, 0, 1),
  78. extract_result<Real>(2));
  79. handle_test_result(result, data[result.worst()], result.worst(), type_name, "cyl_neumann_prime (integer orders)", test_name);
  80. std::cout << std::endl;
  81. #endif
  82. }
  83. template <class Real, class T>
  84. void do_test_sph_neumann_y_prime(const T& data, const char* type_name, const char* test_name)
  85. {
  86. #if !(defined(ERROR_REPORTING_MODE) && !defined(BESSEL_YSP_FUNCTION_TO_TEST))
  87. typedef Real value_type;
  88. typedef value_type (*pg)(unsigned, value_type);
  89. #ifdef BESSEL_YPS_FUNCTION_TO_TEST
  90. pg funcp = BESSEL_YPS_FUNCTION_TO_TEST;
  91. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  92. pg funcp = boost::math::sph_neumann_prime<value_type>;
  93. #else
  94. pg funcp = boost::math::sph_neumann_prime;
  95. #endif
  96. boost::math::tools::test_result<value_type> result;
  97. std::cout << "Testing " << test_name << " with type " << type_name
  98. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  99. //
  100. // test sph_neumann against data:
  101. //
  102. result = boost::math::tools::test_hetero<Real>(
  103. data,
  104. bind_func_int1<Real>(funcp, 0, 1),
  105. extract_result<Real>(2));
  106. handle_test_result(result, data[result.worst()], result.worst(), type_name, "sph_neumann_prime", test_name);
  107. std::cout << std::endl;
  108. #endif
  109. }
  110. template <class T>
  111. void test_bessel_prime(T, const char* name)
  112. {
  113. //
  114. // The actual test data is rather verbose, so it's in a separate file
  115. //
  116. // The contents are as follows, each row of data contains
  117. // three items, input value a, input value b and Y'(a, b):
  118. //
  119. // function values calculated on wolframalpha.com
  120. static const boost::array<boost::array<typename table_type<T>::type, 3>, 9> y0_prime_data = {{
  121. {{ SC_(0.0), SC_(1.0), SC_(0.7812128213002887165471500000479648205499063907164) }},
  122. {{ SC_(0.0), SC_(2.0), SC_(0.1070324315409375468883707722774766366874808982351) }},
  123. {{ SC_(0.0), SC_(4.0), SC_(-0.397925710557100005253979972450791852271189181623) }},
  124. {{ SC_(0.0), SC_(8.0), SC_(0.15806046173124749425555526618748355032734404952671) }},
  125. {{ SC_(0.0), SC_(1e-05), SC_(63661.97727536548515747484843924772510915025447869) }},
  126. {{ SC_(0.0), SC_(1e-10), SC_(6.366197723675813431507891842844626117090808311905e9) }},
  127. {{ SC_(0.0), SC_(1e-20), SC_(6.366197723675813430755350534900574482790569176554e19) }},
  128. {{ SC_(0.0), SC_(1e+03), SC_(0.0247843312923517789148623560971412909386318548649) }},
  129. {{ SC_(0.0), SC_(1e+05), SC_(-0.00171921035008825630099494523539897102954509505) }}
  130. }};
  131. static const boost::array<boost::array<typename table_type<T>::type, 3>, 9> y1_prime_data = {{
  132. {{ SC_(1.0), SC_(1.0), SC_(0.8694697855159656745300767660714799833777239138071) }},
  133. {{ SC_(1.0), SC_(2.0), SC_(0.5638918884202138930407919788658961916118796762034) }},
  134. {{ SC_(1.0), SC_(4.0), SC_(-0.116422166964339993217130127559851181308289885304) }},
  135. {{ SC_(1.0), SC_(8.0), SC_(0.24327904710397215730926780877205580306573293697226) }},
  136. {{ SC_(1.0), SC_(1e-10), SC_(6.366197723675813430034640215574901912821641347643e19) }},
  137. {{ SC_(1.0), SC_(1e-20), SC_(6.366197723675813430755350534900574481363849370436e39) }},
  138. {{ SC_(1.0), SC_(1e+01), SC_(0.030769624862904003032131529943867767819086460209939) }},
  139. {{ SC_(1.0), SC_(1e+03), SC_(0.004740702308915165178688123821762396300797636752) }},
  140. {{ SC_(1.0), SC_(1e+05), SC_(0.00184674896676156322177773107486310726913857253) }}
  141. }};
  142. static const boost::array<boost::array<typename table_type<T>::type, 3>, 10> yn_prime_data = {{
  143. {{ SC_(2.0), SC_(1e-20), SC_(2.546479089470325372302140213960229792551354331847e60) }},
  144. {{ SC_(5.0), SC_(10.0), SC_(-0.21265103571277493482623417349611996600573875672875) }},
  145. {{ SC_(-5.0), SC_(1e+06), SC_(0.00072596421871030053058120610033601018452750251) }},
  146. {{ SC_(10.0), SC_(10.0), SC_(0.16051488637815838440809874678012991818716553338993) }},
  147. {{ SC_(10.0), SC_(1e-10), SC_(1.1828049049433493390095436658120487349235941485975e119) }},
  148. {{ SC_(-10.0), SC_(1e+06), SC_(-0.00033107967471992097725245404942310474516318425) }},
  149. {{ SC_(1e+02), SC_(5.0), SC_(1.0156878983956300357005118672219842696133568692723e117) }},
  150. {{ SC_(1e+03), SC_(1e+05), SC_(0.00128310308817651270517132752369325022363869159) }},
  151. {{ SC_(-1e+03), SC_(7e+02), SC_(1.9243675144213106227065036295645482241938721428442e77) }},
  152. {{ SC_(-25.0), SC_(8.0), SC_(-1.0191840913424144032043561764980932223038174827996e9) }}
  153. }};
  154. static const boost::array<boost::array<T, 3>, 11> yv_prime_data = {{
  155. {{ SC_(0.5), T(1) / (1024*1024), SC_(4.283610118295381639304989276580713877375759e8) }},
  156. {{ SC_(5.5), SC_(3.125), SC_(3.46903134947470280592767672475643312107258) }},
  157. {{ SC_(-5.5), SC_(3.125), SC_(-0.04142495199637659623440832639970224440469) }},
  158. {{ SC_(-5.5), SC_(1e+04), SC_(0.00245022241637437956702428797044365092097074) }},
  159. {{ T(-10486074) / (1024*1024), T(1)/1024, SC_(1.539961618935582531021699399508514975292038639e42) }},
  160. {{ T(-10486074) / (1024*1024), SC_(1e+02), SC_(-0.054782042073650048917092191171177791880141278121) }},
  161. {{ SC_(141.75), SC_(1e+02), SC_(5.3859930471571245788582581390871501852536045509e9) }},
  162. {{ SC_(141.75), SC_(2e+04), SC_(-0.0042010736481689878858599823347897260616269998902) }},
  163. {{ SC_(-141.75), SC_(1e+02), SC_(3.8084722070683992315593455637944657331085673830e9) }},
  164. {{ SC_(8.5), boost::math::constants::pi<T>() * 4, SC_(0.014516314554743677558496402742690038592727861) }},
  165. {{ SC_(-8.5), boost::math::constants::pi<T>() * 4, SC_(-0.194590144622675911618596506265006877277073804) }},
  166. }};
  167. static const boost::array<boost::array<T, 3>, 7> yv_prime_large_data = {{
  168. #if LDBL_MAX_10_EXP > 326
  169. {{ SC_(0.5), static_cast<T>(std::ldexp(0.5, -683)), SC_(2.868703194735890254207338863894358862705699335892099e308) }},
  170. #else
  171. {{ SC_(0.5), static_cast<T>(std::ldexp(0.5, -400)), SC_(4.6822269214637968690651040333526494618220547616350e180) }},
  172. #endif
  173. {{ SC_(-0.5), static_cast<T>(std::ldexp(0.5, -683)), SC_(3.5741154998461284276309443770923823816821202344841e102) }},
  174. {{ SC_(0.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(5.73416113922265864550047623401604244038331542638719289e15) }},
  175. {{ SC_(1.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(5.164873193977108862252341626669725460073766e31) }},
  176. {{ SC_(2.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(1.8608416793448936781963026443824482966468761e48) }},
  177. {{ SC_(3.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(1.0056583072431781406772110820260315331263726e65) }},
  178. {{ SC_(10.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(3.74455823365114672304576809031094538692683400e184) }},
  179. }};
  180. do_test_cyl_neumann_y_prime<T>(y0_prime_data, name, "Y'0: Mathworld Data");
  181. do_test_cyl_neumann_y_prime<T>(y1_prime_data, name, "Y'1: Mathworld Data");
  182. do_test_cyl_neumann_y_prime<T>(yn_prime_data, name, "Y'n: Mathworld Data");
  183. do_test_cyl_neumann_y_prime_int<T>(y0_prime_data, name, "Y'0: Mathworld Data (Integer Version)");
  184. do_test_cyl_neumann_y_prime_int<T>(y1_prime_data, name, "Y'1: Mathworld Data (Integer Version)");
  185. do_test_cyl_neumann_y_prime_int<T>(yn_prime_data, name, "Y'n: Mathworld Data (Integer Version)");
  186. do_test_cyl_neumann_y_prime<T>(yv_prime_data, name, "Y'v: Mathworld Data");
  187. if(yv_prime_large_data[0][1] != 0)
  188. do_test_cyl_neumann_y_prime<T>(yv_prime_large_data, name, "Y'v: Mathworld Data (large values)");
  189. #include "bessel_y01_prime_data.ipp"
  190. do_test_cyl_neumann_y_prime<T>(bessel_y01_prime_data, name, "Y'0 and Y'1: Random Data");
  191. #include "bessel_yn_prime_data.ipp"
  192. do_test_cyl_neumann_y_prime<T>(bessel_yn_prime_data, name, "Y'n: Random Data");
  193. #include "bessel_yv_prime_data.ipp"
  194. do_test_cyl_neumann_y_prime<T>(bessel_yv_prime_data, name, "Y'v: Random Data");
  195. #include "sph_neumann_prime_data.ipp"
  196. do_test_sph_neumann_y_prime<T>(sph_neumann_prime_data, name, "y': Random Data");
  197. }