|
[Date Index]
[Thread Index]
[Author Index]
RE: More Pattern Match Understanding Problems
- To: mathgroup at smc.vnet.net
- Subject: [mg46647] RE: [mg46620] More Pattern Match Understanding Problems
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Thu, 26 Feb 2004 17:53:50 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message-----
>From: Harold.Noffke at wpafb.af.mil [mailto:Harold.Noffke at wpafb.af.mil]
To: mathgroup at smc.vnet.net
>Sent: Wednesday, February 25, 2004 7:07 PM
>To: mathgroup at smc.vnet.net
>Subject: [mg46647] [mg46620] More Pattern Match Understanding Problems
>
>
>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
>
Harold,
from your text I conclude that you understand
ReplaceList[f[a, b, c, d], f[u___, x__] -> u + g[x]]
==> {g[a, b, c, d], a + g[b, c, d], a + b + g[c, d], a + b + c + g[d]}
hence
ReplaceList[f[a, b, c, d], f[u___, x__] -> g[x]]
==> {g[a, b, c, d], g[b, c, d], g[c, d], g[d]}
but that must be the same as
ReplaceList[f[a, b, c, d], f[___, x__] -> g[x]]
(as u wasn't used at rhs of Rule)
BTW: there are no such gross errors in the book; omissions, yes, or in a few
instances, elusive simplifications.
--
Hartmut
Prev by Date:
Re: More Pattern Match Understanding Problems
Next by Date:
Re: Matrix Element Extraction
Previous by thread:
Re: More Pattern Match Understanding Problems
Next by thread:
Question about Integrate and If
|