src/HOL/Multivariate_Analysis/Linear_Algebra.thy
author huffman
Fri, 12 Aug 2011 20:55:22 -0700
changeset 44176 eda112e9cdee
parent 44170 510ac30f44c0
child 44282 f0de18b62d63
permissions -rw-r--r--
remove redundant lemma setsum_norm in favor of norm_setsum; remove finiteness assumption from setsum_norm_le;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44133
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
     1
(*  Title:      HOL/Multivariate_Analysis/Linear_Algebra.thy
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
     2
    Author:     Amine Chaieb, University of Cambridge
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
     3
*)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
     4
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
     5
header {* Elementary linear algebra on Euclidean spaces *}
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
     6
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
     7
theory Linear_Algebra
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
     8
imports
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
     9
  Euclidean_Space
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    10
  "~~/src/HOL/Library/Infinite_Set"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    11
  L2_Norm
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    12
  "~~/src/HOL/Library/Convex"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    13
uses
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    14
  "~~/src/HOL/Library/positivstellensatz.ML"  (* FIXME duplicate use!? *)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    15
  ("normarith.ML")
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    16
begin
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    17
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    18
lemma cond_application_beta: "(if b then f else g) x = (if b then f x else g x)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    19
  by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    20
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    21
notation inner (infix "\<bullet>" 70)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    22
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    23
subsection {* A connectedness or intermediate value lemma with several applications. *}
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    24
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    25
lemma connected_real_lemma:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    26
  fixes f :: "real \<Rightarrow> 'a::metric_space"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    27
  assumes ab: "a \<le> b" and fa: "f a \<in> e1" and fb: "f b \<in> e2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    28
  and dst: "\<And>e x. a <= x \<Longrightarrow> x <= b \<Longrightarrow> 0 < e ==> \<exists>d > 0. \<forall>y. abs(y - x) < d \<longrightarrow> dist(f y) (f x) < e"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    29
  and e1: "\<forall>y \<in> e1. \<exists>e > 0. \<forall>y'. dist y' y < e \<longrightarrow> y' \<in> e1"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    30
  and e2: "\<forall>y \<in> e2. \<exists>e > 0. \<forall>y'. dist y' y < e \<longrightarrow> y' \<in> e2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    31
  and e12: "~(\<exists>x \<ge> a. x <= b \<and> f x \<in> e1 \<and> f x \<in> e2)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    32
  shows "\<exists>x \<ge> a. x <= b \<and> f x \<notin> e1 \<and> f x \<notin> e2" (is "\<exists> x. ?P x")
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    33
proof-
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    34
  let ?S = "{c. \<forall>x \<ge> a. x <= c \<longrightarrow> f x \<in> e1}"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    35
  have Se: " \<exists>x. x \<in> ?S" apply (rule exI[where x=a]) by (auto simp add: fa)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    36
  have Sub: "\<exists>y. isUb UNIV ?S y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    37
    apply (rule exI[where x= b])
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    38
    using ab fb e12 by (auto simp add: isUb_def setle_def)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    39
  from reals_complete[OF Se Sub] obtain l where
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    40
    l: "isLub UNIV ?S l"by blast
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    41
  have alb: "a \<le> l" "l \<le> b" using l ab fa fb e12
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    42
    apply (auto simp add: isLub_def leastP_def isUb_def setle_def setge_def)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    43
    by (metis linorder_linear)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    44
  have ale1: "\<forall>z \<ge> a. z < l \<longrightarrow> f z \<in> e1" using l
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    45
    apply (auto simp add: isLub_def leastP_def isUb_def setle_def setge_def)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    46
    by (metis linorder_linear not_le)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    47
    have th1: "\<And>z x e d :: real. z <= x + e \<Longrightarrow> e < d ==> z < x \<or> abs(z - x) < d" by arith
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    48
    have th2: "\<And>e x:: real. 0 < e ==> ~(x + e <= x)" by arith
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    49
    have "\<And>d::real. 0 < d \<Longrightarrow> 0 < d/2 \<and> d/2 < d" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    50
    then have th3: "\<And>d::real. d > 0 \<Longrightarrow> \<exists>e > 0. e < d" by blast
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    51
    {assume le2: "f l \<in> e2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    52
      from le2 fa fb e12 alb have la: "l \<noteq> a" by metis
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    53
      hence lap: "l - a > 0" using alb by arith
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    54
      from e2[rule_format, OF le2] obtain e where
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    55
        e: "e > 0" "\<forall>y. dist y (f l) < e \<longrightarrow> y \<in> e2" by metis
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    56
      from dst[OF alb e(1)] obtain d where
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    57
        d: "d > 0" "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> dist (f y) (f l) < e" by metis
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    58
      let ?d' = "min (d/2) ((l - a)/2)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    59
      have "?d' < d \<and> 0 < ?d' \<and> ?d' < l - a" using lap d(1)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    60
        by (simp add: min_max.less_infI2)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    61
      then have "\<exists>d'. d' < d \<and> d' >0 \<and> l - d' > a" by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    62
      then obtain d' where d': "d' > 0" "d' < d" "l - d' > a" by metis
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    63
      from d e have th0: "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> f y \<in> e2" by metis
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    64
      from th0[rule_format, of "l - d'"] d' have "f (l - d') \<in> e2" by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    65
      moreover
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    66
      have "f (l - d') \<in> e1" using ale1[rule_format, of "l -d'"] d' by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    67
      ultimately have False using e12 alb d' by auto}
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    68
    moreover
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    69
    {assume le1: "f l \<in> e1"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    70
    from le1 fa fb e12 alb have lb: "l \<noteq> b" by metis
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    71
      hence blp: "b - l > 0" using alb by arith
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    72
      from e1[rule_format, OF le1] obtain e where
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    73
        e: "e > 0" "\<forall>y. dist y (f l) < e \<longrightarrow> y \<in> e1" by metis
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    74
      from dst[OF alb e(1)] obtain d where
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    75
        d: "d > 0" "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> dist (f y) (f l) < e" by metis
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    76
      have "\<And>d::real. 0 < d \<Longrightarrow> d/2 < d \<and> 0 < d/2" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    77
      then have "\<exists>d'. d' < d \<and> d' >0" using d(1) by blast
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    78
      then obtain d' where d': "d' > 0" "d' < d" by metis
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    79
      from d e have th0: "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> f y \<in> e1" by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    80
      hence "\<forall>y. l \<le> y \<and> y \<le> l + d' \<longrightarrow> f y \<in> e1" using d' by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    81
      with ale1 have "\<forall>y. a \<le> y \<and> y \<le> l + d' \<longrightarrow> f y \<in> e1" by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    82
      with l d' have False
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    83
        by (auto simp add: isLub_def isUb_def setle_def setge_def leastP_def) }
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    84
    ultimately show ?thesis using alb by metis
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    85
qed
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    86
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    87
text{* One immediately useful corollary is the existence of square roots! --- Should help to get rid of all the development of square-root for reals as a special case *}
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    88
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    89
lemma square_bound_lemma: "(x::real) < (1 + x) * (1 + x)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    90
proof-
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    91
  have "(x + 1/2)^2 + 3/4 > 0" using zero_le_power2[of "x+1/2"] by arith
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    92
  thus ?thesis by (simp add: field_simps power2_eq_square)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    93
