hyp_1f2_data.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_1f2_gen
  17. {
  18. mp_t operator()(mp_t a1, 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 /= b1++;
  33. term /= b2++;
  34. term /= k;
  35. term *= z;
  36. } while (true);
  37. //
  38. // check precision:
  39. //
  40. if (abs_result * boost::math::tools::epsilon<mp_t>() / fabs(result) > 1e-40)
  41. throw std::domain_error("Unable to calculate result");
  42. std::cout << a1 << " " << b1 << " " << b2 << " " << z << " " << result << std::endl;
  43. return result;
  44. }
  45. };
  46. int main(int, char* [])
  47. {
  48. parameter_info<mp_t> arg1, arg2, arg3, arg4;
  49. test_data<mp_t> data;
  50. std::cout << "Welcome.\n"
  51. "This program will generate spot tests for 2F0:\n";
  52. std::string line;
  53. bool cont = true;
  54. while (cont)
  55. {
  56. float range;
  57. std::cout << "Enter the range to calculate over for a1, b1 and b2 (single value, range will be -x to x): ";
  58. std::cin >> range;
  59. float z_range;
  60. std::cout << "Enter the range to calculate over for z (single value, range will be -x to x): ";
  61. std::cin >> z_range;
  62. int num_spots;
  63. std::cout << "Enter how many test points to calculate: ";
  64. std::cin >> num_spots;
  65. std::vector<mp_t> v;
  66. random_ns::mt19937 rnd;
  67. random_ns::uniform_real_distribution<float> ur_a(-range, range);
  68. random_ns::uniform_real_distribution<float> ur_z(-z_range, z_range);
  69. do
  70. {
  71. mp_t a1 = ur_a(rnd);
  72. mp_t b1 = ur_a(rnd);
  73. mp_t b2 = ur_a(rnd);
  74. mp_t z = ur_z(rnd);
  75. arg1 = make_single_param(a1);
  76. arg2 = make_single_param(b1);
  77. arg3 = make_single_param(b2);
  78. arg4 = make_single_param(z);
  79. data.insert(hypergeometric_1f2_gen(), arg1, arg2, arg3, arg4);
  80. } while (num_spots--);
  81. std::cout << "Any more data?";
  82. std::cin >> cont;
  83. }
  84. std::cout << "Enter name of test data file [default=hypergeometric_1f2.ipp]";
  85. std::getline(std::cin, line);
  86. boost::algorithm::trim(line);
  87. if(line == "")
  88. line = "hypergeometric_1f2.ipp";
  89. std::ofstream ofs(line.c_str());
  90. ofs << std::scientific << std::setprecision(40);
  91. write_code(ofs, data, line.c_str());
  92. return 0;
  93. }