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