MathGroup Archive 2003

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

Search the Archive

Re: Pattern Matching Problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43415] Re: Pattern Matching Problem
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Fri, 29 Aug 2003 07:16:29 -0400 (EDT)
  • Organization: The University of Western Australia
  • References: <bihp1v$b3u$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <bihp1v$b3u$1 at smc.vnet.net>,
 "Ersek, Ted R" <ErsekTR at navair.navy.mil> wrote:

> Consider the following:
> 
> In[1]:=
>   ClearAll[f,a,b,c,w,x,y,z];
>   expr=a+b+c+f[w,2]+f[w,3]+x+f[x,2]+f[x,3]+y+f[y,2]+f[z,2];
> 
>   
> Can somebody suggest a general way to seperate the terms above into like
> groups. By "like" I mean having the same second argument for (f).  So for
> this example I want to get 
> 
> {a+b+c+x+y,  f[w,2]+f[x,2]+f[y,2]+f[z,2],   f[w,3]+f[x,3]}

Not a full answer to your question, but one can get the partitioning you 
are after using

  Collect[expr /. c:f[_, n_] :> g[n] c, g[_]]

Cheers,
Paul

-- 
Paul Abbott                                   Phone: +61 8 9380 2734
School of Physics, M013                         Fax: +61 8 9380 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: Mathematica refuses to evaluate?
  • Next by Date: Re: Pattern Matching Problem
  • Previous by thread: Re: Pattern Matching Problem
  • Next by thread: Re: Pattern Matching Problem