I define a simple TransformationFunctions via:

tfTest[e_] := e /. {x^2 -> Hold[x*x]}

and try to use it with Simplify like this:

Simplify[x^2, TransformationFunctions -> {Automatic, tfTest}]

x^2 (output)

The output is of course the input without tfTest applied to it. Interestingly a TransformationFunction like

tfTest[e_] := e /. {x^2 -> 2}

is working.

I tried monitoring the output via using a ComplexityFunction

cf = (Print[#]; LeafCount[#] + Count[#, _Symbol, {0, -1}]) &;
FullSimplify[x^2, TransformationFunctions -> {Automatic, tfTest}, 
 ComplexityFunction -> cf]

but I could not make sense of the output being an alternating sequence of the answer I would want and the unchanged input.

Any ideas how to fix that?

  • 2
    $\begingroup$ Hint: Simplify tries to minimize ComplexityFunction. $\endgroup$ – Michael E2 Oct 13 '15 at 13:59
  • $\begingroup$ Makes sense that it tries to minimize ComplexityFunction. For some reason I was naive enough to think that manually supplied TransformationFunctions have absolute priority. $\endgroup$ – Wizard Oct 19 '15 at 11:25
tfTest[e_] := e /. {x^2 -> Hold[x*x]}

f[e_] := LeafCount[e] +
  100 Count[e, _Power, {0, Infinity}]

 TransformationFunctions -> {Automatic, tfTest},
 ComplexityFunction -> f]

(*  Hold[x x]  *)

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.