Logical inconsistency
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1229] Logical inconsistency
- From: jorma.virtamo at vtt.fi (Jorma Virtamo)
- Date: Fri, 26 May 1995 03:39:58 -0400
The other day I tried to construct a rule that applies to patterns of type test = h[a] + h[1] + h[anything]; i.e. a sum of functions with head h. The most natural thing to do is to define the general pattern by patt = Plus[__h]; However, when you check for the match, you find to your surprise: In[3]:= MatchQ[test,patt] Out[3]= False This happens because In[4]:= patt Out[4]= __h or more fully In[5]:= patt // FullForm Out[5]=BlankSequence[h] Because BlankSequence as the argument of Plus is a unary argument, Plus "thinks" to be superfluous, and drops out. However, BlankSequence outspokenly stands for a *sequence* of arguments. Therefore, Plus should make an exception to the rule Plus[expr] := expr. A workaround in this case seems to be In[6]:= patt=(pl_/; pl==Plus)[__h]; In[7]:= MatchQ[test,patt] Out[7]= True Has anybody a comment? -- Jorma Virtamo ============================================================ Jorma Virtamo VTT Information Technology / Telecommunications P.O. Box 1202, FIN-02044 VTT, Finland phone: +358 0 456 5612 fax: +358 0 455 0115 email: jorma.virtamo at vtt.fi web: http://www.vtt.fi/tte/ ============================================================