hyp_0f2_data.cpp 2.9 KB

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