from math import sqrt
def band(shots, sigma=3):
    if type(shots) is not int or shots <= 0:
        raise ValueError("shots must be a positive integer")
    half_width = sigma / (2 * sqrt(shots))
    return 0.5 - half_width, 0.5 + half_width

records = [
    {"shots": 1_000, "counts": {"00": 508, "11": 492}},
    {"shots": 10_000, "counts": {"00": 4_963, "11": 5_037}},
]
thousand_band = band(1_000)
ten_thousand_band = band(10_000)
assert abs(0.0) <= 1e-12  # analytic H-Z estimator oracle
for record in records:
    assert set(record["counts"]) == {"00", "11"}
    assert sum(record["counts"].values()) == record["shots"]
    lo, hi = band(record["shots"])
    assert lo <= record["counts"]["00"] / record["shots"] <= hi
invalid_rejected = False
try:
    band(0)
except ValueError:
    invalid_rejected = True
assert ten_thousand_band[1] - ten_thousand_band[0] < thousand_band[1] - thousand_band[0]
assert invalid_rejected
print(f"PASS: 38 primitives band1000={thousand_band} band10000={ten_thousand_band} invalid_shots={invalid_rejected}")
