Datasets:
Download verification/check_math.py from PureOne/ChronoSheaf-Input-Lag: direct link, hf CLI and curl.
- Browser
- Download file 4.09 kB
-
https://huggingface.co/datasets/PureOne/ChronoSheaf-Input-Lag/resolve/main/verification/check_math.py
- Command line
-
hf download hf://datasets/PureOne/ChronoSheaf-Input-Lag/verification/check_math.py
-
curl -L -o check_math.py https://huggingface.co/datasets/PureOne/ChronoSheaf-Input-Lag/resolve/main/verification/check_math.py
4.09 kB
| """Independent enumeration of cuts, pulse starts, clock boxes and repair plans.""" | |
| import itertools as it | |
| import json, math, random, sys | |
| from fractions import Fraction as F | |
| from pathlib import Path | |
| ROOT=Path(__file__).resolve().parents[1] | |
| sys.path.insert(0,str(ROOT/"src")) | |
| from coverage import certificate,robust_witness,front_area,repair_points | |
| def first(trace,start,width=None): | |
| return min((d for s,d in trace if s>=start and (width is None or s<start+width)),default=math.inf) | |
| def finite(): | |
| pairs=[(0,4),(1,4),(2,5),(3,5),(4,6)] | |
| traces=[list(it.compress(pairs,mask)) for mask in it.product(range(2),repeat=5)] | |
| total=areas=0 | |
| for b,c in it.product(traces,repeat=2): | |
| for g in (0,1,3): | |
| result=certificate(b,c,g) | |
| thresholds=[F(j,2) for j in range(-6,13)] | |
| assert result["persistent"]==all(first(c,u)<=first(b,u)+g for u in thresholds) | |
| for w in range(1,7): | |
| starts=[F(i,2) for i in range(-2*w-2,12)] | |
| good=all(first(c,u,w)<=first(b,u,w)+g for u in starts) | |
| bound=result["minimum_pulse_width"] | |
| assert good==(bound is not None and w>=bound) | |
| total+=1 | |
| # Integrate the two horizontal inverse curves independently on integer cells. | |
| summ=sum(min(8,max(3,first(b,F(j*2+1,2))))-min(8,max(3,first(c,F(j*2+1,2)))) for j in range(-1,6)) | |
| assert summ==front_area(b,c,(-1,6),(3,8));areas+=1 | |
| return total,areas | |
| def boxes(): | |
| rng=random.Random(84429);tested=0 | |
| for _ in range(620): | |
| def box(): | |
| s=rng.randrange(5);d=rng.randrange(6,9) | |
| return s,s+rng.randrange(2),d,d+rng.randrange(2) | |
| b=[box()];c=[box(),box()];w=rng.randint(1,6);g=rng.randint(0,2) | |
| witness=robust_witness(b,c,w,g) | |
| starts=[F(k,2) for k in range(-2*w-2,15)] | |
| def realizations(x): | |
| return it.product(*[[(s,d) for s in set((a,b)) for d in set((l,h))] for a,b,l,h in x]) | |
| # A baseline cut can lie inside its closed box. Add interior pulse-compatible | |
| # samples independently at all decision boundaries. | |
| def disagrees(u): | |
| lo,hi,early,_=b[0] | |
| possible=(max(lo,u)<=hi and max(lo,u)<u+w) | |
| return possible and any(first(t,u,w)>early+g for t in realizations(c)) | |
| assert (witness is not None)==any(map(disagrees,starts)) | |
| if witness:assert disagrees(witness[0]) | |
| tested+=1 | |
| return tested | |
| def extras(): | |
| rng=random.Random(3920);repair=phase=contrasts=0 | |
| for _ in range(750): | |
| n=rng.randint(0,8);cuts=sorted(rng.sample(range(14),n)) | |
| opp=list(zip(cuts,[20+2*i for i in range(n)])) | |
| req=[(u,u+rng.randint(1,8),rng.randint(18,38)) for u in (rng.randrange(14) for _ in range(rng.randrange(8)))] | |
| sol=repair_points(opp,req) | |
| def good(P):return all(any(a<=opp[i][0]<b and opp[i][1]<=d for i in P) for a,b,d in req) | |
| brute=min((len(P) for k in range(n+1) for P in it.combinations(range(n),k) if good(P)),default=math.inf) | |
| assert (math.inf if sol is None else len(sol))==brute | |
| if sol is not None:assert good(sol) | |
| repair+=1 | |
| for T in range(2,43): | |
| for delta,w in it.product(range(1,T),repeat=2): | |
| denied=sum(1 for u in range(-w+1,1) | |
| if not any(u<=s<u+w for s in (delta-T,delta))) | |
| assert denied==min(w,T-w,delta,T-delta);phase+=1 | |
| for initial,slope,h,k in it.product(range(0,20),range(-5,6),range(1,11),(0,1,2)): | |
| z=[0,h,h,0];y=[initial+i*slope-k*x for i,x in enumerate(z)] | |
| assert y[0]-y[1]-y[2]+y[3]==2*k*h;contrasts+=1 | |
| return repair,phase,contrasts | |
| if __name__=="__main__": | |
| if not __debug__:raise SystemExit("use active assertions") | |
| total,areas=finite();uncertain=boxes();repair,phase,contrasts=extras() | |
| result=dict(pulse_deadline_cases=total,clipped_area_identities=areas,independent_uncertain_cases=uncertain, | |
| optimal_repair_catalogues=repair,periodic_phase_laws=phase,affine_cancellation_cases=contrasts) | |
| print(json.dumps(result,indent=2)) | |