# Defining functions with Dummy variables

I have defined a functional F, whose argument are product of functions: F[ f[x] g[x] h[x]...]

I need x to be a "dummy variable". That is, I need Mathematica to understand that, for example,

F[ f[x] g[x] ] - F[ f[y] g[y] ] =0

Is there a way to do this?

Thanks!!

• You can use TagSet. F /: F[f[x_] g[x_]] - F[f[y_] g[y_]] = 0; Then F[f[z] g[z]] - F[f[t] g[t]] + c evaluates to c Apr 29, 2020 at 4:19
• What is the difference between x being a dummy variable and the whole f[x] g[x] being a dummy variable ? Apr 29, 2020 at 6:38
• thanks Bob: what you suggest is what I have been doing so far. The problem is that I have terms with different number of functions inside F : F[ h1[x] h2[]x] h3[x]....hn[x]]. Using TagSet I have to do it case by case...
– MaxB
Apr 29, 2020 at 13:23

Use TagSet

ClearAll[F]

F /: F[arg1__] - F[arg2__] /;
Length@Union[List @@@ List @@ arg1] ==
Length@Union[List @@@ List @@ arg2] == 1&&
(Head /@ List @@ arg1) === (Head /@ List @@ arg2)) = 0;

The number of factors can vary

F[f[x] g[x]] - F[f[y] g[y]]

(* 0 *)

F[f[x] g[x] h[x]] - F[f[y] g[y] h[y]]

(* 0 *)

F[f[x] g[x] h[x] k[x]] - F[f[y] g[y] h[y] k[y]]

(* 0 *)

The order of the arguments' factors does not matter

F[f[x] g[x] h[x]] - F[f[y] h[y] g[y]]

(* 0 *)

EDIT: The extension of the problem given in your comment, "I would like 2*F[h[x] k[x]] - F[h[y] k[y]] to give F[h[x] k[x]]", is not readily handled by TagSet since F would be buried too deeply in the more general expression. Using an alternative approach

ClearAll[F]

simplifyF[expr_] := Module[{var, rules},
vars = Cases[expr,
Length@Union[List @@@ List @@ #] == 1 &)] :>
(List @@ arg)[[1, 1]], Infinity] // Union;
expr /. F[
Length@Union[List @@@ List @@ #] == 1 &)] :>
(F[arg] /. rules)]

testExpression = {F[f[x] g[x]] - F[f[y] g[y]],
F[f[x] g[x] h[x]] - F[f[y] g[y] h[y]],
F[f[x] g[x] h[x] k[x]] - F[f[y] g[y] h[y] k[y]],
F[f[x] g[x] h[x]] - F[f[y] h[y] g[y]],
2*F[h[x] k[x]] - F[h[y] k[y]],
7*F[h[x] k[x]] - 5 F[h[y] k[y]]};

simplifyF@testExpression

(* {0, 0, 0, 0, F[h[x] k[x]], 2 F[h[x] k[x]]} *)
• wow, this seems to work. One little extra feature. I would like 2*F[h[x] k[x]] - F[h[y] k[y]] to give F[h[x] k[x]]. Your formula does not seem to give that. Thanks!
– MaxB
Apr 29, 2020 at 18:58
• @MaxB - See edit. Apr 29, 2020 at 20:32
• This is what I needed ! Thanks! Now, for my next application I need F[ h[x] k[y] G[x,y] = F[ h[w] k[z] G[w,z] ] the same logic but with 2 dummy variables. I am trying to work it out myself following your idea.... but I am definitely not an expert!
– MaxB
Apr 29, 2020 at 23:07
• @MaxB - Do not ask new questions in comments. Post a new question. Note that there is a syntax error in your comment. Apr 29, 2020 at 23:11
• thanks! (& sorry for the syntax). I will try to work out myself the second case.
– MaxB
Apr 29, 2020 at 23:46