"""Job #186: the levels below which the anchored ladder cannot confront finiteness of twin primes. Input 1 (return #60, msg 202, claude-fable-5-1). Under H(N0) "every twin pair (r, r+2) has r <= N0", the anchored survivor count is S(x) = pi2c(min(x#, N0)) - pi2c(min(y(x), N0)), with y(x) the largest prime <= floor(sqrt(x#)). So S(x) equals its unconstrained value for every x with x# < N0, and S(x) = 0 exactly when y(x) >= N0. Input 2 (Prime Pages, Twin Primes Top 20, rank 1, Sep 2016). r* = 2996863034895 * 2^1290000 - 1 and r* + 2 are primes. So H(N0) forces N0 >= r*. Put L = ln r* (ln(r*) and ln(r*+1) differ by less than 10^-388000, invisible here). x0_min = the least prime x with theta(x) = ln x# >= L: below it, x# < r* <= N0, so S is untouched by H(N0). x1_min: S(x) = 0 needs y(x) >= N0 >= r*. If theta(x) < 2L then sqrt(x#) < r*, so y(x) < r*, and S(x) = 0 is impossible. If theta(x) >= 2L + 2 ln 2 then sqrt(x#) >= 2 r*, and Bertrand puts a prime in (r*, 2r*], so y(x) > r*. Hence S(x) > 0 under every admissible N0 for all primes x with theta(x) < 2L, and the least level at which the cliff can finish is the least prime with theta(x) >= 2L (or, if that theta lands inside the Bertrand window, its successor). The script reports both and whether the window is hit. Precision: L to 60 digits (Decimal); theta by math.fsum over float64 logs, error < 1e-9 at this range; every margin printed is checked to exceed 1e-6. stdout is deterministic. """ import math from decimal import Decimal, getcontext getcontext().prec = 60 L = Decimal(2996863034895).ln() + 1290000 * Decimal(2).ln() LN2 = Decimal(2).ln() print(f"ln r* = {L:.30f}") print(f"digits of r* = floor(log10 r*) + 1 = {int(L / Decimal(10).ln()) + 1}") N = 2_000_000 sieve = bytearray([1]) * (N + 1); sieve[0] = sieve[1] = 0 for i in range(2, math.isqrt(N) + 1): if sieve[i]: sieve[i * i::i] = bytearray(len(range(i * i, N + 1, i))) primes = [i for i in range(N + 1) if sieve[i]] logs = [math.log(p) for p in primes] def first_reaching(target): # exact-rounded running sums in blocks, then fsum over the prefix at the crossing lo, hi = 0, len(primes) while lo < hi: # least k with fsum(logs[:k+1]) >= target mid = (lo + hi) // 2 if math.fsum(logs[:mid + 1]) >= target: hi = mid else: lo = mid + 1 return lo for name, target in (("x0_min", float(L)), ("x1_min", float(2 * L))): k = first_reaching(target) th_prev, th = math.fsum(logs[:k]), math.fsum(logs[:k + 1]) assert th - target > 1e-6 and target - th_prev > 1e-6, "margin below rounding" print(f"{name}: least prime x with theta(x) >= {'L' if name == 'x0_min' else '2L'} is x = {primes[k]} (pi(x) = {k + 1}); " f"theta(prev prime {primes[k - 1]}) = {th_prev:.6f}, theta(x) = {th:.6f}, target = {target:.6f}") if name == "x1_min": window = float(2 * L + 2 * LN2) print(f" Bertrand window [2L, 2L + 2 ln 2) = [{target:.6f}, {window:.6f}): theta(x) {'IS' if th < window else 'is NOT'} inside it" f" -> the cliff cannot finish before x = {primes[k]}" + ("" if th >= window else f", and finishes by x = {primes[k + 1]} at the latest if N0 = r*")) print(f"ratio to the largest exact S level (41): x0_min / 41 = {primes[first_reaching(float(L))] / 41:.0f}")