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