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.Mon, 14 Sep 2020 11:50:56 +0200How to implement Hensel's Lemma recursion?https://ask.sagemath.org/question/53447/how-to-implement-hensels-lemma-recursion/ I am trying to automate a Hensellian lift calculation.
S.u> = PolynomialRing(GF(5))
L.<x> = PolynomialRing(S)
f = x^5 + u*x^2 - u*x
a0 = 2
k = 50
for n in range (0, k):
**a(n+1) = f(an).truncate(n+1)**
Name = "a" + str(k)
print eval(Name)
In particular, I am stuck on implementing the ** step in a for-loop, or plugging a function into itself, as eval doesn't work to type change from string to integer when you are using it to define a variable. Does anyone know how to get around this or have a suggestion?
I tried to instead use a seperate function, but the same issue arises.
def henselstep(step, input):
return (step+1, f(input).truncate(n+1))
for n in range (0, 2):
astr = "a" + str(n)
avar = eval(astr)
henselstep(n, avar)
henselstep(henselstep(n, avar)) ???
But again, it isn't quite right, ack! I don't know how to handle the recursion and I'm banging my head on the wall, it must be simple but I keep getting it slightly wrong. Thank you very much for your time.
Mon, 14 Sep 2020 03:46:36 +0200https://ask.sagemath.org/question/53447/how-to-implement-hensels-lemma-recursion/Comment by FrédéricC for <p>I am trying to automate a Hensellian lift calculation.</p>
<pre><code>S.u> = PolynomialRing(GF(5))
L.<x> = PolynomialRing(S)
f = x^5 + u*x^2 - u*x
a0 = 2
k = 50
for n in range (0, k):
**a(n+1) = f(an).truncate(n+1)**
Name = "a" + str(k)
print eval(Name)
</code></pre>
<p>In particular, I am stuck on implementing the ** step in a for-loop, or plugging a function into itself, as eval doesn't work to type change from string to integer when you are using it to define a variable. Does anyone know how to get around this or have a suggestion? </p>
<p>I tried to instead use a seperate function, but the same issue arises. </p>
<pre><code>def henselstep(step, input):
return (step+1, f(input).truncate(n+1))
for n in range (0, 2):
astr = "a" + str(n)
avar = eval(astr)
henselstep(n, avar)
henselstep(henselstep(n, avar)) ???
</code></pre>
<p>But again, it isn't quite right, ack! I don't know how to handle the recursion and I'm banging my head on the wall, it must be simple but I keep getting it slightly wrong. Thank you very much for your time.</p>
https://ask.sagemath.org/question/53447/how-to-implement-hensels-lemma-recursion/?comment=53452#post-id-53452use a dictionaryMon, 14 Sep 2020 09:33:33 +0200https://ask.sagemath.org/question/53447/how-to-implement-hensels-lemma-recursion/?comment=53452#post-id-53452Answer by FrédéricC for <p>I am trying to automate a Hensellian lift calculation.</p>
<pre><code>S.u> = PolynomialRing(GF(5))
L.<x> = PolynomialRing(S)
f = x^5 + u*x^2 - u*x
a0 = 2
k = 50
for n in range (0, k):
**a(n+1) = f(an).truncate(n+1)**
Name = "a" + str(k)
print eval(Name)
</code></pre>
<p>In particular, I am stuck on implementing the ** step in a for-loop, or plugging a function into itself, as eval doesn't work to type change from string to integer when you are using it to define a variable. Does anyone know how to get around this or have a suggestion? </p>
<p>I tried to instead use a seperate function, but the same issue arises. </p>
<pre><code>def henselstep(step, input):
return (step+1, f(input).truncate(n+1))
for n in range (0, 2):
astr = "a" + str(n)
avar = eval(astr)
henselstep(n, avar)
henselstep(henselstep(n, avar)) ???
</code></pre>
<p>But again, it isn't quite right, ack! I don't know how to handle the recursion and I'm banging my head on the wall, it must be simple but I keep getting it slightly wrong. Thank you very much for your time.</p>
https://ask.sagemath.org/question/53447/how-to-implement-hensels-lemma-recursion/?answer=53454#post-id-53454To expand on my comment:
S.u> = PolynomialRing(GF(5))
L.<x> = PolynomialRing(S)
f = x^5 + u*x^2 - u*x
a = {}
a[0] = 2
k = 50
for n in range(k):
a[n+1] = f(a[n]).truncate(n+1)
a[49]Mon, 14 Sep 2020 11:50:56 +0200https://ask.sagemath.org/question/53447/how-to-implement-hensels-lemma-recursion/?answer=53454#post-id-53454