#!/usr/bin/env python3 """Check the finite frontier and preserved failed-attempt artifacts. This does not complete or repeat the stopped real-instance solver search. """ import hashlib import importlib.util import json import tempfile from pathlib import Path def module(name,filename): spec=importlib.util.spec_from_file_location(name,Path(__file__).with_name(filename)) m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m);return m ARITH=module('arithmetic758','check-exact-cover758.py') RUP=module('rup758','check-rup758.py') def rejected(function): try:function() except (AssertionError,ValueError,KeyError,FileNotFoundError):return True raise AssertionError('negative control was accepted') def verify(directory): arithmetic=ARITH.check(directory) assert arithmetic['frontier']==4433 and arithmetic['F1']==0 and arithmetic['N']==68 observation=json.loads((directory/'exact-cover758-observation.json').read_text()) assert observation['status']=='unresolved' and observation['stop']=='proof_size_exceeded' assert observation['solver_exit_code']==-15 and observation['raw_solver_statuses']==[] data=b'' for entry in observation['parts']: path=Path(entry['path']);assert path.name==str(path) and not path.is_absolute() part=(directory/path).read_bytes() assert len(part)==entry['bytes'] and hashlib.sha256(part).hexdigest()==entry['sha256'] data+=part assert len(data)==observation['observed_partial_proof_bytes']==8252732 assert hashlib.sha256(data).hexdigest()==observation['partial_proof_sha256'] assert len(data)>observation['proof_limit_bytes']==4000000 output=(directory/'exact-cover758-solver.out').read_text() assert not any(line.startswith('s ') for line in output.splitlines()) assert 'SIGTERM' in output and 'c exit 0' in output fixture=RUP.verify(directory/'fixture758-unsat.cnf.txt',directory/'fixture758-unsat.lrat.txt') controls=[] with tempfile.TemporaryDirectory() as tmp: temp=Path(tmp) # Isolate controls so the immutable original package remains unchanged. for p in directory.iterdir(): if p.is_file() and (p.name.startswith('fixture758') or p.name in ('exact-cover758.cnf.txt','exact-cover758-input.json')): (temp/p.name).write_bytes(p.read_bytes()) meta=json.loads((temp/'exact-cover758-input.json').read_text()) meta['slots'][0]+=1 (temp/'exact-cover758-input.json').write_text(json.dumps(meta)) assert rejected(lambda:ARITH.check(temp));controls.append('changed physical support rejected') (temp/'exact-cover758-input.json').write_bytes((directory/'exact-cover758-input.json').read_bytes()) n,clauses=ARITH.parse_cnf(temp/'exact-cover758.cnf.txt') # A residue-endpoint change affects a cover literal, preserving DIMACS. clauses[-1][0]=clauses[-1][0]+1 (temp/'exact-cover758.cnf.txt').write_text(f'p cnf {n} {len(clauses)}\n'+''.join(' '.join(map(str,c))+' 0\n' for c in clauses)) assert rejected(lambda:ARITH.check(temp));controls.append('changed endpoint clause rejected') lines=(directory/'fixture758-unsat.lrat.txt').read_text().splitlines() for i,line in enumerate(lines): tok=line.split() if len(tok)>2 and tok[1]!='d': nums=list(map(int,tok[1:]));j=nums.index(0)+1 if j0) for l in c) for c in clauses):valid=True;break assert valid and not all(any(l>0 for l in c) for c in clauses) controls.append('corrupted SAT fixture assignment rejected') return {'arithmetic':arithmetic,'fixture_refutation':fixture,'controls':controls, 'historical_artifact_consistency':'PASS','real_instance_status':'UNRESOLVED', 'partial_proof_bytes':len(data),'partial_proof_is_a_certificate':False} if __name__=='__main__': import argparse a=argparse.ArgumentParser();a.add_argument('directory',type=Path) print(json.dumps(verify(a.parse_args().directory),sort_keys=True))