back to table · edit · history · where entries came from · files · download
8538 bytes, as of the version from 2026-10-31 21:28 (current). Recorded here, not run.
"""Independent integral and surface-potential checks for numberdb.org/T629.
Run sage -python checks.py beside generate.py. To check exported values,
call main(document, document_source='live-api-readback') after a fresh API read;
use document_source='exported-document' for other exports. All written intervals
are checked. The provenance label distinguishes a live read from a prepared file.
The defining-integral method is adapted from public T627 and T628 attachments.
Polynomial coefficients use factorials, not the generator recurrence; radial
functions use validated quadrature, not the generator arctangent expression.
Surface hydrostatic equilibrium independently gives Omega^2. Nonzero known
controls precede all comparisons; finite, narrow enclosures are mandatory.
"""
import json
import os
from math import factorial
import platform
from pathlib import Path
import hashlib
from functools import lru_cache
import numberdb.sage as numberdb
from numberdb._write import to_text
from sage.rings.rational_field import QQ
from sage.rings.complex_arb import ComplexBallField
from sage.rings.real_arb import RealBallField
from sage.env import SAGE_VERSION
from generate import (MaclaurinSquaredAngularVelocity, enclose, root_enclosure,
polynomials, client_from_stdin)
PRECISION = 600
C = ComplexBallField(PRECISION)
F = RealBallField(PRECISION)
COARSE_BETA = ('0.35890','0.40345','0.42664','0.44084','0.45044',
'0.45736','0.46259','0.46667','0.46995','0.47265')
COARSE_OMEGA = ('0.087262','0.066105','0.052711','0.043714','0.037301',
'0.032513','0.028806','0.025854','0.023449','0.021451')
COARSE_E = ('0.98523','0.99375','0.99657','0.99784','0.99851',
'0.99891','0.99917','0.99935','0.99947','0.99957')
def decimal_rational(text):
if 'e' in text.lower():
mant,power = text.lower().split('e')
return decimal_rational(mant)*QQ(10)**int(power)
a,b = text.split('.')
return QQ(int(a+b))/QQ(10)**len(b)
@lru_cache(None)
def explicit_coefficients(n):
assert n % 2 == 0
return tuple(QQ(factorial(n+2*j))/(2**n*factorial(n//2-j)*
factorial(n//2+j)*factorial(2*j)) for j in range(n//2+1))
def explicit_p(n,x):
value = x.parent()(0)
for c in explicit_coefficients(n)[::-1]:
value = value*x*x+c
return value
def integral_q(n,x,uncertain=False):
coefficients = [a*x**(2*j) for j,a in enumerate(explicit_coefficients(n))]
def integrand(u,analytic):
p_scaled = C(0)
for a in coefficients:
p_scaled = p_scaled*u*u+a
return x*u**(2*n)/((u*u+x*x)*p_scaled*p_scaled)
tol = F(2)**(-400 if uncertain else -510)
value = explicit_p(n,x)*C.integral(integrand,0,1,abs_tol=tol,rel_tol=tol)
assert value.real().is_finite() and value.imag().is_finite()
assert F(value.real().rad()) < F(10)**(-115 if uncertain else -140)
assert value.imag().contains_zero()
return value.real()
def original_equation(k,x):
xc=C(x)
return (2*explicit_p(2*k+2,x)*integral_q(2*k+2,xc)
-x/explicit_p(2,x)*(1-2*x*integral_q(2,xc)))
def sign(v):
assert v.is_finite()
if v > 0:return 1
if v < 0:return -1
raise ArithmeticError('Unresolved independent sign.')
def physical_energy(x,uncertain=False):
# Focal length a0=1, G=rho=1. AKM surface potential in Section 2.
q0=integral_q(0,C(x),uncertain)
q2=integral_q(2,C(x),uncertain)
a2=1+x*x
mass=4*F.pi()*x*a2/3
phi_pole=-mass*(q0+q2)
phi_equator=-mass*(q0-q2/2)
omega_squared=2*(phi_equator-phi_pole)/a2
inertia=2*mass*a2/5
kinetic=inertia*omega_squared/2
# AKM Section 4: W=(3/5)M Phi0+T; Phi0=Phi_pole.
gravitational=3*mass*phi_pole/5+kinetic
assert kinetic > 0 and gravitational < 0
beta=kinetic/(-gravitational)
assert beta.is_finite() and F(beta.rad()) < F(10)**(-110 if uncertain else -135)
return beta,omega_squared,kinetic,gravitational
def written_interval(text):
from decimal import Decimal
q=Decimal(text)
return decimal_rational(text),QQ(10)**q.as_tuple().exponent
def require_inside(value,center,ulp):
assert value.is_finite()
assert value>F(center-ulp) and value<F(center+ulp)
def main(document=None, document_source=None):
for n,known in [(0,F.pi()/4),(2,F.pi()/2-F(3)/2)]:
got=integral_q(n,C(1))
assert got.overlaps(known) and not got.contains_zero()
control=physical_energy(F(1))
assert control[0].overlaps(2-6/F.pi()) and not control[0].contains_zero()
control_omega=control[1]/(4*F.pi())
assert control_omega.overlaps(F.pi()/2-F(3)/2) and control_omega>0
print('CONTROLS: q0(1), q2(1), beta(1), omega^2(1)=pi/2-3/2 certified.',flush=True)
stored=document is not None
if stored and document_source is None:
raise ValueError('Identify whether the supplied document is prepared or live readback.')
if stored:
records=document['Numbers']
if isinstance(records,dict):
assert [str(k) for k in records]==[str(k) for k in range(1,11)]
texts={int(k):(v['number'] if isinstance(v,dict) else v) for k,v in records.items()}
else:
assert [str(r['params']['k']) for r in records]==[str(k) for k in range(1,11)]
texts={int(r['params']['k']):r['number'] for r in records}
else:
texts={k:to_text(enclose(k)[0],100) for k in range(1,11)}
policy=json.loads((Path(__file__).parent/'skill-evidence.json').read_text())
evidence={'table':'T629','stored_readback':document_source == 'live-api-readback',
'document_source':document_source or 'fresh-generator',
'run_id':policy['run_id'], 'skill_manifest':policy['manifest'],
'skill_sha256':{v['source']:v['sha256'] for v in policy['versions']},
'generator_sha256':hashlib.sha256((Path(__file__).parent/'generate.py').read_bytes()).hexdigest(),
'check_sha256':hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),
'algorithm_origin_run':'20261030T194506Z',
'sage_version':SAGE_VERSION,'python_version':platform.python_version(),
'root_working_bits':[500,700],'quadrature_bits':PRECISION,
'controls_passed':True,'entries':[]}
previous=F(1)
for k in range(1,11):
omega,lo,hi=enclose(k)
other,lo2,hi2=enclose(k,working_bits=700)
assert (lo,hi)==(lo2,hi2) and omega.overlaps(other)
assert previous > omega
previous=omega
x=F((lo+hi)/2).add_error(F((hi-lo)/2))
p,_,_,_,derivative=polynomials(k)
assert list(explicit_coefficients(2*k+2))==list(p.list()[::2])
f_lo=original_equation(k,F(lo));f_hi=original_equation(k,F(hi))
assert sign(f_lo)==1 and sign(f_hi)==-1
beta,physical_omega2,kinetic,gravitational=physical_energy(x,uncertain=True)
independent=physical_omega2/(4*F.pi())
assert independent.is_finite() and F(independent.rad())<F(10)**(-110)
assert omega.overlaps(independent)
center,ulp=written_interval(texts[k])
assert len(texts[k].split('.')[1].lstrip('0'))==100
for ball in [omega,other,independent]:require_inside(ball,center,ulp)
e=1/(1+x*x).sqrt();s=(1-e*e).sqrt();theta=e.arcsin()
omega_e=s*(3-2*e*e)*theta/(2*e**3)-3*s*s/(2*e*e)
relation_beta=x*theta*beta
q2_recurrence=(1+3*x*x)*theta/2-3*x/2
for ball in [omega_e,relation_beta,x*q2_recurrence]:
assert ball.is_finite() and F(ball.rad())<F(10)**(-110)
assert ball.overlaps(omega)
require_inside(ball,center,ulp)
for got,coarse in [(omega,COARSE_OMEGA[k-1]),(beta,COARSE_BETA[k-1]),(e,COARSE_E[k-1])]:
c,u=written_interval(coarse)
assert abs(got-F(c))<F(u/2)
evidence['entries'].append({'k':k,'omega_squared':texts[k],
'xi_lower':str(lo),'xi_upper':str(hi),'omega_radius':str(omega.rad()),
'independent_omega':str(independent),'independent_omega_radius':str(independent.rad()),
'independent_root_endpoint_residuals':[str(f_lo),str(f_hi)],
'root_derivative_certificate_degree':int(derivative.degree()),
'exact_certificate_passed':True,'same_bracket_at_700_bits':True,
'all_displayed_identities_checked':True,'coarse_omega_beta_e_match':True,
'independent_enclosure_inside_written_interval':True})
print('PASS',k,texts[k],flush=True)
print('EVIDENCE_JSON='+json.dumps(evidence,sort_keys=True),flush=True)
if __name__=='__main__':main()