-
-
Notifications
You must be signed in to change notification settings - Fork 565
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
Improve polynomial powering in positive characteristic #18547
Comments
Branch pushed to git repo; I updated commit sha1. New commits:
|
Commit: |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:4
Your added doctest still takes |
comment:5
I don't get it, it seems that the doctest doesn't even use the new code. It's equally slow with or without this patch... |
comment:6
I think it does use the code. But what's happening is that in the line
where
with |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:9
Replying to @jdemeyer:
Right, because my doctest was wrong: The code is intended for sparse polynomials. I have not really been able yet to determine what is precisely going on for dense polynomial. Though, as indicated by fwclarke and mentioned in my note 2. in the description, there is another problem for dense polynomial, namely that creating a large polynomial over a finite field takes a very long time. It is not the purpose of this ticket to correct this, even though it should be corrected! This patch thus improves the situation for sparse polynomials only. The code is indeed not used for dense polynomials over Important note: I forgot to test whether the base ring is a field, which is of course mandatory. I correct this mistake in my latest commit. |
comment:10
You added 3 cases here:
You should add a doctest for each of these 3 cases (and perhaps replace the second |
comment:11
Replying to @bgrenet:
Why is this "of course" mandatory? You need that the characteristic is a prime number, not that the base ring is a field. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:13
The algorithm I proposed was completely wrong: If In the commit, I correct this mistake, and in the same time I take jdemeyer's comments into account:
Furthermore, I improve the code not using |
comment:18
Please justify in the code why
|
comment:19
I suggest to remove the special case for finite fields. The generic code should work just fine for finite fields. |
comment:20
And I'm not too happy with this either:
Checking whether some complicated ring is a field might be an expensive operation. I prefer
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:22
I didn't say you had to remove this:
|
comment:23
Replying to @jdemeyer:
I had run some tests and my conclusion that was using Replying to @jdemeyer:
Done. Replying to @jdemeyer:
Actually, the current code is faster for finite fields. With the special case: sage: R.<x> = PolynomialRing(GF(17),sparse=True)
sage: p = R.random_element(100)
sage: %timeit p^(17^5)
The slowest run took 11.13 times longer than the fastest. This could mean that an intermediate result is being cached
1000 loops, best of 3: 159 µs per loop Without the special case, with the same %timeit p^(17^5)
The slowest run took 26.59 times longer than the fastest. This could mean that an intermediate result is being cached
1000 loops, best of 3: 249 µs per loop I may refactor the code though so that it is less redundant. Tell me what you think. Replying to @jdemeyer:
I am happy if you find a good way to test this function! |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:25
Replying to @jdemeyer:
Right, my mistake! |
comment:26
Replying to @bgrenet:
You have many cases and they should all be tested:
|
comment:28
Replying to @jdemeyer:
I introduced your proposed doctest, with the following change: Since I put a threshold Replying to @bgrenet:
Actually, the code was not correct for non-prime finite fields... (The special case should have been for prime finite fields only.) So I finally followed your advice and removed the special case. In the same time, I refactored a bit the code. |
Reviewer: Jeroen Demeyer |
Changed branch from u/bruno/polynomial_powering_positive_characteristic to |
Before:
After:
Notes.
I've tried to be careful with quite extensive tests not to slow down the computations for "easy" cases. This explains the threshold values in the code.
This is related to inefficient polynomial powering for positive characteristic #7253 and make raising polynomials in characteristic p to large powers (and printing them) more efficient #12660. Though, there is another problem for non-sparse polynomials: Simply assigning the value and printing the polynomial take a very long time. Compare the timings for
and
Thus for tickets inefficient polynomial powering for positive characteristic #7253 and make raising polynomials in characteristic p to large powers (and printing them) more efficient #12660 to be closed, it remains to handle this other problem, but this is not the purpose of this ticket.
Component: commutative algebra
Keywords: polynomial, powering
Author: Bruno Grenet
Branch/Commit:
41dd905
Reviewer: Jeroen Demeyer
Issue created by migration from https://trac.sagemath.org/ticket/18547
The text was updated successfully, but these errors were encountered: