# why this algorithm does not work?

Hello I'm trying to write this algorithm in sage:

def roots(f, q):
# return list of roots of f in finite field of q elements
K.<T> = GF(q)
r = [ ]
g = qq2zz(f).change_ring(K)
for a in K:
if g(a) == 0:
r.append(a)
return r


but i get error, it says that:

Traceback (click to the left of this block for traceback ) ....


how should I correct it?

edit retag close merge delete

Sort by » oldest newest most voted

What is interesting is the line that comes after the message

Traceback (click to the left of this block for traceback)


You are using the notebook, to see more information about the error, just click on the left side of the word Traceback, and then you will get more details.

In your case, it seems that the function qq2zz() does not exist (maybe you defined it before, at least it does not exist in sage).

more

The problem is change_ring(). You must give the new ring of the coefficients instead of the new ring of f. The code below works.

def roots(f, q): # return list of roots of f in finite field of q elements K = GF(q) r = [ ] g = f.change_ring(K) for a in K: if g(a) == 0: r.append(a) return r

"""EXAMPLE R.<x>=QQ['x'] roots(2*x+1,7) """

more