"""Evaluate D1^16 D2^16 D4^16 of the product of seven x-coordinates at 17. Each invariant flow runs for 16 Taylor coefficients over the rings of already computed variables. All divisions are by units. The computation uses the actual vector fields on divisors and performs no Cartier steps. """ from itertools import combinations, product from math import factorial class TaylorRing: def __init__(self, p, inner_variables, bits): self.p, self.bits = p, bits width = 2*p-1 self.stride = bits * width**inner_variables self.mask = (1 << bits)-1 self.shifts = [bits * sum(k*width**j for j, k in enumerate(exponent)) for exponent in product(range(p), repeat=inner_variables)] def reduce(self, raw): if len(self.shifts) == 1: return raw % self.p return sum(((raw >> s) & self.mask) % self.p << s for s in self.shifts) def extend(self, coefficients): return sum(v << (self.stride * n) for n, v in enumerate(coefficients)) def partial_flow(p, degree, direction, initial, ring): g = (degree-1)//2 series = [[v] for v in initial] operations = [] def node(op, a, b): index = len(series) operations.append((index, op, a, b)) series.append([]) return index def mul(a, b): return node('mul', a, b) def add(a, b): return node('add', a, b) def scale(a, v): return node('scale', a, v % p) def multiply(indices): value, *rest = indices for x in rest: value = mul(value, x) return value x, y = list(range(g)), list(range(g, 2*g)) pairs = list(combinations(x, 2)) diff = {pair: 2*g+i for i, pair in enumerate(pairs)} for i, j in pairs: diff[j, i] = scale(diff[i, j], -1) dx, dy = [], [] for i in x: others = [j for j in x if i != j] # Lagrange numerator [X^(d-1)] product_(j!=i) (X-x_j). k = g-direction terms = [multiply(group) for group in combinations(others, k)] numerator = terms[0] for term in terms[1:]: numerator = add(numerator, term) weight = multiply([scale(numerator, (-1)**k)] + [diff[i, j] for j in others]) dx.append(mul(y[i], weight)) dy.append(scale(multiply([weight] + [i]*(degree-1)), degree * pow(2, -1, p))) dr = [mul(mul(diff[i, j], diff[i, j]), add(dx[j], scale(dx[i], -1))) for i, j in pairs] rhs = dx + dy + dr observable = multiply(x) for n in range(p): for index, op, a, b in operations: if op == 'mul': raw = sum(series[a][i] * series[b][n-i] for i in range(n+1)) elif op == 'add': raw = series[a][n] + series[b][n] else: raw = series[a][n] * b series[index].append(ring.reduce(raw)) if n+1 < p: for a, derivative in enumerate(rhs): series[a].append(ring.reduce(series[derivative][n] * pow(n+1, -1, p))) return [ring.extend(s) for s in series[:len(initial)]], series[observable][-1] def main(): p, degree = 17, 15 points = [(0, 4), (2, 5), (6, 6), (7, 2), (9, 1), (11, 8), (12, 3)] assert all((y*y - x**degree + 1) % p == 0 for x, y in points) xs, ys = map(list, zip(*points)) state = xs + ys + [pow(a-b, -1, p) for a, b in combinations(xs, 2)] # At most p³ coefficient products, each ≤(p-1)², per unnormalized # slot. Mixed radices 2p-1 prevent aliasing before truncation. bits = (p**3 * (p-1)**2 + 1).bit_length() axes = [4, 2, 1] for i, direction in enumerate(axes): ring = TaylorRing(p, i, bits) state, coefficient = partial_flow(p, degree, direction, state, ring) top_coefficient = (coefficient >> max(ring.shifts)) & ring.mask leading = top_coefficient * factorial(p-1)**len(axes) % p assert leading == 6 print('p=17, genus 7: D1^16 D2^16 D4^16 (product x_i) =', leading, 'mod 17') if __name__ == '__main__': main()