-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSeparability.v
4659 lines (4387 loc) · 199 KB
/
Separability.v
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
Require Import QuantumLib.Eigenvectors.
Require Export QuantumLib.Permutations.
Require Import QuantumLib.VectorStates.
Require Import HeisenbergFoundations.F2Math.
Require Export HeisenbergFoundations.Normalization.
Local Open Scope F2_scope.
(* Check Matrix *)
(** *** Check Matrix *** **)
Definition toCheckMatrixF2ElementLeftX (a : Pauli) : F2 :=
match a with
| gI => zero
| gX => one
| gY => one
| gZ => zero
end.
Definition toCheckMatrixF2ElementRightZ (a : Pauli) : F2 :=
match a with
| gI => zero
| gX => zero
| gY => one
| gZ => one
end.
Definition toCheckMatrixF2Left (row col : nat) (LLp : list (list Pauli)) : MatrixF2 row col :=
(fun r c : nat => toCheckMatrixF2ElementLeftX (nth c (nth r LLp (repeat gI col)) gI)).
Definition toCheckMatrixF2Right (row col : nat) (LLp : list (list Pauli)) : MatrixF2 row col :=
(fun r c : nat => toCheckMatrixF2ElementRightZ (nth c (nth r LLp (repeat gI col)) gI)).
Lemma WF_toCheckMatrixF2Left : forall (row col : nat) (LLp : list (list Pauli)),
(length LLp <= row)%nat -> Forall (fun Lp : list Pauli => (length Lp <= col)%nat) LLp ->
WF_MatrixF2 (toCheckMatrixF2Left row col LLp).
Proof. intros row col LLp H H0.
unfold WF_MatrixF2, toCheckMatrixF2Left, toCheckMatrixF2ElementLeftX.
intros x y H1.
destruct H1.
- rewrite nth_overflow with (d := (repeat gI col)); try lia.
rewrite nth_repeat. auto.
- bdestruct (x <? length LLp)%nat.
+ rewrite nth_overflow with (d := gI); auto.
rewrite Forall_nth in H0.
specialize (H0 x (repeat gI col) H2). lia.
+ rewrite nth_overflow with (d := (repeat gI col)); try lia.
rewrite nth_repeat. auto.
Qed.
Lemma toCheckMatrixF2Left_nil : forall (r c : nat),
toCheckMatrixF2Left r c [] = ZeroF2.
Proof. intros r c.
unfold toCheckMatrixF2Left, ZeroF2.
prep_matrix_equality.
unfold toCheckMatrixF2ElementLeftX.
simpl; destruct x; rewrite nth_repeat; auto.
Qed.
Lemma WF_toCheckMatrixF2Right : forall (row col : nat) (LLp : list (list Pauli)),
(length LLp <= row)%nat -> Forall (fun Lp : list Pauli => (length Lp <= col)%nat) LLp ->
WF_MatrixF2 (toCheckMatrixF2Right row col LLp).
Proof. intros row col LLp H H0.
unfold WF_MatrixF2, toCheckMatrixF2Right, toCheckMatrixF2ElementRightZ.
intros x y H1.
destruct H1.
- rewrite nth_overflow with (d := (repeat gI col)); try lia.
rewrite nth_repeat. auto.
- bdestruct (x <? length LLp)%nat.
+ rewrite nth_overflow with (d := gI); auto.
rewrite Forall_nth in H0.
specialize (H0 x (repeat gI col) H2). lia.
+ rewrite nth_overflow with (d := (repeat gI col)); try lia.
rewrite nth_repeat. auto.
Qed.
Lemma toCheckMatrixF2Right_nil : forall (r c : nat),
toCheckMatrixF2Right r c [] = ZeroF2.
Proof. intros r c.
unfold toCheckMatrixF2Right, ZeroF2.
prep_matrix_equality.
unfold toCheckMatrixF2ElementRightZ.
simpl; destruct x; rewrite nth_repeat; auto.
Qed.
Definition fromLLpToCheckMatrixF2 (row col : nat) (LLp : list (list Pauli)) : MatrixF2 row (col + col)%nat :=
F2Module.smash (toCheckMatrixF2Left row col LLp) (toCheckMatrixF2Right row col LLp).
Lemma WF_fromLLpToCheckMatrixF2 : forall (row col : nat) (LLp : list (list Pauli)),
(length LLp <= row)%nat -> Forall (fun Lp : list Pauli => (length Lp <= col)%nat) LLp ->
WF_MatrixF2 (fromLLpToCheckMatrixF2 row col LLp).
Proof. intros row col LLp H H0.
apply F2Module.WF_smash.
apply WF_toCheckMatrixF2Left; auto.
apply WF_toCheckMatrixF2Right; auto.
Qed.
Lemma fromLLpToCheckMatrixF2_nil : forall (r c : nat),
fromLLpToCheckMatrixF2 r c [] = ZeroF2.
Proof. intros r c.
unfold fromLLpToCheckMatrixF2.
rewrite toCheckMatrixF2Left_nil, toCheckMatrixF2Right_nil.
unfold F2Module.smash, ZeroF2.
prep_matrix_equality.
bdestruct_all; auto.
Qed.
Definition elemToVecF2 (z : F2) : VectorF2 1%nat :=
(fun r c : nat => if (r =? 0)%nat && (c =? 0)%nat then z else zero).
Lemma elemToVecF2_zero : elemToVecF2 0 = ZeroF2.
Proof. unfold elemToVecF2, ZeroF2. prep_matrix_equality. bdestruct_all; auto. Qed.
Lemma elemToVecF2_one00 : elemToVecF2 1%F2 0%nat 0%nat = 1.
Proof. unfold elemToVecF2, ZeroF2. bdestruct_all; auto. Qed.
Lemma elemToVec_innerproduct : forall (z1 z2 : F2),
elemToVecF2 z1 × transposeF2 (elemToVecF2 z2) = elemToVecF2 (z1 · z2).
Proof. intros z1 z2.
unfold elemToVecF2, transposeF2, MmultF2.
prep_matrix_equality.
bdestruct_all; simpl; auto.
- destruct (z1 · z2); auto.
- destruct z1; auto.
- destruct z2; auto.
Qed.
Lemma toCheckMatrixF2Left_cons : forall (Lp : list Pauli) (p : Pauli),
toCheckMatrixF2Left 1%nat (S (length Lp)) [p :: Lp] =
F2Module.smash (elemToVecF2 (toCheckMatrixF2ElementLeftX p)) (toCheckMatrixF2Left 1%nat (length Lp) [Lp]).
Proof. intros Lp p.
unfold toCheckMatrixF2Left, F2Module.smash, elemToVecF2.
prep_matrix_equality.
bdestruct_all; subst; simpl; auto.
- destruct x; simpl; try lia.
destruct x; simpl; auto.
- destruct x; subst; simpl.
+ destruct y; subst; simpl; try lia.
repeat f_equal; try lia.
+ destruct x; subst; simpl.
* destruct y; subst; simpl; try lia.
repeat f_equal; try lia.
* destruct y; subst; simpl; try lia.
repeat f_equal; try lia.
Qed.
Lemma toCheckMatrixF2Right_cons : forall (Lp : list Pauli) (p : Pauli),
toCheckMatrixF2Right 1%nat (S (length Lp)) [p :: Lp] =
F2Module.smash (elemToVecF2 (toCheckMatrixF2ElementRightZ p)) (toCheckMatrixF2Right 1%nat (length Lp) [Lp]).
Proof. intros Lp p.
unfold toCheckMatrixF2Right, F2Module.smash, elemToVecF2.
prep_matrix_equality.
bdestruct_all; subst; simpl; auto.
- destruct x; simpl; try lia.
destruct x; simpl; auto.
- destruct x; subst; simpl.
+ destruct y; subst; simpl; try lia.
repeat f_equal; try lia.
+ destruct x; subst; simpl.
* destruct y; subst; simpl; try lia.
repeat f_equal; try lia.
* destruct y; subst; simpl; try lia.
repeat f_equal; try lia.
Qed.
(** Λ **)
Definition checkLambdaF2 (n : nat) : MatrixF2 (n + n)%nat (n + n)%nat :=
(fun r c : nat =>
if (r <? (n + n))%nat && (c <? (n + n))%nat && ((c =? r + n)%nat || (r =? c + n)%nat)
then 1 else 0).
Lemma WF_checkLambdaF2 : forall {n : nat},
WF_MatrixF2 (checkLambdaF2 n).
Proof. intros n.
unfold WF_MatrixF2.
intros x y H.
destruct H; unfold checkLambdaF2; bdestruct_all; simpl; auto.
Qed.
Lemma checkLambdaF2_inv : forall (n : nat),
(checkLambdaF2 n) × (checkLambdaF2 n) = IF2 (n + n)%nat.
Proof. intros n.
unfold checkLambdaF2, IF2, MmultF2.
prep_matrix_equality.
bdestruct_all; subst; simpl.
- bdestruct (y <? n).
+ apply big_sum_unique.
exists (y + n)%nat. split; try lia. split.
* bdestruct_all. auto.
* intros x' H2 H3. bdestruct_all. auto.
+ apply big_sum_unique.
exists (y - n)%nat. split; try lia. split.
* bdestruct_all. auto.
* intros x' H2 H3. bdestruct_all. auto.
- rewrite big_sum_0_bounded; auto.
intros x0 H2. bdestruct_all; auto.
- rewrite big_sum_0_bounded; auto.
intros x0 H2. bdestruct_all; auto.
- rewrite big_sum_0_bounded; auto.
intros x0 H2. bdestruct_all; auto.
- rewrite big_sum_0_bounded; auto.
intros x0 H2. bdestruct_all; auto.
- rewrite big_sum_0_bounded; auto.
intros x0 H2. bdestruct_all; auto.
Qed.
Lemma checkLambdaF2_switch_right : forall (n : nat) (a b : MatrixF2 1%nat n),
WF_MatrixF2 a ->
(checkLambdaF2 n) × (F2Module.smash a b)⊤ = (F2Module.smash b a)⊤.
Proof. intros n a b H.
unfold checkLambdaF2, F2Module.smash, transposeF2, MmultF2.
prep_matrix_equality.
bdestruct_all; subst; simpl.
- apply big_sum_unique.
exists (x + n)%nat. split; try lia. split.
+ bdestruct_all. F2simpl. f_equal. lia.
+ intros x' H2 H3. bdestruct_all; rewrite F2mult_0_l; simpl; auto.
- apply big_sum_unique.
exists (x - n)%nat. split; try lia. split.
+ bdestruct_all. rewrite F2mult_1_l. auto.
+ intros x' H2 H3. bdestruct_all; rewrite F2mult_0_l; auto.
- rewrite H; auto; try lia.
rewrite big_sum_0_bounded; auto.
intros x0 H2. destruct (if x0 <? n then a y x0 else b y (x0 - n)%nat); auto.
Qed.
Lemma smash_innerproduct : forall (n m : nat) (a a' : MatrixF2 1%nat n) (b b' : MatrixF2 1%nat m),
F2Module.smash a b × (F2Module.smash a' b')⊤ = a × a'⊤ .+ b × b'⊤.
Proof. intros n m a a' b b'.
unfold F2Module.smash, transposeF2, MmultF2, MplusF2.
prep_matrix_equality.
rewrite big_sum_sum.
simpl.
f_equal.
- apply big_sum_eq_bounded.
intros x0 H.
bdestruct_all.
auto.
- apply big_sum_eq_bounded.
intros x0 H.
bdestruct_all.
replace (n + x0 - n)%nat with x0 by lia.
auto.
Qed.
(* Exercise 10.33: Show that g and g′ commute if and only if r(g)Λr(g′)T = 0. (In the check matrix representation, arithmetic is done modulo two.) *)
Lemma fromLLpToCheckMatrixF2_checkLambdaF2_comm_anticomm : forall (Lp1 Lp2 : list Pauli),
length Lp1 = length Lp2 -> (length Lp1 > 0)%nat ->
(((fromLLpToCheckMatrixF2 1%nat (length Lp1) [Lp1]) × (checkLambdaF2 (length Lp1)) × ((fromLLpToCheckMatrixF2 1%nat (length Lp1) [Lp2]) ⊤)) 0%nat 0%nat = 0 -> commute_listP Lp1 Lp2) /\
(((fromLLpToCheckMatrixF2 1%nat (length Lp1) [Lp1]) × (checkLambdaF2 (length Lp1)) × ((fromLLpToCheckMatrixF2 1%nat (length Lp1) [Lp2]) ⊤)) 0%nat 0%nat = 1 -> anticommute_listP Lp1 Lp2).
Proof. intros Lp1 Lp2 H H0. gen Lp2. induction Lp1; intros. simpl in *; try lia.
destruct Lp2 as [| b Lp2]. inversion H.
simpl in H. apply Nat.succ_inj in H. clear H0.
unfold fromLLpToCheckMatrixF2.
rewrite ! F2Module.GMmult_assoc.
rewrite ! checkLambdaF2_switch_right.
2:{ apply WF_toCheckMatrixF2Left; auto. constructor. simpl; lia. constructor. }
rewrite ! smash_innerproduct.
replace (length (a :: Lp1)) with (S (length Lp1)) by auto.
rewrite ! toCheckMatrixF2Left_cons, ! toCheckMatrixF2Right_cons.
rewrite ! H.
rewrite ! toCheckMatrixF2Left_cons, ! toCheckMatrixF2Right_cons.
replace (S (length Lp2)) with (1 + (length Lp2))%nat by lia.
rewrite ! smash_innerproduct.
rewrite ! elemToVec_innerproduct.
rewrite <- ! H.
destruct Lp1.
clear IHLp1. simpl in *. symmetry in H. rewrite length_zero_iff_nil in H. subst.
unfold toCheckMatrixF2Left, toCheckMatrixF2Right,
toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ,
transposeF2, MmultF2, MplusF2;
destruct a, b; simpl; split; intros H'; constructor; try constructor; auto;
repeat match goal with
| Hyp: 0 = 1 |- _ => symmetry in Hyp
| Hyp: 1 = 0 |- _ => contradict Hyp; apply F2_1_neq_0
end;
match goal with
| Hyp: _ |- _ <> _ => intro H''; try discriminate
end.
destruct Lp2 as [| q Lp2]. inversion H.
assert (length (p :: Lp1) > 0)%nat by (simpl; lia).
specialize (IHLp1 H0 (q :: Lp2) H). clear H0.
unfold fromLLpToCheckMatrixF2 in IHLp1.
rewrite ! F2Module.GMmult_assoc in IHLp1.
rewrite ! checkLambdaF2_switch_right in IHLp1.
2:{ apply WF_toCheckMatrixF2Left; auto. constructor. simpl in *; try lia. constructor. }
rewrite ! smash_innerproduct in IHLp1.
destruct IHLp1.
split; intro H2.
destruct a, b;
try match goal with
| Hyp : _ |- commute_listP (gI :: _) (_) =>
apply commuting_listP_commP_commL; [constructor; auto | apply H0];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
auto
| Hyp : _ |- commute_listP (_) (gI :: _) =>
apply commuting_listP_commP_commL; [constructor; auto | apply H0];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
auto
| Hyp : _ |- commute_listP (gX :: _) (gX :: _) =>
apply commuting_listP_commP_commL; [constructor; auto | apply H0];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
auto
| Hyp : _ |- commute_listP (gY :: _) (gY :: _) =>
apply commuting_listP_commP_commL; [constructor; auto | apply H0];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
auto
| Hyp : _ |- commute_listP (gZ :: _) (gZ :: _) =>
apply commuting_listP_commP_commL; [constructor; auto | apply H0];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
auto
end.
4: { try rewrite ! F2mult_1_l in H2; try rewrite ! F2mult_1_r in H2.
unfold MplusF2 in H2.
rewrite ! elemToVecF2_one00 in H2.
rewrite <- H2.
unfold MplusF2. rewrite ! F2plus_assoc.
setoid_rewrite F2plus_comm at 5. rewrite ! F2plus_assoc.
F2simpl. auto. }
1-6: apply commuting_listP_anticommP_anticommL;
[constructor; intro H''; discriminate | apply H1];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! F2mult_1_l in H2; try rewrite ! F2mult_1_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
unfold MplusF2 in H2; unfold MplusF2;
rewrite ! elemToVecF2_one00 in H2;
try rewrite <- ! F2plus_assoc in H2;
try apply F2plus_flip_l_0 in H2;
try rewrite <- H2; auto.
1-3: try rewrite F2plus_comm in H2 at 1;
try rewrite <- ! F2plus_assoc in H2;
try apply F2plus_flip_l_0 in H2;
try rewrite <- H2; auto; try rewrite F2plus_comm at 1; auto.
destruct a, b;
try match goal with
| Hyp : _ |- anticommute_listP (gI :: _) (_) =>
apply anticommuting_listP_commP_anticommL; [constructor; auto | apply H1];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
auto
| Hyp : _ |- anticommute_listP (_) (gI :: _) =>
apply anticommuting_listP_commP_anticommL; [constructor; auto | apply H1];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
auto
| Hyp : _ |- anticommute_listP (gX :: _) (gX :: _) =>
apply anticommuting_listP_commP_anticommL; [constructor; auto | apply H1];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
auto
| Hyp : _ |- anticommute_listP (gY :: _) (gY :: _) =>
apply anticommuting_listP_commP_anticommL; [constructor; auto | apply H1];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
auto
| Hyp : _ |- anticommute_listP (gZ :: _) (gZ :: _) =>
apply anticommuting_listP_commP_anticommL; [constructor; auto | apply H1];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
auto
end.
4: { try rewrite ! F2mult_1_l in H2; try rewrite ! F2mult_1_r in H2.
unfold MplusF2 in H2.
rewrite ! elemToVecF2_one00 in H2.
rewrite <- H2.
unfold MplusF2. rewrite ! F2plus_assoc.
setoid_rewrite F2plus_comm at 5. rewrite ! F2plus_assoc.
F2simpl. auto. }
1-6: apply anticommuting_listP_anticommP_commL;
[constructor; intro H''; discriminate | apply H0];
unfold toCheckMatrixF2ElementLeftX, toCheckMatrixF2ElementRightZ in H2;
try rewrite ! F2mult_0_l in H2; try rewrite ! F2mult_0_r in H2;
try rewrite ! F2mult_1_l in H2; try rewrite ! F2mult_1_r in H2;
try rewrite ! elemToVecF2_zero in H2;
try rewrite ! F2Module.GMplus_0_l in H2; try rewrite ! F2Module.GMplus_0_r in H2;
unfold MplusF2 in H2; unfold MplusF2;
rewrite ! elemToVecF2_one00 in H2;
try rewrite <- ! F2plus_assoc in H2;
try apply F2plus_flip_l_1 in H2;
try rewrite <- H2; auto.
1-3: try rewrite F2plus_comm in H2 at 1;
try rewrite <- ! F2plus_assoc in H2;
try apply F2plus_flip_l_1 in H2;
try rewrite <- H2; auto; try rewrite F2plus_comm at 1; auto.
Qed.
Lemma fromLLpToCheckMatrixF2_checkLambdaF2_comm_iff : forall (Lp1 Lp2 : list Pauli),
length Lp1 = length Lp2 -> (length Lp1 > 0)%nat ->
((fromLLpToCheckMatrixF2 1%nat (length Lp1) [Lp1]) × (checkLambdaF2 (length Lp1)) × ((fromLLpToCheckMatrixF2 1%nat (length Lp1) [Lp2]) ⊤)) 0%nat 0%nat = 0 <-> commute_listP Lp1 Lp2.
Proof. intros Lp1 Lp2 H H0.
destruct (fromLLpToCheckMatrixF2_checkLambdaF2_comm_anticomm Lp1 Lp2 H H0).
split; auto.
intros H3.
rewrite <- F2_neq1_iff_eq0.
intro H4.
destruct (anticommute_commute_listP_no_middle Lp1 Lp2); try contradiction.
contradict H5.
apply H2; auto.
Qed.
Lemma fromLLpToCheckMatrixF2_checkLambdaF2_anticomm_iff : forall (Lp1 Lp2 : list Pauli),
length Lp1 = length Lp2 -> (length Lp1 > 0)%nat ->
((fromLLpToCheckMatrixF2 1%nat (length Lp1) [Lp1]) × (checkLambdaF2 (length Lp1)) × ((fromLLpToCheckMatrixF2 1%nat (length Lp1) [Lp2]) ⊤)) 0%nat 0%nat = 1 <-> anticommute_listP Lp1 Lp2.
Proof. intros Lp1 Lp2 H H0.
destruct (fromLLpToCheckMatrixF2_checkLambdaF2_comm_anticomm Lp1 Lp2 H H0).
split; auto.
intros H3.
rewrite <- F2_neq0_iff_eq1.
intro H4.
destruct (anticommute_commute_listP_no_middle Lp1 Lp2); try contradiction.
contradict H5.
apply H1; auto.
Qed.
Lemma rowF2_fromLLpToCheckMatrixF2 : forall {n i : nat} {LLp : list (list Pauli)},
Forall (fun Lp : list Pauli => length Lp = n) LLp -> LLp <> [] -> (n > 0)%nat ->
get_rowF2 (fromLLpToCheckMatrixF2 (length LLp) n LLp) i =
fromLLpToCheckMatrixF2 1 n [nth i LLp (repeat gI n)].
Proof. intros n i LLp H H0 H1.
unfold get_rowF2, fromLLpToCheckMatrixF2.
unfold F2Module.smash.
prep_matrix_equality.
bdestruct_all; subst;
unfold toCheckMatrixF2Left, toCheckMatrixF2ElementLeftX,
toCheckMatrixF2Right, toCheckMatrixF2ElementRightZ; auto;
rewrite nth_overflow with (n := x); try rewrite nth_repeat;
simpl; try lia; auto.
Qed.
Lemma get_rowF2_e_iF2_hit : forall {i m : nat},
(i < m)%nat -> (get_rowF2 (@e_iF2 m i) i) 0%nat 0%nat = 1%F2.
Proof. intros i m H.
unfold get_rowF2, e_iF2; bdestruct_all; simpl; auto.
Qed.
Lemma get_rowF2_e_iF2_miss : forall {i j m : nat},
(i < m)%nat -> (j < m)%nat -> (i <> j)%nat -> (get_rowF2 (@e_iF2 m i) j) 0%nat 0%nat = 0%F2.
Proof. intros i j m H H0 H1.
unfold get_rowF2, e_iF2; bdestruct_all; simpl; auto.
Qed.
Lemma existsCheckMatrixF2Vector : forall (n : nat) (LLp : list (list Pauli)),
Forall (fun Lp : list Pauli => length Lp = n) LLp -> LLp <> [] -> (n > 0)%nat ->
linearly_independentF2 ((fromLLpToCheckMatrixF2 (length LLp) n LLp) ⊤) ->
(forall i : nat, (i < length LLp)%nat -> (exists v : VectorF2 (n + n), WF_MatrixF2 v /\
(fromLLpToCheckMatrixF2 (length LLp) n LLp) × checkLambdaF2 n × v = e_iF2 i /\
(fromLLpToCheckMatrixF2 1%nat n [nth i LLp (repeat gI n)] × checkLambdaF2 n × v) 0%nat 0%nat = 1%F2 /\
(forall j : nat, (j < length LLp)%nat -> j <> i ->
(fromLLpToCheckMatrixF2 1%nat n [nth j LLp (repeat gI n)] × checkLambdaF2 n × v) 0%nat 0%nat = 0%F2))).
Proof. intros n LLp H H0 H1 H2 i H3.
assert (WF_MatrixF2 (fromLLpToCheckMatrixF2 (length LLp) n LLp)).
{ apply WF_fromLLpToCheckMatrixF2; auto.
apply Forall_impl with (P := (fun Lp : list Pauli => length Lp = n)); intros; auto; lia. }
assert (WF_MatrixF2 (@e_iF2 (length LLp) i)).
{ apply F2Module.WF_e_i. }
destruct (F2Module.lin_indep_rows_implies_exists_sol
(fromLLpToCheckMatrixF2 (length LLp) n LLp) (e_iF2 i) H4 H5 H2)
as [v [WFv Avb]].
assert ((IF2 (n + n)%nat) × v = v).
{ rewrite F2Module.GMmult_1_l; auto. }
rewrite <- checkLambdaF2_inv in H6.
rewrite F2Module.GMmult_assoc in H6.
exists (checkLambdaF2 n × v).
repeat split.
- apply F2Module.WF_mult; auto. apply WF_checkLambdaF2.
- rewrite F2Module.GMmult_assoc.
rewrite H6. auto.
- rewrite ! F2Module.GMmult_assoc. rewrite H6.
assert (F2Module.get_row (fromLLpToCheckMatrixF2 (length LLp) n LLp × v) i =
F2Module.get_row (@e_iF2 (length LLp) i) i).
{ rewrite Avb. auto. }
rewrite F2Module.matrix_by_basis_transpose in H7; try lia.
rewrite <- F2Module.GMmult_assoc in H7.
rewrite <- F2Module.matrix_by_basis_transpose in H7; try lia.
rewrite rowF2_fromLLpToCheckMatrixF2 in H7; auto.
rewrite H7. rewrite get_rowF2_e_iF2_hit ; auto.
- intros j H7 H8.
rewrite ! F2Module.GMmult_assoc. rewrite H6.
assert (F2Module.get_row (fromLLpToCheckMatrixF2 (length LLp) n LLp × v) j =
F2Module.get_row (@e_iF2 (length LLp) i) j).
{ rewrite Avb. auto. }
rewrite F2Module.matrix_by_basis_transpose in H9; try lia.
rewrite <- F2Module.GMmult_assoc in H9.
rewrite <- F2Module.matrix_by_basis_transpose in H9; try lia.
rewrite rowF2_fromLLpToCheckMatrixF2 in H9; auto.
rewrite H9. rewrite get_rowF2_e_iF2_miss; auto.
Qed.
Definition fromF2PairToPauli (x z : F2) : Pauli :=
match x, z with
| 0, 0 => gI
| 1, 0 => gX
| 0, 1 => gZ
| 1, 1 => gY
end.
Fixpoint fromCheckMatrixF2RowToLp_rec
{m n : nat} (M : MatrixF2 m (n + n)) (row col_count : nat) (acc : list Pauli) : list Pauli :=
match col_count with
| 0%nat => acc
| S col_count' => fromCheckMatrixF2RowToLp_rec M row col_count'
((fromF2PairToPauli (M row col_count') (M row (n + col_count')%nat)) :: acc)
end.
Definition fromCheckMatrixF2RowToLp {m n : nat} (M : MatrixF2 m (n + n)) (row : nat) : list Pauli :=
fromCheckMatrixF2RowToLp_rec M row n [].
Fixpoint fromCheckMatrixF2ToLLp_rec
{m n : nat} (M : MatrixF2 m (n + n)) (row_count : nat) (acc : list (list Pauli)) : list (list Pauli) :=
match row_count with
| 0%nat => acc
| S row_count' => fromCheckMatrixF2ToLLp_rec M row_count'
((fromCheckMatrixF2RowToLp M row_count') :: acc)
end.
Definition fromCheckMatrixF2ToLLp {m n : nat} (M : MatrixF2 m (n + n)) : list (list Pauli) :=
fromCheckMatrixF2ToLLp_rec M m [].
Lemma fromCheckMatrixF2RowToLp_rec_acc_app :
forall {m n : nat} (M : MatrixF2 m (n + n)) (row col_count : nat) (acc : list Pauli),
fromCheckMatrixF2RowToLp_rec M row col_count acc =
(fromCheckMatrixF2RowToLp_rec M row col_count []) ++ acc.
Proof. intros m n M row col_count acc.
gen acc. induction col_count; intros; auto.
simpl. setoid_rewrite IHcol_count.
rewrite <- app_assoc. auto.
Qed.
Lemma fromCheckMatrixF2ToLLp_rec_acc_app :
forall {m n : nat} (M : MatrixF2 m (n + n)) (row_count : nat) (acc : list (list Pauli)),
fromCheckMatrixF2ToLLp_rec M row_count acc =
(fromCheckMatrixF2ToLLp_rec M row_count []) ++ acc.
Proof. intros m n M row_count acc.
gen acc. induction row_count; intros; auto.
simpl. setoid_rewrite IHrow_count.
rewrite <- app_assoc. auto.
Qed.
Lemma fromCheckMatrixF2RowToLp_rec_reduce_row :
forall {m n : nat} (M : MatrixF2 (S m) (n + n)) (row row' col_count : nat) (acc : list Pauli),
(row' < row)%nat ->
fromCheckMatrixF2RowToLp_rec M row' col_count acc =
fromCheckMatrixF2RowToLp_rec (reduce_rowF2 M row) row' col_count acc.
Proof. intros m n M row row' col_count acc H.
gen acc. induction col_count; intros; auto.
simpl. setoid_rewrite IHcol_count; auto. f_equal.
unfold reduce_rowF2. bdestruct_all; auto.
Qed.
Lemma fromCheckMatrixF2ToLLp_rec_reduce_row :
forall {m n : nat} (M : MatrixF2 (S m) (n + n)) (row row_count : nat) (acc : list (list Pauli)),
(row_count <= row)%nat ->
fromCheckMatrixF2ToLLp_rec M row_count acc =
fromCheckMatrixF2ToLLp_rec (reduce_rowF2 M row) row_count acc.
Proof. intros m n M row row_count acc H.
gen n m M row acc. induction row_count; intros; auto.
simpl. rewrite IHrow_count with (row := row); try lia.
do 2 f_equal. unfold fromCheckMatrixF2RowToLp.
rewrite fromCheckMatrixF2RowToLp_rec_reduce_row with (row := row); auto; try lia.
Qed.
Lemma fromCheckMatrixF2ToLLp_rec_length_row :
forall {m n : nat} (M : MatrixF2 m (n + n)) (row_count : nat) (acc : list (list Pauli)),
length (fromCheckMatrixF2ToLLp_rec M row_count acc) = (row_count + length acc)%nat.
Proof. intros m n M row_count acc.
gen acc. induction row_count; intros; auto.
simpl. rewrite IHrow_count. auto.
Qed.
Lemma fromCheckMatrixF2RowToLp_rec_length :
forall {m n : nat} (M : MatrixF2 m (n + n)) (row col_count : nat) (acc : list Pauli),
length (fromCheckMatrixF2RowToLp_rec M row col_count acc) =
(col_count + length acc)%nat.
Proof. intros m n M row col_count acc.
gen acc. induction col_count; intros; auto.
simpl. rewrite IHcol_count. auto.
Qed.
Lemma fromCheckMatrixF2ToLLp_rec_length_col :
forall {m n : nat} (M : MatrixF2 m (n + n)) (row_count : nat) (acc : list (list Pauli)),
Forall (fun Lp : list Pauli => length Lp = n) acc ->
Forall (fun Lp : list Pauli => length Lp = n) (fromCheckMatrixF2ToLLp_rec M row_count acc).
Proof. intros m n M row_count acc H.
gen acc. induction row_count; intros; auto.
simpl. apply IHrow_count; auto.
rewrite Forall_forall. intros x H0.
destruct H0.
- subst. unfold fromCheckMatrixF2RowToLp.
rewrite fromCheckMatrixF2RowToLp_rec_length. auto.
- rewrite Forall_forall in H.
apply H; auto.
Qed.
Lemma toCheckMatrixF2ElementLeftX_nth_fromCheckMatrixF2RowToLp_rec :
forall {m n : nat} (M : MatrixF2 m (n + n)) (r y col_count : nat),
WF_MatrixF2 M -> (y < col_count)%nat ->
toCheckMatrixF2ElementLeftX (nth y (fromCheckMatrixF2RowToLp_rec M r col_count []) gI) = M r y.
Proof. intros m n M r y col_count H H0.
gen m n M r y.
induction col_count; intros; try lia. simpl.
rewrite fromCheckMatrixF2RowToLp_rec_acc_app.
bdestruct (y =? col_count)%nat.
- subst.
assert (length (fromCheckMatrixF2RowToLp_rec M r col_count []) = col_count).
{ rewrite fromCheckMatrixF2RowToLp_rec_length. simpl. auto. }
rewrite <- H1 at 1.
rewrite nth_middle.
unfold toCheckMatrixF2ElementLeftX, fromF2PairToPauli.
destruct (M r col_count); destruct (M r (n + col_count)%nat); auto.
- rewrite <- nth_firstn with (i := y) (n := col_count); try lia.
rewrite firstn_app.
rewrite fromCheckMatrixF2RowToLp_rec_length.
simpl. replace (col_count - (col_count + 0))%nat with 0%nat by lia. simpl.
rewrite app_nil_r.
rewrite firstn_all2 at 1.
+ apply IHcol_count; auto; lia.
+ rewrite fromCheckMatrixF2RowToLp_rec_length; simpl; lia.
Qed.
Lemma toCheckMatrixF2ElementRightZ_nth_fromCheckMatrixF2RowToLp_rec :
forall {m n : nat} (M : MatrixF2 m (n + n)) (r y col_count : nat),
WF_MatrixF2 M -> (y < col_count)%nat ->
toCheckMatrixF2ElementRightZ (nth y (fromCheckMatrixF2RowToLp_rec M r col_count []) gI) = M r (n + y)%nat.
Proof. intros m n M r y col_count H H0.
gen m n M r y.
induction col_count; intros; try lia. simpl.
rewrite fromCheckMatrixF2RowToLp_rec_acc_app.
bdestruct (y =? col_count)%nat.
- subst.
assert (length (fromCheckMatrixF2RowToLp_rec M r col_count []) = col_count).
{ rewrite fromCheckMatrixF2RowToLp_rec_length. simpl. auto. }
rewrite <- H1 at 1.
rewrite nth_middle.
unfold toCheckMatrixF2ElementRightZ, fromF2PairToPauli.
destruct (M r col_count); destruct (M r (n + col_count)%nat); auto.
- rewrite <- nth_firstn with (i := y) (n := col_count); try lia.
rewrite firstn_app.
rewrite fromCheckMatrixF2RowToLp_rec_length.
simpl. replace (col_count - (col_count + 0))%nat with 0%nat by lia. simpl.
rewrite app_nil_r.
rewrite firstn_all2 at 1.
+ apply IHcol_count; auto; lia.
+ rewrite fromCheckMatrixF2RowToLp_rec_length; simpl; lia.
Qed.
Lemma fromCheckMatrixF2ToLLpToCheckMatrixF2 :
forall {m n : nat} (M : MatrixF2 m (n + n)),
WF_MatrixF2 M ->
fromLLpToCheckMatrixF2 m n (fromCheckMatrixF2ToLLp M) = M.
Proof. intros m n M H.
unfold fromLLpToCheckMatrixF2.
unfold F2Module.smash, toCheckMatrixF2Left, toCheckMatrixF2Right.
prep_matrix_equality.
bdestruct_all.
- unfold fromCheckMatrixF2ToLLp.
gen n M x y. induction m; intros.
+ simpl. destruct x; rewrite nth_repeat; rewrite H; auto; try lia.
+ simpl. rewrite fromCheckMatrixF2ToLLp_rec_acc_app.
bdestruct (x <? m)%nat.
* rewrite fromCheckMatrixF2ToLLp_rec_reduce_row with (row := m); auto.
rewrite <- nth_firstn with (i := x) (n := m); auto.
rewrite firstn_app.
rewrite fromCheckMatrixF2ToLLp_rec_length_row.
rewrite firstn_all2 at 1.
-- simpl. replace (m - (m + 0))%nat with 0%nat by lia. simpl.
rewrite app_nil_r.
assert (M x y = (reduce_rowF2 M m) x y).
{ unfold reduce_rowF2. bdestruct_all. auto. }
rewrite H2.
apply IHm; auto.
apply F2Module.WF_reduce_row; auto.
-- rewrite fromCheckMatrixF2ToLLp_rec_length_row. simpl. lia.
* bdestruct (x =? m)%nat.
-- subst.
assert (length (fromCheckMatrixF2ToLLp_rec M m []) = m).
{ rewrite fromCheckMatrixF2ToLLp_rec_length_row. simpl. auto. }
rewrite <- H2 at 1.
rewrite nth_middle.
clear IHm H1 H2.
unfold fromCheckMatrixF2RowToLp.
rewrite toCheckMatrixF2ElementLeftX_nth_fromCheckMatrixF2RowToLp_rec;
auto.
-- rewrite nth_overflow with (n := x).
++ rewrite nth_repeat. unfold toCheckMatrixF2ElementLeftX. rewrite H; auto; lia.
++ rewrite app_length. rewrite fromCheckMatrixF2ToLLp_rec_length_row. simpl. lia.
- unfold fromCheckMatrixF2ToLLp.
gen n M x y. induction m; intros.
+ simpl. destruct x; rewrite nth_repeat; rewrite H; auto; try lia.
+ simpl. rewrite fromCheckMatrixF2ToLLp_rec_acc_app.
bdestruct (x <? m)%nat.
* rewrite fromCheckMatrixF2ToLLp_rec_reduce_row with (row := m); auto.
rewrite <- nth_firstn with (i := x) (n := m); auto.
rewrite firstn_app.
rewrite fromCheckMatrixF2ToLLp_rec_length_row.
rewrite firstn_all2 at 1.
-- simpl. replace (m - (m + 0))%nat with 0%nat by lia. simpl.
rewrite app_nil_r.
assert (M x y = (reduce_rowF2 M m) x y).
{ unfold reduce_rowF2. bdestruct_all. auto. }
rewrite H2.
apply IHm; auto.
apply F2Module.WF_reduce_row; auto.
-- rewrite fromCheckMatrixF2ToLLp_rec_length_row. simpl. lia.
* bdestruct (x =? m)%nat.
-- subst.
assert (length (fromCheckMatrixF2ToLLp_rec M m []) = m).
{ rewrite fromCheckMatrixF2ToLLp_rec_length_row. simpl. auto. }
rewrite <- H2 at 1.
rewrite nth_middle.
clear IHm H1 H2.
unfold fromCheckMatrixF2RowToLp.
bdestruct (y <? n + n)%nat.
++ rewrite toCheckMatrixF2ElementRightZ_nth_fromCheckMatrixF2RowToLp_rec;
auto; f_equal; lia.
++ rewrite nth_overflow with (n := (y - n)%nat).
** unfold toCheckMatrixF2ElementRightZ.
rewrite H; auto; lia.
** rewrite fromCheckMatrixF2RowToLp_rec_length. simpl. lia.
-- rewrite nth_overflow with (n := x).
++ rewrite nth_repeat. unfold toCheckMatrixF2ElementLeftX. rewrite H; auto; lia.
++ rewrite app_length. rewrite fromCheckMatrixF2ToLLp_rec_length_row. simpl. lia.
Qed.
Lemma exists_commute_anticommute_Lp : forall (n : nat) (LLp : list (list Pauli)),
Forall (fun Lp : list Pauli => length Lp = n) LLp -> LLp <> [] -> (n > 0)%nat ->
linearly_independentF2 ((fromLLpToCheckMatrixF2 (length LLp) n LLp) ⊤) ->
(forall i : nat, (i < length LLp)%nat -> (exists Lp : list Pauli, length Lp = n /\
anticommute_listP (nth i LLp (repeat gI n)) Lp /\
(forall j : nat, (j < length LLp)%nat -> j <> i -> commute_listP (nth j LLp (repeat gI n)) Lp))).
Proof. intros n LLp H H0 H1 H2 i H3.
destruct (existsCheckMatrixF2Vector n LLp H H0 H1 H2 i H3)
as [v [WFv [v_to_e_i [to_one to_zero]]]].
assert (WFvt: WF_MatrixF2 v ⊤). { apply F2Module.WF_transpose. auto. }
pose (fromCheckMatrixF2ToLLpToCheckMatrixF2 (v⊤) WFvt) as e.
assert ((fromLLpToCheckMatrixF2 1 n (fromCheckMatrixF2ToLLp (v) ⊤)) ⊤ = ((v) ⊤) ⊤).
{ rewrite e. auto. }
rewrite F2Module.transpose_involutive in H4.
rewrite <- H4 in to_one, to_zero.
exists (nth 0%nat (fromCheckMatrixF2ToLLp (v) ⊤) (repeat gI n)).
repeat split.
- simpl. unfold fromCheckMatrixF2RowToLp.
rewrite fromCheckMatrixF2RowToLp_rec_length.
simpl. auto.
- rewrite <- fromLLpToCheckMatrixF2_checkLambdaF2_anticomm_iff.
+ assert (length (nth i LLp (repeat gI n)) = n).
{ bdestruct (i <? length LLp).
- rewrite Forall_nth in H. apply H; auto.
- rewrite nth_overflow; auto; rewrite repeat_length; auto. }
rewrite ! H5. apply to_one.
+ simpl. unfold fromCheckMatrixF2RowToLp.
rewrite fromCheckMatrixF2RowToLp_rec_length. simpl.
bdestruct (i <? length LLp).
* rewrite Forall_nth in H. rewrite H; auto.
* rewrite nth_overflow; auto; rewrite repeat_length; auto.
+ rewrite Forall_nth in H. rewrite H; auto.
- intros j H5 H6.
rewrite <- fromLLpToCheckMatrixF2_checkLambdaF2_comm_iff.
+ assert (length (nth j LLp (repeat gI n)) = n).
{ bdestruct (j <? length LLp).
- rewrite Forall_nth in H. apply H; auto.
- rewrite nth_overflow; auto; rewrite repeat_length; auto. }
rewrite ! H7. apply to_zero; auto.
+ simpl. unfold fromCheckMatrixF2RowToLp.
rewrite fromCheckMatrixF2RowToLp_rec_length. simpl.
bdestruct (j <? length LLp).
* rewrite Forall_nth in H. rewrite H; auto.
* rewrite nth_overflow; auto; rewrite repeat_length; auto.
+ rewrite Forall_nth in H. rewrite H; auto.
Qed.
(* Separability Semantics *)
Close Scope F2_scope.
Local Open Scope genmatrix_scope.
Local Open Scope matrix_scope.
Declare Module CField : FieldModule
with Definition F := C
with Definition R0 := C_is_monoid
with Definition R1 := C_is_group
with Definition R2 := C_is_comm_group
with Definition R3 := C_is_ring
with Definition R4 := C_is_comm_ring
with Definition R5 := C_is_field.
Module CM := SubspacesOverField CField.
Definition stabilizeByListT
{n : nat} (P : Vector (2 ^ n)%nat -> Prop) (Lt : list (TType n)) (v : Vector (2 ^ n)%nat) :=
P v /\ (forall t : TType n, In t Lt -> (@Mmult (2 ^ n)%nat (2 ^ n)%nat 1%nat (translate t) v = v)).
Lemma stabilizeByListT_is_subspace :
forall {n : nat} (P : Vector (2 ^ n)%nat -> Prop) (Lt : list (TType n)),
@CM.subspace (2 ^ n)%nat P ->
@CM.subspace (2 ^ n)%nat (stabilizeByListT P Lt).
Proof. intros n P Lt H.
unfold stabilizeByListT in *.
unfold CM.subspace in *.
split; [idtac | split; [idtac | split]]; intros.
- destruct H0.
destruct H as [H2 [H3 [H4 H5]]].
apply H2; auto.
- destruct H as [H0 [H1 [H2 H3]]].
split; auto. intros t H.
rewrite Mmult_0_r. lma'.
- destruct H as [H [H2 [H3 H4]]].
destruct H0, H1.
split.
+ apply H3; auto.
+ intros t H7.
rewrite Mmult_plus_distr_l.
f_equal.
* intros. rewrite <- H10 at 2. rewrite <- H11 at 2.
lma.
* apply H5; auto.
* apply H6; auto.
- destruct H as [H [H2 [H3 H4]]].
destruct H0.
split; auto.
intros t H5.
rewrite Mscale_mult_dist_r.
f_equal. intros. rewrite H9. auto.
apply H1; auto.
Qed.
Lemma stabilizeByListT_app :
forall {n : nat} (P : Vector (2 ^ n)%nat -> Prop) (Lt1 Lt2 : list (TType n)),
(forall v : Vector (2 ^ n)%nat, stabilizeByListT P (Lt1 ++ Lt2) v <->
stabilizeByListT P Lt1 v /\ stabilizeByListT P Lt2 v).
Proof. intros n P Lt1 Lt2 v.
unfold stabilizeByListT in *.
split; intros.
- destruct H.
repeat (split; auto); intros.
+ apply H0.
rewrite in_app_iff.
left. auto.
+ apply H0.
rewrite in_app_iff.
right. auto.
- destruct H as [[H H0] [H1 H2]].
split; auto; intros.
rewrite in_app_iff in H3.
destruct H3.
+ apply H0; auto.
+ apply H2; auto.
Qed.
Lemma stabilizeByListT_app_comm :
forall {n : nat} (P : Vector (2 ^ n)%nat -> Prop) (Lt1 Lt2 : list (TType n)),
(forall v : Vector (2 ^ n)%nat, stabilizeByListT P (Lt1 ++ Lt2) v <->
stabilizeByListT P (Lt2 ++ Lt1) v).
Proof. intros n P Lt1 Lt2 v.
split; intros;
rewrite stabilizeByListT_app;
rewrite and_comm;
rewrite <- stabilizeByListT_app;
auto.
Qed.
Lemma stabilizeByListT_cons :
forall {n : nat} (P : Vector (2 ^ n)%nat -> Prop) (Lt : list (TType n)) (t : TType n),
(forall v : Vector (2 ^ n)%nat, stabilizeByListT P (t :: Lt) v <->
stabilizeByListT P [t] v /\ stabilizeByListT P Lt v).
Proof. intros n P Lt t v.
replace (t :: Lt) with ([t] ++ Lt) by (simpl; auto).
rewrite stabilizeByListT_app; split; auto.
Qed.
Lemma stabilizeByListT_Permutation :
forall {n : nat} (P : Vector (2 ^ n)%nat -> Prop) (Lt1 Lt2 : list (TType n)),
Permutation Lt1 Lt2 ->
(forall v : Vector (2^n)%nat, stabilizeByListT P Lt1 v -> stabilizeByListT P Lt2 v).
Proof. intros n P Lt1 Lt2 H v H0.
induction H; auto.
- rewrite stabilizeByListT_cons.
assert ((stabilizeByListT P [x] v /\ stabilizeByListT P l v) ->
(stabilizeByListT P [x] v /\ stabilizeByListT P l' v)).
{ intros H1. destruct H1. split; auto. }
apply H1.
rewrite <- stabilizeByListT_cons; auto.
- rewrite stabilizeByListT_cons in H0.
destruct H0.
rewrite stabilizeByListT_cons in H0.
destruct H0.
rewrite stabilizeByListT_cons. split; auto.
rewrite stabilizeByListT_cons. split; auto.
Qed.
Lemma stabilizeByListT_nil : forall {n : nat} (P : Vector (2 ^ n)%nat -> Prop),
(forall v : Vector (2^n)%nat, stabilizeByListT P [] v <-> P v).
Proof. intros n P v.
unfold stabilizeByListT.
split; intros.
- destruct H; auto.
- split; auto. intros. inversion H0.
Qed.
Lemma translate_defaultT_I_comm : forall {n : nat} (t : TType n),
proper_length_TType t ->
(translate (defaultT_I n) × translate t = translate t × translate (defaultT_I n))%M.
Proof. intros n t H.
rewrite ! translate_defaultT_I.
rewrite Mmult_1_l, Mmult_1_r; auto.
all : apply WF_translate; auto.
Qed.
Lemma anticommute_commute_T_translate : forall {n : nat} (t1 t2 : TType n),
proper_length_TType t1 -> proper_length_TType t2 ->
(anticommute_T t1 t2 -> translate(t1) × translate(t2) = -C1 .* (translate(t2) × translate(t1))) /\
(commute_T t1 t2 -> translate(t1) × translate(t2) = translate(t2) × translate(t1)).
Proof. intros n t1 t2 H H0.
destruct t1, t2, H, H0; unfold translate; simpl in *.
split; intros.
- inversion H3; clear H3; simpl in *.
gen n.
apply anticommute_listP_ind' with
(P0 := fun l l0 : list Pauli => forall n : nat, n <> 0%nat -> length l = n -> n <> 0%nat -> length l0 = n -> @Mmult (2 ^ n)%nat (2 ^ n)%nat (2 ^ n)%nat (c .* (⨂ map translate_P l)) (c0 .* (⨂ map translate_P l0)) = - C1 .* (@Mmult (2 ^ n)%nat (2 ^ n)%nat (2 ^ n)%nat (c0 .* (⨂ map translate_P l0)) (c .* (⨂ map translate_P l))))
(P := fun l l0 : list Pauli => forall n : nat, n <> 0%nat -> length l = n -> n <> 0%nat -> length l0 = n -> @Mmult (2 ^ n)%nat (2 ^ n)%nat (2 ^ n)%nat (c .* (⨂ map translate_P l)) (c0 .* (⨂ map translate_P l0)) = @Mmult (2 ^ n)%nat (2 ^ n)%nat (2 ^ n)%nat (c0 .* (⨂ map translate_P l0)) (c .* (⨂ map translate_P l))) in H4; intros.
+ apply H4; auto.
+ inversion H.
destruct H5 as [H5 | [H5 | H5]]; subst;
try destruct P1; try destruct P2; simpl in *; lma'.
+ simpl in *. destruct n; try contradiction.
apply Nat.succ_inj in H3, H6.
rewrite ! map_length in *. subst. rewrite ! H6 in *.
setoid_rewrite <- Mscale_kron_dist_r.
setoid_rewrite kron_mixed_product'; auto.
f_equal.
* inversion H.
destruct H3 as [H3 | [H3 | H3]]; subst;
try destruct P1; try destruct P2; simpl in *; lma'.
* destruct l1, l2; inversion H0; subst; simpl in *.
-- rewrite ! Matrix.kron_1_r in *.
apply (H1 1%nat); lia.
-- apply (H1 (S (length l1))); lia.
-- apply (H1 (S (length l1))); lia.
+ simpl in *. destruct n; try contradiction.
apply Nat.succ_inj in H3, H6.
rewrite ! map_length in *. subst. rewrite ! H6 in *.
setoid_rewrite <- Mscale_kron_dist_r.
setoid_rewrite kron_mixed_product'; auto.
assert (translate_P P2 × translate_P P1 = -C1 .* (translate_P P1 × translate_P P2)).
{ inversion H. destruct P1, P2; try contradiction; simpl; lma'. }
rewrite H3.
setoid_rewrite Mscale_kron_dist_l.
setoid_rewrite <- Mscale_kron_dist_r.
f_equal.
apply anticommute_listP_nonempty_equal_len in H0.
destruct H0. destruct H7.
apply H1; auto;
intro H'; rewrite length_zero_iff_nil in H'; contradiction.
+ simpl in *.
inversion H.
rewrite ! Matrix.kron_1_r in *.
subst. rewrite ! Mscale_mult_dist_l, ! Mscale_mult_dist_r.
rewrite ! Mscale_assoc.