ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 15 Mar 2020 20:19:07 -0500How do I retrieve the variables that appear in a polynomial?https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/Hello, I'd like to know I can retrieve the list of variables that appear in $g$ in the following example.
A.<x,y> = InfinitePolynomialRing(QQ)
g=x_[0]+x_[1]+y_[0]
Thanks in advance!Sun, 15 Mar 2020 08:28:15 -0500https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/Answer by rburing for <p>Hello, I'd like to know I can retrieve the list of variables that appear in $g$ in the following example.</p>
<pre><code>A.<x,y> = InfinitePolynomialRing(QQ)
g=x_[0]+x_[1]+y_[0]
</code></pre>
<p>Thanks in advance!</p>
https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/?answer=50252#post-id-50252In SageMath 9.0:
sage: A.<x,y> = InfinitePolynomialRing(QQ)
sage: g=x[0]+x[1]+y[0]
sage: g.variables()
(x_1, x_0, y_0)Sun, 15 Mar 2020 10:00:41 -0500https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/?answer=50252#post-id-50252Comment by mcmug for <p>In SageMath 9.0:</p>
<pre><code>sage: A.<x,y> = InfinitePolynomialRing(QQ)
sage: g=x[0]+x[1]+y[0]
sage: g.variables()
(x_1, x_0, y_0)
</code></pre>
https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/?comment=50262#post-id-50262I see. Thanks!Sun, 15 Mar 2020 20:19:07 -0500https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/?comment=50262#post-id-50262Comment by rburing for <p>In SageMath 9.0:</p>
<pre><code>sage: A.<x,y> = InfinitePolynomialRing(QQ)
sage: g=x[0]+x[1]+y[0]
sage: g.variables()
(x_1, x_0, y_0)
</code></pre>
https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/?comment=50257#post-id-50257@mcmug That's tricky. I don't see a clean way to do it right now. You can do it by converting to/from a string though.Sun, 15 Mar 2020 13:07:13 -0500https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/?comment=50257#post-id-50257Comment by mcmug for <p>In SageMath 9.0:</p>
<pre><code>sage: A.<x,y> = InfinitePolynomialRing(QQ)
sage: g=x[0]+x[1]+y[0]
sage: g.variables()
(x_1, x_0, y_0)
</code></pre>
https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/?comment=50253#post-id-50253Thanks. Do you know how I can get a list like [0,1] for x and [0] for y?Sun, 15 Mar 2020 10:16:42 -0500https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/?comment=50253#post-id-50253