"""Exact checks for the audited PDF. Requires Python 3 and NumPy. This program does not import the author's checks. It computes rectangular tables of actual derivatives using the two-variable Bezout polynomials of the universal divisor U,V,W. Arrays indexed by a multi-index store the derivative itself; products use the multi-index Leibniz formula. """ from functools import lru_cache from itertools import product from math import comb, factorial, prod import operator import sys import numpy as np def mul_poly(a, b, modulus): out = [0] * (len(a) + len(b) - 1) for i, x in enumerate(a): for j, y in enumerate(b): out[i + j] += x * y return [x % modulus for x in out] def initial_state(u, v, modulus): g = len(u) - 1 rhs = [-1] + [0] * (2 * g) + [1] for i, x in enumerate(mul_poly(v, v, modulus)): rhs[i] -= x w = [0] * (g + 2) for i in reversed(range(g + 2)): w[i] = rhs[i + g] % modulus for j, x in enumerate(u): rhs[i + j] -= w[i] * x assert all(n % modulus == 0 for n in rhs) return [n % modulus for n in u + v + w] def from_points(points, modulus): u = [1] for x, _ in points: u = mul_poly(u, [-x, 1], modulus) v = [0] * len(points) for x, y in points: basis = [1] denominator = 1 for z, _ in points: if x != z: basis = mul_poly(basis, [-z, 1], modulus) denominator *= x - z scalar = y * pow(denominator, -1, modulus) for j, value in enumerate(basis): v[j] += scalar * value return initial_state(u, v, modulus) def nonbranch_points(p, g, precision): points = [] modulus = p**precision for x in range(p): f = x**(2*g + 1) - 1 y = next((a for a in range(1, p) if (a*a - f) % p == 0), None) if y is not None: for _ in range(precision.bit_length()): y = (y - (y*y - f) * pow(2*y, -1, modulus)) % modulus assert (y*y - f) % modulus == 0 points.append((x, y)) return points def rules(g, direction): """Coefficients of z^(direction-1) in the three flow equations. B(A,B)=(A(X)B(z)-B(X)A(z))/(X-z). D(z)U=B(V,U), 2D(z)V=B(U,W)+U(X)U(z), D(z)W=B(W,V)-V(X)U(z), where D(z)=sum_i D_i z^(i-1). """ u = list(range(g + 1)) v = list(range(g + 1, 2*g + 1)) w = list(range(2*g + 1, 3*g + 3)) forms = [[] for _ in range(3*g + 3)] def bezout(a, b, targets): for i in range(direction, max(len(a),len(b))): for j in range(direction): k = i + j - direction assert k < len(targets) out = forms[targets[k]] if i < len(a) and j < len(b): out.append((a[i], b[j], 1)) if i < len(b) and j < len(a): out.append((b[i], a[j], -1)) bezout(v, u, u) # The temporarily retained degree-g coefficient cancels in 2D(z)V. for_v = list(v) + [len(forms)] forms.append([]) bezout(u, w, for_v) for dest, uk in zip(for_v, u): forms[dest].append((uk, u[direction-1], 1)) bezout(w, v, w) for dest, vk in zip(w, v): forms[dest].append((vk, u[direction-1], -1)) return forms[:-1], v def jets(initial, genus, axes, orders, modulus): """Compute all derivatives in a rectangle using the bilinear flow.""" shapes = tuple(n+1 for n in orders) size = len(initial) # With reduced Leibniz weights, every matrix entry is at most # prod(shapes)*(modulus-1)^3. Larger rings use exact Python integers. dtype = np.int64 if prod(shapes)*modulus**3 < 2**63 else object table = np.zeros(shapes+(size,), dtype=dtype) table[(0,)*len(axes)] = initial flow = [rules(genus, a) for a in axes] inverse_two = pow(2, -1, modulus) @lru_cache(None) def weights(m): col = np.array(1, dtype=dtype) for n in m: line = np.array([comb(n,k) % modulus for k in range(n+1)], dtype=dtype) col = (col[...,None] * line) % modulus return col.reshape(-1) for n in np.ndindex(shapes): if not any(n): continue axis = next(k for k, x in enumerate(n) if x) m = tuple(x - (k == axis) for k,x in enumerate(n)) window = table[tuple(slice(0,t+1) for t in m)] left = window.reshape(-1,size) right = np.flip(window,axis=tuple(range(len(m)))).reshape(-1,size) bilinear = ((left.T * weights(m)) @ right) % modulus polynomials, v_coords = flow[axis] derivative = [sum(sign*int(bilinear[i,j]) for i,j,sign in terms) for terms in polynomials] for j in v_coords: derivative[j] *= inverse_two table[n] = [x % modulus for x in derivative] return table def cartier(p, n, source, target): # Expand (X^n-1)^((p-1)/2) by repeated polynomial multiplication. poly = [1] base = [-1]+[0]*(n-1)+[1] for _ in range((p-1)//2): poly = mul_poly(poly, base, p) k = p*target - source return poly[k] if 0 <= k < len(poly) else 0 def genus_three(): for p, a, b in [(11,2,1), (23,1,2)]: m = p*p h, coeff = cartier(p,7,b,a), cartier(p,7,4,b) print(f'p={p} H={h}, B={coeff}, predicted first residue={-h*coeff%p}') target = (p,p-2) def marked_derivative(initial): table = jets(initial,3,(a,b),target,m) return -int(table[target][b-1]) % m # D_b Z = -u_(b-1) points = nonbranch_points(p,3,2) nb = [marked_derivative(from_points(points[i:i+3],m)) for i in (0,1)] print(' unramified nonbranch triples, derivative mod p^2:',nb) assert nb == ([60,71] if p==11 else [238,468]) actual = [] for s in range(m): if (s*s+s+2) % m == 0: state = initial_state([-1,-1-s,-s,1],[0,0,0],m) deriv = marked_derivative(state) normalized = deriv * pow(factorial(p-1)**2,-1,m) % m actual.append((s,deriv,normalized)) assert actual == ([(15,82,71),(105,27,16)] if p==11 else [(32,445,215),(496,215,514)]) print(' two-torsion mark (s, derivative, scaled Taylor coefficient):', actual) p = 11 m = p**12 pts = nonbranch_points(p,3,12)[:3] assert [(x,y%p) for x,y in pts] == [(4,2),(7,4),(8,1)] state = from_points(pts,m) pu0 = int(jets(state,3,(2,),(1,),m)[1,0]) % p value = int(jets(state,3,(1,),(121,),m)[121,0]) assert (pu0,value) == (2,3*p**11) v = (value//p**11) * pow(pu0,-1,p) % p w = v * cartier(11,7,1,2) % p assert (v,w)==(7,4) print('p=11, Pu0, Q^121u0 mod 11^12, v, w:',pu0,value,v,w) def other_genera(): expected=[0,0,0,0,0,0,3,0] for points in [[(0,5),(2,2),(5,2),(6,2)],[(0,5),(1,0),(2,2),(5,2)]]: # The coefficient of X^0 in X^(r-1) modulo U is the # contraction D1 of the r-th traced differential. Calculate # in the bivariate Taylor ring over F13, degrees <13 per variable. p, g = 13, 4 derivs=jets(from_points(points,p),g,(1,4),(12,12),p) normal=[pow(factorial(i),-1,p) for i in range(p)] t=(derivs*np.outer(normal,normal)[:,:,None])%p one=np.zeros((p,p),dtype=np.int64) one[0,0]=1 def times(f,g): # Kronecker packing with wide digits and no overlap of rows. stride=2*p-1 shifts=[[32*(i*stride+j) for j in range(p)] for i in range(p)] def pack(a): return sum(int(a[i,j])<>s) & 0xffffffff)%p for s in row] for row in shifts]) def times_x(rem): return [(r-times(rem[-1],t[:,:,i]))%p for i,r in enumerate([0*one]+rem[:-1])] rem=[one]+[0*one for _ in range(g-1)] row=[] for _ in range(2*g): row.append(int(rem[0][-1,-1]) * factorial(p-1)**2 % p) rem=times_x(rem) assert row==expected print('p=13, all eight basis residues:', row) # Contraction of Tr(x^j dx) with D1 is the constant coefficient # of X^j V(X) modulo U(X). The second example has primitive x^13/13. rem=[t[:,:,g+1+i] for i in range(g)] exact_tests=[] for j in range(1,13): rem=times_x(rem) if j in (1,12): scalar=2 if j==1 else 1 exact_tests.append(scalar*int(rem[0][-1,-1])*factorial(12)**2%p) assert exact_tests==[0,1 if points[1][0]==2 else 3] print(' primitive x^2 and primitive x^13/13:',exact_tests) p=17 pts=[(0,4),(2,5),(6,6),(7,2),(9,1),(11,8),(12,3)] series=jets(from_points(pts,p),7,(1,2,4),(16,16,16),p) actual = -int(series[16,16,16,0]) % p coeffs=[cartier(p,15,2,1),cartier(p,15,4,2),cartier(p,15,8,4)] assert actual==(-prod(coeffs))%p==6 print('p=17, direct mixed derivative of product in three directions:',actual,'Cartier:',coeffs) def long_flow(axis, order, inner_order, modulus): """Restrict to the Q-curve through the mark, then differentiate on 'axis'. The first nine ordinary Q-Taylor coefficients are available over Z/(11^12) since 9! is a unit. Pack this short polynomial in a large integer to do its exact convolutions inside a univariate derivative calculation along P. Width one also handles the pure Q calculation. """ p=11 precision=0 while p**precision < modulus: precision+=1 points=nonbranch_points(p,3,precision)[:3] state=from_points(points,modulus) table=jets(state,3,(1,),(inner_order,),modulus) width=inner_order+1 bits=((order+1)*width*modulus**3).bit_length()+1 shifts=[bits*j for j in range(width)] mask=(1<>s)&mask)%modulus)<>shifts[-1])&mask))%modulus def long_examples(): # The inner flow differentiates F=-u0 along Q. On the pure Q axis, # Q Z=F, so Q^1341 Z requires 1340 derivatives of F. for axis,order,inner,power,expected in [(2,1341,9,11,9),(1,1340,0,121,2)]: value=long_flow(axis,order,inner,11**(power+1)) assert value==expected*11**power print(f'p=11 long flow: D{axis}^{order} Q^{inner} F / 11^{power} = {expected} mod 11') if __name__ == '__main__': genus_three() other_genera() if '--long' in sys.argv[1:]: long_examples()