Ask Your Question

Get variable of polynomial ring

asked 2018-03-03 04:39:27 -0500

philipp7 gravatar image

I have a univariate polynomial ring and a polynomial in this ring, e.g.

R.<x> = PolynomialRing(ZZ);
p = 3*x^2 + 7*x - 5;

My question is: If I call a function with such a polynomial how can I figure out what the original variable was? For instance, say I have the following:

def f(q) :
   return q*x;
print f(p)

Of course that is a rather stupid example but I hope the idea is clear. How can I swap x with something more general like f.parent().variable() or is there a better way to do such things?

Thank you very much for your help!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-03-03 05:41:59 -0500

j.c. gravatar image

p.variables() returns a tuple which contains the variables of p, so your function could be written:

def f(q):
   return q*q.variables()[0]
edit flag offensive delete link more


Perfect, exactly what I was looking for. Thank you very much!

philipp7 gravatar imagephilipp7 ( 2018-03-03 06:02:25 -0500 )edit

Your Answer

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

Add Answer

Question Tools


Asked: 2018-03-03 04:39:27 -0500

Seen: 17 times

Last updated: Mar 03