qed
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    94
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    95
lemma square_continuous: "0 < (e::real) ==> \<exists>d. 0 < d \<and> (\<forall>y. abs(y - x) < d \<longrightarrow> abs(y * y - x * x) < e)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    96
  using isCont_power[OF isCont_ident, of 2, unfolded isCont_def LIM_eq, rule_format, of e x] apply (auto simp add: power2_eq_square)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    97
  apply (rule_tac x="s" in exI)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    98
  apply auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
    99
  apply (erule_tac x=y in allE)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   100
  apply auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   101
  done
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   102
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   103
lemma real_le_lsqrt: "0 <= x \<Longrightarrow> 0 <= y \<Longrightarrow> x <= y^2 ==> sqrt x <= y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   104
  using real_sqrt_le_iff[of x "y^2"] by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   105
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   106
lemma real_le_rsqrt: "x^2 \<le> y \<Longrightarrow> x \<le> sqrt y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   107
  using real_sqrt_le_mono[of "x^2" y] by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   108
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   109
lemma real_less_rsqrt: "x^2 < y \<Longrightarrow> x < sqrt y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   110
  using real_sqrt_less_mono[of "x^2" y] by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   111
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   112
lemma sqrt_even_pow2: assumes n: "even n"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   113
  shows "sqrt(2 ^ n) = 2 ^ (n div 2)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   114
proof-
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   115
  from n obtain m where m: "n = 2*m" unfolding even_mult_two_ex ..
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   116
  from m  have "sqrt(2 ^ n) = sqrt ((2 ^ m) ^ 2)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   117
    by (simp only: power_mult[symmetric] mult_commute)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   118
  then show ?thesis  using m by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   119
qed
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   120
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   121
lemma real_div_sqrt: "0 <= x ==> x / sqrt(x) = sqrt(x)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   122
  apply (cases "x = 0", simp_all)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   123
  using sqrt_divide_self_eq[of x]
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   124
  apply (simp add: inverse_eq_divide field_simps)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   125
  done
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   126
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   127
text{* Hence derive more interesting properties of the norm. *}
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   128
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   129
(* FIXME: same as norm_scaleR
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   130
lemma norm_mul[simp]: "norm(a *\<^sub>R x) = abs(a) * norm x"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   131
  by (simp add: norm_vector_def setL2_right_distrib abs_mult)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   132
*)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   133
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   134
lemma norm_eq_0_dot: "(norm x = 0) \<longleftrightarrow> (inner x x = (0::real))"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   135
  by (simp add: setL2_def power2_eq_square)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   136
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   137
lemma norm_cauchy_schwarz:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   138
  shows "inner x y <= norm x * norm y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   139
  using Cauchy_Schwarz_ineq2[of x y] by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   140
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   141
lemma norm_cauchy_schwarz_abs:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   142
  shows "\<bar>inner x y\<bar> \<le> norm x * norm y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   143
  by (rule Cauchy_Schwarz_ineq2)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   144
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   145
lemma norm_triangle_sub:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   146
  fixes x y :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   147
  shows "norm x \<le> norm y  + norm (x - y)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   148
  using norm_triangle_ineq[of "y" "x - y"] by (simp add: field_simps)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   149
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   150
lemma real_abs_norm: "\<bar>norm x\<bar> = norm x"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   151
  by (rule abs_norm_cancel)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   152
lemma real_abs_sub_norm: "\<bar>norm x - norm y\<bar> <= norm(x - y)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   153
  by (rule norm_triangle_ineq3)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   154
lemma norm_le: "norm(x) <= norm(y) \<longleftrightarrow> x \<bullet> x <= y \<bullet> y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   155
  by (simp add: norm_eq_sqrt_inner) 
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   156
lemma norm_lt: "norm(x) < norm(y) \<longleftrightarrow> x \<bullet> x < y \<bullet> y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   157
  by (simp add: norm_eq_sqrt_inner)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   158
lemma norm_eq: "norm(x) = norm (y) \<longleftrightarrow> x \<bullet> x = y \<bullet> y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   159
  apply(subst order_eq_iff) unfolding norm_le by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   160
lemma norm_eq_1: "norm(x) = 1 \<longleftrightarrow> x \<bullet> x = 1"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   161
  unfolding norm_eq_sqrt_inner by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   162
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   163
text{* Squaring equations and inequalities involving norms.  *}
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   164
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   165
lemma dot_square_norm: "x \<bullet> x = norm(x)^2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   166
  by (simp add: norm_eq_sqrt_inner)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   167
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   168
lemma norm_eq_square: "norm(x) = a \<longleftrightarrow> 0 <= a \<and> x \<bullet> x = a^2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   169
  by (auto simp add: norm_eq_sqrt_inner)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   170
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   171
lemma real_abs_le_square_iff: "\<bar>x\<bar> \<le> \<bar>y\<bar> \<longleftrightarrow> (x::real)^2 \<le> y^2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   172
proof
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   173
  assume "\<bar>x\<bar> \<le> \<bar>y\<bar>"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   174
  then have "\<bar>x\<bar>\<twosuperior> \<le> \<bar>y\<bar>\<twosuperior>" by (rule power_mono, simp)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   175
  then show "x\<twosuperior> \<le> y\<twosuperior>" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   176
next
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   177
  assume "x\<twosuperior> \<le> y\<twosuperior>"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   178
  then have "sqrt (x\<twosuperior>) \<le> sqrt (y\<twosuperior>)" by (rule real_sqrt_le_mono)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   179
  then show "\<bar>x\<bar> \<le> \<bar>y\<bar>" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   180
qed
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   181
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   182
lemma norm_le_square: "norm(x) <= a \<longleftrightarrow> 0 <= a \<and> x \<bullet> x <= a^2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   183
  apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric])
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   184
  using norm_ge_zero[of x]
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   185
  apply arith
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   186
  done
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   187
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   188
lemma norm_ge_square: "norm(x) >= a \<longleftrightarrow> a <= 0 \<or> x \<bullet> x >= a ^ 2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   189
  apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric])
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   190
  using norm_ge_zero[of x]
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   191
  apply arith
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   192
  done
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   193
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   194
lemma norm_lt_square: "norm(x) < a \<longleftrightarrow> 0 < a \<and> x \<bullet> x < a^2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   195
  by (metis not_le norm_ge_square)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   196
lemma norm_gt_square: "norm(x) > a \<longleftrightarrow> a < 0 \<or> x \<bullet> x > a^2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   197
  by (metis norm_le_square not_less)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   198
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   199
text{* Dot product in terms of the norm rather than conversely. *}
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   200
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   201
lemmas inner_simps = inner.add_left inner.add_right inner.diff_right inner.diff_left 
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   202
inner.scaleR_left inner.scaleR_right
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   203
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   204
lemma dot_norm: "x \<bullet> y = (norm(x + y) ^2 - norm x ^ 2 - norm y ^ 2) / 2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   205
  unfolding power2_norm_eq_inner inner_simps inner_commute by auto 
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   206
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   207
lemma dot_norm_neg: "x \<bullet> y = ((norm x ^ 2 + norm y ^ 2) - norm(x - y) ^ 2) / 2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   208
  unfolding power2_norm_eq_inner inner_simps inner_commute by(auto simp add:algebra_simps)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   209
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   210
text{* Equality of vectors in terms of @{term "op \<bullet>"} products.    *}
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   211
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   212
lemma vector_eq: "x = y \<longleftrightarrow> x \<bullet> x = x \<bullet> y \<and> y \<bullet> y = x \<bullet> x" (is "?lhs \<longleftrightarrow> ?rhs")
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   213
proof
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   214
  assume ?lhs then show ?rhs by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   215
next
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   216
  assume ?rhs
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   217
  then have "x \<bullet> x - x \<bullet> y = 0 \<and> x \<bullet> y - y \<bullet> y = 0" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   218
  hence "x \<bullet> (x - y) = 0 \<and> y \<bullet> (x - y) = 0" by (simp add: inner_simps inner_commute)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   219
  then have "(x - y) \<bullet> (x - y) = 0" by (simp add: field_simps inner_simps inner_commute)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   220
  then show "x = y" by (simp)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   221
qed
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   222
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   223
subsection{* General linear decision procedure for normed spaces. *}
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   224
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   225
lemma norm_cmul_rule_thm:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   226
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   227
  shows "b >= norm(x) ==> \<bar>c\<bar> * b >= norm(scaleR c x)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   228
  unfolding norm_scaleR
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   229
  apply (erule mult_left_mono)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   230
  apply simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   231
  done
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   232
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   233
  (* FIXME: Move all these theorems into the ML code using lemma antiquotation *)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   234
lemma norm_add_rule_thm:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   235
  fixes x1 x2 :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   236
  shows "norm x1 \<le> b1 \<Longrightarrow> norm x2 \<le> b2 \<Longrightarrow> norm (x1 + x2) \<le> b1 + b2"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   237
  by (rule order_trans [OF norm_triangle_ineq add_mono])
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   238
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   239
lemma ge_iff_diff_ge_0: "(a::'a::linordered_ring) \<ge> b == a - b \<ge> 0"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   240
  by (simp add: field_simps)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   241
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   242
lemma pth_1:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   243
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   244
  shows "x == scaleR 1 x" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   245
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   246
lemma pth_2:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   247
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   248
  shows "x - y == x + -y" by (atomize (full)) simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   249
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   250
lemma pth_3:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   251
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   252
  shows "- x == scaleR (-1) x" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   253
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   254
lemma pth_4:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   255
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   256
  shows "scaleR 0 x == 0" and "scaleR c 0 = (0::'a)" by simp_all
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   257
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   258
lemma pth_5:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   259
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   260
  shows "scaleR c (scaleR d x) == scaleR (c * d) x" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   261
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   262
lemma pth_6:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   263
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   264
  shows "scaleR c (x + y) == scaleR c x + scaleR c y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   265
  by (simp add: scaleR_right_distrib)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   266
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   267
lemma pth_7:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   268
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   269
  shows "0 + x == x" and "x + 0 == x" by simp_all
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   270
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   271
lemma pth_8:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   272
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   273
  shows "scaleR c x + scaleR d x == scaleR (c + d) x"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   274
  by (simp add: scaleR_left_distrib)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   275
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   276
lemma pth_9:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   277
  fixes x :: "'a::real_normed_vector" shows
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   278
  "(scaleR c x + z) + scaleR d x == scaleR (c + d) x + z"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   279
  "scaleR c x + (scaleR d x + z) == scaleR (c + d) x + z"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   280
  "(scaleR c x + w) + (scaleR d x + z) == scaleR (c + d) x + (w + z)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   281
  by (simp_all add: algebra_simps)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   282
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   283
lemma pth_a:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   284
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   285
  shows "scaleR 0 x + y == y" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   286
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   287
lemma pth_b:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   288
  fixes x :: "'a::real_normed_vector" shows
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   289
  "scaleR c x + scaleR d y == scaleR c x + scaleR d y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   290
  "(scaleR c x + z) + scaleR d y == scaleR c x + (z + scaleR d y)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   291
  "scaleR c x + (scaleR d y + z) == scaleR c x + (scaleR d y + z)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   292
  "(scaleR c x + w) + (scaleR d y + z) == scaleR c x + (w + (scaleR d y + z))"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   293
  by (simp_all add: algebra_simps)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   294
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   295
lemma pth_c:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   296
  fixes x :: "'a::real_normed_vector" shows
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   297
  "scaleR c x + scaleR d y == scaleR d y + scaleR c x"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   298
  "(scaleR c x + z) + scaleR d y == scaleR d y + (scaleR c x + z)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   299
  "scaleR c x + (scaleR d y + z) == scaleR d y + (scaleR c x + z)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   300
  "(scaleR c x + w) + (scaleR d y + z) == scaleR d y + ((scaleR c x + w) + z)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   301
  by (simp_all add: algebra_simps)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   302
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   303
lemma pth_d:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   304
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   305
  shows "x + 0 == x" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   306
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   307
lemma norm_imp_pos_and_ge:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   308
  fixes x :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   309
  shows "norm x == n \<Longrightarrow> norm x \<ge> 0 \<and> n \<ge> norm x"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   310
  by atomize auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   311
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   312
lemma real_eq_0_iff_le_ge_0: "(x::real) = 0 == x \<ge> 0 \<and> -x \<ge> 0" by arith
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   313
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   314
lemma norm_pths:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   315
  fixes x :: "'a::real_normed_vector" shows
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   316
  "x = y \<longleftrightarrow> norm (x - y) \<le> 0"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   317
  "x \<noteq> y \<longleftrightarrow> \<not> (norm (x - y) \<le> 0)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   318
  using norm_ge_zero[of "x - y"] by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   319
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   320
use "normarith.ML"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   321
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   322
method_setup norm = {* Scan.succeed (SIMPLE_METHOD' o NormArith.norm_arith_tac)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   323
*} "prove simple linear statements about vector norms"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   324
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   325
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   326
text{* Hence more metric properties. *}
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   327
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   328
lemma norm_triangle_half_r:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   329
  shows "norm (y - x1) < e / 2 \<Longrightarrow> norm (y - x2) < e / 2 \<Longrightarrow> norm (x1 - x2) < e"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   330
  using dist_triangle_half_r unfolding dist_norm[THEN sym] by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   331
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   332
lemma norm_triangle_half_l: assumes "norm (x - y) < e / 2" "norm (x' - (y)) < e / 2" 
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   333
  shows "norm (x - x') < e"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   334
  using dist_triangle_half_l[OF assms[unfolded dist_norm[THEN sym]]]
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   335
  unfolding dist_norm[THEN sym] .
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   336
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   337
lemma norm_triangle_le: "norm(x) + norm y <= e ==> norm(x + y) <= e"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   338
  by (metis order_trans norm_triangle_ineq)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   339
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   340
lemma norm_triangle_lt: "norm(x) + norm(y) < e ==> norm(x + y) < e"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   341
  by (metis basic_trans_rules(21) norm_triangle_ineq)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   342
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   343
lemma dist_triangle_add:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   344
  fixes x y x' y' :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   345
  shows "dist (x + y) (x' + y') <= dist x x' + dist y y'"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   346
  by norm
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   347
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   348
lemma dist_triangle_add_half:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   349
  fixes x x' y y' :: "'a::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   350
  shows "dist x x' < e / 2 \<Longrightarrow> dist y y' < e / 2 \<Longrightarrow> dist(x + y) (x' + y') < e"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   351
  by norm
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   352
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   353
lemma setsum_clauses:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   354
  shows "setsum f {} = 0"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   355
  and "finite S \<Longrightarrow> setsum f (insert x S) =
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   356
                 (if x \<in> S then setsum f S else f x + setsum f S)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   357
  by (auto simp add: insert_absorb)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   358
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   359
lemma setsum_norm_le:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   360
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
44176
eda112e9cdee remove redundant lemma setsum_norm in favor of norm_setsum;
huffman
parents: 44170
diff changeset
   361
  assumes fg: "\<forall>x \<in> S. norm (f x) \<le> g x"
44133
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   362
  shows "norm (setsum f S) \<le> setsum g S"
44176
eda112e9cdee remove redundant lemma setsum_norm in favor of norm_setsum;
huffman
parents: 44170
diff changeset
   363
  by (rule order_trans [OF norm_setsum setsum_mono], simp add: fg)
44133
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   364
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   365
lemma setsum_norm_bound:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   366
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   367
  assumes fS: "finite S"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   368
  and K: "\<forall>x \<in> S. norm (f x) \<le> K"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   369
  shows "norm (setsum f S) \<le> of_nat (card S) * K"
44176
eda112e9cdee remove redundant lemma setsum_norm in favor of norm_setsum;
huffman
parents: 44170
diff changeset
   370
  using setsum_norm_le[OF K] setsum_constant[symmetric]
44133
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   371
  by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   372
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   373
lemma setsum_group:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   374
  assumes fS: "finite S" and fT: "finite T" and fST: "f ` S \<subseteq> T"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   375
  shows "setsum (\<lambda>y. setsum g {x. x\<in> S \<and> f x = y}) T = setsum g S"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   376
  apply (subst setsum_image_gen[OF fS, of g f])
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   377
  apply (rule setsum_mono_zero_right[OF fT fST])
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   378
  by (auto intro: setsum_0')
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   379
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   380
lemma dot_lsum: "finite S \<Longrightarrow> setsum f S \<bullet> y = setsum (\<lambda>x. f x \<bullet> y) S "
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   381
  apply(induct rule: finite_induct) by(auto simp add: inner_simps)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   382
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   383
lemma dot_rsum: "finite S \<Longrightarrow> y \<bullet> setsum f S = setsum (\<lambda>x. y \<bullet> f x) S "
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   384
  apply(induct rule: finite_induct) by(auto simp add: inner_simps)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   385
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   386
lemma vector_eq_ldot: "(\<forall>x. x \<bullet> y = x \<bullet> z) \<longleftrightarrow> y = z"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   387
proof
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   388
  assume "\<forall>x. x \<bullet> y = x \<bullet> z"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   389
  hence "\<forall>x. x \<bullet> (y - z) = 0" by (simp add: inner_simps)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   390
  hence "(y - z) \<bullet> (y - z) = 0" ..
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   391
  thus "y = z" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   392
qed simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   393
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   394
lemma vector_eq_rdot: "(\<forall>z. x \<bullet> z = y \<bullet> z) \<longleftrightarrow> x = y"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   395
proof
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   396
  assume "\<forall>z. x \<bullet> z = y \<bullet> z"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   397
  hence "\<forall>z. (x - y) \<bullet> z = 0" by (simp add: inner_simps)
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   398
  hence "(x - y) \<bullet> (x - y) = 0" ..
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   399
  thus "x = y" by simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   400
qed simp
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   401
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   402
subsection{* Orthogonality. *}
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   403
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   404
context real_inner
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   405
begin
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   406
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   407
definition "orthogonal x y \<longleftrightarrow> (x \<bullet> y = 0)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   408
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   409
lemma orthogonal_clauses:
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   410
  "orthogonal a 0"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   411
  "orthogonal a x \<Longrightarrow> orthogonal a (c *\<^sub>R x)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   412
  "orthogonal a x \<Longrightarrow> orthogonal a (-x)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   413
  "orthogonal a x \<Longrightarrow> orthogonal a y \<Longrightarrow> orthogonal a (x + y)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   414
  "orthogonal a x \<Longrightarrow> orthogonal a y \<Longrightarrow> orthogonal a (x - y)"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   415
  "orthogonal 0 a"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   416
  "orthogonal x a \<Longrightarrow> orthogonal (c *\<^sub>R x) a"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   417
  "orthogonal x a \<Longrightarrow> orthogonal (-x) a"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   418
  "orthogonal x a \<Longrightarrow> orthogonal y a \<Longrightarrow> orthogonal (x + y) a"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   419
  "orthogonal x a \<Longrightarrow> orthogonal y a \<Longrightarrow> orthogonal (x - y) a"
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset
   420
  unfolding orthogonal_def inner_simps inner_add_left inner_add_right inner_diff_left inner_diff_right (*FIXME*) by auto
691c52e900ca split Linear_Algebra.thy from Euclidean_Space.thy
huffman
parents:
diff changeset