src/HOL/Library/Euclidean_Space.thy
changeset 31289 847f00f435d4
parent 31285 0a3f9ee4117c
child 31340 5cddd98abe14
equal deleted inserted replaced
31288:67dff9c5b2bd 31289:847f00f435d4
   507   "norm (x::'a^'b) = setL2 (\<lambda>i. norm (x$i)) UNIV"
   507   "norm (x::'a^'b) = setL2 (\<lambda>i. norm (x$i)) UNIV"
   508 
   508 
   509 definition vector_sgn_def:
   509 definition vector_sgn_def:
   510   "sgn (x::'a^'b) = scaleR (inverse (norm x)) x"
   510   "sgn (x::'a^'b) = scaleR (inverse (norm x)) x"
   511 
   511 
       
   512 definition dist_vector_def:
       
   513   "dist (x::'a^'b) y = norm (x - y)"
       
   514 
   512 instance proof
   515 instance proof
   513   fix a :: real and x y :: "'a ^ 'b"
   516   fix a :: real and x y :: "'a ^ 'b"
   514   show "0 \<le> norm x"
   517   show "0 \<le> norm x"
   515     unfolding vector_norm_def
   518     unfolding vector_norm_def
   516     by (rule setL2_nonneg)
   519     by (rule setL2_nonneg)
   525   show "norm (scaleR a x) = \<bar>a\<bar> * norm x"
   528   show "norm (scaleR a x) = \<bar>a\<bar> * norm x"
   526     unfolding vector_norm_def
   529     unfolding vector_norm_def
   527     by (simp add: norm_scaleR setL2_right_distrib)
   530     by (simp add: norm_scaleR setL2_right_distrib)
   528   show "sgn x = scaleR (inverse (norm x)) x"
   531   show "sgn x = scaleR (inverse (norm x)) x"
   529     by (rule vector_sgn_def)
   532     by (rule vector_sgn_def)
       
   533   show "dist x y = norm (x - y)"
       
   534     by (rule dist_vector_def)
   530 qed
   535 qed
   531 
   536 
   532 end
   537 end
   533 
   538 
   534 subsection {* Inner products *}
   539 subsection {* Inner products *}
   619 
   624 
   620 lemma norm_real: "norm(x::real ^ 1) = abs(x$1)"
   625 lemma norm_real: "norm(x::real ^ 1) = abs(x$1)"
   621   by (simp add: norm_vector_1)
   626   by (simp add: norm_vector_1)
   622 
   627 
   623 lemma dist_real: "dist(x::real ^ 1) y = abs((x$1) - (y$1))"
   628 lemma dist_real: "dist(x::real ^ 1) y = abs((x$1) - (y$1))"
   624   by (auto simp add: norm_real dist_def)
   629   by (auto simp add: norm_real dist_norm)
   625 
   630 
   626 subsection {* A connectedness or intermediate value lemma with several applications. *}
   631 subsection {* A connectedness or intermediate value lemma with several applications. *}
   627 
   632 
   628 lemma connected_real_lemma:
   633 lemma connected_real_lemma:
   629   fixes f :: "real \<Rightarrow> real ^ 'n::finite"
   634   fixes f :: "real \<Rightarrow> real ^ 'n::finite"
   951 
   956 
   952 
   957 
   953 
   958 
   954 text{* Hence more metric properties. *}
   959 text{* Hence more metric properties. *}
   955 
   960 
   956 lemma dist_triangle_alt: "dist y z <= dist x y + dist x z"
   961 lemma dist_triangle_alt:
       
   962   fixes x y z :: "'a::metric_space"
       
   963   shows "dist y z <= dist x y + dist x z"
   957 using dist_triangle [of y z x] by (simp add: dist_commute)
   964 using dist_triangle [of y z x] by (simp add: dist_commute)
   958 
   965 
   959 lemma dist_triangle2: "dist x y \<le> dist x z + dist y z"
   966 lemma dist_pos_lt:
   960 using dist_triangle [of x y z] by (simp add: dist_commute)
   967   fixes x y :: "'a::metric_space"
   961 
   968   shows "x \<noteq> y ==> 0 < dist x y"
   962 lemma dist_pos_lt: "x \<noteq> y ==> 0 < dist x y" by (simp add: zero_less_dist_iff)
   969 by (simp add: zero_less_dist_iff)
   963 lemma dist_nz:  "x \<noteq> y \<longleftrightarrow> 0 < dist x y" by (simp add: zero_less_dist_iff)
   970 
   964 
   971 lemma dist_nz:
   965 lemma dist_triangle_le: "dist x z + dist y z <= e \<Longrightarrow> dist x y <= e"
   972   fixes x y :: "'a::metric_space"
       
   973   shows "x \<noteq> y \<longleftrightarrow> 0 < dist x y"
       
   974 by (simp add: zero_less_dist_iff)
       
   975 
       
   976 lemma dist_triangle_le:
       
   977   fixes x y z :: "'a::metric_space"
       
   978   shows "dist x z + dist y z <= e \<Longrightarrow> dist x y <= e"
   966 by (rule order_trans [OF dist_triangle2])
   979 by (rule order_trans [OF dist_triangle2])
   967 
   980 
   968 lemma dist_triangle_lt: "dist x z + dist y z < e ==> dist x y < e"
   981 lemma dist_triangle_lt:
       
   982   fixes x y z :: "'a::metric_space"
       
   983   shows "dist x z + dist y z < e ==> dist x y < e"
   969 by (rule le_less_trans [OF dist_triangle2])
   984 by (rule le_less_trans [OF dist_triangle2])
   970 
   985 
   971 lemma dist_triangle_half_l:
   986 lemma dist_triangle_half_l:
   972   "dist x1 y < e / 2 \<Longrightarrow> dist x2 y < e / 2 \<Longrightarrow> dist x1 x2 < e"
   987   fixes x1 x2 y :: "'a::metric_space"
       
   988   shows "dist x1 y < e / 2 \<Longrightarrow> dist x2 y < e / 2 \<Longrightarrow> dist x1 x2 < e"
   973 by (rule dist_triangle_lt [where z=y], simp)
   989 by (rule dist_triangle_lt [where z=y], simp)
   974 
   990 
   975 lemma dist_triangle_half_r:
   991 lemma dist_triangle_half_r:
   976   "dist y x1 < e / 2 \<Longrightarrow> dist y x2 < e / 2 \<Longrightarrow> dist x1 x2 < e"
   992   fixes x1 x2 y :: "'a::metric_space"
       
   993   shows "dist y x1 < e / 2 \<Longrightarrow> dist y x2 < e / 2 \<Longrightarrow> dist x1 x2 < e"
   977 by (rule dist_triangle_half_l, simp_all add: dist_commute)
   994 by (rule dist_triangle_half_l, simp_all add: dist_commute)
   978 
   995 
   979 lemma dist_triangle_add: "dist (x + y) (x' + y') <= dist x x' + dist y y'"
   996 lemma dist_triangle_add:
   980 unfolding dist_def by (rule norm_diff_triangle_ineq)
   997   fixes x y x' y' :: "'a::real_normed_vector"
       
   998   shows "dist (x + y) (x' + y') <= dist x x' + dist y y'"
       
   999 unfolding dist_norm by (rule norm_diff_triangle_ineq)
   981 
  1000 
   982 lemma dist_mul[simp]: "dist (c *s x) (c *s y) = \<bar>c\<bar> * dist x y"
  1001 lemma dist_mul[simp]: "dist (c *s x) (c *s y) = \<bar>c\<bar> * dist x y"
   983   unfolding dist_def vector_ssub_ldistrib[symmetric] norm_mul ..
  1002   unfolding dist_norm vector_ssub_ldistrib[symmetric] norm_mul ..
   984 
  1003 
   985 lemma dist_triangle_add_half:
  1004 lemma dist_triangle_add_half:
   986   " dist x x' < e / 2 \<Longrightarrow> dist y y' < e / 2 \<Longrightarrow> dist(x + y) (x' + y') < e"
  1005   fixes x x' y y' :: "'a::real_normed_vector"
       
  1006   shows "dist x x' < e / 2 \<Longrightarrow> dist y y' < e / 2 \<Longrightarrow> dist(x + y) (x' + y') < e"
   987 by (rule le_less_trans [OF dist_triangle_add], simp)
  1007 by (rule le_less_trans [OF dist_triangle_add], simp)
   988 
  1008 
   989 lemma setsum_component [simp]:
  1009 lemma setsum_component [simp]:
   990   fixes f:: " 'a \<Rightarrow> ('b::comm_monoid_add) ^'n"
  1010   fixes f:: " 'a \<Rightarrow> ('b::comm_monoid_add) ^'n"
   991   shows "(setsum f S)$i = setsum (\<lambda>x. (f x)$i) S"
  1011   shows "(setsum f S)$i = setsum (\<lambda>x. (f x)$i) S"
  1220 lemma vector_choose_dist: assumes e: "0 <= e"
  1240 lemma vector_choose_dist: assumes e: "0 <= e"
  1221   shows "\<exists>(y::real^'n::finite). dist x y = e"
  1241   shows "\<exists>(y::real^'n::finite). dist x y = e"
  1222 proof-
  1242 proof-
  1223   from vector_choose_size[OF e] obtain c:: "real ^'n"  where "norm c = e"
  1243   from vector_choose_size[OF e] obtain c:: "real ^'n"  where "norm c = e"
  1224     by blast
  1244     by blast
  1225   then have "dist x (x - c) = e" by (simp add: dist_def)
  1245   then have "dist x (x - c) = e" by (simp add: dist_norm)
  1226   then show ?thesis by blast
  1246   then show ?thesis by blast
  1227 qed
  1247 qed
  1228 
  1248 
  1229 lemma basis_inj: "inj (basis :: 'n \<Rightarrow> real ^'n::finite)"
  1249 lemma basis_inj: "inj (basis :: 'n \<Rightarrow> real ^'n::finite)"
  1230   by (simp add: inj_on_def Cart_eq)
  1250   by (simp add: inj_on_def Cart_eq)
  2544     unfolding real_vector_norm_def real_sqrt_le_iff id_def
  2564     unfolding real_vector_norm_def real_sqrt_le_iff id_def
  2545     by (simp add: dot_def)
  2565     by (simp add: dot_def)
  2546 qed
  2566 qed
  2547 
  2567 
  2548 lemma dist_fstcart: "dist(fstcart (x::real^_)) (fstcart y) <= dist x y"
  2568 lemma dist_fstcart: "dist(fstcart (x::real^_)) (fstcart y) <= dist x y"
  2549   by (metis dist_def fstcart_sub[symmetric] norm_fstcart)
  2569   by (metis dist_vector_def fstcart_sub[symmetric] norm_fstcart)
  2550 
  2570 
  2551 lemma norm_sndcart: "norm(sndcart x) <= norm (x::real ^('n::finite + 'm::finite))"
  2571 lemma norm_sndcart: "norm(sndcart x) <= norm (x::real ^('n::finite + 'm::finite))"
  2552 proof-
  2572 proof-
  2553   have th0: "norm x = norm (pastecart (fstcart x) (sndcart x))"
  2573   have th0: "norm x = norm (pastecart (fstcart x) (sndcart x))"
  2554     by (simp add: pastecart_fst_snd)
  2574     by (simp add: pastecart_fst_snd)
  2559     unfolding real_vector_norm_def real_sqrt_le_iff id_def
  2579     unfolding real_vector_norm_def real_sqrt_le_iff id_def
  2560     by (simp add: dot_def)
  2580     by (simp add: dot_def)
  2561 qed
  2581 qed
  2562 
  2582 
  2563 lemma dist_sndcart: "dist(sndcart (x::real^_)) (sndcart y) <= dist x y"
  2583 lemma dist_sndcart: "dist(sndcart (x::real^_)) (sndcart y) <= dist x y"
  2564   by (metis dist_def sndcart_sub[symmetric] norm_sndcart)
  2584   by (metis dist_vector_def sndcart_sub[symmetric] norm_sndcart)
  2565 
  2585 
  2566 lemma dot_pastecart: "(pastecart (x1::'a::{times,comm_monoid_add}^'n::finite) (x2::'a::{times,comm_monoid_add}^'m::finite)) \<bullet> (pastecart y1 y2) =  x1 \<bullet> y1 + x2 \<bullet> y2"
  2586 lemma dot_pastecart: "(pastecart (x1::'a::{times,comm_monoid_add}^'n::finite) (x2::'a::{times,comm_monoid_add}^'m::finite)) \<bullet> (pastecart y1 y2) =  x1 \<bullet> y1 + x2 \<bullet> y2"
  2567   by (simp add: dot_def setsum_UNIV_sum pastecart_def)
  2587   by (simp add: dot_def setsum_UNIV_sum pastecart_def)
  2568 
  2588 
  2569 lemma norm_pastecart: "norm(pastecart x y) <= norm(x :: real ^ 'm::finite) + norm(y::real^'n::finite)"
  2589 lemma norm_pastecart: "norm(pastecart x y) <= norm(x :: real ^ 'm::finite) + norm(y::real^'n::finite)"
  3899   ultimately have CdV: "C hassize dim V" unfolding hassize_def using C(1) by simp
  3919   ultimately have CdV: "C hassize dim V" unfolding hassize_def using C(1) by simp
  3900   from C B CSV CdV iC show ?thesis by auto
  3920   from C B CSV CdV iC show ?thesis by auto
  3901 qed
  3921 qed
  3902 
  3922 
  3903 lemma span_eq: "span S = span T \<longleftrightarrow> S \<subseteq> span T \<and> T \<subseteq> span S"
  3923 lemma span_eq: "span S = span T \<longleftrightarrow> S \<subseteq> span T \<and> T \<subseteq> span S"
  3904   by (metis set_eq_subset span_mono span_span span_inc)
  3924   by (metis set_eq_subset span_mono span_span span_inc) (* FIXME: slow *)
  3905 
  3925 
  3906 (* ------------------------------------------------------------------------- *)
  3926 (* ------------------------------------------------------------------------- *)
  3907 (* Low-dimensional subset is in a hyperplane (weak orthogonal complement).   *)
  3927 (* Low-dimensional subset is in a hyperplane (weak orthogonal complement).   *)
  3908 (* ------------------------------------------------------------------------- *)
  3928 (* ------------------------------------------------------------------------- *)
  3909 
  3929