mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2026-08-13 23:13:52 -04:00
Squashed 'boost/' content from commit b4feb19f2
git-subtree-dir: boost git-subtree-split: b4feb19f287ee92d87a9624b5d36b7cf46aeadeb
This commit is contained in:
@@ -0,0 +1,963 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Incomplete Gamma Functions</title>
|
||||
<link rel="stylesheet" href="../../math.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
|
||||
<link rel="home" href="../../index.html" title="Math Toolkit 2.5.1">
|
||||
<link rel="up" href="../sf_gamma.html" title="Gamma Functions">
|
||||
<link rel="prev" href="gamma_ratios.html" title="Ratios of Gamma Functions">
|
||||
<link rel="next" href="igamma_inv.html" title="Incomplete Gamma Function Inverses">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gamma_ratios.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_gamma.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="igamma_inv.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="math_toolkit.sf_gamma.igamma"></a><a class="link" href="igamma.html" title="Incomplete Gamma Functions">Incomplete Gamma Functions</a>
|
||||
</h3></div></div></div>
|
||||
<h5>
|
||||
<a name="math_toolkit.sf_gamma.igamma.h0"></a>
|
||||
<span class="phrase"><a name="math_toolkit.sf_gamma.igamma.synopsis"></a></span><a class="link" href="igamma.html#math_toolkit.sf_gamma.igamma.synopsis">Synopsis</a>
|
||||
</h5>
|
||||
<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">gamma</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
</pre>
|
||||
<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>
|
||||
|
||||
<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>
|
||||
<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">gamma_p</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">z</span><span class="special">);</span>
|
||||
|
||||
<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 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
|
||||
<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">gamma_p</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">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
|
||||
|
||||
<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>
|
||||
<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">gamma_q</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">z</span><span class="special">);</span>
|
||||
|
||||
<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 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
|
||||
<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">gamma_q</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">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
|
||||
|
||||
<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>
|
||||
<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">tgamma_lower</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">z</span><span class="special">);</span>
|
||||
|
||||
<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 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
|
||||
<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">tgamma_lower</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">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
|
||||
|
||||
<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>
|
||||
<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">tgamma</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">z</span><span class="special">);</span>
|
||||
|
||||
<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 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
|
||||
<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">tgamma</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">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<h5>
|
||||
<a name="math_toolkit.sf_gamma.igamma.h1"></a>
|
||||
<span class="phrase"><a name="math_toolkit.sf_gamma.igamma.description"></a></span><a class="link" href="igamma.html#math_toolkit.sf_gamma.igamma.description">Description</a>
|
||||
</h5>
|
||||
<p>
|
||||
There are four <a href="http://mathworld.wolfram.com/IncompleteGammaFunction.html" target="_top">incomplete
|
||||
gamma functions</a>: two are normalised versions (also known as <span class="emphasis"><em>regularized</em></span>
|
||||
incomplete gamma functions) that return values in the range [0, 1], and two
|
||||
are non-normalised and return values in the range [0, Γ(a)]. Users interested
|
||||
in statistical applications should use the <a href="http://mathworld.wolfram.com/RegularizedGammaFunction.html" target="_top">normalised
|
||||
versions (gamma_p and gamma_q)</a>.
|
||||
</p>
|
||||
<p>
|
||||
All of these functions require <span class="emphasis"><em>a > 0</em></span> and <span class="emphasis"><em>z
|
||||
>= 0</em></span>, otherwise they return the result of <a class="link" href="../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
|
||||
</p>
|
||||
<p>
|
||||
The final <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a> 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 the <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">policy
|
||||
documentation for more details</a>.
|
||||
</p>
|
||||
<p>
|
||||
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
|
||||
type calculation rules</em></span></a> when T1 and T2 are different types,
|
||||
otherwise the return type is simply T1.
|
||||
</p>
|
||||
<pre class="programlisting"><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>
|
||||
<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">gamma_p</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">z</span><span class="special">);</span>
|
||||
|
||||
<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> <span class="identifier">Policy</span><span class="special">></span>
|
||||
<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">gamma_p</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">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Returns the normalised lower incomplete gamma function of a and z:
|
||||
</p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../equations/igamma4.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
This function changes rapidly from 0 to 1 around the point z == a:
|
||||
</p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../graphs/gamma_p.svg" align="middle"></span>
|
||||
</p>
|
||||
<pre class="programlisting"><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>
|
||||
<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">gamma_q</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">z</span><span class="special">);</span>
|
||||
|
||||
<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 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
|
||||
<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">gamma_q</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">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Returns the normalised upper incomplete gamma function of a and z:
|
||||
</p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../equations/igamma3.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
This function changes rapidly from 1 to 0 around the point z == a:
|
||||
</p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../graphs/gamma_q.svg" align="middle"></span>
|
||||
</p>
|
||||
<pre class="programlisting"><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>
|
||||
<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">tgamma_lower</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">z</span><span class="special">);</span>
|
||||
|
||||
<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 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
|
||||
<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">tgamma_lower</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">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Returns the full (non-normalised) lower incomplete gamma function of a and
|
||||
z:
|
||||
</p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../equations/igamma2.svg"></span>
|
||||
</p>
|
||||
<pre class="programlisting"><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>
|
||||
<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">tgamma</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">z</span><span class="special">);</span>
|
||||
|
||||
<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 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
|
||||
<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">tgamma</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">z</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Returns the full (non-normalised) upper incomplete gamma function of a and
|
||||
z:
|
||||
</p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../equations/igamma1.svg"></span>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="math_toolkit.sf_gamma.igamma.h2"></a>
|
||||
<span class="phrase"><a name="math_toolkit.sf_gamma.igamma.accuracy"></a></span><a class="link" href="igamma.html#math_toolkit.sf_gamma.igamma.accuracy">Accuracy</a>
|
||||
</h5>
|
||||
<p>
|
||||
The following tables give peak and mean relative errors in over various domains
|
||||
of a and z, along with comparisons to the <a href="http://www.gnu.org/software/gsl/" target="_top">GSL-1.9</a>
|
||||
and <a href="http://www.netlib.org/cephes/" target="_top">Cephes</a> libraries.
|
||||
Note that only results for the widest floating point type on the system are
|
||||
given as narrower types have <a class="link" href="../relative_error.html#math_toolkit.relative_error.zero_error">effectively
|
||||
zero error</a>.
|
||||
</p>
|
||||
<p>
|
||||
Note that errors grow as <span class="emphasis"><em>a</em></span> grows larger.
|
||||
</p>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<p>
|
||||
All values are in units of epsilon.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="math_toolkit.sf_gamma.igamma.table_gamma_p"></a><p class="title"><b>Table 6.9. Error rates for gamma_p</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Error rates for gamma_p">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Microsoft Visual C++ version 12.0<br> Win32<br> double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
GNU C++ version 5.1.0<br> linux<br> double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
GNU C++ version 5.1.0<br> linux<br> long double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Sun compiler version 0x5130<br> Sun Solaris<br> long double
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) medium values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 35.1ε (Mean = 6.97ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0.955ε (Mean = 0.05ε)</span><br> <br>
|
||||
(<span class="emphasis"><em>GSL 1.16:</em></span> Max = 342ε (Mean = 45.8ε))<br> (<span class="emphasis"><em>Rmath
|
||||
3.0.2:</em></span> Max = 389ε (Mean = 44ε))<br> (<span class="emphasis"><em>Cephes:</em></span>
|
||||
Max = 492ε (Mean = 101ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 41ε (Mean = 8.09ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 239ε (Mean = 30.2ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) small values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 1.54ε (Mean = 0.439ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
|
||||
1.16:</em></span> Max = 4.82ε (Mean = 0.758ε))<br> (<span class="emphasis"><em>Rmath
|
||||
3.0.2:</em></span> Max = 1.01ε (Mean = 0.306ε))<br> (<span class="emphasis"><em>Cephes:</em></span>
|
||||
Max = 21ε (Mean = 5.65ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 2ε (Mean = 0.461ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 2ε (Mean = 0.472ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) large values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 244ε (Mean = 20.2ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
|
||||
1.16:</em></span> Max = 1.02e+03ε (Mean = 105ε))<br> (<span class="emphasis"><em>Rmath
|
||||
3.0.2:</em></span> Max = 1.11e+03ε (Mean = 67.5ε))<br> (<span class="emphasis"><em>Cephes:</em></span>
|
||||
Max = 8.18e+06ε (Mean = 7.69e+05ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 3.08e+04ε (Mean = 1.86e+03ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 3.02e+04ε (Mean = 1.91e+03ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) integer and half integer values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 13ε (Mean = 2.93ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
|
||||
1.16:</em></span> Max = 128ε (Mean = 22.6ε))<br> (<span class="emphasis"><em>Rmath
|
||||
3.0.2:</em></span> Max = 66.2ε (Mean = 12.2ε))<br> (<span class="emphasis"><em>Cephes:</em></span>
|
||||
Max = 83.6ε (Mean = 22.2ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 11.8ε (Mean = 2.65ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 71.6ε (Mean = 9.47ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><div class="table">
|
||||
<a name="math_toolkit.sf_gamma.igamma.table_gamma_q"></a><p class="title"><b>Table 6.10. Error rates for gamma_q</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Error rates for gamma_q">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Microsoft Visual C++ version 12.0<br> Win32<br> double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
GNU C++ version 5.1.0<br> linux<br> double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
GNU C++ version 5.1.0<br> linux<br> long double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Sun compiler version 0x5130<br> Sun Solaris<br> long double
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) medium values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 23.7ε (Mean = 4.03ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0.927ε (Mean = 0.035ε)</span><br> <br>
|
||||
(<span class="emphasis"><em>GSL 1.16:</em></span> Max = 201ε (Mean = 13.5ε))<br> (<span class="emphasis"><em>Rmath
|
||||
3.0.2:</em></span> Max = 131ε (Mean = 12.7ε))<br> (<span class="emphasis"><em>Cephes:</em></span>
|
||||
Max = 388ε (Mean = 93.8ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 31.3ε (Mean = 6.56ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 199ε (Mean = 26.6ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) small values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 2.26ε (Mean = 0.732ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
|
||||
1.16:</em></span> <span class="red">Max = 1.38e+10ε (Mean = 1.05e+09ε))</span><br>
|
||||
(<span class="emphasis"><em>Rmath 3.0.2:</em></span> Max = 65.6ε (Mean = 11ε))<br>
|
||||
(<span class="emphasis"><em>Cephes:</em></span> <span class="red">Max = 3.42e+11ε (Mean
|
||||
= 4.1e+10ε))</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 2.45ε (Mean = 0.832ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 2.25ε (Mean = 0.81ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) large values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 470ε (Mean = 31.5ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
|
||||
1.16:</em></span> Max = 2.71e+04ε (Mean = 2.16e+03ε))<br> (<span class="emphasis"><em>Rmath
|
||||
3.0.2:</em></span> Max = 1.02e+03ε (Mean = 62.7ε))<br> (<span class="emphasis"><em>Cephes:</em></span>
|
||||
Max = 8.17e+06ε (Mean = 7.7e+05ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 6.82e+03ε (Mean = 414ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 1.15e+04ε (Mean = 733ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) integer and half integer values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 8.48ε (Mean = 1.42ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
|
||||
1.16:</em></span> Max = 118ε (Mean = 12.5ε))<br> (<span class="emphasis"><em>Rmath
|
||||
3.0.2:</em></span> Max = 138ε (Mean = 16.9ε))<br> (<span class="emphasis"><em>Cephes:</em></span>
|
||||
Max = 129ε (Mean = 26.5ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 11.1ε (Mean = 2.09ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 54.7ε (Mean = 6.16ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><div class="table">
|
||||
<a name="math_toolkit.sf_gamma.igamma.table_tgamma_lower"></a><p class="title"><b>Table 6.11. Error rates for tgamma_lower</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Error rates for tgamma_lower">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Microsoft Visual C++ version 12.0<br> Win32<br> double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
GNU C++ version 5.1.0<br> linux<br> double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
GNU C++ version 5.1.0<br> linux<br> long double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Sun compiler version 0x5130<br> Sun Solaris<br> long double
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) medium values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 5.62ε (Mean = 1.43ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0.833ε (Mean = 0.0315ε)</span><br>
|
||||
<br> (<span class="emphasis"><em>GSL 1.16:</em></span> Max = 0.833ε (Mean = 0.0315ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 6.79ε (Mean = 1.38ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 363ε (Mean = 63.8ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) small values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 1.57ε (Mean = 0.527ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
|
||||
1.16:</em></span> Max = 0ε (Mean = 0ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 1.97ε (Mean = 0.552ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 1.97ε (Mean = 0.567ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) integer and half integer values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 2.69ε (Mean = 0.866ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
|
||||
1.16:</em></span> Max = 0ε (Mean = 0ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 4.83ε (Mean = 1.12ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 84.7ε (Mean = 17.5ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><div class="table">
|
||||
<a name="math_toolkit.sf_gamma.igamma.table_tgamma_incomplete_"></a><p class="title"><b>Table 6.12. Error rates for tgamma (incomplete)</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Error rates for tgamma (incomplete)">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Microsoft Visual C++ version 12.0<br> Win32<br> double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
GNU C++ version 5.1.0<br> linux<br> double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
GNU C++ version 5.1.0<br> linux<br> long double
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Sun compiler version 0x5130<br> Sun Solaris<br> long double
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) medium values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 8.14ε (Mean = 1.71ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
|
||||
1.16:</em></span> Max = 200ε (Mean = 13.3ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 7.35ε (Mean = 1.69ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 412ε (Mean = 95.5ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) small values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 2.53ε (Mean = 0.66ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0.753ε (Mean = 0.0474ε)</span><br>
|
||||
<br> (<span class="emphasis"><em>GSL 1.16:</em></span> <span class="red">Max =
|
||||
1.38e+10ε (Mean = 1.05e+09ε))</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 2.13ε (Mean = 0.717ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 2.13ε (Mean = 0.712ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tgamma(a, z) integer and half integer values
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 5.16ε (Mean = 1.44ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
|
||||
1.16:</em></span> Max = 117ε (Mean = 12.5ε))
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 5.52ε (Mean = 1.52ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="blue">Max = 79.6ε (Mean = 20.9ε)</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><h5>
|
||||
<a name="math_toolkit.sf_gamma.igamma.h3"></a>
|
||||
<span class="phrase"><a name="math_toolkit.sf_gamma.igamma.testing"></a></span><a class="link" href="igamma.html#math_toolkit.sf_gamma.igamma.testing">Testing</a>
|
||||
</h5>
|
||||
<p>
|
||||
There are two sets of tests: spot tests compare values taken from <a href="http://functions.wolfram.com/GammaBetaErf/" target="_top">Mathworld's online evaluator</a>
|
||||
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 <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos approximation</a>,
|
||||
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.
|
||||
</p>
|
||||
<h5>
|
||||
<a name="math_toolkit.sf_gamma.igamma.h4"></a>
|
||||
<span class="phrase"><a name="math_toolkit.sf_gamma.igamma.implementation"></a></span><a class="link" href="igamma.html#math_toolkit.sf_gamma.igamma.implementation">Implementation</a>
|
||||
</h5>
|
||||
<p>
|
||||
These four functions share a common implementation since they are all related
|
||||
via:
|
||||
</p>
|
||||
<p>
|
||||
1) <span class="inlinemediaobject"><img src="../../../equations/igamma5.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
2) <span class="inlinemediaobject"><img src="../../../equations/igamma6.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
3) <span class="inlinemediaobject"><img src="../../../equations/igamma7.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
The lower incomplete gamma is computed from its series representation:
|
||||
</p>
|
||||
<p>
|
||||
4) <span class="inlinemediaobject"><img src="../../../equations/igamma8.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
Or by subtraction of the upper integral from either Γ(a) or 1 when <span class="emphasis"><em>x
|
||||
- (1</em></span>(3x)) > a and x > 1.1/.
|
||||
</p>
|
||||
<p>
|
||||
The upper integral is computed from Legendre's continued fraction representation:
|
||||
</p>
|
||||
<p>
|
||||
5) <span class="inlinemediaobject"><img src="../../../equations/igamma9.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
When <span class="emphasis"><em>(x > 1.1)</em></span> or by subtraction of the lower integral
|
||||
from either Γ(a) or 1 when <span class="emphasis"><em>x - (1</em></span>(3x)) < a/.
|
||||
</p>
|
||||
<p>
|
||||
For <span class="emphasis"><em>x < 1.1</em></span> 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:
|
||||
</p>
|
||||
<p>
|
||||
6) <span class="inlinemediaobject"><img src="../../../equations/igamma10.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
That lends itself to calculation of the upper integral via rearrangement
|
||||
to:
|
||||
</p>
|
||||
<p>
|
||||
7) <span class="inlinemediaobject"><img src="../../../equations/igamma11.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
Refer to the documentation for <a class="link" href="../powers/powm1.html" title="powm1">powm1</a>
|
||||
and <a class="link" href="tgamma.html" title="Gamma">tgamma1pm1</a> for details
|
||||
of their implementation. Note however that the precision of <a class="link" href="tgamma.html" title="Gamma">tgamma1pm1</a>
|
||||
is capped to either around 35 digits, or to that of the <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
|
||||
approximation</a> 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.
|
||||
</p>
|
||||
<p>
|
||||
For <span class="emphasis"><em>x < 1.1</em></span> the crossover point where the result
|
||||
is ~0.5 no longer occurs for <span class="emphasis"><em>x ~ y</em></span>. Using <span class="emphasis"><em>x
|
||||
* 0.75 < a</em></span> as the crossover criterion for <span class="emphasis"><em>0.5 <
|
||||
x <= 1.1</em></span> keeps the maximum value computed (whether it's the
|
||||
upper or lower interval) to around 0.75. Likewise for <span class="emphasis"><em>x <= 0.5</em></span>
|
||||
then using <span class="emphasis"><em>-0.4 / log(x) < a</em></span> as the crossover criterion
|
||||
keeps the maximum value computed to around 0.7 (whether it's the upper or
|
||||
lower interval).
|
||||
</p>
|
||||
<p>
|
||||
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 <span class="emphasis"><em>1 <= a <
|
||||
30</em></span> then the following finite sum is used:
|
||||
</p>
|
||||
<p>
|
||||
9) <span class="inlinemediaobject"><img src="../../../equations/igamma1f.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
While for half integers in the range <span class="emphasis"><em>0.5 <= a < 30</em></span>
|
||||
then the following finite sum is used:
|
||||
</p>
|
||||
<p>
|
||||
10) <span class="inlinemediaobject"><img src="../../../equations/igamma2f.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
These are both more stable and more efficient than the continued fraction
|
||||
alternative.
|
||||
</p>
|
||||
<p>
|
||||
When the argument <span class="emphasis"><em>a</em></span> is large, and <span class="emphasis"><em>x ~ a</em></span>
|
||||
then the series (4) and continued fraction (5) above are very slow to converge.
|
||||
In this area an expansion due to Temme is used:
|
||||
</p>
|
||||
<p>
|
||||
11) <span class="inlinemediaobject"><img src="../../../equations/igamma16.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
12) <span class="inlinemediaobject"><img src="../../../equations/igamma17.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
13) <span class="inlinemediaobject"><img src="../../../equations/igamma18.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
14) <span class="inlinemediaobject"><img src="../../../equations/igamma19.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
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</sub><sup>n</sup> are
|
||||
computed in advance using the recurrence relations given by Temme. The zone
|
||||
where these expansions are used is
|
||||
</p>
|
||||
<pre class="programlisting"><span class="special">(</span><span class="identifier">a</span> <span class="special">></span> <span class="number">20</span><span class="special">)</span> <span class="special">&&</span> <span class="special">(</span><span class="identifier">a</span> <span class="special"><</span> <span class="number">200</span><span class="special">)</span> <span class="special">&&</span> <span class="identifier">fabs</span><span class="special">(</span><span class="identifier">x</span><span class="special">-</span><span class="identifier">a</span><span class="special">)/</span><span class="identifier">a</span> <span class="special"><</span> <span class="number">0.4</span>
|
||||
</pre>
|
||||
<p>
|
||||
And:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="special">(</span><span class="identifier">a</span> <span class="special">></span> <span class="number">200</span><span class="special">)</span> <span class="special">&&</span> <span class="special">(</span><span class="identifier">fabs</span><span class="special">(</span><span class="identifier">x</span><span class="special">-</span><span class="identifier">a</span><span class="special">)/</span><span class="identifier">a</span> <span class="special"><</span> <span class="number">4.5</span><span class="special">/</span><span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">a</span><span class="special">))</span>
|
||||
</pre>
|
||||
<p>
|
||||
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<sup>-6</sup>, 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 <code class="computeroutput"><span class="identifier">exp</span></code> and <code class="computeroutput"><span class="identifier">erfc</span></code> 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.
|
||||
</p>
|
||||
<p>
|
||||
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 <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
|
||||
approximation</a> gives the greatest accuracy:
|
||||
</p>
|
||||
<p>
|
||||
15) <span class="inlinemediaobject"><img src="../../../equations/igamma12.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
In the event that this causes underflow/overflow then the exponent can be
|
||||
reduced by a factor of <span class="emphasis"><em>a</em></span> and brought inside the power
|
||||
term.
|
||||
</p>
|
||||
<p>
|
||||
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:
|
||||
</p>
|
||||
<p>
|
||||
16) <span class="inlinemediaobject"><img src="../../../equations/igamma13.svg"></span>
|
||||
</p>
|
||||
<p>
|
||||
when <span class="emphasis"><em>a-x</em></span> 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 <span class="emphasis"><em>exp</em></span>
|
||||
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 <span class="emphasis"><em>log(1+x)-x</em></span> here is inspired by
|
||||
Temme (see references below).
|
||||
</p>
|
||||
<h5>
|
||||
<a name="math_toolkit.sf_gamma.igamma.h5"></a>
|
||||
<span class="phrase"><a name="math_toolkit.sf_gamma.igamma.references"></a></span><a class="link" href="igamma.html#math_toolkit.sf_gamma.igamma.references">References</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
N. M. Temme, A Set of Algorithms for the Incomplete Gamma Functions,
|
||||
Probability in the Engineering and Informational Sciences, 8, 1994.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
N. M. Temme, The Asymptotic Expansion of the Incomplete Gamma Functions,
|
||||
Siam J. Math Anal. Vol 10 No 4, July 1979, p757.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
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.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
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. <a href="http://citeseer.ist.psu.edu/gautschi98incomplete.html" target="_top">http://citeseer.ist.psu.edu/gautschi98incomplete.html</a>
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2006-2010, 2012-2014 Nikhar Agrawal,
|
||||
Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
|
||||
Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan Råde, Gautam Sewani,
|
||||
Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
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>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gamma_ratios.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_gamma.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="igamma_inv.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user