Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

My number theory library of choice doesn't implement the logarithmic integral for complex values. I thought that I might take a crack at coding it, but I thought I'd ask here first for algorithmic advice and/or references. I'm sure there are better methods than naively calculating the integral.

share|improve this question

1 Answer 1

up vote 8 down vote accepted

For this answer, I'm assuming the definition

$$\mathrm{li}(z):=\mathrm{PV}\int_0^z\frac{\mathrm{d}u}{\ln\;u}$$

where we assume the Cauchy principal value (the more common definition in number theory that has a lower limit of 2 differs merely by a constant).

Well, the first thing you have to note is the identity

$$\mathrm{li}(z)=\mathrm{Ei}(\ln\;z)$$

where $\mathrm{Ei}(z)$ is an exponential integral. (Again, I repeat my advice to people who encounter strange functions: you would really do well to check the DLMF first for identities and references.)

Now, $\mathrm{Ei}(z)$ is a slightly more tractable beastie to numerically evaluate, since the singularity at $z=0$ can be confined to a logarithmic part; to wit:

$\mathrm{Ei}(z)=\gamma+\ln\;z+\int_0^z \frac{\exp(u)-1}{u}\mathrm{d}u$

where the last portion is an entire function.

Now, depending on which of the left or right half-planes should the exponential integral be evaluated, your strategy will differ (it is a common fact that most special function routines are polyalgorithms, since their behavior can markedly differ in different regions of the complex plane). I will be vague for the rest of this answer since you did not clarify your region of interest. Suffice it to say that one usually uses a continued fraction for arguments in the left half-plane, a power series for small to medium-sized arguments, and asymptotic expansions for large arguments.

If implementing it yourself is starting to sound daunting (because it is), I will have to point out this paper and the corresponding FORTRAN subroutine.

Hope this helps a bit.

share|improve this answer
    
Excellent answer, very complete! Yes, I expected to be evaluating Ei, that's how the library handles Li now (though again, only for real arguments). –  Charles Nov 4 '10 at 12:49
    
@Charles: For estimating the prime-counting function, you don't need it for complex arguments; for evaluating the Riemann function, maybe... if you don't mind my asking, what exactly do you want to do with the logarithmic integral? An especially-tailored solution might be better than this general one I gave, certainly if speed is of the essence (Evaluating special functions at complex arguments is always expensive). –  J. M. Nov 4 '10 at 13:44
    
@J. M.: I want to add it to a library (Pari), so covering all possible ranges is important. My immediate need is relatively unimportant -- just some exploratory work with Riemann's explicit formula. Since this (if successful) will be part of a library, speed is important. –  Charles Nov 4 '10 at 14:10
    
@Charles: in that case, may I suggest that you maintain separate routines for the real argument and complex argument cases, and have a top-level routine that will call whichever of the two is appropriate. The routine by Donald Amos serves well in the complex case, and as for the real case, there are a number of submissions to ACM's Transactions on Mathematical Software to do that job. –  J. M. Nov 4 '10 at 14:15
1  
I forgot to add: for medium sized (real or complex) arguments, I have found from a few numerical experiments that formula 15 in here, due to Ramanujan, might have a slight edge over the usual Maclaurin series. You will have to of course check with your environment to be certain. –  J. M. Nov 4 '10 at 14:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.