-
-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-37170: Total refactor of
any_root()
to solve issue in characteri…
…stic two and clean up the code This PR was inspired by the issue #37160, which found that computing isomorphisms between fields of even characteristic was taking much much longer than expected (20s vs 100ms). My first attempt (see commit history) were to simply patch up the `any_root()` function, but this yielded some results which left the code in an even more confusing state. Following the advice of the reviewers, I have now implemented `any_irreducible_factor()` which given a polynomial element computes an irreducible factor of this polynomial with minimal degree. When the optional parameter `degree=None` is set, then an irreducible factor of degree `degree` is computed and a `ValueError` is raise if no such factor exists. Now, `any_root()` becomes simply a call to `self. any_irreducible_factor(degree=1)` and a root is found from this linear polynomial. We also handle all the other cases of optional arguments handled by the old function, so the function *should* behave as before, but with a cleaner code to read. ### Before PR ```python ┌────────────────────────────────────────────────────────────────────┐ │ SageMath version 10.2, Release Date: 2023-12-03 │ │ Using Python 3.11.4. Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘ sage: set_random_seed(0) ....: K.<z8> = GF(2^8) ....: R.<x> = K[] ....: u = R.irreducible_element(2) ....: K_ext = K.extension(modulus=u, names="a") ....: R_ext.<y_ext> = K_ext[] ....: poly = R_ext.random_element(2).monic() ....: %time poly.roots() CPU times: user 20.5 s, sys: 19.9 ms, total: 20.5 s Wall time: 20.5 s [] ``` ### After PR ```py ┌────────────────────────────────────────────────────────────────────┐ │ SageMath version 10.3.beta6, Release Date: 2024-01-21 │ │ 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.<z8> = GF(2^8) ....: R.<x> = K[] ....: u = R.irreducible_element(2) ....: K_ext = K.extension(modulus=u, names="a") ....: R_ext.<y_ext> = K_ext[] ....: %time R_ext.random_element(2).roots() CPU times: user 110 ms, sys: 9.03 ms, total: 119 ms Wall time: 150 ms [] ``` This fixes #37160 but i think more feedback and thorough doctests need to be included considering this is a very old function which many projects will be using. URL: #37170 Reported by: Giacomo Pope Reviewer(s): Giacomo Pope, grhkm21, Lorenz Panny, Volker Braun
- Loading branch information
Showing
9 changed files
with
624 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.