| author | haftmann | 
| Mon, 03 Feb 2014 08:23:21 +0100 | |
| changeset 55293 | 42cf5802d36a | 
| parent 55136 | fb10f6ce0c16 | 
| child 55775 | 1557a391a858 | 
| permissions | -rw-r--r-- | 
| 44133 | 1 | (* Title: HOL/Multivariate_Analysis/Linear_Algebra.thy | 
| 2 | Author: Amine Chaieb, University of Cambridge | |
| 3 | *) | |
| 4 | ||
| 5 | header {* Elementary linear algebra on Euclidean spaces *}
 | |
| 6 | ||
| 7 | theory Linear_Algebra | |
| 8 | imports | |
| 9 | Euclidean_Space | |
| 10 | "~~/src/HOL/Library/Infinite_Set" | |
| 11 | begin | |
| 12 | ||
| 13 | lemma cond_application_beta: "(if b then f else g) x = (if b then f x else g x)" | |
| 14 | by auto | |
| 15 | ||
| 16 | notation inner (infix "\<bullet>" 70) | |
| 17 | ||
| 53716 | 18 | lemma square_bound_lemma: | 
| 19 | fixes x :: real | |
| 20 | shows "x < (1 + x) * (1 + x)" | |
| 49522 | 21 | proof - | 
| 53406 | 22 | have "(x + 1/2)\<^sup>2 + 3/4 > 0" | 
| 23 | using zero_le_power2[of "x+1/2"] by arith | |
| 24 | then show ?thesis | |
| 25 | by (simp add: field_simps power2_eq_square) | |
| 44133 | 26 | qed | 
| 27 | ||
| 53406 | 28 | lemma square_continuous: | 
| 29 | fixes e :: real | |
| 30 | shows "e > 0 \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>y. abs (y - x) < d \<longrightarrow> abs (y * y - x * x) < e)" | |
| 51478 
270b21f3ae0a
move continuous and continuous_on to the HOL image; isCont is an abbreviation for continuous (at x) (isCont is now restricted to a T2 space)
 hoelzl parents: 
51475diff
changeset | 31 | using isCont_power[OF isCont_ident, of x, unfolded isCont_def LIM_eq, rule_format, of e 2] | 
| 49522 | 32 | apply (auto simp add: power2_eq_square) | 
| 44133 | 33 | apply (rule_tac x="s" in exI) | 
| 34 | apply auto | |
| 35 | apply (erule_tac x=y in allE) | |
| 36 | apply auto | |
| 37 | done | |
| 38 | ||
| 39 | text{* Hence derive more interesting properties of the norm. *}
 | |
| 40 | ||
| 53406 | 41 | lemma norm_eq_0_dot: "norm x = 0 \<longleftrightarrow> x \<bullet> x = (0::real)" | 
| 44666 | 42 | by simp (* TODO: delete *) | 
| 44133 | 43 | |
| 44 | lemma norm_triangle_sub: | |
| 45 | fixes x y :: "'a::real_normed_vector" | |
| 53406 | 46 | shows "norm x \<le> norm y + norm (x - y)" | 
| 44133 | 47 | using norm_triangle_ineq[of "y" "x - y"] by (simp add: field_simps) | 
| 48 | ||
| 53406 | 49 | lemma norm_le: "norm x \<le> norm y \<longleftrightarrow> x \<bullet> x \<le> y \<bullet> y" | 
| 44133 | 50 | by (simp add: norm_eq_sqrt_inner) | 
| 44666 | 51 | |
| 53406 | 52 | lemma norm_lt: "norm x < norm y \<longleftrightarrow> x \<bullet> x < y \<bullet> y" | 
| 53 | by (simp add: norm_eq_sqrt_inner) | |
| 54 | ||
| 55 | lemma norm_eq: "norm x = norm y \<longleftrightarrow> x \<bullet> x = y \<bullet> y" | |
| 49522 | 56 | apply (subst order_eq_iff) | 
| 57 | apply (auto simp: norm_le) | |
| 58 | done | |
| 44666 | 59 | |
| 53406 | 60 | lemma norm_eq_1: "norm x = 1 \<longleftrightarrow> x \<bullet> x = 1" | 
| 44666 | 61 | by (simp add: norm_eq_sqrt_inner) | 
| 44133 | 62 | |
| 63 | text{* Squaring equations and inequalities involving norms.  *}
 | |
| 64 | ||
| 53077 | 65 | lemma dot_square_norm: "x \<bullet> x = (norm x)\<^sup>2" | 
| 44666 | 66 | by (simp only: power2_norm_eq_inner) (* TODO: move? *) | 
| 44133 | 67 | |
| 53406 | 68 | lemma norm_eq_square: "norm x = a \<longleftrightarrow> 0 \<le> a \<and> x \<bullet> x = a\<^sup>2" | 
| 44133 | 69 | by (auto simp add: norm_eq_sqrt_inner) | 
| 70 | ||
| 53077 | 71 | lemma real_abs_le_square_iff: "\<bar>x\<bar> \<le> \<bar>y\<bar> \<longleftrightarrow> (x::real)\<^sup>2 \<le> y\<^sup>2" | 
| 44133 | 72 | proof | 
| 73 | assume "\<bar>x\<bar> \<le> \<bar>y\<bar>" | |
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
51478diff
changeset | 74 | then have "\<bar>x\<bar>\<^sup>2 \<le> \<bar>y\<bar>\<^sup>2" by (rule power_mono, simp) | 
| 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
51478diff
changeset | 75 | then show "x\<^sup>2 \<le> y\<^sup>2" by simp | 
| 44133 | 76 | next | 
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
51478diff
changeset | 77 | assume "x\<^sup>2 \<le> y\<^sup>2" | 
| 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
51478diff
changeset | 78 | then have "sqrt (x\<^sup>2) \<le> sqrt (y\<^sup>2)" by (rule real_sqrt_le_mono) | 
| 44133 | 79 | then show "\<bar>x\<bar> \<le> \<bar>y\<bar>" by simp | 
| 80 | qed | |
| 81 | ||
| 53406 | 82 | lemma norm_le_square: "norm x \<le> a \<longleftrightarrow> 0 \<le> a \<and> x \<bullet> x \<le> a\<^sup>2" | 
| 44133 | 83 | apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric]) | 
| 84 | using norm_ge_zero[of x] | |
| 85 | apply arith | |
| 86 | done | |
| 87 | ||
| 53406 | 88 | lemma norm_ge_square: "norm x \<ge> a \<longleftrightarrow> a \<le> 0 \<or> x \<bullet> x \<ge> a\<^sup>2" | 
| 44133 | 89 | apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric]) | 
| 90 | using norm_ge_zero[of x] | |
| 91 | apply arith | |
| 92 | done | |
| 93 | ||
| 53716 | 94 | lemma norm_lt_square: "norm x < a \<longleftrightarrow> 0 < a \<and> x \<bullet> x < a\<^sup>2" | 
| 44133 | 95 | by (metis not_le norm_ge_square) | 
| 53406 | 96 | |
| 53716 | 97 | lemma norm_gt_square: "norm x > a \<longleftrightarrow> a < 0 \<or> x \<bullet> x > a\<^sup>2" | 
| 44133 | 98 | by (metis norm_le_square not_less) | 
| 99 | ||
| 100 | text{* Dot product in terms of the norm rather than conversely. *}
 | |
| 101 | ||
| 53406 | 102 | lemmas inner_simps = inner_add_left inner_add_right inner_diff_right inner_diff_left | 
| 49522 | 103 | inner_scaleR_left inner_scaleR_right | 
| 44133 | 104 | |
| 53077 | 105 | lemma dot_norm: "x \<bullet> y = ((norm (x + y))\<^sup>2 - (norm x)\<^sup>2 - (norm y)\<^sup>2) / 2" | 
| 53406 | 106 | unfolding power2_norm_eq_inner inner_simps inner_commute by auto | 
| 44133 | 107 | |
| 53077 | 108 | lemma dot_norm_neg: "x \<bullet> y = (((norm x)\<^sup>2 + (norm y)\<^sup>2) - (norm (x - y))\<^sup>2) / 2" | 
| 49525 | 109 | unfolding power2_norm_eq_inner inner_simps inner_commute | 
| 110 | by (auto simp add: algebra_simps) | |
| 44133 | 111 | |
| 112 | text{* Equality of vectors in terms of @{term "op \<bullet>"} products.    *}
 | |
| 113 | ||
| 53406 | 114 | lemma vector_eq: "x = y \<longleftrightarrow> x \<bullet> x = x \<bullet> y \<and> y \<bullet> y = x \<bullet> x" | 
| 115 | (is "?lhs \<longleftrightarrow> ?rhs") | |
| 44133 | 116 | proof | 
| 49652 | 117 | assume ?lhs | 
| 118 | then show ?rhs by simp | |
| 44133 | 119 | next | 
| 120 | assume ?rhs | |
| 53406 | 121 | then have "x \<bullet> x - x \<bullet> y = 0 \<and> x \<bullet> y - y \<bullet> y = 0" | 
| 122 | by simp | |
| 123 | then have "x \<bullet> (x - y) = 0 \<and> y \<bullet> (x - y) = 0" | |
| 124 | by (simp add: inner_diff inner_commute) | |
| 125 | then have "(x - y) \<bullet> (x - y) = 0" | |
| 126 | by (simp add: field_simps inner_diff inner_commute) | |
| 127 | then show "x = y" by simp | |
| 44133 | 128 | qed | 
| 129 | ||
| 130 | lemma norm_triangle_half_r: | |
| 53406 | 131 | "norm (y - x1) < e / 2 \<Longrightarrow> norm (y - x2) < e / 2 \<Longrightarrow> norm (x1 - x2) < e" | 
| 132 | using dist_triangle_half_r unfolding dist_norm[symmetric] by auto | |
| 44133 | 133 | |
| 49522 | 134 | lemma norm_triangle_half_l: | 
| 53406 | 135 | assumes "norm (x - y) < e / 2" | 
| 53842 | 136 | and "norm (x' - y) < e / 2" | 
| 44133 | 137 | shows "norm (x - x') < e" | 
| 53406 | 138 | using dist_triangle_half_l[OF assms[unfolded dist_norm[symmetric]]] | 
| 139 | unfolding dist_norm[symmetric] . | |
| 140 | ||
| 141 | lemma norm_triangle_le: "norm x + norm y \<le> e \<Longrightarrow> norm (x + y) \<le> e" | |
| 44666 | 142 | by (rule norm_triangle_ineq [THEN order_trans]) | 
| 44133 | 143 | |
| 53406 | 144 | lemma norm_triangle_lt: "norm x + norm y < e \<Longrightarrow> norm (x + y) < e" | 
| 44666 | 145 | by (rule norm_triangle_ineq [THEN le_less_trans]) | 
| 44133 | 146 | |
| 147 | lemma setsum_clauses: | |
| 148 |   shows "setsum f {} = 0"
 | |
| 49525 | 149 | and "finite S \<Longrightarrow> setsum f (insert x S) = (if x \<in> S then setsum f S else f x + setsum f S)" | 
| 44133 | 150 | by (auto simp add: insert_absorb) | 
| 151 | ||
| 152 | lemma setsum_norm_le: | |
| 153 | fixes f :: "'a \<Rightarrow> 'b::real_normed_vector" | |
| 44176 
eda112e9cdee
remove redundant lemma setsum_norm in favor of norm_setsum;
 huffman parents: 
44170diff
changeset | 154 | assumes fg: "\<forall>x \<in> S. norm (f x) \<le> g x" | 
| 44133 | 155 | shows "norm (setsum f S) \<le> setsum g S" | 
| 49522 | 156 | by (rule order_trans [OF norm_setsum setsum_mono]) (simp add: fg) | 
| 44133 | 157 | |
| 158 | lemma setsum_norm_bound: | |
| 159 | fixes f :: "'a \<Rightarrow> 'b::real_normed_vector" | |
| 160 | assumes fS: "finite S" | |
| 49522 | 161 | and K: "\<forall>x \<in> S. norm (f x) \<le> K" | 
| 44133 | 162 | shows "norm (setsum f S) \<le> of_nat (card S) * K" | 
| 44176 
eda112e9cdee
remove redundant lemma setsum_norm in favor of norm_setsum;
 huffman parents: 
44170diff
changeset | 163 | using setsum_norm_le[OF K] setsum_constant[symmetric] | 
| 44133 | 164 | by simp | 
| 165 | ||
| 166 | lemma setsum_group: | |
| 167 | assumes fS: "finite S" and fT: "finite T" and fST: "f ` S \<subseteq> T" | |
| 53939 | 168 |   shows "setsum (\<lambda>y. setsum g {x. x \<in> S \<and> f x = y}) T = setsum g S"
 | 
| 44133 | 169 | apply (subst setsum_image_gen[OF fS, of g f]) | 
| 170 | apply (rule setsum_mono_zero_right[OF fT fST]) | |
| 49522 | 171 | apply (auto intro: setsum_0') | 
| 172 | done | |
| 44133 | 173 | |
| 174 | lemma vector_eq_ldot: "(\<forall>x. x \<bullet> y = x \<bullet> z) \<longleftrightarrow> y = z" | |
| 175 | proof | |
| 176 | assume "\<forall>x. x \<bullet> y = x \<bullet> z" | |
| 53406 | 177 | then have "\<forall>x. x \<bullet> (y - z) = 0" | 
| 178 | by (simp add: inner_diff) | |
| 49522 | 179 | then have "(y - z) \<bullet> (y - z) = 0" .. | 
| 49652 | 180 | then show "y = z" by simp | 
| 44133 | 181 | qed simp | 
| 182 | ||
| 183 | lemma vector_eq_rdot: "(\<forall>z. x \<bullet> z = y \<bullet> z) \<longleftrightarrow> x = y" | |
| 184 | proof | |
| 185 | assume "\<forall>z. x \<bullet> z = y \<bullet> z" | |
| 53406 | 186 | then have "\<forall>z. (x - y) \<bullet> z = 0" | 
| 187 | by (simp add: inner_diff) | |
| 49522 | 188 | then have "(x - y) \<bullet> (x - y) = 0" .. | 
| 49652 | 189 | then show "x = y" by simp | 
| 44133 | 190 | qed simp | 
| 191 | ||
| 49522 | 192 | |
| 193 | subsection {* Orthogonality. *}
 | |
| 44133 | 194 | |
| 195 | context real_inner | |
| 196 | begin | |
| 197 | ||
| 53842 | 198 | definition "orthogonal x y \<longleftrightarrow> x \<bullet> y = 0" | 
| 44133 | 199 | |
| 200 | lemma orthogonal_clauses: | |
| 201 | "orthogonal a 0" | |
| 202 | "orthogonal a x \<Longrightarrow> orthogonal a (c *\<^sub>R x)" | |
| 53842 | 203 | "orthogonal a x \<Longrightarrow> orthogonal a (- x)" | 
| 44133 | 204 | "orthogonal a x \<Longrightarrow> orthogonal a y \<Longrightarrow> orthogonal a (x + y)" | 
| 205 | "orthogonal a x \<Longrightarrow> orthogonal a y \<Longrightarrow> orthogonal a (x - y)" | |
| 206 | "orthogonal 0 a" | |
| 207 | "orthogonal x a \<Longrightarrow> orthogonal (c *\<^sub>R x) a" | |
| 53842 | 208 | "orthogonal x a \<Longrightarrow> orthogonal (- x) a" | 
| 44133 | 209 | "orthogonal x a \<Longrightarrow> orthogonal y a \<Longrightarrow> orthogonal (x + y) a" | 
| 210 | "orthogonal x a \<Longrightarrow> orthogonal y a \<Longrightarrow> orthogonal (x - y) a" | |
| 44666 | 211 | unfolding orthogonal_def inner_add inner_diff by auto | 
| 212 | ||
| 44133 | 213 | end | 
| 214 | ||
| 215 | lemma orthogonal_commute: "orthogonal x y \<longleftrightarrow> orthogonal y x" | |
| 216 | by (simp add: orthogonal_def inner_commute) | |
| 217 | ||
| 49522 | 218 | |
| 219 | subsection {* Linear functions. *}
 | |
| 220 | ||
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 221 | lemma linear_iff: | 
| 53716 | 222 | "linear f \<longleftrightarrow> (\<forall>x y. f (x + y) = f x + f y) \<and> (\<forall>c x. f (c *\<^sub>R x) = c *\<^sub>R f x)" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 223 | (is "linear f \<longleftrightarrow> ?rhs") | 
| 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 224 | proof | 
| 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 225 | assume "linear f" then interpret f: linear f . | 
| 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 226 | show "?rhs" by (simp add: f.add f.scaleR) | 
| 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 227 | next | 
| 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 228 | assume "?rhs" then show "linear f" by unfold_locales simp_all | 
| 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 229 | qed | 
| 44133 | 230 | |
| 53406 | 231 | lemma linear_compose_cmul: "linear f \<Longrightarrow> linear (\<lambda>x. c *\<^sub>R f x)" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 232 | by (simp add: linear_iff algebra_simps) | 
| 44133 | 233 | |
| 53406 | 234 | lemma linear_compose_neg: "linear f \<Longrightarrow> linear (\<lambda>x. - f x)" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 235 | by (simp add: linear_iff) | 
| 44133 | 236 | |
| 53406 | 237 | lemma linear_compose_add: "linear f \<Longrightarrow> linear g \<Longrightarrow> linear (\<lambda>x. f x + g x)" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 238 | by (simp add: linear_iff algebra_simps) | 
| 44133 | 239 | |
| 53406 | 240 | lemma linear_compose_sub: "linear f \<Longrightarrow> linear g \<Longrightarrow> linear (\<lambda>x. f x - g x)" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 241 | by (simp add: linear_iff algebra_simps) | 
| 44133 | 242 | |
| 53406 | 243 | lemma linear_compose: "linear f \<Longrightarrow> linear g \<Longrightarrow> linear (g \<circ> f)" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 244 | by (simp add: linear_iff) | 
| 44133 | 245 | |
| 53406 | 246 | lemma linear_id: "linear id" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 247 | by (simp add: linear_iff id_def) | 
| 53406 | 248 | |
| 249 | lemma linear_zero: "linear (\<lambda>x. 0)" | |
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 250 | by (simp add: linear_iff) | 
| 44133 | 251 | |
| 252 | lemma linear_compose_setsum: | |
| 53406 | 253 | assumes fS: "finite S" | 
| 254 | and lS: "\<forall>a \<in> S. linear (f a)" | |
| 53716 | 255 | shows "linear (\<lambda>x. setsum (\<lambda>a. f a x) S)" | 
| 44133 | 256 | using lS | 
| 257 | apply (induct rule: finite_induct[OF fS]) | |
| 49522 | 258 | apply (auto simp add: linear_zero intro: linear_compose_add) | 
| 259 | done | |
| 44133 | 260 | |
| 261 | lemma linear_0: "linear f \<Longrightarrow> f 0 = 0" | |
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 262 | unfolding linear_iff | 
| 44133 | 263 | apply clarsimp | 
| 264 | apply (erule allE[where x="0::'a"]) | |
| 265 | apply simp | |
| 266 | done | |
| 267 | ||
| 53406 | 268 | lemma linear_cmul: "linear f \<Longrightarrow> f (c *\<^sub>R x) = c *\<^sub>R f x" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 269 | by (simp add: linear_iff) | 
| 44133 | 270 | |
| 53406 | 271 | lemma linear_neg: "linear f \<Longrightarrow> f (- x) = - f x" | 
| 44133 | 272 | using linear_cmul [where c="-1"] by simp | 
| 273 | ||
| 53716 | 274 | lemma linear_add: "linear f \<Longrightarrow> f (x + y) = f x + f y" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 275 | by (metis linear_iff) | 
| 44133 | 276 | |
| 53716 | 277 | lemma linear_sub: "linear f \<Longrightarrow> f (x - y) = f x - f y" | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53939diff
changeset | 278 | using linear_add [of f x "- y"] by (simp add: linear_neg) | 
| 44133 | 279 | |
| 280 | lemma linear_setsum: | |
| 53406 | 281 | assumes lin: "linear f" | 
| 282 | and fin: "finite S" | |
| 283 | shows "f (setsum g S) = setsum (f \<circ> g) S" | |
| 284 | using fin | |
| 285 | proof induct | |
| 49522 | 286 | case empty | 
| 53406 | 287 | then show ?case | 
| 288 | by (simp add: linear_0[OF lin]) | |
| 44133 | 289 | next | 
| 49522 | 290 | case (insert x F) | 
| 53406 | 291 | have "f (setsum g (insert x F)) = f (g x + setsum g F)" | 
| 292 | using insert.hyps by simp | |
| 293 | also have "\<dots> = f (g x) + f (setsum g F)" | |
| 294 | using linear_add[OF lin] by simp | |
| 295 | also have "\<dots> = setsum (f \<circ> g) (insert x F)" | |
| 296 | using insert.hyps by simp | |
| 44133 | 297 | finally show ?case . | 
| 298 | qed | |
| 299 | ||
| 300 | lemma linear_setsum_mul: | |
| 53406 | 301 | assumes lin: "linear f" | 
| 302 | and fin: "finite S" | |
| 44133 | 303 | shows "f (setsum (\<lambda>i. c i *\<^sub>R v i) S) = setsum (\<lambda>i. c i *\<^sub>R f (v i)) S" | 
| 53406 | 304 | using linear_setsum[OF lin fin, of "\<lambda>i. c i *\<^sub>R v i" , unfolded o_def] linear_cmul[OF lin] | 
| 49522 | 305 | by simp | 
| 44133 | 306 | |
| 307 | lemma linear_injective_0: | |
| 53406 | 308 | assumes lin: "linear f" | 
| 44133 | 309 | shows "inj f \<longleftrightarrow> (\<forall>x. f x = 0 \<longrightarrow> x = 0)" | 
| 49663 | 310 | proof - | 
| 53406 | 311 | have "inj f \<longleftrightarrow> (\<forall> x y. f x = f y \<longrightarrow> x = y)" | 
| 312 | by (simp add: inj_on_def) | |
| 313 | also have "\<dots> \<longleftrightarrow> (\<forall> x y. f x - f y = 0 \<longrightarrow> x - y = 0)" | |
| 314 | by simp | |
| 44133 | 315 | also have "\<dots> \<longleftrightarrow> (\<forall> x y. f (x - y) = 0 \<longrightarrow> x - y = 0)" | 
| 53406 | 316 | by (simp add: linear_sub[OF lin]) | 
| 317 | also have "\<dots> \<longleftrightarrow> (\<forall> x. f x = 0 \<longrightarrow> x = 0)" | |
| 318 | by auto | |
| 44133 | 319 | finally show ?thesis . | 
| 320 | qed | |
| 321 | ||
| 49522 | 322 | |
| 323 | subsection {* Bilinear functions. *}
 | |
| 44133 | 324 | |
| 53406 | 325 | definition "bilinear f \<longleftrightarrow> (\<forall>x. linear (\<lambda>y. f x y)) \<and> (\<forall>y. linear (\<lambda>x. f x y))" | 
| 326 | ||
| 327 | lemma bilinear_ladd: "bilinear h \<Longrightarrow> h (x + y) z = h x z + h y z" | |
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 328 | by (simp add: bilinear_def linear_iff) | 
| 49663 | 329 | |
| 53406 | 330 | lemma bilinear_radd: "bilinear h \<Longrightarrow> h x (y + z) = h x y + h x z" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 331 | by (simp add: bilinear_def linear_iff) | 
| 44133 | 332 | |
| 53406 | 333 | lemma bilinear_lmul: "bilinear h \<Longrightarrow> h (c *\<^sub>R x) y = c *\<^sub>R h x y" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 334 | by (simp add: bilinear_def linear_iff) | 
| 44133 | 335 | |
| 53406 | 336 | lemma bilinear_rmul: "bilinear h \<Longrightarrow> h x (c *\<^sub>R y) = c *\<^sub>R h x y" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 337 | by (simp add: bilinear_def linear_iff) | 
| 44133 | 338 | |
| 53406 | 339 | lemma bilinear_lneg: "bilinear h \<Longrightarrow> h (- x) y = - h x y" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54413diff
changeset | 340 | by (drule bilinear_lmul [of _ "- 1"]) simp | 
| 44133 | 341 | |
| 53406 | 342 | lemma bilinear_rneg: "bilinear h \<Longrightarrow> h x (- y) = - h x y" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54413diff
changeset | 343 | by (drule bilinear_rmul [of _ _ "- 1"]) simp | 
| 44133 | 344 | |
| 53406 | 345 | lemma (in ab_group_add) eq_add_iff: "x = x + y \<longleftrightarrow> y = 0" | 
| 44133 | 346 | using add_imp_eq[of x y 0] by auto | 
| 347 | ||
| 53406 | 348 | lemma bilinear_lzero: | 
| 349 | assumes "bilinear h" | |
| 350 | shows "h 0 x = 0" | |
| 49663 | 351 | using bilinear_ladd [OF assms, of 0 0 x] by (simp add: eq_add_iff field_simps) | 
| 352 | ||
| 53406 | 353 | lemma bilinear_rzero: | 
| 354 | assumes "bilinear h" | |
| 355 | shows "h x 0 = 0" | |
| 49663 | 356 | using bilinear_radd [OF assms, of x 0 0 ] by (simp add: eq_add_iff field_simps) | 
| 44133 | 357 | |
| 53406 | 358 | lemma bilinear_lsub: "bilinear h \<Longrightarrow> h (x - y) z = h x z - h y z" | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53939diff
changeset | 359 | using bilinear_ladd [of h x "- y"] by (simp add: bilinear_lneg) | 
| 44133 | 360 | |
| 53406 | 361 | lemma bilinear_rsub: "bilinear h \<Longrightarrow> h z (x - y) = h z x - h z y" | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53939diff
changeset | 362 | using bilinear_radd [of h _ x "- y"] by (simp add: bilinear_rneg) | 
| 44133 | 363 | |
| 364 | lemma bilinear_setsum: | |
| 49663 | 365 | assumes bh: "bilinear h" | 
| 366 | and fS: "finite S" | |
| 367 | and fT: "finite T" | |
| 44133 | 368 | shows "h (setsum f S) (setsum g T) = setsum (\<lambda>(i,j). h (f i) (g j)) (S \<times> T) " | 
| 49522 | 369 | proof - | 
| 44133 | 370 | have "h (setsum f S) (setsum g T) = setsum (\<lambda>x. h (f x) (setsum g T)) S" | 
| 371 | apply (rule linear_setsum[unfolded o_def]) | |
| 53406 | 372 | using bh fS | 
| 373 | apply (auto simp add: bilinear_def) | |
| 49522 | 374 | done | 
| 44133 | 375 | also have "\<dots> = setsum (\<lambda>x. setsum (\<lambda>y. h (f x) (g y)) T) S" | 
| 376 | apply (rule setsum_cong, simp) | |
| 377 | apply (rule linear_setsum[unfolded o_def]) | |
| 49522 | 378 | using bh fT | 
| 379 | apply (auto simp add: bilinear_def) | |
| 380 | done | |
| 53406 | 381 | finally show ?thesis | 
| 382 | unfolding setsum_cartesian_product . | |
| 44133 | 383 | qed | 
| 384 | ||
| 49522 | 385 | |
| 386 | subsection {* Adjoints. *}
 | |
| 44133 | 387 | |
| 388 | definition "adjoint f = (SOME f'. \<forall>x y. f x \<bullet> y = x \<bullet> f' y)" | |
| 389 | ||
| 390 | lemma adjoint_unique: | |
| 391 | assumes "\<forall>x y. inner (f x) y = inner x (g y)" | |
| 392 | shows "adjoint f = g" | |
| 49522 | 393 | unfolding adjoint_def | 
| 44133 | 394 | proof (rule some_equality) | 
| 53406 | 395 | show "\<forall>x y. inner (f x) y = inner x (g y)" | 
| 396 | by (rule assms) | |
| 44133 | 397 | next | 
| 53406 | 398 | fix h | 
| 399 | assume "\<forall>x y. inner (f x) y = inner x (h y)" | |
| 400 | then have "\<forall>x y. inner x (g y) = inner x (h y)" | |
| 401 | using assms by simp | |
| 402 | then have "\<forall>x y. inner x (g y - h y) = 0" | |
| 403 | by (simp add: inner_diff_right) | |
| 404 | then have "\<forall>y. inner (g y - h y) (g y - h y) = 0" | |
| 405 | by simp | |
| 406 | then have "\<forall>y. h y = g y" | |
| 407 | by simp | |
| 49652 | 408 | then show "h = g" by (simp add: ext) | 
| 44133 | 409 | qed | 
| 410 | ||
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 411 | text {* TODO: The following lemmas about adjoints should hold for any
 | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 412 | Hilbert space (i.e. complete inner product space). | 
| 54703 | 413 | (see @{url "http://en.wikipedia.org/wiki/Hermitian_adjoint"})
 | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 414 | *} | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 415 | |
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 416 | lemma adjoint_works: | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 417 | fixes f:: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 418 | assumes lf: "linear f" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 419 | shows "x \<bullet> adjoint f y = f x \<bullet> y" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 420 | proof - | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 421 | have "\<forall>y. \<exists>w. \<forall>x. f x \<bullet> y = x \<bullet> w" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 422 | proof (intro allI exI) | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 423 | fix y :: "'m" and x | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 424 | let ?w = "(\<Sum>i\<in>Basis. (f i \<bullet> y) *\<^sub>R i) :: 'n" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 425 | have "f x \<bullet> y = f (\<Sum>i\<in>Basis. (x \<bullet> i) *\<^sub>R i) \<bullet> y" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 426 | by (simp add: euclidean_representation) | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 427 | also have "\<dots> = (\<Sum>i\<in>Basis. (x \<bullet> i) *\<^sub>R f i) \<bullet> y" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 428 | unfolding linear_setsum[OF lf finite_Basis] | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 429 | by (simp add: linear_cmul[OF lf]) | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 430 | finally show "f x \<bullet> y = x \<bullet> ?w" | 
| 53406 | 431 | by (simp add: inner_setsum_left inner_setsum_right mult_commute) | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 432 | qed | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 433 | then show ?thesis | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 434 | unfolding adjoint_def choice_iff | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 435 | by (intro someI2_ex[where Q="\<lambda>f'. x \<bullet> f' y = f x \<bullet> y"]) auto | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 436 | qed | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 437 | |
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 438 | lemma adjoint_clauses: | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 439 | fixes f:: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 440 | assumes lf: "linear f" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 441 | shows "x \<bullet> adjoint f y = f x \<bullet> y" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 442 | and "adjoint f y \<bullet> x = y \<bullet> f x" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 443 | by (simp_all add: adjoint_works[OF lf] inner_commute) | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 444 | |
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 445 | lemma adjoint_linear: | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 446 | fixes f:: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 447 | assumes lf: "linear f" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 448 | shows "linear (adjoint f)" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 449 | by (simp add: lf linear_iff euclidean_eq_iff[where 'a='n] euclidean_eq_iff[where 'a='m] | 
| 53939 | 450 | adjoint_clauses[OF lf] inner_distrib) | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 451 | |
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 452 | lemma adjoint_adjoint: | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 453 | fixes f:: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 454 | assumes lf: "linear f" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 455 | shows "adjoint (adjoint f) = f" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 456 | by (rule adjoint_unique, simp add: adjoint_clauses [OF lf]) | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 457 | |
| 53406 | 458 | |
| 49522 | 459 | subsection {* Interlude: Some properties of real sets *}
 | 
| 44133 | 460 | |
| 53406 | 461 | lemma seq_mono_lemma: | 
| 462 | assumes "\<forall>(n::nat) \<ge> m. (d n :: real) < e n" | |
| 463 | and "\<forall>n \<ge> m. e n \<le> e m" | |
| 44133 | 464 | shows "\<forall>n \<ge> m. d n < e m" | 
| 53406 | 465 | using assms | 
| 466 | apply auto | |
| 44133 | 467 | apply (erule_tac x="n" in allE) | 
| 468 | apply (erule_tac x="n" in allE) | |
| 469 | apply auto | |
| 470 | done | |
| 471 | ||
| 53406 | 472 | lemma infinite_enumerate: | 
| 473 | assumes fS: "infinite S" | |
| 44133 | 474 | shows "\<exists>r. subseq r \<and> (\<forall>n. r n \<in> S)" | 
| 49525 | 475 | unfolding subseq_def | 
| 476 | using enumerate_in_set[OF fS] enumerate_mono[of _ _ S] fS by auto | |
| 44133 | 477 | |
| 478 | 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)" | |
| 49522 | 479 | apply auto | 
| 480 | apply (rule_tac x="d/2" in exI) | |
| 481 | apply auto | |
| 482 | done | |
| 44133 | 483 | |
| 484 | lemma triangle_lemma: | |
| 53406 | 485 | fixes x y z :: real | 
| 486 | assumes x: "0 \<le> x" | |
| 487 | and y: "0 \<le> y" | |
| 488 | and z: "0 \<le> z" | |
| 489 | and xy: "x\<^sup>2 \<le> y\<^sup>2 + z\<^sup>2" | |
| 490 | shows "x \<le> y + z" | |
| 49522 | 491 | proof - | 
| 53406 | 492 | have "y\<^sup>2 + z\<^sup>2 \<le> y\<^sup>2 + 2 *y * z + z\<^sup>2" | 
| 493 | using z y by (simp add: mult_nonneg_nonneg) | |
| 494 | with xy have th: "x\<^sup>2 \<le> (y + z)\<^sup>2" | |
| 495 | by (simp add: power2_eq_square field_simps) | |
| 496 | from y z have yz: "y + z \<ge> 0" | |
| 497 | by arith | |
| 44133 | 498 | from power2_le_imp_le[OF th yz] show ?thesis . | 
| 499 | qed | |
| 500 | ||
| 49522 | 501 | |
| 44133 | 502 | subsection {* A generic notion of "hull" (convex, affine, conic hull and closure). *}
 | 
