Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: More Pattern Match Understanding Problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46636] Re: More Pattern Match Understanding Problems
  • From: drbob at bigfoot.com (Bobby R. Treat)
  • Date: Thu, 26 Feb 2004 17:53:24 -0500 (EST)
  • References: <c1ir85$6b1$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Your adding "<labeled?>" to the definition is incorrect. In the first
example, there are no unlabeled patterns, so your definition couldn't
apply.

In the third example, the shortest possible match to ____ (three
blanks) is an empty set, so x matches beginning with the first
element. But the rule applies again, so it matches with the shortest
sequence starting there -- just a. It doesn't match all the rest of
the elements, because the third pattern ___ is available to do that.

In the second example, the first pattern ____ (three blanks) again
matches an empty set, and x__ matches all the rest of the arguments.
As you see.

Bobby

Harold.Noffke at wpafb.af.mil (Harold Noffke) wrote in message news:<c1ir85$6b1$1 at smc.vnet.net>...
> MathGroup:
> 
> In the Mathematica 5 Book, Section 2.3.8, "Functions with Variable
> Numbers of Arguments," there are three examples of using ReplaceList
> to understand pattern matching (In/Out-4,5,6).  I understand In/Out-4
> and In/Out-6 if I assume the Mathematica explanation (immediately
> below) refers only to "labeled blanks" when it says "blanks" ...
> 
>     When you use multiple blanks, there are often several matches that
>     are possible for a particular expression.  In general, Mathematica
>     tries first those matches that assign the shortest sequences of
>     arguments to the first <labeled?> multiple blanks that appear in
>     the pattern.
> 
> When I examine In/Out-5, however, my understanding breaks down when I
> see that the answer Mathematica gives is g[a,b,c,d], which is the
> longest (not the shortest) sequence assigned to the labeled blank x__.
> 
>     In[5]:=
>         ReplaceList[f[a, b, c, d], f[___, x__] -> g[x]]
>     Out[5]=
>         {g[a,b,c,d], g[b,c,d], g[c,d], g[d]}
> 
> Therefore, I conclude my reasoning is incorrect.
> 
> Can anyone provide some guidance on how to think through In/Out-4,5,6
> without assuming labeled multiple-blanks have priority over unlabeled
> ones?
> 
> Thanks.
> Harold


  • Prev by Date: RE: Matrix Element Extraction
  • Next by Date: RE: More Pattern Match Understanding Problems
  • Previous by thread: More Pattern Match Understanding Problems
  • Next by thread: RE: More Pattern Match Understanding Problems