from pathlib import Path from math import gcd,prod import json PS=[2,3,5,7,11,13,17,19,23,29] def check(x,q,slots): W=prod(p for p in PS if p<=x) for n in slots:assert gcd(n,W)==gcd(n+2,W)==1 excluded=[] for a,b in zip(slots,slots[1:]): for n in range(a+1,b): p=next((p for p in PS if p<=x and (n%p==0 or (n+2)%p==0)),None);assert p excluded.append([n,p]) gaps=[b-a for a,b in zip(slots,slots[1:])];L=len(slots)-2 loose=all(g%q in [0,2,q-2] for g in gaps[1:-1]);phases=[];maximal=[] for k in range(q): dead=[(n+k*W)%q in [0,q-2] for n in slots] if all(dead[1:-1]): phases.append(k) if not dead[0] and not dead[-1]:maximal.append(k) return {'x':x,'q':q,'W':W,'slots':slots,'gaps':gaps,'interior_residues':[n%q for n in slots[1:-1]],'L':L,'loose':loose,'legal_lift_indices':phases,'maximal_lift_indices':maximal,'excluded_integer_count':len(excluded),'exclusion_certificates':excluded,'positive_6grid_thresholds':sum(gaps)//6} a=check(23,29,[98099,98177,98237,98297,98321]);assert a['loose'] and not a['legal_lift_indices'] b=check(29,31,[1321026569,1321026611,1321026671,1321026797,1321026857,1321026899]);assert b['loose'] and len(b['maximal_lift_indices'])==1 and b['positive_6grid_thresholds']==55 assert b['positive_6grid_thresholds']>4 Path(__file__).with_name('witness.json').write_text(json.dumps({'T23_Q3_loose_not_actual':a,'T29_single_Q4_window_sum_lower_bound55':b},indent=2,sort_keys=True)+'\n') print('PASS T23 loose Q3 window has0legal phases; T29 legal maximal Q4 window contributes55thresholds, exceeding4') print('T29 phase',b['legal_lift_indices'],'residues',b['interior_residues'],'excluded',b['excluded_integer_count'])