"""Scaling dimensions of the 3D Ising CFT -- numberdb.org/T473.

Run with SageMath (or passagemath with the numberdb package):
    sage -pip install numberdb
    sage -python generate.py                 # verify all stored entries
    sage -python checks.py                   # check local values and controls
    sage -python checks.py --stored          # check the database values

Reading this unpublished draft requires its author's NUMBERDB_API_KEY.
NUMBERDB_KEY_FROM_STDIN=1 reads a key from standard input instead.
This file transcribes published measurements; it does not solve bootstrap
crossing equations. The finite uncertainties are exactly the source's quoted
radii, not a claim of 100-digit precision or unconditional mathematical proof.

Chang et al., JHEP 03 (2025) 136, Table 1, arXiv:2411.15300v2:
  sigma = 0.518148806(24), epsilon = 1.41262528(29).
Reehorst, JHEP 09 (2022) 177, Table 1 and eqs. (4.1), (4.2),
arXiv:2111.12093v1:
  epsilon-prime = 3.82951(61), sigma-prime = 5.262(89).
T has dimension exactly d = 3 by stress-tensor conservation.

The two primed estimates are separate conditional bootstrap bounds, not a
joint spectrum fit. The full assumptions and source choice are in the table.
The narrower nonrigorous EFM estimates are independent checks, not replacements.
"""
import os
import sys

import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ


# Explicit source spelling avoids any floating-point arithmetic or rounding.
ROWS = {
    'sigma': ('0.518148806 +/- 0.000000024',
              r'The spin primary, odd under spin flip. Table 1 of CITE{Chang2025}.'),
    'epsilon': ('1.41262528 +/- 0.00000029',
                r'The energy primary, even under spin flip. Table 1 of CITE{Chang2025}.'),
    'T': (ZZ(3),
          r'The conserved stress tensor has spin $2$ and dimension exactly $3$.'),
    'epsilon-prime': ('3.82951 +/- 0.00061',
                     r'The next nonidentity even scalar primary. Equation (4.1) of CITE{Reehorst2022}, under its even-scalar spectral-gap assumption.'),
    'sigma-prime': ('5.262 +/- 0.089',
                   r'The next odd scalar primary. Equation (4.2) of CITE{Reehorst2022}, under its odd-scalar spectral-gap assumption.'),
}


class IsingScalingDimensions(numberdb.Generator):
    table = 'T473'
    parameters = ('operator',)
    type = 'R'
    # This is a nominal target. Explicit interval strings retain source precision.
    digits = 100
    rigour = 'measured'
    files = ('generate.py', 'checks.py', 'check.py', 'dry_run.py',
             'source-evidence.json', 'convention.md')

    def enumerate(self):
        for operator in ROWS:
            yield {'operator': operator}

    def value(self, params, digits):
        number, comment = ROWS[params['operator']]
        return {'number': number, 'comment': comment}


def configure_key():
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN') == '1':
        numberdb.configure(api_key=sys.stdin.read().strip(),
                           base_url='https://numberdb.org')


if __name__ == '__main__':
    configure_key()
    report = IsingScalingDimensions().verify(sample=None)
    print(report)
    sys.exit(0 if report.ok else 1)
