Re: Selecting Element from List via Pattern Matching

• To: mathgroup at smc.vnet.net
• Subject: [mg89435] Re: Selecting Element from List via Pattern Matching
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Mon, 9 Jun 2008 02:30:47 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <g2fugh\$2kq\$1@smc.vnet.net>

```immanuel.bloch at googlemail.com wrote:

>  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...

<snip>

Could you provide an example of what you mean by that? (That is an
actual example of what is returned by Mathematica versus what you have
expected to get.) For what I have understood of your query, there are no
problems with the following:

In[1]:= t = Apply[List, Expand[(Sum[Subscript[a, i], {i, 1, 5}])^3]]

Out[1]=
3      2            2    3      2
{a  , 3 a   a , 3 a  a  , a  , 3 a   a ,
1      1   2     1  2    2      1   3

2            2         2
6 a  a  a , 3 a   a , 3 a  a  , 3 a  a  ,
1  2  3     2   3     1  3      2  3

3      2                     2
a  , 3 a   a , 6 a  a  a , 3 a   a ,
3      1   4     1  2  4     2   4

2
6 a  a  a , 6 a  a  a , 3 a   a ,
1  3  4     2  3  4     3   4

2         2         2    3
3 a  a  , 3 a  a  , 3 a  a  , a  ,
1  4      2  4      3  4    4

2                     2
3 a   a , 6 a  a  a , 3 a   a ,
1   5     1  2  5     2   5

2
6 a  a  a , 6 a  a  a , 3 a   a ,
1  3  5     2  3  5     3   5

6 a  a  a , 6 a  a  a , 6 a  a  a ,
1  4  5     2  4  5     3  4  5

2            2         2         2
3 a   a , 3 a  a  , 3 a  a  , 3 a  a  ,
4   5     1  5      2  5      3  5

2    3
3 a  a  , a  }
4  5    5

In[2]:= Cases[t, Times[_, Power[Subscript[a, 2], 2]]]

Out[2]=
2      2         2         2
{3 a  a  , 3 a   a , 3 a   a , 3 a   a }
1  2      2   3     2   4     2   5

In[3]:= Cases[t, x_ /; ! FreeQ[x, Power[Subscript[a, 2], 2]]]

Out[3]=
2      2         2         2
{3 a  a  , 3 a   a , 3 a   a , 3 a   a }
1  2      2   3     2   4     2   5

In[4]:= Cases[t, x_ /; ! FreeQ[x, Power[Subscript[a, 2], _]]]

Out[4]=
2    3      2         2
{3 a  a  , a  , 3 a   a , 3 a   a ,
1  2    2      2   3     2   4

2
3 a   a }
2   5

In[5]:= Cases[t, x_ /; ! FreeQ[x, Subscript[a, 2]]]

Out[5]=
2            2    3
{3 a   a , 3 a  a  , a  , 6 a  a  a ,
1   2     1  2    2      1  2  3

2            2                  2
3 a   a , 3 a  a  , 6 a  a  a , 3 a   a ,
2   3     2  3      1  2  4     2   4

2
6 a  a  a , 3 a  a  , 6 a  a  a ,
2  3  4     2  4      1  2  5

2
3 a   a , 6 a  a  a , 6 a  a  a ,
2   5     2  3  5     2  4  5

2
3 a  a  }
2  5

Regards,
-- Jean-Marc

```

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