ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 07 Oct 2023 00:12:38 +0200How to use lift_x in python?https://ask.sagemath.org/question/73521/how-to-use-lift_x-in-python/I am trying to use sage library in python3, but I have the following problem when I try to find points with given x-coordinate:
>>> from sage.all import *
>>> E = EllipticCurve('37a'); E
Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
>>> E.lift_x(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/sage/schemes/elliptic_curves/ell_generic.py", line 847, in lift_x
L = x.parent()
^^^^^^^^
AttributeError: 'int' object has no attribute 'parent'Wed, 20 Sep 2023 23:20:01 +0200https://ask.sagemath.org/question/73521/how-to-use-lift_x-in-python/Comment by podprostor for <p>I am trying to use sage library in python3, but I have the following problem when I try to find points with given x-coordinate:</p>
<pre><code>>>> from sage.all import *
>>> E = EllipticCurve('37a'); E
Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
>>> E.lift_x(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/sage/schemes/elliptic_curves/ell_generic.py", line 847, in lift_x
L = x.parent()
^^^^^^^^
AttributeError: 'int' object has no attribute 'parent'
</code></pre>
https://ask.sagemath.org/question/73521/how-to-use-lift_x-in-python/?comment=73533#post-id-73533Thank you. I know that Sage uses `Integer`s, but I thought it must be something else.Thu, 21 Sep 2023 16:22:35 +0200https://ask.sagemath.org/question/73521/how-to-use-lift_x-in-python/?comment=73533#post-id-73533Comment by John Palmieri for <p>I am trying to use sage library in python3, but I have the following problem when I try to find points with given x-coordinate:</p>
<pre><code>>>> from sage.all import *
>>> E = EllipticCurve('37a'); E
Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
>>> E.lift_x(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/sage/schemes/elliptic_curves/ell_generic.py", line 847, in lift_x
L = x.parent()
^^^^^^^^
AttributeError: 'int' object has no attribute 'parent'
</code></pre>
https://ask.sagemath.org/question/73521/how-to-use-lift_x-in-python/?comment=73524#post-id-73524Try `E.lift_x(Integer(1))`. The Sage type `Integer` is more fully-functioned than the Python type `int`.Thu, 21 Sep 2023 03:34:44 +0200https://ask.sagemath.org/question/73521/how-to-use-lift_x-in-python/?comment=73524#post-id-73524Answer by dan_fulea for <p>I am trying to use sage library in python3, but I have the following problem when I try to find points with given x-coordinate:</p>
<pre><code>>>> from sage.all import *
>>> E = EllipticCurve('37a'); E
Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
>>> E.lift_x(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/sage/schemes/elliptic_curves/ell_generic.py", line 847, in lift_x
L = x.parent()
^^^^^^^^
AttributeError: 'int' object has no attribute 'parent'
</code></pre>
https://ask.sagemath.org/question/73521/how-to-use-lift_x-in-python/?answer=73795#post-id-73795This is the same answer, with one more touch about how to work around in the given and in similar situations. I am using the interpreter, and for some comfort let it be the `ipython` code eating machine.
[dan@k9 ~]$ ipython
Python 3.11.5 (main, Sep 2 2023, 14:16:33) [GCC 13.2.1 20230801]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.16.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from sage.all import *
In [2]: E = EllipticCurve('37a')
In [3]: E
Out[3]: Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
In [4]: E.lift_x?
The last question mark asks for the doc string of the method. And here it comes:
Signature: E.lift_x(x, all=False, extend=False)
Docstring:
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, or of an extension.
- ``all`` (bool, default False) -- if True, return a (possibly
empty) list of all points; if False, return just one point,
or raise a ValueError if there are none.
- ``extend`` (bool, default False) --
- if ``False``, extend the base if necessary and possible to
include `x`, and only return point(s) defined over this
ring, or raise an error when there are none with this
`x`-coordinate;
- If ``True``, the base ring will be extended if necessary
to contain the `y`-coordinates of the point(s) with this
`x`-coordinate, in addition to a possible base change to
include `x`.
OUTPUT:
... and so on. For us, the parameter `x` is the interesting one. And it must be an element of the base ring of the curve, of of an extension of the curve. So if we want to lift the integer one, we make an element of the base field of the curve from it.
In [6]: E.lift_x( QQ(1) )
Out[6]: (1 : -1 : 1)
In [7]: E.lift_x( QQ(1), all=True )
Out[7]: [(1 : -1 : 1), (1 : 0 : 1)]
Sat, 07 Oct 2023 00:12:38 +0200https://ask.sagemath.org/question/73521/how-to-use-lift_x-in-python/?answer=73795#post-id-73795Answer by podprostor for <p>I am trying to use sage library in python3, but I have the following problem when I try to find points with given x-coordinate:</p>
<pre><code>>>> from sage.all import *
>>> E = EllipticCurve('37a'); E
Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
>>> E.lift_x(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/sage/schemes/elliptic_curves/ell_generic.py", line 847, in lift_x
L = x.parent()
^^^^^^^^
AttributeError: 'int' object has no attribute 'parent'
</code></pre>
https://ask.sagemath.org/question/73521/how-to-use-lift_x-in-python/?answer=73534#post-id-73534**Solutions:**
1. As John Plameri pointed out, you can
to use `Integer(1)` instead of `1`.
2. I could also have done something like: `E.lift_x(E.base_field()(1))` or `E.lift_x(QQ(1))`
<pre>
>>> from sage.all import EllipticCurve, QQ, Integer
>>> E = EllipticCurve('37a'); E
Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
>>> E.lift_x(Integer(1))
(1 : 0 : 1)
>>> E.lift_x(E.base_field()(1))
(1 : 0 : 1)
>>> E.lift_x(QQ(1))
(1 : 0 : 1)
</pre>Thu, 21 Sep 2023 16:34:54 +0200https://ask.sagemath.org/question/73521/how-to-use-lift_x-in-python/?answer=73534#post-id-73534