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