Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / math / doc / sf / expint.qbk
1 [section:expint Exponential Integrals]
2
3 [section:expint_n Exponential Integral En]
4
5 [h4 Synopsis]
6
7 ``
8 #include <boost/math/special_functions/expint.hpp>
9 ``
10
11    namespace boost{ namespace math{
12    
13    template <class T>
14    ``__sf_result`` expint(unsigned n, T z);
15    
16    template <class T, class ``__Policy``>
17    ``__sf_result`` expint(unsigned n, T z, const ``__Policy``&);
18    
19    }} // namespaces
20    
21 The return type of these functions is computed using the __arg_promotion_rules:
22 the return type is `double` if T is an integer type, and T otherwise.
23
24 [optional_policy]
25
26 [h4 Description]
27
28    template <class T>
29    ``__sf_result`` expint(unsigned n, T z);
30    
31    template <class T, class ``__Policy``>
32    ``__sf_result`` expint(unsigned n, T z, const ``__Policy``&);
33    
34 Returns the [@http://mathworld.wolfram.com/En-Function.html exponential integral En]
35 of z:
36
37 [equation expint_n_1]
38
39 [graph expint2]
40
41 [h4 Accuracy]
42
43 The following table shows the peak errors (in units of epsilon) 
44 found on various platforms with various floating point types, 
45 along with comparisons to other libraries.
46 Unless otherwise specified any floating point type that is narrower
47 than the one shown will have __zero_error.
48
49 [table_expint_En_]
50
51 [h4 Testing]
52
53 The tests for these functions come in two parts:
54 basic sanity checks use spot values calculated using
55 [@http://functions.wolfram.com/webMathematica/FunctionEvaluation.jsp?name=ExpIntegralE Mathworld's online evaluator],
56 while accuracy checks use high-precision test values calculated at 1000-bit precision with
57 [@http://shoup.net/ntl/doc/RR.txt NTL::RR] and this implementation. 
58 Note that the generic and type-specific
59 versions of these functions use differing implementations internally, so this
60 gives us reasonably independent test data.  Using our test data to test other
61 "known good" implementations also provides an additional sanity check. 
62
63 [h4 Implementation]
64
65 The generic version of this function uses the continued fraction:
66
67 [equation expint_n_3]
68
69 for large /x/ and the infinite series:
70
71 [equation expint_n_2]
72
73 for small /x/.
74
75 Where the precision of /x/ is known at compile time and is 113 bits or fewer
76 in precision, then rational approximations [jm_rationals] are used for the 
77 `n == 1` case.
78
79 For `x < 1` the approximating form is a minimax approximation:
80
81 [equation expint_n_4]
82
83 and for `x > 1` a Chebyshev interpolated approximation of the form:
84
85 [equation expint_n_5]
86
87 is used.
88
89 [endsect] [/section:expint_n Exponential Integral En]
90
91
92 [section:expint_i Exponential Integral Ei]
93
94 [h4 Synopsis]
95
96 ``
97 #include <boost/math/special_functions/expint.hpp>
98 ``
99
100    namespace boost{ namespace math{
101    
102    template <class T>
103    ``__sf_result`` expint(T z);
104    
105    template <class T, class ``__Policy``>
106    ``__sf_result`` expint(T z, const ``__Policy``&);
107    
108    }} // namespaces
109    
110 The return type of these functions is computed using the __arg_promotion_rules:
111 the return type is `double` if T is an integer type, and T otherwise.
112
113 [optional_policy]
114
115 [h4 Description]
116
117    template <class T>
118    ``__sf_result`` expint(T z);
119    
120    template <class T, class ``__Policy``>
121    ``__sf_result`` expint(T z, const ``__Policy``&);
122    
123 Returns the [@http://mathworld.wolfram.com/ExponentialIntegral.html exponential integral]
124 of z:
125
126 [equation expint_i_1]
127
128 [graph expint_i]
129
130 [h4 Accuracy]
131
132 The following table shows the peak errors (in units of epsilon) 
133 found on various platforms with various floating point types, 
134 along with comparisons to Cody's SPECFUN implementation and the __gsl library.
135 Unless otherwise specified any floating point type that is narrower
136 than the one shown will have __zero_error.
137
138 [table_expint_Ei_]
139
140 It should be noted that all three libraries tested above 
141 offer sub-epsilon precision over most of their range.
142
143 GSL has the greatest difficulty near the positive root of En, while
144 Cody's SPECFUN along with this implementation increase their
145 error rates very slightly over the range \[4,6\].
146
147 The following error plot are based on an exhaustive search of the functions domain, MSVC-15.5 at `double` precision, 
148 and GCC-7.1/Ubuntu for `long double` and `__float128`.
149
150 [graph exponential_integral_ei__double]
151
152 [graph exponential_integral_ei__80_bit_long_double]
153
154 [graph exponential_integral_ei____float128]
155
156 [h4 Testing]
157
158 The tests for these functions come in two parts:
159 basic sanity checks use spot values calculated using
160 [@http://functions.wolfram.com/webMathematica/FunctionEvaluation.jsp?name=ExpIntegralEi Mathworld's online evaluator],
161 while accuracy checks use high-precision test values calculated at 1000-bit precision with
162 [@http://shoup.net/ntl/doc/RR.txt NTL::RR] and this implementation. 
163 Note that the generic and type-specific
164 versions of these functions use differing implementations internally, so this
165 gives us reasonably independent test data.  Using our test data to test other
166 "known good" implementations also provides an additional sanity check. 
167
168 [h4 Implementation]
169
170 For x < 0 this function just calls __expint_n(1, -x): which in turn is implemented
171 in terms of rational approximations when the type of x has 113 or fewer bits of
172 precision.
173
174 For x > 0 the generic version is implemented using the infinte series:
175
176 [equation expint_i_2]
177
178 However, when the precision of the argument type is known at compile time
179 and is 113 bits or less, then rational approximations [jm_rationals] are used.
180
181 For 0 < z < 6 a root-preserving approximation of the form:
182
183 [equation expint_i_3]
184
185 is used, where z[sub 0] is the positive root of the function, and
186 R(z/3 - 1) is a minimax rational approximation rescaled so that
187 it is evaluated over \[-1,1\].  Note that while the rational approximation
188 over \[0,6\] converges rapidly to the minimax solution it is rather
189 ill-conditioned in practice.  Cody and Thacher
190 [footnote W. J. Cody and H. C. Thacher, Jr., 
191 Rational Chebyshev approximations for the exponential integral E[sub 1](x), 
192 Math. Comp. 22 (1968), 641-649,
193 and W. J. Cody and H. C. Thacher, Jr., Chebyshev approximations for the 
194 exponential integral Ei(x), Math. Comp. 23 (1969), 289-303.]
195 experienced the same issue and 
196 converted the polynomials into Chebeshev form to ensure stable
197 computation.  By experiment we found that the polynomials are just as stable
198 in polynomial as Chebyshev form, /provided/ they are computed
199 over the interval \[-1,1\].
200
201 Over the a series of intervals ['[a, b]] and ['[b, INF]] the rational approximation
202 takes the form:
203
204 [equation expint_i_4]
205
206 where /c/ is a constant, and ['R(t)] is a minimax solution optimised for low
207 absolute error compared to /c/.  Variable /t/ is `1/z` when the range in infinite
208 and `2z/(b-a) - (2a/(b-a) + 1)` otherwise: this has the effect of scaling z to the 
209 interval \[-1,1\].  As before rational approximations over arbitrary intervals
210 were found to be ill-conditioned: Cody and Thacher solved this issue by 
211 converting the polynomials to their J-Fraction equivalent.  However, as long
212 as the interval of evaluation was \[-1,1\] and the number of terms carefully chosen,
213 it was found that the polynomials /could/ be evaluated to suitable precision:
214 error rates are typically 2 to 3 epsilon which is comparible to the error
215 rate that Cody and Thacher achieved using J-Fractions, but marginally more
216 efficient given that fewer divisions are involved.
217
218 [endsect] [/section:expint_n Exponential Integral En] 
219
220 [endsect] [/section:expint Exponential Integrals]
221
222 [/ 
223   Copyright 2006 John Maddock and Paul A. Bristow.
224   Distributed under the Boost Software License, Version 1.0.
225   (See accompanying file LICENSE_1_0.txt or copy at
226   http://www.boost.org/LICENSE_1_0.txt).
227 ]