1 (* Title: HOL/Library/Inner_Product.thy |
1 (* Title: HOL/Library/Inner_Product.thy |
2 Author: Brian Huffman |
2 Author: Brian Huffman |
3 *) |
3 *) |
4 |
4 |
5 section {* Inner Product Spaces and the Gradient Derivative *} |
5 section \<open>Inner Product Spaces and the Gradient Derivative\<close> |
6 |
6 |
7 theory Inner_Product |
7 theory Inner_Product |
8 imports "~~/src/HOL/Complex_Main" |
8 imports "~~/src/HOL/Complex_Main" |
9 begin |
9 begin |
10 |
10 |
11 subsection {* Real inner product spaces *} |
11 subsection \<open>Real inner product spaces\<close> |
12 |
12 |
13 text {* |
13 text \<open> |
14 Temporarily relax type constraints for @{term "open"}, |
14 Temporarily relax type constraints for @{term "open"}, |
15 @{term dist}, and @{term norm}. |
15 @{term dist}, and @{term norm}. |
16 *} |
16 \<close> |
17 |
17 |
18 setup {* Sign.add_const_constraint |
18 setup \<open>Sign.add_const_constraint |
19 (@{const_name "open"}, SOME @{typ "'a::open set \<Rightarrow> bool"}) *} |
19 (@{const_name "open"}, SOME @{typ "'a::open set \<Rightarrow> bool"})\<close> |
20 |
20 |
21 setup {* Sign.add_const_constraint |
21 setup \<open>Sign.add_const_constraint |
22 (@{const_name dist}, SOME @{typ "'a::dist \<Rightarrow> 'a \<Rightarrow> real"}) *} |
22 (@{const_name dist}, SOME @{typ "'a::dist \<Rightarrow> 'a \<Rightarrow> real"})\<close> |
23 |
23 |
24 setup {* Sign.add_const_constraint |
24 setup \<open>Sign.add_const_constraint |
25 (@{const_name norm}, SOME @{typ "'a::norm \<Rightarrow> real"}) *} |
25 (@{const_name norm}, SOME @{typ "'a::norm \<Rightarrow> real"})\<close> |
26 |
26 |
27 class real_inner = real_vector + sgn_div_norm + dist_norm + open_dist + |
27 class real_inner = real_vector + sgn_div_norm + dist_norm + open_dist + |
28 fixes inner :: "'a \<Rightarrow> 'a \<Rightarrow> real" |
28 fixes inner :: "'a \<Rightarrow> 'a \<Rightarrow> real" |
29 assumes inner_commute: "inner x y = inner y x" |
29 assumes inner_commute: "inner x y = inner y x" |
30 and inner_add_left: "inner (x + y) z = inner x z + inner y z" |
30 and inner_add_left: "inner (x + y) z = inner x z + inner y z" |
44 using inner_add_left [of x "- y" z] by simp |
44 using inner_add_left [of x "- y" z] by simp |
45 |
45 |
46 lemma inner_setsum_left: "inner (\<Sum>x\<in>A. f x) y = (\<Sum>x\<in>A. inner (f x) y)" |
46 lemma inner_setsum_left: "inner (\<Sum>x\<in>A. f x) y = (\<Sum>x\<in>A. inner (f x) y)" |
47 by (cases "finite A", induct set: finite, simp_all add: inner_add_left) |
47 by (cases "finite A", induct set: finite, simp_all add: inner_add_left) |
48 |
48 |
49 text {* Transfer distributivity rules to right argument. *} |
49 text \<open>Transfer distributivity rules to right argument.\<close> |
50 |
50 |
51 lemma inner_add_right: "inner x (y + z) = inner x y + inner x z" |
51 lemma inner_add_right: "inner x (y + z) = inner x y + inner x z" |
52 using inner_add_left [of y z x] by (simp only: inner_commute) |
52 using inner_add_left [of y z x] by (simp only: inner_commute) |
53 |
53 |
54 lemma inner_scaleR_right [simp]: "inner x (scaleR r y) = r * (inner x y)" |
54 lemma inner_scaleR_right [simp]: "inner x (scaleR r y) = r * (inner x y)" |
68 |
68 |
69 lemmas inner_add [algebra_simps] = inner_add_left inner_add_right |
69 lemmas inner_add [algebra_simps] = inner_add_left inner_add_right |
70 lemmas inner_diff [algebra_simps] = inner_diff_left inner_diff_right |
70 lemmas inner_diff [algebra_simps] = inner_diff_left inner_diff_right |
71 lemmas inner_scaleR = inner_scaleR_left inner_scaleR_right |
71 lemmas inner_scaleR = inner_scaleR_left inner_scaleR_right |
72 |
72 |
73 text {* Legacy theorem names *} |
73 text \<open>Legacy theorem names\<close> |
74 lemmas inner_left_distrib = inner_add_left |
74 lemmas inner_left_distrib = inner_add_left |
75 lemmas inner_right_distrib = inner_add_right |
75 lemmas inner_right_distrib = inner_add_right |
76 lemmas inner_distrib = inner_left_distrib inner_right_distrib |
76 lemmas inner_distrib = inner_left_distrib inner_right_distrib |
77 |
77 |
78 lemma inner_gt_zero_iff [simp]: "0 < inner x x \<longleftrightarrow> x \<noteq> 0" |
78 lemma inner_gt_zero_iff [simp]: "0 < inner x x \<longleftrightarrow> x \<noteq> 0" |
139 by (simp add: power2_eq_square mult.assoc) |
139 by (simp add: power2_eq_square mult.assoc) |
140 qed |
140 qed |
141 |
141 |
142 end |
142 end |
143 |
143 |
144 text {* |
144 text \<open> |
145 Re-enable constraints for @{term "open"}, |
145 Re-enable constraints for @{term "open"}, |
146 @{term dist}, and @{term norm}. |
146 @{term dist}, and @{term norm}. |
147 *} |
147 \<close> |
148 |
148 |
149 setup {* Sign.add_const_constraint |
149 setup \<open>Sign.add_const_constraint |
150 (@{const_name "open"}, SOME @{typ "'a::topological_space set \<Rightarrow> bool"}) *} |
150 (@{const_name "open"}, SOME @{typ "'a::topological_space set \<Rightarrow> bool"})\<close> |
151 |
151 |
152 setup {* Sign.add_const_constraint |
152 setup \<open>Sign.add_const_constraint |
153 (@{const_name dist}, SOME @{typ "'a::metric_space \<Rightarrow> 'a \<Rightarrow> real"}) *} |
153 (@{const_name dist}, SOME @{typ "'a::metric_space \<Rightarrow> 'a \<Rightarrow> real"})\<close> |
154 |
154 |
155 setup {* Sign.add_const_constraint |
155 setup \<open>Sign.add_const_constraint |
156 (@{const_name norm}, SOME @{typ "'a::real_normed_vector \<Rightarrow> real"}) *} |
156 (@{const_name norm}, SOME @{typ "'a::real_normed_vector \<Rightarrow> real"})\<close> |
157 |
157 |
158 lemma bounded_bilinear_inner: |
158 lemma bounded_bilinear_inner: |
159 "bounded_bilinear (inner::'a::real_inner \<Rightarrow> 'a \<Rightarrow> real)" |
159 "bounded_bilinear (inner::'a::real_inner \<Rightarrow> 'a \<Rightarrow> real)" |
160 proof |
160 proof |
161 fix x y z :: 'a and r :: real |
161 fix x y z :: 'a and r :: real |
197 |
197 |
198 lemma differentiable_inner [simp]: |
198 lemma differentiable_inner [simp]: |
199 "f differentiable (at x within s) \<Longrightarrow> g differentiable at x within s \<Longrightarrow> (\<lambda>x. inner (f x) (g x)) differentiable at x within s" |
199 "f differentiable (at x within s) \<Longrightarrow> g differentiable at x within s \<Longrightarrow> (\<lambda>x. inner (f x) (g x)) differentiable at x within s" |
200 unfolding differentiable_def by (blast intro: has_derivative_inner) |
200 unfolding differentiable_def by (blast intro: has_derivative_inner) |
201 |
201 |
202 subsection {* Class instances *} |
202 subsection \<open>Class instances\<close> |
203 |
203 |
204 instantiation real :: real_inner |
204 instantiation real :: real_inner |
205 begin |
205 begin |
206 |
206 |
207 definition inner_real_def [simp]: "inner = op *" |
207 definition inner_real_def [simp]: "inner = op *" |
261 |
261 |
262 lemma complex_inner_ii_right [simp]: "inner x ii = Im x" |
262 lemma complex_inner_ii_right [simp]: "inner x ii = Im x" |
263 unfolding inner_complex_def by simp |
263 unfolding inner_complex_def by simp |
264 |
264 |
265 |
265 |
266 subsection {* Gradient derivative *} |
266 subsection \<open>Gradient derivative\<close> |
267 |
267 |
268 definition |
268 definition |
269 gderiv :: |
269 gderiv :: |
270 "['a::real_inner \<Rightarrow> real, 'a, 'a] \<Rightarrow> bool" |
270 "['a::real_inner \<Rightarrow> real, 'a, 'a] \<Rightarrow> bool" |
271 ("(GDERIV (_)/ (_)/ :> (_))" [1000, 1000, 60] 60) |
271 ("(GDERIV (_)/ (_)/ :> (_))" [1000, 1000, 60] 60) |
337 proof - |
337 proof - |
338 have 1: "FDERIV (\<lambda>x. inner x x) x :> (\<lambda>h. inner x h + inner h x)" |
338 have 1: "FDERIV (\<lambda>x. inner x x) x :> (\<lambda>h. inner x h + inner h x)" |
339 by (intro has_derivative_inner has_derivative_ident) |
339 by (intro has_derivative_inner has_derivative_ident) |
340 have 2: "(\<lambda>h. inner x h + inner h x) = (\<lambda>h. inner h (scaleR 2 x))" |
340 have 2: "(\<lambda>h. inner x h + inner h x) = (\<lambda>h. inner h (scaleR 2 x))" |
341 by (simp add: fun_eq_iff inner_commute) |
341 by (simp add: fun_eq_iff inner_commute) |
342 have "0 < inner x x" using `x \<noteq> 0` by simp |
342 have "0 < inner x x" using \<open>x \<noteq> 0\<close> by simp |
343 then have 3: "DERIV sqrt (inner x x) :> (inverse (sqrt (inner x x)) / 2)" |
343 then have 3: "DERIV sqrt (inner x x) :> (inverse (sqrt (inner x x)) / 2)" |
344 by (rule DERIV_real_sqrt) |
344 by (rule DERIV_real_sqrt) |
345 have 4: "(inverse (sqrt (inner x x)) / 2) *\<^sub>R 2 *\<^sub>R x = sgn x" |
345 have 4: "(inverse (sqrt (inner x x)) / 2) *\<^sub>R 2 *\<^sub>R x = sgn x" |
346 by (simp add: sgn_div_norm norm_eq_sqrt_inner) |
346 by (simp add: sgn_div_norm norm_eq_sqrt_inner) |
347 show ?thesis |
347 show ?thesis |