src/HOL/RealVector.thy
author huffman
Tue Aug 09 12:50:22 2011 -0700 (2011-08-09)
changeset 44127 7b57b9295d98
parent 41969 1cf3e4107a2a
child 44282 f0de18b62d63
permissions -rw-r--r--
lemma bounded_linear_intro
haftmann@29197
     1
(*  Title:      HOL/RealVector.thy
haftmann@27552
     2
    Author:     Brian Huffman
huffman@20504
     3
*)
huffman@20504
     4
huffman@20504
     5
header {* Vector Spaces and Algebras over the Reals *}
huffman@20504
     6
huffman@20504
     7
theory RealVector
huffman@36839
     8
imports RComplete
huffman@20504
     9
begin
huffman@20504
    10
huffman@20504
    11
subsection {* Locale for additive functions *}
huffman@20504
    12
huffman@20504
    13
locale additive =
huffman@20504
    14
  fixes f :: "'a::ab_group_add \<Rightarrow> 'b::ab_group_add"
huffman@20504
    15
  assumes add: "f (x + y) = f x + f y"
huffman@27443
    16
begin
huffman@20504
    17
huffman@27443
    18
lemma zero: "f 0 = 0"
huffman@20504
    19
proof -
huffman@20504
    20
  have "f 0 = f (0 + 0)" by simp
huffman@20504
    21
  also have "\<dots> = f 0 + f 0" by (rule add)
huffman@20504
    22
  finally show "f 0 = 0" by simp
huffman@20504
    23
qed
huffman@20504
    24
huffman@27443
    25
lemma minus: "f (- x) = - f x"
huffman@20504
    26
proof -
huffman@20504
    27
  have "f (- x) + f x = f (- x + x)" by (rule add [symmetric])
huffman@20504
    28
  also have "\<dots> = - f x + f x" by (simp add: zero)
huffman@20504
    29
  finally show "f (- x) = - f x" by (rule add_right_imp_eq)
huffman@20504
    30
qed
huffman@20504
    31
huffman@27443
    32
lemma diff: "f (x - y) = f x - f y"
haftmann@37887
    33
by (simp add: add minus diff_minus)
huffman@20504
    34
huffman@27443
    35
lemma setsum: "f (setsum g A) = (\<Sum>x\<in>A. f (g x))"
huffman@22942
    36
apply (cases "finite A")
huffman@22942
    37
apply (induct set: finite)
huffman@22942
    38
apply (simp add: zero)
huffman@22942
    39
apply (simp add: add)
huffman@22942
    40
apply (simp add: zero)
huffman@22942
    41
done
huffman@22942
    42
huffman@27443
    43
end
huffman@20504
    44
huffman@28029
    45
subsection {* Vector spaces *}
huffman@28029
    46
huffman@28029
    47
locale vector_space =
huffman@28029
    48
  fixes scale :: "'a::field \<Rightarrow> 'b::ab_group_add \<Rightarrow> 'b"
huffman@30070
    49
  assumes scale_right_distrib [algebra_simps]:
huffman@30070
    50
    "scale a (x + y) = scale a x + scale a y"
huffman@30070
    51
  and scale_left_distrib [algebra_simps]:
huffman@30070
    52
    "scale (a + b) x = scale a x + scale b x"
huffman@28029
    53
  and scale_scale [simp]: "scale a (scale b x) = scale (a * b) x"
huffman@28029
    54
  and scale_one [simp]: "scale 1 x = x"
huffman@28029
    55
begin
huffman@28029
    56
huffman@28029
    57
lemma scale_left_commute:
huffman@28029
    58
  "scale a (scale b x) = scale b (scale a x)"
huffman@28029
    59
by (simp add: mult_commute)
huffman@28029
    60
huffman@28029
    61
lemma scale_zero_left [simp]: "scale 0 x = 0"
huffman@28029
    62
  and scale_minus_left [simp]: "scale (- a) x = - (scale a x)"
huffman@30070
    63
  and scale_left_diff_distrib [algebra_simps]:
huffman@30070
    64
        "scale (a - b) x = scale a x - scale b x"
huffman@28029
    65
proof -
ballarin@29229
    66
  interpret s: additive "\<lambda>a. scale a x"
haftmann@28823
    67
    proof qed (rule scale_left_distrib)
huffman@28029
    68
  show "scale 0 x = 0" by (rule s.zero)
huffman@28029
    69
  show "scale (- a) x = - (scale a x)" by (rule s.minus)
huffman@28029
    70
  show "scale (a - b) x = scale a x - scale b x" by (rule s.diff)
huffman@28029
    71
qed
huffman@28029
    72
huffman@28029
    73
lemma scale_zero_right [simp]: "scale a 0 = 0"
huffman@28029
    74
  and scale_minus_right [simp]: "scale a (- x) = - (scale a x)"
huffman@30070
    75
  and scale_right_diff_distrib [algebra_simps]:
huffman@30070
    76
        "scale a (x - y) = scale a x - scale a y"
huffman@28029
    77
proof -
ballarin@29229
    78
  interpret s: additive "\<lambda>x. scale a x"
haftmann@28823
    79
    proof qed (rule scale_right_distrib)
huffman@28029
    80
  show "scale a 0 = 0" by (rule s.zero)
huffman@28029
    81
  show "scale a (- x) = - (scale a x)" by (rule s.minus)
huffman@28029
    82
  show "scale a (x - y) = scale a x - scale a y" by (rule s.diff)
huffman@28029
    83
qed
huffman@28029
    84
huffman@28029
    85
lemma scale_eq_0_iff [simp]:
huffman@28029
    86
  "scale a x = 0 \<longleftrightarrow> a = 0 \<or> x = 0"
huffman@28029
    87
proof cases
huffman@28029
    88
  assume "a = 0" thus ?thesis by simp
huffman@28029
    89
next
huffman@28029
    90
  assume anz [simp]: "a \<noteq> 0"
huffman@28029
    91
  { assume "scale a x = 0"
huffman@28029
    92
    hence "scale (inverse a) (scale a x) = 0" by simp
huffman@28029
    93
    hence "x = 0" by simp }
huffman@28029
    94
  thus ?thesis by force
huffman@28029
    95
qed
huffman@28029
    96
huffman@28029
    97
lemma scale_left_imp_eq:
huffman@28029
    98
  "\<lbrakk>a \<noteq> 0; scale a x = scale a y\<rbrakk> \<Longrightarrow> x = y"
huffman@28029
    99
proof -
huffman@28029
   100
  assume nonzero: "a \<noteq> 0"
huffman@28029
   101
  assume "scale a x = scale a y"
huffman@28029
   102
  hence "scale a (x - y) = 0"
huffman@28029
   103
     by (simp add: scale_right_diff_distrib)
huffman@28029
   104
  hence "x - y = 0" by (simp add: nonzero)
huffman@28029
   105
  thus "x = y" by (simp only: right_minus_eq)
huffman@28029
   106
qed
huffman@28029
   107
huffman@28029
   108
lemma scale_right_imp_eq:
huffman@28029
   109
  "\<lbrakk>x \<noteq> 0; scale a x = scale b x\<rbrakk> \<Longrightarrow> a = b"
huffman@28029
   110
proof -
huffman@28029
   111
  assume nonzero: "x \<noteq> 0"
huffman@28029
   112
  assume "scale a x = scale b x"
huffman@28029
   113
  hence "scale (a - b) x = 0"
huffman@28029
   114
     by (simp add: scale_left_diff_distrib)
huffman@28029
   115
  hence "a - b = 0" by (simp add: nonzero)
huffman@28029
   116
  thus "a = b" by (simp only: right_minus_eq)
huffman@28029
   117
qed
huffman@28029
   118
huffman@31586
   119
lemma scale_cancel_left [simp]:
huffman@28029
   120
  "scale a x = scale a y \<longleftrightarrow> x = y \<or> a = 0"
huffman@28029
   121
by (auto intro: scale_left_imp_eq)
huffman@28029
   122
huffman@31586
   123
lemma scale_cancel_right [simp]:
huffman@28029
   124
  "scale a x = scale b x \<longleftrightarrow> a = b \<or> x = 0"
huffman@28029
   125
by (auto intro: scale_right_imp_eq)
huffman@28029
   126
huffman@28029
   127
end
huffman@28029
   128
huffman@20504
   129
subsection {* Real vector spaces *}
huffman@20504
   130
haftmann@29608
   131
class scaleR =
haftmann@25062
   132
  fixes scaleR :: "real \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "*\<^sub>R" 75)
haftmann@24748
   133
begin
huffman@20504
   134
huffman@20763
   135
abbreviation
haftmann@25062
   136
  divideR :: "'a \<Rightarrow> real \<Rightarrow> 'a" (infixl "'/\<^sub>R" 70)
haftmann@24748
   137
where
haftmann@25062
   138
  "x /\<^sub>R r == scaleR (inverse r) x"
haftmann@24748
   139
haftmann@24748
   140
end
haftmann@24748
   141
haftmann@24588
   142
class real_vector = scaleR + ab_group_add +
haftmann@25062
   143
  assumes scaleR_right_distrib: "scaleR a (x + y) = scaleR a x + scaleR a y"
haftmann@25062
   144
  and scaleR_left_distrib: "scaleR (a + b) x = scaleR a x + scaleR b x"
huffman@30070
   145
  and scaleR_scaleR: "scaleR a (scaleR b x) = scaleR (a * b) x"
huffman@30070
   146
  and scaleR_one: "scaleR 1 x = x"
