legendre_data.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // (C) Copyright John Maddock 2007.
  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 <boost/math/special_functions/legendre.hpp>
  6. #include <boost/math/special_functions/gamma.hpp>
  7. #include <fstream>
  8. #include <boost/math/tools/test_data.hpp>
  9. #include <boost/random.hpp>
  10. #include "mp_t.hpp"
  11. using namespace boost::math::tools;
  12. using namespace boost::math;
  13. using namespace std;
  14. template<class T>
  15. boost::math::tuple<T, T, T, T> legendre_p_data(T n, T x)
  16. {
  17. n = floor(n);
  18. T r1 = legendre_p(boost::math::tools::real_cast<int>(n), x);
  19. T r2 = legendre_q(boost::math::tools::real_cast<int>(n), x);
  20. return boost::math::make_tuple(n, x, r1, r2);
  21. }
  22. template<class T>
  23. boost::math::tuple<T, T, T, T> assoc_legendre_p_data(T n, T x)
  24. {
  25. static boost::mt19937 r;
  26. int l = real_cast<int>(floor(n));
  27. boost::uniform_int<> ui((std::max)(-l, -40), (std::min)(l, 40));
  28. int m = ui(r);
  29. T r1 = legendre_p(l, m, x);
  30. return boost::math::make_tuple(n, m, x, r1);
  31. }
  32. int main(int argc, char*argv [])
  33. {
  34. using namespace boost::math::tools;
  35. parameter_info<mp_t> arg1, arg2;
  36. test_data<mp_t> data;
  37. bool cont;
  38. std::string line;
  39. if(argc < 1)
  40. return 1;
  41. if(strcmp(argv[1], "--legendre2") == 0)
  42. {
  43. do{
  44. if(0 == get_user_parameter_info(arg1, "l"))
  45. return 1;
  46. if(0 == get_user_parameter_info(arg2, "x"))
  47. return 1;
  48. arg1.type |= dummy_param;
  49. arg2.type |= dummy_param;
  50. data.insert(&legendre_p_data<mp_t>, arg1, arg2);
  51. std::cout << "Any more data [y/n]?";
  52. std::getline(std::cin, line);
  53. boost::algorithm::trim(line);
  54. cont = (line == "y");
  55. }while(cont);
  56. }
  57. else if(strcmp(argv[1], "--legendre3") == 0)
  58. {
  59. do{
  60. if(0 == get_user_parameter_info(arg1, "l"))
  61. return 1;
  62. if(0 == get_user_parameter_info(arg2, "x"))
  63. return 1;
  64. arg1.type |= dummy_param;
  65. arg2.type |= dummy_param;
  66. data.insert(&assoc_legendre_p_data<mp_t>, arg1, arg2);
  67. std::cout << "Any more data [y/n]?";
  68. std::getline(std::cin, line);
  69. boost::algorithm::trim(line);
  70. cont = (line == "y");
  71. }while(cont);
  72. }
  73. std::cout << "Enter name of test data file [default=legendre_p.ipp]";
  74. std::getline(std::cin, line);
  75. boost::algorithm::trim(line);
  76. if(line == "")
  77. line = "legendre_p.ipp";
  78. std::ofstream ofs(line.c_str());
  79. ofs << std::scientific << std::setprecision(40);
  80. line.erase(line.find('.'));
  81. write_code(ofs, data, line.c_str());
  82. return 0;
  83. }