"""Verify every rational resource box in the deterministic algorithm.""" from argparse import ArgumentParser from concurrent.futures import ProcessPoolExecutor, as_completed from fractions import Fraction from os import cpu_count import certify_space as certificate def check_row(index): mode = certificate.MODES[index] endpoints = [mode.left, mode.right] if not mode.mixed and mode.left < certificate.LOCAL_T < mode.right: endpoints.insert(1, certificate.LOCAL_T) checks = [ certificate.certify(mode, left, right) for left, right in zip(endpoints, endpoints[1:]) ] return mode.name, sum(count for count, _ in checks), max(depth for _, depth in checks) def main(): parser = ArgumentParser(description=__doc__) parser.add_argument("--workers", type=int, default=min(4, cpu_count() or 1)) parser.add_argument("--verbose", action="store_true") args = parser.parse_args() if not __debug__: parser.error("Assertions must be enabled.") if args.workers < 1: parser.error("--workers must be positive.") certificate.structural_checks() assert certificate.Q / 3 == Fraction(18103, 100000) assert (0 < certificate.X < certificate.MIX_END < certificate.HIGH_EDGE < certificate.EDGE < certificate.TOP_T < certificate.TAIL_MAX) counts = {} indices = range(len(certificate.MODES)) with ProcessPoolExecutor(max_workers=args.workers) as pool: pending = {pool.submit(check_row, i): i for i in indices} for result in as_completed(pending): index = pending[result] name, intervals, depth = result.result() boxes, subtotal, max_depth = counts.get(name, (0, 0, 0)) counts[name] = boxes + 1, subtotal + intervals, max(max_depth, depth) if args.verbose: print(f"row {index} {name}: {intervals} intervals at depth {depth}", flush=True) assert sum(boxes for boxes, _, _ in counts.values()) == len(certificate.MODES) for name, (boxes, intervals, depth) in sorted(counts.items()): print(f"{name}: {boxes} policy rows, {intervals} terminal boxes, depth {depth}") print(f"Verified time exponent 1/2 and writable-space exponent {certificate.Q / 3}.") if __name__ == "__main__": main()