-
Notifications
You must be signed in to change notification settings - Fork 1
/
Complex_L2.thy
1462 lines (1334 loc) · 66.6 KB
/
Complex_L2.thy
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
section \<open>\<open>Complex_L2\<close> -- Hilbert space of square-summable functions\<close>
(*
Authors:
Dominique Unruh, University of Tartu, [email protected]
Jose Manuel Rodriguez Caballero, University of Tartu, [email protected]
*)
theory Complex_L2
imports
Complex_Bounded_Linear_Function
"HOL-Analysis.L2_Norm"
"HOL-Library.Rewrite"
"HOL-Analysis.Infinite_Sum"
begin
unbundle cblinfun_notation
unbundle no_notation_blinfun_apply
subsection \<open>l2 norm of functions\<close>
definition "has_ell2_norm (x::_\<Rightarrow>complex) \<longleftrightarrow> (\<lambda>i. (x i)\<^sup>2) abs_summable_on UNIV"
lemma has_ell2_norm_bdd_above: \<open>has_ell2_norm x \<longleftrightarrow> bdd_above (sum (\<lambda>xa. norm ((x xa)\<^sup>2)) ` Collect finite)\<close>
by (simp add: has_ell2_norm_def abs_summable_bdd_above)
lemma has_ell2_norm_L2_set: "has_ell2_norm x = bdd_above (L2_set (norm o x) ` Collect finite)"
proof (rule iffI)
have \<open>mono sqrt\<close>
using monoI real_sqrt_le_mono by blast
assume \<open>has_ell2_norm x\<close>
then have *: \<open>bdd_above (sum (\<lambda>xa. norm ((x xa)\<^sup>2)) ` Collect finite)\<close>
by (subst (asm) has_ell2_norm_bdd_above)
have \<open>bdd_above ((\<lambda>F. sqrt (sum (\<lambda>xa. norm ((x xa)\<^sup>2)) F)) ` Collect finite)\<close>
using bdd_above_image_mono[OF \<open>mono sqrt\<close> *]
by (auto simp: image_image)
then show \<open>bdd_above (L2_set (norm o x) ` Collect finite)\<close>
by (auto simp: L2_set_def norm_power)
next
define p2 where \<open>p2 x = (if x < 0 then 0 else x^2)\<close> for x :: real
have \<open>mono p2\<close>
by (simp add: monoI p2_def)
have [simp]: \<open>p2 (L2_set f F) = (\<Sum>i\<in>F. (f i)\<^sup>2)\<close> for f and F :: \<open>'a set\<close>
by (smt (verit) L2_set_def L2_set_nonneg p2_def power2_less_0 real_sqrt_pow2 sum.cong sum_nonneg)
assume *: \<open>bdd_above (L2_set (norm o x) ` Collect finite)\<close>
have \<open>bdd_above (p2 ` L2_set (norm o x) ` Collect finite)\<close>
using bdd_above_image_mono[OF \<open>mono p2\<close> *]
by auto
then show \<open>has_ell2_norm x\<close>
apply (simp add: image_image has_ell2_norm_def abs_summable_bdd_above)
by (simp add: norm_power)
qed
definition ell2_norm :: \<open>('a \<Rightarrow> complex) \<Rightarrow> real\<close> where \<open>ell2_norm x = sqrt (\<Sum>\<^sub>\<infinity>i. norm (x i)^2)\<close>
lemma ell2_norm_SUP:
assumes \<open>has_ell2_norm x\<close>
shows "ell2_norm x = sqrt (SUP F\<in>{F. finite F}. sum (\<lambda>i. norm (x i)^2) F)"
using assms apply (auto simp add: ell2_norm_def has_ell2_norm_def)
apply (subst infsum_nonneg_is_SUPREMUM_real)
by (auto simp: norm_power)
lemma ell2_norm_L2_set:
assumes "has_ell2_norm x"
shows "ell2_norm x = (SUP F\<in>{F. finite F}. L2_set (norm o x) F)"
proof-
have "sqrt (\<Squnion> (sum (\<lambda>i. (cmod (x i))\<^sup>2) ` Collect finite)) =
(SUP F\<in>{F. finite F}. sqrt (\<Sum>i\<in>F. (cmod (x i))\<^sup>2))"
proof (subst continuous_at_Sup_mono)
show "mono sqrt"
by (simp add: mono_def)
show "continuous (at_left (\<Squnion> (sum (\<lambda>i. (cmod (x i))\<^sup>2) ` Collect finite))) sqrt"
using continuous_at_split isCont_real_sqrt by blast
show "sum (\<lambda>i. (cmod (x i))\<^sup>2) ` Collect finite \<noteq> {}"
by auto
show "bdd_above (sum (\<lambda>i. (cmod (x i))\<^sup>2) ` Collect finite)"
using has_ell2_norm_bdd_above[THEN iffD1, OF assms] by (auto simp: norm_power)
show "\<Squnion> (sqrt ` sum (\<lambda>i. (cmod (x i))\<^sup>2) ` Collect finite) = (SUP F\<in>Collect finite. sqrt (\<Sum>i\<in>F. (cmod (x i))\<^sup>2))"
by (metis image_image)
qed
thus ?thesis
using assms by (auto simp: ell2_norm_SUP L2_set_def)
qed
lemma has_ell2_norm_finite[simp]: "has_ell2_norm (x::'a::finite\<Rightarrow>_)"
unfolding has_ell2_norm_def by simp
lemma ell2_norm_finite:
"ell2_norm (x::'a::finite\<Rightarrow>complex) = sqrt (sum (\<lambda>i. (norm(x i))^2) UNIV)"
by (simp add: ell2_norm_def)
lemma ell2_norm_finite_L2_set: "ell2_norm (x::'a::finite\<Rightarrow>complex) = L2_set (norm o x) UNIV"
by (simp add: ell2_norm_finite L2_set_def)
lemma ell2_ket:
fixes a
defines \<open>f \<equiv> (\<lambda>i. if a = i then 1 else 0)\<close>
shows has_ell2_norm_ket: \<open>has_ell2_norm f\<close>
and ell2_norm_ket: \<open>ell2_norm f = 1\<close>
proof -
have \<open>(\<lambda>x. (f x)\<^sup>2) abs_summable_on {a}\<close>
apply (rule summable_on_finite) by simp
then show \<open>has_ell2_norm f\<close>
unfolding has_ell2_norm_def
apply (rule summable_on_cong_neutral[THEN iffD1, rotated -1])
unfolding f_def by auto
have \<open>(\<Sum>\<^sub>\<infinity>x\<in>{a}. (f x)\<^sup>2) = 1\<close>
apply (subst infsum_finite)
by (auto simp: f_def)
then show \<open>ell2_norm f = 1\<close>
unfolding ell2_norm_def
apply (subst infsum_cong_neutral[where T=\<open>{a}\<close> and g=\<open>\<lambda>x. (cmod (f x))\<^sup>2\<close>])
by (auto simp: f_def)
qed
lemma ell2_norm_geq0: \<open>ell2_norm x \<ge> 0\<close>
by (auto simp: ell2_norm_def intro!: infsum_nonneg)
lemma ell2_norm_point_bound:
assumes \<open>has_ell2_norm x\<close>
shows \<open>ell2_norm x \<ge> cmod (x i)\<close>
proof -
have \<open>(cmod (x i))\<^sup>2 = norm ((x i)\<^sup>2)\<close>
by (simp add: norm_power)
also have \<open>norm ((x i)\<^sup>2) = sum (\<lambda>i. (norm ((x i)\<^sup>2))) {i}\<close>
by auto
also have \<open>\<dots> = infsum (\<lambda>i. (norm ((x i)\<^sup>2))) {i}\<close>
by (rule infsum_finite[symmetric], simp)
also have \<open>\<dots> \<le> infsum (\<lambda>i. (norm ((x i)\<^sup>2))) UNIV\<close>
apply (rule infsum_mono_neutral)
using assms by (auto simp: has_ell2_norm_def)
also have \<open>\<dots> = (ell2_norm x)\<^sup>2\<close>
by (metis (no_types, lifting) ell2_norm_def ell2_norm_geq0 infsum_cong norm_power real_sqrt_eq_iff real_sqrt_unique)
finally show ?thesis
using ell2_norm_geq0 power2_le_imp_le by blast
qed
lemma ell2_norm_0:
assumes "has_ell2_norm x"
shows "(ell2_norm x = 0) = (x = (\<lambda>_. 0))"
proof
assume u1: "x = (\<lambda>_. 0)"
have u2: "(SUP x::'a set\<in>Collect finite. (0::real)) = 0"
if "x = (\<lambda>_. 0)"
by (metis cSUP_const empty_Collect_eq finite.emptyI)
show "ell2_norm x = 0"
unfolding ell2_norm_def
using u1 u2 by auto
next
assume norm0: "ell2_norm x = 0"
show "x = (\<lambda>_. 0)"
proof
fix i
have \<open>cmod (x i) \<le> ell2_norm x\<close>
using assms by (rule ell2_norm_point_bound)
also have \<open>\<dots> = 0\<close>
by (fact norm0)
finally show "x i = 0" by auto
qed
qed
lemma ell2_norm_smult:
assumes "has_ell2_norm x"
shows "has_ell2_norm (\<lambda>i. c * x i)" and "ell2_norm (\<lambda>i. c * x i) = cmod c * ell2_norm x"
proof -
have L2_set_mul: "L2_set (cmod \<circ> (\<lambda>i. c * x i)) F = cmod c * L2_set (cmod \<circ> x) F" for F
proof-
have "L2_set (cmod \<circ> (\<lambda>i. c * x i)) F = L2_set (\<lambda>i. (cmod c * (cmod o x) i)) F"
by (metis comp_def norm_mult)
also have "\<dots> = cmod c * L2_set (cmod o x) F"
by (metis norm_ge_zero L2_set_right_distrib)
finally show ?thesis .
qed
from assms obtain M where M: "M \<ge> L2_set (cmod o x) F" if "finite F" for F
unfolding has_ell2_norm_L2_set bdd_above_def by auto
hence "cmod c * M \<ge> L2_set (cmod o (\<lambda>i. c * x i)) F" if "finite F" for F
unfolding L2_set_mul
by (simp add: ordered_comm_semiring_class.comm_mult_left_mono that)
thus has: "has_ell2_norm (\<lambda>i. c * x i)"
unfolding has_ell2_norm_L2_set bdd_above_def using L2_set_mul[symmetric] by auto
have "ell2_norm (\<lambda>i. c * x i) = (SUP F \<in> Collect finite. (L2_set (cmod \<circ> (\<lambda>i. c * x i)) F))"
by (simp add: ell2_norm_L2_set has)
also have "\<dots> = (SUP F \<in> Collect finite. (cmod c * L2_set (cmod \<circ> x) F))"
using L2_set_mul by auto
also have "\<dots> = cmod c * ell2_norm x"
proof (subst ell2_norm_L2_set)
show "has_ell2_norm x"
by (simp add: assms)
show "(SUP F\<in>Collect finite. cmod c * L2_set (cmod \<circ> x) F) = cmod c * \<Squnion> (L2_set (cmod \<circ> x) ` Collect finite)"
proof (subst continuous_at_Sup_mono [where f = "\<lambda>x. cmod c * x"])
show "mono ((*) (cmod c))"
by (simp add: mono_def ordered_comm_semiring_class.comm_mult_left_mono)
show "continuous (at_left (\<Squnion> (L2_set (cmod \<circ> x) ` Collect finite))) ((*) (cmod c))"
proof (rule continuous_mult)
show "continuous (at_left (\<Squnion> (L2_set (cmod \<circ> x) ` Collect finite))) (\<lambda>x. cmod c)"
by simp
show "continuous (at_left (\<Squnion> (L2_set (cmod \<circ> x) ` Collect finite))) (\<lambda>x. x)"
by simp
qed
show "L2_set (cmod \<circ> x) ` Collect finite \<noteq> {}"
by auto
show "bdd_above (L2_set (cmod \<circ> x) ` Collect finite)"
by (meson assms has_ell2_norm_L2_set)
show "(SUP F\<in>Collect finite. cmod c * L2_set (cmod \<circ> x) F) = \<Squnion> ((*) (cmod c) ` L2_set (cmod \<circ> x) ` Collect finite)"
by (metis image_image)
qed
qed
finally show "ell2_norm (\<lambda>i. c * x i) = cmod c * ell2_norm x".
qed
lemma ell2_norm_triangle:
assumes "has_ell2_norm x" and "has_ell2_norm y"
shows "has_ell2_norm (\<lambda>i. x i + y i)" and "ell2_norm (\<lambda>i. x i + y i) \<le> ell2_norm x + ell2_norm y"
proof -
have triangle: "L2_set (cmod \<circ> (\<lambda>i. x i + y i)) F \<le> L2_set (cmod \<circ> x) F + L2_set (cmod \<circ> y) F"
(is "?lhs\<le>?rhs")
if "finite F" for F
proof -
have "?lhs \<le> L2_set (\<lambda>i. (cmod o x) i + (cmod o y) i) F"
proof (rule L2_set_mono)
show "(cmod \<circ> (\<lambda>i. x i + y i)) i \<le> (cmod \<circ> x) i + (cmod \<circ> y) i"
if "i \<in> F"
for i :: 'a
using that norm_triangle_ineq by auto
show "0 \<le> (cmod \<circ> (\<lambda>i. x i + y i)) i"
if "i \<in> F"
for i :: 'a
using that
by simp
qed
also have "\<dots> \<le> ?rhs"
by (rule L2_set_triangle_ineq)
finally show ?thesis .
qed
obtain Mx My where Mx: "Mx \<ge> L2_set (cmod o x) F" and My: "My \<ge> L2_set (cmod o y) F"
if "finite F" for F
using assms unfolding has_ell2_norm_L2_set bdd_above_def by auto
hence MxMy: "Mx + My \<ge> L2_set (cmod \<circ> x) F + L2_set (cmod \<circ> y) F" if "finite F" for F
using that by fastforce
hence bdd_plus: "bdd_above ((\<lambda>xa. L2_set (cmod \<circ> x) xa + L2_set (cmod \<circ> y) xa) ` Collect finite)"
unfolding bdd_above_def by auto
from MxMy have MxMy': "Mx + My \<ge> L2_set (cmod \<circ> (\<lambda>i. x i + y i)) F" if "finite F" for F
using triangle that by fastforce
thus has: "has_ell2_norm (\<lambda>i. x i + y i)"
unfolding has_ell2_norm_L2_set bdd_above_def by auto
have SUP_plus: "(SUP x\<in>A. f x + g x) \<le> (SUP x\<in>A. f x) + (SUP x\<in>A. g x)"
if notempty: "A\<noteq>{}" and bddf: "bdd_above (f`A)"and bddg: "bdd_above (g`A)"
for f g :: "'a set \<Rightarrow> real" and A
proof-
have xleq: "x \<le> (SUP x\<in>A. f x) + (SUP x\<in>A. g x)" if x: "x \<in> (\<lambda>x. f x + g x) ` A" for x
proof -
obtain a where aA: "a:A" and ax: "x = f a + g a"
using x by blast
have fa: "f a \<le> (SUP x\<in>A. f x)"
by (simp add: bddf aA cSUP_upper)
moreover have "g a \<le> (SUP x\<in>A. g x)"
by (simp add: bddg aA cSUP_upper)
ultimately have "f a + g a \<le> (SUP x\<in>A. f x) + (SUP x\<in>A. g x)" by simp
with ax show ?thesis by simp
qed
have "(\<lambda>x. f x + g x) ` A \<noteq> {}"
using notempty by auto
moreover have "x \<le> \<Squnion> (f ` A) + \<Squnion> (g ` A)"
if "x \<in> (\<lambda>x. f x + g x) ` A"
for x :: real
using that
by (simp add: xleq)
ultimately show ?thesis
by (meson bdd_above_def cSup_le_iff)
qed
have a2: "bdd_above (L2_set (cmod \<circ> x) ` Collect finite)"
by (meson assms(1) has_ell2_norm_L2_set)
have a3: "bdd_above (L2_set (cmod \<circ> y) ` Collect finite)"
by (meson assms(2) has_ell2_norm_L2_set)
have a1: "Collect finite \<noteq> {}"
by auto
have a4: "\<Squnion> (L2_set (cmod \<circ> (\<lambda>i. x i + y i)) ` Collect finite)
\<le> (SUP xa\<in>Collect finite.
L2_set (cmod \<circ> x) xa + L2_set (cmod \<circ> y) xa)"
by (metis (mono_tags, lifting) a1 bdd_plus cSUP_mono mem_Collect_eq triangle)
have "\<forall>r. \<Squnion> (L2_set (cmod \<circ> (\<lambda>a. x a + y a)) ` Collect finite) \<le> r \<or> \<not> (SUP A\<in>Collect finite. L2_set (cmod \<circ> x) A + L2_set (cmod \<circ> y) A) \<le> r"
using a4 by linarith
hence "\<Squnion> (L2_set (cmod \<circ> (\<lambda>i. x i + y i)) ` Collect finite)
\<le> \<Squnion> (L2_set (cmod \<circ> x) ` Collect finite) +
\<Squnion> (L2_set (cmod \<circ> y) ` Collect finite)"
by (metis (no_types) SUP_plus a1 a2 a3)
hence "\<Squnion> (L2_set (cmod \<circ> (\<lambda>i. x i + y i)) ` Collect finite) \<le> ell2_norm x + ell2_norm y"
by (simp add: assms(1) assms(2) ell2_norm_L2_set)
thus "ell2_norm (\<lambda>i. x i + y i) \<le> ell2_norm x + ell2_norm y"
by (simp add: ell2_norm_L2_set has)
qed
lemma ell2_norm_uminus:
assumes "has_ell2_norm x"
shows \<open>has_ell2_norm (\<lambda>i. - x i)\<close> and \<open>ell2_norm (\<lambda>i. - x i) = ell2_norm x\<close>
using assms by (auto simp: has_ell2_norm_def ell2_norm_def)
subsection \<open>The type \<open>ell2\<close> of square-summable functions\<close>
typedef 'a ell2 = "{x::'a\<Rightarrow>complex. has_ell2_norm x}"
unfolding has_ell2_norm_def by (rule exI[of _ "\<lambda>_.0"], auto)
setup_lifting type_definition_ell2
instantiation ell2 :: (type)complex_vector begin
lift_definition zero_ell2 :: "'a ell2" is "\<lambda>_. 0" by (auto simp: has_ell2_norm_def)
lift_definition uminus_ell2 :: "'a ell2 \<Rightarrow> 'a ell2" is uminus by (simp add: has_ell2_norm_def)
lift_definition plus_ell2 :: "'a ell2 \<Rightarrow> 'a ell2 \<Rightarrow> 'a ell2" is "\<lambda>f g x. f x + g x"
by (rule ell2_norm_triangle)
lift_definition minus_ell2 :: "'a ell2 \<Rightarrow> 'a ell2 \<Rightarrow> 'a ell2" is "\<lambda>f g x. f x - g x"
apply (subst add_uminus_conv_diff[symmetric])
apply (rule ell2_norm_triangle)
by (auto simp add: ell2_norm_uminus)
lift_definition scaleR_ell2 :: "real \<Rightarrow> 'a ell2 \<Rightarrow> 'a ell2" is "\<lambda>r f x. complex_of_real r * f x"
by (rule ell2_norm_smult)
lift_definition scaleC_ell2 :: "complex \<Rightarrow> 'a ell2 \<Rightarrow> 'a ell2" is "\<lambda>c f x. c * f x"
by (rule ell2_norm_smult)
instance
proof
fix a b c :: "'a ell2"
show "((*\<^sub>R) r::'a ell2 \<Rightarrow> _) = (*\<^sub>C) (complex_of_real r)" for r
apply (rule ext) apply transfer by auto
show "a + b + c = a + (b + c)"
by (transfer; rule ext; simp)
show "a + b = b + a"
by (transfer; rule ext; simp)
show "0 + a = a"
by (transfer; rule ext; simp)
show "- a + a = 0"
by (transfer; rule ext; simp)
show "a - b = a + - b"
by (transfer; rule ext; simp)
show "r *\<^sub>C (a + b) = r *\<^sub>C a + r *\<^sub>C b" for r
apply (transfer; rule ext)
by (simp add: vector_space_over_itself.scale_right_distrib)
show "(r + r') *\<^sub>C a = r *\<^sub>C a + r' *\<^sub>C a" for r r'
apply (transfer; rule ext)
by (simp add: ring_class.ring_distribs(2))
show "r *\<^sub>C r' *\<^sub>C a = (r * r') *\<^sub>C a" for r r'
by (transfer; rule ext; simp)
show "1 *\<^sub>C a = a"
by (transfer; rule ext; simp)
qed
end
instantiation ell2 :: (type)complex_normed_vector begin
lift_definition norm_ell2 :: "'a ell2 \<Rightarrow> real" is ell2_norm .
declare norm_ell2_def[code del]
definition "dist x y = norm (x - y)" for x y::"'a ell2"
definition "sgn x = x /\<^sub>R norm x" for x::"'a ell2"
definition [code del]: "uniformity = (INF e\<in>{0<..}. principal {(x::'a ell2, y). norm (x - y) < e})"
definition [code del]: "open U = (\<forall>x\<in>U. \<forall>\<^sub>F (x', y) in INF e\<in>{0<..}. principal {(x, y). norm (x - y) < e}. x' = x \<longrightarrow> y \<in> U)" for U :: "'a ell2 set"
instance
proof
fix a b :: "'a ell2"
show "dist a b = norm (a - b)"
by (simp add: dist_ell2_def)
show "sgn a = a /\<^sub>R norm a"
by (simp add: sgn_ell2_def)
show "uniformity = (INF e\<in>{0<..}. principal {(x, y). dist (x::'a ell2) y < e})"
unfolding dist_ell2_def uniformity_ell2_def by simp
show "open U = (\<forall>x\<in>U. \<forall>\<^sub>F (x', y) in uniformity. (x'::'a ell2) = x \<longrightarrow> y \<in> U)" for U :: "'a ell2 set"
unfolding uniformity_ell2_def open_ell2_def by simp_all
show "(norm a = 0) = (a = 0)"
apply transfer by (fact ell2_norm_0)
show "norm (a + b) \<le> norm a + norm b"
apply transfer by (fact ell2_norm_triangle)
show "norm (r *\<^sub>R (a::'a ell2)) = \<bar>r\<bar> * norm a" for r
and a :: "'a ell2"
apply transfer
by (simp add: ell2_norm_smult(2))
show "norm (r *\<^sub>C a) = cmod r * norm a" for r
apply transfer
by (simp add: ell2_norm_smult(2))
qed
end
lemma norm_point_bound_ell2: "norm (Rep_ell2 x i) \<le> norm x"
apply transfer
by (simp add: ell2_norm_point_bound)
lemma ell2_norm_finite_support:
assumes \<open>finite S\<close> \<open>\<And> i. i \<notin> S \<Longrightarrow> Rep_ell2 x i = 0\<close>
shows \<open>norm x = sqrt ((sum (\<lambda>i. (cmod (Rep_ell2 x i))\<^sup>2)) S)\<close>
proof (insert assms(2), transfer fixing: S)
fix x :: \<open>'a \<Rightarrow> complex\<close>
assume zero: \<open>\<And>i. i \<notin> S \<Longrightarrow> x i = 0\<close>
have \<open>ell2_norm x = sqrt (\<Sum>\<^sub>\<infinity>i. (cmod (x i))\<^sup>2)\<close>
by (auto simp: ell2_norm_def)
also have \<open>\<dots> = sqrt (\<Sum>\<^sub>\<infinity>i\<in>S. (cmod (x i))\<^sup>2)\<close>
apply (subst infsum_cong_neutral[where g=\<open>\<lambda>i. (cmod (x i))\<^sup>2\<close> and S=UNIV and T=S])
using zero by auto
also have \<open>\<dots> = sqrt (\<Sum>i\<in>S. (cmod (x i))\<^sup>2)\<close>
using \<open>finite S\<close> by simp
finally show \<open>ell2_norm x = sqrt (\<Sum>i\<in>S. (cmod (x i))\<^sup>2)\<close>
by -
qed
instantiation ell2 :: (type) complex_inner begin
lift_definition cinner_ell2 :: "'a ell2 \<Rightarrow> 'a ell2 \<Rightarrow> complex" is
"\<lambda>x y. infsum (\<lambda>i. (cnj (x i) * y i)) UNIV" .
declare cinner_ell2_def[code del]
instance
proof standard
fix x y z :: "'a ell2" fix c :: complex
show "cinner x y = cnj (cinner y x)"
proof transfer
fix x y :: "'a\<Rightarrow>complex" assume "has_ell2_norm x" and "has_ell2_norm y"
have "(\<Sum>\<^sub>\<infinity>i. cnj (x i) * y i) = (\<Sum>\<^sub>\<infinity>i. cnj (cnj (y i) * x i))"
by (metis complex_cnj_cnj complex_cnj_mult mult.commute)
also have "\<dots> = cnj (\<Sum>\<^sub>\<infinity>i. cnj (y i) * x i)"
by (metis infsum_cnj)
finally show "(\<Sum>\<^sub>\<infinity>i. cnj (x i) * y i) = cnj (\<Sum>\<^sub>\<infinity>i. cnj (y i) * x i)" .
qed
show "cinner (x + y) z = cinner x z + cinner y z"
proof transfer
fix x y z :: "'a \<Rightarrow> complex"
assume "has_ell2_norm x"
hence cnj_x: "(\<lambda>i. cnj (x i) * cnj (x i)) abs_summable_on UNIV"
by (simp del: complex_cnj_mult add: norm_mult[symmetric] complex_cnj_mult[symmetric] has_ell2_norm_def power2_eq_square)
assume "has_ell2_norm y"
hence cnj_y: "(\<lambda>i. cnj (y i) * cnj (y i)) abs_summable_on UNIV"
by (simp del: complex_cnj_mult add: norm_mult[symmetric] complex_cnj_mult[symmetric] has_ell2_norm_def power2_eq_square)
assume "has_ell2_norm z"
hence z: "(\<lambda>i. z i * z i) abs_summable_on UNIV"
by (simp add: norm_mult[symmetric] has_ell2_norm_def power2_eq_square)
have cnj_x_z:"(\<lambda>i. cnj (x i) * z i) abs_summable_on UNIV"
using cnj_x z by (rule abs_summable_product)
have cnj_y_z:"(\<lambda>i. cnj (y i) * z i) abs_summable_on UNIV"
using cnj_y z by (rule abs_summable_product)
show "(\<Sum>\<^sub>\<infinity>i. cnj (x i + y i) * z i) = (\<Sum>\<^sub>\<infinity>i. cnj (x i) * z i) + (\<Sum>\<^sub>\<infinity>i. cnj (y i) * z i)"
apply (subst infsum_add [symmetric])
using cnj_x_z cnj_y_z
by (auto simp add: summable_on_iff_abs_summable_on_complex distrib_left mult.commute)
qed
show "cinner (c *\<^sub>C x) y = cnj c * cinner x y"
proof transfer
fix x y :: "'a \<Rightarrow> complex" and c :: complex
assume "has_ell2_norm x"
hence cnj_x: "(\<lambda>i. cnj (x i) * cnj (x i)) abs_summable_on UNIV"
by (simp del: complex_cnj_mult add: norm_mult[symmetric] complex_cnj_mult[symmetric] has_ell2_norm_def power2_eq_square)
assume "has_ell2_norm y"
hence y: "(\<lambda>i. y i * y i) abs_summable_on UNIV"
by (simp add: norm_mult[symmetric] has_ell2_norm_def power2_eq_square)
have cnj_x_y:"(\<lambda>i. cnj (x i) * y i) abs_summable_on UNIV"
using cnj_x y by (rule abs_summable_product)
thus "(\<Sum>\<^sub>\<infinity>i. cnj (c * x i) * y i) = cnj c * (\<Sum>\<^sub>\<infinity>i. cnj (x i) * y i)"
by (auto simp flip: infsum_cmult_right simp add: abs_summable_summable mult.commute vector_space_over_itself.scale_left_commute)
qed
show "0 \<le> cinner x x"
proof transfer
fix x :: "'a \<Rightarrow> complex"
assume "has_ell2_norm x"
hence "(\<lambda>i. cmod (cnj (x i) * x i)) abs_summable_on UNIV"
by (simp add: norm_mult has_ell2_norm_def power2_eq_square)
hence "(\<lambda>i. cnj (x i) * x i) abs_summable_on UNIV"
by auto
hence sum: "(\<lambda>i. cnj (x i) * x i) abs_summable_on UNIV"
unfolding has_ell2_norm_def power2_eq_square.
have "0 = (\<Sum>\<^sub>\<infinity>i::'a. 0)" by auto
also have "\<dots> \<le> (\<Sum>\<^sub>\<infinity>i. cnj (x i) * x i)"
apply (rule infsum_mono_complex)
by (auto simp add: abs_summable_summable sum)
finally show "0 \<le> (\<Sum>\<^sub>\<infinity>i. cnj (x i) * x i)" by assumption
qed
show "(cinner x x = 0) = (x = 0)"
proof (transfer, auto)
fix x :: "'a \<Rightarrow> complex"
assume "has_ell2_norm x"
hence "(\<lambda>i::'a. cmod (cnj (x i) * x i)) abs_summable_on UNIV"
by (smt (verit, del_insts) complex_mod_mult_cnj has_ell2_norm_def mult.commute norm_ge_zero norm_power real_norm_def summable_on_cong)
hence cmod_x2: "(\<lambda>i. cnj (x i) * x i) abs_summable_on UNIV"
unfolding has_ell2_norm_def power2_eq_square
by simp
assume eq0: "(\<Sum>\<^sub>\<infinity>i. cnj (x i) * x i) = 0"
show "x = (\<lambda>_. 0)"
proof (rule ccontr)
assume "x \<noteq> (\<lambda>_. 0)"
then obtain i where "x i \<noteq> 0" by auto
hence "0 < cnj (x i) * x i"
by (metis le_less cnj_x_x_geq0 complex_cnj_zero_iff vector_space_over_itself.scale_eq_0_iff)
also have "\<dots> = (\<Sum>\<^sub>\<infinity>i\<in>{i}. cnj (x i) * x i)" by auto
also have "\<dots> \<le> (\<Sum>\<^sub>\<infinity>i. cnj (x i) * x i)"
apply (rule infsum_mono_neutral_complex)
by (auto simp add: abs_summable_summable cmod_x2)
also from eq0 have "\<dots> = 0" by assumption
finally show False by simp
qed
qed
show "norm x = sqrt (cmod (cinner x x))"
proof transfer
fix x :: "'a \<Rightarrow> complex"
assume x: "has_ell2_norm x"
have "(\<lambda>i::'a. cmod (x i) * cmod (x i)) abs_summable_on UNIV \<Longrightarrow>
(\<lambda>i::'a. cmod (cnj (x i) * x i)) abs_summable_on UNIV"
by (simp add: norm_mult has_ell2_norm_def power2_eq_square)
hence sum: "(\<lambda>i. cnj (x i) * x i) abs_summable_on UNIV"
by (metis (no_types, lifting) complex_mod_mult_cnj has_ell2_norm_def mult.commute norm_power summable_on_cong x)
from x have "ell2_norm x = sqrt (\<Sum>\<^sub>\<infinity>i. (cmod (x i))\<^sup>2)"
unfolding ell2_norm_def by simp
also have "\<dots> = sqrt (\<Sum>\<^sub>\<infinity>i. cmod (cnj (x i) * x i))"
unfolding norm_complex_def power2_eq_square by auto
also have "\<dots> = sqrt (cmod (\<Sum>\<^sub>\<infinity>i. cnj (x i) * x i))"
by (auto simp: infsum_cmod abs_summable_summable sum)
finally show "ell2_norm x = sqrt (cmod (\<Sum>\<^sub>\<infinity>i. cnj (x i) * x i))" by assumption
qed
qed
end
instance ell2 :: (type) chilbert_space
proof
fix X :: \<open>nat \<Rightarrow> 'a ell2\<close>
define x where \<open>x n a = Rep_ell2 (X n) a\<close> for n a
have [simp]: \<open>has_ell2_norm (x n)\<close> for n
using Rep_ell2 x_def[abs_def] by simp
assume \<open>Cauchy X\<close>
moreover have "dist (x n a) (x m a) \<le> dist (X n) (X m)" for n m a
by (metis Rep_ell2 x_def dist_norm ell2_norm_point_bound mem_Collect_eq minus_ell2.rep_eq norm_ell2.rep_eq)
ultimately have \<open>Cauchy (\<lambda>n. x n a)\<close> for a
by (meson Cauchy_def le_less_trans)
then obtain l where x_lim: \<open>(\<lambda>n. x n a) \<longlonglongrightarrow> l a\<close> for a
apply atomize_elim apply (rule choice)
by (simp add: convergent_eq_Cauchy)
define L where \<open>L = Abs_ell2 l\<close>
define normF where \<open>normF F x = L2_set (cmod \<circ> x) F\<close> for F :: \<open>'a set\<close> and x
have normF_triangle: \<open>normF F (\<lambda>a. x a + y a) \<le> normF F x + normF F y\<close> if \<open>finite F\<close> for F x y
proof -
have \<open>normF F (\<lambda>a. x a + y a) = L2_set (\<lambda>a. cmod (x a + y a)) F\<close>
by (metis (mono_tags, lifting) L2_set_cong comp_apply normF_def)
also have \<open>\<dots> \<le> L2_set (\<lambda>a. cmod (x a) + cmod (y a)) F\<close>
by (meson L2_set_mono norm_ge_zero norm_triangle_ineq)
also have \<open>\<dots> \<le> L2_set (\<lambda>a. cmod (x a)) F + L2_set (\<lambda>a. cmod (y a)) F\<close>
by (simp add: L2_set_triangle_ineq)
also have \<open>\<dots> \<le> normF F x + normF F y\<close>
by (smt (verit, best) L2_set_cong normF_def comp_apply)
finally show ?thesis
by -
qed
have normF_negate: \<open>normF F (\<lambda>a. - x a) = normF F x\<close> if \<open>finite F\<close> for F x
unfolding normF_def o_def by simp
have normF_ell2norm: \<open>normF F x \<le> ell2_norm x\<close> if \<open>finite F\<close> and \<open>has_ell2_norm x\<close> for F x
apply (auto intro!: cSUP_upper2[where x=F] simp: that normF_def ell2_norm_L2_set)
by (meson has_ell2_norm_L2_set that(2))
note Lim_bounded2[rotated, rule_format, trans]
from \<open>Cauchy X\<close>
obtain I where cauchyX: \<open>norm (X n - X m) \<le> \<epsilon>\<close> if \<open>\<epsilon>>0\<close> \<open>n\<ge>I \<epsilon>\<close> \<open>m\<ge>I \<epsilon>\<close> for \<epsilon> n m
by (metis Cauchy_def dist_norm less_eq_real_def)
have normF_xx: \<open>normF F (\<lambda>a. x n a - x m a) \<le> \<epsilon>\<close> if \<open>finite F\<close> \<open>\<epsilon>>0\<close> \<open>n\<ge>I \<epsilon>\<close> \<open>m\<ge>I \<epsilon>\<close> for \<epsilon> n m F
apply (subst asm_rl[of \<open>(\<lambda>a. x n a - x m a) = Rep_ell2 (X n - X m)\<close>])
apply (simp add: x_def minus_ell2.rep_eq)
using that cauchyX by (metis Rep_ell2 mem_Collect_eq normF_ell2norm norm_ell2.rep_eq order_trans)
have normF_xl_lim: \<open>(\<lambda>m. normF F (\<lambda>a. x m a - l a)) \<longlonglongrightarrow> 0\<close> if \<open>finite F\<close> for F
proof -
have \<open>(\<lambda>xa. cmod (x xa m - l m)) \<longlonglongrightarrow> 0\<close> for m
using x_lim by (simp add: LIM_zero_iff tendsto_norm_zero)
then have \<open>(\<lambda>m. \<Sum>i\<in>F. ((cmod \<circ> (\<lambda>a. x m a - l a)) i)\<^sup>2) \<longlonglongrightarrow> 0\<close>
by (auto intro: tendsto_null_sum)
then show ?thesis
unfolding normF_def L2_set_def
using tendsto_real_sqrt by force
qed
have normF_xl: \<open>normF F (\<lambda>a. x n a - l a) \<le> \<epsilon>\<close>
if \<open>n \<ge> I \<epsilon>\<close> and \<open>\<epsilon> > 0\<close> and \<open>finite F\<close> for n \<epsilon> F
proof -
have \<open>normF F (\<lambda>a. x n a - l a) - \<epsilon> \<le> normF F (\<lambda>a. x n a - x m a) + normF F (\<lambda>a. x m a - l a) - \<epsilon>\<close> for m
using normF_triangle[OF \<open>finite F\<close>, where x=\<open>(\<lambda>a. x n a - x m a)\<close> and y=\<open>(\<lambda>a. x m a - l a)\<close>]
by auto
also have \<open>\<dots> m \<le> normF F (\<lambda>a. x m a - l a)\<close> if \<open>m \<ge> I \<epsilon>\<close> for m
using normF_xx[OF \<open>finite F\<close> \<open>\<epsilon>>0\<close> \<open>n \<ge> I \<epsilon>\<close> \<open>m \<ge> I \<epsilon>\<close>]
by auto
also have \<open>(\<lambda>m. \<dots> m) \<longlonglongrightarrow> 0\<close>
using \<open>finite F\<close> by (rule normF_xl_lim)
finally show ?thesis
by auto
qed
have \<open>normF F l \<le> 1 + normF F (x (I 1))\<close> if [simp]: \<open>finite F\<close> for F
using normF_xl[where F=F and \<epsilon>=1 and n=\<open>I 1\<close>]
using normF_triangle[where F=F and x=\<open>x (I 1)\<close> and y=\<open>\<lambda>a. l a - x (I 1) a\<close>]
using normF_negate[where F=F and x=\<open>(\<lambda>a. x (I 1) a - l a)\<close>]
by auto
also have \<open>\<dots> F \<le> 1 + ell2_norm (x (I 1))\<close> if \<open>finite F\<close> for F
using normF_ell2norm that by simp
finally have [simp]: \<open>has_ell2_norm l\<close>
unfolding has_ell2_norm_L2_set
by (auto intro!: bdd_aboveI simp flip: normF_def)
then have \<open>l = Rep_ell2 L\<close>
by (simp add: Abs_ell2_inverse L_def)
have [simp]: \<open>has_ell2_norm (\<lambda>a. x n a - l a)\<close> for n
apply (subst diff_conv_add_uminus)
apply (rule ell2_norm_triangle)
by (auto intro!: ell2_norm_uminus)
from normF_xl have ell2norm_xl: \<open>ell2_norm (\<lambda>a. x n a - l a) \<le> \<epsilon>\<close>
if \<open>n \<ge> I \<epsilon>\<close> and \<open>\<epsilon> > 0\<close> for n \<epsilon>
apply (subst ell2_norm_L2_set)
using that by (auto intro!: cSUP_least simp: normF_def)
have \<open>norm (X n - L) \<le> \<epsilon>\<close> if \<open>n \<ge> I \<epsilon>\<close> and \<open>\<epsilon> > 0\<close> for n \<epsilon>
using ell2norm_xl[OF that]
by (simp add: x_def norm_ell2.rep_eq \<open>l = Rep_ell2 L\<close> minus_ell2.rep_eq)
then have \<open>X \<longlonglongrightarrow> L\<close>
unfolding tendsto_iff
apply (auto simp: dist_norm eventually_sequentially)
by (meson field_lbound_gt_zero le_less_trans)
then show \<open>convergent X\<close>
by (rule convergentI)
qed
instantiation ell2 :: (CARD_1) complex_algebra_1
begin
lift_definition one_ell2 :: "'a ell2" is "\<lambda>_. 1" by simp
lift_definition times_ell2 :: "'a ell2 \<Rightarrow> 'a ell2 \<Rightarrow> 'a ell2" is "\<lambda>a b x. a x * b x"
by simp
instance
proof
fix a b c :: "'a ell2" and r :: complex
show "a * b * c = a * (b * c)"
by (transfer, auto)
show "(a + b) * c = a * c + b * c"
apply (transfer, rule ext)
by (simp add: distrib_left mult.commute)
show "a * (b + c) = a * b + a * c"
apply transfer
by (simp add: ring_class.ring_distribs(1))
show "r *\<^sub>C a * b = r *\<^sub>C (a * b)"
by (transfer, auto)
show "(a::'a ell2) * r *\<^sub>C b = r *\<^sub>C (a * b)"
by (transfer, auto)
show "1 * a = a"
by (transfer, rule ext, auto)
show "a * 1 = a"
by (transfer, rule ext, auto)
show "(0::'a ell2) \<noteq> 1"
apply transfer
by (meson zero_neq_one)
qed
end
instantiation ell2 :: (CARD_1) field begin
lift_definition divide_ell2 :: "'a ell2 \<Rightarrow> 'a ell2 \<Rightarrow> 'a ell2" is "\<lambda>a b x. a x / b x"
by simp
lift_definition inverse_ell2 :: "'a ell2 \<Rightarrow> 'a ell2" is "\<lambda>a x. inverse (a x)"
by simp
instance
proof (intro_classes; transfer)
fix a :: "'a \<Rightarrow> complex"
assume "a \<noteq> (\<lambda>_. 0)"
then obtain y where ay: "a y \<noteq> 0"
by auto
show "(\<lambda>x. inverse (a x) * a x) = (\<lambda>_. 1)"
proof (rule ext)
fix x
have "x = y"
by auto
with ay have "a x \<noteq> 0"
by metis
then show "inverse (a x) * a x = 1"
by auto
qed
qed (auto simp add: divide_complex_def mult.commute ring_class.ring_distribs)
end
subsection \<open>Orthogonality\<close>
lemma ell2_pointwise_ortho:
assumes \<open>\<And> i. Rep_ell2 x i = 0 \<or> Rep_ell2 y i = 0\<close>
shows \<open>is_orthogonal x y\<close>
using assms apply transfer
by (simp add: infsum_0)
subsection \<open>Truncated vectors\<close>
lift_definition trunc_ell2:: \<open>'a set \<Rightarrow> 'a ell2 \<Rightarrow> 'a ell2\<close>
is \<open>\<lambda> S x. (\<lambda> i. (if i \<in> S then x i else 0))\<close>
proof (rename_tac S x)
fix x :: \<open>'a \<Rightarrow> complex\<close> and S :: \<open>'a set\<close>
assume \<open>has_ell2_norm x\<close>
then have \<open>(\<lambda>i. (x i)\<^sup>2) abs_summable_on UNIV\<close>
unfolding has_ell2_norm_def by -
then have \<open>(\<lambda>i. (x i)\<^sup>2) abs_summable_on S\<close>
using summable_on_subset_banach by blast
then have \<open>(\<lambda>xa. (if xa \<in> S then x xa else 0)\<^sup>2) abs_summable_on UNIV\<close>
apply (rule summable_on_cong_neutral[THEN iffD1, rotated -1])
by auto
then show \<open>has_ell2_norm (\<lambda>i. if i \<in> S then x i else 0)\<close>
unfolding has_ell2_norm_def by -
qed
lemma trunc_ell2_empty[simp]: \<open>trunc_ell2 {} x = 0\<close>
apply transfer by simp
lemma norm_id_minus_trunc_ell2:
\<open>(norm (x - trunc_ell2 S x))^2 = (norm x)^2 - (norm (trunc_ell2 S x))^2\<close>
proof-
have \<open>Rep_ell2 (trunc_ell2 S x) i = 0 \<or> Rep_ell2 (x - trunc_ell2 S x) i = 0\<close> for i
apply transfer
by auto
hence \<open>\<langle> (trunc_ell2 S x), (x - trunc_ell2 S x) \<rangle> = 0\<close>
using ell2_pointwise_ortho by blast
hence \<open>(norm x)^2 = (norm (trunc_ell2 S x))^2 + (norm (x - trunc_ell2 S x))^2\<close>
using pythagorean_theorem by fastforce
thus ?thesis by simp
qed
lemma norm_trunc_ell2_finite:
\<open>finite S \<Longrightarrow> (norm (trunc_ell2 S x)) = sqrt ((sum (\<lambda>i. (cmod (Rep_ell2 x i))\<^sup>2)) S)\<close>
proof-
assume \<open>finite S\<close>
moreover have \<open>\<And> i. i \<notin> S \<Longrightarrow> Rep_ell2 ((trunc_ell2 S x)) i = 0\<close>
by (simp add: trunc_ell2.rep_eq)
ultimately have \<open>(norm (trunc_ell2 S x)) = sqrt ((sum (\<lambda>i. (cmod (Rep_ell2 ((trunc_ell2 S x)) i))\<^sup>2)) S)\<close>
using ell2_norm_finite_support
by blast
moreover have \<open>\<And> i. i \<in> S \<Longrightarrow> Rep_ell2 ((trunc_ell2 S x)) i = Rep_ell2 x i\<close>
by (simp add: trunc_ell2.rep_eq)
ultimately show ?thesis by simp
qed
lemma trunc_ell2_lim_at_UNIV:
\<open>((\<lambda>S. trunc_ell2 S \<psi>) \<longlongrightarrow> \<psi>) (finite_subsets_at_top UNIV)\<close>
proof -
define f where \<open>f i = (cmod (Rep_ell2 \<psi> i))\<^sup>2\<close> for i
have has: \<open>has_ell2_norm (Rep_ell2 \<psi>)\<close>
using Rep_ell2 by blast
then have summable: "f abs_summable_on UNIV"
by (smt (verit, del_insts) f_def has_ell2_norm_def norm_ge_zero norm_power real_norm_def summable_on_cong)
have \<open>norm \<psi> = (ell2_norm (Rep_ell2 \<psi>))\<close>
apply transfer by simp
also have \<open>\<dots> = sqrt (infsum f UNIV)\<close>
by (simp add: ell2_norm_def f_def[symmetric])
finally have norm\<psi>: \<open>norm \<psi> = sqrt (infsum f UNIV)\<close>
by -
have norm_trunc: \<open>norm (trunc_ell2 S \<psi>) = sqrt (sum f S)\<close> if \<open>finite S\<close> for S
using f_def that norm_trunc_ell2_finite by fastforce
have \<open>(sum f \<longlongrightarrow> infsum f UNIV) (finite_subsets_at_top UNIV)\<close>
using f_def[abs_def] infsum_tendsto local.summable by fastforce
then have \<open>((\<lambda>S. sqrt (sum f S)) \<longlongrightarrow> sqrt (infsum f UNIV)) (finite_subsets_at_top UNIV)\<close>
using tendsto_real_sqrt by blast
then have \<open>((\<lambda>S. norm (trunc_ell2 S \<psi>)) \<longlongrightarrow> norm \<psi>) (finite_subsets_at_top UNIV)\<close>
apply (subst tendsto_cong[where g=\<open>\<lambda>S. sqrt (sum f S)\<close>])
by (auto simp add: eventually_finite_subsets_at_top_weakI norm_trunc norm\<psi>)
then have \<open>((\<lambda>S. (norm (trunc_ell2 S \<psi>))\<^sup>2) \<longlongrightarrow> (norm \<psi>)\<^sup>2) (finite_subsets_at_top UNIV)\<close>
by (simp add: tendsto_power)
then have \<open>((\<lambda>S. (norm \<psi>)\<^sup>2 - (norm (trunc_ell2 S \<psi>))\<^sup>2) \<longlongrightarrow> 0) (finite_subsets_at_top UNIV)\<close>
apply (rule tendsto_diff[where a=\<open>(norm \<psi>)^2\<close> and b=\<open>(norm \<psi>)^2\<close>, simplified, rotated])
by auto
then have \<open>((\<lambda>S. (norm (\<psi> - trunc_ell2 S \<psi>))\<^sup>2) \<longlongrightarrow> 0) (finite_subsets_at_top UNIV)\<close>
unfolding norm_id_minus_trunc_ell2 by simp
then have \<open>((\<lambda>S. norm (\<psi> - trunc_ell2 S \<psi>)) \<longlongrightarrow> 0) (finite_subsets_at_top UNIV)\<close>
by auto
then have \<open>((\<lambda>S. \<psi> - trunc_ell2 S \<psi>) \<longlongrightarrow> 0) (finite_subsets_at_top UNIV)\<close>
by (rule tendsto_norm_zero_cancel)
then show ?thesis
apply (rule Lim_transform2[where f=\<open>\<lambda>_. \<psi>\<close>, rotated])
by simp
qed
subsection \<open>Kets and bras\<close>
lift_definition ket :: "'a \<Rightarrow> 'a ell2" is "\<lambda>x y. if x=y then 1 else 0"
by (rule has_ell2_norm_ket)
abbreviation bra :: "'a \<Rightarrow> (_,complex) cblinfun" where "bra i \<equiv> vector_to_cblinfun (ket i)*" for i
instance ell2 :: (type) not_singleton
proof standard
have "ket undefined \<noteq> (0::'a ell2)"
proof transfer
show "(\<lambda>y. if (undefined::'a) = y then 1::complex else 0) \<noteq> (\<lambda>_. 0)"
by (meson one_neq_zero)
qed
thus \<open>\<exists>x y::'a ell2. x \<noteq> y\<close>
by blast
qed
lemma cinner_ket_left: \<open>\<langle>ket i, \<psi>\<rangle> = Rep_ell2 \<psi> i\<close>
apply (transfer fixing: i)
apply (subst infsum_cong_neutral[where T=\<open>{i}\<close>])
by auto
lemma cinner_ket_right: \<open>\<langle>\<psi>, ket i\<rangle> = cnj (Rep_ell2 \<psi> i)\<close>
apply (transfer fixing: i)
apply (subst infsum_cong_neutral[where T=\<open>{i}\<close>])
by auto
lemma cinner_ket_eqI:
assumes \<open>\<And>i. cinner (ket i) \<psi> = cinner (ket i) \<phi>\<close>
shows \<open>\<psi> = \<phi>\<close>
by (metis Rep_ell2_inject assms cinner_ket_left ext)
lemma norm_ket[simp]: "norm (ket i) = 1"
apply transfer by (rule ell2_norm_ket)
lemma cinner_ket_same[simp]:
\<open>\<langle>ket i, ket i\<rangle> = 1\<close>
proof-
have \<open>norm (ket i) = 1\<close>
by simp
hence \<open>sqrt (cmod \<langle>ket i, ket i\<rangle>) = 1\<close>
by (metis norm_eq_sqrt_cinner)
hence \<open>cmod \<langle>ket i, ket i\<rangle> = 1\<close>
using real_sqrt_eq_1_iff by blast
moreover have \<open>\<langle>ket i, ket i\<rangle> = cmod \<langle>ket i, ket i\<rangle>\<close>
proof-
have \<open>\<langle>ket i, ket i\<rangle> \<in> \<real>\<close>
by (simp add: cinner_real)
thus ?thesis
by (metis cinner_ge_zero complex_of_real_cmod)
qed
ultimately show ?thesis by simp
qed
lemma orthogonal_ket[simp]:
\<open>is_orthogonal (ket i) (ket j) \<longleftrightarrow> i \<noteq> j\<close>
by (simp add: cinner_ket_left ket.rep_eq)
lemma cinner_ket: \<open>\<langle>ket i, ket j\<rangle> = (if i=j then 1 else 0)\<close>
by (simp add: cinner_ket_left ket.rep_eq)
lemma ket_injective[simp]: \<open>ket i = ket j \<longleftrightarrow> i = j\<close>
by (metis cinner_ket one_neq_zero)
lemma inj_ket[simp]: \<open>inj ket\<close>
by (simp add: inj_on_def)
lemma trunc_ell2_ket_cspan:
\<open>trunc_ell2 S x \<in> (cspan (range ket))\<close> if \<open>finite S\<close>
proof (use that in induction)
case empty
then show ?case
by (auto intro: complex_vector.span_zero)
next
case (insert a F)
from insert.hyps have \<open>trunc_ell2 (insert a F) x = trunc_ell2 F x + Rep_ell2 x a *\<^sub>C ket a\<close>
apply (transfer fixing: F a)
by auto
with insert.IH
show ?case
by (simp add: complex_vector.span_add_eq complex_vector.span_base complex_vector.span_scale)
qed
lemma closed_cspan_range_ket[simp]:
\<open>closure (cspan (range ket)) = UNIV\<close>
proof (intro set_eqI iffI UNIV_I closure_approachable[THEN iffD2] allI impI)
fix \<psi> :: \<open>'a ell2\<close>
fix e :: real assume \<open>e > 0\<close>
have \<open>((\<lambda>S. trunc_ell2 S \<psi>) \<longlongrightarrow> \<psi>) (finite_subsets_at_top UNIV)\<close>
by (rule trunc_ell2_lim_at_UNIV)
then obtain F where \<open>finite F\<close> and \<open>dist (trunc_ell2 F \<psi>) \<psi> < e\<close>
apply (drule_tac tendstoD[OF _ \<open>e > 0\<close>])
by (auto dest: simp: eventually_finite_subsets_at_top)
moreover have \<open>trunc_ell2 F \<psi> \<in> cspan (range ket)\<close>
using \<open>finite F\<close> trunc_ell2_ket_cspan by blast
ultimately show \<open>\<exists>\<phi>\<in>cspan (range ket). dist \<phi> \<psi> < e\<close>
by auto
qed
lemma ccspan_range_ket[simp]: "ccspan (range ket) = (top::('a ell2 ccsubspace))"
proof-
have \<open>closure (complex_vector.span (range ket)) = (UNIV::'a ell2 set)\<close>
using Complex_L2.closed_cspan_range_ket by blast
thus ?thesis
by (simp add: ccspan.abs_eq top_ccsubspace.abs_eq)
qed
lemma cspan_range_ket_finite[simp]: "cspan (range ket :: 'a::finite ell2 set) = UNIV"
by (metis closed_cspan_range_ket closure_finite_cspan finite_class.finite_UNIV finite_imageI)
instance ell2 :: (finite) cfinite_dim
proof
define basis :: \<open>'a ell2 set\<close> where \<open>basis = range ket\<close>
have \<open>finite basis\<close>
unfolding basis_def by simp
moreover have \<open>cspan basis = UNIV\<close>
by (simp add: basis_def)
ultimately show \<open>\<exists>basis::'a ell2 set. finite basis \<and> cspan basis = UNIV\<close>
by auto
qed
instantiation ell2 :: (enum) onb_enum begin
definition "canonical_basis_ell2 = map ket Enum.enum"
instance
proof
show "distinct (canonical_basis::'a ell2 list)"
proof-
have \<open>finite (UNIV::'a set)\<close>
by simp
have \<open>distinct (enum_class.enum::'a list)\<close>
using enum_distinct by blast
moreover have \<open>inj_on ket (set enum_class.enum)\<close>
by (meson inj_onI ket_injective)
ultimately show ?thesis
unfolding canonical_basis_ell2_def
using distinct_map
by blast
qed
show "is_ortho_set (set (canonical_basis::'a ell2 list))"
apply (auto simp: canonical_basis_ell2_def enum_UNIV)
by (smt (z3) norm_ket f_inv_into_f is_ortho_set_def orthogonal_ket norm_zero)
show "cindependent (set (canonical_basis::'a ell2 list))"
apply (auto simp: canonical_basis_ell2_def enum_UNIV)
by (smt (verit, best) norm_ket f_inv_into_f is_ortho_set_def is_ortho_set_cindependent orthogonal_ket norm_zero)
show "cspan (set (canonical_basis::'a ell2 list)) = UNIV"
by (auto simp: canonical_basis_ell2_def enum_UNIV)
show "norm (x::'a ell2) = 1"
if "(x::'a ell2) \<in> set canonical_basis"
for x :: "'a ell2"
using that unfolding canonical_basis_ell2_def
by auto
qed
end
lemma canonical_basis_length_ell2[code_unfold, simp]:
"length (canonical_basis ::'a::enum ell2 list) = CARD('a)"
unfolding canonical_basis_ell2_def apply simp
using card_UNIV_length_enum by metis
lemma ket_canonical_basis: "ket x = canonical_basis ! enum_idx x"
proof-
have "x = (enum_class.enum::'a list) ! enum_idx x"
using enum_idx_correct[where i = x] by simp
hence p1: "ket x = ket ((enum_class.enum::'a list) ! enum_idx x)"
by simp
have "enum_idx x < length (enum_class.enum::'a list)"
using enum_idx_bound[where x = x].
hence "(map ket (enum_class.enum::'a list)) ! enum_idx x
= ket ((enum_class.enum::'a list) ! enum_idx x)"
by auto
thus ?thesis
unfolding canonical_basis_ell2_def using p1 by auto
qed
lemma clinear_equal_ket:
fixes f g :: \<open>'a::finite ell2 \<Rightarrow> _\<close>
assumes \<open>clinear f\<close>
assumes \<open>clinear g\<close>
assumes \<open>\<And>i. f (ket i) = g (ket i)\<close>
shows \<open>f = g\<close>
apply (rule ext)
apply (rule complex_vector.linear_eq_on_span[where f=f and g=g and B=\<open>range ket\<close>])
using assms by auto
lemma equal_ket:
fixes A B :: \<open>('a ell2, 'b::complex_normed_vector) cblinfun\<close>
assumes \<open>\<And> x. cblinfun_apply A (ket x) = cblinfun_apply B (ket x)\<close>
shows \<open>A = B\<close>
apply (rule cblinfun_eq_gen_eqI[where G=\<open>range ket\<close>])
using assms by auto
lemma antilinear_equal_ket:
fixes f g :: \<open>'a::finite ell2 \<Rightarrow> _\<close>
assumes \<open>antilinear f\<close>
assumes \<open>antilinear g\<close>
assumes \<open>\<And>i. f (ket i) = g (ket i)\<close>
shows \<open>f = g\<close>
proof -
have [simp]: \<open>clinear (f \<circ> from_conjugate_space)\<close>
apply (rule antilinear_o_antilinear)
using assms by (simp_all add: antilinear_from_conjugate_space)
have [simp]: \<open>clinear (g \<circ> from_conjugate_space)\<close>
apply (rule antilinear_o_antilinear)
using assms by (simp_all add: antilinear_from_conjugate_space)
have [simp]: \<open>cspan (to_conjugate_space ` (range ket :: 'a ell2 set)) = UNIV\<close>
by simp
have "f o from_conjugate_space = g o from_conjugate_space"
apply (rule ext)
apply (rule complex_vector.linear_eq_on_span[where f="f o from_conjugate_space" and g="g o from_conjugate_space" and B=\<open>to_conjugate_space ` range ket\<close>])
apply (simp, simp)
using assms(3) by (auto simp: to_conjugate_space_inverse)
then show "f = g"
by (smt (verit) UNIV_I from_conjugate_space_inverse surj_def surj_fun_eq to_conjugate_space_inject)
qed
lemma cinner_ket_adjointI: