Ask Your Question
0

why this algorithm does not work?

asked 11 years ago

Neda gravatar image

updated 11 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
3

answered 11 years ago

tmonteil gravatar image

updated 11 years ago

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

Preview: (hide)
link
1

answered 11 years ago

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

Preview: (hide)
link

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: 11 years ago

Seen: 732 times

Last updated: Jun 17 '13