From a univariate polynomial, I want to delete nonconstant terms whose exponents are less than a threshold. The line below works as planned:
In[34]:= 2 + 3 x - x^2 + 5 x^3 + 9 x^8 /. {(x^k_ /; k < 4) -> 0, Times[ _, x] -> 0}
Out[34]= 2 + 9 x^8
But the line below fails because the term x has neither form Times[ ,x] nor x^k:
In[35]:= 2 + x - x^2 + 5 x^3 + 9 x^8 /. {(x^k_ /; k < 4) -> 0, Times[ _, x] -> 0}
Out[35]= 2 + x + 9 x^8
I tried the line below but it clearly fails (it uses the default operator _. that when used in Cases, uses 1 as the default exponent):
In[36]:= 2 + x - x^2 + 5 x^3 + 9 x^8 /. (x^k_. /; k < 4) -> 0
Out[36]= 2
An easy workaround approach is to multiply the polynomial by some x^m, then cut terms and then restore the original terms. But is there an easier way, ideally using ReplaceAll alone? Thanks.
Bruce