huffman@20504
   147
wenzelm@30729
   148
interpretation real_vector:
ballarin@29229
   149
  vector_space "scaleR :: real \<Rightarrow> 'a \<Rightarrow> 'a::real_vector"
huffman@28009
   150
apply unfold_locales
huffman@28009
   151
apply (rule scaleR_right_distrib)
huffman@28009
   152
apply (rule scaleR_left_distrib)
huffman@28009
   153
apply (rule scaleR_scaleR)
huffman@28009
   154
apply (rule scaleR_one)
huffman@28009
   155
done
huffman@28009
   156
huffman@28009
   157
text {* Recover original theorem names *}
huffman@28009
   158
huffman@28009
   159
lemmas scaleR_left_commute = real_vector.scale_left_commute
huffman@28009
   160
lemmas scaleR_zero_left = real_vector.scale_zero_left
huffman@28009
   161
lemmas scaleR_minus_left = real_vector.scale_minus_left
huffman@28009
   162
lemmas scaleR_left_diff_distrib = real_vector.scale_left_diff_distrib
huffman@28009
   163
lemmas scaleR_zero_right = real_vector.scale_zero_right
huffman@28009
   164
lemmas scaleR_minus_right = real_vector.scale_minus_right
huffman@28009
   165
lemmas scaleR_right_diff_distrib = real_vector.scale_right_diff_distrib
huffman@28009
   166
lemmas scaleR_eq_0_iff = real_vector.scale_eq_0_iff
huffman@28009
   167
lemmas scaleR_left_imp_eq = real_vector.scale_left_imp_eq
huffman@28009
   168
lemmas scaleR_right_imp_eq = real_vector.scale_right_imp_eq
huffman@28009
   169
lemmas scaleR_cancel_left = real_vector.scale_cancel_left
huffman@28009
   170
lemmas scaleR_cancel_right = real_vector.scale_cancel_right
huffman@28009
   171
huffman@31285
   172
lemma scaleR_minus1_left [simp]:
huffman@31285
   173
  fixes x :: "'a::real_vector"
huffman@31285
   174
  shows "scaleR (-1) x = - x"
huffman@31285
   175
  using scaleR_minus_left [of 1 x] by simp
huffman@31285
   176
haftmann@24588
   177
class real_algebra = real_vector + ring +
haftmann@25062
   178
  assumes mult_scaleR_left [simp]: "scaleR a x * y = scaleR a (x * y)"
haftmann@25062
   179
  and mult_scaleR_right [simp]: "x * scaleR a y = scaleR a (x * y)"
huffman@20504
   180
haftmann@24588
   181
class real_algebra_1 = real_algebra + ring_1
huffman@20554
   182
haftmann@24588
   183
class real_div_algebra = real_algebra_1 + division_ring
huffman@20584
   184
haftmann@24588
   185
class real_field = real_div_algebra + field
huffman@20584
   186
huffman@30069
   187
instantiation real :: real_field
huffman@30069
   188
begin
huffman@30069
   189
huffman@30069
   190
definition
huffman@30069
   191
  real_scaleR_def [simp]: "scaleR a x = a * x"
huffman@30069
   192
huffman@30070
   193
instance proof
huffman@30070
   194
qed (simp_all add: algebra_simps)
huffman@20554
   195
huffman@30069
   196
end
huffman@30069
   197
wenzelm@30729
   198
interpretation scaleR_left: additive "(\<lambda>a. scaleR a x::'a::real_vector)"
haftmann@28823
   199
proof qed (rule scaleR_left_distrib)
huffman@20504
   200
wenzelm@30729
   201
interpretation scaleR_right: additive "(\<lambda>x. scaleR a x::'a::real_vector)"
haftmann@28823
   202
proof qed (rule scaleR_right_distrib)
huffman@20504
   203
huffman@20584
   204
lemma nonzero_inverse_scaleR_distrib:
huffman@21809
   205
  fixes x :: "'a::real_div_algebra" shows
huffman@21809
   206
  "\<lbrakk>a \<noteq> 0; x \<noteq> 0\<rbrakk> \<Longrightarrow> inverse (scaleR a x) = scaleR (inverse a) (inverse x)"
huffman@20763
   207
by (rule inverse_unique, simp)
huffman@20584
   208
huffman@20584
   209
lemma inverse_scaleR_distrib:
haftmann@36409
   210
  fixes x :: "'a::{real_div_algebra, division_ring_inverse_zero}"
huffman@21809
   211
  shows "inverse (scaleR a x) = scaleR (inverse a) (inverse x)"
huffman@20584
   212
apply (case_tac "a = 0", simp)
huffman@20584
   213
apply (case_tac "x = 0", simp)
huffman@20584
   214
apply (erule (1) nonzero_inverse_scaleR_distrib)
huffman@20584
   215
done
huffman@20584
   216
huffman@20554
   217
huffman@20554
   218
subsection {* Embedding of the Reals into any @{text real_algebra_1}:
huffman@20554
   219
@{term of_real} *}
huffman@20554
   220
huffman@20554
   221
definition
wenzelm@21404
   222
  of_real :: "real \<Rightarrow> 'a::real_algebra_1" where
huffman@21809
   223
  "of_real r = scaleR r 1"
huffman@20554
   224
huffman@21809
   225
lemma scaleR_conv_of_real: "scaleR r x = of_real r * x"
huffman@20763
   226
by (simp add: of_real_def)
huffman@20763
   227
huffman@20554
   228
lemma of_real_0 [simp]: "of_real 0 = 0"
huffman@20554
   229
by (simp add: of_real_def)
huffman@20554
   230
huffman@20554
   231
lemma of_real_1 [simp]: "of_real 1 = 1"
huffman@20554
   232
by (simp add: of_real_def)
huffman@20554
   233
huffman@20554
   234
lemma of_real_add [simp]: "of_real (x + y) = of_real x + of_real y"
huffman@20554
   235
by (simp add: of_real_def scaleR_left_distrib)
huffman@20554
   236
huffman@20554
   237
lemma of_real_minus [simp]: "of_real (- x) = - of_real x"
huffman@20554
   238
by (simp add: of_real_def)
huffman@20554
   239
huffman@20554
   240
lemma of_real_diff [simp]: "of_real (x - y) = of_real x - of_real y"
huffman@20554
   241
by (simp add: of_real_def scaleR_left_diff_distrib)
huffman@20554
   242
huffman@20554
   243
lemma of_real_mult [simp]: "of_real (x * y) = of_real x * of_real y"
huffman@20763
   244
by (simp add: of_real_def mult_commute)
huffman@20554
   245
huffman@20584
   246
lemma nonzero_of_real_inverse:
huffman@20584
   247
  "x \<noteq> 0 \<Longrightarrow> of_real (inverse x) =
