Message Boards Message Boards


Command TrueQ doenst work with undefined expressions?

Posted 9 years ago
2 Replies
6 Total Likes

For example

Both TrueQ[(m^2 - n^2)^2 + (2 m*n)^2 == (m^2 + n^2)^2]


TrueQ[(x + 1)^2 == x^2 + 2 x + 1]

returns False (why? it is true)


TrueQ[x^2 == x*x]

returns True (of course)

POSTED BY: peter B
2 Replies

No, SameQ with a single argument will always return True, so I don't see how it's relevant here.

In[2]:= SameQ[False]

Out[2]= True

Equal is the right test and it works just fine if we use Expand or more generally Simplify:

In[3]:= Expand[(m^2 - n^2)^2 + (2 m*n)^2 == (m^2 + n^2)^2]

Out[3]= True

In[4]:= Simplify[(x + 1)^2 == x^2 + 2 x + 1]

Out[4]= True

The last identity is actually a documentation example for Equal.

POSTED BY: Ilian Gachevski

Lets do the easy one first. TrueQ[x^2 == x*x] returns True since x*x is converted to x^2 automatically before the test is even done. If you type x*x you'll see the FE returns x^2. Hence now both the left and right side are exactly the same When the kernel gets hold of them. a==a which is Equal[a,a] automatically converted to True for any a. So it becomes TrueQ[True] which returns True

For the other examples, the argument to TrueQ was is not explicitly True, hence TrueQ returned False. The argument to TrueQ has to be an explicit True for TrueQ to return True.

You need to use SameQ for the other 2 examples

SameQ[(m^2 - n^2)^2 + (2 m*n)^2 == (m^2 + n^2)^2] gives True. This is because SameQ[Equal[a,b]] return True if Equal[a,b] itself returns True, which it does in this case. Simplify@Equal[(m^2 - n^2)^2 + (2 m*n)^2, (m^2 + n^2)^2] gives True. So SameQ[True] is True

The bottom line is this: TrueQ[expression] is the same as SameQ[Equal[expression]]

POSTED BY: Nasser M. Abbasi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract