-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
Make Qp.integer_ring() faster. #35442
Merged
Merged
Conversation
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
2 tasks
Look good, though there are linting failures which I didn't look at. |
AFAICT, the linting failures are not my fault and fixed by #35418 . |
3 tasks
The precision for relaxed p-adics has 3 components: `(default_prec, halting_prec, secure)` where the last one `secure` is a boolean defaulting to `False`. However, the `construction()` method doesn't know about it: ``` sage: K = QpER(5, secure=True) sage: K.construction(forbid_frac_field=True) (Completion[5, prec=(20, 40)], Rational Field) sage: R = ZpER(5, secure=True) sage: R.construction() (Completion[5, prec=(20, 40)], Integer Ring) ``` This has two undesired consequences for the `change()` method: a. The `secure` attribute is not copied: ``` sage: K.is_secure() True sage: K.change().is_secure() False sage: R.is_secure() True sage: R.change().is_secure() False ``` b. The `check=False` option is broken: ``` sage: K.change(check=False) ... ValueError: not enough values to unpack (expected 3, got 2) sage: R.change(check=False) ... ValueError: not enough values to unpack (expected 3, got 2) ``` Fixing the `construction()` method solves both issues. After this commit: ``` sage: K = QpER(5, secure=True) sage: K.construction(forbid_frac_field=True) (Completion[5, prec=(20, 40, True)], Rational Field) sage: K.change().is_secure() True sage: K.change(check=False) 5-adic Field handled with relaxed arithmetics sage: K.change(check=False).is_secure() True sage: R = ZpER(5, secure=True) sage: R.construction() (Completion[5, prec=(20, 40, True)], Integer Ring) sage: R.change().is_secure() True sage: R.change(check=False) 5-adic Ring handled with relaxed arithmetics sage: R.change(check=False).is_secure() True ```
The method pAdicGeneric.integer_ring() uses LocalGeneric.change() to turn a p-adic field into a p-adic ring. The latter calls a factory function which, by default, checks primality of p. However, when p came from a Qp this step is not necessary. We avoid it by adding `check=False` to the call to `LocalGeneric.change()` in `pAdicGeneric.integer_ring()`. This results in significant time savings for large primes, e.g. in the current test suite: Before this commit: ``` sage: R = Qp(next_prime(10^60)) sage: timeit('R.integer_ring()') 25 loops, best of 3: 22.2 ms per loop sage: %time TestSuite(R).run() CPU times: user 14.4 s, sys: 44 µs, total: 14.4 s Wall time: 14.4 s ``` After this commit: ``` sage: R = Qp(next_prime(10^60)) sage: timeit('R.integer_ring()') 625 loops, best of 3: 68 μs per loop sage: %time TestSuite(R).run() CPU times: user 714 ms, sys: 239 µs, total: 715 ms Wall time: 717 ms ``` Doctest of `padic_base_leaves.py` goes down from ~33 to ~5 seconds.
tornaria
force-pushed
the
Qp_integer_ring
branch
from
April 6, 2023 23:37
27bf1b2
to
18d6640
Compare
Rebased to 10.0.beta8 |
Documentation preview for this PR is ready! 🎉 |
roed314
approved these changes
Apr 7, 2023
vbraun
pushed a commit
that referenced
this pull request
Apr 23, 2023
### 📚 Description A test is supposed to take < 1s or else be marked # long time. Here we consider slow tests taking >> 10s. When possible we fix or change the test to take less time, otherwise we just mark the test as long time. Occasionally we create a new smaller test and keep the original one as long. After this and #35442 the slowest tests are a few taking ~ 10s. The total time to doctest all goes down from 880 to 806 seconds (using `-tp 8 --all`). ~~NOTE: there's a minor merge conflict with #35314 which I will resolve once that PR is merged.~~ ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #35443 Reported by: Gonzalo Tornaría Reviewer(s): Gonzalo Tornaría, Matthias Köppe
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📚 Description
The method pAdicGeneric.integer_ring() uses LocalGeneric.change() to
turn a p-adic field into a p-adic ring. The latter calls a factory
function which, by default, checks primality of p.
However, when p came from a Qp this step is not necessary. We avoid it
by adding
check=False
to the call toLocalGeneric.change()
inpAdicGeneric.integer_ring()
. This results in significant time savingsfor large primes, e.g. in the current test suite:
Before this commit:
After this commit:
Doctest of
padic_base_leaves.py
goes down from ~33 to ~5 seconds.Note that the
check=False
option for thechange()
method in relaxed type is broken, so this needs #35441. Other than that this is a one-liner.📝 Checklist
⌛ Dependencies