       Working with ppatterns

• To: mathgroup at smc.vnet.net
• Subject: [mg113225] Working with ppatterns
• From: Themis Matsoukas <tmatsoukas at me.com>
• Date: Tue, 19 Oct 2010 05:56:53 -0400 (EDT)

```I would like to create a pattern that recognizes multinomial terms of the form

A (a^x2) (a^x5) (a^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+a+a+a)^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^2 a^2,{{1,2},{2,2}}}
{6 a^2 a^2,{{1,2},{3,2}}}
{6 a^2 a^2,{{2,2},{3,2}}}
{6 a^2 a^2,{{1,2},{4,2}}}
{6 a^2 a^2,{{2,2},{4,2}}}
{6 a^2 a^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 a^3" because the exponent of a 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: What generates the In/Out CellLabels and how do I change them?
• Next by Date: Is this a bug in NSolve in mathematica?
• Previous by thread: Symbolic Manipulation of Matrices [Newbie Question]
• Next by thread: Re: Working with ppatterns