src/HOL/Real/RealVector.thy
author huffman
Tue Aug 26 23:49:46 2008 +0200 (2008-08-26)
changeset 28009 e93b121074fb
parent 27553 d315a513a150
child 28029 4c55cdec4ce7
permissions -rw-r--r--
move real_vector class proofs into vector_space and group_hom locales
haftmann@27552
     1
(*  Title:      RealVector.thy
huffman@20504
     2
    ID:         $Id$
haftmann@27552
     3
    Author:     Brian Huffman
huffman@20504
     4
*)
huffman@20504
     5
huffman@20504
     6
header {* Vector Spaces and Algebras over the Reals *}
huffman@20504
     7
huffman@20504
     8
theory RealVector
huffman@20684
     9
imports RealPow
huffman@20504
    10
begin
huffman@20504
    11
huffman@28009
    12
subsection {* Group homomorphisms *}
huffman@28009
    13
huffman@28009
    14
locale group_hom =
huffman@28009
    15
  ab_group_add
huffman@28009
    16
    mA (infixl "-\<^sub>A" 65)
huffman@28009
    17
    uA ("-\<^sub>A _" [81] 80)
huffman@28009
    18
    zA ("0\<^sub>A")
huffman@28009
    19
    pA (infixl "+\<^sub>A" 65) +
huffman@28009
    20
  ab_group_add
huffman@28009
    21
    mB (infixl "-\<^sub>B" 65)
huffman@28009
    22
    uB ("-\<^sub>B _" [81] 80)
huffman@28009
    23
    zB ("0\<^sub>B")
huffman@28009
    24
    pB (infixl "+\<^sub>B" 65) +
huffman@28009
    25
  fixes f :: "'a \<Rightarrow> 'b"
huffman@28009
    26
  assumes plus: "f (x +\<^sub>A y) = f x +\<^sub>B f y"
huffman@28009
    27
begin
huffman@28009
    28
huffman@28009
    29
lemma zero: "f 0\<^sub>A = 0\<^sub>B"
huffman@28009
    30
proof -
huffman@28009
    31
  have "f 0\<^sub>A +\<^sub>B f 0\<^sub>A = f (0\<^sub>A +\<^sub>A 0\<^sub>A)" by (rule plus [symmetric])
huffman@28009
    32
  also have "f (0\<^sub>A +\<^sub>A 0\<^sub>A) = 0\<^sub>B +\<^sub>B f 0\<^sub>A" by simp
huffman@28009
    33
  finally show "f 0\<^sub>A = 0\<^sub>B" by (rule pB.add_right_imp_eq)
huffman@28009
    34
qed
huffman@28009
    35
huffman@28009
    36
lemma uminus: "f (-\<^sub>A x) = -\<^sub>B f x"
huffman@28009
    37
proof -
huffman@28009
    38
  have "f (-\<^sub>A x) +\<^sub>B f x = f (-\<^sub>A x +\<^sub>A x)" by (rule plus [symmetric])
huffman@28009
    39
  also have "\<dots> = -\<^sub>B f x +\<^sub>B f x" by (simp add: zero)
huffman@28009
    40
  finally show "f (-\<^sub>A x) = -\<^sub>B f x" by (rule pB.add_right_imp_eq)
huffman@28009
    41
qed
huffman@28009
    42
huffman@28009
    43
lemma diff: "f (x -\<^sub>A y) = f x -\<^sub>B f y"
huffman@28009
    44
by (simp add: mA_uA_zA_pA.diff_minus mB_uB_zB_pB.diff_minus plus uminus)
huffman@28009
    45
huffman@28009
    46
text {* TODO:
huffman@28009
    47
Locale-ize definition of setsum, so we can prove a lemma for it *}
huffman@28009
    48
huffman@28009
    49
end
huffman@28009
    50
huffman@28009
    51
subsection {* Vector spaces *}
huffman@28009
    52
huffman@28009
    53
locale vector_space =
huffman@28009
    54
  field
huffman@28009
    55
    inverse
huffman@28009
    56
    divide (infixl "'/\<^sub>F" 70)
huffman@28009
    57
    one ("1\<^sub>F")
huffman@28009
    58
    times (infixl "*\<^sub>F" 70)
huffman@28009
    59
    mF (infixl "-\<^sub>F" 65)
huffman@28009
    60
    uF ("-\<^sub>F _" [81] 80)
huffman@28009
    61
    zF ("0\<^sub>F")
huffman@28009
    62
    pF (infixl "+\<^sub>F" 65) +
huffman@28009
    63
  ab_group_add
huffman@28009
    64
    mV (infixl "-\<^sub>V" 65)
huffman@28009
    65
    uV ("-\<^sub>V _" [81] 80)
huffman@28009
    66
    zV ("0\<^sub>V")
huffman@28009
    67
    pV (infixl "+\<^sub>V" 65) +
huffman@28009
    68
  fixes scale :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" (infixr "%*" 75)
huffman@28009
    69
  assumes scale_right_distrib: "scale a (x +\<^sub>V y) = scale a x +\<^sub>V scale a y"
huffman@28009
    70
  and scale_left_distrib: "scale (a +\<^sub>F b) x = scale a x +\<^sub>V scale b x"
huffman@28009
    71
  and scale_scale [simp]: "scale a (scale b x) = scale (a *\<^sub>F b) x"
huffman@28009
    72
  and scale_one [simp]: "scale 1\<^sub>F x = x"
huffman@28009
    73
begin
huffman@28009
    74
huffman@28009
    75
lemma scale_left_commute:
huffman@28009
    76
  "scale a (scale b x) = scale b (scale a x)"
huffman@28009
    77
by (simp add: mult_commute)
huffman@28009
    78
huffman@28009
    79
lemma scale_zero_left [simp]: "scale 0\<^sub>F x = 0\<^sub>V"
huffman@28009
    80
  and scale_minus_left [simp]: "scale (-\<^sub>F a) x = -\<^sub>V (scale a x)"
huffman@28009
    81
  and scale_left_diff_distrib: "scale (a -\<^sub>F b) x = scale a x -\<^sub>V scale b x"
huffman@28009
    82
proof -
huffman@28009
    83
  interpret s: group_hom
huffman@28009
    84
    [mF uF zF pF mV uV zV pV "\<lambda>a. scale a x"]
huffman@28009
    85
    by unfold_locales (rule scale_left_distrib)
huffman@28009
    86
  show "scale 0\<^sub>F x = 0\<^sub>V" by (rule s.zero)
huffman@28009
    87
  show "scale (-\<^sub>F a) x = -\<^sub>V (scale a x)" by (rule s.uminus)
huffman@28009
    88
  show "scale (a -\<^sub>F b) x = scale a x -\<^sub>V scale b x" by (rule s.diff)
huffman@28009
    89
qed
huffman@28009
    90
huffman@28009
    91
lemma scale_zero_right [simp]: "scale a 0\<^sub>V = 0\<^sub>V"
huffman@28009
    92
  and scale_minus_right [simp]: "scale a (-\<^sub>V x) = -\<^sub>V (scale a x)"
huffman@28009
    93
  and scale_right_diff_distrib: "scale a (x -\<^sub>V y) = scale a x -\<^sub>V scale a y"
huffman@28009
    94
proof -
huffman@28009
    95
  interpret s: group_hom
huffman@28009
    96
    [mV uV zV pV mV uV zV pV "\<lambda>x. scale a x"]
huffman@28009
    97
    by unfold_locales (rule scale_right_distrib)
huffman@28009
    98
  show "scale a 0\<^sub>V = 0\<^sub>V" by (rule s.zero)
huffman@28009
    99
  show "scale a (-\<^sub>V x) = -\<^sub>V (scale a x)" by (rule s.uminus)
huffman@28009
   100
  show "scale a (x -\<^sub>V y) = scale a x -\<^sub>V scale a y" by (rule s.diff)
huffman@28009
   101
qed
huffman@28009
   102
huffman@28009
   103
lemma scale_eq_0_iff [simp]:
huffman@28009
   104
  "scale a x = 0\<^sub>V \<longleftrightarrow> a = 0\<^sub>F \<or> x = 0\<^sub>V"
huffman@28009
   105
proof cases
huffman@28009
   106
  assume "a = 0\<^sub>F" thus ?thesis by simp
huffman@28009
   107
next
huffman@28009
   108
  assume anz [simp]: "a \<noteq> 0\<^sub>F"
huffman@28009
   109
  { assume "scale a x = 0\<^sub>V"
huffman@28009
   110
    hence "scale (inverse a) (scale a x) = 0\<^sub>V" by simp
huffman@28009
   111
    hence "x = 0\<^sub>V" by simp }
huffman@28009
   112
  thus ?thesis by force
huffman@28009
   113
qed
huffman@28009
   114
huffman@28009
   115
lemma scale_left_imp_eq:
huffman@28009
   116
  "\<lbrakk>a \<noteq> 0\<^sub>F; scale a x = scale a y\<rbrakk> \<Longrightarrow> x = y"
huffman@28009
   117
proof -
huffman@28009
   118
  assume nonzero: "a \<noteq> 0\<^sub>F"
huffman@28009
   119
  assume "scale a x = scale a y"
huffman@28009
   120
  hence "scale a (x -\<^sub>V y) = 0\<^sub>V"
huffman@28009
   121
     by (simp add: scale_right_diff_distrib)
huffman@28009
   122
  hence "x -\<^sub>V y = 0\<^sub>V" by (simp add: nonzero)
huffman@28009
   123
  thus "x = y" by (simp only: mV_uV_zV_pV.right_minus_eq)
huffman@28009
   124
qed
huffman@28009
   125
huffman@28009
   126
lemma scale_right_imp_eq:
huffman@28009
   127
  "\<lbrakk>x \<noteq> 0\<^sub>V; scale a x = scale b x\<rbrakk> \<Longrightarrow> a = b"
huffman@28009
   128
proof -
huffman@28009
   129
  assume nonzero: "x \<noteq> 0\<^sub>V"
huffman@28009
   130
  assume "scale a x = scale b x"
huffman@28009
   131
  hence "scale (a -\<^sub>F b) x = 0\<^sub>V"
huffman@28009
   132
     by (simp add: scale_left_diff_distrib)
huffman@28009
   133
  hence "a -\<^sub>F b = 0\<^sub>F" by (simp add: nonzero)
huffman@28009
   134
  thus "a = b" by (simp only: mF_uF_zF_pF.right_minus_eq)
huffman@28009
   135
qed
huffman@28009
   136
huffman@28009
   137
lemma scale_cancel_left:
huffman@28009
   138
  "scale a x = scale a y \<longleftrightarrow> x = y \<or> a = 0\<^sub>F"
huffman@28009
   139
by (auto intro: scale_left_imp_eq)
huffman@28009
   140
huffman@28009
   141
lemma scale_cancel_right:
huffman@28009
   142
  "scale a x = scale b x \<longleftrightarrow> a = b \<or> x = 0\<^sub>V"
huffman@28009
   143
by (auto intro: scale_right_imp_eq)
huffman@28009
   144
huffman@28009
   145
end
huffman@28009
   146
huffman@28009
   147
(* TODO: locale additive is superseded by group_hom; remove *)
huffman@20504
   148
subsection {* Locale for additive functions *}
huffman@20504
   149
huffman@20504
   150
locale additive =
huffman@20504
   151
  fixes f :: "'a::ab_group_add \<Rightarrow> 'b::ab_group_add"
huffman@20504
   152
  assumes add: "f (x + y) = f x + f y"
huffman@27443
   153
begin
huffman@20504
   154
huffman@27443
   155
lemma zero: "f 0 = 0"
huffman@20504
   156
proof -
huffman@20504
   157
  have "f 0 = f (0 + 0)" by simp
huffman@20504
   158
  also have "\<dots> = f 0 + f 0" by (rule add)
huffman@20504
   159
  finally show "f 0 = 0" by simp
huffman@20504
   160
qed
huffman@20504
   161
huffman@27443
   162
lemma minus: "f (- x) = - f x"
huffman@20504
   163
proof -
huffman@20504
   164
  have "f (- x) + f x = f (- x + x)" by (rule add [symmetric])
huffman@20504
   165
  also have "\<dots> = - f x + f x" by (simp add: zero)
huffman@20504
   166
  finally show "f (- x) = - f x" by (rule add_right_imp_eq)
huffman@20504
   167
qed
huffman@20504
   168
huffman@27443
   169
lemma diff: "f (x - y) = f x - f y"
huffman@20504
   170
by (simp add: diff_def add minus)
huffman@20504
   171
huffman@27443
   172
lemma setsum: "f (setsum g A) = (\<Sum>x\<in>A. f (g x))"
huffman@22942
   173
apply (cases "finite A")
huffman@22942
   174
apply (induct set: finite)
huffman@22942
   175
apply (simp add: zero)
huffman@22942
   176
apply (simp add: add)
huffman@22942
   177
apply (simp add: zero)
huffman@22942
   178
done
huffman@22942
   179
huffman@27443
   180
end
huffman@20504
   181
huffman@20504
   182
subsection {* Real vector spaces *}
huffman@20504
   183
huffman@22636
   184
class scaleR = type +
haftmann@25062
   185
  fixes scaleR :: "real \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "*\<^sub>R" 75)
haftmann@24748
   186
begin
huffman@20504
   187
huffman@20763
   188
abbreviation
haftmann@25062
   189
  divideR :: "'a \<Rightarrow> real \<Rightarrow> 'a" (infixl "'/\<^sub>R" 70)
haftmann@24748
   190
where
haftmann@25062
   191
  "x /\<^sub>R r == scaleR (inverse r) x"
haftmann@24748
   192
haftmann@24748
   193
end
haftmann@24748
   194
haftmann@25571
   195
instantiation real :: scaleR
haftmann@25571
   196
begin
haftmann@25571
   197
haftmann@25571
   198
definition
haftmann@25571
   199
  real_scaleR_def [simp]: "scaleR a x = a * x"
haftmann@25571
   200
haftmann@25571
   201
instance ..
haftmann@25571
   202
haftmann@25571
   203
end
huffman@20554
   204
haftmann@24588
   205
class real_vector = scaleR + ab_group_add +
haftmann@25062
   206
  assumes scaleR_right_distrib: "scaleR a (x + y) = scaleR a x + scaleR a y"
haftmann@25062
   207
  and scaleR_left_distrib: "scaleR (a + b) x = scaleR a x + scaleR b x"
haftmann@24588
   208
  and scaleR_scaleR [simp]: "scaleR a (scaleR b x) = scaleR (a * b) x"
haftmann@24588
   209
  and scaleR_one [simp]: "scaleR 1 x = x"
huffman@20504
   210
huffman@28009
   211
interpretation real_vector: vector_space
huffman@28009
   212
  [inverse divide "1" times minus uminus "0" plus
huffman@28009
   213
   minus uminus "0" plus "scaleR::real \<Rightarrow> 'a \<Rightarrow> 'a::real_vector"]
huffman@28009
   214
apply unfold_locales
huffman@28009
   215
apply (rule scaleR_right_distrib)
huffman@28009
   216
apply (rule scaleR_left_distrib)
huffman@28009
   217
apply (rule scaleR_scaleR)
huffman@28009
   218
apply (rule scaleR_one)
huffman@28009
   219
done
huffman@28009
   220
huffman@28009
   221
text {* Recover original theorem names *}
huffman@28009
   222
huffman@28009
   223
lemmas scaleR_left_commute = real_vector.scale_left_commute
huffman@28009
   224
lemmas scaleR_zero_left = real_vector.scale_zero_left
huffman@28009
   225
lemmas scaleR_minus_left = real_vector.scale_minus_left
huffman@28009
   226
lemmas scaleR_left_diff_distrib = real_vector.scale_left_diff_distrib
huffman@28009
   227
lemmas scaleR_zero_right = real_vector.scale_zero_right
huffman@28009
   228
lemmas scaleR_minus_right = real_vector.scale_minus_right
huffman@28009
   229
lemmas scaleR_right_diff_distrib = real_vector.scale_right_diff_distrib
huffman@28009
   230
lemmas scaleR_eq_0_iff = real_vector.scale_eq_0_iff
huffman@28009
   231
lemmas scaleR_left_imp_eq = real_vector.scale_left_imp_eq
huffman@28009
   232
lemmas scaleR_right_imp_eq = real_vector.scale_right_imp_eq
huffman@28009
   233
lemmas scaleR_cancel_left = real_vector.scale_cancel_left
huffman@28009
   234
lemmas scaleR_cancel_right = real_vector.scale_cancel_right
huffman@28009
   235
haftmann@24588
   236
class real_algebra = real_vector + ring +
haftmann@25062
   237
  assumes mult_scaleR_left [simp]: "scaleR a x * y = scaleR a (x * y)"
haftmann@25062
   238
  and mult_scaleR_right [simp]: "x * scaleR a y = scaleR a (x * y)"
huffman@20504
   239
haftmann@24588
   240
class real_algebra_1 = real_algebra + ring_1
huffman@20554
   241
haftmann@24588
   242
class real_div_algebra = real_algebra_1 + division_ring
huffman@20584
   243
haftmann@24588
   244
class real_field = real_div_algebra + field
huffman@20584
   245
huffman@20584
   246
instance real :: real_field
huffman@20554
   247
apply (intro_classes, unfold real_scaleR_def)
huffman@20554
   248
apply (rule right_distrib)
huffman@20554
   249
apply (rule left_distrib)
huffman@20763
   250
apply (rule mult_assoc [symmetric])
huffman@20554
   251
apply (rule mult_1_left)
huffman@20554
   252
apply (rule mult_assoc)
huffman@20554
   253
apply (rule mult_left_commute)
huffman@20554
   254
done
huffman@20554
   255
huffman@23127
   256
interpretation scaleR_left: additive ["(\<lambda>a. scaleR a x::'a::real_vector)"]
huffman@23127
   257
by unfold_locales (rule scaleR_left_distrib)
huffman@20504
   258
huffman@23127
   259
interpretation scaleR_right: additive ["(\<lambda>x. scaleR a x::'a::real_vector)"]
huffman@23127
   260
by unfold_locales (rule scaleR_right_distrib)
huffman@20504
   261
huffman@20584
   262
lemma nonzero_inverse_scaleR_distrib:
huffman@21809
   263
  fixes x :: "'a::real_div_algebra" shows
huffman@21809
   264
  "\<lbrakk>a \<noteq> 0; x \<noteq> 0\<rbrakk> \<Longrightarrow> inverse (scaleR a x) = scaleR (inverse a) (inverse x)"
huffman@20763
   265
by (rule inverse_unique, simp)
huffman@20584
   266
huffman@20584
   267
lemma inverse_scaleR_distrib:
huffman@20584
   268
  fixes x :: "'a::{real_div_algebra,division_by_zero}"
huffman@21809
   269
  shows "inverse (scaleR a x) = scaleR (inverse a) (inverse x)"
huffman@20584
   270
apply (case_tac "a = 0", simp)
huffman@20584
   271
apply (case_tac "x = 0", simp)
huffman@20584
   272
apply (erule (1) nonzero_inverse_scaleR_distrib)
huffman@20584
   273
done
huffman@20584
   274
huffman@20554
   275
huffman@20554
   276
subsection {* Embedding of the Reals into any @{text real_algebra_1}:
huffman@20554
   277
@{term of_real} *}
huffman@20554
   278
huffman@20554
   279
definition
wenzelm@21404
   280
  of_real :: "real \<Rightarrow> 'a::real_algebra_1" where
huffman@21809
   281
  "of_real r = scaleR r 1"
huffman@20554
   282
huffman@21809
   283
lemma scaleR_conv_of_real: "scaleR r x = of_real r * x"
huffman@20763
   284
by (simp add: of_real_def)
huffman@20763
   285
huffman@20554
   286
lemma of_real_0 [simp]: "of_real 0 = 0"
huffman@20554
   287
by (simp add: of_real_def)
huffman@20554
   288
huffman@20554
   289
lemma of_real_1 [simp]: "of_real 1 = 1"
huffman@20554
   290
by (simp add: of_real_def)
huffman@20554
   291
huffman@20554
   292
lemma of_real_add [simp]: "of_real (x + y) = of_real x + of_real y"
huffman@20554
   293
by (simp add: of_real_def scaleR_left_distrib)
huffman@20554
   294
huffman@20554
   295
lemma of_real_minus [simp]: "of_real (- x) = - of_real x"
huffman@20554
   296
by (simp add: of_real_def)
huffman@20554
   297
huffman@20554
   298
lemma of_real_diff [simp]: "of_real (x - y) = of_real x - of_real y"
huffman@20554
   299
by (simp add: of_real_def scaleR_left_diff_distrib)
huffman@20554
   300
huffman@20554
   301
lemma of_real_mult [simp]: "of_real (x * y) = of_real x * of_real y"
huffman@20763
   302
by (simp add: of_real_def mult_commute)
huffman@20554
   303
huffman@20584
   304
lemma nonzero_of_real_inverse:
huffman@20584
   305
  "x \<noteq> 0 \<Longrightarrow> of_real (inverse x) =
huffman@20584
   306
   inverse (of_real x :: 'a::real_div_algebra)"
huffman@20584
   307
by (simp add: of_real_def nonzero_inverse_scaleR_distrib)
huffman@20584
   308
huffman@20584
   309
lemma of_real_inverse [simp]:
huffman@20584
   310
  "of_real (inverse x) =
huffman@20584
   311
   inverse (of_real x :: 'a::{real_div_algebra,division_by_zero})"
huffman@20584
   312
by (simp add: of_real_def inverse_scaleR_distrib)
huffman@20584
   313
huffman@20584
   314
lemma nonzero_of_real_divide:
huffman@20584
   315
  "y \<noteq> 0 \<Longrightarrow> of_real (x / y) =
huffman@20584
   316
   (of_real x / of_real y :: 'a::real_field)"
huffman@20584
   317
by (simp add: divide_inverse nonzero_of_real_inverse)
huffman@20722
   318
huffman@20722
   319
lemma of_real_divide [simp]:
huffman@20584
   320
  "of_real (x / y) =
huffman@20584
   321
   (of_real x / of_real y :: 'a::{real_field,division_by_zero})"
huffman@20584
   322
by (simp add: divide_inverse)
huffman@20584
   323
huffman@20722
   324
lemma of_real_power [simp]:
huffman@20722
   325
  "of_real (x ^ n) = (of_real x :: 'a::{real_algebra_1,recpower}) ^ n"
wenzelm@20772
   326
by (induct n) (simp_all add: power_Suc)
huffman@20722
   327
huffman@20554
   328
lemma of_real_eq_iff [simp]: "(of_real x = of_real y) = (x = y)"
huffman@20554
   329
by (simp add: of_real_def scaleR_cancel_right)
huffman@20554
   330
huffman@20584
   331
lemmas of_real_eq_0_iff [simp] = of_real_eq_iff [of _ 0, simplified]
huffman@20554
   332
huffman@20554
   333
lemma of_real_eq_id [simp]: "of_real = (id :: real \<Rightarrow> real)"
huffman@20554
   334
proof
huffman@20554
   335
  fix r
huffman@20554
   336
  show "of_real r = id r"
huffman@22973
   337
    by (simp add: of_real_def)
huffman@20554
   338
qed
huffman@20554
   339
huffman@20554
   340
text{*Collapse nested embeddings*}
huffman@20554
   341
lemma of_real_of_nat_eq [simp]: "of_real (of_nat n) = of_nat n"
wenzelm@20772
   342
by (induct n) auto
huffman@20554
   343
huffman@20554
   344
lemma of_real_of_int_eq [simp]: "of_real (of_int z) = of_int z"
huffman@20554
   345
by (cases z rule: int_diff_cases, simp)
huffman@20554
   346
huffman@20554
   347
lemma of_real_number_of_eq:
huffman@20554
   348
  "of_real (number_of w) = (number_of w :: 'a::{number_ring,real_algebra_1})"
huffman@20554
   349
by (simp add: number_of_eq)
huffman@20554
   350
huffman@22912
   351
text{*Every real algebra has characteristic zero*}
huffman@22912
   352
instance real_algebra_1 < ring_char_0
huffman@22912
   353
proof
huffman@23282
   354
  fix m n :: nat
huffman@23282
   355
  have "(of_real (of_nat m) = (of_real (of_nat n)::'a)) = (m = n)"
huffman@23282
   356
    by (simp only: of_real_eq_iff of_nat_eq_iff)
huffman@23282
   357
  thus "(of_nat m = (of_nat n::'a)) = (m = n)"
huffman@23282
   358
    by (simp only: of_real_of_nat_eq)
huffman@22912
   359
qed
huffman@22912
   360
huffman@27553
   361
instance real_field < field_char_0 ..
huffman@27553
   362
huffman@20554
   363
huffman@20554
   364
subsection {* The Set of Real Numbers *}
huffman@20554
   365
wenzelm@20772
   366
definition
wenzelm@21404
   367
  Reals :: "'a::real_algebra_1 set" where
haftmann@27435
   368
  [code func del]: "Reals \<equiv> range of_real"
huffman@20554
   369
wenzelm@21210
   370
notation (xsymbols)
huffman@20554
   371
  Reals  ("\<real>")
huffman@20554
   372
huffman@21809
   373
lemma Reals_of_real [simp]: "of_real r \<in> Reals"
huffman@20554
   374
by (simp add: Reals_def)
huffman@20554
   375
huffman@21809
   376
lemma Reals_of_int [simp]: "of_int z \<in> Reals"
huffman@21809
   377
by (subst of_real_of_int_eq [symmetric], rule Reals_of_real)
huffman@20718
   378
huffman@21809
   379
lemma Reals_of_nat [simp]: "of_nat n \<in> Reals"
huffman@21809
   380
by (subst of_real_of_nat_eq [symmetric], rule Reals_of_real)
huffman@21809
   381
huffman@21809
   382
lemma Reals_number_of [simp]:
huffman@21809
   383
  "(number_of w::'a::{number_ring,real_algebra_1}) \<in> Reals"
huffman@21809
   384
by (subst of_real_number_of_eq [symmetric], rule Reals_of_real)
huffman@20718
   385
huffman@20554
   386
lemma Reals_0 [simp]: "0 \<in> Reals"
huffman@20554
   387
apply (unfold Reals_def)
huffman@20554
   388
apply (rule range_eqI)
huffman@20554
   389
apply (rule of_real_0 [symmetric])
huffman@20554
   390
done
huffman@20554
   391
huffman@20554
   392
lemma Reals_1 [simp]: "1 \<in> Reals"
huffman@20554
   393
apply (unfold Reals_def)
huffman@20554
   394
apply (rule range_eqI)
huffman@20554
   395
apply (rule of_real_1 [symmetric])
huffman@20554
   396
done
huffman@20554
   397
huffman@20584
   398
lemma Reals_add [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a + b \<in> Reals"
huffman@20554
   399
apply (auto simp add: Reals_def)
huffman@20554
   400
apply (rule range_eqI)
huffman@20554
   401
apply (rule of_real_add [symmetric])
huffman@20554
   402
done
huffman@20554
   403
huffman@20584
   404
lemma Reals_minus [simp]: "a \<in> Reals \<Longrightarrow> - a \<in> Reals"
huffman@20584
   405
apply (auto simp add: Reals_def)
huffman@20584
   406
apply (rule range_eqI)
huffman@20584
   407
apply (rule of_real_minus [symmetric])
huffman@20584
   408
done
huffman@20584
   409
huffman@20584
   410
lemma Reals_diff [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a - b \<in> Reals"
huffman@20584
   411
apply (auto simp add: Reals_def)
huffman@20584
   412
apply (rule range_eqI)
huffman@20584
   413
apply (rule of_real_diff [symmetric])
huffman@20584
   414
done
huffman@20584
   415
huffman@20584
   416
lemma Reals_mult [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a * b \<in> Reals"
huffman@20554
   417
apply (auto simp add: Reals_def)
huffman@20554
   418
apply (rule range_eqI)
huffman@20554
   419
apply (rule of_real_mult [symmetric])
huffman@20554
   420
done
huffman@20554
   421
huffman@20584
   422
lemma nonzero_Reals_inverse:
huffman@20584
   423
  fixes a :: "'a::real_div_algebra"
huffman@20584
   424
  shows "\<lbrakk>a \<in> Reals; a \<noteq> 0\<rbrakk> \<Longrightarrow> inverse a \<in> Reals"
huffman@20584
   425
apply (auto simp add: Reals_def)
huffman@20584
   426
apply (rule range_eqI)
huffman@20584
   427
apply (erule nonzero_of_real_inverse [symmetric])
huffman@20584
   428
done
huffman@20584
   429
huffman@20584
   430
lemma Reals_inverse [simp]:
huffman@20584
   431
  fixes a :: "'a::{real_div_algebra,division_by_zero}"
huffman@20584
   432
  shows "a \<in> Reals \<Longrightarrow> inverse a \<in> Reals"
huffman@20584
   433
apply (auto simp add: Reals_def)
huffman@20584
   434
apply (rule range_eqI)
huffman@20584
   435
apply (rule of_real_inverse [symmetric])
huffman@20584
   436
done
huffman@20584
   437
huffman@20584
   438
lemma nonzero_Reals_divide:
huffman@20584
   439
  fixes a b :: "'a::real_field"
huffman@20584
   440
  shows "\<lbrakk>a \<in> Reals; b \<in> Reals; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584
   441
apply (auto simp add: Reals_def)
huffman@20584
   442
apply (rule range_eqI)
huffman@20584
   443
apply (erule nonzero_of_real_divide [symmetric])
huffman@20584
   444
done
huffman@20584
   445
huffman@20584
   446
lemma Reals_divide [simp]:
huffman@20584
   447
  fixes a b :: "'a::{real_field,division_by_zero}"
huffman@20584
   448
  shows "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584
   449
apply (auto simp add: Reals_def)
huffman@20584
   450
apply (rule range_eqI)
huffman@20584
   451
apply (rule of_real_divide [symmetric])
huffman@20584
   452
done
huffman@20584
   453
huffman@20722
   454
lemma Reals_power [simp]:
huffman@20722
   455
  fixes a :: "'a::{real_algebra_1,recpower}"
huffman@20722
   456
  shows "a \<in> Reals \<Longrightarrow> a ^ n \<in> Reals"
huffman@20722
   457
apply (auto simp add: Reals_def)
huffman@20722
   458
apply (rule range_eqI)
huffman@20722
   459
apply (rule of_real_power [symmetric])
huffman@20722
   460
done
huffman@20722
   461
huffman@20554
   462
lemma Reals_cases [cases set: Reals]:
huffman@20554
   463
  assumes "q \<in> \<real>"
huffman@20554
   464
  obtains (of_real) r where "q = of_real r"
huffman@20554
   465
  unfolding Reals_def
huffman@20554
   466
proof -
huffman@20554
   467
  from `q \<in> \<real>` have "q \<in> range of_real" unfolding Reals_def .
huffman@20554
   468
  then obtain r where "q = of_real r" ..
huffman@20554
   469
  then show thesis ..
huffman@20554
   470
qed
huffman@20554
   471
huffman@20554
   472
lemma Reals_induct [case_names of_real, induct set: Reals]:
huffman@20554
   473
  "q \<in> \<real> \<Longrightarrow> (\<And>r. P (of_real r)) \<Longrightarrow> P q"
huffman@20554
   474
  by (rule Reals_cases) auto
huffman@20554
   475
huffman@20504
   476
huffman@20504
   477
subsection {* Real normed vector spaces *}
huffman@20504
   478
huffman@22636
   479
class norm = type +
huffman@22636
   480
  fixes norm :: "'a \<Rightarrow> real"
huffman@20504
   481
haftmann@25571
   482
instantiation real :: norm
haftmann@25571
   483
begin
haftmann@25571
   484
haftmann@25571
   485
definition
haftmann@25571
   486
  real_norm_def [simp]: "norm r \<equiv> \<bar>r\<bar>"
haftmann@25571
   487
haftmann@25571
   488
instance ..
haftmann@25571
   489
haftmann@25571
   490
end
huffman@20554
   491
huffman@24520
   492
class sgn_div_norm = scaleR + norm + sgn +
haftmann@25062
   493
  assumes sgn_div_norm: "sgn x = x /\<^sub>R norm x"
nipkow@24506
   494
haftmann@24588
   495
class real_normed_vector = real_vector + sgn_div_norm +
haftmann@24588
   496
  assumes norm_ge_zero [simp]: "0 \<le> norm x"
haftmann@25062
   497
  and norm_eq_zero [simp]: "norm x = 0 \<longleftrightarrow> x = 0"
haftmann@25062
   498
  and norm_triangle_ineq: "norm (x + y) \<le> norm x + norm y"
haftmann@24588
   499
  and norm_scaleR: "norm (scaleR a x) = \<bar>a\<bar> * norm x"
huffman@20504
   500
haftmann@24588
   501
class real_normed_algebra = real_algebra + real_normed_vector +
haftmann@25062
   502
  assumes norm_mult_ineq: "norm (x * y) \<le> norm x * norm y"
huffman@20504
   503
haftmann@24588
   504
class real_normed_algebra_1 = real_algebra_1 + real_normed_algebra +
haftmann@25062
   505
  assumes norm_one [simp]: "norm 1 = 1"
huffman@22852
   506
haftmann@24588
   507
class real_normed_div_algebra = real_div_algebra + real_normed_vector +
haftmann@25062
   508
  assumes norm_mult: "norm (x * y) = norm x * norm y"
huffman@20504
   509
haftmann@24588
   510
class real_normed_field = real_field + real_normed_div_algebra
huffman@20584
   511
huffman@22852
   512
instance real_normed_div_algebra < real_normed_algebra_1
huffman@20554
   513
proof
huffman@20554
   514
  fix x y :: 'a
huffman@20554
   515
  show "norm (x * y) \<le> norm x * norm y"
huffman@20554
   516
    by (simp add: norm_mult)
huffman@22852
   517
next
huffman@22852
   518
  have "norm (1 * 1::'a) = norm (1::'a) * norm (1::'a)"
huffman@22852
   519
    by (rule norm_mult)
huffman@22852
   520
  thus "norm (1::'a) = 1" by simp
huffman@20554
   521
qed
huffman@20554
   522
huffman@20584
   523
instance real :: real_normed_field
huffman@22852
   524
apply (intro_classes, unfold real_norm_def real_scaleR_def)
nipkow@24506
   525
apply (simp add: real_sgn_def)
huffman@20554
   526
apply (rule abs_ge_zero)
huffman@20554
   527
apply (rule abs_eq_0)
huffman@20554
   528
apply (rule abs_triangle_ineq)
huffman@22852
   529
apply (rule abs_mult)
huffman@20554
   530
apply (rule abs_mult)
huffman@20554
   531
done
huffman@20504
   532
huffman@22852
   533
lemma norm_zero [simp]: "norm (0::'a::real_normed_vector) = 0"
huffman@20504
   534
by simp
huffman@20504
   535
huffman@22852
   536
lemma zero_less_norm_iff [simp]:
huffman@22852
   537
  fixes x :: "'a::real_normed_vector"
huffman@22852
   538
  shows "(0 < norm x) = (x \<noteq> 0)"
huffman@20504
   539
by (simp add: order_less_le)
huffman@20504
   540
huffman@22852
   541
lemma norm_not_less_zero [simp]:
huffman@22852
   542
  fixes x :: "'a::real_normed_vector"
huffman@22852
   543
  shows "\<not> norm x < 0"
huffman@20828
   544
by (simp add: linorder_not_less)
huffman@20828
   545
huffman@22852
   546
lemma norm_le_zero_iff [simp]:
huffman@22852
   547
  fixes x :: "'a::real_normed_vector"
huffman@22852
   548
  shows "(norm x \<le> 0) = (x = 0)"
huffman@20828
   549
by (simp add: order_le_less)
huffman@20828
   550
huffman@20504
   551
lemma norm_minus_cancel [simp]:
huffman@20584
   552
  fixes x :: "'a::real_normed_vector"
huffman@20584
   553
  shows "norm (- x) = norm x"
huffman@20504
   554
proof -
huffman@21809
   555
  have "norm (- x) = norm (scaleR (- 1) x)"
huffman@20504
   556
    by (simp only: scaleR_minus_left scaleR_one)
huffman@20533
   557
  also have "\<dots> = \<bar>- 1\<bar> * norm x"
huffman@20504
   558
    by (rule norm_scaleR)
huffman@20504
   559
  finally show ?thesis by simp
huffman@20504
   560
qed
huffman@20504
   561
huffman@20504
   562
lemma norm_minus_commute:
huffman@20584
   563
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   564
  shows "norm (a - b) = norm (b - a)"
huffman@20504
   565
proof -
huffman@22898
   566
  have "norm (- (b - a)) = norm (b - a)"
huffman@22898
   567
    by (rule norm_minus_cancel)
huffman@22898
   568
  thus ?thesis by simp
huffman@20504
   569
qed
huffman@20504
   570
huffman@20504
   571
lemma norm_triangle_ineq2:
huffman@20584
   572
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   573
  shows "norm a - norm b \<le> norm (a - b)"
huffman@20504
   574
proof -
huffman@20533
   575
  have "norm (a - b + b) \<le> norm (a - b) + norm b"
huffman@20504
   576
    by (rule norm_triangle_ineq)
huffman@22898
   577
  thus ?thesis by simp
huffman@20504
   578
qed
huffman@20504
   579
huffman@20584
   580
lemma norm_triangle_ineq3:
huffman@20584
   581
  fixes a b :: "'a::real_normed_vector"
huffman@20584
   582
  shows "\<bar>norm a - norm b\<bar> \<le> norm (a - b)"
huffman@20584
   583
apply (subst abs_le_iff)
huffman@20584
   584
apply auto
huffman@20584
   585
apply (rule norm_triangle_ineq2)
huffman@20584
   586
apply (subst norm_minus_commute)
huffman@20584
   587
apply (rule norm_triangle_ineq2)
huffman@20584
   588
done
huffman@20584
   589
huffman@20504
   590
lemma norm_triangle_ineq4:
huffman@20584
   591
  fixes a b :: "'a::real_normed_vector"
huffman@20533
   592
  shows "norm (a - b) \<le> norm a + norm b"
huffman@20504
   593
proof -
huffman@22898
   594
  have "norm (a + - b) \<le> norm a + norm (- b)"
huffman@20504
   595
    by (rule norm_triangle_ineq)
huffman@22898
   596
  thus ?thesis
huffman@22898
   597
    by (simp only: diff_minus norm_minus_cancel)
huffman@22898
   598
qed
huffman@22898
   599
huffman@22898
   600
lemma norm_diff_ineq:
huffman@22898
   601
  fixes a b :: "'a::real_normed_vector"
huffman@22898
   602
  shows "norm a - norm b \<le> norm (a + b)"
huffman@22898
   603
proof -
huffman@22898
   604
  have "norm a - norm (- b) \<le> norm (a - - b)"
huffman@22898
   605
    by (rule norm_triangle_ineq2)
huffman@22898
   606
  thus ?thesis by simp
huffman@20504
   607
qed
huffman@20504
   608
huffman@20551
   609
lemma norm_diff_triangle_ineq:
huffman@20551
   610
  fixes a b c d :: "'a::real_normed_vector"
huffman@20551
   611
  shows "norm ((a + b) - (c + d)) \<le> norm (a - c) + norm (b - d)"
huffman@20551
   612
proof -
huffman@20551
   613
  have "norm ((a + b) - (c + d)) = norm ((a - c) + (b - d))"
huffman@20551
   614
    by (simp add: diff_minus add_ac)
huffman@20551
   615
  also have "\<dots> \<le> norm (a - c) + norm (b - d)"
huffman@20551
   616
    by (rule norm_triangle_ineq)
huffman@20551
   617
  finally show ?thesis .
huffman@20551
   618
qed
huffman@20551
   619
huffman@22857
   620
lemma abs_norm_cancel [simp]:
huffman@22857
   621
  fixes a :: "'a::real_normed_vector"
huffman@22857
   622
  shows "\<bar>norm a\<bar> = norm a"
huffman@22857
   623
by (rule abs_of_nonneg [OF norm_ge_zero])
huffman@22857
   624
huffman@22880
   625
lemma norm_add_less:
huffman@22880
   626
  fixes x y :: "'a::real_normed_vector"
huffman@22880
   627
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x + y) < r + s"
huffman@22880
   628
by (rule order_le_less_trans [OF norm_triangle_ineq add_strict_mono])
huffman@22880
   629
huffman@22880
   630
lemma norm_mult_less:
huffman@22880
   631
  fixes x y :: "'a::real_normed_algebra"
huffman@22880
   632
  shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x * y) < r * s"
huffman@22880
   633
apply (rule order_le_less_trans [OF norm_mult_ineq])
huffman@22880
   634
apply (simp add: mult_strict_mono')
huffman@22880
   635
done
huffman@22880
   636
huffman@22857
   637
lemma norm_of_real [simp]:
huffman@22857
   638
  "norm (of_real r :: 'a::real_normed_algebra_1) = \<bar>r\<bar>"
huffman@22852
   639
unfolding of_real_def by (simp add: norm_scaleR)
huffman@20560
   640
huffman@22876
   641
lemma norm_number_of [simp]:
huffman@22876
   642
  "norm (number_of w::'a::{number_ring,real_normed_algebra_1})
huffman@22876
   643
    = \<bar>number_of w\<bar>"
huffman@22876
   644
by (subst of_real_number_of_eq [symmetric], rule norm_of_real)
huffman@22876
   645
huffman@22876
   646
lemma norm_of_int [simp]:
huffman@22876
   647
  "norm (of_int z::'a::real_normed_algebra_1) = \<bar>of_int z\<bar>"
huffman@22876
   648
by (subst of_real_of_int_eq [symmetric], rule norm_of_real)
huffman@22876
   649
huffman@22876
   650
lemma norm_of_nat [simp]:
huffman@22876
   651
  "norm (of_nat n::'a::real_normed_algebra_1) = of_nat n"
huffman@22876
   652
apply (subst of_real_of_nat_eq [symmetric])
huffman@22876
   653
apply (subst norm_of_real, simp)
huffman@22876
   654
done
huffman@22876
   655
huffman@20504
   656
lemma nonzero_norm_inverse:
huffman@20504
   657
  fixes a :: "'a::real_normed_div_algebra"
huffman@20533
   658
  shows "a \<noteq> 0 \<Longrightarrow> norm (inverse a) = inverse (norm a)"
huffman@20504
   659
apply (rule inverse_unique [symmetric])
huffman@20504
   660
apply (simp add: norm_mult [symmetric])
huffman@20504
   661
done
huffman@20504
   662
huffman@20504
   663
lemma norm_inverse:
huffman@20504
   664
  fixes a :: "'a::{real_normed_div_algebra,division_by_zero}"
huffman@20533
   665
  shows "norm (inverse a) = inverse (norm a)"
huffman@20504
   666
apply (case_tac "a = 0", simp)
huffman@20504
   667
apply (erule nonzero_norm_inverse)
huffman@20504
   668
done
huffman@20504
   669
huffman@20584
   670
lemma nonzero_norm_divide:
huffman@20584
   671
  fixes a b :: "'a::real_normed_field"
huffman@20584
   672
  shows "b \<noteq> 0 \<Longrightarrow> norm (a / b) = norm a / norm b"
huffman@20584
   673
by (simp add: divide_inverse norm_mult nonzero_norm_inverse)
huffman@20584
   674
huffman@20584
   675
lemma norm_divide:
huffman@20584
   676
  fixes a b :: "'a::{real_normed_field,division_by_zero}"
huffman@20584
   677
  shows "norm (a / b) = norm a / norm b"
huffman@20584
   678
by (simp add: divide_inverse norm_mult norm_inverse)
huffman@20584
   679
huffman@22852
   680
lemma norm_power_ineq:
huffman@22852
   681
  fixes x :: "'a::{real_normed_algebra_1,recpower}"
huffman@22852
   682
  shows "norm (x ^ n) \<le> norm x ^ n"
huffman@22852
   683
proof (induct n)
huffman@22852
   684
  case 0 show "norm (x ^ 0) \<le> norm x ^ 0" by simp
huffman@22852
   685
next
huffman@22852
   686
  case (Suc n)
huffman@22852
   687
  have "norm (x * x ^ n) \<le> norm x * norm (x ^ n)"
huffman@22852
   688
    by (rule norm_mult_ineq)
huffman@22852
   689
  also from Suc have "\<dots> \<le> norm x * norm x ^ n"
huffman@22852
   690
    using norm_ge_zero by (rule mult_left_mono)
huffman@22852
   691
  finally show "norm (x ^ Suc n) \<le> norm x ^ Suc n"
huffman@22852
   692
    by (simp add: power_Suc)
huffman@22852
   693
qed
huffman@22852
   694
huffman@20684
   695
lemma norm_power:
huffman@20684
   696
  fixes x :: "'a::{real_normed_div_algebra,recpower}"
huffman@20684
   697
  shows "norm (x ^ n) = norm x ^ n"
wenzelm@20772
   698
by (induct n) (simp_all add: power_Suc norm_mult)
huffman@20684
   699
huffman@22442
   700
huffman@22972
   701
subsection {* Sign function *}
huffman@22972
   702
nipkow@24506
   703
lemma norm_sgn:
nipkow@24506
   704
  "norm (sgn(x::'a::real_normed_vector)) = (if x = 0 then 0 else 1)"
nipkow@24506
   705
by (simp add: sgn_div_norm norm_scaleR)
huffman@22972
   706
nipkow@24506
   707
lemma sgn_zero [simp]: "sgn(0::'a::real_normed_vector) = 0"
nipkow@24506
   708
by (simp add: sgn_div_norm)
huffman@22972
   709
nipkow@24506
   710
lemma sgn_zero_iff: "(sgn(x::'a::real_normed_vector) = 0) = (x = 0)"
nipkow@24506
   711
by (simp add: sgn_div_norm)
huffman@22972
   712
nipkow@24506
   713
lemma sgn_minus: "sgn (- x) = - sgn(x::'a::real_normed_vector)"
nipkow@24506
   714
by (simp add: sgn_div_norm)
huffman@22972
   715
nipkow@24506
   716
lemma sgn_scaleR:
nipkow@24506
   717
  "sgn (scaleR r x) = scaleR (sgn r) (sgn(x::'a::real_normed_vector))"
nipkow@24506
   718
by (simp add: sgn_div_norm norm_scaleR mult_ac)
huffman@22973
   719
huffman@22972
   720
lemma sgn_one [simp]: "sgn (1::'a::real_normed_algebra_1) = 1"
nipkow@24506
   721
by (simp add: sgn_div_norm)
huffman@22972
   722
huffman@22972
   723
lemma sgn_of_real:
huffman@22972
   724
  "sgn (of_real r::'a::real_normed_algebra_1) = of_real (sgn r)"
huffman@22972
   725
unfolding of_real_def by (simp only: sgn_scaleR sgn_one)
huffman@22972
   726
huffman@22973
   727
lemma sgn_mult:
huffman@22973
   728
  fixes x y :: "'a::real_normed_div_algebra"
huffman@22973
   729
  shows "sgn (x * y) = sgn x * sgn y"
nipkow@24506
   730
by (simp add: sgn_div_norm norm_mult mult_commute)
huffman@22973
   731
huffman@22972
   732
lemma real_sgn_eq: "sgn (x::real) = x / \<bar>x\<bar>"
nipkow@24506
   733
by (simp add: sgn_div_norm divide_inverse)
huffman@22972
   734
huffman@22972
   735
lemma real_sgn_pos: "0 < (x::real) \<Longrightarrow> sgn x = 1"
huffman@22972
   736
unfolding real_sgn_eq by simp
huffman@22972
   737
huffman@22972
   738
lemma real_sgn_neg: "(x::real) < 0 \<Longrightarrow> sgn x = -1"
huffman@22972
   739
unfolding real_sgn_eq by simp
huffman@22972
   740
huffman@22972
   741
huffman@22442
   742
subsection {* Bounded Linear and Bilinear Operators *}
huffman@22442
   743
huffman@22442
   744
locale bounded_linear = additive +
huffman@22442
   745
  constrains f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
huffman@22442
   746
  assumes scaleR: "f (scaleR r x) = scaleR r (f x)"
huffman@22442
   747
  assumes bounded: "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K"
huffman@27443
   748
begin
huffman@22442
   749
huffman@27443
   750
lemma pos_bounded:
huffman@22442
   751
  "\<exists>K>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
   752
proof -
huffman@22442
   753
  obtain K where K: "\<And>x. norm (f x) \<le> norm x * K"
huffman@22442
   754
    using bounded by fast
huffman@22442
   755
  show ?thesis
huffman@22442
   756
  proof (intro exI impI conjI allI)
huffman@22442
   757
    show "0 < max 1 K"
huffman@22442
   758
      by (rule order_less_le_trans [OF zero_less_one le_maxI1])
huffman@22442
   759
  next
huffman@22442
   760
    fix x
huffman@22442
   761
    have "norm (f x) \<le> norm x * K" using K .
huffman@22442
   762
    also have "\<dots> \<le> norm x * max 1 K"
huffman@22442
   763
      by (rule mult_left_mono [OF le_maxI2 norm_ge_zero])
huffman@22442
   764
    finally show "norm (f x) \<le> norm x * max 1 K" .
huffman@22442
   765
  qed
huffman@22442
   766
qed
huffman@22442
   767
huffman@27443
   768
lemma nonneg_bounded:
huffman@22442
   769
  "\<exists>K\<ge>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442
   770
proof -
huffman@22442
   771
  from pos_bounded
huffman@22442
   772
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
   773
qed
huffman@22442
   774
huffman@27443
   775
end
huffman@27443
   776
huffman@22442
   777
locale bounded_bilinear =
huffman@22442
   778
  fixes prod :: "['a::real_normed_vector, 'b::real_normed_vector]
huffman@22442
   779
                 \<Rightarrow> 'c::real_normed_vector"
huffman@22442
   780
    (infixl "**" 70)
huffman@22442
   781
  assumes add_left: "prod (a + a') b = prod a b + prod a' b"
huffman@22442
   782
  assumes add_right: "prod a (b + b') = prod a b + prod a b'"
huffman@22442
   783
  assumes scaleR_left: "prod (scaleR r a) b = scaleR r (prod a b)"
huffman@22442
   784
  assumes scaleR_right: "prod a (scaleR r b) = scaleR r (prod a b)"
huffman@22442
   785
  assumes bounded: "\<exists>K. \<forall>a b. norm (prod a b) \<le> norm a * norm b * K"
huffman@27443
   786
begin
huffman@22442
   787
huffman@27443
   788
lemma pos_bounded:
huffman@22442
   789
  "\<exists>K>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
   790
apply (cut_tac bounded, erule exE)
huffman@22442
   791
apply (rule_tac x="max 1 K" in exI, safe)
huffman@22442
   792
apply (rule order_less_le_trans [OF zero_less_one le_maxI1])
huffman@22442
   793
apply (drule spec, drule spec, erule order_trans)
huffman@22442
   794
apply (rule mult_left_mono [OF le_maxI2])
huffman@22442
   795
apply (intro mult_nonneg_nonneg norm_ge_zero)
huffman@22442
   796
done
huffman@22442
   797
huffman@27443
   798
lemma nonneg_bounded:
huffman@22442
   799
  "\<exists>K\<ge>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442
   800
proof -
huffman@22442
   801
  from pos_bounded
huffman@22442
   802
  show ?thesis by (auto intro: order_less_imp_le)
huffman@22442
   803
qed
huffman@22442
   804
huffman@27443
   805
lemma additive_right: "additive (\<lambda>b. prod a b)"
huffman@22442
   806
by (rule additive.intro, rule add_right)
huffman@22442
   807
huffman@27443
   808
lemma additive_left: "additive (\<lambda>a. prod a b)"
huffman@22442
   809
by (rule additive.intro, rule add_left)
huffman@22442
   810
huffman@27443
   811
lemma zero_left: "prod 0 b = 0"
huffman@22442
   812
by (rule additive.zero [OF additive_left])
huffman@22442
   813
huffman@27443
   814
lemma zero_right: "prod a 0 = 0"
huffman@22442
   815
by (rule additive.zero [OF additive_right])
huffman@22442
   816
huffman@27443
   817
lemma minus_left: "prod (- a) b = - prod a b"
huffman@22442
   818
by (rule additive.minus [OF additive_left])
huffman@22442
   819
huffman@27443
   820
lemma minus_right: "prod a (- b) = - prod a b"
huffman@22442
   821
by (rule additive.minus [OF additive_right])
huffman@22442
   822
huffman@27443
   823
lemma diff_left:
huffman@22442
   824
  "prod (a - a') b = prod a b - prod a' b"
huffman@22442
   825
by (rule additive.diff [OF additive_left])
huffman@22442
   826
huffman@27443
   827
lemma diff_right:
huffman@22442
   828
  "prod a (b - b') = prod a b - prod a b'"
huffman@22442
   829
by (rule additive.diff [OF additive_right])
huffman@22442
   830
huffman@27443
   831
lemma bounded_linear_left:
huffman@22442
   832
  "bounded_linear (\<lambda>a. a ** b)"
huffman@22442
   833
apply (unfold_locales)
huffman@22442
   834
apply (rule add_left)
huffman@22442
   835
apply (rule scaleR_left)
huffman@22442
   836
apply (cut_tac bounded, safe)
huffman@22442
   837
apply (rule_tac x="norm b * K" in exI)
huffman@22442
   838
apply (simp add: mult_ac)
huffman@22442
   839
done
huffman@22442
   840
huffman@27443
   841
lemma bounded_linear_right:
huffman@22442
   842
  "bounded_linear (\<lambda>b. a ** b)"
huffman@22442
   843
apply (unfold_locales)
huffman@22442
   844
apply (rule add_right)
huffman@22442
   845
apply (rule scaleR_right)
huffman@22442
   846
apply (cut_tac bounded, safe)
huffman@22442
   847
apply (rule_tac x="norm a * K" in exI)
huffman@22442
   848
apply (simp add: mult_ac)
huffman@22442
   849
done
huffman@22442
   850
huffman@27443
   851
lemma prod_diff_prod:
huffman@22442
   852
  "(x ** y - a ** b) = (x - a) ** (y - b) + (x - a) ** b + a ** (y - b)"
huffman@22442
   853
by (simp add: diff_left diff_right)
huffman@22442
   854
huffman@27443
   855
end
huffman@27443
   856
huffman@23127
   857
interpretation mult:
huffman@22442
   858
  bounded_bilinear ["op * :: 'a \<Rightarrow> 'a \<Rightarrow> 'a::real_normed_algebra"]
huffman@22442
   859
apply (rule bounded_bilinear.intro)
huffman@22442
   860
apply (rule left_distrib)
huffman@22442
   861
apply (rule right_distrib)
huffman@22442
   862
apply (rule mult_scaleR_left)
huffman@22442
   863
apply (rule mult_scaleR_right)
huffman@22442
   864
apply (rule_tac x="1" in exI)
huffman@22442
   865
apply (simp add: norm_mult_ineq)
huffman@22442
   866
done
huffman@22442
   867
huffman@23127
   868
interpretation mult_left:
huffman@22442
   869
  bounded_linear ["(\<lambda>x::'a::real_normed_algebra. x * y)"]
huffman@23127
   870
by (rule mult.bounded_linear_left)
huffman@22442
   871
huffman@23127
   872
interpretation mult_right:
huffman@23127
   873
  bounded_linear ["(\<lambda>y::'a::real_normed_algebra. x * y)"]
huffman@23127
   874
by (rule mult.bounded_linear_right)
huffman@23127
   875
huffman@23127
   876
interpretation divide:
huffman@23120
   877
  bounded_linear ["(\<lambda>x::'a::real_normed_field. x / y)"]
huffman@23127
   878
unfolding divide_inverse by (rule mult.bounded_linear_left)
huffman@23120
   879
huffman@23127
   880
interpretation scaleR: bounded_bilinear ["scaleR"]
huffman@22442
   881
apply (rule bounded_bilinear.intro)
huffman@22442
   882
apply (rule scaleR_left_distrib)
huffman@22442
   883
apply (rule scaleR_right_distrib)
huffman@22973
   884
apply simp
huffman@22442
   885
apply (rule scaleR_left_commute)
huffman@22442
   886
apply (rule_tac x="1" in exI)
huffman@22442
   887
apply (simp add: norm_scaleR)
huffman@22442
   888
done
huffman@22442
   889
huffman@23127
   890
interpretation scaleR_left: bounded_linear ["\<lambda>r. scaleR r x"]
huffman@23127
   891
by (rule scaleR.bounded_linear_left)
huffman@23127
   892
huffman@23127
   893
interpretation scaleR_right: bounded_linear ["\<lambda>x. scaleR r x"]
huffman@23127
   894
by (rule scaleR.bounded_linear_right)
huffman@23127
   895
huffman@23127
   896
interpretation of_real: bounded_linear ["\<lambda>r. of_real r"]
huffman@23127
   897
unfolding of_real_def by (rule scaleR.bounded_linear_left)
huffman@22625
   898
huffman@20504
   899
end