import contextlib,decimal,difflib,hashlib,importlib.util,io,json,math,pathlib,sys,traceback,types P=pathlib.Path(__file__).parent;D=decimal.Decimal;decimal.getcontext().prec=70 def independent_fit(xs,ys): n=len(xs);mx=sum(xs)/n;my=sum(ys)/n;sxx=sum((x-mx)**2 for x in xs) b=sum((x-mx)*(y-my) for x,y in zip(xs,ys))/sxx;a=my-b*mx residual=sum((y-a-b*x)**2 for x,y in zip(xs,ys));se=(residual/(n-2)/sxx).sqrt() return {'slope':float(b),'slope_se':float(se),'factor':float(a.exp()),'SSE':float(residual),'n':n,'band_descriptive':[float(b-2*se),float(b+2*se)]} try: source=P/'88072a8b6a67-check-1437.py';assert hashlib.sha256(source.read_bytes()).hexdigest()=='88072a8b6a678acc6faddf67052b9674f3e432a925da68f92d34609d52ef11ec' spec=importlib.util.spec_from_file_location('author',source);m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m) saved=sys.argv;sys.argv=['check-1437','--out',str(P/'reproduced.json')] with contextlib.redirect_stdout(io.StringIO()):assert m.main()==0 sys.argv=saved;reproduced=json.loads((P/'reproduced.json').read_text());original=json.loads((P/'fc1a2cc60e6a-check-1437.out.json').read_text());assert reproduced==original arrays={} for name,seq in [('FIXED','A144311'),('ONE','A048670'),('FREE','A288815')]: rows=[list(map(int,s.split())) for s in (P/(seq+'.txt')).read_text().splitlines() if s.strip() and not s.startswith('#')] expected=dict(rows);values=getattr(m,name);assert all(v==expected[i] for i,v in enumerate(values,1));arrays[name]={'literal_terms_checked':len(values),'primary_table_terms':len(rows)} primes=[] for n in range(2,80): if all(n%d for d in range(2,math.isqrt(n)+1)):primes.append(n) rows=[(i+1,primes[i],D(m.FIXED[i]+1)/D(m.ONE[i]),D(m.FREE[i])/D(m.FIXED[i]+1)) for i in range(4,21)] groups={'bottom9_n5_13':rows[:9],'top9_n13_21':rows[-9:],'bottom8_n5_12':rows[:8],'top8_n14_21':rows[-8:],'full':rows} output={'arrays_match_primary_sources':arrays,'original_output_exactly_reproduced':True,'independent_decimal_precision':70,'fits':{},'matched_prime_range':[rows[0][1],rows[-1][1]]} for name,j in [('l7_splits',2),('price_splits',3)]: got={} for key,rr in groups.items(): fit=independent_fit([D(r[1]).ln().ln() for r in rr],[r[j].ln() for r in rr]);expected=original[name][key] for k in ('slope','slope_se','factor'):assert round(fit[k],4)==expected[k],(name,key,k,fit[k],expected[k]) got[key]=fit slope=(rows[-1][j].ln()-rows[0][j].ln())/(D(rows[-1][1]).ln().ln()-D(rows[0][1]).ln().ln()) assert round(float(slope),4)==original[name]['two_point_ends']['slope'];got['two_point_slope']=float(slope);output['fits'][name]=got # Every reported end band contains positive .1 as well as zero; inclusion of zero cannot establish boundedness. output['all_four_price_bands_also_contain_positive_0p1']=all(original['price_splits'][k]['two_sigma_band'][0]<=.1<=original['price_splits'][k]['two_sigma_band'][1] for k in groups if k!='full') assert output['all_four_price_bands_also_contain_positive_0p1'] output['descriptive_price_range']=[float(min(r[3] for r in rows)),float(max(r[3] for r in rows))] # Overlapping slope estimates share one ordinate. Under a hypothetical common iid variance sigma², # covariance divided by sigma² is the dot product of their OLS ordinate weights. def slope_weights(rr): xx=[D(r[1]).ln().ln() for r in rr];mean=sum(xx)/len(xx);denom=sum((x-mean)**2 for x in xx) return {r[0]:(x-mean)/denom for r,x in zip(rr,xx)} wa=slope_weights(rows[:9]);wb=slope_weights(rows[-9:]);overlap=set(wa)&set(wb) output['overlap_n']=sorted(overlap);output['overlap_slope_covariance_per_hypothetical_common_variance']=float(sum(wa[i]*wb[i] for i in overlap)) output['max_rounding_band_endpoint_difference']=max(abs(original[name][k]['two_sigma_band'][i]-output['fits'][name][k]['band_descriptive'][i]) for name in ('l7_splits','price_splits') for k in groups for i in (0,1)) # Correct semantic labels without changing the fit arithmetic or the declared finite predicate. old=source.read_text();new=old replacements={ '"single_power_law_rejected_overlapping_split"':'"descriptive_two_se_bands_disjoint_overlapping_split"', '"rejection_robust_to_split"':'"descriptive_band_disjointness_in_both_splits"', 'single power law does not fit the matched range':'the descriptive bands differ; no formal model test is implied', 'the model-adequacy rejection is NOT robust to the split':'band disjointness is NOT robust to the split', 'and not as a settled rejection':'and not as a calibrated hypothesis test', 'the price\'s constant reading survives end-restriction in BOTH split variants: ':'the finite price slopes do not exclude zero in either split: ', '22 terms, recorded as PROVEN maximal':'22 published terms', } for a,b in replacements.items():assert a in new;new=new.replace(a,b) marker=' out["summary"] = ';pos=new.index(marker) new=new[:pos]+' out["inference_scope"] = {"kind": "descriptive fits to deterministic finite data", "formal_model_rejection": False, "bounded_price_established": False, "asymptotic_regime_decided": False}\n\n'+new[pos:] module=types.ModuleType('patched');exec(compile(new,'patched','exec'),module.__dict__);sys.argv=['check','--out',str(P/'corrected-labels.json')] with contextlib.redirect_stdout(io.StringIO()):assert module.main()==0 sys.argv=saved;patched=json.loads((P/'corrected-labels.json').read_text()) for key in ('l7_splits','price_splits','summary'):assert patched[key]==original[key] output['semantic_patch_preserves_all_fits_and_ten_checks']=True (P/'descriptive-inference.patch').write_text(''.join(difflib.unified_diff(old.splitlines(True),new.splitlines(True),fromfile='a/check-1437.py',tofile='b/check-1437.py')),encoding='utf-8') (P/'independent-checks.json').write_text(json.dumps(output,indent=2),encoding='utf-8') except BaseException: (P/'check-error.txt').write_text(traceback.format_exc(),encoding='utf-8');raise