2
$\begingroup$

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!!

$\endgroup$
3
  • 1
    $\begingroup$ 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 $\endgroup$
    – Bob Hanlon
    Apr 29, 2020 at 4:19
  • $\begingroup$ What is the difference between x being a dummy variable and the whole f[x] g[x] being a dummy variable ? $\endgroup$ Apr 29, 2020 at 6:38
  • $\begingroup$ 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... $\endgroup$
    – MaxB
    Apr 29, 2020 at 13:23

1 Answer 1

1
$\begingroup$

Use TagSet

ClearAll[F]

F /: F[arg1__] - F[arg2__] /;
   (Head[arg1] === Head[arg2] === Times &&
     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,
     F[arg_?(Head[#] === Times &&
           Length@Union[List @@@ List @@ #] == 1 &)] :>
      (List @@ arg)[[1, 1]], Infinity] // Union;
  rules = Thread[Rest[vars] -> First[vars]];
  expr /. F[
     arg_?(Head[#] === Times &&
         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]]} *)
$\endgroup$
5
  • $\begingroup$ 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! $\endgroup$
    – MaxB
    Apr 29, 2020 at 18:58
  • $\begingroup$ @MaxB - See edit. $\endgroup$
    – Bob Hanlon
    Apr 29, 2020 at 20:32
  • $\begingroup$ 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! $\endgroup$
    – MaxB
    Apr 29, 2020 at 23:07
  • $\begingroup$ @MaxB - Do not ask new questions in comments. Post a new question. Note that there is a syntax error in your comment. $\endgroup$
    – Bob Hanlon
    Apr 29, 2020 at 23:11
  • $\begingroup$ thanks! (& sorry for the syntax). I will try to work out myself the second case. $\endgroup$
    – MaxB
    Apr 29, 2020 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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