-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace old complex dilogarithm implementation by faster one (#7)
Gives a performance improvement by ~25%. The original implementation dated back to 20.07.83, written by Wolfgang Hollik, modified by Ansgar Denner.
- Loading branch information
Showing
6 changed files
with
245 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
!********************************************************************* | ||
! This file is part of Polylogarithm. | ||
! | ||
! Polylogarithm is licenced under the MIT License. | ||
!********************************************************************* | ||
|
||
|
||
!********************************************************************* | ||
!> @brief Real dilogarithm \f$\mathrm{Li}_2(x)\f$ | ||
!> @param x real argument | ||
!> @return \f$\mathrm{Li}_2(x)\f$ | ||
!> @author Alexander Voigt | ||
!> | ||
!> Implemented as an economized Pade approximation with a | ||
!> maximum error of 4.16e-18. | ||
!********************************************************************* | ||
|
||
double precision function dli2(x) | ||
implicit none | ||
double precision :: x, y, r, s, z, p, q, l, dhorner | ||
double precision, parameter :: PI = 3.14159265358979324D0 | ||
double precision, parameter :: cp(8) = (/ & | ||
1.0706105563309304277D+0, & | ||
-4.5353562730201404017D+0, & | ||
7.4819657596286408905D+0, & | ||
-6.0516124315132409155D+0, & | ||
2.4733515209909815443D+0, & | ||
-4.6937565143754629578D-1, & | ||
3.1608910440687221695D-2, & | ||
-2.4630612614645039828D-4 /) | ||
double precision, parameter :: cq(8) = (/ & | ||
1.0000000000000000000D+0, & | ||
-4.5355682121856044935D+0, & | ||
8.1790029773247428573D+0, & | ||
-7.4634190853767468810D+0, & | ||
3.6245392503925290187D+0, & | ||
-8.9936784740041174897D-1, & | ||
9.8554565816757007266D-2, & | ||
-3.2116618742475189569D-3 /) | ||
|
||
! transform to [0, 1/2) | ||
if (x .lt. -1) then | ||
l = log(1 - x) | ||
y = 1/(1 - x) | ||
r = -PI**2/6 + l*(0.5D0*l - log(-x)) | ||
s = 1 | ||
elseif (x .eq. -1) then | ||
dli2 = -PI**2/12 | ||
return | ||
elseif (x .lt. 0) then | ||
y = x/(x - 1) | ||
r = -0.5D0*log(1 - x)**2 | ||
s = -1 | ||
elseif (x .eq. 0) then | ||
dli2 = 0 | ||
return | ||
elseif (x .lt. 0.5D0) then | ||
y = x | ||
r = 0 | ||
s = 1 | ||
elseif (x .lt. 1) then | ||
y = 1 - x | ||
r = PI**2/6 - log(x)*log(1 - x) | ||
s = -1 | ||
elseif (x .eq. 1) then | ||
dli2 = PI**2/6 | ||
return | ||
elseif (x .lt. 2) then | ||
l = log(x) | ||
y = 1 - 1/x | ||
r = PI**2/6 - l*(log(1 - 1/x) + 0.5D0*l) | ||
s = 1 | ||
else | ||
y = 1/x | ||
r = PI**2/3 - 0.5D0*log(x)**2 | ||
s = -1 | ||
endif | ||
|
||
z = y - 0.25D0 | ||
|
||
p = dhorner(z, cp, 8) | ||
q = dhorner(z, cq, 8) | ||
|
||
dli2 = r + s*y*p/q | ||
|
||
end function dli2 | ||
|
||
|
||
!********************************************************************* | ||
!> @brief Complex dilogarithm \f$\mathrm{Li}_2(z)\f$ | ||
!> @param z complex argument | ||
!> @return \f$\mathrm{Li}_2(z)\f$ | ||
!> @note Implementation translated from SPheno by Alexander Voigt | ||
!********************************************************************* | ||
|
||
double complex function cdli2(z) | ||
implicit none | ||
double complex :: z, cy, cz, cz2, cz4, sum, fast_cdlog | ||
double precision :: rz, iz, nz, sgn, dli2 | ||
double precision, parameter :: PI = 3.14159265358979324D0 | ||
double precision, parameter :: bf(10) = (/ & | ||
- 1.0D0/4.0D0, & | ||
+ 1.0D0/36.0D0, & | ||
- 1.0D0/3600.0D0, & | ||
+ 1.0D0/211680.0D0, & | ||
- 1.0D0/10886400.0D0, & | ||
+ 1.0D0/526901760.0D0, & | ||
- 4.0647616451442255D-11, & | ||
+ 8.9216910204564526D-13, & | ||
- 1.9939295860721076D-14, & | ||
+ 4.5189800296199182D-16 /) | ||
|
||
rz = real(z) | ||
iz = aimag(z) | ||
nz = rz**2 + iz**2 | ||
|
||
! special cases | ||
if (iz .eq. 0) then | ||
if (rz .le. 1) cdli2 = dcmplx(dli2(rz), 0) | ||
if (rz .gt. 1) cdli2 = dcmplx(dli2(rz), -PI*log(rz)) | ||
return | ||
elseif (nz .lt. EPSILON(1D0)) then | ||
cdli2 = z | ||
return | ||
endif | ||
|
||
! transformation to |z| < 1, Re(z) <= 0.5 | ||
if (rz .le. 0.5D0) then | ||
if (nz .gt. 1) then | ||
cy = -0.5D0*fast_cdlog(-z)**2 - PI**2/6 | ||
cz = -fast_cdlog(1 - 1/z) | ||
sgn = -1 | ||
else ! nz <= 1 | ||
cy = 0 | ||
cz = -fast_cdlog(1 - z) | ||
sgn = 1 | ||
endif | ||
else ! rz > 0.5D0 | ||
if (nz .le. 2*rz) then | ||
cz = -fast_cdlog(z) | ||
cy = cz*fast_cdlog(1 - z) + PI**2/6 | ||
sgn = -1 | ||
else ! nz > 2*rz | ||
cy = -0.5D0*fast_cdlog(-z)**2 - PI**2/6 | ||
cz = -fast_cdlog(1 - 1/z) | ||
sgn = -1 | ||
endif | ||
endif | ||
|
||
cz2 = cz**2 | ||
cz4 = cz2**2 | ||
sum = & | ||
cz + & | ||
cz2 * (bf(1) + & | ||
cz * (bf(2) + & | ||
cz2 * ( & | ||
bf(3) + & | ||
cz2*bf(4) + & | ||
cz4*(bf(5) + cz2*bf(6)) + & | ||
cz4*cz4*(bf(7) + cz2*bf(8) + cz4*(bf(9) + cz2*bf(10))) & | ||
))); | ||
|
||
cdli2 = sgn*sum + cy | ||
|
||
end function cdli2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
!********************************************************************* | ||
! This file is part of Polylogarithm. | ||
! | ||
! Polylogarithm is licenced under the MIT License. | ||
!********************************************************************* | ||
|
||
|
||
!********************************************************************* | ||
!> @brief Fast implementation of complex logarithm | ||
!> @param z complex argument | ||
!> @return log(z) | ||
!********************************************************************* | ||
double complex function fast_cdlog(z) | ||
implicit none | ||
double complex :: z | ||
double precision :: re, im | ||
|
||
re = real(z) | ||
im = aimag(z) | ||
fast_cdlog = dcmplx(0.5D0*log(re**2 + im**2), datan2(im, re)) | ||
|
||
end function fast_cdlog | ||
|
||
|
||
!********************************************************************* | ||
!> @brief Fast implementation of complex logarithm | ||
!> @param z complex argument | ||
!> @return log(z) | ||
!> @note Points on the branch cut are treated differently from log(z): | ||
!> Points with Im(z) == -0D0 are mapped to Im(z) == 0D0 | ||
!********************************************************************* | ||
double complex function fast_pos_cdlog(z) | ||
implicit none | ||
double complex :: z | ||
double precision :: re, im, arg | ||
|
||
re = real(z) | ||
im = aimag(z) | ||
arg = datan2(im, re) | ||
|
||
if (im .eq. 0 .and. arg .lt. 0) arg = -arg | ||
|
||
fast_pos_cdlog = dcmplx(0.5D0*log(re**2 + im**2), arg) | ||
|
||
end function fast_pos_cdlog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
!********************************************************************* | ||
! This file is part of Polylogarithm. | ||
! | ||
! Polylogarithm is licenced under the MIT License. | ||
!********************************************************************* | ||
|
||
|
||
!********************************************************************* | ||
!> @brief Evaluation of polynomial P(x) with len coefficients c | ||
!> @param x real argument of P | ||
!> @param c coefficients of P(x) | ||
!> @param len number of coefficients | ||
!> @return P(x) | ||
!********************************************************************* | ||
|
||
double precision function dhorner(x, c, len) | ||
implicit none | ||
integer :: len, i | ||
double precision :: x, c(len) | ||
|
||
dhorner = 0 | ||
|
||
do i = len, 1, -1 | ||
dhorner = dhorner*x + c(i) | ||
end do | ||
|
||
end function dhorner |