2 Copyright (c) 2006 Xiaogang Zhang
3 Copyright (c) 2006 John Maddock
4 Use, modification and distribution are subject to the
5 Boost Software License, Version 1.0. (See accompanying file
6 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 [section:ellint_1 Elliptic Integrals of the First Kind - Legendre Form]
14 #include <boost/math/special_functions/ellint_1.hpp>
17 namespace boost { namespace math {
19 template <class T1, class T2>
20 ``__sf_result`` ellint_1(T1 k, T2 phi);
22 template <class T1, class T2, class ``__Policy``>
23 ``__sf_result`` ellint_1(T1 k, T2 phi, const ``__Policy``&);
26 ``__sf_result`` ellint_1(T k);
28 template <class T, class ``__Policy``>
29 ``__sf_result`` ellint_1(T k, const ``__Policy``&);
35 These two functions evaluate the incomplete elliptic integral of the first kind
36 ['F([phi], k)] and its complete counterpart ['K(k) = F([pi]/2, k)].
40 The return type of these functions is computed using the __arg_promotion_rules
41 when T1 and T2 are different types: when they are the same type then the result
42 is the same type as the arguments.
44 template <class T1, class T2>
45 ``__sf_result`` ellint_1(T1 k, T2 phi);
47 template <class T1, class T2, class ``__Policy``>
48 ``__sf_result`` ellint_1(T1 k, T2 phi, const ``__Policy``&);
50 Returns the incomplete elliptic integral of the first kind ['F([phi], k)]:
54 Requires k[super 2]sin[super 2](phi) < 1, otherwise returns the result of __domain_error.
59 ``__sf_result`` ellint_1(T k);
62 ``__sf_result`` ellint_1(T k, const ``__Policy``&);
64 Returns the complete elliptic integral of the first kind ['K(k)]:
68 Requires |k| < 1, otherwise returns the result of __domain_error.
74 These functions are computed using only basic arithmetic operations, so
75 there isn't much variation in accuracy over differing platforms.
76 Note that only results for the widest floating point type on the
77 system are given as narrower types have __zero_error. All values
78 are relative errors in units of epsilon.
82 The following error plot are based on an exhaustive search of the functions domain, MSVC-15.5 at `double` precision,
83 and GCC-7.1/Ubuntu for `long double` and `__float128`.
85 [graph elliptic_integral_k__double]
87 [graph elliptic_integral_k__80_bit_long_double]
89 [graph elliptic_integral_k____float128]
93 The tests use a mixture of spot test values calculated using the online
94 calculator at [@http://functions.wolfram.com/ functions.wolfram.com],
95 and random test data generated using
96 NTL::RR at 1000-bit precision and this implementation.
98 [heading Implementation]
100 These functions are implemented in terms of Carlson's integrals using the relations:
108 [endsect] [/section:ellint_1 Elliptic Integrals of the First Kind - Legendre Form]
110 [section:ellint_2 Elliptic Integrals of the Second Kind - Legendre Form]
115 #include <boost/math/special_functions/ellint_2.hpp>
118 namespace boost { namespace math {
120 template <class T1, class T2>
121 ``__sf_result`` ellint_2(T1 k, T2 phi);
123 template <class T1, class T2, class ``__Policy``>
124 ``__sf_result`` ellint_2(T1 k, T2 phi, const ``__Policy``&);
127 ``__sf_result`` ellint_2(T k);
129 template <class T, class ``__Policy``>
130 ``__sf_result`` ellint_2(T k, const ``__Policy``&);
134 [heading Description]
136 These two functions evaluate the incomplete elliptic integral of the second kind
137 ['E([phi], k)] and its complete counterpart ['E(k) = E([pi]/2, k)].
141 The return type of these functions is computed using the __arg_promotion_rules
142 when T1 and T2 are different types: when they are the same type then the result
143 is the same type as the arguments.
145 template <class T1, class T2>
146 ``__sf_result`` ellint_2(T1 k, T2 phi);
148 template <class T1, class T2, class ``__Policy``>
149 ``__sf_result`` ellint_2(T1 k, T2 phi, const ``__Policy``&);
151 Returns the incomplete elliptic integral of the second kind ['E([phi], k)]:
155 Requires k[super 2]sin[super 2](phi) < 1, otherwise returns the result of __domain_error.
160 ``__sf_result`` ellint_2(T k);
163 ``__sf_result`` ellint_2(T k, const ``__Policy``&);
165 Returns the complete elliptic integral of the second kind ['E(k)]:
169 Requires |k| < 1, otherwise returns the result of __domain_error.
175 These functions are computed using only basic arithmetic operations, so
176 there isn't much variation in accuracy over differing platforms.
177 Note that only results for the widest floating point type on the
178 system are given as narrower types have __zero_error. All values
179 are relative errors in units of epsilon.
183 The following error plot are based on an exhaustive search of the functions domain, MSVC-15.5 at `double` precision,
184 and GCC-7.1/Ubuntu for `long double` and `__float128`.
186 [graph elliptic_integral_e__double]
188 [graph elliptic_integral_e__80_bit_long_double]
190 [graph elliptic_integral_e____float128]
194 The tests use a mixture of spot test values calculated using the online
195 calculator at [@http://functions.wolfram.com
196 functions.wolfram.com], and random test data generated using
197 NTL::RR at 1000-bit precision and this implementation.
199 [heading Implementation]
201 These functions are implemented in terms of Carlson's integrals
210 [endsect] [/section:ellint_2 Elliptic Integrals of the Second Kind - Legendre Form]
212 [section:ellint_3 Elliptic Integrals of the Third Kind - Legendre Form]
217 #include <boost/math/special_functions/ellint_3.hpp>
220 namespace boost { namespace math {
222 template <class T1, class T2, class T3>
223 ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi);
225 template <class T1, class T2, class T3, class ``__Policy``>
226 ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi, const ``__Policy``&);
228 template <class T1, class T2>
229 ``__sf_result`` ellint_3(T1 k, T2 n);
231 template <class T1, class T2, class ``__Policy``>
232 ``__sf_result`` ellint_3(T1 k, T2 n, const ``__Policy``&);
236 [heading Description]
238 These two functions evaluate the incomplete elliptic integral of the third kind
239 ['[Pi](n, [phi], k)] and its complete counterpart ['[Pi](n, k) = E(n, [pi]/2, k)].
243 The return type of these functions is computed using the __arg_promotion_rules
244 when the arguments are of different types: when they are the same type then the result
245 is the same type as the arguments.
247 template <class T1, class T2, class T3>
248 ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi);
250 template <class T1, class T2, class T3, class ``__Policy``>
251 ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi, const ``__Policy``&);
253 Returns the incomplete elliptic integral of the third kind ['[Pi](n, [phi], k)]:
257 Requires ['k[super 2]sin[super 2](phi) < 1] and ['n < 1/sin[super 2]([phi])], otherwise
258 returns the result of __domain_error (outside this range the result
263 template <class T1, class T2>
264 ``__sf_result`` ellint_3(T1 k, T2 n);
266 template <class T1, class T2, class ``__Policy``>
267 ``__sf_result`` ellint_3(T1 k, T2 n, const ``__Policy``&);
269 Returns the complete elliptic integral of the first kind ['[Pi](n, k)]:
273 Requires ['|k| < 1] and ['n < 1], otherwise returns the
274 result of __domain_error (outside this range the result would be complex).
280 These functions are computed using only basic arithmetic operations, so
281 there isn't much variation in accuracy over differing platforms.
282 Note that only results for the widest floating point type on the
283 system are given as narrower types have __zero_error. All values
284 are relative errors in units of epsilon.
290 The tests use a mixture of spot test values calculated using the online
291 calculator at [@http://functions.wolfram.com
292 functions.wolfram.com], and random test data generated using
293 NTL::RR at 1000-bit precision and this implementation.
295 [heading Implementation]
297 The implementation for [Pi](n, [phi], k) first siphons off the special cases:
299 [expression ['[Pi](0, [phi], k) = F([phi], k)]]
301 [expression ['[Pi](n, [pi]/2, k) = [Pi](n, k)]]
307 Then if n < 0 the relations (A&S 17.7.15/16):
311 are used to shift /n/ to the range \[0, 1\].
315 [expression ['[Pi](n, -[phi], k) = -[Pi](n, [phi], k)]]
317 [expression ['[Pi](n, [phi]+m[pi], k) = [Pi](n, [phi], k) + 2m[Pi](n, k) ; n <= 1]]
319 [expression ['[Pi](n, [phi]+m[pi], k) = [Pi](n, [phi], k) ; n > 1] [indent] [indent]
320 [footnote I haven't been able to find a literature reference for this
321 relation, but it appears to be the convention used by Mathematica.
322 Intuitively the first ['2 * m * [Pi](n, k)] terms cancel out as the
323 derivative alternates between +[infin] and -[infin].]]
325 are used to move [phi] to the range \[0, [pi]\/2\].
327 The functions are then implemented in terms of Carlson's integrals using the relations:
335 [endsect] [/section:ellint_3 Elliptic Integrals of the Third Kind - Legendre Form]
337 [section:ellint_d Elliptic Integral D - Legendre Form]
342 #include <boost/math/special_functions/ellint_d.hpp>
345 namespace boost { namespace math {
347 template <class T1, class T2>
348 ``__sf_result`` ellint_d(T1 k, T2 phi);
350 template <class T1, class T2, class ``__Policy``>
351 ``__sf_result`` ellint_d(T1 k, T2 phi, const ``__Policy``&);
354 ``__sf_result`` ellint_d(T1 k);
356 template <class T1, class ``__Policy``>
357 ``__sf_result`` ellint_d(T1 k, const ``__Policy``&);
361 [heading Description]
363 These two functions evaluate the incomplete elliptic integral
364 ['D([phi], k)] and its complete counterpart ['D(k) = D([pi]/2, k)].
366 The return type of these functions is computed using the __arg_promotion_rules
367 when the arguments are of different types: when they are the same type then the result
368 is the same type as the arguments.
370 template <class T1, class T2>
371 ``__sf_result`` ellint_d(T1 k, T2 phi);
373 template <class T1, class T2, class ``__Policy``>
374 ``__sf_result`` ellint_3(T1 k, T2 phi, const ``__Policy``&);
376 Returns the incomplete elliptic integral:
380 Requires ['k[super 2]sin[super 2](phi) < 1], otherwise
381 returns the result of __domain_error (outside this range the result
387 ``__sf_result`` ellint_d(T1 k);
389 template <class T1, class ``__Policy``>
390 ``__sf_result`` ellint_d(T1 k, const ``__Policy``&);
392 Returns the complete elliptic integral ['D(k) = D([pi]/2, k)]
394 Requires ['-1 <= k <= 1] otherwise returns the
395 result of __domain_error (outside this range the result would be complex).
401 These functions are trivially computed in terms of other elliptic integrals
402 and generally have very low error rates (a few epsilon) unless parameter [phi]
403 is very large, in which case the usual trigonometric function argument-reduction issues apply.
405 [table_ellint_d_complete_]
409 The following error plot are based on an exhaustive search of the functions domain, MSVC-15.5 at `double` precision,
410 and GCC-7.1/Ubuntu for `long double` and `__float128`.
412 [graph elliptic_integral_d__double]
414 [graph elliptic_integral_d__80_bit_long_double]
416 [graph elliptic_integral_d____float128]
421 The tests use a mixture of spot test values calculated using
422 values calculated at __WolframAlpha, and random test data generated using
423 MPFR at 1000-bit precision and a deliberately naive implementation in terms of
424 the Legendre integrals.
426 [heading Implementation]
428 The implementation for D([phi], k) first performs argument reduction using the relations:
430 [expression ['D(-[phi], k) = -D([phi], k)]]
434 [expression ['D(n[pi]+[phi], k) = 2nD(k) + D([phi], k)]]
436 to move [phi] to the range \[0, [pi]\/2\].
438 The functions are then implemented in terms of Carlson's integral R[sub D]
443 [endsect] [/section:ellint_d Elliptic Integral D - Legendre Form]
445 [section:jacobi_zeta Jacobi Zeta Function]
450 #include <boost/math/special_functions/jacobi_zeta.hpp>
453 namespace boost { namespace math {
455 template <class T1, class T2>
456 ``__sf_result`` jacobi_zeta(T1 k, T2 phi);
458 template <class T1, class T2, class ``__Policy``>
459 ``__sf_result`` jacobi_zeta(T1 k, T2 phi, const ``__Policy``&);
463 [heading Description]
465 This function evaluates the Jacobi Zeta Function ['Z([phi], k)]
467 [equation jacobi_zeta]
469 Please note the use of [phi], and /k/ as the parameters, the function is often defined as ['Z([phi], m)]
470 with ['m = k[super 2]], see for example [@http://mathworld.wolfram.com/JacobiZetaFunction.html Weisstein, Eric W. "Jacobi Zeta Function." From MathWorld--A Wolfram Web Resource.]
471 Or else as [@https://dlmf.nist.gov/22.16#E32 ['Z(x, k)]] with ['[phi] = am(x, k)],
472 where ['am] is the [@https://dlmf.nist.gov/22.16#E1 Jacobi amplitude function]
473 which is equivalent to ['asin(jacobi_elliptic(k, x))].
475 The return type of this function is computed using the __arg_promotion_rules
476 when the arguments are of different types: when they are the same type then the result
477 is the same type as the arguments.
479 Requires ['-1 <= k <= 1], otherwise
480 returns the result of __domain_error (outside this range the result would be complex).
484 Note that there is no complete analogue of this function (where [phi] = [pi] / 2)
485 as this takes the value 0 for all ['k].
489 These functions are trivially computed in terms of other elliptic integrals
490 and generally have very low error rates (a few epsilon) unless parameter [phi]
491 is very large, in which case the usual trigonometric function argument-reduction issues apply.
497 The tests use a mixture of spot test values calculated using
498 values calculated at __WolframAlpha, and random test data generated using
499 MPFR at 1000-bit precision and a deliberately naive implementation in terms of
500 the Legendre integrals.
502 [heading Implementation]
504 The implementation for Z([phi], k) first makes the argument [phi] positive using:
506 [expression ['Z(-[phi], k) = -Z([phi], k)]]
508 The function is then implemented in terms of Carlson's integral R[sub J]
511 [equation jacobi_zeta]
513 There is one special case where the above relation fails: when ['k = 1], in that case
514 the function simplifies to
516 [expression ['Z([phi], 1) = sign(cos([phi])) sin([phi])]]
518 [h5:jacobi_zeta_example Example]
520 A simple example comparing use of __WolframAlpha with Boost.Math (including much higher precision using Boost.Multiprecision)
521 is [@../../example/jacobi_zeta_example.cpp jacobi_zeta_example.cpp].
523 [endsect] [/section:jacobi_zeta Jacobi Zeta Function]
525 [section:heuman_lambda Heuman Lambda Function]
530 #include <boost/math/special_functions/heuman_lambda.hpp>
533 namespace boost { namespace math {
535 template <class T1, class T2>
536 ``__sf_result`` heuman_lambda(T1 k, T2 phi);
538 template <class T1, class T2, class ``__Policy``>
539 ``__sf_result`` heuman_lambda(T1 k, T2 phi, const ``__Policy``&);
543 [heading Description]
545 This function evaluates the Heuman Lambda Function ['[Lambda][sub 0]([phi], k)]
547 [equation heuman_lambda]
549 The return type of this function is computed using the __arg_promotion_rules
550 when the arguments are of different types: when they are the same type then the result
551 is the same type as the arguments.
553 Requires ['-1 <= k <= 1], otherwise
554 returns the result of __domain_error (outside this range the result would be complex).
558 Note that there is no complete analogue of this function (where [phi] = [pi] / 2)
559 as this takes the value 1 for all ['k].
563 These functions are trivially computed in terms of other elliptic integrals
564 and generally have very low error rates (a few epsilon) unless parameter [phi]
565 is very large, in which case the usual trigonometric function argument-reduction issues apply.
567 [table_heuman_lambda]
571 The tests use a mixture of spot test values calculated using
572 values calculated at __WolframAlpha, and random test data generated using
573 MPFR at 1000-bit precision and a deliberately naive implementation in terms of
574 the Legendre integrals.
576 [heading Implementation]
578 The function is then implemented in terms of Carlson's integrals R[sub J] and R[sub F]
581 [equation heuman_lambda]
583 This relation fails for ['|[phi]| >= [pi]/2] in which case the definition in terms of the
586 [endsect] [/section:heuman_lambda Heuman Lambda Function]