Any suggestions as to how to speed up the computational time for this quantum walk problem which is coded using a normalized SparseArray coin operator as follows:
ClearAll["Global`*"]
(*Define number of sites*)
n = 10;
init = SparseArray[{{1, 1} -> 1, {i_, 1} /; i != 1 -> 0}, {n, 1}];
init = Normalize[init, Norm[#, 1] &];
(*Coin operator*)
Hadamardg =
SparseArray[{{i_, j_} /; i == j ->
1/Sqrt[2], {i_, j_} /; j == i + 1 || j == i - 1 ->
1/Sqrt[2]}, {n, n}];
Hadamardg = MatrixPower[Hadamardg, 1/2];
Hadamardg = Normalize[Hadamardg, Norm[#, 1] &];
Shift = SparseArray[{{i_, i_} -> 0, {i_, j_} /; j == i + 1 ->
1, {i_, j_} /; j == i - 1 -> 1}, {n, n}];
steps = 5;
(* Quantum walk *)
state = Nest[(Shift . Hadamardg . #) &, init, steps];
ListPlot[Transpose[Abs[state]^2][[1]], PlotRange -> All,
AxesLabel -> {"Position", "Probability"}]
MatrixPower
asHadamardg = MatrixPower[Hadamardg // N, 1/2];
$\endgroup$A = Shift . Hadamardg
only once and then doingstate = Nest[(A.#) &, init, steps];
might pay off. $\endgroup$n
and largesteps
, you might want to consider also to diagonalizeA
. Then each iteration (i.e., multiplying with the diagonal) costsn
instead ofn^2
. Diagonalization costsO(n^3)
, so this should be faster only ifsteps * n^2
is much greater thann^3 + steps * n
. $\endgroup$state
: shouldn't it beinit = Normalize[init, Norm[#, 2] &];
(orinit = Normalize[init]
, which is shorter), and shoudn't the matriz you apply recursively be unitrary? Like $\mathrm{e}^{\mathrm{i} \,\Delta t \, H}$? with a self-adjoint matrixH
? $\endgroup$