src/HOL/Real_Vector_Spaces.thy
author hoelzl
Tue Apr 09 14:04:47 2013 +0200 (2013-04-09)
changeset 51642 400ec5ae7f8f
parent 51641 cd05e9fcc63d
child 51774 916271d52466
permissions -rw-r--r--
move FrechetDeriv from the Library to HOL/Deriv; base DERIV on FDERIV and both derivatives allow a restricted support set; FDERIV is now an abbreviation of has_derivative
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
huffman@20504
     6
header {* Vector Spaces and Algebras over the Reals *}
huffman@20504
     7
hoelzl@51524
     8
theory Real_Vector_Spaces
hoelzl@51531
     9
imports Real Topological_Spaces
huffman@20504
    10
begin
huffman@20504
    11
huffman@20504
    12
subsection {* Locale for additive functions *}
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@37887
    34
by (simp add: add minus diff_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
huffman@28029
    46
subsection {* Vector spaces *}
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)"
huffman@28029
    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
huffman@20504
   134
subsection {* Real vector spaces *}
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
huffman@28009
   162
text {* Recover original theorem names *}
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
huffman@44282
   179
text {* Legacy names *}
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@36409
   224
  fixes x :: "'a::{real_div_algebra, division_ring_inverse_zero}"
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
huffman@20554
   232
subsection {* Embedding of the Reals into any @{text real_algebra_1}:
huffman@20554
   233
@{term of_real} *}
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"
huffman@20763
   258
by (simp add: of_real_def mult_commute)
huffman@20554
   259
huffman@20584
   260
lemma nonzero_of_real_inverse:
huffman@20584
   261
  "x \<noteq> 0 \<Longrightarrow> of_real (inverse x) =
