#!/usr/bin/env python3 """Small independent checker for the positive-hint RUP subset of textual LRAT. This deliberately rejects RAT steps. It is sufficient only when it accepts an entire refutation, and has no claim to support arbitrary LRAT certificates. """ import argparse from pathlib import Path import importlib.util _spec=importlib.util.spec_from_file_location('arithmetic758',Path(__file__).with_name('check-exact-cover758.py')) _mod=importlib.util.module_from_spec(_spec);_spec.loader.exec_module(_mod) parse_cnf=_mod.parse_cnf def verify(cnf, proof): n,initial=parse_cnf(cnf) database={i+1:tuple(c) for i,c in enumerate(initial)} largest=len(initial);steps=0;empty=False for line in proof.read_text().splitlines(): if not line.strip() or line.startswith('c'):continue tok=line.split();assert len(tok)>=3 index=int(tok[0]);assert index>=0 if tok[1]=='d': ids=list(map(int,tok[2:]));assert ids and ids[-1]==0 and 0 not in ids[:-1] for i in ids[:-1]: assert i>0 and i in database del database[i] continue nums=list(map(int,tok[1:]));zero=nums.index(0) clause=tuple(nums[:zero]);hints=nums[zero+1:] assert hints and hints[-1]==0 and 0 not in hints[:-1] assert index>largest and all(00 and h in database for h in hints[:-1]),'unsupported RAT or missing hint' assignment={};conflict=False # Negating a tautology already gives a conflict and is sound. for lit in clause: var=abs(lit);value=lit<0 if var in assignment and assignment[var]!=value:conflict=True assignment[var]=value for h in hints[:-1]: if conflict:break pending=[];satisfied=False for lit in database[h]: if abs(lit) not in assignment:pending.append(lit) elif assignment[abs(lit)]==(lit>0):satisfied=True;break assert not satisfied,'hint clause is already satisfied' pending=list(dict.fromkeys(pending)) assert len(pending)<=1,'hint is not unit or conflicting' if not pending:conflict=True else:assignment[abs(pending[0])]=pending[0]>0 assert conflict,'addition lacks a unit-propagation contradiction' database[index]=clause;largest=index;steps+=1 if not clause:empty=True assert empty,'no checked empty clause' return {'proof':'PASS','checked_additions':steps,'format':'textual LRAT positive-hint RUP subset'} if __name__=='__main__': import importlib.util,json # The arithmetic checker has a portable hyphenated publication name. a=argparse.ArgumentParser();a.add_argument('cnf',type=Path);a.add_argument('proof',type=Path) args=a.parse_args();print(json.dumps(verify(args.cnf,args.proof),sort_keys=True))