ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 16 Mar 2020 02:19:07 +0100How 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 14:28:15 +0100https://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 16:00:41 +0100https://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=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 16:16:42 +0100https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/?comment=50253#post-id-50253Comment 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 19:07:13 +0100https://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=50262#post-id-50262I see. Thanks!Mon, 16 Mar 2020 02:19:07 +0100https://ask.sagemath.org/question/50250/how-do-i-retrieve-the-variables-that-appear-in-a-polynomial/?comment=50262#post-id-50262