Repository: sagemath/sage

Issue:
Rational `.sqrt()` should return an empty list instead of raising an error when `all=True`
### Steps To Reproduce


```py
sage: K = QQ[I]
sage: K(3).sqrt(extend=False, all=True)
[]
sage: ZZ(3).sqrt(extend=False, all=True)
[]
sage: QQ(3).sqrt(extend=False, all=True)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [19], line 1
----> 1 QQ(Integer(3)).sqrt(extend=False, all=True)

File ~/sage/sage-10.2/src/sage/rings/rational.pyx:1971, in sage.rings.rational.Rational.sqrt()
   1969 if non_square:
   1970     if not extend:
-> 1971         raise ValueError("square root of %s not a rational number" % self)
   1972     from sage.misc.functional import _do_sqrt
   1973     return _do_sqrt(self, prec=prec, all=all)

ValueError: square root of 3 not a rational number
```

### Expected Behavior

When the `all=True` param is set, when there are no sqrt an empty list should be returned:

```py
sage: QQ(3).sqrt(extend=False, all=True)
[]
```

### Actual Behavior

When the `all=True` param is set, when there are no sqrt an empty list should be returned:

```py
sage: QQ(3).sqrt(extend=False, all=True)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [19], line 1
----> 1 QQ(Integer(3)).sqrt(extend=False, all=True)

File ~/sage/sage-10.2/src/sage/rings/rational.pyx:1971, in sage.rings.rational.Rational.sqrt()
   1969 if non_square:
   1970     if not extend:
-> 1971         raise ValueError("square root of %s not a rational number" % self)
   1972     from sage.misc.functional import _do_sqrt
   1973     return _do_sqrt(self, prec=prec, all=all)

ValueError: square root of 3 not a rational number
```

### Additional Information

_No response_

### Environment

```markdown
- **OS**: MacOS
- **Sage Version**: 10.2
```


### Checklist

- [X] I have searched the existing issues for a bug report that matches the one I want to file, without success.
- [X] I have read the documentation and troubleshoot guide


Discussion:

