• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[section:beta_function Beta]
2
3[h4 Synopsis]
4
5``
6#include <boost/math/special_functions/beta.hpp>
7``
8
9   namespace boost{ namespace math{
10
11   template <class T1, class T2>
12   ``__sf_result`` beta(T1 a, T2 b);
13
14   template <class T1, class T2, class ``__Policy``>
15   ``__sf_result`` beta(T1 a, T2 b, const ``__Policy``&);
16
17   }} // namespaces
18
19[h4 Description]
20
21The beta function is defined by:
22
23[equation beta1]
24
25[graph beta]
26
27[optional_policy]
28
29The return type of these functions is computed using the __arg_promotion_rules
30when T1 and T2 are different types.
31
32[h4 Accuracy]
33
34The following table shows peak errors for various domains of input arguments,
35along with comparisons to the __gsl and __cephes libraries.  Note that
36only results for the widest floating point type on the system are given as
37narrower types have __zero_error.
38
39[table_beta]
40
41Note that the worst errors occur when a or b are large, and that
42when this is the case the result is very close to zero, so absolute
43errors will be very small.
44
45[h4 Testing]
46
47A mixture of spot tests of exact values, and randomly generated test data are
48used: the test data was computed using
49[@http://shoup.net/ntl/doc/RR.txt NTL::RR] at 1000-bit precision.
50
51[h4 Implementation]
52
53Traditional methods of evaluating the beta function either involve evaluating
54the gamma functions directly, or taking logarithms and then
55exponentiating the result.  However, the former is prone to overflows
56for even very modest arguments, while the latter is prone to cancellation
57errors.  As an alternative, if we regard the gamma function as a white-box
58containing the __lanczos, then we can combine the power terms:
59
60[equation beta2]
61
62which is almost the ideal solution, however almost all of the error occurs
63in evaluating the power terms when /a/ or /b/ are large.  If we assume that /a > b/
64then the larger of the two power terms can be reduced by a factor of /b/, which
65immediately cuts the maximum error in half:
66
67[equation beta3]
68
69This may not be the final solution, but it is very competitive compared to
70other implementation methods.
71
72The generic implementation - where no __lanczos approximation is available - is
73implemented in a very similar way to the generic version of the gamma function
74by means of Sterling's approximation.
75Again in order to avoid numerical overflow the power terms that prefix the series
76are collected together
77
78There are a few special cases worth mentioning:
79
80When /a/ or /b/ are less than one, we can use the recurrence relations:
81
82[equation beta4]
83
84[equation beta5]
85
86to move to a more favorable region where they are both greater than 1.
87
88In addition:
89
90[equation beta7]
91
92[endsect] [/section:beta_function The Beta Function]
93[/
94  Copyright 2006 John Maddock and Paul A. Bristow.
95  Distributed under the Boost Software License, Version 1.0.
96  (See accompanying file LICENSE_1_0.txt or copy at
97  http://www.boost.org/LICENSE_1_0.txt).
98]
99
100