-
-
Notifications
You must be signed in to change notification settings - Fork 487
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
Bandaid for polynomial evaluation #36127
Bandaid for polynomial evaluation #36127
Conversation
Given that you call this a bandaid, it looks like we agree that the actual bug is that partial evaluations of multivariate polynomials sometimes land in the wrong parent. I don't mind working around this issue as you did, but I think it would be good to add a comment or two to explain what you are doing. |
|
||
# Evaluate the coefficients, then fall through to evaluate the | ||
# resulting univariate polynomial | ||
|
||
if eval_coeffs: | ||
new_base = parent(top) | ||
# this value for the common parent of the evaluated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you mean here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I am not 100% sure what the code is doing exactly. It seem to try to guess a new base ring, depending not only on the existing base ring, but on the substituted coefficients. But it does that by looking only at the substitution in one of the coefficients. Before my changes, it was looking at the substitution in the constant term, and fails if this was zero. I changed it to use the substitution of the leading term. This works a little better.
Of course, the only thing making complete sense would be to look at the common parent of all substituted coeffs. But this may have a large speed penalty..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it does that by looking only at the substitution in one of the coefficients.
Yes, but for this whole business (of evaluating the coefficients of a polynomial and getting a new polynomial) to make sense, evaluation (of the coefficients) should be a ring morphism, so it should be enough to look at the evaluation of one coefficient, or in fact of any element of the base ring.
So as I said in the other comment, I think it is okay to work around the fact that some of the base rings we may want to work with have an evaluation function that does not respect this constraint. However, I'm still not sure what you mean by “this value [...] only works for monomials”.
There may be a tension between landing in the "minimal parent" or the "best uniform parent". If you substitute into 0 in the ring QQ[x,y], you can always land in the ring QQ[x,y] itself, for any value of x and y. As far as I know, we have no mechanism for substitution-coercion at the level of rings, do we ? Do you want me to remove the comment, or write something else ? |
I think the minimal uniform parent (i.e., the smallest parent that makes the operations you are implementing a well-defined map) is almost always the right choice — and is what we are typically using. In other words: usually, the parent of the result should only depend on the parents of the inputs. For p∈ℚ[x,y], I would say p(x=0,y=0) is in ℚ, but p(x=0) == p(x=0, y=y) is in ℚ[y] regardless of the value of p.
I'm not sure what kind of mechanism you have in mind. Perhaps
I think the comment can be removed, but feel free to leave it or reword it if you feel there is something important to say. |
75b6da6
to
956aaf0
Compare
ok, j'ai raccourci le commentaire |
Documentation preview for this PR (built with commit 956aaf0; changes) is ready! 🎉 |
ok, thanks |
There was a problem when evaluating polynomials: the following was failing
I propose a fix that hopefully does not break anything else.
We look at a non-zero coefficient to try to guess the correct new base ring, instead of looking at the constant term.
This does not fix the following inconsistent behaviour:
📝 Checklist