# 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?

edit retag close merge delete

Sort by » oldest newest most voted Here are two options:

sage: S.<X,Y> = FreeAlgebra(QQ)
sage: m = X*Y*X^2
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.__dict__
{'_element_list': [(0, 1), (1, 1), (0, 2)]}
sage: a.__dict__.values()
[(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.

more

Perfect! It is hidden pretty deep, I would not have found that.