MathGroup Archive 2005

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

Search the Archive

Re: Pattern matching in functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54461] Re: Pattern matching in functions
  • From: Peter Pein <petsie at arcor.de>
  • Date: Sun, 20 Feb 2005 00:11:40 -0500 (EST)
  • References: <cv6sop$6pj$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Maximilian Ulbrich wrote:
> Hi,
> 
> I would like to find subexpressions using Cases.
> In the following case, I expected to find a[b] and a[c] and therefore
> get {b,c} as the result. However, I get {l,l}.
> What happens and how can I solve this?
> 
> Cases[l^4*a[b][l] + l*a[c][l], x_a[y_] -> y, {0, Infinity}]
> 
> Thanks,
> Max
> 
Your pattern doesn't match.

Cases[l^4*a[b][l]+l*a[c][l],x_*a[y_][z_]->y]
yields
{b,c}

If l is allways the argument of the functions a[y_], you can replace z_ 
by l. And don't forget to leave a space or put an astrisk between x_ and 
a[y_][z_]. There is no match for an object x_ with head a[y_].

-- 
Peter Pein
Berlin


  • Prev by Date: Re: Why does Inverse[M] hesitate?
  • Next by Date: Re: Pattern matching in functions
  • Previous by thread: Re: Pattern matching in functions
  • Next by thread: Re: Pattern matching in functions