Message Boards Message Boards

0
|
6415 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Delete all odd exponents?

Posted 8 years ago

Deleting all the odd terms in a polynomial expansion does not remove the linear term. I can delete that term explicitly but I am wondering if there is another way to do this. For example,

In[5]:= y = Expand[(a + x)^6]

Out[5]= a^6 + 6 a^5 x + 15 a^4 x^2 + 20 a^3 x^3 + 15 a^2 x^4 + 
 6 a x^5 + x^6

In[6]:= DeleteCases[y, _. x^_?OddQ]

Out[6]= a^6 + 6 a^5 x + 15 a^4 x^2 + 15 a^2 x^4 + x^6

This leaves the term linear in x but

In[7]:= DeleteCases[y, _. x^_?OddQ | _. x]

Out[7]= a^6 + 15 a^4 x^2 + 15 a^2 x^4 + x^6

deletes it. Is there a better way to do this?

POSTED BY: Mike Luntz
4 Replies

The RepleaceAll approach leads to the same result of the DeleteCases . At least in my v. 11.0.1

In

Out[7]= True

POSTED BY: massimo fazio
Posted 8 years ago

Thanks for the suggestions. I tried using

DeleteCases[y,_.x^_.?OddQ]

but that did not seem to work. Explicitly using the Optional function seems to be the only way to do this other than my original approach of explicitly removing the linear terms. Mathematica syntax continues to confound me.

POSTED BY: Mike Luntz

Considering we are talking of a summation, I rather see this operation a substitution with zero of the undesired term. Anyway, this should work as well:

y /. _^exp_ /; OddQ[exp] -> 0
POSTED BY: massimo fazio

This seems to work on your example:

DeleteCases[y, _. x^Optional[_?OddQ]]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract