Firstly i have defined a simple function below.
dotPro[a_, b_] := a[1]*b[1] + a[2]*b[2];
Then i create two terms using the above function.
t1=dotPro[q,σ];
t2=dotPro[ϵ,σ];
Then i have some rules regarding how these parameters multiply
r1 = Rule[σ[1]^2, 1];
r2 = Rule[σ[2]^2, 1];
r3 = Rule[σ[1] σ[2], I*σ[3]];
r4 =Rule[σ[2] σ[1], -I*σ[3]];
Now i expand the product
res = Expand[t1*t2]
Finally i apply the said rules to my expanded terms
res /. r1 /. r2 /. r3 /. r4
The answer i get is the following
(q[1] ϵ[1] + q[2] ϵ[2] + I q[2] ϵ[1] σ[3] + I q[1] ϵ[2] σ[3])
What i want to get is this(minus sign)
q[1] ϵ[1] + q[2] ϵ[2] -I q[2] ϵ[1] σ[3] + I q[1] ϵ[2] σ[3]
I know what the problem is,its related to mathematica assuming commutative product.so at the heart it deals with implementing non-commutative algebra.
So i did find a link to a package here but it was not working and i think this simple thing can be achieved without resort to any packages.
All i want is whenever there is a term with σ[1] σ[2]
it should be replaced by I*σ[3]
and for σ[2] σ[1]
it should be replaced by -I*σ[3]
I tried to achieve it like this,but no success
list = {{1, 1}, {1, 2}, {2, 1}, {2, 2}};
t1[[#[[1]]]]*t2[[#[[2]]]] & /@ list /. r1 /. r2 /. r3 /. r4
Answer
The following code is a quick and dirty solution to your request. The basic idea is to avoid using the usual multiplication and use Dot
instead.
dotPro[a_, b_] := a[1].b[1] + a[2].b[2];
dotPro[q, σ].dotPro[ε, σ]
Distribute[%]
% /. {Dot[x___, a_, y___, a_, z___] :> Dot[x, y, z]
, Dot[x___, a_[1], y___, a_[2], z___] :> I Dot[x, y, a[3]]
, Dot[x___, a_[2], y___, a_[1], z___] :> -I Dot[x, y, a[3]]}
Comments
Post a Comment