repair-dimension-checks-20261025.py

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

4532 bytes, as of the version from 2026-10-25 05:57 (current). Recorded here, not run.

"""Check the dimensional qualification and source values for numberdb.org/T474.

Run with Python 3 or SageMath:
    python3 repair_checks.py
    sage -python repair_checks.py

With T474-before.json, critical-couplings-live.json and chang.html beside
this file, checks use those snapshots. Otherwise, pipe a NumberDB API key
on stdin to check the live draft and fetch the public paper. The key is
used only for the NumberDB API. No bootstrap computation is reproduced.
The universality statement is source-checked in Hasenbusch, sections I-II,
https://arxiv.org/html/1711.10946; a numerical check cannot prove it.
"""
from fractions import Fraction
from html.parser import HTMLParser
from itertools import combinations_with_replacement
from pathlib import Path
import json
import re
import sys
import urllib.request

class Cells(HTMLParser):
    def __init__(self):
        super().__init__()
        self.cells = {}
        self.current = None
    def handle_starttag(self, tag, attrs):
        if tag == 'td':
            self.current = dict(attrs).get('id')
            if self.current:
                self.cells[self.current] = ''
    def handle_endtag(self, tag):
        if tag == 'td':
            self.current = None
    def handle_data(self, text):
        if self.current:
            self.cells[self.current] += text

def parenthesized(text):
    match = re.fullmatch(r'(\d+\.\d+)\((\d+)\)', text.strip())
    assert match, text
    centre, radius = match.groups()
    return Fraction(centre), Fraction(int(radius), 10 ** len(centre.split('.')[1]))

def stored(text):
    return tuple(Fraction(t.strip()) for t in text.split('+/-'))

def main():
    root = Path(__file__).resolve().parent
    if (root / 'T474-before.json').exists():
        table = json.loads((root / 'T474-before.json').read_text())
        lattices = json.loads((root / 'critical-couplings-live.json').read_text())
        paper = (root / 'chang.html').read_text()
        mode = 'saved snapshots'
    else:
        key = sys.stdin.read().strip()
        assert key, 'Pipe the draft reader API key on stdin.'
        def read_api(identifier):
            url = 'https://numberdb.org/api/table?id=' + identifier
            request = urllib.request.Request(url, headers={'Authorization': 'Bearer ' + key})
            with urllib.request.urlopen(request, timeout=60) as response:
                return json.load(response)
        table = read_api('T474')
        lattices = read_api('Critical_couplings_of_the_Ising_model_on_lattices')
        with urllib.request.urlopen('https://arxiv.org/html/2411.15300v2', timeout=60) as response:
            paper = response.read().decode()
        mode = 'live API and paper'
    labels = lattices['Parameters']['lattice']['values']
    expected = {'square': 'square $(4^4)$', 'triangular': 'triangular $(3^6)$',
                'sc': 'simple cubic', 'bcc': 'body-centred cubic',
                'fcc': 'face-centred cubic', 'diamond': 'diamond'}
    assert all(labels[k] == v and k in lattices['Numbers'] for k,v in expected.items())
    assert 'nearest-neighbour ferromagnetic Ising model' in lattices['Definition']
    assert 'three-dimensional Ising' in table['Definition']
    assert parenthesized('1.250(12)') == (Fraction(5,4), Fraction(3,250))
    parser = Cells()
    parser.feed(paper)
    checks = []
    for triple, cell in [(('sigma','sigma','epsilon'),'S1.T1.3.4.2'),
                         (('epsilon','epsilon','epsilon'),'S1.T1.3.5.2')]:
        value = table['Numbers']
        for key in triple:
            value = value[key]
        source = parser.cells[cell].strip()
        actual = stored(value['number'])
        assert actual == parenthesized(source)
        assert actual[1] > 0 and actual[0] > actual[1]
        checks.append({'triple': list(triple), 'source': source,
                       'stored': value['number'], 'match': True})
    allowed = [t for t in combinations_with_replacement(('sigma','epsilon'),3)
               if t.count('sigma') % 2 == 0]
    assert allowed == [('sigma','sigma','epsilon'),('epsilon','epsilon','epsilon')]
    report = {'tid': 'T474', 'python': sys.version.split()[0], 'mode': mode,
              'lattice_labels_checked': expected, 'source_transcriptions': checks,
              'even_parity_triples': allowed,
              'limits': 'Source transcription and dimension labels checked; universality is supported by the cited paper, not proved computationally.'}
    print(json.dumps(report,indent=2))

if __name__ == '__main__':
    main()