The expressions a (b + c) + b c and a b + (a + b) c are equivalent and equally complex as measured by SimplifyCount:

Reduce[a (b + c) + b c == a b + (a + b) c]
(* True *)

SimplifyCount[a (b + c) + b c] == SimplifyCount[a b + (a + b) c] == 9
(* True *)

And unlike the example that I used in How does `Simplify` resolve `LeafCount` ties?, the two expressions are not automatically simplified to the same expression before Simplify evaluates them:

a (b + c) + b c
(* b c + a (b + c) *)

a b + (a + b) c
(* a b + (a + b) c *)

a (b + c) + b c === a b + (a + b) c
(* False *)

Nevertheless, Simplify converts the latter expression into the former:

Simplify[a (b + c) + b c]
(* b c + a (b + c) *)

% === a (b + c) + b c
(* True *)

Simplify[a b + (a + b) c]
(* b c + a (b + c) *)

% === a b + (a + b) c
(* False *)

How does Simplify decide which expression is simpler, if they have the same SimplifyCount?

My guess is that it always breaks ties by going with whichever expression comes last in canonical order:

Sort[{a (b + c) + b c, a b + (a + b) c}]
(* {a b + (a + b) c, b c + a (b + c)} *)

Is this always the case? If so, then Simplify actually uses a total order on expressions, rather than the total preorder given by SimplifyCount.

  • $\begingroup$ I'm not seeing how this is not just a clarification of your previous question, linked above. $\endgroup$
    – Michael E2
    Aug 7 '17 at 17:39
  • $\begingroup$ @MichaelE2 While I didn't realize this when I posted it, the answer to my previous question had nothing at all to do with the behavior of Simplify - the "tie" was completely trivial because Simplify was evaluating the same expression in both instances. Since there was no actual nontrivial SimplifyCount tie, the premise of my question was invalid. This question really does concern a nontrivial SimplifyCount tie, so its answer will be unrelated to the answer to my previous question. $\endgroup$
    – tparker
    Aug 7 '17 at 17:48
  • $\begingroup$ I marked the older question as "a simple mistake" -- let this question stand as the corrected/clarified version. ( @MichaelE2 ) $\endgroup$
    – Mr.Wizard
    Aug 7 '17 at 18:03
  • $\begingroup$ @Mr.Wizard Originally, given the accepted answer, it seemed a duplicate of (26172), which contains the same answer!, despite the semantic differences in the stated questions; tparker's comment makes them seem more like duplicates. But ilian's comment shows it is indeed a simple mistake. Let it stand. $\endgroup$
    – Michael E2
    Aug 7 '17 at 20:21
  • $\begingroup$ @tparker I don't see anything in the prior question that would not also be addressed if this question is adequately answered. You did not realize that Simplify was redundant in that example so it really has nothing to do with Simplify, and if it were corrected it would become equivalent to this one I believe. You might instead ask "why does -(a + b) evaluate to -a - b but that is yet again a different question and not the one you asked, as I read it. I don't mean to discourage you; I find this an interesting question and you have my vote on it. $\endgroup$
    – Mr.Wizard
    Aug 7 '17 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.