Re: ? Repeated Patterns ?

*To*: mathgroup at smc.vnet.net*Subject*: [mg18868] Re: [mg18858] ? Repeated Patterns ?*From*: "Wolf, Hartmut" <hwolf at debis.com>*Date*: Sun, 25 Jul 1999 03:30:07 -0400*Organization*: debis Systemhaus*References*: <199907230257.WAA20702@smc.vnet.net.>*Sender*: owner-wri-mathgroup at wolfram.com

DongGook Park schrieb: > > Dear Mathematica users, > > The following Mathematica result quite confuses me. I can understand the output of > the first input command, but not the second output. Why not {0,1) but > {0,0,0,1}? > Many thanks if anyone could help me. > > DongGook Park > > ----- Mathematica script (Repeated patterns) -------- > > In[1]:= > {1,0,0,0} /. {x___Integer, y_Integer..} -> {x, y} > > Out[1]= > {1,0} > > In[2]:= > {0,0,0,1} /. {x_Integer.., y___Integer} -> {x, y} > > Out[2]= > {0,0,0,1} Dear DongGook, to see, just look at your expressions with a little more diagnostics: In[1]:= ReplaceList[{1, 0, 0, 0}, {x___Integer, yall : y_Integer ..} -> {{x}, {y}, yall}] Out[1]= {{{1}, {0}, 0, 0, 0}, {{1, 0}, {0}, 0, 0}, {{1, 0, 0}, {0}, 0}} The most important thing is that y_Integer.. is not equivalent to y__Integer: if in your expression y_ tries to match 1 ,then y_.. can't match the rest of the sequence (because they are not all 1), so we have no occurrence of x___ matching the null sequence. All other matches are possible and shown by ReplaceList. What you found (and understand) is the first match, whereafter ReplaceAll is satisfied. Regarding your second example In[2]:= ReplaceList[{0, 0, 0, 1}, {xall : x_Integer .., y___Integer} -> {xall, {x}, {y}}] Out[2]= {{0, {0}, {0, 0, 1}}, {0, 0, {0}, {0, 1}}, {0, 0, 0, {0}, {1}}} then nothing is different in principle, except that match you desired occures in the last position of all possible matches. But this only is because matching is tried from left to right. kind regards, hw

**References**:**? Repeated Patterns ?***From:*"DongGook Park" <park@isrc.qut.edu.au>