*To*: mathgroup@smc.vnet.net*Subject*: [mg12060] Re: [mg11991] Pattern matching more than once*From*: "Jürgen Tischer" <jtischer@pitagoras.univalle.edu.co>*Date*: Fri, 24 Apr 1998 01:52:30 -0400

Hi Asari, I hope I understood what you are interested in. extent[{x__,y_},{y_,z__}]={x,y,z}; extent[{x__?AtomQ,y_},li1:{__List}]:= With[{li2=Cases[li1,{y,__}]},If[li2=={},{x,y}, extent[{x,y},#]&/@li2]]; extent[li1:{__List},li2:{__List}]:= Cases[extent[#,li2]&/@li1,{__?AtomQ},\[Infinity]] fu[li1_,li2_]:= Module[{li3=Intersection[li1,li2],aux}, aux=Split[#,UnsameQ]&/@({li1,li2}/.(x_/;MemberQ[li3,x]->Sequence[x,x])); FixedPoint[extent[#,Union@@Rest/@aux]&,First/@aux]] aux doubles the common elements and then splits (with UnsameQ) between those elements, producing segments with ends where crossing can take place. FixedPoint extents---beginning with the first segments of the two lists---until there is no more extension possible. I supposed you were interested in all possible chains, not only the maximal ones. J|rgen -----Original Message----- From: ASARI Hirotsugu <asari@math.uiuc.edu> To: mathgroup@smc.vnet.net Subject: [mg12060] [mg11991] Pattern matching more than once >I have been stuck with the following problem for about 10 days. I can't >think of an elegant solution. > >Input: Two lists, from some universal set Output: Many "spliced" lists >obtained from the input. > >e.g. {{a,b,c},{d,e,f}} --> {{a,b,c},{d,e,f}} (no common element) > > {{a,b,c},{d,b,f}} --> {{a,b,c},{d,b,f},{a,b,f},{d,b,c}} > > {{a,b,c,d,e},{f,b,g,d,h}} --> > {{a,b,c,d,e},{a,b,c,d,h},{a,b,g,d,e},{a,b,g,d,h}, > {f,b,c,d,e},{f,b,c,d,h},{f,b,g,d,e},{f,b,g,d,h}} > >I will regard the input as list of chains (totally ordered set) coming >from a partially ordered set, and I would like to extend these chains >as much as possible. If there is at most one common element in the >inputs, the following will do: > >extendList[{list1:{pre1___,x_,post1___},list2:{pre2___,x_,post2___}}]:= > {list1,list2,{pre1,x,post2},{pre2,x,post1}}; > >The problem is that when the lists have more than one common element, >the second common element will not be considered at all. I suppose I >could just write, for instance, > >extendList2[{list1:{pre1___,x_,mid1___,y_,post1___}, > list2:{pre2___,x_,mid2___,y_,post2___}}]:= > Union[ > {list1,{pre1,x,mid1,y,post2},{pre1,x,mid2,y,post1}, > {pre1,x,mid2,y,post2},list2,{pre2,x,mid1,y,post1}, > {pre2,x,mid1,y,post2},{pre2,x,mid2,y,post1}}]; But this is very ugly. > >I suppose I could write some For[] loop through >Intersection[list1,list2], but I would rather avoid it if I could. > >Any help would be appreciated. > >-- >ASARI Hirotsugu // http://www.math.uiuc.edu/~asari/ >finger://math.uiuc.edu/asari // ph://ns.uiuc.edu/asari > "We are what we pretend to be, so we must be careful > about what we pretend to be." --Kurt Vonnegut >