#!/usr/bin/env python3 # job1636-checks.py -- exact per-gap two-class analogue of Holt-Rudd arXiv:1408.6002v1. # # HR Cor. 6.3 (p. 25-26, verified in job #1635): for q prime not dividing g, # sum_j n_{g,j}(qN) = (q-2) * sum_j n_{g,j}(N), # with the driver count q-2 and the boundary term n_{s,j+1}(N) in Cor. 3.2. # The twin tile T_x = {twin slots mod x#} is the two-class object. This script # measures, exactly and with an independent implementation: # A. the lifting identity D(T_q) = (q-2)*D(T_p) for q the next prime (q-2 driver), # B. the per-gap defect C_g = N_g(new) - (q-2)*N_g(old) -- HR Figure 4's # "q-2 remain as driving terms of various lengths", made numerical per gap, # C. candidate identifications of C_g with quantities computable in the OLD tile # (oriented adjacent-pair count A_g, window counts), and # D. the scope of the defect: its support and a cheap bound test |C_g| <= 2*A_g. import json, sys, time from fractions import Fraction PASS, FAIL = [], [] def check(label, ok, detail=""): (PASS if ok else FAIL).append(label) print(("PASS " if ok else "FAIL ") + label + (" " + detail if detail else "")) def sieve_marks(W, primes): comp = bytearray(W) for p in primes: if p < W: comp[0::p] = b"\x01" * len(range(0, W, p)) return comp def twin_slots(W, primes): """slots s mod W with s and s+2 both coprime to W (cyclically).""" comp = sieve_marks(W, primes) return [s for s in range(1, W) if not comp[s] and not comp[(s + 2) % W]] def gaps(slots, W): n = len(slots) return [slots[i + 1] - slots[i] for i in range(n - 1)] + [slots[0] + W - slots[-1]] def hist(word): h = {} for g in word: h[g] = h.get(g, 0) + 1 return h def adj_pair_counts(word): """A_g = # of cyclic consecutive positions i with word[i] + word[i+1] = g.""" n = len(word) a = {} for i in range(n): s = word[i] + word[(i + 1) % n] a[s] = a.get(s, 0) + 1 return a def window_counts(word, gmax, Lcap): """W_g = # of cyclic windows of length 2..Lcap with sum exactly g.""" n = len(word) w2 = word + word w = {} for i in range(n): s = 0 for L in range(Lcap): s += w2[i + L] if L >= 1 and s <= gmax: w[s] = w.get(s, 0) + 1 return w def main(): out = {} LAD = {13: (30030, [2, 3, 5, 7, 11, 13]), 17: (510510, [2, 3, 5, 7, 11, 13, 17]), 19: (9699690, [2, 3, 5, 7, 11, 13, 17, 19])} tile = {} for x in sorted(LAD): W, ps = LAD[x] t0 = time.time() tile[x] = gaps(twin_slots(W, ps), W) print(" [tile T_%d build %.2fs: D=%d gaps]" % (x, time.time() - t0, len(tile[x])), file=sys.stderr) out["D"] = {str(x): len(tile[x]) for x in tile} out["maxgap"] = {str(x): max(tile[x]) for x in tile} folds = [(13, 17, 17), (17, 19, 19)] # ---------------- A. the lifting identity (q-2 driver, total level) ---------------- for (xo, xn, q) in folds: do, dn = len(tile[xo]), len(tile[xn]) check("A: D(T_%d) = %d * D(T_%d) exactly" % (xn, q - 2, xo), dn == (q - 2) * do, "D_new=%d (q-2)*D_old=%d" % (dn, (q - 2) * do)) out["lift_%d_%d" % (xo, xn)] = {"q": q, "q_minus_2": q - 2, "D_old": do, "D_new": dn, "ratio": dn / do} # ---------------- B/C/D. per-gap defect and its identification ---------------- defects = [] for (xo, xn, q) in folds: ho, hn = hist(tile[xo]), hist(tile[xn]) Ao = adj_pair_counts(tile[xo]) Wo = window_counts(tile[xo], max(tile[xo]), 4) rows = [] for g in sorted(set(ho) | set(hn)): no, nn = ho.get(g, 0), hn.get(g, 0) plain = (q - 2) * no c = nn - plain rows.append({"g": g, "N_old": no, "N_new": nn, "plain": plain, "C": c, "A": Ao.get(g, 0), "W2_4": Wo.get(g, 0)}) all_c = {r["g"]: r["C"] for r in rows} sum_c = sum(all_c.values()) nonz = [(r["g"], r["C"]) for r in rows if r["C"] != 0] eq_A = all(r["C"] == r["A"] for r in rows) eq_2A = all(r["C"] == 2 * r["A"] for r in rows) eq_W2 = all(r["C"] == r["W2_4"] for r in rows) bound2A = all(abs(r["C"]) <= 2 * r["A"] for r in rows) maxabs = max((abs(r["C"]), r["g"]) for r in rows) defects.append({"old": xo, "new": xn, "q": q, "rows": rows, "sum_C": sum_c, "n_nonzero": len(nonz), "nonzero": nonz[:24], "C_eq_A": eq_A, "C_eq_2A": eq_2A, "C_eq_W_2_4": eq_W2, "absC_le_2A": bound2A, "max_abs_C": maxabs, "C_at_2q": all_c.get(2 * q, None), "C_at_2": all_c.get(2, None)}) # B: the totals are exact but the per-gap split moves -- "various lengths" check("B: sum_g C_g = 0 at T_%d -> T_%d (total is (q-2)-exact, per-gap is not)" % (xo, xn), sum_c == 0, "sum_C=%d, %d/%d gaps with C != 0" % (sum_c, len(nonz), len(rows))) check("B: no gap scales by (q-2) per-gap at T_%d -> T_%d (the defect is nonempty)" % (xo, xn), len(nonz) > 0, "max |C_g| = %d at g=%d" % maxabs) check("C: C_g equals the old tile's oriented adjacent-pair count A_g (T_%d -> T_%d)" % (xo, xn), eq_A) check("C: C_g equals 2*A_g (T_%d -> T_%d)" % (xo, xn), eq_2A) check("C: C_g equals the old tile's 2..4-window count W_g (T_%d -> T_%d)" % (xo, xn), eq_W2) check("D: |C_g| <= 2*A_g for every g (T_%d -> T_%d)" % (xo, xn), bound2A, "worst (|C|,g)=%s" % (maxabs,)) out["defects"] = defects # the two smallest-gap positions: the twin-tile defect's local shape for d in defects: small = sorted(d["rows"], key=lambda r: r["g"])[:6] print(" [T_%d->T_%d small gaps: " % (d["old"], d["new"]) + ", ".join("g=%d N_old=%d N_new=%d (q-2)N=%d C=%d A=%d" % (r["g"], r["N_old"], r["N_new"], r["plain"], r["C"], r["A"]) for r in small) + "]") # ---------------- E. exact per-gap growth factors r_g = N_new(g)/N_old(g) ---------------- # HR Cor 3.2's driver is (p_{k+1}-j-1) with j the length of the driving sum, so the # two-class analogue should show a DEPENDENCE of r_g on the gap class, not one factor. factor_rows = [] for (xo, xn, q) in folds: ho, hn = hist(tile[xo]), hist(tile[xn]) rows = [] for g in sorted(ho): if ho[g] == 0: continue r = Fraction(hn.get(g, 0), ho[g]) rows.append({"g": g, "N_old": ho[g], "N_new": hn.get(g, 0), "r": str(r), "r_int": int(r) if r.denominator == 1 else None}) by_r = {} for r in rows: by_r.setdefault(str(r["r"]), []).append(r["g"]) # the weighted-mean identity: sum_g N_old(g)*r_g = (q-2)*D_old exactly wsum = sum(Fraction(r["N_old"]) * Fraction(r["r"]) for r in rows) tot = Fraction((q - 2) * len(tile[xo])) r6 = next((r["r"] for r in rows if r["g"] == 6), None) r12 = next((r["r"] for r in rows if r["g"] == 12), None) small_carry_qm4 = [r["g"] for r in rows if r["r"] == str(Fraction(q - 4))] all_le = all(Fraction(r["r"]) <= q - 2 for r in rows) factor_rows.append({"old": xo, "new": xn, "q": q, "rows": rows, "distinct_r": {k: v for k, v in sorted(by_r.items())}, "weighted_sum": str(wsum), "target": str(tot), "r6": r6, "r12": r12, "gaps_with_r_qm4": small_carry_qm4, "all_r_at_most_qm2": all_le}) check("E: sum_g N_old(g)*r_g = (q-2)*D_old exactly (T_%d -> T_%d)" % (xo, xn), wsum == tot, "%s vs %s" % (wsum, tot)) check("E: r_6 = r_12 = q-4 = %d exactly, below the total factor q-2 = %d (T_%d -> T_%d)" % (q - 4, q - 2, xo, xn), r6 == str(Fraction(q - 4)) and r12 == str(Fraction(q - 4)), "r_6=%s r_12=%s" % (r6, r12)) check("E: every r_g <= q-2 (T_%d -> T_%d)" % (xo, xn), all_le, "distinct r: %s" % sorted(by_r.keys())) print(" [T_%d->T_%d r_g by gap: %s]" % (xo, xn, ", ".join("g=%d:r=%s" % (r["g"], r["r"]) for r in rows))) out["per_gap_factors"] = factor_rows # refutation of the #1635-successor guess, recorded explicitly out["successor_guess_refuted"] = {str(d["old"]): {"C_eq_A": d["C_eq_A"], "C_eq_2A": d["C_eq_2A"], "C_eq_W_2_4": d["C_eq_W_2_4"], "absC_le_2A": d["absC_le_2A"]} for d in defects} print("\n%d checks, %d PASS, %d FAIL" % (len(PASS) + len(FAIL), len(PASS), len(FAIL))) print("all_pass=%s" % (len(FAIL) == 0)) json.dump(out, open("job1636-checks.json", "w"), indent=1, default=str) return 0 if __name__ == "__main__": sys.exit(main())