Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancements in infinite polynomial rings #36651

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions src/sage/rings/polynomial/infinite_polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@
try:
if len(L) == 2:
return self._D[L[0]][int(L[1])]
except Exception:
except (TypeError, ValueError):
pass
raise KeyError("%s is not a variable name" % k)

Expand Down Expand Up @@ -614,7 +614,7 @@
return D[k]
except KeyError:
pass
raise KeyError("%s is not a variable name of %s or its iterated base rings" % (k, self._P))
raise KeyError("{} is not a variable name of {} or its iterated base rings".format(k, self._P))


##############################################################
Expand Down Expand Up @@ -739,7 +739,7 @@

# some basic data
self._order = order
self._name_dict = dict([(names[i], i) for i in range(len(names))])
self._name_dict = {name: i for i, name in enumerate(names)}
from sage.categories.commutative_algebras import CommutativeAlgebras
CommutativeRing.__init__(self, R, category=CommutativeAlgebras(R))

Expand All @@ -755,7 +755,7 @@
sage: X.<alpha,beta> = InfinitePolynomialRing(ZZ, order='deglex'); X
Infinite polynomial ring in alpha, beta over Integer Ring
"""
return "Infinite polynomial ring in %s over %s" % (", ".join(self._names), self._base)
return "Infinite polynomial ring in {} over {}".format(", ".join(self._names), self._base)

def _latex_(self):
r"""
Expand All @@ -768,7 +768,7 @@
"""
from sage.misc.latex import latex
vars = ', '.join(latex(X) for X in self.gens())
return "%s[%s]" % (latex(self.base_ring()), vars)
return f"{latex(self.base_ring())}[{vars}]"

@cached_method
def _an_element_(self):
Expand Down Expand Up @@ -856,7 +856,7 @@
# We do not care about the orders. But base ring and generators
# of the pushout should remain the same as in self.
return P._names == self._names and P._base == self._base
except Exception:
except (TypeError, ValueError):
return False

def _element_constructor_(self, x):
Expand Down Expand Up @@ -896,15 +896,15 @@
if isinstance(x, str):
try:
x = sage_eval(x, self.gens_dict())
except Exception:
raise ValueError("cannot convert %s into an element of %s" % (x, self))
except (TypeError, ValueError, SyntaxError):
raise ValueError(f"cannot convert {x} into an element of {self}")

Check warning on line 900 in src/sage/rings/polynomial/infinite_polynomial_ring.py

View check run for this annotation

Codecov / codecov/patch

src/sage/rings/polynomial/infinite_polynomial_ring.py#L899-L900

Added lines #L899 - L900 were not covered by tests
P = parent(x)
if P is self:
return x
elif self._base.has_coerce_map_from(P):
return InfinitePolynomial(self, self._base(x))
else:
raise ValueError("cannot convert %s into an element of %s" % (x, self))
raise ValueError(f"cannot convert {x} into an element of {self}")

if isinstance(parent(x), InfinitePolynomialRing_sparse):
# the easy case - parent == self - is already past
Expand All @@ -926,7 +926,7 @@
# remark: Conversion to self._P (if applicable)
# is done in InfinitePolynomial()
return InfinitePolynomial(self, x)
except Exception:
except (TypeError, ValueError):
pass

# By now, we can assume that x has a parent, because
Expand All @@ -937,8 +937,8 @@
if not hasattr(x, 'variables'):
try:
return sage_eval(repr(x), self.gens_dict())
except Exception:
raise ValueError("cannot convert %s into an element of %s" % (x, self))
except (TypeError, ValueError, SyntaxError):
raise ValueError(f"cannot convert {x} into an element of {self}")

# direct conversion will only be used if the underlying polynomials are libsingular.
from sage.rings.polynomial.multi_polynomial import MPolynomial_libsingular
Expand All @@ -965,7 +965,7 @@
# This tests admissibility on the fly:
VarList.sort(key=self.varname_key, reverse=True)
except ValueError:
raise ValueError("cannot convert %s into an element of %s - variables are not admissible" % (x, self))
raise ValueError("cannot convert {} into an element of {} - variables are not admissible".format(x, self))

Check warning on line 968 in src/sage/rings/polynomial/infinite_polynomial_ring.py

View check run for this annotation

Codecov / codecov/patch

src/sage/rings/polynomial/infinite_polynomial_ring.py#L968

Added line #L968 was not covered by tests
xmaxind = max([int(v.split('_')[1]) for v in VarList])
try:
# Apparently, in libsingular, the polynomial conversion is not done by
Expand All @@ -981,13 +981,13 @@
# conversion to self._P will be done in InfinitePolynomial.__init__
return InfinitePolynomial(self, x)
except (ValueError, TypeError, NameError):
raise ValueError("cannot convert %s (from %s, but variables %s) into an element of %s - no conversion into underlying polynomial ring %s" % (x, x.parent(), x.variables(), self, self._P))
raise ValueError("cannot convert {} (from {}, but variables {}) into an element of {} - no conversion into underlying polynomial ring {}".format(x, x.parent(), x.variables(), self, self._P))

Check warning on line 984 in src/sage/rings/polynomial/infinite_polynomial_ring.py

View check run for this annotation

Codecov / codecov/patch

src/sage/rings/polynomial/infinite_polynomial_ring.py#L984

Added line #L984 was not covered by tests
# By now, x or self._P are not libsingular. Since MPolynomialRing_polydict
# is too buggy, we use string evaluation
try:
return sage_eval(repr(x), self.gens_dict())
except (ValueError, TypeError, NameError):
raise ValueError("cannot convert %s into an element of %s - no conversion into underlying polynomial ring" % (x, self))
raise ValueError("cannot convert {} into an element of {} - no conversion into underlying polynomial ring".format(x, self))

# By now, we are in the sparse case.
try:
Expand All @@ -998,7 +998,7 @@
# This tests admissibility on the fly:
VarList.sort(key=self.varname_key, reverse=True)
except ValueError:
raise ValueError("cannot convert %s into an element of %s - variables are not admissible" % (x, self))
raise ValueError("cannot convert {} into an element of {} - variables are not admissible".format(x, self))

if len(VarList) == 1:
# univariate polynomial rings are crab. So, make up another variable.
Expand All @@ -1017,7 +1017,7 @@
try:
VarList.sort(key=self.varname_key, reverse=True)
except ValueError:
raise ValueError("cannot convert %s into an element of %s; the variables are not admissible" % (x, self))
raise ValueError("cannot convert {} into an element of {}; the variables are not admissible".format(x, self))

Check warning on line 1020 in src/sage/rings/polynomial/infinite_polynomial_ring.py

View check run for this annotation

Codecov / codecov/patch

src/sage/rings/polynomial/infinite_polynomial_ring.py#L1020

Added line #L1020 was not covered by tests

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
R = PolynomialRing(self._base, VarList, order=self._order)
Expand All @@ -1031,16 +1031,16 @@
# Hence, for being on the safe side, we coerce into a pushout ring:
x = R(1) * x
return InfinitePolynomial(self, x)
except Exception:
except (TypeError, ValueError):
# OK, last resort, to be on the safe side
try:
return sage_eval(repr(x), self.gens_dict())
except (ValueError, TypeError, NameError):
raise ValueError("cannot convert %s into an element of %s; conversion of the underlying polynomial failed" % (x, self))
raise ValueError("cannot convert {} into an element of {}; conversion of the underlying polynomial failed".format(x, self))

Check warning on line 1039 in src/sage/rings/polynomial/infinite_polynomial_ring.py

View check run for this annotation

Codecov / codecov/patch

src/sage/rings/polynomial/infinite_polynomial_ring.py#L1039

Added line #L1039 was not covered by tests
try:
return sage_eval(repr(x), self.gens_dict())
except (ValueError, TypeError, NameError):
raise ValueError("cannot convert %s into an element of %s" % (x, self))
raise ValueError(f"cannot convert {x} into an element of {self}")

Check warning on line 1043 in src/sage/rings/polynomial/infinite_polynomial_ring.py

View check run for this annotation

Codecov / codecov/patch

src/sage/rings/polynomial/infinite_polynomial_ring.py#L1043

Added line #L1043 was not covered by tests

def tensor_with_ring(self, R):
"""
Expand Down Expand Up @@ -1085,7 +1085,7 @@
# try to find the correct base ring in other ways:
try:
o = B.one() * R.one()
except Exception:
except (TypeError, ValueError):

