Predicting maximal gaps in sets of primes

Let $q>r\ge1$ be coprime integers. Let ${\mathbb P}_c$ be an increasing sequence of primes $p$ satisfying two conditions: (i) $p\equiv r$ (mod $q$) and (ii) $p$ starts a prime $k$-tuple of a particular type. Let $\pi_c(x)$ be the number of primes in ${\mathbb P}_c$ not exceeding $x$. We heuristically derive formulas predicting the growth trend of the maximal gap $G_c(x)=p'-p$ between consecutive primes $p,p'\in{\mathbb P}_c$ below $x$. Computations show that a simple trend formula $$G_c(x) \sim {x\over\pi_c(x)}\cdot(\log \pi_c(x) + O_k(1))$$ works well for maximal gaps between initial primes of $k$-tuples with $k\ge2$ (e.g., twin primes, prime triplets, etc.) in residue class $r$ (mod $q$). For $k=1$, however, a more sophisticated formula $$G_c(x) \sim {x\over\pi_c(x)}\cdot\big(\log{\pi_c^2(x)\over x}+O(\log q)\big)$$ gives a better prediction of maximal gap sizes. The latter includes the important special case of maximal gaps between primes ($k=1$, $q=2$). In all of the above cases, the distribution of appropriately rescaled maximal gaps $G_c(x)$ near their respective trend is close to the Gumbel extreme value distribution. Almost all maximal gaps turn out to satisfy the inequality $G_c(x) \lesssim C_k^{-1}\varphi_k(q)\log^{k+1}x$ (an analog of Cramer's conjecture), where $C_k$ is the corresponding Hardy-Littlewood constant, and $\varphi_k(q)$ is an appropriate generalization of Euler's totient function. We conjecture that the number of maximal gaps between primes in ${\mathbb P}_c$ below $x$ is $O_k(\log x)$.


Introduction
A prime gap is the difference between consecutive prime numbers. The sequence of prime gaps behaves quite erratically (see OEIS A001223 [34]). While the prime number theorem tells us that the average gap between primes near x is about log x, the actual gaps near x can be significantly larger or smaller than log x. We call a gap maximal if it is strictly greater than all gaps before it. Large gaps between primes have been studied by many authors; see, e.g., [2,5,6,12,14,27,29,33,38,39].
Let G(x) be the maximal gap between primes not exceeding x: Estimating G(x) is a subtle and delicate problem. Cramér [6] conjectured on probabilistic grounds that G(x) = O(log 2 x), while Shanks [33] heuristically found that G(x) ∼ log 2 x. Granville [15] heuristically argues that for a certain subsequence of maximal gaps we should expect G(x) ∼ M log 2 x, with some positive M ≥ 2e −γ > 1; that is, lim sup x→∞ G(x) log 2 x ≥ 2e −γ . Earlier, we have independently proposed formulas closely related to the Cramér and Shanks conjectures. Wolf [37,38,39] expressed the probable size of maximal gaps G(x) in terms of the prime-counting function π(x): which suggests an analog of Shanks conjecture G(x) ∼ log 2 x − 2 log x log log x + O(log x); see also Cadwell [5]. Extending the problem statement to prime k-tuples, Kourbatov [18,19] empirically tested (for x ≤ 10 15 , k ≤ 7) the following heuristic formula for the probable size of maximal gaps G k (x) between prime k-tuples below x: where a is the expected average gap between the particular prime k-tuples. Similar to (1), formula (2) also suggests an analog of the Shanks conjecture, G k (x) ∼ C log k+1 x, with a negative correction term of size O k (log x) k log log x ; see also [11]. In this paper we study a further generalization of the prime gap growth problem, viz.: What happens to maximal gaps if we only look at primes in a specific residue class mod q?
The new problem statement subsumes, as special cases, maximal prime gaps (k = 1, q = 2) as well as maximal gaps between prime k-tuples (k ≥ 2, q = 2). One of our present goals is to generalize formulas (1) and (2) to gaps between primes in a residue class -and test them in computational experiments. Another goal is to investigate how many maximal gaps should be expected between primes p ≤ x in a residue class, with an additional (optional) condition that p starts a prime constellation of a certain type.

Notation
q, r coprime integers, 1 ≤ r < q p n the n-th prime; {p n } = {2, 3, 5, 7, 11, . . .} P c increasing sequence of primes p such that (i) p ≡ r (mod q) and (ii) p is the least prime in a prime k-tuple of a specific type. Note: P c depends on q, r, k, and on the pattern of the k-tuple. When k = 1, P c is the sequence of all primes p ≡ r (mod q). gcd(m, n) the greatest common divisor of m and n ϕ(q) Euler's totient function (OEIS A000010) ϕ k (q) generalization of Euler's totient function (defined in sect. the maximal gap between primes ≤ x G q,r (x) the maximal gap between primes p = r + nq ≤ x (case k = 1) G c (x) the maximal gap between primes p ∈ P c not exceeding x R c (n) the n-th record (maximal) gap between primes p ∈ P c a c (x) the expected average gap between primes in P c near x (see sect. 2.2) a c (x) the expected average gap between primes in P c below x (see sect. 2.2) T ,T c ,T c trend functions predicting the growth of maximal gaps (see sect. 2.3)

Gap counting functions:
the number of maximal gaps G c with endpoints p ≤ x N q,r (x) the number of maximal gaps G q,r with endpoints p ≤ x (case k = 1) the number of gaps of a given even size d = p ′ − p between successive primes p, Prime counting functions: π(x) the total number of primes p n ≤ x π c (x) the total number of primes p ∈ P c not exceeding x π q,r (x) the total number of primes p = r + nq ≤ x (case k = 1) Notation π q,r (x) is a compact form of the often-used π(x; q, r), and π c (x) is a compact form of π(x; q, r, k).
Quantities with the c subscript may, in general, depend on q, r, k, and on the pattern of the prime k-tuple.
1.2 Definitions: prime k-tuples, gaps, sequence P c Prime k-tuples are clusters of k consecutive primes that have an admissible 1 (repeatable) pattern. In what follows, when we speak of a k-tuple, for certainty we will mean a densest admissible prime k-tuple, with a given k ≤ 7. However, our observations can be extended to other admissible k-tuples, including those with larger k and not necessarily densest ones. The densest k-tuples that exist for a given k may sometimes be called prime constellations or prime k-tuplets.
• Twin primes are pairs of consecutive primes that have the form (p, p + 2). This is the densest admissible pattern of two primes.
• Prime quadruplets are clusters of four consecutive primes of the form (p, p + 2, p + 6, p + 8). This is the densest admissible pattern of four primes.
A gap between prime k-tuples is the distance p ′ − p between the initial primes p and p ′ in two consecutive k-tuples of the same type (i. e., with the same pattern). For example, the gap between twin prime pairs (17,19) and (29,31) is 12: p ′ − p = 29 − 17 = 12.
A maximal gap between prime k-tuples is a gap that is strictly greater than all gaps between preceding k-tuples of the same type. For example, the gap of size 6 between twin primes (5,7) and (11,13) is maximal, while the gap (also of size 6) between twin primes (11,13) and (17,19) is not maximal. Let q > r ≥ 1 be coprime integers. Let P c be an increasing sequence of primes p satisfying two conditions: (i) p ≡ r (mod q) and (ii) p is the least prime in a prime k-tuple of a specific type. Importantly, P c depends on q, r, k, and on the pattern of the k-tuple. When k = 1, P c is the sequence of all primes p ≡ r (mod q). Gaps between primes in P c are defined as differences p ′ − p between successive primes p, p ′ ∈ P c . As before, a gap is maximal if it is strictly greater than all preceding gaps.
Studying maximal gaps between primes in P c is convenient. Indeed, if the modulo q used for defining P c is "not too small", we get plenty of data to study maximal gaps; that is, we get many sequences of maximal gaps corresponding to P c 's with different r for the same q, which allows us to study common properties of these sequences. (One such property is the average number of maximal gaps between primes in P c below x.) By contrast, data on maximal prime gaps are scarce: at present we know only 80 maximal gaps between primes below 2 64 [27]. Even fewer maximal gaps are known between k-tuples of any given type [19]. 1 A prime k-tuple with a given pattern is admissible (repeatable) unless it is prohibited by an elementary divisibility argument. For example, the cluster of five numbers (p, p + 2, p + 4, p + 6, p + 8) is prohibited because one of the numbers is divisible by 5 (and, moreover, at least one of the numbers is divisible by 3); hence all these five numbers cannot simultaneously be prime infinitely often. Likewise, the cluster of three numbers (p, p + 2, p + 4) is prohibited because one of the numbers is divisible by 3; so these three numbers cannot simultaneously be prime infinitely often.

Heuristics and conjectures 2.1 Equidistribution of k-tuples
Everywhere we assume that q > r are coprime positive integers. Let π q,r (x) be the number of primes p ≡ r (mod q) such that p ≤ x. The prime number theorem for arithmetic progressions [9, p. 190] establishes that Furthermore, the generalized Riemann hypothesis (GRH) is equivalent to the statement That is to say, the primes below x are approximately equally distributed among the ϕ(q) "admissible" residue classes modulo q; roughly speaking, the GRH implies that, as x → ∞, the numbers π q,r (x) and ⌊li x/ϕ(q)⌋ almost agree in the left half of their digits. Based on empirical evidence, below we conjecture that a similar phenomenon also occurs for prime k-tuples: in every admissible residue class modulo q, there are infinitely many primes starting an admissible k-tuple of a particular type. Moreover, such primes are distributed approximately equally among all admissible residue classes modulo q. Our conjectures are closely related to the Hardy-Littlewood k-tuple conjecture [17] and the Bateman-Horn conjecture [3].

Counting admissible residue classes
First, consider an example: Which residue classes modulo 4 may contain the lesser prime p in a pair of twin primes (p, p + 2)? Clearly, the residue class 0 mod 4 is prohibited: all numbers in this class are even. The residue class 2 mod 4 is prohibited for the same reason. The remaining residue classes, p ≡ 1 mod 4 and p ≡ 3 mod 4, are not prohibited. We call these two classes admissible. Indeed, each of these two admissible residue classes does contain lesser twin primes -and there are, conjecturally, infinitely many such primes in each admissible class (see OEIS A071695 and A071698).
That is, the residue class r (mod q) is admissible if it is not prohibited (by divisibility considerations) from containing infinitely many primes p starting a prime k-tuple of the given type.
How many residue classes modulo q are admissible for a given prime k-tuple? To count admissible residue classes (mod q), we will need an appropriate generalization of Euler's totient function ϕ(q).

The k-tuple infinitude conjecture
We expect each of the ϕ k (q) admissible residue classes to contain infinitely many primes p starting an admissible prime k-tuple (p, p + ∆ 2 , p + ∆ 3 , . . . , p + ∆ k ). In other words, the corresponding sequence P c is infinite.

The k-tuple equidistribution conjecture
The number of primes p ∈ P c , p ≤ x, is where η < 1, the coefficient C k is the Hardy-Littlewood constant for the particular k-tuple (see Appendix 5.5), and ϕ k (q) is an appropriate generalization of Euler's totient function (defined in sect. 2.1.1).

Remarks.
(i) This conjecture is akin to the GRH statement (4); the latter pertains to the case k = 1.
(ii) The conjecture is compatible with the Bateman-Horn and Hardy-Littlewood k-tuple conjectures but does not follow from them.

Average gap sizes
We define the expected average gaps between primes in P c as follows.
Definition ofã c (x). The expected average gap between primes in P c below x is Definition ofā c (x). The expected average gap between primes in P c near x is In view of the equidistribution conjecture (5), it is easy to see from these definitions that We have the limits (with very slow convergence):

Case of k-tuples: k ≥ 2
Consider a probabilistic example. Suppose that intervals between rare random events are exponentially distributed, with cdf Exp(ξ; α) = 1 − e −ξ/α , where α is the mean interval between events. If our observations of the events continue for x seconds, extreme value theory (EVT) predicts that the most probable maximal interval between events is where Π(x) ≈ x/α is the total count of the events we observed in x seconds. (For details on deriving eq. (11), see e. g. [18, sect. 8].) By analogy with EVT, we define the expected trend functions for maximal gaps as follows.
Definition ofT c (x). The lower trend of maximal gaps between primes in P c is In view of the equidistribution conjecture (5), We also define another trend function,T c (x), that is simpler because it does not use Li k (x).
Definition ofT c (x). The upper trend of maximal gaps between primes in P c is These definitions imply that at the same time, we have the asymptotic equivalence: We have the limits (convergence is quite slow): . We make the following conjectures regarding the behavior of maximal gaps G c (x).
Conjecture on the trend of G c (x). For any sequence P c with k ≥ 2, a positive proportion of maximal gaps G c (x) satisfy the double inequalitỹ and the difference G c (x) −T c (x) changes its sign infinitely often.
Generalized Shanks conjecture for G c (p). Almost all maximal gaps G c (p) satisfy Here G c (p) denotes the maximal gap that ends at the prime p.

Case of primes: k = 1
The EVT-based trend formulas (12), (14) work well for maximal gaps between k-tuples, k ≥ 2. However, when k = 1, the observed sizes of maximal gaps G q,r (x) between primes in residue class r mod q are usually a little less than predicted by the corresponding lower trend formula akin to (12). For example, with k = 1 and q = 2, the most probable values of maximal prime gaps G(x) turn out to be less than the EVT-predicted value x log li x li x less by approximately log x log log x (cf. Cadwell [5, p. 912]). In this respect, primes do not behave like "random darts". Instead, the situation looks as if primes "conspire together" so that each prime p n ≤ x lowers the typical maximal gap G(x) by about p −1 n log x; indeed, we have pn≤x p −1 n ∼ log log x. Below we offer a heuristic explanation of this phenomenon. Let τ q,r (d, x) be the number of gaps of a given even size d = p ′ − p between successive primes p, p ′ ≡ r (mod q), p ′ ≤ x. Empirically, the function τ q,r has the form (cf. [38, p. 5]) where P q (d) is an oscillating factor, and The essential point now is that we can find the unknown functions A q (x) and B q (x) in (22) just by assuming the exponential decay of τ q,r as a function of d and employing the following two conditions (which are true by definition of τ q,r ): (a) the total number of gaps is (b) the total length of gaps is The erratic behavior of the oscillating factor P q (d) presents an obstacle in the calculation of sums (24) and (25). We will assume that, for sufficiently regular functions f (d, x), where s is such that, on average, P q (d) ≈ s; and the summation is for d such that both sides of (26) are non-zero. Extending the summation in (24), (25) to infinity, using (26), and writing 2 d = cj, j ∈ N, we obtain two series expressions: (24) gives us a geometric series 2 In view of (23), in the representation d = cj we must use c = LCM(2, q) = O(q). Accordingly, the factor s in (26) can be naturally defined as s = lim n→∞ 1 n n j=1 P q (cj).

while (25) yields a differentiated geometric series
Thus we have obtained two equations: To solve these equations, we use the approximations e −cAq(x) ≈ 1 and 1 − e −cAq(x) ≈ cA q (x) (which is justified because we expect A q (x) → 0 for large x). In this way we obtain A posteriori we indeed see that A q (x) → 0 as x → ∞. Substituting (29) into (22) we get From (30) we can obtain an approximate formula for G q,r (x). Note that τ q,r (d, x) = 1 when the gap of size d is maximal (and/or a first occurrence); in either of these cases we have d ≈ G q,r (x). So, to get an approximate value of the maximal gap G q,r (x), we solve for d the equation τ q,r (d, x) = 1, or where we skipped P q (d)/s because, on average, P q (d) ≈ s. Taking the log of both sides of (31) we find the solution G q,r (x) expressed directly in terms of π q,r (x): Since π q,r (x) ≈ li x ϕ(q) and log − log x, we can state the following Conjecture on the trend of G q,r (x). The most probable sizes of maximal gaps G q,r (x) are near a trend curve T (q, x): where b = b(q, x) = O(log q) tends to a constant as x → ∞. The difference G q,r (x) − T (q, x) changes its sign infinitely often.
Further, we expect that the width of distribution of the maximal gaps near x is O q (log x), i.e., the width of distribution is on the order of the average gap ϕ(q) log x. (This can be heuristically justified by extreme value theory -and agrees with numerical results of sect. 3.2.) On the other hand, for large x, the trend (33) differs from the line ϕ(q) log 2 x by O q (log x log log x), that is, by much more than the average gap. This suggests natural generalizations of the Cramér and Shanks conjectures: Generalized Cramér conjecture for G q,r (p). Almost all maximal gaps G q,r (p) satisfy Generalized Shanks conjecture for G q,r (p). Almost all maximal gaps G q,r (p) satisfy Conjectures (34) and (35) can be viewed as particular cases of (20), (21) for k = 1. . For x → ∞, we will heuristically argue that if the limit of ℓ exists, then the limit is k + 1. We assume that ℓ(x; q, k) → ℓ * as x → ∞, and the limit ℓ * is independent of q. Let n be a "typical" number of maximal gaps up to x; our assumption lim x→∞ ℓ = ℓ * means that For large n, we can estimate the order of magnitude of the typical n-th maximal gap R c (n) using the generalized Cramér and Shanks conjectures (20), (21): Define ∆R c (n) = R c (n + 1) − R c (n). By formula (37), for large q and large n we have where the mean is taken over all admissible residue classes; see sect. 2.1.1. Combining this with (36) we find On the other hand, heuristically we expect that, on average, two consecutive record gaps should differ by the "local" average gap (7) between primes in P c : Together, equations (38) and (39) imply that Therefore, for large x we should expect (cf. sect. 3.3, 3.4) In particular, for the number N q,r of maximal gaps between primes p ≡ r (mod q) we have Remark. Earlier we gave a semi-empirical formula for the number of maximal prime gaps up to x (i.e., for the special case k = 1, q = 2) which is asymptotically equivalent to (41): In essence, formula (42) tells us that maximal prime gaps occur, on average, about twice as often as records in an i.i.d. random sequence of ⌊li x⌋ terms. Note also the following straightforward generalization of (42) giving a very rough estimate of N q,r (x) in the general case: N q,r (x) ≈ max 0, 2 log li x ϕ(q) [23, eq. 10].
Computation shows that, for the special case of maximal prime gaps G(x), formula (42) works quite well. However, the more general formula (43) usually overestimates N q,r (x). At the same time, the right-hand side of (43) is less than 2 log x. Thus the right-hand sides of (41) as well as (43) overestimate the actual gap counts N q,r (x) in most cases. In section 3.3 we will see an alternative (a posteriori) approximation based on the average number of maximal gaps observed for primes in the interval [x, ex]. Namely, the estimated average number ℓ(x; q, k) of maximal gaps with endpoints in [x, ex] is (see Figs. [6][7][8][9] ℓ(x; q, k) ≈ mean

Numerical results
To test our conjectures of the previous section, we performed extensive computational experiments. We used PARI/GP (see Appendix for code examples) to compute maximal gaps G c between initial primes p = r + nq ∈ P c in densest admissible prime k-tuples, k ≤ 6. We experimented with many different values of q ∈ [4, 10 5 ]. To assemble a complete data set of maximal gaps for a given q, we used all admissible residue classes r (mod q). For additional details of our computational experiments with maximal gaps between primes p = r + nq (i.e., for the case k = 1), see also [23, sect. 3]. Figure 1: Maximal gaps G q,r between primes p = r + nq ≤ x for q = 313, x < 10 12 . Red curve: trend (33), (45); blue curve: EVT-based trend ϕ(q)x li x log li x ϕ(q) ; top line: y = ϕ(q) log 2 p.

The growth trend of maximal gaps
The vast majority of maximal gap sizes G c (x) are indeed observed near the trend curves predicted in section 2.3. Specifically, for maximal gaps G c between primes p = r + nq ∈ P c in k-tuples (k ≥ 2), the gap sizes are mostly within O(ā c ) (that is, within O q (log k x)) of the corresponding trend curves of eqs. (12), (14) derived from extreme value theory. However, for k = 1, the trend eq. (33) gives a better prediction of maximal gaps G q,r . Figures 1-3  • For k = 1 (the case of maximal gaps G q,r between primes p = r + nq) the EVT-based trend curve ϕ(q)x li x log li x ϕ(q) goes too high (Fig. 1, blue curve). Meanwhile, the trend (33) Fig. 1, red curve) satisfactorily predicts gap sizes G q,r (x), with the empirical correction term where the parameter values are close to optimal 3 for q ∈ [10 2 , 10 5 ] and x ∈ [10 7 , 10 12 ].
• For k = 2, approximately half of maximal gaps G c between lesser twin primes p ∈ P c are below the lower trend curveT c (x) of eq. (12), while the other half are above that curve; see Fig. 2.
• For k ≥ 3, more than half of maximal gaps G c are usually above the lower trend curvẽ T c (x) of eq. (12). At the same time, more than half of maximal gaps are usually below the upper trend curveT c (x) of eq. (14); see Fig. 3. Recall that the two trend curvesT c andT c are within kā c from each other as x → ∞; see (17).
As noted by Brent [4], twin primes seem to be more random than primes. We can add that, likewise, maximal gaps G q,r between primes in a residue class seem to be somewhat less random than those for prime k-tuples; primes p ≡ r (mod q) do not go quite as far from each other as we would expect based on extreme value theory. Pintz [30] discusses various other aspects of the "random" and not-so-random behavior of primes. Figure 2: Maximal gaps G c between lesser twin primes p = r + nq ∈ P c below x for q = 313, x < 10 12 , k = 2. Blue curve: trendT c of eq. (12); top line: y = C −1 2 ϕ 2 (q) log 3 p. Figure 3: Maximal gaps G c between prime sextuplets p = r + nq ∈ P c below x for q = 313, x < 10 14 , k = 6. Blue curves: trendsT c andT c of (12), (14); top line: y = C −1 6 ϕ 6 (q) log 7 p.

The distribution of maximal gaps
In section 3.1 we have tested equations that determine the growth trend of maximal gaps between primes in sequences P c . How are maximal gap sizes distributed in the neighborhood of their respective trend? We will perform a rescaling transformation (motivated by extreme value theory): subtract the trend from the actual gap size, and then divide the result by a natural unit, the "local" average gap. This way each maximal gap size is mapped to its rescaled value: Gaps above the trend curve are mapped to positive rescaled values, while gaps below the trend curve are mapped to negative rescaled values.
Case k = 1. For maximal gaps G q,r between primes p ≡ r (mod q), the trend T is given by eqs. (33), (45), (46). The rescaling operation has the form Figure 4 shows histograms of rescaled values w for maximal gaps G q,r between primes p ≡ r (mod q) for q = 16001.
Case k ≥ 2. For maximal gaps G c between prime k-tuples with p = r + nq ∈ P c , we can use the trendT c of eq. (12). Then the rescaling operation has the form whereã c (x) is defined by (6). Figure 5 shows histograms of rescaled valuesh for maximal gaps G c between lesser twin primes p = r + nq ∈ P c for q = 16001, k = 2.
In both Figs. 4 and 5, we easily see that the histograms and fitting distributions are skewed to the right, i.e., the right tail is longer and heavier. Among two-parameter distributions, the Gumbel extreme value distribution is a very good fit; cf. [21]. This was true in all our computational experiments. For all histograms shown in Figs. 4 and 5, the Kolmogorov-Smirnov goodness-of-fit statistic is less than 0.01; in fact, for most of the histograms, the goodness-of-fit statistic is about 0.003.
If we look at three-parameter distributions, then an excellent fit is the Generalized Extreme Value (GEV) distribution, which includes the Gumbel distribution as a special case. The shape parameter in the best-fit GEV distributions is close to zero; note that the Gumbel distribution is a GEV distribution whose shape parameter is exactly zero. So can the Gumbel distribution be the limit law for appropriately rescaled sequences of maximal gaps G q,r (p) and G c (p) as p → ∞? Does such a limiting distribution exist at all? The scale parameter α. For k = 1, we observed that the scale parameter of best-fit Gumbel distributions for w-values (47) was in the range α ∈ [0.7, 1]. The parameter α seems to slowly grow towards 1 as p → ∞; see Fig. 4. For k ≥ 2, the scale parameter of best-fit Gumbel distributions forh-values (48) was usually a little over 1; see Fig. 5. However, if instead of (48) we use the (simpler) rescaling transformation whereā c andT c are defined, respectively, by (7) and (14), then the resulting Gumbel distributions ofh-values will typically have scales α a little below 1. In a similar experiment with random gaps, the scale was also close to 1; see [23, sect. 3.3].

Counting the maximal gaps
We used PARI/GP function findallgaps (see source code in Appendix 5.2) to determine average numbers of maximal gaps G q,r between primes p = r + nq, p ∈ [x, ex], for x = e j , j = 1, 2, . . . , 27. Similar statistics were also gathered for gaps G c . Figures 6-9 show the results of this computation for q = 16001, k ≤ 4. The average number of maximal gaps G c for p ∈ [x, ex] indeed seems to very slowly approach k + 1, as predicted by (40); see sect. 2.4. The graph of mean(N c (ex) − N c (x)) vs. log x for gaps G c between k-tuples is closely approximated by a hyperbola with horizontal asymptote y = k + 1; see Figs. 6-9.

How long do we wait for the next maximal gap?
Let P (n) = A002386(n) and P ′ (n) = A000101(n) be the lower and upper endpoints of the n-th record (maximal) gap R(n) between primes: R(n) = A005250(n) = P ′ (n) − P (n). Consider the distances P (n) − P (n − 1) from one maximal gap to the next. (In statistics, a similar quantity is sometimes called "inter-record times".) In Figure 10 we present a plot of these distances; the figure also shows the corresponding plot for twin primes. As can be seen from Fig. 10, the quantity P (n) − P (n − 1) grows approximately exponentially with n (but not monotonically). Indeed, typical inter-record times are expected to satisfy 4 log(P (n) − P (n − 1)) < log P (n) ∼ n 2 as n → ∞.
(50) Figure 10: Inter-record times P (n) − P (n − 1) for gaps between primes (black) and a similar quantity P c (n) − P c (n − 1) for gaps between twin primes (red). Lines are exponential fits. Values for n < 10 are skipped.
More generally, let P c (n) and P ′ c (n) be the endpoints of the n-th maximal gap R c (n) between primes in sequence P c , where each prime is r (mod q) and starts an admissible prime k-tuple. Then, in accordance with heuristic reasoning of sect. 2.4, for typical interrecord times P c (n) − P c (n − 1) separating the maximal gaps R c (n − 1) and R c (n) we expect to see log(P c (n) − P c (n − 1)) < log P c (n) ∼ n k + 1 as n → ∞.
In the special case k = 2, that is, for maximal gaps between twin primes, the right-hand side of (51) is expected to be n 3 for large n (whereas Fig. 10 suggests the right-hand side 0.38n based on a very limited data set for 10 ≤ n ≤ 75). As we have seen in sect. 3.3, the average number of maximal gaps between k-tuples occurring for primes p ∈ [x, ex] slowly approaches k + 1 from below. For moderate values of x attainable in computation, this average is typically between 1 and k + 1. Accordingly, we see that the right-hand side of (51) yields a prediction ≍ e n/(k+1) that underestimates the typical inter-record times and the primes P c (n). Computations may yield estimates P c (n) − P c (n − 1) < P c (n) ≈ Ce βn , where β ∈ [ 1 k+1 , 1], depending on the range of available data. Remarks. (i) Sample graphs of log P c (n) vs. n can be plotted online at the OEIS website: click graph and scroll to the logarithmic plot for sequences A002386 (k = 1), A113275 (k = 2), A201597 (k = 3), A201599 (k = 3), A229907 (k = 4), A201063 (k = 5), A201074 (k = 5), A200504 (k = 6). In all these graphs, when n is large enough, log P c (n) seems to grow approximately linearly with n. We conjecture that the slope of such a linear approximation slowly decreases, approaching the slope value 1/(k + 1) as n → ∞.
(ii) Recall that for the maximal prime gaps G(x) Shanks [33] conjectured the asymptotic equality G(x) ∼ log 2 x, a strengthened form of Cramér's conjecture. This seems to suggest that (unusually large) maximal gaps g may in fact occur as early as at x ≍ e √ g . On the other hand, Wolf [36,38] conjectured that typically a gap of size d appears for the first time between primes near √ d · e √ d . Combining these observations, we may further observe that exceptionally large maximal gaps exceptionally large gaps g = G(x) > log 2 x (52) are also those which appear for the first time unusually early. Namely, they occur at x roughly by a factor of √ d earlier than the typical first occurrence of a gap d at x ≍ √ d · e √ d . Note that Granville [15, p. 24] suggests that gaps of unusually large size (52) occur infinitely often -and we will even see infinitely many of those exceeding 1.1229 log 2 x. In contrast, Sun [35,Conj. 2.3] made a conjecture implying that exceptions like (52) occur only finitely often, while Firoozbakht's conjecture implies that exceptions (52) never occur for primes p ≥ 11; see [22]. Here we cautiously predict that exceptional gaps of size (52) are only a zero proportion of maximal gaps. This can be viewed as restatement of the generalized Cramér conjectures (20), (34) for the special case k = 1, q = 2 (cf. Appendix 5.4).

Summary
We have extensively studied record (maximal) gaps between prime k-tuples in residue classes (mod q). Our computational experiments described in section 3 took months of computer time. Numerical evidence allows us to arrive at the following conclusions, which are also supported by heuristic reasoning.
In particular, for maximal prime gaps (k = 1, q = 2) the trend equation reduces to • For k ≥ 2, a significant proportion of maximal gaps G c (x) are observed between the trend curves of eqs. (12) and (14), which can be heuristically derived from extreme value theory.
• The Gumbel distribution, after proper rescaling, is a possible limit law for G q,r (p) as well as G c (p). The existence of such a limiting distribution is an open question.
• Almost all maximal gaps G q,r (p) between primes in residue classes mod q seem to satisfy appropriate generalizations of the Cramér and Shanks conjectures (34) and (35): • Similar generalizations (20) and (21) of the Cramér and Shanks conjectures are apparently true for almost all maximal gaps G c (p) between primes in P c : • Exceptionally large gaps G q,r (p) > ϕ(q) log 2 p are extremely rare (see Appendix 5.4).
We conjecture that only a zero proportion of maximal gaps are such exceptions. A similar observation holds for G c (p) violating (20).
• We conjecture that the total number N q,r (x) of maximal gaps G q,r observed up to x is below C log x for some C > 2.
• More generally, the number N c (x) of maximal gaps between primes in P c up to x satisfies the inequality N c (x) < C log x for some C > k + 1, where k is the number of primes in the k-tuple pattern defining the sequence P c .

Notes on distribution fitting
To study distributions of rescaled maximal gaps, we used the distribution-fitting software EasyFit [26]. Data files created with maxgap.gp are easily imported into EasyFit: The above table lists exceptionally large maximal gaps G q,r (p) > ϕ(q) log 2 p. No other maximal gaps with this property were found for p < 10 9 , q ≤ 25000. Three sections of the table correspond to (i) odd q, r; (ii) even q; (iii) even r. (Overlap between sections is due to the fact that ϕ(q) = ϕ(2q) for odd q.) No such large gaps exist for p < 10 10 , q ≤ 1000.

The Hardy-Littlewood constants C k
The Hardy-Littlewood k-tuple conjecture [17] allows one to predict the average frequencies of prime k-tuples near p, as well as the approximate total counts of prime k-tuples below x. Specifically, the Hardy-Littlewood k-tuple constants C k , divided by log k p, give us an estimate of the average frequency of prime k-tuples near p: Frequency of k-tuples ∼ C k log k p .
Accordingly, for π k (x), the total count of k-tuples below x, we have The Hardy-Littlewood constants C k can be defined in terms of infinite products over primes.
In particular, for densest admissible prime k-tuples with k ≤ 7 we have: Forbes [10] gives values of the Hardy-Littlewood constants C k up to k = 24, albeit with fewer significant digits; see also [8, p. 86]. Starting from k = 8, we may often encounter more than one numerical value of C k for a single k. (If there are m different patterns of densest admissible prime k-tuples for the same k, then we have ⌈ m 2 ⌉ different numerical values of C k , depending on the actual pattern of the k-tuple; see [10].)

Integrals Li k (x)
Let k ∈ N and x > 1, and let F k (x) = dx log k x (indefinite integral); Li k (x) = In PARI/GP, an easy way to compute li x is as follows: li(x) = real(-eint1(-log(p))).
The integrals F k (x) and Li k (x) = F k (x) − F k (2) can also be expressed in terms of li x. Integration by parts gives Therefore, (log x + 1) + C, F 4 (x) = 1 3! li x − x log 3 x (log 2 x + log x + 2) + C, (log 3 x + log 2 x + 2 log x + 6) + C, F 6 (x) = 1 5! li x − x log 5 x (log 4 x + log 3 x + 2 log 2 x + 6 log x + 24) + C, and, in general, Using these formulas we can compute Li k (x) for approximating π c (x) (the prime counting function for sequence P c ) in accordance with the k-tuple equidistribution conjecture (5): The values of li x, and hence Li k (x), can be calculated without (numerical) integration. For example, one can use the following rapidly converging series for li x, with n! in the denominator and log n x in the numerator (see [ log n x n · n! for x > 1.