| 503 | ||
| 53406 | 504 | definition hull :: "('a set \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set"  (infixl "hull" 75)
 | 
| 505 |   where "S hull s = \<Inter>{t. S t \<and> s \<subseteq> t}"
 | |
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 506 | |
| 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 507 | lemma hull_same: "S s \<Longrightarrow> S hull s = s" | 
| 44133 | 508 | unfolding hull_def by auto | 
| 509 | ||
| 53406 | 510 | lemma hull_in: "(\<And>T. Ball T S \<Longrightarrow> S (\<Inter>T)) \<Longrightarrow> S (S hull s)" | 
| 49522 | 511 | unfolding hull_def Ball_def by auto | 
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 512 | |
| 53406 | 513 | lemma hull_eq: "(\<And>T. Ball T S \<Longrightarrow> S (\<Inter>T)) \<Longrightarrow> (S hull s) = s \<longleftrightarrow> S s" | 
| 49522 | 514 | using hull_same[of S s] hull_in[of S s] by metis | 
| 44133 | 515 | |
| 516 | lemma hull_hull: "S hull (S hull s) = S hull s" | |
| 517 | unfolding hull_def by blast | |
| 518 | ||
| 519 | lemma hull_subset[intro]: "s \<subseteq> (S hull s)" | |
| 520 | unfolding hull_def by blast | |
| 521 | ||
| 53406 | 522 | lemma hull_mono: "s \<subseteq> t \<Longrightarrow> (S hull s) \<subseteq> (S hull t)" | 
| 44133 | 523 | unfolding hull_def by blast | 
| 524 | ||
| 53406 | 525 | lemma hull_antimono: "\<forall>x. S x \<longrightarrow> T x \<Longrightarrow> (T hull s) \<subseteq> (S hull s)" | 
| 44133 | 526 | unfolding hull_def by blast | 
| 527 | ||
| 53406 | 528 | lemma hull_minimal: "s \<subseteq> t \<Longrightarrow> S t \<Longrightarrow> (S hull s) \<subseteq> t" | 
| 44133 | 529 | unfolding hull_def by blast | 
| 530 | ||
| 53406 | 531 | lemma subset_hull: "S t \<Longrightarrow> S hull s \<subseteq> t \<longleftrightarrow> s \<subseteq> t" | 
| 44133 | 532 | unfolding hull_def by blast | 
| 533 | ||
| 53596 | 534 | lemma hull_UNIV: "S hull UNIV = UNIV" | 
| 535 | unfolding hull_def by auto | |
| 536 | ||
| 53406 | 537 | lemma hull_unique: "s \<subseteq> t \<Longrightarrow> S t \<Longrightarrow> (\<And>t'. s \<subseteq> t' \<Longrightarrow> S t' \<Longrightarrow> t \<subseteq> t') \<Longrightarrow> (S hull s = t)" | 
| 49652 | 538 | unfolding hull_def by auto | 
| 44133 | 539 | |
| 540 | 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"
 | |
| 541 |   using hull_minimal[of S "{x. P x}" Q]
 | |
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 542 | by (auto simp add: subset_eq) | 
| 44133 | 543 | |
| 49522 | 544 | lemma hull_inc: "x \<in> S \<Longrightarrow> x \<in> P hull S" | 
| 545 | by (metis hull_subset subset_eq) | |
| 44133 | 546 | |
| 547 | lemma hull_union_subset: "(S hull s) \<union> (S hull t) \<subseteq> (S hull (s \<union> t))" | |
| 49522 | 548 | unfolding Un_subset_iff by (metis hull_mono Un_upper1 Un_upper2) | 
| 549 | ||
| 550 | lemma hull_union: | |
| 53406 | 551 | assumes T: "\<And>T. Ball T S \<Longrightarrow> S (\<Inter>T)" | 
| 44133 | 552 | shows "S hull (s \<union> t) = S hull (S hull s \<union> S hull t)" | 
| 49522 | 553 | apply rule | 
| 554 | apply (rule hull_mono) | |
| 555 | unfolding Un_subset_iff | |
| 556 | apply (metis hull_subset Un_upper1 Un_upper2 subset_trans) | |
| 557 | apply (rule hull_minimal) | |
| 558 | apply (metis hull_union_subset) | |
| 559 | apply (metis hull_in T) | |
| 560 | done | |
| 44133 | 561 | |
| 562 | lemma hull_redundant_eq: "a \<in> (S hull s) \<longleftrightarrow> (S hull (insert a s) = S hull s)" | |
| 563 | unfolding hull_def by blast | |
| 564 | ||
| 53406 | 565 | lemma hull_redundant: "a \<in> (S hull s) \<Longrightarrow> (S hull (insert a s) = S hull s)" | 
| 49522 | 566 | by (metis hull_redundant_eq) | 
| 567 | ||
| 44133 | 568 | |
| 44666 | 569 | subsection {* Archimedean properties and useful consequences *}
 | 
| 44133 | 570 | |
| 53406 | 571 | lemma real_arch_simple: "\<exists>n. x \<le> real (n::nat)" | 
| 44666 | 572 | unfolding real_of_nat_def by (rule ex_le_of_nat) | 
| 44133 | 573 | |
| 574 | lemma real_arch_inv: "0 < e \<longleftrightarrow> (\<exists>n::nat. n \<noteq> 0 \<and> 0 < inverse (real n) \<and> inverse (real n) < e)" | |
| 575 | using reals_Archimedean | |
| 576 | apply (auto simp add: field_simps) | |
| 577 | apply (subgoal_tac "inverse (real n) > 0") | |
| 578 | apply arith | |
| 579 | apply simp | |
| 580 | done | |
| 581 | ||
| 53406 | 582 | lemma real_pow_lbound: "0 \<le> x \<Longrightarrow> 1 + real n * x \<le> (1 + x) ^ n" | 
| 49522 | 583 | proof (induct n) | 
| 584 | case 0 | |
| 585 | then show ?case by simp | |
| 44133 | 586 | next | 
| 587 | case (Suc n) | |
| 53406 | 588 | then have h: "1 + real n * x \<le> (1 + x) ^ n" | 
| 589 | by simp | |
| 590 | from h have p: "1 \<le> (1 + x) ^ n" | |
| 591 | using Suc.prems by simp | |
| 592 | from h have "1 + real n * x + x \<le> (1 + x) ^ n + x" | |
| 593 | by simp | |
| 594 | also have "\<dots> \<le> (1 + x) ^ Suc n" | |
| 595 | apply (subst diff_le_0_iff_le[symmetric]) | |
| 44133 | 596 | apply (simp add: field_simps) | 
| 53406 | 597 | using mult_left_mono[OF p Suc.prems] | 
| 598 | apply simp | |
| 49522 | 599 | done | 
| 53406 | 600 | finally show ?case | 
| 601 | by (simp add: real_of_nat_Suc field_simps) | |
| 44133 | 602 | qed | 
| 603 | ||
| 53406 | 604 | lemma real_arch_pow: | 
| 605 | fixes x :: real | |
| 606 | assumes x: "1 < x" | |
| 607 | shows "\<exists>n. y < x^n" | |
| 49522 | 608 | proof - | 
| 53406 | 609 | from x have x0: "x - 1 > 0" | 
| 610 | by arith | |
| 44666 | 611 | from reals_Archimedean3[OF x0, rule_format, of y] | 
| 53406 | 612 | obtain n :: nat where n: "y < real n * (x - 1)" by metis | 
| 44133 | 613 | from x0 have x00: "x- 1 \<ge> 0" by arith | 
| 614 | from real_pow_lbound[OF x00, of n] n | |
| 615 | have "y < x^n" by auto | |
| 616 | then show ?thesis by metis | |
| 617 | qed | |
| 618 | ||
| 53406 | 619 | lemma real_arch_pow2: | 
| 620 | fixes x :: real | |
| 621 | shows "\<exists>n. x < 2^ n" | |
| 44133 | 622 | using real_arch_pow[of 2 x] by simp | 
| 623 | ||
| 49522 | 624 | lemma real_arch_pow_inv: | 
| 53406 | 625 | fixes x y :: real | 
| 626 | assumes y: "y > 0" | |
| 627 | and x1: "x < 1" | |
| 44133 | 628 | shows "\<exists>n. x^n < y" | 
| 53406 | 629 | proof (cases "x > 0") | 
| 630 | case True | |
| 631 | with x1 have ix: "1 < 1/x" by (simp add: field_simps) | |
| 632 | from real_arch_pow[OF ix, of "1/y"] | |
| 633 | obtain n where n: "1/y < (1/x)^n" by blast | |
| 634 | then show ?thesis using y `x > 0` | |
| 635 | by (auto simp add: field_simps power_divide) | |
| 636 | next | |
| 637 | case False | |
| 638 | with y x1 show ?thesis | |
| 639 | apply auto | |
| 640 | apply (rule exI[where x=1]) | |
| 641 | apply auto | |
| 642 | done | |
| 44133 | 643 | qed | 
| 644 | ||
| 49522 | 645 | lemma forall_pos_mono: | 
| 53406 | 646 | "(\<And>d e::real. d < e \<Longrightarrow> P d \<Longrightarrow> P e) \<Longrightarrow> | 
| 647 | (\<And>n::nat. n \<noteq> 0 \<Longrightarrow> P (inverse (real n))) \<Longrightarrow> (\<And>e. 0 < e \<Longrightarrow> P e)" | |
| 44133 | 648 | by (metis real_arch_inv) | 
| 649 | ||
| 49522 | 650 | lemma forall_pos_mono_1: | 
| 53406 | 651 | "(\<And>d e::real. d < e \<Longrightarrow> P d \<Longrightarrow> P e) \<Longrightarrow> | 
| 53716 | 652 | (\<And>n. P (inverse (real (Suc n)))) \<Longrightarrow> 0 < e \<Longrightarrow> P e" | 
| 44133 | 653 | apply (rule forall_pos_mono) | 
| 654 | apply auto | |
| 655 | apply (atomize) | |
| 656 | apply (erule_tac x="n - 1" in allE) | |
| 657 | apply auto | |
| 658 | done | |
| 659 | ||
| 49522 | 660 | lemma real_archimedian_rdiv_eq_0: | 
| 53406 | 661 | assumes x0: "x \<ge> 0" | 
| 662 | and c: "c \<ge> 0" | |
| 663 | and xc: "\<forall>(m::nat)>0. real m * x \<le> c" | |
| 44133 | 664 | shows "x = 0" | 
| 53406 | 665 | proof (rule ccontr) | 
| 666 | assume "x \<noteq> 0" | |
| 667 | with x0 have xp: "x > 0" by arith | |
| 668 | from reals_Archimedean3[OF xp, rule_format, of c] | |
| 669 | obtain n :: nat where n: "c < real n * x" | |
| 670 | by blast | |
| 671 | with xc[rule_format, of n] have "n = 0" | |
| 672 | by arith | |
| 673 | with n c show False | |
| 674 | by simp | |
| 44133 | 675 | qed | 
| 676 | ||
| 49522 | 677 | |
| 44133 | 678 | subsection{* A bit of linear algebra. *}
 | 
| 679 | ||
| 49522 | 680 | definition (in real_vector) subspace :: "'a set \<Rightarrow> bool" | 
| 681 | where "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 *\<^sub>R x \<in>S )" | |
| 44133 | 682 | |
| 683 | definition (in real_vector) "span S = (subspace hull S)" | |
| 53716 | 684 | definition (in real_vector) "dependent S \<longleftrightarrow> (\<exists>a \<in> S. a \<in> span (S - {a}))"
 | 
| 53406 | 685 | abbreviation (in real_vector) "independent s \<equiv> \<not> dependent s" | 
| 44133 | 686 | |
| 687 | text {* Closure properties of subspaces. *}
 | |
| 688 | ||
| 53406 | 689 | lemma subspace_UNIV[simp]: "subspace UNIV" | 
| 690 | by (simp add: subspace_def) | |
| 691 | ||
| 692 | lemma (in real_vector) subspace_0: "subspace S \<Longrightarrow> 0 \<in> S" | |
| 693 | by (metis subspace_def) | |
| 694 | ||
| 695 | lemma (in real_vector) subspace_add: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x + y \<in> S" | |
| 44133 | 696 | by (metis subspace_def) | 
| 697 | ||
| 698 | lemma (in real_vector) subspace_mul: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> c *\<^sub>R x \<in> S" | |
| 699 | by (metis subspace_def) | |
| 700 | ||
| 701 | lemma subspace_neg: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> - x \<in> S" | |
| 702 | by (metis scaleR_minus1_left subspace_mul) | |
| 703 | ||
| 704 | lemma subspace_sub: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x - y \<in> S" | |
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53939diff
changeset | 705 | using subspace_add [of S x "- y"] by (simp add: subspace_neg) | 
| 44133 | 706 | |
| 707 | lemma (in real_vector) subspace_setsum: | |
| 53406 | 708 | assumes sA: "subspace A" | 
| 709 | and fB: "finite B" | |
| 49522 | 710 | and f: "\<forall>x\<in> B. f x \<in> A" | 
| 44133 | 711 | shows "setsum f B \<in> A" | 
| 712 | using fB f sA | |
| 49522 | 713 | by (induct rule: finite_induct[OF fB]) | 
| 714 | (simp add: subspace_def sA, auto simp add: sA subspace_add) | |
| 44133 | 715 | |
| 716 | lemma subspace_linear_image: | |
| 53406 | 717 | assumes lf: "linear f" | 
| 718 | and sS: "subspace S" | |
| 719 | shows "subspace (f ` S)" | |
| 44133 | 720 | using lf sS linear_0[OF lf] | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 721 | unfolding linear_iff subspace_def | 
| 44133 | 722 | apply (auto simp add: image_iff) | 
| 53406 | 723 | apply (rule_tac x="x + y" in bexI) | 
| 724 | apply auto | |
| 725 | apply (rule_tac x="c *\<^sub>R x" in bexI) | |
| 726 | apply auto | |
| 44133 | 727 | done | 
| 728 | ||
| 44521 | 729 | lemma subspace_linear_vimage: "linear f \<Longrightarrow> subspace S \<Longrightarrow> subspace (f -` S)" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 730 | by (auto simp add: subspace_def linear_iff linear_0[of f]) | 
| 44521 | 731 | |
| 53406 | 732 | lemma subspace_linear_preimage: "linear f \<Longrightarrow> subspace S \<Longrightarrow> subspace {x. f x \<in> S}"
 | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 733 | by (auto simp add: subspace_def linear_iff linear_0[of f]) | 
| 44133 | 734 | |
| 735 | lemma subspace_trivial: "subspace {0}"
 | |
| 736 | by (simp add: subspace_def) | |
| 737 | ||
| 53406 | 738 | lemma (in real_vector) subspace_inter: "subspace A \<Longrightarrow> subspace B \<Longrightarrow> subspace (A \<inter> B)" | 
| 44133 | 739 | by (simp add: subspace_def) | 
| 740 | ||
| 53406 | 741 | lemma subspace_Times: "subspace A \<Longrightarrow> subspace B \<Longrightarrow> subspace (A \<times> B)" | 
| 44521 | 742 | unfolding subspace_def zero_prod_def by simp | 
| 743 | ||
| 744 | text {* Properties of span. *}
 | |
