Ask Your Question

Revision history [back]

One can produce strings and have the polynomial ring eat them.

String formatting is easy thanks to Python.

Define a polynomial ring as in the question:

R.<x1, x3, x5> = PolynomialRing(QQ)

Define a "generator power" function as follows:

def f(i, j):
    r"""
    Return the polynomial variable xi raised to the j-th power.
    """
    return R('x{}^{}'.format(i, j))

Example:

sage: f(3, 2)
x3^2