# Filter out terms that include any combination of F[X] and G[-X]

I have the following problem which is closely linked to a previous question I asked some time ago (Replacement rule for terms that are separated by operators?).

In this specific instance, suppose I have any arbitrary expression "EXPR" and I specifically want to set it to zero if there are a function F, F[X] and another function G, G[-X].

GOAL: I am looking for a rule that realizes the aforementioned situation.

Some Examples of EXPR that I want to set to zero:

1)F[X]*___*G[-X]

2)F[X]@___@G[-X]

3)___F[X]@___@G[-X]___

4)___@F[X]@___@G[-X]___

I literally only care if any term just has F[X] and G[-X] together in whatever setting or form.

BONUS:

A possible solution I thought of is the following

EXPR_ /; ! (Module[{X},
FreeQ[EXPR, F[-X]] && FreeQ[EXPR, G[X]]]) :> (0)


but unfortunately FreeQ does not work in a module

Module[{Z}, FreeQ[F[X], F[Z]]]   Input
True                             Output

• Does this work for you: f[expr_ /; ! FreeQ[expr, _F] && ! FreeQ[expr, _G]] := 0; f[expr_] := expr ?
– Alx
Nov 13 '19 at 12:15
• Thanks for your answer. Unfortunately it does not work because I specifically need F and G to also have the opposite arguments as stated F[X] and G[-X]. Nov 13 '19 at 12:26
• Ah, maybe this one: f[expr_ /; ! FreeQ[expr, F[x_]] && ! FreeQ[expr, G[-x_]]] := 0; f[expr_] := expr. tested with f[F[Sin[x]]*G[Sin[-x]]] is 0 because MMA replaces G[Sin[-x]] with G[-Sin[x]].
– Alx
Nov 13 '19 at 13:05
• Yes, this works at first glance but I am not really sure it distinguishes the x argument correctly that it is the same in both F and G. Try this for example f[F[X] G[-Z]] this is evaluated to zero when it shouldn't since they do not have the same argument. Nov 13 '19 at 15:40

Probably this should work:

ClearAll[f]
f[expr_ /; Cases[expr, F[x_] -> x, ∞, Heads -> True] ==
-Cases[expr, G[x_] -> x, ∞, Heads -> True]] := 0
f[expr_] := expr


Some testing:

f[kk[X]@F[X]@rr[X]@G[-X]] = 0
f[kk[X]@F[X]@rr[X]@G[-Z]] = kk[X][F[X][rr[X][G[-Z]]]]
f[F[X]@rr[X]@G[-Z]@zz[w]] = F[X][rr[X][G[-Z][zz[w]]]]
f[F[X]@rr[X]@G[-X]@zz[w]] = 0
f[F[X]@G[-Z]] = F[X][G[-Z]]
f[F[X]@G[-X]] = 0
f[F[X]/G[-X]] = 0
f[F[X]*G[-Z]] = F[X] G[-Z]
f[F[X^2]*G[-X^2]] = 0
f[F[Sin[X^2]]*G[Sin[-X^2]]] = 0