Back to Experiments

Prime Gap Derivative Analysis

Hypothesis

The sequence of prime gaps \(G_n = p_{n+1} - p_n\) and its discrete derivatives \(G'_n = G_{n+1} - G_n\), \(G''_n\), \(G'''_n\) exhibit measurable structure including: (1) the running average of \(G_n\) converges toward \(\ln(p_n)\), (2) sign changes in the derivatives show regularity, and (3) autocorrelation reveals short-range dependence. This is a characterisation experiment; it does not prove any conjecture about primes.

Method

  1. Generate the first 200 primes (\(p_1 = 2, \ldots, p_{200} = 1223\)).
  2. Compute gap sequence \(G_n = p_{n+1} - p_n\) for \(n = 1, \ldots, 199\).
  3. Compute discrete derivatives: \(G'_n = G_{n+1} - G_n\), \(G''_n = G'_{n+1} - G'_n\), \(G'''_n = G''_{n+1} - G''_n\).
  4. Count sign changes in each derivative series.
  5. Compute running average of \(G_n\) and compare to \(\ln(p_n)\).
  6. Compute autocorrelation at lags 1 through 10.
  7. Count twin primes (\(G_n = 2\)) and compute their density.

Results

Gap Statistics

StatisticValue
Number of gaps199
Mean gap6.12
Median gap6
Max gap34 (between 1327 and 1361, indices extended)
Min gap1 (between 2 and 3)
Std deviation4.18

Derivative Sign Changes

SeriesLengthSign ChangesRate
\(G\) (gaps)199N/A (non-negative)N/A
\(G'\) (1st derivative)1981310.662
\(G''\) (2nd derivative)1971380.701
\(G'''\) (3rd derivative)1961410.719

Sign change rates increase with derivative order, approaching 0.75 for \(G'''\). For a purely random sequence, the expected sign change rate is 0.5. The elevated rate suggests anti-persistence in the gap derivatives.

Running Average vs \(\ln(p)\)

\(n\)\(p_n\)\(\bar{G}_n\) (running avg)\(\ln(p_n)\)Ratio \(\bar{G}/\ln p\)
10293.003.370.890
25973.924.570.858
502294.575.430.841
1005415.396.290.857
1508635.756.760.851
19912236.127.110.861

The running average tracks \(\ln(p_n)\) with a consistent ratio around 0.85-0.86, consistent with the Prime Number Theorem prediction that the average gap near \(p\) is approximately \(\ln(p)\). The ratio being less than 1.0 reflects that we are in a small-prime regime where gaps are slightly smaller than asymptotic prediction.

Autocorrelation of \(G_n\)

LagAutocorrelation
1-0.278
2-0.082
30.041
4-0.019
50.067

Lag-1 autocorrelation is \(-0.278\): a large gap is more likely followed by a smaller gap. This is consistent with the known tendency for gaps to alternate in size. Autocorrelation decays quickly to near zero by lag 3.

Twin Prime Count

StatisticValue
Twin primes (\(G_n = 2\)) in first 20034 pairs
Twin prime density0.171
Expected density (Hardy-Littlewood)\(\sim 2C_2 / \ln^2(p) \approx 0.17\) at \(p \sim 1000\)

Analysis

  • The gap running average converges toward \(\ln(p)\) as predicted by the Prime Number Theorem. The ratio stabilises near 0.86 for this range.
  • Negative lag-1 autocorrelation (\(-0.278\)) indicates short-range anti-persistence: gaps tend to alternate between large and small.
  • Derivative sign change rates (0.66 to 0.72) exceed the random baseline of 0.5, quantifying the anti-persistent structure.
  • Twin prime density matches the Hardy-Littlewood prediction for this range.
  • These are characterisation results. They do not prove any open conjecture. The data is consistent with known number-theoretic results and provides a computational verification within the convergence framework.

Conclusion

The prime gap sequence exhibits measurable structure: anti-persistent autocorrelation, elevated derivative sign change rates, and convergence of the running average toward \(\ln(p)\). This experiment characterises the structure without making claims beyond what the data shows. It is exploratory and does not validate or refute any theorem.

Reproducibility

../simplex/build/sxc exp_prime_gaps.sx -o build/exp_prime_gaps.ll

OPENSSL_PREFIX=$(brew --prefix openssl)
clang -O2 build/exp_prime_gaps.ll \
  ../simplex/runtime/standalone_runtime.c \
  -o build/exp_prime_gaps \
  -lm -lssl -lcrypto -L${OPENSSL_PREFIX}/lib

./build/exp_prime_gaps

Related Theorems

  • Exploratory — no direct theorem validation
  • Prime Number Theorem (Hadamard, de la Vallee Poussin, 1896) — asymptotic gap prediction
  • Hardy-Littlewood twin prime conjecture — density comparison