repair-20261028T222848Z-check.py

back to table · edit · history · where entries came from · files · download

2904 bytes, as of the version from 2026-10-28 22:35 (current). Recorded here, not run.

"""Independent small-square check for T592, without changing any values.

Run: sage -python repair_check.py (with document-before.json in this directory).
The repair only removes Data properties.digits. This check covers four roots,
not the whole 245-entry table. It imports no code from the table's generator.
Skill manifest: agents/runs/20261028T222848Z-repair-skills/manifest.json.
Local and live skill SHA-256:
28ecbeeccb0c5e5d6eb541b5a5b0f88aec47b154374d909085116d34f5629199
"""
import json
import re
from pathlib import Path
from decimal import Decimal
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.qqbar import AA, QQbar, _init_qqbar
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.real_mpfi import RealIntervalField
from sage.env import SAGE_VERSION

_init_qqbar()
R = PolynomialRing(QQbar, 'z')
z = R.gen()
b = QQbar(2).sqrt() - 1
edges = [(0, 1), (0, 2), (1, 3), (2, 3)]
p = R(0)
for mask in range(16):
    cut = sum(((mask >> u) & 1) != ((mask >> v) & 1) for u, v in edges)
    p += z**mask.bit_count() * b**cut
control = 1 + 4*b*b*z + (4*b*b+2*b**4)*z*z + 4*b*b*z**3 + z**4
assert p == control
roots = sorted(p.roots(), key=lambda item: (item[0].real(), item[0].imag()))
assert len(roots) == 4 and all(mult == 1 for _, mult in roots)


def decimal_bounds(s):
    dec = Decimal(s)
    num, den = dec.as_integer_ratio()
    midpoint = QQ(num) / QQ(den)
    ulp = QQ(10)**dec.as_tuple().exponent
    return midpoint - ulp, midpoint + ulp


def contained(iv, bounds):
    lo, hi = bounds
    return lo <= QQ(iv.lower()) <= QQ(iv.upper()) <= hi

rif = RealIntervalField(560)
assert contained(AA(1).interval(rif), (QQ(0), QQ(2)))
assert not contained(AA(3).interval(rif), (QQ(0), QQ(2)))
d = json.loads((Path(__file__).with_name('document-before.json')).read_text())
widths = []
for j, (root, mult) in enumerate(roots, 1):
    written = d['Numbers']['2']['2'][str(j)]['number']
    real, imag = written.split(' + i * ')
    for component, stored in ((root.real(), real), (root.imag(), imag)):
        interval = component.interval(rif)
        assert interval.absolute_diameter() < QQ(1)/10**150
        assert contained(interval, decimal_bounds(stored)), (j, stored)
        widths.append(QQ(interval.upper()) - QQ(interval.lower()))
    assert root * root.conjugate() == 1
    print('PASS 2,2,%d: both components contained in stored decimal intervals' % j)
print(json.dumps({'table': 'T592', 'sage_version': SAGE_VERSION, 'precision_bits': 560,
                  'roots_checked': 4, 'total_table_roots': 245,
                  'positive_negative_controls': 'passed',
                  'coefficient_control': 'four-cycle polynomial',
                  'max_component_width_lt': '1e-150',
                  'new_values': 0, 'all_sample_checks_passed': True}, indent=2))