test_laguerre.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #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/array.hpp>
  13. #include "functor.hpp"
  14. #include "handle_test_result.hpp"
  15. #include "table_type.hpp"
  16. #ifndef SC_
  17. #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
  18. #endif
  19. template <class Real, class T>
  20. void do_test_laguerre2(const T& data, const char* type_name, const char* test_name)
  21. {
  22. #if !(defined(ERROR_REPORTING_MODE) && !defined(LAGUERRE_FUNCTION_TO_TEST))
  23. typedef Real value_type;
  24. typedef value_type (*pg)(unsigned, value_type);
  25. #ifdef LAGUERRE_FUNCTION_TO_TEST
  26. pg funcp = LAGUERRE_FUNCTION_TO_TEST;
  27. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  28. pg funcp = boost::math::laguerre<value_type>;
  29. #else
  30. pg funcp = boost::math::laguerre;
  31. #endif
  32. boost::math::tools::test_result<value_type> result;
  33. std::cout << "Testing " << test_name << " with type " << type_name
  34. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  35. //
  36. // test laguerre against data:
  37. //
  38. result = boost::math::tools::test_hetero<Real>(
  39. data,
  40. bind_func_int1<Real>(funcp, 0, 1),
  41. extract_result<Real>(2));
  42. handle_test_result(result, data[result.worst()], result.worst(), type_name, "laguerre(n, x)", test_name);
  43. std::cout << std::endl;
  44. #endif
  45. }
  46. template <class Real, class T>
  47. void do_test_laguerre3(const T& data, const char* type_name, const char* test_name)
  48. {
  49. #if !(defined(ERROR_REPORTING_MODE) && !defined(ASSOC_LAGUERRE_FUNCTION_TO_TEST))
  50. typedef Real value_type;
  51. typedef value_type (*pg)(unsigned, unsigned, value_type);
  52. #ifdef ASSOC_LAGUERRE_FUNCTION_TO_TEST
  53. pg funcp = ASSOC_LAGUERRE_FUNCTION_TO_TEST;
  54. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  55. pg funcp = boost::math::laguerre<unsigned, value_type>;
  56. #else
  57. pg funcp = boost::math::laguerre;
  58. #endif
  59. boost::math::tools::test_result<value_type> result;
  60. std::cout << "Testing " << test_name << " with type " << type_name
  61. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  62. //
  63. // test laguerre against data:
  64. //
  65. result = boost::math::tools::test_hetero<Real>(
  66. data,
  67. bind_func_int2<Real>(funcp, 0, 1, 2),
  68. extract_result<Real>(3));
  69. handle_test_result(result, data[result.worst()], result.worst(), type_name, "laguerre(n, m, x)", test_name);
  70. std::cout << std::endl;
  71. #endif
  72. }
  73. template <class T>
  74. void test_laguerre(T, const char* name)
  75. {
  76. //
  77. // The actual test data is rather verbose, so it's in a separate file
  78. //
  79. // The contents are as follows, each row of data contains
  80. // three items, input value a, input value b and erf(a, b):
  81. //
  82. # include "laguerre2.ipp"
  83. do_test_laguerre2<T>(laguerre2, name, "Laguerre Polynomials");
  84. # include "laguerre3.ipp"
  85. do_test_laguerre3<T>(laguerre3, name, "Associated Laguerre Polynomials");
  86. }
  87. template <class T>
  88. void test_spots(T, const char* t)
  89. {
  90. std::cout << "Testing basic sanity checks for type " << t << std::endl;
  91. //
  92. // basic sanity checks, tolerance is 100 epsilon:
  93. //
  94. T tolerance = boost::math::tools::epsilon<T>() * 100;
  95. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(1, static_cast<T>(0.5L)), static_cast<T>(0.5L), tolerance);
  96. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, static_cast<T>(0.5L)), static_cast<T>(-0.3307291666666666666666666666666666666667L), tolerance);
  97. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(7, static_cast<T>(0.5L)), static_cast<T>(-0.5183392237103174603174603174603174603175L), tolerance);
  98. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(20, static_cast<T>(0.5L)), static_cast<T>(0.3120174870800154148915399248893113634676L), tolerance);
  99. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, static_cast<T>(0.5L)), static_cast<T>(-0.3181388060269979064951118308575628226834L), tolerance);
  100. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(1, static_cast<T>(-0.5L)), static_cast<T>(1.5L), tolerance);
  101. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, static_cast<T>(-0.5L)), static_cast<T>(3.835937500000000000000000000000000000000L), tolerance);
  102. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(7, static_cast<T>(-0.5L)), static_cast<T>(7.950934709821428571428571428571428571429L), tolerance);
  103. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(20, static_cast<T>(-0.5L)), static_cast<T>(76.12915699869631476833699787070874048223L), tolerance);
  104. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, static_cast<T>(-0.5L)), static_cast<T>(2307.428631277506570629232863491518399720L), tolerance);
  105. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(1, static_cast<T>(4.5L)), static_cast<T>(-3.500000000000000000000000000000000000000L), tolerance);
  106. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, static_cast<T>(4.5L)), static_cast<T>(0.08593750000000000000000000000000000000000L), tolerance);
  107. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(7, static_cast<T>(4.5L)), static_cast<T>(-1.036928013392857142857142857142857142857L), tolerance);
  108. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(20, static_cast<T>(4.5L)), static_cast<T>(1.437239150257817378525582974722170737587L), tolerance);
  109. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, static_cast<T>(4.5L)), static_cast<T>(-0.7795068145562651416494321484050019245248L), tolerance);
  110. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, 5, static_cast<T>(0.5L)), static_cast<T>(88.31510416666666666666666666666666666667L), tolerance);
  111. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 0, static_cast<T>(2.5L)), static_cast<T>(-0.8802526766660982969576719576719576719577L), tolerance);
  112. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 1, static_cast<T>(4.5L)), static_cast<T>(1.564311458042689732142857142857142857143L), tolerance);
  113. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 6, static_cast<T>(8.5L)), static_cast<T>(20.51596541066649098875661375661375661376L), tolerance);
  114. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 12, static_cast<T>(12.5L)), static_cast<T>(-199.5560968456234671241181657848324514991L), tolerance);
  115. BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, 40, static_cast<T>(12.5L)), static_cast<T>(-4.996769495006119488583146995907246595400e16L), tolerance);
  116. }