reduction.sage 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. F = GF(47)
  2. K.<x, y> = F[]
  3. EC_A, EC_B = 4, 0
  4. E = EllipticCurve(F, [EC_A, EC_B])
  5. C = E.defining_polynomial()
  6. S = K.quotient(C(x, y, 1)).fraction_field()
  7. X, Y = S(x), S(y)
  8. inf = E[0]
  9. # If we have points sharing the same x value then construct a vertical
  10. # line through them to eliminate them.
  11. points = [(34, 30), (44, 14), (7, 18), (28, 31), (27, 45), (12, 15),
  12. (43, 22), (11, 23), (38, 9), (0, 1), (26, 33)]
  13. def lagrange_basis(x_k, domain):
  14. assert x_k in domain
  15. domain = [x_i for x_i in domain if x_i != x_k]
  16. assert x_k not in domain
  17. l = 1
  18. for x_i in domain:
  19. l *= (x - x_i)
  20. l /= l(x_k, 0)
  21. # Check everything is correct
  22. assert l(x_k, 0) == 1
  23. for x_i in domain:
  24. assert l(x_i, 0) == 0
  25. return l
  26. print(f"P = {points}")
  27. domain = [Px for Px, _ in points]
  28. f = 0
  29. for Px, Py in points:
  30. f += Py * lagrange_basis(Px, domain)
  31. # Now make it zero at all the y values
  32. f = y - f
  33. # Check polynomial is correct
  34. for Px, Py in points:
  35. assert f(Px, Py) == 0
  36. # Now find remaining points in the support
  37. I = ideal([C(x, y, 1), f])
  38. V = [(info[x], info[y]) for info in I.variety()]
  39. print(f"V(I) = {V}")
  40. diff = set(P) - set(V)
  41. print(f"diff = {diff}")