Skip to content

Commit d583081

Browse files
committed
adding test and benchmark of Li2 against Pythia 8.315
1 parent 5ae6beb commit d583081

File tree

6 files changed

+86
-0
lines changed

6 files changed

+86
-0
lines changed

test/alt/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_subdirectory(koelbig)
1010
add_subdirectory(feynhiggs)
1111
add_subdirectory(morris)
1212
add_subdirectory(pade)
13+
add_subdirectory(pythia)
1314
add_subdirectory(sherpa)
1415
add_subdirectory(spheno)
1516
add_subdirectory(tsil)
@@ -35,6 +36,7 @@ target_link_libraries(alt
3536
feynhiggs
3637
morris
3738
pade
39+
pythia
3840
sherpa
3941
spheno
4042
tsil

test/alt/alt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ void feynhiggs_dilog(long double re, long double im, long double* res_re, long d
2525

2626
double morris_dilog(double x);
2727

28+
double pythia_dilog(const double x, const double kmax, const double xerr);
29+
2830
void hdecay_dilog(double re, double im, double* res_re, double* res_im);
2931

3032
void hollik_dilog(double re, double im, double* res_re, double* res_im);

test/alt/pythia/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_library(pythia
2+
pythia.c
3+
)
4+
5+
target_include_directories(pythia PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

test/alt/pythia/pythia.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <math.h>
2+
3+
#ifndef M_PI
4+
#define M_PI 3.1415926535897932
5+
#endif
6+
7+
/*
8+
Dilogarithm
9+
10+
Implementation from Pythia 8.315.
11+
Translated to C by Alexander Voigt.
12+
*/
13+
double pythia_dilog(const double x, const double kmax, const double xerr)
14+
{
15+
if (x < 0.0) {
16+
return 0.5*pythia_dilog(x*x, kmax, xerr) - pythia_dilog(-x, kmax, xerr);
17+
}
18+
19+
if (x <= 0.5) {
20+
double sum = x, term = x;
21+
22+
for (int k = 2; k < kmax; k++) {
23+
double rk = (k-1.0)/k;
24+
term *= x*rk*rk;
25+
sum += term;
26+
if (fabs(term/sum) < xerr) return sum;
27+
}
28+
29+
/* cout << "Maximum number of iterations exceeded in pythia_dilog" << endl; */
30+
return sum;
31+
}
32+
33+
if (x < 1.0) {
34+
return M_PI*M_PI/6.0 - pythia_dilog(1.0 - x, kmax, xerr) - log(x)*log(1.0 - x);
35+
}
36+
37+
if (x == 1.0) {
38+
return M_PI*M_PI/6.0;
39+
}
40+
41+
if (x <= 1.01) {
42+
const double eps = x - 1.0,
43+
lne = log(eps),
44+
c0 = M_PI*M_PI/6.0,
45+
c1 = 1.0 - lne,
46+
c2 = -(1.0 - 2.0*lne)/4.0,
47+
c3 = (1.0 - 3.0*lne)/9.0,
48+
c4 = -(1.0 - 4.0*lne)/16.0,
49+
c5 = (1.0 - 5.0*lne)/25.0,
50+
c6 = -(1.0 - 6.0*lne)/36.0,
51+
c7 = (1.0 - 7.0*lne)/49.0,
52+
c8 = -(1.0 - 8.0*lne)/64.0;
53+
54+
return c0 + eps*(c1 + eps*(c2 + eps*(c3 + eps*(c4 + eps*(c5 + eps*(c6 + eps*(c7 + eps*c8)))))));
55+
}
56+
57+
double logx = log(x);
58+
59+
if (x <= 2.0) {
60+
return M_PI*M_PI/6.0 + pythia_dilog(1.0 - 1.0/x, kmax, xerr) -
61+
logx*(log(1.0 - 1.0/x) + 0.5*logx);
62+
}
63+
64+
return M_PI*M_PI/3.0 - pythia_dilog(1.0/x, kmax, xerr) - 0.5*logx*logx;
65+
}

test/bench_Li.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ int main() {
323323
bench_fn([&](double x) { return morris_dilog(x); }, values_d,
324324
"Morris", "double");
325325

326+
bench_fn([&](double x) { return pythia_dilog(x, 100.0, 1e-9); }, values_d,
327+
"pythia(default)", "double");
328+
329+
bench_fn([&](double x) { return pythia_dilog(x, std::numeric_limits<double>::max(), std::numeric_limits<double>::epsilon()); }, values_d,
330+
"pythia(max)", "double");
331+
326332
bench_fn([&](long double x) { return polylogarithm::Li2(x); }, values_l,
327333
"polylogarithm C++", "long double");
328334

test/test_Li2.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ TEST_CASE("test_real_fixed_values")
496496
const auto li64_koelbig = koelbig_dilog(x64);
497497
const auto li128_koelbig = koelbig_dilogl(x128);
498498
const auto li64_morris = morris_dilog(x64);
499+
const auto li64_pythia = pythia_dilog(x64, 100.0, std::numeric_limits<double>::epsilon());
499500
#ifdef ENABLE_GSL
500501
const auto li64_gsl = gsl_Li2(x64);
501502
#endif
@@ -525,6 +526,7 @@ TEST_CASE("test_real_fixed_values")
525526
INFO("Li2(64) real = " << li64_hassani << " (hassani)");
526527
INFO("Li2(64) real = " << li64_koelbig << " (koelbig)");
527528
INFO("Li2(64) real = " << li64_morris << " (morris)");
529+
INFO("Li2(64) real = " << li64_pythia << " (pythia(default))");
528530
#ifdef ENABLE_GSL
529531
INFO("Li2(64) real = " << li64_gsl << " (GSL)");
530532
#endif
@@ -551,6 +553,7 @@ TEST_CASE("test_real_fixed_values")
551553
CHECK_CLOSE(li64_hassani , std::real(li64_expected) , 100*eps64);
552554
CHECK_CLOSE(li64_koelbig , std::real(li64_expected) , 2*eps64);
553555
CHECK_CLOSE(li64_morris , std::real(li64_expected) , 2*eps64);
556+
CHECK_CLOSE(li64_pythia , std::real(li64_expected) , 2*eps64);
554557
#ifdef ENABLE_GSL
555558
CHECK_CLOSE(li64_gsl , std::real(li64_expected) , 2*eps64);
556559
#endif
@@ -680,6 +683,7 @@ TEST_CASE("test_real_random_values")
680683
const double li2_hassani = hassani_dilog(v);
681684
const double li2_koelbig = koelbig_dilog(v);
682685
const double li2_morris = morris_dilog(v);
686+
const double li2_pythia = pythia_dilog(v, 100.0, std::numeric_limits<double>::epsilon());
683687

684688
INFO("x = " << v);
685689
INFO("Li2(64) real = " << li2 << " (polylogarithm C++)");
@@ -699,6 +703,7 @@ TEST_CASE("test_real_random_values")
699703
INFO("Li2(64) real = " << li2_hassani << " (Hassani)");
700704
INFO("Li2(64) real = " << li2_koelbig << " (Koelbig)");
701705
INFO("Li2(64) real = " << li2_morris << " (Morris)");
706+
INFO("Li2(64) real = " << li2_pythia << " (pythia)");
702707

703708
CHECK_CLOSE(li2, li2_c , eps64);
704709
#ifdef ENABLE_FORTRAN
@@ -716,6 +721,7 @@ TEST_CASE("test_real_random_values")
716721
CHECK_CLOSE(li2, li2_hassani , 100*eps64);
717722
CHECK_CLOSE(li2, li2_koelbig , 2*eps64);
718723
CHECK_CLOSE(li2, li2_morris , eps64);
724+
CHECK_CLOSE(li2, li2_pythia , 2*eps64);
719725
}
720726
}
721727

0 commit comments

Comments
 (0)