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