Resolving patch:
diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py
--- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py
+++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py
@@ -248,29 +248,265 @@ def is_smooth(self):
         """
         return True
 
+    def is_x_coord(self, x):
+        """
+        Return True if ``x`` is the `x`-coordinate of a point on this curve.
+
+        .. SEEALSO::
+
+            See also :meth:`lift_x` to find the point(s) with a given
+            `x`-coordinate.  This function may be useful in cases where
+            testing an element of the base field for being a square is
+            faster than finding its square root.
+
+        INPUT:
+
+        - ``x`` -- an element of the base ring of the curve
+
+        OUTPUT:
+
+        A bool stating whether or not `x` is a x-coordinate of a point on the curve
+
+        EXAMPLES:
+
+        When `x` is the `x`-coordinate of a rational point on the
+        curve, we can request these::
+
+            sage: R.<x> = PolynomialRing(QQ)
+            sage: f = x^5 + x^3 + 1
+            sage: H = HyperellipticCurve(f)
+            sage: H.is_x_coord(0)
+            True
+
+        There are no rational points with `x`-coordinate 3::
+
+            sage: H.is_x_coord(3)
+            False
+
+        The function also handles the case when `h(x)` is not zero::
+
+            sage: R.<x> = PolynomialRing(QQ)
+            sage: f = x^5 + x^3 + 1
+            sage: h = x + 1
+            sage: H = HyperellipticCurve(f, h)
+            sage: H.is_x_coord(1)
+            True
+
+        We can perform these operations over finite fields too::
+
+            sage: # needs sage.rings.finite_rings
+            sage: R.<x> = PolynomialRing(GF(163))
+            sage: f = x^7 + x + 1
+            sage: H = HyperellipticCurve(f)
+            sage: H.is_x_coord(13)
+            True
+
+        Including the case of characteristic two::
+
+            sage: # needs sage.rings.finite_rings
+            sage: F.<z4> = GF(2^4)
+            sage: R.<x> = PolynomialRing(F)
+            sage: f = x^7 + x^3 + 1
+            sage: h = x + 1
+            sage: H = HyperellipticCurve(f, h)
+            sage: H.is_x_coord(z4^3 + z4^2 + z4)
+            True
+
+        AUTHORS:
+
+        - Giacomo Pope (2024): adapted from :meth:`lift_x`
+
+        TESTS:
+
+        The `x`-coordinate must be defined over the base field of the curve::
+
+            sage: p = 11
+            sage: F = GF(11)
+            sage: F_ext = GF(11^2)
+            sage: R.<x> = PolynomialRing(F)
+            sage: f = x^7 + x^3 + 1
+            sage: H = HyperellipticCurve(f)
+            sage: H.is_x_coord(F_ext.gen())
+            Traceback (most recent call last):
+            ...
+            TypeError: x must be coercible into the base ring of the curve
+        """
+        f, h = self.hyperelliptic_polynomials()
+        K = self.base_ring()
+        try:
+            x = K(x)
+        except (ValueError, TypeError):
+            raise TypeError('x must be coercible into the base ring of the curve')
+
+        # When h is zero then x is a valid coordinate if y2 is square
+        if not h:
+            y2 = f(x)
+            return y2.is_square()
+        # Generic case for h != 0
+        a = f(x)
+        b = h(x)
+        # Special case for char 2
+        if K.characteristic() == 2:
+            R = f.parent()  # Polynomial ring K[x]
+            F = R([-a, b, 1])
+            return bool(F.roots())
+        # Otherwise x is a point on the curve if the discriminant is a square
+        D = b*b + 4*a
+        return D.is_square()
+
     def lift_x(self, x, all=False):
-        f, h = self._hyperelliptic_polynomials
-        x += self.base_ring()(0)
-        one = x.parent()(1)
-        if h.is_zero():
+        """
+        Return one or all points with given `x`-coordinate.
+
+        This method is deterministic: It returns the same data each
+        time when called again with the same `x`.
+
+        INPUT:
+
+        - ``x`` -- an element of the base ring of the curve
+
+        - ``all`` (bool, default ``False``) -- if ``True``, return a
+          (possibly empty) list of all points; if ``False``, return
+          just one point, or raise a :class:`ValueError` if there are none.
+
+        OUTPUT:
+
+        A point or list of up to two points on this curve.
+
+        .. SEEALSO::
+
+            :meth:`is_x_coord`
+
+        AUTHORS:
+
+        - Giacomo Pope (2024): Allowed for the case of characteristic two
+
+        EXAMPLES:
+
+        When `x` is the `x`-coordinate of a rational point on the
+        curve, we can request these::
+
+            sage: R.<x> = PolynomialRing(QQ)
+            sage: f = x^5 + x^3 + 1
+            sage: H = HyperellipticCurve(f)
+            sage: H.lift_x(0)
+            (0 : -1 : 1)
+            sage: H.lift_x(4, all=True)
+            [(4 : -33 : 1), (4 : 33 : 1)]
+
+        There are no rational points with `x`-coordinate 3::
+
+            sage: H.lift_x(3)
+            Traceback (most recent call last):
+            ...
+            ValueError: No point with x-coordinate 3 on Hyperelliptic Curve over Rational Field defined by y^2 = x^5 + x^3 + 1
+
+        An empty list is returned when there are no points and ``all=True``::
+
+            sage: H.lift_x(3, all=True)
+            []
+
+        The function also handles the case when `h(x)` is not zero::
+
+            sage: R.<x> = PolynomialRing(QQ)
+            sage: f = x^5 + x^3 + 1
+            sage: h = x + 1
+            sage: H = HyperellipticCurve(f, h)
+            sage: H.lift_x(1)
+            (1 : -3 : 1)
+
+        We can perform these operations over finite fields too::
+
+            sage: # needs sage.rings.finite_rings
+            sage: R.<x> = PolynomialRing(GF(163))
+            sage: f = x^7 + x + 1
+            sage: H = HyperellipticCurve(f)
+            sage: H.lift_x(13)
+            (13 : 41 : 1)
+
+        Including the case of characteristic two::
+
+            sage: # needs sage.rings.finite_rings
+            sage: F.<z4> = GF(2^4)
+            sage: R.<x> = PolynomialRing(F)
+            sage: f = x^7 + x^3 + 1
+            sage: h = x + 1
+            sage: H = HyperellipticCurve(f, h)
+            sage: H.lift_x(z4^3 + z4^2 + z4, all=True)
+            [(z4^3 + z4^2 + z4 : z4^2 + z4 + 1 : 1), (z4^3 + z4^2 + z4 : z4^3 : 1)]
+
+        TESTS::
+
+            sage: # needs sage.rings.finite_rings
+            sage: F1 = GF(11)
+            sage: F2 = GF(13)
+            sage: R.<x> = PolynomialRing(F1)
+            sage: f = x^7 + x^3 + 1
+            sage: H = HyperellipticCurve(f)
+            sage: H.lift_x(F2.random_element())
+            Traceback (most recent call last):
+            ...
+            ValueError: x must have a common parent with the base ring
+
+        Ensure that :issue:`37097` is fixed::
+
+            sage: # needs sage.rings.finite_rings
+            sage: F.<z4> = GF(2^4)
+            sage: R.<x> = PolynomialRing(F)
+            sage: f = x^7 + x^3 + 1
+            sage: h = x + 1
+            sage: H = HyperellipticCurve(f, h)
+            sage: H.lift_x(z4^3 + z4^2 + z4, all=True)
+            [(z4^3 + z4^2 + z4 : z4^2 + z4 + 1 : 1), (z4^3 + z4^2 + z4 : z4^3 : 1)]
+        """
+        from sage.structure.element import get_coercion_model
+        cm = get_coercion_model()
+
+        f, h = self.hyperelliptic_polynomials()
+        K = self.base_ring()
+
+        # Compute the common parent between the base ring of the curve and
+        # the parent of the input x-coordinate.
+        try:
+            L = cm.common_parent(x.parent(), K)
+            x = L(x)
+        except (TypeError, ValueError):
+            raise ValueError('x must have a common parent with the base ring')
+
+        # First we compute the y-coordinates the given x-coordinate
+        ys = []
+        one = L.one()
+
+        # When h is zero we find all y-coordinates with a single sqrt
+        if not h:
             y2 = f(x)
-            if y2.is_square():
-                if all:
-                    return [self.point([x, y, one], check=False) for y in y2.sqrt(all=True)]
-                else:
-                    return self.point([x, y2.sqrt(), one], check=False)
+            # When y2 is not a square, ys will be an empty list
+            ys = y2.sqrt(all=True, extend=False)
+        # Otherwise we need roots of the discriminant
         else:
+            a = f(x)
             b = h(x)
-            D = b*b + 4*f(x)
-            if D.is_square():
-                if all:
-                    return [self.point([x, (-b+d)/2, one], check=False) for d in D.sqrt(all=True)]
-                else:
-                    return self.point([x, (-b+D.sqrt())/2, one], check=False)
+            # Special case for char 2
+            if K.characteristic() == 2:
+                R = f.parent()
+                F = R([-a, b, 1])
+                ys = F.roots(L, multiplicities=False)
+            else:
+                D = b*b + 4*a
+                # When D is not a square, ys will be an empty list
+                ys = [(-b+d)/2 for d in D.sqrt(all=True, extend=False)]
+
+        if ys:
+            ys.sort()  # Make lifting deterministic
+            if all:
+                return [self.point([x, y, one], check=False) for y in ys]
+            else:
+                return self.point([x, ys[0], one], check=False)
+
         if all:
             return []
         else:
-            raise ValueError("No point with x-coordinate %s on %s" % (x, self))
+            raise ValueError(f"No point with x-coordinate {x} on {self}")
 
     def genus(self):
         return self._genus
diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_padic_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_padic_field.py
--- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_padic_field.py
+++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_padic_field.py
@@ -103,7 +103,7 @@ def local_analytic_interpolation(self, P, Q):
             sage: x,y,z = HK.local_analytic_interpolation(P,HK(1,0))
             Traceback (most recent call last):
             ...
-            ValueError: (5^-2 + O(5^6) : 5^-3 + 4*5^2 + 5^3 + 3*5^4 + O(5^5) : 1 + O(5^8)) and (1 + O(5^8) : 0 : 1 + O(5^8)) are not in the same residue disc
+            ValueError: (5^-2 + O(5^6) : 4*5^-3 + 4*5^-2 + 4*5^-1 + 4 + 4*5 + 3*5^3 + 5^4 + O(5^5) : 1 + O(5^8)) and (1 + O(5^8) : 0 : 1 + O(5^8)) are not in the same residue disc
 
         TESTS:
 
@@ -186,7 +186,7 @@ def is_in_weierstrass_disc(self, P):
             sage: HK.is_in_weierstrass_disc(S)
             True
             sage: T = HK.lift_x(1+3*5^2); T
-            (1 + 3*5^2 + O(5^8) : 2*5 + 4*5^3 + 3*5^4 + 5^5 + 3*5^6 + O(5^7) : 1 + O(5^8))
+            (1 + 3*5^2 + O(5^8) : 3*5 + 4*5^2 + 5^4 + 3*5^5 + 5^6 + O(5^7) : 1 + O(5^8))
             sage: HK.is_in_weierstrass_disc(T)
             True
 
@@ -216,7 +216,7 @@ def is_weierstrass(self, P):
             sage: HK.is_weierstrass(S)
             True
             sage: T = HK.lift_x(1+3*5^2); T
-            (1 + 3*5^2 + O(5^8) : 2*5 + 4*5^3 + 3*5^4 + 5^5 + 3*5^6 + O(5^7) : 1 + O(5^8))
+            (1 + 3*5^2 + O(5^8) : 3*5 + 4*5^2 + 5^4 + 3*5^5 + 5^6 + O(5^7) : 1 + O(5^8))
             sage: HK.is_weierstrass(T)
             False
 
@@ -364,7 +364,7 @@ def tiny_integrals(self, F, P, Q):
             sage: P = C.lift_x(11^(-2))
             sage: Q = C.lift_x(3*11^(-2))
             sage: C.tiny_integrals([1],P,Q)
-            (3*11^3 + 7*11^4 + 4*11^5 + 7*11^6 + 5*11^7 + O(11^8))
+            (5*11^3 + 7*11^4 + 2*11^5 + 6*11^6 + 11^7 + O(11^8))
 
         Note that this fails if the points are not in the same residue disc::
 
@@ -426,7 +426,7 @@ def tiny_integrals_on_basis(self, P, Q):
             sage: P = C.lift_x(11^(-2))
             sage: Q = C.lift_x(3*11^(-2))
             sage: C.tiny_integrals_on_basis(P,Q)
-            (3*11^3 + 7*11^4 + 4*11^5 + 7*11^6 + 5*11^7 + O(11^8), 3*11 + 10*11^2 + 8*11^3 + 9*11^4 + 7*11^5 + O(11^6), 4*11^-1 + 2 + 6*11 + 6*11^2 + 7*11^3 + O(11^4), 11^-3 + 6*11^-2 + 2*11^-1 + 2 + O(11^2))
+            (5*11^3 + 7*11^4 + 2*11^5 + 6*11^6 + 11^7 + O(11^8), 10*11 + 2*11^3 + 3*11^4 + 5*11^5 + O(11^6), 5*11^-1 + 8 + 4*11 + 10*11^2 + 7*11^3 + O(11^4), 2*11^-3 + 11^-2 + 11^-1 + 10 + 8*11 + O(11^2))
 
 
         Note that this fails if the points are not in the same residue disc::
@@ -497,19 +497,19 @@ def coleman_integrals_on_basis(self, P, Q, algorithm=None):
             sage: P = C.lift_x(2)
             sage: Q = C.lift_x(3)
             sage: C.coleman_integrals_on_basis(P, Q)
-            (10*11 + 6*11^3 + 2*11^4 + O(11^5), 11 + 9*11^2 + 7*11^3 + 9*11^4 + O(11^5), 3 + 10*11 + 5*11^2 + 9*11^3 + 4*11^4 + O(11^5), 3 + 11 + 5*11^2 + 4*11^4 + O(11^5))
+            (9*11^2 + 7*11^3 + 5*11^4 + O(11^5), 11 + 3*11^2 + 7*11^3 + 11^4 + O(11^5), 10*11 + 11^2 + 5*11^3 + 5*11^4 + O(11^5), 3 + 9*11^2 + 6*11^3 + 11^4 + O(11^5))
             sage: C.coleman_integrals_on_basis(P, Q, algorithm='teichmuller')
-            (10*11 + 6*11^3 + 2*11^4 + O(11^5), 11 + 9*11^2 + 7*11^3 + 9*11^4 + O(11^5), 3 + 10*11 + 5*11^2 + 9*11^3 + 4*11^4 + O(11^5), 3 + 11 + 5*11^2 + 4*11^4 + O(11^5))
+            (9*11^2 + 7*11^3 + 5*11^4 + O(11^5), 11 + 3*11^2 + 7*11^3 + 11^4 + O(11^5), 10*11 + 11^2 + 5*11^3 + 5*11^4 + O(11^5), 3 + 9*11^2 + 6*11^3 + 11^4 + O(11^5))
 
         ::
 
             sage: K = pAdicField(11,5)
             sage: x = polygen(K)
             sage: C = HyperellipticCurve(x^5 + 33/16*x^4 + 3/4*x^3 + 3/8*x^2 - 1/4*x + 1/16)
-            sage: P = C.lift_x(11^(-2))
-            sage: Q = C.lift_x(3*11^(-2))
+            sage: P = C(11^-2, 10*11^-5 + 10*11^-4 + 10*11^-3 + 2*11^-2 + 10*11^-1)
+            sage: Q = C(3*11^-2, 11^-5 + 11^-3 + 10*11^-2 + 7*11^-1)
             sage: C.coleman_integrals_on_basis(P, Q)
-            (3*11^3 + 7*11^4 + 4*11^5 + 7*11^6 + 5*11^7 + O(11^8), 3*11 + 10*11^2 + 8*11^3 + 9*11^4 + 7*11^5 + O(11^6), 4*11^-1 + 2 + 6*11 + 6*11^2 + 7*11^3 + O(11^4), 11^-3 + 6*11^-2 + 2*11^-1 + 2 + O(11^2))
+            (6*11^3 + 3*11^4 + 8*11^5 + 4*11^6 + 9*11^7 + O(11^8), 11 + 10*11^2 + 8*11^3 + 7*11^4 + 5*11^5 + O(11^6), 6*11^-1 + 2 + 6*11 + 3*11^3 + O(11^4), 9*11^-3 + 9*11^-2 + 9*11^-1 + 2*11 + O(11^2))
 
         ::
 
@@ -538,9 +538,9 @@ def coleman_integrals_on_basis(self, P, Q, algorithm=None):
             sage: HK.coleman_integrals_on_basis(P,S) == -HK.coleman_integrals_on_basis(S,P)
             True
             sage: HK.coleman_integrals_on_basis(S,Q)
-            (4*5 + 4*5^2 + 4*5^3 + O(5^4), 5^-1 + O(5^3))
+            (5 + O(5^4), 4*5^-1 + 4 + 4*5 + 4*5^2 + O(5^3))
             sage: HK.coleman_integrals_on_basis(Q,R)
-            (4*5 + 2*5^2 + 2*5^3 + 2*5^4 + 5^5 + 5^6 + 5^7 + 3*5^8 + O(5^9), 2*5^-1 + 4 + 4*5 + 4*5^2 + 4*5^3 + 2*5^4 + 3*5^5 + 2*5^6 + O(5^7))
+            (5 + 2*5^2 + 2*5^3 + 2*5^4 + 3*5^5 + 3*5^6 + 3*5^7 + 5^8 + O(5^9), 3*5^-1 + 2*5^4 + 5^5 + 2*5^6 + O(5^7))
             sage: HK.coleman_integrals_on_basis(S,R) == HK.coleman_integrals_on_basis(S,Q) + HK.coleman_integrals_on_basis(Q,R)
             True
             sage: HK.coleman_integrals_on_basis(T,T)
@@ -748,7 +748,7 @@ def coleman_integral(self, w, P, Q, algorithm='None'):
             (O(71^4), O(71^4))
             sage: R, R1 = C.lift_x(4, all=True)
             sage: w.integrate(P, R)
-            21*71 + 67*71^2 + 27*71^3 + O(71^4)
+            50*71 + 3*71^2 + 43*71^3 + O(71^4)
             sage: w.integrate(P, R) + w.integrate(P1, R1)
             O(71^4)
 
@@ -792,7 +792,7 @@ def coleman_integral(self, w, P, Q, algorithm='None'):
             sage: HK = H.change_ring(K)
             sage: w = HK.invariant_differential()
             sage: P = HK(0,1)
-            sage: Q = HK.lift_x(5)
+            sage: Q = HK(5, 1 + 3*5^3 + 2*5^4 + 2*5^5 + 3*5^7)
             sage: x,y = HK.monsky_washnitzer_gens()
             sage: (2*y*w).coleman_integral(P,Q)
             5 + O(5^9)
@@ -881,11 +881,11 @@ def frobenius(self, P=None):
             sage: E = HyperellipticCurve(x^5 - 21*x - 20)
             sage: P = E.lift_x(2)
             sage: E.frobenius(P)
-            (2 + 10*11 + 5*11^2 + 11^3 + O(11^5) : 5 + 9*11 + 2*11^2 + 2*11^3 + O(11^5) : 1 + O(11^5))
+            (2 + 10*11 + 5*11^2 + 11^3 + O(11^5) : 6 + 11 + 8*11^2 + 8*11^3 + 10*11^4 + O(11^5) : 1 + O(11^5))
             sage: Q = E.teichmuller(P); Q
-            (2 + 10*11 + 4*11^2 + 9*11^3 + 11^4 + O(11^5) : 5 + 9*11 + 6*11^2 + 11^3 + 6*11^4 + O(11^5) : 1 + O(11^5))
+            (2 + 10*11 + 4*11^2 + 9*11^3 + 11^4 + O(11^5) : 6 + 11 + 4*11^2 + 9*11^3 + 4*11^4 + O(11^5) : 1 + O(11^5))
             sage: E.frobenius(Q)
-            (2 + 10*11 + 4*11^2 + 9*11^3 + 11^4 + O(11^5) : 5 + 9*11 + 6*11^2 + 11^3 + 6*11^4 + O(11^5) : 1 + O(11^5))
+            (2 + 10*11 + 4*11^2 + 9*11^3 + 11^4 + O(11^5) : 6 + 11 + 4*11^2 + 9*11^3 + 4*11^4 + O(11^5) : 1 + O(11^5))
 
         ::
 
diff --git a/src/sage/schemes/hyperelliptic_curves/jacobian_morphism.py b/src/sage/schemes/hyperelliptic_curves/jacobian_morphism.py
--- a/src/sage/schemes/hyperelliptic_curves/jacobian_morphism.py
+++ b/src/sage/schemes/hyperelliptic_curves/jacobian_morphism.py
@@ -187,11 +187,11 @@ def cantor_reduction(a, b, f, h, genus):
     The next point is not 2-torsion::
 
         sage: P = J(H.lift_x(-1)); P
-        (x + 1, y - 1)
+        (x + 1, y)
         sage: 2 * J(H.lift_x(-1)) # indirect doctest
-        (x^2 + 2*x + 1, y - 3*x - 4)
+        (x^2 + 2*x + 1, y + 4*x + 4)
         sage: 3 * J(H.lift_x(-1)) # indirect doctest
-        (x^2 - 487*x - 324, y - 10754*x - 7146)
+        (x^2 - 487*x - 324, y + 10755*x + 7146)
     """
     assert a.degree() < 2*genus+1
     assert b.degree() < a.degree()
