# Frequency of gaps between consecutive prime numbers

This plot, from Odlyzko, Rubinstein & Wolf, 1999, shows the frequency of the gaps between consecutive primes of a given size. Where $$N(x,d)$$ is the number of primes $$p \leq x$$ such that $$p+2d$$ is the smallest prime $$> p$$.

My question is what happens to the plot as $$x \to \infty$$? In particular, does the gradient of the plot approach a specific value? What about $$\frac{N(x,d)}{\pi(x)}$$ ?

This explanation is provided in the paper:

Figure 1 Log plot of $$\log {N(x,d)}$$, the number of jumps of length $$2d$$ between primes up to $$x$$, for $$x = 2^{20}, 2^{22}, \ldots, 2^{44}$$. Integrating (2-8) by parts and taking logarithms we see that, for fixed $$x$$, the graph should follow a straight line with small perturbations of size $$\log{A_{d,1}}$$ (see text); this can be seen in the figure.

Where (2-8) is the approximation: $$N(d,x) \sim A_{d,1} \int_2^x \frac{\exp{(-2d / \log t )}}{\log^2{t}} dt .$$

I am having difficulty performing the integration

\begin{align} \int \frac{\exp{(-2d / \log t )}}{\log^2{t}} dt &= \int \frac{t}{2d} \frac{2d\exp{(-2d / \log t )}}{t\log^2{t}} dt \\ &= \int \frac{t}{2d} \frac{d}{dt} \left[ \exp{(-2d / \log t )} \right] dt \\ &= \frac{t}{2d} \exp{(-2d / \log t )} - \int \frac{1}{2d} \left[ \exp{(-2d / \log t )} \right] dt \end{align}

and I don't see how to make progress.

Using the relationship $$e^x=\underset{K\to\infty}{\text{lim}}\left(\sum\limits_{k=0}^K\frac{x^k}{k!}\right)$$ leads to formula (1) below for $$f_d(x)=\int\limits_2^x\frac{e^{-\frac{2 d}{\log (t)}}}{\log ^2(t)}\,dt$$ which seems to converge fairly rapidly. The function $$f_d(x)$$ can also be approximated using the Mathematica $$\text{NIntegrate}$$ function as illustrated in formula (2) below.

$$f_d(x)=\underset{K\to \infty }{\text{lim}}\left(\sum _{k=0}^K \frac{(2 d)^k (\Gamma (-k-1,-\log (x))-\Gamma (-k-1,-\log (2)))}{k!}\right)\tag{1}$$

$$f_d(x)\approx\text{NIntegrate}\left[\frac{e^{-\frac{2 d}{\log (t)}}}{\log ^2(t)},\{t,2,x\}\right]\tag{2}$$

The following figure illustrates formula (1) for $$f_1(x)$$ above in orange overlaid on the blue reference function defined in formula (2) above where formula (1) is evaluated with the upper limit $$K=100$$. Figure (1): Illustration of formulas (1) and (2) for $$f_1(x)$$ in orange and blue respectively.

The following figure illustrates formula (2) for $$f_d(x)$$ for $$d\in \{1,2,3,4,5\}$$ where the blue top curve corresponds to $$f_1(x)$$ and the purple bottom curve corresponds to $$f_5(x)$$. Figure (2): Illustration of formula (2) for $$f_d(x)$$ for $$d\in \{1,2,3,4,5\}$$

Note $$N(x,1)=\pi_2(x)$$ where $$\pi_2(x)$$ counts the number of twin-prime pairs $$(p, p+2)$$ with $$p\le x$$ (see OEIS A071538). Also see Wikipedia: Twin prime and Weisstein, Eric W. "Twin Primes." From MathWorld--A Wolfram Web Resource.