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