"""Exact checks supporting, not replacing, the genus-two isogeny proof.""" import json import sympy as s def character(a, p): value = pow(a % p, (p - 1) // 2, p) return 0 if value == 0 else 1 if value == 1 else -1 def trace(p, t): return -sum(character(x**3 + 9*x*x + 6*(t+2)*x + (t+2)**2, p) for x in range(p)) def chebyshev3(x, p): return (x**3 - 3*x) % p def main(): x, y, t, b, c = s.symbols("x y t b c") a = t + 2 xp = x + b*c/x + c*c/x**2 yp = y - c*c*(2*y+b*x+c)/x**3 - b*c*(b*x+y)/x**2 - b*c*c/x**2 quotient_equation = yp**2+b*xp*yp+c*yp-xp**3+5*b*c*xp+c*(b**3+7*c) numerator = s.together(quotient_equation).as_numer_denom()[0] residual = s.rem(s.Poly(numerator, y), s.Poly(y*y+b*x*y+c*y-x**3, y)).as_expr().factor() assert residual == 0 quotient = x**3+9*x*x-54*a*x-27*a*(t+18) twist = x**3-27*x*x+54*(2-t)*x-27*(t-2)**2 assert s.expand(twist.subs(x, x+12)-quotient) == 0 b2, b4, b6 = 36, 12*a, 4*a*a c4 = s.factor(b2*b2-24*b4) discriminant = s.factor(-8*b4**3-27*b6**2+9*b2*b4*b6) assert s.expand(discriminant-432*(2-t)*(t+2)**3) == 0 j_invariant = s.factor(c4**3/discriminant) rows = [] for p, u in [(53, 4), (107, 47)]: assert chebyshev3(u, p) == p-1 ts = [v for v in range(p) if chebyshev3(v, p) == u] assert len(ts) == 3 for v in ts: assert v not in (2, p-2) ap, am = trace(p, v), trace(p, (-v) % p) assert am == -ap rows.append({ "p": p, "u": u, "t": v, "a_plus": ap, "a_minus": am, "N_Eplus": p+1-ap, "N_Eminus": p+1-am, "P_descending_coefficients": [1, 0, 2*p-ap*ap, 0, p*p], }) assert [r["a_plus"] for r in rows if r["p"] == 53] == [3, 9, -9] assert [r["a_plus"] for r in rows if r["p"] == 107] == [-9, -9, -9] output = { "symbolic": { "velu_residual": str(residual), "twist_translation_difference": "0", "c4": str(c4), "discriminant": str(discriminant), "j": str(j_invariant), }, "rows": rows, } print(json.dumps(output, indent=2)) if __name__ == "__main__": main()