0
$\begingroup$
{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

{x+y+z,x+y,0}

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

$\endgroup$
3
  • 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, 2014 at 4:00
  • $\begingroup$ Somehow this input looks familiar. $\endgroup$ Nov 2, 2014 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$ Nov 2, 2014 at 4:06

0

Browse other questions tagged or ask your own question.