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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 5 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 3 deletions
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

Lines changed: 31 additions & 7 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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
"""

0 commit comments

Comments
 (0)