from math import log10
def db_to_fraction(loss_db):
    return 10 ** (-loss_db / 10)
def path_survival(stages):
    if len({(stage["wavelength_nm"], stage["scope"]) for stage in stages}) != 1:
        raise ValueError("mismatched optical scope")
    survival = 1.0
    for stage in stages:
        survival *= stage["fraction"] ** stage.get("count", 1) * db_to_fraction(stage.get("loss_db", 0))
    return survival
stages = [{"fraction":.92,"count":20,"loss_db":0,"wavelength_nm":1550,"scope":"synthetic-path"}, {"fraction":1.0,"loss_db":3,"wavelength_nm":1550,"scope":"synthetic-path"}]
baseline = path_survival(stages)
boundary = path_survival([{**stages[0], "fraction":1.0, "count":1}])
counterfactual = path_survival([stages[0], {**stages[1], "loss_db":6}])
try:
    path_survival([stages[0], {**stages[1], "wavelength_nm":780}])
    raise AssertionError("wavelength mismatch accepted")
except ValueError:
    rejected = True
assert abs(db_to_fraction(3) - .5011872336) < 1e-9 and abs(-10 * log10(db_to_fraction(3)) - 3) < 1e-12
assert boundary == 1.0 and 0 < counterfactual < baseline < .1 and rejected
print(f"PASS: 58 photonic evidence survival={baseline:.8f} six_dB={counterfactual:.8f} mismatch_rejected={rejected}")
