hyp_2f1_data.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_2f1_gen
  17. {
  18. mp_t operator()(mp_t a1, mp_t a2, mp_t b, 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 /= b++;
  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 << " " << a2 << " " << b << " " << 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;
  54. std::vector<mp_t> v;
  55. random_ns::mt19937 rnd;
  56. random_ns::uniform_real_distribution<float> ur_a(-100, 100);
  57. random_ns::uniform_real_distribution<float> ur_z(-1, 1);
  58. int num_spots;
  59. std::cout << "Enter how many test points to calculate: ";
  60. std::cin >> num_spots;
  61. do
  62. {
  63. mp_t a1 = ur_a(rnd);
  64. mp_t a2 = ur_a(rnd);
  65. mp_t b = ur_a(rnd);
  66. mp_t z = ur_z(rnd);
  67. arg1 = make_single_param(a1);
  68. arg2 = make_single_param(a2);
  69. arg3 = make_single_param(b);
  70. arg4 = make_single_param(z);
  71. data.insert(hypergeometric_2f1_gen(), arg1, arg2, arg3, arg4);
  72. } while (num_spots--);
  73. std::cout << "Enter name of test data file [default=hypergeometric_2f1.ipp]";
  74. std::getline(std::cin, line);
  75. boost::algorithm::trim(line);
  76. if(line == "")
  77. line = "hypergeometric_2f1.ipp";
  78. std::ofstream ofs(line.c_str());
  79. ofs << std::scientific << std::setprecision(40);
  80. write_code(ofs, data, line.c_str());
  81. return 0;
  82. }