Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Working with ppatterns

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113245] Re: Working with ppatterns
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Wed, 20 Oct 2010 04:08:43 -0400 (EDT)

Hi Themis,

You will need something like this:

In[10]:=
AB=Cases[data,(X:_:1) a[i1_]^(j1:_:1) a[i2_]^(j2:_:1)];
ABindices=Cases[data,(X:_:1) a[i1_]^(j1:_:1)
a[i2_]^(j2:_:1)->{{i1,j1},{i2,j2}}];
Column[Transpose[{AB,ABindices}]]


Out[12]=
{4 a[1]^3 a[2],{{1,3},{2,1}}}
{6 a[1]^2 a[2]^2,{{1,2},{2,2}}}
{4 a[1] a[2]^3,{{1,1},{2,3}}}
{4 a[1]^3 a[3],{{1,3},{3,1}}}
{12 a[1]^2 a[2] a[3],{{1,2},{2,1}}}
{12 a[1] a[2]^2 a[3],{{1,1},{2,2}}}
{4 a[2]^3 a[3],{{2,3},{3,1}}}
{6 a[1]^2 a[3]^2,{{1,2},{3,2}}}
{12 a[1] a[2] a[3]^2,{{1,1},{2,1}}}
{6 a[2]^2 a[3]^2,{{2,2},{3,2}}}
{4 a[1] a[3]^3,{{1,1},{3,3}}}
{4 a[2] a[3]^3,{{2,1},{3,3}}}
{4 a[1]^3 a[4],{{1,3},{4,1}}}
{12 a[1]^2 a[2] a[4],{{1,2},{2,1}}}
{12 a[1] a[2]^2 a[4],{{1,1},{2,2}}}
{4 a[2]^3 a[4],{{2,3},{4,1}}}
{12 a[1]^2 a[3] a[4],{{1,2},{3,1}}}
{24 a[1] a[2] a[3] a[4],{{1,1},{2,1}}}
{12 a[2]^2 a[3] a[4],{{2,2},{3,1}}}
{12 a[1] a[3]^2 a[4],{{1,1},{3,2}}}
{12 a[2] a[3]^2 a[4],{{2,1},{3,2}}}
{4 a[3]^3 a[4],{{3,3},{4,1}}}
{6 a[1]^2 a[4]^2,{{1,2},{4,2}}}
{12 a[1] a[2] a[4]^2,{{1,1},{2,1}}}
{6 a[2]^2 a[4]^2,{{2,2},{4,2}}}
{12 a[1] a[3] a[4]^2,{{1,1},{3,1}}}
{12 a[2] a[3] a[4]^2,{{2,1},{3,1}}}
{6 a[3]^2 a[4]^2,{{3,2},{4,2}}}
{4 a[1] a[4]^3,{{1,1},{4,3}}}
{4 a[2] a[4]^3,{{2,1},{4,3}}}
{4 a[3] a[4]^3,{{3,1},{4,3}}}

Regards,
Leonid


On Tue, Oct 19, 2010 at 2:56 AM, Themis Matsoukas <tmatsoukas at me.com> wrote:

> I would like to create a pattern that recognizes multinomial terms of the
> form
>
> A (a[2]^x2) (a[5]^x5) (a[6]^x6)...
>
> Ultimately, I want to identify all the indices i (as in a[i]) and exponents
> xi that appear in a given term so that the above term would produce a list
> {{2, x2}, {5, x5}, {6, x6}, etc}.
>
> I have hard time writing a rule that is general enough to work with any
> number of terms in the products and also one that will work whether the
> prefactor or any of the exponents of the multinomial is 1. I explain all
> this with the example below:
>
> data=Apply[List,Expand[(a[1]+a[2]+a[3]+a[4])^4]];
> Column[data];
>
> AB=Cases[data,X_ a[i1_]^j1_ a[i2_]^j2_];
> ABindices=Cases[data,X_ a[i1_]^j1_ a[i2_]^j2_->{{i1,j1}, {i2, j2}}];
> Column[Transpose[{AB, ABindices}]]
>
> {6 a[1]^2 a[2]^2,{{1,2},{2,2}}}
> {6 a[1]^2 a[3]^2,{{1,2},{3,2}}}
> {6 a[2]^2 a[3]^2,{{2,2},{3,2}}}
> {6 a[1]^2 a[4]^2,{{1,2},{4,2}}}
> {6 a[2]^2 a[4]^2,{{2,2},{4,2}}}
> {6 a[3]^2 a[4]^2,{{3,2},{4,2}}}
>
> Here, data is a made up list of multinomials, AB uses a rule to extract
> double products, and ABindices produces a list of indices and exponents, as
> I wanted. However:
>
> 1. my rule does misses terms like "4 a[1] a[3]^3" because the exponent of
> a[1] is 1; a separate rule would have to be written.
>
> 2. If the prefactor of a term is 1, the term will not be selected unless X_
> is removed from the rule.
>
> In summary, I would have to write separate rules depending on the number of
> terms in the product, and also depending on whether X or any of the
> exponents is 1 or not.
>
> Is there a way to write the rule so that ABindices would contain the
> indices and exponents of *all* terms in the original data?
>
> Themis
>
>



  • Prev by Date: Re: Is this a bug in NSolve in mathematica?
  • Next by Date: Re: Working with ppatterns
  • Previous by thread: Re: Working with ppatterns
  • Next by thread: Re: Working with ppatterns