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:





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


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
  • $\begingroup$ Does this work for you: f[expr_ /; ! FreeQ[expr, _F] && ! FreeQ[expr, _G]] := 0; f[expr_] := expr ? $\endgroup$
    – Alx
    Nov 13 '19 at 12:15
  • $\begingroup$ 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]. $\endgroup$ Nov 13 '19 at 12:26
  • $\begingroup$ 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]]. $\endgroup$
    – Alx
    Nov 13 '19 at 13:05
  • $\begingroup$ 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. $\endgroup$ Nov 13 '19 at 15:40

Probably this should work:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.