# Finding constant term in product expression

I've an expression which is product of 20 or more factors of polynomial, something like $$\left(1-\frac{pq}{z^i}\right)(1+pq z^j+z^k)$$ and I want to find coefficient of $$z^0$$. SeriesCoefficient works well for less factors but as the number of factors increases it takes too much time. I don't care about the whole expression of constant term which is a function of $$p,q$$; just the low power $$p,q$$ terms are what I want to extract. Is there any method to do this manipulation?

• Welcome to the Mathematica Stack Exchange. Please load Mathematica code that can be copied, pasted and executed locally in our own notebook sessions. Copy directly from your input cell, click the Edit button under your post and format as code using the { } icon in the Edit window. Thanks.
– Syed
Commented Mar 5 at 13:47

You may use "Expand" to get the expanded form of your polynomial. And then "Cases" can pick the constant terms. here is an example. First we create some large polynomial:

poly = Product[
1 - p  z^RandomInteger[{-3, 3}] + z^RandomInteger[{-3, 3}], {i,
20}];


Then we expand this polynomial and pick the constant terms:

Cases[poly // Expand, x_ /; FreeQ[x, z]]

{0.0121714, {78960, -808576 p, 3839652 p^2, -11369974 p^3,
23661281 p^4, -36890023 p^5, 44821328 p^6, -43457855 p^7,
34132492 p^8, -21930300 p^9, 11564989 p^10, -4993479 p^11,
1751413 p^12, -491642 p^13, 108480 p^14, -18203 p^15,
2090 p^16, -128 p^17, p^18}}


To get an idea how fast this is:

Cases[poly // Expand, x_ /; FreeQ[x, z]]; // AbsoluteTiming

{0.0120267, Null}

• Thanks for the answer. This worked for me totally. Commented Mar 8 at 6:11