Cutting of terms on denominators of giant expression

I have an immense expression of the form

$$\sum_i \frac{f_i(X,Y,x,y)}{(a_iX^2+b_iY^2+c_ix^2+d_iy^2)(e_iX^2+g_iY^2+h_ix^2+k_iy^2)},$$ where at $$a_i$$ or $$b_i$$ AND $$e_i$$ or $$g_i$$ is different from zero.

How can I alter this expression, in an automated form, so as to cut off every term, in each factor of the denominator, that does not contain $$X$$ or $$Y$$?

That is, the expression is to become

$$\sum_i \frac{f_i(X,Y,x,y)}{(a_iX^2+b_iY^2)(e_iX^2+g_iY^2)}.$$

How can this be done?

• Perhaps newdenominator=denominator//.{x->0,y->0}. Please test that carefully to make certain that it is exactly correct. If so then use that newdenominator inside your sum.
– Bill
Oct 1 '21 at 4:58
• @Bill that depends on how the actual expression is. If it has for example 1/x or 1/x^2 or such, it will cause divide by zero or some other problem. It was not clear from the question, since no actual MWE was given. But if the denominator has the exact same form shown, I think setting x and y to zero should work also. Oct 1 '21 at 5:09
• @Bill It occurred to me that separating each term in Numerator and Denominator, setting x,y to zero and then reassemble the complete expression would be the way to do it, however I couldn't set up a correct syntax for it. Oct 1 '21 at 15:38
• @Nasser That won't happen because the denominators are never of the form 1/(x,y)^2 because on each term either the x or the y coefficient is different from zero and the f are polynomials. Oct 1 '21 at 15:41

Consider this expression

expr = Sum[
f[i][X, Y, x, y]/
(a[i] X^2 + b[i] Y^2 + c[i] x^2 + d[i] y^2)/
(e[i] X^2 + g[i] Y^2 + h[i] x^2 + k[i] y^2), {i, 1, 3}]

Since Numerator and Denominator can be used to isolate the $$f_i$$'s of each term of this expression, we can do this

Numerator[#]/(Denominator[#] /. {x -> 0, y -> 0}) &  /@ expr

But, Numerator may not be able to identify all of your $$f_i$$'s.

• The f's are polynomial expressions, so I think it will work fine! Thank you! Oct 1 '21 at 15:45

You can try

Clear["Global*"]
oneTerm = f[X, Y, x, y]/((a*X^2 + b*Y^2 + c*x^2 + d*y^2)*(e*X^2 + g*Y^2 + h*x^2 + k*y^2))
cleanOneTermInSum[oneTerm, X, Y]

which takes and returns Since you did not post an actual sum in Mathematica code, I can't try it on your code to make sure it works. You can now wrap each one of the terms in the sum by the above call.

The idea is to look at the denominator, and use Select with FreeQ to remove unwanted expressions.

Clear["Global*"]
oneTerm = f[X, Y, x, y]/((a*X^2 + b*Y^2 + c*x^2 + d*y^2)*(e*X^2 + g*Y^2 + h*x^2 + k*y^2));

cleanIt[expr_, X_, Y_] := Select[expr, Not[ FreeQ[#, X] && FreeQ[#, Y]] &];(*helper*)

cleanOneTermInSum[term_, X_Symbol, Y_Symbol] := Module[{den, cleanDen, cleanExpr},

den = Denominator[term];

If[AtomQ[den],
cleanExpr = term
,