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