from pathlib import Path
import sys,json
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
from runner import *

run('Connect LXX refinement to completion','Does the LXX full-refinement gain equal its original Nativity-stage change?',
 lambda:model('LXX_completion_join',{'refined_held_path':model('partitions_LXX')['FSN']['path1406'],'primary_completed_path':model('partitions_LXX')['F']['path6'],'refinement_gain':model('refinement_law')['LXX']['observed_change'],'stage_gain':inverse(1400)-1400,'common_head':model('partitions_LXX')['FSN']['path1406'][-1]}),
 'Both routes reach13636: the LXX upper refinement gains2700, exactly matching4100−1400 from the Nativity extension.',
 'Test the same equality inMT andSP to identify the actual family scope.')

run('Compare the completion relation across manuscripts','Which traditions have equality between the fully refined held head and primary completed head?',
 lambda:model('refinement_scope',{m:{'refined_held':model('partitions_'+m)['FSN']['path1406'][-1],'primary_completed':model('partitions_'+m)['F']['path6'][-1],'signed_difference':model('partitions_'+m)['FSN']['path1406'][-1]-model('partitions_'+m)['F']['path6'][-1]} for m in ['MT','LXX','SP']}),
 'The signed differences are−6030,0,−7020 forMT/LXX/SP. This particular refinement–completion equality belongs to the selectedLXX source values.',
 'Compare the internalLXX paths so equal heads do not erase distinct constructions.')

run('Compare the twoLXX routes internally','Do the two routes to13636 also agree at their intermediate nodes?',
 lambda:{'refined_Conquest':[1406,5746,6346,6936,13636],'primary_Nativity':[6,4106,8446,13636],'common_nodes':sorted(set(model('partitions_LXX')['FSN']['path1406'])&set(model('partitions_LXX')['F']['path6']))},
 'The selected paths share only their head13636. One retains Flood/Shem/Noah from1406; the other retains the primary Flood path after the Nativity extension.',
 'Check that stage translation still preserves all named refinement differences.')

run('Verify stage compatibility for the whole named family','Does prepending1400 preserve every internal suffix and partition difference in all21 constructions?',
 lambda:{m:{p:{'suffix_displacements':[y-x for x,y in zip(v['path1406'],v['path6'][1:])],'total_head_change':v['path6'][-1]-v['path1406'][-1]} for p,v in model('partitions_'+m).items()} for m in ['MT','LXX','SP']},
 'Every suffix node shifts2700 in all21 paths. Hence the local refinement laws apply unchanged in either held-anchor context.',
 'Record theSP completed-source relation as a consequence of the same law.')

run('Explain theSP completed refinement relative to its source','How does the completed full-refinement head sit relative to acceptedSPFall?',
 lambda:{'source_Fall':13396,'primary_completed':14116,'refined_completed':model('partitions_SP')['FSN']['path6'][-1],'primary_source_shift':14116-13396,'refined_source_shift':model('partitions_SP')['FSN']['path6'][-1]-13396,'decomposition':[720,-4320]},
 'The completed refined head9796 is3600 later than sourceFall13396: the earlier+720 shift minus4320 becomes−3600.',
 'Retain this as a derived corollary, then connect the2730 form to its existingMT placement.')

run('Locate an existingMT placement of2730','Does the source’s MT Year-6/Terah comparison supply the same appointed interval asSP2736→6?',
 lambda:{'source_pair':[4176,1446],'source_role':'MT Year-6 with+60Terah toExodus','SP_pair':[2736,6],'translation':1440,'translated_SP':[2736+1440,6+1440],'lengths':[4176-1446,2736-6]},
 'The sourceMT4176→1446 interval is the exact+1440 translation ofSP2736→6; both measure2730. The MT comparison retains its declaredYear-6/+60 state.',
 'Use this as an existing placement of the same calendar-form interval, not as a new source state.', ['File17.md §13.1,13.4','File29.md §4.2'])

run('Separate inheritedNoah results from comparative extension','Which pieces of theNoah study were already in the corpus?',
 lambda:model('claim_ledger_second50',{'inherited':['MT cumulativeNoah6386','MT Noah/FloodNoah13016 secondaryhead','sourceNoah950 andShem600','primarysixspines','placeholder-preservinginverse'],'comparative_synthesis':['allthreeN=FN','shared4320 splitlaw','LXX source-row/register explanation','LXX13636 refinement/completion join','complete21partitiontable'],'derived_corollary':['SP completedrefinedhead3600 afterFall'],'no_claim':['seconddecimalreversal','newcanonicalchronology','sourceindependentstatisticalevidence']}),
 'The manuscript comparison and local laws extend establishedMT controls; the inheritedMT branch is not presented as rediscovered.',
 'Summarize how these findings change the common grammar before editing the reader.')

run('Update the explanatory kernel','What does theNoah comparison add to the earlier Babylonian synthesis?',
 lambda:model('final_kernel',{'source_layer':'namedlifespanrows andfixedsourceanchors','path_layer':'single reversaloforiginalpartitionlegs','local_law':'uppergain−common4320 explainsfullrefinement','placement_layer':'stage translations,wholeShem edge,namedBabylonian/Covenantcuts','relations':['allthreeNoahmergeadditivity','allthree1550splitloss','LXXrefinementcompletionjoin'],'interpretation':'sharedoperations generateagreementandstructureddifference;noonechronologyforced'}),
 'The grammar now explains both cross-family junctions and their partition sensitivity from the same source lives and operations.',
 'Write a compactNoah subsection, then integrate both new families into the main explanation.')
