check_values.py

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

6583 bytes, as of the version from 2026-12-02 10:31 (current). Recorded here, not run.

"""Independent exact checks for cube-containment entries (standard Python only).

Usage: python3 check_values.py computation.json check-results.json
   or: python3 check_values.py stored-document.json check-results.json
No generator imports or approximate square roots are used. Exact fitting
matrices determine the squared edge; positivity and rational endpoint
squaring check each decimal's entire advertised enclosure. The odd-dimensional
optimality upper bound is the separately cited theorem, not proved by this
attainment certificate. Read the cited manuscript to assess that input.
"""
from fractions import Fraction as F
from math import isqrt
from pathlib import Path
import json,re,sys,hashlib,platform


def interval(s):
    s=str(s).strip()
    if s.startswith('[') and s.endswith(']'):
        a,b=s[1:-1].split(',');return F(a.strip()),F(b.strip())
    if '+/-' in s:
        a,r=s.split('+/-');return F(a)-F(r),F(a)+F(r)
    if '.' not in s and 'e' not in s.lower():
        return F(s),F(s)
    match=re.fullmatch(r'([+-]?\d+)(?:\.(\d*))?(?:[eE]([+-]?\d+))?',s)
    if not match: raise ValueError('Unsupported numeric spelling')
    exponent=int(match[3] or 0)-len(match[2] or '')
    ulp=F(10)**exponent;c=F(s)
    return c-ulp,c+ulp


def fitting_matrix(m,n):
    if n%m==0:
        return [[F(int(j%m==i)) for j in range(n)] for i in range(m)]
    if m==2 and n%2==1:
        rows=[[F(3,4),F(3,4),F(0)],[F(1,4),F(-1,4),F(1)]]
        for _ in range((n-3)//2):
            rows[0].extend([F(1),F(0)]);rows[1].extend([F(0),F(1)])
        return rows
    raise ValueError('Dimension pair outside selected formula classes')


def check_record(record):
    p=record['params'];assert list(p)==['m','n'], 'Wrong parameter order'
    m,n=int(p['m']),int(p['n']);assert 1<=m<n<=16,'Wrong dimension domain'
    V=fitting_matrix(m,n)
    gram=[[sum(x*y for x,y in zip(a,b)) for b in V] for a in V]
    q=gram[0][0]
    assert all(gram[i][j]==(q if i==j else 0) for i in range(m) for j in range(m)), 'Bad Gram matrix'
    assert len(V[0])==n and all(sum(abs(V[i][j]) for i in range(m))==1 for j in range(n)), 'Cube does not fit'
    if n%m==0:assert q==F(n,m),'Diagonal upper bound not attained'
    else:assert q==F(n-1,2)+F(1,8),'Wrong odd-dimension squared edge'
    lo,hi=interval(record['number']);assert 0<lo<=hi, 'Nonpositive/unordered interval'
    square=isqrt(q.numerator)**2==q.numerator and isqrt(q.denominator)**2==q.denominator
    if square:
        exact=F(isqrt(q.numerator),isqrt(q.denominator))
        assert lo==hi==exact, 'Known exact rational returned approximately'
    else:
        assert lo<hi and lo*lo<q<hi*hi, 'Stored enclosure misses the positive root'
        assert (hi-lo)/lo<=F(1,10**98), 'Enclosure too wide for 100 significant digits'
        s=str(record['number']);mantissa=re.split('[eE]',s)[0]
        assert len(mantissa.replace('.','').lstrip('+-0'))==100, 'Unexpected significant-digit count'
    return {'params':{'m':m,'n':n},'squared_edge':str(q),'enclosure_width':str(hi-lo),'exact':square,'matrix_shape':[m,n],'attainment':True}


def rows_from(document):
    if 'records' in document:return [{'params':r['params'],'number':r['number']} for r in document['records']]
    b=document.get('Numbers',document.get('Data'))
    if isinstance(b,list):return b
    rows=[]
    for m,entries in b.items():
        for n,v in entries.items():
            rows.append({'params':{'m':m,'n':n},'number':v.get('number') if isinstance(v,dict) else v})
    return rows


def main(source,output):
    path=Path(source);document=json.loads(path.read_text());rows=rows_from(document)
    expected={(m,n) for n in range(2,17) for m in range(1,n) if n%m==0 or m==2}
    actual=[(int(r['params']['m']),int(r['params']['n'])) for r in rows]
    failures=[];details=[]
    if set(actual)!=expected or len(actual)!=len(expected):failures.append('Selected parameter identities differ from the full stated 41-pair selection')
    for row in rows:
        try:details.append(check_record(row))
        except Exception as e:failures.append({'params':row.get('params'),'error':str(e)})
    controls={}
    for m,n,v in [(1,4,'2'),(1,9,'3'),(2,8,'2'),(4,16,'2')]:
        controls[f'exact_{m}_{n}']=check_record({'params':{'m':m,'n':n},'number':v})['exact']
    controls['nonzero_2_3_squared_9_over_8']=fitting_matrix(2,3)[0][0]**2+fitting_matrix(2,3)[0][1]**2==F(9,8)
    negatives={}
    wrongs={
      'sqrt_n_divided_by_m':{'params':{'m':2,'n':4},'number':'1'},
      'squared_edge_stored_as_edge':{'params':{'m':2,'n':3},'number':'9/8'},
      'changed_dimension_key':{'params':{'m':2,'n':5},'number':next(r['number'] for r in rows if int(r['params']['m'])==2 and int(r['params']['n'])==3)},
      'vacuously_wide_enclosure':{'params':{'m':2,'n':3},'number':'[1, 2]'},
      'nonfinite':{'params':{'m':2,'n':3},'number':'NaN'},
      'exact_integer_disguised_as_decimal':{'params':{'m':1,'n':4},'number':'2.0000000000000000000'}
    }
    for label,row in wrongs.items():
        try:check_record(row)
        except (AssertionError,ValueError):negatives[label]=True
        else:negatives[label]=False;failures.append('Failed negative control '+label)
    result={'stage':'builder check, not independent actor verdict','checked_entries':len(details),'total_entries':len(rows),'failures':failures,'known_answer_control':all(controls.values()),'negative_control_rejected':all(negatives.values()),'controls':controls,'negative_controls':negatives,'details':details,'method':'Exact rational fitting matrices, Gram and column-sum identities, positive endpoint squaring; no generator imports or floating arithmetic','independence':'Implementation differs from Arb square-root generator; shared assumptions are the definition and cited odd-dimensional optimality theorem','limitations':'Attainment does not prove odd-dimensional global optimality; literature theorem remains a mathematical input. This is build evidence, awaiting fresh independent critique.','source_sha256':hashlib.sha256(path.read_bytes()).hexdigest(),'checker_sha256':hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),'python':platform.python_version(),'skill_manifest':'agents/runs/20261202T092637Z-build-skills/manifest.json'}
    Path(output).write_text(json.dumps(result,indent=2)+'\n')
    print(json.dumps({k:result[k] for k in ('checked_entries','total_entries','known_answer_control','negative_control_rejected','failures')}))
    return int(bool(failures) or not all(controls.values()) or not all(negatives.values()))

if __name__=='__main__':sys.exit(main(*sys.argv[1:]))