# ratio46.py -- solveathome job #46. From each level's cand, recompute the uniform expectation # expect = window * (1/2) * prod_{2
2: dens *= Fraction(p - 2, p) last = max(last, pn) expect = dens * r["window"] ratio = Fraction(r["cand"]) / expect e1 = float(round(Decimal(expect.numerator) / Decimal(expect.denominator), 1)) r3 = float(round(Decimal(ratio.numerator) / Decimal(ratio.denominator), 3)) ok = (abs(e1 - r["expect"]) < 1e-9 and abs(r3 - r["ratio"]) < 1e-9) c = cc.get(pn) cmatch = c is not None and c == (pn, r["pNext"], r["window"], r["cand"]) inband = 0.79 <= float(ratio) <= 1.0 if not (ok and cmatch): bad += 1 rdec = Decimal(ratio.numerator) / Decimal(ratio.denominator) print(f"{pn:<6} {r['pNext']:<6} {r['window']:<10} {r['cand']:<12} {c[3] if c else '-':<8} {float(expect):<19.6f} {r['expect']:<8} " f"{float(ratio):<14.9f} {r['ratio']:<8} {'ok' if ok else 'DIFF'}{'' if cmatch else ' C-DIFF'} {'inside' if inband else 'OUTSIDE'} {float(rdec - TARGET):+.6f}") print(f"e^(2 gamma)/4 = {TARGET:.12f}; rows with a rounding or C mismatch: {bad}")