Ask Your Question
0

Change of a polynomial to a list of monomials in sagemath.

asked 2022-11-04 11:34:21 +0100

lijr07 gravatar image

How to change a polynomial to a list of monomials in sagemath? The task is as follows. I defined a set of symbols:

for i in range(k):
    for j in range(n):
        var('y'+'_'+str(i)+'_'+str(j))

I would like to change a polynomial in $y_{ij}$ to a list of monomials. For example,

-y_0_3^2*y_1_2*y_2_1 + y_0_2*y_1_3*y_2_1^3

is changed to [[-1, y_0_3, y_0_3, y_1_2, y_2_1], [1, y_0_2, y_1_3, y_2_1, y_2_1, y_2_1]]. How to do this in sagemath? Thank you very much.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-11-04 11:58:27 +0100

rburing gravatar image

This looks very much like an XY problem. Anyway:

sage: f = -y_0_3^2*y_1_2*y_2_1 + y_0_2*y_1_3*y_2_1^3
sage: R = PolynomialRing(QQ, names=['y_{}_{}'.format(i,j) for i in range(k) for j in range(n)])
sage: [[c] + sum([[SR(R.gen(i))]*e[i] for i in range(R.ngens()) if e[i] != 0], []) for (e,c) in R(f).dict().items()]
[[1, y_0_2, y_1_3, y_2_1, y_2_1, y_2_1], [-1, y_0_3, y_0_3, y_1_2, y_2_1]]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-11-04 11:34:21 +0100

Seen: 239 times

Last updated: Nov 04 '22