src/HOL/Real_Vector_Spaces.thy
author paulson
Mon Jul 20 23:12:50 2015 +0100 (2015-07-20)
changeset 60762 bf0c76ccee8d
parent 60758 d8d85a8172b5
child 60800 7d04351c795a
permissions -rw-r--r--
new material for multivariate analysis, etc.
hoelzl@51524
     1
(*  Title:      HOL/Real_Vector_Spaces.thy
haftmann@27552
     2
    Author:     Brian Huffman
hoelzl@51531
     3
    Author:     Johannes Hölzl
huffman@20504
     4
*)
huffman@20504
     5
wenzelm@60758
     6
section \<open>Vector Spaces and Algebras over the Reals\<close>
huffman@20504
     7
hoelzl@51524
     8
theory Real_Vector_Spaces
hoelzl@51531
     9
imports Real Topological_Spaces
huffman@20504
    10
begin
huffman@20504
    11
wenzelm@60758
    12
subsection \<open>Locale for additive functions\<close>
huffman@20504
    13
huffman@20504
    14
locale additive =
huffman@20504
    15
  fixes f :: "'a::ab_group_add \<Rightarrow> 'b::ab_group_add"
huffman@20504
    16
  assumes add: "f (x + y) = f x + f y"
huffman@27443
    17
begin
huffman@20504
    18
huffman@27443
    19
lemma zero: "f 0 = 0"
huffman@20504
    20
proof -
huffman@20504
    21
  have "f 0 = f (0 + 0)" by simp
huffman@20504
    22
  also have "\<dots> = f 0 + f 0" by (rule add)
huffman@20504
    23
  finally show "f 0 = 0" by simp
huffman@20504
    24
qed
huffman@20504
    25
huffman@27443
    26
lemma minus: "f (- x) = - f x"
huffman@20504
    27
proof -
huffman@20504
    28
  have "f (- x) + f x = f (- x + x)" by (rule add [symmetric])
huffman@20504
    29
  also have "\<dots> = - f x + f x" by (simp add: zero)
huffman@20504
    30
  finally show "f (- x) = - f x" by (rule add_right_imp_eq)
huffman@20504
    31
qed
huffman@20504
    32
huffman@27443
    33
lemma diff: "f (x - y) = f x - f y"
haftmann@54230
    34
  using add [of x "- y"] by (simp add: minus)
huffman@20504
    35
huffman@27443
    36
lemma setsum: "f (setsum g A) = (\<Sum>x\<in>A. f (g x))"
huffman@22942
    37
apply (cases "finite A")
huffman@22942
    38
apply (induct set: finite)
huffman@22942
    39
apply (simp add: zero)
huffman@22942
    40
apply (simp add: add)
huffman@22942
    41
apply (simp add: zero)
huffman@22942
    42
done
huffman@22942
    43
huffman@27443
    44
end
huffman@20504
    45
wenzelm@60758
    46
subsection \<open>Vector spaces\<close>
huffman@28029
    47
huffman@28029
    48
locale vector_space =
huffman@28029
    49
  fixes scale :: "'a::field \<Rightarrow> 'b::ab_group_add \<Rightarrow> 'b"
huffman@30070
    50
  assumes scale_right_distrib [algebra_simps]:
huffman@30070
    51
    "scale a (x + y) = scale a x + scale a y"
huffman@30070
    52
  and scale_left_distrib [algebra_simps]:
huffman@30070
    53
    "scale (a + b) x = scale a x + scale b x"
huffman@28029
    54
  and scale_scale [simp]: "scale a (scale b x) = scale (a * b) x"
huffman@28029
    55
  and scale_one [simp]: "scale 1 x = x"
huffman@28029
    56
begin
huffman@28029
    57
huffman@28029
    58
lemma scale_left_commute:
huffman@28029
    59
  "scale a (scale b x) = scale b (scale a x)"
haftmann@57512
    60
by (simp add: mult.commute)
huffman@28029
    61
huffman@28029
    62
lemma scale_zero_left [simp]: "scale 0 x = 0"
huffman@28029
    63
  and scale_minus_left [simp]: "scale (- a) x = - (scale a x)"
huffman@30070
    64
  and scale_left_diff_distrib [algebra_simps]:
huffman@30070
    65
        "scale (a - b) x = scale a x - scale b x"
huffman@44282
    66
  and scale_setsum_left: "scale (setsum f A) x = (\<Sum>a\<in>A. scale (f a) x)"
huffman@28029
    67
proof -
ballarin@29229
    68
  interpret s: additive "\<lambda>a. scale a x"
haftmann@28823
    69
    proof qed (rule scale_left_distrib)
huffman@28029
    70
  show "scale 0 x = 0" by (rule s.zero)
huffman@28029
    71
  show "scale (- a) x = - (scale a x)" by (rule s.minus)
huffman@28029
    72
  show "scale (a - b) x = scale a x - scale b x" by (rule s.diff)
huffman@44282
    73
  show "scale (setsum f A) x = (\<Sum>a\<in>A. scale (f a) x)" by (rule s.setsum)
huffman@28029
    74
qed
huffman@28029
    75
huffman@28029
    76
lemma scale_zero_right [simp]: "scale a 0 = 0"
huffman@28029
    77
  and scale_minus_right [simp]: "scale a (- x) = - (scale a x)"
huffman@30070
    78
  and scale_right_diff_distrib [algebra_simps]:
huffman@30070
    79
        "scale a (x - y) = scale a x - scale a y"
huffman@44282
    80
  and scale_setsum_right: "scale a (setsum f A) = (\<Sum>x\<in>A. scale a (f x))"
huffman@28029
    81
proof -
ballarin@29229
    82
  interpret s: additive "\<lambda>x. scale a x"
haftmann@28823
    83
    proof qed (rule scale_right_distrib)
huffman@28029
    84
  show "scale a 0 = 0" by (rule s.zero)
huffman@28029
    85
  show "scale a (- x) = - (scale a x)" by (rule s.minus)
huffman@28029
    86
  show "scale a (x - y) = scale a x - scale a y" by (rule s.diff)
huffman@44282
    87
  show "scale a (setsum f A) = (\<Sum>x\<in>A. scale a (f x))" by (rule s.setsum)
huffman@28029
    88
qed
huffman@28029
    89
huffman@28029
    90
lemma scale_eq_0_iff [simp]:
huffman@28029
    91
  "scale a x = 0 \<longleftrightarrow> a = 0 \<or> x = 0"
huffman@28029
    92
proof cases
huffman@28029
    93
  assume "a = 0" thus ?thesis by simp
huffman@28029
    94
next
huffman@28029
    95
  assume anz [simp]: "a \<noteq> 0"
huffman@28029
    96
  { assume "scale a x = 0"
huffman@28029
    97
    hence "scale (inverse a) (scale a x) = 0" by simp
huffman@28029
    98
    hence "x = 0" by simp }
huffman@28029
    99
  thus ?thesis by force
huffman@28029
   100
qed
huffman@28029
   101
huffman@28029
   102
lemma scale_left_imp_eq:
huffman@28029
   103
  "\<lbrakk>a \<noteq> 0; scale a x = scale a y\<rbrakk> \<Longrightarrow> x = y"
huffman@28029
   104
proof -
huffman@28029
   105
  assume nonzero: "a \<noteq> 0"
huffman@28029
   106
  assume "scale a x = scale a y"
huffman@28029
   107
  hence "scale a (x - y) = 0"
huffman@28029
   108
     by (simp add: scale_right_diff_distrib)
huffman@28029
   109
  hence "x - y = 0" by (simp add: nonzero)
huffman@28029
   110
  thus "x = y" by (simp only: right_minus_eq)
huffman@28029
   111
qed
huffman@28029
   112
huffman@28029
   113
lemma scale_right_imp_eq:
huffman@28029
   114
  "\<lbrakk>x \<noteq> 0; scale a x = scale b x\<rbrakk> \<Longrightarrow> a = b"
huffman@28029
   115
proof -
huffman@28029
   116
  assume nonzero: "x \<noteq> 0"
huffman@28029
   117
  assume "scale a x = scale b x"
huffman@28029
   118
  hence "scale (a - b) x = 0"
huffman@28029
   119
     by (simp add: scale_left_diff_distrib)
huffman@28029
   120
  hence "a - b = 0" by (simp add: nonzero)
huffman@28029
   121
  thus "a = b" by (simp only: right_minus_eq)
huffman@28029
   122
qed
huffman@28029
   123
huffman@31586
   124
lemma scale_cancel_left [simp]:
huffman@28029
   125
  "scale a x = scale a y \<longleftrightarrow> x = y \<or> a = 0"
huffman@28029
   126
by (auto intro: scale_left_imp_eq)
huffman@28029
   127
huffman@31586
   128
lemma scale_cancel_right [simp]:
huffman@28029
   129
  "scale a x = scale b x \<longleftrightarrow> a = b \<or> x = 0"
huffman@28029
   130
by (auto intro: scale_right_imp_eq)
huffman@28029
   131
huffman@28029
   132
end
huffman@28029
   133
wenzelm@60758
   134
subsection \<open>Real vector spaces\<close>
huffman@20504
   135
haftmann@29608
   136
class scaleR =
haftmann@25062
   137
  fixes scaleR :: "real \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "*\<^sub>R" 75)
haftmann@24748
   138
begin
huffman@20504
   139
huffman@20763
   140
abbreviation
haftmann@25062
   141
  divideR :: "'a \<Rightarrow> real \<Rightarrow> 'a" (infixl "'/\<^sub>R" 70)
haftmann@24748
   142
where
haftmann@25062
   143
  "x /\<^sub>R r == scaleR (inverse r) x"
haftmann@24748
   144
haftmann@24748
   145
end
haftmann@24748
   146
haftmann@24588
   147
class real_vector = scaleR + ab_group_add +
huffman@44282
   148
  assumes scaleR_add_right: "scaleR a (x + y) = scaleR a x + scaleR a y"
huffman@44282
   149
  and scaleR_add_left: "scaleR (a + b) x = scaleR a x + scaleR b x"
huffman@30070
   150
  and scaleR_scaleR: "scaleR a (scaleR b x) = scaleR (a * b) x"
huffman@30070
   151
  and scaleR_one: "scaleR 1 x = x"
huffman@20504
   152
wenzelm@30729
   153
interpretation real_vector:
ballarin@29229
   154
  vector_space "scaleR :: real \<Rightarrow> 'a \<Rightarrow> 'a::real_vector"
huffman@28009
   155
apply unfold_locales
huffman@44282
   156
apply (rule scaleR_add_right)
huffman@44282
   157
apply (rule scaleR_add_left)
huffman@28009
   158
apply (rule scaleR_scaleR)
huffman@28009
   159
apply (rule scaleR_one)
huffman@28009
   160
done
huffman@28009
   161
wenzelm@60758
   162
text \<open>Recover original theorem names\<close>
huffman@28009
   163
huffman@28009
   164
lemmas scaleR_left_commute = real_vector.scale_left_commute
huffman@28009
   165
lemmas scaleR_zero_left = real_vector.scale_zero_left
huffman@28009
   166
lemmas scaleR_minus_left = real_vector.scale_minus_left
huffman@44282
   167
lemmas scaleR_diff_left = real_vector.scale_left_diff_distrib
huffman@44282
   168
lemmas scaleR_setsum_left = real_vector.scale_setsum_left
huffman@28009
   169
lemmas scaleR_zero_right = real_vector.scale_zero_right
huffman@28009
   170
lemmas scaleR_minus_right = real_vector.scale_minus_right
huffman@44282
   171
lemmas scaleR_diff_right = real_vector.scale_right_diff_distrib
huffman@44282
   172
lemmas scaleR_setsum_right = real_vector.scale_setsum_right
huffman@28009
   173
lemmas scaleR_eq_0_iff = real_vector.scale_eq_0_iff
huffman@28009
   174
lemmas scaleR_left_imp_eq = real_vector.scale_left_imp_eq
huffman@28009
   175
lemmas scaleR_right_imp_eq = real_vector.scale_right_imp_eq
huffman@28009
   176
lemmas scaleR_cancel_left = real_vector.scale_cancel_left
huffman@28009
   177
lemmas scaleR_cancel_right = real_vector.scale_cancel_right
huffman@28009
   178
wenzelm@60758
   179
text \<open>Legacy names\<close>
huffman@44282
   180
huffman@44282
   181
lemmas scaleR_left_distrib = scaleR_add_left
huffman@44282
   182
lemmas scaleR_right_distrib = scaleR_add_right
huffman@44282
   183
lemmas scaleR_left_diff_distrib = scaleR_diff_left
huffman@44282
   184
lemmas scaleR_right_diff_distrib = scaleR_diff_right
huffman@44282
   185
huffman@31285
   186
lemma scaleR_minus1_left [simp]:
huffman@31285
   187
  fixes x :: "'a::real_vector"
huffman@31285
   188
  shows "scaleR (-1) x = - x"
huffman@31285
   189
  using scaleR_minus_left [of 1 x] by simp
huffman@31285
   190
haftmann@24588
   191
class real_algebra = real_vector + ring +
haftmann@25062
   192
  assumes mult_scaleR_left [simp]: "scaleR a x * y = scaleR a (x * y)"
haftmann@25062
   193
  and mult_scaleR_right [simp]: "x * scaleR a y = scaleR a (x * y)"
huffman@20504
   194
haftmann@24588
   195
class real_algebra_1 = real_algebra + ring_1
huffman@20554
   196
haftmann@24588
   197
class real_div_algebra = real_algebra_1 + division_ring
huffman@20584
   198
haftmann@24588
   199
class real_field = real_div_algebra + field
huffman@20584
   200
huffman@30069
   201
instantiation real :: real_field
huffman@30069
   202
begin
huffman@30069
   203
huffman@30069
   204
definition
huffman@30069
   205
  real_scaleR_def [simp]: "scaleR a x = a * x"
huffman@30069
   206
huffman@30070
   207
instance proof
huffman@30070
   208
qed (simp_all add: algebra_simps)
huffman@20554
   209
huffman@30069
   210
end
huffman@30069
   211
wenzelm@30729
   212
interpretation scaleR_left: additive "(\<lambda>a. scaleR a x::'a::real_vector)"
haftmann@28823
   213
proof qed (rule scaleR_left_distrib)
huffman@20504
   214
wenzelm@30729
   215
interpretation scaleR_right: additive "(\<lambda>x. scaleR a x::'a::real_vector)"
haftmann@28823
   216
proof qed (rule scaleR_right_distrib)
huffman@20504
   217
huffman@20584
   218
lemma nonzero_inverse_scaleR_distrib:
huffman@21809
   219
  fixes x :: "'a::real_div_algebra" shows
huffman@21809
   220
  "\<lbrakk>a \<noteq> 0; x \<noteq> 0\<rbrakk> \<Longrightarrow> inverse (scaleR a x) = scaleR (inverse a) (inverse x)"
huffman@20763
   221
by (rule inverse_unique, simp)
huffman@20584
   222
huffman@20584
   223
lemma inverse_scaleR_distrib:
haftmann@59867
   224
  fixes x :: "'a::{real_div_algebra, division_ring}"
huffman@21809
   225
  shows "inverse (scaleR a x) = scaleR (inverse a) (inverse x)"
huffman@20584
   226
apply (case_tac "a = 0", simp)
huffman@20584
   227
apply (case_tac "x = 0", simp)
huffman@20584
   228
apply (erule (1) nonzero_inverse_scaleR_distrib)
huffman@20584
   229
done
huffman@20584
   230
huffman@20554
   231
wenzelm@60758
   232
subsection \<open>Embedding of the Reals into any @{text real_algebra_1}:
wenzelm@60758
   233
@{term of_real}\<close>
huffman@20554
   234
huffman@20554
   235
definition
wenzelm@21404
   236
  of_real :: "real \<Rightarrow> 'a::real_algebra_1" where
huffman@21809
   237
  "of_real r = scaleR r 1"
huffman@20554
   238
huffman@21809
   239
lemma scaleR_conv_of_real: "scaleR r x = of_real r * x"
huffman@20763
   240
by (simp add: of_real_def)
huffman@20763
   241
huffman@20554
   242
lemma of_real_0 [simp]: "of_real 0 = 0"
huffman@20554
   243
by (simp add: of_real_def)
huffman@20554
   244
huffman@20554
   245
lemma of_real_1 [simp]: "of_real 1 = 1"
huffman@20554
   246
by (simp add: of_real_def)
huffman@20554
   247
huffman@20554
   248
lemma of_real_add [simp]: "of_real (x + y) = of_real x + of_real y"
huffman@20554
   249
by (simp add: of_real_def scaleR_left_distrib)
huffman@20554
   250
