import json import sys from fractions import Fraction as F from itertools import count from math import isqrt, prod from pathlib import Path def prime(n): if n < 2: return False if n % 2 == 0: return n == 2 return all(n % d for d in range(3, isqrt(n) + 1, 2)) def next_prime(n): while not prime(n): n += 1 return n def below_power(s, exponent): return s ** exponent.denominator < 2 ** exponent.numerator def exact_cut(j, exponent): power = j * exponent assert power.denominator == 1 return 1 << power.numerator def verify(): threshold_checks = 0 for eta in (F(1, 401), F(1, 500), F(1, 1000)): for j in range(1, 201): exponent = 2 * eta * j assert below_power(1, exponent) assert not below_power(2, exponent) threshold_checks += 1 for k in range(1, 5): eta = F(1, 500) assert not below_power(2 ** k, 2 * eta * (250 * k)) assert below_power(2 ** k, 2 * eta * (250 * k + 1)) threshold_checks += 2 j, eta, w = 500, F(1, 500), F(1, 20) x = 1 << j W = exact_cut(j, w) D = max(W, exact_cut(j, 1 - w - 2 * eta)) z = exact_cut(j, 1 - w - eta) assert (W, D, z) == (1 << 25, 1 << 473, 1 << 474) assert 0 < eta < F(1, 400) and z == 2 * D P, small_factors = 1, [] for q in count(3, 2): if not prime(q): continue if P * q > D // 10000: break P *= q small_factors.append(q) q = next_prime((5 * D) // (4 * P) + 1) factors = small_factors + [q] d = prod(factors) p = next_prime(W + 1) m = 2 * p * d all_factors = [2, p] + factors assert len(set(all_factors)) == len(all_factors) assert all(prime(q) for q in all_factors) assert all(2 < q < W for q in factors) assert 5 * D < 4 * d and 2 * d < 3 * D assert D < d < z < 2 * d assert x // 2 - 2 < m <= x - 2 assert x // 2 < m + 2 <= x assert W < p and 2 * p <= W * W assert below_power(2, 2 * eta * j) assert prod(all_factors) == m # Every other divisor of 2*d has complementary divisor at least three. assert 2 * d < 3 * D mu_d = (-1) ** len(factors) assert mu_d in (-1, 1) return { "status": "passed", "scope": "Exact cofactor threshold and one actual-cutoff coefficient witness; not a shifted sum", "threshold_checks": threshold_checks, "parameters": {"log2_x": j, "eta": str(eta), "w_right": str(w)}, "witness": { "x": str(x), "W": str(W), "D": str(D), "z": str(z), "p": p, "d": str(d), "d_prime_factors": factors, "m": str(m), "shifted_parent_n": str(m + 2), "s": 2, "mu_d": mu_d, "full_coefficient_formula": "mu_d*log(p)*log(z/d)/log(2)", "full_coefficient_sign": mu_d, "unit_cofactor_value": 0, }, "active_controls": { "threshold_is_strict_at_equality": True, "all_factors_prime_and_distinct": True, "only_large_prime_is_p": True, "only_window_divisor_of_2d_is_d": True, "unit_cofactor_replacement_is_false": True, }, } def main(): if len(sys.argv) > 2: raise SystemExit("usage: check4433.py [check4433-output.json]") output = (json.dumps(verify(), sort_keys=True) + "\n").encode() if len(sys.argv) == 2 and Path(sys.argv[1]).read_bytes() != output: raise ValueError("Target bytes differ from the recomputed exact witness") sys.stdout.buffer.write(output) if __name__ == "__main__": main()