From 3df71d581a10a14a5399b79f666560e1fd2dfc6b Mon Sep 17 00:00:00 2001 From: kevin lui Date: Sun, 18 Aug 2019 19:09:04 -0700 Subject: [PATCH] Implemented prime_factors --- src/sage/rings/number_field/number_field.py | 4 +- .../number_field/order_fractional_ideal.py | 42 ++++++++++++++++--- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index cb52a1b67f9..eca506fb694 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -3384,7 +3384,7 @@ def primes_above(self, x, degree=None): sage: F.prime_above(0) Traceback (most recent call last): ... - AttributeError: 'NumberFieldIdeal' object has no attribute 'prime_factors' + ValueError: Does not make sense to factor (0) """ if degree is not None: degree = ZZ(degree) @@ -3479,7 +3479,7 @@ def prime_above(self, x, degree=None): sage: F.prime_above(0) Traceback (most recent call last): ... - AttributeError: 'NumberFieldIdeal' object has no attribute 'prime_factors' + ValueError: Does not make sense to factor (0) """ ids = self.primes_above(x, degree) diff --git a/src/sage/rings/number_field/order_fractional_ideal.py b/src/sage/rings/number_field/order_fractional_ideal.py index f8f6e4870e4..cce7d3330e0 100644 --- a/src/sage/rings/number_field/order_fractional_ideal.py +++ b/src/sage/rings/number_field/order_fractional_ideal.py @@ -66,6 +66,19 @@ def _richcmp_(self, other, op): return NotImplemented return richcmp(self.free_module(), other.free_module(), op) + def is_zero(self): + r""" + Return whether this ideal is the zero ideal. + + EXAMPLES:: + + sage: K. = QuadraticField(5) + sage: O = K.order(a) + sage: O.ideal(0).is_zero() + True + """ + return all(x.is_zero() for x in self.gens()) + @cached_method def is_integral(self): """ @@ -200,14 +213,31 @@ def free_module(self): """ return basis_to_module(self.basis(), self.number_field()) - # def prime_factors(self): - # O = self.order() - # OK = O.integral_closure() + def prime_factors(self): + r""" + Return a list of the prime ideal factors of `self`. + + EXAMPLES:: + + In this example, 5 splits in `OK` but not in `O`. :: + + sage: K. = QuadraticField(-1) + sage: OK = K.maximal_order() + sage: O = K.order(5*a) + sage: OK.ideal(5).prime_factors() + [Fractional ideal (-a - 2), Fractional ideal (2*a + 1)] + sage: O.ideal(5).prime_factors() + [Fractional ideal (5, 5*a) of non-maximal order] + """ + if self.is_zero(): + raise ValueError("Does not make sense to factor (0)") + O = self.order() + OK = O.integral_closure() - # aOK = OK.ideal(self.gens()) - # above = aOK.prime_factors() + aOK = OK.ideal(self.gens()) + above = aOK.prime_factors() - # return [O.intersection(p) for p in above] + return list(set(O.intersection(p) for p in above)) def basis_to_module(B, K):