Pattern matching more than once
- To: mathgroup@smc.vnet.net
- Subject: [mg11991] Pattern matching more than once
- From: asari@math.uiuc.edu (ASARI Hirotsugu)
- Date: Fri, 17 Apr 1998 03:40:27 -0400
- Organization: University of Illinois at Urbana-Champaign
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