Skip to content

Commit

Permalink
Use direct summation
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmasson committed Oct 26, 2020
1 parent c30d3eb commit 4bc22b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
18 changes: 5 additions & 13 deletions build/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -3615,13 +3615,9 @@ function hurwitzZeta( x, a, tolerance=1e-10 ) {

if ( x.re === 1 && x.im === 0 ) throw Error( 'Hurwitz zeta pole' );

// dlmf.nist.gov/25.11.4
if ( isNegativeIntegerOrZero(a) ) throw Error( 'Hurwitz zeta parameter pole' );

if ( a.re > 1 ) {
var m = Math.floor(a.re);
a = sub( a, m );
return sub( hurwitzZeta(x,a), summation( i => pow( add(a,i), neg(x) ), [0,m-1] ) );
}
// direct summation more accurate than dlmf.nist.gov/25.11.4 for positive a

if ( a.re < 0 ) {
var m = -Math.floor(a.re);
Expand Down Expand Up @@ -3693,16 +3689,12 @@ function hurwitzZeta( x, a, tolerance=1e-10 ) {

if ( x === 1 ) throw Error( 'Hurwitz zeta pole' );

// dlmf.nist.gov/25.11.4

if ( a > 1 ) {
var m = Math.floor(a);
a -= m;
return hurwitzZeta(x,a) - summation( i => 1 / (a+i)**x, [0,m-1] );
}
if ( isNegativeIntegerOrZero(a) ) throw Error( 'Hurwitz zeta parameter pole' );

if ( a < 0 ) return hurwitzZeta( x, complex(a) );

// direct summation more accurate than dlmf.nist.gov/25.11.4

// Euler-Maclaurin has differences of large values in left-hand plane
// switch to different summation: dlmf.nist.gov/25.11.9

Expand Down
18 changes: 5 additions & 13 deletions src/functions/zeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,9 @@ function hurwitzZeta( x, a, tolerance=1e-10 ) {

if ( x.re === 1 && x.im === 0 ) throw Error( 'Hurwitz zeta pole' );

// dlmf.nist.gov/25.11.4
if ( isNegativeIntegerOrZero(a) ) throw Error( 'Hurwitz zeta parameter pole' );

if ( a.re > 1 ) {
var m = Math.floor(a.re);
a = sub( a, m );
return sub( hurwitzZeta(x,a), summation( i => pow( add(a,i), neg(x) ), [0,m-1] ) );
}
// direct summation more accurate than dlmf.nist.gov/25.11.4 for positive a

if ( a.re < 0 ) {
var m = -Math.floor(a.re);
Expand Down Expand Up @@ -191,16 +187,12 @@ function hurwitzZeta( x, a, tolerance=1e-10 ) {

if ( x === 1 ) throw Error( 'Hurwitz zeta pole' );

// dlmf.nist.gov/25.11.4

if ( a > 1 ) {
var m = Math.floor(a);
a -= m;
return hurwitzZeta(x,a) - summation( i => 1 / (a+i)**x, [0,m-1] );
}
if ( isNegativeIntegerOrZero(a) ) throw Error( 'Hurwitz zeta parameter pole' );

if ( a < 0 ) return hurwitzZeta( x, complex(a) );

// direct summation more accurate than dlmf.nist.gov/25.11.4

// Euler-Maclaurin has differences of large values in left-hand plane
// switch to different summation: dlmf.nist.gov/25.11.9

Expand Down

0 comments on commit 4bc22b8

Please sign in to comment.