# How to put the tensor product of two operators onto two variables?

I am trying to make an intuitive Mathemtaica program to show the principle of quantum walking. The idea of quantum walking is very simple and direct, but when I try to transfer it into Mathemitca codes, I meet several difficulties.

The principle of quantum walk is introduced here http://susan-stepney.blogspot.jp/2014/02/mathjax.html and here http://xxx.tau.ac.il/abs/quant-ph/0303081

There are two operations in one step:

1. Coin operation (Hadamard coin H) 2. Step operation (S) With these two operations, bellow shows the first three steps of a quantum walk I hope to express this process in an intuitive Mathematica codes.

The result of one step can be expressed as The two operators, H and S, are put on these two variables I do not know how to realize such a tensor product in Mathemcatica. ,

where S and H are two operators; x and y are two variables; x is an array; y is an integer.

But I guess this equation is correct, because similar equation is shown in wiki( http://en.wikipedia.org/wiki/Tensor_product) To realize this equation in Mathematica, I test an example first, as shown below . My expected result is But I cannot obtain this result.

My questions are:

1. How can I realize in Mathematica？

2. How to intuitively express the first three steps of quantum walk using Mathematica codes?

I have tried to solve this problem for several days, but made no progress. Any help or suggestion will be highly appreciated,

• btw you can use latex syntax for equations. Aug 28, 2014 at 12:50
• @lalmei, Thank for you information! How to show latex in stackexchange? Do you have some tutorial link? Aug 29, 2014 at 6:59
• There is a "How to Format" on the right hand side when you edit your question. The link MathJax has all the information, but long story short, just type latex and it interprets automatically . e.g. \$\$<equation>\$\$ etc. Aug 29, 2014 at 10:43
• @lalmei, thanks a lot! Aug 29, 2014 at 11:13

You can implement your "quantum walk" states and operators as follows:

Represent the basis state in the form state[spin, index], where spin is either "↑" or "↓".

Define how the H and S operators act on basis states.

H[state[spin : ("↑" | "↓"), index_]] :=
1/Sqrt state["↑", index] +
1/Sqrt If[spin == "↑", 1, -1] state["↓", index];

S[state[spin : ("↑" | "↓"), index_]] :=
state[spin, index + If[spin == "↑", 1, -1]];


Define simplification rules for the operators, which reduces any operation to one in which operators act only on basis states.

H[u_ + v_] := H[u] + H[v];
S[u_ + v_] := S[u] + S[v];

H[u_?(FreeQ[#, state] &) v_] := u H[v];
S[u_?(FreeQ[#, state] &) v_] := u S[v];


Evaluate the random walk example at the top of your question.

state["↓", 0]
H[%]
S[%]
H[%]
S[%]
H[%]
S[%] // Simplify


I have used Simplify on the final result to rearrange it into a more concise form, which is

(-state["↓", -3] - 2 state["↓", -1] +
state["↓", 1] + state["↑", -1] +
state["↑", 3])/(2 Sqrt)


You can use the Notation package to make state[spin, index] display in a nicer way. For instance, after loading the Notation package, you could use the Notation palette to define the following notation

Notation[\[LeftBracketingBar]spin_〉⊗\[LeftBracketingBar]index_〉 ⟺ state[spin_,index_]]


and then re-evaluate the above random walk to obtain a "prettified" version of the output.

• I have a further question: How to rearrange the element in an increasing order of the “index”? e.g., (-state["[DownArrow]", -3] - 2 state["[DownArrow]", -1] + state["[DownArrow]", 1] + state["[UpArrow]", -1] + state["[UpArrow]", 3])/(2 Sqrt) is rearranged as (-state["[DownArrow]", -3] - 2 state["[DownArrow]", -1] + state["[UpArrow]", -1] + state["[DownArrow]", 1] + state["[UpArrow]", 3])/(2 Sqrt) Aug 30, 2014 at 9:06
• The easiest way to get the ordering you want is to define the basis state as state[index, spin] rather than state[spin, index], and to correspondingly adjust the definitions of how the H and S operators act on these basis states. Don't forget to remove the old definitions first, or start with a fresh kernel. Mathematica will then automatically display the result ordered as you want it to be. Aug 30, 2014 at 10:48
• Thanks a lot! But I need to keep the form of state[spin,index], so as to show the original physical meaning. Would you please make a high-level program to rearrange the element? Thank you very much! Aug 30, 2014 at 14:14
• You can display the results in the form that you want by simply using the Notation package (that I mentioned in my answer above) to map each internal state[index, spin] expression to your required state[spin, index] displayed output. You then get the best of both worlds - convenient internal computations AND convenient displayed output - with the Notation package connecting the two of these together. Aug 30, 2014 at 20:57
• Thanks a lot for your good suggestion. I have succeesfully gotten the order I need. Furthermore, I need to extract the coefficient of each term, so as to plot a figure of positions VS probabilities (probability= square of the coefficient). In the above example, the probability for position -1 is (-2/(2 Sqrt))^2+(1/(2 Sqrt))^2. Do you have some suggestions for picking up the coefficients? I have tried several commands in Mathematica, but not succeed. Thank you very much! Sep 2, 2014 at 9:58