Ask Your Question
0

Get variable of polynomial ring

asked 2018-03-03 11:39:27 +0200

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
2

answered 2018-03-03 12:41:59 +0200

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

Comments

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

philipp7 gravatar imagephilipp7 ( 2018-03-03 13:02:25 +0200 )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

Stats

Asked: 2018-03-03 11:39:27 +0200

Seen: 814 times

Last updated: Mar 03 '18