hyp_2f2_data.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #define BOOST_MATH_MAX_SERIES_ITERATION_POLICY 10000000
  6. #include <boost/math/constants/constants.hpp>
  7. #include <boost/lexical_cast.hpp>
  8. #include <fstream>
  9. #include <map>
  10. #include <boost/math/tools/test_data.hpp>
  11. #include <boost/random.hpp>
  12. #include "mp_t.hpp"
  13. using namespace boost::math::tools;
  14. using namespace boost::math;
  15. using namespace std;
  16. struct hypergeometric_2f2_gen
  17. {
  18. mp_t operator()(mp_t a1, mp_t a2, mp_t b1, mp_t b2, mp_t z)
  19. {
  20. mp_t result = 0;
  21. mp_t abs_result = 0;
  22. mp_t term = 1;
  23. mp_t k = 0;
  24. do
  25. {
  26. result += term;
  27. abs_result += fabs(term);
  28. if (fabs(result) * boost::math::tools::epsilon<mp_t>() > fabs(term))
  29. break;
  30. ++k;
  31. term *= a1++;
  32. term *= a2++;
  33. term /= b1++;
  34. term /= b2++;
  35. term /= k;
  36. term *= z;
  37. } while (true);
  38. //
  39. // check precision:
  40. //
  41. if (abs_result * boost::math::tools::epsilon<mp_t>() / fabs(result) > 1e-40)
  42. throw std::domain_error("Unable to calculate result");
  43. if(fabs(result) > (std::numeric_limits<double>::max)())
  44. throw std::domain_error("Unable to calculate result");
  45. std::cout << a1 << " " << a2 << " " << b1 << " " << b2 << " " << z << " " << result << std::endl;
  46. return result;
  47. }
  48. };
  49. int main(int, char* [])
  50. {
  51. parameter_info<mp_t> arg1, arg2, arg3, arg4, arg5;
  52. test_data<mp_t> data;
  53. std::cout << "Welcome.\n"
  54. "This program will generate spot tests for 2F2:\n";
  55. std::string line;
  56. bool cont = true;
  57. while (cont)
  58. {
  59. float range;
  60. std::cout << "Enter the range to calculate over for a1, a2, b1 and b2 (single value, range will be -x to x): ";
  61. std::cin >> range;
  62. float z_range;
  63. std::cout << "Enter the range to calculate over for z (single value, range will be -x to x): ";
  64. std::cin >> z_range;
  65. int num_spots;
  66. std::cout << "Enter how many test points to calculate: ";
  67. std::cin >> num_spots;
  68. std::vector<mp_t> v;
  69. random_ns::mt19937 rnd;
  70. random_ns::uniform_real_distribution<float> ur_a(-range, range);
  71. random_ns::uniform_real_distribution<float> ur_z(-z_range, z_range);
  72. do
  73. {
  74. mp_t a1 = ur_a(rnd);
  75. mp_t a2 = ur_a(rnd);
  76. mp_t b1 = ur_a(rnd);
  77. mp_t b2 = ur_a(rnd);
  78. mp_t z = ur_z(rnd);
  79. arg1 = make_single_param(a1);
  80. arg2 = make_single_param(a2);
  81. arg3 = make_single_param(b1);
  82. arg4 = make_single_param(b2);
  83. arg5 = make_single_param(z);
  84. data.insert(hypergeometric_2f2_gen(), arg1, arg2, arg3, arg4, arg5);
  85. } while (num_spots--);
  86. std::cout << "Any more data?";
  87. std::cin >> cont;
  88. }
  89. std::cout << "Enter name of test data file [default=hypergeometric_2f2.ipp]";
  90. std::getline(std::cin, line);
  91. boost::algorithm::trim(line);
  92. if(line == "")
  93. line = "hypergeometric_2f2.ipp";
  94. std::ofstream ofs(line.c_str());
  95. ofs << std::scientific << std::setprecision(40);
  96. write_code(ofs, data, line.c_str());
  97. return 0;
  98. }