5
$\begingroup$

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.

1 Answers 1

10

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.

  • 0
    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).2010-11-04
  • 0
    @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).2010-11-04
  • 0
    @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.2010-11-04
  • 0
    @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.2010-11-04
  • 0
    Another note: it is extremely rare that a general routine for a special function will be fast, most certainly if you are aiming for arbitrary precision evaluation like in PARI/GP. I believe this is not one of the things that can be computed very fast (relative to, say, evaluating a logarithm or an exponential).2010-11-04
  • 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](http://mathworld.wolfram.com/LogarithmicIntegral.html), 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.2010-11-04
  • 0
    Thank you, you have been extremely helpful. Yes, I will keep the complex case separate; the real case is already written and fairly efficient. (Mine will not be as good.) I will look into the Ramanujan formula you mention; medium-sized arguments are of special interest.2010-11-04