src/HOL/Analysis/Change_Of_Vars.thy
changeset 68072 493b818e8e10
parent 68001 0a2a1b6507c1
child 68073 fad29d2a17a5
equal deleted inserted replaced
68001:0a2a1b6507c1 68072:493b818e8e10
   177   qed
   177   qed
   178   show ?thesis
   178   show ?thesis
   179     by (rule induct_matrix_elementary) (auto intro: assms *)
   179     by (rule induct_matrix_elementary) (auto intro: assms *)
   180 qed
   180 qed
   181 
   181 
       
   182 lemma matrix_vector_mult_matrix_matrix_mult_compose:
       
   183   "( *v) (A ** B) = ( *v) A \<circ> ( *v) B"
       
   184   by (auto simp: matrix_vector_mul_assoc)
       
   185 
   182 lemma induct_linear_elementary:
   186 lemma induct_linear_elementary:
   183   fixes f :: "real^'n \<Rightarrow> real^'n"
   187   fixes f :: "real^'n \<Rightarrow> real^'n"
   184   assumes "linear f"
   188   assumes "linear f"
   185     and comp: "\<And>f g. \<lbrakk>linear f; linear g; P f; P g\<rbrakk> \<Longrightarrow> P(f \<circ> g)"
   189     and comp: "\<And>f g. \<lbrakk>linear f; linear g; P f; P g\<rbrakk> \<Longrightarrow> P(f \<circ> g)"
   186     and zeroes: "\<And>f i. \<lbrakk>linear f; \<And>x. (f x) $ i = 0\<rbrakk> \<Longrightarrow> P f"
   190     and zeroes: "\<And>f i. \<lbrakk>linear f; \<And>x. (f x) $ i = 0\<rbrakk> \<Longrightarrow> P f"
   192   have "P (( *v) A)" for A
   196   have "P (( *v) A)" for A
   193   proof (rule induct_matrix_elementary_alt)
   197   proof (rule induct_matrix_elementary_alt)
   194     fix A B
   198     fix A B
   195     assume "P (( *v) A)" and "P (( *v) B)"
   199     assume "P (( *v) A)" and "P (( *v) B)"
   196     then show "P (( *v) (A ** B))"
   200     then show "P (( *v) (A ** B))"
   197       by (metis (no_types, lifting) comp linear_compose matrix_compose matrix_eq matrix_vector_mul matrix_vector_mul_linear)
   201       by (auto simp add: matrix_vector_mult_matrix_matrix_mult_compose matrix_vector_mul_linear
       
   202           intro!: comp)
   198   next
   203   next
   199     fix A :: "real^'n^'n" and i
   204     fix A :: "real^'n^'n" and i
   200     assume "row i A = 0"
   205     assume "row i A = 0"
   201     then show "P (( *v) A)"
   206     show "P (( *v) A)"
   202       by (metis inner_zero_left matrix_vector_mul_component matrix_vector_mul_linear row_def vec_eq_iff vec_lambda_beta zeroes)
   207       using matrix_vector_mul_linear
       
   208       by (rule zeroes[where i=i])
       
   209         (metis \<open>row i A = 0\<close> inner_zero_left matrix_vector_mul_component row_def vec_lambda_eta)
   203   next
   210   next
   204     fix A :: "real^'n^'n"
   211     fix A :: "real^'n^'n"
   205     assume 0: "\<And>i j. i \<noteq> j \<Longrightarrow> A $ i $ j = 0"
   212     assume 0: "\<And>i j. i \<noteq> j \<Longrightarrow> A $ i $ j = 0"
   206     have "A $ i $ i * x $ i = (\<Sum>j\<in>UNIV. A $ i $ j * x $ j)" for x and i :: "'n"
   213     have "A $ i $ i * x $ i = (\<Sum>j\<in>UNIV. A $ i $ j * x $ j)" for x and i :: "'n"
   207       by (simp add: 0 comm_monoid_add_class.sum.remove [where x=i])
   214       by (simp add: 0 comm_monoid_add_class.sum.remove [where x=i])
   244        (is  "?f ` _ \<in> _")
   251        (is  "?f ` _ \<in> _")
   245    and measure_shear_interval: "measure lebesgue ((\<lambda>x. \<chi> i. if i = m then x$m + x$n else x$i) ` cbox a b)
   252    and measure_shear_interval: "measure lebesgue ((\<lambda>x. \<chi> i. if i = m then x$m + x$n else x$i) ` cbox a b)
   246                = measure lebesgue (cbox a b)" (is "?Q")
   253                = measure lebesgue (cbox a b)" (is "?Q")
   247 proof -
   254 proof -
   248   have lin: "linear ?f"
   255   have lin: "linear ?f"
   249     by (force simp: plus_vec_def scaleR_vec_def algebra_simps intro: linearI)
   256     by (rule linearI) (auto simp: plus_vec_def scaleR_vec_def algebra_simps)
   250   show fab: "?f ` cbox a b \<in> lmeasurable"
   257   show fab: "?f ` cbox a b \<in> lmeasurable"
   251     by (simp add: lin measurable_linear_image_interval)
   258     by (simp add: lin measurable_linear_image_interval)
   252   let ?c = "\<chi> i. if i = m then b$m + b$n else b$i"
   259   let ?c = "\<chi> i. if i = m then b$m + b$n else b$i"
   253   let ?mn = "axis m 1 - axis n (1::real)"
   260   let ?mn = "axis m 1 - axis n (1::real)"
   254   have eq1: "measure lebesgue (cbox a ?c)
   261   have eq1: "measure lebesgue (cbox a ?c)
   472     fix f :: "real^'n::_ \<Rightarrow> real^'n::_" and i and S :: "(real^'n::_) set"
   479     fix f :: "real^'n::_ \<Rightarrow> real^'n::_" and i and S :: "(real^'n::_) set"
   473     assume "linear f" and 0: "\<And>x. f x $ i = 0" and "S \<in> lmeasurable"
   480     assume "linear f" and 0: "\<And>x. f x $ i = 0" and "S \<in> lmeasurable"
   474     then have "\<not> inj f"
   481     then have "\<not> inj f"
   475       by (metis (full_types) linear_injective_imp_surjective one_neq_zero surjE vec_component)
   482       by (metis (full_types) linear_injective_imp_surjective one_neq_zero surjE vec_component)
   476     have detf: "det (matrix f) = 0"
   483     have detf: "det (matrix f) = 0"
   477       by (metis "0" \<open>linear f\<close> invertible_det_nz invertible_right_inverse matrix_right_invertible_surjective matrix_vector_mul surjE vec_component)
   484       using \<open>\<not> inj f\<close> det_nz_iff_inj[OF \<open>linear f\<close>] by blast
   478     show "f ` S \<in> lmeasurable \<and> ?Q f S"
   485     show "f ` S \<in> lmeasurable \<and> ?Q f S"
   479     proof
   486     proof
   480       show "f ` S \<in> lmeasurable"
   487       show "f ` S \<in> lmeasurable"
   481         using lmeasurable_iff_indicator_has_integral \<open>linear f\<close> \<open>\<not> inj f\<close> negligible_UNIV negligible_linear_singular_image by blast
   488         using lmeasurable_iff_indicator_has_integral \<open>linear f\<close> \<open>\<not> inj f\<close> negligible_UNIV negligible_linear_singular_image by blast
   482       have "measure lebesgue (f ` S) = 0"
   489       have "measure lebesgue (f ` S) = 0"
   498   next
   505   next
   499     fix m :: "'n" and n :: "'n" and S :: "(real, 'n) vec set"
   506     fix m :: "'n" and n :: "'n" and S :: "(real, 'n) vec set"
   500     assume "m \<noteq> n" and "S \<in> lmeasurable"
   507     assume "m \<noteq> n" and "S \<in> lmeasurable"
   501     let ?h = "\<lambda>v::(real, 'n) vec. \<chi> i. v $ Fun.swap m n id i"
   508     let ?h = "\<lambda>v::(real, 'n) vec. \<chi> i. v $ Fun.swap m n id i"
   502     have lin: "linear ?h"
   509     have lin: "linear ?h"
   503       by (simp add: plus_vec_def scaleR_vec_def linearI)
   510       by (rule linearI) (simp_all add: plus_vec_def scaleR_vec_def)
   504     have meq: "measure lebesgue ((\<lambda>v::(real, 'n) vec. \<chi> i. v $ Fun.swap m n id i) ` cbox a b)
   511     have meq: "measure lebesgue ((\<lambda>v::(real, 'n) vec. \<chi> i. v $ Fun.swap m n id i) ` cbox a b)
   505              = measure lebesgue (cbox a b)" for a b
   512              = measure lebesgue (cbox a b)" for a b
   506     proof (cases "cbox a b = {}")
   513     proof (cases "cbox a b = {}")
   507       case True then show ?thesis
   514       case True then show ?thesis
   508         by simp
   515         by simp
   530   next
   537   next
   531     fix m n :: "'n" and S :: "(real, 'n) vec set"
   538     fix m n :: "'n" and S :: "(real, 'n) vec set"
   532     assume "m \<noteq> n" and "S \<in> lmeasurable"
   539     assume "m \<noteq> n" and "S \<in> lmeasurable"
   533     let ?h = "\<lambda>v::(real, 'n) vec. \<chi> i. if i = m then v $ m + v $ n else v $ i"
   540     let ?h = "\<lambda>v::(real, 'n) vec. \<chi> i. if i = m then v $ m + v $ n else v $ i"
   534     have lin: "linear ?h"
   541     have lin: "linear ?h"
   535       by (auto simp: algebra_simps plus_vec_def scaleR_vec_def vec_eq_iff intro: linearI)
   542       by (rule linearI) (auto simp: algebra_simps plus_vec_def scaleR_vec_def vec_eq_iff)
   536     consider "m < n" | " n < m"
   543     consider "m < n" | " n < m"
   537       using \<open>m \<noteq> n\<close> less_linear by blast
   544       using \<open>m \<noteq> n\<close> less_linear by blast
   538     then have 1: "det(matrix ?h) = 1"
   545     then have 1: "det(matrix ?h) = 1"
   539     proof cases
   546     proof cases
   540       assume "m < n"
   547       assume "m < n"
   995             next
  1002             next
   996               case False
  1003               case False
   997               then show ?thesis
  1004               then show ?thesis
   998               proof (rule_tac x="(y - x) /\<^sub>R r" in bexI)
  1005               proof (rule_tac x="(y - x) /\<^sub>R r" in bexI)
   999                 have "f' x ((y - x) /\<^sub>R r) = f' x (y - x) /\<^sub>R r"
  1006                 have "f' x ((y - x) /\<^sub>R r) = f' x (y - x) /\<^sub>R r"
  1000                   by (simp add: lin linear_cmul)
  1007                   by (simp add: lin linear_scale)
  1001                 then have "dist (f' x ((y - x) /\<^sub>R r)) ((f y - f x) /\<^sub>R r) = norm (f' x (y - x) /\<^sub>R r - (f y - f x) /\<^sub>R r)"
  1008                 then have "dist (f' x ((y - x) /\<^sub>R r)) ((f y - f x) /\<^sub>R r) = norm (f' x (y - x) /\<^sub>R r - (f y - f x) /\<^sub>R r)"
  1002                   by (simp add: dist_norm)
  1009                   by (simp add: dist_norm)
  1003                 also have "\<dots> = norm (f' x (y - x) - (f y - f x)) / r"
  1010                 also have "\<dots> = norm (f' x (y - x) - (f y - f x)) / r"
  1004                   using \<open>r > 0\<close> by (simp add: real_vector.scale_right_diff_distrib [symmetric] divide_simps)
  1011                   using \<open>r > 0\<close> by (simp add: scale_right_diff_distrib [symmetric] divide_simps)
  1005                 also have "\<dots> \<le> norm (f y - (f x + f' x (y - x))) / norm (y - x)"
  1012                 also have "\<dots> \<le> norm (f y - (f x + f' x (y - x))) / norm (y - x)"
  1006                   using that \<open>r > 0\<close> False by (simp add: algebra_simps divide_simps dist_norm norm_minus_commute mult_right_mono)
  1013                   using that \<open>r > 0\<close> False by (simp add: algebra_simps divide_simps dist_norm norm_minus_commute mult_right_mono)
  1007                 also have "\<dots> < k"
  1014                 also have "\<dots> < k"
  1008                   using that \<open>0 < \<zeta>\<close> by (simp add: dist_commute r_def  \<zeta> [OF \<open>y \<in> S\<close> False])
  1015                   using that \<open>0 < \<zeta>\<close> by (simp add: dist_commute r_def  \<zeta> [OF \<open>y \<in> S\<close> False])
  1009                 finally show "dist (f' x ((y - x) /\<^sub>R r)) ((f y - f x) /\<^sub>R r) < k" .
  1016                 finally show "dist (f' x ((y - x) /\<^sub>R r)) ((f y - f x) /\<^sub>R r) < k" .
  1608   fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
  1615   fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
  1609   assumes "linear f" and lim0: "((\<lambda>x. f x /\<^sub>R norm x) \<longlongrightarrow> 0) (at 0 within S)"
  1616   assumes "linear f" and lim0: "((\<lambda>x. f x /\<^sub>R norm x) \<longlongrightarrow> 0) (at 0 within S)"
  1610     and lb: "\<And>v. v \<noteq> 0 \<Longrightarrow> (\<exists>k>0. \<forall>e>0. \<exists>x. x \<in> S - {0} \<and> norm x < e \<and> k * norm x \<le> \<bar>v \<bullet> x\<bar>)"
  1617     and lb: "\<And>v. v \<noteq> 0 \<Longrightarrow> (\<exists>k>0. \<forall>e>0. \<exists>x. x \<in> S - {0} \<and> norm x < e \<and> k * norm x \<le> \<bar>v \<bullet> x\<bar>)"
  1611   shows "f x = 0"
  1618   shows "f x = 0"
  1612 proof -
  1619 proof -
       
  1620   interpret linear f by fact
  1613   have "dim {x. f x = 0} \<le> DIM('a)"
  1621   have "dim {x. f x = 0} \<le> DIM('a)"
  1614     using dim_subset_UNIV by blast
  1622     by (rule dim_subset_UNIV)
  1615   moreover have False if less: "dim {x. f x = 0} < DIM('a)"
  1623   moreover have False if less: "dim {x. f x = 0} < DIM('a)"
  1616   proof -
  1624   proof -
  1617     obtain d where "d \<noteq> 0" and d: "\<And>y. f y = 0 \<Longrightarrow> d \<bullet> y = 0"
  1625     obtain d where "d \<noteq> 0" and d: "\<And>y. f y = 0 \<Longrightarrow> d \<bullet> y = 0"
  1618       using orthogonal_to_subspace_exists [OF less] orthogonal_def
  1626       using orthogonal_to_subspace_exists [OF less] orthogonal_def
  1619       by (metis (mono_tags, lifting) mem_Collect_eq span_clauses(1))
  1627       by (metis (mono_tags, lifting) mem_Collect_eq span_clauses(1))
  1660         with \<open>strict_mono \<rho>\<close> have "(\<alpha> \<circ> \<rho>) \<longlonglongrightarrow> 0"
  1668         with \<open>strict_mono \<rho>\<close> have "(\<alpha> \<circ> \<rho>) \<longlonglongrightarrow> 0"
  1661           by (metis LIMSEQ_subseq_LIMSEQ)
  1669           by (metis LIMSEQ_subseq_LIMSEQ)
  1662         with lim0 \<alpha> have "((\<lambda>x. f x /\<^sub>R norm x) \<circ> (\<alpha> \<circ> \<rho>)) \<longlonglongrightarrow> 0"
  1670         with lim0 \<alpha> have "((\<lambda>x. f x /\<^sub>R norm x) \<circ> (\<alpha> \<circ> \<rho>)) \<longlonglongrightarrow> 0"
  1663           by (force simp: tendsto_at_iff_sequentially)
  1671           by (force simp: tendsto_at_iff_sequentially)
  1664         then show "(f \<circ> (\<lambda>n. \<alpha> n /\<^sub>R norm (\<alpha> n)) \<circ> \<rho>) \<longlonglongrightarrow> 0"
  1672         then show "(f \<circ> (\<lambda>n. \<alpha> n /\<^sub>R norm (\<alpha> n)) \<circ> \<rho>) \<longlonglongrightarrow> 0"
  1665           by (simp add: o_def linear_cmul \<open>linear f\<close>)
  1673           by (simp add: o_def scale)
  1666       qed
  1674       qed
  1667     qed
  1675     qed
  1668     ultimately show False
  1676     ultimately show False
  1669       using \<open>k > 0\<close> by auto
  1677       using \<open>k > 0\<close> by auto
  1670   qed
  1678   qed
  1671   ultimately have dim: "dim {x. f x = 0} = DIM('a)"
  1679   ultimately have dim: "dim {x. f x = 0} = DIM('a)"
  1672     by force
  1680     by force
  1673   then show ?thesis
  1681   then show ?thesis
  1674     by (metis (mono_tags, lifting) UNIV_I assms(1) dim_eq_full linear_eq_0_span mem_Collect_eq)
  1682     using dim_eq_full
       
  1683     by (metis (mono_tags, lifting) eq_0_on_span eucl.span_Basis linear_axioms linear_eq_stdbasis
       
  1684         mem_Collect_eq module_hom_zero span_base span_raw_def)
  1675 qed
  1685 qed
  1676 
  1686 
  1677 lemma lemma_partial_derivatives:
  1687 lemma lemma_partial_derivatives:
  1678   fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
  1688   fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
  1679   assumes "linear f" and lim: "((\<lambda>x. f (x - a) /\<^sub>R norm (x - a)) \<longlongrightarrow> 0) (at a within S)"
  1689   assumes "linear f" and lim: "((\<lambda>x. f (x - a) /\<^sub>R norm (x - a)) \<longlongrightarrow> 0) (at a within S)"
  1948             let ?CA = "{x. Cauchy (\<lambda>n. (A n) *v x)}"
  1958             let ?CA = "{x. Cauchy (\<lambda>n. (A n) *v x)}"
  1949             have "subspace ?CA"
  1959             have "subspace ?CA"
  1950               unfolding subspace_def convergent_eq_Cauchy [symmetric]
  1960               unfolding subspace_def convergent_eq_Cauchy [symmetric]
  1951                 by (force simp: algebra_simps intro: tendsto_intros)
  1961                 by (force simp: algebra_simps intro: tendsto_intros)
  1952             then have CA_eq: "?CA = span ?CA"
  1962             then have CA_eq: "?CA = span ?CA"
  1953               by (metis span_eq)
  1963               by (metis span_eq_iff)
  1954             also have "\<dots> = UNIV"
  1964             also have "\<dots> = UNIV"
  1955             proof -
  1965             proof -
  1956               have "dim ?CA \<le> CARD('m)"
  1966               have "dim ?CA \<le> CARD('m)"
  1957                 by (rule dim_subset_UNIV_cart)
  1967                 using dim_subset_UNIV[of ?CA]
       
  1968                 by auto
  1958               moreover have "False" if less: "dim ?CA < CARD('m)"
  1969               moreover have "False" if less: "dim ?CA < CARD('m)"
  1959               proof -
  1970               proof -
  1960                 obtain d where "d \<noteq> 0" and d: "\<And>y. y \<in> span ?CA \<Longrightarrow> orthogonal d y"
  1971                 obtain d where "d \<noteq> 0" and d: "\<And>y. y \<in> span ?CA \<Longrightarrow> orthogonal d y"
  1961                   using less by (force intro: orthogonal_to_subspace_exists [of ?CA])
  1972                   using less by (force intro: orthogonal_to_subspace_exists [of ?CA])
  1962                 with x [OF \<open>d \<noteq> 0\<close>] obtain \<xi> where "\<xi> > 0"
  1973                 with x [OF \<open>d \<noteq> 0\<close>] obtain \<xi> where "\<xi> > 0"
  2100           then obtain B where B: "\<And>i j. (\<lambda>n. A n $ i $ j) \<longlonglongrightarrow> B $ i $ j"
  2111           then obtain B where B: "\<And>i j. (\<lambda>n. A n $ i $ j) \<longlonglongrightarrow> B $ i $ j"
  2101             by (auto simp: lambda_skolem)
  2112             by (auto simp: lambda_skolem)
  2102           have lin_df: "linear (f' x)"
  2113           have lin_df: "linear (f' x)"
  2103                and lim_df: "((\<lambda>y. (1 / norm (y - x)) *\<^sub>R (f y - (f x + f' x (y - x)))) \<longlongrightarrow> 0) (at x within S)"
  2114                and lim_df: "((\<lambda>y. (1 / norm (y - x)) *\<^sub>R (f y - (f x + f' x (y - x)))) \<longlongrightarrow> 0) (at x within S)"
  2104             using \<open>x \<in> S\<close> assms by (auto simp: has_derivative_within linear_linear)
  2115             using \<open>x \<in> S\<close> assms by (auto simp: has_derivative_within linear_linear)
  2105           moreover have "(matrix (f' x) - B) *v w = 0" for w
  2116           moreover
       
  2117           interpret linear "f' x" by fact
       
  2118           have "(matrix (f' x) - B) *v w = 0" for w
  2106           proof (rule lemma_partial_derivatives [of "( *v) (matrix (f' x) - B)"])
  2119           proof (rule lemma_partial_derivatives [of "( *v) (matrix (f' x) - B)"])
  2107             show "linear (( *v) (matrix (f' x) - B))"
  2120             show "linear (( *v) (matrix (f' x) - B))"
  2108               by (rule matrix_vector_mul_linear)
  2121               by (rule matrix_vector_mul_linear)
  2109             have "((\<lambda>y. ((f x + f' x (y - x)) - f y) /\<^sub>R norm (y - x)) \<longlongrightarrow> 0) (at x within S)"
  2122             have "((\<lambda>y. ((f x + f' x (y - x)) - f y) /\<^sub>R norm (y - x)) \<longlongrightarrow> 0) (at x within S)"
  2110               using tendsto_minus [OF lim_df] by (simp add: algebra_simps divide_simps)
  2123               using tendsto_minus [OF lim_df] by (simp add: algebra_simps divide_simps)
  2122                   show "\<forall>\<^sub>F k in sequentially. norm (onorm (\<lambda>y. (A k - B) *v y)) \<le> ?g k"
  2135                   show "\<forall>\<^sub>F k in sequentially. norm (onorm (\<lambda>y. (A k - B) *v y)) \<le> ?g k"
  2123                   proof (rule eventually_sequentiallyI)
  2136                   proof (rule eventually_sequentiallyI)
  2124                     fix k :: "nat"
  2137                     fix k :: "nat"
  2125                     assume "0 \<le> k"
  2138                     assume "0 \<le> k"
  2126                     have "0 \<le> onorm (( *v) (A k - B))"
  2139                     have "0 \<le> onorm (( *v) (A k - B))"
  2127                       by (simp add: linear_linear onorm_pos_le matrix_vector_mul_linear)
  2140                       using matrix_vector_mul_bounded_linear
       
  2141                       by (rule onorm_pos_le)
  2128                     then show "norm (onorm (( *v) (A k - B))) \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>(A k - B) $ i $ j\<bar>)"
  2142                     then show "norm (onorm (( *v) (A k - B))) \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>(A k - B) $ i $ j\<bar>)"
  2129                       by (simp add: onorm_le_matrix_component_sum del: vector_minus_component)
  2143                       by (simp add: onorm_le_matrix_component_sum del: vector_minus_component)
  2130                   qed
  2144                   qed
  2131                 next
  2145                 next
  2132                   show "?g \<longlonglongrightarrow> 0"
  2146                   show "?g \<longlonglongrightarrow> 0"
  2172                 qed
  2186                 qed
  2173               qed
  2187               qed
  2174               then show "((\<lambda>y. (matrix (f' x) - B) *v (y - x) /\<^sub>R
  2188               then show "((\<lambda>y. (matrix (f' x) - B) *v (y - x) /\<^sub>R
  2175                            norm (y - x) - (f x + f' x (y - x) - f y) /\<^sub>R norm (y - x)) \<longlongrightarrow> 0)
  2189                            norm (y - x) - (f x + f' x (y - x) - f y) /\<^sub>R norm (y - x)) \<longlongrightarrow> 0)
  2176                           (at x within S)"
  2190                           (at x within S)"
  2177                 by (simp add: algebra_simps lin_df linear_diff matrix_vector_mul_linear)
  2191                 by (simp add: algebra_simps diff lin_df matrix_vector_mul_linear scalar_mult_eq_scaleR)
  2178             qed
  2192             qed
  2179           qed (use x in \<open>simp; auto simp: not_less\<close>)
  2193           qed (use x in \<open>simp; auto simp: not_less\<close>)
  2180           ultimately have "f' x = ( *v) B"
  2194           ultimately have "f' x = ( *v) B"
  2181             by (force simp: algebra_simps)
  2195             by (force simp: algebra_simps scalar_mult_eq_scaleR)
  2182           show "matrix (f' x) $ m $ n \<le> b"
  2196           show "matrix (f' x) $ m $ n \<le> b"
  2183           proof (rule tendsto_upperbound [of "\<lambda>i. (A i $ m $ n)" _ sequentially])
  2197           proof (rule tendsto_upperbound [of "\<lambda>i. (A i $ m $ n)" _ sequentially])
  2184             show "(\<lambda>i. A i $ m $ n) \<longlonglongrightarrow> matrix (f' x) $ m $ n"
  2198             show "(\<lambda>i. A i $ m $ n) \<longlonglongrightarrow> matrix (f' x) $ m $ n"
  2185               by (simp add: B \<open>f' x = ( *v) B\<close>)
  2199               by (simp add: B \<open>f' x = ( *v) B\<close>)
  2186             show "\<forall>\<^sub>F i in sequentially. A i $ m $ n \<le> b"
  2200             show "\<forall>\<^sub>F i in sequentially. A i $ m $ n \<le> b"
  2226                 have split246: "\<lbrakk>norm y \<le> e / 6; norm(x - y) \<le> e / 4\<rbrakk> \<Longrightarrow> norm x \<le> e/2" if "e > 0" for e and x y :: "real^'n"
  2240                 have split246: "\<lbrakk>norm y \<le> e / 6; norm(x - y) \<le> e / 4\<rbrakk> \<Longrightarrow> norm x \<le> e/2" if "e > 0" for e and x y :: "real^'n"
  2227                   using norm_triangle_le [of y "x-y" "e/2"] \<open>e > 0\<close> by simp
  2241                   using norm_triangle_le [of y "x-y" "e/2"] \<open>e > 0\<close> by simp
  2228                 have "linear (f' x)"
  2242                 have "linear (f' x)"
  2229                   using True f has_derivative_linear by blast
  2243                   using True f has_derivative_linear by blast
  2230                 then have "norm (f' x (y - x) - B *v (y - x)) = norm ((matrix (f' x) - B) *v (y - x))"
  2244                 then have "norm (f' x (y - x) - B *v (y - x)) = norm ((matrix (f' x) - B) *v (y - x))"
  2231                   by (metis matrix_vector_mul matrix_vector_mult_diff_rdistrib)
  2245                   by (simp add: matrix_vector_mult_diff_rdistrib)
  2232                 also have "\<dots> \<le> (e * norm (y - x)) / 2"
  2246                 also have "\<dots> \<le> (e * norm (y - x)) / 2"
  2233                 proof (rule split246)
  2247                 proof (rule split246)
  2234                   have "norm ((?A - B) *v (y - x)) / norm (y - x) \<le> onorm(\<lambda>x. (?A - B) *v x)"
  2248                   have "norm ((?A - B) *v (y - x)) / norm (y - x) \<le> onorm(\<lambda>x. (?A - B) *v x)"
  2235                     by (simp add: le_onorm linear_linear matrix_vector_mul_linear)
  2249                     by (rule le_onorm) auto
  2236                   also have  "\<dots> < e/6"
  2250                   also have  "\<dots> < e/6"
  2237                     by (rule Bo_e6)
  2251                     by (rule Bo_e6)
  2238                   finally have "norm ((?A - B) *v (y - x)) / norm (y - x) < e / 6" .
  2252                   finally have "norm ((?A - B) *v (y - x)) / norm (y - x) < e / 6" .
  2239                   then show "norm ((?A - B) *v (y - x)) \<le> e * norm (y - x) / 6"
  2253                   then show "norm ((?A - B) *v (y - x)) \<le> e * norm (y - x) / 6"
  2240                     by (simp add: divide_simps False)
  2254                     by (simp add: divide_simps False)
  2443       then have "norm (inv T x) \<le> m"
  2457       then have "norm (inv T x) \<le> m"
  2444         using orthogonal_transformation_inv [OF T] by (simp add: orthogonal_transformation_norm)
  2458         using orthogonal_transformation_inv [OF T] by (simp add: orthogonal_transformation_norm)
  2445       moreover have "\<exists>t\<in>T -` P. norm (inv T x - t) \<le> e"
  2459       moreover have "\<exists>t\<in>T -` P. norm (inv T x - t) \<le> e"
  2446       proof
  2460       proof
  2447         have "T (inv T x - inv T t) = x - t"
  2461         have "T (inv T x - inv T t) = x - t"
  2448           using T linear_diff orthogonal_transformation_def by fastforce
  2462           using T linear_diff orthogonal_transformation_def
       
  2463           by (metis (no_types, hide_lams) Tinv)
  2449         then have "norm (inv T x - inv T t) = norm (x - t)"
  2464         then have "norm (inv T x - inv T t) = norm (x - t)"
  2450           by (metis T orthogonal_transformation_norm)
  2465           by (metis T orthogonal_transformation_norm)
  2451         then show "norm (inv T x - inv T t) \<le> e"
  2466         then show "norm (inv T x - inv T t) \<le> e"
  2452           using \<open>norm (x - t) \<le> e\<close> by linarith
  2467           using \<open>norm (x - t) \<le> e\<close> by linarith
  2453        next
  2468        next
  2471  obtains S where "S \<in> lmeasurable"
  2486  obtains S where "S \<in> lmeasurable"
  2472             and "{z. norm(z - w) \<le> m \<and> (\<exists>t \<in> P. norm(z - w - t) \<le> e)} \<subseteq> S"
  2487             and "{z. norm(z - w) \<le> m \<and> (\<exists>t \<in> P. norm(z - w - t) \<le> e)} \<subseteq> S"
  2473             and "measure lebesgue S \<le> (2 * e) * (2 * m) ^ (CARD('n) - 1)"
  2488             and "measure lebesgue S \<le> (2 * e) * (2 * m) ^ (CARD('n) - 1)"
  2474 proof -
  2489 proof -
  2475   obtain a where "a \<noteq> 0" "P \<subseteq> {x. a \<bullet> x = 0}"
  2490   obtain a where "a \<noteq> 0" "P \<subseteq> {x. a \<bullet> x = 0}"
  2476     using lowdim_subset_hyperplane [of P] P span_inc by auto
  2491     using lowdim_subset_hyperplane [of P] P span_base by auto
  2477   then obtain S where S: "S \<in> lmeasurable"
  2492   then obtain S where S: "S \<in> lmeasurable"
  2478     and subS: "{z. norm z \<le> m \<and> (\<exists>t \<in> P. norm(z - t) \<le> e)} \<subseteq> S"
  2493     and subS: "{z. norm z \<le> m \<and> (\<exists>t \<in> P. norm(z - t) \<le> e)} \<subseteq> S"
  2479     and mS: "measure lebesgue S \<le> (2 * e) * (2 * m) ^ (CARD('n) - 1)"
  2494     and mS: "measure lebesgue S \<le> (2 * e) * (2 * m) ^ (CARD('n) - 1)"
  2480     by (rule Sard_lemma0 [OF _ _ \<open>0 \<le> m\<close> \<open>0 \<le> e\<close>])
  2495     by (rule Sard_lemma0 [OF _ _ \<open>0 \<le> m\<close> \<open>0 \<le> e\<close>])
  2481   show thesis
  2496   show thesis
  2564       then have uv_ne: "cbox u v \<noteq> {}"
  2579       then have uv_ne: "cbox u v \<noteq> {}"
  2565         using cbox that by fastforce
  2580         using cbox that by fastforce
  2566       obtain x where x: "x \<in> S \<inter> cbox u v" "cbox u v \<subseteq> ball x (r x)"
  2581       obtain x where x: "x \<in> S \<inter> cbox u v" "cbox u v \<subseteq> ball x (r x)"
  2567         using \<open>K \<in> \<D>\<close> covered uv by blast
  2582         using \<open>K \<in> \<D>\<close> covered uv by blast
  2568       then have "dim (range (f' x)) < ?n"
  2583       then have "dim (range (f' x)) < ?n"
  2569         using rank_dim_range [of "matrix (f' x)"] lin_f' rank by fastforce
  2584         using rank_dim_range [of "matrix (f' x)"] x rank[of x]
       
  2585         by (auto simp: matrix_works scalar_mult_eq_scaleR lin_f')
  2570       then obtain T where T: "T \<in> lmeasurable"
  2586       then obtain T where T: "T \<in> lmeasurable"
  2571             and subT: "{z. norm(z - f x) \<le> (2 * B) * norm(v - u) \<and> (\<exists>t \<in> range (f' x). norm(z - f x - t) \<le> d * norm(v - u))} \<subseteq> T"
  2587             and subT: "{z. norm(z - f x) \<le> (2 * B) * norm(v - u) \<and> (\<exists>t \<in> range (f' x). norm(z - f x - t) \<le> d * norm(v - u))} \<subseteq> T"
  2572             and measT: "?\<mu> T \<le> (2 * (d * norm(v - u))) * (2 * ((2 * B) * norm(v - u))) ^ (?n - 1)"
  2588             and measT: "?\<mu> T \<le> (2 * (d * norm(v - u))) * (2 * ((2 * B) * norm(v - u))) ^ (?n - 1)"
  2573                         (is "_ \<le> ?DVU")
  2589                         (is "_ \<le> ?DVU")
  2574         apply (rule Sard_lemma1 [of "range (f' x)" "(2 * B) * norm(v - u)" "d * norm(v - u)" "f x"])
  2590         apply (rule Sard_lemma1 [of "range (f' x)" "(2 * B) * norm(v - u)" "d * norm(v - u)" "f x"])
  2584             by (metis dist_norm mem_ball norm_minus_commute subsetCE x(2))
  2600             by (metis dist_norm mem_ball norm_minus_commute subsetCE x(2))
  2585           then have le_dyx: "norm (f y - f x - f' x (y - x)) \<le> d * norm (y - x)"
  2601           then have le_dyx: "norm (f y - f x - f' x (y - x)) \<le> d * norm (y - x)"
  2586             using r [of x y] x \<open>y \<in> S\<close> by blast
  2602             using r [of x y] x \<open>y \<in> S\<close> by blast
  2587           have yx_le: "norm (y - x) \<le> norm (v - u)"
  2603           have yx_le: "norm (y - x) \<le> norm (v - u)"
  2588           proof (rule norm_le_componentwise_cart)
  2604           proof (rule norm_le_componentwise_cart)
  2589             show "\<bar>(y - x) $ i\<bar> \<le> \<bar>(v - u) $ i\<bar>" for i
  2605             show "norm ((y - x) $ i) \<le> norm ((v - u) $ i)" for i
  2590             using x y by (force simp: mem_box_cart dest!: spec [where x=i])
  2606               using x y by (force simp: mem_box_cart dest!: spec [where x=i])
  2591           qed
  2607           qed
  2592           have *: "\<lbrakk>norm(y - x - z) \<le> d; norm z \<le> B; d \<le> B\<rbrakk> \<Longrightarrow> norm(y - x) \<le> 2 * B"
  2608           have *: "\<lbrakk>norm(y - x - z) \<le> d; norm z \<le> B; d \<le> B\<rbrakk> \<Longrightarrow> norm(y - x) \<le> 2 * B"
  2593             for x y z :: "real^'n::_" and d B
  2609             for x y z :: "real^'n::_" and d B
  2594             using norm_triangle_ineq2 [of "y - x" z] by auto
  2610             using norm_triangle_ineq2 [of "y - x" z] by auto
  2595           show "norm (f y - f x) \<le> 2 * (B * norm (v - u))"
  2611           show "norm (f y - f x) \<le> 2 * (B * norm (v - u))"
  3175       let ?fgh = "\<lambda>x. \<bar>det (matrix (h' x))\<bar> * (\<bar>det (matrix (g' (h x)))\<bar> * f (g (h x)))"
  3191       let ?fgh = "\<lambda>x. \<bar>det (matrix (h' x))\<bar> * (\<bar>det (matrix (g' (h x)))\<bar> * f (g (h x)))"
  3176       have ddf: "?fgh x = f x"
  3192       have ddf: "?fgh x = f x"
  3177         if "x \<in> T" for x
  3193         if "x \<in> T" for x
  3178       proof -
  3194       proof -
  3179         have "matrix (h' x) ** matrix (g' (h x)) = mat 1"
  3195         have "matrix (h' x) ** matrix (g' (h x)) = mat 1"
  3180           using that id matrix_compose
  3196           using that id[OF that] der_g[of "h x"] gh[OF that] left_inverse_linear has_derivative_linear
  3181           by (metis der_g gh has_derivative_linear left_inverse_linear matrix_id_mat_1)
  3197           by (subst matrix_compose[symmetric]) (force simp: matrix_id_mat_1 has_derivative_linear)+
  3182         then have "\<bar>det (matrix (h' x))\<bar> * \<bar>det (matrix (g' (h x)))\<bar> = 1"
  3198         then have "\<bar>det (matrix (h' x))\<bar> * \<bar>det (matrix (g' (h x)))\<bar> = 1"
  3183           by (metis abs_1 abs_mult det_I det_mul)
  3199           by (metis abs_1 abs_mult det_I det_mul)
  3184         then show ?thesis
  3200         then show ?thesis
  3185           by (simp add: gh that)
  3201           by (simp add: gh that)
  3186       qed
  3202       qed