File size: 1,546 Bytes
33e9f46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
"""Check exported rational certificates without invoking the compiler."""
import json
from pathlib import Path
import sympy as sp
from src.continuation import ExteriorCertificate, Ratio

ROOT = Path(__file__).resolve().parent

def matrix(rows):
    return sp.Matrix([[sp.Rational(value) for value in row] for row in rows])

def ratio(record):
    return Ratio(matrix(record['beta']), matrix(record['alpha']), tuple(record['word']))

def main() -> None:
    records = json.loads((ROOT/'results'/'exact_certificates.json').read_text())
    for record in records:
        n = int(record['n'])
        seeds = tuple(ratio(row) for row in record['seeds'])
        ratios = [ratio(row) for row in record['ratios']]
        branches = (matrix(record['A']), matrix(record['B']))
        cert = ExteriorCertificate(
            normalizer=matrix(record['normalizer']),
            readouts=tuple(seed.numerator for seed in seeds), seeds=seeds,
            branches=branches, ratios=ratios, R=matrix(record['R']),
            transports=[matrix(H) for H in record['H']],
            depth=max((len(r.word) for r in ratios), default=0))
        if not cert.verify():
            raise AssertionError(f'Failed certificate at n={n}')
        if cert.normalizer*(branches[0]+branches[1]) != cert.normalizer:
            raise AssertionError(f'Failed instrument normalization at n={n}')
        print(f'n={n}: seed coverage, provenance, row integrity, positivity, '
              'transport, and normalization all pass.')

if __name__ == '__main__':
    main()