@@ -239,15 +239,15 @@ def cantor_composition_simple(D1,D2,f,genus):
 
         sage: # needs sage.rings.number_field
         sage: P = J(H.lift_x(F(1))); P
-        (x - 1, y - a)
+        (x - 1, y + a)
         sage: Q = J(H.lift_x(F(0))); Q
         (x, y)
         sage: 2*P + 2*Q # indirect doctest
-        (x^2 - 2*x + 1, y - 3/2*a*x + 1/2*a)
+        (x^2 - 2*x + 1, y + 3/2*a*x - 1/2*a)
         sage: 2*(P + Q) # indirect doctest
-        (x^2 - 2*x + 1, y - 3/2*a*x + 1/2*a)
+        (x^2 - 2*x + 1, y + 3/2*a*x - 1/2*a)
         sage: 3*P # indirect doctest
-        (x^2 - 25/32*x + 49/32, y - 45/256*a*x - 315/256*a)
+        (x^2 - 25/32*x + 49/32, y + 45/256*a*x + 315/256*a)
     """
     a1, b1 = D1
     a2, b2 = D2
@@ -286,17 +286,16 @@ def cantor_composition(D1,D2,f,h,genus):
     ::
 
         sage: Q = J(H.lift_x(F(1))); Q                                                  # needs sage.rings.finite_rings
-        (x + 6, y + 2*a + 2)
+        (x + 6, y + 5*a)
         sage: 10*Q  # indirect doctest                                                  # needs sage.rings.finite_rings
-        (x^3 + (3*a + 1)*x^2 + (2*a + 5)*x + a + 5,
-         y + (4*a + 5)*x^2 + (a + 1)*x + 6*a + 3)
+        (x^3 + (3*a + 1)*x^2 + (2*a + 5)*x + a + 5, y + (3*a + 2)*x^2 + (6*a + 1)*x + a + 4)
         sage: 7*8297*Q                                                                  # needs sage.rings.finite_rings
         (1)
 
     ::
 
         sage: Q = J(H.lift_x(F(a+1))); Q                                                # needs sage.rings.finite_rings
-        (x + 6*a + 6, y + 2*a)
+        (x + 6*a + 6, y + 2)
         sage: 7*8297*Q  # indirect doctest                                              # needs sage.rings.finite_rings
         (1)
 
@@ -421,7 +420,7 @@ def _printing_polys(self):
         ::
 
             sage: Q = J(H.lift_x(F(1))); Q  # indirect doctest                          # needs sage.rings.finite_rings
-            (x + 6, y + 2*a + 2)
+            (x + 6, y + 5*a)
         """
         a, b = self.__polys
         P = self.parent()._printing_ring
