import numpy as np, importlib.util, sys
spec = importlib.util.spec_from_file_location("mc","montecarlo_robust.py")
mc = importlib.util.module_from_spec(spec); spec.loader.exec_module(mc)

# 1. Reproduce headline (flat rate floor)
r = mc.cost_recovery_mc(n=200_000, verbose=False)
print("flat floor p_payback:", r["p_payback"], "(json says 29.4)")

# 2. Rate-invariance of COUNTY total? identity claim says P_pub cancels -> county invariant to RT.
c0 = mc.county_value_mc(15, scn={'rate_track':0.0})
c1 = mc.county_value_mc(15, scn={'rate_track':1.0})
print("county P50 RT=0:", c0["county_P50"], " RT=1:", c1["county_P50"], " diff:", c1["county_P50"]-c0["county_P50"])
print("county p_ahead RT=0:", c0["p_county_ahead"], " RT=1:", c1["p_county_ahead"])
print("household P50 RT=0:", c0["household_savings_P50"], " RT=1:", c1["household_savings_P50"])
print("district P50 RT=0:", c0["district_P50"], " RT=1:", c1["district_P50"])

# 3. Convexity claim: mean should exceed det_at_mean per comment. Check benefit.
pv,_ = mc.benefit_mc(mc.CUST, 15, 0.04)
print("benefit mean:", round(pv.mean()), " det_at_mean:", round(mc.benefit_det(mc.CUST,15,0.04)), " (comment: mean should be HIGHER)")
