src/HOL/Analysis/Linear_Algebra.thy
 changeset 68062 ee88c0fccbae parent 68058 69715dfdc286 child 68069 36209dfb981e
```     1.1 --- a/src/HOL/Analysis/Linear_Algebra.thy	Tue May 01 16:42:14 2018 +0200
1.2 +++ b/src/HOL/Analysis/Linear_Algebra.thy	Tue May 01 23:25:00 2018 +0100
1.3 @@ -27,13 +27,6 @@
1.4    show "f (s *\<^sub>R v) = s *\<^sub>R (f v)" by (rule f.scaleR)
1.5  qed
1.6
1.7 -lemma bounded_linearI:
1.8 -  assumes "\<And>x y. f (x + y) = f x + f y"
1.9 -    and "\<And>r x. f (r *\<^sub>R x) = r *\<^sub>R f x"
1.10 -    and "\<And>x. norm (f x) \<le> norm x * K"
1.11 -  shows "bounded_linear f"
1.12 -  using assms by (rule bounded_linear_intro) (* FIXME: duplicate *)
1.13 -
1.14  subsection \<open>A generic notion of "hull" (convex, affine, conic hull and closure).\<close>
1.15
1.16  definition%important hull :: "('a set \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set"  (infixl "hull" 75)
1.17 @@ -2514,35 +2507,27 @@
1.18      and fx: "f x = 0"
1.19    shows "x = 0"
1.20    using fB ifB fi xsB fx
1.21 -proof (induct arbitrary: x rule: finite_induct[OF fB])
1.22 -  case 1
1.23 +proof (induction B arbitrary: x rule: finite_induct)
1.24 +  case empty
1.25    then show ?case by auto
1.26  next
1.27 -  case (2 a b x)
1.28 -  have fb: "finite b" using "2.prems" by simp
1.29 +  case (insert a b x)
1.30    have th0: "f ` b \<subseteq> f ` (insert a b)"
1.31 -    apply (rule image_mono)
1.32 -    apply blast
1.33 -    done
1.34 -  from independent_mono[ OF "2.prems"(2) th0]
1.35 -  have ifb: "independent (f ` b)"  .
1.36 +    by (simp add: subset_insertI)
1.37 +  have ifb: "independent (f ` b)"
1.38 +    using independent_mono insert.prems(1) th0 by blast
1.39    have fib: "inj_on f b"
1.40 -    apply (rule subset_inj_on [OF "2.prems"(3)])
1.41 -    apply blast
1.42 -    done
1.43 -  from span_breakdown[of a "insert a b", simplified, OF "2.prems"(4)]
1.44 +    using insert.prems(2) by blast
1.45 +  from span_breakdown[of a "insert a b", simplified, OF insert.prems(3)]
1.46    obtain k where k: "x - k*\<^sub>R a \<in> span (b - {a})"
1.47      by blast
1.48    have "f (x - k*\<^sub>R a) \<in> span (f ` b)"
1.49      unfolding span_linear_image[OF lf]
1.50 -    apply (rule imageI)
1.51 -    using k span_mono[of "b - {a}" b]
1.52 -    apply blast
1.53 -    done
1.54 +    using "insert.hyps"(2) k by auto
1.55    then have "f x - k*\<^sub>R f a \<in> span (f ` b)"
1.56      by (simp add: linear_diff[OF lf] linear_cmul[OF lf])
1.57    then have th: "-k *\<^sub>R f a \<in> span (f ` b)"
1.58 -    using "2.prems"(5) by simp
1.59 +    using insert.prems(4) by simp
1.60    have xsb: "x \<in> span b"
1.61    proof (cases "k = 0")
1.62      case True
1.63 @@ -2551,19 +2536,18 @@
1.64        by blast
1.65    next
1.66      case False
1.67 -    with span_mul[OF th, of "- 1/ k"]
1.68 -    have th1: "f a \<in> span (f ` b)"
1.69 -      by auto
1.70 -    from inj_on_image_set_diff[OF "2.prems"(3), of "insert a b " "{a}", symmetric]
1.71 -    have tha: "f ` insert a b - f ` {a} = f ` (insert a b - {a})" by blast
1.72 -    from "2.prems"(2) [unfolded dependent_def bex_simps(8), rule_format, of "f a"]
1.73 -    have "f a \<notin> span (f ` b)" using tha
1.74 -      using "2.hyps"(2)
1.75 -      "2.prems"(3) by auto
1.76 -    with th1 have False by blast
1.77 +    from inj_on_image_set_diff[OF insert.prems(2), of "insert a b " "{a}", symmetric]
1.78 +    have "f ` insert a b - f ` {a} = f ` (insert a b - {a})" by blast
1.79 +    then have "f a \<notin> span (f ` b)"
1.80 +      using dependent_def insert.hyps(2) insert.prems(1) by fastforce
1.81 +    moreover have "f a \<in> span (f ` b)"
1.82 +      using False span_mul[OF th, of "- 1/ k"] by auto
1.83 +    ultimately have False
1.84 +      by blast
1.85      then show ?thesis by blast
1.86    qed
1.87 -  from "2.hyps"(3)[OF fb ifb fib xsb "2.prems"(5)] show "x = 0" .
1.88 +  show "x = 0"
1.89 +    using ifb fib xsb insert.IH insert.prems(4) by blast
1.90  qed
1.91
1.92  text \<open>Can construct an isomorphism between spaces of same dimension.\<close>
1.93 @@ -2644,9 +2628,8 @@
1.94    let ?P = "{x. \<forall>y\<in> span C. f x y = g x y}"
1.95    from bf bg have sp: "subspace ?P"
1.96      unfolding bilinear_def linear_iff subspace_def bf bg
1.97 -    by (auto simp add: span_0 bilinear_lzero[OF bf] bilinear_lzero[OF bg] span_add Ball_def
1.98 +    by (auto simp add: bilinear_lzero[OF bf] bilinear_lzero[OF bg] span_add
1.99        intro: bilinear_ladd[OF bf])
1.100 -
1.101    have sfg: "\<And>x. x \<in> B \<Longrightarrow> subspace {a. f x a = g x a}"
1.102      apply (auto simp add: subspace_def)
1.103      using bf bg unfolding bilinear_def linear_iff
1.104 @@ -2655,10 +2638,7 @@
1.105      done
1.106    have "\<forall>y\<in> span C. f x y = g x y" if "x \<in> span B" for x
1.107      apply (rule span_induct [OF that sp])
1.108 -    apply (rule ballI)
1.109 -    apply (erule span_induct)
1.110 -    apply (simp_all add: sfg fg)
1.111 -    done
1.112 +    using fg sfg span_induct by blast
1.113    then show ?thesis
1.114      using SB TC assms by auto
1.115  qed
1.116 @@ -2707,11 +2687,8 @@
1.117    (is "?lhs \<longleftrightarrow> ?rhs")
1.118  proof
1.119    assume h: "?lhs"
1.120 -  {
1.121 -    fix x y
1.122 -    assume x: "x \<in> S"
1.123 -    assume y: "y \<in> S"
1.124 -    assume f: "f x = f y"
1.125 +  { fix x y
1.126 +    assume x: "x \<in> S" and y: "y \<in> S" and f: "f x = f y"
1.127      from x fS have S0: "card S \<noteq> 0"
1.128        by auto
1.129      have "x = y"
1.130 @@ -2719,15 +2696,13 @@
1.131        assume xy: "\<not> ?thesis"
1.132        have th: "card S \<le> card (f ` (S - {y}))"
1.133          unfolding c
1.134 -        apply (rule card_mono)
1.135 -        apply (rule finite_imageI)
1.136 -        using fS apply simp
1.137 -        using h xy x y f unfolding subset_eq image_iff
1.138 -        apply auto
1.139 -        apply (case_tac "xa = f x")
1.140 -        apply (rule bexI[where x=x])
1.141 -        apply auto
1.142 -        done
1.143 +      proof (rule card_mono)
1.144 +        show "finite (f ` (S - {y}))"
1.145 +          by (simp add: fS)
1.146 +        show "T \<subseteq> f ` (S - {y})"
1.147 +          using h xy x y f unfolding subset_eq image_iff
1.148 +          by (metis member_remove remove_def)
1.149 +      qed
1.150        also have " \<dots> \<le> card (S - {y})"
1.151          apply (rule card_image_le)
1.152          using fS by simp
1.153 @@ -2740,17 +2715,13 @@
1.154  next
1.155    assume h: ?rhs
1.156    have "f ` S = T"
1.157 -    apply (rule card_subset_eq[OF fT ST])
1.158 -    unfolding card_image[OF h]
1.159 -    apply (rule c)
1.160 -    done
1.161 +    by (simp add: ST c card_image card_subset_eq fT h)
1.162    then show ?lhs by blast
1.163  qed
1.164
1.165  lemma linear_surjective_imp_injective:
1.166    fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"
1.167 -  assumes lf: "linear f"
1.168 -    and sf: "surj f"
1.169 +  assumes lf: "linear f" and sf: "surj f"
1.170    shows "inj f"
1.171  proof -
1.172    let ?U = "UNIV :: 'a set"
1.173 @@ -2759,46 +2730,29 @@
1.174      by blast
1.175    {
1.176      fix x
1.177 -    assume x: "x \<in> span B"
1.178 -    assume fx: "f x = 0"
1.179 +    assume x: "x \<in> span B" and fx: "f x = 0"
1.180      from B(2) have fB: "finite B"
1.181        using independent_bound by auto
1.182 +    have Uspan: "UNIV \<subseteq> span (f ` B)"
1.183 +      by (simp add: B(3) lf sf spanning_surjective_image)
1.184      have fBi: "independent (f ` B)"
1.185 -      apply (rule card_le_dim_spanning[of "f ` B" ?U])
1.186 -      apply blast
1.187 -      using sf B(3)
1.188 -      unfolding span_linear_image[OF lf] surj_def subset_eq image_iff
1.189 -      apply blast
1.190 -      using fB apply blast
1.191 -      unfolding d[symmetric]
1.192 -      apply (rule card_image_le)
1.193 -      apply (rule fB)
1.194 -      done
1.195 +    proof (rule card_le_dim_spanning)
1.196 +      show "card (f ` B) \<le> dim ?U"
1.197 +        using card_image_le d fB by fastforce
1.198 +    qed (use fB Uspan in auto)
1.199      have th0: "dim ?U \<le> card (f ` B)"
1.200 -      apply (rule span_card_ge_dim)
1.201 -      apply blast
1.202 -      unfolding span_linear_image[OF lf]
1.203 -      apply (rule subset_trans[where B = "f ` UNIV"])
1.204 -      using sf unfolding surj_def
1.205 -      apply blast
1.206 -      apply (rule image_mono)
1.207 -      apply (rule B(3))
1.208 -      apply (metis finite_imageI fB)
1.209 -      done
1.210 +      by (rule span_card_ge_dim) (use Uspan fB in auto)
1.211      moreover have "card (f ` B) \<le> card B"
1.212        by (rule card_image_le, rule fB)
1.213      ultimately have th1: "card B = card (f ` B)"
1.214        unfolding d by arith
1.215      have fiB: "inj_on f B"
1.216 -      unfolding surjective_iff_injective_gen[OF fB finite_imageI[OF fB] th1 subset_refl, symmetric]
1.217 -      by blast
1.218 +      by (simp add: eq_card_imp_inj_on fB th1)
1.219      from linear_indep_image_lemma[OF lf fB fBi fiB x] fx
1.220      have "x = 0" by blast
1.221    }
1.222    then show ?thesis
1.223 -    unfolding linear_injective_0[OF lf]
1.224 -    using B(3)
1.225 -    by blast
1.226 +    unfolding linear_injective_0[OF lf] using B(3) by blast
1.227  qed
1.228
1.229  text \<open>Hence either is enough for isomorphism.\<close>
1.230 @@ -2854,9 +2808,7 @@
1.231      assume lf: "linear f" "linear f'"
1.232      assume f: "f \<circ> f' = id"
1.233      from f have sf: "surj f"
1.234 -      apply (auto simp add: o_def id_def surj_def)
1.235 -      apply metis
1.236 -      done
1.237 +      by (auto simp add: o_def id_def surj_def) metis
1.238      from linear_surjective_isomorphism[OF lf(1) sf] lf f
1.239      have "f' \<circ> f = id"
1.240        unfolding fun_eq_iff o_def id_def by metis
1.241 @@ -2874,18 +2826,13 @@
1.242    shows "linear g"
1.243  proof -
1.244    from gf have fi: "inj f"
1.245 -    apply (auto simp add: inj_on_def o_def id_def fun_eq_iff)
1.246 -    apply metis
1.247 -    done
1.248 +    by (auto simp add: inj_on_def o_def id_def fun_eq_iff) metis
1.249    from linear_injective_isomorphism[OF lf fi]
1.250 -  obtain h :: "'a \<Rightarrow> 'a" where h: "linear h" "\<forall>x. h (f x) = x" "\<forall>x. f (h x) = x"
1.251 +  obtain h :: "'a \<Rightarrow> 'a" where "linear h" and h: "\<forall>x. h (f x) = x" "\<forall>x. f (h x) = x"
1.252      by blast
1.253    have "h = g"
1.254 -    apply (rule ext) using gf h(2,3)
1.255 -    apply (simp add: o_def id_def fun_eq_iff)
1.256 -    apply metis
1.257 -    done
1.258 -  with h(1) show ?thesis by blast
1.259 +    by (metis gf h isomorphism_expand left_right_inverse_eq)
1.260 +  with \<open>linear h\<close> show ?thesis by blast
1.261  qed
1.262
1.263  lemma inj_linear_imp_inv_linear:
1.264 @@ -2944,28 +2891,21 @@
1.265    by (simp add: infnorm_eq_0)
1.266
1.267  lemma infnorm_neg: "infnorm (- x) = infnorm x"
1.268 -  unfolding infnorm_def
1.269 -  apply (rule cong[of "Sup" "Sup"])
1.270 -  apply blast
1.271 -  apply auto
1.272 -  done
1.273 +  unfolding infnorm_def by simp
1.274
1.275  lemma infnorm_sub: "infnorm (x - y) = infnorm (y - x)"
1.276 -proof -
1.277 -  have "y - x = - (x - y)" by simp
1.278 -  then show ?thesis
1.279 -    by (metis infnorm_neg)
1.280 -qed
1.281 -
1.282 -lemma real_abs_sub_infnorm: "\<bar>infnorm x - infnorm y\<bar> \<le> infnorm (x - y)"
1.283 +  by (metis infnorm_neg minus_diff_eq)
1.284 +
1.285 +lemma absdiff_infnorm: "\<bar>infnorm x - infnorm y\<bar> \<le> infnorm (x - y)"
1.286  proof -
1.287 -  have th: "\<And>(nx::real) n ny. nx \<le> n + ny \<Longrightarrow> ny \<le> n + nx \<Longrightarrow> \<bar>nx - ny\<bar> \<le> n"
1.288 +  have *: "\<And>(nx::real) n ny. nx \<le> n + ny \<Longrightarrow> ny \<le> n + nx \<Longrightarrow> \<bar>nx - ny\<bar> \<le> n"
1.289      by arith
1.290 -  from infnorm_triangle[of "x - y" " y"] infnorm_triangle[of "x - y" "-x"]
1.291 -  have ths: "infnorm x \<le> infnorm (x - y) + infnorm y"
1.292 -    "infnorm y \<le> infnorm (x - y) + infnorm x"
1.293 -    by (simp_all add: field_simps infnorm_neg)
1.294 -  from th[OF ths] show ?thesis .
1.295 +  show ?thesis
1.296 +  proof (rule *)
1.297 +    from infnorm_triangle[of "x - y" " y"] infnorm_triangle[of "x - y" "-x"]
1.298 +    show "infnorm x \<le> infnorm (x - y) + infnorm y" "infnorm y \<le> infnorm (x - y) + infnorm x"
1.299 +      by (simp_all add: field_simps infnorm_neg)
1.300 +  qed
1.301  qed
1.302
1.303  lemma real_abs_infnorm: "\<bar>infnorm x\<bar> = infnorm x"
1.304 @@ -2980,8 +2920,7 @@
1.305    unfolding infnorm_Max
1.306  proof (safe intro!: Max_eqI)
1.307    let ?B = "(\<lambda>i. \<bar>x \<bullet> i\<bar>) ` Basis"
1.308 -  {
1.309 -    fix b :: 'a
1.310 +  { fix b :: 'a
1.311      assume "b \<in> Basis"
1.312      then show "\<bar>a *\<^sub>R x \<bullet> b\<bar> \<le> \<bar>a\<bar> * Max ?B"
1.313        by (simp add: abs_mult mult_left_mono)
1.314 @@ -3007,27 +2946,17 @@
1.315  lemma norm_le_infnorm:
1.316    fixes x :: "'a::euclidean_space"
1.317    shows "norm x \<le> sqrt DIM('a) * infnorm x"
1.318 -proof -
1.319 -  let ?d = "DIM('a)"
1.320 -  have "real ?d \<ge> 0"
1.321 -    by simp
1.322 -  then have d2: "(sqrt (real ?d))\<^sup>2 = real ?d"
1.323 -    by (auto intro: real_sqrt_pow2)
1.324 -  have th: "sqrt (real ?d) * infnorm x \<ge> 0"
1.325 +  unfolding norm_eq_sqrt_inner id_def
1.326 +proof (rule real_le_lsqrt[OF inner_ge_zero])
1.327 +  show "sqrt DIM('a) * infnorm x \<ge> 0"
1.328      by (simp add: zero_le_mult_iff infnorm_pos_le)
1.329 -  have th1: "x \<bullet> x \<le> (sqrt (real ?d) * infnorm x)\<^sup>2"
1.330 -    unfolding power_mult_distrib d2
1.331 -    apply (subst euclidean_inner)
1.332 -    apply (subst power2_abs[symmetric])
1.333 -    apply (rule order_trans[OF sum_bounded_above[where K="\<bar>infnorm x\<bar>\<^sup>2"]])
1.334 -    apply (auto simp add: power2_eq_square[symmetric])
1.335 -    apply (subst power2_abs[symmetric])
1.336 -    apply (rule power_mono)
1.337 -    apply (auto simp: infnorm_Max)
1.338 -    done
1.339 -  from real_le_lsqrt[OF inner_ge_zero th th1]
1.340 -  show ?thesis
1.341 -    unfolding norm_eq_sqrt_inner id_def .
1.342 +  have "x \<bullet> x \<le> (\<Sum>b\<in>Basis. x \<bullet> b * (x \<bullet> b))"
1.343 +    by (metis euclidean_inner order_refl)
1.344 +  also have "... \<le> DIM('a) * \<bar>infnorm x\<bar>\<^sup>2"
1.345 +    by (rule sum_bounded_above) (metis Basis_le_infnorm abs_le_square_iff power2_eq_square real_abs_infnorm)
1.346 +  also have "... \<le> (sqrt DIM('a) * infnorm x)\<^sup>2"
1.347 +    by (simp add: power_mult_distrib)
1.348 +  finally show "x \<bullet> x \<le> (sqrt DIM('a) * infnorm x)\<^sup>2" .
1.349  qed
1.350
1.351  lemma tendsto_infnorm [tendsto_intros]:
1.352 @@ -3037,46 +2966,30 @@
1.353    fix r :: real
1.354    assume "r > 0"
1.355    then show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (infnorm x - infnorm a) < r"
1.356 -    by (metis real_norm_def le_less_trans real_abs_sub_infnorm infnorm_le_norm)
1.357 +    by (metis real_norm_def le_less_trans absdiff_infnorm infnorm_le_norm)
1.358  qed
1.359
1.360  text \<open>Equality in Cauchy-Schwarz and triangle inequalities.\<close>
1.361
1.362  lemma norm_cauchy_schwarz_eq: "x \<bullet> y = norm x * norm y \<longleftrightarrow> norm x *\<^sub>R y = norm y *\<^sub>R x"
1.363    (is "?lhs \<longleftrightarrow> ?rhs")
1.364 -proof -
1.365 -  {
1.366 -    assume h: "x = 0"
1.367 -    then have ?thesis by simp
1.368 -  }
1.369 -  moreover
1.370 -  {
1.371 -    assume h: "y = 0"
1.372 -    then have ?thesis by simp
1.373 -  }
1.374 -  moreover
1.375 -  {
1.376 -    assume x: "x \<noteq> 0" and y: "y \<noteq> 0"
1.377 -    from inner_eq_zero_iff[of "norm y *\<^sub>R x - norm x *\<^sub>R y"]
1.378 -    have "?rhs \<longleftrightarrow>
1.379 +proof (cases "x=0")
1.380 +  case True
1.381 +  then show ?thesis
1.382 +    by auto
1.383 +next
1.384 +  case False
1.385 +  from inner_eq_zero_iff[of "norm y *\<^sub>R x - norm x *\<^sub>R y"]
1.386 +  have "?rhs \<longleftrightarrow>
1.387        (norm y * (norm y * norm x * norm x - norm x * (x \<bullet> y)) -
1.388          norm x * (norm y * (y \<bullet> x) - norm x * norm y * norm y) =  0)"
1.389 -      using x y
1.390 -      unfolding inner_simps
1.391 -      unfolding power2_norm_eq_inner[symmetric] power2_eq_square right_minus_eq
1.392 -      apply (simp add: inner_commute)
1.393 -      apply (simp add: field_simps)
1.394 -      apply metis
1.395 -      done
1.396 -    also have "\<dots> \<longleftrightarrow> (2 * norm x * norm y * (norm x * norm y - x \<bullet> y) = 0)" using x y
1.397 -      by (simp add: field_simps inner_commute)
1.398 -    also have "\<dots> \<longleftrightarrow> ?lhs" using x y
1.399 -      apply simp
1.400 -      apply metis
1.401 -      done
1.402 -    finally have ?thesis by blast
1.403 -  }
1.404 -  ultimately show ?thesis by blast
1.405 +    using False unfolding inner_simps
1.406 +    by (auto simp add: power2_norm_eq_inner[symmetric] power2_eq_square inner_commute field_simps)
1.407 +  also have "\<dots> \<longleftrightarrow> (2 * norm x * norm y * (norm x * norm y - x \<bullet> y) = 0)"
1.408 +    using False  by (simp add: field_simps inner_commute)
1.409 +  also have "\<dots> \<longleftrightarrow> ?lhs"
1.410 +    using False by auto
1.411 +  finally show ?thesis by metis
1.412  qed
1.413
1.414  lemma norm_cauchy_schwarz_abs_eq:
1.415 @@ -3088,7 +3001,7 @@
1.416      by arith
1.417    have "?rhs \<longleftrightarrow> norm x *\<^sub>R y = norm y *\<^sub>R x \<or> norm (- x) *\<^sub>R y = norm y *\<^sub>R (- x)"
1.418      by simp
1.419 -  also have "\<dots> \<longleftrightarrow>(x \<bullet> y = norm x * norm y \<or> (- x) \<bullet> y = norm x * norm y)"
1.420 +  also have "\<dots> \<longleftrightarrow> (x \<bullet> y = norm x * norm y \<or> (- x) \<bullet> y = norm x * norm y)"
1.421      unfolding norm_cauchy_schwarz_eq[symmetric]
1.422      unfolding norm_minus_cancel norm_scaleR ..
1.423    also have "\<dots> \<longleftrightarrow> ?lhs"
1.424 @@ -3100,33 +3013,21 @@
1.425  lemma norm_triangle_eq:
1.426    fixes x y :: "'a::real_inner"
1.427    shows "norm (x + y) = norm x + norm y \<longleftrightarrow> norm x *\<^sub>R y = norm y *\<^sub>R x"
1.428 -proof -
1.429 -  {
1.430 -    assume x: "x = 0 \<or> y = 0"
1.431 -    then have ?thesis
1.432 -      by (cases "x = 0") simp_all
1.433 -  }
1.434 -  moreover
1.435 -  {
1.436 -    assume x: "x \<noteq> 0" and y: "y \<noteq> 0"
1.437 -    then have "norm x \<noteq> 0" "norm y \<noteq> 0"
1.438 -      by simp_all
1.439 -    then have n: "norm x > 0" "norm y > 0"
1.440 -      using norm_ge_zero[of x] norm_ge_zero[of y] by arith+
1.441 -    have th: "\<And>(a::real) b c. a + b + c \<noteq> 0 \<Longrightarrow> a = b + c \<longleftrightarrow> a\<^sup>2 = (b + c)\<^sup>2"
1.442 -      by algebra
1.443 -    have "norm (x + y) = norm x + norm y \<longleftrightarrow> (norm (x + y))\<^sup>2 = (norm x + norm y)\<^sup>2"
1.444 -      apply (rule th)
1.445 -      using n norm_ge_zero[of "x + y"]
1.446 -      apply arith
1.447 -      done
1.448 -    also have "\<dots> \<longleftrightarrow> norm x *\<^sub>R y = norm y *\<^sub>R x"
1.449 -      unfolding norm_cauchy_schwarz_eq[symmetric]
1.450 -      unfolding power2_norm_eq_inner inner_simps
1.451 -      by (simp add: power2_norm_eq_inner[symmetric] power2_eq_square inner_commute field_simps)
1.452 -    finally have ?thesis .
1.453 -  }
1.454 -  ultimately show ?thesis by blast
1.455 +proof (cases "x = 0 \<or> y = 0")
1.456 +  case True
1.457 +  then show ?thesis
1.458 +    by force
1.459 +next
1.460 +  case False
1.461 +  then have n: "norm x > 0" "norm y > 0"
1.462 +    by auto
1.463 +  have "norm (x + y) = norm x + norm y \<longleftrightarrow> (norm (x + y))\<^sup>2 = (norm x + norm y)\<^sup>2"
1.464 +    by simp
1.465 +  also have "\<dots> \<longleftrightarrow> norm x *\<^sub>R y = norm y *\<^sub>R x"
1.466 +    unfolding norm_cauchy_schwarz_eq[symmetric]
1.467 +    unfolding power2_norm_eq_inner inner_simps
1.468 +    by (simp add: power2_norm_eq_inner[symmetric] power2_eq_square inner_commute field_simps)
1.469 +  finally show ?thesis .
1.470  qed
1.471
1.472
1.473 @@ -3185,81 +3086,67 @@
1.474  lemma collinear_2 [iff]: "collinear {x, y}"
1.475    apply (simp add: collinear_def)
1.476    apply (rule exI[where x="x - y"])
1.477 -  apply auto
1.478 -  apply (rule exI[where x=1], simp)
1.479 -  apply (rule exI[where x="- 1"], simp)
1.480 -  done
1.481 +  by (metis minus_diff_eq scaleR_left.minus scaleR_one)
1.482
1.483  lemma collinear_lemma: "collinear {0, x, y} \<longleftrightarrow> x = 0 \<or> y = 0 \<or> (\<exists>c. y = c *\<^sub>R x)"
1.484    (is "?lhs \<longleftrightarrow> ?rhs")
1.485 -proof -
1.486 -  {
1.487 -    assume "x = 0 \<or> y = 0"
1.488 -    then have ?thesis
1.489 -      by (cases "x = 0") (simp_all add: collinear_2 insert_commute)
1.490 -  }
1.491 -  moreover
1.492 -  {
1.493 -    assume x: "x \<noteq> 0" and y: "y \<noteq> 0"
1.494 -    have ?thesis
1.495 -    proof
1.496 -      assume h: "?lhs"
1.497 -      then obtain u where u: "\<forall> x\<in> {0,x,y}. \<forall>y\<in> {0,x,y}. \<exists>c. x - y = c *\<^sub>R u"
1.498 -        unfolding collinear_def by blast
1.499 -      from u[rule_format, of x 0] u[rule_format, of y 0]
1.500 -      obtain cx and cy where
1.501 -        cx: "x = cx *\<^sub>R u" and cy: "y = cy *\<^sub>R u"
1.502 -        by auto
1.503 -      from cx x have cx0: "cx \<noteq> 0" by auto
1.504 -      from cy y have cy0: "cy \<noteq> 0" by auto
1.505 -      let ?d = "cy / cx"
1.506 -      from cx cy cx0 have "y = ?d *\<^sub>R x"
1.507 -        by simp
1.508 -      then show ?rhs using x y by blast
1.509 -    next
1.510 -      assume h: "?rhs"
1.511 -      then obtain c where c: "y = c *\<^sub>R x"
1.512 -        using x y by blast
1.513 -      show ?lhs
1.514 -        unfolding collinear_def c
1.515 -        apply (rule exI[where x=x])
1.516 -        apply auto
1.517 -        apply (rule exI[where x="- 1"], simp)
1.518 -        apply (rule exI[where x= "-c"], simp)
1.519 +proof (cases "x = 0 \<or> y = 0")
1.520 +  case True
1.521 +  then show ?thesis
1.522 +    by (auto simp: insert_commute)
1.523 +next
1.524 +  case False
1.525 +  show ?thesis
1.526 +  proof
1.527 +    assume h: "?lhs"
1.528 +    then obtain u where u: "\<forall> x\<in> {0,x,y}. \<forall>y\<in> {0,x,y}. \<exists>c. x - y = c *\<^sub>R u"
1.529 +      unfolding collinear_def by blast
1.530 +    from u[rule_format, of x 0] u[rule_format, of y 0]
1.531 +    obtain cx and cy where
1.532 +      cx: "x = cx *\<^sub>R u" and cy: "y = cy *\<^sub>R u"
1.533 +      by auto
1.534 +    from cx cy False have cx0: "cx \<noteq> 0" and cy0: "cy \<noteq> 0" by auto
1.535 +    let ?d = "cy / cx"
1.536 +    from cx cy cx0 have "y = ?d *\<^sub>R x"
1.537 +      by simp
1.538 +    then show ?rhs using False by blast
1.539 +  next
1.540 +    assume h: "?rhs"
1.541 +    then obtain c where c: "y = c *\<^sub>R x"
1.542 +      using False by blast
1.543 +    show ?lhs
1.544 +      unfolding collinear_def c
1.545 +      apply (rule exI[where x=x])
1.546 +      apply auto
1.547 +          apply (rule exI[where x="- 1"], simp)
1.548 +         apply (rule exI[where x= "-c"], simp)
1.549          apply (rule exI[where x=1], simp)
1.550 -        apply (rule exI[where x="1 - c"], simp add: scaleR_left_diff_distrib)
1.551 -        apply (rule exI[where x="c - 1"], simp add: scaleR_left_diff_distrib)
1.552 -        done
1.553 -    qed
1.554 -  }
1.555 -  ultimately show ?thesis by blast
1.556 +       apply (rule exI[where x="1 - c"], simp add: scaleR_left_diff_distrib)
1.557 +      apply (rule exI[where x="c - 1"], simp add: scaleR_left_diff_distrib)
1.558 +      done
1.559 +  qed
1.560  qed
1.561
1.562  lemma norm_cauchy_schwarz_equal: "\<bar>x \<bullet> y\<bar> = norm x * norm y \<longleftrightarrow> collinear {0, x, y}"
1.563 -  unfolding norm_cauchy_schwarz_abs_eq
1.564 -  apply (cases "x=0", simp_all)
1.565 -  apply (cases "y=0", simp_all add: insert_commute)
1.566 -  unfolding collinear_lemma
1.567 -  apply simp
1.568 -  apply (subgoal_tac "norm x \<noteq> 0")
1.569 -  apply (subgoal_tac "norm y \<noteq> 0")
1.570 -  apply (rule iffI)
1.571 -  apply (cases "norm x *\<^sub>R y = norm y *\<^sub>R x")
1.572 -  apply (rule exI[where x="(1/norm x) * norm y"])
1.573 -  apply (drule sym)
1.574 -  unfolding scaleR_scaleR[symmetric]
1.575 -  apply (simp add: field_simps)
1.576 -  apply (rule exI[where x="(1/norm x) * - norm y"])
1.577 -  apply clarify
1.578 -  apply (drule sym)
1.579 -  unfolding scaleR_scaleR[symmetric]
1.580 -  apply (simp add: field_simps)
1.581 -  apply (erule exE)
1.582 -  apply (erule ssubst)
1.583 -  unfolding scaleR_scaleR
1.584 -  unfolding norm_scaleR
1.585 -  apply (subgoal_tac "norm x * c = \<bar>c\<bar> * norm x \<or> norm x * c = - \<bar>c\<bar> * norm x")
1.586 -  apply (auto simp add: field_simps)
1.587 -  done
1.588 +proof (cases "x=0")
1.589 +  case True
1.590 +  then show ?thesis
1.591 +    by (auto simp: insert_commute)
1.592 +next
1.593 +  case False
1.594 +  then have nnz: "norm x \<noteq> 0"
1.595 +    by auto
1.596 +  show ?thesis
1.597 +  proof
1.598 +    assume "\<bar>x \<bullet> y\<bar> = norm x * norm y"
1.599 +    then show "collinear {0, x, y}"
1.600 +      unfolding norm_cauchy_schwarz_abs_eq collinear_lemma
1.601 +      by (meson eq_vector_fraction_iff nnz)
1.602 +  next
1.603 +    assume "collinear {0, x, y}"
1.604 +    with False show "\<bar>x \<bullet> y\<bar> = norm x * norm y"
1.605 +      unfolding norm_cauchy_schwarz_abs_eq collinear_lemma  by (auto simp: abs_if)
1.606 +  qed
1.607 +qed
1.608
1.609  end
```