# 什么原因导致“ Poly对象没有属性'expand'”错误？

##### 问题描述投票：0回答：1

``````S = Matrix([[Poly(alpha**4 + alpha**3, alpha, modulus=2), Poly(alpha**4 + alpha**3 + alpha + 1, alpha, modulus=2),Poly(alpha**3 + alpha**2 + alpha, alpha, modulus=2), Poly(alpha**4 + alpha**3 + alpha**2 + alpha, alpha, modulus=2)],
[Poly(alpha**4 + alpha**3 + alpha + 1, alpha, modulus=2), Poly(alpha**3 + alpha**2 + alpha, alpha, modulus=2), Poly(alpha**4 + alpha**3 + alpha**2 + alpha, alpha, modulus=2),Poly(alpha**3 + alpha**2, alpha, modulus=2)],
[Poly(alpha**3 + alpha**2 + alpha, alpha, modulus=2), Poly(alpha**4 + alpha**3 + alpha**2 + alpha, alpha, modulus=2), Poly(alpha**3 + alpha**2, alpha, modulus=2), Poly(alpha**4 + alpha + 1, alpha, modulus=2)],
[Poly(alpha**4 + alpha**3 + alpha**2 + alpha, alpha, modulus=2), Poly(alpha**3 + alpha**2, alpha, modulus=2), Poly(alpha**4 + alpha + 1, alpha, modulus=2),Poly(alpha**2 + alpha + 1, alpha, modulus=2)]])
``````

``````S_det = (S.det()).set_domain(GF(self.q))
``````

## 调试器输出：

File“ /home/gamergod77/.local/lib/python3.8/site-packages/sympy/core/function.py”，第2799行，在expand_mul中返回sympify（expr）.expand（deep = deep，mul = True，power_exp = False，

## [AttributeError：'Poly'对象没有属性'expand'

``````S[:3, :3].det().set_domain(GF(2))
``````

python matrix sympy attributeerror poly
##### 1个回答
0

``````In [5]: S = S.applyfunc(lambda p: p.as_expr())

In [6]: S
Out[6]:
⎡     4    3        4    3              3    2          4    3    2    ⎤
⎢    α  + α        α  + α  + α + 1     α  + α  + α     α  + α  + α  + α⎥
⎢                                                                      ⎥
⎢ 4    3              3    2          4    3    2           3    2     ⎥
⎢α  + α  + α + 1     α  + α  + α     α  + α  + α  + α      α  + α      ⎥
⎢                                                                      ⎥
⎢   3    2          4    3    2           3    2           4           ⎥
⎢  α  + α  + α     α  + α  + α  + α      α  + α           α  + α + 1   ⎥
⎢                                                                      ⎥
⎢ 4    3    2           3    2           4                 2           ⎥
⎣α  + α  + α  + α      α  + α           α  + α + 1        α  + α + 1   ⎦

In [7]: S.det()
Out[7]:
15      14      13      12      11      10      9      8    7      5      4    3      2
α   + 3⋅α   + 4⋅α   + 4⋅α   - 2⋅α   - 3⋅α   + 6⋅α  + 9⋅α  + α  + 5⋅α  + 2⋅α  + α  + 5⋅α  + 4⋅α + 1

In [8]: d = S.det()

In [9]: d
Out[9]:
15      14      13      12      11      10      9      8    7      5      4    3      2
α   + 3⋅α   + 4⋅α   + 4⋅α   - 2⋅α   - 3⋅α   + 6⋅α  + 9⋅α  + α  + 5⋅α  + 2⋅α  + α  + 5⋅α  + 4⋅α + 1

In [10]: Poly(d, alpha).set_domain(GF(2))
Out[10]: Poly(alpha**15 + alpha**14 + alpha**10 + alpha**8 + alpha**7 + alpha**5 + alpha**3 + alpha**2 + 1, alpha, modulus=2)

``````