0
$\begingroup$

I am a new user of Mathematica and have been trying to find a method for verifying equality. The issue that I keep running into is that nothing seems to work for all cases. Let me give you some examples:

  • in: True === (x^2)/x == x
  • out: True
  • Good
  • in:True === ab + b^2 + bc == b (a + b + c)
  • out:False
  • Bad
  • in:True === FullSimplify[ab + b*b + bc == b (a + b + c)]
  • False
  • Bad
  • in:(x^2)/x === x
  • out:True
  • Good
  • in:Sqrt[(x + y^2)/y] === Sqrt[x/y + y]
  • out:Fals
  • Bad

Is there any "one size fits all" type approach that will work for me. It just does not make sense to me how it says (x^2)/x is x but Sqrt[(x + y^2)/y] is not Sqrt[x/y + y].

$\endgroup$
5
  • $\begingroup$ Try this Reduce[a b + b^2 + b c == b (a + b + c)] and Reduce[Sqrt[(x + y^2)/y] == Sqrt[x/y + y]] . $\endgroup$ Commented May 21, 2022 at 18:55
  • $\begingroup$ Note a b not ab. In particular, Simplify[a b + b*b + b c == b (a + b + c)] works as desired. $\endgroup$
    – Michael E2
    Commented May 21, 2022 at 19:03
  • 2
    $\begingroup$ (1) Note that === (SameQ) is for identical expressions, not mathematically nor computationally equivalent expressions. Thus Simplify[Sqrt[(x + y^2)/y] == Sqrt[x/y + y]] but not Simplify[Sqrt[(x + y^2)/y] === Sqrt[x/y + y]]. (2) I sometimes have more success with Simplify[X - Y] instead of Simplify[X == Y] (compare equal to 0). (3) Simplification in Mma is an expression minimization problem, not a mathematical problem. It tries to make the expression tree as small as possible, using a finite set of transformations. It's not exactly the same as what is taught in algebra class. $\endgroup$
    – Michael E2
    Commented May 21, 2022 at 19:13
  • $\begingroup$ Related: (8796), (159648), (229204). Possible duplicate: (115303) $\endgroup$
    – Michael E2
    Commented May 21, 2022 at 19:19
  • $\begingroup$ You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is useful for learning how to format your questions and answers. You may also find the meta Q&A, How to copy code from Mathematica so it looks good on this site, helpful $\endgroup$
    – Michael E2
    Commented May 22, 2022 at 15:29

1 Answer 1

2
$\begingroup$

See Evaluating an If condition to yield True/False and the linked questions for a discussion of the difference between === and ==. Don't use === for the OP's examples; use == instead. I'm discounting the apparent mistake writing ab without a space between the a and the b. Like in most programming languages, a string of letters without punctuation or white space signifies a single Symbol or "identifier".

Perhaps the only difference I see between Testing equivalence of analytical expressions like $x^2 -x == x(x-1)$ and this question is the role of autosimplification, which may explain why the question has not been closed. Since no one has voted to close yet, I will attempt to answer. Sometimes autosimplification and simplification via Simplify[] and FullSimplify[] are confused and lead to a misunderstanding of when a particular simplifying step happens.

Here are the OP's examples with Equal replacing SameQ per the advice in the linked Q&A; Simplify works on all five three:

testEqual = {
  Sqrt[(x + y^2)/y] == Sqrt[x/y + y],
  (x^2)/x == x, 
  a b + b*b + b c == b (a + b + c)
  (* , (x^2)/x == x,  <-- becomes the same the first *)
  (* Sqrt[(x + y^2)/y] == Sqrt[x/y + y]  (* ditto *)};

Simplify /@ testEqual
(*  {True, True, True}  *)

The last question in the OP concerns autosimplification, in particular of the expressions x^2/x and (x + y^2)/y. As far as I know, neither the autosimplification rules nor the transformation rules used in either Simplify or FullSimplify are documented. So you have to get used to them. There's not much the user can do about autosimplify rules, except for a couple of options in SystemOptions["SimplificationOptions"], neither of which apply here.

The first expression x^2/x has the FullForm

Times[Power[x, 2], Power[x, -1]]

There is an autosimplify rule that combines the product of powers that have the same base. This happens notoriously for x/x, too. So x^2/x first evaluates to x. The OP's comparison of x^2/x with x becomes a comparison of x to x. It does not matter whether === or == is used in this special case; both return True.

The second expression (x + y^2)/y has the FullForm

Times[Power[y, -1], Plus[x, Power[y, 2]]]

Any algebraic simplification involves rewriting the expression and testing whether the result is simpler -- and if not, you just wasted the user's time. Unlike combining like bases, there isn't a general rule that always simplifies this expression. Something similar can be said about the expression it is compared to, x/y + y. Sometimes users need the terms separated (hence Expand[]) and sometimes combined as a rational function (hence Together[]). Neither expression should be autosimplified. For the OP's comparison, one needs to use Simplify (and Equal!).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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