MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Logical inconsistency

  • To: mathgroup at
  • Subject: [mg1249] Re: Logical inconsistency
  • From: rubin at (Paul A. Rubin)
  • Date: Fri, 26 May 1995 07:00:31 -0400
  • Organization: Michigan State University

In article <3q14ct$725 at>,
   jorma.virtamo at (Jorma Virtamo) wrote:
->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:
->  MatchQ[test,patt]
->  False
->This happens because
->  patt
->  __h
->or more fully
->  patt // FullForm
->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  
->  patt=(pl_/; pl==Plus)[__h]; 
->  MatchQ[test,patt]
->  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     web:

I think the key is not that Plus[x] == x but that the expression Plus[__h] 
is being evaluated at all.  You want to convey to Mathematica that Plus is 
part of the pattern; you can do that by wrapping it in Literal[], which 
prevents evaluation.  Just change the pattern creation line to 

   patt = Literal[Plus[__h]];

and you get what you want.


* Paul A. Rubin                                  Phone: (517) 432-3509   *
* Department of Management                       Fax:   (517) 432-1111   *
* Eli Broad Graduate School of Management        Net:   RUBIN at MSU.EDU    *
* Michigan State University                                              *
* East Lansing, MI  48824-1122  (USA)                                    *
Mathematicians are like Frenchmen:  whenever you say something to them,
they translate it into their own language, and at once it is something
entirely different.                                    J. W. v. GOETHE

  • Prev by Date: RE: Re: BUGGY Graphics
  • Next by Date: Re: Fastest Mathematica implementation?
  • Previous by thread: Re: Logical inconsistency
  • Next by thread: [Q] Differential operators <--> polynomials