-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComplex_Inner_Product.thy
2227 lines (2025 loc) · 111 KB
/
Complex_Inner_Product.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
(*
Authors:
Dominique Unruh, University of Tartu, [email protected]
Jose Manuel Rodriguez Caballero, University of Tartu, [email protected]
*)
section \<open>\<open>Complex_Inner_Product\<close> -- Complex Inner Product Spaces\<close>
theory Complex_Inner_Product
imports
Complex_Inner_Product0
begin
subsection \<open>Complex inner product spaces\<close>
bundle cinner_bracket_notation begin
notation cinner ("\<langle>_, _\<rangle>")
end
unbundle cinner_bracket_notation
bundle no_cinner_bracket_notation begin
no_notation cinner ("\<langle>_, _\<rangle>")
end
lemma cinner_real: "cinner x x \<in> \<real>"
by (simp add: cdot_square_norm)
lemmas cinner_commute' [simp] = cinner_commute[symmetric]
lemma (in complex_inner) cinner_eq_flip: \<open>(cinner x y = cinner z w) \<longleftrightarrow> (cinner y x = cinner w z)\<close>
by (metis cinner_commute)
lemma Im_cinner_x_x[simp]: "Im \<langle>x , x\<rangle> = 0"
using comp_Im_same[OF cinner_ge_zero] by simp
lemma of_complex_inner_1' [simp]:
"cinner (1 :: 'a :: {complex_inner, complex_normed_algebra_1}) (of_complex x) = x"
by (metis cinner_commute complex_cnj_cnj of_complex_inner_1)
class chilbert_space = complex_inner + complete_space
begin
subclass cbanach by standard
end
instantiation complex :: "chilbert_space" begin
instance ..
end
subsection \<open>Misc facts\<close>
text \<open>This is a useful rule for establishing the equality of vectors\<close>
lemma cinner_extensionality:
assumes \<open>\<And>\<gamma>. \<langle>\<gamma>, \<psi>\<rangle> = \<langle>\<gamma>, \<phi>\<rangle>\<close>
shows \<open>\<psi> = \<phi>\<close>
by (metis assms cinner_eq_zero_iff cinner_simps(3) right_minus_eq)
lemma polar_identity:
includes notation_norm
shows \<open>\<parallel>x + y\<parallel>^2 = \<parallel>x\<parallel>^2 + \<parallel>y\<parallel>^2 + 2*Re \<langle>x, y\<rangle>\<close>
\<comment> \<open>Shown in the proof of Corollary 1.5 in @{cite conway2013course}\<close>
proof -
have \<open>\<langle>x , y\<rangle> + \<langle>y , x\<rangle> = \<langle>x , y\<rangle> + cnj \<langle>x , y\<rangle>\<close>
by simp
hence \<open>\<langle>x , y\<rangle> + \<langle>y , x\<rangle> = 2 * Re \<langle>x , y\<rangle> \<close>
using complex_add_cnj by presburger
have \<open>\<parallel>x + y\<parallel>^2 = \<langle>x+y, x+y\<rangle>\<close>
by (simp add: cdot_square_norm)
hence \<open>\<parallel>x + y\<parallel>^2 = \<langle>x , x\<rangle> + \<langle>x , y\<rangle> + \<langle>y , x\<rangle> + \<langle>y , y\<rangle>\<close>
by (simp add: cinner_add_left cinner_add_right)
thus ?thesis using \<open>\<langle>x , y\<rangle> + \<langle>y , x\<rangle> = 2 * Re \<langle>x , y\<rangle>\<close>
by (smt (verit, ccfv_SIG) Re_complex_of_real plus_complex.simps(1) power2_norm_eq_cinner')
qed
lemma polar_identity_minus:
includes notation_norm
shows \<open>\<parallel>x - y\<parallel>^2 = \<parallel>x\<parallel>^2 + \<parallel>y\<parallel>^2 - 2 * Re \<langle>x, y\<rangle>\<close>
proof-
have \<open>\<parallel>x + (-y)\<parallel>^2 = \<parallel>x\<parallel>^2 + \<parallel>-y\<parallel>^2 + 2 * Re \<langle>x , (-y)\<rangle>\<close>
using polar_identity by blast
hence \<open>\<parallel>x - y\<parallel>^2 = \<parallel>x\<parallel>^2 + \<parallel>y\<parallel>^2 - 2*Re \<langle>x , y\<rangle>\<close>
by simp
thus ?thesis
by blast
qed
proposition parallelogram_law:
includes notation_norm
fixes x y :: "'a::complex_inner"
shows \<open>\<parallel>x+y\<parallel>^2 + \<parallel>x-y\<parallel>^2 = 2*( \<parallel>x\<parallel>^2 + \<parallel>y\<parallel>^2 )\<close>
\<comment> \<open>Shown in the proof of Theorem 2.3 in @{cite conway2013course}\<close>
by (simp add: polar_identity_minus polar_identity)
theorem pythagorean_theorem:
includes notation_norm
shows \<open>\<langle>x , y\<rangle> = 0 \<Longrightarrow> \<parallel> x + y \<parallel>^2 = \<parallel> x \<parallel>^2 + \<parallel> y \<parallel>^2\<close>
\<comment> \<open>Shown in the proof of Theorem 2.2 in @{cite conway2013course}\<close>
by (simp add: polar_identity)
lemma pythagorean_theorem_sum:
assumes q1: "\<And>a a'. a \<in> t \<Longrightarrow> a' \<in> t \<Longrightarrow> a \<noteq> a' \<Longrightarrow> \<langle>f a, f a'\<rangle> = 0"
and q2: "finite t"
shows "(norm (\<Sum>a\<in>t. f a))^2 = (\<Sum>a\<in>t.(norm (f a))^2)"
proof (insert q1, use q2 in induction)
case empty
show ?case
by auto
next
case (insert x F)
have r1: "\<langle>f x, f a\<rangle> = 0"
if "a \<in> F"
for a
using that insert.hyps(2) insert.prems by auto
have "sum f F = (\<Sum>a\<in>F. f a)"
by simp
hence s4: "\<langle>f x, sum f F\<rangle> = \<langle>f x, (\<Sum>a\<in>F. f a)\<rangle>"
by simp
also have s3: "\<dots> = (\<Sum>a\<in>F. \<langle>f x, f a\<rangle>)"
using cinner_sum_right by auto
also have s2: "\<dots> = (\<Sum>a\<in>F. 0)"
using r1
by simp
also have s1: "\<dots> = 0"
by simp
finally have xF_ortho: "\<langle>f x, sum f F\<rangle> = 0"
using s2 s3 by auto
have "(norm (sum f (insert x F)))\<^sup>2 = (norm (f x + sum f F))\<^sup>2"
by (simp add: insert.hyps(1) insert.hyps(2))
also have "\<dots> = (norm (f x))\<^sup>2 + (norm (sum f F))\<^sup>2"
using xF_ortho by (rule pythagorean_theorem)
also have "\<dots> = (norm (f x))\<^sup>2 + (\<Sum>a\<in>F.(norm (f a))^2)"
apply (subst insert.IH) using insert.prems by auto
also have "\<dots> = (\<Sum>a\<in>insert x F.(norm (f a))^2)"
by (simp add: insert.hyps(1) insert.hyps(2))
finally show ?case
by simp
qed
lemma Cauchy_cinner_Cauchy:
fixes x y :: \<open>nat \<Rightarrow> 'a::complex_inner\<close>
assumes a1: \<open>Cauchy x\<close> and a2: \<open>Cauchy y\<close>
shows \<open>Cauchy (\<lambda> n. \<langle> x n, y n \<rangle>)\<close>
proof-
have \<open>bounded (range x)\<close>
using a1
by (simp add: Elementary_Metric_Spaces.cauchy_imp_bounded)
hence b1: \<open>\<exists>M. \<forall>n. norm (x n) < M\<close>
by (meson bounded_pos_less rangeI)
have \<open>bounded (range y)\<close>
using a2
by (simp add: Elementary_Metric_Spaces.cauchy_imp_bounded)
hence b2: \<open>\<exists> M. \<forall> n. norm (y n) < M\<close>
by (meson bounded_pos_less rangeI)
have \<open>\<exists>M. \<forall>n. norm (x n) < M \<and> norm (y n) < M\<close>
using b1 b2
by (metis dual_order.strict_trans linorder_neqE_linordered_idom)
then obtain M where M1: \<open>\<And>n. norm (x n) < M\<close> and M2: \<open>\<And>n. norm (y n) < M\<close>
by blast
have M3: \<open>M > 0\<close>
by (smt M2 norm_not_less_zero)
have \<open>\<exists>N. \<forall>n \<ge> N. \<forall>m \<ge> N. norm ( (\<lambda> i. \<langle> x i, y i \<rangle>) n - (\<lambda> i. \<langle> x i, y i \<rangle>) m ) < e\<close>
if "e > 0" for e
proof-
have \<open>e / (2*M) > 0\<close>
using M3
by (simp add: that)
hence \<open>\<exists>N. \<forall>n\<ge>N. \<forall>m\<ge>N. norm (x n - x m) < e / (2*M)\<close>
using a1
by (simp add: Cauchy_iff)
then obtain N1 where N1_def: \<open>\<And>n m. n\<ge>N1 \<Longrightarrow> m\<ge>N1 \<Longrightarrow> norm (x n - x m) < e / (2*M)\<close>
by blast
have x1: \<open>\<exists>N. \<forall> n\<ge>N. \<forall> m\<ge>N. norm (y n - y m) < e / (2*M)\<close>
using a2 \<open>e / (2*M) > 0\<close>
by (simp add: Cauchy_iff)
obtain N2 where N2_def: \<open>\<And>n m. n\<ge>N2 \<Longrightarrow> m\<ge>N2 \<Longrightarrow> norm (y n - y m) < e / (2*M)\<close>
using x1
by blast
define N where N_def: \<open>N = N1 + N2\<close>
hence \<open>N \<ge> N1\<close>
by auto
have \<open>N \<ge> N2\<close>
using N_def
by auto
have \<open>norm ( \<langle> x n, y n \<rangle> - \<langle> x m, y m \<rangle> ) < e\<close>
if \<open>n \<ge> N\<close> and \<open>m \<ge> N\<close>
for n m
proof -
have \<open>\<langle> x n, y n \<rangle> - \<langle> x m, y m \<rangle> = (\<langle> x n, y n \<rangle> - \<langle> x m, y n \<rangle>) + (\<langle> x m, y n \<rangle> - \<langle> x m, y m \<rangle>)\<close>
by simp
hence y1: \<open>norm (\<langle> x n, y n \<rangle> - \<langle> x m, y m \<rangle>) \<le> norm (\<langle> x n, y n \<rangle> - \<langle> x m, y n \<rangle>)
+ norm (\<langle> x m, y n \<rangle> - \<langle> x m, y m \<rangle>)\<close>
by (metis norm_triangle_ineq)
have \<open>\<langle> x n, y n \<rangle> - \<langle> x m, y n \<rangle> = \<langle> x n - x m, y n \<rangle>\<close>
by (simp add: cinner_diff_left)
hence \<open>norm (\<langle> x n, y n \<rangle> - \<langle> x m, y n \<rangle>) = norm \<langle> x n - x m, y n \<rangle>\<close>
by simp
moreover have \<open>norm \<langle> x n - x m, y n \<rangle> \<le> norm (x n - x m) * norm (y n)\<close>
using complex_inner_class.Cauchy_Schwarz_ineq2 by blast
moreover have \<open>norm (y n) < M\<close>
by (simp add: M2)
moreover have \<open>norm (x n - x m) < e/(2*M)\<close>
using \<open>N \<le> m\<close> \<open>N \<le> n\<close> \<open>N1 \<le> N\<close> N1_def by auto
ultimately have \<open>norm (\<langle> x n, y n \<rangle> - \<langle> x m, y n \<rangle>) < (e/(2*M)) * M\<close>
by (smt linordered_semiring_strict_class.mult_strict_mono norm_ge_zero)
moreover have \<open> (e/(2*M)) * M = e/2\<close>
using \<open>M > 0\<close> by simp
ultimately have \<open>norm (\<langle> x n, y n \<rangle> - \<langle> x m, y n \<rangle>) < e/2\<close>
by simp
hence y2: \<open>norm (\<langle> x n, y n \<rangle> - \<langle> x m, y n \<rangle>) < e/2\<close>
by blast
have \<open>\<langle> x m, y n \<rangle> - \<langle> x m, y m \<rangle> = \<langle> x m, y n - y m \<rangle>\<close>
by (simp add: cinner_diff_right)
hence \<open>norm (\<langle> x m, y n \<rangle> - \<langle> x m, y m \<rangle>) = norm \<langle> x m, y n - y m \<rangle>\<close>
by simp
moreover have \<open>norm \<langle> x m, y n - y m \<rangle> \<le> norm (x m) * norm (y n - y m)\<close>
by (meson complex_inner_class.Cauchy_Schwarz_ineq2)
moreover have \<open>norm (x m) < M\<close>
by (simp add: M1)
moreover have \<open>norm (y n - y m) < e/(2*M)\<close>
using \<open>N \<le> m\<close> \<open>N \<le> n\<close> \<open>N2 \<le> N\<close> N2_def by auto
ultimately have \<open>norm (\<langle> x m, y n \<rangle> - \<langle> x m, y m \<rangle>) < M * (e/(2*M))\<close>
by (smt linordered_semiring_strict_class.mult_strict_mono norm_ge_zero)
moreover have \<open>M * (e/(2*M)) = e/2\<close>
using \<open>M > 0\<close> by simp
ultimately have \<open>norm (\<langle> x m, y n \<rangle> - \<langle> x m, y m \<rangle>) < e/2\<close>
by simp
hence y3: \<open>norm (\<langle> x m, y n \<rangle> - \<langle> x m, y m \<rangle>) < e/2\<close>
by blast
show \<open>norm ( \<langle> x n, y n \<rangle> - \<langle> x m, y m \<rangle> ) < e\<close>
using y1 y2 y3 by simp
qed
thus ?thesis by blast
qed
thus ?thesis
by (simp add: CauchyI)
qed
lemma cinner_sup_norm: \<open>norm \<psi> = (SUP \<phi>. cmod (cinner \<phi> \<psi>) / norm \<phi>)\<close>
proof (rule sym, rule cSup_eq_maximum)
have \<open>norm \<psi> = cmod (cinner \<psi> \<psi>) / norm \<psi>\<close>
by (metis norm_eq_sqrt_cinner norm_ge_zero real_div_sqrt)
then show \<open>norm \<psi> \<in> range (\<lambda>\<phi>. cmod (cinner \<phi> \<psi>) / norm \<phi>)\<close>
by blast
next
fix n assume \<open>n \<in> range (\<lambda>\<phi>. cmod (cinner \<phi> \<psi>) / norm \<phi>)\<close>
then obtain \<phi> where n\<phi>: \<open>n = cmod (cinner \<phi> \<psi>) / norm \<phi>\<close>
by auto
show \<open>n \<le> norm \<psi>\<close>
unfolding n\<phi>
by (simp add: complex_inner_class.Cauchy_Schwarz_ineq2 divide_le_eq ordered_field_class.sign_simps(33))
qed
lemma cinner_sup_onorm:
fixes A :: \<open>'a::{real_normed_vector,not_singleton} \<Rightarrow> 'b::complex_inner\<close>
assumes \<open>bounded_linear A\<close>
shows \<open>onorm A = (SUP (\<psi>,\<phi>). cmod (cinner \<psi> (A \<phi>)) / (norm \<psi> * norm \<phi>))\<close>
proof (unfold onorm_def, rule cSup_eq_cSup)
show \<open>bdd_above (range (\<lambda>x. norm (A x) / norm x))\<close>
by (meson assms bdd_aboveI2 le_onorm)
next
fix a
assume \<open>a \<in> range (\<lambda>\<phi>. norm (A \<phi>) / norm \<phi>)\<close>
then obtain \<phi> where \<open>a = norm (A \<phi>) / norm \<phi>\<close>
by auto
then have \<open>a \<le> cmod (cinner (A \<phi>) (A \<phi>)) / (norm (A \<phi>) * norm \<phi>)\<close>
apply auto
by (smt (verit) divide_divide_eq_left norm_eq_sqrt_cinner norm_imp_pos_and_ge real_div_sqrt)
then show \<open>\<exists>b\<in>range (\<lambda>(\<psi>, \<phi>). cmod (cinner \<psi> (A \<phi>)) / (norm \<psi> * norm \<phi>)). a \<le> b\<close>
by force
next
fix b
assume \<open>b \<in> range (\<lambda>(\<psi>, \<phi>). cmod (cinner \<psi> (A \<phi>)) / (norm \<psi> * norm \<phi>))\<close>
then obtain \<psi> \<phi> where b: \<open>b = cmod (cinner \<psi> (A \<phi>)) / (norm \<psi> * norm \<phi>)\<close>
by auto
then have \<open>b \<le> norm (A \<phi>) / norm \<phi>\<close>
apply auto
by (smt (verit, ccfv_threshold) complex_inner_class.Cauchy_Schwarz_ineq2 division_ring_divide_zero linordered_field_class.divide_right_mono mult_cancel_left1 nonzero_mult_divide_mult_cancel_left2 norm_imp_pos_and_ge ordered_field_class.sign_simps(33) zero_le_divide_iff)
then show \<open>\<exists>a\<in>range (\<lambda>x. norm (A x) / norm x). b \<le> a\<close>
by auto
qed
subsection \<open>Orthogonality\<close>
definition "orthogonal_complement S = {x| x. \<forall>y\<in>S. cinner x y = 0}"
lemma orthogonal_complement_orthoI:
\<open>x \<in> orthogonal_complement M \<Longrightarrow> y \<in> M \<Longrightarrow> \<langle> x, y \<rangle> = 0\<close>
unfolding orthogonal_complement_def by auto
lemma orthogonal_complement_orthoI':
\<open>x \<in> M \<Longrightarrow> y \<in> orthogonal_complement M \<Longrightarrow> \<langle> x, y \<rangle> = 0\<close>
by (metis cinner_commute' complex_cnj_zero orthogonal_complement_orthoI)
lemma orthogonal_complementI:
\<open>(\<And>x. x \<in> M \<Longrightarrow> \<langle> y, x \<rangle> = 0) \<Longrightarrow> y \<in> orthogonal_complement M\<close>
unfolding orthogonal_complement_def
by simp
abbreviation is_orthogonal::\<open>'a::complex_inner \<Rightarrow> 'a \<Rightarrow> bool\<close> where
\<open>is_orthogonal x y \<equiv> \<langle> x, y \<rangle> = 0\<close>
bundle orthogonal_notation begin
notation is_orthogonal (infixl "\<bottom>" 69)
end
bundle no_orthogonal_notation begin
no_notation is_orthogonal (infixl "\<bottom>" 69)
end
lemma is_orthogonal_sym: "is_orthogonal \<psi> \<phi> = is_orthogonal \<phi> \<psi>"
by (metis cinner_commute' complex_cnj_zero)
lemma orthogonal_complement_closed_subspace[simp]:
"closed_csubspace (orthogonal_complement A)"
for A :: \<open>('a::complex_inner) set\<close>
proof (intro closed_csubspace.intro complex_vector.subspaceI)
fix x y and c
show \<open>0 \<in> orthogonal_complement A\<close>
by (rule orthogonal_complementI, simp)
show \<open>x + y \<in> orthogonal_complement A\<close>
if \<open>x \<in> orthogonal_complement A\<close> and \<open>y \<in> orthogonal_complement A\<close>
using that by (auto intro!: orthogonal_complementI dest!: orthogonal_complement_orthoI
simp add: cinner_add_left)
show \<open>c *\<^sub>C x \<in> orthogonal_complement A\<close> if \<open>x \<in> orthogonal_complement A\<close>
using that by (auto intro!: orthogonal_complementI dest!: orthogonal_complement_orthoI)
show "closed (orthogonal_complement A)"
proof (auto simp add: closed_sequential_limits, rename_tac an a)
fix an a
assume ortho: \<open>\<forall>n::nat. an n \<in> orthogonal_complement A\<close>
assume lim: \<open>an \<longlonglongrightarrow> a\<close>
have \<open>\<forall> y \<in> A. \<forall> n. \<langle> y , an n \<rangle> = 0\<close>
using orthogonal_complement_orthoI'
by (simp add: orthogonal_complement_orthoI' ortho)
moreover have \<open>isCont (\<lambda> x. \<langle> y , x \<rangle>) a\<close> for y
using bounded_clinear_cinner_right clinear_continuous_at
by (simp add: clinear_continuous_at bounded_clinear_cinner_right)
ultimately have \<open>(\<lambda> n. (\<lambda> v. \<langle> y , v \<rangle>) (an n)) \<longlonglongrightarrow> (\<lambda> v. \<langle> y , v \<rangle>) a\<close> for y
using isCont_tendsto_compose
by (simp add: isCont_tendsto_compose lim)
hence \<open>\<forall> y\<in>A. (\<lambda> n. \<langle> y , an n \<rangle> ) \<longlonglongrightarrow> \<langle> y , a \<rangle>\<close>
by simp
hence \<open>\<forall> y\<in>A. (\<lambda> n. 0 ) \<longlonglongrightarrow> \<langle> y , a \<rangle>\<close>
using \<open>\<forall> y \<in> A. \<forall> n. \<langle> y , an n \<rangle> = 0\<close>
by fastforce
hence \<open>\<forall> y \<in> A. \<langle> y , a \<rangle> = 0\<close>
using limI by fastforce
then show \<open>a \<in> orthogonal_complement A\<close>
by (simp add: orthogonal_complementI is_orthogonal_sym)
qed
qed
lemma orthogonal_complement_zero_intersection:
assumes "0\<in>M"
shows \<open>M \<inter> (orthogonal_complement M) = {0}\<close>
proof -
have "x=0" if "x\<in>M" and "x\<in>orthogonal_complement M" for x
proof -
from that have "\<langle> x, x \<rangle> = 0"
unfolding orthogonal_complement_def by auto
thus "x=0"
by auto
qed
with assms show ?thesis
unfolding orthogonal_complement_def by auto
qed
lemma is_orthogonal_closure_cspan:
assumes "\<And>x y. x \<in> X \<Longrightarrow> y \<in> Y \<Longrightarrow> is_orthogonal x y"
assumes \<open>x \<in> closure (cspan X)\<close> \<open>y \<in> closure (cspan Y)\<close>
shows "is_orthogonal x y"
proof -
have *: \<open>cinner x y = 0\<close> if \<open>y \<in> Y\<close> for y
using bounded_antilinear_cinner_left apply (rule bounded_antilinear_eq_on[where G=X])
using assms that by auto
show \<open>cinner x y = 0\<close>
using bounded_clinear_cinner_right apply (rule bounded_clinear_eq_on[where G=Y])
using * assms by auto
qed
instantiation ccsubspace :: (complex_inner) "uminus"
begin
lift_definition uminus_ccsubspace::\<open>'a ccsubspace \<Rightarrow> 'a ccsubspace\<close>
is \<open>orthogonal_complement\<close>
by simp
instance ..
end
instantiation ccsubspace :: (complex_inner) minus begin
lift_definition minus_ccsubspace :: "'a ccsubspace \<Rightarrow> 'a ccsubspace \<Rightarrow> 'a ccsubspace"
is "\<lambda>A B. A \<inter> (orthogonal_complement B)"
by simp
instance..
end
text \<open>Orthogonal set\<close>
definition is_ortho_set :: "'a::complex_inner set \<Rightarrow> bool" where
\<open>is_ortho_set S = ((\<forall>x\<in>S. \<forall>y\<in>S. x \<noteq> y \<longrightarrow> \<langle>x, y\<rangle> = 0) \<and> 0 \<notin> S)\<close>
lemma is_ortho_set_empty[simp]: "is_ortho_set {}"
unfolding is_ortho_set_def by auto
lemma is_ortho_set_antimono: \<open>A \<subseteq> B \<Longrightarrow> is_ortho_set B \<Longrightarrow> is_ortho_set A\<close>
unfolding is_ortho_set_def by auto
lemma orthogonal_complement_of_closure:
fixes A ::"('a::complex_inner) set"
shows "orthogonal_complement A = orthogonal_complement (closure A)"
proof-
have s1: \<open>\<langle> y, x \<rangle> = 0\<close>
if a1: "x \<in> (orthogonal_complement A)"
and a2: \<open>y \<in> closure A\<close>
for x y
proof-
have \<open>\<forall> y \<in> A. \<langle> y , x \<rangle> = 0\<close>
by (simp add: a1 orthogonal_complement_orthoI')
then obtain yy where \<open>\<forall> n. yy n \<in> A\<close> and \<open>yy \<longlonglongrightarrow> y\<close>
using a2 closure_sequential by blast
have \<open>isCont (\<lambda> t. \<langle> t , x \<rangle>) y\<close>
by simp
hence \<open>(\<lambda> n. \<langle> yy n , x \<rangle>) \<longlonglongrightarrow> \<langle> y , x \<rangle>\<close>
using \<open>yy \<longlonglongrightarrow> y\<close> isCont_tendsto_compose
by fastforce
hence \<open>(\<lambda> n. 0) \<longlonglongrightarrow> \<langle> y , x \<rangle>\<close>
using \<open>\<forall> y \<in> A. \<langle> y , x \<rangle> = 0\<close> \<open>\<forall> n. yy n \<in> A\<close> by simp
thus ?thesis
using limI by force
qed
hence "x \<in> orthogonal_complement (closure A)"
if a1: "x \<in> (orthogonal_complement A)"
for x
using that
by (meson orthogonal_complementI is_orthogonal_sym)
moreover have \<open>x \<in> (orthogonal_complement A)\<close>
if "x \<in> (orthogonal_complement (closure A))"
for x
using that
by (meson closure_subset orthogonal_complement_orthoI orthogonal_complementI subset_eq)
ultimately show ?thesis by blast
qed
lemma is_orthogonal_closure:
assumes \<open>\<And>s. s \<in> S \<Longrightarrow> is_orthogonal a s\<close>
assumes \<open>x \<in> closure S\<close>
shows \<open>is_orthogonal a x\<close>
by (metis assms(1) assms(2) orthogonal_complementI orthogonal_complement_of_closure orthogonal_complement_orthoI)
lemma is_orthogonal_cspan:
assumes a1: "\<And>s. s \<in> S \<Longrightarrow> is_orthogonal a s" and a3: "x \<in> cspan S"
shows "\<langle>a, x\<rangle> = 0"
proof-
have "\<exists>t r. finite t \<and> t \<subseteq> S \<and> (\<Sum>a\<in>t. r a *\<^sub>C a) = x"
using complex_vector.span_explicit
by (smt a3 mem_Collect_eq)
then obtain t r where b1: "finite t" and b2: "t \<subseteq> S" and b3: "(\<Sum>a\<in>t. r a *\<^sub>C a) = x"
by blast
have x1: "\<langle>a, i\<rangle> = 0"
if "i\<in>t" for i
using b2 a1 that by blast
have "\<langle>a, x\<rangle> = \<langle>a, (\<Sum>i\<in>t. r i *\<^sub>C i)\<rangle>"
by (simp add: b3)
also have "\<dots> = (\<Sum>i\<in>t. r i *\<^sub>C \<langle>a, i\<rangle>)"
by (simp add: cinner_sum_right)
also have "\<dots> = 0"
using x1 by simp
finally show ?thesis.
qed
lemma ccspan_leq_ortho_ccspan:
assumes "\<And>s t. s\<in>S \<Longrightarrow> t\<in>T \<Longrightarrow> is_orthogonal s t"
shows "ccspan S \<le> - (ccspan T)"
using assms apply transfer
by (smt (verit, ccfv_threshold) is_orthogonal_closure is_orthogonal_cspan is_orthogonal_sym orthogonal_complementI subsetI)
lemma double_orthogonal_complement_increasing[simp]:
shows "M \<subseteq> orthogonal_complement (orthogonal_complement M)"
proof (rule subsetI)
fix x assume s1: "x \<in> M"
have \<open>\<forall> y \<in> (orthogonal_complement M). \<langle> x, y \<rangle> = 0\<close>
using s1 orthogonal_complement_orthoI' by auto
hence \<open>x \<in> orthogonal_complement (orthogonal_complement M)\<close>
by (simp add: orthogonal_complement_def)
then show "x \<in> orthogonal_complement (orthogonal_complement M)"
by blast
qed
lemma orthonormal_basis_of_cspan:
fixes S::"'a::complex_inner set"
assumes "finite S"
shows "\<exists>A. is_ortho_set A \<and> (\<forall>x\<in>A. norm x = 1) \<and> cspan A = cspan S \<and> finite A"
proof (use assms in induction)
case empty
show ?case
apply (rule exI[of _ "{}"])
by auto
next
case (insert s S)
from insert.IH
obtain A where orthoA: "is_ortho_set A" and normA: "\<And>x. x\<in>A \<Longrightarrow> norm x = 1" and spanA: "cspan A = cspan S" and finiteA: "finite A"
by auto
show ?case
proof (cases \<open>s \<in> cspan S\<close>)
case True
then have \<open>cspan (insert s S) = cspan S\<close>
by (simp add: complex_vector.span_redundant)
with orthoA normA spanA finiteA
show ?thesis
by auto
next
case False
obtain a where a_ortho: \<open>\<And>x. x\<in>A \<Longrightarrow> is_orthogonal x a\<close> and sa_span: \<open>s - a \<in> cspan A\<close>
proof (atomize_elim, use \<open>finite A\<close> \<open>is_ortho_set A\<close> in induction)
case empty
then show ?case
by auto
next
case (insert x A)
then obtain a where orthoA: \<open>\<And>x. x \<in> A \<Longrightarrow> is_orthogonal x a\<close> and sa: \<open>s - a \<in> cspan A\<close>
by (meson is_ortho_set_antimono subset_insertI)
define a' where \<open>a' = a - cinner x a *\<^sub>C inverse (cinner x x) *\<^sub>C x\<close>
have \<open>is_orthogonal x a'\<close>
unfolding a'_def cinner_diff_right cinner_scaleC_right
apply (cases \<open>cinner x x = 0\<close>)
by auto
have orthoA: \<open>is_orthogonal y a'\<close> if \<open>y \<in> A\<close> for y
unfolding a'_def cinner_diff_right cinner_scaleC_right
apply auto by (metis insert.prems insertCI is_ortho_set_def mult_not_zero orthoA that)
have \<open>s - a' \<in> cspan (insert x A)\<close>
unfolding a'_def apply auto
by (metis (no_types, lifting) complex_vector.span_breakdown_eq diff_add_cancel diff_diff_add sa)
with \<open>is_orthogonal x a'\<close> orthoA
show ?case
apply (rule_tac exI[of _ a'])
by auto
qed
from False sa_span
have \<open>a \<noteq> 0\<close>
unfolding spanA by auto
define a' where \<open>a' = inverse (norm a) *\<^sub>C a\<close>
with \<open>a \<noteq> 0\<close> have \<open>norm a' = 1\<close>
by (simp add: norm_inverse)
have a: \<open>a = norm a *\<^sub>C a'\<close>
by (simp add: \<open>a \<noteq> 0\<close> a'_def)
from sa_span spanA
have a'_span: \<open>a' \<in> cspan (insert s S)\<close>
unfolding a'_def
by (metis complex_vector.eq_span_insert_eq complex_vector.span_scale complex_vector.span_superset in_mono insertI1)
from sa_span
have s_span: \<open>s \<in> cspan (insert a' A)\<close>
apply (subst (asm) a)
using complex_vector.span_breakdown_eq by blast
from \<open>a \<noteq> 0\<close> a_ortho orthoA
have ortho: "is_ortho_set (insert a' A)"
unfolding is_ortho_set_def a'_def
apply auto
by (meson is_orthogonal_sym)
have span: \<open>cspan (insert a' A) = cspan (insert s S)\<close>
using a'_span s_span spanA apply auto
apply (metis (full_types) complex_vector.span_breakdown_eq complex_vector.span_redundant insert_commute s_span)
by (metis (full_types) complex_vector.span_breakdown_eq complex_vector.span_redundant insert_commute s_span)
show ?thesis
apply (rule exI[of _ \<open>insert a' A\<close>])
by (simp add: ortho \<open>norm a' = 1\<close> normA finiteA span)
qed
qed
lemma is_ortho_set_cindependent:
assumes "is_ortho_set A"
shows "cindependent A"
proof -
have "u v = 0"
if b1: "finite t" and b2: "t \<subseteq> A" and b3: "(\<Sum>v\<in>t. u v *\<^sub>C v) = 0" and b4: "v \<in> t"
for t u v
proof -
have "\<langle>v, v'\<rangle> = 0" if c1: "v'\<in>t-{v}" for v'
by (metis DiffE assms b2 b4 insertI1 is_ortho_set_antimono is_ortho_set_def that)
hence sum0: "(\<Sum>v'\<in>t-{v}. u v' * \<langle>v, v'\<rangle>) = 0"
by simp
have "\<langle>v, (\<Sum>v'\<in>t. u v' *\<^sub>C v')\<rangle> = (\<Sum>v'\<in>t. u v' * \<langle>v, v'\<rangle>)"
using b1
by (metis (mono_tags, lifting) cinner_scaleC_right cinner_sum_right sum.cong)
also have "\<dots> = u v * \<langle>v, v\<rangle> + (\<Sum>v'\<in>t-{v}. u v' * \<langle>v, v'\<rangle>)"
by (meson b1 b4 sum.remove)
also have "\<dots> = u v * \<langle>v, v\<rangle>"
using sum0 by simp
finally have "\<langle>v, (\<Sum>v'\<in>t. u v' *\<^sub>C v')\<rangle> = u v * \<langle>v, v\<rangle>"
by blast
hence "u v * \<langle>v, v\<rangle> = 0" using b3 by simp
moreover have "\<langle>v, v\<rangle> \<noteq> 0"
using assms is_ortho_set_def b2 b4 by auto
ultimately show "u v = 0" by simp
qed
thus ?thesis using complex_vector.independent_explicit_module
by (smt cdependent_raw_def)
qed
lemma onb_expansion_finite:
includes notation_norm
fixes T::\<open>'a::{complex_inner,cfinite_dim} set\<close>
assumes a1: \<open>cspan T = UNIV\<close> and a3: \<open>is_ortho_set T\<close>
and a4: \<open>\<And>t. t\<in>T \<Longrightarrow> \<parallel>t\<parallel> = 1\<close>
shows \<open>x = (\<Sum>t\<in>T. \<langle> t, x \<rangle> *\<^sub>C t)\<close>
proof -
have \<open>finite T\<close>
apply (rule cindependent_cfinite_dim_finite)
by (simp add: a3 is_ortho_set_cindependent)
have \<open>closure (complex_vector.span T) = complex_vector.span T\<close>
by (simp add: a1)
have \<open>{\<Sum>a\<in>t. r a *\<^sub>C a |t r. finite t \<and> t \<subseteq> T} = {\<Sum>a\<in>T. r a *\<^sub>C a |r. True}\<close>
apply auto
apply (rule_tac x=\<open>\<lambda>a. if a \<in> t then r a else 0\<close> in exI)
apply (simp add: \<open>finite T\<close> sum.mono_neutral_cong_right)
using \<open>finite T\<close> by blast
have f1: "\<forall>A. {a. \<exists>Aa f. (a::'a) = (\<Sum>a\<in>Aa. f a *\<^sub>C a) \<and> finite Aa \<and> Aa \<subseteq> A} = cspan A"
by (simp add: complex_vector.span_explicit)
have f2: "\<forall>a. (\<exists>f. a = (\<Sum>a\<in>T. f a *\<^sub>C a)) \<or> (\<forall>A. (\<forall>f. a \<noteq> (\<Sum>a\<in>A. f a *\<^sub>C a)) \<or> infinite A \<or> \<not> A \<subseteq> T)"
using \<open>{\<Sum>a\<in>t. r a *\<^sub>C a |t r. finite t \<and> t \<subseteq> T} = {\<Sum>a\<in>T. r a *\<^sub>C a |r. True}\<close> by auto
have f3: "\<forall>A a. (\<exists>Aa f. (a::'a) = (\<Sum>a\<in>Aa. f a *\<^sub>C a) \<and> finite Aa \<and> Aa \<subseteq> A) \<or> a \<notin> cspan A"
using f1 by blast
have "cspan T = UNIV"
by (metis (full_types, lifting) \<open>complex_vector.span T = UNIV\<close>)
hence \<open>\<exists> r. x = (\<Sum> a\<in>T. r a *\<^sub>C a)\<close>
using f3 f2 by blast
then obtain r where \<open>x = (\<Sum> a\<in>T. r a *\<^sub>C a)\<close>
by blast
have \<open>r a = \<langle>a, x\<rangle>\<close> if \<open>a \<in> T\<close> for a
proof-
have \<open>norm a = 1\<close>
using a4
by (simp add: \<open>a \<in> T\<close>)
moreover have \<open>norm a = sqrt (norm \<langle>a, a\<rangle>)\<close>
using norm_eq_sqrt_cinner by auto
ultimately have \<open>sqrt (norm \<langle>a, a\<rangle>) = 1\<close>
by simp
hence \<open>norm \<langle>a, a\<rangle> = 1\<close>
using real_sqrt_eq_1_iff by blast
moreover have \<open>\<langle>a, a\<rangle> \<in> \<real>\<close>
by (simp add: cinner_real)
moreover have \<open>\<langle>a, a\<rangle> \<ge> 0\<close>
using cinner_ge_zero by blast
ultimately have w1: \<open>\<langle>a, a\<rangle> = 1\<close>
by (metis \<open>0 \<le> \<langle>a, a\<rangle>\<close> \<open>cmod \<langle>a, a\<rangle> = 1\<close> complex_of_real_cmod of_real_1)
have \<open>r t * \<langle>a, t\<rangle> = 0\<close> if \<open>t \<in> T-{a}\<close> for t
by (metis DiffD1 DiffD2 \<open>a \<in> T\<close> a3 is_ortho_set_def mult_eq_0_iff singletonI that)
hence s1: \<open>(\<Sum> t\<in>T-{a}. r t * \<langle>a, t\<rangle>) = 0\<close>
by (simp add: \<open>\<And>t. t \<in> T - {a} \<Longrightarrow> r t * \<langle>a, t\<rangle> = 0\<close>)
have \<open>\<langle>a, x\<rangle> = \<langle>a, (\<Sum> t\<in>T. r t *\<^sub>C t)\<rangle>\<close>
using \<open>x = (\<Sum> a\<in>T. r a *\<^sub>C a)\<close>
by simp
also have \<open>\<dots> = (\<Sum> t\<in>T. \<langle>a, r t *\<^sub>C t\<rangle>)\<close>
using cinner_sum_right by blast
also have \<open>\<dots> = (\<Sum> t\<in>T. r t * \<langle>a, t\<rangle>)\<close>
by simp
also have \<open>\<dots> = r a * \<langle>a, a\<rangle> + (\<Sum> t\<in>T-{a}. r t * \<langle>a, t\<rangle>)\<close>
using \<open>a \<in> T\<close>
by (meson \<open>finite T\<close> sum.remove)
also have \<open>\<dots> = r a * \<langle>a, a\<rangle>\<close>
using s1
by simp
also have \<open>\<dots> = r a\<close>
by (simp add: w1)
finally show ?thesis by auto
qed
thus ?thesis
using \<open>x = (\<Sum> a\<in>T. r a *\<^sub>C a)\<close>
by fastforce
qed
subsection \<open>Projections\<close>
lemma smallest_norm_exists:
\<comment> \<open>Theorem 2.5 in @{cite conway2013course} (inside the proof)\<close>
includes notation_norm
fixes M :: \<open>'a::chilbert_space set\<close>
assumes q1: \<open>convex M\<close> and q2: \<open>closed M\<close> and q3: \<open>M \<noteq> {}\<close>
shows \<open>\<exists>k. is_arg_min (\<lambda> x. \<parallel>x\<parallel>) (\<lambda> t. t \<in> M) k\<close>
proof-
define d where \<open>d = Inf { \<parallel>x\<parallel>^2 | x. x \<in> M }\<close>
have w4: \<open>{ \<parallel>x\<parallel>^2 | x. x \<in> M } \<noteq> {}\<close>
by (simp add: assms(3))
have \<open>\<forall> x. \<parallel>x\<parallel>^2 \<ge> 0\<close>
by simp
hence bdd_below1: \<open>bdd_below { \<parallel>x\<parallel>^2 | x. x \<in> M }\<close>
by fastforce
have \<open>d \<le> \<parallel>x\<parallel>^2\<close>
if a1: "x \<in> M"
for x
proof-
have "\<forall>v. (\<exists>w. Re (\<langle>v , v\<rangle> ) = \<parallel>w\<parallel>\<^sup>2 \<and> w \<in> M) \<or> v \<notin> M"
by (metis (no_types) power2_norm_eq_cinner')
hence "Re (\<langle>x , x\<rangle> ) \<in> {\<parallel>v\<parallel>\<^sup>2 |v. v \<in> M}"
using a1 by blast
thus ?thesis
unfolding d_def
by (metis (lifting) bdd_below1 cInf_lower power2_norm_eq_cinner')
qed
have \<open>\<forall> \<epsilon> > 0. \<exists> t \<in> { \<parallel>x\<parallel>^2 | x. x \<in> M }. t < d + \<epsilon>\<close>
unfolding d_def
using w4 bdd_below1
by (meson cInf_lessD less_add_same_cancel1)
hence \<open>\<forall> \<epsilon> > 0. \<exists> x \<in> M. \<parallel>x\<parallel>^2 < d + \<epsilon>\<close>
by auto
hence \<open>\<forall> \<epsilon> > 0. \<exists> x \<in> M. \<parallel>x\<parallel>^2 < d + \<epsilon>\<close>
by (simp add: \<open>\<And>x. x \<in> M \<Longrightarrow> d \<le> \<parallel>x\<parallel>\<^sup>2\<close>)
hence w1: \<open>\<forall> n::nat. \<exists> x \<in> M. \<parallel>x\<parallel>^2 < d + 1/(n+1)\<close> by auto
then obtain r::\<open>nat \<Rightarrow> 'a\<close> where w2: \<open>\<forall> n. r n \<in> M \<and> \<parallel> r n \<parallel>^2 < d + 1/(n+1)\<close>
by metis
have w3: \<open>\<forall> n. r n \<in> M\<close>
by (simp add: w2)
have \<open>\<forall> n. \<parallel> r n \<parallel>^2 < d + 1/(n+1)\<close>
by (simp add: w2)
have w5: \<open>\<parallel> (r n) - (r m) \<parallel>^2 < 2*(1/(n+1) + 1/(m+1))\<close>
for m n
proof-
have w6: \<open>\<parallel> r n \<parallel>^2 < d + 1/(n+1)\<close>
by (metis w2 of_nat_1 of_nat_add)
have \<open> \<parallel> r m \<parallel>^2 < d + 1/(m+1)\<close>
by (metis w2 of_nat_1 of_nat_add)
have \<open>(r n) \<in> M\<close>
by (simp add: \<open>\<forall>n. r n \<in> M\<close>)
moreover have \<open>(r m) \<in> M\<close>
by (simp add: \<open>\<forall>n. r n \<in> M\<close>)
ultimately have \<open>(1/2) *\<^sub>R (r n) + (1/2) *\<^sub>R (r m) \<in> M\<close>
using \<open>convex M\<close>
by (simp add: convexD)
hence \<open>\<parallel> (1/2) *\<^sub>R (r n) + (1/2) *\<^sub>R (r m) \<parallel>^2 \<ge> d\<close>
by (simp add: \<open>\<And>x. x \<in> M \<Longrightarrow> d \<le> \<parallel>x\<parallel>\<^sup>2\<close>)
have \<open>\<parallel> (1/2) *\<^sub>R (r n) - (1/2) *\<^sub>R (r m) \<parallel>^2
= (1/2)*( \<parallel> r n \<parallel>^2 + \<parallel> r m \<parallel>^2 ) - \<parallel> (1/2) *\<^sub>R (r n) + (1/2) *\<^sub>R (r m) \<parallel>^2\<close>
by (smt (z3) div_by_1 field_sum_of_halves nonzero_mult_div_cancel_left parallelogram_law polar_identity power2_norm_eq_cinner' scaleR_collapse times_divide_eq_left)
also have \<open>...
< (1/2)*( d + 1/(n+1) + \<parallel> r m \<parallel>^2 ) - \<parallel> (1/2) *\<^sub>R (r n) + (1/2) *\<^sub>R (r m) \<parallel>^2\<close>
using \<open>\<parallel>r n\<parallel>\<^sup>2 < d + 1 / real (n + 1)\<close> by auto
also have \<open>...
< (1/2)*( d + 1/(n+1) + d + 1/(m+1) ) - \<parallel> (1/2) *\<^sub>R (r n) + (1/2) *\<^sub>R (r m) \<parallel>^2\<close>
using \<open>\<parallel>r m\<parallel>\<^sup>2 < d + 1 / real (m + 1)\<close> by auto
also have \<open>...
\<le> (1/2)*( d + 1/(n+1) + d + 1/(m+1) ) - d\<close>
by (simp add: \<open>d \<le> \<parallel>(1 / 2) *\<^sub>R r n + (1 / 2) *\<^sub>R r m\<parallel>\<^sup>2\<close>)
also have \<open>...
\<le> (1/2)*( 1/(n+1) + 1/(m+1) + 2*d ) - d\<close>
by simp
also have \<open>...
\<le> (1/2)*( 1/(n+1) + 1/(m+1) ) + (1/2)*(2*d) - d\<close>
by (simp add: distrib_left)
also have \<open>...
\<le> (1/2)*( 1/(n+1) + 1/(m+1) ) + d - d\<close>
by simp
also have \<open>...
\<le> (1/2)*( 1/(n+1) + 1/(m+1) )\<close>
by simp
finally have \<open> \<parallel>(1 / 2) *\<^sub>R r n - (1 / 2) *\<^sub>R r m\<parallel>\<^sup>2 < 1 / 2 * (1 / real (n + 1) + 1 / real (m + 1)) \<close>
by blast
hence \<open> \<parallel>(1 / 2) *\<^sub>R (r n - r m) \<parallel>\<^sup>2 < (1 / 2) * (1 / real (n + 1) + 1 / real (m + 1)) \<close>
by (simp add: real_vector.scale_right_diff_distrib)
hence \<open> ((1 / 2)*\<parallel> (r n - r m) \<parallel>)\<^sup>2 < (1 / 2) * (1 / real (n + 1) + 1 / real (m + 1)) \<close>
by simp
hence \<open> (1 / 2)^2*(\<parallel> (r n - r m) \<parallel>)\<^sup>2 < (1 / 2) * (1 / real (n + 1) + 1 / real (m + 1)) \<close>
by (metis power_mult_distrib)
hence \<open> (1 / 4) *(\<parallel> (r n - r m) \<parallel>)\<^sup>2 < (1 / 2) * (1 / real (n + 1) + 1 / real (m + 1)) \<close>
by (simp add: power_divide)
hence \<open> \<parallel> (r n - r m) \<parallel>\<^sup>2 < 2 * (1 / real (n + 1) + 1 / real (m + 1)) \<close>
by simp
thus ?thesis
by (metis of_nat_1 of_nat_add)
qed
hence "\<exists> N. \<forall> n m. n \<ge> N \<and> m \<ge> N \<longrightarrow> \<parallel> (r n) - (r m) \<parallel>^2 < \<epsilon>^2"
if "\<epsilon> > 0"
for \<epsilon>
proof-
obtain N::nat where \<open>1/(N + 1) < \<epsilon>^2/4\<close>
using LIMSEQ_ignore_initial_segment[OF lim_inverse_n', where k=1]
by (metis Suc_eq_plus1 \<open>0 < \<epsilon>\<close> nat_approx_posE zero_less_divide_iff zero_less_numeral
zero_less_power )
hence \<open>4/(N + 1) < \<epsilon>^2\<close>
by simp
have "2*(1/(n+1) + 1/(m+1)) < \<epsilon>^2"
if f1: "n \<ge> N" and f2: "m \<ge> N"
for m n::nat
proof-
have \<open>1/(n+1) \<le> 1/(N+1)\<close>
by (simp add: f1 linordered_field_class.frac_le)
moreover have \<open>1/(m+1) \<le> 1/(N+1)\<close>
by (simp add: f2 linordered_field_class.frac_le)
ultimately have \<open>2*(1/(n+1) + 1/(m+1)) \<le> 4/(N+1)\<close>
by simp
thus ?thesis using \<open>4/(N + 1) < \<epsilon>^2\<close>
by linarith
qed
hence "\<parallel> (r n) - (r m) \<parallel>^2 < \<epsilon>^2"
if y1: "n \<ge> N" and y2: "m \<ge> N"
for m n::nat
using that
by (smt \<open>\<And>n m. \<parallel>r n - r m\<parallel>\<^sup>2 < 2 * (1 / (real n + 1) + 1 / (real m + 1))\<close> of_nat_1 of_nat_add)
thus ?thesis
by blast
qed
hence \<open>\<forall> \<epsilon> > 0. \<exists> N::nat. \<forall> n m::nat. n \<ge> N \<and> m \<ge> N \<longrightarrow> \<parallel> (r n) - (r m) \<parallel>^2 < \<epsilon>^2\<close>
by blast
hence \<open>\<forall> \<epsilon> > 0. \<exists> N::nat. \<forall> n m::nat. n \<ge> N \<and> m \<ge> N \<longrightarrow> \<parallel> (r n) - (r m) \<parallel> < \<epsilon>\<close>
by (meson less_eq_real_def power_less_imp_less_base)
hence \<open>Cauchy r\<close>
using CauchyI by fastforce
then obtain k where \<open>r \<longlonglongrightarrow> k\<close>
using convergent_eq_Cauchy by auto
have \<open>k \<in> M\<close> using \<open>closed M\<close>
using \<open>\<forall>n. r n \<in> M\<close> \<open>r \<longlonglongrightarrow> k\<close> closed_sequentially by auto
have \<open>(\<lambda> n. \<parallel> r n \<parallel>^2) \<longlonglongrightarrow> \<parallel> k \<parallel>^2\<close>
by (simp add: \<open>r \<longlonglongrightarrow> k\<close> tendsto_norm tendsto_power)
moreover have \<open>(\<lambda> n. \<parallel> r n \<parallel>^2) \<longlonglongrightarrow> d\<close>
proof-
have \<open>\<bar>\<parallel> r n \<parallel>^2 - d\<bar> < 1/(n+1)\<close> for n :: nat
using \<open>\<And>x. x \<in> M \<Longrightarrow> d \<le> \<parallel>x\<parallel>\<^sup>2\<close> \<open>\<forall>n. r n \<in> M \<and> \<parallel>r n\<parallel>\<^sup>2 < d + 1 / (real n + 1)\<close> of_nat_1 of_nat_add
by smt
moreover have \<open>(\<lambda>n. 1 / real (n + 1)) \<longlonglongrightarrow> 0\<close>
using LIMSEQ_ignore_initial_segment[OF lim_inverse_n', where k=1] by blast
ultimately have \<open>(\<lambda> n. \<bar>\<parallel> r n \<parallel>^2 - d\<bar> ) \<longlonglongrightarrow> 0\<close>
by (simp add: LIMSEQ_norm_0)
hence \<open>(\<lambda> n. \<parallel> r n \<parallel>^2 - d ) \<longlonglongrightarrow> 0\<close>
by (simp add: tendsto_rabs_zero_iff)
moreover have \<open>(\<lambda> n. d ) \<longlonglongrightarrow> d\<close>
by simp
ultimately have \<open>(\<lambda> n. (\<parallel> r n \<parallel>^2 - d)+d ) \<longlonglongrightarrow> 0+d\<close>
using tendsto_add by fastforce
thus ?thesis by simp
qed
ultimately have \<open>d = \<parallel> k \<parallel>^2\<close>
using LIMSEQ_unique by auto
hence \<open>t \<in> M \<Longrightarrow> \<parallel> k \<parallel>^2 \<le> \<parallel> t \<parallel>^2\<close> for t
using \<open>\<And>x. x \<in> M \<Longrightarrow> d \<le> \<parallel>x\<parallel>\<^sup>2\<close> by auto
hence q1: \<open>\<exists> k. is_arg_min (\<lambda> x. \<parallel>x\<parallel>^2) (\<lambda> t. t \<in> M) k\<close>
using \<open>k \<in> M\<close>
is_arg_min_def \<open>d = \<parallel>k\<parallel>\<^sup>2\<close>
by smt
thus \<open>\<exists> k. is_arg_min (\<lambda> x. \<parallel>x\<parallel>) (\<lambda> t. t \<in> M) k\<close>
by (smt is_arg_min_def norm_ge_zero power2_eq_square power2_le_imp_le)
qed
lemma smallest_norm_unique:
\<comment> \<open>Theorem 2.5 in @{cite conway2013course} (inside the proof)\<close>
includes notation_norm
fixes M :: \<open>'a::complex_inner set\<close>
assumes q1: \<open>convex M\<close>
assumes r: \<open>is_arg_min (\<lambda> x. \<parallel>x\<parallel>) (\<lambda> t. t \<in> M) r\<close>
assumes s: \<open>is_arg_min (\<lambda> x. \<parallel>x\<parallel>) (\<lambda> t. t \<in> M) s\<close>
shows \<open>r = s\<close>
proof -
have \<open>r \<in> M\<close>
using \<open>is_arg_min (\<lambda>x. \<parallel>x\<parallel>) (\<lambda> t. t \<in> M) r\<close>
by (simp add: is_arg_min_def)
moreover have \<open>s \<in> M\<close>
using \<open>is_arg_min (\<lambda>x. \<parallel>x\<parallel>) (\<lambda> t. t \<in> M) s\<close>
by (simp add: is_arg_min_def)
ultimately have \<open>((1/2) *\<^sub>R r + (1/2) *\<^sub>R s) \<in> M\<close> using \<open>convex M\<close>
by (simp add: convexD)
hence \<open>\<parallel>r\<parallel> \<le> \<parallel> (1/2) *\<^sub>R r + (1/2) *\<^sub>R s \<parallel>\<close>
by (metis is_arg_min_linorder r)
hence u2: \<open>\<parallel>r\<parallel>^2 \<le> \<parallel> (1/2) *\<^sub>R r + (1/2) *\<^sub>R s \<parallel>^2\<close>
using norm_ge_zero power_mono by blast
have \<open>\<parallel>r\<parallel> \<le> \<parallel>s\<parallel>\<close>
using r s is_arg_min_def
by (metis is_arg_min_linorder)
moreover have \<open>\<parallel>s\<parallel> \<le> \<parallel>r\<parallel>\<close>
using r s is_arg_min_def
by (metis is_arg_min_linorder)
ultimately have u3: \<open>\<parallel>r\<parallel> = \<parallel>s\<parallel>\<close> by simp
have \<open>\<parallel> (1/2) *\<^sub>R r - (1/2) *\<^sub>R s \<parallel>^2 \<le> 0\<close>
using u2 u3 parallelogram_law
by (smt (verit, ccfv_SIG) polar_identity_minus power2_norm_eq_cinner' scaleR_add_right scaleR_half_double)
hence \<open>\<parallel> (1/2) *\<^sub>R r - (1/2) *\<^sub>R s \<parallel>^2 = 0\<close>
by simp
hence \<open>\<parallel> (1/2) *\<^sub>R r - (1/2) *\<^sub>R s \<parallel> = 0\<close>
by auto
hence \<open>(1/2) *\<^sub>R r - (1/2) *\<^sub>R s = 0\<close>
using norm_eq_zero by blast
thus ?thesis by simp
qed
theorem smallest_dist_exists:
\<comment> \<open>Theorem 2.5 in @{cite conway2013course}\<close>
fixes M::\<open>'a::chilbert_space set\<close> and h
assumes a1: \<open>convex M\<close> and a2: \<open>closed M\<close> and a3: \<open>M \<noteq> {}\<close>
shows \<open>\<exists>k. is_arg_min (\<lambda> x. dist x h) (\<lambda> x. x \<in> M) k\<close>
proof-
have *: "is_arg_min (\<lambda>x. dist x h) (\<lambda>x. x\<in>M) (k+h) \<longleftrightarrow> is_arg_min (\<lambda>x. norm x) (\<lambda>x. x\<in>(\<lambda>x. x-h) ` M) k" for k
unfolding dist_norm is_arg_min_def apply auto using add_implies_diff by blast
have \<open>\<exists>k. is_arg_min (\<lambda>x. dist x h) (\<lambda>x. x\<in>M) (k+h)\<close>
apply (subst *)
apply (rule smallest_norm_exists)
using assms by (auto simp: closed_translation_subtract)
then show \<open>\<exists>k. is_arg_min (\<lambda> x. dist x h) (\<lambda> x. x \<in> M) k\<close>
by metis
qed
theorem smallest_dist_unique:
\<comment> \<open>Theorem 2.5 in @{cite conway2013course}\<close>
fixes M::\<open>'a::complex_inner set\<close> and h
assumes a1: \<open>convex M\<close>
assumes \<open>is_arg_min (\<lambda> x. dist x h) (\<lambda> x. x \<in> M) r\<close>
assumes \<open>is_arg_min (\<lambda> x. dist x h) (\<lambda> x. x \<in> M) s\<close>
shows \<open>r = s\<close>
proof-
have *: "is_arg_min (\<lambda>x. dist x h) (\<lambda>x. x\<in>M) k \<longleftrightarrow> is_arg_min (\<lambda>x. norm x) (\<lambda>x. x\<in>(\<lambda>x. x-h) ` M) (k-h)" for k
unfolding dist_norm is_arg_min_def by auto
have \<open>r - h = s - h\<close>
using _ assms(2,3)[unfolded *] apply (rule smallest_norm_unique)
by (simp add: a1)
thus \<open>r = s\<close>
by auto
qed
\<comment> \<open>Theorem 2.6 in @{cite conway2013course}\<close>
theorem smallest_dist_is_ortho:
fixes M::\<open>'a::complex_inner set\<close> and h k::'a
assumes b1: \<open>closed_csubspace M\<close>
shows \<open>(is_arg_min (\<lambda> x. dist x h) (\<lambda> x. x \<in> M) k) \<longleftrightarrow>
h - k \<in> (orthogonal_complement M) \<and> k \<in> M\<close>
proof-
include notation_norm
have \<open>csubspace M\<close>
using \<open>closed_csubspace M\<close> unfolding closed_csubspace_def by blast
have r1: \<open>2 * Re (\<langle> h - k , f \<rangle>) \<le> \<parallel> f \<parallel>^2\<close>
if "f \<in> M" and \<open>k \<in> M\<close> and \<open>is_arg_min (\<lambda>x. dist x h) (\<lambda> x. x \<in> M) k\<close>
for f
proof-
have \<open>k + f \<in> M\<close>
using \<open>csubspace M\<close>
by (simp add:complex_vector.subspace_add that)
have "\<forall>f A a b. \<not> is_arg_min f (\<lambda> x. x \<in> A) (a::'a) \<or> (f a::real) \<le> f b \<or> b \<notin> A"
by (metis (no_types) is_arg_min_linorder)
hence "dist k h \<le> dist (f + k) h"
by (metis \<open>is_arg_min (\<lambda>x. dist x h) (\<lambda> x. x \<in> M) k\<close> \<open>k + f \<in> M\<close> add.commute)
hence \<open>dist h k \<le> dist h (k + f)\<close>
by (simp add: add.commute dist_commute)
hence \<open>\<parallel> h - k \<parallel> \<le> \<parallel> h - (k + f) \<parallel>\<close>
by (simp add: dist_norm)
hence \<open>\<parallel> h - k \<parallel>^2 \<le> \<parallel> h - (k + f) \<parallel>^2\<close>
by (simp add: power_mono)
also have \<open>... \<le> \<parallel> (h - k) - f \<parallel>^2\<close>
by (simp add: diff_diff_add)
also have \<open>... \<le> \<parallel> (h - k) \<parallel>^2 + \<parallel> f \<parallel>^2 - 2 * Re (\<langle> h - k , f \<rangle>)\<close>
by (simp add: polar_identity_minus)
finally have \<open>\<parallel> (h - k) \<parallel>^2 \<le> \<parallel> (h - k) \<parallel>^2 + \<parallel> f \<parallel>^2 - 2 * Re (\<langle> h - k , f \<rangle>)\<close>
by simp
thus ?thesis by simp
qed
have q4: \<open>\<forall> c > 0. 2 * Re (\<langle> h - k , f \<rangle>) \<le> c\<close>
if \<open>\<forall>c>0. 2 * Re (\<langle>h - k , f\<rangle> ) \<le> c * \<parallel>f\<parallel>\<^sup>2\<close>
for f
proof (cases \<open>\<parallel> f \<parallel>^2 > 0\<close>)
case True
hence \<open>\<forall> c > 0. 2 * Re (\<langle> h - k , f \<rangle>) \<le> (c/\<parallel> f \<parallel>^2)*\<parallel> f \<parallel>^2\<close>
using that linordered_field_class.divide_pos_pos by blast
thus ?thesis
using True by auto
next
case False
hence \<open>\<parallel> f \<parallel>^2 = 0\<close>
by simp
thus ?thesis
by auto
qed
have q3: \<open>\<forall> c::real. c > 0 \<longrightarrow> 2 * Re (\<langle> h - k , f \<rangle>) \<le> 0\<close>
if a3: \<open>\<forall>f. f \<in> M \<longrightarrow> (\<forall>c>0. 2 * Re \<langle>h - k , f\<rangle> \<le> c * \<parallel>f\<parallel>\<^sup>2)\<close>
and a2: "f \<in> M"
and a1: "is_arg_min (\<lambda> x. dist x h) (\<lambda> x. x \<in> M) k"