ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 09 Dec 2013 22:24:48 -0600Problem with the lift_x fuction in SAGEhttp://ask.sagemath.org/question/9083/problem-with-the-lift_x-fuction-in-sage/Hello,
When I work with an elliptic curve and i apply E.lift_x(1407284663933896236729058440000)
i obtain the point (1407284663933896236729058440000 : 4215171991512676773155222850458328 : 1) and works fine.
My problem is when i have a value of x that don't in the curve and aplly E.lift_x(x) and it's generate a **Raise of Error** and stop my program. Well, i have to increment the value of x end try to another point E.lift_x(x+1) and works fine but the problem is that i can't reach that because **Raise of Error** stop my loop.
How can i debug that? Another fuction like lift_x?
Thank very much. I wait yor answers.
Sat, 16 Jun 2012 10:59:54 -0500http://ask.sagemath.org/question/9083/problem-with-the-lift_x-fuction-in-sage/Answer by DSM for <p>Hello,</p>
<p>When I work with an elliptic curve and i apply E.lift_x(1407284663933896236729058440000)
i obtain the point (1407284663933896236729058440000 : 4215171991512676773155222850458328 : 1) and works fine.</p>
<p>My problem is when i have a value of x that don't in the curve and aplly E.lift_x(x) and it's generate a <strong>Raise of Error</strong> and stop my program. Well, i have to increment the value of x end try to another point E.lift_x(x+1) and works fine but the problem is that i can't reach that because <strong>Raise of Error</strong> stop my loop.</p>
<p>How can i debug that? Another fuction like lift_x? </p>
<p>Thank very much. I wait yor answers. </p>
http://ask.sagemath.org/question/9083/problem-with-the-lift_x-fuction-in-sage/?answer=13716#post-id-13716Reading through a Python tutorial would be helpful, I think. You could catch the ValueError using a `try/except` pair:
p=(10^34+1000).next_prime()
E=EllipticCurve(GF(p),[0,57])
for i in range(10):
print i,
try:
print E.lift_x(i)
except ValueError:
print 'is not on the curve'
gives
0 is not on the curve
1 is not on the curve
2 is not on the curve
3 is not on the curve
4 (4 : 11 : 1)
5 is not on the curve
6 is not on the curve
7 (7 : 20 : 1)
8 (8 : 4398486930972910766515963067497788 : 1)
9 (9 : 1034823061610515416790842872226417 : 1)
If you simply want a random point on the curve and you don't care about it being the 'next' one, you can use `.random_element()`:
sage: E.random_element()
(9537865290021818371758914785117256 : 7089648854090040163853290659008613 : 1)
sage: E.random_element()
(8894960861306214748776439558874048 : 5076442993216186749708177737959875 : 1)
sage: E.random_element()
(713560432970815994889067437364213 : 4835570217047194554079202261200998 : 1)
Sat, 16 Jun 2012 11:09:52 -0500http://ask.sagemath.org/question/9083/problem-with-the-lift_x-fuction-in-sage/?answer=13716#post-id-13716Comment by vescapam for <p>Reading through a Python tutorial would be helpful, I think. You could catch the ValueError using a <code>try/except</code> pair:</p>
<pre><code>p=(10^34+1000).next_prime()
E=EllipticCurve(GF(p),[0,57])
for i in range(10):
print i,
try:
print E.lift_x(i)
except ValueError:
print 'is not on the curve'
</code></pre>
<p>gives</p>
<pre><code>0 is not on the curve
1 is not on the curve
2 is not on the curve
3 is not on the curve
4 (4 : 11 : 1)
5 is not on the curve
6 is not on the curve
7 (7 : 20 : 1)
8 (8 : 4398486930972910766515963067497788 : 1)
9 (9 : 1034823061610515416790842872226417 : 1)
</code></pre>
<p>If you simply want a random point on the curve and you don't care about it being the 'next' one, you can use <code>.random_element()</code>:</p>
<pre><code>sage: E.random_element()
(9537865290021818371758914785117256 : 7089648854090040163853290659008613 : 1)
sage: E.random_element()
(8894960861306214748776439558874048 : 5076442993216186749708177737959875 : 1)
sage: E.random_element()
(713560432970815994889067437364213 : 4835570217047194554079202261200998 : 1)
</code></pre>
http://ask.sagemath.org/question/9083/problem-with-the-lift_x-fuction-in-sage/?comment=19583#post-id-19583Thank you very much. Well explained. You are a genius. :)Sat, 16 Jun 2012 11:33:51 -0500http://ask.sagemath.org/question/9083/problem-with-the-lift_x-fuction-in-sage/?comment=19583#post-id-19583Answer by John Cremona for <p>Hello,</p>
<p>When I work with an elliptic curve and i apply E.lift_x(1407284663933896236729058440000)
i obtain the point (1407284663933896236729058440000 : 4215171991512676773155222850458328 : 1) and works fine.</p>
<p>My problem is when i have a value of x that don't in the curve and aplly E.lift_x(x) and it's generate a <strong>Raise of Error</strong> and stop my program. Well, i have to increment the value of x end try to another point E.lift_x(x+1) and works fine but the problem is that i can't reach that because <strong>Raise of Error</strong> stop my loop.</p>
<p>How can i debug that? Another fuction like lift_x? </p>
<p>Thank very much. I wait yor answers. </p>
http://ask.sagemath.org/question/9083/problem-with-the-lift_x-fuction-in-sage/?answer=15777#post-id-15777I think I wrote this function, and exactly for the reasons you are asking I allowed for two alternataives foms of output, controlled by the parameter "all" which defaults to False. For the documentation, as usual do this:
{{{
sage: E = EllipticCurve([0,0,0,0,1])
sage: E.lift_x?
}}}
I would use the default in situations where you know that x is a valid x-coordinate, otherwise use all=True, for example:
{{{
sage: [E.lift_x(x,all=True) for x in [-5..5]]
[[],
[],
[],
[],
[(-1 : 0 : 1)],
[(0 : 1 : 1), (0 : -1 : 1)],
[],
[(2 : 3 : 1), (2 : -3 : 1)],
[],
[],
[]]
}}}
Mon, 09 Dec 2013 22:24:48 -0600http://ask.sagemath.org/question/9083/problem-with-the-lift_x-fuction-in-sage/?answer=15777#post-id-15777