blob: de35264032712ba8b6d2db16ef266c7f9ef05b06 [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Polygamma</title>
<link rel="stylesheet" href="../../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
<link rel="home" href="../../index.html" title="Math Toolkit 2.2.0">
<link rel="up" href="../sf_gamma.html" title="Gamma Functions">
<link rel="prev" href="trigamma.html" title="Trigamma">
<link rel="next" href="gamma_ratios.html" title="Ratios of Gamma Functions">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="math_toolkit.sf_gamma.polygamma"></a><a class="link" href="polygamma.html" title="Polygamma">Polygamma</a>
</h3></div></div></div>
<h5>
<a name="math_toolkit.sf_gamma.polygamma.h0"></a>
<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>
</h5>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</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">&gt;</span>
</pre>
<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>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<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">template</span> <span class="special">&lt;</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&#160;14.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<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&#160;14.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<h5>
<a name="math_toolkit.sf_gamma.polygamma.h1"></a>
<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>
</h5>
<p>
Returns the polygamma function of <span class="emphasis"><em>x</em></span>. Polygamma is defined
as the n'th derivative of the digamma function:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../equations/polygamma1.svg"></span>
</p>
<p>
The following graphs illustrate the behaviour of the function for odd and
even order:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../graphs/polygamma2.svg" align="middle"></span>
<span class="inlinemediaobject"><img src="../../../graphs/polygamma3.svg" align="middle"></span>
</p>
<p>
The final <a class="link" href="../../policy.html" title="Chapter&#160;14.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
be used to control the behaviour of the function: how it handles errors,
what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter&#160;14.&#160;Policies: Controlling Precision, Error Handling etc">policy
documentation for more details</a>.
</p>
<p>
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
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
T otherwise.
</p>
<h5>
<a name="math_toolkit.sf_gamma.polygamma.h2"></a>
<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>
</h5>
<p>
The following table shows the peak errors (in units of epsilon) found on
various platforms with various floating point types. Unless otherwise specified
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>.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Significand Size
</p>
</th>
<th>
<p>
Platform and Compiler
</p>
</th>
<th>
<p>
Small-medium positive arguments
</p>
</th>
<th>
<p>
Small-medium negative x
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
53
</p>
</td>
<td>
<p>
Win32 Visual C++ 12
</p>
</td>
<td>
<p>
Peak=5.0 Mean=1
</p>
</td>
<td>
<p>
Peak=1200 Mean=65
</p>
</td>
</tr>
<tr>
<td>
<p>
64
</p>
</td>
<td>
<p>
Win64 Mingw GCC
</p>
</td>
<td>
<p>
Peak=16 Mean=3
</p>
</td>
<td>
<p>
Peak=33 Mean=3
</p>
</td>
</tr>
<tr>
<td>
<p>
113
</p>
</td>
<td>
<p>
Win64 Mingw GCC __float128
</p>
</td>
<td>
<p>
Peak=6.5 Mean=1
</p>
</td>
<td>
<p>
Peak=30 Mean=4
</p>
</td>
</tr>
</tbody>
</table></div>
<p>
As shown above, error rates are generally very acceptable for moderately
sized arguments. Error rates should stay low for exact inputs, however, please
note that the function becomes exceptionally sensitive to small changes in
input for large n and negative x, indeed for cases where <span class="emphasis"><em>n!</em></span>
would overflow, the function changes directly from -&#8734; to +&#8734; somewhere between
each negative integer - <span class="emphasis"><em>these cases are not handled correctly</em></span>.
</p>
<p>
<span class="bold"><strong>For these reasons results should be treated with extreme
caution when <span class="emphasis"><em>n</em></span> is large and x negative</strong></span>.
</p>
<h5>
<a name="math_toolkit.sf_gamma.polygamma.h3"></a>
<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>
</h5>
<p>
Testing is against Mathematica generated spot values to 35 digit precision.
</p>
<h5>
<a name="math_toolkit.sf_gamma.polygamma.h4"></a>
<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>
</h5>
<p>
For x &lt; 0 the following reflection formula is used:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../equations/polygamma2.svg"></span>
</p>
<p>
The n'th derivative of <span class="emphasis"><em>cot(x)</em></span> is tabulated for small
<span class="emphasis"><em>n</em></span>, and for larger n has the general form:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../equations/polygamma3.svg"></span>
</p>
<p>
The coefficients of the cosine terms can be calculated iteratively starting
from <span class="emphasis"><em>C<sub>1,0</sub> = -1</em></span> and then using
</p>
<p>
<span class="inlinemediaobject"><img src="../../../equations/polygamma7.svg"></span>
</p>
<p>
to generate coefficients for n+1.
</p>
<p>
Note that every other coefficient is zero, and therefore what we have are
even or odd polynomials depending on whether n is even or odd.
</p>
<p>
Once x is positive then we have two methods available to us, for small x
we use the series expansion:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../equations/polygamma4.svg"></span>
</p>
<p>
Note that the evaluation of zeta functions at integer values is essentially
a table lookup as <a class="link" href="../zetas/zeta.html" title="Riemann Zeta Function">zeta</a> is
optimized for those cases.
</p>
<p>
For large x we use the asymptotic expansion:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../equations/polygamma5.svg"></span>
</p>
<p>
For x in-between the two extremes we use the relation:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../equations/polygamma6.svg"></span>
</p>
<p>
to make x large enough for the asymptotic expansion to be used.
</p>
<p>
There are also two special cases:
</p>
<p>
<span class="inlinemediaobject"><img src="../../../equations/polygamma8.svg"></span>
</p>
<p>
<span class="inlinemediaobject"><img src="../../../equations/polygamma9.svg"></span>
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2006-2010, 2012-2014 Nikhar Agrawal,
Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
Holin, Bruno Lalande, John Maddock, Johan R&#229;de, Gautam Sewani, Benjamin Sobotta,
Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
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>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
</body>
</html>