# HG changeset patch
# User Nick Alexander <ncalexander@gmail.com>
# Date 1241624778 -7200
# Node ID 08c63b587c8d03bb899f22b06a97b74311564780
# Parent  d22a81385eb6030f5904e7c0604722b0ac305b81
Fix for #5982

diff -r d22a81385eb6 -r 08c63b587c8d sage/rings/polynomial/multi_polynomial_ideal.py
--- a/sage/rings/polynomial/multi_polynomial_ideal.py	Mon Jun 15 00:02:27 2009 -0700
+++ b/sage/rings/polynomial/multi_polynomial_ideal.py	Wed May 06 17:46:18 2009 +0200
@@ -813,6 +813,49 @@
           York 1993.
         """
         return [P for _,P in self.complete_primary_decomposition(algorithm)]
+
+    def is_prime(self, **kwds):
+        r"""
+        Return ``True`` if this ideal is prime.
+
+        INPUT::
+
+        - keyword arguments are passed on to
+          ``complete_primary_decomposition``; in this way you can
+          specify the algorithm to use.
+
+        EXAMPLES::
+
+            sage: R.<x, y> = PolynomialRing(QQ, 2)
+            sage: I = (x^2 - y^2 - 1)*R
+            sage: I.is_prime()
+            True
+            sage: (I^2).is_prime()
+            False
+
+            sage: J = (x^2 - y^2)*R
+            sage: J.is_prime()
+            False
+            sage: (J^3).is_prime()
+            False
+
+            sage: (I * J).is_prime()
+            False
+
+            The following is Trac #5982.  Note that the quotient ring
+            is not recognized as being a field at this time, so the
+            fraction field is not the quotient ring itself::
+
+            sage: Q = R.quotient(I); Q
+            Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 - y^2 - 1)
+            sage: Q.fraction_field()
+            Fraction Field of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 - y^2 - 1)
+        """
+        CPD = self.complete_primary_decomposition(**kwds)
+        if len(CPD) != 1:
+            return False
+        _, P = CPD[0]
+        return self == P
             
     @require_field
     def triangular_decomposition(self, algorithm=None, singular=singular_default):
diff -r d22a81385eb6 -r 08c63b587c8d sage/rings/ring.pyx
--- a/sage/rings/ring.pyx	Mon Jun 15 00:02:27 2009 -0700
+++ b/sage/rings/ring.pyx	Wed May 06 17:46:18 2009 +0200
@@ -706,10 +706,15 @@
             sage: R.fraction_field()
             Fraction Field of Multivariate Polynomial Ring in x, y over Ring of integers modulo 389            
         """
-        if self.is_field():
-            return self
-        elif not self.is_integral_domain():
+        if not self.is_integral_domain():
             raise TypeError, "self must be an integral domain."
+
+        try:
+            if self.is_field():
+                return self
+        except NotImplementedError:
+            pass
+
         if self.__fraction_field is not None:
             return self.__fraction_field
         else:
