| 1 |
<html> |
| 2 |
<head> |
| 3 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 4 |
<title>Incomplete Gamma Functions</title> |
| 5 |
<link rel="stylesheet" href="../../math.css" type="text/css"> |
| 6 |
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> |
| 7 |
<link rel="home" href="../../index.html" title="Math Toolkit 4.2.1"> |
| 8 |
<link rel="up" href="../sf_gamma.html" title="Gamma Functions"> |
| 9 |
<link rel="prev" href="gamma_ratios.html" title="Ratios of Gamma Functions"> |
| 10 |
<link rel="next" href="igamma_inv.html" title="Incomplete Gamma Function Inverses"> |
| 11 |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 12 |
</head> |
| 13 |
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| 14 |
<table cellpadding="2" width="100%"><tr> |
| 15 |
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> |
| 16 |
<td align="center"><a href="../../../../../../index.html">Home</a></td> |
| 17 |
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> |
| 18 |
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> |
| 19 |
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> |
| 20 |
<td align="center"><a href="../../../../../../more/index.htm">More</a></td> |
| 21 |
</tr></table> |
| 22 |
<hr> |
| 23 |
<div class="spirit-nav"> |
| 24 |
<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> |
| 25 |
</div> |
| 26 |
<div class="section"> |
| 27 |
<div class="titlepage"><div><div><h3 class="title"> |
| 28 |
<a name="math_toolkit.sf_gamma.igamma"></a><a class="link" href="igamma.html" title="Incomplete Gamma Functions">Incomplete Gamma Functions</a> |
| 29 |
</h3></div></div></div> |
| 30 |
<h5> |
| 31 |
<a name="math_toolkit.sf_gamma.igamma.h0"></a> |
| 32 |
<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> |
| 33 |
</h5> |
| 34 |
<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> |
| 35 |
</pre> |
| 36 |
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span> |
| 37 |
|
| 38 |
<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> |
| 39 |
<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> |
| 40 |
|
| 41 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> |
| 42 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> |
| 43 |
|
| 44 |
<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> |
| 45 |
<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> |
| 46 |
|
| 47 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> |
| 48 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> |
| 49 |
|
| 50 |
<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> |
| 51 |
<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> |
| 52 |
|
| 53 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> |
| 54 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> |
| 55 |
|
| 56 |
<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> |
| 57 |
<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> |
| 58 |
|
| 59 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> |
| 60 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> |
| 61 |
|
| 62 |
<span class="special">}}</span> <span class="comment">// namespaces</span> |
| 63 |
</pre> |
| 64 |
<h5> |
| 65 |
<a name="math_toolkit.sf_gamma.igamma.h1"></a> |
| 66 |
<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> |
| 67 |
</h5> |
| 68 |
<p> |
| 69 |
There are four <a href="http://mathworld.wolfram.com/IncompleteGammaFunction.html" target="_top">incomplete |
| 70 |
gamma functions</a>: two are normalised versions (also known as <span class="emphasis"><em>regularized</em></span> |
| 71 |
incomplete gamma functions) that return values in the range [0, 1], and two |
| 72 |
are non-normalised and return values in the range [0, Γ(a)]. Users interested |
| 73 |
in statistical applications should use the <a href="http://mathworld.wolfram.com/RegularizedGammaFunction.html" target="_top">normalised |
| 74 |
versions (<code class="computeroutput"><span class="identifier">gamma_p</span></code> and <code class="computeroutput"><span class="identifier">gamma_q</span></code>)</a>. |
| 75 |
</p> |
| 76 |
<p> |
| 77 |
All of these functions require <span class="emphasis"><em>a > 0</em></span> and <span class="emphasis"><em>z |
| 78 |
>= 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>. |
| 79 |
</p> |
| 80 |
<p> |
| 81 |
The final <a class="link" href="../../policy.html" title="Chapter 22. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can |
| 82 |
be used to control the behaviour of the function: how it handles errors, |
| 83 |
what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 22. Policies: Controlling Precision, Error Handling etc">policy |
| 84 |
documentation for more details</a>. |
| 85 |
</p> |
| 86 |
<p> |
| 87 |
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 |
| 88 |
type calculation rules</em></span></a> when T1 and T2 are different types, |
| 89 |
otherwise the return type is simply T1. |
| 90 |
</p> |
| 91 |
<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> |
| 92 |
<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> |
| 93 |
|
| 94 |
<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> |
| 95 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> |
| 96 |
</pre> |
| 97 |
<p> |
| 98 |
Returns the normalised lower incomplete gamma function of a and z: |
| 99 |
</p> |
| 100 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 101 |
<span class="inlinemediaobject"><img src="../../../equations/igamma4.svg"></span> |
| 102 |
|
| 103 |
</p></blockquote></div> |
| 104 |
<p> |
| 105 |
This function changes rapidly from 0 to 1 around the point z == a: |
| 106 |
</p> |
| 107 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 108 |
<span class="inlinemediaobject"><img src="../../../graphs/gamma_p.svg" align="middle"></span> |
| 109 |
|
| 110 |
</p></blockquote></div> |
| 111 |
<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> |
| 112 |
<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> |
| 113 |
|
| 114 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> |
| 115 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> |
| 116 |
</pre> |
| 117 |
<p> |
| 118 |
Returns the normalised upper incomplete gamma function of a and z: |
| 119 |
</p> |
| 120 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 121 |
<span class="inlinemediaobject"><img src="../../../equations/igamma3.svg"></span> |
| 122 |
|
| 123 |
</p></blockquote></div> |
| 124 |
<p> |
| 125 |
This function changes rapidly from 1 to 0 around the point z == a: |
| 126 |
</p> |
| 127 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 128 |
<span class="inlinemediaobject"><img src="../../../graphs/gamma_q.svg" align="middle"></span> |
| 129 |
|
| 130 |
</p></blockquote></div> |
| 131 |
<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> |
| 132 |
<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> |
| 133 |
|
| 134 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> |
| 135 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> |
| 136 |
</pre> |
| 137 |
<p> |
| 138 |
Returns the full (non-normalised) lower incomplete gamma function of a and |
| 139 |
z: |
| 140 |
</p> |
| 141 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 142 |
<span class="inlinemediaobject"><img src="../../../equations/igamma2.svg"></span> |
| 143 |
|
| 144 |
</p></blockquote></div> |
| 145 |
<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> |
| 146 |
<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> |
| 147 |
|
| 148 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> |
| 149 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> |
| 150 |
</pre> |
| 151 |
<p> |
| 152 |
Returns the full (non-normalised) upper incomplete gamma function of a and |
| 153 |
z: |
| 154 |
</p> |
| 155 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 156 |
<span class="inlinemediaobject"><img src="../../../equations/igamma1.svg"></span> |
| 157 |
|
| 158 |
</p></blockquote></div> |
| 159 |
<h5> |
| 160 |
<a name="math_toolkit.sf_gamma.igamma.h2"></a> |
| 161 |
<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> |
| 162 |
</h5> |
| 163 |
<p> |
| 164 |
The following tables give peak and mean relative errors in over various domains |
| 165 |
of a and z, along with comparisons to the <a href="http://www.gnu.org/software/gsl/" target="_top">GSL-1.9</a> |
| 166 |
and <a href="http://www.netlib.org/cephes/" target="_top">Cephes</a> libraries. |
| 167 |
Note that only results for the widest floating-point type on the system are |
| 168 |
given as narrower types have <a class="link" href="../relative_error.html#math_toolkit.relative_error.zero_error">effectively |
| 169 |
zero error</a>. |
| 170 |
</p> |
| 171 |
<p> |
| 172 |
Note that errors grow as <span class="emphasis"><em>a</em></span> grows larger. |
| 173 |
</p> |
| 174 |
<p> |
| 175 |
Note also that the higher error rates for the 80 and 128 bit long double |
| 176 |
results are somewhat misleading: expected results that are zero at 64-bit |
| 177 |
double precision may be non-zero - but exceptionally small - with the larger |
| 178 |
exponent range of a long double. These results therefore reflect the more |
| 179 |
extreme nature of the tests conducted for these types. |
| 180 |
</p> |
| 181 |
<p> |
| 182 |
All values are in units of epsilon. |
| 183 |
</p> |
| 184 |
<div class="table"> |
| 185 |
<a name="math_toolkit.sf_gamma.igamma.table_gamma_p"></a><p class="title"><b>Table 8.9. Error rates for gamma_p</b></p> |
| 186 |
<div class="table-contents"><table class="table" summary="Error rates for gamma_p"> |
| 187 |
<colgroup> |
| 188 |
<col> |
| 189 |
<col> |
| 190 |
<col> |
| 191 |
<col> |
| 192 |
<col> |
| 193 |
</colgroup> |
| 194 |
<thead><tr> |
| 195 |
<th> |
| 196 |
</th> |
| 197 |
<th> |
| 198 |
<p> |
| 199 |
GNU C++ version 7.1.0<br> linux<br> double |
| 200 |
</p> |
| 201 |
</th> |
| 202 |
<th> |
| 203 |
<p> |
| 204 |
GNU C++ version 7.1.0<br> linux<br> long double |
| 205 |
</p> |
| 206 |
</th> |
| 207 |
<th> |
| 208 |
<p> |
| 209 |
Sun compiler version 0x5150<br> Sun Solaris<br> long double |
| 210 |
</p> |
| 211 |
</th> |
| 212 |
<th> |
| 213 |
<p> |
| 214 |
Microsoft Visual C++ version 14.1<br> Win32<br> double |
| 215 |
</p> |
| 216 |
</th> |
| 217 |
</tr></thead> |
| 218 |
<tbody> |
| 219 |
<tr> |
| 220 |
<td> |
| 221 |
<p> |
| 222 |
tgamma(a, z) medium values |
| 223 |
</p> |
| 224 |
</td> |
| 225 |
<td> |
| 226 |
<p> |
| 227 |
<span class="blue">Max = 0.955ε (Mean = 0.05ε)</span><br> <br> |
| 228 |
(<span class="emphasis"><em>GSL 2.1:</em></span> Max = 342ε (Mean = 45.8ε))<br> (<span class="emphasis"><em>Rmath |
| 229 |
3.2.3:</em></span> Max = 389ε (Mean = 44ε)) |
| 230 |
</p> |
| 231 |
</td> |
| 232 |
<td> |
| 233 |
<p> |
| 234 |
<span class="blue">Max = 41.6ε (Mean = 8.09ε)</span> |
| 235 |
</p> |
| 236 |
</td> |
| 237 |
<td> |
| 238 |
<p> |
| 239 |
<span class="blue">Max = 239ε (Mean = 30.2ε)</span> |
| 240 |
</p> |
| 241 |
</td> |
| 242 |
<td> |
| 243 |
<p> |
| 244 |
<span class="blue">Max = 35.1ε (Mean = 6.98ε)</span> |
| 245 |
</p> |
| 246 |
</td> |
| 247 |
</tr> |
| 248 |
<tr> |
| 249 |
<td> |
| 250 |
<p> |
| 251 |
tgamma(a, z) small values |
| 252 |
</p> |
| 253 |
</td> |
| 254 |
<td> |
| 255 |
<p> |
| 256 |
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL |
| 257 |
2.1:</em></span> Max = 4.82ε (Mean = 0.758ε))<br> (<span class="emphasis"><em>Rmath |
| 258 |
3.2.3:</em></span> Max = 1.01ε (Mean = 0.306ε)) |
| 259 |
</p> |
| 260 |
</td> |
| 261 |
<td> |
| 262 |
<p> |
| 263 |
<span class="blue">Max = 2ε (Mean = 0.464ε)</span> |
| 264 |
</p> |
| 265 |
</td> |
| 266 |
<td> |
| 267 |
<p> |
| 268 |
<span class="blue">Max = 2ε (Mean = 0.461ε)</span> |
| 269 |
</p> |
| 270 |
</td> |
| 271 |
<td> |
| 272 |
<p> |
| 273 |
<span class="blue">Max = 1.54ε (Mean = 0.439ε)</span> |
| 274 |
</p> |
| 275 |
</td> |
| 276 |
</tr> |
| 277 |
<tr> |
| 278 |
<td> |
| 279 |
<p> |
| 280 |
tgamma(a, z) large values |
| 281 |
</p> |
| 282 |
</td> |
| 283 |
<td> |
| 284 |
<p> |
| 285 |
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL |
| 286 |
2.1:</em></span> Max = 1.02e+03ε (Mean = 105ε))<br> (<span class="emphasis"><em>Rmath |
| 287 |
3.2.3:</em></span> Max = 1.11e+03ε (Mean = 67.5ε)) |
| 288 |
</p> |
| 289 |
</td> |
| 290 |
<td> |
| 291 |
<p> |
| 292 |
<span class="blue">Max = 3.08e+04ε (Mean = 1.86e+03ε)</span> |
| 293 |
</p> |
| 294 |
</td> |
| 295 |
<td> |
| 296 |
<p> |
| 297 |
<span class="blue">Max = 3.02e+04ε (Mean = 1.91e+03ε)</span> |
| 298 |
</p> |
| 299 |
</td> |
| 300 |
<td> |
| 301 |
<p> |
| 302 |
<span class="blue">Max = 243ε (Mean = 20.2ε)</span> |
| 303 |
</p> |
| 304 |
</td> |
| 305 |
</tr> |
| 306 |
<tr> |
| 307 |
<td> |
| 308 |
<p> |
| 309 |
tgamma(a, z) integer and half integer values |
| 310 |
</p> |
| 311 |
</td> |
| 312 |
<td> |
| 313 |
<p> |
| 314 |
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL |
| 315 |
2.1:</em></span> Max = 128ε (Mean = 22.6ε))<br> (<span class="emphasis"><em>Rmath |
| 316 |
3.2.3:</em></span> Max = 66.2ε (Mean = 12.2ε)) |
| 317 |
</p> |
| 318 |
</td> |
| 319 |
<td> |
| 320 |
<p> |
| 321 |
<span class="blue">Max = 11.8ε (Mean = 2.66ε)</span> |
| 322 |
</p> |
| 323 |
</td> |
| 324 |
<td> |
| 325 |
<p> |
| 326 |
<span class="blue">Max = 71.6ε (Mean = 9.47ε)</span> |
| 327 |
</p> |
| 328 |
</td> |
| 329 |
<td> |
| 330 |
<p> |
| 331 |
<span class="blue">Max = 13ε (Mean = 2.97ε)</span> |
| 332 |
</p> |
| 333 |
</td> |
| 334 |
</tr> |
| 335 |
</tbody> |
| 336 |
</table></div> |
| 337 |
</div> |
| 338 |
<br class="table-break"><div class="table"> |
| 339 |
<a name="math_toolkit.sf_gamma.igamma.table_gamma_q"></a><p class="title"><b>Table 8.10. Error rates for gamma_q</b></p> |
| 340 |
<div class="table-contents"><table class="table" summary="Error rates for gamma_q"> |
| 341 |
<colgroup> |
| 342 |
<col> |
| 343 |
<col> |
| 344 |
<col> |
| 345 |
<col> |
| 346 |
<col> |
| 347 |
</colgroup> |
| 348 |
<thead><tr> |
| 349 |
<th> |
| 350 |
</th> |
| 351 |
<th> |
| 352 |
<p> |
| 353 |
GNU C++ version 7.1.0<br> linux<br> double |
| 354 |
</p> |
| 355 |
</th> |
| 356 |
<th> |
| 357 |
<p> |
| 358 |
GNU C++ version 7.1.0<br> linux<br> long double |
| 359 |
</p> |
| 360 |
</th> |
| 361 |
<th> |
| 362 |
<p> |
| 363 |
Sun compiler version 0x5150<br> Sun Solaris<br> long double |
| 364 |
</p> |
| 365 |
</th> |
| 366 |
<th> |
| 367 |
<p> |
| 368 |
Microsoft Visual C++ version 14.1<br> Win32<br> double |
| 369 |
</p> |
| 370 |
</th> |
| 371 |
</tr></thead> |
| 372 |
<tbody> |
| 373 |
<tr> |
| 374 |
<td> |
| 375 |
<p> |
| 376 |
tgamma(a, z) medium values |
| 377 |
</p> |
| 378 |
</td> |
| 379 |
<td> |
| 380 |
<p> |
| 381 |
<span class="blue">Max = 0.927ε (Mean = 0.035ε)</span><br> <br> |
| 382 |
(<span class="emphasis"><em>GSL 2.1:</em></span> Max = 201ε (Mean = 13.5ε))<br> (<span class="emphasis"><em>Rmath |
| 383 |
3.2.3:</em></span> Max = 131ε (Mean = 12.7ε)) |
| 384 |
</p> |
| 385 |
</td> |
| 386 |
<td> |
| 387 |
<p> |
| 388 |
<span class="blue">Max = 32.3ε (Mean = 6.61ε)</span> |
| 389 |
</p> |
| 390 |
</td> |
| 391 |
<td> |
| 392 |
<p> |
| 393 |
<span class="blue">Max = 199ε (Mean = 26.6ε)</span> |
| 394 |
</p> |
| 395 |
</td> |
| 396 |
<td> |
| 397 |
<p> |
| 398 |
<span class="blue">Max = 23.7ε (Mean = 4ε)</span> |
| 399 |
</p> |
| 400 |
</td> |
| 401 |
</tr> |
| 402 |
<tr> |
| 403 |
<td> |
| 404 |
<p> |
| 405 |
tgamma(a, z) small values |
| 406 |
</p> |
| 407 |
</td> |
| 408 |
<td> |
| 409 |
<p> |
| 410 |
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL |
| 411 |
2.1:</em></span> <span class="red">Max = 1.38e+10ε (Mean = 1.05e+09ε))</span><br> |
| 412 |
(<span class="emphasis"><em>Rmath 3.2.3:</em></span> Max = 65.6ε (Mean = 11ε)) |
| 413 |
</p> |
| 414 |
</td> |
| 415 |
<td> |
| 416 |
<p> |
| 417 |
<span class="blue">Max = 2.45ε (Mean = 0.885ε)</span> |
| 418 |
</p> |
| 419 |
</td> |
| 420 |
<td> |
| 421 |
<p> |
| 422 |
<span class="blue">Max = 2.45ε (Mean = 0.819ε)</span> |
| 423 |
</p> |
| 424 |
</td> |
| 425 |
<td> |
| 426 |
<p> |
| 427 |
<span class="blue">Max = 2.26ε (Mean = 0.74ε)</span> |
| 428 |
</p> |
| 429 |
</td> |
| 430 |
</tr> |
| 431 |
<tr> |
| 432 |
<td> |
| 433 |
<p> |
| 434 |
tgamma(a, z) large values |
| 435 |
</p> |
| 436 |
</td> |
| 437 |
<td> |
| 438 |
<p> |
| 439 |
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL |
| 440 |
2.1:</em></span> Max = 2.71e+04ε (Mean = 2.16e+03ε))<br> (<span class="emphasis"><em>Rmath |
| 441 |
3.2.3:</em></span> Max = 1.02e+03ε (Mean = 62.7ε)) |
| 442 |
</p> |
| 443 |
</td> |
| 444 |
<td> |
| 445 |
<p> |
| 446 |
<span class="blue">Max = 6.82e+03ε (Mean = 414ε)</span> |
| 447 |
</p> |
| 448 |
</td> |
| 449 |
<td> |
| 450 |
<p> |
| 451 |
<span class="blue">Max = 1.15e+04ε (Mean = 733ε)</span> |
| 452 |
</p> |
| 453 |
</td> |
| 454 |
<td> |
| 455 |
<p> |
| 456 |
<span class="blue">Max = 469ε (Mean = 31.5ε)</span> |
| 457 |
</p> |
| 458 |
</td> |
| 459 |
</tr> |
| 460 |
<tr> |
| 461 |
<td> |
| 462 |
<p> |
| 463 |
tgamma(a, z) integer and half integer values |
| 464 |
</p> |
| 465 |
</td> |
| 466 |
<td> |
| 467 |
<p> |
| 468 |
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL |
| 469 |
2.1:</em></span> Max = 118ε (Mean = 12.5ε))<br> (<span class="emphasis"><em>Rmath |
| 470 |
3.2.3:</em></span> Max = 138ε (Mean = 16.9ε)) |
| 471 |
</p> |
| 472 |
</td> |
| 473 |
<td> |
| 474 |
<p> |
| 475 |
<span class="blue">Max = 11.1ε (Mean = 2.07ε)</span> |
| 476 |
</p> |
| 477 |
</td> |
| 478 |
<td> |
| 479 |
<p> |
| 480 |
<span class="blue">Max = 54.7ε (Mean = 6.16ε)</span> |
| 481 |
</p> |
| 482 |
</td> |
| 483 |
<td> |
| 484 |
<p> |
| 485 |
<span class="blue">Max = 8.72ε (Mean = 1.48ε)</span> |
| 486 |
</p> |
| 487 |
</td> |
| 488 |
</tr> |
| 489 |
</tbody> |
| 490 |
</table></div> |
| 491 |
</div> |
| 492 |
<br class="table-break"><div class="table"> |
| 493 |
<a name="math_toolkit.sf_gamma.igamma.table_tgamma_lower"></a><p class="title"><b>Table 8.11. Error rates for tgamma_lower</b></p> |
| 494 |
<div class="table-contents"><table class="table" summary="Error rates for tgamma_lower"> |
| 495 |
<colgroup> |
| 496 |
<col> |
| 497 |
<col> |
| 498 |
<col> |
| 499 |
<col> |
| 500 |
<col> |
| 501 |
</colgroup> |
| 502 |
<thead><tr> |
| 503 |
<th> |
| 504 |
</th> |
| 505 |
<th> |
| 506 |
<p> |
| 507 |
GNU C++ version 7.1.0<br> linux<br> double |
| 508 |
</p> |
| 509 |
</th> |
| 510 |
<th> |
| 511 |
<p> |
| 512 |
GNU C++ version 7.1.0<br> linux<br> long double |
| 513 |
</p> |
| 514 |
</th> |
| 515 |
<th> |
| 516 |
<p> |
| 517 |
Sun compiler version 0x5150<br> Sun Solaris<br> long double |
| 518 |
</p> |
| 519 |
</th> |
| 520 |
<th> |
| 521 |
<p> |
| 522 |
Microsoft Visual C++ version 14.1<br> Win32<br> double |
| 523 |
</p> |
| 524 |
</th> |
| 525 |
</tr></thead> |
| 526 |
<tbody> |
| 527 |
<tr> |
| 528 |
<td> |
| 529 |
<p> |
| 530 |
tgamma(a, z) medium values |
| 531 |
</p> |
| 532 |
</td> |
| 533 |
<td> |
| 534 |
<p> |
| 535 |
<span class="blue">Max = 0.833ε (Mean = 0.0315ε)</span><br> |
| 536 |
<br> (<span class="emphasis"><em>GSL 2.1:</em></span> Max = 0.833ε (Mean = 0.0315ε)) |
| 537 |
</p> |
| 538 |
</td> |
| 539 |
<td> |
| 540 |
<p> |
| 541 |
<span class="blue">Max = 6.79ε (Mean = 1.46ε)</span> |
| 542 |
</p> |
| 543 |
</td> |
| 544 |
<td> |
| 545 |
<p> |
| 546 |
<span class="blue">Max = 363ε (Mean = 63.8ε)</span> |
| 547 |
</p> |
| 548 |
</td> |
| 549 |
<td> |
| 550 |
<p> |
| 551 |
<span class="blue">Max = 5.62ε (Mean = 1.49ε)</span> |
| 552 |
</p> |
| 553 |
</td> |
| 554 |
</tr> |
| 555 |
<tr> |
| 556 |
<td> |
| 557 |
<p> |
| 558 |
tgamma(a, z) small values |
| 559 |
</p> |
| 560 |
</td> |
| 561 |
<td> |
| 562 |
<p> |
| 563 |
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL |
| 564 |
2.1:</em></span> Max = 0ε (Mean = 0ε)) |
| 565 |
</p> |
| 566 |
</td> |
| 567 |
<td> |
| 568 |
<p> |
| 569 |
<span class="blue">Max = 1.97ε (Mean = 0.555ε)</span> |
| 570 |
</p> |
| 571 |
</td> |
| 572 |
<td> |
| 573 |
<p> |
| 574 |
<span class="blue">Max = 1.97ε (Mean = 0.558ε)</span> |
| 575 |
</p> |
| 576 |
</td> |
| 577 |
<td> |
| 578 |
<p> |
| 579 |
<span class="blue">Max = 1.57ε (Mean = 0.525ε)</span> |
| 580 |
</p> |
| 581 |
</td> |
| 582 |
</tr> |
| 583 |
<tr> |
| 584 |
<td> |
| 585 |
<p> |
| 586 |
tgamma(a, z) integer and half integer values |
| 587 |
</p> |
| 588 |
</td> |
| 589 |
<td> |
| 590 |
<p> |
| 591 |
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL |
| 592 |
2.1:</em></span> Max = 0ε (Mean = 0ε)) |
| 593 |
</p> |
| 594 |
</td> |
| 595 |
<td> |
| 596 |
<p> |
| 597 |
<span class="blue">Max = 4.83ε (Mean = 1.15ε)</span> |
| 598 |
</p> |
| 599 |
</td> |
| 600 |
<td> |
| 601 |
<p> |
| 602 |
<span class="blue">Max = 84.7ε (Mean = 17.5ε)</span> |
| 603 |
</p> |
| 604 |
</td> |
| 605 |
<td> |
| 606 |
<p> |
| 607 |
<span class="blue">Max = 2.69ε (Mean = 0.849ε)</span> |
| 608 |
</p> |
| 609 |
</td> |
| 610 |
</tr> |
| 611 |
</tbody> |
| 612 |
</table></div> |
| 613 |
</div> |
| 614 |
<br class="table-break"><div class="table"> |
| 615 |
<a name="math_toolkit.sf_gamma.igamma.table_tgamma_incomplete_"></a><p class="title"><b>Table 8.12. Error rates for tgamma (incomplete)</b></p> |
| 616 |
<div class="table-contents"><table class="table" summary="Error rates for tgamma (incomplete)"> |
| 617 |
<colgroup> |
| 618 |
<col> |
| 619 |
<col> |
| 620 |
<col> |
| 621 |
<col> |
| 622 |
<col> |
| 623 |
</colgroup> |
| 624 |
<thead><tr> |
| 625 |
<th> |
| 626 |
</th> |
| 627 |
<th> |
| 628 |
<p> |
| 629 |
GNU C++ version 7.1.0<br> linux<br> double |
| 630 |
</p> |
| 631 |
</th> |
| 632 |
<th> |
| 633 |
<p> |
| 634 |
GNU C++ version 7.1.0<br> linux<br> long double |
| 635 |
</p> |
| 636 |
</th> |
| 637 |
<th> |
| 638 |
<p> |
| 639 |
Sun compiler version 0x5150<br> Sun Solaris<br> long double |
| 640 |
</p> |
| 641 |
</th> |
| 642 |
<th> |
| 643 |
<p> |
| 644 |
Microsoft Visual C++ version 14.1<br> Win32<br> double |
| 645 |
</p> |
| 646 |
</th> |
| 647 |
</tr></thead> |
| 648 |
<tbody> |
| 649 |
<tr> |
| 650 |
<td> |
| 651 |
<p> |
| 652 |
tgamma(a, z) medium values |
| 653 |
</p> |
| 654 |
</td> |
| 655 |
<td> |
| 656 |
<p> |
| 657 |
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL |
| 658 |
2.1:</em></span> Max = 200ε (Mean = 13.3ε)) |
| 659 |
</p> |
| 660 |
</td> |
| 661 |
<td> |
| 662 |
<p> |
| 663 |
<span class="blue">Max = 8.47ε (Mean = 1.9ε)</span> |
| 664 |
</p> |
| 665 |
</td> |
| 666 |
<td> |
| 667 |
<p> |
| 668 |
<span class="blue">Max = 412ε (Mean = 95.5ε)</span> |
| 669 |
</p> |
| 670 |
</td> |
| 671 |
<td> |
| 672 |
<p> |
| 673 |
<span class="blue">Max = 8.14ε (Mean = 1.76ε)</span> |
| 674 |
</p> |
| 675 |
</td> |
| 676 |
</tr> |
| 677 |
<tr> |
| 678 |
<td> |
| 679 |
<p> |
| 680 |
tgamma(a, z) small values |
| 681 |
</p> |
| 682 |
</td> |
| 683 |
<td> |
| 684 |
<p> |
| 685 |
<span class="blue">Max = 0.753ε (Mean = 0.0474ε)</span><br> |
| 686 |
<br> (<span class="emphasis"><em>GSL 2.1:</em></span> <span class="red">Max = |
| 687 |
1.38e+10ε (Mean = 1.05e+09ε))</span> |
| 688 |
</p> |
| 689 |
</td> |
| 690 |
<td> |
| 691 |
<p> |
| 692 |
<span class="blue">Max = 2.31ε (Mean = 0.775ε)</span> |
| 693 |
</p> |
| 694 |
</td> |
| 695 |
<td> |
| 696 |
<p> |
| 697 |
<span class="blue">Max = 2.13ε (Mean = 0.717ε)</span> |
| 698 |
</p> |
| 699 |
</td> |
| 700 |
<td> |
| 701 |
<p> |
| 702 |
<span class="blue">Max = 2.53ε (Mean = 0.66ε)</span> |
| 703 |
</p> |
| 704 |
</td> |
| 705 |
</tr> |
| 706 |
<tr> |
| 707 |
<td> |
| 708 |
<p> |
| 709 |
tgamma(a, z) integer and half integer values |
| 710 |
</p> |
| 711 |
</td> |
| 712 |
<td> |
| 713 |
<p> |
| 714 |
<span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL |
| 715 |
2.1:</em></span> Max = 117ε (Mean = 12.5ε)) |
| 716 |
</p> |
| 717 |
</td> |
| 718 |
<td> |
| 719 |
<p> |
| 720 |
<span class="blue">Max = 5.52ε (Mean = 1.48ε)</span> |
| 721 |
</p> |
| 722 |
</td> |
| 723 |
<td> |
| 724 |
<p> |
| 725 |
<span class="blue">Max = 79.6ε (Mean = 20.9ε)</span> |
| 726 |
</p> |
| 727 |
</td> |
| 728 |
<td> |
| 729 |
<p> |
| 730 |
<span class="blue">Max = 5.16ε (Mean = 1.33ε)</span> |
| 731 |
</p> |
| 732 |
</td> |
| 733 |
</tr> |
| 734 |
</tbody> |
| 735 |
</table></div> |
| 736 |
</div> |
| 737 |
<br class="table-break"><h5> |
| 738 |
<a name="math_toolkit.sf_gamma.igamma.h3"></a> |
| 739 |
<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> |
| 740 |
</h5> |
| 741 |
<p> |
| 742 |
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> |
| 743 |
with this implementation to perform a basic "sanity check". Accuracy |
| 744 |
tests use data generated at very high precision (using NTL's RR class set |
| 745 |
at 1000-bit precision) using this implementation with a very high precision |
| 746 |
60-term <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos approximation</a>, |
| 747 |
and some but not all of the special case handling disabled. This is less |
| 748 |
than satisfactory: an independent method should really be used, but apparently |
| 749 |
a complete lack of such methods are available. We can't even use a deliberately |
| 750 |
naive implementation without special case handling since Legendre's continued |
| 751 |
fraction (see below) is unstable for small a and z. |
| 752 |
</p> |
| 753 |
<h5> |
| 754 |
<a name="math_toolkit.sf_gamma.igamma.h4"></a> |
| 755 |
<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> |
| 756 |
</h5> |
| 757 |
<p> |
| 758 |
These four functions share a common implementation since they are all related |
| 759 |
via: |
| 760 |
</p> |
| 761 |
<p> |
| 762 |
1) |
| 763 |
</p> |
| 764 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 765 |
<span class="inlinemediaobject"><img src="../../../equations/igamma5.svg"></span> |
| 766 |
|
| 767 |
</p></blockquote></div> |
| 768 |
<p> |
| 769 |
2) |
| 770 |
</p> |
| 771 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 772 |
<span class="inlinemediaobject"><img src="../../../equations/igamma6.svg"></span> |
| 773 |
|
| 774 |
</p></blockquote></div> |
| 775 |
<p> |
| 776 |
3) |
| 777 |
</p> |
| 778 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 779 |
<span class="inlinemediaobject"><img src="../../../equations/igamma7.svg"></span> |
| 780 |
|
| 781 |
</p></blockquote></div> |
| 782 |
<p> |
| 783 |
The lower incomplete gamma is computed from its series representation: |
| 784 |
</p> |
| 785 |
<p> |
| 786 |
4) |
| 787 |
</p> |
| 788 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 789 |
<span class="inlinemediaobject"><img src="../../../equations/igamma8.svg"></span> |
| 790 |
|
| 791 |
</p></blockquote></div> |
| 792 |
<p> |
| 793 |
Or by subtraction of the upper integral from either Γ(a) or 1 when <span class="emphasis"><em>x |
| 794 |
- (1</em></span>(3x)) > a and x > 1.1/. |
| 795 |
</p> |
| 796 |
<p> |
| 797 |
The upper integral is computed from Legendre's continued fraction representation: |
| 798 |
</p> |
| 799 |
<p> |
| 800 |
5) |
| 801 |
</p> |
| 802 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 803 |
<span class="inlinemediaobject"><img src="../../../equations/igamma9.svg"></span> |
| 804 |
|
| 805 |
</p></blockquote></div> |
| 806 |
<p> |
| 807 |
When <span class="emphasis"><em>(x > 1.1)</em></span> or by subtraction of the lower integral |
| 808 |
from either Γ(a) or 1 when <span class="emphasis"><em>x - (1</em></span>(3x)) < a/. |
| 809 |
</p> |
| 810 |
<p> |
| 811 |
For <span class="emphasis"><em>x < 1.1</em></span> computation of the upper integral is |
| 812 |
more complex as the continued fraction representation is unstable in this |
| 813 |
area. However there is another series representation for the lower integral: |
| 814 |
</p> |
| 815 |
<p> |
| 816 |
6) |
| 817 |
</p> |
| 818 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 819 |
<span class="inlinemediaobject"><img src="../../../equations/igamma10.svg"></span> |
| 820 |
|
| 821 |
</p></blockquote></div> |
| 822 |
<p> |
| 823 |
That lends itself to calculation of the upper integral via rearrangement |
| 824 |
to: |
| 825 |
</p> |
| 826 |
<p> |
| 827 |
7) |
| 828 |
</p> |
| 829 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 830 |
<span class="inlinemediaobject"><img src="../../../equations/igamma11.svg"></span> |
| 831 |
|
| 832 |
</p></blockquote></div> |
| 833 |
<p> |
| 834 |
Refer to the documentation for <a class="link" href="../powers/powm1.html" title="powm1">powm1</a> |
| 835 |
and <a class="link" href="tgamma.html" title="Gamma">tgamma1pm1</a> for details |
| 836 |
of their implementation. |
| 837 |
</p> |
| 838 |
<p> |
| 839 |
For <span class="emphasis"><em>x < 1.1</em></span> the crossover point where the result |
| 840 |
is ~0.5 no longer occurs for <span class="emphasis"><em>x ~ y</em></span>. Using <span class="emphasis"><em>x |
| 841 |
* 0.75 < a</em></span> as the crossover criterion for <span class="emphasis"><em>0.5 < |
| 842 |
x <= 1.1</em></span> keeps the maximum value computed (whether it's the |
| 843 |
upper or lower interval) to around 0.75. Likewise for <span class="emphasis"><em>x <= 0.5</em></span> |
| 844 |
then using <span class="emphasis"><em>-0.4 / log(x) < a</em></span> as the crossover criterion |
| 845 |
keeps the maximum value computed to around 0.7 (whether it's the upper or |
| 846 |
lower interval). |
| 847 |
</p> |
| 848 |
<p> |
| 849 |
There are two special cases used when a is an integer or half integer, and |
| 850 |
the crossover conditions listed above indicate that we should compute the |
| 851 |
upper integral Q. If a is an integer in the range <span class="emphasis"><em>1 <= a < |
| 852 |
30</em></span> then the following finite sum is used: |
| 853 |
</p> |
| 854 |
<p> |
| 855 |
9) |
| 856 |
</p> |
| 857 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 858 |
<span class="inlinemediaobject"><img src="../../../equations/igamma1f.svg"></span> |
| 859 |
|
| 860 |
</p></blockquote></div> |
| 861 |
<p> |
| 862 |
While for half-integers in the range <span class="emphasis"><em>0.5 <= a < 30</em></span> |
| 863 |
then the following finite sum is used: |
| 864 |
</p> |
| 865 |
<p> |
| 866 |
10) |
| 867 |
</p> |
| 868 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 869 |
<span class="inlinemediaobject"><img src="../../../equations/igamma2f.svg"></span> |
| 870 |
|
| 871 |
</p></blockquote></div> |
| 872 |
<p> |
| 873 |
These are both more stable and more efficient than the continued fraction |
| 874 |
alternative. |
| 875 |
</p> |
| 876 |
<p> |
| 877 |
When the argument <span class="emphasis"><em>a</em></span> is large, and <span class="emphasis"><em>x ~ a</em></span> |
| 878 |
then the series (4) and continued fraction (5) above are very slow to converge. |
| 879 |
In this area an expansion due to Temme is used: |
| 880 |
</p> |
| 881 |
<p> |
| 882 |
11) |
| 883 |
</p> |
| 884 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 885 |
<span class="inlinemediaobject"><img src="../../../equations/igamma16.svg"></span> |
| 886 |
|
| 887 |
</p></blockquote></div> |
| 888 |
<p> |
| 889 |
12) |
| 890 |
</p> |
| 891 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 892 |
<span class="inlinemediaobject"><img src="../../../equations/igamma17.svg"></span> |
| 893 |
|
| 894 |
</p></blockquote></div> |
| 895 |
<p> |
| 896 |
13) |
| 897 |
</p> |
| 898 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 899 |
<span class="inlinemediaobject"><img src="../../../equations/igamma18.svg"></span> |
| 900 |
|
| 901 |
</p></blockquote></div> |
| 902 |
<p> |
| 903 |
14) |
| 904 |
</p> |
| 905 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 906 |
<span class="inlinemediaobject"><img src="../../../equations/igamma19.svg"></span> |
| 907 |
|
| 908 |
</p></blockquote></div> |
| 909 |
<p> |
| 910 |
The double sum is truncated to a fixed number of terms - to give a specific |
| 911 |
target precision - and evaluated as a polynomial-of-polynomials. There are |
| 912 |
versions for up to 128-bit long double precision: types requiring greater |
| 913 |
precision than that do not use these expansions. The coefficients C<sub>k</sub><sup>n</sup> are |
| 914 |
computed in advance using the recurrence relations given by Temme. The zone |
| 915 |
where these expansions are used is |
| 916 |
</p> |
| 917 |
<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> |
| 918 |
</pre> |
| 919 |
<p> |
| 920 |
And: |
| 921 |
</p> |
| 922 |
<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> |
| 923 |
</pre> |
| 924 |
<p> |
| 925 |
The latter range is valid for all types up to 128-bit long doubles, and is |
| 926 |
designed to ensure that the result is larger than 10<sup>-6</sup>, the first range is |
| 927 |
used only for types up to 80-bit long doubles. These domains are narrower |
| 928 |
than the ones recommended by either Temme or Didonato and Morris. However, |
| 929 |
using a wider range results in large and inexact (i.e. computed) values being |
| 930 |
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 |
| 931 |
larger error rates. In other words there is a fine trade off here between |
| 932 |
efficiency and error. The current limits should keep the number of terms |
| 933 |
required by (4) and (5) to no more than ~20 at double precision. |
| 934 |
</p> |
| 935 |
<p> |
| 936 |
For the normalised incomplete gamma functions, calculation of the leading |
| 937 |
power terms is central to the accuracy of the function. For smallish a and |
| 938 |
x combining the power terms with the <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos |
| 939 |
approximation</a> gives the greatest accuracy: |
| 940 |
</p> |
| 941 |
<p> |
| 942 |
15) |
| 943 |
</p> |
| 944 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 945 |
<span class="inlinemediaobject"><img src="../../../equations/igamma12.svg"></span> |
| 946 |
|
| 947 |
</p></blockquote></div> |
| 948 |
<p> |
| 949 |
In the event that this causes underflow/overflow then the exponent can be |
| 950 |
reduced by a factor of <span class="emphasis"><em>a</em></span> and brought inside the power |
| 951 |
term. |
| 952 |
</p> |
| 953 |
<p> |
| 954 |
When a and x are large, we end up with a very large exponent with a base |
| 955 |
near one: this will not be computed accurately via the pow function, and |
| 956 |
taking logs simply leads to cancellation errors. The worst of the errors |
| 957 |
can be avoided by using: |
| 958 |
</p> |
| 959 |
<p> |
| 960 |
16) |
| 961 |
</p> |
| 962 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 963 |
<span class="inlinemediaobject"><img src="../../../equations/igamma13.svg"></span> |
| 964 |
|
| 965 |
</p></blockquote></div> |
| 966 |
<p> |
| 967 |
when <span class="emphasis"><em>a-x</em></span> is small and a and x are large. There is still |
| 968 |
a subtraction and therefore some cancellation errors - but the terms are |
| 969 |
small so the absolute error will be small - and it is absolute rather than |
| 970 |
relative error that counts in the argument to the <span class="emphasis"><em>exp</em></span> |
| 971 |
function. Note that for sufficiently large a and x the errors will still |
| 972 |
get you eventually, although this does delay the inevitable much longer than |
| 973 |
other methods. Use of <span class="emphasis"><em>log(1+x)-x</em></span> here is inspired by |
| 974 |
Temme (see references below). |
| 975 |
</p> |
| 976 |
<h5> |
| 977 |
<a name="math_toolkit.sf_gamma.igamma.h5"></a> |
| 978 |
<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> |
| 979 |
</h5> |
| 980 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 981 |
<li class="listitem"> |
| 982 |
N. M. Temme, A Set of Algorithms for the Incomplete Gamma Functions, |
| 983 |
Probability in the Engineering and Informational Sciences, 8, 1994. |
| 984 |
</li> |
| 985 |
<li class="listitem"> |
| 986 |
N. M. Temme, The Asymptotic Expansion of the Incomplete Gamma Functions, |
| 987 |
Siam J. Math Anal. Vol 10 No 4, July 1979, p757. |
| 988 |
</li> |
| 989 |
<li class="listitem"> |
| 990 |
A. R. Didonato and A. H. Morris, Computation of the Incomplete Gamma |
| 991 |
Function Ratios and their Inverse. ACM TOMS, Vol 12, No 4, Dec 1986, |
| 992 |
p377. |
| 993 |
</li> |
| 994 |
<li class="listitem"> |
| 995 |
W. Gautschi, The Incomplete Gamma Functions Since Tricomi, In Tricomi's |
| 996 |
Ideas and Contemporary Applied Mathematics, Atti dei Convegni Lincei, |
| 997 |
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> |
| 998 |
</li> |
| 999 |
</ul></div> |
| 1000 |
</div> |
| 1001 |
<div class="copyright-footer">Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland, |
| 1002 |
Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno |
| 1003 |
Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde, |
| 1004 |
Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle |
| 1005 |
Walker and Xiaogang Zhang<p> |
| 1006 |
Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 1007 |
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>) |
| 1008 |
</p> |
| 1009 |
</div> |
| 1010 |
<hr> |
| 1011 |
<div class="spirit-nav"> |
| 1012 |
<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> |
| 1013 |
</div> |
| 1014 |
</body> |
| 1015 |
</html> |