
haftmann@29197: (*  Title:      HOL/RealVector.thy
haftmann@27552:     Author:     Brian Huffman
huffman@20504: *)
huffman@20504: 
huffman@20504: header {* Vector Spaces and Algebras over the Reals *}
huffman@20504: 
huffman@20504: theory RealVector
haftmann@29197: imports RealPow
huffman@20504: begin
huffman@20504: 
huffman@20504: subsection {* Locale for additive functions *}
huffman@20504: 
huffman@20504: locale additive =
huffman@20504:   fixes f :: "'a::ab_group_add \<Rightarrow> 'b::ab_group_add"
huffman@20504:   assumes add: "f (x + y) = f x + f y"
huffman@27443: begin
huffman@20504: 
huffman@27443: lemma zero: "f 0 = 0"
huffman@20504: proof -
huffman@20504:   have "f 0 = f (0 + 0)" by simp
huffman@20504:   also have "\<dots> = f 0 + f 0" by (rule add)
huffman@20504:   finally show "f 0 = 0" by simp
huffman@20504: qed
huffman@20504: 
huffman@27443: lemma minus: "f (- x) = - f x"
huffman@20504: proof -
huffman@20504:   have "f (- x) + f x = f (- x + x)" by (rule add [symmetric])
huffman@20504:   also have "\<dots> = - f x + f x" by (simp add: zero)
huffman@20504:   finally show "f (- x) = - f x" by (rule add_right_imp_eq)
huffman@20504: qed
huffman@20504: 
huffman@27443: lemma diff: "f (x - y) = f x - f y"
huffman@20504: by (simp add: diff_def add minus)
huffman@20504: 
huffman@27443: lemma setsum: "f (setsum g A) = (\<Sum>x\<in>A. f (g x))"
huffman@22942: apply (cases "finite A")
huffman@22942: apply (induct set: finite)
huffman@22942: apply (simp add: zero)
huffman@22942: apply (simp add: add)
huffman@22942: apply (simp add: zero)
huffman@22942: done
huffman@22942: 
huffman@27443: end
huffman@20504: 
huffman@28029: subsection {* Vector spaces *}
huffman@28029: 
huffman@28029: locale vector_space =
huffman@28029:   fixes scale :: "'a::field \<Rightarrow> 'b::ab_group_add \<Rightarrow> 'b"
huffman@30070:   assumes scale_right_distrib [algebra_simps]:
huffman@30070:     "scale a (x + y) = scale a x + scale a y"
huffman@30070:   and scale_left_distrib [algebra_simps]:
huffman@30070:     "scale (a + b) x = scale a x + scale b x"
huffman@28029:   and scale_scale [simp]: "scale a (scale b x) = scale (a * b) x"
huffman@28029:   and scale_one [simp]: "scale 1 x = x"
huffman@28029: begin
huffman@28029: 
huffman@28029: lemma scale_left_commute:
huffman@28029:   "scale a (scale b x) = scale b (scale a x)"
huffman@28029: by (simp add: mult_commute)
huffman@28029: 
huffman@28029: lemma scale_zero_left [simp]: "scale 0 x = 0"
huffman@28029:   and scale_minus_left [simp]: "scale (- a) x = - (scale a x)"
huffman@30070:   and scale_left_diff_distrib [algebra_simps]:
huffman@30070:         "scale (a - b) x = scale a x - scale b x"
huffman@28029: proof -
ballarin@29229:   interpret s: additive "\<lambda>a. scale a x"
haftmann@28823:     proof qed (rule scale_left_distrib)
huffman@28029:   show "scale 0 x = 0" by (rule s.zero)
huffman@28029:   show "scale (- a) x = - (scale a x)" by (rule s.minus)
huffman@28029:   show "scale (a - b) x = scale a x - scale b x" by (rule s.diff)
huffman@28029: qed
huffman@28029: 
huffman@28029: lemma scale_zero_right [simp]: "scale a 0 = 0"
huffman@28029:   and scale_minus_right [simp]: "scale a (- x) = - (scale a x)"
huffman@30070:   and scale_right_diff_distrib [algebra_simps]:
huffman@30070:         "scale a (x - y) = scale a x - scale a y"
huffman@28029: proof -
ballarin@29229:   interpret s: additive "\<lambda>x. scale a x"
haftmann@28823:     proof qed (rule scale_right_distrib)
huffman@28029:   show "scale a 0 = 0" by (rule s.zero)
huffman@28029:   show "scale a (- x) = - (scale a x)" by (rule s.minus)
huffman@28029:   show "scale a (x - y) = scale a x - scale a y" by (rule s.diff)
huffman@28029: qed
huffman@28029: 
huffman@28029: lemma scale_eq_0_iff [simp]:
huffman@28029:   "scale a x = 0 \<longleftrightarrow> a = 0 \<or> x = 0"
huffman@28029: proof cases
huffman@28029:   assume "a = 0" thus ?thesis by simp
huffman@28029: next
huffman@28029:   assume anz [simp]: "a \<noteq> 0"
huffman@28029:   { assume "scale a x = 0"
huffman@28029:     hence "scale (inverse a) (scale a x) = 0" by simp
huffman@28029:     hence "x = 0" by simp }
huffman@28029:   thus ?thesis by force
huffman@28029: qed
huffman@28029: 
huffman@28029: lemma scale_left_imp_eq:
huffman@28029:   "\<lbrakk>a \<noteq> 0; scale a x = scale a y\<rbrakk> \<Longrightarrow> x = y"
huffman@28029: proof -
huffman@28029:   assume nonzero: "a \<noteq> 0"
huffman@28029:   assume "scale a x = scale a y"
huffman@28029:   hence "scale a (x - y) = 0"
huffman@28029:      by (simp add: scale_right_diff_distrib)
huffman@28029:   hence "x - y = 0" by (simp add: nonzero)
huffman@28029:   thus "x = y" by (simp only: right_minus_eq)
huffman@28029: qed
huffman@28029: 
huffman@28029: lemma scale_right_imp_eq:
huffman@28029:   "\<lbrakk>x \<noteq> 0; scale a x = scale b x\<rbrakk> \<Longrightarrow> a = b"
huffman@28029: proof -
huffman@28029:   assume nonzero: "x \<noteq> 0"
huffman@28029:   assume "scale a x = scale b x"
huffman@28029:   hence "scale (a - b) x = 0"
huffman@28029:      by (simp add: scale_left_diff_distrib)
huffman@28029:   hence "a - b = 0" by (simp add: nonzero)
huffman@28029:   thus "a = b" by (simp only: right_minus_eq)
huffman@28029: qed
huffman@28029: 
huffman@28029: lemma scale_cancel_left:
huffman@28029:   "scale a x = scale a y \<longleftrightarrow> x = y \<or> a = 0"
huffman@28029: by (auto intro: scale_left_imp_eq)
huffman@28029: 
huffman@28029: lemma scale_cancel_right:
huffman@28029:   "scale a x = scale b x \<longleftrightarrow> a = b \<or> x = 0"
huffman@28029: by (auto intro: scale_right_imp_eq)
huffman@28029: 
huffman@28029: end
huffman@28029: 
huffman@20504: subsection {* Real vector spaces *}
huffman@20504: 
haftmann@29608: class scaleR =
haftmann@25062:   fixes scaleR :: "real \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "*\<^sub>R" 75)
haftmann@24748: begin
huffman@20504: 
huffman@20763: abbreviation
haftmann@25062:   divideR :: "'a \<Rightarrow> real \<Rightarrow> 'a" (infixl "'/\<^sub>R" 70)
haftmann@24748: where
haftmann@25062:   "x /\<^sub>R r == scaleR (inverse r) x"
haftmann@24748: 
haftmann@24748: end
haftmann@24748: 
haftmann@24588: class real_vector = scaleR + ab_group_add +
haftmann@25062:   assumes scaleR_right_distrib: "scaleR a (x + y) = scaleR a x + scaleR a y"
haftmann@25062:   and scaleR_left_distrib: "scaleR (a + b) x = scaleR a x + scaleR b x"
huffman@30070:   and scaleR_scaleR: "scaleR a (scaleR b x) = scaleR (a * b) x"
huffman@30070:   and scaleR_one: "scaleR 1 x = x"
huffman@20504: 
ballarin@29233: interpretation real_vector!:
ballarin@29229:   vector_space "scaleR :: real \<Rightarrow> 'a \<Rightarrow> 'a::real_vector"
huffman@28009: apply unfold_locales
huffman@28009: apply (rule scaleR_right_distrib)
huffman@28009: apply (rule scaleR_left_distrib)
huffman@28009: apply (rule scaleR_scaleR)
huffman@28009: apply (rule scaleR_one)
huffman@28009: done
huffman@28009: 
huffman@28009: text {* Recover original theorem names *}
huffman@28009: 
huffman@28009: lemmas scaleR_left_commute = real_vector.scale_left_commute
huffman@28009: lemmas scaleR_zero_left = real_vector.scale_zero_left
huffman@28009: lemmas scaleR_minus_left = real_vector.scale_minus_left
huffman@28009: lemmas scaleR_left_diff_distrib = real_vector.scale_left_diff_distrib
huffman@28009: lemmas scaleR_zero_right = real_vector.scale_zero_right
huffman@28009: lemmas scaleR_minus_right = real_vector.scale_minus_right
huffman@28009: lemmas scaleR_right_diff_distrib = real_vector.scale_right_diff_distrib
huffman@28009: lemmas scaleR_eq_0_iff = real_vector.scale_eq_0_iff
huffman@28009: lemmas scaleR_left_imp_eq = real_vector.scale_left_imp_eq
huffman@28009: lemmas scaleR_right_imp_eq = real_vector.scale_right_imp_eq
huffman@28009: lemmas scaleR_cancel_left = real_vector.scale_cancel_left
huffman@28009: lemmas scaleR_cancel_right = real_vector.scale_cancel_right
huffman@28009: 
haftmann@24588: class real_algebra = real_vector + ring +
haftmann@25062:   assumes mult_scaleR_left [simp]: "scaleR a x * y = scaleR a (x * y)"
haftmann@25062:   and mult_scaleR_right [simp]: "x * scaleR a y = scaleR a (x * y)"
huffman@20504: 
haftmann@24588: class real_algebra_1 = real_algebra + ring_1
huffman@20554: 
haftmann@24588: class real_div_algebra = real_algebra_1 + division_ring
huffman@20584: 
haftmann@24588: class real_field = real_div_algebra + field
huffman@20584: 
huffman@30069: instantiation real :: real_field
huffman@30069: begin
huffman@30069: 
huffman@30069: definition
huffman@30069:   real_scaleR_def [simp]: "scaleR a x = a * x"
huffman@30069: 
huffman@30070: instance proof
huffman@30070: qed (simp_all add: algebra_simps)
huffman@20554: 
huffman@30069: end
huffman@30069: 
ballarin@29233: interpretation scaleR_left!: additive "(\<lambda>a. scaleR a x::'a::real_vector)"
haftmann@28823: proof qed (rule scaleR_left_distrib)
huffman@20504: 
ballarin@29233: interpretation scaleR_right!: additive "(\<lambda>x. scaleR a x::'a::real_vector)"
haftmann@28823: proof qed (rule scaleR_right_distrib)
huffman@20504: 
huffman@20584: lemma nonzero_inverse_scaleR_distrib:
huffman@21809:   fixes x :: "'a::real_div_algebra" shows
huffman@21809:   "\<lbrakk>a \<noteq> 0; x \<noteq> 0\<rbrakk> \<Longrightarrow> inverse (scaleR a x) = scaleR (inverse a) (inverse x)"
huffman@20763: by (rule inverse_unique, simp)
huffman@20584: 
huffman@20584: lemma inverse_scaleR_distrib:
huffman@20584:   fixes x :: "'a::{real_div_algebra,division_by_zero}"
huffman@21809:   shows "inverse (scaleR a x) = scaleR (inverse a) (inverse x)"
huffman@20584: apply (case_tac "a = 0", simp)
huffman@20584: apply (case_tac "x = 0", simp)
huffman@20584: apply (erule (1) nonzero_inverse_scaleR_distrib)
huffman@20584: done
huffman@20584: 
huffman@20554: 
huffman@20554: subsection {* Embedding of the Reals into any @{text real_algebra_1}:
huffman@20554: @{term of_real} *}
huffman@20554: 
huffman@20554: definition
wenzelm@21404:   of_real :: "real \<Rightarrow> 'a::real_algebra_1" where
huffman@21809:   "of_real r = scaleR r 1"
huffman@20554: 
huffman@21809: lemma scaleR_conv_of_real: "scaleR r x = of_real r * x"
huffman@20763: by (simp add: of_real_def)
huffman@20763: 
huffman@20554: lemma of_real_0 [simp]: "of_real 0 = 0"
huffman@20554: by (simp add: of_real_def)
huffman@20554: 
huffman@20554: lemma of_real_1 [simp]: "of_real 1 = 1"
huffman@20554: by (simp add: of_real_def)
huffman@20554: 
huffman@20554: lemma of_real_add [simp]: "of_real (x + y) = of_real x + of_real y"
huffman@20554: by (simp add: of_real_def scaleR_left_distrib)
huffman@20554: 
huffman@20554: lemma of_real_minus [simp]: "of_real (- x) = - of_real x"
huffman@20554: by (simp add: of_real_def)
huffman@20554: 
huffman@20554: lemma of_real_diff [simp]: "of_real (x - y) = of_real x - of_real y"
huffman@20554: by (simp add: of_real_def scaleR_left_diff_distrib)
huffman@20554: 
huffman@20554: lemma of_real_mult [simp]: "of_real (x * y) = of_real x * of_real y"
huffman@20763: by (simp add: of_real_def mult_commute)
huffman@20554: 
huffman@20584: lemma nonzero_of_real_inverse:
huffman@20584:   "x \<noteq> 0 \<Longrightarrow> of_real (inverse x) =
huffman@20584:    inverse (of_real x :: 'a::real_div_algebra)"
huffman@20584: by (simp add: of_real_def nonzero_inverse_scaleR_distrib)
huffman@20584: 
huffman@20584: lemma of_real_inverse [simp]:
huffman@20584:   "of_real (inverse x) =
huffman@20584:    inverse (of_real x :: 'a::{real_div_algebra,division_by_zero})"
huffman@20584: by (simp add: of_real_def inverse_scaleR_distrib)
huffman@20584: 
huffman@20584: lemma nonzero_of_real_divide:
huffman@20584:   "y \<noteq> 0 \<Longrightarrow> of_real (x / y) =
huffman@20584:    (of_real x / of_real y :: 'a::real_field)"
huffman@20584: by (simp add: divide_inverse nonzero_of_real_inverse)
huffman@20722: 
huffman@20722: lemma of_real_divide [simp]:
huffman@20584:   "of_real (x / y) =
huffman@20584:    (of_real x / of_real y :: 'a::{real_field,division_by_zero})"
huffman@20584: by (simp add: divide_inverse)
huffman@20584: 
huffman@20722: lemma of_real_power [simp]:
huffman@20722:   "of_real (x ^ n) = (of_real x :: 'a::{real_algebra_1,recpower}) ^ n"
huffman@30273: by (induct n) simp_all
huffman@20722: 
huffman@20554: lemma of_real_eq_iff [simp]: "(of_real x = of_real y) = (x = y)"
huffman@20554: by (simp add: of_real_def scaleR_cancel_right)
huffman@20554: 
huffman@20584: lemmas of_real_eq_0_iff [simp] = of_real_eq_iff [of _ 0, simplified]
huffman@20554: 
huffman@20554: lemma of_real_eq_id [simp]: "of_real = (id :: real \<Rightarrow> real)"
huffman@20554: proof
huffman@20554:   fix r
huffman@20554:   show "of_real r = id r"
huffman@22973:     by (simp add: of_real_def)
huffman@20554: qed
huffman@20554: 
huffman@20554: text{*Collapse nested embeddings*}
huffman@20554: lemma of_real_of_nat_eq [simp]: "of_real (of_nat n) = of_nat n"
wenzelm@20772: by (induct n) auto
huffman@20554: 
huffman@20554: lemma of_real_of_int_eq [simp]: "of_real (of_int z) = of_int z"
huffman@20554: by (cases z rule: int_diff_cases, simp)
huffman@20554: 
huffman@20554: lemma of_real_number_of_eq:
huffman@20554:   "of_real (number_of w) = (number_of w :: 'a::{number_ring,real_algebra_1})"
huffman@20554: by (simp add: number_of_eq)
huffman@20554: 
huffman@22912: text{*Every real algebra has characteristic zero*}
huffman@22912: instance real_algebra_1 < ring_char_0
huffman@22912: proof
huffman@23282:   fix m n :: nat
huffman@23282:   have "(of_real (of_nat m) = (of_real (of_nat n)::'a)) = (m = n)"
huffman@23282:     by (simp only: of_real_eq_iff of_nat_eq_iff)
huffman@23282:   thus "(of_nat m = (of_nat n::'a)) = (m = n)"
huffman@23282:     by (simp only: of_real_of_nat_eq)
huffman@22912: qed
huffman@22912: 
huffman@27553: instance real_field < field_char_0 ..
huffman@27553: 
huffman@20554: 
huffman@20554: subsection {* The Set of Real Numbers *}
huffman@20554: 
wenzelm@20772: definition
wenzelm@21404:   Reals :: "'a::real_algebra_1 set" where
huffman@30070:   [code del]: "Reals = range of_real"
huffman@20554: 
wenzelm@21210: notation (xsymbols)
huffman@20554:   Reals  ("\<real>")
huffman@20554: 
huffman@21809: lemma Reals_of_real [simp]: "of_real r \<in> Reals"
huffman@20554: by (simp add: Reals_def)
huffman@20554: 
huffman@21809: lemma Reals_of_int [simp]: "of_int z \<in> Reals"
huffman@21809: by (subst of_real_of_int_eq [symmetric], rule Reals_of_real)
huffman@20718: 
huffman@21809: lemma Reals_of_nat [simp]: "of_nat n \<in> Reals"
huffman@21809: by (subst of_real_of_nat_eq [symmetric], rule Reals_of_real)
huffman@21809: 
huffman@21809: lemma Reals_number_of [simp]:
huffman@21809:   "(number_of w::'a::{number_ring,real_algebra_1}) \<in> Reals"
huffman@21809: by (subst of_real_number_of_eq [symmetric], rule Reals_of_real)
huffman@20718: 
huffman@20554: lemma Reals_0 [simp]: "0 \<in> Reals"
huffman@20554: apply (unfold Reals_def)
huffman@20554: apply (rule range_eqI)
huffman@20554: apply (rule of_real_0 [symmetric])
huffman@20554: done
huffman@20554: 
huffman@20554: lemma Reals_1 [simp]: "1 \<in> Reals"
huffman@20554: apply (unfold Reals_def)
huffman@20554: apply (rule range_eqI)
huffman@20554: apply (rule of_real_1 [symmetric])
huffman@20554: done
huffman@20554: 
huffman@20584: lemma Reals_add [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a + b \<in> Reals"
huffman@20554: apply (auto simp add: Reals_def)
huffman@20554: apply (rule range_eqI)
huffman@20554: apply (rule of_real_add [symmetric])
huffman@20554: done
huffman@20554: 
huffman@20584: lemma Reals_minus [simp]: "a \<in> Reals \<Longrightarrow> - a \<in> Reals"
huffman@20584: apply (auto simp add: Reals_def)
huffman@20584: apply (rule range_eqI)
huffman@20584: apply (rule of_real_minus [symmetric])
huffman@20584: done
huffman@20584: 
huffman@20584: lemma Reals_diff [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a - b \<in> Reals"
huffman@20584: apply (auto simp add: Reals_def)
huffman@20584: apply (rule range_eqI)
huffman@20584: apply (rule of_real_diff [symmetric])
huffman@20584: done
huffman@20584: 
huffman@20584: lemma Reals_mult [simp]: "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a * b \<in> Reals"
huffman@20554: apply (auto simp add: Reals_def)
huffman@20554: apply (rule range_eqI)
huffman@20554: apply (rule of_real_mult [symmetric])
huffman@20554: done
huffman@20554: 
huffman@20584: lemma nonzero_Reals_inverse:
huffman@20584:   fixes a :: "'a::real_div_algebra"
huffman@20584:   shows "\<lbrakk>a \<in> Reals; a \<noteq> 0\<rbrakk> \<Longrightarrow> inverse a \<in> Reals"
huffman@20584: apply (auto simp add: Reals_def)
huffman@20584: apply (rule range_eqI)
huffman@20584: apply (erule nonzero_of_real_inverse [symmetric])
huffman@20584: done
huffman@20584: 
huffman@20584: lemma Reals_inverse [simp]:
huffman@20584:   fixes a :: "'a::{real_div_algebra,division_by_zero}"
huffman@20584:   shows "a \<in> Reals \<Longrightarrow> inverse a \<in> Reals"
huffman@20584: apply (auto simp add: Reals_def)
huffman@20584: apply (rule range_eqI)
huffman@20584: apply (rule of_real_inverse [symmetric])
huffman@20584: done
huffman@20584: 
huffman@20584: lemma nonzero_Reals_divide:
huffman@20584:   fixes a b :: "'a::real_field"
huffman@20584:   shows "\<lbrakk>a \<in> Reals; b \<in> Reals; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584: apply (auto simp add: Reals_def)
huffman@20584: apply (rule range_eqI)
huffman@20584: apply (erule nonzero_of_real_divide [symmetric])
huffman@20584: done
huffman@20584: 
huffman@20584: lemma Reals_divide [simp]:
huffman@20584:   fixes a b :: "'a::{real_field,division_by_zero}"
huffman@20584:   shows "\<lbrakk>a \<in> Reals; b \<in> Reals\<rbrakk> \<Longrightarrow> a / b \<in> Reals"
huffman@20584: apply (auto simp add: Reals_def)
huffman@20584: apply (rule range_eqI)
huffman@20584: apply (rule of_real_divide [symmetric])
huffman@20584: done
huffman@20584: 
huffman@20722: lemma Reals_power [simp]:
huffman@20722:   fixes a :: "'a::{real_algebra_1,recpower}"
huffman@20722:   shows "a \<in> Reals \<Longrightarrow> a ^ n \<in> Reals"
huffman@20722: apply (auto simp add: Reals_def)
huffman@20722: apply (rule range_eqI)
huffman@20722: apply (rule of_real_power [symmetric])
huffman@20722: done
huffman@20722: 
huffman@20554: lemma Reals_cases [cases set: Reals]:
huffman@20554:   assumes "q \<in> \<real>"
huffman@20554:   obtains (of_real) r where "q = of_real r"
huffman@20554:   unfolding Reals_def
huffman@20554: proof -
huffman@20554:   from `q \<in> \<real>` have "q \<in> range of_real" unfolding Reals_def .
huffman@20554:   then obtain r where "q = of_real r" ..
huffman@20554:   then show thesis ..
huffman@20554: qed
huffman@20554: 
huffman@20554: lemma Reals_induct [case_names of_real, induct set: Reals]:
huffman@20554:   "q \<in> \<real> \<Longrightarrow> (\<And>r. P (of_real r)) \<Longrightarrow> P q"
huffman@20554:   by (rule Reals_cases) auto
huffman@20554: 
huffman@20504: 
huffman@20504: subsection {* Real normed vector spaces *}
huffman@20504: 
haftmann@29608: class norm =
huffman@22636:   fixes norm :: "'a \<Rightarrow> real"
huffman@20504: 
huffman@24520: class sgn_div_norm = scaleR + norm + sgn +
haftmann@25062:   assumes sgn_div_norm: "sgn x = x /\<^sub>R norm x"
nipkow@24506: 
haftmann@24588: class real_normed_vector = real_vector + sgn_div_norm +
haftmann@24588:   assumes norm_ge_zero [simp]: "0 \<le> norm x"
haftmann@25062:   and norm_eq_zero [simp]: "norm x = 0 \<longleftrightarrow> x = 0"
haftmann@25062:   and norm_triangle_ineq: "norm (x + y) \<le> norm x + norm y"
haftmann@24588:   and norm_scaleR: "norm (scaleR a x) = \<bar>a\<bar> * norm x"
huffman@20504: 
haftmann@24588: class real_normed_algebra = real_algebra + real_normed_vector +
haftmann@25062:   assumes norm_mult_ineq: "norm (x * y) \<le> norm x * norm y"
huffman@20504: 
haftmann@24588: class real_normed_algebra_1 = real_algebra_1 + real_normed_algebra +
haftmann@25062:   assumes norm_one [simp]: "norm 1 = 1"
huffman@22852: 
haftmann@24588: class real_normed_div_algebra = real_div_algebra + real_normed_vector +
haftmann@25062:   assumes norm_mult: "norm (x * y) = norm x * norm y"
huffman@20504: 
haftmann@24588: class real_normed_field = real_field + real_normed_div_algebra
huffman@20584: 
huffman@22852: instance real_normed_div_algebra < real_normed_algebra_1
huffman@20554: proof
huffman@20554:   fix x y :: 'a
huffman@20554:   show "norm (x * y) \<le> norm x * norm y"
huffman@20554:     by (simp add: norm_mult)
huffman@22852: next
huffman@22852:   have "norm (1 * 1::'a) = norm (1::'a) * norm (1::'a)"
huffman@22852:     by (rule norm_mult)
huffman@22852:   thus "norm (1::'a) = 1" by simp
huffman@20554: qed
huffman@20554: 
huffman@30069: instantiation real :: real_normed_field
huffman@30069: begin
huffman@30069: 
huffman@30069: definition
huffman@30069:   real_norm_def [simp]: "norm r = \<bar>r\<bar>"
huffman@30069: 
huffman@30069: instance
huffman@22852: apply (intro_classes, unfold real_norm_def real_scaleR_def)
nipkow@24506: apply (simp add: real_sgn_def)
huffman@20554: apply (rule abs_ge_zero)
huffman@20554: apply (rule abs_eq_0)
huffman@20554: apply (rule abs_triangle_ineq)
huffman@22852: apply (rule abs_mult)
huffman@20554: apply (rule abs_mult)
huffman@20554: done
huffman@20504: 
huffman@30069: end
huffman@30069: 
huffman@22852: lemma norm_zero [simp]: "norm (0::'a::real_normed_vector) = 0"
huffman@20504: by simp
huffman@20504: 
huffman@22852: lemma zero_less_norm_iff [simp]:
huffman@22852:   fixes x :: "'a::real_normed_vector"
huffman@22852:   shows "(0 < norm x) = (x \<noteq> 0)"
huffman@20504: by (simp add: order_less_le)
huffman@20504: 
huffman@22852: lemma norm_not_less_zero [simp]:
huffman@22852:   fixes x :: "'a::real_normed_vector"
huffman@22852:   shows "\<not> norm x < 0"
huffman@20828: by (simp add: linorder_not_less)
huffman@20828: 
huffman@22852: lemma norm_le_zero_iff [simp]:
huffman@22852:   fixes x :: "'a::real_normed_vector"
huffman@22852:   shows "(norm x \<le> 0) = (x = 0)"
huffman@20828: by (simp add: order_le_less)
huffman@20828: 
huffman@20504: lemma norm_minus_cancel [simp]:
huffman@20584:   fixes x :: "'a::real_normed_vector"
huffman@20584:   shows "norm (- x) = norm x"
huffman@20504: proof -
huffman@21809:   have "norm (- x) = norm (scaleR (- 1) x)"
huffman@20504:     by (simp only: scaleR_minus_left scaleR_one)
huffman@20533:   also have "\<dots> = \<bar>- 1\<bar> * norm x"
huffman@20504:     by (rule norm_scaleR)
huffman@20504:   finally show ?thesis by simp
huffman@20504: qed
huffman@20504: 
huffman@20504: lemma norm_minus_commute:
huffman@20584:   fixes a b :: "'a::real_normed_vector"
huffman@20584:   shows "norm (a - b) = norm (b - a)"
huffman@20504: proof -
huffman@22898:   have "norm (- (b - a)) = norm (b - a)"
huffman@22898:     by (rule norm_minus_cancel)
huffman@22898:   thus ?thesis by simp
huffman@20504: qed
huffman@20504: 
huffman@20504: lemma norm_triangle_ineq2:
huffman@20584:   fixes a b :: "'a::real_normed_vector"
huffman@20533:   shows "norm a - norm b \<le> norm (a - b)"
huffman@20504: proof -
huffman@20533:   have "norm (a - b + b) \<le> norm (a - b) + norm b"
huffman@20504:     by (rule norm_triangle_ineq)
huffman@22898:   thus ?thesis by simp
huffman@20504: qed
huffman@20504: 
huffman@20584: lemma norm_triangle_ineq3:
huffman@20584:   fixes a b :: "'a::real_normed_vector"
huffman@20584:   shows "\<bar>norm a - norm b\<bar> \<le> norm (a - b)"
huffman@20584: apply (subst abs_le_iff)
huffman@20584: apply auto
huffman@20584: apply (rule norm_triangle_ineq2)
huffman@20584: apply (subst norm_minus_commute)
huffman@20584: apply (rule norm_triangle_ineq2)
huffman@20584: done
huffman@20584: 
huffman@20504: lemma norm_triangle_ineq4:
huffman@20584:   fixes a b :: "'a::real_normed_vector"
huffman@20533:   shows "norm (a - b) \<le> norm a + norm b"
huffman@20504: proof -
huffman@22898:   have "norm (a + - b) \<le> norm a + norm (- b)"
huffman@20504:     by (rule norm_triangle_ineq)
huffman@22898:   thus ?thesis
huffman@22898:     by (simp only: diff_minus norm_minus_cancel)
huffman@22898: qed
huffman@22898: 
huffman@22898: lemma norm_diff_ineq:
huffman@22898:   fixes a b :: "'a::real_normed_vector"
huffman@22898:   shows "norm a - norm b \<le> norm (a + b)"
huffman@22898: proof -
huffman@22898:   have "norm a - norm (- b) \<le> norm (a - - b)"
huffman@22898:     by (rule norm_triangle_ineq2)
huffman@22898:   thus ?thesis by simp
huffman@20504: qed
huffman@20504: 
huffman@20551: lemma norm_diff_triangle_ineq:
huffman@20551:   fixes a b c d :: "'a::real_normed_vector"
huffman@20551:   shows "norm ((a + b) - (c + d)) \<le> norm (a - c) + norm (b - d)"
huffman@20551: proof -
huffman@20551:   have "norm ((a + b) - (c + d)) = norm ((a - c) + (b - d))"
huffman@20551:     by (simp add: diff_minus add_ac)
huffman@20551:   also have "\<dots> \<le> norm (a - c) + norm (b - d)"
huffman@20551:     by (rule norm_triangle_ineq)
huffman@20551:   finally show ?thesis .
huffman@20551: qed
huffman@20551: 
huffman@22857: lemma abs_norm_cancel [simp]:
huffman@22857:   fixes a :: "'a::real_normed_vector"
huffman@22857:   shows "\<bar>norm a\<bar> = norm a"
huffman@22857: by (rule abs_of_nonneg [OF norm_ge_zero])
huffman@22857: 
huffman@22880: lemma norm_add_less:
huffman@22880:   fixes x y :: "'a::real_normed_vector"
huffman@22880:   shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x + y) < r + s"
huffman@22880: by (rule order_le_less_trans [OF norm_triangle_ineq add_strict_mono])
huffman@22880: 
huffman@22880: lemma norm_mult_less:
huffman@22880:   fixes x y :: "'a::real_normed_algebra"
huffman@22880:   shows "\<lbrakk>norm x < r; norm y < s\<rbrakk> \<Longrightarrow> norm (x * y) < r * s"
huffman@22880: apply (rule order_le_less_trans [OF norm_mult_ineq])
huffman@22880: apply (simp add: mult_strict_mono')
huffman@22880: done
huffman@22880: 
huffman@22857: lemma norm_of_real [simp]:
huffman@22857:   "norm (of_real r :: 'a::real_normed_algebra_1) = \<bar>r\<bar>"
huffman@22852: unfolding of_real_def by (simp add: norm_scaleR)
huffman@20560: 
huffman@22876: lemma norm_number_of [simp]:
huffman@22876:   "norm (number_of w::'a::{number_ring,real_normed_algebra_1})
huffman@22876:     = \<bar>number_of w\<bar>"
huffman@22876: by (subst of_real_number_of_eq [symmetric], rule norm_of_real)
huffman@22876: 
huffman@22876: lemma norm_of_int [simp]:
huffman@22876:   "norm (of_int z::'a::real_normed_algebra_1) = \<bar>of_int z\<bar>"
huffman@22876: by (subst of_real_of_int_eq [symmetric], rule norm_of_real)
huffman@22876: 
huffman@22876: lemma norm_of_nat [simp]:
huffman@22876:   "norm (of_nat n::'a::real_normed_algebra_1) = of_nat n"
huffman@22876: apply (subst of_real_of_nat_eq [symmetric])
huffman@22876: apply (subst norm_of_real, simp)
huffman@22876: done
huffman@22876: 
huffman@20504: lemma nonzero_norm_inverse:
huffman@20504:   fixes a :: "'a::real_normed_div_algebra"
huffman@20533:   shows "a \<noteq> 0 \<Longrightarrow> norm (inverse a) = inverse (norm a)"
huffman@20504: apply (rule inverse_unique [symmetric])
huffman@20504: apply (simp add: norm_mult [symmetric])
huffman@20504: done
huffman@20504: 
huffman@20504: lemma norm_inverse:
huffman@20504:   fixes a :: "'a::{real_normed_div_algebra,division_by_zero}"
huffman@20533:   shows "norm (inverse a) = inverse (norm a)"
huffman@20504: apply (case_tac "a = 0", simp)
huffman@20504: apply (erule nonzero_norm_inverse)
huffman@20504: done
huffman@20504: 
huffman@20584: lemma nonzero_norm_divide:
huffman@20584:   fixes a b :: "'a::real_normed_field"
huffman@20584:   shows "b \<noteq> 0 \<Longrightarrow> norm (a / b) = norm a / norm b"
huffman@20584: by (simp add: divide_inverse norm_mult nonzero_norm_inverse)
huffman@20584: 
huffman@20584: lemma norm_divide:
huffman@20584:   fixes a b :: "'a::{real_normed_field,division_by_zero}"
huffman@20584:   shows "norm (a / b) = norm a / norm b"
huffman@20584: by (simp add: divide_inverse norm_mult norm_inverse)
huffman@20584: 
huffman@22852: lemma norm_power_ineq:
huffman@22852:   fixes x :: "'a::{real_normed_algebra_1,recpower}"
huffman@22852:   shows "norm (x ^ n) \<le> norm x ^ n"
huffman@22852: proof (induct n)
huffman@22852:   case 0 show "norm (x ^ 0) \<le> norm x ^ 0" by simp
huffman@22852: next
huffman@22852:   case (Suc n)
huffman@22852:   have "norm (x * x ^ n) \<le> norm x * norm (x ^ n)"
huffman@22852:     by (rule norm_mult_ineq)
huffman@22852:   also from Suc have "\<dots> \<le> norm x * norm x ^ n"
huffman@22852:     using norm_ge_zero by (rule mult_left_mono)
huffman@22852:   finally show "norm (x ^ Suc n) \<le> norm x ^ Suc n"
huffman@30273:     by simp
huffman@22852: qed
huffman@22852: 
huffman@20684: lemma norm_power:
huffman@20684:   fixes x :: "'a::{real_normed_div_algebra,recpower}"
huffman@20684:   shows "norm (x ^ n) = norm x ^ n"
huffman@30273: by (induct n) (simp_all add: norm_mult)
huffman@20684: 
huffman@22442: 
huffman@22972: subsection {* Sign function *}
huffman@22972: 
nipkow@24506: lemma norm_sgn:
nipkow@24506:   "norm (sgn(x::'a::real_normed_vector)) = (if x = 0 then 0 else 1)"
nipkow@24506: by (simp add: sgn_div_norm norm_scaleR)
huffman@22972: 
nipkow@24506: lemma sgn_zero [simp]: "sgn(0::'a::real_normed_vector) = 0"
nipkow@24506: by (simp add: sgn_div_norm)
huffman@22972: 
nipkow@24506: lemma sgn_zero_iff: "(sgn(x::'a::real_normed_vector) = 0) = (x = 0)"
nipkow@24506: by (simp add: sgn_div_norm)
huffman@22972: 
nipkow@24506: lemma sgn_minus: "sgn (- x) = - sgn(x::'a::real_normed_vector)"
nipkow@24506: by (simp add: sgn_div_norm)
huffman@22972: 
nipkow@24506: lemma sgn_scaleR:
nipkow@24506:   "sgn (scaleR r x) = scaleR (sgn r) (sgn(x::'a::real_normed_vector))"
nipkow@24506: by (simp add: sgn_div_norm norm_scaleR mult_ac)
huffman@22973: 
huffman@22972: lemma sgn_one [simp]: "sgn (1::'a::real_normed_algebra_1) = 1"
nipkow@24506: by (simp add: sgn_div_norm)
huffman@22972: 
huffman@22972: lemma sgn_of_real:
huffman@22972:   "sgn (of_real r::'a::real_normed_algebra_1) = of_real (sgn r)"
huffman@22972: unfolding of_real_def by (simp only: sgn_scaleR sgn_one)
huffman@22972: 
huffman@22973: lemma sgn_mult:
huffman@22973:   fixes x y :: "'a::real_normed_div_algebra"
huffman@22973:   shows "sgn (x * y) = sgn x * sgn y"
nipkow@24506: by (simp add: sgn_div_norm norm_mult mult_commute)
huffman@22973: 
huffman@22972: lemma real_sgn_eq: "sgn (x::real) = x / \<bar>x\<bar>"
nipkow@24506: by (simp add: sgn_div_norm divide_inverse)
huffman@22972: 
huffman@22972: lemma real_sgn_pos: "0 < (x::real) \<Longrightarrow> sgn x = 1"
huffman@22972: unfolding real_sgn_eq by simp
huffman@22972: 
huffman@22972: lemma real_sgn_neg: "(x::real) < 0 \<Longrightarrow> sgn x = -1"
huffman@22972: unfolding real_sgn_eq by simp
huffman@22972: 
huffman@22972: 
huffman@22442: subsection {* Bounded Linear and Bilinear Operators *}
huffman@22442: 
huffman@22442: locale bounded_linear = additive +
huffman@22442:   constrains f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
huffman@22442:   assumes scaleR: "f (scaleR r x) = scaleR r (f x)"
huffman@22442:   assumes bounded: "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K"
huffman@27443: begin
huffman@22442: 
huffman@27443: lemma pos_bounded:
huffman@22442:   "\<exists>K>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442: proof -
huffman@22442:   obtain K where K: "\<And>x. norm (f x) \<le> norm x * K"
huffman@22442:     using bounded by fast
huffman@22442:   show ?thesis
huffman@22442:   proof (intro exI impI conjI allI)
huffman@22442:     show "0 < max 1 K"
huffman@22442:       by (rule order_less_le_trans [OF zero_less_one le_maxI1])
huffman@22442:   next
huffman@22442:     fix x
huffman@22442:     have "norm (f x) \<le> norm x * K" using K .
huffman@22442:     also have "\<dots> \<le> norm x * max 1 K"
huffman@22442:       by (rule mult_left_mono [OF le_maxI2 norm_ge_zero])
huffman@22442:     finally show "norm (f x) \<le> norm x * max 1 K" .
huffman@22442:   qed
huffman@22442: qed
huffman@22442: 
huffman@27443: lemma nonneg_bounded:
huffman@22442:   "\<exists>K\<ge>0. \<forall>x. norm (f x) \<le> norm x * K"
huffman@22442: proof -
huffman@22442:   from pos_bounded
huffman@22442:   show ?thesis by (auto intro: order_less_imp_le)
huffman@22442: qed
huffman@22442: 
huffman@27443: end
huffman@27443: 
huffman@22442: locale bounded_bilinear =
huffman@22442:   fixes prod :: "['a::real_normed_vector, 'b::real_normed_vector]
huffman@22442:                  \<Rightarrow> 'c::real_normed_vector"
huffman@22442:     (infixl "**" 70)
huffman@22442:   assumes add_left: "prod (a + a') b = prod a b + prod a' b"
huffman@22442:   assumes add_right: "prod a (b + b') = prod a b + prod a b'"
huffman@22442:   assumes scaleR_left: "prod (scaleR r a) b = scaleR r (prod a b)"
huffman@22442:   assumes scaleR_right: "prod a (scaleR r b) = scaleR r (prod a b)"
huffman@22442:   assumes bounded: "\<exists>K. \<forall>a b. norm (prod a b) \<le> norm a * norm b * K"
huffman@27443: begin
huffman@22442: 
huffman@27443: lemma pos_bounded:
huffman@22442:   "\<exists>K>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442: apply (cut_tac bounded, erule exE)
huffman@22442: apply (rule_tac x="max 1 K" in exI, safe)
huffman@22442: apply (rule order_less_le_trans [OF zero_less_one le_maxI1])
huffman@22442: apply (drule spec, drule spec, erule order_trans)
huffman@22442: apply (rule mult_left_mono [OF le_maxI2])
huffman@22442: apply (intro mult_nonneg_nonneg norm_ge_zero)
huffman@22442: done
huffman@22442: 
huffman@27443: lemma nonneg_bounded:
huffman@22442:   "\<exists>K\<ge>0. \<forall>a b. norm (a ** b) \<le> norm a * norm b * K"
huffman@22442: proof -
huffman@22442:   from pos_bounded
huffman@22442:   show ?thesis by (auto intro: order_less_imp_le)
huffman@22442: qed
huffman@22442: 
huffman@27443: lemma additive_right: "additive (\<lambda>b. prod a b)"
huffman@22442: by (rule additive.intro, rule add_right)
huffman@22442: 
huffman@27443: lemma additive_left: "additive (\<lambda>a. prod a b)"
huffman@22442: by (rule additive.intro, rule add_left)
huffman@22442: 
huffman@27443: lemma zero_left: "prod 0 b = 0"
huffman@22442: by (rule additive.zero [OF additive_left])
huffman@22442: 
huffman@27443: lemma zero_right: "prod a 0 = 0"
huffman@22442: by (rule additive.zero [OF additive_right])
huffman@22442: 
huffman@27443: lemma minus_left: "prod (- a) b = - prod a b"
huffman@22442: by (rule additive.minus [OF additive_left])
huffman@22442: 
huffman@27443: lemma minus_right: "prod a (- b) = - prod a b"
huffman@22442: by (rule additive.minus [OF additive_right])
huffman@22442: 
huffman@27443: lemma diff_left:
huffman@22442:   "prod (a - a') b = prod a b - prod a' b"
huffman@22442: by (rule additive.diff [OF additive_left])
huffman@22442: 
huffman@27443: lemma diff_right:
huffman@22442:   "prod a (b - b') = prod a b - prod a b'"
huffman@22442: by (rule additive.diff [OF additive_right])
huffman@22442: 
huffman@27443: lemma bounded_linear_left:
huffman@22442:   "bounded_linear (\<lambda>a. a ** b)"
huffman@22442: apply (unfold_locales)
huffman@22442: apply (rule add_left)
huffman@22442: apply (rule scaleR_left)
huffman@22442: apply (cut_tac bounded, safe)
huffman@22442: apply (rule_tac x="norm b * K" in exI)
huffman@22442: apply (simp add: mult_ac)
huffman@22442: done
huffman@22442: 
huffman@27443: lemma bounded_linear_right:
huffman@22442:   "bounded_linear (\<lambda>b. a ** b)"
huffman@22442: apply (unfold_locales)
huffman@22442: apply (rule add_right)
huffman@22442: apply (rule scaleR_right)
huffman@22442: apply (cut_tac bounded, safe)
huffman@22442: apply (rule_tac x="norm a * K" in exI)
huffman@22442: apply (simp add: mult_ac)
huffman@22442: done
huffman@22442: 
huffman@27443: lemma prod_diff_prod:
huffman@22442:   "(x ** y - a ** b) = (x - a) ** (y - b) + (x - a) ** b + a ** (y - b)"
huffman@22442: by (simp add: diff_left diff_right)
huffman@22442: 
huffman@27443: end
huffman@27443: 
ballarin@29233: interpretation mult!:
ballarin@29229:   bounded_bilinear "op * :: 'a \<Rightarrow> 'a \<Rightarrow> 'a::real_normed_algebra"
huffman@22442: apply (rule bounded_bilinear.intro)
huffman@22442: apply (rule left_distrib)
huffman@22442: apply (rule right_distrib)
huffman@22442: apply (rule mult_scaleR_left)
huffman@22442: apply (rule mult_scaleR_right)
huffman@22442: apply (rule_tac x="1" in exI)
huffman@22442: apply (simp add: norm_mult_ineq)
huffman@22442: done
huffman@22442: 
ballarin@29233: interpretation mult_left!:
ballarin@29229:   bounded_linear "(\<lambda>x::'a::real_normed_algebra. x * y)"
huffman@23127: by (rule mult.bounded_linear_left)
huffman@22442: 
ballarin@29233: interpretation mult_right!:
ballarin@29229:   bounded_linear "(\<lambda>y::'a::real_normed_algebra. x * y)"
huffman@23127: by (rule mult.bounded_linear_right)
huffman@23127: 
ballarin@29233: interpretation divide!:
ballarin@29229:   bounded_linear "(\<lambda>x::'a::real_normed_field. x / y)"
huffman@23127: unfolding divide_inverse by (rule mult.bounded_linear_left)
huffman@23120: 
ballarin@29233: interpretation scaleR!: bounded_bilinear "scaleR"
huffman@22442: apply (rule bounded_bilinear.intro)
huffman@22442: apply (rule scaleR_left_distrib)
huffman@22442: apply (rule scaleR_right_distrib)
huffman@22973: apply simp
huffman@22442: apply (rule scaleR_left_commute)
huffman@22442: apply (rule_tac x="1" in exI)
huffman@22442: apply (simp add: norm_scaleR)
huffman@22442: done
huffman@22442: 
ballarin@29233: interpretation scaleR_left!: bounded_linear "\<lambda>r. scaleR r x"
huffman@23127: by (rule scaleR.bounded_linear_left)
huffman@23127: 
ballarin@29233: interpretation scaleR_right!: bounded_linear "\<lambda>x. scaleR r x"
huffman@23127: by (rule scaleR.bounded_linear_right)
huffman@23127: 
ballarin@29233: interpretation of_real!: bounded_linear "\<lambda>r. of_real r"
huffman@23127: unfolding of_real_def by (rule scaleR.bounded_linear_left)
huffman@22625: 
huffman@20504: end




