src/HOL/Multivariate_Analysis/Linear_Algebra.thy
author hoelzl
Fri Apr 22 11:43:47 2016 +0200 (2016-04-22)
changeset 63050 ca4cce24c75d
parent 63007 aa894a49f77d
child 63051 e5e69206d52d
permissions -rw-r--r--
Linear_Algebra: move abstract concepts to front
<
huffman@44133
     1
(*  Title:      HOL/Multivariate_Analysis/Linear_Algebra.thy
huffman@44133
     2
    Author:     Amine Chaieb, University of Cambridge
huffman@44133
     3
*)
huffman@44133
     4
wenzelm@60420
     5
section \<open>Elementary linear algebra on Euclidean spaces\<close>
huffman@44133
     6
huffman@44133
     7
theory Linear_Algebra
huffman@44133
     8
imports
huffman@44133
     9
  Euclidean_Space
huffman@44133
    10
  "~~/src/HOL/Library/Infinite_Set"
huffman@44133
    11
begin
huffman@44133
    12
hoelzl@63050
    13
subsection \<open>A generic notion of "hull" (convex, affine, conic hull and closure).\<close>
hoelzl@63050
    14
hoelzl@63050
    15
definition hull :: "('a set \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set"  (infixl "hull" 75)
hoelzl@63050
    16
  where "S hull s = \<Inter>{t. S t \<and> s \<subseteq> t}"
hoelzl@63050
    17
hoelzl@63050
    18
lemma hull_same: "S s \<Longrightarrow> S hull s = s"
hoelzl@63050
    19
  unfolding hull_def by auto
hoelzl@63050
    20
hoelzl@63050
    21
lemma hull_in: "(\<And>T. Ball T S \<Longrightarrow> S (\<Inter>T)) \<Longrightarrow> S (S hull s)"
hoelzl@63050
    22
  unfolding hull_def Ball_def by auto
hoelzl@63050
    23
hoelzl@63050
    24
lemma hull_eq: "(\<And>T. Ball T S \<Longrightarrow> S (\<Inter>T)) \<Longrightarrow> (S hull s) = s \<longleftrightarrow> S s"
hoelzl@63050
    25
  using hull_same[of S s] hull_in[of S s] by metis
hoelzl@63050
    26
hoelzl@63050
    27
lemma hull_hull [simp]: "S hull (S hull s) = S hull s"
hoelzl@63050
    28
  unfolding hull_def by blast
hoelzl@63050
    29
hoelzl@63050
    30
lemma hull_subset[intro]: "s \<subseteq> (S hull s)"
hoelzl@63050
    31
  unfolding hull_def by blast
hoelzl@63050
    32
hoelzl@63050
    33
lemma hull_mono: "s \<subseteq> t \<Longrightarrow> (S hull s) \<subseteq> (S hull t)"
hoelzl@63050
    34
  unfolding hull_def by blast
hoelzl@63050
    35
hoelzl@63050
    36
lemma hull_antimono: "\<forall>x. S x \<longrightarrow> T x \<Longrightarrow> (T hull s) \<subseteq> (S hull s)"
hoelzl@63050
    37
  unfolding hull_def by blast
hoelzl@63050
    38
hoelzl@63050
    39
lemma hull_minimal: "s \<subseteq> t \<Longrightarrow> S t \<Longrightarrow> (S hull s) \<subseteq> t"
hoelzl@63050
    40
  unfolding hull_def by blast
hoelzl@63050
    41
hoelzl@63050
    42
lemma subset_hull: "S t \<Longrightarrow> S hull s \<subseteq> t \<longleftrightarrow> s \<subseteq> t"
hoelzl@63050
    43
  unfolding hull_def by blast
hoelzl@63050
    44
hoelzl@63050
    45
lemma hull_UNIV [simp]: "S hull UNIV = UNIV"
hoelzl@63050
    46
  unfolding hull_def by auto
hoelzl@63050
    47
hoelzl@63050
    48
lemma hull_unique: "s \<subseteq> t \<Longrightarrow> S t \<Longrightarrow> (\<And>t'. s \<subseteq> t' \<Longrightarrow> S t' \<Longrightarrow> t \<subseteq> t') \<Longrightarrow> (S hull s = t)"
hoelzl@63050
    49
  unfolding hull_def by auto
hoelzl@63050
    50
hoelzl@63050
    51
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"
hoelzl@63050
    52
  using hull_minimal[of S "{x. P x}" Q]
hoelzl@63050
    53
  by (auto simp add: subset_eq)
hoelzl@63050
    54
hoelzl@63050
    55
lemma hull_inc: "x \<in> S \<Longrightarrow> x \<in> P hull S"
hoelzl@63050
    56
  by (metis hull_subset subset_eq)
hoelzl@63050
    57
hoelzl@63050
    58
lemma hull_union_subset: "(S hull s) \<union> (S hull t) \<subseteq> (S hull (s \<union> t))"
hoelzl@63050
    59
  unfolding Un_subset_iff by (metis hull_mono Un_upper1 Un_upper2)
hoelzl@63050
    60
hoelzl@63050
    61
lemma hull_union:
hoelzl@63050
    62
  assumes T: "\<And>T. Ball T S \<Longrightarrow> S (\<Inter>T)"
hoelzl@63050
    63
  shows "S hull (s \<union> t) = S hull (S hull s \<union> S hull t)"
hoelzl@63050
    64
  apply rule
hoelzl@63050
    65
  apply (rule hull_mono)
hoelzl@63050
    66
  unfolding Un_subset_iff
hoelzl@63050
    67
  apply (metis hull_subset Un_upper1 Un_upper2 subset_trans)
hoelzl@63050
    68
  apply (rule hull_minimal)
hoelzl@63050
    69
  apply (metis hull_union_subset)
hoelzl@63050
    70
  apply (metis hull_in T)
huffman@44133
    71
  done
huffman@44133
    72
hoelzl@63050
    73
lemma hull_redundant_eq: "a \<in> (S hull s) \<longleftrightarrow> S hull (insert a s) = S hull s"
hoelzl@63050
    74
  unfolding hull_def by blast
hoelzl@63050
    75
hoelzl@63050
    76
lemma hull_redundant: "a \<in> (S hull s) \<Longrightarrow> S hull (insert a s) = S hull s"
hoelzl@63050
    77
  by (metis hull_redundant_eq)
wenzelm@49522
    78
wenzelm@60420
    79
subsection \<open>Linear functions.\<close>
wenzelm@49522
    80
huffman@53600
    81
lemma linear_iff:
wenzelm@53716
    82
  "linear f \<longleftrightarrow> (\<forall>x y. f (x + y) = f x + f y) \<and> (\<forall>c x. f (c *\<^sub>R x) = c *\<^sub>R f x)"
huffman@53600
    83
  (is "linear f \<longleftrightarrow> ?rhs")
huffman@53600
    84
proof
wenzelm@56444
    85
  assume "linear f"
wenzelm@56444
    86
  then interpret f: linear f .
huffman@53600
    87
  show "?rhs" by (simp add: f.add f.scaleR)
huffman@53600
    88
next
wenzelm@56444
    89
  assume "?rhs"
wenzelm@56444
    90
  then show "linear f" by unfold_locales simp_all
huffman@53600
    91
qed
huffman@44133
    92
wenzelm@53406
    93
lemma linear_compose_cmul: "linear f \<Longrightarrow> linear (\<lambda>x. c *\<^sub>R f x)"
huffman@53600
    94
  by (simp add: linear_iff algebra_simps)
huffman@44133
    95
lp15@63007
    96
lemma linear_compose_scaleR: "linear f \<Longrightarrow> linear (\<lambda>x. f x *\<^sub>R c)"
lp15@63007
    97
  by (simp add: linear_iff scaleR_add_left)
lp15@63007
    98
wenzelm@53406
    99
lemma linear_compose_neg: "linear f \<Longrightarrow> linear (\<lambda>x. - f x)"
huffman@53600
   100
  by (simp add: linear_iff)
huffman@44133
   101
wenzelm@53406
   102
lemma linear_compose_add: "linear f \<Longrightarrow> linear g \<Longrightarrow> linear (\<lambda>x. f x + g x)"
huffman@53600
   103
  by (simp add: linear_iff algebra_simps)
huffman@44133
   104
wenzelm@53406
   105
lemma linear_compose_sub: "linear f \<Longrightarrow> linear g \<Longrightarrow> linear (\<lambda>x. f x - g x)"
huffman@53600
   106
  by (simp add: linear_iff algebra_simps)
huffman@44133
   107
wenzelm@53406
   108
lemma linear_compose: "linear f \<Longrightarrow> linear g \<Longrightarrow> linear (g \<circ> f)"
huffman@53600
   109
  by (simp add: linear_iff)
huffman@44133
   110
wenzelm@53406
   111
lemma linear_id: "linear id"
huffman@53600
   112
  by (simp add: linear_iff id_def)
wenzelm@53406
   113
wenzelm@53406
   114
lemma linear_zero: "linear (\<lambda>x. 0)"
huffman@53600
   115
  by (simp add: linear_iff)
huffman@44133
   116
huffman@44133
   117
lemma linear_compose_setsum:
huffman@56196
   118
  assumes lS: "\<forall>a \<in> S. linear (f a)"
wenzelm@53716
   119
  shows "linear (\<lambda>x. setsum (\<lambda>a. f a x) S)"
huffman@56196
   120
proof (cases "finite S")
huffman@56196
   121
  case True
huffman@56196
   122
  then show ?thesis
huffman@56196
   123
    using lS by induct (simp_all add: linear_zero linear_compose_add)
wenzelm@56444
   124
next
wenzelm@56444
   125
  case False
wenzelm@56444
   126
  then show ?thesis
wenzelm@56444
   127
    by (simp add: linear_zero)
wenzelm@56444
   128
qed
huffman@44133
   129
huffman@44133
   130
lemma linear_0: "linear f \<Longrightarrow> f 0 = 0"
huffman@53600
   131
  unfolding linear_iff
huffman@44133
   132
  apply clarsimp
huffman@44133
   133
  apply (erule allE[where x="0::'a"])
huffman@44133
   134
  apply simp
huffman@44133
   135
  done
huffman@44133
   136
wenzelm@53406
   137
lemma linear_cmul: "linear f \<Longrightarrow> f (c *\<^sub>R x) = c *\<^sub>R f x"
lp15@60800
   138
  by (rule linear.scaleR)
huffman@44133
   139
wenzelm@53406
   140
lemma linear_neg: "linear f \<Longrightarrow> f (- x) = - f x"
huffman@44133
   141
  using linear_cmul [where c="-1"] by simp
huffman@44133
   142
wenzelm@53716
   143
lemma linear_add: "linear f \<Longrightarrow> f (x + y) = f x + f y"
huffman@53600
   144
  by (metis linear_iff)
huffman@44133
   145
wenzelm@53716
   146
lemma linear_sub: "linear f \<Longrightarrow> f (x - y) = f x - f y"
haftmann@54230
   147
  using linear_add [of f x "- y"] by (simp add: linear_neg)
huffman@44133
   148
huffman@44133
   149
lemma linear_setsum:
huffman@56196
   150
  assumes f: "linear f"
wenzelm@53406
   151
  shows "f (setsum g S) = setsum (f \<circ> g) S"
huffman@56196
   152
proof (cases "finite S")
huffman@56196
   153
  case True
huffman@56196
   154
  then show ?thesis
huffman@56196
   155
    by induct (simp_all add: linear_0 [OF f] linear_add [OF f])
wenzelm@56444
   156
next
wenzelm@56444
   157
  case False
wenzelm@56444
   158
  then show ?thesis
wenzelm@56444
   159
    by (simp add: linear_0 [OF f])
wenzelm@56444
   160
qed
huffman@44133
   161
huffman@44133
   162
lemma linear_setsum_mul:
wenzelm@53406
   163
  assumes lin: "linear f"
huffman@44133
   164
  shows "f (setsum (\<lambda>i. c i *\<^sub>R v i) S) = setsum (\<lambda>i. c i *\<^sub>R f (v i)) S"
huffman@56196
   165
  using linear_setsum[OF lin, of "\<lambda>i. c i *\<^sub>R v i" , unfolded o_def] linear_cmul[OF lin]
wenzelm@49522
   166
  by simp
huffman@44133
   167
huffman@44133
   168
lemma linear_injective_0:
wenzelm@53406
   169
  assumes lin: "linear f"
huffman@44133
   170
  shows "inj f \<longleftrightarrow> (\<forall>x. f x = 0 \<longrightarrow> x = 0)"
wenzelm@49663
   171
proof -
wenzelm@53406
   172
  have "inj f \<longleftrightarrow> (\<forall> x y. f x = f y \<longrightarrow> x = y)"
wenzelm@53406
   173
    by (simp add: inj_on_def)
wenzelm@53406
   174
  also have "\<dots> \<longleftrightarrow> (\<forall> x y. f x - f y = 0 \<longrightarrow> x - y = 0)"
wenzelm@53406
   175
    by simp
huffman@44133
   176
  also have "\<dots> \<longleftrightarrow> (\<forall> x y. f (x - y) = 0 \<longrightarrow> x - y = 0)"
wenzelm@53406
   177
    by (simp add: linear_sub[OF lin])
wenzelm@53406
   178
  also have "\<dots> \<longleftrightarrow> (\<forall> x. f x = 0 \<longrightarrow> x = 0)"
wenzelm@53406
   179
    by auto
huffman@44133
   180
  finally show ?thesis .
huffman@44133
   181
qed
huffman@44133
   182
lp15@61520
   183
lemma linear_scaleR  [simp]: "linear (\<lambda>x. scaleR c x)"
lp15@61520
   184
  by (simp add: linear_iff scaleR_add_right)
lp15@61520
   185
lp15@61520
   186
lemma linear_scaleR_left [simp]: "linear (\<lambda>r. scaleR r x)"
lp15@61520
   187
  by (simp add: linear_iff scaleR_add_left)
lp15@61520
   188
lp15@61520
   189
lemma injective_scaleR: "c \<noteq> 0 \<Longrightarrow> inj (\<lambda>x::'a::real_vector. scaleR c x)"
lp15@61520
   190
  by (simp add: inj_on_def)
lp15@61520
   191
lp15@61520
   192
lemma linear_add_cmul:
lp15@61520
   193
  assumes "linear f"
lp15@61520
   194
  shows "f (a *\<^sub>R x + b *\<^sub>R y) = a *\<^sub>R f x +  b *\<^sub>R f y"
lp15@61520
   195
  using linear_add[of f] linear_cmul[of f] assms by simp
lp15@61520
   196
hoelzl@63050
   197
subsection \<open>Subspaces of vector spaces\<close>
huffman@44133
   198
wenzelm@49522
   199
definition (in real_vector) subspace :: "'a set \<Rightarrow> bool"
wenzelm@56444
   200
  where "subspace S \<longleftrightarrow> 0 \<in> S \<and> (\<forall>x \<in> S. \<forall>y \<in> S. x + y \<in> S) \<and> (\<forall>c. \<forall>x \<in> S. c *\<^sub>R x \<in> S)"
huffman@44133
   201
huffman@44133
   202
definition (in real_vector) "span S = (subspace hull S)"
wenzelm@53716
   203
definition (in real_vector) "dependent S \<longleftrightarrow> (\<exists>a \<in> S. a \<in> span (S - {a}))"
wenzelm@53406
   204
abbreviation (in real_vector) "independent s \<equiv> \<not> dependent s"
huffman@44133
   205
wenzelm@60420
   206
text \<open>Closure properties of subspaces.\<close>
huffman@44133
   207
wenzelm@53406
   208
lemma subspace_UNIV[simp]: "subspace UNIV"
wenzelm@53406
   209
  by (simp add: subspace_def)
wenzelm@53406
   210
wenzelm@53406
   211
lemma (in real_vector) subspace_0: "subspace S \<Longrightarrow> 0 \<in> S"
wenzelm@53406
   212
  by (metis subspace_def)
wenzelm@53406
   213
wenzelm@53406
   214
lemma (in real_vector) subspace_add: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x + y \<in> S"
huffman@44133
   215
  by (metis subspace_def)
huffman@44133
   216
huffman@44133
   217
lemma (in real_vector) subspace_mul: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> c *\<^sub>R x \<in> S"
huffman@44133
   218
  by (metis subspace_def)
huffman@44133
   219
huffman@44133
   220
lemma subspace_neg: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> - x \<in> S"
huffman@44133
   221
  by (metis scaleR_minus1_left subspace_mul)
huffman@44133
   222
huffman@44133
   223
lemma subspace_sub: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x - y \<in> S"
haftmann@54230
   224
  using subspace_add [of S x "- y"] by (simp add: subspace_neg)
huffman@44133
   225
huffman@44133
   226
lemma (in real_vector) subspace_setsum:
wenzelm@53406
   227
  assumes sA: "subspace A"
huffman@56196
   228
    and f: "\<forall>x\<in>B. f x \<in> A"
huffman@44133
   229
  shows "setsum f B \<in> A"
huffman@56196
   230
proof (cases "finite B")
huffman@56196
   231
  case True
huffman@56196
   232
  then show ?thesis
huffman@56196
   233
    using f by induct (simp_all add: subspace_0 [OF sA] subspace_add [OF sA])
huffman@56196
   234
qed (simp add: subspace_0 [OF sA])
huffman@44133
   235
huffman@44133
   236
lemma subspace_trivial: "subspace {0}"
huffman@44133
   237
  by (simp add: subspace_def)
huffman@44133
   238
wenzelm@53406
   239
lemma (in real_vector) subspace_inter: "subspace A \<Longrightarrow> subspace B \<Longrightarrow> subspace (A \<inter> B)"
huffman@44133
   240
  by (simp add: subspace_def)
huffman@44133
   241
wenzelm@53406
   242
lemma subspace_Times: "subspace A \<Longrightarrow> subspace B \<Longrightarrow> subspace (A \<times> B)"
huffman@44521
   243
  unfolding subspace_def zero_prod_def by simp
huffman@44521
   244
wenzelm@60420
   245
text \<open>Properties of span.\<close>
huffman@44521
   246
wenzelm@53406
   247
lemma (in real_vector) span_mono: "A \<subseteq> B \<Longrightarrow> span A \<subseteq> span B"
huffman@44133
   248
  by (metis span_def hull_mono)
huffman@44133
   249
wenzelm@53406
   250
lemma (in real_vector) subspace_span: "subspace (span S)"
huffman@44133
   251
  unfolding span_def
huffman@44170
   252
  apply (rule hull_in)
huffman@44133
   253
  apply (simp only: subspace_def Inter_iff Int_iff subset_eq)
huffman@44133
   254
  apply auto
huffman@44133
   255
  done
huffman@44133
   256
huffman@44133
   257
lemma (in real_vector) span_clauses:
wenzelm@53406
   258
  "a \<in> S \<Longrightarrow> a \<in> span S"
huffman@44133
   259
  "0 \<in> span S"
wenzelm@53406
   260
  "x\<in> span S \<Longrightarrow> y \<in> span S \<Longrightarrow> x + y \<in> span S"
huffman@44133
   261
  "x \<in> span S \<Longrightarrow> c *\<^sub>R x \<in> span S"
wenzelm@53406
   262
  by (metis span_def hull_subset subset_eq) (metis subspace_span subspace_def)+
huffman@44133
   263
huffman@44521
   264
lemma span_unique:
wenzelm@49522
   265
  "S \<subseteq> T \<Longrightarrow> subspace T \<Longrightarrow> (\<And>T'. S \<subseteq> T' \<Longrightarrow> subspace T' \<Longrightarrow> T \<subseteq> T') \<Longrightarrow> span S = T"
huffman@44521
   266
  unfolding span_def by (rule hull_unique)
huffman@44521
   267
huffman@44521
   268
lemma span_minimal: "S \<subseteq> T \<Longrightarrow> subspace T \<Longrightarrow> span S \<subseteq> T"
huffman@44521
   269
  unfolding span_def by (rule hull_minimal)
huffman@44521
   270
huffman@44521
   271
lemma (in real_vector) span_induct:
wenzelm@49522
   272
  assumes x: "x \<in> span S"
wenzelm@49522
   273
    and P: "subspace P"
wenzelm@53406
   274
    and SP: "\<And>x. x \<in> S \<Longrightarrow> x \<in> P"
huffman@44521
   275
  shows "x \<in> P"
wenzelm@49522
   276
proof -
wenzelm@53406
   277
  from SP have SP': "S \<subseteq> P"
wenzelm@53406
   278
    by (simp add: subset_eq)
