RE: perhaps? RE: Finding pattern Matched series
- To: mathgroup at smc.vnet.net
- Subject: [mg33086] RE: perhaps? RE: [mg33051] Finding pattern Matched series
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Fri, 1 Mar 2002 06:51:54 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
> -----Original Message-----
> From: J C [SMTP:jabidof at yahoo.fr]
To: mathgroup at smc.vnet.net
> Sent: Wednesday, February 27, 2002 6:02 PM
> To: Wolf, Hartmut
> Subject: Re: perhaps? RE: [mg33051] Finding pattern Matched series
>
>
--snipped--
> Sorry for giving you some guesswork. Here is the
> answers I am looking for:
>
> Given:
>
> {{2, 1}, {2, 3}, {3, 2}, {3, 5}, {4, 2}, {4, 5}, {5,4}, {6, 4}}
>
> get:
>
> {{{2, 3}, {3, 2}}, {{4, 5}, {5, 4}}, {{2, 3}, {3, 5},{5, 4}, {4, 2}}}
>
> in other words, the list of all possible oriented
> loops formed by the given list of coordinates.
>
[Hartmut Wolf]
-- loops, aha, so you are working on graphs in general, or applied, e.g. for
polytopes.
If you want _all_ subsequences, i.e. for all gap lengths -- as I called it
-- then the methods I gave you are not appropriate.
Also another question arises: whether your input list should be treated as
cyclic.
Assumed not so, if I bring your "in other words" to code
In[1]:=
t={{2,1},{2,3},{3,2},{3,5},{4,2},{4,5},{5,4},{6,4}};
In[2]:=
res=ReplaceList[
t,{___,{x_,a_},bb___,{c_,x_},___}\[RuleDelayed]{{x,a},bb,{c,x}}]
Out[2]=
{{{2,1},{2,3},{3,2}},
{{2,3},{3,2}},
{{2,1},{2,3},{3,2},{3,5},{4,2}},
{{2,3},{3,2},{3,5},{4,2}},
{{4,2},{4,5},{5,4}},
{{4,5},{5,4}},
{{4,2},{4,5},{5,4},{6,4}},
{{4,5},{5,4},{6,4}}}
This is clearly different from your answer:
In[3]:=
your\[UnderParenthesis]answer=
{{{2,3},{3,2}},
{{4,5},{5,4}},
{{2,3},{3,5},{5,4},{4,2}}};
In[4]:=
your\[UnderParenthesis]answer \[Equal] res
Out[4]=
False
In[5]:=
Intersection[res,your\[UnderParenthesis]answer]
Out[5]=
{{{2,3},{3,2}},{{4,5},{5,4}}}
Especially I have no clue on what makes {{2,3},{3,5},{5,4},{4,2}} be part of
it?
--
Hartmut
_____________
P.S.:
Just getting another idea:
In[10]:= {t1,t2}=Transpose[t]
Out[10]=
{{2,2,3,3,4,4,5,6},{1,3,2,5,2,5,4,4}}
In[26]:=
ls=Transpose/@NestList[{First[#],RotateLeft[Last[#]]}&,{t1,t2},Length[t]-1]
In[30]:= p=Position[ls,{x_,x_}]
Out[30]=
{{2,2},{2,6},{3,1},{3,5},{3,6},{4,2},{4,5},{5,1},{6,7},{7,4},{8,3},{8,7}}
In[38]:=
r2=Check[Take[t,{#2,#2+#1-1}],Unevaluated[Sequence[]]]& @@@ p
Out[38]=
{{{2,3},{3,2}},
{{4,5},{5,4}},
{{2,1},{2,3},{3,2}},
{{4,2},{4,5},{5,4}},
{{4,5},{5,4},{6,4}},
{{2,3},{3,2},{3,5},{4,2}},
{{4,2},{4,5},{5,4},{6,4}},
{{2,1},{2,3},{3,2},{3,5},{4,2}}}
In[40]:= Sort[res]\[Equal]Sort[r2]
Out[40]= True
You might not like the accompanied error messages. Now, observing that the
paired rotated list ls is equivalent to
In[22]:=
lc=ListCorrelate[t1,t2,{1,1},t2,List,List]
In[27]:= lc\[Equal]ls
Out[27]= True
So we can do this:
In[41]:= lc=ListCorrelate[t1,t2,{1,1},{},List,List]
In[42]:= p2=Position[lc,{x_,x_}]
In[44]:= Take[t,{#2,#2+#1-1}]& @@@ p2
Out[44]=
{{{2,3},{3,2}},
{{4,5},{5,4}},
{{2,1},{2,3},{3,2}},
{{4,2},{4,5},{5,4}},
{{4,5},{5,4},{6,4}},
{{2,3},{3,2},{3,5},{4,2}},
{{4,2},{4,5},{5,4},{6,4}},
{{2,1},{2,3},{3,2},{3,5},{4,2}}}