I hit the following error using sympy.groebner: “sympy.polys.polyerrors.PolynomialError: non-commutative expressions are not supported”.
In the real case, I have a very diffcult expression which is not easy to reduce. The beginning of the polynom p
to reduce is
And I get (where compute_vtmv_product
compute a polynomial p
that should be reduced using Groebner basis)
I tried to reduce the problem (the same way the variables are created / used in the real example) but the problem seems to disappear
In the real case, variables are mixed, so I tried adding a/b/c variables mixed with x/y/z variables but I get
Does somebody have any clue on the cause of these problems?
UPDATE
p
is a polynomial which real coefs (not integer nor rational).
Any clue on how to fix / find or transform this problem to something what could work would be great!
2
You are using an older version of SymPy but with the latest version 1.13.1 you would see a different error here:
CoercionFailed: expected an integer, got a
The reason is that the Groebner
reduce method expects that the expression to be reduced should be a polynomial with the same generators and domain as is used for the Groebner basis. There are two ways to do this:
- Add the symbols a, b and c as variables to the basis.
- Compute a basis over a domain that includes the symbols a, b and c
In [21]: x, y, z = symbols('x, y, z')
In [22]: a, b, c = symbols('a, b, c')
In [23]: groebner([x, y, z])
Out[23]: GroebnerBasis([x, y, z], x, y, z, domain=ℤ, order=lex)
In [24]: groebner([x, y, z], [x, y, z, a, b, c])
Out[24]: GroebnerBasis([x, y, z], x, y, z, a, b, c, domain=ℤ, order=lex)
In [25]: groebner([x, y, z], domain=QQ[a, b, c])
Out[25]: GroebnerBasis([x, y, z], x, y, z, domain=ℚ[a, b, c], order=lex)
In [26]: G = groebner([x, y, z], domain=QQ[a, b, c])
In [27]: p = a*x + b*y + c*z
In [28]: G.reduce(p)
Out[28]: ([a, b, c], 0)
2