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$
Thanks for any suggestions.