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