-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmatrix_lemmas.lean
1703 lines (1436 loc) · 40.1 KB
/
matrix_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 matrix
import matrix_inner_product
import common_lemmas
import linear_algebra.nonsingular_inverse
open_locale big_operators
open matrix
open Matrix
------------------------------------------------------------------------------
-- ℝ lemmas
lemma real.lt_of_lt_pow_two {a b : ℝ} : a^2 < b^2 → 0 ≤ a → 0 ≤ b → a < b
:= begin
intros h an bn,
rw <- real.sqrt_mul_self an,
rw <- real.sqrt_mul_self bn,
iterate 2 { rw pow_two at h },
apply (real.sqrt_lt _).mpr, assumption,
rw <- pow_two; apply pow_two_nonneg,
end
lemma real.add_squares_le_square_add (x y : ℝ): 0 ≤ x → 0 ≤ y → x^2 + y^2 ≤ (x + y)^2
:= begin
intros xn yn,
repeat { rw pow_two },
repeat { rw mul_add },
repeat { rw add_mul },
have f1: x * x + y * x + (x * y + y * y) = (x * x + y * y) + (x * y + y * x), {
ring,
},
rw f1,
simp [add_nonneg, mul_nonneg, *],
end
------------------------------------------------------------------------------
-- (pure) ℂ lemmas
@[simp]
lemma complex.abs_nonneg' (c : ℂ) : 0 ≤ c.abs := by apply complex.abs_nonneg
@[simp]
lemma complex.norm_sq_nonneg' (c : ℂ) : 0 ≤ complex.norm_sq c := by apply complex.norm_sq_nonneg
@[simp]
lemma complex.conj_mul (c : ℂ) : c.conj * c = c.norm_sq
:= begin
rw mul_comm,
apply complex.mul_conj,
end
@[simp]
lemma complex.conj_mul' (c : ℂ) : c * c.conj = c.norm_sq
:= begin
apply complex.mul_conj,
end
lemma complex.re_div_eq_div_re (a b : ℂ) : a.im = 0 → b.im = 0 → (a / b).re = a.re / b.re
:= begin
intros ap bp,
have f1: a = a.re, {
cases a,
cases b,
cases ap,
cases bp,
simp at *,
refl,
},
have f2: b = b.re, {
cases a,
cases b,
cases ap,
cases bp,
simp at *,
refl,
},
have f3: (a / b) = (a.re / b.re), {
rw f1,
rw f2,
simp,
},
rw f3,
norm_cast,
end
lemma complex.re_add_eq_add_re (a b : ℂ) : (a + b).re = a.re + b.re
:= begin
exact rfl,
end
----------------------------------------------------------------------------------------
-- ℂ + is_R_or_C
lemma complex.mul_conj_abs_square (c : ℂ) : (c†) * c = |c| ^ 2
:= begin
simp,
apply_mod_cast complex.norm_sq_eq_abs,
end
lemma complex.abs_of_real' (x : ℝ) : |x| = |(x : ℂ)|
:= begin
refl,
end
lemma complex.re_conj_eq_re (c : ℂ): (c†).re = c.re
:= begin
refl,
end
lemma complex.conj_sum_dist {n} (f : fin n → ℂ)
: (∑ k, (f k)†) = (∑ k, (f k))†
:= begin
exact finset.univ.sum_hom complex.conj,
end
@[simp]
lemma complex.norm_sq_eq_mul_abs (c : ℂ) : |c| * |c| = c.norm_sq
:= begin
rw complex.norm_sq_eq_abs,
rw pow_two, simp,
end
----------------------------------------------------------------------------------------
-- matrix type-cast helpers
section matrix_cast
variables {α : Type} [semiring α]
variables {m n : Type} [fintype m] [fintype n]
variables {m' n' : Type} [fintype m'] [fintype n']
variables (s : α) (M : matrix m n α) (N : matrix m n α)
lemma matrix_congr (h1: m = m') (h2: n = n') : matrix m n α = matrix m' n' α
:= begin
congr; assumption,
end
lemma push_cast_matrix_smul (h1: m = m') (h2: n = n')
: cast (matrix_congr h1 h2) (s • M) = s • (cast (matrix_congr h1 h2) M)
:= begin
apply cast_eq_of_heq,
tactic.unfreeze_local_instances,
cases h1,
cases h2,
congr' 1; try {assumption},
end
lemma push_cast_matrix_add (h1: m = m') (h2: n = n')
: cast (matrix_congr h1 h2) (M + N) = (cast (matrix_congr h1 h2) M) + (cast (matrix_congr h1 h2) N)
:= begin
apply cast_eq_of_heq,
tactic.unfreeze_local_instances,
cases h1,
cases h2,
congr; try {assumption},
end
end matrix_cast
section matrix_cast_apply
variables {α : Type}
variables {m n m' n': Type} [fintype m] [fintype n] [fintype m'] [fintype n']
variables (A : matrix m n α) (B : matrix m' n' α)
lemma A_eq (m_eq: m = m') (n_eq: n = n') : matrix m n α = matrix m' n' α
:= begin
congr; assumption,
end
-- for easier pattern matching with matrix
lemma matrix_cast_apply (m_eq: m = m') (n_eq: n = n') (i' : m') (j' : n')
: (cast (A_eq m_eq n_eq) A) i' j' = A (cast m_eq.symm i') (cast n_eq.symm j')
:= begin
apply cast_apply2,
end
end matrix_cast_apply
----------------------------------------------------------------------------------------
-- Matrix lemmas
section matrix
variables {m n o : ℕ}
variables {A : Matrix m n} {B : Matrix n o}
variables {s : Vector n}
@[simp]
lemma Matrix_zero_neq_one {n} : 0 ≠ (I (n+1))
:= begin
intro h,
have c3: (1 : ℂ) = 0, {
calc (1 : ℂ) = (I (n+1)) 0 0 : by simp
... = (0 : Square (n+1)) 0 0 : by {rw h}
... = 0 : by simp,
},
have c4: (1 : ℝ) = 0, {
apply_mod_cast c3,
},
linarith,
end
lemma Matrix_nonzero_has_nonzero_val : A ≠ 0 → (∃ i j, A i j ≠ 0)
:= begin
contrapose!, intros h,
apply matrix.ext, intros i j,
apply h,
end
lemma Vector_nonzero_has_nonzero_val : s ≠ 0 → (∃ i, s i 0 ≠ 0)
:= begin
contrapose!, intros h,
apply matrix.ext, intros i j,
have j0 : j = 0, cases j, simp, cases j0, clear j0, simp,
apply h,
end
-- Special case of 1 × 1 matrix.
lemma matrix_mul_cancel_left_square_one {n} {x : Vector n} {y z : Square 1} : x ⬝ y = x ⬝ z → x ≠ 0 → y = z
:= begin
intros h xn,
apply matrix.ext, intros i j,
rw <- matrix.ext_iff at h,
cases (Vector_nonzero_has_nonzero_val xn) with k kp,
specialize h k j,
iterate 2 {
rw matrix.mul_apply at h,
rw finset.sum_fin_eq_sum_range at h,
rw finset.sum_range_one at h,
rw dif_pos at h; try {solve1 {linarith}}, simp at h,
},
have i0 : i = 0, cases i; simp, cases i0; clear i0,
have j0 : j = 0, cases j; simp, cases j0; clear j0,
simp at *,
cases h, {
assumption,
}, {
exfalso,
apply kp; assumption,
}
end
-- Special case of 1 × 1 matrix.
lemma matrix_mul_square_one {x y : Square 1} {i j : fin 1}: (x ⬝ y) i j = x i j * y i j
:= begin
unfold matrix.mul matrix.dot_product,
have i0 : i = 0, cases i; simp, cases i0; clear i0,
have j0 : j = 0, cases j; simp, cases j0; clear j0,
rw finset.sum_fin_eq_sum_range,
rw finset.sum_range_one,
rw dif_pos; simp,
end
-- Special case of 1 × 1 matrix.
lemma matrix_mul_comm_square_one {x y : Square 1} : x ⬝ y = y ⬝ x
:= begin
apply matrix.ext, intros i j,
iterate 2 { rw matrix_mul_square_one },
ring,
end
-- Special case of 1 × 1 matrix.
@[simp]
lemma id_one_apply {x y : fin 1} : (I 1) x y = 1
:= begin
have xp: x = 0, by simp,
have yp: y = 0, by simp,
cases xp,
cases yp,
simp,
end
-- Slightly relaxed version of matrix.smul_apply for easier matching.
-- Note the scalar type is ℝ, not ℂ.
lemma Matrix.real_smul_apply {a : ℝ} {i : fin m} {j : fin n}
: (a • A) i j = a * A i j := rfl
-- Slightly relaxed version of matrix.mul_smul for easier matching.
-- Note the scalar type is ℝ, not ℂ.
lemma Matrix.mul_real_smul {a : ℝ} : A ⬝ (a • B) = a • (A ⬝ B)
:= by {apply matrix.mul_smul,}
end matrix
----------------------------------------------------------------------------------------
-- adjoint lemmas
@[simp]
theorem adjoint_zero {m n} : (0 : Matrix m n)† = 0
:= begin
apply matrix.ext, intros i j,
unfold adjoint, simp,
end
@[simp]
theorem adjoint_one {n} : (1 : Matrix n n)† = 1
:= begin
apply matrix.ext,
intros i j,
unfold adjoint,
by_cases i = j, {
simp [h],
}, {
rw matrix.one_apply_ne h,
have h' : ¬ j = i, {
cc,
},
rw matrix.one_apply_ne h',
simp,
}
end
section adjoint
variables {m n : ℕ}
variables (x y : Matrix m n)
@[simp]
theorem adjoint_involutive : x†† = x
:= begin
apply matrix.ext,
intros i j,
unfold adjoint,
simp,
end
theorem adjoint_inj : (x†) = (y†) → x = y
:= begin
intros h,
apply matrix.ext, intros i j,
rw <- matrix.ext_iff at h,
specialize h j i,
unfold adjoint at h,
apply complex.conj_inj.mp h,
end
lemma adjoint_add : ((x + y)†) = (x†) + (y†)
:= begin
apply matrix.ext, intros i j, simp,
unfold adjoint, simp,
end
lemma adjoint_neg (x : Matrix m n): (-x)† = -(x†)
:= begin
apply matrix.ext, intros i j,
simp, unfold adjoint, simp,
end
lemma adjoint_smul (s : ℂ) : (s • x)† = (s†) • (x†)
:= begin
apply matrix.ext, intros i j,
unfold has_scalar.smul,
unfold adjoint,
simp,
end
lemma adjoint_apply (x : Matrix m n) (i : fin n) (j : fin m) : (x†) i j = ((x j i)†)
:= begin
unfold adjoint,
end
end adjoint
---------------------------------------------------------------------------------------------
-- Adjoint + mul lemmas
section adjoint_mul
variables {m n o : ℕ}
variable (A : Matrix m n)
variable (B : Matrix n o)
lemma conj_mul_eq_dot_product (i : fin m) (j : fin o)
: ((A ⬝ B) i j)† = dot_product (λ k, (B k j)†)
(λ k, (A i k)†)
:= begin
unfold matrix.dot_product,
unfold matrix.mul,
unfold matrix.dot_product,
rw <- complex.conj_sum_dist, {
congr,
refine funext _,
intro k,
simp,
ring,
},
end
theorem adjoint_mul : (A ⬝ B)† = (B†) ⬝ (A†)
:= begin
apply matrix.ext,
intros j i,
apply conj_mul_eq_dot_product,
end
end adjoint_mul
----------------------------------------------------------------------------------------
-- Vector + adjoint lemmas
section vector_adjoint
variables {n : ℕ} (s : Vector n)
lemma dot_adjoint_eq_sum_mul_conj
: dot_product (s† 0) (λ j, s j 0)
= ∑ j, ((s j 0)†) * (s j 0)
:= begin
congr,
end
lemma dot_adjoint_eq_sum_squre
: dot_product (s† 0) (λ j, s j 0)
= ∑ j, |s j 0| ^ 2
:= begin
rw dot_adjoint_eq_sum_mul_conj,
congr,
apply funext,
intros x,
apply complex.mul_conj_abs_square,
end
example : (((s†) ⬝ s) 0 0) = ((∑ i, |s i 0| ^ 2) : ℂ)
:= begin
apply dot_adjoint_eq_sum_squre,
end
@[simp]
lemma sum_square_one_if_mul_adjoint_one : ((s†) ⬝ s) = 1 → (∑ i, |s i 0| ^ 2) = 1
:= begin
intros h,
unfold matrix.mul at h,
rw <- matrix.ext_iff at h,
specialize h 0 0,
rw dot_adjoint_eq_sum_squre at h,
simp at h,
apply_mod_cast h,
end
lemma mul_adjoint_one_if_sum_square_one : (∑ i, |s i 0| ^ 2) = 1 → ((s†) ⬝ s) = 1
:= begin
intros h,
apply matrix.ext,
intros i j,
have i_eq : i = 0, {
cases i with i ip; simp,
},
have j_eq : j = 0, {
cases i with i ip; simp,
},
cases i_eq,
cases j_eq,
simp,
unfold matrix.mul,
rw dot_adjoint_eq_sum_squre,
apply_mod_cast h,
end
end vector_adjoint
----------------------------------------------------------------------------------------
-- unit lemmas
lemma unfold_unit {n} {s : Vector n} : s.unit -> (s†) ⬝ s = 1 := by {tautology}
lemma unit_nonzero {n : ℕ} {s : Vector n} : s.unit → s ≠ 0
:= begin
contrapose!, intros h c,
rw <- matrix.ext_iff at h, simp at h,
unfold matrix.unit at c,
rw <- matrix.ext_iff at c,
specialize (c 0 0),
unfold matrix.mul matrix.dot_product at c, simp at c,
have h1: ∑ (i : fin n), s† 0 i * s i 0 = 0, {
apply finset.sum_eq_zero, intros i ip,
rw h, simp,
},
have c2: (0 : ℂ) = 1, {
rw <- h1,
rw <- c,
},
norm_num at c2,
end
----------------------------------------------------------------------------------------
-- std_basis lemmas
section std_basis
variables {m : Type*} [fintype m]
variables [decidable_eq m]
@[simp]
lemma std_basis_eq_zero {n : m} : ∀ {j i}, ¬ j = n → std_basis n j i = 0
:= begin
intros j i h,
unfold std_basis,
exact if_neg h,
end
@[simp]
lemma std_basis_eq_one {n : m} : ∀ {j i}, j = n → std_basis n j i = 1
:= begin
intros j i h,
rw h,
unfold std_basis,
simp,
end
variables {n : ℕ} {i j : fin n}
@[simp]
theorem std_basis_unit : (std_basis i).unit
:= begin
apply mul_adjoint_one_if_sum_square_one,
rw finset.sum_eq_single i, {
simp,
}, {
intros b bp h,
rw std_basis_eq_zero h; simp,
}, {
intro h,
exfalso,
apply h; simp,
}
end
@[simp]
lemma std_basis_adjoint_apply {s : fin n} : ∀ x, ((std_basis s)†) x i = (std_basis s) i x
:= begin
unfold Matrix.adjoint,
intros x,
by_cases c : i = s, {
rw std_basis_eq_one c, simp,
}, {
rw std_basis_eq_zero c, simp,
}
end
@[simp]
lemma std_basis_inner_product : ((std_basis i)†) ⬝ (std_basis i) = 1
:= begin
apply std_basis_unit,
end
lemma std_basis_inner_product_eq_zero : ¬ i = j → ((std_basis i)†) ⬝ (std_basis j) = 0
:= begin
intros h,
apply matrix.ext, intros v w,
unfold matrix.mul matrix.dot_product Matrix.adjoint,
have v0 : v = 0, by simp,
have w0 : w = 0, by simp,
rw v0, rw w0, simp,
rw finset.sum_eq_single i; simp [std_basis_eq_zero h],
intros b h',
left,
rw std_basis_eq_zero h',
end
@[simp]
lemma inner_product_std_basis_cancel_left {s : Vector n}
: ((std_basis i)† ⬝ s) 0 0 = s i 0
:= begin
unfold matrix.mul adjoint std_basis,
unfold matrix.dot_product,
rw finset.sum_eq_single i; simp; cc,
end
@[simp]
lemma adjoint_inner_product_std_basis_cancel_left {s : Vector n}
: ((std_basis i)† ⬝ s)† 0 0 = (s i 0)†
:= begin
unfold matrix.mul adjoint std_basis,
unfold matrix.dot_product,
rw finset.sum_eq_single i; simp; cc,
end
end std_basis
----------------------------------------------------------------------------------------
-- lemmas about matrix_std_basis from mathlib
section matrix_std_basis
variables {m n: Type*} [fintype m] [fintype n]
variables [decidable_eq m] [decidable_eq n]
variables {α : Type} [semiring α]
@[simp]
lemma std_basis_matrix_eq_given {i' : m} {j' : n} {v : α}
: ∀ {i j}, i = i' ∧ j = j' → std_basis_matrix i' j' v i j = v
:= begin
intros i j h,
cases h with h1 h2,
rw h1,
rw h2,
unfold std_basis_matrix,
simp,
end
lemma std_basis_matrix_eq_zero {i' : m} {j' : n} {v : α}
: ∀ {i j}, ¬ i = i' ∨ ¬ j = j' → std_basis_matrix i' j' v i j = 0
:= begin
intros i j h,
unfold std_basis_matrix,
rwa if_neg,
by_contradiction c,
cases c with c1 c2,
cases h, {
apply h; assumption,
}, {
apply h; assumption,
}
end
lemma std_basis_eq_std_basis_matrix {n : m}
: std_basis n = matrix.std_basis_matrix n 0 1
:= begin
apply matrix.ext,
intros i j,
have jp : j = 0, {
cases j with j jp,
simp,
},
cases jp,
simp,
by_cases i = n, {
cases h,
simp,
}, {
rw std_basis_eq_zero h,
rw std_basis_matrix_eq_zero,
left, assumption,
}
end
end matrix_std_basis
----------------------------------------------------------------------------------------
-- state vector decomposition into standard basis vectors
theorem Vector_decomposition {n} (s : Vector n) : s = ∑ i, s i 0 • std_basis i
:= begin
apply matrix.ext,
intros i j,
cases j with j jp,
have jeq: j = 0, {
linarith,
},
cases jeq,
simp,
rw finset.sum_eq_single i, {
simp,
}, {
intros b bp h,
rw std_basis_eq_zero h.symm; simp,
}, {
intros c,
exfalso,
apply c; simp,
}
end
------------------------------------------------------------------------------
-- kron_loc lemmas
section kron_loc
variables {n m : ℕ}
@[simp]
lemma kron_loc_composition (x : fin (n*m)): kron_loc (kron_div x) (kron_mod x) = x
:= begin
unfold kron_div kron_mod kron_loc,
cases x with x xp,
simp,
have f1: 0 < m, {
cases m, {
exfalso,
simp at xp,
assumption,
}, {
simp,
}
},
symmetry,
apply nat_decompose_mul_add, assumption,
end
@[simp]
lemma kron_div_kron_loc {k : fin n} {j : fin m} : kron_div (kron_loc k j) = k
:= begin
unfold kron_div kron_loc, simp,
cases k with k kp,
cases j with j jp,
simp,
rw nat_add_mul_left_div_left, {
rw nat.div_eq_zero; simp *,
}, {
linarith,
}
end
@[simp]
lemma kron_mod_kron_loc {k : fin n} {j : fin m} : kron_mod (kron_loc k j) = j
:= begin
unfold kron_mod kron_loc, simp,
cases k with k kp,
cases j with j jp,
simp,
rw nat_add_mul_left_mod_left, {
rw nat.mod_eq_of_lt; assumption,
}
end
lemma kron_loc_inj (a b : fin n) (c d : fin m) : kron_loc a c = kron_loc b d → a = b ∧ c = d
:= begin
intros h,
cases a with a ap,
cases b with b bp,
cases c with c cp,
cases d with d dp,
simp,
unfold kron_loc at h, simp at h,
apply add_mul_congr; try {assumption},
end
lemma kron_loc_inj_iff (a b : fin n) (c d : fin m) : kron_loc a c = kron_loc b d ↔ a = b ∧ c = d
:= begin
split, {
apply kron_loc_inj,
}, {
intros h, rcases h with ⟨h1, h2⟩,
cases h1, cases h2, clear h1 h2, refl,
}
end
end kron_loc
---------------------------------------------------------------------------------------------
-- kron lemmas
section kron
variables {m n p q : ℕ}
variables (A : Matrix m n) (B : Matrix p q)
theorem adjoint_kron : (A ⊗ B)† = (A†) ⊗ (B†)
:= begin
apply matrix.ext,
intros j i,
unfold kron,
unfold Matrix.adjoint,
simp,
end
theorem mul_to_kron (r : fin m) (s : fin n) (v : fin p) (w : fin q)
: A r s * B v w = (A ⊗ B) (kron_loc r v) (kron_loc s w)
:= begin
unfold kron,
unfold kron_loc,
unfold kron_div kron_mod,
cases r with r hr,
cases s with s hs,
cases v with v hv,
cases w with w hw,
simp,
congr, {
rw nat_add_mul_left_div_left,
rw nat.div_eq_of_lt hv; refl,
linarith,
}, {
rw nat_add_mul_left_div_left,
rw nat.div_eq_of_lt hw; refl,
linarith,
}, {
rw nat_add_mul_left_mod_left,
rw nat.mod_eq_of_lt hv,
}, {
rw nat_add_mul_left_mod_left,
rw nat.mod_eq_of_lt hw,
}
end
theorem kron_ext_mul (M : Matrix (m*p) (n*q))
: (∀ (r : fin m) (s : fin n) (v : fin p) (w : fin q)
, A r s * B v w = M (kron_loc r v) (kron_loc s w))
→ A ⊗ B = M
:= begin
intro h,
rw <- matrix.ext_iff,
intros x y,
unfold kron,
rw h,
unfold kron_loc,
unfold kron_div kron_mod,
simp,
congr, {
cases x with x hx,
simp,
rw add_comm,
apply nat.mod_add_div,
}, {
cases y with y hy,
simp,
rw add_comm,
apply nat.mod_add_div,
}
end
theorem kron_ext_mul_iff {M : Matrix (m*p) (n*q)}
: A ⊗ B = M
↔ (∀ (r : fin m) (s : fin n) (v : fin p) (w : fin q)
, A r s * B v w = M (kron_loc r v) (kron_loc s w))
:= begin
split, intros h, {
intros, rw mul_to_kron, rw h,
}, {
apply kron_ext_mul,
}
end
@[simp]
lemma kron_zero_left {p q m n} {x : Matrix m n} : (0 : Matrix p q) ⊗ x = 0
:= begin
apply kron_ext_mul, intros r s v w, simp,
end
@[simp]
lemma kron_zero_right {p q m n} {x : Matrix m n} : x ⊗ (0 : Matrix p q) = 0
:= begin
apply kron_ext_mul, intros r s v w, simp,
end
theorem kron_id : (I m) ⊗ (I n) = I (m * n)
:= begin
apply kron_ext_mul,
intros r s v w,
by_cases h1: r = s, {
rw <- h1,
clear h1,
by_cases h2: v = w, {
rw <- h2,
clear h2,
simp,
}, {
have f1: (I n) v w = 0, {
apply if_neg, exact h2,
},
rw f1,
simp,
have f2: (kron_loc r v) ≠ (kron_loc r w), {
unfold kron_loc,
intro h,
apply h2,
rw fin.eq_iff_veq at h,
simp at h,
apply fin.coe_injective,
exact h,
},
symmetry,
apply if_neg,
exact f2,
}
}, {
have f1: (I m) r s = 0, {
apply if_neg, exact h1,
},
rw f1,
simp,
have f2: (kron_loc r v) ≠ (kron_loc s w), {
unfold kron_loc,
intro h,
apply h1,
rw fin.eq_iff_veq at h,
cases v with v vh,
cases w with w wh,
simp at h,
cases add_mul_congr h vh wh with e1 e2,
apply fin.coe_injective,
exact e1,
},
symmetry,
apply if_neg,
exact f2,
}
end
-- kron distributive over addition
theorem kron_dist_over_add_right (C : Matrix p q) : A ⊗ (B + C) = A ⊗ B + A ⊗ C
:= begin
apply matrix.ext, intros i j,
unfold kron, simp,
ring,
end
theorem kron_dist_over_add_left (C : Matrix p q) : (B + C) ⊗ A = B ⊗ A + C ⊗ A
:= begin
apply matrix.ext, intros i j,
unfold kron, simp,
ring,
end
lemma kron_dist_over_sub_right (C : Matrix p q) : A ⊗ (B - C) = A ⊗ B - A ⊗ C
:= begin
apply matrix.ext, intros i j,
unfold kron, simp,
ring,
end
lemma kron_dist_over_sub_left (C : Matrix p q) : (B - C) ⊗ A = B ⊗ A - C ⊗ A
:= begin
apply matrix.ext, intros i j,
unfold kron, simp,
ring,
end
@[simp]
lemma kron_smul_right {s : ℂ} : A ⊗ (s • B) = s • (A ⊗ B)
:= begin
apply kron_ext_mul, intros r s v w,
simp,
rw <- mul_assoc,
rw mul_comm (A r s),
rw mul_assoc,
congr' 1,
apply mul_to_kron,
end
@[simp]
lemma kron_smul_left {s : ℂ} : (s • A) ⊗ B = s • (A ⊗ B)
:= begin
apply kron_ext_mul, intros r s v w,
simp,
rw mul_assoc,
congr' 1,
apply mul_to_kron,
end
lemma kron_id_left : (I 1) ⊗ A = cast (by simp) A
:= begin
apply matrix.ext, intros i j,
unfold kron kron_div kron_mod,
cases i with i ip,
cases j with j jp,
simp,
rw matrix_cast_apply; try {simp},
have ip': i < m, by linarith,
have jp': j < n, by linarith,
congr' 2, {
rw nat.mod_eq_of_lt ip',
}, {
rw nat.mod_eq_of_lt jp',
},
end
lemma kron_id_right : A ⊗ (I 1) = cast (by simp) A
:= begin
apply matrix.ext, intros i j,
unfold kron kron_div kron_mod,
cases i with i ip,
cases j with j jp,
simp,
rw matrix_cast_apply; try {simp},
congr' 2,
end