"""Direct two-variable divisor flow at p=13 on y²=x⁹-1. Uses NumPy and SciPy for exact convolution of bounded integer arrays. This check tests the orbit (1,4,7) and includes an exact differential whose chosen primitive has a vertical pole. """ from math import factorial import numpy as np from scipy.signal import convolve2d P = 13 N = 9 ONE = np.zeros((P, P), dtype=np.int64) ONE[0, 0] = 1 def multiply(a, b): # Each retained coefficient sums at most P² products of residues. return convolve2d(a % P, b % P, mode="full")[:P, :P] % P def power(a, n): result = ONE while n: if n & 1: result = multiply(result, a) a = multiply(a, a) n //= 2 return result def inverse(a): constant = int(a[0, 0]) % P assert constant # Every nonconstant monomial has p-th power zero in this quotient. return power(a, P-1) * pow(constant, -1, P) % P def lagrange(xs, direction): weights = [] for i, x in enumerate(xs): numerator, denominator = ONE, ONE for j, other in enumerate(xs): if j == i: continue denominator = multiply(denominator, x - other) if direction == 1: numerator = multiply(numerator, -other) # Direction 1 extracts the constant coefficient; 4 the leading one. assert direction in (1, 4) weights.append(multiply(numerator, inverse(denominator))) return weights def flow(xs, ys, direction, axis): for n in range(P-1): weights = lagrange(xs, direction) dx = [multiply(y, weight) for y, weight in zip(ys, weights)] dy = [N * pow(2, -1, P) * multiply(power(x, N-1), weight) % P for x, weight in zip(xs, weights)] for coordinate, rhs in zip(xs + ys, dx + dy): line = coordinate if axis == 0 else coordinate.T derivative = rhs if axis == 0 else rhs.T line[n+1] = derivative[n] * pow(n+1, -1, P) % P def check(points): xs = [ONE * x for x, _ in points] ys = [ONE * y for _, y in points] dx_at_mark = sum(int(y[0, 0]) * int(w[0, 0]) for y, w in zip(ys, lagrange(xs, 4))) % P flow(xs, ys, direction=1, axis=0) flow(xs, ys, direction=4, axis=1) for x, y in zip(xs, ys): assert not np.any((multiply(y, y) - power(x, N) + ONE) % P) weights = lagrange(xs, 1) scale = factorial(P-1)**2 % P def top(factors): return scale * sum(int(multiply(v, w)[-1, -1]) for v, w in zip(factors, weights)) % P monomials = [top([power(x, i-1) for x in xs]) for i in range(1, N)] integral_exact = top([2 * multiply(x, y) % P for x, y in zip(xs, ys)]) vertical_exact = top([multiply(power(x, P-1), y) for x, y in zip(xs, ys)]) assert monomials == [0, 0, 0, 0, 0, 0, 3, 0] assert integral_exact == 0 assert vertical_exact == (-7 * dx_at_mark) % P print(f"{points}: basis residues {monomials}, d(x²) = {integral_exact}, " f"d(x¹³/13) = {vertical_exact}") if __name__ == "__main__": check([(0, 5), (2, 2), (5, 2), (6, 2)]) check([(0, 5), (1, 0), (2, 2), (5, 2)])