• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright (c) 2017 John Maddock
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/quadrature/gauss_kronrod.hpp>
7 #include <boost/multiprecision/cpp_bin_float.hpp>
8 
9 template <class T>
print_gauss_constants(const char * suffix,int prec,int tag)10 void print_gauss_constants(const char* suffix, int prec, int tag)
11 {
12    auto ab = T::abscissa();
13    auto w = T::weights();
14    std::cout << std::setprecision(prec) << std::scientific;
15    std::size_t order = (ab[0] == 0) ? (ab.size() * 2) - 1 : ab.size() * 2;
16    std::cout <<
17       "template <class T>\n"
18       "class gauss_detail<T, " << order << ", " << tag << ">\n"
19       "   {\n"
20       "   public:\n"
21       "      static " << (prec > 40 ? " " : "constexpr ") << "std::array<T, " << ab.size() << "> const & abscissa()\n"
22       "      {\n"
23       "         static " << (prec > 40 ? " " : "constexpr ") << "std::array<T, " << ab.size() << "> data = {\n";
24    for (unsigned i = 0; i < ab.size(); ++i)
25       std::cout << "            " << (prec > 40 ? "BOOST_MATH_HUGE_CONSTANT(T, 0, " : "") << ab[i] << (prec > 40 ? ")" : suffix) << ",\n";
26    std::cout <<
27       "};\n"
28       "         return data;\n"
29       "      }\n"
30       "      static " << (prec > 40 ? " " : "constexpr ") << "std::array<T, " << w.size() << "> const & weights()\n"
31       "      {\n"
32       "         static " << (prec > 40 ? " " : "constexpr ") << "std::array<T, " << w.size() << "> data = {\n";
33    for (unsigned i = 0; i < w.size(); ++i)
34       std::cout << "            " << (prec > 40 ? "BOOST_MATH_HUGE_CONSTANT(T, 0, " : "") << w[i] << (prec > 40 ? ")" : suffix) << ",\n";
35 
36    std::cout << "         };\n"
37       "         return data;\n"
38       "      }\n"
39       "   };\n\n";
40 }
41 
42 template <class T>
print_gauss_kronrod_constants(const char * suffix,int prec,int tag)43 void print_gauss_kronrod_constants(const char* suffix, int prec, int tag)
44 {
45    auto ab = T::abscissa();
46    auto w = T::weights();
47    std::cout << std::setprecision(prec) << std::scientific;
48    std::size_t order = (ab.size() * 2) - 1;
49    std::cout <<
50       "   template <class T>\n"
51       "   class gauss_kronrod_detail<T, " << order << ", " << tag << ">\n"
52       "   {\n"
53       "   public:\n"
54       "      static " << (prec > 40 ? " " : "constexpr ") << "std::array<T, " << ab.size() << "> const & abscissa()\n"
55       "      {\n"
56       "         static " << (prec > 40 ? " " : "constexpr ") << "std::array<T, " << ab.size() << "> data = {\n";
57 
58    for (unsigned i = 0; i < ab.size(); ++i)
59       std::cout << "            " << (prec > 40 ? "BOOST_MATH_HUGE_CONSTANT(T, 0, " : "") << ab[i] << (prec > 40 ? ")" : suffix) << ",\n";
60 
61    std::cout << "         };\n"
62       "         return data;\n"
63       "      }\n"
64       "      static " << (prec > 40 ? " " : "constexpr ") << "std::array<T, " << w.size() << "> const & weights()\n"
65       "      {\n"
66       "         static " << (prec > 40 ? " " : "constexpr ") << "std::array<T, " << w.size() << "> data = {\n";
67 
68    for (unsigned i = 0; i < w.size(); ++i)
69       std::cout << "            " << (prec > 40 ? "BOOST_MATH_HUGE_CONSTANT(T, 0, " : "") << w[i] << (prec > 40 ? ")" : suffix) << ",\n";
70 
71    std::cout << "         };\n"
72       "         return data;\n"
73       "      }\n"
74       "   };\n\n";
75 }
76 
77 
78 
main()79 int main()
80 {
81    typedef boost::multiprecision::number<boost::multiprecision::cpp_bin_float<250> > mp_type;
82 
83    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 7> >("f", 9, 0);
84    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 7> >("", 17, 1);
85    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 7> >("L", 35, 2);
86    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 7> >("Q", 35, 3);
87    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 7> >("", 115, 4);
88 
89    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 10> >("f", 9, 0);
90    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 10> >("", 17, 1);
91    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 10> >("L", 35, 2);
92    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 10> >("Q", 35, 3);
93    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 10> >("", 115, 4);
94 
95    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 15> >("f", 9, 0);
96    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 15> >("", 17, 1);
97    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 15> >("L", 35, 2);
98    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 15> >("Q", 35, 3);
99    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 15> >("", 115, 4);
100 
101    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 20> >("f", 9, 0);
102    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 20> >("", 17, 1);
103    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 20> >("L", 35, 2);
104    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 20> >("Q", 35, 3);
105    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 20> >("", 115, 4);
106 
107    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 25> >("f", 9, 0);
108    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 25> >("", 17, 1);
109    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 25> >("L", 35, 2);
110    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 25> >("Q", 35, 3);
111    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 25> >("", 115, 4);
112 
113    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 30> >("f", 9, 0);
114    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 30> >("", 17, 1);
115    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 30> >("L", 35, 2);
116    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 30> >("Q", 35, 3);
117    print_gauss_constants<boost::math::quadrature::gauss<mp_type, 30> >("", 115, 4);
118 
119 
120    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 15> >("f", 9, 0);
121    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 15> >("", 17, 1);
122    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 15> >("L", 35, 2);
123    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 15> >("Q", 35, 3);
124    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 15> >("", 115, 4);
125 
126    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 21> >("f", 9, 0);
127    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 21> >("", 17, 1);
128    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 21> >("L", 35, 2);
129    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 21> >("Q", 35, 3);
130    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 21> >("", 115, 4);
131 
132    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 31> >("f", 9, 0);
133    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 31> >("", 17, 1);
134    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 31> >("L", 35, 2);
135    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 31> >("Q", 35, 3);
136    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 31> >("", 115, 4);
137 
138    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 41> >("f", 9, 0);
139    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 41> >("", 17, 1);
140    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 41> >("L", 35, 2);
141    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 41> >("Q", 35, 3);
142    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 41> >("", 115, 4);
143 
144    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 51> >("f", 9, 0);
145    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 51> >("", 17, 1);
146    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 51> >("L", 35, 2);
147    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 51> >("Q", 35, 3);
148    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 51> >("", 115, 4);
149 
150    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 61> >("f", 9, 0);
151    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 61> >("", 17, 1);
152    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 61> >("L", 35, 2);
153    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 61> >("Q", 35, 3);
154    print_gauss_kronrod_constants<boost::math::quadrature::gauss_kronrod<mp_type, 61> >("", 115, 4);
155 
156    return 0;
157 }
158 
159