MathGroup Archive 2003

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

Search the Archive

Re: Pattern Matching Problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43389] Re: Pattern Matching Problem
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Fri, 29 Aug 2003 07:15:49 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <bihp1v$b3u$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

you mean

Plus @@@ Split[List @@ expr, Head[#1] === Head[#2] &]

or

{Select[#, Symbol === Head[#] &], Select[#, f === Head[#] &]} & [expr]

or

Plus @@@ {Cases[#, _Symbol], Cases[#, _f]} & [expr]

or

(lst = Cases[#, _.*_f]; {# - Plus @@ lst, Plus @@ lst}) & [expr]

or

{DeleteCases[#, _.*_f], Cases[#, _.*_f]} &[expr]

?

Regards
  Jens

"Ersek, Ted R" 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]}
> 
> The pattern matcher should be able to do this because Plus has attributes
> Flat and Orderless.  However I can't find a way to make it happen.
> 
> -------------------
> Thanks,
>    Ted Ersek


  • Prev by Date: maxsteps, startingstepsize in NDSolve.
  • Next by Date: Re: Pattern Matching Problem
  • Previous by thread: Re: Pattern Matching Problem
  • Next by thread: Re: Pattern Matching Problem