TransWikia.com

Removing terms with odd degrees in polynomial

Mathematica Asked by mikis on February 11, 2021

I have a polynomial in four variables and I would like to eliminate all terms that are odd in at least one of these variables.
For example, if $p(x,y,z,t)=3x^2y+y^4z^2+x^2yt + x^2t^2$, then the only part that should remain is $y^4z^2+x^2y^2$ (since in the first term $y$ is of an odd degree, and in the third term both $y$ and $t$ are of odd degrees).

I found a solution in a case when we would like eliminate terms of fixed sum of degrees, but do not know how to apply similar elimination procure here. What is the simplest method to do it?

One Answer

Approach #1

I think the following code does the trick:

p = 3 x^2 y + y^4 z^2 + x^2 y t + x^2 t^2
vars = {x, y, z, t}
coeffs = CoefficientRules[p, vars]
evencoeffs = Select[coeffs, And @@ EvenQ[First[#]] &]
FromCoefficientRules[evencoeffs, vars]

(* t^2 x^2 + y^4 z^2 *)

Essentially, CoefficientRules returns a list of rules associated to each term in the polynomial; for example, the first term becomes {2, 3, 0, 0} -> 3. We then select all sets of rules for which all entries in that first list are even, and reconstruct the polynomial from the selected rules.

Approach #2

Simplify[Fold[(#1 + (#1 /. #2 -> -#2))/2 &, p, vars]]

This code takes advantage of the fact that $frac{1}{2} [p(x,y,z,t) + p(-x,y,z,t)]$ will only contain even powers of $x$. Fold applies this process iteratively to p for each of the elements of vars, thereby eliminating all terms that are odd in any of the variables, and then reports out the final result.

Answered by Michael Seifert on February 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP