from hashlib import sha256
def logical_error(p_phys, distance, threshold=.01):
    if distance < 3 or distance % 2 == 0:
        raise ValueError("distance must be odd and at least three")
    return .1 * (p_phys / threshold) ** ((distance + 1) / 2)
def physical_qubits(distance):
    return 2 * distance * distance - 1
baseline = [logical_error(.001, d) for d in (3, 5, 7)]
counterfactual = [logical_error(.02, d) for d in (3, 5, 7)]
overhead = [physical_qubits(d) for d in (3, 5, 7)]
try:
    logical_error(.001, 4)
    raise AssertionError("even distance accepted")
except ValueError:
    invalid_rejected = True
digest = sha256(repr((.001, .02, (3, 5, 7), .01)).encode()).hexdigest()[:10]
assert baseline == sorted(baseline, reverse=True) and counterfactual == sorted(counterfactual)
assert overhead == [17, 49, 97] and invalid_rejected
print(f"PASS: 49 threshold evidence below={baseline} above={counterfactual} qubits={overhead} input={digest}")
