#!/usr/bin/env python3 """0029 structural validation (fast): our combinatorics vs the reference's, and the grid against the reference engine's own recorded values.""" import importlib.util import sys from fractions import Fraction as F from pathlib import Path HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE)) sys.path.insert(0, str(HERE / "repo")) spec = importlib.util.spec_from_file_location("asm0029", HERE / "0029_assembly.py") ASM = importlib.util.module_from_spec(spec) sys.modules["asm0029"] = ASM spec.loader.exec_module(ASM) import pg186_repro_ih as REF ok = True for sig in ASM.SIGNATURES: for count in (39, 40): if ASM.moment_terms(count, sig) != REF.moment_terms(count, sig): ok = False print("MISMATCH moment_terms", sig, count) print("moment_terms identical to the reference's for all 11 signatures x {39,40}:", ok) sq_ours, sq_ref = ASM.square_polynomials(), REF.square_polynomials() same = set(sq_ours) == set(sq_ref) and all( tuple(F(x) for x in sq_ours[s]) == tuple(F(x) for x in sq_ref[s]) for s in sq_ours) print("square polynomials identical to the reference's (%d groups): %s" % (len(sq_ours), same)) # grid vs the values printed by 0029_probe_survival.py (the reference engine's own objects) REF_GRID = {68225: 1.0, 68226: 0.999985342724, 68227: 0.999970685662, 68325: 0.99853533478, 98262: 0.635173685889} REF_SURV = {68225: 0.999992671344, 68226: 0.999978014175, 68227: 0.999963357221, 68325: 0.99852801685, 98262: 0.63516859746} lo, hi = ASM.build_grid(68225) law = ASM.cell_law("trapz", 68225, lo, hi) worst_grid = max(abs(float(lo[j]) - REF_GRID[j]) / REF_GRID[j] for j in REF_GRID) worst_surv = max(abs(float(law[j]) - REF_SURV[j]) / REF_SURV[j] for j in REF_SURV) print("grid vs the reference engine: worst relative deviation %.3g (printed-precision limited)" % worst_grid) print("trapz cell law vs the reference engine's survival: worst relative deviation %.3g" % worst_surv)