How can I eliminate terms containing two variables raised to different powers?

I have defined two functions: Θ and Θc (the conjugate of Θ), along with some of their properties.

Θ[a_, b_, ord_] := Θ[a + 2, b, ord] /; a < 0;
Θ[a_, b_, ord_] := Θ[a - 2, b, ord] /; a > 2;
Θ[a_, b_, ord_] := Exp[-I Pi a]*Θ[a, b + 2, ord] /; b < 0;
Θ[a_, b_, ord_] := Exp[I Pi a]*Θ[a, b - 2, ord] /; b >= 2;
Θ[a_, b_, ord_] := (qi qr)^(a^2/4) Exp[I Pi a b/2] + Sum[(qi qr)^(n + a/2)^2 Exp[I Pi (n + a/2) b] + (qr*qi)^(n - a/2)^2 Exp[I Pi (-n + a/2) b] , {n, 1,ord}]+O[qr]^((ord + 1 - Abs[a]/2)^2);
Θc[a_, b_, ord_] := Θc[a + 2, b, ord] /; a < 0;
Θc[a_, b_, ord_] := Θc[a - 2, b, ord] /; a > 2;
Θc[a_, b_, ord_] := Exp[I Pi a]*Θc[a, b + 2, ord] /; b < 0;
Θc[a_, b_, ord_] := Exp[-I Pi a]*Θc[a, b - 2, ord] /; b >= 2;
Θc[a_, b_, ord_] := (qr/qi)^(a^2/4) Exp[I Pi a b/2] + Sum[(qr/qi)^(n+a/2)^2Exp[I Pi (n + a/2) b] + (qr/qi)^(n-a/2)^2 Exp[I Pi (-n+a/2) b] , {n, 1, ord}]+O[qr]^((ord + 1 - Abs[a]/2)^2);


These functions are expansions in terms of two parameters, qr and qi, and the variable ord is there to cut the expansion at some order I want, for example

ord=5;


I want to calculate expressions of the form:

Z1 = 2*(Θ[1,0,ord]^4*(Θc[0,0,ord]^8 Θc[0,1,ord]^8+Θc[0,1,ord]^8 Θc[0,0,ord]^8));
Z1//FullSimplify


The output is a massive wall of terms, but I will only copy the first ones:

64 qi qr+(256 (-8+qi^4) qr^3)/qi+(128 (240-64 qi^4+3 qi^8) qr^5)/qi^3


I am only interested in keeping terms of the form (qr qi)^n and discarding the rest. For example 64 qi qr (first term) and 256 qi^3 qr^3 (from the second term) are ok, but 256*(-8)qr^3/qi (from the second term) is not.

The final result should be of the form Sum[an (qr*qi)^n]= ... + a (qr qi)^(-1) +b(qr qi)^0 +c(qr qi)^1 + ...

How can I eliminate all terms that do not contain (qr qi)^n?

You can use DeleteCases with the appropriate Pattern condition:

DeleteCases[
ExpandAll@Normal@Z1,
Alternatives[
Times[c_?NumericQ, qi, qr^n_],
Times[c_?NumericQ, qi^n_, qr],
Times[
c_?NumericQ,
qr^n_, qi^m_
] /; n != m
]
]
(* Out[1]= 64 qi qr + 256 qi^3 qr^3 + 384 qi^5 qr^5 + 512 qi^7 qr^7 +
832 qi^9 qr^9 + 768 qi^11 qr^11 + 896 qi^13 qr^13 +
1536 qi^15 qr^15 + 1152 qi^17 qr^17 + 1280 qi^19 qr^19 +
2048 qi^21 qr^21 + 1536 qi^23 qr^23 + 1984 qi^25 qr^25 +
2560 qi^27 qr^27 + 1920 qi^29 qr^29 *)


where we have to explicitly include the cases in which qi or qr are elevated to the first power because they do not match patterns like qr^n_.

• Thanks for the quick answer. That's exactly what I needed. Commented Dec 8, 2016 at 12:37

Another method is

Expand[Normal@Z1] /. (qi^n_. qr^m_. :> 0 /; m != n)


Note the . gives the default (for powers, 1), so you don't have to enumerate the alternatives as in gIS's answer.