huffman@44170
   279
  from x hull_minimal[where S=subspace, OF SP' P, unfolded span_def[symmetric]]
wenzelm@53406
   280
  show "x \<in> P"
wenzelm@53406
   281
    by (metis subset_eq)
huffman@44133
   282
qed
huffman@44133
   283
huffman@44133
   284
lemma span_empty[simp]: "span {} = {0}"
huffman@44133
   285
  apply (simp add: span_def)
huffman@44133
   286
  apply (rule hull_unique)
huffman@44170
   287
  apply (auto simp add: subspace_def)
huffman@44133
   288
  done
huffman@44133
   289
lp15@62948
   290
lemma (in real_vector) independent_empty [iff]: "independent {}"
huffman@44133
   291
  by (simp add: dependent_def)
huffman@44133
   292
wenzelm@49522
   293
lemma dependent_single[simp]: "dependent {x} \<longleftrightarrow> x = 0"
huffman@44133
   294
  unfolding dependent_def by auto
huffman@44133
   295
wenzelm@53406
   296
lemma (in real_vector) independent_mono: "independent A \<Longrightarrow> B \<subseteq> A \<Longrightarrow> independent B"
huffman@44133
   297
  apply (clarsimp simp add: dependent_def span_mono)
huffman@44133
   298
  apply (subgoal_tac "span (B - {a}) \<le> span (A - {a})")
huffman@44133
   299
  apply force
huffman@44133
   300
  apply (rule span_mono)
huffman@44133
   301
  apply auto
huffman@44133
   302
  done
huffman@44133
   303
huffman@44133
   304
lemma (in real_vector) span_subspace: "A \<subseteq> B \<Longrightarrow> B \<le> span A \<Longrightarrow>  subspace B \<Longrightarrow> span A = B"
huffman@44170
   305
  by (metis order_antisym span_def hull_minimal)
huffman@44133
   306
wenzelm@49711
   307
lemma (in real_vector) span_induct':
hoelzl@63050
   308
  "\<forall>x \<in> S. P x \<Longrightarrow> subspace {x. P x} \<Longrightarrow> \<forall>x \<in> span S. P x"
hoelzl@63050
   309
  unfolding span_def by (rule hull_induct) auto
huffman@44133
   310
wenzelm@56444
   311
inductive_set (in real_vector) span_induct_alt_help for S :: "'a set"
wenzelm@53406
   312
where
huffman@44170
   313
  span_induct_alt_help_0: "0 \<in> span_induct_alt_help S"
wenzelm@49522
   314
| span_induct_alt_help_S:
wenzelm@53406
   315
    "x \<in> S \<Longrightarrow> z \<in> span_induct_alt_help S \<Longrightarrow>
wenzelm@53406
   316
      (c *\<^sub>R x + z) \<in> span_induct_alt_help S"
huffman@44133
   317
huffman@44133
   318
lemma span_induct_alt':
wenzelm@53406
   319
  assumes h0: "h 0"
wenzelm@53406
   320
    and hS: "\<And>c x y. x \<in> S \<Longrightarrow> h y \<Longrightarrow> h (c *\<^sub>R x + y)"
wenzelm@49522
   321
  shows "\<forall>x \<in> span S. h x"
wenzelm@49522
   322
proof -
wenzelm@53406
   323
  {
wenzelm@53406
   324
    fix x :: 'a
wenzelm@53406
   325
    assume x: "x \<in> span_induct_alt_help S"
huffman@44133
   326
    have "h x"
huffman@44133
   327
      apply (rule span_induct_alt_help.induct[OF x])
huffman@44133
   328
      apply (rule h0)
wenzelm@53406
   329
      apply (rule hS)
wenzelm@53406
   330
      apply assumption
wenzelm@53406
   331
      apply assumption
wenzelm@53406
   332
      done
wenzelm@53406
   333
  }
huffman@44133
   334
  note th0 = this
wenzelm@53406
   335
  {
wenzelm@53406
   336
    fix x
wenzelm@53406
   337
    assume x: "x \<in> span S"
huffman@44170
   338
    have "x \<in> span_induct_alt_help S"
wenzelm@49522
   339
    proof (rule span_induct[where x=x and S=S])
wenzelm@53406
   340
      show "x \<in> span S" by (rule x)
wenzelm@49522
   341
    next
wenzelm@53406
   342
      fix x
wenzelm@53406
   343
      assume xS: "x \<in> S"
wenzelm@53406
   344
      from span_induct_alt_help_S[OF xS span_induct_alt_help_0, of 1]
wenzelm@53406
   345
      show "x \<in> span_induct_alt_help S"
wenzelm@53406
   346
        by simp
wenzelm@49522
   347
    next
wenzelm@49522
   348
      have "0 \<in> span_induct_alt_help S" by (rule span_induct_alt_help_0)
wenzelm@49522
   349
      moreover
wenzelm@53406
   350
      {
wenzelm@53406
   351
        fix x y
wenzelm@49522
   352
        assume h: "x \<in> span_induct_alt_help S" "y \<in> span_induct_alt_help S"
wenzelm@49522
   353
        from h have "(x + y) \<in> span_induct_alt_help S"
wenzelm@49522
   354
          apply (induct rule: span_induct_alt_help.induct)
wenzelm@49522
   355
          apply simp
haftmann@57512
   356
          unfolding add.assoc
wenzelm@49522
   357
          apply (rule span_induct_alt_help_S)
wenzelm@49522
   358
          apply assumption
wenzelm@49522
   359
          apply simp
wenzelm@53406
   360
          done
wenzelm@53406
   361
      }
wenzelm@49522
   362
      moreover
wenzelm@53406
   363
      {
wenzelm@53406
   364
        fix c x
wenzelm@49522
   365
        assume xt: "x \<in> span_induct_alt_help S"
wenzelm@49522
   366
        then have "(c *\<^sub>R x) \<in> span_induct_alt_help S"
wenzelm@49522
   367
          apply (induct rule: span_induct_alt_help.induct)
wenzelm@49522
   368
          apply (simp add: span_induct_alt_help_0)
wenzelm@49522
   369
          apply (simp add: scaleR_right_distrib)
wenzelm@49522
   370
          apply (rule span_induct_alt_help_S)
wenzelm@49522
   371
          apply assumption
wenzelm@49522
   372
          apply simp
wenzelm@49522
   373
          done }
wenzelm@53406
   374
      ultimately show "subspace (span_induct_alt_help S)"
wenzelm@49522
   375
        unfolding subspace_def Ball_def by blast
wenzelm@53406
   376
    qed
wenzelm@53406
   377
  }
huffman@44133
   378
  with th0 show ?thesis by blast
huffman@44133
   379
qed
huffman@44133
   380
huffman@44133
   381
lemma span_induct_alt:
wenzelm@53406
   382
  assumes h0: "h 0"
wenzelm@53406
   383
    and hS: "\<And>c x y. x \<in> S \<Longrightarrow> h y \<Longrightarrow> h (c *\<^sub>R x + y)"
wenzelm@53406
   384
    and x: "x \<in> span S"
huffman@44133
   385
  shows "h x"
wenzelm@49522
   386
  using span_induct_alt'[of h S] h0 hS x by blast
huffman@44133
   387
wenzelm@60420
   388
text \<open>Individual closure properties.\<close>
huffman@44133
   389
huffman@44133
   390
lemma span_span: "span (span A) = span A"
huffman@44133
   391
  unfolding span_def hull_hull ..
huffman@44133
   392
wenzelm@53406
   393
lemma (in real_vector) span_superset: "x \<in> S \<Longrightarrow> x \<in> span S"
wenzelm@53406
   394
  by (metis span_clauses(1))
wenzelm@53406
   395
wenzelm@53406
   396
lemma (in real_vector) span_0: "0 \<in> span S"
wenzelm@53406
   397
  by (metis subspace_span subspace_0)
huffman@44133
   398
huffman@44133
   399
lemma span_inc: "S \<subseteq> span S"
huffman@44133
   400
  by (metis subset_eq span_superset)
huffman@44133
   401
wenzelm@53406
   402
lemma (in real_vector) dependent_0:
wenzelm@53406
   403
  assumes "0 \<in> A"
wenzelm@53406
   404
  shows "dependent A"
wenzelm@53406
   405
  unfolding dependent_def
wenzelm@53406
   406
  using assms span_0
lp15@60162
   407
  by auto
wenzelm@53406
   408
wenzelm@53406
   409
lemma (in real_vector) span_add: "x \<in> span S \<Longrightarrow> y \<in> span S \<Longrightarrow> x + y \<in> span S"
huffman@44133
   410
  by (metis subspace_add subspace_span)
huffman@44133
   411
wenzelm@53406
   412
lemma (in real_vector) span_mul: "x \<in> span S \<Longrightarrow> c *\<^sub>R x \<in> span S"
huffman@44133
   413
  by (metis subspace_span subspace_mul)
huffman@44133
   414
wenzelm@53406
   415
lemma span_neg: "x \<in> span S \<Longrightarrow> - x \<in> span S"
huffman@44133
   416
  by (metis subspace_neg subspace_span)
huffman@44133
   417
wenzelm@53406
   418
lemma span_sub: "x \<in> span S \<Longrightarrow> y \<in> span S \<Longrightarrow> x - y \<in> span S"
huffman@44133
   419
  by (metis subspace_span subspace_sub)
huffman@44133
   420
huffman@56196
   421
lemma (in real_vector) span_setsum: "\<forall>x\<in>A. f x \<in> span S \<Longrightarrow> setsum f A \<in> span S"
huffman@56196
   422
  by (rule subspace_setsum [OF subspace_span])
huffman@44133
   423
huffman@44133
   424
lemma span_add_eq: "x \<in> span S \<Longrightarrow> x + y \<in> span S \<longleftrightarrow> y \<in> span S"
lp15@55775
   425
  by (metis add_minus_cancel scaleR_minus1_left subspace_def subspace_span)
huffman@44133
   426
hoelzl@63050
   427
text \<open>The key breakdown property.\<close>
hoelzl@63050
   428
hoelzl@63050
   429
lemma span_singleton: "span {x} = range (\<lambda>k. k *\<^sub>R x)"
hoelzl@63050
   430
proof (rule span_unique)
hoelzl@63050
   431
  show "{x} \<subseteq> range (\<lambda>k. k *\<^sub>R x)"
hoelzl@63050
   432
    by (fast intro: scaleR_one [symmetric])
hoelzl@63050
   433
  show "subspace (range (\<lambda>k. k *\<^sub>R x))"
hoelzl@63050
   434
    unfolding subspace_def
hoelzl@63050
   435
    by (auto intro: scaleR_add_left [symmetric])
hoelzl@63050
   436
next
hoelzl@63050
   437
  fix T
hoelzl@63050
   438
  assume "{x} \<subseteq> T" and "subspace T"
hoelzl@63050
   439
  then show "range (\<lambda>k. k *\<^sub>R x) \<subseteq> T"
hoelzl@63050
   440
    unfolding subspace_def by auto
hoelzl@63050
   441
qed
hoelzl@63050
   442
wenzelm@60420
   443
text \<open>Mapping under linear image.\<close>
huffman@44133
   444
hoelzl@63050
   445
lemma subspace_linear_image:
hoelzl@63050
   446
  assumes lf: "linear f"
hoelzl@63050
   447
    and sS: "subspace S"
hoelzl@63050
   448
  shows "subspace (f ` S)"
hoelzl@63050
   449
  using lf sS linear_0[OF lf]
hoelzl@63050
   450
  unfolding linear_iff subspace_def
hoelzl@63050
   451
  apply (auto simp add: image_iff)
hoelzl@63050
   452
  apply (rule_tac x="x + y" in bexI)
hoelzl@63050
   453
  apply auto
hoelzl@63050
   454
  apply (rule_tac x="c *\<^sub>R x" in bexI)
hoelzl@63050
   455
  apply auto
hoelzl@63050
   456
  done
hoelzl@63050
   457
hoelzl@63050
   458
lemma subspace_linear_vimage: "linear f \<Longrightarrow> subspace S \<Longrightarrow> subspace (f -` S)"
hoelzl@63050
   459
  by (auto simp add: subspace_def linear_iff linear_0[of f])
hoelzl@63050
   460
hoelzl@63050
   461
lemma subspace_linear_preimage: "linear f \<Longrightarrow> subspace S \<Longrightarrow> subspace {x. f x \<in> S}"
hoelzl@63050
   462
  by (auto simp add: subspace_def linear_iff linear_0[of f])
hoelzl@63050
   463
huffman@44521
   464
lemma span_linear_image:
huffman@44521
   465
  assumes lf: "linear f"
wenzelm@56444
   466
  shows "span (f ` S) = f ` span S"
huffman@44521
   467
proof (rule span_unique)
huffman@44521
   468
  show "f ` S \<subseteq> f ` span S"
huffman@44521
   469
    by (intro image_mono span_inc)
huffman@44521
   470
  show "subspace (f ` span S)"
huffman@44521
   471
    using lf subspace_span by (rule subspace_linear_image)
huffman@44521
   472
next
wenzelm@53406
   473
  fix T
wenzelm@53406
   474
  assume "f ` S \<subseteq> T" and "subspace T"
wenzelm@49522
   475
  then show "f ` span S \<subseteq> T"
huffman@44521
   476
    unfolding image_subset_iff_subset_vimage
huffman@44521
   477
    by (intro span_minimal subspace_linear_vimage lf)
huffman@44521
   478
qed
huffman@44521
   479
huffman@44521
   480
lemma span_union: "span (A \<union> B) = (\<lambda>(a, b). a + b) ` (span A \<times> span B)"
huffman@44521
   481
proof (rule span_unique)
huffman@44521
   482
  show "A \<union> B \<subseteq> (\<lambda>(a, b). a + b) ` (span A \<times> span B)"
huffman@44521
   483
    by safe (force intro: span_clauses)+
huffman@44521
   484
next
huffman@44521
   485
  have "linear (\<lambda>(a, b). a + b)"
huffman@53600
   486
    by (simp add: linear_iff scaleR_add_right)
huffman@44521
   487
  moreover have "subspace (span A \<times> span B)"
huffman@44521
   488
    by (intro subspace_Times subspace_span)
huffman@44521
   489
  ultimately show "subspace ((\<lambda>(a, b). a + b) ` (span A \<times> span B))"
huffman@44521
   490
    by (rule subspace_linear_image)
huffman@44521
   491
next
wenzelm@49711
   492
  fix T
wenzelm@49711
   493
  assume "A \<union> B \<subseteq> T" and "subspace T"
wenzelm@49522
   494
  then show "(\<lambda>(a, b). a + b) ` (span A \<times> span B) \<subseteq> T"
huffman@44521
   495
    by (auto intro!: subspace_add elim: span_induct)
huffman@44133
   496
qed
huffman@44133
   497
wenzelm@49522
   498
lemma span_insert: "span (insert a S) = {x. \<exists>k. (x - k *\<^sub>R a) \<in> span S}"
huffman@44521
   499
proof -
huffman@44521
   500
  have "span ({a} \<union> S) = {x. \<exists>k. (x - k *\<^sub>R a) \<in> span S}"
huffman@44521
   501
    unfolding span_union span_singleton
huffman@44521
   502
    apply safe
huffman@44521
   503
    apply (rule_tac x=k in exI, simp)
huffman@44521
   504
    apply (erule rev_image_eqI [OF SigmaI [OF rangeI]])
haftmann@54230
   505
    apply auto
huffman@44521
   506
    done
wenzelm@49522
   507
  then show ?thesis by simp
huffman@44521
   508
qed
huffman@44521
   509
huffman@44133
   510
lemma span_breakdown:
wenzelm@53406
   511
  assumes bS: "b \<in> S"
wenzelm@53406
   512
    and aS: "a \<in> span S"
huffman@44521
   513
  shows "\<exists>k. a - k *\<^sub>R b \<in> span (S - {b})"
huffman@44521
   514
  using assms span_insert [of b "S - {b}"]
huffman@44521
   515
  by (simp add: insert_absorb)
huffman@44133
   516
wenzelm@53406
   517
lemma span_breakdown_eq: "x \<in> span (insert a S) \<longleftrightarrow> (\<exists>k. x - k *\<^sub>R a \<in> span S)"
huffman@44521
   518
  by (simp add: span_insert)
huffman@44133
   519
wenzelm@60420
   520
text \<open>Hence some "reversal" results.\<close>
huffman@44133
   521
huffman@44133
   522
lemma in_span_insert:
wenzelm@49711
   523
  assumes a: "a \<in> span (insert b S)"
wenzelm@49711
   524
    and na: "a \<notin> span S"
huffman@44133
   525
  shows "b \<in> span (insert a S)"
wenzelm@49663
   526
proof -
huffman@55910
   527
  from a obtain k where k: "a - k *\<^sub>R b \<in> span S"
huffman@55910
   528
    unfolding span_insert by fast
wenzelm@53406
   529
  show ?thesis
wenzelm@53406
   530
  proof (cases "k = 0")
wenzelm@53406
   531
    case True
huffman@55910
   532
    with k have "a \<in> span S" by simp
huffman@55910
   533
    with na show ?thesis by simp
wenzelm@53406
   534
  next
wenzelm@53406
   535
    case False
huffman@55910
   536
    from k have "(- inverse k) *\<^sub>R (a - k *\<^sub>R b) \<in> span S"
huffman@44133
   537
      by (rule span_mul)
huffman@55910
   538
    then have "b - inverse k *\<^sub>R a \<in> span S"
wenzelm@60420
   539
      using \<open>k \<noteq> 0\<close> by (simp add: scaleR_diff_right)
huffman@55910
   540
    then show ?thesis
huffman@55910
   541
      unfolding span_insert by fast
wenzelm@53406
   542
  qed
huffman@44133
   543
qed
huffman@44133
   544
huffman@44133
   545
lemma in_span_delete:
huffman@44133
   546
  assumes a: "a \<in> span S"
wenzelm@53716
   547
    and na: "a \<notin> span (S - {b})"
huffman@44133
   548
  shows "b \<in> span (insert a (S - {b}))"
huffman@44133
   549
  apply (rule in_span_insert)
huffman@44133
   550
  apply (rule set_rev_mp)
huffman@44133
   551
  apply (rule a)
huffman@44133
   552
  apply (rule span_mono)
huffman@44133
   553
  apply blast
huffman@44133
   554
  apply (rule na)
huffman@44133
   555
  done
huffman@44133
   556
wenzelm@60420
   557
text \<open>Transitivity property.\<close>
huffman@44133
   558
huffman@44521
   559
lemma span_redundant: "x \<in> span S \<Longrightarrow> span (insert x S) = span S"
huffman@44521
   560
  unfolding span_def by (rule hull_redundant)
huffman@44521
   561
huffman@44133
   562
lemma span_trans:
wenzelm@53406
   563
  assumes x: "x \<in> span S"
wenzelm@53406
   564
    and y: "y \<in> span (insert x S)"
huffman@44133
   565
  shows "y \<in> span S"
huffman@44521
   566
  using assms by (simp only: span_redundant)
huffman@44133
   567
huffman@44133
   568
lemma span_insert_0[simp]: "span (insert 0 S) = span S"
huffman@44521
   569
  by (simp only: span_redundant span_0)
huffman@44133
   570
wenzelm@60420
   571
text \<open>An explicit expansion is sometimes needed.\<close>
huffman@44133
   572
huffman@44133
   573
lemma span_explicit:
huffman@44133
   574
  "span P = {y. \<exists>S u. finite S \<and> S \<subseteq> P \<and> setsum (\<lambda>v. u v *\<^sub>R v) S = y}"
huffman@44133
   575
  (is "_ = ?E" is "_ = {y. ?h y}" is "_ = {y. \<exists>S u. ?Q S u y}")
wenzelm@49663
   576
proof -
wenzelm@53406
   577
  {
wenzelm@53406
   578
    fix x
huffman@55910
   579
    assume "?h x"
huffman@55910
   580
    then obtain S u where "finite S" and "S \<subseteq> P" and "setsum (\<lambda>v. u v *\<^sub>R v) S = x"
huffman@44133
   581
      by blast
huffman@55910
   582
    then have "x \<in> span P"
huffman@55910
   583
      by (auto intro: span_setsum span_mul span_superset)
wenzelm@53406
   584
  }
huffman@44133
   585
  moreover
huffman@55910
   586
  have "\<forall>x \<in> span P. ?h x"
wenzelm@49522
   587
  proof (rule span_induct_alt')
huffman@55910
   588
    show "?h 0"
huffman@55910
   589
      by (rule exI[where x="{}"], simp)
huffman@44133
   590
  next
huffman@44133
   591
    fix c x y
wenzelm@53406
   592
    assume x: "x \<in> P"
huffman@55910
   593
    assume hy: "?h y"
huffman@44133
   594
    from hy obtain S u where fS: "finite S" and SP: "S\<subseteq>P"
huffman@44133
   595
      and u: "setsum (\<lambda>v. u v *\<^sub>R v) S = y" by blast
huffman@44133
   596
    let ?S = "insert x S"
wenzelm@49522
   597
    let ?u = "\<lambda>y. if y = x then (if x \<in> S then u y + c else c) else u y"
wenzelm@53406
   598
    from fS SP x have th0: "finite (insert x S)" "insert x S \<subseteq> P"
wenzelm@53406
   599
      by blast+
wenzelm@53406
   600
    have "?Q ?S ?u (c*\<^sub>R x + y)"
wenzelm@53406
   601
    proof cases
wenzelm@53406
   602
      assume xS: "x \<in> S"
huffman@55910
   603
      have "setsum (\<lambda>v. ?u v *\<^sub>R v) ?S = (\<Sum>v\<in>S - {x}. u v *\<^sub>R v) + (u x + c) *\<^sub>R x"
huffman@55910
   604
        using xS by (simp add: setsum.remove [OF fS xS] insert_absorb)
huffman@44133
   605
      also have "\<dots> = (\<Sum>v\<in>S. u v *\<^sub>R v) + c *\<^sub>R x"
huffman@55910
   606
        by (simp add: setsum.remove [OF fS xS] algebra_simps)
huffman@44133
   607
      also have "\<dots> = c*\<^sub>R x + y"
haftmann@57512
   608
        by (simp add: add.commute u)
huffman@44133
   609
      finally have "setsum (\<lambda>v. ?u v *\<^sub>R v) ?S = c*\<^sub>R x + y" .
wenzelm@53406
   610
      then show ?thesis using th0 by blast
wenzelm@53406
   611
    next
wenzelm@53406
   612
      assume xS: "x \<notin> S"
wenzelm@49522
   613
      have th00: "(\<Sum>v\<in>S. (if v = x then c else u v) *\<^sub>R v) = y"
wenzelm@49522
   614
        unfolding u[symmetric]
haftmann@57418
   615
        apply (rule setsum.cong)
wenzelm@53406
   616
        using xS
wenzelm@53406
   617
        apply auto
wenzelm@49522
   618
        done
wenzelm@53406
   619
      show ?thesis using fS xS th0
haftmann@57512
   620
        by (simp add: th00 add.commute cong del: if_weak_cong)
wenzelm@53406
   621
    qed
huffman@55910
   622
    then show "?h (c*\<^sub>R x + y)"
huffman@55910
   623
      by fast
huffman@44133
   624
  qed
huffman@44133
   625
  ultimately show ?thesis by blast
huffman@44133
   626
qed
huffman@44133
   627
huffman@44133
   628
lemma dependent_explicit:
wenzelm@49522
   629
  "dependent P \<longleftrightarrow> (\<exists>S u. finite S \<and> S \<subseteq> P \<and> (\<exists>v\<in>S. u v \<noteq> 0 \<and> setsum (\<lambda>v. u v *\<^sub>R v) S = 0))"
wenzelm@49522
   630
  (is "?lhs = ?rhs")
wenzelm@49522
   631
proof -
wenzelm@53406
   632
  {
wenzelm@53406
   633
    assume dP: "dependent P"
huffman@44133
   634
    then obtain a S u where aP: "a \<in> P" and fS: "finite S"
huffman@44133
   635
      and SP: "S \<subseteq> P - {a}" and ua: "setsum (\<lambda>v. u v *\<^sub>R v) S = a"
huffman@44133
   636
      unfolding dependent_def span_explicit by blast
huffman@44133
   637
    let ?S = "insert a S"
huffman@44133
   638
    let ?u = "\<lambda>y. if y = a then - 1 else u y"
huffman@44133
   639
    let ?v = a
wenzelm@53406
   640
    from aP SP have aS: "a \<notin> S"
wenzelm@53406
   641
      by blast
wenzelm@53406
   642
    from fS SP aP have th0: "finite ?S" "?S \<subseteq> P" "?v \<in> ?S" "?u ?v \<noteq> 0"
wenzelm@53406
   643
      by auto
huffman@44133
   644
    have s0: "setsum (\<lambda>v. ?u v *\<^sub>R v) ?S = 0"
huffman@44133
   645
      using fS aS
huffman@55910
   646
      apply simp
huffman@44133
   647
      apply (subst (2) ua[symmetric])
haftmann@57418
   648
      apply (rule setsum.cong)
wenzelm@49522
   649
      apply auto
wenzelm@49522
   650
      done
huffman@55910
   651
    with th0 have ?rhs by fast
wenzelm@49522
   652
  }
huffman@44133
   653
  moreover
wenzelm@53406
   654
  {
wenzelm@53406
   655
    fix S u v
wenzelm@49522
   656
    assume fS: "finite S"
wenzelm@53406
   657
      and SP: "S \<subseteq> P"
wenzelm@53406
   658
      and vS: "v \<in> S"
wenzelm@53406
   659
      and uv: "u v \<noteq> 0"
wenzelm@49522
   660
      and u: "setsum (\<lambda>v. u v *\<^sub>R v) S = 0"
huffman@44133
   661
    let ?a = v
huffman@44133
   662
    let ?S = "S - {v}"
huffman@44133
   663
    let ?u = "\<lambda>i. (- u i) / u v"
wenzelm@53406
   664
    have th0: "?a \<in> P" "finite ?S" "?S \<subseteq> P"
wenzelm@53406
   665
      using fS SP vS by auto
wenzelm@53406
   666
    have "setsum (\<lambda>v. ?u v *\<^sub>R v) ?S =
wenzelm@53406
   667
      setsum (\<lambda>v. (- (inverse (u ?a))) *\<^sub>R (u v *\<^sub>R v)) S - ?u v *\<^sub>R v"
hoelzl@56480
   668
      using fS vS uv by (simp add: setsum_diff1 field_simps)
wenzelm@53406
   669
    also have "\<dots> = ?a"
hoelzl@56479
   670
      unfolding scaleR_right.setsum [symmetric] u using uv by simp
wenzelm@53406
   671
    finally have "setsum (\<lambda>v. ?u v *\<^sub>R v) ?S = ?a" .
huffman@44133
   672
    with th0 have ?lhs
huffman@44133
   673
      unfolding dependent_def span_explicit
huffman@44133
   674
      apply -
huffman@44133
   675
      apply (rule bexI[where x= "?a"])
huffman@44133
   676
      apply (simp_all del: scaleR_minus_left)
huffman@44133
   677
      apply (rule exI[where x= "?S"])
wenzelm@49522
   678
      apply (auto simp del: scaleR_minus_left)
wenzelm@49522
   679
      done
wenzelm@49522
   680
  }
huffman@44133
   681
  ultimately show ?thesis by blast
huffman@44133
   682
qed
huffman@44133
   683
huffman@44133
   684
lemma span_finite:
huffman@44133
   685
  assumes fS: "finite S"
huffman@44133
   686
  shows "span S = {y. \<exists>u. setsum (\<lambda>v. u v *\<^sub>R v) S = y}"
huffman@44133
   687
  (is "_ = ?rhs")
wenzelm@49522
   688
proof -
wenzelm@53406
   689
  {
wenzelm@53406
   690
    fix y
wenzelm@49711
   691
    assume y: "y \<in> span S"
wenzelm@53406
   692
    from y obtain S' u where fS': "finite S'"
wenzelm@53406
   693
      and SS': "S' \<subseteq> S"
wenzelm@53406
   694
      and u: "setsum (\<lambda>v. u v *\<^sub>R v) S' = y"
wenzelm@53406
   695
      unfolding span_explicit by blast
huffman@44133
   696
    let ?u = "\<lambda>x. if x \<in> S' then u x else 0"
huffman@44133
   697
    have "setsum (\<lambda>v. ?u v *\<^sub>R v) S = setsum (\<lambda>v. u v *\<^sub>R v) S'"
haftmann@57418
   698
      using SS' fS by (auto intro!: setsum.mono_neutral_cong_right)
wenzelm@49522
   699
    then have "setsum (\<lambda>v. ?u v *\<^sub>R v) S = y" by (metis u)
wenzelm@53406
   700
    then have "y \<in> ?rhs" by auto
wenzelm@53406
   701
  }
huffman@44133
   702
  moreover
wenzelm@53406
   703
  {
wenzelm@53406
   704
    fix y u
wenzelm@49522
   705
    assume u: "setsum (\<lambda>v. u v *\<^sub>R v) S = y"
wenzelm@53406
   706
    then have "y \<in> span S" using fS unfolding span_explicit by auto
wenzelm@53406
   707
  }
huffman@44133
   708
  ultimately show ?thesis by blast
huffman@44133
   709
qed
huffman@44133
   710
wenzelm@60420
   711
text \<open>This is useful for building a basis step-by-step.\<close>
huffman@44133
   712
huffman@44133
   713
lemma independent_insert:
wenzelm@53406
   714
  "independent (insert a S) \<longleftrightarrow>
wenzelm@53406
   715
    (if a \<in> S then independent S else independent S \<and> a \<notin> span S)"
wenzelm@53406
   716
  (is "?lhs \<longleftrightarrow> ?rhs")
wenzelm@53406
   717
proof (cases "a \<in> S")
wenzelm@53406
   718
  case True
wenzelm@53406
   719
  then show ?thesis
wenzelm@53406
   720
    using insert_absorb[OF True] by simp
wenzelm@53406
   721
next
wenzelm@53406
   722
  case False
wenzelm@53406
   723
  show ?thesis
wenzelm@53406
   724
  proof
wenzelm@53406
   725
    assume i: ?lhs
wenzelm@53406
   726
    then show ?rhs
wenzelm@53406
   727
      using False
wenzelm@53406
   728
      apply simp
wenzelm@53406
   729
      apply (rule conjI)
wenzelm@53406
   730
      apply (rule independent_mono)
wenzelm@53406
   731
      apply assumption
wenzelm@53406
   732
      apply blast
wenzelm@53406
   733
      apply (simp add: dependent_def)
wenzelm@53406
   734
      done
wenzelm@53406
   735
  next
wenzelm@53406
   736
    assume i: ?rhs
wenzelm@53406
   737
    show ?lhs
wenzelm@53406
   738
      using i False
wenzelm@53406
   739
      apply (auto simp add: dependent_def)
lp15@60810
   740
      by (metis in_span_insert insert_Diff_if insert_Diff_single insert_absorb)
wenzelm@53406
   741
  qed
huffman@44133
   742
qed
huffman@44133
   743
wenzelm@60420
   744
text \<open>The degenerate case of the Exchange Lemma.\<close>
huffman@44133
   745
huffman@44133
   746
lemma spanning_subset_independent:
wenzelm@49711
   747
  assumes BA: "B \<subseteq> A"
wenzelm@49711
   748
    and iA: "independent A"
wenzelm@49522
   749
    and AsB: "A \<subseteq> span B"
huffman@44133
   750
  shows "A = B"
huffman@44133
   751
proof
wenzelm@49663
   752
  show "B \<subseteq> A" by (rule BA)
wenzelm@49663
   753
huffman@44133
   754
  from span_mono[OF BA] span_mono[OF AsB]
huffman@44133
   755
  have sAB: "span A = span B" unfolding span_span by blast
huffman@44133
   756
wenzelm@53406
   757
  {
wenzelm@53406
   758
    fix x
wenzelm@53406
   759
    assume x: "x \<in> A"
huffman@44133
   760
    from iA have th0: "x \<notin> span (A - {x})"
huffman@44133
   761
      unfolding dependent_def using x by blast
wenzelm@53406
   762
    from x have xsA: "x \<in> span A"
wenzelm@53406
   763
      by (blast intro: span_superset)
huffman@44133
   764
    have "A - {x} \<subseteq> A" by blast
wenzelm@53406
   765
    then have th1: "span (A - {x}) \<subseteq> span A"
wenzelm@53406
   766
      by (metis span_mono)
wenzelm@53406
   767
    {
wenzelm@53406
   768
      assume xB: "x \<notin> B"
wenzelm@53406
   769
      from xB BA have "B \<subseteq> A - {x}"
wenzelm@53406
   770
        by blast
wenzelm@53406
   771
      then have "span B \<subseteq> span (A - {x})"
wenzelm@53406
   772
        by (metis span_mono)
wenzelm@53406
   773
      with th1 th0 sAB have "x \<notin> span A"
wenzelm@53406
   774
        by blast
wenzelm@53406
   775
      with x have False
wenzelm@53406
   776
        by (metis span_superset)
wenzelm@53406
   777
    }
wenzelm@53406
   778
    then have "x \<in> B" by blast
wenzelm@53406
   779
  }
huffman@44133
   780
  then show "A \<subseteq> B" by blast
huffman@44133
   781
qed
huffman@44133
   782
wenzelm@60420
   783
text \<open>The general case of the Exchange Lemma, the key to what follows.\<close>
huffman@44133
   784
huffman@44133
   785
lemma exchange_lemma:
wenzelm@49711
   786
  assumes f:"finite t"
wenzelm@49711
   787
    and i: "independent s"
wenzelm@49711
   788
    and sp: "s \<subseteq> span t"
wenzelm@53406
   789
  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'"
wenzelm@49663
   790
  using f i sp
wenzelm@49522
   791
proof (induct "card (t - s)" arbitrary: s t rule: less_induct)
huffman@44133
   792
  case less
wenzelm@60420
   793
  note ft = \<open>finite t\<close> and s = \<open>independent s\<close> and sp = \<open>s \<subseteq> span t\<close>
wenzelm@53406
   794
  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'"
huffman@44133
   795
  let ?ths = "\<exists>t'. ?P t'"
wenzelm@53406
   796
  {
lp15@55775
   797
    assume "s \<subseteq> t"
lp15@55775
   798
    then have ?ths
lp15@55775
   799
      by (metis ft Un_commute sp sup_ge1)
wenzelm@53406
   800
  }
huffman@44133
   801
  moreover
wenzelm@53406
   802
  {
wenzelm@53406
   803
    assume st: "t \<subseteq> s"
wenzelm@53406
   804
    from spanning_subset_independent[OF st s sp] st ft span_mono[OF st]
wenzelm@53406
   805
    have ?ths
lp15@55775
   806
      by (metis Un_absorb sp)
wenzelm@53406
   807
  }
huffman@44133
   808
  moreover
wenzelm@53406
   809
  {
wenzelm@53406
   810
    assume st: "\<not> s \<subseteq> t" "\<not> t \<subseteq> s"
wenzelm@53406
   811
    from st(2) obtain b where b: "b \<in> t" "b \<notin> s"
wenzelm@53406
   812
      by blast
wenzelm@53406
   813
    from b have "t - {b} - s \<subset> t - s"
wenzelm@53406
   814
      by blast
wenzelm@53406
   815
    then have cardlt: "card (t - {b} - s) < card (t - s)"
wenzelm@53406
   816
      using ft by (auto intro: psubset_card_mono)
wenzelm@53406
   817
    from b ft have ct0: "card t \<noteq> 0"
wenzelm@53406
   818
      by auto
wenzelm@53406
   819
    have ?ths
wenzelm@53406
   820
    proof cases
wenzelm@53716
   821
      assume stb: "s \<subseteq> span (t - {b})"
wenzelm@53716
   822
      from ft have ftb: "finite (t - {b})"
wenzelm@53406
   823
        by auto
huffman@44133
   824
      from less(1)[OF cardlt ftb s stb]
wenzelm@53716
   825
      obtain u where u: "card u = card (t - {b})" "s \<subseteq> u" "u \<subseteq> s \<union> (t - {b})" "s \<subseteq> span u"
wenzelm@49522
   826
        and fu: "finite u" by blast
huffman@44133
   827
      let ?w = "insert b u"
wenzelm@53406
   828
      have th0: "s \<subseteq> insert b u"
wenzelm@53406
   829
        using u by blast
wenzelm@53406
   830
      from u(3) b have "u \<subseteq> s \<union> t"
wenzelm@53406
   831
        by blast
wenzelm@53406
   832
      then have th1: "insert b u \<subseteq> s \<union> t"
wenzelm@53406
   833
        using u b by blast
wenzelm@53406
   834
      have bu: "b \<notin> u"
wenzelm@53406
   835
        using b u by blast
wenzelm@53406
   836
      from u(1) ft b have "card u = (card t - 1)"
wenzelm@53406
   837
        by auto
wenzelm@49522
   838
      then have th2: "card (insert b u) = card t"
huffman@44133
   839
        using card_insert_disjoint[OF fu bu] ct0 by auto
huffman@44133
   840
      from u(4) have "s \<subseteq> span u" .
wenzelm@53406
   841
      also have "\<dots> \<subseteq> span (insert b u)"
wenzelm@53406
   842
        by (rule span_mono) blast
huffman@44133
   843
      finally have th3: "s \<subseteq> span (insert b u)" .
wenzelm@53406
   844
      from th0 th1 th2 th3 fu have th: "?P ?w"
wenzelm@53406
   845
        by blast
wenzelm@53406
   846
      from th show ?thesis by blast
wenzelm@53406
   847
    next
wenzelm@53716
   848
      assume stb: "\<not> s \<subseteq> span (t - {b})"
wenzelm@53406
   849
      from stb obtain a where a: "a \<in> s" "a \<notin> span (t - {b})"
wenzelm@53406
   850
        by blast
wenzelm@53406
   851
      have ab: "a \<noteq> b"
wenzelm@53406
   852
        using a b by blast
wenzelm@53406
   853
      have at: "a \<notin> t"
wenzelm@53406
   854
        using a ab span_superset[of a "t- {b}"] by auto
huffman@44133
   855
      have mlt: "card ((insert a (t - {b})) - s) < card (t - s)"
huffman@44133
   856
        using cardlt ft a b by auto
wenzelm@53406
   857
      have ft': "finite (insert a (t - {b}))"
wenzelm@53406
   858
        using ft by auto
wenzelm@53406
   859
      {
wenzelm@53406
   860
        fix x
wenzelm@53406
   861
        assume xs: "x \<in> s"
wenzelm@53406
   862
        have t: "t \<subseteq> insert b (insert a (t - {b}))"
wenzelm@53406
   863
          using b by auto
wenzelm@53406
   864
        from b(1) have "b \<in> span t"
wenzelm@53406
   865
          by (simp add: span_superset)
wenzelm@53406
   866
        have bs: "b \<in> span (insert a (t - {b}))"
wenzelm@53406
   867
          apply (rule in_span_delete)
wenzelm@53406
   868
          using a sp unfolding subset_eq
wenzelm@53406
   869
          apply auto
wenzelm@53406
   870
          done
wenzelm@53406
   871
        from xs sp have "x \<in> span t"
wenzelm@53406
   872
          by blast
wenzelm@53406
   873
        with span_mono[OF t] have x: "x \<in> span (insert b (insert a (t - {b})))" ..
wenzelm@53406
   874
        from span_trans[OF bs x] have "x \<in> span (insert a (t - {b}))" .
wenzelm@53406
   875
      }
wenzelm@53406
   876
      then have sp': "s \<subseteq> span (insert a (t - {b}))"
wenzelm@53406
   877
        by blast
wenzelm@53406
   878
      from less(1)[OF mlt ft' s sp'] obtain u where u:
wenzelm@53716
   879
        "card u = card (insert a (t - {b}))"
wenzelm@53716
   880
        "finite u" "s \<subseteq> u" "u \<subseteq> s \<union> insert a (t - {b})"
wenzelm@53406
   881
        "s \<subseteq> span u" by blast
wenzelm@53406
   882
      from u a b ft at ct0 have "?P u"
wenzelm@53406
   883
        by auto
wenzelm@53406
   884
      then show ?thesis by blast
wenzelm@53406
   885
    qed
huffman@44133
   886
  }
wenzelm@49522
   887
  ultimately show ?ths by blast
huffman@44133
   888
qed
huffman@44133
   889
wenzelm@60420
   890
text \<open>This implies corresponding size bounds.\<close>
huffman@44133
   891
huffman@44133
   892
lemma independent_span_bound:
wenzelm@53406
   893
  assumes f: "finite t"
wenzelm@53406
   894
    and i: "independent s"
wenzelm@53406
   895
    and sp: "s \<subseteq> span t"
huffman@44133
   896
  shows "finite s \<and> card s \<le> card t"
huffman@44133
   897
  by (metis exchange_lemma[OF f i sp] finite_subset card_mono)
huffman@44133
   898
huffman@44133
   899
lemma finite_Atleast_Atmost_nat[simp]: "finite {f x |x. x\<in> (UNIV::'a::finite set)}"
wenzelm@49522
   900
proof -
wenzelm@53406
   901
  have eq: "{f x |x. x\<in> UNIV} = f ` UNIV"
wenzelm@53406
   902
    by auto
huffman@44133
   903
  show ?thesis unfolding eq
huffman@44133
   904
    apply (rule finite_imageI)
huffman@44133
   905
    apply (rule finite)
huffman@44133
   906
    done
huffman@44133
   907
qed
huffman@44133
   908
wenzelm@53406
   909
hoelzl@63050
   910
subsection \<open>More interesting properties of the norm.\<close>
hoelzl@63050
   911
hoelzl@63050
   912
lemma cond_application_beta: "(if b then f else g) x = (if b then f x else g x)"
hoelzl@63050
   913
  by auto
hoelzl@63050
   914
hoelzl@63050
   915
notation inner (infix "\<bullet>" 70)
hoelzl@63050
   916
hoelzl@63050
   917
lemma square_bound_lemma:
hoelzl@63050
   918
  fixes x :: real
hoelzl@63050
   919
  shows "x < (1 + x) * (1 + x)"
hoelzl@63050
   920
proof -
hoelzl@63050
   921
  have "(x + 1/2)\<^sup>2 + 3/4 > 0"
hoelzl@63050
   922
    using zero_le_power2[of "x+1/2"] by arith
hoelzl@63050
   923
  then show ?thesis
hoelzl@63050
   924
    by (simp add: field_simps power2_eq_square)
hoelzl@63050
   925
qed
hoelzl@63050
   926
hoelzl@63050
   927
lemma square_continuous:
hoelzl@63050
   928
  fixes e :: real
hoelzl@63050
   929
  shows "e > 0 \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>y. \<bar>y - x\<bar> < d \<longrightarrow> \<bar>y * y - x * x\<bar> < e)"
hoelzl@63050
   930
  using isCont_power[OF continuous_ident, of x, unfolded isCont_def LIM_eq, rule_format, of e 2]
hoelzl@63050
   931
  by (force simp add: power2_eq_square)
hoelzl@63050
   932
hoelzl@63050
   933
hoelzl@63050
   934
lemma norm_eq_0_dot: "norm x = 0 \<longleftrightarrow> x \<bullet> x = (0::real)"
hoelzl@63050
   935
  by simp (* TODO: delete *)
hoelzl@63050
   936
hoelzl@63050
   937
lemma norm_triangle_sub:
hoelzl@63050
   938
  fixes x y :: "'a::real_normed_vector"
hoelzl@63050
   939
  shows "norm x \<le> norm y + norm (x - y)"
hoelzl@63050
   940
  using norm_triangle_ineq[of "y" "x - y"] by (simp add: field_simps)
hoelzl@63050
   941
hoelzl@63050
   942
lemma norm_le: "norm x \<le> norm y \<longleftrightarrow> x \<bullet> x \<le> y \<bullet> y"
hoelzl@63050
   943
  by (simp add: norm_eq_sqrt_inner)
hoelzl@63050
   944
hoelzl@63050
   945
lemma norm_lt: "norm x < norm y \<longleftrightarrow> x \<bullet> x < y \<bullet> y"
hoelzl@63050
   946
  by (simp add: norm_eq_sqrt_inner)
hoelzl@63050
   947
hoelzl@63050
   948
lemma norm_eq: "norm x = norm y \<longleftrightarrow> x \<bullet> x = y \<bullet> y"
hoelzl@63050
   949
  apply (subst order_eq_iff)
hoelzl@63050
   950
  apply (auto simp: norm_le)
hoelzl@63050
   951
  done
hoelzl@63050
   952
hoelzl@63050
   953
lemma norm_eq_1: "norm x = 1 \<longleftrightarrow> x \<bullet> x = 1"
hoelzl@63050
   954
  by (simp add: norm_eq_sqrt_inner)
hoelzl@63050
   955
hoelzl@63050
   956
text\<open>Squaring equations and inequalities involving norms.\<close>
hoelzl@63050
   957
hoelzl@63050
   958
lemma dot_square_norm: "x \<bullet> x = (norm x)\<^sup>2"
hoelzl@63050
   959
  by (simp only: power2_norm_eq_inner) (* TODO: move? *)
hoelzl@63050
   960
hoelzl@63050
   961
lemma norm_eq_square: "norm x = a \<longleftrightarrow> 0 \<le> a \<and> x \<bullet> x = a\<^sup>2"
hoelzl@63050
   962
  by (auto simp add: norm_eq_sqrt_inner)
hoelzl@63050
   963
hoelzl@63050
   964
lemma norm_le_square: "norm x \<le> a \<longleftrightarrow> 0 \<le> a \<and> x \<bullet> x \<le> a\<^sup>2"
hoelzl@63050
   965
  apply (simp add: dot_square_norm abs_le_square_iff[symmetric])
hoelzl@63050
   966
  using norm_ge_zero[of x]
hoelzl@63050
   967
  apply arith
hoelzl@63050
   968
  done
hoelzl@63050
   969
hoelzl@63050
   970
lemma norm_ge_square: "norm x \<ge> a \<longleftrightarrow> a \<le> 0 \<or> x \<bullet> x \<ge> a\<^sup>2"
hoelzl@63050
   971
  apply (simp add: dot_square_norm abs_le_square_iff[symmetric])
hoelzl@63050
   972
  using norm_ge_zero[of x]
hoelzl@63050
   973
  apply arith
hoelzl@63050
   974
  done
hoelzl@63050
   975
hoelzl@63050
   976
lemma norm_lt_square: "norm x < a \<longleftrightarrow> 0 < a \<and> x \<bullet> x < a\<^sup>2"
hoelzl@63050
   977
  by (metis not_le norm_ge_square)
hoelzl@63050
   978
hoelzl@63050
   979
lemma norm_gt_square: "norm x > a \<longleftrightarrow> a < 0 \<or> x \<bullet> x > a\<^sup>2"
hoelzl@63050
   980
  by (metis norm_le_square not_less)
hoelzl@63050
   981
hoelzl@63050
   982
text\<open>Dot product in terms of the norm rather than conversely.\<close>
hoelzl@63050
   983
hoelzl@63050
   984
lemmas inner_simps = inner_add_left inner_add_right inner_diff_right inner_diff_left
hoelzl@63050
   985
  inner_scaleR_left inner_scaleR_right
hoelzl@63050
   986
hoelzl@63050
   987
lemma dot_norm: "x \<bullet> y = ((norm (x + y))\<^sup>2 - (norm x)\<^sup>2 - (norm y)\<^sup>2) / 2"
hoelzl@63050
   988
  unfolding power2_norm_eq_inner inner_simps inner_commute by auto
hoelzl@63050
   989
hoelzl@63050
   990
lemma dot_norm_neg: "x \<bullet> y = (((norm x)\<^sup>2 + (norm y)\<^sup>2) - (norm (x - y))\<^sup>2) / 2"
hoelzl@63050
   991
  unfolding power2_norm_eq_inner inner_simps inner_commute
hoelzl@63050
   992
  by (auto simp add: algebra_simps)
hoelzl@63050
   993
hoelzl@63050
   994
text\<open>Equality of vectors in terms of @{term "op \<bullet>"} products.\<close>
hoelzl@63050
   995
hoelzl@63050
   996
lemma linear_componentwise:
hoelzl@63050
   997
  fixes f:: "'a::euclidean_space \<Rightarrow> 'b::real_inner"
hoelzl@63050
   998
  assumes lf: "linear f"
hoelzl@63050
   999
  shows "(f x) \<bullet> j = (\<Sum>i\<in>Basis. (x\<bullet>i) * (f i\<bullet>j))" (is "?lhs = ?rhs")
hoelzl@63050
  1000
proof -
hoelzl@63050
  1001
  have "?rhs = (\<Sum>i\<in>Basis. (x\<bullet>i) *\<^sub>R (f i))\<bullet>j"
hoelzl@63050
  1002
    by (simp add: inner_setsum_left)
hoelzl@63050
  1003
  then show ?thesis
hoelzl@63050
  1004
    unfolding linear_setsum_mul[OF lf, symmetric]
hoelzl@63050
  1005
    unfolding euclidean_representation ..
hoelzl@63050
  1006
qed
hoelzl@63050
  1007
hoelzl@63050
  1008
lemma vector_eq: "x = y \<longleftrightarrow> x \<bullet> x = x \<bullet> y \<and> y \<bullet> y = x \<bullet> x"
hoelzl@63050
  1009
  (is "?lhs \<longleftrightarrow> ?rhs")
hoelzl@63050
  1010
proof
hoelzl@63050
  1011
  assume ?lhs
hoelzl@63050
  1012
  then show ?rhs by simp
hoelzl@63050
  1013
next
hoelzl@63050
  1014
  assume ?rhs
hoelzl@63050
  1015
  then have "x \<bullet> x - x \<bullet> y = 0 \<and> x \<bullet> y - y \<bullet> y = 0"
hoelzl@63050
  1016
    by simp
hoelzl@63050
  1017
  then have "x \<bullet> (x - y) = 0 \<and> y \<bullet> (x - y) = 0"
hoelzl@63050
  1018
    by (simp add: inner_diff inner_commute)
hoelzl@63050
  1019
  then have "(x - y) \<bullet> (x - y) = 0"
hoelzl@63050
  1020
    by (simp add: field_simps inner_diff inner_commute)
hoelzl@63050
  1021
  then show "x = y" by simp
hoelzl@63050
  1022
qed
hoelzl@63050
  1023
hoelzl@63050
  1024
lemma norm_triangle_half_r:
hoelzl@63050
  1025
  "norm (y - x1) < e / 2 \<Longrightarrow> norm (y - x2) < e / 2 \<Longrightarrow> norm (x1 - x2) < e"
hoelzl@63050
  1026
  using dist_triangle_half_r unfolding dist_norm[symmetric] by auto
hoelzl@63050
  1027
hoelzl@63050
  1028
lemma norm_triangle_half_l:
hoelzl@63050
  1029
  assumes "norm (x - y) < e / 2"
hoelzl@63050
  1030
    and "norm (x' - y) < e / 2"
hoelzl@63050
  1031
  shows "norm (x - x') < e"
hoelzl@63050
  1032
  using dist_triangle_half_l[OF assms[unfolded dist_norm[symmetric]]]
hoelzl@63050
  1033
  unfolding dist_norm[symmetric] .
hoelzl@63050
  1034
hoelzl@63050
  1035
lemma norm_triangle_le: "norm x + norm y \<le> e \<Longrightarrow> norm (x + y) \<le> e"
hoelzl@63050
  1036
  by (rule norm_triangle_ineq [THEN order_trans])
hoelzl@63050
  1037
hoelzl@63050
  1038
lemma norm_triangle_lt: "norm x + norm y < e \<Longrightarrow> norm (x + y) < e"
hoelzl@63050
  1039
  by (rule norm_triangle_ineq [THEN le_less_trans])
hoelzl@63050
  1040
hoelzl@63050
  1041
lemma setsum_clauses:
hoelzl@63050
  1042
  shows "setsum f {} = 0"
hoelzl@63050
  1043
    and "finite S \<Longrightarrow> setsum f (insert x S) = (if x \<in> S then setsum f S else f x + setsum f S)"
hoelzl@63050
  1044
  by (auto simp add: insert_absorb)
hoelzl@63050
  1045
hoelzl@63050
  1046
lemma setsum_norm_le:
hoelzl@63050
  1047
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
hoelzl@63050
  1048
  assumes fg: "\<forall>x \<in> S. norm (f x) \<le> g x"
hoelzl@63050
  1049
  shows "norm (setsum f S) \<le> setsum g S"
hoelzl@63050
  1050
  by (rule order_trans [OF norm_setsum setsum_mono]) (simp add: fg)
hoelzl@63050
  1051
hoelzl@63050
  1052
lemma setsum_norm_bound:
hoelzl@63050
  1053
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
hoelzl@63050
  1054
  assumes K: "\<forall>x \<in> S. norm (f x) \<le> K"
hoelzl@63050
  1055
  shows "norm (setsum f S) \<le> of_nat (card S) * K"
hoelzl@63050
  1056
  using setsum_norm_le[OF K] setsum_constant[symmetric]
hoelzl@63050
  1057
  by simp
hoelzl@63050
  1058
hoelzl@63050
  1059
lemma setsum_group:
hoelzl@63050
  1060
  assumes fS: "finite S" and fT: "finite T" and fST: "f ` S \<subseteq> T"
hoelzl@63050
  1061
  shows "setsum (\<lambda>y. setsum g {x. x \<in> S \<and> f x = y}) T = setsum g S"
hoelzl@63050
  1062
  apply (subst setsum_image_gen[OF fS, of g f])
hoelzl@63050
  1063
  apply (rule setsum.mono_neutral_right[OF fT fST])
hoelzl@63050
  1064
  apply (auto intro: setsum.neutral)
hoelzl@63050
  1065
  done
hoelzl@63050
  1066
hoelzl@63050
  1067
lemma vector_eq_ldot: "(\<forall>x. x \<bullet> y = x \<bullet> z) \<longleftrightarrow> y = z"
hoelzl@63050
  1068
proof
hoelzl@63050
  1069
  assume "\<forall>x. x \<bullet> y = x \<bullet> z"
hoelzl@63050
  1070
  then have "\<forall>x. x \<bullet> (y - z) = 0"
hoelzl@63050
  1071
    by (simp add: inner_diff)
hoelzl@63050
  1072
  then have "(y - z) \<bullet> (y - z) = 0" ..
hoelzl@63050
  1073
  then show "y = z" by simp
hoelzl@63050
  1074
qed simp
hoelzl@63050
  1075
hoelzl@63050
  1076
lemma vector_eq_rdot: "(\<forall>z. x \<bullet> z = y \<bullet> z) \<longleftrightarrow> x = y"
hoelzl@63050
  1077
proof
hoelzl@63050
  1078
  assume "\<forall>z. x \<bullet> z = y \<bullet> z"
hoelzl@63050
  1079
  then have "\<forall>z. (x - y) \<bullet> z = 0"
hoelzl@63050
  1080
    by (simp add: inner_diff)
hoelzl@63050
  1081
  then have "(x - y) \<bullet> (x - y) = 0" ..
hoelzl@63050
  1082
  then show "x = y" by simp
hoelzl@63050
  1083
qed simp
hoelzl@63050
  1084
hoelzl@63050
  1085
hoelzl@63050
  1086
subsection \<open>Orthogonality.\<close>
hoelzl@63050
  1087
hoelzl@63050
  1088
context real_inner
hoelzl@63050
  1089
begin
hoelzl@63050
  1090
hoelzl@63050
  1091
definition "orthogonal x y \<longleftrightarrow> x \<bullet> y = 0"
hoelzl@63050
  1092
hoelzl@63050
  1093
lemma orthogonal_clauses:
hoelzl@63050
  1094
  "orthogonal a 0"
hoelzl@63050
  1095
  "orthogonal a x \<Longrightarrow> orthogonal a (c *\<^sub>R x)"
hoelzl@63050
  1096
  "orthogonal a x \<Longrightarrow> orthogonal a (- x)"
hoelzl@63050
  1097
  "orthogonal a x \<Longrightarrow> orthogonal a y \<Longrightarrow> orthogonal a (x + y)"
hoelzl@63050
  1098
  "orthogonal a x \<Longrightarrow> orthogonal a y \<Longrightarrow> orthogonal a (x - y)"
hoelzl@63050
  1099
  "orthogonal 0 a"
hoelzl@63050
  1100
  "orthogonal x a \<Longrightarrow> orthogonal (c *\<^sub>R x) a"
hoelzl@63050
  1101
  "orthogonal x a \<Longrightarrow> orthogonal (- x) a"
hoelzl@63050
  1102
  "orthogonal x a \<Longrightarrow> orthogonal y a \<Longrightarrow> orthogonal (x + y) a"
hoelzl@63050
  1103
  "orthogonal x a \<Longrightarrow> orthogonal y a \<Longrightarrow> orthogonal (x - y) a"
hoelzl@63050
  1104
  unfolding orthogonal_def inner_add inner_diff by auto
hoelzl@63050
  1105
hoelzl@63050
  1106
end
hoelzl@63050
  1107
hoelzl@63050
  1108
lemma orthogonal_commute: "orthogonal x y \<longleftrightarrow> orthogonal y x"
hoelzl@63050
  1109
  by (simp add: orthogonal_def inner_commute)
hoelzl@63050
  1110
hoelzl@63050
  1111
hoelzl@63050
  1112
subsection \<open>Bilinear functions.\<close>
hoelzl@63050
  1113
hoelzl@63050
  1114
definition "bilinear f \<longleftrightarrow> (\<forall>x. linear (\<lambda>y. f x y)) \<and> (\<forall>y. linear (\<lambda>x. f x y))"
hoelzl@63050
  1115
hoelzl@63050
  1116
lemma bilinear_ladd: "bilinear h \<Longrightarrow> h (x + y) z = h x z + h y z"
hoelzl@63050
  1117
  by (simp add: bilinear_def linear_iff)
hoelzl@63050
  1118
hoelzl@63050
  1119
lemma bilinear_radd: "bilinear h \<Longrightarrow> h x (y + z) = h x y + h x z"
hoelzl@63050
  1120
  by (simp add: bilinear_def linear_iff)
hoelzl@63050
  1121
hoelzl@63050
  1122
lemma bilinear_lmul: "bilinear h \<Longrightarrow> h (c *\<^sub>R x) y = c *\<^sub>R h x y"
hoelzl@63050
  1123
  by (simp add: bilinear_def linear_iff)
hoelzl@63050
  1124
hoelzl@63050
  1125
lemma bilinear_rmul: "bilinear h \<Longrightarrow> h x (c *\<^sub>R y) = c *\<^sub>R h x y"
hoelzl@63050
  1126
  by (simp add: bilinear_def linear_iff)
hoelzl@63050
  1127
hoelzl@63050
  1128
lemma bilinear_lneg: "bilinear h \<Longrightarrow> h (- x) y = - h x y"
hoelzl@63050
  1129
  by (drule bilinear_lmul [of _ "- 1"]) simp
hoelzl@63050
  1130
hoelzl@63050
  1131
lemma bilinear_rneg: "bilinear h \<Longrightarrow> h x (- y) = - h x y"
hoelzl@63050
  1132
  by (drule bilinear_rmul [of _ _ "- 1"]) simp
hoelzl@63050
  1133
hoelzl@63050
  1134
lemma (in ab_group_add) eq_add_iff: "x = x + y \<longleftrightarrow> y = 0"
hoelzl@63050
  1135
  using add_left_imp_eq[of x y 0] by auto
hoelzl@63050
  1136
hoelzl@63050
  1137
lemma bilinear_lzero:
hoelzl@63050
  1138
  assumes "bilinear h"
hoelzl@63050
  1139
  shows "h 0 x = 0"
hoelzl@63050
  1140
  using bilinear_ladd [OF assms, of 0 0 x] by (simp add: eq_add_iff field_simps)
hoelzl@63050
  1141
hoelzl@63050
  1142
lemma bilinear_rzero:
hoelzl@63050
  1143
  assumes "bilinear h"
hoelzl@63050
  1144
  shows "h x 0 = 0"
hoelzl@63050
  1145
  using bilinear_radd [OF assms, of x 0 0 ] by (simp add: eq_add_iff field_simps)
hoelzl@63050
  1146
hoelzl@63050
  1147
lemma bilinear_lsub: "bilinear h \<Longrightarrow> h (x - y) z = h x z - h y z"
hoelzl@63050
  1148
  using bilinear_ladd [of h x "- y"] by (simp add: bilinear_lneg)
hoelzl@63050
  1149
hoelzl@63050
  1150
lemma bilinear_rsub: "bilinear h \<Longrightarrow> h z (x - y) = h z x - h z y"
hoelzl@63050
  1151
  using bilinear_radd [of h _ x "- y"] by (simp add: bilinear_rneg)
hoelzl@63050
  1152
hoelzl@63050
  1153
lemma bilinear_setsum:
hoelzl@63050
  1154
  assumes bh: "bilinear h"
hoelzl@63050
  1155
    and fS: "finite S"
hoelzl@63050
  1156
    and fT: "finite T"
hoelzl@63050
  1157
  shows "h (setsum f S) (setsum g T) = setsum (\<lambda>(i,j). h (f i) (g j)) (S \<times> T) "
hoelzl@63050
  1158
proof -
hoelzl@63050
  1159
  have "h (setsum f S) (setsum g T) = setsum (\<lambda>x. h (f x) (setsum g T)) S"
hoelzl@63050
  1160
    apply (rule linear_setsum[unfolded o_def])
hoelzl@63050
  1161
    using bh fS
hoelzl@63050
  1162
    apply (auto simp add: bilinear_def)
hoelzl@63050
  1163
    done
hoelzl@63050
  1164
  also have "\<dots> = setsum (\<lambda>x. setsum (\<lambda>y. h (f x) (g y)) T) S"
hoelzl@63050
  1165
    apply (rule setsum.cong, simp)
hoelzl@63050
  1166
    apply (rule linear_setsum[unfolded o_def])
hoelzl@63050
  1167
    using bh fT
hoelzl@63050
  1168
    apply (auto simp add: bilinear_def)
hoelzl@63050
  1169
    done
hoelzl@63050
  1170
  finally show ?thesis
hoelzl@63050
  1171
    unfolding setsum.cartesian_product .
hoelzl@63050
  1172
qed
hoelzl@63050
  1173
hoelzl@63050
  1174
hoelzl@63050
  1175
subsection \<open>Adjoints.\<close>
hoelzl@63050
  1176
hoelzl@63050
  1177
definition "adjoint f = (SOME f'. \<forall>x y. f x \<bullet> y = x \<bullet> f' y)"
hoelzl@63050
  1178
hoelzl@63050
  1179
lemma adjoint_unique:
hoelzl@63050
  1180
  assumes "\<forall>x y. inner (f x) y = inner x (g y)"
hoelzl@63050
  1181
  shows "adjoint f = g"
hoelzl@63050
  1182
  unfolding adjoint_def
hoelzl@63050
  1183
proof (rule some_equality)
hoelzl@63050
  1184
  show "\<forall>x y. inner (f x) y = inner x (g y)"
hoelzl@63050
  1185
    by (rule assms)
hoelzl@63050
  1186
next
hoelzl@63050
  1187
  fix h
hoelzl@63050
  1188
  assume "\<forall>x y. inner (f x) y = inner x (h y)"
hoelzl@63050
  1189
  then have "\<forall>x y. inner x (g y) = inner x (h y)"
hoelzl@63050
  1190
    using assms by simp
hoelzl@63050
  1191
  then have "\<forall>x y. inner x (g y - h y) = 0"
hoelzl@63050
  1192
    by (simp add: inner_diff_right)
hoelzl@63050
  1193
  then have "\<forall>y. inner (g y - h y) (g y - h y) = 0"
hoelzl@63050
  1194
    by simp
hoelzl@63050
  1195
  then have "\<forall>y. h y = g y"
hoelzl@63050
  1196
    by simp
hoelzl@63050
  1197
  then show "h = g" by (simp add: ext)
hoelzl@63050
  1198
qed
hoelzl@63050
  1199
hoelzl@63050
  1200
text \<open>TODO: The following lemmas about adjoints should hold for any
hoelzl@63050
  1201
Hilbert space (i.e. complete inner product space).
hoelzl@63050
  1202
(see @{url "http://en.wikipedia.org/wiki/Hermitian_adjoint"})
hoelzl@63050
  1203
\<close>
hoelzl@63050
  1204
hoelzl@63050
  1205
lemma adjoint_works:
hoelzl@63050
  1206
  fixes f :: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space"
hoelzl@63050
  1207
  assumes lf: "linear f"
hoelzl@63050
  1208
  shows "x \<bullet> adjoint f y = f x \<bullet> y"
hoelzl@63050
  1209
proof -
hoelzl@63050
  1210
  have "\<forall>y. \<exists>w. \<forall>x. f x \<bullet> y = x \<bullet> w"
hoelzl@63050
  1211
  proof (intro allI exI)
hoelzl@63050
  1212
    fix y :: "'m" and x
hoelzl@63050
  1213
    let ?w = "(\<Sum>i\<in>Basis. (f i \<bullet> y) *\<^sub>R i) :: 'n"
hoelzl@63050
  1214
    have "f x \<bullet> y = f (\<Sum>i\<in>Basis. (x \<bullet> i) *\<^sub>R i) \<bullet> y"
hoelzl@63050
  1215
      by (simp add: euclidean_representation)
hoelzl@63050
  1216
    also have "\<dots> = (\<Sum>i\<in>Basis. (x \<bullet> i) *\<^sub>R f i) \<bullet> y"
hoelzl@63050
  1217
      unfolding linear_setsum[OF lf]
hoelzl@63050
  1218
      by (simp add: linear_cmul[OF lf])
hoelzl@63050
  1219
    finally show "f x \<bullet> y = x \<bullet> ?w"
hoelzl@63050
  1220
      by (simp add: inner_setsum_left inner_setsum_right mult.commute)
hoelzl@63050
  1221
  qed
hoelzl@63050
  1222
  then show ?thesis
hoelzl@63050
  1223
    unfolding adjoint_def choice_iff
hoelzl@63050
  1224
    by (intro someI2_ex[where Q="\<lambda>f'. x \<bullet> f' y = f x \<bullet> y"]) auto
hoelzl@63050
  1225
qed
hoelzl@63050
  1226
hoelzl@63050
  1227
lemma adjoint_clauses:
hoelzl@63050
  1228
  fixes f :: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space"
hoelzl@63050
  1229
  assumes lf: "linear f"
hoelzl@63050
  1230
  shows "x \<bullet> adjoint f y = f x \<bullet> y"
hoelzl@63050
  1231
    and "adjoint f y \<bullet> x = y \<bullet> f x"
hoelzl@63050
  1232
  by (simp_all add: adjoint_works[OF lf] inner_commute)
hoelzl@63050
  1233
hoelzl@63050
  1234
lemma adjoint_linear:
hoelzl@63050
  1235
  fixes f :: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space"
hoelzl@63050
  1236
  assumes lf: "linear f"
hoelzl@63050
  1237
  shows "linear (adjoint f)"
hoelzl@63050
  1238
  by (simp add: lf linear_iff euclidean_eq_iff[where 'a='n] euclidean_eq_iff[where 'a='m]
hoelzl@63050
  1239
    adjoint_clauses[OF lf] inner_distrib)
hoelzl@63050
  1240
hoelzl@63050
  1241
lemma adjoint_adjoint:
hoelzl@63050
  1242
  fixes f :: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space"
hoelzl@63050
  1243
  assumes lf: "linear f"
hoelzl@63050
  1244
  shows "adjoint (adjoint f) = f"
hoelzl@63050
  1245
  by (rule adjoint_unique, simp add: adjoint_clauses [OF lf])
hoelzl@63050
  1246
hoelzl@63050
  1247
hoelzl@63050
  1248
subsection \<open>Interlude: Some properties of real sets\<close>
hoelzl@63050
  1249
hoelzl@63050
  1250
lemma seq_mono_lemma:
hoelzl@63050
  1251
  assumes "\<forall>(n::nat) \<ge> m. (d n :: real) < e n"
hoelzl@63050
  1252
    and "\<forall>n \<ge> m. e n \<le> e m"
hoelzl@63050
  1253
  shows "\<forall>n \<ge> m. d n < e m"
hoelzl@63050
  1254
  using assms
hoelzl@63050
  1255
  apply auto
hoelzl@63050
  1256
  apply (erule_tac x="n" in allE)
hoelzl@63050
  1257
  apply (erule_tac x="n" in allE)
hoelzl@63050
  1258
  apply auto
hoelzl@63050
  1259
  done
hoelzl@63050
  1260
hoelzl@63050
  1261
lemma infinite_enumerate:
hoelzl@63050
  1262
  assumes fS: "infinite S"
hoelzl@63050
  1263
  shows "\<exists>r. subseq r \<and> (\<forall>n. r n \<in> S)"
hoelzl@63050
  1264
  unfolding subseq_def
hoelzl@63050
  1265
  using enumerate_in_set[OF fS] enumerate_mono[of _ _ S] fS by auto
hoelzl@63050
  1266
hoelzl@63050
  1267
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)"
hoelzl@63050
  1268
  apply auto
hoelzl@63050
  1269
  apply (rule_tac x="d/2" in exI)
hoelzl@63050
  1270
  apply auto
hoelzl@63050
  1271
  done
hoelzl@63050
  1272
hoelzl@63050
  1273
lemma approachable_lt_le2:  \<comment>\<open>like the above, but pushes aside an extra formula\<close>
hoelzl@63050
  1274
    "(\<exists>(d::real) > 0. \<forall>x. Q x \<longrightarrow> f x < d \<longrightarrow> P x) \<longleftrightarrow> (\<exists>d>0. \<forall>x. f x \<le> d \<longrightarrow> Q x \<longrightarrow> P x)"
hoelzl@63050
  1275
  apply auto
hoelzl@63050
  1276
  apply (rule_tac x="d/2" in exI, auto)
hoelzl@63050
  1277
  done
hoelzl@63050
  1278
hoelzl@63050
  1279
lemma triangle_lemma:
hoelzl@63050
  1280
  fixes x y z :: real
hoelzl@63050
  1281
  assumes x: "0 \<le> x"
hoelzl@63050
  1282
    and y: "0 \<le> y"
hoelzl@63050
  1283
    and z: "0 \<le> z"
hoelzl@63050
  1284
    and xy: "x\<^sup>2 \<le> y\<^sup>2 + z\<^sup>2"
hoelzl@63050
  1285
  shows "x \<le> y + z"
hoelzl@63050
  1286
proof -
hoelzl@63050
  1287
  have "y\<^sup>2 + z\<^sup>2 \<le> y\<^sup>2 + 2 * y * z + z\<^sup>2"
hoelzl@63050
  1288
    using z y by simp
hoelzl@63050
  1289
  with xy have th: "x\<^sup>2 \<le> (y + z)\<^sup>2"
hoelzl@63050
  1290
    by (simp add: power2_eq_square field_simps)
hoelzl@63050
  1291
  from y z have yz: "y + z \<ge> 0"
hoelzl@63050
  1292
    by arith
hoelzl@63050
  1293
  from power2_le_imp_le[OF th yz] show ?thesis .
hoelzl@63050
  1294
qed
hoelzl@63050
  1295
hoelzl@63050
  1296
hoelzl@63050
  1297
hoelzl@63050
  1298
subsection \<open>Archimedean properties and useful consequences\<close>
hoelzl@63050
  1299
hoelzl@63050
  1300
text\<open>Bernoulli's inequality\<close>
hoelzl@63050
  1301
proposition Bernoulli_inequality:
hoelzl@63050
  1302
  fixes x :: real
hoelzl@63050
  1303
  assumes "-1 \<le> x"
hoelzl@63050
  1304
    shows "1 + n * x \<le> (1 + x) ^ n"
hoelzl@63050
  1305
proof (induct n)
hoelzl@63050
  1306
  case 0
hoelzl@63050
  1307
  then show ?case by simp
hoelzl@63050
  1308
next
hoelzl@63050
  1309
  case (Suc n)
hoelzl@63050
  1310
  have "1 + Suc n * x \<le> 1 + (Suc n)*x + n * x^2"
hoelzl@63050
  1311
    by (simp add: algebra_simps)
hoelzl@63050
  1312
  also have "... = (1 + x) * (1 + n*x)"
hoelzl@63050
  1313
    by (auto simp: power2_eq_square algebra_simps  of_nat_Suc)
hoelzl@63050
  1314
  also have "... \<le> (1 + x) ^ Suc n"
hoelzl@63050
  1315
    using Suc.hyps assms mult_left_mono by fastforce
hoelzl@63050
  1316
  finally show ?case .
hoelzl@63050
  1317
qed
hoelzl@63050
  1318
hoelzl@63050
  1319
corollary Bernoulli_inequality_even:
hoelzl@63050
  1320
  fixes x :: real
hoelzl@63050
  1321
  assumes "even n"
hoelzl@63050
  1322
    shows "1 + n * x \<le> (1 + x) ^ n"
hoelzl@63050
  1323
proof (cases "-1 \<le> x \<or> n=0")
hoelzl@63050
  1324
  case True
hoelzl@63050
  1325
  then show ?thesis
hoelzl@63050
  1326
    by (auto simp: Bernoulli_inequality)
hoelzl@63050
  1327
next
hoelzl@63050
  1328
  case False
hoelzl@63050
  1329
  then have "real n \<ge> 1"
hoelzl@63050
  1330
    by simp
hoelzl@63050
  1331
  with False have "n * x \<le> -1"
hoelzl@63050
  1332
    by (metis linear minus_zero mult.commute mult.left_neutral mult_left_mono_neg neg_le_iff_le order_trans zero_le_one)
hoelzl@63050
  1333
  then have "1 + n * x \<le> 0"
hoelzl@63050
  1334
    by auto
hoelzl@63050
  1335
  also have "... \<le> (1 + x) ^ n"
hoelzl@63050
  1336
    using assms
hoelzl@63050
  1337
    using zero_le_even_power by blast
hoelzl@63050
  1338
  finally show ?thesis .
hoelzl@63050
  1339
qed
hoelzl@63050
  1340
hoelzl@63050
  1341
corollary real_arch_pow:
hoelzl@63050
  1342
  fixes x :: real
hoelzl@63050
  1343
  assumes x: "1 < x"
hoelzl@63050
  1344
  shows "\<exists>n. y < x^n"
hoelzl@63050
  1345
proof -
hoelzl@63050
  1346
  from x have x0: "x - 1 > 0"
hoelzl@63050
  1347
    by arith
hoelzl@63050
  1348
  from reals_Archimedean3[OF x0, rule_format, of y]
hoelzl@63050
  1349
  obtain n :: nat where n: "y < real n * (x - 1)" by metis
hoelzl@63050
  1350
  from x0 have x00: "x- 1 \<ge> -1" by arith
hoelzl@63050
  1351
  from Bernoulli_inequality[OF x00, of n] n
hoelzl@63050
  1352
  have "y < x^n" by auto
hoelzl@63050
  1353
  then show ?thesis by metis
hoelzl@63050
  1354
qed
hoelzl@63050
  1355
hoelzl@63050
  1356
corollary real_arch_pow_inv:
hoelzl@63050
  1357
  fixes x y :: real
hoelzl@63050
  1358
  assumes y: "y > 0"
hoelzl@63050
  1359
    and x1: "x < 1"
hoelzl@63050
  1360
  shows "\<exists>n. x^n < y"
hoelzl@63050
  1361
proof (cases "x > 0")
hoelzl@63050
  1362
  case True
hoelzl@63050
  1363
  with x1 have ix: "1 < 1/x" by (simp add: field_simps)
hoelzl@63050
  1364
  from real_arch_pow[OF ix, of "1/y"]
hoelzl@63050
  1365
  obtain n where n: "1/y < (1/x)^n" by blast
hoelzl@63050
  1366
  then show ?thesis using y \<open>x > 0\<close>
hoelzl@63050
  1367
    by (auto simp add: field_simps)
hoelzl@63050
  1368
next
hoelzl@63050
  1369
  case False
hoelzl@63050
  1370
  with y x1 show ?thesis
hoelzl@63050
  1371
    apply auto
hoelzl@63050
  1372
    apply (rule exI[where x=1])
hoelzl@63050
  1373
    apply auto
hoelzl@63050
  1374
    done
hoelzl@63050
  1375
qed
hoelzl@63050
  1376
hoelzl@63050
  1377
lemma forall_pos_mono:
hoelzl@63050
  1378
  "(\<And>d e::real. d < e \<Longrightarrow> P d \<Longrightarrow> P e) \<Longrightarrow>
hoelzl@63050
  1379
    (\<And>n::nat. n \<noteq> 0 \<Longrightarrow> P (inverse (real n))) \<Longrightarrow> (\<And>e. 0 < e \<Longrightarrow> P e)"
hoelzl@63050
  1380
  by (metis real_arch_inverse)
hoelzl@63050
  1381
hoelzl@63050
  1382
lemma forall_pos_mono_1:
hoelzl@63050
  1383
  "(\<And>d e::real. d < e \<Longrightarrow> P d \<Longrightarrow> P e) \<Longrightarrow>
hoelzl@63050
  1384
    (\<And>n. P (inverse (real (Suc n)))) \<Longrightarrow> 0 < e \<Longrightarrow> P e"
hoelzl@63050
  1385
  apply (rule forall_pos_mono)
hoelzl@63050
  1386
  apply auto
hoelzl@63050
  1387
  apply (metis Suc_pred of_nat_Suc)
hoelzl@63050
  1388
  done
hoelzl@63050
  1389
hoelzl@63050
  1390
wenzelm@60420
  1391
subsection \<open>Euclidean Spaces as Typeclass\<close>
huffman@44133
  1392
hoelzl@50526
  1393
lemma independent_Basis: "independent Basis"
hoelzl@50526
  1394
  unfolding dependent_def
hoelzl@50526
  1395
  apply (subst span_finite)
hoelzl@50526
  1396
  apply simp
huffman@44133
  1397
  apply clarify
hoelzl@50526
  1398
  apply (drule_tac f="inner a" in arg_cong)
hoelzl@50526
  1399
  apply (simp add: inner_Basis inner_setsum_right eq_commute)
hoelzl@50526
  1400
  done
hoelzl@50526
  1401
huffman@53939
  1402
lemma span_Basis [simp]: "span Basis = UNIV"
huffman@53939
  1403
  unfolding span_finite [OF finite_Basis]
huffman@53939
  1404
  by (fast intro: euclidean_representation)
huffman@44133
  1405
hoelzl@50526
  1406
lemma in_span_Basis: "x \<in> span Basis"
hoelzl@50526
  1407
  unfolding span_Basis ..
hoelzl@50526
  1408
hoelzl@50526
  1409
lemma Basis_le_norm: "b \<in> Basis \<Longrightarrow> \<bar>x \<bullet> b\<bar> \<le> norm x"
hoelzl@50526
  1410
  by (rule order_trans [OF Cauchy_Schwarz_ineq2]) simp
hoelzl@50526
  1411
hoelzl@50526
  1412
lemma norm_bound_Basis_le: "b \<in> Basis \<Longrightarrow> norm x \<le> e \<Longrightarrow> \<bar>x \<bullet> b\<bar> \<le> e"
hoelzl@50526
  1413
  by (metis Basis_le_norm order_trans)
hoelzl@50526
  1414
hoelzl@50526
  1415
lemma norm_bound_Basis_lt: "b \<in> Basis \<Longrightarrow> norm x < e \<Longrightarrow> \<bar>x \<bullet> b\<bar> < e"
huffman@53595
  1416
  by (metis Basis_le_norm le_less_trans)
hoelzl@50526
  1417
hoelzl@50526
  1418
lemma norm_le_l1: "norm x \<le> (\<Sum>b\<in>Basis. \<bar>x \<bullet> b\<bar>)"
hoelzl@50526
  1419
  apply (subst euclidean_representation[of x, symmetric])
huffman@44176
  1420
  apply (rule order_trans[OF norm_setsum])
wenzelm@49522
  1421
  apply (auto intro!: setsum_mono)
wenzelm@49522
  1422
  done
huffman@44133
  1423
huffman@44133
  1424
lemma setsum_norm_allsubsets_bound:
wenzelm@56444
  1425
  fixes f :: "'a \<Rightarrow> 'n::euclidean_space"
wenzelm@53406
  1426
  assumes fP: "finite P"
wenzelm@53406
  1427
    and fPs: "\<And>Q. Q \<subseteq> P \<Longrightarrow> norm (setsum f Q) \<le> e"
hoelzl@50526
  1428
  shows "(\<Sum>x\<in>P. norm (f x)) \<le> 2 * real DIM('n) * e"
wenzelm@49522
  1429
proof -
hoelzl@50526
  1430
  have "(\<Sum>x\<in>P. norm (f x)) \<le> (\<Sum>x\<in>P. \<Sum>b\<in>Basis. \<bar>f x \<bullet> b\<bar>)"
hoelzl@50526
  1431
    by (rule setsum_mono) (rule norm_le_l1)
hoelzl@50526
  1432
  also have "(\<Sum>x\<in>P. \<Sum>b\<in>Basis. \<bar>f x \<bullet> b\<bar>) = (\<Sum>b\<in>Basis. \<Sum>x\<in>P. \<bar>f x \<bullet> b\<bar>)"
haftmann@57418
  1433
    by (rule setsum.commute)
hoelzl@50526
  1434
  also have "\<dots> \<le> of_nat (card (Basis :: 'n set)) * (2 * e)"
lp15@60974
  1435
  proof (rule setsum_bounded_above)
wenzelm@53406
  1436
    fix i :: 'n
wenzelm@53406
  1437
    assume i: "i \<in> Basis"
wenzelm@53406
  1438
    have "norm (\<Sum>x\<in>P. \<bar>f x \<bullet> i\<bar>) \<le>
hoelzl@50526
  1439
      norm ((\<Sum>x\<in>P \<inter> - {x. f x \<bullet> i < 0}. f x) \<bullet> i) + norm ((\<Sum>x\<in>P \<inter> {x. f x \<bullet> i < 0}. f x) \<bullet> i)"
haftmann@57418
  1440
      by (simp add: abs_real_def setsum.If_cases[OF fP] setsum_negf norm_triangle_ineq4 inner_setsum_left
wenzelm@56444
  1441
        del: real_norm_def)
wenzelm@53406
  1442
    also have "\<dots> \<le> e + e"
wenzelm@53406
  1443
      unfolding real_norm_def
hoelzl@50526
  1444
      by (intro add_mono norm_bound_Basis_le i fPs) auto
hoelzl@50526
  1445
    finally show "(\<Sum>x\<in>P. \<bar>f x \<bullet> i\<bar>) \<le> 2*e" by simp
huffman@44133
  1446
  qed
lp15@61609
  1447
  also have "\<dots> = 2 * real DIM('n) * e" by simp
huffman@44133
  1448
  finally show ?thesis .
huffman@44133
  1449
qed
huffman@44133
  1450
wenzelm@53406
  1451
wenzelm@60420
  1452
subsection \<open>Linearity and Bilinearity continued\<close>
huffman@44133
  1453
huffman@44133
  1454
lemma linear_bounded:
wenzelm@56444
  1455
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
huffman@44133
  1456
  assumes lf: "linear f"
huffman@44133
  1457
  shows "\<exists>B. \<forall>x. norm (f x) \<le> B * norm x"
huffman@53939
  1458
proof
hoelzl@50526
  1459
  let ?B = "\<Sum>b\<in>Basis. norm (f b)"
huffman@53939
  1460
  show "\<forall>x. norm (f x) \<le> ?B * norm x"
huffman@53939
  1461
  proof
wenzelm@53406
  1462
    fix x :: 'a
hoelzl@50526
  1463
    let ?g = "\<lambda>b. (x \<bullet> b) *\<^sub>R f b"
hoelzl@50526
  1464
    have "norm (f x) = norm (f (\<Sum>b\<in>Basis. (x \<bullet> b) *\<^sub>R b))"
hoelzl@50526
  1465
      unfolding euclidean_representation ..
hoelzl@50526
  1466
    also have "\<dots> = norm (setsum ?g Basis)"
huffman@53939
  1467
      by (simp add: linear_setsum [OF lf] linear_cmul [OF lf])
hoelzl@50526
  1468
    finally have th0: "norm (f x) = norm (setsum ?g Basis)" .
huffman@53939
  1469
    have th: "\<forall>b\<in>Basis. norm (?g b) \<le> norm (f b) * norm x"
huffman@53939
  1470
    proof
wenzelm@53406
  1471
      fix i :: 'a
wenzelm@53406
  1472
      assume i: "i \<in> Basis"
hoelzl@50526
  1473
      from Basis_le_norm[OF i, of x]
huffman@53939
  1474
      show "norm (?g i) \<le> norm (f i) * norm x"
wenzelm@49663
  1475
        unfolding norm_scaleR
haftmann@57512
  1476
        apply (subst mult.commute)
wenzelm@49663
  1477
        apply (rule mult_mono)
wenzelm@49663
  1478
        apply (auto simp add: field_simps)
wenzelm@53406
  1479
        done
huffman@53939
  1480
    qed
hoelzl@50526
  1481
    from setsum_norm_le[of _ ?g, OF th]
huffman@53939
  1482
    show "norm (f x) \<le> ?B * norm x"
wenzelm@53406
  1483
      unfolding th0 setsum_left_distrib by metis
huffman@53939
  1484
  qed
huffman@44133
  1485
qed
huffman@44133
  1486
huffman@44133
  1487
lemma linear_conv_bounded_linear:
huffman@44133
  1488
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
huffman@44133
  1489
  shows "linear f \<longleftrightarrow> bounded_linear f"
huffman@44133
  1490
proof
huffman@44133
  1491
  assume "linear f"
huffman@53939
  1492
  then interpret f: linear f .
huffman@44133
  1493
  show "bounded_linear f"
huffman@44133
  1494
  proof
huffman@44133
  1495
    have "\<exists>B. \<forall>x. norm (f x) \<le> B * norm x"
wenzelm@60420
  1496
      using \<open>linear f\<close> by (rule linear_bounded)
wenzelm@49522
  1497
    then show "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K"
haftmann@57512
  1498
      by (simp add: mult.commute)
huffman@44133
  1499
  qed
huffman@44133
  1500
next
huffman@44133
  1501
  assume "bounded_linear f"
huffman@44133
  1502
  then interpret f: bounded_linear f .
huffman@53939
  1503
  show "linear f" ..
huffman@53939
  1504
qed
huffman@53939
  1505
paulson@61518
  1506
lemmas linear_linear = linear_conv_bounded_linear[symmetric]
paulson@61518
  1507
huffman@53939
  1508
lemma linear_bounded_pos:
wenzelm@56444
  1509
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
huffman@53939
  1510
  assumes lf: "linear f"
huffman@53939
  1511
  shows "\<exists>B > 0. \<forall>x. norm (f x) \<le> B * norm x"
huffman@53939
  1512
proof -
huffman@53939
  1513
  have "\<exists>B > 0. \<forall>x. norm (f x) \<le> norm x * B"
huffman@53939
  1514
    using lf unfolding linear_conv_bounded_linear
huffman@53939
  1515
    by (rule bounded_linear.pos_bounded)
huffman@53939
  1516
  then show ?thesis
haftmann@57512
  1517
    by (simp only: mult.commute)
huffman@44133
  1518
qed
huffman@44133
  1519
wenzelm@49522
  1520
lemma bounded_linearI':
wenzelm@56444
  1521
  fixes f ::"'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
wenzelm@53406
  1522
  assumes "\<And>x y. f (x + y) = f x + f y"
wenzelm@53406
  1523
    and "\<And>c x. f (c *\<^sub>R x) = c *\<^sub>R f x"
wenzelm@49522
  1524
  shows "bounded_linear f"
wenzelm@53406
  1525
  unfolding linear_conv_bounded_linear[symmetric]
wenzelm@49522
  1526
  by (rule linearI[OF assms])
huffman@44133
  1527
huffman@44133
  1528
lemma bilinear_bounded:
wenzelm@56444
  1529
  fixes h :: "'m::euclidean_space \<Rightarrow> 'n::euclidean_space \<Rightarrow> 'k::real_normed_vector"
huffman@44133
  1530
  assumes bh: "bilinear h"
huffman@44133
  1531
  shows "\<exists>B. \<forall>x y. norm (h x y) \<le> B * norm x * norm y"
hoelzl@50526
  1532
proof (clarify intro!: exI[of _ "\<Sum>i\<in>Basis. \<Sum>j\<in>Basis. norm (h i j)"])
wenzelm@53406
  1533
  fix x :: 'm
wenzelm@53406
  1534
  fix y :: 'n
wenzelm@53406
  1535
  have "norm (h x y) = norm (h (setsum (\<lambda>i. (x \<bullet> i) *\<^sub>R i) Basis) (setsum (\<lambda>i. (y \<bullet> i) *\<^sub>R i) Basis))"
wenzelm@53406
  1536
    apply (subst euclidean_representation[where 'a='m])
wenzelm@53406
  1537
    apply (subst euclidean_representation[where 'a='n])
hoelzl@50526
  1538
    apply rule
hoelzl@50526
  1539
    done
wenzelm@53406
  1540
  also have "\<dots> = norm (setsum (\<lambda> (i,j). h ((x \<bullet> i) *\<^sub>R i) ((y \<bullet> j) *\<^sub>R j)) (Basis \<times> Basis))"
hoelzl@50526
  1541
    unfolding bilinear_setsum[OF bh finite_Basis finite_Basis] ..
hoelzl@50526
  1542
  finally have th: "norm (h x y) = \<dots>" .
hoelzl@50526
  1543
  show "norm (h x y) \<le> (\<Sum>i\<in>Basis. \<Sum>j\<in>Basis. norm (h i j)) * norm x * norm y"
haftmann@57418
  1544
    apply (auto simp add: setsum_left_distrib th setsum.cartesian_product)
wenzelm@53406
  1545
    apply (rule setsum_norm_le)
wenzelm@53406
  1546
    apply simp
wenzelm@53406
  1547
    apply (auto simp add: bilinear_rmul[OF bh] bilinear_lmul[OF bh]
wenzelm@53406
  1548
      field_simps simp del: scaleR_scaleR)
wenzelm@53406
  1549
    apply (rule mult_mono)
wenzelm@53406
  1550
    apply (auto simp add: zero_le_mult_iff Basis_le_norm)
wenzelm@53406
  1551
    apply (rule mult_mono)
wenzelm@53406
  1552
    apply (auto simp add: zero_le_mult_iff Basis_le_norm)
wenzelm@53406
  1553
    done
huffman@44133
  1554
qed
huffman@44133
  1555
huffman@44133
  1556
lemma bilinear_conv_bounded_bilinear:
huffman@44133
  1557
  fixes h :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space \<Rightarrow> 'c::real_normed_vector"
huffman@44133
  1558
  shows "bilinear h \<longleftrightarrow> bounded_bilinear h"
huffman@44133
  1559
proof
huffman@44133
  1560
  assume "bilinear h"
huffman@44133
  1561
  show "bounded_bilinear h"
huffman@44133
  1562
  proof
wenzelm@53406
  1563
    fix x y z
wenzelm@53406
  1564
    show "h (x + y) z = h x z + h y z"
wenzelm@60420
  1565
      using \<open>bilinear h\<close> unfolding bilinear_def linear_iff by simp
huffman@44133
  1566
  next
wenzelm@53406
  1567
    fix x y z
wenzelm@53406
  1568
    show "h x (y + z) = h x y + h x z"
wenzelm@60420
  1569
      using \<open>bilinear h\<close> unfolding bilinear_def linear_iff by simp
huffman@44133
  1570
  next
wenzelm@53406
  1571
    fix r x y
wenzelm@53406
  1572
    show "h (scaleR r x) y = scaleR r (h x y)"
wenzelm@60420
  1573
      using \<open>bilinear h\<close> unfolding bilinear_def linear_iff
huffman@44133
  1574
      by simp
huffman@44133
  1575
  next
wenzelm@53406
  1576
    fix r x y
wenzelm@53406
  1577
    show "h x (scaleR r y) = scaleR r (h x y)"
wenzelm@60420
  1578
      using \<open>bilinear h\<close> unfolding bilinear_def linear_iff
huffman@44133
  1579
      by simp
huffman@44133
  1580
  next
huffman@44133
  1581
    have "\<exists>B. \<forall>x y. norm (h x y) \<le> B * norm x * norm y"
wenzelm@60420
  1582
      using \<open>bilinear h\<close> by (rule bilinear_bounded)
wenzelm@49522
  1583
    then show "\<exists>K. \<forall>x y. norm (h x y) \<le> norm x * norm y * K"
haftmann@57514
  1584
      by (simp add: ac_simps)
huffman@44133
  1585
  qed
huffman@44133
  1586
next
huffman@44133
  1587
  assume "bounded_bilinear h"
huffman@44133
  1588
  then interpret h: bounded_bilinear h .
huffman@44133
  1589
  show "bilinear h"
huffman@44133
  1590
    unfolding bilinear_def linear_conv_bounded_linear
wenzelm@49522
  1591
    using h.bounded_linear_left h.bounded_linear_right by simp
huffman@44133
  1592
qed
huffman@44133
  1593
huffman@53939
  1594
lemma bilinear_bounded_pos:
wenzelm@56444
  1595
  fixes h :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space \<Rightarrow> 'c::real_normed_vector"
huffman@53939
  1596
  assumes bh: "bilinear h"
huffman@53939
  1597
  shows "\<exists>B > 0. \<forall>x y. norm (h x y) \<le> B * norm x * norm y"
huffman@53939
  1598
proof -
huffman@53939
  1599
  have "\<exists>B > 0. \<forall>x y. norm (h x y) \<le> norm x * norm y * B"
huffman@53939
  1600
    using bh [unfolded bilinear_conv_bounded_bilinear]
huffman@53939
  1601
    by (rule bounded_bilinear.pos_bounded)
huffman@53939
  1602
  then show ?thesis
haftmann@57514
  1603
    by (simp only: ac_simps)
huffman@53939
  1604
qed
huffman@53939
  1605
wenzelm@49522
  1606
wenzelm@60420
  1607
subsection \<open>We continue.\<close>
huffman@44133
  1608
huffman@44133
  1609
lemma independent_bound:
wenzelm@53716
  1610
  fixes S :: "'a::euclidean_space set"
wenzelm@53716
  1611
  shows "independent S \<Longrightarrow> finite S \<and> card S \<le> DIM('a)"
hoelzl@50526
  1612
  using independent_span_bound[OF finite_Basis, of S] by auto
huffman@44133
  1613
lp15@61609
  1614
corollary
paulson@60303
  1615
  fixes S :: "'a::euclidean_space set"
paulson@60303
  1616
  assumes "independent S"
paulson@60303
  1617
  shows independent_imp_finite: "finite S" and independent_card_le:"card S \<le> DIM('a)"
paulson@60303
  1618
using assms independent_bound by auto
lp15@61609
  1619
wenzelm@49663
  1620
lemma dependent_biggerset:
wenzelm@56444
  1621
  fixes S :: "'a::euclidean_space set"
wenzelm@56444
  1622
  shows "(finite S \<Longrightarrow> card S > DIM('a)) \<Longrightarrow> dependent S"
huffman@44133
  1623
  by (metis independent_bound not_less)
huffman@44133
  1624
wenzelm@60420
  1625
text \<open>Hence we can create a maximal independent subset.\<close>
huffman@44133
  1626
huffman@44133
  1627
lemma maximal_independent_subset_extend:
wenzelm@53406
  1628
  fixes S :: "'a::euclidean_space set"
wenzelm@53406
  1629
  assumes sv: "S \<subseteq> V"
wenzelm@49663
  1630
    and iS: "independent S"
huffman@44133
  1631
  shows "\<exists>B. S \<subseteq> B \<and> B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B"
huffman@44133
  1632
  using sv iS
wenzelm@49522
  1633
proof (induct "DIM('a) - card S" arbitrary: S rule: less_induct)
huffman@44133
  1634
  case less
wenzelm@60420
  1635
  note sv = \<open>S \<subseteq> V\<close> and i = \<open>independent S\<close>
huffman@44133
  1636
  let ?P = "\<lambda>B. S \<subseteq> B \<and> B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B"
huffman@44133
  1637
  let ?ths = "\<exists>x. ?P x"
huffman@44133
  1638
  let ?d = "DIM('a)"
wenzelm@53406
  1639
  show ?ths
wenzelm@53406
  1640
  proof (cases "V \<subseteq> span S")
wenzelm@53406
  1641
    case True
wenzelm@53406
  1642
    then show ?thesis
wenzelm@53406
  1643
      using sv i by blast
wenzelm@53406
  1644
  next
wenzelm@53406
  1645
    case False
wenzelm@53406
  1646
    then obtain a where a: "a \<in> V" "a \<notin> span S"
wenzelm@53406
  1647
      by blast
wenzelm@53406
  1648
    from a have aS: "a \<notin> S"
wenzelm@53406
  1649
      by (auto simp add: span_superset)
wenzelm@53406
  1650
    have th0: "insert a S \<subseteq> V"
wenzelm@53406
  1651
      using a sv by blast
huffman@44133
  1652
    from independent_insert[of a S]  i a
wenzelm@53406
  1653
    have th1: "independent (insert a S)"
wenzelm@53406
  1654
      by auto
huffman@44133
  1655
    have mlt: "?d - card (insert a S) < ?d - card S"
wenzelm@49522
  1656
      using aS a independent_bound[OF th1] by auto
huffman@44133
  1657
huffman@44133
  1658
    from less(1)[OF mlt th0 th1]
huffman@44133
  1659
    obtain B where B: "insert a S \<subseteq> B" "B \<subseteq> V" "independent B" " V \<subseteq> span B"
huffman@44133
  1660
      by blast
huffman@44133
  1661
    from B have "?P B" by auto
wenzelm@53406
  1662
    then show ?thesis by blast
wenzelm@53406
  1663
  qed
huffman@44133
  1664
qed
huffman@44133
  1665
huffman@44133
  1666
lemma maximal_independent_subset:
huffman@44133
  1667
  "\<exists>(B:: ('a::euclidean_space) set). B\<subseteq> V \<and> independent B \<and> V \<subseteq> span B"
wenzelm@49522
  1668
  by (metis maximal_independent_subset_extend[of "{}:: ('a::euclidean_space) set"]
wenzelm@49522
  1669
    empty_subsetI independent_empty)
huffman@44133
  1670
huffman@44133
  1671
wenzelm@60420
  1672
text \<open>Notion of dimension.\<close>
huffman@44133
  1673
wenzelm@53406
  1674
definition "dim V = (SOME n. \<exists>B. B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> card B = n)"
huffman@44133
  1675
wenzelm@49522
  1676
lemma basis_exists:
wenzelm@49522
  1677
  "\<exists>B. (B :: ('a::euclidean_space) set) \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> (card B = dim V)"
wenzelm@49522
  1678
  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)"]
