#!/usr/bin/env python3 """Validate the engine (def.c) against exact rational products of the definition. f_p(h) = (1 - nu_p(h)/p)/(1 - 2/p)^2, nu_p(h) = #{0,2,h,h+2 mod p}, F(h) = prod_{p>2} f_p(h) = head(h) * Tail(h+2), head(h) = prod_{3<=p<=h+2} f_p(h), Tail(x) = prod_{p>x} (p-1)/(p-2). For h >= 6 the ratio to h = 6 is exact: F(h)/F(6) = head(h)/head(6) * prod_{8
1 else "F_dump.txt" KV = int(sys.argv[2]) if len(sys.argv) > 2 else 100000 ps = [p for p in sieve(KV) if p >= 3] def head(h): v = Fr(1) for p in ps: if p > h + 2: break nu = len({0, 2 % p, h % p, (h + 2) % p}) if p - nu <= 0: return Fr(0) v *= Fr(p - nu, p) / Fr(p - 2, p) ** 2 return v def tailfac(h): v = Fr(1) for p in ps: if p > h + 2: break if p > 8: v *= Fr(p - 1, p - 2) return v eng = {} for line in open(dump, encoding="utf-8-sig"): a = line.split() if len(a) == 2: eng[int(a[0])] = float(a[1]) h6 = head(6) base = eng.get(6) if base is None: print("F_dump.txt does not contain h = 6") return 2 worst = 0.0 wh = None n = 0 for h in sorted(eng): if h < 6 or h % 2: continue hh = head(h) if hh == 0: continue exact = hh / h6 * tailfac(h) d = abs((eng[h] / base) / float(exact) - 1.0) if d > worst: worst, wh = d, h n += 1 print("checked %d even h against the exact definition" % n) print("max |engine ratio / exact ratio - 1| = %.3e at h = %s" % (worst, wh)) return 0 if worst < 1e-9 else 1 if __name__ == "__main__": sys.exit(main())