Skip to content

Commit 67e1892

Browse files
author
Release Manager
committed
gh-38767: polynomials/fix category We put polynomials (and friends) into the category of algebras with basis. Dependencies: #38729 URL: #38767 Reported by: Martin Rubey Reviewer(s): Travis Scrimshaw
2 parents 2b3b9e9 + 6a5aece commit 67e1892

13 files changed

+104
-41
lines changed

src/sage/categories/additive_magmas.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,8 @@ def extra_super_categories(self):
971971
[Category of unital magmas]
972972
973973
sage: C.super_categories()
974-
[Category of unital algebras with basis over Rational Field,
975-
Category of additive magma algebras over Rational Field]
974+
[Category of additive magma algebras over Rational Field,
975+
Category of unital algebras with basis over Rational Field]
976976
"""
977977
from sage.categories.magmas import Magmas
978978
return [Magmas().Unital()]

src/sage/categories/algebra_functor.py

-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@
128128
Category of semigroup algebras over Rational Field,
129129
...
130130
Category of unital magma algebras over Rational Field,
131-
...
132131
Category of magma algebras over Rational Field,
133132
...
134133
Category of set algebras over Rational Field,

src/sage/categories/map.pyx

+5-3
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,11 @@ cdef class Map(Element):
655655
sage: f = R.hom([x+y, x-y], R)
656656
sage: f.category_for()
657657
Join of Category of unique factorization domains
658-
and Category of commutative algebras
659-
over (number fields and quotient fields and metric spaces)
660-
and Category of infinite sets
658+
and Category of algebras with basis over
659+
(number fields and quotient fields and metric spaces)
660+
and Category of commutative algebras over
661+
(number fields and quotient fields and metric spaces)
662+
and Category of infinite sets
661663
sage: f.category()
662664
Category of endsets of unital magmas
663665
and right modules over (number fields and quotient fields and metric spaces)

src/sage/categories/modules.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ def __init_extra__(self):
893893
(Vector space of dimension 2 over Rational Field,
894894
Univariate Polynomial Ring in x over Rational Field)
895895
sage: A.category() # needs sage.modules
896-
Category of Cartesian products of vector spaces
896+
Category of Cartesian products of vector spaces with basis
897897
over (number fields and quotient fields and metric spaces)
898898
sage: A.base_ring() # needs sage.modules
899899
Rational Field

src/sage/interfaces/tab_completion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def completions(s, globs):
7171
sage: import sage.interfaces.tab_completion as s
7272
sage: p = x**2 + 1
7373
sage: s.completions('p.co',globals()) # indirect doctest
74-
['p.coefficients',...]
74+
['p.coefficient',...]
7575
7676
sage: s.completions('dic',globals()) # indirect doctest
7777
['dickman_rho', 'dict']

src/sage/rings/lazy_series_ring.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1488,10 +1488,14 @@ def __init__(self, base_ring, names, sparse=True, category=None):
14881488
sage: TestSuite(L).run() # needs sage.libs.singular
14891489
sage: L.category()
14901490
Category of infinite commutative no zero divisors algebras over
1491-
(unique factorization domains and commutative algebras over
1491+
(unique factorization domains and algebras with basis over
14921492
(Dedekind domains and euclidean domains
1493-
and noetherian rings
1494-
and infinite enumerated sets and metric spaces)
1493+
and noetherian rings
1494+
and infinite enumerated sets and metric spaces)
1495+
and commutative algebras over
1496+
(Dedekind domains and euclidean domains
1497+
and noetherian rings
1498+
and infinite enumerated sets and metric spaces)
14951499
and infinite sets)
14961500
14971501
sage: L = LazyLaurentSeriesRing(GF(5), 't')

src/sage/rings/polynomial/laurent_polynomial_ring.py

+31-7
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ def __init__(self, R):
445445
if R.ngens() != 1:
446446
raise ValueError("must be 1 generator")
447447
LaurentPolynomialRing_generic.__init__(self, R)
448+
from sage.rings.integer_ring import IntegerRing
449+
self._indices = IntegerRing()
448450

449451
Element = LaurentPolynomial_univariate
450452

@@ -561,6 +563,12 @@ def _element_constructor_(self, x):
561563

562564
return self.element_class(self, x)
563565

566+
def monomial(self, arg):
567+
r"""
568+
Return the monomial with the given exponent.
569+
"""
570+
return self.element_class(self, {arg: self.base_ring().one()})
571+
564572
def __reduce__(self):
565573
"""
566574
Used in pickling.
@@ -591,6 +599,9 @@ def __init__(self, R):
591599
if not R.base_ring().is_integral_domain():
592600
raise ValueError("base ring must be an integral domain")
593601
LaurentPolynomialRing_generic.__init__(self, R)
602+
from sage.modules.free_module import FreeModule
603+
from sage.rings.integer_ring import IntegerRing
604+
self._indices = FreeModule(IntegerRing(), R.ngens())
594605

595606
Element = LazyImport('sage.rings.polynomial.laurent_polynomial_mpair', 'LaurentPolynomial_mpair')
596607