wenzelm@49522
  1679
  using maximal_independent_subset[of V] independent_bound
wenzelm@49522
  1680
  by auto
huffman@44133
  1681
lp15@60307
  1682
corollary dim_le_card:
lp15@60307
  1683
  fixes s :: "'a::euclidean_space set"
lp15@60307
  1684
  shows "finite s \<Longrightarrow> dim s \<le> card s"
lp15@60307
  1685
by (metis basis_exists card_mono)
lp15@60307
  1686
wenzelm@60420
  1687
text \<open>Consequences of independence or spanning for cardinality.\<close>
huffman@44133
  1688
wenzelm@53406
  1689
lemma independent_card_le_dim:
wenzelm@53406
  1690
  fixes B :: "'a::euclidean_space set"
wenzelm@53406
  1691
  assumes "B \<subseteq> V"
wenzelm@53406
  1692
    and "independent B"
wenzelm@49522
  1693
  shows "card B \<le> dim V"
huffman@44133
  1694
proof -
wenzelm@60420
  1695
  from basis_exists[of V] \<open>B \<subseteq> V\<close>
wenzelm@53406
  1696
  obtain B' where "independent B'"
wenzelm@53406
  1697
    and "B \<subseteq> span B'"
wenzelm@53406
  1698
    and "card B' = dim V"
wenzelm@53406
  1699
    by blast
wenzelm@60420
  1700
  with independent_span_bound[OF _ \<open>independent B\<close> \<open>B \<subseteq> span B'\<close>] independent_bound[of B']
huffman@44133
  1701
  show ?thesis by auto
huffman@44133
  1702
qed
huffman@44133
  1703
wenzelm@49522
  1704
lemma span_card_ge_dim:
wenzelm@53406
  1705
  fixes B :: "'a::euclidean_space set"
wenzelm@53406
  1706
  shows "B \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> finite B \<Longrightarrow> dim V \<le> card B"
huffman@44133
  1707
  by (metis basis_exists[of V] independent_span_bound subset_trans)
huffman@44133
  1708
huffman@44133
  1709
lemma basis_card_eq_dim:
wenzelm@53406
  1710
  fixes V :: "'a::euclidean_space set"
wenzelm@53406
  1711
  shows "B \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> independent B \<Longrightarrow> finite B \<and> card B = dim V"
huffman@44133
  1712
  by (metis order_eq_iff independent_card_le_dim span_card_ge_dim independent_bound)
huffman@44133
  1713
wenzelm@53406
  1714
lemma dim_unique:
wenzelm@53406
  1715
  fixes B :: "'a::euclidean_space set"
wenzelm@53406
  1716
  shows "B \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> independent B \<Longrightarrow> card B = n \<Longrightarrow> dim V = n"
huffman@44133
  1717
  by (metis basis_card_eq_dim)
huffman@44133
  1718
wenzelm@60420
  1719
text \<open>More lemmas about dimension.\<close>
huffman@44133
  1720
wenzelm@53406
  1721
lemma dim_UNIV: "dim (UNIV :: 'a::euclidean_space set) = DIM('a)"
hoelzl@50526
  1722
  using independent_Basis
hoelzl@50526
  1723
  by (intro dim_unique[of Basis]) auto
huffman@44133
  1724
huffman@44133
  1725
lemma dim_subset:
wenzelm@53406
  1726
  fixes S :: "'a::euclidean_space set"
wenzelm@53406
  1727
  shows "S \<subseteq> T \<Longrightarrow> dim S \<le> dim T"
huffman@44133
  1728
  using basis_exists[of T] basis_exists[of S]
huffman@44133
  1729
  by (metis independent_card_le_dim subset_trans)
huffman@44133
  1730
wenzelm@53406
  1731
lemma dim_subset_UNIV:
wenzelm@53406
  1732
  fixes S :: "'a::euclidean_space set"
wenzelm@53406
  1733
  shows "dim S \<le> DIM('a)"
huffman@44133
  1734
  by (metis dim_subset subset_UNIV dim_UNIV)
huffman@44133
  1735
