-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProjective.lean
More file actions
242 lines (198 loc) · 9.73 KB
/
Copy pathProjective.lean
File metadata and controls
242 lines (198 loc) · 9.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import QuantumComputing.Measurement.Generalized
/-!
# Projective Measurements
Projective measurements generated by vector projectors and their bridge to
generalized measurements.
-/
namespace QuantumComputing
namespace Measurement
/-- Projection operators associated with an arbitrary family of state vectors. -/
noncomputable def projectiveOperators {n outcomes : ℕ}
(u : Fin outcomes → Vector n) : Fin outcomes → Square n :=
fun i => Matrix.proj (u i)
/-- A family of vectors defines a complete projective measurement when its projectors are complete. -/
def IsProjectiveComplete {n outcomes : ℕ} (u : Fin outcomes → Vector n) : Prop :=
IsComplete (projectiveOperators u)
/-- Probability for a projective measurement generated by vector projectors. -/
noncomputable def projProb {n outcomes : ℕ}
(u : Fin outcomes → Vector n) (s : Vector n) (i : Fin outcomes) : ℝ :=
((s† ⬝ Matrix.proj (u i) ⬝ s) 0 0).re
/-- Post-measurement state for a projective measurement generated by vector projectors. -/
noncomputable def projPostMeasure {n outcomes : ℕ}
(u : Fin outcomes → Vector n) (s : Vector n) (i : Fin outcomes) : Vector n :=
((1 / Real.sqrt (projProb u s i) : ℝ) : ℂ) • (Matrix.proj (u i) ⬝ s)
/--
Matrix whose rows are the adjoints of a projective-measurement vector family.
Applying it before a computational-basis measurement gives the same outcome
probabilities as measuring the original vector projectors.
-/
noncomputable def projectiveMeasurementOp {n : ℕ} (u : Fin n → Vector n) : Square n :=
fun i j => (u i)† 0 j
/--
Restore operator for the `i`-th computational-basis outcome after using
`projectiveMeasurementOp`.
-/
noncomputable def projectiveRestoreOp {n : ℕ} (u : Fin n → Vector n) (i : Fin n) : Square n :=
u i ⬝ (Vector.basis i)†
/-- Complete projective measurement generated by a family of state-vector projectors. -/
structure Projective (n outcomes : ℕ) where
vector : Fin outcomes → Vector n
isNormalized : ∀ i, Vector.IsNormalized (vector i)
isComplete : IsProjectiveComplete vector
@[simp]
theorem projectiveOperators_apply {n outcomes : ℕ}
(u : Fin outcomes → Vector n) (i : Fin outcomes) :
projectiveOperators u i = Matrix.proj (u i) :=
rfl
theorem generalizedProb_projectiveOperators_of_isNormalized {n outcomes : ℕ}
{u : Fin outcomes → Vector n} (s : Vector n) {i : Fin outcomes}
(hu : Vector.IsNormalized (u i)) :
generalizedProb (projectiveOperators u) s i = projProb u s i := by
simp [generalizedProb, projProb, projectiveOperators, Matrix.proj_mul_proj_of_isNormalized hu]
theorem generalizedPostMeasure_projectiveOperators_of_isNormalized {n outcomes : ℕ}
{u : Fin outcomes → Vector n} (s : Vector n) {i : Fin outcomes}
(hu : Vector.IsNormalized (u i)) :
generalizedPostMeasure (projectiveOperators u) s i = projPostMeasure u s i := by
simp [generalizedPostMeasure, projPostMeasure, projectiveOperators,
generalizedProb_projectiveOperators_of_isNormalized s hu]
theorem projectiveOperators_eq_projectors (n : ℕ) :
projectiveOperators (fun i : Fin n => Vector.basis i) = projectors n :=
rfl
theorem projectiveOperators_computationalBasis_isComplete (n : ℕ) :
IsProjectiveComplete (fun i : Fin n => Vector.basis i) := by
simpa [projectiveOperators_eq_projectors] using projectors_isComplete n
namespace Projective
variable {n outcomes : ℕ}
instance : CoeFun (Projective n outcomes) (fun _ => Fin outcomes → Vector n) where
coe M := M.vector
@[simp]
theorem coe_apply (M : Projective n outcomes) (m : Fin outcomes) :
(M : Fin outcomes → Vector n) m = M.vector m :=
rfl
noncomputable def operator (M : Projective n outcomes) : Fin outcomes → Square n :=
projectiveOperators M.vector
/-- View a complete projective measurement as a generalized measurement. -/
noncomputable def toGeneralized (M : Projective n outcomes) : Generalized n outcomes where
operator := M.operator
isComplete := M.isComplete
/-- Probability of projective measurement outcome `m`. -/
noncomputable def prob (M : Projective n outcomes) (s : Vector n) (m : Fin outcomes) : ℝ :=
projProb M.vector s m
/-- Normalized post-measurement state after projective measurement outcome `m`. -/
noncomputable def postMeasure
(M : Projective n outcomes) (s : Vector n) (m : Fin outcomes) : Vector n :=
projPostMeasure M.vector s m
@[simp]
theorem operator_apply (M : Projective n outcomes) (m : Fin outcomes) :
M.operator m = Matrix.proj (M.vector m) :=
rfl
@[simp]
theorem toGeneralized_operator (M : Projective n outcomes) :
M.toGeneralized.operator = M.operator :=
rfl
@[simp]
theorem prob_eq_projProb (M : Projective n outcomes)
(s : Vector n) (m : Fin outcomes) :
M.prob s m = projProb M.vector s m :=
rfl
@[simp]
theorem postMeasure_eq_projPostMeasure (M : Projective n outcomes)
(s : Vector n) (m : Fin outcomes) :
M.postMeasure s m = projPostMeasure M.vector s m :=
rfl
@[simp]
theorem prob_eq_generalized_prob (M : Projective n outcomes)
(s : Vector n) (m : Fin outcomes) :
M.prob s m = M.toGeneralized.prob s m :=
(generalizedProb_projectiveOperators_of_isNormalized s (M.isNormalized m)).symm
@[simp]
theorem postMeasure_eq_generalizedPostMeasure (M : Projective n outcomes)
(s : Vector n) (m : Fin outcomes) :
M.postMeasure s m = M.toGeneralized.postMeasure s m :=
(generalizedPostMeasure_projectiveOperators_of_isNormalized s (M.isNormalized m)).symm
theorem postMeasure_isNormalized (M : Projective n outcomes)
(s : Vector n) (m : Fin outcomes) (h : M.prob s m ≠ 0) :
Vector.IsNormalized (M.postMeasure s m) := by
have hg : generalizedProb (projectiveOperators M.vector) s m ≠ 0 := by
rw [generalizedProb_projectiveOperators_of_isNormalized s (M.isNormalized m)]
simpa [Projective.prob] using h
have hnorm := generalizedPostMeasure_isNormalized (projectiveOperators M.vector) s m hg
rw [generalizedPostMeasure_projectiveOperators_of_isNormalized s (M.isNormalized m)] at hnorm
simpa [Projective.postMeasure] using hnorm
theorem operator_mul_postMeasure (M : Projective n outcomes) (s : Vector n) (m : Fin outcomes) :
M.operator m ⬝ M.postMeasure s m = M.postMeasure s m := by
unfold Projective.operator Projective.postMeasure projPostMeasure projectiveOperators
rw [Matrix.mul_smul]
congr 1
rw [show Matrix.proj (M.vector m) ⬝ (Matrix.proj (M.vector m) ⬝ s) =
(Matrix.proj (M.vector m) ⬝ Matrix.proj (M.vector m)) ⬝ s by
simp [Matrix.mul, _root_.Matrix.mul_assoc]]
rw [Matrix.proj_mul_proj_of_isNormalized (M.isNormalized m)]
theorem sum_prob_of_isNormalized (M : Projective n outcomes)
{s : Vector n} (hs : Vector.IsNormalized s) :
(∑ m : Fin outcomes, M.prob s m) = 1 := by
calc
(∑ m : Fin outcomes, M.prob s m) = ∑ m : Fin outcomes, M.toGeneralized.prob s m := by
apply Finset.sum_congr rfl
intro m _
exact M.prob_eq_generalized_prob s m
_ = 1 := M.toGeneralized.sum_prob_of_isNormalized hs
noncomputable def computationalBasis (n : ℕ) : Projective n n where
vector := fun i => Vector.basis i
isNormalized := fun i => Vector.basis_isNormalized i
isComplete := projectiveOperators_computationalBasis_isComplete n
@[simp]
theorem computationalBasis_apply {n : ℕ} (i : Fin n) :
(computationalBasis n).vector i = Vector.basis i :=
rfl
@[simp]
theorem computationalBasis_prob {n : ℕ} (s : Vector n) (i : Fin n) :
(computationalBasis n).prob s i = _root_.QuantumComputing.Measurement.prob s i := by
unfold Projective.prob projProb
simp only [computationalBasis_apply]
rw [← proj_def i]
exact quadratic_proj s i
@[simp]
theorem computationalBasis_postMeasure {n : ℕ} (s : Vector n) (i : Fin n) :
(computationalBasis n).postMeasure s i =
_root_.QuantumComputing.Measurement.postMeasure s i := by
unfold Projective.postMeasure projPostMeasure _root_.QuantumComputing.Measurement.postMeasure
simp only [computationalBasis_apply]
rw [show projProb (computationalBasis n).vector s i =
_root_.QuantumComputing.Measurement.prob s i by
simpa [Projective.prob] using computationalBasis_prob s i]
rw [← proj_def i]
end Projective
theorem projProb_eq_quadratic_projector {n outcomes : ℕ}
(u : Fin outcomes → Vector n) (s : Vector n) (i : Fin outcomes) :
projProb u s i = ((s† ⬝ Matrix.proj (u i) ⬝ s) 0 0).re := by
simp [projProb]
theorem projective_quadratic_eq_inner_square {n outcomes : ℕ}
(u : Fin outcomes → Vector n) (s : Vector n) (i : Fin outcomes) :
s† ⬝ Matrix.proj (u i) ⬝ s = ((u i)† ⬝ s)† ⬝ ((u i)† ⬝ s) := by
simp [Matrix.proj, Matrix.mul, Matrix.adjoint, _root_.Matrix.mul_assoc]
theorem prob_projectiveMeasurementOp {n : ℕ} (u : Fin n → Vector n) (s : Vector n)
(i : Fin n) :
prob (projectiveMeasurementOp u ⬝ s) i = projProb u s i := by
let z : ℂ := ((u i)† ⬝ s) 0 0
have hop : (projectiveMeasurementOp u ⬝ s) i 0 = z := by
simp [z, projectiveMeasurementOp, Matrix.mul, _root_.Matrix.mul_apply]
have hquad : projProb u s i = Complex.normSq z := by
rw [projProb]
rw [projective_quadratic_eq_inner_square]
have hsum := sum_prob (((u i)†) ⬝ s)
simpa [prob, z, Matrix.adjoint, Matrix.mul, _root_.Matrix.mul_assoc] using hsum.symm
rw [hquad]
simp [prob, hop]
theorem postMeasure_projectiveMeasurementOp {n : ℕ} (u : Fin n → Vector n) (s : Vector n)
(i : Fin n) :
projPostMeasure u s i =
projectiveRestoreOp u i ⬝ postMeasure (projectiveMeasurementOp u ⬝ s) i := by
unfold projPostMeasure projectiveRestoreOp postMeasure
rw [prob_projectiveMeasurementOp]
ext j k
fin_cases k
simp [projectiveMeasurementOp, proj, Matrix.proj, Matrix.mul, Matrix.adjoint, Vector.basis,
_root_.Matrix.mul_apply, Finset.mul_sum, mul_left_comm, mul_comm]
end Measurement
end QuantumComputing