Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ring categories #37719

Merged
merged 24 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/doc/en/thematic_tutorials/coercion_and_categories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ This base class provides a lot more methods than a general parent::
'_coerce_impl',
'_default_category',
'_gens',
'_ideal_class_',
'_ideal_monoid',
'_latex_names',
'_list',
Expand All @@ -127,24 +126,20 @@ This base class provides a lot more methods than a general parent::
'_zero_ideal',
'algebraic_closure',
'base_extend',
'class_group',
'content',
'derivation',
'derivation_module',
'divides',
'epsilon',
'extension',
'fraction_field',
'frobenius_endomorphism',
'gcd',
'gen',
'gens',
'ideal',
'ideal_monoid',
'integral_closure',
'is_commutative',
'is_field',
'is_integral_domain',
'is_integrally_closed',
'is_noetherian',
'is_prime_field',
Expand Down Expand Up @@ -858,7 +853,9 @@ The four axioms requested for coercions
rational field is a homomorphism of euclidean domains::

sage: QQ.coerce_map_from(ZZ).category_for()
Join of Category of euclidean domains and Category of infinite sets
Join of Category of euclidean domains
and Category of noetherian rings
and Category of infinite sets
and Category of metric spaces

.. end of output
Expand Down
1 change: 1 addition & 0 deletions src/doc/en/tutorial/tour_coercion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ implemented in Sage as well:
sage: ZZ.category()
Join of Category of Dedekind domains
and Category of euclidean domains
and Category of noetherian rings
and Category of infinite enumerated sets
and Category of metric spaces
sage: ZZ.category().is_subcategory(Rings())
Expand Down
1 change: 1 addition & 0 deletions src/doc/fr/tutorial/tour_coercion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ par ailleurs les catégories en tant que telles :
sage: ZZ.category()
Join of Category of Dedekind domains
and Category of euclidean domains
and Category of noetherian rings
and Category of infinite enumerated sets
and Category of metric spaces
sage: ZZ.category().is_subcategory(Rings())
Expand Down
1 change: 1 addition & 0 deletions src/doc/ja/tutorial/tour_coercion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Sageのクラス階層と圏の階層構造にはそれなりに類似が見ら
sage: ZZ.category()
Join of Category of Dedekind domains
and Category of euclidean domains
and Category of noetherian rings
and Category of infinite enumerated sets
and Category of metric spaces
sage: ZZ.category().is_subcategory(Rings())
Expand Down
1 change: 1 addition & 0 deletions src/doc/pt/tutorial/tour_coercion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ categorias matemáticas também são implementadas no Sage:
sage: ZZ.category()
Join of Category of Dedekind domains
and Category of euclidean domains
and Category of noetherian rings
and Category of infinite enumerated sets
and Category of metric spaces
sage: ZZ.category().is_subcategory(Rings())
Expand Down
3 changes: 3 additions & 0 deletions src/sage/algebras/clifford_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ def __init__(self, Q, names, category=None):
sage: Cl.category()
Category of finite dimensional super algebras with basis over
(Dedekind domains and euclidean domains
and noetherian rings
and infinite enumerated sets and metric spaces)
sage: TestSuite(Cl).run()

Expand Down Expand Up @@ -1093,6 +1094,7 @@ def lift_module_morphism(self, m, names=None):
sage: phi.category_for()
Category of finite dimensional super algebras with basis over
(Dedekind domains and euclidean domains
and noetherian rings
and infinite enumerated sets and metric spaces)
sage: phi.matrix()
[ 1 0 0 0 7 -3 -7 0]
Expand Down Expand Up @@ -1177,6 +1179,7 @@ def lift_isometry(self, m, names=None):
sage: phi.category_for()
Category of finite dimensional super algebras with basis over
(Dedekind domains and euclidean domains
and noetherian rings
and infinite enumerated sets and metric spaces)
sage: phi.matrix()
[ 1 0 0 0 1 2 5 0]
Expand Down
2 changes: 2 additions & 0 deletions src/sage/categories/bimodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def _make_named_class_key(self, name):
and Category of metric spaces,
Join of Category of Dedekind domains
and Category of euclidean domains
and Category of noetherian rings
and Category of infinite enumerated sets
and Category of metric spaces)

Expand All @@ -85,6 +86,7 @@ def _make_named_class_key(self, name):
(Category of fields,
Join of Category of Dedekind domains
and Category of euclidean domains
and Category of noetherian rings
and Category of infinite enumerated sets
and Category of metric spaces)

