src/HOL/Real_Vector_Spaces.thy
author paulson <lp15@cam.ac.uk>
Wed Apr 29 14:04:22 2015 +0100 (2015-04-29)
changeset 60155 91477b3a2d6b
parent 60026 41d81b4a0a21
child 60303 00c06f1315d0
permissions -rw-r--r--
Tidying. Improved simplification for numerals, esp in exponents.
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@58889
     6
section {* 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@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
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)"
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
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@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
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"
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
huffman@20554
   306
text{*Collapse nested embeddings*}
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
huffman@22912
   325
text{*Every real algebra has characteristic zero*}
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
huffman@20554
   336
subsection {* The Set of Real Numbers *}
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 -
huffman@20554
   442
  from `q \<in> \<real>` 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
immler@54778
   471
subsection {* Ordered real vector spaces *}
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
immler@54778
   521
lemma scaleR_nonneg_nonneg: "0 \<le> a \<Longrightarrow> 0 \<le> (x::'a::ordered_real_vector) \<Longrightarrow> 0 \<le> a *\<^sub>R x"
immler@54778
   522
  using scaleR_left_mono [of 0 x a]
immler@54778
   523
  by simp
immler@54778
   524
immler@54778
   525
lemma scaleR_nonneg_nonpos: "0 \<le> a \<Longrightarrow> (x::'a::ordered_real_vector) \<le> 0 \<Longrightarrow> a *\<^sub>R x \<le> 0"
immler@54778
   526
  using scaleR_left_mono [of x 0 a] by simp
immler@54778
   527
immler@54778
   528
lemma scaleR_nonpos_nonneg: "a \<le> 0 \<Longrightarrow> 0 \<le> (x::'a::ordered_real_vector) \<Longrightarrow> a *\<^sub>R x \<le> 0"
immler@54778
   529
  using scaleR_right_mono [of a 0 x] by simp
immler@54778
   530
immler@54778
   531
lemma split_scaleR_neg_le: "(0 \<le> a & x \<le> 0) | (a \<le> 0 & 0 \<le> x) \<Longrightarrow>
immler@54778
   532
  a *\<^sub>R (x::'a::ordered_real_vector) \<le> 0"
immler@54778
   533
  by (auto simp add: scaleR_nonneg_nonpos scaleR_nonpos_nonneg)
immler@54778
   534
immler@54778
   535
lemma le_add_iff1:
immler@54778
   536
  fixes c d e::"'a::ordered_real_vector"
immler@54778
   537
  shows "a *\<^sub>R e + c \<le> b *\<^sub>R e + d \<longleftrightarrow> (a - b) *\<^sub>R e + c \<le> d"
immler@54778
   538
  by (simp add: algebra_simps)
immler@54778
   539
immler@54778
   540
lemma le_add_iff2:
immler@54778
   541
  fixes c d e::"'a::ordered_real_vector"
immler@54778
   542
  shows "a *\<^sub>R e + c \<le> b *\<^sub>R e + d \<longleftrightarrow> c \<le> (b - a) *\<^sub>R e + d"
immler@54778
   543
  by (simp add: algebra_simps)
immler@54778
   544
immler@54778
   545
lemma scaleR_left_mono_neg:
immler@54778
   546
  fixes a b::"'a::ordered_real_vector"
immler@54778
   547
  shows "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> c *\<^sub>R a \<le> c *\<^sub>R b"
immler@54778
   548
  apply (drule scaleR_left_mono [of _ _ "- c"])
immler@54778
   549
  apply simp_all
immler@54778
   550
  done
immler@54778
   551
immler@54778
   552
lemma scaleR_right_mono_neg:
immler@54778
   553
  fixes c::"'a::ordered_real_vector"
immler@54778
   554
  shows "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> a *\<^sub>R c \<le> b *\<^sub>R c"
immler@54778
   555
  apply (drule scaleR_right_mono [of _ _ "- c"])
immler@54778
   556
  apply simp_all
immler@54778
   557
  done
immler@54778
   558
immler@54778
   559
lemma scaleR_nonpos_nonpos: "a \<le> 0 \<Longrightarrow> (b::'a::ordered_real_vector) \<le> 0 \<Longrightarrow> 0 \<le> a *\<^sub>R b"
immler@54778
   560
using scaleR_right_mono_neg [of a 0 b] by simp
immler@54778
   561
immler@54778
   562
lemma split_scaleR_pos_le:
immler@54778
   563
  fixes b::"'a::ordered_real_vector"
immler@54778
   564
  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
   565
  by (auto simp add: scaleR_nonneg_nonneg scaleR_nonpos_nonpos)
immler@54778
   566
immler@54778
   567
lemma zero_le_scaleR_iff:
immler@54778
   568
  fixes b::"'a::ordered_real_vector"
immler@54778
   569
  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
   570
proof cases
immler@54778
   571
  assume "a \<noteq> 0"
immler@54778
   572
  show ?thesis
immler@54778
   573
  proof
immler@54778
   574
    assume lhs: ?lhs
immler@54778
   575
    {
immler@54778
   576
      assume "0 < a"
immler@54778
   577
      with lhs have "inverse a *\<^sub>R 0 \<le> inverse a *\<^sub>R (a *\<^sub>R b)"
immler@54778
   578
        by (intro scaleR_mono) auto
immler@54778
   579
      hence ?rhs using `0 < a`
immler@54778
   580
        by simp
immler@54778
   581
    } moreover {
immler@54778
   582
      assume "0 > a"
immler@54778
   583
      with lhs have "- inverse a *\<^sub>R 0 \<le> - inverse a *\<^sub>R (a *\<^sub>R b)"
immler@54778
   584
        by (intro scaleR_mono) auto
immler@54778
   585
      hence ?rhs using `0 > a`
immler@54778
   586
        by simp
immler@54778
   587
    } ultimately show ?rhs using `a \<noteq> 0` by arith
immler@54778
   588
  qed (auto simp: not_le `a \<noteq> 0` intro!: split_scaleR_pos_le)
immler@54778
   589
qed simp
immler@54778
   590
immler@54778
   591
lemma scaleR_le_0_iff:
immler@54778
   592
  fixes b::"'a::ordered_real_vector"
immler@54778
   593
  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
   594
  by (insert zero_le_scaleR_iff [of "-a" b]) force
immler@54778
   595
immler@54778
   596
lemma scaleR_le_cancel_left:
immler@54778
   597
  fixes b::"'a::ordered_real_vector"
immler@54778
   598
  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
   599
  by (auto simp add: neq_iff scaleR_left_mono scaleR_left_mono_neg
immler@54778
   600
    dest: scaleR_left_mono[where a="inverse c"] scaleR_left_mono_neg[where c="inverse c"])
immler@54778
   601
immler@54778
   602
lemma scaleR_le_cancel_left_pos:
immler@54778
   603
  fixes b::"'a::ordered_real_vector"
immler@54778
   604
  shows "0 < c \<Longrightarrow> c *\<^sub>R a \<le> c *\<^sub>R b \<longleftrightarrow> a \<le> b"
immler@54778
   605
  by (auto simp: scaleR_le_cancel_left)
immler@54778
   606
immler@54778
   607
lemma scaleR_le_cancel_left_neg:
immler@54778
   608
  fixes b::"'a::ordered_real_vector"
immler@54778
   609
  shows "c < 0 \<Longrightarrow> c *\<^sub>R a \<le> c *\<^sub>R b \<longleftrightarrow> b \<le> a"
immler@54778
   610
  by (auto simp: scaleR_le_cancel_left)
immler@54778
   611
immler@54778
   612
lemma scaleR_left_le_one_le:
immler@54778
   613
  fixes x::"'a::ordered_real_vector" and a::real
immler@54778
   614
  shows "0 \<le> x \<Longrightarrow> a \<le> 1 \<Longrightarrow> a *\<^sub>R x \<le> x"
immler@54778
   615
  using scaleR_right_mono[of a 1 x] by simp
immler@54778
   616
huffman@20504
   617
huffman@20504
   618
subsection {* Real normed vector spaces *}
huffman@20504
   619
hoelzl@51531
   620
class dist =
hoelzl@51531
   621
  fixes dist :: "'a \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@51531
   622
haftmann@29608
   623
class norm =
huffman@22636
   624
  fixes norm :: "'a \<Rightarrow> real"
huffman@20504
   625
huffman@24520
   626
class sgn_div_norm = scaleR + norm + sgn +
haftmann@25062
   627
  assumes sgn_div_norm: "sgn x = x /\<^sub>R norm x"
nipkow@24506
   628
huffman@31289
   629
class dist_norm = dist + norm + minus +
huffman@31289
   630
  assumes dist_norm: "dist x y = norm (x - y)"
huffman@31289
   631
hoelzl@51531
   632
class open_dist = "open" + dist +
hoelzl@51531
   633
  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
   634
huffman@31492
   635
class real_normed_vector = real_vector + sgn_div_norm + dist_norm + open_dist +
hoelzl@51002
   636
  assumes norm_eq_zero [simp]: "norm x = 0 \<longleftrightarrow> x = 0"
haftmann@25062
   637
  and norm_triangle_ineq: "norm (x + y) \<le> norm x + norm y"
huffman@31586
   638
  and norm_scaleR [simp]: "norm (scaleR a x) = \<bar>a\<bar> * norm x"
hoelzl@51002
   639
begin
hoelzl@51002
   640
hoelzl@51002
   641
lemma norm_ge_zero [simp]: "0 \<le> norm x"
hoelzl@51002
   642
proof -
lp15@60026
   643
  have "0 = norm (x + -1 *\<^sub>R x)"
hoelzl@51002
   644
    using scaleR_add_left[of 1 "-1" x] norm_scaleR[of 0 x] by (simp add: scaleR_one)
hoelzl@51002
   645
  also have "\<dots> \<le> norm x + norm (-1 *\<^sub>R x)" by (rule norm_triangle_ineq)
hoelzl@51002
   646
  finally show ?thesis by simp
hoelzl@51002
   647
qed
hoelzl@51002
   648
hoelzl@51002
   649
end
huffman@20504
   650
haftmann@24588
   651
class real_normed_algebra = real_algebra + real_normed_vector +
haftmann@25062
   652
  assumes norm_mult_ineq: "norm (x * y) \<le> norm x * norm y"
huffman@20504
   653
haftmann@24588
   654
class real_normed_algebra_1 = real_algebra_1 + real_normed_algebra +
haftmann@25062
   655
  assumes norm_one [simp]: "norm 1 = 1"
huffman@22852
   656
haftmann@24588
   657
class real_normed_div_algebra = real_div_algebra + real_normed_vector +
haftmann@25062
   658
  assumes norm_mult: "norm (x * y) = norm x * norm y"
huffman@20504
   659
haftmann@24588
   660
class real_normed_field = real_field + real_normed_div_algebra
huffman@20584
   661
huffman@22852
   662
instance real_normed_div_algebra < real_normed_algebra_1
huffman@20554
   663
proof
huffman@20554
   664
  fix x y :: 'a
huffman@20554
   665
  show "norm (x * y) \<le> norm x * norm y"
huffman@20554
   666
    by (simp add: norm_mult)
huffman@22852
   667
next
huffman@22852
   668
  have "norm (1 * 1::'a) = norm (1::'a) * norm (1::'a)"
huffman@22852
   669
    by (rule norm_mult)
huffman@22852
   670
  thus "norm (1::'a) = 1" by simp
huffman@20554
   671
qed
huffman@20554
   672
huffman@22852
   673
lemma norm_zero [simp]: "norm (0::'a::real_normed_vector) = 0"
huffman@20504
   674
by simp
huffman@20504
   675
huffman@22852
   676
lemma zero_less_norm_iff [simp]:
huffman@22852
   677
  fixes x :: "'a::real_normed_vector"
huffman@22852
   678
  shows "(0 < norm x) = (x \<noteq> 0)"
huffman@20504
   679
by (simp add: order_less_le)
huffman@20504
   680
huffman@22852
   681
lemma norm_not_less_zero [simp]:
huffman@22852
   682
  fixes x :: "'a::real_normed_vector"
huffman@22852
   683
  shows "\<not> norm x < 0"
huffman@20828
   684
by (simp add: linorder_not_less)
huffman@20828
   685
huffman@22852
   686
lemma norm_le_zero_iff [simp]:
huffman@22852
   687
  fixes x :: "'a::real_normed_vector"
huffman@22852
   688
  shows "(norm x \<le> 0) = (x = 0)"
huffman@20828
   689
by (simp add: order_le_less)
huffman@20828
   690
huffman@20504
   691
lemma norm_minus_cancel [simp]:
huffman@20584
   692
  fixes x :: "'a::real_normed_vector"
huffman@20584
   693
  shows "norm (- x) = norm x"
huffman@20504
   694
proof -
huffman@21809
   695
  have "norm (- x) = norm (scaleR (- 1) x)"
huffman@20504
   696
    by (simp only: scaleR_minus_left scaleR_one)
huffman@20533
   697
  also have "\<dots> = \<bar>- 1\<bar> * norm x"
huffman@20504
   698
    by (rule norm_scaleR)
huffman@20504
   699
  finally show ?thesis by simp
huffman@20504
   700
qed
huffman@20504
   701
huffman@20504
   702
lemma norm_minus_commute:
huffman@20584
   703
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   704
  shows "norm (a - b) = norm (b - a)"
huffman@20504
   705
proof -
huffman@22898
   706
  have "norm (- (b - a)) = norm (b - a)"
huffman@22898
   707
    by (rule norm_minus_cancel)
huffman@22898
   708
  thus ?thesis by simp
huffman@20504
   709
qed
huffman@20504
   710
huffman@20504
   711
lemma norm_triangle_ineq2:
huffman@20584
   712
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   713
  shows "norm a - norm b \<le> norm (a - b)"
huffman@20504
   714
proof -
huffman@20533
   715
  have "norm (a - b + b) \<le> norm (a - b) + norm b"
huffman@20504
   716
    by (rule norm_triangle_ineq)
huffman@22898
   717
  thus ?thesis by simp
huffman@20504
   718
qed
huffman@20504
   719
huffman@20584
   720
lemma norm_triangle_ineq3:
huffman@20584
   721
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   722
  shows "\<bar>norm a - norm b\<bar> \<le> norm (a - b)"
huffman@20584
   723
apply (subst abs_le_iff)
huffman@20584
   724
apply auto
huffman@20584
   725
apply (rule norm_triangle_ineq2)
huffman@20584
   726
apply (subst norm_minus_commute)
huffman@20584
   727
apply (rule norm_triangle_ineq2)
huffman@20584
   728
done
huffman@20584
   729
huffman@20504
   730
lemma norm_triangle_ineq4:
huffman@20584
   731
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   732
  shows "norm (a - b) \<le> norm a + norm b"
huffman@20504
   733
proof -
huffman@22898
   734
  have "norm (a + - b) \<le> norm a + norm (- b)"
huffman@20504
   735
    by (rule norm_triangle_ineq)
haftmann@54230
   736
  then show ?thesis by simp
huffman@22898
   737
qed
huffman@22898
   738
huffman@22898
   739
lemma norm_diff_ineq:
huffman@22898
   740
  fixes a b :: "'a::real_normed_vector"
huffman@22898
   741
  shows "norm a - norm b \<le> norm (a + b)"
huffman@22898
   742
proof -
huffman@22898
   743
  have "norm a - norm (- b) \<le> norm (a - - b)"
huffman@22898
   744
    by (rule norm_triangle_ineq2)
huffman@22898
   745
  thus ?thesis by simp
huffman@20504
   746
qed
huffman@20504
   747
huffman@20551
   748
lemma norm_diff_triangle_ineq:
huffman@20551
   749
  fixes a b c d :: "'a::real_normed_vector"
huffman@20551
   750
  shows "norm ((a + b) - (c + d)) \<le> norm (a - c) + norm (b - d)"
huffman@20551
   751
proof -
huffman@20551
   752
  have "norm ((a + b) - (c + d)) = norm ((a - c) + (b - d))"
haftmann@54230
   753
    by (simp add: algebra_simps)
huffman@20551
   754
  also have "\<dots> \<le> norm (a - c) + norm (b - d)"
huffman@20551
   755
    by (rule norm_triangle_ineq)
huffman@20551
   756
  finally show ?thesis .
huffman@20551
   757
qed
huffman@20551
   758
lp15@60026
   759
lemma norm_triangle_mono:
lp15@55719
   760
  fixes a b :: "'a::real_normed_vector"
lp15@55719
   761
  shows "\<lbrakk>norm a \<le> r; norm b \<le> s\<rbrakk> \<Longrightarrow> norm (a + b) \<le> r + s"
lp15@55719
   762
by (metis add_mono_thms_linordered_semiring(1) norm_triangle_ineq order.trans)
lp15@55719
   763
hoelzl@56194
   764
lemma norm_setsum:
hoelzl@56194
   765
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
hoelzl@56194
   766
  shows "norm (setsum f A) \<le> (\<Sum>i\<in>A. norm (f i))"
hoelzl@56194
   767
  by (induct A rule: infinite_finite_induct) (auto intro: norm_triangle_mono)
hoelzl@56194
   768
hoelzl@56369
   769
lemma setsum_norm_le:
hoelzl@56369
   770
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
hoelzl@56369
   771
  assumes fg: "\<forall>x \<in> S. norm (f x) \<le> g x"
hoelzl@56369
   772
  shows "norm (setsum f S) \<le> setsum g S"
hoelzl@56369
   773
  by (rule order_trans [OF norm_setsum setsum_mono]) (simp add: fg)
hoelzl@56369
   774
huffman@22857
   775
lemma abs_norm_cancel [simp]:
huffman@22857
   776
  fixes a :: "'a::real_normed_vector"
huffman@22857
   777
  shows "\<bar>norm a\<bar> = norm a"
huffman@22857
   778
by (rule abs_of_nonneg [OF norm_ge_zero])
huffman@22857
   779
huffman@22880
   780
lemma norm_add_less:
huffman@22880
   781
  fixes x y :: "'a::real_normed_vector"
huffman@22880
   782
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x + y) < r + s"
huffman@22880
   783