wenzelm@60420
  1736
text \<open>Converses to those.\<close>
huffman@44133
  1737
huffman@44133
  1738
lemma card_ge_dim_independent:
wenzelm@53406
  1739
  fixes B :: "'a::euclidean_space set"
wenzelm@53406
  1740
  assumes BV: "B \<subseteq> V"
wenzelm@53406
  1741
    and iB: "independent B"
wenzelm@53406
  1742
    and dVB: "dim V \<le> card B"
huffman@44133
  1743
  shows "V \<subseteq> span B"
wenzelm@53406
  1744
proof
wenzelm@53406
  1745
  fix a
wenzelm@53406
  1746
  assume aV: "a \<in> V"
wenzelm@53406
  1747
  {
wenzelm@53406
  1748
    assume aB: "a \<notin> span B"
wenzelm@53406
  1749
    then have iaB: "independent (insert a B)"
wenzelm@53406
  1750
      using iB aV BV by (simp add: independent_insert)
wenzelm@53406
  1751
    from aV BV have th0: "insert a B \<subseteq> V"
wenzelm@53406
  1752
      by blast
wenzelm@53406
  1753
    from aB have "a \<notin>B"
wenzelm@53406
  1754
      by (auto simp add: span_superset)
wenzelm@53406
  1755
    with independent_card_le_dim[OF th0 iaB] dVB independent_bound[OF iB]
wenzelm@53406
  1756
    have False by auto
wenzelm@53406
  1757
  }
wenzelm@53406
  1758
  then show "a \<in> span B" by blast
huffman@44133
  1759
qed
huffman@44133
  1760
huffman@44133
  1761
lemma card_le_dim_spanning:
wenzelm@49663
  1762
  assumes BV: "(B:: ('a::euclidean_space) set) \<subseteq> V"
wenzelm@49663
  1763
    and VB: "V \<subseteq> span B"
wenzelm@49663
  1764
    and fB: "finite B"
wenzelm@49663
  1765
    and dVB: "dim V \<ge> card B"
huffman@44133
  1766
  shows "independent B"
wenzelm@49522
  1767
