I want to use custom transformation functions in Simplify, but Mathematica does not seem to use them properly. Consider the following

t1[a] := 1
t2[b] := 0
FullSimplify[a + b, TransformationFunctions -> {t1, t2}]

As intended this evaluates to 1. However, if I add the standard transformation functions nothing happens:

FullSimplify[a + b, TransformationFunctions -> {Automatic, t1, t2}]

This gives a + b. Why did Mathematica forget about my custom functions? Ideas?


Interesting question. I don't know if this behavior is intended but I think I can at least give some insight into the problem.

We can use a custom ComplexityFunction with an embedded Print to take a look at what transformed expressions are tested.

cf = (Print[#]; LeafCount[#] + Count[#, _Symbol, {0, -1}]) &;

We will also need to make use of ClearSystemCache[] to see all simplification attempts.

First without Automatic:

Simplify[a + b, TransformationFunctions -> {t1, t2}, ComplexityFunction -> cf]

Observe that for whatever reason t1 and t2 are not applied to atomic elements when Automatic is included:

Simplify[a + b, TransformationFunctions -> {Automatic, t1, t2}, ComplexityFunction -> cf]

While the cause is not clear the solution is: write your transformation functions so that they work on compound expressions.

For example:

t3 = # /. {a -> 1, b -> 0} &;

Simplify[a + b, TransformationFunctions -> {Automatic, t3}]

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.