3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
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 2.11.0">
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">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="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>
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="math_toolkit.sf_gamma.igamma"></a><a class="link" href="igamma.html" title="Incomplete Gamma Functions">Incomplete Gamma Functions</a>
28 </h3></div></div></div>
30 <a name="math_toolkit.sf_gamma.igamma.h0"></a>
31 <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 <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 class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
37 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">></span>
38 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">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 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
41 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
43 <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>
44 <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 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
47 <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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
49 <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>
50 <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 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
53 <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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
55 <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>
56 <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 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
59 <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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
61 <span class="special">}}</span> <span class="comment">// namespaces</span>
64 <a name="math_toolkit.sf_gamma.igamma.h1"></a>
65 <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>
68 There are four <a href="http://mathworld.wolfram.com/IncompleteGammaFunction.html" target="_top">incomplete
69 gamma functions</a>: two are normalised versions (also known as <span class="emphasis"><em>regularized</em></span>
70 incomplete gamma functions) that return values in the range [0, 1], and two
71 are non-normalised and return values in the range [0, Γ(a)]. Users interested
72 in statistical applications should use the <a href="http://mathworld.wolfram.com/RegularizedGammaFunction.html" target="_top">normalised
73 versions (<code class="computeroutput"><span class="identifier">gamma_p</span></code> and <code class="computeroutput"><span class="identifier">gamma_q</span></code>)</a>.
76 All of these functions require <span class="emphasis"><em>a > 0</em></span> and <span class="emphasis"><em>z
77 >= 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>.
80 The final <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
81 be used to control the behaviour of the function: how it handles errors,
82 what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">policy
83 documentation for more details</a>.
86 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
87 type calculation rules</em></span></a> when T1 and T2 are different types,
88 otherwise the return type is simply T1.
90 <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>
91 <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 <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>
94 <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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
97 Returns the normalised lower incomplete gamma function of a and z:
99 <div class="blockquote"><blockquote class="blockquote"><p>
100 <span class="inlinemediaobject"><img src="../../../equations/igamma4.svg"></span>
102 </p></blockquote></div>
104 This function changes rapidly from 0 to 1 around the point z == a:
106 <div class="blockquote"><blockquote class="blockquote"><p>
107 <span class="inlinemediaobject"><img src="../../../graphs/gamma_p.svg" align="middle"></span>
109 </p></blockquote></div>
110 <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>
111 <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 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
114 <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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
117 Returns the normalised upper incomplete gamma function of a and z:
119 <div class="blockquote"><blockquote class="blockquote"><p>
120 <span class="inlinemediaobject"><img src="../../../equations/igamma3.svg"></span>
122 </p></blockquote></div>
124 This function changes rapidly from 1 to 0 around the point z == a:
126 <div class="blockquote"><blockquote class="blockquote"><p>
127 <span class="inlinemediaobject"><img src="../../../graphs/gamma_q.svg" align="middle"></span>
129 </p></blockquote></div>
130 <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>
131 <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 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
134 <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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
137 Returns the full (non-normalised) lower incomplete gamma function of a and
140 <div class="blockquote"><blockquote class="blockquote"><p>
141 <span class="inlinemediaobject"><img src="../../../equations/igamma2.svg"></span>
143 </p></blockquote></div>
144 <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>
145 <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 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
148 <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 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span>
151 Returns the full (non-normalised) upper incomplete gamma function of a and
154 <div class="blockquote"><blockquote class="blockquote"><p>
155 <span class="inlinemediaobject"><img src="../../../equations/igamma1.svg"></span>
157 </p></blockquote></div>
159 <a name="math_toolkit.sf_gamma.igamma.h2"></a>
160 <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>
163 The following tables give peak and mean relative errors in over various domains
164 of a and z, along with comparisons to the <a href="http://www.gnu.org/software/gsl/" target="_top">GSL-1.9</a>
165 and <a href="http://www.netlib.org/cephes/" target="_top">Cephes</a> libraries.
166 Note that only results for the widest floating-point type on the system are
167 given as narrower types have <a class="link" href="../relative_error.html#math_toolkit.relative_error.zero_error">effectively
171 Note that errors grow as <span class="emphasis"><em>a</em></span> grows larger.
174 Note also that the higher error rates for the 80 and 128 bit long double
175 results are somewhat misleading: expected results that are zero at 64-bit
176 double precision may be non-zero - but exceptionally small - with the larger
177 exponent range of a long double. These results therefore reflect the more
178 extreme nature of the tests conducted for these types.
181 All values are in units of epsilon.
184 <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>
185 <div class="table-contents"><table class="table" summary="Error rates for gamma_p">
198 GNU C++ version 7.1.0<br> linux<br> double
203 GNU C++ version 7.1.0<br> linux<br> long double
208 Sun compiler version 0x5150<br> Sun Solaris<br> long double
213 Microsoft Visual C++ version 14.1<br> Win32<br> double
221 tgamma(a, z) medium values
226 <span class="blue">Max = 0.955ε (Mean = 0.05ε)</span><br> <br>
227 (<span class="emphasis"><em>GSL 2.1:</em></span> Max = 342ε (Mean = 45.8ε))<br> (<span class="emphasis"><em>Rmath
228 3.2.3:</em></span> Max = 389ε (Mean = 44ε))
233 <span class="blue">Max = 41.6ε (Mean = 8.09ε)</span>
238 <span class="blue">Max = 239ε (Mean = 30.2ε)</span>
243 <span class="blue">Max = 35.1ε (Mean = 6.98ε)</span>
250 tgamma(a, z) small values
255 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
256 2.1:</em></span> Max = 4.82ε (Mean = 0.758ε))<br> (<span class="emphasis"><em>Rmath
257 3.2.3:</em></span> Max = 1.01ε (Mean = 0.306ε))
262 <span class="blue">Max = 2ε (Mean = 0.464ε)</span>
267 <span class="blue">Max = 2ε (Mean = 0.461ε)</span>
272 <span class="blue">Max = 1.54ε (Mean = 0.439ε)</span>
279 tgamma(a, z) large values
284 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
285 2.1:</em></span> Max = 1.02e+03ε (Mean = 105ε))<br> (<span class="emphasis"><em>Rmath
286 3.2.3:</em></span> Max = 1.11e+03ε (Mean = 67.5ε))
291 <span class="blue">Max = 3.08e+04ε (Mean = 1.86e+03ε)</span>
296 <span class="blue">Max = 3.02e+04ε (Mean = 1.91e+03ε)</span>
301 <span class="blue">Max = 243ε (Mean = 20.2ε)</span>
308 tgamma(a, z) integer and half integer values
313 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
314 2.1:</em></span> Max = 128ε (Mean = 22.6ε))<br> (<span class="emphasis"><em>Rmath
315 3.2.3:</em></span> Max = 66.2ε (Mean = 12.2ε))
320 <span class="blue">Max = 11.8ε (Mean = 2.66ε)</span>
325 <span class="blue">Max = 71.6ε (Mean = 9.47ε)</span>
330 <span class="blue">Max = 13ε (Mean = 2.97ε)</span>
337 <br class="table-break"><div class="table">
338 <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>
339 <div class="table-contents"><table class="table" summary="Error rates for gamma_q">
352 GNU C++ version 7.1.0<br> linux<br> double
357 GNU C++ version 7.1.0<br> linux<br> long double
362 Sun compiler version 0x5150<br> Sun Solaris<br> long double
367 Microsoft Visual C++ version 14.1<br> Win32<br> double
375 tgamma(a, z) medium values
380 <span class="blue">Max = 0.927ε (Mean = 0.035ε)</span><br> <br>
381 (<span class="emphasis"><em>GSL 2.1:</em></span> Max = 201ε (Mean = 13.5ε))<br> (<span class="emphasis"><em>Rmath
382 3.2.3:</em></span> Max = 131ε (Mean = 12.7ε))
387 <span class="blue">Max = 32.3ε (Mean = 6.61ε)</span>
392 <span class="blue">Max = 199ε (Mean = 26.6ε)</span>
397 <span class="blue">Max = 23.7ε (Mean = 4ε)</span>
404 tgamma(a, z) small values
409 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
410 2.1:</em></span> <span class="red">Max = 1.38e+10ε (Mean = 1.05e+09ε))</span><br>
411 (<span class="emphasis"><em>Rmath 3.2.3:</em></span> Max = 65.6ε (Mean = 11ε))
416 <span class="blue">Max = 2.45ε (Mean = 0.885ε)</span>
421 <span class="blue">Max = 2.45ε (Mean = 0.819ε)</span>
426 <span class="blue">Max = 2.26ε (Mean = 0.74ε)</span>
433 tgamma(a, z) large values
438 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
439 2.1:</em></span> Max = 2.71e+04ε (Mean = 2.16e+03ε))<br> (<span class="emphasis"><em>Rmath
440 3.2.3:</em></span> Max = 1.02e+03ε (Mean = 62.7ε))
445 <span class="blue">Max = 6.82e+03ε (Mean = 414ε)</span>
450 <span class="blue">Max = 1.15e+04ε (Mean = 733ε)</span>
455 <span class="blue">Max = 469ε (Mean = 31.5ε)</span>
462 tgamma(a, z) integer and half integer values
467 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
468 2.1:</em></span> Max = 118ε (Mean = 12.5ε))<br> (<span class="emphasis"><em>Rmath
469 3.2.3:</em></span> Max = 138ε (Mean = 16.9ε))
474 <span class="blue">Max = 11.1ε (Mean = 2.07ε)</span>
479 <span class="blue">Max = 54.7ε (Mean = 6.16ε)</span>
484 <span class="blue">Max = 8.72ε (Mean = 1.48ε)</span>
491 <br class="table-break"><div class="table">
492 <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>
493 <div class="table-contents"><table class="table" summary="Error rates for tgamma_lower">
506 GNU C++ version 7.1.0<br> linux<br> double
511 GNU C++ version 7.1.0<br> linux<br> long double
516 Sun compiler version 0x5150<br> Sun Solaris<br> long double
521 Microsoft Visual C++ version 14.1<br> Win32<br> double
529 tgamma(a, z) medium values
534 <span class="blue">Max = 0.833ε (Mean = 0.0315ε)</span><br>
535 <br> (<span class="emphasis"><em>GSL 2.1:</em></span> Max = 0.833ε (Mean = 0.0315ε))
540 <span class="blue">Max = 6.79ε (Mean = 1.46ε)</span>
545 <span class="blue">Max = 363ε (Mean = 63.8ε)</span>
550 <span class="blue">Max = 5.62ε (Mean = 1.49ε)</span>
557 tgamma(a, z) small values
562 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
563 2.1:</em></span> Max = 0ε (Mean = 0ε))
568 <span class="blue">Max = 1.97ε (Mean = 0.555ε)</span>
573 <span class="blue">Max = 1.97ε (Mean = 0.558ε)</span>
578 <span class="blue">Max = 1.57ε (Mean = 0.525ε)</span>
585 tgamma(a, z) integer and half integer values
590 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
591 2.1:</em></span> Max = 0ε (Mean = 0ε))
596 <span class="blue">Max = 4.83ε (Mean = 1.15ε)</span>
601 <span class="blue">Max = 84.7ε (Mean = 17.5ε)</span>
606 <span class="blue">Max = 2.69ε (Mean = 0.849ε)</span>
613 <br class="table-break"><div class="table">
614 <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>
615 <div class="table-contents"><table class="table" summary="Error rates for tgamma (incomplete)">
628 GNU C++ version 7.1.0<br> linux<br> double
633 GNU C++ version 7.1.0<br> linux<br> long double
638 Sun compiler version 0x5150<br> Sun Solaris<br> long double
643 Microsoft Visual C++ version 14.1<br> Win32<br> double
651 tgamma(a, z) medium values
656 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
657 2.1:</em></span> Max = 200ε (Mean = 13.3ε))
662 <span class="blue">Max = 8.47ε (Mean = 1.9ε)</span>
667 <span class="blue">Max = 412ε (Mean = 95.5ε)</span>
672 <span class="blue">Max = 8.14ε (Mean = 1.76ε)</span>
679 tgamma(a, z) small values
684 <span class="blue">Max = 0.753ε (Mean = 0.0474ε)</span><br>
685 <br> (<span class="emphasis"><em>GSL 2.1:</em></span> <span class="red">Max =
686 1.38e+10ε (Mean = 1.05e+09ε))</span>
691 <span class="blue">Max = 2.31ε (Mean = 0.775ε)</span>
696 <span class="blue">Max = 2.13ε (Mean = 0.717ε)</span>
701 <span class="blue">Max = 2.53ε (Mean = 0.66ε)</span>
708 tgamma(a, z) integer and half integer values
713 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
714 2.1:</em></span> Max = 117ε (Mean = 12.5ε))
719 <span class="blue">Max = 5.52ε (Mean = 1.48ε)</span>
724 <span class="blue">Max = 79.6ε (Mean = 20.9ε)</span>
729 <span class="blue">Max = 5.16ε (Mean = 1.33ε)</span>
736 <br class="table-break"><h5>
737 <a name="math_toolkit.sf_gamma.igamma.h3"></a>
738 <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>
741 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>
742 with this implementation to perform a basic "sanity check". Accuracy
743 tests use data generated at very high precision (using NTL's RR class set
744 at 1000-bit precision) using this implementation with a very high precision
745 60-term <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos approximation</a>,
746 and some but not all of the special case handling disabled. This is less
747 than satisfactory: an independent method should really be used, but apparently
748 a complete lack of such methods are available. We can't even use a deliberately
749 naive implementation without special case handling since Legendre's continued
750 fraction (see below) is unstable for small a and z.
753 <a name="math_toolkit.sf_gamma.igamma.h4"></a>
754 <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>
757 These four functions share a common implementation since they are all related
763 <div class="blockquote"><blockquote class="blockquote"><p>
764 <span class="inlinemediaobject"><img src="../../../equations/igamma5.svg"></span>
766 </p></blockquote></div>
770 <div class="blockquote"><blockquote class="blockquote"><p>
771 <span class="inlinemediaobject"><img src="../../../equations/igamma6.svg"></span>
773 </p></blockquote></div>
777 <div class="blockquote"><blockquote class="blockquote"><p>
778 <span class="inlinemediaobject"><img src="../../../equations/igamma7.svg"></span>
780 </p></blockquote></div>
782 The lower incomplete gamma is computed from its series representation:
787 <div class="blockquote"><blockquote class="blockquote"><p>
788 <span class="inlinemediaobject"><img src="../../../equations/igamma8.svg"></span>
790 </p></blockquote></div>
792 Or by subtraction of the upper integral from either Γ(a) or 1 when <span class="emphasis"><em>x
793 - (1</em></span>(3x)) > a and x > 1.1/.
796 The upper integral is computed from Legendre's continued fraction representation:
801 <div class="blockquote"><blockquote class="blockquote"><p>
802 <span class="inlinemediaobject"><img src="../../../equations/igamma9.svg"></span>
804 </p></blockquote></div>
806 When <span class="emphasis"><em>(x > 1.1)</em></span> or by subtraction of the lower integral
807 from either Γ(a) or 1 when <span class="emphasis"><em>x - (1</em></span>(3x)) < a/.
810 For <span class="emphasis"><em>x < 1.1</em></span> computation of the upper integral is
811 more complex as the continued fraction representation is unstable in this
812 area. However there is another series representation for the lower integral:
817 <div class="blockquote"><blockquote class="blockquote"><p>
818 <span class="inlinemediaobject"><img src="../../../equations/igamma10.svg"></span>
820 </p></blockquote></div>
822 That lends itself to calculation of the upper integral via rearrangement
828 <div class="blockquote"><blockquote class="blockquote"><p>
829 <span class="inlinemediaobject"><img src="../../../equations/igamma11.svg"></span>
831 </p></blockquote></div>
833 Refer to the documentation for <a class="link" href="../powers/powm1.html" title="powm1">powm1</a>
834 and <a class="link" href="tgamma.html" title="Gamma">tgamma1pm1</a> for details
835 of their implementation.
838 For <span class="emphasis"><em>x < 1.1</em></span> the crossover point where the result
839 is ~0.5 no longer occurs for <span class="emphasis"><em>x ~ y</em></span>. Using <span class="emphasis"><em>x
840 * 0.75 < a</em></span> as the crossover criterion for <span class="emphasis"><em>0.5 <
841 x <= 1.1</em></span> keeps the maximum value computed (whether it's the
842 upper or lower interval) to around 0.75. Likewise for <span class="emphasis"><em>x <= 0.5</em></span>
843 then using <span class="emphasis"><em>-0.4 / log(x) < a</em></span> as the crossover criterion
844 keeps the maximum value computed to around 0.7 (whether it's the upper or
848 There are two special cases used when a is an integer or half integer, and
849 the crossover conditions listed above indicate that we should compute the
850 upper integral Q. If a is an integer in the range <span class="emphasis"><em>1 <= a <
851 30</em></span> then the following finite sum is used:
856 <div class="blockquote"><blockquote class="blockquote"><p>
857 <span class="inlinemediaobject"><img src="../../../equations/igamma1f.svg"></span>
859 </p></blockquote></div>
861 While for half-integers in the range <span class="emphasis"><em>0.5 <= a < 30</em></span>
862 then the following finite sum is used:
867 <div class="blockquote"><blockquote class="blockquote"><p>
868 <span class="inlinemediaobject"><img src="../../../equations/igamma2f.svg"></span>
870 </p></blockquote></div>
872 These are both more stable and more efficient than the continued fraction
876 When the argument <span class="emphasis"><em>a</em></span> is large, and <span class="emphasis"><em>x ~ a</em></span>
877 then the series (4) and continued fraction (5) above are very slow to converge.
878 In this area an expansion due to Temme is used:
883 <div class="blockquote"><blockquote class="blockquote"><p>
884 <span class="inlinemediaobject"><img src="../../../equations/igamma16.svg"></span>
886 </p></blockquote></div>
890 <div class="blockquote"><blockquote class="blockquote"><p>
891 <span class="inlinemediaobject"><img src="../../../equations/igamma17.svg"></span>
893 </p></blockquote></div>
897 <div class="blockquote"><blockquote class="blockquote"><p>
898 <span class="inlinemediaobject"><img src="../../../equations/igamma18.svg"></span>
900 </p></blockquote></div>
904 <div class="blockquote"><blockquote class="blockquote"><p>
905 <span class="inlinemediaobject"><img src="../../../equations/igamma19.svg"></span>
907 </p></blockquote></div>
909 The double sum is truncated to a fixed number of terms - to give a specific
910 target precision - and evaluated as a polynomial-of-polynomials. There are
911 versions for up to 128-bit long double precision: types requiring greater
912 precision than that do not use these expansions. The coefficients C<sub>k</sub><sup>n</sup> are
913 computed in advance using the recurrence relations given by Temme. The zone
914 where these expansions are used is
916 <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>
921 <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>
924 The latter range is valid for all types up to 128-bit long doubles, and is
925 designed to ensure that the result is larger than 10<sup>-6</sup>, the first range is
926 used only for types up to 80-bit long doubles. These domains are narrower
927 than the ones recommended by either Temme or Didonato and Morris. However,
928 using a wider range results in large and inexact (i.e. computed) values being
929 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
930 larger error rates. In other words there is a fine trade off here between
931 efficiency and error. The current limits should keep the number of terms
932 required by (4) and (5) to no more than ~20 at double precision.
935 For the normalised incomplete gamma functions, calculation of the leading
936 power terms is central to the accuracy of the function. For smallish a and
937 x combining the power terms with the <a class="link" href="../lanczos.html" title="The Lanczos Approximation">Lanczos
938 approximation</a> gives the greatest accuracy:
943 <div class="blockquote"><blockquote class="blockquote"><p>
944 <span class="inlinemediaobject"><img src="../../../equations/igamma12.svg"></span>
946 </p></blockquote></div>
948 In the event that this causes underflow/overflow then the exponent can be
949 reduced by a factor of <span class="emphasis"><em>a</em></span> and brought inside the power
953 When a and x are large, we end up with a very large exponent with a base
954 near one: this will not be computed accurately via the pow function, and
955 taking logs simply leads to cancellation errors. The worst of the errors
956 can be avoided by using:
961 <div class="blockquote"><blockquote class="blockquote"><p>
962 <span class="inlinemediaobject"><img src="../../../equations/igamma13.svg"></span>
964 </p></blockquote></div>
966 when <span class="emphasis"><em>a-x</em></span> is small and a and x are large. There is still
967 a subtraction and therefore some cancellation errors - but the terms are
968 small so the absolute error will be small - and it is absolute rather than
969 relative error that counts in the argument to the <span class="emphasis"><em>exp</em></span>
970 function. Note that for sufficiently large a and x the errors will still
971 get you eventually, although this does delay the inevitable much longer than
972 other methods. Use of <span class="emphasis"><em>log(1+x)-x</em></span> here is inspired by
973 Temme (see references below).
976 <a name="math_toolkit.sf_gamma.igamma.h5"></a>
977 <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 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
980 <li class="listitem">
981 N. M. Temme, A Set of Algorithms for the Incomplete Gamma Functions,
982 Probability in the Engineering and Informational Sciences, 8, 1994.
984 <li class="listitem">
985 N. M. Temme, The Asymptotic Expansion of the Incomplete Gamma Functions,
986 Siam J. Math Anal. Vol 10 No 4, July 1979, p757.
988 <li class="listitem">
989 A. R. Didonato and A. H. Morris, Computation of the Incomplete Gamma
990 Function Ratios and their Inverse. ACM TOMS, Vol 12, No 4, Dec 1986,
993 <li class="listitem">
994 W. Gautschi, The Incomplete Gamma Functions Since Tricomi, In Tricomi's
995 Ideas and Contemporary Applied Mathematics, Atti dei Convegni Lincei,
996 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>
1000 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
1001 <td align="left"></td>
1002 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
1003 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
1004 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
1005 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
1006 Daryle Walker and Xiaogang Zhang<p>
1007 Distributed under the Boost Software License, Version 1.0. (See accompanying
1008 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>)
1013 <div class="spirit-nav">
1014 <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>