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