Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Commit d1f39b1

Browse files
committed
Revising Zeta comments and copyright
1 parent ab2cdb2 commit d1f39b1

File tree

2 files changed

+41
-71
lines changed

2 files changed

+41
-71
lines changed

internal/cephes/zeta.go

Lines changed: 38 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,53 @@
1-
// Copyright ©2016 The gonum Authors. All rights reserved.
1+
// Derived from SciPy's special/cephes/zeta.c
2+
// https://github.com/scipy/scipy/blob/master/scipy/special/cephes/zeta.c
3+
24
// Use of this source code is governed by a BSD-style
35
// license that can be found in the LICENSE file.
4-
5-
/*
6-
* Cephes Math Library Release 2.1: January, 1989
7-
* Copyright 1984, 1987, 1989 by Stephen L. Moshier
8-
* Direct inquiries to 30 Frost Street, Cambridge, MA 02140
9-
*/
6+
// Copyright ©1984, ©1987 by Stephen L. Moshier
7+
// Portions Copyright ©2016 The gonum Authors. All rights reserved.
108

119
package cephes
1210

1311
import "math"
1412

15-
/*
16-
* Adapted from scipy's cephes zeta.c
17-
*/
18-
19-
/*
20-
* Riemann zeta function of two arguments
21-
*
22-
*
23-
* DESCRIPTION:
24-
*
25-
* inf.
26-
* - -x
27-
* zeta(x,q) = > (k+q)
28-
* -
29-
* k=0
30-
*
31-
* where x > 1 and q is not a negative integer or zero.
32-
* The Euler-Maclaurin summation formula is used to obtain
33-
* the expansion
34-
*
35-
* n
36-
* - -x
37-
* zeta(x,q) = > (k+q)
38-
* -
39-
* k=1
40-
*
41-
* 1-x inf. B x(x+1)...(x+2j)
42-
* (n+q) 1 - 2j
43-
* + --------- - ------- + > --------------------
44-
* x-1 x - x+2j+1
45-
* 2(n+q) j=1 (2j)! (n+q)
46-
*
47-
* where the B2j are Bernoulli numbers. Note that (see zetac.c)
48-
* zeta(x,1) = zetac(x) + 1.
49-
*
50-
*
51-
* REFERENCE:
52-
*
53-
* Gradshteyn, I. S., and I. M. Ryzhik, Tables of Integrals,
54-
* Series, and Products, p. 1073; Academic Press, 1980.
55-
*
56-
*/
57-
58-
/* Expansion coefficients
59-
* for Euler-Maclaurin summation formula
60-
* (2k)! / B2k
61-
* where B2k are Bernoulli numbers
62-
*/
13+
// zetaCoegs are the expansion coefficients for Euler-Maclaurin summation
14+
// formula:
15+
// \frac{(2k)!}{B_{2k}}
16+
// where
17+
// B_{2k}
18+
// are Bernoulli numbers.
6319
var zetaCoefs = []float64{
6420
12.0,
6521
-720.0,
6622
30240.0,
6723
-1209600.0,
6824
47900160.0,
69-
-1.8924375803183791606e9, /*1.307674368e12/691 */
25+
-1.307674368e12 / 691,
7026
7.47242496e10,
71-
-2.950130727918164224e12, /*1.067062284288e16/3617 */
72-
1.1646782814350067249e14, /*5.109094217170944e18/43867 */
73-
-4.5979787224074726105e15, /*8.028576626982912e20/174611 */
74-
1.8152105401943546773e17, /*1.5511210043330985984e23/854513 */
75-
-7.1661652561756670113e18, /*1.6938241367317436694528e27/236364091 */
27+
-1.067062284288e16 / 3617,
28+
5.109094217170944e18 / 43867,
29+
-8.028576626982912e20 / 174611,
30+
1.5511210043330985984e23 / 854513,
31+
-1.6938241367317436694528e27 / 236364091,
7632
}
7733

78-
// Zeta calculates the Riemann zeta function of two arguments
34+
// Zeta computes the Riemann zeta function of two arguments.
35+
// Zeta(x,q) = \sum_{k=0}^{\infty} (k+q)^{-x}
36+
// Note that Zeta returns +Inf if x is 1 and will panic if x is less than 1,
37+
// q is either zero or a negative integer, or q is negative and x is not an
38+
// integer.
39+
//
40+
// The Euler-Maclaurin summation formula is used to obtain the expansion:
41+
// Zeta(x,q) = \sum_{k=1}^n (k+q)^{-x} + \frac{(n+q)^{1-x}}{x-1} - \frac{1}{2(n+q)^x} + \sum_{j=1}^{\infty} \frac{B_{2j}x(x+1)...(x+2j)}{(2j)! (n+q)^{x+2j+1}}
42+
// where
43+
// B_{2j}
44+
// are Bernoulli numbers.
45+
//
46+
// Note that:
47+
// zeta(x,1) = zetac(x) + 1
48+
//
49+
// REFERENCE: Gradshteyn, I. S., and I. M. Ryzhik, Tables of Integrals, Series,
50+
// and Products, p. 1073; Academic Press, 1980.
7951
func Zeta(x, q float64) float64 {
8052
if x == 1 {
8153
return math.MaxFloat64
@@ -94,20 +66,16 @@ func Zeta(x, q float64) float64 {
9466
}
9567
}
9668

97-
/* Asymptotic expansion
98-
* http://dlmf.nist.gov/25.11#E43
99-
*/
69+
// Asymptotic expansion: http://dlmf.nist.gov/25.11#E43
10070
if q > 1e8 {
10171
return (1/(x-1) + 1/(2*q)) * math.Pow(q, 1-x)
10272
}
10373

10474
// Euler-Maclaurin summation formula
10575

106-
/* Permit negative q but continue sum until n+q > +9 .
107-
* This case should be handled by a reflection formula.
108-
* If q<0 and x is an integer, there is a relation to
109-
* the polyGamma function.
110-
*/
76+
// Permit negative q but continue sum until n+q > 9. This case should be
77+
// handled by a reflection formula. If q<0 and x is an integer, there is a
78+
// relation to the polyGamma function.
11179
s := math.Pow(q, -x)
11280
a := q
11381
i := 0

zeta.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import "github.com/gonum/mathext/internal/cephes"
88

99
// Zeta computes the Riemann zeta function of two arguments.
1010
// Zeta(x,q) = \sum_{k=0}^{\infty} (k+q)^{-x}
11-
// where x > 1 and q is not a negative integer or zero.
11+
// Note that Zeta returns +Inf if x is 1 and will panic if x is less than 1,
12+
// q is either zero or a negative integer, or q is negative and x is not an
13+
// integer.
1214
//
1315
// See http://mathworld.wolfram.com/HurwitzZetaFunction.html
1416
// or https://en.wikipedia.org/wiki/Multiple_zeta_function#Two_parameters_case

0 commit comments

Comments
 (0)