Check warning on line 1088 in src/sage/rings/polynomial/infinite_polynomial_ring.py

View check run for this annotation

Codecov / codecov/patch

src/sage/rings/polynomial/infinite_polynomial_ring.py#L1088

Added line #L1088 was not covered by tests
raise TypeError("we cannot tensor with " + repr(R))
return InfinitePolynomialRing(o.parent(), self._names, self._order, implementation='sparse')

Expand Down Expand Up @@ -1528,7 +1528,7 @@
sage: print(x) # indirect doctest
Generator for the x's in Infinite polynomial ring in x, y over Rational Field
"""
return "Generator for the %s's in %s" % (self._name, self._parent)
return f"Generator for the {self._name}'s in {self._parent}"


##############################################################
Expand Down Expand Up @@ -1623,7 +1623,7 @@
# try to find the correct base ring in other ways:
try:
o = B.one() * R.one()
except Exception:
except (TypeError, ValueError):

Check warning on line 1626 in src/sage/rings/polynomial/infinite_polynomial_ring.py

View check run for this annotation

Codecov / codecov/patch

src/sage/rings/polynomial/infinite_polynomial_ring.py#L1626

Added line #L1626 was not covered by tests
raise TypeError("we cannot tensor with " + repr(R))
return InfinitePolynomialRing(o.parent(), self._names, self._order, implementation='dense')

Expand Down
Loading