4

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.

kglr
  • 394,356
  • 18
  • 477
  • 896
tparker
  • 1,856
  • 12
  • 22
  • The automatic ComplexityFunction is SimplifyCount in ComplexityFunction >> Properties and Relations – kglr Aug 07 '17 at 07:33
  • 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]]. – kglr Aug 07 '17 at 07:40
  • @kglr Great, thanks. Convert to an answer and I'll accept. – tparker Aug 07 '17 at 07:45
  • Similar: https://mathematica.stackexchange.com/questions/26172/how-do-i-invoke-the-default-complexity-function – Michael E2 Aug 07 '17 at 11:00
  • 3
    @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. – Michael E2 Aug 07 '17 at 11:04
  • 5
    Note that -(a + b) evaluates to -a - b, so Simplify is irrelevant. – ilian Aug 07 '17 at 13:33
  • 2
    @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 https://mathematica.stackexchange.com/questions/153273/how-does-simplify-resolve-simplifycount-ties. – tparker Aug 07 '17 at 17:42
  • tparker please unaccept my answer so that i can delete it – kglr Aug 08 '17 at 00:19
  • @MichaelE2 or Mr.Wizard, i would expect a downvote on the question before one on an accepted answer. – kglr Aug 08 '17 at 00:29
  • @kglr Why? Even if it's a simple mistake, I think your answer is useful. – tparker Aug 08 '17 at 00:29
  • tparker, (despite the wrong example) I think your question is a good one and its title is exceptionally clear. – kglr Aug 08 '17 at 00:44
  • @kglr So why did you delete your answer? – tparker Aug 08 '17 at 00:50
  • @kglr I wasn't me. I usually expect someone to state a reason for the DV. I usually only DV answers that do not do what they claim to do or are in some way "dangerous" and I think should be deleted. That happens rarely, and even more rarely does it have anything at all to do with the quality of the question. – Michael E2 Aug 08 '17 at 01:10
  • @Mr.Wizard, thank you for your clarification re the downvote on my (now deleted) answer. – kglr Dec 30 '17 at 08:39

0 Answers0