from pathlib import Path
from fractions import Fraction as F
from itertools import product
from functools import reduce
from math import gcd,lcm
import json,hashlib
BASE=Path('/workspace/scratch/1b40da62dcbd');OUT=BASE/'c932_c1131/prep/key_constraints'
qsha=hashlib.sha256((OUT/'questions.json').read_bytes()).hexdigest();q2sha=hashlib.sha256((OUT/'questions_addendum.json').read_bytes()).hexdigest()
def clean(x):
if isinstance(x,F):return x.numerator if x.denominator==1 else str(x)
if isinstance(x,dict):return {str(k):clean(v) for k,v in x.items()}
if isinstance(x,(tuple,list)):return [clean(v) for v in x]
return x
def save(n,o):(OUT/n).write_text(json.dumps(clean(o),indent=2)+'\n')
paths={
'Strategy':BASE/'upload/490d_Unification_Research_Strategy_v0_2_20260906.md',
'File12':BASE/'project_sources/16-File_12.Calendrical_Physics-20260907-192303-.md',
'File46':BASE/'project_sources/20-File_46.Harmonic_Expansion_Protocols-1-.md',
'File60':BASE/'project_sources/36-File_60.Levitical_Covenant_Spine_161_299_Key_of_23_Reconciliation-10-.md',
'File63':BASE/'project_sources/09-File_63.Scale_Neutral_480_483_490_Carrier-20260821-143254-.md',
'SupplementA':BASE/'project_sources/14-file_70-supplement-a-key-of-23-fine-resolution-720-30-rail-2-.md',
'File52c_latest':BASE/'upload/File_52c.Rounded_Whole_Span_Inverse_Detailed_Study_Draft (2)(1).md',
'prior_index':BASE/'c832_c931/prep/completed_family_index_C482_C831.tsv'}
sources={k:{'path':str(p),'sha256':hashlib.sha256(p.read_bytes()).hexdigest()} for k,p in paths.items()}
def ex(key,lo,hi):return {'source':key,'lines':[lo,hi],'text':'\n'.join(paths[key].read_text().splitlines()[lo-1:hi])}
prior={}
sel={'c482_c531':[505,506,507,509,511],'c532_c631':[532,533,568,569,570,571,574,575,609],'c632_c731':[666,667,690,713,714,715],'c832_c931':[873,880,881,885,886,887,889,898,901,906,908,910]}
for cyc,steps in sel.items():
p=BASE/cyc/'journal.json';jj=json.loads(p.read_text())
prior[cyc]={'path':str(p),'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'selected_records':[s for s in jj if s['step'] in steps]}
packet={'status':'Frozen literal/source-controlled inputs, prepared after question manifests and before diagnostics; no numbered actions.', 'question_hashes':{'questions.json':qsha,'questions_addendum.json':q2sha},'sources':sources,
'excerpts':[ex('Strategy',109,141),ex('File12',263,264),ex('File46',148,245),ex('File46',363,382),ex('File60',1027,1142),ex('File63',568,613),ex('File63',1799,1851),ex('File63',2868,2900),ex('SupplementA',517,558),ex('SupplementA',2130,2194)],
'literal_inputs':{'calendar_measures':{'E':336,'P':360,'J':364},'known_keys':{'E':[25,23],'P':[70,69],'J':[300,299]},'source_partitions':{'dual490':['805/2','161/2'],'actual12558':[12075,483],'retained_macro':[9660,2940],'Covenant':[299,161]},'source_path_actual12558':[14004,1929,1446],'source_retained_macro_path':[14006,4346,1406], 'source_SupplementA_table':[[690,700,750],[720,730,780],[750,760,810]],'source_macro_totals':[12600,12740,13440],'File46_heads':[14926,14896,14466,14436,14006],'File46_head_anchor':14006,'fixed_diagnostic_pivots':[14006,4836]},'prior_results':prior,
'scope':['Source-appointed cuts and generated fractions remain separate.','No newly licensed mixed chronology routes.','No new target tally, Gear propagation, second decimal inversion, primer research or unlimited word search.','Mixed-unit interpretations below are conditional calendrical realizations, not literal calendar claims for the source chronology.']}
save('sourcepacket.json',packet)
E,P,J=F(25,23),F(70,69),F(300,299);keys={'E':E,'P':P,'J':J};days={'E':336,'P':360,'J':364};K=336*E
# Exact linear algebra without external packages.
def rref(mat):
a=[[F(x) for x in row] for row in mat];r=0;piv=[]
for c in range(len(a[0])):
ii=next((i for i in range(r,len(a)) if a[i][c]),None)
if ii is None:continue
a[r],a[ii]=a[ii],a[r];v=a[r][c];a[r]=[x/v for x in a[r]]
for i in range(len(a)):
if i!=r:
t=a[i][c];a[i]=[x-t*y for x,y in zip(a[i],a[r])]
piv.append(c);r+=1
if r==len(a):break
return a,piv
A=[[336,-360,0],[336,0,-364],[1,-6,0],[1,0,-26]];b=[0,0,-5,-25]
rr,pp=rref([row+[v] for row,v in zip(A,b)]);rank=len(rref(A)[1]);dep=[7,-6,-420,84]
assert [sum(dep[i]*A[i][j] for i in range(4)) for j in range(3)]==[0,0,0]
assert sum(dep[i]*b[i] for i in range(4))==0
solve_E=lambda dt,f:F(dt)*(1-f)/(336-F(dt)*f)
EP=solve_E(360,F(1,6));EJ=solve_E(364,F(1,26));perturb=solve_E(364,F(1,25))
alloc=lambda f,k:1+f*(k-1)
fractions={a+'→'+b:(keys[b]-1)/(keys[a]-1) for a,b in [('E','P'),('P','J'),('E','J')]}
diag={'questions_bound_before_computation':[qsha,q2sha], 'calibration_allocation_basis':{'coefficient_matrix':A,'rhs':b,'rank':rank,'augmented_rref':rr,'left_dependence':dep,'E_from_336_360_1over6':EP,'E_from_336_364_1over26':EJ,'common_K':K,'free_calibration_family':'(E,P,J)=K*(1/336,1/360,1/364) before adding a source allocation','predicted_f_E_to_J_from_EP_and364':((336*EP/F(364))-1)/(EP-1),'diagnostic_f1over25_E':perturb,'diagnostic_E_difference':perturb-E},
'allocation_triangle':{'fractions':fractions,'nested_product':fractions['E→P']*fractions['P→J'],'nested_selected_factor':alloc(fractions['P→J'],alloc(fractions['E→P'],E)),'sequential_PJ_factor':P*J,'proof':'A_g(A_f(k))=1+g*f*(k-1)=A_(gf)(k); this is selection composition, not applying two chronological Keys in succession.'}}
# Component defects on the fixed existing source objects: old values, new common linear comparison.
partcases=[('483_final_E',[F(805,2),F(161,2)],[1,E]),('12558_final_E',[12075,483],[1,E]),('12600_upper_P',[9660,2940],[P,1]),('12600_upper_E',[9660,2940],[E,1])]
rows=[]
for name,v,ks in partcases:
v=list(map(F,v));ks=list(map(F,ks));T=sum(v);part=[x*k for x,k in zip(v,ks)];eff=sum(part)/T;uniform=[eff*x for x in v];delta=[x-y for x,y in zip(part,uniform)];assert sum(delta)==0
rows.append({'name':name,'source_parts':v,'component_factors':ks,'effective_factor':eff,'partial_image':part,'uniform_image':uniform,'difference_vector':delta,'difference_sum':sum(delta)})
diag['component_defect_family']={'status':'Existing source examples C609/C714–715; new compression into the kernel of total evaluation.','rows':rows,'general_two_part_defect':'For upper fractionf and factor k there, delta=(k−1)f(1−f)S*(1,−1); reverse component order reverses the sign.','coarsening_criterion':'C*diag(k_i)=diag(kbar_B)*C for all vectors iff all k_i in each coarsened blockB equal kbar_B.','counterexample':'Weight-dependent effective factors can make equality true for one fixed vector without a commuting operator square.'}
# Retained component u and untouched v produce native/P/E triple, whose independent measurements have rank2.
B=[[1,1],[P,1],[E,1]];null=[5,-6,1]
assert all(sum(null[i]*B[i][j] for i in range(3))==0 for j in range(2))
outputs=[]
for u,v in [(690,0),(690,30),(690,60),(9660,2940)]:
T=[F(u+v),P*u+v,E*u+v];rec_u=69*(T[1]-T[0]);rec_v=T[0]-rec_u
outputs.append({'source_u_v':[u,v],'native_P_E':T,'constraint':5*T[0]-6*T[1]+T[2],'recovered_u_v':[rec_u,rec_v]})
diag['retained_total_measurement_basis']={'matrix':B,'rank':len(rref(B)[1]),'left_constraint':null,'det_native_P':1-P,'inverse':'u=69(T_P−T_0); v=T_0−u','complete_fixed_rows':outputs,'limitation':'Recovers numerical parts only; does not infer their source roles, order, anchors or source authorization.'}
# 529 ladder dependency certificate: normalized inherited values, not new discovery.
diag['inherited_529_constraint_basis']={'primitive_pair':[23,25],'normalized_ladder':[529,575,625],'gain_pair':[46,50],'geometric_relation':575**2-529*625,'second_difference':625-2*575+529,'total_gain':625-529,'middle_minus_arithmetic_midpoint':F(575)-F(529+625,2),'novelty':'Low priority compression only; C505 already proved the ladder.'}
# New affine two-stage congruence theorem with the source pivots held.
def stage_coset(k1,k2,a,b):
a,b=int(a),int(b);p1,q1=k1.numerator,k1.denominator;q2=k2.denominator;g=gcd(p1,q2)
if (b-a)%g:return {'nonempty':False,'obstruction_divisor':g,'pivot_difference_mod_g':(b-a)%g}
qred=q2//g;t0=0 if qred==1 else (((b-a)//g)*pow(p1//g,-1,qred))%qred
per=q1*qred;res=(a+q1*t0)%per
# Exact coefficient check at the generated congruence representative; no historical label assigned.
x=F(res);y=a+k1*(x-a);z=b+k2*(y-b);assert y.denominator==z.denominator==1
return {'nonempty':True,'obstruction_divisor':g,'residue':res,'period':per,'formula':'x=residue+period*n, n integer; representative is not an event date'}
pivots=(14006,4836);arows=[]
for akey,bkey in product(keys,repeat=2):arows.append({'execution':akey+'→'+bkey,'first_pivot':pivots[0],'second_pivot':pivots[1],**stage_coset(keys[akey],keys[bkey],*pivots)})
known=[]
for name,xs,a,b in [('C480',[2148,3206],3620,2756),('fixed12026',[4114,3056],12026,12026)]:
c=stage_coset(E,E,a,b);known.append({'case':name,'fixed_points':xs,'coset':c,'placement_matches':[int((x-c['residue'])%c['period'])==0 for x in xs],'difference_lattice_divides_period':(xs[1]-xs[0])%c['period']==0})
diag['affine_prefix_cosets']={'scope':'Whole-stage integer membership for fixed integer pivots, diagnostic compositions unless source already licensed.','derivation':['First integer image iff x=a+q1*t.','First image is a+p1*t.','Second integer image iff p1*t≡b−a modq2.','g=gcd(p1,q2); solvable iff g dividesb−a; periodq1*q2/g.'],'fixed_nine_pairs':arows,'inherited_witnesses':known,'whole_field':'A nonempty coset contains all points iff one point has the right residue and every source difference is divisible by its period.','covariance':'Adding the same integer t to all points and both pivots adds t to the residue; the period and obstruction are unchanged.'}
for row in arows:
if row['nonempty']:
akey,bkey=row['execution'].split('→');move=30;c=stage_coset(keys[akey],keys[bkey],pivots[0]+move,pivots[1]+move)
assert c['period']==row['period'] and c['residue']==(row['residue']+move)%row['period']
heads=[14926,14896,14466,14436,14006];anchor=14006;gaps=[x-anchor for x in heads];step=reduce(gcd,gaps);idx=[d//step for d in gaps];images=[anchor+E*d for d in gaps]
diag['exact_full_field_normal_form']={'source_anchor':anchor,'difference_mesh':step,'labelled_indices':idx,'source_heads':heads,'image_difference_mesh':E*step,'image_heads':images,'integer_image_indices':[i for i in idx if (E*step*i).denominator==1],'formula':'Source=a+10*n; image=a+(250/23)*n. The finite index pattern is retained; its comparison mesh changes.','status':'Exact affine comparison lattice, not a new calendar or historical date grid.'}
# Complete predetermined mixed-calendar field on299|161. Conditional calendar realization only.
assign=[]
for k1,k2 in product(keys,repeat=2):
vals=[299*keys[k1],161*keys[k2]];vols=[vals[0]*days[k1],vals[1]*days[k2]]
assert sum(vols)==K*460
assign.append({'assignment':[k1,k2],'calendar_measures':[days[k1],days[k2]],'output_components':vals,'naked_sum':sum(vals),'component_day_volumes':vols,'total_day_volume':sum(vols),'common336_count':sum(vols)/336,'common360_count':sum(vols)/360,'common364_count':sum(vols)/364})
diag['conditional_mixed_calendar_family']={'source_parts':[299,161],'assignments':assign,'shared_volume':K*460,'source_mixed_JE':[300,175],'matched_unit_volume':300*364+175*336,'swapped_unit_volume':300*336+175*364,'swap_defect':(300*336+175*364)-(300*364+175*336),'status':'Scalar assignments except the inherited source branches are diagnostic. Interpreting each output in its matching Key calendar is conditional; no assertion that475 is literally a mixed-calendar elapsed chronology.'}
save('exactdiagnostics.json',diag)
print(json.dumps(clean({'rank':rank,'E_solutions':[EP,EJ],'allocation_fractions':fractions,'affine_pairs':arows,'source_field_mesh':E*step,'mixed_volume':K*460}),indent=2))
Evidence
prepare.py
Linked sources and evidence
Edition and provenance
prepare.py
SHA-256 d76a411ca827e1a36bc0cd7a93c85ba1869737b38112b9f5233818258b7b3985
C480–C1634/Research_Cycles/C0932_C1131/prep/key_constraints/prepare.py