Skip to content

Commit a451b65

Browse files
author
Release Manager
committed
gh-37341: Avoid algebra in polynomials One avoids using `Algebra` and `CommutativeAlgebra` in the polynomial classes. And the general method `is_commutative` is delegated to the categories of Rings and CommutativeRings. ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [x] I have updated the documentation accordingly. URL: #37341 Reported by: Frédéric Chapoton Reviewer(s): Martin Rubey
2 parents 57a404c + 53b69df commit a451b65

File tree

7 files changed

+47
-30
lines changed

7 files changed

+47
-30
lines changed

src/sage/categories/commutative_rings.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ class CommutativeRings(CategoryWithAxiom):
4747
4848
"""
4949
class ParentMethods:
50+
def is_commutative(self) -> bool:
51+
"""
52+
Return whether the ring is commutative.
53+
54+
The answer is ``True`` only if the category is a sub-category of
55+
``CommutativeRings``.
56+
57+
It is recommended to use instead ``R in Rings().Commutative()``.
58+
59+
EXAMPLES::
60+
61+
sage: QQ.is_commutative()
62+
True
63+
sage: QQ['x,y,z'].is_commutative()
64+
True
65+
"""
66+
return True
67+
5068
def _test_divides(self, **options):
5169
r"""
5270
Run generic tests on the method :meth:`divides`.

src/sage/categories/rings.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,23 @@ def is_ring(self) -> bool:
322322
"""
323323
return True
324324

325+
def is_commutative(self) -> bool:
326+
"""
327+
Return whether the ring is commutative.
328+
329+
The answer is ``True`` only if the category is a sub-category of
330+
``CommutativeRings``.
331+
332+
It is recommended to use instead ``R in Rings().Commutative()``.
333+
334+
EXAMPLES::
335+
336+
sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -1, -1) # needs sage.combinat sage.modules
337+
sage: Q.is_commutative() # needs sage.combinat sage.modules
338+
False
339+
"""
340+
return False
341+
325342
def is_zero(self) -> bool:
326343
"""
327344
Return ``True`` if this is the zero ring.

src/sage/graphs/chrompoly.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ from memory_allocator cimport MemoryAllocator
3131
from sage.libs.gmp.mpz cimport *
3232
from sage.rings.integer_ring import ZZ
3333
from sage.rings.integer cimport Integer
34-
from sage.rings.ring cimport Algebra
34+
from sage.rings.ring cimport Ring
3535
from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint
3636
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
3737

@@ -436,7 +436,7 @@ def chromatic_polynomial_with_cache(G, cache=None):
436436
...
437437
TypeError: parameter cache must be a dictionary or None
438438
"""
439-
cdef Algebra R = PolynomialRing(ZZ, "x", implementation="FLINT")
439+
cdef Ring R = PolynomialRing(ZZ, "x", implementation="FLINT")
440440
cdef Polynomial_integer_dense_flint one = R.one()
441441
cdef Polynomial_integer_dense_flint zero = R.zero()
442442
cdef Polynomial_integer_dense_flint x = R.gen()

src/sage/rings/polynomial/polynomial_ring.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@
130130
131131
"""
132132

133-
#*****************************************************************************
133+
# ****************************************************************************
134134
# Copyright (C) 2006 William Stein <[email protected]>
135135
#
136136
# This program is free software: you can redistribute it and/or modify
137137
# it under the terms of the GNU General Public License as published by
138138
# the Free Software Foundation, either version 2 of the License, or
139139
# (at your option) any later version.
140-
# http://www.gnu.org/licenses/
141-
#*****************************************************************************
140+
# https://www.gnu.org/licenses/
141+
# ****************************************************************************
142142

143143

144144
import sys
@@ -148,7 +148,7 @@
148148
import sage.categories as categories
149149
from sage.categories.morphism import IdentityMorphism
150150

151-
from sage.rings.ring import (Algebra, CommutativeAlgebra, IntegralDomain,
151+
from sage.rings.ring import (Ring, IntegralDomain,
152152
PrincipalIdealDomain, is_Ring)
153153
from sage.structure.element import is_RingElement
154154
import sage.rings.rational_field as rational_field
@@ -226,7 +226,7 @@ def is_PolynomialRing(x):
226226

227227
#########################################################################################
228228

229-
class PolynomialRing_general(Algebra):
229+
class PolynomialRing_general(Ring):
230230
"""
231231
Univariate polynomial ring over a ring.
232232
"""
@@ -303,7 +303,7 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None,
303303
self.Element = self._polynomial_class
304304
self.__cyclopoly_cache = {}
305305
self._has_singular = False
306-
Algebra.__init__(self, base_ring, names=name, normalize=True, category=category)
306+
Ring.__init__(self, base_ring, names=name, normalize=True, category=category)
307307
self._populate_coercion_lists_(convert_method_name='_polynomial_')
308308

309309
def __reduce__(self):
@@ -1709,7 +1709,7 @@ def monics( self, of_degree=None, max_degree=None ):
17091709
raise ValueError("you should pass exactly one of of_degree and max_degree")
17101710

17111711

1712-
class PolynomialRing_commutative(PolynomialRing_general, CommutativeAlgebra):
1712+
class PolynomialRing_commutative(PolynomialRing_general):
17131713
"""
17141714
Univariate polynomial ring over a commutative ring.
17151715
"""

src/sage/rings/ring.pyx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -686,24 +686,6 @@ cdef class Ring(ParentWithGens):
686686
return x
687687
return self._one_element
688688

689-
def is_commutative(self):
690-
"""
691-
Return ``True`` if this ring is commutative.
692-
693-
EXAMPLES::
694-
695-
sage: QQ.is_commutative()
696-
True
697-
sage: QQ['x,y,z'].is_commutative()
698-
True
699-
sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -1, -1) # needs sage.combinat sage.modules
700-
sage: Q.is_commutative() # needs sage.combinat sage.modules
701-
False
702-
"""
703-
if self.is_zero():
704-
return True
705-
raise NotImplementedError
706-
707689
def is_field(self, proof = True):
708690
"""
709691
Return ``True`` if this ring is a field.

src/sage/structure/element.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,11 +2655,11 @@ cdef class RingElement(ModuleElement):
26552655

26562656
cpdef _pow_int(self, n) noexcept:
26572657
"""
2658-
Return the (integral) power of self.
2658+
Return the (integral) power of ``self``.
26592659
26602660
EXAMPLES::
26612661
2662-
sage: a = Integers(389)['x']['y'](37)
2662+
sage: a = GF(389)['x']['y'](37)
26632663
sage: p = sage.structure.element.RingElement.__pow__
26642664
sage: p(a,2)
26652665
202

src/sage/tests/books/computational-mathematics-with-sagemath/polynomes_doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
sage: (t^2+t)/t
121121
Traceback (most recent call last):
122122
...
123-
TypeError: self must be an integral domain.
123+
TypeError: unsupported operand parent(s) for /: 'Univariate Polynomial Ring in t over Ring of integers modulo 42' and 'Univariate Polynomial Ring in t over Ring of integers modulo 42'
124124
125125
Sage example in ./polynomes.tex, line 685::
126126

0 commit comments

Comments
 (0)