from pathlib import Path from fractions import Fraction from math import comb import json,hashlib p=Path(__file__).resolve().parent def check(hist): lo,hi=min(hist),max(hist);degree=hi-lo lc=[];newton=[] for s in range(lo+1,hi): a,b,c=[hist.get(k,0) for k in [s-1,s,s+1]];j=s-lo if b*bFraction(q['bernoulli_width_bound']);rows.append(q) assert all(r['width_bound_violated'] and r['newton_failures'] for r in rows if r['primary']) positive=check({k:comb(12,k)*2**k for k in range(13)}) assert not positive['newton_failures'] negative=check({0:1,1:1,2:1});assert len(negative['newton_failures'])==1 out={'source_sha256':hashlib.sha256((p/'actual-reference.txt').read_bytes()).hexdigest(),'rows':rows, 'positive_control':'(1+2t)^12: every normalized Newton inequality equality', 'negative_control':negative} (p/'checks.json').write_text(json.dumps(out,indent=2)+'\n') for r in rows: if r['primary']:print(r['z'],'LC failures',len(r['ordinary_log_concavity_failures']),'Newton failures',len(r['newton_failures']),'first',r['newton_failures'][:1])