Ask Your Question
1

Functions in polynomials rings

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

mathstudent gravatar image

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

2 answers

Sort by ยป oldest newest most voted
1

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

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):
    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
edit flag offensive delete link more
1

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

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]
x0

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

Stats

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

Seen: 56 times

Last updated: Sep 19