Skip to content
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

is_prime for ideals uses factorization, can be VERY slow #34980

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/sage/rings/number_field/number_field_ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,16 +996,38 @@ def is_prime(self):
False
sage: K.ideal(17).is_prime() # ramified
False

TESTS:

Check that we do not factor the norm of the ideal, this used
to take half an hour, see :trac:`33360`::

sage: K.<a,b,c> = NumberField([x^2-2,x^2-3,x^2-5])
sage: t = (((-2611940*c + 1925290/7653)*b - 1537130/7653*c
....: + 10130950)*a + (1343014/7653*c - 8349770)*b
....: + 6477058*c - 2801449990/4002519)
sage: t.is_prime()
False
"""
try:
return self._pari_prime is not None
except AttributeError:
F = self.factor() # factorization with caching
if len(F) != 1 or F[0][1] != 1:
self._pari_prime = None
else:
self._pari_prime = F[0][0]._pari_prime
return self._pari_prime is not None
pass

K = self.number_field().pari_nf()
I = self.pari_hnf()

candidate = K.idealismaximal(I) or None

# PARI uses probabilistic primality testing inside idealismaximal().
if get_flag(None, 'arithmetic'):
# proof required, check using isprime()
if candidate and not candidate[0].isprime():
candidate = None

self._pari_prime = candidate

return self._pari_prime is not None

def pari_prime(self):
r"""
Expand Down