0
|
3771 Views
|
2 Replies
|
6 Total Likes
View groups...
Share
GROUPS:

# Command TrueQ doenst work with undefined expressions?

Posted 9 years ago
 For example Both TrueQ[(m^2 - n^2)^2 + (2 m*n)^2 == (m^2 + n^2)^2] and TrueQ[(x + 1)^2 == x^2 + 2 x + 1] returns False (why? it is true) However TrueQ[x^2 == x*x] returns True (of course)
2 Replies
Sort By:
Posted 9 years ago
 No, SameQ with a single argument will always return True, so I don't see how it's relevant here. In:= SameQ[False] Out= True Equal is the right test and it works just fine if we use Expand or more generally Simplify: In:= Expand[(m^2 - n^2)^2 + (2 m*n)^2 == (m^2 + n^2)^2] Out= True In:= Simplify[(x + 1)^2 == x^2 + 2 x + 1] Out= True The last identity is actually a documentation example for Equal.
Posted 9 years ago
 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 TrueFor 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 examplesSameQ[(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 TrueThe bottom line is this: TrueQ[expression] is the same as SameQ[Equal[expression]]