# How to implement this simple product rule in mathematica [duplicate]

Firstly i have defined a simple function below.

   dotPro[a_, b_] := a*b + a*b;


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[σ^2, 1];
r2 = Rule[σ^2, 1];
r3 = Rule[σ σ, I*σ];
r4 =Rule[σ σ, -I*σ];


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 ϵ + q ϵ + I q ϵ σ + I q ϵ σ)


What i want to get is this(minus sign)

 q ϵ + q ϵ -I q ϵ σ + I q ϵ σ


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 σ σ it should be replaced by I*σ and for σ σ it should be replaced by -I*σ

I tried to achieve it like this,but no success

list = {{1, 1}, {1, 2}, {2, 1}, {2, 2}};
t1[[#[]]]*t2[[#[]]] & /@ list /. r1 /. r2 /. r3 /. r4

• Could you please specify the commutators of q, σ, ε. That is, what are [q[i],σ[j]], [q[i],ε[j]], and [σ[i],ε[j]]? Aug 30 '13 at 15:08
• q, σ, ε all commute with each other, namely [q[i],σ[j]]=0, [q[i],ε[j]]=0 and [σ[i],ε[j]]=0 Aug 30 '13 at 15:26
• The σ are exactly the matrices PauliMatrix[i], so it's easiest to realize this algebra using them explicitly. You can always re-express results of explicit matrix algebra in terms of the Pauli matrices because the latter (together with IdentityMatrix or PauliMatrix) form a basis of the space of $2\times 2$ matrices.
– Jens
Aug 30 '13 at 16:01
• @Jens Thanks for the link.i think it will help.i will look at it later and see if can apply it my problem.Also as you said if i actually introduced the sigma matrix like s[x_] := PauliMatrix[x]; Then off-course i get the correct matrix representation but what i really want is the symbolic sigma3 in my answer because i have to use that in my further calculations. Aug 30 '13 at 16:28

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.b + a.b;
dotPro[q, σ].dotPro[ε, σ]
Distribute[%]
% /. {Dot[x___, a_, y___, a_, z___] :> Dot[x, y, z]
, Dot[x___, a_, y___, a_, z___] :> I Dot[x, y, a]
, Dot[x___, a_, y___, a_, z___] :> -I Dot[x, y, a]}

• @ hector thanks, this is good enough for me. Aug 31 '13 at 5:49

To flesh out what I mentioned in the comment: one can also attack this problem by implementing the non-commuting objects $\sigma$ using PauliMatrix, because the given rules in the question are faithfully represented by these $2\times 2$ matrices. All algebraic simplifications then occur in the matrix form.

But the goal is to get back a result in terms of the symbolic matrices $\sigma$. Fortunately, this can always be done because the Pauli matrices when combined with the unit matrix form a basis of the vector space of two-dimensional matrices. This means that for a given matrix a, the equation Solve[{x1, x2, x3, x4}.PauliMatrix[{0, 1, 2, 3}] == a] has one and only one solution {x1, x2, x3, x4}. These coefficients can be used to form a linear expression using the symbolic matrices $\sigma$ in the end.

So here is a function pauliReduce which takes an expression involving the symbolic σ[i] (where i = 0, 1, 2, 3), and returns a simplified result in terms of the same symbols, and potentially the unit matrix which I called $\hat{1}$ to distinguish it from the number 1. The unit matrix is also given by σ.

Clear[pauliReduce]
pauliReduce[a_] := Module[
{x, symbolicPauliIndices, expression},
x = Array[\[FormalX], 4];
symbolicPauliIndices =
DeleteDuplicates[Cases[a, σ[i_Symbol] :> i, Infinity]];
expression = {OverHat, σ, σ, σ}.(
x /. First[
Solve[
x.PauliMatrix[{0, 1, 2, 3}]
==
a /. σ[i_] :>
Sum[KroneckerDelta[i, k] PauliMatrix[k], {k, 0, 3}],
x
]
]
);
FullSimplify[
expression,
Assumptions ->
Map[# \[Element] Integers && 1 <= # <= 3 &,
symbolicPauliIndices]]
]


Here are some relations that can now be proved:

pauliReduce[σ.σ]


$\text{I}$ σ$$

pauliReduce[σ.σ - σ.σ]


2 $\text{I}$ σ$$

pauliReduce[σ.σ]


$\hat{1}$

pauliReduce[σ.σ + σ.σ]


0

pauliReduce[MatrixExp[α σ]]


Cosh[α] $\hat{1}$ + Sinh[α] σ$$

pauliReduce[σ[i].σ[j] + σ[j].σ[i]] For the example in the question, I get this (after correcting the multiplications to make them matrix products where needed):

res =
q ϵ σ.σ +
q ϵ σ.σ +
q ϵ σ.σ +
q ϵ σ.σ;

pauliReduce[res]


$\hat{1}\,q ϵ + \text{I} (q (ϵ - ϵ) + q ϵ)\, σ$

The advantage of this approach is in particular shown by the application of MatrixExp which is automatically simplified. In a more algebraic approach without matrix representation, you would first have to introduce the series expansion for such matrix functions by hand.