Suppose, I have an expression like so:
In[68]:= expr = 2 + 5*q + q^2 + 8 q^3 + 19 q^7
Out[68]= 2 + 5 q + q^2 + 8 q^3 + 19 q^7
Now I want to take all powers of q lying between 0 and 2 to zero i.e. my desired output is:
$8 q^3 + 19 q^7$
I tried the following without success:
In[72]:= expr /. q^n_. /; 0 <= n <= 2 -> 0
Out[72]= 2
What could be a neat way to do it? I know the following works:
In[73]:= Plus @@ (If[0 <= Exponent[#, q] <= 2, 0, #] & /@ List @@ expr)
Out[73]= 8 q^3 + 19 q^7
I just wanted to do this with simple pattern matching and replacement.
Any help will be appreciated.