| 1 |
<html> |
| 2 |
<head> |
| 3 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 4 |
<title>Trigamma</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 4.2.1"> |
| 8 |
<link rel="up" href="../sf_gamma.html" title="Gamma Functions"> |
| 9 |
<link rel="prev" href="digamma.html" title="Digamma"> |
| 10 |
<link rel="next" href="polygamma.html" title="Polygamma"> |
| 11 |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 12 |
</head> |
| 13 |
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| 14 |
<table cellpadding="2" width="100%"><tr> |
| 15 |
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> |
| 16 |
<td align="center"><a href="../../../../../../index.html">Home</a></td> |
| 17 |
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> |
| 18 |
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> |
| 19 |
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> |
| 20 |
<td align="center"><a href="../../../../../../more/index.htm">More</a></td> |
| 21 |
</tr></table> |
| 22 |
<hr> |
| 23 |
<div class="spirit-nav"> |
| 24 |
<a accesskey="p" href="digamma.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="polygamma.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> |
| 25 |
</div> |
| 26 |
<div class="section"> |
| 27 |
<div class="titlepage"><div><div><h3 class="title"> |
| 28 |
<a name="math_toolkit.sf_gamma.trigamma"></a><a class="link" href="trigamma.html" title="Trigamma">Trigamma</a> |
| 29 |
</h3></div></div></div> |
| 30 |
<h5> |
| 31 |
<a name="math_toolkit.sf_gamma.trigamma.h0"></a> |
| 32 |
<span class="phrase"><a name="math_toolkit.sf_gamma.trigamma.synopsis"></a></span><a class="link" href="trigamma.html#math_toolkit.sf_gamma.trigamma.synopsis">Synopsis</a> |
| 33 |
</h5> |
| 34 |
<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">trigamma</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> |
| 35 |
</pre> |
| 36 |
<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 |
|
| 38 |
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> |
| 39 |
<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">trigamma</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">x</span><span class="special">);</span> |
| 40 |
|
| 41 |
<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 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> |
| 42 |
<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">trigamma</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 22. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> |
| 43 |
|
| 44 |
<span class="special">}}</span> <span class="comment">// namespaces</span> |
| 45 |
</pre> |
| 46 |
<h5> |
| 47 |
<a name="math_toolkit.sf_gamma.trigamma.h1"></a> |
| 48 |
<span class="phrase"><a name="math_toolkit.sf_gamma.trigamma.description"></a></span><a class="link" href="trigamma.html#math_toolkit.sf_gamma.trigamma.description">Description</a> |
| 49 |
</h5> |
| 50 |
<p> |
| 51 |
Returns the trigamma function of <span class="emphasis"><em>x</em></span>. Trigamma is defined |
| 52 |
as the derivative of the digamma function: |
| 53 |
</p> |
| 54 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 55 |
<span class="inlinemediaobject"><img src="../../../equations/trigamma1.svg"></span> |
| 56 |
|
| 57 |
</p></blockquote></div> |
| 58 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 59 |
<span class="inlinemediaobject"><img src="../../../graphs/trigamma.svg" align="middle"></span> |
| 60 |
|
| 61 |
</p></blockquote></div> |
| 62 |
<p> |
| 63 |
The final <a class="link" href="../../policy.html" title="Chapter 22. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can |
| 64 |
be used to control the behaviour of the function: how it handles errors, |
| 65 |
what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 22. Policies: Controlling Precision, Error Handling etc">policy |
| 66 |
documentation for more details</a>. |
| 67 |
</p> |
| 68 |
<p> |
| 69 |
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 |
| 70 |
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 |
| 71 |
T otherwise. |
| 72 |
</p> |
| 73 |
<h5> |
| 74 |
<a name="math_toolkit.sf_gamma.trigamma.h2"></a> |
| 75 |
<span class="phrase"><a name="math_toolkit.sf_gamma.trigamma.accuracy"></a></span><a class="link" href="trigamma.html#math_toolkit.sf_gamma.trigamma.accuracy">Accuracy</a> |
| 76 |
</h5> |
| 77 |
<p> |
| 78 |
The following table shows the peak errors (in units of epsilon) found on |
| 79 |
various platforms with various floating point types. Unless otherwise specified |
| 80 |
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>. |
| 81 |
</p> |
| 82 |
<div class="table"> |
| 83 |
<a name="math_toolkit.sf_gamma.trigamma.table_trigamma"></a><p class="title"><b>Table 8.5. Error rates for trigamma</b></p> |
| 84 |
<div class="table-contents"><table class="table" summary="Error rates for trigamma"> |
| 85 |
<colgroup> |
| 86 |
<col> |
| 87 |
<col> |
| 88 |
<col> |
| 89 |
<col> |
| 90 |
<col> |
| 91 |
</colgroup> |
| 92 |
<thead><tr> |
| 93 |
<th> |
| 94 |
</th> |
| 95 |
<th> |
| 96 |
<p> |
| 97 |
GNU C++ version 7.1.0<br> linux<br> double |
| 98 |
</p> |
| 99 |
</th> |
| 100 |
<th> |
| 101 |
<p> |
| 102 |
GNU C++ version 7.1.0<br> linux<br> long double |
| 103 |
</p> |
| 104 |
</th> |
| 105 |
<th> |
| 106 |
<p> |
| 107 |
Sun compiler version 0x5150<br> Sun Solaris<br> long double |
| 108 |
</p> |
| 109 |
</th> |
| 110 |
<th> |
| 111 |
<p> |
| 112 |
Microsoft Visual C++ version 14.1<br> Win32<br> double |
| 113 |
</p> |
| 114 |
</th> |
| 115 |
</tr></thead> |
| 116 |
<tbody><tr> |
| 117 |
<td> |
| 118 |
<p> |
| 119 |
Mathematica Data |
| 120 |
</p> |
| 121 |
</td> |
| 122 |
<td> |
| 123 |
<p> |
| 124 |
<span class="blue">Max = 0.998ε (Mean = 0.105ε)</span><br> <br> |
| 125 |
(<span class="emphasis"><em>GSL 2.1:</em></span> Max = 1.34e+04ε (Mean = 1.49e+03ε))<br> |
| 126 |
(<span class="emphasis"><em>Rmath 3.2.3:</em></span> Max = 1.34e+04ε (Mean = 1.51e+03ε)) |
| 127 |
</p> |
| 128 |
</td> |
| 129 |
<td> |
| 130 |
<p> |
| 131 |
<span class="blue">Max = 1.28ε (Mean = 0.449ε)</span> |
| 132 |
</p> |
| 133 |
</td> |
| 134 |
<td> |
| 135 |
<p> |
| 136 |
<span class="blue">Max = 1.28ε (Mean = 0.449ε)</span> |
| 137 |
</p> |
| 138 |
</td> |
| 139 |
<td> |
| 140 |
<p> |
| 141 |
<span class="blue">Max = 1ε (Mean = 0.382ε)</span> |
| 142 |
</p> |
| 143 |
</td> |
| 144 |
</tr></tbody> |
| 145 |
</table></div> |
| 146 |
</div> |
| 147 |
<br class="table-break"><p> |
| 148 |
As shown above, error rates are generally very low for built in types. For |
| 149 |
multiprecision types, error rates are typically in the order of a few epsilon. |
| 150 |
</p> |
| 151 |
<p> |
| 152 |
The following error plot are based on an exhaustive search of the functions |
| 153 |
domain, MSVC-15.5 at <code class="computeroutput"><span class="keyword">double</span></code> |
| 154 |
precision, and GCC-7.1/Ubuntu for <code class="computeroutput"><span class="keyword">long</span> |
| 155 |
<span class="keyword">double</span></code> and <code class="computeroutput"><span class="identifier">__float128</span></code>. |
| 156 |
</p> |
| 157 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 158 |
<span class="inlinemediaobject"><img src="../../../graphs/trigamma__double.svg" align="middle"></span> |
| 159 |
|
| 160 |
</p></blockquote></div> |
| 161 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 162 |
<span class="inlinemediaobject"><img src="../../../graphs/trigamma__80_bit_long_double.svg" align="middle"></span> |
| 163 |
|
| 164 |
</p></blockquote></div> |
| 165 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 166 |
<span class="inlinemediaobject"><img src="../../../graphs/trigamma____float128.svg" align="middle"></span> |
| 167 |
|
| 168 |
</p></blockquote></div> |
| 169 |
<h5> |
| 170 |
<a name="math_toolkit.sf_gamma.trigamma.h3"></a> |
| 171 |
<span class="phrase"><a name="math_toolkit.sf_gamma.trigamma.testing"></a></span><a class="link" href="trigamma.html#math_toolkit.sf_gamma.trigamma.testing">Testing</a> |
| 172 |
</h5> |
| 173 |
<p> |
| 174 |
Testing is against Mathematica generated spot values to 35 digit precision. |
| 175 |
</p> |
| 176 |
<h5> |
| 177 |
<a name="math_toolkit.sf_gamma.trigamma.h4"></a> |
| 178 |
<span class="phrase"><a name="math_toolkit.sf_gamma.trigamma.implementation"></a></span><a class="link" href="trigamma.html#math_toolkit.sf_gamma.trigamma.implementation">Implementation</a> |
| 179 |
</h5> |
| 180 |
<p> |
| 181 |
The arbitrary precision version of this function simply calls <a class="link" href="polygamma.html" title="Polygamma">polygamma</a>. |
| 182 |
</p> |
| 183 |
<p> |
| 184 |
For built in fixed-precision types, negative arguments are first made positive |
| 185 |
via: |
| 186 |
</p> |
| 187 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 188 |
<span class="inlinemediaobject"><img src="../../../equations/trigamma2.svg"></span> |
| 189 |
|
| 190 |
</p></blockquote></div> |
| 191 |
<p> |
| 192 |
Then arguments in the range [0, 1) are shifted to >= 1 via: |
| 193 |
</p> |
| 194 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 195 |
<span class="inlinemediaobject"><img src="../../../equations/trigamma3.svg"></span> |
| 196 |
|
| 197 |
</p></blockquote></div> |
| 198 |
<p> |
| 199 |
Then evaluation is via one of a number of rational approximations, for small |
| 200 |
<span class="emphasis"><em>x</em></span> these are of the form: |
| 201 |
</p> |
| 202 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 203 |
<span class="inlinemediaobject"><img src="../../../equations/trigamma4.svg"></span> |
| 204 |
|
| 205 |
</p></blockquote></div> |
| 206 |
<p> |
| 207 |
and for large <span class="emphasis"><em>x</em></span> of the form: |
| 208 |
</p> |
| 209 |
<div class="blockquote"><blockquote class="blockquote"><p> |
| 210 |
<span class="inlinemediaobject"><img src="../../../equations/trigamma5.svg"></span> |
| 211 |
|
| 212 |
</p></blockquote></div> |
| 213 |
</div> |
| 214 |
<div class="copyright-footer">Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland, |
| 215 |
Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno |
| 216 |
Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde, |
| 217 |
Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle |
| 218 |
Walker and Xiaogang Zhang<p> |
| 219 |
Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 220 |
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>) |
| 221 |
</p> |
| 222 |
</div> |
| 223 |
<hr> |
| 224 |
<div class="spirit-nav"> |
| 225 |
<a accesskey="p" href="digamma.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="polygamma.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> |
| 226 |
</div> |
| 227 |
</body> |
| 228 |
</html> |