收集系数MPolynomial_libsingular

时间:2014-08-21 14:15:15

标签: python sage

我希望将p中的多项式GF(2^n)[X0, ..., X{N-1}]的符号系数转换为GF(2)[t]

例如,对于n = 2p = X0*X1 = (x_00+x_01*t)*(x_10+x_11*t) = (x_00*x_10+x_01*x_11) + (x_01*x_11+x_01*x_10 + x_00*x_11)*t,该方法应该为[(x_00*x_10 + x_01*x_11), (x_01*x_11 + x_01*x_10 + x_00*x_11)]

在下面的代码中,我的问题是我想要收集t的系数。如何以有效的方式收集这些系数

sage: q = 2
sage: N = 2
sage: k.<t> = GF(2^q)
sage: Xi = []
sage: xij = []
sage: for i in range(N):
....:     Xi.append(var('X' + str(i)))
....:     for j in range(q):
....:         xij.append(var('x' + str(i) + '' + str(j)))
sage: Xi.append(t)
sage: P = PolynomialRing(k, names=Xi)
sage: R = PolynomialRing(k, names=xij)
sage: S = PolynomialRing(R, 't')
sage: p = P.random_element(degree=2)
sage: subsvar = [sum((t^i*R.gen(i+q*j) for i in range(q))) for j in range(N)]
sage: subsvar.append(t)
sage: p =  p(subsvar)
sage: p
(t + 1)*x00*x10 + x01*x10 + x00*x11 + (t)*x01*x11 + (t)*x10 + (t + 1)*x11 + (t + 1)

1 个答案:

答案 0 :(得分:1)

这是一种方法。作为参考,我使用的是Sage 6.3。

设置,用下划线来区分 例如x1_11x11_1,对于较大的q和nvars。

q = 2
nvars = 2
k.<t> = GF(2^q)
Xi = []
xij = []
for i in range(nvars):
    Xi.append(var('X'+str(i)))
    for j in range(q):
        xij.append(var('x'+str(i)+'_'+str(j)))
P = PolynomialRing(k,names=Xi)
R = PolynomialRing(k,names=xij)
S = PolynomialRing(R,'t')
subsvar = [sum((t^i*R.gen(i+q*j) for i in range(q))) for j in range(nvars)]

将多项式从环P转换为多项式 在t中,系数为R

p = P('X0*X1')
pp = sum(b*S(a.polynomial()) for (a,b) in p(subsvar))
pp

输出自然地以t的力量收集。

(x0_1*x1_0 + x0_0*x1_1 + x0_1*x1_1)*t + x0_0*x1_0 + x0_1*x1_1

时间示例X0*X1

sage: timeit('pp = sum(b*S(a.polynomial()) for (a,b) in p(subsvar))')
625 loops, best of 3: 469 µs per loop