src/HOL/Multivariate_Analysis/Linear_Algebra.thy
changeset 53077 a1b3784f8129
parent 53015 a1119cf551e8
child 53406 d4374a69ddff
equal deleted inserted replaced
53076:47c9aff07725 53077:a1b3784f8129
    15 
    15 
    16 notation inner (infix "\<bullet>" 70)
    16 notation inner (infix "\<bullet>" 70)
    17 
    17 
    18 lemma square_bound_lemma: "(x::real) < (1 + x) * (1 + x)"
    18 lemma square_bound_lemma: "(x::real) < (1 + x) * (1 + x)"
    19 proof -
    19 proof -
    20   have "(x + 1/2)^2 + 3/4 > 0" using zero_le_power2[of "x+1/2"] by arith
    20   have "(x + 1/2)\<^sup>2 + 3/4 > 0" using zero_le_power2[of "x+1/2"] by arith
    21   then show ?thesis by (simp add: field_simps power2_eq_square)
    21   then show ?thesis by (simp add: field_simps power2_eq_square)
    22 qed
    22 qed
    23 
    23 
    24 lemma square_continuous: "0 < (e::real) ==> \<exists>d. 0 < d \<and> (\<forall>y. abs(y - x) < d \<longrightarrow> abs(y * y - x * x) < e)"
    24 lemma square_continuous: "0 < (e::real) ==> \<exists>d. 0 < d \<and> (\<forall>y. abs(y - x) < d \<longrightarrow> abs(y * y - x * x) < e)"
    25   using isCont_power[OF isCont_ident, of x, unfolded isCont_def LIM_eq, rule_format, of e 2]
    25   using isCont_power[OF isCont_ident, of x, unfolded isCont_def LIM_eq, rule_format, of e 2]
    28   apply auto
    28   apply auto
    29   apply (erule_tac x=y in allE)
    29   apply (erule_tac x=y in allE)
    30   apply auto
    30   apply auto
    31   done
    31   done
    32 
    32 
    33 lemma real_le_lsqrt: "0 <= x \<Longrightarrow> 0 <= y \<Longrightarrow> x <= y^2 ==> sqrt x <= y"
    33 lemma real_le_lsqrt: "0 <= x \<Longrightarrow> 0 <= y \<Longrightarrow> x <= y\<^sup>2 ==> sqrt x <= y"
    34   using real_sqrt_le_iff[of x "y^2"] by simp
    34   using real_sqrt_le_iff[of x "y\<^sup>2"] by simp
    35 
    35 
    36 lemma real_le_rsqrt: "x^2 \<le> y \<Longrightarrow> x \<le> sqrt y"
    36 lemma real_le_rsqrt: "x\<^sup>2 \<le> y \<Longrightarrow> x \<le> sqrt y"
    37   using real_sqrt_le_mono[of "x^2" y] by simp
    37   using real_sqrt_le_mono[of "x\<^sup>2" y] by simp
    38 
    38 
    39 lemma real_less_rsqrt: "x^2 < y \<Longrightarrow> x < sqrt y"
    39 lemma real_less_rsqrt: "x\<^sup>2 < y \<Longrightarrow> x < sqrt y"
    40   using real_sqrt_less_mono[of "x^2" y] by simp
    40   using real_sqrt_less_mono[of "x\<^sup>2" y] by simp
    41 
    41 
    42 lemma sqrt_even_pow2:
    42 lemma sqrt_even_pow2:
    43   assumes n: "even n"
    43   assumes n: "even n"
    44   shows "sqrt(2 ^ n) = 2 ^ (n div 2)"
    44   shows "sqrt(2 ^ n) = 2 ^ (n div 2)"
    45 proof -
    45 proof -
    46   from n obtain m where m: "n = 2*m" unfolding even_mult_two_ex ..
    46   from n obtain m where m: "n = 2*m" unfolding even_mult_two_ex ..
    47   from m  have "sqrt(2 ^ n) = sqrt ((2 ^ m) ^ 2)"
    47   from m  have "sqrt(2 ^ n) = sqrt ((2 ^ m)\<^sup>2)"
    48     by (simp only: power_mult[symmetric] mult_commute)
    48     by (simp only: power_mult[symmetric] mult_commute)
    49   then show ?thesis  using m by simp
    49   then show ?thesis  using m by simp
    50 qed
    50 qed
    51 
    51 
    52 lemma real_div_sqrt: "0 <= x ==> x / sqrt(x) = sqrt(x)"
    52 lemma real_div_sqrt: "0 <= x ==> x / sqrt(x) = sqrt(x)"
    83 lemma norm_eq_1: "norm(x) = 1 \<longleftrightarrow> x \<bullet> x = 1"
    83 lemma norm_eq_1: "norm(x) = 1 \<longleftrightarrow> x \<bullet> x = 1"
    84   by (simp add: norm_eq_sqrt_inner)
    84   by (simp add: norm_eq_sqrt_inner)
    85 
    85 
    86 text{* Squaring equations and inequalities involving norms.  *}
    86 text{* Squaring equations and inequalities involving norms.  *}
    87 
    87 
    88 lemma dot_square_norm: "x \<bullet> x = norm(x)^2"
    88 lemma dot_square_norm: "x \<bullet> x = (norm x)\<^sup>2"
    89   by (simp only: power2_norm_eq_inner) (* TODO: move? *)
    89   by (simp only: power2_norm_eq_inner) (* TODO: move? *)
    90 
    90 
    91 lemma norm_eq_square: "norm(x) = a \<longleftrightarrow> 0 <= a \<and> x \<bullet> x = a^2"
    91 lemma norm_eq_square: "norm(x) = a \<longleftrightarrow> 0 <= a \<and> x \<bullet> x = a\<^sup>2"
    92   by (auto simp add: norm_eq_sqrt_inner)
    92   by (auto simp add: norm_eq_sqrt_inner)
    93 
    93 
    94 lemma real_abs_le_square_iff: "\<bar>x\<bar> \<le> \<bar>y\<bar> \<longleftrightarrow> (x::real)^2 \<le> y^2"
    94 lemma real_abs_le_square_iff: "\<bar>x\<bar> \<le> \<bar>y\<bar> \<longleftrightarrow> (x::real)\<^sup>2 \<le> y\<^sup>2"
    95 proof
    95 proof
    96   assume "\<bar>x\<bar> \<le> \<bar>y\<bar>"
    96   assume "\<bar>x\<bar> \<le> \<bar>y\<bar>"
    97   then have "\<bar>x\<bar>\<^sup>2 \<le> \<bar>y\<bar>\<^sup>2" by (rule power_mono, simp)
    97   then have "\<bar>x\<bar>\<^sup>2 \<le> \<bar>y\<bar>\<^sup>2" by (rule power_mono, simp)
    98   then show "x\<^sup>2 \<le> y\<^sup>2" by simp
    98   then show "x\<^sup>2 \<le> y\<^sup>2" by simp
    99 next
    99 next
   100   assume "x\<^sup>2 \<le> y\<^sup>2"
   100   assume "x\<^sup>2 \<le> y\<^sup>2"
   101   then have "sqrt (x\<^sup>2) \<le> sqrt (y\<^sup>2)" by (rule real_sqrt_le_mono)
   101   then have "sqrt (x\<^sup>2) \<le> sqrt (y\<^sup>2)" by (rule real_sqrt_le_mono)
   102   then show "\<bar>x\<bar> \<le> \<bar>y\<bar>" by simp
   102   then show "\<bar>x\<bar> \<le> \<bar>y\<bar>" by simp
   103 qed
   103 qed
   104 
   104 
   105 lemma norm_le_square: "norm(x) <= a \<longleftrightarrow> 0 <= a \<and> x \<bullet> x <= a^2"
   105 lemma norm_le_square: "norm(x) <= a \<longleftrightarrow> 0 <= a \<and> x \<bullet> x <= a\<^sup>2"
   106   apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric])
   106   apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric])
   107   using norm_ge_zero[of x]
   107   using norm_ge_zero[of x]
   108   apply arith
   108   apply arith
   109   done
   109   done
   110 
   110 
   111 lemma norm_ge_square: "norm(x) >= a \<longleftrightarrow> a <= 0 \<or> x \<bullet> x >= a ^ 2"
   111 lemma norm_ge_square: "norm(x) >= a \<longleftrightarrow> a <= 0 \<or> x \<bullet> x >= a\<^sup>2"
   112   apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric])
   112   apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric])
   113   using norm_ge_zero[of x]
   113   using norm_ge_zero[of x]
   114   apply arith
   114   apply arith
   115   done
   115   done
   116 
   116 
   117 lemma norm_lt_square: "norm(x) < a \<longleftrightarrow> 0 < a \<and> x \<bullet> x < a^2"
   117 lemma norm_lt_square: "norm(x) < a \<longleftrightarrow> 0 < a \<and> x \<bullet> x < a\<^sup>2"
   118   by (metis not_le norm_ge_square)
   118   by (metis not_le norm_ge_square)
   119 lemma norm_gt_square: "norm(x) > a \<longleftrightarrow> a < 0 \<or> x \<bullet> x > a^2"
   119 lemma norm_gt_square: "norm(x) > a \<longleftrightarrow> a < 0 \<or> x \<bullet> x > a\<^sup>2"
   120   by (metis norm_le_square not_less)
   120   by (metis norm_le_square not_less)
   121 
   121 
   122 text{* Dot product in terms of the norm rather than conversely. *}
   122 text{* Dot product in terms of the norm rather than conversely. *}
   123 
   123 
   124 lemmas inner_simps = inner_add_left inner_add_right inner_diff_right inner_diff_left 
   124 lemmas inner_simps = inner_add_left inner_add_right inner_diff_right inner_diff_left 
   125   inner_scaleR_left inner_scaleR_right
   125   inner_scaleR_left inner_scaleR_right
   126 
   126 
   127 lemma dot_norm: "x \<bullet> y = (norm(x + y) ^2 - norm x ^ 2 - norm y ^ 2) / 2"
   127 lemma dot_norm: "x \<bullet> y = ((norm (x + y))\<^sup>2 - (norm x)\<^sup>2 - (norm y)\<^sup>2) / 2"
   128   unfolding power2_norm_eq_inner inner_simps inner_commute by auto 
   128   unfolding power2_norm_eq_inner inner_simps inner_commute by auto 
   129 
   129 
   130 lemma dot_norm_neg: "x \<bullet> y = ((norm x ^ 2 + norm y ^ 2) - norm(x - y) ^ 2) / 2"
   130 lemma dot_norm_neg: "x \<bullet> y = (((norm x)\<^sup>2 + (norm y)\<^sup>2) - (norm (x - y))\<^sup>2) / 2"
   131   unfolding power2_norm_eq_inner inner_simps inner_commute
   131   unfolding power2_norm_eq_inner inner_simps inner_commute
   132   by (auto simp add: algebra_simps)
   132   by (auto simp add: algebra_simps)
   133 
   133 
   134 text{* Equality of vectors in terms of @{term "op \<bullet>"} products.    *}
   134 text{* Equality of vectors in terms of @{term "op \<bullet>"} products.    *}
   135 
   135 
   467   apply auto
   467   apply auto
   468   done
   468   done
   469 
   469 
   470 
   470 
   471 lemma triangle_lemma:
   471 lemma triangle_lemma:
   472   assumes x: "0 <= (x::real)" and y:"0 <= y" and z: "0 <= z" and xy: "x^2 <= y^2 + z^2"
   472   assumes x: "0 <= (x::real)" and y:"0 <= y" and z: "0 <= z" and xy: "x\<^sup>2 <= y\<^sup>2 + z\<^sup>2"
   473   shows "x <= y + z"
   473   shows "x <= y + z"
   474 proof -
   474 proof -
   475   have "y^2 + z^2 \<le> y^2 + 2*y*z + z^2" using z y by (simp add: mult_nonneg_nonneg)
   475   have "y\<^sup>2 + z\<^sup>2 \<le> y\<^sup>2 + 2*y*z + z\<^sup>2" using z y by (simp add: mult_nonneg_nonneg)
   476   with xy have th: "x ^2 \<le> (y+z)^2" by (simp add: power2_eq_square field_simps)
   476   with xy have th: "x\<^sup>2 \<le> (y+z)\<^sup>2" by (simp add: power2_eq_square field_simps)
   477   from y z have yz: "y + z \<ge> 0" by arith
   477   from y z have yz: "y + z \<ge> 0" by arith
   478   from power2_le_imp_le[OF th yz] show ?thesis .
   478   from power2_le_imp_le[OF th yz] show ?thesis .
   479 qed
   479 qed
   480 
   480 
   481 
   481 
  2590 
  2590 
  2591 lemma norm_le_infnorm: "norm x \<le> sqrt DIM('a) * infnorm(x::'a::euclidean_space)"
  2591 lemma norm_le_infnorm: "norm x \<le> sqrt DIM('a) * infnorm(x::'a::euclidean_space)"
  2592 proof -
  2592 proof -
  2593   let ?d = "DIM('a)"
  2593   let ?d = "DIM('a)"
  2594   have "real ?d \<ge> 0" by simp
  2594   have "real ?d \<ge> 0" by simp
  2595   then have d2: "(sqrt (real ?d))^2 = real ?d"
  2595   then have d2: "(sqrt (real ?d))\<^sup>2 = real ?d"
  2596     by (auto intro: real_sqrt_pow2)
  2596     by (auto intro: real_sqrt_pow2)
  2597   have th: "sqrt (real ?d) * infnorm x \<ge> 0"
  2597   have th: "sqrt (real ?d) * infnorm x \<ge> 0"
  2598     by (simp add: zero_le_mult_iff infnorm_pos_le)
  2598     by (simp add: zero_le_mult_iff infnorm_pos_le)
  2599   have th1: "x \<bullet> x \<le> (sqrt (real ?d) * infnorm x)^2"
  2599   have th1: "x \<bullet> x \<le> (sqrt (real ?d) * infnorm x)\<^sup>2"
  2600     unfolding power_mult_distrib d2
  2600     unfolding power_mult_distrib d2
  2601     unfolding real_of_nat_def
  2601     unfolding real_of_nat_def
  2602     apply(subst euclidean_inner)
  2602     apply(subst euclidean_inner)
  2603     apply (subst power2_abs[symmetric])
  2603     apply (subst power2_abs[symmetric])
  2604     apply (rule order_trans[OF setsum_bounded[where K="\<bar>infnorm x\<bar>\<^sup>2"]])
  2604     apply (rule order_trans[OF setsum_bounded[where K="\<bar>infnorm x\<bar>\<^sup>2"]])
  2678   { assume x: "x \<noteq> 0" and y: "y \<noteq> 0"
  2678   { assume x: "x \<noteq> 0" and y: "y \<noteq> 0"
  2679     then have "norm x \<noteq> 0" "norm y \<noteq> 0"
  2679     then have "norm x \<noteq> 0" "norm y \<noteq> 0"
  2680       by simp_all
  2680       by simp_all
  2681     then have n: "norm x > 0" "norm y > 0"
  2681     then have n: "norm x > 0" "norm y > 0"
  2682       using norm_ge_zero[of x] norm_ge_zero[of y] by arith+
  2682       using norm_ge_zero[of x] norm_ge_zero[of y] by arith+
  2683     have th: "\<And>(a::real) b c. a + b + c \<noteq> 0 ==> (a = b + c \<longleftrightarrow> a^2 = (b + c)^2)"
  2683     have th: "\<And>(a::real) b c. a + b + c \<noteq> 0 ==> (a = b + c \<longleftrightarrow> a\<^sup>2 = (b + c)\<^sup>2)"
  2684       by algebra
  2684       by algebra
  2685     have "norm(x + y) = norm x + norm y \<longleftrightarrow> norm(x + y)^ 2 = (norm x + norm y) ^2"
  2685     have "norm (x + y) = norm x + norm y \<longleftrightarrow> (norm (x + y))\<^sup>2 = (norm x + norm y)\<^sup>2"
  2686       apply (rule th) using n norm_ge_zero[of "x + y"]
  2686       apply (rule th) using n norm_ge_zero[of "x + y"]
  2687       apply arith
  2687       apply arith
  2688       done
  2688       done
  2689     also have "\<dots> \<longleftrightarrow> norm x *\<^sub>R y = norm y *\<^sub>R x"
  2689     also have "\<dots> \<longleftrightarrow> norm x *\<^sub>R y = norm y *\<^sub>R x"
  2690       unfolding norm_cauchy_schwarz_eq[symmetric]
  2690       unfolding norm_cauchy_schwarz_eq[symmetric]