from pathlib import Path
from fractions import Fraction
import hashlib,json,re,ast
ROOT=Path('/workspace/scratch/1b40da62dcbd/c832_c931')
SRC=ROOT/'evidence/sources/File52c_latest.md'
raw=SRC.read_text()
expected='a5ea84562101158b60d0cf296765d6eff38e7a2abda4e74ad1b353dfd13b9530'
checks={'primary_source_hash':hashlib.sha256(SRC.read_bytes()).hexdigest()==expected}
assert checks['primary_source_hash']
def extract_section(start,end):
return raw.split(start,1)[1].split(end,1)[0]
def numeric_rows(section):
return [[c.strip() for c in line.split('|')[1:-1]] for line in section.splitlines() if re.match(r'^\|\s*\d+\s*\|',line)]
manifest=numeric_rows(extract_section('### 2.1 The 32 admitted dates','### 2.2'))
nat=numeric_rows(extract_section('### A.2 Nativity-family inverses','### A.3'))
con=numeric_rows(extract_section('### A.3 Conquest-family inverses','### A.4'))
assert len(manifest)==len(nat)==len(con)==32
def forward_arithmetic(n):
# Integer arithmetic, independent of both the prepared string reversal
# and the completed positional-vector calculation. No output is re-used.
assert n>0
scale=1
while n%10==0:
n//=10
scale*=10
answer=0
while n:
n,digit=divmod(n,10)
answer=10*answer+digit
return scale*answer
packet=json.loads((ROOT/'model/inverse_inputs.json').read_text())
field=json.loads((ROOT/'model/inverse_paired_field.json').read_text())
gains=json.loads((ROOT/'model/inverse_gain_field.json').read_text())
long=json.loads((ROOT/'model/inverse_long_core_branches.json').read_text())
short=json.loads((ROOT/'model/inverse_short_core_branches.json').read_text())
journal={s['step']:s for s in json.loads((ROOT/'journal.json').read_text()) if 850<=s['step']<=858}
rows=[]; wanted_long={};wanted_short={};wanted_zero={};pair_deltas=[]
for i,(m,N,C,p,f,g) in enumerate(zip(manifest,nat,con,packet['source_rows'],field,gains),1):
num,name,date=int(m[0]),m[1],int(m[2])
assert num==i==int(N[0])==int(C[0])==p['number']
assert name==p['source_name']==f['name']==g['name']
assert date==p['source_BC']==f['source_BC']
a0=6 if date%10==6 else 1
assert date%10 in [1,6]
endpoints=[];route_results=[]
for role,literal in [('Nativity',N),('Conquest',C)]:
anchor=int(literal[1]);end=int(literal[2]);span=date-anchor
assert anchor==a0+(1400 if role=='Conquest' else 0)
generated=anchor+forward_arithmetic(span)
v=f['routes'][role]
assert anchor==p[role]['anchor_BC']==v['anchor']
assert generated==end==p[role]['endpoint_BC']==v['endpoint']==v['literal']==v['positional']
assert span==v['duration']
assert end-date==g['gain_N' if role=='Nativity' else 'gain_C']
endpoints.append(end)
route_results.append({'role':role,'anchor':anchor,'original_duration':span,'literal_endpoint':end,'independent_endpoint':generated})
n=(date-a0)//10;a,b,c=n//100,n//10%10,n%10;delta=endpoints[1]-endpoints[0]
assert delta==g['delta']==g['gain_C']-g['gain_N'] and n==g['n']
if c==0:
assert n in [200,410]
branch='retained_zero';prediction=0 if n==200 else 7200
wanted_zero[name]=prediction
elif n>=240:
branch='no_borrow' if b>=4 else 'borrow'
prediction=990 if b>=4 else 1980
wanted_long[name]=(prediction,int(b<4),[a-1-int(b<4),b-4+10*int(b<4),c])
elif n>=150:
branch='three-to-two';prediction=1260+90*a-90*b-900*c
wanted_short[name]=(prediction,branch)
else:
assert 144<=n<150
branch='three-to-one';prediction=990-990*c
wanted_short[name]=(prediction,branch)
assert prediction==delta
rows.append({'number':i,'name':name,'date':date,'n':n,'branch':branch,'independent_delta':prediction,'literal_delta':delta,'routes':route_results})
pair_deltas.append(delta)
checks['all_32_source_rows_match_literal_manifest']=True
checks['all_64_original_endpoints_independently_reconstruct']=True
checks['all_32_gain_identities_match']=True
checks['all_32_branch_formulas_match']=True
checks['long_branches_match']=len(long)==len(wanted_long) and all((x['predicted_delta'],x['borrow'],x['shifted_digits'])==wanted_long[x['name']] and x['observed_delta']==x['predicted_delta'] for x in long)
checks['short_branches_match']=len(short)==len(wanted_short) and all((x['predicted'],x['register_change'])==wanted_short[x['name']] and x['observed']==x['predicted'] for x in short)
checks['zero_branches_match']={x['name']:x['delta'] for x in journal[856]['results']['retained_zero_cases']}==wanted_zero
checks['case_partition_14_16_2']=journal[856]['results']['complete_case_partition']==[len(wanted_long),len(wanted_short),len(wanted_zero)]==[14,16,2]
covered=list(wanted_long)+list(wanted_short)+list(wanted_zero)
checks['complete_disjoint_branch_cover']=len(covered)==len(set(covered))==32 and set(covered)=={m[1] for m in manifest}
checks['journal_full_gain_vector']=journal[853]['results']['paired_delta']==pair_deltas
by_name={r['name']:r for r in rows}
u,U=[x['literal_endpoint'] for x in by_name['Seth']['routes']]
v,V=[x['literal_endpoint'] for x in by_name['Enosh']['routes']]
slope=Fraction(V-U,v-u);intercept=U-slope*u
x,y=[x['literal_endpoint'] for x in by_name['Lamech']['routes']]
pred=slope*x+intercept
checks['affine_obstruction_exact']=(slope,intercept,pred,y)==(1,990,4226,5216)
# Structural inspection of all completed scripts: the only executed inverse
# call in this block is s852's original local variable `duration`.
calls=[]
for step in range(850,859):
code=(ROOT/f'evidence/s{step}.py').read_text()
for node in ast.walk(ast.parse(code)):
if isinstance(node,ast.Call) and isinstance(node.func,ast.Name) and node.func.id=='inv':
calls.append({'step':step,'line':node.lineno,'argument':ast.unparse(node.args[0])})
checks['inverse_calls_use_only_original_duration']=len(calls)==1 and calls[0]['step']==852 and calls[0]['argument']=='duration'
checks['C851_is_twenty_step_checkpoint']=851-832+1==20 and journal[851]['checks']['twenty'] is True
def digest(path):return hashlib.sha256(path.read_bytes()).hexdigest()
observed_files={str(p.relative_to(ROOT)):digest(p) for p in [SRC,*[ROOT/f'evidence/s{i}.py' for i in range(850,859)],*[ROOT/'model'/name for name in ['inverse_inputs.json','inverse_paired_field.json','inverse_gain_field.json','inverse_long_core_branches.json','inverse_short_core_branches.json','inverse_module_summary.json']]]}
assert all(checks.values()),checks
result={'review':'Independent forward-arithmetic and literal-source review of C850–C858','status':'PASS','source_sha256':expected,'checks':checks,'scope':'No target columns, frequency scan, or second inversion; source manifest fixed. C851 count/scope reviewed, not a fresh audit of the earlier File58 results.','inverse_call_inspection':calls,'rows':rows,'observed_file_sha256':observed_files,'overclaims':[],'presentation_qualifications':['The compact branch formulas cover this fixed manifest and its explicitly stated digit domains; they are not a universal formula for arbitrary source dates.','The gain field explains arithmetic route dependence, not why historical source chronologies contain these particular digits.']}
(ROOT/'evidence/INDEPENDENT_C850_C858.json').write_text(json.dumps(result,indent=2)+'\n')
print(json.dumps({'status':result['status'],'checks':len(checks),'rows':len(rows),'endpoints':sum(len(x['routes']) for x in rows),'inverse_calls':calls}))
Evidence
independent review C850 C858.py
Linked sources and evidence
Edition and provenance
independent_review_C850_C858.py
SHA-256 4a0912485503943153452dc674a6b2ca67c939244dfe14942f2187b05928a4c9
C480–C1634/Research_Cycles/C0832_C0931/prep/independent_review_C850_C858.py