-
Notifications
You must be signed in to change notification settings - Fork 147
Fix polyratfun bugs caused by incorrect clean flag #482
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
Conversation
|
Looking through the issues, I think that the known open polyratfun bugs are now caught and terminate form, so the user can adjust their script to avoid them, though of course they are not fixed. Without looking at the complicated interactions of polyratfun with collect, argument etc in more detail, this seems like a good intermediate change to make, for safety. What do you think? |
|
At least with @tueda 's benchmark ( https://gist.github.com/tueda/8cabf511573b115b9c17a7a181bf0248 ) there is no measurable performance difference due to this. |
|
The code compares the powers of the first variable in the first and last terms. It is true that at least it catches problems in particular cases, e.g., But I'm not sure what really causes the error in the following sense: I can't make a simple case that is wrong but can't be caught by this check. For example, if I give If we can find more precise conditions under which errors occur, the check may become simpler and lighter. |
|
Interesting. The second variable doesn't even need to go in rat1. This should be causing So actually it seems like the issues can all be fixed properly, and the checks removed, by unconditionally calling |
|
For @tueda 's benchmark (with default N=30), on my system I get |
|
How about some simple checks like the following pseudocode: if (!sort_univar)
if (is_univariate)
if (number_of_terms >= 2)
if (power_of_variable_in_1st_term < power_of_variable_in_2nd_term)
sort_univar = true; |
|
This needs some gymnastics with dollar variables, but it can be done.
… On 1 Mar 2024, at 09:37, Takahiro Ueda ***@***.***> wrote:
How about some simple check like
if (is_univariate)
if (number_of_terms >= 2)
if (power_of_variable_in_1st_term < power_of_variable_in_2nd_term)
sort_univar = true;
—
Reply to this email directly, view it on GitHub <#482 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABJPCETTDLWLGIC73AVDGVDYWA425AVCNFSM6AAAAABD2PZUHCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZSG42DQOBQGY>.
You are receiving this because you are subscribed to this thread.
|
|
I meant adding a simple check that is negligible in time for Josh's unconditional call of |
|
Sorry about that then.
… On 1 Mar 2024, at 10:14, Takahiro Ueda ***@***.***> wrote:
I meant adding a simple check that is negligible in time for Josh's unconditional calling normalize() in poly.cc.
—
Reply to this email directly, view it on GitHub <#482 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABJPCESOLZWIDDSCSAD4KA3YWBBI5AVCNFSM6AAAAABD2PZUHCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZSHAYDMOJYHA>.
You are receiving this because you commented.
|
|
I'll look at this and check performance. It is not quite so simple, checking powers of first and second terms fails in the case of Edit: I did not appreciate this before. In this case, not even |
|
Here is a new try. Checking first and last monomials should work also for cases where symbols appear with negative exponent. Times: |
|
It gives the correct answer for |
|
No it's not expected, good catch. I'll take a look. |
|
I am not sure what to make of this one. In the In the |
|
OK, now I think I follow it. |
|
This was quite easy to fix actually; just check for negative powers in the normalized num and den unconditionally, and then set the clean flag if they appear. For the checks in I am fairly sure we now catch the bad cases here. If you're happy I will squash all of these commits. |
OK. That's fine.
The check is now performed with or without the |
|
Presumably there is a very small loss, I will try to measure. I think you do need to check all of the powers though, since in multivariate cases you can't just check the last term of the polynomial, since the negative power might be in a variable which is sorted earlier, and appear in the middle of the terms. Edit: I don't see any measurable performance difference: 4.3.1: |
There are circumstances in which polyratfun arguments are passed into poly_ratfun_read, with MUSTCLEANPRF not set. For example, if the function was inside another function argument at the point where PolyRatFun is enabled. This causes errors because the input into the poly routines is not properly sorted and normalized. The issue must be caught in two places. In poly.cc poly::argument_to_poly, for univariate cases we can check whether the order of the terms is wrong, and ensure we call normalize if so. In the multivariate cases, normalize was always called unconditionally anyway. In poly_ratfun_read, even though the terms are now always in the correct order, if the argument is not marked MUSTCLEANPRF, denominators of the numerator and denominator are not dealt with. This is resolved by unconditionally checking the minimum power of the symbols in the polynomials, and ensuring clean = false if the minimum powers are ever negative.
|
I ran a multivariate benchmark and also can't measure any performance loss: 4.3.1: |
|
Do you feel there is anything further to add to this one? I think it is in a pretty good shape now. |
|
Unless there is some performance loss for other use cases, I think this is fine. It should be merged before the next (beta?) version release. |
There are some known issues regarding polyratfun which are not easy to fix.
The least we can do is to crash when we hit something that is definitely wrong, for now.
This "fixes" the example in Issue #336
This does not catch Issue #270 !