huffman@20554
   251
lemma of_real_minus [simp]: "of_real (- x) = - of_real x"
huffman@20554
   252
by (simp add: of_real_def)
huffman@20554
   253
huffman@20554
   254
lemma of_real_diff [simp]: "of_real (x - y) = of_real x - of_real y"
huffman@20554
   255
by (simp add: of_real_def scaleR_left_diff_distrib)
huffman@20554
   256
huffman@20554
   257
lemma of_real_mult [simp]: "of_real (x * y) = of_real x * of_real y"
haftmann@57512
   258
by (simp add: of_real_def mult.commute)
huffman@20554
   259
hoelzl@56889
   260
lemma of_real_setsum[simp]: "of_real (setsum f s) = (\<Sum>x\<in>s. of_real (f x))"
hoelzl@56889
   261
  by (induct s rule: infinite_finite_induct) auto
hoelzl@56889
   262
hoelzl@56889
   263
lemma of_real_setprod[simp]: "of_real (setprod f s) = (\<Prod>x\<in>s. of_real (f x))"
hoelzl@56889
   264
  by (induct s rule: infinite_finite_induct) auto
hoelzl@56889
   265
huffman@20584
   266
lemma nonzero_of_real_inverse:
huffman@20584
   267
  "x \<noteq> 0 \<Longrightarrow> of_real (inverse x) =