huffman@20584
   262
   inverse (of_real x :: 'a::real_div_algebra)"
huffman@20584
   263
by (simp add: of_real_def nonzero_inverse_scaleR_distrib)
huffman@20584
   264
huffman@20584
   265
lemma of_real_inverse [simp]:
huffman@20584
   266
  "of_real (inverse x) =
haftmann@36409
   267
   inverse (of_real x :: 'a::{real_div_algebra, division_ring_inverse_zero})"
huffman@20584
   268
by (simp add: of_real_def inverse_scaleR_distrib)
huffman@20584
   269
huffman@20584
   270
lemma nonzero_of_real_divide:
huffman@20584
   271
  "y \<noteq> 0 \<Longrightarrow> of_real (x / y) =
huffman@20584
   272
   (of_real x / of_real y :: 'a::real_field)"
huffman@20584
   273
by (simp add: divide_inverse nonzero_of_real_inverse)
huffman@20722
   274
huffman@20722
   275
lemma of_real_divide [simp]:
huffman@20584
   276
  "of_real (x / y) =
haftmann@36409
   277
   (of_real x / of_real y :: 'a::{real_field, field_inverse_zero})"
huffman@20584
   278
by (simp add: divide_inverse)
huffman@20584
   279
huffman@20722
   280
lemma of_real_power [simp]:
haftmann@31017
   281
  "of_real (x ^ n) = (of_real x :: 'a::{real_algebra_1}) ^ n"
huffman@30273
   282
by (induct n) simp_all
huffman@20722
   283
huffman@20554
   284
lemma of_real_eq_iff [simp]: "(of_real x = of_real y) = (x = y)"
huffman@35216
   285
by (simp add: of_real_def)
huffman@20554
   286
haftmann@38621
   287
lemma inj_of_real:
haftmann@38621
   288
  "inj of_real"
haftmann@38621
   289
  by (auto intro: injI)
haftmann@38621
   290
huffman@20584
   291
lemmas of_real_eq_0_iff [simp] = of_real_eq_iff [of _ 0, simplified]
huffman@20554
   292
huffman@20554
   293
lemma of_real_eq_id [simp]: "of_real = (id :: real \<Rightarrow> real)"
huffman@20554
   294
proof
huffman@20554
   295
  fix r
huffman@20554
   296
  show "of_real r = id r"
huffman@22973
   297
    by (simp add: of_real_def)
huffman@20554
   298
qed
huffman@20554
   299
huffman@20554
   300
text{*Collapse nested embeddings*}
huffman@20554
   301
lemma of_real_of_nat_eq [simp]: "of_real (of_nat n) = of_nat n"
wenzelm@20772
   302
by (induct n) auto
huffman@20554
   303
huffman@20554
   304
lemma of_real_of_int_eq [simp]: "of_real (of_int z) = of_int z"
huffman@20554
   305
by (cases z rule: int_diff_cases, simp)
huffman@20554
   306
huffman@47108
   307
lemma of_real_numeral: "of_real (numeral w) = numeral w"
huffman@47108
   308
using of_real_of_int_eq [of "numeral w"] by simp
huffman@47108
   309
huffman@47108
   310
lemma of_real_neg_numeral: "of_real (neg_numeral w) = neg_numeral w"
huffman@47108
   311
using of_real_of_int_eq [of "neg_numeral w"] by simp
huffman@20554
   312
huffman@22912
   313
text{*Every real algebra has characteristic zero*}
haftmann@38621
   314
huffman@22912
   315
instance real_algebra_1 < ring_char_0
huffman@22912
   316
proof
haftmann@38621
   317
  from inj_of_real inj_of_nat have "inj (of_real \<circ> of_nat)" by (rule inj_comp)
haftmann@38621
   318
  then show "inj (of_nat :: nat \<Rightarrow> 'a)" by (simp add: comp_def)
huffman@22912
   319
qed
huffman@22912
   320
huffman@27553
   321
instance real_field < field_char_0 ..
huffman@27553
   322
huffman@20554
   323
huffman@20554
   324
subsection {* The Set of Real Numbers *}
huffman@20554
   325
haftmann@37767
   326
definition Reals :: "'a::real_algebra_1 set" where
haftmann@37767
   327
  "Reals = range of_real"
huffman@20554
   328
wenzelm@21210
   329
notation (xsymbols)
huffman@20554
   330
  Reals  ("\<real>")
huffman@20554
   331
huffman@21809
   332
lemma Reals_of_real [simp]: "of_real r \<in> Reals"
huffman@20554
   333
by (simp add: Reals_def)
huffman@20554
   334
huffman@21809
   335
lemma Reals_of_int [simp]: "of_int z \<in> Reals"
huffman@21809
   336
by (subst of_real_of_int_eq [symmetric], rule Reals_of_real)
huffman@20718
   337
huffman@21809
   338
lemma Reals_of_nat [simp]: "of_nat n \<in> Reals"
huffman@21809
   339
by (subst of_real_of_nat_eq [symmetric], rule Reals_of_real)
huffman@21809
   340
huffman@47108
   341
lemma Reals_numeral [simp]: "numeral w \<in> Reals"
huffman@47108
   342
by (subst of_real_numeral [symmetric], rule Reals_of_real)
huffman@47108
   343
huffman@47108
   344
lemma Reals_neg_numeral [simp]: "neg_numeral w \<in> Reals"
huffman@47108
   345
by (subst of_real_neg_numeral [symmetric], rule Reals_of_real)
huffman@20718
   346
huffman@20554
   347
lemma Reals_0 [simp]: "0 \<in> Reals"
huffman@20554
   348
apply (unfold Reals_def)
huffman@20554
   349
apply (rule range_eqI)
huffman@20554
   350
apply (rule of_real_0 [symmetric])
huffman@20554
   351
done
huffman@20554
   352
huffman@20554
   353
lemma Reals_1 [simp]: "1 \<in> Reals"
huffman@20554
   354
apply (unfold Reals_def)
huffman@20554
   355
apply (rule range_eqI)
huffman@20554
   356
apply (rule of_real_1 [symmetric])
huffman@20554
   357
done
huffman@20554
   358
huffman@20584
   359
lemma Reals_add [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a + b \<in> Reals"
huffman@20554
   360
apply (auto simp add: Reals_def)
huffman@20554
   361
apply (rule range_eqI)
huffman@20554
   362
apply (rule of_real_add [symmetric])
huffman@20554
   363
done
huffman@20554
   364
huffman@20584
   365
lemma Reals_minus [simp]: "a \<in> Reals \<Longrightarrow> - a \<in> Reals"
huffman@20584
   366
apply (auto simp add: Reals_def)
huffman@20584
   367
apply (rule range_eqI)
huffman@20584
   368
apply (rule of_real_minus [symmetric])
huffman@20584
   369
done
huffman@20584
   370
huffman@20584
   371
lemma Reals_diff [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a - b \<in> Reals"
huffman@20584
   372
apply (auto simp add: Reals_def)
huffman@20584
   373
apply (rule range_eqI)
huffman@20584
   374
apply (rule of_real_diff [symmetric])
huffman@20584
   375
done
huffman@20584
   376
huffman@20584
   377
lemma Reals_mult [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a * b \<in> Reals"
huffman@20554
   378
apply (auto simp add: Reals_def)
huffman@20554
   379
apply (rule range_eqI)
huffman@20554
   380
apply (rule of_real_mult [symmetric])
huffman@20554
   381
done
huffman@20554
   382
huffman@20584
   383
lemma nonzero_Reals_inverse:
huffman@20584
   384
  fixes a :: "'a::real_div_algebra"
huffman@20584
   385
  shows "\<lbrakk>a \<in> Reals; a \<noteq> 0\<rbrakk> \<Longrightarrow> inverse a \<in> Reals"
huffman@20584
   386
apply (auto simp add: Reals_def)
huffman@20584
   387
apply (rule range_eqI)
huffman@20584
   388
apply (erule nonzero_of_real_inverse [symmetric])
huffman@20584
   389
done
huffman@20584
   390
huffman@20584
   391
lemma Reals_inverse [simp]:
haftmann@36409
   392
  fixes a :: "'a::{real_div_algebra, division_ring_inverse_zero}"
huffman@20584
   393
  shows "a \<in> Reals \<Longrightarrow> inverse a \<in> Reals"
huffman@20584
   394
apply (auto simp add: Reals_def)
huffman@20584
   395
apply (rule range_eqI)
huffman@20584
   396
apply (rule of_real_inverse [symmetric])
huffman@20584
   397
done
huffman@20584
   398
huffman@20584
   399
lemma nonzero_Reals_divide:
huffman@20584
   400
  fixes a b :: "'a::real_field"
huffman@20584
   401
  shows "\<lbrakk>a \<in> Reals; b \<in> Reals; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584
   402
apply (auto simp add: Reals_def)
huffman@20584
   403
apply (rule range_eqI)
huffman@20584
   404
apply (erule nonzero_of_real_divide [symmetric])
huffman@20584
   405
done
huffman@20584
   406
huffman@20584
   407
lemma Reals_divide [simp]:
haftmann@36409
   408
  fixes a b :: "'a::{real_field, field_inverse_zero}"
huffman@20584
   409
  shows "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584
   410
apply (auto simp add: Reals_def)
huffman@20584
   411
apply (rule range_eqI)
huffman@20584
   412
apply (rule of_real_divide [symmetric])
huffman@20584
   413
done
huffman@20584
   414
huffman@20722
   415
lemma Reals_power [simp]:
haftmann@31017
   416
  fixes a :: "'a::{real_algebra_1}"
huffman@20722
   417
  shows "a \<in> Reals \<Longrightarrow> a ^ n \<in> Reals"
huffman@20722
   418
apply (auto simp add: Reals_def)
huffman@20722
   419
apply (rule range_eqI)
huffman@20722
   420
apply (rule of_real_power [symmetric])
huffman@20722
   421
done
huffman@20722
   422
huffman@20554
   423
lemma Reals_cases [cases set: Reals]:
huffman@20554
   424
  assumes "q \<in> \<real>"
huffman@20554
   425
  obtains (of_real) r where "q = of_real r"
huffman@20554
   426
  unfolding Reals_def
huffman@20554
   427
proof -
huffman@20554
   428
  from `q \<in> \<real>` have "q \<in> range of_real" unfolding Reals_def .
huffman@20554
   429
  then obtain r where "q = of_real r" ..
huffman@20554
   430
  then show thesis ..
huffman@20554
   431
qed
huffman@20554
   432
huffman@20554
   433
lemma Reals_induct [case_names of_real, induct set: Reals]:
huffman@20554
   434
  "q \<in> \<real> \<Longrightarrow> (\<And>r. P (of_real r)) \<Longrightarrow> P q"
huffman@20554
   435
  by (rule Reals_cases) auto
huffman@20554
   436
huffman@20504
   437
huffman@20504
   438
subsection {* Real normed vector spaces *}
huffman@20504
   439
hoelzl@51531
   440
class dist =
hoelzl@51531
   441
  fixes dist :: "'a \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@51531
   442
haftmann@29608
   443
class norm =
huffman@22636
   444
  fixes norm :: "'a \<Rightarrow> real"
huffman@20504
   445
huffman@24520
   446
class sgn_div_norm = scaleR + norm + sgn +
haftmann@25062
   447
  assumes sgn_div_norm: "sgn x = x /\<^sub>R norm x"
nipkow@24506
   448
huffman@31289
   449
class dist_norm = dist + norm + minus +
huffman@31289
   450
  assumes dist_norm: "dist x y = norm (x - y)"
huffman@31289
   451
hoelzl@51531
   452
class open_dist = "open" + dist +
hoelzl@51531
   453
  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
   454
huffman@31492
   455
class real_normed_vector = real_vector + sgn_div_norm + dist_norm + open_dist +
hoelzl@51002
   456
  assumes norm_eq_zero [simp]: "norm x = 0 \<longleftrightarrow> x = 0"
haftmann@25062
   457
  and norm_triangle_ineq: "norm (x + y) \<le> norm x + norm y"
huffman@31586
   458
  and norm_scaleR [simp]: "norm (scaleR a x) = \<bar>a\<bar> * norm x"
hoelzl@51002
   459
begin
hoelzl@51002
   460
hoelzl@51002
   461
lemma norm_ge_zero [simp]: "0 \<le> norm x"
hoelzl@51002
   462
proof -
hoelzl@51002
   463
  have "0 = norm (x + -1 *\<^sub>R x)" 
hoelzl@51002
   464
    using scaleR_add_left[of 1 "-1" x] norm_scaleR[of 0 x] by (simp add: scaleR_one)
hoelzl@51002
   465
  also have "\<dots> \<le> norm x + norm (-1 *\<^sub>R x)" by (rule norm_triangle_ineq)
hoelzl@51002
   466
  finally show ?thesis by simp
hoelzl@51002
   467
qed
hoelzl@51002
   468
hoelzl@51002
   469
end
huffman@20504
   470
haftmann@24588
   471
class real_normed_algebra = real_algebra + real_normed_vector +
haftmann@25062
   472
  assumes norm_mult_ineq: "norm (x * y) \<le> norm x * norm y"
huffman@20504
   473
haftmann@24588
   474
class real_normed_algebra_1 = real_algebra_1 + real_normed_algebra +
haftmann@25062
   475
  assumes norm_one [simp]: "norm 1 = 1"
huffman@22852
   476
haftmann@24588
   477
class real_normed_div_algebra = real_div_algebra + real_normed_vector +
haftmann@25062
   478
  assumes norm_mult: "norm (x * y) = norm x * norm y"
huffman@20504
   479
haftmann@24588
   480
class real_normed_field = real_field + real_normed_div_algebra
huffman@20584
   481
huffman@22852
   482
instance real_normed_div_algebra < real_normed_algebra_1
huffman@20554
   483
proof
huffman@20554
   484
  fix x y :: 'a
huffman@20554
   485
  show "norm (x * y) \<le> norm x * norm y"
huffman@20554
   486
    by (simp add: norm_mult)
huffman@22852
   487
next
huffman@22852
   488
  have "norm (1 * 1::'a) = norm (1::'a) * norm (1::'a)"
huffman@22852
   489
    by (rule norm_mult)
huffman@22852
   490
  thus "norm (1::'a) = 1" by simp
huffman@20554
   491
qed
huffman@20554
   492
huffman@22852
   493
lemma norm_zero [simp]: "norm (0::'a::real_normed_vector) = 0"
huffman@20504
   494
by simp
huffman@20504
   495
huffman@22852
   496
lemma zero_less_norm_iff [simp]:
huffman@22852
   497
  fixes x :: "'a::real_normed_vector"
huffman@22852
   498
  shows "(0 < norm x) = (x \<noteq> 0)"
huffman@20504
   499
by (simp add: order_less_le)
huffman@20504
   500
huffman@22852
   501
lemma norm_not_less_zero [simp]:
huffman@22852
   502
  fixes x :: "'a::real_normed_vector"
huffman@22852
   503
  shows "\<not> norm x < 0"
huffman@20828
   504
by (simp add: linorder_not_less)
huffman@20828
   505
huffman@22852
   506
lemma norm_le_zero_iff [simp]:
huffman@22852
   507
  fixes x :: "'a::real_normed_vector"
huffman@22852
   508
  shows "(norm x \<le> 0) = (x = 0)"
huffman@20828
   509
by (simp add: order_le_less)
huffman@20828
   510
huffman@20504
   511
lemma norm_minus_cancel [simp]:
huffman@20584
   512
  fixes x :: "'a::real_normed_vector"
huffman@20584
   513
  shows "norm (- x) = norm x"
huffman@20504
   514
proof -
huffman@21809
   515
  have "norm (- x) = norm (scaleR (- 1) x)"
huffman@20504
   516
    by (simp only: scaleR_minus_left scaleR_one)
huffman@20533
   517
  also have "\<dots> = \<bar>- 1\<bar> * norm x"
huffman@20504
   518
    by (rule norm_scaleR)
huffman@20504
   519
  finally show ?thesis by simp
huffman@20504
   520
qed
huffman@20504
   521
huffman@20504
   522
lemma norm_minus_commute:
huffman@20584
   523
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   524
  shows "norm (a - b) = norm (b - a)"
huffman@20504
   525
proof -
huffman@22898
   526
  have "norm (- (b - a)) = norm (b - a)"
huffman@22898
   527
    by (rule norm_minus_cancel)
huffman@22898
   528
  thus ?thesis by simp
huffman@20504
   529
qed
huffman@20504
   530
huffman@20504
   531
lemma norm_triangle_ineq2:
huffman@20584
   532
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   533
  shows "norm a - norm b \<le> norm (a - b)"
huffman@20504
   534
proof -
huffman@20533
   535
  have "norm (a - b + b) \<le> norm (a - b) + norm b"
huffman@20504
   536
    by (rule norm_triangle_ineq)
huffman@22898
   537
  thus ?thesis by simp
huffman@20504
   538
qed
huffman@20504
   539
huffman@20584
   540
lemma norm_triangle_ineq3:
huffman@20584
   541
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   542
  shows "\<bar>norm a - norm b\<bar> \<le> norm (a - b)"
huffman@20584
   543
apply (subst abs_le_iff)
huffman@20584
   544
apply auto
huffman@20584
   545
apply (rule norm_triangle_ineq2)
huffman@20584
   546
apply (subst norm_minus_commute)
huffman@20584
   547
apply (rule norm_triangle_ineq2)
huffman@20584
   548
done
huffman@20584
   549
huffman@20504
   550
lemma norm_triangle_ineq4:
huffman@20584
   551
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   552
  shows "norm (a - b) \<le> norm a + norm b"
huffman@20504
   553
proof -
huffman@22898
   554
  have "norm (a + - b) \<le> norm a + norm (- b)"
huffman@20504
   555
    by (rule norm_triangle_ineq)
huffman@22898
   556
  thus ?thesis
huffman@22898
   557
    by (simp only: diff_minus norm_minus_cancel)
huffman@22898
   558
qed
huffman@22898
   559
huffman@22898
   560
lemma norm_diff_ineq:
huffman@22898
   561
  fixes a b :: "'a::real_normed_vector"
huffman@22898
   562
  shows "norm a - norm b \<le> norm (a + b)"
huffman@22898
   563
proof -
huffman@22898
   564
  have "norm a - norm (- b) \<le> norm (a - - b)"
huffman@22898
   565
    by (rule norm_triangle_ineq2)
huffman@22898
   566
  thus ?thesis by simp
huffman@20504
   567
qed
huffman@20504
   568
huffman@20551
   569
lemma norm_diff_triangle_ineq:
huffman@20551
   570
  fixes a b c d :: "'a::real_normed_vector"
huffman@20551
   571
  shows "norm ((a + b) - (c + d)) \<le> norm (a - c) + norm (b - d)"
huffman@20551
   572
proof -
huffman@20551
   573
  have "norm ((a + b) - (c + d)) = norm ((a - c) + (b - d))"
huffman@20551
   574
    by (simp add: diff_minus add_ac)
huffman@20551
   575
  also have "\<dots> \<le> norm (a - c) + norm (b - d)"
huffman@20551
   576
    by (rule norm_triangle_ineq)
huffman@20551
   577
  finally show ?thesis .
huffman@20551
   578
qed
huffman@20551
   579
huffman@22857
   580
lemma abs_norm_cancel [simp]:
huffman@22857
   581
  fixes a :: "'a::real_normed_vector"
huffman@22857
   582
  shows "\<bar>norm a\<bar> = norm a"
huffman@22857
   583
by (rule abs_of_nonneg [OF norm_ge_zero])
huffman@22857
   584
huffman@22880
   585
lemma norm_add_less:
huffman@22880
   586
  fixes x y :: "'a::real_normed_vector"
huffman@22880
   587
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x + y) < r + s"
huffman@22880
   588
by (rule order_le_less_trans [OF norm_triangle_ineq add_strict_mono])
huffman@22880
   589
huffman@22880
   590
lemma norm_mult_less:
huffman@22880
   591
  fixes x y :: "'a::real_normed_algebra"
huffman@22880
   592
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x * y) < r * s"
huffman@22880
   593
apply (rule order_le_less_trans [OF norm_mult_ineq])
huffman@22880
   594
apply (simp add: mult_strict_mono')
huffman@22880
   595
done
huffman@22880
   596
huffman@22857
   597
lemma norm_of_real [simp]:
huffman@22857
   598
  "norm (of_real r :: 'a::real_normed_algebra_1) = \<bar>r\<bar>"
huffman@31586
   599
unfolding of_real_def by simp
huffman@20560
   600
huffman@47108
   601
lemma norm_numeral [simp]:
huffman@47108
   602
  "norm (numeral w::'a::real_normed_algebra_1) = numeral w"
huffman@47108
   603
by (subst of_real_numeral [symmetric], subst norm_of_real, simp)
huffman@47108
   604
huffman@47108
   605
lemma norm_neg_numeral [simp]:
huffman@47108
   606
  "norm (neg_numeral w::'a::real_normed_algebra_1) = numeral w"
huffman@47108
   607
by (subst of_real_neg_numeral [symmetric], subst norm_of_real, simp)
huffman@22876
   608
huffman@22876
   609
lemma norm_of_int [simp]:
huffman@22876
   610
  "norm (of_int z::'a::real_normed_algebra_1) = \<bar>of_int z\<bar>"
huffman@22876
   611
by (subst of_real_of_int_eq [symmetric], rule norm_of_real)
huffman@22876
   612
huffman@22876
   613
lemma norm_of_nat [simp]:
huffman@22876
   614
  "norm (of_nat n::'a::real_normed_algebra_1) = of_nat n"
huffman@22876
   615
apply (subst of_real_of_nat_eq [symmetric])
huffman@22876
   616
apply (subst norm_of_real, simp)
huffman@22876
   617
done
huffman@22876
   618
huffman@20504
   619
lemma nonzero_norm_inverse:
huffman@20504
   620
  fixes a :: "'a::real_normed_div_algebra"
huffman@20533
   621
  shows "a \<noteq> 0 \<Longrightarrow> norm (inverse a) = inverse (norm a)"
huffman@20504
   622
apply (rule inverse_unique [symmetric])
huffman@20504
   623
apply (simp add: norm_mult [symmetric])
huffman@20504
   624
done
huffman@20504
   625
huffman@20504
   626
lemma norm_inverse:
haftmann@36409
   627
  fixes a :: "'a::{real_normed_div_algebra, division_ring_inverse_zero}"
huffman@20533
   628
  shows "norm (inverse a) = inverse (norm a)"
huffman@20504
   629
apply (case_tac "a = 0", simp)
huffman@20504
   630
apply (erule nonzero_norm_inverse)
huffman@20504
   631
done
huffman@20504
   632
huffman@20584
   633
lemma nonzero_norm_divide:
huffman@20584
   634
  fixes a b :: "'a::real_normed_field"
huffman@20584
   635
  shows "b \<noteq> 0 \<Longrightarrow> norm (a / b) = norm a / norm b"
huffman@20584
   636
by (simp add: divide_inverse norm_mult nonzero_norm_inverse)
huffman@20584
   637
huffman@20584
   638
lemma norm_divide:
haftmann@36409
   639
  fixes a b :: "'a::{real_normed_field, field_inverse_zero}"
huffman@20584
   640
  shows "norm (a / b) = norm a / norm b"
huffman@20584
   641
by (simp add: divide_inverse norm_mult norm_inverse)
huffman@20584
   642
huffman@22852
   643
lemma norm_power_ineq:
haftmann@31017
   644
  fixes x :: "'a::{real_normed_algebra_1}"
huffman@22852
   645
  shows "norm (x ^ n) \<le> norm x ^ n"
huffman@22852
   646
proof (induct n)
huffman@22852
   647
  case 0 show "norm (x ^ 0) \<le> norm x ^ 0" by simp
huffman@22852
   648
next
huffman@22852
   649
  case (Suc n)
huffman@22852
   650
  have "norm (x * x ^ n) \<le> norm x * norm (x ^ n)"
huffman@22852
   651
    by (rule norm_mult_ineq)
huffman@22852
   652
  also from Suc have "\<dots> \<le> norm x * norm x ^ n"
huffman@22852
   653
    using norm_ge_zero by (rule mult_left_mono)
huffman@22852
   654
  finally show "norm (x ^ Suc n) \<le> norm x ^ Suc n"
huffman@30273
   655
    by simp
huffman@22852
   656
qed
huffman@22852
   657
huffman@20684
   658
lemma norm_power:
haftmann@31017
   659
  fixes x :: "'a::{real_normed_div_algebra}"
huffman@20684
   660
  shows "norm (x ^ n) = norm x ^ n"
huffman@30273
   661
by (induct n) (simp_all add: norm_mult)
huffman@20684
   662
hoelzl@51531
   663
hoelzl@51531
   664
subsection {* Metric spaces *}
hoelzl@51531
   665
hoelzl@51531
   666
class metric_space = open_dist +
hoelzl@51531
   667
  assumes dist_eq_0_iff [simp]: "dist x y = 0 \<longleftrightarrow> x = y"
hoelzl@51531
   668
  assumes dist_triangle2: "dist x y \<le> dist x z + dist y z"
hoelzl@51531
   669
begin
hoelzl@51531
   670
hoelzl@51531
   671
lemma dist_self [simp]: "dist x x = 0"
hoelzl@51531
   672
by simp
hoelzl@51531
   673
hoelzl@51531
   674
lemma zero_le_dist [simp]: "0 \<le> dist x y"
hoelzl@51531
   675
using dist_triangle2 [of x x y] by simp
hoelzl@51531
   676
hoelzl@51531
   677
lemma zero_less_dist_iff: "0 < dist x y \<longleftrightarrow> x \<noteq> y"
hoelzl@51531
   678
by (simp add: less_le)
hoelzl@51531
   679
hoelzl@51531
   680
lemma dist_not_less_zero [simp]: "\<not> dist x y < 0"
hoelzl@51531
   681
by (simp add: not_less)
hoelzl@51531
   682
hoelzl@51531
   683
lemma dist_le_zero_iff [simp]: "dist x y \<le> 0 \<longleftrightarrow> x = y"
hoelzl@51531
   684
by (simp add: le_less)
hoelzl@51531
   685
hoelzl@51531
   686
lemma dist_commute: "dist x y = dist y x"
hoelzl@51531
   687
proof (rule order_antisym)
hoelzl@51531
   688
  show "dist x y \<le> dist y x"
hoelzl@51531
   689
    using dist_triangle2 [of x y x] by simp
hoelzl@51531
   690
  show "dist y x \<le> dist x y"
hoelzl@51531
   691
    using dist_triangle2 [of y x y] by simp
hoelzl@51531
   692
qed
hoelzl@51531
   693
hoelzl@51531
   694
lemma dist_triangle: "dist x z \<le> dist x y + dist y z"
hoelzl@51531
   695
using dist_triangle2 [of x z y] by (simp add: dist_commute)
hoelzl@51531
   696
hoelzl@51531
   697
lemma dist_triangle3: "dist x y \<le> dist a x + dist a y"
hoelzl@51531
   698
using dist_triangle2 [of x y a] by (simp add: dist_commute)
hoelzl@51531
   699
hoelzl@51531
   700
lemma dist_triangle_alt:
hoelzl@51531
   701
  shows "dist y z <= dist x y + dist x z"
hoelzl@51531
   702
by (rule dist_triangle3)
hoelzl@51531
   703
hoelzl@51531
   704
lemma dist_pos_lt:
hoelzl@51531
   705
  shows "x \<noteq> y ==> 0 < dist x y"
hoelzl@51531
   706
by (simp add: zero_less_dist_iff)
hoelzl@51531
   707
hoelzl@51531
   708
lemma dist_nz:
hoelzl@51531
   709
  shows "x \<noteq> y \<longleftrightarrow> 0 < dist x y"
hoelzl@51531
   710
by (simp add: zero_less_dist_iff)
hoelzl@51531
   711
hoelzl@51531
   712
lemma dist_triangle_le:
hoelzl@51531
   713
  shows "dist x z + dist y z <= e \<Longrightarrow> dist x y <= e"
hoelzl@51531
   714
by (rule order_trans [OF dist_triangle2])
hoelzl@51531
   715
hoelzl@51531
   716
lemma dist_triangle_lt:
hoelzl@51531
   717
  shows "dist x z + dist y z < e ==> dist x y < e"
hoelzl@51531
   718
by (rule le_less_trans [OF dist_triangle2])
hoelzl@51531
   719
hoelzl@51531
   720
lemma dist_triangle_half_l:
hoelzl@51531
   721
  shows "dist x1 y < e / 2 \<Longrightarrow> dist x2 y < e / 2 \<Longrightarrow> dist x1 x2 < e"
hoelzl@51531
   722
by (rule dist_triangle_lt [where z=y], simp)
hoelzl@51531
   723
hoelzl@51531
   724
lemma dist_triangle_half_r:
hoelzl@51531
   725
  shows "dist y x1 < e / 2 \<Longrightarrow> dist y x2 < e / 2 \<Longrightarrow> dist x1 x2 < e"
hoelzl@51531
   726
by (rule dist_triangle_half_l, simp_all add: dist_commute)
hoelzl@51531
   727
hoelzl@51531
   728
subclass topological_space
hoelzl@51531
   729
proof
hoelzl@51531
   730
  have "\<exists>e::real. 0 < e"
hoelzl@51531
   731
    by (fast intro: zero_less_one)
hoelzl@51531
   732
  then show "open UNIV"
hoelzl@51531
   733
    unfolding open_dist by simp
hoelzl@51531
   734
next
hoelzl@51531
   735
  fix S T assume "open S" "open T"
hoelzl@51531
   736
  then show "open (S \<inter> T)"
hoelzl@51531
   737
    unfolding open_dist
hoelzl@51531
   738
    apply clarify
hoelzl@51531
   739
    apply (drule (1) bspec)+
hoelzl@51531
   740
    apply (clarify, rename_tac r s)
hoelzl@51531
   741
    apply (rule_tac x="min r s" in exI, simp)
hoelzl@51531
   742
    done
hoelzl@51531
   743
next
hoelzl@51531
   744
  fix K assume "\<forall>S\<in>K. open S" thus "open (\<Union>K)"
hoelzl@51531
   745
    unfolding open_dist by fast
hoelzl@51531
   746
qed
hoelzl@51531
   747
hoelzl@51531
   748
lemma open_ball: "open {y. dist x y < d}"
hoelzl@51531
   749
proof (unfold open_dist, intro ballI)
hoelzl@51531
   750
  fix y assume *: "y \<in> {y. dist x y < d}"
hoelzl@51531
   751
  then show "\<exists>e>0. \<forall>z. dist z y < e \<longrightarrow> z \<in> {y. dist x y < d}"
hoelzl@51531
   752
    by (auto intro!: exI[of _ "d - dist x y"] simp: field_simps dist_triangle_lt)
hoelzl@51531
   753
qed
hoelzl@51531
   754
hoelzl@51531
   755
subclass first_countable_topology
hoelzl@51531
   756
proof
hoelzl@51531
   757
  fix x 
hoelzl@51531
   758
  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
   759
  proof (safe intro!: exI[of _ "\<lambda>n. {y. dist x y < inverse (Suc n)}"])
hoelzl@51531
   760
    fix S assume "open S" "x \<in> S"
hoelzl@51531
   761
    then obtain e where "0 < e" "{y. dist x y < e} \<subseteq> S"
hoelzl@51531
   762
      by (auto simp: open_dist subset_eq dist_commute)
hoelzl@51531
   763
    moreover
hoelzl@51531
   764
    then obtain i where "inverse (Suc i) < e"
hoelzl@51531
   765
      by (auto dest!: reals_Archimedean)
hoelzl@51531
   766
    then have "{y. dist x y < inverse (Suc i)} \<subseteq> {y. dist x y < e}"
hoelzl@51531
   767
      by auto
hoelzl@51531
   768
    ultimately show "\<exists>i. {y. dist x y < inverse (Suc i)} \<subseteq> S"
hoelzl@51531
   769
      by blast
hoelzl@51531
   770
  qed (auto intro: open_ball)
hoelzl@51531
   771
qed
hoelzl@51531
   772
hoelzl@51531
   773
end
hoelzl@51531
   774
hoelzl@51531
   775
instance metric_space \<subseteq> t2_space
hoelzl@51531
   776
proof
hoelzl@51531
   777
  fix x y :: "'a::metric_space"
hoelzl@51531
   778
  assume xy: "x \<noteq> y"
hoelzl@51531
   779
  let ?U = "{y'. dist x y' < dist x y / 2}"
hoelzl@51531
   780
  let ?V = "{x'. dist y x' < dist x y / 2}"
hoelzl@51531
   781
  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
   782
               \<Longrightarrow> \<not>(d x y * 2 < d x z \<and> d z y * 2 < d x z)" by arith
hoelzl@51531
   783
  have "open ?U \<and> open ?V \<and> x \<in> ?U \<and> y \<in> ?V \<and> ?U \<inter> ?V = {}"
hoelzl@51531
   784
    using dist_pos_lt[OF xy] th0[of dist, OF dist_triangle dist_commute]
hoelzl@51531
   785
    using open_ball[of _ "dist x y / 2"] by auto
hoelzl@51531
   786
  then show "\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
hoelzl@51531
   787
    by blast
hoelzl@51531
   788
qed
hoelzl@51531
   789
huffman@31289
   790
text {* Every normed vector space is a metric space. *}
huffman@31285
   791
huffman@31289
   792
instance real_normed_vector < metric_space
huffman@31289
   793
proof
huffman@31289
   794
  fix x y :: 'a show "dist x y = 0 \<longleftrightarrow> x = y"
huffman@31289
   795
    unfolding dist_norm by simp
huffman@31289
   796
next
huffman@31289
   797
  fix x y z :: 'a show "dist x y \<le> dist x z + dist y z"
huffman@31289
   798
    unfolding dist_norm
huffman@31289
   799
    using norm_triangle_ineq4 [of "x - z" "y - z"] by simp
huffman@31289
   800
qed
huffman@31285
   801
huffman@31564
   802
subsection {* Class instances for real numbers *}
huffman@31564
   803
huffman@31564
   804
instantiation real :: real_normed_field
huffman@31564
   805
begin
huffman@31564
   806
hoelzl@51531
   807
definition dist_real_def:
hoelzl@51531
   808
  "dist x y = \<bar>x - y\<bar>"
hoelzl@51531
   809
hoelzl@51531
   810
definition open_real_def:
hoelzl@51531
   811
  "open (S :: real set) \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
hoelzl@51531
   812
huffman@31564
   813
definition real_norm_def [simp]:
huffman@31564
   814
  "norm r = \<bar>r\<bar>"
huffman@31564
   815
huffman@31564
   816
instance
huffman@31564
   817
apply (intro_classes, unfold real_norm_def real_scaleR_def)
huffman@31564
   818
apply (rule dist_real_def)
hoelzl@51531
   819
apply (rule open_real_def)
huffman@36795
   820
apply (simp add: sgn_real_def)
huffman@31564
   821
apply (rule abs_eq_0)
huffman@31564
   822
apply (rule abs_triangle_ineq)
huffman@31564
   823
apply (rule abs_mult)
huffman@31564
   824
apply (rule abs_mult)
huffman@31564
   825
done
huffman@31564
   826
huffman@31564
   827
end
huffman@31564
   828
hoelzl@51531
   829
instance real :: linorder_topology
hoelzl@51531
   830
proof
hoelzl@51531
   831
  show "(open :: real set \<Rightarrow> bool) = generate_topology (range lessThan \<union> range greaterThan)"
hoelzl@51531
   832
  proof (rule ext, safe)
hoelzl@51531
   833
    fix S :: "real set" assume "open S"
hoelzl@51531
   834
    then guess f unfolding open_real_def bchoice_iff ..
hoelzl@51531
   835
    then have *: "S = (\<Union>x\<in>S. {x - f x <..} \<inter> {..< x + f x})"
hoelzl@51531
   836
      by (fastforce simp: dist_real_def)
hoelzl@51531
   837
    show "generate_topology (range lessThan \<union> range greaterThan) S"
hoelzl@51531
   838
      apply (subst *)
hoelzl@51531
   839
      apply (intro generate_topology_Union generate_topology.Int)
hoelzl@51531
   840
      apply (auto intro: generate_topology.Basis)
hoelzl@51531
   841
      done
hoelzl@51531
   842
  next
hoelzl@51531
   843
    fix S :: "real set" assume "generate_topology (range lessThan \<union> range greaterThan) S"
hoelzl@51531
   844
    moreover have "\<And>a::real. open {..<a}"
hoelzl@51531
   845
      unfolding open_real_def dist_real_def
hoelzl@51531
   846
    proof clarify
hoelzl@51531
   847
      fix x a :: real assume "x < a"
hoelzl@51531
   848
      hence "0 < a - x \<and> (\<forall>y. \<bar>y - x\<bar> < a - x \<longrightarrow> y \<in> {..<a})" by auto
hoelzl@51531
   849
      thus "\<exists>e>0. \<forall>y. \<bar>y - x\<bar> < e \<longrightarrow> y \<in> {..<a}" ..
hoelzl@51531
   850
    qed
hoelzl@51531
   851
    moreover have "\<And>a::real. open {a <..}"
hoelzl@51531
   852
      unfolding open_real_def dist_real_def
hoelzl@51531
   853
    proof clarify
hoelzl@51531
   854
      fix x a :: real assume "a < x"
hoelzl@51531
   855
      hence "0 < x - a \<and> (\<forall>y. \<bar>y - x\<bar> < x - a \<longrightarrow> y \<in> {a<..})" by auto
hoelzl@51531
   856
      thus "\<exists>e>0. \<forall>y. \<bar>y - x\<bar> < e \<longrightarrow> y \<in> {a<..}" ..
hoelzl@51531
   857
    qed
hoelzl@51531
   858
    ultimately show "open S"
hoelzl@51531
   859
      by induct auto
hoelzl@51531
   860
  qed
hoelzl@51531
   861
qed
hoelzl@51531
   862
hoelzl@51518
   863
instance real :: linear_continuum_topology ..
hoelzl@51518
   864
hoelzl@51531
   865
lemmas open_real_greaterThan = open_greaterThan[where 'a=real]
hoelzl@51531
   866
lemmas open_real_lessThan = open_lessThan[where 'a=real]
hoelzl@51531
   867
lemmas open_real_greaterThanLessThan = open_greaterThanLessThan[where 'a=real]
hoelzl@51531
   868
lemmas closed_real_atMost = closed_atMost[where 'a=real]
hoelzl@51531
   869
lemmas closed_real_atLeast = closed_atLeast[where 'a=real]
hoelzl@51531
   870
lemmas closed_real_atLeastAtMost = closed_atLeastAtMost[where 'a=real]
hoelzl@51531
   871
huffman@31446
   872
subsection {* Extra type constraints *}
huffman@31446
   873
huffman@31492
   874
text {* Only allow @{term "open"} in class @{text topological_space}. *}
huffman@31492
   875
huffman@31492
   876
setup {* Sign.add_const_constraint
huffman@31492
   877
  (@{const_name "open"}, SOME @{typ "'a::topological_space set \<Rightarrow> bool"}) *}
huffman@31492
   878
huffman@31446
   879
text {* Only allow @{term dist} in class @{text metric_space}. *}
huffman@31446
   880
huffman@31446
   881
setup {* Sign.add_const_constraint
huffman@31446
   882
  (@{const_name dist}, SOME @{typ "'a::metric_space \<Rightarrow> 'a \<Rightarrow> real"}) *}
huffman@31446
   883
huffman@31446
   884
text {* Only allow @{term norm} in class @{text real_normed_vector}. *}
huffman@31446
   885
huffman@31446
   886
setup {* Sign.add_const_constraint
huffman@31446
   887
  (@{const_name norm}, SOME @{typ "'a::real_normed_vector \<Rightarrow> real"}) *}
huffman@31446
   888
huffman@22972
   889
subsection {* Sign function *}
huffman@22972
   890
nipkow@24506
   891
lemma norm_sgn:
nipkow@24506
   892
  "norm (sgn(x::'a::real_normed_vector)) = (if x = 0 then 0 else 1)"
huffman@31586
   893
by (simp add: sgn_div_norm)
huffman@22972
   894
nipkow@24506
   895
lemma sgn_zero [simp]: "sgn(0::'a::real_normed_vector) = 0"
nipkow@24506
   896
by (simp add: sgn_div_norm)
huffman@22972
   897
nipkow@24506
   898
lemma sgn_zero_iff: "(sgn(x::'a::real_normed_vector) = 0) = (x = 0)"
nipkow@24506
   899
by (simp add: sgn_div_norm)
huffman@22972
   900
nipkow@24506
   901
lemma sgn_minus: "sgn (- x) = - sgn(x::'a::real_normed_vector)"
nipkow@24506
   902
by (simp add: sgn_div_norm)
huffman@22972
   903
nipkow@24506
   904
lemma sgn_scaleR:
nipkow@24506
   905
  "sgn (scaleR r x) = scaleR (sgn r) (sgn(x::'a::real_normed_vector))"
huffman@31586
   906
by (simp add: sgn_div_norm mult_ac)
huffman@22973
   907
huffman@22972
   908
lemma sgn_one [simp]: "sgn (1::'a::real_normed_algebra_1) = 1"
nipkow@24506
   909
by (simp add: sgn_div_norm)
huffman@22972
   910
huffman@22972
   911
lemma sgn_of_real:
huffman@22972
   912
  "sgn (of_real r::'a::real_normed_algebra_1) = of_real (sgn r)"
huffman@22972
   913
unfolding of_real_def by (simp only: sgn_scaleR sgn_one)
huffman@22972
   914
huffman@22973
   915
lemma sgn_mult:
huffman@22973
   916
  fixes x y :: "'a::real_normed_div_algebra"
huffman@22973
   917
  shows "sgn (x * y) = sgn x * sgn y"
nipkow@24506
   918
by (simp add: sgn_div_norm norm_mult mult_commute)
huffman@22973
   919
huffman@22972
   920
lemma real_sgn_eq: "sgn (x::real) = x / \<bar>x\<bar>"
nipkow@24506
   921
by (simp add: sgn_div_norm divide_inverse)
huffman@22972
   922
huffman@22972
   923
lemma real_sgn_pos: "0 < (x::real) \<Longrightarrow> sgn x = 1"
huffman@22972
   924
unfolding real_sgn_eq by simp
huffman@22972
   925
huffman@22972
   926
lemma real_sgn_neg: "(x::real) < 0 \<Longrightarrow> sgn x = -1"
huffman@22972
   927
unfolding real_sgn_eq by simp
huffman@22972
   928
hoelzl@51474
   929
lemma norm_conv_dist: "norm x = dist x 0"
hoelzl@51474
   930
  unfolding dist_norm by simp
huffman@22972
   931
huffman@22442
   932
subsection {* Bounded Linear and Bilinear Operators *}
huffman@22442
   933
wenzelm@46868
   934
locale bounded_linear = additive f for f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector" +
huffman@22442
   935
  assumes scaleR: "f (scaleR r x) = scaleR r (f x)"
huffman@22442
   936
  assumes bounded: "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K"
huffman@27443
   937
begin
huffman@22442
   938
huffman@27443
   939
lemma pos_bounded:
huffman@22442
   940
  "\<exists>K>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
   941
proof -
huffman@22442
   942
  obtain K where K: "\<And>x. norm (f x) \<le> norm x * K"
huffman@22442
   943
    using bounded by fast
huffman@22442
   944
  show ?thesis
huffman@22442
   945
  proof (intro exI impI conjI allI)
huffman@22442
   946
    show "0 < max 1 K"
huffman@22442
   947
      by (rule order_less_le_trans [OF zero_less_one le_maxI1])
huffman@22442
   948
  next
huffman@22442
   949
    fix x
huffman@22442
   950
    have "norm (f x) \<le> norm x * K" using K .
huffman@22442
   951
    also have "\<dots> \<le> norm x * max 1 K"
huffman@22442
   952
      by (rule mult_left_mono [OF le_maxI2 norm_ge_zero])
huffman@22442
   953
    finally show "norm (f x) \<le> norm x * max 1 K" .
huffman@22442
   954
  qed
huffman@22442
   955
qed
huffman@22442
   956
huffman@27443
   957
lemma nonneg_bounded:
huffman@22442
   958
  "\<exists>K\<ge>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
   959
proof -
huffman@22442
   960
  from pos_bounded
huffman@22442
   961
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
   962
qed
huffman@22442
   963
huffman@27443
   964
end
huffman@27443
   965
huffman@44127
   966
lemma bounded_linear_intro:
huffman@44127
   967
  assumes "\<And>x y. f (x + y) = f x + f y"
huffman@44127
   968
  assumes "\<And>r x. f (scaleR r x) = scaleR r (f x)"
huffman@44127
   969
  assumes "\<And>x. norm (f x) \<le> norm x * K"
huffman@44127
   970
  shows "bounded_linear f"
huffman@44127
   971
  by default (fast intro: assms)+
huffman@44127
   972
huffman@22442
   973
locale bounded_bilinear =
huffman@22442
   974
  fixes prod :: "['a::real_normed_vector, 'b::real_normed_vector]
huffman@22442
   975
                 \<Rightarrow> 'c::real_normed_vector"
huffman@22442
   976
    (infixl "**" 70)
huffman@22442
   977
  assumes add_left: "prod (a + a') b = prod a b + prod a' b"
huffman@22442
   978
  assumes add_right: "prod a (b + b') = prod a b + prod a b'"
huffman@22442
   979
  assumes scaleR_left: "prod (scaleR r a) b = scaleR r (prod a b)"
huffman@22442
   980
  assumes scaleR_right: "prod a (scaleR r b) = scaleR r (prod a b)"
huffman@22442
   981
  assumes bounded: "\<exists>K. \<forall>a b. norm (prod a b) \<le> norm a * norm b * K"
huffman@27443
   982
begin
huffman@22442
   983
huffman@27443
   984
lemma pos_bounded:
huffman@22442
   985
  "\<exists>K>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
   986
apply (cut_tac bounded, erule exE)
huffman@22442
   987
apply (rule_tac x="max 1 K" in exI, safe)
huffman@22442
   988
apply (rule order_less_le_trans [OF zero_less_one le_maxI1])
huffman@22442
   989
apply (drule spec, drule spec, erule order_trans)
huffman@22442
   990
apply (rule mult_left_mono [OF le_maxI2])
huffman@22442
   991
apply (intro mult_nonneg_nonneg norm_ge_zero)
huffman@22442
   992
done
huffman@22442
   993
huffman@27443
   994
lemma nonneg_bounded:
huffman@22442
   995
  "\<exists>K\<ge>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
   996
proof -
huffman@22442
   997
  from pos_bounded
huffman@22442
   998
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
   999
qed
huffman@22442
  1000
huffman@27443
  1001
lemma additive_right: "additive (\<lambda>b. prod a b)"
huffman@22442
  1002
by (rule additive.intro, rule add_right)
huffman@22442
  1003
huffman@27443
  1004
lemma additive_left: "additive (\<lambda>a. prod a b)"
huffman@22442
  1005
by (rule additive.intro, rule add_left)
huffman@22442
  1006
huffman@27443
  1007
lemma zero_left: "prod 0 b = 0"
huffman@22442
  1008
by (rule additive.zero [OF additive_left])
huffman@22442
  1009
huffman@27443
  1010
lemma zero_right: "prod a 0 = 0"
huffman@22442
  1011
by (rule additive.zero [OF additive_right])
huffman@22442
  1012
huffman@27443
  1013
lemma minus_left: "prod (- a) b = - prod a b"
huffman@22442
  1014
by (rule additive.minus [OF additive_left])
huffman@22442
  1015
huffman@27443
  1016
lemma minus_right: "prod a (- b) = - prod a b"
huffman@22442
  1017
by (rule additive.minus [OF additive_right])
huffman@22442
  1018
huffman@27443
  1019
lemma diff_left:
huffman@22442
  1020
  "prod (a - a') b = prod a b - prod a' b"
huffman@22442
  1021
by (rule additive.diff [OF additive_left])
huffman@22442
  1022
huffman@27443
  1023
lemma diff_right:
huffman@22442
  1024
  "prod a (b - b') = prod a b - prod a b'"
huffman@22442
  1025
by (rule additive.diff [OF additive_right])
huffman@22442
  1026
huffman@27443
  1027
lemma bounded_linear_left:
huffman@22442
  1028
  "bounded_linear (\<lambda>a. a ** b)"
huffman@44127
  1029
apply (cut_tac bounded, safe)
huffman@44127
  1030
apply (rule_tac K="norm b * K" in bounded_linear_intro)
huffman@22442
  1031
apply (rule add_left)
huffman@22442
  1032
apply (rule scaleR_left)
huffman@22442
  1033
apply (simp add: mult_ac)
huffman@22442
  1034
done
huffman@22442
  1035
huffman@27443
  1036
lemma bounded_linear_right:
huffman@22442
  1037
  "bounded_linear (\<lambda>b. a ** b)"
huffman@44127
  1038
apply (cut_tac bounded, safe)
huffman@44127
  1039
apply (rule_tac K="norm a * K" in bounded_linear_intro)
huffman@22442
  1040
apply (rule add_right)
huffman@22442
  1041
apply (rule scaleR_right)
huffman@22442
  1042
apply (simp add: mult_ac)
huffman@22442
  1043
done
huffman@22442
  1044
huffman@27443
  1045
lemma prod_diff_prod:
huffman@22442
  1046
  "(x ** y - a ** b) = (x - a) ** (y - b) + (x - a) ** b + a ** (y - b)"
huffman@22442
  1047
by (simp add: diff_left diff_right)
huffman@22442
  1048
huffman@27443
  1049
end
huffman@27443
  1050
hoelzl@51642
  1051
lemma bounded_linear_ident[simp]: "bounded_linear (\<lambda>x. x)"
hoelzl@51642
  1052
  by default (auto intro!: exI[of _ 1])
hoelzl@51642
  1053
hoelzl@51642
  1054
lemma bounded_linear_zero[simp]: "bounded_linear (\<lambda>x. 0)"
hoelzl@51642
  1055
  by default (auto intro!: exI[of _ 1])
hoelzl@51642
  1056
hoelzl@51642
  1057
lemma bounded_linear_add:
hoelzl@51642
  1058
  assumes "bounded_linear f"
hoelzl@51642
  1059
  assumes "bounded_linear g"
hoelzl@51642
  1060
  shows "bounded_linear (\<lambda>x. f x + g x)"
hoelzl@51642
  1061
proof -
hoelzl@51642
  1062
  interpret f: bounded_linear f by fact
hoelzl@51642
  1063
  interpret g: bounded_linear g by fact
hoelzl@51642
  1064
  show ?thesis
hoelzl@51642
  1065
  proof
hoelzl@51642
  1066
    from f.bounded obtain Kf where Kf: "\<And>x. norm (f x) \<le> norm x * Kf" by blast
hoelzl@51642
  1067
    from g.bounded obtain Kg where Kg: "\<And>x. norm (g x) \<le> norm x * Kg" by blast
hoelzl@51642
  1068
    show "\<exists>K. \<forall>x. norm (f x + g x) \<le> norm x * K"
hoelzl@51642
  1069
      using add_mono[OF Kf Kg]
hoelzl@51642
  1070
      by (intro exI[of _ "Kf + Kg"]) (auto simp: field_simps intro: norm_triangle_ineq order_trans)
hoelzl@51642
  1071
  qed (simp_all add: f.add g.add f.scaleR g.scaleR scaleR_right_distrib)
hoelzl@51642
  1072
qed
hoelzl@51642
  1073
hoelzl@51642
  1074
lemma bounded_linear_minus:
hoelzl@51642
  1075
  assumes "bounded_linear f"
hoelzl@51642
  1076
  shows "bounded_linear (\<lambda>x. - f x)"
hoelzl@51642
  1077
proof -
hoelzl@51642
  1078
  interpret f: bounded_linear f by fact
hoelzl@51642
  1079
  show ?thesis apply (unfold_locales)
hoelzl@51642
  1080
    apply (simp add: f.add)
hoelzl@51642
  1081
    apply (simp add: f.scaleR)
hoelzl@51642
  1082
    apply (simp add: f.bounded)
hoelzl@51642
  1083
    done
hoelzl@51642
  1084
qed
hoelzl@51642
  1085
hoelzl@51642
  1086
lemma bounded_linear_compose:
hoelzl@51642
  1087
  assumes "bounded_linear f"
hoelzl@51642
  1088
  assumes "bounded_linear g"
hoelzl@51642
  1089
  shows "bounded_linear (\<lambda>x. f (g x))"
hoelzl@51642
  1090
proof -
hoelzl@51642
  1091
  interpret f: bounded_linear f by fact
hoelzl@51642
  1092
  interpret g: bounded_linear g by fact
hoelzl@51642
  1093
  show ?thesis proof (unfold_locales)
hoelzl@51642
  1094
    fix x y show "f (g (x + y)) = f (g x) + f (g y)"
hoelzl@51642
  1095
      by (simp only: f.add g.add)
hoelzl@51642
  1096
  next
hoelzl@51642
  1097
    fix r x show "f (g (scaleR r x)) = scaleR r (f (g x))"
hoelzl@51642
  1098
      by (simp only: f.scaleR g.scaleR)
hoelzl@51642
  1099
  next
hoelzl@51642
  1100
    from f.pos_bounded
hoelzl@51642
  1101
    obtain Kf where f: "\<And>x. norm (f x) \<le> norm x * Kf" and Kf: "0 < Kf" by fast
hoelzl@51642
  1102
    from g.pos_bounded
hoelzl@51642
  1103
    obtain Kg where g: "\<And>x. norm (g x) \<le> norm x * Kg" by fast
hoelzl@51642
  1104
    show "\<exists>K. \<forall>x. norm (f (g x)) \<le> norm x * K"
hoelzl@51642
  1105
    proof (intro exI allI)
hoelzl@51642
  1106
      fix x
hoelzl@51642
  1107
      have "norm (f (g x)) \<le> norm (g x) * Kf"
hoelzl@51642
  1108
        using f .
hoelzl@51642
  1109
      also have "\<dots> \<le> (norm x * Kg) * Kf"
hoelzl@51642
  1110
        using g Kf [THEN order_less_imp_le] by (rule mult_right_mono)
hoelzl@51642
  1111
      also have "(norm x * Kg) * Kf = norm x * (Kg * Kf)"
hoelzl@51642
  1112
        by (rule mult_assoc)
hoelzl@51642
  1113
      finally show "norm (f (g x)) \<le> norm x * (Kg * Kf)" .
hoelzl@51642
  1114
    qed
hoelzl@51642
  1115
  qed
hoelzl@51642
  1116
qed
hoelzl@51642
  1117
huffman@44282
  1118
lemma bounded_bilinear_mult:
huffman@44282
  1119
  "bounded_bilinear (op * :: 'a \<Rightarrow> 'a \<Rightarrow> 'a::real_normed_algebra)"
huffman@22442
  1120
apply (rule bounded_bilinear.intro)
webertj@49962
  1121
apply (rule distrib_right)
webertj@49962
  1122
apply (rule distrib_left)
huffman@22442
  1123
apply (rule mult_scaleR_left)
huffman@22442
  1124
apply (rule mult_scaleR_right)
huffman@22442
  1125
apply (rule_tac x="1" in exI)
huffman@22442
  1126
apply (simp add: norm_mult_ineq)
huffman@22442
  1127
done
huffman@22442
  1128
huffman@44282
  1129
lemma bounded_linear_mult_left:
huffman@44282
  1130
  "bounded_linear (\<lambda>x::'a::real_normed_algebra. x * y)"
huffman@44282
  1131
  using bounded_bilinear_mult
huffman@44282
  1132
  by (rule bounded_bilinear.bounded_linear_left)
huffman@22442
  1133
huffman@44282
  1134
lemma bounded_linear_mult_right:
huffman@44282
  1135
  "bounded_linear (\<lambda>y::'a::real_normed_algebra. x * y)"
huffman@44282
  1136
  using bounded_bilinear_mult
huffman@44282
  1137
  by (rule bounded_bilinear.bounded_linear_right)
huffman@23127
  1138
hoelzl@51642
  1139
lemmas bounded_linear_mult_const =
hoelzl@51642
  1140
  bounded_linear_mult_left [THEN bounded_linear_compose]
hoelzl@51642
  1141
hoelzl@51642
  1142
lemmas bounded_linear_const_mult =
hoelzl@51642
  1143
  bounded_linear_mult_right [THEN bounded_linear_compose]
hoelzl@51642
  1144
huffman@44282
  1145
lemma bounded_linear_divide:
huffman@44282
  1146
  "bounded_linear (\<lambda>x::'a::real_normed_field. x / y)"
huffman@44282
  1147
  unfolding divide_inverse by (rule bounded_linear_mult_left)
huffman@23120
  1148
huffman@44282
  1149
lemma bounded_bilinear_scaleR: "bounded_bilinear scaleR"
huffman@22442
  1150
apply (rule bounded_bilinear.intro)
huffman@22442
  1151
apply (rule scaleR_left_distrib)
huffman@22442
  1152
apply (rule scaleR_right_distrib)
huffman@22973
  1153
apply simp
huffman@22442
  1154
apply (rule scaleR_left_commute)
huffman@31586
  1155
apply (rule_tac x="1" in exI, simp)
huffman@22442
  1156
done
huffman@22442
  1157
huffman@44282
  1158
lemma bounded_linear_scaleR_left: "bounded_linear (\<lambda>r. scaleR r x)"
huffman@44282
  1159
  using bounded_bilinear_scaleR
huffman@44282
  1160
  by (rule bounded_bilinear.bounded_linear_left)
huffman@23127
  1161
huffman@44282
  1162
lemma bounded_linear_scaleR_right: "bounded_linear (\<lambda>x. scaleR r x)"
huffman@44282
  1163
  using bounded_bilinear_scaleR
huffman@44282
  1164
  by (rule bounded_bilinear.bounded_linear_right)
huffman@23127
  1165
huffman@44282
  1166
lemma bounded_linear_of_real: "bounded_linear (\<lambda>r. of_real r)"
huffman@44282
  1167
  unfolding of_real_def by (rule bounded_linear_scaleR_left)
huffman@22625
  1168
hoelzl@51642
  1169
lemma real_bounded_linear:
hoelzl@51642
  1170
  fixes f :: "real \<Rightarrow> real"
hoelzl@51642
  1171
  shows "bounded_linear f \<longleftrightarrow> (\<exists>c::real. f = (\<lambda>x. x * c))"
hoelzl@51642
  1172
proof -
hoelzl@51642
  1173
  { fix x assume "bounded_linear f"
hoelzl@51642
  1174
    then interpret bounded_linear f .
hoelzl@51642
  1175
    from scaleR[of x 1] have "f x = x * f 1"
hoelzl@51642
  1176
      by simp }
hoelzl@51642
  1177
  then show ?thesis
hoelzl@51642
  1178
    by (auto intro: exI[of _ "f 1"] bounded_linear_mult_left)
hoelzl@51642
  1179
qed
hoelzl@51642
  1180
huffman@44571
  1181
instance real_normed_algebra_1 \<subseteq> perfect_space
huffman@44571
  1182
proof
huffman@44571
  1183
  fix x::'a
huffman@44571
  1184
  show "\<not> open {x}"
huffman@44571
  1185
    unfolding open_dist dist_norm
huffman@44571
  1186
    by (clarsimp, rule_tac x="x + of_real (e/2)" in exI, simp)
huffman@44571
  1187
qed
huffman@44571
  1188
hoelzl@51531
  1189
subsection {* Filters and Limits on Metric Space *}
hoelzl@51531
  1190
hoelzl@51531
  1191
lemma eventually_nhds_metric:
hoelzl@51531
  1192
  fixes a :: "'a :: metric_space"
hoelzl@51531
  1193
  shows "eventually P (nhds a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. dist x a < d \<longrightarrow> P x)"
hoelzl@51531
  1194
unfolding eventually_nhds open_dist
hoelzl@51531
  1195
apply safe
hoelzl@51531
  1196
apply fast
hoelzl@51531
  1197
apply (rule_tac x="{x. dist x a < d}" in exI, simp)
hoelzl@51531
  1198
apply clarsimp
hoelzl@51531
  1199
apply (rule_tac x="d - dist x a" in exI, clarsimp)
hoelzl@51531
  1200
apply (simp only: less_diff_eq)
hoelzl@51531
  1201
apply (erule le_less_trans [OF dist_triangle])
hoelzl@51531
  1202
done
hoelzl@51531
  1203
hoelzl@51531
  1204
lemma eventually_at:
hoelzl@51641
  1205
  fixes a :: "'a :: metric_space"
hoelzl@51641
  1206
  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
  1207
  unfolding eventually_at_filter eventually_nhds_metric by (auto simp: dist_nz)
hoelzl@51531
  1208
hoelzl@51641
  1209
lemma eventually_at_le:
hoelzl@51641
  1210
  fixes a :: "'a::metric_space"
hoelzl@51641
  1211
  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
  1212
  unfolding eventually_at_filter eventually_nhds_metric
hoelzl@51641
  1213
  apply auto
hoelzl@51641
  1214
  apply (rule_tac x="d / 2" in exI)
hoelzl@51641
  1215
  apply auto
hoelzl@51641
  1216
  done
hoelzl@51531
  1217
hoelzl@51531
  1218
lemma tendstoI:
hoelzl@51531
  1219
  fixes l :: "'a :: metric_space"
hoelzl@51531
  1220
  assumes "\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
hoelzl@51531
  1221
  shows "(f ---> l) F"
hoelzl@51531
  1222
  apply (rule topological_tendstoI)
hoelzl@51531
  1223
  apply (simp add: open_dist)
hoelzl@51531
  1224
  apply (drule (1) bspec, clarify)
hoelzl@51531
  1225
  apply (drule assms)
hoelzl@51531
  1226
  apply (erule eventually_elim1, simp)
hoelzl@51531
  1227
  done
hoelzl@51531
  1228
hoelzl@51531
  1229
lemma tendstoD:
hoelzl@51531
  1230
  fixes l :: "'a :: metric_space"
hoelzl@51531
  1231
  shows "(f ---> l) F \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
hoelzl@51531
  1232
  apply (drule_tac S="{x. dist x l < e}" in topological_tendstoD)
hoelzl@51531
  1233
  apply (clarsimp simp add: open_dist)
hoelzl@51531
  1234
  apply (rule_tac x="e - dist x l" in exI, clarsimp)
hoelzl@51531
  1235
  apply (simp only: less_diff_eq)
hoelzl@51531
  1236
  apply (erule le_less_trans [OF dist_triangle])
hoelzl@51531
  1237
  apply simp
hoelzl@51531
  1238
  apply simp
hoelzl@51531
  1239
  done
hoelzl@51531
  1240
hoelzl@51531
  1241
lemma tendsto_iff:
hoelzl@51531
  1242
  fixes l :: "'a :: metric_space"
hoelzl@51531
  1243
  shows "(f ---> l) F \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) F)"
hoelzl@51531
  1244
  using tendstoI tendstoD by fast
hoelzl@51531
  1245
hoelzl@51531
  1246
lemma metric_tendsto_imp_tendsto:
hoelzl@51531
  1247
  fixes a :: "'a :: metric_space" and b :: "'b :: metric_space"
hoelzl@51531
  1248
  assumes f: "(f ---> a) F"
hoelzl@51531
  1249
  assumes le: "eventually (\<lambda>x. dist (g x) b \<le> dist (f x) a) F"
hoelzl@51531
  1250
  shows "(g ---> b) F"
hoelzl@51531
  1251
proof (rule tendstoI)
hoelzl@51531
  1252
  fix e :: real assume "0 < e"
hoelzl@51531
  1253
  with f have "eventually (\<lambda>x. dist (f x) a < e) F" by (rule tendstoD)
hoelzl@51531
  1254
  with le show "eventually (\<lambda>x. dist (g x) b < e) F"
hoelzl@51531
  1255
    using le_less_trans by (rule eventually_elim2)
hoelzl@51531
  1256
qed
hoelzl@51531
  1257
hoelzl@51531
  1258
lemma filterlim_real_sequentially: "LIM x sequentially. real x :> at_top"
hoelzl@51531
  1259
  unfolding filterlim_at_top
hoelzl@51531
  1260
  apply (intro allI)
hoelzl@51531
  1261
  apply (rule_tac c="natceiling (Z + 1)" in eventually_sequentiallyI)
hoelzl@51531
  1262
  apply (auto simp: natceiling_le_eq)
hoelzl@51531
  1263
  done
hoelzl@51531
  1264
hoelzl@51531
  1265
subsubsection {* Limits of Sequences *}
hoelzl@51531
  1266
hoelzl@51531
  1267
lemma LIMSEQ_def: "X ----> (L::'a::metric_space) \<longleftrightarrow> (\<forall>r>0. \<exists>no. \<forall>n\<ge>no. dist (X n) L < r)"
hoelzl@51531
  1268
  unfolding tendsto_iff eventually_sequentially ..
hoelzl@51531
  1269
hoelzl@51531
  1270
lemma LIMSEQ_iff_nz: "X ----> (L::'a::metric_space) = (\<forall>r>0. \<exists>no>0. \<forall>n\<ge>no. dist (X n) L < r)"
hoelzl@51531
  1271
  unfolding LIMSEQ_def by (metis Suc_leD zero_less_Suc)
hoelzl@51531
  1272
hoelzl@51531
  1273
lemma metric_LIMSEQ_I:
hoelzl@51531
  1274
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. dist (X n) L < r) \<Longrightarrow> X ----> (L::'a::metric_space)"
hoelzl@51531
  1275
by (simp add: LIMSEQ_def)
hoelzl@51531
  1276
hoelzl@51531
  1277
lemma metric_LIMSEQ_D:
hoelzl@51531
  1278
  "\<lbrakk>X ----> (L::'a::metric_space); 0 < r\<rbrakk> \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. dist (X n) L < r"
hoelzl@51531
  1279
by (simp add: LIMSEQ_def)
hoelzl@51531
  1280
hoelzl@51531
  1281
hoelzl@51531
  1282
subsubsection {* Limits of Functions *}
hoelzl@51531
  1283
hoelzl@51531
  1284
lemma LIM_def: "f -- (a::'a::metric_space) --> (L::'b::metric_space) =
hoelzl@51531
  1285
     (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & dist x a < s
hoelzl@51531
  1286
        --> dist (f x) L < r)"
hoelzl@51641
  1287
  unfolding tendsto_iff eventually_at by simp
hoelzl@51531
  1288
hoelzl@51531
  1289
lemma metric_LIM_I:
hoelzl@51531
  1290
  "(\<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
  1291
    \<Longrightarrow> f -- (a::'a::metric_space) --> (L::'b::metric_space)"
hoelzl@51531
  1292
by (simp add: LIM_def)
hoelzl@51531
  1293
hoelzl@51531
  1294
lemma metric_LIM_D:
hoelzl@51531
  1295
  "\<lbrakk>f -- (a::'a::metric_space) --> (L::'b::metric_space); 0 < r\<rbrakk>
hoelzl@51531
  1296
    \<Longrightarrow> \<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x) L < r"
hoelzl@51531
  1297
by (simp add: LIM_def)
hoelzl@51531
  1298
hoelzl@51531
  1299
lemma metric_LIM_imp_LIM:
hoelzl@51531
  1300
  assumes f: "f -- a --> (l::'a::metric_space)"
hoelzl@51531
  1301
  assumes le: "\<And>x. x \<noteq> a \<Longrightarrow> dist (g x) m \<le> dist (f x) l"
hoelzl@51531
  1302
  shows "g -- a --> (m::'b::metric_space)"
hoelzl@51531
  1303
  by (rule metric_tendsto_imp_tendsto [OF f]) (auto simp add: eventually_at_topological le)
hoelzl@51531
  1304
hoelzl@51531
  1305
lemma metric_LIM_equal2:
hoelzl@51531
  1306
  assumes 1: "0 < R"
hoelzl@51531
  1307
  assumes 2: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < R\<rbrakk> \<Longrightarrow> f x = g x"
hoelzl@51531
  1308
  shows "g -- a --> l \<Longrightarrow> f -- (a::'a::metric_space) --> l"
hoelzl@51531
  1309
apply (rule topological_tendstoI)
hoelzl@51531
  1310
apply (drule (2) topological_tendstoD)
hoelzl@51531
  1311
apply (simp add: eventually_at, safe)
hoelzl@51531
  1312
apply (rule_tac x="min d R" in exI, safe)
hoelzl@51531
  1313
apply (simp add: 1)
hoelzl@51531
  1314
apply (simp add: 2)
hoelzl@51531
  1315
done
hoelzl@51531
  1316
hoelzl@51531
  1317
lemma metric_LIM_compose2:
hoelzl@51531
  1318
  assumes f: "f -- (a::'a::metric_space) --> b"
hoelzl@51531
  1319
  assumes g: "g -- b --> c"
hoelzl@51531
  1320
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> b"
hoelzl@51531
  1321
  shows "(\<lambda>x. g (f x)) -- a --> c"
hoelzl@51641
  1322
  using inj
hoelzl@51641
  1323
  by (intro tendsto_compose_eventually[OF g f]) (auto simp: eventually_at)
hoelzl@51531
  1324
hoelzl@51531
  1325
lemma metric_isCont_LIM_compose2:
hoelzl@51531
  1326
  fixes f :: "'a :: metric_space \<Rightarrow> _"
hoelzl@51531
  1327
  assumes f [unfolded isCont_def]: "isCont f a"
hoelzl@51531
  1328
  assumes g: "g -- f a --> l"
hoelzl@51531
  1329
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> f a"
hoelzl@51531
  1330
  shows "(\<lambda>x. g (f x)) -- a --> l"
hoelzl@51531
  1331
by (rule metric_LIM_compose2 [OF f g inj])
hoelzl@51531
  1332
hoelzl@51531
  1333
subsection {* Complete metric spaces *}
hoelzl@51531
  1334
hoelzl@51531
  1335
subsection {* Cauchy sequences *}
hoelzl@51531
  1336
hoelzl@51531
  1337
definition (in metric_space) Cauchy :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool" where
hoelzl@51531
  1338
  "Cauchy X = (\<forall>e>0. \<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. dist (X m) (X n) < e)"
hoelzl@51531
  1339
hoelzl@51531
  1340
subsection {* Cauchy Sequences *}
hoelzl@51531
  1341
hoelzl@51531
  1342
lemma metric_CauchyI:
hoelzl@51531
  1343
  "(\<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
  1344
  by (simp add: Cauchy_def)
hoelzl@51531
  1345
hoelzl@51531
  1346
lemma metric_CauchyD:
hoelzl@51531
  1347
  "Cauchy X \<Longrightarrow> 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < e"
hoelzl@51531
  1348
  by (simp add: Cauchy_def)
hoelzl@51531
  1349
hoelzl@51531
  1350
lemma metric_Cauchy_iff2:
hoelzl@51531
  1351
  "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
  1352
apply (simp add: Cauchy_def, auto)
hoelzl@51531
  1353
apply (drule reals_Archimedean, safe)
hoelzl@51531
  1354
apply (drule_tac x = n in spec, auto)
hoelzl@51531
  1355
apply (rule_tac x = M in exI, auto)
hoelzl@51531
  1356
apply (drule_tac x = m in spec, simp)
hoelzl@51531
  1357
apply (drule_tac x = na in spec, auto)
hoelzl@51531
  1358
done
hoelzl@51531
  1359
hoelzl@51531
  1360
lemma Cauchy_iff2:
hoelzl@51531
  1361
  "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
  1362
  unfolding metric_Cauchy_iff2 dist_real_def ..
hoelzl@51531
  1363
hoelzl@51531
  1364
lemma Cauchy_subseq_Cauchy:
hoelzl@51531
  1365
  "\<lbrakk> Cauchy X; subseq f \<rbrakk> \<Longrightarrow> Cauchy (X o f)"
hoelzl@51531
  1366
apply (auto simp add: Cauchy_def)
hoelzl@51531
  1367
apply (drule_tac x=e in spec, clarify)
hoelzl@51531
  1368
apply (rule_tac x=M in exI, clarify)
hoelzl@51531
  1369
apply (blast intro: le_trans [OF _ seq_suble] dest!: spec)
hoelzl@51531
  1370
done
hoelzl@51531
  1371
hoelzl@51531
  1372
theorem LIMSEQ_imp_Cauchy:
hoelzl@51531
  1373
  assumes X: "X ----> a" shows "Cauchy X"
hoelzl@51531
  1374
proof (rule metric_CauchyI)
hoelzl@51531
  1375
  fix e::real assume "0 < e"
hoelzl@51531
  1376
  hence "0 < e/2" by simp
hoelzl@51531
  1377
  with X have "\<exists>N. \<forall>n\<ge>N. dist (X n) a < e/2" by (rule metric_LIMSEQ_D)
hoelzl@51531
  1378
  then obtain N where N: "\<forall>n\<ge>N. dist (X n) a < e/2" ..
hoelzl@51531
  1379
  show "\<exists>N. \<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m) (X n) < e"
hoelzl@51531
  1380
  proof (intro exI allI impI)
hoelzl@51531
  1381
    fix m assume "N \<le> m"
hoelzl@51531
  1382
    hence m: "dist (X m) a < e/2" using N by fast
hoelzl@51531
  1383
    fix n assume "N \<le> n"
hoelzl@51531
  1384
    hence n: "dist (X n) a < e/2" using N by fast
hoelzl@51531
  1385
    have "dist (X m) (X n) \<le> dist (X m) a + dist (X n) a"
hoelzl@51531
  1386
      by (rule dist_triangle2)
hoelzl@51531
  1387
    also from m n have "\<dots> < e" by simp
hoelzl@51531
  1388
    finally show "dist (X m) (X n) < e" .
hoelzl@51531
  1389
  qed
hoelzl@51531
  1390
qed
hoelzl@51531
  1391
hoelzl@51531
  1392
lemma convergent_Cauchy: "convergent X \<Longrightarrow> Cauchy X"
hoelzl@51531
  1393
unfolding convergent_def
hoelzl@51531
  1394
by (erule exE, erule LIMSEQ_imp_Cauchy)
hoelzl@51531
  1395
hoelzl@51531
  1396
subsubsection {* Cauchy Sequences are Convergent *}
hoelzl@51531
  1397
hoelzl@51531
  1398
class complete_space = metric_space +
hoelzl@51531
  1399
  assumes Cauchy_convergent: "Cauchy X \<Longrightarrow> convergent X"
hoelzl@51531
  1400
hoelzl@51531
  1401
lemma Cauchy_convergent_iff:
hoelzl@51531
  1402
  fixes X :: "nat \<Rightarrow> 'a::complete_space"
hoelzl@51531
  1403
  shows "Cauchy X = convergent X"
hoelzl@51531
  1404
by (fast intro: Cauchy_convergent convergent_Cauchy)
hoelzl@51531
  1405
hoelzl@51531
  1406
subsection {* The set of real numbers is a complete metric space *}
hoelzl@51531
  1407
hoelzl@51531
  1408
text {*
hoelzl@51531
  1409
Proof that Cauchy sequences converge based on the one from
hoelzl@51531
  1410
http://pirate.shu.edu/~wachsmut/ira/numseq/proofs/cauconv.html
hoelzl@51531
  1411
*}
hoelzl@51531
  1412
hoelzl@51531
  1413
text {*
hoelzl@51531
  1414
  If sequence @{term "X"} is Cauchy, then its limit is the lub of
hoelzl@51531
  1415
  @{term "{r::real. \<exists>N. \<forall>n\<ge>N. r < X n}"}
hoelzl@51531
  1416
*}
hoelzl@51531
  1417
hoelzl@51531
  1418
lemma isUb_UNIV_I: "(\<And>y. y \<in> S \<Longrightarrow> y \<le> u) \<Longrightarrow> isUb UNIV S u"
hoelzl@51531
  1419
by (simp add: isUbI setleI)
hoelzl@51531
  1420
hoelzl@51531
  1421
lemma increasing_LIMSEQ:
hoelzl@51531
  1422
  fixes f :: "nat \<Rightarrow> real"
hoelzl@51531
  1423
  assumes inc: "\<And>n. f n \<le> f (Suc n)"
hoelzl@51531
  1424
      and bdd: "\<And>n. f n \<le> l"
hoelzl@51531
  1425
      and en: "\<And>e. 0 < e \<Longrightarrow> \<exists>n. l \<le> f n + e"
hoelzl@51531
  1426
  shows "f ----> l"
hoelzl@51531
  1427
proof (rule increasing_tendsto)
hoelzl@51531
  1428
  fix x assume "x < l"
hoelzl@51531
  1429
  with dense[of 0 "l - x"] obtain e where "0 < e" "e < l - x"
hoelzl@51531
  1430
    by auto
hoelzl@51531
  1431
  from en[OF `0 < e`] obtain n where "l - e \<le> f n"
hoelzl@51531
  1432
    by (auto simp: field_simps)
hoelzl@51531
  1433
  with `e < l - x` `0 < e` have "x < f n" by simp
hoelzl@51531
  1434
  with incseq_SucI[of f, OF inc] show "eventually (\<lambda>n. x < f n) sequentially"
hoelzl@51531
  1435
    by (auto simp: eventually_sequentially incseq_def intro: less_le_trans)
hoelzl@51531
  1436
qed (insert bdd, auto)
hoelzl@51531
  1437
hoelzl@51531
  1438
lemma real_Cauchy_convergent:
hoelzl@51531
  1439
  fixes X :: "nat \<Rightarrow> real"
hoelzl@51531
  1440
  assumes X: "Cauchy X"
hoelzl@51531
  1441
  shows "convergent X"
hoelzl@51531
  1442
proof -
hoelzl@51531
  1443
  def S \<equiv> "{x::real. \<exists>N. \<forall>n\<ge>N. x < X n}"
hoelzl@51531
  1444
  then have mem_S: "\<And>N x. \<forall>n\<ge>N. x < X n \<Longrightarrow> x \<in> S" by auto
hoelzl@51531
  1445
hoelzl@51531
  1446
  { fix N x assume N: "\<forall>n\<ge>N. X n < x"
hoelzl@51531
  1447
  have "isUb UNIV S x"
hoelzl@51531
  1448
  proof (rule isUb_UNIV_I)
hoelzl@51531
  1449
  fix y::real assume "y \<in> S"
hoelzl@51531
  1450
  hence "\<exists>M. \<forall>n\<ge>M. y < X n"
hoelzl@51531
  1451
    by (simp add: S_def)
hoelzl@51531
  1452
  then obtain M where "\<forall>n\<ge>M. y < X n" ..
hoelzl@51531
  1453
  hence "y < X (max M N)" by simp
hoelzl@51531
  1454
  also have "\<dots> < x" using N by simp
hoelzl@51531
  1455
  finally show "y \<le> x"
hoelzl@51531
  1456
    by (rule order_less_imp_le)
hoelzl@51531
  1457
  qed }
hoelzl@51531
  1458
  note bound_isUb = this 
hoelzl@51531
  1459
hoelzl@51531
  1460
  have "\<exists>u. isLub UNIV S u"
hoelzl@51531
  1461
  proof (rule reals_complete)
hoelzl@51531
  1462
  obtain N where "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m) (X n) < 1"
hoelzl@51531
  1463
    using X[THEN metric_CauchyD, OF zero_less_one] by auto
hoelzl@51531
  1464
  hence N: "\<forall>n\<ge>N. dist (X n) (X N) < 1" by simp
hoelzl@51531
  1465
  show "\<exists>x. x \<in> S"
hoelzl@51531
  1466
  proof
hoelzl@51531
  1467
    from N have "\<forall>n\<ge>N. X N - 1 < X n"
hoelzl@51531
  1468
      by (simp add: abs_diff_less_iff dist_real_def)
hoelzl@51531
  1469
    thus "X N - 1 \<in> S" by (rule mem_S)
hoelzl@51531
  1470
  qed
hoelzl@51531
  1471
  show "\<exists>u. isUb UNIV S u"
hoelzl@51531
  1472
  proof
hoelzl@51531
  1473
    from N have "\<forall>n\<ge>N. X n < X N + 1"
hoelzl@51531
  1474
      by (simp add: abs_diff_less_iff dist_real_def)
hoelzl@51531
  1475
    thus "isUb UNIV S (X N + 1)"
hoelzl@51531
  1476
      by (rule bound_isUb)
hoelzl@51531
  1477
  qed
hoelzl@51531
  1478
  qed
hoelzl@51531
  1479
  then obtain x where x: "isLub UNIV S x" ..
hoelzl@51531
  1480
  have "X ----> x"
hoelzl@51531
  1481
  proof (rule metric_LIMSEQ_I)
hoelzl@51531
  1482
  fix r::real assume "0 < r"
hoelzl@51531
  1483
  hence r: "0 < r/2" by simp
hoelzl@51531
  1484
  obtain N where "\<forall>n\<ge>N. \<forall>m\<ge>N. dist (X n) (X m) < r/2"
hoelzl@51531
  1485
    using metric_CauchyD [OF X r] by auto
hoelzl@51531
  1486
  hence "\<forall>n\<ge>N. dist (X n) (X N) < r/2" by simp
hoelzl@51531
  1487
  hence N: "\<forall>n\<ge>N. X N - r/2 < X n \<and> X n < X N + r/2"
hoelzl@51531
  1488
    by (simp only: dist_real_def abs_diff_less_iff)
hoelzl@51531
  1489
hoelzl@51531
  1490
  from N have "\<forall>n\<ge>N. X N - r/2 < X n" by fast
hoelzl@51531
  1491
  hence "X N - r/2 \<in> S" by (rule mem_S)
hoelzl@51531
  1492
  hence 1: "X N - r/2 \<le> x" using x isLub_isUb isUbD by fast
hoelzl@51531
  1493
hoelzl@51531
  1494
  from N have "\<forall>n\<ge>N. X n < X N + r/2" by fast
hoelzl@51531
  1495
  hence "isUb UNIV S (X N + r/2)" by (rule bound_isUb)
hoelzl@51531
  1496
  hence 2: "x \<le> X N + r/2" using x isLub_le_isUb by fast
hoelzl@51531
  1497
hoelzl@51531
  1498
  show "\<exists>N. \<forall>n\<ge>N. dist (X n) x < r"
hoelzl@51531
  1499
  proof (intro exI allI impI)
hoelzl@51531
  1500
    fix n assume n: "N \<le> n"
hoelzl@51531
  1501
    from N n have "X n < X N + r/2" and "X N - r/2 < X n" by simp+
hoelzl@51531
  1502
    thus "dist (X n) x < r" using 1 2
hoelzl@51531
  1503
      by (simp add: abs_diff_less_iff dist_real_def)
hoelzl@51531
  1504
  qed
hoelzl@51531
  1505
  qed
hoelzl@51531
  1506
  then show ?thesis unfolding convergent_def by auto
hoelzl@51531
  1507
qed
hoelzl@51531
  1508
hoelzl@51531
  1509
instance real :: complete_space
hoelzl@51531
  1510
  by intro_classes (rule real_Cauchy_convergent)
hoelzl@51531
  1511
hoelzl@51531
  1512
class banach = real_normed_vector + complete_space
hoelzl@51531
  1513
hoelzl@51531
  1514
instance real :: banach by default
hoelzl@51531
  1515
hoelzl@51531
  1516
lemma tendsto_at_topI_sequentially:
hoelzl@51531
  1517
  fixes f :: "real \<Rightarrow> real"
hoelzl@51531
  1518
  assumes mono: "mono f"
hoelzl@51531
  1519
  assumes limseq: "(\<lambda>n. f (real n)) ----> y"
hoelzl@51531
  1520
  shows "(f ---> y) at_top"
hoelzl@51531
  1521
proof (rule tendstoI)
hoelzl@51531
  1522
  fix e :: real assume "0 < e"
hoelzl@51531
  1523
  with limseq obtain N :: nat where N: "\<And>n. N \<le> n \<Longrightarrow> \<bar>f (real n) - y\<bar> < e"
hoelzl@51531
  1524
    by (auto simp: LIMSEQ_def dist_real_def)
hoelzl@51531
  1525
  { fix x :: real
hoelzl@51531
  1526
    from ex_le_of_nat[of x] guess n ..
hoelzl@51531
  1527
    note monoD[OF mono this]
hoelzl@51531
  1528
    also have "f (real_of_nat n) \<le> y"
hoelzl@51531
  1529
      by (rule LIMSEQ_le_const[OF limseq])
hoelzl@51531
  1530
         (auto intro: exI[of _ n] monoD[OF mono] simp: real_eq_of_nat[symmetric])
hoelzl@51531
  1531
    finally have "f x \<le> y" . }
hoelzl@51531
  1532
  note le = this
hoelzl@51531
  1533
  have "eventually (\<lambda>x. real N \<le> x) at_top"
hoelzl@51531
  1534
    by (rule eventually_ge_at_top)
hoelzl@51531
  1535
  then show "eventually (\<lambda>x. dist (f x) y < e) at_top"
hoelzl@51531
  1536
  proof eventually_elim
hoelzl@51531
  1537
    fix x assume N': "real N \<le> x"
hoelzl@51531
  1538
    with N[of N] le have "y - f (real N) < e" by auto
hoelzl@51531
  1539
    moreover note monoD[OF mono N']
hoelzl@51531
  1540
    ultimately show "dist (f x) y < e"
hoelzl@51531
  1541
      using le[of x] by (auto simp: dist_real_def field_simps)
hoelzl@51531
  1542
  qed
hoelzl@51531
  1543
qed
hoelzl@51531
  1544
huffman@20504
  1545
end