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) enter image description here

  2. Step operation (S)

enter image description here

With these two operations, bellow shows the first three steps of a quantum walk enter image description here

I hope to express this process in an intuitive Mathematica codes.

The result of one step can be expressed as

enter image description here

The two operators, H and S, are put on these two variables

enter image description here

I do not know how to realize such a tensor product in Mathemcatica.

enter image description here,

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)

enter image description here

To realize this equation in Mathematica, I test an example first, as shown below .

enter image description here

My expected result is

enter image description here

But I cannot obtain this result.

My questions are:

  1. How can I realize enter image description here 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,

  • $\begingroup$ btw you can use latex syntax for equations. $\endgroup$
    – lalmei
    Aug 28, 2014 at 12:50
  • $\begingroup$ @lalmei, Thank for you information! How to show latex in stackexchange? Do you have some tutorial link? $\endgroup$
    – user14634
    Aug 29, 2014 at 6:59
  • $\begingroup$ 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. $\endgroup$
    – lalmei
    Aug 29, 2014 at 10:43
  • $\begingroup$ @lalmei, thanks a lot! $\endgroup$
    – user14634
    Aug 29, 2014 at 11:13

1 Answer 1


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[2] state["↑", index] + 
  1/Sqrt[2] 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]
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[2])

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.

  • $\begingroup$ 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[2]) is rearranged as (-state["[DownArrow]", -3] - 2 state["[DownArrow]", -1] + state["[UpArrow]", -1] + state["[DownArrow]", 1] + state["[UpArrow]", 3])/(2 Sqrt[2]) $\endgroup$
    – user14634
    Aug 30, 2014 at 9:06
  • $\begingroup$ 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. $\endgroup$ Aug 30, 2014 at 10:48
  • $\begingroup$ 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! $\endgroup$
    – user14634
    Aug 30, 2014 at 14:14
  • $\begingroup$ 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. $\endgroup$ Aug 30, 2014 at 20:57
  • $\begingroup$ 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]))^2+(1/(2 Sqrt[2]))^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! $\endgroup$
    – user14634
    Sep 2, 2014 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.