Skip to content

Refine general Li(n,z) function #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Feb 18, 2022
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
017278c
extract zeta function
Expander Feb 13, 2022
f6da230
adding constexpr and noexcept specifiers
Expander Feb 13, 2022
74c5ef1
lookup table for (negative) Dirichlet eta function
Expander Feb 13, 2022
e66045d
remove unused function
Expander Feb 13, 2022
141278d
move harmonic number calculation to separate module
Expander Feb 13, 2022
7961e60
faster implementation of harmonic for large n
Expander Feb 13, 2022
eb15208
shrink if-else branches
Expander Feb 13, 2022
ec1597d
always perform transformation to unit circle
Expander Feb 13, 2022
5956ee5
use more precise inverse factorial
Expander Feb 13, 2022
182c861
move remainder to separate function
Expander Feb 14, 2022
ccf529f
use alternative implementation of remainder of inversion formula
Expander Feb 14, 2022
edadc95
comment out unused routine
Expander Feb 14, 2022
64c5fca
avoid re-calculation of ln(-z)^n
Expander Feb 14, 2022
c5121dc
avoid always using inversion formula
Expander Feb 14, 2022
5446747
remove unused headers
Expander Feb 14, 2022
fc39c0f
fix indentation
Expander Feb 14, 2022
9e08eef
stricter if statements
Expander Feb 14, 2022
87f48c8
reorder if statements
Expander Feb 14, 2022
234f95d
remove unnecessary statement
Expander Feb 14, 2022
035d6c6
increase test precision
Expander Feb 14, 2022
aa9f900
catch nan and inf input
Expander Feb 14, 2022
bc2caf3
remove tests for nan and inf
Expander Feb 14, 2022
bab018d
mark functions as noexcept
Expander Feb 14, 2022
42765da
remove manual setting imaginary part to zero
Expander Feb 14, 2022
a8cabf8
rename file
Expander Feb 15, 2022
0a2e22b
test zeta function
Expander Feb 15, 2022
ccffa51
test harmonic numbers
Expander Feb 15, 2022
3de0b37
test eta function
Expander Feb 15, 2022
4514ee3
test factorial
Expander Feb 15, 2022
337c419
sort headers
Expander Feb 15, 2022
9093109
extend transformation to negative n
Expander Feb 15, 2022
3b27f48
use naive sum for n < 0 far from z = 1
Expander Feb 15, 2022
1973ba6
avoid one division
Expander Feb 15, 2022
38250c3
use faster expansion for n < 0
Expander Feb 15, 2022
d27f954
remove unused functions
Expander Feb 15, 2022
6aa8cfa
add missing header inclusion
Expander Feb 15, 2022
7d2337e
rename functions
Expander Feb 15, 2022
54303ba
shorten function
Expander Feb 15, 2022
42b06e2
correcting returned inf for z == 1 and n <= 0
Expander Feb 15, 2022
73b9a30
adding more test data
Expander Feb 15, 2022
e7b6757
rename function
Expander Feb 15, 2022
c1a6f21
keep powers small
Expander Feb 16, 2022
98824c6
adding (commented) tests
Expander Feb 16, 2022
511aeb5
use zeta expansion for broarder range for n < 0
Expander Feb 18, 2022
93f0d9f
avoid calculation of one sqrt
Expander Feb 18, 2022
dfe5c58
use more numerically stable approach of arXiv:2010.09860
Expander Feb 18, 2022
244784e
avoid numerical instability in complex std::pow when imag == 0
Expander Feb 18, 2022
e075d49
adding more test data
Expander Feb 18, 2022
4bb668f
fix instability for Re(z) == 0 or Im(z) == 0
Expander Feb 18, 2022
111002e
use more performant implementations for fixed n
Expander Feb 18, 2022
7dd89c3
reorder if statements to be more systematic
Expander Feb 18, 2022
f6fe944
remove unused if statement
Expander Feb 18, 2022
3381f74
adding author information and reference
Expander Feb 18, 2022
7cba1cd
mark function noexcept
Expander Feb 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move remainder to separate function
  • Loading branch information
Expander committed Feb 14, 2022
commit 182c861f4d2548590fd8c04e14d833aba0985b3b
33 changes: 20 additions & 13 deletions src/cpp/Li.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ namespace {
return std::pow(mu, n - 1)*inv_fac(n - 1)*(harmonic(n - 1) - clog(-mu)) + sum;
}

/// returns remainder from inversion formula
std::complex<double> Li_rest(int64_t n, const std::complex<double>& z) noexcept
{
const double PI = 3.141592653589793;
const std::complex<double> IPI2(0.,2*PI);
const std::complex<double> lnz = clog(-z);

return -std::pow(IPI2, n)*inv_fac(n)*bernoulli_p(n, 0.5 + lnz/IPI2);
}

} // anonymous namespace

/**
Expand Down Expand Up @@ -266,28 +276,25 @@ std::complex<double> Li(int64_t n, const std::complex<double>& z)
return {neg_eta(n), 0.0};
}

if (n >= 12) {
const auto li = Li_naive_sum(n, z);
// const auto liy = Li_naive_sum(n, y);
// std::cout << "n = " << n << ", z = " << z << ", y = " << y << ": Li(n,z) = " << li << ", sgn = " << sgn << ", r = " << r << ", Li(n,y) = " << liy << '\n';
// return liy;
return li; // @todo(alex): remove
// return sgn*Li_naive_sum(n, y) + r;
}

// transformation z to y in the unit circle
std::complex<double> y(z), r(0.0, 0.0);
double sgn = 1;

if (std::norm(z) > 1.0) {
const double PI = 3.141592653589793;
const std::complex<double> IPI2(0.,2*PI);
const std::complex<double> lnz = clog(-z);
y = 1.0/z;
r = -std::pow(IPI2, n)*inv_fac(n)*bernoulli_p(n, 0.5 + lnz/IPI2);
r = Li_rest(n, z);
sgn = is_even(n) ? -1. : 1.;
}

if (n >= 12) {
const auto li = Li_naive_sum(n, z);
const auto liy = Li_naive_sum(n, y);
// std::cout << "n = " << n << ", z = " << z << ", y = " << y << ": Li(n,z) = " << li << ", sgn = " << sgn << ", r = " << r << ", Li(n,y) = " << liy << '\n';
// return liy;
return li; // @todo(alex): remove
return sgn*Li_naive_sum(n, y) + r;
}

if (is_close(y, 1., 2e-2)) {
return sgn*Li_expand_around_unity(n, y) + r;
}
Expand Down