New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ideal membership testing raises ValueError
#26572
Comments
I guess it just needs a special case for zero as a generator. Maybe zeros should be removed at instantiation. |
I think you're right that removing zero generators would relieve the symptom, but it's not obvious without deep knowledge of the codebase—which I lack!—that it would solve the problem robustly. For example, is it definitely the case that an ideal generated by x and x will never be transformed into one generated by x and x - x = 0? It seems plausible to me that a safer, root-cause fix could be to ensure that |
The ideal is an immutable object that represents the mathematical ideal. I don't think it ever gets transformed into anything else but we could simplify it at creation time using various basic identities:
More generally the ideal for the Groebner basis should be the same as the ideal for the original generating set: In [1]: groebner([x, 0], [x])
Out[1]: GroebnerBasis([x], x, domain=ℤ, order=lex)
In [2]: groebner([0], [x])
Out[2]: GroebnerBasis([], x, domain=ℤ, order=lex) Computing a Groebner basis can be expensive though so probably should not be done automatically. Maybe in general it is better just to the ideal be as defined by the user without any canonicalisation though.
Yes, that's what I meant by a special case for zero as a generator. Feel free to submit a pull request with that as a fix. |
sympy/sympy/polys/distributedmodules.py Line 332 in 999fd9b
The documentation of However, if the function should raise errors at zero, it may be reasonable to fix it from the preconditions where the function is used. It is reasonable to check the loop of |
For even basic things like |
An exception can be raised by testing membership of an element contained in a ring ideal, perhaps due to a bug in the Groebner basis algorithms.
The following minimal working example exercises the bug in Sympy
1.12
:The final line should evaluate to
true
, but instead raises an exception, with a stack trace ending in:Curiously, the error does not occur if the ideal is replaced with any of
R.ideal(0)
,R.ideal(x)
,R.ideal(0, 0)
orR.ideal(x, x)
, and the correct result is obtained in all of these cases.The text was updated successfully, but these errors were encountered: