本文整理匯總了Python中polynomial.Polynomial.coef方法的典型用法代碼示例。如果您正苦於以下問題:Python Polynomial.coef方法的具體用法?Python Polynomial.coef怎麽用?Python Polynomial.coef使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類polynomial.Polynomial
的用法示例。
在下文中一共展示了Polynomial.coef方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_ntt_mul
# 需要導入模塊: from polynomial import Polynomial [as 別名]
# 或者: from polynomial.Polynomial import coef [as 別名]
def test_ntt_mul():
global w,wInv
print "test_ntt_mul"
powers2 = [pow(2,i) for i in range(1,19)]
for N in powers2:
print N
k = (P-1)/(2*N)
assert (P-1)%(2*N) == 0
wN = pow(7,k,P)
assert pow(wN,(2*N),P) == 1
w = []
for j in range(2*N):
w.append(pow(wN,j,P))
wInv = []
for j in range(2*N):
wInv.append(pow(w[j],P-2,P))
a = [randint(0,2**16) for _ in xrange(N)]+[0]*N
b = [randint(0,2**16) for _ in xrange(N)]+[0]*N
polynomial_a = Polynomial()
polynomial_a.coef = a
polynomial_b = Polynomial()
polynomial_b.coef = b
polynomial_c = polynomial_a*polynomial_b
my_ntt_a = CPU_NTT(a)
my_ntt_b = CPU_NTT(b)
my_ntt_c = [x[0]*x[1] % P for x in zip(my_ntt_a,my_ntt_b)]
ntt_intt_c = CPU_INTT(my_ntt_c)
# assert len(ntt_intt_c) == len(polynomial_c.coef)
for i,v in enumerate(polynomial_c.coef):
v2 = ntt_intt_c[i]/(2*N)
assert v == v2
print "We are good"