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.Thu, 06 Apr 2017 16:31:10 +0200How to extract exponents from a monomial in a FreeAlgebrahttps://ask.sagemath.org/question/37170/how-to-extract-exponents-from-a-monomial-in-a-freealgebra/I want something like this, or a way to get the equivalent information:
sage: S.<X,Y> = FreeAlgebra(QQ)
sage: m = X*Y*X^2
sage: m.my_exponents_function()
[(X,1),(Y,1),(X,2)]
or
sage: m.my_factor_function()
[X,Y,X,X]
would be as good or maybe better.
How can I get that information? I've looked over the available methods and can't seem to find anything. This is easy to do with Polynomial Rings.
I guess I could parse the string representation, but shouldn't there be a better way?Wed, 05 Apr 2017 01:34:43 +0200https://ask.sagemath.org/question/37170/how-to-extract-exponents-from-a-monomial-in-a-freealgebra/Answer by John Palmieri for <p>I want something like this, or a way to get the equivalent information:</p>
<pre><code>sage: S.<X,Y> = FreeAlgebra(QQ)
sage: m = X*Y*X^2
sage: m.my_exponents_function()
[(X,1),(Y,1),(X,2)]
</code></pre>
<p>or</p>
<pre><code>sage: m.my_factor_function()
[X,Y,X,X]
</code></pre>
<p>would be as good or maybe better.</p>
<p>How can I get that information? I've looked over the available methods and can't seem to find anything. This is easy to do with Polynomial Rings. </p>
<p>I guess I could parse the string representation, but shouldn't there be a better way?</p>
https://ask.sagemath.org/question/37170/how-to-extract-exponents-from-a-monomial-in-a-freealgebra/?answer=37179#post-id-37179Here are two options:
sage: S.<X,Y> = FreeAlgebra(QQ)
sage: m = X*Y*X^2
sage: a = m.leading_support()
sage: a.to_list()
[X, Y, X, X]
So if you have more than one term:
sage: m = X*Y*X**2 + 3*X**4*Y
sage: [a.to_list() for a in m.support()]
[[X, Y, X, X], [X, X, X, X, Y]]
You can also access raw exponent information:
sage: S.<X,Y> = FreeAlgebra(QQ)
sage: m = X*Y*X^2
sage: a = m.leading_support()
sage: a.__dict__
{'_element_list': [(0, 1), (1, 1), (0, 2)]}
sage: a.__dict__.values()[0]
[(0, 1), (1, 1), (0, 2)]
Each entry in this list is of the form `(gen, power)`, where `gen=0` corresponds to `X` and `gen=1` corresponds to `Y`.Wed, 05 Apr 2017 17:10:14 +0200https://ask.sagemath.org/question/37170/how-to-extract-exponents-from-a-monomial-in-a-freealgebra/?answer=37179#post-id-37179Comment by paragon for <p>Here are two options:</p>
<pre><code>sage: S.<X,Y> = FreeAlgebra(QQ)
sage: m = X*Y*X^2
sage: a = m.leading_support()
sage: a.to_list()
[X, Y, X, X]
</code></pre>
<p>So if you have more than one term:</p>
<pre><code>sage: m = X*Y*X**2 + 3*X**4*Y
sage: [a.to_list() for a in m.support()]
[[X, Y, X, X], [X, X, X, X, Y]]
</code></pre>
<p>You can also access raw exponent information:</p>
<pre><code>sage: S.<X,Y> = FreeAlgebra(QQ)
sage: m = X*Y*X^2
sage: a = m.leading_support()
sage: a.__dict__
{'_element_list': [(0, 1), (1, 1), (0, 2)]}
sage: a.__dict__.values()[0]
[(0, 1), (1, 1), (0, 2)]
</code></pre>
<p>Each entry in this list is of the form <code>(gen, power)</code>, where <code>gen=0</code> corresponds to <code>X</code> and <code>gen=1</code> corresponds to <code>Y</code>.</p>
https://ask.sagemath.org/question/37170/how-to-extract-exponents-from-a-monomial-in-a-freealgebra/?comment=37180#post-id-37180Perfect! It is hidden pretty deep, I would not have found that.Wed, 05 Apr 2017 20:08:51 +0200https://ask.sagemath.org/question/37170/how-to-extract-exponents-from-a-monomial-in-a-freealgebra/?comment=37180#post-id-37180Comment by John Palmieri for <p>Here are two options:</p>
<pre><code>sage: S.<X,Y> = FreeAlgebra(QQ)
sage: m = X*Y*X^2
sage: a = m.leading_support()
sage: a.to_list()
[X, Y, X, X]
</code></pre>
<p>So if you have more than one term:</p>
<pre><code>sage: m = X*Y*X**2 + 3*X**4*Y
sage: [a.to_list() for a in m.support()]
[[X, Y, X, X], [X, X, X, X, Y]]
</code></pre>
<p>You can also access raw exponent information:</p>
<pre><code>sage: S.<X,Y> = FreeAlgebra(QQ)
sage: m = X*Y*X^2
sage: a = m.leading_support()
sage: a.__dict__
{'_element_list': [(0, 1), (1, 1), (0, 2)]}
sage: a.__dict__.values()[0]
[(0, 1), (1, 1), (0, 2)]
</code></pre>
<p>Each entry in this list is of the form <code>(gen, power)</code>, where <code>gen=0</code> corresponds to <code>X</code> and <code>gen=1</code> corresponds to <code>Y</code>.</p>
https://ask.sagemath.org/question/37170/how-to-extract-exponents-from-a-monomial-in-a-freealgebra/?comment=37191#post-id-37191I agree, it's not at all obvious.Thu, 06 Apr 2017 16:31:10 +0200https://ask.sagemath.org/question/37170/how-to-extract-exponents-from-a-monomial-in-a-freealgebra/?comment=37191#post-id-37191