void-packages/srcpkgs/sagemath/patches/trac-33360-avoid_factoring_...

54 lines
2.1 KiB
Diff
Raw Normal View History

From 6330cee1a69229b2f5d8ac4a09a73d8152f5e14d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= <tornaria@cmat.edu.uy>
Date: Mon, 28 Feb 2022 23:15:16 -0300
Subject: trac 33360: avoid factoring in is_prime()
In the added TEST, the ideal norm is product of two primes but factoring
this product takes about half an hour, so factoring the ideal is slow.
To fix the issue, we only factor the ideal if the norm is a prime power.
---
src/sage/rings/number_field/number_field_ideal.py | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/sage/rings/number_field/number_field_ideal.py b/src/sage/rings/number_field/number_field_ideal.py
index f785f22..10d1f88 100644
--- a/src/sage/rings/number_field/number_field_ideal.py
+++ b/src/sage/rings/number_field/number_field_ideal.py
@@ -995,10 +995,32 @@ class NumberFieldIdeal(Ideal_generic):
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:
+ K = self.number_field().pari_nf()
+ I = self.pari_hnf()
+ # This would be better, but it is broken in pari 2.13.3.
+ # self._pari_prime = K.idealismaximal(I) or None
+ # Instead we factor I, but only if the norm is a prime power
+ n = K.idealnorm(I)
+ if n.denominator() > 1 or not n.isprimepower():
+ self._pari_prime = None
+ return False
F = self.factor() # factorization with caching
if len(F) != 1 or F[0][1] != 1:
self._pari_prime = None
--
cgit v1.0-1-gd88e