#!/usr/bin/env python3 # JOB #630 -- is the zone's LAST twin pair always in the onset-free desert? # # zonegap-02-reduction.md section 4 proves the desert (p^2, p'^2) carries no # onset tread (D1: treads are >= 4p+4 apart) and that the total just-onset # contribution to the zone's last delta is exactly one struck integer, p'^2-2 # (D2). It then says [OPEN]: "whether the binding gap's interval always lies # wholly inside (p^2, p'^2) is OPEN". This script settles the sharper version # for the LAST pair: for every prime p <= PLIM, locate the zone's last twin # pair (a_last, a_last+2) below p'^2 and test a_last > p^2, i.e. the tail # p'^2 - a_last < p'^2 - p^2. # # It also re-measures the three piece scales the note's section 2 table quotes # (head mean 0.7229 ln^2 p; tail in ln^2(p'^2) units; Z2 ln^3 family) so the # SAME run corroborates or contradicts the table rather than restating it. # # Exact, deterministic, no randomness. stdout is the artifact. import sys, math PLIM = 1000 def sieve(n): s = bytearray([1]) * (n + 1) s[0] = s[1] = 0 i = 2 while i * i <= n: if s[i]: s[i*i::i] = bytearray(len(s[i*i::i])) i += 1 return s # max next-prime square PR = [p for p in range(2, PLIM + 2) if all(p % q for q in range(2, int(p**0.5) + 1))] # trivially extend to find p' for p = largest prime <= PLIM def primality(n): if n < 2: return False if n % 2 == 0: return n == 2 i = 3 while i * i <= n: if n % i == 0: return False i += 2 return True def nextp(p): q = p + 1 while not primality(q): q += 1 return q plist = [p for p in PR if 3 <= p <= PLIM] maxsq = max(nextp(p) ** 2 for p in plist) S = sieve(maxsq + 2) isP = lambda n: n >= 2 and S[n] == 1 rows = [] for p in plist: pp = nextp(p) top = pp * pp # openers a with p < a and a + 2 < top openers = [a for a in range(p + 1, top - 1) if isP(a) and isP(a + 2)] if not openers: rows.append(dict(p=p, pp=pp, top=top, C=0, empty=True)) continue C = len(openers) a_first, a_last = openers[0], openers[-1] head = a_first - p tail = top - a_last # p'^2 - a_last width = top - p gaps = [openers[i+1] - openers[i] for i in range(C - 1)] Z2 = max(gaps) if gaps else 0 desert_lo = p * p rows.append(dict(p=p, pp=pp, top=top, C=C, empty=False, a_first=a_first, a_last=a_last, head=head, tail=tail, width=width, Z2=Z2, last_in_desert=(a_last > desert_lo), tail_lt_desert=(tail < top - desert_lo), desert_len=top - desert_lo, first_in_desert=(a_first > desert_lo))) N = len(rows) empt = [r for r in rows if r.get("empty")] notdesert = [r for r in rows if not r.get("empty") and not r["last_in_desert"]] print(f"JOB #630 -- last pair vs the onset-free desert, every prime p <= {PLIM}") print(f"levels {N}; empty zones {len(empt)}; last pair NOT in desert: {len(notdesert)}") if notdesert: print(" counterexamples (p, a_last, p^2, p'^2):") for r in notdesert[:20]: print(f" p={r['p']} a_last={r['a_last']} p^2={r['p']**2} p'^2={r['top']}" f" tail={r['tail']} desert_len={r['desert_len']}") print(" >>> the natural extrapolation of section 4 FAILS") else: print(" >>> every zone's last pair lies in the desert (a_last > p^2) on this range") print() print(" p p'^2 C head tail desert_len tail/(ln^2 p'^2) Z2/(ln^3 p) last_in_desert") import statistics tl = [] for r in rows[::max(1, N // 30)]: if r.get("empty"): continue ln2 = math.log(r["top"]) ** 2 ln3 = math.log(r["p"]) ** 3 tl.append(r["tail"] / ln2) print(f" {r['p']:4d} {r['top']:9d} {r['C']:5d} {r['head']:6d} {r['tail']:6d} " f"{r['desert_len']:9d} {r['tail']/ln2:14.4f} {r['Z2']/ln3:12.4f} {r['last_in_desert']}") good = [r for r in rows if not r.get("empty")] heads = [r["head"] / math.log(r["p"]) ** 2 for r in good] tails = [r["tail"] / math.log(r["top"]) ** 2 for r in good] z2s = [r["Z2"] / math.log(r["p"]) ** 3 for r in good] inD = sum(1 for r in good if r["first_in_desert"]) print() print("SUMMARY (exact, deterministic)") print(f" head / ln^2 p : mean {statistics.mean(heads):.4f} max {max(heads):.4f} (note table: mean 0.7229)") print(f" tail / ln^2 p'^2 : mean {statistics.mean(tails):.4f} range [{min(tails):.4f}, {max(tails):.4f}] (note table band 0.58..0.77)") print(f" Z2 / ln^3 p : mean {statistics.mean(z2s):.4f} range [{min(z2s):.4f}, {max(z2s):.4f}] (note table c3 3.43..4.02)") print(f" first pair already in desert: {inD}/{len(good)} levels") print(f" last pair in desert : {len(good) - len(notdesert)}/{len(good)} levels") # tail monotone? report the largest tail/desert_len ratio (how close the tail gets to leaving the desert) worst = max(good, key=lambda r: r["tail"] / r["desert_len"]) print(f" closest approach: tail/desert_len = {worst['tail']/worst['desert_len']:.4f} at p={worst['p']}" f" (tail={worst['tail']}, desert_len={worst['desert_len']})")