Skip to content

Commit

Permalink
gh-34980: is_prime for ideals uses factorization, can be VERY slow
Browse files Browse the repository at this point in the history
    
Fixes #33360.
    
URL: #34980
Reported by: Lorenz Panny
Reviewer(s): Gonzalo Tornaría, Lorenz Panny, roed314
  • Loading branch information
Release Manager committed Mar 10, 2023
2 parents a6eda33 + 3d4d764 commit f7ea8c7
Showing 1 changed file with 28 additions and 6 deletions.
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

0 comments on commit f7ea8c7

Please sign in to comment.