11r"""
22Integral domains
3+
4+ AUTHORS:
5+
6+ - Teresa Gomez-Diaz (2008): initial version
7+
8+ - Julian Rueth (2013-09-10): added category refinement similar to the one done by Fields
9+
310"""
411#*****************************************************************************
512# Copyright (C) 2008 Teresa Gomez-Diaz (CNRS) <[email protected] > 13+ # 2013 Julian Rueth <[email protected] > 614#
715# Distributed under the terms of the GNU General Public License (GPL)
816# http://www.gnu.org/licenses/
917#******************************************************************************
1018
1119from sage .categories .category import Category
12- from sage .categories .category_singleton import Category_singleton
20+ from sage .categories .category_singleton import Category_singleton , Category_contains_method_by_parent_class
1321from sage .misc .cachefunc import cached_method
1422from sage .categories .commutative_rings import CommutativeRings
23+ from sage .misc .lazy_attribute import lazy_class_attribute
1524from sage .categories .domains import Domains
25+ import sage .rings .ring
1626
1727class IntegralDomains (Category_singleton ):
1828 """
19- The category of integral domains
20- commutative rings with no zero divisors
29+ The category of integral domains, i.e., non-trivial commutative rings with
30+ no zero divisors
2131
2232 EXAMPLES::
2333
@@ -40,6 +50,60 @@ def super_categories(self):
4050 """
4151 return [CommutativeRings (), Domains ()]
4252
53+ def __contains__ (self , x ):
54+ """
55+ Return whether ``x`` is in the category of integral domains.
56+
57+ EXAMPLES::
58+
59+ sage: GF(4, "a") in IntegralDomains()
60+ True
61+ sage: QQ in IntegralDomains()
62+ True
63+ sage: ZZ in IntegralDomains()
64+ True
65+ sage: IntegerModRing(4) in IntegralDomains()
66+ False
67+
68+ Test that :trac:`15183` has been fixed::
69+
70+ sage: IntegerModRing(2) in IntegralDomains()
71+ True
72+
73+ """
74+ try :
75+ return self ._contains_helper (x ) or sage .rings .ring ._is_IntegralDomain (x )
76+ except StandardError :
77+ return False
78+
79+ @lazy_class_attribute
80+ def _contains_helper (cls ):
81+ """
82+ Helper for containment tests in the category of integral domains.
83+
84+ This helper just tests whether the given object's category is already
85+ known to be a sub-category of the category of integral domains. There
86+ are, however, rings that are initialised as plain commutative rings and
87+ found out to be integral domains only afterwards. Hence, this helper
88+ alone is not enough for a proper containment test.
89+
90+ TESTS::
91+
92+ sage: P.<x> = QQ[]
93+ sage: Q = P.quotient(x^2+2)
94+ sage: Q.category()
95+ Join of Category of commutative algebras over Rational Field and Category of subquotients of monoids and Category of quotients of semigroups
96+ sage: ID = IntegralDomains()
97+ sage: ID._contains_helper(Q)
98+ False
99+ sage: Q in ID # This changes the category!
100+ True
101+ sage: ID._contains_helper(Q)
102+ True
103+
104+ """
105+ return Category_contains_method_by_parent_class (cls ())
106+
43107 class ParentMethods :
44108 def is_integral_domain (self ):
45109 """
0 commit comments