Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The documentation for Simplify[expr] says that it performs a sequence of algebraic and other transformations on expr, and returns the simplest form it finds. How can I see which transformations it applies?

share|improve this question

1 Answer 1

up vote 18 down vote accepted

I thought of this question while on the train but the solution appeared in my brain as soon as I got into work. All you need to do is create a ComplexityFunction that includes a side effect

f[x_] := (Print[x];
  LeafCount[x])

Simplify[TrigExpand[Tan[x + y]], ComplexityFunction -> f]

This gives the following output

(Cos[y] Sin[x])/(Cos[x] Cos[y]-Sin[x] Sin[y])+(Cos[x] Sin[y])/(Cos[x] Cos[y]-Sin[x] Sin[y])
(Cos[y] Sin[x]+Cos[x] Sin[y])/(Cos[x] Cos[y]-Sin[x] Sin[y])
(Cos[y] Sin[x]+Cos[x] Sin[y])/(Cos[x] Cos[y]-Sin[x] Sin[y])
(Cos[y] Sin[x]+Cos[x] Sin[y])/(Cos[x] Cos[y]-Sin[x] Sin[y])
(Cos[y] Sin[x])/(Cos[x] Cos[y]-Sin[x] Sin[y])+(Cos[x] Sin[y])/(Cos[x] Cos[y]-Sin[x] Sin[y])
(1/2 Csc[x] Sin[2 x] Sin[y]+1/2 Csc[y] Sin[x] Sin[2 y])/(-Sin[x] Sin[y]+1/4 Csc[x] Csc[y] Sin[2 x] Sin[2 y])
(Cos[y] Sin[x]+Cos[x] Sin[y])/(Cos[x] Cos[y]-Sin[x] Sin[y])
Tan[x+y]
Tan[x+y]
x+y
x+y
x+y
x+y
x+y
x+y
x+y  
x+y
x+y
x+y
x+y  
Tan[x+y]
Tan[x+y]
(Cos[y] Sin[x])/(Cos[x] Cos[y]-Sin[x] Sin[y])+(Cos[x] Sin[y])/(Cos[x] Cos[y]-Sin[x] Sin[y])
Tan[x+y]

Note that this shows every expression that the ComplexityFunction is applied to. Clearly x+y is not equivalent to Tan[x+y]

It is interesting to also apply this to FullSimplify to see all of the extra transformations that get applied

FullSimplify[TrigExpand[Tan[x + y]], ComplexityFunction -> f]
share|improve this answer
    
+1. I used this method all the time when dealing with Simplify/FullSimplify a lot, some years ago. –  Leonid Shifrin Nov 28 '12 at 9:53
1  
One thing that I wonder is 'Does the choice of complexity function affect which transformations get applied? In other words, does Simplify do some sort of intelligent optimization or does it just try out a standard suite of transforms and return the best' I've not investigated this. –  WalkingRandomly Nov 28 '12 at 10:03
1  
IIRC, the choice of transformations does indeed depend on the complexity function generally. The problem is that the optimization seems to be rather "local" in many cases (in the space of transformations), so that it is often hard to come up with a complexity function which would significantly change the tranformation chain. But if memory serves, I managed to do this a few times for cases which were of interest to me. –  Leonid Shifrin Nov 28 '12 at 10:07
1  
Something that I'd really like to do is to say to Mathematica 'Go Crazy..try as many things as you can possibly think of subject to a time limit of X seconds' Might help discover interesting relationships. –  WalkingRandomly Nov 28 '12 at 10:11
1  
I think the hardest part is actually to limit the space of possible transformation in a sensible way given the time constraints. So, in a sense, what you are thinking of is exactly what Simplify and friends should not be doing if you want any results in reasonable time. These commands don't do things the way humans do, and lack the intuition which allows humans to pick the right routes to follow. –  Leonid Shifrin Nov 28 '12 at 10:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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