The corresponding head differs from some model

I want to combine an expression whose head is different from f.

It works

[In]  !MatchQ[t[3], x_ /; Head[x] == f]
[Out] True

But not this

 [In]  MatchQ[t[3], x_ /; Head[x] != f]
 [Out] False

Why doesn't the second solution work? How can I make it work?

+5
source share
1 answer

Why this does not work: you should use =!=( UnsameQ) and not !=( Unequal) for structural comparisons:

In[18]:= MatchQ[t[3],x_/;Head[x]=!=f]
Out[18]= True

For this reason, you can evaluate the reason:

In[22]:= Head[t[3]]!=f
Out[22]= t!=f

== (Equal) != (Unequal) , ( ) . . , SameQ UnsameQ.

, , :

MatchQ[t[3],Except[_f]]
+14

All Articles