back to table · edit · history · where entries came from · files · download
8818 bytes, as of the version from 2026-11-28 03:17 (current). Recorded here, not run.
"""Builder validation of T842, not an independent critic's verdict.
sage -python independent_check.py
Inputs beside this file: unit-rows.json, companion-stored-records.json.
No generator is imported. Independently digit-lift roots, evaluate the bounded
logarithm series using integer modular arithmetic, and certify all candidate
fundamental units by a complete finite Pell census. Proof-enabled class groups
support the separate comparison with the analytic T841 values. A sibling table
is a consistency comparison, not the independent evidence for the logarithms.
The modular-series technique reuses the documented component design of the
preceding analytic build, rather than treating its conclusions as established.
"""
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.qqbar import AA
from sage.rings.number_field.number_field import QuadraticField
from sage.modular.dirichlet import kronecker_character
import os,sys,json,re,math,time,hashlib
from pathlib import Path
def floorlog(k,p):
n=0
while k>=p:k//=p;n+=1
return n
def hensel(D,p,A):
roots=[r for r in range(1,p) if (r*r-D)%p==0];assert len(roots)==2
r0=min(roots);r=r0
for k in range(1,A):
modulus=p**k
r+=(((D-r*r)//modulus)*pow(2*r,-1,p)%p)*modulus
assert r%p==r0 and (2*r0)%p and (r*r-D)%(p**A)==0
return r,r0
def series(e,p,A):
assert e%p
K=1
while K-floorlog(K,p)<A:K+=1
guard=floorlog(K,p);large=p**(A+guard);mod=p**A
z=(pow(e,p-1,large)-1)%large;assert z%p==0
total=0;power=1
for k in range(1,K):
power=power*z%large;q=k;v=0
while q%p==0:q//=p;v+=1
assert power%p**v==0
total=(total+(-1)**(k+1)*(power//p**v)*pow(q,-1,mod))%mod
return total*pow(p-1,-1,mod)%mod,K
def field_data(D):
K=QuadraticField(D,'b');assert K.discriminant()==D
eps=K.unit_group(proof=True).gens_values()[1];emb=K.hom([AA(D).sqrt()],AA)
if emb(eps)<0:eps=-eps
if emb(eps)<1:eps=1/eps
t,u=int(ZZ(2*eps[0])),int(ZZ(2*eps[1]));n=int(eps.norm())
assert eps.is_integral() and t>0 and u>0 and t*t-D*u*u==4*n and n in (-1,1)
candidates=[]
for v in range(1,u+1):
for norm in (-1,1):
square=D*v*v+4*norm
if square<=0:continue
s=math.isqrt(square)
if s*s!=square:continue
if (D%4==1 and (s-v)%2) or (D%4==0 and s%2):continue
value=(AA(s)+v*AA(D).sqrt())/2
if value>1:candidates.append((value,s,v,norm))
# Any smaller unit >1 has u' <= u. Indeed u=(eps-n/eps)/sqrt(D),
# and changing the norm sign changes this by <2/(eps*sqrt(D))<1.
best=min(candidates,key=lambda row:row[0]);assert best[1:]==(t,u,n) and best[0]==emb(eps)
return dict(D=D,t=t,u=u,norm=n,h=int(K.class_number(proof=True)),minimality_u_bound=u,pell_candidates=len(candidates))
def decode(text,p):
# NumberDB val-unit encoding, with a mandatory finite, positive modulus.
match=re.fullmatch(r'(.+) \+ O\((\d+)\^(\d+)\)',text)
assert match and int(match[2])==p and int(match[3])>0,text
coefficient=match[1].strip();A=int(match[3]);factor=1
if '*' in coefficient:
left,right=coefficient.split('*');coefficient=right.strip();left=left.strip()
if '^' in left:
base,exponent=map(int,left.split('^'));assert base==p and exponent>=0;factor=p**exponent
else:factor=int(left);assert factor==p
residue=factor*int(coefficient)%(p**A)
return residue,A
def accept(row,expected,certified_A):
p=int(row['params']['p']);A=int(row['A']);res=int(row['residue']);N=0;power=1
while power<10**100:N+=1;power*=p
if not (0<res<p**A and A<=certified_A):return False
v=0;part=res
while part%p==0:part//=p;v+=1
return A-v>=N and (res-expected)%p**A==0
def run(path,companion_path,output):
rows=json.loads(path.read_text());companions=json.loads(companion_path.read_text());start=time.monotonic()
analytic={tuple(int(r['params'][k]) for k in ('D','p')):decode(r['number'],int(r['params']['p'])) for r in companions}
fields={D:field_data(D) for D in sorted({int(r['params']['D']) for r in rows})}
expected=[]
for D in range(5,101):
d=D if D%4==1 else D//4
if not ((D%4==1 and ZZ(D).is_squarefree()) or (D%4==0 and d%4 in (2,3) and ZZ(d).is_squarefree())):continue
chi=kronecker_character(D)
assert chi.is_primitive() and chi.is_even() and chi.conductor()==D
for p in range(3,32):
if ZZ(p).is_prime() and chi(p)==1:expected.append((D,p))
assert [tuple(int(r['params'][k]) for k in ('D','p')) for r in rows]==expected
assert set(analytic)==set(expected) and len(rows)==107
assert (fields[5]['t'],fields[5]['u'],fields[5]['norm'],fields[5]['h'])==(1,1,-1,1)
assert fields[12]['norm']==1 and (fields[12]['t'],fields[12]['u'])==(4,1)
assert (fields[40]['t'],fields[40]['u'],fields[40]['h'])==(6,1,2)
controls={}
for p in sorted({p for D,p in expected}):
controls[str(p)]=(series(1,p,8)[0]==0 and series(-1,p,8)[0]==0 and series(1+p,p,8)[0]%(p*p)==p)
checks=[];failures=[];negative={};overclaim=False
for row in rows:
D,p=(int(row['params'][k]) for k in ('D','p'));A=int(row['A']);f=fields[D];M=max(A+12,analytic[(D,p)][1]+14);mod=p**M
r,r0=hensel(D,p,M);e=(f['t']+f['u']*r)*pow(2,-1,mod)%mod
ell,cutoff=series(e,p,M);good=accept(row,ell,M)
decoded,stored_A=decode(row['number'],p);assert stored_A==A and decoded==int(row['residue'])
# Stored entry comments must name the same exact unit, branch and precision.
context=(int(re.search(r't_D=(\d+)',row['comment'])[1]),int(re.search(r'u_D=(\d+)',row['comment'])[1]),int(re.search(r'n_D=(-?\d+)',row['comment'])[1]),int(re.search(r'r_0=(\d+)',row['comment'])[1]))
assert context==(f['t'],f['u'],f['norm'],r0)
econj=(f['t']-f['u']*r)*pow(2,-1,mod)%mod;ellconj,_=series(econj,p,M)
assert econj*e%mod==f['norm']%mod and (ell+ellconj)%mod==0
assert ell%p==0
predicted=(ell//p)*2*f['h']*(p-1)*pow(r,-1,p**(M-1))%(p**(M-1))
lam,LA=analytic[(D,p)];assert M-1>=LA
consistency=(predicted-lam)%p**LA==0
if not good:failures.append(dict(D=D,p=p,kind='independent log series'))
if not consistency:failures.append(dict(D=D,p=p,kind='analytic companion consistency'))
corrupt=dict(row,residue=str((int(row['residue'])+p**(A-1))%p**A));assert not accept(corrupt,ell,M)
assert not accept(dict(row,A=0,residue='0'),ell,M)
if not overclaim and ell%p**(A+1)!=int(row['residue']):
overclaim=not accept(dict(row,A=A+1),ell,M);negative['overclaimed_modulus']=dict(D=D,p=p,rejected=overclaim)
if (D,p)==(5,11):
assert r0==4 and e%p==8 and econj%p==4
wrong_euler=ell*2*f['h']*pow(r,-1,mod)%mod
negative.update(omit_Euler_factor=(wrong_euler-lam)%p**LA!=0,square_norm_minus_one_unit=not accept(row,2*ell,M),reverse_root_sign_only=(-predicted-lam)%p**LA!=0)
# A stored L-value of precision LA implies this log modulo p^(LA+1)
# because h=1. No precision is inferred from numerical coincidence.
inverse=lam*p*r*pow(2*f['h']*(p-1),-1,p**(LA+1))%p**(LA+1)
assert (inverse-ell)%p**(LA+1)==0 and (LA+1)>=A
negative['recognition_round_trip']=True
if (D,p)==(40,3):negative['omit_class_number']=(predicted*pow(2,-1,p**(M-1))-lam)%p**LA!=0
checks.append(dict(D=D,p=p,matched=good,stored_A=A,check_A=M,series_cutoff=cutoff,root_residue=r0,root=str(r),unit_residue=e%p,log_residue=str(ell),companion_A=LA,companion_residue=str(lam),companion_consistent=consistency,analytic_prediction=str(predicted),conjugation_checked=True))
assert all(controls.values()) and all(v for v in negative.values() if isinstance(v,bool)) and overclaim and not failures
result=dict(checked_entries=len(rows),total_entries=len(rows),failures=failures,known_answer_control=all(controls.values()),negative_control_rejected=True,controls=controls,negative_controls=negative,fields=list(fields.values()),comparisons=checks,input_sha256=hashlib.sha256(path.read_bytes()).hexdigest(),companion_sha256=hashlib.sha256(companion_path.read_bytes()).hexdigest(),elapsed_s=time.monotonic()-start,skill_manifest='skill-manifest.json')
output.write_text(json.dumps(result,indent=2))
print('ARTIFACT',output.name,json.dumps(result),flush=True)
print('Checked',len(rows),'logarithms by independent series; all analytic companion comparisons matched; controls passed.',flush=True)
return result
if __name__=='__main__':
w=Path(__file__).parent
run(w/'unit-rows.json',w/'companion-stored-records.json',Path(sys.argv[1]) if len(sys.argv)>1 else w/'check-results.json')