Why does MatchQ[a, r_ /; Head[r] != Plus] evaluate to False?

Why does MatchQ[a, r_ /; Head[r] != Plus] evaluate to False?



I'm trying to understand. Why is it that:


MatchQ[a, r_ /; Head[r] != Plus]



Evaluates to:


False



? For me, I would think that, because:


Head[a]



Evaluates to:


Symbol



Where a has no value or expression assigned to it, then this:


a


MatchQ[a, r_ /; Head[r] != Plus]



Should evaluate to True. Could someone point me in the right direction to understanding this better? Thanks!


True




1 Answer
1



The problem is this:



If a is a symbol then its Head is Symbol, so Head[a] != Plus reduces to Symbol != Plus. Unequal (!=) is supposed to be a mathematical test for inequality. In this case, it just cannot decide whether Symbol != Plus should evaluate to True or to False, since both sides are Symbols. Here an example why this is undecidable with the current amount of information:


a


Head


Symbol


Head[a] != Plus


Symbol != Plus


Unequal


!=


Symbol != Plus


True


False


Symbol


With[Symbol = 1, Plus = 1, Symbol != Plus]
With[Symbol = 1, Plus = 0, Symbol != Plus]



False



True



So the expression Symbol != Plus stays unevaluated. (This is the best strategy since later definitions could make it decidable.)


Symbol != Plus



Because the second argument of Condition (/;) does not evaluate to True, the pattern does not match.


Condition


/;


True



Lesson to learn: For testing for structual inequality, use UnsameQ (=!=):


UnsameQ


=!=


MatchQ[a, r_ /; Head[r] =!= Plus]



True



Of course, the same applies, mutatis mutandis, to Equal and SameQ.


Equal


SameQ



Thanks for contributing an answer to Mathematica Stack Exchange!



But avoid



Use MathJax to format equations. MathJax reference.



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

Node.js puppeteer - Use values from array in a loop to cycle through pages