void-packages/srcpkgs/sagemath/patches/34980-avoid_factoring_in_is...

48 lines
1.7 KiB
Diff

diff --git a/src/sage/rings/number_field/number_field_ideal.py b/src/sage/rings/number_field/number_field_ideal.py
index d5f7157217f..1a9d11aec68 100644
--- a/src/sage/rings/number_field/number_field_ideal.py
+++ b/src/sage/rings/number_field/number_field_ideal.py
@@ -996,16 +996,36 @@ 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()
+
+ self._pari_prime = K.idealismaximal(I) or None
+
+ # PARI uses probabilistic primality testing inside idealismaximal().
+ if self._pari_prime \
+ and get_flag(None, 'arithmetic') \
+ and not self._pari_prime[0].isprime():
+ self._pari_prime = None
+
+ return self._pari_prime is not None
def pari_prime(self):
r"""