MathGroup Archive 2009

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

Search the Archive

Re: Re: Re: Full expansion with a

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103571] Re: [mg103561] Re: [mg103541] Re: [mg103517] Full expansion with a
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Tue, 29 Sep 2009 07:35:18 -0400 (EDT)
  • References: <200909261012.GAA23367@smc.vnet.net>

This may work incorrectly if you have some symbolic objects more complex
than those in this simple example. Consider:

In[1] = MapAll[Distribute, ((2 a2 + q[a + b + c] + a3 ** a4) ** a6) ** a7]

Out[1] = 2 (a2 ** a6) ** a7 + ((a3 ** a4) ** a6) ** a7 + (q[a] ** a6) **
  a7 + (q[b] ** a6) ** a7 + (q[c] ** a6) ** a7

where q is some general head. There is no reason why the function should
distribute over q, since nothing is known about q. My version does not do
it:

In[2]  = distributeAll[((2 a2 + q[a + b + c] + a3 ** a4) ** a6) ** a7]

Out[2] = 2 (a2 ** a6) ** a7 + ((a3 ** a4) ** a6) ** a7 + (q[a + b + c] **
a6) **
   a7


Regards,
Leonid


On Mon, Sep 28, 2009 at 7:08 AM, Kurt TeKolste <tekolste at fastmail.us> wrote:

> Doesn't this have the same effect with a bit less code?
>
> In[30]:= MapAll[Distribute, ((2 a2 + a3 ** a4) ** a6) ** a7]
>
> Out[30]= 2 (a2 ** a6) ** a7 + ((a3 ** a4) ** a6) ** a7
>
> In[31]:= MapAll[Distribute, (2 a2 + a3 ** a4) ** (3 a6)]
>
> Out[31]= 6 a2 ** a6 + 3 (a3 ** a4) ** a6
>
> ekt
>
> On Sun, 27 Sep 2009 07:32 -0400, "Leonid Shifrin" <lshifr at gmail.com>
> wrote:
> > Hi Crhis,
> >
> > I think you are looking for something like this:
> >
> > ClearAll[distributeAll];
> > distributeAll[expr_] :=
> >   expr //. x : HoldPattern[a_ ** Plus[b__] | Plus[b__] ** a_] :>
> >     Distribute[x];
> >
> > In[1] =
> > distributeAll[((2 a2 + a3 ** a4) ** a6) ** a7]
> >
> > Out[1] =
> > 2 (a2 ** a6) ** a7 + ((a3 ** a4) ** a6) ** a7
> >
> > In[2] =
> > distributeAll[(2 a2 + a3 ** a4) ** (3 a6)]
> >
> > Out[2] =
> > 3 (2 a2 ** a6 + (a3 ** a4) ** a6)
> >
> > Perhaps the name of the function (distributeAll) could
> > have been chosen better.
> >
> > Regards,
> > Leonid
> >
> >
> >
> > On Sat, Sep 26, 2009 at 3:12 AM, ChrisL <chris.ladroue at gmail.com> wrote:
> >
> > > Dear all,
> > > I am using a non-associative, non-commutative product **
> > > (NonCommutativeMultiply[]). I have a procedure which builds long
> > > polynomials that use ** and the usual Times. What I need eventually is
> > > to extract each of the mononials (parts of the final expression that
> > > do not contain any Plus[]) for some further processing.
> > > I defined NonCommutativeMultiply[] very simply like this:
> > > Unprotect[NonCommutativeMultiply];
> > > ClearAttributes[NonCommutativeMultiply, Flat]; (* forcing non-
> > > associativity *)
> > > 0 ** x_ := 0;
> > > x_ ** 0 := 0;
> > > 1 ** x_ := x;
> > > x_ ** 1 := x;
> > > (m_Integer*x_) ** y_ := m*(x ** y);
> > > x_ ** (m_Integer*y_) := m (x ** y);
> > > Protect[NonCommutativeMultiply];
> > >
> > > And getting the full expansion seems to work fine:
> > > Distribute[2 (3 a1) ** (5 a2)]
> > > Distribute[a1 ** (2 a2 + a3 ** a4)]
> > > yields
> > > 30 a1 ** a2
> > > 2 a1 ** a2 + a1 ** (a3 ** a4)
> > > This is great: I can pick up each mononial with Table[expr[[i]],
> > > {i,Length[expr]}]
> > >
> > > Unfortunately, the expansion seems to stop at the second level. Thus:
> > > Distribute[((2 a2 + a3 ** a4 ) ** a6) ** a7]
> > > Distribute[(2 a2 + a3 ** a4 ) ** (3 a6)]
> > > yields
> > > ((2 a2 +  a3 ** a4) ** a6) ** a7
> > > 3 (2 a2  + a3 ** a4) ** a6
> > >
> > > when I need:
> > > 2 (a2**a6)**a7 + ((a3**a4)**a6)**a7
> > > and
> > > 6 a2**a6 + 3 (a3**a4)**a6
> > >
> > >  Is there any way achieve this? Or do I need to write the full
> > > expansion algorithm myself? Note that the final expression will be
> > > much longer - about 30'000 mononials.
> > >
> > > thank you very much in advance!
> > > Cheers.
> > >
> > >
> >
> Regards,
> Kurt Tekolste
>
>
>


  • Prev by Date: Re: A question about parallel computation in mathematica
  • Next by Date: Re: Re: A question about parallel computation in mathematica
  • Previous by thread: Re: Re: Full expansion with a mixture of Times
  • Next by thread: Re: Full expansion with a mixture of Times and NonCommutativeMultiply