Skip to content

Commit

Permalink
Make Qp.integer_ring() faster.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tornaria committed Apr 6, 2023
1 parent 1d0a04a commit 18d6640
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/sage/rings/padics/padic_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def integer_ring(self, print_mode=None):
if not self.is_field() and print_mode is None:
return self
if print_mode is None:
return self.change(field=False)
return self.change(field=False, check=False)
else:
from sage.misc.superseded import deprecation
deprecation(23227, "Use the change method if you want to change print options in integer_ring()")
Expand Down

0 comments on commit 18d6640

Please sign in to comment.