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

run('Derive the shared lifespan split','What change does separating the original1550 into600 and950 cause under one reversal?',
 lambda:model('lifespan_split_law',{'original_combined':1550,'original_separate':[600,950],'inverse_combined':inverse(1550),'inverse_separate':[inverse(600),inverse(950)],'loss':inverse(1550)-inverse(600)-inverse(950)}),
 'The combined inverse is5510; the separate lives give600+590=1190. Restoring the Shem division therefore lowers the transformed total by4320.',
 'Test the predicted4320 against every manuscript, including the completed contexts.')

run('Verify the common4320 response','Does one local split explain all FN-to-FSN head changes?',
 lambda:{m:{'held_heads':[model('partitions_'+m)[p]['path1406'][-1] for p in ['FN','FSN']],'completed_heads':[model('partitions_'+m)[p]['path6'][-1] for p in ['FN','FSN']],'loss':model('partitions_'+m)['FN']['total']-model('partitions_'+m)['FSN']['total']} for m in ['MT','LXX','SP']},
 'The held pairs13016/8696,17956/13636 and11416/7096 all differ4320; their Nativity-extended pairs retain the same loss.',
 'Explain why the starting FN heads differ from each primary Flood head.')

run('Derive the upper1550 partition response','How much does separating1550 from the remaining upperprefix change each primary trunk?',
 lambda:model('upper_1550_law',{m:{'prefix':c,'primary_upper':inverse(1550+c),'Noah_grouped_upper':inverse(1550)+inverse(c),'gain':inverse(1550)+inverse(c)-inverse(1550+c)} for m,c in [('MT',7620),('LXX',7600),('SP',7130)]}),
 'The upper gains are990 forMT,7020 forLXX and0 forSP. The lower merge contributes zero in each case.',
 'Combine the upper gain and shared split loss into one full-refinement law.')

run('Predict all fully refined heads','Does upper gain minus4320 reconstruct the changes from primary Flood to all named cuts?',
 lambda:model('refinement_law',{m:{'upper_gain':model('upper_1550_law')[m]['gain'],'split_loss':4320,'predicted_change':model('upper_1550_law')[m]['gain']-4320,'observed_change':model('partitions_'+m)['FSN']['total']-model('partitions_'+m)['F']['total']} for m in ['MT','LXX','SP']}),
 'The common law gives−3330, +2700 and−4320 forMT, LXX andSP, exactly the observed three responses.',
 'Trace the large LXX upper gain to its source rows and decimal register.')

run('Trace theMT/LXX prefix difference to Lamech','Which source lifespan causes the20-year prefix difference?',
 lambda:{'rounded_differences':[b-a for a,b in zip(model('prefix_source_rows')['rounded']['MT'],model('prefix_source_rows')['rounded']['LXX'])],'actual_Lamech':[777,753],'rounded_Lamech':[775,755],'prefixes':[7620,7600]},
 'The first eight rounded preNoah lives agree; selected Lamech775 versus755 accounts for the entire−20 prefix difference.',
 'Inspect how that small difference changes the retained trailing-zero register.', ['File18.md selected753 decision','File51a.md roundingrule'])

run('Explain the decimal amplification','Why does the20-year prefix difference become4030 after reversal?',
 lambda:{'MT':{'source':7620,'core':762,'zeros':1,'inverse':inverse(7620)},'LXX':{'source':7600,'core':76,'zeros':2,'inverse':inverse(7600)},'source_difference':7600-7620,'inverse_difference':inverse(7600)-inverse(7620)},
 '7620 reverses to2670 while7600 reverses to6700. The selected row difference crosses the significant-core/trailing-zero register, producing+4030.',
 'Combine this upper difference with the separately retained lower910 difference.')

run('Locate the retained lower910 difference','Does the cumulativeNoah lower branch preserve theLXX–MT910 separation?',
 lambda:{'source_lower':[6386-1406,7296-1406],'source_difference':7296-6386,'inverse_lower':[inverse(4980),inverse(5890)],'inverse_difference':inverse(5890)-inverse(4980),'refined_lower':[3430+600+590,4340+600+590]},
 'The lower Noah branch remains910 longer inLXX, both when grouped and when its shared lives are explicit.',
 'Use910+4030 to account for the complete MT/LXX inverse head separation.')

run('Explain the4940 head separation','Do the lower and upper differences account for both Noah-partition comparisons?',
 lambda:{'source_head_gap':14896-14006,'source_decomposition':[910,-20],'inverse_decomposition':[910,4030],'Noah_head_gap':model('partitions_LXX')['N']['path1406'][-1]-model('partitions_MT')['N']['path1406'][-1],'fully_refined_gap':model('partitions_LXX')['FSN']['path1406'][-1]-model('partitions_MT')['FSN']['path1406'][-1]},
 'The source gap890=910−20 becomes inverse4940=910+4030; the common4320 split leaves that difference intact.',
 'Classify theSP equivalence among its selected partitions.')

run('Classify theSP partition family','Which of the sevenSP constructions share a head, and why?',
 lambda:{'classes':{'11416':[p for p in model('partitions_SP') if model('partitions_SP')[p]['path1406'][-1]==11416],'7096':[p for p in model('partitions_SP') if model('partitions_SP')[p]['path1406'][-1]==7096]},'upper1550_gain':model('upper_1550_law')['SP']['gain'],'600_refinement':'inheritedzero localdefects','explicit_life_loss':4320},
 'F/S/N/FS/FN form oneSP head class, whileSN/FSN form a second4320 later. The same local laws explain both classes.',
 'Determine exactly how the earlier SP upper-branch translation changes through Noah.')

run('Extend theSP branch throughNoah','Does the prior uniform upper-branch translation survive theexplicit950-year life?',
 lambda:model('SP_refinement_scope',{'source_branch':[4716,5316,6266,13396],'inverse_branch':model('partitions_SP')['FSN']['path1406'][1:],'node_shifts':[y-x for x,y in zip([4716,5316,6266,13396],model('partitions_SP')['FSN']['path1406'][1:])],'new_local_contractions':[950-inverse(950),7130-inverse(7130)]}),
 'The shifts are−1980,−1980,−2340,−6300. TheShem edge stays intact; Noah’s life contracts360 and the remaining prefix3960. Their4320 sum explains why uniform translation stops.',
 'Investigate theLXX+2700 result as a relation between refinement and stage completion.')