Expand Down
5 changes: 4 additions & 1 deletion src/sage/categories/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ def structure(self):
sage: structure(Rings())
(Category of unital magmas, Category of additive unital additive magmas)
sage: structure(Fields())
(Category of euclidean domains,)
(Category of euclidean domains, Category of noetherian rings)
sage: structure(Algebras(QQ))
(Category of unital magmas,
Category of right modules over Rational Field,
Expand Down Expand Up @@ -2839,6 +2839,7 @@ def _make_named_class_key(self, name):
sage: Algebras(ZZ)._make_named_class_key("parent_class")
Join of Category of Dedekind domains
and Category of euclidean domains
and Category of noetherian rings
and Category of infinite enumerated sets
and Category of metric spaces

Expand All @@ -2851,6 +2852,7 @@ def _make_named_class_key(self, name):
and Category of metric spaces,
Join of Category of Dedekind domains
and Category of euclidean domains
and Category of noetherian rings
and Category of infinite enumerated sets
and Category of metric spaces)

Expand Down Expand Up @@ -2978,6 +2980,7 @@ def _make_named_class_key(self, name):
sage: Modules(ZZ)._make_named_class_key('element_class')
Join of Category of Dedekind domains
and Category of euclidean domains
and Category of noetherian rings
and Category of infinite enumerated sets
and Category of metric spaces
sage: Modules(QQ)._make_named_class_key('parent_class')
Expand Down
3 changes: 2 additions & 1 deletion src/sage/categories/category_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ def _make_named_class_key(self, name):

sage: Modules(ZZ)._make_named_class_key('element_class')
Join of Category of Dedekind domains
and Category of euclidean domains
and Category of euclidean domains
and Category of noetherian rings
and Category of infinite enumerated sets
and Category of metric spaces
sage: Modules(QQ)._make_named_class_key('parent_class')
Expand Down
50 changes: 48 additions & 2 deletions src/sage/categories/commutative_rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,39 @@ def is_commutative(self) -> bool:
"""
return True

def _ideal_class_(self, n=0):
r"""
Return a callable object that can be used to create ideals in this
commutative ring.

This class can depend on `n`, the number of generators of the ideal.
The default input of `n=0` indicates an unspecified number of generators,
in which case a class that works for any number of generators is returned.

EXAMPLES::

sage: ZZ._ideal_class_()
<class 'sage.rings.ideal.Ideal_pid'>
sage: RR._ideal_class_()
<class 'sage.rings.ideal.Ideal_pid'>
sage: R.<x,y> = GF(5)[]
sage: R._ideal_class_(1)
<class 'sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal'>
sage: S = R.quo(x^3 - y^2)
sage: S._ideal_class_(1)
<class 'sage.rings.quotient_ring.QuotientRingIdeal_principal'>
sage: S._ideal_class_(2)
<class 'sage.rings.quotient_ring.QuotientRingIdeal_generic'>
sage: T.<z> = S[] # needs sage.libs.singular
sage: T._ideal_class_(5) # needs sage.libs.singular
<class 'sage.rings.ideal.Ideal_generic'>
sage: T._ideal_class_(1) # needs sage.libs.singular
<class 'sage.rings.ideal.Ideal_principal'>
"""
# One might need more than just n
from sage.rings.ideal import Ideal_generic, Ideal_principal
return Ideal_principal if n == 1 else Ideal_generic

def _test_divides(self, **options):
r"""
Run generic tests on the method :meth:`divides`.
Expand Down Expand Up @@ -248,6 +281,19 @@ class Finite(CategoryWithAxiom):
....: GF(5)]) in Rings().Commutative().Finite()
True
"""
def extra_super_categories(self):
r"""
Let Sage knows that finite commutative rings
are Noetherian.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check whether you want to use "Noetherian" or "noetherian" throughout the text


EXAMPLES::

sage: CommutativeRings().Finite().extra_super_categories()
[Category of noetherian rings]
"""
from sage.categories.noetherian_rings import NoetherianRings
return [NoetherianRings()]

class ParentMethods:
def cyclotomic_cosets(self, q, cosets=None):
r"""
Expand Down Expand Up @@ -367,7 +413,7 @@ def cyclotomic_cosets(self, q, cosets=None):
try:
~q
except ZeroDivisionError:
raise ValueError("%s is not invertible in %s" % (q,self))
raise ValueError("%s is not invertible in %s" % (q, self))

