0

我有一个 4x4 的多项式 sympy 矩阵:

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 = (S.det()).set_domain(GF(self.q))

调试器输出:

 File "/home/gamergod77/work/Staircase codes/Product Codes/bchcoder.py", line 52, in decode
    S_det = (S.det()).set_domain(GF(self.q))

  File "/home/gamergod77/.local/lib/python3.8/site-packages/sympy/matrices/matrices.py", line 123, in det
    return _det(self, method=method, iszerofunc=iszerofunc)

  File "/home/gamergod77/.local/lib/python3.8/site-packages/sympy/matrices/determinant.py", line 596, in _det
    return M._eval_det_bareiss(iszerofunc=iszerofunc)

  File "/home/gamergod77/.local/lib/python3.8/site-packages/sympy/matrices/matrices.py", line 99, in _eval_det_bareiss
    return _det_bareiss(self, iszerofunc=iszerofunc)

  File "/home/gamergod77/.local/lib/python3.8/site-packages/sympy/matrices/determinant.py", line 669, in _det_bareiss
    return bareiss(M)

  File "/home/gamergod77/.local/lib/python3.8/site-packages/sympy/matrices/determinant.py", line 637, in bareiss
    pivot_pos, pivot_val, _, _ = _find_reasonable_pivot(mat[:, 0], iszerofunc=iszerofunc)

  File "/home/gamergod77/.local/lib/python3.8/site-packages/sympy/matrices/determinant.py", line 56, in _find_reasonable_pivot
    is_zero = iszerofunc(x)

  File "/home/gamergod77/.local/lib/python3.8/site-packages/sympy/matrices/utilities.py", line 84, in _is_zero_after_expand_mul
    return expand_mul(x) == 0

  File "/home/gamergod77/.local/lib/python3.8/site-packages/sympy/core/function.py", line 2799, in expand_mul
    return sympify(expr).expand(deep=deep, mul=True, power_exp=False,

AttributeError: 'Poly' object has no attribute 'expand'

值得注意的是,像

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

具有相同的S通过非常好

4

1 回答 1

0

您应该Expr在矩阵中使用,或者应该使用PolyMatrix。看起来 usingExpr最适合您的示例:

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)

于 2020-06-01T16:17:02.143 回答