# Prime gap counts in short intervals

Since it is conjectured that the twin prime count at $n\sim2 C_2\ \frac{n}{\log^2n},$ where $C_2 = \prod_{p\ge 3} \frac{p(p-2)}{(p-1)^2} = 0.66016 18158 \dots,$ it follows that the twin prime count for a given range; ie, in the interval $[a,b]$, the twin prime count will be $\sim2 C_2\left( \frac{b}{\log^2b}- \frac{a}{\log^2a}\right).$

Now, plotting the $\log$ of counts of gaps between adjacent primes: pairs $(p,p+2n),\ n\in \mathbb{N}$ etc. (ie, with no primes inbetween) is clearly linear, with a "tail" of very low counts along the x-axis:

the above plot showing $\log$ counts of pairs $(p,p+2n)$ in the interval $[10^6,2\cdot 10^6],$ plotted with pgTIPS[10^6, 2*10^6] (code below).

Since this tail can be arbitrarily long, depending on the interval chosen, eg pgTIPS[1425172824437000000, 1425172824437000000 + 10^7]:

it seems that the "tail" does not fall within reasonable bounds of this question.

However, it may be noted that a reasonable (under) estimate can be give as to the length of the $\log$ linear count by

$$\log \left(\frac{(a+b)/2}{\log \left((a+b)/2\right)}\right) \log \left(\frac{2 C_2\ b}{\log ^2(b)}-\frac{2 C_2\ a}{\log ^2(a)}\right)$$

and can of course be adjusted to account for the fluctuations in prime gaps $\mod 6:$

With[{a = 10^6, b = 2*10^6}, With[{bb = estLIST[a, b]},
With[{cc = Length@# & /@ bb}, ListLinePlot[Log@Take[#, Min@cc] & /@ bb,
DataRange -> {2, 2 Min@cc}]]]]


The comparison with the above (under) estimate-model, and Cramer's (over) estimate-model (blue) can be seen as follows:

