Ask Your Question

Functions in polynomials rings

asked 2020-09-18 23:59:12 -0600

mathstudent gravatar image

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


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 flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2020-09-19 12:21:22 -0600

slelievre gravatar image

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):
    Return the polynomial variable xi raised to the j-th power.
    return R('x{}^{}'.format(i, j))


sage: f(3, 2)
edit flag offensive delete link more

answered 2020-09-19 03:18:47 -0600

rburing gravatar image

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[0]

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

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2020-09-18 23:59:12 -0600

Seen: 66 times

Last updated: Sep 19 '20