@@ -447,9 +446,9 @@ def _repr_(self):
             sage: Q = J(0); Q  # indirect doctest                                       # needs sage.rings.finite_rings
             (1)
             sage: Q = J(H.lift_x(F(1))); Q  # indirect doctest                          # needs sage.rings.finite_rings
-            (x + 6, y + 2*a + 2)
+            (x + 6, y + 5*a)
             sage: Q + Q  # indirect doctest                                             # needs sage.rings.finite_rings
-            (x^2 + 5*x + 1, y + 3*a*x + 6*a + 2)
+            (x^2 + 5*x + 1, y + (4*a + 2)*x + a + 5)
         """
         if self.is_zero():
             return "(1)"
@@ -474,12 +473,12 @@ def _latex_(self):
             sage: Q = J(0); print(latex(Q))  # indirect doctest                         # needs sage.rings.finite_rings
             \left(1\right)
             sage: Q = J(H.lift_x(F(1))); print(latex(Q))  # indirect doctest            # needs sage.rings.finite_rings
-            \left(x + 6, y + 2 \alpha + 2\right)
+            \left(x + 6, y + 5 \alpha\right)
 
         ::
 
             sage: print(latex(Q + Q))                                                   # needs sage.rings.finite_rings
-            \left(x^{2} + 5 x + 1, y + 3 \alpha x + 6 \alpha + 2\right)
+            \left(x^{2} + 5 x + 1, y + \left(4 \alpha + 2\right) x + \alpha + 5\right)
         """
         if self.is_zero():
             return "\\left(1\\right)"
