2
$\begingroup$
f[_x] := x^2
g[_x] := x^2
TrueQ[f[x] == g[x]]

Can anyone explain why it returns False, while TrueQ[x^2 == x^2] does not? Does it compare the value of the pointers of the functions? How can I compare the "content" of defined functions otherwise?

$\endgroup$

closed as off-topic by m_goldberg, WReach, István Zachar, Hector, Bob Hanlon Aug 12 '16 at 18:54

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." – m_goldberg, WReach, István Zachar, Hector, Bob Hanlon
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    $\begingroup$ I believe you meant to write these as f[x_] := x^2; what you have written is a function that matches on any pattern with the head x, such as x[] or x[1,2]. The symbol x itself has head Symbol, so f[x] is just f[x]. $\endgroup$ – nben Aug 12 '16 at 14:27
  • $\begingroup$ @user21382: your comment would make a perfectly valid answer i think, why not post it as an answer? :) $\endgroup$ – Thies Heidecke Aug 12 '16 at 14:29
  • 1
    $\begingroup$ @user21382 is right, if you use the proper syntax it will return True. $\endgroup$ – Siav Josep Aug 12 '16 at 14:29
6
$\begingroup$

I believe you meant to write these as f[x_] := x^2; g[x_] := x^2;. What you have written is a pair of functions that match on any pattern with the head x (by using _x instead of x_), such as x[] or x[1,2]. The symbol x itself has head Symbol, so f[x] does not match f[_x]. See the page on Patterns for more information.

f[x_] := x^2;
g[x_] := x^2;
TrueQ[f[x] == g[x]]

True

$\endgroup$

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