by (rule order_le_less_trans [OF norm_triangle_ineq add_strict_mono])
huffman@22880
   784
huffman@22880
   785
lemma norm_mult_less:
huffman@22880
   786
  fixes x y :: "'a::real_normed_algebra"
huffman@22880
   787
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x * y) < r * s"
huffman@22880
   788
apply (rule order_le_less_trans [OF norm_mult_ineq])
huffman@22880
   789
apply (simp add: mult_strict_mono')
huffman@22880
   790
done
huffman@22880
   791
huffman@22857
   792
lemma norm_of_real [simp]:
huffman@22857
   793
  "norm (of_real r :: 'a::real_normed_algebra_1) = \<bar>r\<bar>"
huffman@31586
   794
unfolding of_real_def by simp
huffman@20560
   795
huffman@47108
   796
lemma norm_numeral [simp]:
huffman@47108
   797
  "norm (numeral w::'a::real_normed_algebra_1) = numeral w"
huffman@47108
   798
by (subst of_real_numeral [symmetric], subst norm_of_real, simp)
huffman@47108
   799
huffman@47108
   800
lemma norm_neg_numeral [simp]:
haftmann@54489
   801
  "norm (- numeral w::'a::real_normed_algebra_1) = numeral w"
huffman@47108
   802
by (subst of_real_neg_numeral [symmetric], subst norm_of_real, simp)
huffman@22876
   803
huffman@22876
   804
lemma norm_of_int [simp]:
huffman@22876
   805
  "norm (of_int z::'a::real_normed_algebra_1) = \<bar>of_int z\<bar>"
huffman@22876
   806
by (subst of_real_of_int_eq [symmetric], rule norm_of_real)
huffman@22876
   807
huffman@22876
   808
lemma norm_of_nat [simp]:
huffman@22876
   809
  "norm (of_nat n::'a::real_normed_algebra_1) = of_nat n"
huffman@22876
   810
apply (subst of_real_of_nat_eq [symmetric])
huffman@22876
   811
apply (subst norm_of_real, simp)
huffman@22876
   812
done
huffman@22876
   813
huffman@20504
   814
lemma nonzero_norm_inverse:
huffman@20504
   815
  fixes a :: "'a::real_normed_div_algebra"
huffman@20533
   816
  shows "a \<noteq> 0 \<Longrightarrow> norm (inverse a) = inverse (norm a)"
huffman@20504
   817
apply (rule inverse_unique [symmetric])
huffman@20504
   818
apply (simp add: norm_mult [symmetric])
huffman@20504
   819
done
huffman@20504
   820
huffman@20504
   821
lemma norm_inverse:
haftmann@59867
   822
  fixes a :: "'a::{real_normed_div_algebra, division_ring}"
huffman@20533
   823
  shows "norm (inverse a) = inverse (norm a)"
huffman@20504
   824
apply (case_tac "a = 0", simp)
huffman@20504
   825
apply (erule nonzero_norm_inverse)
huffman@20504
   826
done
huffman@20504
   827
huffman@20584
   828
lemma nonzero_norm_divide:
huffman@20584
   829
  fixes a b :: "'a::real_normed_field"
huffman@20584
   830
  shows "b \<noteq> 0 \<Longrightarrow> norm (a / b) = norm a / norm b"
huffman@20584
   831
by (simp add: divide_inverse norm_mult nonzero_norm_inverse)
huffman@20584
   832
huffman@20584
   833
lemma norm_divide:
haftmann@59867
   834
  fixes a b :: "'a::{real_normed_field, field}"
huffman@20584
   835
  shows "norm (a / b) = norm a / norm b"
huffman@20584
   836
by (simp add: divide_inverse norm_mult norm_inverse)
huffman@20584
   837
huffman@22852
   838
lemma norm_power_ineq:
haftmann@31017
   839
  fixes x :: "'a::{real_normed_algebra_1}"
huffman@22852
   840
  shows "norm (x ^ n) \<le> norm x ^ n"
huffman@22852
   841
proof (induct n)
huffman@22852
   842
  case 0 show "norm (x ^ 0) \<le> norm x ^ 0" by simp
huffman@22852
   843
next
huffman@22852
   844
  case (Suc n)
huffman@22852
   845
  have "norm (x * x ^ n) \<le> norm x * norm (x ^ n)"
huffman@22852
   846
    by (rule norm_mult_ineq)
huffman@22852
   847
  also from Suc have "\<dots> \<le> norm x * norm x ^ n"
huffman@22852
   848
    using norm_ge_zero by (rule mult_left_mono)
huffman@22852
   849
  finally show "norm (x ^ Suc n) \<le> norm x ^ Suc n"
huffman@30273
   850
    by simp
huffman@22852
   851
qed
huffman@22852
   852
huffman@20684
   853
lemma norm_power:
haftmann@31017
   854
  fixes x :: "'a::{real_normed_div_algebra}"
huffman@20684
   855
  shows "norm (x ^ n) = norm x ^ n"
huffman@30273
   856
by (induct n) (simp_all add: norm_mult)
huffman@20684
   857
lp15@59613
   858
text{*Despite a superficial resemblance, @{text norm_eq_1} is not relevant.*}
lp15@59613
   859
lemma square_norm_one:
lp15@59613
   860
  fixes x :: "'a::real_normed_div_algebra"
lp15@59613
   861
  assumes "x^2 = 1" shows "norm x = 1"
lp15@59613
   862
  by (metis assms norm_minus_cancel norm_one power2_eq_1_iff)
lp15@59613
   863
lp15@59658
   864
lemma norm_less_p1:
lp15@59658
   865
  fixes x :: "'a::real_normed_algebra_1"
lp15@59658
   866
  shows "norm x < norm (of_real (norm x) + 1 :: 'a)"
lp15@59658
   867
proof -
lp15@59658
   868
  have "norm x < norm (of_real (norm x + 1) :: 'a)"
lp15@59658
   869
    by (simp add: of_real_def)
lp15@59658
   870
  then show ?thesis
lp15@59658
   871
    by simp
lp15@59658
   872
qed
lp15@59658
   873
lp15@55719
   874
lemma setprod_norm:
lp15@55719
   875
  fixes f :: "'a \<Rightarrow> 'b::{comm_semiring_1,real_normed_div_algebra}"
lp15@55719
   876
  shows "setprod (\<lambda>x. norm(f x)) A = norm (setprod f A)"
hoelzl@57275
   877
  by (induct A rule: infinite_finite_induct) (auto simp: norm_mult)
hoelzl@57275
   878
lp15@60026
   879
lemma norm_setprod_le:
hoelzl@57275
   880
  "norm (setprod f A) \<le> (\<Prod>a\<in>A. norm (f a :: 'a :: {real_normed_algebra_1, comm_monoid_mult}))"
hoelzl@57275
   881
proof (induction A rule: infinite_finite_induct)
hoelzl@57275
   882
  case (insert a A)
hoelzl@57275
   883
  then have "norm (setprod f (insert a A)) \<le> norm (f a) * norm (setprod f A)"
hoelzl@57275
   884
    by (simp add: norm_mult_ineq)
hoelzl@57275
   885
  also have "norm (setprod f A) \<le> (\<Prod>a\<in>A. norm (f a))"
hoelzl@57275
   886
    by (rule insert)
hoelzl@57275
   887
  finally show ?case
hoelzl@57275
   888
    by (simp add: insert mult_left_mono)
hoelzl@57275
   889
qed simp_all
hoelzl@57275
   890
hoelzl@57275
   891
lemma norm_setprod_diff:
hoelzl@57275
   892
  fixes z w :: "'i \<Rightarrow> 'a::{real_normed_algebra_1, comm_monoid_mult}"
hoelzl@57275
   893
  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
   894
    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
   895
proof (induction I rule: infinite_finite_induct)
hoelzl@57275
   896
  case (insert i I)
hoelzl@57275
   897
  note insert.hyps[simp]
hoelzl@57275
   898
hoelzl@57275
   899
  have "norm ((\<Prod>i\<in>insert i I. z i) - (\<Prod>i\<in>insert i I. w i)) =
hoelzl@57275
   900
    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
   901
    (is "_ = norm (?t1 + ?t2)")
hoelzl@57275
   902
    by (auto simp add: field_simps)
hoelzl@57275
   903
  also have "... \<le> norm ?t1 + norm ?t2"
hoelzl@57275
   904
    by (rule norm_triangle_ineq)
hoelzl@57275
   905
  also have "norm ?t1 \<le> norm (\<Prod>i\<in>I. z i) * norm (z i - w i)"
hoelzl@57275
   906
    by (rule norm_mult_ineq)
hoelzl@57275
   907
  also have "\<dots> \<le> (\<Prod>i\<in>I. norm (z i)) * norm(z i - w i)"
hoelzl@57275
   908
    by (rule mult_right_mono) (auto intro: norm_setprod_le)
hoelzl@57275
   909
  also have "(\<Prod>i\<in>I. norm (z i)) \<le> (\<Prod>i\<in>I. 1)"
hoelzl@57275
   910
    by (intro setprod_mono) (auto intro!: insert)
hoelzl@57275
   911
  also have "norm ?t2 \<le> norm ((\<Prod>i\<in>I. z i) - (\<Prod>i\<in>I. w i)) * norm (w i)"
hoelzl@57275
   912
    by (rule norm_mult_ineq)
hoelzl@57275
   913
  also have "norm (w i) \<le> 1"
hoelzl@57275
   914
    by (auto intro: insert)
hoelzl@57275
   915
  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
   916
    using insert by auto
hoelzl@57275
   917
  finally show ?case
haftmann@57514
   918
    by (auto simp add: ac_simps mult_right_mono mult_left_mono)
hoelzl@57275
   919
qed simp_all
hoelzl@57275
   920
lp15@60026
   921
lemma norm_power_diff:
hoelzl@57275
   922
  fixes z w :: "'a::{real_normed_algebra_1, comm_monoid_mult}"
hoelzl@57275
   923
  assumes "norm z \<le> 1" "norm w \<le> 1"
hoelzl@57275
   924
  shows "norm (z^m - w^m) \<le> m * norm (z - w)"
hoelzl@57275
   925
proof -
hoelzl@57275
   926
  have "norm (z^m - w^m) = norm ((\<Prod> i < m. z) - (\<Prod> i < m. w))"
hoelzl@57275
   927
    by (simp add: setprod_constant)
hoelzl@57275
   928
  also have "\<dots> \<le> (\<Sum>i<m. norm (z - w))"
hoelzl@57275
   929
    by (intro norm_setprod_diff) (auto simp add: assms)
hoelzl@57275
   930
  also have "\<dots> = m * norm (z - w)"
hoelzl@57275
   931
    by (simp add: real_of_nat_def)
hoelzl@57275
   932
  finally show ?thesis .
lp15@55719
   933
qed
lp15@55719
   934
hoelzl@51531
   935
subsection {* Metric spaces *}
hoelzl@51531
   936
hoelzl@51531
   937
class metric_space = open_dist +
hoelzl@51531
   938
  assumes dist_eq_0_iff [simp]: "dist x y = 0 \<longleftrightarrow> x = y"
hoelzl@51531
   939
  assumes dist_triangle2: "dist x y \<le> dist x z + dist y z"
hoelzl@51531
   940
begin
hoelzl@51531
   941
hoelzl@51531
   942
lemma dist_self [simp]: "dist x x = 0"
hoelzl@51531
   943
by simp
hoelzl@51531
   944
hoelzl@51531
   945
lemma zero_le_dist [simp]: "0 \<le> dist x y"
hoelzl@51531
   946
using dist_triangle2 [of x x y] by simp
hoelzl@51531
   947
hoelzl@51531
   948
lemma zero_less_dist_iff: "0 < dist x y \<longleftrightarrow> x \<noteq> y"
hoelzl@51531
   949
by (simp add: less_le)
hoelzl@51531
   950
hoelzl@51531
   951
lemma dist_not_less_zero [simp]: "\<not> dist x y < 0"
hoelzl@51531
   952
by (simp add: not_less)
hoelzl@51531
   953
hoelzl@51531
   954
lemma dist_le_zero_iff [simp]: "dist x y \<le> 0 \<longleftrightarrow> x = y"
hoelzl@51531
   955
by (simp add: le_less)
hoelzl@51531
   956
hoelzl@51531
   957
lemma dist_commute: "dist x y = dist y x"
hoelzl@51531
   958
proof (rule order_antisym)
hoelzl@51531
   959
  show "dist x y \<le> dist y x"
hoelzl@51531
   960
    using dist_triangle2 [of x y x] by simp
hoelzl@51531
   961
  show "dist y x \<le> dist x y"
hoelzl@51531
   962
    using dist_triangle2 [of y x y] by simp
hoelzl@51531
   963
qed
hoelzl@51531
   964
hoelzl@51531
   965
lemma dist_triangle: "dist x z \<le> dist x y + dist y z"
hoelzl@51531
   966
using dist_triangle2 [of x z y] by (simp add: dist_commute)
hoelzl@51531
   967
hoelzl@51531
   968
lemma dist_triangle3: "dist x y \<le> dist a x + dist a y"
hoelzl@51531
   969
using dist_triangle2 [of x y a] by (simp add: dist_commute)
hoelzl@51531
   970
hoelzl@51531
   971
lemma dist_triangle_alt:
hoelzl@51531
   972
  shows "dist y z <= dist x y + dist x z"
hoelzl@51531
   973
by (rule dist_triangle3)
hoelzl@51531
   974
hoelzl@51531
   975
lemma dist_pos_lt:
hoelzl@51531
   976
  shows "x \<noteq> y ==> 0 < dist x y"
hoelzl@51531
   977
by (simp add: zero_less_dist_iff)
hoelzl@51531
   978
hoelzl@51531
   979
lemma dist_nz:
hoelzl@51531
   980
  shows "x \<noteq> y \<longleftrightarrow> 0 < dist x y"
hoelzl@51531
   981
by (simp add: zero_less_dist_iff)
hoelzl@51531
   982
hoelzl@51531
   983
lemma dist_triangle_le:
hoelzl@51531
   984
  shows "dist x z + dist y z <= e \<Longrightarrow> dist x y <= e"
hoelzl@51531
   985
by (rule order_trans [OF dist_triangle2])
hoelzl@51531
   986
hoelzl@51531
   987
lemma dist_triangle_lt:
hoelzl@51531
   988
  shows "dist x z + dist y z < e ==> dist x y < e"
hoelzl@51531
   989
by (rule le_less_trans [OF dist_triangle2])
hoelzl@51531
   990
hoelzl@51531
   991
lemma dist_triangle_half_l:
hoelzl@51531
   992
  shows "dist x1 y < e / 2 \<Longrightarrow> dist x2 y < e / 2 \<Longrightarrow> dist x1 x2 < e"
hoelzl@51531
   993
by (rule dist_triangle_lt [where z=y], simp)
hoelzl@51531
   994
hoelzl@51531
   995
lemma dist_triangle_half_r:
hoelzl@51531
   996
  shows "dist y x1 < e / 2 \<Longrightarrow> dist y x2 < e / 2 \<Longrightarrow> dist x1 x2 < e"
hoelzl@51531
   997
by (rule dist_triangle_half_l, simp_all add: dist_commute)
hoelzl@51531
   998
hoelzl@51531
   999
subclass topological_space
hoelzl@51531
  1000
proof
hoelzl@51531
  1001
  have "\<exists>e::real. 0 < e"
hoelzl@51531
  1002
    by (fast intro: zero_less_one)
hoelzl@51531
  1003
  then show "open UNIV"
hoelzl@51531
  1004
    unfolding open_dist by simp
hoelzl@51531
  1005
next
hoelzl@51531
  1006
  fix S T assume "open S" "open T"
hoelzl@51531
  1007
  then show "open (S \<inter> T)"
hoelzl@51531
  1008
    unfolding open_dist
hoelzl@51531
  1009
    apply clarify
hoelzl@51531
  1010
    apply (drule (1) bspec)+
hoelzl@51531
  1011
    apply (clarify, rename_tac r s)
hoelzl@51531
  1012
    apply (rule_tac x="min r s" in exI, simp)
hoelzl@51531
  1013
    done
hoelzl@51531
  1014
next
hoelzl@51531
  1015
  fix K assume "\<forall>S\<in>K. open S" thus "open (\<Union>K)"
hoelzl@51531
  1016
    unfolding open_dist by fast
hoelzl@51531
  1017
qed
hoelzl@51531
  1018
hoelzl@51531
  1019
lemma open_ball: "open {y. dist x y < d}"
hoelzl@51531
  1020
proof (unfold open_dist, intro ballI)
hoelzl@51531
  1021
  fix y assume *: "y \<in> {y. dist x y < d}"
hoelzl@51531
  1022
  then show "\<exists>e>0. \<forall>z. dist z y < e \<longrightarrow> z \<in> {y. dist x y < d}"
hoelzl@51531
  1023
    by (auto intro!: exI[of _ "d - dist x y"] simp: field_simps dist_triangle_lt)
hoelzl@51531
  1024
qed
hoelzl@51531
  1025
hoelzl@51531
  1026
subclass first_countable_topology
hoelzl@51531
  1027
proof
lp15@60026
  1028
  fix x
hoelzl@51531
  1029
  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
  1030
  proof (safe intro!: exI[of _ "\<lambda>n. {y. dist x y < inverse (Suc n)}"])
hoelzl@51531
  1031
    fix S assume "open S" "x \<in> S"
wenzelm@53374
  1032
    then obtain e where e: "0 < e" and "{y. dist x y < e} \<subseteq> S"
hoelzl@51531
  1033
      by (auto simp: open_dist subset_eq dist_commute)
hoelzl@51531
  1034
    moreover
wenzelm@53374
  1035
    from e obtain i where "inverse (Suc i) < e"
hoelzl@51531
  1036
      by (auto dest!: reals_Archimedean)
hoelzl@51531
  1037
    then have "{y. dist x y < inverse (Suc i)} \<subseteq> {y. dist x y < e}"
hoelzl@51531
  1038
      by auto
hoelzl@51531
  1039
    ultimately show "\<exists>i. {y. dist x y < inverse (Suc i)} \<subseteq> S"
hoelzl@51531
  1040
      by blast
hoelzl@51531
  1041
  qed (auto intro: open_ball)
hoelzl@51531
  1042
qed
hoelzl@51531
  1043
hoelzl@51531
  1044
end
hoelzl@51531
  1045
hoelzl@51531
  1046
instance metric_space \<subseteq> t2_space
hoelzl@51531
  1047
proof
hoelzl@51531
  1048
  fix x y :: "'a::metric_space"
hoelzl@51531
  1049
  assume xy: "x \<noteq> y"
hoelzl@51531
  1050
  let ?U = "{y'. dist x y' < dist x y / 2}"
hoelzl@51531
  1051
  let ?V = "{x'. dist y x' < dist x y / 2}"
hoelzl@51531
  1052
  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
  1053
               \<Longrightarrow> \<not>(d x y * 2 < d x z \<and> d z y * 2 < d x z)" by arith
hoelzl@51531
  1054
  have "open ?U \<and> open ?V \<and> x \<in> ?U \<and> y \<in> ?V \<and> ?U \<inter> ?V = {}"
hoelzl@51531
  1055
    using dist_pos_lt[OF xy] th0[of dist, OF dist_triangle dist_commute]
hoelzl@51531
  1056
    using open_ball[of _ "dist x y / 2"] by auto
hoelzl@51531
  1057
  then show "\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
hoelzl@51531
  1058
    by blast
hoelzl@51531
  1059
qed
hoelzl@51531
  1060
huffman@31289
  1061
text {* Every normed vector space is a metric space. *}
huffman@31285
  1062
huffman@31289
  1063
instance real_normed_vector < metric_space
huffman@31289
  1064
proof
huffman@31289
  1065
  fix x y :: 'a show "dist x y = 0 \<longleftrightarrow> x = y"
huffman@31289
  1066
    unfolding dist_norm by simp
huffman@31289
  1067
next
huffman@31289
  1068
  fix x y z :: 'a show "dist x y \<le> dist x z + dist y z"
huffman@31289
  1069
    unfolding dist_norm
huffman@31289
  1070
    using norm_triangle_ineq4 [of "x - z" "y - z"] by simp
huffman@31289
  1071
qed
huffman@31285
  1072
huffman@31564
  1073
subsection {* Class instances for real numbers *}
huffman@31564
  1074
huffman@31564
  1075
instantiation real :: real_normed_field
huffman@31564
  1076
begin
huffman@31564
  1077
hoelzl@51531
  1078
definition dist_real_def:
hoelzl@51531
  1079
  "dist x y = \<bar>x - y\<bar>"
hoelzl@51531
  1080
haftmann@52381
  1081
definition open_real_def [code del]:
hoelzl@51531
  1082
  "open (S :: real set) \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
hoelzl@51531
  1083
huffman@31564
  1084
definition real_norm_def [simp]:
huffman@31564
  1085
  "norm r = \<bar>r\<bar>"
huffman@31564
  1086
huffman@31564
  1087
instance
huffman@31564
  1088
apply (intro_classes, unfold real_norm_def real_scaleR_def)
huffman@31564
  1089
apply (rule dist_real_def)
hoelzl@51531
  1090
apply (rule open_real_def)
huffman@36795
  1091
apply (simp add: sgn_real_def)
huffman@31564
  1092
apply (rule abs_eq_0)
huffman@31564
  1093
apply (rule abs_triangle_ineq)
huffman@31564
  1094
apply (rule abs_mult)
huffman@31564
  1095
apply (rule abs_mult)
huffman@31564
  1096
done
huffman@31564
  1097
huffman@31564
  1098
end
huffman@31564
  1099
haftmann@54890
  1100
declare [[code abort: "open :: real set \<Rightarrow> bool"]]
haftmann@52381
  1101
hoelzl@51531
  1102
instance real :: linorder_topology
hoelzl@51531
  1103
proof
hoelzl@51531
  1104
  show "(open :: real set \<Rightarrow> bool) = generate_topology (range lessThan \<union> range greaterThan)"
hoelzl@51531
  1105
  proof (rule ext, safe)
hoelzl@51531
  1106
    fix S :: "real set" assume "open S"
wenzelm@53381
  1107
    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
  1108
      unfolding open_real_def bchoice_iff ..
hoelzl@51531
  1109
    then have *: "S = (\<Union>x\<in>S. {x - f x <..} \<inter> {..< x + f x})"
hoelzl@51531
  1110
      by (fastforce simp: dist_real_def)
hoelzl@51531
  1111
    show "generate_topology (range lessThan \<union> range greaterThan) S"
hoelzl@51531
  1112
      apply (subst *)
hoelzl@51531
  1113
      apply (intro generate_topology_Union generate_topology.Int)
hoelzl@51531
  1114
      apply (auto intro: generate_topology.Basis)
hoelzl@51531
  1115
      done
hoelzl@51531
  1116
  next
hoelzl@51531
  1117
    fix S :: "real set" assume "generate_topology (range lessThan \<union> range greaterThan) S"
hoelzl@51531
  1118
    moreover have "\<And>a::real. open {..<a}"
hoelzl@51531
  1119
      unfolding open_real_def dist_real_def
hoelzl@51531
  1120
    proof clarify
hoelzl@51531
  1121
      fix x a :: real assume "x < a"
hoelzl@51531
  1122
      hence "0 < a - x \<and> (\<forall>y. \<bar>y - x\<bar> < a - x \<longrightarrow> y \<in> {..<a})" by auto
hoelzl@51531
  1123
      thus "\<exists>e>0. \<forall>y. \<bar>y - x\<bar> < e \<longrightarrow> y \<in> {..<a}" ..
hoelzl@51531
  1124
    qed
hoelzl@51531
  1125
    moreover have "\<And>a::real. open {a <..}"
hoelzl@51531
  1126
      unfolding open_real_def dist_real_def
hoelzl@51531
  1127
    proof clarify
hoelzl@51531
  1128
      fix x a :: real assume "a < x"
hoelzl@51531
  1129
      hence "0 < x - a \<and> (\<forall>y. \<bar>y - x\<bar> < x - a \<longrightarrow> y \<in> {a<..})" by auto
hoelzl@51531
  1130
      thus "\<exists>e>0. \<forall>y. \<bar>y - x\<bar> < e \<longrightarrow> y \<in> {a<..}" ..
hoelzl@51531
  1131
    qed
hoelzl@51531
  1132
    ultimately show "open S"
hoelzl@51531
  1133
      by induct auto
hoelzl@51531
  1134
  qed
hoelzl@51531
  1135
qed
hoelzl@51531
  1136
hoelzl@51775
  1137
instance real :: linear_continuum_topology ..
hoelzl@51518
  1138
hoelzl@51531
  1139
lemmas open_real_greaterThan = open_greaterThan[where 'a=real]
hoelzl@51531
  1140
lemmas open_real_lessThan = open_lessThan[where 'a=real]
hoelzl@51531
  1141
lemmas open_real_greaterThanLessThan = open_greaterThanLessThan[where 'a=real]
hoelzl@51531
  1142
lemmas closed_real_atMost = closed_atMost[where 'a=real]
hoelzl@51531
  1143
lemmas closed_real_atLeast = closed_atLeast[where 'a=real]
hoelzl@51531
  1144
lemmas closed_real_atLeastAtMost = closed_atLeastAtMost[where 'a=real]
hoelzl@51531
  1145
huffman@31446
  1146
subsection {* Extra type constraints *}
huffman@31446
  1147
huffman@31492
  1148
text {* Only allow @{term "open"} in class @{text topological_space}. *}
huffman@31492
  1149
huffman@31492
  1150
setup {* Sign.add_const_constraint
huffman@31492
  1151
  (@{const_name "open"}, SOME @{typ "'a::topological_space set \<Rightarrow> bool"}) *}
huffman@31492
  1152
huffman@31446
  1153
text {* Only allow @{term dist} in class @{text metric_space}. *}
huffman@31446
  1154
huffman@31446
  1155
setup {* Sign.add_const_constraint
huffman@31446
  1156
  (@{const_name dist}, SOME @{typ "'a::metric_space \<Rightarrow> 'a \<Rightarrow> real"}) *}
huffman@31446
  1157
huffman@31446
  1158
text {* Only allow @{term norm} in class @{text real_normed_vector}. *}
huffman@31446
  1159
huffman@31446
  1160
setup {* Sign.add_const_constraint
huffman@31446
  1161
  (@{const_name norm}, SOME @{typ "'a::real_normed_vector \<Rightarrow> real"}) *}
huffman@31446
  1162
huffman@22972
  1163
subsection {* Sign function *}
huffman@22972
  1164
nipkow@24506
  1165
lemma norm_sgn:
nipkow@24506
  1166
  "norm (sgn(x::'a::real_normed_vector)) = (if x = 0 then 0 else 1)"
huffman@31586
  1167
by (simp add: sgn_div_norm)
huffman@22972
  1168
nipkow@24506
  1169
lemma sgn_zero [simp]: "sgn(0::'a::real_normed_vector) = 0"
nipkow@24506
  1170
by (simp add: sgn_div_norm)
huffman@22972
  1171
nipkow@24506
  1172
lemma sgn_zero_iff: "(sgn(x::'a::real_normed_vector) = 0) = (x = 0)"
nipkow@24506
  1173
by (simp add: sgn_div_norm)
huffman@22972
  1174
nipkow@24506
  1175
lemma sgn_minus: "sgn (- x) = - sgn(x::'a::real_normed_vector)"
nipkow@24506
  1176
by (simp add: sgn_div_norm)
huffman@22972
  1177
nipkow@24506
  1178
lemma sgn_scaleR:
nipkow@24506
  1179
  "sgn (scaleR r x) = scaleR (sgn r) (sgn(x::'a::real_normed_vector))"
haftmann@57514
  1180
by (simp add: sgn_div_norm ac_simps)
huffman@22973
  1181
huffman@22972
  1182
lemma sgn_one [simp]: "sgn (1::'a::real_normed_algebra_1) = 1"
nipkow@24506
  1183
by (simp add: sgn_div_norm)
huffman@22972
  1184
huffman@22972
  1185
lemma sgn_of_real:
huffman@22972
  1186
  "sgn (of_real r::'a::real_normed_algebra_1) = of_real (sgn r)"
huffman@22972
  1187
unfolding of_real_def by (simp only: sgn_scaleR sgn_one)
huffman@22972
  1188
huffman@22973
  1189
lemma sgn_mult:
huffman@22973
  1190
  fixes x y :: "'a::real_normed_div_algebra"
huffman@22973
  1191
  shows "sgn (x * y) = sgn x * sgn y"
haftmann@57512
  1192
by (simp add: sgn_div_norm norm_mult mult.commute)
huffman@22973
  1193
huffman@22972
  1194
lemma real_sgn_eq: "sgn (x::real) = x / \<bar>x\<bar>"
nipkow@24506
  1195
by (simp add: sgn_div_norm divide_inverse)
huffman@22972
  1196
huffman@22972
  1197
lemma real_sgn_pos: "0 < (x::real) \<Longrightarrow> sgn x = 1"
hoelzl@56479
  1198
unfolding real_sgn_eq by simp
huffman@22972
  1199
huffman@22972
  1200
lemma real_sgn_neg: "(x::real) < 0 \<Longrightarrow> sgn x = -1"
hoelzl@56479
  1201
unfolding real_sgn_eq by simp
huffman@22972
  1202
hoelzl@56889
  1203
lemma zero_le_sgn_iff [simp]: "0 \<le> sgn x \<longleftrightarrow> 0 \<le> (x::real)"
hoelzl@56889
  1204
  by (cases "0::real" x rule: linorder_cases) simp_all
lp15@60026
  1205
hoelzl@56889
  1206
lemma zero_less_sgn_iff [simp]: "0 < sgn x \<longleftrightarrow> 0 < (x::real)"
hoelzl@56889
  1207
  by (cases "0::real" x rule: linorder_cases) simp_all
hoelzl@56889
  1208
hoelzl@56889
  1209
lemma sgn_le_0_iff [simp]: "sgn x \<le> 0 \<longleftrightarrow> (x::real) \<le> 0"
hoelzl@56889
  1210
  by (cases "0::real" x rule: linorder_cases) simp_all
lp15@60026
  1211
hoelzl@56889
  1212
lemma sgn_less_0_iff [simp]: "sgn x < 0 \<longleftrightarrow> (x::real) < 0"
hoelzl@56889
  1213
  by (cases "0::real" x rule: linorder_cases) simp_all
hoelzl@56889
  1214
hoelzl@51474
  1215
lemma norm_conv_dist: "norm x = dist x 0"
hoelzl@51474
  1216
  unfolding dist_norm by simp
huffman@22972
  1217
huffman@22442
  1218
subsection {* Bounded Linear and Bilinear Operators *}
huffman@22442
  1219
huffman@53600
  1220
locale linear = additive f for f :: "'a::real_vector \<Rightarrow> 'b::real_vector" +
huffman@22442
  1221
  assumes scaleR: "f (scaleR r x) = scaleR r (f x)"
huffman@53600
  1222
huffman@53600
  1223
lemma linearI:
huffman@53600
  1224
  assumes "\<And>x y. f (x + y) = f x + f y"
huffman@53600
  1225
  assumes "\<And>c x. f (c *\<^sub>R x) = c *\<^sub>R f x"
huffman@53600
  1226
  shows "linear f"
huffman@53600
  1227
  by default (rule assms)+
huffman@53600
  1228
huffman@53600
  1229
locale bounded_linear = linear f for f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector" +
huffman@22442
  1230
  assumes bounded: "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K"
huffman@27443
  1231
begin
huffman@22442
  1232
huffman@27443
  1233
lemma pos_bounded:
huffman@22442
  1234
  "\<exists>K>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
  1235
proof -
huffman@22442
  1236
  obtain K where K: "\<And>x. norm (f x) \<le> norm x * K"
huffman@22442
  1237
    using bounded by fast
huffman@22442
  1238
  show ?thesis
huffman@22442
  1239
  proof (intro exI impI conjI allI)
huffman@22442
  1240
    show "0 < max 1 K"
haftmann@54863
  1241
      by (rule order_less_le_trans [OF zero_less_one max.cobounded1])
huffman@22442
  1242
  next
huffman@22442
  1243
    fix x
huffman@22442
  1244
    have "norm (f x) \<le> norm x * K" using K .
huffman@22442
  1245
    also have "\<dots> \<le> norm x * max 1 K"
haftmann@54863
  1246
      by (rule mult_left_mono [OF max.cobounded2 norm_ge_zero])
huffman@22442
  1247
    finally show "norm (f x) \<le> norm x * max 1 K" .
huffman@22442
  1248
  qed
huffman@22442
  1249
qed
huffman@22442
  1250
huffman@27443
  1251
lemma nonneg_bounded:
huffman@22442
  1252
  "\<exists>K\<ge>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
  1253
proof -
huffman@22442
  1254
  from pos_bounded
huffman@22442
  1255
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
  1256
qed
huffman@22442
  1257
hoelzl@56369
  1258
lemma linear: "linear f" ..
hoelzl@56369
  1259
huffman@27443
  1260
end
huffman@27443
  1261
huffman@44127
  1262
lemma bounded_linear_intro:
huffman@44127
  1263
  assumes "\<And>x y. f (x + y) = f x + f y"
huffman@44127
  1264
  assumes "\<And>r x. f (scaleR r x) = scaleR r (f x)"
huffman@44127
  1265
  assumes "\<And>x. norm (f x) \<le> norm x * K"
huffman@44127
  1266
  shows "bounded_linear f"
huffman@44127
  1267
  by default (fast intro: assms)+
huffman@44127
  1268
huffman@22442
  1269
locale bounded_bilinear =
huffman@22442
  1270
  fixes prod :: "['a::real_normed_vector, 'b::real_normed_vector]
huffman@22442
  1271
                 \<Rightarrow> 'c::real_normed_vector"
huffman@22442
  1272
    (infixl "**" 70)
huffman@22442
  1273
  assumes add_left: "prod (a + a') b = prod a b + prod a' b"
huffman@22442
  1274
  assumes add_right: "prod a (b + b') = prod a b + prod a b'"
huffman@22442
  1275
  assumes scaleR_left: "prod (scaleR r a) b = scaleR r (prod a b)"
huffman@22442
  1276
  assumes scaleR_right: "prod a (scaleR r b) = scaleR r (prod a b)"
huffman@22442
  1277
  assumes bounded: "\<exists>K. \<forall>a b. norm (prod a b) \<le> norm a * norm b * K"
huffman@27443
  1278
begin
huffman@22442
  1279
huffman@27443
  1280
lemma pos_bounded:
huffman@22442
  1281
  "\<exists>K>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
  1282
apply (cut_tac bounded, erule exE)
huffman@22442
  1283
apply (rule_tac x="max 1 K" in exI, safe)
haftmann@54863
  1284
apply (rule order_less_le_trans [OF zero_less_one max.cobounded1])
huffman@22442
  1285
apply (drule spec, drule spec, erule order_trans)
haftmann@54863
  1286
apply (rule mult_left_mono [OF max.cobounded2])
huffman@22442
  1287
apply (intro mult_nonneg_nonneg norm_ge_zero)
huffman@22442
  1288
done
huffman@22442
  1289
huffman@27443
  1290
lemma nonneg_bounded:
huffman@22442
  1291
  "\<exists>K\<ge>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
  1292
proof -
huffman@22442
  1293
  from pos_bounded
huffman@22442
  1294
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
  1295
qed
huffman@22442
  1296
huffman@27443
  1297
lemma additive_right: "additive (\<lambda>b. prod a b)"
huffman@22442
  1298
by (rule additive.intro, rule add_right)
huffman@22442
  1299
huffman@27443
  1300
lemma additive_left: "additive (\<lambda>a. prod a b)"
huffman@22442
  1301
by (rule additive.intro, rule add_left)
huffman@22442
  1302
huffman@27443
  1303
lemma zero_left: "prod 0 b = 0"
huffman@22442
  1304
by (rule additive.zero [OF additive_left])
huffman@22442
  1305
huffman@27443
  1306
lemma zero_right: "prod a 0 = 0"
huffman@22442
  1307
by (rule additive.zero [OF additive_right])
huffman@22442
  1308
huffman@27443
  1309
lemma minus_left: "prod (- a) b = - prod a b"
huffman@22442
  1310
by (rule additive.minus [OF additive_left])
huffman@22442
  1311
huffman@27443
  1312
lemma minus_right: "prod a (- b) = - prod a b"
huffman@22442
  1313
by (rule additive.minus [OF additive_right])
huffman@22442
  1314
huffman@27443
  1315
lemma diff_left:
huffman@22442
  1316
  "prod (a - a') b = prod a b - prod a' b"
huffman@22442
  1317
by (rule additive.diff [OF additive_left])
huffman@22442
  1318
huffman@27443
  1319
lemma diff_right:
huffman@22442
  1320
  "prod a (b - b') = prod a b - prod a b'"
huffman@22442
  1321
by (rule additive.diff [OF additive_right])
huffman@22442
  1322
huffman@27443
  1323
lemma bounded_linear_left:
huffman@22442
  1324
  "bounded_linear (\<lambda>a. a ** b)"
huffman@44127
  1325
apply (cut_tac bounded, safe)
huffman@44127
  1326
apply (rule_tac K="norm b * K" in bounded_linear_intro)
huffman@22442
  1327
apply (rule add_left)
huffman@22442
  1328
apply (rule scaleR_left)
haftmann@57514
  1329
apply (simp add: ac_simps)
huffman@22442
  1330
done
huffman@22442
  1331
huffman@27443
  1332
lemma bounded_linear_right:
huffman@22442
  1333
  "bounded_linear (\<lambda>b. a ** b)"
huffman@44127
  1334
apply (cut_tac bounded, safe)
huffman@44127
  1335
apply (rule_tac K="norm a * K" in bounded_linear_intro)
huffman@22442
  1336
apply (rule add_right)
huffman@22442
  1337
apply (rule scaleR_right)
haftmann@57514
  1338
apply (simp add: ac_simps)
huffman@22442
  1339
done
huffman@22442
  1340
huffman@27443
  1341
lemma prod_diff_prod:
huffman@22442
  1342
  "(x ** y - a ** b) = (x - a) ** (y - b) + (x - a) ** b + a ** (y - b)"
huffman@22442
  1343
by (simp add: diff_left diff_right)
huffman@22442
  1344
huffman@27443
  1345
end
huffman@27443
  1346
hoelzl@51642
  1347
lemma bounded_linear_ident[simp]: "bounded_linear (\<lambda>x. x)"
hoelzl@51642
  1348
  by default (auto intro!: exI[of _ 1])
hoelzl@51642
  1349
hoelzl@51642
  1350
lemma bounded_linear_zero[simp]: "bounded_linear (\<lambda>x. 0)"
hoelzl@51642
  1351
  by default (auto intro!: exI[of _ 1])
hoelzl@51642
  1352
hoelzl@51642
  1353
lemma bounded_linear_add:
hoelzl@51642
  1354
  assumes "bounded_linear f"
hoelzl@51642
  1355
  assumes "bounded_linear g"
hoelzl@51642
  1356
  shows "bounded_linear (\<lambda>x. f x + g x)"
hoelzl@51642
  1357
proof -
hoelzl@51642
  1358
  interpret f: bounded_linear f by fact
hoelzl@51642
  1359
  interpret g: bounded_linear g by fact
hoelzl@51642
  1360
  show ?thesis
hoelzl@51642
  1361
  proof
hoelzl@51642
  1362
    from f.bounded obtain Kf where Kf: "\<And>x. norm (f x) \<le> norm x * Kf" by blast
hoelzl@51642
  1363
    from g.bounded obtain Kg where Kg: "\<And>x. norm (g x) \<le> norm x * Kg" by blast
hoelzl@51642
  1364
    show "\<exists>K. \<forall>x. norm (f x + g x) \<le> norm x * K"
hoelzl@51642
  1365
      using add_mono[OF Kf Kg]
hoelzl@51642
  1366
      by (intro exI[of _ "Kf + Kg"]) (auto simp: field_simps intro: norm_triangle_ineq order_trans)
hoelzl@51642
  1367
  qed (simp_all add: f.add g.add f.scaleR g.scaleR scaleR_right_distrib)
hoelzl@51642
  1368
qed
hoelzl@51642
  1369
hoelzl@51642
  1370
lemma bounded_linear_minus:
hoelzl@51642
  1371
  assumes "bounded_linear f"
hoelzl@51642
  1372
  shows "bounded_linear (\<lambda>x. - f x)"
hoelzl@51642
  1373
proof -
hoelzl@51642
  1374
  interpret f: bounded_linear f by fact
hoelzl@51642
  1375
  show ?thesis apply (unfold_locales)
hoelzl@51642
  1376
    apply (simp add: f.add)
hoelzl@51642
  1377
    apply (simp add: f.scaleR)
hoelzl@51642
  1378
    apply (simp add: f.bounded)
hoelzl@51642
  1379
    done
hoelzl@51642
  1380
qed
hoelzl@51642
  1381
hoelzl@51642
  1382
lemma bounded_linear_compose:
hoelzl@51642
  1383
  assumes "bounded_linear f"
hoelzl@51642
  1384
  assumes "bounded_linear g"
hoelzl@51642
  1385
  shows "bounded_linear (\<lambda>x. f (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 proof (unfold_locales)
hoelzl@51642
  1390
    fix x y show "f (g (x + y)) = f (g x) + f (g y)"
hoelzl@51642
  1391
      by (simp only: f.add g.add)
hoelzl@51642
  1392
  next
hoelzl@51642
  1393
    fix r x show "f (g (scaleR r x)) = scaleR r (f (g x))"
hoelzl@51642
  1394
      by (simp only: f.scaleR g.scaleR)
hoelzl@51642
  1395
  next
hoelzl@51642
  1396
    from f.pos_bounded
hoelzl@51642
  1397
    obtain Kf where f: "\<And>x. norm (f x) \<le> norm x * Kf" and Kf: "0 < Kf" by fast
hoelzl@51642
  1398
    from g.pos_bounded
hoelzl@51642
  1399
    obtain Kg where g: "\<And>x. norm (g x) \<le> norm x * Kg" by fast
hoelzl@51642
  1400
    show "\<exists>K. \<forall>x. norm (f (g x)) \<le> norm x * K"
hoelzl@51642
  1401
    proof (intro exI allI)
hoelzl@51642
  1402
      fix x
hoelzl@51642
  1403
      have "norm (f (g x)) \<le> norm (g x) * Kf"
hoelzl@51642
  1404
        using f .
hoelzl@51642
  1405
      also have "\<dots> \<le> (norm x * Kg) * Kf"
hoelzl@51642
  1406
        using g Kf [THEN order_less_imp_le] by (rule mult_right_mono)
hoelzl@51642
  1407
      also have "(norm x * Kg) * Kf = norm x * (Kg * Kf)"
haftmann@57512
  1408
        by (rule mult.assoc)
hoelzl@51642
  1409
      finally show "norm (f (g x)) \<le> norm x * (Kg * Kf)" .
hoelzl@51642
  1410
    qed
hoelzl@51642
  1411
  qed
hoelzl@51642
  1412
qed
hoelzl@51642
  1413
huffman@44282
  1414
lemma bounded_bilinear_mult:
huffman@44282
  1415
  "bounded_bilinear (op * :: 'a \<Rightarrow> 'a \<Rightarrow> 'a::real_normed_algebra)"
huffman@22442
  1416
apply (rule bounded_bilinear.intro)
webertj@49962
  1417
apply (rule distrib_right)
webertj@49962
  1418
apply (rule distrib_left)
huffman@22442
  1419
apply (rule mult_scaleR_left)
huffman@22442
  1420
apply (rule mult_scaleR_right)
huffman@22442
  1421
apply (rule_tac x="1" in exI)
huffman@22442
  1422
apply (simp add: norm_mult_ineq)
huffman@22442
  1423
done
huffman@22442
  1424
huffman@44282
  1425
lemma bounded_linear_mult_left:
huffman@44282
  1426
  "bounded_linear (\<lambda>x::'a::real_normed_algebra. x * y)"
huffman@44282
  1427
  using bounded_bilinear_mult
huffman@44282
  1428
  by (rule bounded_bilinear.bounded_linear_left)
huffman@22442
  1429
huffman@44282
  1430
lemma bounded_linear_mult_right:
huffman@44282
  1431
  "bounded_linear (\<lambda>y::'a::real_normed_algebra. x * y)"
huffman@44282
  1432
  using bounded_bilinear_mult
huffman@44282
  1433
  by (rule bounded_bilinear.bounded_linear_right)
huffman@23127
  1434
hoelzl@51642
  1435
lemmas bounded_linear_mult_const =
hoelzl@51642
  1436
  bounded_linear_mult_left [THEN bounded_linear_compose]
hoelzl@51642
  1437
hoelzl@51642
  1438
lemmas bounded_linear_const_mult =
hoelzl@51642
  1439
  bounded_linear_mult_right [THEN bounded_linear_compose]
hoelzl@51642
  1440
huffman@44282
  1441
lemma bounded_linear_divide:
huffman@44282
  1442
  "bounded_linear (\<lambda>x::'a::real_normed_field. x / y)"
huffman@44282
  1443
  unfolding divide_inverse by (rule bounded_linear_mult_left)
huffman@23120
  1444
huffman@44282
  1445
lemma bounded_bilinear_scaleR: "bounded_bilinear scaleR"
huffman@22442
  1446
apply (rule bounded_bilinear.intro)
huffman@22442
  1447
apply (rule scaleR_left_distrib)
huffman@22442
  1448
apply (rule scaleR_right_distrib)
huffman@22973
  1449
apply simp
huffman@22442
  1450
apply (rule scaleR_left_commute)
huffman@31586
  1451
apply (rule_tac x="1" in exI, simp)
huffman@22442
  1452
done
huffman@22442
  1453
huffman@44282
  1454
lemma bounded_linear_scaleR_left: "bounded_linear (\<lambda>r. scaleR r x)"
huffman@44282
  1455
  using bounded_bilinear_scaleR
huffman@44282
  1456
  by (rule bounded_bilinear.bounded_linear_left)
huffman@23127
  1457
huffman@44282
  1458
lemma bounded_linear_scaleR_right: "bounded_linear (\<lambda>x. scaleR r x)"
huffman@44282
  1459
  using bounded_bilinear_scaleR
huffman@44282
  1460
  by (rule bounded_bilinear.bounded_linear_right)
huffman@23127
  1461
huffman@44282
  1462
lemma bounded_linear_of_real: "bounded_linear (\<lambda>r. of_real r)"
huffman@44282
  1463
  unfolding of_real_def by (rule bounded_linear_scaleR_left)
huffman@22625
  1464
hoelzl@51642
  1465
lemma real_bounded_linear:
hoelzl@51642
  1466
  fixes f :: "real \<Rightarrow> real"
hoelzl@51642
  1467
  shows "bounded_linear f \<longleftrightarrow> (\<exists>c::real. f = (\<lambda>x. x * c))"
hoelzl@51642
  1468
proof -
hoelzl@51642
  1469
  { fix x assume "bounded_linear f"
hoelzl@51642
  1470
    then interpret bounded_linear f .
hoelzl@51642
  1471
    from scaleR[of x 1] have "f x = x * f 1"
hoelzl@51642
  1472
      by simp }
hoelzl@51642
  1473
  then show ?thesis
hoelzl@51642
  1474
    by (auto intro: exI[of _ "f 1"] bounded_linear_mult_left)
hoelzl@51642
  1475
qed
hoelzl@51642
  1476
huffman@44571
  1477
instance real_normed_algebra_1 \<subseteq> perfect_space
huffman@44571
  1478
proof
huffman@44571
  1479
  fix x::'a
huffman@44571
  1480
  show "\<not> open {x}"
huffman@44571
  1481
    unfolding open_dist dist_norm
huffman@44571
  1482
    by (clarsimp, rule_tac x="x + of_real (e/2)" in exI, simp)
huffman@44571
  1483
qed
huffman@44571
  1484
hoelzl@51531
  1485
subsection {* Filters and Limits on Metric Space *}
hoelzl@51531
  1486
hoelzl@57448
  1487
lemma (in metric_space) nhds_metric: "nhds x = (INF e:{0 <..}. principal {y. dist y x < e})"
hoelzl@57448
  1488
  unfolding nhds_def
hoelzl@57448
  1489
proof (safe intro!: INF_eq)
hoelzl@57448
  1490
  fix S assume "open S" "x \<in> S"
hoelzl@57448
  1491
  then obtain e where "{y. dist y x < e} \<subseteq> S" "0 < e"
hoelzl@57448
  1492
    by (auto simp: open_dist subset_eq)
hoelzl@57448
  1493
  then show "\<exists>e\<in>{0<..}. principal {y. dist y x < e} \<le> principal S"
hoelzl@57448
  1494
    by auto
hoelzl@57448
  1495
qed (auto intro!: exI[of _ "{y. dist x y < e}" for e] open_ball simp: dist_commute)
hoelzl@57448
  1496
hoelzl@57448
  1497
lemma (in metric_space) tendsto_iff:
hoelzl@57448
  1498
  "(f ---> l) F \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) F)"
hoelzl@57448
  1499
  unfolding nhds_metric filterlim_INF filterlim_principal by auto
hoelzl@57448
  1500
hoelzl@57448
  1501
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
  1502
  by (auto simp: tendsto_iff)
hoelzl@57448
  1503
hoelzl@57448
  1504
lemma (in metric_space) tendstoD: "(f ---> l) F \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
hoelzl@57448
  1505
  by (auto simp: tendsto_iff)
hoelzl@57448
  1506
hoelzl@57448
  1507
lemma (in metric_space) eventually_nhds_metric:
hoelzl@57448
  1508
  "eventually P (nhds a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. dist x a < d \<longrightarrow> P x)"
hoelzl@57448
  1509
  unfolding nhds_metric
hoelzl@57448
  1510
  by (subst eventually_INF_base)
hoelzl@57448
  1511
     (auto simp: eventually_principal Bex_def subset_eq intro: exI[of _ "min a b" for a b])
hoelzl@51531
  1512
hoelzl@51531
  1513
lemma eventually_at:
hoelzl@51641
  1514
  fixes a :: "'a :: metric_space"
hoelzl@51641
  1515
  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
  1516
  unfolding eventually_at_filter eventually_nhds_metric by (auto simp: dist_nz)
hoelzl@51531
  1517
hoelzl@51641
  1518
lemma eventually_at_le:
hoelzl@51641
  1519
  fixes a :: "'a::metric_space"
hoelzl@51641
  1520
  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
  1521
  unfolding eventually_at_filter eventually_nhds_metric
hoelzl@51641
  1522
  apply auto
hoelzl@51641
  1523
  apply (rule_tac x="d / 2" in exI)
hoelzl@51641
  1524
  apply auto
hoelzl@51641
  1525
  done
hoelzl@51531
  1526
hoelzl@51531
  1527
lemma metric_tendsto_imp_tendsto:
hoelzl@51531
  1528
  fixes a :: "'a :: metric_space" and b :: "'b :: metric_space"
hoelzl@51531
  1529
  assumes f: "(f ---> a) F"
hoelzl@51531
  1530
  assumes le: "eventually (\<lambda>x. dist (g x) b \<le> dist (f x) a) F"
hoelzl@51531
  1531
  shows "(g ---> b) F"
hoelzl@51531
  1532
proof (rule tendstoI)
hoelzl@51531
  1533
  fix e :: real assume "0 < e"
hoelzl@51531
  1534
  with f have "eventually (\<lambda>x. dist (f x) a < e) F" by (rule tendstoD)
hoelzl@51531
  1535
  with le show "eventually (\<lambda>x. dist (g x) b < e) F"
hoelzl@51531
  1536
    using le_less_trans by (rule eventually_elim2)
hoelzl@51531
  1537
qed
hoelzl@51531
  1538
hoelzl@51531
  1539
lemma filterlim_real_sequentially: "LIM x sequentially. real x :> at_top"
hoelzl@51531
  1540
  unfolding filterlim_at_top
hoelzl@51531
  1541
  apply (intro allI)
nipkow@59587
  1542
  apply (rule_tac c="nat(ceiling (Z + 1))" in eventually_sequentiallyI)
nipkow@59587
  1543
  by linarith
hoelzl@51531
  1544
hoelzl@51531
  1545
subsubsection {* Limits of Sequences *}
hoelzl@51531
  1546
lp15@60017
  1547
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
  1548
  unfolding tendsto_iff eventually_sequentially ..
hoelzl@51531
  1549
lp15@60026
  1550
lemmas LIMSEQ_def = lim_sequentially  (*legacy binding*)
lp15@60026
  1551
hoelzl@51531
  1552
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
  1553
  unfolding lim_sequentially by (metis Suc_leD zero_less_Suc)
hoelzl@51531
  1554
hoelzl@51531
  1555
lemma metric_LIMSEQ_I:
hoelzl@51531
  1556
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. dist (X n) L < r) \<Longrightarrow> X ----> (L::'a::metric_space)"
lp15@60017
  1557
by (simp add: lim_sequentially)
hoelzl@51531
  1558
hoelzl@51531
  1559
lemma metric_LIMSEQ_D:
hoelzl@51531
  1560
  "\<lbrakk>X ----> (L::'a::metric_space); 0 < r\<rbrakk> \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. dist (X n) L < r"
lp15@60017
  1561
by (simp add: lim_sequentially)
hoelzl@51531
  1562
hoelzl@51531
  1563
hoelzl@51531
  1564
subsubsection {* Limits of Functions *}
hoelzl@51531
  1565
hoelzl@51531
  1566
lemma LIM_def: "f -- (a::'a::metric_space) --> (L::'b::metric_space) =
hoelzl@51531
  1567
     (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & dist x a < s
hoelzl@51531
  1568
        --> dist (f x) L < r)"
hoelzl@51641
  1569
  unfolding tendsto_iff eventually_at by simp
hoelzl@51531
  1570
hoelzl@51531
  1571
lemma metric_LIM_I:
hoelzl@51531
  1572
  "(\<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
  1573
    \<Longrightarrow> f -- (a::'a::metric_space) --> (L::'b::metric_space)"
hoelzl@51531
  1574
by (simp add: LIM_def)
hoelzl@51531
  1575
hoelzl@51531
  1576
lemma metric_LIM_D:
hoelzl@51531
  1577
  "\<lbrakk>f -- (a::'a::metric_space) --> (L::'b::metric_space); 0 < r\<rbrakk>
hoelzl@51531
  1578
    \<Longrightarrow> \<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x) L < r"
hoelzl@51531
  1579
by (simp add: LIM_def)
hoelzl@51531
  1580
hoelzl@51531
  1581
lemma metric_LIM_imp_LIM:
hoelzl@51531
  1582
  assumes f: "f -- a --> (l::'a::metric_space)"
hoelzl@51531
  1583
  assumes le: "\<And>x. x \<noteq> a \<Longrightarrow> dist (g x) m \<le> dist (f x) l"
hoelzl@51531
  1584
  shows "g -- a --> (m::'b::metric_space)"
hoelzl@51531
  1585
  by (rule metric_tendsto_imp_tendsto [OF f]) (auto simp add: eventually_at_topological le)
hoelzl@51531
  1586
hoelzl@51531
  1587
lemma metric_LIM_equal2:
hoelzl@51531
  1588
  assumes 1: "0 < R"
hoelzl@51531
  1589
  assumes 2: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < R\<rbrakk> \<Longrightarrow> f x = g x"
hoelzl@51531
  1590
  shows "g -- a --> l \<Longrightarrow> f -- (a::'a::metric_space) --> l"
hoelzl@51531
  1591
apply (rule topological_tendstoI)
hoelzl@51531
  1592
apply (drule (2) topological_tendstoD)
hoelzl@51531
  1593
apply (simp add: eventually_at, safe)
hoelzl@51531
  1594
apply (rule_tac x="min d R" in exI, safe)
hoelzl@51531
  1595
apply (simp add: 1)
hoelzl@51531
  1596
apply (simp add: 2)
hoelzl@51531
  1597
done
hoelzl@51531
  1598
hoelzl@51531
  1599
lemma metric_LIM_compose2:
hoelzl@51531
  1600
  assumes f: "f -- (a::'a::metric_space) --> b"
hoelzl@51531
  1601
  assumes g: "g -- b --> c"
hoelzl@51531
  1602
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> b"
hoelzl@51531
  1603
  shows "(\<lambda>x. g (f x)) -- a --> c"
hoelzl@51641
  1604
  using inj
hoelzl@51641
  1605
  by (intro tendsto_compose_eventually[OF g f]) (auto simp: eventually_at)
hoelzl@51531
  1606
hoelzl@51531
  1607
lemma metric_isCont_LIM_compose2:
hoelzl@51531
  1608
  fixes f :: "'a :: metric_space \<Rightarrow> _"
hoelzl@51531
  1609
  assumes f [unfolded isCont_def]: "isCont f a"
hoelzl@51531
  1610
  assumes g: "g -- f a --> l"
hoelzl@51531
  1611
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> f a"
hoelzl@51531
  1612
  shows "(\<lambda>x. g (f x)) -- a --> l"
hoelzl@51531
  1613
by (rule metric_LIM_compose2 [OF f g inj])
hoelzl@51531
  1614
hoelzl@51531
  1615
subsection {* Complete metric spaces *}
hoelzl@51531
  1616
hoelzl@51531
  1617
subsection {* Cauchy sequences *}
hoelzl@51531
  1618
hoelzl@51531
  1619
definition (in metric_space) Cauchy :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool" where
hoelzl@51531
  1620
  "Cauchy X = (\<forall>e>0. \<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. dist (X m) (X n) < e)"
hoelzl@51531
  1621
hoelzl@51531
  1622
subsection {* Cauchy Sequences *}
hoelzl@51531
  1623
hoelzl@51531
  1624
lemma metric_CauchyI:
hoelzl@51531
  1625
  "(\<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
  1626
  by (simp add: Cauchy_def)
hoelzl@51531
  1627
hoelzl@51531
  1628
lemma metric_CauchyD:
hoelzl@51531
  1629
  "Cauchy X \<Longrightarrow> 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < e"
hoelzl@51531
  1630
  by (simp add: Cauchy_def)
hoelzl@51531
  1631
hoelzl@51531
  1632
lemma metric_Cauchy_iff2:
hoelzl@51531
  1633
  "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
  1634
apply (simp add: Cauchy_def, auto)
hoelzl@51531
  1635
apply (drule reals_Archimedean, safe)
hoelzl@51531
  1636
apply (drule_tac x = n in spec, auto)
hoelzl@51531
  1637
apply (rule_tac x = M in exI, auto)
hoelzl@51531
  1638
apply (drule_tac x = m in spec, simp)
hoelzl@51531
  1639
apply (drule_tac x = na in spec, auto)
hoelzl@51531
  1640
done
hoelzl@51531
  1641
hoelzl@51531
  1642
lemma Cauchy_iff2:
hoelzl@51531
  1643
  "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
  1644
  unfolding metric_Cauchy_iff2 dist_real_def ..
hoelzl@51531
  1645
hoelzl@51531
  1646
lemma Cauchy_subseq_Cauchy:
hoelzl@51531
  1647
  "\<lbrakk> Cauchy X; subseq f \<rbrakk> \<Longrightarrow> Cauchy (X o f)"
hoelzl@51531
  1648
apply (auto simp add: Cauchy_def)
hoelzl@51531
  1649
apply (drule_tac x=e in spec, clarify)
hoelzl@51531
  1650
apply (rule_tac x=M in exI, clarify)
hoelzl@51531
  1651
apply (blast intro: le_trans [OF _ seq_suble] dest!: spec)
hoelzl@51531
  1652
done
hoelzl@51531
  1653
hoelzl@51531
  1654
theorem LIMSEQ_imp_Cauchy:
hoelzl@51531
  1655
  assumes X: "X ----> a" shows "Cauchy X"
hoelzl@51531
  1656
proof (rule metric_CauchyI)
hoelzl@51531
  1657
  fix e::real assume "0 < e"
hoelzl@51531
  1658
  hence "0 < e/2" by simp
hoelzl@51531
  1659
  with X have "\<exists>N. \<forall>n\<ge>N. dist (X n) a < e/2" by (rule metric_LIMSEQ_D)
hoelzl@51531
  1660
  then obtain N where N: "\<forall>n\<ge>N. dist (X n) a < e/2" ..
hoelzl@51531
  1661
  show "\<exists>N. \<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m) (X n) < e"
hoelzl@51531
  1662
  proof (intro exI allI impI)
hoelzl@51531
  1663
    fix m assume "N \<le> m"
hoelzl@51531
  1664
    hence m: "dist (X m) a < e/2" using N by fast
hoelzl@51531
  1665
    fix n assume "N \<le> n"
hoelzl@51531
  1666
    hence n: "dist (X n) a < e/2" using N by fast
hoelzl@51531
  1667
    have "dist (X m) (X n) \<le> dist (X m) a + dist (X n) a"
hoelzl@51531
  1668
      by (rule dist_triangle2)
hoelzl@51531
  1669
    also from m n have "\<dots> < e" by simp
hoelzl@51531
  1670
    finally show "dist (X m) (X n) < e" .
hoelzl@51531
  1671
  qed
hoelzl@51531
  1672
qed
hoelzl@51531
  1673
hoelzl@51531
  1674
lemma convergent_Cauchy: "convergent X \<Longrightarrow> Cauchy X"
hoelzl@51531
  1675
unfolding convergent_def
hoelzl@51531
  1676
by (erule exE, erule LIMSEQ_imp_Cauchy)
hoelzl@51531
  1677
hoelzl@51531
  1678
subsubsection {* Cauchy Sequences are Convergent *}
hoelzl@51531
  1679
hoelzl@51531
  1680
class complete_space = metric_space +
hoelzl@51531
  1681
  assumes Cauchy_convergent: "Cauchy X \<Longrightarrow> convergent X"
hoelzl@51531
  1682
hoelzl@51531
  1683
lemma Cauchy_convergent_iff:
hoelzl@51531
  1684
  fixes X :: "nat \<Rightarrow> 'a::complete_space"
hoelzl@51531
  1685
  shows "Cauchy X = convergent X"
hoelzl@51531
  1686
by (fast intro: Cauchy_convergent convergent_Cauchy)
hoelzl@51531
  1687
hoelzl@51531
  1688
subsection {* The set of real numbers is a complete metric space *}
hoelzl@51531
  1689
hoelzl@51531
  1690
text {*
hoelzl@51531
  1691
Proof that Cauchy sequences converge based on the one from
wenzelm@54703
  1692
@{url "http://pirate.shu.edu/~wachsmut/ira/numseq/proofs/cauconv.html"}
hoelzl@51531
  1693
*}
hoelzl@51531
  1694
hoelzl@51531
  1695
text {*
hoelzl@51531
  1696
  If sequence @{term "X"} is Cauchy, then its limit is the lub of
hoelzl@51531
  1697
  @{term "{r::real. \<exists>N. \<forall>n\<ge>N. r < X n}"}
hoelzl@51531
  1698
*}
hoelzl@51531
  1699
hoelzl@51531
  1700
lemma increasing_LIMSEQ:
hoelzl@51531
  1701
  fixes f :: "nat \<Rightarrow> real"
hoelzl@51531
  1702
  assumes inc: "\<And>n. f n \<le> f (Suc n)"
hoelzl@51531
  1703
      and bdd: "\<And>n. f n \<le> l"
hoelzl@51531
  1704
      and en: "\<And>e. 0 < e \<Longrightarrow> \<exists>n. l \<le> f n + e"
hoelzl@51531
  1705
  shows "f ----> l"
hoelzl@51531
  1706
proof (rule increasing_tendsto)
hoelzl@51531
  1707
  fix x assume "x < l"
hoelzl@51531
  1708
  with dense[of 0 "l - x"] obtain e where "0 < e" "e < l - x"
hoelzl@51531
  1709
    by auto
hoelzl@51531
  1710
  from en[OF `0 < e`] obtain n where "l - e \<le> f n"
hoelzl@51531
  1711
    by (auto simp: field_simps)
hoelzl@51531
  1712
  with `e < l - x` `0 < e` have "x < f n" by simp
hoelzl@51531
  1713
  with incseq_SucI[of f, OF inc] show "eventually (\<lambda>n. x < f n) sequentially"
hoelzl@51531
  1714
    by (auto simp: eventually_sequentially incseq_def intro: less_le_trans)
hoelzl@51531
  1715
qed (insert bdd, auto)
hoelzl@51531
  1716
hoelzl@51531
  1717
lemma real_Cauchy_convergent:
hoelzl@51531
  1718
  fixes X :: "nat \<Rightarrow> real"
hoelzl@51531
  1719
  assumes X: "Cauchy X"
hoelzl@51531
  1720
  shows "convergent X"
hoelzl@51531
  1721
proof -
hoelzl@51531
  1722
  def S \<equiv> "{x::real. \<exists>N. \<forall>n\<ge>N. x < X n}"
hoelzl@51531
  1723
  then have mem_S: "\<And>N x. \<forall>n\<ge>N. x < X n \<Longrightarrow> x \<in> S" by auto
hoelzl@51531
  1724
hoelzl@51531
  1725
  { fix N x assume N: "\<forall>n\<ge>N. X n < x"
hoelzl@51531
  1726
  fix y::real assume "y \<in> S"
hoelzl@51531
  1727
  hence "\<exists>M. \<forall>n\<ge>M. y < X n"
hoelzl@51531
  1728
    by (simp add: S_def)
hoelzl@51531
  1729
  then obtain M where "\<forall>n\<ge>M. y < X n" ..
hoelzl@51531
  1730
  hence "y < X (max M N)" by simp
hoelzl@51531
  1731
  also have "\<dots> < x" using N by simp
hoelzl@54263
  1732
  finally have "y \<le> x"
hoelzl@54263
  1733
    by (rule order_less_imp_le) }
lp15@60026
  1734
  note bound_isUb = this
hoelzl@51531
  1735
hoelzl@51531
  1736
  obtain N where "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m) (X n) < 1"
hoelzl@51531
  1737
    using X[THEN metric_CauchyD, OF zero_less_one] by auto
hoelzl@51531
  1738
  hence N: "\<forall>n\<ge>N. dist (X n) (X N) < 1" by simp
hoelzl@54263
  1739
  have [simp]: "S \<noteq> {}"
hoelzl@54263
  1740
  proof (intro exI ex_in_conv[THEN iffD1])
hoelzl@51531
  1741
    from N have "\<forall>n\<ge>N. X N - 1 < X n"
hoelzl@51531
  1742
      by (simp add: abs_diff_less_iff dist_real_def)
hoelzl@51531
  1743
    thus "X N - 1 \<in> S" by (rule mem_S)
hoelzl@51531
  1744
  qed
hoelzl@54263
  1745
  have [simp]: "bdd_above S"
hoelzl@51531
  1746
  proof
hoelzl@51531
  1747
    from N have "\<forall>n\<ge>N. X n < X N + 1"
hoelzl@51531
  1748
      by (simp add: abs_diff_less_iff dist_real_def)
hoelzl@54263
  1749
    thus "\<And>s. s \<in> S \<Longrightarrow>  s \<le> X N + 1"
hoelzl@51531
  1750
      by (rule bound_isUb)
hoelzl@51531
  1751
  qed
hoelzl@54263
  1752
  have "X ----> Sup S"
hoelzl@51531
  1753
  proof (rule metric_LIMSEQ_I)
hoelzl@51531
  1754
  fix r::real assume "0 < r"
hoelzl@51531
  1755
  hence r: "0 < r/2" by simp
hoelzl@51531
  1756
  obtain N where "\<forall>n\<ge>N. \<forall>m\<ge>N. dist (X n) (X m) < r/2"
hoelzl@51531
  1757
    using metric_CauchyD [OF X r] by auto
hoelzl@51531
  1758
  hence "\<forall>n\<ge>N. dist (X n) (X N) < r/2" by simp
hoelzl@51531
  1759
  hence N: "\<forall>n\<ge>N. X N - r/2 < X n \<and> X n < X N + r/2"
hoelzl@51531
  1760
    by (simp only: dist_real_def abs_diff_less_iff)
hoelzl@51531
  1761
hoelzl@51531
  1762
  from N have "\<forall>n\<ge>N. X N - r/2 < X n" by fast
hoelzl@51531
  1763
  hence "X N - r/2 \<in> S" by (rule mem_S)
hoelzl@54263
  1764
  hence 1: "X N - r/2 \<le> Sup S" by (simp add: cSup_upper)
hoelzl@51531
  1765
hoelzl@51531
  1766
  from N have "\<forall>n\<ge>N. X n < X N + r/2" by fast
hoelzl@54263
  1767
  from bound_isUb[OF this]
hoelzl@54263
  1768
  have 2: "Sup S \<le> X N + r/2"
hoelzl@54263
  1769
    by (intro cSup_least) simp_all
hoelzl@51531
  1770
hoelzl@54263
  1771
  show "\<exists>N. \<forall>n\<ge>N. dist (X n) (Sup S) < r"
hoelzl@51531
  1772
  proof (intro exI allI impI)
hoelzl@51531
  1773
    fix n assume n: "N \<le> n"
hoelzl@51531
  1774
    from N n have "X n < X N + r/2" and "X N - r/2 < X n" by simp+
hoelzl@54263
  1775
    thus "dist (X n) (Sup S) < r" using 1 2
hoelzl@51531
  1776
      by (simp add: abs_diff_less_iff dist_real_def)
hoelzl@51531
  1777
  qed
hoelzl@51531
  1778
  qed
hoelzl@51531
  1779
  then show ?thesis unfolding convergent_def by auto
hoelzl@51531
  1780
qed
hoelzl@51531
  1781
hoelzl@51531
  1782
instance real :: complete_space
hoelzl@51531
  1783
  by intro_classes (rule real_Cauchy_convergent)
hoelzl@51531
  1784
hoelzl@51531
  1785
class banach = real_normed_vector + complete_space
hoelzl@51531
  1786
hoelzl@51531
  1787
instance real :: banach by default
hoelzl@51531
  1788
hoelzl@51531
  1789
lemma tendsto_at_topI_sequentially:
hoelzl@57275
  1790
  fixes f :: "real \<Rightarrow> 'b::first_countable_topology"
hoelzl@57275
  1791
  assumes *: "\<And>X. filterlim X at_top sequentially \<Longrightarrow> (\<lambda>n. f (X n)) ----> y"
hoelzl@57275
  1792
  shows "(f ---> y) at_top"
hoelzl@57448
  1793
proof -
hoelzl@57448
  1794
  from nhds_countable[of y] guess A . note A = this
hoelzl@57275
  1795
hoelzl@57448
  1796
  have "\<forall>m. \<exists>k. \<forall>x\<ge>k. f x \<in> A m"
hoelzl@57448
  1797
  proof (rule ccontr)
hoelzl@57448
  1798
    assume "\<not> (\<forall>m. \<exists>k. \<forall>x\<ge>k. f x \<in> A m)"
hoelzl@57448
  1799
    then obtain m where "\<And>k. \<exists>x\<ge>k. f x \<notin> A m"
hoelzl@57448
  1800
      by auto
hoelzl@57448
  1801
    then have "\<exists>X. \<forall>n. (f (X n) \<notin> A m) \<and> max n (X n) + 1 \<le> X (Suc n)"
hoelzl@57448
  1802
      by (intro dependent_nat_choice) (auto simp del: max.bounded_iff)
hoelzl@57448
  1803
    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
  1804
      by auto
hoelzl@57448
  1805
    { fix n have "1 \<le> n \<longrightarrow> real n \<le> X n"
hoelzl@57448
  1806
        using X[of "n - 1"] by auto }
hoelzl@57448
  1807
    then have "filterlim X at_top sequentially"
hoelzl@57448
  1808
      by (force intro!: filterlim_at_top_mono[OF filterlim_real_sequentially]
hoelzl@57448
  1809
                simp: eventually_sequentially)
hoelzl@57448
  1810
    from topological_tendstoD[OF *[OF this] A(2, 3), of m] X(1) show False
hoelzl@57448
  1811
      by auto
hoelzl@57275
  1812
  qed
hoelzl@57448
  1813
  then obtain k where "\<And>m x. k m \<le> x \<Longrightarrow> f x \<in> A m"
hoelzl@57448
  1814
    by metis
hoelzl@57448
  1815
  then show ?thesis
hoelzl@57448
  1816
    unfolding at_top_def A
hoelzl@57448
  1817
    by (intro filterlim_base[where i=k]) auto
hoelzl@57275
  1818
qed
hoelzl@57275
  1819
hoelzl@57275
  1820
lemma tendsto_at_topI_sequentially_real:
hoelzl@51531
  1821
  fixes f :: "real \<Rightarrow> real"
hoelzl@51531
  1822
  assumes mono: "mono f"
hoelzl@51531
  1823
  assumes limseq: "(\<lambda>n. f (real n)) ----> y"
hoelzl@51531
  1824
  shows "(f ---> y) at_top"
hoelzl@51531
  1825
proof (rule tendstoI)
hoelzl@51531
  1826
  fix e :: real assume "0 < e"
hoelzl@51531
  1827
  with limseq obtain N :: nat where N: "\<And>n. N \<le> n \<Longrightarrow> \<bar>f (real n) - y\<bar> < e"
lp15@60017
  1828
    by (auto simp: lim_sequentially dist_real_def)
hoelzl@51531
  1829
  { fix x :: real
wenzelm@53381
  1830
    obtain n where "x \<le> real_of_nat n"
wenzelm@53381
  1831
      using ex_le_of_nat[of x] ..
hoelzl@51531
  1832
    note monoD[OF mono this]
hoelzl@51531
  1833
    also have "f (real_of_nat n) \<le> y"
hoelzl@51531
  1834
      by (rule LIMSEQ_le_const[OF limseq])
hoelzl@51531
  1835
         (auto intro: exI[of _ n] monoD[OF mono] simp: real_eq_of_nat[symmetric])
hoelzl@51531
  1836
    finally have "f x \<le> y" . }
hoelzl@51531
  1837
  note le = this
hoelzl@51531
  1838
  have "eventually (\<lambda>x. real N \<le> x) at_top"
hoelzl@51531
  1839
    by (rule eventually_ge_at_top)
hoelzl@51531
  1840
  then show "eventually (\<lambda>x. dist (f x) y < e) at_top"
hoelzl@51531
  1841
  proof eventually_elim
hoelzl@51531
  1842
    fix x assume N': "real N \<le> x"
hoelzl@51531
  1843
    with N[of N] le have "y - f (real N) < e" by auto
hoelzl@51531
  1844
    moreover note monoD[OF mono N']
hoelzl@51531
  1845
    ultimately show "dist (f x) y < e"
hoelzl@51531
  1846
      using le[of x] by (auto simp: dist_real_def field_simps)
hoelzl@51531
  1847
  qed
hoelzl@51531
  1848
qed
hoelzl@51531
  1849
huffman@20504
  1850
end
hoelzl@57276
  1851