back to table · edit · history · where entries came from · files · download
4656 bytes, as of the version from 2026-12-01 18:34 (current). Recorded here, not run.
"""Independent MPFI product check for all generated or stored root intervals.
Does not import the generator. Thue-Morse digits are built by morphism, not
bit parity. Q(z)=prod(1-z^(2^j)); its coefficients are (-1)^t_n by expanding
each binary subset. Thus A(z)=(1/(1-z)-Q(z))/2. Truncating at J factors has
absolute error <= z^(2^J)/(1-z^(2^J)), using 1-prod(1-a_j)<=sum(a_j).
Input: JSON list of records M,lo,hi with exact rational endpoints.
Output includes every checked endpoint, widths, residuals, and controls.
"""
import json, os, sys
from pathlib import Path
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.real_mpfi import RealIntervalField
I=RealIntervalField(640)
def thue_morphism(N):
word=[0]
while len(word)<N: word=word+[1-x for x in word]
return word[:N]
def product_A(z):
z=I(z); Q=I(1); power=z
for _ in range(12): Q*=1-power; power*=power
error=power/(1-power)
assert 0<error.upper()<QQ(1)/10**180
Q-=I(0,error.upper())
return (1/(1-z)-Q)/2
def sum_value(M,q):
z=1/I(q); A=product_A(z); k=M//2
return k/(I(q)-1) + (A if M%2 else (1-z)*A)
def check_record(r):
M=int(r['M']); l=QQ(r['lo']); u=QQ(r['hi'])
assert 1<l<u<M+1 and 0<u-l<QQ(1)/10**95
a=sum_value(M,l)-1; b=sum_value(M,u)-1
assert not a.lower().is_infinity() and not b.upper().is_infinity()
assert a.lower()>0 and b.upper()<0, 'root not enclosed'
assert a.absolute_diameter()<QQ(1)/10**180 and b.absolute_diameter()<QQ(1)/10**180
return {'M':M,'lo':str(l),'hi':str(u),'width':str(u-l),
'left_residual':str(a),'right_residual':str(b)}
def run(records):
word=thue_morphism(2048)
assert word[:9]==[0,1,1,0,1,0,0,1,1]
prefixes={}
for M in range(1,33):
k=M//2
d=[k+word[n] if M%2 else k+word[n]-word[n-1] for n in range(1,1025)]
assert all(0<=x<=M for x in d) and d[0]>0
prefixes[str(M)]=d[:8]
assert prefixes['1']==[1,1,0,1,0,0,1,1]
assert prefixes['2']==[2,1,0,2,0,1,2,1]
# Known nonzero exact coefficient identity at z=1/3, J=6.
z=QQ(1)/3
Q=QQ(1)
for j in range(6): Q*=1-z**(2**j)
assert Q==sum((1-2*word[n])*z**n for n in range(64)) and Q>0
# An independently formed 1024-digit sum at z=1/2 encloses the same A.
# Its tail is <=2^-1024. Require tight intersection and nonzero value.
finite=sum(QQ(word[n])/2**n for n in range(1024))
A=product_A(QQ(1)/2)
known=I(finite,finite+QQ(1)/2**1023)
assert A.overlaps(known) and A.lower()>QQ(4)/5 and A.upper()<1
assert A.absolute_diameter()<QQ(1)/10**180
checked=[]; failures=[]
for r in records:
try: checked.append(check_record(r))
except Exception as e: failures.append({'M':r['M'],'error':str(e)})
# Shift a narrow first interval by 10^-80: checker must reject it.
r=dict(records[0]); delta=QQ(1)/10**80
r.update(lo=str(QQ(r['lo'])+delta),hi=str(QQ(r['hi'])+delta))
rejected=False
try: check_record(r)
except AssertionError: rejected=True
assert rejected
# Wrong conventions: t_0 in the first position changes A to z*A;
# using the odd formula for even M drops the required (1-z) factor.
by_M={int(r['M']):r for r in records}
q1=I(QQ(by_M[1]['lo']),QQ(by_M[1]['hi'])); z1=1/q1
q2=I(QQ(by_M[2]['lo']),QQ(by_M[2]['hi'])); z2=1/q2
wrong_shift=z1*product_A(z1)
wrong_even=1/(q2-1)+product_A(z2)
assert wrong_shift.upper()<1 and wrong_even.lower()>1
return {'checked_entries':len(checked),'total_entries':len(records),
'known_answer_control':True,'negative_control_rejected':rejected,
'failures':failures,'checks':checked,'prefixes':prefixes,
'control':{'coefficient_identity_z':'1/3','factors':6,'exact_product':str(Q),
'A_half':str(A),'negative_shift':str(delta),
'index_shift_rejected':True,'incorrect_even_formula_rejected':True,
'wrong_shift_sum':str(wrong_shift),'wrong_even_sum':str(wrong_even)},
'independence':'MPFI product with certified omitted factors, no generator imports; morphism digits.',
'skill_manifest':'../20261201T182123Z-build-skills/manifest.json'}
if __name__=='__main__':
p=Path(os.environ.get('NUMBERDB_WORKDIR',Path(__file__).parent))
infile=Path(sys.argv[1]) if len(sys.argv)>1 else p/'generated-brackets.json'
out=Path(sys.argv[2]) if len(sys.argv)>2 else p/'product-check-results.json'
result=run(json.loads(infile.read_text()))
out.write_text(json.dumps(result,indent=2))
print(json.dumps({k:v for k,v in result.items() if k not in ['checks','prefixes','control']},indent=2))
assert not result['failures']