huffman@20584
   248
   inverse (of_real x :: 'a::real_div_algebra)"
huffman@20584
   249
by (simp add: of_real_def nonzero_inverse_scaleR_distrib)
huffman@20584
   250
huffman@20584
   251
lemma of_real_inverse [simp]:
huffman@20584
   252
  "of_real (inverse x) =
haftmann@36409
   253
   inverse (of_real x :: 'a::{real_div_algebra, division_ring_inverse_zero})"
huffman@20584
   254
by (simp add: of_real_def inverse_scaleR_distrib)
huffman@20584
   255
huffman@20584
   256
lemma nonzero_of_real_divide:
huffman@20584
   257
  "y \<noteq> 0 \<Longrightarrow> of_real (x / y) =
huffman@20584
   258
   (of_real x / of_real y :: 'a::real_field)"
huffman@20584
   259
by (simp add: divide_inverse nonzero_of_real_inverse)
huffman@20722
   260
huffman@20722
   261
lemma of_real_divide [simp]:
huffman@20584
   262
  "of_real (x / y) =
haftmann@36409
   263
   (of_real x / of_real y :: 'a::{real_field, field_inverse_zero})"
huffman@20584
   264
by (simp add: divide_inverse)
huffman@20584
   265
huffman@20722
   266
lemma of_real_power [simp]:
haftmann@31017
   267
  "of_real (x ^ n) = (of_real x :: 'a::{real_algebra_1}) ^ n"
huffman@30273
   268
by (induct n) simp_all
huffman@20722
   269
huffman@20554
   270
lemma of_real_eq_iff [simp]: "(of_real x = of_real y) = (x = y)"
huffman@35216
   271
by (simp add: of_real_def)
huffman@20554
   272
haftmann@38621
   273
lemma inj_of_real:
haftmann@38621
   274
  "inj of_real"
haftmann@38621
   275
  by (auto intro: injI)
haftmann@38621
   276
huffman@20584
   277
lemmas of_real_eq_0_iff [simp] = of_real_eq_iff [of _ 0, simplified]
huffman@20554
   278
huffman@20554
   279
lemma of_real_eq_id [simp]: "of_real = (id :: real \<Rightarrow> real)"
huffman@20554
   280
proof
huffman@20554
   281
  fix r
huffman@20554
   282
  show "of_real r = id r"
huffman@22973
   283
    by (simp add: of_real_def)
huffman@20554
   284
qed
huffman@20554
   285
huffman@20554
   286
text{*Collapse nested embeddings*}
huffman@20554
   287
lemma of_real_of_nat_eq [simp]: "of_real (of_nat n) = of_nat n"
wenzelm@20772
   288
by (induct n) auto
huffman@20554
   289
huffman@20554
   290
lemma of_real_of_int_eq [simp]: "of_real (of_int z) = of_int z"
huffman@20554
   291
by (cases z rule: int_diff_cases, simp)
huffman@20554
   292
huffman@20554
   293
lemma of_real_number_of_eq:
huffman@20554
   294
  "of_real (number_of w) = (number_of w :: 'a::{number_ring,real_algebra_1})"
huffman@20554
   295
by (simp add: number_of_eq)
huffman@20554
   296
huffman@22912
   297
text{*Every real algebra has characteristic zero*}
haftmann@38621
   298
huffman@22912
   299
instance real_algebra_1 < ring_char_0
huffman@22912
   300
proof
haftmann@38621
   301
  from inj_of_real inj_of_nat have "inj (of_real \<circ> of_nat)" by (rule inj_comp)
haftmann@38621
   302
  then show "inj (of_nat :: nat \<Rightarrow> 'a)" by (simp add: comp_def)
huffman@22912
   303
qed
huffman@22912
   304
huffman@27553
   305
instance real_field < field_char_0 ..
huffman@27553
   306
huffman@20554
   307
huffman@20554
   308
subsection {* The Set of Real Numbers *}
huffman@20554
   309
haftmann@37767
   310
definition Reals :: "'a::real_algebra_1 set" where
haftmann@37767
   311
  "Reals = range of_real"
huffman@20554
   312
wenzelm@21210
   313
notation (xsymbols)
huffman@20554
   314
  Reals  ("\<real>")
huffman@20554
   315
huffman@21809
   316
lemma Reals_of_real [simp]: "of_real r \<in> Reals"
huffman@20554
   317
by (simp add: Reals_def)
huffman@20554
   318
huffman@21809
   319
lemma Reals_of_int [simp]: "of_int z \<in> Reals"
huffman@21809
   320
by (subst of_real_of_int_eq [symmetric], rule Reals_of_real)
huffman@20718
   321
huffman@21809
   322
lemma Reals_of_nat [simp]: "of_nat n \<in> Reals"
huffman@21809
   323
by (subst of_real_of_nat_eq [symmetric], rule Reals_of_real)
huffman@21809
   324
huffman@21809
   325
lemma Reals_number_of [simp]:
huffman@21809
   326
  "(number_of w::'a::{number_ring,real_algebra_1}) \<in> Reals"
huffman@21809
   327
by (subst of_real_number_of_eq [symmetric], rule Reals_of_real)
huffman@20718
   328
huffman@20554
   329
lemma Reals_0 [simp]: "0 \<in> Reals"
huffman@20554
   330
apply (unfold Reals_def)
huffman@20554
   331
apply (rule range_eqI)
huffman@20554
   332
apply (rule of_real_0 [symmetric])
huffman@20554
   333
done
huffman@20554
   334
huffman@20554
   335
lemma Reals_1 [simp]: "1 \<in> Reals"
huffman@20554
   336
apply (unfold Reals_def)
huffman@20554
   337
apply (rule range_eqI)
huffman@20554
   338
apply (rule of_real_1 [symmetric])
huffman@20554
   339
done
huffman@20554
   340
huffman@20584
   341
lemma Reals_add [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a + b \<in> Reals"
huffman@20554
   342
apply (auto simp add: Reals_def)
huffman@20554
   343
apply (rule range_eqI)
huffman@20554
   344
apply (rule of_real_add [symmetric])
huffman@20554
   345
done
huffman@20554
   346
huffman@20584
   347
lemma Reals_minus [simp]: "a \<in> Reals \<Longrightarrow> - a \<in> Reals"
huffman@20584
   348
apply (auto simp add: Reals_def)
huffman@20584
   349
apply (rule range_eqI)
huffman@20584
   350
apply (rule of_real_minus [symmetric])
huffman@20584
   351
done
huffman@20584
   352
huffman@20584
   353
lemma Reals_diff [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a - b \<in> Reals"
huffman@20584
   354
apply (auto simp add: Reals_def)
huffman@20584
   355
apply (rule range_eqI)
huffman@20584
   356
apply (rule of_real_diff [symmetric])
huffman@20584
   357
done
huffman@20584
   358
huffman@20584
   359
lemma Reals_mult [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a * b \<in> Reals"
huffman@20554
   360
apply (auto simp add: Reals_def)
huffman@20554
   361
apply (rule range_eqI)
huffman@20554
   362
apply (rule of_real_mult [symmetric])
huffman@20554
   363
done
huffman@20554
   364
huffman@20584
   365
lemma nonzero_Reals_inverse:
huffman@20584
   366
  fixes a :: "'a::real_div_algebra"
huffman@20584
   367
  shows "\<lbrakk>a \<in> Reals; a \<noteq> 0\<rbrakk> \<Longrightarrow> inverse a \<in> Reals"
huffman@20584
   368
apply (auto simp add: Reals_def)
huffman@20584
   369
apply (rule range_eqI)
huffman@20584
   370
apply (erule nonzero_of_real_inverse [symmetric])
huffman@20584
   371
done
huffman@20584
   372
huffman@20584
   373
lemma Reals_inverse [simp]:
haftmann@36409
   374
  fixes a :: "'a::{real_div_algebra, division_ring_inverse_zero}"
huffman@20584
   375
  shows "a \<in> Reals \<Longrightarrow> inverse a \<in> Reals"
huffman@20584
   376
apply (auto simp add: Reals_def)
huffman@20584
   377
apply (rule range_eqI)
huffman@20584
   378
apply (rule of_real_inverse [symmetric])
huffman@20584
   379
done
huffman@20584
   380
huffman@20584
   381
lemma nonzero_Reals_divide:
huffman@20584
   382
  fixes a b :: "'a::real_field"
huffman@20584
   383
  shows "\<lbrakk>a \<in> Reals; b \<in> Reals; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584
   384
apply (auto simp add: Reals_def)
huffman@20584
   385
apply (rule range_eqI)
huffman@20584
   386
apply (erule nonzero_of_real_divide [symmetric])
huffman@20584
   387
done
huffman@20584
   388
huffman@20584
   389
lemma Reals_divide [simp]:
haftmann@36409
   390
  fixes a b :: "'a::{real_field, field_inverse_zero}"
huffman@20584
   391
  shows "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584
   392
apply (auto simp add: Reals_def)
huffman@20584
   393
apply (rule range_eqI)
huffman@20584
   394
apply (rule of_real_divide [symmetric])
huffman@20584
   395
done
huffman@20584
   396
huffman@20722
   397
lemma Reals_power [simp]:
haftmann@31017
   398
  fixes a :: "'a::{real_algebra_1}"
huffman@20722
   399
  shows "a \<in> Reals \<Longrightarrow> a ^ n \<in> Reals"
huffman@20722
   400
apply (auto simp add: Reals_def)
huffman@20722
   401
apply (rule range_eqI)
huffman@20722
   402
apply (rule of_real_power [symmetric])
huffman@20722
   403
done
huffman@20722
   404
huffman@20554
   405
lemma Reals_cases [cases set: Reals]:
huffman@20554
   406
  assumes "q \<in> \<real>"
huffman@20554
   407
  obtains (of_real) r where "q = of_real r"
huffman@20554
   408
  unfolding Reals_def
huffman@20554
   409
proof -
huffman@20554
   410
  from `q \<in> \<real>` have "q \<in> range of_real" unfolding Reals_def .
huffman@20554
   411
  then obtain r where "q = of_real r" ..
huffman@20554
   412
  then show thesis ..
huffman@20554
   413
qed
huffman@20554
   414
huffman@20554
   415
lemma Reals_induct [case_names of_real, induct set: Reals]:
huffman@20554
   416
  "q \<in> \<real> \<Longrightarrow> (\<And>r. P (of_real r)) \<Longrightarrow> P q"
huffman@20554
   417
  by (rule Reals_cases) auto
huffman@20554
   418
huffman@20504
   419
huffman@31413
   420
subsection {* Topological spaces *}
huffman@31413
   421
huffman@31492
   422
class "open" =
huffman@31494
   423
  fixes "open" :: "'a set \<Rightarrow> bool"
huffman@31490
   424
huffman@31492
   425
class topological_space = "open" +
huffman@31492
   426
  assumes open_UNIV [simp, intro]: "open UNIV"
huffman@31492
   427
  assumes open_Int [intro]: "open S \<Longrightarrow> open T \<Longrightarrow> open (S \<inter> T)"
huffman@31492
   428
  assumes open_Union [intro]: "\<forall>S\<in>K. open S \<Longrightarrow> open (\<Union> K)"
huffman@31490
   429
begin
huffman@31490
   430
huffman@31490
   431
definition
huffman@31490
   432
  closed :: "'a set \<Rightarrow> bool" where
huffman@31490
   433
  "closed S \<longleftrightarrow> open (- S)"
huffman@31490
   434
huffman@31490
   435
lemma open_empty [intro, simp]: "open {}"
huffman@31490
   436
  using open_Union [of "{}"] by simp
huffman@31490
   437
huffman@31490
   438
lemma open_Un [intro]: "open S \<Longrightarrow> open T \<Longrightarrow> open (S \<union> T)"
huffman@31490
   439
  using open_Union [of "{S, T}"] by simp
huffman@31490
   440
huffman@31490
   441
lemma open_UN [intro]: "\<forall>x\<in>A. open (B x) \<Longrightarrow> open (\<Union>x\<in>A. B x)"
huffman@31490
   442
  unfolding UN_eq by (rule open_Union) auto
huffman@31490
   443
huffman@31490
   444
lemma open_INT [intro]: "finite A \<Longrightarrow> \<forall>x\<in>A. open (B x) \<Longrightarrow> open (\<Inter>x\<in>A. B x)"
huffman@31490
   445
  by (induct set: finite) auto
huffman@31490
   446
huffman@31490
   447
lemma open_Inter [intro]: "finite S \<Longrightarrow> \<forall>T\<in>S. open T \<Longrightarrow> open (\<Inter>S)"
huffman@31490
   448
  unfolding Inter_def by (rule open_INT)
huffman@31490
   449
huffman@31490
   450
lemma closed_empty [intro, simp]:  "closed {}"
huffman@31490
   451
  unfolding closed_def by simp
huffman@31490
   452
huffman@31490
   453
lemma closed_Un [intro]: "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<union> T)"
huffman@31490
   454
  unfolding closed_def by auto
huffman@31490
   455
huffman@31490
   456
lemma closed_Inter [intro]: "\<forall>S\<in>K. closed S \<Longrightarrow> closed (\<Inter> K)"
huffman@31490
   457
  unfolding closed_def Inter_def by auto
huffman@31490
   458
huffman@31490
   459
lemma closed_UNIV [intro, simp]: "closed UNIV"
huffman@31490
   460
  unfolding closed_def by simp
huffman@31490
   461
huffman@31490
   462
lemma closed_Int [intro]: "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<inter> T)"
huffman@31490
   463
  unfolding closed_def by auto
huffman@31490
   464
huffman@31490
   465
lemma closed_INT [intro]: "\<forall>x\<in>A. closed (B x) \<Longrightarrow> closed (\<Inter>x\<in>A. B x)"
huffman@31490
   466
  unfolding closed_def by auto
huffman@31490
   467
huffman@31490
   468
lemma closed_UN [intro]: "finite A \<Longrightarrow> \<forall>x\<in>A. closed (B x) \<Longrightarrow> closed (\<Union>x\<in>A. B x)"
huffman@31490
   469
  by (induct set: finite) auto
huffman@31490
   470
huffman@31490
   471
lemma closed_Union [intro]: "finite S \<Longrightarrow> \<forall>T\<in>S. closed T \<Longrightarrow> closed (\<Union>S)"
huffman@31490
   472
  unfolding Union_def by (rule closed_UN)
huffman@31490
   473
huffman@31490
   474
lemma open_closed: "open S \<longleftrightarrow> closed (- S)"
huffman@31490
   475
  unfolding closed_def by simp
huffman@31490
   476
huffman@31490
   477
lemma closed_open: "closed S \<longleftrightarrow> open (- S)"
huffman@31490
   478
  unfolding closed_def by simp
huffman@31490
   479
huffman@31490
   480
lemma open_Diff [intro]: "open S \<Longrightarrow> closed T \<Longrightarrow> open (S - T)"
huffman@31490
   481
  unfolding closed_open Diff_eq by (rule open_Int)
huffman@31490
   482
huffman@31490
   483
lemma closed_Diff [intro]: "closed S \<Longrightarrow> open T \<Longrightarrow> closed (S - T)"
huffman@31490
   484
  unfolding open_closed Diff_eq by (rule closed_Int)
huffman@31490
   485
huffman@31490
   486
lemma open_Compl [intro]: "closed S \<Longrightarrow> open (- S)"
huffman@31490
   487
  unfolding closed_open .
huffman@31490
   488
huffman@31490
   489
lemma closed_Compl [intro]: "open S \<Longrightarrow> closed (- S)"
huffman@31490
   490
  unfolding open_closed .
huffman@31490
   491
huffman@31490
   492
end
huffman@31413
   493
huffman@31413
   494
huffman@31289
   495
subsection {* Metric spaces *}
huffman@31289
   496
huffman@31289
   497
class dist =
huffman@31289
   498
  fixes dist :: "'a \<Rightarrow> 'a \<Rightarrow> real"
huffman@31289
   499
huffman@31492
   500
class open_dist = "open" + dist +
huffman@31492
   501
  assumes open_dist: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
huffman@31413
   502
huffman@31492
   503
class metric_space = open_dist +
huffman@31289
   504
  assumes dist_eq_0_iff [simp]: "dist x y = 0 \<longleftrightarrow> x = y"
huffman@31289
   505
  assumes dist_triangle2: "dist x y \<le> dist x z + dist y z"
huffman@31289
   506
begin
huffman@31289
   507
huffman@31289
   508
lemma dist_self [simp]: "dist x x = 0"
huffman@31289
   509
by simp
huffman@31289
   510
huffman@31289
   511
lemma zero_le_dist [simp]: "0 \<le> dist x y"
huffman@31289
   512
using dist_triangle2 [of x x y] by simp
huffman@31289
   513
huffman@31289
   514
lemma zero_less_dist_iff: "0 < dist x y \<longleftrightarrow> x \<noteq> y"
huffman@31289
   515
by (simp add: less_le)
huffman@31289
   516
huffman@31289
   517
lemma dist_not_less_zero [simp]: "\<not> dist x y < 0"
huffman@31289
   518
by (simp add: not_less)
huffman@31289
   519
huffman@31289
   520
lemma dist_le_zero_iff [simp]: "dist x y \<le> 0 \<longleftrightarrow> x = y"
huffman@31289
   521
by (simp add: le_less)
huffman@31289
   522
huffman@31289
   523
lemma dist_commute: "dist x y = dist y x"
huffman@31289
   524
proof (rule order_antisym)
huffman@31289
   525
  show "dist x y \<le> dist y x"
huffman@31289
   526
    using dist_triangle2 [of x y x] by simp
huffman@31289
   527
  show "dist y x \<le> dist x y"
huffman@31289
   528
    using dist_triangle2 [of y x y] by simp
huffman@31289
   529
qed
huffman@31289
   530
huffman@31289
   531
lemma dist_triangle: "dist x z \<le> dist x y + dist y z"
huffman@31289
   532
using dist_triangle2 [of x z y] by (simp add: dist_commute)
huffman@31289
   533
huffman@31565
   534
lemma dist_triangle3: "dist x y \<le> dist a x + dist a y"
huffman@31565
   535
using dist_triangle2 [of x y a] by (simp add: dist_commute)
huffman@31565
   536
hoelzl@41969
   537
lemma dist_triangle_alt:
hoelzl@41969
   538
  shows "dist y z <= dist x y + dist x z"
hoelzl@41969
   539
by (rule dist_triangle3)
hoelzl@41969
   540
hoelzl@41969
   541
lemma dist_pos_lt:
hoelzl@41969
   542
  shows "x \<noteq> y ==> 0 < dist x y"
hoelzl@41969
   543
by (simp add: zero_less_dist_iff)
hoelzl@41969
   544
hoelzl@41969
   545
lemma dist_nz:
hoelzl@41969
   546
  shows "x \<noteq> y \<longleftrightarrow> 0 < dist x y"
hoelzl@41969
   547
by (simp add: zero_less_dist_iff)
hoelzl@41969
   548
hoelzl@41969
   549
lemma dist_triangle_le:
hoelzl@41969
   550
  shows "dist x z + dist y z <= e \<Longrightarrow> dist x y <= e"
hoelzl@41969
   551
by (rule order_trans [OF dist_triangle2])
hoelzl@41969
   552
hoelzl@41969
   553
lemma dist_triangle_lt:
hoelzl@41969
   554
  shows "dist x z + dist y z < e ==> dist x y < e"
hoelzl@41969
   555
by (rule le_less_trans [OF dist_triangle2])
hoelzl@41969
   556
hoelzl@41969
   557
lemma dist_triangle_half_l:
hoelzl@41969
   558
  shows "dist x1 y < e / 2 \<Longrightarrow> dist x2 y < e / 2 \<Longrightarrow> dist x1 x2 < e"
hoelzl@41969
   559
by (rule dist_triangle_lt [where z=y], simp)
hoelzl@41969
   560
hoelzl@41969
   561
lemma dist_triangle_half_r:
hoelzl@41969
   562
  shows "dist y x1 < e / 2 \<Longrightarrow> dist y x2 < e / 2 \<Longrightarrow> dist x1 x2 < e"
hoelzl@41969
   563
by (rule dist_triangle_half_l, simp_all add: dist_commute)
hoelzl@41969
   564
huffman@31413
   565
subclass topological_space
huffman@31413
   566
proof
huffman@31413
   567
  have "\<exists>e::real. 0 < e"
huffman@31413
   568
    by (fast intro: zero_less_one)
huffman@31492
   569
  then show "open UNIV"
huffman@31492
   570
    unfolding open_dist by simp
huffman@31413
   571
next
huffman@31492
   572
  fix S T assume "open S" "open T"
huffman@31492
   573
  then show "open (S \<inter> T)"
huffman@31492
   574
    unfolding open_dist
huffman@31413
   575
    apply clarify
huffman@31413
   576
    apply (drule (1) bspec)+
huffman@31413
   577
    apply (clarify, rename_tac r s)
huffman@31413
   578
    apply (rule_tac x="min r s" in exI, simp)
huffman@31413
   579
    done
huffman@31413
   580
next
huffman@31492
   581
  fix K assume "\<forall>S\<in>K. open S" thus "open (\<Union>K)"
huffman@31492
   582
    unfolding open_dist by fast
huffman@31413
   583
qed
huffman@31413
   584
hoelzl@41969
   585
lemma (in metric_space) open_ball: "open {y. dist x y < d}"
hoelzl@41969
   586
proof (unfold open_dist, intro ballI)
hoelzl@41969
   587
  fix y assume *: "y \<in> {y. dist x y < d}"
hoelzl@41969
   588
  then show "\<exists>e>0. \<forall>z. dist z y < e \<longrightarrow> z \<in> {y. dist x y < d}"
hoelzl@41969
   589
    by (auto intro!: exI[of _ "d - dist x y"] simp: field_simps dist_triangle_lt)
hoelzl@41969
   590
qed
hoelzl@41969
   591
huffman@31289
   592
end
huffman@31289
   593
huffman@31289
   594
huffman@20504
   595
subsection {* Real normed vector spaces *}
huffman@20504
   596
haftmann@29608
   597
class norm =
huffman@22636
   598
  fixes norm :: "'a \<Rightarrow> real"
huffman@20504
   599
huffman@24520
   600
class sgn_div_norm = scaleR + norm + sgn +
haftmann@25062
   601
  assumes sgn_div_norm: "sgn x = x /\<^sub>R norm x"
nipkow@24506
   602
huffman@31289
   603
class dist_norm = dist + norm + minus +
huffman@31289
   604
  assumes dist_norm: "dist x y = norm (x - y)"
huffman@31289
   605
huffman@31492
   606
class real_normed_vector = real_vector + sgn_div_norm + dist_norm + open_dist +
haftmann@24588
   607
  assumes norm_ge_zero [simp]: "0 \<le> norm x"
haftmann@25062
   608
  and norm_eq_zero [simp]: "norm x = 0 \<longleftrightarrow> x = 0"
haftmann@25062
   609
  and norm_triangle_ineq: "norm (x + y) \<le> norm x + norm y"
huffman@31586
   610
  and norm_scaleR [simp]: "norm (scaleR a x) = \<bar>a\<bar> * norm x"
huffman@20504
   611
haftmann@24588
   612
class real_normed_algebra = real_algebra + real_normed_vector +
haftmann@25062
   613
  assumes norm_mult_ineq: "norm (x * y) \<le> norm x * norm y"
huffman@20504
   614
haftmann@24588
   615
class real_normed_algebra_1 = real_algebra_1 + real_normed_algebra +
haftmann@25062
   616
  assumes norm_one [simp]: "norm 1 = 1"
huffman@22852
   617
haftmann@24588
   618
class real_normed_div_algebra = real_div_algebra + real_normed_vector +
haftmann@25062
   619
  assumes norm_mult: "norm (x * y) = norm x * norm y"
huffman@20504
   620
haftmann@24588
   621
class real_normed_field = real_field + real_normed_div_algebra
huffman@20584
   622
huffman@22852
   623
instance real_normed_div_algebra < real_normed_algebra_1
huffman@20554
   624
proof
huffman@20554
   625
  fix x y :: 'a
huffman@20554
   626
  show "norm (x * y) \<le> norm x * norm y"
huffman@20554
   627
    by (simp add: norm_mult)
huffman@22852
   628
next
huffman@22852
   629
  have "norm (1 * 1::'a) = norm (1::'a) * norm (1::'a)"
huffman@22852
   630
    by (rule norm_mult)
huffman@22852
   631
  thus "norm (1::'a) = 1" by simp
huffman@20554
   632
qed
huffman@20554
   633
huffman@22852
   634
lemma norm_zero [simp]: "norm (0::'a::real_normed_vector) = 0"
huffman@20504
   635
by simp
huffman@20504
   636
huffman@22852
   637
lemma zero_less_norm_iff [simp]:
huffman@22852
   638
  fixes x :: "'a::real_normed_vector"
huffman@22852
   639
  shows "(0 < norm x) = (x \<noteq> 0)"
huffman@20504
   640
by (simp add: order_less_le)
huffman@20504
   641
huffman@22852
   642
lemma norm_not_less_zero [simp]:
huffman@22852
   643
  fixes x :: "'a::real_normed_vector"
huffman@22852
   644
  shows "\<not> norm x < 0"
huffman@20828
   645
by (simp add: linorder_not_less)
huffman@20828
   646
huffman@22852
   647
lemma norm_le_zero_iff [simp]:
huffman@22852
   648
  fixes x :: "'a::real_normed_vector"
huffman@22852
   649
  shows "(norm x \<le> 0) = (x = 0)"
huffman@20828
   650
by (simp add: order_le_less)
huffman@20828
   651
huffman@20504
   652
lemma norm_minus_cancel [simp]:
huffman@20584
   653
  fixes x :: "'a::real_normed_vector"
huffman@20584
   654
  shows "norm (- x) = norm x"
huffman@20504
   655
proof -
huffman@21809
   656
  have "norm (- x) = norm (scaleR (- 1) x)"
huffman@20504
   657
    by (simp only: scaleR_minus_left scaleR_one)
huffman@20533
   658
  also have "\<dots> = \<bar>- 1\<bar> * norm x"
huffman@20504
   659
    by (rule norm_scaleR)
huffman@20504
   660
  finally show ?thesis by simp
huffman@20504
   661
qed
huffman@20504
   662
huffman@20504
   663
lemma norm_minus_commute:
huffman@20584
   664
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   665
  shows "norm (a - b) = norm (b - a)"
huffman@20504
   666
proof -
huffman@22898
   667
  have "norm (- (b - a)) = norm (b - a)"
huffman@22898
   668
    by (rule norm_minus_cancel)
huffman@22898
   669
  thus ?thesis by simp
huffman@20504
   670
qed
huffman@20504
   671
huffman@20504
   672
lemma norm_triangle_ineq2:
huffman@20584
   673
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   674
  shows "norm a - norm b \<le> norm (a - b)"
huffman@20504
   675
proof -
huffman@20533
   676
  have "norm (a - b + b) \<le> norm (a - b) + norm b"
huffman@20504
   677
    by (rule norm_triangle_ineq)
huffman@22898
   678
  thus ?thesis by simp
huffman@20504
   679
qed
huffman@20504
   680
huffman@20584
   681
lemma norm_triangle_ineq3:
huffman@20584
   682
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   683
  shows "\<bar>norm a - norm b\<bar> \<le> norm (a - b)"
huffman@20584
   684
apply (subst abs_le_iff)
huffman@20584
   685
apply auto
huffman@20584
   686
apply (rule norm_triangle_ineq2)
huffman@20584
   687
apply (subst norm_minus_commute)
huffman@20584
   688
apply (rule norm_triangle_ineq2)
huffman@20584
   689
done
huffman@20584
   690
huffman@20504
   691
lemma norm_triangle_ineq4:
huffman@20584
   692
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   693
  shows "norm (a - b) \<le> norm a + norm b"
huffman@20504
   694
proof -
huffman@22898
   695
  have "norm (a + - b) \<le> norm a + norm (- b)"
huffman@20504
   696
    by (rule norm_triangle_ineq)
huffman@22898
   697
  thus ?thesis
huffman@22898
   698
    by (simp only: diff_minus norm_minus_cancel)
huffman@22898
   699
qed
huffman@22898
   700
huffman@22898
   701
lemma norm_diff_ineq:
huffman@22898
   702
  fixes a b :: "'a::real_normed_vector"
huffman@22898
   703
  shows "norm a - norm b \<le> norm (a + b)"
huffman@22898
   704
proof -
huffman@22898
   705
  have "norm a - norm (- b) \<le> norm (a - - b)"
huffman@22898
   706
    by (rule norm_triangle_ineq2)
huffman@22898
   707
  thus ?thesis by simp
huffman@20504
   708
qed
huffman@20504
   709
huffman@20551
   710
lemma norm_diff_triangle_ineq:
huffman@20551
   711
  fixes a b c d :: "'a::real_normed_vector"
huffman@20551
   712
  shows "norm ((a + b) - (c + d)) \<le> norm (a - c) + norm (b - d)"
huffman@20551
   713
proof -
huffman@20551
   714
  have "norm ((a + b) - (c + d)) = norm ((a - c) + (b - d))"
huffman@20551
   715
    by (simp add: diff_minus add_ac)
huffman@20551
   716
  also have "\<dots> \<le> norm (a - c) + norm (b - d)"
huffman@20551
   717
    by (rule norm_triangle_ineq)
huffman@20551
   718
  finally show ?thesis .
huffman@20551
   719
qed
huffman@20551
   720
huffman@22857
   721
lemma abs_norm_cancel [simp]:
huffman@22857
   722
  fixes a :: "'a::real_normed_vector"
huffman@22857
   723
  shows "\<bar>norm a\<bar> = norm a"
huffman@22857
   724
by (rule abs_of_nonneg [OF norm_ge_zero])
huffman@22857
   725
huffman@22880
   726
lemma norm_add_less:
huffman@22880
   727
  fixes x y :: "'a::real_normed_vector"
huffman@22880
   728
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x + y) < r + s"
huffman@22880
   729
by (rule order_le_less_trans [OF norm_triangle_ineq add_strict_mono])
huffman@22880
   730
huffman@22880
   731
lemma norm_mult_less:
huffman@22880
   732
  fixes x y :: "'a::real_normed_algebra"
huffman@22880
   733
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x * y) < r * s"
huffman@22880
   734
apply (rule order_le_less_trans [OF norm_mult_ineq])
huffman@22880
   735
apply (simp add: mult_strict_mono')
huffman@22880
   736
done
huffman@22880
   737
huffman@22857
   738
lemma norm_of_real [simp]:
huffman@22857
   739
  "norm (of_real r :: 'a::real_normed_algebra_1) = \<bar>r\<bar>"
huffman@31586
   740
unfolding of_real_def by simp
huffman@20560
   741
huffman@22876
   742
lemma norm_number_of [simp]:
huffman@22876
   743
  "norm (number_of w::'a::{number_ring,real_normed_algebra_1})
huffman@22876
   744
    = \<bar>number_of w\<bar>"
huffman@22876
   745
by (subst of_real_number_of_eq [symmetric], rule norm_of_real)
huffman@22876
   746
huffman@22876
   747
lemma norm_of_int [simp]:
huffman@22876
   748
  "norm (of_int z::'a::real_normed_algebra_1) = \<bar>of_int z\<bar>"
huffman@22876
   749
by (subst of_real_of_int_eq [symmetric], rule norm_of_real)
huffman@22876
   750
huffman@22876
   751
lemma norm_of_nat [simp]:
huffman@22876
   752
  "norm (of_nat n::'a::real_normed_algebra_1) = of_nat n"
huffman@22876
   753
apply (subst of_real_of_nat_eq [symmetric])
huffman@22876
   754
apply (subst norm_of_real, simp)
huffman@22876
   755
done
huffman@22876
   756
huffman@20504
   757
lemma nonzero_norm_inverse:
huffman@20504
   758
  fixes a :: "'a::real_normed_div_algebra"
huffman@20533
   759
  shows "a \<noteq> 0 \<Longrightarrow> norm (inverse a) = inverse (norm a)"
huffman@20504
   760
apply (rule inverse_unique [symmetric])
huffman@20504
   761
apply (simp add: norm_mult [symmetric])
huffman@20504
   762
done
huffman@20504
   763
huffman@20504
   764
lemma norm_inverse:
haftmann@36409
   765
  fixes a :: "'a::{real_normed_div_algebra, division_ring_inverse_zero}"
huffman@20533
   766
  shows "norm (inverse a) = inverse (norm a)"
huffman@20504
   767
apply (case_tac "a = 0", simp)
huffman@20504
   768
apply (erule nonzero_norm_inverse)
huffman@20504
   769
done
huffman@20504
   770
huffman@20584
   771
lemma nonzero_norm_divide:
huffman@20584
   772
  fixes a b :: "'a::real_normed_field"
huffman@20584
   773
  shows "b \<noteq> 0 \<Longrightarrow> norm (a / b) = norm a / norm b"
huffman@20584
   774
by (simp add: divide_inverse norm_mult nonzero_norm_inverse)
huffman@20584
   775
huffman@20584
   776
lemma norm_divide:
haftmann@36409
   777
  fixes a b :: "'a::{real_normed_field, field_inverse_zero}"
huffman@20584
   778
  shows "norm (a / b) = norm a / norm b"
huffman@20584
   779
by (simp add: divide_inverse norm_mult norm_inverse)
huffman@20584
   780
huffman@22852
   781
lemma norm_power_ineq:
haftmann@31017
   782
  fixes x :: "'a::{real_normed_algebra_1}"
huffman@22852
   783
  shows "norm (x ^ n) \<le> norm x ^ n"
huffman@22852
   784
proof (induct n)
huffman@22852
   785
  case 0 show "norm (x ^ 0) \<le> norm x ^ 0" by simp
huffman@22852
   786
next
huffman@22852
   787
  case (Suc n)
huffman@22852
   788
  have "norm (x * x ^ n) \<le> norm x * norm (x ^ n)"
huffman@22852
   789
    by (rule norm_mult_ineq)
huffman@22852
   790
  also from Suc have "\<dots> \<le> norm x * norm x ^ n"
huffman@22852
   791
    using norm_ge_zero by (rule mult_left_mono)
huffman@22852
   792
  finally show "norm (x ^ Suc n) \<le> norm x ^ Suc n"
huffman@30273
   793
    by simp
huffman@22852
   794
qed
huffman@22852
   795
huffman@20684
   796
lemma norm_power:
haftmann@31017
   797
  fixes x :: "'a::{real_normed_div_algebra}"
huffman@20684
   798
  shows "norm (x ^ n) = norm x ^ n"
huffman@30273
   799
by (induct n) (simp_all add: norm_mult)
huffman@20684
   800
huffman@31289
   801
text {* Every normed vector space is a metric space. *}
huffman@31285
   802
huffman@31289
   803
instance real_normed_vector < metric_space
huffman@31289
   804
proof
huffman@31289
   805
  fix x y :: 'a show "dist x y = 0 \<longleftrightarrow> x = y"
huffman@31289
   806
    unfolding dist_norm by simp
huffman@31289
   807
next
huffman@31289
   808
  fix x y z :: 'a show "dist x y \<le> dist x z + dist y z"
huffman@31289
   809
    unfolding dist_norm
huffman@31289
   810
    using norm_triangle_ineq4 [of "x - z" "y - z"] by simp
huffman@31289
   811
qed
huffman@31285
   812
huffman@31564
   813
huffman@31564
   814
subsection {* Class instances for real numbers *}
huffman@31564
   815
huffman@31564
   816
instantiation real :: real_normed_field
huffman@31564
   817
begin
huffman@31564
   818
huffman@31564
   819
definition real_norm_def [simp]:
huffman@31564
   820
  "norm r = \<bar>r\<bar>"
huffman@31564
   821
huffman@31564
   822
definition dist_real_def:
huffman@31564
   823
  "dist x y = \<bar>x - y\<bar>"
huffman@31564
   824
haftmann@37767
   825
definition open_real_def:
huffman@31564
   826
  "open (S :: real set) \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
huffman@31564
   827
huffman@31564
   828
instance
huffman@31564
   829
apply (intro_classes, unfold real_norm_def real_scaleR_def)
huffman@31564
   830
apply (rule dist_real_def)
huffman@31564
   831
apply (rule open_real_def)
huffman@36795
   832
apply (simp add: sgn_real_def)
huffman@31564
   833
apply (rule abs_ge_zero)
huffman@31564
   834
apply (rule abs_eq_0)
huffman@31564
   835
apply (rule abs_triangle_ineq)
huffman@31564
   836
apply (rule abs_mult)
huffman@31564
   837
apply (rule abs_mult)
huffman@31564
   838
done
huffman@31564
   839
huffman@31564
   840
end
huffman@31564
   841
huffman@31564
   842
lemma open_real_lessThan [simp]:
huffman@31564
   843
  fixes a :: real shows "open {..<a}"
huffman@31564
   844
unfolding open_real_def dist_real_def
huffman@31564
   845
proof (clarify)
huffman@31564
   846
  fix x assume "x < a"
huffman@31564
   847
  hence "0 < a - x \<and> (\<forall>y. \<bar>y - x\<bar> < a - x \<longrightarrow> y \<in> {..<a})" by auto
huffman@31564
   848
  thus "\<exists>e>0. \<forall>y. \<bar>y - x\<bar> < e \<longrightarrow> y \<in> {..<a}" ..
huffman@31564
   849
qed
huffman@31564
   850
huffman@31564
   851
lemma open_real_greaterThan [simp]:
huffman@31564
   852
  fixes a :: real shows "open {a<..}"
huffman@31564
   853
unfolding open_real_def dist_real_def
huffman@31564
   854
proof (clarify)
huffman@31564
   855
  fix x assume "a < x"
huffman@31564
   856
  hence "0 < x - a \<and> (\<forall>y. \<bar>y - x\<bar> < x - a \<longrightarrow> y \<in> {a<..})" by auto
huffman@31564
   857
  thus "\<exists>e>0. \<forall>y. \<bar>y - x\<bar> < e \<longrightarrow> y \<in> {a<..}" ..
huffman@31564
   858
qed
huffman@31564
   859
huffman@31564
   860
lemma open_real_greaterThanLessThan [simp]:
huffman@31564
   861
  fixes a b :: real shows "open {a<..<b}"
huffman@31564
   862
proof -
huffman@31564
   863
  have "{a<..<b} = {a<..} \<inter> {..<b}" by auto
huffman@31564
   864
  thus "open {a<..<b}" by (simp add: open_Int)
huffman@31564
   865
qed
huffman@31564
   866
huffman@31567
   867
lemma closed_real_atMost [simp]: 
huffman@31567
   868
  fixes a :: real shows "closed {..a}"
huffman@31567
   869
unfolding closed_open by simp
huffman@31567
   870
huffman@31567
   871
lemma closed_real_atLeast [simp]:
huffman@31567
   872
  fixes a :: real shows "closed {a..}"
huffman@31567
   873
unfolding closed_open by simp
huffman@31567
   874
huffman@31567
   875
lemma closed_real_atLeastAtMost [simp]:
huffman@31567
   876
  fixes a b :: real shows "closed {a..b}"
huffman@31567
   877
proof -
huffman@31567
   878
  have "{a..b} = {a..} \<inter> {..b}" by auto
huffman@31567
   879
  thus "closed {a..b}" by (simp add: closed_Int)
huffman@31567
   880
qed
huffman@31567
   881
huffman@31564
   882
huffman@31446
   883
subsection {* Extra type constraints *}
huffman@31446
   884
huffman@31492
   885
text {* Only allow @{term "open"} in class @{text topological_space}. *}
huffman@31492
   886
huffman@31492
   887
setup {* Sign.add_const_constraint
huffman@31492
   888
  (@{const_name "open"}, SOME @{typ "'a::topological_space set \<Rightarrow> bool"}) *}
huffman@31492
   889
huffman@31446
   890
text {* Only allow @{term dist} in class @{text metric_space}. *}
huffman@31446
   891
huffman@31446
   892
setup {* Sign.add_const_constraint
huffman@31446
   893
  (@{const_name dist}, SOME @{typ "'a::metric_space \<Rightarrow> 'a \<Rightarrow> real"}) *}
huffman@31446
   894
huffman@31446
   895
text {* Only allow @{term norm} in class @{text real_normed_vector}. *}
huffman@31446
   896
huffman@31446
   897
setup {* Sign.add_const_constraint
huffman@31446
   898
  (@{const_name norm}, SOME @{typ "'a::real_normed_vector \<Rightarrow> real"}) *}
huffman@31446
   899
huffman@31285
   900
huffman@22972
   901
subsection {* Sign function *}
huffman@22972
   902
nipkow@24506
   903
lemma norm_sgn:
nipkow@24506
   904
  "norm (sgn(x::'a::real_normed_vector)) = (if x = 0 then 0 else 1)"
huffman@31586
   905
by (simp add: sgn_div_norm)
huffman@22972
   906
nipkow@24506
   907
lemma sgn_zero [simp]: "sgn(0::'a::real_normed_vector) = 0"
nipkow@24506
   908
by (simp add: sgn_div_norm)
huffman@22972
   909
nipkow@24506
   910
lemma sgn_zero_iff: "(sgn(x::'a::real_normed_vector) = 0) = (x = 0)"
nipkow@24506
   911
by (simp add: sgn_div_norm)
huffman@22972
   912
nipkow@24506
   913
lemma sgn_minus: "sgn (- x) = - sgn(x::'a::real_normed_vector)"
nipkow@24506
   914
by (simp add: sgn_div_norm)
huffman@22972
   915
nipkow@24506
   916
lemma sgn_scaleR:
nipkow@24506
   917
  "sgn (scaleR r x) = scaleR (sgn r) (sgn(x::'a::real_normed_vector))"
huffman@31586
   918
by (simp add: sgn_div_norm mult_ac)
huffman@22973
   919
huffman@22972
   920
lemma sgn_one [simp]: "sgn (1::'a::real_normed_algebra_1) = 1"
nipkow@24506
   921
by (simp add: sgn_div_norm)
huffman@22972
   922
huffman@22972
   923
lemma sgn_of_real:
huffman@22972
   924
  "sgn (of_real r::'a::real_normed_algebra_1) = of_real (sgn r)"
huffman@22972
   925
unfolding of_real_def by (simp only: sgn_scaleR sgn_one)
huffman@22972
   926
huffman@22973
   927
lemma sgn_mult:
huffman@22973
   928
  fixes x y :: "'a::real_normed_div_algebra"
huffman@22973
   929
  shows "sgn (x * y) = sgn x * sgn y"
nipkow@24506
   930
by (simp add: sgn_div_norm norm_mult mult_commute)
huffman@22973
   931
huffman@22972
   932
lemma real_sgn_eq: "sgn (x::real) = x / \<bar>x\<bar>"
nipkow@24506
   933
by (simp add: sgn_div_norm divide_inverse)
huffman@22972
   934
huffman@22972
   935
lemma real_sgn_pos: "0 < (x::real) \<Longrightarrow> sgn x = 1"
huffman@22972
   936
unfolding real_sgn_eq by simp
huffman@22972
   937
huffman@22972
   938
lemma real_sgn_neg: "(x::real) < 0 \<Longrightarrow> sgn x = -1"
huffman@22972
   939
unfolding real_sgn_eq by simp
huffman@22972
   940
huffman@22972
   941
huffman@22442
   942
subsection {* Bounded Linear and Bilinear Operators *}
huffman@22442
   943
huffman@22442
   944
locale bounded_linear = additive +
huffman@22442
   945
  constrains f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
huffman@22442
   946
  assumes scaleR: "f (scaleR r x) = scaleR r (f x)"
huffman@22442
   947
  assumes bounded: "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K"
huffman@27443
   948
begin
huffman@22442
   949
huffman@27443
   950
lemma pos_bounded:
huffman@22442
   951
  "\<exists>K>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
   952
proof -
huffman@22442
   953
  obtain K where K: "\<And>x. norm (f x) \<le> norm x * K"
huffman@22442
   954
    using bounded by fast
huffman@22442
   955
  show ?thesis
huffman@22442
   956
  proof (intro exI impI conjI allI)
huffman@22442
   957
    show "0 < max 1 K"
huffman@22442
   958
      by (rule order_less_le_trans [OF zero_less_one le_maxI1])
huffman@22442
   959
  next
huffman@22442
   960
    fix x
huffman@22442
   961
    have "norm (f x) \<le> norm x * K" using K .
huffman@22442
   962
    also have "\<dots> \<le> norm x * max 1 K"
huffman@22442
   963
      by (rule mult_left_mono [OF le_maxI2 norm_ge_zero])
huffman@22442
   964
    finally show "norm (f x) \<le> norm x * max 1 K" .
huffman@22442
   965
  qed
huffman@22442
   966
qed
huffman@22442
   967
huffman@27443
   968
lemma nonneg_bounded:
huffman@22442
   969
  "\<exists>K\<ge>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
   970
proof -
huffman@22442
   971
  from pos_bounded
huffman@22442
   972
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
   973
qed
huffman@22442
   974
huffman@27443
   975
end
huffman@27443
   976
huffman@44127
   977
lemma bounded_linear_intro:
huffman@44127
   978
  assumes "\<And>x y. f (x + y) = f x + f y"
huffman@44127
   979
  assumes "\<And>r x. f (scaleR r x) = scaleR r (f x)"
huffman@44127
   980
  assumes "\<And>x. norm (f x) \<le> norm x * K"
huffman@44127
   981
  shows "bounded_linear f"
huffman@44127
   982
  by default (fast intro: assms)+
huffman@44127
   983
huffman@22442
   984
locale bounded_bilinear =
huffman@22442
   985
  fixes prod :: "['a::real_normed_vector, 'b::real_normed_vector]
huffman@22442
   986
                 \<Rightarrow> 'c::real_normed_vector"
huffman@22442
   987
    (infixl "**" 70)
huffman@22442
   988
  assumes add_left: "prod (a + a') b = prod a b + prod a' b"
huffman@22442
   989
  assumes add_right: "prod a (b + b') = prod a b + prod a b'"
huffman@22442
   990
  assumes scaleR_left: "prod (scaleR r a) b = scaleR r (prod a b)"
huffman@22442
   991
  assumes scaleR_right: "prod a (scaleR r b) = scaleR r (prod a b)"
huffman@22442
   992
  assumes bounded: "\<exists>K. \<forall>a b. norm (prod a b) \<le> norm a * norm b * K"
huffman@27443
   993
begin
huffman@22442
   994
huffman@27443
   995
lemma pos_bounded:
huffman@22442
   996
  "\<exists>K>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
   997
apply (cut_tac bounded, erule exE)
huffman@22442
   998
apply (rule_tac x="max 1 K" in exI, safe)
huffman@22442
   999
apply (rule order_less_le_trans [OF zero_less_one le_maxI1])
huffman@22442
  1000
apply (drule spec, drule spec, erule order_trans)
huffman@22442
  1001
apply (rule mult_left_mono [OF le_maxI2])
huffman@22442
  1002
apply (intro mult_nonneg_nonneg norm_ge_zero)
huffman@22442
  1003
done
huffman@22442
  1004
huffman@27443
  1005
lemma nonneg_bounded:
huffman@22442
  1006
  "\<exists>K\<ge>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
  1007
proof -
huffman@22442
  1008
  from pos_bounded
huffman@22442
  1009
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
  1010
qed
huffman@22442
  1011
huffman@27443
  1012
lemma additive_right: "additive (\<lambda>b. prod a b)"
huffman@22442
  1013
by (rule additive.intro, rule add_right)
huffman@22442
  1014
huffman@27443
  1015
lemma additive_left: "additive (\<lambda>a. prod a b)"
huffman@22442
  1016
by (rule additive.intro, rule add_left)
huffman@22442
  1017
huffman@27443
  1018
lemma zero_left: "prod 0 b = 0"
huffman@22442
  1019
by (rule additive.zero [OF additive_left])
huffman@22442
  1020
huffman@27443
  1021
lemma zero_right: "prod a 0 = 0"
huffman@22442
  1022
by (rule additive.zero [OF additive_right])
huffman@22442
  1023
huffman@27443
  1024
lemma minus_left: "prod (- a) b = - prod a b"
huffman@22442
  1025
by (rule additive.minus [OF additive_left])
huffman@22442
  1026
huffman@27443
  1027
lemma minus_right: "prod a (- b) = - prod a b"
huffman@22442
  1028
by (rule additive.minus [OF additive_right])
huffman@22442
  1029
huffman@27443
  1030
lemma diff_left:
huffman@22442
  1031
  "prod (a - a') b = prod a b - prod a' b"
huffman@22442
  1032
by (rule additive.diff [OF additive_left])
huffman@22442
  1033
huffman@27443
  1034
lemma diff_right:
huffman@22442
  1035
  "prod a (b - b') = prod a b - prod a b'"
huffman@22442
  1036
by (rule additive.diff [OF additive_right])
huffman@22442
  1037
huffman@27443
  1038
lemma bounded_linear_left:
huffman@22442
  1039
  "bounded_linear (\<lambda>a. a ** b)"
huffman@44127
  1040
apply (cut_tac bounded, safe)
huffman@44127
  1041
apply (rule_tac K="norm b * K" in bounded_linear_intro)
huffman@22442
  1042
apply (rule add_left)
huffman@22442
  1043
apply (rule scaleR_left)
huffman@22442
  1044
apply (simp add: mult_ac)
huffman@22442
  1045
done
huffman@22442
  1046
huffman@27443
  1047
lemma bounded_linear_right:
huffman@22442
  1048
  "bounded_linear (\<lambda>b. a ** b)"
huffman@44127
  1049
apply (cut_tac bounded, safe)
huffman@44127
  1050
apply (rule_tac K="norm a * K" in bounded_linear_intro)
huffman@22442
  1051
apply (rule add_right)
huffman@22442
  1052
apply (rule scaleR_right)
huffman@22442
  1053
apply (simp add: mult_ac)
huffman@22442
  1054
done
huffman@22442
  1055
huffman@27443
  1056
lemma prod_diff_prod:
huffman@22442
  1057
  "(x ** y - a ** b) = (x - a) ** (y - b) + (x - a) ** b + a ** (y - b)"
huffman@22442
  1058
by (simp add: diff_left diff_right)
huffman@22442
  1059
huffman@27443
  1060
end
huffman@27443
  1061
wenzelm@30729
  1062
interpretation mult:
ballarin@29229
  1063
  bounded_bilinear "op * :: 'a \<Rightarrow> 'a \<Rightarrow> 'a::real_normed_algebra"
huffman@22442
  1064
apply (rule bounded_bilinear.intro)
huffman@22442
  1065
apply (rule left_distrib)
huffman@22442
  1066
apply (rule right_distrib)
huffman@22442
  1067
apply (rule mult_scaleR_left)
huffman@22442
  1068
apply (rule mult_scaleR_right)
huffman@22442
  1069
apply (rule_tac x="1" in exI)
huffman@22442
  1070
apply (simp add: norm_mult_ineq)
huffman@22442
  1071
done
huffman@22442
  1072
wenzelm@30729
  1073
interpretation mult_left:
ballarin@29229
  1074
  bounded_linear "(\<lambda>x::'a::real_normed_algebra. x * y)"
huffman@23127
  1075
by (rule mult.bounded_linear_left)
huffman@22442
  1076
wenzelm@30729
  1077
interpretation mult_right:
ballarin@29229
  1078
  bounded_linear "(\<lambda>y::'a::real_normed_algebra. x * y)"
huffman@23127
  1079
by (rule mult.bounded_linear_right)
huffman@23127
  1080
wenzelm@30729
  1081
interpretation divide:
ballarin@29229
  1082
  bounded_linear "(\<lambda>x::'a::real_normed_field. x / y)"
huffman@23127
  1083
unfolding divide_inverse by (rule mult.bounded_linear_left)
huffman@23120
  1084
wenzelm@30729
  1085
interpretation scaleR: bounded_bilinear "scaleR"
huffman@22442
  1086
apply (rule bounded_bilinear.intro)
huffman@22442
  1087
apply (rule scaleR_left_distrib)
huffman@22442
  1088
apply (rule scaleR_right_distrib)
huffman@22973
  1089
apply simp
huffman@22442
  1090
apply (rule scaleR_left_commute)
huffman@31586
  1091
apply (rule_tac x="1" in exI, simp)
huffman@22442
  1092
done
huffman@22442
  1093
wenzelm@30729
  1094
interpretation scaleR_left: bounded_linear "\<lambda>r. scaleR r x"
huffman@23127
  1095
by (rule scaleR.bounded_linear_left)
huffman@23127
  1096
wenzelm@30729
  1097
interpretation scaleR_right: bounded_linear "\<lambda>x. scaleR r x"
huffman@23127
  1098
by (rule scaleR.bounded_linear_right)
huffman@23127
  1099
wenzelm@30729
  1100
interpretation of_real: bounded_linear "\<lambda>r. of_real r"
huffman@23127
  1101
unfolding of_real_def by (rule scaleR.bounded_linear_left)
huffman@22625
  1102
hoelzl@41969
  1103
subsection{* Hausdorff and other separation properties *}
hoelzl@41969
  1104
hoelzl@41969
  1105
class t0_space = topological_space +
hoelzl@41969
  1106
  assumes t0_space: "x \<noteq> y \<Longrightarrow> \<exists>U. open U \<and> \<not> (x \<in> U \<longleftrightarrow> y \<in> U)"
hoelzl@41969
  1107
hoelzl@41969
  1108
class t1_space = topological_space +
hoelzl@41969
  1109
  assumes t1_space: "x \<noteq> y \<Longrightarrow> \<exists>U. open U \<and> x \<in> U \<and> y \<notin> U"
hoelzl@41969
  1110
hoelzl@41969
  1111
instance t1_space \<subseteq> t0_space
hoelzl@41969
  1112
proof qed (fast dest: t1_space)
hoelzl@41969
  1113
hoelzl@41969
  1114
lemma separation_t1:
hoelzl@41969
  1115
  fixes x y :: "'a::t1_space"
hoelzl@41969
  1116
  shows "x \<noteq> y \<longleftrightarrow> (\<exists>U. open U \<and> x \<in> U \<and> y \<notin> U)"
hoelzl@41969
  1117
  using t1_space[of x y] by blast
hoelzl@41969
  1118
hoelzl@41969
  1119
lemma closed_singleton:
hoelzl@41969
  1120
  fixes a :: "'a::t1_space"
hoelzl@41969
  1121
  shows "closed {a}"
hoelzl@41969
  1122
proof -
hoelzl@41969
  1123
  let ?T = "\<Union>{S. open S \<and> a \<notin> S}"
hoelzl@41969
  1124
  have "open ?T" by (simp add: open_Union)
hoelzl@41969
  1125
  also have "?T = - {a}"
hoelzl@41969
  1126
    by (simp add: set_eq_iff separation_t1, auto)
hoelzl@41969
  1127
  finally show "closed {a}" unfolding closed_def .
hoelzl@41969
  1128
qed
hoelzl@41969
  1129
hoelzl@41969
  1130
lemma closed_insert [simp]:
hoelzl@41969
  1131
  fixes a :: "'a::t1_space"
hoelzl@41969
  1132
  assumes "closed S" shows "closed (insert a S)"
hoelzl@41969
  1133
proof -
hoelzl@41969
  1134
  from closed_singleton assms
hoelzl@41969
  1135
  have "closed ({a} \<union> S)" by (rule closed_Un)
hoelzl@41969
  1136
  thus "closed (insert a S)" by simp
hoelzl@41969
  1137
qed
hoelzl@41969
  1138
hoelzl@41969
  1139
lemma finite_imp_closed:
hoelzl@41969
  1140
  fixes S :: "'a::t1_space set"
hoelzl@41969
  1141
  shows "finite S \<Longrightarrow> closed S"
hoelzl@41969
  1142
by (induct set: finite, simp_all)
hoelzl@41969
  1143
hoelzl@41969
  1144
text {* T2 spaces are also known as Hausdorff spaces. *}
hoelzl@41969
  1145
hoelzl@41969
  1146
class t2_space = topological_space +
hoelzl@41969
  1147
  assumes hausdorff: "x \<noteq> y \<Longrightarrow> \<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
hoelzl@41969
  1148
hoelzl@41969
  1149
instance t2_space \<subseteq> t1_space
hoelzl@41969
  1150
proof qed (fast dest: hausdorff)
hoelzl@41969
  1151
hoelzl@41969
  1152
instance metric_space \<subseteq> t2_space
hoelzl@41969
  1153
proof
hoelzl@41969
  1154
  fix x y :: "'a::metric_space"
hoelzl@41969
  1155
  assume xy: "x \<noteq> y"
hoelzl@41969
  1156
  let ?U = "{y'. dist x y' < dist x y / 2}"
hoelzl@41969
  1157
  let ?V = "{x'. dist y x' < dist x y / 2}"
hoelzl@41969
  1158
  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@41969
  1159
               \<Longrightarrow> \<not>(d x y * 2 < d x z \<and> d z y * 2 < d x z)" by arith
hoelzl@41969
  1160
  have "open ?U \<and> open ?V \<and> x \<in> ?U \<and> y \<in> ?V \<and> ?U \<inter> ?V = {}"
hoelzl@41969
  1161
    using dist_pos_lt[OF xy] th0[of dist, OF dist_triangle dist_commute]
hoelzl@41969
  1162
    using open_ball[of _ "dist x y / 2"] by auto
hoelzl@41969
  1163
  then show "\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
hoelzl@41969
  1164
    by blast
hoelzl@41969
  1165
qed
hoelzl@41969
  1166
hoelzl@41969
  1167
lemma separation_t2:
hoelzl@41969
  1168
  fixes x y :: "'a::t2_space"
hoelzl@41969
  1169
  shows "x \<noteq> y \<longleftrightarrow> (\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {})"
hoelzl@41969
  1170
  using hausdorff[of x y] by blast
hoelzl@41969
  1171
hoelzl@41969
  1172
lemma separation_t0:
hoelzl@41969
  1173
  fixes x y :: "'a::t0_space"
hoelzl@41969
  1174
  shows "x \<noteq> y \<longleftrightarrow> (\<exists>U. open U \<and> ~(x\<in>U \<longleftrightarrow> y\<in>U))"
hoelzl@41969
  1175
  using t0_space[of x y] by blast
hoelzl@41969
  1176
huffman@20504
  1177
end