Skip to content

Commit

Permalink
Merge branch 'polynomials/monomial_coefficients' into lazy_series/pus…
Browse files Browse the repository at this point in the history
…hout_experiment
  • Loading branch information
mantepse committed Sep 30, 2024
2 parents d38dd0a + 9a37e27 commit 7023cc6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/sage/rings/polynomial/multi_polynomial_ring_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ from sage.rings.polynomial import polynomial_ring
from sage.rings.polynomial.term_order import TermOrder
from sage.rings.polynomial.polynomial_ring_constructor import (PolynomialRing,
polynomial_default_category)
from sage.rings.polynomial.polydict import ETuple


def is_MPolynomialRing(x):
Expand Down Expand Up @@ -617,7 +618,6 @@ cdef class MPolynomialRing_base(CommutativeRing):
a dict with respect to ``self.variable_names()``.
"""
# This is probably horribly inefficient
from sage.rings.polynomial.polydict import ETuple
other_vars = list(x.parent().variable_names())
name_mapping = [(other_vars.index(var) if var in other_vars else -1) for var in self.variable_names()]
K = self.base_ring()
Expand Down Expand Up @@ -1376,9 +1376,17 @@ cdef class MPolynomialRing_base(CommutativeRing):
sage: R.monomial(e)
x*y^2*z^3
TESTS:
Check that ETuples also work::
sage: from sage.rings.polynomial.polydict import ETuple
sage: R.monomial(ETuple(e))
x*y^2*z^3
"""
if len(exponents) == 1 and isinstance(exponents[0], tuple):
return self({exponents[0]: self.base_ring().one()})
if len(exponents) == 1 and isinstance((e := exponents[0]), (tuple, ETuple)):
return self({e: self.base_ring().one()})
return self({exponents: self.base_ring().one()})

def monomials_of_degree(self, degree):
Expand Down

0 comments on commit 7023cc6

Please sign in to comment.