@@ -537,7 +536,7 @@ def __list__(self):
 
             sage: P = J(H.lift_x(F(1)))                                                 # needs sage.rings.number_field
             sage: list(P)  # indirect doctest                                           # needs sage.rings.number_field
-            [x - 1, a]
+            [x - 1, -a]
         """
         return list(self.__polys)
 
@@ -561,7 +560,7 @@ def __tuple__(self):
 
             sage: P = J(H.lift_x(F(1)))                                                 # needs sage.rings.number_field
             sage: tuple(P)  # indirect doctest                                          # needs sage.rings.number_field
-            (x - 1, a)
+            (x - 1, -a)
         """
         return tuple(self.__polys)
 
@@ -588,9 +587,9 @@ def __getitem__(self, n):
             sage: P[0] # indirect doctest
             x - 1
             sage: P[1] # indirect doctest
-            a
+            -a
             sage: P[-1] # indirect doctest
-            a
+            -a
             sage: P[:1] # indirect doctest
             [x - 1]
         """
@@ -696,9 +695,9 @@ def __neg__(self):
             sage: H2 = HyperellipticCurve(x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x, x)
             sage: J2 = H2.jacobian()(GF(37))
             sage: P2 = J2(H2.lift_x(2)); P2
-            (x + 35, y + 15)
-            sage: - P2  # indirect doctest
             (x + 35, y + 24)
+            sage: - P2  # indirect doctest
+            (x + 35, y + 15)
             sage: P2 + (-P2)  # indirect doctest
             (1)
 


Test patch: