Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / math / tools / legendre_data.cpp
1 //  (C) Copyright John Maddock 2007.
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 #include <boost/math/special_functions/legendre.hpp>
7 #include <boost/math/special_functions/gamma.hpp>
8 #include <fstream>
9 #include <boost/math/tools/test_data.hpp>
10 #include <boost/random.hpp>
11 #include "mp_t.hpp"
12
13 using namespace boost::math::tools;
14 using namespace boost::math;
15 using namespace std;
16
17
18 template<class T>
19 boost::math::tuple<T, T, T, T> legendre_p_data(T n, T x)
20 {
21    n = floor(n);
22    T r1 = legendre_p(boost::math::tools::real_cast<int>(n), x);
23    T r2 = legendre_q(boost::math::tools::real_cast<int>(n), x);
24    return boost::math::make_tuple(n, x, r1, r2);
25 }
26    
27 template<class T>
28 boost::math::tuple<T, T, T, T> assoc_legendre_p_data(T n, T x)
29 {
30    static boost::mt19937 r;
31    int l = real_cast<int>(floor(n));
32    boost::uniform_int<> ui((std::max)(-l, -40), (std::min)(l, 40));
33    int m = ui(r);
34    T r1 = legendre_p(l, m, x);
35    return boost::math::make_tuple(n, m, x, r1);
36 }
37
38 int main(int argc, char*argv [])
39 {
40    using namespace boost::math::tools;
41
42    parameter_info<mp_t> arg1, arg2;
43    test_data<mp_t> data;
44
45    bool cont;
46    std::string line;
47
48    if(argc < 1)
49       return 1;
50
51    if(strcmp(argv[1], "--legendre2") == 0)
52    {
53       do{
54          if(0 == get_user_parameter_info(arg1, "l"))
55             return 1;
56          if(0 == get_user_parameter_info(arg2, "x"))
57             return 1;
58          arg1.type |= dummy_param;
59          arg2.type |= dummy_param;
60
61          data.insert(&legendre_p_data<mp_t>, arg1, arg2);
62
63          std::cout << "Any more data [y/n]?";
64          std::getline(std::cin, line);
65          boost::algorithm::trim(line);
66          cont = (line == "y");
67       }while(cont);
68    }
69    else if(strcmp(argv[1], "--legendre3") == 0)
70    {
71       do{
72          if(0 == get_user_parameter_info(arg1, "l"))
73             return 1;
74          if(0 == get_user_parameter_info(arg2, "x"))
75             return 1;
76          arg1.type |= dummy_param;
77          arg2.type |= dummy_param;
78
79          data.insert(&assoc_legendre_p_data<mp_t>, arg1, arg2);
80
81          std::cout << "Any more data [y/n]?";
82          std::getline(std::cin, line);
83          boost::algorithm::trim(line);
84          cont = (line == "y");
85       }while(cont);
86    }
87
88
89    std::cout << "Enter name of test data file [default=legendre_p.ipp]";
90    std::getline(std::cin, line);
91    boost::algorithm::trim(line);
92    if(line == "")
93       line = "legendre_p.ipp";
94    std::ofstream ofs(line.c_str());
95    ofs << std::scientific << std::setprecision(40);
96    line.erase(line.find('.'));
97    write_code(ofs, data, line.c_str());
98
99    return 0;
100 }
101