math/doc/html/math_toolkit/sf_gamma/igamma.html
2019-10-31 17:55:35 +00:00

1018 lines
52 KiB
HTML

<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.11.0">
<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">&lt;</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">&gt;</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">&lt;</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">&gt;</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">&lt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
<span class="keyword">template</span> <span class="special">&lt;</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">&gt;</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">&lt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
<span class="keyword">template</span> <span class="special">&lt;</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">&gt;</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">&lt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
<span class="keyword">template</span> <span class="special">&lt;</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">&gt;</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">&lt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</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, &#915;(a)]. Users interested
in statistical applications should use the <a href="http://mathworld.wolfram.com/RegularizedGammaFunction.html" target="_top">normalised
versions (<code class="computeroutput"><span class="identifier">gamma_p</span></code> and <code class="computeroutput"><span class="identifier">gamma_q</span></code>)</a>.
</p>
<p>
All of these functions require <span class="emphasis"><em>a &gt; 0</em></span> and <span class="emphasis"><em>z
&gt;= 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&#160;20.&#160;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&#160;20.&#160;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">&lt;</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">&gt;</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">&lt;</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">&gt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
</pre>
<p>
Returns the normalised lower incomplete gamma function of a and z:
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma4.svg"></span>
</p></blockquote></div>
<p>
This function changes rapidly from 0 to 1 around the point z == a:
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../graphs/gamma_p.svg" align="middle"></span>
</p></blockquote></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</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">&gt;</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">&lt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
</pre>
<p>
Returns the normalised upper incomplete gamma function of a and z:
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma3.svg"></span>
</p></blockquote></div>
<p>
This function changes rapidly from 1 to 0 around the point z == a:
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../graphs/gamma_q.svg" align="middle"></span>
</p></blockquote></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</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">&gt;</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">&lt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
</pre>
<p>
Returns the full (non-normalised) lower incomplete gamma function of a and
z:
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma2.svg"></span>
</p></blockquote></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</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">&gt;</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">&lt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
</pre>
<p>
Returns the full (non-normalised) upper incomplete gamma function of a and
z:
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma1.svg"></span>
</p></blockquote></div>
<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&#160;8.9.&#160;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>
GNU C++ version 7.1.0<br> linux<br> double
</p>
</th>
<th>
<p>
GNU C++ version 7.1.0<br> linux<br> long double
</p>
</th>
<th>
<p>
Sun compiler version 0x5150<br> Sun Solaris<br> long double
</p>
</th>
<th>
<p>
Microsoft Visual C++ version 14.1<br> Win32<br> double
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
tgamma(a, z) medium values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0.955&#949; (Mean = 0.05&#949;)</span><br> <br>
(<span class="emphasis"><em>GSL 2.1:</em></span> Max = 342&#949; (Mean = 45.8&#949;))<br> (<span class="emphasis"><em>Rmath
3.2.3:</em></span> Max = 389&#949; (Mean = 44&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 41.6&#949; (Mean = 8.09&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 239&#949; (Mean = 30.2&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 35.1&#949; (Mean = 6.98&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
tgamma(a, z) small values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
2.1:</em></span> Max = 4.82&#949; (Mean = 0.758&#949;))<br> (<span class="emphasis"><em>Rmath
3.2.3:</em></span> Max = 1.01&#949; (Mean = 0.306&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 2&#949; (Mean = 0.464&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 2&#949; (Mean = 0.461&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 1.54&#949; (Mean = 0.439&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
tgamma(a, z) large values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
2.1:</em></span> Max = 1.02e+03&#949; (Mean = 105&#949;))<br> (<span class="emphasis"><em>Rmath
3.2.3:</em></span> Max = 1.11e+03&#949; (Mean = 67.5&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 3.08e+04&#949; (Mean = 1.86e+03&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 3.02e+04&#949; (Mean = 1.91e+03&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 243&#949; (Mean = 20.2&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
tgamma(a, z) integer and half integer values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
2.1:</em></span> Max = 128&#949; (Mean = 22.6&#949;))<br> (<span class="emphasis"><em>Rmath
3.2.3:</em></span> Max = 66.2&#949; (Mean = 12.2&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 11.8&#949; (Mean = 2.66&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 71.6&#949; (Mean = 9.47&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 13&#949; (Mean = 2.97&#949;)</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&#160;8.10.&#160;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>
GNU C++ version 7.1.0<br> linux<br> double
</p>
</th>
<th>
<p>
GNU C++ version 7.1.0<br> linux<br> long double
</p>
</th>
<th>
<p>
Sun compiler version 0x5150<br> Sun Solaris<br> long double
</p>
</th>
<th>
<p>
Microsoft Visual C++ version 14.1<br> Win32<br> double
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
tgamma(a, z) medium values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0.927&#949; (Mean = 0.035&#949;)</span><br> <br>
(<span class="emphasis"><em>GSL 2.1:</em></span> Max = 201&#949; (Mean = 13.5&#949;))<br> (<span class="emphasis"><em>Rmath
3.2.3:</em></span> Max = 131&#949; (Mean = 12.7&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 32.3&#949; (Mean = 6.61&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 199&#949; (Mean = 26.6&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 23.7&#949; (Mean = 4&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
tgamma(a, z) small values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
2.1:</em></span> <span class="red">Max = 1.38e+10&#949; (Mean = 1.05e+09&#949;))</span><br>
(<span class="emphasis"><em>Rmath 3.2.3:</em></span> Max = 65.6&#949; (Mean = 11&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 2.45&#949; (Mean = 0.885&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 2.45&#949; (Mean = 0.819&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 2.26&#949; (Mean = 0.74&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
tgamma(a, z) large values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
2.1:</em></span> Max = 2.71e+04&#949; (Mean = 2.16e+03&#949;))<br> (<span class="emphasis"><em>Rmath
3.2.3:</em></span> Max = 1.02e+03&#949; (Mean = 62.7&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 6.82e+03&#949; (Mean = 414&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 1.15e+04&#949; (Mean = 733&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 469&#949; (Mean = 31.5&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
tgamma(a, z) integer and half integer values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
2.1:</em></span> Max = 118&#949; (Mean = 12.5&#949;))<br> (<span class="emphasis"><em>Rmath
3.2.3:</em></span> Max = 138&#949; (Mean = 16.9&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 11.1&#949; (Mean = 2.07&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 54.7&#949; (Mean = 6.16&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 8.72&#949; (Mean = 1.48&#949;)</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&#160;8.11.&#160;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>
GNU C++ version 7.1.0<br> linux<br> double
</p>
</th>
<th>
<p>
GNU C++ version 7.1.0<br> linux<br> long double
</p>
</th>
<th>
<p>
Sun compiler version 0x5150<br> Sun Solaris<br> long double
</p>
</th>
<th>
<p>
Microsoft Visual C++ version 14.1<br> Win32<br> double
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
tgamma(a, z) medium values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0.833&#949; (Mean = 0.0315&#949;)</span><br>
<br> (<span class="emphasis"><em>GSL 2.1:</em></span> Max = 0.833&#949; (Mean = 0.0315&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 6.79&#949; (Mean = 1.46&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 363&#949; (Mean = 63.8&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 5.62&#949; (Mean = 1.49&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
tgamma(a, z) small values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
2.1:</em></span> Max = 0&#949; (Mean = 0&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 1.97&#949; (Mean = 0.555&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 1.97&#949; (Mean = 0.558&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 1.57&#949; (Mean = 0.525&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
tgamma(a, z) integer and half integer values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
2.1:</em></span> Max = 0&#949; (Mean = 0&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 4.83&#949; (Mean = 1.15&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 84.7&#949; (Mean = 17.5&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 2.69&#949; (Mean = 0.849&#949;)</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&#160;8.12.&#160;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>
GNU C++ version 7.1.0<br> linux<br> double
</p>
</th>
<th>
<p>
GNU C++ version 7.1.0<br> linux<br> long double
</p>
</th>
<th>
<p>
Sun compiler version 0x5150<br> Sun Solaris<br> long double
</p>
</th>
<th>
<p>
Microsoft Visual C++ version 14.1<br> Win32<br> double
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
tgamma(a, z) medium values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
2.1:</em></span> Max = 200&#949; (Mean = 13.3&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 8.47&#949; (Mean = 1.9&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 412&#949; (Mean = 95.5&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 8.14&#949; (Mean = 1.76&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
tgamma(a, z) small values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0.753&#949; (Mean = 0.0474&#949;)</span><br>
<br> (<span class="emphasis"><em>GSL 2.1:</em></span> <span class="red">Max =
1.38e+10&#949; (Mean = 1.05e+09&#949;))</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 2.31&#949; (Mean = 0.775&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 2.13&#949; (Mean = 0.717&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 2.53&#949; (Mean = 0.66&#949;)</span>
</p>
</td>
</tr>
<tr>
<td>
<p>
tgamma(a, z) integer and half integer values
</p>
</td>
<td>
<p>
<span class="blue">Max = 0&#949; (Mean = 0&#949;)</span><br> <br> (<span class="emphasis"><em>GSL
2.1:</em></span> Max = 117&#949; (Mean = 12.5&#949;))
</p>
</td>
<td>
<p>
<span class="blue">Max = 5.52&#949; (Mean = 1.48&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 79.6&#949; (Mean = 20.9&#949;)</span>
</p>
</td>
<td>
<p>
<span class="blue">Max = 5.16&#949; (Mean = 1.33&#949;)</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)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma5.svg"></span>
</p></blockquote></div>
<p>
2)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma6.svg"></span>
</p></blockquote></div>
<p>
3)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma7.svg"></span>
</p></blockquote></div>
<p>
The lower incomplete gamma is computed from its series representation:
</p>
<p>
4)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma8.svg"></span>
</p></blockquote></div>
<p>
Or by subtraction of the upper integral from either &#915;(a) or 1 when <span class="emphasis"><em>x
- (1</em></span>(3x)) &gt; a and x &gt; 1.1/.
</p>
<p>
The upper integral is computed from Legendre's continued fraction representation:
</p>
<p>
5)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma9.svg"></span>
</p></blockquote></div>
<p>
When <span class="emphasis"><em>(x &gt; 1.1)</em></span> or by subtraction of the lower integral
from either &#915;(a) or 1 when <span class="emphasis"><em>x - (1</em></span>(3x)) &lt; a/.
</p>
<p>
For <span class="emphasis"><em>x &lt; 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)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma10.svg"></span>
</p></blockquote></div>
<p>
That lends itself to calculation of the upper integral via rearrangement
to:
</p>
<p>
7)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma11.svg"></span>
</p></blockquote></div>
<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.
</p>
<p>
For <span class="emphasis"><em>x &lt; 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 &lt; a</em></span> as the crossover criterion for <span class="emphasis"><em>0.5 &lt;
x &lt;= 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 &lt;= 0.5</em></span>
then using <span class="emphasis"><em>-0.4 / log(x) &lt; 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 &lt;= a &lt;
30</em></span> then the following finite sum is used:
</p>
<p>
9)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma1f.svg"></span>
</p></blockquote></div>
<p>
While for half-integers in the range <span class="emphasis"><em>0.5 &lt;= a &lt; 30</em></span>
then the following finite sum is used:
</p>
<p>
10)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma2f.svg"></span>
</p></blockquote></div>
<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)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma16.svg"></span>
</p></blockquote></div>
<p>
12)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma17.svg"></span>
</p></blockquote></div>
<p>
13)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma18.svg"></span>
</p></blockquote></div>
<p>
14)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma19.svg"></span>
</p></blockquote></div>
<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">&gt;</span> <span class="number">20</span><span class="special">)</span> <span class="special">&amp;&amp;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&lt;</span> <span class="number">200</span><span class="special">)</span> <span class="special">&amp;&amp;</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">&lt;</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">&gt;</span> <span class="number">200</span><span class="special">)</span> <span class="special">&amp;&amp;</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">&lt;</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)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma12.svg"></span>
</p></blockquote></div>
<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)
</p>
<div class="blockquote"><blockquote class="blockquote"><p>
<span class="inlinemediaobject"><img src="../../../equations/igamma13.svg"></span>
</p></blockquote></div>
<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 &#169; 2006-2019 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
R&#229;de, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, 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>