Ask Your Question
0

I've got a big expression I need to dissect a certain way

asked 2021-07-12 22:11:18 +0200

Tim02130 gravatar image

I've got a BIG polynomial (7 indeterminates, total degree 12), and I want to collect all the terms therein that contain only EVEN powers of all the indeterminates. Is there any reasonably simple way to do this? By "simple," I mean short of traversing the whole expression tree, testing each term to see if it contains only even powers, and collecting them one-by-one in a list (which, BTW, I also don't really know how to do)! If it makes any difference, I haven't been using the sage.rings.polynomial module, just generic Sage expressions.

edit retag flag offensive close merge delete

Comments

Can you convert it to an element of a polynomial ring? (Or better yet, create it as such in the first place.) Then it's easy. Please post some of the terms, to make the question easier to answer.

rburing gravatar imagerburing ( 2021-07-12 22:40:43 +0200 )edit

I suppose I could convert it to (or more easily, just recreate it as) an element of a multivariate polynomial ring over the integers, but before I do, I'd like to know how that makes it "easy."

Anyway here's three of the terms (which I don't think is going to tell you much that you don't already know): -A_123^5A_124^3A_12_34^4 - 2A_123^4A_124^4A_12_34^4 - A_123^3A_124^5*A_12_34^4 + ... In this case, I want to keep the 2nd term and throw out the other two.

Tim02130 gravatar imageTim02130 ( 2021-07-12 23:08:11 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-07-13 05:15:09 +0200

If you are willing to work with polynomials, you can do this. There may be ways to speed up the following. First define the polynomial ring and the indeterminates:

sage: R.<A_123, A_12_34, A_124> = QQ[]

Now define the expression:

sage: a = -A_123^5*A_124^3*A_12_34^4 - 2*A_123^4*A_124^4*A_12_34^4 - A_123^3*A_124^5*A_12_34^4

Note that "for m in a" prints out useful information: pairs (coefficient, monomial):

sage: for m in a: print(m)
(-1, A_123^5*A_12_34^4*A_124^3)
(-2, A_123^4*A_12_34^4*A_124^4)
(-1, A_123^3*A_12_34^4*A_124^5)
sage: sum(m[0]*m[1] for m in a)
-A_123^5*A_12_34^4*A_124^3 - 2*A_123^4*A_12_34^4*A_124^4 - A_123^3*A_12_34^4*A_124^5
sage: sum(m[0]*m[1] for m in a) == a
True

Now pick out the terms where all of the exponents are even:

sage: sum(m[0]*m[1] for m in a if all(x%2 == 0 for x in m[1].exponents()[0]))
-2*A_123^4*A_12_34^4*A_124^4
edit flag offensive delete link more

Comments

Thank you!

Tim02130 gravatar imageTim02130 ( 2021-07-13 13:29:37 +0200 )edit

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: 2021-07-12 22:11:18 +0200

Seen: 55 times

Last updated: Jul 13