3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5 <link rel="stylesheet" href="../../math.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../index.html" title="Math Toolkit 2.11.0">
8 <link rel="up" href="../sf_beta.html" title="Beta Functions">
9 <link rel="prev" href="../sf_beta.html" title="Beta Functions">
10 <link rel="next" href="ibeta_function.html" title="Incomplete Beta Functions">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="../sf_beta.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_beta.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="ibeta_function.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="math_toolkit.sf_beta.beta_function"></a><a class="link" href="beta_function.html" title="Beta">Beta</a>
28 </h3></div></div></div>
30 <a name="math_toolkit.sf_beta.beta_function.h0"></a>
31 <span class="phrase"><a name="math_toolkit.sf_beta.beta_function.synopsis"></a></span><a class="link" href="beta_function.html#math_toolkit.sf_beta.beta_function.synopsis">Synopsis</a>
33 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">special_functions</span><span class="special">/</span><span class="identifier">beta</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
35 <pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
37 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">></span>
38 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">beta</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">);</span>
40 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
41 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">beta</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
43 <span class="special">}}</span> <span class="comment">// namespaces</span>
46 <a name="math_toolkit.sf_beta.beta_function.h1"></a>
47 <span class="phrase"><a name="math_toolkit.sf_beta.beta_function.description"></a></span><a class="link" href="beta_function.html#math_toolkit.sf_beta.beta_function.description">Description</a>
50 The beta function is defined by:
52 <div class="blockquote"><blockquote class="blockquote"><p>
53 <span class="inlinemediaobject"><img src="../../../equations/beta1.svg"></span>
55 </p></blockquote></div>
56 <div class="blockquote"><blockquote class="blockquote"><p>
57 <span class="inlinemediaobject"><img src="../../../graphs/beta.svg" align="middle"></span>
59 </p></blockquote></div>
61 The final <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
62 be used to control the behaviour of the function: how it handles errors,
63 what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">policy
64 documentation for more details</a>.
67 The return type of these functions is computed using the <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>result
68 type calculation rules</em></span></a> when T1 and T2 are different types.
71 <a name="math_toolkit.sf_beta.beta_function.h2"></a>
72 <span class="phrase"><a name="math_toolkit.sf_beta.beta_function.accuracy"></a></span><a class="link" href="beta_function.html#math_toolkit.sf_beta.beta_function.accuracy">Accuracy</a>
75 The following table shows peak errors for various domains of input arguments,
76 along with comparisons to the <a href="http://www.gnu.org/software/gsl/" target="_top">GSL-1.9</a>
77 and <a href="http://www.netlib.org/cephes/" target="_top">Cephes</a> libraries.
78 Note that only results for the widest floating point type on the system are
79 given as narrower types have <a class="link" href="../relative_error.html#math_toolkit.relative_error.zero_error">effectively
83 <a name="math_toolkit.sf_beta.beta_function.table_beta"></a><p class="title"><b>Table 8.17. Error rates for beta</b></p>
84 <div class="table-contents"><table class="table" summary="Error rates for beta">
97 GNU C++ version 7.1.0<br> linux<br> double
102 GNU C++ version 7.1.0<br> linux<br> long double
107 Sun compiler version 0x5150<br> Sun Solaris<br> long double
112 Microsoft Visual C++ version 14.1<br> Win32<br> double
120 Beta Function: Small Values
125 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
126 2.1:</em></span> <span class="red">Max = +INFε (Mean = +INFε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_beta_GSL_2_1_Beta_Function_Small_Values">And
127 other failures.</a>)</span><br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span>
128 Max = 1.14ε (Mean = 0.574ε))
133 <span class="blue">Max = 2.86ε (Mean = 1.22ε)</span><br> <br>
134 (<span class="emphasis"><em><cmath>:</em></span> Max = 364ε (Mean = 76.2ε))
139 <span class="blue">Max = 2.86ε (Mean = 1.22ε)</span>
144 <span class="blue">Max = 2.23ε (Mean = 1.14ε)</span>
151 Beta Function: Medium Values
156 <span class="blue">Max = 0.978ε (Mean = 0.0595ε)</span><br>
157 <br> (<span class="emphasis"><em>GSL 2.1:</em></span> Max = 1.18e+03ε (Mean = 238ε))<br>
158 (<span class="emphasis"><em>Rmath 3.2.3:</em></span> Max = 1.09e+03ε (Mean = 265ε))
163 <span class="blue">Max = 61.4ε (Mean = 19.4ε)</span><br> <br>
164 (<span class="emphasis"><em><cmath>:</em></span> Max = 1.07e+03ε (Mean = 264ε))
169 <span class="blue">Max = 107ε (Mean = 24.5ε)</span>
174 <span class="blue">Max = 96.5ε (Mean = 22.4ε)</span>
181 Beta Function: Divergent Values
186 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
187 2.1:</em></span> Max = 12.1ε (Mean = 1.99ε))<br> (<span class="emphasis"><em>Rmath
188 3.2.3:</em></span> Max = 176ε (Mean = 28ε))
193 <span class="blue">Max = 8.99ε (Mean = 2.44ε)</span><br> <br>
194 (<span class="emphasis"><em><cmath>:</em></span> Max = 128ε (Mean = 23.8ε))
199 <span class="blue">Max = 18.8ε (Mean = 2.71ε)</span>
204 <span class="blue">Max = 11.4ε (Mean = 2.19ε)</span>
211 <br class="table-break"><p>
212 Note that the worst errors occur when a or b are large, and that when this
213 is the case the result is very close to zero, so absolute errors will be
217 <a name="math_toolkit.sf_beta.beta_function.h3"></a>
218 <span class="phrase"><a name="math_toolkit.sf_beta.beta_function.testing"></a></span><a class="link" href="beta_function.html#math_toolkit.sf_beta.beta_function.testing">Testing</a>
221 A mixture of spot tests of exact values, and randomly generated test data
222 are used: the test data was computed using <a href="http://shoup.net/ntl/doc/RR.txt" target="_top">NTL::RR</a>
223 at 1000-bit precision.
226 <a name="math_toolkit.sf_beta.beta_function.h4"></a>
227 <span class="phrase"><a name="math_toolkit.sf_beta.beta_function.implementation"></a></span><a class="link" href="beta_function.html#math_toolkit.sf_beta.beta_function.implementation">Implementation</a>
230 Traditional methods of evaluating the beta function either involve evaluating
231 the gamma functions directly, or taking logarithms and then exponentiating
232 the result. However, the former is prone to overflows for even very modest
233 arguments, while the latter is prone to cancellation errors. As an alternative,
234 if we regard the gamma function as a white-box containing the <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
235 approximation</a>, then we can combine the power terms:
237 <div class="blockquote"><blockquote class="blockquote"><p>
238 <span class="inlinemediaobject"><img src="../../../equations/beta2.svg"></span>
240 </p></blockquote></div>
242 which is almost the ideal solution, however almost all of the error occurs
243 in evaluating the power terms when <span class="emphasis"><em>a</em></span> or <span class="emphasis"><em>b</em></span>
244 are large. If we assume that <span class="emphasis"><em>a > b</em></span> then the larger
245 of the two power terms can be reduced by a factor of <span class="emphasis"><em>b</em></span>,
246 which immediately cuts the maximum error in half:
248 <div class="blockquote"><blockquote class="blockquote"><p>
249 <span class="inlinemediaobject"><img src="../../../equations/beta3.svg"></span>
251 </p></blockquote></div>
253 This may not be the final solution, but it is very competitive compared to
254 other implementation methods.
257 The generic implementation - where no <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
258 approximation</a> approximation is available - is implemented in a very
259 similar way to the generic version of the gamma function by means of Sterling's
260 approximation. Again in order to avoid numerical overflow the power terms
261 that prefix the series are collected together
264 There are a few special cases worth mentioning:
267 When <span class="emphasis"><em>a</em></span> or <span class="emphasis"><em>b</em></span> are less than one,
268 we can use the recurrence relations:
270 <div class="blockquote"><blockquote class="blockquote"><p>
271 <span class="inlinemediaobject"><img src="../../../equations/beta4.svg"></span>
273 </p></blockquote></div>
274 <div class="blockquote"><blockquote class="blockquote"><p>
275 <span class="inlinemediaobject"><img src="../../../equations/beta5.svg"></span>
277 </p></blockquote></div>
279 to move to a more favorable region where they are both greater than 1.
284 <div class="blockquote"><blockquote class="blockquote"><p>
285 <span class="inlinemediaobject"><img src="../../../equations/beta7.svg"></span>
287 </p></blockquote></div>
289 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
290 <td align="left"></td>
291 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
292 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
293 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
294 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
295 Daryle Walker and Xiaogang Zhang<p>
296 Distributed under the Boost Software License, Version 1.0. (See accompanying
297 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
302 <div class="spirit-nav">
303 <a accesskey="p" href="../sf_beta.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_beta.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="ibeta_function.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>