MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

pattern matching question

  • To: mathgroup at
  • Subject: [mg61827] pattern matching question
  • From: Robert Schoefbeck <schoefbeck at>
  • Date: Mon, 31 Oct 2005 06:10:04 -0500 (EST)
  • Sender: owner-wri-mathgroup at

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 
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
1/(m1-m2) + something
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

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

  • Prev by Date: Re: preserving order of eigenvalues in a matrix diagonalization
  • Next by Date: Re: Re: Re: Re: aggregation of related elements in a list
  • Previous by thread: call notebook
  • Next by thread: Re: pattern matching question