"""Premise check for route 143's step (job 4323): which reduced denominators can occur in the band |r|/q < 2/h at all? No FFT, no minorant values: this only enumerates divisors of q = x# against #1927's recorded h grid. Input: results4293.json from #1927 (served file). stdout is the artifact.""" import json, math, sys from itertools import combinations res = json.load(open(sys.argv[1] if len(sys.argv) > 1 else "results4293.json")) def primes(x): return [p for p in range(2, x + 1) if all(p % d for d in range(2, int(p**.5) + 1))] def divisors(ps): ds = [1] for p in ps: ds += [d * p for d in ds] return sorted(ds) out = [] for key in ["11_1", "11_2", "13_1", "13_2", "17_1", "17_2", "19_1", "19_2"]: c = res[key]; x, dim = map(int, key.split("_")); q = c["q"]; ps = primes(x) assert math.prod(ps) == q divs = divisors(ps) hs = [r["h"] for r in c["rows"]] hm = c["summary"]["m"]["h_cert"] if "summary" in c else None i = hs.index(hm) for tag, h in (("h_m", hm), ("h_m+1", hs[i + 1] if i + 1 < len(hs) else None)): if h is None: continue # in-band nonzero r (mod q, |r| < 2q/h) <-> reduced a/d, d | q, gcd(a,d)=1, 0<|a|<2d/h # |a| >= 1 forces d > h/2; count terms per d exactly: phi-like count of a def nterms(d): A = math.ceil(2 * d / h) - 1 # largest |a| with |a| < 2d/h (strict) if A < 1: return 0 pd = [p for p in ps if d % p == 0] cnt = sum(1 for a in range(1, A + 1) if all(a % p for p in pd)) return 2 * cnt band = sum(1 for r in range(1, q) if min(r, q - r) * h < 2 * q) tot = sum(nterms(d) for d in divs) small = [d for d in divs if h / 2 < d <= h] n_le_h = sum(nterms(d) for d in divs if d <= h) qx = q / x n_lt_qx = sum(nterms(d) for d in divs if d < qx) out.append({"x": x, "dim": dim, "q": q, "which": tag, "h": h, "band_terms": band, "band_terms_by_d": tot, "d_le_h_half": [d for d in divs if 1 < d <= h / 2 and nterms(d)], "divisors_in_(h/2,h]": small, "terms_d_le_h": n_le_h, "log_h_over_log_x": round(math.log(h) / math.log(x), 3), "terms_d_lt_q/x": n_lt_qx}) for o in out: print(json.dumps(o))