Ask Your Question
0

why this algorithm does not work?

asked 2013-06-13 09:28:39 -0500

Neda gravatar image

updated 2013-06-13 10:00:21 -0500

tmonteil gravatar image

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2013-06-13 10:00:10 -0500

tmonteil gravatar image

updated 2013-06-13 10:02:30 -0500

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).

edit flag offensive delete link more
1

answered 2013-06-17 05:18:48 -0500

barbules gravatar image

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) """

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-06-13 09:28:39 -0500

Seen: 68 times

Last updated: Jun 17 '13