src/HOL/RealVector.thy
author huffman
Sun Jun 07 12:00:03 2009 -0700 (2009-06-07)
changeset 31490 c350f3ad6b0d
parent 31446 2d91b2416de8
child 31492 5400beeddb55
permissions -rw-r--r--
move definitions of open, closed to RealVector.thy
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
haftmann@29197
     8
imports RealPow
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"
huffman@20504
    33
by (simp add: diff_def add 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@28029
   119
lemma scale_cancel_left:
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@28029
   123
lemma scale_cancel_right:
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:
huffman@20584
   210
  fixes x :: "'a::{real_div_algebra,division_by_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) =
huffman@20584
   253
   inverse (of_real x :: 'a::{real_div_algebra,division_by_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) =
huffman@20584
   263
   (of_real x / of_real y :: 'a::{real_field,division_by_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@20554
   271
by (simp add: of_real_def scaleR_cancel_right)
huffman@20554
   272
huffman@20584
   273
lemmas of_real_eq_0_iff [simp] = of_real_eq_iff [of _ 0, simplified]
huffman@20554
   274
huffman@20554
   275
lemma of_real_eq_id [simp]: "of_real = (id :: real \<Rightarrow> real)"
huffman@20554
   276
proof
huffman@20554
   277
  fix r
huffman@20554
   278
  show "of_real r = id r"
huffman@22973
   279
    by (simp add: of_real_def)
huffman@20554
   280
qed
huffman@20554
   281
huffman@20554
   282
text{*Collapse nested embeddings*}
huffman@20554
   283
lemma of_real_of_nat_eq [simp]: "of_real (of_nat n) = of_nat n"
wenzelm@20772
   284
by (induct n) auto
huffman@20554
   285
huffman@20554
   286
lemma of_real_of_int_eq [simp]: "of_real (of_int z) = of_int z"
huffman@20554
   287
by (cases z rule: int_diff_cases, simp)
huffman@20554
   288
huffman@20554
   289
lemma of_real_number_of_eq:
huffman@20554
   290
  "of_real (number_of w) = (number_of w :: 'a::{number_ring,real_algebra_1})"
huffman@20554
   291
by (simp add: number_of_eq)
huffman@20554
   292
huffman@22912
   293
text{*Every real algebra has characteristic zero*}
huffman@22912
   294
instance real_algebra_1 < ring_char_0
huffman@22912
   295
proof
huffman@23282
   296
  fix m n :: nat
huffman@23282
   297
  have "(of_real (of_nat m) = (of_real (of_nat n)::'a)) = (m = n)"
huffman@23282
   298
    by (simp only: of_real_eq_iff of_nat_eq_iff)
huffman@23282
   299
  thus "(of_nat m = (of_nat n::'a)) = (m = n)"
huffman@23282
   300
    by (simp only: of_real_of_nat_eq)
huffman@22912
   301
qed
huffman@22912
   302
huffman@27553
   303
instance real_field < field_char_0 ..
huffman@27553
   304
huffman@20554
   305
huffman@20554
   306
subsection {* The Set of Real Numbers *}
huffman@20554
   307
wenzelm@20772
   308
definition
wenzelm@21404
   309
  Reals :: "'a::real_algebra_1 set" where
huffman@30070
   310
  [code del]: "Reals = range of_real"
huffman@20554
   311
wenzelm@21210
   312
notation (xsymbols)
huffman@20554
   313
  Reals  ("\<real>")
huffman@20554
   314
huffman@21809
   315
lemma Reals_of_real [simp]: "of_real r \<in> Reals"
huffman@20554
   316
by (simp add: Reals_def)
huffman@20554
   317
huffman@21809
   318
lemma Reals_of_int [simp]: "of_int z \<in> Reals"
huffman@21809
   319
by (subst of_real_of_int_eq [symmetric], rule Reals_of_real)
huffman@20718
   320
huffman@21809
   321
lemma Reals_of_nat [simp]: "of_nat n \<in> Reals"
huffman@21809
   322
by (subst of_real_of_nat_eq [symmetric], rule Reals_of_real)
huffman@21809
   323
huffman@21809
   324
lemma Reals_number_of [simp]:
huffman@21809
   325
  "(number_of w::'a::{number_ring,real_algebra_1}) \<in> Reals"
huffman@21809
   326
by (subst of_real_number_of_eq [symmetric], rule Reals_of_real)
huffman@20718
   327
huffman@20554
   328
lemma Reals_0 [simp]: "0 \<in> Reals"
huffman@20554
   329
apply (unfold Reals_def)
huffman@20554
   330
apply (rule range_eqI)
huffman@20554
   331
apply (rule of_real_0 [symmetric])
huffman@20554
   332
done
huffman@20554
   333
huffman@20554
   334
lemma Reals_1 [simp]: "1 \<in> Reals"
huffman@20554
   335
apply (unfold Reals_def)
huffman@20554
   336
apply (rule range_eqI)
huffman@20554
   337
apply (rule of_real_1 [symmetric])
huffman@20554
   338
done
huffman@20554
   339
huffman@20584
   340
lemma Reals_add [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a + b \<in> Reals"
huffman@20554
   341
apply (auto simp add: Reals_def)
huffman@20554
   342
apply (rule range_eqI)
huffman@20554
   343
apply (rule of_real_add [symmetric])
huffman@20554
   344
done
huffman@20554
   345
huffman@20584
   346
lemma Reals_minus [simp]: "a \<in> Reals \<Longrightarrow> - a \<in> Reals"
huffman@20584
   347
apply (auto simp add: Reals_def)
huffman@20584
   348
apply (rule range_eqI)
huffman@20584
   349
apply (rule of_real_minus [symmetric])
huffman@20584
   350
done
huffman@20584
   351
huffman@20584
   352
lemma Reals_diff [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a - b \<in> Reals"
huffman@20584
   353
apply (auto simp add: Reals_def)
huffman@20584
   354
apply (rule range_eqI)
huffman@20584
   355
apply (rule of_real_diff [symmetric])
huffman@20584
   356
done
huffman@20584
   357
huffman@20584
   358
lemma Reals_mult [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_mult [symmetric])
huffman@20554
   362
done
huffman@20554
   363
huffman@20584
   364
lemma nonzero_Reals_inverse:
huffman@20584
   365
  fixes a :: "'a::real_div_algebra"
huffman@20584
   366
  shows "\<lbrakk>a \<in> Reals; a \<noteq> 0\<rbrakk> \<Longrightarrow> inverse a \<in> Reals"
huffman@20584
   367
apply (auto simp add: Reals_def)
huffman@20584
   368
apply (rule range_eqI)
huffman@20584
   369
apply (erule nonzero_of_real_inverse [symmetric])
huffman@20584
   370
done
huffman@20584
   371
huffman@20584
   372
lemma Reals_inverse [simp]:
huffman@20584
   373
  fixes a :: "'a::{real_div_algebra,division_by_zero}"
huffman@20584
   374
  shows "a \<in> Reals \<Longrightarrow> inverse a \<in> Reals"
huffman@20584
   375
apply (auto simp add: Reals_def)
huffman@20584
   376
apply (rule range_eqI)
huffman@20584
   377
apply (rule of_real_inverse [symmetric])
huffman@20584
   378
done
huffman@20584
   379
huffman@20584
   380
lemma nonzero_Reals_divide:
huffman@20584
   381
  fixes a b :: "'a::real_field"
huffman@20584
   382
  shows "\<lbrakk>a \<in> Reals; b \<in> Reals; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584
   383
apply (auto simp add: Reals_def)
huffman@20584
   384
apply (rule range_eqI)
huffman@20584
   385
apply (erule nonzero_of_real_divide [symmetric])
huffman@20584
   386
done
huffman@20584
   387
huffman@20584
   388
lemma Reals_divide [simp]:
huffman@20584
   389
  fixes a b :: "'a::{real_field,division_by_zero}"
huffman@20584
   390
  shows "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584
   391
apply (auto simp add: Reals_def)
huffman@20584
   392
apply (rule range_eqI)
huffman@20584
   393
apply (rule of_real_divide [symmetric])
huffman@20584
   394
done
huffman@20584
   395
huffman@20722
   396
lemma Reals_power [simp]:
haftmann@31017
   397
  fixes a :: "'a::{real_algebra_1}"
huffman@20722
   398
  shows "a \<in> Reals \<Longrightarrow> a ^ n \<in> Reals"
huffman@20722
   399
apply (auto simp add: Reals_def)
huffman@20722
   400
apply (rule range_eqI)
huffman@20722
   401
apply (rule of_real_power [symmetric])
huffman@20722
   402
done
huffman@20722
   403
huffman@20554
   404
lemma Reals_cases [cases set: Reals]:
huffman@20554
   405
  assumes "q \<in> \<real>"
huffman@20554
   406
  obtains (of_real) r where "q = of_real r"
huffman@20554
   407
  unfolding Reals_def
huffman@20554
   408
proof -
huffman@20554
   409
  from `q \<in> \<real>` have "q \<in> range of_real" unfolding Reals_def .
huffman@20554
   410
  then obtain r where "q = of_real r" ..
huffman@20554
   411
  then show thesis ..
huffman@20554
   412
qed
huffman@20554
   413
huffman@20554
   414
lemma Reals_induct [case_names of_real, induct set: Reals]:
huffman@20554
   415
  "q \<in> \<real> \<Longrightarrow> (\<And>r. P (of_real r)) \<Longrightarrow> P q"
huffman@20554
   416
  by (rule Reals_cases) auto
huffman@20554
   417
huffman@20504
   418
huffman@31413
   419
subsection {* Topological spaces *}
huffman@31413
   420
huffman@31417
   421
class topo =
huffman@31417
   422
  fixes topo :: "'a set set"
huffman@31413
   423
huffman@31490
   424
text {*
huffman@31490
   425
  The syntactic class uses @{term topo} instead of @{text "open"}
huffman@31490
   426
  so that @{text "open"} and @{text closed} will have the same type.
huffman@31490
   427
  Maybe we could use extra type constraints instead, like with
huffman@31490
   428
  @{text dist} and @{text norm}?
huffman@31490
   429
*}
huffman@31490
   430
huffman@31417
   431
class topological_space = topo +
huffman@31417
   432
  assumes topo_UNIV: "UNIV \<in> topo"
huffman@31417
   433
  assumes topo_Int: "A \<in> topo \<Longrightarrow> B \<in> topo \<Longrightarrow> A \<inter> B \<in> topo"
huffman@31417
   434
  assumes topo_Union: "T \<subseteq> topo \<Longrightarrow> \<Union>T \<in> topo"
huffman@31490
   435
begin
huffman@31490
   436
huffman@31490
   437
definition
huffman@31490
   438
  "open" :: "'a set \<Rightarrow> bool" where
huffman@31490
   439
  "open S \<longleftrightarrow> S \<in> topo"
huffman@31490
   440
huffman@31490
   441
definition
huffman@31490
   442
  closed :: "'a set \<Rightarrow> bool" where
huffman@31490
   443
  "closed S \<longleftrightarrow> open (- S)"
huffman@31490
   444
huffman@31490
   445
lemma open_UNIV [intro, simp]:  "open UNIV"
huffman@31490
   446
  unfolding open_def by (rule topo_UNIV)
huffman@31490
   447
huffman@31490
   448
lemma open_Int [intro]: "open S \<Longrightarrow> open T \<Longrightarrow> open (S \<inter> T)"
huffman@31490
   449
  unfolding open_def by (rule topo_Int)
huffman@31490
   450
huffman@31490
   451
lemma open_Union [intro]: "\<forall>S\<in>K. open S \<Longrightarrow> open (\<Union> K)"
huffman@31490
   452
  unfolding open_def subset_eq [symmetric] by (rule topo_Union)
huffman@31490
   453
huffman@31490
   454
lemma open_empty [intro, simp]: "open {}"
huffman@31490
   455
  using open_Union [of "{}"] by simp
huffman@31490
   456
huffman@31490
   457
lemma open_Un [intro]: "open S \<Longrightarrow> open T \<Longrightarrow> open (S \<union> T)"
huffman@31490
   458
  using open_Union [of "{S, T}"] by simp
huffman@31490
   459
huffman@31490
   460
lemma open_UN [intro]: "\<forall>x\<in>A. open (B x) \<Longrightarrow> open (\<Union>x\<in>A. B x)"
huffman@31490
   461
  unfolding UN_eq by (rule open_Union) auto
huffman@31490
   462
huffman@31490
   463
lemma open_INT [intro]: "finite A \<Longrightarrow> \<forall>x\<in>A. open (B x) \<Longrightarrow> open (\<Inter>x\<in>A. B x)"
huffman@31490
   464
  by (induct set: finite) auto
huffman@31490
   465
huffman@31490
   466
lemma open_Inter [intro]: "finite S \<Longrightarrow> \<forall>T\<in>S. open T \<Longrightarrow> open (\<Inter>S)"
huffman@31490
   467
  unfolding Inter_def by (rule open_INT)
huffman@31490
   468
huffman@31490
   469
lemma closed_empty [intro, simp]:  "closed {}"
huffman@31490
   470
  unfolding closed_def by simp
huffman@31490
   471
huffman@31490
   472
lemma closed_Un [intro]: "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<union> T)"
huffman@31490
   473
  unfolding closed_def by auto
huffman@31490
   474
huffman@31490
   475
lemma closed_Inter [intro]: "\<forall>S\<in>K. closed S \<Longrightarrow> closed (\<Inter> K)"
huffman@31490
   476
  unfolding closed_def Inter_def by auto
huffman@31490
   477
huffman@31490
   478
lemma closed_UNIV [intro, simp]: "closed UNIV"
huffman@31490
   479
  unfolding closed_def by simp
huffman@31490
   480
huffman@31490
   481
lemma closed_Int [intro]: "closed S \<Longrightarrow> closed T \<Longrightarrow> closed (S \<inter> T)"
huffman@31490
   482
  unfolding closed_def by auto
huffman@31490
   483
huffman@31490
   484
lemma closed_INT [intro]: "\<forall>x\<in>A. closed (B x) \<Longrightarrow> closed (\<Inter>x\<in>A. B x)"
huffman@31490
   485
  unfolding closed_def by auto
huffman@31490
   486
huffman@31490
   487
lemma closed_UN [intro]: "finite A \<Longrightarrow> \<forall>x\<in>A. closed (B x) \<Longrightarrow> closed (\<Union>x\<in>A. B x)"
huffman@31490
   488
  by (induct set: finite) auto
huffman@31490
   489
huffman@31490
   490
lemma closed_Union [intro]: "finite S \<Longrightarrow> \<forall>T\<in>S. closed T \<Longrightarrow> closed (\<Union>S)"
huffman@31490
   491
  unfolding Union_def by (rule closed_UN)
huffman@31490
   492
huffman@31490
   493
lemma open_closed: "open S \<longleftrightarrow> closed (- S)"
huffman@31490
   494
  unfolding closed_def by simp
huffman@31490
   495
huffman@31490
   496
lemma closed_open: "closed S \<longleftrightarrow> open (- S)"
huffman@31490
   497
  unfolding closed_def by simp
huffman@31490
   498
huffman@31490
   499
lemma open_Diff [intro]: "open S \<Longrightarrow> closed T \<Longrightarrow> open (S - T)"
huffman@31490
   500
  unfolding closed_open Diff_eq by (rule open_Int)
huffman@31490
   501
huffman@31490
   502
lemma closed_Diff [intro]: "closed S \<Longrightarrow> open T \<Longrightarrow> closed (S - T)"
huffman@31490
   503
  unfolding open_closed Diff_eq by (rule closed_Int)
huffman@31490
   504
huffman@31490
   505
lemma open_Compl [intro]: "closed S \<Longrightarrow> open (- S)"
huffman@31490
   506
  unfolding closed_open .
huffman@31490
   507
huffman@31490
   508
lemma closed_Compl [intro]: "open S \<Longrightarrow> closed (- S)"
huffman@31490
   509
  unfolding open_closed .
huffman@31490
   510
huffman@31490
   511
end
huffman@31413
   512
huffman@31413
   513
huffman@31289
   514
subsection {* Metric spaces *}
huffman@31289
   515
huffman@31289
   516
class dist =
huffman@31289
   517
  fixes dist :: "'a \<Rightarrow> 'a \<Rightarrow> real"
huffman@31289
   518
huffman@31417
   519
class topo_dist = topo + dist +
huffman@31417
   520
  assumes topo_dist: "topo = {S. \<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S}"
huffman@31413
   521
huffman@31417
   522
class metric_space = topo_dist +
huffman@31289
   523
  assumes dist_eq_0_iff [simp]: "dist x y = 0 \<longleftrightarrow> x = y"
huffman@31289
   524
  assumes dist_triangle2: "dist x y \<le> dist x z + dist y z"
huffman@31289
   525
begin
huffman@31289
   526
huffman@31289
   527
lemma dist_self [simp]: "dist x x = 0"
huffman@31289
   528
by simp
huffman@31289
   529
huffman@31289
   530
lemma zero_le_dist [simp]: "0 \<le> dist x y"
huffman@31289
   531
using dist_triangle2 [of x x y] by simp
huffman@31289
   532
huffman@31289
   533
lemma zero_less_dist_iff: "0 < dist x y \<longleftrightarrow> x \<noteq> y"
huffman@31289
   534
by (simp add: less_le)
huffman@31289
   535
huffman@31289
   536
lemma dist_not_less_zero [simp]: "\<not> dist x y < 0"
huffman@31289
   537
by (simp add: not_less)
huffman@31289
   538
huffman@31289
   539
lemma dist_le_zero_iff [simp]: "dist x y \<le> 0 \<longleftrightarrow> x = y"
huffman@31289
   540
by (simp add: le_less)
huffman@31289
   541
huffman@31289
   542
lemma dist_commute: "dist x y = dist y x"
huffman@31289
   543
proof (rule order_antisym)
huffman@31289
   544
  show "dist x y \<le> dist y x"
huffman@31289
   545
    using dist_triangle2 [of x y x] by simp
huffman@31289
   546
  show "dist y x \<le> dist x y"
huffman@31289
   547
    using dist_triangle2 [of y x y] by simp
huffman@31289
   548
qed
huffman@31289
   549
huffman@31289
   550
lemma dist_triangle: "dist x z \<le> dist x y + dist y z"
huffman@31289
   551
using dist_triangle2 [of x z y] by (simp add: dist_commute)
huffman@31289
   552
huffman@31413
   553
subclass topological_space
huffman@31413
   554
proof
huffman@31413
   555
  have "\<exists>e::real. 0 < e"
huffman@31413
   556
    by (fast intro: zero_less_one)
huffman@31417
   557
  then show "UNIV \<in> topo"
huffman@31417
   558
    unfolding topo_dist by simp
huffman@31413
   559
next
huffman@31417
   560
  fix A B assume "A \<in> topo" "B \<in> topo"
huffman@31417
   561
  then show "A \<inter> B \<in> topo"
huffman@31417
   562
    unfolding topo_dist
huffman@31413
   563
    apply clarify
huffman@31413
   564
    apply (drule (1) bspec)+
huffman@31413
   565
    apply (clarify, rename_tac r s)
huffman@31413
   566
    apply (rule_tac x="min r s" in exI, simp)
huffman@31413
   567
    done
huffman@31413
   568
next
huffman@31417
   569
  fix T assume "T \<subseteq> topo" thus "\<Union>T \<in> topo"
huffman@31417
   570
    unfolding topo_dist by fast
huffman@31413
   571
qed
huffman@31413
   572
huffman@31289
   573
end
huffman@31289
   574
huffman@31289
   575
huffman@20504
   576
subsection {* Real normed vector spaces *}
huffman@20504
   577
haftmann@29608
   578
class norm =
huffman@22636
   579
  fixes norm :: "'a \<Rightarrow> real"
huffman@20504
   580
huffman@24520
   581
class sgn_div_norm = scaleR + norm + sgn +
haftmann@25062
   582
  assumes sgn_div_norm: "sgn x = x /\<^sub>R norm x"
nipkow@24506
   583
huffman@31289
   584
class dist_norm = dist + norm + minus +
huffman@31289
   585
  assumes dist_norm: "dist x y = norm (x - y)"
huffman@31289
   586
huffman@31417
   587
class real_normed_vector = real_vector + sgn_div_norm + dist_norm + topo_dist +
haftmann@24588
   588
  assumes norm_ge_zero [simp]: "0 \<le> norm x"
haftmann@25062
   589
  and norm_eq_zero [simp]: "norm x = 0 \<longleftrightarrow> x = 0"
haftmann@25062
   590
  and norm_triangle_ineq: "norm (x + y) \<le> norm x + norm y"
haftmann@24588
   591
  and norm_scaleR: "norm (scaleR a x) = \<bar>a\<bar> * norm x"
huffman@20504
   592
haftmann@24588
   593
class real_normed_algebra = real_algebra + real_normed_vector +
haftmann@25062
   594
  assumes norm_mult_ineq: "norm (x * y) \<le> norm x * norm y"
huffman@20504
   595
haftmann@24588
   596
class real_normed_algebra_1 = real_algebra_1 + real_normed_algebra +
haftmann@25062
   597
  assumes norm_one [simp]: "norm 1 = 1"
huffman@22852
   598
haftmann@24588
   599
class real_normed_div_algebra = real_div_algebra + real_normed_vector +
haftmann@25062
   600
  assumes norm_mult: "norm (x * y) = norm x * norm y"
huffman@20504
   601
haftmann@24588
   602
class real_normed_field = real_field + real_normed_div_algebra
huffman@20584
   603
huffman@22852
   604
instance real_normed_div_algebra < real_normed_algebra_1
huffman@20554
   605
proof
huffman@20554
   606
  fix x y :: 'a
huffman@20554
   607
  show "norm (x * y) \<le> norm x * norm y"
huffman@20554
   608
    by (simp add: norm_mult)
huffman@22852
   609
next
huffman@22852
   610
  have "norm (1 * 1::'a) = norm (1::'a) * norm (1::'a)"
huffman@22852
   611
    by (rule norm_mult)
huffman@22852
   612
  thus "norm (1::'a) = 1" by simp
huffman@20554
   613
qed
huffman@20554
   614
huffman@30069
   615
instantiation real :: real_normed_field
huffman@30069
   616
begin
huffman@30069
   617
huffman@31413
   618
definition real_norm_def [simp]:
huffman@31413
   619
  "norm r = \<bar>r\<bar>"
huffman@30069
   620
huffman@31413
   621
definition dist_real_def:
huffman@31413
   622
  "dist x y = \<bar>x - y\<bar>"
huffman@31413
   623
huffman@31419
   624
definition topo_real_def [code del]:
huffman@31417
   625
  "topo = {S::real set. \<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S}"
huffman@31289
   626
huffman@30069
   627
instance
huffman@22852
   628
apply (intro_classes, unfold real_norm_def real_scaleR_def)
huffman@31289
   629
apply (rule dist_real_def)
nipkow@24506
   630
apply (simp add: real_sgn_def)
huffman@31417
   631
apply (rule topo_real_def)
huffman@20554
   632
apply (rule abs_ge_zero)
huffman@20554
   633
apply (rule abs_eq_0)
huffman@20554
   634
apply (rule abs_triangle_ineq)
huffman@22852
   635
apply (rule abs_mult)
huffman@20554
   636
apply (rule abs_mult)
huffman@20554
   637
done
huffman@20504
   638
huffman@30069
   639
end
huffman@30069
   640
huffman@22852
   641
lemma norm_zero [simp]: "norm (0::'a::real_normed_vector) = 0"
huffman@20504
   642
by simp
huffman@20504
   643
huffman@22852
   644
lemma zero_less_norm_iff [simp]:
huffman@22852
   645
  fixes x :: "'a::real_normed_vector"
huffman@22852
   646
  shows "(0 < norm x) = (x \<noteq> 0)"
huffman@20504
   647
by (simp add: order_less_le)
huffman@20504
   648
huffman@22852
   649
lemma norm_not_less_zero [simp]:
huffman@22852
   650
  fixes x :: "'a::real_normed_vector"
huffman@22852
   651
  shows "\<not> norm x < 0"
huffman@20828
   652
by (simp add: linorder_not_less)
huffman@20828
   653
huffman@22852
   654
lemma norm_le_zero_iff [simp]:
huffman@22852
   655
  fixes x :: "'a::real_normed_vector"
huffman@22852
   656
  shows "(norm x \<le> 0) = (x = 0)"
huffman@20828
   657
by (simp add: order_le_less)
huffman@20828
   658
huffman@20504
   659
lemma norm_minus_cancel [simp]:
huffman@20584
   660
  fixes x :: "'a::real_normed_vector"
huffman@20584
   661
  shows "norm (- x) = norm x"
huffman@20504
   662
proof -
huffman@21809
   663
  have "norm (- x) = norm (scaleR (- 1) x)"
huffman@20504
   664
    by (simp only: scaleR_minus_left scaleR_one)
huffman@20533
   665
  also have "\<dots> = \<bar>- 1\<bar> * norm x"
huffman@20504
   666
    by (rule norm_scaleR)
huffman@20504
   667
  finally show ?thesis by simp
huffman@20504
   668
qed
huffman@20504
   669
huffman@20504
   670
lemma norm_minus_commute:
huffman@20584
   671
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   672
  shows "norm (a - b) = norm (b - a)"
huffman@20504
   673
proof -
huffman@22898
   674
  have "norm (- (b - a)) = norm (b - a)"
huffman@22898
   675
    by (rule norm_minus_cancel)
huffman@22898
   676
  thus ?thesis by simp
huffman@20504
   677
qed
huffman@20504
   678
huffman@20504
   679
lemma norm_triangle_ineq2:
huffman@20584
   680
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   681
  shows "norm a - norm b \<le> norm (a - b)"
huffman@20504
   682
proof -
huffman@20533
   683
  have "norm (a - b + b) \<le> norm (a - b) + norm b"
huffman@20504
   684
    by (rule norm_triangle_ineq)
huffman@22898
   685
  thus ?thesis by simp
huffman@20504
   686
qed
huffman@20504
   687
huffman@20584
   688
lemma norm_triangle_ineq3:
huffman@20584
   689
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   690
  shows "\<bar>norm a - norm b\<bar> \<le> norm (a - b)"
huffman@20584
   691
apply (subst abs_le_iff)
huffman@20584
   692
apply auto
huffman@20584
   693
apply (rule norm_triangle_ineq2)
huffman@20584
   694
apply (subst norm_minus_commute)
huffman@20584
   695
apply (rule norm_triangle_ineq2)
huffman@20584
   696
done
huffman@20584
   697
huffman@20504
   698
lemma norm_triangle_ineq4:
huffman@20584
   699
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   700
  shows "norm (a - b) \<le> norm a + norm b"
huffman@20504
   701
proof -
huffman@22898
   702
  have "norm (a + - b) \<le> norm a + norm (- b)"
huffman@20504
   703
    by (rule norm_triangle_ineq)
huffman@22898
   704
  thus ?thesis
huffman@22898
   705
    by (simp only: diff_minus norm_minus_cancel)
huffman@22898
   706
qed
huffman@22898
   707
huffman@22898
   708
lemma norm_diff_ineq:
huffman@22898
   709
  fixes a b :: "'a::real_normed_vector"
huffman@22898
   710
  shows "norm a - norm b \<le> norm (a + b)"
huffman@22898
   711
proof -
huffman@22898
   712
  have "norm a - norm (- b) \<le> norm (a - - b)"
huffman@22898
   713
    by (rule norm_triangle_ineq2)
huffman@22898
   714
  thus ?thesis by simp
huffman@20504
   715
qed
huffman@20504
   716
huffman@20551
   717
lemma norm_diff_triangle_ineq:
huffman@20551
   718
  fixes a b c d :: "'a::real_normed_vector"
huffman@20551
   719
  shows "norm ((a + b) - (c + d)) \<le> norm (a - c) + norm (b - d)"
huffman@20551
   720
proof -
huffman@20551
   721
  have "norm ((a + b) - (c + d)) = norm ((a - c) + (b - d))"
huffman@20551
   722
    by (simp add: diff_minus add_ac)
huffman@20551
   723
  also have "\<dots> \<le> norm (a - c) + norm (b - d)"
huffman@20551
   724
    by (rule norm_triangle_ineq)
huffman@20551
   725
  finally show ?thesis .
huffman@20551
   726
qed
huffman@20551
   727
huffman@22857
   728
lemma abs_norm_cancel [simp]:
huffman@22857
   729
  fixes a :: "'a::real_normed_vector"
huffman@22857
   730
  shows "\<bar>norm a\<bar> = norm a"
huffman@22857
   731
by (rule abs_of_nonneg [OF norm_ge_zero])
huffman@22857
   732
huffman@22880
   733
lemma norm_add_less:
huffman@22880
   734
  fixes x y :: "'a::real_normed_vector"
huffman@22880
   735
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x + y) < r + s"
huffman@22880
   736
by (rule order_le_less_trans [OF norm_triangle_ineq add_strict_mono])
huffman@22880
   737
huffman@22880
   738
lemma norm_mult_less:
huffman@22880
   739
  fixes x y :: "'a::real_normed_algebra"
huffman@22880
   740
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x * y) < r * s"
huffman@22880
   741
apply (rule order_le_less_trans [OF norm_mult_ineq])
huffman@22880
   742
apply (simp add: mult_strict_mono')
huffman@22880
   743
done
huffman@22880
   744
huffman@22857
   745
lemma norm_of_real [simp]:
huffman@22857
   746
  "norm (of_real r :: 'a::real_normed_algebra_1) = \<bar>r\<bar>"
huffman@22852
   747
unfolding of_real_def by (simp add: norm_scaleR)
huffman@20560
   748
huffman@22876
   749
lemma norm_number_of [simp]:
huffman@22876
   750
  "norm (number_of w::'a::{number_ring,real_normed_algebra_1})
huffman@22876
   751
    = \<bar>number_of w\<bar>"
huffman@22876
   752
by (subst of_real_number_of_eq [symmetric], rule norm_of_real)
huffman@22876
   753
huffman@22876
   754
lemma norm_of_int [simp]:
huffman@22876
   755
  "norm (of_int z::'a::real_normed_algebra_1) = \<bar>of_int z\<bar>"
huffman@22876
   756
by (subst of_real_of_int_eq [symmetric], rule norm_of_real)
huffman@22876
   757
huffman@22876
   758
lemma norm_of_nat [simp]:
huffman@22876
   759
  "norm (of_nat n::'a::real_normed_algebra_1) = of_nat n"
huffman@22876
   760
apply (subst of_real_of_nat_eq [symmetric])
huffman@22876
   761
apply (subst norm_of_real, simp)
huffman@22876
   762
done
huffman@22876
   763
huffman@20504
   764
lemma nonzero_norm_inverse:
huffman@20504
   765
  fixes a :: "'a::real_normed_div_algebra"
huffman@20533
   766
  shows "a \<noteq> 0 \<Longrightarrow> norm (inverse a) = inverse (norm a)"
huffman@20504
   767
apply (rule inverse_unique [symmetric])
huffman@20504
   768
apply (simp add: norm_mult [symmetric])
huffman@20504
   769
done
huffman@20504
   770
huffman@20504
   771
lemma norm_inverse:
huffman@20504
   772
  fixes a :: "'a::{real_normed_div_algebra,division_by_zero}"
huffman@20533
   773
  shows "norm (inverse a) = inverse (norm a)"
huffman@20504
   774
apply (case_tac "a = 0", simp)
huffman@20504
   775
apply (erule nonzero_norm_inverse)
huffman@20504
   776
done
huffman@20504
   777
huffman@20584
   778
lemma nonzero_norm_divide:
huffman@20584
   779
  fixes a b :: "'a::real_normed_field"
huffman@20584
   780
  shows "b \<noteq> 0 \<Longrightarrow> norm (a / b) = norm a / norm b"
huffman@20584
   781
by (simp add: divide_inverse norm_mult nonzero_norm_inverse)
huffman@20584
   782
huffman@20584
   783
lemma norm_divide:
huffman@20584
   784
  fixes a b :: "'a::{real_normed_field,division_by_zero}"
huffman@20584
   785
  shows "norm (a / b) = norm a / norm b"
huffman@20584
   786
by (simp add: divide_inverse norm_mult norm_inverse)
huffman@20584
   787
huffman@22852
   788
lemma norm_power_ineq:
haftmann@31017
   789
  fixes x :: "'a::{real_normed_algebra_1}"
huffman@22852
   790
  shows "norm (x ^ n) \<le> norm x ^ n"
huffman@22852
   791
proof (induct n)
huffman@22852
   792
  case 0 show "norm (x ^ 0) \<le> norm x ^ 0" by simp
huffman@22852
   793
next
huffman@22852
   794
  case (Suc n)
huffman@22852
   795
  have "norm (x * x ^ n) \<le> norm x * norm (x ^ n)"
huffman@22852
   796
    by (rule norm_mult_ineq)
huffman@22852
   797
  also from Suc have "\<dots> \<le> norm x * norm x ^ n"
huffman@22852
   798
    using norm_ge_zero by (rule mult_left_mono)
huffman@22852
   799
  finally show "norm (x ^ Suc n) \<le> norm x ^ Suc n"
huffman@30273
   800
    by simp
huffman@22852
   801
qed
huffman@22852
   802
huffman@20684
   803
lemma norm_power:
haftmann@31017
   804
  fixes x :: "'a::{real_normed_div_algebra}"
huffman@20684
   805
  shows "norm (x ^ n) = norm x ^ n"
huffman@30273
   806
by (induct n) (simp_all add: norm_mult)
huffman@20684
   807
huffman@31289
   808
text {* Every normed vector space is a metric space. *}
huffman@31285
   809
huffman@31289
   810
instance real_normed_vector < metric_space
huffman@31289
   811
proof
huffman@31289
   812
  fix x y :: 'a show "dist x y = 0 \<longleftrightarrow> x = y"
huffman@31289
   813
    unfolding dist_norm by simp
huffman@31289
   814
next
huffman@31289
   815
  fix x y z :: 'a show "dist x y \<le> dist x z + dist y z"
huffman@31289
   816
    unfolding dist_norm
huffman@31289
   817
    using norm_triangle_ineq4 [of "x - z" "y - z"] by simp
huffman@31289
   818
qed
huffman@31285
   819
huffman@31446
   820
subsection {* Extra type constraints *}
huffman@31446
   821
huffman@31446
   822
text {* Only allow @{term dist} in class @{text metric_space}. *}
huffman@31446
   823
huffman@31446
   824
setup {* Sign.add_const_constraint
huffman@31446
   825
  (@{const_name dist}, SOME @{typ "'a::metric_space \<Rightarrow> 'a \<Rightarrow> real"}) *}
huffman@31446
   826
huffman@31446
   827
text {* Only allow @{term norm} in class @{text real_normed_vector}. *}
huffman@31446
   828
huffman@31446
   829
setup {* Sign.add_const_constraint
huffman@31446
   830
  (@{const_name norm}, SOME @{typ "'a::real_normed_vector \<Rightarrow> real"}) *}
huffman@31446
   831
huffman@31285
   832
huffman@22972
   833
subsection {* Sign function *}
huffman@22972
   834
nipkow@24506
   835
lemma norm_sgn:
nipkow@24506
   836
  "norm (sgn(x::'a::real_normed_vector)) = (if x = 0 then 0 else 1)"
nipkow@24506
   837
by (simp add: sgn_div_norm norm_scaleR)
huffman@22972
   838
nipkow@24506
   839
lemma sgn_zero [simp]: "sgn(0::'a::real_normed_vector) = 0"
nipkow@24506
   840
by (simp add: sgn_div_norm)
huffman@22972
   841
nipkow@24506
   842
lemma sgn_zero_iff: "(sgn(x::'a::real_normed_vector) = 0) = (x = 0)"
nipkow@24506
   843
by (simp add: sgn_div_norm)
huffman@22972
   844
nipkow@24506
   845
lemma sgn_minus: "sgn (- x) = - sgn(x::'a::real_normed_vector)"
nipkow@24506
   846
by (simp add: sgn_div_norm)
huffman@22972
   847
nipkow@24506
   848
lemma sgn_scaleR:
nipkow@24506
   849
  "sgn (scaleR r x) = scaleR (sgn r) (sgn(x::'a::real_normed_vector))"
nipkow@24506
   850
by (simp add: sgn_div_norm norm_scaleR mult_ac)
huffman@22973
   851
huffman@22972
   852
lemma sgn_one [simp]: "sgn (1::'a::real_normed_algebra_1) = 1"
nipkow@24506
   853
by (simp add: sgn_div_norm)
huffman@22972
   854
huffman@22972
   855
lemma sgn_of_real:
huffman@22972
   856
  "sgn (of_real r::'a::real_normed_algebra_1) = of_real (sgn r)"
huffman@22972
   857
unfolding of_real_def by (simp only: sgn_scaleR sgn_one)
huffman@22972
   858
huffman@22973
   859
lemma sgn_mult:
huffman@22973
   860
  fixes x y :: "'a::real_normed_div_algebra"
huffman@22973
   861
  shows "sgn (x * y) = sgn x * sgn y"
nipkow@24506
   862
by (simp add: sgn_div_norm norm_mult mult_commute)
huffman@22973
   863
huffman@22972
   864
lemma real_sgn_eq: "sgn (x::real) = x / \<bar>x\<bar>"
nipkow@24506
   865
by (simp add: sgn_div_norm divide_inverse)
huffman@22972
   866
huffman@22972
   867
lemma real_sgn_pos: "0 < (x::real) \<Longrightarrow> sgn x = 1"
huffman@22972
   868
unfolding real_sgn_eq by simp
huffman@22972
   869
huffman@22972
   870
lemma real_sgn_neg: "(x::real) < 0 \<Longrightarrow> sgn x = -1"
huffman@22972
   871
unfolding real_sgn_eq by simp
huffman@22972
   872
huffman@22972
   873
huffman@22442
   874
subsection {* Bounded Linear and Bilinear Operators *}
huffman@22442
   875
huffman@22442
   876
locale bounded_linear = additive +
huffman@22442
   877
  constrains f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
huffman@22442
   878
  assumes scaleR: "f (scaleR r x) = scaleR r (f x)"
huffman@22442
   879
  assumes bounded: "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K"
huffman@27443
   880
begin
huffman@22442
   881
huffman@27443
   882
lemma pos_bounded:
huffman@22442
   883
  "\<exists>K>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
   884
proof -
huffman@22442
   885
  obtain K where K: "\<And>x. norm (f x) \<le> norm x * K"
huffman@22442
   886
    using bounded by fast
huffman@22442
   887
  show ?thesis
huffman@22442
   888
  proof (intro exI impI conjI allI)
huffman@22442
   889
    show "0 < max 1 K"
huffman@22442
   890
      by (rule order_less_le_trans [OF zero_less_one le_maxI1])
huffman@22442
   891
  next
huffman@22442
   892
    fix x
huffman@22442
   893
    have "norm (f x) \<le> norm x * K" using K .
huffman@22442
   894
    also have "\<dots> \<le> norm x * max 1 K"
huffman@22442
   895
      by (rule mult_left_mono [OF le_maxI2 norm_ge_zero])
huffman@22442
   896
    finally show "norm (f x) \<le> norm x * max 1 K" .
huffman@22442
   897
  qed
huffman@22442
   898
qed
huffman@22442
   899
huffman@27443
   900
lemma nonneg_bounded:
huffman@22442
   901
  "\<exists>K\<ge>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
   902
proof -
huffman@22442
   903
  from pos_bounded
huffman@22442
   904
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
   905
qed
huffman@22442
   906
huffman@27443
   907
end
huffman@27443
   908
huffman@22442
   909
locale bounded_bilinear =
huffman@22442
   910
  fixes prod :: "['a::real_normed_vector, 'b::real_normed_vector]
huffman@22442
   911
                 \<Rightarrow> 'c::real_normed_vector"
huffman@22442
   912
    (infixl "**" 70)
huffman@22442
   913
  assumes add_left: "prod (a + a') b = prod a b + prod a' b"
huffman@22442
   914
  assumes add_right: "prod a (b + b') = prod a b + prod a b'"
huffman@22442
   915
  assumes scaleR_left: "prod (scaleR r a) b = scaleR r (prod a b)"
huffman@22442
   916
  assumes scaleR_right: "prod a (scaleR r b) = scaleR r (prod a b)"
huffman@22442
   917
  assumes bounded: "\<exists>K. \<forall>a b. norm (prod a b) \<le> norm a * norm b * K"
huffman@27443
   918
begin
huffman@22442
   919
huffman@27443
   920
lemma pos_bounded:
huffman@22442
   921
  "\<exists>K>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
   922
apply (cut_tac bounded, erule exE)
huffman@22442
   923
apply (rule_tac x="max 1 K" in exI, safe)
huffman@22442
   924
apply (rule order_less_le_trans [OF zero_less_one le_maxI1])
huffman@22442
   925
apply (drule spec, drule spec, erule order_trans)
huffman@22442
   926
apply (rule mult_left_mono [OF le_maxI2])
huffman@22442
   927
apply (intro mult_nonneg_nonneg norm_ge_zero)
huffman@22442
   928
done
huffman@22442
   929
huffman@27443
   930
lemma nonneg_bounded:
huffman@22442
   931
  "\<exists>K\<ge>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
   932
proof -
huffman@22442
   933
  from pos_bounded
huffman@22442
   934
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
   935
qed
huffman@22442
   936
huffman@27443
   937
lemma additive_right: "additive (\<lambda>b. prod a b)"
huffman@22442
   938
by (rule additive.intro, rule add_right)
huffman@22442
   939
huffman@27443
   940
lemma additive_left: "additive (\<lambda>a. prod a b)"
huffman@22442
   941
by (rule additive.intro, rule add_left)
huffman@22442
   942
huffman@27443
   943
lemma zero_left: "prod 0 b = 0"
huffman@22442
   944
by (rule additive.zero [OF additive_left])
huffman@22442
   945
huffman@27443
   946
lemma zero_right: "prod a 0 = 0"
huffman@22442
   947
by (rule additive.zero [OF additive_right])
huffman@22442
   948
huffman@27443
   949
lemma minus_left: "prod (- a) b = - prod a b"
huffman@22442
   950
by (rule additive.minus [OF additive_left])
huffman@22442
   951
huffman@27443
   952
lemma minus_right: "prod a (- b) = - prod a b"
huffman@22442
   953
by (rule additive.minus [OF additive_right])
huffman@22442
   954
huffman@27443
   955
lemma diff_left:
huffman@22442
   956
  "prod (a - a') b = prod a b - prod a' b"
huffman@22442
   957
by (rule additive.diff [OF additive_left])
huffman@22442
   958
huffman@27443
   959
lemma diff_right:
huffman@22442
   960
  "prod a (b - b') = prod a b - prod a b'"
huffman@22442
   961
by (rule additive.diff [OF additive_right])
huffman@22442
   962
huffman@27443
   963
lemma bounded_linear_left:
huffman@22442
   964
  "bounded_linear (\<lambda>a. a ** b)"
huffman@22442
   965
apply (unfold_locales)
huffman@22442
   966
apply (rule add_left)
huffman@22442
   967
apply (rule scaleR_left)
huffman@22442
   968
apply (cut_tac bounded, safe)
huffman@22442
   969
apply (rule_tac x="norm b * K" in exI)
huffman@22442
   970
apply (simp add: mult_ac)
huffman@22442
   971
done
huffman@22442
   972
huffman@27443
   973
lemma bounded_linear_right:
huffman@22442
   974
  "bounded_linear (\<lambda>b. a ** b)"
huffman@22442
   975
apply (unfold_locales)
huffman@22442
   976
apply (rule add_right)
huffman@22442
   977
apply (rule scaleR_right)
huffman@22442
   978
apply (cut_tac bounded, safe)
huffman@22442
   979
apply (rule_tac x="norm a * K" in exI)
huffman@22442
   980
apply (simp add: mult_ac)
huffman@22442
   981
done
huffman@22442
   982
huffman@27443
   983
lemma prod_diff_prod:
huffman@22442
   984
  "(x ** y - a ** b) = (x - a) ** (y - b) + (x - a) ** b + a ** (y - b)"
huffman@22442
   985
by (simp add: diff_left diff_right)
huffman@22442
   986
huffman@27443
   987
end
huffman@27443
   988
wenzelm@30729
   989
interpretation mult:
ballarin@29229
   990
  bounded_bilinear "op * :: 'a \<Rightarrow> 'a \<Rightarrow> 'a::real_normed_algebra"
huffman@22442
   991
apply (rule bounded_bilinear.intro)
huffman@22442
   992
apply (rule left_distrib)
huffman@22442
   993
apply (rule right_distrib)
huffman@22442
   994
apply (rule mult_scaleR_left)
huffman@22442
   995
apply (rule mult_scaleR_right)
huffman@22442
   996
apply (rule_tac x="1" in exI)
huffman@22442
   997
apply (simp add: norm_mult_ineq)
huffman@22442
   998
done
huffman@22442
   999
wenzelm@30729
  1000
interpretation mult_left:
ballarin@29229
  1001
  bounded_linear "(\<lambda>x::'a::real_normed_algebra. x * y)"
huffman@23127
  1002
by (rule mult.bounded_linear_left)
huffman@22442
  1003
wenzelm@30729
  1004
interpretation mult_right:
ballarin@29229
  1005
  bounded_linear "(\<lambda>y::'a::real_normed_algebra. x * y)"
huffman@23127
  1006
by (rule mult.bounded_linear_right)
huffman@23127
  1007
wenzelm@30729
  1008
interpretation divide:
ballarin@29229
  1009
  bounded_linear "(\<lambda>x::'a::real_normed_field. x / y)"
huffman@23127
  1010
unfolding divide_inverse by (rule mult.bounded_linear_left)
huffman@23120
  1011
wenzelm@30729
  1012
interpretation scaleR: bounded_bilinear "scaleR"
huffman@22442
  1013
apply (rule bounded_bilinear.intro)
huffman@22442
  1014
apply (rule scaleR_left_distrib)
huffman@22442
  1015
apply (rule scaleR_right_distrib)
huffman@22973
  1016
apply simp
huffman@22442
  1017
apply (rule scaleR_left_commute)
huffman@22442
  1018
apply (rule_tac x="1" in exI)
huffman@22442
  1019
apply (simp add: norm_scaleR)
huffman@22442
  1020
done
huffman@22442
  1021
wenzelm@30729
  1022
interpretation scaleR_left: bounded_linear "\<lambda>r. scaleR r x"
huffman@23127
  1023
by (rule scaleR.bounded_linear_left)
huffman@23127
  1024
wenzelm@30729
  1025
interpretation scaleR_right: bounded_linear "\<lambda>x. scaleR r x"
huffman@23127
  1026
by (rule scaleR.bounded_linear_right)
huffman@23127
  1027
wenzelm@30729
  1028
interpretation of_real: bounded_linear "\<lambda>r. of_real r"
huffman@23127
  1029
unfolding of_real_def by (rule scaleR.bounded_linear_left)
huffman@22625
  1030
huffman@20504
  1031
end