#!/usr/bin/env python3 """Does the float cutoff ever move the BAND? (band.py showed E1 moves from j=54.) Tmax = floor((x-2)/(elo+1)) is the only way E1 reaches the band, and it is a small integer, so an ulp-level error in E1 need not move it. This decides whether corner-measurement.md section 5's unchecked float limitation has any operational consequence, and over what range of j. """ import math import bisect from band import band, primes_upto, floor_two_pow, Z_EXP, E1_EXP from fractions import Fraction # The sieve must cover Tmax at the largest j checked, or the two band lists below are # BOTH truncated at the sieve limit, compare equal, and the check silently passes on a # range it never examined. Guarded explicitly rather than chosen by eye. JMAX = 300 PR = primes_upto(4 * 10 ** 6) print("# Tmax and band: exact vs the script's float arithmetic") first_T, first_band, checked = None, None, 0 rows = [] for j in range(20, JMAX + 1): e, f = band(j, exact=True), band(j, exact=False) assert max(e["Tmax"], f["Tmax"]) <= PR[-1], ( f"sieve limit {PR[-1]} below Tmax {max(e['Tmax'], f['Tmax'])} at j={j}: " "the comparison would be vacuous") # index pairs into PR, not materialised lists: equal (lo, hi) means identical # contents, and this is ~500x cheaper than rescanning the prime list per j be = (bisect.bisect_right(PR, e["Z"]), bisect.bisect_right(PR, e["Tmax"])) bf = (bisect.bisect_right(PR, f["Z"]), bisect.bisect_right(PR, f["Tmax"])) checked += 1 if e["Tmax"] != f["Tmax"] and first_T is None: first_T = j if be != bf and first_band is None: first_band = j if e["Tmax"] != f["Tmax"]: rows.append((j, e["Tmax"], f["Tmax"], be[1] - be[0], bf[1] - bf[0])) print(f" j = 20..300 checked ({checked} values)") print(f" first j where Tmax differs : {first_T}") print(f" first j where the BAND differs: {first_band}") for j, te, tf, ne, nf in rows[:12]: print(f" j={j}: Tmax exact={te} float={tf} | #band exact={ne} float={nf}") print("\n# Sanity: band contents over the measured range, against the note's section 3") def _n(j): b = band(j) return bisect.bisect_right(PR, b['Tmax']) - bisect.bisect_right(PR, b['Z']) emp = [j for j in range(20, 37) if _n(j) == 0] mx = max(_n(j) for j in range(20, 37)) print(f" j=20..36: empty at {emp}; max band size = {mx}") print(f" note section 3 states: 'at most one prime', 'empty at j=20,21,22,32,33'")