"""Independent set-of-tuples certificate checker; does not import the producer.""" import json,time,itertools,sys from pathlib import Path sys.setrecursionlimit(5000) class Invalid(Exception):pass def demand(condition,message): if not condition:raise Invalid(message) def verify(proof,cpu_limit=18): started=time.process_time();slots=proof['slots'];qs=proof['Q'];nodes=proof['nodes'];seen=set() demand(len(slots)==len(set(slots)) and len(qs)==len(set(qs)),'duplicate input') blocks={i:{i} for i in range(len(slots))} domains={i:{(q,(-s)%q) for q in qs}|{(q,(-s-2)%q) for q in qs} for i,s in enumerate(slots)} edges={i:set() for i in blocks} def forced(d,e): for a,b in itertools.combinations(sorted(d),2): if not(d[a]&d[b]):e[a].add(b);e[b].add(a) forced(domains,edges) def compatible(a,x,b,y,e):return x[0]!=y[0] or (b not in e[a] and x==y) def visit(index,bl,d,e): demand(time.process_time()-started0 and mask>>q==0,'deletion schema') removed={(q,b) for b in range(q) if mask>>b&1} demand(removed<=d[a],'deleting absent value') for x in removed: demand(any(not any(compatible(a,x,b,y,e) for y in d[b]) for b in d if b!=a),'unsupported deletion') d[a]-=removed if tag=='e':demand(row[1] in d and not d[row[1]],'false empty leaf');return demand(all(d.values()),'missed empty domain') # This direct quantification is deliberately different from the # producer's single-prime bit-mask simplification. for a in d: demand(time.process_time()-startedlen(qs),'false cardinality leaf') else:demand(len({q for a in W for q,b in d[a]})