|
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 | + TESTS:: |
| 41 | +
|
| 42 | + sage: from sage.schemes.hyperelliptic_curves.constructor import _parse_multivariate_defining_equation |
| 43 | + sage: R.<x,y> = QQ[] |
| 44 | + sage: _parse_multivariate_defining_equation(y^2 + 3*x^2*y - (x^5 + x + 1)) |
| 45 | + ([1, 1, 0, 0, 0, 1], [0, 0, 3]) |
| 46 | + sage: _parse_multivariate_defining_equation(2*y^2 + 3*x^2*y - (x^5 + x + 1)) |
| 47 | + ([1/2, 1/2, 0, 0, 0, 1/2], [0, 0, 3/2]) |
| 48 | +
|
| 49 | + The variable names are arbitrary:: |
| 50 | +
|
| 51 | + sage: S.<z,t> = GF(13)[] |
| 52 | + sage: _parse_multivariate_defining_equation(2*t^2 + 3*z^2*t - (z^5 + z + 1)) |
| 53 | + ([7, 7, 0, 0, 0, 7], [0, 0, 8]) |
| 54 | + """ |
| 55 | + from sage.rings.polynomial.multi_polynomial import MPolynomial |
| 56 | + if not isinstance(g, MPolynomial): |
| 57 | + raise ValueError("must be a multivariate polynomial") |
| 58 | + |
| 59 | + variables = g.variables() |
| 60 | + if len(variables) != 2: |
| 61 | + raise ValueError("must be a polynomial in two variables") |
| 62 | + |
| 63 | + y, x = sorted(variables, key=g.degree) |
| 64 | + if g.degree(y) != 2: |
| 65 | + raise ValueError("must be a polynomial of degree 2 in a variable") |
| 66 | + |
| 67 | + f = [] |
| 68 | + h = [] |
| 69 | + for k, v in g: |
| 70 | + dx = v.degree(x) |
| 71 | + dy = v.degree(y) |
| 72 | + if dy == 2: |
| 73 | + if dx != 0: |
| 74 | + raise ValueError(f"cannot have a term y*x^{dx}") |
| 75 | + y2 = k |
| 76 | + elif dy == 1: |
| 77 | + while len(h) <= dx: |
| 78 | + h.append(0) |
| 79 | + h[dx] = k |
| 80 | + else: |
| 81 | + assert dy == 0 |
| 82 | + while len(f) <= dx: |
| 83 | + f.append(0) |
| 84 | + f[dx] = -k |
| 85 | + |
| 86 | + if not y2.is_one(): |
| 87 | + y2_inv = y2.inverse_of_unit() |
| 88 | + f = [c * y2_inv for c in f] |
| 89 | + h = [c * y2_inv for c in h] |
| 90 | + |
| 91 | + return f, h |
| 92 | + |
| 93 | + |
| 94 | +def HyperellipticCurve(f, h=None, names=None, PP=None, check_squarefree=True): |
33 | 95 | r"""
|
34 | 96 | Return the hyperelliptic curve `y^2 + h y = f`, for
|
35 | 97 | univariate polynomials `h` and `f`. If `h`
|
@@ -76,6 +138,12 @@ def HyperellipticCurve(f, h=0, names=None, PP=None, check_squarefree=True):
|
76 | 138 | Hyperelliptic Curve over Finite Field in a of size 3^2
|
77 | 139 | defined by y^2 + (x + a)*y = x^3 + x + 2
|
78 | 140 |
|
| 141 | + Construct from defining polynomial:: |
| 142 | +
|
| 143 | + sage: R.<x,y> = QQ[] |
| 144 | + sage: HyperellipticCurve(y^2 + 3*x^2*y - (x^5 + x + 1)) |
| 145 | + Hyperelliptic Curve over Rational Field defined by y^2 + 3*x^2*y = x^5 + x + 1 |
| 146 | +
|
79 | 147 | Characteristic two::
|
80 | 148 |
|
81 | 149 | sage: # needs sage.rings.finite_rings
|
@@ -200,6 +268,17 @@ def HyperellipticCurve(f, h=0, names=None, PP=None, check_squarefree=True):
|
200 | 268 | """
|
201 | 269 | # F is the discriminant; use this for the type check
|
202 | 270 | # rather than f and h, one of which might be constant.
|
| 271 | + if h is None: |
| 272 | + from sage.rings.polynomial.multi_polynomial import MPolynomial |
| 273 | + if isinstance(f, MPolynomial) and len(f.parent().gens()) == 2: |
| 274 | + from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing |
| 275 | + from sage.structure.element import get_coercion_model |
| 276 | + P = PolynomialRing(f.base_ring(), 'x') |
| 277 | + f, h = _parse_multivariate_defining_equation(f) |
| 278 | + f, h = P(f), P(h) |
| 279 | + else: |
| 280 | + h = 0 |
| 281 | + |
203 | 282 | F = h**2 + 4 * f
|
204 | 283 | if not isinstance(F, Polynomial):
|
205 | 284 | raise TypeError(f"arguments f = {f} and h = {h} must be polynomials")
|
|
0 commit comments