Mathematica fails to put the following into an obvious simplest form:

   numerator = C2p D2 (C1y N1x - C1x N1y - C1y N2x + N1y N2x + C1x N2y - N1x N2y) + 
C1p D1 (-(C2y N1x) + C2x N1y + C2y N2x - N1y N2x - C2x N2y + N1x N2y)

numerator = Simplify[numerator]  


C2p D2 (-(C1x N1y) + C1y (N1x - N2x) + N1y N2x + C1x N2y - N1x N2y) + 
C1p D1 (C2x N1y - N1y N2x + C2y (-N1x + N2x) - C2x N2y + N1x N2y)  

which has obvious simplification failures

If I change the name of a variable it succeeds.

numerator = ReplaceAll[numerator,{N2y -> aN2y}]
numerator = Simplify[numerator]

C2p D2 (aN2y (C1x - N1x) + C1y (N1x - N2x) + N1y (-C1x + N2x)) +
 C1p D1 (aN2y (-C2x + N1x) + N1y (C2x - N2x) + C2y (-N1x + N2x))

numerator = ReplaceAll[numerator,{aN2y -> N2y}]

    C2p D2 (C1y (N1x - N2x) + N1y (-C1x + N2x) + (C1x - N1x) N2y) +
 C1p D1 (N1y (C2x - N2x) + C2y (-N1x + N2x) + (-C2x + N1x) N2y)

Once one knows that success depends on the variable names, possibly an alphabetic sort order in the sum somewhere, one knows what to do in order to simplify, but I am concerned about much bigger expressions where you don't know that you need to trick it. Is there any way to get Mathematica to get past this variable name dependence? FullSimplify does not help here.

  • 4
    $\begingroup$ If you do SetOptions[Simplify, ComplexityFunction -> LeafCount] the results are indepent or variable name change. So it has to do with the "Automatic" setting of ComplexityFunction. However, I don't know what Automatic means here. And no, the SimplifyCount function mentioned in ref/ComplexityFunction (advertised as "The automatic complexity function") is obviously not the Automatic setting of of Simplify, since doing SetOptions[Simplify, SimplifyCount] behaves differently from the default setting. This is one example where the documentation could be improved. Unexplained Automatic's are bad $\endgroup$ – Rolf Mertig Mar 25 '13 at 20:42
  • 2
    $\begingroup$ I attempted an explanation of this phenomenon in this related post $\endgroup$ – Jens Mar 25 '13 at 21:07
  • $\begingroup$ Closely related question and MathGroup thread. $\endgroup$ – Mr.Wizard Mar 29 '13 at 1:10

Thanks for pointing out LeafCount. The LeafCount for the original result and the result obtained by variable renaming are the same (51). Mathematica must be staying with the first form that it gets with that minimum leaf count. Changing the variable names must affect the order in which the forms show up in the search, causing the desired expression to be the first one that appears in the search with the minimum leaf count. Understanding that, I would presume that it is possible to write one's own function to judge the simplicity that penalizes the failure to find the remaining opportunities to factor sub-terms in the expression.


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.