@@ -605,7 +616,7 @@ def _repr_(self):
605616
"""
606617
return "Multivariate Laurent Polynomial Ring in %s over %s" % (", ".join(self._R.variable_names()), self._R.base_ring())
607618

608-
def monomial(self, *args):
619+
def monomial(self, *exponents):
609620
r"""
610621
Return the monomial whose exponents are given in argument.
611622
@@ -629,14 +640,27 @@ def monomial(self, *args):
629640
sage: L.monomial(1, 2, 3) # needs sage.modules
630641
Traceback (most recent call last):
631642
...
632-
TypeError: tuple key must have same length as ngens
633-
"""
634-
if len(args) != self.ngens():
635-
raise TypeError("tuple key must have same length as ngens")
643+
TypeError: tuple key (1, 2, 3) must have same length as ngens (= 2)
644+
645+
We also allow to specify the exponents in a single tuple::
646+
647+
sage: L.monomial((-1, 2)) # needs sage.modules
648+
x0^-1*x1^2
636649
650+
sage: L.monomial((-1, 2, 3)) # needs sage.modules
651+
Traceback (most recent call last):
652+
...
653+
TypeError: tuple key (-1, 2, 3) must have same length as ngens (= 2)
654+
"""
637655
from sage.rings.polynomial.polydict import ETuple
638-
m = ETuple(args, int(self.ngens()))
639-
return self.element_class(self, self.polynomial_ring().one(), m)
656+
if len(exponents) == 1 and isinstance((e := exponents[0]), (tuple, ETuple)):
657+
exponents = e
658+
659+
if len(exponents) != self.ngens():
660+
raise TypeError(f"tuple key {exponents} must have same length as ngens (= {self.ngens()})")
661+
662+
m = ETuple(exponents, int(self.ngens()))
663+
return self.element_class(self, self.polynomial_ring().base_ring().one(), m)
640664

641665
def _element_constructor_(self, x, mon=None):
642666
"""

src/sage/rings/polynomial/laurent_polynomial_ring_base.py

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class LaurentPolynomialRing_generic(CommutativeRing, Parent):
4242
sage: R.<x1,x2> = LaurentPolynomialRing(QQ)
4343
sage: R.category()
4444
Join of Category of unique factorization domains
45+
and Category of algebras with basis
46+
over (number fields and quotient fields and metric spaces)
4547
and Category of commutative algebras
4648
over (number fields and quotient fields and metric spaces)
4749
and Category of infinite sets

src/sage/rings/polynomial/multi_polynomial_ring_base.pxd

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from sage.structure.parent cimport Parent
44
cdef class MPolynomialRing_base(CommutativeRing):
55
cdef object _ngens
66
cdef object _term_order
7+
cdef public object _indices
78
cdef public object _has_singular
89
cdef public object _magma_gens
910
cdef public dict _magma_cache

src/sage/rings/polynomial/multi_polynomial_ring_base.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ cdef class MPolynomialRing_base(CommutativeRing):
9999
else:
100100
category = polynomial_default_category(base_ring.category(), n)
101101
Ring.__init__(self, base_ring, names, category=category)
102+
from sage.combinat.integer_vector import IntegerVectors
103+
self._indices = IntegerVectors(self._ngens)
102104

103105
def is_integral_domain(self, proof=True):
104106
"""

src/sage/rings/polynomial/polynomial_ring.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,25 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None,
256256
257257
sage: category(ZZ['x'])
258258
Join of Category of unique factorization domains
259+
and Category of algebras with basis over
260+
(Dedekind domains and euclidean domains
261+
and noetherian rings and infinite enumerated sets
262+
and metric spaces)
259263
and Category of commutative algebras over
260264
(Dedekind domains and euclidean domains
261265
and noetherian rings and infinite enumerated sets
262266
and metric spaces)
263267
and Category of infinite sets
268+
264269
sage: category(GF(7)['x'])
265270
Join of Category of euclidean domains
266-
and Category of commutative algebras over
267-
(finite enumerated fields and subquotients of monoids and quotients of semigroups) and Category of infinite sets
271+
and Category of algebras with basis over
272+
(finite enumerated fields and subquotients of monoids
273+
and quotients of semigroups)
274+
and Category of commutative algebras over
275+
(finite enumerated fields and subquotients of monoids
276+
and quotients of semigroups)
277+
and Category of infinite sets
268278
269279
TESTS:
270280
@@ -314,6 +324,8 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None,
314324
self.__cyclopoly_cache = {}
315325
self._has_singular = False
316326
Ring.__init__(self, base_ring, names=name, normalize=True, category=category)
327+
from sage.rings.semirings.non_negative_integer_semiring import NonNegativeIntegerSemiring
328+
self._indices = NonNegativeIntegerSemiring()
317329
self._populate_coercion_lists_(convert_method_name='_polynomial_')
318330

319331
def __reduce__(self):