| 745 | ||
| 53406 | 746 | lemma (in real_vector) span_mono: "A \<subseteq> B \<Longrightarrow> span A \<subseteq> span B" | 
| 44133 | 747 | by (metis span_def hull_mono) | 
| 748 | ||
| 53406 | 749 | lemma (in real_vector) subspace_span: "subspace (span S)" | 
| 44133 | 750 | unfolding span_def | 
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 751 | apply (rule hull_in) | 
| 44133 | 752 | apply (simp only: subspace_def Inter_iff Int_iff subset_eq) | 
| 753 | apply auto | |
| 754 | done | |
| 755 | ||
| 756 | lemma (in real_vector) span_clauses: | |
| 53406 | 757 | "a \<in> S \<Longrightarrow> a \<in> span S" | 
| 44133 | 758 | "0 \<in> span S" | 
| 53406 | 759 | "x\<in> span S \<Longrightarrow> y \<in> span S \<Longrightarrow> x + y \<in> span S" | 
| 44133 | 760 | "x \<in> span S \<Longrightarrow> c *\<^sub>R x \<in> span S" | 
| 53406 | 761 | by (metis span_def hull_subset subset_eq) (metis subspace_span subspace_def)+ | 
| 44133 | 762 | |
| 44521 | 763 | lemma span_unique: | 
| 49522 | 764 | "S \<subseteq> T \<Longrightarrow> subspace T \<Longrightarrow> (\<And>T'. S \<subseteq> T' \<Longrightarrow> subspace T' \<Longrightarrow> T \<subseteq> T') \<Longrightarrow> span S = T" | 
| 44521 | 765 | unfolding span_def by (rule hull_unique) | 
| 766 | ||
| 767 | lemma span_minimal: "S \<subseteq> T \<Longrightarrow> subspace T \<Longrightarrow> span S \<subseteq> T" | |
| 768 | unfolding span_def by (rule hull_minimal) | |
| 769 | ||
| 770 | lemma (in real_vector) span_induct: | |
| 49522 | 771 | assumes x: "x \<in> span S" | 
| 772 | and P: "subspace P" | |
| 53406 | 773 | and SP: "\<And>x. x \<in> S \<Longrightarrow> x \<in> P" | 
| 44521 | 774 | shows "x \<in> P" | 
| 49522 | 775 | proof - | 
| 53406 | 776 | from SP have SP': "S \<subseteq> P" | 
| 777 | by (simp add: subset_eq) | |
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 778 | from x hull_minimal[where S=subspace, OF SP' P, unfolded span_def[symmetric]] | 
| 53406 | 779 | show "x \<in> P" | 
| 780 | by (metis subset_eq) | |
| 44133 | 781 | qed | 
| 782 | ||
| 783 | lemma span_empty[simp]: "span {} = {0}"
 | |
| 784 | apply (simp add: span_def) | |
| 785 | apply (rule hull_unique) | |
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 786 | apply (auto simp add: subspace_def) | 
| 44133 | 787 | done | 
| 788 | ||
| 789 | lemma (in real_vector) independent_empty[intro]: "independent {}"
 | |
| 790 | by (simp add: dependent_def) | |
| 791 | ||
| 49522 | 792 | lemma dependent_single[simp]: "dependent {x} \<longleftrightarrow> x = 0"
 | 
| 44133 | 793 | unfolding dependent_def by auto | 
| 794 | ||
| 53406 | 795 | lemma (in real_vector) independent_mono: "independent A \<Longrightarrow> B \<subseteq> A \<Longrightarrow> independent B" | 
| 44133 | 796 | apply (clarsimp simp add: dependent_def span_mono) | 
| 797 |   apply (subgoal_tac "span (B - {a}) \<le> span (A - {a})")
 | |
| 798 | apply force | |
| 799 | apply (rule span_mono) | |
| 800 | apply auto | |
| 801 | done | |
| 802 | ||
| 803 | lemma (in real_vector) span_subspace: "A \<subseteq> B \<Longrightarrow> B \<le> span A \<Longrightarrow> subspace B \<Longrightarrow> span A = B" | |
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 804 | by (metis order_antisym span_def hull_minimal) | 
| 44133 | 805 | |
| 49711 | 806 | lemma (in real_vector) span_induct': | 
| 807 | assumes SP: "\<forall>x \<in> S. P x" | |
| 808 |     and P: "subspace {x. P x}"
 | |
| 809 | shows "\<forall>x \<in> span S. P x" | |
| 44133 | 810 | using span_induct SP P by blast | 
| 811 | ||
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 812 | inductive_set (in real_vector) span_induct_alt_help for S:: "'a set" | 
| 53406 | 813 | where | 
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 814 | span_induct_alt_help_0: "0 \<in> span_induct_alt_help S" | 
| 49522 | 815 | | span_induct_alt_help_S: | 
| 53406 | 816 | "x \<in> S \<Longrightarrow> z \<in> span_induct_alt_help S \<Longrightarrow> | 
| 817 | (c *\<^sub>R x + z) \<in> span_induct_alt_help S" | |
| 44133 | 818 | |
| 819 | lemma span_induct_alt': | |
| 53406 | 820 | assumes h0: "h 0" | 
| 821 | and hS: "\<And>c x y. x \<in> S \<Longrightarrow> h y \<Longrightarrow> h (c *\<^sub>R x + y)" | |
| 49522 | 822 | shows "\<forall>x \<in> span S. h x" | 
| 823 | proof - | |
| 53406 | 824 |   {
 | 
| 825 | fix x :: 'a | |
| 826 | assume x: "x \<in> span_induct_alt_help S" | |
| 44133 | 827 | have "h x" | 
| 828 | apply (rule span_induct_alt_help.induct[OF x]) | |
| 829 | apply (rule h0) | |
| 53406 | 830 | apply (rule hS) | 
| 831 | apply assumption | |
| 832 | apply assumption | |
| 833 | done | |
| 834 | } | |
| 44133 | 835 | note th0 = this | 
| 53406 | 836 |   {
 | 
| 837 | fix x | |
| 838 | assume x: "x \<in> span S" | |
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 839 | have "x \<in> span_induct_alt_help S" | 
| 49522 | 840 | proof (rule span_induct[where x=x and S=S]) | 
| 53406 | 841 | show "x \<in> span S" by (rule x) | 
| 49522 | 842 | next | 
| 53406 | 843 | fix x | 
| 844 | assume xS: "x \<in> S" | |
| 845 | from span_induct_alt_help_S[OF xS span_induct_alt_help_0, of 1] | |
| 846 | show "x \<in> span_induct_alt_help S" | |
| 847 | by simp | |
| 49522 | 848 | next | 
| 849 | have "0 \<in> span_induct_alt_help S" by (rule span_induct_alt_help_0) | |
| 850 | moreover | |
| 53406 | 851 |       {
 | 
| 852 | fix x y | |
| 49522 | 853 | assume h: "x \<in> span_induct_alt_help S" "y \<in> span_induct_alt_help S" | 
| 854 | from h have "(x + y) \<in> span_induct_alt_help S" | |
| 855 | apply (induct rule: span_induct_alt_help.induct) | |
| 856 | apply simp | |
| 857 | unfolding add_assoc | |
| 858 | apply (rule span_induct_alt_help_S) | |
| 859 | apply assumption | |
| 860 | apply simp | |
| 53406 | 861 | done | 
| 862 | } | |
| 49522 | 863 | moreover | 
| 53406 | 864 |       {
 | 
| 865 | fix c x | |
| 49522 | 866 | assume xt: "x \<in> span_induct_alt_help S" | 
| 867 | then have "(c *\<^sub>R x) \<in> span_induct_alt_help S" | |
| 868 | apply (induct rule: span_induct_alt_help.induct) | |
| 869 | apply (simp add: span_induct_alt_help_0) | |
| 870 | apply (simp add: scaleR_right_distrib) | |
| 871 | apply (rule span_induct_alt_help_S) | |
| 872 | apply assumption | |
| 873 | apply simp | |
| 874 | done } | |
| 53406 | 875 | ultimately show "subspace (span_induct_alt_help S)" | 
| 49522 | 876 | unfolding subspace_def Ball_def by blast | 
| 53406 | 877 | qed | 
| 878 | } | |
| 44133 | 879 | with th0 show ?thesis by blast | 
| 880 | qed | |
| 881 | ||
| 882 | lemma span_induct_alt: | |
| 53406 | 883 | assumes h0: "h 0" | 
| 884 | and hS: "\<And>c x y. x \<in> S \<Longrightarrow> h y \<Longrightarrow> h (c *\<^sub>R x + y)" | |
| 885 | and x: "x \<in> span S" | |
| 44133 | 886 | shows "h x" | 
| 49522 | 887 | using span_induct_alt'[of h S] h0 hS x by blast | 
| 44133 | 888 | |
| 889 | text {* Individual closure properties. *}
 | |
| 890 | ||
| 891 | lemma span_span: "span (span A) = span A" | |
| 892 | unfolding span_def hull_hull .. | |
| 893 | ||
| 53406 | 894 | lemma (in real_vector) span_superset: "x \<in> S \<Longrightarrow> x \<in> span S" | 
| 895 | by (metis span_clauses(1)) | |
| 896 | ||
| 897 | lemma (in real_vector) span_0: "0 \<in> span S" | |
| 898 | by (metis subspace_span subspace_0) | |
| 44133 | 899 | |
| 900 | lemma span_inc: "S \<subseteq> span S" | |
| 901 | by (metis subset_eq span_superset) | |
| 902 | ||
| 53406 | 903 | lemma (in real_vector) dependent_0: | 
| 904 | assumes "0 \<in> A" | |
| 905 | shows "dependent A" | |
| 906 | unfolding dependent_def | |
| 907 | apply (rule_tac x=0 in bexI) | |
| 908 | using assms span_0 | |
| 909 | apply auto | |
| 910 | done | |
| 911 | ||
| 912 | lemma (in real_vector) span_add: "x \<in> span S \<Longrightarrow> y \<in> span S \<Longrightarrow> x + y \<in> span S" | |
| 44133 | 913 | by (metis subspace_add subspace_span) | 
| 914 | ||
| 53406 | 915 | lemma (in real_vector) span_mul: "x \<in> span S \<Longrightarrow> c *\<^sub>R x \<in> span S" | 
| 44133 | 916 | by (metis subspace_span subspace_mul) | 
| 917 | ||
| 53406 | 918 | lemma span_neg: "x \<in> span S \<Longrightarrow> - x \<in> span S" | 
| 44133 | 919 | by (metis subspace_neg subspace_span) | 
| 920 | ||
| 53406 | 921 | lemma span_sub: "x \<in> span S \<Longrightarrow> y \<in> span S \<Longrightarrow> x - y \<in> span S" | 
| 44133 | 922 | by (metis subspace_span subspace_sub) | 
| 923 | ||
| 53406 | 924 | lemma (in real_vector) span_setsum: "finite A \<Longrightarrow> \<forall>x \<in> A. f x \<in> span S \<Longrightarrow> setsum f A \<in> span S" | 
| 44133 | 925 | by (rule subspace_setsum, rule subspace_span) | 
| 926 | ||
| 927 | lemma span_add_eq: "x \<in> span S \<Longrightarrow> x + y \<in> span S \<longleftrightarrow> y \<in> span S" | |
| 928 | apply (auto simp only: span_add span_sub) | |
| 53406 | 929 | apply (subgoal_tac "(x + y) - x \<in> span S") | 
| 930 | apply simp | |
| 49522 | 931 | apply (simp only: span_add span_sub) | 
| 932 | done | |
| 44133 | 933 | |
| 934 | text {* Mapping under linear image. *}
 | |
| 935 | ||
| 44521 | 936 | lemma image_subset_iff_subset_vimage: "f ` A \<subseteq> B \<longleftrightarrow> A \<subseteq> f -` B" | 
| 937 | by auto (* TODO: move *) | |
| 938 | ||
| 939 | lemma span_linear_image: | |
| 940 | assumes lf: "linear f" | |
| 44133 | 941 | shows "span (f ` S) = f ` (span S)" | 
| 44521 | 942 | proof (rule span_unique) | 
| 943 | show "f ` S \<subseteq> f ` span S" | |
| 944 | by (intro image_mono span_inc) | |
| 945 | show "subspace (f ` span S)" | |
| 946 | using lf subspace_span by (rule subspace_linear_image) | |
| 947 | next | |
| 53406 | 948 | fix T | 
| 949 | assume "f ` S \<subseteq> T" and "subspace T" | |
| 49522 | 950 | then show "f ` span S \<subseteq> T" | 
| 44521 | 951 | unfolding image_subset_iff_subset_vimage | 
| 952 | by (intro span_minimal subspace_linear_vimage lf) | |
| 953 | qed | |
| 954 | ||
| 955 | lemma span_union: "span (A \<union> B) = (\<lambda>(a, b). a + b) ` (span A \<times> span B)" | |
| 956 | proof (rule span_unique) | |
| 957 | show "A \<union> B \<subseteq> (\<lambda>(a, b). a + b) ` (span A \<times> span B)" | |
| 958 | by safe (force intro: span_clauses)+ | |
| 959 | next | |
| 960 | have "linear (\<lambda>(a, b). a + b)" | |
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 961 | by (simp add: linear_iff scaleR_add_right) | 
| 44521 | 962 | moreover have "subspace (span A \<times> span B)" | 
| 963 | by (intro subspace_Times subspace_span) | |
| 964 | ultimately show "subspace ((\<lambda>(a, b). a + b) ` (span A \<times> span B))" | |
| 965 | by (rule subspace_linear_image) | |
| 966 | next | |
| 49711 | 967 | fix T | 
| 968 | assume "A \<union> B \<subseteq> T" and "subspace T" | |
| 49522 | 969 | then show "(\<lambda>(a, b). a + b) ` (span A \<times> span B) \<subseteq> T" | 
| 44521 | 970 | by (auto intro!: subspace_add elim: span_induct) | 
| 44133 | 971 | qed | 
| 972 | ||
| 973 | text {* The key breakdown property. *}
 | |
| 974 | ||
| 44521 | 975 | lemma span_singleton: "span {x} = range (\<lambda>k. k *\<^sub>R x)"
 | 
| 976 | proof (rule span_unique) | |
| 977 |   show "{x} \<subseteq> range (\<lambda>k. k *\<^sub>R x)"
 | |
| 978 | by (fast intro: scaleR_one [symmetric]) | |
| 979 | show "subspace (range (\<lambda>k. k *\<^sub>R x))" | |
| 980 | unfolding subspace_def | |
| 981 | by (auto intro: scaleR_add_left [symmetric]) | |
| 53406 | 982 | next | 
| 983 | fix T | |
| 984 |   assume "{x} \<subseteq> T" and "subspace T"
 | |
| 985 | then show "range (\<lambda>k. k *\<^sub>R x) \<subseteq> T" | |
| 44521 | 986 | unfolding subspace_def by auto | 
| 987 | qed | |
| 988 | ||
| 49522 | 989 | lemma span_insert: "span (insert a S) = {x. \<exists>k. (x - k *\<^sub>R a) \<in> span S}"
 | 
| 44521 | 990 | proof - | 
| 991 |   have "span ({a} \<union> S) = {x. \<exists>k. (x - k *\<^sub>R a) \<in> span S}"
 | |
| 992 | unfolding span_union span_singleton | |
| 993 | apply safe | |
| 994 | apply (rule_tac x=k in exI, simp) | |
| 995 | apply (erule rev_image_eqI [OF SigmaI [OF rangeI]]) | |
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53939diff
changeset | 996 | apply auto | 
| 44521 | 997 | done | 
| 49522 | 998 | then show ?thesis by simp | 
| 44521 | 999 | qed | 
| 1000 | ||
| 44133 | 1001 | lemma span_breakdown: | 
| 53406 | 1002 | assumes bS: "b \<in> S" | 
| 1003 | and aS: "a \<in> span S" | |
| 44521 | 1004 |   shows "\<exists>k. a - k *\<^sub>R b \<in> span (S - {b})"
 | 
| 1005 |   using assms span_insert [of b "S - {b}"]
 | |
| 1006 | by (simp add: insert_absorb) | |
| 44133 | 1007 | |
| 53406 | 1008 | lemma span_breakdown_eq: "x \<in> span (insert a S) \<longleftrightarrow> (\<exists>k. x - k *\<^sub>R a \<in> span S)" | 
| 44521 | 1009 | by (simp add: span_insert) | 
| 44133 | 1010 | |
| 1011 | text {* Hence some "reversal" results. *}
 | |
| 1012 | ||
| 1013 | lemma in_span_insert: | |
| 49711 | 1014 | assumes a: "a \<in> span (insert b S)" | 
| 1015 | and na: "a \<notin> span S" | |
| 44133 | 1016 | shows "b \<in> span (insert a S)" | 
| 49663 | 1017 | proof - | 
| 44133 | 1018 | from span_breakdown[of b "insert b S" a, OF insertI1 a] | 
| 1019 |   obtain k where k: "a - k*\<^sub>R b \<in> span (S - {b})" by auto
 | |
| 53406 | 1020 | show ?thesis | 
| 1021 | proof (cases "k = 0") | |
| 1022 | case True | |
| 44133 | 1023 | with k have "a \<in> span S" | 
| 1024 | apply (simp) | |
| 1025 | apply (rule set_rev_mp) | |
| 1026 | apply assumption | |
| 1027 | apply (rule span_mono) | |
| 1028 | apply blast | |
| 1029 | done | |
| 53406 | 1030 | with na show ?thesis by blast | 
| 1031 | next | |
| 1032 | case False | |
| 44133 | 1033 | have eq: "b = (1/k) *\<^sub>R a - ((1/k) *\<^sub>R a - b)" by simp | 
| 53406 | 1034 | from False have eq': "(1/k) *\<^sub>R (a - k*\<^sub>R b) = (1/k) *\<^sub>R a - b" | 
| 44133 | 1035 | by (simp add: algebra_simps) | 
| 1036 |     from k have "(1/k) *\<^sub>R (a - k*\<^sub>R b) \<in> span (S - {b})"
 | |
| 1037 | by (rule span_mul) | |
| 49652 | 1038 |     then have th: "(1/k) *\<^sub>R a - b \<in> span (S - {b})"
 | 
| 44133 | 1039 | unfolding eq' . | 
| 53406 | 1040 | from k show ?thesis | 
| 44133 | 1041 | apply (subst eq) | 
| 1042 | apply (rule span_sub) | |
| 1043 | apply (rule span_mul) | |
| 1044 | apply (rule span_superset) | |
| 1045 | apply blast | |
| 1046 | apply (rule set_rev_mp) | |
| 1047 | apply (rule th) | |
| 1048 | apply (rule span_mono) | |
| 53406 | 1049 | using na | 
| 1050 | apply blast | |
| 1051 | done | |
| 1052 | qed | |
| 44133 | 1053 | qed | 
| 1054 | ||
| 1055 | lemma in_span_delete: | |
| 1056 | assumes a: "a \<in> span S" | |
| 53716 | 1057 |     and na: "a \<notin> span (S - {b})"
 | 
| 44133 | 1058 |   shows "b \<in> span (insert a (S - {b}))"
 | 
| 1059 | apply (rule in_span_insert) | |
| 1060 | apply (rule set_rev_mp) | |
| 1061 | apply (rule a) | |
| 1062 | apply (rule span_mono) | |
| 1063 | apply blast | |
| 1064 | apply (rule na) | |
| 1065 | done | |
| 1066 | ||
| 1067 | text {* Transitivity property. *}
 | |
| 1068 | ||
| 44521 | 1069 | lemma span_redundant: "x \<in> span S \<Longrightarrow> span (insert x S) = span S" | 
| 1070 | unfolding span_def by (rule hull_redundant) | |
| 1071 | ||
| 44133 | 1072 | lemma span_trans: | 
| 53406 | 1073 | assumes x: "x \<in> span S" | 
| 1074 | and y: "y \<in> span (insert x S)" | |
| 44133 | 1075 | shows "y \<in> span S" | 
| 44521 | 1076 | using assms by (simp only: span_redundant) | 
| 44133 | 1077 | |
| 1078 | lemma span_insert_0[simp]: "span (insert 0 S) = span S" | |
| 44521 | 1079 | by (simp only: span_redundant span_0) | 
| 44133 | 1080 | |
| 1081 | text {* An explicit expansion is sometimes needed. *}
 | |
| 1082 | ||
| 1083 | lemma span_explicit: | |
| 1084 |   "span P = {y. \<exists>S u. finite S \<and> S \<subseteq> P \<and> setsum (\<lambda>v. u v *\<^sub>R v) S = y}"
 | |
| 1085 |   (is "_ = ?E" is "_ = {y. ?h y}" is "_ = {y. \<exists>S u. ?Q S u y}")
 | |
| 49663 | 1086 | proof - | 
| 53406 | 1087 |   {
 | 
| 1088 | fix x | |
| 1089 | assume x: "x \<in> ?E" | |
| 44133 | 1090 | then obtain S u where fS: "finite S" and SP: "S\<subseteq>P" and u: "setsum (\<lambda>v. u v *\<^sub>R v) S = x" | 
| 1091 | by blast | |
| 1092 | have "x \<in> span P" | |
| 1093 | unfolding u[symmetric] | |
| 1094 | apply (rule span_setsum[OF fS]) | |
| 1095 | using span_mono[OF SP] | |
| 49522 | 1096 | apply (auto intro: span_superset span_mul) | 
| 53406 | 1097 | done | 
| 1098 | } | |
| 44133 | 1099 | moreover | 
| 1100 | have "\<forall>x \<in> span P. x \<in> ?E" | |
| 49522 | 1101 | proof (rule span_induct_alt') | 
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 1102 | show "0 \<in> Collect ?h" | 
| 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 1103 | unfolding mem_Collect_eq | 
| 49522 | 1104 |       apply (rule exI[where x="{}"])
 | 
| 1105 | apply simp | |
| 1106 | done | |
| 44133 | 1107 | next | 
| 1108 | fix c x y | |
| 53406 | 1109 | assume x: "x \<in> P" | 
| 1110 | assume hy: "y \<in> Collect ?h" | |
| 44133 | 1111 | from hy obtain S u where fS: "finite S" and SP: "S\<subseteq>P" | 
| 1112 | and u: "setsum (\<lambda>v. u v *\<^sub>R v) S = y" by blast | |
| 1113 | let ?S = "insert x S" | |
| 49522 | 1114 | let ?u = "\<lambda>y. if y = x then (if x \<in> S then u y + c else c) else u y" | 
| 53406 | 1115 | from fS SP x have th0: "finite (insert x S)" "insert x S \<subseteq> P" | 
| 1116 | by blast+ | |
| 1117 | have "?Q ?S ?u (c*\<^sub>R x + y)" | |
| 1118 | proof cases | |
| 1119 | assume xS: "x \<in> S" | |
| 44133 | 1120 |       have S1: "S = (S - {x}) \<union> {x}"
 | 
| 53716 | 1121 |         and Sss:"finite (S - {x})" "finite {x}" "(S - {x}) \<inter> {x} = {}"
 | 
| 53406 | 1122 | using xS fS by auto | 
| 44133 | 1123 |       have "setsum (\<lambda>v. ?u v *\<^sub>R v) ?S =(\<Sum>v\<in>S - {x}. u v *\<^sub>R v) + (u x + c) *\<^sub>R x"
 | 
| 1124 | using xS | |
| 1125 | by (simp add: setsum_Un_disjoint[OF Sss, unfolded S1[symmetric]] | |
| 1126 | setsum_clauses(2)[OF fS] cong del: if_weak_cong) | |
| 1127 | also have "\<dots> = (\<Sum>v\<in>S. u v *\<^sub>R v) + c *\<^sub>R x" | |
| 1128 | apply (simp add: setsum_Un_disjoint[OF Sss, unfolded S1[symmetric]]) | |
| 49522 | 1129 | apply (simp add: algebra_simps) | 
| 1130 | done | |
| 44133 | 1131 | also have "\<dots> = c*\<^sub>R x + y" | 
| 1132 | by (simp add: add_commute u) | |
| 1133 | finally have "setsum (\<lambda>v. ?u v *\<^sub>R v) ?S = c*\<^sub>R x + y" . | |
| 53406 | 1134 | then show ?thesis using th0 by blast | 
| 1135 | next | |
| 1136 | assume xS: "x \<notin> S" | |
| 49522 | 1137 | have th00: "(\<Sum>v\<in>S. (if v = x then c else u v) *\<^sub>R v) = y" | 
| 1138 | unfolding u[symmetric] | |
| 1139 | apply (rule setsum_cong2) | |
| 53406 | 1140 | using xS | 
| 1141 | apply auto | |
| 49522 | 1142 | done | 
| 53406 | 1143 | show ?thesis using fS xS th0 | 
| 1144 | by (simp add: th00 setsum_clauses add_commute cong del: if_weak_cong) | |
| 1145 | qed | |
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 1146 | then show "(c*\<^sub>R x + y) \<in> Collect ?h" | 
| 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 1147 | unfolding mem_Collect_eq | 
| 44133 | 1148 | apply - | 
| 1149 | apply (rule exI[where x="?S"]) | |
| 49522 | 1150 | apply (rule exI[where x="?u"]) | 
| 1151 | apply metis | |
| 1152 | done | |
| 44133 | 1153 | qed | 
| 1154 | ultimately show ?thesis by blast | |
| 1155 | qed | |
| 1156 | ||
| 1157 | lemma dependent_explicit: | |
| 49522 | 1158 | "dependent P \<longleftrightarrow> (\<exists>S u. finite S \<and> S \<subseteq> P \<and> (\<exists>v\<in>S. u v \<noteq> 0 \<and> setsum (\<lambda>v. u v *\<^sub>R v) S = 0))" | 
| 1159 | (is "?lhs = ?rhs") | |
| 1160 | proof - | |
| 53406 | 1161 |   {
 | 
| 1162 | assume dP: "dependent P" | |
| 44133 | 1163 | then obtain a S u where aP: "a \<in> P" and fS: "finite S" | 
| 1164 |       and SP: "S \<subseteq> P - {a}" and ua: "setsum (\<lambda>v. u v *\<^sub>R v) S = a"
 | |
| 1165 | unfolding dependent_def span_explicit by blast | |
| 1166 | let ?S = "insert a S" | |
| 1167 | let ?u = "\<lambda>y. if y = a then - 1 else u y" | |
| 1168 | let ?v = a | |
| 53406 | 1169 | from aP SP have aS: "a \<notin> S" | 
| 1170 | by blast | |
| 1171 | from fS SP aP have th0: "finite ?S" "?S \<subseteq> P" "?v \<in> ?S" "?u ?v \<noteq> 0" | |
| 1172 | by auto | |
| 44133 | 1173 | have s0: "setsum (\<lambda>v. ?u v *\<^sub>R v) ?S = 0" | 
| 1174 | using fS aS | |
| 1175 | apply (simp add: setsum_clauses field_simps) | |
| 1176 | apply (subst (2) ua[symmetric]) | |
| 1177 | apply (rule setsum_cong2) | |
| 49522 | 1178 | apply auto | 
| 1179 | done | |
| 44133 | 1180 | with th0 have ?rhs | 
| 1181 | apply - | |
| 1182 | apply (rule exI[where x= "?S"]) | |
| 1183 | apply (rule exI[where x= "?u"]) | |
| 49522 | 1184 | apply auto | 
| 1185 | done | |
| 1186 | } | |
| 44133 | 1187 | moreover | 
| 53406 | 1188 |   {
 | 
| 1189 | fix S u v | |
| 49522 | 1190 | assume fS: "finite S" | 
| 53406 | 1191 | and SP: "S \<subseteq> P" | 
| 1192 | and vS: "v \<in> S" | |
| 1193 | and uv: "u v \<noteq> 0" | |
| 49522 | 1194 | and u: "setsum (\<lambda>v. u v *\<^sub>R v) S = 0" | 
| 44133 | 1195 | let ?a = v | 
| 1196 |     let ?S = "S - {v}"
 | |
| 1197 | let ?u = "\<lambda>i. (- u i) / u v" | |
| 53406 | 1198 | have th0: "?a \<in> P" "finite ?S" "?S \<subseteq> P" | 
| 1199 | using fS SP vS by auto | |
| 1200 | have "setsum (\<lambda>v. ?u v *\<^sub>R v) ?S = | |
| 1201 | setsum (\<lambda>v. (- (inverse (u ?a))) *\<^sub>R (u v *\<^sub>R v)) S - ?u v *\<^sub>R v" | |
| 49522 | 1202 | using fS vS uv by (simp add: setsum_diff1 divide_inverse field_simps) | 
| 53406 | 1203 | also have "\<dots> = ?a" | 
| 1204 | unfolding scaleR_right.setsum [symmetric] u using uv by simp | |
| 1205 | finally have "setsum (\<lambda>v. ?u v *\<^sub>R v) ?S = ?a" . | |
| 44133 | 1206 | with th0 have ?lhs | 
| 1207 | unfolding dependent_def span_explicit | |
| 1208 | apply - | |
| 1209 | apply (rule bexI[where x= "?a"]) | |
| 1210 | apply (simp_all del: scaleR_minus_left) | |
| 1211 | apply (rule exI[where x= "?S"]) | |
| 49522 | 1212 | apply (auto simp del: scaleR_minus_left) | 
| 1213 | done | |
| 1214 | } | |
| 44133 | 1215 | ultimately show ?thesis by blast | 
| 1216 | qed | |
| 1217 | ||
| 1218 | ||
| 1219 | lemma span_finite: | |
| 1220 | assumes fS: "finite S" | |
| 1221 |   shows "span S = {y. \<exists>u. setsum (\<lambda>v. u v *\<^sub>R v) S = y}"
 | |
| 1222 | (is "_ = ?rhs") | |
| 49522 | 1223 | proof - | 
| 53406 | 1224 |   {
 | 
| 1225 | fix y | |
| 49711 | 1226 | assume y: "y \<in> span S" | 
| 53406 | 1227 | from y obtain S' u where fS': "finite S'" | 
| 1228 | and SS': "S' \<subseteq> S" | |
| 1229 | and u: "setsum (\<lambda>v. u v *\<^sub>R v) S' = y" | |
| 1230 | unfolding span_explicit by blast | |
| 44133 | 1231 | let ?u = "\<lambda>x. if x \<in> S' then u x else 0" | 
| 1232 | have "setsum (\<lambda>v. ?u v *\<^sub>R v) S = setsum (\<lambda>v. u v *\<^sub>R v) S'" | |
| 1233 | using SS' fS by (auto intro!: setsum_mono_zero_cong_right) | |
| 49522 | 1234 | then have "setsum (\<lambda>v. ?u v *\<^sub>R v) S = y" by (metis u) | 
| 53406 | 1235 | then have "y \<in> ?rhs" by auto | 
| 1236 | } | |
| 44133 | 1237 | moreover | 
| 53406 | 1238 |   {
 | 
| 1239 | fix y u | |
| 49522 | 1240 | assume u: "setsum (\<lambda>v. u v *\<^sub>R v) S = y" | 
| 53406 | 1241 | then have "y \<in> span S" using fS unfolding span_explicit by auto | 
| 1242 | } | |
| 44133 | 1243 | ultimately show ?thesis by blast | 
| 1244 | qed | |
| 1245 | ||
| 1246 | text {* This is useful for building a basis step-by-step. *}
 | |
| 1247 | ||
| 1248 | lemma independent_insert: | |
| 53406 | 1249 | "independent (insert a S) \<longleftrightarrow> | 
| 1250 | (if a \<in> S then independent S else independent S \<and> a \<notin> span S)" | |
| 1251 | (is "?lhs \<longleftrightarrow> ?rhs") | |
| 1252 | proof (cases "a \<in> S") | |
| 1253 | case True | |
| 1254 | then show ?thesis | |
| 1255 | using insert_absorb[OF True] by simp | |
| 1256 | next | |
| 1257 | case False | |
| 1258 | show ?thesis | |
| 1259 | proof | |
| 1260 | assume i: ?lhs | |
| 1261 | then show ?rhs | |
| 1262 | using False | |
| 1263 | apply simp | |
| 1264 | apply (rule conjI) | |
| 1265 | apply (rule independent_mono) | |
| 1266 | apply assumption | |
| 1267 | apply blast | |
| 1268 | apply (simp add: dependent_def) | |
| 1269 | done | |
| 1270 | next | |
| 1271 | assume i: ?rhs | |
| 1272 | show ?lhs | |
| 1273 | using i False | |
| 1274 | apply simp | |
| 1275 | apply (auto simp add: dependent_def) | |
| 1276 | apply (case_tac "aa = a") | |
| 1277 | apply auto | |
| 1278 |       apply (subgoal_tac "insert a S - {aa} = insert a (S - {aa})")
 | |
| 1279 | apply simp | |
| 1280 |       apply (subgoal_tac "a \<in> span (insert aa (S - {aa}))")
 | |
| 1281 |       apply (subgoal_tac "insert aa (S - {aa}) = S")
 | |
| 1282 | apply simp | |
| 1283 | apply blast | |
| 1284 | apply (rule in_span_insert) | |
| 1285 | apply assumption | |
| 1286 | apply blast | |
| 1287 | apply blast | |
| 1288 | done | |
| 1289 | qed | |
| 44133 | 1290 | qed | 
| 1291 | ||
| 1292 | text {* The degenerate case of the Exchange Lemma. *}
 | |
| 1293 | ||
| 1294 | lemma mem_delete: "x \<in> (A - {a}) \<longleftrightarrow> x \<noteq> a \<and> x \<in> A"
 | |
| 1295 | by blast | |
| 1296 | ||
| 1297 | lemma spanning_subset_independent: | |
| 49711 | 1298 | assumes BA: "B \<subseteq> A" | 
| 1299 | and iA: "independent A" | |
| 49522 | 1300 | and AsB: "A \<subseteq> span B" | 
| 44133 | 1301 | shows "A = B" | 
| 1302 | proof | |
| 49663 | 1303 | show "B \<subseteq> A" by (rule BA) | 
| 1304 | ||
| 44133 | 1305 | from span_mono[OF BA] span_mono[OF AsB] | 
| 1306 | have sAB: "span A = span B" unfolding span_span by blast | |
| 1307 | ||
| 53406 | 1308 |   {
 | 
| 1309 | fix x | |
| 1310 | assume x: "x \<in> A" | |
| 44133 | 1311 |     from iA have th0: "x \<notin> span (A - {x})"
 | 
| 1312 | unfolding dependent_def using x by blast | |
| 53406 | 1313 | from x have xsA: "x \<in> span A" | 
| 1314 | by (blast intro: span_superset) | |
| 44133 | 1315 |     have "A - {x} \<subseteq> A" by blast
 | 
| 53406 | 1316 |     then have th1: "span (A - {x}) \<subseteq> span A"
 | 
| 1317 | by (metis span_mono) | |
| 1318 |     {
 | |
| 1319 | assume xB: "x \<notin> B" | |
| 1320 |       from xB BA have "B \<subseteq> A - {x}"
 | |
| 1321 | by blast | |
| 1322 |       then have "span B \<subseteq> span (A - {x})"
 | |
| 1323 | by (metis span_mono) | |
| 1324 | with th1 th0 sAB have "x \<notin> span A" | |
| 1325 | by blast | |
| 1326 | with x have False | |
| 1327 | by (metis span_superset) | |
| 1328 | } | |
| 1329 | then have "x \<in> B" by blast | |
| 1330 | } | |
| 44133 | 1331 | then show "A \<subseteq> B" by blast | 
| 1332 | qed | |
| 1333 | ||
| 1334 | text {* The general case of the Exchange Lemma, the key to what follows. *}
 | |
| 1335 | ||
| 1336 | lemma exchange_lemma: | |
| 49711 | 1337 | assumes f:"finite t" | 
| 1338 | and i: "independent s" | |
| 1339 | and sp: "s \<subseteq> span t" | |
| 53406 | 1340 | 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'" | 
| 49663 | 1341 | using f i sp | 
| 49522 | 1342 | proof (induct "card (t - s)" arbitrary: s t rule: less_induct) | 
| 44133 | 1343 | case less | 
| 1344 | note ft = `finite t` and s = `independent s` and sp = `s \<subseteq> span t` | |
| 53406 | 1345 | 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'" | 
| 44133 | 1346 | let ?ths = "\<exists>t'. ?P t'" | 
| 53406 | 1347 |   {
 | 
| 1348 | assume st: "s \<subseteq> t" | |
| 1349 | from st ft span_mono[OF st] | |
| 1350 | have ?ths | |
| 1351 | apply - | |
| 1352 | apply (rule exI[where x=t]) | |
| 49522 | 1353 | apply (auto intro: span_superset) | 
| 53406 | 1354 | done | 
| 1355 | } | |
| 44133 | 1356 | moreover | 
| 53406 | 1357 |   {
 | 
| 1358 | assume st: "t \<subseteq> s" | |
| 1359 | from spanning_subset_independent[OF st s sp] st ft span_mono[OF st] | |
| 1360 | have ?ths | |
| 1361 | apply - | |
| 1362 | apply (rule exI[where x=t]) | |
| 1363 | apply (auto intro: span_superset) | |
| 1364 | done | |
| 1365 | } | |
| 44133 | 1366 | moreover | 
| 53406 | 1367 |   {
 | 
| 1368 | assume st: "\<not> s \<subseteq> t" "\<not> t \<subseteq> s" | |
| 1369 | from st(2) obtain b where b: "b \<in> t" "b \<notin> s" | |
| 1370 | by blast | |
| 1371 |     from b have "t - {b} - s \<subset> t - s"
 | |
| 1372 | by blast | |
| 1373 |     then have cardlt: "card (t - {b} - s) < card (t - s)"
 | |
| 1374 | using ft by (auto intro: psubset_card_mono) | |
| 1375 | from b ft have ct0: "card t \<noteq> 0" | |
| 1376 | by auto | |
| 1377 | have ?ths | |
| 1378 | proof cases | |
| 53716 | 1379 |       assume stb: "s \<subseteq> span (t - {b})"
 | 
| 1380 |       from ft have ftb: "finite (t - {b})"
 | |
| 53406 | 1381 | by auto | 
| 44133 | 1382 | from less(1)[OF cardlt ftb s stb] | 
| 53716 | 1383 |       obtain u where u: "card u = card (t - {b})" "s \<subseteq> u" "u \<subseteq> s \<union> (t - {b})" "s \<subseteq> span u"
 | 
| 49522 | 1384 | and fu: "finite u" by blast | 
| 44133 | 1385 | let ?w = "insert b u" | 
| 53406 | 1386 | have th0: "s \<subseteq> insert b u" | 
| 1387 | using u by blast | |
| 1388 | from u(3) b have "u \<subseteq> s \<union> t" | |
| 1389 | by blast | |
| 1390 | then have th1: "insert b u \<subseteq> s \<union> t" | |
| 1391 | using u b by blast | |
| 1392 | have bu: "b \<notin> u" | |
| 1393 | using b u by blast | |
| 1394 | from u(1) ft b have "card u = (card t - 1)" | |
| 1395 | by auto | |
| 49522 | 1396 | then have th2: "card (insert b u) = card t" | 
| 44133 | 1397 | using card_insert_disjoint[OF fu bu] ct0 by auto | 
| 1398 | from u(4) have "s \<subseteq> span u" . | |
| 53406 | 1399 | also have "\<dots> \<subseteq> span (insert b u)" | 
| 1400 | by (rule span_mono) blast | |
| 44133 | 1401 | finally have th3: "s \<subseteq> span (insert b u)" . | 
| 53406 | 1402 | from th0 th1 th2 th3 fu have th: "?P ?w" | 
| 1403 | by blast | |
| 1404 | from th show ?thesis by blast | |
| 1405 | next | |
| 53716 | 1406 |       assume stb: "\<not> s \<subseteq> span (t - {b})"
 | 
| 53406 | 1407 |       from stb obtain a where a: "a \<in> s" "a \<notin> span (t - {b})"
 | 
| 1408 | by blast | |
| 1409 | have ab: "a \<noteq> b" | |
| 1410 | using a b by blast | |
| 1411 | have at: "a \<notin> t" | |
| 1412 |         using a ab span_superset[of a "t- {b}"] by auto
 | |
| 44133 | 1413 |       have mlt: "card ((insert a (t - {b})) - s) < card (t - s)"
 | 
| 1414 | using cardlt ft a b by auto | |
| 53406 | 1415 |       have ft': "finite (insert a (t - {b}))"
 | 
| 1416 | using ft by auto | |
| 1417 |       {
 | |
| 1418 | fix x | |
| 1419 | assume xs: "x \<in> s" | |
| 1420 |         have t: "t \<subseteq> insert b (insert a (t - {b}))"
 | |
| 1421 | using b by auto | |
| 1422 | from b(1) have "b \<in> span t" | |
| 1423 | by (simp add: span_superset) | |
| 1424 |         have bs: "b \<in> span (insert a (t - {b}))"
 | |
| 1425 | apply (rule in_span_delete) | |
| 1426 | using a sp unfolding subset_eq | |
| 1427 | apply auto | |
| 1428 | done | |
| 1429 | from xs sp have "x \<in> span t" | |
| 1430 | by blast | |
| 1431 |         with span_mono[OF t] have x: "x \<in> span (insert b (insert a (t - {b})))" ..
 | |
| 1432 |         from span_trans[OF bs x] have "x \<in> span (insert a (t - {b}))" .
 | |
| 1433 | } | |
| 1434 |       then have sp': "s \<subseteq> span (insert a (t - {b}))"
 | |
| 1435 | by blast | |
| 1436 | from less(1)[OF mlt ft' s sp'] obtain u where u: | |
| 53716 | 1437 |         "card u = card (insert a (t - {b}))"
 | 
| 1438 |         "finite u" "s \<subseteq> u" "u \<subseteq> s \<union> insert a (t - {b})"
 | |
| 53406 | 1439 | "s \<subseteq> span u" by blast | 
| 1440 | from u a b ft at ct0 have "?P u" | |
| 1441 | by auto | |
| 1442 | then show ?thesis by blast | |
| 1443 | qed | |
| 44133 | 1444 | } | 
| 49522 | 1445 | ultimately show ?ths by blast | 
| 44133 | 1446 | qed | 
| 1447 | ||
| 1448 | text {* This implies corresponding size bounds. *}
 | |
| 1449 | ||
| 1450 | lemma independent_span_bound: | |
| 53406 | 1451 | assumes f: "finite t" | 
| 1452 | and i: "independent s" | |
| 1453 | and sp: "s \<subseteq> span t" | |
| 44133 | 1454 | shows "finite s \<and> card s \<le> card t" | 
| 1455 | by (metis exchange_lemma[OF f i sp] finite_subset card_mono) | |
| 1456 | ||
| 1457 | lemma finite_Atleast_Atmost_nat[simp]: "finite {f x |x. x\<in> (UNIV::'a::finite set)}"
 | |
| 49522 | 1458 | proof - | 
| 53406 | 1459 |   have eq: "{f x |x. x\<in> UNIV} = f ` UNIV"
 | 
| 1460 | by auto | |
| 44133 | 1461 | show ?thesis unfolding eq | 
| 1462 | apply (rule finite_imageI) | |
| 1463 | apply (rule finite) | |
| 1464 | done | |
| 1465 | qed | |
| 1466 | ||
| 53406 | 1467 | |
| 1468 | subsection {* Euclidean Spaces as Typeclass *}
 | |
| 44133 | 1469 | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1470 | lemma independent_Basis: "independent Basis" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1471 | unfolding dependent_def | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1472 | apply (subst span_finite) | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1473 | apply simp | 
| 44133 | 1474 | apply clarify | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1475 | apply (drule_tac f="inner a" in arg_cong) | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1476 | apply (simp add: inner_Basis inner_setsum_right eq_commute) | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1477 | done | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1478 | |
| 53939 | 1479 | lemma span_Basis [simp]: "span Basis = UNIV" | 
| 1480 | unfolding span_finite [OF finite_Basis] | |
| 1481 | by (fast intro: euclidean_representation) | |
| 44133 | 1482 | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1483 | lemma in_span_Basis: "x \<in> span Basis" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1484 | unfolding span_Basis .. | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1485 | |
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1486 | lemma Basis_le_norm: "b \<in> Basis \<Longrightarrow> \<bar>x \<bullet> b\<bar> \<le> norm x" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1487 | by (rule order_trans [OF Cauchy_Schwarz_ineq2]) simp | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1488 | |
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1489 | lemma norm_bound_Basis_le: "b \<in> Basis \<Longrightarrow> norm x \<le> e \<Longrightarrow> \<bar>x \<bullet> b\<bar> \<le> e" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1490 | by (metis Basis_le_norm order_trans) | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1491 | |
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1492 | lemma norm_bound_Basis_lt: "b \<in> Basis \<Longrightarrow> norm x < e \<Longrightarrow> \<bar>x \<bullet> b\<bar> < e" | 
| 53595 | 1493 | by (metis Basis_le_norm le_less_trans) | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1494 | |
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1495 | lemma norm_le_l1: "norm x \<le> (\<Sum>b\<in>Basis. \<bar>x \<bullet> b\<bar>)" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1496 | apply (subst euclidean_representation[of x, symmetric]) | 
| 44176 
eda112e9cdee
remove redundant lemma setsum_norm in favor of norm_setsum;
 huffman parents: 
44170diff
changeset | 1497 | apply (rule order_trans[OF norm_setsum]) | 
| 49522 | 1498 | apply (auto intro!: setsum_mono) | 
| 1499 | done | |
| 44133 | 1500 | |
| 1501 | lemma setsum_norm_allsubsets_bound: | |
| 1502 | fixes f:: "'a \<Rightarrow> 'n::euclidean_space" | |
| 53406 | 1503 | assumes fP: "finite P" | 
| 1504 | and fPs: "\<And>Q. Q \<subseteq> P \<Longrightarrow> norm (setsum f Q) \<le> e" | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1505 |   shows "(\<Sum>x\<in>P. norm (f x)) \<le> 2 * real DIM('n) * e"
 | 
| 49522 | 1506 | proof - | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1507 | have "(\<Sum>x\<in>P. norm (f x)) \<le> (\<Sum>x\<in>P. \<Sum>b\<in>Basis. \<bar>f x \<bullet> b\<bar>)" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1508 | by (rule setsum_mono) (rule norm_le_l1) | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1509 | also have "(\<Sum>x\<in>P. \<Sum>b\<in>Basis. \<bar>f x \<bullet> b\<bar>) = (\<Sum>b\<in>Basis. \<Sum>x\<in>P. \<bar>f x \<bullet> b\<bar>)" | 
| 44133 | 1510 | by (rule setsum_commute) | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1511 | also have "\<dots> \<le> of_nat (card (Basis :: 'n set)) * (2 * e)" | 
| 49522 | 1512 | proof (rule setsum_bounded) | 
| 53406 | 1513 | fix i :: 'n | 
| 1514 | assume i: "i \<in> Basis" | |
| 1515 | have "norm (\<Sum>x\<in>P. \<bar>f x \<bullet> i\<bar>) \<le> | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1516 |       norm ((\<Sum>x\<in>P \<inter> - {x. f x \<bullet> i < 0}. f x) \<bullet> i) + norm ((\<Sum>x\<in>P \<inter> {x. f x \<bullet> i < 0}. f x) \<bullet> i)"
 | 
| 55136 | 1517 | by (simp add: abs_real_def setsum_cases[OF fP] setsum_negf norm_triangle_ineq4 inner_setsum_left del: real_norm_def) | 
| 53406 | 1518 | also have "\<dots> \<le> e + e" | 
| 1519 | unfolding real_norm_def | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1520 | by (intro add_mono norm_bound_Basis_le i fPs) auto | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1521 | finally show "(\<Sum>x\<in>P. \<bar>f x \<bullet> i\<bar>) \<le> 2*e" by simp | 
| 44133 | 1522 | qed | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1523 |   also have "\<dots> = 2 * real DIM('n) * e"
 | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1524 | by (simp add: real_of_nat_def) | 
| 44133 | 1525 | finally show ?thesis . | 
| 1526 | qed | |
| 1527 | ||
| 53406 | 1528 | |
| 44133 | 1529 | subsection {* Linearity and Bilinearity continued *}
 | 
| 1530 | ||
| 1531 | lemma linear_bounded: | |
| 1532 | fixes f:: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector" | |
| 1533 | assumes lf: "linear f" | |
| 1534 | shows "\<exists>B. \<forall>x. norm (f x) \<le> B * norm x" | |
| 53939 | 1535 | proof | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1536 | let ?B = "\<Sum>b\<in>Basis. norm (f b)" | 
| 53939 | 1537 | show "\<forall>x. norm (f x) \<le> ?B * norm x" | 
| 1538 | proof | |
| 53406 | 1539 | fix x :: 'a | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1540 | let ?g = "\<lambda>b. (x \<bullet> b) *\<^sub>R f b" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1541 | have "norm (f x) = norm (f (\<Sum>b\<in>Basis. (x \<bullet> b) *\<^sub>R b))" | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1542 | unfolding euclidean_representation .. | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1543 | also have "\<dots> = norm (setsum ?g Basis)" | 
| 53939 | 1544 | by (simp add: linear_setsum [OF lf] linear_cmul [OF lf]) | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1545 | finally have th0: "norm (f x) = norm (setsum ?g Basis)" . | 
| 53939 | 1546 | have th: "\<forall>b\<in>Basis. norm (?g b) \<le> norm (f b) * norm x" | 
| 1547 | proof | |
| 53406 | 1548 | fix i :: 'a | 
| 1549 | assume i: "i \<in> Basis" | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1550 | from Basis_le_norm[OF i, of x] | 
| 53939 | 1551 | show "norm (?g i) \<le> norm (f i) * norm x" | 
| 49663 | 1552 | unfolding norm_scaleR | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1553 | apply (subst mult_commute) | 
| 49663 | 1554 | apply (rule mult_mono) | 
| 1555 | apply (auto simp add: field_simps) | |
| 53406 | 1556 | done | 
| 53939 | 1557 | qed | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1558 | from setsum_norm_le[of _ ?g, OF th] | 
| 53939 | 1559 | show "norm (f x) \<le> ?B * norm x" | 
| 53406 | 1560 | unfolding th0 setsum_left_distrib by metis | 
| 53939 | 1561 | qed | 
| 44133 | 1562 | qed | 
| 1563 | ||
| 1564 | lemma linear_conv_bounded_linear: | |
| 1565 | fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector" | |
| 1566 | shows "linear f \<longleftrightarrow> bounded_linear f" | |
| 1567 | proof | |
| 1568 | assume "linear f" | |
| 53939 | 1569 | then interpret f: linear f . | 
| 44133 | 1570 | show "bounded_linear f" | 
| 1571 | proof | |
| 1572 | have "\<exists>B. \<forall>x. norm (f x) \<le> B * norm x" | |
| 1573 | using `linear f` by (rule linear_bounded) | |
| 49522 | 1574 | then show "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K" | 
| 44133 | 1575 | by (simp add: mult_commute) | 
| 1576 | qed | |
| 1577 | next | |
| 1578 | assume "bounded_linear f" | |
| 1579 | then interpret f: bounded_linear f . | |
| 53939 | 1580 | show "linear f" .. | 
| 1581 | qed | |
| 1582 | ||
| 1583 | lemma linear_bounded_pos: | |
| 1584 | fixes f:: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector" | |
| 1585 | assumes lf: "linear f" | |
| 1586 | shows "\<exists>B > 0. \<forall>x. norm (f x) \<le> B * norm x" | |
| 1587 | proof - | |
| 1588 | have "\<exists>B > 0. \<forall>x. norm (f x) \<le> norm x * B" | |
| 1589 | using lf unfolding linear_conv_bounded_linear | |
| 1590 | by (rule bounded_linear.pos_bounded) | |
| 1591 | then show ?thesis | |
| 1592 | by (simp only: mult_commute) | |
| 44133 | 1593 | qed | 
| 1594 | ||
| 49522 | 1595 | lemma bounded_linearI': | 
| 1596 | fixes f::"'a::euclidean_space \<Rightarrow> 'b::real_normed_vector" | |
| 53406 | 1597 | assumes "\<And>x y. f (x + y) = f x + f y" | 
| 1598 | and "\<And>c x. f (c *\<^sub>R x) = c *\<^sub>R f x" | |
| 49522 | 1599 | shows "bounded_linear f" | 
| 53406 | 1600 | unfolding linear_conv_bounded_linear[symmetric] | 
| 49522 | 1601 | by (rule linearI[OF assms]) | 
| 44133 | 1602 | |
| 1603 | lemma bilinear_bounded: | |
| 1604 | fixes h:: "'m::euclidean_space \<Rightarrow> 'n::euclidean_space \<Rightarrow> 'k::real_normed_vector" | |
| 1605 | assumes bh: "bilinear h" | |
| 1606 | shows "\<exists>B. \<forall>x y. norm (h x y) \<le> B * norm x * norm y" | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1607 | proof (clarify intro!: exI[of _ "\<Sum>i\<in>Basis. \<Sum>j\<in>Basis. norm (h i j)"]) | 
| 53406 | 1608 | fix x :: 'm | 
| 1609 | fix y :: 'n | |
| 1610 | have "norm (h x y) = norm (h (setsum (\<lambda>i. (x \<bullet> i) *\<^sub>R i) Basis) (setsum (\<lambda>i. (y \<bullet> i) *\<^sub>R i) Basis))" | |
| 1611 | apply (subst euclidean_representation[where 'a='m]) | |
| 1612 | apply (subst euclidean_representation[where 'a='n]) | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1613 | apply rule | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1614 | done | 
| 53406 | 1615 | also have "\<dots> = norm (setsum (\<lambda> (i,j). h ((x \<bullet> i) *\<^sub>R i) ((y \<bullet> j) *\<^sub>R j)) (Basis \<times> Basis))" | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1616 | unfolding bilinear_setsum[OF bh finite_Basis finite_Basis] .. | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1617 | finally have th: "norm (h x y) = \<dots>" . | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1618 | show "norm (h x y) \<le> (\<Sum>i\<in>Basis. \<Sum>j\<in>Basis. norm (h i j)) * norm x * norm y" | 
| 53406 | 1619 | apply (auto simp add: setsum_left_distrib th setsum_cartesian_product) | 
| 1620 | apply (rule setsum_norm_le) | |
| 1621 | apply simp | |
| 1622 | apply (auto simp add: bilinear_rmul[OF bh] bilinear_lmul[OF bh] | |
| 1623 | field_simps simp del: scaleR_scaleR) | |
| 1624 | apply (rule mult_mono) | |
| 1625 | apply (auto simp add: zero_le_mult_iff Basis_le_norm) | |
| 1626 | apply (rule mult_mono) | |
| 1627 | apply (auto simp add: zero_le_mult_iff Basis_le_norm) | |
| 1628 | done | |
| 44133 | 1629 | qed | 
| 1630 | ||
| 1631 | lemma bilinear_conv_bounded_bilinear: | |
| 1632 | fixes h :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space \<Rightarrow> 'c::real_normed_vector" | |
| 1633 | shows "bilinear h \<longleftrightarrow> bounded_bilinear h" | |
| 1634 | proof | |
| 1635 | assume "bilinear h" | |
| 1636 | show "bounded_bilinear h" | |
| 1637 | proof | |
| 53406 | 1638 | fix x y z | 
| 1639 | show "h (x + y) z = h x z + h y z" | |
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 1640 | using `bilinear h` unfolding bilinear_def linear_iff by simp | 
| 44133 | 1641 | next | 
| 53406 | 1642 | fix x y z | 
| 1643 | show "h x (y + z) = h x y + h x z" | |
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 1644 | using `bilinear h` unfolding bilinear_def linear_iff by simp | 
| 44133 | 1645 | next | 
| 53406 | 1646 | fix r x y | 
| 1647 | show "h (scaleR r x) y = scaleR r (h x y)" | |
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 1648 | using `bilinear h` unfolding bilinear_def linear_iff | 
| 44133 | 1649 | by simp | 
| 1650 | next | |
| 53406 | 1651 | fix r x y | 
| 1652 | show "h x (scaleR r y) = scaleR r (h x y)" | |
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 1653 | using `bilinear h` unfolding bilinear_def linear_iff | 
| 44133 | 1654 | by simp | 
| 1655 | next | |
| 1656 | have "\<exists>B. \<forall>x y. norm (h x y) \<le> B * norm x * norm y" | |
| 1657 | using `bilinear h` by (rule bilinear_bounded) | |
| 49522 | 1658 | then show "\<exists>K. \<forall>x y. norm (h x y) \<le> norm x * norm y * K" | 
| 44133 | 1659 | by (simp add: mult_ac) | 
| 1660 | qed | |
| 1661 | next | |
| 1662 | assume "bounded_bilinear h" | |
| 1663 | then interpret h: bounded_bilinear h . | |
| 1664 | show "bilinear h" | |
| 1665 | unfolding bilinear_def linear_conv_bounded_linear | |
| 49522 | 1666 | using h.bounded_linear_left h.bounded_linear_right by simp | 
| 44133 | 1667 | qed | 
| 1668 | ||
| 53939 | 1669 | lemma bilinear_bounded_pos: | 
| 1670 | fixes h:: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space \<Rightarrow> 'c::real_normed_vector" | |
| 1671 | assumes bh: "bilinear h" | |
| 1672 | shows "\<exists>B > 0. \<forall>x y. norm (h x y) \<le> B * norm x * norm y" | |
| 1673 | proof - | |
| 1674 | have "\<exists>B > 0. \<forall>x y. norm (h x y) \<le> norm x * norm y * B" | |
| 1675 | using bh [unfolded bilinear_conv_bounded_bilinear] | |
| 1676 | by (rule bounded_bilinear.pos_bounded) | |
| 1677 | then show ?thesis | |
| 1678 | by (simp only: mult_ac) | |
| 1679 | qed | |
| 1680 | ||
| 49522 | 1681 | |
| 44133 | 1682 | subsection {* We continue. *}
 | 
| 1683 | ||
| 1684 | lemma independent_bound: | |
| 53716 | 1685 | fixes S :: "'a::euclidean_space set" | 
| 1686 |   shows "independent S \<Longrightarrow> finite S \<and> card S \<le> DIM('a)"
 | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1687 | using independent_span_bound[OF finite_Basis, of S] by auto | 
| 44133 | 1688 | |
| 49663 | 1689 | lemma dependent_biggerset: | 
| 53406 | 1690 |   "(finite (S::('a::euclidean_space) set) \<Longrightarrow> card S > DIM('a)) \<Longrightarrow> dependent S"
 | 
| 44133 | 1691 | by (metis independent_bound not_less) | 
| 1692 | ||
| 1693 | text {* Hence we can create a maximal independent subset. *}
 | |
| 1694 | ||
| 1695 | lemma maximal_independent_subset_extend: | |
| 53406 | 1696 | fixes S :: "'a::euclidean_space set" | 
| 1697 | assumes sv: "S \<subseteq> V" | |
| 49663 | 1698 | and iS: "independent S" | 
| 44133 | 1699 | shows "\<exists>B. S \<subseteq> B \<and> B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B" | 
| 1700 | using sv iS | |
| 49522 | 1701 | proof (induct "DIM('a) - card S" arbitrary: S rule: less_induct)
 | 
| 44133 | 1702 | case less | 
| 1703 | note sv = `S \<subseteq> V` and i = `independent S` | |
| 1704 | let ?P = "\<lambda>B. S \<subseteq> B \<and> B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B" | |
| 1705 | let ?ths = "\<exists>x. ?P x" | |
| 1706 |   let ?d = "DIM('a)"
 | |
| 53406 | 1707 | show ?ths | 
| 1708 | proof (cases "V \<subseteq> span S") | |
| 1709 | case True | |
| 1710 | then show ?thesis | |
| 1711 | using sv i by blast | |
| 1712 | next | |
| 1713 | case False | |
| 1714 | then obtain a where a: "a \<in> V" "a \<notin> span S" | |
| 1715 | by blast | |
| 1716 | from a have aS: "a \<notin> S" | |
| 1717 | by (auto simp add: span_superset) | |
| 1718 | have th0: "insert a S \<subseteq> V" | |
| 1719 | using a sv by blast | |
| 44133 | 1720 | from independent_insert[of a S] i a | 
| 53406 | 1721 | have th1: "independent (insert a S)" | 
| 1722 | by auto | |
| 44133 | 1723 | have mlt: "?d - card (insert a S) < ?d - card S" | 
| 49522 | 1724 | using aS a independent_bound[OF th1] by auto | 
| 44133 | 1725 | |
| 1726 | from less(1)[OF mlt th0 th1] | |
| 1727 | obtain B where B: "insert a S \<subseteq> B" "B \<subseteq> V" "independent B" " V \<subseteq> span B" | |
| 1728 | by blast | |
| 1729 | from B have "?P B" by auto | |
| 53406 | 1730 | then show ?thesis by blast | 
| 1731 | qed | |
| 44133 | 1732 | qed | 
| 1733 | ||
| 1734 | lemma maximal_independent_subset: | |
| 1735 |   "\<exists>(B:: ('a::euclidean_space) set). B\<subseteq> V \<and> independent B \<and> V \<subseteq> span B"
 | |
| 49522 | 1736 |   by (metis maximal_independent_subset_extend[of "{}:: ('a::euclidean_space) set"]
 | 
| 1737 | empty_subsetI independent_empty) | |
| 44133 | 1738 | |
| 1739 | ||
| 1740 | text {* Notion of dimension. *}
 | |
| 1741 | ||
| 53406 | 1742 | definition "dim V = (SOME n. \<exists>B. B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> card B = n)" | 
| 44133 | 1743 | |
| 49522 | 1744 | lemma basis_exists: | 
| 1745 |   "\<exists>B. (B :: ('a::euclidean_space) set) \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> (card B = dim V)"
 | |
| 1746 | 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)"] | |
| 1747 | using maximal_independent_subset[of V] independent_bound | |
| 1748 | by auto | |
| 44133 | 1749 | |
| 1750 | text {* Consequences of independence or spanning for cardinality. *}
 | |
| 1751 | ||
| 53406 | 1752 | lemma independent_card_le_dim: | 
| 1753 | fixes B :: "'a::euclidean_space set" | |
| 1754 | assumes "B \<subseteq> V" | |
| 1755 | and "independent B" | |
| 49522 | 1756 | shows "card B \<le> dim V" | 
| 44133 | 1757 | proof - | 
| 1758 | from basis_exists[of V] `B \<subseteq> V` | |
| 53406 | 1759 | obtain B' where "independent B'" | 
| 1760 | and "B \<subseteq> span B'" | |
| 1761 | and "card B' = dim V" | |
| 1762 | by blast | |
| 44133 | 1763 | with independent_span_bound[OF _ `independent B` `B \<subseteq> span B'`] independent_bound[of B'] | 
| 1764 | show ?thesis by auto | |
| 1765 | qed | |
| 1766 | ||
| 49522 | 1767 | lemma span_card_ge_dim: | 
| 53406 | 1768 | fixes B :: "'a::euclidean_space set" | 
| 1769 | shows "B \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> finite B \<Longrightarrow> dim V \<le> card B" | |
| 44133 | 1770 | by (metis basis_exists[of V] independent_span_bound subset_trans) | 
| 1771 | ||
| 1772 | lemma basis_card_eq_dim: | |
| 53406 | 1773 | fixes V :: "'a::euclidean_space set" | 
| 1774 | shows "B \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> independent B \<Longrightarrow> finite B \<and> card B = dim V" | |
| 44133 | 1775 | by (metis order_eq_iff independent_card_le_dim span_card_ge_dim independent_bound) | 
| 1776 | ||
| 53406 | 1777 | lemma dim_unique: | 
| 1778 | fixes B :: "'a::euclidean_space set" | |
| 1779 | shows "B \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> independent B \<Longrightarrow> card B = n \<Longrightarrow> dim V = n" | |
| 44133 | 1780 | by (metis basis_card_eq_dim) | 
| 1781 | ||
| 1782 | text {* More lemmas about dimension. *}
 | |
| 1783 | ||
| 53406 | 1784 | lemma dim_UNIV: "dim (UNIV :: 'a::euclidean_space set) = DIM('a)"
 | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1785 | using independent_Basis | 
| 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 1786 | by (intro dim_unique[of Basis]) auto | 
| 44133 | 1787 | |
| 1788 | lemma dim_subset: | |
| 53406 | 1789 | fixes S :: "'a::euclidean_space set" | 
| 1790 | shows "S \<subseteq> T \<Longrightarrow> dim S \<le> dim T" | |
| 44133 | 1791 | using basis_exists[of T] basis_exists[of S] | 
| 1792 | by (metis independent_card_le_dim subset_trans) | |
| 1793 | ||
| 53406 | 1794 | lemma dim_subset_UNIV: | 
| 1795 | fixes S :: "'a::euclidean_space set" | |
| 1796 |   shows "dim S \<le> DIM('a)"
 | |
| 44133 | 1797 | by (metis dim_subset subset_UNIV dim_UNIV) | 
| 1798 | ||
| 1799 | text {* Converses to those. *}
 | |
| 1800 | ||
| 1801 | lemma card_ge_dim_independent: | |
| 53406 | 1802 | fixes B :: "'a::euclidean_space set" | 
| 1803 | assumes BV: "B \<subseteq> V" | |
| 1804 | and iB: "independent B" | |
| 1805 | and dVB: "dim V \<le> card B" | |
| 44133 | 1806 | shows "V \<subseteq> span B" | 
| 53406 | 1807 | proof | 
| 1808 | fix a | |
| 1809 | assume aV: "a \<in> V" | |
| 1810 |   {
 | |
| 1811 | assume aB: "a \<notin> span B" | |
| 1812 | then have iaB: "independent (insert a B)" | |
| 1813 | using iB aV BV by (simp add: independent_insert) | |
| 1814 | from aV BV have th0: "insert a B \<subseteq> V" | |
| 1815 | by blast | |
| 1816 | from aB have "a \<notin>B" | |
| 1817 | by (auto simp add: span_superset) | |
| 1818 | with independent_card_le_dim[OF th0 iaB] dVB independent_bound[OF iB] | |
| 1819 | have False by auto | |
| 1820 | } | |
| 1821 | then show "a \<in> span B" by blast | |
| 44133 | 1822 | qed | 
| 1823 | ||
| 1824 | lemma card_le_dim_spanning: | |
| 49663 | 1825 |   assumes BV: "(B:: ('a::euclidean_space) set) \<subseteq> V"
 | 
| 1826 | and VB: "V \<subseteq> span B" | |
| 1827 | and fB: "finite B" | |
| 1828 | and dVB: "dim V \<ge> card B" | |
| 44133 | 1829 | shows "independent B" | 
| 49522 | 1830 | proof - | 
| 53406 | 1831 |   {
 | 
| 1832 | fix a | |
| 53716 | 1833 |     assume a: "a \<in> B" "a \<in> span (B - {a})"
 | 
| 53406 | 1834 | from a fB have c0: "card B \<noteq> 0" | 
| 1835 | by auto | |
| 53716 | 1836 |     from a fB have cb: "card (B - {a}) = card B - 1"
 | 
| 53406 | 1837 | by auto | 
| 53716 | 1838 |     from BV a have th0: "B - {a} \<subseteq> V"
 | 
| 53406 | 1839 | by blast | 
| 1840 |     {
 | |
| 1841 | fix x | |
| 1842 | assume x: "x \<in> V" | |
| 53716 | 1843 |       from a have eq: "insert a (B - {a}) = B"
 | 
| 53406 | 1844 | by blast | 
| 1845 | from x VB have x': "x \<in> span B" | |
| 1846 | by blast | |
| 44133 | 1847 | from span_trans[OF a(2), unfolded eq, OF x'] | 
| 53716 | 1848 |       have "x \<in> span (B - {a})" .
 | 
| 53406 | 1849 | } | 
| 53716 | 1850 |     then have th1: "V \<subseteq> span (B - {a})"
 | 
| 53406 | 1851 | by blast | 
| 53716 | 1852 |     have th2: "finite (B - {a})"
 | 
| 53406 | 1853 | using fB by auto | 
| 44133 | 1854 | from span_card_ge_dim[OF th0 th1 th2] | 
| 53716 | 1855 |     have c: "dim V \<le> card (B - {a})" .
 | 
| 53406 | 1856 | from c c0 dVB cb have False by simp | 
| 1857 | } | |
| 1858 | then show ?thesis | |
| 1859 | unfolding dependent_def by blast | |
| 44133 | 1860 | qed | 
| 1861 | ||
| 53406 | 1862 | lemma card_eq_dim: | 
| 1863 | fixes B :: "'a::euclidean_space set" | |
| 1864 | shows "B \<subseteq> V \<Longrightarrow> card B = dim V \<Longrightarrow> finite B \<Longrightarrow> independent B \<longleftrightarrow> V \<subseteq> span B" | |
| 49522 | 1865 | by (metis order_eq_iff card_le_dim_spanning card_ge_dim_independent) | 
| 44133 | 1866 | |
| 1867 | text {* More general size bound lemmas. *}
 | |
| 1868 | ||
| 1869 | lemma independent_bound_general: | |
| 53406 | 1870 | fixes S :: "'a::euclidean_space set" | 
| 1871 | shows "independent S \<Longrightarrow> finite S \<and> card S \<le> dim S" | |
| 44133 | 1872 | by (metis independent_card_le_dim independent_bound subset_refl) | 
| 1873 | ||
| 49522 | 1874 | lemma dependent_biggerset_general: | 
| 53406 | 1875 | fixes S :: "'a::euclidean_space set" | 
| 1876 | shows "(finite S \<Longrightarrow> card S > dim S) \<Longrightarrow> dependent S" | |
| 44133 | 1877 | using independent_bound_general[of S] by (metis linorder_not_le) | 
| 1878 | ||
| 53406 | 1879 | lemma dim_span: | 
| 1880 | fixes S :: "'a::euclidean_space set" | |
| 1881 | shows "dim (span S) = dim S" | |
| 49522 | 1882 | proof - | 
| 44133 | 1883 | have th0: "dim S \<le> dim (span S)" | 
| 1884 | by (auto simp add: subset_eq intro: dim_subset span_superset) | |
| 1885 | from basis_exists[of S] | |
| 53406 | 1886 | obtain B where B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S" | 
| 1887 | by blast | |
| 1888 | from B have fB: "finite B" "card B = dim S" | |
| 1889 | using independent_bound by blast+ | |
| 1890 | have bSS: "B \<subseteq> span S" | |
| 1891 | using B(1) by (metis subset_eq span_inc) | |
| 1892 | have sssB: "span S \<subseteq> span B" | |
| 1893 | using span_mono[OF B(3)] by (simp add: span_span) | |
| 44133 | 1894 | from span_card_ge_dim[OF bSS sssB fB(1)] th0 show ?thesis | 
| 49522 | 1895 | using fB(2) by arith | 
| 44133 | 1896 | qed | 
| 1897 | ||
| 53406 | 1898 | lemma subset_le_dim: | 
| 1899 | fixes S :: "'a::euclidean_space set" | |
| 1900 | shows "S \<subseteq> span T \<Longrightarrow> dim S \<le> dim T" | |
| 44133 | 1901 | by (metis dim_span dim_subset) | 
| 1902 | ||
| 53406 | 1903 | lemma span_eq_dim: | 
| 1904 | fixes S:: "'a::euclidean_space set" | |
| 1905 | shows "span S = span T \<Longrightarrow> dim S = dim T" | |
| 44133 | 1906 | by (metis dim_span) | 
| 1907 | ||
| 1908 | lemma spans_image: | |
| 49663 | 1909 | assumes lf: "linear f" | 
| 1910 | and VB: "V \<subseteq> span B" | |
| 44133 | 1911 | shows "f ` V \<subseteq> span (f ` B)" | 
| 49522 | 1912 | unfolding span_linear_image[OF lf] by (metis VB image_mono) | 
| 44133 | 1913 | |
| 1914 | lemma dim_image_le: | |
| 1915 | fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space" | |
| 49663 | 1916 | assumes lf: "linear f" | 
| 1917 | shows "dim (f ` S) \<le> dim (S)" | |
| 49522 | 1918 | proof - | 
| 44133 | 1919 | from basis_exists[of S] obtain B where | 
| 1920 | B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S" by blast | |
| 53406 | 1921 | from B have fB: "finite B" "card B = dim S" | 
| 1922 | using independent_bound by blast+ | |
| 44133 | 1923 | have "dim (f ` S) \<le> card (f ` B)" | 
| 1924 | apply (rule span_card_ge_dim) | |
| 53406 | 1925 | using lf B fB | 
| 1926 | apply (auto simp add: span_linear_image spans_image subset_image_iff) | |
| 49522 | 1927 | done | 
| 53406 | 1928 | also have "\<dots> \<le> dim S" | 
| 1929 | using card_image_le[OF fB(1)] fB by simp | |
| 44133 | 1930 | finally show ?thesis . | 
| 1931 | qed | |
| 1932 | ||
| 1933 | text {* Relation between bases and injectivity/surjectivity of map. *}
 | |
| 1934 | ||
| 1935 | lemma spanning_surjective_image: | |
| 1936 | assumes us: "UNIV \<subseteq> span S" | |
| 53406 | 1937 | and lf: "linear f" | 
| 1938 | and sf: "surj f" | |
| 44133 | 1939 | shows "UNIV \<subseteq> span (f ` S)" | 
| 49663 | 1940 | proof - | 
| 53406 | 1941 | have "UNIV \<subseteq> f ` UNIV" | 
| 1942 | using sf by (auto simp add: surj_def) | |
| 1943 | also have " \<dots> \<subseteq> span (f ` S)" | |
| 1944 | using spans_image[OF lf us] . | |
| 1945 | finally show ?thesis . | |
| 44133 | 1946 | qed | 
| 1947 | ||
| 1948 | lemma independent_injective_image: | |
| 49663 | 1949 | assumes iS: "independent S" | 
| 1950 | and lf: "linear f" | |
| 1951 | and fi: "inj f" | |
| 44133 | 1952 | shows "independent (f ` S)" | 
| 49663 | 1953 | proof - | 
| 53406 | 1954 |   {
 | 
| 1955 | fix a | |
| 49663 | 1956 |     assume a: "a \<in> S" "f a \<in> span (f ` S - {f a})"
 | 
| 53406 | 1957 |     have eq: "f ` S - {f a} = f ` (S - {a})"
 | 
| 1958 | using fi by (auto simp add: inj_on_def) | |
| 53716 | 1959 |     from a have "f a \<in> f ` span (S - {a})"
 | 
| 53406 | 1960 |       unfolding eq span_linear_image[OF lf, of "S - {a}"] by blast
 | 
| 53716 | 1961 |     then have "a \<in> span (S - {a})"
 | 
| 53406 | 1962 | using fi by (auto simp add: inj_on_def) | 
| 1963 | with a(1) iS have False | |
| 1964 | by (simp add: dependent_def) | |
| 1965 | } | |
| 1966 | then show ?thesis | |
| 1967 | unfolding dependent_def by blast | |
| 44133 | 1968 | qed | 
| 1969 | ||
| 1970 | text {* Picking an orthogonal replacement for a spanning set. *}
 | |
| 1971 | ||
| 53406 | 1972 | (* FIXME : Move to some general theory ?*) | 
| 44133 | 1973 | definition "pairwise R S \<longleftrightarrow> (\<forall>x \<in> S. \<forall>y\<in> S. x\<noteq>y \<longrightarrow> R x y)" | 
| 1974 | ||
| 53406 | 1975 | lemma vector_sub_project_orthogonal: | 
| 1976 | fixes b x :: "'a::euclidean_space" | |
| 1977 | shows "b \<bullet> (x - ((b \<bullet> x) / (b \<bullet> b)) *\<^sub>R b) = 0" | |
| 44133 | 1978 | unfolding inner_simps by auto | 
| 1979 | ||
| 44528 | 1980 | lemma pairwise_orthogonal_insert: | 
| 1981 | assumes "pairwise orthogonal S" | |
| 49522 | 1982 | and "\<And>y. y \<in> S \<Longrightarrow> orthogonal x y" | 
| 44528 | 1983 | shows "pairwise orthogonal (insert x S)" | 
| 1984 | using assms unfolding pairwise_def | |
| 1985 | by (auto simp add: orthogonal_commute) | |
| 1986 | ||
| 44133 | 1987 | lemma basis_orthogonal: | 
| 53406 | 1988 | fixes B :: "'a::real_inner set" | 
| 44133 | 1989 | assumes fB: "finite B" | 
| 1990 | shows "\<exists>C. finite C \<and> card C \<le> card B \<and> span C = span B \<and> pairwise orthogonal C" | |
| 1991 | (is " \<exists>C. ?P B C") | |
| 49522 | 1992 | using fB | 
| 1993 | proof (induct rule: finite_induct) | |
| 1994 | case empty | |
| 53406 | 1995 | then show ?case | 
| 1996 |     apply (rule exI[where x="{}"])
 | |
| 1997 | apply (auto simp add: pairwise_def) | |
| 1998 | done | |
| 44133 | 1999 | next | 
| 49522 | 2000 | case (insert a B) | 
| 44133 | 2001 | note fB = `finite B` and aB = `a \<notin> B` | 
| 2002 | from `\<exists>C. finite C \<and> card C \<le> card B \<and> span C = span B \<and> pairwise orthogonal C` | |
| 2003 | obtain C where C: "finite C" "card C \<le> card B" | |
| 2004 | "span C = span B" "pairwise orthogonal C" by blast | |
| 2005 | let ?a = "a - setsum (\<lambda>x. (x \<bullet> a / (x \<bullet> x)) *\<^sub>R x) C" | |
| 2006 | let ?C = "insert ?a C" | |
| 53406 | 2007 | from C(1) have fC: "finite ?C" | 
| 2008 | by simp | |
| 49522 | 2009 | from fB aB C(1,2) have cC: "card ?C \<le> card (insert a B)" | 
| 2010 | by (simp add: card_insert_if) | |
| 53406 | 2011 |   {
 | 
| 2012 | fix x k | |
| 49522 | 2013 | have th0: "\<And>(a::'a) b c. a - (b - c) = c + (a - b)" | 
| 2014 | by (simp add: field_simps) | |
| 44133 | 2015 | have "x - k *\<^sub>R (a - (\<Sum>x\<in>C. (x \<bullet> a / (x \<bullet> x)) *\<^sub>R x)) \<in> span C \<longleftrightarrow> x - k *\<^sub>R a \<in> span C" | 
| 2016 | apply (simp only: scaleR_right_diff_distrib th0) | |
| 2017 | apply (rule span_add_eq) | |
| 2018 | apply (rule span_mul) | |
| 2019 | apply (rule span_setsum[OF C(1)]) | |
| 2020 | apply clarify | |
| 2021 | apply (rule span_mul) | |
| 49522 | 2022 | apply (rule span_superset) | 
| 2023 | apply assumption | |
| 53406 | 2024 | done | 
| 2025 | } | |
| 44133 | 2026 | then have SC: "span ?C = span (insert a B)" | 
| 2027 | unfolding set_eq_iff span_breakdown_eq C(3)[symmetric] by auto | |
| 53406 | 2028 |   {
 | 
| 2029 | fix y | |
| 2030 | assume yC: "y \<in> C" | |
| 2031 |     then have Cy: "C = insert y (C - {y})"
 | |
| 2032 | by blast | |
| 2033 |     have fth: "finite (C - {y})"
 | |
| 2034 | using C by simp | |
| 44528 | 2035 | have "orthogonal ?a y" | 
| 2036 | unfolding orthogonal_def | |
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53939diff
changeset | 2037 | unfolding inner_diff inner_setsum_left right_minus_eq | 
| 44528 | 2038 | unfolding setsum_diff1' [OF `finite C` `y \<in> C`] | 
| 2039 | apply (clarsimp simp add: inner_commute[of y a]) | |
| 2040 | apply (rule setsum_0') | |
| 2041 | apply clarsimp | |
| 2042 | apply (rule C(4)[unfolded pairwise_def orthogonal_def, rule_format]) | |
| 53406 | 2043 | using `y \<in> C` by auto | 
| 2044 | } | |
| 44528 | 2045 | with `pairwise orthogonal C` have CPO: "pairwise orthogonal ?C" | 
| 2046 | by (rule pairwise_orthogonal_insert) | |
| 53406 | 2047 | from fC cC SC CPO have "?P (insert a B) ?C" | 
| 2048 | by blast | |
| 44133 | 2049 | then show ?case by blast | 
| 2050 | qed | |
| 2051 | ||
| 2052 | lemma orthogonal_basis_exists: | |
| 2053 |   fixes V :: "('a::euclidean_space) set"
 | |
| 2054 | shows "\<exists>B. independent B \<and> B \<subseteq> span V \<and> V \<subseteq> span B \<and> (card B = dim V) \<and> pairwise orthogonal B" | |
| 49663 | 2055 | proof - | 
| 49522 | 2056 | from basis_exists[of V] obtain B where | 
| 53406 | 2057 | B: "B \<subseteq> V" "independent B" "V \<subseteq> span B" "card B = dim V" | 
| 2058 | by blast | |
| 2059 | from B have fB: "finite B" "card B = dim V" | |
| 2060 | using independent_bound by auto | |
| 44133 | 2061 | from basis_orthogonal[OF fB(1)] obtain C where | 
| 53406 | 2062 | C: "finite C" "card C \<le> card B" "span C = span B" "pairwise orthogonal C" | 
| 2063 | by blast | |
| 2064 | from C B have CSV: "C \<subseteq> span V" | |
| 2065 | by (metis span_inc span_mono subset_trans) | |
| 2066 | from span_mono[OF B(3)] C have SVC: "span V \<subseteq> span C" | |
| 2067 | by (simp add: span_span) | |
| 44133 | 2068 | from card_le_dim_spanning[OF CSV SVC C(1)] C(2,3) fB | 
| 53406 | 2069 | have iC: "independent C" | 
| 44133 | 2070 | by (simp add: dim_span) | 
| 53406 | 2071 | from C fB have "card C \<le> dim V" | 
| 2072 | by simp | |
| 2073 | moreover have "dim V \<le> card C" | |
| 2074 | using span_card_ge_dim[OF CSV SVC C(1)] | |
| 2075 | by (simp add: dim_span) | |
| 2076 | ultimately have CdV: "card C = dim V" | |
| 2077 | using C(1) by simp | |
| 2078 | from C B CSV CdV iC show ?thesis | |
| 2079 | by auto | |
| 44133 | 2080 | qed | 
| 2081 | ||
| 2082 | lemma span_eq: "span S = span T \<longleftrightarrow> S \<subseteq> span T \<and> T \<subseteq> span S" | |
| 2083 | using span_inc[unfolded subset_eq] using span_mono[of T "span S"] span_mono[of S "span T"] | |
| 49522 | 2084 | by (auto simp add: span_span) | 
| 44133 | 2085 | |
| 2086 | text {* Low-dimensional subset is in a hyperplane (weak orthogonal complement). *}
 | |
| 2087 | ||
| 49522 | 2088 | lemma span_not_univ_orthogonal: | 
| 53406 | 2089 | fixes S :: "'a::euclidean_space set" | 
| 44133 | 2090 | assumes sU: "span S \<noteq> UNIV" | 
| 2091 | shows "\<exists>(a::'a). a \<noteq>0 \<and> (\<forall>x \<in> span S. a \<bullet> x = 0)" | |
| 49522 | 2092 | proof - | 
| 53406 | 2093 | from sU obtain a where a: "a \<notin> span S" | 
| 2094 | by blast | |
| 44133 | 2095 | from orthogonal_basis_exists obtain B where | 
| 2096 | B: "independent B" "B \<subseteq> span S" "S \<subseteq> span B" "card B = dim S" "pairwise orthogonal B" | |
| 2097 | by blast | |
| 53406 | 2098 | from B have fB: "finite B" "card B = dim S" | 
| 2099 | using independent_bound by auto | |
| 44133 | 2100 | from span_mono[OF B(2)] span_mono[OF B(3)] | 
| 53406 | 2101 | have sSB: "span S = span B" | 
| 2102 | by (simp add: span_span) | |
| 44133 | 2103 | let ?a = "a - setsum (\<lambda>b. (a \<bullet> b / (b \<bullet> b)) *\<^sub>R b) B" | 
| 2104 | have "setsum (\<lambda>b. (a \<bullet> b / (b \<bullet> b)) *\<^sub>R b) B \<in> span S" | |
| 2105 | unfolding sSB | |
| 2106 | apply (rule span_setsum[OF fB(1)]) | |
| 2107 | apply clarsimp | |
| 2108 | apply (rule span_mul) | |
| 49522 | 2109 | apply (rule span_superset) | 
| 2110 | apply assumption | |
| 2111 | done | |
| 53406 | 2112 | with a have a0:"?a \<noteq> 0" | 
| 2113 | by auto | |
| 44133 | 2114 | have "\<forall>x\<in>span B. ?a \<bullet> x = 0" | 
| 49522 | 2115 | proof (rule span_induct') | 
| 2116 |     show "subspace {x. ?a \<bullet> x = 0}"
 | |
| 2117 | by (auto simp add: subspace_def inner_add) | |
| 2118 | next | |
| 53406 | 2119 |     {
 | 
| 2120 | fix x | |
| 2121 | assume x: "x \<in> B" | |
| 2122 |       from x have B': "B = insert x (B - {x})"
 | |
| 2123 | by blast | |
| 2124 |       have fth: "finite (B - {x})"
 | |
| 2125 | using fB by simp | |
| 44133 | 2126 | have "?a \<bullet> x = 0" | 
| 53406 | 2127 | apply (subst B') | 
| 2128 | using fB fth | |
| 44133 | 2129 | unfolding setsum_clauses(2)[OF fth] | 
| 2130 | apply simp unfolding inner_simps | |
| 44527 
bf8014b4f933
remove dot_lsum and dot_rsum in favor of inner_setsum_{left,right}
 huffman parents: 
44521diff
changeset | 2131 | apply (clarsimp simp add: inner_add inner_setsum_left) | 
| 44133 | 2132 | apply (rule setsum_0', rule ballI) | 
| 2133 | unfolding inner_commute | |
| 49711 | 2134 | apply (auto simp add: x field_simps | 
| 2135 | intro: B(5)[unfolded pairwise_def orthogonal_def, rule_format]) | |
| 53406 | 2136 | done | 
| 2137 | } | |
| 2138 | then show "\<forall>x \<in> B. ?a \<bullet> x = 0" | |
| 2139 | by blast | |
| 44133 | 2140 | qed | 
| 53406 | 2141 | with a0 show ?thesis | 
| 2142 | unfolding sSB by (auto intro: exI[where x="?a"]) | |
| 44133 | 2143 | qed | 
| 2144 | ||
| 2145 | lemma span_not_univ_subset_hyperplane: | |
| 53406 | 2146 | fixes S :: "'a::euclidean_space set" | 
| 2147 | assumes SU: "span S \<noteq> UNIV" | |
| 44133 | 2148 |   shows "\<exists> a. a \<noteq>0 \<and> span S \<subseteq> {x. a \<bullet> x = 0}"
 | 
| 2149 | using span_not_univ_orthogonal[OF SU] by auto | |
| 2150 | ||
| 49663 | 2151 | lemma lowdim_subset_hyperplane: | 
| 53406 | 2152 | fixes S :: "'a::euclidean_space set" | 
| 44133 | 2153 |   assumes d: "dim S < DIM('a)"
 | 
| 2154 |   shows "\<exists>(a::'a). a  \<noteq> 0 \<and> span S \<subseteq> {x. a \<bullet> x = 0}"
 | |
| 49522 | 2155 | proof - | 
| 53406 | 2156 |   {
 | 
| 2157 | assume "span S = UNIV" | |
| 2158 |     then have "dim (span S) = dim (UNIV :: ('a) set)"
 | |
| 2159 | by simp | |
| 2160 |     then have "dim S = DIM('a)"
 | |
| 2161 | by (simp add: dim_span dim_UNIV) | |
| 2162 | with d have False by arith | |
| 2163 | } | |
| 2164 | then have th: "span S \<noteq> UNIV" | |
| 2165 | by blast | |
| 44133 | 2166 | from span_not_univ_subset_hyperplane[OF th] show ?thesis . | 
| 2167 | qed | |
| 2168 | ||
| 2169 | text {* We can extend a linear basis-basis injection to the whole set. *}
 | |
| 2170 | ||
| 2171 | lemma linear_indep_image_lemma: | |
| 49663 | 2172 | assumes lf: "linear f" | 
| 2173 | and fB: "finite B" | |
| 49522 | 2174 | and ifB: "independent (f ` B)" | 
| 49663 | 2175 | and fi: "inj_on f B" | 
| 2176 | and xsB: "x \<in> span B" | |
| 49522 | 2177 | and fx: "f x = 0" | 
| 44133 | 2178 | shows "x = 0" | 
| 2179 | using fB ifB fi xsB fx | |
| 49522 | 2180 | proof (induct arbitrary: x rule: finite_induct[OF fB]) | 
| 49663 | 2181 | case 1 | 
| 2182 | then show ?case by auto | |
| 44133 | 2183 | next | 
| 2184 | case (2 a b x) | |
| 2185 | have fb: "finite b" using "2.prems" by simp | |
| 2186 | have th0: "f ` b \<subseteq> f ` (insert a b)" | |
| 53406 | 2187 | apply (rule image_mono) | 
| 2188 | apply blast | |
| 2189 | done | |
| 44133 | 2190 | from independent_mono[ OF "2.prems"(2) th0] | 
| 2191 | have ifb: "independent (f ` b)" . | |
| 2192 | have fib: "inj_on f b" | |
| 2193 | apply (rule subset_inj_on [OF "2.prems"(3)]) | |
| 49522 | 2194 | apply blast | 
| 2195 | done | |
| 44133 | 2196 | from span_breakdown[of a "insert a b", simplified, OF "2.prems"(4)] | 
| 53406 | 2197 |   obtain k where k: "x - k*\<^sub>R a \<in> span (b - {a})"
 | 
| 2198 | by blast | |
| 44133 | 2199 | have "f (x - k*\<^sub>R a) \<in> span (f ` b)" | 
| 2200 | unfolding span_linear_image[OF lf] | |
| 2201 | apply (rule imageI) | |
| 53716 | 2202 |     using k span_mono[of "b - {a}" b]
 | 
| 53406 | 2203 | apply blast | 
| 49522 | 2204 | done | 
| 2205 | then have "f x - k*\<^sub>R f a \<in> span (f ` b)" | |
| 44133 | 2206 | by (simp add: linear_sub[OF lf] linear_cmul[OF lf]) | 
| 49522 | 2207 | then have th: "-k *\<^sub>R f a \<in> span (f ` b)" | 
| 44133 | 2208 | using "2.prems"(5) by simp | 
| 53406 | 2209 | have xsb: "x \<in> span b" | 
| 2210 | proof (cases "k = 0") | |
| 2211 | case True | |
| 53716 | 2212 |     with k have "x \<in> span (b - {a})" by simp
 | 
| 2213 |     then show ?thesis using span_mono[of "b - {a}" b]
 | |
| 53406 | 2214 | by blast | 
| 2215 | next | |
| 2216 | case False | |
| 2217 | with span_mul[OF th, of "- 1/ k"] | |
| 44133 | 2218 | have th1: "f a \<in> span (f ` b)" | 
| 2219 | by auto | |
| 2220 |     from inj_on_image_set_diff[OF "2.prems"(3), of "insert a b " "{a}", symmetric]
 | |
| 2221 |     have tha: "f ` insert a b - f ` {a} = f ` (insert a b - {a})" by blast
 | |
| 2222 | from "2.prems"(2) [unfolded dependent_def bex_simps(8), rule_format, of "f a"] | |
| 2223 | have "f a \<notin> span (f ` b)" using tha | |
| 2224 | using "2.hyps"(2) | |
| 2225 | "2.prems"(3) by auto | |
| 2226 | with th1 have False by blast | |
| 53406 | 2227 | then show ?thesis by blast | 
| 2228 | qed | |
| 2229 | from "2.hyps"(3)[OF fb ifb fib xsb "2.prems"(5)] show "x = 0" . | |
| 44133 | 2230 | qed | 
| 2231 | ||
| 2232 | text {* We can extend a linear mapping from basis. *}
 | |
| 2233 | ||
| 2234 | lemma linear_independent_extend_lemma: | |
| 2235 | fixes f :: "'a::real_vector \<Rightarrow> 'b::real_vector" | |
| 53406 | 2236 | assumes fi: "finite B" | 
| 2237 | and ib: "independent B" | |
| 2238 | shows "\<exists>g. | |
| 2239 | (\<forall>x\<in> span B. \<forall>y\<in> span B. g (x + y) = g x + g y) \<and> | |
| 2240 | (\<forall>x\<in> span B. \<forall>c. g (c*\<^sub>R x) = c *\<^sub>R g x) \<and> | |
| 2241 | (\<forall>x\<in> B. g x = f x)" | |
| 49663 | 2242 | using ib fi | 
| 49522 | 2243 | proof (induct rule: finite_induct[OF fi]) | 
| 49663 | 2244 | case 1 | 
| 2245 | then show ?case by auto | |
| 44133 | 2246 | next | 
| 2247 | case (2 a b) | |
| 2248 | from "2.prems" "2.hyps" have ibf: "independent b" "finite b" | |
| 2249 | by (simp_all add: independent_insert) | |
| 2250 | from "2.hyps"(3)[OF ibf] obtain g where | |
| 2251 | g: "\<forall>x\<in>span b. \<forall>y\<in>span b. g (x + y) = g x + g y" | |
| 2252 | "\<forall>x\<in>span b. \<forall>c. g (c *\<^sub>R x) = c *\<^sub>R g x" "\<forall>x\<in>b. g x = f x" by blast | |
| 2253 | let ?h = "\<lambda>z. SOME k. (z - k *\<^sub>R a) \<in> span b" | |
| 53406 | 2254 |   {
 | 
| 2255 | fix z | |
| 2256 | assume z: "z \<in> span (insert a b)" | |
| 44133 | 2257 | have th0: "z - ?h z *\<^sub>R a \<in> span b" | 
| 2258 | apply (rule someI_ex) | |
| 2259 | unfolding span_breakdown_eq[symmetric] | |
| 53406 | 2260 | apply (rule z) | 
| 2261 | done | |
| 2262 |     {
 | |
| 2263 | fix k | |
| 2264 | assume k: "z - k *\<^sub>R a \<in> span b" | |
| 44133 | 2265 | have eq: "z - ?h z *\<^sub>R a - (z - k*\<^sub>R a) = (k - ?h z) *\<^sub>R a" | 
| 2266 | by (simp add: field_simps scaleR_left_distrib [symmetric]) | |
| 53406 | 2267 | from span_sub[OF th0 k] have khz: "(k - ?h z) *\<^sub>R a \<in> span b" | 
| 2268 | by (simp add: eq) | |
| 2269 |       {
 | |
| 2270 | assume "k \<noteq> ?h z" | |
| 2271 | then have k0: "k - ?h z \<noteq> 0" by simp | |
| 44133 | 2272 | from k0 span_mul[OF khz, of "1 /(k - ?h z)"] | 
| 2273 | have "a \<in> span b" by simp | |
| 2274 | with "2.prems"(1) "2.hyps"(2) have False | |
| 53406 | 2275 | by (auto simp add: dependent_def) | 
| 2276 | } | |
| 2277 | then have "k = ?h z" by blast | |
| 2278 | } | |
| 2279 | with th0 have "z - ?h z *\<^sub>R a \<in> span b \<and> (\<forall>k. z - k *\<^sub>R a \<in> span b \<longrightarrow> k = ?h z)" | |
| 2280 | by blast | |
| 2281 | } | |
| 44133 | 2282 | note h = this | 
| 2283 | let ?g = "\<lambda>z. ?h z *\<^sub>R f a + g (z - ?h z *\<^sub>R a)" | |
| 53406 | 2284 |   {
 | 
| 2285 | fix x y | |
| 2286 | assume x: "x \<in> span (insert a b)" | |
| 2287 | and y: "y \<in> span (insert a b)" | |
| 44133 | 2288 | have tha: "\<And>(x::'a) y a k l. (x + y) - (k + l) *\<^sub>R a = (x - k *\<^sub>R a) + (y - l *\<^sub>R a)" | 
| 2289 | by (simp add: algebra_simps) | |
| 2290 | have addh: "?h (x + y) = ?h x + ?h y" | |
| 2291 | apply (rule conjunct2[OF h, rule_format, symmetric]) | |
| 2292 | apply (rule span_add[OF x y]) | |
| 2293 | unfolding tha | |
| 53406 | 2294 | apply (metis span_add x y conjunct1[OF h, rule_format]) | 
| 2295 | done | |
| 44133 | 2296 | have "?g (x + y) = ?g x + ?g y" | 
| 2297 | unfolding addh tha | |
| 2298 | g(1)[rule_format,OF conjunct1[OF h, OF x] conjunct1[OF h, OF y]] | |
| 2299 | by (simp add: scaleR_left_distrib)} | |
| 2300 | moreover | |
| 53406 | 2301 |   {
 | 
| 2302 | fix x :: "'a" | |
| 2303 | fix c :: real | |
| 49522 | 2304 | assume x: "x \<in> span (insert a b)" | 
| 44133 | 2305 | have tha: "\<And>(x::'a) c k a. c *\<^sub>R x - (c * k) *\<^sub>R a = c *\<^sub>R (x - k *\<^sub>R a)" | 
| 2306 | by (simp add: algebra_simps) | |
| 2307 | have hc: "?h (c *\<^sub>R x) = c * ?h x" | |
| 2308 | apply (rule conjunct2[OF h, rule_format, symmetric]) | |
| 2309 | apply (metis span_mul x) | |
| 49522 | 2310 | apply (metis tha span_mul x conjunct1[OF h]) | 
| 2311 | done | |
| 44133 | 2312 | have "?g (c *\<^sub>R x) = c*\<^sub>R ?g x" | 
| 2313 | unfolding hc tha g(2)[rule_format, OF conjunct1[OF h, OF x]] | |
| 53406 | 2314 | by (simp add: algebra_simps) | 
| 2315 | } | |
| 44133 | 2316 | moreover | 
| 53406 | 2317 |   {
 | 
| 2318 | fix x | |
| 2319 | assume x: "x \<in> insert a b" | |
| 2320 |     {
 | |
| 2321 | assume xa: "x = a" | |
| 44133 | 2322 | have ha1: "1 = ?h a" | 
| 2323 | apply (rule conjunct2[OF h, rule_format]) | |
| 2324 | apply (metis span_superset insertI1) | |
| 2325 | using conjunct1[OF h, OF span_superset, OF insertI1] | |
| 49522 | 2326 | apply (auto simp add: span_0) | 
| 2327 | done | |
| 44133 | 2328 | from xa ha1[symmetric] have "?g x = f x" | 
| 2329 | apply simp | |
| 2330 | using g(2)[rule_format, OF span_0, of 0] | |
| 49522 | 2331 | apply simp | 
| 53406 | 2332 | done | 
| 2333 | } | |
| 44133 | 2334 | moreover | 
| 53406 | 2335 |     {
 | 
| 2336 | assume xb: "x \<in> b" | |
| 44133 | 2337 | have h0: "0 = ?h x" | 
| 2338 | apply (rule conjunct2[OF h, rule_format]) | |
| 2339 | apply (metis span_superset x) | |
| 2340 | apply simp | |
| 2341 | apply (metis span_superset xb) | |
| 2342 | done | |
| 2343 | have "?g x = f x" | |
| 53406 | 2344 | by (simp add: h0[symmetric] g(3)[rule_format, OF xb]) | 
| 2345 | } | |
| 2346 | ultimately have "?g x = f x" | |
| 2347 | using x by blast | |
| 2348 | } | |
| 49663 | 2349 | ultimately show ?case | 
| 2350 | apply - | |
| 2351 | apply (rule exI[where x="?g"]) | |
| 2352 | apply blast | |
| 2353 | done | |
| 44133 | 2354 | qed | 
| 2355 | ||
| 2356 | lemma linear_independent_extend: | |
| 53406 | 2357 | fixes B :: "'a::euclidean_space set" | 
| 2358 | assumes iB: "independent B" | |
| 44133 | 2359 | shows "\<exists>g. linear g \<and> (\<forall>x\<in>B. g x = f x)" | 
| 49522 | 2360 | proof - | 
| 44133 | 2361 | from maximal_independent_subset_extend[of B UNIV] iB | 
| 53406 | 2362 | obtain C where C: "B \<subseteq> C" "independent C" "\<And>x. x \<in> span C" | 
| 2363 | by auto | |
| 44133 | 2364 | |
| 2365 | from C(2) independent_bound[of C] linear_independent_extend_lemma[of C f] | |
| 53406 | 2366 | obtain g where g: | 
| 2367 | "(\<forall>x\<in> span C. \<forall>y\<in> span C. g (x + y) = g x + g y) \<and> | |
| 2368 | (\<forall>x\<in> span C. \<forall>c. g (c*\<^sub>R x) = c *\<^sub>R g x) \<and> | |
| 2369 | (\<forall>x\<in> C. g x = f x)" by blast | |
| 2370 | from g show ?thesis | |
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 2371 | unfolding linear_iff | 
| 53406 | 2372 | using C | 
| 49663 | 2373 | apply clarsimp | 
| 2374 | apply blast | |
| 2375 | done | |
| 44133 | 2376 | qed | 
| 2377 | ||
| 2378 | text {* Can construct an isomorphism between spaces of same dimension. *}
 | |
| 2379 | ||
| 2380 | lemma subspace_isomorphism: | |
| 53406 | 2381 | fixes S :: "'a::euclidean_space set" | 
| 2382 | and T :: "'b::euclidean_space set" | |
| 2383 | assumes s: "subspace S" | |
| 2384 | and t: "subspace T" | |
| 49522 | 2385 | and d: "dim S = dim T" | 
| 44133 | 2386 | shows "\<exists>f. linear f \<and> f ` S = T \<and> inj_on f S" | 
| 49522 | 2387 | proof - | 
| 53406 | 2388 | from basis_exists[of S] independent_bound | 
| 2389 | obtain B where B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S" and fB: "finite B" | |
| 2390 | by blast | |
| 2391 | from basis_exists[of T] independent_bound | |
| 2392 | obtain C where C: "C \<subseteq> T" "independent C" "T \<subseteq> span C" "card C = dim T" and fC: "finite C" | |
| 2393 | by blast | |
| 2394 | from B(4) C(4) card_le_inj[of B C] d | |
| 2395 | obtain f where f: "f ` B \<subseteq> C" "inj_on f B" using `finite B` `finite C` | |
| 2396 | by auto | |
| 2397 | from linear_independent_extend[OF B(2)] | |
| 2398 | obtain g where g: "linear g" "\<forall>x\<in> B. g x = f x" | |
| 2399 | by blast | |
| 2400 | from inj_on_iff_eq_card[OF fB, of f] f(2) have "card (f ` B) = card B" | |
| 44133 | 2401 | by simp | 
| 53406 | 2402 | with B(4) C(4) have ceq: "card (f ` B) = card C" | 
| 2403 | using d by simp | |
| 2404 | have "g ` B = f ` B" | |
| 2405 | using g(2) by (auto simp add: image_iff) | |
| 44133 | 2406 | also have "\<dots> = C" using card_subset_eq[OF fC f(1) ceq] . | 
| 2407 | finally have gBC: "g ` B = C" . | |
| 53406 | 2408 | have gi: "inj_on g B" | 
| 2409 | using f(2) g(2) by (auto simp add: inj_on_def) | |
| 44133 | 2410 | note g0 = linear_indep_image_lemma[OF g(1) fB, unfolded gBC, OF C(2) gi] | 
| 53406 | 2411 |   {
 | 
| 2412 | fix x y | |
| 2413 | assume x: "x \<in> S" and y: "y \<in> S" and gxy: "g x = g y" | |
| 2414 | from B(3) x y have x': "x \<in> span B" and y': "y \<in> span B" | |
| 2415 | by blast+ | |
| 2416 | from gxy have th0: "g (x - y) = 0" | |
| 2417 | by (simp add: linear_sub[OF g(1)]) | |
| 2418 | have th1: "x - y \<in> span B" | |
| 2419 | using x' y' by (metis span_sub) | |
| 2420 | have "x = y" | |
| 2421 | using g0[OF th1 th0] by simp | |
| 2422 | } | |
| 44133 | 2423 | then have giS: "inj_on g S" | 
| 2424 | unfolding inj_on_def by blast | |
| 53406 | 2425 | from span_subspace[OF B(1,3) s] have "g ` S = span (g ` B)" | 
| 2426 | by (simp add: span_linear_image[OF g(1)]) | |
| 44133 | 2427 | also have "\<dots> = span C" unfolding gBC .. | 
| 2428 | also have "\<dots> = T" using span_subspace[OF C(1,3) t] . | |
| 2429 | finally have gS: "g ` S = T" . | |
| 53406 | 2430 | from g(1) gS giS show ?thesis | 
| 2431 | by blast | |
| 44133 | 2432 | qed | 
| 2433 | ||
| 2434 | text {* Linear functions are equal on a subspace if they are on a spanning set. *}
 | |
| 2435 | ||
| 2436 | lemma subspace_kernel: | |
| 2437 | assumes lf: "linear f" | |
| 2438 |   shows "subspace {x. f x = 0}"
 | |
| 49522 | 2439 | apply (simp add: subspace_def) | 
| 2440 | apply (simp add: linear_add[OF lf] linear_cmul[OF lf] linear_0[OF lf]) | |
| 2441 | done | |
| 44133 | 2442 | |
| 2443 | lemma linear_eq_0_span: | |
| 2444 | assumes lf: "linear f" and f0: "\<forall>x\<in>B. f x = 0" | |
| 2445 | shows "\<forall>x \<in> span B. f x = 0" | |
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 2446 | using f0 subspace_kernel[OF lf] | 
| 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 2447 | by (rule span_induct') | 
| 44133 | 2448 | |
| 2449 | lemma linear_eq_0: | |
| 49663 | 2450 | assumes lf: "linear f" | 
| 2451 | and SB: "S \<subseteq> span B" | |
| 2452 | and f0: "\<forall>x\<in>B. f x = 0" | |
| 44133 | 2453 | shows "\<forall>x \<in> S. f x = 0" | 
| 2454 | by (metis linear_eq_0_span[OF lf] subset_eq SB f0) | |
| 2455 | ||
| 2456 | lemma linear_eq: | |
| 49663 | 2457 | assumes lf: "linear f" | 
| 2458 | and lg: "linear g" | |
| 2459 | and S: "S \<subseteq> span B" | |
| 49522 | 2460 | and fg: "\<forall> x\<in> B. f x = g x" | 
| 44133 | 2461 | shows "\<forall>x\<in> S. f x = g x" | 
| 49663 | 2462 | proof - | 
| 44133 | 2463 | let ?h = "\<lambda>x. f x - g x" | 
| 2464 | from fg have fg': "\<forall>x\<in> B. ?h x = 0" by simp | |
| 2465 | from linear_eq_0[OF linear_compose_sub[OF lf lg] S fg'] | |
| 2466 | show ?thesis by simp | |
| 2467 | qed | |
| 2468 | ||
| 2469 | lemma linear_eq_stdbasis: | |
| 49663 | 2470 | assumes lf: "linear (f::'a::euclidean_space \<Rightarrow> _)" | 
| 2471 | and lg: "linear g" | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2472 | and fg: "\<forall>b\<in>Basis. f b = g b" | 
| 44133 | 2473 | shows "f = g" | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2474 | using linear_eq[OF lf lg, of _ Basis] fg by auto | 
| 44133 | 2475 | |
| 2476 | text {* Similar results for bilinear functions. *}
 | |
| 2477 | ||
| 2478 | lemma bilinear_eq: | |
| 2479 | assumes bf: "bilinear f" | |
| 49522 | 2480 | and bg: "bilinear g" | 
| 53406 | 2481 | and SB: "S \<subseteq> span B" | 
| 2482 | and TC: "T \<subseteq> span C" | |
| 49522 | 2483 | and fg: "\<forall>x\<in> B. \<forall>y\<in> C. f x y = g x y" | 
| 44133 | 2484 | shows "\<forall>x\<in>S. \<forall>y\<in>T. f x y = g x y " | 
| 49663 | 2485 | proof - | 
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 2486 |   let ?P = "{x. \<forall>y\<in> span C. f x y = g x y}"
 | 
| 44133 | 2487 | from bf bg have sp: "subspace ?P" | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 2488 | unfolding bilinear_def linear_iff subspace_def bf bg | 
| 49663 | 2489 | by (auto simp add: span_0 bilinear_lzero[OF bf] bilinear_lzero[OF bg] span_add Ball_def | 
| 2490 | intro: bilinear_ladd[OF bf]) | |
| 44133 | 2491 | |
| 2492 | have "\<forall>x \<in> span B. \<forall>y\<in> span C. f x y = g x y" | |
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 2493 | apply (rule span_induct' [OF _ sp]) | 
| 44133 | 2494 | apply (rule ballI) | 
| 44170 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 2495 | apply (rule span_induct') | 
| 
510ac30f44c0
make Multivariate_Analysis work with separate set type
 huffman parents: 
44166diff
changeset | 2496 | apply (simp add: fg) | 
| 44133 | 2497 | apply (auto simp add: subspace_def) | 
| 53600 
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
 huffman parents: 
53596diff
changeset | 2498 | using bf bg unfolding bilinear_def linear_iff | 
| 49522 | 2499 | apply (auto simp add: span_0 bilinear_rzero[OF bf] bilinear_rzero[OF bg] span_add Ball_def | 
| 49663 | 2500 | intro: bilinear_ladd[OF bf]) | 
| 49522 | 2501 | done | 
| 53406 | 2502 | then show ?thesis | 
| 2503 | using SB TC by auto | |
| 44133 | 2504 | qed | 
| 2505 | ||
| 49522 | 2506 | lemma bilinear_eq_stdbasis: | 
| 53406 | 2507 | fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space \<Rightarrow> _" | 
| 44133 | 2508 | assumes bf: "bilinear f" | 
| 49522 | 2509 | and bg: "bilinear g" | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2510 | and fg: "\<forall>i\<in>Basis. \<forall>j\<in>Basis. f i j = g i j" | 
| 44133 | 2511 | shows "f = g" | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2512 | using bilinear_eq[OF bf bg equalityD2[OF span_Basis] equalityD2[OF span_Basis] fg] by blast | 
| 44133 | 2513 | |
| 2514 | text {* Detailed theorems about left and right invertibility in general case. *}
 | |
| 2515 | ||
| 49522 | 2516 | lemma linear_injective_left_inverse: | 
| 53406 | 2517 | fixes f::"'a::euclidean_space \<Rightarrow> 'b::euclidean_space" | 
| 44133 | 2518 | assumes lf: "linear f" and fi: "inj f" | 
| 2519 | shows "\<exists>g. linear g \<and> g o f = id" | |
| 49522 | 2520 | proof - | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2521 | from linear_independent_extend[OF independent_injective_image, OF independent_Basis, OF lf fi] | 
| 53406 | 2522 | obtain h:: "'b \<Rightarrow> 'a" where h: "linear h" "\<forall>x \<in> f ` Basis. h x = inv f x" | 
| 2523 | by blast | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2524 | from h(2) have th: "\<forall>i\<in>Basis. (h \<circ> f) i = id i" | 
| 44133 | 2525 | using inv_o_cancel[OF fi, unfolded fun_eq_iff id_def o_def] | 
| 2526 | by auto | |
| 2527 | from linear_eq_stdbasis[OF linear_compose[OF lf h(1)] linear_id th] | |
| 2528 | have "h o f = id" . | |
| 53406 | 2529 | then show ?thesis | 
| 2530 | using h(1) by blast | |
| 44133 | 2531 | qed | 
| 2532 | ||
| 49522 | 2533 | lemma linear_surjective_right_inverse: | 
| 53406 | 2534 | fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space" | 
| 2535 | assumes lf: "linear f" | |
| 2536 | and sf: "surj f" | |
| 44133 | 2537 | shows "\<exists>g. linear g \<and> f o g = id" | 
| 49522 | 2538 | proof - | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2539 | from linear_independent_extend[OF independent_Basis[where 'a='b],of "inv f"] | 
| 53406 | 2540 | obtain h:: "'b \<Rightarrow> 'a" where h: "linear h" "\<forall>x\<in>Basis. h x = inv f x" | 
| 2541 | by blast | |
| 2542 | from h(2) have th: "\<forall>i\<in>Basis. (f o h) i = id i" | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2543 | using sf by (auto simp add: surj_iff_all) | 
| 44133 | 2544 | from linear_eq_stdbasis[OF linear_compose[OF h(1) lf] linear_id th] | 
| 2545 | have "f o h = id" . | |
| 53406 | 2546 | then show ?thesis | 
| 2547 | using h(1) by blast | |
| 44133 | 2548 | qed | 
| 2549 | ||
| 2550 | text {* An injective map @{typ "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"} is also surjective. *}
 | |
| 2551 | ||
| 49522 | 2552 | lemma linear_injective_imp_surjective: | 
| 53406 | 2553 | fixes f::"'a::euclidean_space \<Rightarrow> 'a::euclidean_space" | 
| 2554 | assumes lf: "linear f" | |
| 2555 | and fi: "inj f" | |
| 44133 | 2556 | shows "surj f" | 
| 49522 | 2557 | proof - | 
| 44133 | 2558 | let ?U = "UNIV :: 'a set" | 
| 2559 | from basis_exists[of ?U] obtain B | |
| 2560 | where B: "B \<subseteq> ?U" "independent B" "?U \<subseteq> span B" "card B = dim ?U" | |
| 2561 | by blast | |
| 53406 | 2562 | from B(4) have d: "dim ?U = card B" | 
| 2563 | by simp | |
| 44133 | 2564 | have th: "?U \<subseteq> span (f ` B)" | 
| 2565 | apply (rule card_ge_dim_independent) | |
| 2566 | apply blast | |
| 2567 | apply (rule independent_injective_image[OF B(2) lf fi]) | |
| 2568 | apply (rule order_eq_refl) | |
| 2569 | apply (rule sym) | |
| 2570 | unfolding d | |
| 2571 | apply (rule card_image) | |
| 2572 | apply (rule subset_inj_on[OF fi]) | |
| 49522 | 2573 | apply blast | 
| 2574 | done | |
| 44133 | 2575 | from th show ?thesis | 
| 2576 | unfolding span_linear_image[OF lf] surj_def | |
| 2577 | using B(3) by blast | |
| 2578 | qed | |
| 2579 | ||
| 2580 | text {* And vice versa. *}
 | |
| 2581 | ||
| 2582 | lemma surjective_iff_injective_gen: | |
| 49663 | 2583 | assumes fS: "finite S" | 
| 2584 | and fT: "finite T" | |
| 2585 | and c: "card S = card T" | |
| 49522 | 2586 | and ST: "f ` S \<subseteq> T" | 
| 53406 | 2587 | shows "(\<forall>y \<in> T. \<exists>x \<in> S. f x = y) \<longleftrightarrow> inj_on f S" | 
| 2588 | (is "?lhs \<longleftrightarrow> ?rhs") | |
| 2589 | proof | |
| 2590 | assume h: "?lhs" | |
| 2591 |   {
 | |
| 2592 | fix x y | |
| 2593 | assume x: "x \<in> S" | |
| 2594 | assume y: "y \<in> S" | |
| 2595 | assume f: "f x = f y" | |
| 2596 | from x fS have S0: "card S \<noteq> 0" | |
| 2597 | by auto | |
| 2598 | have "x = y" | |
| 2599 | proof (rule ccontr) | |
| 53716 | 2600 | assume xy: "\<not> ?thesis" | 
| 53406 | 2601 |       have th: "card S \<le> card (f ` (S - {y}))"
 | 
| 2602 | unfolding c | |
| 2603 | apply (rule card_mono) | |
| 2604 | apply (rule finite_imageI) | |
| 2605 | using fS apply simp | |
| 2606 | using h xy x y f unfolding subset_eq image_iff | |
| 2607 | apply auto | |
| 2608 | apply (case_tac "xa = f x") | |
| 2609 | apply (rule bexI[where x=x]) | |
| 2610 | apply auto | |
| 2611 | done | |
| 53716 | 2612 |       also have " \<dots> \<le> card (S - {y})"
 | 
| 53406 | 2613 | apply (rule card_image_le) | 
| 2614 | using fS by simp | |
| 2615 | also have "\<dots> \<le> card S - 1" using y fS by simp | |
| 2616 | finally show False using S0 by arith | |
| 2617 | qed | |
| 2618 | } | |
| 2619 | then show ?rhs | |
| 2620 | unfolding inj_on_def by blast | |
| 2621 | next | |
| 2622 | assume h: ?rhs | |
| 2623 | have "f ` S = T" | |
| 2624 | apply (rule card_subset_eq[OF fT ST]) | |
| 2625 | unfolding card_image[OF h] | |
| 2626 | apply (rule c) | |
| 2627 | done | |
| 2628 | then show ?lhs by blast | |
| 44133 | 2629 | qed | 
| 2630 | ||
| 49522 | 2631 | lemma linear_surjective_imp_injective: | 
| 53406 | 2632 | fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space" | 
| 2633 | assumes lf: "linear f" | |
| 2634 | and sf: "surj f" | |
| 44133 | 2635 | shows "inj f" | 
| 49522 | 2636 | proof - | 
| 44133 | 2637 | let ?U = "UNIV :: 'a set" | 
| 2638 | from basis_exists[of ?U] obtain B | |
| 2639 | where B: "B \<subseteq> ?U" "independent B" "?U \<subseteq> span B" and d: "card B = dim ?U" | |
| 2640 | by blast | |
| 53406 | 2641 |   {
 | 
| 2642 | fix x | |
| 2643 | assume x: "x \<in> span B" | |
| 2644 | assume fx: "f x = 0" | |
| 2645 | from B(2) have fB: "finite B" | |
| 2646 | using independent_bound by auto | |
| 44133 | 2647 | have fBi: "independent (f ` B)" | 
| 2648 | apply (rule card_le_dim_spanning[of "f ` B" ?U]) | |
| 2649 | apply blast | |
| 2650 | using sf B(3) | |
| 2651 | unfolding span_linear_image[OF lf] surj_def subset_eq image_iff | |
| 2652 | apply blast | |
| 2653 | using fB apply blast | |
| 2654 | unfolding d[symmetric] | |
| 2655 | apply (rule card_image_le) | |
| 2656 | apply (rule fB) | |
| 2657 | done | |
| 2658 | have th0: "dim ?U \<le> card (f ` B)" | |
| 2659 | apply (rule span_card_ge_dim) | |
| 2660 | apply blast | |
| 2661 | unfolding span_linear_image[OF lf] | |
| 2662 | apply (rule subset_trans[where B = "f ` UNIV"]) | |
| 53406 | 2663 | using sf unfolding surj_def | 
| 2664 | apply blast | |
| 44133 | 2665 | apply (rule image_mono) | 
| 2666 | apply (rule B(3)) | |
| 2667 | apply (metis finite_imageI fB) | |
| 2668 | done | |
| 2669 | moreover have "card (f ` B) \<le> card B" | |
| 2670 | by (rule card_image_le, rule fB) | |
| 53406 | 2671 | ultimately have th1: "card B = card (f ` B)" | 
| 2672 | unfolding d by arith | |
| 44133 | 2673 | have fiB: "inj_on f B" | 
| 49522 | 2674 | unfolding surjective_iff_injective_gen[OF fB finite_imageI[OF fB] th1 subset_refl, symmetric] | 
| 2675 | by blast | |
| 44133 | 2676 | from linear_indep_image_lemma[OF lf fB fBi fiB x] fx | 
| 53406 | 2677 | have "x = 0" by blast | 
| 2678 | } | |
| 2679 | then show ?thesis | |
| 2680 | unfolding linear_injective_0[OF lf] | |
| 2681 | using B(3) | |
| 2682 | by blast | |
| 44133 | 2683 | qed | 
| 2684 | ||
| 2685 | text {* Hence either is enough for isomorphism. *}
 | |
| 2686 | ||
| 2687 | lemma left_right_inverse_eq: | |
| 53406 | 2688 | assumes fg: "f \<circ> g = id" | 
| 2689 | and gh: "g \<circ> h = id" | |
| 44133 | 2690 | shows "f = h" | 
| 49522 | 2691 | proof - | 
| 53406 | 2692 | have "f = f \<circ> (g \<circ> h)" | 
| 2693 | unfolding gh by simp | |
| 2694 | also have "\<dots> = (f \<circ> g) \<circ> h" | |
| 2695 | by (simp add: o_assoc) | |
| 2696 | finally show "f = h" | |
| 2697 | unfolding fg by simp | |
| 44133 | 2698 | qed | 
| 2699 | ||
| 2700 | lemma isomorphism_expand: | |
| 53406 | 2701 | "f \<circ> g = id \<and> g \<circ> f = id \<longleftrightarrow> (\<forall>x. f (g x) = x) \<and> (\<forall>x. g (f x) = x)" | 
| 44133 | 2702 | by (simp add: fun_eq_iff o_def id_def) | 
| 2703 | ||
| 49522 | 2704 | lemma linear_injective_isomorphism: | 
| 53406 | 2705 | fixes f::"'a::euclidean_space \<Rightarrow> 'a::euclidean_space" | 
| 2706 | assumes lf: "linear f" | |
| 2707 | and fi: "inj f" | |
| 44133 | 2708 | shows "\<exists>f'. linear f' \<and> (\<forall>x. f' (f x) = x) \<and> (\<forall>x. f (f' x) = x)" | 
| 49522 | 2709 | unfolding isomorphism_expand[symmetric] | 
| 2710 | using linear_surjective_right_inverse[OF lf linear_injective_imp_surjective[OF lf fi]] | |
| 2711 | linear_injective_left_inverse[OF lf fi] | |
| 2712 | by (metis left_right_inverse_eq) | |
| 44133 | 2713 | |
| 53406 | 2714 | lemma linear_surjective_isomorphism: | 
| 2715 | fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space" | |
| 2716 | assumes lf: "linear f" | |
| 2717 | and sf: "surj f" | |
| 44133 | 2718 | shows "\<exists>f'. linear f' \<and> (\<forall>x. f' (f x) = x) \<and> (\<forall>x. f (f' x) = x)" | 
| 49522 | 2719 | unfolding isomorphism_expand[symmetric] | 
| 2720 | using linear_surjective_right_inverse[OF lf sf] | |
| 2721 | linear_injective_left_inverse[OF lf linear_surjective_imp_injective[OF lf sf]] | |
| 2722 | by (metis left_right_inverse_eq) | |
| 44133 | 2723 | |
| 53406 | 2724 | text {* Left and right inverses are the same for
 | 
| 2725 |   @{typ "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"}. *}
 | |
| 44133 | 2726 | |
| 49522 | 2727 | lemma linear_inverse_left: | 
| 53406 | 2728 | fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space" | 
| 2729 | assumes lf: "linear f" | |
| 2730 | and lf': "linear f'" | |
| 2731 | shows "f \<circ> f' = id \<longleftrightarrow> f' \<circ> f = id" | |
| 49522 | 2732 | proof - | 
| 53406 | 2733 |   {
 | 
| 2734 | fix f f':: "'a \<Rightarrow> 'a" | |
| 2735 | assume lf: "linear f" "linear f'" | |
| 2736 | assume f: "f \<circ> f' = id" | |
| 44133 | 2737 | from f have sf: "surj f" | 
| 2738 | apply (auto simp add: o_def id_def surj_def) | |
| 49522 | 2739 | apply metis | 
| 2740 | done | |
| 44133 | 2741 | from linear_surjective_isomorphism[OF lf(1) sf] lf f | 
| 53406 | 2742 | have "f' \<circ> f = id" | 
| 2743 | unfolding fun_eq_iff o_def id_def by metis | |
| 2744 | } | |
| 2745 | then show ?thesis | |
| 2746 | using lf lf' by metis | |
| 44133 | 2747 | qed | 
| 2748 | ||
| 2749 | text {* Moreover, a one-sided inverse is automatically linear. *}
 | |
| 2750 | ||
| 49522 | 2751 | lemma left_inverse_linear: | 
| 53406 | 2752 | fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space" | 
| 2753 | assumes lf: "linear f" | |
| 2754 | and gf: "g \<circ> f = id" | |
| 44133 | 2755 | shows "linear g" | 
| 49522 | 2756 | proof - | 
| 2757 | from gf have fi: "inj f" | |
| 2758 | apply (auto simp add: inj_on_def o_def id_def fun_eq_iff) | |
| 2759 | apply metis | |
| 2760 | done | |
| 44133 | 2761 | from linear_injective_isomorphism[OF lf fi] | 
| 53406 | 2762 | obtain h :: "'a \<Rightarrow> 'a" where h: "linear h" "\<forall>x. h (f x) = x" "\<forall>x. f (h x) = x" | 
| 2763 | by blast | |
| 49522 | 2764 | have "h = g" | 
| 2765 | apply (rule ext) using gf h(2,3) | |
| 44133 | 2766 | apply (simp add: o_def id_def fun_eq_iff) | 
| 49522 | 2767 | apply metis | 
| 2768 | done | |
| 44133 | 2769 | with h(1) show ?thesis by blast | 
| 2770 | qed | |
| 2771 | ||
| 49522 | 2772 | |
| 44133 | 2773 | subsection {* Infinity norm *}
 | 
| 2774 | ||
| 53716 | 2775 | definition "infnorm (x::'a::euclidean_space) = Sup {abs (x \<bullet> b) |b. b \<in> Basis}"
 | 
| 44133 | 2776 | |
| 2777 | lemma infnorm_set_image: | |
| 53716 | 2778 | fixes x :: "'a::euclidean_space" | 
| 2779 |   shows "{abs (x \<bullet> i) |i. i \<in> Basis} = (\<lambda>i. abs (x \<bullet> i)) ` Basis"
 | |
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2780 | by blast | 
| 44133 | 2781 | |
| 53716 | 2782 | lemma infnorm_Max: | 
| 2783 | fixes x :: "'a::euclidean_space" | |
| 2784 | shows "infnorm x = Max ((\<lambda>i. abs (x \<bullet> i)) ` Basis)" | |
| 51475 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2785 | by (simp add: infnorm_def infnorm_set_image cSup_eq_Max) | 
| 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2786 | |
| 44133 | 2787 | lemma infnorm_set_lemma: | 
| 53716 | 2788 | fixes x :: "'a::euclidean_space" | 
| 2789 |   shows "finite {abs (x \<bullet> i) |i. i \<in> Basis}"
 | |
| 2790 |     and "{abs (x \<bullet> i) |i. i \<in> Basis} \<noteq> {}"
 | |
| 44133 | 2791 | unfolding infnorm_set_image | 
| 2792 | by auto | |
| 2793 | ||
| 53406 | 2794 | lemma infnorm_pos_le: | 
| 2795 | fixes x :: "'a::euclidean_space" | |
| 2796 | shows "0 \<le> infnorm x" | |
| 51475 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2797 | by (simp add: infnorm_Max Max_ge_iff ex_in_conv) | 
| 44133 | 2798 | |
| 53406 | 2799 | lemma infnorm_triangle: | 
| 2800 | fixes x :: "'a::euclidean_space" | |
| 2801 | shows "infnorm (x + y) \<le> infnorm x + infnorm y" | |
| 49522 | 2802 | proof - | 
| 51475 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2803 | have *: "\<And>a b c d :: real. \<bar>a\<bar> \<le> c \<Longrightarrow> \<bar>b\<bar> \<le> d \<Longrightarrow> \<bar>a + b\<bar> \<le> c + d" | 
| 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2804 | by simp | 
| 44133 | 2805 | show ?thesis | 
| 51475 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2806 | by (auto simp: infnorm_Max inner_add_left intro!: *) | 
| 44133 | 2807 | qed | 
| 2808 | ||
| 53406 | 2809 | lemma infnorm_eq_0: | 
| 2810 | fixes x :: "'a::euclidean_space" | |
| 2811 | shows "infnorm x = 0 \<longleftrightarrow> x = 0" | |
| 49522 | 2812 | proof - | 
| 51475 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2813 | have "infnorm x \<le> 0 \<longleftrightarrow> x = 0" | 
| 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2814 | unfolding infnorm_Max by (simp add: euclidean_all_zero_iff) | 
| 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2815 | then show ?thesis | 
| 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2816 | using infnorm_pos_le[of x] by simp | 
| 44133 | 2817 | qed | 
| 2818 | ||
| 2819 | lemma infnorm_0: "infnorm 0 = 0" | |
| 2820 | by (simp add: infnorm_eq_0) | |
| 2821 | ||
| 2822 | lemma infnorm_neg: "infnorm (- x) = infnorm x" | |
| 2823 | unfolding infnorm_def | |
| 2824 | apply (rule cong[of "Sup" "Sup"]) | |
| 49522 | 2825 | apply blast | 
| 2826 | apply auto | |
| 2827 | done | |
| 44133 | 2828 | |
| 2829 | lemma infnorm_sub: "infnorm (x - y) = infnorm (y - x)" | |
| 49522 | 2830 | proof - | 
| 44133 | 2831 | have "y - x = - (x - y)" by simp | 
| 53406 | 2832 | then show ?thesis | 
| 2833 | by (metis infnorm_neg) | |
| 44133 | 2834 | qed | 
| 2835 | ||
| 53406 | 2836 | lemma real_abs_sub_infnorm: "\<bar>infnorm x - infnorm y\<bar> \<le> infnorm (x - y)" | 
| 49522 | 2837 | proof - | 
| 53406 | 2838 | have th: "\<And>(nx::real) n ny. nx \<le> n + ny \<Longrightarrow> ny <= n + nx \<Longrightarrow> \<bar>nx - ny\<bar> \<le> n" | 
| 44133 | 2839 | by arith | 
| 2840 | from infnorm_triangle[of "x - y" " y"] infnorm_triangle[of "x - y" "-x"] | |
| 2841 | have ths: "infnorm x \<le> infnorm (x - y) + infnorm y" | |
| 2842 | "infnorm y \<le> infnorm (x - y) + infnorm x" | |
| 44454 | 2843 | by (simp_all add: field_simps infnorm_neg) | 
| 53406 | 2844 | from th[OF ths] show ?thesis . | 
| 44133 | 2845 | qed | 
| 2846 | ||
| 53406 | 2847 | lemma real_abs_infnorm: "\<bar>infnorm x\<bar> = infnorm x" | 
| 44133 | 2848 | using infnorm_pos_le[of x] by arith | 
| 2849 | ||
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2850 | lemma Basis_le_infnorm: | 
| 53406 | 2851 | fixes x :: "'a::euclidean_space" | 
| 2852 | shows "b \<in> Basis \<Longrightarrow> \<bar>x \<bullet> b\<bar> \<le> infnorm x" | |
| 51475 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2853 | by (simp add: infnorm_Max) | 
| 44133 | 2854 | |
| 53716 | 2855 | lemma infnorm_mul: "infnorm (a *\<^sub>R x) = abs a * infnorm x" | 
| 51475 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2856 | unfolding infnorm_Max | 
| 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2857 | proof (safe intro!: Max_eqI) | 
| 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2858 | let ?B = "(\<lambda>i. \<bar>x \<bullet> i\<bar>) ` Basis" | 
| 53406 | 2859 |   {
 | 
| 2860 | fix b :: 'a | |
| 2861 | assume "b \<in> Basis" | |
| 2862 | then show "\<bar>a *\<^sub>R x \<bullet> b\<bar> \<le> \<bar>a\<bar> * Max ?B" | |
| 2863 | by (simp add: abs_mult mult_left_mono) | |
| 2864 | next | |
| 2865 | from Max_in[of ?B] obtain b where "b \<in> Basis" "Max ?B = \<bar>x \<bullet> b\<bar>" | |
| 2866 | by (auto simp del: Max_in) | |
| 2867 | then show "\<bar>a\<bar> * Max ((\<lambda>i. \<bar>x \<bullet> i\<bar>) ` Basis) \<in> (\<lambda>i. \<bar>a *\<^sub>R x \<bullet> i\<bar>) ` Basis" | |
| 2868 | by (intro image_eqI[where x=b]) (auto simp: abs_mult) | |
| 2869 | } | |
| 51475 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2870 | qed simp | 
| 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2871 | |
| 53406 | 2872 | lemma infnorm_mul_lemma: "infnorm (a *\<^sub>R x) \<le> \<bar>a\<bar> * infnorm x" | 
| 51475 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2873 | unfolding infnorm_mul .. | 
| 44133 | 2874 | |
| 2875 | lemma infnorm_pos_lt: "infnorm x > 0 \<longleftrightarrow> x \<noteq> 0" | |
| 2876 | using infnorm_pos_le[of x] infnorm_eq_0[of x] by arith | |
| 2877 | ||
| 2878 | text {* Prove that it differs only up to a bound from Euclidean norm. *}
 | |
| 2879 | ||
| 2880 | lemma infnorm_le_norm: "infnorm x \<le> norm x" | |
| 51475 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2881 | by (simp add: Basis_le_norm infnorm_Max) | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2882 | |
| 54776 
db890d9fc5c2
ordered_euclidean_space compatible with more standard pointwise ordering on products; conditionally complete lattice with product order
 immler parents: 
54703diff
changeset | 2883 | lemma (in euclidean_space) euclidean_inner: "inner x y = (\<Sum>b\<in>Basis. (x \<bullet> b) * (y \<bullet> b))" | 
| 
db890d9fc5c2
ordered_euclidean_space compatible with more standard pointwise ordering on products; conditionally complete lattice with product order
 immler parents: 
54703diff
changeset | 2884 | by (subst (1 2) euclidean_representation[symmetric]) | 
| 
db890d9fc5c2
ordered_euclidean_space compatible with more standard pointwise ordering on products; conditionally complete lattice with product order
 immler parents: 
54703diff
changeset | 2885 | (simp add: inner_setsum_left inner_setsum_right setsum_cases inner_Basis ac_simps if_distrib) | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2886 | |
| 53716 | 2887 | lemma norm_le_infnorm: | 
| 2888 | fixes x :: "'a::euclidean_space" | |
| 2889 |   shows "norm x \<le> sqrt DIM('a) * infnorm x"
 | |
| 49522 | 2890 | proof - | 
| 44133 | 2891 |   let ?d = "DIM('a)"
 | 
| 53406 | 2892 | have "real ?d \<ge> 0" | 
| 2893 | by simp | |
| 53077 | 2894 | then have d2: "(sqrt (real ?d))\<^sup>2 = real ?d" | 
| 44133 | 2895 | by (auto intro: real_sqrt_pow2) | 
| 2896 | have th: "sqrt (real ?d) * infnorm x \<ge> 0" | |
| 2897 | by (simp add: zero_le_mult_iff infnorm_pos_le) | |
| 53077 | 2898 | have th1: "x \<bullet> x \<le> (sqrt (real ?d) * infnorm x)\<^sup>2" | 
| 44133 | 2899 | unfolding power_mult_distrib d2 | 
| 50526 
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
 hoelzl parents: 
50105diff
changeset | 2900 | unfolding real_of_nat_def | 
| 53716 | 2901 | apply (subst euclidean_inner) | 
| 44133 | 2902 | apply (subst power2_abs[symmetric]) | 
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
51478diff
changeset | 2903 | apply (rule order_trans[OF setsum_bounded[where K="\<bar>infnorm x\<bar>\<^sup>2"]]) | 
| 49663 | 2904 | apply (auto simp add: power2_eq_square[symmetric]) | 
| 44133 | 2905 | apply (subst power2_abs[symmetric]) | 
| 2906 | apply (rule power_mono) | |
| 51475 
ebf9d4fd00ba
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
 hoelzl parents: 
50526diff
changeset | 2907 | apply (auto simp: infnorm_Max) | 
| 49522 | 2908 | done | 
| 44133 | 2909 | from real_le_lsqrt[OF inner_ge_zero th th1] | 
| 53406 | 2910 | show ?thesis | 
| 2911 | unfolding norm_eq_sqrt_inner id_def . | |
| 44133 | 2912 | qed | 
| 2913 | ||
| 44646 | 2914 | lemma tendsto_infnorm [tendsto_intros]: | 
| 49522 | 2915 | assumes "(f ---> a) F" | 
| 2916 | shows "((\<lambda>x. infnorm (f x)) ---> infnorm a) F" | |
| 44646 | 2917 | proof (rule tendsto_compose [OF LIM_I assms]) | 
| 53406 | 2918 | fix r :: real | 
| 2919 | assume "r > 0" | |
| 49522 | 2920 | then show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (infnorm x - infnorm a) < r" | 
| 44646 | 2921 | by (metis real_norm_def le_less_trans real_abs_sub_infnorm infnorm_le_norm) | 
| 2922 | qed | |
| 2923 | ||
| 44133 | 2924 | text {* Equality in Cauchy-Schwarz and triangle inequalities. *}
 | 
| 2925 | ||
| 53406 | 2926 | lemma norm_cauchy_schwarz_eq: "x \<bullet> y = norm x * norm y \<longleftrightarrow> norm x *\<^sub>R y = norm y *\<^sub>R x" | 
| 2927 | (is "?lhs \<longleftrightarrow> ?rhs") | |
| 49522 | 2928 | proof - | 
| 53406 | 2929 |   {
 | 
| 2930 | assume h: "x = 0" | |
| 2931 | then have ?thesis by simp | |
| 2932 | } | |
| 44133 | 2933 | moreover | 
| 53406 | 2934 |   {
 | 
| 2935 | assume h: "y = 0" | |
| 2936 | then have ?thesis by simp | |
| 2937 | } | |
| 44133 | 2938 | moreover | 
| 53406 | 2939 |   {
 | 
| 2940 | assume x: "x \<noteq> 0" and y: "y \<noteq> 0" | |
| 44133 | 2941 | from inner_eq_zero_iff[of "norm y *\<^sub>R x - norm x *\<^sub>R y"] | 
| 49522 | 2942 | have "?rhs \<longleftrightarrow> | 
| 2943 | (norm y * (norm y * norm x * norm x - norm x * (x \<bullet> y)) - | |
| 2944 | norm x * (norm y * (y \<bullet> x) - norm x * norm y * norm y) = 0)" | |
| 44133 | 2945 | using x y | 
| 2946 | unfolding inner_simps | |
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53939diff
changeset | 2947 | unfolding power2_norm_eq_inner[symmetric] power2_eq_square right_minus_eq | 
| 49522 | 2948 | apply (simp add: inner_commute) | 
| 2949 | apply (simp add: field_simps) | |
| 2950 | apply metis | |
| 2951 | done | |
| 44133 | 2952 | also have "\<dots> \<longleftrightarrow> (2 * norm x * norm y * (norm x * norm y - x \<bullet> y) = 0)" using x y | 
| 2953 | by (simp add: field_simps inner_commute) | |
| 2954 | also have "\<dots> \<longleftrightarrow> ?lhs" using x y | |
| 2955 | apply simp | |
| 49522 | 2956 | apply metis | 
| 2957 | done | |
| 53406 | 2958 | finally have ?thesis by blast | 
| 2959 | } | |
| 44133 | 2960 | ultimately show ?thesis by blast | 
| 2961 | qed | |
| 2962 | ||
| 2963 | lemma norm_cauchy_schwarz_abs_eq: | |
| 53716 | 2964 | "abs (x \<bullet> y) = norm x * norm y \<longleftrightarrow> | 
| 2965 | norm x *\<^sub>R y = norm y *\<^sub>R x \<or> norm x *\<^sub>R y = - norm y *\<^sub>R x" | |
| 53406 | 2966 | (is "?lhs \<longleftrightarrow> ?rhs") | 
| 49522 | 2967 | proof - | 
| 53406 | 2968 | have th: "\<And>(x::real) a. a \<ge> 0 \<Longrightarrow> abs x = a \<longleftrightarrow> x = a \<or> x = - a" | 
| 2969 | by arith | |
| 44133 | 2970 | have "?rhs \<longleftrightarrow> norm x *\<^sub>R y = norm y *\<^sub>R x \<or> norm (- x) *\<^sub>R y = norm y *\<^sub>R (- x)" | 
| 2971 | by simp | |
| 53406 | 2972 | also have "\<dots> \<longleftrightarrow>(x \<bullet> y = norm x * norm y \<or> (- x) \<bullet> y = norm x * norm y)" | 
| 44133 | 2973 | unfolding norm_cauchy_schwarz_eq[symmetric] | 
| 2974 | unfolding norm_minus_cancel norm_scaleR .. | |
| 2975 | also have "\<dots> \<longleftrightarrow> ?lhs" | |
| 53406 | 2976 | unfolding th[OF mult_nonneg_nonneg, OF norm_ge_zero[of x] norm_ge_zero[of y]] inner_simps | 
| 2977 | by auto | |
| 44133 | 2978 | finally show ?thesis .. | 
| 2979 | qed | |
| 2980 | ||
| 2981 | lemma norm_triangle_eq: | |
| 2982 | fixes x y :: "'a::real_inner" | |
| 53406 | 2983 | shows "norm (x + y) = norm x + norm y \<longleftrightarrow> norm x *\<^sub>R y = norm y *\<^sub>R x" | 
| 49522 | 2984 | proof - | 
| 53406 | 2985 |   {
 | 
| 2986 | assume x: "x = 0 \<or> y = 0" | |
| 2987 | then have ?thesis | |
| 2988 | by (cases "x = 0") simp_all | |
| 2989 | } | |
| 44133 | 2990 | moreover | 
| 53406 | 2991 |   {
 | 
| 2992 | assume x: "x \<noteq> 0" and y: "y \<noteq> 0" | |
| 49522 | 2993 | then have "norm x \<noteq> 0" "norm y \<noteq> 0" | 
| 44133 | 2994 | by simp_all | 
| 49522 | 2995 | then have n: "norm x > 0" "norm y > 0" | 
| 2996 | using norm_ge_zero[of x] norm_ge_zero[of y] by arith+ | |
| 53406 | 2997 | have th: "\<And>(a::real) b c. a + b + c \<noteq> 0 \<Longrightarrow> a = b + c \<longleftrightarrow> a\<^sup>2 = (b + c)\<^sup>2" | 
| 49522 | 2998 | by algebra | 
| 53077 | 2999 | have "norm (x + y) = norm x + norm y \<longleftrightarrow> (norm (x + y))\<^sup>2 = (norm x + norm y)\<^sup>2" | 
| 53406 | 3000 | apply (rule th) | 
| 3001 | using n norm_ge_zero[of "x + y"] | |
| 49522 | 3002 | apply arith | 
| 3003 | done | |
| 44133 | 3004 | also have "\<dots> \<longleftrightarrow> norm x *\<^sub>R y = norm y *\<^sub>R x" | 
| 3005 | unfolding norm_cauchy_schwarz_eq[symmetric] | |
| 3006 | unfolding power2_norm_eq_inner inner_simps | |
| 3007 | by (simp add: power2_norm_eq_inner[symmetric] power2_eq_square inner_commute field_simps) | |
| 53406 | 3008 | finally have ?thesis . | 
| 3009 | } | |
| 44133 | 3010 | ultimately show ?thesis by blast | 
| 3011 | qed | |
| 3012 | ||
| 49522 | 3013 | |
| 44133 | 3014 | subsection {* Collinearity *}
 | 
| 3015 | ||
| 49522 | 3016 | definition collinear :: "'a::real_vector set \<Rightarrow> bool" | 
| 3017 | where "collinear S \<longleftrightarrow> (\<exists>u. \<forall>x \<in> S. \<forall> y \<in> S. \<exists>c. x - y = c *\<^sub>R u)" | |
| 44133 | 3018 | |
| 53406 | 3019 | lemma collinear_empty: "collinear {}"
 | 
| 3020 | by (simp add: collinear_def) | |
| 44133 | 3021 | |
| 3022 | lemma collinear_sing: "collinear {x}"
 | |
| 3023 | by (simp add: collinear_def) | |
| 3024 | ||
| 3025 | lemma collinear_2: "collinear {x, y}"
 | |
| 3026 | apply (simp add: collinear_def) | |
| 3027 | apply (rule exI[where x="x - y"]) | |
| 3028 | apply auto | |
| 3029 | apply (rule exI[where x=1], simp) | |
| 3030 | apply (rule exI[where x="- 1"], simp) | |
| 3031 | done | |
| 3032 | ||
| 53406 | 3033 | lemma collinear_lemma: "collinear {0,x,y} \<longleftrightarrow> x = 0 \<or> y = 0 \<or> (\<exists>c. y = c *\<^sub>R x)"
 | 
| 3034 | (is "?lhs \<longleftrightarrow> ?rhs") | |
| 49522 | 3035 | proof - | 
| 53406 | 3036 |   {
 | 
| 3037 | assume "x = 0 \<or> y = 0" | |
| 3038 | then have ?thesis | |
| 3039 | by (cases "x = 0") (simp_all add: collinear_2 insert_commute) | |
| 3040 | } | |
| 44133 | 3041 | moreover | 
| 53406 | 3042 |   {
 | 
| 3043 | assume x: "x \<noteq> 0" and y: "y \<noteq> 0" | |
| 3044 | have ?thesis | |
| 3045 | proof | |
| 3046 | assume h: "?lhs" | |
| 49522 | 3047 |       then obtain u where u: "\<forall> x\<in> {0,x,y}. \<forall>y\<in> {0,x,y}. \<exists>c. x - y = c *\<^sub>R u"
 | 
| 3048 | unfolding collinear_def by blast | |
| 44133 | 3049 | from u[rule_format, of x 0] u[rule_format, of y 0] | 
| 3050 | obtain cx and cy where | |
| 3051 | cx: "x = cx *\<^sub>R u" and cy: "y = cy *\<^sub>R u" | |
| 3052 | by auto | |
| 3053 | from cx x have cx0: "cx \<noteq> 0" by auto | |
| 3054 | from cy y have cy0: "cy \<noteq> 0" by auto | |
| 3055 | let ?d = "cy / cx" | |
| 3056 | from cx cy cx0 have "y = ?d *\<^sub>R x" | |
| 3057 | by simp | |
| 53406 | 3058 | then show ?rhs using x y by blast | 
| 3059 | next | |
| 3060 | assume h: "?rhs" | |
| 3061 | then obtain c where c: "y = c *\<^sub>R x" | |
| 3062 | using x y by blast | |
| 3063 | show ?lhs | |
| 3064 | unfolding collinear_def c | |
| 44133 | 3065 | apply (rule exI[where x=x]) | 
| 3066 | apply auto | |
| 3067 | apply (rule exI[where x="- 1"], simp) | |
| 3068 | apply (rule exI[where x= "-c"], simp) | |
| 3069 | apply (rule exI[where x=1], simp) | |
| 3070 | apply (rule exI[where x="1 - c"], simp add: scaleR_left_diff_distrib) | |
| 3071 | apply (rule exI[where x="c - 1"], simp add: scaleR_left_diff_distrib) | |
| 53406 | 3072 | done | 
| 3073 | qed | |
| 3074 | } | |
| 44133 | 3075 | ultimately show ?thesis by blast | 
| 3076 | qed | |
| 3077 | ||
| 53406 | 3078 | lemma norm_cauchy_schwarz_equal: "abs (x \<bullet> y) = norm x * norm y \<longleftrightarrow> collinear {0, x, y}"
 | 
| 49522 | 3079 | unfolding norm_cauchy_schwarz_abs_eq | 
| 3080 | apply (cases "x=0", simp_all add: collinear_2) | |
| 3081 | apply (cases "y=0", simp_all add: collinear_2 insert_commute) | |
| 3082 | unfolding collinear_lemma | |
| 3083 | apply simp | |
| 3084 | apply (subgoal_tac "norm x \<noteq> 0") | |
| 3085 | apply (subgoal_tac "norm y \<noteq> 0") | |
| 3086 | apply (rule iffI) | |
| 3087 | apply (cases "norm x *\<^sub>R y = norm y *\<^sub>R x") | |
| 3088 | apply (rule exI[where x="(1/norm x) * norm y"]) | |
| 3089 | apply (drule sym) | |
| 3090 | unfolding scaleR_scaleR[symmetric] | |
| 3091 | apply (simp add: field_simps) | |
| 3092 | apply (rule exI[where x="(1/norm x) * - norm y"]) | |
| 3093 | apply clarify | |
| 3094 | apply (drule sym) | |
| 3095 | unfolding scaleR_scaleR[symmetric] | |
| 3096 | apply (simp add: field_simps) | |
| 3097 | apply (erule exE) | |
| 3098 | apply (erule ssubst) | |
| 3099 | unfolding scaleR_scaleR | |
| 3100 | unfolding norm_scaleR | |
| 3101 | apply (subgoal_tac "norm x * c = \<bar>c\<bar> * norm x \<or> norm x * c = - \<bar>c\<bar> * norm x") | |
| 53406 | 3102 | apply (case_tac "c \<le> 0", simp add: field_simps) | 
| 49522 | 3103 | apply (simp add: field_simps) | 
| 53406 | 3104 | apply (case_tac "c \<le> 0", simp add: field_simps) | 
| 49522 | 3105 | apply (simp add: field_simps) | 
| 3106 | apply simp | |
| 3107 | apply simp | |
| 3108 | done | |
| 3109 | ||
| 54776 
db890d9fc5c2
ordered_euclidean_space compatible with more standard pointwise ordering on products; conditionally complete lattice with product order
 immler parents: 
54703diff
changeset | 3110 | end | 
| 
db890d9fc5c2
ordered_euclidean_space compatible with more standard pointwise ordering on products; conditionally complete lattice with product order
 immler parents: 
54703diff
changeset | 3111 |