This question already has an answer here:

{g[x, y, z], h[x, y], f[]} /. (f_[t___] /; f != List) :> Plus[t]

Why is the output of this expression

{g[x, y, z], h[x, y], f[]}

instead of


When I change the code to

{g[x, y, z], h[x, y], f[]} /. (f_[t___] /; f =!= List) :> Plus[t]

everything works as I expected


marked as duplicate by Mr.Wizard Nov 2 '14 at 4:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ This has been answered before. It is the same as the difference between SameQ and Equal. Instead of repeating things, please see this difference-between-and-in-mathematica which talks about the difference between SameQ and Equal. This applies exactly to UnSameQ and Unequal. $\endgroup$ – Nasser Nov 2 '14 at 4:00
  • $\begingroup$ Somehow this input looks familiar. $\endgroup$ – Leonid Shifrin Nov 2 '14 at 4:00
  • 3
    $\begingroup$ I will add to Nasser's comment, that, for the purposes of pattern-matching, every pattern condition that does not explicitly evaluate to True, is considered False. Equal does not evaluate, so there is no match. All these bits can actually also be found in the book (but not in one place), although perhaps I could have elaborated more on this particular example you picked. $\endgroup$ – Leonid Shifrin Nov 2 '14 at 4:06