我想 从 Python调用PARI/GPnfroots({nf}; x)
的函数。(请参阅此链接中第 371 页的函数号 3.13.135.on :),但问题是,我无法发送需要发送的代数表达式或多项式,例如,这是一个非常简单的示例四次多项式可以做什么:x^2-7x+12
gp
> V = readvec("coeff.txt");
> print(V)
[1,-7,12]
> P = Pol(V); # I get following error when I use Pol in my code: func=self._FuncPtr((name_or_ordinal, self)) AttributeError: function 'pol' not found
> print(P)
x^2 -7*x +12
> print(nfroots(,P))
>4, 3
从斯蒂芬施莱赫特的回答(点击这里),我设法写 -
from ctypes import *
pari = cdll.LoadLibrary("C:\\Program Files\\Pari64-2-11-3\\libpari.dll")
pari.stoi.restype = POINTER(c_long)
pari.cgetg.restype = POINTER(POINTER(c_long))
pari.nfroots.restype = POINTER(POINTER(c_long))
pari.pari_init(2 ** 19, 0)
def t_vec(numbers):
l = len(numbers) + 1
p1 = pari.cgetg(c_long(l), c_long(10)) #t_POL = 10,
for i in range(1, l):
p1[i] = pari.stoi(c_long(numbers[i - 1]))
return p1
def main():
h = "x^2-7x+12"
res = pari.nfroots(t_vec(h))
for i in range(1, len(res)):
print(pari.itos(res[i]))
if __name__ == '__main__':
main()
请注意,创建 PARI 对象有特定的过程(参见Stephan Schlecht的答案),我更改了 的值t_POL = 10
,但代码不起作用,如何从 python 执行上述 PARI/GP 代码?