pattern matching question
- To: mathgroup at smc.vnet.net
- Subject: [mg61827] pattern matching question
- From: Robert Schoefbeck <schoefbeck at hep.itp.tuwien.ac.at>
- Date: Mon, 31 Oct 2005 06:10:04 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
hello everybody, i'm having the following problem: from time to times within a long calculation i have to perform a time consuming operation which takes a structure {{n1,m1},{n2,m2},{n3,m3},...} as an argument and returns a lengthy result. however, these list structures occur repeatedly, in fact, there are only very few (for a given calculation) and they occur very often. thus, i wrote a routine which gets all instances of these list and produces the result as a list of rules to be used within the actual calculation. my problem is the following: say, the list {{n1,m1},{n1,m2},{n1,m3}} gives 1/(m1-m2) + something and {{n1,m1},{n1,m1},{n1,m3}} gives 1 + something if the list of rules is now applied within the calculation the FIRST rule in my example is used also on the SECOND case with m1=m2 producing a 1/0 Sorting the list of rules would of course do the trick, but there is no canonical way, because the generic structure of such a list is quite involved: any multiples of the m-parameters might occor at any place. What i think i need is something like {{n1,m1},{n1,m2},{n1,m3}}/;(m1=!=m2)-> 1/(m1+m2)+something {{n1,m1},{n1,m1},{n1,m3}}->1+something which is not mathematica syntax i believe. To put it differently: I need a pattern {{_,m1_},{_,m2_},{_,m3_}} to be matched only if the parameters are different. is there any elegant solution to this? robert schoefbeck