At the end of some computation I arrive at a lengthy but purely numerical expression involving roots. I wonder why Mathematica left me with this result (I manually indented it such that opening and associated closing parentheses vertically match to make the structure for a human reader more easy to recognize):

expr = (2/Sqrt[33] - 
        (Sqrt[2/165] + Sqrt[6/55])/Sqrt[10]
       )/Sqrt[25/33 + 
              (2/Sqrt[33] - 
               (3*(Sqrt[2/165] + Sqrt[6/55]))/Sqrt[10]
              )^2 + 
              (2/Sqrt[33] - 
               (Sqrt[2/165] + Sqrt[6/55])/Sqrt[10]
             ] == 
       6/Sqrt[665]                                            (* 1 *)

If I take the lhs of this expression, Mathematica still leaves me with it after I copy it and paste it to a new expression which I execute then:

lhs = (2/Sqrt[33] - 
       (Sqrt[2/165] + Sqrt[6/55])/Sqrt[10]
      )/Sqrt[25/33 + 
             (2/Sqrt[33] - 
              (3*(Sqrt[2/165] + Sqrt[6/55]))/Sqrt[10]
             )^2 + 
             (2/Sqrt[33] - 
              (Sqrt[2/165] + Sqrt[6/55])/Sqrt[10]
            ]                                                 (* 2 *)

This expression remains unchanged (except for format change).

However, if I expressively apply Together or Simplify to lhs the result is


which of course should have resulted in True for (* 1 *) if it would have been computed there.

If Mathematica would have applied the rule

Equal[a_, b_] :> Equal[Simplify[a], Simplify[b]]`

to (* 1 *) it would have resulted in True:

expr /. Equal[a_, b_] :> Equal[Simplify[a], Simplify[b]]      (* 3 *)

yields True. Of course, a delayed rule ( :> ) has to be applied here instead of a normal one ( -> ).

If I replace the equal sign in expr by a subtraction, it still leaves me with a lengthy purely numerical result which easily could be reduced from leaf count of 111 by simply applying Together to 0, a result with a leaf count of 1.


Why does Mathematica not try Together to simplify this purely numerical result?

How can one "teach" Mathematica to apply Together to large purely numerical sub-expressions like the ones discussed in this post?


closed as off-topic by Feyre, Bob Hanlon, Edmund, m_goldberg, happy fish Oct 31 '16 at 10:53

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." – Feyre, Bob Hanlon, Edmund, m_goldberg, happy fish
If this question can be reworded to fit the rules in the help center, please edit the question.


How can one "teach" Mathematica to try Together on the lhs and on the rhs of an equation separately if it was not able to decide it before doing so?

You could use the built-in global variable $Post to this end.

The following definition tries reformulating the left-hand side lhs and right-hand side rhs of an output expression of the form lhs == rhs. The way both sides of the equation are reexpressed is given by the symbols lhsTransform and rhsTransform, the definitions of which are given separately.

$Post = Module[{expr = #, lhs, rhs},
          If[Head[expr] === Equal,
              lhs = First@ expr;
              rhs = Last@ expr;
              lhsTransform[lhs] == rhsTransform[rhs],

For your specific question, the post-processing could be called with the transformation functions:

lhsTransform[lhs_] := Together[lhs];
rhsTransform[rhs_] := Together[rhs];

which gives the expected result:

(2/Sqrt[33] - (Sqrt[2/165] + Sqrt[6/55])/Sqrt[10]) / 
Sqrt[25/33 + (2/Sqrt[33] - (3*(Sqrt[2/165] + Sqrt[6/55]) ) / Sqrt[10])^2 
           + (2/Sqrt[33] - (Sqrt[2/165] + Sqrt[6/55]) / Sqrt[10])^2
] == 6/Sqrt[665]

(* True *)

Note that the definitions of lhsTransform and rhsTransform are minimal, they do not check whether a given side is NumericQ. They will apply accordingly the symbol Together for non purely numeric arguments as well.

To get this restriction, the definitions could be refined as

lhsTransform[lhs : Except[_Integer | _Rational | _Real | _Complex, _?NumericQ]] := 
lhsTransform[lhs_] := lhs;
rhsTransform[rhs : Except[_Integer | _Rational | _Real | _Complex, _?NumericQ]] := 
rhsTransform[rhs_] := rhs;

The exceptions on the heads of lhs and rhs avoid Together to be applied on numeric quantities that would remain unchanged.

  • $\begingroup$ Yes, \$Post = Simplify or \$PrePrint = Simplify did solve my problem, even those problems which I added in my edidet post. Xavier goes one step further how to restrict Simplify to expressions lhs==rhs. $\endgroup$ – Adalbert Hanßen Nov 5 '16 at 11:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.