author | huffman |
Wed, 28 Apr 2010 15:05:45 -0700 | |
changeset 36581 | bbea7f52e8e1 |
parent 36436 | 1c0f42fb92f1 |
child 36585 | f2faab7b46e7 |
permissions | -rw-r--r-- |
35253 | 1 |
(* Title: Library/Multivariate_Analysis/Euclidean_Space.thy |
33175 | 2 |
Author: Amine Chaieb, University of Cambridge |
3 |
*) |
|
4 |
||
5 |
header {* (Real) Vectors in Euclidean space, and elementary linear algebra.*} |
|
6 |
||
7 |
theory Euclidean_Space |
|
8 |
imports |
|
9 |
Complex_Main "~~/src/HOL/Decision_Procs/Dense_Linear_Order" |
|
36336 | 10 |
Finite_Cartesian_Product Infinite_Set Numeral_Type |
36333 | 11 |
Inner_Product L2_Norm |
33175 | 12 |
uses "positivstellensatz.ML" ("normarith.ML") |
13 |
begin |
|
14 |
||
15 |
subsection{* Basic componentwise operations on vectors. *} |
|
16 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
17 |
instantiation cart :: (plus,finite) plus |
33175 | 18 |
begin |
35253 | 19 |
definition vector_add_def : "op + \<equiv> (\<lambda> x y. (\<chi> i. (x$i) + (y$i)))" |
20 |
instance .. |
|
33175 | 21 |
end |
22 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
23 |
instantiation cart :: (times,finite) times |
33175 | 24 |
begin |
25 |
definition vector_mult_def : "op * \<equiv> (\<lambda> x y. (\<chi> i. (x$i) * (y$i)))" |
|
26 |
instance .. |
|
27 |
end |
|
28 |
||
35253 | 29 |
instantiation cart :: (minus,finite) minus |
30 |
begin |
|
33175 | 31 |
definition vector_minus_def : "op - \<equiv> (\<lambda> x y. (\<chi> i. (x$i) - (y$i)))" |
35253 | 32 |
instance .. |
33175 | 33 |
end |
34 |
||
35253 | 35 |
instantiation cart :: (uminus,finite) uminus |
36 |
begin |
|
33175 | 37 |
definition vector_uminus_def : "uminus \<equiv> (\<lambda> x. (\<chi> i. - (x$i)))" |
35253 | 38 |
instance .. |
33175 | 39 |
end |
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
40 |
|
35253 | 41 |
instantiation cart :: (zero,finite) zero |
42 |
begin |
|
33175 | 43 |
definition vector_zero_def : "0 \<equiv> (\<chi> i. 0)" |
35253 | 44 |
instance .. |
33175 | 45 |
end |
46 |
||
35253 | 47 |
instantiation cart :: (one,finite) one |
48 |
begin |
|
33175 | 49 |
definition vector_one_def : "1 \<equiv> (\<chi> i. 1)" |
35253 | 50 |
instance .. |
33175 | 51 |
end |
52 |
||
35540 | 53 |
instantiation cart :: (scaleR, finite) scaleR |
54 |
begin |
|
55 |
definition vector_scaleR_def: "scaleR = (\<lambda> r x. (\<chi> i. scaleR r (x$i)))" |
|
56 |
instance .. |
|
57 |
end |
|
58 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
59 |
instantiation cart :: (ord,finite) ord |
35253 | 60 |
begin |
61 |
definition vector_le_def: |
|
62 |
"less_eq (x :: 'a ^'b) y = (ALL i. x$i <= y$i)" |
|
63 |
definition vector_less_def: "less (x :: 'a ^'b) y = (ALL i. x$i < y$i)" |
|
64 |
instance by (intro_classes) |
|
33175 | 65 |
end |
66 |
||
36431
340755027840
move definitions and theorems for type real^1 to separate theory file
huffman
parents:
36365
diff
changeset
|
67 |
text{* The ordering on one-dimensional vectors is linear. *} |
35540 | 68 |
|
69 |
class cart_one = assumes UNIV_one: "card (UNIV \<Colon> 'a set) = Suc 0" |
|
33175 | 70 |
begin |
35540 | 71 |
subclass finite |
72 |
proof from UNIV_one show "finite (UNIV :: 'a set)" |
|
73 |
by (auto intro!: card_ge_0_finite) qed |
|
33175 | 74 |
end |
75 |
||
35540 | 76 |
instantiation cart :: (linorder,cart_one) linorder begin |
77 |
instance proof |
|
78 |
guess a B using UNIV_one[where 'a='b] unfolding card_Suc_eq apply- by(erule exE)+ |
|
79 |
hence *:"UNIV = {a}" by auto |
|
80 |
have "\<And>P. (\<forall>i\<in>UNIV. P i) \<longleftrightarrow> P a" unfolding * by auto hence all:"\<And>P. (\<forall>i. P i) \<longleftrightarrow> P a" by auto |
|
81 |
fix x y z::"'a^'b::cart_one" note * = vector_le_def vector_less_def all Cart_eq |
|
82 |
show "x\<le>x" "(x < y) = (x \<le> y \<and> \<not> y \<le> x)" "x\<le>y \<or> y\<le>x" unfolding * by(auto simp only:field_simps) |
|
83 |
{ assume "x\<le>y" "y\<le>z" thus "x\<le>z" unfolding * by(auto simp only:field_simps) } |
|
84 |
{ assume "x\<le>y" "y\<le>x" thus "x=y" unfolding * by(auto simp only:field_simps) } |
|
85 |
qed end |
|
86 |
||
33175 | 87 |
text{* Also the scalar-vector multiplication. *} |
88 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
89 |
definition vector_scalar_mult:: "'a::times \<Rightarrow> 'a ^ 'n \<Rightarrow> 'a ^ 'n" (infixl "*s" 70) |
33175 | 90 |
where "c *s x = (\<chi> i. c * (x$i))" |
91 |
||
92 |
text{* Constant Vectors *} |
|
93 |
||
94 |
definition "vec x = (\<chi> i. x)" |
|
95 |
||
96 |
subsection {* A naive proof procedure to lift really trivial arithmetic stuff from the basis of the vector space. *} |
|
97 |
||
98 |
method_setup vector = {* |
|
99 |
let |
|
35542 | 100 |
val ss1 = HOL_basic_ss addsimps [@{thm setsum_addf} RS sym, |
33175 | 101 |
@{thm setsum_subtractf} RS sym, @{thm setsum_right_distrib}, |
102 |
@{thm setsum_left_distrib}, @{thm setsum_negf} RS sym] |
|
103 |
val ss2 = @{simpset} addsimps |
|
104 |
[@{thm vector_add_def}, @{thm vector_mult_def}, |
|
105 |
@{thm vector_minus_def}, @{thm vector_uminus_def}, |
|
106 |
@{thm vector_one_def}, @{thm vector_zero_def}, @{thm vec_def}, |
|
107 |
@{thm vector_scaleR_def}, |
|
108 |
@{thm Cart_lambda_beta}, @{thm vector_scalar_mult_def}] |
|
109 |
fun vector_arith_tac ths = |
|
110 |
simp_tac ss1 |
|
111 |
THEN' (fn i => rtac @{thm setsum_cong2} i |
|
112 |
ORELSE rtac @{thm setsum_0'} i |
|
113 |
ORELSE simp_tac (HOL_basic_ss addsimps [@{thm "Cart_eq"}]) i) |
|
114 |
(* THEN' TRY o clarify_tac HOL_cs THEN' (TRY o rtac @{thm iffI}) *) |
|
115 |
THEN' asm_full_simp_tac (ss2 addsimps ths) |
|
116 |
in |
|
117 |
Attrib.thms >> (fn ths => K (SIMPLE_METHOD' (vector_arith_tac ths))) |
|
118 |
end |
|
119 |
*} "Lifts trivial vector statements to real arith statements" |
|
120 |
||
121 |
lemma vec_0[simp]: "vec 0 = 0" by (vector vector_zero_def) |
|
122 |
lemma vec_1[simp]: "vec 1 = 1" by (vector vector_one_def) |
|
123 |
||
124 |
text{* Obvious "component-pushing". *} |
|
125 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
126 |
lemma vec_component [simp]: "vec x $ i = x" |
33175 | 127 |
by (vector vec_def) |
128 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
129 |
lemma vector_add_component [simp]: "(x + y)$i = x$i + y$i" |
33175 | 130 |
by vector |
131 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
132 |
lemma vector_minus_component [simp]: "(x - y)$i = x$i - y$i" |
33175 | 133 |
by vector |
134 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
135 |
lemma vector_mult_component [simp]: "(x * y)$i = x$i * y$i" |
33175 | 136 |
by vector |
137 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
138 |
lemma vector_smult_component [simp]: "(c *s y)$i = c * (y$i)" |
33175 | 139 |
by vector |
140 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
141 |
lemma vector_uminus_component [simp]: "(- x)$i = - (x$i)" |
33175 | 142 |
by vector |
143 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
144 |
lemma vector_scaleR_component [simp]: "(scaleR r x)$i = scaleR r (x$i)" |
33175 | 145 |
by vector |
146 |
||
147 |
lemma cond_component: "(if b then x else y)$i = (if b then x$i else y$i)" by vector |
|
148 |
||
149 |
lemmas vector_component = |
|
150 |
vec_component vector_add_component vector_mult_component |
|
151 |
vector_smult_component vector_minus_component vector_uminus_component |
|
152 |
vector_scaleR_component cond_component |
|
153 |
||
154 |
subsection {* Some frequently useful arithmetic lemmas over vectors. *} |
|
155 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
156 |
instance cart :: (semigroup_add,finite) semigroup_add |
33175 | 157 |
apply (intro_classes) by (vector add_assoc) |
158 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
159 |
instance cart :: (monoid_add,finite) monoid_add |
33175 | 160 |
apply (intro_classes) by vector+ |
161 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
162 |
instance cart :: (group_add,finite) group_add |
33175 | 163 |
apply (intro_classes) by (vector algebra_simps)+ |
164 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
165 |
instance cart :: (ab_semigroup_add,finite) ab_semigroup_add |
33175 | 166 |
apply (intro_classes) by (vector add_commute) |
167 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
168 |
instance cart :: (comm_monoid_add,finite) comm_monoid_add |
33175 | 169 |
apply (intro_classes) by vector |
170 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
171 |
instance cart :: (ab_group_add,finite) ab_group_add |
33175 | 172 |
apply (intro_classes) by vector+ |
173 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
174 |
instance cart :: (cancel_semigroup_add,finite) cancel_semigroup_add |
33175 | 175 |
apply (intro_classes) |
176 |
by (vector Cart_eq)+ |
|
177 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
178 |
instance cart :: (cancel_ab_semigroup_add,finite) cancel_ab_semigroup_add |
33175 | 179 |
apply (intro_classes) |
180 |
by (vector Cart_eq) |
|
181 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
182 |
instance cart :: (real_vector, finite) real_vector |
33175 | 183 |
by default (vector scaleR_left_distrib scaleR_right_distrib)+ |
184 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
185 |
instance cart :: (semigroup_mult,finite) semigroup_mult |
33175 | 186 |
apply (intro_classes) by (vector mult_assoc) |
187 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
188 |
instance cart :: (monoid_mult,finite) monoid_mult |
33175 | 189 |
apply (intro_classes) by vector+ |
190 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
191 |
instance cart :: (ab_semigroup_mult,finite) ab_semigroup_mult |
33175 | 192 |
apply (intro_classes) by (vector mult_commute) |
193 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
194 |
instance cart :: (ab_semigroup_idem_mult,finite) ab_semigroup_idem_mult |
33175 | 195 |
apply (intro_classes) by (vector mult_idem) |
196 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
197 |
instance cart :: (comm_monoid_mult,finite) comm_monoid_mult |
33175 | 198 |
apply (intro_classes) by vector |
199 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
200 |
fun vector_power where |
33175 | 201 |
"vector_power x 0 = 1" |
202 |
| "vector_power x (Suc n) = x * vector_power x n" |
|
203 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
204 |
instance cart :: (semiring,finite) semiring |
36350 | 205 |
apply (intro_classes) by (vector field_simps)+ |
33175 | 206 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
207 |
instance cart :: (semiring_0,finite) semiring_0 |
36350 | 208 |
apply (intro_classes) by (vector field_simps)+ |
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
209 |
instance cart :: (semiring_1,finite) semiring_1 |
33175 | 210 |
apply (intro_classes) by vector |
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
211 |
instance cart :: (comm_semiring,finite) comm_semiring |
36350 | 212 |
apply (intro_classes) by (vector field_simps)+ |
33175 | 213 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
214 |
instance cart :: (comm_semiring_0,finite) comm_semiring_0 by (intro_classes) |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
215 |
instance cart :: (cancel_comm_monoid_add, finite) cancel_comm_monoid_add .. |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
216 |
instance cart :: (semiring_0_cancel,finite) semiring_0_cancel by (intro_classes) |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
217 |
instance cart :: (comm_semiring_0_cancel,finite) comm_semiring_0_cancel by (intro_classes) |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
218 |
instance cart :: (ring,finite) ring by (intro_classes) |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
219 |
instance cart :: (semiring_1_cancel,finite) semiring_1_cancel by (intro_classes) |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
220 |
instance cart :: (comm_semiring_1,finite) comm_semiring_1 by (intro_classes) |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
221 |
|
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
222 |
instance cart :: (ring_1,finite) ring_1 .. |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
223 |
|
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
224 |
instance cart :: (real_algebra,finite) real_algebra |
33175 | 225 |
apply intro_classes |
36350 | 226 |
apply (simp_all add: vector_scaleR_def field_simps) |
33175 | 227 |
apply vector |
228 |
apply vector |
|
229 |
done |
|
230 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
231 |
instance cart :: (real_algebra_1,finite) real_algebra_1 .. |
33175 | 232 |
|
233 |
lemma of_nat_index: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
234 |
"(of_nat n :: 'a::semiring_1 ^'n)$i = of_nat n" |
33175 | 235 |
apply (induct n) |
236 |
apply vector |
|
237 |
apply vector |
|
238 |
done |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
239 |
|
33175 | 240 |
lemma zero_index[simp]: |
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
241 |
"(0 :: 'a::zero ^'n)$i = 0" by vector |
33175 | 242 |
|
243 |
lemma one_index[simp]: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
244 |
"(1 :: 'a::one ^'n)$i = 1" by vector |
33175 | 245 |
|
246 |
lemma one_plus_of_nat_neq_0: "(1::'a::semiring_char_0) + of_nat n \<noteq> 0" |
|
247 |
proof- |
|
248 |
have "(1::'a) + of_nat n = 0 \<longleftrightarrow> of_nat 1 + of_nat n = (of_nat 0 :: 'a)" by simp |
|
249 |
also have "\<dots> \<longleftrightarrow> 1 + n = 0" by (simp only: of_nat_add[symmetric] of_nat_eq_iff) |
|
250 |
finally show ?thesis by simp |
|
251 |
qed |
|
252 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
253 |
instance cart :: (semiring_char_0,finite) semiring_char_0 |
33175 | 254 |
proof (intro_classes) |
255 |
fix m n ::nat |
|
256 |
show "(of_nat m :: 'a^'b) = of_nat n \<longleftrightarrow> m = n" |
|
257 |
by (simp add: Cart_eq of_nat_index) |
|
258 |
qed |
|
259 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
260 |
instance cart :: (comm_ring_1,finite) comm_ring_1 by intro_classes |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
261 |
instance cart :: (ring_char_0,finite) ring_char_0 by intro_classes |
33175 | 262 |
|
263 |
lemma vector_smult_assoc: "a *s (b *s x) = ((a::'a::semigroup_mult) * b) *s x" |
|
264 |
by (vector mult_assoc) |
|
265 |
lemma vector_sadd_rdistrib: "((a::'a::semiring) + b) *s x = a *s x + b *s x" |
|
36350 | 266 |
by (vector field_simps) |
33175 | 267 |
lemma vector_add_ldistrib: "(c::'a::semiring) *s (x + y) = c *s x + c *s y" |
36350 | 268 |
by (vector field_simps) |
33175 | 269 |
lemma vector_smult_lzero[simp]: "(0::'a::mult_zero) *s x = 0" by vector |
270 |
lemma vector_smult_lid[simp]: "(1::'a::monoid_mult) *s x = x" by vector |
|
271 |
lemma vector_ssub_ldistrib: "(c::'a::ring) *s (x - y) = c *s x - c *s y" |
|
36350 | 272 |
by (vector field_simps) |
33175 | 273 |
lemma vector_smult_rneg: "(c::'a::ring) *s -x = -(c *s x)" by vector |
274 |
lemma vector_smult_lneg: "- (c::'a::ring) *s x = -(c *s x)" by vector |
|
275 |
lemma vector_sneg_minus1: "-x = (- (1::'a::ring_1)) *s x" by vector |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
276 |
lemma vector_smult_rzero[simp]: "c *s 0 = (0::'a::mult_zero ^ 'n)" by vector |
33175 | 277 |
lemma vector_sub_rdistrib: "((a::'a::ring) - b) *s x = a *s x - b *s x" |
36350 | 278 |
by (vector field_simps) |
33175 | 279 |
|
280 |
lemma vec_eq[simp]: "(vec m = vec n) \<longleftrightarrow> (m = n)" |
|
281 |
by (simp add: Cart_eq) |
|
282 |
||
283 |
subsection {* Topological space *} |
|
284 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
285 |
instantiation cart :: (topological_space, finite) topological_space |
33175 | 286 |
begin |
287 |
||
288 |
definition open_vector_def: |
|
289 |
"open (S :: ('a ^ 'b) set) \<longleftrightarrow> |
|
290 |
(\<forall>x\<in>S. \<exists>A. (\<forall>i. open (A i) \<and> x$i \<in> A i) \<and> |
|
291 |
(\<forall>y. (\<forall>i. y$i \<in> A i) \<longrightarrow> y \<in> S))" |
|
292 |
||
293 |
instance proof |
|
294 |
show "open (UNIV :: ('a ^ 'b) set)" |
|
295 |
unfolding open_vector_def by auto |
|
296 |
next |
|
297 |
fix S T :: "('a ^ 'b) set" |
|
298 |
assume "open S" "open T" thus "open (S \<inter> T)" |
|
299 |
unfolding open_vector_def |
|
300 |
apply clarify |
|
301 |
apply (drule (1) bspec)+ |
|
302 |
apply (clarify, rename_tac Sa Ta) |
|
303 |
apply (rule_tac x="\<lambda>i. Sa i \<inter> Ta i" in exI) |
|
304 |
apply (simp add: open_Int) |
|
305 |
done |
|
306 |
next |
|
307 |
fix K :: "('a ^ 'b) set set" |
|
308 |
assume "\<forall>S\<in>K. open S" thus "open (\<Union>K)" |
|
309 |
unfolding open_vector_def |
|
310 |
apply clarify |
|
311 |
apply (drule (1) bspec) |
|
312 |
apply (drule (1) bspec) |
|
313 |
apply clarify |
|
314 |
apply (rule_tac x=A in exI) |
|
315 |
apply fast |
|
316 |
done |
|
317 |
qed |
|
318 |
||
319 |
end |
|
320 |
||
321 |
lemma open_vector_box: "\<forall>i. open (S i) \<Longrightarrow> open {x. \<forall>i. x $ i \<in> S i}" |
|
322 |
unfolding open_vector_def by auto |
|
323 |
||
324 |
lemma open_vimage_Cart_nth: "open S \<Longrightarrow> open ((\<lambda>x. x $ i) -` S)" |
|
325 |
unfolding open_vector_def |
|
326 |
apply clarify |
|
327 |
apply (rule_tac x="\<lambda>k. if k = i then S else UNIV" in exI, simp) |
|
328 |
done |
|
329 |
||
330 |
lemma closed_vimage_Cart_nth: "closed S \<Longrightarrow> closed ((\<lambda>x. x $ i) -` S)" |
|
331 |
unfolding closed_open vimage_Compl [symmetric] |
|
332 |
by (rule open_vimage_Cart_nth) |
|
333 |
||
334 |
lemma closed_vector_box: "\<forall>i. closed (S i) \<Longrightarrow> closed {x. \<forall>i. x $ i \<in> S i}" |
|
335 |
proof - |
|
336 |
have "{x. \<forall>i. x $ i \<in> S i} = (\<Inter>i. (\<lambda>x. x $ i) -` S i)" by auto |
|
337 |
thus "\<forall>i. closed (S i) \<Longrightarrow> closed {x. \<forall>i. x $ i \<in> S i}" |
|
338 |
by (simp add: closed_INT closed_vimage_Cart_nth) |
|
339 |
qed |
|
340 |
||
341 |
lemma tendsto_Cart_nth [tendsto_intros]: |
|
342 |
assumes "((\<lambda>x. f x) ---> a) net" |
|
343 |
shows "((\<lambda>x. f x $ i) ---> a $ i) net" |
|
344 |
proof (rule topological_tendstoI) |
|
345 |
fix S assume "open S" "a $ i \<in> S" |
|
346 |
then have "open ((\<lambda>y. y $ i) -` S)" "a \<in> ((\<lambda>y. y $ i) -` S)" |
|
347 |
by (simp_all add: open_vimage_Cart_nth) |
|
348 |
with assms have "eventually (\<lambda>x. f x \<in> (\<lambda>y. y $ i) -` S) net" |
|
349 |
by (rule topological_tendstoD) |
|
350 |
then show "eventually (\<lambda>x. f x $ i \<in> S) net" |
|
351 |
by simp |
|
352 |
qed |
|
353 |
||
354 |
subsection {* Metric *} |
|
355 |
||
356 |
(* TODO: move somewhere else *) |
|
357 |
lemma finite_choice: "finite A \<Longrightarrow> \<forall>x\<in>A. \<exists>y. P x y \<Longrightarrow> \<exists>f. \<forall>x\<in>A. P x (f x)" |
|
358 |
apply (induct set: finite, simp_all) |
|
359 |
apply (clarify, rename_tac y) |
|
360 |
apply (rule_tac x="f(x:=y)" in exI, simp) |
|
361 |
done |
|
362 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
363 |
instantiation cart :: (metric_space, finite) metric_space |
33175 | 364 |
begin |
365 |
||
366 |
definition dist_vector_def: |
|
367 |
"dist (x::'a^'b) (y::'a^'b) = setL2 (\<lambda>i. dist (x$i) (y$i)) UNIV" |
|
368 |
||
369 |
lemma dist_nth_le: "dist (x $ i) (y $ i) \<le> dist x y" |
|
370 |
unfolding dist_vector_def |
|
371 |
by (rule member_le_setL2) simp_all |
|
372 |
||
373 |
instance proof |
|
374 |
fix x y :: "'a ^ 'b" |
|
375 |
show "dist x y = 0 \<longleftrightarrow> x = y" |
|
376 |
unfolding dist_vector_def |
|
377 |
by (simp add: setL2_eq_0_iff Cart_eq) |
|
378 |
next |
|
379 |
fix x y z :: "'a ^ 'b" |
|
380 |
show "dist x y \<le> dist x z + dist y z" |
|
381 |
unfolding dist_vector_def |
|
382 |
apply (rule order_trans [OF _ setL2_triangle_ineq]) |
|
383 |
apply (simp add: setL2_mono dist_triangle2) |
|
384 |
done |
|
385 |
next |
|
386 |
(* FIXME: long proof! *) |
|
387 |
fix S :: "('a ^ 'b) set" |
|
388 |
show "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)" |
|
389 |
unfolding open_vector_def open_dist |
|
390 |
apply safe |
|
391 |
apply (drule (1) bspec) |
|
392 |
apply clarify |
|
393 |
apply (subgoal_tac "\<exists>e>0. \<forall>i y. dist y (x$i) < e \<longrightarrow> y \<in> A i") |
|
394 |
apply clarify |
|
395 |
apply (rule_tac x=e in exI, clarify) |
|
396 |
apply (drule spec, erule mp, clarify) |
|
397 |
apply (drule spec, drule spec, erule mp) |
|
398 |
apply (erule le_less_trans [OF dist_nth_le]) |
|
399 |
apply (subgoal_tac "\<forall>i\<in>UNIV. \<exists>e>0. \<forall>y. dist y (x$i) < e \<longrightarrow> y \<in> A i") |
|
400 |
apply (drule finite_choice [OF finite], clarify) |
|
401 |
apply (rule_tac x="Min (range f)" in exI, simp) |
|
402 |
apply clarify |
|
403 |
apply (drule_tac x=i in spec, clarify) |
|
404 |
apply (erule (1) bspec) |
|
405 |
apply (drule (1) bspec, clarify) |
|
406 |
apply (subgoal_tac "\<exists>r. (\<forall>i::'b. 0 < r i) \<and> e = setL2 r UNIV") |
|
407 |
apply clarify |
|
408 |
apply (rule_tac x="\<lambda>i. {y. dist y (x$i) < r i}" in exI) |
|
409 |
apply (rule conjI) |
|
410 |
apply clarify |
|
411 |
apply (rule conjI) |
|
412 |
apply (clarify, rename_tac y) |
|
413 |
apply (rule_tac x="r i - dist y (x$i)" in exI, rule conjI, simp) |
|
414 |
apply clarify |
|
415 |
apply (simp only: less_diff_eq) |
|
416 |
apply (erule le_less_trans [OF dist_triangle]) |
|
417 |
apply simp |
|
418 |
apply clarify |
|
419 |
apply (drule spec, erule mp) |
|
420 |
apply (simp add: dist_vector_def setL2_strict_mono) |
|
421 |
apply (rule_tac x="\<lambda>i. e / sqrt (of_nat CARD('b))" in exI) |
|
422 |
apply (simp add: divide_pos_pos setL2_constant) |
|
423 |
done |
|
424 |
qed |
|
425 |
||
426 |
end |
|
427 |
||
428 |
lemma LIMSEQ_Cart_nth: |
|
429 |
"(X ----> a) \<Longrightarrow> (\<lambda>n. X n $ i) ----> a $ i" |
|
430 |
unfolding LIMSEQ_conv_tendsto by (rule tendsto_Cart_nth) |
|
431 |
||
432 |
lemma LIM_Cart_nth: |
|
433 |
"(f -- x --> y) \<Longrightarrow> (\<lambda>x. f x $ i) -- x --> y $ i" |
|
434 |
unfolding LIM_conv_tendsto by (rule tendsto_Cart_nth) |
|
435 |
||
436 |
lemma Cauchy_Cart_nth: |
|
437 |
"Cauchy (\<lambda>n. X n) \<Longrightarrow> Cauchy (\<lambda>n. X n $ i)" |
|
438 |
unfolding Cauchy_def by (fast intro: le_less_trans [OF dist_nth_le]) |
|
439 |
||
440 |
lemma LIMSEQ_vector: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
441 |
fixes X :: "nat \<Rightarrow> 'a::metric_space ^ 'n" |
33175 | 442 |
assumes X: "\<And>i. (\<lambda>n. X n $ i) ----> (a $ i)" |
443 |
shows "X ----> a" |
|
444 |
proof (rule metric_LIMSEQ_I) |
|
445 |
fix r :: real assume "0 < r" |
|
446 |
then have "0 < r / of_nat CARD('n)" (is "0 < ?s") |
|
447 |
by (simp add: divide_pos_pos) |
|
448 |
def N \<equiv> "\<lambda>i. LEAST N. \<forall>n\<ge>N. dist (X n $ i) (a $ i) < ?s" |
|
449 |
def M \<equiv> "Max (range N)" |
|
450 |
have "\<And>i. \<exists>N. \<forall>n\<ge>N. dist (X n $ i) (a $ i) < ?s" |
|
451 |
using X `0 < ?s` by (rule metric_LIMSEQ_D) |
|
452 |
hence "\<And>i. \<forall>n\<ge>N i. dist (X n $ i) (a $ i) < ?s" |
|
453 |
unfolding N_def by (rule LeastI_ex) |
|
454 |
hence M: "\<And>i. \<forall>n\<ge>M. dist (X n $ i) (a $ i) < ?s" |
|
455 |
unfolding M_def by simp |
|
456 |
{ |
|
457 |
fix n :: nat assume "M \<le> n" |
|
458 |
have "dist (X n) a = setL2 (\<lambda>i. dist (X n $ i) (a $ i)) UNIV" |
|
459 |
unfolding dist_vector_def .. |
|
460 |
also have "\<dots> \<le> setsum (\<lambda>i. dist (X n $ i) (a $ i)) UNIV" |
|
461 |
by (rule setL2_le_setsum [OF zero_le_dist]) |
|
462 |
also have "\<dots> < setsum (\<lambda>i::'n. ?s) UNIV" |
|
463 |
by (rule setsum_strict_mono, simp_all add: M `M \<le> n`) |
|
464 |
also have "\<dots> = r" |
|
465 |
by simp |
|
466 |
finally have "dist (X n) a < r" . |
|
467 |
} |
|
468 |
hence "\<forall>n\<ge>M. dist (X n) a < r" |
|
469 |
by simp |
|
470 |
then show "\<exists>M. \<forall>n\<ge>M. dist (X n) a < r" .. |
|
471 |
qed |
|
472 |
||
473 |
lemma Cauchy_vector: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
474 |
fixes X :: "nat \<Rightarrow> 'a::metric_space ^ 'n" |
33175 | 475 |
assumes X: "\<And>i. Cauchy (\<lambda>n. X n $ i)" |
476 |
shows "Cauchy (\<lambda>n. X n)" |
|
477 |
proof (rule metric_CauchyI) |
|
478 |
fix r :: real assume "0 < r" |
|
479 |
then have "0 < r / of_nat CARD('n)" (is "0 < ?s") |
|
480 |
by (simp add: divide_pos_pos) |
|
481 |
def N \<equiv> "\<lambda>i. LEAST N. \<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m $ i) (X n $ i) < ?s" |
|
482 |
def M \<equiv> "Max (range N)" |
|
483 |
have "\<And>i. \<exists>N. \<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m $ i) (X n $ i) < ?s" |
|
484 |
using X `0 < ?s` by (rule metric_CauchyD) |
|
485 |
hence "\<And>i. \<forall>m\<ge>N i. \<forall>n\<ge>N i. dist (X m $ i) (X n $ i) < ?s" |
|
486 |
unfolding N_def by (rule LeastI_ex) |
|
487 |
hence M: "\<And>i. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m $ i) (X n $ i) < ?s" |
|
488 |
unfolding M_def by simp |
|
489 |
{ |
|
490 |
fix m n :: nat |
|
491 |
assume "M \<le> m" "M \<le> n" |
|
492 |
have "dist (X m) (X n) = setL2 (\<lambda>i. dist (X m $ i) (X n $ i)) UNIV" |
|
493 |
unfolding dist_vector_def .. |
|
494 |
also have "\<dots> \<le> setsum (\<lambda>i. dist (X m $ i) (X n $ i)) UNIV" |
|
495 |
by (rule setL2_le_setsum [OF zero_le_dist]) |
|
496 |
also have "\<dots> < setsum (\<lambda>i::'n. ?s) UNIV" |
|
497 |
by (rule setsum_strict_mono, simp_all add: M `M \<le> m` `M \<le> n`) |
|
498 |
also have "\<dots> = r" |
|
499 |
by simp |
|
500 |
finally have "dist (X m) (X n) < r" . |
|
501 |
} |
|
502 |
hence "\<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < r" |
|
503 |
by simp |
|
504 |
then show "\<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < r" .. |
|
505 |
qed |
|
506 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
507 |
instance cart :: (complete_space, finite) complete_space |
33175 | 508 |
proof |
509 |
fix X :: "nat \<Rightarrow> 'a ^ 'b" assume "Cauchy X" |
|
510 |
have "\<And>i. (\<lambda>n. X n $ i) ----> lim (\<lambda>n. X n $ i)" |
|
511 |
using Cauchy_Cart_nth [OF `Cauchy X`] |
|
512 |
by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff) |
|
513 |
hence "X ----> Cart_lambda (\<lambda>i. lim (\<lambda>n. X n $ i))" |
|
514 |
by (simp add: LIMSEQ_vector) |
|
515 |
then show "convergent X" |
|
516 |
by (rule convergentI) |
|
517 |
qed |
|
518 |
||
519 |
subsection {* Norms *} |
|
520 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
521 |
instantiation cart :: (real_normed_vector, finite) real_normed_vector |
33175 | 522 |
begin |
523 |
||
524 |
definition norm_vector_def: |
|
525 |
"norm (x::'a^'b) = setL2 (\<lambda>i. norm (x$i)) UNIV" |
|
526 |
||
527 |
definition vector_sgn_def: |
|
528 |
"sgn (x::'a^'b) = scaleR (inverse (norm x)) x" |
|
529 |
||
530 |
instance proof |
|
531 |
fix a :: real and x y :: "'a ^ 'b" |
|
532 |
show "0 \<le> norm x" |
|
533 |
unfolding norm_vector_def |
|
534 |
by (rule setL2_nonneg) |
|
535 |
show "norm x = 0 \<longleftrightarrow> x = 0" |
|
536 |
unfolding norm_vector_def |
|
537 |
by (simp add: setL2_eq_0_iff Cart_eq) |
|
538 |
show "norm (x + y) \<le> norm x + norm y" |
|
539 |
unfolding norm_vector_def |
|
540 |
apply (rule order_trans [OF _ setL2_triangle_ineq]) |
|
541 |
apply (simp add: setL2_mono norm_triangle_ineq) |
|
542 |
done |
|
543 |
show "norm (scaleR a x) = \<bar>a\<bar> * norm x" |
|
544 |
unfolding norm_vector_def |
|
545 |
by (simp add: setL2_right_distrib) |
|
546 |
show "sgn x = scaleR (inverse (norm x)) x" |
|
547 |
by (rule vector_sgn_def) |
|
548 |
show "dist x y = norm (x - y)" |
|
549 |
unfolding dist_vector_def norm_vector_def |
|
550 |
by (simp add: dist_norm) |
|
551 |
qed |
|
552 |
||
553 |
end |
|
554 |
||
555 |
lemma norm_nth_le: "norm (x $ i) \<le> norm x" |
|
556 |
unfolding norm_vector_def |
|
557 |
by (rule member_le_setL2) simp_all |
|
558 |
||
559 |
interpretation Cart_nth: bounded_linear "\<lambda>x. x $ i" |
|
560 |
apply default |
|
561 |
apply (rule vector_add_component) |
|
562 |
apply (rule vector_scaleR_component) |
|
563 |
apply (rule_tac x="1" in exI, simp add: norm_nth_le) |
|
564 |
done |
|
565 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
566 |
instance cart :: (banach, finite) banach .. |
33175 | 567 |
|
568 |
subsection {* Inner products *} |
|
569 |
||
35542 | 570 |
abbreviation inner_bullet (infix "\<bullet>" 70) where "x \<bullet> y \<equiv> inner x y" |
571 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
572 |
instantiation cart :: (real_inner, finite) real_inner |
33175 | 573 |
begin |
574 |
||
575 |
definition inner_vector_def: |
|
576 |
"inner x y = setsum (\<lambda>i. inner (x$i) (y$i)) UNIV" |
|
577 |
||
578 |
instance proof |
|
579 |
fix r :: real and x y z :: "'a ^ 'b" |
|
580 |
show "inner x y = inner y x" |
|
581 |
unfolding inner_vector_def |
|
582 |
by (simp add: inner_commute) |
|
583 |
show "inner (x + y) z = inner x z + inner y z" |
|
584 |
unfolding inner_vector_def |
|
585 |
by (simp add: inner_add_left setsum_addf) |
|
586 |
show "inner (scaleR r x) y = r * inner x y" |
|
587 |
unfolding inner_vector_def |
|
588 |
by (simp add: setsum_right_distrib) |
|
589 |
show "0 \<le> inner x x" |
|
590 |
unfolding inner_vector_def |
|
591 |
by (simp add: setsum_nonneg) |
|
592 |
show "inner x x = 0 \<longleftrightarrow> x = 0" |
|
593 |
unfolding inner_vector_def |
|
594 |
by (simp add: Cart_eq setsum_nonneg_eq_0_iff) |
|
595 |
show "norm x = sqrt (inner x x)" |
|
596 |
unfolding inner_vector_def norm_vector_def setL2_def |
|
597 |
by (simp add: power2_norm_eq_inner) |
|
598 |
qed |
|
599 |
||
600 |
end |
|
601 |
||
602 |
subsection {* A connectedness or intermediate value lemma with several applications. *} |
|
603 |
||
604 |
lemma connected_real_lemma: |
|
605 |
fixes f :: "real \<Rightarrow> 'a::metric_space" |
|
606 |
assumes ab: "a \<le> b" and fa: "f a \<in> e1" and fb: "f b \<in> e2" |
|
607 |
and dst: "\<And>e x. a <= x \<Longrightarrow> x <= b \<Longrightarrow> 0 < e ==> \<exists>d > 0. \<forall>y. abs(y - x) < d \<longrightarrow> dist(f y) (f x) < e" |
|
608 |
and e1: "\<forall>y \<in> e1. \<exists>e > 0. \<forall>y'. dist y' y < e \<longrightarrow> y' \<in> e1" |
|
609 |
and e2: "\<forall>y \<in> e2. \<exists>e > 0. \<forall>y'. dist y' y < e \<longrightarrow> y' \<in> e2" |
|
610 |
and e12: "~(\<exists>x \<ge> a. x <= b \<and> f x \<in> e1 \<and> f x \<in> e2)" |
|
611 |
shows "\<exists>x \<ge> a. x <= b \<and> f x \<notin> e1 \<and> f x \<notin> e2" (is "\<exists> x. ?P x") |
|
612 |
proof- |
|
613 |
let ?S = "{c. \<forall>x \<ge> a. x <= c \<longrightarrow> f x \<in> e1}" |
|
614 |
have Se: " \<exists>x. x \<in> ?S" apply (rule exI[where x=a]) by (auto simp add: fa) |
|
615 |
have Sub: "\<exists>y. isUb UNIV ?S y" |
|
616 |
apply (rule exI[where x= b]) |
|
617 |
using ab fb e12 by (auto simp add: isUb_def setle_def) |
|
618 |
from reals_complete[OF Se Sub] obtain l where |
|
619 |
l: "isLub UNIV ?S l"by blast |
|
620 |
have alb: "a \<le> l" "l \<le> b" using l ab fa fb e12 |
|
621 |
apply (auto simp add: isLub_def leastP_def isUb_def setle_def setge_def) |
|
622 |
by (metis linorder_linear) |
|
623 |
have ale1: "\<forall>z \<ge> a. z < l \<longrightarrow> f z \<in> e1" using l |
|
624 |
apply (auto simp add: isLub_def leastP_def isUb_def setle_def setge_def) |
|
625 |
by (metis linorder_linear not_le) |
|
626 |
have th1: "\<And>z x e d :: real. z <= x + e \<Longrightarrow> e < d ==> z < x \<or> abs(z - x) < d" by arith |
|
627 |
have th2: "\<And>e x:: real. 0 < e ==> ~(x + e <= x)" by arith |
|
628 |
have th3: "\<And>d::real. d > 0 \<Longrightarrow> \<exists>e > 0. e < d" by dlo |
|
629 |
{assume le2: "f l \<in> e2" |
|
630 |
from le2 fa fb e12 alb have la: "l \<noteq> a" by metis |
|
631 |
hence lap: "l - a > 0" using alb by arith |
|
632 |
from e2[rule_format, OF le2] obtain e where |
|
633 |
e: "e > 0" "\<forall>y. dist y (f l) < e \<longrightarrow> y \<in> e2" by metis |
|
634 |
from dst[OF alb e(1)] obtain d where |
|
635 |
d: "d > 0" "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> dist (f y) (f l) < e" by metis |
|
636 |
have "\<exists>d'. d' < d \<and> d' >0 \<and> l - d' > a" using lap d(1) |
|
637 |
apply ferrack by arith |
|
638 |
then obtain d' where d': "d' > 0" "d' < d" "l - d' > a" by metis |
|
639 |
from d e have th0: "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> f y \<in> e2" by metis |
|
640 |
from th0[rule_format, of "l - d'"] d' have "f (l - d') \<in> e2" by auto |
|
641 |
moreover |
|
642 |
have "f (l - d') \<in> e1" using ale1[rule_format, of "l -d'"] d' by auto |
|
643 |
ultimately have False using e12 alb d' by auto} |
|
644 |
moreover |
|
645 |
{assume le1: "f l \<in> e1" |
|
646 |
from le1 fa fb e12 alb have lb: "l \<noteq> b" by metis |
|
647 |
hence blp: "b - l > 0" using alb by arith |
|
648 |
from e1[rule_format, OF le1] obtain e where |
|
649 |
e: "e > 0" "\<forall>y. dist y (f l) < e \<longrightarrow> y \<in> e1" by metis |
|
650 |
from dst[OF alb e(1)] obtain d where |
|
651 |
d: "d > 0" "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> dist (f y) (f l) < e" by metis |
|
652 |
have "\<exists>d'. d' < d \<and> d' >0" using d(1) by dlo |
|
653 |
then obtain d' where d': "d' > 0" "d' < d" by metis |
|
654 |
from d e have th0: "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> f y \<in> e1" by auto |
|
655 |
hence "\<forall>y. l \<le> y \<and> y \<le> l + d' \<longrightarrow> f y \<in> e1" using d' by auto |
|
656 |
with ale1 have "\<forall>y. a \<le> y \<and> y \<le> l + d' \<longrightarrow> f y \<in> e1" by auto |
|
657 |
with l d' have False |
|
658 |
by (auto simp add: isLub_def isUb_def setle_def setge_def leastP_def) } |
|
659 |
ultimately show ?thesis using alb by metis |
|
660 |
qed |
|
661 |
||
36431
340755027840
move definitions and theorems for type real^1 to separate theory file
huffman
parents:
36365
diff
changeset
|
662 |
text{* One immediately useful corollary is the existence of square roots! --- Should help to get rid of all the development of square-root for reals as a special case *} |
33175 | 663 |
|
664 |
lemma square_bound_lemma: "(x::real) < (1 + x) * (1 + x)" |
|
665 |
proof- |
|
666 |
have "(x + 1/2)^2 + 3/4 > 0" using zero_le_power2[of "x+1/2"] by arith |
|
36350 | 667 |
thus ?thesis by (simp add: field_simps power2_eq_square) |
33175 | 668 |
qed |
669 |
||
670 |
lemma square_continuous: "0 < (e::real) ==> \<exists>d. 0 < d \<and> (\<forall>y. abs(y - x) < d \<longrightarrow> abs(y * y - x * x) < e)" |
|
671 |
using isCont_power[OF isCont_ident, of 2, unfolded isCont_def LIM_eq, rule_format, of e x] apply (auto simp add: power2_eq_square) |
|
672 |
apply (rule_tac x="s" in exI) |
|
673 |
apply auto |
|
674 |
apply (erule_tac x=y in allE) |
|
675 |
apply auto |
|
676 |
done |
|
677 |
||
678 |
lemma real_le_lsqrt: "0 <= x \<Longrightarrow> 0 <= y \<Longrightarrow> x <= y^2 ==> sqrt x <= y" |
|
679 |
using real_sqrt_le_iff[of x "y^2"] by simp |
|
680 |
||
681 |
lemma real_le_rsqrt: "x^2 \<le> y \<Longrightarrow> x \<le> sqrt y" |
|
682 |
using real_sqrt_le_mono[of "x^2" y] by simp |
|
683 |
||
684 |
lemma real_less_rsqrt: "x^2 < y \<Longrightarrow> x < sqrt y" |
|
685 |
using real_sqrt_less_mono[of "x^2" y] by simp |
|
686 |
||
687 |
lemma sqrt_even_pow2: assumes n: "even n" |
|
688 |
shows "sqrt(2 ^ n) = 2 ^ (n div 2)" |
|
689 |
proof- |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
690 |
from n obtain m where m: "n = 2*m" unfolding even_mult_two_ex .. |
33175 | 691 |
from m have "sqrt(2 ^ n) = sqrt ((2 ^ m) ^ 2)" |
692 |
by (simp only: power_mult[symmetric] mult_commute) |
|
693 |
then show ?thesis using m by simp |
|
694 |
qed |
|
695 |
||
696 |
lemma real_div_sqrt: "0 <= x ==> x / sqrt(x) = sqrt(x)" |
|
697 |
apply (cases "x = 0", simp_all) |
|
698 |
using sqrt_divide_self_eq[of x] |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
699 |
apply (simp add: inverse_eq_divide field_simps) |
33175 | 700 |
done |
701 |
||
702 |
text{* Hence derive more interesting properties of the norm. *} |
|
703 |
||
704 |
text {* |
|
705 |
This type-specific version is only here |
|
706 |
to make @{text normarith.ML} happy. |
|
707 |
*} |
|
708 |
lemma norm_0: "norm (0::real ^ _) = 0" |
|
709 |
by (rule norm_zero) |
|
710 |
||
711 |
lemma norm_mul[simp]: "norm(a *s x) = abs(a) * norm x" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
712 |
by (simp add: norm_vector_def setL2_right_distrib abs_mult) |
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
713 |
|
35542 | 714 |
lemma norm_eq_0_dot: "(norm x = 0) \<longleftrightarrow> (inner x x = (0::real))" |
715 |
by (simp add: norm_vector_def setL2_def power2_eq_square) |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
716 |
lemma norm_eq_0_imp: "norm x = 0 ==> x = (0::real ^'n)" by (metis norm_eq_zero) |
33175 | 717 |
lemma vector_mul_eq_0[simp]: "(a *s x = 0) \<longleftrightarrow> a = (0::'a::idom) \<or> x = 0" |
718 |
by vector |
|
719 |
lemma vector_mul_lcancel[simp]: "a *s x = a *s y \<longleftrightarrow> a = (0::real) \<or> x = y" |
|
720 |
by (metis eq_iff_diff_eq_0 vector_mul_eq_0 vector_ssub_ldistrib) |
|
721 |
lemma vector_mul_rcancel[simp]: "a *s x = b *s x \<longleftrightarrow> (a::real) = b \<or> x = 0" |
|
722 |
by (metis eq_iff_diff_eq_0 vector_mul_eq_0 vector_sub_rdistrib) |
|
723 |
lemma vector_mul_lcancel_imp: "a \<noteq> (0::real) ==> a *s x = a *s y ==> (x = y)" |
|
724 |
by (metis vector_mul_lcancel) |
|
725 |
lemma vector_mul_rcancel_imp: "x \<noteq> 0 \<Longrightarrow> (a::real) *s x = b *s x ==> a = b" |
|
726 |
by (metis vector_mul_rcancel) |
|
35542 | 727 |
|
33175 | 728 |
lemma norm_cauchy_schwarz: |
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
729 |
fixes x y :: "real ^ 'n" |
35542 | 730 |
shows "inner x y <= norm x * norm y" |
731 |
using Cauchy_Schwarz_ineq2[of x y] by auto |
|
33175 | 732 |
|
733 |
lemma norm_cauchy_schwarz_abs: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
734 |
fixes x y :: "real ^ 'n" |
35542 | 735 |
shows "\<bar>inner x y\<bar> \<le> norm x * norm y" |
33175 | 736 |
using norm_cauchy_schwarz[of x y] norm_cauchy_schwarz[of x "-y"] |
35542 | 737 |
by (simp add: real_abs_def) |
33175 | 738 |
|
739 |
lemma norm_triangle_sub: |
|
740 |
fixes x y :: "'a::real_normed_vector" |
|
741 |
shows "norm x \<le> norm y + norm (x - y)" |
|
36350 | 742 |
using norm_triangle_ineq[of "y" "x - y"] by (simp add: field_simps) |
33175 | 743 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
744 |
lemma component_le_norm: "\<bar>x$i\<bar> <= norm x" |
33175 | 745 |
apply (simp add: norm_vector_def) |
746 |
apply (rule member_le_setL2, simp_all) |
|
747 |
done |
|
748 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
749 |
lemma norm_bound_component_le: "norm x <= e ==> \<bar>x$i\<bar> <= e" |
33175 | 750 |
by (metis component_le_norm order_trans) |
751 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
752 |
lemma norm_bound_component_lt: "norm x < e ==> \<bar>x$i\<bar> < e" |
33175 | 753 |
by (metis component_le_norm basic_trans_rules(21)) |
754 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
755 |
lemma norm_le_l1: "norm x <= setsum(\<lambda>i. \<bar>x$i\<bar>) UNIV" |
33175 | 756 |
by (simp add: norm_vector_def setL2_le_setsum) |
757 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
758 |
lemma real_abs_norm: "\<bar>norm x\<bar> = norm x" |
33175 | 759 |
by (rule abs_norm_cancel) |
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
760 |
lemma real_abs_sub_norm: "\<bar>norm (x::real ^ 'n) - norm y\<bar> <= norm(x - y)" |
33175 | 761 |
by (rule norm_triangle_ineq3) |
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
762 |
lemma norm_le: "norm(x::real ^ 'n) <= norm(y) \<longleftrightarrow> x \<bullet> x <= y \<bullet> y" |
35542 | 763 |
by (simp add: norm_eq_sqrt_inner) |
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
764 |
lemma norm_lt: "norm(x::real ^ 'n) < norm(y) \<longleftrightarrow> x \<bullet> x < y \<bullet> y" |
35542 | 765 |
by (simp add: norm_eq_sqrt_inner) |
766 |
lemma norm_eq: "norm(x::real ^ 'n) = norm (y::real ^ 'n) \<longleftrightarrow> x \<bullet> x = y \<bullet> y" |
|
767 |
apply(subst order_eq_iff) unfolding norm_le by auto |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
768 |
lemma norm_eq_1: "norm(x::real ^ 'n) = 1 \<longleftrightarrow> x \<bullet> x = 1" |
35542 | 769 |
unfolding norm_eq_sqrt_inner by auto |
33175 | 770 |
|
771 |
text{* Squaring equations and inequalities involving norms. *} |
|
772 |
||
773 |
lemma dot_square_norm: "x \<bullet> x = norm(x)^2" |
|
35542 | 774 |
by (simp add: norm_eq_sqrt_inner) |
33175 | 775 |
|
776 |
lemma norm_eq_square: "norm(x) = a \<longleftrightarrow> 0 <= a \<and> x \<bullet> x = a^2" |
|
35542 | 777 |
by (auto simp add: norm_eq_sqrt_inner) |
33175 | 778 |
|
779 |
lemma real_abs_le_square_iff: "\<bar>x\<bar> \<le> \<bar>y\<bar> \<longleftrightarrow> (x::real)^2 \<le> y^2" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
780 |
proof |
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
781 |
assume "\<bar>x\<bar> \<le> \<bar>y\<bar>" |
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
782 |
then have "\<bar>x\<bar>\<twosuperior> \<le> \<bar>y\<bar>\<twosuperior>" by (rule power_mono, simp) |
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
783 |
then show "x\<twosuperior> \<le> y\<twosuperior>" by simp |
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
784 |
next |
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
785 |
assume "x\<twosuperior> \<le> y\<twosuperior>" |
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
786 |
then have "sqrt (x\<twosuperior>) \<le> sqrt (y\<twosuperior>)" by (rule real_sqrt_le_mono) |
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
787 |
then show "\<bar>x\<bar> \<le> \<bar>y\<bar>" by simp |
33175 | 788 |
qed |
789 |
||
790 |
lemma norm_le_square: "norm(x) <= a \<longleftrightarrow> 0 <= a \<and> x \<bullet> x <= a^2" |
|
791 |
apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric]) |
|
792 |
using norm_ge_zero[of x] |
|
793 |
apply arith |
|
794 |
done |
|
795 |
||
796 |
lemma norm_ge_square: "norm(x) >= a \<longleftrightarrow> a <= 0 \<or> x \<bullet> x >= a ^ 2" |
|
797 |
apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric]) |
|
798 |
using norm_ge_zero[of x] |
|
799 |
apply arith |
|
800 |
done |
|
801 |
||
802 |
lemma norm_lt_square: "norm(x) < a \<longleftrightarrow> 0 < a \<and> x \<bullet> x < a^2" |
|
803 |
by (metis not_le norm_ge_square) |
|
804 |
lemma norm_gt_square: "norm(x) > a \<longleftrightarrow> a < 0 \<or> x \<bullet> x > a^2" |
|
805 |
by (metis norm_le_square not_less) |
|
806 |
||
807 |
text{* Dot product in terms of the norm rather than conversely. *} |
|
808 |
||
35542 | 809 |
lemmas inner_simps = inner.add_left inner.add_right inner.diff_right inner.diff_left |
810 |
inner.scaleR_left inner.scaleR_right |
|
811 |
||
33175 | 812 |
lemma dot_norm: "x \<bullet> y = (norm(x + y) ^2 - norm x ^ 2 - norm y ^ 2) / 2" |
35542 | 813 |
unfolding power2_norm_eq_inner inner_simps inner_commute by auto |
33175 | 814 |
|
815 |
lemma dot_norm_neg: "x \<bullet> y = ((norm x ^ 2 + norm y ^ 2) - norm(x - y) ^ 2) / 2" |
|
36350 | 816 |
unfolding power2_norm_eq_inner inner_simps inner_commute by(auto simp add:algebra_simps) |
33175 | 817 |
|
818 |
text{* Equality of vectors in terms of @{term "op \<bullet>"} products. *} |
|
819 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
820 |
lemma vector_eq: "(x:: real ^ 'n) = y \<longleftrightarrow> x \<bullet> x = x \<bullet> y\<and> y \<bullet> y = x \<bullet> x" (is "?lhs \<longleftrightarrow> ?rhs") |
33175 | 821 |
proof |
822 |
assume "?lhs" then show ?rhs by simp |
|
823 |
next |
|
824 |
assume ?rhs |
|
35542 | 825 |
then have "x \<bullet> x - x \<bullet> y = 0 \<and> x \<bullet> y - y \<bullet> y = 0" by simp |
826 |
hence "x \<bullet> (x - y) = 0 \<and> y \<bullet> (x - y) = 0" by (simp add: inner_simps inner_commute) |
|
36350 | 827 |
then have "(x - y) \<bullet> (x - y) = 0" by (simp add: field_simps inner_simps inner_commute) |
35542 | 828 |
then show "x = y" by (simp) |
33175 | 829 |
qed |
830 |
||
831 |
subsection{* General linear decision procedure for normed spaces. *} |
|
832 |
||
833 |
lemma norm_cmul_rule_thm: |
|
834 |
fixes x :: "'a::real_normed_vector" |
|
835 |
shows "b >= norm(x) ==> \<bar>c\<bar> * b >= norm(scaleR c x)" |
|
836 |
unfolding norm_scaleR |
|
837 |
apply (erule mult_mono1) |
|
838 |
apply simp |
|
839 |
done |
|
840 |
||
841 |
(* FIXME: Move all these theorems into the ML code using lemma antiquotation *) |
|
842 |
lemma norm_add_rule_thm: |
|
843 |
fixes x1 x2 :: "'a::real_normed_vector" |
|
844 |
shows "norm x1 \<le> b1 \<Longrightarrow> norm x2 \<le> b2 \<Longrightarrow> norm (x1 + x2) \<le> b1 + b2" |
|
845 |
by (rule order_trans [OF norm_triangle_ineq add_mono]) |
|
846 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
34964
diff
changeset
|
847 |
lemma ge_iff_diff_ge_0: "(a::'a::linordered_ring) \<ge> b == a - b \<ge> 0" |
36350 | 848 |
by (simp add: field_simps) |
33175 | 849 |
|
850 |
lemma pth_1: |
|
851 |
fixes x :: "'a::real_normed_vector" |
|
852 |
shows "x == scaleR 1 x" by simp |
|
853 |
||
854 |
lemma pth_2: |
|
855 |
fixes x :: "'a::real_normed_vector" |
|
856 |
shows "x - y == x + -y" by (atomize (full)) simp |
|
857 |
||
858 |
lemma pth_3: |
|
859 |
fixes x :: "'a::real_normed_vector" |
|
860 |
shows "- x == scaleR (-1) x" by simp |
|
861 |
||
862 |
lemma pth_4: |
|
863 |
fixes x :: "'a::real_normed_vector" |
|
864 |
shows "scaleR 0 x == 0" and "scaleR c 0 = (0::'a)" by simp_all |
|
865 |
||
866 |
lemma pth_5: |
|
867 |
fixes x :: "'a::real_normed_vector" |
|
868 |
shows "scaleR c (scaleR d x) == scaleR (c * d) x" by simp |
|
869 |
||
870 |
lemma pth_6: |
|
871 |
fixes x :: "'a::real_normed_vector" |
|
872 |
shows "scaleR c (x + y) == scaleR c x + scaleR c y" |
|
873 |
by (simp add: scaleR_right_distrib) |
|
874 |
||
875 |
lemma pth_7: |
|
876 |
fixes x :: "'a::real_normed_vector" |
|
877 |
shows "0 + x == x" and "x + 0 == x" by simp_all |
|
878 |
||
879 |
lemma pth_8: |
|
880 |
fixes x :: "'a::real_normed_vector" |
|
881 |
shows "scaleR c x + scaleR d x == scaleR (c + d) x" |
|
882 |
by (simp add: scaleR_left_distrib) |
|
883 |
||
884 |
lemma pth_9: |
|
885 |
fixes x :: "'a::real_normed_vector" shows |
|
886 |
"(scaleR c x + z) + scaleR d x == scaleR (c + d) x + z" |
|
887 |
"scaleR c x + (scaleR d x + z) == scaleR (c + d) x + z" |
|
888 |
"(scaleR c x + w) + (scaleR d x + z) == scaleR (c + d) x + (w + z)" |
|
889 |
by (simp_all add: algebra_simps) |
|
890 |
||
891 |
lemma pth_a: |
|
892 |
fixes x :: "'a::real_normed_vector" |
|
893 |
shows "scaleR 0 x + y == y" by simp |
|
894 |
||
895 |
lemma pth_b: |
|
896 |
fixes x :: "'a::real_normed_vector" shows |
|
897 |
"scaleR c x + scaleR d y == scaleR c x + scaleR d y" |
|
898 |
"(scaleR c x + z) + scaleR d y == scaleR c x + (z + scaleR d y)" |
|
899 |
"scaleR c x + (scaleR d y + z) == scaleR c x + (scaleR d y + z)" |
|
900 |
"(scaleR c x + w) + (scaleR d y + z) == scaleR c x + (w + (scaleR d y + z))" |
|
901 |
by (simp_all add: algebra_simps) |
|
902 |
||
903 |
lemma pth_c: |
|
904 |
fixes x :: "'a::real_normed_vector" shows |
|
905 |
"scaleR c x + scaleR d y == scaleR d y + scaleR c x" |
|
906 |
"(scaleR c x + z) + scaleR d y == scaleR d y + (scaleR c x + z)" |
|
907 |
"scaleR c x + (scaleR d y + z) == scaleR d y + (scaleR c x + z)" |
|
908 |
"(scaleR c x + w) + (scaleR d y + z) == scaleR d y + ((scaleR c x + w) + z)" |
|
909 |
by (simp_all add: algebra_simps) |
|
910 |
||
911 |
lemma pth_d: |
|
912 |
fixes x :: "'a::real_normed_vector" |
|
913 |
shows "x + 0 == x" by simp |
|
914 |
||
915 |
lemma norm_imp_pos_and_ge: |
|
916 |
fixes x :: "'a::real_normed_vector" |
|
917 |
shows "norm x == n \<Longrightarrow> norm x \<ge> 0 \<and> n \<ge> norm x" |
|
918 |
by atomize auto |
|
919 |
||
920 |
lemma real_eq_0_iff_le_ge_0: "(x::real) = 0 == x \<ge> 0 \<and> -x \<ge> 0" by arith |
|
921 |
||
922 |
lemma norm_pths: |
|
923 |
fixes x :: "'a::real_normed_vector" shows |
|
924 |
"x = y \<longleftrightarrow> norm (x - y) \<le> 0" |
|
925 |
"x \<noteq> y \<longleftrightarrow> \<not> (norm (x - y) \<le> 0)" |
|
926 |
using norm_ge_zero[of "x - y"] by auto |
|
927 |
||
928 |
lemma vector_dist_norm: |
|
929 |
fixes x :: "'a::real_normed_vector" |
|
930 |
shows "dist x y = norm (x - y)" |
|
931 |
by (rule dist_norm) |
|
932 |
||
933 |
use "normarith.ML" |
|
934 |
||
935 |
method_setup norm = {* Scan.succeed (SIMPLE_METHOD' o NormArith.norm_arith_tac) |
|
936 |
*} "Proves simple linear statements about vector norms" |
|
937 |
||
938 |
||
939 |
text{* Hence more metric properties. *} |
|
940 |
||
941 |
lemma dist_triangle_alt: |
|
942 |
fixes x y z :: "'a::metric_space" |
|
943 |
shows "dist y z <= dist x y + dist x z" |
|
944 |
using dist_triangle [of y z x] by (simp add: dist_commute) |
|
945 |
||
946 |
lemma dist_pos_lt: |
|
947 |
fixes x y :: "'a::metric_space" |
|
948 |
shows "x \<noteq> y ==> 0 < dist x y" |
|
949 |
by (simp add: zero_less_dist_iff) |
|
950 |
||
951 |
lemma dist_nz: |
|
952 |
fixes x y :: "'a::metric_space" |
|
953 |
shows "x \<noteq> y \<longleftrightarrow> 0 < dist x y" |
|
954 |
by (simp add: zero_less_dist_iff) |
|
955 |
||
956 |
lemma dist_triangle_le: |
|
957 |
fixes x y z :: "'a::metric_space" |
|
958 |
shows "dist x z + dist y z <= e \<Longrightarrow> dist x y <= e" |
|
959 |
by (rule order_trans [OF dist_triangle2]) |
|
960 |
||
961 |
lemma dist_triangle_lt: |
|
962 |
fixes x y z :: "'a::metric_space" |
|
963 |
shows "dist x z + dist y z < e ==> dist x y < e" |
|
964 |
by (rule le_less_trans [OF dist_triangle2]) |
|
965 |
||
966 |
lemma dist_triangle_half_l: |
|
967 |
fixes x1 x2 y :: "'a::metric_space" |
|
968 |
shows "dist x1 y < e / 2 \<Longrightarrow> dist x2 y < e / 2 \<Longrightarrow> dist x1 x2 < e" |
|
969 |
by (rule dist_triangle_lt [where z=y], simp) |
|
970 |
||
971 |
lemma dist_triangle_half_r: |
|
972 |
fixes x1 x2 y :: "'a::metric_space" |
|
973 |
shows "dist y x1 < e / 2 \<Longrightarrow> dist y x2 < e / 2 \<Longrightarrow> dist x1 x2 < e" |
|
974 |
by (rule dist_triangle_half_l, simp_all add: dist_commute) |
|
975 |
||
35172
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
976 |
|
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
977 |
lemma norm_triangle_half_r: |
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
978 |
shows "norm (y - x1) < e / 2 \<Longrightarrow> norm (y - x2) < e / 2 \<Longrightarrow> norm (x1 - x2) < e" |
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
979 |
using dist_triangle_half_r unfolding vector_dist_norm[THEN sym] by auto |
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
980 |
|
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
981 |
lemma norm_triangle_half_l: assumes "norm (x - y) < e / 2" "norm (x' - (y)) < e / 2" |
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
982 |
shows "norm (x - x') < e" |
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
983 |
using dist_triangle_half_l[OF assms[unfolded vector_dist_norm[THEN sym]]] |
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
984 |
unfolding vector_dist_norm[THEN sym] . |
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
985 |
|
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
986 |
lemma norm_triangle_le: "norm(x) + norm y <= e ==> norm(x + y) <= e" |
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
987 |
by (metis order_trans norm_triangle_ineq) |
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
988 |
|
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
989 |
lemma norm_triangle_lt: "norm(x) + norm(y) < e ==> norm(x + y) < e" |
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
990 |
by (metis basic_trans_rules(21) norm_triangle_ineq) |
579dd5570f96
Added integration to Multivariate-Analysis (upto FTC)
himmelma
parents:
35150
diff
changeset
|
991 |
|
33175 | 992 |
lemma dist_triangle_add: |
993 |
fixes x y x' y' :: "'a::real_normed_vector" |
|
994 |
shows "dist (x + y) (x' + y') <= dist x x' + dist y y'" |
|
995 |
by norm |
|
996 |
||
997 |
lemma dist_mul[simp]: "dist (c *s x) (c *s y) = \<bar>c\<bar> * dist x y" |
|
998 |
unfolding dist_norm vector_ssub_ldistrib[symmetric] norm_mul .. |
|
999 |
||
1000 |
lemma dist_triangle_add_half: |
|
1001 |
fixes x x' y y' :: "'a::real_normed_vector" |
|
1002 |
shows "dist x x' < e / 2 \<Longrightarrow> dist y y' < e / 2 \<Longrightarrow> dist(x + y) (x' + y') < e" |
|
1003 |
by norm |
|
1004 |
||
1005 |
lemma setsum_component [simp]: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1006 |
fixes f:: " 'a \<Rightarrow> ('b::comm_monoid_add) ^'n" |
33175 | 1007 |
shows "(setsum f S)$i = setsum (\<lambda>x. (f x)$i) S" |
1008 |
by (cases "finite S", induct S set: finite, simp_all) |
|
1009 |
||
1010 |
lemma setsum_eq: "setsum f S = (\<chi> i. setsum (\<lambda>x. (f x)$i ) S)" |
|
1011 |
by (simp add: Cart_eq) |
|
1012 |
||
1013 |
lemma setsum_clauses: |
|
1014 |
shows "setsum f {} = 0" |
|
1015 |
and "finite S \<Longrightarrow> setsum f (insert x S) = |
|
1016 |
(if x \<in> S then setsum f S else f x + setsum f S)" |
|
1017 |
by (auto simp add: insert_absorb) |
|
1018 |
||
1019 |
lemma setsum_cmul: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1020 |
fixes f:: "'c \<Rightarrow> ('a::semiring_1)^'n" |
33175 | 1021 |
shows "setsum (\<lambda>x. c *s f x) S = c *s setsum f S" |
1022 |
by (simp add: Cart_eq setsum_right_distrib) |
|
1023 |
||
1024 |
lemma setsum_norm: |
|
1025 |
fixes f :: "'a \<Rightarrow> 'b::real_normed_vector" |
|
1026 |
assumes fS: "finite S" |
|
1027 |
shows "norm (setsum f S) <= setsum (\<lambda>x. norm(f x)) S" |
|
1028 |
proof(induct rule: finite_induct[OF fS]) |
|
1029 |
case 1 thus ?case by simp |
|
1030 |
next |
|
1031 |
case (2 x S) |
|
1032 |
from "2.hyps" have "norm (setsum f (insert x S)) \<le> norm (f x) + norm (setsum f S)" by (simp add: norm_triangle_ineq) |
|
1033 |
also have "\<dots> \<le> norm (f x) + setsum (\<lambda>x. norm(f x)) S" |
|
1034 |
using "2.hyps" by simp |
|
1035 |
finally show ?case using "2.hyps" by simp |
|
1036 |
qed |
|
1037 |
||
1038 |
lemma real_setsum_norm: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1039 |
fixes f :: "'a \<Rightarrow> real ^'n" |
33175 | 1040 |
assumes fS: "finite S" |
1041 |
shows "norm (setsum f S) <= setsum (\<lambda>x. norm(f x)) S" |
|
1042 |
proof(induct rule: finite_induct[OF fS]) |
|
1043 |
case 1 thus ?case by simp |
|
1044 |
next |
|
1045 |
case (2 x S) |
|
1046 |
from "2.hyps" have "norm (setsum f (insert x S)) \<le> norm (f x) + norm (setsum f S)" by (simp add: norm_triangle_ineq) |
|
1047 |
also have "\<dots> \<le> norm (f x) + setsum (\<lambda>x. norm(f x)) S" |
|
1048 |
using "2.hyps" by simp |
|
1049 |
finally show ?case using "2.hyps" by simp |
|
1050 |
qed |
|
1051 |
||
1052 |
lemma setsum_norm_le: |
|
1053 |
fixes f :: "'a \<Rightarrow> 'b::real_normed_vector" |
|
1054 |
assumes fS: "finite S" |
|
1055 |
and fg: "\<forall>x \<in> S. norm (f x) \<le> g x" |
|
1056 |
shows "norm (setsum f S) \<le> setsum g S" |
|
1057 |
proof- |
|
1058 |
from fg have "setsum (\<lambda>x. norm(f x)) S <= setsum g S" |
|
1059 |
by - (rule setsum_mono, simp) |
|
1060 |
then show ?thesis using setsum_norm[OF fS, of f] fg |
|
1061 |
by arith |
|
1062 |
qed |
|
1063 |
||
1064 |
lemma real_setsum_norm_le: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1065 |
fixes f :: "'a \<Rightarrow> real ^ 'n" |
33175 | 1066 |
assumes fS: "finite S" |
1067 |
and fg: "\<forall>x \<in> S. norm (f x) \<le> g x" |
|
1068 |
shows "norm (setsum f S) \<le> setsum g S" |
|
1069 |
proof- |
|
1070 |
from fg have "setsum (\<lambda>x. norm(f x)) S <= setsum g S" |
|
1071 |
by - (rule setsum_mono, simp) |
|
1072 |
then show ?thesis using real_setsum_norm[OF fS, of f] fg |
|
1073 |
by arith |
|
1074 |
qed |
|
1075 |
||
1076 |
lemma setsum_norm_bound: |
|
1077 |
fixes f :: "'a \<Rightarrow> 'b::real_normed_vector" |
|
1078 |
assumes fS: "finite S" |
|
1079 |
and K: "\<forall>x \<in> S. norm (f x) \<le> K" |
|
1080 |
shows "norm (setsum f S) \<le> of_nat (card S) * K" |
|
1081 |
using setsum_norm_le[OF fS K] setsum_constant[symmetric] |
|
1082 |
by simp |
|
1083 |
||
1084 |
lemma real_setsum_norm_bound: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1085 |
fixes f :: "'a \<Rightarrow> real ^ 'n" |
33175 | 1086 |
assumes fS: "finite S" |
1087 |
and K: "\<forall>x \<in> S. norm (f x) \<le> K" |
|
1088 |
shows "norm (setsum f S) \<le> of_nat (card S) * K" |
|
1089 |
using real_setsum_norm_le[OF fS K] setsum_constant[symmetric] |
|
1090 |
by simp |
|
1091 |
||
1092 |
lemma setsum_vmul: |
|
1093 |
fixes f :: "'a \<Rightarrow> 'b::{real_normed_vector,semiring, mult_zero}" |
|
1094 |
assumes fS: "finite S" |
|
1095 |
shows "setsum f S *s v = setsum (\<lambda>x. f x *s v) S" |
|
1096 |
proof(induct rule: finite_induct[OF fS]) |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
1097 |
case 1 then show ?case by simp |
33175 | 1098 |
next |
1099 |
case (2 x F) |
|
1100 |
from "2.hyps" have "setsum f (insert x F) *s v = (f x + setsum f F) *s v" |
|
1101 |
by simp |
|
1102 |
also have "\<dots> = f x *s v + setsum f F *s v" |
|
1103 |
by (simp add: vector_sadd_rdistrib) |
|
1104 |
also have "\<dots> = setsum (\<lambda>x. f x *s v) (insert x F)" using "2.hyps" by simp |
|
1105 |
finally show ?case . |
|
1106 |
qed |
|
1107 |
||
1108 |
(* FIXME : Problem thm setsum_vmul[of _ "f:: 'a \<Rightarrow> real ^'n"] --- |
|
1109 |
Get rid of *s and use real_vector instead! Also prove that ^ creates a real_vector !! *) |
|
1110 |
||
1111 |
(* FIXME: Here too need stupid finiteness assumption on T!!! *) |
|
1112 |
lemma setsum_group: |
|
1113 |
assumes fS: "finite S" and fT: "finite T" and fST: "f ` S \<subseteq> T" |
|
1114 |
shows "setsum (\<lambda>y. setsum g {x. x\<in> S \<and> f x = y}) T = setsum g S" |
|
1115 |
||
1116 |
apply (subst setsum_image_gen[OF fS, of g f]) |
|
1117 |
apply (rule setsum_mono_zero_right[OF fT fST]) |
|
1118 |
by (auto intro: setsum_0') |
|
1119 |
||
1120 |
lemma vsum_norm_allsubsets_bound: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1121 |
fixes f:: "'a \<Rightarrow> real ^'n" |
33175 | 1122 |
assumes fP: "finite P" and fPs: "\<And>Q. Q \<subseteq> P \<Longrightarrow> norm (setsum f Q) \<le> e" |
1123 |
shows "setsum (\<lambda>x. norm (f x)) P \<le> 2 * real CARD('n) * e" |
|
1124 |
proof- |
|
1125 |
let ?d = "real CARD('n)" |
|
1126 |
let ?nf = "\<lambda>x. norm (f x)" |
|
1127 |
let ?U = "UNIV :: 'n set" |
|
1128 |
have th0: "setsum (\<lambda>x. setsum (\<lambda>i. \<bar>f x $ i\<bar>) ?U) P = setsum (\<lambda>i. setsum (\<lambda>x. \<bar>f x $ i\<bar>) P) ?U" |
|
1129 |
by (rule setsum_commute) |
|
1130 |
have th1: "2 * ?d * e = of_nat (card ?U) * (2 * e)" by (simp add: real_of_nat_def) |
|
1131 |
have "setsum ?nf P \<le> setsum (\<lambda>x. setsum (\<lambda>i. \<bar>f x $ i\<bar>) ?U) P" |
|
1132 |
apply (rule setsum_mono) |
|
1133 |
by (rule norm_le_l1) |
|
1134 |
also have "\<dots> \<le> 2 * ?d * e" |
|
1135 |
unfolding th0 th1 |
|
1136 |
proof(rule setsum_bounded) |
|
1137 |
fix i assume i: "i \<in> ?U" |
|
1138 |
let ?Pp = "{x. x\<in> P \<and> f x $ i \<ge> 0}" |
|
1139 |
let ?Pn = "{x. x \<in> P \<and> f x $ i < 0}" |
|
1140 |
have thp: "P = ?Pp \<union> ?Pn" by auto |
|
1141 |
have thp0: "?Pp \<inter> ?Pn ={}" by auto |
|
1142 |
have PpP: "?Pp \<subseteq> P" and PnP: "?Pn \<subseteq> P" by blast+ |
|
1143 |
have Ppe:"setsum (\<lambda>x. \<bar>f x $ i\<bar>) ?Pp \<le> e" |
|
1144 |
using component_le_norm[of "setsum (\<lambda>x. f x) ?Pp" i] fPs[OF PpP] |
|
1145 |
by (auto intro: abs_le_D1) |
|
1146 |
have Pne: "setsum (\<lambda>x. \<bar>f x $ i\<bar>) ?Pn \<le> e" |
|
1147 |
using component_le_norm[of "setsum (\<lambda>x. - f x) ?Pn" i] fPs[OF PnP] |
|
1148 |
by (auto simp add: setsum_negf intro: abs_le_D1) |
|
1149 |
have "setsum (\<lambda>x. \<bar>f x $ i\<bar>) P = setsum (\<lambda>x. \<bar>f x $ i\<bar>) ?Pp + setsum (\<lambda>x. \<bar>f x $ i\<bar>) ?Pn" |
|
1150 |
apply (subst thp) |
|
1151 |
apply (rule setsum_Un_zero) |
|
1152 |
using fP thp0 by auto |
|
1153 |
also have "\<dots> \<le> 2*e" using Pne Ppe by arith |
|
1154 |
finally show "setsum (\<lambda>x. \<bar>f x $ i\<bar>) P \<le> 2*e" . |
|
1155 |
qed |
|
1156 |
finally show ?thesis . |
|
1157 |
qed |
|
1158 |
||
35542 | 1159 |
lemma dot_lsum: "finite S \<Longrightarrow> setsum f S \<bullet> (y::'a::{real_inner}^'n) = setsum (\<lambda>x. f x \<bullet> y) S " |
1160 |
apply(induct rule: finite_induct) by(auto simp add: inner_simps) |
|
1161 |
||
1162 |
lemma dot_rsum: "finite S \<Longrightarrow> (y::'a::{real_inner}^'n) \<bullet> setsum f S = setsum (\<lambda>x. y \<bullet> f x) S " |
|
1163 |
apply(induct rule: finite_induct) by(auto simp add: inner_simps) |
|
33175 | 1164 |
|
1165 |
subsection{* Basis vectors in coordinate directions. *} |
|
1166 |
||
1167 |
definition "basis k = (\<chi> i. if i = k then 1 else 0)" |
|
1168 |
||
1169 |
lemma basis_component [simp]: "basis k $ i = (if k=i then 1 else 0)" |
|
1170 |
unfolding basis_def by simp |
|
1171 |
||
1172 |
lemma delta_mult_idempotent: |
|
1173 |
"(if k=a then 1 else (0::'a::semiring_1)) * (if k=a then 1 else 0) = (if k=a then 1 else 0)" by (cases "k=a", auto) |
|
1174 |
||
1175 |
lemma norm_basis: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1176 |
shows "norm (basis k :: real ^'n) = 1" |
35542 | 1177 |
apply (simp add: basis_def norm_eq_sqrt_inner) unfolding inner_vector_def |
33175 | 1178 |
apply (vector delta_mult_idempotent) |
35542 | 1179 |
using setsum_delta[of "UNIV :: 'n set" "k" "\<lambda>k. 1::real"] by auto |
33175 | 1180 |
|
1181 |
lemma norm_basis_1: "norm(basis 1 :: real ^'n::{finite,one}) = 1" |
|
1182 |
by (rule norm_basis) |
|
1183 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1184 |
lemma vector_choose_size: "0 <= c ==> \<exists>(x::real^'n). norm x = c" |
33175 | 1185 |
apply (rule exI[where x="c *s basis arbitrary"]) |
1186 |
by (simp only: norm_mul norm_basis) |
|
1187 |
||
1188 |
lemma vector_choose_dist: assumes e: "0 <= e" |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1189 |
shows "\<exists>(y::real^'n). dist x y = e" |
33175 | 1190 |
proof- |
1191 |
from vector_choose_size[OF e] obtain c:: "real ^'n" where "norm c = e" |
|
1192 |
by blast |
|
1193 |
then have "dist x (x - c) = e" by (simp add: dist_norm) |
|
1194 |
then show ?thesis by blast |
|
1195 |
qed |
|
1196 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1197 |
lemma basis_inj: "inj (basis :: 'n \<Rightarrow> real ^'n)" |
33175 | 1198 |
by (simp add: inj_on_def Cart_eq) |
1199 |
||
1200 |
lemma cond_value_iff: "f (if b then x else y) = (if b then f x else f y)" |
|
1201 |
by auto |
|
1202 |
||
1203 |
lemma basis_expansion: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1204 |
"setsum (\<lambda>i. (x$i) *s basis i) UNIV = (x::('a::ring_1) ^'n)" (is "?lhs = ?rhs" is "setsum ?f ?S = _") |
33175 | 1205 |
by (auto simp add: Cart_eq cond_value_iff setsum_delta[of "?S", where ?'b = "'a", simplified] cong del: if_weak_cong) |
1206 |
||
1207 |
lemma basis_expansion_unique: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1208 |
"setsum (\<lambda>i. f i *s basis i) UNIV = (x::('a::comm_ring_1) ^'n) \<longleftrightarrow> (\<forall>i. f i = x$i)" |
33175 | 1209 |
by (simp add: Cart_eq setsum_delta cond_value_iff cong del: if_weak_cong) |
1210 |
||
1211 |
lemma cond_application_beta: "(if b then f else g) x = (if b then f x else g x)" |
|
1212 |
by auto |
|
1213 |
||
1214 |
lemma dot_basis: |
|
35542 | 1215 |
shows "basis i \<bullet> x = x$i" "x \<bullet> (basis i) = (x$i)" |
1216 |
unfolding inner_vector_def by (auto simp add: basis_def cond_application_beta cond_value_iff setsum_delta cong del: if_weak_cong) |
|
33175 | 1217 |
|
1218 |
lemma inner_basis: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1219 |
fixes x :: "'a::{real_inner, real_algebra_1} ^ 'n" |
33175 | 1220 |
shows "inner (basis i) x = inner 1 (x $ i)" |
1221 |
and "inner x (basis i) = inner (x $ i) 1" |
|
1222 |
unfolding inner_vector_def basis_def |
|
1223 |
by (auto simp add: cond_application_beta cond_value_iff setsum_delta cong del: if_weak_cong) |
|
1224 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1225 |
lemma basis_eq_0: "basis i = (0::'a::semiring_1^'n) \<longleftrightarrow> False" |
33175 | 1226 |
by (auto simp add: Cart_eq) |
1227 |
||
1228 |
lemma basis_nonzero: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1229 |
shows "basis k \<noteq> (0:: 'a::semiring_1 ^'n)" |
33175 | 1230 |
by (simp add: basis_eq_0) |
1231 |
||
35542 | 1232 |
lemma vector_eq_ldot: "(\<forall>x. x \<bullet> y = x \<bullet> z) \<longleftrightarrow> y = (z::real^'n)" |
33175 | 1233 |
apply (auto simp add: Cart_eq dot_basis) |
1234 |
apply (erule_tac x="basis i" in allE) |
|
1235 |
apply (simp add: dot_basis) |
|
1236 |
apply (subgoal_tac "y = z") |
|
1237 |
apply simp |
|
1238 |
apply (simp add: Cart_eq) |
|
1239 |
done |
|
1240 |
||
35542 | 1241 |
lemma vector_eq_rdot: "(\<forall>z. x \<bullet> z = y \<bullet> z) \<longleftrightarrow> x = (y::real^'n)" |
33175 | 1242 |
apply (auto simp add: Cart_eq dot_basis) |
1243 |
apply (erule_tac x="basis i" in allE) |
|
1244 |
apply (simp add: dot_basis) |
|
1245 |
apply (subgoal_tac "x = y") |
|
1246 |
apply simp |
|
1247 |
apply (simp add: Cart_eq) |
|
1248 |
done |
|
1249 |
||
1250 |
subsection{* Orthogonality. *} |
|
1251 |
||
1252 |
definition "orthogonal x y \<longleftrightarrow> (x \<bullet> y = 0)" |
|
1253 |
||
1254 |
lemma orthogonal_basis: |
|
35542 | 1255 |
shows "orthogonal (basis i) x \<longleftrightarrow> x$i = (0::real)" |
1256 |
by (auto simp add: orthogonal_def inner_vector_def basis_def cond_value_iff cond_application_beta setsum_delta cong del: if_weak_cong) |
|
33175 | 1257 |
|
1258 |
lemma orthogonal_basis_basis: |
|
35542 | 1259 |
shows "orthogonal (basis i :: real^'n) (basis j) \<longleftrightarrow> i \<noteq> j" |
33175 | 1260 |
unfolding orthogonal_basis[of i] basis_component[of j] by simp |
1261 |
||
1262 |
(* FIXME : Maybe some of these require less than comm_ring, but not all*) |
|
1263 |
lemma orthogonal_clauses: |
|
35542 | 1264 |
"orthogonal a (0::real ^'n)" |
1265 |
"orthogonal a x ==> orthogonal a (c *\<^sub>R x)" |
|
33175 | 1266 |
"orthogonal a x ==> orthogonal a (-x)" |
1267 |
"orthogonal a x \<Longrightarrow> orthogonal a y ==> orthogonal a (x + y)" |
|
1268 |
"orthogonal a x \<Longrightarrow> orthogonal a y ==> orthogonal a (x - y)" |
|
1269 |
"orthogonal 0 a" |
|
35542 | 1270 |
"orthogonal x a ==> orthogonal (c *\<^sub>R x) a" |
33175 | 1271 |
"orthogonal x a ==> orthogonal (-x) a" |
1272 |
"orthogonal x a \<Longrightarrow> orthogonal y a ==> orthogonal (x + y) a" |
|
1273 |
"orthogonal x a \<Longrightarrow> orthogonal y a ==> orthogonal (x - y) a" |
|
35542 | 1274 |
unfolding orthogonal_def inner_simps by auto |
1275 |
||
1276 |
lemma orthogonal_commute: "orthogonal (x::real ^'n)y \<longleftrightarrow> orthogonal y x" |
|
1277 |
by (simp add: orthogonal_def inner_commute) |
|
33175 | 1278 |
|
1279 |
subsection{* Linear functions. *} |
|
1280 |
||
1281 |
definition "linear f \<longleftrightarrow> (\<forall>x y. f(x + y) = f x + f y) \<and> (\<forall>c x. f(c *s x) = c *s f x)" |
|
1282 |
||
33714
eb2574ac4173
Added new lemmas to Euclidean Space by Robert Himmelmann
hoelzl
parents:
33270
diff
changeset
|
1283 |
lemma linearI: assumes "\<And>x y. f (x + y) = f x + f y" "\<And>c x. f (c *s x) = c *s f x" |
eb2574ac4173
Added new lemmas to Euclidean Space by Robert Himmelmann
hoelzl
parents:
33270
diff
changeset
|
1284 |
shows "linear f" using assms unfolding linear_def by auto |
eb2574ac4173
Added new lemmas to Euclidean Space by Robert Himmelmann
hoelzl
parents:
33270
diff
changeset
|
1285 |
|
33175 | 1286 |
lemma linear_compose_cmul: "linear f ==> linear (\<lambda>x. (c::'a::comm_semiring) *s f x)" |
36350 | 1287 |
by (vector linear_def Cart_eq field_simps) |
33175 | 1288 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1289 |
lemma linear_compose_neg: "linear (f :: 'a ^'n \<Rightarrow> 'a::comm_ring ^'m) ==> linear (\<lambda>x. -(f(x)))" by (vector linear_def Cart_eq) |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1290 |
|
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1291 |
lemma linear_compose_add: "linear (f :: 'a ^'n \<Rightarrow> 'a::semiring_1 ^'m) \<Longrightarrow> linear g ==> linear (\<lambda>x. f(x) + g(x))" |
36350 | 1292 |
by (vector linear_def Cart_eq field_simps) |
33175 | 1293 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1294 |
lemma linear_compose_sub: "linear (f :: 'a ^'n \<Rightarrow> 'a::ring_1 ^'m) \<Longrightarrow> linear g ==> linear (\<lambda>x. f x - g x)" |
36350 | 1295 |
by (vector linear_def Cart_eq field_simps) |
33175 | 1296 |
|
1297 |
lemma linear_compose: "linear f \<Longrightarrow> linear g ==> linear (g o f)" |
|
1298 |
by (simp add: linear_def) |
|
1299 |
||
1300 |
lemma linear_id: "linear id" by (simp add: linear_def id_def) |
|
1301 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1302 |
lemma linear_zero: "linear (\<lambda>x. 0::'a::semiring_1 ^ 'n)" by (simp add: linear_def) |
33175 | 1303 |
|
1304 |
lemma linear_compose_setsum: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1305 |
assumes fS: "finite S" and lS: "\<forall>a \<in> S. linear (f a :: 'a::semiring_1 ^ 'n \<Rightarrow> 'a ^'m)" |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1306 |
shows "linear(\<lambda>x. setsum (\<lambda>a. f a x :: 'a::semiring_1 ^'m) S)" |
33175 | 1307 |
using lS |
1308 |
apply (induct rule: finite_induct[OF fS]) |
|
1309 |
by (auto simp add: linear_zero intro: linear_compose_add) |
|
1310 |
||
1311 |
lemma linear_vmul_component: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1312 |
fixes f:: "'a::semiring_1^'m \<Rightarrow> 'a^'n" |
33175 | 1313 |
assumes lf: "linear f" |
1314 |
shows "linear (\<lambda>x. f x $ k *s v)" |
|
1315 |
using lf |
|
1316 |
apply (auto simp add: linear_def ) |
|
36350 | 1317 |
by (vector field_simps)+ |
33175 | 1318 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1319 |
lemma linear_0: "linear f ==> f 0 = (0::'a::semiring_1 ^'n)" |
33175 | 1320 |
unfolding linear_def |
1321 |
apply clarsimp |
|
1322 |
apply (erule allE[where x="0::'a"]) |
|
1323 |
apply simp |
|
1324 |
done |
|
1325 |
||
1326 |
lemma linear_cmul: "linear f ==> f(c*s x) = c *s f x" by (simp add: linear_def) |
|
1327 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1328 |
lemma linear_neg: "linear (f :: 'a::ring_1 ^'n \<Rightarrow> _) ==> f (-x) = - f x" |
33175 | 1329 |
unfolding vector_sneg_minus1 |
1330 |
using linear_cmul[of f] by auto |
|
1331 |
||
1332 |
lemma linear_add: "linear f ==> f(x + y) = f x + f y" by (metis linear_def) |
|
1333 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1334 |
lemma linear_sub: "linear (f::'a::ring_1 ^'n \<Rightarrow> _) ==> f(x - y) = f x - f y" |
33175 | 1335 |
by (simp add: diff_def linear_add linear_neg) |
1336 |
||
1337 |
lemma linear_setsum: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1338 |
fixes f:: "'a::semiring_1^'n \<Rightarrow> _" |
33175 | 1339 |
assumes lf: "linear f" and fS: "finite S" |
1340 |
shows "f (setsum g S) = setsum (f o g) S" |
|
1341 |
proof (induct rule: finite_induct[OF fS]) |
|
1342 |
case 1 thus ?case by (simp add: linear_0[OF lf]) |
|
1343 |
next |
|
1344 |
case (2 x F) |
|
1345 |
have "f (setsum g (insert x F)) = f (g x + setsum g F)" using "2.hyps" |
|
1346 |
by simp |
|
1347 |
also have "\<dots> = f (g x) + f (setsum g F)" using linear_add[OF lf] by simp |
|
1348 |
also have "\<dots> = setsum (f o g) (insert x F)" using "2.hyps" by simp |
|
1349 |
finally show ?case . |
|
1350 |
qed |
|
1351 |
||
1352 |
lemma linear_setsum_mul: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1353 |
fixes f:: "'a ^'n \<Rightarrow> 'a::semiring_1^'m" |
33175 | 1354 |
assumes lf: "linear f" and fS: "finite S" |
1355 |
shows "f (setsum (\<lambda>i. c i *s v i) S) = setsum (\<lambda>i. c i *s f (v i)) S" |
|
1356 |
using linear_setsum[OF lf fS, of "\<lambda>i. c i *s v i" , unfolded o_def] |
|
1357 |
linear_cmul[OF lf] by simp |
|
1358 |
||
1359 |
lemma linear_injective_0: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1360 |
assumes lf: "linear (f:: 'a::ring_1 ^ 'n \<Rightarrow> _)" |
33175 | 1361 |
shows "inj f \<longleftrightarrow> (\<forall>x. f x = 0 \<longrightarrow> x = 0)" |
1362 |
proof- |
|
1363 |
have "inj f \<longleftrightarrow> (\<forall> x y. f x = f y \<longrightarrow> x = y)" by (simp add: inj_on_def) |
|
1364 |
also have "\<dots> \<longleftrightarrow> (\<forall> x y. f x - f y = 0 \<longrightarrow> x - y = 0)" by simp |
|
1365 |
also have "\<dots> \<longleftrightarrow> (\<forall> x y. f (x - y) = 0 \<longrightarrow> x - y = 0)" |
|
1366 |
by (simp add: linear_sub[OF lf]) |
|
1367 |
also have "\<dots> \<longleftrightarrow> (\<forall> x. f x = 0 \<longrightarrow> x = 0)" by auto |
|
1368 |
finally show ?thesis . |
|
1369 |
qed |
|
1370 |
||
1371 |
lemma linear_bounded: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1372 |
fixes f:: "real ^'m \<Rightarrow> real ^'n" |
33175 | 1373 |
assumes lf: "linear f" |
1374 |
shows "\<exists>B. \<forall>x. norm (f x) \<le> B * norm x" |
|
1375 |
proof- |
|
1376 |
let ?S = "UNIV:: 'm set" |
|
1377 |
let ?B = "setsum (\<lambda>i. norm(f(basis i))) ?S" |
|
1378 |
have fS: "finite ?S" by simp |
|
1379 |
{fix x:: "real ^ 'm" |
|
1380 |
let ?g = "(\<lambda>i. (x$i) *s (basis i) :: real ^ 'm)" |
|
1381 |
have "norm (f x) = norm (f (setsum (\<lambda>i. (x$i) *s (basis i)) ?S))" |
|
1382 |
by (simp only: basis_expansion) |
|
1383 |
also have "\<dots> = norm (setsum (\<lambda>i. (x$i) *s f (basis i))?S)" |
|
1384 |
using linear_setsum[OF lf fS, of ?g, unfolded o_def] linear_cmul[OF lf] |
|
1385 |
by auto |
|
1386 |
finally have th0: "norm (f x) = norm (setsum (\<lambda>i. (x$i) *s f (basis i))?S)" . |
|
1387 |
{fix i assume i: "i \<in> ?S" |
|
1388 |
from component_le_norm[of x i] |
|
1389 |
have "norm ((x$i) *s f (basis i :: real ^'m)) \<le> norm (f (basis i)) * norm x" |
|
1390 |
unfolding norm_mul |
|
1391 |
apply (simp only: mult_commute) |
|
1392 |
apply (rule mult_mono) |
|
36365 | 1393 |
by (auto simp add: field_simps) } |
33175 | 1394 |
then have th: "\<forall>i\<in> ?S. norm ((x$i) *s f (basis i :: real ^'m)) \<le> norm (f (basis i)) * norm x" by metis |
1395 |
from real_setsum_norm_le[OF fS, of "\<lambda>i. (x$i) *s (f (basis i))", OF th] |
|
1396 |
have "norm (f x) \<le> ?B * norm x" unfolding th0 setsum_left_distrib by metis} |
|
1397 |
then show ?thesis by blast |
|
1398 |
qed |
|
1399 |
||
1400 |
lemma linear_bounded_pos: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1401 |
fixes f:: "real ^'n \<Rightarrow> real ^'m" |
33175 | 1402 |
assumes lf: "linear f" |
1403 |
shows "\<exists>B > 0. \<forall>x. norm (f x) \<le> B * norm x" |
|
1404 |
proof- |
|
1405 |
from linear_bounded[OF lf] obtain B where |
|
1406 |
B: "\<forall>x. norm (f x) \<le> B * norm x" by blast |
|
1407 |
let ?K = "\<bar>B\<bar> + 1" |
|
1408 |
have Kp: "?K > 0" by arith |
|
1409 |
{assume C: "B < 0" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
1410 |
have "norm (1::real ^ 'n) > 0" by simp |
33175 | 1411 |
with C have "B * norm (1:: real ^ 'n) < 0" |
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
1412 |
by (simp add: mult_less_0_iff) |
33175 | 1413 |
with B[rule_format, of 1] norm_ge_zero[of "f 1"] have False by simp |
1414 |
} |
|
1415 |
then have Bp: "B \<ge> 0" by ferrack |
|
1416 |
{fix x::"real ^ 'n" |
|
1417 |
have "norm (f x) \<le> ?K * norm x" |
|
1418 |
using B[rule_format, of x] norm_ge_zero[of x] norm_ge_zero[of "f x"] Bp |
|
36350 | 1419 |
apply (auto simp add: field_simps split add: abs_split) |
33175 | 1420 |
apply (erule order_trans, simp) |
1421 |
done |
|
1422 |
} |
|
1423 |
then show ?thesis using Kp by blast |
|
1424 |
qed |
|
1425 |
||
1426 |
lemma smult_conv_scaleR: "c *s x = scaleR c x" |
|
1427 |
unfolding vector_scalar_mult_def vector_scaleR_def by simp |
|
1428 |
||
1429 |
lemma linear_conv_bounded_linear: |
|
1430 |
fixes f :: "real ^ _ \<Rightarrow> real ^ _" |
|
1431 |
shows "linear f \<longleftrightarrow> bounded_linear f" |
|
1432 |
proof |
|
1433 |
assume "linear f" |
|
1434 |
show "bounded_linear f" |
|
1435 |
proof |
|
1436 |
fix x y show "f (x + y) = f x + f y" |
|
1437 |
using `linear f` unfolding linear_def by simp |
|
1438 |
next |
|
1439 |
fix r x show "f (scaleR r x) = scaleR r (f x)" |
|
1440 |
using `linear f` unfolding linear_def |
|
1441 |
by (simp add: smult_conv_scaleR) |
|
1442 |
next |
|
1443 |
have "\<exists>B. \<forall>x. norm (f x) \<le> B * norm x" |
|
1444 |
using `linear f` by (rule linear_bounded) |
|
1445 |
thus "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K" |
|
1446 |
by (simp add: mult_commute) |
|
1447 |
qed |
|
1448 |
next |
|
1449 |
assume "bounded_linear f" |
|
1450 |
then interpret f: bounded_linear f . |
|
1451 |
show "linear f" |
|
1452 |
unfolding linear_def smult_conv_scaleR |
|
1453 |
by (simp add: f.add f.scaleR) |
|
1454 |
qed |
|
1455 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1456 |
lemma bounded_linearI': fixes f::"real^'n \<Rightarrow> real^'m" |
33714
eb2574ac4173
Added new lemmas to Euclidean Space by Robert Himmelmann
hoelzl
parents:
33270
diff
changeset
|
1457 |
assumes "\<And>x y. f (x + y) = f x + f y" "\<And>c x. f (c *s x) = c *s f x" |
eb2574ac4173
Added new lemmas to Euclidean Space by Robert Himmelmann
hoelzl
parents:
33270
diff
changeset
|
1458 |
shows "bounded_linear f" unfolding linear_conv_bounded_linear[THEN sym] |
eb2574ac4173
Added new lemmas to Euclidean Space by Robert Himmelmann
hoelzl
parents:
33270
diff
changeset
|
1459 |
by(rule linearI[OF assms]) |
eb2574ac4173
Added new lemmas to Euclidean Space by Robert Himmelmann
hoelzl
parents:
33270
diff
changeset
|
1460 |
|
33175 | 1461 |
subsection{* Bilinear functions. *} |
1462 |
||
1463 |
definition "bilinear f \<longleftrightarrow> (\<forall>x. linear(\<lambda>y. f x y)) \<and> (\<forall>y. linear(\<lambda>x. f x y))" |
|
1464 |
||
1465 |
lemma bilinear_ladd: "bilinear h ==> h (x + y) z = (h x z) + (h y z)" |
|
1466 |
by (simp add: bilinear_def linear_def) |
|
1467 |
lemma bilinear_radd: "bilinear h ==> h x (y + z) = (h x y) + (h x z)" |
|
1468 |
by (simp add: bilinear_def linear_def) |
|
1469 |
||
1470 |
lemma bilinear_lmul: "bilinear h ==> h (c *s x) y = c *s (h x y)" |
|
1471 |
by (simp add: bilinear_def linear_def) |
|
1472 |
||
1473 |
lemma bilinear_rmul: "bilinear h ==> h x (c *s y) = c *s (h x y)" |
|
1474 |
by (simp add: bilinear_def linear_def) |
|
1475 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1476 |
lemma bilinear_lneg: "bilinear h ==> h (- (x:: 'a::ring_1 ^ 'n)) y = -(h x y)" |
33175 | 1477 |
by (simp only: vector_sneg_minus1 bilinear_lmul) |
1478 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1479 |
lemma bilinear_rneg: "bilinear h ==> h x (- (y:: 'a::ring_1 ^ 'n)) = - h x y" |
33175 | 1480 |
by (simp only: vector_sneg_minus1 bilinear_rmul) |
1481 |
||
1482 |
lemma (in ab_group_add) eq_add_iff: "x = x + y \<longleftrightarrow> y = 0" |
|
1483 |
using add_imp_eq[of x y 0] by auto |
|
1484 |
||
1485 |
lemma bilinear_lzero: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1486 |
fixes h :: "'a::ring^'n \<Rightarrow> _" assumes bh: "bilinear h" shows "h 0 x = 0" |
33175 | 1487 |
using bilinear_ladd[OF bh, of 0 0 x] |
36350 | 1488 |
by (simp add: eq_add_iff field_simps) |
33175 | 1489 |
|
1490 |
lemma bilinear_rzero: |
|
34289 | 1491 |
fixes h :: "'a::ring^_ \<Rightarrow> _" assumes bh: "bilinear h" shows "h x 0 = 0" |
33175 | 1492 |
using bilinear_radd[OF bh, of x 0 0 ] |
36350 | 1493 |
by (simp add: eq_add_iff field_simps) |
33175 | 1494 |
|
34289 | 1495 |
lemma bilinear_lsub: "bilinear h ==> h (x - (y:: 'a::ring_1 ^ _)) z = h x z - h y z" |
33175 | 1496 |
by (simp add: diff_def bilinear_ladd bilinear_lneg) |
1497 |
||
34289 | 1498 |
lemma bilinear_rsub: "bilinear h ==> h z (x - (y:: 'a::ring_1 ^ _)) = h z x - h z y" |
33175 | 1499 |
by (simp add: diff_def bilinear_radd bilinear_rneg) |
1500 |
||
1501 |
lemma bilinear_setsum: |
|
34289 | 1502 |
fixes h:: "'a ^_ \<Rightarrow> 'a::semiring_1^_\<Rightarrow> 'a ^ _" |
33175 | 1503 |
assumes bh: "bilinear h" and fS: "finite S" and fT: "finite T" |
1504 |
shows "h (setsum f S) (setsum g T) = setsum (\<lambda>(i,j). h (f i) (g j)) (S \<times> T) " |
|
1505 |
proof- |
|
1506 |
have "h (setsum f S) (setsum g T) = setsum (\<lambda>x. h (f x) (setsum g T)) S" |
|
1507 |
apply (rule linear_setsum[unfolded o_def]) |
|
1508 |
using bh fS by (auto simp add: bilinear_def) |
|
1509 |
also have "\<dots> = setsum (\<lambda>x. setsum (\<lambda>y. h (f x) (g y)) T) S" |
|
1510 |
apply (rule setsum_cong, simp) |
|
1511 |
apply (rule linear_setsum[unfolded o_def]) |
|
1512 |
using bh fT by (auto simp add: bilinear_def) |
|
1513 |
finally show ?thesis unfolding setsum_cartesian_product . |
|
1514 |
qed |
|
1515 |
||
1516 |
lemma bilinear_bounded: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1517 |
fixes h:: "real ^'m \<Rightarrow> real^'n \<Rightarrow> real ^'k" |
33175 | 1518 |
assumes bh: "bilinear h" |
1519 |
shows "\<exists>B. \<forall>x y. norm (h x y) \<le> B * norm x * norm y" |
|
1520 |
proof- |
|
1521 |
let ?M = "UNIV :: 'm set" |
|
1522 |
let ?N = "UNIV :: 'n set" |
|
1523 |
let ?B = "setsum (\<lambda>(i,j). norm (h (basis i) (basis j))) (?M \<times> ?N)" |
|
1524 |
have fM: "finite ?M" and fN: "finite ?N" by simp_all |
|
1525 |
{fix x:: "real ^ 'm" and y :: "real^'n" |
|
1526 |
have "norm (h x y) = norm (h (setsum (\<lambda>i. (x$i) *s basis i) ?M) (setsum (\<lambda>i. (y$i) *s basis i) ?N))" unfolding basis_expansion .. |
|
1527 |
also have "\<dots> = norm (setsum (\<lambda> (i,j). h ((x$i) *s basis i) ((y$j) *s basis j)) (?M \<times> ?N))" unfolding bilinear_setsum[OF bh fM fN] .. |
|
1528 |
finally have th: "norm (h x y) = \<dots>" . |
|
1529 |
have "norm (h x y) \<le> ?B * norm x * norm y" |
|
1530 |
apply (simp add: setsum_left_distrib th) |
|
1531 |
apply (rule real_setsum_norm_le) |
|
1532 |
using fN fM |
|
1533 |
apply simp |
|
36365 | 1534 |
apply (auto simp add: bilinear_rmul[OF bh] bilinear_lmul[OF bh] field_simps) |
33175 | 1535 |
apply (rule mult_mono) |
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
1536 |
apply (auto simp add: zero_le_mult_iff component_le_norm) |
33175 | 1537 |
apply (rule mult_mono) |
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
1538 |
apply (auto simp add: zero_le_mult_iff component_le_norm) |
33175 | 1539 |
done} |
1540 |
then show ?thesis by metis |
|
1541 |
qed |
|
1542 |
||
1543 |
lemma bilinear_bounded_pos: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1544 |
fixes h:: "real ^'m \<Rightarrow> real^'n \<Rightarrow> real ^'k" |
33175 | 1545 |
assumes bh: "bilinear h" |
1546 |
shows "\<exists>B > 0. \<forall>x y. norm (h x y) \<le> B * norm x * norm y" |
|
1547 |
proof- |
|
1548 |
from bilinear_bounded[OF bh] obtain B where |
|
1549 |
B: "\<forall>x y. norm (h x y) \<le> B * norm x * norm y" by blast |
|
1550 |
let ?K = "\<bar>B\<bar> + 1" |
|
1551 |
have Kp: "?K > 0" by arith |
|
1552 |
have KB: "B < ?K" by arith |
|
1553 |
{fix x::"real ^'m" and y :: "real ^'n" |
|
1554 |
from KB Kp |
|
1555 |
have "B * norm x * norm y \<le> ?K * norm x * norm y" |
|
1556 |
apply - |
|
1557 |
apply (rule mult_right_mono, rule mult_right_mono) |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
1558 |
by auto |
33175 | 1559 |
then have "norm (h x y) \<le> ?K * norm x * norm y" |
1560 |
using B[rule_format, of x y] by simp} |
|
1561 |
with Kp show ?thesis by blast |
|
1562 |
qed |
|
1563 |
||
1564 |
lemma bilinear_conv_bounded_bilinear: |
|
1565 |
fixes h :: "real ^ _ \<Rightarrow> real ^ _ \<Rightarrow> real ^ _" |
|
1566 |
shows "bilinear h \<longleftrightarrow> bounded_bilinear h" |
|
1567 |
proof |
|
1568 |
assume "bilinear h" |
|
1569 |
show "bounded_bilinear h" |
|
1570 |
proof |
|
1571 |
fix x y z show "h (x + y) z = h x z + h y z" |
|
1572 |
using `bilinear h` unfolding bilinear_def linear_def by simp |
|
1573 |
next |
|
1574 |
fix x y z show "h x (y + z) = h x y + h x z" |
|
1575 |
using `bilinear h` unfolding bilinear_def linear_def by simp |
|
1576 |
next |
|
1577 |
fix r x y show "h (scaleR r x) y = scaleR r (h x y)" |
|
1578 |
using `bilinear h` unfolding bilinear_def linear_def |
|
1579 |
by (simp add: smult_conv_scaleR) |
|
1580 |
next |
|
1581 |
fix r x y show "h x (scaleR r y) = scaleR r (h x y)" |
|
1582 |
using `bilinear h` unfolding bilinear_def linear_def |
|
1583 |
by (simp add: smult_conv_scaleR) |
|
1584 |
next |
|
1585 |
have "\<exists>B. \<forall>x y. norm (h x y) \<le> B * norm x * norm y" |
|
1586 |
using `bilinear h` by (rule bilinear_bounded) |
|
1587 |
thus "\<exists>K. \<forall>x y. norm (h x y) \<le> norm x * norm y * K" |
|
1588 |
by (simp add: mult_ac) |
|
1589 |
qed |
|
1590 |
next |
|
1591 |
assume "bounded_bilinear h" |
|
1592 |
then interpret h: bounded_bilinear h . |
|
1593 |
show "bilinear h" |
|
1594 |
unfolding bilinear_def linear_conv_bounded_linear |
|
1595 |
using h.bounded_linear_left h.bounded_linear_right |
|
1596 |
by simp |
|
1597 |
qed |
|
1598 |
||
1599 |
subsection{* Adjoints. *} |
|
1600 |
||
1601 |
definition "adjoint f = (SOME f'. \<forall>x y. f x \<bullet> y = x \<bullet> f' y)" |
|
1602 |
||
1603 |
lemma choice_iff: "(\<forall>x. \<exists>y. P x y) \<longleftrightarrow> (\<exists>f. \<forall>x. P x (f x))" by metis |
|
1604 |
||
1605 |
lemma adjoint_works_lemma: |
|
35542 | 1606 |
fixes f:: "real ^'n \<Rightarrow> real ^'m" |
33175 | 1607 |
assumes lf: "linear f" |
1608 |
shows "\<forall>x y. f x \<bullet> y = x \<bullet> adjoint f y" |
|
1609 |
proof- |
|
1610 |
let ?N = "UNIV :: 'n set" |
|
1611 |
let ?M = "UNIV :: 'm set" |
|
1612 |
have fN: "finite ?N" by simp |
|
1613 |
have fM: "finite ?M" by simp |
|
35542 | 1614 |
{fix y:: "real ^ 'm" |
1615 |
let ?w = "(\<chi> i. (f (basis i) \<bullet> y)) :: real ^ 'n" |
|
33175 | 1616 |
{fix x |
1617 |
have "f x \<bullet> y = f (setsum (\<lambda>i. (x$i) *s basis i) ?N) \<bullet> y" |
|
1618 |
by (simp only: basis_expansion) |
|
1619 |
also have "\<dots> = (setsum (\<lambda>i. (x$i) *s f (basis i)) ?N) \<bullet> y" |
|
1620 |
unfolding linear_setsum[OF lf fN] |
|
1621 |
by (simp add: linear_cmul[OF lf]) |
|
1622 |
finally have "f x \<bullet> y = x \<bullet> ?w" |
|
1623 |
apply (simp only: ) |
|
36350 | 1624 |
apply (simp add: inner_vector_def setsum_left_distrib setsum_right_distrib setsum_commute[of _ ?M ?N] field_simps) |
33175 | 1625 |
done} |
1626 |
} |
|
1627 |
then show ?thesis unfolding adjoint_def |
|
1628 |
some_eq_ex[of "\<lambda>f'. \<forall>x y. f x \<bullet> y = x \<bullet> f' y"] |
|
1629 |
using choice_iff[of "\<lambda>a b. \<forall>x. f x \<bullet> a = x \<bullet> b "] |
|
1630 |
by metis |
|
1631 |
qed |
|
1632 |
||
1633 |
lemma adjoint_works: |
|
35542 | 1634 |
fixes f:: "real ^'n \<Rightarrow> real ^'m" |
33175 | 1635 |
assumes lf: "linear f" |
1636 |
shows "x \<bullet> adjoint f y = f x \<bullet> y" |
|
1637 |
using adjoint_works_lemma[OF lf] by metis |
|
1638 |
||
1639 |
lemma adjoint_linear: |
|
35542 | 1640 |
fixes f:: "real ^'n \<Rightarrow> real ^'m" |
33175 | 1641 |
assumes lf: "linear f" |
1642 |
shows "linear (adjoint f)" |
|
35542 | 1643 |
unfolding linear_def vector_eq_ldot[symmetric] apply safe |
1644 |
unfolding inner_simps smult_conv_scaleR adjoint_works[OF lf] by auto |
|
33175 | 1645 |
|
1646 |
lemma adjoint_clauses: |
|
35542 | 1647 |
fixes f:: "real ^'n \<Rightarrow> real ^'m" |
33175 | 1648 |
assumes lf: "linear f" |
1649 |
shows "x \<bullet> adjoint f y = f x \<bullet> y" |
|
1650 |
and "adjoint f y \<bullet> x = y \<bullet> f x" |
|
35542 | 1651 |
by (simp_all add: adjoint_works[OF lf] inner_commute) |
33175 | 1652 |
|
1653 |
lemma adjoint_adjoint: |
|
35542 | 1654 |
fixes f:: "real ^'n \<Rightarrow> real ^'m" |
33175 | 1655 |
assumes lf: "linear f" |
1656 |
shows "adjoint (adjoint f) = f" |
|
1657 |
apply (rule ext) |
|
1658 |
by (simp add: vector_eq_ldot[symmetric] adjoint_clauses[OF adjoint_linear[OF lf]] adjoint_clauses[OF lf]) |
|
1659 |
||
1660 |
lemma adjoint_unique: |
|
35542 | 1661 |
fixes f:: "real ^'n \<Rightarrow> real ^'m" |
33175 | 1662 |
assumes lf: "linear f" and u: "\<forall>x y. f' x \<bullet> y = x \<bullet> f y" |
1663 |
shows "f' = adjoint f" |
|
1664 |
apply (rule ext) |
|
1665 |
using u |
|
1666 |
by (simp add: vector_eq_rdot[symmetric] adjoint_clauses[OF lf]) |
|
1667 |
||
36581 | 1668 |
subsection {* Matrix operations *} |
1669 |
||
33175 | 1670 |
text{* Matrix notation. NB: an MxN matrix is of type @{typ "'a^'n^'m"}, not @{typ "'a^'m^'n"} *} |
1671 |
||
34292
14fd037ccc47
remove overloaded star operator, use specific vector / matrix operators
hoelzl
parents:
34291
diff
changeset
|
1672 |
definition matrix_matrix_mult :: "('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'p^'n \<Rightarrow> 'a ^ 'p ^'m" (infixl "**" 70) |
14fd037ccc47
remove overloaded star operator, use specific vector / matrix operators
hoelzl
parents:
34291
diff
changeset
|
1673 |
where "m ** m' == (\<chi> i j. setsum (\<lambda>k. ((m$i)$k) * ((m'$k)$j)) (UNIV :: 'n set)) ::'a ^ 'p ^'m" |
14fd037ccc47
remove overloaded star operator, use specific vector / matrix operators
hoelzl
parents:
34291
diff
changeset
|
1674 |
|
14fd037ccc47
remove overloaded star operator, use specific vector / matrix operators
hoelzl
parents:
34291
diff
changeset
|
1675 |
definition matrix_vector_mult :: "('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'n \<Rightarrow> 'a ^ 'm" (infixl "*v" 70) |
14fd037ccc47
remove overloaded star operator, use specific vector / matrix operators
hoelzl
parents:
34291
diff
changeset
|
1676 |
where "m *v x \<equiv> (\<chi> i. setsum (\<lambda>j. ((m$i)$j) * (x$j)) (UNIV ::'n set)) :: 'a^'m" |
14fd037ccc47
remove overloaded star operator, use specific vector / matrix operators
hoelzl
parents:
34291
diff
changeset
|
1677 |
|
14fd037ccc47
remove overloaded star operator, use specific vector / matrix operators
hoelzl
parents:
34291
diff
changeset
|
1678 |
definition vector_matrix_mult :: "'a ^ 'm \<Rightarrow> ('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'n " (infixl "v*" 70) |
14fd037ccc47
remove overloaded star operator, use specific vector / matrix operators
hoelzl
parents:
34291
diff
changeset
|
1679 |
where "v v* m == (\<chi> j. setsum (\<lambda>i. ((m$i)$j) * (v$i)) (UNIV :: 'm set)) :: 'a^'n" |
33175 | 1680 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1681 |
definition "(mat::'a::zero => 'a ^'n^'n) k = (\<chi> i j. if i = j then k else 0)" |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1682 |
definition transpose where |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1683 |
"(transpose::'a^'n^'m \<Rightarrow> 'a^'m^'n) A = (\<chi> i j. ((A$j)$i))" |
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1684 |
definition "(row::'m => 'a ^'n^'m \<Rightarrow> 'a ^'n) i A = (\<chi> j. ((A$i)$j))" |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1685 |
definition "(column::'n =>'a^'n^'m =>'a^'m) j A = (\<chi> i. ((A$i)$j))" |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1686 |
definition "rows(A::'a^'n^'m) = { row i A | i. i \<in> (UNIV :: 'm set)}" |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1687 |
definition "columns(A::'a^'n^'m) = { column i A | i. i \<in> (UNIV :: 'n set)}" |
33175 | 1688 |
|
1689 |
lemma mat_0[simp]: "mat 0 = 0" by (vector mat_def) |
|
34292
14fd037ccc47
remove overloaded star operator, use specific vector / matrix operators
hoelzl
parents:
34291
diff
changeset
|
1690 |
lemma matrix_add_ldistrib: "(A ** (B + C)) = (A ** B) + (A ** C)" |
36350 | 1691 |
by (vector matrix_matrix_mult_def setsum_addf[symmetric] field_simps) |
33175 | 1692 |
|
1693 |
lemma matrix_mul_lid: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1694 |
fixes A :: "'a::semiring_1 ^ 'm ^ 'n" |
33175 | 1695 |
shows "mat 1 ** A = A" |
1696 |
apply (simp add: matrix_matrix_mult_def mat_def) |
|
1697 |
apply vector |
|
1698 |
by (auto simp only: cond_value_iff cond_application_beta setsum_delta'[OF finite] mult_1_left mult_zero_left if_True UNIV_I) |
|
1699 |
||
1700 |
||
1701 |
lemma matrix_mul_rid: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1702 |
fixes A :: "'a::semiring_1 ^ 'm ^ 'n" |
33175 | 1703 |
shows "A ** mat 1 = A" |
1704 |
apply (simp add: matrix_matrix_mult_def mat_def) |
|
1705 |
apply vector |
|
1706 |
by (auto simp only: cond_value_iff cond_application_beta setsum_delta[OF finite] mult_1_right mult_zero_right if_True UNIV_I cong: if_cong) |
|
1707 |
||
1708 |
lemma matrix_mul_assoc: "A ** (B ** C) = (A ** B) ** C" |
|
1709 |
apply (vector matrix_matrix_mult_def setsum_right_distrib setsum_left_distrib mult_assoc) |
|
1710 |
apply (subst setsum_commute) |
|
1711 |
apply simp |
|
1712 |
done |
|
1713 |
||
1714 |
lemma matrix_vector_mul_assoc: "A *v (B *v x) = (A ** B) *v x" |
|
1715 |
apply (vector matrix_matrix_mult_def matrix_vector_mult_def setsum_right_distrib setsum_left_distrib mult_assoc) |
|
1716 |
apply (subst setsum_commute) |
|
1717 |
apply simp |
|
1718 |
done |
|
1719 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1720 |
lemma matrix_vector_mul_lid: "mat 1 *v x = (x::'a::semiring_1 ^ 'n)" |
33175 | 1721 |
apply (vector matrix_vector_mult_def mat_def) |
1722 |
by (simp add: cond_value_iff cond_application_beta |
|
1723 |
setsum_delta' cong del: if_weak_cong) |
|
1724 |
||
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1725 |
lemma matrix_transpose_mul: "transpose(A ** B) = transpose B ** transpose (A::'a::comm_semiring_1^_^_)" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1726 |
by (simp add: matrix_matrix_mult_def transpose_def Cart_eq mult_commute) |
33175 | 1727 |
|
1728 |
lemma matrix_eq: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1729 |
fixes A B :: "'a::semiring_1 ^ 'n ^ 'm" |
33175 | 1730 |
shows "A = B \<longleftrightarrow> (\<forall>x. A *v x = B *v x)" (is "?lhs \<longleftrightarrow> ?rhs") |
1731 |
apply auto |
|
1732 |
apply (subst Cart_eq) |
|
1733 |
apply clarify |
|
1734 |
apply (clarsimp simp add: matrix_vector_mult_def basis_def cond_value_iff cond_application_beta Cart_eq cong del: if_weak_cong) |
|
1735 |
apply (erule_tac x="basis ia" in allE) |
|
1736 |
apply (erule_tac x="i" in allE) |
|
1737 |
by (auto simp add: basis_def cond_value_iff cond_application_beta setsum_delta[OF finite] cong del: if_weak_cong) |
|
1738 |
||
1739 |
lemma matrix_vector_mul_component: |
|
35542 | 1740 |
shows "((A::real^_^_) *v x)$k = (A$k) \<bullet> x" |
1741 |
by (simp add: matrix_vector_mult_def inner_vector_def) |
|
1742 |
||
1743 |
lemma dot_lmul_matrix: "((x::real ^_) v* A) \<bullet> y = x \<bullet> (A *v y)" |
|
1744 |
apply (simp add: inner_vector_def matrix_vector_mult_def vector_matrix_mult_def setsum_left_distrib setsum_right_distrib mult_ac) |
|
33175 | 1745 |
apply (subst setsum_commute) |
1746 |
by simp |
|
1747 |
||
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1748 |
lemma transpose_mat: "transpose (mat n) = mat n" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1749 |
by (vector transpose_def mat_def) |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1750 |
|
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1751 |
lemma transpose_transpose: "transpose(transpose A) = A" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1752 |
by (vector transpose_def) |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1753 |
|
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1754 |
lemma row_transpose: |
34289 | 1755 |
fixes A:: "'a::semiring_1^_^_" |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1756 |
shows "row i (transpose A) = column i A" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1757 |
by (simp add: row_def column_def transpose_def Cart_eq) |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1758 |
|
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1759 |
lemma column_transpose: |
34289 | 1760 |
fixes A:: "'a::semiring_1^_^_" |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1761 |
shows "column i (transpose A) = row i A" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1762 |
by (simp add: row_def column_def transpose_def Cart_eq) |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1763 |
|
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1764 |
lemma rows_transpose: "rows(transpose (A::'a::semiring_1^_^_)) = columns A" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1765 |
by (auto simp add: rows_def columns_def row_transpose intro: set_ext) |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1766 |
|
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1767 |
lemma columns_transpose: "columns(transpose (A::'a::semiring_1^_^_)) = rows A" by (metis transpose_transpose rows_transpose) |
33175 | 1768 |
|
1769 |
text{* Two sometimes fruitful ways of looking at matrix-vector multiplication. *} |
|
1770 |
||
1771 |
lemma matrix_mult_dot: "A *v x = (\<chi> i. A$i \<bullet> x)" |
|
35542 | 1772 |
by (simp add: matrix_vector_mult_def inner_vector_def) |
33175 | 1773 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1774 |
lemma matrix_mult_vsum: "(A::'a::comm_semiring_1^'n^'m) *v x = setsum (\<lambda>i. (x$i) *s column i A) (UNIV:: 'n set)" |
33175 | 1775 |
by (simp add: matrix_vector_mult_def Cart_eq column_def mult_commute) |
1776 |
||
1777 |
lemma vector_componentwise: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1778 |
"(x::'a::ring_1^'n) = (\<chi> j. setsum (\<lambda>i. (x$i) * (basis i :: 'a^'n)$j) (UNIV :: 'n set))" |
33175 | 1779 |
apply (subst basis_expansion[symmetric]) |
1780 |
by (vector Cart_eq setsum_component) |
|
1781 |
||
1782 |
lemma linear_componentwise: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1783 |
fixes f:: "'a::ring_1 ^'m \<Rightarrow> 'a ^ _" |
33175 | 1784 |
assumes lf: "linear f" |
1785 |
shows "(f x)$j = setsum (\<lambda>i. (x$i) * (f (basis i)$j)) (UNIV :: 'm set)" (is "?lhs = ?rhs") |
|
1786 |
proof- |
|
1787 |
let ?M = "(UNIV :: 'm set)" |
|
1788 |
let ?N = "(UNIV :: 'n set)" |
|
1789 |
have fM: "finite ?M" by simp |
|
1790 |
have "?rhs = (setsum (\<lambda>i.(x$i) *s f (basis i) ) ?M)$j" |
|
1791 |
unfolding vector_smult_component[symmetric] |
|
1792 |
unfolding setsum_component[of "(\<lambda>i.(x$i) *s f (basis i :: 'a^'m))" ?M] |
|
1793 |
.. |
|
1794 |
then show ?thesis unfolding linear_setsum_mul[OF lf fM, symmetric] basis_expansion .. |
|
1795 |
qed |
|
1796 |
||
1797 |
text{* Inverse matrices (not necessarily square) *} |
|
1798 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1799 |
definition "invertible(A::'a::semiring_1^'n^'m) \<longleftrightarrow> (\<exists>A'::'a^'m^'n. A ** A' = mat 1 \<and> A' ** A = mat 1)" |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1800 |
|
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1801 |
definition "matrix_inv(A:: 'a::semiring_1^'n^'m) = |
33175 | 1802 |
(SOME A'::'a^'m^'n. A ** A' = mat 1 \<and> A' ** A = mat 1)" |
1803 |
||
1804 |
text{* Correspondence between matrices and linear operators. *} |
|
1805 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1806 |
definition matrix:: "('a::{plus,times, one, zero}^'m \<Rightarrow> 'a ^ 'n) \<Rightarrow> 'a^'m^'n" |
33175 | 1807 |
where "matrix f = (\<chi> i j. (f(basis j))$i)" |
1808 |
||
34289 | 1809 |
lemma matrix_vector_mul_linear: "linear(\<lambda>x. A *v (x::'a::comm_semiring_1 ^ _))" |
36350 | 1810 |
by (simp add: linear_def matrix_vector_mult_def Cart_eq field_simps setsum_right_distrib setsum_addf) |
33175 | 1811 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1812 |
lemma matrix_works: assumes lf: "linear f" shows "matrix f *v x = f (x::'a::comm_ring_1 ^ 'n)" |
33175 | 1813 |
apply (simp add: matrix_def matrix_vector_mult_def Cart_eq mult_commute) |
1814 |
apply clarify |
|
1815 |
apply (rule linear_componentwise[OF lf, symmetric]) |
|
1816 |
done |
|
1817 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1818 |
lemma matrix_vector_mul: "linear f ==> f = (\<lambda>x. matrix f *v (x::'a::comm_ring_1 ^ 'n))" by (simp add: ext matrix_works) |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1819 |
|
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1820 |
lemma matrix_of_matrix_vector_mul: "matrix(\<lambda>x. A *v (x :: 'a:: comm_ring_1 ^ 'n)) = A" |
33175 | 1821 |
by (simp add: matrix_eq matrix_vector_mul_linear matrix_works) |
1822 |
||
1823 |
lemma matrix_compose: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1824 |
assumes lf: "linear (f::'a::comm_ring_1^'n \<Rightarrow> 'a^'m)" |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1825 |
and lg: "linear (g::'a::comm_ring_1^'m \<Rightarrow> 'a^_)" |
33175 | 1826 |
shows "matrix (g o f) = matrix g ** matrix f" |
1827 |
using lf lg linear_compose[OF lf lg] matrix_works[OF linear_compose[OF lf lg]] |
|
1828 |
by (simp add: matrix_eq matrix_works matrix_vector_mul_assoc[symmetric] o_def) |
|
1829 |
||
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1830 |
lemma matrix_vector_column:"(A::'a::comm_semiring_1^'n^_) *v x = setsum (\<lambda>i. (x$i) *s ((transpose A)$i)) (UNIV:: 'n set)" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1831 |
by (simp add: matrix_vector_mult_def transpose_def Cart_eq mult_commute) |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1832 |
|
35542 | 1833 |
lemma adjoint_matrix: "adjoint(\<lambda>x. (A::real^'n^'m) *v x) = (\<lambda>x. transpose A *v x)" |
33175 | 1834 |
apply (rule adjoint_unique[symmetric]) |
1835 |
apply (rule matrix_vector_mul_linear) |
|
35542 | 1836 |
apply (simp add: transpose_def inner_vector_def matrix_vector_mult_def setsum_left_distrib setsum_right_distrib) |
33175 | 1837 |
apply (subst setsum_commute) |
1838 |
apply (auto simp add: mult_ac) |
|
1839 |
done |
|
1840 |
||
35542 | 1841 |
lemma matrix_adjoint: assumes lf: "linear (f :: real^'n \<Rightarrow> real ^'m)" |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
1842 |
shows "matrix(adjoint f) = transpose(matrix f)" |
33175 | 1843 |
apply (subst matrix_vector_mul[OF lf]) |
1844 |
unfolding adjoint_matrix matrix_of_matrix_vector_mul .. |
|
1845 |
||
1846 |
subsection{* Interlude: Some properties of real sets *} |
|
1847 |
||
1848 |
lemma seq_mono_lemma: assumes "\<forall>(n::nat) \<ge> m. (d n :: real) < e n" and "\<forall>n \<ge> m. e n <= e m" |
|
1849 |
shows "\<forall>n \<ge> m. d n < e m" |
|
1850 |
using prems apply auto |
|
1851 |
apply (erule_tac x="n" in allE) |
|
1852 |
apply (erule_tac x="n" in allE) |
|
1853 |
apply auto |
|
1854 |
done |
|
1855 |
||
1856 |
||
1857 |
lemma real_convex_bound_lt: |
|
1858 |
assumes xa: "(x::real) < a" and ya: "y < a" and u: "0 <= u" and v: "0 <= v" |
|
1859 |
and uv: "u + v = 1" |
|
1860 |
shows "u * x + v * y < a" |
|
1861 |
proof- |
|
1862 |
have uv': "u = 0 \<longrightarrow> v \<noteq> 0" using u v uv by arith |
|
1863 |
have "a = a * (u + v)" unfolding uv by simp |
|
36350 | 1864 |
hence th: "u * a + v * a = a" by (simp add: field_simps) |
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
1865 |
from xa u have "u \<noteq> 0 \<Longrightarrow> u*x < u*a" by (simp add: mult_strict_left_mono) |
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
1866 |
from ya v have "v \<noteq> 0 \<Longrightarrow> v * y < v * a" by (simp add: mult_strict_left_mono) |
33175 | 1867 |
from xa ya u v have "u * x + v * y < u * a + v * a" |
1868 |
apply (cases "u = 0", simp_all add: uv') |
|
1869 |
apply(rule mult_strict_left_mono) |
|
1870 |
using uv' apply simp_all |
|
1871 |
||
1872 |
apply (rule add_less_le_mono) |
|
1873 |
apply(rule mult_strict_left_mono) |
|
1874 |
apply simp_all |
|
1875 |
apply (rule mult_left_mono) |
|
1876 |
apply simp_all |
|
1877 |
done |
|
1878 |
thus ?thesis unfolding th . |
|
1879 |
qed |
|
1880 |
||
1881 |
lemma real_convex_bound_le: |
|
1882 |
assumes xa: "(x::real) \<le> a" and ya: "y \<le> a" and u: "0 <= u" and v: "0 <= v" |
|
1883 |
and uv: "u + v = 1" |
|
1884 |
shows "u * x + v * y \<le> a" |
|
1885 |
proof- |
|
1886 |
from xa ya u v have "u * x + v * y \<le> u * a + v * a" by (simp add: add_mono mult_left_mono) |
|
36350 | 1887 |
also have "\<dots> \<le> (u + v) * a" by (simp add: field_simps) |
33175 | 1888 |
finally show ?thesis unfolding uv by simp |
1889 |
qed |
|
1890 |
||
1891 |
lemma infinite_enumerate: assumes fS: "infinite S" |
|
1892 |
shows "\<exists>r. subseq r \<and> (\<forall>n. r n \<in> S)" |
|
1893 |
unfolding subseq_def |
|
1894 |
using enumerate_in_set[OF fS] enumerate_mono[of _ _ S] fS by auto |
|
1895 |
||
1896 |
lemma approachable_lt_le: "(\<exists>(d::real)>0. \<forall>x. f x < d \<longrightarrow> P x) \<longleftrightarrow> (\<exists>d>0. \<forall>x. f x \<le> d \<longrightarrow> P x)" |
|
1897 |
apply auto |
|
1898 |
apply (rule_tac x="d/2" in exI) |
|
1899 |
apply auto |
|
1900 |
done |
|
1901 |
||
1902 |
||
1903 |
lemma triangle_lemma: |
|
1904 |
assumes x: "0 <= (x::real)" and y:"0 <= y" and z: "0 <= z" and xy: "x^2 <= y^2 + z^2" |
|
1905 |
shows "x <= y + z" |
|
1906 |
proof- |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
1907 |
have "y^2 + z^2 \<le> y^2 + 2*y*z + z^2" using z y by (simp add: mult_nonneg_nonneg) |
36350 | 1908 |
with xy have th: "x ^2 \<le> (y+z)^2" by (simp add: power2_eq_square field_simps) |
33175 | 1909 |
from y z have yz: "y + z \<ge> 0" by arith |
1910 |
from power2_le_imp_le[OF th yz] show ?thesis . |
|
1911 |
qed |
|
1912 |
||
1913 |
||
1914 |
lemma lambda_skolem: "(\<forall>i. \<exists>x. P i x) \<longleftrightarrow> |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1915 |
(\<exists>x::'a ^ 'n. \<forall>i. P i (x$i))" (is "?lhs \<longleftrightarrow> ?rhs") |
33175 | 1916 |
proof- |
1917 |
let ?S = "(UNIV :: 'n set)" |
|
1918 |
{assume H: "?rhs" |
|
1919 |
then have ?lhs by auto} |
|
1920 |
moreover |
|
1921 |
{assume H: "?lhs" |
|
1922 |
then obtain f where f:"\<forall>i. P i (f i)" unfolding choice_iff by metis |
|
1923 |
let ?x = "(\<chi> i. (f i)) :: 'a ^ 'n" |
|
1924 |
{fix i |
|
1925 |
from f have "P i (f i)" by metis |
|
1926 |
then have "P i (?x$i)" by auto |
|
1927 |
} |
|
1928 |
hence "\<forall>i. P i (?x$i)" by metis |
|
1929 |
hence ?rhs by metis } |
|
1930 |
ultimately show ?thesis by metis |
|
1931 |
qed |
|
1932 |
||
34964 | 1933 |
lemma vec_in_image_vec: "vec x \<in> (vec ` S) \<longleftrightarrow> x \<in> S" by auto |
1934 |
||
1935 |
lemma vec_add: "vec(x + y) = vec x + vec y" by (vector vec_def) |
|
1936 |
lemma vec_sub: "vec(x - y) = vec x - vec y" by (vector vec_def) |
|
1937 |
lemma vec_cmul: "vec(c* x) = c *s vec x " by (vector vec_def) |
|
1938 |
lemma vec_neg: "vec(- x) = - vec x " by (vector vec_def) |
|
33714
eb2574ac4173
Added new lemmas to Euclidean Space by Robert Himmelmann
hoelzl
parents:
33270
diff
changeset
|
1939 |
|
34964 | 1940 |
lemma vec_setsum: assumes fS: "finite S" |
1941 |
shows "vec(setsum f S) = setsum (vec o f) S" |
|
33175 | 1942 |
apply (induct rule: finite_induct[OF fS]) |
34964 | 1943 |
apply (simp) |
1944 |
apply (auto simp add: vec_add) |
|
33175 | 1945 |
done |
1946 |
||
1947 |
text{* Pasting vectors. *} |
|
1948 |
||
34964 | 1949 |
lemma linear_fstcart[intro]: "linear fstcart" |
33175 | 1950 |
by (auto simp add: linear_def Cart_eq) |
1951 |
||
34964 | 1952 |
lemma linear_sndcart[intro]: "linear sndcart" |
33175 | 1953 |
by (auto simp add: linear_def Cart_eq) |
1954 |
||
1955 |
lemma fstcart_vec[simp]: "fstcart(vec x) = vec x" |
|
1956 |
by (simp add: Cart_eq) |
|
1957 |
||
34289 | 1958 |
lemma fstcart_add[simp]:"fstcart(x + y) = fstcart (x::'a::{plus,times}^('b::finite + 'c::finite)) + fstcart y" |
33175 | 1959 |
by (simp add: Cart_eq) |
1960 |
||
34289 | 1961 |
lemma fstcart_cmul[simp]:"fstcart(c*s x) = c*s fstcart (x::'a::{plus,times}^('b::finite + 'c::finite))" |
33175 | 1962 |
by (simp add: Cart_eq) |
1963 |
||
34289 | 1964 |
lemma fstcart_neg[simp]:"fstcart(- x) = - fstcart (x::'a::ring_1^(_ + _))" |
33175 | 1965 |
by (simp add: Cart_eq) |
1966 |
||
34289 | 1967 |
lemma fstcart_sub[simp]:"fstcart(x - y) = fstcart (x::'a::ring_1^(_ + _)) - fstcart y" |
33175 | 1968 |
by (simp add: Cart_eq) |
1969 |
||
1970 |
lemma fstcart_setsum: |
|
1971 |
fixes f:: "'d \<Rightarrow> 'a::semiring_1^_" |
|
1972 |
assumes fS: "finite S" |
|
1973 |
shows "fstcart (setsum f S) = setsum (\<lambda>i. fstcart (f i)) S" |
|
1974 |
by (induct rule: finite_induct[OF fS], simp_all add: vec_0[symmetric] del: vec_0) |
|
1975 |
||
1976 |
lemma sndcart_vec[simp]: "sndcart(vec x) = vec x" |
|
1977 |
by (simp add: Cart_eq) |
|
1978 |
||
34289 | 1979 |
lemma sndcart_add[simp]:"sndcart(x + y) = sndcart (x::'a::{plus,times}^(_ + _)) + sndcart y" |
33175 | 1980 |
by (simp add: Cart_eq) |
1981 |
||
34289 | 1982 |
lemma sndcart_cmul[simp]:"sndcart(c*s x) = c*s sndcart (x::'a::{plus,times}^(_ + _))" |
33175 | 1983 |
by (simp add: Cart_eq) |
1984 |
||
34289 | 1985 |
lemma sndcart_neg[simp]:"sndcart(- x) = - sndcart (x::'a::ring_1^(_ + _))" |
33175 | 1986 |
by (simp add: Cart_eq) |
1987 |
||
34289 | 1988 |
lemma sndcart_sub[simp]:"sndcart(x - y) = sndcart (x::'a::ring_1^(_ + _)) - sndcart y" |
33175 | 1989 |
by (simp add: Cart_eq) |
1990 |
||
1991 |
lemma sndcart_setsum: |
|
1992 |
fixes f:: "'d \<Rightarrow> 'a::semiring_1^_" |
|
1993 |
assumes fS: "finite S" |
|
1994 |
shows "sndcart (setsum f S) = setsum (\<lambda>i. sndcart (f i)) S" |
|
1995 |
by (induct rule: finite_induct[OF fS], simp_all add: vec_0[symmetric] del: vec_0) |
|
1996 |
||
1997 |
lemma pastecart_vec[simp]: "pastecart (vec x) (vec x) = vec x" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
1998 |
by (simp add: pastecart_eq) |
33175 | 1999 |
|
2000 |
lemma pastecart_add[simp]:"pastecart (x1::'a::{plus,times}^_) y1 + pastecart x2 y2 = pastecart (x1 + x2) (y1 + y2)" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
2001 |
by (simp add: pastecart_eq) |
33175 | 2002 |
|
2003 |
lemma pastecart_cmul[simp]: "pastecart (c *s (x1::'a::{plus,times}^_)) (c *s y1) = c *s pastecart x1 y1" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
2004 |
by (simp add: pastecart_eq) |
33175 | 2005 |
|
2006 |
lemma pastecart_neg[simp]: "pastecart (- (x::'a::ring_1^_)) (- y) = - pastecart x y" |
|
2007 |
unfolding vector_sneg_minus1 pastecart_cmul .. |
|
2008 |
||
2009 |
lemma pastecart_sub: "pastecart (x1::'a::ring_1^_) y1 - pastecart x2 y2 = pastecart (x1 - x2) (y1 - y2)" |
|
2010 |
by (simp add: diff_def pastecart_neg[symmetric] del: pastecart_neg) |
|
2011 |
||
2012 |
lemma pastecart_setsum: |
|
2013 |
fixes f:: "'d \<Rightarrow> 'a::semiring_1^_" |
|
2014 |
assumes fS: "finite S" |
|
2015 |
shows "pastecart (setsum f S) (setsum g S) = setsum (\<lambda>i. pastecart (f i) (g i)) S" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
2016 |
by (simp add: pastecart_eq fstcart_setsum[OF fS] sndcart_setsum[OF fS]) |
33175 | 2017 |
|
2018 |
lemma setsum_Plus: |
|
2019 |
"\<lbrakk>finite A; finite B\<rbrakk> \<Longrightarrow> |
|
2020 |
(\<Sum>x\<in>A <+> B. g x) = (\<Sum>x\<in>A. g (Inl x)) + (\<Sum>x\<in>B. g (Inr x))" |
|
2021 |
unfolding Plus_def |
|
2022 |
by (subst setsum_Un_disjoint, auto simp add: setsum_reindex) |
|
2023 |
||
2024 |
lemma setsum_UNIV_sum: |
|
2025 |
fixes g :: "'a::finite + 'b::finite \<Rightarrow> _" |
|
2026 |
shows "(\<Sum>x\<in>UNIV. g x) = (\<Sum>x\<in>UNIV. g (Inl x)) + (\<Sum>x\<in>UNIV. g (Inr x))" |
|
2027 |
apply (subst UNIV_Plus_UNIV [symmetric]) |
|
2028 |
apply (rule setsum_Plus [OF finite finite]) |
|
2029 |
done |
|
2030 |
||
2031 |
lemma norm_fstcart: "norm(fstcart x) <= norm (x::real ^('n::finite + 'm::finite))" |
|
2032 |
proof- |
|
2033 |
have th0: "norm x = norm (pastecart (fstcart x) (sndcart x))" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
2034 |
by simp |
33175 | 2035 |
have th1: "fstcart x \<bullet> fstcart x \<le> pastecart (fstcart x) (sndcart x) \<bullet> pastecart (fstcart x) (sndcart x)" |
35542 | 2036 |
by (simp add: inner_vector_def setsum_UNIV_sum pastecart_def setsum_nonneg) |
33175 | 2037 |
then show ?thesis |
2038 |
unfolding th0 |
|
35542 | 2039 |
unfolding norm_eq_sqrt_inner real_sqrt_le_iff id_def |
2040 |
by (simp add: inner_vector_def) |
|
33175 | 2041 |
qed |
2042 |
||
2043 |
lemma dist_fstcart: "dist(fstcart (x::real^_)) (fstcart y) <= dist x y" |
|
2044 |
unfolding dist_norm by (metis fstcart_sub[symmetric] norm_fstcart) |
|
2045 |
||
2046 |
lemma norm_sndcart: "norm(sndcart x) <= norm (x::real ^('n::finite + 'm::finite))" |
|
2047 |
proof- |
|
2048 |
have th0: "norm x = norm (pastecart (fstcart x) (sndcart x))" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
2049 |
by simp |
33175 | 2050 |
have th1: "sndcart x \<bullet> sndcart x \<le> pastecart (fstcart x) (sndcart x) \<bullet> pastecart (fstcart x) (sndcart x)" |
35542 | 2051 |
by (simp add: inner_vector_def setsum_UNIV_sum pastecart_def setsum_nonneg) |
33175 | 2052 |
then show ?thesis |
2053 |
unfolding th0 |
|
35542 | 2054 |
unfolding norm_eq_sqrt_inner real_sqrt_le_iff id_def |
2055 |
by (simp add: inner_vector_def) |
|
33175 | 2056 |
qed |
2057 |
||
2058 |
lemma dist_sndcart: "dist(sndcart (x::real^_)) (sndcart y) <= dist x y" |
|
2059 |
unfolding dist_norm by (metis sndcart_sub[symmetric] norm_sndcart) |
|
2060 |
||
35542 | 2061 |
lemma dot_pastecart: "(pastecart (x1::real^'n) (x2::real^'m)) \<bullet> (pastecart y1 y2) = x1 \<bullet> y1 + x2 \<bullet> y2" |
2062 |
by (simp add: inner_vector_def setsum_UNIV_sum pastecart_def) |
|
33175 | 2063 |
|
2064 |
text {* TODO: move to NthRoot *} |
|
2065 |
lemma sqrt_add_le_add_sqrt: |
|
2066 |
assumes x: "0 \<le> x" and y: "0 \<le> y" |
|
2067 |
shows "sqrt (x + y) \<le> sqrt x + sqrt y" |
|
2068 |
apply (rule power2_le_imp_le) |
|
2069 |
apply (simp add: real_sum_squared_expand add_nonneg_nonneg x y) |
|
2070 |
apply (simp add: mult_nonneg_nonneg x y) |
|
2071 |
apply (simp add: add_nonneg_nonneg x y) |
|
2072 |
done |
|
2073 |
||
2074 |
lemma norm_pastecart: "norm (pastecart x y) <= norm x + norm y" |
|
2075 |
unfolding norm_vector_def setL2_def setsum_UNIV_sum |
|
2076 |
by (simp add: sqrt_add_le_add_sqrt setsum_nonneg) |
|
2077 |
||
2078 |
subsection {* A generic notion of "hull" (convex, affine, conic hull and closure). *} |
|
2079 |
||
2080 |
definition hull :: "'a set set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "hull" 75) where |
|
2081 |
"S hull s = Inter {t. t \<in> S \<and> s \<subseteq> t}" |
|
2082 |
||
2083 |
lemma hull_same: "s \<in> S \<Longrightarrow> S hull s = s" |
|
2084 |
unfolding hull_def by auto |
|
2085 |
||
2086 |
lemma hull_in: "(\<And>T. T \<subseteq> S ==> Inter T \<in> S) ==> (S hull s) \<in> S" |
|
2087 |
unfolding hull_def subset_iff by auto |
|
2088 |
||
2089 |
lemma hull_eq: "(\<And>T. T \<subseteq> S ==> Inter T \<in> S) ==> (S hull s) = s \<longleftrightarrow> s \<in> S" |
|
2090 |
using hull_same[of s S] hull_in[of S s] by metis |
|
2091 |
||
2092 |
||
2093 |
lemma hull_hull: "S hull (S hull s) = S hull s" |
|
2094 |
unfolding hull_def by blast |
|
2095 |
||
34964 | 2096 |
lemma hull_subset[intro]: "s \<subseteq> (S hull s)" |
33175 | 2097 |
unfolding hull_def by blast |
2098 |
||
2099 |
lemma hull_mono: " s \<subseteq> t ==> (S hull s) \<subseteq> (S hull t)" |
|
2100 |
unfolding hull_def by blast |
|
2101 |
||
2102 |
lemma hull_antimono: "S \<subseteq> T ==> (T hull s) \<subseteq> (S hull s)" |
|
2103 |
unfolding hull_def by blast |
|
2104 |
||
2105 |
lemma hull_minimal: "s \<subseteq> t \<Longrightarrow> t \<in> S ==> (S hull s) \<subseteq> t" |
|
2106 |
unfolding hull_def by blast |
|
2107 |
||
2108 |
lemma subset_hull: "t \<in> S ==> S hull s \<subseteq> t \<longleftrightarrow> s \<subseteq> t" |
|
2109 |
unfolding hull_def by blast |
|
2110 |
||
2111 |
lemma hull_unique: "s \<subseteq> t \<Longrightarrow> t \<in> S \<Longrightarrow> (\<And>t'. s \<subseteq> t' \<Longrightarrow> t' \<in> S ==> t \<subseteq> t') |
|
2112 |
==> (S hull s = t)" |
|
2113 |
unfolding hull_def by auto |
|
2114 |
||
2115 |
lemma hull_induct: "(\<And>x. x\<in> S \<Longrightarrow> P x) \<Longrightarrow> Q {x. P x} \<Longrightarrow> \<forall>x\<in> Q hull S. P x" |
|
2116 |
using hull_minimal[of S "{x. P x}" Q] |
|
2117 |
by (auto simp add: subset_eq Collect_def mem_def) |
|
2118 |
||
2119 |
lemma hull_inc: "x \<in> S \<Longrightarrow> x \<in> P hull S" by (metis hull_subset subset_eq) |
|
2120 |
||
2121 |
lemma hull_union_subset: "(S hull s) \<union> (S hull t) \<subseteq> (S hull (s \<union> t))" |
|
2122 |
unfolding Un_subset_iff by (metis hull_mono Un_upper1 Un_upper2) |
|
2123 |
||
2124 |
lemma hull_union: assumes T: "\<And>T. T \<subseteq> S ==> Inter T \<in> S" |
|
2125 |
shows "S hull (s \<union> t) = S hull (S hull s \<union> S hull t)" |
|
2126 |
apply rule |
|
2127 |
apply (rule hull_mono) |
|
2128 |
unfolding Un_subset_iff |
|
2129 |
apply (metis hull_subset Un_upper1 Un_upper2 subset_trans) |
|
2130 |
apply (rule hull_minimal) |
|
2131 |
apply (metis hull_union_subset) |
|
2132 |
apply (metis hull_in T) |
|
2133 |
done |
|
2134 |
||
2135 |
lemma hull_redundant_eq: "a \<in> (S hull s) \<longleftrightarrow> (S hull (insert a s) = S hull s)" |
|
2136 |
unfolding hull_def by blast |
|
2137 |
||
2138 |
lemma hull_redundant: "a \<in> (S hull s) ==> (S hull (insert a s) = S hull s)" |
|
2139 |
by (metis hull_redundant_eq) |
|
2140 |
||
2141 |
text{* Archimedian properties and useful consequences. *} |
|
2142 |
||
2143 |
lemma real_arch_simple: "\<exists>n. x <= real (n::nat)" |
|
2144 |
using reals_Archimedean2[of x] apply auto by (rule_tac x="Suc n" in exI, auto) |
|
2145 |
lemmas real_arch_lt = reals_Archimedean2 |
|
2146 |
||
2147 |
lemmas real_arch = reals_Archimedean3 |
|
2148 |
||
2149 |
lemma real_arch_inv: "0 < e \<longleftrightarrow> (\<exists>n::nat. n \<noteq> 0 \<and> 0 < inverse (real n) \<and> inverse (real n) < e)" |
|
2150 |
using reals_Archimedean |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
2151 |
apply (auto simp add: field_simps) |
33175 | 2152 |
apply (subgoal_tac "inverse (real n) > 0") |
2153 |
apply arith |
|
2154 |
apply simp |
|
2155 |
done |
|
2156 |
||
2157 |
lemma real_pow_lbound: "0 <= x ==> 1 + real n * x <= (1 + x) ^ n" |
|
2158 |
proof(induct n) |
|
2159 |
case 0 thus ?case by simp |
|
2160 |
next |
|
2161 |
case (Suc n) |
|
2162 |
hence h: "1 + real n * x \<le> (1 + x) ^ n" by simp |
|
2163 |
from h have p: "1 \<le> (1 + x) ^ n" using Suc.prems by simp |
|
2164 |
from h have "1 + real n * x + x \<le> (1 + x) ^ n + x" by simp |
|
2165 |
also have "\<dots> \<le> (1 + x) ^ Suc n" apply (subst diff_le_0_iff_le[symmetric]) |
|
36350 | 2166 |
apply (simp add: field_simps) |
33175 | 2167 |
using mult_left_mono[OF p Suc.prems] by simp |
36350 | 2168 |
finally show ?case by (simp add: real_of_nat_Suc field_simps) |
33175 | 2169 |
qed |
2170 |
||
2171 |
lemma real_arch_pow: assumes x: "1 < (x::real)" shows "\<exists>n. y < x^n" |
|
2172 |
proof- |
|
2173 |
from x have x0: "x - 1 > 0" by arith |
|
2174 |
from real_arch[OF x0, rule_format, of y] |
|
2175 |
obtain n::nat where n:"y < real n * (x - 1)" by metis |
|
2176 |
from x0 have x00: "x- 1 \<ge> 0" by arith |
|
2177 |
from real_pow_lbound[OF x00, of n] n |
|
2178 |
have "y < x^n" by auto |
|
2179 |
then show ?thesis by metis |
|
2180 |
qed |
|
2181 |
||
2182 |
lemma real_arch_pow2: "\<exists>n. (x::real) < 2^ n" |
|
2183 |
using real_arch_pow[of 2 x] by simp |
|
2184 |
||
2185 |
lemma real_arch_pow_inv: assumes y: "(y::real) > 0" and x1: "x < 1" |
|
2186 |
shows "\<exists>n. x^n < y" |
|
2187 |
proof- |
|
2188 |
{assume x0: "x > 0" |
|
2189 |
from x0 x1 have ix: "1 < 1/x" by (simp add: field_simps) |
|
2190 |
from real_arch_pow[OF ix, of "1/y"] |
|
2191 |
obtain n where n: "1/y < (1/x)^n" by blast |
|
2192 |
then |
|
2193 |
have ?thesis using y x0 by (auto simp add: field_simps power_divide) } |
|
2194 |
moreover |
|
2195 |
{assume "\<not> x > 0" with y x1 have ?thesis apply auto by (rule exI[where x=1], auto)} |
|
2196 |
ultimately show ?thesis by metis |
|
2197 |
qed |
|
2198 |
||
2199 |
lemma forall_pos_mono: "(\<And>d e::real. d < e \<Longrightarrow> P d ==> P e) \<Longrightarrow> (\<And>n::nat. n \<noteq> 0 ==> P(inverse(real n))) \<Longrightarrow> (\<And>e. 0 < e ==> P e)" |
|
2200 |
by (metis real_arch_inv) |
|
2201 |
||
2202 |
lemma forall_pos_mono_1: "(\<And>d e::real. d < e \<Longrightarrow> P d ==> P e) \<Longrightarrow> (\<And>n. P(inverse(real (Suc n)))) ==> 0 < e ==> P e" |
|
2203 |
apply (rule forall_pos_mono) |
|
2204 |
apply auto |
|
2205 |
apply (atomize) |
|
2206 |
apply (erule_tac x="n - 1" in allE) |
|
2207 |
apply auto |
|
2208 |
done |
|
2209 |
||
2210 |
lemma real_archimedian_rdiv_eq_0: assumes x0: "x \<ge> 0" and c: "c \<ge> 0" and xc: "\<forall>(m::nat)>0. real m * x \<le> c" |
|
2211 |
shows "x = 0" |
|
2212 |
proof- |
|
2213 |
{assume "x \<noteq> 0" with x0 have xp: "x > 0" by arith |
|
2214 |
from real_arch[OF xp, rule_format, of c] obtain n::nat where n: "c < real n * x" by blast |
|
2215 |
with xc[rule_format, of n] have "n = 0" by arith |
|
2216 |
with n c have False by simp} |
|
2217 |
then show ?thesis by blast |
|
2218 |
qed |
|
2219 |
||
2220 |
(* ------------------------------------------------------------------------- *) |
|
2221 |
(* Geometric progression. *) |
|
2222 |
(* ------------------------------------------------------------------------- *) |
|
2223 |
||
2224 |
lemma sum_gp_basic: "((1::'a::{field}) - x) * setsum (\<lambda>i. x^i) {0 .. n} = (1 - x^(Suc n))" |
|
2225 |
(is "?lhs = ?rhs") |
|
2226 |
proof- |
|
2227 |
{assume x1: "x = 1" hence ?thesis by simp} |
|
2228 |
moreover |
|
2229 |
{assume x1: "x\<noteq>1" |
|
2230 |
hence x1': "x - 1 \<noteq> 0" "1 - x \<noteq> 0" "x - 1 = - (1 - x)" "- (1 - x) \<noteq> 0" by auto |
|
2231 |
from geometric_sum[OF x1, of "Suc n", unfolded x1'] |
|
2232 |
have "(- (1 - x)) * setsum (\<lambda>i. x^i) {0 .. n} = - (1 - x^(Suc n))" |
|
2233 |
unfolding atLeastLessThanSuc_atLeastAtMost |
|
36350 | 2234 |
using x1' apply (auto simp only: field_simps) |
2235 |
apply (simp add: field_simps) |
|
33175 | 2236 |
done |
36350 | 2237 |
then have ?thesis by (simp add: field_simps) } |
33175 | 2238 |
ultimately show ?thesis by metis |
2239 |
qed |
|
2240 |
||
2241 |
lemma sum_gp_multiplied: assumes mn: "m <= n" |
|
2242 |
shows "((1::'a::{field}) - x) * setsum (op ^ x) {m..n} = x^m - x^ Suc n" |
|
2243 |
(is "?lhs = ?rhs") |
|
2244 |
proof- |
|
2245 |
let ?S = "{0..(n - m)}" |
|
2246 |
from mn have mn': "n - m \<ge> 0" by arith |
|
2247 |
let ?f = "op + m" |
|
2248 |
have i: "inj_on ?f ?S" unfolding inj_on_def by auto |
|
2249 |
have f: "?f ` ?S = {m..n}" |
|
2250 |
using mn apply (auto simp add: image_iff Bex_def) by arith |
|
2251 |
have th: "op ^ x o op + m = (\<lambda>i. x^m * x^i)" |
|
2252 |
by (rule ext, simp add: power_add power_mult) |
|
2253 |
from setsum_reindex[OF i, of "op ^ x", unfolded f th setsum_right_distrib[symmetric]] |
|
2254 |
have "?lhs = x^m * ((1 - x) * setsum (op ^ x) {0..n - m})" by simp |
|
2255 |
then show ?thesis unfolding sum_gp_basic using mn |
|
36350 | 2256 |
by (simp add: field_simps power_add[symmetric]) |
33175 | 2257 |
qed |
2258 |
||
2259 |
lemma sum_gp: "setsum (op ^ (x::'a::{field})) {m .. n} = |
|
2260 |
(if n < m then 0 else if x = 1 then of_nat ((n + 1) - m) |
|
2261 |
else (x^ m - x^ (Suc n)) / (1 - x))" |
|
2262 |
proof- |
|
2263 |
{assume nm: "n < m" hence ?thesis by simp} |
|
2264 |
moreover |
|
2265 |
{assume "\<not> n < m" hence nm: "m \<le> n" by arith |
|
2266 |
{assume x: "x = 1" hence ?thesis by simp} |
|
2267 |
moreover |
|
2268 |
{assume x: "x \<noteq> 1" hence nz: "1 - x \<noteq> 0" by simp |
|
36350 | 2269 |
from sum_gp_multiplied[OF nm, of x] nz have ?thesis by (simp add: field_simps)} |
33175 | 2270 |
ultimately have ?thesis by metis |
2271 |
} |
|
2272 |
ultimately show ?thesis by metis |
|
2273 |
qed |
|
2274 |
||
2275 |
lemma sum_gp_offset: "setsum (op ^ (x::'a::{field})) {m .. m+n} = |
|
2276 |
(if x = 1 then of_nat n + 1 else x^m * (1 - x^Suc n) / (1 - x))" |
|
2277 |
unfolding sum_gp[of x m "m + n"] power_Suc |
|
36350 | 2278 |
by (simp add: field_simps power_add) |
33175 | 2279 |
|
2280 |
||
2281 |
subsection{* A bit of linear algebra. *} |
|
2282 |
||
2283 |
definition "subspace S \<longleftrightarrow> 0 \<in> S \<and> (\<forall>x\<in> S. \<forall>y \<in>S. x + y \<in> S) \<and> (\<forall>c. \<forall>x \<in>S. c *s x \<in>S )" |
|
2284 |
definition "span S = (subspace hull S)" |
|
2285 |
definition "dependent S \<longleftrightarrow> (\<exists>a \<in> S. a \<in> span(S - {a}))" |
|
2286 |
abbreviation "independent s == ~(dependent s)" |
|
2287 |
||
2288 |
(* Closure properties of subspaces. *) |
|
2289 |
||
2290 |
lemma subspace_UNIV[simp]: "subspace(UNIV)" by (simp add: subspace_def) |
|
2291 |
||
2292 |
lemma subspace_0: "subspace S ==> 0 \<in> S" by (metis subspace_def) |
|
2293 |
||
2294 |
lemma subspace_add: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S ==> x + y \<in> S" |
|
2295 |
by (metis subspace_def) |
|
2296 |
||
2297 |
lemma subspace_mul: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> c *s x \<in> S" |
|
2298 |
by (metis subspace_def) |
|
2299 |
||
34289 | 2300 |
lemma subspace_neg: "subspace S \<Longrightarrow> (x::'a::ring_1^_) \<in> S \<Longrightarrow> - x \<in> S" |
33175 | 2301 |
by (metis vector_sneg_minus1 subspace_mul) |
2302 |
||
34289 | 2303 |
lemma subspace_sub: "subspace S \<Longrightarrow> (x::'a::ring_1^_) \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x - y \<in> S" |
33175 | 2304 |
by (metis diff_def subspace_add subspace_neg) |
2305 |
||
2306 |
lemma subspace_setsum: |
|
2307 |
assumes sA: "subspace A" and fB: "finite B" |
|
2308 |
and f: "\<forall>x\<in> B. f x \<in> A" |
|
2309 |
shows "setsum f B \<in> A" |
|
2310 |
using fB f sA |
|
2311 |
apply(induct rule: finite_induct[OF fB]) |
|
2312 |
by (simp add: subspace_def sA, auto simp add: sA subspace_add) |
|
2313 |
||
2314 |
lemma subspace_linear_image: |
|
34289 | 2315 |
assumes lf: "linear (f::'a::semiring_1^_ \<Rightarrow> _)" and sS: "subspace S" |
33175 | 2316 |
shows "subspace(f ` S)" |
2317 |
using lf sS linear_0[OF lf] |
|
2318 |
unfolding linear_def subspace_def |
|
2319 |
apply (auto simp add: image_iff) |
|
2320 |
apply (rule_tac x="x + y" in bexI, auto) |
|
2321 |
apply (rule_tac x="c*s x" in bexI, auto) |
|
2322 |
done |
|
2323 |
||
34289 | 2324 |
lemma subspace_linear_preimage: "linear (f::'a::semiring_1^_ \<Rightarrow> _) ==> subspace S ==> subspace {x. f x \<in> S}" |
33175 | 2325 |
by (auto simp add: subspace_def linear_def linear_0[of f]) |
2326 |
||
2327 |
lemma subspace_trivial: "subspace {0::'a::semiring_1 ^_}" |
|
2328 |
by (simp add: subspace_def) |
|
2329 |
||
2330 |
lemma subspace_inter: "subspace A \<Longrightarrow> subspace B ==> subspace (A \<inter> B)" |
|
2331 |
by (simp add: subspace_def) |
|
2332 |
||
2333 |
||
2334 |
lemma span_mono: "A \<subseteq> B ==> span A \<subseteq> span B" |
|
2335 |
by (metis span_def hull_mono) |
|
2336 |
||
2337 |
lemma subspace_span: "subspace(span S)" |
|
2338 |
unfolding span_def |
|
2339 |
apply (rule hull_in[unfolded mem_def]) |
|
2340 |
apply (simp only: subspace_def Inter_iff Int_iff subset_eq) |
|
2341 |
apply auto |
|
2342 |
apply (erule_tac x="X" in ballE) |
|
2343 |
apply (simp add: mem_def) |
|
2344 |
apply blast |
|
2345 |
apply (erule_tac x="X" in ballE) |
|
2346 |
apply (erule_tac x="X" in ballE) |
|
2347 |
apply (erule_tac x="X" in ballE) |
|
2348 |
apply (clarsimp simp add: mem_def) |
|
2349 |
apply simp |
|
2350 |
apply simp |
|
2351 |
apply simp |
|
2352 |
apply (erule_tac x="X" in ballE) |
|
2353 |
apply (erule_tac x="X" in ballE) |
|
2354 |
apply (simp add: mem_def) |
|
2355 |
apply simp |
|
2356 |
apply simp |
|
2357 |
done |
|
2358 |
||
2359 |
lemma span_clauses: |
|
2360 |
"a \<in> S ==> a \<in> span S" |
|
2361 |
"0 \<in> span S" |
|
2362 |
"x\<in> span S \<Longrightarrow> y \<in> span S ==> x + y \<in> span S" |
|
2363 |
"x \<in> span S \<Longrightarrow> c *s x \<in> span S" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
2364 |
by (metis span_def hull_subset subset_eq) |
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
2365 |
(metis subspace_span subspace_def)+ |
33175 | 2366 |
|
2367 |
lemma span_induct: assumes SP: "\<And>x. x \<in> S ==> P x" |
|
2368 |
and P: "subspace P" and x: "x \<in> span S" shows "P x" |
|
2369 |
proof- |
|
2370 |
from SP have SP': "S \<subseteq> P" by (simp add: mem_def subset_eq) |
|
2371 |
from P have P': "P \<in> subspace" by (simp add: mem_def) |
|
2372 |
from x hull_minimal[OF SP' P', unfolded span_def[symmetric]] |
|
2373 |
show "P x" by (metis mem_def subset_eq) |
|
2374 |
qed |
|
2375 |
||
34289 | 2376 |
lemma span_empty: "span {} = {(0::'a::semiring_0 ^ _)}" |
33175 | 2377 |
apply (simp add: span_def) |
2378 |
apply (rule hull_unique) |
|
2379 |
apply (auto simp add: mem_def subspace_def) |
|
34289 | 2380 |
unfolding mem_def[of "0::'a^_", symmetric] |
33175 | 2381 |
apply simp |
2382 |
done |
|
2383 |
||
2384 |
lemma independent_empty: "independent {}" |
|
2385 |
by (simp add: dependent_def) |
|
2386 |
||
2387 |
lemma independent_mono: "independent A \<Longrightarrow> B \<subseteq> A ==> independent B" |
|
2388 |
apply (clarsimp simp add: dependent_def span_mono) |
|
2389 |
apply (subgoal_tac "span (B - {a}) \<le> span (A - {a})") |
|
2390 |
apply force |
|
2391 |
apply (rule span_mono) |
|
2392 |
apply auto |
|
2393 |
done |
|
2394 |
||
2395 |
lemma span_subspace: "A \<subseteq> B \<Longrightarrow> B \<le> span A \<Longrightarrow> subspace B \<Longrightarrow> span A = B" |
|
2396 |
by (metis order_antisym span_def hull_minimal mem_def) |
|
2397 |
||
2398 |
lemma span_induct': assumes SP: "\<forall>x \<in> S. P x" |
|
2399 |
and P: "subspace P" shows "\<forall>x \<in> span S. P x" |
|
2400 |
using span_induct SP P by blast |
|
2401 |
||
34289 | 2402 |
inductive span_induct_alt_help for S:: "'a::semiring_1^_ \<Rightarrow> bool" |
33175 | 2403 |
where |
2404 |
span_induct_alt_help_0: "span_induct_alt_help S 0" |
|
2405 |
| span_induct_alt_help_S: "x \<in> S \<Longrightarrow> span_induct_alt_help S z \<Longrightarrow> span_induct_alt_help S (c *s x + z)" |
|
2406 |
||
2407 |
lemma span_induct_alt': |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
2408 |
assumes h0: "h (0::'a::semiring_1^'n)" and hS: "\<And>c x y. x \<in> S \<Longrightarrow> h y \<Longrightarrow> h (c*s x + y)" shows "\<forall>x \<in> span S. h x" |
33175 | 2409 |
proof- |
2410 |
{fix x:: "'a^'n" assume x: "span_induct_alt_help S x" |
|
2411 |
have "h x" |
|
2412 |
apply (rule span_induct_alt_help.induct[OF x]) |
|
2413 |
apply (rule h0) |
|
2414 |
apply (rule hS, assumption, assumption) |
|
2415 |
done} |
|
2416 |
note th0 = this |
|
2417 |
{fix x assume x: "x \<in> span S" |
|
2418 |
||
2419 |
have "span_induct_alt_help S x" |
|
2420 |
proof(rule span_induct[where x=x and S=S]) |
|
2421 |
show "x \<in> span S" using x . |
|
2422 |
next |
|
2423 |
fix x assume xS : "x \<in> S" |
|
2424 |
from span_induct_alt_help_S[OF xS span_induct_alt_help_0, of 1] |
|
2425 |
show "span_induct_alt_help S x" by simp |
|
2426 |
next |
|
2427 |
have "span_induct_alt_help S 0" by (rule span_induct_alt_help_0) |
|
2428 |
moreover |
|
2429 |
{fix x y assume h: "span_induct_alt_help S x" "span_induct_alt_help S y" |
|
2430 |
from h |
|
2431 |
have "span_induct_alt_help S (x + y)" |
|
2432 |
apply (induct rule: span_induct_alt_help.induct) |
|
2433 |
apply simp |
|
2434 |
unfolding add_assoc |
|
2435 |
apply (rule span_induct_alt_help_S) |
|
2436 |
apply assumption |
|
2437 |
apply simp |
|
2438 |
done} |
|
2439 |
moreover |
|
2440 |
{fix c x assume xt: "span_induct_alt_help S x" |
|
2441 |
then have "span_induct_alt_help S (c*s x)" |
|
2442 |
apply (induct rule: span_induct_alt_help.induct) |
|
2443 |
apply (simp add: span_induct_alt_help_0) |
|
2444 |
apply (simp add: vector_smult_assoc vector_add_ldistrib) |
|
2445 |
apply (rule span_induct_alt_help_S) |
|
2446 |
apply assumption |
|
2447 |
apply simp |
|
2448 |
done |
|
2449 |
} |
|
2450 |
ultimately show "subspace (span_induct_alt_help S)" |
|
2451 |
unfolding subspace_def mem_def Ball_def by blast |
|
2452 |
qed} |
|
2453 |
with th0 show ?thesis by blast |
|
2454 |
qed |
|
2455 |
||
2456 |
lemma span_induct_alt: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
2457 |
assumes h0: "h (0::'a::semiring_1^'n)" and hS: "\<And>c x y. x \<in> S \<Longrightarrow> h y \<Longrightarrow> h (c*s x + y)" and x: "x \<in> span S" |
33175 | 2458 |
shows "h x" |
2459 |
using span_induct_alt'[of h S] h0 hS x by blast |
|
2460 |
||
2461 |
(* Individual closure properties. *) |
|
2462 |
||
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
2463 |
lemma span_superset: "x \<in> S ==> x \<in> span S" by (metis span_clauses(1)) |
33175 | 2464 |
|
2465 |
lemma span_0: "0 \<in> span S" by (metis subspace_span subspace_0) |
|
2466 |
||
2467 |
lemma span_add: "x \<in> span S \<Longrightarrow> y \<in> span S ==> x + y \<in> span S" |
|
2468 |
by (metis subspace_add subspace_span) |
|
2469 |
||
2470 |
lemma span_mul: "x \<in> span S ==> (c *s x) \<in> span S" |
|
2471 |
by (metis subspace_span subspace_mul) |
|
2472 |
||
34289 | 2473 |
lemma span_neg: "x \<in> span S ==> - (x::'a::ring_1^_) \<in> span S" |
33175 | 2474 |
by (metis subspace_neg subspace_span) |
2475 |
||
34289 | 2476 |
lemma span_sub: "(x::'a::ring_1^_) \<in> span S \<Longrightarrow> y \<in> span S ==> x - y \<in> span S" |
33175 | 2477 |
by (metis subspace_span subspace_sub) |
2478 |
||
2479 |
lemma span_setsum: "finite A \<Longrightarrow> \<forall>x \<in> A. f x \<in> span S ==> setsum f A \<in> span S" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
2480 |
by (rule subspace_setsum, rule subspace_span) |
33175 | 2481 |
|
34289 | 2482 |
lemma span_add_eq: "(x::'a::ring_1^_) \<in> span S \<Longrightarrow> x + y \<in> span S \<longleftrightarrow> y \<in> span S" |
33175 | 2483 |
apply (auto simp only: span_add span_sub) |
2484 |
apply (subgoal_tac "(x + y) - x \<in> span S", simp) |
|
2485 |
by (simp only: span_add span_sub) |
|
2486 |
||
2487 |
(* Mapping under linear image. *) |
|
2488 |
||
34289 | 2489 |
lemma span_linear_image: assumes lf: "linear (f::'a::semiring_1 ^ _ => _)" |
33175 | 2490 |
shows "span (f ` S) = f ` (span S)" |
2491 |
proof- |
|
2492 |
{fix x |
|
2493 |
assume x: "x \<in> span (f ` S)" |
|
2494 |
have "x \<in> f ` span S" |
|
2495 |
apply (rule span_induct[where x=x and S = "f ` S"]) |
|
2496 |
apply (clarsimp simp add: image_iff) |
|
2497 |
apply (frule span_superset) |
|
2498 |
apply blast |
|
2499 |
apply (simp only: mem_def) |
|
2500 |
apply (rule subspace_linear_image[OF lf]) |
|
2501 |
apply (rule subspace_span) |
|
2502 |
apply (rule x) |
|
2503 |
done} |
|
2504 |
moreover |
|
2505 |
{fix x assume x: "x \<in> span S" |
|
2506 |
have th0:"(\<lambda>a. f a \<in> span (f ` S)) = {x. f x \<in> span (f ` S)}" apply (rule set_ext) |
|
2507 |
unfolding mem_def Collect_def .. |
|
2508 |
have "f x \<in> span (f ` S)" |
|
2509 |
apply (rule span_induct[where S=S]) |
|
2510 |
apply (rule span_superset) |
|
2511 |
apply simp |
|
2512 |
apply (subst th0) |
|
2513 |
apply (rule subspace_linear_preimage[OF lf subspace_span, of "f ` S"]) |
|
2514 |
apply (rule x) |
|
2515 |
done} |
|
2516 |
ultimately show ?thesis by blast |
|
2517 |
qed |
|
2518 |
||
2519 |
(* The key breakdown property. *) |
|
2520 |
||
2521 |
lemma span_breakdown: |
|
34289 | 2522 |
assumes bS: "(b::'a::ring_1 ^ _) \<in> S" and aS: "a \<in> span S" |
33175 | 2523 |
shows "\<exists>k. a - k*s b \<in> span (S - {b})" (is "?P a") |
2524 |
proof- |
|
2525 |
{fix x assume xS: "x \<in> S" |
|
2526 |
{assume ab: "x = b" |
|
2527 |
then have "?P x" |
|
2528 |
apply simp |
|
2529 |
apply (rule exI[where x="1"], simp) |
|
2530 |
by (rule span_0)} |
|
2531 |
moreover |
|
2532 |
{assume ab: "x \<noteq> b" |
|
2533 |
then have "?P x" using xS |
|
2534 |
apply - |
|
2535 |
apply (rule exI[where x=0]) |
|
2536 |
apply (rule span_superset) |
|
2537 |
by simp} |
|
2538 |
ultimately have "?P x" by blast} |
|
2539 |
moreover have "subspace ?P" |
|
2540 |
unfolding subspace_def |
|
2541 |
apply auto |
|
2542 |
apply (simp add: mem_def) |
|
2543 |
apply (rule exI[where x=0]) |
|
2544 |
using span_0[of "S - {b}"] |
|
2545 |
apply (simp add: mem_def) |
|
2546 |
apply (clarsimp simp add: mem_def) |
|
2547 |
apply (rule_tac x="k + ka" in exI) |
|
2548 |
apply (subgoal_tac "x + y - (k + ka) *s b = (x - k*s b) + (y - ka *s b)") |
|
2549 |
apply (simp only: ) |
|
2550 |
apply (rule span_add[unfolded mem_def]) |
|
2551 |
apply assumption+ |
|
36350 | 2552 |
apply (vector field_simps) |
33175 | 2553 |
apply (clarsimp simp add: mem_def) |
2554 |
apply (rule_tac x= "c*k" in exI) |
|
2555 |
apply (subgoal_tac "c *s x - (c * k) *s b = c*s (x - k*s b)") |
|
2556 |
apply (simp only: ) |
|
2557 |
apply (rule span_mul[unfolded mem_def]) |
|
2558 |
apply assumption |
|
36350 | 2559 |
by (vector field_simps) |
33175 | 2560 |
ultimately show "?P a" using aS span_induct[where S=S and P= "?P"] by metis |
2561 |
qed |
|
2562 |
||
2563 |
lemma span_breakdown_eq: |
|
34289 | 2564 |
"(x::'a::ring_1^_) \<in> span (insert a S) \<longleftrightarrow> (\<exists>k. (x - k *s a) \<in> span S)" (is "?lhs \<longleftrightarrow> ?rhs") |
33175 | 2565 |
proof- |
2566 |
{assume x: "x \<in> span (insert a S)" |
|
2567 |
from x span_breakdown[of "a" "insert a S" "x"] |
|
2568 |
have ?rhs apply clarsimp |
|
2569 |
apply (rule_tac x= "k" in exI) |
|
2570 |
apply (rule set_rev_mp[of _ "span (S - {a})" _]) |
|
2571 |
apply assumption |
|
2572 |
apply (rule span_mono) |
|
2573 |
apply blast |
|
2574 |
done} |
|
2575 |
moreover |
|
2576 |
{ fix k assume k: "x - k *s a \<in> span S" |
|
2577 |
have eq: "x = (x - k *s a) + k *s a" by vector |
|
2578 |
have "(x - k *s a) + k *s a \<in> span (insert a S)" |
|
2579 |
apply (rule span_add) |
|
2580 |
apply (rule set_rev_mp[of _ "span S" _]) |
|
2581 |
apply (rule k) |
|
2582 |
apply (rule span_mono) |
|
2583 |
apply blast |
|
2584 |
apply (rule span_mul) |
|
2585 |
apply (rule span_superset) |
|
2586 |
apply blast |
|
2587 |
done |
|
2588 |
then have ?lhs using eq by metis} |
|
2589 |
ultimately show ?thesis by blast |
|
2590 |
qed |
|
2591 |
||
2592 |
(* Hence some "reversal" results.*) |
|
2593 |
||
2594 |
lemma in_span_insert: |
|
34289 | 2595 |
assumes a: "(a::'a::field^_) \<in> span (insert b S)" and na: "a \<notin> span S" |
33175 | 2596 |
shows "b \<in> span (insert a S)" |
2597 |
proof- |
|
2598 |
from span_breakdown[of b "insert b S" a, OF insertI1 a] |
|
2599 |
obtain k where k: "a - k*s b \<in> span (S - {b})" by auto |
|
2600 |
{assume k0: "k = 0" |
|
2601 |
with k have "a \<in> span S" |
|
2602 |
apply (simp) |
|
2603 |
apply (rule set_rev_mp) |
|
2604 |
apply assumption |
|
2605 |
apply (rule span_mono) |
|
2606 |
apply blast |
|
2607 |
done |
|
2608 |
with na have ?thesis by blast} |
|
2609 |
moreover |
|
2610 |
{assume k0: "k \<noteq> 0" |
|
2611 |
have eq: "b = (1/k) *s a - ((1/k) *s a - b)" by vector |
|
2612 |
from k0 have eq': "(1/k) *s (a - k*s b) = (1/k) *s a - b" |
|
2613 |
by (vector field_simps) |
|
2614 |
from k have "(1/k) *s (a - k*s b) \<in> span (S - {b})" |
|
2615 |
by (rule span_mul) |
|
2616 |
hence th: "(1/k) *s a - b \<in> span (S - {b})" |
|
2617 |
unfolding eq' . |
|
2618 |
||
2619 |
from k |
|
2620 |
have ?thesis |
|
2621 |
apply (subst eq) |
|
2622 |
apply (rule span_sub) |
|
2623 |
apply (rule span_mul) |
|
2624 |
apply (rule span_superset) |
|
2625 |
apply blast |
|
2626 |
apply (rule set_rev_mp) |
|
2627 |
apply (rule th) |
|
2628 |
apply (rule span_mono) |
|
2629 |
using na by blast} |
|
2630 |
ultimately show ?thesis by blast |
|
2631 |
qed |
|
2632 |
||
2633 |
lemma in_span_delete: |
|
34289 | 2634 |
assumes a: "(a::'a::field^_) \<in> span S" |
33175 | 2635 |
and na: "a \<notin> span (S-{b})" |
2636 |
shows "b \<in> span (insert a (S - {b}))" |
|
2637 |
apply (rule in_span_insert) |
|
2638 |
apply (rule set_rev_mp) |
|
2639 |
apply (rule a) |
|
2640 |
apply (rule span_mono) |
|
2641 |
apply blast |
|
2642 |
apply (rule na) |
|
2643 |
done |
|
2644 |
||
2645 |
(* Transitivity property. *) |
|
2646 |
||
2647 |
lemma span_trans: |
|
34289 | 2648 |
assumes x: "(x::'a::ring_1^_) \<in> span S" and y: "y \<in> span (insert x S)" |
33175 | 2649 |
shows "y \<in> span S" |
2650 |
proof- |
|
2651 |
from span_breakdown[of x "insert x S" y, OF insertI1 y] |
|
2652 |
obtain k where k: "y -k*s x \<in> span (S - {x})" by auto |
|
2653 |
have eq: "y = (y - k *s x) + k *s x" by vector |
|
2654 |
show ?thesis |
|
2655 |
apply (subst eq) |
|
2656 |
apply (rule span_add) |
|
2657 |
apply (rule set_rev_mp) |
|
2658 |
apply (rule k) |
|
2659 |
apply (rule span_mono) |
|
2660 |
apply blast |
|
2661 |
apply (rule span_mul) |
|
2662 |
by (rule x) |
|
2663 |
qed |
|
2664 |
||
2665 |
(* ------------------------------------------------------------------------- *) |
|
2666 |
(* An explicit expansion is sometimes needed. *) |
|
2667 |
(* ------------------------------------------------------------------------- *) |
|
2668 |
||
2669 |
lemma span_explicit: |
|
34289 | 2670 |
"span P = {y::'a::semiring_1^_. \<exists>S u. finite S \<and> S \<subseteq> P \<and> setsum (\<lambda>v. u v *s v) S = y}" |
33175 | 2671 |
(is "_ = ?E" is "_ = {y. ?h y}" is "_ = {y. \<exists>S u. ?Q S u y}") |
2672 |
proof- |
|
2673 |
{fix x assume x: "x \<in> ?E" |
|
2674 |
then obtain S u where fS: "finite S" and SP: "S\<subseteq>P" and u: "setsum (\<lambda>v. u v *s v) S = x" |
|
2675 |
by blast |
|
2676 |
have "x \<in> span P" |
|
2677 |
unfolding u[symmetric] |
|
2678 |
apply (rule span_setsum[OF fS]) |
|
2679 |
using span_mono[OF SP] |
|
2680 |
by (auto intro: span_superset span_mul)} |
|
2681 |
moreover |
|
2682 |
have "\<forall>x \<in> span P. x \<in> ?E" |
|
2683 |
unfolding mem_def Collect_def |
|
2684 |
proof(rule span_induct_alt') |
|
2685 |
show "?h 0" |
|
2686 |
apply (rule exI[where x="{}"]) by simp |
|
2687 |
next |
|
2688 |
fix c x y |
|
2689 |
assume x: "x \<in> P" and hy: "?h y" |
|
2690 |
from hy obtain S u where fS: "finite S" and SP: "S\<subseteq>P" |
|
2691 |
and u: "setsum (\<lambda>v. u v *s v) S = y" by blast |
|
2692 |
let ?S = "insert x S" |
|
2693 |
let ?u = "\<lambda>y. if y = x then (if x \<in> S then u y + c else c) |
|
2694 |
else u y" |
|
2695 |
from fS SP x have th0: "finite (insert x S)" "insert x S \<subseteq> P" by blast+ |
|
2696 |
{assume xS: "x \<in> S" |
|
2697 |
have S1: "S = (S - {x}) \<union> {x}" |
|
2698 |
and Sss:"finite (S - {x})" "finite {x}" "(S -{x}) \<inter> {x} = {}" using xS fS by auto |
|
2699 |
have "setsum (\<lambda>v. ?u v *s v) ?S =(\<Sum>v\<in>S - {x}. u v *s v) + (u x + c) *s x" |
|
2700 |
using xS |
|
2701 |
by (simp add: setsum_Un_disjoint[OF Sss, unfolded S1[symmetric]] |
|
2702 |
setsum_clauses(2)[OF fS] cong del: if_weak_cong) |
|
2703 |
also have "\<dots> = (\<Sum>v\<in>S. u v *s v) + c *s x" |
|
2704 |
apply (simp add: setsum_Un_disjoint[OF Sss, unfolded S1[symmetric]]) |
|
36350 | 2705 |
by (vector field_simps) |
33175 | 2706 |
also have "\<dots> = c*s x + y" |
2707 |
by (simp add: add_commute u) |
|
2708 |
finally have "setsum (\<lambda>v. ?u v *s v) ?S = c*s x + y" . |
|
2709 |
then have "?Q ?S ?u (c*s x + y)" using th0 by blast} |
|
2710 |
moreover |
|
2711 |
{assume xS: "x \<notin> S" |
|
2712 |
have th00: "(\<Sum>v\<in>S. (if v = x then c else u v) *s v) = y" |
|
2713 |
unfolding u[symmetric] |
|
2714 |
apply (rule setsum_cong2) |
|
2715 |
using xS by auto |
|
2716 |
have "?Q ?S ?u (c*s x + y)" using fS xS th0 |
|
2717 |
by (simp add: th00 setsum_clauses add_commute cong del: if_weak_cong)} |
|
2718 |
ultimately have "?Q ?S ?u (c*s x + y)" |
|
2719 |
by (cases "x \<in> S", simp, simp) |
|
2720 |
then show "?h (c*s x + y)" |
|
2721 |
apply - |
|
2722 |
apply (rule exI[where x="?S"]) |
|
2723 |
apply (rule exI[where x="?u"]) by metis |
|
2724 |
qed |
|
2725 |
ultimately show ?thesis by blast |
|
2726 |
qed |
|
2727 |
||
2728 |
lemma dependent_explicit: |
|
34289 | 2729 |
"dependent P \<longleftrightarrow> (\<exists>S u. finite S \<and> S \<subseteq> P \<and> (\<exists>(v::'a::{idom,field}^_) \<in>S. u v \<noteq> 0 \<and> setsum (\<lambda>v. u v *s v) S = 0))" (is "?lhs = ?rhs") |
33175 | 2730 |
proof- |
2731 |
{assume dP: "dependent P" |
|
2732 |
then obtain a S u where aP: "a \<in> P" and fS: "finite S" |
|
2733 |
and SP: "S \<subseteq> P - {a}" and ua: "setsum (\<lambda>v. u v *s v) S = a" |
|
2734 |
unfolding dependent_def span_explicit by blast |
|
2735 |
let ?S = "insert a S" |
|
2736 |
let ?u = "\<lambda>y. if y = a then - 1 else u y" |
|
2737 |
let ?v = a |
|
2738 |
from aP SP have aS: "a \<notin> S" by blast |
|
2739 |
from fS SP aP have th0: "finite ?S" "?S \<subseteq> P" "?v \<in> ?S" "?u ?v \<noteq> 0" by auto |
|
2740 |
have s0: "setsum (\<lambda>v. ?u v *s v) ?S = 0" |
|
2741 |
using fS aS |
|
36365 | 2742 |
apply (simp add: vector_smult_lneg setsum_clauses field_simps) |
33175 | 2743 |
apply (subst (2) ua[symmetric]) |
2744 |
apply (rule setsum_cong2) |
|
2745 |
by auto |
|
2746 |
with th0 have ?rhs |
|
2747 |
apply - |
|
2748 |
apply (rule exI[where x= "?S"]) |
|
2749 |
apply (rule exI[where x= "?u"]) |
|
2750 |
by clarsimp} |
|
2751 |
moreover |
|
2752 |
{fix S u v assume fS: "finite S" |
|
2753 |
and SP: "S \<subseteq> P" and vS: "v \<in> S" and uv: "u v \<noteq> 0" |
|
2754 |
and u: "setsum (\<lambda>v. u v *s v) S = 0" |
|
2755 |
let ?a = v |
|
2756 |
let ?S = "S - {v}" |
|
2757 |
let ?u = "\<lambda>i. (- u i) / u v" |
|
2758 |
have th0: "?a \<in> P" "finite ?S" "?S \<subseteq> P" using fS SP vS by auto |
|
2759 |
have "setsum (\<lambda>v. ?u v *s v) ?S = setsum (\<lambda>v. (- (inverse (u ?a))) *s (u v *s v)) S - ?u v *s v" |
|
2760 |
using fS vS uv |
|
2761 |
by (simp add: setsum_diff1 vector_smult_lneg divide_inverse |
|
2762 |
vector_smult_assoc field_simps) |
|
2763 |
also have "\<dots> = ?a" |
|
2764 |
unfolding setsum_cmul u |
|
2765 |
using uv by (simp add: vector_smult_lneg) |
|
2766 |
finally have "setsum (\<lambda>v. ?u v *s v) ?S = ?a" . |
|
2767 |
with th0 have ?lhs |
|
2768 |
unfolding dependent_def span_explicit |
|
2769 |
apply - |
|
2770 |
apply (rule bexI[where x= "?a"]) |
|
2771 |
apply simp_all |
|
2772 |
apply (rule exI[where x= "?S"]) |
|
2773 |
by auto} |
|
2774 |
ultimately show ?thesis by blast |
|
2775 |
qed |
|
2776 |
||
2777 |
||
2778 |
lemma span_finite: |
|
2779 |
assumes fS: "finite S" |
|
34289 | 2780 |
shows "span S = {(y::'a::semiring_1^_). \<exists>u. setsum (\<lambda>v. u v *s v) S = y}" |
33175 | 2781 |
(is "_ = ?rhs") |
2782 |
proof- |
|
2783 |
{fix y assume y: "y \<in> span S" |
|
2784 |
from y obtain S' u where fS': "finite S'" and SS': "S' \<subseteq> S" and |
|
2785 |
u: "setsum (\<lambda>v. u v *s v) S' = y" unfolding span_explicit by blast |
|
2786 |
let ?u = "\<lambda>x. if x \<in> S' then u x else 0" |
|
2787 |
from setsum_restrict_set[OF fS, of "\<lambda>v. u v *s v" S', symmetric] SS' |
|
2788 |
have "setsum (\<lambda>v. ?u v *s v) S = setsum (\<lambda>v. u v *s v) S'" |
|
2789 |
unfolding cond_value_iff cond_application_beta |
|
2790 |
by (simp add: cond_value_iff inf_absorb2 cong del: if_weak_cong) |
|
2791 |
hence "setsum (\<lambda>v. ?u v *s v) S = y" by (metis u) |
|
2792 |
hence "y \<in> ?rhs" by auto} |
|
2793 |
moreover |
|
2794 |
{fix y u assume u: "setsum (\<lambda>v. u v *s v) S = y" |
|
2795 |
then have "y \<in> span S" using fS unfolding span_explicit by auto} |
|
2796 |
ultimately show ?thesis by blast |
|
2797 |
qed |
|
2798 |
||
2799 |
||
2800 |
(* Standard bases are a spanning set, and obviously finite. *) |
|
2801 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
2802 |
lemma span_stdbasis:"span {basis i :: 'a::ring_1^'n | i. i \<in> (UNIV :: 'n set)} = UNIV" |
33175 | 2803 |
apply (rule set_ext) |
2804 |
apply auto |
|
2805 |
apply (subst basis_expansion[symmetric]) |
|
2806 |
apply (rule span_setsum) |
|
2807 |
apply simp |
|
2808 |
apply auto |
|
2809 |
apply (rule span_mul) |
|
2810 |
apply (rule span_superset) |
|
2811 |
apply (auto simp add: Collect_def mem_def) |
|
2812 |
done |
|
2813 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
2814 |
lemma finite_stdbasis: "finite {basis i ::real^'n |i. i\<in> (UNIV:: 'n set)}" (is "finite ?S") |
33175 | 2815 |
proof- |
2816 |
have eq: "?S = basis ` UNIV" by blast |
|
33715 | 2817 |
show ?thesis unfolding eq by auto |
33175 | 2818 |
qed |
2819 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
2820 |
lemma card_stdbasis: "card {basis i ::real^'n |i. i\<in> (UNIV :: 'n set)} = CARD('n)" (is "card ?S = _") |
33715 | 2821 |
proof- |
2822 |
have eq: "?S = basis ` UNIV" by blast |
|
2823 |
show ?thesis unfolding eq using card_image[OF basis_inj] by simp |
|
2824 |
qed |
|
2825 |
||
33175 | 2826 |
|
2827 |
lemma independent_stdbasis_lemma: |
|
34289 | 2828 |
assumes x: "(x::'a::semiring_1 ^ _) \<in> span (basis ` S)" |
33175 | 2829 |
and iS: "i \<notin> S" |
2830 |
shows "(x$i) = 0" |
|
2831 |
proof- |
|
2832 |
let ?U = "UNIV :: 'n set" |
|
2833 |
let ?B = "basis ` S" |
|
34289 | 2834 |
let ?P = "\<lambda>(x::'a^_). \<forall>i\<in> ?U. i \<notin> S \<longrightarrow> x$i =0" |
2835 |
{fix x::"'a^_" assume xS: "x\<in> ?B" |
|
33175 | 2836 |
from xS have "?P x" by auto} |
2837 |
moreover |
|
2838 |
have "subspace ?P" |
|
2839 |
by (auto simp add: subspace_def Collect_def mem_def) |
|
2840 |
ultimately show ?thesis |
|
2841 |
using x span_induct[of ?B ?P x] iS by blast |
|
2842 |
qed |
|
2843 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
2844 |
lemma independent_stdbasis: "independent {basis i ::real^'n |i. i\<in> (UNIV :: 'n set)}" |
33175 | 2845 |
proof- |
2846 |
let ?I = "UNIV :: 'n set" |
|
2847 |
let ?b = "basis :: _ \<Rightarrow> real ^'n" |
|
2848 |
let ?B = "?b ` ?I" |
|
2849 |
have eq: "{?b i|i. i \<in> ?I} = ?B" |
|
2850 |
by auto |
|
2851 |
{assume d: "dependent ?B" |
|
2852 |
then obtain k where k: "k \<in> ?I" "?b k \<in> span (?B - {?b k})" |
|
2853 |
unfolding dependent_def by auto |
|
2854 |
have eq1: "?B - {?b k} = ?B - ?b ` {k}" by simp |
|
2855 |
have eq2: "?B - {?b k} = ?b ` (?I - {k})" |
|
2856 |
unfolding eq1 |
|
2857 |
apply (rule inj_on_image_set_diff[symmetric]) |
|
2858 |
apply (rule basis_inj) using k(1) by auto |
|
2859 |
from k(2) have th0: "?b k \<in> span (?b ` (?I - {k}))" unfolding eq2 . |
|
2860 |
from independent_stdbasis_lemma[OF th0, of k, simplified] |
|
2861 |
have False by simp} |
|
2862 |
then show ?thesis unfolding eq dependent_def .. |
|
2863 |
qed |
|
2864 |
||
2865 |
(* This is useful for building a basis step-by-step. *) |
|
2866 |
||
2867 |
lemma independent_insert: |
|
34289 | 2868 |
"independent(insert (a::'a::field ^_) S) \<longleftrightarrow> |
33175 | 2869 |
(if a \<in> S then independent S |
2870 |
else independent S \<and> a \<notin> span S)" (is "?lhs \<longleftrightarrow> ?rhs") |
|
2871 |
proof- |
|
2872 |
{assume aS: "a \<in> S" |
|
2873 |
hence ?thesis using insert_absorb[OF aS] by simp} |
|
2874 |
moreover |
|
2875 |
{assume aS: "a \<notin> S" |
|
2876 |
{assume i: ?lhs |
|
2877 |
then have ?rhs using aS |
|
2878 |
apply simp |
|
2879 |
apply (rule conjI) |
|
2880 |
apply (rule independent_mono) |
|
2881 |
apply assumption |
|
2882 |
apply blast |
|
2883 |
by (simp add: dependent_def)} |
|
2884 |
moreover |
|
2885 |
{assume i: ?rhs |
|
2886 |
have ?lhs using i aS |
|
2887 |
apply simp |
|
2888 |
apply (auto simp add: dependent_def) |
|
2889 |
apply (case_tac "aa = a", auto) |
|
2890 |
apply (subgoal_tac "insert a S - {aa} = insert a (S - {aa})") |
|
2891 |
apply simp |
|
2892 |
apply (subgoal_tac "a \<in> span (insert aa (S - {aa}))") |
|
2893 |
apply (subgoal_tac "insert aa (S - {aa}) = S") |
|
2894 |
apply simp |
|
2895 |
apply blast |
|
2896 |
apply (rule in_span_insert) |
|
2897 |
apply assumption |
|
2898 |
apply blast |
|
2899 |
apply blast |
|
2900 |
done} |
|
2901 |
ultimately have ?thesis by blast} |
|
2902 |
ultimately show ?thesis by blast |
|
2903 |
qed |
|
2904 |
||
2905 |
(* The degenerate case of the Exchange Lemma. *) |
|
2906 |
||
2907 |
lemma mem_delete: "x \<in> (A - {a}) \<longleftrightarrow> x \<noteq> a \<and> x \<in> A" |
|
2908 |
by blast |
|
2909 |
||
2910 |
lemma span_span: "span (span A) = span A" |
|
2911 |
unfolding span_def hull_hull .. |
|
2912 |
||
2913 |
lemma span_inc: "S \<subseteq> span S" |
|
2914 |
by (metis subset_eq span_superset) |
|
2915 |
||
2916 |
lemma spanning_subset_independent: |
|
34289 | 2917 |
assumes BA: "B \<subseteq> A" and iA: "independent (A::('a::field ^_) set)" |
33175 | 2918 |
and AsB: "A \<subseteq> span B" |
2919 |
shows "A = B" |
|
2920 |
proof |
|
2921 |
from BA show "B \<subseteq> A" . |
|
2922 |
next |
|
2923 |
from span_mono[OF BA] span_mono[OF AsB] |
|
2924 |
have sAB: "span A = span B" unfolding span_span by blast |
|
2925 |
||
2926 |
{fix x assume x: "x \<in> A" |
|
2927 |
from iA have th0: "x \<notin> span (A - {x})" |
|
2928 |
unfolding dependent_def using x by blast |
|
2929 |
from x have xsA: "x \<in> span A" by (blast intro: span_superset) |
|
2930 |
have "A - {x} \<subseteq> A" by blast |
|
2931 |
hence th1:"span (A - {x}) \<subseteq> span A" by (metis span_mono) |
|
2932 |
{assume xB: "x \<notin> B" |
|
2933 |
from xB BA have "B \<subseteq> A -{x}" by blast |
|
2934 |
hence "span B \<subseteq> span (A - {x})" by (metis span_mono) |
|
2935 |
with th1 th0 sAB have "x \<notin> span A" by blast |
|
2936 |
with x have False by (metis span_superset)} |
|
2937 |
then have "x \<in> B" by blast} |
|
2938 |
then show "A \<subseteq> B" by blast |
|
2939 |
qed |
|
2940 |
||
2941 |
(* The general case of the Exchange Lemma, the key to what follows. *) |
|
2942 |
||
2943 |
lemma exchange_lemma: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
2944 |
assumes f:"finite (t:: ('a::field^'n) set)" and i: "independent s" |
33175 | 2945 |
and sp:"s \<subseteq> span t" |
33715 | 2946 |
shows "\<exists>t'. (card t' = card t) \<and> finite t' \<and> s \<subseteq> t' \<and> t' \<subseteq> s \<union> t \<and> s \<subseteq> span t'" |
33175 | 2947 |
using f i sp |
34915 | 2948 |
proof(induct "card (t - s)" arbitrary: s t rule: less_induct) |
2949 |
case less |
|
2950 |
note ft = `finite t` and s = `independent s` and sp = `s \<subseteq> span t` |
|
33715 | 2951 |
let ?P = "\<lambda>t'. (card t' = card t) \<and> finite t' \<and> s \<subseteq> t' \<and> t' \<subseteq> s \<union> t \<and> s \<subseteq> span t'" |
33175 | 2952 |
let ?ths = "\<exists>t'. ?P t'" |
2953 |
{assume st: "s \<subseteq> t" |
|
2954 |
from st ft span_mono[OF st] have ?ths apply - apply (rule exI[where x=t]) |
|
33715 | 2955 |
by (auto intro: span_superset)} |
33175 | 2956 |
moreover |
2957 |
{assume st: "t \<subseteq> s" |
|
2958 |
||
2959 |
from spanning_subset_independent[OF st s sp] |
|
2960 |
st ft span_mono[OF st] have ?ths apply - apply (rule exI[where x=t]) |
|
33715 | 2961 |
by (auto intro: span_superset)} |
33175 | 2962 |
moreover |
2963 |
{assume st: "\<not> s \<subseteq> t" "\<not> t \<subseteq> s" |
|
2964 |
from st(2) obtain b where b: "b \<in> t" "b \<notin> s" by blast |
|
2965 |
from b have "t - {b} - s \<subset> t - s" by blast |
|
34915 | 2966 |
then have cardlt: "card (t - {b} - s) < card (t - s)" using ft |
33175 | 2967 |
by (auto intro: psubset_card_mono) |
2968 |
from b ft have ct0: "card t \<noteq> 0" by auto |
|
2969 |
{assume stb: "s \<subseteq> span(t -{b})" |
|
2970 |
from ft have ftb: "finite (t -{b})" by auto |
|
34915 | 2971 |
from less(1)[OF cardlt ftb s stb] |
33715 | 2972 |
obtain u where u: "card u = card (t-{b})" "s \<subseteq> u" "u \<subseteq> s \<union> (t - {b})" "s \<subseteq> span u" and fu: "finite u" by blast |
33175 | 2973 |
let ?w = "insert b u" |
2974 |
have th0: "s \<subseteq> insert b u" using u by blast |
|
2975 |
from u(3) b have "u \<subseteq> s \<union> t" by blast |
|
2976 |
then have th1: "insert b u \<subseteq> s \<union> t" using u b by blast |
|
2977 |
have bu: "b \<notin> u" using b u by blast |
|
33715 | 2978 |
from u(1) ft b have "card u = (card t - 1)" by auto |
33175 | 2979 |
then |
33715 | 2980 |
have th2: "card (insert b u) = card t" |
2981 |
using card_insert_disjoint[OF fu bu] ct0 by auto |
|
33175 | 2982 |
from u(4) have "s \<subseteq> span u" . |
2983 |
also have "\<dots> \<subseteq> span (insert b u)" apply (rule span_mono) by blast |
|
33715 | 2984 |
finally have th3: "s \<subseteq> span (insert b u)" . |
2985 |
from th0 th1 th2 th3 fu have th: "?P ?w" by blast |
|
33175 | 2986 |
from th have ?ths by blast} |
2987 |
moreover |
|
2988 |
{assume stb: "\<not> s \<subseteq> span(t -{b})" |
|
2989 |
from stb obtain a where a: "a \<in> s" "a \<notin> span (t - {b})" by blast |
|
2990 |
have ab: "a \<noteq> b" using a b by blast |
|
2991 |
have at: "a \<notin> t" using a ab span_superset[of a "t- {b}"] by auto |
|
34915 | 2992 |
have mlt: "card ((insert a (t - {b})) - s) < card (t - s)" |
2993 |
using cardlt ft a b by auto |
|
33175 | 2994 |
have ft': "finite (insert a (t - {b}))" using ft by auto |
2995 |
{fix x assume xs: "x \<in> s" |
|
2996 |
have t: "t \<subseteq> (insert b (insert a (t -{b})))" using b by auto |
|
2997 |
from b(1) have "b \<in> span t" by (simp add: span_superset) |
|
35541 | 2998 |
have bs: "b \<in> span (insert a (t - {b}))" apply(rule in_span_delete) |
2999 |
using a sp unfolding subset_eq by auto |
|
33175 | 3000 |
from xs sp have "x \<in> span t" by blast |
3001 |
with span_mono[OF t] |
|
3002 |
have x: "x \<in> span (insert b (insert a (t - {b})))" .. |
|
3003 |
from span_trans[OF bs x] have "x \<in> span (insert a (t - {b}))" .} |
|
3004 |
then have sp': "s \<subseteq> span (insert a (t - {b}))" by blast |
|
3005 |
||
34915 | 3006 |
from less(1)[OF mlt ft' s sp'] obtain u where |
33715 | 3007 |
u: "card u = card (insert a (t -{b}))" "finite u" "s \<subseteq> u" "u \<subseteq> s \<union> insert a (t -{b})" |
33175 | 3008 |
"s \<subseteq> span u" by blast |
33715 | 3009 |
from u a b ft at ct0 have "?P u" by auto |
33175 | 3010 |
then have ?ths by blast } |
3011 |
ultimately have ?ths by blast |
|
3012 |
} |
|
3013 |
ultimately |
|
3014 |
show ?ths by blast |
|
3015 |
qed |
|
3016 |
||
3017 |
(* This implies corresponding size bounds. *) |
|
3018 |
||
3019 |
lemma independent_span_bound: |
|
34289 | 3020 |
assumes f: "finite t" and i: "independent (s::('a::field^_) set)" and sp:"s \<subseteq> span t" |
33175 | 3021 |
shows "finite s \<and> card s \<le> card t" |
33715 | 3022 |
by (metis exchange_lemma[OF f i sp] finite_subset card_mono) |
33175 | 3023 |
|
3024 |
||
3025 |
lemma finite_Atleast_Atmost_nat[simp]: "finite {f x |x. x\<in> (UNIV::'a::finite set)}" |
|
3026 |
proof- |
|
3027 |
have eq: "{f x |x. x\<in> UNIV} = f ` UNIV" by auto |
|
3028 |
show ?thesis unfolding eq |
|
3029 |
apply (rule finite_imageI) |
|
3030 |
apply (rule finite) |
|
3031 |
done |
|
3032 |
qed |
|
3033 |
||
3034 |
||
3035 |
lemma independent_bound: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3036 |
fixes S:: "(real^'n) set" |
33175 | 3037 |
shows "independent S \<Longrightarrow> finite S \<and> card S <= CARD('n)" |
3038 |
apply (subst card_stdbasis[symmetric]) |
|
3039 |
apply (rule independent_span_bound) |
|
3040 |
apply (rule finite_Atleast_Atmost_nat) |
|
3041 |
apply assumption |
|
3042 |
unfolding span_stdbasis |
|
3043 |
apply (rule subset_UNIV) |
|
3044 |
done |
|
3045 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3046 |
lemma dependent_biggerset: "(finite (S::(real ^'n) set) ==> card S > CARD('n)) ==> dependent S" |
33175 | 3047 |
by (metis independent_bound not_less) |
3048 |
||
3049 |
(* Hence we can create a maximal independent subset. *) |
|
3050 |
||
3051 |
lemma maximal_independent_subset_extend: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3052 |
assumes sv: "(S::(real^'n) set) \<subseteq> V" and iS: "independent S" |
33175 | 3053 |
shows "\<exists>B. S \<subseteq> B \<and> B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B" |
3054 |
using sv iS |
|
34915 | 3055 |
proof(induct "CARD('n) - card S" arbitrary: S rule: less_induct) |
3056 |
case less |
|
3057 |
note sv = `S \<subseteq> V` and i = `independent S` |
|
33175 | 3058 |
let ?P = "\<lambda>B. S \<subseteq> B \<and> B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B" |
3059 |
let ?ths = "\<exists>x. ?P x" |
|
3060 |
let ?d = "CARD('n)" |
|
3061 |
{assume "V \<subseteq> span S" |
|
3062 |
then have ?ths using sv i by blast } |
|
3063 |
moreover |
|
3064 |
{assume VS: "\<not> V \<subseteq> span S" |
|
3065 |
from VS obtain a where a: "a \<in> V" "a \<notin> span S" by blast |
|
3066 |
from a have aS: "a \<notin> S" by (auto simp add: span_superset) |
|
3067 |
have th0: "insert a S \<subseteq> V" using a sv by blast |
|
3068 |
from independent_insert[of a S] i a |
|
3069 |
have th1: "independent (insert a S)" by auto |
|
34915 | 3070 |
have mlt: "?d - card (insert a S) < ?d - card S" |
3071 |
using aS a independent_bound[OF th1] |
|
33175 | 3072 |
by auto |
3073 |
||
34915 | 3074 |
from less(1)[OF mlt th0 th1] |
33175 | 3075 |
obtain B where B: "insert a S \<subseteq> B" "B \<subseteq> V" "independent B" " V \<subseteq> span B" |
3076 |
by blast |
|
3077 |
from B have "?P B" by auto |
|
3078 |
then have ?ths by blast} |
|
3079 |
ultimately show ?ths by blast |
|
3080 |
qed |
|
3081 |
||
3082 |
lemma maximal_independent_subset: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3083 |
"\<exists>(B:: (real ^'n) set). B\<subseteq> V \<and> independent B \<and> V \<subseteq> span B" |
33175 | 3084 |
by (metis maximal_independent_subset_extend[of "{}:: (real ^'n) set"] empty_subsetI independent_empty) |
3085 |
||
3086 |
(* Notion of dimension. *) |
|
3087 |
||
33715 | 3088 |
definition "dim V = (SOME n. \<exists>B. B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> (card B = n))" |
3089 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3090 |
lemma basis_exists: "\<exists>B. (B :: (real ^'n) set) \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> (card B = dim V)" |
33715 | 3091 |
unfolding dim_def some_eq_ex[of "\<lambda>n. \<exists>B. B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> (card B = n)"] |
33175 | 3092 |
using maximal_independent_subset[of V] independent_bound |
3093 |
by auto |
|
3094 |
||
3095 |
(* Consequences of independence or spanning for cardinality. *) |
|
3096 |
||
33715 | 3097 |
lemma independent_card_le_dim: |
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3098 |
assumes "(B::(real ^'n) set) \<subseteq> V" and "independent B" shows "card B \<le> dim V" |
33715 | 3099 |
proof - |
3100 |
from basis_exists[of V] `B \<subseteq> V` |
|
3101 |
obtain B' where "independent B'" and "B \<subseteq> span B'" and "card B' = dim V" by blast |
|
3102 |
with independent_span_bound[OF _ `independent B` `B \<subseteq> span B'`] independent_bound[of B'] |
|
3103 |
show ?thesis by auto |
|
3104 |
qed |
|
33175 | 3105 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3106 |
lemma span_card_ge_dim: "(B::(real ^'n) set) \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> finite B \<Longrightarrow> dim V \<le> card B" |
33715 | 3107 |
by (metis basis_exists[of V] independent_span_bound subset_trans) |
33175 | 3108 |
|
3109 |
lemma basis_card_eq_dim: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3110 |
"B \<subseteq> (V:: (real ^'n) set) \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> independent B \<Longrightarrow> finite B \<and> card B = dim V" |
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
3111 |
by (metis order_eq_iff independent_card_le_dim span_card_ge_dim independent_bound) |
33715 | 3112 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3113 |
lemma dim_unique: "(B::(real ^'n) set) \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> independent B \<Longrightarrow> card B = n \<Longrightarrow> dim V = n" |
33715 | 3114 |
by (metis basis_card_eq_dim) |
33175 | 3115 |
|
3116 |
(* More lemmas about dimension. *) |
|
3117 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3118 |
lemma dim_univ: "dim (UNIV :: (real^'n) set) = CARD('n)" |
33175 | 3119 |
apply (rule dim_unique[of "{basis i |i. i\<in> (UNIV :: 'n set)}"]) |
33715 | 3120 |
by (auto simp only: span_stdbasis card_stdbasis finite_stdbasis independent_stdbasis) |
33175 | 3121 |
|
3122 |
lemma dim_subset: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3123 |
"(S:: (real ^'n) set) \<subseteq> T \<Longrightarrow> dim S \<le> dim T" |
33175 | 3124 |
using basis_exists[of T] basis_exists[of S] |
33715 | 3125 |
by (metis independent_card_le_dim subset_trans) |
33175 | 3126 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3127 |
lemma dim_subset_univ: "dim (S:: (real^'n) set) \<le> CARD('n)" |
33175 | 3128 |
by (metis dim_subset subset_UNIV dim_univ) |
3129 |
||
3130 |
(* Converses to those. *) |
|
3131 |
||
3132 |
lemma card_ge_dim_independent: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3133 |
assumes BV:"(B::(real ^'n) set) \<subseteq> V" and iB:"independent B" and dVB:"dim V \<le> card B" |
33175 | 3134 |
shows "V \<subseteq> span B" |
3135 |
proof- |
|
3136 |
{fix a assume aV: "a \<in> V" |
|
3137 |
{assume aB: "a \<notin> span B" |
|
3138 |
then have iaB: "independent (insert a B)" using iB aV BV by (simp add: independent_insert) |
|
3139 |
from aV BV have th0: "insert a B \<subseteq> V" by blast |
|
3140 |
from aB have "a \<notin>B" by (auto simp add: span_superset) |
|
33715 | 3141 |
with independent_card_le_dim[OF th0 iaB] dVB independent_bound[OF iB] have False by auto } |
33175 | 3142 |
then have "a \<in> span B" by blast} |
3143 |
then show ?thesis by blast |
|
3144 |
qed |
|
3145 |
||
3146 |
lemma card_le_dim_spanning: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3147 |
assumes BV: "(B:: (real ^'n) set) \<subseteq> V" and VB: "V \<subseteq> span B" |
33175 | 3148 |
and fB: "finite B" and dVB: "dim V \<ge> card B" |
3149 |
shows "independent B" |
|
3150 |
proof- |
|
3151 |
{fix a assume a: "a \<in> B" "a \<in> span (B -{a})" |
|
3152 |
from a fB have c0: "card B \<noteq> 0" by auto |
|
3153 |
from a fB have cb: "card (B -{a}) = card B - 1" by auto |
|
3154 |
from BV a have th0: "B -{a} \<subseteq> V" by blast |
|
3155 |
{fix x assume x: "x \<in> V" |
|
3156 |
from a have eq: "insert a (B -{a}) = B" by blast |
|
3157 |
from x VB have x': "x \<in> span B" by blast |
|
3158 |
from span_trans[OF a(2), unfolded eq, OF x'] |
|
3159 |
have "x \<in> span (B -{a})" . } |
|
3160 |
then have th1: "V \<subseteq> span (B -{a})" by blast |
|
3161 |
have th2: "finite (B -{a})" using fB by auto |
|
3162 |
from span_card_ge_dim[OF th0 th1 th2] |
|
3163 |
have c: "dim V \<le> card (B -{a})" . |
|
3164 |
from c c0 dVB cb have False by simp} |
|
3165 |
then show ?thesis unfolding dependent_def by blast |
|
3166 |
qed |
|
3167 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3168 |
lemma card_eq_dim: "(B:: (real ^'n) set) \<subseteq> V \<Longrightarrow> card B = dim V \<Longrightarrow> finite B \<Longrightarrow> independent B \<longleftrightarrow> V \<subseteq> span B" |
33715 | 3169 |
by (metis order_eq_iff card_le_dim_spanning |
33175 | 3170 |
card_ge_dim_independent) |
3171 |
||
3172 |
(* ------------------------------------------------------------------------- *) |
|
3173 |
(* More general size bound lemmas. *) |
|
3174 |
(* ------------------------------------------------------------------------- *) |
|
3175 |
||
3176 |
lemma independent_bound_general: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3177 |
"independent (S:: (real^'n) set) \<Longrightarrow> finite S \<and> card S \<le> dim S" |
33175 | 3178 |
by (metis independent_card_le_dim independent_bound subset_refl) |
3179 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3180 |
lemma dependent_biggerset_general: "(finite (S:: (real^'n) set) \<Longrightarrow> card S > dim S) \<Longrightarrow> dependent S" |
33175 | 3181 |
using independent_bound_general[of S] by (metis linorder_not_le) |
3182 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3183 |
lemma dim_span: "dim (span (S:: (real ^'n) set)) = dim S" |
33175 | 3184 |
proof- |
3185 |
have th0: "dim S \<le> dim (span S)" |
|
3186 |
by (auto simp add: subset_eq intro: dim_subset span_superset) |
|
3187 |
from basis_exists[of S] |
|
33715 | 3188 |
obtain B where B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S" by blast |
3189 |
from B have fB: "finite B" "card B = dim S" using independent_bound by blast+ |
|
33175 | 3190 |
have bSS: "B \<subseteq> span S" using B(1) by (metis subset_eq span_inc) |
3191 |
have sssB: "span S \<subseteq> span B" using span_mono[OF B(3)] by (simp add: span_span) |
|
3192 |
from span_card_ge_dim[OF bSS sssB fB(1)] th0 show ?thesis |
|
3193 |
using fB(2) by arith |
|
3194 |
qed |
|
3195 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3196 |
lemma subset_le_dim: "(S:: (real ^'n) set) \<subseteq> span T \<Longrightarrow> dim S \<le> dim T" |
33175 | 3197 |
by (metis dim_span dim_subset) |
3198 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3199 |
lemma span_eq_dim: "span (S:: (real ^'n) set) = span T ==> dim S = dim T" |
33175 | 3200 |
by (metis dim_span) |
3201 |
||
3202 |
lemma spans_image: |
|
34289 | 3203 |
assumes lf: "linear (f::'a::semiring_1^_ \<Rightarrow> _)" and VB: "V \<subseteq> span B" |
33175 | 3204 |
shows "f ` V \<subseteq> span (f ` B)" |
3205 |
unfolding span_linear_image[OF lf] |
|
3206 |
by (metis VB image_mono) |
|
3207 |
||
3208 |
lemma dim_image_le: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3209 |
fixes f :: "real^'n \<Rightarrow> real^'m" |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3210 |
assumes lf: "linear f" shows "dim (f ` S) \<le> dim (S:: (real ^'n) set)" |
33175 | 3211 |
proof- |
3212 |
from basis_exists[of S] obtain B where |
|
33715 | 3213 |
B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S" by blast |
3214 |
from B have fB: "finite B" "card B = dim S" using independent_bound by blast+ |
|
33175 | 3215 |
have "dim (f ` S) \<le> card (f ` B)" |
3216 |
apply (rule span_card_ge_dim) |
|
3217 |
using lf B fB by (auto simp add: span_linear_image spans_image subset_image_iff) |
|
3218 |
also have "\<dots> \<le> dim S" using card_image_le[OF fB(1)] fB by simp |
|
3219 |
finally show ?thesis . |
|
3220 |
qed |
|
3221 |
||
3222 |
(* Relation between bases and injectivity/surjectivity of map. *) |
|
3223 |
||
3224 |
lemma spanning_surjective_image: |
|
34289 | 3225 |
assumes us: "UNIV \<subseteq> span (S:: ('a::semiring_1 ^_) set)" |
33175 | 3226 |
and lf: "linear f" and sf: "surj f" |
3227 |
shows "UNIV \<subseteq> span (f ` S)" |
|
3228 |
proof- |
|
3229 |
have "UNIV \<subseteq> f ` UNIV" using sf by (auto simp add: surj_def) |
|
3230 |
also have " \<dots> \<subseteq> span (f ` S)" using spans_image[OF lf us] . |
|
3231 |
finally show ?thesis . |
|
3232 |
qed |
|
3233 |
||
3234 |
lemma independent_injective_image: |
|
34289 | 3235 |
assumes iS: "independent (S::('a::semiring_1^_) set)" and lf: "linear f" and fi: "inj f" |
33175 | 3236 |
shows "independent (f ` S)" |
3237 |
proof- |
|
3238 |
{fix a assume a: "a \<in> S" "f a \<in> span (f ` S - {f a})" |
|
3239 |
have eq: "f ` S - {f a} = f ` (S - {a})" using fi |
|
3240 |
by (auto simp add: inj_on_def) |
|
3241 |
from a have "f a \<in> f ` span (S -{a})" |
|
3242 |
unfolding eq span_linear_image[OF lf, of "S - {a}"] by blast |
|
3243 |
hence "a \<in> span (S -{a})" using fi by (auto simp add: inj_on_def) |
|
3244 |
with a(1) iS have False by (simp add: dependent_def) } |
|
3245 |
then show ?thesis unfolding dependent_def by blast |
|
3246 |
qed |
|
3247 |
||
3248 |
(* ------------------------------------------------------------------------- *) |
|
3249 |
(* Picking an orthogonal replacement for a spanning set. *) |
|
3250 |
(* ------------------------------------------------------------------------- *) |
|
3251 |
(* FIXME : Move to some general theory ?*) |
|
3252 |
definition "pairwise R S \<longleftrightarrow> (\<forall>x \<in> S. \<forall>y\<in> S. x\<noteq>y \<longrightarrow> R x y)" |
|
3253 |
||
35542 | 3254 |
lemma vector_sub_project_orthogonal: "(b::real^'n) \<bullet> (x - ((b \<bullet> x) / (b \<bullet> b)) *s b) = 0" |
3255 |
unfolding inner_simps smult_conv_scaleR by auto |
|
33175 | 3256 |
|
3257 |
lemma basis_orthogonal: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3258 |
fixes B :: "(real ^'n) set" |
33175 | 3259 |
assumes fB: "finite B" |
3260 |
shows "\<exists>C. finite C \<and> card C \<le> card B \<and> span C = span B \<and> pairwise orthogonal C" |
|
3261 |
(is " \<exists>C. ?P B C") |
|
3262 |
proof(induct rule: finite_induct[OF fB]) |
|
3263 |
case 1 thus ?case apply (rule exI[where x="{}"]) by (auto simp add: pairwise_def) |
|
3264 |
next |
|
3265 |
case (2 a B) |
|
3266 |
note fB = `finite B` and aB = `a \<notin> B` |
|
3267 |
from `\<exists>C. finite C \<and> card C \<le> card B \<and> span C = span B \<and> pairwise orthogonal C` |
|
3268 |
obtain C where C: "finite C" "card C \<le> card B" |
|
3269 |
"span C = span B" "pairwise orthogonal C" by blast |
|
35542 | 3270 |
let ?a = "a - setsum (\<lambda>x. (x \<bullet> a / (x \<bullet> x)) *s x) C" |
33175 | 3271 |
let ?C = "insert ?a C" |
3272 |
from C(1) have fC: "finite ?C" by simp |
|
3273 |
from fB aB C(1,2) have cC: "card ?C \<le> card (insert a B)" by (simp add: card_insert_if) |
|
3274 |
{fix x k |
|
36350 | 3275 |
have th0: "\<And>(a::'b::comm_ring) b c. a - (b - c) = c + (a - b)" by (simp add: field_simps) |
33175 | 3276 |
have "x - k *s (a - (\<Sum>x\<in>C. (x \<bullet> a / (x \<bullet> x)) *s x)) \<in> span C \<longleftrightarrow> x - k *s a \<in> span C" |
3277 |
apply (simp only: vector_ssub_ldistrib th0) |
|
3278 |
apply (rule span_add_eq) |
|
3279 |
apply (rule span_mul) |
|
3280 |
apply (rule span_setsum[OF C(1)]) |
|
3281 |
apply clarify |
|
3282 |
apply (rule span_mul) |
|
3283 |
by (rule span_superset)} |
|
3284 |
then have SC: "span ?C = span (insert a B)" |
|
3285 |
unfolding expand_set_eq span_breakdown_eq C(3)[symmetric] by auto |
|
3286 |
thm pairwise_def |
|
3287 |
{fix x y assume xC: "x \<in> ?C" and yC: "y \<in> ?C" and xy: "x \<noteq> y" |
|
3288 |
{assume xa: "x = ?a" and ya: "y = ?a" |
|
3289 |
have "orthogonal x y" using xa ya xy by blast} |
|
3290 |
moreover |
|
3291 |
{assume xa: "x = ?a" and ya: "y \<noteq> ?a" "y \<in> C" |
|
3292 |
from ya have Cy: "C = insert y (C - {y})" by blast |
|
3293 |
have fth: "finite (C - {y})" using C by simp |
|
3294 |
have "orthogonal x y" |
|
3295 |
using xa ya |
|
35542 | 3296 |
unfolding orthogonal_def xa inner_simps diff_eq_0_iff_eq |
33175 | 3297 |
apply simp |
3298 |
apply (subst Cy) |
|
3299 |
using C(1) fth |
|
35542 | 3300 |
apply (simp only: setsum_clauses) unfolding smult_conv_scaleR |
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
3301 |
apply (auto simp add: inner_simps inner_commute[of y a] dot_lsum[OF fth]) |
33175 | 3302 |
apply (rule setsum_0') |
3303 |
apply clarsimp |
|
3304 |
apply (rule C(4)[unfolded pairwise_def orthogonal_def, rule_format]) |
|
3305 |
by auto} |
|
3306 |
moreover |
|
3307 |
{assume xa: "x \<noteq> ?a" "x \<in> C" and ya: "y = ?a" |
|
3308 |
from xa have Cx: "C = insert x (C - {x})" by blast |
|
3309 |
have fth: "finite (C - {x})" using C by simp |
|
3310 |
have "orthogonal x y" |
|
3311 |
using xa ya |
|
35542 | 3312 |
unfolding orthogonal_def ya inner_simps diff_eq_0_iff_eq |
33175 | 3313 |
apply simp |
3314 |
apply (subst Cx) |
|
3315 |
using C(1) fth |
|
35542 | 3316 |
apply (simp only: setsum_clauses) unfolding smult_conv_scaleR |
3317 |
apply (subst inner_commute[of x]) |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
3318 |
apply (auto simp add: inner_simps inner_commute[of x a] dot_rsum[OF fth]) |
33175 | 3319 |
apply (rule setsum_0') |
3320 |
apply clarsimp |
|
3321 |
apply (rule C(4)[unfolded pairwise_def orthogonal_def, rule_format]) |
|
3322 |
by auto} |
|
3323 |
moreover |
|
3324 |
{assume xa: "x \<in> C" and ya: "y \<in> C" |
|
3325 |
have "orthogonal x y" using xa ya xy C(4) unfolding pairwise_def by blast} |
|
3326 |
ultimately have "orthogonal x y" using xC yC by blast} |
|
3327 |
then have CPO: "pairwise orthogonal ?C" unfolding pairwise_def by blast |
|
3328 |
from fC cC SC CPO have "?P (insert a B) ?C" by blast |
|
3329 |
then show ?case by blast |
|
3330 |
qed |
|
3331 |
||
3332 |
lemma orthogonal_basis_exists: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3333 |
fixes V :: "(real ^'n) set" |
33715 | 3334 |
shows "\<exists>B. independent B \<and> B \<subseteq> span V \<and> V \<subseteq> span B \<and> (card B = dim V) \<and> pairwise orthogonal B" |
33175 | 3335 |
proof- |
33715 | 3336 |
from basis_exists[of V] obtain B where B: "B \<subseteq> V" "independent B" "V \<subseteq> span B" "card B = dim V" by blast |
3337 |
from B have fB: "finite B" "card B = dim V" using independent_bound by auto |
|
33175 | 3338 |
from basis_orthogonal[OF fB(1)] obtain C where |
3339 |
C: "finite C" "card C \<le> card B" "span C = span B" "pairwise orthogonal C" by blast |
|
3340 |
from C B |
|
3341 |
have CSV: "C \<subseteq> span V" by (metis span_inc span_mono subset_trans) |
|
3342 |
from span_mono[OF B(3)] C have SVC: "span V \<subseteq> span C" by (simp add: span_span) |
|
3343 |
from card_le_dim_spanning[OF CSV SVC C(1)] C(2,3) fB |
|
3344 |
have iC: "independent C" by (simp add: dim_span) |
|
3345 |
from C fB have "card C \<le> dim V" by simp |
|
3346 |
moreover have "dim V \<le> card C" using span_card_ge_dim[OF CSV SVC C(1)] |
|
3347 |
by (simp add: dim_span) |
|
33715 | 3348 |
ultimately have CdV: "card C = dim V" using C(1) by simp |
33175 | 3349 |
from C B CSV CdV iC show ?thesis by auto |
3350 |
qed |
|
3351 |
||
3352 |
lemma span_eq: "span S = span T \<longleftrightarrow> S \<subseteq> span T \<and> T \<subseteq> span S" |
|
35541 | 3353 |
using span_inc[unfolded subset_eq] using span_mono[of T "span S"] span_mono[of S "span T"] |
3354 |
by(auto simp add: span_span) |
|
33175 | 3355 |
|
3356 |
(* ------------------------------------------------------------------------- *) |
|
3357 |
(* Low-dimensional subset is in a hyperplane (weak orthogonal complement). *) |
|
3358 |
(* ------------------------------------------------------------------------- *) |
|
3359 |
||
3360 |
lemma span_not_univ_orthogonal: |
|
3361 |
assumes sU: "span S \<noteq> UNIV" |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3362 |
shows "\<exists>(a:: real ^'n). a \<noteq>0 \<and> (\<forall>x \<in> span S. a \<bullet> x = 0)" |
33175 | 3363 |
proof- |
3364 |
from sU obtain a where a: "a \<notin> span S" by blast |
|
3365 |
from orthogonal_basis_exists obtain B where |
|
33715 | 3366 |
B: "independent B" "B \<subseteq> span S" "S \<subseteq> span B" "card B = dim S" "pairwise orthogonal B" |
33175 | 3367 |
by blast |
33715 | 3368 |
from B have fB: "finite B" "card B = dim S" using independent_bound by auto |
33175 | 3369 |
from span_mono[OF B(2)] span_mono[OF B(3)] |
3370 |
have sSB: "span S = span B" by (simp add: span_span) |
|
35542 | 3371 |
let ?a = "a - setsum (\<lambda>b. (a \<bullet> b / (b \<bullet> b)) *s b) B" |
3372 |
have "setsum (\<lambda>b. (a \<bullet> b / (b \<bullet> b)) *s b) B \<in> span S" |
|
33175 | 3373 |
unfolding sSB |
3374 |
apply (rule span_setsum[OF fB(1)]) |
|
3375 |
apply clarsimp |
|
3376 |
apply (rule span_mul) |
|
3377 |
by (rule span_superset) |
|
3378 |
with a have a0:"?a \<noteq> 0" by auto |
|
3379 |
have "\<forall>x\<in>span B. ?a \<bullet> x = 0" |
|
3380 |
proof(rule span_induct') |
|
35542 | 3381 |
show "subspace (\<lambda>x. ?a \<bullet> x = 0)" by (auto simp add: subspace_def mem_def inner_simps smult_conv_scaleR) |
3382 |
||
3383 |
next |
|
33175 | 3384 |
{fix x assume x: "x \<in> B" |
3385 |
from x have B': "B = insert x (B - {x})" by blast |
|
3386 |
have fth: "finite (B - {x})" using fB by simp |
|
3387 |
have "?a \<bullet> x = 0" |
|
3388 |
apply (subst B') using fB fth |
|
3389 |
unfolding setsum_clauses(2)[OF fth] |
|
35542 | 3390 |
apply simp unfolding inner_simps smult_conv_scaleR |
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
3391 |
apply (clarsimp simp add: inner_simps smult_conv_scaleR dot_lsum) |
33175 | 3392 |
apply (rule setsum_0', rule ballI) |
35542 | 3393 |
unfolding inner_commute |
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
3394 |
by (auto simp add: x field_simps intro: B(5)[unfolded pairwise_def orthogonal_def, rule_format])} |
33175 | 3395 |
then show "\<forall>x \<in> B. ?a \<bullet> x = 0" by blast |
3396 |
qed |
|
3397 |
with a0 show ?thesis unfolding sSB by (auto intro: exI[where x="?a"]) |
|
3398 |
qed |
|
3399 |
||
3400 |
lemma span_not_univ_subset_hyperplane: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3401 |
assumes SU: "span S \<noteq> (UNIV ::(real^'n) set)" |
33175 | 3402 |
shows "\<exists> a. a \<noteq>0 \<and> span S \<subseteq> {x. a \<bullet> x = 0}" |
3403 |
using span_not_univ_orthogonal[OF SU] by auto |
|
3404 |
||
3405 |
lemma lowdim_subset_hyperplane: |
|
3406 |
assumes d: "dim S < CARD('n::finite)" |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3407 |
shows "\<exists>(a::real ^'n). a \<noteq> 0 \<and> span S \<subseteq> {x. a \<bullet> x = 0}" |
33175 | 3408 |
proof- |
3409 |
{assume "span S = UNIV" |
|
3410 |
hence "dim (span S) = dim (UNIV :: (real ^'n) set)" by simp |
|
3411 |
hence "dim S = CARD('n)" by (simp add: dim_span dim_univ) |
|
3412 |
with d have False by arith} |
|
3413 |
hence th: "span S \<noteq> UNIV" by blast |
|
3414 |
from span_not_univ_subset_hyperplane[OF th] show ?thesis . |
|
3415 |
qed |
|
3416 |
||
3417 |
(* We can extend a linear basis-basis injection to the whole set. *) |
|
3418 |
||
3419 |
lemma linear_indep_image_lemma: |
|
3420 |
assumes lf: "linear f" and fB: "finite B" |
|
3421 |
and ifB: "independent (f ` B)" |
|
3422 |
and fi: "inj_on f B" and xsB: "x \<in> span B" |
|
34289 | 3423 |
and fx: "f (x::'a::field^_) = 0" |
33175 | 3424 |
shows "x = 0" |
3425 |
using fB ifB fi xsB fx |
|
3426 |
proof(induct arbitrary: x rule: finite_induct[OF fB]) |
|
3427 |
case 1 thus ?case by (auto simp add: span_empty) |
|
3428 |
next |
|
3429 |
case (2 a b x) |
|
3430 |
have fb: "finite b" using "2.prems" by simp |
|
3431 |
have th0: "f ` b \<subseteq> f ` (insert a b)" |
|
3432 |
apply (rule image_mono) by blast |
|
3433 |
from independent_mono[ OF "2.prems"(2) th0] |
|
3434 |
have ifb: "independent (f ` b)" . |
|
3435 |
have fib: "inj_on f b" |
|
3436 |
apply (rule subset_inj_on [OF "2.prems"(3)]) |
|
3437 |
by blast |
|
3438 |
from span_breakdown[of a "insert a b", simplified, OF "2.prems"(4)] |
|
3439 |
obtain k where k: "x - k*s a \<in> span (b -{a})" by blast |
|
3440 |
have "f (x - k*s a) \<in> span (f ` b)" |
|
3441 |
unfolding span_linear_image[OF lf] |
|
3442 |
apply (rule imageI) |
|
3443 |
using k span_mono[of "b-{a}" b] by blast |
|
3444 |
hence "f x - k*s f a \<in> span (f ` b)" |
|
3445 |
by (simp add: linear_sub[OF lf] linear_cmul[OF lf]) |
|
3446 |
hence th: "-k *s f a \<in> span (f ` b)" |
|
3447 |
using "2.prems"(5) by (simp add: vector_smult_lneg) |
|
3448 |
{assume k0: "k = 0" |
|
3449 |
from k0 k have "x \<in> span (b -{a})" by simp |
|
3450 |
then have "x \<in> span b" using span_mono[of "b-{a}" b] |
|
3451 |
by blast} |
|
3452 |
moreover |
|
3453 |
{assume k0: "k \<noteq> 0" |
|
3454 |
from span_mul[OF th, of "- 1/ k"] k0 |
|
3455 |
have th1: "f a \<in> span (f ` b)" |
|
3456 |
by (auto simp add: vector_smult_assoc) |
|
3457 |
from inj_on_image_set_diff[OF "2.prems"(3), of "insert a b " "{a}", symmetric] |
|
3458 |
have tha: "f ` insert a b - f ` {a} = f ` (insert a b - {a})" by blast |
|
3459 |
from "2.prems"(2)[unfolded dependent_def bex_simps(10), rule_format, of "f a"] |
|
3460 |
have "f a \<notin> span (f ` b)" using tha |
|
3461 |
using "2.hyps"(2) |
|
3462 |
"2.prems"(3) by auto |
|
3463 |
with th1 have False by blast |
|
3464 |
then have "x \<in> span b" by blast} |
|
3465 |
ultimately have xsb: "x \<in> span b" by blast |
|
3466 |
from "2.hyps"(3)[OF fb ifb fib xsb "2.prems"(5)] |
|
3467 |
show "x = 0" . |
|
3468 |
qed |
|
3469 |
||
3470 |
(* We can extend a linear mapping from basis. *) |
|
3471 |
||
3472 |
lemma linear_independent_extend_lemma: |
|
3473 |
assumes fi: "finite B" and ib: "independent B" |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3474 |
shows "\<exists>g. (\<forall>x\<in> span B. \<forall>y\<in> span B. g ((x::'a::field^'n) + y) = g x + g y) |
33175 | 3475 |
\<and> (\<forall>x\<in> span B. \<forall>c. g (c*s x) = c *s g x) |
3476 |
\<and> (\<forall>x\<in> B. g x = f x)" |
|
3477 |
using ib fi |
|
3478 |
proof(induct rule: finite_induct[OF fi]) |
|
3479 |
case 1 thus ?case by (auto simp add: span_empty) |
|
3480 |
next |
|
3481 |
case (2 a b) |
|
3482 |
from "2.prems" "2.hyps" have ibf: "independent b" "finite b" |
|
3483 |
by (simp_all add: independent_insert) |
|
3484 |
from "2.hyps"(3)[OF ibf] obtain g where |
|
3485 |
g: "\<forall>x\<in>span b. \<forall>y\<in>span b. g (x + y) = g x + g y" |
|
3486 |
"\<forall>x\<in>span b. \<forall>c. g (c *s x) = c *s g x" "\<forall>x\<in>b. g x = f x" by blast |
|
3487 |
let ?h = "\<lambda>z. SOME k. (z - k *s a) \<in> span b" |
|
3488 |
{fix z assume z: "z \<in> span (insert a b)" |
|
3489 |
have th0: "z - ?h z *s a \<in> span b" |
|
3490 |
apply (rule someI_ex) |
|
3491 |
unfolding span_breakdown_eq[symmetric] |
|
3492 |
using z . |
|
3493 |
{fix k assume k: "z - k *s a \<in> span b" |
|
3494 |
have eq: "z - ?h z *s a - (z - k*s a) = (k - ?h z) *s a" |
|
36350 | 3495 |
by (simp add: field_simps vector_sadd_rdistrib[symmetric]) |
33175 | 3496 |
from span_sub[OF th0 k] |
3497 |
have khz: "(k - ?h z) *s a \<in> span b" by (simp add: eq) |
|
3498 |
{assume "k \<noteq> ?h z" hence k0: "k - ?h z \<noteq> 0" by simp |
|
3499 |
from k0 span_mul[OF khz, of "1 /(k - ?h z)"] |
|
3500 |
have "a \<in> span b" by (simp add: vector_smult_assoc) |
|
3501 |
with "2.prems"(1) "2.hyps"(2) have False |
|
3502 |
by (auto simp add: dependent_def)} |
|
3503 |
then have "k = ?h z" by blast} |
|
3504 |
with th0 have "z - ?h z *s a \<in> span b \<and> (\<forall>k. z - k *s a \<in> span b \<longrightarrow> k = ?h z)" by blast} |
|
3505 |
note h = this |
|
3506 |
let ?g = "\<lambda>z. ?h z *s f a + g (z - ?h z *s a)" |
|
3507 |
{fix x y assume x: "x \<in> span (insert a b)" and y: "y \<in> span (insert a b)" |
|
3508 |
have tha: "\<And>(x::'a^'n) y a k l. (x + y) - (k + l) *s a = (x - k *s a) + (y - l *s a)" |
|
36350 | 3509 |
by (vector field_simps) |
33175 | 3510 |
have addh: "?h (x + y) = ?h x + ?h y" |
3511 |
apply (rule conjunct2[OF h, rule_format, symmetric]) |
|
3512 |
apply (rule span_add[OF x y]) |
|
3513 |
unfolding tha |
|
3514 |
by (metis span_add x y conjunct1[OF h, rule_format]) |
|
3515 |
have "?g (x + y) = ?g x + ?g y" |
|
3516 |
unfolding addh tha |
|
3517 |
g(1)[rule_format,OF conjunct1[OF h, OF x] conjunct1[OF h, OF y]] |
|
3518 |
by (simp add: vector_sadd_rdistrib)} |
|
3519 |
moreover |
|
3520 |
{fix x:: "'a^'n" and c:: 'a assume x: "x \<in> span (insert a b)" |
|
3521 |
have tha: "\<And>(x::'a^'n) c k a. c *s x - (c * k) *s a = c *s (x - k *s a)" |
|
36350 | 3522 |
by (vector field_simps) |
33175 | 3523 |
have hc: "?h (c *s x) = c * ?h x" |
3524 |
apply (rule conjunct2[OF h, rule_format, symmetric]) |
|
3525 |
apply (metis span_mul x) |
|
3526 |
by (metis tha span_mul x conjunct1[OF h]) |
|
3527 |
have "?g (c *s x) = c*s ?g x" |
|
3528 |
unfolding hc tha g(2)[rule_format, OF conjunct1[OF h, OF x]] |
|
36350 | 3529 |
by (vector field_simps)} |
33175 | 3530 |
moreover |
3531 |
{fix x assume x: "x \<in> (insert a b)" |
|
3532 |
{assume xa: "x = a" |
|
3533 |
have ha1: "1 = ?h a" |
|
3534 |
apply (rule conjunct2[OF h, rule_format]) |
|
3535 |
apply (metis span_superset insertI1) |
|
3536 |
using conjunct1[OF h, OF span_superset, OF insertI1] |
|
3537 |
by (auto simp add: span_0) |
|
3538 |
||
3539 |
from xa ha1[symmetric] have "?g x = f x" |
|
3540 |
apply simp |
|
3541 |
using g(2)[rule_format, OF span_0, of 0] |
|
3542 |
by simp} |
|
3543 |
moreover |
|
3544 |
{assume xb: "x \<in> b" |
|
3545 |
have h0: "0 = ?h x" |
|
3546 |
apply (rule conjunct2[OF h, rule_format]) |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
3547 |
apply (metis span_superset x) |
33175 | 3548 |
apply simp |
3549 |
apply (metis span_superset xb) |
|
3550 |
done |
|
3551 |
have "?g x = f x" |
|
3552 |
by (simp add: h0[symmetric] g(3)[rule_format, OF xb])} |
|
3553 |
ultimately have "?g x = f x" using x by blast } |
|
3554 |
ultimately show ?case apply - apply (rule exI[where x="?g"]) by blast |
|
3555 |
qed |
|
3556 |
||
3557 |
lemma linear_independent_extend: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3558 |
assumes iB: "independent (B:: (real ^'n) set)" |
33175 | 3559 |
shows "\<exists>g. linear g \<and> (\<forall>x\<in>B. g x = f x)" |
3560 |
proof- |
|
3561 |
from maximal_independent_subset_extend[of B UNIV] iB |
|
3562 |
obtain C where C: "B \<subseteq> C" "independent C" "\<And>x. x \<in> span C" by auto |
|
3563 |
||
3564 |
from C(2) independent_bound[of C] linear_independent_extend_lemma[of C f] |
|
3565 |
obtain g where g: "(\<forall>x\<in> span C. \<forall>y\<in> span C. g (x + y) = g x + g y) |
|
3566 |
\<and> (\<forall>x\<in> span C. \<forall>c. g (c*s x) = c *s g x) |
|
3567 |
\<and> (\<forall>x\<in> C. g x = f x)" by blast |
|
3568 |
from g show ?thesis unfolding linear_def using C |
|
3569 |
apply clarsimp by blast |
|
3570 |
qed |
|
3571 |
||
3572 |
(* Can construct an isomorphism between spaces of same dimension. *) |
|
3573 |
||
3574 |
lemma card_le_inj: assumes fA: "finite A" and fB: "finite B" |
|
3575 |
and c: "card A \<le> card B" shows "(\<exists>f. f ` A \<subseteq> B \<and> inj_on f A)" |
|
3576 |
using fB c |
|
3577 |
proof(induct arbitrary: B rule: finite_induct[OF fA]) |
|
3578 |
case 1 thus ?case by simp |
|
3579 |
next |
|
3580 |
case (2 x s t) |
|
3581 |
thus ?case |
|
3582 |
proof(induct rule: finite_induct[OF "2.prems"(1)]) |
|
3583 |
case 1 then show ?case by simp |
|
3584 |
next |
|
3585 |
case (2 y t) |
|
3586 |
from "2.prems"(1,2,5) "2.hyps"(1,2) have cst:"card s \<le> card t" by simp |
|
3587 |
from "2.prems"(3) [OF "2.hyps"(1) cst] obtain f where |
|
3588 |
f: "f ` s \<subseteq> t \<and> inj_on f s" by blast |
|
3589 |
from f "2.prems"(2) "2.hyps"(2) show ?case |
|
3590 |
apply - |
|
3591 |
apply (rule exI[where x = "\<lambda>z. if z = x then y else f z"]) |
|
3592 |
by (auto simp add: inj_on_def) |
|
3593 |
qed |
|
3594 |
qed |
|
3595 |
||
3596 |
lemma card_subset_eq: assumes fB: "finite B" and AB: "A \<subseteq> B" and |
|
3597 |
c: "card A = card B" |
|
3598 |
shows "A = B" |
|
3599 |
proof- |
|
3600 |
from fB AB have fA: "finite A" by (auto intro: finite_subset) |
|
3601 |
from fA fB have fBA: "finite (B - A)" by auto |
|
3602 |
have e: "A \<inter> (B - A) = {}" by blast |
|
3603 |
have eq: "A \<union> (B - A) = B" using AB by blast |
|
3604 |
from card_Un_disjoint[OF fA fBA e, unfolded eq c] |
|
3605 |
have "card (B - A) = 0" by arith |
|
3606 |
hence "B - A = {}" unfolding card_eq_0_iff using fA fB by simp |
|
3607 |
with AB show "A = B" by blast |
|
3608 |
qed |
|
3609 |
||
3610 |
lemma subspace_isomorphism: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3611 |
assumes s: "subspace (S:: (real ^'n) set)" |
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3612 |
and t: "subspace (T :: (real ^'m) set)" |
33175 | 3613 |
and d: "dim S = dim T" |
3614 |
shows "\<exists>f. linear f \<and> f ` S = T \<and> inj_on f S" |
|
3615 |
proof- |
|
33715 | 3616 |
from basis_exists[of S] independent_bound obtain B where |
3617 |
B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S" and fB: "finite B" by blast |
|
3618 |
from basis_exists[of T] independent_bound obtain C where |
|
3619 |
C: "C \<subseteq> T" "independent C" "T \<subseteq> span C" "card C = dim T" and fC: "finite C" by blast |
|
33175 | 3620 |
from B(4) C(4) card_le_inj[of B C] d obtain f where |
33715 | 3621 |
f: "f ` B \<subseteq> C" "inj_on f B" using `finite B` `finite C` by auto |
33175 | 3622 |
from linear_independent_extend[OF B(2)] obtain g where |
3623 |
g: "linear g" "\<forall>x\<in> B. g x = f x" by blast |
|
3624 |
from inj_on_iff_eq_card[OF fB, of f] f(2) |
|
3625 |
have "card (f ` B) = card B" by simp |
|
3626 |
with B(4) C(4) have ceq: "card (f ` B) = card C" using d |
|
33715 | 3627 |
by simp |
33175 | 3628 |
have "g ` B = f ` B" using g(2) |
3629 |
by (auto simp add: image_iff) |
|
3630 |
also have "\<dots> = C" using card_subset_eq[OF fC f(1) ceq] . |
|
3631 |
finally have gBC: "g ` B = C" . |
|
3632 |
have gi: "inj_on g B" using f(2) g(2) |
|
3633 |
by (auto simp add: inj_on_def) |
|
3634 |
note g0 = linear_indep_image_lemma[OF g(1) fB, unfolded gBC, OF C(2) gi] |
|
3635 |
{fix x y assume x: "x \<in> S" and y: "y \<in> S" and gxy:"g x = g y" |
|
3636 |
from B(3) x y have x': "x \<in> span B" and y': "y \<in> span B" by blast+ |
|
3637 |
from gxy have th0: "g (x - y) = 0" by (simp add: linear_sub[OF g(1)]) |
|
3638 |
have th1: "x - y \<in> span B" using x' y' by (metis span_sub) |
|
3639 |
have "x=y" using g0[OF th1 th0] by simp } |
|
3640 |
then have giS: "inj_on g S" |
|
3641 |
unfolding inj_on_def by blast |
|
3642 |
from span_subspace[OF B(1,3) s] |
|
3643 |
have "g ` S = span (g ` B)" by (simp add: span_linear_image[OF g(1)]) |
|
3644 |
also have "\<dots> = span C" unfolding gBC .. |
|
3645 |
also have "\<dots> = T" using span_subspace[OF C(1,3) t] . |
|
3646 |
finally have gS: "g ` S = T" . |
|
3647 |
from g(1) gS giS show ?thesis by blast |
|
3648 |
qed |
|
3649 |
||
3650 |
(* linear functions are equal on a subspace if they are on a spanning set. *) |
|
3651 |
||
3652 |
lemma subspace_kernel: |
|
34289 | 3653 |
assumes lf: "linear (f::'a::semiring_1 ^_ \<Rightarrow> _)" |
33175 | 3654 |
shows "subspace {x. f x = 0}" |
3655 |
apply (simp add: subspace_def) |
|
3656 |
by (simp add: linear_add[OF lf] linear_cmul[OF lf] linear_0[OF lf]) |
|
3657 |
||
3658 |
lemma linear_eq_0_span: |
|
3659 |
assumes lf: "linear f" and f0: "\<forall>x\<in>B. f x = 0" |
|
34289 | 3660 |
shows "\<forall>x \<in> span B. f x = (0::'a::semiring_1 ^_)" |
33175 | 3661 |
proof |
3662 |
fix x assume x: "x \<in> span B" |
|
3663 |
let ?P = "\<lambda>x. f x = 0" |
|
3664 |
from subspace_kernel[OF lf] have "subspace ?P" unfolding Collect_def . |
|
3665 |
with x f0 span_induct[of B "?P" x] show "f x = 0" by blast |
|
3666 |
qed |
|
3667 |
||
3668 |
lemma linear_eq_0: |
|
3669 |
assumes lf: "linear f" and SB: "S \<subseteq> span B" and f0: "\<forall>x\<in>B. f x = 0" |
|
34289 | 3670 |
shows "\<forall>x \<in> S. f x = (0::'a::semiring_1^_)" |
33175 | 3671 |
by (metis linear_eq_0_span[OF lf] subset_eq SB f0) |
3672 |
||
3673 |
lemma linear_eq: |
|
34289 | 3674 |
assumes lf: "linear (f::'a::ring_1^_ \<Rightarrow> _)" and lg: "linear g" and S: "S \<subseteq> span B" |
33175 | 3675 |
and fg: "\<forall> x\<in> B. f x = g x" |
3676 |
shows "\<forall>x\<in> S. f x = g x" |
|
3677 |
proof- |
|
3678 |
let ?h = "\<lambda>x. f x - g x" |
|
3679 |
from fg have fg': "\<forall>x\<in> B. ?h x = 0" by simp |
|
3680 |
from linear_eq_0[OF linear_compose_sub[OF lf lg] S fg'] |
|
3681 |
show ?thesis by simp |
|
3682 |
qed |
|
3683 |
||
3684 |
lemma linear_eq_stdbasis: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3685 |
assumes lf: "linear (f::'a::ring_1^'m \<Rightarrow> 'a^'n)" and lg: "linear g" |
33175 | 3686 |
and fg: "\<forall>i. f (basis i) = g(basis i)" |
3687 |
shows "f = g" |
|
3688 |
proof- |
|
3689 |
let ?U = "UNIV :: 'm set" |
|
3690 |
let ?I = "{basis i:: 'a^'m|i. i \<in> ?U}" |
|
3691 |
{fix x assume x: "x \<in> (UNIV :: ('a^'m) set)" |
|
3692 |
from equalityD2[OF span_stdbasis] |
|
3693 |
have IU: " (UNIV :: ('a^'m) set) \<subseteq> span ?I" by blast |
|
3694 |
from linear_eq[OF lf lg IU] fg x |
|
3695 |
have "f x = g x" unfolding Collect_def Ball_def mem_def by metis} |
|
3696 |
then show ?thesis by (auto intro: ext) |
|
3697 |
qed |
|
3698 |
||
3699 |
(* Similar results for bilinear functions. *) |
|
3700 |
||
3701 |
lemma bilinear_eq: |
|
34289 | 3702 |
assumes bf: "bilinear (f:: 'a::ring^_ \<Rightarrow> 'a^_ \<Rightarrow> 'a^_)" |
33175 | 3703 |
and bg: "bilinear g" |
3704 |
and SB: "S \<subseteq> span B" and TC: "T \<subseteq> span C" |
|
3705 |
and fg: "\<forall>x\<in> B. \<forall>y\<in> C. f x y = g x y" |
|
3706 |
shows "\<forall>x\<in>S. \<forall>y\<in>T. f x y = g x y " |
|
3707 |
proof- |
|
3708 |
let ?P = "\<lambda>x. \<forall>y\<in> span C. f x y = g x y" |
|
3709 |
from bf bg have sp: "subspace ?P" |
|
3710 |
unfolding bilinear_def linear_def subspace_def bf bg |
|
3711 |
by(auto simp add: span_0 mem_def bilinear_lzero[OF bf] bilinear_lzero[OF bg] span_add Ball_def intro: bilinear_ladd[OF bf]) |
|
3712 |
||
3713 |
have "\<forall>x \<in> span B. \<forall>y\<in> span C. f x y = g x y" |
|
3714 |
apply - |
|
3715 |
apply (rule ballI) |
|
3716 |
apply (rule span_induct[of B ?P]) |
|
3717 |
defer |
|
3718 |
apply (rule sp) |
|
3719 |
apply assumption |
|
3720 |
apply (clarsimp simp add: Ball_def) |
|
3721 |
apply (rule_tac P="\<lambda>y. f xa y = g xa y" and S=C in span_induct) |
|
3722 |
using fg |
|
3723 |
apply (auto simp add: subspace_def) |
|
3724 |
using bf bg unfolding bilinear_def linear_def |
|
3725 |
by(auto simp add: span_0 mem_def bilinear_rzero[OF bf] bilinear_rzero[OF bg] span_add Ball_def intro: bilinear_ladd[OF bf]) |
|
3726 |
then show ?thesis using SB TC by (auto intro: ext) |
|
3727 |
qed |
|
3728 |
||
3729 |
lemma bilinear_eq_stdbasis: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3730 |
assumes bf: "bilinear (f:: 'a::ring_1^'m \<Rightarrow> 'a^'n \<Rightarrow> 'a^_)" |
33175 | 3731 |
and bg: "bilinear g" |
3732 |
and fg: "\<forall>i j. f (basis i) (basis j) = g (basis i) (basis j)" |
|
3733 |
shows "f = g" |
|
3734 |
proof- |
|
3735 |
from fg have th: "\<forall>x \<in> {basis i| i. i\<in> (UNIV :: 'm set)}. \<forall>y\<in> {basis j |j. j \<in> (UNIV :: 'n set)}. f x y = g x y" by blast |
|
3736 |
from bilinear_eq[OF bf bg equalityD2[OF span_stdbasis] equalityD2[OF span_stdbasis] th] show ?thesis by (blast intro: ext) |
|
3737 |
qed |
|
3738 |
||
3739 |
(* Detailed theorems about left and right invertibility in general case. *) |
|
3740 |
||
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
3741 |
lemma left_invertible_transpose: |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
3742 |
"(\<exists>(B). B ** transpose (A) = mat (1::'a::comm_semiring_1)) \<longleftrightarrow> (\<exists>(B). A ** B = mat 1)" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
3743 |
by (metis matrix_transpose_mul transpose_mat transpose_transpose) |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
3744 |
|
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
3745 |
lemma right_invertible_transpose: |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
3746 |
"(\<exists>(B). transpose (A) ** B = mat (1::'a::comm_semiring_1)) \<longleftrightarrow> (\<exists>(B). B ** A = mat 1)" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
3747 |
by (metis matrix_transpose_mul transpose_mat transpose_transpose) |
33175 | 3748 |
|
3749 |
lemma linear_injective_left_inverse: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3750 |
assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'m)" and fi: "inj f" |
33175 | 3751 |
shows "\<exists>g. linear g \<and> g o f = id" |
3752 |
proof- |
|
3753 |
from linear_independent_extend[OF independent_injective_image, OF independent_stdbasis, OF lf fi] |
|
3754 |
obtain h:: "real ^'m \<Rightarrow> real ^'n" where h: "linear h" " \<forall>x \<in> f ` {basis i|i. i \<in> (UNIV::'n set)}. h x = inv f x" by blast |
|
3755 |
from h(2) |
|
3756 |
have th: "\<forall>i. (h \<circ> f) (basis i) = id (basis i)" |
|
3757 |
using inv_o_cancel[OF fi, unfolded stupid_ext[symmetric] id_def o_def] |
|
3758 |
by auto |
|
3759 |
||
3760 |
from linear_eq_stdbasis[OF linear_compose[OF lf h(1)] linear_id th] |
|
3761 |
have "h o f = id" . |
|
3762 |
then show ?thesis using h(1) by blast |
|
3763 |
qed |
|
3764 |
||
3765 |
lemma linear_surjective_right_inverse: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3766 |
assumes lf: "linear (f:: real ^'m \<Rightarrow> real ^'n)" and sf: "surj f" |
33175 | 3767 |
shows "\<exists>g. linear g \<and> f o g = id" |
3768 |
proof- |
|
3769 |
from linear_independent_extend[OF independent_stdbasis] |
|
3770 |
obtain h:: "real ^'n \<Rightarrow> real ^'m" where |
|
3771 |
h: "linear h" "\<forall> x\<in> {basis i| i. i\<in> (UNIV :: 'n set)}. h x = inv f x" by blast |
|
3772 |
from h(2) |
|
3773 |
have th: "\<forall>i. (f o h) (basis i) = id (basis i)" |
|
3774 |
using sf |
|
3775 |
apply (auto simp add: surj_iff o_def stupid_ext[symmetric]) |
|
3776 |
apply (erule_tac x="basis i" in allE) |
|
3777 |
by auto |
|
3778 |
||
3779 |
from linear_eq_stdbasis[OF linear_compose[OF h(1) lf] linear_id th] |
|
3780 |
have "f o h = id" . |
|
3781 |
then show ?thesis using h(1) by blast |
|
3782 |
qed |
|
3783 |
||
3784 |
lemma matrix_left_invertible_injective: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3785 |
"(\<exists>B. (B::real^'m^'n) ** (A::real^'n^'m) = mat 1) \<longleftrightarrow> (\<forall>x y. A *v x = A *v y \<longrightarrow> x = y)" |
33175 | 3786 |
proof- |
3787 |
{fix B:: "real^'m^'n" and x y assume B: "B ** A = mat 1" and xy: "A *v x = A*v y" |
|
3788 |
from xy have "B*v (A *v x) = B *v (A*v y)" by simp |
|
3789 |
hence "x = y" |
|
3790 |
unfolding matrix_vector_mul_assoc B matrix_vector_mul_lid .} |
|
3791 |
moreover |
|
3792 |
{assume A: "\<forall>x y. A *v x = A *v y \<longrightarrow> x = y" |
|
3793 |
hence i: "inj (op *v A)" unfolding inj_on_def by auto |
|
3794 |
from linear_injective_left_inverse[OF matrix_vector_mul_linear i] |
|
3795 |
obtain g where g: "linear g" "g o op *v A = id" by blast |
|
3796 |
have "matrix g ** A = mat 1" |
|
3797 |
unfolding matrix_eq matrix_vector_mul_lid matrix_vector_mul_assoc[symmetric] matrix_works[OF g(1)] |
|
3798 |
using g(2) by (simp add: o_def id_def stupid_ext) |
|
3799 |
then have "\<exists>B. (B::real ^'m^'n) ** A = mat 1" by blast} |
|
3800 |
ultimately show ?thesis by blast |
|
3801 |
qed |
|
3802 |
||
3803 |
lemma matrix_left_invertible_ker: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3804 |
"(\<exists>B. (B::real ^'m^'n) ** (A::real^'n^'m) = mat 1) \<longleftrightarrow> (\<forall>x. A *v x = 0 \<longrightarrow> x = 0)" |
33175 | 3805 |
unfolding matrix_left_invertible_injective |
3806 |
using linear_injective_0[OF matrix_vector_mul_linear, of A] |
|
3807 |
by (simp add: inj_on_def) |
|
3808 |
||
3809 |
lemma matrix_right_invertible_surjective: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3810 |
"(\<exists>B. (A::real^'n^'m) ** (B::real^'m^'n) = mat 1) \<longleftrightarrow> surj (\<lambda>x. A *v x)" |
33175 | 3811 |
proof- |
3812 |
{fix B :: "real ^'m^'n" assume AB: "A ** B = mat 1" |
|
3813 |
{fix x :: "real ^ 'm" |
|
3814 |
have "A *v (B *v x) = x" |
|
3815 |
by (simp add: matrix_vector_mul_lid matrix_vector_mul_assoc AB)} |
|
3816 |
hence "surj (op *v A)" unfolding surj_def by metis } |
|
3817 |
moreover |
|
3818 |
{assume sf: "surj (op *v A)" |
|
3819 |
from linear_surjective_right_inverse[OF matrix_vector_mul_linear sf] |
|
3820 |
obtain g:: "real ^'m \<Rightarrow> real ^'n" where g: "linear g" "op *v A o g = id" |
|
3821 |
by blast |
|
3822 |
||
3823 |
have "A ** (matrix g) = mat 1" |
|
3824 |
unfolding matrix_eq matrix_vector_mul_lid |
|
3825 |
matrix_vector_mul_assoc[symmetric] matrix_works[OF g(1)] |
|
3826 |
using g(2) unfolding o_def stupid_ext[symmetric] id_def |
|
3827 |
. |
|
3828 |
hence "\<exists>B. A ** (B::real^'m^'n) = mat 1" by blast |
|
3829 |
} |
|
3830 |
ultimately show ?thesis unfolding surj_def by blast |
|
3831 |
qed |
|
3832 |
||
3833 |
lemma matrix_left_invertible_independent_columns: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3834 |
fixes A :: "real^'n^'m" |
33175 | 3835 |
shows "(\<exists>(B::real ^'m^'n). B ** A = mat 1) \<longleftrightarrow> (\<forall>c. setsum (\<lambda>i. c i *s column i A) (UNIV :: 'n set) = 0 \<longrightarrow> (\<forall>i. c i = 0))" |
3836 |
(is "?lhs \<longleftrightarrow> ?rhs") |
|
3837 |
proof- |
|
3838 |
let ?U = "UNIV :: 'n set" |
|
3839 |
{assume k: "\<forall>x. A *v x = 0 \<longrightarrow> x = 0" |
|
3840 |
{fix c i assume c: "setsum (\<lambda>i. c i *s column i A) ?U = 0" |
|
3841 |
and i: "i \<in> ?U" |
|
3842 |
let ?x = "\<chi> i. c i" |
|
3843 |
have th0:"A *v ?x = 0" |
|
3844 |
using c |
|
3845 |
unfolding matrix_mult_vsum Cart_eq |
|
3846 |
by auto |
|
3847 |
from k[rule_format, OF th0] i |
|
3848 |
have "c i = 0" by (vector Cart_eq)} |
|
3849 |
hence ?rhs by blast} |
|
3850 |
moreover |
|
3851 |
{assume H: ?rhs |
|
3852 |
{fix x assume x: "A *v x = 0" |
|
3853 |
let ?c = "\<lambda>i. ((x$i ):: real)" |
|
3854 |
from H[rule_format, of ?c, unfolded matrix_mult_vsum[symmetric], OF x] |
|
3855 |
have "x = 0" by vector}} |
|
3856 |
ultimately show ?thesis unfolding matrix_left_invertible_ker by blast |
|
3857 |
qed |
|
3858 |
||
3859 |
lemma matrix_right_invertible_independent_rows: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3860 |
fixes A :: "real^'n^'m" |
33175 | 3861 |
shows "(\<exists>(B::real^'m^'n). A ** B = mat 1) \<longleftrightarrow> (\<forall>c. setsum (\<lambda>i. c i *s row i A) (UNIV :: 'm set) = 0 \<longrightarrow> (\<forall>i. c i = 0))" |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
3862 |
unfolding left_invertible_transpose[symmetric] |
33175 | 3863 |
matrix_left_invertible_independent_columns |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
3864 |
by (simp add: column_transpose) |
33175 | 3865 |
|
3866 |
lemma matrix_right_invertible_span_columns: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3867 |
"(\<exists>(B::real ^'n^'m). (A::real ^'m^'n) ** B = mat 1) \<longleftrightarrow> span (columns A) = UNIV" (is "?lhs = ?rhs") |
33175 | 3868 |
proof- |
3869 |
let ?U = "UNIV :: 'm set" |
|
3870 |
have fU: "finite ?U" by simp |
|
3871 |
have lhseq: "?lhs \<longleftrightarrow> (\<forall>y. \<exists>(x::real^'m). setsum (\<lambda>i. (x$i) *s column i A) ?U = y)" |
|
3872 |
unfolding matrix_right_invertible_surjective matrix_mult_vsum surj_def |
|
3873 |
apply (subst eq_commute) .. |
|
3874 |
have rhseq: "?rhs \<longleftrightarrow> (\<forall>x. x \<in> span (columns A))" by blast |
|
3875 |
{assume h: ?lhs |
|
3876 |
{fix x:: "real ^'n" |
|
3877 |
from h[unfolded lhseq, rule_format, of x] obtain y:: "real ^'m" |
|
3878 |
where y: "setsum (\<lambda>i. (y$i) *s column i A) ?U = x" by blast |
|
3879 |
have "x \<in> span (columns A)" |
|
3880 |
unfolding y[symmetric] |
|
3881 |
apply (rule span_setsum[OF fU]) |
|
3882 |
apply clarify |
|
3883 |
apply (rule span_mul) |
|
3884 |
apply (rule span_superset) |
|
3885 |
unfolding columns_def |
|
3886 |
by blast} |
|
3887 |
then have ?rhs unfolding rhseq by blast} |
|
3888 |
moreover |
|
3889 |
{assume h:?rhs |
|
3890 |
let ?P = "\<lambda>(y::real ^'n). \<exists>(x::real^'m). setsum (\<lambda>i. (x$i) *s column i A) ?U = y" |
|
3891 |
{fix y have "?P y" |
|
3892 |
proof(rule span_induct_alt[of ?P "columns A"]) |
|
3893 |
show "\<exists>x\<Colon>real ^ 'm. setsum (\<lambda>i. (x$i) *s column i A) ?U = 0" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
3894 |
by (rule exI[where x=0], simp) |
33175 | 3895 |
next |
3896 |
fix c y1 y2 assume y1: "y1 \<in> columns A" and y2: "?P y2" |
|
3897 |
from y1 obtain i where i: "i \<in> ?U" "y1 = column i A" |
|
3898 |
unfolding columns_def by blast |
|
3899 |
from y2 obtain x:: "real ^'m" where |
|
3900 |
x: "setsum (\<lambda>i. (x$i) *s column i A) ?U = y2" by blast |
|
3901 |
let ?x = "(\<chi> j. if j = i then c + (x$i) else (x$j))::real^'m" |
|
3902 |
show "?P (c*s y1 + y2)" |
|
3903 |
proof(rule exI[where x= "?x"], vector, auto simp add: i x[symmetric] cond_value_iff right_distrib cond_application_beta cong del: if_weak_cong) |
|
3904 |
fix j |
|
3905 |
have th: "\<forall>xa \<in> ?U. (if xa = i then (c + (x$i)) * ((column xa A)$j) |
|
3906 |
else (x$xa) * ((column xa A$j))) = (if xa = i then c * ((column i A)$j) else 0) + ((x$xa) * ((column xa A)$j))" using i(1) |
|
36350 | 3907 |
by (simp add: field_simps) |
33175 | 3908 |
have "setsum (\<lambda>xa. if xa = i then (c + (x$i)) * ((column xa A)$j) |
3909 |
else (x$xa) * ((column xa A$j))) ?U = setsum (\<lambda>xa. (if xa = i then c * ((column i A)$j) else 0) + ((x$xa) * ((column xa A)$j))) ?U" |
|
3910 |
apply (rule setsum_cong[OF refl]) |
|
3911 |
using th by blast |
|
3912 |
also have "\<dots> = setsum (\<lambda>xa. if xa = i then c * ((column i A)$j) else 0) ?U + setsum (\<lambda>xa. ((x$xa) * ((column xa A)$j))) ?U" |
|
3913 |
by (simp add: setsum_addf) |
|
3914 |
also have "\<dots> = c * ((column i A)$j) + setsum (\<lambda>xa. ((x$xa) * ((column xa A)$j))) ?U" |
|
3915 |
unfolding setsum_delta[OF fU] |
|
3916 |
using i(1) by simp |
|
3917 |
finally show "setsum (\<lambda>xa. if xa = i then (c + (x$i)) * ((column xa A)$j) |
|
3918 |
else (x$xa) * ((column xa A$j))) ?U = c * ((column i A)$j) + setsum (\<lambda>xa. ((x$xa) * ((column xa A)$j))) ?U" . |
|
3919 |
qed |
|
3920 |
next |
|
3921 |
show "y \<in> span (columns A)" unfolding h by blast |
|
3922 |
qed} |
|
3923 |
then have ?lhs unfolding lhseq ..} |
|
3924 |
ultimately show ?thesis by blast |
|
3925 |
qed |
|
3926 |
||
3927 |
lemma matrix_left_invertible_span_rows: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3928 |
"(\<exists>(B::real^'m^'n). B ** (A::real^'n^'m) = mat 1) \<longleftrightarrow> span (rows A) = UNIV" |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
3929 |
unfolding right_invertible_transpose[symmetric] |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
3930 |
unfolding columns_transpose[symmetric] |
33175 | 3931 |
unfolding matrix_right_invertible_span_columns |
3932 |
.. |
|
3933 |
||
3934 |
(* An injective map real^'n->real^'n is also surjective. *) |
|
3935 |
||
3936 |
lemma linear_injective_imp_surjective: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3937 |
assumes lf: "linear (f:: real ^'n \<Rightarrow> real ^'n)" and fi: "inj f" |
33175 | 3938 |
shows "surj f" |
3939 |
proof- |
|
3940 |
let ?U = "UNIV :: (real ^'n) set" |
|
3941 |
from basis_exists[of ?U] obtain B |
|
33715 | 3942 |
where B: "B \<subseteq> ?U" "independent B" "?U \<subseteq> span B" "card B = dim ?U" |
33175 | 3943 |
by blast |
33715 | 3944 |
from B(4) have d: "dim ?U = card B" by simp |
33175 | 3945 |
have th: "?U \<subseteq> span (f ` B)" |
3946 |
apply (rule card_ge_dim_independent) |
|
3947 |
apply blast |
|
3948 |
apply (rule independent_injective_image[OF B(2) lf fi]) |
|
3949 |
apply (rule order_eq_refl) |
|
3950 |
apply (rule sym) |
|
3951 |
unfolding d |
|
3952 |
apply (rule card_image) |
|
3953 |
apply (rule subset_inj_on[OF fi]) |
|
3954 |
by blast |
|
3955 |
from th show ?thesis |
|
3956 |
unfolding span_linear_image[OF lf] surj_def |
|
3957 |
using B(3) by blast |
|
3958 |
qed |
|
3959 |
||
3960 |
(* And vice versa. *) |
|
3961 |
||
3962 |
lemma surjective_iff_injective_gen: |
|
3963 |
assumes fS: "finite S" and fT: "finite T" and c: "card S = card T" |
|
3964 |
and ST: "f ` S \<subseteq> T" |
|
3965 |
shows "(\<forall>y \<in> T. \<exists>x \<in> S. f x = y) \<longleftrightarrow> inj_on f S" (is "?lhs \<longleftrightarrow> ?rhs") |
|
3966 |
proof- |
|
3967 |
{assume h: "?lhs" |
|
3968 |
{fix x y assume x: "x \<in> S" and y: "y \<in> S" and f: "f x = f y" |
|
3969 |
from x fS have S0: "card S \<noteq> 0" by auto |
|
3970 |
{assume xy: "x \<noteq> y" |
|
3971 |
have th: "card S \<le> card (f ` (S - {y}))" |
|
3972 |
unfolding c |
|
3973 |
apply (rule card_mono) |
|
3974 |
apply (rule finite_imageI) |
|
3975 |
using fS apply simp |
|
3976 |
using h xy x y f unfolding subset_eq image_iff |
|
3977 |
apply auto |
|
3978 |
apply (case_tac "xa = f x") |
|
3979 |
apply (rule bexI[where x=x]) |
|
3980 |
apply auto |
|
3981 |
done |
|
3982 |
also have " \<dots> \<le> card (S -{y})" |
|
3983 |
apply (rule card_image_le) |
|
3984 |
using fS by simp |
|
3985 |
also have "\<dots> \<le> card S - 1" using y fS by simp |
|
3986 |
finally have False using S0 by arith } |
|
3987 |
then have "x = y" by blast} |
|
3988 |
then have ?rhs unfolding inj_on_def by blast} |
|
3989 |
moreover |
|
3990 |
{assume h: ?rhs |
|
3991 |
have "f ` S = T" |
|
3992 |
apply (rule card_subset_eq[OF fT ST]) |
|
3993 |
unfolding card_image[OF h] using c . |
|
3994 |
then have ?lhs by blast} |
|
3995 |
ultimately show ?thesis by blast |
|
3996 |
qed |
|
3997 |
||
3998 |
lemma linear_surjective_imp_injective: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
3999 |
assumes lf: "linear (f::real ^'n => real ^'n)" and sf: "surj f" |
33175 | 4000 |
shows "inj f" |
4001 |
proof- |
|
4002 |
let ?U = "UNIV :: (real ^'n) set" |
|
4003 |
from basis_exists[of ?U] obtain B |
|
33715 | 4004 |
where B: "B \<subseteq> ?U" "independent B" "?U \<subseteq> span B" and d: "card B = dim ?U" |
33175 | 4005 |
by blast |
4006 |
{fix x assume x: "x \<in> span B" and fx: "f x = 0" |
|
33715 | 4007 |
from B(2) have fB: "finite B" using independent_bound by auto |
33175 | 4008 |
have fBi: "independent (f ` B)" |
4009 |
apply (rule card_le_dim_spanning[of "f ` B" ?U]) |
|
4010 |
apply blast |
|
4011 |
using sf B(3) |
|
4012 |
unfolding span_linear_image[OF lf] surj_def subset_eq image_iff |
|
4013 |
apply blast |
|
4014 |
using fB apply (blast intro: finite_imageI) |
|
33715 | 4015 |
unfolding d[symmetric] |
33175 | 4016 |
apply (rule card_image_le) |
4017 |
apply (rule fB) |
|
4018 |
done |
|
4019 |
have th0: "dim ?U \<le> card (f ` B)" |
|
4020 |
apply (rule span_card_ge_dim) |
|
4021 |
apply blast |
|
4022 |
unfolding span_linear_image[OF lf] |
|
4023 |
apply (rule subset_trans[where B = "f ` UNIV"]) |
|
4024 |
using sf unfolding surj_def apply blast |
|
4025 |
apply (rule image_mono) |
|
4026 |
apply (rule B(3)) |
|
4027 |
apply (metis finite_imageI fB) |
|
4028 |
done |
|
4029 |
||
4030 |
moreover have "card (f ` B) \<le> card B" |
|
4031 |
by (rule card_image_le, rule fB) |
|
4032 |
ultimately have th1: "card B = card (f ` B)" unfolding d by arith |
|
4033 |
have fiB: "inj_on f B" |
|
4034 |
unfolding surjective_iff_injective_gen[OF fB finite_imageI[OF fB] th1 subset_refl, symmetric] by blast |
|
4035 |
from linear_indep_image_lemma[OF lf fB fBi fiB x] fx |
|
4036 |
have "x = 0" by blast} |
|
4037 |
note th = this |
|
4038 |
from th show ?thesis unfolding linear_injective_0[OF lf] |
|
4039 |
using B(3) by blast |
|
4040 |
qed |
|
4041 |
||
4042 |
(* Hence either is enough for isomorphism. *) |
|
4043 |
||
4044 |
lemma left_right_inverse_eq: |
|
4045 |
assumes fg: "f o g = id" and gh: "g o h = id" |
|
4046 |
shows "f = h" |
|
4047 |
proof- |
|
4048 |
have "f = f o (g o h)" unfolding gh by simp |
|
4049 |
also have "\<dots> = (f o g) o h" by (simp add: o_assoc) |
|
4050 |
finally show "f = h" unfolding fg by simp |
|
4051 |
qed |
|
4052 |
||
4053 |
lemma isomorphism_expand: |
|
4054 |
"f o g = id \<and> g o f = id \<longleftrightarrow> (\<forall>x. f(g x) = x) \<and> (\<forall>x. g(f x) = x)" |
|
4055 |
by (simp add: expand_fun_eq o_def id_def) |
|
4056 |
||
4057 |
lemma linear_injective_isomorphism: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4058 |
assumes lf: "linear (f :: real^'n \<Rightarrow> real ^'n)" and fi: "inj f" |
33175 | 4059 |
shows "\<exists>f'. linear f' \<and> (\<forall>x. f' (f x) = x) \<and> (\<forall>x. f (f' x) = x)" |
4060 |
unfolding isomorphism_expand[symmetric] |
|
4061 |
using linear_surjective_right_inverse[OF lf linear_injective_imp_surjective[OF lf fi]] linear_injective_left_inverse[OF lf fi] |
|
4062 |
by (metis left_right_inverse_eq) |
|
4063 |
||
4064 |
lemma linear_surjective_isomorphism: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4065 |
assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'n)" and sf: "surj f" |
33175 | 4066 |
shows "\<exists>f'. linear f' \<and> (\<forall>x. f' (f x) = x) \<and> (\<forall>x. f (f' x) = x)" |
4067 |
unfolding isomorphism_expand[symmetric] |
|
4068 |
using linear_surjective_right_inverse[OF lf sf] linear_injective_left_inverse[OF lf linear_surjective_imp_injective[OF lf sf]] |
|
4069 |
by (metis left_right_inverse_eq) |
|
4070 |
||
4071 |
(* Left and right inverses are the same for R^N->R^N. *) |
|
4072 |
||
4073 |
lemma linear_inverse_left: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4074 |
assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'n)" and lf': "linear f'" |
33175 | 4075 |
shows "f o f' = id \<longleftrightarrow> f' o f = id" |
4076 |
proof- |
|
4077 |
{fix f f':: "real ^'n \<Rightarrow> real ^'n" |
|
4078 |
assume lf: "linear f" "linear f'" and f: "f o f' = id" |
|
4079 |
from f have sf: "surj f" |
|
4080 |
||
4081 |
apply (auto simp add: o_def stupid_ext[symmetric] id_def surj_def) |
|
4082 |
by metis |
|
4083 |
from linear_surjective_isomorphism[OF lf(1) sf] lf f |
|
4084 |
have "f' o f = id" unfolding stupid_ext[symmetric] o_def id_def |
|
4085 |
by metis} |
|
4086 |
then show ?thesis using lf lf' by metis |
|
4087 |
qed |
|
4088 |
||
4089 |
(* Moreover, a one-sided inverse is automatically linear. *) |
|
4090 |
||
4091 |
lemma left_inverse_linear: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4092 |
assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'n)" and gf: "g o f = id" |
33175 | 4093 |
shows "linear g" |
4094 |
proof- |
|
4095 |
from gf have fi: "inj f" apply (auto simp add: inj_on_def o_def id_def stupid_ext[symmetric]) |
|
4096 |
by metis |
|
4097 |
from linear_injective_isomorphism[OF lf fi] |
|
4098 |
obtain h:: "real ^'n \<Rightarrow> real ^'n" where |
|
4099 |
h: "linear h" "\<forall>x. h (f x) = x" "\<forall>x. f (h x) = x" by blast |
|
4100 |
have "h = g" apply (rule ext) using gf h(2,3) |
|
4101 |
apply (simp add: o_def id_def stupid_ext[symmetric]) |
|
4102 |
by metis |
|
4103 |
with h(1) show ?thesis by blast |
|
4104 |
qed |
|
4105 |
||
4106 |
lemma right_inverse_linear: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4107 |
assumes lf: "linear (f:: real ^'n \<Rightarrow> real ^'n)" and gf: "f o g = id" |
33175 | 4108 |
shows "linear g" |
4109 |
proof- |
|
4110 |
from gf have fi: "surj f" apply (auto simp add: surj_def o_def id_def stupid_ext[symmetric]) |
|
4111 |
by metis |
|
4112 |
from linear_surjective_isomorphism[OF lf fi] |
|
4113 |
obtain h:: "real ^'n \<Rightarrow> real ^'n" where |
|
4114 |
h: "linear h" "\<forall>x. h (f x) = x" "\<forall>x. f (h x) = x" by blast |
|
4115 |
have "h = g" apply (rule ext) using gf h(2,3) |
|
4116 |
apply (simp add: o_def id_def stupid_ext[symmetric]) |
|
4117 |
by metis |
|
4118 |
with h(1) show ?thesis by blast |
|
4119 |
qed |
|
4120 |
||
4121 |
(* The same result in terms of square matrices. *) |
|
4122 |
||
4123 |
lemma matrix_left_right_inverse: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4124 |
fixes A A' :: "real ^'n^'n" |
33175 | 4125 |
shows "A ** A' = mat 1 \<longleftrightarrow> A' ** A = mat 1" |
4126 |
proof- |
|
4127 |
{fix A A' :: "real ^'n^'n" assume AA': "A ** A' = mat 1" |
|
4128 |
have sA: "surj (op *v A)" |
|
4129 |
unfolding surj_def |
|
4130 |
apply clarify |
|
4131 |
apply (rule_tac x="(A' *v y)" in exI) |
|
4132 |
by (simp add: matrix_vector_mul_assoc AA' matrix_vector_mul_lid) |
|
4133 |
from linear_surjective_isomorphism[OF matrix_vector_mul_linear sA] |
|
4134 |
obtain f' :: "real ^'n \<Rightarrow> real ^'n" |
|
4135 |
where f': "linear f'" "\<forall>x. f' (A *v x) = x" "\<forall>x. A *v f' x = x" by blast |
|
4136 |
have th: "matrix f' ** A = mat 1" |
|
4137 |
by (simp add: matrix_eq matrix_works[OF f'(1)] matrix_vector_mul_assoc[symmetric] matrix_vector_mul_lid f'(2)[rule_format]) |
|
4138 |
hence "(matrix f' ** A) ** A' = mat 1 ** A'" by simp |
|
4139 |
hence "matrix f' = A'" by (simp add: matrix_mul_assoc[symmetric] AA' matrix_mul_rid matrix_mul_lid) |
|
4140 |
hence "matrix f' ** A = A' ** A" by simp |
|
4141 |
hence "A' ** A = mat 1" by (simp add: th)} |
|
4142 |
then show ?thesis by blast |
|
4143 |
qed |
|
4144 |
||
4145 |
(* Considering an n-element vector as an n-by-1 or 1-by-n matrix. *) |
|
4146 |
||
4147 |
definition "rowvector v = (\<chi> i j. (v$j))" |
|
4148 |
||
4149 |
definition "columnvector v = (\<chi> i j. (v$i))" |
|
4150 |
||
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
4151 |
lemma transpose_columnvector: |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
4152 |
"transpose(columnvector v) = rowvector v" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
4153 |
by (simp add: transpose_def rowvector_def columnvector_def Cart_eq) |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
4154 |
|
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
4155 |
lemma transpose_rowvector: "transpose(rowvector v) = columnvector v" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
4156 |
by (simp add: transpose_def columnvector_def rowvector_def Cart_eq) |
33175 | 4157 |
|
4158 |
lemma dot_rowvector_columnvector: |
|
4159 |
"columnvector (A *v v) = A ** columnvector v" |
|
4160 |
by (vector columnvector_def matrix_matrix_mult_def matrix_vector_mult_def) |
|
4161 |
||
35542 | 4162 |
lemma dot_matrix_product: "(x::real^'n) \<bullet> y = (((rowvector x ::real^'n^1) ** (columnvector y :: real^1^'n))$1)$1" |
4163 |
by (vector matrix_matrix_mult_def rowvector_def columnvector_def inner_vector_def) |
|
33175 | 4164 |
|
4165 |
lemma dot_matrix_vector_mul: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4166 |
fixes A B :: "real ^'n ^'n" and x y :: "real ^'n" |
33175 | 4167 |
shows "(A *v x) \<bullet> (B *v y) = |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
4168 |
(((rowvector x :: real^'n^1) ** ((transpose A ** B) ** (columnvector y :: real ^1^'n)))$1)$1" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
4169 |
unfolding dot_matrix_product transpose_columnvector[symmetric] |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35043
diff
changeset
|
4170 |
dot_rowvector_columnvector matrix_transpose_mul matrix_mul_assoc .. |
33175 | 4171 |
|
4172 |
(* Infinity norm. *) |
|
4173 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4174 |
definition "infnorm (x::real^'n) = Sup {abs(x$i) |i. i\<in> (UNIV :: 'n set)}" |
33175 | 4175 |
|
4176 |
lemma numseg_dimindex_nonempty: "\<exists>i. i \<in> (UNIV :: 'n set)" |
|
4177 |
by auto |
|
4178 |
||
4179 |
lemma infnorm_set_image: |
|
34289 | 4180 |
"{abs(x$i) |i. i\<in> (UNIV :: _ set)} = |
4181 |
(\<lambda>i. abs(x$i)) ` (UNIV)" by blast |
|
33175 | 4182 |
|
4183 |
lemma infnorm_set_lemma: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4184 |
shows "finite {abs((x::'a::abs ^'n)$i) |i. i\<in> (UNIV :: 'n set)}" |
33175 | 4185 |
and "{abs(x$i) |i. i\<in> (UNIV :: 'n::finite set)} \<noteq> {}" |
4186 |
unfolding infnorm_set_image |
|
4187 |
by (auto intro: finite_imageI) |
|
4188 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4189 |
lemma infnorm_pos_le: "0 \<le> infnorm (x::real^'n)" |
33175 | 4190 |
unfolding infnorm_def |
33270 | 4191 |
unfolding Sup_finite_ge_iff[ OF infnorm_set_lemma] |
33175 | 4192 |
unfolding infnorm_set_image |
4193 |
by auto |
|
4194 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4195 |
lemma infnorm_triangle: "infnorm ((x::real^'n) + y) \<le> infnorm x + infnorm y" |
33175 | 4196 |
proof- |
4197 |
have th: "\<And>x y (z::real). x - y <= z \<longleftrightarrow> x - z <= y" by arith |
|
4198 |
have th1: "\<And>S f. f ` S = { f i| i. i \<in> S}" by blast |
|
4199 |
have th2: "\<And>x (y::real). abs(x + y) - abs(x) <= abs(y)" by arith |
|
4200 |
show ?thesis |
|
4201 |
unfolding infnorm_def |
|
33270 | 4202 |
unfolding Sup_finite_le_iff[ OF infnorm_set_lemma] |
33175 | 4203 |
apply (subst diff_le_eq[symmetric]) |
33270 | 4204 |
unfolding Sup_finite_ge_iff[ OF infnorm_set_lemma] |
33175 | 4205 |
unfolding infnorm_set_image bex_simps |
4206 |
apply (subst th) |
|
4207 |
unfolding th1 |
|
33270 | 4208 |
unfolding Sup_finite_ge_iff[ OF infnorm_set_lemma] |
33175 | 4209 |
|
4210 |
unfolding infnorm_set_image ball_simps bex_simps |
|
4211 |
apply simp |
|
4212 |
apply (metis th2) |
|
4213 |
done |
|
4214 |
qed |
|
4215 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4216 |
lemma infnorm_eq_0: "infnorm x = 0 \<longleftrightarrow> (x::real ^'n) = 0" |
33175 | 4217 |
proof- |
4218 |
have "infnorm x <= 0 \<longleftrightarrow> x = 0" |
|
4219 |
unfolding infnorm_def |
|
33270 | 4220 |
unfolding Sup_finite_le_iff[OF infnorm_set_lemma] |
33175 | 4221 |
unfolding infnorm_set_image ball_simps |
4222 |
by vector |
|
4223 |
then show ?thesis using infnorm_pos_le[of x] by simp |
|
4224 |
qed |
|
4225 |
||
4226 |
lemma infnorm_0: "infnorm 0 = 0" |
|
4227 |
by (simp add: infnorm_eq_0) |
|
4228 |
||
4229 |
lemma infnorm_neg: "infnorm (- x) = infnorm x" |
|
4230 |
unfolding infnorm_def |
|
33270 | 4231 |
apply (rule cong[of "Sup" "Sup"]) |
33175 | 4232 |
apply blast |
4233 |
apply (rule set_ext) |
|
4234 |
apply auto |
|
4235 |
done |
|
4236 |
||
4237 |
lemma infnorm_sub: "infnorm (x - y) = infnorm (y - x)" |
|
4238 |
proof- |
|
4239 |
have "y - x = - (x - y)" by simp |
|
4240 |
then show ?thesis by (metis infnorm_neg) |
|
4241 |
qed |
|
4242 |
||
4243 |
lemma real_abs_sub_infnorm: "\<bar> infnorm x - infnorm y\<bar> \<le> infnorm (x - y)" |
|
4244 |
proof- |
|
4245 |
have th: "\<And>(nx::real) n ny. nx <= n + ny \<Longrightarrow> ny <= n + nx ==> \<bar>nx - ny\<bar> <= n" |
|
4246 |
by arith |
|
4247 |
from infnorm_triangle[of "x - y" " y"] infnorm_triangle[of "x - y" "-x"] |
|
4248 |
have ths: "infnorm x \<le> infnorm (x - y) + infnorm y" |
|
4249 |
"infnorm y \<le> infnorm (x - y) + infnorm x" |
|
36350 | 4250 |
by (simp_all add: field_simps infnorm_neg diff_def[symmetric]) |
33175 | 4251 |
from th[OF ths] show ?thesis . |
4252 |
qed |
|
4253 |
||
4254 |
lemma real_abs_infnorm: " \<bar>infnorm x\<bar> = infnorm x" |
|
4255 |
using infnorm_pos_le[of x] by arith |
|
4256 |
||
4257 |
lemma component_le_infnorm: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4258 |
shows "\<bar>x$i\<bar> \<le> infnorm (x::real^'n)" |
33175 | 4259 |
proof- |
4260 |
let ?U = "UNIV :: 'n set" |
|
4261 |
let ?S = "{\<bar>x$i\<bar> |i. i\<in> ?U}" |
|
4262 |
have fS: "finite ?S" unfolding image_Collect[symmetric] |
|
4263 |
apply (rule finite_imageI) unfolding Collect_def mem_def by simp |
|
4264 |
have S0: "?S \<noteq> {}" by blast |
|
4265 |
have th1: "\<And>S f. f ` S = { f i| i. i \<in> S}" by blast |
|
33270 | 4266 |
from Sup_finite_in[OF fS S0] |
4267 |
show ?thesis unfolding infnorm_def infnorm_set_image |
|
4268 |
by (metis Sup_finite_ge_iff finite finite_imageI UNIV_not_empty image_is_empty |
|
4269 |
rangeI real_le_refl) |
|
33175 | 4270 |
qed |
4271 |
||
4272 |
lemma infnorm_mul_lemma: "infnorm(a *s x) <= \<bar>a\<bar> * infnorm x" |
|
4273 |
apply (subst infnorm_def) |
|
33270 | 4274 |
unfolding Sup_finite_le_iff[OF infnorm_set_lemma] |
33175 | 4275 |
unfolding infnorm_set_image ball_simps |
4276 |
apply (simp add: abs_mult) |
|
4277 |
apply (rule allI) |
|
4278 |
apply (cut_tac component_le_infnorm[of x]) |
|
4279 |
apply (rule mult_mono) |
|
4280 |
apply auto |
|
4281 |
done |
|
4282 |
||
4283 |
lemma infnorm_mul: "infnorm(a *s x) = abs a * infnorm x" |
|
4284 |
proof- |
|
4285 |
{assume a0: "a = 0" hence ?thesis by (simp add: infnorm_0) } |
|
4286 |
moreover |
|
4287 |
{assume a0: "a \<noteq> 0" |
|
4288 |
from a0 have th: "(1/a) *s (a *s x) = x" |
|
4289 |
by (simp add: vector_smult_assoc) |
|
4290 |
from a0 have ap: "\<bar>a\<bar> > 0" by arith |
|
4291 |
from infnorm_mul_lemma[of "1/a" "a *s x"] |
|
4292 |
have "infnorm x \<le> 1/\<bar>a\<bar> * infnorm (a*s x)" |
|
4293 |
unfolding th by simp |
|
4294 |
with ap have "\<bar>a\<bar> * infnorm x \<le> \<bar>a\<bar> * (1/\<bar>a\<bar> * infnorm (a *s x))" by (simp add: field_simps) |
|
4295 |
then have "\<bar>a\<bar> * infnorm x \<le> infnorm (a*s x)" |
|
4296 |
using ap by (simp add: field_simps) |
|
4297 |
with infnorm_mul_lemma[of a x] have ?thesis by arith } |
|
4298 |
ultimately show ?thesis by blast |
|
4299 |
qed |
|
4300 |
||
4301 |
lemma infnorm_pos_lt: "infnorm x > 0 \<longleftrightarrow> x \<noteq> 0" |
|
4302 |
using infnorm_pos_le[of x] infnorm_eq_0[of x] by arith |
|
4303 |
||
4304 |
(* Prove that it differs only up to a bound from Euclidean norm. *) |
|
4305 |
||
4306 |
lemma infnorm_le_norm: "infnorm x \<le> norm x" |
|
33270 | 4307 |
unfolding infnorm_def Sup_finite_le_iff[OF infnorm_set_lemma] |
33175 | 4308 |
unfolding infnorm_set_image ball_simps |
4309 |
by (metis component_le_norm) |
|
4310 |
lemma card_enum: "card {1 .. n} = n" by auto |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4311 |
lemma norm_le_infnorm: "norm(x) <= sqrt(real CARD('n)) * infnorm(x::real ^'n)" |
33175 | 4312 |
proof- |
4313 |
let ?d = "CARD('n)" |
|
4314 |
have "real ?d \<ge> 0" by simp |
|
4315 |
hence d2: "(sqrt (real ?d))^2 = real ?d" |
|
4316 |
by (auto intro: real_sqrt_pow2) |
|
4317 |
have th: "sqrt (real ?d) * infnorm x \<ge> 0" |
|
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
36336
diff
changeset
|
4318 |
by (simp add: zero_le_mult_iff infnorm_pos_le) |
35542 | 4319 |
have th1: "x \<bullet> x \<le> (sqrt (real ?d) * infnorm x)^2" |
33175 | 4320 |
unfolding power_mult_distrib d2 |
35542 | 4321 |
unfolding real_of_nat_def inner_vector_def |
4322 |
apply (subst power2_abs[symmetric]) |
|
4323 |
apply (rule setsum_bounded) |
|
4324 |
apply(auto simp add: power2_eq_square[symmetric]) |
|
33175 | 4325 |
apply (subst power2_abs[symmetric]) |
4326 |
apply (rule power_mono) |
|
33270 | 4327 |
unfolding infnorm_def Sup_finite_ge_iff[OF infnorm_set_lemma] |
35542 | 4328 |
unfolding infnorm_set_image bex_simps apply(rule_tac x=i in exI) by auto |
4329 |
from real_le_lsqrt[OF inner_ge_zero th th1] |
|
4330 |
show ?thesis unfolding norm_eq_sqrt_inner id_def . |
|
33175 | 4331 |
qed |
4332 |
||
4333 |
(* Equality in Cauchy-Schwarz and triangle inequalities. *) |
|
4334 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4335 |
lemma norm_cauchy_schwarz_eq: "(x::real ^'n) \<bullet> y = norm x * norm y \<longleftrightarrow> norm x *s y = norm y *s x" (is "?lhs \<longleftrightarrow> ?rhs") |
33175 | 4336 |
proof- |
4337 |
{assume h: "x = 0" |
|
4338 |
hence ?thesis by simp} |
|
4339 |
moreover |
|
4340 |
{assume h: "y = 0" |
|
4341 |
hence ?thesis by simp} |
|
4342 |
moreover |
|
4343 |
{assume x: "x \<noteq> 0" and y: "y \<noteq> 0" |
|
35542 | 4344 |
from inner_eq_zero_iff[of "norm y *s x - norm x *s y"] |
33175 | 4345 |
have "?rhs \<longleftrightarrow> (norm y * (norm y * norm x * norm x - norm x * (x \<bullet> y)) - norm x * (norm y * (y \<bullet> x) - norm x * norm y * norm y) = 0)" |
4346 |
using x y |
|
35542 | 4347 |
unfolding inner_simps smult_conv_scaleR |
4348 |
unfolding power2_norm_eq_inner[symmetric] power2_eq_square diff_eq_0_iff_eq apply (simp add: inner_commute) |
|
36350 | 4349 |
apply (simp add: field_simps) by metis |
33175 | 4350 |
also have "\<dots> \<longleftrightarrow> (2 * norm x * norm y * (norm x * norm y - x \<bullet> y) = 0)" using x y |
36350 | 4351 |
by (simp add: field_simps inner_commute) |
33175 | 4352 |
also have "\<dots> \<longleftrightarrow> ?lhs" using x y |
4353 |
apply simp |
|
4354 |
by metis |
|
4355 |
finally have ?thesis by blast} |
|
4356 |
ultimately show ?thesis by blast |
|
4357 |
qed |
|
4358 |
||
4359 |
lemma norm_cauchy_schwarz_abs_eq: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4360 |
fixes x y :: "real ^ 'n" |
33175 | 4361 |
shows "abs(x \<bullet> y) = norm x * norm y \<longleftrightarrow> |
4362 |
norm x *s y = norm y *s x \<or> norm(x) *s y = - norm y *s x" (is "?lhs \<longleftrightarrow> ?rhs") |
|
4363 |
proof- |
|
4364 |
have th: "\<And>(x::real) a. a \<ge> 0 \<Longrightarrow> abs x = a \<longleftrightarrow> x = a \<or> x = - a" by arith |
|
4365 |
have "?rhs \<longleftrightarrow> norm x *s y = norm y *s x \<or> norm (- x) *s y = norm y *s (- x)" |
|
4366 |
apply simp by vector |
|
4367 |
also have "\<dots> \<longleftrightarrow>(x \<bullet> y = norm x * norm y \<or> |
|
4368 |
(-x) \<bullet> y = norm x * norm y)" |
|
4369 |
unfolding norm_cauchy_schwarz_eq[symmetric] |
|
4370 |
unfolding norm_minus_cancel |
|
4371 |
norm_mul by blast |
|
4372 |
also have "\<dots> \<longleftrightarrow> ?lhs" |
|
35542 | 4373 |
unfolding th[OF mult_nonneg_nonneg, OF norm_ge_zero[of x] norm_ge_zero[of y]] inner_simps by auto |
33175 | 4374 |
finally show ?thesis .. |
4375 |
qed |
|
4376 |
||
4377 |
lemma norm_triangle_eq: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4378 |
fixes x y :: "real ^ 'n" |
33175 | 4379 |
shows "norm(x + y) = norm x + norm y \<longleftrightarrow> norm x *s y = norm y *s x" |
4380 |
proof- |
|
4381 |
{assume x: "x =0 \<or> y =0" |
|
4382 |
hence ?thesis by (cases "x=0", simp_all)} |
|
4383 |
moreover |
|
4384 |
{assume x: "x \<noteq> 0" and y: "y \<noteq> 0" |
|
4385 |
hence "norm x \<noteq> 0" "norm y \<noteq> 0" |
|
4386 |
by simp_all |
|
4387 |
hence n: "norm x > 0" "norm y > 0" |
|
4388 |
using norm_ge_zero[of x] norm_ge_zero[of y] |
|
4389 |
by arith+ |
|
4390 |
have th: "\<And>(a::real) b c. a + b + c \<noteq> 0 ==> (a = b + c \<longleftrightarrow> a^2 = (b + c)^2)" by algebra |
|
4391 |
have "norm(x + y) = norm x + norm y \<longleftrightarrow> norm(x + y)^ 2 = (norm x + norm y) ^2" |
|
4392 |
apply (rule th) using n norm_ge_zero[of "x + y"] |
|
4393 |
by arith |
|
4394 |
also have "\<dots> \<longleftrightarrow> norm x *s y = norm y *s x" |
|
4395 |
unfolding norm_cauchy_schwarz_eq[symmetric] |
|
35542 | 4396 |
unfolding power2_norm_eq_inner inner_simps |
36350 | 4397 |
by (simp add: power2_norm_eq_inner[symmetric] power2_eq_square inner_commute field_simps) |
33175 | 4398 |
finally have ?thesis .} |
4399 |
ultimately show ?thesis by blast |
|
4400 |
qed |
|
4401 |
||
4402 |
(* Collinearity.*) |
|
4403 |
||
4404 |
definition "collinear S \<longleftrightarrow> (\<exists>u. \<forall>x \<in> S. \<forall> y \<in> S. \<exists>c. x - y = c *s u)" |
|
4405 |
||
4406 |
lemma collinear_empty: "collinear {}" by (simp add: collinear_def) |
|
4407 |
||
34289 | 4408 |
lemma collinear_sing: "collinear {(x::'a::ring_1^_)}" |
33175 | 4409 |
apply (simp add: collinear_def) |
4410 |
apply (rule exI[where x=0]) |
|
4411 |
by simp |
|
4412 |
||
34289 | 4413 |
lemma collinear_2: "collinear {(x::'a::ring_1^_),y}" |
33175 | 4414 |
apply (simp add: collinear_def) |
4415 |
apply (rule exI[where x="x - y"]) |
|
4416 |
apply auto |
|
4417 |
apply (rule exI[where x=0], simp) |
|
4418 |
apply (rule exI[where x=1], simp) |
|
4419 |
apply (rule exI[where x="- 1"], simp add: vector_sneg_minus1[symmetric]) |
|
4420 |
apply (rule exI[where x=0], simp) |
|
4421 |
done |
|
4422 |
||
34289 | 4423 |
lemma collinear_lemma: "collinear {(0::real^_),x,y} \<longleftrightarrow> x = 0 \<or> y = 0 \<or> (\<exists>c. y = c *s x)" (is "?lhs \<longleftrightarrow> ?rhs") |
33175 | 4424 |
proof- |
4425 |
{assume "x=0 \<or> y = 0" hence ?thesis |
|
4426 |
by (cases "x = 0", simp_all add: collinear_2 insert_commute)} |
|
4427 |
moreover |
|
4428 |
{assume x: "x \<noteq> 0" and y: "y \<noteq> 0" |
|
4429 |
{assume h: "?lhs" |
|
4430 |
then obtain u where u: "\<forall> x\<in> {0,x,y}. \<forall>y\<in> {0,x,y}. \<exists>c. x - y = c *s u" unfolding collinear_def by blast |
|
4431 |
from u[rule_format, of x 0] u[rule_format, of y 0] |
|
4432 |
obtain cx and cy where |
|
4433 |
cx: "x = cx*s u" and cy: "y = cy*s u" |
|
4434 |
by auto |
|
4435 |
from cx x have cx0: "cx \<noteq> 0" by auto |
|
4436 |
from cy y have cy0: "cy \<noteq> 0" by auto |
|
4437 |
let ?d = "cy / cx" |
|
4438 |
from cx cy cx0 have "y = ?d *s x" |
|
4439 |
by (simp add: vector_smult_assoc) |
|
4440 |
hence ?rhs using x y by blast} |
|
4441 |
moreover |
|
4442 |
{assume h: "?rhs" |
|
4443 |
then obtain c where c: "y = c*s x" using x y by blast |
|
4444 |
have ?lhs unfolding collinear_def c |
|
4445 |
apply (rule exI[where x=x]) |
|
4446 |
apply auto |
|
4447 |
apply (rule exI[where x="- 1"], simp only: vector_smult_lneg vector_smult_lid) |
|
4448 |
apply (rule exI[where x= "-c"], simp only: vector_smult_lneg) |
|
4449 |
apply (rule exI[where x=1], simp) |
|
4450 |
apply (rule exI[where x="1 - c"], simp add: vector_smult_lneg vector_sub_rdistrib) |
|
4451 |
apply (rule exI[where x="c - 1"], simp add: vector_smult_lneg vector_sub_rdistrib) |
|
4452 |
done} |
|
4453 |
ultimately have ?thesis by blast} |
|
4454 |
ultimately show ?thesis by blast |
|
4455 |
qed |
|
4456 |
||
4457 |
lemma norm_cauchy_schwarz_equal: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
4458 |
fixes x y :: "real ^ 'n" |
33175 | 4459 |
shows "abs(x \<bullet> y) = norm x * norm y \<longleftrightarrow> collinear {(0::real^'n),x,y}" |
4460 |
unfolding norm_cauchy_schwarz_abs_eq |
|
4461 |
apply (cases "x=0", simp_all add: collinear_2) |
|
4462 |
apply (cases "y=0", simp_all add: collinear_2 insert_commute) |
|
4463 |
unfolding collinear_lemma |
|
4464 |
apply simp |
|
4465 |
apply (subgoal_tac "norm x \<noteq> 0") |
|
4466 |
apply (subgoal_tac "norm y \<noteq> 0") |
|
4467 |
apply (rule iffI) |
|
4468 |
apply (cases "norm x *s y = norm y *s x") |
|
4469 |
apply (rule exI[where x="(1/norm x) * norm y"]) |
|
4470 |
apply (drule sym) |
|
4471 |
unfolding vector_smult_assoc[symmetric] |
|
4472 |
apply (simp add: vector_smult_assoc field_simps) |
|
4473 |
apply (rule exI[where x="(1/norm x) * - norm y"]) |
|
4474 |
apply clarify |
|
4475 |
apply (drule sym) |
|
4476 |
unfolding vector_smult_assoc[symmetric] |
|
4477 |
apply (simp add: vector_smult_assoc field_simps) |
|
4478 |
apply (erule exE) |
|
4479 |
apply (erule ssubst) |
|
4480 |
unfolding vector_smult_assoc |
|
4481 |
unfolding norm_mul |
|
4482 |
apply (subgoal_tac "norm x * c = \<bar>c\<bar> * norm x \<or> norm x * c = - \<bar>c\<bar> * norm x") |
|
36350 | 4483 |
apply (case_tac "c <= 0", simp add: field_simps) |
4484 |
apply (simp add: field_simps) |
|
4485 |
apply (case_tac "c <= 0", simp add: field_simps) |
|
4486 |
apply (simp add: field_simps) |
|
33175 | 4487 |
apply simp |
4488 |
apply simp |
|
4489 |
done |
|
4490 |
||
4491 |
end |