Full expansion with a mixture of Times and NonCommutativeMultiply
- To: mathgroup at smc.vnet.net
- Subject: [mg103517] Full expansion with a mixture of Times and NonCommutativeMultiply
- From: ChrisL <chris.ladroue at gmail.com>
- Date: Sat, 26 Sep 2009 06:12:52 -0400 (EDT)
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.
- Follow-Ups:
- Re: Re: Re: Full expansion with a
- From: Leonid Shifrin <lshifr@gmail.com>
- Re: Re: Full expansion with a mixture of Times
- From: "Kurt TeKolste" <tekolste@fastmail.us>
- Re: Full expansion with a mixture of Times and
- From: Leonid Shifrin <lshifr@gmail.com>
- Re: Re: Re: Full expansion with a