back to table · edit · history · where entries came from · files · download
5299 bytes, as of the version from 2026-12-01 18:15 (current). Recorded here, not run.
"""Independent regular paperfolding digit check for all recorded values.
Run: sage -python check_values.py entries.json [results.json]
Requires only Python's exact Fraction and the JSON entries exported from
NumberDB. The campaign runs it through agents/sage.sh, as for every Sage job.
It does not import the production generator or use its grouped sum.
Starting from the empty word, replace w by w+[1]+reverse(complement(w)).
For N fractional digits the exact base-b value is S_N and the tail is in
[0,b^(-N)/(b-1)]. Containment in the decimal interval, not midpoint agreement,
is required. The decimal interval has radius one unit in its last place.
"""
import json
import sys
from pathlib import Path
from fractions import Fraction as Q
def folding_word(length):
word = []
while len(word) < length:
word = word + [1] + [1-x for x in reversed(word)]
return word[:length]
def digit_bracket(b, digits=130):
N = 1
while b**N < b * 10**digits:
N += 1
numerator = 0
for digit in folding_word(N):
numerator = b*numerator + digit
lower = Q(numerator, b**N)
tail = Q(1, b**N * (b-1))
return lower, lower + tail, N
def decimal_bracket(text):
from decimal import Decimal
d = Decimal(text)
if not d.is_finite():
raise ValueError('nonfinite decimal')
centre = Q(d)
exp = d.as_tuple().exponent
ulp = Q(10)**exp
significant = len(d.as_tuple().digits)
return centre-ulp, centre+ulp, ulp, significant
def contained(lo, hi, lower, upper, digits=99):
return (lo <= hi and lower < upper and
upper-lower <= Q(1,10**digits) and lower <= lo <= hi <= upper)
def check(entries):
known = folding_word(16) == [1,1,0,1,1,0,0,1,1,1,0,0,1,0,0,1]
known = known and Q(int('1101',2),2**4) == Q(13,16)
known = known and contained(Q(1,3),Q(1,3)+Q(1,10**132),Q(1,3)-Q(1,10**100),Q(1,3)+Q(1,10**100))
result={'checked_entries':0,'total_entries':len(entries),'failures':[],
'known_answer_control':bool(known),'negative_control_rejected':False,
'method':'Independent recursive folding word; exact rational radix evaluation and geometric tail containment.',
'independence':'No production generator import or grouped-sum evaluation. Odd-part rule checks the word separately.',
'rows':[],'controls':{},'selection':[str(e['params']['b']) for e in entries]}
word=folding_word(1023)
for n,digit in enumerate(word,1):
odd=n
while odd%2==0:odd//=2
if digit != int(odd%4==1):result['failures'].append('folding/odd-part mismatch at '+str(n))
result['odd_part_prefix_checked']=1023
if result['selection']!=[str(b) for b in range(2,17)]:result['failures'].append('selection differs from b=2,...,16')
negative=[]
for entry in entries:
b=int(entry['params']['b']);lo,hi,N=digit_bracket(b)
lower,upper,ulp,significant=decimal_bracket(entry['number'])
ok=contained(lo,hi,lower,upper) and significant==100
# Check the functional equation against a second independent digit
# evaluation at radix b^2, without adding any stored entries.
lo2,hi2,N2=digit_bracket(b*b)
odd_part=Q(b**3,b**4-1)
functional=lo <= hi2+odd_part and lo2+odd_part <= hi
# Missing j=0, a one-place shift, a ten-ulp mutation, and a vacuous
# interval must all be rejected, at every radix.
tests={
'omitted_j0':not contained(lo,hi,lower-odd_part,upper-odd_part),
'radix_shift':not contained(lo,hi,b*lower,b*upper),
'ten_ulp_change':not contained(lo,hi,lower+10*ulp,upper+10*ulp),
'wide_interval':not contained(lo,hi,Q(-10),Q(10))}
negative.extend(tests.values())
if not ok:result['failures'].append('stored interval containment failed at b='+str(b))
if not functional:result['failures'].append('functional identity failed at b='+str(b))
result['rows'].append({'b':b,'N':N,'tail':str(hi-lo),'stored_ulp':str(ulp),
'digits':significant,'contained':bool(ok),'functional_identity':bool(functional),
'tail_over_ulp':str((hi-lo)/ulp),
'lower_margin_ulps':str((lo-lower)/ulp),
'upper_margin_ulps':str((upper-hi)/ulp),'negative_controls':tests})
result['checked_entries']+=1
try:decimal_bracket('NaN')
except ValueError:nan_rejected=True
else:nan_rejected=False
result['controls']={'source_prefix_16':bool(known),'exact_binary_prefix_4':'13/16',
'odd_part_prefix':1023,'nan_rejected':nan_rejected,'wrong_inputs_per_base':4}
result['negative_control_rejected']=bool(negative and all(negative) and nan_rejected)
if not known:result['failures'].append('known answer control failed')
if not result['negative_control_rejected']:result['failures'].append('negative control failed')
return result
if __name__ == '__main__':
source=Path(sys.argv[1]) if len(sys.argv)>1 else Path(__file__).with_name('entries.json')
entries=json.loads(source.read_text())
results=check(entries)
encoded=json.dumps(results,indent=2)+'\n'
if len(sys.argv)>2:Path(sys.argv[2]).write_text(encoded)
print('CHECK_JSON='+json.dumps(results))
raise SystemExit(bool(results['failures']))