1 [section:expint Exponential Integrals]
3 [section:expint_n Exponential Integral En]
8 #include <boost/math/special_functions/expint.hpp>
11 namespace boost{ namespace math{
14 ``__sf_result`` expint(unsigned n, T z);
16 template <class T, class ``__Policy``>
17 ``__sf_result`` expint(unsigned n, T z, const ``__Policy``&);
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.
29 ``__sf_result`` expint(unsigned n, T z);
31 template <class T, class ``__Policy``>
32 ``__sf_result`` expint(unsigned n, T z, const ``__Policy``&);
34 Returns the [@http://mathworld.wolfram.com/En-Function.html exponential integral En]
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.
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.
65 The generic version of this function uses the continued fraction:
69 for large /x/ and the infinite series:
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
79 For `x < 1` the approximating form is a minimax approximation:
83 and for `x > 1` a Chebyshev interpolated approximation of the form:
89 [endsect] [/section:expint_n Exponential Integral En]
92 [section:expint_i Exponential Integral Ei]
97 #include <boost/math/special_functions/expint.hpp>
100 namespace boost{ namespace math{
103 ``__sf_result`` expint(T z);
105 template <class T, class ``__Policy``>
106 ``__sf_result`` expint(T z, const ``__Policy``&);
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.
118 ``__sf_result`` expint(T z);
120 template <class T, class ``__Policy``>
121 ``__sf_result`` expint(T z, const ``__Policy``&);
123 Returns the [@http://mathworld.wolfram.com/ExponentialIntegral.html exponential integral]
126 [equation expint_i_1]
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.
140 It should be noted that all three libraries tested above
141 offer sub-epsilon precision over most of their range.
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\].
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`.
150 [graph exponential_integral_ei__double]
152 [graph exponential_integral_ei__80_bit_long_double]
154 [graph exponential_integral_ei____float128]
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.
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
174 For x > 0 the generic version is implemented using the infinte series:
176 [equation expint_i_2]
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.
181 For 0 < z < 6 a root-preserving approximation of the form:
183 [equation expint_i_3]
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\].
201 Over the a series of intervals ['[a, b]] and ['[b, INF]] the rational approximation
204 [equation expint_i_4]
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.
218 [endsect] [/section:expint_n Exponential Integral En]
220 [endsect] [/section:expint Exponential Integrals]
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).