#!/usr/bin/env python3 """Independent checker for job #2733 (route 113, basin inheritance). Shares NO code with the producer `basin.py` and uses no numpy. It marks the kill set by byte-slice assignment over the residue classes 0 (mod p) and -tau (mod p) for each prime p | W, then reads the longest killed run out of the resulting bytes with bytes.split. Different algorithm, different data structure, different arithmetic path -- the two agreeing is the check. cover(tau) = length of the longest run of consecutive killed integers. check2733.py facts --out facts.json # recompute the load-bearing values check2733.py verify target.json facts.json # compare, exit 0 iff every claim holds """ import argparse, json, sys, time from basin import primes_upto _CACHE = {} def level(x): if x in _CACHE: return _CACHE[x] ps = primes_upto(x) W = 1 for p in ps: W *= p base = bytearray(W) for p in ps: base[0::p] = b"\x01" * ((W + p - 1) // p) _CACHE[x] = (W, ps, base) return _CACHE[x] def cover(x, tau): """Longest run of consecutive integers killed by class 0 or class -tau, some prime p | W.""" W, ps, base = level(x) b = bytearray(base) for p in ps: s = (-tau) % p if s: b[s::p] = b"\x01" * len(range(s, W, p)) bb = bytes(b) parts = bb.split(b"\x00") best = max(len(v) for v in parts) if bb[-1] == 1: # leading run and trailing run are adjacent through the wrap lead = len(parts[0]) trail = len(parts[-1]) if lead + trail > best: best = lead + trail return best def facts_level13(): W, ps, base = level(13) offs = list(range(0, W, 2)) cov = [cover(13, t) for t in offs] mx = max(cov) argmax = [t for t, c in zip(offs, cov) if c == mx] sym = all(cov[i] == cover(13, (W - offs[i]) % W) for i in range(0, len(offs), 97)) band = lambda thr: sum(1 for c in cov if c >= thr) hist = {} for c in cov: hist[c] = hist.get(c, 0) + 1 return {"W": W, "offsets": len(offs), "max": mx, "argmax_count": len(argmax), "argmax": sorted(argmax), "cover0_plus1": cov[0] + 1, "cover2": cov[offs.index(2)], "symmetry_tau_lt_neg_tau": sym, "band_ge_119": band(119), "band_ge_107": band(107), "band_ge_101": band(101), "hist_top": sorted(hist.items(), key=lambda kv: -kv[0])[:8], "_cov": cov, "_offs": offs} def facts_pair13_17(f13): """One ascending pass over d, accumulating band members -- the producer's own loop shape, but on the checker's arithmetic. Stops at the first d whose band reaches the target.""" W, ps, base = level(13) Wp, psp, basep = level(17) cov = f13["_cov"]; offs = f13["_offs"] mx = f13["max"] kn = Wp // W target = 191 order = sorted(range(len(offs)), key=lambda i: -cov[i]) taus = [offs[i] for i in order] covs = [cov[i] for i in order] seen = 0 tested = 0 best = -1 witness = None min_d = None trace = [] d = 0 while d <= 79: cut = mx - d hi = 0 while hi < len(covs) and covs[hi] >= cut: hi += 1 for j in range(seen, hi): t = taus[j] for k in range(kn): v = cover(17, t + k * W) tested += 1 if v > best: best = v witness = {"tau": t, "k": k, "lift": t + k * W} if hi != seen: trace.append({"d": d, "band_size": hi, "cum_lifts": tested, "best": best}) seen = hi if best >= target: min_d = d break d += 1 tiers = {} for dd in (0, 30, 42, 48): row = next((t for t in trace if t["d"] == dd), None) tiers[str(dd)] = row mut = {} for dd in (0, 48): members = [taus[i] for i in range(len(taus)) if covs[i] >= mx - dd] mut[str(dd)] = max(cover(17, t) for t in members) return {"lifts_per_offset": kn, "target_cover_at_17": target, "smallest_d_reaching_target": min_d, "best_overall": best, "witness": witness, "witness_cover13": next((c for t, c in zip(offs, cov) if t == witness["tau"]), None) if witness else None, "trace": trace, "tiers": tiers, "mutant_k0_only_best": mut} def facts_level17_spot(): return {str(t): cover(17, t) for t in (0, 2, 5582, 11168, 13142)} def facts_probe(a): """Re-verify level-17 band members and their level-19 lifts, independently, shardable by k.""" src = json.load(open(a.taus, encoding="utf-8")) pairs = src["offsets"] W, _, _ = level(17) band_bad = 0 best = -1 best_rec = None n = 0 t0 = time.time() checked_cov = [] for i, (tau, cov17) in enumerate(pairs): if a.verify_band and i % 13 == 0: # sample: re-derive the level-17 cover v17 = cover(17, tau) checked_cov.append([tau, cov17, v17]) if v17 != cov17: band_bad += 1 for k in range(a.k_lo, a.k_hi + 1): v = cover(19, tau + k * W) n += 1 if v > best: best = v best_rec = {"tau": tau, "k": k, "lift": tau + k * W, "cover19": v} if (i + 1) % 100 == 0: sys.stderr.write("probe-check %d/%d offsets %d cands best=%d %.1fs\n" % (i + 1, len(pairs), n, best, time.time() - t0)) sys.stderr.flush() return {"band_offsets": len(pairs), "k_lo": a.k_lo, "k_hi": a.k_hi, "candidates": n, "best_cover19": best, "best_record": best_rec, "band_members_checked": len(checked_cov), "band_value_mismatches": band_bad, "secs": round(time.time() - t0, 1)} def cmd_facts(a): t0 = time.time() f13 = facts_level13() sys.stderr.write("level13 done %.1fs\n" % (time.time() - t0)); sys.stderr.flush() pair = facts_pair13_17(f13) sys.stderr.write("pair13_17 done %.1fs\n" % (time.time() - t0)); sys.stderr.flush() spot = facts_level17_spot() sys.stderr.write("level17 spot done %.1fs\n" % (time.time() - t0)); sys.stderr.flush() probe = facts_probe(a) if a.taus else None doc = {"tool": "check2733.py/1", "level13": {k: v for k, v in f13.items() if not k.startswith("_")}, "pair13_17": pair, "level17_spot": spot, "probe": probe, "secs": round(time.time() - t0, 1)} if a.out: with open(a.out, "w", encoding="utf-8") as f: json.dump(doc, f, indent=1, sort_keys=True) print(json.dumps(doc, indent=1, sort_keys=True)) return 0 def get(d, path): cur = d for part in path.split("."): if cur is None: return None if isinstance(cur, list): cur = cur[int(part)] else: cur = cur.get(part) return cur def cmd_verify(a): target = json.load(open(a.target, encoding="utf-8")) facts = json.load(open(a.facts, encoding="utf-8")) npass = nfail = 0 for claim in target["claims"]: got = get(facts, claim["path"]) ok = (got == claim["value"]) print("%-4s %-52s expected=%s got=%s" % ("PASS" if ok else "FAIL", claim["path"], json.dumps(claim["value"]), json.dumps(got))) npass += ok nfail += (not ok) print("\n%d PASS, %d FAIL" % (npass, nfail)) print("VERDICT %s" % ("pass" if nfail == 0 else "fail")) return 0 if nfail == 0 else 2 def main(): ap = argparse.ArgumentParser() sub = ap.add_subparsers(dest="cmd", required=True) f = sub.add_parser("facts") f.add_argument("--out") f.add_argument("--taus") f.add_argument("--k-lo", dest="k_lo", type=int, default=0) f.add_argument("--k-hi", dest="k_hi", type=int, default=18) f.add_argument("--verify-band", dest="verify_band", action="store_true") f.set_defaults(func=cmd_facts) v = sub.add_parser("verify") v.add_argument("target") v.add_argument("facts") v.set_defaults(func=cmd_verify) a = ap.parse_args() return a.func(a) if __name__ == "__main__": sys.exit(main())