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