2
$\begingroup$

Consider the simple example :

ff[x_] := x^2

gg[x_] := (ff[x] - ff[-x])^2

Let's assume I would like to expand g[x_] as a polynome of ff[x] and ff[-x], but I don't want mathematica to replace ff[x] by their value x^2 (even if it is defined in my code).

How can I do it ?

Said differently : I would like to Expand[gg[x]] such that I would have a polynome in ff[x], ff[-x] where they are not evaluated.

I want to do it to check consistancy in some functions I defined in a more complicated code (if mathematica replaces me all the function by their values it will be hard for me to check this).

$\endgroup$
  • 1
    $\begingroup$ perhaps defining gg as ClearAll[gg]; gg[x_] :=Inactivate[ (ff[x] - ff[-x])^2,ff]? $\endgroup$ – kglr Jun 27 at 10:11
  • $\begingroup$ ... or as gg[x_] := (HoldForm[ff][x] -HoldForm[ ff][-x])^2? $\endgroup$ – kglr Jun 27 at 10:17
  • $\begingroup$ @kglr and is there a way from the "outside" to do it ? Because it would ask me to redefine my function g. Like is there a way to do "Expand[NotEvaluateInside[gg[x]]" ? It could be more clean for my notebook to not redefine my functions if I just want to check their expression $\endgroup$ – StarBucK Jun 27 at 11:27
  • 1
    $\begingroup$ how about ClearAll[gg];gg[x_] := (ff[x] - ff[-x])^2; Block[{ff=Inactive[ff]}, Expand[gg[x]]]? $\endgroup$ – kglr Jun 27 at 11:34

Your Answer

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

Browse other questions tagged or ask your own question.