3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Polygamma</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="trigamma.html" title="Trigamma">
10 <link rel="next" href="gamma_ratios.html" title="Ratios of Gamma Functions">
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="trigamma.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="gamma_ratios.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.polygamma"></a><a class="link" href="polygamma.html" title="Polygamma">Polygamma</a>
28 </h3></div></div></div>
30 <a name="math_toolkit.sf_gamma.polygamma.h0"></a>
31 <span class="phrase"><a name="math_toolkit.sf_gamma.polygamma.synopsis"></a></span><a class="link" href="polygamma.html#math_toolkit.sf_gamma.polygamma.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">polygamma</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">T</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">polygamma</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">T</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">T</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">polygamma</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">T</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="special">}}</span> <span class="comment">// namespaces</span>
46 <a name="math_toolkit.sf_gamma.polygamma.h1"></a>
47 <span class="phrase"><a name="math_toolkit.sf_gamma.polygamma.description"></a></span><a class="link" href="polygamma.html#math_toolkit.sf_gamma.polygamma.description">Description</a>
50 Returns the polygamma function of <span class="emphasis"><em>x</em></span>. Polygamma is defined
51 as the n'th derivative of the digamma function:
53 <div class="blockquote"><blockquote class="blockquote"><p>
54 <span class="inlinemediaobject"><img src="../../../equations/polygamma1.svg"></span>
56 </p></blockquote></div>
58 The following graphs illustrate the behaviour of the function for odd and
61 <div class="blockquote"><blockquote class="blockquote"><p>
62 <span class="inlinemediaobject"><img src="../../../graphs/polygamma2.svg" align="middle"></span>
64 </p></blockquote></div>
65 <div class="blockquote"><blockquote class="blockquote"><p>
66 <span class="inlinemediaobject"><img src="../../../graphs/polygamma3.svg" align="middle"></span>
68 </p></blockquote></div>
70 The final <a class="link" href="../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
71 be used to control the behaviour of the function: how it handles errors,
72 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
73 documentation for more details</a>.
76 The return type of this function is computed using the <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>result
77 type calculation rules</em></span></a>: the result is of type <code class="computeroutput"><span class="keyword">double</span></code> when T is an integer type, and type
81 <a name="math_toolkit.sf_gamma.polygamma.h2"></a>
82 <span class="phrase"><a name="math_toolkit.sf_gamma.polygamma.accuracy"></a></span><a class="link" href="polygamma.html#math_toolkit.sf_gamma.polygamma.accuracy">Accuracy</a>
85 The following table shows the peak errors (in units of epsilon) found on
86 various platforms with various floating point types. Unless otherwise specified
87 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>.
90 <a name="math_toolkit.sf_gamma.polygamma.table_polygamma"></a><p class="title"><b>Table 8.6. Error rates for polygamma</b></p>
91 <div class="table-contents"><table class="table" summary="Error rates for polygamma">
104 GNU C++ version 7.1.0<br> linux<br> double
109 GNU C++ version 7.1.0<br> linux<br> long double
114 Sun compiler version 0x5150<br> Sun Solaris<br> long double
119 Microsoft Visual C++ version 14.1<br> Win32<br> double
132 <span class="blue">Max = 0.824ε (Mean = 0.0574ε)</span><br>
133 <br> (<span class="emphasis"><em>GSL 2.1:</em></span> Max = 62.9ε (Mean = 12.8ε))<br>
134 (<span class="emphasis"><em>Rmath 3.2.3:</em></span> Max = 108ε (Mean = 15.2ε))
139 <span class="blue">Max = 7.38ε (Mean = 1.84ε)</span>
144 <span class="blue">Max = 34.3ε (Mean = 7.65ε)</span>
149 <span class="blue">Max = 9.32ε (Mean = 1.95ε)</span>
156 Mathematica Data - large arguments
161 <span class="blue">Max = 0.998ε (Mean = 0.0592ε)</span><br>
162 <br> (<span class="emphasis"><em>GSL 2.1:</em></span> Max = 244ε (Mean = 32.8ε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_polygamma_GSL_2_1_Mathematica_Data_large_arguments">And
163 other failures.</a>)<br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span>
164 <span class="red">Max = 1.71e+56ε (Mean = 1.01e+55ε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_polygamma_Rmath_3_2_3_Mathematica_Data_large_arguments">And
165 other failures.</a>)</span>
170 <span class="blue">Max = 2.23ε (Mean = 0.323ε)</span>
175 <span class="blue">Max = 11.1ε (Mean = 0.848ε)</span>
180 <span class="blue">Max = 150ε (Mean = 13.9ε)</span>
187 Mathematica Data - negative arguments
192 <span class="blue">Max = 0.516ε (Mean = 0.022ε)</span><br> <br>
193 (<span class="emphasis"><em>GSL 2.1:</em></span> Max = 36.6ε (Mean = 3.04ε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_polygamma_GSL_2_1_Mathematica_Data_negative_arguments">And
194 other failures.</a>)<br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span>
195 Max = 0ε (Mean = 0ε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_polygamma_Rmath_3_2_3_Mathematica_Data_negative_arguments">And
201 <span class="blue">Max = 269ε (Mean = 87.7ε)</span>
206 <span class="blue">Max = 269ε (Mean = 88.4ε)</span>
211 <span class="blue">Max = 497ε (Mean = 129ε)</span>
218 Mathematica Data - large negative arguments
223 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
224 2.1:</em></span> Max = 1.79ε (Mean = 0.197ε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_polygamma_GSL_2_1_Mathematica_Data_large_negative_arguments">And
225 other failures.</a>)<br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span>
226 Max = 0ε (Mean = 0ε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_polygamma_Rmath_3_2_3_Mathematica_Data_large_negative_arguments">And
232 <span class="blue">Max = 155ε (Mean = 96.4ε)</span>
237 <span class="blue">Max = 155ε (Mean = 96.4ε)</span>
242 <span class="blue">Max = 162ε (Mean = 101ε)</span>
249 Mathematica Data - small arguments
254 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
255 2.1:</em></span> Max = 15.2ε (Mean = 5.03ε))<br> (<span class="emphasis"><em>Rmath
256 3.2.3:</em></span> Max = 106ε (Mean = 20ε))
261 <span class="blue">Max = 3.33ε (Mean = 0.75ε)</span>
266 <span class="blue">Max = 3.33ε (Mean = 0.75ε)</span>
271 <span class="blue">Max = 3ε (Mean = 0.496ε)</span>
278 Mathematica Data - Large orders and other bug cases
283 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL
284 2.1:</em></span> Max = 151ε (Mean = 39.3ε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_polygamma_GSL_2_1_Mathematica_Data_Large_orders_and_other_bug_cases">And
285 other failures.</a>)<br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span>
286 <span class="red">Max = +INFε (Mean = +INFε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_polygamma_Rmath_3_2_3_Mathematica_Data_Large_orders_and_other_bug_cases">And
287 other failures.</a>)</span>
292 <span class="blue">Max = 54.5ε (Mean = 13.3ε)</span>
297 <span class="blue">Max = 145ε (Mean = 55.9ε)</span>
302 <span class="blue">Max = 200ε (Mean = 57.2ε)</span>
309 <br class="table-break"><p>
310 As shown above, error rates are generally very acceptable for moderately
311 sized arguments. Error rates should stay low for exact inputs, however, please
312 note that the function becomes exceptionally sensitive to small changes in
313 input for large n and negative x, indeed for cases where <span class="emphasis"><em>n!</em></span>
314 would overflow, the function changes directly from -∞ to +∞ somewhere between
315 each negative integer - <span class="emphasis"><em>these cases are not handled correctly</em></span>.
318 <span class="bold"><strong>For these reasons results should be treated with extreme
319 caution when <span class="emphasis"><em>n</em></span> is large and x negative</strong></span>.
322 <a name="math_toolkit.sf_gamma.polygamma.h3"></a>
323 <span class="phrase"><a name="math_toolkit.sf_gamma.polygamma.testing"></a></span><a class="link" href="polygamma.html#math_toolkit.sf_gamma.polygamma.testing">Testing</a>
326 Testing is against Mathematica generated spot values to 35 digit precision.
329 <a name="math_toolkit.sf_gamma.polygamma.h4"></a>
330 <span class="phrase"><a name="math_toolkit.sf_gamma.polygamma.implementation"></a></span><a class="link" href="polygamma.html#math_toolkit.sf_gamma.polygamma.implementation">Implementation</a>
333 For x < 0 the following reflection formula is used:
335 <div class="blockquote"><blockquote class="blockquote"><p>
336 <span class="inlinemediaobject"><img src="../../../equations/polygamma2.svg"></span>
338 </p></blockquote></div>
340 The n'th derivative of <span class="emphasis"><em>cot(x)</em></span> is tabulated for small
341 <span class="emphasis"><em>n</em></span>, and for larger n has the general form:
343 <div class="blockquote"><blockquote class="blockquote"><p>
344 <span class="inlinemediaobject"><img src="../../../equations/polygamma3.svg"></span>
346 </p></blockquote></div>
348 The coefficients of the cosine terms can be calculated iteratively starting
349 from <span class="emphasis"><em>C<sub>1,0</sub> = -1</em></span> and then using
351 <div class="blockquote"><blockquote class="blockquote"><p>
352 <span class="inlinemediaobject"><img src="../../../equations/polygamma7.svg"></span>
354 </p></blockquote></div>
356 to generate coefficients for n+1.
359 Note that every other coefficient is zero, and therefore what we have are
360 even or odd polynomials depending on whether n is even or odd.
363 Once x is positive then we have two methods available to us, for small x
364 we use the series expansion:
366 <div class="blockquote"><blockquote class="blockquote"><p>
367 <span class="inlinemediaobject"><img src="../../../equations/polygamma4.svg"></span>
369 </p></blockquote></div>
371 Note that the evaluation of zeta functions at integer values is essentially
372 a table lookup as <a class="link" href="../zetas/zeta.html" title="Riemann Zeta Function">zeta</a> is
373 optimized for those cases.
376 For large x we use the asymptotic expansion:
378 <div class="blockquote"><blockquote class="blockquote"><p>
379 <span class="inlinemediaobject"><img src="../../../equations/polygamma5.svg"></span>
381 </p></blockquote></div>
383 For x in-between the two extremes we use the relation:
385 <div class="blockquote"><blockquote class="blockquote"><p>
386 <span class="inlinemediaobject"><img src="../../../equations/polygamma6.svg"></span>
388 </p></blockquote></div>
390 to make x large enough for the asymptotic expansion to be used.
393 There are also two special cases:
395 <div class="blockquote"><blockquote class="blockquote"><p>
396 <span class="inlinemediaobject"><img src="../../../equations/polygamma8.svg"></span>
398 </p></blockquote></div>
399 <div class="blockquote"><blockquote class="blockquote"><p>
400 <span class="inlinemediaobject"><img src="../../../equations/polygamma9.svg"></span>
402 </p></blockquote></div>
404 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
405 <td align="left"></td>
406 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
407 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
408 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
409 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
410 Daryle Walker and Xiaogang Zhang<p>
411 Distributed under the Boost Software License, Version 1.0. (See accompanying
412 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>)
417 <div class="spirit-nav">
418 <a accesskey="p" href="trigamma.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="gamma_ratios.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>