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