-
Notifications
You must be signed in to change notification settings - Fork 4
/
quantum_lemmas.lean
1610 lines (1354 loc) · 47.2 KB
/
quantum_lemmas.lean
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import quantum
import matrix_lemmas
open_locale big_operators
open matrix
open Matrix
open quantum
------------------------------------------------------------------------------
section measurement
variables {n : ℕ} {s : Vector n}
lemma measure_eq_mul_conj {m : fin n}
: (measure s m : ℂ) = ((s m 0)†) * (s m 0)
:= begin
unfold quantum.measure,
rw <- complex.mul_conj, ring,
end
lemma measure_eq_proj {m : fin n} : (measure s m : ℂ) = proj s m m
:= begin
unfold quantum.measure proj,
unfold matrix.mul matrix.dot_product,
unfold adjoint,
rw finset.sum_fin_eq_sum_range,
rw finset.sum_range_one,
repeat { rw dif_pos }; simp,
end
lemma measure_eq_of_proj_eq {a b : Vector n} :
proj a = proj b
→ measure a = measure b
:= begin
intros h,
rw <- matrix.ext_iff at h,
apply funext, intros i,
have g: (measure a i : ℂ) = measure b i, {
iterate 2 {rw measure_eq_proj},
apply h,
},
apply_mod_cast g,
end
lemma nonzero_vector_has_nonzero_measure
: s ≠ 0 → (∃ i, measure s i ≠ 0)
:= begin
contrapose!,
intros h,
apply matrix.ext, intros i j,
have j0: j = 0, by {simp},
cases j0, clear j0, simp,
rw <- complex.norm_sq_eq_zero,
apply h,
end
end measurement
------------------------------------------------------------------------------
-- proj lemmas
section proj
variables {n : ℕ} {s t : Vector n}
-- `proj s` is self-adjoint (aka "Hermitian").
@[simp]
lemma proj_self_adjoint (s : Vector n) : ((proj s)†) = proj s
:= begin
unfold proj,
rw adjoint_mul, simp,
end
lemma proj_mul_adjoint_eq_self {n} {u : Vector n} : u.unit → (proj u)† ⬝ (proj u) = proj u
:= begin
unfold proj, intros h,
rw adjoint_mul, simp,
rw matrix.mul_assoc, congr' 1,
rw <- matrix.mul_assoc,
rw unfold_unit h, simp,
end
lemma outer_product_diagnonal_apply {i : fin n}
: (s ⬝ t†) i i = (s i 0) * (t i 0).conj
:= begin
unfold matrix.mul adjoint matrix.dot_product,
rw finset.sum_fin_eq_sum_range,
rw finset.sum_eq_single 0,
rw dif_pos; simp,
simp,
simp,
end
lemma outer_product_self_diagnonal_apply_eq_norm_sq {i : fin n}
: (s ⬝ s†) i i = (s i 0).norm_sq
:= begin
rw outer_product_diagnonal_apply, simp,
end
lemma proj_diagnonal_eq_mul_conj {i : fin n} : s.proj i i = (s i 0)† * s i 0
:= begin
unfold proj,
rw outer_product_diagnonal_apply,
ring,
end
lemma proj_diagnonal_eq_norm_sq {i : fin n} : s.proj i i = (s i 0).norm_sq
:= begin
rw proj_diagnonal_eq_mul_conj, simp,
end
end proj
section proj_kron
variables {n : ℕ} {s : Vector n}
variables {m : ℕ} {t : Vector m}
lemma proj_kron : proj (s ⊗ t) = proj s ⊗ proj t
:= begin
unfold proj,
rw adjoint_kron,
rw kron_mixed_prod,
end
lemma proj_kron_apply {i : fin n} {j : fin m}
: proj (s ⊗ t) (kron_loc i j) (kron_loc i j)
= proj s i i * proj t j j
:= begin
rw proj_kron,
cases i with i ip,
cases j with j jp,
unfold kron kron_div kron_mod,
have f1: (m * i + j) / m = i, {
rw add_comm,
rw nat.add_mul_div_left,
rw nat.div_eq_zero jp, simp, linarith,
},
have f2: (m * i + j) % m = j, {
rw add_comm,
rw nat.add_mul_mod_self_left,
rw nat.mod_eq_of_lt jp,
},
congr' 1, {
congr; simp; assumption,
}, {
congr; simp; assumption,
}
end
end proj_kron
------------------------------------------------------------------------------
-- proj + std_basis lemmas
section proj_std_basis
variables {n : ℕ} {m : fin n}
lemma proj_std_basis_eq_diagonal
: proj (std_basis m) = matrix.diagonal (λ i, if i = m then 1 else 0)
:= begin
unfold proj matrix.mul,
unfold Matrix.adjoint,
apply matrix.ext, intros i j,
simp,
unfold matrix.dot_product,
simp,
by_cases h: i = j, {
cases h,
simp,
by_cases h2: i = m, {
cases h2,
simp,
}, {
rw if_neg; try {assumption},
rw std_basis_eq_zero h2,
simp,
}
}, {
unfold matrix.diagonal,
rw if_neg h,
by_cases h2: i = m, {
have f1: ¬ j = m, by cc,
rw std_basis_eq_zero f1, simp,
}, {
have f1: ¬ i = m, by cc,
rw std_basis_eq_zero f1, simp,
}
}
end
@[simp]
lemma proj_std_basis_eq_one : proj (std_basis m) m m = 1
:= begin
rw proj_std_basis_eq_diagonal,
unfold matrix.diagonal, simp,
end
lemma proj_std_basis_eq_zero1 {i j : fin n} : ¬ i = m → proj (std_basis m) i j = 0
:= begin
rw proj_std_basis_eq_diagonal,
unfold matrix.diagonal, intros e,
rw if_neg e, simp,
end
lemma proj_std_basis_eq_zero2 {i j : fin n} : ¬ j = m → proj (std_basis m) i j = 0
:= begin
rw proj_std_basis_eq_diagonal,
unfold matrix.diagonal, intros e,
by_cases h : i = j, {
cases h, simp, cc,
}, {
rw if_neg h,
}
end
lemma mul_proj_std_basis_left {n} {m : fin n} {U : Square n}
: proj (std_basis m) ⬝ U = λ i j, ite (i = m) (U i j) 0
:= begin
apply matrix.ext, intros i j,
rw proj_std_basis_eq_diagonal,
rw matrix.diagonal_mul,
by_cases h: i = m, {
cases h, clear h, simp,
}, {
iterate 2 { rw if_neg h }, simp,
}
end
lemma mul_proj_std_basis_right {n} {m : fin n} {U : Square n}
: U ⬝ proj (std_basis m) = λ i j, ite (j = m) (U i j) 0
:= begin
apply matrix.ext, intros i j,
rw proj_std_basis_eq_diagonal,
rw matrix.mul_diagonal,
by_cases h: j = m, {
cases h, clear h, simp,
}, {
iterate 2 { rw if_neg h }, simp,
}
end
lemma kron_proj_std_basis {m : fin 2} {U : Square 2}
: proj (std_basis m) ⊗ U = λ i j, ite (kron_div i = m ∧ kron_div j = m) (U (kron_mod i) (kron_mod j)) 0
:= begin
apply kron_ext_mul, intros r s v w, simp,
by_cases h1: r = m, {
cases h1, clear h1, simp,
by_cases h2: s = m, {
cases h2, clear h2, simp,
}, {
rw proj_std_basis_eq_zero2 h2,
rw if_neg h2, simp,
}
}, {
rw proj_std_basis_eq_zero1 h1,
have : ¬ (r = m ∧ s = m), by cc,
rw if_neg this, simp,
}
end
end proj_std_basis
------------------------------------------------------------------------------
-- trace lemmas
section trace
variables {n : ℕ} (v w : Square n)
theorem trace_smul (s : ℂ) : Tr(s • v) = s * Tr(v)
:= begin
unfold Matrix.trace,
simp,
rw finset.mul_sum,
end
lemma trace_adjoint : Tr((v†)) = Tr(v)†
:= begin
unfold Matrix.trace,
unfold adjoint,
rw complex.conj_sum_dist,
end
lemma abs_trace_adjoint : |Tr(v†)| = |Tr(v)|
:= begin
unfold Matrix.trace,
unfold adjoint,
rw complex.conj_sum_dist,
rw is_R_or_C.abs_conj,
end
lemma trace_mul_comm : Tr(v ⬝ w) = Tr(w ⬝ v)
:= begin
unfold Matrix.trace,
unfold matrix.mul matrix.dot_product,
rw finset.sum_comm,
congr, apply funext, intros i,
congr, apply funext, intros j,
ring,
end
-- for easier match
lemma fin_sum_sum_mul (f : fin n → fin n → ℂ) (g : fin n → ℂ)
: (∑ (i : fin n), ((∑ (j : fin n), f i j) * (g i)))
= (∑ (i : fin n) (j : fin n), f i j * g i)
:= begin
congr, apply funext, intros i,
rw finset.sum_mul,
end
variables {m : ℕ}
lemma trace_mul_rotate_l (a : Matrix m n) (b : Matrix n m)
: Tr(a ⬝ v ⬝ b) = Tr(v ⬝ b ⬝ a)
:= begin
unfold Matrix.trace,
unfold matrix.mul matrix.dot_product,
symmetry,
rw finset.sum_comm,
congr, apply funext, intros k,
iterate 2 { rw fin_sum_sum_mul },
rw finset.sum_comm,
congr, apply funext, intros i,
congr, apply funext, intros j,
ring,
end
theorem trace_kron {x : Square m}: Tr(v ⊗ x) = Tr(v) * Tr(x)
:= begin
unfold Matrix.trace kron,
rw kron_sum_mul_mul,
end
end trace
section trace_proj
variables {n : ℕ} (s t : Vector n)
theorem trace_outer_eq_inner : Tr(s ⬝ (t†)) = (t† ⬝ s) 0 0
:= begin
unfold Matrix.trace,
unfold matrix.mul,
unfold matrix.dot_product,
congr' 1, apply funext, intro x,
rw finset.sum_fin_eq_sum_range,
rw finset.sum_range_one,
rw dif_pos; try { solve1 {simp} },
simp,
ring,
end
lemma trace_outer_eq_trace_inner : Tr(s ⬝ (t†)) = Tr((t†) ⬝ s)
:= begin
rw trace_outer_eq_inner,
unfold Matrix.trace,
rw finset.sum_fin_eq_sum_range,
rw finset.sum_eq_single 0; simp,
end
theorem trace_proj : Tr(proj s) = ((s†) ⬝ s) 0 0
:= begin
unfold proj,
rw trace_outer_eq_inner,
end
lemma trace_proj_eq_one_of_unit {s : Vector n} : s.unit → Tr(proj s) = 1
:= begin
intros h,
rw trace_proj,
rw unfold_unit h, simp,
end
lemma trace_proj_eq_one_of_unit' {s : Vector n} : s.unit → Tr(s ⬝ (s†)) = 1
:= begin
intros h,
rw trace_outer_eq_inner,
rw unfold_unit h, simp,
end
lemma unit_of_trace_proj_eq_one : Tr(proj s) = 1 → s.unit
:= begin
rw trace_proj,
intros h,
unfold matrix.unit,
apply matrix.ext, intros i j,
have i0 : i = 0, {
cases i, simp,
},
have j0 : j = 0, {
cases j, simp,
},
cases i0,
cases j0,
simp, assumption,
end
lemma trace_proj_inner_prod : Tr(proj (s† ⬝ t)) = Tr(proj s ⬝ proj t)
:= begin
unfold proj,
rw adjoint_mul, simp,
rw <- matrix.mul_assoc,
rw matrix.mul_assoc (s†),
rw trace_mul_rotate_l,
rw matrix.mul_assoc,
rw _root_.trace_mul_comm,
end
lemma conj_trace_outer_product : Tr(s ⬝ t†)† = Tr(s† ⬝ t)
:= begin
have f1: (t ⬝ s†)† = (s ⬝ t†), {
rw adjoint_mul, simp,
},
rw <- f1,
rw trace_adjoint, simp,
apply trace_outer_eq_trace_inner,
end
end trace_proj
------------------------------------------------------------------------------
-- partial_trace lemmas
section partial_trace_add
variables {n m : ℕ} {x y : Square n * m}
lemma partial_trace_add : partial_trace (x + y) = partial_trace x + partial_trace y
:= begin
unfold partial_trace Matrix.trace,
apply funext, intros k,
apply funext, intros i,
simp,
rw finset.sum_add_distrib,
end
end partial_trace_add
section partial_trace_kron
variables {n m : ℕ} (v : Square n) (w : Square m)
lemma partial_trace_kron : partial_trace (v ⊗ w) = Tr(w) • v
:= begin
unfold partial_trace Matrix.trace,
apply funext, intros k,
apply funext, intros i,
simp,
rw finset.sum_mul,
congr' 1, apply funext, intros j,
rw mul_comm,
rw mul_to_kron,
end
@[simp]
theorem trace_partial_trace {v : Square n*m} : Tr(partial_trace v) = Tr(v)
:= begin
unfold Matrix.trace partial_trace,
rw <- finset.sum_preimage (λ x : fin n × fin m, (kron_loc x.fst x.snd : fin (n * m))), {
rw <- finset.sum_product',
simp,
}, {
simp,
unfold set.inj_on,
intros,
rw prod.eq_iff_fst_eq_snd_eq,
apply kron_loc_inj; assumption,
}, {
intros x _ h2,
exfalso,
apply h2, clear h2,
use (⟨kron_div x, kron_mod x⟩),
simp,
}
end
lemma partial_trace_kron_eq {o} (x : Square o): Tr(v) = Tr(w)
→ partial_trace (x ⊗ v) = partial_trace (x ⊗ w)
:= begin
intros t,
iterate 2 { rw partial_trace_kron },
rw t,
end
lemma partial_trace_kron_neq {o} (x y : Square o): Tr(v) = Tr(w)
→ partial_trace (x ⊗ v) ≠ partial_trace (y ⊗ w)
→ x ≠ y
:= begin
intros t h c, apply h, clear h,
cases c, apply partial_trace_kron_eq, assumption,
end
end partial_trace_kron
section partial_trace_proj
variables {n : ℕ} {s t : Vector n}
variables {m : ℕ} {a b : Vector m}
lemma partial_proj_eq_of_kron_eq :
a ⊗ s = b ⊗ t
→ Tr(proj s) = 1 → Tr(proj t) = 1
→ proj a = proj b
:= begin
intros h vt wt,
have f1: partial_trace (proj (a ⊗ s)) = partial_trace (proj (b ⊗ t)), {
rw h,
},
iterate 2 { rw proj_kron at f1 },
iterate 2 { rw partial_trace_kron at f1 },
rw vt at f1,
rw wt at f1,
simp at f1, assumption,
end
lemma partial_proj_eq_of_kron_eq' :
a ⊗ s = b ⊗ t
→ s.unit → t.unit
→ proj a = proj b
:= begin
intros h su tu,
apply partial_proj_eq_of_kron_eq; try {assumption},
rw trace_proj, rw unfold_unit su, simp,
rw trace_proj, rw unfold_unit tu, simp,
end
end partial_trace_proj
section partial_trace_add_kron
variables {n : ℕ} (v w x y : Square n)
variables {m : ℕ} (a b c d : Square m)
lemma partial_trace_add_kron : partial_trace (a ⊗ v + b ⊗ w) = Tr(v) • a + Tr(w) • b
:= begin
unfold partial_trace Matrix.trace,
apply funext, intros k,
apply funext, intros i,
simp,
rw finset.sum_add_distrib,
rw finset.sum_mul,
rw finset.sum_mul,
congr' 1, {
congr' 1, apply funext, intros j,
rw mul_comm (v j j),
rw mul_to_kron,
}, {
congr' 1, apply funext, intros j,
rw mul_comm (w j j),
rw mul_to_kron,
}
end
lemma partial_trace_add_kron2 : partial_trace (a ⊗ v + b ⊗ w + c ⊗ x + d ⊗ y)
= Tr(v) • a + Tr(w) • b + Tr(x) • c + Tr(y) • d
:= begin
unfold partial_trace Matrix.trace,
apply funext, intros k,
apply funext, intros i,
simp,
repeat { rw finset.sum_add_distrib },
repeat { rw finset.sum_mul },
congr' 1, {
congr' 1, {
congr' 1, {
congr' 1, apply funext, intros j,
rw mul_comm (v j j),
rw mul_to_kron,
}, {
congr' 1, apply funext, intros j,
rw mul_comm (w j j),
rw mul_to_kron,
}
}, {
congr' 1, apply funext, intros j,
rw mul_comm (x j j),
rw mul_to_kron,
}
}, {
congr' 1, apply funext, intros j,
rw mul_comm (y j j),
rw mul_to_kron,
}
end
end partial_trace_add_kron
section partial_trace_proj_add_kron
variables {n: ℕ} (s t p: Vector n)
variables {m: ℕ} (v w q: Vector m)
lemma proj_add_kron : proj ((t ⊗ w) + (p ⊗ q))
= t ⬝ (t†) ⊗ (w ⬝ (w†)) + t ⬝ (p†) ⊗ (w ⬝ (q†)) + p ⬝ (t†) ⊗ (q ⬝ (w†)) + p ⬝ (p†) ⊗ (q ⬝ (q†))
:= begin
unfold proj, repeat { rw adjoint_add <|> rw adjoint_kron },
repeat { rw matrix.add_mul <|> rw matrix.mul_add },
repeat { rw kron_mixed_prod },
rw <- add_assoc,
end
lemma partial_trace_proj_add_kron : w.unit → q.unit → (w†) ⬝ q = 1
→ partial_trace (proj ((t ⊗ w) + (p ⊗ q))) = proj (t + p)
:= begin
intros wu qu h,
rw proj_add_kron,
rw partial_trace_add_kron2,
rw trace_proj_eq_one_of_unit' wu,
rw trace_proj_eq_one_of_unit' qu,
have f1: Tr(q ⬝ (w†)) = 1, {
rw trace_outer_eq_inner, rw h, simp,
},
have f2: Tr(w ⬝ (q†)) = 1, {
have h': (q†) ⬝ w = 1, {
apply adjoint_inj, rw adjoint_mul, simp *,
},
rw trace_outer_eq_inner, rw h', simp,
},
rw f1, rw f2, simp,
unfold proj, rw adjoint_add,
repeat { rw matrix.add_mul <|> rw matrix.mul_add },
abel,
end
lemma partial_trace_proj_add_kron2 : w.unit → q.unit → (w†) ⬝ q = 0
→ partial_trace (proj ((t ⊗ w) + (p ⊗ q))) = proj t + proj p
:= begin
intros wu qu h,
rw proj_add_kron,
rw partial_trace_add_kron2,
rw trace_proj_eq_one_of_unit' wu,
rw trace_proj_eq_one_of_unit' qu,
have f1: Tr(q ⬝ (w†)) = 0, {
rw trace_outer_eq_inner, rw h, simp,
},
have f2: Tr(w ⬝ (q†)) = 0, {
have h': (q†) ⬝ w = 0, {
apply adjoint_inj, rw adjoint_mul, simp *,
},
rw trace_outer_eq_inner, rw h', simp,
},
rw f1, rw f2, unfold proj, simp,
end
end partial_trace_proj_add_kron
------------------------------------------------------------------------------
-- state_after_measure lemmas
section state_after_measure_lemmas
variables {n : ℕ} {s : Vector n} {m : fin n}
lemma state_after_measure_eq_zero {i : fin n}
: ¬ i = m → (state_after_measure s m) i 0 = 0
:= begin
unfold quantum.measure state_after_measure,
intros h,
rw Matrix.real_smul_apply,
rw matrix.mul_apply,
rw finset.sum_eq_zero; try {solve1 {simp}},
intros x xh,
rw proj_std_basis_eq_zero1; simp [*],
end
lemma abs_state_after_measure_eq_one {i : fin n}
: ⟦s⟧ m ≠ 0 → i = m → |state_after_measure s m i 0| = 1
:= begin
intros sp h, cases h, clear h,
unfold quantum.measure state_after_measure,
rw Matrix.real_smul_apply,
rw matrix.mul_apply,
rw finset.sum_eq_single m, {
simp, ring,
rw <- is_R_or_C.norm_sq_to_complex,
rw is_R_or_C.sqrt_norm_sq_eq_norm,
simp,
rw mul_inv_cancel, {
intro c,
apply sp, clear sp,
unfold quantum.measure,
rw complex.norm_sq_eq_abs,
rw c, simp,
}
}, {
intros x xp xh,
rw proj_std_basis_eq_zero2; simp [*],
}, {
simp,
}
end
lemma measure_state_after_measure_eq_one {i : fin n}
: ⟦s⟧ m ≠ 0 → i = m → measure (state_after_measure s m) i = 1
:= begin
intros sp h, cases h, clear h,
unfold quantum.measure state_after_measure,
rw Matrix.real_smul_apply,
rw matrix.mul_apply,
rw finset.sum_eq_single m, {
simp, rw mul_comm,
rw mul_inv_cancel, {
intro c,
apply sp, clear sp,
apply c,
}
}, {
intros x xp xh,
rw proj_std_basis_eq_zero2; simp [*],
}, {
simp,
}
end
lemma measure_state_after_measure_eq_measure_std_basis
: ⟦s⟧ m ≠ 0 → measure (state_after_measure s m) = measure (std_basis m)
:= begin
intros h,
ext1 i,
by_cases c: i = m, {
cases c, clear c,
rw measure_state_after_measure_eq_one h rfl,
unfold quantum.measure, simp,
}, {
unfold quantum.measure,
rw state_after_measure_eq_zero c,
rw std_basis_eq_zero c,
},
end
end state_after_measure_lemmas
------------------------------------------------------------------------------
-- partial measure lemmas
section partial_measure
variables {n : ℕ} {a b : Vector n}
variables {m : ℕ} {s t : Vector m}
lemma measure_eq_of_kron_eq :
a ⊗ s = b ⊗ t
→ Tr(proj s) = 1 → Tr(proj t) = 1
→ measure a = measure b
:= begin
intros h su tu,
apply measure_eq_of_proj_eq,
apply partial_proj_eq_of_kron_eq h; assumption,
end
-- not true
-- example: a ⊗ (s + t) = b ⊗ (v + w)
-- → Tr(proj (s + t)) = 1 → Tr(proj (v + w)) = 1
-- → proj a = proj b
lemma partial_measure_proj_kron
: Tr(proj s) = 1
→ partial_measure (a ⊗ s) = measure a
:= begin
intros vu,
apply funext, intros i,
unfold partial_measure quantum.measure,
rw proj_kron,
rw partial_trace_kron,
rw vu, simp,
rw proj_diagnonal_eq_norm_sq, simp,
end
lemma partial_measure_eq_of_kron_eq :
a ⊗ s = b ⊗ t
→ Tr(proj s) = 1 → Tr(proj t) = 1
→ measure a = measure b
:= begin
intros h stu vwu,
have f1: partial_measure (a ⊗ s) = partial_measure (b ⊗ t), {
rw h,
},
rw partial_measure_proj_kron stu at f1,
rw partial_measure_proj_kron vwu at f1,
assumption,
end
lemma unit_has_nonzero_measure
: s.unit → (∃ i, measure s i ≠ 0)
:= begin
intros h,
apply nonzero_vector_has_nonzero_measure,
apply unit_nonzero, assumption,
end
lemma measure_kron_apply {i : fin n} {j : fin m}
: measure (a ⊗ s) (kron_loc i j)
= measure a i * measure s j
:= begin
have goal: (measure (a ⊗ s) (kron_loc i j) : ℂ)
= measure a i * measure s j, {
repeat { rw measure_eq_proj },
apply proj_kron_apply,
},
apply_mod_cast goal,
end
lemma measure_kron_cancel_right:
measure (a ⊗ s) = measure (b ⊗ s)
→ s.unit
→ measure a = measure b
:= begin
intros h su,
apply funext, intro i,
rw function.funext_iff at h,
rcases (unit_has_nonzero_measure su) with ⟨j, jp⟩,
specialize (h (kron_loc i j)),
iterate 2 {rw measure_kron_apply at h},
apply mul_right_cancel' _ h; assumption,
end
lemma measure_kron_cancel_left:
measure (s ⊗ a) = measure (s ⊗ b)
→ s.unit
→ measure a = measure b
:= begin
intros h su,
apply funext, intro i,
rw function.funext_iff at h,
rcases (unit_has_nonzero_measure su) with ⟨j, jp⟩,
specialize (h (kron_loc j i)),
iterate 2 {rw measure_kron_apply at h},
apply mul_left_cancel' _ h; assumption,
end
end partial_measure
------------------------------------------------------------------------------
-- partial_measure_add_kron
section partial_measure_add_kron
variables {n : ℕ} {a b : Vector n}
variables {m : ℕ} {s t : Vector m}
lemma partial_measure_add_kron_rhs {a b k : ℂ}
: ((a + b).norm_sq : ℂ) - (2 * ((1 - k) * (a * b†)).re : ℝ)
= (a.norm_sq + b.norm_sq : ℂ) + (2 * (k * (a * b.conj)).re : ℝ)
:= begin
have l1: ((a + b).norm_sq : ℂ)
= (a.norm_sq + b.norm_sq)
+ (2 * (a * b.conj).re : ℝ), {
rw <- complex.conj_mul' (a + b),
repeat { rw complex.conj.map_add },
repeat { rw add_mul },
repeat { rw mul_add },
have l1_1: a * b.conj + b * a.conj
= (2 * (a * b.conj).re : ℝ), {
rw <- complex.add_conj,
congr, simp, ring,
},
rw <- l1_1, clear l1_1,
simp, ring,
},
rw l1, clear l1,
rw add_sub_assoc (a.norm_sq + b.norm_sq : ℂ),
congr' 1,
repeat { rw sub_mul },
repeat { rw two_mul },
rw complex.sub_re,
rw is_R_or_C.conj_to_complex,
norm_cast, ring,
rw <- sub_sub,
rw <- sub_add,
rw <- sub_add,
repeat { rw <- mul_assoc },
ring,
end
lemma partial_measure_add_kron : Tr(proj s) = 1 → Tr(proj t) = 1
→ ⦃ a ⊗ s + b ⊗ t ⦄
= λ i, |(a i 0 + b i 0).norm_sq
- 2 * ((1 - Tr(s ⬝ t†)) * (a i 0 * (b i 0)†)).re|
:= begin
intros su tu,
ext i,
have lhs: ⦃a ⊗ s + b ⊗ t⦄ i
= |((a ⬝ a†) i i + (b ⬝ b†) i i) + (Tr(s ⬝ t†) • ((a ⬝ b†) i i) + Tr(t ⬝ s†) • ((b ⬝ a†) i i))|,
{
unfold partial_measure,
rw proj_add_kron,
repeat { rw partial_trace_add },
repeat { rw partial_trace_kron },
unfold proj at su,
unfold proj at tu,
rw su, rw tu,
simp,
congr' 1,
ring,
},
rw lhs, clear lhs,
iterate 2 { rw outer_product_self_diagnonal_apply_eq_norm_sq },
iterate 2 { rw outer_product_diagnonal_apply },
have rhs: (((a i 0 + b i 0).norm_sq - 2 * ((1 - Tr(s ⬝ t†)) * (a i 0 * (b i 0)†)).re : ℝ) : ℂ)
= ((a i 0).norm_sq + (b i 0).norm_sq : ℂ)
+ (2 * (Tr(s ⬝ t†) * (a i 0 * (b i 0).conj)).re : ℝ), {
apply_mod_cast partial_measure_add_kron_rhs,
},
rw complex.abs_of_real',
rw rhs,
congr' 1,
congr' 1,
have f1: Tr(s ⬝ t†) * (a i 0 * (b i 0).conj) + Tr(t ⬝ s†) * (b i 0 * (a i 0).conj)
= (2 * (Tr(s ⬝ t†) * (a i 0 * (b i 0).conj)).re : ℝ), {
rw <- complex.add_conj,
simp,
congr' 1, {
rw <- adjoint_involutive t,
rw <- adjoint_mul,
rw trace_adjoint,
simp,
}, {
ring,
}
},
apply f1,
end
lemma partial_measure_add_kron' : Tr(proj s) = 1 → Tr(proj t) = 1
→ ⦃ a ⊗ s + b ⊗ t ⦄
= λ i, |(a i 0 + b i 0).norm_sq
- 2 * ((1 - Tr(s† ⬝ t)) * ((a i 0)† * b i 0)).re|
:= begin
intros su tu,
rw partial_measure_add_kron su tu,
ext i,
have f1: ((1 - Tr(s ⬝ t†)) * (a i 0 * (b i 0)†)).re
= ((1 - Tr(s† ⬝ t)) * ((a i 0)† * b i 0)).re, {
rw <- complex.re_conj_eq_re,
congr' 1,
simp,
left,
rw <- is_R_or_C.conj_to_complex,
rw conj_trace_outer_product,
},
rw f1,
end
lemma partial_measure_add_kron_of_orthogonal : Tr(proj s) = 1 → Tr(proj t) = 1
→ (∀ i, (a i 0)† * b i 0 = 0)
→ ⦃ a ⊗ s + b ⊗ t ⦄ = ⟦ a + b ⟧
:= begin
intros su tu h,
rw partial_measure_add_kron' su tu,
ext i,
rw h, simp,
unfold quantum.measure,
apply _root_.abs_of_nonneg, simp,
end
end partial_measure_add_kron
------------------------------------------------------------------------------
-- std_basis lemmas for proof automation
meta def solve_std_basis_zero := `[rw std_basis_eq_zero, dec_trivial]
@[simp] lemma std_basis_0_2_1 : (std_basis 0 : Vector 2) 1 0 = 0 := by solve_std_basis_zero
@[simp] lemma std_basis_1_2_0 : (std_basis 1 : Vector 2) 0 0 = 0 := by solve_std_basis_zero
@[simp] lemma std_basis_0_4_1 : (std_basis 0 : Vector 4) 1 0 = 0 := by solve_std_basis_zero
@[simp] lemma std_basis_0_4_2 : (std_basis 0 : Vector 4) 2 0 = 0 := by solve_std_basis_zero
@[simp] lemma std_basis_0_4_3 : (std_basis 0 : Vector 4) 3 0 = 0 := by solve_std_basis_zero
@[simp] lemma std_basis_1_4_0 : (std_basis 1 : Vector 4) 0 0 = 0 := by solve_std_basis_zero
@[simp] lemma std_basis_1_4_2 : (std_basis 1 : Vector 4) 2 0 = 0 := by solve_std_basis_zero
@[simp] lemma std_basis_1_4_3 : (std_basis 1 : Vector 4) 3 0 = 0 := by solve_std_basis_zero