test_legendre.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // (C) Copyright John Maddock 2006.
  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. #include <pch_light.hpp>
  6. #include "test_legendre.hpp"
  7. //
  8. // DESCRIPTION:
  9. // ~~~~~~~~~~~~
  10. //
  11. // This file tests the legendre polynomials.
  12. // There are two sets of tests, spot
  13. // tests which compare our results with selected values computed
  14. // using the online special function calculator at
  15. // functions.wolfram.com, while the bulk of the accuracy tests
  16. // use values generated with NTL::RR at 1000-bit precision
  17. // and our generic versions of these functions.
  18. //
  19. // Note that when this file is first run on a new platform many of
  20. // these tests will fail: the default accuracy is 1 epsilon which
  21. // is too tight for most platforms. In this situation you will
  22. // need to cast a human eye over the error rates reported and make
  23. // a judgement as to whether they are acceptable. Either way please
  24. // report the results to the Boost mailing list. Acceptable rates of
  25. // error are marked up below as a series of regular expressions that
  26. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  27. // along with the maximum expected peek and RMS mean errors for that
  28. // test.
  29. //
  30. void expected_results()
  31. {
  32. //
  33. // Define the max and mean errors expected for
  34. // various compilers and platforms.
  35. //
  36. const char* largest_type;
  37. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  38. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  39. {
  40. largest_type = "(long\\s+)?double";
  41. }
  42. else
  43. {
  44. largest_type = "long double";
  45. }
  46. #else
  47. largest_type = "(long\\s+)?double";
  48. #endif
  49. //
  50. // Linux:
  51. //
  52. if((std::numeric_limits<long double>::digits <= 64)
  53. && (std::numeric_limits<long double>::digits != std::numeric_limits<double>::digits))
  54. {
  55. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  56. add_expected_result(
  57. ".*", // compiler
  58. ".*", // stdlib
  59. ".*", // platform
  60. "double", // test type(s)
  61. ".*", // test data group
  62. ".*", 10, 5); // test function
  63. #endif
  64. }
  65. if(std::numeric_limits<long double>::digits == 64)
  66. {
  67. add_expected_result(
  68. ".*", // compiler
  69. ".*", // stdlib
  70. ".*", // platform
  71. largest_type, // test type(s)
  72. "Legendre Polynomials.*Large.*", // test data group
  73. "legendre_p", 1000, 200); // test function
  74. add_expected_result(
  75. "Intel.*", // compiler
  76. ".*", // stdlib
  77. ".*", // platform
  78. largest_type, // test type(s)
  79. "Legendre Polynomials.*Large.*", // test data group
  80. "legendre_q", 10000, 1000); // test function
  81. add_expected_result(
  82. ".*", // compiler
  83. ".*", // stdlib
  84. ".*", // platform
  85. largest_type, // test type(s)
  86. "Legendre Polynomials.*Large.*", // test data group
  87. "legendre_q", 7000, 1000); // test function
  88. add_expected_result(
  89. ".*", // compiler
  90. ".*", // stdlib
  91. ".*", // platform
  92. "real_concept", // test type(s)
  93. "Legendre Polynomials.*Large.*", // test data group
  94. "legendre_p", 1000, 200); // test function
  95. add_expected_result(
  96. ".*", // compiler
  97. ".*", // stdlib
  98. ".*", // platform
  99. "real_concept", // test type(s)
  100. "Legendre Polynomials.*Large.*", // test data group
  101. "legendre_q", 7000, 1000); // test function
  102. }
  103. //
  104. // Catch all cases come last:
  105. //
  106. add_expected_result(
  107. ".*", // compiler
  108. ".*", // stdlib
  109. ".*", // platform
  110. largest_type, // test type(s)
  111. "Legendre Polynomials.*Large.*", // test data group
  112. "legendre_p", 500, 200); // test function
  113. add_expected_result(
  114. ".*", // compiler
  115. ".*", // stdlib
  116. ".*", // platform
  117. largest_type, // test type(s)
  118. "Legendre Polynomials.*Large.*", // test data group
  119. "legendre_q", 5400, 500); // test function
  120. add_expected_result(
  121. ".*", // compiler
  122. ".*", // stdlib
  123. ".*", // platform
  124. largest_type, // test type(s)
  125. "Legendre Polynomials.*", // test data group
  126. "legendre_p", 300, 80); // test function
  127. add_expected_result(
  128. ".*", // compiler
  129. ".*", // stdlib
  130. ".*", // platform
  131. largest_type, // test type(s)
  132. "Legendre Polynomials.*", // test data group
  133. "legendre_q", 100, 50); // test function
  134. add_expected_result(
  135. "Intel.*", // compiler
  136. ".*", // stdlib
  137. ".*", // platform
  138. largest_type, // test type(s)
  139. "Associated Legendre Polynomials.*", // test data group
  140. ".*", 300, 20); // test function
  141. add_expected_result(
  142. ".*", // compiler
  143. ".*", // stdlib
  144. ".*", // platform
  145. largest_type, // test type(s)
  146. "Associated Legendre Polynomials.*", // test data group
  147. ".*", 200, 20); // test function
  148. add_expected_result(
  149. ".*", // compiler
  150. ".*", // stdlib
  151. ".*", // platform
  152. "real_concept", // test type(s)
  153. "Legendre Polynomials.*Large.*", // test data group
  154. "legendre_p", 500, 200); // test function
  155. add_expected_result(
  156. ".*", // compiler
  157. ".*", // stdlib
  158. ".*", // platform
  159. "real_concept", // test type(s)
  160. "Legendre Polynomials.*Large.*", // test data group
  161. "legendre_q", 5400, 500); // test function
  162. add_expected_result(
  163. ".*", // compiler
  164. ".*", // stdlib
  165. ".*", // platform
  166. "real_concept", // test type(s)
  167. "Legendre Polynomials.*", // test data group
  168. "legendre_p", 300, 80); // test function
  169. add_expected_result(
  170. ".*", // compiler
  171. ".*", // stdlib
  172. ".*", // platform
  173. "real_concept", // test type(s)
  174. "Legendre Polynomials.*", // test data group
  175. "legendre_q", 100, 50); // test function
  176. add_expected_result(
  177. ".*", // compiler
  178. ".*", // stdlib
  179. ".*", // platform
  180. "real_concept", // test type(s)
  181. "Associated Legendre Polynomials.*", // test data group
  182. ".*", 200, 20); // test function
  183. //
  184. // Finish off by printing out the compiler/stdlib/platform names,
  185. // we do this to make it easier to mark up expected error rates.
  186. //
  187. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  188. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  189. }
  190. BOOST_AUTO_TEST_CASE( test_main )
  191. {
  192. BOOST_MATH_CONTROL_FP;
  193. test_spots(0.0F, "float");
  194. test_spots(0.0, "double");
  195. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  196. test_spots(0.0L, "long double");
  197. test_spots(boost::math::concepts::real_concept(0.1), "real_concept");
  198. #endif
  199. expected_results();
  200. test_legendre_p(0.1F, "float");
  201. test_legendre_p(0.1, "double");
  202. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  203. test_legendre_p(0.1L, "long double");
  204. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  205. test_legendre_p(boost::math::concepts::real_concept(0.1), "real_concept");
  206. #endif
  207. #else
  208. std::cout << "<note>The long double tests have been disabled on this platform "
  209. "either because the long double overloads of the usual math functions are "
  210. "not available at all, or because they are too inaccurate for these tests "
  211. "to pass.</note>" << std::endl;
  212. #endif
  213. test_legendre_p_prime<float>();
  214. test_legendre_p_prime<double>();
  215. test_legendre_p_prime<long double>();
  216. int ulp_distance = test_legendre_p_zeros_double_ulp(1, 100);
  217. BOOST_CHECK(ulp_distance <= 2);
  218. test_legendre_p_zeros<float>();
  219. test_legendre_p_zeros<double>();
  220. test_legendre_p_zeros<long double>();
  221. }