# Second question on sorting of prime gaps

Let $g_i$ be the $i^{th}$ prime gap $p_{i+1}-p_i.$

If we re-arrange the sequence $(g_{n,i})_{i=1}^n$ so that for any finite $n$ the gaps are arranged from smallest to largest we have a new sequence $(\hat{g}_{n,i})_{i=1}^n.$

For example, for $n = 10,$

$$(g_{10,i})_{i=1}^{10} = 1, 2, 2, 4, 2, 4, 2, 4, 6, 2;$$ $$(\hat{g}_{10,i})_{i=1}^{10} = 1, 2, 2, 2, 2, 2, 4, 4, 4, 6.$$

We can ask about the number of elements of the original sequence which are fixed under the sorting operation. For the example above $g_i = \hat{g}_i$ for $i = 1,2,3,5,8.$

[Digression: Without making any claims, it seems that the gaps fixed by this rearrangement are those which are well-behaved in terms of the PNT, that is, gaps for which $g_n \approx (n+1)\log(n+1)-n\log n.$ So one measure of the jumpiness of the prime gaps would be the degree to which the elements of the original sequence deviate from the (in some sense optimal) rearrangement above.]

If $g(n)$ is the $n$th element of the sequence of the first $n$ gaps, and $\hat{g}(n)$ the corresponding element in the rearranged sequence, we can form

$$S(n) =\sum_{k=1}^n |g(k)-\hat{g(k)}|.$$

Conjecture based on empirical observation:

$$L = \lim_{n\to \infty} \frac{\log S(n)}{\log p(n)} = 1.$$

For $n = 10000,50000,100000,5000000$ the ratios tending toward $L$ are respectively $0.975,0.9816,0.984,0.9906.$

My question is how to prove this (and in particular is it a consequence of the prime number theorem)?

This question does not depend on an answer to an earlier question on the sorting of gaps. I could fill space with my own efforts but the digression above is a merciful synopsis.