1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Riemann Zeta Function</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="../zetas.html" title="Zeta Functions"> 9<link rel="prev" href="../zetas.html" title="Zeta Functions"> 10<link rel="next" href="../expint.html" title="Exponential Integrals"> 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="../zetas.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../zetas.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="../expint.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.zetas.zeta"></a><a class="link" href="zeta.html" title="Riemann Zeta Function">Riemann Zeta Function</a> 28</h3></div></div></div> 29<h5> 30<a name="math_toolkit.zetas.zeta.h0"></a> 31 <span class="phrase"><a name="math_toolkit.zetas.zeta.synopsis"></a></span><a class="link" href="zeta.html#math_toolkit.zetas.zeta.synopsis">Synopsis</a> 32 </h5> 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">zeta</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></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"><</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">zeta</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">);</span> 39 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 21. 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">zeta</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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> 42 43<span class="special">}}</span> <span class="comment">// namespaces</span> 44</pre> 45<p> 46 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 47 type calculation rules</em></span></a>: the return type is <code class="computeroutput"><span class="keyword">double</span></code> if T is an integer type, and T otherwise. 48 </p> 49<p> 50 The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can 51 be used to control the behaviour of the function: how it handles errors, 52 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 53 documentation for more details</a>. 54 </p> 55<h5> 56<a name="math_toolkit.zetas.zeta.h1"></a> 57 <span class="phrase"><a name="math_toolkit.zetas.zeta.description"></a></span><a class="link" href="zeta.html#math_toolkit.zetas.zeta.description">Description</a> 58 </h5> 59<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 60<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">zeta</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">);</span> 61 62<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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> 63<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">zeta</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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> 64</pre> 65<p> 66 Returns the <a href="http://mathworld.wolfram.com/RiemannZetaFunction.html" target="_top">zeta 67 function</a> of z: 68 </p> 69<div class="blockquote"><blockquote class="blockquote"><p> 70 <span class="inlinemediaobject"><img src="../../../equations/zeta1.svg"></span> 71 72 </p></blockquote></div> 73<div class="blockquote"><blockquote class="blockquote"><p> 74 <span class="inlinemediaobject"><img src="../../../graphs/zeta1.svg" align="middle"></span> 75 76 </p></blockquote></div> 77<div class="blockquote"><blockquote class="blockquote"><p> 78 <span class="inlinemediaobject"><img src="../../../graphs/zeta2.svg" align="middle"></span> 79 80 </p></blockquote></div> 81<h5> 82<a name="math_toolkit.zetas.zeta.h2"></a> 83 <span class="phrase"><a name="math_toolkit.zetas.zeta.accuracy"></a></span><a class="link" href="zeta.html#math_toolkit.zetas.zeta.accuracy">Accuracy</a> 84 </h5> 85<p> 86 The following table shows the peak errors (in units of epsilon) found on 87 various platforms with various floating point types, along with comparisons 88 to the <a href="http://www.gnu.org/software/gsl/" target="_top">GSL-1.9</a> and 89 <a href="http://www.netlib.org/cephes/" target="_top">Cephes</a> libraries. Unless 90 otherwise specified any floating point type that is narrower than the one 91 shown will have <a class="link" href="../relative_error.html#math_toolkit.relative_error.zero_error">effectively 92 zero error</a>. 93 </p> 94<div class="table"> 95<a name="math_toolkit.zetas.zeta.table_zeta"></a><p class="title"><b>Table 8.76. Error rates for zeta</b></p> 96<div class="table-contents"><table class="table" summary="Error rates for zeta"> 97<colgroup> 98<col> 99<col> 100<col> 101<col> 102<col> 103</colgroup> 104<thead><tr> 105<th> 106 </th> 107<th> 108 <p> 109 GNU C++ version 7.1.0<br> linux<br> long double 110 </p> 111 </th> 112<th> 113 <p> 114 GNU C++ version 7.1.0<br> linux<br> double 115 </p> 116 </th> 117<th> 118 <p> 119 Sun compiler version 0x5150<br> Sun Solaris<br> long double 120 </p> 121 </th> 122<th> 123 <p> 124 Microsoft Visual C++ version 14.1<br> Win32<br> double 125 </p> 126 </th> 127</tr></thead> 128<tbody> 129<tr> 130<td> 131 <p> 132 Zeta: Random values greater than 1 133 </p> 134 </td> 135<td> 136 <p> 137 <span class="blue">Max = 0.846ε (Mean = 0.0833ε)</span><br> 138 <br> (<span class="emphasis"><em><cmath>:</em></span> Max = 5.45ε (Mean = 1ε)) 139 </p> 140 </td> 141<td> 142 <p> 143 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL 144 2.1:</em></span> Max = 8.69ε (Mean = 1.03ε)) 145 </p> 146 </td> 147<td> 148 <p> 149 <span class="blue">Max = 0.846ε (Mean = 0.0833ε)</span> 150 </p> 151 </td> 152<td> 153 <p> 154 <span class="blue">Max = 0.836ε (Mean = 0.093ε)</span> 155 </p> 156 </td> 157</tr> 158<tr> 159<td> 160 <p> 161 Zeta: Random values less than 1 162 </p> 163 </td> 164<td> 165 <p> 166 <span class="blue">Max = 7.03ε (Mean = 2.93ε)</span><br> <br> 167 (<span class="emphasis"><em><cmath>:</em></span> Max = 538ε (Mean = 59.3ε)) 168 </p> 169 </td> 170<td> 171 <p> 172 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL 173 2.1:</em></span> Max = 137ε (Mean = 13.8ε)) 174 </p> 175 </td> 176<td> 177 <p> 178 <span class="blue">Max = 70.1ε (Mean = 17.1ε)</span> 179 </p> 180 </td> 181<td> 182 <p> 183 <span class="blue">Max = 6.84ε (Mean = 3.12ε)</span> 184 </p> 185 </td> 186</tr> 187<tr> 188<td> 189 <p> 190 Zeta: Values close to and greater than 1 191 </p> 192 </td> 193<td> 194 <p> 195 <span class="blue">Max = 0.995ε (Mean = 0.5ε)</span><br> <br> 196 (<span class="emphasis"><em><cmath>:</em></span> Max = 1.9e+06ε (Mean = 5.11e+05ε)) 197 </p> 198 </td> 199<td> 200 <p> 201 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL 202 2.1:</em></span> Max = 7.73ε (Mean = 4.07ε)) 203 </p> 204 </td> 205<td> 206 <p> 207 <span class="blue">Max = 0.995ε (Mean = 0.5ε)</span> 208 </p> 209 </td> 210<td> 211 <p> 212 <span class="blue">Max = 0.994ε (Mean = 0.421ε)</span> 213 </p> 214 </td> 215</tr> 216<tr> 217<td> 218 <p> 219 Zeta: Values close to and less than 1 220 </p> 221 </td> 222<td> 223 <p> 224 <span class="blue">Max = 0.998ε (Mean = 0.508ε)</span><br> <br> 225 (<span class="emphasis"><em><cmath>:</em></span> Max = 8.53e+06ε (Mean = 1.87e+06ε)) 226 </p> 227 </td> 228<td> 229 <p> 230 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL 231 2.1:</em></span> Max = 0.991ε (Mean = 0.28ε)) 232 </p> 233 </td> 234<td> 235 <p> 236 <span class="blue">Max = 0.998ε (Mean = 0.508ε)</span> 237 </p> 238 </td> 239<td> 240 <p> 241 <span class="blue">Max = 0.991ε (Mean = 0.375ε)</span> 242 </p> 243 </td> 244</tr> 245<tr> 246<td> 247 <p> 248 Zeta: Integer arguments 249 </p> 250 </td> 251<td> 252 <p> 253 <span class="blue">Max = 9ε (Mean = 3.06ε)</span><br> <br> 254 (<span class="emphasis"><em><cmath>:</em></span> Max = 70.3ε (Mean = 17.4ε)) 255 </p> 256 </td> 257<td> 258 <p> 259 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>GSL 260 2.1:</em></span> Max = 3.75ε (Mean = 1.1ε)) 261 </p> 262 </td> 263<td> 264 <p> 265 <span class="blue">Max = 28ε (Mean = 5.62ε)</span> 266 </p> 267 </td> 268<td> 269 <p> 270 <span class="blue">Max = 9ε (Mean = 3ε)</span> 271 </p> 272 </td> 273</tr> 274</tbody> 275</table></div> 276</div> 277<br class="table-break"><p> 278 The following error plot are based on an exhaustive search of the functions 279 domain, MSVC-15.5 at <code class="computeroutput"><span class="keyword">double</span></code> 280 precision, and GCC-7.1/Ubuntu for <code class="computeroutput"><span class="keyword">long</span> 281 <span class="keyword">double</span></code> and <code class="computeroutput"><span class="identifier">__float128</span></code>. 282 </p> 283<div class="blockquote"><blockquote class="blockquote"><p> 284 <span class="inlinemediaobject"><img src="../../../graphs/zeta__double.svg" align="middle"></span> 285 286 </p></blockquote></div> 287<div class="blockquote"><blockquote class="blockquote"><p> 288 <span class="inlinemediaobject"><img src="../../../graphs/zeta__80_bit_long_double.svg" align="middle"></span> 289 290 </p></blockquote></div> 291<div class="blockquote"><blockquote class="blockquote"><p> 292 <span class="inlinemediaobject"><img src="../../../graphs/zeta____float128.svg" align="middle"></span> 293 294 </p></blockquote></div> 295<h5> 296<a name="math_toolkit.zetas.zeta.h3"></a> 297 <span class="phrase"><a name="math_toolkit.zetas.zeta.testing"></a></span><a class="link" href="zeta.html#math_toolkit.zetas.zeta.testing">Testing</a> 298 </h5> 299<p> 300 The tests for these functions come in two parts: basic sanity checks use 301 spot values calculated using <a href="http://functions.wolfram.com/webMathematica/FunctionEvaluation.jsp?name=Zeta" target="_top">Mathworld's 302 online evaluator</a>, while accuracy checks use high-precision test values 303 calculated at 1000-bit precision with <a href="http://shoup.net/ntl/doc/RR.txt" target="_top">NTL::RR</a> 304 and this implementation. Note that the generic and type-specific versions 305 of these functions use differing implementations internally, so this gives 306 us reasonably independent test data. Using our test data to test other "known 307 good" implementations also provides an additional sanity check. 308 </p> 309<h5> 310<a name="math_toolkit.zetas.zeta.h4"></a> 311 <span class="phrase"><a name="math_toolkit.zetas.zeta.implementation"></a></span><a class="link" href="zeta.html#math_toolkit.zetas.zeta.implementation">Implementation</a> 312 </h5> 313<p> 314 All versions of these functions first use the usual reflection formulas to 315 make their arguments positive: 316 </p> 317<div class="blockquote"><blockquote class="blockquote"><p> 318 <span class="inlinemediaobject"><img src="../../../equations/zeta3.svg"></span> 319 320 </p></blockquote></div> 321<p> 322 The generic versions of these functions are implemented using the series: 323 </p> 324<div class="blockquote"><blockquote class="blockquote"><p> 325 <span class="inlinemediaobject"><img src="../../../equations/zeta6.svg"></span> 326 327 </p></blockquote></div> 328<p> 329 When the significand (mantissa) size is recognised (currently for 53, 64 330 and 113-bit reals, plus single-precision 24-bit handled via promotion to 331 double) then a series of rational approximations <a class="link" href="../sf_implementation.html#math_toolkit.sf_implementation.rational_approximations_used">devised 332 by JM</a> are used. 333 </p> 334<p> 335 For 0 < z < 1 the approximating form is: 336 </p> 337<div class="blockquote"><blockquote class="blockquote"><p> 338 <span class="inlinemediaobject"><img src="../../../equations/zeta4.svg"></span> 339 340 </p></blockquote></div> 341<p> 342 For a rational approximation <span class="emphasis"><em>R(1-z)</em></span> and a constant 343 <span class="emphasis"><em>C</em></span>: 344 </p> 345<p> 346 For 1 < z < 4 the approximating form is: 347 </p> 348<div class="blockquote"><blockquote class="blockquote"><p> 349 <span class="inlinemediaobject"><img src="../../../equations/zeta5.svg"></span> 350 351 </p></blockquote></div> 352<p> 353 For a rational approximation <span class="emphasis"><em>R(n-z)</em></span> and a constant 354 <span class="emphasis"><em>C</em></span> and integer <span class="emphasis"><em>n</em></span>: 355 </p> 356<p> 357 For z > 4 the approximating form is: 358 </p> 359<div class="blockquote"><blockquote class="blockquote"><p> 360 <span class="serif_italic">ζ(z) = 1 + e<sup>R(z - n)</sup></span> 361 </p></blockquote></div> 362<p> 363 For a rational approximation <span class="emphasis"><em>R(z-n)</em></span> and integer <span class="emphasis"><em>n</em></span>, 364 note that the accuracy required for <span class="emphasis"><em>R(z-n)</em></span> is not full 365 machine-precision, but an absolute error of: /ε<span class="emphasis"><em>R(0)</em></span>. 366 This saves us quite a few digits when dealing with large <span class="emphasis"><em>z</em></span>, 367 especially when ε is small. 368 </p> 369<p> 370 Finally, there are some special cases for integer arguments, there are closed 371 forms for negative or even integers: 372 </p> 373<div class="blockquote"><blockquote class="blockquote"><p> 374 <span class="inlinemediaobject"><img src="../../../equations/zeta7.svg"></span> 375 376 </p></blockquote></div> 377<div class="blockquote"><blockquote class="blockquote"><p> 378 <span class="inlinemediaobject"><img src="../../../equations/zeta8.svg"></span> 379 380 </p></blockquote></div> 381<div class="blockquote"><blockquote class="blockquote"><p> 382 <span class="inlinemediaobject"><img src="../../../equations/zeta9.svg"></span> 383 384 </p></blockquote></div> 385<p> 386 and for positive odd integers we simply cache pre-computed values as these 387 are of great benefit to some infinite series calculations. 388 </p> 389</div> 390<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 391<td align="left"></td> 392<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 393 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 394 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 395 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 396 Daryle Walker and Xiaogang Zhang<p> 397 Distributed under the Boost Software License, Version 1.0. (See accompanying 398 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>) 399 </p> 400</div></td> 401</tr></table> 402<hr> 403<div class="spirit-nav"> 404<a accesskey="p" href="../zetas.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../zetas.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="../expint.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 405</div> 406</body> 407</html> 408