MathGroup Archive 2008

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

Search the Archive

Re: Selecting Element from List via Pattern Matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89411] Re: Selecting Element from List via Pattern Matching
  • From: magma <maderri2 at gmail.com>
  • Date: Mon, 9 Jun 2008 02:26:15 -0400 (EDT)
  • References: <g2fugh$2kq$1@smc.vnet.net>

On Jun 8, 8:33 am, immanuel.bl... at googlemail.com wrote:
> Hello,
>
>  I am trying to extract from a Power Series all elements with a
> certain exponent, e.g.
> let us say I have generated a list via
>
> t = Apply[List, Expand[(Sum[Subscript[a, i], {i, 1, 5}])^3]]
>
> How can I then extract all terms with e.g. a_2^2 in it or any other
> exponent?
>
> I have tried something like
>
> Cases[t, Times[_, Power[Subscript[a,2],2]]]
>
> but this somehow only works with the exponent n=1 and no others...
>
> Does anybody know a solution to this pattern matching problem?
>
> Thanks!
> Immanuel

Try with

Cases[t, Times[_., Power[Subscript[a, 2], 2]]]

The special form s_. is equivalent to Optional[s_] and can be used to
represent function arguments which, if omitted, should be replaced by
default values globally specified for the functions in which they
occur.

this will pick up also terms with a coefficient of 1, which normally
are not picked up by Times[_,.....]

see Optional in the documentation


  • Prev by Date: Re: Selecting Element from List via Pattern Matching
  • Next by Date: Re: Selecting Element from List via Pattern Matching
  • Previous by thread: Re: Selecting Element from List via Pattern Matching
  • Next by thread: Re: Selecting Element from List via Pattern Matching