if cosets is None:
rest = set(self)
Expand All @@ -378,7 +424,7 @@ def cyclotomic_cosets(self, q, cosets=None):
while rest:
x0 = rest.pop()
o = [x0]
x = q*x0
x = q * x0
while x != x0:
o.append(x)
rest.discard(x)
Expand Down
14 changes: 9 additions & 5 deletions src/sage/categories/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from sage.categories.category_singleton import Category_contains_method_by_parent_class
from sage.categories.euclidean_domains import EuclideanDomains
from sage.categories.division_rings import DivisionRings
from sage.categories.noetherian_rings import NoetherianRings

from sage.structure.element import coerce_binop

Expand All @@ -33,7 +34,9 @@ class Fields(CategoryWithAxiom):
sage: K
Category of fields
sage: Fields().super_categories()
[Category of euclidean domains, Category of division rings]
[Category of euclidean domains,
Category of division rings,
Category of noetherian rings]

sage: K(IntegerRing())
Rational Field
Expand All @@ -54,10 +57,9 @@ def extra_super_categories(self):
EXAMPLES::

sage: Fields().extra_super_categories()
[Category of euclidean domains]

[Category of euclidean domains, Category of noetherian rings]
"""
return [EuclideanDomains()]
return [EuclideanDomains(), NoetherianRings()]

def __contains__(self, x):
"""
Expand Down Expand Up @@ -165,7 +167,9 @@ def _call_(self, x):
sage: K
Category of fields
sage: Fields().super_categories()
[Category of euclidean domains, Category of division rings]
[Category of euclidean domains,
Category of division rings,
Category of noetherian rings]

sage: K(IntegerRing()) # indirect doctest
Rational Field
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/homset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ def reversed(self):
the principal ideal domain Integer Ring to Ambient free module
of rank 3 over the principal ideal domain Integer Ring in
Category of finite dimensional modules with basis over (Dedekind
domains and euclidean domains
domains and euclidean domains and noetherian rings
and infinite enumerated sets and metric spaces)
sage: type(H)
<class 'sage.modules.free_module_homspace.FreeModuleHomspace_with_category'>
Expand All @@ -1254,7 +1254,7 @@ def reversed(self):
the principal ideal domain Integer Ring to Ambient free module
of rank 2 over the principal ideal domain Integer Ring in
Category of finite dimensional modules with basis over (Dedekind
domains and euclidean domains
domains and euclidean domains and noetherian rings
and infinite enumerated sets and metric spaces)
sage: type(H.reversed())
<class 'sage.modules.free_module_homspace.FreeModuleHomspace_with_category'>
Expand Down
5 changes: 5 additions & 0 deletions src/sage/categories/integral_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def is_integral_domain(self, proof=True):

EXAMPLES::

sage: ZZ.is_integral_domain()
True
sage: QQ.is_integral_domain()
True
sage: Parent(QQ, category=IntegralDomains()).is_integral_domain()
Expand All @@ -113,6 +115,9 @@ def is_integral_domain(self, proof=True):
True
sage: L.is_integral_domain(proof=True) # needs sage.combinat
True

sage: ZZ['x'].is_integral_domain()
True
"""
return True

Expand Down
3 changes: 2 additions & 1 deletion src/sage/categories/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,8 @@ def __init_extra__(self):
sage: M.category() # needs sage.modules
Category of Cartesian products of modules with basis
over (Dedekind domains and euclidean domains
and infinite enumerated sets and metric spaces)
and noetherian rings
and infinite enumerated sets and metric spaces)
sage: M.base_ring() # needs sage.modules
Integer Ring

Expand Down
7 changes: 5 additions & 2 deletions src/sage/categories/morphism.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,12 @@ cdef class Morphism(Map):
sage: f.category()
Category of endsets of unital magmas and right modules over
(Dedekind domains and euclidean domains
and noetherian rings
and infinite enumerated sets and metric spaces)
and left modules over
(Dedekind domains and euclidean domains
and noetherian rings
and infinite enumerated sets and metric spaces)
and left modules over (Dedekind domains and euclidean domains
and infinite enumerated sets and metric spaces)

sage: # needs sage.rings.number_field
sage: K = CyclotomicField(12)
Expand Down
Loading
Loading