#!/usr/bin/env python3 """Exact checks for Sections 8 and 9 of "Fourier zeros and the Schottky problem I". None of this is used in the proofs of the paper; the script only re-derives, in exact rational arithmetic, formulas which are proved by hand there. (1) Formula (6) for the second order term Q(x,u) of a graph (Proposition 8.2) is compared, at random rational points (x,u), with the definition of Q from a fine zonotopal tiling (Proposition 8.1, with the signs of Lemma 2.1 for a random lift), for K_4, K_5, K_{3,3} and K_{3,3} with a triangle in one colour class. (2) The evaluations of Lemma 8.5 (K_5), Lemma 9.1 (K_{3,3}) and Lemma 9.3 (three stars on three terminals) are compared with the theta sum (7), computed by enumerating the subgraphs in W. (3) For K_5 with unit weights the tile formula (1) is compared with the vertex sum of Brion's formula at two rational points z (the ratio of the two sides, divided by z^4, must be the same constant). Exit status 0 if and only if all checks succeed. Requires SymPy and mpmath. """ import itertools import random import sys from fractions import Fraction as Fr import sympy as sp from mpmath import mp, mpf, mpc, exp, cos, sin random.seed(20261201) ok = True def check(name, cond): global ok print(('ok ' if cond else 'FAIL ') + name) ok = ok and bool(cond) def rnd(lo=-5, hi=5, den=4): while True: q = Fr(random.randint(lo * den, hi * den), random.randint(1, den)) if q != 0: return q # ---------------------------------------------------------------- graphs def n_components(n, E): par = list(range(n)) def find(v): while par[v] != v: v = par[v] return v for p, q in E: par[find(p)] = find(q) return len({find(v) for v in range(n)}) def spanning_trees(n, edges): for S in itertools.combinations(range(len(edges)), n - 1): if n_components(n, [edges[i] for i in S]) == 1: yield S def theta_subgraphs(n, edges): """connected spanning subgraphs with n+1 edges whose core is a theta graph; returns pairs (edge indices, the two branch vertices)""" out = [] for W in itertools.combinations(range(len(edges)), n + 1): E = [edges[i] for i in W] if n_components(n, E) != 1: continue core = list(E) while True: deg = [0] * n for p, q in core: deg[p] += 1 deg[q] += 1 leaves = {v for v in range(n) if deg[v] == 1} if not leaves: break core = [e for e in core if e[0] not in leaves and e[1] not in leaves] deg = [0] * n for p, q in core: deg[p] += 1 deg[q] += 1 branch = [v for v in range(n) if deg[v] == 3] if len(branch) != 2 or max(deg) != 3: continue # a core with two vertices of degree 3 is a theta graph iff it has # no bridge (otherwise it is two cycles joined by a path) k = n_components(n, core) if any(n_components(n, core[:i] + core[i + 1:]) != k for i in range(len(core))): continue out.append((W, branch)) return out def tree_poly(n, edges, x): L = sp.zeros(n, n) for (p, q), c in zip(edges, x): L[p, p] += c L[q, q] += c L[p, q] -= c L[q, p] -= c return L, L[1:, 1:].det() def Q_theta_node(n, edges, x, u, W=None): W = theta_subgraphs(n, edges) if W is None else W return -sum(sp.prod([x[i] for i in w]) * (u[br[0]] - u[br[1]])**2 for w, br in W) def Q_formula(n, edges, x, u, W): """right hand side of (6)""" m = len(edges) b = [u[p] - u[q] for p, q in edges] trees = list(spanning_trees(n, edges)) T = sum(sp.prod([x[i] for i in S]) for S in trees) dT = [sum(sp.prod([x[i] for i in S if i != e]) for S in trees if e in S) for e in range(m)] return (-sp.Rational(1, 2) * sum(b[e]**2 * x[e]**2 for e in range(m)) * T + sp.Rational(1, 3) * sum(b[e]**2 * x[e]**3 * dT[e] for e in range(m)) + Q_theta_node(n, edges, x, u, W)) def tiling_signs(n, edges, h): """signs eps^S_l = -sgn(h_l - ) of Lemma 2.1, a_e = e_p - e_q""" signs = {} m = len(edges) for S in spanning_trees(n, edges): # potential w on the vertices with w_p - w_q = h_e on the tree edges w = {0: Fr(0)} todo = set(S) while todo: for i in list(todo): p, q = edges[i] if p in w and q not in w: w[q] = w[p] - h[i] todo.remove(i) elif q in w and p not in w: w[p] = w[q] + h[i] todo.remove(i) eps = {} for l in range(m): if l not in S: p, q = edges[l] r = h[l] - (w[p] - w[q]) assert r != 0 eps[l] = -1 if r > 0 else 1 signs[S] = eps return signs def Q_definition(n, edges, x, u, signs): """the definition of Q in Proposition 8.1 (all |det A_S| = 1)""" b = [u[p] - u[q] for p, q in edges] tot = 0 for S, eps in signs.items(): lin = sum(eps[l] * b[l] * x[l] for l in eps) tot += sp.prod([x[i] for i in S]) * ( sp.Rational(1, 2) * lin**2 + sp.Rational(1, 6) * sum(b[i]**2 * x[i]**2 for i in S)) return -tot # ---------------------------------------------------------------- (1) K4 = (4, list(itertools.combinations(range(4), 2))) K5 = (5, list(itertools.combinations(range(5), 2))) K33 = (6, [(i, 3 + j) for i in range(3) for j in range(3)]) K33T = (6, K33[1] + [(0, 1), (0, 2), (1, 2)]) for name, (n, edges) in (('K4', K4), ('K5', K5), ('K33', K33), ('K33 + triangle', K33T)): W = theta_subgraphs(n, edges) good = True for trial in range(3): h = [Fr(random.randint(1, 10**6), random.randint(1, 10**6)) for _ in edges] signs = tiling_signs(n, edges, h) x = [sp.Rational(*rnd().as_integer_ratio()) for _ in edges] u = [sp.Rational(*rnd().as_integer_ratio()) for _ in range(n)] good = good and (Q_definition(n, edges, x, u, signs) == Q_formula(n, edges, x, u, W)) check('(1) formula (6) agrees with the tiling definition for %s ' '(%d subgraphs in W)' % (name, len(W)), good) # ---------------------------------------------------------------- (2) R = sp.Rational # Lemma 8.5 n, edges = K5 W5 = theta_subgraphs(n, edges) good = True for theta in (1, -1): a = [R(3), R(1, 2), R(2), R(5, 3)] sig = sum(a) t = [R(1), R(-2), R(1, 3), R(2, 3)] x = {} for j in range(1, 5): x[(0, j)] = a[j - 1] for j, k in itertools.combinations(range(1, 5), 2): x[(j, k)] = -(a[j - 1] * a[k - 1] / sig + theta * t[j - 1] * t[k - 1]) xv = [x[e] for e in edges] L, T = tree_poly(n, edges, xv) good = good and L.rank() == 2 inner = list(itertools.combinations(range(1, 5), 2)) L4 = sp.zeros(5, 5) for p, q in inner: L4[p, p] += x[(p, q)] L4[q, q] += x[(p, q)] L4[p, q] -= x[(p, q)] L4[q, p] -= x[(p, q)] T4 = L4[2:, 2:].det() T3 = 0 for m_ in range(1, 5): j, k, l = [v for v in range(1, 5) if v != m_] T3 += x[(j, k)] * x[(k, l)] + x[(j, k)] * x[(j, l)] + x[(j, l)] * x[(k, l)] e3 = sum(a[i] * a[j] * a[k] for i, j, k in itertools.combinations(range(4), 3)) good = good and (Q_theta_node(n, edges, xv, [1, 0, 0, 0, 0], W5) == -e3 * T4 - sp.prod(a) * T3) rho2 = [sig * t[i]**2 / a[i]**2 for i in range(4)] good = good and (T4 == -sp.prod(a) / sig * (1 - R(theta) / sig * sum(a[i] * rho2[i] for i in range(4)))) check('(2) Lemma 8.5: rank 2, the formula for Q(x,e_1) and the value of T_4', good) # Lemma 9.1 (b): Q(x(s,xi),u0)/s -> 4 al2^2 al3^2 be2^2 be3^2/(A B) n, edges = K33 # vertices a1,a2,a3,b1,b2,b3 = 0,...,5 W33 = theta_subgraphs(n, edges) al = {2: R(2), 3: R(3)} be = {2: R(5), 3: R(1, 2)} A, B = al[2] + al[3], be[2] + be[3] xi = R(3, 2) pred = 4 * al[2]**2 * al[3]**2 * be[2]**2 * be[3]**2 / (A * B) mp.dps = 40 vals = [] for sv in (R(1, 10**4), R(1, 10**5)): D = sv * (A + B) + A * B p = -be[2] * be[3] * (sv + A) / D r = -al[2] * al[3] * (sv + B) / D half = (xi + p / xi) / 2 zeta = -half + sp.sqrt(half**2 - r) # a root of z^2+(xi+p/xi)z+r wv = {1: xi, 2: p / xi, 4: zeta, 5: r / zeta} # a2,a3,b2,b3 x = {(0, 3): sv, (0, 4): al[2], (0, 5): al[3], (1, 3): be[2], (2, 3): be[3]} for i in (2, 3): for j in (2, 3): x[(i - 1, 2 + j)] = -wv[i - 1] * wv[2 + j] - be[i] * al[j] * sv / D xv = [sp.nsimplify(x[e]) for e in edges] Qv = sp.N(Q_theta_node(n, edges, xv, [1, 0, 0, 1, 0, 0], W33) / sv, 30) vals.append(Qv) check('(2) Lemma 9.1(b): Q/s = %.8f, %.8f for s = 1e-4, 1e-5; limit %.8f' % (vals[0], vals[1], pred), abs(vals[1] - pred) < abs(vals[0] - pred) < 1e-2 and abs(vals[1] - pred) < 1e-3) # Lemma 9.3 (b) good = True for EA in ([(0, 1), (0, 2), (1, 2)], [(0, 1), (0, 2)]): lam = [[R(random.randint(1, 9), random.randint(1, 5)) for j in range(3)] for i in range(3)] Gam = [sum(lam[i][j] for i in range(3)) for j in range(3)] if len(EA) == 3: m = [R(1), R(1), R(1)] else: k = [lam[1][j] * lam[2][j] / Gam[j] for j in range(3)] m = [R(1), R(1), -(k[0] + k[1]) / k[2]] y = {(i, k_): -sum(m[j] * lam[i][j] * lam[k_][j] / Gam[j] for j in range(3)) for i, k_ in itertools.combinations(range(3), 2)} edges = [(i, 3 + j) for i in range(3) for j in range(3)] + EA xv = [m[j] * lam[i][j] for i in range(3) for j in range(3)] + [y[e] for e in EA] L, T = tree_poly(6, edges, xv) beta = [R(2), R(-1, 3), R(5)] om = [m[j]**2 * beta[j] * lam[0][j] * lam[1][j] * lam[2][j] / Gam[j] for j in range(3)] good = good and L.rank() == 3 and (len(EA) == 3 or y[(1, 2)] == 0) good = good and (Q_theta_node(6, edges, xv, [0, 0, 0] + beta) == sp.prod(Gam) * sp.prod(m) * (sum(om)**2 - 2 * sum(o**2 for o in om))) check('(2) Lemma 9.3: rank 3 and the formula for Q(x(m),u0), ' 'two and three terminal edges', good) # ---------------------------------------------------------------- (3) n, edges = K5 U = [Fr(1), Fr(157399, 100000), Fr(3902047, 1000000), Fr(1214551, 500000), Fr(-939987, 500000)] h = [Fr(random.randint(1, 10**6), random.randint(1, 10**6)) for _ in edges] signs = tiling_signs(n, edges, h) bq = [U[p] - U[q] for p, q in edges] mp.dps = 40 def tile_sum(z): tot = mpf(0) for S, eps in signs.items(): ph = sum(eps[l] * bq[l] for l in eps) term = cos(z * mpf(ph.numerator) / ph.denominator) for i in S: bi = mpf(bq[i].numerator) / bq[i].denominator term *= sin(bi * z) / (bi * z) tot += term return tot def brion_sum(z): tot = mpc(0) for p in itertools.permutations(range(5)): den = Fr(1) for k in range(4): den *= U[p[k + 1]] - U[p[k]] fr = sum((2 * k - 4) * U[p[k]] for k in range(5)) tot += exp(1j * z * mpf(fr.numerator) / fr.denominator) \ * den.denominator / den.numerator return tot ratios = [brion_sum(z) / (z**4 * tile_sum(z)) for z in (mpf('0.7'), mpf('2.3'))] check('(3) K_5, unit weights: tile formula (1) and Brion\'s vertex sum agree ' 'up to a constant', abs(ratios[0] - ratios[1]) < mpf(10)**(-30) and abs(ratios[0]) > 1) print('ALL CHECKS PASSED' if ok else 'SOME CHECK FAILED') sys.exit(0 if ok else 1)