4
$\begingroup$

The documentation for ComplexityFunction says

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.

and

LeafCount[-a - b] == LeafCount[-(a + b)] == 7
>> True

so I would expect that Simplify would not change either expression. But

Simplify[-a - b]
>> -a - b

Simplify[-(a + b)]
>> -a - b

seems to imply that Mathematica considers the expression -a - b to be strictly simpler than -(a + b). Why is it doing so, since the two expressions seem to have the same complexity as measured by LeafCount? I'm not sure whether to interpret the quoted sentence in the documentation as saying that the integer-digit correction to LeafCount is the only correction, or if it is just giving the integer-digit correction as one example of multiple corrections.

$\endgroup$

closed as off-topic by Mr.Wizard Aug 7 '17 at 18:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ The automatic ComplexityFunction is SimplifyCount in ComplexityFunction >> Properties and Relations $\endgroup$ – kglr Aug 7 '17 at 7:33
  • $\begingroup$ tparker it is in the last section in the linked page. It also gives the same value for both expressions because both functions are seen as Plus[Times[-1, a], Times[-1, b]]. $\endgroup$ – kglr Aug 7 '17 at 7:40
  • 3
    $\begingroup$ @kglr, tparker: Forgive me, but both LeafCount and SimplifyCount yield ties. I don't see how the question (how ties are resolved) has been answered yet. $\endgroup$ – Michael E2 Aug 7 '17 at 11:04
  • 5
    $\begingroup$ Note that -(a + b) evaluates to -a - b, so Simplify is irrelevant. $\endgroup$ – ilian Aug 7 '17 at 13:33
  • 2
    $\begingroup$ @MichaelE2 Good point. kglr's comment answers both the explicit question "explain this particular behavior" and the implicit question "clarify the LeafCount documentation" in the body of the OP, so I accepted their posted answer (although ironically, as written it only answers the implicit question). I've spun the question off in the title as a separate question at mathematica.stackexchange.com/questions/153273/…. $\endgroup$ – tparker Aug 7 '17 at 17:42