1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Ratios of 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.12.0"> 8<link rel="up" href="../sf_gamma.html" title="Gamma Functions"> 9<link rel="prev" href="polygamma.html" title="Polygamma"> 10<link rel="next" href="igamma.html" title="Incomplete Gamma Functions"> 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="polygamma.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.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.gamma_ratios"></a><a class="link" href="gamma_ratios.html" title="Ratios of Gamma Functions">Ratios of Gamma Functions</a> 28</h3></div></div></div> 29<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> 30</pre> 31<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> 32 33<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> 34<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_ratio</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">b</span><span class="special">);</span> 35 36<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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> 37<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_ratio</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">b</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> 38 39<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> 40<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_delta_ratio</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">delta</span><span class="special">);</span> 41 42<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> 43<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_delta_ratio</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">delta</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> 44 45<span class="special">}}</span> <span class="comment">// namespaces</span> 46</pre> 47<h5> 48<a name="math_toolkit.sf_gamma.gamma_ratios.h0"></a> 49 <span class="phrase"><a name="math_toolkit.sf_gamma.gamma_ratios.description"></a></span><a class="link" href="gamma_ratios.html#math_toolkit.sf_gamma.gamma_ratios.description">Description</a> 50 </h5> 51<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> 52<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_ratio</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">b</span><span class="special">);</span> 53 54<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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> 55<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_ratio</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">b</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> 56</pre> 57<p> 58 Returns the ratio of gamma functions: 59 </p> 60<div class="blockquote"><blockquote class="blockquote"><p> 61 <span class="inlinemediaobject"><img src="../../../equations/gamma_ratio0.svg"></span> 62 63 </p></blockquote></div> 64<p> 65 The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can 66 be used to control the behaviour of the function: how it handles errors, 67 what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy 68 documentation for more details</a>. 69 </p> 70<p> 71 Internally this just calls <code class="computeroutput"><span class="identifier">tgamma_delta_ratio</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span> 72 <span class="identifier">b</span><span class="special">-</span><span class="identifier">a</span><span class="special">)</span></code>. 73 </p> 74<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> 75<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_delta_ratio</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">delta</span><span class="special">);</span> 76 77<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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> 78<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_delta_ratio</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">delta</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> 79</pre> 80<p> 81 Returns the ratio of gamma functions: 82 </p> 83<div class="blockquote"><blockquote class="blockquote"><p> 84 <span class="inlinemediaobject"><img src="../../../equations/gamma_ratio1.svg"></span> 85 86 </p></blockquote></div> 87<p> 88 The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can 89 be used to control the behaviour of the function: how it handles errors, 90 what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy 91 documentation for more details</a>. 92 </p> 93<p> 94 Note that the result is calculated accurately even when <span class="emphasis"><em>delta</em></span> 95 is small compared to <span class="emphasis"><em>a</em></span>: indeed even if <span class="emphasis"><em>a+delta 96 ~ a</em></span>. The function is typically used when <span class="emphasis"><em>a</em></span> 97 is large and <span class="emphasis"><em>delta</em></span> is very small. 98 </p> 99<p> 100 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 101 type calculation rules</em></span></a> when T1 and T2 are different types, 102 otherwise the result type is simple T1. 103 </p> 104<div class="blockquote"><blockquote class="blockquote"><p> 105 <span class="inlinemediaobject"><img src="../../../graphs/tgamma_delta_ratio.svg" align="middle"></span> 106 107 </p></blockquote></div> 108<h5> 109<a name="math_toolkit.sf_gamma.gamma_ratios.h1"></a> 110 <span class="phrase"><a name="math_toolkit.sf_gamma.gamma_ratios.accuracy"></a></span><a class="link" href="gamma_ratios.html#math_toolkit.sf_gamma.gamma_ratios.accuracy">Accuracy</a> 111 </h5> 112<p> 113 The following table shows the peak errors (in units of epsilon) found on 114 various platforms with various floating point types. Unless otherwise specified 115 any floating point type that is narrower than the one shown will have <a class="link" href="../relative_error.html#math_toolkit.relative_error.zero_error">effectively zero error</a>. 116 </p> 117<div class="table"> 118<a name="math_toolkit.sf_gamma.gamma_ratios.table_tgamma_delta_ratio"></a><p class="title"><b>Table 8.7. Error rates for tgamma_delta_ratio</b></p> 119<div class="table-contents"><table class="table" summary="Error rates for tgamma_delta_ratio"> 120<colgroup> 121<col> 122<col> 123<col> 124<col> 125<col> 126</colgroup> 127<thead><tr> 128<th> 129 </th> 130<th> 131 <p> 132 GNU C++ version 7.1.0<br> linux<br> double 133 </p> 134 </th> 135<th> 136 <p> 137 GNU C++ version 7.1.0<br> linux<br> long double 138 </p> 139 </th> 140<th> 141 <p> 142 Sun compiler version 0x5150<br> Sun Solaris<br> long double 143 </p> 144 </th> 145<th> 146 <p> 147 Microsoft Visual C++ version 14.1<br> Win32<br> double 148 </p> 149 </th> 150</tr></thead> 151<tbody> 152<tr> 153<td> 154 <p> 155 tgamma + small delta ratios 156 </p> 157 </td> 158<td> 159 <p> 160 <span class="blue">Max = 0ε (Mean = 0ε)</span> 161 </p> 162 </td> 163<td> 164 <p> 165 <span class="blue">Max = 5.83ε (Mean = 1.3ε)</span> 166 </p> 167 </td> 168<td> 169 <p> 170 <span class="blue">Max = 15.4ε (Mean = 2.09ε)</span> 171 </p> 172 </td> 173<td> 174 <p> 175 <span class="blue">Max = 7.56ε (Mean = 1.31ε)</span> 176 </p> 177 </td> 178</tr> 179<tr> 180<td> 181 <p> 182 tgamma + small delta ratios (negative delta) 183 </p> 184 </td> 185<td> 186 <p> 187 <span class="blue">Max = 0ε (Mean = 0ε)</span> 188 </p> 189 </td> 190<td> 191 <p> 192 <span class="blue">Max = 7.94ε (Mean = 1.4ε)</span> 193 </p> 194 </td> 195<td> 196 <p> 197 <span class="blue">Max = 18.3ε (Mean = 2.03ε)</span> 198 </p> 199 </td> 200<td> 201 <p> 202 <span class="blue">Max = 7.43ε (Mean = 1.42ε)</span> 203 </p> 204 </td> 205</tr> 206<tr> 207<td> 208 <p> 209 tgamma + small integer ratios 210 </p> 211 </td> 212<td> 213 <p> 214 <span class="blue">Max = 0ε (Mean = 0ε)</span> 215 </p> 216 </td> 217<td> 218 <p> 219 <span class="blue">Max = 1.96ε (Mean = 0.677ε)</span> 220 </p> 221 </td> 222<td> 223 <p> 224 <span class="blue">Max = 1.96ε (Mean = 0.677ε)</span> 225 </p> 226 </td> 227<td> 228 <p> 229 <span class="blue">Max = 2.74ε (Mean = 0.736ε)</span> 230 </p> 231 </td> 232</tr> 233<tr> 234<td> 235 <p> 236 tgamma + small integer ratios (negative delta) 237 </p> 238 </td> 239<td> 240 <p> 241 <span class="blue">Max = 0ε (Mean = 0ε)</span> 242 </p> 243 </td> 244<td> 245 <p> 246 <span class="blue">Max = 1.62ε (Mean = 0.451ε)</span> 247 </p> 248 </td> 249<td> 250 <p> 251 <span class="blue">Max = 1.62ε (Mean = 0.451ε)</span> 252 </p> 253 </td> 254<td> 255 <p> 256 <span class="blue">Max = 2.15ε (Mean = 0.685ε)</span> 257 </p> 258 </td> 259</tr> 260<tr> 261<td> 262 <p> 263 integer tgamma ratios 264 </p> 265 </td> 266<td> 267 <p> 268 <span class="blue">Max = 0ε (Mean = 0ε)</span> 269 </p> 270 </td> 271<td> 272 <p> 273 <span class="blue">Max = 0.997ε (Mean = 0.4ε)</span> 274 </p> 275 </td> 276<td> 277 <p> 278 <span class="blue">Max = 0.997ε (Mean = 0.4ε)</span> 279 </p> 280 </td> 281<td> 282 <p> 283 <span class="blue">Max = 0.968ε (Mean = 0.386ε)</span> 284 </p> 285 </td> 286</tr> 287<tr> 288<td> 289 <p> 290 integer tgamma ratios (negative delta) 291 </p> 292 </td> 293<td> 294 <p> 295 <span class="blue">Max = 0ε (Mean = 0ε)</span> 296 </p> 297 </td> 298<td> 299 <p> 300 <span class="blue">Max = 0.853ε (Mean = 0.176ε)</span> 301 </p> 302 </td> 303<td> 304 <p> 305 <span class="blue">Max = 0.853ε (Mean = 0.176ε)</span> 306 </p> 307 </td> 308<td> 309 <p> 310 <span class="blue">Max = 0.974ε (Mean = 0.175ε)</span> 311 </p> 312 </td> 313</tr> 314</tbody> 315</table></div> 316</div> 317<br class="table-break"><div class="table"> 318<a name="math_toolkit.sf_gamma.gamma_ratios.table_tgamma_ratio"></a><p class="title"><b>Table 8.8. Error rates for tgamma_ratio</b></p> 319<div class="table-contents"><table class="table" summary="Error rates for tgamma_ratio"> 320<colgroup> 321<col> 322<col> 323<col> 324<col> 325<col> 326</colgroup> 327<thead><tr> 328<th> 329 </th> 330<th> 331 <p> 332 GNU C++ version 7.1.0<br> linux<br> double 333 </p> 334 </th> 335<th> 336 <p> 337 GNU C++ version 7.1.0<br> linux<br> long double 338 </p> 339 </th> 340<th> 341 <p> 342 Sun compiler version 0x5150<br> Sun Solaris<br> long double 343 </p> 344 </th> 345<th> 346 <p> 347 Microsoft Visual C++ version 14.1<br> Win32<br> double 348 </p> 349 </th> 350</tr></thead> 351<tbody><tr> 352<td> 353 <p> 354 tgamma ratios 355 </p> 356 </td> 357<td> 358 <p> 359 <span class="blue">Max = 0.694ε (Mean = 0.0347ε)</span> 360 </p> 361 </td> 362<td> 363 <p> 364 <span class="blue">Max = 2.99ε (Mean = 1.15ε)</span> 365 </p> 366 </td> 367<td> 368 <p> 369 <span class="blue">Max = 174ε (Mean = 61.2ε)</span> 370 </p> 371 </td> 372<td> 373 <p> 374 <span class="blue">Max = 3.28ε (Mean = 1.12ε)</span> 375 </p> 376 </td> 377</tr></tbody> 378</table></div> 379</div> 380<br class="table-break"><h5> 381<a name="math_toolkit.sf_gamma.gamma_ratios.h2"></a> 382 <span class="phrase"><a name="math_toolkit.sf_gamma.gamma_ratios.testing"></a></span><a class="link" href="gamma_ratios.html#math_toolkit.sf_gamma.gamma_ratios.testing">Testing</a> 383 </h5> 384<p> 385 Accuracy tests use data generated at very high precision (with <a href="http://shoup.net/ntl/doc/RR.txt" target="_top">NTL 386 RR class</a> set at 1000-bit precision: about 300 decimal digits) and 387 a deliberately naive calculation of Γ(x)/Γ(y). 388 </p> 389<h5> 390<a name="math_toolkit.sf_gamma.gamma_ratios.h3"></a> 391 <span class="phrase"><a name="math_toolkit.sf_gamma.gamma_ratios.implementation"></a></span><a class="link" href="gamma_ratios.html#math_toolkit.sf_gamma.gamma_ratios.implementation">Implementation</a> 392 </h5> 393<p> 394 The implementation of these functions is very similar to that of <a class="link" href="../sf_beta/beta_function.html" title="Beta">beta</a>, 395 and is based on combining similar power terms to improve accuracy and avoid 396 spurious overflow/underflow. 397 </p> 398<p> 399 In addition there are optimisations for the situation where <span class="emphasis"><em>delta</em></span> 400 is a small integer: in which case this function is basically the reciprocal 401 of a rising factorial, or where both arguments are smallish integers: in 402 which case table lookup of factorials can be used to calculate the ratio. 403 </p> 404</div> 405<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 406<td align="left"></td> 407<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 408 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 409 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 410 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 411 Daryle Walker and Xiaogang Zhang<p> 412 Distributed under the Boost Software License, Version 1.0. (See accompanying 413 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>) 414 </p> 415</div></td> 416</tr></table> 417<hr> 418<div class="spirit-nav"> 419<a accesskey="p" href="polygamma.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.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 420</div> 421</body> 422</html> 423