Ask Your Question

# Functions in polynomials rings

I want to define a function in a polynomial ring in several variables.

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


I am trying to define a function that takes $(i,j)$ to $x_i^j$.

I tried

def f(i,j):
return xi^j


This does not work. I tried replacing xi with x[i], that doesn't work. Can someone please tell me what I am doing wrong and how to fix it? If instead of taking 3 variables I take only 1 variable then the method works.

edit retag close merge delete

## 2 Answers

Sort by » oldest newest most voted You want to access the generators of R as a tuple:

sage: R = PolynomialRing(QQ, 3, names='x'); R
Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
sage: x = R.gens(); x
(x0, x1, x2)
sage: x
x0


If you want to use some strange alternative indexing, then you can achieve it with a function.

more

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

more

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2020-09-19 06:59:12 +0200

Seen: 70 times

Last updated: Sep 19 '20