# Defining a*b=-b*a

I am fairly new to using Mathematica and was wondering if it's possible to define something along the lines of: $$a*b=-b*a$$ a sort of antisymmetry or skew symmetry if you will. I would like to do this so that when I multiply by some number say: $$a*b*3=-b*a*3$$ where the order in which the "a" and "b" are multiplied is preserved since there would be a antisymmetry. Hence, $$\left(a*b*3 \right) + \left(b*a*3 \right)=0$$ Would this be possible to do in Mathematica.

Edit: Essentially what I would like to define is the following

$$a_{i} a_{j}=\left\{\begin{array}{ll}-a_{j} a_{i}, & \text { For } i \neq j \\ 1, & \text { For } i=j\end{array}\right.$$

I have written the following in Mathematica using NonCommutativeMultiply[],

Unprotect[a]
ClearAll@a
a /: NonCommutativeMultiply[a[i_], a[j_]] /;
i < j := -NonCommutativeMultiply[a[j], a[i]]
a /: NonCommutativeMultiply[a[i_], a[i_]] := 1
Protect[a]


which gets only half the job done. I guess I would like to have this noncommutative multiplication follow all the usual axioms that the usual binary operation of multiplication does, (factoring out like terms, distributive property, works on vectors, etc.). There is no guide in how to define new rules for this new operation and the NonCommutativeMultiply[] only gets me so far. Is there any where I can read or get some assistance in order to properly define this? Thank you

What you are trying to do is implement a Grassmann Algebra. A Grassmann Algebra is exactly the algebra of anti commuting numbers you describe above. That kind of algebra is frequently met in quantum many particle physics. Fermion coherent states for example have eigenvalues which anti commute.

Since Grassmann numbers are well known in Physics it's obvious that someone implemented this before and a with a quick internet search a very nice package by Mathew Headrick named grassmann.m can be found on his site.

You can define the generators of your algebra with the Fermion function:

Fermion[a, b]


Afterwards you can use them with the NonCommutativeMultiply operator.

A few tests:

a**b + b**a
Out: 0


Another test

a**b + 2*b**a
Out: -a**b


Final test

a**a
Out: 0


That package has many more features, which might be useful depending on your area of interest. The package also includes an extensive documentation. As stated on the website if you use that package for research always remember to give proper credit to the author.

• Thank you so very much this helps immensely! And I sure will! – lastgunslinger May 1 at 18:44

Make use of FeynCalc. It is a package from the online Mathematica package repository on github.com: FeynCalc

The command is:

DeclareNonCommutative[a, b]


And then:

DataType[a, b, NonCommutative]


This has the datatypes: NonCommutative, PositiveInteger, NegativeInteger, PositiveNumber, FreeIndex, and GrasmannParity.

There are definitions like Anticommutator, DotSimplify, CommutatorExplicit and more.

With the package, FeynCalc comes great documentation with good examples.