huffman@20584
   268
   inverse (of_real x :: 'a::real_div_algebra)"
huffman@20584
   269
by (simp add: of_real_def nonzero_inverse_scaleR_distrib)
huffman@20584
   270
huffman@20584
   271
lemma of_real_inverse [simp]:
huffman@20584
   272
  "of_real (inverse x) =
haftmann@59867
   273
   inverse (of_real x :: 'a::{real_div_algebra, division_ring})"
huffman@20584
   274
by (simp add: of_real_def inverse_scaleR_distrib)
huffman@20584
   275
huffman@20584
   276
lemma nonzero_of_real_divide:
huffman@20584
   277
  "y \<noteq> 0 \<Longrightarrow> of_real (x / y) =
huffman@20584
   278
   (of_real x / of_real y :: 'a::real_field)"
huffman@20584
   279
by (simp add: divide_inverse nonzero_of_real_inverse)
huffman@20722
   280
huffman@20722
   281
lemma of_real_divide [simp]:
huffman@20584
   282
  "of_real (x / y) =
haftmann@59867
   283
   (of_real x / of_real y :: 'a::{real_field, field})"
huffman@20584
   284
by (simp add: divide_inverse)
huffman@20584
   285
huffman@20722
   286
lemma of_real_power [simp]:
haftmann@31017
   287
  "of_real (x ^ n) = (of_real x :: 'a::{real_algebra_1}) ^ n"
huffman@30273
   288
by (induct n) simp_all
huffman@20722
   289
huffman@20554
   290
lemma of_real_eq_iff [simp]: "(of_real x = of_real y) = (x = y)"
huffman@35216
   291
by (simp add: of_real_def)
huffman@20554
   292
haftmann@38621
   293
lemma inj_of_real:
haftmann@38621
   294
  "inj of_real"
haftmann@38621
   295
  by (auto intro: injI)
haftmann@38621
   296
huffman@20584
   297
lemmas of_real_eq_0_iff [simp] = of_real_eq_iff [of _ 0, simplified]
huffman@20554
   298
huffman@20554
   299
lemma of_real_eq_id [simp]: "of_real = (id :: real \<Rightarrow> real)"
huffman@20554
   300
proof
huffman@20554
   301
  fix r
huffman@20554
   302
  show "of_real r = id r"
huffman@22973
   303
    by (simp add: of_real_def)
huffman@20554
   304
qed
huffman@20554
   305
wenzelm@60758
   306
text\<open>Collapse nested embeddings\<close>
huffman@20554
   307
lemma of_real_of_nat_eq [simp]: "of_real (of_nat n) = of_nat n"
wenzelm@20772
   308
by (induct n) auto
huffman@20554
   309
huffman@20554
   310
lemma of_real_of_int_eq [simp]: "of_real (of_int z) = of_int z"
huffman@20554
   311
by (cases z rule: int_diff_cases, simp)
huffman@20554
   312
hoelzl@56889
   313
lemma of_real_real_of_nat_eq [simp]: "of_real (real n) = of_nat n"
hoelzl@56889
   314
  by (simp add: real_of_nat_def)
hoelzl@56889
   315
hoelzl@56889
   316
lemma of_real_real_of_int_eq [simp]: "of_real (real z) = of_int z"
hoelzl@56889
   317
  by (simp add: real_of_int_def)
hoelzl@56889
   318
lp15@60155
   319
lemma of_real_numeral [simp]: "of_real (numeral w) = numeral w"
huffman@47108
   320
using of_real_of_int_eq [of "numeral w"] by simp
huffman@47108
   321
lp15@60155
   322
lemma of_real_neg_numeral [simp]: "of_real (- numeral w) = - numeral w"
haftmann@54489
   323
using of_real_of_int_eq [of "- numeral w"] by simp
huffman@20554
   324
wenzelm@60758
   325
text\<open>Every real algebra has characteristic zero\<close>
haftmann@38621
   326
huffman@22912
   327
instance real_algebra_1 < ring_char_0
huffman@22912
   328
proof
haftmann@38621
   329
  from inj_of_real inj_of_nat have "inj (of_real \<circ> of_nat)" by (rule inj_comp)
haftmann@38621
   330
  then show "inj (of_nat :: nat \<Rightarrow> 'a)" by (simp add: comp_def)
huffman@22912
   331
qed
huffman@22912
   332
huffman@27553
   333
instance real_field < field_char_0 ..
huffman@27553
   334
huffman@20554
   335
wenzelm@60758
   336
subsection \<open>The Set of Real Numbers\<close>
huffman@20554
   337
haftmann@37767
   338
definition Reals :: "'a::real_algebra_1 set" where
haftmann@37767
   339
  "Reals = range of_real"
huffman@20554
   340
wenzelm@21210
   341
notation (xsymbols)
huffman@20554
   342
  Reals  ("\<real>")
huffman@20554
   343
huffman@21809
   344
lemma Reals_of_real [simp]: "of_real r \<in> Reals"
huffman@20554
   345
by (simp add: Reals_def)
huffman@20554
   346
huffman@21809
   347
lemma Reals_of_int [simp]: "of_int z \<in> Reals"
huffman@21809
   348
by (subst of_real_of_int_eq [symmetric], rule Reals_of_real)
huffman@20718
   349
huffman@21809
   350
lemma Reals_of_nat [simp]: "of_nat n \<in> Reals"
huffman@21809
   351
by (subst of_real_of_nat_eq [symmetric], rule Reals_of_real)
huffman@21809
   352
huffman@47108
   353
lemma Reals_numeral [simp]: "numeral w \<in> Reals"
huffman@47108
   354
by (subst of_real_numeral [symmetric], rule Reals_of_real)
huffman@47108
   355
huffman@20554
   356
lemma Reals_0 [simp]: "0 \<in> Reals"
huffman@20554
   357
apply (unfold Reals_def)
huffman@20554
   358
apply (rule range_eqI)
huffman@20554
   359
apply (rule of_real_0 [symmetric])
huffman@20554
   360
done
huffman@20554
   361
huffman@20554
   362
lemma Reals_1 [simp]: "1 \<in> Reals"
huffman@20554
   363
apply (unfold Reals_def)
huffman@20554
   364
apply (rule range_eqI)
huffman@20554
   365
apply (rule of_real_1 [symmetric])
huffman@20554
   366
done
huffman@20554
   367
huffman@20584
   368
lemma Reals_add [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a + b \<in> Reals"
huffman@20554
   369
apply (auto simp add: Reals_def)
huffman@20554
   370
apply (rule range_eqI)
huffman@20554
   371
apply (rule of_real_add [symmetric])
huffman@20554
   372
done
huffman@20554
   373
huffman@20584
   374
lemma Reals_minus [simp]: "a \<in> Reals \<Longrightarrow> - a \<in> Reals"
huffman@20584
   375
apply (auto simp add: Reals_def)
huffman@20584
   376
apply (rule range_eqI)
huffman@20584
   377
apply (rule of_real_minus [symmetric])
huffman@20584
   378
done
huffman@20584
   379
huffman@20584
   380
lemma Reals_diff [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a - b \<in> Reals"
huffman@20584
   381
apply (auto simp add: Reals_def)
huffman@20584
   382
apply (rule range_eqI)
huffman@20584
   383
apply (rule of_real_diff [symmetric])
huffman@20584
   384
done
huffman@20584
   385
huffman@20584
   386
lemma Reals_mult [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a * b \<in> Reals"
huffman@20554
   387
apply (auto simp add: Reals_def)
huffman@20554
   388
apply (rule range_eqI)
huffman@20554
   389
apply (rule of_real_mult [symmetric])
huffman@20554
   390
done
huffman@20554
   391
huffman@20584
   392
lemma nonzero_Reals_inverse:
huffman@20584
   393
  fixes a :: "'a::real_div_algebra"
huffman@20584
   394
  shows "\<lbrakk>a \<in> Reals; a \<noteq> 0\<rbrakk> \<Longrightarrow> inverse a \<in> Reals"
huffman@20584
   395
apply (auto simp add: Reals_def)
huffman@20584
   396
apply (rule range_eqI)
huffman@20584
   397
apply (erule nonzero_of_real_inverse [symmetric])
huffman@20584
   398
done
huffman@20584
   399
lp15@55719
   400
lemma Reals_inverse:
haftmann@59867
   401
  fixes a :: "'a::{real_div_algebra, division_ring}"
huffman@20584
   402
  shows "a \<in> Reals \<Longrightarrow> inverse a \<in> Reals"
huffman@20584
   403
apply (auto simp add: Reals_def)
huffman@20584
   404
apply (rule range_eqI)
huffman@20584
   405
apply (rule of_real_inverse [symmetric])
huffman@20584
   406
done
huffman@20584
   407
lp15@60026
   408
lemma Reals_inverse_iff [simp]:
haftmann@59867
   409
  fixes x:: "'a :: {real_div_algebra, division_ring}"
lp15@55719
   410
  shows "inverse x \<in> \<real> \<longleftrightarrow> x \<in> \<real>"
lp15@55719
   411
by (metis Reals_inverse inverse_inverse_eq)
lp15@55719
   412
huffman@20584
   413
lemma nonzero_Reals_divide:
huffman@20584
   414
  fixes a b :: "'a::real_field"
huffman@20584
   415
  shows "\<lbrakk>a \<in> Reals; b \<in> Reals; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584
   416
apply (auto simp add: Reals_def)
huffman@20584
   417
apply (rule range_eqI)
huffman@20584
   418
apply (erule nonzero_of_real_divide [symmetric])
huffman@20584
   419
done
huffman@20584
   420
huffman@20584
   421
lemma Reals_divide [simp]:
haftmann@59867
   422
  fixes a b :: "'a::{real_field, field}"
huffman@20584
   423
  shows "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584
   424
apply (auto simp add: Reals_def)
huffman@20584
   425
apply (rule range_eqI)
huffman@20584
   426
apply (rule of_real_divide [symmetric])
huffman@20584
   427
done
huffman@20584
   428
huffman@20722
   429
lemma Reals_power [simp]:
haftmann@31017
   430
  fixes a :: "'a::{real_algebra_1}"
huffman@20722
   431
  shows "a \<in> Reals \<Longrightarrow> a ^ n \<in> Reals"
huffman@20722
   432
apply (auto simp add: Reals_def)
huffman@20722
   433
apply (rule range_eqI)
huffman@20722
   434
apply (rule of_real_power [symmetric])
huffman@20722
   435
done
huffman@20722
   436
huffman@20554
   437
lemma Reals_cases [cases set: Reals]:
huffman@20554
   438
  assumes "q \<in> \<real>"
huffman@20554
   439
  obtains (of_real) r where "q = of_real r"
huffman@20554
   440
  unfolding Reals_def
huffman@20554
   441
proof -
wenzelm@60758
   442
  from \<open>q \<in> \<real>\<close> have "q \<in> range of_real" unfolding Reals_def .
huffman@20554
   443
  then obtain r where "q = of_real r" ..
huffman@20554
   444
  then show thesis ..
huffman@20554
   445
qed
huffman@20554
   446
lp15@59741
   447
lemma setsum_in_Reals [intro,simp]:
lp15@59741
   448
  assumes "\<And>i. i \<in> s \<Longrightarrow> f i \<in> \<real>" shows "setsum f s \<in> \<real>"
lp15@55719
   449
proof (cases "finite s")
lp15@55719
   450
  case True then show ?thesis using assms
lp15@55719
   451
    by (induct s rule: finite_induct) auto
lp15@55719
   452
next
lp15@55719
   453
  case False then show ?thesis using assms
haftmann@57418
   454
    by (metis Reals_0 setsum.infinite)
lp15@55719
   455
qed
lp15@55719
   456
lp15@60026
   457
lemma setprod_in_Reals [intro,simp]:
lp15@59741
   458
  assumes "\<And>i. i \<in> s \<Longrightarrow> f i \<in> \<real>" shows "setprod f s \<in> \<real>"
lp15@55719
   459
proof (cases "finite s")
lp15@55719
   460
  case True then show ?thesis using assms
lp15@55719
   461
    by (induct s rule: finite_induct) auto
lp15@55719
   462
next
lp15@55719
   463
  case False then show ?thesis using assms
haftmann@57418
   464
    by (metis Reals_1 setprod.infinite)
lp15@55719
   465
qed
lp15@55719
   466
huffman@20554
   467
lemma Reals_induct [case_names of_real, induct set: Reals]:
huffman@20554
   468
  "q \<in> \<real> \<Longrightarrow> (\<And>r. P (of_real r)) \<Longrightarrow> P q"
huffman@20554
   469
  by (rule Reals_cases) auto
huffman@20554
   470
wenzelm@60758
   471
subsection \<open>Ordered real vector spaces\<close>
immler@54778
   472
immler@54778
   473
class ordered_real_vector = real_vector + ordered_ab_group_add +
immler@54778
   474
  assumes scaleR_left_mono: "x \<le> y \<Longrightarrow> 0 \<le> a \<Longrightarrow> a *\<^sub>R x \<le> a *\<^sub>R y"
immler@54778
   475
  assumes scaleR_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> x \<Longrightarrow> a *\<^sub>R x \<le> b *\<^sub>R x"
immler@54778
   476
begin
immler@54778
   477
immler@54778
   478
lemma scaleR_mono:
immler@54778
   479
  "a \<le> b \<Longrightarrow> x \<le> y \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> x \<Longrightarrow> a *\<^sub>R x \<le> b *\<^sub>R y"
immler@54778
   480
apply (erule scaleR_right_mono [THEN order_trans], assumption)
immler@54778
   481
apply (erule scaleR_left_mono, assumption)
immler@54778
   482
done
immler@54778
   483
immler@54778
   484
lemma scaleR_mono':
immler@54778
   485
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> a \<Longrightarrow> 0 \<le> c \<Longrightarrow> a *\<^sub>R c \<le> b *\<^sub>R d"
immler@54778
   486
  by (rule scaleR_mono) (auto intro: order.trans)
immler@54778
   487
immler@54785
   488
lemma pos_le_divideRI:
immler@54785
   489
  assumes "0 < c"
immler@54785
   490
  assumes "c *\<^sub>R a \<le> b"
immler@54785
   491
  shows "a \<le> b /\<^sub>R c"
immler@54785
   492
proof -
immler@54785
   493
  from scaleR_left_mono[OF assms(2)] assms(1)
immler@54785
   494
  have "c *\<^sub>R a /\<^sub>R c \<le> b /\<^sub>R c"
immler@54785
   495
    by simp
immler@54785
   496
  with assms show ?thesis
immler@54785
   497
    by (simp add: scaleR_one scaleR_scaleR inverse_eq_divide)
immler@54785
   498
qed
immler@54785
   499
immler@54785
   500
lemma pos_le_divideR_eq:
immler@54785
   501
  assumes "0 < c"
immler@54785
   502
  shows "a \<le> b /\<^sub>R c \<longleftrightarrow> c *\<^sub>R a \<le> b"
immler@54785
   503
proof rule
immler@54785
   504
  assume "a \<le> b /\<^sub>R c"
immler@54785
   505
  from scaleR_left_mono[OF this] assms
immler@54785
   506
  have "c *\<^sub>R a \<le> c *\<^sub>R (b /\<^sub>R c)"
immler@54785
   507
    by simp
immler@54785
   508
  with assms show "c *\<^sub>R a \<le> b"
immler@54785
   509
    by (simp add: scaleR_one scaleR_scaleR inverse_eq_divide)
immler@54785
   510
qed (rule pos_le_divideRI[OF assms])
immler@54785
   511
immler@54785
   512
lemma scaleR_image_atLeastAtMost:
immler@54785
   513
  "c > 0 \<Longrightarrow> scaleR c ` {x..y} = {c *\<^sub>R x..c *\<^sub>R y}"
immler@54785
   514
  apply (auto intro!: scaleR_left_mono)
immler@54785
   515
  apply (rule_tac x = "inverse c *\<^sub>R xa" in image_eqI)
immler@54785
   516
  apply (simp_all add: pos_le_divideR_eq[symmetric] scaleR_scaleR scaleR_one)
immler@54785
   517
  done
immler@54785
   518
immler@54778
   519
end
immler@54778
   520
paulson@60303
   521
lemma neg_le_divideR_eq:
paulson@60303
   522
  fixes a :: "'a :: ordered_real_vector"
paulson@60303
   523
  assumes "c < 0"
paulson@60303
   524
  shows "a \<le> b /\<^sub>R c \<longleftrightarrow> b \<le> c *\<^sub>R a"
paulson@60303
   525
  using pos_le_divideR_eq [of "-c" a "-b"] assms
paulson@60303
   526
  by simp
paulson@60303
   527
immler@54778
   528
lemma scaleR_nonneg_nonneg: "0 \<le> a \<Longrightarrow> 0 \<le> (x::'a::ordered_real_vector) \<Longrightarrow> 0 \<le> a *\<^sub>R x"
immler@54778
   529
  using scaleR_left_mono [of 0 x a]
immler@54778
   530
  by simp
immler@54778
   531
immler@54778
   532
lemma scaleR_nonneg_nonpos: "0 \<le> a \<Longrightarrow> (x::'a::ordered_real_vector) \<le> 0 \<Longrightarrow> a *\<^sub>R x \<le> 0"
immler@54778
   533
  using scaleR_left_mono [of x 0 a] by simp
immler@54778
   534
immler@54778
   535
lemma scaleR_nonpos_nonneg: "a \<le> 0 \<Longrightarrow> 0 \<le> (x::'a::ordered_real_vector) \<Longrightarrow> a *\<^sub>R x \<le> 0"
immler@54778
   536
  using scaleR_right_mono [of a 0 x] by simp
immler@54778
   537
immler@54778
   538
lemma split_scaleR_neg_le: "(0 \<le> a & x \<le> 0) | (a \<le> 0 & 0 \<le> x) \<Longrightarrow>
immler@54778
   539
  a *\<^sub>R (x::'a::ordered_real_vector) \<le> 0"
immler@54778
   540
  by (auto simp add: scaleR_nonneg_nonpos scaleR_nonpos_nonneg)
immler@54778
   541
immler@54778
   542
lemma le_add_iff1:
immler@54778
   543
  fixes c d e::"'a::ordered_real_vector"
immler@54778
   544
  shows "a *\<^sub>R e + c \<le> b *\<^sub>R e + d \<longleftrightarrow> (a - b) *\<^sub>R e + c \<le> d"
immler@54778
   545
  by (simp add: algebra_simps)
immler@54778
   546
immler@54778
   547
lemma le_add_iff2:
immler@54778
   548
  fixes c d e::"'a::ordered_real_vector"
immler@54778
   549
  shows "a *\<^sub>R e + c \<le> b *\<^sub>R e + d \<longleftrightarrow> c \<le> (b - a) *\<^sub>R e + d"
immler@54778
   550
  by (simp add: algebra_simps)
immler@54778
   551
immler@54778
   552
lemma scaleR_left_mono_neg:
immler@54778
   553
  fixes a b::"'a::ordered_real_vector"
immler@54778
   554
  shows "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> c *\<^sub>R a \<le> c *\<^sub>R b"
immler@54778
   555
  apply (drule scaleR_left_mono [of _ _ "- c"])
immler@54778
   556
  apply simp_all
immler@54778
   557
  done
immler@54778
   558
immler@54778
   559
lemma scaleR_right_mono_neg:
immler@54778
   560
  fixes c::"'a::ordered_real_vector"
immler@54778
   561
  shows "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> a *\<^sub>R c \<le> b *\<^sub>R c"
immler@54778
   562
  apply (drule scaleR_right_mono [of _ _ "- c"])
immler@54778
   563
  apply simp_all
immler@54778
   564
  done
immler@54778
   565
immler@54778
   566
lemma scaleR_nonpos_nonpos: "a \<le> 0 \<Longrightarrow> (b::'a::ordered_real_vector) \<le> 0 \<Longrightarrow> 0 \<le> a *\<^sub>R b"
immler@54778
   567
using scaleR_right_mono_neg [of a 0 b] by simp
immler@54778
   568
immler@54778
   569
lemma split_scaleR_pos_le:
immler@54778
   570
  fixes b::"'a::ordered_real_vector"
immler@54778
   571
  shows "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a *\<^sub>R b"
immler@54778
   572
  by (auto simp add: scaleR_nonneg_nonneg scaleR_nonpos_nonpos)
immler@54778
   573
immler@54778
   574
lemma zero_le_scaleR_iff:
immler@54778
   575
  fixes b::"'a::ordered_real_vector"
immler@54778
   576
  shows "0 \<le> a *\<^sub>R b \<longleftrightarrow> 0 < a \<and> 0 \<le> b \<or> a < 0 \<and> b \<le> 0 \<or> a = 0" (is "?lhs = ?rhs")
immler@54778
   577
proof cases
immler@54778
   578
  assume "a \<noteq> 0"
immler@54778
   579
  show ?thesis
immler@54778
   580
  proof
immler@54778
   581
    assume lhs: ?lhs
immler@54778
   582
    {
immler@54778
   583
      assume "0 < a"
immler@54778
   584
      with lhs have "inverse a *\<^sub>R 0 \<le> inverse a *\<^sub>R (a *\<^sub>R b)"
immler@54778
   585
        by (intro scaleR_mono) auto
wenzelm@60758
   586
      hence ?rhs using \<open>0 < a\<close>
immler@54778
   587
        by simp
immler@54778
   588
    } moreover {
immler@54778
   589
      assume "0 > a"
immler@54778
   590
      with lhs have "- inverse a *\<^sub>R 0 \<le> - inverse a *\<^sub>R (a *\<^sub>R b)"
immler@54778
   591
        by (intro scaleR_mono) auto
wenzelm@60758
   592
      hence ?rhs using \<open>0 > a\<close>
immler@54778
   593
        by simp
wenzelm@60758
   594
    } ultimately show ?rhs using \<open>a \<noteq> 0\<close> by arith
wenzelm@60758
   595
  qed (auto simp: not_le \<open>a \<noteq> 0\<close> intro!: split_scaleR_pos_le)
immler@54778
   596
qed simp
immler@54778
   597
immler@54778
   598
lemma scaleR_le_0_iff:
immler@54778
   599
  fixes b::"'a::ordered_real_vector"
immler@54778
   600
  shows "a *\<^sub>R b \<le> 0 \<longleftrightarrow> 0 < a \<and> b \<le> 0 \<or> a < 0 \<and> 0 \<le> b \<or> a = 0"
immler@54778
   601
  by (insert zero_le_scaleR_iff [of "-a" b]) force
immler@54778
   602
immler@54778
   603
lemma scaleR_le_cancel_left:
immler@54778
   604
  fixes b::"'a::ordered_real_vector"
immler@54778
   605
  shows "c *\<^sub>R a \<le> c *\<^sub>R b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
immler@54778
   606
  by (auto simp add: neq_iff scaleR_left_mono scaleR_left_mono_neg
immler@54778
   607
    dest: scaleR_left_mono[where a="inverse c"] scaleR_left_mono_neg[where c="inverse c"])
immler@54778
   608
immler@54778
   609
lemma scaleR_le_cancel_left_pos:
immler@54778
   610
  fixes b::"'a::ordered_real_vector"
immler@54778
   611
  shows "0 < c \<Longrightarrow> c *\<^sub>R a \<le> c *\<^sub>R b \<longleftrightarrow> a \<le> b"
immler@54778
   612
  by (auto simp: scaleR_le_cancel_left)
immler@54778
   613
immler@54778
   614
lemma scaleR_le_cancel_left_neg:
immler@54778
   615
  fixes b::"'a::ordered_real_vector"
immler@54778
   616
  shows "c < 0 \<Longrightarrow> c *\<^sub>R a \<le> c *\<^sub>R b \<longleftrightarrow> b \<le> a"
immler@54778
   617
  by (auto simp: scaleR_le_cancel_left)
immler@54778
   618
immler@54778
   619
lemma scaleR_left_le_one_le:
immler@54778
   620
  fixes x::"'a::ordered_real_vector" and a::real
immler@54778
   621
  shows "0 \<le> x \<Longrightarrow> a \<le> 1 \<Longrightarrow> a *\<^sub>R x \<le> x"
immler@54778
   622
  using scaleR_right_mono[of a 1 x] by simp
immler@54778
   623
huffman@20504
   624
wenzelm@60758
   625
subsection \<open>Real normed vector spaces\<close>
huffman@20504
   626
hoelzl@51531
   627
class dist =
hoelzl@51531
   628
  fixes dist :: "'a \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@51531
   629
haftmann@29608
   630
class norm =
huffman@22636
   631
  fixes norm :: "'a \<Rightarrow> real"
huffman@20504
   632
huffman@24520
   633
class sgn_div_norm = scaleR + norm + sgn +
haftmann@25062
   634
  assumes sgn_div_norm: "sgn x = x /\<^sub>R norm x"
nipkow@24506
   635
huffman@31289
   636
class dist_norm = dist + norm + minus +
huffman@31289
   637
  assumes dist_norm: "dist x y = norm (x - y)"
huffman@31289
   638
hoelzl@51531
   639
class open_dist = "open" + dist +
hoelzl@51531
   640
  assumes open_dist: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
hoelzl@51531
   641
huffman@31492
   642
class real_normed_vector = real_vector + sgn_div_norm + dist_norm + open_dist +
hoelzl@51002
   643
  assumes norm_eq_zero [simp]: "norm x = 0 \<longleftrightarrow> x = 0"
haftmann@25062
   644
  and norm_triangle_ineq: "norm (x + y) \<le> norm x + norm y"
huffman@31586
   645
  and norm_scaleR [simp]: "norm (scaleR a x) = \<bar>a\<bar> * norm x"
hoelzl@51002
   646
begin
hoelzl@51002
   647
hoelzl@51002
   648
lemma norm_ge_zero [simp]: "0 \<le> norm x"
hoelzl@51002
   649
proof -
lp15@60026
   650
  have "0 = norm (x + -1 *\<^sub>R x)"
hoelzl@51002
   651
    using scaleR_add_left[of 1 "-1" x] norm_scaleR[of 0 x] by (simp add: scaleR_one)
hoelzl@51002
   652
  also have "\<dots> \<le> norm x + norm (-1 *\<^sub>R x)" by (rule norm_triangle_ineq)
hoelzl@51002
   653
  finally show ?thesis by simp
hoelzl@51002
   654
qed
hoelzl@51002
   655
hoelzl@51002
   656
end
huffman@20504
   657
haftmann@24588
   658
class real_normed_algebra = real_algebra + real_normed_vector +
haftmann@25062
   659
  assumes norm_mult_ineq: "norm (x * y) \<le> norm x * norm y"
huffman@20504
   660
haftmann@24588
   661
class real_normed_algebra_1 = real_algebra_1 + real_normed_algebra +
haftmann@25062
   662
  assumes norm_one [simp]: "norm 1 = 1"
huffman@22852
   663
haftmann@24588
   664
class real_normed_div_algebra = real_div_algebra + real_normed_vector +
haftmann@25062
   665
  assumes norm_mult: "norm (x * y) = norm x * norm y"
huffman@20504
   666
haftmann@24588
   667
class real_normed_field = real_field + real_normed_div_algebra
huffman@20584
   668
huffman@22852
   669
instance real_normed_div_algebra < real_normed_algebra_1
huffman@20554
   670
proof
huffman@20554
   671
  fix x y :: 'a
huffman@20554
   672
  show "norm (x * y) \<le> norm x * norm y"
huffman@20554
   673
    by (simp add: norm_mult)
huffman@22852
   674
next
huffman@22852
   675
  have "norm (1 * 1::'a) = norm (1::'a) * norm (1::'a)"
huffman@22852
   676
    by (rule norm_mult)
huffman@22852
   677
  thus "norm (1::'a) = 1" by simp
huffman@20554
   678
qed
huffman@20554
   679
huffman@22852
   680
lemma norm_zero [simp]: "norm (0::'a::real_normed_vector) = 0"
huffman@20504
   681
by simp
huffman@20504
   682
huffman@22852
   683
lemma zero_less_norm_iff [simp]:
huffman@22852
   684
  fixes x :: "'a::real_normed_vector"
huffman@22852
   685
  shows "(0 < norm x) = (x \<noteq> 0)"
huffman@20504
   686
by (simp add: order_less_le)
huffman@20504
   687
huffman@22852
   688
lemma norm_not_less_zero [simp]:
huffman@22852
   689
  fixes x :: "'a::real_normed_vector"
huffman@22852
   690
  shows "\<not> norm x < 0"
huffman@20828
   691
by (simp add: linorder_not_less)
huffman@20828
   692
huffman@22852
   693
lemma norm_le_zero_iff [simp]:
huffman@22852
   694
  fixes x :: "'a::real_normed_vector"
huffman@22852
   695
  shows "(norm x \<le> 0) = (x = 0)"
huffman@20828
   696
by (simp add: order_le_less)
huffman@20828
   697
huffman@20504
   698
lemma norm_minus_cancel [simp]:
huffman@20584
   699
  fixes x :: "'a::real_normed_vector"
huffman@20584
   700
  shows "norm (- x) = norm x"
huffman@20504
   701
proof -
huffman@21809
   702
  have "norm (- x) = norm (scaleR (- 1) x)"
huffman@20504
   703
    by (simp only: scaleR_minus_left scaleR_one)
huffman@20533
   704
  also have "\<dots> = \<bar>- 1\<bar> * norm x"
huffman@20504
   705
    by (rule norm_scaleR)
huffman@20504
   706
  finally show ?thesis by simp
huffman@20504
   707
qed
huffman@20504
   708
huffman@20504
   709
lemma norm_minus_commute:
huffman@20584
   710
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   711
  shows "norm (a - b) = norm (b - a)"
huffman@20504
   712
proof -
huffman@22898
   713
  have "norm (- (b - a)) = norm (b - a)"
huffman@22898
   714
    by (rule norm_minus_cancel)
huffman@22898
   715
  thus ?thesis by simp
huffman@20504
   716
qed
huffman@20504
   717
huffman@20504
   718
lemma norm_triangle_ineq2:
huffman@20584
   719
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   720
  shows "norm a - norm b \<le> norm (a - b)"
huffman@20504
   721
proof -
huffman@20533
   722
  have "norm (a - b + b) \<le> norm (a - b) + norm b"
huffman@20504
   723
    by (rule norm_triangle_ineq)
huffman@22898
   724
  thus ?thesis by simp
huffman@20504
   725
qed
huffman@20504
   726
huffman@20584
   727
lemma norm_triangle_ineq3:
huffman@20584
   728
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   729
  shows "\<bar>norm a - norm b\<bar> \<le> norm (a - b)"
huffman@20584
   730
apply (subst abs_le_iff)
huffman@20584
   731
apply auto
huffman@20584
   732
apply (rule norm_triangle_ineq2)
huffman@20584
   733
apply (subst norm_minus_commute)
huffman@20584
   734
apply (rule norm_triangle_ineq2)
huffman@20584
   735
done
huffman@20584
   736
huffman@20504
   737
lemma norm_triangle_ineq4:
huffman@20584
   738
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   739
  shows "norm (a - b) \<le> norm a + norm b"
huffman@20504
   740
proof -
huffman@22898
   741
  have "norm (a + - b) \<le> norm a + norm (- b)"
huffman@20504
   742
    by (rule norm_triangle_ineq)
haftmann@54230
   743
  then show ?thesis by simp
huffman@22898
   744
qed
huffman@22898
   745
huffman@22898
   746
lemma norm_diff_ineq:
huffman@22898
   747
  fixes a b :: "'a::real_normed_vector"
huffman@22898
   748
  shows "norm a - norm b \<le> norm (a + b)"
huffman@22898
   749
proof -
huffman@22898
   750
  have "norm a - norm (- b) \<le> norm (a - - b)"
huffman@22898
   751
    by (rule norm_triangle_ineq2)
huffman@22898
   752
  thus ?thesis by simp
huffman@20504
   753
qed
huffman@20504
   754
huffman@20551
   755
lemma norm_diff_triangle_ineq:
huffman@20551
   756
  fixes a b c d :: "'a::real_normed_vector"
huffman@20551
   757
  shows "norm ((a + b) - (c + d)) \<le> norm (a - c) + norm (b - d)"
huffman@20551
   758
proof -
huffman@20551
   759
  have "norm ((a + b) - (c + d)) = norm ((a - c) + (b - d))"
haftmann@54230
   760
    by (simp add: algebra_simps)
huffman@20551
   761
  also have "\<dots> \<le> norm (a - c) + norm (b - d)"
huffman@20551
   762
    by (rule norm_triangle_ineq)
huffman@20551
   763
  finally show ?thesis .
huffman@20551
   764
qed
huffman@20551
   765
lp15@60026
   766
lemma norm_triangle_mono:
lp15@55719
   767
  fixes a b :: "'a::real_normed_vector"
lp15@55719
   768
  shows "\<lbrakk>norm a \<le> r; norm b \<le> s\<rbrakk> \<Longrightarrow> norm (a + b) \<le> r + s"
lp15@55719
   769
by (metis add_mono_thms_linordered_semiring(1) norm_triangle_ineq order.trans)
lp15@55719
   770
hoelzl@56194
   771
lemma norm_setsum:
hoelzl@56194
   772
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
hoelzl@56194
   773
  shows "norm (setsum f A) \<le> (\<Sum>i\<in>A. norm (f i))"
hoelzl@56194
   774
  by (induct A rule: infinite_finite_induct) (auto intro: norm_triangle_mono)
hoelzl@56194
   775
hoelzl@56369
   776
lemma setsum_norm_le:
hoelzl@56369
   777
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
hoelzl@56369
   778
  assumes fg: "\<forall>x \<in> S. norm (f x) \<le> g x"
hoelzl@56369
   779
  shows "norm (setsum f S) \<le> setsum g S"
hoelzl@56369
   780
  by (rule order_trans [OF norm_setsum setsum_mono]) (simp add: fg)
hoelzl@56369
   781
huffman@22857
   782
lemma abs_norm_cancel [simp]:
huffman@22857
   783
  fixes a :: "'a::real_normed_vector"
huffman@22857
   784
  shows "\<bar>norm a\<bar> = norm a"
huffman@22857
   785
by (rule abs_of_nonneg [OF norm_ge_zero])
huffman@22857
   786
huffman@22880
   787
lemma norm_add_less:
huffman@22880
   788
  fixes x y :: "'a::real_normed_vector"
huffman@22880
   789
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x + y) < r + s"
huffman@22880
   790
by (rule order_le_less_trans [OF norm_triangle_ineq add_strict_mono])
huffman@22880
   791
huffman@22880
   792
lemma norm_mult_less:
huffman@22880
   793
  fixes x y :: "'a::real_normed_algebra"
huffman@22880
   794
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x * y) < r * s"
huffman@22880
   795
apply (rule order_le_less_trans [OF norm_mult_ineq])
huffman@22880
   796
apply (simp add: mult_strict_mono')
huffman@22880
   797
done
huffman@22880
   798
huffman@22857
   799
lemma norm_of_real [simp]:
huffman@22857
   800
  "norm (of_real r :: 'a::real_normed_algebra_1) = \<bar>r\<bar>"
huffman@31586
   801
unfolding of_real_def by simp
huffman@20560
   802
huffman@47108
   803
lemma norm_numeral [simp]:
huffman@47108
   804
  "norm (numeral w::'a::real_normed_algebra_1) = numeral w"
huffman@47108
   805
by (subst of_real_numeral [symmetric], subst norm_of_real, simp)
huffman@47108
   806
huffman@47108
   807
lemma norm_neg_numeral [simp]:
haftmann@54489
   808
  "norm (- numeral w::'a::real_normed_algebra_1) = numeral w"
huffman@47108
   809
by (subst of_real_neg_numeral [symmetric], subst norm_of_real, simp)
huffman@22876
   810
huffman@22876
   811
lemma norm_of_int [simp]:
huffman@22876
   812
  "norm (of_int z::'a::real_normed_algebra_1) = \<bar>of_int z\<bar>"
huffman@22876
   813
by (subst of_real_of_int_eq [symmetric], rule norm_of_real)
huffman@22876
   814
huffman@22876
   815
lemma norm_of_nat [simp]:
huffman@22876
   816
  "norm (of_nat n::'a::real_normed_algebra_1) = of_nat n"
huffman@22876
   817
apply (subst of_real_of_nat_eq [symmetric])
huffman@22876
   818
apply (subst norm_of_real, simp)
huffman@22876
   819
done
huffman@22876
   820
huffman@20504
   821
lemma nonzero_norm_inverse:
huffman@20504
   822
  fixes a :: "'a::real_normed_div_algebra"
huffman@20533
   823
  shows "a \<noteq> 0 \<Longrightarrow> norm (inverse a) = inverse (norm a)"
huffman@20504
   824
apply (rule inverse_unique [symmetric])
huffman@20504
   825
apply (simp add: norm_mult [symmetric])
huffman@20504
   826
done
huffman@20504
   827
huffman@20504
   828
lemma norm_inverse:
haftmann@59867
   829
  fixes a :: "'a::{real_normed_div_algebra, division_ring}"
huffman@20533
   830
  shows "norm (inverse a) = inverse (norm a)"
huffman@20504
   831
apply (case_tac "a = 0", simp)
huffman@20504
   832
apply (erule nonzero_norm_inverse)
huffman@20504
   833
done
huffman@20504
   834
huffman@20584
   835
lemma nonzero_norm_divide:
huffman@20584
   836
  fixes a b :: "'a::real_normed_field"
huffman@20584
   837
  shows "b \<noteq> 0 \<Longrightarrow> norm (a / b) = norm a / norm b"
huffman@20584
   838
by (simp add: divide_inverse norm_mult nonzero_norm_inverse)
huffman@20584
   839
huffman@20584
   840
lemma norm_divide:
haftmann@59867
   841
  fixes a b :: "'a::{real_normed_field, field}"
huffman@20584
   842
  shows "norm (a / b) = norm a / norm b"
huffman@20584
   843
by (simp add: divide_inverse norm_mult norm_inverse)
huffman@20584
   844
huffman@22852
   845
lemma norm_power_ineq:
haftmann@31017
   846
  fixes x :: "'a::{real_normed_algebra_1}"
huffman@22852
   847
  shows "norm (x ^ n) \<le> norm x ^ n"
huffman@22852
   848
proof (induct n)
huffman@22852
   849
  case 0 show "norm (x ^ 0) \<le> norm x ^ 0" by simp
huffman@22852
   850
next
huffman@22852
   851
  case (Suc n)
huffman@22852
   852
  have "norm (x * x ^ n) \<le> norm x * norm (x ^ n)"
huffman@22852
   853
    by (rule norm_mult_ineq)
huffman@22852
   854
  also from Suc have "\<dots> \<le> norm x * norm x ^ n"
huffman@22852
   855
    using norm_ge_zero by (rule mult_left_mono)
huffman@22852
   856
  finally show "norm (x ^ Suc n) \<le> norm x ^ Suc n"
huffman@30273
   857
    by simp
huffman@22852
   858
qed
huffman@22852
   859
huffman@20684
   860
lemma norm_power:
haftmann@31017
   861
  fixes x :: "'a::{real_normed_div_algebra}"
huffman@20684
   862
  shows "norm (x ^ n) = norm x ^ n"
huffman@30273
   863
by (induct n) (simp_all add: norm_mult)
huffman@20684
   864
paulson@60762
   865
lemma norm_mult_numeral1 [simp]:
paulson@60762
   866
  fixes a b :: "'a::{real_normed_field, field}"
paulson@60762
   867
  shows "norm (numeral w * a) = numeral w * norm a"
paulson@60762
   868
by (simp add: norm_mult)
paulson@60762
   869
paulson@60762
   870
lemma norm_mult_numeral2 [simp]:
paulson@60762
   871
  fixes a b :: "'a::{real_normed_field, field}"
paulson@60762
   872
  shows "norm (a * numeral w) = norm a * numeral w"
paulson@60762
   873
by (simp add: norm_mult)
paulson@60762
   874
paulson@60762
   875
lemma norm_divide_numeral [simp]:
paulson@60762
   876
  fixes a b :: "'a::{real_normed_field, field}"
paulson@60762
   877
  shows "norm (a / numeral w) = norm a / numeral w"
paulson@60762
   878
by (simp add: norm_divide)
paulson@60762
   879
paulson@60762
   880
lemma norm_of_real_diff [simp]:
paulson@60762
   881
    "norm (of_real b - of_real a :: 'a::real_normed_algebra_1) \<le> \<bar>b - a\<bar>"
paulson@60762
   882
  by (metis norm_of_real of_real_diff order_refl)
paulson@60762
   883
wenzelm@60758
   884
text\<open>Despite a superficial resemblance, @{text norm_eq_1} is not relevant.\<close>
lp15@59613
   885
lemma square_norm_one:
lp15@59613
   886
  fixes x :: "'a::real_normed_div_algebra"
lp15@59613
   887
  assumes "x^2 = 1" shows "norm x = 1"
lp15@59613
   888
  by (metis assms norm_minus_cancel norm_one power2_eq_1_iff)
lp15@59613
   889
lp15@59658
   890
lemma norm_less_p1:
lp15@59658
   891
  fixes x :: "'a::real_normed_algebra_1"
lp15@59658
   892
  shows "norm x < norm (of_real (norm x) + 1 :: 'a)"
lp15@59658
   893
proof -
lp15@59658
   894
  have "norm x < norm (of_real (norm x + 1) :: 'a)"
lp15@59658
   895
    by (simp add: of_real_def)
lp15@59658
   896
  then show ?thesis
lp15@59658
   897
    by simp
lp15@59658
   898
qed
lp15@59658
   899
lp15@55719
   900
lemma setprod_norm:
lp15@55719
   901
  fixes f :: "'a \<Rightarrow> 'b::{comm_semiring_1,real_normed_div_algebra}"
lp15@55719
   902
  shows "setprod (\<lambda>x. norm(f x)) A = norm (setprod f A)"
hoelzl@57275
   903
  by (induct A rule: infinite_finite_induct) (auto simp: norm_mult)
hoelzl@57275
   904
lp15@60026
   905
lemma norm_setprod_le:
hoelzl@57275
   906
  "norm (setprod f A) \<le> (\<Prod>a\<in>A. norm (f a :: 'a :: {real_normed_algebra_1, comm_monoid_mult}))"
hoelzl@57275
   907
proof (induction A rule: infinite_finite_induct)
hoelzl@57275
   908
  case (insert a A)
hoelzl@57275
   909
  then have "norm (setprod f (insert a A)) \<le> norm (f a) * norm (setprod f A)"
hoelzl@57275
   910
    by (simp add: norm_mult_ineq)
hoelzl@57275
   911
  also have "norm (setprod f A) \<le> (\<Prod>a\<in>A. norm (f a))"
hoelzl@57275
   912
    by (rule insert)
hoelzl@57275
   913
  finally show ?case
hoelzl@57275
   914
    by (simp add: insert mult_left_mono)
hoelzl@57275
   915
qed simp_all
hoelzl@57275
   916
hoelzl@57275
   917
lemma norm_setprod_diff:
hoelzl@57275
   918
  fixes z w :: "'i \<Rightarrow> 'a::{real_normed_algebra_1, comm_monoid_mult}"
hoelzl@57275
   919
  shows "(\<And>i. i \<in> I \<Longrightarrow> norm (z i) \<le> 1) \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> norm (w i) \<le> 1) \<Longrightarrow>
lp15@60026
   920
    norm ((\<Prod>i\<in>I. z i) - (\<Prod>i\<in>I. w i)) \<le> (\<Sum>i\<in>I. norm (z i - w i))"
hoelzl@57275
   921
proof (induction I rule: infinite_finite_induct)
hoelzl@57275
   922
  case (insert i I)
hoelzl@57275
   923
  note insert.hyps[simp]
hoelzl@57275
   924
hoelzl@57275
   925
  have "norm ((\<Prod>i\<in>insert i I. z i) - (\<Prod>i\<in>insert i I. w i)) =
hoelzl@57275
   926
    norm ((\<Prod>i\<in>I. z i) * (z i - w i) + ((\<Prod>i\<in>I. z i) - (\<Prod>i\<in>I. w i)) * w i)"
hoelzl@57275
   927
    (is "_ = norm (?t1 + ?t2)")
hoelzl@57275
   928
    by (auto simp add: field_simps)
hoelzl@57275
   929
  also have "... \<le> norm ?t1 + norm ?t2"
hoelzl@57275
   930
    by (rule norm_triangle_ineq)
hoelzl@57275
   931
  also have "norm ?t1 \<le> norm (\<Prod>i\<in>I. z i) * norm (z i - w i)"
hoelzl@57275
   932
    by (rule norm_mult_ineq)
hoelzl@57275
   933
  also have "\<dots> \<le> (\<Prod>i\<in>I. norm (z i)) * norm(z i - w i)"
hoelzl@57275
   934
    by (rule mult_right_mono) (auto intro: norm_setprod_le)
hoelzl@57275
   935
  also have "(\<Prod>i\<in>I. norm (z i)) \<le> (\<Prod>i\<in>I. 1)"
hoelzl@57275
   936
    by (intro setprod_mono) (auto intro!: insert)
hoelzl@57275
   937
  also have "norm ?t2 \<le> norm ((\<Prod>i\<in>I. z i) - (\<Prod>i\<in>I. w i)) * norm (w i)"
hoelzl@57275
   938
    by (rule norm_mult_ineq)
hoelzl@57275
   939
  also have "norm (w i) \<le> 1"
hoelzl@57275
   940
    by (auto intro: insert)
hoelzl@57275
   941
  also have "norm ((\<Prod>i\<in>I. z i) - (\<Prod>i\<in>I. w i)) \<le> (\<Sum>i\<in>I. norm (z i - w i))"
hoelzl@57275
   942
    using insert by auto
hoelzl@57275
   943
  finally show ?case
haftmann@57514
   944
    by (auto simp add: ac_simps mult_right_mono mult_left_mono)
hoelzl@57275
   945
qed simp_all
hoelzl@57275
   946
lp15@60026
   947
lemma norm_power_diff:
hoelzl@57275
   948
  fixes z w :: "'a::{real_normed_algebra_1, comm_monoid_mult}"
hoelzl@57275
   949
  assumes "norm z \<le> 1" "norm w \<le> 1"
hoelzl@57275
   950
  shows "norm (z^m - w^m) \<le> m * norm (z - w)"
hoelzl@57275
   951
proof -
hoelzl@57275
   952
  have "norm (z^m - w^m) = norm ((\<Prod> i < m. z) - (\<Prod> i < m. w))"
hoelzl@57275
   953
    by (simp add: setprod_constant)
hoelzl@57275
   954
  also have "\<dots> \<le> (\<Sum>i<m. norm (z - w))"
hoelzl@57275
   955
    by (intro norm_setprod_diff) (auto simp add: assms)
hoelzl@57275
   956
  also have "\<dots> = m * norm (z - w)"
hoelzl@57275
   957
    by (simp add: real_of_nat_def)
hoelzl@57275
   958
  finally show ?thesis .
lp15@55719
   959
qed
lp15@55719
   960
wenzelm@60758
   961
subsection \<open>Metric spaces\<close>
hoelzl@51531
   962
hoelzl@51531
   963
class metric_space = open_dist +
hoelzl@51531
   964
  assumes dist_eq_0_iff [simp]: "dist x y = 0 \<longleftrightarrow> x = y"
hoelzl@51531
   965
  assumes dist_triangle2: "dist x y \<le> dist x z + dist y z"
hoelzl@51531
   966
begin
hoelzl@51531
   967
hoelzl@51531
   968
lemma dist_self [simp]: "dist x x = 0"
hoelzl@51531
   969
by simp
hoelzl@51531
   970
hoelzl@51531
   971
lemma zero_le_dist [simp]: "0 \<le> dist x y"
hoelzl@51531
   972
using dist_triangle2 [of x x y] by simp
hoelzl@51531
   973
hoelzl@51531
   974
lemma zero_less_dist_iff: "0 < dist x y \<longleftrightarrow> x \<noteq> y"
hoelzl@51531
   975
by (simp add: less_le)
hoelzl@51531
   976
hoelzl@51531
   977
lemma dist_not_less_zero [simp]: "\<not> dist x y < 0"
hoelzl@51531
   978
by (simp add: not_less)
hoelzl@51531
   979
hoelzl@51531
   980
lemma dist_le_zero_iff [simp]: "dist x y \<le> 0 \<longleftrightarrow> x = y"
hoelzl@51531
   981
by (simp add: le_less)
hoelzl@51531
   982
hoelzl@51531
   983
lemma dist_commute: "dist x y = dist y x"
hoelzl@51531
   984
proof (rule order_antisym)
hoelzl@51531
   985
  show "dist x y \<le> dist y x"
hoelzl@51531
   986
    using dist_triangle2 [of x y x] by simp
hoelzl@51531
   987
  show "dist y x \<le> dist x y"
hoelzl@51531
   988
    using dist_triangle2 [of y x y] by simp
hoelzl@51531
   989
qed
hoelzl@51531
   990
hoelzl@51531
   991
lemma dist_triangle: "dist x z \<le> dist x y + dist y z"
hoelzl@51531
   992
using dist_triangle2 [of x z y] by (simp add: dist_commute)
hoelzl@51531
   993
hoelzl@51531
   994
lemma dist_triangle3: "dist x y \<le> dist a x + dist a y"
hoelzl@51531
   995
using dist_triangle2 [of x y a] by (simp add: dist_commute)
hoelzl@51531
   996
hoelzl@51531
   997
lemma dist_triangle_alt:
hoelzl@51531
   998
  shows "dist y z <= dist x y + dist x z"
hoelzl@51531
   999
by (rule dist_triangle3)
hoelzl@51531
  1000
hoelzl@51531
  1001
lemma dist_pos_lt:
hoelzl@51531
  1002
  shows "x \<noteq> y ==> 0 < dist x y"
hoelzl@51531
  1003
by (simp add: zero_less_dist_iff)
hoelzl@51531
  1004
hoelzl@51531
  1005
lemma dist_nz:
hoelzl@51531
  1006
  shows "x \<noteq> y \<longleftrightarrow> 0 < dist x y"
hoelzl@51531
  1007
by (simp add: zero_less_dist_iff)
hoelzl@51531
  1008
hoelzl@51531
  1009
lemma dist_triangle_le:
hoelzl@51531
  1010
  shows "dist x z + dist y z <= e \<Longrightarrow> dist x y <= e"
hoelzl@51531
  1011
by (rule order_trans [OF dist_triangle2])
hoelzl@51531
  1012
hoelzl@51531
  1013
lemma dist_triangle_lt:
hoelzl@51531
  1014
  shows "dist x z + dist y z < e ==> dist x y < e"
hoelzl@51531
  1015
by (rule le_less_trans [OF dist_triangle2])
hoelzl@51531
  1016
hoelzl@51531
  1017
lemma dist_triangle_half_l:
hoelzl@51531
  1018
  shows "dist x1 y < e / 2 \<Longrightarrow> dist x2 y < e / 2 \<Longrightarrow> dist x1 x2 < e"
hoelzl@51531
  1019
by (rule dist_triangle_lt [where z=y], simp)
hoelzl@51531
  1020
hoelzl@51531
  1021
lemma dist_triangle_half_r:
hoelzl@51531
  1022
  shows "dist y x1 < e / 2 \<Longrightarrow> dist y x2 < e / 2 \<Longrightarrow> dist x1 x2 < e"
hoelzl@51531
  1023
by (rule dist_triangle_half_l, simp_all add: dist_commute)
hoelzl@51531
  1024
hoelzl@51531
  1025
subclass topological_space
hoelzl@51531
  1026
proof
hoelzl@51531
  1027
  have "\<exists>e::real. 0 < e"
hoelzl@51531
  1028
    by (fast intro: zero_less_one)
hoelzl@51531
  1029
  then show "open UNIV"
hoelzl@51531
  1030
    unfolding open_dist by simp
hoelzl@51531
  1031
next
hoelzl@51531
  1032
  fix S T assume "open S" "open T"
hoelzl@51531
  1033
  then show "open (S \<inter> T)"
hoelzl@51531
  1034
    unfolding open_dist
hoelzl@51531
  1035
    apply clarify
hoelzl@51531
  1036
    apply (drule (1) bspec)+
hoelzl@51531
  1037
    apply (clarify, rename_tac r s)
hoelzl@51531
  1038
    apply (rule_tac x="min r s" in exI, simp)
hoelzl@51531
  1039
    done
hoelzl@51531
  1040
next
hoelzl@51531
  1041
  fix K assume "\<forall>S\<in>K. open S" thus "open (\<Union>K)"
hoelzl@51531
  1042
    unfolding open_dist by fast
hoelzl@51531
  1043
qed
hoelzl@51531
  1044
hoelzl@51531
  1045
lemma open_ball: "open {y. dist x y < d}"
hoelzl@51531
  1046
proof (unfold open_dist, intro ballI)
hoelzl@51531
  1047
  fix y assume *: "y \<in> {y. dist x y < d}"
hoelzl@51531
  1048
  then show "\<exists>e>0. \<forall>z. dist z y < e \<longrightarrow> z \<in> {y. dist x y < d}"
hoelzl@51531
  1049
    by (auto intro!: exI[of _ "d - dist x y"] simp: field_simps dist_triangle_lt)
hoelzl@51531
  1050
qed
hoelzl@51531
  1051
hoelzl@51531
  1052
subclass first_countable_topology
hoelzl@51531
  1053
proof
lp15@60026
  1054
  fix x
hoelzl@51531
  1055
  show "\<exists>A::nat \<Rightarrow> 'a set. (\<forall>i. x \<in> A i \<and> open (A i)) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>i. A i \<subseteq> S))"
hoelzl@51531
  1056
  proof (safe intro!: exI[of _ "\<lambda>n. {y. dist x y < inverse (Suc n)}"])
hoelzl@51531
  1057
    fix S assume "open S" "x \<in> S"
wenzelm@53374
  1058
    then obtain e where e: "0 < e" and "{y. dist x y < e} \<subseteq> S"
hoelzl@51531
  1059
      by (auto simp: open_dist subset_eq dist_commute)
hoelzl@51531
  1060
    moreover
wenzelm@53374
  1061
    from e obtain i where "inverse (Suc i) < e"
hoelzl@51531
  1062
      by (auto dest!: reals_Archimedean)
hoelzl@51531
  1063
    then have "{y. dist x y < inverse (Suc i)} \<subseteq> {y. dist x y < e}"
hoelzl@51531
  1064
      by auto
hoelzl@51531
  1065
    ultimately show "\<exists>i. {y. dist x y < inverse (Suc i)} \<subseteq> S"
hoelzl@51531
  1066
      by blast
hoelzl@51531
  1067
  qed (auto intro: open_ball)
hoelzl@51531
  1068
qed
hoelzl@51531
  1069
hoelzl@51531
  1070
end
hoelzl@51531
  1071
hoelzl@51531
  1072
instance metric_space \<subseteq> t2_space
hoelzl@51531
  1073
proof
hoelzl@51531
  1074
  fix x y :: "'a::metric_space"
hoelzl@51531
  1075
  assume xy: "x \<noteq> y"
hoelzl@51531
  1076
  let ?U = "{y'. dist x y' < dist x y / 2}"
hoelzl@51531
  1077
  let ?V = "{x'. dist y x' < dist x y / 2}"
hoelzl@51531
  1078
  have th0: "\<And>d x y z. (d x z :: real) \<le> d x y + d y z \<Longrightarrow> d y z = d z y
hoelzl@51531
  1079
               \<Longrightarrow> \<not>(d x y * 2 < d x z \<and> d z y * 2 < d x z)" by arith
hoelzl@51531
  1080
  have "open ?U \<and> open ?V \<and> x \<in> ?U \<and> y \<in> ?V \<and> ?U \<inter> ?V = {}"
hoelzl@51531
  1081
    using dist_pos_lt[OF xy] th0[of dist, OF dist_triangle dist_commute]
hoelzl@51531
  1082
    using open_ball[of _ "dist x y / 2"] by auto
hoelzl@51531
  1083
  then show "\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
hoelzl@51531
  1084
    by blast
hoelzl@51531
  1085
qed
hoelzl@51531
  1086
wenzelm@60758
  1087
text \<open>Every normed vector space is a metric space.\<close>
huffman@31285
  1088
huffman@31289
  1089
instance real_normed_vector < metric_space
huffman@31289
  1090
proof
huffman@31289
  1091
  fix x y :: 'a show "dist x y = 0 \<longleftrightarrow> x = y"
huffman@31289
  1092
    unfolding dist_norm by simp
huffman@31289
  1093
next
huffman@31289
  1094
  fix x y z :: 'a show "dist x y \<le> dist x z + dist y z"
huffman@31289
  1095
    unfolding dist_norm
huffman@31289
  1096
    using norm_triangle_ineq4 [of "x - z" "y - z"] by simp
huffman@31289
  1097
qed
huffman@31285
  1098
wenzelm@60758
  1099
subsection \<open>Class instances for real numbers\<close>
huffman@31564
  1100
huffman@31564
  1101
instantiation real :: real_normed_field
huffman@31564
  1102
begin
huffman@31564
  1103
hoelzl@51531
  1104
definition dist_real_def:
hoelzl@51531
  1105
  "dist x y = \<bar>x - y\<bar>"
hoelzl@51531
  1106
haftmann@52381
  1107
definition open_real_def [code del]:
hoelzl@51531
  1108
  "open (S :: real set) \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
hoelzl@51531
  1109
huffman@31564
  1110
definition real_norm_def [simp]:
huffman@31564
  1111
  "norm r = \<bar>r\<bar>"
huffman@31564
  1112
huffman@31564
  1113
instance
huffman@31564
  1114
apply (intro_classes, unfold real_norm_def real_scaleR_def)
huffman@31564
  1115
apply (rule dist_real_def)
hoelzl@51531
  1116
apply (rule open_real_def)
huffman@36795
  1117
apply (simp add: sgn_real_def)
huffman@31564
  1118
apply (rule abs_eq_0)
huffman@31564
  1119
apply (rule abs_triangle_ineq)
huffman@31564
  1120
apply (rule abs_mult)
huffman@31564
  1121
apply (rule abs_mult)
huffman@31564
  1122
done
huffman@31564
  1123
huffman@31564
  1124
end
huffman@31564
  1125
haftmann@54890
  1126
declare [[code abort: "open :: real set \<Rightarrow> bool"]]
haftmann@52381
  1127
hoelzl@51531
  1128
instance real :: linorder_topology
hoelzl@51531
  1129
proof
hoelzl@51531
  1130
  show "(open :: real set \<Rightarrow> bool) = generate_topology (range lessThan \<union> range greaterThan)"
hoelzl@51531
  1131
  proof (rule ext, safe)
hoelzl@51531
  1132
    fix S :: "real set" assume "open S"
wenzelm@53381
  1133
    then obtain f where "\<forall>x\<in>S. 0 < f x \<and> (\<forall>y. dist y x < f x \<longrightarrow> y \<in> S)"
wenzelm@53381
  1134
      unfolding open_real_def bchoice_iff ..
hoelzl@51531
  1135
    then have *: "S = (\<Union>x\<in>S. {x - f x <..} \<inter> {..< x + f x})"
hoelzl@51531
  1136
      by (fastforce simp: dist_real_def)
hoelzl@51531
  1137
    show "generate_topology (range lessThan \<union> range greaterThan) S"
hoelzl@51531
  1138
      apply (subst *)
hoelzl@51531
  1139
      apply (intro generate_topology_Union generate_topology.Int)
hoelzl@51531
  1140
      apply (auto intro: generate_topology.Basis)
hoelzl@51531
  1141
      done
hoelzl@51531
  1142
  next
hoelzl@51531
  1143
    fix S :: "real set" assume "generate_topology (range lessThan \<union> range greaterThan) S"
hoelzl@51531
  1144
    moreover have "\<And>a::real. open {..<a}"
hoelzl@51531
  1145
      unfolding open_real_def dist_real_def
hoelzl@51531
  1146
    proof clarify
hoelzl@51531
  1147
      fix x a :: real assume "x < a"
hoelzl@51531
  1148
      hence "0 < a - x \<and> (\<forall>y. \<bar>y - x\<bar> < a - x \<longrightarrow> y \<in> {..<a})" by auto
hoelzl@51531
  1149
      thus "\<exists>e>0. \<forall>y. \<bar>y - x\<bar> < e \<longrightarrow> y \<in> {..<a}" ..
hoelzl@51531
  1150
    qed
hoelzl@51531
  1151
    moreover have "\<And>a::real. open {a <..}"
hoelzl@51531
  1152
      unfolding open_real_def dist_real_def
hoelzl@51531
  1153
    proof clarify
hoelzl@51531
  1154
      fix x a :: real assume "a < x"
hoelzl@51531
  1155
      hence "0 < x - a \<and> (\<forall>y. \<bar>y - x\<bar> < x - a \<longrightarrow> y \<in> {a<..})" by auto
hoelzl@51531
  1156
      thus "\<exists>e>0. \<forall>y. \<bar>y - x\<bar> < e \<longrightarrow> y \<in> {a<..}" ..
hoelzl@51531
  1157
    qed
hoelzl@51531
  1158
    ultimately show "open S"
hoelzl@51531
  1159
      by induct auto
hoelzl@51531
  1160
  qed
hoelzl@51531
  1161
qed
hoelzl@51531
  1162
hoelzl@51775
  1163
instance real :: linear_continuum_topology ..
hoelzl@51518
  1164
hoelzl@51531
  1165
lemmas open_real_greaterThan = open_greaterThan[where 'a=real]
hoelzl@51531
  1166
lemmas open_real_lessThan = open_lessThan[where 'a=real]
hoelzl@51531
  1167
lemmas open_real_greaterThanLessThan = open_greaterThanLessThan[where 'a=real]
hoelzl@51531
  1168
lemmas closed_real_atMost = closed_atMost[where 'a=real]
hoelzl@51531
  1169
lemmas closed_real_atLeast = closed_atLeast[where 'a=real]
hoelzl@51531
  1170
lemmas closed_real_atLeastAtMost = closed_atLeastAtMost[where 'a=real]
hoelzl@51531
  1171
wenzelm@60758
  1172
subsection \<open>Extra type constraints\<close>
huffman@31446
  1173
wenzelm@60758
  1174
text \<open>Only allow @{term "open"} in class @{text topological_space}.\<close>
huffman@31492
  1175
wenzelm@60758
  1176
setup \<open>Sign.add_const_constraint
wenzelm@60758
  1177
  (@{const_name "open"}, SOME @{typ "'a::topological_space set \<Rightarrow> bool"})\<close>
huffman@31492
  1178
wenzelm@60758
  1179
text \<open>Only allow @{term dist} in class @{text metric_space}.\<close>
huffman@31446
  1180
wenzelm@60758
  1181
setup \<open>Sign.add_const_constraint
wenzelm@60758
  1182
  (@{const_name dist}, SOME @{typ "'a::metric_space \<Rightarrow> 'a \<Rightarrow> real"})\<close>
huffman@31446
  1183
wenzelm@60758
  1184
text \<open>Only allow @{term norm} in class @{text real_normed_vector}.\<close>
huffman@31446
  1185
wenzelm@60758
  1186
setup \<open>Sign.add_const_constraint
wenzelm@60758
  1187
  (@{const_name norm}, SOME @{typ "'a::real_normed_vector \<Rightarrow> real"})\<close>
huffman@31446
  1188
wenzelm@60758
  1189
subsection \<open>Sign function\<close>
huffman@22972
  1190
nipkow@24506
  1191
lemma norm_sgn:
nipkow@24506
  1192
  "norm (sgn(x::'a::real_normed_vector)) = (if x = 0 then 0 else 1)"
huffman@31586
  1193
by (simp add: sgn_div_norm)
huffman@22972
  1194
nipkow@24506
  1195
lemma sgn_zero [simp]: "sgn(0::'a::real_normed_vector) = 0"
nipkow@24506
  1196
by (simp add: sgn_div_norm)
huffman@22972
  1197
nipkow@24506
  1198
lemma sgn_zero_iff: "(sgn(x::'a::real_normed_vector) = 0) = (x = 0)"
nipkow@24506
  1199
by (simp add: sgn_div_norm)
huffman@22972
  1200
nipkow@24506
  1201
lemma sgn_minus: "sgn (- x) = - sgn(x::'a::real_normed_vector)"
nipkow@24506
  1202
by (simp add: sgn_div_norm)
huffman@22972
  1203
nipkow@24506
  1204
lemma sgn_scaleR:
nipkow@24506
  1205
  "sgn (scaleR r x) = scaleR (sgn r) (sgn(x::'a::real_normed_vector))"
haftmann@57514
  1206
by (simp add: sgn_div_norm ac_simps)
huffman@22973
  1207
huffman@22972
  1208
lemma sgn_one [simp]: "sgn (1::'a::real_normed_algebra_1) = 1"
nipkow@24506
  1209
by (simp add: sgn_div_norm)
huffman@22972
  1210
huffman@22972
  1211
lemma sgn_of_real:
huffman@22972
  1212
  "sgn (of_real r::'a::real_normed_algebra_1) = of_real (sgn r)"
huffman@22972
  1213
unfolding of_real_def by (simp only: sgn_scaleR sgn_one)
huffman@22972
  1214
huffman@22973
  1215
lemma sgn_mult:
huffman@22973
  1216
  fixes x y :: "'a::real_normed_div_algebra"
huffman@22973
  1217
  shows "sgn (x * y) = sgn x * sgn y"
haftmann@57512
  1218
by (simp add: sgn_div_norm norm_mult mult.commute)
huffman@22973
  1219
huffman@22972
  1220
lemma real_sgn_eq: "sgn (x::real) = x / \<bar>x\<bar>"
nipkow@24506
  1221
by (simp add: sgn_div_norm divide_inverse)
huffman@22972
  1222
huffman@22972
  1223
lemma real_sgn_pos: "0 < (x::real) \<Longrightarrow> sgn x = 1"
hoelzl@56479
  1224
unfolding real_sgn_eq by simp
huffman@22972
  1225
huffman@22972
  1226
lemma real_sgn_neg: "(x::real) < 0 \<Longrightarrow> sgn x = -1"
hoelzl@56479
  1227
unfolding real_sgn_eq by simp
huffman@22972
  1228
hoelzl@56889
  1229
lemma zero_le_sgn_iff [simp]: "0 \<le> sgn x \<longleftrightarrow> 0 \<le> (x::real)"
hoelzl@56889
  1230
  by (cases "0::real" x rule: linorder_cases) simp_all
lp15@60026
  1231
hoelzl@56889
  1232
lemma zero_less_sgn_iff [simp]: "0 < sgn x \<longleftrightarrow> 0 < (x::real)"
hoelzl@56889
  1233
  by (cases "0::real" x rule: linorder_cases) simp_all
hoelzl@56889
  1234
hoelzl@56889
  1235
lemma sgn_le_0_iff [simp]: "sgn x \<le> 0 \<longleftrightarrow> (x::real) \<le> 0"
hoelzl@56889
  1236
  by (cases "0::real" x rule: linorder_cases) simp_all
lp15@60026
  1237
hoelzl@56889
  1238
lemma sgn_less_0_iff [simp]: "sgn x < 0 \<longleftrightarrow> (x::real) < 0"
hoelzl@56889
  1239
  by (cases "0::real" x rule: linorder_cases) simp_all
hoelzl@56889
  1240
hoelzl@51474
  1241
lemma norm_conv_dist: "norm x = dist x 0"
hoelzl@51474
  1242
  unfolding dist_norm by simp
huffman@22972
  1243
lp15@60307
  1244
lemma dist_diff [simp]: "dist a (a - b) = norm b"  "dist (a - b) a = norm b"
lp15@60307
  1245
  by (simp_all add: dist_norm)
lp15@60307
  1246
  
wenzelm@60758
  1247
subsection \<open>Bounded Linear and Bilinear Operators\<close>
huffman@22442
  1248
huffman@53600
  1249
locale linear = additive f for f :: "'a::real_vector \<Rightarrow> 'b::real_vector" +
huffman@22442
  1250
  assumes scaleR: "f (scaleR r x) = scaleR r (f x)"
huffman@53600
  1251
huffman@53600
  1252
lemma linearI:
huffman@53600
  1253
  assumes "\<And>x y. f (x + y) = f x + f y"
huffman@53600
  1254
  assumes "\<And>c x. f (c *\<^sub>R x) = c *\<^sub>R f x"
huffman@53600
  1255
  shows "linear f"
huffman@53600
  1256
  by default (rule assms)+
huffman@53600
  1257
huffman@53600
  1258
locale bounded_linear = linear f for f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector" +
huffman@22442
  1259
  assumes bounded: "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K"
huffman@27443
  1260
begin
huffman@22442
  1261
huffman@27443
  1262
lemma pos_bounded:
huffman@22442
  1263
  "\<exists>K>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
  1264
proof -
huffman@22442
  1265
  obtain K where K: "\<And>x. norm (f x) \<le> norm x * K"
huffman@22442
  1266
    using bounded by fast
huffman@22442
  1267
  show ?thesis
huffman@22442
  1268
  proof (intro exI impI conjI allI)
huffman@22442
  1269
    show "0 < max 1 K"
haftmann@54863
  1270
      by (rule order_less_le_trans [OF zero_less_one max.cobounded1])
huffman@22442
  1271
  next
huffman@22442
  1272
    fix x
huffman@22442
  1273
    have "norm (f x) \<le> norm x * K" using K .
huffman@22442
  1274
    also have "\<dots> \<le> norm x * max 1 K"
haftmann@54863
  1275
      by (rule mult_left_mono [OF max.cobounded2 norm_ge_zero])
huffman@22442
  1276
    finally show "norm (f x) \<le> norm x * max 1 K" .
huffman@22442
  1277
  qed
huffman@22442
  1278
qed
huffman@22442
  1279
huffman@27443
  1280
lemma nonneg_bounded:
huffman@22442
  1281
  "\<exists>K\<ge>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
  1282
proof -
huffman@22442
  1283
  from pos_bounded
huffman@22442
  1284
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
  1285
qed
huffman@22442
  1286
hoelzl@56369
  1287
lemma linear: "linear f" ..
hoelzl@56369
  1288
huffman@27443
  1289
end
huffman@27443
  1290
huffman@44127
  1291
lemma bounded_linear_intro:
huffman@44127
  1292
  assumes "\<And>x y. f (x + y) = f x + f y"
huffman@44127
  1293
  assumes "\<And>r x. f (scaleR r x) = scaleR r (f x)"
huffman@44127
  1294
  assumes "\<And>x. norm (f x) \<le> norm x * K"
huffman@44127
  1295
  shows "bounded_linear f"
huffman@44127
  1296
  by default (fast intro: assms)+
huffman@44127
  1297
huffman@22442
  1298
locale bounded_bilinear =
huffman@22442
  1299
  fixes prod :: "['a::real_normed_vector, 'b::real_normed_vector]
huffman@22442
  1300
                 \<Rightarrow> 'c::real_normed_vector"
huffman@22442
  1301
    (infixl "**" 70)
huffman@22442
  1302
  assumes add_left: "prod (a + a') b = prod a b + prod a' b"
huffman@22442
  1303
  assumes add_right: "prod a (b + b') = prod a b + prod a b'"
huffman@22442
  1304
  assumes scaleR_left: "prod (scaleR r a) b = scaleR r (prod a b)"
huffman@22442
  1305
  assumes scaleR_right: "prod a (scaleR r b) = scaleR r (prod a b)"
huffman@22442
  1306
  assumes bounded: "\<exists>K. \<forall>a b. norm (prod a b) \<le> norm a * norm b * K"
huffman@27443
  1307
begin
huffman@22442
  1308
huffman@27443
  1309
lemma pos_bounded:
huffman@22442
  1310
  "\<exists>K>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
  1311
apply (cut_tac bounded, erule exE)
huffman@22442
  1312
apply (rule_tac x="max 1 K" in exI, safe)
haftmann@54863
  1313
apply (rule order_less_le_trans [OF zero_less_one max.cobounded1])
huffman@22442
  1314
apply (drule spec, drule spec, erule order_trans)
haftmann@54863
  1315
apply (rule mult_left_mono [OF max.cobounded2])
huffman@22442
  1316
apply (intro mult_nonneg_nonneg norm_ge_zero)
huffman@22442
  1317
done
huffman@22442
  1318
huffman@27443
  1319
lemma nonneg_bounded:
huffman@22442
  1320
  "\<exists>K\<ge>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
  1321
proof -
huffman@22442
  1322
  from pos_bounded
huffman@22442
  1323
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
  1324
qed
huffman@22442
  1325
huffman@27443
  1326
lemma additive_right: "additive (\<lambda>b. prod a b)"
huffman@22442
  1327
by (rule additive.intro, rule add_right)
huffman@22442
  1328
huffman@27443
  1329
lemma additive_left: "additive (\<lambda>a. prod a b)"
huffman@22442
  1330
by (rule additive.intro, rule add_left)
huffman@22442
  1331
huffman@27443
  1332
lemma zero_left: "prod 0 b = 0"
huffman@22442
  1333
by (rule additive.zero [OF additive_left])
huffman@22442
  1334
huffman@27443
  1335
lemma zero_right: "prod a 0 = 0"
huffman@22442
  1336
by (rule additive.zero [OF additive_right])
huffman@22442
  1337
huffman@27443
  1338
lemma minus_left: "prod (- a) b = - prod a b"
huffman@22442
  1339
by (rule additive.minus [OF additive_left])
huffman@22442
  1340
huffman@27443
  1341
lemma minus_right: "prod a (- b) = - prod a b"
huffman@22442
  1342
by (rule additive.minus [OF additive_right])
huffman@22442
  1343
huffman@27443
  1344
lemma diff_left:
huffman@22442
  1345
  "prod (a - a') b = prod a b - prod a' b"
huffman@22442
  1346
by (rule additive.diff [OF additive_left])
huffman@22442
  1347
huffman@27443
  1348
lemma diff_right:
huffman@22442
  1349
  "prod a (b - b') = prod a b - prod a b'"
huffman@22442
  1350
by (rule additive.diff [OF additive_right])
huffman@22442
  1351
huffman@27443
  1352
lemma bounded_linear_left:
huffman@22442
  1353
  "bounded_linear (\<lambda>a. a ** b)"
huffman@44127
  1354
apply (cut_tac bounded, safe)
huffman@44127
  1355
apply (rule_tac K="norm b * K" in bounded_linear_intro)
huffman@22442
  1356
apply (rule add_left)
huffman@22442
  1357
apply (rule scaleR_left)
haftmann@57514
  1358
apply (simp add: ac_simps)
huffman@22442
  1359
done
huffman@22442
  1360
huffman@27443
  1361
lemma bounded_linear_right:
huffman@22442
  1362
  "bounded_linear (\<lambda>b. a ** b)"
huffman@44127
  1363
apply (cut_tac bounded, safe)
huffman@44127
  1364
apply (rule_tac K="norm a * K" in bounded_linear_intro)
huffman@22442
  1365
apply (rule add_right)
huffman@22442
  1366
apply (rule scaleR_right)
haftmann@57514
  1367
apply (simp add: ac_simps)
huffman@22442
  1368
done
huffman@22442
  1369
huffman@27443
  1370
lemma prod_diff_prod:
huffman@22442
  1371
  "(x ** y - a ** b) = (x - a) ** (y - b) + (x - a) ** b + a ** (y - b)"
huffman@22442
  1372
by (simp add: diff_left diff_right)
huffman@22442
  1373
huffman@27443
  1374
end
huffman@27443
  1375
hoelzl@51642
  1376
lemma bounded_linear_ident[simp]: "bounded_linear (\<lambda>x. x)"
hoelzl@51642
  1377
  by default (auto intro!: exI[of _ 1])
hoelzl@51642
  1378
hoelzl@51642
  1379
lemma bounded_linear_zero[simp]: "bounded_linear (\<lambda>x. 0)"
hoelzl@51642
  1380
  by default (auto intro!: exI[of _ 1])
hoelzl@51642
  1381
hoelzl@51642
  1382
lemma bounded_linear_add:
hoelzl@51642
  1383
  assumes "bounded_linear f"
hoelzl@51642
  1384
  assumes "bounded_linear g"
hoelzl@51642
  1385
  shows "bounded_linear (\<lambda>x. f x + g x)"
hoelzl@51642
  1386
proof -
hoelzl@51642
  1387
  interpret f: bounded_linear f by fact
hoelzl@51642
  1388
  interpret g: bounded_linear g by fact
hoelzl@51642
  1389
  show ?thesis
hoelzl@51642
  1390
  proof
hoelzl@51642
  1391
    from f.bounded obtain Kf where Kf: "\<And>x. norm (f x) \<le> norm x * Kf" by blast
hoelzl@51642
  1392
    from g.bounded obtain Kg where Kg: "\<And>x. norm (g x) \<le> norm x * Kg" by blast
hoelzl@51642
  1393
    show "\<exists>K. \<forall>x. norm (f x + g x) \<le> norm x * K"
hoelzl@51642
  1394
      using add_mono[OF Kf Kg]
hoelzl@51642
  1395
      by (intro exI[of _ "Kf + Kg"]) (auto simp: field_simps intro: norm_triangle_ineq order_trans)
hoelzl@51642
  1396
  qed (simp_all add: f.add g.add f.scaleR g.scaleR scaleR_right_distrib)
hoelzl@51642
  1397
qed
hoelzl@51642
  1398
hoelzl@51642
  1399
lemma bounded_linear_minus:
hoelzl@51642
  1400
  assumes "bounded_linear f"
hoelzl@51642
  1401
  shows "bounded_linear (\<lambda>x. - f x)"
hoelzl@51642
  1402
proof -
hoelzl@51642
  1403
  interpret f: bounded_linear f by fact
hoelzl@51642
  1404
  show ?thesis apply (unfold_locales)
hoelzl@51642
  1405
    apply (simp add: f.add)
hoelzl@51642
  1406
    apply (simp add: f.scaleR)
hoelzl@51642
  1407
    apply (simp add: f.bounded)
hoelzl@51642
  1408
    done
hoelzl@51642
  1409
qed
hoelzl@51642
  1410
hoelzl@51642
  1411
lemma bounded_linear_compose:
hoelzl@51642
  1412
  assumes "bounded_linear f"
hoelzl@51642
  1413
  assumes "bounded_linear g"
hoelzl@51642
  1414
  shows "bounded_linear (\<lambda>x. f (g x))"
hoelzl@51642
  1415
proof -
hoelzl@51642
  1416
  interpret f: bounded_linear f by fact
hoelzl@51642
  1417
  interpret g: bounded_linear g by fact
hoelzl@51642
  1418
  show ?thesis proof (unfold_locales)
hoelzl@51642
  1419
    fix x y show "f (g (x + y)) = f (g x) + f (g y)"
hoelzl@51642
  1420
      by (simp only: f.add g.add)
hoelzl@51642
  1421
  next
hoelzl@51642
  1422
    fix r x show "f (g (scaleR r x)) = scaleR r (f (g x))"
hoelzl@51642
  1423
      by (simp only: f.scaleR g.scaleR)
hoelzl@51642
  1424
  next
hoelzl@51642
  1425
    from f.pos_bounded
hoelzl@51642
  1426
    obtain Kf where f: "\<And>x. norm (f x) \<le> norm x * Kf" and Kf: "0 < Kf" by fast
hoelzl@51642
  1427
    from g.pos_bounded
hoelzl@51642
  1428
    obtain Kg where g: "\<And>x. norm (g x) \<le> norm x * Kg" by fast
hoelzl@51642
  1429
    show "\<exists>K. \<forall>x. norm (f (g x)) \<le> norm x * K"
hoelzl@51642
  1430
    proof (intro exI allI)
hoelzl@51642
  1431
      fix x
hoelzl@51642
  1432
      have "norm (f (g x)) \<le> norm (g x) * Kf"
hoelzl@51642
  1433
        using f .
hoelzl@51642
  1434
      also have "\<dots> \<le> (norm x * Kg) * Kf"
hoelzl@51642
  1435
        using g Kf [THEN order_less_imp_le] by (rule mult_right_mono)
hoelzl@51642
  1436
      also have "(norm x * Kg) * Kf = norm x * (Kg * Kf)"
haftmann@57512
  1437
        by (rule mult.assoc)
hoelzl@51642
  1438
      finally show "norm (f (g x)) \<le> norm x * (Kg * Kf)" .
hoelzl@51642
  1439
    qed
hoelzl@51642
  1440
  qed
hoelzl@51642
  1441
qed
hoelzl@51642
  1442
huffman@44282
  1443
lemma bounded_bilinear_mult:
huffman@44282
  1444
  "bounded_bilinear (op * :: 'a \<Rightarrow> 'a \<Rightarrow> 'a::real_normed_algebra)"
huffman@22442
  1445
apply (rule bounded_bilinear.intro)
webertj@49962
  1446
apply (rule distrib_right)
webertj@49962
  1447
apply (rule distrib_left)
huffman@22442
  1448
apply (rule mult_scaleR_left)
huffman@22442
  1449
apply (rule mult_scaleR_right)
huffman@22442
  1450
apply (rule_tac x="1" in exI)
huffman@22442
  1451
apply (simp add: norm_mult_ineq)
huffman@22442
  1452
done
huffman@22442
  1453
huffman@44282
  1454
lemma bounded_linear_mult_left:
huffman@44282
  1455
  "bounded_linear (\<lambda>x::'a::real_normed_algebra. x * y)"
huffman@44282
  1456
  using bounded_bilinear_mult
huffman@44282
  1457
  by (rule bounded_bilinear.bounded_linear_left)
huffman@22442
  1458
huffman@44282
  1459
lemma bounded_linear_mult_right:
huffman@44282
  1460
  "bounded_linear (\<lambda>y::'a::real_normed_algebra. x * y)"
huffman@44282
  1461
  using bounded_bilinear_mult
huffman@44282
  1462
  by (rule bounded_bilinear.bounded_linear_right)
huffman@23127
  1463
hoelzl@51642
  1464
lemmas bounded_linear_mult_const =
hoelzl@51642
  1465
  bounded_linear_mult_left [THEN bounded_linear_compose]
hoelzl@51642
  1466
hoelzl@51642
  1467
lemmas bounded_linear_const_mult =
hoelzl@51642
  1468
  bounded_linear_mult_right [THEN bounded_linear_compose]
hoelzl@51642
  1469
huffman@44282
  1470
lemma bounded_linear_divide:
huffman@44282
  1471
  "bounded_linear (\<lambda>x::'a::real_normed_field. x / y)"
huffman@44282
  1472
  unfolding divide_inverse by (rule bounded_linear_mult_left)
huffman@23120
  1473
huffman@44282
  1474
lemma bounded_bilinear_scaleR: "bounded_bilinear scaleR"
huffman@22442
  1475
apply (rule bounded_bilinear.intro)
huffman@22442
  1476
apply (rule scaleR_left_distrib)
huffman@22442
  1477
apply (rule scaleR_right_distrib)
huffman@22973
  1478
apply simp
huffman@22442
  1479
apply (rule scaleR_left_commute)
huffman@31586
  1480
apply (rule_tac x="1" in exI, simp)
huffman@22442
  1481
done
huffman@22442
  1482
huffman@44282
  1483
lemma bounded_linear_scaleR_left: "bounded_linear (\<lambda>r. scaleR r x)"
huffman@44282
  1484
  using bounded_bilinear_scaleR
huffman@44282
  1485
  by (rule bounded_bilinear.bounded_linear_left)
huffman@23127
  1486
huffman@44282
  1487
lemma bounded_linear_scaleR_right: "bounded_linear (\<lambda>x. scaleR r x)"
huffman@44282
  1488
  using bounded_bilinear_scaleR
huffman@44282
  1489
  by (rule bounded_bilinear.bounded_linear_right)
huffman@23127
  1490
huffman@44282
  1491
lemma bounded_linear_of_real: "bounded_linear (\<lambda>r. of_real r)"
huffman@44282
  1492
  unfolding of_real_def by (rule bounded_linear_scaleR_left)
huffman@22625
  1493
hoelzl@51642
  1494
lemma real_bounded_linear:
hoelzl@51642
  1495
  fixes f :: "real \<Rightarrow> real"
hoelzl@51642
  1496
  shows "bounded_linear f \<longleftrightarrow> (\<exists>c::real. f = (\<lambda>x. x * c))"
hoelzl@51642
  1497
proof -
hoelzl@51642
  1498
  { fix x assume "bounded_linear f"
hoelzl@51642
  1499
    then interpret bounded_linear f .
hoelzl@51642
  1500
    from scaleR[of x 1] have "f x = x * f 1"
hoelzl@51642
  1501
      by simp }
hoelzl@51642
  1502
  then show ?thesis
hoelzl@51642
  1503
    by (auto intro: exI[of _ "f 1"] bounded_linear_mult_left)
hoelzl@51642
  1504
qed
hoelzl@51642
  1505
huffman@44571
  1506
instance real_normed_algebra_1 \<subseteq> perfect_space
huffman@44571
  1507
proof
huffman@44571
  1508
  fix x::'a
huffman@44571
  1509
  show "\<not> open {x}"
huffman@44571
  1510
    unfolding open_dist dist_norm
huffman@44571
  1511
    by (clarsimp, rule_tac x="x + of_real (e/2)" in exI, simp)
huffman@44571
  1512
qed
huffman@44571
  1513
wenzelm@60758
  1514
subsection \<open>Filters and Limits on Metric Space\<close>
hoelzl@51531
  1515
hoelzl@57448
  1516
lemma (in metric_space) nhds_metric: "nhds x = (INF e:{0 <..}. principal {y. dist y x < e})"
hoelzl@57448
  1517
  unfolding nhds_def
hoelzl@57448
  1518
proof (safe intro!: INF_eq)
hoelzl@57448
  1519
  fix S assume "open S" "x \<in> S"
hoelzl@57448
  1520
  then obtain e where "{y. dist y x < e} \<subseteq> S" "0 < e"
hoelzl@57448
  1521
    by (auto simp: open_dist subset_eq)
hoelzl@57448
  1522
  then show "\<exists>e\<in>{0<..}. principal {y. dist y x < e} \<le> principal S"
hoelzl@57448
  1523
    by auto
hoelzl@57448
  1524
qed (auto intro!: exI[of _ "{y. dist x y < e}" for e] open_ball simp: dist_commute)
hoelzl@57448
  1525
hoelzl@57448
  1526
lemma (in metric_space) tendsto_iff:
hoelzl@57448
  1527
  "(f ---> l) F \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) F)"
hoelzl@57448
  1528
  unfolding nhds_metric filterlim_INF filterlim_principal by auto
hoelzl@57448
  1529
hoelzl@57448
  1530
lemma (in metric_space) tendstoI: "(\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F) \<Longrightarrow> (f ---> l) F"
hoelzl@57448
  1531
  by (auto simp: tendsto_iff)
hoelzl@57448
  1532
hoelzl@57448
  1533
lemma (in metric_space) tendstoD: "(f ---> l) F \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
hoelzl@57448
  1534
  by (auto simp: tendsto_iff)
hoelzl@57448
  1535
hoelzl@57448
  1536
lemma (in metric_space) eventually_nhds_metric:
hoelzl@57448
  1537
  "eventually P (nhds a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. dist x a < d \<longrightarrow> P x)"
hoelzl@57448
  1538
  unfolding nhds_metric
hoelzl@57448
  1539
  by (subst eventually_INF_base)
hoelzl@57448
  1540
     (auto simp: eventually_principal Bex_def subset_eq intro: exI[of _ "min a b" for a b])
hoelzl@51531
  1541
hoelzl@51531
  1542
lemma eventually_at:
hoelzl@51641
  1543
  fixes a :: "'a :: metric_space"
hoelzl@51641
  1544
  shows "eventually P (at a within S) \<longleftrightarrow> (\<exists>d>0. \<forall>x\<in>S. x \<noteq> a \<and> dist x a < d \<longrightarrow> P x)"
hoelzl@51641
  1545
  unfolding eventually_at_filter eventually_nhds_metric by (auto simp: dist_nz)
hoelzl@51531
  1546
hoelzl@51641
  1547
lemma eventually_at_le:
hoelzl@51641
  1548
  fixes a :: "'a::metric_space"
hoelzl@51641
  1549
  shows "eventually P (at a within S) \<longleftrightarrow> (\<exists>d>0. \<forall>x\<in>S. x \<noteq> a \<and> dist x a \<le> d \<longrightarrow> P x)"
hoelzl@51641
  1550
  unfolding eventually_at_filter eventually_nhds_metric
hoelzl@51641
  1551
  apply auto
hoelzl@51641
  1552
  apply (rule_tac x="d / 2" in exI)
hoelzl@51641
  1553
  apply auto
hoelzl@51641
  1554
  done
hoelzl@51531
  1555
hoelzl@51531
  1556
lemma metric_tendsto_imp_tendsto:
hoelzl@51531
  1557
  fixes a :: "'a :: metric_space" and b :: "'b :: metric_space"
hoelzl@51531
  1558
  assumes f: "(f ---> a) F"
hoelzl@51531
  1559
  assumes le: "eventually (\<lambda>x. dist (g x) b \<le> dist (f x) a) F"
hoelzl@51531
  1560
  shows "(g ---> b) F"
hoelzl@51531
  1561
proof (rule tendstoI)
hoelzl@51531
  1562
  fix e :: real assume "0 < e"
hoelzl@51531
  1563
  with f have "eventually (\<lambda>x. dist (f x) a < e) F" by (rule tendstoD)
hoelzl@51531
  1564
  with le show "eventually (\<lambda>x. dist (g x) b < e) F"
hoelzl@51531
  1565
    using le_less_trans by (rule eventually_elim2)
hoelzl@51531
  1566
qed
hoelzl@51531
  1567
hoelzl@51531
  1568
lemma filterlim_real_sequentially: "LIM x sequentially. real x :> at_top"
hoelzl@51531
  1569
  unfolding filterlim_at_top
hoelzl@51531
  1570
  apply (intro allI)
nipkow@59587
  1571
  apply (rule_tac c="nat(ceiling (Z + 1))" in eventually_sequentiallyI)
nipkow@59587
  1572
  by linarith
hoelzl@51531
  1573
wenzelm@60758
  1574
subsubsection \<open>Limits of Sequences\<close>
hoelzl@51531
  1575
lp15@60017
  1576
lemma lim_sequentially: "X ----> (L::'a::metric_space) \<longleftrightarrow> (\<forall>r>0. \<exists>no. \<forall>n\<ge>no. dist (X n) L < r)"
hoelzl@51531
  1577
  unfolding tendsto_iff eventually_sequentially ..
hoelzl@51531
  1578
lp15@60026
  1579
lemmas LIMSEQ_def = lim_sequentially  (*legacy binding*)
lp15@60026
  1580
hoelzl@51531
  1581
lemma LIMSEQ_iff_nz: "X ----> (L::'a::metric_space) = (\<forall>r>0. \<exists>no>0. \<forall>n\<ge>no. dist (X n) L < r)"
lp15@60017
  1582
  unfolding lim_sequentially by (metis Suc_leD zero_less_Suc)
hoelzl@51531
  1583
hoelzl@51531
  1584
lemma metric_LIMSEQ_I:
hoelzl@51531
  1585
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. dist (X n) L < r) \<Longrightarrow> X ----> (L::'a::metric_space)"
lp15@60017
  1586
by (simp add: lim_sequentially)
hoelzl@51531
  1587
hoelzl@51531
  1588
lemma metric_LIMSEQ_D:
hoelzl@51531
  1589
  "\<lbrakk>X ----> (L::'a::metric_space); 0 < r\<rbrakk> \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. dist (X n) L < r"
lp15@60017
  1590
by (simp add: lim_sequentially)
hoelzl@51531
  1591
hoelzl@51531
  1592
wenzelm@60758
  1593
subsubsection \<open>Limits of Functions\<close>
hoelzl@51531
  1594
hoelzl@51531
  1595
lemma LIM_def: "f -- (a::'a::metric_space) --> (L::'b::metric_space) =
hoelzl@51531
  1596
     (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & dist x a < s
hoelzl@51531
  1597
        --> dist (f x) L < r)"
hoelzl@51641
  1598
  unfolding tendsto_iff eventually_at by simp
hoelzl@51531
  1599
hoelzl@51531
  1600
lemma metric_LIM_I:
hoelzl@51531
  1601
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x) L < r)
hoelzl@51531
  1602
    \<Longrightarrow> f -- (a::'a::metric_space) --> (L::'b::metric_space)"
hoelzl@51531
  1603
by (simp add: LIM_def)
hoelzl@51531
  1604
hoelzl@51531
  1605
lemma metric_LIM_D:
hoelzl@51531
  1606
  "\<lbrakk>f -- (a::'a::metric_space) --> (L::'b::metric_space); 0 < r\<rbrakk>
hoelzl@51531
  1607
    \<Longrightarrow> \<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x) L < r"
hoelzl@51531
  1608
by (simp add: LIM_def)
hoelzl@51531
  1609
hoelzl@51531
  1610
lemma metric_LIM_imp_LIM:
hoelzl@51531
  1611
  assumes f: "f -- a --> (l::'a::metric_space)"
hoelzl@51531
  1612
  assumes le: "\<And>x. x \<noteq> a \<Longrightarrow> dist (g x) m \<le> dist (f x) l"
hoelzl@51531
  1613
  shows "g -- a --> (m::'b::metric_space)"
hoelzl@51531
  1614
  by (rule metric_tendsto_imp_tendsto [OF f]) (auto simp add: eventually_at_topological le)
hoelzl@51531
  1615
hoelzl@51531
  1616
lemma metric_LIM_equal2:
hoelzl@51531
  1617
  assumes 1: "0 < R"
hoelzl@51531
  1618
  assumes 2: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < R\<rbrakk> \<Longrightarrow> f x = g x"
hoelzl@51531
  1619
  shows "g -- a --> l \<Longrightarrow> f -- (a::'a::metric_space) --> l"
hoelzl@51531
  1620
apply (rule topological_tendstoI)
hoelzl@51531
  1621
apply (drule (2) topological_tendstoD)
hoelzl@51531
  1622
apply (simp add: eventually_at, safe)
hoelzl@51531
  1623
apply (rule_tac x="min d R" in exI, safe)
hoelzl@51531
  1624
apply (simp add: 1)
hoelzl@51531
  1625
apply (simp add: 2)
hoelzl@51531
  1626
done
hoelzl@51531
  1627
hoelzl@51531
  1628
lemma metric_LIM_compose2:
hoelzl@51531
  1629
  assumes f: "f -- (a::'a::metric_space) --> b"
hoelzl@51531
  1630
  assumes g: "g -- b --> c"
hoelzl@51531
  1631
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> b"
hoelzl@51531
  1632
  shows "(\<lambda>x. g (f x)) -- a --> c"
hoelzl@51641
  1633
  using inj
hoelzl@51641
  1634
  by (intro tendsto_compose_eventually[OF g f]) (auto simp: eventually_at)
hoelzl@51531
  1635
hoelzl@51531
  1636
lemma metric_isCont_LIM_compose2:
hoelzl@51531
  1637
  fixes f :: "'a :: metric_space \<Rightarrow> _"
hoelzl@51531
  1638
  assumes f [unfolded isCont_def]: "isCont f a"
hoelzl@51531
  1639
  assumes g: "g -- f a --> l"
hoelzl@51531
  1640
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> f a"
hoelzl@51531
  1641
  shows "(\<lambda>x. g (f x)) -- a --> l"
hoelzl@51531
  1642
by (rule metric_LIM_compose2 [OF f g inj])
hoelzl@51531
  1643
wenzelm@60758
  1644
subsection \<open>Complete metric spaces\<close>
hoelzl@51531
  1645
wenzelm@60758
  1646
subsection \<open>Cauchy sequences\<close>
hoelzl@51531
  1647
hoelzl@51531
  1648
definition (in metric_space) Cauchy :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool" where
hoelzl@51531
  1649
  "Cauchy X = (\<forall>e>0. \<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. dist (X m) (X n) < e)"
hoelzl@51531
  1650
wenzelm@60758
  1651
subsection \<open>Cauchy Sequences\<close>
hoelzl@51531
  1652
hoelzl@51531
  1653
lemma metric_CauchyI:
hoelzl@51531
  1654
  "(\<And>e. 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < e) \<Longrightarrow> Cauchy X"
hoelzl@51531
  1655
  by (simp add: Cauchy_def)
hoelzl@51531
  1656
hoelzl@51531
  1657
lemma metric_CauchyD:
hoelzl@51531
  1658
  "Cauchy X \<Longrightarrow> 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < e"
hoelzl@51531
  1659
  by (simp add: Cauchy_def)
hoelzl@51531
  1660
hoelzl@51531
  1661
lemma metric_Cauchy_iff2:
hoelzl@51531
  1662
  "Cauchy X = (\<forall>j. (\<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. dist (X m) (X n) < inverse(real (Suc j))))"
hoelzl@51531
  1663
apply (simp add: Cauchy_def, auto)
hoelzl@51531
  1664
apply (drule reals_Archimedean, safe)
hoelzl@51531
  1665
apply (drule_tac x = n in spec, auto)
hoelzl@51531
  1666
apply (rule_tac x = M in exI, auto)
hoelzl@51531
  1667
apply (drule_tac x = m in spec, simp)
hoelzl@51531
  1668
apply (drule_tac x = na in spec, auto)
hoelzl@51531
  1669
done
hoelzl@51531
  1670
hoelzl@51531
  1671
lemma Cauchy_iff2:
hoelzl@51531
  1672
  "Cauchy X = (\<forall>j. (\<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. \<bar>X m - X n\<bar> < inverse(real (Suc j))))"
hoelzl@51531
  1673
  unfolding metric_Cauchy_iff2 dist_real_def ..
hoelzl@51531
  1674
hoelzl@51531
  1675
lemma Cauchy_subseq_Cauchy:
hoelzl@51531
  1676
  "\<lbrakk> Cauchy X; subseq f \<rbrakk> \<Longrightarrow> Cauchy (X o f)"
hoelzl@51531
  1677
apply (auto simp add: Cauchy_def)
hoelzl@51531
  1678
apply (drule_tac x=e in spec, clarify)
hoelzl@51531
  1679
apply (rule_tac x=M in exI, clarify)
hoelzl@51531
  1680
apply (blast intro: le_trans [OF _ seq_suble] dest!: spec)
hoelzl@51531
  1681
done
hoelzl@51531
  1682
hoelzl@51531
  1683
theorem LIMSEQ_imp_Cauchy:
hoelzl@51531
  1684
  assumes X: "X ----> a" shows "Cauchy X"
hoelzl@51531
  1685
proof (rule metric_CauchyI)
hoelzl@51531
  1686
  fix e::real assume "0 < e"
hoelzl@51531
  1687
  hence "0 < e/2" by simp
hoelzl@51531
  1688
  with X have "\<exists>N. \<forall>n\<ge>N. dist (X n) a < e/2" by (rule metric_LIMSEQ_D)
hoelzl@51531
  1689
  then obtain N where N: "\<forall>n\<ge>N. dist (X n) a < e/2" ..
hoelzl@51531
  1690
  show "\<exists>N. \<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m) (X n) < e"
hoelzl@51531
  1691
  proof (intro exI allI impI)
hoelzl@51531
  1692
    fix m assume "N \<le> m"
hoelzl@51531
  1693
    hence m: "dist (X m) a < e/2" using N by fast
hoelzl@51531
  1694
    fix n assume "N \<le> n"
hoelzl@51531
  1695
    hence n: "dist (X n) a < e/2" using N by fast
hoelzl@51531
  1696
    have "dist (X m) (X n) \<le> dist (X m) a + dist (X n) a"
hoelzl@51531
  1697
      by (rule dist_triangle2)
hoelzl@51531
  1698
    also from m n have "\<dots> < e" by simp
hoelzl@51531
  1699
    finally show "dist (X m) (X n) < e" .
hoelzl@51531
  1700
  qed
hoelzl@51531
  1701
qed
hoelzl@51531
  1702
hoelzl@51531
  1703
lemma convergent_Cauchy: "convergent X \<Longrightarrow> Cauchy X"
hoelzl@51531
  1704
unfolding convergent_def
hoelzl@51531
  1705
by (erule exE, erule LIMSEQ_imp_Cauchy)
hoelzl@51531
  1706
wenzelm@60758
  1707
subsubsection \<open>Cauchy Sequences are Convergent\<close>
hoelzl@51531
  1708
hoelzl@51531
  1709
class complete_space = metric_space +
hoelzl@51531
  1710
  assumes Cauchy_convergent: "Cauchy X \<Longrightarrow> convergent X"
hoelzl@51531
  1711
hoelzl@51531
  1712
lemma Cauchy_convergent_iff:
hoelzl@51531
  1713
  fixes X :: "nat \<Rightarrow> 'a::complete_space"
hoelzl@51531
  1714
  shows "Cauchy X = convergent X"
hoelzl@51531
  1715
by (fast intro: Cauchy_convergent convergent_Cauchy)
hoelzl@51531
  1716
wenzelm@60758
  1717
subsection \<open>The set of real numbers is a complete metric space\<close>
hoelzl@51531
  1718
wenzelm@60758
  1719
text \<open>
hoelzl@51531
  1720
Proof that Cauchy sequences converge based on the one from
wenzelm@54703
  1721
@{url "http://pirate.shu.edu/~wachsmut/ira/numseq/proofs/cauconv.html"}
wenzelm@60758
  1722
\<close>
hoelzl@51531
  1723
wenzelm@60758
  1724
text \<open>
hoelzl@51531
  1725
  If sequence @{term "X"} is Cauchy, then its limit is the lub of
hoelzl@51531
  1726
  @{term "{r::real. \<exists>N. \<forall>n\<ge>N. r < X n}"}
wenzelm@60758
  1727
\<close>
hoelzl@51531
  1728
hoelzl@51531
  1729
lemma increasing_LIMSEQ:
hoelzl@51531
  1730
  fixes f :: "nat \<Rightarrow> real"
hoelzl@51531
  1731
  assumes inc: "\<And>n. f n \<le> f (Suc n)"
hoelzl@51531
  1732
      and bdd: "\<And>n. f n \<le> l"
hoelzl@51531
  1733
      and en: "\<And>e. 0 < e \<Longrightarrow> \<exists>n. l \<le> f n + e"
hoelzl@51531
  1734
  shows "f ----> l"
hoelzl@51531
  1735
proof (rule increasing_tendsto)
hoelzl@51531
  1736
  fix x assume "x < l"
hoelzl@51531
  1737
  with dense[of 0 "l - x"] obtain e where "0 < e" "e < l - x"
hoelzl@51531
  1738
    by auto
wenzelm@60758
  1739
  from en[OF \<open>0 < e\<close>] obtain n where "l - e \<le> f n"
hoelzl@51531
  1740
    by (auto simp: field_simps)
wenzelm@60758
  1741
  with \<open>e < l - x\<close> \<open>0 < e\<close> have "x < f n" by simp
hoelzl@51531
  1742
  with incseq_SucI[of f, OF inc] show "eventually (\<lambda>n. x < f n) sequentially"
hoelzl@51531
  1743
    by (auto simp: eventually_sequentially incseq_def intro: less_le_trans)
hoelzl@51531
  1744
qed (insert bdd, auto)
hoelzl@51531
  1745
hoelzl@51531
  1746
lemma real_Cauchy_convergent:
hoelzl@51531
  1747
  fixes X :: "nat \<Rightarrow> real"
hoelzl@51531
  1748
  assumes X: "Cauchy X"
hoelzl@51531
  1749
  shows "convergent X"
hoelzl@51531
  1750
proof -
hoelzl@51531
  1751
  def S \<equiv> "{x::real. \<exists>N. \<forall>n\<ge>N. x < X n}"
hoelzl@51531
  1752
  then have mem_S: "\<And>N x. \<forall>n\<ge>N. x < X n \<Longrightarrow> x \<in> S" by auto
hoelzl@51531
  1753
hoelzl@51531
  1754
  { fix N x assume N: "\<forall>n\<ge>N. X n < x"
hoelzl@51531
  1755
  fix y::real assume "y \<in> S"
hoelzl@51531
  1756
  hence "\<exists>M. \<forall>n\<ge>M. y < X n"
hoelzl@51531
  1757
    by (simp add: S_def)
hoelzl@51531
  1758
  then obtain M where "\<forall>n\<ge>M. y < X n" ..
hoelzl@51531
  1759
  hence "y < X (max M N)" by simp
hoelzl@51531
  1760
  also have "\<dots> < x" using N by simp
hoelzl@54263
  1761
  finally have "y \<le> x"
hoelzl@54263
  1762
    by (rule order_less_imp_le) }
lp15@60026
  1763
  note bound_isUb = this
hoelzl@51531
  1764
hoelzl@51531
  1765
  obtain N where "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m) (X n) < 1"
hoelzl@51531
  1766
    using X[THEN metric_CauchyD, OF zero_less_one] by auto
hoelzl@51531
  1767
  hence N: "\<forall>n\<ge>N. dist (X n) (X N) < 1" by simp
hoelzl@54263
  1768
  have [simp]: "S \<noteq> {}"
hoelzl@54263
  1769
  proof (intro exI ex_in_conv[THEN iffD1])
hoelzl@51531
  1770
    from N have "\<forall>n\<ge>N. X N - 1 < X n"
hoelzl@51531
  1771
      by (simp add: abs_diff_less_iff dist_real_def)
hoelzl@51531
  1772
    thus "X N - 1 \<in> S" by (rule mem_S)
hoelzl@51531
  1773
  qed
hoelzl@54263
  1774
  have [simp]: "bdd_above S"
hoelzl@51531
  1775
  proof
hoelzl@51531
  1776
    from N have "\<forall>n\<ge>N. X n < X N + 1"
hoelzl@51531
  1777
      by (simp add: abs_diff_less_iff dist_real_def)
hoelzl@54263
  1778
    thus "\<And>s. s \<in> S \<Longrightarrow>  s \<le> X N + 1"
hoelzl@51531
  1779
      by (rule bound_isUb)
hoelzl@51531
  1780
  qed
hoelzl@54263
  1781
  have "X ----> Sup S"
hoelzl@51531
  1782
  proof (rule metric_LIMSEQ_I)
hoelzl@51531
  1783
  fix r::real assume "0 < r"
hoelzl@51531
  1784
  hence r: "0 < r/2" by simp
hoelzl@51531
  1785
  obtain N where "\<forall>n\<ge>N. \<forall>m\<ge>N. dist (X n) (X m) < r/2"
hoelzl@51531
  1786
    using metric_CauchyD [OF X r] by auto
hoelzl@51531
  1787
  hence "\<forall>n\<ge>N. dist (X n) (X N) < r/2" by simp
hoelzl@51531
  1788
  hence N: "\<forall>n\<ge>N. X N - r/2 < X n \<and> X n < X N + r/2"
hoelzl@51531
  1789
    by (simp only: dist_real_def abs_diff_less_iff)
hoelzl@51531
  1790
hoelzl@51531
  1791
  from N have "\<forall>n\<ge>N. X N - r/2 < X n" by fast
hoelzl@51531
  1792
  hence "X N - r/2 \<in> S" by (rule mem_S)
hoelzl@54263
  1793
  hence 1: "X N - r/2 \<le> Sup S" by (simp add: cSup_upper)
hoelzl@51531
  1794
hoelzl@51531
  1795
  from N have "\<forall>n\<ge>N. X n < X N + r/2" by fast
hoelzl@54263
  1796
  from bound_isUb[OF this]
hoelzl@54263
  1797
  have 2: "Sup S \<le> X N + r/2"
hoelzl@54263
  1798
    by (intro cSup_least) simp_all
hoelzl@51531
  1799
hoelzl@54263
  1800
  show "\<exists>N. \<forall>n\<ge>N. dist (X n) (Sup S) < r"
hoelzl@51531
  1801
  proof (intro exI allI impI)
hoelzl@51531
  1802
    fix n assume n: "N \<le> n"
hoelzl@51531
  1803
    from N n have "X n < X N + r/2" and "X N - r/2 < X n" by simp+
hoelzl@54263
  1804
    thus "dist (X n) (Sup S) < r" using 1 2
hoelzl@51531
  1805
      by (simp add: abs_diff_less_iff dist_real_def)
hoelzl@51531
  1806
  qed
hoelzl@51531
  1807
  qed
hoelzl@51531
  1808
  then show ?thesis unfolding convergent_def by auto
hoelzl@51531
  1809
qed
hoelzl@51531
  1810
hoelzl@51531
  1811
instance real :: complete_space
hoelzl@51531
  1812
  by intro_classes (rule real_Cauchy_convergent)
hoelzl@51531
  1813
hoelzl@51531
  1814
class banach = real_normed_vector + complete_space
hoelzl@51531
  1815
hoelzl@51531
  1816
instance real :: banach by default
hoelzl@51531
  1817
hoelzl@51531
  1818
lemma tendsto_at_topI_sequentially:
hoelzl@57275
  1819
  fixes f :: "real \<Rightarrow> 'b::first_countable_topology"
hoelzl@57275
  1820
  assumes *: "\<And>X. filterlim X at_top sequentially \<Longrightarrow> (\<lambda>n. f (X n)) ----> y"
hoelzl@57275
  1821
  shows "(f ---> y) at_top"
hoelzl@57448
  1822
proof -
hoelzl@57448
  1823
  from nhds_countable[of y] guess A . note A = this
hoelzl@57275
  1824
hoelzl@57448
  1825
  have "\<forall>m. \<exists>k. \<forall>x\<ge>k. f x \<in> A m"
hoelzl@57448
  1826
  proof (rule ccontr)
hoelzl@57448
  1827
    assume "\<not> (\<forall>m. \<exists>k. \<forall>x\<ge>k. f x \<in> A m)"
hoelzl@57448
  1828
    then obtain m where "\<And>k. \<exists>x\<ge>k. f x \<notin> A m"
hoelzl@57448
  1829
      by auto
hoelzl@57448
  1830
    then have "\<exists>X. \<forall>n. (f (X n) \<notin> A m) \<and> max n (X n) + 1 \<le> X (Suc n)"
hoelzl@57448
  1831
      by (intro dependent_nat_choice) (auto simp del: max.bounded_iff)
hoelzl@57448
  1832
    then obtain X where X: "\<And>n. f (X n) \<notin> A m" "\<And>n. max n (X n) + 1 \<le> X (Suc n)"
hoelzl@57448
  1833
      by auto
hoelzl@57448
  1834
    { fix n have "1 \<le> n \<longrightarrow> real n \<le> X n"
hoelzl@57448
  1835
        using X[of "n - 1"] by auto }
hoelzl@57448
  1836
    then have "filterlim X at_top sequentially"
hoelzl@57448
  1837
      by (force intro!: filterlim_at_top_mono[OF filterlim_real_sequentially]
hoelzl@57448
  1838
                simp: eventually_sequentially)
hoelzl@57448
  1839
    from topological_tendstoD[OF *[OF this] A(2, 3), of m] X(1) show False
hoelzl@57448
  1840
      by auto
hoelzl@57275
  1841
  qed
hoelzl@57448
  1842
  then obtain k where "\<And>m x. k m \<le> x \<Longrightarrow> f x \<in> A m"
hoelzl@57448
  1843
    by metis
hoelzl@57448
  1844
  then show ?thesis
hoelzl@57448
  1845
    unfolding at_top_def A
hoelzl@57448
  1846
    by (intro filterlim_base[where i=k]) auto
hoelzl@57275
  1847
qed
hoelzl@57275
  1848
hoelzl@57275
  1849
lemma tendsto_at_topI_sequentially_real:
hoelzl@51531
  1850
  fixes f :: "real \<Rightarrow> real"
hoelzl@51531
  1851
  assumes mono: "mono f"
hoelzl@51531
  1852
  assumes limseq: "(\<lambda>n. f (real n)) ----> y"
hoelzl@51531
  1853
  shows "(f ---> y) at_top"
hoelzl@51531
  1854
proof (rule tendstoI)
hoelzl@51531
  1855
  fix e :: real assume "0 < e"
hoelzl@51531
  1856
  with limseq obtain N :: nat where N: "\<And>n. N \<le> n \<Longrightarrow> \<bar>f (real n) - y\<bar> < e"
lp15@60017
  1857
    by (auto simp: lim_sequentially dist_real_def)
hoelzl@51531
  1858
  { fix x :: real
wenzelm@53381
  1859
    obtain n where "x \<le> real_of_nat n"
wenzelm@53381
  1860
      using ex_le_of_nat[of x] ..
hoelzl@51531
  1861
    note monoD[OF mono this]
hoelzl@51531
  1862
    also have "f (real_of_nat n) \<le> y"
hoelzl@51531
  1863
      by (rule LIMSEQ_le_const[OF limseq])
hoelzl@51531
  1864
         (auto intro: exI[of _ n] monoD[OF mono] simp: real_eq_of_nat[symmetric])
hoelzl@51531
  1865
    finally have "f x \<le> y" . }
hoelzl@51531
  1866
  note le = this
hoelzl@51531
  1867
  have "eventually (\<lambda>x. real N \<le> x) at_top"
hoelzl@51531
  1868
    by (rule eventually_ge_at_top)
hoelzl@51531
  1869
  then show "eventually (\<lambda>x. dist (f x) y < e) at_top"
hoelzl@51531
  1870
  proof eventually_elim
hoelzl@51531
  1871
    fix x assume N': "real N \<le> x"
hoelzl@51531
  1872
    with N[of N] le have "y - f (real N) < e" by auto
hoelzl@51531
  1873
    moreover note monoD[OF mono N']
hoelzl@51531
  1874
    ultimately show "dist (f x) y < e"
hoelzl@51531
  1875
      using le[of x] by (auto simp: dist_real_def field_simps)
hoelzl@51531
  1876
  qed
hoelzl@51531
  1877
qed
hoelzl@51531
  1878
huffman@20504
  1879
end
hoelzl@57276
  1880