cc={{0,2},{1,3},{3,7},{5,23},{7,89},{13,113},{17,523},{19,887},{21,1129},{33,1327},{35,9551},{43,15683},{51,19609},{71,31397},{85,155921},{95,360653},{111,370261},{113,492113},{117,1349533},{131,1357201},{147,2010733},{153,4652353},{179,17051707},{209,20831323},{219,47326693},{221,122164747},{233,189695659},{247,191912783},{249,387096133},{281,436273009},{287,1294268491},{291,1453168141},{319,2300942549},{335,3842610773},{353,4302407359},{381,10726904659},{383,20678048297},{393,22367084959},{455,25056082087},{463,42652618343},{467,127976334671},{473,182226896239},{485,241160624143},{489,297501075799},{499,303371455241},{513,304599508537},{515,416608695821},{531,461690510011},{533,614487453523},{539,738832927927},{581,1346294310749},{587,1408695493609},{601,1968188556461},{651,2614941710599},{673,7177162611713},{715,13829048559701},{765,19581334192423},{777,42842283925351},{803,90874329411493},{805,171231342420521},{905,218209405436543},{915,1189459969825483},{923,1686994940955803},{1131,1693182318746371},{1183,43841547845541059},{1197,55350776431903243},{1219,80873624627234849},{1223,203986478517455989},{1247,218034721194214273},{1271,305405826521087869},{1327,352521223451364323},{1355,401429925999153707},{1369,418032645936712127},{1441,804212830686677669},{1475,1425172824437699411}};
ccc = With[{c = 0.660161815846869573927812110014}, x /. FindRoot[Log[(2 c x)/Log[x]^2] Log[LogIntegral@x] == #, {x, Sqrt@#}]] & /@ Range[3, 1600];
With[{nn = 1600}, ListPlot[{Sqrt@# & /@ Range@(nn), {#[[1]], Log@#[[2]]} & /@ cc, Log@ccc}, Joined -> True]]


The questions then, are as follows:

a)$\quad$Is the above model likely to be accurate as an esitmate for all but the "tail" as describeld above?

b)$\quad$Should the "tail" be included in short interval estimates, or does that default to Cramer's conjecture (or similar)?

A log-plot added to help clarify scale for x and y-axes as questioned in comments below:

With[{a = 10^6, b = 2*10^6}, With[{bb = pgLIST[a, b]},
With[{cc = Length@# & /@ bb}, ListLogPlot[Take[#, Min@cc] & /@ bb,
Joined -> True, DataRange -> {2, 2 Min@cc}]]]]


essentially identical to first plot (minus tail), where y-axis s number of gaps, and x-axis is gap size $(2,4,6,8,\dots)$ spread across appropriate data range. Blue line is estimate, and jaged line is actual.

Mathematica code:

pGAPS[r1_, r2_] := If[r1 < 3, "start range must be < 2",
With[{bb = Split@PrimeQ@Range[r1, r2]},
With[{cc = If[bb[[1, 1]] == False, bb[[;; ;; 2]], bb[[2 ;; -1 ;; 2]]]},
Most@Rest@(Length@# & /@ cc + 1)]]]

pgLIST[a_, b_, c2_] := With[{const = 0.660161815846869573927812110014},
With[{aa = pGAPS[a, b]},
With[{bb = (Count[aa, #] & /@ Range@Max@aa)},
{Table[Round@Exp[(c2 Log[(2 const b)/Log[b]^2 - (2 const a)/
Log[a]^2] Log[((b + a)/2)/Log[((b + a)/2)]] - gap + 2)/
(Log[((b + )/2)/Log[((b + a)/2)]])],
{gap, 2, Round[Log[(2 const b)/Log[b]^2 - (2 const a)/
Log[a]^2] Log[((b + a)/2)/Log[((b + a)/2)]], 2], 2}],
bb[[#]] & /@ Range[2, Max@aa, 2]}]]]

pgLIST[a_, b_] := pgLIST[a, b, 1]

estLIST[a_, b_] := {#[[2]], Round@Riffle[Riffle[
(#[[1]] Exp[1/(2*1.13)])[[1 ;; -1 ;; 3]],
(#[[1]] Exp[1/(2*1.13)])[[1 ;; -1 ;; 3]]],
(#[[1]] Exp[1.13])[[3 ;; -1 ;; 3]], 3]} &@pgLIST[a, b]

pgTIPS[a_, b_, c2_] := With[{const = 0.660161815846869573927812110014},
With[{aa = pGAPS[10^6, 2*10^6]},Show[ListLogPlot[Transpose@{Range[2,Max@aa,2],
Count[aa, #] & /@ Range[2, Max@aa, 2]}, Joined -> True],
ListLinePlot[{{c2 Log[(2 const b)/Log[b]^2 -
(2 const a)/Log[a]^2] Log[((b + a)/2)/Log[((b + a)/2)]], 0},
{2, c2 Log[(2 const b)/Log[b]^2 - (2 const a)/Log[a]^2]}},
PlotStyle -> ColorData[97, "ColorList"][[2]]], PlotRange -> All]]]

pgTIPS[a_, b_] := pgTIPS[a, b, 1]

• I'm afraid I cannot understand your question at all. For example, what exactly is plotted in the first graph? What is the x-axis? What is on the y-axis? – Lucia Sep 5 '15 at 17:25
• @Lucia The x-axis is the length of the prime gap (eg, 2,4,6,8,etc.), and the y-axis is the log of the number of pairs of that type within the interval gioven. (Basically a log plot, but taking the log direcly allowed me to "cheat" a little in plotting just a straight line for the estimate). I hope that is a bit clearer - if not, feel free to ask again ... – martin Sep 5 '15 at 18:11
• Sorry I don't understand: if you are counting pairs $p$, $p+2n$ both being prime, why are these being compared to the twin prime constant $C_2$? – Lucia Sep 5 '15 at 18:14
• Ok I have no clue what this question is about. I guess others must be able to figure it out. – Lucia Sep 5 '15 at 18:21
• @Lucia - plot added to question to help clarify. – martin Sep 5 '15 at 19:00