# More on the FullSimplify function

In 12.2.0 for Microsoft Windows (64-bit) (December 12, 2020), writing:

expr = (f1 J31 - f3 J11) (J22 J43 - J23 J42) -
(f1 J32 - f3 J12) (J21 J43 - J23 J41) +
(f2 J43 - f4 J23) (J11 J32 - J12 J31);

FullSimplify[Expand[expr]]


I get:

J23 (f4 J12 J31 - f4 J11 J32 - f3 J12 J41 + f1 J32 J41 + f3 J11 J42 - f1 J31 J42) +
(f3 J12 J21 - f3 J11 J22 - f2 J12 J31 + f1 J22 J31 + f2 J11 J32 - f1 J21 J32) J43


Therefore, according to the Mathematica algorithms, this latter expression is "simpler" than the first.

I realize that what is simple for me isn't necessarily simple for others, but I was wondering if it was possible to instruct Mathematica to obtain the first expression (starting from the expanded form).

Thank you!

I think this is a case where "Simplify" and "FullSimplify" fail to obtain the optimal answer.

According to the manual:

ComplexityFunction: how to assess the complexity of each form generated

With the default setting ComplexityFunction->Automatic, forms are ranked primarily according to their LeafCount, with corrections to treat integers with more digits as more complex.

We therefore need to look at "LeafCount" to understand what is going on. Again from the manual:

LeafCount counts the number of subexpressions in expr that correspond to "leaves" on the expression tree.

Now the "LeafCount" turns out to be the same as the number of nodes in the "TreeForm" of an expression. E.g.:

LeafCount[1 + a + b^2]
(* 6 *)
TreeForm[1 + a + b^2]


Now back to our expression:

expr = (f1 J31 - f3 J11) (J22 J43 - J23 J42) - (f1 J32 -
f3 J12) (J21 J43 - J23 J41) + (f2 J43 - f4 J23) (J11 J32 -
J12 J31);
LeafCount[expr]
(* 53 *)


If we now expand expr, the LeafCount increases:

LeafCount[Expand@expr]
(* 67 *)


and when we apply Simplify or FullSimplify:

{ LeafCount[Simplify[#]], LeafCount[FullSimplify[#]]} & [Expand@expr]
(* {66, 61} *)
`

what is worse than the LeafCount of the expression (53) we started with.

• @DanielHuber FullSimplify look for "local" and not "global" minimum of leaf count. In the example above "global" minimum is outside of reach by standard simple transformations. It could be that in order to obtain the desired form, one may need, for example to add and subtract the same term (which disappear during expansion).
– Acus
Commented May 3, 2021 at 10:23
• @user18792 Thank's for the hint Commented May 3, 2021 at 11:55