back to table · edit · history · where entries came from · files · download
11428 bytes, as of the version from 2026-11-17 10:38 (current). Recorded here, not run.
"""Builder checks for T736. This is not an independent critique verdict.
Run: sage -python build_check.py entries.json [stored-document.json]
No production-generator imports. Independent ideal factorization and finite
fields validate indices and character phases. Quadratic sums use unweighted
squares. Jacobi sums reduce exactly in Q(zeta6). The inferred cubic sum is
checked by the cube equation and the character-free unweighted S_p identity,
which selects the root, or by the inert exact value. CRT covers composites.
Shared software: Sage cyclotomic arithmetic and Arb, not sextic lattice sums.
"""
import json,sys,hashlib
from pathlib import Path
from fractions import Fraction
from math import isqrt
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.number_field.number_field import CyclotomicField
from sage.rings.complex_arb import ComplexBallField
from sage.rings.finite_rings.finite_field_constructor import GF
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.real_mpfi import RealIntervalField
from sage.env import SAGE_VERSION
BASE=Path(__file__).resolve().parent
K=CyclotomicField(3);w=K.gen();C=ComplexBallField(640)
def coords(x):return tuple(int(v) for v in K(x))
def eprimary(x):
a,b=coords(x)
if int(x.norm())%2==0 or int(x.norm())%3==0 or a%3==0 or b%3:return False
if b%2==0:return (a+b)%4==1
if a%2==0:return b%4==1
return a%4==3
def canonical(x):
options=[x*(-w)**j for j in range(6) if eprimary(x*(-w)**j)]
assert len(options)==1
return options[0]
def prime_ideals(limit):
primes=[]
for p in range(5,limit+1):
if not ZZ(p).is_prime():continue
for I,e in K.ideal(p).factor():
if I.norm()>limit:continue
x=canonical(I.gens_reduced()[0]);assert K.ideal(x)==I
primes.append(x)
return sorted(primes,key=lambda x:(x.norm(),*coords(x)))
def product_selection(primes,limit):
choices={}
def visit(start,current,fs):
for j in range(start,len(primes)):
pi=primes[j]
if current.norm()*pi.norm()>limit:break
new=current*pi;assert eprimary(new)
ident=coords(new);assert ident not in choices
choices[ident]=fs+(pi,);visit(j+1,new,fs+(pi,))
visit(0,K(1),())
return choices
field_cache={}
def local_field(pi):
key=coords(pi)
if key in field_cache:return field_cache[key]
a,b=key;n=int(pi.norm())
if ZZ(n).is_prime():F=GF(n);om=-F(a)/F(b)
else:
q=isqrt(n);assert q*q==n and q%3==2
P=PolynomialRing(GF(q),'t');t=P.gen();F=GF(q*q,'u',modulus=t*t+t+1);om=F.gen()
assert om**3==1 and om!=1
field_cache[key]=(F,om)
return F,om
def residue_exp(x,pi):
F,om=local_field(pi);a,b=coords(x);y=F(a)+F(b)*om
if not y:return None
roots=[(F(1)+om)**j for j in range(6)];assert len(set(roots))==6
t=y**((int(pi.norm())-1)//6);assert t in roots
return roots.index(t)
def field_exponents(pi):
F,om=local_field(pi);z=F(1)+om;roots=[z**j for j in range(6)]
result={}
for x in F:
result[x]=None if not x else roots.index(x**((int(F.cardinality())-1)//6))
return result
def additive_numerator(x,pi):
a,b=coords(pi);n=int(pi.norm())
if ZZ(n).is_prime():return -b*int(x)
cs=list(x);v=int(cs[1]) if len(cs)>1 else 0
return a*v
def local_data(pi,L):
F,om=local_field(pi);n=int(pi.norm());z=L.gen();z6=z**n
exps=field_exponents(pi)
# Unweighted quadratic exponential sum: #roots(t)=1+eta(t).
qcounts=[0]*(6*n)
for x in F:qcounts[(6*additive_numerator(x*x,pi))%(6*n)]+=1
quadratic=L(qcounts);assert quadratic*conjugate_exact(L,quadratic)==n
# Jacobi sum calculated in the small sextic field, including zero mask.
M=CyclotomicField(6);jcounts=[0]*6
for x in F:
e=exps[x];f=exps[1-x]
if e is not None and f is not None:jcounts[(3*e+2*f)%6]+=1
J=embed_exact(L,M(jcounts));assert J*conjugate_exact(L,J)==n
lm=residue_exp(1+2*w,pi);minus=residue_exp(K(-1),pi)
assert minus in [0,3]
return quadratic,J,lm,minus,jcounts
def validate_prime(pi,L,v):
a,b=coords(pi);n=int(pi.norm());z6=L.gen()**n;om=z6**2
quadratic,J,lm,minus,jcounts=local_data(pi,L)
# From G(eta)G(chi)=J(eta,chi)G(bar psi) and
# G(psi)=psi(-1)*conj(G(bar psi)), solve for the cubic sum.
diff_cubic=J*z6**minus*conjugate_exact(L,v)*conjugate_exact(L,quadratic)/n
trace_cubic=z6**((-2*lm)%6)*diff_cubic
if ZZ(n).is_prime():
sign=1 if a%3==1 else -1
pp=sign*(a+b*om)
assert trace_cubic**3==-n*pp,(a,b,'cubic equation')
cs=[0]*(6*n)
for x in range(n):cs[6*pow(x,3,n)]+=1
S=L(cs)
assert trace_cubic+conjugate_exact(L,trace_cubic)==S,(a,b,'cubic root selection')
for j in [1,2]:
bad=om**j*trace_cubic
assert bad+conjugate_exact(L,bad)!=S
else:
assert trace_cubic==isqrt(n),(a,b,'inert cubic')
assert trace_cubic*conjugate_exact(L,trace_cubic)==n
# Exact inverse reconstruction, independent of the production sextic sum.
reconstructed=z6**minus*conjugate_exact(L,quadratic*diff_cubic*conjugate_exact(L,J)/n)
assert reconstructed==v
return {'params':{'a':a,'b':b},'norm':n,'quadratic_unweighted':True,'jacobi_coefficients':jcounts,'lambda_symbol_exponent':lm,'minus_symbol_exponent':minus,'cubic_phase_selected':True}
def conjugate_exact(L,x):
# zeta_m -> zeta_m^(-1). Permute exponents, then reduce once in L.
order=int(L.gen().multiplicative_order());coefficients=[0]*order
for j,c in enumerate(x):coefficients[(-j)%order]+=c
return L(coefficients)
def embed_exact(L,x):
source_order=int(x.parent().gen().multiplicative_order())
target_order=int(L.gen().multiplicative_order())
assert target_order%source_order==0
ratio=target_order//source_order;coefficients=[0]*target_order
for j,c in enumerate(x):coefficients[(ratio*j)%target_order]+=c
return L(coefficients)
def eval_exact(L,x):
# The defining generator is exp(2*pi*i/(3*N)); the field's full unit-root
# order can be twice that conductor and must not be substituted here.
order=int(L.gen().multiplicative_order())
root=(C(0,2)*C.pi()/order).exp();result=C(0)
for a in reversed(list(x)):result=result*root+C(a)
assert result.real().is_finite() and result.imag().is_finite()
assert result.accuracy()>500
return result
def component_interval(s):
s=s.strip()
# Exact integers/rationals remain points. A decimal has one last-place ulp.
if '.' not in s and 'e' not in s.lower():
q=Fraction(s);return q,q
q=Fraction(s)
mantissa,sep,exp=s.lower().partition('e');exponent=int(exp) if sep else 0
places=len(mantissa.partition('.')[2])
ulp=Fraction(10)**(exponent-places)
return q-ulp,q+ulp
def stored_parts(s):
s=s.replace(' ','')
if '+i*' in s:r,i=s.split('+i*')
elif '-i*' in s:r,i=s.split('-i*');i='-'+i
elif s.startswith('i*'):r,i='0',s[2:]
else:r,i=s,'0'
return component_interval(r),component_interval(i)
def stored_contains(s,z):
for part,(lo,hi) in zip((z.real(),z.imag()),stored_parts(s)):
assert part.is_finite()
if lo==hi:
# Exact-point claim is separately certified by the exact algebraic tests.
assert QQ(lo.numerator)/lo.denominator in part
else:
assert part.accuracy()>500
assert QQ(lo.numerator)/lo.denominator < QQ(part.lower())
assert QQ(part.upper()) < QQ(hi.numerator)/hi.denominator
return True
def safe_contains(s,z):
try:return stored_contains(s,z)
except (AssertionError,ValueError,TypeError,AttributeError):return False
def run(rows,stored=None):
for m in [6,42,78]:
L=CyclotomicField(m);x=L.gen()+2*L.gen()**3
assert conjugate_exact(L,x)==x.conjugate()
assert embed_exact(CyclotomicField(42),CyclotomicField(6).gen())==CyclotomicField(42).gen()**7
primes=prime_ideals(500);selected=product_selection(primes,500)
ids=[(int(r['params']['a']),int(r['params']['b'])) for r in rows]
assert set(ids)==set(selected) and len(ids)==len(selected)==142
assert ids==sorted(ids,key=lambda t:(int(K(t[0]+t[1]*w).norm()),*t))
data={}
for ident,row in zip(ids,rows):
L=CyclotomicField(6*row['norm']);data[ident]=(L,L(row['exact_coefficients']),row)
prime_results=[];prime_exact={};split=inert=0
for pi in primes:
ident=coords(pi);L,v,row=data[ident]
prime_results.append(validate_prime(pi,L,v));prime_exact[ident]=v
if ZZ(pi.norm()).is_prime():split+=1
else:inert+=1
print('CHECKPOINT_PRIME',json.dumps({'params':ident,'norm':int(pi.norm()),'checked':True}),flush=True)
checks=[];composite=0;nontrivial_crt=[]
for ident in ids:
L,v,row=data[ident];fs=selected[ident];z6=L.gen()**row['norm'];expected=L(1);part=K(1)
plain=L(1)
for pi in fs:
e=(residue_exp(part,pi)+sum(residue_exp(pi,r) for r in selected.get(coords(part),())))%6 if part!=1 else 0
local=embed_exact(L,prime_exact[coords(pi)])
expected*=z6**e*local;plain*=local;part*=pi
assert coords(part)==ident and expected==v,(ident,'CRT')
assert v*conjugate_exact(L,v)==row['norm']
if len(fs)>1:
composite+=1
if plain!=v:nontrivial_crt.append(ident)
z=eval_exact(L,expected);s=row['number'] if stored is None else stored[ident]
assert stored_contains(s,z)
if '.' not in s:assert v in QQ and QQ(v)==QQ(s)
checks.append({'params':row['params'],'norm':row['norm'],'factor_count':len(fs),'exact_magnitude':True,'phase_checked':True,'stored_interval_contains_independent_ball':True})
print('CHECKPOINT_ENTRY',json.dumps(checks[-1]),flush=True)
assert (split,inert,composite)==(90,3,49)
assert nontrivial_crt,'missing CRT-phase control'
assert data[(5,0)][1]==5 and data[(-11,0)][1]==11 and data[(17,0)][1]==17
L,v,row=data[(-1,-3)];good=eval_exact(L,v)
assert not safe_contains(row['number'],good+C(1)/10**60)
assert not safe_contains(row['number'],C(RealIntervalField(640)(-1000,1000)))
assert not safe_contains(row['number'],C('nan'))
# Sign change at norm 7 has psi(-1)=-1 and must be rejected.
assert residue_exp(K(-1),K(-1-3*w))==3
assert not safe_contains(row['number'],-good)
# Wrong additive embedding (trace instead of different) cannot pass.
F,fw=local_field(K(-1-3*w));es=field_exponents(K(-1-3*w));cs=[0]*42
for x in F:
if es[x] is not None:cs[(7*es[x]+6*int(x))%42]+=1
wrong=L(cs);assert wrong!=v
assert not safe_contains(row['number'],eval_exact(L,wrong))
return {'checked_entries':142,'total_entries':142,'failures':[],'known_answer_control':True,'negative_control_rejected':True,
'counts':{'split_prime':split,'inert_prime':inert,'composite':composite},'prime_checks':prime_results,'comparisons':checks,
'nontrivial_crt_controls':nontrivial_crt,'controls':['G6(5)=5, G6(-11)=11, G6(17)=17','wrong cubic roots rejected at all split primes','missing CRT phase rejected','wrong norm-7 denominator sign rejected','wrong norm-7 additive character rejected','10^-60 shift rejected','broad ball rejected','NaN rejected'],
'independence':'Independent rational-prime ideal factorization, finite fields and lower-order Gauss/Jacobi identities; no generator import or production sextic lattice sum. Shared Sage exact cyclotomic arithmetic and Arb.',
'software':{'sage':SAGE_VERSION,'python':sys.version.split()[0],'numberdb':numberdb.__version__},
'skill_manifest_sha256':hashlib.sha256((BASE/'skill-manifest.json').read_bytes()).hexdigest()}
if __name__=='__main__':
rows=json.loads((Path(sys.argv[1]) if len(sys.argv)>1 else BASE/'entries.json').read_text());stored=None
if len(sys.argv)>2:
from numberdb._generate import _stored_entries
d=json.loads(Path(sys.argv[2]).read_text());stored={tuple(map(int,k.split(','))):v for k,v in _stored_entries(d).items()};assert len(stored)==142
print('RESULT',json.dumps(run(rows,stored)),flush=True)