diff options
| author | Christoph Berg <myon@debian.org> | 2018-12-19 22:58:32 +0100 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2018-12-19 22:58:32 +0100 |
| commit | e0737c56c1e384e05064a0c6e1ac46979371041b (patch) | |
| tree | a0123d694a2d36c43dabdf0a3907392fce11d457 /boost/libs/math/doc/sf | |
| parent | b4aebf2d137b892f53503b13785ecae900062ff7 (diff) | |
New upstream version 2.0.0+repackupstream/2.0.0+repack
Diffstat (limited to 'boost/libs/math/doc/sf')
44 files changed, 8695 insertions, 0 deletions
diff --git a/boost/libs/math/doc/sf/airy.qbk b/boost/libs/math/doc/sf/airy.qbk new file mode 100644 index 00000000..8078142e --- /dev/null +++ b/boost/libs/math/doc/sf/airy.qbk @@ -0,0 +1,384 @@ +[/ +Copyright (c) 2012 John Maddock +Use, modification and distribution are subject to the +Boost Software License, Version 1.0. (See accompanying file +LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +] + +[section:airy Airy Functions] + +[section:ai Airy Ai Function] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/airy.hpp> +`` + + namespace boost { namespace math { + + template <class T> + ``__sf_result`` airy_ai(T x); + + template <class T, class Policy> + ``__sf_result`` airy_ai(T x, const Policy&); + + }} // namespaces + +[heading Description] + +The function __airy_ai calculates the Airy function Ai which is the first solution +to the differential equation: + +[equation airy] + +See Weisstein, Eric W. "Airy Functions." From MathWorld--A Wolfram Web Resource. +[@http://mathworld.wolfram.com/AiryFunctions.html]; + + +[optional_policy] + +The following graph illustrates how this function changes as /x/ changes: for negative /x/ +the function is cyclic, while for positive /x/ the value tends to zero: + +[graph airy_ai] + +[heading Accuracy] + +This function is implemented entirely in terms of the Bessel functions +__cyl_bessel_j and __cyl_bessel_k - refer to those functions for detailed accuracy information. + +In general though, the relative error is low (less than 100 [epsilon]) for /x > 0/ while +only the absolute error is low for /x < 0/. + +[heading Testing] + +Since this function is implemented in terms of other special functions, there are only a few +basic sanity checks, using test values from [@http://functions.wolfram.com/ Wolfram Airy Functions]. + +[heading Implementation] + +This function is implemented in terms of the Bessel functions using the relations: + +[equation airy_ai] + +[endsect] + +[section:bi Airy Bi Function] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/airy.hpp> +`` + + namespace boost { namespace math { + + template <class T> + ``__sf_result`` airy_bi(T x); + + template <class T, class Policy> + ``__sf_result`` airy_bi(T x, const Policy&); + + }} // namespaces + +[heading Description] + +The function __airy_bi calculates the Airy function Bi which is the second solution to the differential equation: + +[equation airy] + +[optional_policy] + +The following graph illustrates how this function changes as /x/ changes: for negative /x/ +the function is cyclic, while for positive /x/ the value tends to infinity: + +[graph airy_bi] + +[heading Accuracy] + +This function is implemented entirely in terms of the Bessel functions +__cyl_bessel_i and __cyl_bessel_j - refer to those functions for detailed accuracy information. + +In general though, the relative error is low (less than 100 [epsilon]) for /x > 0/ while +only the absolute error is low for /x < 0/. + +[heading Testing] + +Since this function is implemented in terms of other special functions, there are only a few +basic sanity checks, using test values from [@http://functions.wolfram.com functions.wolfram.com]. + +[heading Implementation] + +This function is implemented in terms of the Bessel functions using the relations: + +[equation airy_bi] + +[endsect] + +[section:aip Airy Ai' Function] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/airy.hpp> +`` + + namespace boost { namespace math { + + template <class T> + ``__sf_result`` airy_ai_prime(T x); + + template <class T, class Policy> + ``__sf_result`` airy_ai_prime(T x, const Policy&); + + }} // namespaces + +[heading Description] + +The function __airy_ai_prime calculates the Airy function Ai' which is the derivative of the first solution to the differential equation: + +[equation airy] + +[optional_policy] + +The following graph illustrates how this function changes as /x/ changes: for negative /x/ +the function is cyclic, while for positive /x/ the value tends to zero: + +[graph airy_aip] + +[heading Accuracy] + +This function is implemented entirely in terms of the Bessel functions +__cyl_bessel_j and __cyl_bessel_k - refer to those functions for detailed accuracy information. + +In general though, the relative error is low (less than 100 [epsilon]) for /x > 0/ while +only the absolute error is low for /x < 0/. + +[heading Testing] + +Since this function is implemented in terms of other special functions, there are only a few +basic sanity checks, using test values from [@http://functions.wolfram.com functions.wolfram.com]. + +[heading Implementation] + +This function is implemented in terms of the Bessel functions using the relations: + +[equation airy_aip] + +[endsect] + +[section:bip Airy Bi' Function] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/airy.hpp> +`` + + namespace boost { namespace math { + + template <class T> + ``__sf_result`` airy_bi_prime(T x); + + template <class T, class Policy> + ``__sf_result`` airy_bi_prime(T x, const Policy&); + + }} // namespaces + +[heading Description] + +The function __airy_bi_prime calculates the Airy function Bi' which is the derivative of the second solution to the differential equation: + +[equation airy] + +[optional_policy] + +The following graph illustrates how this function changes as /x/ changes: for negative /x/ +the function is cyclic, while for positive /x/ the value tends to infinity: + +[graph airy_bi] + +[heading Accuracy] + +This function is implemented entirely in terms of the Bessel functions +__cyl_bessel_i and __cyl_bessel_j - refer to those functions for detailed accuracy information. + +In general though, the relative error is low (less than 100 [epsilon]) for /x > 0/ while +only the absolute error is low for /x < 0/. + +[heading Testing] + +Since this function is implemented in terms of other special functions, there are only a few +basic sanity checks, using test values from [@http://functions.wolfram.com functions.wolfram.com]. + +[heading Implementation] + +This function is implemented in terms of the Bessel functions using the relations: + +[equation airy_bip] + +[endsect] + +[section:airy_root Finding Zeros of Airy Functions] + +[h4 Synopsis] + +`#include <boost/math/special_functions/airy.hpp>` + +Functions for obtaining both a single zero or root of the Airy functions, +and placing multiple zeros into a container like `std::vector` +by providing an output iterator. + +The signature of the single value functions are: + + template <class T> + T airy_ai_zero( + int m); // 1-based index of zero. + + template <class T> + T airy_bi_zero( + int m); // 1-based index of zero. + +and for multiple zeros: + + template <class T, class OutputIterator> + OutputIterator airy_ai_zero( + int start_index, // 1-based index of first zero. + unsigned number_of_zeros, // How many zeros to generate. + OutputIterator out_it); // Destination for zeros. + + template <class T, class OutputIterator> + OutputIterator airy_bi_zero( + int start_index, // 1-based index of zero. + unsigned number_of_zeros, // How many zeros to generate + OutputIterator out_it); // Destination for zeros. + +There are also versions which allow control of the __policy_section for error handling and precision. + + template <class T> + T airy_ai_zero( + int m, // 1-based index of zero. + const Policy&); // Policy to use. + + template <class T> + T airy_bi_zero( + int m, // 1-based index of zero. + const Policy&); // Policy to use. + + + template <class T, class OutputIterator> + OutputIterator airy_ai_zero( + int start_index, // 1-based index of first zero. + unsigned number_of_zeros, // How many zeros to generate. + OutputIterator out_it, // Destination for zeros. + const Policy& pol); // Policy to use. + + template <class T, class OutputIterator> + OutputIterator airy_bi_zero( + int start_index, // 1-based index of zero. + unsigned number_of_zeros, // How many zeros to generate. + OutputIterator out_it, // Destination for zeros. + const Policy& pol); // Policy to use. + +[h4 Description] + +The Airy Ai and Bi functions have an infinite +number of zeros on the negative real axis. The real zeros on the negative real +axis can be found by solving for the roots of + +[emquad] ['Ai(x[sub m]) = 0] + +[emquad] ['Bi(y[sub m]) = 0] + +Here, ['x[sub m]] represents the ['m[super th]] +root of the Airy Ai function, +and ['y[sub m]] represents the ['m[super th]] +root of the Airy Bi function. + +The zeros or roots (values of `x` where the function crosses the horizontal `y = 0` axis) +of the Airy Ai and Bi functions are computed by two functions, +`airy_ai_zero` and `airy_bi_zero`. + +In each case the index or rank of the zero +returned is 1-based, which is to say: + + airy_ai_zero(1); + +returns the first zero of Ai. + +Passing an `start_index <= 0` results in a __domain_error being raised. + +The first few zeros returned by these functions have approximate values as follows: + +[table +[[m][Ai][Bi]] +[[1][-2.33811...][-1.17371...]] +[[2][-4.08795...][-3.27109...]] +[[3][-5.52056...][-4.83074...]] +[[4][-6.78671...][-6.16985...]] +[[5][-7.94413...][-7.37676...]] +[[6][-9.02265...][-8.49195...]] +] + +[graph airy_zeros] + + +[h4 Examples of finding Airy Zeros] + +[import ../../example/airy_zeros_example.cpp] + +[airy_zeros_example_1] +[airy_zeros_example_2] + +Produces the program output: +[pre +boost::math::airy_ai_zero<double>(1) = -2.33811 +boost::math::airy_ai_zero<double>(2) = -4.08795 +boost::math::airy_bi_zero<double>(3) = -4.83074 +airy_ai_zeros: +-2.33811 +-4.08795 +-5.52056 +-6.78671 +-7.94413 + +boost::math::airy_bi_zero<float_type>(1) = -2.3381074104597670384891972524467354406385401456711 +boost::math::airy_bi_zero<float_type>(2) = -4.0879494441309706166369887014573910602247646991085 +boost::math::airy_bi_zero<float_type>(7) = -9.5381943793462388866329885451560196208390720763825 +airy_ai_zeros: +-2.3381074104597670384891972524467354406385401456711 +-4.0879494441309706166369887014573910602247646991085 +-5.5205598280955510591298555129312935737972142806175 +] + +The full code (and output) for this example is at +[@../../example/airy_zeros_example.cpp airy_zeros_example.cpp], + +[h3 Implementation] + +Given the following function (A&S 10.4.105): + +[equation airy_zero_1] + +Then an initial estimate for the n[super th] zero a[sub n] of Ai is given by (A&S 10.4.94): + +[equation airy_zero_2] + +and an initial estimate for the n[super th] zero b[sub n] of Bi is given by (A&S 10.4.98): + +[equation airy_zero_3] + +Thereafter the roots are refined using Newton iteration. + + +[h3 Testing] + +The precision of evaluation of zeros was tested at 50 decimal digits using `cpp_dec_float_50` +and found identical with spot values computed by __WolframAlpha. + +[endsect] [/section:bessel Finding Zeros of Bessel Functions of the First and Second Kinds] + + +[endsect] + diff --git a/boost/libs/math/doc/sf/bernoulli_numbers.qbk b/boost/libs/math/doc/sf/bernoulli_numbers.qbk new file mode 100644 index 00000000..d97cad6e --- /dev/null +++ b/boost/libs/math/doc/sf/bernoulli_numbers.qbk @@ -0,0 +1,223 @@ +[section:bernoulli_numbers Bernoulli Numbers] + +[@https://en.wikipedia.org/wiki/Bernoulli_number Bernoulli numbers] +are a sequence of rational numbers useful for the Taylor series expansion, +Euler-Maclaurin formula, and the Riemann zeta function. + +Bernoulli numbers are used in evaluation of some Boost.Math functions, +including the __tgamma, __lgamma and polygamma functions. + +[h4 Single Bernoulli number] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/bernoulli.hpp> +`` + + namespace boost { namespace math { + + template <class T> + T bernoulli_b2n(const int n); // Single Bernoulli number (default policy). + + template <class T, class Policy> + T bernoulli_b2n(const int n, const Policy &pol); // User policy for errors etc. + + }} // namespaces + +[h4 Description] + +Both return the (2 * n)[super th] Bernoulli number B[sub 2n]. + +Note that since all odd numbered Bernoulli numbers are zero (apart from B[sub 1] which is [plusminus][frac12]) +the interface will only return the even numbered Bernoulli numbers. + +This function uses fast table lookup for low-indexed Bernoulli numbers, while larger values are calculated +as needed and then cached. The caching mechanism requires a certain amount of thread safety code, so +`unchecked_bernoulli_b2n` may provide a better interface for performance critical code. + +The final __Policy argument is optional and can be used to control the behaviour of the function: +how it handles errors, what level of precision to use, etc. + +Refer to __policy_section for more details. + +[h4 Examples] + +[import ../../example/bernoulli_example.cpp] +[bernoulli_example_1] + +[bernoulli_output_1] + +[h4 Single (unchecked) Bernoulli number] + +[h4 Synopsis] +`` +#include <boost/math/special_functions/bernoulli.hpp> + +`` + + template <> + struct max_bernoulli_b2n<T>; + + template<class T> + inline T unchecked_bernoulli_b2n(unsigned n); + +`unchecked_bernoulli_b2n` provides access to Bernoulli numbers [*without any checks for overflow or invalid parameters]. +It is implemented as a direct (and very fast) table lookup, and while not recommended for general use it can be useful +inside inner loops where the ultimate performance is required, and error checking is moved outside the loop. + +The largest value you can pass to `unchecked_bernoulli_b2n<>` is `max_bernoulli_b2n<>::value`: passing values greater than +that will result in a buffer overrun error, so it's clearly important to place the error handling in your own code +when using this direct interface. + +The value of `boost::math::max_bernoulli_b2n<T>::value` varies by the type T, for types `float`/`double`/`long double` +it's the largest value which doesn't overflow the target type: for example, `boost::math::max_bernoulli_b2n<double>::value` is 129. +However, for multiprecision types, it's the largest value for which the result can be represented as the ratio of two 64-bit +integers, for example `boost::math::max_bernoulli_b2n<boost::multiprecision::cpp_dec_float_50>::value` is just 17. Of course +larger indexes can be passed to `bernoulli_b2n<T>(n)`, but then you lose fast table lookup (i.e. values may need to be calculated). + +[bernoulli_example_4] +[bernoulli_output_4] + +[h4 Multiple Bernoulli Numbers] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/bernoulli.hpp> +`` + + namespace boost { namespace math { + + // Multiple Bernoulli numbers (default policy). + template <class T, class OutputIterator> + OutputIterator bernoulli_b2n( + int start_index, + unsigned number_of_bernoullis_b2n, + OutputIterator out_it); + + // Multiple Bernoulli numbers (user policy). + template <class T, class OutputIterator, class Policy> + OutputIterator bernoulli_b2n( + int start_index, + unsigned number_of_bernoullis_b2n, + OutputIterator out_it, + const Policy& pol); + }} // namespaces + +[h4 Description] + +Two versions of the Bernoulli number function are provided to compute multiple Bernoulli numbers +with one call (one with default policy and the other allowing a user-defined policy). + +These return a series of Bernoulli numbers: + +[:B[sub 2*start_index],B[sub 2*(start_index+1)],...,B[sub 2*(start_index+number_of_bernoullis_b2n-1)]] + +[h4 Examples] +[bernoulli_example_2] +[bernoulli_output_2] +[bernoulli_example_3] +[bernoulli_output_3] + +The source of this example is at [@../../example/bernoulli_example.cpp bernoulli_example.cpp] + +[h4 Accuracy] + +All the functions usually return values within one ULP (unit in the last place) for the floating-point type. + +[h4 Implementation] + +The implementation details are in [@../../include/boost/math/special_functions/detail/bernoulli_details.hpp bernoulli_details.hpp] +and [@../../include/boost/math/special_functions/detail/unchecked_bernoulli.hpp unchecked_bernoulli.hpp]. + +For `i <= max_bernoulli_index<T>::value` this is implemented by simple table lookup from a statically initialized table; +for larger values of `i`, this is implemented by the Tangent Numbers algorithm as described in the paper: +Fast Computation of Bernoulli, Tangent and Secant Numbers, Richard P. Brent and David Harvey, +[@http://arxiv.org/pdf/1108.0286v3.pdf] (2011). + +[@http://mathworld.wolfram.com/TangentNumber.html Tangent (or Zag) numbers] +(an even alternating permutation number) are defined +and their generating function is also given therein. + +The relation of Tangent numbers with Bernoulli numbers ['B[sub i]] +is given by Brent and Harvey's equation 14: + +__spaces[equation tangent_numbers] + +Their relation with Bernoulli numbers ['B[sub i]] are defined by + +if i > 0 and i is even then +__spaces[equation bernoulli_numbers] [br] +elseif i == 0 then ['B[sub i]] = 1 [br] +elseif i == 1 then ['B[sub i]] = -1/2 [br] +elseif i < 0 or i is odd then ['B[sub i]] = 0 + +Note that computed values are stored in a fixed-size table, access is thread safe via atomic operations (i.e. lock +free programming), this imparts a much lower overhead on access to cached values than might otherwise be expected - +typically for multiprecision types the cost of thread synchronisation is negligible, while for built in types +this code is not normally executed anyway. For very large arguments which cannot be reasonably computed or +stored in our cache, an asymptotic expansion [@http://www.luschny.de/math/primes/bernincl.html due to Luschny] is used: + +[equation bernoulli_numbers2] + +[endsect] [/section:bernoulli_numbers Bernoulli Numbers] + + +[section:tangent_numbers Tangent Numbers] + +[@http://en.wikipedia.org/wiki/Tangent_numbers Tangent numbers], +also called a zag function. See also +[@http://mathworld.wolfram.com/TangentNumber.html Tangent number]. + +From the number, An, of alternating permutations of the set {1, ..., n}, +the numbers A2n+1 with odd indices are called tangent numbers or zag numbers. +The first few values are 1, 2, 16, 272, 7936, 353792, 22368256, 1903757312 ... +(sequence [@http://oeis.org/A000182 A000182 in OEIS]). +They are called tangent numbers because they appear as +numerators in the Maclaurin series of tan x. + +Tangent numbers are used in the computation of Bernoulli numbers, +but are also made available here. + +[h4 Synopsis] +`` +#include <boost/math/special_functions/detail/bernoulli.hpp> +`` + + template <class T> + T tangent_t2n(const int i); // Single tangent number (default policy). + + template <class T, class Policy> + T tangent_t2n(const int i, const Policy &pol); // Single tangent number (user policy). + + // Multiple tangent numbers (default policy). + template <class T, class OutputIterator> + OutputIterator tangent_t2n(const int start_index, + const unsigned number_of_tangent_t2n, + OutputIterator out_it); + + // Multiple tangent numbers (user policy). + template <class T, class OutputIterator, class Policy> + OutputIterator tangent_t2n(const int start_index, + const unsigned number_of_tangent_t2n, + OutputIterator out_it, + const Policy& pol); + +[h4 Examples] + +[tangent_example_1] + +The output is: +[tangent_output_1] + +The source of this example is at [../../example/bernoulli_example.cpp bernoulli_example.cpp] + +[endsect] [/section:tangent_numbers Tangent Numbers] + +[/ + Copyright 2013, 2014 Nikhar Agrawal, Christopher Kormanyos, John Maddock, Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/bessel_ik.qbk b/boost/libs/math/doc/sf/bessel_ik.qbk new file mode 100644 index 00000000..9c081bae --- /dev/null +++ b/boost/libs/math/doc/sf/bessel_ik.qbk @@ -0,0 +1,194 @@ + +[section:mbessel Modified Bessel Functions of the First and Second Kinds] + +[h4 Synopsis] + +`#include <boost/math/special_functions/bessel.hpp>` + + template <class T1, class T2> + ``__sf_result`` cyl_bessel_i(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` cyl_bessel_i(T1 v, T2 x, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` cyl_bessel_k(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` cyl_bessel_k(T1 v, T2 x, const ``__Policy``&); + + +[h4 Description] + +The functions __cyl_bessel_i and __cyl_bessel_k return the result of the +modified Bessel functions of the first and second kind respectively: + +cyl_bessel_i(v, x) = I[sub v](x) + +cyl_bessel_k(v, x) = K[sub v](x) + +where: + +[equation mbessel2] + +[equation mbessel3] + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types. The functions are also optimised for the +relatively common case that T1 is an integer. + +[optional_policy] + +The functions return the result of __domain_error whenever the result is +undefined or complex. For __cyl_bessel_j this occurs when `x < 0` and v is not +an integer, or when `x == 0` and `v != 0`. For __cyl_neumann this occurs +when `x <= 0`. + +The following graph illustrates the exponential behaviour of I[sub v]. + +[graph cyl_bessel_i] + +The following graph illustrates the exponential decay of K[sub v]. + +[graph cyl_bessel_k] + +[h4 Testing] + +There are two sets of test values: spot values calculated using +[@http://functions.wolfram.com functions.wolfram.com], +and a much larger set of tests computed using +a simplified version of this implementation +(with all the special case handling removed). + +[h4 Accuracy] + +The following tables show how the accuracy of these functions +varies on various platforms, along with comparison to other libraries. +Note that only results for the widest floating-point type on the +system are given, as narrower types have __zero_error. All values +are relative errors in units of epsilon. Note that our test suite +includes some fairly extreme inputs which results in most of the worst +problem cases in other libraries: + +[table_cyl_bessel_i_integer_orders_] + +[table_cyl_bessel_i] + +[table_cyl_bessel_k_integer_orders_] + +[table_cyl_bessel_k] + +[h4 Implementation] + +The following are handled as special cases first: + +When computing I[sub v][space] for ['x < 0], then [nu][space] must be an integer +or a domain error occurs. If [nu][space] is an integer, then the function is +odd if [nu][space] is odd and even if [nu][space] is even, and we can reflect to +['x > 0]. + +For I[sub v][space] with v equal to 0, 1 or 0.5 are handled as special cases. + +The 0 and 1 cases use minimax rational approximations on +finite and infinite intervals. The coefficients are from: + +* J.M. Blair and C.A. Edwards, ['Stable rational minimax approximations + to the modified Bessel functions I_0(x) and I_1(x)], Atomic Energy of Canada + Limited Report 4928, Chalk River, 1974. +* S. Moshier, ['Methods and Programs for Mathematical Functions], + Ellis Horwood Ltd, Chichester, 1989. + +While the 0.5 case is a simple trigonometric function: + +I[sub 0.5](x) = sqrt(2 / [pi]x) * sinh(x) + +For K[sub v][space] with /v/ an integer, the result is calculated using the +recurrence relation: + +[equation mbessel5] + +starting from K[sub 0][space] and K[sub 1][space] which are calculated +using rational the approximations above. These rational approximations are +accurate to around 19 digits, and are therefore only used when T has +no more than 64 binary digits of precision. + +When /x/ is small compared to /v/, I[sub v]x[space] is best computed directly from the series: + +[equation mbessel17] + +In the general case, we first normalize [nu][space] to \[[^0, [inf]]) +with the help of the reflection formulae: + +[equation mbessel9] + +[equation mbessel10] + +Let [mu][space] = [nu] - floor([nu] + 1/2), then [mu][space] is the fractional part of +[nu][space] such that |[mu]| <= 1/2 (we need this for convergence later). The idea is to +calculate K[sub [mu]](x) and K[sub [mu]+1](x), and use them to obtain +I[sub [nu]](x) and K[sub [nu]](x). + +The algorithm is proposed by Temme in +N.M. Temme, ['On the numerical evaluation of the modified bessel function + of the third kind], Journal of Computational Physics, vol 19, 324 (1975), +which needs two continued fractions as well as the Wronskian: + +[equation mbessel11] + +[equation mbessel12] + +[equation mbessel8] + +The continued fractions are computed using the modified Lentz's method +(W.J. Lentz, ['Generating Bessel functions in Mie scattering calculations + using continued fractions], Applied Optics, vol 15, 668 (1976)). +Their convergence rates depend on ['x], therefore we need +different strategies for large ['x] and small ['x]. + +['x > v], CF1 needs O(['x]) iterations to converge, CF2 converges rapidly. + +['x <= v], CF1 converges rapidly, CF2 fails to converge when ['x] [^->] 0. + +When ['x] is large (['x] > 2), both continued fractions converge (CF1 +may be slow for really large ['x]). K[sub [mu]][space] and K[sub [mu]+1][space] +can be calculated by + +[equation mbessel13] + +where + +[equation mbessel14] + +['S] is also a series that is summed along with CF2, see +I.J. Thompson and A.R. Barnett, ['Modified Bessel functions I_v and K_v + of real order and complex argument to selected accuracy], Computer Physics + Communications, vol 47, 245 (1987). + +When ['x] is small (['x] <= 2), CF2 convergence may fail (but CF1 +works very well). The solution here is Temme's series: + +[equation mbessel15] + +where + +[equation mbessel16] + +f[sub k][space] and h[sub k][space] +are also computed by recursions (involving gamma functions), but the +formulas are a little complicated, readers are referred to +N.M. Temme, ['On the numerical evaluation of the modified Bessel function + of the third kind], Journal of Computational Physics, vol 19, 324 (1975). +Note: Temme's series converge only for |[mu]| <= 1/2. + +K[sub [nu]](x) is then calculated from the forward +recurrence, as is K[sub [nu]+1](x). With these two values and +f[sub [nu]], the Wronskian yields I[sub [nu]](x) directly. + +[endsect] + +[/ + Copyright 2006 John Maddock, Paul A. Bristow and Xiaogang Zhang. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/bessel_introduction.qbk b/boost/libs/math/doc/sf/bessel_introduction.qbk new file mode 100644 index 00000000..4cdfe629 --- /dev/null +++ b/boost/libs/math/doc/sf/bessel_introduction.qbk @@ -0,0 +1,124 @@ + +[section:bessel_over Bessel Function Overview] + +[h4 Ordinary Bessel Functions] + +Bessel Functions are solutions to Bessel's ordinary differential +equation: + +[equation bessel1] + +where [nu][space] is the /order/ of the equation, and may be an arbitrary +real or complex number, although integer orders are the most common occurrence. + +This library supports either integer or real orders. + +Since this is a second order differential equation, there must be two +linearly independent solutions, the first of these is denoted J[sub v][space] +and known as a Bessel function of the first kind: + +[equation bessel2] + +This function is implemented in this library as __cyl_bessel_j. + +The second solution is denoted either Y[sub v][space] or N[sub v][space] +and is known as either a Bessel Function of the second kind, or as a +Neumann function: + +[equation bessel3] + +This function is implemented in this library as __cyl_neumann. + +The Bessel functions satisfy the recurrence relations: + +[equation bessel4] + +[equation bessel5] + +Have the derivatives: + +[equation bessel6] + +[equation bessel7] + +Have the Wronskian relation: + +[equation bessel8] + +and the reflection formulae: + +[equation bessel9] + +[equation bessel10] + + +[h4 Modified Bessel Functions] + +The Bessel functions are valid for complex argument /x/, and an important +special case is the situation where /x/ is purely imaginary: giving a real +valued result. In this case the functions are the two linearly +independent solutions to the modified Bessel equation: + +[equation mbessel1] + +The solutions are known as the modified Bessel functions of the first and +second kind (or occasionally as the hyperbolic Bessel functions of the first +and second kind). They are denoted I[sub v][space] and K[sub v][space] +respectively: + +[equation mbessel2] + +[equation mbessel3] + +These functions are implemented in this library as __cyl_bessel_i and +__cyl_bessel_k respectively. + +The modified Bessel functions satisfy the recurrence relations: + +[equation mbessel4] + +[equation mbessel5] + +Have the derivatives: + +[equation mbessel6] + +[equation mbessel7] + +Have the Wronskian relation: + +[equation mbessel8] + +and the reflection formulae: + +[equation mbessel9] + +[equation mbessel10] + +[h4 Spherical Bessel Functions] + +When solving the Helmholtz equation in spherical coordinates by +separation of variables, the radial equation has the form: + +[equation sbessel1] + +The two linearly independent solutions to this equation are called the +spherical Bessel functions j[sub n][space] and y[sub n][space], and are related to the +ordinary Bessel functions J[sub n][space] and Y[sub n][space] by: + +[equation sbessel2] + +The spherical Bessel function of the second kind y[sub n][space] +is also known as the spherical Neumann function n[sub n]. + +These functions are implemented in this library as __sph_bessel and +__sph_neumann. + +[endsect] + +[/ + Copyright 2006 John Maddock, Paul A. Bristow and Xiaogang Zhang. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/bessel_jy.qbk b/boost/libs/math/doc/sf/bessel_jy.qbk new file mode 100644 index 00000000..6fe1bb24 --- /dev/null +++ b/boost/libs/math/doc/sf/bessel_jy.qbk @@ -0,0 +1,548 @@ + +[section:bessel_first Bessel Functions of the First and Second Kinds] + +[h4 Synopsis] + +`#include <boost/math/special_functions/bessel.hpp>` + + template <class T1, class T2> + ``__sf_result`` cyl_bessel_j(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` cyl_bessel_j(T1 v, T2 x, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` cyl_neumann(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` cyl_neumann(T1 v, T2 x, const ``__Policy``&); + + +[h4 Description] + +The functions __cyl_bessel_j and __cyl_neumann return the result of the +Bessel functions of the first and second kinds respectively: + +cyl_bessel_j(v, x) = J[sub v](x) + +cyl_neumann(v, x) = Y[sub v](x) = N[sub v](x) + +where: + +[equation bessel2] + +[equation bessel3] + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types. The functions are also optimised for the +relatively common case that T1 is an integer. + +[optional_policy] + +The functions return the result of __domain_error whenever the result is +undefined or complex. For __cyl_bessel_j this occurs when `x < 0` and v is not +an integer, or when `x == 0` and `v != 0`. For __cyl_neumann this occurs +when `x <= 0`. + +The following graph illustrates the cyclic nature of J[sub v]: + +[graph cyl_bessel_j] + +The following graph shows the behaviour of Y[sub v]: this is also +cyclic for large /x/, but tends to -[infin][space] for small /x/: + +[graph cyl_neumann] + +[h4 Testing] + +There are two sets of test values: spot values calculated using +[@http://functions.wolfram.com functions.wolfram.com], +and a much larger set of tests computed using +a simplified version of this implementation +(with all the special case handling removed). + +[h4 Accuracy] + +The following tables show how the accuracy of these functions +varies on various platforms, along with comparisons to other +libraries. Note that the cyclic nature of these +functions means that they have an infinite number of irrational +roots: in general these functions have arbitrarily large /relative/ +errors when the arguments are sufficiently close to a root. Of +course the absolute error in such cases is always small. +Note that only results for the widest floating-point type on the +system are given as narrower types have __zero_error. All values +are relative errors in units of epsilon. Most of the gross errors +exhibited by other libraries occur for very large arguments - you will +need to drill down into the actual program output if you need more +information on this. + +[table_cyl_bessel_j_integer_orders_] + +[table_cyl_bessel_j] + +[table_cyl_neumann_integer_orders_] + +[table_cyl_neumann] + +Note that for large /x/ these functions are largely dependent on +the accuracy of the `std::sin` and `std::cos` functions. + +Comparison to GSL and __cephes is interesting: both __cephes and this library optimise +the integer order case - leading to identical results - simply using the general +case is for the most part slightly more accurate though, as noted by the +better accuracy of GSL in the integer argument cases. This implementation tends to +perform much better when the arguments become large, __cephes in particular produces +some remarkably inaccurate results with some of the test data (no significant figures +correct), and even GSL performs badly with some inputs to J[sub v]. Note that +by way of double-checking these results, the worst performing __cephes and GSL cases +were recomputed using [@http://functions.wolfram.com functions.wolfram.com], +and the result checked against our test data: no errors in the test data were found. + +[h4 Implementation] + +The implementation is mostly about filtering off various special cases: + +When /x/ is negative, then the order /v/ must be an integer or the +result is a domain error. If the order is an integer then the function +is odd for odd orders and even for even orders, so we reflect to /x > 0/. + +When the order /v/ is negative then the reflection formulae can be used to +move to /v > 0/: + +[equation bessel9] + +[equation bessel10] + +Note that if the order is an integer, then these formulae reduce to: + +J[sub -n] = (-1)[super n]J[sub n] + +Y[sub -n] = (-1)[super n]Y[sub n] + +However, in general, a negative order implies that we will need to compute +both J and Y. + +When /x/ is large compared to the order /v/ then the asymptotic expansions +for large /x/ in M. Abramowitz and I.A. Stegun, +['Handbook of Mathematical Functions] 9.2.19 are used +(these were found to be more reliable +than those in A&S 9.2.5). + +When the order /v/ is an integer the method first relates the result +to J[sub 0], J[sub 1], Y[sub 0][space] and Y[sub 1][space] using either +forwards or backwards recurrence (Miller's algorithm) depending upon which is stable. +The values for J[sub 0], J[sub 1], Y[sub 0][space] and Y[sub 1][space] are +calculated using the rational minimax approximations on +root-bracketing intervals for small ['|x|] and Hankel asymptotic +expansion for large ['|x|]. The coefficients are from: + +W.J. Cody, ['ALGORITHM 715: SPECFUN - A Portable FORTRAN Package of +Special Function Routines and Test Drivers], ACM Transactions on Mathematical +Software, vol 19, 22 (1993). + +and + +J.F. Hart et al, ['Computer Approximations], John Wiley & Sons, New York, 1968. + +These approximations are accurate to around 19 decimal digits: therefore +these methods are not used when type T has more than 64 binary digits. + +When /x/ is smaller than machine epsilon then the following approximations for +Y[sub 0](x), Y[sub 1](x), Y[sub 2](x) and Y[sub n](x) can be used +(see: [@http://functions.wolfram.com/03.03.06.0037.01 http://functions.wolfram.com/03.03.06.0037.01], +[@http://functions.wolfram.com/03.03.06.0038.01 http://functions.wolfram.com/03.03.06.0038.01], +[@http://functions.wolfram.com/03.03.06.0039.01 http://functions.wolfram.com/03.03.06.0039.01] +and [@http://functions.wolfram.com/03.03.06.0040.01 http://functions.wolfram.com/03.03.06.0040.01]): + +[equation bessel_y0_small_z] + +[equation bessel_y1_small_z] + +[equation bessel_y2_small_z] + +[equation bessel_yn_small_z] + +When /x/ is small compared to /v/ and /v/ is not an integer, then the following +series approximation can be used for Y[sub v](x), this is also an area where other +approximations are often too slow to converge to be used +(see [@http://functions.wolfram.com/03.03.06.0034.01 http://functions.wolfram.com/03.03.06.0034.01]): + +[equation bessel_yv_small_z] + +When /x/ is small compared to /v/, J[sub v]x[space] is best computed directly from the series: + +[equation bessel2] + +In the general case we compute J[sub v][space] and +Y[sub v][space] simultaneously. + +To get the initial values, let +[mu][space] = [nu] - floor([nu] + 1/2), then [mu][space] is the fractional part +of [nu][space] such that +|[mu]| <= 1/2 (we need this for convergence later). The idea is to +calculate J[sub [mu]](x), J[sub [mu]+1](x), Y[sub [mu]](x), Y[sub [mu]+1](x) +and use them to obtain J[sub [nu]](x), Y[sub [nu]](x). + +The algorithm is called Steed's method, which needs two +continued fractions as well as the Wronskian: + +[equation bessel8] + +[equation bessel11] + +[equation bessel12] + +See: F.S. Acton, ['Numerical Methods that Work], + The Mathematical Association of America, Washington, 1997. + +The continued fractions are computed using the modified Lentz's method +(W.J. Lentz, ['Generating Bessel functions in Mie scattering calculations +using continued fractions], Applied Optics, vol 15, 668 (1976)). +Their convergence rates depend on ['x], therefore we need +different strategies for large ['x] and small ['x]. + +['x > v], CF1 needs O(['x]) iterations to converge, CF2 converges rapidly + +['x <= v], CF1 converges rapidly, CF2 fails to converge when ['x] [^->] 0 + +When ['x] is large (['x] > 2), both continued fractions converge (CF1 +may be slow for really large ['x]). J[sub [mu]], J[sub [mu]+1], +Y[sub [mu]], Y[sub [mu]+1] can be calculated by + +[equation bessel13] + +where + +[equation bessel14] + +J[sub [nu]] and Y[sub [mu]] are then calculated using backward +(Miller's algorithm) and forward recurrence respectively. + +When ['x] is small (['x] <= 2), CF2 convergence may fail (but CF1 +works very well). The solution here is Temme's series: + +[equation bessel15] + +where + +[equation bessel16] + +g[sub k][space] and h[sub k][space] +are also computed by recursions (involving gamma functions), but the +formulas are a little complicated, readers are refered to +N.M. Temme, ['On the numerical evaluation of the ordinary Bessel function +of the second kind], Journal of Computational Physics, vol 21, 343 (1976). +Note Temme's series converge only for |[mu]| <= 1/2. + +As the previous case, Y[sub [nu]][space] is calculated from the forward +recurrence, so is Y[sub [nu]+1]. With these two +values and f[sub [nu]], the Wronskian yields J[sub [nu]](x) directly +without backward recurrence. + +[endsect] + +[section:bessel_root Finding Zeros of Bessel Functions of the First and Second Kinds] + +[h4 Synopsis] + +`#include <boost/math/special_functions/bessel.hpp>` + +Functions for obtaining both a single zero or root of the Bessel function, +and placing multiple zeros into a container like `std::vector` +by providing an output iterator. + +The signature of the single value functions are: + + template <class T> + T cyl_bessel_j_zero( + T v, // Floating-point value for Jv. + int m); // 1-based index of zero. + + template <class T> + T cyl_neumann_zero( + T v, // Floating-point value for Jv. + int m); // 1-based index of zero. + +and for multiple zeros: + + template <class T, class OutputIterator> + OutputIterator cyl_bessel_j_zero( + T v, // Floating-point value for Jv. + int start_index, // 1-based index of first zero. + unsigned number_of_zeros, // How many zeros to generate. + OutputIterator out_it); // Destination for zeros. + + template <class T, class OutputIterator> + OutputIterator cyl_neumann_zero( + T v, // Floating-point value for Jv. + int start_index, // 1-based index of zero. + unsigned number_of_zeros, // How many zeros to generate + OutputIterator out_it); // Destination for zeros. + +There are also versions which allow control of the __policy_section for error handling and precision. + + template <class T> + T cyl_bessel_j_zero( + T v, // Floating-point value for Jv. + int m, // 1-based index of zero. + const Policy&); // Policy to use. + + template <class T> + T cyl_neumann_zero( + T v, // Floating-point value for Jv. + int m, // 1-based index of zero. + const Policy&); // Policy to use. + + + template <class T, class OutputIterator> + OutputIterator cyl_bessel_j_zero( + T v, // Floating-point value for Jv. + int start_index, // 1-based index of first zero. + unsigned number_of_zeros, // How many zeros to generate. + OutputIterator out_it, // Destination for zeros. + const Policy& pol); // Policy to use. + + template <class T, class OutputIterator> + OutputIterator cyl_neumann_zero( + T v, // Floating-point value for Jv. + int start_index, // 1-based index of zero. + unsigned number_of_zeros, // How many zeros to generate. + OutputIterator out_it, // Destination for zeros. + const Policy& pol); // Policy to use. + +[h4 Description] + +Every real order [nu] cylindrical Bessel and Neumann functions have an infinite +number of zeros on the positive real axis. The real zeros on the positive real +axis can be found by solving for the roots of + +[emquad] ['J[sub [nu]](j[sub [nu], m]) = 0] + +[emquad] ['Y[sub [nu]](y[sub [nu], m]) = 0] + +Here, ['j[sub [nu], m]] represents the ['m[super th]] +root of the cylindrical Bessel function of order ['[nu]], +and ['y[sub [nu], m]] represents the ['m[super th]] +root of the cylindrical Neumann function of order ['[nu]]. + +The zeros or roots (values of `x` where the function crosses the horizontal `y = 0` axis) +of the Bessel and Neumann functions are computed by two functions, +`cyl_bessel_j_zero` and `cyl_neumann_zero`. + +In each case the index or rank of the zero +returned is 1-based, which is to say: + + cyl_bessel_j_zero(v, 1); + +returns the first zero of Bessel J. + +Passing an `start_index <= 0` results in a `std::domain_error` being raised. + +For certain parameters, however, the zero'th root is defined and +it has a value of zero. For example, the zero'th root +of `J[sub v](x)` is defined and it has a value of zero for all +values of `v > 0` and for negative integer values of `v = -n`. +Similar cases are described in the implementation details below. + +The order `v` of `J` can be positive, negative and zero for the `cyl_bessel_j` +and `cyl_neumann` functions, but not infinite nor NaN. + +[graph bessel_j_zeros] + +[graph neumann_y_zeros] + +[h4 Examples of finding Bessel and Neumann zeros] + +[import ../../example/bessel_zeros_example_1.cpp] + +[bessel_zeros_example_1] +[bessel_zeros_example_2] + +[import ../../example/bessel_zeros_interator_example.cpp] + +[bessel_zeros_iterator_example_1] +[bessel_zeros_iterator_example_2] + +[import ../../example/neumann_zeros_example_1.cpp] + +[neumann_zeros_example_1] +[neumann_zeros_example_2] + +[import ../../example/bessel_errors_example.cpp] + +[bessel_errors_example_1] +[bessel_errors_example_2] + +The full code (and output) for these examples is at +[@../../example/bessel_zeros_example_1.cpp Bessel zeros], +[@../../example/bessel_zeros_interator_example.cpp Bessel zeros iterator], +[@../../example/neumann_zeros_example_1.cpp Neumann zeros], +[@../../example/bessel_errors_example.cpp Bessel error messages]. + +[h3 Implementation] + +Various methods are used to compute initial estimates +for ['j[sub [nu], m]] and ['y[sub [nu], m]] ; these are described in detail below. + +After finding the initial estimate of a given root, +its precision is subsequently refined to the desired level +using Newton-Raphson iteration from Boost.Math's __root_finding_with_derivatives +utilities combined with the functions __cyl_bessel_j and __cyl_neumann. + +Newton iteration requires both ['J[sub [nu]](x)] or ['Y[sub [nu]](x)] +as well as its derivative. The derivatives of ['J[sub [nu]](x)] and ['Y[sub [nu]](x)] +with respect to ['x] are given by __Abramowitz_Stegun. +In particular, + +[emquad] ['d/[sub dx] ['J[sub [nu]](x)] = ['J[sub [nu]-1](x)] - [nu] J[sub [nu]](x)] / x + +[emquad] ['d/[sub dx] ['Y[sub [nu]](x)] = ['Y[sub [nu]-1](x)] - [nu] Y[sub [nu]](x)] / x + +Enumeration of the rank of a root (in other words the index of a root) +begins with one and counts up, in other words +['m,=1,2,3,[ellipsis]] The value of the first root is always greater than zero. + +For certain special parameters, cylindrical Bessel functions +and cylindrical Neumann functions have a root at the origin. For example, +['J[sub [nu]](x)] has a root at the origin for every positive order +['[nu] > 0], and for every negative integer order +['[nu] = -n] with ['n [isin] [negative] [super +]] and ['n [ne] 0]. + +In addition, ['Y[sub [nu]](x)] has a root at the origin +for every negative half-integer order ['[nu] = -n/2], with ['n [isin] [negative] [super +]] and +and ['n [ne] 0]. + +For these special parameter values, the origin with +a value of ['x = 0] is provided as the ['0[super th]] +root generated by `cyl_bessel_j_zero()` +and `cyl_neumann_zero()`. + +When calculating initial estimates for the roots +of Bessel functions, a distinction is made between +positive order and negative order, and different +methods are used for these. In addition, different algorithms +are used for the first root ['m = 1] and +for subsequent roots with higher rank ['m [ge] 2]. +Furthermore, estimates of the roots for Bessel functions +with order above and below a cutoff at ['[nu] = 2.2] +are calculated with different methods. + +Calculations of the estimates of ['j[sub [nu],1]] and ['y[sub [nu],1]] +with ['0 [le] [nu] < 2.2] use empirically tabulated values. +The coefficients for these have been generated by a +computer algebra system. + +Calculations of the estimates of ['j[sub [nu],1]] and ['y[sub [nu],1]] +with ['[nu][ge] 2.2] use Eqs.9.5.14 and 9.5.15 in __Abramowitz_Stegun. + +In particular, + +[emquad] ['j[sub [nu],1] [cong] [nu] + 1.85575 [nu][super [frac13]] + 1.033150 [nu][super -[frac13]] - 0.00397 [nu][super -1] - 0.0908 [nu][super -5/3] + 0.043 [nu][super -7/3] + [ellipsis]] + +and + +[emquad] ['y[sub [nu],1] [cong] [nu] + 0.93157 [nu][super [frac13]] + 0.26035 [nu][super -[frac13]] + 0.01198 [nu][super -1] - 0.0060 [nu][super -5/3] - 0.001 [nu][super -7/3] + [ellipsis]] + +Calculations of the estimates of ['j[sub [nu], m]] and ['y[sub [nu], m]] +with rank ['m > 2] and ['0 [le] [nu] < 2.2] use +McMahon's approximation, as described in M. Abramowitz and I. A. Stegan, Section 9.5 and 9.5.12. +In particular, + +[emquad] ['j[sub [nu],m], y[sub [nu],m] [cong] [beta] - ([mu]-1) / 8[beta]] + +[emquad] [emquad] [emquad] ['- 4([mu]-1)(7[mu] - 31) / 3(8[beta])[super 3]] + +[emquad] [emquad] [emquad] ['-32([mu]-1)(83[mu][sup2] - 982[mu] + 3779) / 15(8[beta])[super 5]] + +[emquad] [emquad] [emquad] ['-64([mu]-1)(6949[mu][super 3] - 153855[mu][sup2] + 1585743[mu]- 6277237) / 105(8a)[super 7]] + +[emquad] [emquad] [emquad] ['- [ellipsis]] [emquad] [emquad] (5) + +where ['[mu] = 4[nu][super 2]] and ['[beta] = (m + [frac12][nu] - [frac14])[pi]] +for ['j[sub [nu],m]] and +['[beta] = (m + [frac12][nu] -[frac34])[pi] for ['y[sub [nu],m]]]. + +Calculations of the estimates of ['j[sub [nu], m]] and ['y[sub [nu], m]] +with ['[nu] [ge] 2.2] use +one term in the asymptotic expansion given in +Eq.9.5.22 and top line of Eq.9.5.26 combined with Eq. 9.3.39, +all in __Abramowitz_Stegun explicit and easy-to-understand treatment +for asymptotic expansion of zeros. +The latter two equations are expressed for argument ['(x)] greater than one. +(Olver also gives the series form of the equations in +[@http://dlmf.nist.gov/10.21#vi [sect]10.21(vi) McMahon's Asymptotic Expansions for Large Zeros] - using slightly different variable names). + +In summary, + +[emquad] ['j[sub [nu], m] [sim] [nu]x(-[zeta]) + f[sub 1](-[zeta]/[nu])] + +where ['-[zeta] = [nu][super -2/3]a[sub m]] and ['a[sub m]] is +the absolute value of the ['m[super th]] root of ['Ai(x)] on the negative real axis. + +Here ['x = x(-[zeta])] is the inverse of the function + +[emquad] ['[frac23](-[zeta])[super 3/2] = [radic](x[sup2] - 1) - cos[supminus][sup1](1/x)] [emquad] [emquad] (7) + +Furthermore, + +[emquad] ['f[sub 1](-[zeta]) = [frac12]x(-[zeta]) {h(-[zeta])}[sup2] [sdot] b[sub 0](-[zeta])] + +where + +[emquad] ['h(-[zeta]) = {4(-[zeta]) / (x[sup2] - 1)}[super 4]] + +and + +[emquad] ['b[sub 0](-[zeta]) = -5/(48[zeta][sup2]) + 1/(-[zeta])[super [frac12]] [sdot] { 5/(24(x[super 2]-1)[super 3/2]) + 1/(8(x[super 2]-1)[super [frac12])]}] + +When solving for ['x(-[zeta])] in Eq. 7 above, +the right-hand-side is expanded to order 2 in +a Taylor series for large ['x]. This results in + +[emquad] ['[frac23](-[zeta])[super 3/2] [approx] x + 1/2x - [pi]/2] + +The positive root of the resulting quadratic equation +is used to find an initial estimate ['x(-[zeta])]. +This initial estimate is subsequently refined with +several steps of Newton-Raphson iteration +in Eq. 7. + +Estimates of the roots of cylindrical Bessel functions +of negative order on the positive real axis are found +using interlacing relations. For example, the ['m[super th]] +root of the cylindrical Bessel function ['j[sub -[nu],m]] +is bracketed by the ['m[super th]] root and the +['(m+1)[super th]] root of the Bessel function of +corresponding positive integer order. In other words, + +[emquad] ['j[sub n[nu],m]] < ['j[sub -[nu],m]] < ['j[sub n[nu],m+1]] + +where ['m > 1] and ['n[sub [nu]]] represents the integral +floor of the absolute value of ['|-[nu]|]. + +Similar bracketing relations are used to find estimates +of the roots of Neumann functions of negative order, +whereby a discontinuity at every negative half-integer +order needs to be handled. + +Bracketing relations do not hold for the first root +of cylindrical Bessel functions and cylindrical Neumann +functions with negative order. Therefore, iterative algorithms +combined with root-finding via bisection are used +to localize ['j[sub -[nu],1]] and ['y[sub -[nu],1]]. + +[h3 Testing] + +The precision of evaluation of zeros was tested at 50 decimal digits using `cpp_dec_float_50` +and found identical with spot values computed by __WolframAlpha. + +[endsect] [/section:bessel Finding Zeros of Bessel Functions of the First and Second Kinds] + +[/ + Copyright 2006, 2013 John Maddock, Paul A. Bristow, Xiaogang Zhang and Christopher Kormanyos. + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/bessel_prime.qbk b/boost/libs/math/doc/sf/bessel_prime.qbk new file mode 100644 index 00000000..ca6d21d9 --- /dev/null +++ b/boost/libs/math/doc/sf/bessel_prime.qbk @@ -0,0 +1,109 @@ + +[section:bessel_derivatives Derivatives of the Bessel Functions] + +[h4 Synopsis] + +`#include <boost/math/special_functions/bessel_prime.hpp>` + + template <class T1, class T2> + ``__sf_result`` cyl_bessel_j_prime(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` cyl_bessel_j_prime(T1 v, T2 x, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` cyl_neumann_prime(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` cyl_neumann_prime(T1 v, T2 x, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` cyl_bessel_i_prime(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` cyl_bessel_i_prime(T1 v, T2 x, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` cyl_bessel_k_prime(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` cyl_bessel_k_prime(T1 v, T2 x, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` sph_bessel_prime(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` sph_bessel_prime(T1 v, T2 x, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` sph_neumann_prime(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` sph_neumann_prime(T1 v, T2 x, const ``__Policy``&); + + +[h4 Description] + +These functions return the first derivative with respect to /x/ of the corresponding Bessel function. + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types. The functions are also optimised for the +relatively common case that T1 is an integer. + +[optional_policy] + +The functions return the result of __domain_error whenever the result is +undefined or complex. + +[h4 Testing] + +There are two sets of test values: spot values calculated using +[@http://www.wolframalpha.com/ wolframalpha.com], +and a much larger set of tests computed using +a relation to the underlying Bessel functions that the implementation +does not use. + +[h4 Accuracy] + +The accuracy of these functions is broadly similar to the underlying Bessel functions. + +[table_cyl_bessel_i_prime_integer_orders_] + +[table_cyl_bessel_i_prime] + +[table_cyl_bessel_j_prime_integer_orders_] + +[table_cyl_bessel_j_prime] + +[table_cyl_bessel_k_prime_integer_orders_] + +[table_cyl_bessel_k_prime] + +[table_sph_bessel_prime] + +[table_sph_neumann_prime] + + +[h4 Implementation] + +In the general case, the derivatives are calculated using the relations: + +[equation bessel_derivatives1] + +There are also a number of special cases, for large x we have: + +[equation bessel_derivatives4] + +And for small x: + +[equation bessel_derivatives5] + +[endsect] + +[/ + Copyright 2013, 2013 John Maddock, Anton Bikineev. + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/bessel_spherical.qbk b/boost/libs/math/doc/sf/bessel_spherical.qbk new file mode 100644 index 00000000..5a3b3b1b --- /dev/null +++ b/boost/libs/math/doc/sf/bessel_spherical.qbk @@ -0,0 +1,90 @@ + +[section:sph_bessel Spherical Bessel Functions of the First and Second Kinds] + +[h4 Synopsis] + +`#include <boost/math/special_functions/bessel.hpp>` + + template <class T1, class T2> + ``__sf_result`` sph_bessel(unsigned v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` sph_bessel(unsigned v, T2 x, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` sph_neumann(unsigned v, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` sph_neumann(unsigned v, T2 x, const ``__Policy``&); + +[h4 Description] + +The functions __sph_bessel and __sph_neumann return the result of the +Spherical Bessel functions of the first and second kinds respectively: + +sph_bessel(v, x) = j[sub v](x) + +sph_neumann(v, x) = y[sub v](x) = n[sub v](x) + +where: + +[equation sbessel2] + +The return type of these functions is computed using the __arg_promotion_rules +for the single argument type T. + +[optional_policy] + +The functions return the result of __domain_error whenever the result is +undefined or complex: this occurs when `x < 0`. + +The j[sub v][space] function is cyclic like J[sub v][space] but differs +in its behaviour at the origin: + +[graph sph_bessel] + +Likewise y[sub v][space] is also cyclic for large x, but tends to -[infin][space] +for small /x/: + +[graph sph_neumann] + +[h4 Testing] + +There are two sets of test values: spot values calculated using +[@http://functions.wolfram.com/ functions.wolfram.com], +and a much larger set of tests computed using +a simplified version of this implementation +(with all the special case handling removed). + +[h4 Accuracy] + +[table_sph_bessel] + +[table_sph_neumann] + +[h4 Implementation] + +Other than error handling and a couple of special cases these functions +are implemented directly in terms of their definitions: + +[equation sbessel2] + +The special cases occur for: + +j[sub 0][space]= __sinc_pi(x) = sin(x) / x + +and for small ['x < 1], we can use the series: + +[equation sbessel5] + +which neatly avoids the problem of calculating 0/0 that can occur with the +main definition as x [rarr] 0. + +[endsect] + +[/ + Copyright 2006 John Maddock, Paul A. Bristow and Xiaogang Zhang. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/beta.qbk b/boost/libs/math/doc/sf/beta.qbk new file mode 100644 index 00000000..f1c505bc --- /dev/null +++ b/boost/libs/math/doc/sf/beta.qbk @@ -0,0 +1,110 @@ +[section:beta_function Beta] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/beta.hpp> +`` + + namespace boost{ namespace math{ + + template <class T1, class T2> + ``__sf_result`` beta(T1 a, T2 b); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` beta(T1 a, T2 b, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +The beta function is defined by: + +[equation beta1] + +[graph beta] + +[optional_policy] + +There are effectively two versions of this function internally: a fully +generic version that is slow, but reasonably accurate, and a much more +efficient approximation that is used where the number of digits in the significand +of T correspond to a certain __lanczos. In practice any built-in +floating-point type you will encounter has an appropriate __lanczos +defined for it. It is also possible, given enough machine time, to generate +further __lanczos's using the program libs/math/tools/lanczos_generator.cpp. + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types. + +[h4 Accuracy] + +The following table shows peak errors for various domains of input arguments, +along with comparisons to the __gsl and __cephes libraries. Note that +only results for the widest floating point type on the system are given as +narrower types have __zero_error. + +[table_beta] + +Note that the worst errors occur when a or b are large, and that +when this is the case the result is very close to zero, so absolute +errors will be very small. + +[h4 Testing] + +A mixture of spot tests of exact values, and randomly generated test data are +used: the test data was computed using +[@http://shoup.net/ntl/doc/RR.txt NTL::RR] at 1000-bit precision. + +[h4 Implementation] + +Traditional methods of evaluating the beta function either involve evaluating +the gamma functions directly, or taking logarithms and then +exponentiating the result. However, the former is prone to overflows +for even very modest arguments, while the latter is prone to cancellation +errors. As an alternative, if we regard the gamma function as a white-box +containing the __lanczos, then we can combine the power terms: + +[equation beta2] + +which is almost the ideal solution, however almost all of the error occurs +in evaluating the power terms when /a/ or /b/ are large. If we assume that /a > b/ +then the larger of the two power terms can be reduced by a factor of /b/, which +immediately cuts the maximum error in half: + +[equation beta3] + +This may not be the final solution, but it is very competitive compared to +other implementation methods. + +The generic implementation - where no __lanczos approximation is available - is +implemented in a very similar way to the generic version of the gamma function. +Again in order to avoid numerical overflow the power terms that prefix the series and +continued fraction parts are collected together into: + +[equation beta8] + +where la, lb and lc are the integration limits used for a, b, and a+b. + +There are a few special cases worth mentioning: + +When /a/ or /b/ are less than one, we can use the recurrence relations: + +[equation beta4] + +[equation beta5] + +to move to a more favorable region where they are both greater than 1. + +In addition: + +[equation beta7] + +[endsect][/section:beta_function The Beta Function] +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/beta_derivative.qbk b/boost/libs/math/doc/sf/beta_derivative.qbk new file mode 100644 index 00000000..24c22628 --- /dev/null +++ b/boost/libs/math/doc/sf/beta_derivative.qbk @@ -0,0 +1,50 @@ +[section:beta_derivative Derivative of the Incomplete Beta Function] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/beta.hpp> +`` + + namespace boost{ namespace math{ + + template <class T1, class T2, class T3> + ``__sf_result`` ibeta_derivative(T1 a, T2 b, T3 x); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibeta_derivative(T1 a, T2 b, T3 x, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +This function finds some uses in statistical distributions: it +computes the partial derivative with respect to /x/ of the incomplete +beta function __ibeta. + +[equation derivative2] + +The return type of this function is computed using the __arg_promotion_rules +when T1, T2 and T3 are different types. + +[optional_policy] + +[h4 Accuracy] + +Almost identical to the incomplete beta function __ibeta. + +[h4 Implementation] + +This function just expose some of the internals of the incomplete +beta function __ibeta: refer to the documentation for that function +for more information. + +[endsect][/section Derivatives of the Incomplete Beta and Gamma Functions] +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + + diff --git a/boost/libs/math/doc/sf/digamma.qbk b/boost/libs/math/doc/sf/digamma.qbk new file mode 100644 index 00000000..0bcdf60a --- /dev/null +++ b/boost/libs/math/doc/sf/digamma.qbk @@ -0,0 +1,142 @@ +[section:digamma Digamma] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/digamma.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` digamma(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` digamma(T z, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +Returns the digamma or psi function of /x/. Digamma is defined as the logarithmic +derivative of the gamma function: + +[equation digamma1] + +[graph digamma] + +[optional_policy] + +The return type of this function is computed using the __arg_promotion_rules: +the result is of type `double` when T is an integer type, and type T otherwise. + +[h4 Accuracy] + +The following table shows the peak errors (in units of epsilon) +found on various platforms with various floating point types. +Unless otherwise specified any floating point type that is narrower +than the one shown will have __zero_error. + +[table_digamma] + +As shown above, error rates for positive arguments are generally very low. +For negative arguments there are an infinite number of irrational roots: +relative errors very close to these can be arbitrarily large, although +absolute error will remain very low. + +[h4 Testing] + +There are two sets of tests: spot values are computed using +the online calculator at functions.wolfram.com, while random test values +are generated using the high-precision reference implementation (a +differentiated __lanczos see below). + +[h4 Implementation] + +The implementation is divided up into the following domains: + +For Negative arguments the reflection formula: + + digamma(1-x) = digamma(x) + pi/tan(pi*x); + +is used to make /x/ positive. + +For arguments in the range [0,1] the recurrence relation: + + digamma(x) = digamma(x+1) - 1/x + +is used to shift the evaluation to [1,2]. + +For arguments in the range [1,2] a rational approximation [jm_rationals] is used (see below). + +For arguments in the range [2,BIG] the recurrence relation: + + digamma(x+1) = digamma(x) + 1/x; + +is used to shift the evaluation to the range [1,2]. + +For arguments > BIG the asymptotic expansion: + +[equation digamma2] + +can be used. However, this expansion is divergent after a few terms: +exactly how many terms depends on the size of /x/. Therefore the value +of /BIG/ must be chosen so that the series can be truncated at a term +that is too small to have any effect on the result when evaluated at /BIG/. +Choosing BIG=10 for up to 80-bit reals, and BIG=20 for 128-bit reals allows +the series to truncated after a suitably small number of terms and evaluated +as a polynomial in `1/(x*x)`. + +The arbitrary precision version of this function uses recurrence relations until +x > BIG, and then evaluation via the asymptotic expansion above. As special cases +integer and half integer arguments are handled via: + +[equation digamma4] + +[equation digamma5] + +The rational approximation [jm_rationals] in the range [1,2] is derived as follows. + +First a high precision approximation to digamma was constructed using a 60-term +differentiated __lanczos, the form used is: + +[equation digamma3] + +Where P(x) and Q(x) are the polynomials from the rational form of the Lanczos sum, +and P'(x) and Q'(x) are their first derivatives. The Lanzos part of this +approximation has a theoretical precision of ~100 decimal digits. However, +cancellation in the above sum will reduce that to around `99-(1/y)` digits +if /y/ is the result. This approximation was used to calculate the positive root +of digamma, and was found to agree with the value used by +Cody to 25 digits (See Math. Comp. 27, 123-127 (1973) by Cody, Strecok and Thacher) +and with the value used by Morris to 35 digits (See TOMS Algorithm 708). + +Likewise a few spot tests agreed with values calculated using +functions.wolfram.com to >40 digits. +That's sufficiently precise to insure that the approximation below is +accurate to double precision. Achieving 128-bit long double precision requires that +the location of the root is known to ~70 digits, and it's not clear whether +the value calculated by this method meets that requirement: the difficulty +lies in independently verifying the value obtained. + +The rational approximation [jm_rationals] was optimised for absolute error using the form: + + digamma(x) = (x - X0)(Y + R(x - 1)); + +Where X0 is the positive root of digamma, Y is a constant, and R(x - 1) is the +rational approximation. Note that since X0 is irrational, we need twice as many +digits in X0 as in x in order to avoid cancellation error during the subtraction +(this assumes that /x/ is an exact value, if it's not then all bets are off). That +means that even when x is the value of the root rounded to the nearest +representable value, the result of digamma(x) ['[*will not be zero]]. + + +[endsect][/section:digamma The Digamma Function] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/ellint_carlson.qbk b/boost/libs/math/doc/sf/ellint_carlson.qbk new file mode 100644 index 00000000..4d94ad71 --- /dev/null +++ b/boost/libs/math/doc/sf/ellint_carlson.qbk @@ -0,0 +1,246 @@ +[/ +Copyright (c) 2006 Xiaogang Zhang +Copyright (c) 2006 John Maddock +Use, modification and distribution are subject to the +Boost Software License, Version 1.0. (See accompanying file +LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +] + +[section:ellint_carlson Elliptic Integrals - Carlson Form] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/ellint_rf.hpp> +`` + + namespace boost { namespace math { + + template <class T1, class T2, class T3> + ``__sf_result`` ellint_rf(T1 x, T2 y, T3 z) + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ellint_rf(T1 x, T2 y, T3 z, const ``__Policy``&) + + }} // namespaces + + +`` + #include <boost/math/special_functions/ellint_rd.hpp> +`` + + namespace boost { namespace math { + + template <class T1, class T2, class T3> + ``__sf_result`` ellint_rd(T1 x, T2 y, T3 z) + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ellint_rd(T1 x, T2 y, T3 z, const ``__Policy``&) + + }} // namespaces + + +`` + #include <boost/math/special_functions/ellint_rj.hpp> +`` + + namespace boost { namespace math { + + template <class T1, class T2, class T3, class T4> + ``__sf_result`` ellint_rj(T1 x, T2 y, T3 z, T4 p) + + template <class T1, class T2, class T3, class T4, class ``__Policy``> + ``__sf_result`` ellint_rj(T1 x, T2 y, T3 z, T4 p, const ``__Policy``&) + + }} // namespaces + + +`` + #include <boost/math/special_functions/ellint_rc.hpp> +`` + + namespace boost { namespace math { + + template <class T1, class T2> + ``__sf_result`` ellint_rc(T1 x, T2 y) + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` ellint_rc(T1 x, T2 y, const ``__Policy``&) + + }} // namespaces + +`` + #include <boost/math/special_functions/ellint_rg.hpp> +`` + + namespace boost { namespace math { + + template <class T1, class T2, class T3> + ``__sf_result`` ellint_rg(T1 x, T2 y, T3 z) + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ellint_rg(T1 x, T2 y, T3 z, const ``__Policy``&) + + }} // namespaces + + + +[heading Description] + +These functions return Carlson's symmetrical elliptic integrals, the functions +have complicated behavior over all their possible domains, but the following +graph gives an idea of their behavior: + +[graph ellint_carlson] + +The return type of these functions is computed using the __arg_promotion_rules +when the arguments are of different types: otherwise the return is the same type +as the arguments. + + template <class T1, class T2, class T3> + ``__sf_result`` ellint_rf(T1 x, T2 y, T3 z) + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ellint_rf(T1 x, T2 y, T3 z, const ``__Policy``&) + +Returns Carlson's Elliptic Integral R[sub F]: + +[equation ellint9] + +Requires that all of the arguments are non-negative, and at most +one may be zero. Otherwise returns the result of __domain_error. + +[optional_policy] + + template <class T1, class T2, class T3> + ``__sf_result`` ellint_rd(T1 x, T2 y, T3 z) + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ellint_rd(T1 x, T2 y, T3 z, const ``__Policy``&) + +Returns Carlson's elliptic integral R[sub D]: + +[equation ellint10] + +Requires that x and y are non-negative, with at most one of them +zero, and that z >= 0. Otherwise returns the result of __domain_error. + +[optional_policy] + + template <class T1, class T2, class T3, class T4> + ``__sf_result`` ellint_rj(T1 x, T2 y, T3 z, T4 p) + + template <class T1, class T2, class T3, class T4, class ``__Policy``> + ``__sf_result`` ellint_rj(T1 x, T2 y, T3 z, T4 p, const ``__Policy``&) + +Returns Carlson's elliptic integral R[sub J]: + +[equation ellint11] + +Requires that x, y and z are non-negative, with at most one of them +zero, and that ['p != 0]. Otherwise returns the result of __domain_error. + +[optional_policy] + +When ['p < 0] the function returns the +[@http://en.wikipedia.org/wiki/Cauchy_principal_value Cauchy principal value] +using the relation: + +[equation ellint17] + + template <class T1, class T2> + ``__sf_result`` ellint_rc(T1 x, T2 y) + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` ellint_rc(T1 x, T2 y, const ``__Policy``&) + +Returns Carlson's elliptic integral R[sub C]: + +[equation ellint12] + +Requires that ['x > 0] and that ['y != 0]. +Otherwise returns the result of __domain_error. + +[optional_policy] + +When ['y < 0] the function returns the +[@http://mathworld.wolfram.com/CauchyPrincipalValue.html Cauchy principal value] +using the relation: + +[equation ellint18] + + template <class T1, class T2, class T3> + ``__sf_result`` ellint_rg(T1 x, T2 y, T3 z) + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ellint_rg(T1 x, T2 y, T3 z, const ``__Policy``&) + +Returns Carlson's elliptic integral R[sub G]: + +[equation ellint27] + +Requires that x and y are non-negative, otherwise returns the result of __domain_error. + +[optional_policy] + +[heading Testing] + +There are two sets of tests. + +Spot tests compare selected values with test data given in: + +[:B. C. Carlson, ['[@http://arxiv.org/abs/math.CA/9409227 +Numerical computation of real or complex elliptic integrals]]. Numerical Algorithms, +Volume 10, Number 1 / March, 1995, pp 13-26.] + +Random test data generated using NTL::RR at 1000-bit precision and our +implementation checks for rounding-errors and/or regressions. + +There are also sanity checks that use the inter-relations between the integrals +to verify their correctness: see the above Carlson paper for details. + +[heading Accuracy] + +These functions are computed using only basic arithmetic operations, so +there isn't much variation in accuracy over differing platforms. +Note that only results for the widest floating-point type on the +system are given as narrower types have __zero_error. All values +are relative errors in units of epsilon. + +[table_ellint_rc] + +[table_ellint_rd] + +[table_ellint_rg] + +[table_ellint_rf] + +[table_ellint_rj] + + +[heading Implementation] + +The key of Carlson's algorithm [[link ellint_ref_carlson79 Carlson79]] is the +duplication theorem: + +[equation ellint13] + +By applying it repeatedly, ['x], ['y], ['z] get +closer and closer. When they are nearly equal, the special case equation + +[equation ellint16] + +is used. More specifically, ['[R F]] is evaluated from a Taylor series +expansion to the fifth order. The calculations of the other three integrals +are analogous, except for R[sub C] which can be computed from elementary functions. + +For ['p < 0] in ['R[sub J](x, y, z, p)] and ['y < 0] in ['R[sub C](x, y)], +the integrals are singular and their +[@http://mathworld.wolfram.com/CauchyPrincipalValue.html Cauchy principal values] +are returned via the relations: + +[equation ellint17] + +[equation ellint18] + +[endsect] diff --git a/boost/libs/math/doc/sf/ellint_introduction.qbk b/boost/libs/math/doc/sf/ellint_introduction.qbk new file mode 100644 index 00000000..80c11f65 --- /dev/null +++ b/boost/libs/math/doc/sf/ellint_introduction.qbk @@ -0,0 +1,249 @@ +[/ +Copyright (c) 2006 Xiaogang Zhang +Use, modification and distribution are subject to the +Boost Software License, Version 1.0. (See accompanying file +LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +] + +[section:ellint_intro Elliptic Integral Overview] + +The main reference for the elliptic integrals is: + +[:M. Abramowitz and I. A. Stegun (Eds.) (1964) +Handbook of Mathematical Functions with Formulas, Graphs, and +Mathematical Tables, +National Bureau of Standards Applied Mathematics Series, U.S. Government Printing Office, Washington, D.C.] + +Mathworld also contain a lot of useful background information: + +[:[@http://mathworld.wolfram.com/EllipticIntegral.html Weisstein, Eric W. +"Elliptic Integral." From MathWorld--A Wolfram Web Resource.]] + +As does [@http://en.wikipedia.org/wiki/Elliptic_integral Wikipedia Elliptic integral]. + +[h4 Notation] + +All variables are real numbers unless otherwise noted. + +[h4 Definition] + +[equation ellint1] + +is called elliptic integral if ['R(t, s)] is a rational function +of ['t] and ['s], and ['s[super 2]] is a cubic or quartic polynomial +in ['t]. + +Elliptic integrals generally can not be expressed in terms of +elementary functions. However, Legendre showed that all elliptic +integrals can be reduced to the following three canonical forms: + +Elliptic Integral of the First Kind (Legendre form) + +[equation ellint2] + +Elliptic Integral of the Second Kind (Legendre form) + +[equation ellint3] + +Elliptic Integral of the Third Kind (Legendre form) + +[equation ellint4] + +where + +[equation ellint5] + +[note ['[phi]] is called the amplitude. + +['k] is called the modulus. + +['[alpha]] is called the modular angle. + +['n] is called the characteristic.] + +[caution Perhaps more than any other special functions the elliptic +integrals are expressed in a variety of different ways. In particular, +the final parameter /k/ (the modulus) may be expressed using a modular +angle [alpha], or a parameter /m/. These are related by: + +k = sin[alpha] + +m = k[super 2] = sin[super 2][alpha] + +So that the integral of the third kind (for example) may be expressed as +either: + +[Pi](n, [phi], k) + +[Pi](n, [phi] \\ [alpha]) + +[Pi](n, [phi]| m) + +To further complicate matters, some texts refer to the ['complement +of the parameter m], or 1 - m, where: + +1 - m = 1 - k[super 2] = cos[super 2][alpha] + +This implementation uses /k/ throughout: this matches the requirements +of the [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf +Technical Report on C++ Library Extensions]. However, you should +be extra careful when using these functions!] + +When ['[phi]] = ['[pi]] / 2, the elliptic integrals are called ['complete]. + +Complete Elliptic Integral of the First Kind (Legendre form) + +[equation ellint6] + +Complete Elliptic Integral of the Second Kind (Legendre form) + +[equation ellint7] + +Complete Elliptic Integral of the Third Kind (Legendre form) + +[equation ellint8] + +Legendre also defined a forth integral D([phi],k) which is a combination of the other three: + +[equation ellint_d] + +Like the other Legendre integrals this comes in both complete and incomplete forms. + +[h4 Carlson Elliptic Integrals] + +Carlson [[link ellint_ref_carlson77 Carlson77]] [[link ellint_ref_carlson78 Carlson78]] gives an alternative definition of +elliptic integral's canonical forms: + +Carlson's Elliptic Integral of the First Kind + +[equation ellint9] + +where ['x], ['y], ['z] are nonnegative and at most one of them +may be zero. + +Carlson's Elliptic Integral of the Second Kind + +[equation ellint10] + +where ['x], ['y] are nonnegative, at most one of them may be zero, +and ['z] must be positive. + +Carlson's Elliptic Integral of the Third Kind + +[equation ellint11] + +where ['x], ['y], ['z] are nonnegative, at most one of them may be +zero, and ['p] must be nonzero. + +Carlson's Degenerate Elliptic Integral + +[equation ellint12] + +where ['x] is nonnegative and ['y] is nonzero. + +[note ['R[sub C](x, y) = R[sub F](x, y, y)] + +['R[sub D](x, y, z) = R[sub J](x, y, z, z)]] + +Carlson's Symmetric Integral + +[equation ellint27] + +[h4 Duplication Theorem] + +Carlson proved in [[link ellint_ref_carlson78 Carlson78]] that + +[equation ellint13] + +[h4 Carlson's Formulas] + +The Legendre form and Carlson form of elliptic integrals are related +by equations: + +[equation ellint14] + +In particular, + +[equation ellint15] + +[h4 Miscellaneous Elliptic Integrals] + +There are two functions related to the elliptic integrals which otherwise +defy categorisation, these are the Jacobi Zeta function: + +[equation jacobi_zeta] + +and the Heuman Lambda function: + +[equation heuman_lambda] + +Both of these functions are easily implemented in terms of Carlson's integrals, and are +provided in this library as __jacobi_zeta and __heuman_lambda. + +[h4 Numerical Algorithms] + +The conventional methods for computing elliptic integrals are Gauss +and Landen transformations, which converge quadratically and work +well for elliptic integrals of the first and second kinds. +Unfortunately they suffer from loss of significant digits for the +third kind. Carlson's algorithm [[link ellint_ref_carlson79 Carlson79]] [[link ellint_ref_carlson78 Carlson78]], by contrast, +provides a unified method for all three kinds of elliptic integrals +with satisfactory precisions. + +[h4 References] + +Special mention goes to: + +[:A. M. Legendre, ['Traitd des Fonctions Elliptiques et des Integrales +Euleriennes], Vol. 1. Paris (1825).] + +However the main references are: + +# [#ellint_ref_AS]M. Abramowitz and I. A. Stegun (Eds.) (1964) +Handbook of Mathematical Functions with Formulas, Graphs, and +Mathematical Tables, +National Bureau of Standards Applied Mathematics Series, U.S. Government Printing Office, Washington, D.C. +# [#ellint_ref_carlson79]B.C. Carlson, ['Computing elliptic integrals by duplication], + Numerische Mathematik, vol 33, 1 (1979). +# [#ellint_ref_carlson77]B.C. Carlson, ['Elliptic Integrals of the First Kind], + SIAM Journal on Mathematical Analysis, vol 8, 231 (1977). +# [#ellint_ref_carlson78]B.C. Carlson, ['Short Proofs of Three Theorems on Elliptic Integrals], + SIAM Journal on Mathematical Analysis, vol 9, 524 (1978). +# [#ellint_ref_carlson81]B.C. Carlson and E.M. Notis, ['ALGORITHM 577: Algorithms for Incomplete + Elliptic Integrals], ACM Transactions on Mathematmal Software, + vol 7, 398 (1981). +# B. C. Carlson, ['On computing elliptic integrals and functions]. J. Math. and +Phys., 44 (1965), pp. 36-51. +# B. C. Carlson, ['A table of elliptic integrals of the second kind]. Math. Comp., 49 +(1987), pp. 595-606. (Supplement, ibid., pp. S13-S17.) +# B. C. Carlson, ['A table of elliptic integrals of the third kind]. Math. Comp., 51 (1988), +pp. 267-280. (Supplement, ibid., pp. S1-S5.) +# B. C. Carlson, ['A table of elliptic integrals: cubic cases]. Math. Comp., 53 (1989), pp. +327-333. +# B. C. Carlson, ['A table of elliptic integrals: one quadratic factor]. Math. Comp., 56 (1991), +pp. 267-280. +# B. C. Carlson, ['A table of elliptic integrals: two quadratic factors]. Math. Comp., 59 +(1992), pp. 165-180. +# B. C. Carlson, ['[@http://arxiv.org/abs/math.CA/9409227 +Numerical computation of real or complex elliptic integrals]]. Numerical Algorithms, +Volume 10, Number 1 / March, 1995, p13-26. +# B. C. Carlson and John L. Gustafson, ['[@http://arxiv.org/abs/math.CA/9310223 +Asymptotic Approximations for Symmetric Elliptic Integrals]], +SIAM Journal on Mathematical Analysis, Volume 25, Issue 2 (March 1994), 288-303. + + +The following references, while not directly relevent to our implementation, +may also be of interest: + +# R. Burlisch, ['Numerical Compuation of Elliptic Integrals and Elliptic Functions.] +Numerical Mathematik 7, 78-90. +# R. Burlisch, ['An extension of the Bartky Transformation to Incomplete +Elliptic Integrals of the Third Kind]. Numerical Mathematik 13, 266-284. +# R. Burlisch, ['Numerical Compuation of Elliptic Integrals and Elliptic Functions. III]. +Numerical Mathematik 13, 305-315. +# T. Fukushima and H. Ishizaki, ['[@http://adsabs.harvard.edu/abs/1994CeMDA..59..237F +Numerical Computation of Incomplete Elliptic Integrals of a General Form.]] +Celestial Mechanics and Dynamical Astronomy, Volume 59, Number 3 / July, 1994, +237-251. + +[endsect] diff --git a/boost/libs/math/doc/sf/ellint_legendre.qbk b/boost/libs/math/doc/sf/ellint_legendre.qbk new file mode 100644 index 00000000..4eeb52c2 --- /dev/null +++ b/boost/libs/math/doc/sf/ellint_legendre.qbk @@ -0,0 +1,554 @@ +[/ +Copyright (c) 2006 Xiaogang Zhang +Copyright (c) 2006 John Maddock +Use, modification and distribution are subject to the +Boost Software License, Version 1.0. (See accompanying file +LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +] + +[section:ellint_1 Elliptic Integrals of the First Kind - Legendre Form] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/ellint_1.hpp> +`` + + namespace boost { namespace math { + + template <class T1, class T2> + ``__sf_result`` ellint_1(T1 k, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` ellint_1(T1 k, T2 phi, const ``__Policy``&); + + template <class T> + ``__sf_result`` ellint_1(T k); + + template <class T, class ``__Policy``> + ``__sf_result`` ellint_1(T k, const ``__Policy``&); + + }} // namespaces + +[heading Description] + +These two functions evaluate the incomplete elliptic integral of the first kind +['F([phi], k)] and its complete counterpart ['K(k) = F([pi]/2, k)]. + +[graph ellint_1] + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types: when they are the same type then the result +is the same type as the arguments. + + template <class T1, class T2> + ``__sf_result`` ellint_1(T1 k, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` ellint_1(T1 k, T2 phi, const ``__Policy``&); + +Returns the incomplete elliptic integral of the first kind ['F([phi], k)]: + +[equation ellint2] + +Requires -1 <= k <= 1, otherwise returns the result of __domain_error. + +[optional_policy] + + template <class T> + ``__sf_result`` ellint_1(T k); + + template <class T> + ``__sf_result`` ellint_1(T k, const ``__Policy``&); + +Returns the complete elliptic integral of the first kind ['K(k)]: + +[equation ellint6] + +Requires -1 <= k <= 1, otherwise returns the result of __domain_error. + +[optional_policy] + +[heading Accuracy] + +These functions are computed using only basic arithmetic operations, so +there isn't much variation in accuracy over differing platforms. +Note that only results for the widest floating point type on the +system are given as narrower types have __zero_error. All values +are relative errors in units of epsilon. + +[table_ellint_1] + +[heading Testing] + +The tests use a mixture of spot test values calculated using the online +calculator at [@http://functions.wolfram.com/ functions.wolfram.com], +and random test data generated using +NTL::RR at 1000-bit precision and this implementation. + +[heading Implementation] + +These functions are implemented in terms of Carlson's integrals +using the relations: + +[equation ellint19] + +and + +[equation ellint20] + + +[endsect] + +[section:ellint_2 Elliptic Integrals of the Second Kind - Legendre Form] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/ellint_2.hpp> +`` + + namespace boost { namespace math { + + template <class T1, class T2> + ``__sf_result`` ellint_2(T1 k, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` ellint_2(T1 k, T2 phi, const ``__Policy``&); + + template <class T> + ``__sf_result`` ellint_2(T k); + + template <class T, class ``__Policy``> + ``__sf_result`` ellint_2(T k, const ``__Policy``&); + + }} // namespaces + +[heading Description] + +These two functions evaluate the incomplete elliptic integral of the second kind +['E([phi], k)] and its complete counterpart ['E(k) = E([pi]/2, k)]. + +[graph ellint_2] + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types: when they are the same type then the result +is the same type as the arguments. + + template <class T1, class T2> + ``__sf_result`` ellint_2(T1 k, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` ellint_2(T1 k, T2 phi, const ``__Policy``&); + +Returns the incomplete elliptic integral of the second kind ['E([phi], k)]: + +[equation ellint3] + +Requires -1 <= k <= 1, otherwise returns the result of __domain_error. + +[optional_policy] + + template <class T> + ``__sf_result`` ellint_2(T k); + + template <class T> + ``__sf_result`` ellint_2(T k, const ``__Policy``&); + +Returns the complete elliptic integral of the second kind ['E(k)]: + +[equation ellint7] + +Requires -1 <= k <= 1, otherwise returns the result of __domain_error. + +[optional_policy] + +[heading Accuracy] + +These functions are computed using only basic arithmetic operations, so +there isn't much variation in accuracy over differing platforms. +Note that only results for the widest floating point type on the +system are given as narrower types have __zero_error. All values +are relative errors in units of epsilon. + +[table_ellint_2] + +[heading Testing] + +The tests use a mixture of spot test values calculated using the online +calculator at [@http://functions.wolfram.com +functions.wolfram.com], and random test data generated using +NTL::RR at 1000-bit precision and this implementation. + +[heading Implementation] + +These functions are implemented in terms of Carlson's integrals +using the relations: + +[equation ellint21] + +and + +[equation ellint22] + + +[endsect] + +[section:ellint_3 Elliptic Integrals of the Third Kind - Legendre Form] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/ellint_3.hpp> +`` + + namespace boost { namespace math { + + template <class T1, class T2, class T3> + ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` ellint_3(T1 k, T2 n); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` ellint_3(T1 k, T2 n, const ``__Policy``&); + + }} // namespaces + +[heading Description] + +These two functions evaluate the incomplete elliptic integral of the third kind +['[Pi](n, [phi], k)] and its complete counterpart ['[Pi](n, k) = E(n, [pi]/2, k)]. + +[graph ellint_3] + +The return type of these functions is computed using the __arg_promotion_rules +when the arguments are of different types: when they are the same type then the result +is the same type as the arguments. + + template <class T1, class T2, class T3> + ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ellint_3(T1 k, T2 n, T3 phi, const ``__Policy``&); + +Returns the incomplete elliptic integral of the third kind ['[Pi](n, [phi], k)]: + +[equation ellint4] + +Requires ['-1 <= k <= 1] and ['n < 1/sin[super 2]([phi])], otherwise +returns the result of __domain_error (outside this range the result +would be complex). + +[optional_policy] + + template <class T1, class T2> + ``__sf_result`` ellint_3(T1 k, T2 n); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` ellint_3(T1 k, T2 n, const ``__Policy``&); + +Returns the complete elliptic integral of the first kind ['[Pi](n, k)]: + +[equation ellint8] + +Requires ['-1 <= k <= 1] and ['n < 1], otherwise returns the +result of __domain_error (outside this range the result would be complex). + +[optional_policy] + +[heading Accuracy] + +These functions are computed using only basic arithmetic operations, so +there isn't much variation in accuracy over differing platforms. +Note that only results for the widest floating point type on the +system are given as narrower types have __zero_error. All values +are relative errors in units of epsilon. + +[table_ellint_3] + +[heading Testing] + +The tests use a mixture of spot test values calculated using the online +calculator at [@http://functions.wolfram.com +functions.wolfram.com], and random test data generated using +NTL::RR at 1000-bit precision and this implementation. + +[heading Implementation] + +The implementation for [Pi](n, [phi], k) first siphons off the special cases: + +['[Pi](0, [phi], k) = F([phi], k)] + +['[Pi](n, [pi]/2, k) = [Pi](n, k)] + +and + +[equation ellint23] + +Then if n < 0 the relations (A&S 17.7.15/16): + +[equation ellint24] + +are used to shift /n/ to the range \[0, 1\]. + +Then the relations: + +['[Pi](n, -[phi], k) = -[Pi](n, [phi], k)] + +['[Pi](n, [phi]+m[pi], k) = [Pi](n, [phi], k) + 2m[Pi](n, k) ; n <= 1] + +['[Pi](n, [phi]+m[pi], k) = [Pi](n, [phi], k) ; n > 1] +[footnote I haven't been able to find a literature reference for this +relation, but it appears to be the convention used by Mathematica. +Intuitively the first ['2 * m * [Pi](n, k)] terms cancel out as the +derivative alternates between +[infin] and -[infin].] + +are used to move [phi][space] to the range \[0, [pi]\/2\]. + +The functions are then implemented in terms of Carlson's integrals +using the relations: + +[equation ellint25] + +and + +[equation ellint26] + +[endsect] + +[section:ellint_d Elliptic Integral D - Legendre Form] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/ellint_d.hpp> +`` + + namespace boost { namespace math { + + template <class T1, class T2> + ``__sf_result`` ellint_d(T1 k, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` ellint_d(T1 k, T2 phi, const ``__Policy``&); + + template <class T1> + ``__sf_result`` ellint_d(T1 k); + + template <class T1, class ``__Policy``> + ``__sf_result`` ellint_d(T1 k, const ``__Policy``&); + + }} // namespaces + +[heading Description] + +These two functions evaluate the incomplete elliptic integral +['D([phi], k)] and its complete counterpart ['D(k) = D([pi]/2, k)]. + +The return type of these functions is computed using the __arg_pomotion_rules +when the arguments are of different types: when they are the same type then the result +is the same type as the arguments. + + template <class T1, class T2> + ``__sf_result`` ellint_d(T1 k, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` ellint_3(T1 k, T2 phi, const ``__Policy``&); + +Returns the incomplete elliptic integral: + +[equation ellint_d] + +Requires ['-1 <= k <= 1], otherwise +returns the result of __domain_error (outside this range the result +would be complex). + +[optional_policy] + + template <class T1> + ``__sf_result`` ellint_d(T1 k); + + template <class T1, class ``__Policy``> + ``__sf_result`` ellint_d(T1 k, const ``__Policy``&); + +Returns the complete elliptic integral ['D(k) = D([pi]/2, k)] + +Requires ['-1 <= k <= 1] otherwise returns the +result of __domain_error (outside this range the result would be complex). + +[optional_policy] + +[heading Accuracy] + +These functions are trivially computed in terms of other elliptic integrals +and generally have very low error rates (a few epsilon) unless parameter [phi] +is very large, in which case the usual trigonometric function argument-reduction issues apply. + +[table_ellint_d_complete_] + +[table_ellint_d] + +[heading Testing] + +The tests use a mixture of spot test values calculated using +values calculated at wolframalpha.com, and random test data generated using +MPFR at 1000-bit precision and a deliberately naive implementation in terms of +the Legendre integrals. + +[heading Implementation] + +The implementation for D([phi], k) first performs argument reduction using the relations: + +['D(-[phi], k) = -D([phi], k)] + +and + +['D(n[pi]+[phi], k) = 2nD(k) + D([phi], k)] + +to move [phi][space] to the range \[0, [pi]\/2\]. + +The functions are then implemented in terms of Carlson's integral R[sub D] +using the relation: + +[equation ellint_d] + +[endsect] + +[section:jacobi_zeta Jacobi Zeta Function] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_zeta.hpp> +`` + + namespace boost { namespace math { + + template <class T1, class T2> + ``__sf_result`` jacobi_zeta(T1 k, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` jacobi_zeta(T1 k, T2 phi, const ``__Policy``&); + + }} // namespaces + +[heading Description] + +This function evaluates the Jacobi Zeta Function ['Z([phi], k)] + +[equation jacobi_zeta] + +The return type of this function is computed using the __arg_pomotion_rules +when the arguments are of different types: when they are the same type then the result +is the same type as the arguments. + +Requires ['-1 <= k <= 1], otherwise +returns the result of __domain_error (outside this range the result +would be complex). + +[optional_policy] + +Note that there is no complete analogue of this function (where [phi] = [pi] / 2) +as this takes the value 0 for all ['k]. + +[heading Accuracy] + +These functions are trivially computed in terms of other elliptic integrals +and generally have very low error rates (a few epsilon) unless parameter [phi] +is very large, in which case the usual trigonometric function argument-reduction issues apply. + +[table_jacobi_zeta] + +[heading Testing] + +The tests use a mixture of spot test values calculated using +values calculated at wolframalpha.com, and random test data generated using +MPFR at 1000-bit precision and a deliberately naive implementation in terms of +the Legendre integrals. + +[heading Implementation] + +The implementation for Z([phi], k) first makes the argument [phi] positive using: + +['Z(-[phi], k) = -Z([phi], k)] + +The function is then implemented in terms of Carlson's integral R[sub J] +using the relation: + +[equation jacobi_zeta] + +There is one special case where the above relation fails: when ['k = 1], in that case +the function simplifies to + +['Z([phi], 1) = sign(cos([phi])) sin([phi])] + +[endsect] + +[section:heuman_lambda Heuman Lambda Function] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/heuman_lambda.hpp> +`` + + namespace boost { namespace math { + + template <class T1, class T2> + ``__sf_result`` heuman_lambda(T1 k, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` heuman_lambda(T1 k, T2 phi, const ``__Policy``&); + + }} // namespaces + +[heading Description] + +This function evaluates the Heuman Lambda Function ['[Lambda][sub 0]([phi], k)] + +[equation heuman_lambda] + +The return type of this function is computed using the __arg_pomotion_rules +when the arguments are of different types: when they are the same type then the result +is the same type as the arguments. + +Requires ['-1 <= k <= 1], otherwise +returns the result of __domain_error (outside this range the result +would be complex). + +[optional_policy] + +Note that there is no complete analogue of this function (where [phi] = [pi] / 2) +as this takes the value 1 for all ['k]. + +[heading Accuracy] + +These functions are trivially computed in terms of other elliptic integrals +and generally have very low error rates (a few epsilon) unless parameter [phi] +is very large, in which case the usual trigonometric function argument-reduction issues apply. + +[table_heuman_lambda] + +[heading Testing] + +The tests use a mixture of spot test values calculated using +values calculated at wolframalpha.com, and random test data generated using +MPFR at 1000-bit precision and a deliberately naive implementation in terms of +the Legendre integrals. + +[heading Implementation] + +The function is then implemented in terms of Carlson's integrals R[sub J] and R[sub F] +using the relation: + +[equation heuman_lambda] + +This relation fails for ['|[phi]| >= [pi]/2] in which case the definition in terms of the +Jacobi Zeta is used. + +[endsect] + diff --git a/boost/libs/math/doc/sf/erf.qbk b/boost/libs/math/doc/sf/erf.qbk new file mode 100644 index 00000000..2051d051 --- /dev/null +++ b/boost/libs/math/doc/sf/erf.qbk @@ -0,0 +1,142 @@ +[section:error_function Error Functions] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/erf.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` erf(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` erf(T z, const ``__Policy``&); + + template <class T> + ``__sf_result`` erfc(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` erfc(T z, const ``__Policy``&); + + }} // namespaces + +The return type of these functions is computed using the __arg_promotion_rules: +the return type is `double` if T is an integer type, and T otherwise. + +[optional_policy] + +[h4 Description] + + template <class T> + ``__sf_result`` erf(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` erf(T z, const ``__Policy``&); + +Returns the [@http://en.wikipedia.org/wiki/Error_function error function] +[@http://functions.wolfram.com/GammaBetaErf/Erf/ erf] of z: + +[equation erf1] + +[graph erf] + + template <class T> + ``__sf_result`` erfc(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` erfc(T z, const ``__Policy``&); + +Returns the complement of the [@http://functions.wolfram.com/GammaBetaErf/Erfc/ error function] of z: + +[equation erf2] + +[graph erfc] + +[h4 Accuracy] + +The following table shows the peak errors (in units of epsilon) +found on various platforms with various floating point types, +along with comparisons to the __gsl, __glibc, __hpc and __cephes libraries. +Unless otherwise specified any floating point type that is narrower +than the one shown will have __zero_error. + +[table_erf] + +[table_erfc] + +[h4 Testing] + +The tests for these functions come in two parts: +basic sanity checks use spot values calculated using +[@http://functions.wolfram.com/webMathematica/FunctionEvaluation.jsp?name=Erf Mathworld's online evaluator], +while accuracy checks use high-precision test values calculated at 1000-bit precision with +[@http://shoup.net/ntl/doc/RR.txt NTL::RR] and this implementation. +Note that the generic and type-specific +versions of these functions use differing implementations internally, so this +gives us reasonably independent test data. Using our test data to test other +"known good" implementations also provides an additional sanity check. + +[h4 Implementation] + +All versions of these functions first use the usual reflection formulas +to make their arguments positive: + + erf(-z) = 1 - erf(z); + + erfc(-z) = 2 - erfc(z); // preferred when -z < -0.5 + + erfc(-z) = 1 + erf(z); // preferred when -0.5 <= -z < 0 + +The generic versions of these functions are implemented in terms of +the incomplete gamma function. + +When the significand (mantissa) size is recognised +(currently for 53, 64 and 113-bit reals, plus single-precision 24-bit handled via promotion to double) +then a series of rational approximations [jm_rationals] are used. + +For `z <= 0.5` then a rational approximation to erf is used, based on the +observation that erf is an odd function and therefore erf is calculated using: + + erf(z) = z * (C + R(z*z)); + +where the rational approximation R(z*z) is optimised for absolute error: +as long as its absolute error is small enough compared to the constant C, then any +round-off error incurred during the computation of R(z*z) will effectively +disappear from the result. As a result the error for erf and erfc in this +region is very low: the last bit is incorrect in only a very small number of +cases. + +For `z > 0.5` we observe that over a small interval \[a, b) then: + + erfc(z) * exp(z*z) * z ~ c + +for some constant c. + +Therefore for `z > 0.5` we calculate erfc using: + + erfc(z) = exp(-z*z) * (C + R(z - B)) / z; + +Again R(z - B) is optimised for absolute error, and the constant `C` is +the average of `erfc(z) * exp(z*z) * z` taken at the endpoints of the range. +Once again, as long as the absolute error in R(z - B) is small +compared to `c` then `c + R(z - B)` will be correctly rounded, and the error +in the result will depend only on the accuracy of the exp function. In practice, +in all but a very small number of cases, the error is confined to the last bit +of the result. The constant `B` is chosen so that the left hand end of the range +of the rational approximation is 0. + +For large `z` over a range \[a, +[infin]\] the above approximation is modified to: + + erfc(z) = exp(-z*z) * (C + R(1 / z)) / z; + +[endsect] +[/ :error_function The Error Functions] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/erf_inv.qbk b/boost/libs/math/doc/sf/erf_inv.qbk new file mode 100644 index 00000000..6885cf4c --- /dev/null +++ b/boost/libs/math/doc/sf/erf_inv.qbk @@ -0,0 +1,136 @@ +[section:error_inv Error Function Inverses] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/erf.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` erf_inv(T p); + + template <class T, class ``__Policy``> + ``__sf_result`` erf_inv(T p, const ``__Policy``&); + + template <class T> + ``__sf_result`` erfc_inv(T p); + + template <class T, class ``__Policy``> + ``__sf_result`` erfc_inv(T p, const ``__Policy``&); + + }} // namespaces + +The return type of these functions is computed using the __arg_promotion_rules: +the return type is `double` if T is an integer type, and T otherwise. + +[optional_policy] + +[h4 Description] + + template <class T> + ``__sf_result`` erf_inv(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` erf_inv(T z, const ``__Policy``&); + +Returns the [@http://functions.wolfram.com/GammaBetaErf/InverseErf/ inverse error function] +of z, that is a value x such that: + + p = erf(x); + +[graph erf_inv] + + template <class T> + ``__sf_result`` erfc_inv(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` erfc_inv(T z, const ``__Policy``&); + +Returns the inverse of the complement of the error function of z, that is a +value x such that: + + p = erfc(x); + +[graph erfc_inv] + +[h4 Accuracy] + +For types up to and including 80-bit long doubles the approximations used +are accurate to less than ~ 2 epsilon. For higher precision types these +functions have the same accuracy as the +[link math_toolkit.sf_erf.error_function forward error functions]. + +[table_erf_inv] + +[table_erfc_inv] + +[h4 Testing] + +There are two sets of tests: + +* Basic sanity checks attempt to "round-trip" from +/x/ to /p/ and back again. These tests have quite +generous tolerances: in general both the error functions and their +inverses change so rapidly in some places that round tripping to more than a couple +of significant digits isn't possible. This is especially true when +/p/ is very near one: in this case there isn't enough +"information content" in the input to the inverse function to get +back where you started. +* Accuracy checks using high-precision test values. These measure +the accuracy of the result, given /exact/ input values. + +[h4 Implementation] + +These functions use a rational approximation [jm_rationals] +to calculate an initial +approximation to the result that is accurate to ~10[super -19], +then only if that has insufficient accuracy compared to the epsilon for T, +do we clean up the result using +[@http://en.wikipedia.org/wiki/Simple_rational_approximation Halley iteration]. + +Constructing rational approximations to the erf/erfc functions is actually +surprisingly hard, especially at high precision. For this reason no attempt +has been made to achieve 10[super -34 ] accuracy suitable for use with 128-bit +reals. + +In the following discussion, /p/ is the value passed to erf_inv, and /q/ is +the value passed to erfc_inv, so that /p = 1 - q/ and /q = 1 - p/ and in both +cases we want to solve for the same result /x/. + +For /p < 0.5/ the inverse erf function is reasonably smooth and the approximation: + + x = p(p + 10)(Y + R(p)) + +Gives a good result for a constant Y, and R(p) optimised for low absolute error +compared to |Y|. + +For q < 0.5 things get trickier, over the interval /0.5 > q > 0.25/ +the following approximation works well: + + x = sqrt(-2log(q)) / (Y + R(q)) + +While for q < 0.25, let + + z = sqrt(-log(q)) + +Then the result is given by: + + x = z(Y + R(z - B)) + +As before Y is a constant and the rational function R is optimised for low +absolute error compared to |Y|. B is also a constant: it is the smallest value +of /z/ for which each approximation is valid. There are several approximations +of this form each of which reaches a little further into the tail of the erfc +function (at `long double` precision the extended exponent range compared to +`double` means that the tail goes on for a very long way indeed). + +[endsect][/ :error_inv The Error Function Inverses] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/expint.qbk b/boost/libs/math/doc/sf/expint.qbk new file mode 100644 index 00000000..945354e6 --- /dev/null +++ b/boost/libs/math/doc/sf/expint.qbk @@ -0,0 +1,217 @@ +[section:expint Exponential Integrals] + +[section:expint_n Exponential Integral En] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/expint.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` expint(unsigned n, T z); + + template <class T, class ``__Policy``> + ``__sf_result`` expint(unsigned n, T z, const ``__Policy``&); + + }} // namespaces + +The return type of these functions is computed using the __arg_promotion_rules: +the return type is `double` if T is an integer type, and T otherwise. + +[optional_policy] + +[h4 Description] + + template <class T> + ``__sf_result`` expint(unsigned n, T z); + + template <class T, class ``__Policy``> + ``__sf_result`` expint(unsigned n, T z, const ``__Policy``&); + +Returns the [@http://mathworld.wolfram.com/En-Function.html exponential integral En] +of z: + +[equation expint_n_1] + +[graph expint2] + +[h4 Accuracy] + +The following table shows the peak errors (in units of epsilon) +found on various platforms with various floating point types, +along with comparisons to other libraries. +Unless otherwise specified any floating point type that is narrower +than the one shown will have __zero_error. + +[table_expint_En_] + +[h4 Testing] + +The tests for these functions come in two parts: +basic sanity checks use spot values calculated using +[@http://functions.wolfram.com/webMathematica/FunctionEvaluation.jsp?name=ExpIntegralE Mathworld's online evaluator], +while accuracy checks use high-precision test values calculated at 1000-bit precision with +[@http://shoup.net/ntl/doc/RR.txt NTL::RR] and this implementation. +Note that the generic and type-specific +versions of these functions use differing implementations internally, so this +gives us reasonably independent test data. Using our test data to test other +"known good" implementations also provides an additional sanity check. + +[h4 Implementation] + +The generic version of this function uses the continued fraction: + +[equation expint_n_3] + +for large /x/ and the infinite series: + +[equation expint_n_2] + +for small /x/. + +Where the precision of /x/ is known at compile time and is 113 bits or fewer +in precision, then rational approximations [jm_rationals] are used for the +`n == 1` case. + +For `x < 1` the approximating form is a minimax approximation: + +[equation expint_n_4] + +and for `x > 1` a Chebyshev interpolated approximation of the form: + +[equation expint_n_5] + +is used. + + +[endsect] + +[section:expint_i Exponential Integral Ei] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/expint.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` expint(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` expint(T z, const ``__Policy``&); + + }} // namespaces + +The return type of these functions is computed using the __arg_promotion_rules: +the return type is `double` if T is an integer type, and T otherwise. + +[optional_policy] + +[h4 Description] + + template <class T> + ``__sf_result`` expint(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` expint(T z, const ``__Policy``&); + +Returns the [@http://mathworld.wolfram.com/ExponentialIntegral.html exponential integral] +of z: + +[equation expint_i_1] + +[graph expint_i] + +[h4 Accuracy] + +The following table shows the peak errors (in units of epsilon) +found on various platforms with various floating point types, +along with comparisons to Cody's SPECFUN implementation and the __gsl library. +Unless otherwise specified any floating point type that is narrower +than the one shown will have __zero_error. + +[table_expint_Ei_] + +It should be noted that all three libraries tested above +offer sub-epsilon precision over most of their range. + +GSL has the greatest difficulty near the positive root of En, while +Cody's SPECFUN along with this implementation increase their +error rates very slightly over the range \[4,6\]. + +[h4 Testing] + +The tests for these functions come in two parts: +basic sanity checks use spot values calculated using +[@http://functions.wolfram.com/webMathematica/FunctionEvaluation.jsp?name=ExpIntegralEi Mathworld's online evaluator], +while accuracy checks use high-precision test values calculated at 1000-bit precision with +[@http://shoup.net/ntl/doc/RR.txt NTL::RR] and this implementation. +Note that the generic and type-specific +versions of these functions use differing implementations internally, so this +gives us reasonably independent test data. Using our test data to test other +"known good" implementations also provides an additional sanity check. + +[h4 Implementation] + +For x < 0 this function just calls __expint_n(1, -x): which in turn is implemented +in terms of rational approximations when the type of x has 113 or fewer bits of +precision. + +For x > 0 the generic version is implemented using the infinte series: + +[equation expint_i_2] + +However, when the precision of the argument type is known at compile time +and is 113 bits or less, then rational approximations [jm_rationals] are used. + +For 0 < z < 6 a root-preserving approximation of the form: + +[equation expint_i_3] + +is used, where z[sub 0] is the positive root of the function, and +R(z/3 - 1) is a minimax rational approximation rescaled so that +it is evaluated over \[-1,1\]. Note that while the rational approximation +over \[0,6\] converges rapidly to the minimax solution it is rather +ill-conditioned in practice. Cody and Thacher +[footnote W. J. Cody and H. C. Thacher, Jr., +Rational Chebyshev approximations for the exponential integral E[sub 1](x), +Math. Comp. 22 (1968), 641-649, +and W. J. Cody and H. C. Thacher, Jr., Chebyshev approximations for the +exponential integral Ei(x), Math. Comp. 23 (1969), 289-303.] +experienced the same issue and +converted the polynomials into Chebeshev form to ensure stable +computation. By experiment we found that the polynomials are just as stable +in polynomial as Chebyshev form, /provided/ they are computed +over the interval \[-1,1\]. + +Over the a series of intervals [a,b] and [b,INF] the rational approximation +takes the form: + +[equation expint_i_4] + +where /c/ is a constant, and R(t) is a minimax solution optimised for low +absolute error compared to /c/. Variable /t/ is `1/z` when the range in infinite +and `2z/(b-a) - (2a/(b-a) + 1)` otherwise: this has the effect of scaling z to the +interval \[-1,1\]. As before rational approximations over arbitrary intervals +were found to be ill-conditioned: Cody and Thacher solved this issue by +converting the polynomials to their J-Fraction equivalent. However, as long +as the interval of evaluation was \[-1,1\] and the number of terms carefully chosen, +it was found that the polynomials /could/ be evaluated to suitable precision: +error rates are typically 2 to 3 epsilon which is comparible to the error +rate that Cody and Thacher achieved using J-Fractions, but marginally more +efficient given that fewer divisions are involved. + +[endsect] +[endsect] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/factorials.qbk b/boost/libs/math/doc/sf/factorials.qbk new file mode 100644 index 00000000..792aff35 --- /dev/null +++ b/boost/libs/math/doc/sf/factorials.qbk @@ -0,0 +1,374 @@ +[section:factorials Factorials and Binomial Coefficients] + +[section:sf_factorial Factorial] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/factorials.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + T factorial(unsigned i); + + template <class T, class ``__Policy``> + T factorial(unsigned i, const ``__Policy``&); + + template <class T> + T unchecked_factorial(unsigned i); + + template <class T> + struct max_factorial; + + }} // namespaces + +[h4 Description] + +[important +The functions described below are templates where the template argument T CANNOT be deduced from the +arguments passed to the function. Therefore if you write something like: + + `boost::math::factorial(2);` + +You will get a (perhaps perplexing) compiler error, ususally indicating that there is no such function to be found. +Instead you need to specify the return type explicity and write: + + `boost::math::factorial<double>(2);` + +So that the return type is known. + +Furthermore, the template argument must be a real-valued type such as `float` or `double` +and not an integer type - that would overflow far too easily for quite small values of parameter `i`! + +The source code `static_assert` and comment just after the will be: + +`` + BOOST_STATIC_ASSERT(!boost::is_integral<T>::value); + // factorial<unsigned int>(n) is not implemented + // because it would overflow integral type T for too small n + // to be useful. Use instead a floating-point type, + // and convert to an unsigned type if essential, for example: + // unsigned int nfac = static_cast<unsigned int>(factorial<double>(n)); + // See factorial documentation for more detail. +`` +] + + template <class T> + T factorial(unsigned i); + + template <class T, class ``__Policy``> + T factorial(unsigned i, const ``__Policy``&); + +Returns [^i!]. + +[optional_policy] + +For [^i <= max_factorial<T>::value] this is implemented by table lookup, +for larger values of [^i], this function is implemented in terms of __tgamma. + +If [^i] is so large that the result can not be represented in type T, then +calls __overflow_error. + + template <class T> + T unchecked_factorial(unsigned i); + +Returns [^i!]. + +Internally this function performs table lookup of the result. Further it performs +no range checking on the value of i: it is up to the caller to ensure +that [^i <= max_factorial<T>::value]. This function is intended to be used +inside inner loops that require fast table lookup of factorials, but requires +care to ensure that argument [^i] never grows too large. + + template <class T> + struct max_factorial + { + static const unsigned value = X; + }; + +This traits class defines the largest value that can be passed to +[^unchecked_factorial]. The member `value` can be used where integral +constant expressions are required: for example to define the size of +further tables that depend on the factorials. + +[h4 Accuracy] + +For arguments smaller than `max_factorial<T>::value` +the result should be +correctly rounded. For larger arguments the accuracy will be the same +as for __tgamma. + +[h4 Testing] + +Basic sanity checks and spot values to verify the data tables: +the main tests for the __tgamma function handle those cases already. + +[h4 Implementation] + +The factorial function is table driven for small arguments, and is +implemented in terms of __tgamma for larger arguments. + +[endsect] + +[section:sf_double_factorial Double Factorial] + +`` +#include <boost/math/special_functions/factorials.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + T double_factorial(unsigned i); + + template <class T, class ``__Policy``> + T double_factorial(unsigned i, const ``__Policy``&); + + }} // namespaces + +Returns [^i!!]. + +[optional_policy] + +May return the result of __overflow_error if the result is too large +to represent in type T. The implementation is designed to be optimised +for small /i/ where table lookup of i! is possible. + +[important +The functions described above are templates where the template argument T can not be deduced from the +arguments passed to the function. Therefore if you write something like: + + `boost::math::double_factorial(2);` + +You will get a (possibly perplexing) compiler error, ususally indicating that there is no such function to be found. Instead you need to specifiy +the return type explicity and write: + + `boost::math::double_factorial<double>(2);` + +So that the return type is known. Further, the template argument must be a real-valued type such as `float` or `double` +and not an integer type - that would overflow far too easily! + +The source code `static_assert` and comment just after the will be: + +`` + BOOST_STATIC_ASSERT(!boost::is_integral<T>::value); + // factorial<unsigned int>(n) is not implemented + // because it would overflow integral type T for too small n + // to be useful. Use instead a floating-point type, + // and convert to an unsigned type if essential, for example: + // unsigned int nfac = static_cast<unsigned int>(factorial<double>(n)); + // See factorial documentation for more detail. +`` +] + +[note The argument to `double_factorial` is type `unsigned` even though technically -1!! is defined.] + +[h4 Accuracy] + +The implementation uses a trivial adaptation of +the factorial function, so error rates should be no more than a couple +of epsilon higher. + +[h4 Testing] + +The spot tests for the double factorial use data +generated by functions.wolfram.com. + +[h4 Implementation] + +The double factorial is implemented in terms of the factorial and gamma +functions using the relations: + +(2n)!! = 2[super n ] * n! + +(2n+1)!! = (2n+1)! / (2[super n ] n!) + +and + +(2n-1)!! = [Gamma]((2n+1)/2) * 2[super n ] / sqrt(pi) + +[endsect] + +[section:sf_rising_factorial Rising Factorial] + +`` +#include <boost/math/special_functions/factorials.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` rising_factorial(T x, int i); + + template <class T, class ``__Policy``> + ``__sf_result`` rising_factorial(T x, int i, const ``__Policy``&); + + }} // namespaces + +Returns the rising factorial of /x/ and /i/: + +rising_factorial(x, i) = [Gamma](x + i) / [Gamma](x); + +or + +rising_factorial(x, i) = x(x+1)(x+2)(x+3)...(x+i-1) + +Note that both /x/ and /i/ can be negative as well as positive. + +[optional_policy] + +May return the result of __overflow_error if the result is too large +to represent in type T. + +The return type of these functions is computed using the __arg_promotion_rules: +the type of the result is `double` if T is an integer type, otherwise the type +of the result is T. + +[h4 Accuracy] + +The accuracy will be the same as +the __tgamma_delta_ratio function. + +[h4 Testing] + +The spot tests for the rising factorials use data generated +by functions.wolfram.com. + +[h4 Implementation] + +Rising and falling factorials are implemented as ratios of gamma functions +using __tgamma_delta_ratio. Optimisations for +small integer arguments are handled internally by that function. + +[endsect] + +[section:sf_falling_factorial Falling Factorial] + +`` +#include <boost/math/special_functions/factorials.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` falling_factorial(T x, unsigned i); + + template <class T, class ``__Policy``> + ``__sf_result`` falling_factorial(T x, unsigned i, const ``__Policy``&); + + }} // namespaces + +Returns the falling factorial of /x/ and /i/: + +falling_factorial(x, i) = x(x-1)(x-2)(x-3)...(x-i+1) + +Note that this function is only defined for positive /i/, hence the +`unsigned` second argument. Argument /x/ can be either positive or +negative however. + +[optional_policy] + +May return the result of __overflow_error if the result is too large +to represent in type T. + +The return type of these functions is computed using the __arg_promotion_rules: +the type of the result is `double` if T is an integer type, otherwise the type +of the result is T. + +[h4 Accuracy] + +The accuracy will be the same as +the __tgamma_delta_ratio function. + +[h4 Testing] + +The spot tests for the falling factorials use data generated by +functions.wolfram.com. + +[h4 Implementation] + +Rising and falling factorials are implemented as ratios of gamma functions +using __tgamma_delta_ratio. Optimisations for +small integer arguments are handled internally by that function. + +[endsect] + +[section:sf_binomial Binomial Coefficients] + +`` +#include <boost/math/special_functions/binomial.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + T binomial_coefficient(unsigned n, unsigned k); + + template <class T, class ``__Policy``> + T binomial_coefficient(unsigned n, unsigned k, const ``__Policy``&); + + }} // namespaces + +Returns the binomial coefficient: [sub n]C[sub k]. + +Requires k <= n. + +[optional_policy] + +May return the result of __overflow_error if the result is too large +to represent in type T. + +[important +The functions described above are templates where the template argument T can not be deduced from the +arguments passed to the function. Therefore if you write something like: + + `boost::math::binomial_coefficient(10, 2);` + +You will get a compiler error, ususally indicating that there is no such function to be found. Instead you need to specifiy +the return type explicity and write: + + `boost::math::binomial_coefficient<double>(10, 2);` + +So that the return type is known. Further, the template argument must be a real-valued type such as `float` or `double` +and not an integer type - that would overflow far too easily! +] + +[h4 Accuracy] + +The accuracy will be the same as for the +factorials for small arguments (i.e. no more than one or two epsilon), +and the __beta function for larger arguments. + +[h4 Testing] + +The spot tests for the binomial coefficients use data +generated by functions.wolfram.com. + +[h4 Implementation] + +Binomial coefficients are calculated using table lookup of factorials +where possible using: + +[sub n]C[sub k] = n! / (k!(n-k)!) + +Otherwise it is implemented in terms of the beta function using the relations: + +[sub n]C[sub k] = 1 / (k * __beta(k, n-k+1)) + +and + +[sub n]C[sub k] = 1 / ((n-k) * __beta(k+1, n-k)) + +[endsect] + + +[endsect][/section:factorials Factorials] + +[/ + Copyright 2006, 2010 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/gamma_derivatives.qbk b/boost/libs/math/doc/sf/gamma_derivatives.qbk new file mode 100644 index 00000000..f2323610 --- /dev/null +++ b/boost/libs/math/doc/sf/gamma_derivatives.qbk @@ -0,0 +1,54 @@ +[section:gamma_derivatives Derivative of the Incomplete Gamma Function] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/gamma.hpp> +`` + + namespace boost{ namespace math{ + + template <class T1, class T2> + ``__sf_result`` gamma_p_derivative(T1 a, T2 x); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_p_derivative(T1 a, T2 x, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +This function find some uses in statistical distributions: it +implements the partial derivative with respect to /x/ of the incomplete +gamma function. + +[equation derivative1] + +[optional_policy] + +Note that the derivative of the function __gamma_q can be obtained by negating +the result of this function. + +The return type of this function is computed using the __arg_promotion_rules +when T1 and T2 are different types, otherwise the return type is simply T1. + +[h4 Accuracy] + +Almost identical to the incomplete gamma function __gamma_p: refer to +the documentation for that function for more information. + +[h4 Implementation] + +This function just expose some of the internals of the incomplete +gamma function __gamma_p: refer to the documentation for that function +for more information. + +[endsect][/section Derivative of the Incomplete Gamma Functions] +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + + diff --git a/boost/libs/math/doc/sf/gamma_ratios.qbk b/boost/libs/math/doc/sf/gamma_ratios.qbk new file mode 100644 index 00000000..c76a3c92 --- /dev/null +++ b/boost/libs/math/doc/sf/gamma_ratios.qbk @@ -0,0 +1,98 @@ +[section:gamma_ratios Ratios of Gamma Functions] + +`` +#include <boost/math/special_functions/gamma.hpp> +`` + + namespace boost{ namespace math{ + + template <class T1, class T2> + ``__sf_result`` tgamma_ratio(T1 a, T2 b); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` tgamma_ratio(T1 a, T2 b, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` tgamma_delta_ratio(T1 a, T2 delta); + + template <class T1, class T2, class Policy> + ``__sf_result`` tgamma_delta_ratio(T1 a, T2 delta, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + + template <class T1, class T2> + ``__sf_result`` tgamma_ratio(T1 a, T2 b); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` tgamma_ratio(T1 a, T2 b, const ``__Policy``&); + +Returns the ratio of gamma functions: + +[equation gamma_ratio0] + +[optional_policy] + +Internally this just calls `tgamma_delta_ratio(a, b-a)`. + + template <class T1, class T2> + ``__sf_result`` tgamma_delta_ratio(T1 a, T2 delta); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` tgamma_delta_ratio(T1 a, T2 delta, const ``__Policy``&); + +Returns the ratio of gamma functions: + +[equation gamma_ratio1] + +[optional_policy] + +Note that the result is calculated accurately even when /delta/ is +small compared to /a/: indeed even if /a+delta ~ a/. The function is +typically used when /a/ is large and /delta/ is very small. + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types, otherwise the result type is simple T1. + +[graph tgamma_delta_ratio] + +[h4 Accuracy] + +The following table shows the peak errors (in units of epsilon) +found on various platforms with various floating point types. +Unless otherwise specified any floating point type that is narrower +than the one shown will have __zero_error. + +[table_tgamma_delta_ratio] + +[table_tgamma_ratio] + +[h4 Testing] + +Accuracy tests use data generated at very high precision +(with [@http://shoup.net/ntl/doc/RR.txt NTL RR class] +set at 1000-bit precision: about 300 decimal digits) +and a deliberately naive calculation of [Gamma](x)/[Gamma](y). + +[h4 Implementation] + +The implementation of these functions is very similar to that of +__beta, and is based on combining similar power terms +to improve accuracy and avoid spurious overflow/underflow. + +In addition there are optimisations for the situation where /delta/ +is a small integer: in which case this function is basically +the reciprocal of a rising factorial, or where both arguments +are smallish integers: in which case table lookup of factorials +can be used to calculate the ratio. + +[endsect][/section:gamma_ratios Ratios of Gamma Functions] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/hankel.qbk b/boost/libs/math/doc/sf/hankel.qbk new file mode 100644 index 00000000..b487ea67 --- /dev/null +++ b/boost/libs/math/doc/sf/hankel.qbk @@ -0,0 +1,136 @@ + +[section:hankel Hankel Functions] +[section:cyl_hankel Cyclic Hankel Functions] + +[h4 Synopsis] + + template <class T1, class T2> + std::complex<``__sf_result``> cyl_hankel_1(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + std::complex<``__sf_result``> cyl_hankel_1(T1 v, T2 x, const ``__Policy``&); + + template <class T1, class T2> + std::complex<``__sf_result``> cyl_hankel_2(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + std::complex<``__sf_result``> cyl_hankel_2(T1 v, T2 x, const ``__Policy``&); + + +[h4 Description] + +The functions __cyl_hankel_1 and __cyl_hankel_2 return the result of the +[@http://dlmf.nist.gov/10.2#P3 Hankel functions] of the first and second kind respectively: + +[:['cyl_hankel_1(v, x) = H[sub v][super (1)](x) = J[sub v](x) + i Y[sub v](x)]] + +[:['cyl_hankel_2(v, x) = H[sub v][super (2)](x) = J[sub v](x) - i Y[sub v](x)]] + +where: + +['J[sub v](x)] is the Bessel function of the first kind, and ['Y[sub v](x)] is the Bessel function of the second kind. + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types. The functions are also optimised for the +relatively common case that T1 is an integer. + +[optional_policy] + +Note that while the arguments to these functions are real values, the results are complex. +That means that the functions can only be instantiated on types `float`, `double` and `long double`. +The functions have also been extended to operate over the whole range of ['v] and ['x] +(unlike __cyl_bessel_j and __cyl_neumann). + +[h4 Performance] + +These functions are generally more efficient than two separate calls to the underlying Bessel +functions as internally Bessel J and Y can be computed simultaneously. + +[h4 Testing] + +There are just a few spot tests to exercise all the special case handling - the bulk of the testing is done +on the Bessel functions upon which these are based. + +[h4 Accuracy] + +Refer to __cyl_bessel_j and __cyl_neumann. + +[h4 Implementation] + +For ['x < 0] the following reflection formulae are used: + +[@http://functions.wolfram.com/Bessel-TypeFunctions/BesselJ/16/01/01/ [equation hankel1]] + +[@http://functions.wolfram.com/Bessel-TypeFunctions/BesselY/16/01/01/ [equation hankel2]] + +[@http://functions.wolfram.com/Bessel-TypeFunctions/BesselY/16/01/01/ [equation hankel3]] + +Otherwise the implementation is trivially in terms of the Bessel J and Y functions. + +Note however, that the Hankel functions compute the Bessel J and Y functions simultaneously, +and therefore a single Hankel function call is more efficient than two Bessel function calls. +The one exception is when ['v] is a small positive integer, in which case the usual Bessel function +routines for integer order are used. + +[endsect] + + +[section:sph_hankel Spherical Hankel Functions] + +[h4 Synopsis] + + template <class T1, class T2> + std::complex<``__sf_result``> sph_hankel_1(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + std::complex<``__sf_result``> sph_hankel_1(T1 v, T2 x, const ``__Policy``&); + + template <class T1, class T2> + std::complex<``__sf_result``> sph_hankel_2(T1 v, T2 x); + + template <class T1, class T2, class ``__Policy``> + std::complex<``__sf_result``> sph_hankel_2(T1 v, T2 x, const ``__Policy``&); + + +[h4 Description] + +The functions __sph_hankel_1 and __sph_hankel_2 return the result of the +[@http://dlmf.nist.gov/10.47#P1 spherical Hankel functions] of the first and second kind respectively: + +[equation hankel4] + +[equation hankel5] + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types. The functions are also optimised for the +relatively common case that T1 is an integer. + +[optional_policy] + +Note that while the arguments to these functions are real values, the results are complex. +That means that the functions can only be instantiated on types `float`, `double` and `long double`. +The functions have also been extended to operate over the whole range of ['v] and ['x] +(unlike __cyl_bessel_j and __cyl_neumann). + +[h4 Testing] + +There are just a few spot tests to exercise all the special case handling - the bulk of the testing is done +on the Bessel functions upon which these are based. + +[h4 Accuracy] + +Refer to __cyl_bessel_j and __cyl_neumann. + +[h4 Implementation] + +These functions are trivially implemented in terms of __cyl_hankel_1 and __cyl_hankel_2. + +[endsect] +[endsect] + +[/ + Copyright 2012 John Maddock. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/hermite.qbk b/boost/libs/math/doc/sf/hermite.qbk new file mode 100644 index 00000000..c88aadc3 --- /dev/null +++ b/boost/libs/math/doc/sf/hermite.qbk @@ -0,0 +1,107 @@ +[section:hermite Hermite Polynomials] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/hermite.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` hermite(unsigned n, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` hermite(unsigned n, T x, const ``__Policy``&); + + template <class T1, class T2, class T3> + ``__sf_result`` hermite_next(unsigned n, T1 x, T2 Hn, T3 Hnm1); + + }} // namespaces + +[h4 Description] + +The return type of these functions is computed using the __arg_promotion_rules: +note than when there is a single template argument the result is the same type +as that argument or `double` if the template argument is an integer type. + + template <class T> + ``__sf_result`` hermite(unsigned n, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` hermite(unsigned n, T x, const ``__Policy``&); + +Returns the value of the Hermite Polynomial of order /n/ at point /x/: + +[equation hermite_0] + +[optional_policy] + +The following graph illustrates the behaviour of the first few +Hermite Polynomials: + +[graph hermite] + + template <class T1, class T2, class T3> + ``__sf_result`` hermite_next(unsigned n, T1 x, T2 Hn, T3 Hnm1); + +Implements the three term recurrence relation for the Hermite +polynomials, this function can be used to create a sequence of +values evaluated at the same /x/, and for rising /n/. + +[equation hermite_1] + +For example we could produce a vector of the first 10 polynomial +values using: + + double x = 0.5; // Abscissa value + vector<double> v; + v.push_back(hermite(0, x)).push_back(hermite(1, x)); + for(unsigned l = 1; l < 10; ++l) + v.push_back(hermite_next(l, x, v[l], v[l-1])); + +Formally the arguments are: + +[variablelist +[[n][The degree /n/ of the last polynomial calculated.]] +[[x][The abscissa value]] +[[Hn][The value of the polynomial evaluated at degree /n/.]] +[[Hnm1][The value of the polynomial evaluated at degree /n-1/.]] +] + +[h4 Accuracy] + +The following table shows peak errors (in units of epsilon) +for various domains of input arguments. +Note that only results for the widest floating point type on the system are +given as narrower types have __zero_error. + +[table_hermite] + +Note that the worst errors occur when the degree increases, values greater than +~120 are very unlikely to produce sensible results, especially in the associated +polynomial case when the order is also large. Further the relative errors +are likely to grow arbitrarily large when the function is very close to a root. + +[h4 Testing] + +A mixture of spot tests of values calculated using functions.wolfram.com, +and randomly generated test data are +used: the test data was computed using +[@http://shoup.net/ntl/doc/RR.txt NTL::RR] at 1000-bit precision. + +[h4 Implementation] + +These functions are implemented using the stable three term +recurrence relations. These relations guarantee low absolute error +but cannot guarantee low relative error near one of the roots of the +polynomials. + +[endsect][/section:beta_function The Beta Function] +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/ibeta.qbk b/boost/libs/math/doc/sf/ibeta.qbk new file mode 100644 index 00000000..b4a20f92 --- /dev/null +++ b/boost/libs/math/doc/sf/ibeta.qbk @@ -0,0 +1,202 @@ +[section:ibeta_function Incomplete Beta Functions] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/beta.hpp> +`` + + namespace boost{ namespace math{ + + template <class T1, class T2, class T3> + ``__sf_result`` ibeta(T1 a, T2 b, T3 x); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibeta(T1 a, T2 b, T3 x, const ``__Policy``&); + + template <class T1, class T2, class T3> + ``__sf_result`` ibetac(T1 a, T2 b, T3 x); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibetac(T1 a, T2 b, T3 x, const ``__Policy``&); + + template <class T1, class T2, class T3> + ``__sf_result`` beta(T1 a, T2 b, T3 x); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` beta(T1 a, T2 b, T3 x, const ``__Policy``&); + + template <class T1, class T2, class T3> + ``__sf_result`` betac(T1 a, T2 b, T3 x); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` betac(T1 a, T2 b, T3 x, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +There are four [@http://en.wikipedia.org/wiki/Incomplete_beta_function incomplete beta functions] +: two are normalised versions (also known as ['regularized] beta functions) +that return values in the range [0, 1], and two are non-normalised and +return values in the range [0, __beta(a, b)]. Users interested in statistical +applications should use the normalised (or +[@http://mathworld.wolfram.com/RegularizedBetaFunction.html regularized] +) versions (ibeta and ibetac). + +All of these functions require /0 <= x <= 1/. + +The normalized functions __ibeta and __ibetac require /a,b >= 0/, and in addition that +not both /a/ and /b/ are zero. + +The functions __beta and __betac require /a,b > 0/. + +The return type of these functions is computed using the __arg_promotion_rules +when T1, T2 and T3 are different types. + +[optional_policy] + + template <class T1, class T2, class T3> + ``__sf_result`` ibeta(T1 a, T2 b, T3 x); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibeta(T1 a, T2 b, T3 x, const ``__Policy``&); + +Returns the normalised incomplete beta function of a, b and x: + +[equation ibeta3] + +[graph ibeta] + + template <class T1, class T2, class T3> + ``__sf_result`` ibetac(T1 a, T2 b, T3 x); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibetac(T1 a, T2 b, T3 x, const ``__Policy``&); + +Returns the normalised complement of the incomplete beta function of a, b and x: + +[equation ibeta4] + + template <class T1, class T2, class T3> + ``__sf_result`` beta(T1 a, T2 b, T3 x); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` beta(T1 a, T2 b, T3 x, const ``__Policy``&); + +Returns the full (non-normalised) incomplete beta function of a, b and x: + +[equation ibeta1] + + template <class T1, class T2, class T3> + ``__sf_result`` betac(T1 a, T2 b, T3 x); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` betac(T1 a, T2 b, T3 x, const ``__Policy``&); + +Returns the full (non-normalised) complement of the incomplete beta function of a, b and x: + +[equation ibeta2] + +[h4 Accuracy] + +The following tables give peak and mean relative errors in over various domains of +a, b and x, along with comparisons to the __gsl and __cephes libraries. +Note that only results for the widest floating-point type on the system are given as +narrower types have __zero_error. + +Note that the results for 80 and 128-bit long doubles are noticeably higher than +for doubles: this is because the wider exponent range of these types allow +more extreme test cases to be tested. For example expected results that +are zero at double precision, may be finite but exceptionally small with +the wider exponent range of the long double types. + +[table_ibeta] + +[table_ibetac] + +[table_beta_incomplete_] + +[table_betac] + +[h4 Testing] + +There are two sets of tests: spot tests compare values taken from +[@http://functions.wolfram.com/webMathematica/FunctionEvaluation.jsp?name=BetaRegularized Mathworld's online function evaluator] +with this implementation: they provide a basic "sanity check" +for the implementation, with one spot-test in each implementation-domain +(see implementation notes below). + +Accuracy tests use data generated at very high precision +(with [@http://shoup.net/ntl/doc/RR.txt NTL RR class] set at 1000-bit precision), +using the "textbook" continued fraction representation (refer to the first continued +fraction in the implementation discussion below). +Note that this continued fraction is /not/ used in the implementation, +and therefore we have test data that is fully independent of the code. + +[h4 Implementation] + +This implementation is closely based upon +[@http://portal.acm.org/citation.cfm?doid=131766.131776 "Algorithm 708; Significant digit computation of the incomplete beta function ratios", DiDonato and Morris, ACM, 1992.] + +All four of these functions share a common implementation: this is passed both +x and y, and can return either p or q where these are related by: + +[equation ibeta_inv5] + +so at any point we can swap a for b, x for y and p for q if this results in +a more favourable position. Generally such swaps are performed so that we always +compute a value less than 0.9: when required this can then be subtracted from 1 +without undue cancellation error. + +The following continued fraction representation is found in many textbooks +but is not used in this implementation - it's both slower and less accurate than +the alternatives - however it is used to generate test data: + +[equation ibeta5] + +The following continued fraction is due to [@http://portal.acm.org/citation.cfm?doid=131766.131776 Didonato and Morris], +and is used in this implementation when a and b are both greater than 1: + +[equation ibeta6] + +For smallish b and x then a series representation can be used: + +[equation ibeta7] + +When b << a then the transition from 0 to 1 occurs very close to x = 1 +and some care has to be taken over the method of computation, in that case +the following series representation is used: + +[equation ibeta8] +[/[equation ibeta9]] + +Where Q(a,x) is an [@http://functions.wolfram.com/GammaBetaErf/Gamma2/ incomplete gamma function]. +Note that this method relies +on keeping a table of all the p[sub n ] previously computed, which does limit +the precision of the method, depending upon the size of the table used. + +When /a/ and /b/ are both small integers, then we can relate the incomplete +beta to the binomial distribution and use the following finite sum: + +[equation ibeta12] + +Finally we can sidestep difficult areas, or move to an area with a more +efficient means of computation, by using the duplication formulae: + +[equation ibeta10] + +[equation ibeta11] + +The domains of a, b and x for which the various methods are used are identical +to those described in the +[@http://portal.acm.org/citation.cfm?doid=131766.131776 Didonato and Morris TOMS 708 paper]. + +[endsect][/section:ibeta_function The Incomplete Beta Function] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/ibeta_inv.qbk b/boost/libs/math/doc/sf/ibeta_inv.qbk new file mode 100644 index 00000000..684d3dcb --- /dev/null +++ b/boost/libs/math/doc/sf/ibeta_inv.qbk @@ -0,0 +1,368 @@ +[section:ibeta_inv_function The Incomplete Beta Function Inverses] + +`` +#include <boost/math/special_functions/beta.hpp> +`` + + namespace boost{ namespace math{ + + template <class T1, class T2, class T3> + ``__sf_result`` ibeta_inv(T1 a, T2 b, T3 p); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibeta_inv(T1 a, T2 b, T3 p, const ``__Policy``&); + + template <class T1, class T2, class T3, class T4> + ``__sf_result`` ibeta_inv(T1 a, T2 b, T3 p, T4* py); + + template <class T1, class T2, class T3, class T4, class ``__Policy``> + ``__sf_result`` ibeta_inv(T1 a, T2 b, T3 p, T4* py, const ``__Policy``&); + + template <class T1, class T2, class T3> + ``__sf_result`` ibetac_inv(T1 a, T2 b, T3 q); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibetac_inv(T1 a, T2 b, T3 q, const ``__Policy``&); + + template <class T1, class T2, class T3, class T4> + ``__sf_result`` ibetac_inv(T1 a, T2 b, T3 q, T4* py); + + template <class T1, class T2, class T3, class T4, class ``__Policy``> + ``__sf_result`` ibetac_inv(T1 a, T2 b, T3 q, T4* py, const ``__Policy``&); + + template <class T1, class T2, class T3> + ``__sf_result`` ibeta_inva(T1 b, T2 x, T3 p); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibeta_inva(T1 b, T2 x, T3 p, const ``__Policy``&); + + template <class T1, class T2, class T3> + ``__sf_result`` ibetac_inva(T1 b, T2 x, T3 q); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibetac_inva(T1 b, T2 x, T3 q, const ``__Policy``&); + + template <class T1, class T2, class T3> + ``__sf_result`` ibeta_invb(T1 a, T2 x, T3 p); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibeta_invb(T1 a, T2 x, T3 p, const ``__Policy``&); + + template <class T1, class T2, class T3> + ``__sf_result`` ibetac_invb(T1 a, T2 x, T3 q); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibetac_invb(T1 a, T2 x, T3 q, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + + +There are six [@http://functions.wolfram.com/GammaBetaErf/ incomplete beta function inverses] +which allow you solve for +any of the three parameters to the incomplete beta, starting from either +the result of the incomplete beta (p) or its complement (q). + +[optional_policy] + +[tip When people normally talk about the inverse of the incomplete +beta function, they are talking about inverting on parameter /x/. +These are implemented here as ibeta_inv and ibetac_inv, and are by +far the most efficient of the inverses presented here. + +The inverses on the /a/ and /b/ parameters find use in some statistical +applications, but have to be computed by rather brute force numerical +techniques and are consequently several times slower. +These are implemented here as ibeta_inva and ibeta_invb, +and complement versions ibetac_inva and ibetac_invb.] + +The return type of these functions is computed using the __arg_promotion_rules +when called with arguments T1...TN of different types. + + template <class T1, class T2, class T3> + ``__sf_result`` ibeta_inv(T1 a, T2 b, T3 p); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibeta_inv(T1 a, T2 b, T3 p, const ``__Policy``&); + + template <class T1, class T2, class T3, class T4> + ``__sf_result`` ibeta_inv(T1 a, T2 b, T3 p, T4* py); + + template <class T1, class T2, class T3, class T4, class ``__Policy``> + ``__sf_result`` ibeta_inv(T1 a, T2 b, T3 p, T4* py, const ``__Policy``&); + +Returns a value /x/ such that: `p = ibeta(a, b, x);` +and sets `*py = 1 - x` when the `py` parameter is provided and is non-null. +Note that internally this function computes whichever is the smaller of +`x` and `1-x`, and therefore the value assigned to `*py` is free from +cancellation errors. That means that even if the function returns `1`, the +value stored in `*py` may be non-zero, albeit very small. + +Requires: /a,b > 0/ and /0 <= p <= 1/. + +[optional_policy] + + template <class T1, class T2, class T3> + ``__sf_result`` ibetac_inv(T1 a, T2 b, T3 q); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibetac_inv(T1 a, T2 b, T3 q, const ``__Policy``&); + + template <class T1, class T2, class T3, class T4> + ``__sf_result`` ibetac_inv(T1 a, T2 b, T3 q, T4* py); + + template <class T1, class T2, class T3, class T4, class ``__Policy``> + ``__sf_result`` ibetac_inv(T1 a, T2 b, T3 q, T4* py, const ``__Policy``&); + +Returns a value /x/ such that: `q = ibetac(a, b, x);` +and sets `*py = 1 - x` when the `py` parameter is provided and is non-null. +Note that internally this function computes whichever is the smaller of +`x` and `1-x`, and therefore the value assigned to `*py` is free from +cancellation errors. That means that even if the function returns `1`, the +value stored in `*py` may be non-zero, albeit very small. + +Requires: /a,b > 0/ and /0 <= q <= 1/. + +[optional_policy] + + template <class T1, class T2, class T3> + ``__sf_result`` ibeta_inva(T1 b, T2 x, T3 p); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibeta_inva(T1 b, T2 x, T3 p, const ``__Policy``&); + +Returns a value /a/ such that: `p = ibeta(a, b, x);` + +Requires: /b > 0/, /0 < x < 1/ and /0 <= p <= 1/. + +[optional_policy] + + template <class T1, class T2, class T3> + ``__sf_result`` ibetac_inva(T1 b, T2 x, T3 p); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibetac_inva(T1 b, T2 x, T3 p, const ``__Policy``&); + +Returns a value /a/ such that: `q = ibetac(a, b, x);` + +Requires: /b > 0/, /0 < x < 1/ and /0 <= q <= 1/. + +[optional_policy] + + template <class T1, class T2, class T3> + ``__sf_result`` ibeta_invb(T1 b, T2 x, T3 p); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibeta_invb(T1 b, T2 x, T3 p, const ``__Policy``&); + +Returns a value /b/ such that: `p = ibeta(a, b, x);` + +Requires: /a > 0/, /0 < x < 1/ and /0 <= p <= 1/. + +[optional_policy] + + template <class T1, class T2, class T3> + ``__sf_result`` ibetac_invb(T1 b, T2 x, T3 p); + + template <class T1, class T2, class T3, class ``__Policy``> + ``__sf_result`` ibetac_invb(T1 b, T2 x, T3 p, const ``__Policy``&); + +Returns a value /b/ such that: `q = ibetac(a, b, x);` + +Requires: /a > 0/, /0 < x < 1/ and /0 <= q <= 1/. + +[optional_policy] + +[h4 Accuracy] + +The accuracy of these functions should closely follow that +of the regular forward incomplete beta functions. However, +note that in some parts of their domain, these functions can +be extremely sensitive to changes in input, particularly when +the argument /p/ (or it's complement /q/) is very close to `0` or `1`. + +Comparisons to other libraries are shown below, note that our test data +exercises some rather extreme cases in the incomplete beta function +which many other libraries fail to handle: + +[table_ibeta_inv] + +[table_ibetac_inv] + +[table_ibeta_inva] + +[table_ibetac_inva] + +[table_ibeta_invb] + +[table_ibetac_invb] + +[h4 Testing] + +There are two sets of tests: + +* Basic sanity checks attempt to "round-trip" from +/a, b/ and /x/ to /p/ or /q/ and back again. These tests have quite +generous tolerances: in general both the incomplete beta and its +inverses change so rapidly, that round tripping to more than a couple +of significant digits isn't possible. This is especially true when +/p/ or /q/ is very near one: in this case there isn't enough +"information content" in the input to the inverse function to get +back where you started. +* Accuracy checks using high precision test values. These measure +the accuracy of the result, given exact input values. + +[h4 Implementation of ibeta_inv and ibetac_inv] + +These two functions share a common implementation. + +First an initial approximation to x is computed then the +last few bits are cleaned up using +[@http://en.wikipedia.org/wiki/Simple_rational_approximation Halley iteration]. +The iteration limit is set to 1/2 of the number of bits in T, which by experiment is +sufficient to ensure that the inverses are at least as accurate as the normal +incomplete beta functions. Up to 5 iterations may be +required in extreme cases, although normally only one or two are required. +Further, the number of iterations required decreases with increasing /a/ and +/b/ (which generally form the more important use cases). + +The initial guesses used for iteration are obtained as follows: + +Firstly recall that: + +[equation ibeta_inv5] + +We may wish to start from either p or q, and to calculate either x or y. +In addition at +any stage we can exchange a for b, p for q, and x for y if it results in a +more manageable problem. + +For `a+b >= 5` the initial guess is computed using the methods described in: + +Asymptotic Inversion of the Incomplete Beta Function, +by N. M. [@http://homepages.cwi.nl/~nicot/ Temme]. +Journal of Computational and Applied Mathematics 41 (1992) 145-157. + +The nearly symmetrical case (section 2 of the paper) is used for + +[equation ibeta_inv2] + +and involves solving the inverse error function first. The method is accurate +to at least 2 decimal digits when [^a = 5] rising to at least 8 digits when +[^a = 10[super 5]]. + +The general error function case (section 3 of the paper) is used for + +[equation ibeta_inv3] + +and again expresses the inverse incomplete beta in terms of the +inverse of the error function. The method is accurate to at least +2 decimal digits when [^a+b = 5] rising to 11 digits when [^a+b = 10[super 5]]. +However, when the result is expected to be very small, and when a+b is +also small, then its accuracy tails off, in this case when p[super 1/a] < 0.0025 +then it is better to use the following as an initial estimate: + +[equation ibeta_inv4] + +Finally the for all other cases where `a+b > 5` the method of section +4 of the paper is used. This expresses the inverse incomplete beta in terms +of the inverse of the incomplete gamma function, and is therefore significantly +more expensive to compute than the other cases. However the method is accurate +to at least 3 decimal digits when [^a = 5] rising to at least 10 digits when +[^a = 10[super 5]]. This method is limited to a > b, and therefore we need to perform +an exchange a for b, p for q and x for y when this is not the case. In addition +when p is close to 1 the method is inaccurate should we actually want y rather +than x as output. Therefore when q is small ([^q[super 1/p] < 10[super -3]]) we use: + +[equation ibeta_inv6] + +which is both cheaper to compute than the full method, and a more accurate +estimate on q. + +When a and b are both small there is a distinct lack of information in the +literature on how to proceed. I am extremely grateful to Prof Nico Temme +who provided the following information with a great deal of patience and +explanation on his part. Any errors that follow are entirely my own, and not +Prof Temme's. + +When a and b are both less than 1, then there is a point of inflection in +the incomplete beta at point `xs = (1 - a) / (2 - a - b)`. Therefore if +[^p > I[sub x](a,b)] we swap a for b, p for q and x for y, so that now we always +look for a point x below the point of inflection `xs`, and on a convex curve. +An initial estimate for x is made with: + +[equation ibeta_inv7] + +which is provably below the true value for x: +[@http://en.wikipedia.org/wiki/Newton%27s_method Newton iteration] will +therefore smoothly converge on x without problems caused by overshooting etc. + +When a and b are both greater than 1, but a+b is too small to use the other +methods mentioned above, we proceed as follows. Observe that there is a point +of inflection in the incomplete beta at `xs = (1 - a) / (2 - a - b)`. Therefore +if [^p > I[sub x](a,b)] we swap a for b, p for q and x for y, so that now we always +look for a point x below the point of inflection `xs`, and on a concave curve. +An initial estimate for x is made with: + +[equation ibeta_inv4] + +which can be improved somewhat to: + +[equation ibeta_inv1] + +when b and x are both small (I've used b < a and x < 0.2). This +actually under-estimates x, which drops us on the wrong side of x for Newton +iteration to converge monotonically. However, use of higher derivatives +and Halley iteration keeps everything under control. + +The final case to be considered if when one of a and b is less than or equal +to 1, and the other greater that 1. Here, if b < a we swap a for b, p for q +and x for y. Now the curve of the incomplete beta is convex with no points +of inflection in [0,1]. For small p, x can be estimated using + +[equation ibeta_inv4] + +which under-estimates x, and drops us on the right side of the true value +for Newton iteration to converge monotonically. However, when p is large +this can quite badly underestimate x. This is especially an issue when we +really want to find y, in which case this method can be an arbitrary number +of order of magnitudes out, leading to very poor convergence during iteration. + +Things can be improved by considering the incomplete beta as a distorted +quarter circle, and estimating y from: + +[equation ibeta_inv8] + +This doesn't guarantee that we will drop in on the right side of x for +monotonic convergence, but it does get us close enough that Halley iteration +rapidly converges on the true value. + +[h4 Implementation of inverses on the a and b parameters] + +These four functions share a common implementation. + +First an initial approximation is computed for /a/ or /b/: +where possible this uses a Cornish-Fisher expansion for the +negative binomial distribution to get within around 1 of the +result. However, when /a/ or /b/ are very small the Cornish Fisher +expansion is not usable, in this case the initial approximation +is chosen so that +I[sub x](a, b) is near the middle of the range [0,1]. + +This initial guess is then +used as a starting value for a generic root finding algorithm. The +algorithm converges rapidly on the root once it has been +bracketed, but bracketing the root may take several iterations. +A better initial approximation for /a/ or /b/ would improve these +functions quite substantially: currently 10-20 incomplete beta +function invocations are required to find the root. + +[endsect][/section:ibeta_inv_function The Incomplete Beta Function Inverses] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/igamma.qbk b/boost/libs/math/doc/sf/igamma.qbk new file mode 100644 index 00000000..a9206aa7 --- /dev/null +++ b/boost/libs/math/doc/sf/igamma.qbk @@ -0,0 +1,290 @@ +[section:igamma Incomplete Gamma Functions] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/gamma.hpp> +`` + + namespace boost{ namespace math{ + + template <class T1, class T2> + ``__sf_result`` gamma_p(T1 a, T2 z); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_p(T1 a, T2 z, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` gamma_q(T1 a, T2 z); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_q(T1 a, T2 z, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` tgamma_lower(T1 a, T2 z); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` tgamma_lower(T1 a, T2 z, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` tgamma(T1 a, T2 z); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` tgamma(T1 a, T2 z, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +There are four [@http://mathworld.wolfram.com/IncompleteGammaFunction.html +incomplete gamma functions]: +two are normalised versions (also known as /regularized/ incomplete gamma functions) +that return values in the range [0, 1], and two are non-normalised and +return values in the range [0, [Gamma](a)]. Users interested in statistical +applications should use the +[@http://mathworld.wolfram.com/RegularizedGammaFunction.html normalised versions (gamma_p and gamma_q)]. + +All of these functions require /a > 0/ and /z >= 0/, otherwise they return +the result of __domain_error. + +[optional_policy] + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types, otherwise the return type is simply T1. + + template <class T1, class T2> + ``__sf_result`` gamma_p(T1 a, T2 z); + + template <class T1, class T2, class Policy> + ``__sf_result`` gamma_p(T1 a, T2 z, const ``__Policy``&); + +Returns the normalised lower incomplete gamma function of a and z: + +[equation igamma4] + +This function changes rapidly from 0 to 1 around the point z == a: + +[graph gamma_p] + + template <class T1, class T2> + ``__sf_result`` gamma_q(T1 a, T2 z); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_q(T1 a, T2 z, const ``__Policy``&); + +Returns the normalised upper incomplete gamma function of a and z: + +[equation igamma3] + +This function changes rapidly from 1 to 0 around the point z == a: + +[graph gamma_q] + + template <class T1, class T2> + ``__sf_result`` tgamma_lower(T1 a, T2 z); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` tgamma_lower(T1 a, T2 z, const ``__Policy``&); + +Returns the full (non-normalised) lower incomplete gamma function of a and z: + +[equation igamma2] + + template <class T1, class T2> + ``__sf_result`` tgamma(T1 a, T2 z); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` tgamma(T1 a, T2 z, const ``__Policy``&); + +Returns the full (non-normalised) upper incomplete gamma function of a and z: + +[equation igamma1] + +[h4 Accuracy] + +The following tables give peak and mean relative errors in over various domains of +a and z, along with comparisons to the __gsl and __cephes libraries. +Note that only results for the widest floating point type on the system are given as +narrower types have __zero_error. + +Note that errors grow as /a/ grows larger. + +Note also that the higher error rates for the 80 and 128 bit +long double results are somewhat misleading: expected results that are +zero at 64-bit double precision may be non-zero - but exceptionally small - +with the larger exponent range of a long double. These results therefore +reflect the more extreme nature of the tests conducted for these types. + +All values are in units of epsilon. + +[table_gamma_p] + +[table_gamma_q] + +[table_tgamma_lower] + +[table_tgamma_incomplete_] + +[h4 Testing] + +There are two sets of tests: spot tests compare values taken from +[@http://functions.wolfram.com/GammaBetaErf/ Mathworld's online evaluator] +with this implementation to perform a basic "sanity check". +Accuracy tests use data generated at very high precision +(using NTL's RR class set at 1000-bit precision) using this implementation +with a very high precision 60-term __lanczos, and some but not all of the special +case handling disabled. +This is less than satisfactory: an independent method should really be used, +but apparently a complete lack of such methods are available. We can't even use a deliberately +naive implementation without special case handling since Legendre's continued fraction +(see below) is unstable for small a and z. + +[h4 Implementation] + +These four functions share a common implementation since +they are all related via: + +1) [equation igamma5] + +2) [equation igamma6] + +3) [equation igamma7] + +The lower incomplete gamma is computed from its series representation: + +4) [equation igamma8] + +Or by subtraction of the upper integral from either [Gamma](a) or 1 +when /x - (1/(3x)) > a and x > 1.1/. + +The upper integral is computed from Legendre's continued fraction representation: + +5) [equation igamma9] + +When /(x > 1.1)/ or by subtraction of the lower integral from either [Gamma](a) or 1 +when /x - (1/(3x)) < a/. + +For /x < 1.1/ computation of the upper integral is more complex as the continued +fraction representation is unstable in this area. However there is another +series representation for the lower integral: + +6) [equation igamma10] + +That lends itself to calculation of the upper integral via rearrangement +to: + +7) [equation igamma11] + +Refer to the documentation for __powm1 and __tgamma1pm1 for details +of their implementation. Note however that the precision of __tgamma1pm1 +is capped to either around 35 digits, or to that of the __lanczos associated with +type T - if there is one - whichever of the two is the greater. +That therefore imposes a similar limit on the precision of this +function in this region. + +For /x < 1.1/ the crossover point where the result is ~0.5 no longer +occurs for /x ~ y/. Using /x * 0.75 < a/ as the crossover criterion +for /0.5 < x <= 1.1/ keeps the maximum value computed (whether +it's the upper or lower interval) to around 0.75. Likewise for +/x <= 0.5/ then using /-0.4 / log(x) < a/ as the crossover criterion +keeps the maximum value computed to around 0.7 +(whether it's the upper or lower interval). + +There are two special cases used when a is an integer or half integer, +and the crossover conditions listed above indicate that we should compute +the upper integral Q. +If a is an integer in the range /1 <= a < 30/ then the following +finite sum is used: + +9) [equation igamma1f] + +While for half integers in the range /0.5 <= a < 30/ then the +following finite sum is used: + +10) [equation igamma2f] + +These are both more stable and more efficient than the continued fraction +alternative. + +When the argument /a/ is large, and /x ~ a/ then the series (4) and continued +fraction (5) above are very slow to converge. In this area an expansion due to +Temme is used: + +11) [equation igamma16] + +12) [equation igamma17] + +13) [equation igamma18] + +14) [equation igamma19] + +The double sum is truncated to a fixed number of terms - to give a specific +target precision - and evaluated as a polynomial-of-polynomials. There are +versions for up to 128-bit long double precision: types requiring +greater precision than that do not use these expansions. The +coefficients C[sub k][super n] are computed in advance using the recurrence +relations given by Temme. The zone where these expansions are used is + + (a > 20) && (a < 200) && fabs(x-a)/a < 0.4 + +And: + + (a > 200) && (fabs(x-a)/a < 4.5/sqrt(a)) + +The latter range is valid for all types up to 128-bit long doubles, and +is designed to ensure that the result is larger than 10[super -6], the +first range is used only for types up to 80-bit long doubles. These +domains are narrower than the ones recommended by either Temme or Didonato +and Morris. However, using a wider range results in large and inexact +(i.e. computed) values being passed to the `exp` and `erfc` functions +resulting in significantly larger error rates. In other words there is a +fine trade off here between efficiency and error. The current limits should +keep the number of terms required by (4) and (5) to no more than ~20 +at double precision. + +For the normalised incomplete gamma functions, calculation of the +leading power terms is central to the accuracy of the function. +For smallish a and x combining +the power terms with the __lanczos gives the greatest accuracy: + +15) [equation igamma12] + +In the event that this causes underflow/overflow then the exponent can +be reduced by a factor of /a/ and brought inside the power term. + +When a and x are large, we end up with a very large exponent with a base +near one: this will not be computed accurately via the pow function, +and taking logs simply leads to cancellation errors. The worst of the +errors can be avoided by using: + +16) [equation igamma13] + +when /a-x/ is small and a and x are large. There is still a subtraction +and therefore some cancellation errors - but the terms are small so the absolute +error will be small - and it is absolute rather than relative error that +counts in the argument to the /exp/ function. Note that for sufficiently +large a and x the errors will still get you eventually, although this does +delay the inevitable much longer than other methods. Use of /log(1+x)-x/ here +is inspired by Temme (see references below). + +[h4 References] + +* N. M. Temme, A Set of Algorithms for the Incomplete Gamma Functions, +Probability in the Engineering and Informational Sciences, 8, 1994. +* N. M. Temme, The Asymptotic Expansion of the Incomplete Gamma Functions, +Siam J. Math Anal. Vol 10 No 4, July 1979, p757. +* A. R. Didonato and A. H. Morris, Computation of the Incomplete Gamma +Function Ratios and their Inverse. ACM TOMS, Vol 12, No 4, Dec 1986, p377. +* W. Gautschi, The Incomplete Gamma Functions Since Tricomi, In Tricomi's Ideas +and Contemporary Applied Mathematics, Atti dei Convegni Lincei, n. 147, +Accademia Nazionale dei Lincei, Roma, 1998, pp. 203--237. +[@http://citeseer.ist.psu.edu/gautschi98incomplete.html http://citeseer.ist.psu.edu/gautschi98incomplete.html] + +[endsect][/section:igamma The Incomplete Gamma Function] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/igamma_inv.qbk b/boost/libs/math/doc/sf/igamma_inv.qbk new file mode 100644 index 00000000..7393d9af --- /dev/null +++ b/boost/libs/math/doc/sf/igamma_inv.qbk @@ -0,0 +1,169 @@ +[section:igamma_inv Incomplete Gamma Function Inverses] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/gamma.hpp> +`` + + namespace boost{ namespace math{ + + template <class T1, class T2> + ``__sf_result`` gamma_q_inv(T1 a, T2 q); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_q_inv(T1 a, T2 q, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` gamma_p_inv(T1 a, T2 p); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_p_inv(T1 a, T2 p, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` gamma_q_inva(T1 x, T2 q); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_q_inva(T1 x, T2 q, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` gamma_p_inva(T1 x, T2 p); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_p_inva(T1 x, T2 p, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +There are four [@http://mathworld.wolfram.com/IncompleteGammaFunction.html incomplete gamma function] +inverses which either compute +/x/ given /a/ and /p/ or /q/, +or else compute /a/ given /x/ and either /p/ or /q/. + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types, otherwise the return type is simply T1. + +[optional_policy] + +[tip When people normally talk about the inverse of the incomplete +gamma function, they are talking about inverting on parameter /x/. +These are implemented here as gamma_p_inv and gamma_q_inv, and are by +far the most efficient of the inverses presented here. + +The inverse on the /a/ parameter finds use in some statistical +applications but has to be computed by rather brute force numerical +techniques and is consequently several times slower. +These are implemented here as gamma_p_inva and gamma_q_inva.] + + + template <class T1, class T2> + ``__sf_result`` gamma_q_inv(T1 a, T2 q); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_q_inv(T1 a, T2 q, const ``__Policy``&); + +Returns a value x such that: `q = gamma_q(a, x);` + +Requires: /a > 0/ and /1 >= p,q >= 0/. + + template <class T1, class T2> + ``__sf_result`` gamma_p_inv(T1 a, T2 p); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_p_inv(T1 a, T2 p, const ``__Policy``&); + +Returns a value x such that: `p = gamma_p(a, x);` + +Requires: /a > 0/ and /1 >= p,q >= 0/. + + template <class T1, class T2> + ``__sf_result`` gamma_q_inva(T1 x, T2 q); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_q_inva(T1 x, T2 q, const ``__Policy``&); + +Returns a value a such that: `q = gamma_q(a, x);` + +Requires: /x > 0/ and /1 >= p,q >= 0/. + + template <class T1, class T2> + ``__sf_result`` gamma_p_inva(T1 x, T2 p); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` gamma_p_inva(T1 x, T2 p, const ``__Policy``&); + +Returns a value a such that: `p = gamma_p(a, x);` + +Requires: /x > 0/ and /1 >= p,q >= 0/. + +[h4 Accuracy] + +The accuracy of these functions doesn't vary much by platform or by +the type T. Given that these functions are computed by iterative methods, +they are deliberately "detuned" so as not to be too accurate: it is in +any case impossible for these function to be more accurate than the +regular forward incomplete gamma functions. In practice, the accuracy +of these functions is very similar to that of __gamma_p and __gamma_q +functions: + +[table_gamma_p_inv] + +[table_gamma_q_inv] + +[table_gamma_p_inva] + +[table_gamma_q_inva] + +[h4 Testing] + +There are two sets of tests: + +* Basic sanity checks attempt to "round-trip" from +/a/ and /x/ to /p/ or /q/ and back again. These tests have quite +generous tolerances: in general both the incomplete gamma, and its +inverses, change so rapidly that round tripping to more than a couple +of significant digits isn't possible. This is especially true when +/p/ or /q/ is very near one: in this case there isn't enough +"information content" in the input to the inverse function to get +back where you started. +* Accuracy checks using high precision test values. These measure +the accuracy of the result, given exact input values. + +[h4 Implementation] + +The functions gamma_p_inv and [@http://functions.wolfram.com/GammaBetaErf/InverseGammaRegularized/ gamma_q_inv] +share a common implementation. + +First an initial approximation is computed using the methodology described +in: + +[@http://portal.acm.org/citation.cfm?id=23109&coll=portal&dl=ACM +A. R. Didonato and A. H. Morris, Computation of the Incomplete Gamma +Function Ratios and their Inverse, ACM Trans. Math. Software 12 (1986), 377-393.] + +Finally, the last few bits are cleaned up using Halley iteration, the iteration +limit is set to 2/3 of the number of bits in T, which by experiment is +sufficient to ensure that the inverses are at least as accurate as the normal +incomplete gamma functions. In testing, no more than 3 iterations are required +to produce a result as accurate as the forward incomplete gamma function, and +in many cases only one iteration is required. + +The functions gamma_p_inva and gamma_q_inva also share a common implementation +but are handled separately from gamma_p_inv and gamma_q_inv. + +An initial approximation for /a/ is computed very crudely so that +/gamma_p(a, x) ~ 0.5/, this value is then used as a starting point +for a generic derivative-free root finding algorithm. As a consequence, +these two functions are rather more expensive to compute than the +gamma_p_inv or gamma_q_inv functions. Even so, the root is usually found +in fewer than 10 iterations. + +[endsect][/section The Incomplete Gamma Function Inverses] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/inv_hyper.qbk b/boost/libs/math/doc/sf/inv_hyper.qbk new file mode 100644 index 00000000..10e20a19 --- /dev/null +++ b/boost/libs/math/doc/sf/inv_hyper.qbk @@ -0,0 +1,279 @@ +[/ math.qbk + Copyright 2006 Hubert Holin and John Maddock. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + +[def __form1 [^\[0;+'''∞'''\[]] +[def __form2 [^\]-'''∞''';+1\[]] +[def __form3 [^\]-'''∞''';-1\[]] +[def __form4 [^\]+1;+'''∞'''\[]] +[def __form5 [^\[-1;-1+'''ε'''\[]] +[def __form6 '''ε'''] +[def __form7 [^\]+1-'''ε''';+1\]]] + +[def __effects [*Effects: ]] +[def __formula [*Formula: ]] +[def __exm1 '''<code>e<superscript>x</superscript> - 1</code>'''[space]] +[def __ex '''<code>e<superscript>x</superscript></code>'''] +[def __te '''2ε'''] + +[section:inv_hyper Inverse Hyperbolic Functions] + +[section:inv_hyper_over Inverse Hyperbolic Functions Overview] + +The exponential funtion is defined, for all objects for which this makes sense, +as the power series +[equation special_functions_blurb1], +with ['[^n! = 1x2x3x4x5...xn]] (and ['[^0! = 1]] by definition) being the factorial of ['[^n]]. +In particular, the exponential function is well defined for real numbers, +complex number, quaternions, octonions, and matrices of complex numbers, +among others. + +[: ['[*Graph of exp on R]] ] + +[: [$../graphs/exp_on_r.png] ] + +[: ['[*Real and Imaginary parts of exp on C]]] +[: [$../graphs/im_exp_on_c.png]] + +The hyperbolic functions are defined as power series which +can be computed (for reals, complex, quaternions and octonions) as: + +Hyperbolic cosine: [equation special_functions_blurb5] + +Hyperbolic sine: [equation special_functions_blurb6] + +Hyperbolic tangent: [equation special_functions_blurb7] + +[: ['[*Trigonometric functions on R (cos: purple; sin: red; tan: blue)]]] +[: [$../graphs/trigonometric.png]] + +[: ['[*Hyperbolic functions on r (cosh: purple; sinh: red; tanh: blue)]]] +[: [$../graphs/hyperbolic.png]] + +The hyperbolic sine is one to one on the set of real numbers, +with range the full set of reals, while the hyperbolic tangent is +also one to one on the set of real numbers but with range __form1, and +therefore both have inverses. The hyperbolic cosine is one to one from __form2 +onto __form3 (and from __form4 onto __form3); the inverse function we use +here is defined on __form3 with range __form2. + +The inverse of the hyperbolic tangent is called the Argument hyperbolic tangent, +and can be computed as [equation special_functions_blurb15]. + +The inverse of the hyperbolic sine is called the Argument hyperbolic sine, +and can be computed (for __form5) as [equation special_functions_blurb17]. + +The inverse of the hyperbolic cosine is called the Argument hyperbolic cosine, +and can be computed as [equation special_functions_blurb18]. + +[endsect] + +[section:acosh acosh] + +`` +#include <boost/math/special_functions/acosh.hpp> +`` + + template<class T> + ``__sf_result`` acosh(const T x); + + template<class T, class ``__Policy``> + ``__sf_result`` acosh(const T x, const ``__Policy``&); + +Computes the reciprocal of (the restriction to the range of __form1) +[link math_toolkit.inv_hyper.inv_hyper_over +the hyperbolic cosine function], at x. Values returned are positive. + +If x is in the range __form2 then returns the result of __domain_error. + +The return type of this function is computed using the __arg_promotion_rules: +the return type is `double` when T is an integer type, and T otherwise. + +[optional_policy] + +[graph acosh] + +[h4 Accuracy] + +Generally accuracy is to within 1 or 2 epsilon across all supported platforms. + +[h4 Testing] + +This function is tested using a combination of random test values designed to give +full function coverage computed at high precision using the "naive" formula: + +[equation acosh1] + +along with a selection of sanity check values +computed using functions.wolfram.com to at least 50 decimal digits. + +[h4 Implementation] + +For sufficiently large x, we can use the +[@http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/06/01/0001/ +approximation]: + +[equation acosh2] + +For x sufficiently close to 1 we can use the +[@http://functions.wolfram.com/ElementaryFunctions/ArcCosh/06/01/04/01/0001/ +approximation]: + +[equation acosh4] + +Otherwise for x close to 1 we can use the following rearrangement of the +primary definition to preserve accuracy: + +[equation acosh3] + +Otherwise the +[@http://functions.wolfram.com/ElementaryFunctions/ArcCosh/02/ +primary definition] is used: + +[equation acosh1] + +[endsect] + +[section:asinh asinh] + +`` +#include <boost/math/special_functions/asinh.hpp> +`` + + template<class T> + ``__sf_result`` asinh(const T x); + + template<class T, class ``__Policy``> + ``__sf_result`` asinh(const T x, const ``__Policy``&); + +Computes the reciprocal of +[link math_toolkit.inv_hyper.inv_hyper_over +the hyperbolic sine function]. + +The return type of this function is computed using the __arg_promotion_rules: +the return type is `double` when T is an integer type, and T otherwise. + +[graph asinh] + +[optional_policy] + +[h4 Accuracy] + +Generally accuracy is to within 1 or 2 epsilon across all supported platforms. + +[h4 Testing] + +This function is tested using a combination of random test values designed to give +full function coverage computed at high precision using the "naive" formula: + +[equation asinh1] + +along with a selection of sanity check values +computed using functions.wolfram.com to at least 50 decimal digits. + +[h4 Implementation] + +For sufficiently large x we can use the +[@http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/06/01/0001/ +approximation]: + +[equation asinh2] + +While for very small x we can use the +[@http://functions.wolfram.com/ElementaryFunctions/ArcSinh/06/01/03/01/0001/ +approximation]: + +[equation asinh3] + +For 0.5 > x > [epsilon] the following rearrangement of the primary definition is used: + +[equation asinh4] + +Otherwise evalution is via the +[@http://functions.wolfram.com/ElementaryFunctions/ArcSinh/02/ +primary definition]: + +[equation asinh4] + +[endsect] + +[section:atanh atanh] + +`` +#include <boost/math/special_functions/atanh.hpp> +`` + + template<class T> + ``__sf_result`` atanh(const T x); + + template<class T, class ``__Policy``> + ``__sf_result`` atanh(const T x, const ``__Policy``&); + +Computes the reciprocal of +[link math_toolkit.inv_hyper.inv_hyper_over +the hyperbolic tangent function], at x. + +[optional_policy] + +If x is in the range +__form3 +or in the range +__form4 +then returns the result of __domain_error. + +If x is in the range +__form5, +then the result of -__overflow_error is returned, with +__form6[space] +denoting numeric_limits<T>::epsilon(). + +If x is in the range +__form7, +then the result of __overflow_error is returned, with +__form6[space] +denoting +numeric_limits<T>::epsilon(). + +The return type of this function is computed using the __arg_promotion_rules: +the return type is `double` when T is an integer type, and T otherwise. + +[graph atanh] + +[h4 Accuracy] + +Generally accuracy is to within 1 or 2 epsilon across all supported platforms. + +[h4 Testing] + +This function is tested using a combination of random test values designed to give +full function coverage computed at high precision using the "naive" formula: + +[equation atanh1] + +along with a selection of sanity check values +computed using functions.wolfram.com to at least 50 decimal digits. + +[h4 Implementation] + +For sufficiently small x we can use the +[@http://functions.wolfram.com/ElementaryFunctions/ArcTanh/06/01/03/01/ approximation]: + +[equation atanh2] + +Otherwise the +[@http://functions.wolfram.com/ElementaryFunctions/ArcTanh/02/ primary definition]: + +[equation atanh1] + +or its equivalent form: + +[equation atanh3] + +is used. + +[endsect] + +[endsect] diff --git a/boost/libs/math/doc/sf/jacobi_elliptic.qbk b/boost/libs/math/doc/sf/jacobi_elliptic.qbk new file mode 100644 index 00000000..7290c0f3 --- /dev/null +++ b/boost/libs/math/doc/sf/jacobi_elliptic.qbk @@ -0,0 +1,550 @@ +[/ +Copyright (c) 2012 John Maddock +Use, modification and distribution are subject to the +Boost Software License, Version 1.0. (See accompanying file +LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +] + +[section:jacobi Jacobi Elliptic Functions] + +[section:jac_over Overvew of the Jacobi Elliptic Functions] + +There are twelve Jacobi Elliptic functions, of which the three copolar functions ['sn], ['cn] and ['dn] are the most important +as the other nine can be computed from these three +[footnote [@http://en.wikipedia.org/wiki/Jacobi_elliptic_functions Wikipedia: Jacobi elliptic functions]] +[footnote [@http://mathworld.wolfram.com/JacobiEllipticFunctions.html Weisstein, Eric W. "Jacobi Elliptic Functions." From MathWorld - A Wolfram Web Resource.]] +[footnote [@http://dlmf.nist.gov/22 Digital Library of Mathematical Functions: Jacobian Elliptic Functions]]. + +These functions each take two arguments: a parameter, and a variable as described below. + +Like all elliptic functions these can be parameterised in a number of ways: + +* In terms of a parameter ['m]. +* In terms of the elliptic modulus ['k] where ['m = k[super 2]]. +* In terms of the modular angle [alpha], where ['m = sin[super 2][alpha]]. + +In our implementation, these functions all take the elliptic modulus /k/ as the parameter. + +In addition the variable /u/ is sometimes expressed as an amplitude [phi], in our implementation we always use /u/. + +Finally note that our functions all take the elliptic modulus as the first argument - this is for alignment with +the Elliptic Integrals. + +There are twenve functions for computing the twelve individual Jacobi elliptic functions: __jacobi_cd, __jacobi_cn, __jacobi_cs, +__jacobi_dc, __jacobi_dn, __jacobi_ds, __jacobi_nc, __jacobi_nd, __jacobi_ns, __jacobi_sc, __jacobi_sd and __jacobi_sn. + +They are all called as for example: + + jacobi_cs(k, u); + +Note however that these individual functions are all really thin wrappers around the function __jacobi_elliptic which calculates +the three copolar functions ['sn], ['cn] and ['dn] in a single function call. Thus if you need more than one of these functions +for a given set of arguments, it's most efficient to use __jacobi_elliptic. + +[endsect] + +[section:jacobi_elliptic Jacobi Elliptic SN, CN and DN] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U, class V> + ``__sf_result`` jacobi_elliptic(T k, U u, V* pcn, V* pdn); + + template <class T, class U, class V, class Policy> + ``__sf_result`` jacobi_elliptic(T k, U u, V* pcn, V* pdn, const Policy&); + + }} // namespaces + +[heading Description] + +The function __jacobi_elliptic calculates the three copolar Jacobi elliptic functions +['sn(u, k)], ['cn(u, k)] and ['dn(u, k)]. The returned value is +['sn(u, k)], and if provided, ['*pcn] is +set to ['cn(u, k)], and ['*pdn] is set to ['dn(u, k)]. + +The functions are defined as follows, given: + +[equation jacobi1] + +The the angle [phi] is called the ['amplitude] and: + +[equation jacobi2] + +[note ['[phi]] is called the amplitude. + +['k] is called the modulus. + +] + +[caution Rather like other elliptic functions, the Jacobi functions +are expressed in a variety of different ways. In particular, +the parameter /k/ (the modulus) may also be expressed using a modular +angle [alpha], or a parameter /m/. These are related by: + +k = sin[alpha] + +m = k[super 2] = sin[super 2][alpha] + +So that the function ['sn] (for example) may be expressed as +either: + +sn(u, k) + +sn(u \\ [alpha]) + +sn(u| m) + +To further complicate matters, some texts refer to the ['complement +of the parameter m], or 1 - m, where: + +1 - m = 1 - k[super 2] = cos[super 2][alpha] + +This implementation uses /k/ throughout, and makes this the first argument +to the functions: this is for alignment with the elliptic integrals which match the requirements +of the [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf +Technical Report on C++ Library Extensions]. However, you should +be extra careful when using these functions!] + +[optional_policy] + +The following graphs illustrate how these functions change as /k/ changes: for small /k/ +these are sine waves, while as /k/ tends to 1 they become hyperbolic functions: + +[graph jacobi_sn] + +[graph jacobi_cn] + +[graph jacobi_dn] + +[heading Accuracy] + +These functions are computed using only basic arithmetic operations and trigomometric functions, so +there isn't much variation in accuracy over differing platforms. +Typically errors are trivially small for small angles, and as is typical for cyclic +functions, grow as the angle increases. +Note that only results for the widest floating point type on the +system are given as narrower types have __zero_error. All values +are relative errors in units of epsilon. + +[table_jacobi_cn] + +[table_jacobi_dn] + +[table_jacobi_sn] + +[heading Testing] + +The tests use a mixture of spot test values calculated using the online +calculator at [@http://functions.wolfram.com/ functions.wolfram.com], +and random test data generated using +MPFR at 1000-bit precision and this implementation. + +[heading Implementation] + +For ['k > 1] we apply the relations: + +[equation jacobi3] + +Then filter off the special cases: + +['sn(0, k) = 0] and ['cn(0, k) = dn(0, k) = 1]. + +['sn(u, 0) = sin(u), cn(u, 0) = cos(u) and dn(u, 0) = 1]. + +['sn(u, 1) = tanh(u), cn(u, 1) = dn(u, 1) = 1 / cosh(u)]. + +And for ['k[super 4] < [epsilon]] we have: + +[equation jacobi4] + +Otherwise the values are calculated using the method of [@http://dlmf.nist.gov/22.20#SS2 arithmetic geometric means]. + +[endsect] + +[section:jacobi_cd Jacobi Elliptic Function cd] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_cd(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_cd(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['cd]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic, with: + +['cd(u, k) = cn(u, k) / dn(u, k)] + +[graph jacobi_cd] + +[endsect] + +[section:jacobi_cn Jacobi Elliptic Function cn] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_cn(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_cn(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['cn]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic. + +[graph jacobi_cn] + +[endsect] + +[section:jacobi_cs Jacobi Elliptic Function cs] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_cs(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_cs(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['cs]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic, with: + +['cs(u, k) = cn(u, k) / sn(u, k)] + +[graph jacobi_cs] + +[endsect] + +[section:jacobi_dc Jacobi Elliptic Function dc] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_dc(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_dc(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['dc]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic, with: + +['dc(u, k) = dn(u, k) / cn(u, k)] + +[graph jacobi_dc] + +[endsect] + +[section:jacobi_dn Jacobi Elliptic Function dn] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_dn(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_dn(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['dn]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic. + +[graph jacobi_dn] + +[endsect] + +[section:jacobi_ds Jacobi Elliptic Function ds] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_ds(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_ds(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['ds]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic, with: + +['ds(u, k) = dn(u, k) / sn(u, k)] + +[graph jacobi_ds] + +[endsect] + +[section:jacobi_nc Jacobi Elliptic Function nc] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_nc(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_nc(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['nc]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic, with: + +['nc(u, k) = 1 / cn(u, k)] + +[graph jacobi_nc] + +[endsect] + +[section:jacobi_nd Jacobi Elliptic Function nd] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_nd(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_nd(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['nd]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic, with: + +['nd(u, k) = 1 / dn(u, k)] + +[graph jacobi_nd] + +[endsect] + +[section:jacobi_ns Jacobi Elliptic Function ns] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_ns(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_ns(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['ns]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic, with: + +['ns(u, k) = 1 / sn(u, k)] + +[graph jacobi_ns] + +[endsect] + +[section:jacobi_sc Jacobi Elliptic Function sc] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_sc(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_sc(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['sc]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic, with: + +['sc(u, k) = sn(u, k) / cn(u, k)] + +[graph jacobi_sc] + +[endsect] + +[section:jacobi_sd Jacobi Elliptic Function sd] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_sd(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_sd(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['sd]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic, with: + +['sd(u, k) = sn(u, k) / dn(u, k)] + +[graph jacobi_sd] + +[endsect] + +[section:jacobi_sn Jacobi Elliptic Function sn] + +[heading Synopsis] + +`` + #include <boost/math/special_functions/jacobi_elliptic.hpp> +`` + + namespace boost { namespace math { + + template <class T, class U> + ``__sf_result`` jacobi_sn(T k, U u); + + template <class T, class U, class Policy> + ``__sf_result`` jacobi_sn(T k, U u, const Policy& pol); + + }} // namespaces + +[heading Description] + +This function returns the Jacobi elliptic function ['sn]. + +[optional_policy] + +This function is a trivial wrapper around __jacobi_elliptic. + +[graph jacobi_sn] + +[endsect] + + +[endsect] + diff --git a/boost/libs/math/doc/sf/laguerre.qbk b/boost/libs/math/doc/sf/laguerre.qbk new file mode 100644 index 00000000..a208d63d --- /dev/null +++ b/boost/libs/math/doc/sf/laguerre.qbk @@ -0,0 +1,159 @@ +[section:laguerre Laguerre (and Associated) Polynomials] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/laguerre.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` laguerre(unsigned n, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` laguerre(unsigned n, T x, const ``__Policy``&); + + template <class T> + ``__sf_result`` laguerre(unsigned n, unsigned m, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` laguerre(unsigned n, unsigned m, T x, const ``__Policy``&); + + template <class T1, class T2, class T3> + ``__sf_result`` laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1); + + template <class T1, class T2, class T3> + ``__sf_result`` laguerre_next(unsigned n, unsigned m, T1 x, T2 Ln, T3 Lnm1); + + + }} // namespaces + +[h4 Description] + +The return type of these functions is computed using the __arg_promotion_rules: +note than when there is a single template argument the result is the same type +as that argument or `double` if the template argument is an integer type. + +[optional_policy] + + template <class T> + ``__sf_result`` laguerre(unsigned n, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` laguerre(unsigned n, T x, const ``__Policy``&); + +Returns the value of the Laguerre Polynomial of order /n/ at point /x/: + +[equation laguerre_0] + +The following graph illustrates the behaviour of the first few +Laguerre Polynomials: + +[graph laguerre] + + template <class T> + ``__sf_result`` laguerre(unsigned n, unsigned m, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` laguerre(unsigned n, unsigned m, T x, const ``__Policy``&); + +Returns the Associated Laguerre polynomial of degree /n/ +and order /m/ at point /x/: + +[equation laguerre_1] + + template <class T1, class T2, class T3> + ``__sf_result`` laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1); + +Implements the three term recurrence relation for the Laguerre +polynomials, this function can be used to create a sequence of +values evaluated at the same /x/, and for rising /n/. + +[equation laguerre_2] + +For example we could produce a vector of the first 10 polynomial +values using: + + double x = 0.5; // Abscissa value + vector<double> v; + v.push_back(laguerre(0, x)).push_back(laguerre(1, x)); + for(unsigned l = 1; l < 10; ++l) + v.push_back(laguerre_next(l, x, v[l], v[l-1])); + +Formally the arguments are: + +[variablelist +[[n][The degree /n/ of the last polynomial calculated.]] +[[x][The abscissa value]] +[[Ln][The value of the polynomial evaluated at degree /n/.]] +[[Lnm1][The value of the polynomial evaluated at degree /n-1/.]] +] + + template <class T1, class T2, class T3> + ``__sf_result`` laguerre_next(unsigned n, unsigned m, T1 x, T2 Ln, T3 Lnm1); + +Implements the three term recurrence relation for the Associated Laguerre +polynomials, this function can be used to create a sequence of +values evaluated at the same /x/, and for rising degree /n/. + +[equation laguerre_3] + +For example we could produce a vector of the first 10 polynomial +values using: + + double x = 0.5; // Abscissa value + int m = 10; // order + vector<double> v; + v.push_back(laguerre(0, m, x)).push_back(laguerre(1, m, x)); + for(unsigned l = 1; l < 10; ++l) + v.push_back(laguerre_next(l, m, x, v[l], v[l-1])); + +Formally the arguments are: + +[variablelist +[[n][The degree of the last polynomial calculated.]] +[[m][The order of the Associated Polynomial.]] +[[x][The abscissa value.]] +[[Ln][The value of the polynomial evaluated at degree /n/.]] +[[Lnm1][The value of the polynomial evaluated at degree /n-1/.]] +] + +[h4 Accuracy] + +The following table shows peak errors (in units of epsilon) +for various domains of input arguments. +Note that only results for the widest floating point type on the system are +given as narrower types have __zero_error. + +[table_laguerre_n_x_] + +[table_laguerre_n_m_x_] + +Note that the worst errors occur when the degree increases, values greater than +~120 are very unlikely to produce sensible results, especially in the associated +polynomial case when the order is also large. Further the relative errors +are likely to grow arbitrarily large when the function is very close to a root. + +[h4 Testing] + +A mixture of spot tests of values calculated using functions.wolfram.com, +and randomly generated test data are +used: the test data was computed using +[@http://shoup.net/ntl/doc/RR.txt NTL::RR] at 1000-bit precision. + +[h4 Implementation] + +These functions are implemented using the stable three term +recurrence relations. These relations guarantee low absolute error +but cannot guarantee low relative error near one of the roots of the +polynomials. + +[endsect][/section:beta_function The Beta Function] +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/latin1_symbols.qbk b/boost/libs/math/doc/sf/latin1_symbols.qbk new file mode 100644 index 00000000..9bbd93b7 --- /dev/null +++ b/boost/libs/math/doc/sf/latin1_symbols.qbk @@ -0,0 +1,115 @@ +[/ Symbols and accented letters from Latin-1] +[/ File Latin1_symbols.qbk] +[/ http://www.htmlhelp.com/reference/html40/entities/latin1.html ] +[/ based on table Copyright </copyright.html> 1998-2006 Liam Quinn.] +[/ Glyphs <http://www.unicode.org/charts/> of the characters ] +[/ are available at the Unicode Consortium <http://www.unicode.org/>. ] +[/ To use these symbols in Quickbook: enclose template name in square brackets.] +[/ See also Greek and math symbols in html4_symbols.qbk] + +[/ These are all 8th bit ANSI symbols. C1 controls and Latin-1 Supplement] +[/ See http://www.unicode.org/charts/PDF/U0080.pdf] +[template nbsp[]''' '''] [/ no-break space = non-breaking space] +[template iexcl[]'''¡'''] [/ inverted exclamation mark ] +[template cent[]'''¢'''] [/ cent sign ] +[template pound[]'''£'''] [/ pound sign ] +[template curren[]'''¤'''] [/ currency sign ] +[template yen[]'''¥'''] [/ yen sign = yuan sign ] +[template brvbar[]'''¦'''] [/ broken vertical bar ] +[template sectsign[]'''§'''] [/ section sign ] +[template uml[]'''¨'''] [/ diaeresis ] +[template copy[]'''©'''] [/ copyright ] +[template ordf[]'''ª'''] [/ feminine ordinal indicator ] +[template laquo[]'''«'''] [/ left-pointing double angle quotation mark = left pointing guillemet ] +[template not[]'''¬'''] [/ not sign ] +[template shy[]'''­'''] [/ soft hyphen = discretionary hyphen ] +[template reg[]'''®'''] [/ registered sign = registered trade mark sign ] +[template macron[]'''¯'''] [/ macron = spacing macron = overline = APL overbar ] +[template deg[]'''°'''] [/ degree sign ] +[template plusmn[]'''±'''] [/ plus-minus sign = plus-or-minus sign ] +[template sup2[]'''²'''] [/ superscript two = superscript digit two = squared ] +[template cubed[]'''³'''] [/ superscript three = superscript digit three = cubed ] +[template acute[]'''´'''] [/ acute accent = spacing acute ] +[template micro[]'''µ'''] [/ micro sign ] +[template polcrow[]'''¶'''] [/ pilcrow sign = paragraph sign - care ! name para conflicts with para macro!!] +[template middot[]'''·'''] [/ middle dot = Georgian comma = Greek middle dot ] +[template cedil[]'''¸'''] [/ cedilla = spacing cedilla ] +[template sup1[]'''¹'''] [/ superscript one = superscript digit one ] +[template ordm[]'''º'''] [/ masculine ordinal indicator ] +[template raquo[]'''»'''] [/ right-pointing double angle quotation mark = right pointing guillemet ] +[template frac14[]'''¼'''] [/ vulgar fraction one quarter = fraction one quarter ] +[template frac12[]'''½'''] [/ vulgar fraction one half = fraction one half ] +[template frac34[]'''¾'''] [/vulgar fraction three quarters = fraction three quarters ] +[template iquest[]'''¿'''] [/ inverted question mark = turned question mark ] +[template Agrave[]'''À'''] [/ Latin capital letter A with grave = Latin capital letter A grave ] +[template Aacute[]'''Á'''] [/ Latin capital letter A with acute = Latin capital letter A acute ] +[template Acirc[]'''Â'''] [/ Latin capital letter A with circumflex ] +[template Atilde[]'''Ã'''] [/Latin capital letter A with tilde ] +[template Auml[]'''Ä'''] [/ Latin capital letter A with diaeresis ] +[template Aring[]'''Å'''] [/ Latin capital letter A with ring above = Latin capital letter A ring ] +[template AElig[]'''Æ'''] [/ Latin capital letter AE = Latin capital ligature AE ] +[template Ccedil[]'''Ç'''] [/ Latin capital letter C with cedilla ] +[template Egrave[]'''È'''] [/ Latin capital letter E with grave ] +[template Eacute[]'''É'''] [/ Latin capital letter E with acute ] +[template Ecirc[]'''Ê'''] [/ Latin capital letter E with circumflex ] +[template Euml[]'''Ë'''] [/ Latin capital letter E with diaeresis ] +[template Igrave[]'''Ì'''] [/ Latin capital letter I with grave ] +[template Iacute[]'''Í'''] [/ Latin capital letter I with acute ] +[template Icirc[]'''Î'''] [/ Latin capital letter I with circumflex ] +[template Iuml[]'''Ï'''] [/ Latin capital letter I with diaeresis ] +[template ETH[]'''Ð'''] [/ Latin capital letter ETH ] +[template Ntilde[]'''Ñ'''] [/ Latin capital letter N with tilde ] +[template Ograve[]'''Ò'''] [/ Latin capital letter O with grave] +[template Oacute[]'''Ó'''] [/ Latin capital letter O with acute ] +[template Ocirc[]'''Ô'''] [/ Latin capital letter O with circumflex ] +[template Otilde[]'''Õ'''] [/ Latin capital letter O with tilde ] +[template Ouml[]'''Ö'''] [/ Latin capital letter O with diaeresis ] +[template times[]'''×'''] [/ multiplication sign ] +[template Oslash[]'''Ø'''] [/ Latin capital letter O with stroke = Latin capital letter O slash ] +[template Ugrave[]'''Ù'''] [/ Latin capital letter U with grave ] +[template Uacute[]'''Ú'''] [/ Latin capital letter U with acute ] +[template Ucirc[]'''Û'''] [/ Latin capital letter U with circumflex ] +[template Uuml[]'''Ü'''] [/ Latin capital letter U with diaeresis ] +[template Yacute[]'''Ý'''] [/ Latin capital letter Y with acute ] +[template THORN[]'''Þ'''] [/ Latin capital letter THORN ] +[template szlig[]'''ß'''] [/ Latin small letter sharp s = ess-zed ] +[template agrave[]'''à'''] [/ Latin small letter a with grave = Latin small letter a grave ] +[template aacute[]'''á'''] [/ Latin small letter a with acute ] +[template acirc[]'''â'''] [/ Latin small letter a with circumflex ] +[template atilde[]'''ã'''] [/ Latin small letter a with tilde ] +[template auml[]'''ä'''] [/ Latin small letter a with diaeresis ] +[template aring[]'''å'''] [/ Latin small letter a with ring above = Latin small letter a ring ] +[template aelig[]'''æ'''] [/ Latin small letter ae = Latin small ligature ae ] +[template ccedil[]'''ç'''] [/ Latin small letter c with cedilla ] +[template egrave[]'''è'''] [/ Latin small letter e with grave ] +[template eacute[]'''é'''] [/ Latin small letter e with acute ] +[template ecirc[]'''ê'''] [/ Latin small letter e with circumflex ] +[template euml[]'''ë'''] [/ Latin small letter e with diaeresis ] +[template igrave[]'''ì'''] [/ Latin small letter i with grave ] +[template iacute[]'''í'''] [/ Latin small letter i with acute ] +[template icirc[]'''î'''] [/ Latin small letter i with circumflex ] +[template iuml[]'''ï'''] [/ Latin small letter i with diaeresis ] +[template eth[]'''ð'''] [/ Latin small letter eth ] +[template ntilde[]'''ñ'''] [/ Latin small letter n with tilde ] +[template ograve[]'''ò'''] [/Latin small letter o with grave ] +[template oacute[]'''ó'''] [/ Latin small letter o with acute ] +[template ocirc[]'''ô'''] [/ Latin small letter o with circumflex ] +[template otilde[]'''õ'''] [/ Latin small letter o with tilde ] +[template ouml[]'''ö'''] [/ Latin small letter o with diaeresis ] +[template divide[]'''÷'''] [/ division sign ] +[template oslash[]'''ø'''] [/ Latin small letter o with stroke = Latin small letter o slash ] +[template ugrave[]'''ù'''] [/ Latin small letter u with grave ] +[template uacute[]'''ú'''] [/ Latin small letter u with acute ] +[template ucirc[]'''û'''] [/ Latin small letter u with circumflex ] +[template uuml[]'''ü'''] [/ Latin small letter u with diaeresis ] +[template yacute[]'''ý'''] [/ Latin small letter y with acute ] +[template thorn[]'''þ'''] [/ Latin small letter thorn ] +[template yuml[]'''ÿ'''] [/ Latin small letter y with diaeresis ] + +[/ File Latin1_symbols.qbk +Copyright 2007, 2010 Paul A. Bristow. +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE_1_0.txt or copy at +http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/legendre.qbk b/boost/libs/math/doc/sf/legendre.qbk new file mode 100644 index 00000000..d80866ca --- /dev/null +++ b/boost/libs/math/doc/sf/legendre.qbk @@ -0,0 +1,228 @@ +[section:legendre Legendre (and Associated) Polynomials] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/legendre.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` legendre_p(int n, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` legendre_p(int n, T x, const ``__Policy``&); + + template <class T> + ``__sf_result`` legendre_p(int n, int m, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` legendre_p(int n, int m, T x, const ``__Policy``&); + + template <class T> + ``__sf_result`` legendre_q(unsigned n, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` legendre_q(unsigned n, T x, const ``__Policy``&); + + template <class T1, class T2, class T3> + ``__sf_result`` legendre_next(unsigned l, T1 x, T2 Pl, T3 Plm1); + + template <class T1, class T2, class T3> + ``__sf_result`` legendre_next(unsigned l, unsigned m, T1 x, T2 Pl, T3 Plm1); + + + }} // namespaces + +The return type of these functions is computed using the __arg_promotion_rules: +note than when there is a single template argument the result is the same type +as that argument or `double` if the template argument is an integer type. + +[optional_policy] + +[h4 Description] + + template <class T> + ``__sf_result`` legendre_p(int l, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` legendre_p(int l, T x, const ``__Policy``&); + +Returns the Legendre Polynomial of the first kind: + +[equation legendre_0] + +Requires -1 <= x <= 1, otherwise returns the result of __domain_error. + +Negative orders are handled via the reflection formula: + +P[sub -l-1](x) = P[sub l](x) + +The following graph illustrates the behaviour of the first few +Legendre Polynomials: + +[graph legendre_p] + + template <class T> + ``__sf_result`` legendre_p(int l, int m, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` legendre_p(int l, int m, T x, const ``__Policy``&); + +Returns the associated Legendre polynomial of the first kind: + +[equation legendre_1] + +Requires -1 <= x <= 1, otherwise returns the result of __domain_error. + +Negative values of /l/ and /m/ are handled via the identity relations: + +[equation legendre_3] + +[caution The definition of the associated Legendre polynomial used here +includes a leading Condon-Shortley phase term of (-1)[super m]. This +matches the definition given by Abramowitz and Stegun (8.6.6) and that +used by [@http://mathworld.wolfram.com/LegendrePolynomial.html Mathworld] +and [@http://documents.wolfram.com/mathematica/functions/LegendreP +Mathematica's LegendreP function]. However, uses in the literature +do not always include this phase term, and strangely the specification +for the associated Legendre function in the C++ TR1 (assoc_legendre) +also omits it, in spite of stating that it uses Abramowitz and Stegun +as the final arbiter on these matters. + +See: + +[@http://mathworld.wolfram.com/LegendrePolynomial.html +Weisstein, Eric W. "Legendre Polynomial." +From MathWorld--A Wolfram Web Resource]. + +Abramowitz, M. and Stegun, I. A. (Eds.). "Legendre Functions" and +"Orthogonal Polynomials." Ch. 22 in Chs. 8 and 22 in Handbook of +Mathematical Functions with Formulas, Graphs, and Mathematical Tables, +9th printing. New York: Dover, pp. 331-339 and 771-802, 1972. + ] + + template <class T> + ``__sf_result`` legendre_q(unsigned n, T x); + + template <class T, class ``__Policy``> + ``__sf_result`` legendre_q(unsigned n, T x, const ``__Policy``&); + +Returns the value of the Legendre polynomial that is the second solution +to the Legendre differential equation, for example: + +[equation legendre_2] + +Requires -1 <= x <= 1, otherwise __domain_error is called. + +The following graph illustrates the first few Legendre functions of the +second kind: + +[graph legendre_q] + + template <class T1, class T2, class T3> + ``__sf_result`` legendre_next(unsigned l, T1 x, T2 Pl, T3 Plm1); + +Implements the three term recurrence relation for the Legendre +polynomials, this function can be used to create a sequence of +values evaluated at the same /x/, and for rising /l/. This recurrence +relation holds for Legendre Polynomials of both the first and second kinds. + +[equation legendre_4] + +For example we could produce a vector of the first 10 polynomial +values using: + + double x = 0.5; // Abscissa value + vector<double> v; + v.push_back(legendre_p(0, x)); + v.push_back(legendre_p(1, x)); + for(unsigned l = 1; l < 10; ++l) + v.push_back(legendre_next(l, x, v[l], v[l-1])); + // Double check values: + for(unsigned l = 1; l < 10; ++l) + assert(v[l] == legendre_p(l, x)); + +Formally the arguments are: + +[variablelist +[[l][The degree of the last polynomial calculated.]] +[[x][The abscissa value]] +[[Pl][The value of the polynomial evaluated at degree /l/.]] +[[Plm1][The value of the polynomial evaluated at degree /l-1/.]] +] + + template <class T1, class T2, class T3> + ``__sf_result`` legendre_next(unsigned l, unsigned m, T1 x, T2 Pl, T3 Plm1); + +Implements the three term recurrence relation for the Associated Legendre +polynomials, this function can be used to create a sequence of +values evaluated at the same /x/, and for rising /l/. + +[equation legendre_5] + +For example we could produce a vector of the first m+10 polynomial +values using: + + double x = 0.5; // Abscissa value + int m = 10; // order + vector<double> v; + v.push_back(legendre_p(m, m, x)); + v.push_back(legendre_p(1 + m, m, x)); + for(unsigned l = 1; l < 10; ++l) + v.push_back(legendre_next(l + 10, m, x, v[l], v[l-1])); + // Double check values: + for(unsigned l = 1; l < 10; ++l) + assert(v[l] == legendre_p(10 + l, m, x)); + +Formally the arguments are: + +[variablelist +[[l][The degree of the last polynomial calculated.]] +[[m][The order of the Associated Polynomial.]] +[[x][The abscissa value]] +[[Pl][The value of the polynomial evaluated at degree /l/.]] +[[Plm1][The value of the polynomial evaluated at degree /l-1/.]] +] + +[h4 Accuracy] + +The following table shows peak errors (in units of epsilon) +for various domains of input arguments. +Note that only results for the widest floating point type on the system are +given as narrower types have __zero_error. + +[table_legendre_p] + +[table_legendre_q] + +[table_legendre_p_associated_] + +Note that the worst errors occur when the order increases, values greater than +~120 are very unlikely to produce sensible results, especially in the associated +polynomial case when the degree is also large. Further the relative errors +are likely to grow arbitrarily large when the function is very close to a root. + +[h4 Testing] + +A mixture of spot tests of values calculated using functions.wolfram.com, +and randomly generated test data are +used: the test data was computed using +[@http://shoup.net/ntl/doc/RR.txt NTL::RR] at 1000-bit precision. + +[h4 Implementation] + +These functions are implemented using the stable three term +recurrence relations. These relations guarantee low absolute error +but cannot guarantee low relative error near one of the roots of the +polynomials. + +[endsect][/section:beta_function The Beta Function] +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/lgamma.qbk b/boost/libs/math/doc/sf/lgamma.qbk new file mode 100644 index 00000000..deccd8a7 --- /dev/null +++ b/boost/libs/math/doc/sf/lgamma.qbk @@ -0,0 +1,161 @@ +[section:lgamma Log Gamma] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/gamma.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` lgamma(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` lgamma(T z, const ``__Policy``&); + + template <class T> + ``__sf_result`` lgamma(T z, int* sign); + + template <class T, class ``__Policy``> + ``__sf_result`` lgamma(T z, int* sign, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +The [@http://en.wikipedia.org/wiki/Gamma_function lgamma function] is defined by: + +[equation lgamm1] + +The second form of the function takes a pointer to an integer, +which if non-null is set on output to the sign of tgamma(z). + +[optional_policy] + +[graph lgamma] + +There are effectively two versions of this function internally: a fully +generic version that is slow, but reasonably accurate, and a much more +efficient approximation that is used where the number of digits in the significand +of T correspond to a certain __lanczos. In practice, any built-in +floating-point type you will encounter has an appropriate __lanczos +defined for it. It is also possible, given enough machine time, to generate +further __lanczos's using the program libs/math/tools/lanczos_generator.cpp. + +The return type of these functions is computed using the __arg_promotion_rules: +the result is of type `double` if T is an integer type, or type T otherwise. + +[h4 Accuracy] + +The following table shows the peak errors (in units of epsilon) +found on various platforms +with various floating point types, along with comparisons to +various other libraries. Unless otherwise specified any +floating point type that is narrower than the one shown will have +__zero_error. + +Note that while the relative errors near the positive roots of lgamma +are very low, the lgamma function has an infinite number of irrational +roots for negative arguments: very close to these negative roots only +a low absolute error can be guaranteed. + +[table_lgamma] + +[h4 Testing] + +The main tests for this function involve comparisons against the logs of +the factorials which can be independently calculated to very high accuracy. + +Random tests in key problem areas are also used. + +[h4 Implementation] + +The generic version of this function is implemented using Sterling's approximation +for large arguments: + +[equation gamma6] + +For small arguments, the logarithm of tgamma is used. + +For negative /z/ the logarithm version of the +reflection formula is used: + +[equation lgamm3] + +For types of known precision, the __lanczos is used, a traits class +`boost::math::lanczos::lanczos_traits` maps type T to an appropriate +approximation. The logarithmic version of the __lanczos is: + +[equation lgamm4] + +Where L[sub e,g][space] is the Lanczos sum, scaled by e[super g]. + +As before the reflection formula is used for /z < 0/. + +When z is very near 1 or 2, then the logarithmic version of the __lanczos +suffers very badly from cancellation error: indeed for values sufficiently +close to 1 or 2, arbitrarily large relative errors can be obtained (even though +the absolute error is tiny). + +For types with up to 113 bits of precision +(up to and including 128-bit long doubles), root-preserving +rational approximations [jm_rationals] are used +over the intervals [1,2] and [2,3]. Over the interval [2,3] the approximation +form used is: + + lgamma(z) = (z-2)(z+1)(Y + R(z-2)); + +Where Y is a constant, and R(z-2) is the rational approximation: optimised +so that it's absolute error is tiny compared to Y. In addition +small values of z greater +than 3 can handled by argument reduction using the recurrence relation: + + lgamma(z+1) = log(z) + lgamma(z); + +Over the interval [1,2] two approximations have to be used, one for small z uses: + + lgamma(z) = (z-1)(z-2)(Y + R(z-1)); + +Once again Y is a constant, and R(z-1) is optimised for low absolute error +compared to Y. For z > 1.5 the above form wouldn't converge to a +minimax solution but this similar form does: + + lgamma(z) = (2-z)(1-z)(Y + R(2-z)); + +Finally for z < 1 the recurrence relation can be used to move to z > 1: + + lgamma(z) = lgamma(z+1) - log(z); + +Note that while this involves a subtraction, it appears not +to suffer from cancellation error: as z decreases from 1 +the `-log(z)` term grows positive much more +rapidly than the `lgamma(z+1)` term becomes negative. So in this +specific case, significant digits are preserved, rather than cancelled. + +For other types which do have a __lanczos defined for them +the current solution is as follows: imagine we +balance the two terms in the __lanczos by dividing the power term by its value +at /z = 1/, and then multiplying the Lanczos coefficients by the same value. +Now each term will take the value 1 at /z = 1/ and we can rearrange the power terms +in terms of log1p. Likewise if we subtract 1 from the Lanczos sum part +(algebraically, by subtracting the value of each term at /z = 1/), we obtain +a new summation that can be also be fed into log1p. Crucially, all of the +terms tend to zero, as /z -> 1/: + +[equation lgamm5] + +The C[sub k][space] terms in the above are the same as in the __lanczos. + +A similar rearrangement can be performed at /z = 2/: + +[equation lgamm6] + +[endsect][/section:lgamma The Log Gamma Function] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/license.qbk b/boost/libs/math/doc/sf/license.qbk new file mode 100644 index 00000000..6a3aeb99 --- /dev/null +++ b/boost/libs/math/doc/sf/license.qbk @@ -0,0 +1,6 @@ +[/ + Copyright 2006 - 2010 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/number_series.qbk b/boost/libs/math/doc/sf/number_series.qbk new file mode 100644 index 00000000..631cc294 --- /dev/null +++ b/boost/libs/math/doc/sf/number_series.qbk @@ -0,0 +1,270 @@ +[section:number_series Number Series] + +[section:bernoulli_numbers Bernoulli Numbers] + +[@https://en.wikipedia.org/wiki/Bernoulli_number Bernoulli numbers] +are a sequence of rational numbers useful for the Taylor series expansion, +Euler-Maclaurin formula, and the Riemann zeta function. + +Bernoulli numbers are used in evaluation of some Boost.Math functions, +including the __tgamma, __lgamma and polygamma functions. + +[h4 Single Bernoulli number] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/bernoulli.hpp> +`` + + namespace boost { namespace math { + + template <class T> + T bernoulli_b2n(const int n); // Single Bernoulli number (default policy). + + template <class T, class Policy> + T bernoulli_b2n(const int n, const Policy &pol); // User policy for errors etc. + + }} // namespaces + +[h4 Description] + +Both return the (2 * n)[super th] Bernoulli number B[sub 2n]. + +Note that since all odd numbered Bernoulli numbers are zero (apart from B[sub 1] which is -[frac12]) +the interface will only return the even numbered Bernoulli numbers. + +This function uses fast table lookup for low-indexed Bernoulli numbers, while larger values are calculated +as needed and then cached. The caching mechanism requires a certain amount of thread safety code, so +`unchecked_bernoulli_b2n` may provide a better interface for performance critical code. + +The final __Policy argument is optional and can be used to control the behaviour of the function: +how it handles errors, what level of precision to use, etc. + +Refer to __policy_section for more details. + +[h4 Examples] + +[import ../../example/bernoulli_example.cpp] +[bernoulli_example_1] + +[bernoulli_output_1] + +[h4 Single (unchecked) Bernoulli number] + +[h4 Synopsis] +`` +#include <boost/math/special_functions/bernoulli.hpp> + +`` + + template <> + struct max_bernoulli_b2n<T>; + + template<class T> + inline T unchecked_bernoulli_b2n(unsigned n); + +`unchecked_bernoulli_b2n` provides access to Bernoulli numbers [*without any checks for overflow or invalid parameters]. +It is implemented as a direct (and very fast) table lookup, and while not recommended for general use it can be useful +inside inner loops where the ultimate performance is required, and error checking is moved outside the loop. + +The largest value you can pass to `unchecked_bernoulli_b2n<>` is `max_bernoulli_b2n<>::value`: passing values greater than +that will result in a buffer overrun error, so it's clearly important to place the error handling in your own code +when using this direct interface. + +The value of `boost::math::max_bernoulli_b2n<T>::value` varies by the type T, for types `float`/`double`/`long double` +it's the largest value which doesn't overflow the target type: for example, `boost::math::max_bernoulli_b2n<double>::value` is 129. +However, for multiprecision types, it's the largest value for which the result can be represented as the ratio of two 64-bit +integers, for example `boost::math::max_bernoulli_b2n<boost::multiprecision::cpp_dec_float_50>::value` is just 17. Of course +larger indexes can be passed to `bernoulli_b2n<T>(n)`, but then you lose fast table lookup (i.e. values may need to be calculated). + +[bernoulli_example_4] +[bernoulli_output_4] + +[h4 Multiple Bernoulli Numbers] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/bernoulli.hpp> +`` + + namespace boost { namespace math { + + // Multiple Bernoulli numbers (default policy). + template <class T, class OutputIterator> + OutputIterator bernoulli_b2n( + int start_index, + unsigned number_of_bernoullis_b2n, + OutputIterator out_it); + + // Multiple Bernoulli numbers (user policy). + template <class T, class OutputIterator, class Policy> + OutputIterator bernoulli_b2n( + int start_index, + unsigned number_of_bernoullis_b2n, + OutputIterator out_it, + const Policy& pol); + }} // namespaces + +[h4 Description] + +Two versions of the Bernoulli number function are provided to compute multiple Bernoulli numbers +with one call (one with default policy and the other allowing a user-defined policy). + +These return a series of Bernoulli numbers: + +[:B[sub 2*start_index],B[sub 2*(start_index+1)],...,B[sub 2*(start_index+number_of_bernoullis_b2n-1)]] + +[h4 Examples] +[bernoulli_example_2] +[bernoulli_output_2] +[bernoulli_example_3] +[bernoulli_output_3] + +The source of this example is at [@../../example/bernoulli_example.cpp bernoulli_example.cpp] + +[h4 Accuracy] + +All the functions usually return values within one ULP (unit in the last place) for the floating-point type. + +[h4 Implementation] + +The implementation details are in [@../../include/boost/math/special_functions/detail/bernoulli_details.hpp bernoulli_details.hpp] +and [@../../include/boost/math/special_functions/detail/unchecked_bernoulli.hpp unchecked_bernoulli.hpp]. + +For `i <= max_bernoulli_index<T>::value` this is implemented by simple table lookup from a statically initialized table; +for larger values of `i`, this is implemented by the Tangent Numbers algorithm as described in the paper: +Fast Computation of Bernoulli, Tangent and Secant Numbers, Richard P. Brent and David Harvey, +[@http://arxiv.org/pdf/1108.0286v3.pdf] (2011). + +[@http://mathworld.wolfram.com/TangentNumber.html Tangent (or Zag) numbers] +(an even alternating permutation number) are defined +and their generating function is also given therein. + +The relation of Tangent numbers with Bernoulli numbers ['B[sub i]] +is given by Brent and Harvey's equation 14: + +__spaces[equation tangent_numbers] + +Their relation with Bernoulli numbers ['B[sub i]] are defined by + +if i > 0 and i is even then +__spaces[equation bernoulli_numbers] [br] +elseif i == 0 then ['B[sub i]] = 1 [br] +elseif i == 1 then ['B[sub i]] = -1/2 [br] +elseif i < 0 or i is odd then ['B[sub i]] = 0 + +Note that computed values are stored in a fixed-size table, access is thread safe via atomic operations (i.e. lock +free programming), this imparts a much lower overhead on access to cached values than might otherwise be expected - +typically for multiprecision types the cost of thread synchronisation is negligible, while for built in types +this code is not normally executed anyway. For very large arguments which cannot be reasonably computed or +stored in our cache, an asymptotic expansion [@http://www.luschny.de/math/primes/bernincl.html due to Luschny] is used: + +[equation bernoulli_numbers2] + +[endsect] [/section:bernoulli_numbers Bernoulli Numbers] + + +[section:tangent_numbers Tangent Numbers] + +[@http://en.wikipedia.org/wiki/Tangent_numbers Tangent numbers], +also called a zag function. See also +[@http://mathworld.wolfram.com/TangentNumber.html Tangent number]. + +The first few values are 1, 2, 16, 272, 7936, 353792, 22368256, 1903757312 ... +(sequence [@http://oeis.org/A000182 A000182 in OEIS]). +They are called tangent numbers because they appear as +numerators in the Maclaurin series of `tan(x)`. + +[*Important:] there are two competing definitions of Tangent numbers in common use +(depending on whether you take the even or odd numbered values as non-zero), we use: + +[equation tangent_number_def] + +Which gives: + +[equation tangent_number_def2] + +Tangent numbers are used in the computation of Bernoulli numbers, +but are also made available here. + +[h4 Synopsis] +`` +#include <boost/math/special_functions/detail/bernoulli.hpp> +`` + + template <class T> + T tangent_t2n(const int i); // Single tangent number (default policy). + + template <class T, class Policy> + T tangent_t2n(const int i, const Policy &pol); // Single tangent number (user policy). + + // Multiple tangent numbers (default policy). + template <class T, class OutputIterator> + OutputIterator tangent_t2n(const int start_index, + const unsigned number_of_tangent_t2n, + OutputIterator out_it); + + // Multiple tangent numbers (user policy). + template <class T, class OutputIterator, class Policy> + OutputIterator tangent_t2n(const int start_index, + const unsigned number_of_tangent_t2n, + OutputIterator out_it, + const Policy& pol); + +[h4 Examples] + +[tangent_example_1] + +The output is: +[tangent_output_1] + +The source of this example is at [@../../example/bernoulli_example.cpp bernoulli_example.cpp] + +[h4 Implementation] + +Tangent numbers are calculated as intermediates in the calculation of the __bernoulli_numbers: +refer to the __bernoulli_numbers documentation for details. + +[endsect] [/section:tangent_numbers Tangent Numbers] + +[section:primes Prime Numbers] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/prime.hpp> +`` + + namespace boost { namespace math { + + template <class Policy> + boost::uint32_t prime(unsigned n, const Policy& pol); + + boost::uint32_t prime(unsigned n); + + static const unsigned max_prime = 10000; + + }} // namespaces + +[h4 Description] + +The function `prime` provides fast table lookup to the first 10000 prime numbers (starting from 2 +as the zeroth prime: as 1 isn't terribly useful in practice). There are two function signatures +one of which takes an optional __Policy as the second parameter to control error handling. + +The constant `max_prime` is the largest value you can pass to `prime` without incurring an error. + +Passing a value greater than `max_prime` results in a __domain_error being raised. + +[endsect] [/section:primes] + +[endsect] [/Number Series] + +[/ + Copyright 2013, 2014 Nikhar Agrawal, Christopher Kormanyos, John Maddock, Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/owens_t.qbk b/boost/libs/math/doc/sf/owens_t.qbk new file mode 100644 index 00000000..536924f7 --- /dev/null +++ b/boost/libs/math/doc/sf/owens_t.qbk @@ -0,0 +1,136 @@ +[section:owens_t Owen's T function] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/owens_t.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` owens_t(T h, T a); + + template <class T, class ``__Policy``> + ``__sf_result`` owens_t(T h, T a, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +Returns the +[@http://en.wikipedia.org/wiki/Owen%27s_T_function Owens_t function] +of ['h] and ['a]. + +[optional_policy] + +[sixemspace][sixemspace][equation owens_t] + +[$../graphs/plot_owens_t.png] + +The function `owens_t(h, a)` gives the probability +of the event ['(X > h and 0 < Y < a * X)], +where ['X] and ['Y] are independent standard normal random variables. + +For h and a > 0, T(h,a), +gives the volume of an uncorrelated bivariate normal distribution +with zero means and unit variances over the area between +['y = ax] and ['y = 0] and to the right of ['x = h]. + +That is the area shaded in the figure below (Owens 1956). + +[graph owens_integration_area] + +and is also illustrated by a 3D plot. + +[$../graphs/plot_owens_3d_xyp.png] + +This function is used in the computation of the __skew_normal_distrib. +It is also used in the computation of bivariate and +multivariate normal distribution probabilities. +The return type of this function is computed using the __arg_promotion_rules: +the result is of type `double` when T is an integer type, and type T otherwise. + +Owen's original paper (page 1077) provides some additional corner cases. + +[: ['T(h, 0) = 0]] + +[:['T(0, a) = [frac12][pi] arctan(a)]] + +[:['T(h, 1) = [frac12] G(h) \[1 - G(h)\]]] + +[:['T(h, [infin]) = G(|h|)]] + +where G(h) is the univariate normal with zero mean and unit variance integral from -[infin] to h. + +[h4 Accuracy] + +Over the built-in types and range tested, +errors are less than 10 * std::numeric_limits<RealType>::epsilon(). + +[table_owens_t] + +[h4 Testing] + +Test data was generated by Patefield and Tandy algorithms T1 and T4, +and also the suggested reference routine T7. + +* T1 was rejected if the result was too small compared to `atan(a)` (ie cancellation), +* T4 was rejected if there was no convergence, +* Both were rejected if they didn't agree. + +Over the built-in types and range tested, +errors are less than 10 std::numeric_limits<RealType>::epsilon(). + +However, that there was a whole domain (large ['h], small ['a]) +where it was not possible to generate any reliable test values +(all the methods got rejected for one reason or another). + +There are also two sets of sanity tests: spot values are computed using __Mathematica and __R. + + +[h4 Implementation] + +The function was proposed and evaluated by +[@http://projecteuclid.org/DPubS?service=UI&version=1.0&verb=Display&handle=euclid.aoms/1177728074 +Donald. B. Owen, Tables for computing bivariate normal probabilities, +Ann. Math. Statist., 27, 1075-1090 (1956)]. + +The algorithms of Patefield, M. and Tandy, D. +"Fast and accurate Calculation of Owen's T-Function", Journal of Statistical Software, 5 (5), 1 - 25 (2000) +are adapted for C++ with arbitrary RealType. + +The Patefield-Tandy algorithm provides six methods of evalualution (T1 to T6); +the best method is selected according to the values of ['a] and ['h]. +See the original paper and the source in +[@../../../../boost/math/special_functions/owens_t.hpp owens_t.hpp] for details. + +The Patefield-Tandy algorithm is accurate to approximately 20 decimal places, so for +types with greater precision we use: + +* A modified version of T1 which folds the calculation of ['atan(h)] into the T1 series +(to avoid subtracting two values similar in magnitude), and then accelerates the +resulting alternating series using method 1 from H. Cohen, F. Rodriguez Villegas, D. Zagier, +"Convergence acceleration of alternating series", Bonn, (1991). The result is valid everywhere, +but doesn't always converge, or may become too divergent in the first few terms to sum accurately. +This is used for ['ah < 1]. +* A modified version of T2 which is accelerated in the same manner as T1. This is used for ['h > 1]. +* A version of T4 only when both T1 and T2 have failed to produce an accurate answer. +* Fallback to the Patefiled Tandy algorithm when all the above methods fail: this happens not at all +for our test data at 100 decimal digits precision. However, there is a difficult area when +['a] is very close to 1 and the precision increases which may cause this to happen in very exceptional +circumstances. + +Using the above algorithm and a 100-decimal digit type, results accurate to 80 decimal places were obtained +in the difficult area where ['a] is close to 1, and greater than 95 decimal places elsewhere. + +[endsect] [/section:owens_t The owens_t Function] + +[/ + Copyright 2012 Bejamin Sobotta, John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + + diff --git a/boost/libs/math/doc/sf/poisson_optimisation.qbk b/boost/libs/math/doc/sf/poisson_optimisation.qbk new file mode 100644 index 00000000..1b16cfa7 --- /dev/null +++ b/boost/libs/math/doc/sf/poisson_optimisation.qbk @@ -0,0 +1,121 @@ +[sect:optim Optimisation Examples} + +[h4 Poisson Distribution - Optimization and Accuracy is quite complicated. + +The general formula for calculating the CDF uses the incomplete gamma thus: + + return gamma_q(k+1, mean); + +But the case of small integral k is *very* common, so it is worth considering optimisation. + +The first obvious step is to use a finite sum of each pdf (Probability *density* function) +for each value of k to build up the cdf (*cumulative* distribution function). + +This could be done using the pdf function for the distribution, +for which there are two equivalent formulae: + + return exp(-mean + log(mean) * k - lgamma(k+1)); + + return gamma_p_derivative(k+1, mean); + +The pdf would probably be more accurate using gamma_p_derivative. + +The reason is that the expression: + + -mean + log(mean) * k - lgamma(k+1) + +Will produce a value much smaller than the largest of the terms, so you get +cancellation error: and then when you pass the result to exp() which +converts the absolute error in its argument to a relative error in the +result (explanation available if required), you effectively amplify the +error further still. + +gamma_p_derivative is just a thin wrapper around some of the internals of +the incomplete gamma, it does its utmost to avoid issues like this, because +this function is responsible for virtually all of the error in the result. +Hopefully further advances in the future might improve things even further +(what is really needed is an 'accurate' pow(1+x) function, but that's a whole +other story!). + +But calling pdf function makes repeated, redundant, checks on the value of mean and k, + + result += pdf(dist, i); + +so it may be faster to substitute the formula for the pdf in a summation loop + + result += exp(-mean) * pow(mean, i) / unchecked_factorial(i); + +(simplified by removing casting from RealType). + +Of course, mean is unchanged during this summation, +so exp(mean) should only be calculated once, outside the loop. + +Optimising compilers 'might' do this, but one can easily ensure this. + +Obviously too, k must be small enough that unchecked_factorial is OK: +34 is an obvious choice as the limit for 32-bit float. +For larger k, the number of iterations is like to be uneconomic. +Only experiment can determine the optimum value of k +for any particular RealType (float, double...) + +But also note that + +The incomplete gamma already optimises this case +(argument "a" is a small int), +although only when the result q (1-p) would be < 0.5. + +And moreover, in the above series, each term can be calculated +from the previous one much more efficiently: + +cdf = sum from 0 to k of C[k] + +with: + +C[0] = exp(-mean) + +C[N+1] = C[N] * mean / (N+1) + +So hopefully that's: + + { + RealType result = exp(-mean); + RealType term = result; + for(int i = 1; i <= k; ++i) + { // cdf is sum of pdfs. + term *= mean / i; + result += term; + } + return result; + } + +This is exactly the same finite sum as used by gamma_p/gamma_q internally. + +As explained previously it's only used when the result + +p > 0.5 or 1-p = q < 0.5. + +The slight danger when using the sum directly like this, is that if +the mean is small and k is large then you're calculating a value ~1, so +conceivably you might overshoot slightly. For this and other reasons in the +case when p < 0.5 and q > 0.5 gamma_p/gamma_q use a different (infinite but +rapidly converging) sum, so that danger isn't present since you always +calculate the smaller of p and q. + +So... it's tempting to suggest that you just call gamma_p/gamma_q as +required. However, there is a slight benefit for the k = 0 case because you +avoid all the internal logic inside gamma_p/gamma_q trying to figure out +which method to use etc. + +For the incomplete beta function, there are no simple finite sums +available (that I know of yet anyway), so when there's a choice between a +finite sum of the PDF and an incomplete beta call, the finite sum may indeed +win out in that case. + +[endsect][/sect:optim Optimisation Examples} + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/boost/libs/math/doc/sf/polygamma.qbk b/boost/libs/math/doc/sf/polygamma.qbk new file mode 100644 index 00000000..5155095a --- /dev/null +++ b/boost/libs/math/doc/sf/polygamma.qbk @@ -0,0 +1,110 @@ +[section:polygamma Polygamma] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/polygamma.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` polygamma(int n, T z); + + template <class T, class ``__Policy``> + ``__sf_result`` polygamma(int n, T z, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +Returns the polygamma function of /x/. Polygamma is defined as the n'th +derivative of the digamma function: + +[equation polygamma1] + +The following graphs illustrate the behaviour of the function for odd and even order: + +[graph polygamma2] +[graph polygamma3] + +[optional_policy] + +The return type of this function is computed using the __arg_promotion_rules: +the result is of type `double` when T is an integer type, and type T otherwise. + +[h4 Accuracy] + +The following table shows the peak errors (in units of epsilon) +found on various platforms with various floating point types. +Unless otherwise specified any floating point type that is narrower +than the one shown will have __zero_error. + +[table_polygamma] + +As shown above, error rates are generally very acceptable for moderately sized +arguments. Error rates should stay low for exact inputs, however, please note that the +function becomes exceptionally sensitive to small changes in input for large n and negative x, +indeed for cases where ['n!] would overflow, the function changes directly from -[infin] to ++[infin] somewhere between each negative integer - ['these cases are not handled correctly]. + +[*For these reasons results should be treated with extreme caution when /n/ is large and x negative]. + +[h4 Testing] + +Testing is against Mathematica generated spot values to 35 digit precision. + +[h4 Implementation] + +For x < 0 the following reflection formula is used: + +[equation polygamma2] + +The n'th derivative of ['cot(x)] is tabulated for small /n/, and for larger n +has the general form: + +[equation polygamma3] + +The coefficients of the cosine terms can be calculated iteratively starting +from ['C[sub 1,0] = -1] and then using + +[equation polygamma7] + +to generate coefficients for n+1. + +Note that every other coefficient is zero, and therefore what we have are +even or odd polynomials depending on whether n is even or odd. + +Once x is positive then we have two methods available to us, for small x +we use the series expansion: + +[equation polygamma4] + +Note that the evaluation of zeta functions at integer values is essentially a table lookup +as __zeta is optimized for those cases. + +For large x we use the asymptotic expansion: + +[equation polygamma5] + +For x in-between the two extremes we use the relation: + +[equation polygamma6] + +to make x large enough for the asymptotic expansion to be used. + +There are also two special cases: + +[equation polygamma8] + +[equation polygamma9] + +[endsect][/section:polygamma The Polygamma Function] + +[/ + Copyright 2014 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/pow.qbk b/boost/libs/math/doc/sf/pow.qbk new file mode 100644 index 00000000..59f33555 --- /dev/null +++ b/boost/libs/math/doc/sf/pow.qbk @@ -0,0 +1,157 @@ +[section:ct_pow Compile Time Power of a Runtime Base] + +The `pow` function effectively computes the compile-time integral +power of a run-time base. + +[h4 Synopsis] + +[@../../../../boost/math/special_functions/pow.hpp `#include <boost/math/special_functions/pow.hpp>`] + + namespace boost { namespace math { + + template <int N, typename T> + ``__sf_result`` pow(T base); + + template <int N, typename T, class Policy> + ``__sf_result`` pow(T base, const Policy& policy); + + }} + +[h4 Rationale and Usage] + +Computing the power of a number with an exponent that is known +at compile time is a common need for programmers. In such cases, +the usual method is to avoid the overhead implied by +the `pow`, `powf` and `powl` C functions by hardcoding an expression +such as: + + // Hand-written 8th power of a 'base' variable + double result = base*base*base*base*base*base*base*base; + +However, this kind of expression is not really readable (knowing the +value of the exponent involves counting the number of occurrences of /base/), +error-prone (it's easy to forget an occurrence), syntactically bulky, and +non-optimal in terms of performance. + +The pow function of Boost.Math helps writing this kind expression along +with solving all the problems listed above: + + // 8th power of a 'base' variable using math::pow + double result = pow<8>(base); + +The expression is now shorter, easier to read, safer, and even faster. +Indeed, `pow` will compute the expression such that only log2(N) +products are made for a power of N. For instance in the +example above, the resulting expression will be the same as if we had +written this, with only one computation of each identical subexpression: + + // Internal effect of pow<8>(base) + double result = ((base*base)*(base*base))*((base*base)*(base*base)); + +Only 3 different products were actually computed. + + +[h4 Return Type] + +The return type of these functions is computed using the __arg_promotion_rules. +For example: + +* If T is a `float`, the return type is a `float`. +* If T is a `long double`, the return type is a `long double`. +* Otherwise, the return type is a `double`. + +[h4 Policies] + +[optional_policy] + +[h4 Error Handling] + +Two cases of errors can occur when using `pow`: + +* In case of null base and negative exponent, an __overflow_error occurs since +this operation is a division by 0 (it equals to 1/0). +* In case of null base and null exponent, an __indeterminate_result_error +occurs since the result of this operation is indeterminate. +Those errors follow the +[link math_toolkit.error_handling +general policies of error handling in Boost.Math]. + +The default overflow error policy is `throw_on_error`. A call like `pow<-2>(0)` +will thus throw a `std::overflow_error` exception. As shown in the +link given above, other error handling policies can be used: + +* `errno_on_error`: Sets `::errno` to `ERANGE` and returns `std::numeric_limits<T>::infinity()`. +* `ignore_error`: Returns `std::numeric_limits<T>::infinity()`. +* `user_error`: Returns the result of `boost::math::policies::user_overflow_error`: + this function must be defined by the user. + +The default indeterminate result error policy is `ignore_error`, which for this +function returns 1 since it's the most commonly chosen result for a power of 0. +Here again, other error handling policies can be used: + +* `throw_on_error`: Throws `std::domain_error` +* `errno_on_error`: Sets `::errno` to `EDOM` and returns 1. +* `user_error`: Returns the result of `boost::math::policies::user_indeterminate_result_error`: + this function must be defined by the user. + +Here is an example of error handling customization where we want to +specify the result that has to be returned in case of error. We will +thus use the `user_error` policy, by passing as second argument an +instance of an overflow_error policy templated with `user_error`: + + // First we open the boost::math::policies namespace and define the `user_overflow_error` + // by making it return the value we want in case of error (-1 here) + + namespace boost { namespace math { namespace policies { + template <class T> + T user_overflow_error(const char*, const char*, const T&) + { return -1; } + }}} + + + // Then we invoke pow and indicate that we want to use the user_error policy + using boost::math::policies; + double result = pow<-5>(base, policy<overflow_error<user_error> >()); + + // We can now test the returned value and treat the special case if needed: + if (result == -1) + { + // there was an error, do something... + } + +Another way is to redefine the default `overflow_error` policy by using the +BOOST_MATH_OVERFLOW_ERROR_POLICY macro. Once the `user_overflow_error` function +is defined as above, we can achieve the same result like this: + + // Redefine the default error_overflow policy + #define BOOST_MATH_OVERFLOW_ERROR_POLICY user_error + #include <boost/math/special_functions/pow.hpp> + + // From this point, passing a policy in argument is no longer needed, a call like this one + // will return -1 in case of error: + + double result = pow<-5>(base); + + +[h4 Acknowledgements] + +Bruno Lalande submitted this addition to Boost.Math. + +''' +Thanks to Joaquín López Muñoz and Scott McMurray for their help in +improving the implementation. +''' + +[h4 References] + +D.E. Knuth, ['The Art of Computer Programming, Vol. 2: Seminumerical Algorithms], 2nd ed., Addison-Wesley, Reading, MA, 1981 + +[endsect] + +[/ + Copyright 2008 Bruno Lalande. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/powers.qbk b/boost/libs/math/doc/sf/powers.qbk new file mode 100644 index 00000000..e1ef2593 --- /dev/null +++ b/boost/libs/math/doc/sf/powers.qbk @@ -0,0 +1,350 @@ +[section:powers Basic Functions] + +[section:sin_pi sin_pi] + +`` +#include <boost/math/special_functions/sin_pi.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` sin_pi(T x); + + template <class T, class ``__Policy``> + ``__sf_result`` sin_pi(T x, const ``__Policy``&); + + }} // namespaces + +Returns the sine of ['[pi]x]. + +The return type of this function is computed using the __arg_promotion_rules: +the return is `double` when /x/ is an integer type and T otherwise. + +[optional_policy] + +This function performs exact all-integer arithmetic argument reduction before computing the sine of ['[pi]x]. + +[table_sin_pi] + +[endsect] + +[section:cos_pi cos_pi] + +`` +#include <boost/math/special_functions/cos_pi.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` cos_pi(T x); + + template <class T, class ``__Policy``> + ``__sf_result`` cos_pi(T x, const ``__Policy``&); + + }} // namespaces + +Returns the cosine of ['[pi]x]. + +The return type of this function is computed using the __arg_promotion_rules: +the return is `double` when /x/ is an integer type and T otherwise. + +[optional_policy] + +This function performs exact all-integer arithmetic argument reduction before computing the cosine of ['[pi]x]. + +[table_cos_pi] + +[endsect] + +[section:log1p log1p] + +`` +#include <boost/math/special_functions/log1p.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` log1p(T x); + + template <class T, class ``__Policy``> + ``__sf_result`` log1p(T x, const ``__Policy``&); + + }} // namespaces + +Returns the natural logarithm of `x+1`. + +The return type of this function is computed using the __arg_promotion_rules: +the return is `double` when /x/ is an integer type and T otherwise. + +[optional_policy] + +There are many situations where it is desirable to compute `log(x+1)`. +However, for small `x` then `x+1` suffers from catastrophic cancellation errors +so that `x+1 == 1` and `log(x+1) == 0`, when in fact for very small x, the +best approximation to `log(x+1)` would be `x`. `log1p` calculates the best +approximation to `log(1+x)` using a Taylor series expansion for accuracy +(less than __te). +Alternatively note that there are faster methods available, +for example using the equivalence: + + log(1+x) == (log(1+x) * x) / ((1+x) - 1) + +However, experience has shown that these methods tend to fail quite spectacularly +once the compiler's optimizations are turned on, consequently they are +used only when known not to break with a particular compiler. +In contrast, the series expansion method seems to be reasonably +immune to optimizer-induced errors. + +Finally when BOOST_HAS_LOG1P is defined then the `float/double/long double` +specializations of this template simply forward to the platform's +native (POSIX) implementation of this function. + +The following graph illustrates the behaviour of log1p: + +[graph log1p] + +[h4 Accuracy] + +For built in floating point types `log1p` +should have approximately 1 epsilon accuracy. + +[table_log1p] + +[h4 Testing] + +A mixture of spot test sanity checks, and random high precision test values +calculated using NTL::RR at 1000-bit precision. + +[endsect] + +[section:expm1 expm1] + +`` +#include <boost/math/special_functions/expm1.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` expm1(T x); + + template <class T, class ``__Policy``> + ``__sf_result`` expm1(T x, const ``__Policy``&); + + }} // namespaces + +Returns e[super x] - 1. + +The return type of this function is computed using the __arg_promotion_rules: +the return is `double` when /x/ is an integer type and T otherwise. + +[optional_policy] + +For small x, then __ex is very close to 1, as a result calculating __exm1 results +in catastrophic cancellation errors when x is small. `expm1` calculates __exm1 using +rational approximations (for up to 128-bit long doubles), otherwise via +a series expansion when x is small (giving an accuracy of less than __te). + +Finally when BOOST_HAS_EXPM1 is defined then the `float/double/long double` +specializations of this template simply forward to the platform's +native (POSIX) implementation of this function. + +The following graph illustrates the behaviour of expm1: + +[graph expm1] + +[h4 Accuracy] + +For built in floating point types `expm1` +should have approximately 1 epsilon accuracy. + +[table_expm1] + +[h4 Testing] + +A mixture of spot test sanity checks, and random high precision test values +calculated using NTL::RR at 1000-bit precision. + +[endsect] + +[section:cbrt cbrt] + +`` +#include <boost/math/special_functions/cbrt.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` cbrt(T x); + + template <class T, class ``__Policy``> + ``__sf_result`` cbrt(T x, const ``__Policy``&); + + }} // namespaces + +Returns the cubed root of x: x[super 1/3]. + +The return type of this function is computed using the __arg_promotion_rules: +the return is `double` when /x/ is an integer type and T otherwise. + +[optional_policy] + +Implemented using Halley iteration. + +The following graph illustrates the behaviour of cbrt: + +[graph cbrt] + +[h4 Accuracy] + +For built in floating-point types `cbrt` +should have approximately 2 epsilon accuracy. + +[table_cbrt] + +[h4 Testing] + +A mixture of spot test sanity checks, and random high precision test values +calculated using NTL::RR at 1000-bit precision. + +[endsect] + +[section:sqrt1pm1 sqrt1pm1] + +`` +#include <boost/math/special_functions/sqrt1pm1.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` sqrt1pm1(T x); + + template <class T, class ``__Policy``> + ``__sf_result`` sqrt1pm1(T x, const ``__Policy``&); + + }} // namespaces + +Returns `sqrt(1+x) - 1`. + +The return type of this function is computed using the __arg_promotion_rules: +the return is `double` when /x/ is an integer type and T otherwise. + +[optional_policy] + +This function is useful when you need the difference between sqrt(x) and 1, when +x is itself close to 1. + +Implemented in terms of `log1p` and `expm1`. + +The following graph illustrates the behaviour of sqrt1pm1: + +[graph sqrt1pm1] + +[h4 Accuracy] + +For built in floating-point types `sqrt1pm1` +should have approximately 3 epsilon accuracy. + +[table_sqrt1pm1] + +[h4 Testing] + +A selection of random high precision test values +calculated using NTL::RR at 1000-bit precision. + +[endsect] + +[section:powm1 powm1] + +`` +#include <boost/math/special_functions/powm1.hpp> +`` + + namespace boost{ namespace math{ + + template <class T1, class T2> + ``__sf_result`` powm1(T1 x, T2 y); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` powm1(T1 x, T2 y, const ``__Policy``&); + + }} // namespaces + +Returns x[super y ] - 1. + +The return type of this function is computed using the __arg_promotion_rules +when T1 and T2 are dufferent types. + +[optional_policy] + +There are two domains where this is useful: when y is very small, or when +x is close to 1. + +Implemented in terms of `expm1`. + +The following graph illustrates the behaviour of powm1: + +[graph powm1] + +[h4 Accuracy] + +Should have approximately 2-3 epsilon accuracy. + +[table_powm1] + +[h4 Testing] + +A selection of random high precision test values +calculated using NTL::RR at 1000-bit precision. + +[endsect] + +[section:hypot hypot] + + template <class T1, class T2> + ``__sf_result`` hypot(T1 x, T2 y); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` hypot(T1 x, T2 y, const ``__Policy``&); + +__effects computes [equation hypot] +in such a way as to avoid undue underflow and overflow. + +The return type of this function is computed using the __arg_promotion_rules +when T1 and T2 are of different types. + +[optional_policy] + +When calculating [equation hypot] it's quite easy for the intermediate terms to either +overflow or underflow, even though the result is in fact perfectly representable. + +[h4 Implementation] + +The function is even and symmetric in x and y, so first take assume +['x,y > 0] and ['x > y] (we can permute the arguments if this is not the case). + +Then if ['x * [epsilon][space] >= y] we can simply return /x/. + +Otherwise the result is given by: + +[equation hypot2] + +[endsect] + +[include pow.qbk] + + +[endsect][/section:powers Logs, Powers, Roots and Exponentials] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/sinc.qbk b/boost/libs/math/doc/sf/sinc.qbk new file mode 100644 index 00000000..4a83df0e --- /dev/null +++ b/boost/libs/math/doc/sf/sinc.qbk @@ -0,0 +1,110 @@ +[/ math.qbk + Copyright 2006 Hubert Holin and John Maddock. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + +[section:sinc Sinus Cardinal and Hyperbolic Sinus Cardinal Functions] + +[section:sinc_overview Sinus Cardinal and Hyperbolic Sinus Cardinal Functions Overview] + +The [@http://mathworld.wolfram.com/SincFunction.html Sinus Cardinal family of functions] +(indexed by the family of indices [^a > 0]) +is defined by + +[equation special_functions_blurb20] + +it sees heavy use in signal processing tasks. + +By analogy, the +[@http://mathworld.wolfram.com/SinhcFunction.htm Hyperbolic Sinus Cardinal] +family of functions +(also indexed by the family of indices [^a > 0]) is defined by + +[equation special_functions_blurb22] + +These two families of functions are composed of entire functions. + +These functions (__sinc_pi and __sinhc_pi) are needed by +[@http://www.boost.org/libs/math/quaternion/quaternion.html our implementation] +of [@http://mathworld.wolfram.com/Quaternion.html quaternions] +and [@http://mathworld.wolfram.com/Octonion.html octonions]. + +[: ['[*Sinus Cardinal of index pi (purple) and Hyperbolic Sinus Cardinal of index pi (red) on R]]] +[: [$../graphs/sinc_pi_and_sinhc_pi_on_r.png]] + +[endsect] + +[section sinc_pi] + +`` +#include <boost/math/special_functions/sinc.hpp> +`` + + template<class T> + ``__sf_result`` sinc_pi(const T x); + + template<class T, class ``__Policy``> + ``__sf_result`` sinc_pi(const T x, const ``__Policy``&); + + template<class T, template<typename> class U> + U<T> sinc_pi(const U<T> x); + + template<class T, template<typename> class U, class ``__Policy``> + U<T> sinc_pi(const U<T> x, const ``__Policy``&); + +Computes +[link math_toolkit.sinc.sinc_overview +the Sinus Cardinal] of x: + + sinc_pi(x) = sin(x) / x + +The second form is for complex numbers, +quaternions, octonions etc. Taylor series are used at the origin +to ensure accuracy. + +[graph sinc_pi] + +[optional_policy] + +[endsect] + +[section sinhc_pi] + +`` +#include <boost/math/special_functions/sinhc.hpp> +`` + + template<class T> + ``__sf_result`` sinhc_pi(const T x); + + template<class T, class ``__Policy``> + ``__sf_result`` sinhc_pi(const T x, const ``__Policy``&); + + template<typename T, template<typename> class U> + U<T> sinhc_pi(const U<T> x); + + template<class T, template<typename> class U, class ``__Policy``> + U<T> sinhc_pi(const U<T> x, const ``__Policy``&); + +Computes http://mathworld.wolfram.com/SinhcFunction.html +[link math_toolkit.sinc.sinc_overview +the Hyperbolic Sinus Cardinal] of x: + + sinhc_pi(x) = sinh(x) / x + +The second form is for +complex numbers, quaternions, octonions etc. Taylor series are used at the origin +to ensure accuracy. + +The return type of the first form is computed using the __arg_promotion_rules +when T is an integer type. + +[optional_policy] + +[graph sinhc_pi] + +[endsect] + +[endsect] diff --git a/boost/libs/math/doc/sf/spherical_harmonic.qbk b/boost/libs/math/doc/sf/spherical_harmonic.qbk new file mode 100644 index 00000000..830521f9 --- /dev/null +++ b/boost/libs/math/doc/sf/spherical_harmonic.qbk @@ -0,0 +1,144 @@ +[section:sph_harm Spherical Harmonics] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/spherical_harmonic.hpp> +`` + + namespace boost{ namespace math{ + + template <class T1, class T2> + std::complex<``__sf_result``> spherical_harmonic(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class ``__Policy``> + std::complex<``__sf_result``> spherical_harmonic(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&); + + template <class T1, class T2> + ``__sf_result`` spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +The return type of these functions is computed using the __arg_promotion_rules +when T1 and T2 are different types. + +[optional_policy] + + template <class T1, class T2> + std::complex<``__sf_result``> spherical_harmonic(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class ``__Policy``> + std::complex<``__sf_result``> spherical_harmonic(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&); + +Returns the value of the Spherical Harmonic Y[sub n][super m](theta, phi): + +[equation spherical_0] + +The spherical harmonics Y[sub n][super m](theta, phi) are the angular +portion of the solution to Laplace's equation in spherical coordinates +where azimuthal symmetry is not present. + +[caution Care must be taken in correctly identifying the arguments to this +function: [theta][space] is taken as the polar (colatitudinal) coordinate +with [theta][space] in \[0, [pi]\], and [phi][space] as the azimuthal (longitudinal) +coordinate with [phi][space] in \[0,2[pi]). This is the convention used in Physics, +and matches the definition used by +[@http://documents.wolfram.com/mathematica/functions/SphericalHarmonicY +Mathematica in the function SpericalHarmonicY], +but is opposite to the usual mathematical conventions. + +Some other sources include an additional Condon-Shortley phase term of +(-1)[super m] in the definition of this function: note however that our +definition of the associated Legendre polynomial already includes this term. + +This implementation returns zero for m > n + +For [theta][space] outside \[0, [pi]\] and [phi][space] outside \[0, 2[pi]\] this +implementation follows the convention used by Mathematica: +the function is periodic with period [pi][space] in [theta][space] and 2[pi][space] in +[phi]. Please note that this is not the behaviour one would get +from a casual application of the function's definition. Cautious users +should keep [theta][space] and [phi][space] to the range \[0, [pi]\] and +\[0, 2[pi]\] respectively. + +See: [@http://mathworld.wolfram.com/SphericalHarmonic.html +Weisstein, Eric W. "Spherical Harmonic." +From MathWorld--A Wolfram Web Resource]. ] + + template <class T1, class T2> + ``__sf_result`` spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&); + +Returns the real part of Y[sub n][super m](theta, phi): + +[equation spherical_1] + + template <class T1, class T2> + ``__sf_result`` spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class ``__Policy``> + ``__sf_result`` spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const ``__Policy``&); + +Returns the imaginary part of Y[sub n][super m](theta, phi): + +[equation spherical_2] + +[h4 Accuracy] + +The following table shows peak errors for various domains of input arguments. +Note that only results for the widest floating point type on the system are +given as narrower types have __zero_error. Peak errors are the same +for both the real and imaginary parts, as the error is dominated by +calculation of the associated Legendre polynomials: especially near the +roots of the associated Legendre function. + +All values are in units of epsilon. + +[table_spherical_harmonic_r] + +[table_spherical_harmonic_i] + +Note that the worst errors occur when the degree increases, values greater than +~120 are very unlikely to produce sensible results, especially +when the order is also large. Further the relative errors +are likely to grow arbitrarily large when the function is very close to a root. + +[h4 Testing] + +A mixture of spot tests of values calculated using functions.wolfram.com, +and randomly generated test data are +used: the test data was computed using +[@http://shoup.net/ntl/doc/RR.txt NTL::RR] at 1000-bit precision. + +[h4 Implementation] + +These functions are implemented fairly naively using the formulae +given above. Some extra care is taken to prevent roundoff error +when converting from polar coordinates (so for example the +['1-x[super 2]] term used by the associated Legendre functions is calculated +without roundoff error using ['x = cos(theta)], and +['1-x[super 2] = sin[super 2](theta)]). The limiting factor in the error +rates for these functions is the need to calculate values near the roots +of the associated Legendre functions. + +[endsect][/section:beta_function The Beta Function] +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/test_html4_symbols.qbk b/boost/libs/math/doc/sf/test_html4_symbols.qbk new file mode 100644 index 00000000..f19684d1 --- /dev/null +++ b/boost/libs/math/doc/sf/test_html4_symbols.qbk @@ -0,0 +1,144 @@ +[section:test_HTML_4_Symbols test HTML4 symbols] +[/ Examples of using all the Greek and Math symbols defined in HTML4_symbols.qbk] +[/ See http://www.htmlhelp.com/reference/html40/entities/symbols.html] + +[/ Also some miscellaneous math charaters added to this list - see the end.] + +[/ To use, enclose the template name in square brackets.] + + +[fnof], +[Alpha], +[Beta], +[Gamma], +[Delta], +[Epsilon], +[Zeta], +[Eta], +[Theta], +[Iota], +[Kappa], +[Lambda], +[Mu], +[Nu], +[Xi], +[Omicron], +[Pi], +[Rho], +[Sigma], +[Tau], +[Upsilon], +[Phi], +[Chi], +[Psi], +[Omega], +[alpha], +[beta], +[gamma], +[delta], +[epsilon], +[zeta], +[eta], +[theta], +[iota], +[kappa], +[lambda], +[mu], +[nu], +[xi], +[omicron], +[pi], +[rho], +[sigmaf], +[sigma], +[tau], +[upsilon], +[phi], +[chi], +[psi], +[omega], +[thetasym], +[upsih], +[piv], +[bull], +[hellip], +[prime], +[Prime], +[oline], +[frasl], +[weierp], +[image], +[real], +[trade], +[alefsym], +[larr], +[uarr], +[rarr], +[darr], +[harr], +[crarr], +[lArr], +[uArr], +[rArr], +[dArr], +[hArr], +[forall], +[part], +[exist], +[empty], +[nabla], +[isin], +[notin], +[ni], +[prod], +[sum], +[minus], +[lowast], +[radic], +[prop], +[infin], +[ang], +[and], +[or], +[cap], +[cup], +[int], +[there4], +[sim], +[cong], +[asymp], +[ne], +[equiv], +[le], +[ge], +[subset], +[superset], +[nsubset], +[sube], +[supe], +[oplus], +[otimes], +[perp], +[sdot], +[lceil], +[rceil], +[lfloor], +[rfloor], +[lang], +[rang], +[loz], +[spades], +[clubs], +[hearts], +[diams], + +[endsect] + +[/ test_MTML4_symbols.qbk + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + + diff --git a/boost/libs/math/doc/sf/tgamma.qbk b/boost/libs/math/doc/sf/tgamma.qbk new file mode 100644 index 00000000..1146a1cd --- /dev/null +++ b/boost/libs/math/doc/sf/tgamma.qbk @@ -0,0 +1,141 @@ +[section:tgamma Gamma] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/gamma.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` tgamma(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` tgamma(T z, const ``__Policy``&); + + template <class T> + ``__sf_result`` tgamma1pm1(T dz); + + template <class T, class ``__Policy``> + ``__sf_result`` tgamma1pm1(T dz, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + + template <class T> + ``__sf_result`` tgamma(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` tgamma(T z, const ``__Policy``&); + +Returns the "true gamma" (hence name tgamma) of value z: + +[equation gamm1] + +[graph tgamma] + +[optional_policy] + +There are effectively two versions of the [@http://en.wikipedia.org/wiki/Gamma_function tgamma] +function internally: a fully +generic version that is slow, but reasonably accurate, and a much more +efficient approximation that is used where the number of digits in the significand +of T correspond to a certain __lanczos. In practice any built in +floating point type you will encounter has an appropriate __lanczos +defined for it. It is also possible, given enough machine time, to generate +further __lanczos's using the program libs/math/tools/lanczos_generator.cpp. + +The return type of this function is computed using the __arg_promotion_rules: +the result is `double` when T is an integer type, and T otherwise. + + template <class T> + ``__sf_result`` tgamma1pm1(T dz); + + template <class T, class ``__Policy``> + ``__sf_result`` tgamma1pm1(T dz, const ``__Policy``&); + +Returns `tgamma(dz + 1) - 1`. Internally the implementation does not make +use of the addition and subtraction implied by the definition, leading to +accurate results even for very small `dz`. However, the implementation is +capped to either 35 digit accuracy, or to the precision of the __lanczos +associated with type T, whichever is more accurate. + +The return type of this function is computed using the __arg_promotion_rules: +the result is `double` when T is an integer type, and T otherwise. + +[optional_policy] + +[h4 Accuracy] + +The following table shows the peak errors (in units of epsilon) +found on various platforms with various floating point types, +along with comparisons to other common libraries. +Unless otherwise specified any floating point type that is narrower +than the one shown will have __zero_error. + +[table_tgamma] + +[table_tgamma1pm1] + +[h4 Testing] + +The gamma is relatively easy to test: factorials and half-integer factorials +can be calculated exactly by other means and compared with the gamma function. +In addition, some accuracy tests in known tricky areas were computed at high precision +using the generic version of this function. + +The function `tgamma1pm1` is tested against values calculated very naively +using the formula `tgamma(1+dz)-1` with a lanczos approximation accurate +to around 100 decimal digits. + +[h4 Implementation] + +The generic version of the `tgamma` function is implemented Sterling's approximation +for lgamma for large z: + +[equation gamma6] + +Following exponentiation, downward recursion is then used for small values of z. + +For types of known precision the __lanczos is used, a traits class +`boost::math::lanczos::lanczos_traits` maps type T to an appropriate +approximation. + +For z in the range -20 < z < 1 then recursion is used to shift to z > 1 via: + +[equation gamm3] + +For very small z, this helps to preserve the identity: + +[equation gamm4] + +For z < -20 the reflection formula: + +[equation gamm5] + +is used. Particular care has to be taken to evaluate the [^ z * sin([pi][space] * z)] part: +a special routine is used to reduce z prior to multiplying by [pi][space] to ensure that the +result in is the range [0, [pi]/2]. Without this an excessive amount of error occurs +in this region (which is hard enough already, as the rate of change near a negative pole +is /exceptionally/ high). + +Finally if the argument is a small integer then table lookup of the factorial +is used. + +The function `tgamma1pm1` is implemented using rational approximations [jm_rationals] in the +region `-0.5 < dz < 2`. These are the same approximations (and internal routines) +that are used for __lgamma, and so aren't detailed further here. The result of +the approximation is `log(tgamma(dz+1))` which can fed into __expm1 to give +the desired result. Outside the range `-0.5 < dz < 2` then the naive formula +`tgamma1pm1(dz) = tgamma(dz+1)-1` can be used directly. + +[endsect][/section:tgamma The Gamma Function] +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/trigamma.qbk b/boost/libs/math/doc/sf/trigamma.qbk new file mode 100644 index 00000000..966ec2f6 --- /dev/null +++ b/boost/libs/math/doc/sf/trigamma.qbk @@ -0,0 +1,79 @@ +[section:trigamma Trigamma] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/trigamma.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` trigamma(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` trigamma(T z, const ``__Policy``&); + + }} // namespaces + +[h4 Description] + +Returns the trigamma function of /x/. Trigamma is defined as the +derivative of the digamma function: + +[equation trigamma1] + +[graph trigamma] + +[optional_policy] + +The return type of this function is computed using the __arg_promotion_rules: +the result is of type `double` when T is an integer type, and type T otherwise. + +[h4 Accuracy] + +The following table shows the peak errors (in units of epsilon) +found on various platforms with various floating point types. +Unless otherwise specified any floating point type that is narrower +than the one shown will have __zero_error. + +[table_trigamma] + +As shown above, error rates are generally very low for built in types. +For multiprecision types, error rates are typically in the order of a +few epsilon. + +[h4 Testing] + +Testing is against Mathematica generated spot values to 35 digit precision. + +[h4 Implementation] + +The arbitrary precision version of this function simply calls __polygamma. + +For built in fixed precision types, negative arguments are first made positive via: + +[equation trigamma2] + +Then arguments in the range \[0, 1) are shifted to >= 1 via: + +[equation trigamma3] + +Then evaluation is via one of a number of rational approximations, for small x these are +of the form: + +[equation trigamma4] + +and for large x of the form: + +[equation trigamma5] + +[endsect][/section:digamma The Trigamma Function] + +[/ + Copyright 2014 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/boost/libs/math/doc/sf/zeta.qbk b/boost/libs/math/doc/sf/zeta.qbk new file mode 100644 index 00000000..b0ba8352 --- /dev/null +++ b/boost/libs/math/doc/sf/zeta.qbk @@ -0,0 +1,119 @@ +[section:zeta Riemann Zeta Function] + +[h4 Synopsis] + +`` +#include <boost/math/special_functions/zeta.hpp> +`` + + namespace boost{ namespace math{ + + template <class T> + ``__sf_result`` zeta(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` zeta(T z, const ``__Policy``&); + + }} // namespaces + +The return type of these functions is computed using the __arg_promotion_rules: +the return type is `double` if T is an integer type, and T otherwise. + +[optional_policy] + +[h4 Description] + + template <class T> + ``__sf_result`` zeta(T z); + + template <class T, class ``__Policy``> + ``__sf_result`` zeta(T z, const ``__Policy``&); + +Returns the [@http://mathworld.wolfram.com/RiemannZetaFunction.html zeta function] +of z: + +[equation zeta1] + +[graph zeta1] + +[graph zeta2] + +[h4 Accuracy] + +The following table shows the peak errors (in units of epsilon) +found on various platforms with various floating point types, +along with comparisons to the __gsl and __cephes libraries. +Unless otherwise specified any floating point type that is narrower +than the one shown will have __zero_error. + +[table_zeta] + +[h4 Testing] + +The tests for these functions come in two parts: +basic sanity checks use spot values calculated using +[@http://functions.wolfram.com/webMathematica/FunctionEvaluation.jsp?name=Zeta Mathworld's online evaluator], +while accuracy checks use high-precision test values calculated at 1000-bit precision with +[@http://shoup.net/ntl/doc/RR.txt NTL::RR] and this implementation. +Note that the generic and type-specific +versions of these functions use differing implementations internally, so this +gives us reasonably independent test data. Using our test data to test other +"known good" implementations also provides an additional sanity check. + +[h4 Implementation] + +All versions of these functions first use the usual reflection formulas +to make their arguments positive: + +[equation zeta3] + +The generic versions of these functions are implemented using the series: + +[equation zeta6] + +When the significand (mantissa) size is recognised +(currently for 53, 64 and 113-bit reals, plus single-precision 24-bit handled via promotion to double) +then a series of rational approximations [jm_rationals] are used. + +For 0 < z < 1 the approximating form is: + +[equation zeta4] + +For a rational approximation R(1-z) and a constant C. + +For 1 < z < 4 the approximating form is: + +[equation zeta5] + +For a rational approximation R(n-z) and a constant C and integer n. + +For z > 4 the approximating form is: + +[zeta](z) = 1 + e[super R(z - n)] + +For a rational approximation R(z-n) and integer n, note that the accuracy +required for R(z-n) is not full machine precision, but an absolute error +of: [epsilon]/R(0). This saves us quite a few digits when dealing with large +z, especially when [epsilon] is small. + +Finally, there are some special cases for integer arguments, there are +closed forms for negative or even integers: + +[equation zeta7] + +[equation zeta8] + +[equation zeta9] + +and for positive odd integers we simply cache pre-computed values as these are of great +benefit to some infinite series calculations. + +[endsect] +[/ :error_function The Error Functions] + +[/ + Copyright 2006 John Maddock and Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] |
