Message Boards Message Boards

0
|
7578 Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Zeroing-out polynomial terms?

Posted 7 years ago

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

POSTED BY: Bruce Colletti
6 Replies
Posted 7 years ago

Thanks Carl. Using Normal is what I first used but for my long Laurent polynomials, processing was slowing down. That's when I asked Tech Support if there was a faster way and that's when zeroing-out was suggested. Since Normal adapts to many things, more work is done to determining its appropriate use and this -- among other things -- contributes to the slowing down.

HOWEVER, your first example uses (x, Infinity, -3} -- I've never considered using Infinity as the center point. So, you've just helped with other matters that will soon come back into my inbox. Thank you again for this.

POSTED BY: Bruce Colletti

I didn't suggest this earlier, because you wanted to keep the constant term while dropping non-constant terms below a threshold. Your last comment suggests that you do want to zero-out the linear term. So, if you wanted to drop all terms below a threshold, including the constant term, then you could use Series as follows:

Normal @ Series[1/x^3 + 1/x^2 + 1/x + 1 + x + x^2 + x^3 + x^4 + x^5, {x, Infinity, -3}]]
(* x^3 + x^4 + x^5 *)

If you wanted to drop terms below 1/x, then:

Normal @ Series[1/x^3 + 1/x^2 + 1/x + 1 + x + x^2 + x^3 + x^4 + x^5, {x, Infinity, 1}]]
(* 1 + 1/x + x + x^2 + x^3 + x^4 + x^5 *)
POSTED BY: Carl Woll
Posted 7 years ago

Thanks Sander. This looks great for use with polynomials.

As it turns out, what I had called a "polynomial" is really a Laurent polynomial, and so the negative integer exponents cause trouble. I'll still further investigate CoefficientRules.

Yours and Brad's replies suggest that maybe Replacement can't be coerced into zeroing-out a linear term in a Laurent polynomial. If so then this is important to know.

POSTED BY: Bruce Colletti

I would recommend using CoefficientRules and FromCoefficientRules:

CoefficientRules[2 + 3 x - x^2 + 5 x^3 + 9 x^8]
DeleteCases[%, ({n_} -> _) /; 1 <= n < 4]
FromCoefficientRules[%, x]

Or if you prefer function based, rather than rule-based:

CoefficientRules[2 + 3 x - x^2 + 5 x^3 + 9 x^8]
Select[%, Not[1 <= #[[1, 1]] < 4] &]
FromCoefficientRules[%, x]
POSTED BY: Sander Huisman

Let's say you have $P=P_{\ge4}+P_{<4}$ and trouble computing $P_{\ge4}$ directly.

Why not compute $P_{<4}$ and then obtain $P_{\ge4}$ by subtraction, $P_{\ge4}=P-P_{<4}$?

Whenever you know the maximum exponent in your power series, you have another option to use "Coefficient" and work in a vector space of the coefficients. The advantage here is that

Coefficient[ P, x, 0 ] 

will return $2$ in your case. Combining with Map, Part, Dot, Power, and Range I think you should be able to calculate $P_{\ge4}$ without ever using any replacement rules.

POSTED BY: Brad Klee
Posted 7 years ago

Thanks for the reply and its good sense approach.

Since my earlier method to strike that subpolynomial took too long, Tech Support used zero replacement to swiftly strike it. But then I noticed an occasional wrong result caused by a linear term c x that replacement didn't touch. Unable to zero out the subpolynomial-with-linear-term, I turned to Wolfram Community to see if Replacement could be made to do so.

In the actual application, the full polynomial (in x) is the sum of many bilinear forms a.B.c where B is the power of another matrix whose entries are powers of x -- B also depends upon the summation index (whose values are tuples). And so computing that subpolynomial isn't so easy. Although it seems that Replacement can't be made to behave as I had hoped, your idea to use Coefficient is a good one that I'll remember.

POSTED BY: Bruce Colletti
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