Incorrect behaviour for solve_poly_system
mohammedehab2002 opened this issue · comments
from sympy import symbols,sympify,groebner
from sympy.solvers.polysys import solve_poly_system
s=symbols("s")
c=symbols("c")
eqns=[c**2 + s**2 - 1, -1.98079646822393*c - 0.887785747630113*s - 0.15634896910398]
print(solve_poly_system(eqns,s,c))
This code raises NotImplementedError: only zero-dimensional systems supported (finite number of solutions), but the system is indeed zero-dimensional. Furthermore, if the order of the generators is changed to c,s instead, the code works as expected.
I've been generally running into a lot of trouble with this function claiming the system is not zero-dimensional or returning no solutions when there are solutions for systems generated by intersecting a circle with a random affine line like the one above.
As a workaround you can use solve_poly_system(eqns,s,c,domain=QQ)
Somehow the Groebner basis comes out as
In [14]: groebner(eqns)
Out[14]:
⎛⎡ 2 ⎤ ⎞
GroebnerBasis⎝⎣2.23116497816229⋅c + 1.0⋅s + 0.176111150152324, 1.0⋅c + 0.131457559146912⋅c - 0.162089179364897, 1.0⎦, s, c, domain=ℝ, order=lex⎠
In [15]: groebner(eqns)[-1]
Out[15]: 1.00000000000000
That shouldn't happen because if 1 is in the Groebner basis then it should be the whole basis.
The problem is here:
sympy/sympy/polys/groebnertools.py
Lines 103 to 107 in 73ae5e9
We get a small
h
that should be zero but is not quite zero because of floating point rounding error:
103 def normal(g, J):
104 h = g.rem([ f[j] for j in J ])
105 breakpoint()
106
107 -> if not h:
108 return None
109 else:
110 h = h.monic()
111
112 if h not in I:
(Pdb) p h
-1.11022302462516e-16
Possibly the algorithms used for groebner
cannot handle inexact arithmetic and so inexact domains should be converted to exact ones.
Using solve_poly_system(eqns,s,c,domain=QQ) seems slow because of all the rational computations, and I need to solve many of these systems. Any work around for that?
Using solve_poly_system(eqns,s,c,domain=QQ) seems slow because of all the rational computations
The algorithm needs to use exact calculations to work properly. Please open a separate issue about slowness and give an example of a case that is slow.