src/sage/rings/polynomial/polynomial_ring_constructor.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -916,23 +916,30 @@ def polynomial_default_category(base_ring_category, n_variables):
916916
EXAMPLES::
917917
918918
sage: from sage.rings.polynomial.polynomial_ring_constructor import polynomial_default_category
919-
sage: polynomial_default_category(Rings(),1) is Algebras(Rings()).Infinite()
919+
sage: polynomial_default_category(Rings(), 1)
920+
Category of infinite algebras with basis over rings
921+
sage: polynomial_default_category(Rings().Commutative(), 1)
922+
Category of infinite commutative algebras with basis
923+
over commutative rings
924+
sage: polynomial_default_category(Fields(), 1)
925+
Join of Category of euclidean domains
926+
and Category of algebras with basis over fields
927+
and Category of commutative algebras over fields
928+
and Category of infinite sets
929+
sage: polynomial_default_category(Fields(), 2)
930+
Join of Category of unique factorization domains
931+
and Category of algebras with basis over fields
932+
and Category of commutative algebras over fields
933+
and Category of infinite sets
934+
935+
sage: QQ['t'].category() is EuclideanDomains() & CommutativeAlgebras(QQ.category()).WithBasis().Infinite()
920936
True
921-
sage: polynomial_default_category(Rings().Commutative(),1) is Algebras(Rings().Commutative()).Commutative().Infinite()
937+
sage: QQ['s','t'].category() is UniqueFactorizationDomains() & CommutativeAlgebras(QQ.category()).WithBasis().Infinite()
922938
True
923-
sage: polynomial_default_category(Fields(),1) is EuclideanDomains() & Algebras(Fields()).Infinite()
924-
True
925-
sage: polynomial_default_category(Fields(),2) is UniqueFactorizationDomains() & CommutativeAlgebras(Fields()).Infinite()
926-
True
927-
928-
sage: QQ['t'].category() is EuclideanDomains() & CommutativeAlgebras(QQ.category()).Infinite()
929-
True
930-
sage: QQ['s','t'].category() is UniqueFactorizationDomains() & CommutativeAlgebras(QQ.category()).Infinite()
931-
True
932-
sage: QQ['s']['t'].category() is UniqueFactorizationDomains() & CommutativeAlgebras(QQ['s'].category()).Infinite()
939+
sage: QQ['s']['t'].category() is UniqueFactorizationDomains() & CommutativeAlgebras(QQ['s'].category()).WithBasis().Infinite()
933940
True
934941
"""
935-
category = Algebras(base_ring_category)
942+
category = Algebras(base_ring_category).WithBasis()
936943

937944
if n_variables:
938945
# here we assume the base ring to be nonzero
@@ -1034,4 +1041,4 @@ def BooleanPolynomialRing_constructor(n=None, names=None, order='lex'):
10341041

10351042
############################################################################
10361043
# END (Factory function for making polynomial rings)
1037-
############################################################################
1044+
############################################################################

src/sage/rings/ring.pyx

+17-7
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ cdef class Ring(ParentWithGens):
155155
Running the test suite of self.an_element()
156156
running ._test_category() . . . pass
157157
running ._test_eq() . . . pass
158+
running ._test_monomial_coefficients() . . . pass
158159
running ._test_new() . . . pass
159160
running ._test_nonzero_equal() . . . pass
160161
running ._test_not_implemented_methods() . . . pass
@@ -184,20 +185,29 @@ cdef class Ring(ParentWithGens):
184185
Test against another bug fixed in :issue:`9944`::
185186
186187
sage: QQ['x'].category()
187-
Join of Category of euclidean domains and Category of commutative algebras over
188-
(number fields and quotient fields and metric spaces) and Category of infinite sets
188+
Join of Category of euclidean domains
189+
and Category of algebras with basis
190+
over (number fields and quotient fields and metric spaces)
191+
and Category of commutative algebras
192+
over (number fields and quotient fields and metric spaces)
193+
and Category of infinite sets
189194
sage: QQ['x','y'].category()
190195
Join of Category of unique factorization domains
196+
and Category of algebras with basis
197+
over (number fields and quotient fields and metric spaces)
191198
and Category of commutative algebras
192199
over (number fields and quotient fields and metric spaces)
193200
and Category of infinite sets
194201
sage: PolynomialRing(MatrixSpace(QQ, 2),'x').category() # needs sage.modules
195-
Category of infinite algebras over (finite dimensional algebras with basis over
196-
(number fields and quotient fields and metric spaces) and infinite sets)
202+
Category of infinite algebras with basis
203+
over (finite dimensional algebras with basis
204+
over (number fields and quotient fields and metric spaces)
205+
and infinite sets)
197206
sage: PolynomialRing(SteenrodAlgebra(2),'x').category() # needs sage.combinat sage.modules
198-
Category of infinite algebras over (super Hopf algebras with basis
199-
over Finite Field of size 2 and supercocommutative super coalgebras
200-
over Finite Field of size 2)
207+
Category of infinite algebras with basis
208+
over (super Hopf algebras with basis over Finite Field of size 2
209+
and supercocommutative super coalgebras
210+
over Finite Field of size 2)
201211
202212
TESTS::
203213

0 commit comments

Comments
 (0)