teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

edit

2018/05/08 12:31

投稿

mkgrei
mkgrei

スコア8562

answer CHANGED
@@ -6,4 +6,61 @@
6
6
  ---
7
7
 
8
8
  wikipedia先生によると対称になるのは[1,i]/sqrt(2)の時ですが…
9
- それが正しければ、ノルムの計算方法もまずいです。
9
+ それが正しければ、ノルムの計算方法もまずいです。
10
+
11
+ ---
12
+
13
+ ```python
14
+ import numpy as np
15
+ import matplotlib.pyplot as plt
16
+
17
+ n = 100
18
+ H = np.array([[1, 1],[1, -1]]) / np.sqrt(2)
19
+ P = np.zeros((2, 2)); P[0, :] = H[0, :]
20
+ Q = np.zeros((2, 2)); Q[1, :] = H[1, :]
21
+
22
+ pos = np.zeros((2*n+1, 2), dtype=np.complex)
23
+ pos[n, :] = np.array([1, 1j], dtype=np.complex) / np.sqrt(2)
24
+ x = np.arange(-n, n+1)
25
+
26
+ history = np.zeros((n, 2*n+1, 2), dtype=np.complex)
27
+ history[0, :, :] = pos[:, :]
28
+ prob = np.zeros((n, 2*n+1))
29
+ prob[0, :] = np.sum(np.conj(history[0, :, :]) * history[0, :, :], axis=-1)[:]
30
+ for t in range(1, n):
31
+ history[t, :-1, :] += np.inner(history[t-1, 1:, :], P.T)
32
+ history[t, 1:, :] += np.inner(history[t-1, :-1, :], Q.T)
33
+ prob[t, :] = np.sum(np.conj(history[t, :, :]) * history[t, :, :], axis=-1)[:]
34
+
35
+ history_ = np.zeros((n, 2*n+1))
36
+ history_[0, n] = 1.
37
+ for t in range(1, n):
38
+ history_[t, :-1] += history_[t-1, 1:]/2.
39
+ history_[t, 1:] += history_[t-1, :-1]/2.
40
+
41
+ def show(x, y, y_=None, nonzeros=True):
42
+ if nonzeros:
43
+ s = 1
44
+ ss = 2
45
+ else:
46
+ s = 0
47
+ ss = 1
48
+ plt.xlabel("x")
49
+ plt.ylabel("probability")
50
+ plt.ylim((0, np.max(y)*1.1))
51
+ plt.xlim((np.min(x), np.max(x)))
52
+ plt.plot(x[s::ss], y[s::ss], color="red", linewidth=1.0)
53
+ if y_ is not None:
54
+ plt.plot(x[s::ss], y_[s::ss], color="blue", linewidth=1.0)
55
+ plt.grid()
56
+ plt.savefig('q.png')
57
+ plt.show()
58
+
59
+ show(x, prob[-1], y_=history_[-1])
60
+ ```
61
+
62
+ 参考:
63
+ https://arxiv.org/pdf/quant-ph/0303081.pdf
64
+ Google画像: Quantum Random Walk
65
+
66
+ ![QRW:赤、RW:青](c016c0a68f52e5719291a801f3fd99bf.png)

2

edit

2018/05/08 12:31

投稿

mkgrei
mkgrei

スコア8562

answer CHANGED
@@ -1,4 +1,9 @@
1
1
  s_listの更新のタイミングが悪いことと、
2
2
  確保してあるs_listのサイズが足りないことが問題だと思います。
3
3
 
4
- 端の場所がおかしいのも問題ですね…
4
+ 端の場所がおかしいのも問題ですね…
5
+
6
+ ---
7
+
8
+ wikipedia先生によると対称になるのは[1,i]/sqrt(2)の時ですが…
9
+ それが正しければ、ノルムの計算方法もまずいです。

1

Edit

2018/05/07 23:53

投稿

mkgrei
mkgrei

スコア8562

answer CHANGED
@@ -1,2 +1,4 @@
1
1
  s_listの更新のタイミングが悪いことと、
2
- 確保してあるs_listのサイズが足りないことが問題だと思います。
2
+ 確保してあるs_listのサイズが足りないことが問題だと思います。
3
+
4
+ 端の場所がおかしいのも問題ですね…