proof -
wenzelm@53406
  1768
  {
wenzelm@53406
  1769
    fix a
wenzelm@53716
  1770
    assume a: "a \<in> B" "a \<in> span (B - {a})"
wenzelm@53406
  1771
    from a fB have c0: "card B \<noteq> 0"
wenzelm@53406
  1772
      by auto
wenzelm@53716
  1773
    from a fB have cb: "card (B - {a}) = card B - 1"
wenzelm@53406
  1774
      by auto
wenzelm@53716
  1775
    from BV a have th0: "B - {a} \<subseteq> V"
wenzelm@53406
  1776
      by blast
wenzelm@53406
  1777
    {
wenzelm@53406
  1778
      fix x
wenzelm@53406
  1779
      assume x: "x \<in> V"
wenzelm@53716
  1780
      from a have eq: "insert a (B - {a}) = B"
wenzelm@53406
  1781
        by blast
wenzelm@53406
  1782
      from x VB have x': "x \<in> span B"
wenzelm@53406
  1783
        by blast
huffman@44133
  1784
      from span_trans[OF a(2), unfolded eq, OF x']
wenzelm@53716
  1785
      have "x \<in> span (B - {a})" .
wenzelm@53406
  1786
    }
wenzelm@53716
  1787
    then have th1: "V \<subseteq> span (B - {a})"
wenzelm@53406
  1788
      by blast
wenzelm@53716
  1789
    have th2: "finite (B - {a})"
wenzelm@53406
  1790
      using fB by auto
huffman@44133
  1791
    from span_card_ge_dim[OF th0 th1 th2]
wenzelm@53716
  1792
    have c: "dim V \<le> card (B - {a})" .
wenzelm@53406
  1793
    from c c0 dVB cb have False by simp
wenzelm@53406
  1794
  }
wenzelm@53406
  1795
  then show ?thesis
wenzelm@53406
  1796
    unfolding dependent_def by blast
huffman@44133
  1797
qed
huffman@44133
  1798
wenzelm@53406
  1799
lemma card_eq_dim:
wenzelm@53406
  1800
  fixes B :: "'a::euclidean_space set"
wenzelm@53406
  1801
  shows "B \<subseteq> V \<Longrightarrow> card B = dim V \<Longrightarrow> finite B \<Longrightarrow> independent B \<longleftrightarrow> V \<subseteq> span B"
wenzelm@49522
  1802
  by (metis order_eq_iff card_le_dim_spanning card_ge_dim_independent)
huffman@44133
  1803
wenzelm@60420
  1804
text \<open>More general size bound lemmas.\<close>
huffman@44133
  1805
huffman@44133
  1806
lemma independent_bound_general:
wenzelm@53406
  1807
  fixes S :: "'a::euclidean_space set"
wenzelm@53406
  1808
  shows "independent S \<Longrightarrow> finite S \<and> card S \<le> dim S"
huffman@44133
  1809
  by (metis independent_card_le_dim independent_bound subset_refl)
huffman@44133
  1810
wenzelm@49522
  1811
lemma dependent_biggerset_general:
wenzelm@53406
  1812
  fixes S :: "'a::euclidean_space set"
wenzelm@53406
  1813
  shows "(finite S \<Longrightarrow> card S > dim S) \<Longrightarrow> dependent S"
huffman@44133
  1814
  using independent_bound_general[of S] by (metis linorder_not_le)
huffman@44133
  1815
paulson@60303
  1816
lemma dim_span [simp]:
wenzelm@53406
  1817
  fixes S :: "'a::euclidean_space set"
wenzelm@53406
  1818
  shows "dim (span S) = dim S"
wenzelm@49522
  1819
proof -
huffman@44133
  1820
  have th0: "dim S \<le> dim (span S)"
huffman@44133
  1821
    by (auto simp add: subset_eq intro: dim_subset span_superset)
huffman@44133
  1822
  from basis_exists[of S]
wenzelm@53406
  1823
  obtain B where B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S"
wenzelm@53406
  1824
    by blast
wenzelm@53406
  1825
  from B have fB: "finite B" "card B = dim S"
wenzelm@53406
  1826
    using independent_bound by blast+
wenzelm@53406
  1827
  have bSS: "B \<subseteq> span S"
wenzelm@53406
  1828
    using B(1) by (metis subset_eq span_inc)
wenzelm@53406
  1829
  have sssB: "span S \<subseteq> span B"
wenzelm@53406
  1830
    using span_mono[OF B(3)] by (simp add: span_span)
huffman@44133
  1831
  from span_card_ge_dim[OF bSS sssB fB(1)] th0 show ?thesis
wenzelm@49522
  1832
    using fB(2) by arith
huffman@44133
  1833
qed
huffman@44133
  1834
wenzelm@53406
  1835
lemma subset_le_dim:
wenzelm@53406
  1836
  fixes S :: "'a::euclidean_space set"
wenzelm@53406
  1837
  shows "S \<subseteq> span T \<Longrightarrow> dim S \<le> dim T"
huffman@44133
  1838
  by (metis dim_span dim_subset)
huffman@44133
  1839
wenzelm@53406
  1840
lemma span_eq_dim:
wenzelm@56444
  1841
  fixes S :: "'a::euclidean_space set"
wenzelm@53406
  1842
  shows "span S = span T \<Longrightarrow> dim S = dim T"
huffman@44133
  1843
  by (metis dim_span)
huffman@44133
  1844
huffman@44133
  1845
lemma spans_image:
wenzelm@49663
  1846
  assumes lf: "linear f"
wenzelm@49663
  1847
    and VB: "V \<subseteq> span B"
huffman@44133
  1848
  shows "f ` V \<subseteq> span (f ` B)"
wenzelm@49522
  1849
  unfolding span_linear_image[OF lf] by (metis VB image_mono)
huffman@44133
  1850
huffman@44133
  1851
lemma dim_image_le:
huffman@44133
  1852
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
wenzelm@49663
  1853
  assumes lf: "linear f"
wenzelm@49663
  1854
  shows "dim (f ` S) \<le> dim (S)"
wenzelm@49522
  1855
proof -
huffman@44133
  1856
  from basis_exists[of S] obtain B where
huffman@44133
  1857
    B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S" by blast
wenzelm@53406
  1858
  from B have fB: "finite B" "card B = dim S"
wenzelm@53406
  1859
    using independent_bound by blast+
huffman@44133
  1860
  have "dim (f ` S) \<le> card (f ` B)"
huffman@44133
  1861
    apply (rule span_card_ge_dim)
wenzelm@53406
  1862
    using lf B fB
wenzelm@53406
  1863
    apply (auto simp add: span_linear_image spans_image subset_image_iff)
wenzelm@49522
  1864
    done
wenzelm@53406
  1865
  also have "\<dots> \<le> dim S"
wenzelm@53406
  1866
    using card_image_le[OF fB(1)] fB by simp
huffman@44133
  1867
  finally show ?thesis .
huffman@44133
  1868
qed
huffman@44133
  1869
wenzelm@60420
  1870
text \<open>Relation between bases and injectivity/surjectivity of map.\<close>
huffman@44133
  1871
huffman@44133
  1872
lemma spanning_surjective_image:
huffman@44133
  1873
  assumes us: "UNIV \<subseteq> span S"
wenzelm@53406
  1874
    and lf: "linear f"
wenzelm@53406
  1875
    and sf: "surj f"
huffman@44133
  1876
  shows "UNIV \<subseteq> span (f ` S)"
wenzelm@49663
  1877
proof -
wenzelm@53406
  1878
  have "UNIV \<subseteq> f ` UNIV"
wenzelm@53406
  1879
    using sf by (auto simp add: surj_def)
wenzelm@53406
  1880
  also have " \<dots> \<subseteq> span (f ` S)"
wenzelm@53406
  1881
    using spans_image[OF lf us] .
wenzelm@53406
  1882
  finally show ?thesis .
huffman@44133
  1883
qed
huffman@44133
  1884
huffman@44133
  1885
lemma independent_injective_image:
wenzelm@49663
  1886
  assumes iS: "independent S"
wenzelm@49663
  1887
    and lf: "linear f"
wenzelm@49663
  1888
    and fi: "inj f"
huffman@44133
  1889
  shows "independent (f ` S)"
wenzelm@49663
  1890
proof -
wenzelm@53406
  1891
  {
wenzelm@53406
  1892
    fix a
wenzelm@49663
  1893
    assume a: "a \<in> S" "f a \<in> span (f ` S - {f a})"
wenzelm@53406
  1894
    have eq: "f ` S - {f a} = f ` (S - {a})"
wenzelm@53406
  1895
      using fi by (auto simp add: inj_on_def)
wenzelm@53716
  1896
    from a have "f a \<in> f ` span (S - {a})"
wenzelm@53406
  1897
      unfolding eq span_linear_image[OF lf, of "S - {a}"] by blast
wenzelm@53716
  1898
    then have "a \<in> span (S - {a})"
wenzelm@53406
  1899
      using fi by (auto simp add: inj_on_def)
wenzelm@53406
  1900
    with a(1) iS have False
wenzelm@53406
  1901
      by (simp add: dependent_def)
wenzelm@53406
  1902
  }
wenzelm@53406
  1903
  then show ?thesis
wenzelm@53406
  1904
    unfolding dependent_def by blast
huffman@44133
  1905
qed
huffman@44133
  1906
wenzelm@60420
  1907
text \<open>Picking an orthogonal replacement for a spanning set.\<close>
huffman@44133
  1908
wenzelm@53406
  1909
lemma vector_sub_project_orthogonal:
wenzelm@53406
  1910
  fixes b x :: "'a::euclidean_space"
wenzelm@53406
  1911
  shows "b \<bullet> (x - ((b \<bullet> x) / (b \<bullet> b)) *\<^sub>R b) = 0"
huffman@44133
  1912
  unfolding inner_simps by auto
huffman@44133
  1913
huffman@44528
  1914
lemma pairwise_orthogonal_insert:
huffman@44528
  1915
  assumes "pairwise orthogonal S"
wenzelm@49522
  1916
    and "\<And>y. y \<in> S \<Longrightarrow> orthogonal x y"
huffman@44528
  1917
  shows "pairwise orthogonal (insert x S)"
huffman@44528
  1918
  using assms unfolding pairwise_def
huffman@44528
  1919
  by (auto simp add: orthogonal_commute)
huffman@44528
  1920
huffman@44133
  1921
lemma basis_orthogonal:
wenzelm@53406
  1922
  fixes B :: "'a::real_inner set"
huffman@44133
  1923
  assumes fB: "finite B"
huffman@44133
  1924
  shows "\<exists>C. finite C \<and> card C \<le> card B \<and> span C = span B \<and> pairwise orthogonal C"
huffman@44133
  1925
  (is " \<exists>C. ?P B C")
wenzelm@49522
  1926
  using fB
wenzelm@49522
  1927
proof (induct rule: finite_induct)
wenzelm@49522
  1928
  case empty
wenzelm@53406
  1929
  then show ?case
wenzelm@53406
  1930
    apply (rule exI[where x="{}"])
wenzelm@53406
  1931
    apply (auto simp add: pairwise_def)
wenzelm@53406
  1932
    done
huffman@44133
  1933
next
wenzelm@49522
  1934
  case (insert a B)
wenzelm@60420
  1935
  note fB = \<open>finite B\<close> and aB = \<open>a \<notin> B\<close>
wenzelm@60420
  1936
  from \<open>\<exists>C. finite C \<and> card C \<le> card B \<and> span C = span B \<and> pairwise orthogonal C\<close>
huffman@44133
  1937
  obtain C where C: "finite C" "card C \<le> card B"
huffman@44133
  1938
    "span C = span B" "pairwise orthogonal C" by blast
huffman@44133
  1939
  let ?a = "a - setsum (\<lambda>x. (x \<bullet> a / (x \<bullet> x)) *\<^sub>R x) C"
huffman@44133
  1940
  let ?C = "insert ?a C"
wenzelm@53406
  1941
  from C(1) have fC: "finite ?C"
wenzelm@53406
  1942
    by simp
wenzelm@49522
  1943
  from fB aB C(1,2) have cC: "card ?C \<le> card (insert a B)"
wenzelm@49522
  1944
    by (simp add: card_insert_if)
wenzelm@53406
  1945
  {
wenzelm@53406
  1946
    fix x k
wenzelm@49522
  1947
    have th0: "\<And>(a::'a) b c. a - (b - c) = c + (a - b)"
wenzelm@49522
  1948
      by (simp add: field_simps)
huffman@44133
  1949
    have "x - k *\<^sub>R (a - (\<Sum>x\<in>C. (x \<bullet> a / (x \<bullet> x)) *\<^sub>R x)) \<in> span C \<longleftrightarrow> x - k *\<^sub>R a \<in> span C"
huffman@44133
  1950
      apply (simp only: scaleR_right_diff_distrib th0)
huffman@44133
  1951
      apply (rule span_add_eq)
huffman@44133
  1952
      apply (rule span_mul)
huffman@56196
  1953
      apply (rule span_setsum)
huffman@44133
  1954
      apply clarify
huffman@44133
  1955
      apply (rule span_mul)
wenzelm@49522
  1956
      apply (rule span_superset)
wenzelm@49522
  1957
      apply assumption
wenzelm@53406
  1958
      done
wenzelm@53406
  1959
  }
huffman@44133
  1960
  then have SC: "span ?C = span (insert a B)"
huffman@44133
  1961
    unfolding set_eq_iff span_breakdown_eq C(3)[symmetric] by auto
wenzelm@53406
  1962
  {
wenzelm@53406
  1963
    fix y
wenzelm@53406
  1964
    assume yC: "y \<in> C"
wenzelm@53406
  1965
    then have Cy: "C = insert y (C - {y})"
wenzelm@53406
  1966
      by blast
wenzelm@53406
  1967
    have fth: "finite (C - {y})"
wenzelm@53406
  1968
      using C by simp
huffman@44528
  1969
    have "orthogonal ?a y"
huffman@44528
  1970
      unfolding orthogonal_def
haftmann@54230
  1971
      unfolding inner_diff inner_setsum_left right_minus_eq
wenzelm@60420
  1972
      unfolding setsum.remove [OF \<open>finite C\<close> \<open>y \<in> C\<close>]
huffman@44528
  1973
      apply (clarsimp simp add: inner_commute[of y a])
haftmann@57418
  1974
      apply (rule setsum.neutral)
huffman@44528
  1975
      apply clarsimp
huffman@44528
  1976
      apply (rule C(4)[unfolded pairwise_def orthogonal_def, rule_format])
wenzelm@60420
  1977
      using \<open>y \<in> C\<close> by auto
wenzelm@53406
  1978
  }
wenzelm@60420
  1979
  with \<open>pairwise orthogonal C\<close> have CPO: "pairwise orthogonal ?C"
huffman@44528
  1980
    by (rule pairwise_orthogonal_insert)
wenzelm@53406
  1981
  from fC cC SC CPO have "?P (insert a B) ?C"
wenzelm@53406
  1982
    by blast
huffman@44133
  1983
  then show ?case by blast
huffman@44133
  1984
qed
huffman@44133
  1985
huffman@44133
  1986
lemma orthogonal_basis_exists:
huffman@44133
  1987
  fixes V :: "('a::euclidean_space) set"
huffman@44133
  1988
  shows "\<exists>B. independent B \<and> B \<subseteq> span V \<and> V \<subseteq> span B \<and> (card B = dim V) \<and> pairwise orthogonal B"
wenzelm@49663
  1989
proof -
wenzelm@49522
  1990
  from basis_exists[of V] obtain B where
wenzelm@53406
  1991
    B: "B \<subseteq> V" "independent B" "V \<subseteq> span B" "card B = dim V"
wenzelm@53406
  1992
    by blast
wenzelm@53406
  1993
  from B have fB: "finite B" "card B = dim V"
wenzelm@53406
  1994
    using independent_bound by auto
huffman@44133
  1995
  from basis_orthogonal[OF fB(1)] obtain C where
wenzelm@53406
  1996
    C: "finite C" "card C \<le> card B" "span C = span B" "pairwise orthogonal C"
wenzelm@53406
  1997
    by blast
wenzelm@53406
  1998
  from C B have CSV: "C \<subseteq> span V"
wenzelm@53406
  1999
    by (metis span_inc span_mono subset_trans)
wenzelm@53406
  2000
  from span_mono[OF B(3)] C have SVC: "span V \<subseteq> span C"
wenzelm@53406
  2001
    by (simp add: span_span)
huffman@44133
  2002
  from card_le_dim_spanning[OF CSV SVC C(1)] C(2,3) fB
wenzelm@53406
  2003
  have iC: "independent C"
huffman@44133
  2004
    by (simp add: dim_span)
wenzelm@53406
  2005
  from C fB have "card C \<le> dim V"
wenzelm@53406
  2006
    by simp
wenzelm@53406
  2007
  moreover have "dim V \<le> card C"
wenzelm@53406
  2008
    using span_card_ge_dim[OF CSV SVC C(1)]
wenzelm@53406
  2009
    by (simp add: dim_span)
wenzelm@53406
  2010
  ultimately have CdV: "card C = dim V"
wenzelm@53406
  2011
    using C(1) by simp
wenzelm@53406
  2012
  from C B CSV CdV iC show ?thesis
wenzelm@53406
  2013
    by auto
huffman@44133
  2014
qed
huffman@44133
  2015
huffman@44133
  2016
lemma span_eq: "span S = span T \<longleftrightarrow> S \<subseteq> span T \<and> T \<subseteq> span S"
huffman@44133
  2017
  using span_inc[unfolded subset_eq] using span_mono[of T "span S"] span_mono[of S "span T"]
wenzelm@49522
  2018
  by (auto simp add: span_span)
huffman@44133
  2019
wenzelm@60420
  2020
text \<open>Low-dimensional subset is in a hyperplane (weak orthogonal complement).\<close>
huffman@44133
  2021
wenzelm@49522
  2022
lemma span_not_univ_orthogonal:
wenzelm@53406
  2023
  fixes S :: "'a::euclidean_space set"
huffman@44133
  2024
  assumes sU: "span S \<noteq> UNIV"
wenzelm@56444
  2025
  shows "\<exists>a::'a. a \<noteq> 0 \<and> (\<forall>x \<in> span S. a \<bullet> x = 0)"
wenzelm@49522
  2026
proof -
wenzelm@53406
  2027
  from sU obtain a where a: "a \<notin> span S"
wenzelm@53406
  2028
    by blast
huffman@44133
  2029
  from orthogonal_basis_exists obtain B where
huffman@44133
  2030
    B: "independent B" "B \<subseteq> span S" "S \<subseteq> span B" "card B = dim S" "pairwise orthogonal B"
huffman@44133
  2031
    by blast
wenzelm@53406
  2032
  from B have fB: "finite B" "card B = dim S"
wenzelm@53406
  2033
    using independent_bound by auto
huffman@44133
  2034
  from span_mono[OF B(2)] span_mono[OF B(3)]
wenzelm@53406
  2035
  have sSB: "span S = span B"
wenzelm@53406
  2036
    by (simp add: span_span)
huffman@44133
  2037
  let ?a = "a - setsum (\<lambda>b. (a \<bullet> b / (b \<bullet> b)) *\<^sub>R b) B"
huffman@44133
  2038
  have "setsum (\<lambda>b. (a \<bullet> b / (b \<bullet> b)) *\<^sub>R b) B \<in> span S"
huffman@44133
  2039
    unfolding sSB
huffman@56196
  2040
    apply (rule span_setsum)
huffman@44133
  2041
    apply clarsimp
huffman@44133
  2042
    apply (rule span_mul)
wenzelm@49522
  2043
    apply (rule span_superset)
wenzelm@49522
  2044
    apply assumption
wenzelm@49522
  2045
    done
wenzelm@53406
  2046
  with a have a0:"?a  \<noteq> 0"
wenzelm@53406
  2047
    by auto
huffman@44133
  2048
  have "\<forall>x\<in>span B. ?a \<bullet> x = 0"
wenzelm@49522
  2049
  proof (rule span_induct')
wenzelm@49522
  2050
    show "subspace {x. ?a \<bullet> x = 0}"
wenzelm@49522
  2051
      by (auto simp add: subspace_def inner_add)
wenzelm@49522
  2052
  next
wenzelm@53406
  2053
    {
wenzelm@53406
  2054
      fix x
wenzelm@53406
  2055
      assume x: "x \<in> B"
wenzelm@53406
  2056
      from x have B': "B = insert x (B - {x})"
wenzelm@53406
  2057
        by blast
wenzelm@53406
  2058
      have fth: "finite (B - {x})"
wenzelm@53406
  2059
        using fB by simp
huffman@44133
  2060
      have "?a \<bullet> x = 0"
wenzelm@53406
  2061
        apply (subst B')
wenzelm@53406
  2062
        using fB fth
huffman@44133
  2063
        unfolding setsum_clauses(2)[OF fth]
huffman@44133
  2064
        apply simp unfolding inner_simps
huffman@44527
  2065
        apply (clarsimp simp add: inner_add inner_setsum_left)
haftmann@57418
  2066
        apply (rule setsum.neutral, rule ballI)
huffman@44133
  2067
        unfolding inner_commute
wenzelm@49711
  2068
        apply (auto simp add: x field_simps
wenzelm@49711
  2069
          intro: B(5)[unfolded pairwise_def orthogonal_def, rule_format])
wenzelm@53406
  2070
        done
wenzelm@53406
  2071
    }
wenzelm@53406
  2072
    then show "\<forall>x \<in> B. ?a \<bullet> x = 0"
wenzelm@53406
  2073
      by blast
huffman@44133
  2074
  qed
wenzelm@53406
  2075
  with a0 show ?thesis
wenzelm@53406
  2076
    unfolding sSB by (auto intro: exI[where x="?a"])
huffman@44133
  2077
qed
huffman@44133
  2078
huffman@44133
  2079
lemma span_not_univ_subset_hyperplane:
wenzelm@53406
  2080
  fixes S :: "'a::euclidean_space set"
wenzelm@53406
  2081
  assumes SU: "span S \<noteq> UNIV"
huffman@44133
  2082
  shows "\<exists> a. a \<noteq>0 \<and> span S \<subseteq> {x. a \<bullet> x = 0}"
huffman@44133
  2083
  using span_not_univ_orthogonal[OF SU] by auto
huffman@44133
  2084
wenzelm@49663
  2085
lemma lowdim_subset_hyperplane:
wenzelm@53406
  2086
  fixes S :: "'a::euclidean_space set"
huffman@44133
  2087
  assumes d: "dim S < DIM('a)"
wenzelm@56444
  2088
  shows "\<exists>a::'a. a \<noteq> 0 \<and> span S \<subseteq> {x. a \<bullet> x = 0}"
wenzelm@49522
  2089
proof -
wenzelm@53406
  2090
  {
wenzelm@53406
  2091
    assume "span S = UNIV"
wenzelm@53406
  2092
    then have "dim (span S) = dim (UNIV :: ('a) set)"
wenzelm@53406
  2093
      by simp
wenzelm@53406
  2094
    then have "dim S = DIM('a)"
wenzelm@53406
  2095
      by (simp add: dim_span dim_UNIV)
wenzelm@53406
  2096
    with d have False by arith
wenzelm@53406
  2097
  }
wenzelm@53406
  2098
  then have th: "span S \<noteq> UNIV"
wenzelm@53406
  2099
    by blast
huffman@44133
  2100
  from span_not_univ_subset_hyperplane[OF th] show ?thesis .
huffman@44133
  2101
qed
huffman@44133
  2102
wenzelm@60420
  2103
text \<open>We can extend a linear basis-basis injection to the whole set.\<close>
huffman@44133
  2104
huffman@44133
  2105
lemma linear_indep_image_lemma:
wenzelm@49663
  2106
  assumes lf: "linear f"
wenzelm@49663
  2107
    and fB: "finite B"
wenzelm@49522
  2108
    and ifB: "independent (f ` B)"
wenzelm@49663
  2109
    and fi: "inj_on f B"
wenzelm@49663
  2110
    and xsB: "x \<in> span B"
wenzelm@49522
  2111
    and fx: "f x = 0"
huffman@44133
  2112
  shows "x = 0"
huffman@44133
  2113
  using fB ifB fi xsB fx
wenzelm@49522
  2114
proof (induct arbitrary: x rule: finite_induct[OF fB])
wenzelm@49663
  2115
  case 1
wenzelm@49663
  2116
  then show ?case by auto
huffman@44133
  2117
next
huffman@44133
  2118
  case (2 a b x)
huffman@44133
  2119
  have fb: "finite b" using "2.prems" by simp
huffman@44133
  2120
  have th0: "f ` b \<subseteq> f ` (insert a b)"
wenzelm@53406
  2121
    apply (rule image_mono)
wenzelm@53406
  2122
    apply blast
wenzelm@53406
  2123
    done
huffman@44133
  2124
  from independent_mono[ OF "2.prems"(2) th0]
huffman@44133
  2125
  have ifb: "independent (f ` b)"  .
huffman@44133
  2126
  have fib: "inj_on f b"
huffman@44133
  2127
    apply (rule subset_inj_on [OF "2.prems"(3)])
wenzelm@49522
  2128
    apply blast
wenzelm@49522
  2129
    done
huffman@44133
  2130
  from span_breakdown[of a "insert a b", simplified, OF "2.prems"(4)]
wenzelm@53406
  2131
  obtain k where k: "x - k*\<^sub>R a \<in> span (b - {a})"
wenzelm@53406
  2132
    by blast
huffman@44133
  2133
  have "f (x - k*\<^sub>R a) \<in> span (f ` b)"
huffman@44133
  2134
    unfolding span_linear_image[OF lf]
huffman@44133
  2135
    apply (rule imageI)
wenzelm@53716
  2136
    using k span_mono[of "b - {a}" b]
wenzelm@53406
  2137
    apply blast
wenzelm@49522
  2138
    done
wenzelm@49522
  2139
  then have "f x - k*\<^sub>R f a \<in> span (f ` b)"
huffman@44133
  2140
    by (simp add: linear_sub[OF lf] linear_cmul[OF lf])
wenzelm@49522
  2141
  then have th: "-k *\<^sub>R f a \<in> span (f ` b)"
huffman@44133
  2142
    using "2.prems"(5) by simp
wenzelm@53406
  2143
  have xsb: "x \<in> span b"
wenzelm@53406
  2144
  proof (cases "k = 0")
wenzelm@53406
  2145
    case True
wenzelm@53716
  2146
    with k have "x \<in> span (b - {a})" by simp
wenzelm@53716
  2147
    then show ?thesis using span_mono[of "b - {a}" b]
wenzelm@53406
  2148
      by blast
wenzelm@53406
  2149
  next
wenzelm@53406
  2150
    case False
wenzelm@53406
  2151
    with span_mul[OF th, of "- 1/ k"]
huffman@44133
  2152
    have th1: "f a \<in> span (f ` b)"
hoelzl@56479
  2153
      by auto
huffman@44133
  2154
    from inj_on_image_set_diff[OF "2.prems"(3), of "insert a b " "{a}", symmetric]
huffman@44133
  2155
    have tha: "f ` insert a b - f ` {a} = f ` (insert a b - {a})" by blast
huffman@44133
  2156
    from "2.prems"(2) [unfolded dependent_def bex_simps(8), rule_format, of "f a"]
huffman@44133
  2157
    have "f a \<notin> span (f ` b)" using tha
huffman@44133
  2158
      using "2.hyps"(2)
huffman@44133
  2159
      "2.prems"(3) by auto
huffman@44133
  2160
    with th1 have False by blast
wenzelm@53406
  2161
    then show ?thesis by blast
wenzelm@53406
  2162
  qed
wenzelm@53406
  2163
  from "2.hyps"(3)[OF fb ifb fib xsb "2.prems"(5)] show "x = 0" .
huffman@44133
  2164
qed
huffman@44133
  2165
wenzelm@60420
  2166
text \<open>We can extend a linear mapping from basis.\<close>
huffman@44133
  2167
huffman@44133
  2168
lemma linear_independent_extend_lemma:
huffman@44133
  2169
  fixes f :: "'a::real_vector \<Rightarrow> 'b::real_vector"
wenzelm@53406
  2170
  assumes fi: "finite B"
wenzelm@53406
  2171
    and ib: "independent B"
wenzelm@53406
  2172
  shows "\<exists>g.
wenzelm@53406
  2173
    (\<forall>x\<in> span B. \<forall>y\<in> span B. g (x + y) = g x + g y) \<and>
wenzelm@53406
  2174
    (\<forall>x\<in> span B. \<forall>c. g (c*\<^sub>R x) = c *\<^sub>R g x) \<and>
wenzelm@53406
  2175
    (\<forall>x\<in> B. g x = f x)"
wenzelm@49663
  2176
  using ib fi
wenzelm@49522
  2177
proof (induct rule: finite_induct[OF fi])
wenzelm@49663
  2178
  case 1
wenzelm@49663
  2179
  then show ?case by auto
huffman@44133
  2180
next
huffman@44133
  2181
  case (2 a b)
huffman@44133
  2182
  from "2.prems" "2.hyps" have ibf: "independent b" "finite b"
huffman@44133
  2183
    by (simp_all add: independent_insert)
huffman@44133
  2184
  from "2.hyps"(3)[OF ibf] obtain g where
huffman@44133
  2185
    g: "\<forall>x\<in>span b. \<forall>y\<in>span b. g (x + y) = g x + g y"
huffman@44133
  2186
    "\<forall>x\<in>span b. \<forall>c. g (c *\<^sub>R x) = c *\<^sub>R g x" "\<forall>x\<in>b. g x = f x" by blast
huffman@44133
  2187
  let ?h = "\<lambda>z. SOME k. (z - k *\<^sub>R a) \<in> span b"
wenzelm@53406
  2188
  {
wenzelm@53406
  2189
    fix z
wenzelm@53406
  2190
    assume z: "z \<in> span (insert a b)"
huffman@44133
  2191
    have th0: "z - ?h z *\<^sub>R a \<in> span b"
huffman@44133
  2192
      apply (rule someI_ex)
huffman@44133
  2193
      unfolding span_breakdown_eq[symmetric]
wenzelm@53406
  2194
      apply (rule z)
wenzelm@53406
  2195
      done
wenzelm@53406
  2196
    {
wenzelm@53406
  2197
      fix k
wenzelm@53406
  2198
      assume k: "z - k *\<^sub>R a \<in> span b"
huffman@44133
  2199
      have eq: "z - ?h z *\<^sub>R a - (z - k*\<^sub>R a) = (k - ?h z) *\<^sub>R a"
huffman@44133
  2200
        by (simp add: field_simps scaleR_left_distrib [symmetric])
wenzelm@53406
  2201
      from span_sub[OF th0 k] have khz: "(k - ?h z) *\<^sub>R a \<in> span b"
wenzelm@53406
  2202
        by (simp add: eq)
wenzelm@53406
  2203
      {
wenzelm@53406
  2204
        assume "k \<noteq> ?h z"
wenzelm@53406
  2205
        then have k0: "k - ?h z \<noteq> 0" by simp
huffman@44133
  2206
        from k0 span_mul[OF khz, of "1 /(k - ?h z)"]
huffman@44133
  2207
        have "a \<in> span b" by simp
huffman@44133
  2208
        with "2.prems"(1) "2.hyps"(2) have False
wenzelm@53406
  2209
          by (auto simp add: dependent_def)
wenzelm@53406
  2210
      }
wenzelm@53406
  2211
      then have "k = ?h z" by blast
wenzelm@53406
  2212
    }
wenzelm@53406
  2213
    with th0 have "z - ?h z *\<^sub>R a \<in> span b \<and> (\<forall>k. z - k *\<^sub>R a \<in> span b \<longrightarrow> k = ?h z)"
wenzelm@53406
  2214
      by blast
wenzelm@53406
  2215
  }
huffman@44133
  2216
  note h = this
huffman@44133
  2217
  let ?g = "\<lambda>z. ?h z *\<^sub>R f a + g (z - ?h z *\<^sub>R a)"
wenzelm@53406
  2218
  {
wenzelm@53406
  2219
    fix x y
wenzelm@53406
  2220
    assume x: "x \<in> span (insert a b)"
wenzelm@53406
  2221
      and y: "y \<in> span (insert a b)"
huffman@44133
  2222
    have tha: "\<And>(x::'a) y a k l. (x + y) - (k + l) *\<^sub>R a = (x - k *\<^sub>R a) + (y - l *\<^sub>R a)"
huffman@44133
  2223
      by (simp add: algebra_simps)
huffman@44133
  2224
    have addh: "?h (x + y) = ?h x + ?h y"
huffman@44133
  2225
      apply (rule conjunct2[OF h, rule_format, symmetric])
huffman@44133
  2226
      apply (rule span_add[OF x y])
huffman@44133
  2227
      unfolding tha
wenzelm@53406
  2228
      apply (metis span_add x y conjunct1[OF h, rule_format])
wenzelm@53406
  2229
      done
huffman@44133
  2230
    have "?g (x + y) = ?g x + ?g y"
huffman@44133
  2231
      unfolding addh tha
huffman@44133
  2232
      g(1)[rule_format,OF conjunct1[OF h, OF x] conjunct1[OF h, OF y]]
huffman@44133
  2233
      by (simp add: scaleR_left_distrib)}
huffman@44133
  2234
  moreover
wenzelm@53406
  2235
  {
wenzelm@53406
  2236
    fix x :: "'a"
wenzelm@53406
  2237
    fix c :: real
wenzelm@49522
  2238
    assume x: "x \<in> span (insert a b)"
huffman@44133
  2239
    have tha: "\<And>(x::'a) c k a. c *\<^sub>R x - (c * k) *\<^sub>R a = c *\<^sub>R (x - k *\<^sub>R a)"
huffman@44133
  2240
      by (simp add: algebra_simps)
huffman@44133
  2241
    have hc: "?h (c *\<^sub>R x) = c * ?h x"
huffman@44133
  2242
      apply (rule conjunct2[OF h, rule_format, symmetric])
huffman@44133
  2243
      apply (metis span_mul x)
wenzelm@49522
  2244
      apply (metis tha span_mul x conjunct1[OF h])
wenzelm@49522
  2245
      done
huffman@44133
  2246
    have "?g (c *\<^sub>R x) = c*\<^sub>R ?g x"
huffman@44133
  2247
      unfolding hc tha g(2)[rule_format, OF conjunct1[OF h, OF x]]
wenzelm@53406
  2248
      by (simp add: algebra_simps)
wenzelm@53406
  2249
  }
huffman@44133
  2250
  moreover
wenzelm@53406
  2251
  {
wenzelm@53406
  2252
    fix x
wenzelm@53406
  2253
    assume x: "x \<in> insert a b"
wenzelm@53406
  2254
    {
wenzelm@53406
  2255
      assume xa: "x = a"
huffman@44133
  2256
      have ha1: "1 = ?h a"
huffman@44133
  2257
        apply (rule conjunct2[OF h, rule_format])
huffman@44133
  2258
        apply (metis span_superset insertI1)
huffman@44133
  2259
        using conjunct1[OF h, OF span_superset, OF insertI1]
wenzelm@49522
  2260
        apply (auto simp add: span_0)
wenzelm@49522
  2261
        done
huffman@44133
  2262
      from xa ha1[symmetric] have "?g x = f x"
huffman@44133
  2263
        apply simp
huffman@44133
  2264
        using g(2)[rule_format, OF span_0, of 0]
wenzelm@49522
  2265
        apply simp
wenzelm@53406
  2266
        done
wenzelm@53406
  2267
    }
huffman@44133
  2268
    moreover
wenzelm@53406
  2269
    {
wenzelm@53406
  2270
      assume xb: "x \<in> b"
huffman@44133
  2271
      have h0: "0 = ?h x"
huffman@44133
  2272
        apply (rule conjunct2[OF h, rule_format])
huffman@44133
  2273
        apply (metis  span_superset x)
huffman@44133
  2274
        apply simp
huffman@44133
  2275
        apply (metis span_superset xb)
huffman@44133
  2276
        done
huffman@44133
  2277
      have "?g x = f x"
wenzelm@53406
  2278
        by (simp add: h0[symmetric] g(3)[rule_format, OF xb])
wenzelm@53406
  2279
    }
wenzelm@53406
  2280
    ultimately have "?g x = f x"
wenzelm@53406
  2281
      using x by blast
wenzelm@53406
  2282
  }
wenzelm@49663
  2283
  ultimately show ?case
wenzelm@49663
  2284
    apply -
wenzelm@49663
  2285
    apply (rule exI[where x="?g"])
wenzelm@49663
  2286
    apply blast
wenzelm@49663
  2287
    done
huffman@44133
  2288
qed
huffman@44133
  2289
huffman@44133
  2290
lemma linear_independent_extend:
wenzelm@53406
  2291
  fixes B :: "'a::euclidean_space set"
wenzelm@53406
  2292
  assumes iB: "independent B"
huffman@44133
  2293
  shows "\<exists>g. linear g \<and> (\<forall>x\<in>B. g x = f x)"
wenzelm@49522
  2294
proof -
huffman@44133
  2295
  from maximal_independent_subset_extend[of B UNIV] iB
wenzelm@53406
  2296
  obtain C where C: "B \<subseteq> C" "independent C" "\<And>x. x \<in> span C"
wenzelm@53406
  2297
    by auto
huffman@44133
  2298
huffman@44133
  2299
  from C(2) independent_bound[of C] linear_independent_extend_lemma[of C f]
wenzelm@53406
  2300
  obtain g where g:
wenzelm@53406
  2301
    "(\<forall>x\<in> span C. \<forall>y\<in> span C. g (x + y) = g x + g y) \<and>
wenzelm@53406
  2302
     (\<forall>x\<in> span C. \<forall>c. g (c*\<^sub>R x) = c *\<^sub>R g x) \<and>
wenzelm@53406
  2303
     (\<forall>x\<in> C. g x = f x)" by blast
wenzelm@53406
  2304
  from g show ?thesis
huffman@53600
  2305
    unfolding linear_iff
wenzelm@53406
  2306
    using C
wenzelm@49663
  2307
    apply clarsimp
wenzelm@49663
  2308
    apply blast
wenzelm@49663
  2309
    done
huffman@44133
  2310
qed
huffman@44133
  2311
wenzelm@60420
  2312
text \<open>Can construct an isomorphism between spaces of same dimension.\<close>
huffman@44133
  2313
huffman@44133
  2314
lemma subspace_isomorphism:
wenzelm@53406
  2315
  fixes S :: "'a::euclidean_space set"
wenzelm@53406
  2316
    and T :: "'b::euclidean_space set"
wenzelm@53406
  2317
  assumes s: "subspace S"
wenzelm@53406
  2318
    and t: "subspace T"
wenzelm@49522
  2319
    and d: "dim S = dim T"
huffman@44133
  2320
  shows "\<exists>f. linear f \<and> f ` S = T \<and> inj_on f S"
wenzelm@49522
  2321
proof -
wenzelm@53406
  2322
  from basis_exists[of S] independent_bound
wenzelm@53406
  2323
  obtain B where B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S" and fB: "finite B"
wenzelm@53406
  2324
    by blast
wenzelm@53406
  2325
  from basis_exists[of T] independent_bound
wenzelm@53406
  2326
  obtain C where C: "C \<subseteq> T" "independent C" "T \<subseteq> span C" "card C = dim T" and fC: "finite C"
wenzelm@53406
  2327
    by blast
wenzelm@53406
  2328
  from B(4) C(4) card_le_inj[of B C] d
wenzelm@60420
  2329
  obtain f where f: "f ` B \<subseteq> C" "inj_on f B" using \<open>finite B\<close> \<open>finite C\<close>
wenzelm@53406
  2330
    by auto
wenzelm@53406
  2331
  from linear_independent_extend[OF B(2)]
wenzelm@53406
  2332
  obtain g where g: "linear g" "\<forall>x\<in> B. g x = f x"
wenzelm@53406
  2333
    by blast
wenzelm@53406
  2334
  from inj_on_iff_eq_card[OF fB, of f] f(2) have "card (f ` B) = card B"
huffman@44133
  2335
    by simp
wenzelm@53406
  2336
  with B(4) C(4) have ceq: "card (f ` B) = card C"
wenzelm@53406
  2337
    using d by simp
wenzelm@53406
  2338
  have "g ` B = f ` B"
wenzelm@53406
  2339
    using g(2) by (auto simp add: image_iff)
huffman@44133
  2340
  also have "\<dots> = C" using card_subset_eq[OF fC f(1) ceq] .
huffman@44133
  2341
  finally have gBC: "g ` B = C" .
wenzelm@53406
  2342
  have gi: "inj_on g B"
wenzelm@53406
  2343
    using f(2) g(2) by (auto simp add: inj_on_def)
huffman@44133
  2344
  note g0 = linear_indep_image_lemma[OF g(1) fB, unfolded gBC, OF C(2) gi]
wenzelm@53406
  2345
  {
wenzelm@53406
  2346
    fix x y
wenzelm@53406
  2347
    assume x: "x \<in> S" and y: "y \<in> S" and gxy: "g x = g y"
wenzelm@53406
  2348
    from B(3) x y have x': "x \<in> span B" and y': "y \<in> span B"
wenzelm@53406
  2349
      by blast+
wenzelm@53406
  2350
    from gxy have th0: "g (x - y) = 0"
wenzelm@53406
  2351
      by (simp add: linear_sub[OF g(1)])
wenzelm@53406
  2352
    have th1: "x - y \<in> span B"
wenzelm@53406
  2353
      using x' y' by (metis span_sub)
wenzelm@53406
  2354
    have "x = y"
wenzelm@53406
  2355
      using g0[OF th1 th0] by simp
wenzelm@53406
  2356
  }
huffman@44133
  2357
  then have giS: "inj_on g S"
huffman@44133
  2358
    unfolding inj_on_def by blast
wenzelm@53406
  2359
  from span_subspace[OF B(1,3) s] have "g ` S = span (g ` B)"
wenzelm@53406
  2360
    by (simp add: span_linear_image[OF g(1)])
huffman@44133
  2361
  also have "\<dots> = span C" unfolding gBC ..
huffman@44133
  2362
  also have "\<dots> = T" using span_subspace[OF C(1,3) t] .
huffman@44133
  2363
  finally have gS: "g ` S = T" .
wenzelm@53406
  2364
  from g(1) gS giS show ?thesis
wenzelm@53406
  2365
    by blast
huffman@44133
  2366
qed
huffman@44133
  2367
wenzelm@60420
  2368
text \<open>Linear functions are equal on a subspace if they are on a spanning set.\<close>
huffman@44133
  2369
huffman@44133
  2370
lemma subspace_kernel:
huffman@44133
  2371
  assumes lf: "linear f"
huffman@44133
  2372
  shows "subspace {x. f x = 0}"
wenzelm@49522
  2373
  apply (simp add: subspace_def)
wenzelm@49522
  2374
  apply (simp add: linear_add[OF lf] linear_cmul[OF lf] linear_0[OF lf])
wenzelm@49522
  2375
  done
huffman@44133
  2376
huffman@44133
  2377
lemma linear_eq_0_span:
huffman@44133
  2378
  assumes lf: "linear f" and f0: "\<forall>x\<in>B. f x = 0"
huffman@44133
  2379
  shows "\<forall>x \<in> span B. f x = 0"
huffman@44170
  2380
  using f0 subspace_kernel[OF lf]
huffman@44170
  2381
  by (rule span_induct')
huffman@44133
  2382
huffman@44133
  2383
lemma linear_eq_0:
wenzelm@49663
  2384
  assumes lf: "linear f"
wenzelm@49663
  2385
    and SB: "S \<subseteq> span B"
wenzelm@49663
  2386
    and f0: "\<forall>x\<in>B. f x = 0"
huffman@44133
  2387
  shows "\<forall>x \<in> S. f x = 0"
huffman@44133
  2388
  by (metis linear_eq_0_span[OF lf] subset_eq SB f0)
huffman@44133
  2389
huffman@44133
  2390
lemma linear_eq:
wenzelm@49663
  2391
  assumes lf: "linear f"
wenzelm@49663
  2392
    and lg: "linear g"
wenzelm@49663
  2393
    and S: "S \<subseteq> span B"
wenzelm@49522
  2394
    and fg: "\<forall> x\<in> B. f x = g x"
huffman@44133
  2395
  shows "\<forall>x\<in> S. f x = g x"
wenzelm@49663
  2396
proof -
huffman@44133
  2397
  let ?h = "\<lambda>x. f x - g x"
huffman@44133
  2398
  from fg have fg': "\<forall>x\<in> B. ?h x = 0" by simp
huffman@44133
  2399
  from linear_eq_0[OF linear_compose_sub[OF lf lg] S fg']
huffman@44133
  2400
  show ?thesis by simp
huffman@44133
  2401
qed
huffman@44133
  2402
huffman@44133
  2403
lemma linear_eq_stdbasis:
wenzelm@56444
  2404
  fixes f :: "'a::euclidean_space \<Rightarrow> _"
wenzelm@56444
  2405
  assumes lf: "linear f"
wenzelm@49663
  2406
    and lg: "linear g"
hoelzl@50526
  2407
    and fg: "\<forall>b\<in>Basis. f b = g b"
huffman@44133
  2408
  shows "f = g"
hoelzl@50526
  2409
  using linear_eq[OF lf lg, of _ Basis] fg by auto
huffman@44133
  2410
wenzelm@60420
  2411
text \<open>Similar results for bilinear functions.\<close>
huffman@44133
  2412
huffman@44133
  2413
lemma bilinear_eq:
huffman@44133
  2414
  assumes bf: "bilinear f"
wenzelm@49522
  2415
    and bg: "bilinear g"
wenzelm@53406
  2416
    and SB: "S \<subseteq> span B"
wenzelm@53406
  2417
    and TC: "T \<subseteq> span C"
wenzelm@49522
  2418
    and fg: "\<forall>x\<in> B. \<forall>y\<in> C. f x y = g x y"
huffman@44133
  2419
  shows "\<forall>x\<in>S. \<forall>y\<in>T. f x y = g x y "
wenzelm@49663
  2420
proof -
huffman@44170
  2421
  let ?P = "{x. \<forall>y\<in> span C. f x y = g x y}"
huffman@44133
  2422
  from bf bg have sp: "subspace ?P"
huffman@53600
  2423
    unfolding bilinear_def linear_iff subspace_def bf bg
wenzelm@49663
  2424
    by (auto simp add: span_0 bilinear_lzero[OF bf] bilinear_lzero[OF bg] span_add Ball_def
wenzelm@49663
  2425
      intro: bilinear_ladd[OF bf])
huffman@44133
  2426
huffman@44133
  2427
  have "\<forall>x \<in> span B. \<forall>y\<in> span C. f x y = g x y"
huffman@44170
  2428
    apply (rule span_induct' [OF _ sp])
huffman@44133
  2429
    apply (rule ballI)
huffman@44170
  2430
    apply (rule span_induct')
huffman@44170
  2431
    apply (simp add: fg)
huffman@44133
  2432
    apply (auto simp add: subspace_def)
huffman@53600
  2433
    using bf bg unfolding bilinear_def linear_iff
wenzelm@49522
  2434
    apply (auto simp add: span_0 bilinear_rzero[OF bf] bilinear_rzero[OF bg] span_add Ball_def
wenzelm@49663
  2435
      intro: bilinear_ladd[OF bf])
wenzelm@49522
  2436
    done
wenzelm@53406
  2437
  then show ?thesis
wenzelm@53406
  2438
    using SB TC by auto
huffman@44133
  2439
qed
huffman@44133
  2440
wenzelm@49522
  2441
lemma bilinear_eq_stdbasis:
wenzelm@53406
  2442
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space \<Rightarrow> _"
huffman@44133
  2443
  assumes bf: "bilinear f"
wenzelm@49522
  2444
    and bg: "bilinear g"
hoelzl@50526
  2445
    and fg: "\<forall>i\<in>Basis. \<forall>j\<in>Basis. f i j = g i j"
huffman@44133
  2446
  shows "f = g"
hoelzl@50526
  2447
  using bilinear_eq[OF bf bg equalityD2[OF span_Basis] equalityD2[OF span_Basis] fg] by blast