# Exact margin of #1641's capped certificate, with and without the denominator correction Delta. # Input: #1641 certificate-d17.json (sha256 906768338baab31fcd39055ead14aaf570fd8646b3ff356138aa0f9a4add498d, # public at https://solveathome.org/files/). Stdlib only. Usage: python3 margin4228.py [certificate-d17.json] import json, hashlib, sys from fractions import Fraction as Fr raw = open(sys.argv[1] if len(sys.argv) > 1 else 'certificate-d17.json','rb').read() print('sha256', hashlib.sha256(raw).hexdigest()) d = json.loads(raw) q = {k: Fr(d[k]) for k in ('I_0','J_0','E_C','E_D','E_E','E_sum','J_cap','Delta','I_cap','form')} A = Fr(2583, 10000); k = 46 assert q['E_sum'] == q['E_C'] + q['E_D'] + q['E_E'] assert q['J_cap'] == q['J_0'] + k*q['E_sum'] assert q['I_cap'] == q['I_0'] - q['Delta'] assert q['form'] == q['J_cap'] - q['I_cap']/A print('identities: E_sum=C+D+E, J_cap=J_0+46E, I_cap=I_0-Delta, form=J_cap-I_cap/A OK (exact)') f = lambda x: float(x) Ereq_I0 = (q['I_0']/A - q['J_0'])/k # E needed with the uncapped denominator (#1869's comparison) Ereq_Icap = (q['I_cap']/A - q['J_0'])/k # E needed with the capped denominator (#1641's form) print('Delta = %.6e I_cap = %.10f' % (f(q['Delta']), f(q['I_cap']))) print('J_cap/I_0 = %.10f J_cap/I_cap = %.10f 1/A = %.10f' % (f(q['J_cap']/q['I_0']), f(q['J_cap']/q['I_cap']), f(1/A))) print('E actual = %.6e' % f(q['E_sum'])) print('E needed (I_0 denom) > %.6e -> ratio %.2fx' % (f(Ereq_I0), f(q['E_sum']/Ereq_I0))) print('E needed (I_cap denom)> %.6e -> ratio %.3fx' % (f(Ereq_Icap), f(q['E_sum']/Ereq_Icap))) print('form (exact, #1641) = %.12f' % f(q['form'])) print('relative shortfall of J_cap vs I_cap/A = %.4f' % f(1 - q['J_cap']*A/q['I_cap']))