src/HOL/Real_Vector_Spaces.thy
changeset 71720 1d8a1f727879
parent 71544 66bc4b668d6e
child 71827 5e315defb038
equal deleted inserted replaced
71699:8e5c20e4e11a 71720:1d8a1f727879
    60     and representation_raw_def: representation = real_vector.representation
    60     and representation_raw_def: representation = real_vector.representation
    61     and subspace_raw_def: subspace = real_vector.subspace
    61     and subspace_raw_def: subspace = real_vector.subspace
    62     and span_raw_def: span = real_vector.span
    62     and span_raw_def: span = real_vector.span
    63     and extend_basis_raw_def: extend_basis = real_vector.extend_basis
    63     and extend_basis_raw_def: extend_basis = real_vector.extend_basis
    64     and dim_raw_def: dim = real_vector.dim
    64     and dim_raw_def: dim = real_vector.dim
    65     apply unfold_locales
    65 proof unfold_locales
    66        apply (rule scaleR_add_right)
    66   show "Vector_Spaces.linear (*\<^sub>R) (*\<^sub>R) = linear" "Vector_Spaces.linear (*) (*\<^sub>R) = linear"
    67       apply (rule scaleR_add_left)
    67     by (force simp: linear_def real_scaleR_def[abs_def])+
    68      apply (rule scaleR_scaleR)
    68 qed (use scaleR_add_right scaleR_add_left scaleR_scaleR scaleR_one in auto)
    69     apply (rule scaleR_one)
       
    70    apply (force simp: linear_def)
       
    71   apply (force simp: linear_def real_scaleR_def[abs_def])
       
    72   done
       
    73 
    69 
    74 hide_const (open)\<comment> \<open>locale constants\<close>
    70 hide_const (open)\<comment> \<open>locale constants\<close>
    75   real_vector.dependent
    71   real_vector.dependent
    76   real_vector.independent
    72   real_vector.independent
    77   real_vector.representation
    73   real_vector.representation
    84 
    80 
    85 global_interpretation real_vector?: vector_space_pair "scaleR::_\<Rightarrow>_\<Rightarrow>'a::real_vector" "scaleR::_\<Rightarrow>_\<Rightarrow>'b::real_vector"
    81 global_interpretation real_vector?: vector_space_pair "scaleR::_\<Rightarrow>_\<Rightarrow>'a::real_vector" "scaleR::_\<Rightarrow>_\<Rightarrow>'b::real_vector"
    86   rewrites  "Vector_Spaces.linear (*\<^sub>R) (*\<^sub>R) = linear"
    82   rewrites  "Vector_Spaces.linear (*\<^sub>R) (*\<^sub>R) = linear"
    87     and "Vector_Spaces.linear (*) (*\<^sub>R) = linear"
    83     and "Vector_Spaces.linear (*) (*\<^sub>R) = linear"
    88   defines construct_raw_def: construct = real_vector.construct
    84   defines construct_raw_def: construct = real_vector.construct
    89   apply unfold_locales
    85 proof unfold_locales
    90   unfolding linear_def real_scaleR_def
    86   show "Vector_Spaces.linear (*) (*\<^sub>R) = linear"
    91   by (rule refl)+
    87   unfolding linear_def real_scaleR_def by auto
       
    88 qed (auto simp: linear_def)
    92 
    89 
    93 hide_const (open)\<comment> \<open>locale constants\<close>
    90 hide_const (open)\<comment> \<open>locale constants\<close>
    94   real_vector.construct
    91   real_vector.construct
    95 
    92 
    96 lemma linear_compose: "linear f \<Longrightarrow> linear g \<Longrightarrow> linear (g \<circ> f)"
    93 lemma linear_compose: "linear f \<Longrightarrow> linear g \<Longrightarrow> linear (g \<circ> f)"
   388 
   385 
   389 lemma Reals_minus [simp]: "a \<in> \<real> \<Longrightarrow> - a \<in> \<real>"
   386 lemma Reals_minus [simp]: "a \<in> \<real> \<Longrightarrow> - a \<in> \<real>"
   390   by (auto simp: Reals_def)
   387   by (auto simp: Reals_def)
   391 
   388 
   392 lemma Reals_minus_iff [simp]: "- a \<in> \<real> \<longleftrightarrow> a \<in> \<real>"
   389 lemma Reals_minus_iff [simp]: "- a \<in> \<real> \<longleftrightarrow> a \<in> \<real>"
   393   apply (auto simp: Reals_def)
   390   using Reals_minus by fastforce
   394   by (metis add.inverse_inverse of_real_minus rangeI)
       
   395 
   391 
   396 lemma Reals_diff [simp]: "a \<in> \<real> \<Longrightarrow> b \<in> \<real> \<Longrightarrow> a - b \<in> \<real>"
   392 lemma Reals_diff [simp]: "a \<in> \<real> \<Longrightarrow> b \<in> \<real> \<Longrightarrow> a - b \<in> \<real>"
   397   by (metis Reals_add Reals_minus_iff add_uminus_conv_diff)
   393   by (metis Reals_add Reals_minus_iff add_uminus_conv_diff)
   398 
   394 
   399 lemma Reals_mult [simp]: "a \<in> \<real> \<Longrightarrow> b \<in> \<real> \<Longrightarrow> a * b \<in> \<real>"
   395 lemma Reals_mult [simp]: "a \<in> \<real> \<Longrightarrow> b \<in> \<real> \<Longrightarrow> a * b \<in> \<real>"
   512 lemma pos_minus_divideR_less_eq [field_simps]:
   508 lemma pos_minus_divideR_less_eq [field_simps]:
   513   "- (b /\<^sub>R c) < a \<longleftrightarrow> - b < c *\<^sub>R a" if "c > 0"
   509   "- (b /\<^sub>R c) < a \<longleftrightarrow> - b < c *\<^sub>R a" if "c > 0"
   514   using that by (simp add: less_le_not_le pos_le_minus_divideR_eq pos_minus_divideR_le_eq) 
   510   using that by (simp add: less_le_not_le pos_le_minus_divideR_eq pos_minus_divideR_le_eq) 
   515 
   511 
   516 lemma scaleR_image_atLeastAtMost: "c > 0 \<Longrightarrow> scaleR c ` {x..y} = {c *\<^sub>R x..c *\<^sub>R y}"
   512 lemma scaleR_image_atLeastAtMost: "c > 0 \<Longrightarrow> scaleR c ` {x..y} = {c *\<^sub>R x..c *\<^sub>R y}"
   517   apply (auto intro!: scaleR_left_mono)
   513   apply (auto intro!: scaleR_left_mono simp: image_iff Bex_def)
   518   apply (rule_tac x = "inverse c *\<^sub>R xa" in image_eqI)
   514   by (meson local.eq_iff pos_divideR_le_eq pos_le_divideR_eq)
   519    apply (simp_all add: pos_le_divideR_eq[symmetric] scaleR_scaleR scaleR_one)
       
   520   done
       
   521 
   515 
   522 end
   516 end
   523 
   517 
   524 lemma neg_le_divideR_eq [field_simps]:
   518 lemma neg_le_divideR_eq [field_simps]:
   525   "a \<le> b /\<^sub>R c \<longleftrightarrow> b \<le> c *\<^sub>R a" (is "?P \<longleftrightarrow> ?Q") if "c < 0"
   519   "a \<le> b /\<^sub>R c \<longleftrightarrow> b \<le> c *\<^sub>R a" (is "?P \<longleftrightarrow> ?Q") if "c < 0"
  1271   proof (rule ext, safe)
  1265   proof (rule ext, safe)
  1272     fix S :: "real set"
  1266     fix S :: "real set"
  1273     assume "open S"
  1267     assume "open S"
  1274     then obtain f where "\<forall>x\<in>S. 0 < f x \<and> (\<forall>y. dist y x < f x \<longrightarrow> y \<in> S)"
  1268     then obtain f where "\<forall>x\<in>S. 0 < f x \<and> (\<forall>y. dist y x < f x \<longrightarrow> y \<in> S)"
  1275       unfolding open_dist bchoice_iff ..
  1269       unfolding open_dist bchoice_iff ..
  1276     then have *: "S = (\<Union>x\<in>S. {x - f x <..} \<inter> {..< x + f x})"
  1270     then have *: "(\<Union>x\<in>S. {x - f x <..} \<inter> {..< x + f x}) = S" (is "?S = S")
  1277       by (fastforce simp: dist_real_def)
  1271       by (fastforce simp: dist_real_def)
  1278     show "generate_topology (range lessThan \<union> range greaterThan) S"
  1272     moreover have "generate_topology (range lessThan \<union> range greaterThan) ?S"
  1279       apply (subst *)
  1273       by (force intro: generate_topology.Basis generate_topology_Union generate_topology.Int)
  1280       apply (intro generate_topology_Union generate_topology.Int)
  1274     ultimately show "generate_topology (range lessThan \<union> range greaterThan) S"
  1281        apply (auto intro: generate_topology.Basis)
  1275       by simp
  1282       done
       
  1283   next
  1276   next
  1284     fix S :: "real set"
  1277     fix S :: "real set"
  1285     assume "generate_topology (range lessThan \<union> range greaterThan) S"
  1278     assume "generate_topology (range lessThan \<union> range greaterThan) S"
  1286     moreover have "\<And>a::real. open {..<a}"
  1279     moreover have "\<And>a::real. open {..<a}"
  1287       unfolding open_dist dist_real_def
  1280       unfolding open_dist dist_real_def
  1546 
  1539 
  1547 lemma prod_diff_prod: "(x ** y - a ** b) = (x - a) ** (y - b) + (x - a) ** b + a ** (y - b)"
  1540 lemma prod_diff_prod: "(x ** y - a ** b) = (x - a) ** (y - b) + (x - a) ** b + a ** (y - b)"
  1548   by (simp add: diff_left diff_right)
  1541   by (simp add: diff_left diff_right)
  1549 
  1542 
  1550 lemma flip: "bounded_bilinear (\<lambda>x y. y ** x)"
  1543 lemma flip: "bounded_bilinear (\<lambda>x y. y ** x)"
  1551   apply standard
  1544 proof
  1552       apply (simp_all add: add_right add_left scaleR_right scaleR_left)
  1545   show "\<exists>K. \<forall>a b. norm (b ** a) \<le> norm a * norm b * K"
  1553   by (metis bounded mult.commute)
  1546     by (metis bounded mult.commute)
       
  1547 qed (simp_all add: add_right add_left scaleR_right scaleR_left)
  1554 
  1548 
  1555 lemma comp1:
  1549 lemma comp1:
  1556   assumes "bounded_linear g"
  1550   assumes "bounded_linear g"
  1557   shows "bounded_bilinear (\<lambda>x. (**) (g x))"
  1551   shows "bounded_bilinear (\<lambda>x. (**) (g x))"
  1558 proof unfold_locales
  1552 proof unfold_locales
  1651     qed
  1645     qed
  1652   qed
  1646   qed
  1653 qed
  1647 qed
  1654 
  1648 
  1655 lemma bounded_bilinear_mult: "bounded_bilinear ((*) :: 'a \<Rightarrow> 'a \<Rightarrow> 'a::real_normed_algebra)"
  1649 lemma bounded_bilinear_mult: "bounded_bilinear ((*) :: 'a \<Rightarrow> 'a \<Rightarrow> 'a::real_normed_algebra)"
  1656   apply (rule bounded_bilinear.intro)
  1650 proof (rule bounded_bilinear.intro)
  1657       apply (auto simp: algebra_simps)
  1651   show "\<exists>K. \<forall>a b::'a. norm (a * b) \<le> norm a * norm b * K"
  1658   apply (rule_tac x=1 in exI)
  1652     by (rule_tac x=1 in exI) (simp add: norm_mult_ineq)
  1659   apply (simp add: norm_mult_ineq)
  1653 qed (auto simp: algebra_simps)
  1660   done
       
  1661 
  1654 
  1662 lemma bounded_linear_mult_left: "bounded_linear (\<lambda>x::'a::real_normed_algebra. x * y)"
  1655 lemma bounded_linear_mult_left: "bounded_linear (\<lambda>x::'a::real_normed_algebra. x * y)"
  1663   using bounded_bilinear_mult
  1656   using bounded_bilinear_mult
  1664   by (rule bounded_bilinear.bounded_linear_left)
  1657   by (rule bounded_bilinear.bounded_linear_left)
  1665 
  1658 
  1676 lemma bounded_linear_divide: "bounded_linear (\<lambda>x. x / y)"
  1669 lemma bounded_linear_divide: "bounded_linear (\<lambda>x. x / y)"
  1677   for y :: "'a::real_normed_field"
  1670   for y :: "'a::real_normed_field"
  1678   unfolding divide_inverse by (rule bounded_linear_mult_left)
  1671   unfolding divide_inverse by (rule bounded_linear_mult_left)
  1679 
  1672 
  1680 lemma bounded_bilinear_scaleR: "bounded_bilinear scaleR"
  1673 lemma bounded_bilinear_scaleR: "bounded_bilinear scaleR"
  1681   apply (rule bounded_bilinear.intro)
  1674 proof (rule bounded_bilinear.intro)
  1682       apply (auto simp: algebra_simps)
  1675   show "\<exists>K. \<forall>a b. norm (a *\<^sub>R b) \<le> norm a * norm b * K"
  1683   apply (rule_tac x=1 in exI, simp)
  1676     using less_eq_real_def by auto
  1684   done
  1677 qed (auto simp: algebra_simps)
  1685 
  1678 
  1686 lemma bounded_linear_scaleR_left: "bounded_linear (\<lambda>r. scaleR r x)"
  1679 lemma bounded_linear_scaleR_left: "bounded_linear (\<lambda>r. scaleR r x)"
  1687   using bounded_bilinear_scaleR
  1680   using bounded_bilinear_scaleR
  1688   by (rule bounded_bilinear.bounded_linear_left)
  1681   by (rule bounded_bilinear.bounded_linear_left)
  1689 
  1682 
  1714     by (auto intro: exI[of _ "f 1"] bounded_linear_mult_left)
  1707     by (auto intro: exI[of _ "f 1"] bounded_linear_mult_left)
  1715 qed
  1708 qed
  1716 
  1709 
  1717 instance real_normed_algebra_1 \<subseteq> perfect_space
  1710 instance real_normed_algebra_1 \<subseteq> perfect_space
  1718 proof
  1711 proof
  1719   show "\<not> open {x}" for x :: 'a
  1712   fix x::'a
  1720     apply (clarsimp simp: open_dist dist_norm)
  1713   have "\<And>e. 0 < e \<Longrightarrow> \<exists>y. norm (y - x) < e \<and> y \<noteq> x"
  1721     apply (rule_tac x = "x + of_real (e/2)" in exI)
  1714     by (rule_tac x = "x + of_real (e/2)" in exI) auto
  1722     apply simp
  1715   then show "\<not> open {x}" 
  1723     done
  1716     by (clarsimp simp: open_dist dist_norm)
  1724 qed
  1717 qed
  1725 
  1718 
  1726 
  1719 
  1727 subsection \<open>Filters and Limits on Metric Space\<close>
  1720 subsection \<open>Filters and Limits on Metric Space\<close>
  1728 
  1721 
  1791   with le show "eventually (\<lambda>x. dist (g x) b < e) F"
  1784   with le show "eventually (\<lambda>x. dist (g x) b < e) F"
  1792     using le_less_trans by (rule eventually_elim2)
  1785     using le_less_trans by (rule eventually_elim2)
  1793 qed
  1786 qed
  1794 
  1787 
  1795 lemma filterlim_real_sequentially: "LIM x sequentially. real x :> at_top"
  1788 lemma filterlim_real_sequentially: "LIM x sequentially. real x :> at_top"
  1796   apply (clarsimp simp: filterlim_at_top)
  1789 proof (clarsimp simp: filterlim_at_top)
  1797   apply (rule_tac c="nat \<lceil>Z + 1\<rceil>" in eventually_sequentiallyI, linarith)
  1790   fix Z
  1798   done
  1791   show "\<forall>\<^sub>F x in sequentially. Z \<le> real x"
       
  1792     by (meson eventually_sequentiallyI nat_ceiling_le_eq)
       
  1793 qed
  1799 
  1794 
  1800 lemma filterlim_nat_sequentially: "filterlim nat sequentially at_top"
  1795 lemma filterlim_nat_sequentially: "filterlim nat sequentially at_top"
  1801 proof -
  1796 proof -
  1802   have "\<forall>\<^sub>F x in at_top. Z \<le> nat x" for Z
  1797   have "\<forall>\<^sub>F x in at_top. Z \<le> nat x" for Z
  1803     by (auto intro!: eventually_at_top_linorderI[where c="int Z"])
  1798     by (auto intro!: eventually_at_top_linorderI[where c="int Z"])
  1812   then show ?thesis
  1807   then show ?thesis
  1813     unfolding filterlim_at_top ..
  1808     unfolding filterlim_at_top ..
  1814 qed
  1809 qed
  1815 
  1810 
  1816 lemma filterlim_sequentially_iff_filterlim_real:
  1811 lemma filterlim_sequentially_iff_filterlim_real:
  1817   "filterlim f sequentially F \<longleftrightarrow> filterlim (\<lambda>x. real (f x)) at_top F"
  1812   "filterlim f sequentially F \<longleftrightarrow> filterlim (\<lambda>x. real (f x)) at_top F" (is "?lhs = ?rhs")
  1818   apply (rule iffI)
  1813 proof
  1819   subgoal using filterlim_compose filterlim_real_sequentially by blast
  1814   assume ?lhs then show ?rhs
  1820   subgoal premises prems
  1815     using filterlim_compose filterlim_real_sequentially by blast
       
  1816 next
       
  1817   assume R: ?rhs
       
  1818   show ?lhs
  1821   proof -
  1819   proof -
  1822     have "filterlim (\<lambda>x. nat (floor (real (f x)))) sequentially F"
  1820     have "filterlim (\<lambda>x. nat (floor (real (f x)))) sequentially F"
  1823       by (intro filterlim_compose[OF filterlim_nat_sequentially]
  1821       by (intro filterlim_compose[OF filterlim_nat_sequentially]
  1824           filterlim_compose[OF filterlim_floor_sequentially] prems)
  1822           filterlim_compose[OF filterlim_floor_sequentially] R)
  1825     then show ?thesis by simp
  1823     then show ?thesis by simp
  1826   qed
  1824   qed
  1827   done
  1825 qed
  1828 
  1826 
  1829 
  1827 
  1830 subsubsection \<open>Limits of Sequences\<close>
  1828 subsubsection \<open>Limits of Sequences\<close>
  1831 
  1829 
  1832 lemma lim_sequentially: "X \<longlonglongrightarrow> L \<longleftrightarrow> (\<forall>r>0. \<exists>no. \<forall>n\<ge>no. dist (X n) L < r)"
  1830 lemma lim_sequentially: "X \<longlonglongrightarrow> L \<longleftrightarrow> (\<forall>r>0. \<exists>no. \<forall>n\<ge>no. dist (X n) L < r)"
  1897   assumes "g \<midarrow>a\<rightarrow> l" "0 < R"
  1895   assumes "g \<midarrow>a\<rightarrow> l" "0 < R"
  1898     and "\<And>x. x \<noteq> a \<Longrightarrow> dist x a < R \<Longrightarrow> f x = g x"
  1896     and "\<And>x. x \<noteq> a \<Longrightarrow> dist x a < R \<Longrightarrow> f x = g x"
  1899   shows "f \<midarrow>a\<rightarrow> l"
  1897   shows "f \<midarrow>a\<rightarrow> l"
  1900 proof -
  1898 proof -
  1901   have "\<And>S. \<lbrakk>open S; l \<in> S; \<forall>\<^sub>F x in at a. g x \<in> S\<rbrakk> \<Longrightarrow> \<forall>\<^sub>F x in at a. f x \<in> S"
  1899   have "\<And>S. \<lbrakk>open S; l \<in> S; \<forall>\<^sub>F x in at a. g x \<in> S\<rbrakk> \<Longrightarrow> \<forall>\<^sub>F x in at a. f x \<in> S"
  1902     apply (clarsimp simp add: eventually_at)
  1900     apply (simp add: eventually_at)
  1903     apply (rule_tac x="min d R" in exI)
  1901     by (metis assms(2) assms(3) dual_order.strict_trans linorder_neqE_linordered_idom)
  1904      apply (auto simp: assms)
       
  1905     done
       
  1906   then show ?thesis
  1902   then show ?thesis
  1907     using assms by (simp add: tendsto_def)
  1903     using assms by (simp add: tendsto_def)
  1908 qed
  1904 qed
  1909 
  1905 
  1910 lemma metric_LIM_compose2:
  1906 lemma metric_LIM_compose2:
  2169     have "dist (u n) l < e" if "n \<ge> max N1 N2" for n
  2165     have "dist (u n) l < e" if "n \<ge> max N1 N2" for n
  2170     proof -
  2166     proof -
  2171       have "dist (u n) l \<le> dist (u n) ((u \<circ> r) n) + dist ((u \<circ> r) n) l"
  2167       have "dist (u n) l \<le> dist (u n) ((u \<circ> r) n) + dist ((u \<circ> r) n) l"
  2172         by (rule dist_triangle)
  2168         by (rule dist_triangle)
  2173       also have "\<dots> < e/2 + e/2"
  2169       also have "\<dots> < e/2 + e/2"
  2174         apply (intro add_strict_mono)
  2170       proof (intro add_strict_mono)
  2175         using N1[of n "r n"] N2[of n] that unfolding comp_def
  2171         show "dist (u n) ((u \<circ> r) n) < e / 2"
  2176         by (auto simp: less_imp_le) (meson assms(2) less_imp_le order.trans seq_suble)
  2172           using N1[of n "r n"] N2[of n] that unfolding comp_def
       
  2173           by (meson assms(2) le_trans max.bounded_iff strict_mono_imp_increasing)
       
  2174         show "dist ((u \<circ> r) n) l < e / 2"
       
  2175           using N2 that by auto
       
  2176       qed
  2177       finally show ?thesis by simp
  2177       finally show ?thesis by simp
  2178     qed 
  2178     qed 
  2179     then show ?thesis unfolding eventually_sequentially by blast
  2179     then show ?thesis unfolding eventually_sequentially by blast
  2180   qed
  2180   qed
  2181   have "(\<lambda>n. dist (u n) l) \<longlonglongrightarrow> 0"
  2181   have "(\<lambda>n. dist (u n) l) \<longlonglongrightarrow> 0"
  2182     apply (rule order_tendstoI)
  2182     by (simp add: less_le_trans * order_tendstoI)
  2183     using * by auto (meson eventually_sequentiallyI less_le_trans zero_le_dist)
       
  2184   then show ?thesis using tendsto_dist_iff by auto
  2183   then show ?thesis using tendsto_dist_iff by auto
  2185 qed
  2184 qed
  2186 
  2185 
  2187 subsection \<open>The set of real numbers is a complete metric space\<close>
  2186 subsection \<open>The set of real numbers is a complete metric space\<close>
  2188 
  2187