#!/usr/bin/env python3 """Standard-library verifier for every recipe in exact_results.json. This independently verifies the exhibited constructions. It separately checks that archived solver metadata is internally consistent; it does not replay or certify an optimizer's lower-bound proof. """ import json,sys from itertools import combinations from collections import Counter def shift(block,v,kind): if kind=="cyclic": return tuple(sorted((x+1)%v for x in block)) f=v-1; return tuple(sorted(f if x==f else (x+1)%(v-1) for x in block)) def develop(base,v,kind): n=v if kind=="cyclic" else v-1; out=set(); cur=tuple(sorted(base)) for _ in range(n): out.add(cur); cur=shift(cur,v,kind) return out def near(x,n,tol=1e-7): return abs(float(x)-n)<=tol def main(path="exact_results.json"): d=json.load(open(path,encoding="utf-8")); failures=0 for e in d["entries"]: v,k,t=e["cell"]; bases=[tuple(b) for b in e["base_blocks"]] bases_ok=all(len(b)==k and len(set(b))==k and tuple(sorted(b))==b and min(b)>=0 and max(b)=v] mult=Counter(q for b in blocks for q in combinations(b,t)) all_t=list(combinations(range(v),t)); unc=[q for q in all_t if mult[q]==0] expected=e["exact_minimum_blocks"] construction_ok=(bases_ok and canonical_ok and distinct_orbits and not malformed and len(blocks)==expected and not unc) cp=e["cp_sat"]; sc=e["scip"] metadata_ok=(cp["status"]=="OPTIMAL" and sc["status"]=="OPTIMAL" and near(cp["objective"],expected) and near(cp["best_bound"],expected) and near(sc["objective"],expected) and near(sc["best_bound"],expected)) prof=Counter(mult[q] for q in all_t) print(f"{e['cell']} {e['group']}: blocks={len(blocks)} expected={expected} uncovered={len(unc)} multiplicity={dict(sorted(prof.items()))} construction={'PASS' if construction_ok else 'FAIL'} recorded_metadata={'CONSISTENT' if metadata_ok else 'INCONSISTENT'}") failures += not (construction_ok and metadata_ok) return 1 if failures else 0 if __name__=="__main__":sys.exit(main(sys.argv[1] if len(sys.argv)>1 else "exact_results.json"))