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