From 12fc4bca0610fc89dd36c01051ee80f666f70668 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Sat, 6 Apr 2024 23:49:51 +0200 Subject: [PATCH 01/19] return numerator and denominator as elements of self, restrict element_constructor, fix coefficients --- .../polynomial/infinite_polynomial_element.py | 68 +++++++++++-------- .../polynomial/infinite_polynomial_ring.py | 2 +- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index b135404a020..03f6f83673c 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -560,6 +560,14 @@ def is_nilpotent(self): """ return self._p.is_nilpotent() + def numerator(self): + P = self.parent() + return InfinitePolynomial(P, self._p.numerator()) + + def denominator(self): + P = self.parent() + return InfinitePolynomial(P, self._p.denominator()) + @cached_method def variables(self): """ @@ -1018,42 +1026,42 @@ def coefficient(self, monomial): 2 """ + P = self.parent() if self._p == 0: - res = 0 - elif isinstance(monomial, self.__class__): - if not (self.parent().has_coerce_map_from(monomial.parent())): - res = 0 + return P.zero() + if isinstance(monomial, self.__class__): + if not (P.has_coerce_map_from(monomial.parent())): + return P.zero() + if hasattr(self._p, 'variables'): + VarList = [str(X) for X in self._p.variables()] else: - if hasattr(self._p, 'variables'): - VarList = [str(X) for X in self._p.variables()] - else: - VarList = [] - if hasattr(monomial._p, 'variables'): - VarList.extend([str(X) for X in monomial._p.variables()]) - VarList = list(set(VarList)) - VarList.sort(key=self.parent().varname_key, reverse=True) - from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing - if len(VarList) == 1: - # 'xx' is guaranteed to be no variable - # name of monomial, since coercions - # were tested before - R = PolynomialRing(self._p.base_ring(), VarList + ['xx'], order=self.parent()._order) - - res = PolynomialRing(self._p.base_ring(), VarList, order=self.parent()._order)(R(self._p).coefficient(R(monomial._p))) - else: - R = PolynomialRing(self._p.base_ring(), VarList, order=self.parent()._order) - res = R(self._p).coefficient(R(monomial._p)) - elif isinstance(monomial, dict): + VarList = [] + if hasattr(monomial._p, 'variables'): + VarList.extend([str(X) for X in monomial._p.variables()]) + VarList = list(set(VarList)) + VarList.sort(key=P.varname_key, reverse=True) + from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing + if len(VarList) == 1: + # 'xx' is guaranteed to be no variable + # name of monomial, since coercions + # were tested before + R = PolynomialRing(self._p.base_ring(), VarList + ['xx'], order=P._order) + S = PolynomialRing(self._p.base_ring(), VarList, order=P._order) + res = S(R(self._p).coefficient(R(monomial._p))) + return InfinitePolynomial(P, res) + + R = PolynomialRing(self._p.base_ring(), VarList, order=P._order) + res = R(self._p).coefficient(R(monomial._p)) + return InfinitePolynomial(P, res) + + if isinstance(monomial, dict): if monomial: I = iter(monomial) K = next(I) del monomial[K] - res = self.coefficient(K).coefficient(monomial) - else: - return self - else: - raise TypeError("Objects of type %s have no coefficients in InfinitePolynomials" % (type(monomial))) - return self.parent()(res) + return self.coefficient(K).coefficient(monomial) + return self + raise TypeError("Objects of type %s have no coefficients in InfinitePolynomials" % (type(monomial))) # Essentials for Buchberger def reduce(self, I, tailreduce=False, report=None): diff --git a/src/sage/rings/polynomial/infinite_polynomial_ring.py b/src/sage/rings/polynomial/infinite_polynomial_ring.py index dbb71289f89..8e4891613d9 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_ring.py +++ b/src/sage/rings/polynomial/infinite_polynomial_ring.py @@ -922,7 +922,7 @@ def _element_constructor_(self, x): if isinstance(self._base, MPolynomialRing_polydict): x = sage_eval(repr(), next(self.gens_dict())) else: - x = self._base(x) + x = self._base.coerce(x) # remark: Conversion to self._P (if applicable) # is done in InfinitePolynomial() return InfinitePolynomial(self, x) From a0deca48a98f424e7372738694daa7768ec24419 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Sun, 7 Apr 2024 11:37:18 +0200 Subject: [PATCH 02/19] add docstring to numerator, remove wrong denominator method (the inherited method is correct) --- .../polynomial/infinite_polynomial_element.py | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index 03f6f83673c..8aa310c20de 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -561,12 +561,32 @@ def is_nilpotent(self): return self._p.is_nilpotent() def numerator(self): - P = self.parent() - return InfinitePolynomial(P, self._p.numerator()) + r""" + Return a numerator of ``self``, computed as ``self * self.denominator()``. + + Note that some subclasses may implement its own numerator + function. + + .. warning:: + + This is not the numerator of the rational function + defined by ``self``, which would always be self since ``self`` is a + polynomial. + + EXAMPLES: - def denominator(self): + sage: X. = InfinitePolynomialRing(QQ) + sage: p = 2/3*x[1] + 4/9*x[2] - 2*x[1]*x[3] + sage: num = p.numerator(); num + -18*x_3*x_1 + 4*x_2 + 6*x_1 + + TESTS:: + + sage: num.parent() + Infinite polynomial ring in x over Rational Field + """ P = self.parent() - return InfinitePolynomial(P, self._p.denominator()) + return InfinitePolynomial(P, self._p.numerator()) @cached_method def variables(self): From 690e048d6c846587103591acc56fa478495b747b Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Wed, 3 Apr 2024 13:24:32 +0200 Subject: [PATCH 03/19] remove workaround and fix InfinitePolynomialRing instead --- .../rings/polynomial/infinite_polynomial_element.py | 11 ++++++++++- src/sage/rings/polynomial/infinite_polynomial_ring.py | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index 8aa310c20de..b48d22a9f1d 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -606,9 +606,18 @@ def variables(self): """ if hasattr(self._p, 'variables'): - return tuple(self._p.variables()) + P = self.parent() + return tuple(InfinitePolynomial(P, v) for v in self._p.variables()) return () + @cached_method + def monomials(self): + P = self.parent() + return [InfinitePolynomial(P, m) for m in self._p.monomials()] + + def monomial_coefficient(self, mon): + return self._p.monomial_coefficient(mon._p) + @cached_method def max_index(self): r""" diff --git a/src/sage/rings/polynomial/infinite_polynomial_ring.py b/src/sage/rings/polynomial/infinite_polynomial_ring.py index 8e4891613d9..169978acf95 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_ring.py +++ b/src/sage/rings/polynomial/infinite_polynomial_ring.py @@ -279,8 +279,8 @@ class InfinitePolynomialRingFactory(UniqueFactory): """ A factory for creating infinite polynomial ring elements. It - handles making sure that they are unique as well as handling - pickling. For more details, see + makes sure that they are unique as well as handling pickling. + For more details, see :class:`~sage.structure.factory.UniqueFactory` and :mod:`~sage.rings.polynomial.infinite_polynomial_ring`. From 6d4659c22512310a2ad69f610c483bc7d33995e2 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Wed, 3 Apr 2024 13:48:40 +0200 Subject: [PATCH 04/19] add documentation and tests, remove cached_method --- .../polynomial/infinite_polynomial_element.py | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index b48d22a9f1d..fba15b886c2 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -610,12 +610,64 @@ def variables(self): return tuple(InfinitePolynomial(P, v) for v in self._p.variables()) return () - @cached_method def monomials(self): + """ + Return the list of monomials in self. The returned list is + decreasingly ordered by the term ordering of + ``self.parent()``. + + EXAMPLES:: + + sage: X. = InfinitePolynomialRing(QQ) + sage: p = x[1]^3 + x[2] - 2*x[1]*x[3] + sage: p.monomials() + [x_3*x_1, x_2, x_1^3] + + sage: X. = InfinitePolynomialRing(QQ, order='deglex') + sage: p = x[1]^3 + x[2] - 2*x[1]*x[3] + sage: p.monomials() + [x_1^3, x_3*x_1, x_2] + """ P = self.parent() return [InfinitePolynomial(P, m) for m in self._p.monomials()] def monomial_coefficient(self, mon): + """ + Return the coefficient in the base ring of the monomial mon in + ``self``, where mon must have the same parent as self. + + This function contrasts with the function ``coefficient`` + which returns the coefficient of a monomial viewing this + polynomial in a polynomial ring over a base ring having fewer + variables. + + INPUT: + + - ``mon`` - a monomial + + OUTPUT: + + coefficient in base ring + + .. SEEALSO:: + + For coefficients in a base ring of fewer variables, + look at ``coefficient``. + + EXAMPLES:: + + sage: X. = InfinitePolynomialRing(QQ) + sage: f = 2*x[0]*x[2] + 3*x[1]^2 + sage: c = f.monomial_coefficient(x[1]^2); c + 3 + sage: c.parent() + Rational Field + + sage: c = f.coefficient(x[2]); c + 2*x_0 + sage: c.parent() + Infinite polynomial ring in x over Rational Field + """ return self._p.monomial_coefficient(mon._p) @cached_method From 0fe5270a2c1e3428e61f4c7ba572839de91d6b11 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Sun, 7 Apr 2024 11:54:35 +0200 Subject: [PATCH 05/19] add doctest, fix linter --- .../rings/polynomial/infinite_polynomial_ring.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_ring.py b/src/sage/rings/polynomial/infinite_polynomial_ring.py index 169978acf95..0d3af0e9bf4 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_ring.py +++ b/src/sage/rings/polynomial/infinite_polynomial_ring.py @@ -19,7 +19,7 @@ - ``R``, the base ring. It has to be a commutative ring, and in some applications it must even be a field -- ``names``, a finite list of generator names. Generator names must be alpha-numeric. +- ``names``, a finite list of generator names. Generator names must be alphanumeric. - ``order`` (optional string). The default order is ``'lex'`` (lexicographic). ``'deglex'`` is degree lexicographic, and ``'degrevlex'`` (degree reverse lexicographic) is possible but discouraged. @@ -566,7 +566,7 @@ def __init__(self, parent, start): def __next__(self): """ - Return a dictionary that can be used to interprete strings in the base ring of ``self``. + Return a dictionary that can be used to interpret strings in the base ring of ``self``. EXAMPLES:: @@ -704,7 +704,7 @@ def __init__(self, R, names, order): names = ['x'] for n in names: if not (isinstance(n, str) and n.isalnum() and (not n[0].isdigit())): - raise ValueError("generator names must be alpha-numeric strings not starting with a digit, but %s is not" % n) + raise ValueError("generator names must be alphanumeric strings not starting with a digit, but %s is not" % n) if len(names) != len(set(names)): raise ValueError("generator names must be pairwise different") self._names = tuple(names) @@ -888,6 +888,15 @@ def _element_constructor_(self, x): Traceback (most recent call last): ... ValueError: cannot convert 1/3 into an element of Infinite polynomial ring in x over Integer Ring + + Check that :issue:`37756` is fixed:: + + sage: L. = QQ[] + sage: R. = InfinitePolynomialRing(QQ) + sage: M = InfinitePolynomialRing(L, names=["a"]) + sage: c = a[0] + sage: M(c) + a_0 """ from sage.rings.polynomial.infinite_polynomial_element import InfinitePolynomial # In many cases, the easiest solution is to "simply" evaluate From 064d6ba536d9b998f2d49673abef8982b6763868 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Sun, 7 Apr 2024 11:57:43 +0200 Subject: [PATCH 06/19] add doctest for coercion issue --- .../rings/polynomial/infinite_polynomial_element.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index fba15b886c2..be383e381f5 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -584,6 +584,16 @@ def numerator(self): sage: num.parent() Infinite polynomial ring in x over Rational Field + + Check that :issue:`37756` is fixed:: + + sage: R. = InfinitePolynomialRing(QQ) + sage: P. = QQ[] + sage: FF = P.fraction_field() + sage: FF(a[0]) + Traceback (most recent call last): + ... + TypeError: Could not find a mapping of the passed element to this ring. """ P = self.parent() return InfinitePolynomial(P, self._p.numerator()) From 7b49ae12d4f54a1aee47df3ee9dad73b657a9d14 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Sun, 7 Apr 2024 20:57:01 +0200 Subject: [PATCH 07/19] Fix missing backticks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matthias Köppe --- src/sage/rings/polynomial/infinite_polynomial_element.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index be383e381f5..0ca5cdfed55 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -622,8 +622,9 @@ def variables(self): def monomials(self): """ - Return the list of monomials in self. The returned list is - decreasingly ordered by the term ordering of + Return the list of monomials in ``self``. + + The returned list is decreasingly ordered by the term ordering of ``self.parent()``. EXAMPLES:: From a36aac5e8b7ff3a6cfd0617a5e93346261d87671 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Sun, 7 Apr 2024 20:58:08 +0200 Subject: [PATCH 08/19] Fix missing backticks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matthias Köppe --- src/sage/rings/polynomial/infinite_polynomial_element.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index 0ca5cdfed55..306ad66de36 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -570,7 +570,7 @@ def numerator(self): .. warning:: This is not the numerator of the rational function - defined by ``self``, which would always be self since ``self`` is a + defined by ``self``, which would always be ``self`` since it is a polynomial. EXAMPLES: From b128a60c31ccb62a6db77f374d1f49544967960b Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Sun, 7 Apr 2024 21:14:26 +0200 Subject: [PATCH 09/19] remove misleading sentence and whitespace --- src/sage/rings/polynomial/infinite_polynomial_element.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index 306ad66de36..ac507fc2aa2 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -564,9 +564,6 @@ def numerator(self): r""" Return a numerator of ``self``, computed as ``self * self.denominator()``. - Note that some subclasses may implement its own numerator - function. - .. warning:: This is not the numerator of the rational function @@ -622,8 +619,8 @@ def variables(self): def monomials(self): """ - Return the list of monomials in ``self``. - + Return the list of monomials in ``self``. + The returned list is decreasingly ordered by the term ordering of ``self.parent()``. From 8015042510adff40bad70a635cb9f6351cf21201 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Sun, 7 Apr 2024 21:55:31 +0200 Subject: [PATCH 10/19] add missing colon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matthias Köppe --- src/sage/rings/polynomial/infinite_polynomial_element.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index ac507fc2aa2..6ae25934f21 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -570,7 +570,7 @@ def numerator(self): defined by ``self``, which would always be ``self`` since it is a polynomial. - EXAMPLES: + EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) sage: p = 2/3*x[1] + 4/9*x[2] - 2*x[1]*x[3] From 385ee8c3a673b80b5ab2d62d1fcc37f8907989a4 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Sun, 7 Apr 2024 22:06:54 +0200 Subject: [PATCH 11/19] use proper sphinx roles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matthias Köppe --- .../polynomial/infinite_polynomial_element.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index 6ae25934f21..729f0f88a28 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -641,26 +641,23 @@ def monomials(self): def monomial_coefficient(self, mon): """ - Return the coefficient in the base ring of the monomial mon in - ``self``, where mon must have the same parent as self. - - This function contrasts with the function ``coefficient`` + Return the base ring element that is the coefficient of ``mon`` in ``self``. + + This function contrasts with the function :meth:`coefficient`, which returns the coefficient of a monomial viewing this polynomial in a polynomial ring over a base ring having fewer variables. INPUT: - - ``mon`` - a monomial - - OUTPUT: + - ``mon`` -- a monomial of the parent of ``self`` - coefficient in base ring + OUTPUT: coefficient in base ring .. SEEALSO:: For coefficients in a base ring of fewer variables, - look at ``coefficient``. + look at :meth:`coefficient`. EXAMPLES:: From 6706a3925a46925e5627bcdb6458c74f3c2db098 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Mon, 8 Apr 2024 09:28:52 +0200 Subject: [PATCH 12/19] remove whitespace --- src/sage/rings/polynomial/infinite_polynomial_element.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index 729f0f88a28..bfa6fd9dbaf 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -642,7 +642,7 @@ def monomials(self): def monomial_coefficient(self, mon): """ Return the base ring element that is the coefficient of ``mon`` in ``self``. - + This function contrasts with the function :meth:`coefficient`, which returns the coefficient of a monomial viewing this polynomial in a polynomial ring over a base ring having fewer From 575731d8ae9d53547e0f51d4ee7987a4feaa8ee8 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Mon, 8 Apr 2024 09:30:37 +0200 Subject: [PATCH 13/19] improve docstring formatting Co-authored-by: Travis Scrimshaw --- src/sage/rings/polynomial/infinite_polynomial_element.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index bfa6fd9dbaf..0470186552c 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -564,7 +564,8 @@ def numerator(self): r""" Return a numerator of ``self``, computed as ``self * self.denominator()``. - .. warning:: + .. WARNING + :: This is not the numerator of the rational function defined by ``self``, which would always be ``self`` since it is a From 97dbbc60822bf4e1cd4919b14e8d80248e2725d3 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Mon, 8 Apr 2024 09:34:32 +0200 Subject: [PATCH 14/19] remove unnecessary parens Co-authored-by: Travis Scrimshaw --- src/sage/rings/polynomial/infinite_polynomial_element.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index 0470186552c..1f6249fec57 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -1117,7 +1117,7 @@ def coefficient(self, monomial): if self._p == 0: return P.zero() if isinstance(monomial, self.__class__): - if not (P.has_coerce_map_from(monomial.parent())): + if not P.has_coerce_map_from(monomial.parent()): return P.zero() if hasattr(self._p, 'variables'): VarList = [str(X) for X in self._p.variables()] From 9b76cf6ee0e8b1561d04b2271c8a1d809516765c Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Mon, 8 Apr 2024 09:36:41 +0200 Subject: [PATCH 15/19] improve docstring --- src/sage/rings/polynomial/infinite_polynomial_element.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index 1f6249fec57..df9e201c12f 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -642,7 +642,8 @@ def monomials(self): def monomial_coefficient(self, mon): """ - Return the base ring element that is the coefficient of ``mon`` in ``self``. + Return the base ring element that is the coefficient of ``mon`` + in ``self``. This function contrasts with the function :meth:`coefficient`, which returns the coefficient of a monomial viewing this @@ -651,7 +652,7 @@ def monomial_coefficient(self, mon): INPUT: - - ``mon`` -- a monomial of the parent of ``self`` + - ``mon`` -- a monomial in the parent of ``self`` OUTPUT: coefficient in base ring @@ -673,6 +674,7 @@ def monomial_coefficient(self, mon): 2*x_0 sage: c.parent() Infinite polynomial ring in x over Rational Field + """ return self._p.monomial_coefficient(mon._p) From 2f607aadcad477051a7fdef0b5ff96eec842198f Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Mon, 8 Apr 2024 10:48:51 +0200 Subject: [PATCH 16/19] fix sphinx role --- src/sage/rings/polynomial/infinite_polynomial_element.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index df9e201c12f..5645c307731 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -564,8 +564,7 @@ def numerator(self): r""" Return a numerator of ``self``, computed as ``self * self.denominator()``. - .. WARNING - :: + .. WARNING:: This is not the numerator of the rational function defined by ``self``, which would always be ``self`` since it is a From 3cdc7addf575a6c1be6991256290d5eb33edf518 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Sat, 27 Jul 2024 21:09:35 +0200 Subject: [PATCH 17/19] revert original fix -- replacing self._base(x) with self._base.coerce(x) -- from 12fc4bca0610 --- src/sage/rings/polynomial/infinite_polynomial_ring.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_ring.py b/src/sage/rings/polynomial/infinite_polynomial_ring.py index 99ce577b416..9965b827783 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_ring.py +++ b/src/sage/rings/polynomial/infinite_polynomial_ring.py @@ -889,13 +889,15 @@ def _element_constructor_(self, x): ... ValueError: cannot convert 1/3 into an element of Infinite polynomial ring in x over Integer Ring - Check that :issue:`37756` is fixed:: + .. WARNING: + + The :issue:`37756` is not yet fixed:: sage: L. = QQ[] sage: R. = InfinitePolynomialRing(QQ) sage: M = InfinitePolynomialRing(L, names=["a"]) sage: c = a[0] - sage: M(c) + sage: M(c) # known bug a_0 """ from sage.rings.polynomial.infinite_polynomial_element import InfinitePolynomial @@ -931,7 +933,7 @@ def _element_constructor_(self, x): if isinstance(self._base, MPolynomialRing_polydict): x = sage_eval(repr(), next(self.gens_dict())) else: - x = self._base.coerce(x) + x = self._base(x) # remark: Conversion to self._P (if applicable) # is done in InfinitePolynomial() return InfinitePolynomial(self, x) From c719db35aa1189c535bd0f561771eb438a9c7bbb Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Tue, 6 Aug 2024 09:58:00 +0200 Subject: [PATCH 18/19] Apply suggestions concerning docstring formatting from code review Co-authored-by: Travis Scrimshaw --- src/sage/rings/polynomial/infinite_polynomial_element.py | 1 - src/sage/rings/polynomial/infinite_polynomial_ring.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index 15ff9a97182..a0f1709fe8b 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -672,7 +672,6 @@ def monomial_coefficient(self, mon): 2*x_0 sage: c.parent() Infinite polynomial ring in x over Rational Field - """ return self._p.monomial_coefficient(mon._p) diff --git a/src/sage/rings/polynomial/infinite_polynomial_ring.py b/src/sage/rings/polynomial/infinite_polynomial_ring.py index 9965b827783..99cc696b637 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_ring.py +++ b/src/sage/rings/polynomial/infinite_polynomial_ring.py @@ -889,11 +889,11 @@ def _element_constructor_(self, x): ... ValueError: cannot convert 1/3 into an element of Infinite polynomial ring in x over Integer Ring - .. WARNING: + .. WARNING:: - The :issue:`37756` is not yet fixed:: + The :issue:`37756` is not yet fixed:: - sage: L. = QQ[] + sage: L. = QQ[] sage: R. = InfinitePolynomialRing(QQ) sage: M = InfinitePolynomialRing(L, names=["a"]) sage: c = a[0] From 79991674925e7306d41e9a21a0c7556f8761932e Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Wed, 7 Aug 2024 12:58:59 +0200 Subject: [PATCH 19/19] indent forgotten lines Co-authored-by: Travis Scrimshaw --- src/sage/rings/polynomial/infinite_polynomial_ring.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_ring.py b/src/sage/rings/polynomial/infinite_polynomial_ring.py index 480541acf58..05735a21cd2 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_ring.py +++ b/src/sage/rings/polynomial/infinite_polynomial_ring.py @@ -890,11 +890,11 @@ def _element_constructor_(self, x): The :issue:`37756` is not yet fixed:: sage: L. = QQ[] - sage: R. = InfinitePolynomialRing(QQ) - sage: M = InfinitePolynomialRing(L, names=["a"]) - sage: c = a[0] - sage: M(c) # known bug - a_0 + sage: R. = InfinitePolynomialRing(QQ) + sage: M = InfinitePolynomialRing(L, names=["a"]) + sage: c = a[0] + sage: M(c) # known bug + a_0 """ from sage.rings.polynomial.infinite_polynomial_element import InfinitePolynomial # In many cases, the easiest solution is to "simply" evaluate