I wanted the inverse logarithmic intgral, so I typed

InverseFunction[LogIntegral]


and received the expected symbolic answer. But when I try to integrate it or even evaluate it it fails. Is there some way to sweet-talk Mathematica into computing this function?

Edit: I was asked for how it fails, here's an example.

NIntegrate[n/(InverseFunction[LogIntegral][n])^2, {n, 10^7, 10^9}]


yields

NIntegrate::inumr : The integrand (...) has evaluated to non-numerical values for all sampling points in the region with boundaries {{10000000,1000000000}}.

• You haven't explained how evaluation "fails". It just works nicely, e.g. InverseFunction[LogIntegral] yields Root[{-4 + LogIntegral[#1] &, 5.60927669305089035535879233715}]. When integrating one should expect that in general there is no closed form exprssion, however e.g.NIntegrate[InverseFunction[LogIntegra l][x], {x, 2, 10}] yields quite resonably 82.0804. Perhaps you should remember Inverting a function in a certain region Dec 4, 2014 at 18:54
• @Artes: With an NIntegrate::inumr error. I've edited in code. Dec 4, 2014 at 19:17
• In:= f[x_?NumberQ] := y /. FindRoot[LogIntegral[y] == x, {y, 2}]; NIntegrate[n/(f[n])^2, {n, 10^7, 10^9}] Out= 1.249875*10^17 Dec 4, 2014 at 19:24
• @DanielLichtblau: That's not a sensible answer, though. The li^{-1}(x) > x (in fact ~ x log x), so the integral should be less than the integral of 1/x over the same region, which is about 4.6. Dec 4, 2014 at 19:33
• (The true answer should be about 0.01125, or 19 orders of magnitude smaller.) Dec 4, 2014 at 19:34

This seems usable at least for moderately large x. one could use cutoffs and different start values if this is not useful in smaller ranges.

f[x_?NumberQ] :=
y /. FindRoot[LogIntegral[y] == x, {y, x*Log[x]},
WorkingPrecision -> 20, PrecisionGoal -> 12]

Two examples:

f[10^200]

(* Out= 4.6565831394119416907*10^202 *)

NIntegrate[n/(f[n])^2, {n, 10^7, 10^200}, MinRecursion -> 5,
MaxRecursion -> 20]

During evaluation of In:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. >>

(* Out= 0.0519673879642 *)

• Works great, thanks! I tweaked the WorkingPrecision and PrecisionGoal upward and all was good. Dec 4, 2014 at 21:50
• I edited to fix that PrecisionGoal (realized I was specifying it all wrong. It happens.) Dec 4, 2014 at 22:16
• As a minor point, x_?NumericQ would be better than x_?NumberQ so that the function will accept numeric constants such as Pi or E. Dec 4, 2014 at 22:54
• @Charles FWIW, for the particular integral in your question, substituting n = LogIntegral[y] yields this easier to evaluate expression: NIntegrate[LogIntegral[y]/(Log[y] y^2), {y, f[10^7], f[10^9]}], where f is the numeric inverse of LogIntegral in Daniel's answer. Dec 5, 2014 at 21:02

A bit of an aside, but a little variable substitution helps that integral quite a lot.

  f[x_?NumberQ] :=
y /. FindRoot[LogIntegral[y] == x, {y, x*Log[x]},
WorkingPrecision -> 20, PrecisionGoal -> 12]
Log NIntegrate[(10^n/f[10^n])^2 , {n, 7, 200},
MinRecursion -> 5, MaxRecursion -> 20]


0.0519674

(~10x faster w/ no warnings about convergence )