#!/usr/bin/env python3 """Independent check of every load-bearing claim of the route-132 continuation return. Shares no code with the producer. Where the producer used one mechanism, this uses another: claim 1 x_{p,r} = 1/p is feasible for the model's LP relaxation at every R producer: analytic S(n) argument plus highs LP solve here: the model is rebuilt from the definition (no ilp132 import), every row is evaluated by hand at xf, and the LP is re-solved from that rebuilt model claim 2 no linear combination of the model's rows separates xf, slack = (S(n)-1)*sum(lambda) producer: ilp132.encode column indices + Fraction arithmetic here: coefficients keyed by (p, r) tuples, built from the row definitions, and compared against the closed-form expectation claim 3 no rank-1 Chvatal-Gomory rounding in the searched space separates xf, and the space's closest approach is the recorded one producer: enumerated 85,644 cuts, reported the minimum of value - rhs here: the recorded closest cut is rebuilt from its description and its slack is recomputed independently claim 4 the LP decides nothing until ~2/3 of the residues are fixed producer: random cubes fixed by changing column bounds on one model object here: each cube is fixed by ADDING equality rows to a fresh model, and the sampled fractions are compared against the recorded curve as interval statements claim 5 the gate's budget arithmetic: charged = sum over levels of k*cap, closure = any seed proving UNSAT, and a_n_reached = the ladder value of the deepest closed level producer: gate132.py here: recomputed from the level records in the served gate JSON claim 6 the instrument ordering against the cited CDCL baseline is stable at n = 9..11 and not stable at n = 12 producer: analyze-reps.py here: recomputed from the raw repetition rows and the cited runs file Exit 0 iff every claim holds. Prints one JSON document; progress on stderr. """ import glob import json import os import random import sys from fractions import Fraction as F import highspy as hp import numpy as np WORK = os.path.dirname(os.path.abspath(__file__)) # this script lives in the work dir it checks HERE = os.path.dirname(WORK) LOGS = os.path.join(WORK, "logs") def resolve(name, workdir=None): """Find an evidence file. A served copy of this return is flat (every manifest path in one directory), so each file is looked for next to the checker as well as in a logs/ subdirectory.""" cands = [os.path.join(workdir or WORK, name), os.path.join(workdir or WORK, "logs", name), os.path.join(LOGS, name), os.path.join(WORK, name), os.path.join(WORK, "r1422", name), os.path.join(workdir or WORK, "r1422", name)] for c in cands: if os.path.exists(c): return c raise FileNotFoundError(name) A = [1, 1, 5, 11, 29, 41, 65, 107, 149, 203, 257, 347, 527, 545, 617, 707, 869, 965, 1079, 1283, 1397, 1529, 1709] def primes(k): ps, x = [], 2 while len(ps) < k: if all(x % q for q in ps): ps.append(x) x += 1 return ps def rows_from_definition(n, R): """Rebuild the constraint system from its definition: one exactly-one row per prime, one cover row per position. Returns (ps, cover_rows, one_rows, xf) with rows as {(p, r): coeff}.""" ps = primes(n) cover = [] for i in range(R): row = {} for p in ps: for r in {(1 - i) % p, (-1 - i) % p}: row[(p, r)] = 1.0 cover.append(row) one = [{ (p, r): 1.0 for r in range(p)} for p in ps] xf = {(p, r): F(1, p) for p in ps for r in range(p)} return ps, cover, one, xf def main(): res, bad = {}, [] # ---- claim 1 ------------------------------------------------------------------------------- ps, cover, one, xf = rows_from_definition(9, 204) acts = [sum(c * float(xf[k]) for k, c in row.items()) for row in cover] ones = [sum(c * float(xf[k]) for k, c in row.items()) for row in one] S = sum((F(2, p) if p > 2 else F(1, 2)) for p in ps) c1 = {"n": 9, "R": 204, "cover_row_activity_min": round(min(acts), 9), "cover_row_activity_max": round(max(acts), 9), "one_row_activity_min": round(min(ones), 9), "one_row_activity_max": round(max(ones), 9), "S_n_exact": str(S), "S_n_float": round(float(S), 9), "all_cover_rows_strictly_feasible": min(acts) > 1.0, "all_one_rows_exact": min(ones) == max(ones) == 1.0, "activity_equals_S_n": abs(min(acts) - float(S)) < 1e-12 and abs(max(acts) - float(S)) < 1e-12} # an LP re-solved on the rebuilt system, at R well beyond the ladder for (nn, RR) in ((9, 205), (12, 200000)): psn, covn, onen, xfn = rows_from_definition(nn, RR) keys = [(p, r) for p in psn for r in range(p)] idx = {k: j for j, k in enumerate(keys)} h = hp.Highs() h.setOptionValue("output_flag", False) h.addVars(len(keys), np.zeros(len(keys)), np.ones(len(keys))) rlb, rub, idxs, vals, starts = [], [], [], [], [0] for row in list(onen) + list(covn): for k, c in row.items(): idxs.append(idx[k]); vals.append(c) rlb.append(1.0); rub.append(1.0 if row in onen else hp.kHighsInf); starts.append(len(idxs)) h.addRows(len(rlb), np.asarray(rlb), np.asarray(rub), len(idxs), np.asarray(starts, dtype=np.int32), np.asarray(idxs, dtype=np.int32), np.asarray(vals)) h.run() c1["lp_status_n%d_R%d" % (nn, RR)] = str(h.getModelStatus()).split(".")[-1] c1["lp_feasible_n%d_R%d" % (nn, RR)] = str(h.getModelStatus()).split(".")[-1] == "kOptimal" if not (c1["all_cover_rows_strictly_feasible"] and c1["all_one_rows_exact"] and c1["activity_equals_S_n"] and c1["lp_feasible_n9_R205"] and c1["lp_feasible_n12_R200000"]): bad.append("claim1") res["claim1_xf_feasible_at_every_R"] = c1 print("claim1 done: min cover activity %.6f vs S = %.6f" % (min(acts), float(S)), file=sys.stderr) # ---- claim 2 ------------------------------------------------------------------------------- rnd = random.Random(11) c2 = {"checked": 0, "counterexamples": 0, "min_slack": None} for (nn, RR) in ((9, 204), (12, 528)): psn, covn, onen, xfn = rows_from_definition(nn, RR) Sn = sum((F(2, p) if p > 2 else F(1, 2)) for p in psn) for _ in range(40): k = rnd.randint(1, 4) I = rnd.sample(range(RR), k) lam = {i: F(rnd.randint(1, 3), rnd.randint(1, 3)) for i in I} mu = {p: rnd.randint(-1, 1) for p in psn} c = {} for i, li in lam.items(): for key in covn[i]: c[key] = c.get(key, F(0)) + li for p, m in mu.items(): for r in range(p): c[(p, r)] = c.get((p, r), F(0)) + m B = F(sum(lam.values())) + F(sum(mu.values())) val = sum(v * xfn[key] for key, v in c.items()) slack = val - B want = (Sn - 1) * sum(lam.values()) c2["checked"] += 1 if slack != want or val < B: c2["counterexamples"] += 1 c2["min_slack"] = str(slack) if c2["min_slack"] is None else str(min(F(c2["min_slack"]), slack)) if c2["counterexamples"]: bad.append("claim2") res["claim2_combination_identity"] = c2 print("claim2 done: %d combinations, %d counterexamples" % (c2["checked"], c2["counterexamples"]), file=sys.stderr) # ---- claim 3 ------------------------------------------------------------------------------- def cg_cut(c, B): ce = lambda f: -((-f.numerator) // f.denominator) fl = lambda f: f.numerator // f.denominator r = {k: (ce(v) if v >= 0 else fl(v)) for k, v in c.items()} neg = [v for v in c.values() if v < 0] return r, ce(B + sum(-v for v in neg)) - sum(ce(-v) for v in neg) c3 = {} for (nn, RR, recorded) in ((9, 204, "1.331245"), (12, 528, "1.518781")): psn, covn, onen, xfn = rows_from_definition(nn, RR) lam = {0: F(1, 3)} mu = {psn[0]: -1, psn[1]: -1} c = {} for i, li in lam.items(): for key in covn[i]: c[key] = c.get(key, F(0)) + li for p, m in mu.items(): for r in range(p): c[(p, r)] = c.get((p, r), F(0)) + m B = F(sum(lam.values())) + F(sum(mu.values())) coeff, rhs = cg_cut(c, B) value = sum(F(v, p) for (p, r), v in coeff.items() if v != 0) slack = value - rhs # the record states the slack to 6 decimals, so the check is to that many decimals c3["n%d" % nn] = {"value": str(value), "rhs": str(rhs), "slack": str(slack), "slack_float": round(float(slack), 6), "recorded_closest_approach": recorded, "matches_record": round(float(slack), 6) == round(float(recorded), 6), "negative_coefficients_present": any(v < 0 for v in c.values())} if round(float(slack), 6) != round(float(recorded), 6): bad.append("claim3_n%d" % nn) res["claim3_closest_cut_rebuilt"] = c3 print("claim3 done", file=sys.stderr) # ---- claim 4 ------------------------------------------------------------------------------- prod = json.load(open(resolve("cut-search-9-204.json"), encoding="utf-8")) curve = {int(r["depth"]): r["fraction"] for r in prod["C3_root_lp_and_depth"]["depth_curve"]} psn, covn, onen, xfn = rows_from_definition(9, 204) keys = [(p, r) for p in psn for r in range(p)] idx = {k: j for j, k in enumerate(keys)} base_rlb, base_rub, base_i, base_v, base_s = [], [], [], [], [0] for row in list(onen) + list(covn): for k, cc in row.items(): base_i.append(idx[k]); base_v.append(cc) base_rlb.append(1.0); base_rub.append(1.0 if row in onen else hp.kHighsInf) base_s.append(len(base_i)) rnd4 = random.Random(23) c4 = {"design": "each cube fixed by ADDING equality rows (producer changed column bounds instead)", "samples_per_depth": 25, "depth": {}} for d in (2, 4, 6, 7, 8): inf = 0 for _ in range(25): fixed = rnd4.sample(list(psn), d) rlb, rub, idxs, vals, starts = list(base_rlb), list(base_rub), list(base_i), list(base_v), list(base_s) for p in fixed: r = rnd4.randrange(p) idxs.append(idx[(p, r)]); vals.append(1.0) rlb.append(1.0); rub.append(1.0); starts.append(len(idxs)) h = hp.Highs() h.setOptionValue("output_flag", False) h.addVars(len(keys), np.zeros(len(keys)), np.ones(len(keys))) h.addRows(len(rlb), np.asarray(rlb), np.asarray(rub), len(idxs), np.asarray(starts, dtype=np.int32), np.asarray(idxs, dtype=np.int32), np.asarray(vals)) h.run() inf += str(h.getModelStatus()).split(".")[-1] == "kInfeasible" c4["depth"][d] = {"infeasible": inf, "of": 25, "fraction": round(inf / 25, 3), "producer_fraction": curve.get(d)} # interval statements rather than point equality: sampling error is real at 25 samples ok4 = (c4["depth"][2]["infeasible"] == 0 and c4["depth"][4]["infeasible"] <= 5 and c4["depth"][6]["infeasible"] >= 12 and c4["depth"][7]["infeasible"] >= 18 and c4["depth"][8]["infeasible"] == 25) c4["matches_producer_shape"] = ok4 if not ok4: bad.append("claim4") res["claim4_depth_curve_independent_mechanism"] = c4 print("claim4 done: %s" % {d: v["infeasible"] for d, v in c4["depth"].items()}, file=sys.stderr) # ---- claim 5 ------------------------------------------------------------------------------- gate = json.load(open(resolve("gate132.out"), encoding="utf-8")) charged = sum(l["charged_seconds"] for l in gate["levels"]) actual = sum(v.get("sec") or 0.0 for l in gate["levels"] for v in l["verdicts"]) ladder = max((l["n"] for l in gate["levels"] if l["closed"]), default=None) c5 = {"charged_seconds": charged, "budget_seconds": gate["budget_seconds"], "charged_equals_declared": abs(charged - gate["budget_seconds"]) < 1e-6, "actual_seconds": round(actual, 3), "actual_within_charged": actual <= charged + 1e-6, "levels_closed": [l["n"] for l in gate["levels"] if l["closed"]], "closure_matches_a_seed_proving_unsat": all( l["closed"] == any(v["status"] == "kInfeasible" for v in l["verdicts"]) for l in gate["levels"]), "deepest_closed_level": ladder, "ladder_value_at_that_n": A[ladder] if ladder else None, "recorded_a_n_reached": gate.get("a_n_reached"), "a_n_reached_matches": gate.get("a_n_reached") == (A[ladder] if ladder else None), "seeds_per_level": {l["n"]: len(l["seeds"]) for l in gate["levels"]}, "unsat_verdicts": {l["n"]: [v["status"] for v in l["verdicts"]] for l in gate["levels"]}} if not (c5["charged_equals_declared"] and c5["actual_within_charged"] and c5["closure_matches_a_seed_proving_unsat"] and c5["a_n_reached_matches"]): bad.append("claim5") res["claim5_gate_budget_recomputed"] = c5 print("claim5 done: charged %.1f s, actual %.1f s, closed %s" % (charged, actual, c5["levels_closed"]), file=sys.stderr) # ---- claim 6 ------------------------------------------------------------------------------- cited = {} for line in open(resolve("job2806_runs.jsonl"), encoding="utf-8"): line = line.strip() if not line.startswith("{"): continue d = json.loads(line) if d.get("solver") is None and d.get("R") == A[d["n"]] + 1: cited[d["n"]] = d["sec"] meas = {} # only the live sweep files; *.frozen.jsonl snapshots would double-count the same rows for path in sorted(glob.glob(os.path.join(LOGS, "reps-*.jsonl")) + glob.glob(os.path.join(WORK, "reps-*.jsonl")) + glob.glob(os.path.join(WORK, "logs", "reps-*.jsonl"))): if ".frozen." in os.path.basename(path): continue setting = os.path.basename(path)[5:-6] for line in open(path, encoding="utf-8", errors="replace"): line = line.strip() if not line.startswith("{"): continue try: d = json.loads(line) except ValueError: continue if d.get("R") == A[d["n"]] + 1: meas.setdefault((d["n"], setting), []).append((d["seed"], d["sec"], d["nodes"])) c6, unstable, stable = {}, [], [] for n in sorted({n for (n, _) in meas}): ref = cited.get(n) if ref is None: continue secs = [s for k, v in meas.items() if k[0] == n for (_, s, _) in v] c6[n] = {"cited_cdcl_sec": ref, "mip_sec": sorted(round(s, 3) for s in secs), "all_slower": all(s > ref for s in secs), "all_faster": all(s < ref for s in secs), "order_stable": all(s > ref for s in secs) or all(s < ref for s in secs)} (stable if c6[n]["order_stable"] else unstable).append(n) c6 = {"per_n": c6, "n_with_stable_order": stable, "n_with_unstable_order": unstable, "cited_source": "work2818/r1422/job2806_runs.jsonl (default solver block, R = a(n)+1)"} if 12 not in unstable: bad.append("claim6") res["claim6_ordering_stability_recomputed"] = c6 print("claim6 done: stable %s, unstable %s" % (stable, unstable), file=sys.stderr) # ---- cross-check: the SAT side at n = 13 confirms the ladder entry ------------------------ sat = [] for path in sorted(glob.glob(os.path.join(LOGS, "sat-n1*-seed*.jsonl")) + glob.glob(os.path.join(WORK, "sat-n1*-seed*.jsonl"))): for line in open(path, encoding="utf-8", errors="replace"): line = line.strip() if line.startswith("{"): d = json.loads(line) sat.append({"n": d["n"], "R": d["R"], "seed": d["seed"], "status": d["status"], "sec": d["sec"], "witness_ok": d.get("witness_ok"), "ladder_value": A[d["n"]]}) sat.sort(key=lambda d: (d["n"], d["seed"], d["R"])) res["sat_side_runs"] = sat res["sat_side_decisions"] = { "n=13 confirmed (SAT at 545 with a checked witness, UNSAT at 546 from the gate)": any(x["n"] == 13 and x["status"] == "kOptimal" and x["witness_ok"] for x in sat), "n=14 confirmed (SAT at 617 with a checked witness, UNSAT at 618 from the gate)": any(x["n"] == 14 and x["status"] == "kOptimal" and x["witness_ok"] for x in sat)} res["ok"] = not bad res["failed_claims"] = bad print(json.dumps(res, indent=1, sort_keys=True, ensure_ascii=False)) return 0 if not bad else 1 if __name__ == "__main__": sys.exit(main())