2
$\begingroup$

In order to optimize my computation and save memory, I'd like to modify NonCommutativeMultiply so that for a given $n$ one has $a1**a2** \cdots **an=0$ for any $a1, a2, \ldots, an$.

To make it simpler: I need only $n=3,4,5$.

I've already modified NonCommutativeMultiply to be able to work with formal power series in non-commutative variables.

ClearAll[NCM, n]
NCM[(h :NonCommutativeMultiply)[a___, b_Plus,
 c___]] := Distribute[h[a, b, c], Plus, h, Plus, NCM[h[##]] &];
NCM[(h : NonCommutativeMultiply)[c1___, b_Times, c2___]] := Most[b] 
    NCM[h[c1, Last[b], c2]];
NCM[a_ + b_] := NCM[a] + NCM[b];
NCM[a_ b_] := a NCM[b];
NCM[a_] := ExpandAll[a];

I'd like to have, for example, for $n=3$

NCM[x**(x+y**x)**y+x**y]=x**x**y+x**y 

Thanks for any suggestions.

$\endgroup$
  • 1
    $\begingroup$ Not clear enough for me.Can you explain further? $\endgroup$ – Dr. belisarius Jan 27 '15 at 15:42
  • $\begingroup$ I make computations with formal power series in non-commutative variables. In course of calculating the beginning of the resulting power series (= monomials of degree lower than $n$), I try to get rid of monomials of degree not lower than $n$. $\endgroup$ – 8k14 Jan 27 '15 at 16:15
1
$\begingroup$
ClearAll[ncm];
ncm[x__] := 0 /; Length[{x}] > n
ncm[x__] := NonCommutativeMultiply[x] /; Length[{x}] <= n
n = 3;
{ncm[c, d, f], ncm[c, d, f, g]}

(* {c ** d ** f, 0} *)
$\endgroup$
  • $\begingroup$ @8k14 Please edit your answer and add how you managed to include the distributive property $\endgroup$ – Dr. belisarius Jan 27 '15 at 17:11
  • $\begingroup$ Sorry, I can't edit my comment. Instead, I expanded my question. $\endgroup$ – 8k14 Jan 27 '15 at 17:43
1
$\begingroup$
ncm[a__, n_List: {5}] :=
NonCommutativeMultiply[a] && Length[List[a]] < n[[1]] || 
0 && Length[List[a]] >= n[[1]]

I defined a function ncm[a,{n}] where a is a sequence of multiplyers and {n} is an optional argument which says starting from how many multiplyers will evaluate function to zero.

for example by default n is set to length of sequence of arguments = 5

ncm[1, 2, 3, 4]
(*1 ** 2 ** 3 ** 4*)

ncm[1, 2, 3, 4, 5]
(*0*)

ncm[1, 2, 3, 4, 5, {6}]
(*1 ** 2 ** 3 ** 4 ** 5*)

Addining new behavior

ncm[x___, a_ + b_, y___] := ncm[x, a, y] + ncm[x, b, y]
ncm[a__, n_List: {5}] := 
NonCommutativeMultiply[a] && Length[List[a]] < n[[1]] || 0 && Length[List[a]] >= n[[1]]
$\endgroup$
  • $\begingroup$ Thanks but your method does not work with power series. For example, for $n=3$ I'd like to have $ncm[x∗∗(x+x∗∗y)∗∗y+x∗∗y]=x∗∗x∗∗y+x∗∗y$ (I have already modified ncm to be distributive) $\endgroup$ – 8k14 Jan 27 '15 at 17:18
  • $\begingroup$ @8k14 it's a problem of function NonCommutativeMultiply rather then of this realization $\endgroup$ – k_v Jan 27 '15 at 17:53
  • $\begingroup$ Thus what is your suggestion? $\endgroup$ – 8k14 Jan 27 '15 at 18:50
  • $\begingroup$ @8k14 look at updated defenition of ncm $\endgroup$ – k_v Jan 27 '15 at 19:11
  • $\begingroup$ I may be wrong but ncm[x ** (x + x ** y) ** y + x ** y] for $n=3$ results in x ** y + x ** (x + x ** y) ** y $\endgroup$ – 8k14 Jan 27 '15 at 19:42
0
$\begingroup$

It suffices to add just one line

NCM[a___] := 0 /; Head[a] == NonCommutativeMultiply && Length[a] > n;

Thanks to @belisarius and @k_v.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.