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