"""Reproduce the genus-three theta/Fourier stage at p=17, q=5 using Arb. Requires python-flint 0.9.0. All displayed enclosures are complex balls. This only tests the analytic entry to the CM construction. """ import argparse import itertools from functools import lru_cache from flint import acb, acb_mat, arb, arb_mat, ctx, fmpz_poly ctx.prec = 256 roots = [z.real for z, m in fmpz_poly([1, -3, 0, 1]).complex_roots()] S = arb_mat([[1, z, z*z] for z in roots]) B = arb_mat([[0, 0, 1], [0, 1, 0], [1, 0, 3]]) J = S.inv() W = arb_mat([[abs(3*roots[i]**2-3) if i == j else 0 for j in range(3)] for i in range(3)]) Y = (J * W * J.transpose()) * (arb(15).sqrt()/2) X = B.inv()/2 tau = acb_mat([[acb(X[i,j], Y[i,j]) for j in range(3)] for i in range(3)]) def characteristic(t, a, b, d): a = acb_mat(3, 1, [acb(x)/d for x in a]) b = acb_mat(3, 1, [acb(x)/d for x in b]) displacement = t*a+b phase = (a.transpose()*(displacement+b))[0,0].exp_pi_i() return phase*t.theta(displacement)[0,0] @lru_cache(maxsize=4096) def high_level(c): centered = [x if x <= 8 else x-16 for x in c] return characteristic(tau*16, centered, (0,0,0), 16) @lru_cache(maxsize=16) def root_of_unity(k): return (acb(2*k)/16).exp_pi_i() def compare(A, B, verbose=False): direct = characteristic(tau, A, B, 4) total = acb(0) for j in itertools.product(range(4), repeat=3): c = tuple(a + 4*i for a, i in zip(A, j)) phase = root_of_unity(sum(x*b for x, b in zip(c, B)) % 16) total += phase*high_level(c) assert direct.overlaps(total), (direct,total) assert (direct-total).abs_upper() < arb(2)**(-120) error = (direct-total).abs_upper() if verbose: print(A, B, direct.str(20), total.str(20), 'discrepancy bound', error.str(3)) return error if __name__ == '__main__': options = argparse.ArgumentParser(description=__doc__) options.add_argument('--all', action='store_true', help='test all 4096 characteristics') exhaustive = options.parse_args().all examples = [((0,0,0),(0,0,0)), ((1,0,2),(3,1,1))] pairs = itertools.product(itertools.product(range(4), repeat=3), repeat=2) if exhaustive else examples worst = arb(0) for count, (A, B) in enumerate(pairs, 1): error = compare(A, B, verbose=(A, B) in examples) worst = worst.max(error) print(count, 'characteristics, maximum upper bound', worst.str(6))