Implementing associative algebras in Mathematica
We introduce implementation of noncommutative algebras via Mathematica.
Designing idea
What expressions are noncommutative? We can specify and store noncommutative operators in the list $operator
and use FreeQ
to determine whether an expression is a scalar or an operator.
$operator = {};
scalarQ[expr_] :=
FreeQ[expr,Alternatives@@$operator];
The function scalarQ[expr]
returns True
when expr
is a scalar.
We then implement the relations of noncommutative multiplication by a list of rules $relation
, and simplify expressions using the function ReplaceRepeated
.
$relation = {};
algebraSimplify[expr_] :=
ReplaceRepeated[expr,$relation]//Simplify;
Noncommutative multiplication needs to satisfy the rules of linearity and distributivity, which is independent of specific algebras:
NonCommutativeMultiply//Unprotect;
NonCommutativeMultiply//Attributes = {Flat,OneIdentity};
$relationInternal = {
x_**y_/;scalarQ[x]||scalarQ[y]:>x*y,
(k_?scalarQ*x_)**y_:>k*x**y,
x_**(k_?scalarQ*y_):>k*x**y,
(x_+y_)**z_:>x**z+y**z,
z_**(x_+y_):>z**x+z**y
};
Here we have overload the internal function NonCommutativeMultiply
with operator form **
by adding the attributes {Flat,OneIdentity}
.
To make the results readable, we define additional formatting rules.
$printing = {} ;
algebraPrint[expr_] :=
ReplaceRepeated[expr,$printing];
To ensure the convergence of ReplaceRepeated
, we need to determine the ordering of operators, and a simple choice is the Poincare-Birkhoff-Witt basis.
Example
$operator = {X,Y,H,v};
$relation = {
Splice@$relationInternal,
X**H:>-2 X+H**X,
H**Y:>-2 Y+Y**H,
X**Y:>H+Y**X,
H**v[h_]:>h v[h],
X**v[h_]:>0
};
To-do
- algebra and module from factorization algebra