-
-
Notifications
You must be signed in to change notification settings - Fork 514
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
Polynomial division by a unit scalar unexpectedly changes the base ring #39318
Comments
This is a design choice, not a bug. If I understand correctly, the suggestion is that when sage divides a polynomial If a user knows that |
I agree that testing I understand the division of polynomial
In my view, here |
Btw, it does look like a bug to me, not an enhancement. Please restore the bug label. |
No, it's not a bug. Sagemath is a collaborative effort. You may have a particular point of view (or a particular implementation in mind) that makes you think the program should behave a certain way, but please understand that there can be other reasonable viewpoints or implementations that represent different choices, not bugs. In this particular case, I think division by a scalar is implemented as multiplication by the inverse of the scalar, because part of
This seems very reasonable to me, and I'm not at all convinced that your suggestion is better. |
The coercion framework bases its coercions on the parents; not on the particular values of the elements. So in your case, by dividing an element of R by an element in K needs a new parent, since not all elements of K have an inverse in K (or in R). The transcript below shows how the coercion model discovers what to do:
You could use euclidean division instead. It does not need to construct an inverse:
The example with It looks like there is an inconsistency, though:
indicates that the coercion system is able to find an action of QQ on R, but it does not look like that is what is actually used:
The latter does seem like a reportable bug that is hopefully easy to fix. Perhaps you want to repurpose this issue for that? |
I think the code snippet in my comment shows that |
Indeed, it does seem to do that. So one fix would be to remove that special case, because this example shows we may end up with the wrong parents: QQ does have an action on QQ['x']['y']; it is not necessary to treat this via the scalar multiplication of QQ['x'] on QQ['x']['y']. That might give a performance regression: the coercion framework tries very hard to cause a low overhead, but this workaround might have been put in for a reason. In that case it should be guarded a little more carefully so that in doesn't cause these too-general coercions. Digging in the "blame" of those lines suggests the special case was there since very early on and that the proper use of the coercion system was tacked on afterwards. So there's a good chance that this code was just inherited and never properly reviewed when the coercion system got into its current state. |
Some simple timings indicate the "shortcut" of trying to coerce the scalar into the base ring and invert there doesn't seem to save much in time. In the case where the new parent needs to be constructed they seem to be equivalent:
In the case where the action of a smaller ring means the parent doesn't need to be extended, we of course get way better performance:
And finally, if we're already working in a parent where
So I expect that removal of the attempted scalar conversion can just be removed and that we get better behaviour and similar performance by just letting the coercion framework do its work. |
Somewhat related issue #37544 with the parent ring scrambling. |
Steps To Reproduce
We have
which is expected. But then a similar division in another polynomial ring changes the base ring to
Fraction Field
of the original one:Expected Behavior
Division by a unit scalar (ie. an invertible element of the base ring) should not change the base ring of polynomials.
Actual Behavior
Sometimes it is changed as shown by the example above.
Additional Information
No response
Environment
Checklist
The text was updated successfully, but these errors were encountered: