Message Boards Message Boards

0
|
1255 Views
|
14 Replies
|
6 Total Likes
View groups...
Share
Share this post:

How to check expressions for symbolic equality? (some unexpected results)

Posted 3 months ago

Thanks to Eric in the previous post, I found that I could use Simplify along with Equal to find when two symbolic expressions are equal.

ie, Mathematica returns "True" when Mathematica considers them equal,
and returns a "function" when Mathematica considers them different.

I tested all of the following examples in Wolfram Cloud: Wolfram Mathematica.

Here are four examples where Mathematica returns expected results:

// Desired result: True, Mathematica result: True

Simplify[Equal[ToExpression["(a+b)-c"],ToExpression["(a-c)+b"]]]

// Desired result: False, Mathematica result: "b == c"

Simplify[Equal[ToExpression["(a-b)+c"],ToExpression["(a-c)+b"]]]

// Desired result: True, Mathematica result: True

Simplify[Equal[ToExpression["(a-b)/((c-d)^(d-e))"], ToExpression["(a-b)\*((c-d)^(e-d))"]]]

// Desired result: False, Mathematica result: "(a-b)*((c-d)^(-d+e)-(-c+d)^(-d+e)) == 0"

Simplify[Equal[ToExpression["(a-b)/((c-d)^(d-e))"], ToExpression["(a-b)\*((d-c)^(e-d))"]]]

However, I have found examples where Mathematica fails to correctly identify two symbolic expressions as equivalent.

Here are two such examples:

// Desired result: True, Mathematica result: "(a^b)^c == (a^c)^b"

Simplify[Equal[ToExpression["(a^b)^c"],ToExpression["(a^c)^b"]]]

// Desired result: True, Mathematica result: "(a^(b*c) == (a^b)^c"

Simplify[Equal[ToExpression["(a^b)^c"],ToExpression["(a^(b\*c)"]]]

1) Is there any way to get Mathematica to correctly interpret these inputs as equivalent?

2) Is there some mathematical assumption that I can adjust to fix the Equal check?

3) Is this a bug in Mathemtaica?

Thanks for any help anyone can provide.

POSTED BY: W T
14 Replies
Posted 3 months ago

Chris, thank you for the suggestion of:

Simplify[(a^b)^c == a^(b*c), Assumptions -> Element[b | c, Integers]]

That produced the results I was looking for in all of my test cases.

Thank you both for all your help and suggestions!

POSTED BY: W T

If you only want to check the equality in the elementary situations, you can use PowerExpand, which applies the familiar rules of powers without precautions:

(a^b)^c == a^(b*c) // PowerExpand
POSTED BY: Gianluca Gorni
Posted 3 months ago

Hello, thank you for the suggestion, but I'm not sure how to use it:

PowerExpand["(a^b)^c"] == PowerExpand["a^(b*c)"]

Gives a result of "False".

Ah, I see that I have to use ToExpression:

PowerExpand[ToExpression["(a^b)^c"]] == PowerExpand[ToExpression["a^(b*c)"]]

Gives a result of "True". Thank you for the extra help!

POSTED BY: W T
Posted 3 months ago

Maybe:

1/ if you want only True or False answers to your tests then wrap Simplify with TrueQ

TrueQ[Simplify[(a - b) + c == (a - c) + b]]

False

You could also use directly SameQ (===) instead of Equal (==)

(a - b) + c === (a - c) + b

False

but then Simplify won't work anymore:

Simplify[1 - x^2 == (1 - x) (1 + x)]

True

Simplify[1 - x^2 === (1 - x) (1 + x)]

False

2/ For your (a^b)^c problem, maybe this:

Simplify[(a^b)^c == a^(b*c), Assumptions -> Element[b | c, Integers]]

True

Simplify[(a^b)^c == (a^c)^b, Assumptions -> Element[b | c, Integers]]

True

POSTED BY: Chris P
Posted 3 months ago

I am using ToExpression because I plan on generating multiple different expressions programmatically, and then comparing them to see if any are mathematically/algebraically equivalent. I don't know how to do that without manipulating strings.

The following two expressions produce the correct output:

// expecting false, returns false

Reduce[ForAll[{a, b, c}, (a + b) - c == (a - b) + c]] 

// expecting true, returns true

Reduce[ForAll[{a, b, c}, (a + b) - c == (a - c) + b]]

But I just tried that on one of the original comparison expressions, and so far it is failing to produce any output in Mathematica. It's been running for about 10 minutes now.

// expecting true, hasn't returned any output yet...

Reduce[ForAll[{a, b, c}, (a^b)^c == (a^c)^b]]

And... Actually, it looks like it just stopped. Still no output. I guess there is a 10 minute time limit for online calculations.

Can you think of any way to compare expressions to get the following results:
(a-b)+c == (c-b)+a -> True
(a-b)+c == (a-c)+b -> False
(a-b)/(c-d) == (b-a)/(d-c) -> True
(a-b)/(c-d) == (b-a)/(c-d) -> False
(a-b)/((c-d)^(d-e)) == (a-b)*((c-d)^(e-d)) -> True
(a-b)/((c-d)^(d-e)) == (a-b)*((d-c)^(e-d)) -> False
(a^b)^c == (a^c)^b -> True
(a^b)^c == (b^a)^c -> False
a^(b*c) == (a^c)^b -> True
a^(b^c) == (a^b)^c -> False

POSTED BY: W T

It is sad that

Reduce[ForAll[{a, b, c}, (a^b)^c == (a^c)^b]]

works on forever, because FindInstance finds a counterexample in no time.

As for automatic checking of identities, this could be a start:

expressionList = {(a - b) + c == (c - b) + a,
(a - b) + c == (a - c) + b,
(a - b)/(c - d) == (b - a)/(d - c),
(a - b)/(c - d) == (b - a)/(c - d),
(a - b)/((c - d)^(d - e)) == (a - b)*((c - d)^(e - d)),
(a - b)/((c - d)^(d - e)) == (a - b)*((d - c)^(e - d)),
(a^b)^c == (a^c)^b,
(a^b)^c == (b^a)^c,
a^(b*c) == (a^c)^b,
a^(b^c) == (a^b)^c};
Map[{#, Simplify[#]} &,
  expressionList] // TableForm

The ones that do not give True are good candidates for not being identities.

Identities that involve powers can be very tricky, as you have been learning.

POSTED BY: Gianluca Gorni

One must remember that deciding if two expressions are identical is very difficult in its full generality. If you generate the expressions programmatically, you cannot expect to get the answer easily at the first try. Search "Constant problem" on Wikipedia.

POSTED BY: Gianluca Gorni
Posted 3 months ago

I was unable to find anything related to my original request, which is why I've started this thread.

I tried to adapt your example to use FullSimplify, but this gives incorrect results on even simple comparisons like the following, ie they return True when they should return False:

// Expecting False, Mathematica returns True

Equal[FullSimplify[ToExpression["(a+b)-c"] == ToExpression["(a-b)+c"]]]

// Expecting False, Mathematica returns True

Equal[FullSimplify[ToExpression["(a+b)-c"] == ToExpression["(a-b)+c"], Reals]]

// Expecting False, Mathematica returns True

Equal[FullSimplify[ToExpression["(a+b)-c"] == ToExpression["(a-b)+c"], Integers]]

Am I using these incorrectly?

POSTED BY: W T

Wrong syntax. Simplify[(a + b) - c == (a - b) + c] gives b == c, which is equivalent condition for the equality. If you insert b == c inside Equal you call Equal with one argument, which returns True whatever the argument is. Perhaps you meant

Reduce[ForAll[{a, b, c}, (a + b) - c == (a - b) + c]]

Why are you using ToExpression of a string?

POSTED BY: Gianluca Gorni
Posted 3 months ago

Thank you again for providing examples where they are not equivalent.

However, I would like to restrict the Domain to the Positive Reals, where I believe these symbolic expressions are equal.

Is there a way to perform the symbolic comparison with this restriction?

POSTED BY: W T

Here are two conditions under which the equality is true:

Reduce[(a^b)^c == (a^c)^b &&
  Element[c | b, Integers] && a != 0]
Reduce[(a^b)^c == (a^c)^b && a > 0, Reals]

You can try FullSimplify instead of Reduce.

If you search the archives you will probably find earlier discussions of the topic.

POSTED BY: Gianluca Gorni

The condition that the parameters are real is not enough:

FindInstance[(a^b)^c != (a^c)^b && Element[a | b | c, Reals],
 {a, b, c}]
FindInstance[a^(b*c) != (a^b)^c && Element[a | b | c, Reals],
 {a, b, c}]
POSTED BY: Gianluca Gorni
Posted 3 months ago

When I ran your example code, I see that Mathematica returned imaginary results.

While I am not looking for "solutions" (actual values for a,b,c), I would like to restrict the symbolic comparison to the Real domain, hmmm maybe even more restricted to the positive Reals, in which case (I believe) the expressions are equivalent.

Is there a way to perform the symbolic comparison with this restriction?

POSTED BY: W T

It is a grand classic. In general it is False that (a^b)^c == (a^c)^b and a^(b*c) == (a^b)^c:

FindInstance[(a^b)^c != (a^c)^b, {a, b, c}, 2]
FindInstance[a^(b*c) != (a^b)^c, {a, b, c}, 2]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract