|
29 | 29 | from sage.structure.dynamic_class import dynamic_class
|
30 | 30 |
|
31 | 31 |
|
32 |
| -def HyperellipticCurve(f, h=0, names=None, PP=None, check_squarefree=True): |
| 32 | +def _parse_multivariate_defining_equation(g): |
| 33 | + """ |
| 34 | + Parse a defining equation for a hyperelliptic curve. |
| 35 | + The input `g` should have the form `g(x, y) = y^2 + h(x) y - f(x)`, |
| 36 | + or a constant multiple of that. |
| 37 | +
|
| 38 | + OUTPUT: tuple (f, h), each of them given as a list of coefficients. |
| 39 | + """ |
| 40 | + from sage.rings.polynomial.multi_polynomial import MPolynomial |
| 41 | + if not isinstance(g, MPolynomial): |
| 42 | + raise ValueError("must be a multivariate polynomial") |
| 43 | + |
| 44 | + variables = g.variables() |
| 45 | + if len(variables) != 2: |
| 46 | + raise ValueError("must be a polynomial in two variables") |
| 47 | + |
| 48 | + y, x = sorted(variables, key=g.degree) |
| 49 | + if g.degree(y) != 2: |
| 50 | + raise ValueError("must be a polynomial of degree 2 in a variable") |
| 51 | + |
| 52 | + f = [] |
| 53 | + h = [] |
| 54 | + for k, v in g: |
| 55 | + dx = v.degree(x) |
| 56 | + dy = v.degree(y) |
| 57 | + if dy == 2: |
| 58 | + if dx != 0: |
| 59 | + raise ValueError(f"cannot have a term y*x^{dx}") |
| 60 | + y2 = k |
| 61 | + elif dy == 1: |
| 62 | + while len(h) <= dx: |
| 63 | + h.append(0) |
| 64 | + h[dx] = k |
| 65 | + else: |
| 66 | + assert dy == 0 |
| 67 | + while len(f) <= dx: |
| 68 | + f.append(0) |
| 69 | + f[dx] = -k |
| 70 | + |
| 71 | + if not y2.is_one(): |
| 72 | + y2_inv = y2.inverse_of_unit() |
| 73 | + f = [c * y2_inv for c in f] |
| 74 | + h = [c * y2_inv for c in h] |
| 75 | + |
| 76 | + return f, h |
| 77 | + |
| 78 | + |
| 79 | +def HyperellipticCurve(f, h=None, names=None, PP=None, check_squarefree=True): |
33 | 80 | r"""
|
34 | 81 | Return the hyperelliptic curve `y^2 + h y = f`, for
|
35 | 82 | univariate polynomials `h` and `f`. If `h`
|
@@ -76,6 +123,12 @@ def HyperellipticCurve(f, h=0, names=None, PP=None, check_squarefree=True):
|
76 | 123 | Hyperelliptic Curve over Finite Field in a of size 3^2
|
77 | 124 | defined by y^2 + (x + a)*y = x^3 + x + 2
|
78 | 125 |
|
| 126 | + Construct from defining polynomial:: |
| 127 | +
|
| 128 | + sage: R.<x,y> = QQ[] |
| 129 | + sage: HyperellipticCurve(y^2 + 3*x^2*y - (x^5 + x + 1)) |
| 130 | + Hyperelliptic Curve over Rational Field defined by y^2 + 3*x^2*y = x^5 + x + 1 |
| 131 | +
|
79 | 132 | Characteristic two::
|
80 | 133 |
|
81 | 134 | sage: # needs sage.rings.finite_rings
|
@@ -200,6 +253,17 @@ def HyperellipticCurve(f, h=0, names=None, PP=None, check_squarefree=True):
|
200 | 253 | """
|
201 | 254 | # F is the discriminant; use this for the type check
|
202 | 255 | # rather than f and h, one of which might be constant.
|
| 256 | + if h is None: |
| 257 | + from sage.rings.polynomial.multi_polynomial import MPolynomial |
| 258 | + if isinstance(f, MPolynomial) and len(f.parent().gens()) == 2: |
| 259 | + from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing |
| 260 | + from sage.structure.element import get_coercion_model |
| 261 | + P = PolynomialRing(f.base_ring(), 'x') |
| 262 | + f, h = _parse_multivariate_defining_equation(f) |
| 263 | + f, h = P(f), P(h) |
| 264 | + else: |
| 265 | + h = 0 |
| 266 | + |
203 | 267 | F = h**2 + 4 * f
|
204 | 268 | if not isinstance(F, Polynomial):
|
205 | 269 | raise TypeError(f"arguments f = {f} and h = {h} must be polynomials")
|
|
0 commit comments