Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

How to translate a 2007 sympy/sage/python code to a modern day sympy/python code?

Me struggling with the General Number Field Sieve : round 2 ! As usual : english is not my first langage so 'sorry for bad english'. So : I'm trying to implement this algorithm and to do it I'm heavily relying on sympy. But I'm also basing parts of my work on the code of Pr. William Stein (https://wstein.org/misc/aly-lll/gnfs.html), written in python/sympy/sage in 2007.

In it, there is this peice of code (which, of course, happens to be one of the most important) :

def find_kernel_vectors(M):
    return M.kernel().basis_matrix().rows()    [1]

It will be applied the matrix :

M = Matrix(GF(2), len(sel), ev)    [2]

where sel is a list and ev the coefficients of the matrix, which are each either 0 or 1.

However, when I copy-paste it, adding from sympy import Matrix, GF, I run in quite a lot of troubles.

Upon execution of [2], I get the error message GF(2) is not an integer I looked up how to use matrices in sympy and from what I gathered, only the list of coefficients in an acceptable input.

So I decided to define M as follows in order to be able to test [1] :

M = Matrix(ev)

And upon execution of 1, I get the error message MutableDenseMatrix has no attribute kernel

The thing is, it's not the first time that things like this happen, because Pr. Stein was coding in a 2007 version of python/sympy/sage.

I don't really think that the issue with [2] is an actual issue because, as I said, the coefficients of my matrix are already 0 or 1 (i.e. elements of GF(2)), however I'm not sure about it. But I'm sure about the fact that [1] is a big issue that I don't have any idea to solve.

I beleive it all boils down to the translation between 2007 sage/sympy/python to modern day python, so if someone knows how to do it, it would save my code.

Thanks a lot !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...