14

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?

xzczd
  • 65,995
  • 9
  • 163
  • 468
Berg
  • 1,059
  • 5
  • 14

1 Answers1

9

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:

ClearSystemCache[]
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:

ClearSystemCache[]
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}]
 1
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371