How to specify algebraic relations between objects?
There are different ways to go about doing this. I'll set UpValues
on e
for the multiplication of the basis vectors as you've defined them, and I'll use replacement Rule
s for the simplification of products of vectors expanded in the basis.
First of all
Unprotect[e]
ClearAll@e
e /: NonCommutativeMultiply[e[i_], e[j_]] /; i < j := -NonCommutativeMultiply[e[j], e[i]]
e /: NonCommutativeMultiply[e[i_], e[i_]] := 1
Protect[e]
This sets up a "normal order" for the products of basis vectors. It might not be what you want, but it aids in simplifying compound expressions. Once you've run the lines above, then (non-commutative) products of the e
s are automatically sorted according to descending order left to right:
e[3] ** e[3]
(* 1 *)
and
e[1] ** e[2]
(* -e[2] ** e[1] *)
and
e[2] ** e[1]
(* e[2] ** e[1] *)
To extend this basis to a linear space, we form all formal linear combinations of these basis elements. Particular examples are
ClearAll[a,b]
vec1 = Sum[e[j] a[j], {j, 1, 3}]
vec2 = Sum[e[j] b[j], {j, 1, 3}]
(* a[1] e[1] + a[2] e[2] + a[3] e[3] *)
(* b[1] e[1] + b[2] e[2] + b[3] e[3] *)
Then, we can implement some linearity rules and scalar rules
ncmRules = {
a___ ** (-b_) ** c___ :> -a ** b ** c,
a_Plus ** b_ :> (# ** b & /@ a),
a_ ** b_Plus :> (a ** # & /@ b),
x___ ** a_ ** y_ /; FreeQ[a, e] :> a x ** y,
x_ ** a_ ** y___ /; FreeQ[a, e] :> a x ** y,
x___ ** (a_ y_) ** z_ /; FreeQ[a, e] :> a x ** y ** z,
(x_) ** (a_ y_) ** z___ /; FreeQ[a, e] :> a x ** y ** z,
NonCommutativeMultiply[a_] :> a
};
and define a function that applies these rules:
ncmSimplify[expr_] := expr //. ncmRules
For instance,
Collect[vec1 ** vec2 // ncmSimplify, _e ** _e]
(* a[1] b[1] + a[2] b[2] + a[3] b[3]
+ (a[2] b[1] - a[1] b[2]) e[2] ** e[1]
+ (a[3] b[1] - a[1] b[3]) e[3] ** e[1]
+ (a[3] b[2] - a[2] b[3]) e[3] ** e[2] *)
and
e[1] ** e[2] ** e[1] ** e[2] // ncmSimplify
(* -1 *)
There is a new paclet for doing Geometric Algebra:
PacletInstall["https://wolfr.am/N9OenlOc"]
<< GeometricAlgebra`;
You can construct multivectors of any algebra with it, and use it in computations:
{e1, e2, e3} = MultivectorBasis[GeometricAlgebra[3], 1];
e1 ** e2 ** e1 ** e2
(e1 ** e2) ^ 2
e1 ^ (3/5)
And more:
Inverse[2 e1]
MultivectorFunction[Exp, e1]
(e1 + 3 e2)["Normalize"]
(e1 + 2 e2 + e3)["Conjugate"]
e1["Dual"]
MultivectorMatrix[e1 + I e2]
ConvertGeometricAlgebra[e1, GeometricAlgebra[0, 3]]