File size: 2,172 Bytes
5fe5e69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
"""Certify a supplied illuminating family for a normalized unconditional polytope.
Input JSON keys: positive_rows (rational strings or integers), opposite_pairs.
A failed test is not a proof that no other illuminating family exists.
"""
import argparse,json,sys
from fractions import Fraction
from pathlib import Path
from verify_primary import orthant_vertices,make_certificate

def main():
    ap=argparse.ArgumentParser(description=__doc__);ap.add_argument('input',type=Path);ap.add_argument('--output',type=Path,required=True)
    args=ap.parse_args()
    try:
        obj=json.loads(args.input.read_text());raw=obj['positive_rows'];pairs=obj['opposite_pairs']
        if not raw or not pairs:raise ValueError('Rows and direction pairs must be nonempty.')
        if any(isinstance(x,float) for r in raw for x in r):raise ValueError('Use rational strings, not floating-point coefficients.')
        rows=tuple(tuple(Fraction(x) for x in r) for r in raw);n=len(rows[0])
        if not 2<=n<=8:raise ValueError('Supported dimensions are 2 through 8.')
        if len(rows)>20:raise ValueError('This simple enumerator is limited to 20 positive rows.')
        if any(len(r)!=n or min(r)<0 or max(r)>1 for r in rows):raise ValueError('Rows must be nonnegative, normalized, and equally sized.')
        if any(max(r[i] for r in rows)!=1 for i in range(n)):raise ValueError('Each coordinate must have unit intercept (column maximum one).')
        ds=[tuple(Fraction(x) for x in d) for d in pairs]
        if any(len(d)!=n or not any(d) for d in ds):raise ValueError('Each direction must be nonzero and have the correct dimension.')
        c=make_certificate(obj.get('label',args.input.stem),rows,orthant_vertices(rows),ds,True)
        args.output.parent.mkdir(parents=True,exist_ok=True);args.output.write_text(json.dumps(c,indent=2)+'\n')
        print(f"PASS: {c['direction_count']} directions; closed radius {c['closed_Hausdorff_radius']}; open radius {c['open_Hausdorff_radius']}")
    except (ValueError,KeyError,TypeError,OSError) as e:
        print(f'Certificate not issued: {e}',file=sys.stderr);sys.exit(1)
if __name__=='__main__':main()