Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
#18639: handle division for 0 ideal
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCremona committed Jun 9, 2015
1 parent 30ca395 commit 7be3884
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions src/sage/rings/number_field/number_field_ideal.py
Expand Up @@ -1032,6 +1032,8 @@ def is_prime(self):
sage: K.ideal(17).is_prime() # ramified
False
"""
if self.is_zero():
return True
try:
return self._pari_prime is not None
except AttributeError:
Expand Down Expand Up @@ -1068,6 +1070,9 @@ def pari_prime(self):
"""
if not self.is_prime():
raise ValueError("%s is not a prime ideal"%self)
# Handle zero separately for a better error messageL
if self.is_zero():
raise ValueError("%s is not a nonzero prime ideal"%self)
return self._pari_prime

def _cache_bnfisprincipal(self, proof=None, gens_needed=False):
Expand Down Expand Up @@ -1257,6 +1262,39 @@ def is_zero(self):
"""
return self == self.number_field().ideal(0)

def __div__(self, other):
"""
Return the quotient self / other.
EXAMPLES::
sage: R.<x> = PolynomialRing(QQ)
sage: K.<a> = NumberField(x^2 - 5)
sage: I = K.ideal(2/(5+a))
sage: J = K.ideal(17+a)
sage: I/J
Fractional ideal (-17/1420*a + 1/284)
sage: (I/J) * J == I
True
Handling of the zero ideal (see :trac:`18639`)::
sage: K.<a> = NumberField(x^2-10)
sage: I = K.ideal(a)
sage: I0 = K.ideal(0)
sage: I0/I
Ideal (0) of Number Field in a with defining polynomial x^2 - 10
sage: I/I0
Traceback (most recent call last):
...
ZeroDivisionError: division by zero ideal invalid
"""
if other.is_zero():
raise ZeroDivisionError("division by zero ideal invalid")
if self.is_zero():
return self
return self * other.__invert__()

def norm(self):
"""
Return the norm of this fractional ideal as a rational number.
Expand Down Expand Up @@ -1763,11 +1801,6 @@ def divides(self, other):
sage: I.divides(K.ideal(0))
True
"""
try:
if other.is_zero():
return True
except AttributeError:
pass
if not isinstance(other, NumberFieldIdeal):
other = self.number_field().ideal(other)
return (other / self).is_integral()
Expand Down Expand Up @@ -1820,23 +1853,6 @@ def prime_factors(self):
"""
return [x[0] for x in self.factor()]

def __div__(self, other):
"""
Return the quotient self / other.
EXAMPLES::
sage: R.<x> = PolynomialRing(QQ)
sage: K.<a> = NumberField(x^2 - 5)
sage: I = K.ideal(2/(5+a))
sage: J = K.ideal(17+a)
sage: I/J
Fractional ideal (-17/1420*a + 1/284)
sage: (I/J) * J == I
True
"""
return self * other.__invert__()

def __invert__(self):
"""
Return the multiplicative inverse of self. Call with ~self.
Expand Down

0 comments on commit 7be3884

Please sign in to comment.