As we all know, Mathematica has extensive built-in support for computations in free commutative algebras, AKA polynomials algebras. It's also not that hard to make computations in exterior algebras with a fixed set of generators. One possibility is to use NonCommutativeMultiply, follow the documentation to make it into a bilinear operation, and explicitly stating that the generators anti-commute:
ncm[(h : NonCommutativeMultiply)[a___, b_Plus, c___]] :=
Distribute[h[a, b, c], Plus, h, Plus, ncm[h[##1]] &]
ncm[a_Plus] := ncm /@ a
ncm[(h : NonCommutativeMultiply)[a___, b_Times, c___]] :=
Most[b] ncm[h[a, Last[b], c]]
(* Skew-symmetry )
generators = Array[e, 5];
(ncm[a___ * # ** #2 ** b___] := -ncm[a ** #2 ** # ** b]) & @@@
Subsets[generators, {2}];
(ncm[___ ** # ** # ** ___] = 0) & /@ generators;
ncm[a_] := ExpandAll[a]
(* Examples )
ncm[e[1] * e[2] + e[2] ** e[1]]
(* 0 )
ncm[e[3] * e[2] ** e[3]]
(* 0 *)
This is cumbersome but it kind of works. A somewhat simpler possibility is to use the facilities for tensor computations, like here: Computations in the exterior algebra
Now, I'd like to have a graded commutative algebra: generators have a certain degree, and homogeneous elements satisfy $$xy = (-1)^{|x| \, |y|}yx.$$
It's also possible to massage the ncm function into making this work. For example, if I have three generators $x,y,z$ of respective degrees $1,2,3$, I can replace the section "Skew-symmetry" of the code with:
ncm[a___ ** x ** x ** b___] := 0
ncm[a___ ** z ** z ** b___] := 0
ncm[a___ ** y ** x ** b___] := ncm[a ** x ** y ** b]
ncm[a___ ** z ** x ** b___] := -ncm[a ** x ** z ** b]
ncm[a___ ** z ** y ** b___] := ncm[a ** y ** z ** b]
And this kind of works:
ncm[x ** z ** y + y ** z ** x]
(* 0 *)
ncm[y ** z ** y ** x]
(* 0 *)
But this is very cumbersome: I'm doing everything by hand in the definition. It feels like there must be a better way... Sure, I could automatize a little by defining the degrees somewhere and then iterating over pairs to create definitions, but that's not great. Basically, I'm working in the tensor algebra and explicitly adding relation for the graded commutativity of variables - but that's a very inefficient way of making computations. Gröbner bases and so on are much smaller when taking the commutativity right into the structure.
I also tried to do something analogous to Computations in the exterior algebra but I was unable to.
Is there a nice way to handle graded commutativity in Mathematica?