-
-
Notifications
You must be signed in to change notification settings - Fork 529
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
any_root(ring=F_ext)
is underperforming
#37442
Comments
Looking a little more carefully the real culprit is the "cheating" any_root() did before. In the original code, if The new code always uses I started working on a fix in #37443, but I have an issue that if I do
SageMath cannot always coerce the root in This coercion is a serious problem and even dumb examples lead to errors sage: R.<x> = GF(11)[]
....: F_ext = GF(11^6, modulus=x^6+3*x^4+4*x^3+6*x^2+7*x+2,names="a")
....: ring = GF(11^6, modulus=x^6+3*x^4+4*x^3+6*x^2+7*x+2,names="b")
....: F_ext(ring.random_element())
# Error I think maybe this needs a separate issue? |
Yes, let’s open a separate issue for the finite field issue(sss), and probably get people on sage-devel? I think maybe the whole design should be reconsidered. |
I agree. Are you happy to make the finite field issue? For now we could patch this function to call roots when the degree of the base field goes over a threshold or when the characteristic goes over a threshold? This seems ugly but I don't know what else to do |
Yes and yes. I'll collect some more data / potential fixes first before creating the issue |
This should now be fixed by #37443 ┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.2, Release Date: 2023-12-03 │
│ Using Python 3.11.4. Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: set_random_seed(0)
....: K.<x> = GF((29, 3), names="a")[]
....: f = K.random_element(15).monic()
....: L.<a> = f.splitting_field()
....: %time _ = f.roots(L)
....: %time _ = f.any_root(L)
CPU times: user 90.3 ms, sys: 399 µs, total: 90.7 ms
Wall time: 90.7 ms
CPU times: user 11.1 ms, sys: 615 µs, total: 11.7 ms
Wall time: 12.8 ms ┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.3.beta8, Release Date: 2024-02-13 │
│ Using Python 3.11.4. Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable. ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: set_random_seed(0)
....: K.<x> = GF((29, 3), names="a")[]
....: f = K.random_element(15).monic()
....: L.<a> = f.splitting_field()
....: %time _ = f.roots(L)
....: %time _ = f.any_root(L)
CPU times: user 81 ms, sys: 347 µs, total: 81.3 ms
Wall time: 81.4 ms
CPU times: user 7.63 ms, sys: 407 µs, total: 8.04 ms
Wall time: 8.92 ms |
Steps To Reproduce
In my refactoring of
any_root()
#37170 I accidentally introduced a performance regression when finding roots over extension fields.Sage 10.2
SageMath version 10.3.beta8
Expected Behavior
When I refactor code, it should not have worse performance
Actual Behavior
I have refactored code and introduced poor performance
Additional Information
The fix will be to go back to
any_root()
and complicate the implementation to look for a root in the smallest extension before casting the root toF_ext
. Currently, the implementation finds a root inf.change_ring(F_ext).any_root()
which is very slow for very large extensions.The new version should look for some
degree
degree distinct degree factorisation over various extensions working with the smallest one possible.Environment
Checklist
The text was updated successfully, but these errors were encountered: