src/HOL/Analysis/Cartesian_Euclidean_Space.thy
changeset 67719 bffb7482faaa
parent 67686 2c58505bf151
child 67728 d97a28a006f9
equal deleted inserted replaced
67717:5a1b299fe4af 67719:bffb7482faaa
     4 imports Finite_Cartesian_Product Derivative
     4 imports Finite_Cartesian_Product Derivative
     5 begin
     5 begin
     6 
     6 
     7 lemma subspace_special_hyperplane: "subspace {x. x $ k = 0}"
     7 lemma subspace_special_hyperplane: "subspace {x. x $ k = 0}"
     8   by (simp add: subspace_def)
     8   by (simp add: subspace_def)
     9 
       
    10 lemma delta_mult_idempotent:
       
    11   "(if k=a then 1 else (0::'a::semiring_1)) * (if k=a then 1 else 0) = (if k=a then 1 else 0)"
       
    12   by simp
       
    13 
       
    14 (*move up?*)
       
    15 lemma sum_UNIV_sum:
       
    16   fixes g :: "'a::finite + 'b::finite \<Rightarrow> _"
       
    17   shows "(\<Sum>x\<in>UNIV. g x) = (\<Sum>x\<in>UNIV. g (Inl x)) + (\<Sum>x\<in>UNIV. g (Inr x))"
       
    18   apply (subst UNIV_Plus_UNIV [symmetric])
       
    19   apply (subst sum.Plus)
       
    20   apply simp_all
       
    21   done
       
    22 
     9 
    23 lemma sum_mult_product:
    10 lemma sum_mult_product:
    24   "sum h {..<A * B :: nat} = (\<Sum>i\<in>{..<A}. \<Sum>j\<in>{..<B}. h (j + i * B))"
    11   "sum h {..<A * B :: nat} = (\<Sum>i\<in>{..<A}. \<Sum>j\<in>{..<B}. h (j + i * B))"
    25   unfolding sum_nat_group[of h B A, unfolded atLeast0LessThan, symmetric]
    12   unfolding sum_nat_group[of h B A, unfolded atLeast0LessThan, symmetric]
    26 proof (rule sum.cong, simp, rule sum.reindex_cong)
    13 proof (rule sum.cong, simp, rule sum.reindex_cong)
   630     unfolding scalar_mult_eq_scaleR[symmetric]
   617     unfolding scalar_mult_eq_scaleR[symmetric]
   631     unfolding basis_expansion
   618     unfolding basis_expansion
   632     by simp
   619     by simp
   633 qed
   620 qed
   634 
   621 
   635 text\<open>Inverse matrices  (not necessarily square)\<close>
   622 subsection\<open>Inverse matrices  (not necessarily square)\<close>
   636 
   623 
   637 definition
   624 definition
   638   "invertible(A::'a::semiring_1^'n^'m) \<longleftrightarrow> (\<exists>A'::'a^'m^'n. A ** A' = mat 1 \<and> A' ** A = mat 1)"
   625   "invertible(A::'a::semiring_1^'n^'m) \<longleftrightarrow> (\<exists>A'::'a^'m^'n. A ** A' = mat 1 \<and> A' ** A = mat 1)"
   639 
   626 
   640 definition
   627 definition
   726   unfolding adjoint_matrix matrix_of_matrix_vector_mul
   713   unfolding adjoint_matrix matrix_of_matrix_vector_mul
   727   apply rule
   714   apply rule
   728   done
   715   done
   729 
   716 
   730 
   717 
       
   718 subsection\<open>Some bounds on components etc. relative to operator norm.\<close>
       
   719 
       
   720 lemma norm_column_le_onorm:
       
   721   fixes A :: "real^'n^'m"
       
   722   shows "norm(column i A) \<le> onorm(( *v) A)"
       
   723 proof -
       
   724   have bl: "bounded_linear (( *v) A)"
       
   725     by (simp add: linear_linear matrix_vector_mul_linear)
       
   726   have "norm (\<chi> j. A $ j $ i) \<le> norm (A *v axis i 1)"
       
   727     by (simp add: matrix_mult_dot cart_eq_inner_axis)
       
   728   also have "\<dots> \<le> onorm (( *v) A)"
       
   729     using onorm [OF bl, of "axis i 1"] by (auto simp: axis_in_Basis)
       
   730   finally have "norm (\<chi> j. A $ j $ i) \<le> onorm (( *v) A)" .
       
   731   then show ?thesis
       
   732     unfolding column_def .
       
   733 qed
       
   734 
       
   735 lemma matrix_component_le_onorm:
       
   736   fixes A :: "real^'n^'m"
       
   737   shows "\<bar>A $ i $ j\<bar> \<le> onorm(( *v) A)"
       
   738 proof -
       
   739   have "\<bar>A $ i $ j\<bar> \<le> norm (\<chi> n. (A $ n $ j))"
       
   740     by (metis (full_types, lifting) component_le_norm_cart vec_lambda_beta)
       
   741   also have "\<dots> \<le> onorm (( *v) A)"
       
   742     by (metis (no_types) column_def norm_column_le_onorm)
       
   743   finally show ?thesis .
       
   744 qed
       
   745 
       
   746 lemma component_le_onorm:
       
   747   fixes f :: "real^'m \<Rightarrow> real^'n"
       
   748   shows "linear f \<Longrightarrow> \<bar>matrix f $ i $ j\<bar> \<le> onorm f"
       
   749   by (metis matrix_component_le_onorm matrix_vector_mul)
       
   750 
       
   751 lemma onorm_le_matrix_component_sum:
       
   752   fixes A :: "real^'n^'m"
       
   753   shows "onorm(( *v) A) \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar>)"
       
   754 proof (rule onorm_le)
       
   755   fix x
       
   756   have "norm (A *v x) \<le> (\<Sum>i\<in>UNIV. \<bar>(A *v x) $ i\<bar>)"
       
   757     by (rule norm_le_l1_cart)
       
   758   also have "\<dots> \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar> * norm x)"
       
   759   proof (rule sum_mono)
       
   760     fix i
       
   761     have "\<bar>(A *v x) $ i\<bar> \<le> \<bar>\<Sum>j\<in>UNIV. A $ i $ j * x $ j\<bar>"
       
   762       by (simp add: matrix_vector_mult_def)
       
   763     also have "\<dots> \<le> (\<Sum>j\<in>UNIV. \<bar>A $ i $ j * x $ j\<bar>)"
       
   764       by (rule sum_abs)
       
   765     also have "\<dots> \<le> (\<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar> * norm x)"
       
   766       by (rule sum_mono) (simp add: abs_mult component_le_norm_cart mult_left_mono)
       
   767     finally show "\<bar>(A *v x) $ i\<bar> \<le> (\<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar> * norm x)" .
       
   768   qed
       
   769   finally show "norm (A *v x) \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar>) * norm x"
       
   770     by (simp add: sum_distrib_right)
       
   771 qed
       
   772 
       
   773 lemma onorm_le_matrix_component:
       
   774   fixes A :: "real^'n^'m"
       
   775   assumes "\<And>i j. abs(A$i$j) \<le> B"
       
   776   shows "onorm(( *v) A) \<le> real (CARD('m)) * real (CARD('n)) * B"
       
   777 proof (rule onorm_le)
       
   778   fix x :: "(real, 'n) vec"
       
   779   have "norm (A *v x) \<le> (\<Sum>i\<in>UNIV. \<bar>(A *v x) $ i\<bar>)"
       
   780     by (rule norm_le_l1_cart)
       
   781   also have "\<dots> \<le> (\<Sum>i::'m \<in>UNIV. real (CARD('n)) * B * norm x)"
       
   782   proof (rule sum_mono)
       
   783     fix i
       
   784     have "\<bar>(A *v x) $ i\<bar> \<le> norm(A $ i) * norm x"
       
   785       by (simp add: matrix_mult_dot Cauchy_Schwarz_ineq2)
       
   786     also have "\<dots> \<le> (\<Sum>j\<in>UNIV. \<bar>A $ i $ j\<bar>) * norm x"
       
   787       by (simp add: mult_right_mono norm_le_l1_cart)
       
   788     also have "\<dots> \<le> real (CARD('n)) * B * norm x"
       
   789       by (simp add: assms sum_bounded_above mult_right_mono)
       
   790     finally show "\<bar>(A *v x) $ i\<bar> \<le> real (CARD('n)) * B * norm x" .
       
   791   qed
       
   792   also have "\<dots> \<le> CARD('m) * real (CARD('n)) * B * norm x"
       
   793     by simp
       
   794   finally show "norm (A *v x) \<le> CARD('m) * real (CARD('n)) * B * norm x" .
       
   795 qed
       
   796 
   731 subsection \<open>lambda skolemization on cartesian products\<close>
   797 subsection \<open>lambda skolemization on cartesian products\<close>
   732 
       
   733 (* FIXME: rename do choice_cart *)
       
   734 
   798 
   735 lemma lambda_skolem: "(\<forall>i. \<exists>x. P i x) \<longleftrightarrow>
   799 lemma lambda_skolem: "(\<forall>i. \<exists>x. P i x) \<longleftrightarrow>
   736    (\<exists>x::'a ^ 'n. \<forall>i. P i (x $ i))" (is "?lhs \<longleftrightarrow> ?rhs")
   800    (\<exists>x::'a ^ 'n. \<forall>i. P i (x $ i))" (is "?lhs \<longleftrightarrow> ?rhs")
   737 proof -
   801 proof -
   738   let ?S = "(UNIV :: 'n set)"
   802   let ?S = "(UNIV :: 'n set)"
   747       then have "P i (?x $ i)" by auto
   811       then have "P i (?x $ i)" by auto
   748     }
   812     }
   749     hence "\<forall>i. P i (?x$i)" by metis
   813     hence "\<forall>i. P i (?x$i)" by metis
   750     hence ?rhs by metis }
   814     hence ?rhs by metis }
   751   ultimately show ?thesis by metis
   815   ultimately show ?thesis by metis
       
   816 qed
       
   817 
       
   818 lemma rational_approximation:
       
   819   assumes "e > 0"
       
   820   obtains r::real where "r \<in> \<rat>" "\<bar>r - x\<bar> < e"
       
   821   using Rats_dense_in_real [of "x - e/2" "x + e/2"] assms by auto
       
   822 
       
   823 lemma matrix_rational_approximation:
       
   824   fixes A :: "real^'n^'m"
       
   825   assumes "e > 0"
       
   826   obtains B where "\<And>i j. B$i$j \<in> \<rat>" "onorm(\<lambda>x. (A - B) *v x) < e"
       
   827 proof -
       
   828   have "\<forall>i j. \<exists>q \<in> \<rat>. \<bar>q - A $ i $ j\<bar> < e / (2 * CARD('m) * CARD('n))"
       
   829     using assms by (force intro: rational_approximation [of "e / (2 * CARD('m) * CARD('n))"])
       
   830   then obtain B where B: "\<And>i j. B$i$j \<in> \<rat>" and Bclo: "\<And>i j. \<bar>B$i$j - A $ i $ j\<bar> < e / (2 * CARD('m) * CARD('n))"
       
   831     by (auto simp: lambda_skolem Bex_def)
       
   832   show ?thesis
       
   833   proof
       
   834     have "onorm (( *v) (A - B)) \<le> real CARD('m) * real CARD('n) *
       
   835     (e / (2 * real CARD('m) * real CARD('n)))"
       
   836       apply (rule onorm_le_matrix_component)
       
   837       using Bclo by (simp add: abs_minus_commute less_imp_le)
       
   838     also have "\<dots> < e"
       
   839       using \<open>0 < e\<close> by (simp add: divide_simps)
       
   840     finally show "onorm (( *v) (A - B)) < e" .
       
   841   qed (use B in auto)
   752 qed
   842 qed
   753 
   843 
   754 lemma vector_sub_project_orthogonal_cart: "(b::real^'n) \<bullet> (x - ((b \<bullet> x) / (b \<bullet> b)) *s b) = 0"
   844 lemma vector_sub_project_orthogonal_cart: "(b::real^'n) \<bullet> (x - ((b \<bullet> x) / (b \<bullet> b)) *s b) = 0"
   755   unfolding inner_simps scalar_mult_eq_scaleR by auto
   845   unfolding inner_simps scalar_mult_eq_scaleR by auto
   756 
   846 
  1137     and "cbox a b \<inter> box c d = {} \<longleftrightarrow> (\<exists>i. (b$i < a$i \<or> d$i \<le> c$i \<or> b$i \<le> c$i \<or> d$i \<le> a$i))" (is ?th2)
  1227     and "cbox a b \<inter> box c d = {} \<longleftrightarrow> (\<exists>i. (b$i < a$i \<or> d$i \<le> c$i \<or> b$i \<le> c$i \<or> d$i \<le> a$i))" (is ?th2)
  1138     and "box a b \<inter> cbox c d = {} \<longleftrightarrow> (\<exists>i. (b$i \<le> a$i \<or> d$i < c$i \<or> b$i \<le> c$i \<or> d$i \<le> a$i))" (is ?th3)
  1228     and "box a b \<inter> cbox c d = {} \<longleftrightarrow> (\<exists>i. (b$i \<le> a$i \<or> d$i < c$i \<or> b$i \<le> c$i \<or> d$i \<le> a$i))" (is ?th3)
  1139     and "box a b \<inter> box c d = {} \<longleftrightarrow> (\<exists>i. (b$i \<le> a$i \<or> d$i \<le> c$i \<or> b$i \<le> c$i \<or> d$i \<le> a$i))" (is ?th4)
  1229     and "box a b \<inter> box c d = {} \<longleftrightarrow> (\<exists>i. (b$i \<le> a$i \<or> d$i \<le> c$i \<or> b$i \<le> c$i \<or> d$i \<le> a$i))" (is ?th4)
  1140   using disjoint_interval[of a b c d] by (simp_all add: Basis_vec_def inner_axis)
  1230   using disjoint_interval[of a b c d] by (simp_all add: Basis_vec_def inner_axis)
  1141 
  1231 
  1142 lemma inter_interval_cart:
  1232 lemma Int_interval_cart:
  1143   fixes a :: "real^'n"
  1233   fixes a :: "real^'n"
  1144   shows "cbox a b \<inter> cbox c d =  {(\<chi> i. max (a$i) (c$i)) .. (\<chi> i. min (b$i) (d$i))}"
  1234   shows "cbox a b \<inter> cbox c d =  {(\<chi> i. max (a$i) (c$i)) .. (\<chi> i. min (b$i) (d$i))}"
  1145   unfolding Int_interval
  1235   unfolding Int_interval
  1146   by (auto simp: mem_box less_eq_vec_def)
  1236   by (auto simp: mem_box less_eq_vec_def)
  1147     (auto simp: Basis_vec_def inner_axis)
  1237     (auto simp: Basis_vec_def inner_axis)
  1222     by (auto simp: Basis_vec_def)
  1312     by (auto simp: Basis_vec_def)
  1223   thus ?thesis
  1313   thus ?thesis
  1224     using dim_substandard[of "?a ` d"] card_image[of ?a d]
  1314     using dim_substandard[of "?a ` d"] card_image[of ?a d]
  1225     by (auto simp: axis_eq_axis inj_on_def *)
  1315     by (auto simp: axis_eq_axis inj_on_def *)
  1226 qed
  1316 qed
       
  1317 
       
  1318 lemma dim_subset_UNIV_cart:
       
  1319   fixes S :: "(real^'n) set"
       
  1320   shows "dim S \<le> CARD('n)"
       
  1321   by (metis dim_subset_UNIV DIM_cart DIM_real mult.right_neutral)
  1227 
  1322 
  1228 lemma affinity_inverses:
  1323 lemma affinity_inverses:
  1229   assumes m0: "m \<noteq> (0::'a::field)"
  1324   assumes m0: "m \<noteq> (0::'a::field)"
  1230   shows "(\<lambda>x. m *s x + c) \<circ> (\<lambda>x. inverse(m) *s x + (-(inverse(m) *s c))) = id"
  1325   shows "(\<lambda>x. m *s x + c) \<circ> (\<lambda>x. inverse(m) *s x + (-(inverse(m) *s c))) = id"
  1231   "(\<lambda>x. inverse(m) *s x + (-(inverse(m) *s c))) \<circ> (\<lambda>x. m *s x + c) = id"
  1326   "(\<lambda>x. inverse(m) *s x + (-(inverse(m) *s c))) \<circ> (\<lambda>x. m *s x + c) = id"
  1428  "(vector [x,y,z] ::('a::zero)^3)$2 = y"
  1523  "(vector [x,y,z] ::('a::zero)^3)$2 = y"
  1429  "(vector [x,y,z] ::('a::zero)^3)$3 = z"
  1524  "(vector [x,y,z] ::('a::zero)^3)$3 = z"
  1430   unfolding vector_def by simp_all
  1525   unfolding vector_def by simp_all
  1431 
  1526 
  1432 lemma forall_vector_1: "(\<forall>v::'a::zero^1. P v) \<longleftrightarrow> (\<forall>x. P(vector[x]))"
  1527 lemma forall_vector_1: "(\<forall>v::'a::zero^1. P v) \<longleftrightarrow> (\<forall>x. P(vector[x]))"
  1433   apply auto
  1528   by (metis vector_1 vector_one)
  1434   apply (erule_tac x="v$1" in allE)
       
  1435   apply (subgoal_tac "vector [v$1] = v")
       
  1436   apply simp
       
  1437   apply (vector vector_def)
       
  1438   apply simp
       
  1439   done
       
  1440 
  1529 
  1441 lemma forall_vector_2: "(\<forall>v::'a::zero^2. P v) \<longleftrightarrow> (\<forall>x y. P(vector[x, y]))"
  1530 lemma forall_vector_2: "(\<forall>v::'a::zero^2. P v) \<longleftrightarrow> (\<forall>x y. P(vector[x, y]))"
  1442   apply auto
  1531   apply auto
  1443   apply (erule_tac x="v$1" in allE)
  1532   apply (erule_tac x="v$1" in allE)
  1444   apply (erule_tac x="v$2" in allE)
  1533   apply (erule_tac x="v$2" in allE)