-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeisenberg.v
2582 lines (2113 loc) · 78.5 KB
/
Heisenberg.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 Psatz.
Require Import String.
Require Import Program.
Require Import List.
Require Export Complex.
Require Export Matrix.
Require Export Quantum.
Require Export Eigenvectors.
(* Some helpers *)
(* this is trivial but helps shorten proofs and Ltacs *)
Lemma kill_true : forall P : Prop,
P /\ True <-> P.
Proof. split. intros [H _]. easy.
intros. split. easy. easy.
Qed.
Lemma in_simplify : forall {X} (x x1 : X),
In x1 [x] -> x1 = x.
Proof. intros. simpl in H.
destruct H. easy. easy.
Qed.
(**************************************)
(* defining Heisenberg representation *)
(**************************************)
Declare Scope heisenberg_scope.
Delimit Scope heisenberg_scope with H.
Open Scope heisenberg_scope.
Notation vecType n := (list (Square n)).
Definition singVecType {n : nat} (v : Vector n) (U : Square n) : Prop :=
WF_Matrix v /\ exists λ, Eigenpair U (v, λ).
Definition vecHasType {n : nat} (v : Vector n) (ts: vecType n) : Prop :=
forall (A : Square n), In A ts -> singVecType v A.
(* an alternate definition which helps with singleton tactics later *)
Fixpoint vecHasType' {n : nat} (v : Vector n) (ts: vecType n) : Prop :=
match ts with
| [] => True
| (t :: ts') => (singVecType v t) /\ vecHasType' v ts'
end.
Lemma vecHasType_is_vecHasType' : forall (n : nat) (v : Vector n) (A : vecType n),
vecHasType v A <-> vecHasType' v A.
Proof. intros n v A. split.
- induction A as [| h].
* easy.
* intros H.
simpl. split.
+ unfold vecHasType in H.
apply H.
simpl; left; reflexivity.
+ apply IHA.
unfold vecHasType in H.
unfold vecHasType; intros.
apply H; simpl; right; apply H0.
- induction A as [| h].
* easy.
* intros [H1 H2].
unfold vecHasType; intros.
apply IHA in H2.
unfold vecHasType in H2.
destruct H as [H3 | H4].
rewrite <- H3; apply H1.
apply H2; apply H4.
Qed.
Notation "v :' T" := (vecHasType v T) (at level 61) : heisenberg_scope.
Notation "A ∩ B" := (A ++ B) (at level 60, no associativity) : heisenberg_scope.
(*****************************)
(* Basic vectType operations *)
(*****************************)
(* Singleton says if a vectType is able to be multiplied, scaled, or kronned *)
Definition Singleton {n : nat} (A : vecType n) :=
match A with
| [a] => True
| _ => False
end.
(* helper lemma to immediatly turn singleton vecType into [a] form *)
Lemma singleton_simplify : forall {n} (A : vecType n),
Singleton A -> exists (a : Square n), A = [a].
Proof. intros; destruct A.
easy.
destruct A.
exists m.
reflexivity.
easy.
Qed.
(* multiplies every combination of lists A and B *)
Fixpoint mul {n : nat} (A B : vecType n) :=
match A with
| [] => []
| (a :: as') => List.map (fun b => a × b) B ++ mul as' B
end.
Definition scale {n : nat} (c : C) (A : vecType n) :=
List.map (fun a => c .* a) A.
Definition i {n : nat} (A : vecType n) :=
scale Ci A.
Definition neg {n : nat} (A : vecType n) :=
scale (-1) A.
(* tensor similar to mul *)
Fixpoint tensor {n m : nat} (A : vecType n) (B : vecType m) : vecType (n * m) :=
match A with
| [] => []
| (a :: as') => List.map (fun b => a ⊗ b) B ++ tensor as' B
end.
Fixpoint big_tensor {n} (As : list (vecType n)) :
vecType (n^(length As)) :=
match As with
| [] => [I 1]
| A :: As' => tensor A (big_tensor As')
end.
Fixpoint tensor_n n {m} (A : vecType m) :=
match n with
| 0 => [I 1]
| S n' => tensor (tensor_n n' A) A
end.
Notation "- T" := (neg T) : heisenberg_scope.
Infix "*'" := mul (at level 40, left associativity) : heisenberg_scope.
Infix "⊗'" := tensor (at level 51, right associativity) : heisenberg_scope.
Infix "·" := scale (at level 45, left associativity) : heisenberg_scope.
Notation "n ⨂' A" := (tensor_n n A) (at level 30, no associativity) : heisenberg_scope.
Notation "⨂' A" := (big_tensor A) (at level 60): heisenberg_scope.
(*****************************************************)
(* helper lemmas to extract from mult, tensor, scale *)
(*****************************************************)
Lemma in_mult : forall {n} (p : Square n) (A B : vecType n),
In p (A *' B) -> exists a b, In a A /\ In b B /\ p = a × b.
Proof. intros. induction A as [| h].
- simpl in H. easy.
- simpl in H.
apply in_app_or in H; destruct H as [H | H].
* apply in_map_iff in H. destruct H.
exists h, x. split.
simpl. left. easy. destruct H as [H H'].
split. apply H'. rewrite H; reflexivity.
* apply IHA in H. do 2 (destruct H).
exists x, x0.
destruct H as [H1 H2].
split. simpl. right; apply H1.
apply H2.
Qed.
Lemma in_tensor : forall {n m} (p : Square (n*m)) (A : vecType n) (B : vecType m),
In p (A ⊗' B) -> exists a b, In a A /\ In b B /\ p = a ⊗ b.
Proof. intros. induction A as [| h].
- simpl in H. easy.
- simpl in H.
apply in_app_or in H; destruct H as [H | H].
* apply in_map_iff in H. destruct H.
exists h, x. split.
simpl. left. easy. destruct H as [H H'].
split. apply H'. rewrite H; reflexivity.
* apply IHA in H. do 2 (destruct H).
exists x, x0.
destruct H as [H1 H2].
split. simpl. right; apply H1.
apply H2.
Qed.
Lemma in_scale : forall {n} (p : Square n) (c : C) (A : vecType n),
In p (c · A) -> exists a, In a A /\ p = c .* a.
Proof. intros. induction A as [| h].
- simpl in H. easy.
- simpl in H.
destruct H as [H | H].
* exists h. split.
left. easy.
rewrite H. reflexivity.
* apply IHA in H. do 2 (destruct H).
exists x. split.
right. apply H.
apply H0.
Qed.
Lemma in_scale_rev : forall {n} (p : Square n) (c : C) (A : vecType n),
In p A -> In (c .* p) (c · A).
Proof. intros. induction A as [| h].
- simpl in H. easy.
- simpl in H.
destruct H as [H0 | H0].
* left. rewrite H0. reflexivity.
* right. apply IHA. apply H0.
Qed.
(******************)
(* Singleton laws *)
(******************)
Definition X' : vecType 2 := [σx].
Definition Z' : vecType 2 := [σz].
Definition I' : vecType 2 := [I 2].
Definition I_n (n : nat) : vecType n := [I n].
Lemma SI : Singleton I'. Proof. easy. Qed.
Lemma SX : Singleton X'. Proof. easy. Qed.
Lemma SZ : Singleton Z'. Proof. easy. Qed.
Lemma SI_n : forall (n : nat), Singleton (I_n n). Proof. easy. Qed.
Lemma S_neg : forall (n : nat) (A : vecType n), Singleton A -> Singleton (neg A).
Proof. intros n A H.
apply singleton_simplify in H.
destruct H; rewrite H.
easy.
Qed.
Lemma S_i : forall (n : nat) (A : vecType n), Singleton A -> Singleton (i A).
Proof. intros n A H.
apply singleton_simplify in H.
destruct H; rewrite H.
easy.
Qed.
Lemma S_mul : forall (n : nat) (A B : vecType n),
Singleton A -> Singleton B -> Singleton (A *' B).
Proof. intros n A B HA HB.
apply singleton_simplify in HA;
apply singleton_simplify in HB;
destruct HA; destruct HB; rewrite H, H0.
easy.
Qed.
Lemma S_tensor : forall (n m : nat) (A : vecType n) (B : vecType m),
Singleton A -> Singleton B -> Singleton (A ⊗' B).
Proof. intros n m A B HA HB.
apply singleton_simplify in HA;
apply singleton_simplify in HB;
destruct HA; destruct HB; rewrite H, H0.
easy.
Qed.
Lemma tensor_nil_r : forall (n m : nat) (A : vecType n), @tensor n m A [] = [].
Proof. induction A as [| h].
- easy.
- simpl. apply IHA.
Qed.
Lemma S_tensor_conv : forall (n m : nat) (A : vecType n) (B : vecType m),
Singleton (A ⊗' B) -> Singleton A /\ Singleton B.
Proof. intros n m A B H.
destruct A. easy.
destruct B. rewrite tensor_nil_r in H. easy.
destruct A. destruct B.
easy. easy. destruct B.
easy. easy.
Qed.
Lemma S_big_tensor : forall (n : nat) (As : list (vecType n)),
(forall a, In a As -> Singleton a) -> Singleton (⨂' As).
Proof. intros. induction As as [| h].
- easy.
- simpl. apply S_tensor.
apply H; left; easy.
apply IHAs.
intros.
apply H; right; apply H0.
Qed.
Lemma S_big_tensor_conv : forall (n : nat) (As : list (vecType n)) (a : vecType n),
Singleton (⨂' As) -> In a As -> Singleton a.
Proof. intros. induction As as [| h].
- easy.
- destruct H0 as [Hh | Ha].
+ simpl in H.
apply S_tensor_conv in H.
rewrite <- Hh; easy.
+ apply IHAs.
simpl in H.
apply S_tensor_conv in H.
easy.
apply Ha.
Qed.
Lemma S_tensor_subset : forall (n : nat) (As Bs : list (vecType n)),
Singleton (⨂' As) -> Bs ⊆ As -> Singleton (⨂' Bs).
Proof. intros.
unfold subset_gen in H0.
apply S_big_tensor.
intros.
apply H0 in H1.
apply (S_big_tensor_conv n As a) in H.
apply H.
apply H1.
Qed.
Hint Resolve SI SX SZ SI_n S_neg S_i S_mul S_tensor : sing_db.
Notation Y' := (i (X' *' Z')).
Lemma SY : Singleton Y'.
Proof. auto with sing_db. Qed.
(****************)
(* Unitary laws *)
(****************)
Definition uni_vecType {n : nat} (vt : vecType n) : Prop :=
forall A, In A vt -> WF_Unitary A.
Lemma uni_vecType_cons : forall {n : nat} (a : Square n) (A : vecType n),
uni_vecType (a :: A) -> WF_Unitary a /\ uni_vecType A.
Proof. intros.
split.
- apply H.
left; easy.
- unfold uni_vecType in *.
intros.
apply H.
right; easy.
Qed.
Lemma univ_I : uni_vecType I'.
Proof. unfold uni_vecType. intros.
apply in_simplify in H; rewrite H.
auto with unit_db.
Qed.
Lemma univ_X : uni_vecType X'.
Proof. unfold uni_vecType. intros.
apply in_simplify in H; rewrite H.
auto with unit_db.
Qed.
Lemma univ_Z : uni_vecType Z'.
Proof. unfold uni_vecType. intros.
apply in_simplify in H; rewrite H.
apply σz_unitary.
Qed.
Lemma univ_I_n : forall (n : nat), uni_vecType (I_n n).
Proof. unfold uni_vecType. intros.
apply in_simplify in H; rewrite H.
auto with unit_db.
Qed.
Lemma univ_neg : forall (n : nat) (A : vecType n), uni_vecType A -> uni_vecType (neg A).
Proof. unfold uni_vecType in *.
intros n A H a H1. unfold neg in H1.
apply in_scale in H1. destruct H1 as [x [H1 H2]].
apply H in H1.
destruct H1 as [H1 H3].
rewrite H2. split; auto with wf_db.
rewrite Mscale_adj.
distribute_scale. rewrite H3.
lma.
Qed.
Lemma univ_i : forall (n : nat) (A : vecType n), uni_vecType A -> uni_vecType (i A).
Proof. unfold uni_vecType in *.
intros n A H a H1. unfold neg in H1.
apply in_scale in H1. destruct H1 as [x [H1 H2]].
apply H in H1.
destruct H1 as [H1 H3].
rewrite H2. split; auto with wf_db.
rewrite Mscale_adj.
distribute_scale. rewrite H3.
lma.
Qed.
Lemma univ_mul : forall (n : nat) (A B : vecType n),
uni_vecType A -> uni_vecType B -> uni_vecType (A *' B).
Proof. unfold uni_vecType in *.
intros n A B HA HB ab Hab.
apply in_mult in Hab.
destruct Hab as [a [b [Ha [Hb Hab]]]].
rewrite Hab.
auto with unit_db.
Qed.
Lemma univ_tensor : forall (n m : nat) (A : vecType n) (B : vecType m),
uni_vecType A -> uni_vecType B -> uni_vecType (A ⊗' B).
Proof. unfold uni_vecType in *.
intros n m A B HA HB ab Hab.
apply in_tensor in Hab.
destruct Hab as [a [b [Ha [Hb Hab]]]].
rewrite Hab.
auto with unit_db.
Qed.
Local Open Scope nat_scope.
(* alternate version that is sometimes necessary *)
Lemma univ_tensor' : forall (n m o : nat) (A : vecType n) (B : vecType m),
n * m = o -> uni_vecType A -> uni_vecType B -> @uni_vecType o (A ⊗' B).
Proof. unfold uni_vecType in *.
intros n m o A B H HA HB ab Hab.
rewrite <- H.
apply in_tensor in Hab.
destruct Hab as [a [b [Ha [Hb Hab]]]].
rewrite Hab.
auto with unit_db.
Qed.
Lemma univ_tensor_list : forall (n : nat) (A : list (vecType n)),
(forall a, In a A -> uni_vecType a) -> uni_vecType (⨂' A).
Proof. intros.
induction A as [| h].
- simpl.
replace [I 1] with (I_n 1) by auto.
apply univ_I_n.
- simpl.
apply univ_tensor.
apply (H h); left; auto.
apply IHA; intros.
apply H; right; auto.
Qed.
Hint Resolve univ_I univ_X univ_Z univ_I_n univ_neg univ_i univ_mul univ_tensor : univ_db.
Lemma univ_Y : uni_vecType Y'.
Proof. auto with univ_db. Qed.
Local Close Scope nat_scope.
(***********************)
(* Multiplication laws *)
(***********************)
(* some helper lemmas *)
Lemma cons_conc : forall (X : Type) (x : X) (ls : list X),
x :: ls = [x] ++ ls.
Proof. reflexivity. Qed.
Lemma mul_sing : forall (n : nat) (a b : Square n),
[a] *' [b] = [a × b].
Proof. reflexivity.
Qed.
Lemma mul_nil_l : forall (n : nat) (A : vecType n), [] *' A = [].
Proof. simpl. reflexivity.
Qed.
Lemma mul_nil_r : forall (n : nat) (A : vecType n), A *' [] = [].
Proof. intros n A. induction A as [| a].
- simpl. reflexivity.
- simpl. apply IHA.
Qed.
Lemma cons_into_mul_l : forall (n : nat) (a : Square n) (A B : vecType n),
(a :: A) *' B = ([a] *' B) ++ (A *' B).
Proof. intros n a A B. simpl.
rewrite <- app_nil_end.
reflexivity.
Qed.
Lemma concat_into_mul_l : forall (n : nat) (A B C : vecType n),
(A ++ B) *' C = (A *' C) ++ (B *' C).
Proof. intros n A B C. induction A as [| a].
- simpl. reflexivity.
- rewrite cons_into_mul_l.
rewrite cons_conc. rewrite app_ass.
rewrite <- cons_conc.
rewrite cons_into_mul_l.
rewrite IHA. rewrite app_ass.
reflexivity.
Qed.
Lemma sing_concat_into_mul_r : forall (n : nat) (a : Square n) (B C : vecType n),
[a] *' (B ++ C) = ([a] *' B) ++ ([a] *' C).
Proof. intros n a B C. simpl.
do 3 (rewrite <- app_nil_end).
rewrite map_app.
reflexivity.
Qed.
Lemma sing_mul_assoc : forall (n : nat) (a b : Square n) (C : vecType n),
[a] *' [b] *' C = [a] *' ([b] *' C).
Proof. intros n a b C. induction C as [| c].
- simpl. reflexivity.
- rewrite (cons_conc _ c C).
rewrite (sing_concat_into_mul_r n b [c] C).
do 2 (rewrite mul_sing).
rewrite (sing_concat_into_mul_r n _ [c] C).
rewrite (sing_concat_into_mul_r n a _ _).
rewrite <- IHC.
do 3 (rewrite mul_sing).
rewrite Mmult_assoc.
reflexivity.
Qed.
Lemma sing_mul_assoc2 : forall (n : nat) (a : Square n) (B C : vecType n),
[a] *' B *' C = [a] *' (B *' C).
Proof. intros n a B C. induction B as [| b].
- simpl. reflexivity.
- rewrite (cons_conc _ b B).
rewrite sing_concat_into_mul_r.
do 2 (rewrite concat_into_mul_l).
rewrite sing_concat_into_mul_r.
rewrite sing_mul_assoc.
rewrite IHB.
reflexivity.
Qed.
Theorem mul_assoc : forall (n : nat) (A B C : vecType n), A *' (B *' C) = A *' B *' C.
Proof. intros n A B C. induction A as [| a].
- simpl. reflexivity.
- rewrite cons_conc.
do 3 (rewrite concat_into_mul_l).
rewrite IHA.
rewrite sing_mul_assoc2.
reflexivity.
Qed.
Lemma mul_I_l : forall (A : vecType 2), uni_vecType A -> I' *' A = A.
Proof. intros A H. unfold I'. induction A as [| a].
- reflexivity.
- rewrite (cons_conc _ a A).
rewrite sing_concat_into_mul_r.
apply uni_vecType_cons in H.
destruct H as [[H _] H0].
rewrite IHA; try easy.
simpl.
rewrite Mmult_1_l; easy.
Qed.
Lemma mul_I_r : forall (A : vecType 2), uni_vecType A -> A *' I' = A.
Proof. intros A H. unfold I'. induction A as [| a].
- reflexivity.
- rewrite cons_into_mul_l.
apply uni_vecType_cons in H.
destruct H as [[H _] H0].
rewrite IHA; try easy.
simpl.
rewrite Mmult_1_r; try easy.
Qed.
Lemma Xsqr : X' *' X' = I'.
Proof. simpl. unfold I. rewrite XtimesXid. reflexivity.
Qed.
Lemma Zsqr : Z' *' Z' = I'.
Proof. simpl. unfold I. rewrite ZtimesZid. reflexivity.
Qed.
Lemma ZmulX : Z' *' X' = - (X' *' Z').
Proof. simpl. assert (H : σz × σx = -1 .* (σx × σz)).
{ lma'. } rewrite H. reflexivity.
Qed.
Lemma scale_1_l : forall (n : nat) (A : vecType n), 1 · A = A.
Proof. intros n A. induction A as [|a].
- reflexivity.
- simpl. rewrite IHA.
rewrite Mscale_1_l.
reflexivity.
Qed.
Lemma scale_assoc : forall (n : nat) (a b : C) (A : vecType n),
a · (b · A) = (a * b) · A.
Proof. intros n a b A. induction A as [| h].
- reflexivity.
- simpl. rewrite IHA.
rewrite Mscale_assoc.
reflexivity.
Qed.
Lemma neg_inv : forall (n : nat) (A : vecType n), - - A = A.
Proof. intros n A. unfold neg.
rewrite scale_assoc.
assert (H: -1 * -1 = 1). { lca. }
rewrite H. rewrite scale_1_l.
reflexivity.
Qed.
Lemma concat_into_scale : forall (n : nat) (c : C) (A B : vecType n),
c · (A ++ B) = (c · A) ++ (c · B).
Proof. intros n c A B.
unfold scale.
rewrite map_app.
reflexivity.
Qed.
Lemma scale_sing : forall (n : nat) (c : C) (a : Square n),
c · [a] = [c .* a].
Proof. reflexivity.
Qed.
Lemma sing_scale_dist_l : forall (n : nat) (c : C) (a : Square n) (B : vecType n),
(c · [a]) *' B = c · ([a] *' B).
Proof. intros n c a B. induction B as [|b].
- reflexivity.
- rewrite (cons_conc _ b B).
rewrite sing_concat_into_mul_r.
rewrite concat_into_scale.
rewrite scale_sing.
rewrite sing_concat_into_mul_r.
rewrite <- IHB. rewrite scale_sing.
do 2 (rewrite mul_sing).
rewrite scale_sing.
rewrite Mscale_mult_dist_l.
reflexivity.
Qed.
Lemma scale_dist_l : forall (n : nat) (c : C) (A B : vecType n), (c · A) *' B = c · (A *' B).
Proof. intros n c A B. induction A as [|a].
- reflexivity.
- rewrite cons_into_mul_l. rewrite cons_conc.
do 2 (rewrite concat_into_scale).
rewrite concat_into_mul_l.
rewrite IHA. rewrite sing_scale_dist_l.
reflexivity.
Qed.
(* note that this is slightly different than what we would expect. *)
(* scaling is on right, but singleton is still left list *)
Lemma sing_scale_dist_r : forall (n : nat) (c : C) (a : Square n) (B : vecType n),
[a] *' (c · B) = c · ([a] *' B).
Proof. intros n c a B. induction B as [| b].
- reflexivity.
- rewrite (cons_conc _ b B).
rewrite sing_concat_into_mul_r.
do 2 (rewrite concat_into_scale).
rewrite sing_concat_into_mul_r.
rewrite IHB.
rewrite scale_sing.
do 2 (rewrite mul_sing).
rewrite scale_sing.
rewrite Mscale_mult_dist_r.
reflexivity.
Qed.
Lemma scale_dist_r : forall (n : nat) (c : C) (A B : vecType n), A *' (c · B) = c · (A *' B).
Proof. intros n c A B. induction A as [|a].
- reflexivity.
- rewrite cons_into_mul_l.
rewrite (cons_into_mul_l n a A B).
rewrite concat_into_scale.
rewrite IHA.
rewrite sing_scale_dist_r.
reflexivity.
Qed.
Lemma neg_dist_l : forall (n : nat) (A B : vecType n), -A *' B = - (A *' B).
Proof. intros n A B.
unfold neg.
rewrite scale_dist_l. reflexivity.
Qed.
Lemma neg_dist_r : forall (n : nat) (A B : vecType n), A *' -B = - (A *' B).
Proof. intros n A B.
unfold neg.
rewrite scale_dist_r. reflexivity.
Qed.
Lemma i_sqr : forall (n : nat) (A : vecType n), i (i A) = -A.
Proof. intros n A. unfold neg. unfold i.
rewrite scale_assoc.
assert (H: Ci * Ci = -1). { lca. }
rewrite H.
reflexivity.
Qed.
Lemma i_dist_l : forall (n : nat) (A B : vecType n), i A *' B = i (A *' B).
Proof. intros n A B.
unfold i.
rewrite scale_dist_l. reflexivity.
Qed.
Lemma i_dist_r : forall (n : nat) (A B : vecType n), A *' i B = i (A *' B).
Proof. intros n A B.
unfold i.
rewrite scale_dist_r. reflexivity.
Qed.
Lemma i_neg_comm : forall (n : nat) (A : vecType n), i (-A) = -i A.
Proof. intros n A. unfold neg; unfold i.
do 2 (rewrite scale_assoc).
assert (H: Ci * -1 = -1 * Ci).
{ lca. } rewrite H. reflexivity.
Qed.
Hint Rewrite mul_sing mul_nil_r mul_I_l mul_I_r Xsqr Zsqr ZmulX neg_inv scale_dist_l scale_dist_r neg_dist_l neg_dist_r i_sqr i_dist_l i_dist_r i_neg_comm : mul_db.
(***************)
(* Tensor Laws *)
(***************)
Lemma tensor_1_l : forall (n : nat) (A : vecType n),
uni_vecType A -> [I 1] ⊗' A = A.
Proof. intros. induction A as [| h].
- easy.
- simpl in *.
apply uni_vecType_cons in H.
destruct H as [[H _] H0].
rewrite kron_1_l; try easy.
rewrite IHA; try easy.
Qed.
Lemma big_tensor_1_l : forall (n m : nat) (A : vecType n),
uni_vecType A -> (@big_tensor m []) ⊗' A = A.
Proof. intros.
assert (H' : forall m, (@big_tensor m []) = [I 1]).
{ easy. }
rewrite H'.
apply tensor_1_l.
easy.
Qed.
(* basically, we need the same helper lemmas for tensoring *)
(* should all WF conditions, but I will assume all gates are well formed *)
Lemma tensor_sing : forall (m n : nat) (a : Square n) (b : Square m),
[a] ⊗' [b] = [a ⊗ b].
Proof. reflexivity.
Qed.
Lemma cons_into_tensor_l : forall (m n : nat) (a : Square n) (A : vecType n) (B : vecType m),
(a :: A) ⊗' B = ([a] ⊗' B) ++ (A ⊗' B).
Proof. intros m n a A B. simpl.
rewrite <- app_nil_end.
reflexivity.
Qed.
Lemma concat_into_tensor_l : forall (m n : nat) (A B : vecType n) (C : vecType m),
(A ++ B) ⊗' C = (A ⊗' C) ++ (B ⊗' C).
Proof. intros m n A B C. induction A as [| a].
- simpl. reflexivity.
- rewrite cons_into_tensor_l.
rewrite cons_conc. rewrite app_ass.
rewrite <- cons_conc.
rewrite cons_into_tensor_l.
rewrite IHA. rewrite app_ass.
reflexivity.
Qed.
Lemma sing_concat_into_tensor_r : forall (m n : nat) (a : Square m) (B C : vecType n),
[a] ⊗' (B ++ C) = ([a] ⊗' B) ++ ([a] ⊗' C).
Proof. intros m n a B C. simpl.
do 3 (rewrite <- app_nil_end).
rewrite map_app.
reflexivity.
Qed.
Lemma sing_tensor_assoc : forall (m n o : nat) (a : Square m) (b : Square n) (C : vecType o),
WF_Matrix a -> WF_Matrix b -> uni_vecType C ->
([a] ⊗' [b]) ⊗' C = [a] ⊗' ([b] ⊗' C).
Proof. intros m n o a b C H H0 H1. induction C as [| c].
- simpl. reflexivity.
- rewrite (cons_conc _ c C).
apply uni_vecType_cons in H1.
destruct H1 as [H1 H2].
rewrite (sing_concat_into_tensor_r n o b [c] C).
do 2 (rewrite tensor_sing).
rewrite (sing_concat_into_tensor_r _ o _ [c] C).
rewrite (sing_concat_into_tensor_r _ _ a _ _).
rewrite <- IHC; auto.
do 3 (rewrite tensor_sing).
rewrite kron_assoc; auto.
destruct H1; auto.
Qed.
Lemma sing_tensor_assoc2 : forall (m n o: nat) (a : Square m) (B : vecType n) (C : vecType o),
WF_Matrix a -> uni_vecType B -> uni_vecType C ->
([a] ⊗' B) ⊗' C = [a] ⊗' (B ⊗' C).
Proof. intros m n o a B C H H0 H1. induction B as [| b].
- simpl. reflexivity.
- rewrite (cons_conc _ b B).
apply uni_vecType_cons in H0.
destruct H0 as [[H0 _] H2].
rewrite sing_concat_into_tensor_r.
do 2 (rewrite concat_into_tensor_l).
rewrite sing_concat_into_tensor_r.
rewrite sing_tensor_assoc; auto.
rewrite IHB; auto.
Qed.
Theorem tensor_assoc : forall (m n o: nat) (A : vecType m) (B : vecType n) (C : vecType o),
uni_vecType A -> uni_vecType B -> uni_vecType C ->
A ⊗' (B ⊗' C) = (A ⊗' B) ⊗' C.
Proof. intros m n o A B C H H0 H1. induction A as [| a].
- simpl. reflexivity.
- rewrite cons_conc.
apply uni_vecType_cons in H.
destruct H as [[H _] H2].
do 3 (rewrite concat_into_tensor_l); auto.
rewrite IHA; auto.
rewrite sing_tensor_assoc2; auto.
Qed.
Lemma sing_scale_tensor_dist_l : forall (n m : nat) (c : C) (a : Square n) (B : vecType m),
(c · [a]) ⊗' B = c · ([a] ⊗' B).
Proof. intros n m c a B. induction B as [|b].
- reflexivity.
- rewrite (cons_conc _ b B).
rewrite sing_concat_into_tensor_r.
rewrite concat_into_scale.
rewrite scale_sing.
rewrite sing_concat_into_tensor_r.
rewrite <- IHB. rewrite scale_sing.
do 2 (rewrite tensor_sing).
rewrite scale_sing.
rewrite Mscale_kron_dist_l.
reflexivity.
Qed.
Lemma scale_tensor_dist_l : forall (n m : nat) (c : C) (A : vecType n) (B : vecType m),
(c · A) ⊗' B = c · (A ⊗' B).
Proof. intros n m c A B. induction A as [|a].
- reflexivity.
- rewrite cons_into_tensor_l. rewrite cons_conc.
do 2 (rewrite concat_into_scale).
rewrite concat_into_tensor_l.
rewrite IHA. rewrite sing_scale_tensor_dist_l.
reflexivity.
Qed.
(* note that this is slightly different than what we would expect. *)
(* scaling is on right, but singleton is still left list *)
Lemma sing_scale_tensor_dist_r : forall (m n : nat) (c : C) (a : Square n) (B : vecType m),
[a] ⊗' (c · B) = c · ([a] ⊗' B).
Proof. intros m n c a B. induction B as [| b].
- reflexivity.
- rewrite (cons_conc _ b B).
rewrite sing_concat_into_tensor_r.
do 2 (rewrite concat_into_scale).
rewrite sing_concat_into_tensor_r.
rewrite IHB.
rewrite scale_sing.
do 2 (rewrite tensor_sing).
rewrite scale_sing.
rewrite Mscale_kron_dist_r.
reflexivity.
Qed.
Lemma scale_tensor_dist_r : forall (m n : nat) (c : C) (A : vecType n) (B : vecType m),
A ⊗' (c · B) = c · (A ⊗' B).
Proof. intros m n c A B. induction A as [|a].
- reflexivity.
- rewrite cons_into_tensor_l.
rewrite (cons_into_tensor_l m n a A B).
rewrite concat_into_scale.
rewrite IHA.
rewrite sing_scale_tensor_dist_r.
reflexivity.
Qed.
Lemma neg_tensor_dist_l : forall (m n : nat) (A : vecType n) (B : vecType m),
-A ⊗' B = - (A ⊗' B).
Proof. intros m n A B. unfold neg.
rewrite scale_tensor_dist_l.
reflexivity.
Qed.
Lemma neg_tensor_dist_r : forall (m n : nat) (A : vecType n) (B : vecType m),
A ⊗' -B = - (A ⊗' B).
Proof. intros m n A B. unfold neg.
rewrite scale_tensor_dist_r.
reflexivity.
Qed.
Lemma i_tensor_dist_l : forall (m n : nat) (A : vecType n) (B : vecType m),
i A ⊗' B = i (A ⊗' B).
Proof. intros m n A B. unfold i.
rewrite scale_tensor_dist_l.
reflexivity.
Qed.
Lemma i_tensor_dist_r : forall (m n : nat) (A : vecType n) (B : vecType m),
A ⊗' i B = i (A ⊗' B).
Proof. intros m n A B. unfold i.
rewrite scale_tensor_dist_r.
reflexivity.
Qed.
Hint Rewrite concat_into_tensor_l scale_tensor_dist_r scale_tensor_dist_l neg_tensor_dist_l neg_tensor_dist_r i_tensor_dist_l i_tensor_dist_r : tensor_db.
(********************************)
(* Multiplication & Tensor Laws *)
(********************************)
Lemma mul_tensor_dist_sing : forall (m n : nat)
(a : Square m) (b : Square n) (c : Square m) (D : vecType n),
([a] ⊗' [b]) *' ([c] ⊗' D) = ([a] *' [c]) ⊗' ([b] *' D).
Proof. intros m n a b c D. induction D as [| d].
- reflexivity.
- rewrite (cons_conc _ d D).
rewrite sing_concat_into_tensor_r, sing_concat_into_mul_r.
rewrite mul_sing, tensor_sing.
rewrite sing_concat_into_tensor_r.
rewrite sing_concat_into_mul_r.
rewrite <- mul_sing. rewrite <- tensor_sing.
assert (H: ([a] ⊗' [b]) *' ([c] ⊗' [d]) = [a] *' [c] ⊗' [b] *' [d]).
{ simpl. rewrite kron_mixed_product. reflexivity. }
rewrite H, IHD.
reflexivity.
Qed.
Lemma mul_tensor_dist_sing2 : forall (m n : nat)
(a : Square m) (B : vecType n) (c : Square m) (D : vecType n),
([a] ⊗' B) *' ([c] ⊗' D) = ([a] *' [c]) ⊗' (B *' D).
Proof. intros m n a B c D. induction B as [| b].
- reflexivity.
- rewrite (cons_conc _ b B).
rewrite sing_concat_into_tensor_r.
rewrite concat_into_mul_l.
rewrite concat_into_mul_l.
rewrite mul_sing.
rewrite sing_concat_into_tensor_r.
rewrite <- mul_sing.
rewrite IHB, mul_tensor_dist_sing.
reflexivity.
Qed.
Lemma mul_tensor_dist : forall (m n : nat)