src/HOL/Multivariate_Analysis/Path_Connected.thy
author hoelzl
Fri Mar 22 10:41:43 2013 +0100 (2013-03-22)
changeset 51478 270b21f3ae0a
parent 50935 cfdf19d3ca32
child 51481 ef949192e5d6
permissions -rw-r--r--
move continuous and continuous_on to the HOL image; isCont is an abbreviation for continuous (at x) (isCont is now restricted to a T2 space)
     1 (*  Title:      HOL/Multivariate_Analysis/Path_Connected.thy
     2     Author:     Robert Himmelmann, TU Muenchen
     3 *)
     4 
     5 header {* Continuous paths and path-connected sets *}
     6 
     7 theory Path_Connected
     8 imports Convex_Euclidean_Space
     9 begin
    10 
    11 lemma continuous_on_cong: (* MOVE to Topological_Spaces *)
    12   "s = t \<Longrightarrow> (\<And>x. x \<in> t \<Longrightarrow> f x = g x) \<Longrightarrow> continuous_on s f \<longleftrightarrow> continuous_on t g"
    13   unfolding continuous_on_def by (intro ball_cong Lim_cong_within) auto
    14 
    15 lemma continuous_on_compose2:
    16   shows "continuous_on t g \<Longrightarrow> continuous_on s f \<Longrightarrow> t = f ` s \<Longrightarrow> continuous_on s (\<lambda>x. g (f x))"
    17   using continuous_on_compose[of s f g] by (simp add: comp_def)
    18 
    19 subsection {* Paths. *}
    20 
    21 definition path :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> bool"
    22   where "path g \<longleftrightarrow> continuous_on {0 .. 1} g"
    23 
    24 definition pathstart :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> 'a"
    25   where "pathstart g = g 0"
    26 
    27 definition pathfinish :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> 'a"
    28   where "pathfinish g = g 1"
    29 
    30 definition path_image :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> 'a set"
    31   where "path_image g = g ` {0 .. 1}"
    32 
    33 definition reversepath :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> (real \<Rightarrow> 'a)"
    34   where "reversepath g = (\<lambda>x. g(1 - x))"
    35 
    36 definition joinpaths :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> (real \<Rightarrow> 'a) \<Rightarrow> (real \<Rightarrow> 'a)"
    37     (infixr "+++" 75)
    38   where "g1 +++ g2 = (\<lambda>x. if x \<le> 1/2 then g1 (2 * x) else g2 (2 * x - 1))"
    39 
    40 definition simple_path :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> bool"
    41   where "simple_path g \<longleftrightarrow>
    42     (\<forall>x\<in>{0..1}. \<forall>y\<in>{0..1}. g x = g y \<longrightarrow> x = y \<or> x = 0 \<and> y = 1 \<or> x = 1 \<and> y = 0)"
    43 
    44 definition injective_path :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> bool"
    45   where "injective_path g \<longleftrightarrow> (\<forall>x\<in>{0..1}. \<forall>y\<in>{0..1}. g x = g y \<longrightarrow> x = y)"
    46 
    47 
    48 subsection {* Some lemmas about these concepts. *}
    49 
    50 lemma injective_imp_simple_path: "injective_path g \<Longrightarrow> simple_path g"
    51   unfolding injective_path_def simple_path_def by auto
    52 
    53 lemma path_image_nonempty: "path_image g \<noteq> {}"
    54   unfolding path_image_def image_is_empty interval_eq_empty by auto 
    55 
    56 lemma pathstart_in_path_image[intro]: "(pathstart g) \<in> path_image g"
    57   unfolding pathstart_def path_image_def by auto
    58 
    59 lemma pathfinish_in_path_image[intro]: "(pathfinish g) \<in> path_image g"
    60   unfolding pathfinish_def path_image_def by auto
    61 
    62 lemma connected_path_image[intro]: "path g \<Longrightarrow> connected(path_image g)"
    63   unfolding path_def path_image_def
    64   apply (erule connected_continuous_image)
    65   apply (rule convex_connected, rule convex_real_interval)
    66   done
    67 
    68 lemma compact_path_image[intro]: "path g \<Longrightarrow> compact(path_image g)"
    69   unfolding path_def path_image_def
    70   by (erule compact_continuous_image, rule compact_interval)
    71 
    72 lemma reversepath_reversepath[simp]: "reversepath(reversepath g) = g"
    73   unfolding reversepath_def by auto
    74 
    75 lemma pathstart_reversepath[simp]: "pathstart(reversepath g) = pathfinish g"
    76   unfolding pathstart_def reversepath_def pathfinish_def by auto
    77 
    78 lemma pathfinish_reversepath[simp]: "pathfinish(reversepath g) = pathstart g"
    79   unfolding pathstart_def reversepath_def pathfinish_def by auto
    80 
    81 lemma pathstart_join[simp]: "pathstart (g1 +++ g2) = pathstart g1"
    82   unfolding pathstart_def joinpaths_def pathfinish_def by auto
    83 
    84 lemma pathfinish_join[simp]: "pathfinish (g1 +++ g2) = pathfinish g2"
    85   unfolding pathstart_def joinpaths_def pathfinish_def by auto
    86 
    87 lemma path_image_reversepath[simp]: "path_image(reversepath g) = path_image g"
    88 proof -
    89   have *: "\<And>g. path_image(reversepath g) \<subseteq> path_image g"
    90     unfolding path_image_def subset_eq reversepath_def Ball_def image_iff
    91     apply(rule,rule,erule bexE)
    92     apply(rule_tac x="1 - xa" in bexI)
    93     apply auto
    94     done
    95   show ?thesis
    96     using *[of g] *[of "reversepath g"]
    97     unfolding reversepath_reversepath by auto
    98 qed
    99 
   100 lemma path_reversepath[simp]: "path (reversepath g) \<longleftrightarrow> path g"
   101 proof -
   102   have *: "\<And>g. path g \<Longrightarrow> path (reversepath g)"
   103     unfolding path_def reversepath_def
   104     apply (rule continuous_on_compose[unfolded o_def, of _ "\<lambda>x. 1 - x"])
   105     apply (intro continuous_on_intros)
   106     apply (rule continuous_on_subset[of "{0..1}"], assumption)
   107     apply auto
   108     done
   109   show ?thesis
   110     using *[of "reversepath g"] *[of g]
   111     unfolding reversepath_reversepath
   112     by (rule iffI)
   113 qed
   114 
   115 lemmas reversepath_simps =
   116   path_reversepath path_image_reversepath pathstart_reversepath pathfinish_reversepath
   117 
   118 lemma path_join[simp]:
   119   assumes "pathfinish g1 = pathstart g2"
   120   shows "path (g1 +++ g2) \<longleftrightarrow> path g1 \<and> path g2"
   121   unfolding path_def pathfinish_def pathstart_def
   122 proof safe
   123   assume cont: "continuous_on {0..1} (g1 +++ g2)"
   124   have g1: "continuous_on {0..1} g1 \<longleftrightarrow> continuous_on {0..1} ((g1 +++ g2) \<circ> (\<lambda>x. x / 2))"
   125     by (intro continuous_on_cong refl) (auto simp: joinpaths_def)
   126   have g2: "continuous_on {0..1} g2 \<longleftrightarrow> continuous_on {0..1} ((g1 +++ g2) \<circ> (\<lambda>x. x / 2 + 1/2))"
   127     using assms by (intro continuous_on_cong refl) (auto simp: joinpaths_def pathfinish_def pathstart_def)
   128   show "continuous_on {0..1} g1" "continuous_on {0..1} g2"
   129     unfolding g1 g2 by (auto intro!: continuous_on_intros continuous_on_subset[OF cont])
   130 next
   131   assume g1g2: "continuous_on {0..1} g1" "continuous_on {0..1} g2"
   132   have 01: "{0 .. 1} = {0..1/2} \<union> {1/2 .. 1::real}"
   133     by auto
   134   { fix x :: real assume "0 \<le> x" "x \<le> 1" then have "x \<in> (\<lambda>x. x * 2) ` {0..1 / 2}"
   135       by (intro image_eqI[where x="x/2"]) auto }
   136   note 1 = this
   137   { fix x :: real assume "0 \<le> x" "x \<le> 1" then have "x \<in> (\<lambda>x. x * 2 - 1) ` {1 / 2..1}"
   138       by (intro image_eqI[where x="x/2 + 1/2"]) auto }
   139   note 2 = this
   140   show "continuous_on {0..1} (g1 +++ g2)"
   141     using assms unfolding joinpaths_def 01
   142     by (intro continuous_on_cases closed_atLeastAtMost g1g2[THEN continuous_on_compose2] continuous_on_intros)
   143        (auto simp: field_simps pathfinish_def pathstart_def intro!: 1 2)
   144 qed
   145 
   146 lemma path_image_join_subset: "path_image(g1 +++ g2) \<subseteq> (path_image g1 \<union> path_image g2)"
   147   unfolding path_image_def joinpaths_def by auto
   148 
   149 lemma subset_path_image_join:
   150   assumes "path_image g1 \<subseteq> s" "path_image g2 \<subseteq> s"
   151   shows "path_image(g1 +++ g2) \<subseteq> s"
   152   using path_image_join_subset[of g1 g2] and assms by auto
   153 
   154 lemma path_image_join:
   155   assumes "pathfinish g1 = pathstart g2"
   156   shows "path_image(g1 +++ g2) = (path_image g1) \<union> (path_image g2)"
   157   apply (rule, rule path_image_join_subset, rule)
   158   unfolding Un_iff
   159 proof (erule disjE)
   160   fix x
   161   assume "x \<in> path_image g1"
   162   then obtain y where y: "y\<in>{0..1}" "x = g1 y"
   163     unfolding path_image_def image_iff by auto
   164   then show "x \<in> path_image (g1 +++ g2)"
   165     unfolding joinpaths_def path_image_def image_iff
   166     apply (rule_tac x="(1/2) *\<^sub>R y" in bexI)
   167     apply auto
   168     done
   169 next
   170   fix x
   171   assume "x \<in> path_image g2"
   172   then obtain y where y: "y\<in>{0..1}" "x = g2 y"
   173     unfolding path_image_def image_iff by auto
   174   then show "x \<in> path_image (g1 +++ g2)"
   175     unfolding joinpaths_def path_image_def image_iff
   176     apply(rule_tac x="(1/2) *\<^sub>R (y + 1)" in bexI)
   177     using assms(1)[unfolded pathfinish_def pathstart_def]
   178     apply (auto simp add: add_divide_distrib) 
   179     done
   180 qed
   181 
   182 lemma not_in_path_image_join:
   183   assumes "x \<notin> path_image g1" "x \<notin> path_image g2"
   184   shows "x \<notin> path_image(g1 +++ g2)"
   185   using assms and path_image_join_subset[of g1 g2] by auto
   186 
   187 lemma simple_path_reversepath:
   188   assumes "simple_path g"
   189   shows "simple_path (reversepath g)"
   190   using assms
   191   unfolding simple_path_def reversepath_def
   192   apply -
   193   apply (rule ballI)+
   194   apply (erule_tac x="1-x" in ballE, erule_tac x="1-y" in ballE)
   195   apply auto
   196   done
   197 
   198 lemma simple_path_join_loop:
   199   assumes "injective_path g1" "injective_path g2" "pathfinish g2 = pathstart g1"
   200     "(path_image g1 \<inter> path_image g2) \<subseteq> {pathstart g1,pathstart g2}"
   201   shows "simple_path(g1 +++ g2)"
   202   unfolding simple_path_def
   203 proof ((rule ballI)+, rule impI)
   204   let ?g = "g1 +++ g2"
   205   note inj = assms(1,2)[unfolded injective_path_def, rule_format]
   206   fix x y :: real
   207   assume xy: "x \<in> {0..1}" "y \<in> {0..1}" "?g x = ?g y"
   208   show "x = y \<or> x = 0 \<and> y = 1 \<or> x = 1 \<and> y = 0"
   209   proof (case_tac "x \<le> 1/2", case_tac[!] "y \<le> 1/2", unfold not_le)
   210     assume as: "x \<le> 1 / 2" "y \<le> 1 / 2"
   211     then have "g1 (2 *\<^sub>R x) = g1 (2 *\<^sub>R y)"
   212       using xy(3) unfolding joinpaths_def by auto
   213     moreover
   214     have "2 *\<^sub>R x \<in> {0..1}" "2 *\<^sub>R y \<in> {0..1}" using xy(1,2) as
   215       by auto
   216     ultimately
   217     show ?thesis using inj(1)[of "2*\<^sub>R x" "2*\<^sub>R y"] by auto
   218   next
   219     assume as:"x > 1 / 2" "y > 1 / 2"
   220     then have "g2 (2 *\<^sub>R x - 1) = g2 (2 *\<^sub>R y - 1)"
   221       using xy(3) unfolding joinpaths_def by auto
   222     moreover
   223     have "2 *\<^sub>R x - 1 \<in> {0..1}" "2 *\<^sub>R y - 1 \<in> {0..1}"
   224       using xy(1,2) as by auto
   225     ultimately
   226     show ?thesis using inj(2)[of "2*\<^sub>R x - 1" "2*\<^sub>R y - 1"] by auto
   227   next
   228     assume as:"x \<le> 1 / 2" "y > 1 / 2"
   229     then have "?g x \<in> path_image g1" "?g y \<in> path_image g2"
   230       unfolding path_image_def joinpaths_def
   231       using xy(1,2) by auto
   232     moreover
   233       have "?g y \<noteq> pathstart g2" using as(2) unfolding pathstart_def joinpaths_def
   234       using inj(2)[of "2 *\<^sub>R y - 1" 0] and xy(2)
   235       by (auto simp add: field_simps)
   236     ultimately
   237     have *:"?g x = pathstart g1" using assms(4) unfolding xy(3) by auto
   238     then have "x = 0" unfolding pathstart_def joinpaths_def using as(1) and xy(1)
   239       using inj(1)[of "2 *\<^sub>R x" 0] by auto
   240     moreover
   241     have "y = 1" using * unfolding xy(3) assms(3)[THEN sym]
   242       unfolding joinpaths_def pathfinish_def using as(2) and xy(2)
   243       using inj(2)[of "2 *\<^sub>R y - 1" 1] by auto
   244     ultimately show ?thesis by auto
   245   next
   246     assume as: "x > 1 / 2" "y \<le> 1 / 2"
   247     then have "?g x \<in> path_image g2" "?g y \<in> path_image g1"
   248       unfolding path_image_def joinpaths_def
   249       using xy(1,2) by auto
   250     moreover
   251       have "?g x \<noteq> pathstart g2" using as(1) unfolding pathstart_def joinpaths_def
   252       using inj(2)[of "2 *\<^sub>R x - 1" 0] and xy(1)
   253       by (auto simp add: field_simps)
   254     ultimately
   255     have *: "?g y = pathstart g1" using assms(4) unfolding xy(3) by auto
   256     then have "y = 0" unfolding pathstart_def joinpaths_def using as(2) and xy(2)
   257       using inj(1)[of "2 *\<^sub>R y" 0] by auto
   258     moreover
   259     have "x = 1" using * unfolding xy(3)[THEN sym] assms(3)[THEN sym]
   260       unfolding joinpaths_def pathfinish_def using as(1) and xy(1)
   261       using inj(2)[of "2 *\<^sub>R x - 1" 1] by auto
   262     ultimately show ?thesis by auto
   263   qed
   264 qed
   265 
   266 lemma injective_path_join:
   267   assumes "injective_path g1" "injective_path g2" "pathfinish g1 = pathstart g2"
   268     "(path_image g1 \<inter> path_image g2) \<subseteq> {pathstart g2}"
   269   shows "injective_path(g1 +++ g2)"
   270   unfolding injective_path_def
   271 proof (rule, rule, rule)
   272   let ?g = "g1 +++ g2"
   273   note inj = assms(1,2)[unfolded injective_path_def, rule_format]
   274   fix x y
   275   assume xy: "x \<in> {0..1}" "y \<in> {0..1}" "(g1 +++ g2) x = (g1 +++ g2) y"
   276   show "x = y"
   277   proof (cases "x \<le> 1/2", case_tac[!] "y \<le> 1/2", unfold not_le)
   278     assume "x \<le> 1 / 2" "y \<le> 1 / 2"
   279     then show ?thesis using inj(1)[of "2*\<^sub>R x" "2*\<^sub>R y"] and xy
   280       unfolding joinpaths_def by auto
   281   next
   282     assume "x > 1 / 2" "y > 1 / 2"
   283     then show ?thesis using inj(2)[of "2*\<^sub>R x - 1" "2*\<^sub>R y - 1"] and xy
   284       unfolding joinpaths_def by auto
   285   next
   286     assume as: "x \<le> 1 / 2" "y > 1 / 2"
   287     then have "?g x \<in> path_image g1" "?g y \<in> path_image g2"
   288       unfolding path_image_def joinpaths_def
   289       using xy(1,2) by auto
   290     then have "?g x = pathfinish g1" "?g y = pathstart g2"
   291       using assms(4) unfolding assms(3) xy(3) by auto
   292     then show ?thesis
   293       using as and inj(1)[of "2 *\<^sub>R x" 1] inj(2)[of "2 *\<^sub>R y - 1" 0] and xy(1,2)
   294       unfolding pathstart_def pathfinish_def joinpaths_def
   295       by auto
   296   next
   297     assume as:"x > 1 / 2" "y \<le> 1 / 2" 
   298     then have "?g x \<in> path_image g2" "?g y \<in> path_image g1"
   299       unfolding path_image_def joinpaths_def
   300       using xy(1,2) by auto
   301     then have "?g x = pathstart g2" "?g y = pathfinish g1"
   302       using assms(4) unfolding assms(3) xy(3) by auto
   303     then show ?thesis using as and inj(2)[of "2 *\<^sub>R x - 1" 0] inj(1)[of "2 *\<^sub>R y" 1] and xy(1,2)
   304       unfolding pathstart_def pathfinish_def joinpaths_def
   305       by auto
   306   qed
   307 qed
   308 
   309 lemmas join_paths_simps = path_join path_image_join pathstart_join pathfinish_join
   310  
   311 
   312 subsection {* Reparametrizing a closed curve to start at some chosen point. *}
   313 
   314 definition "shiftpath a (f::real \<Rightarrow> 'a::topological_space) =
   315   (\<lambda>x. if (a + x) \<le> 1 then f(a + x) else f(a + x - 1))"
   316 
   317 lemma pathstart_shiftpath: "a \<le> 1 \<Longrightarrow> pathstart(shiftpath a g) = g a"
   318   unfolding pathstart_def shiftpath_def by auto
   319 
   320 lemma pathfinish_shiftpath:
   321   assumes "0 \<le> a" "pathfinish g = pathstart g"
   322   shows "pathfinish(shiftpath a g) = g a"
   323   using assms unfolding pathstart_def pathfinish_def shiftpath_def
   324   by auto
   325 
   326 lemma endpoints_shiftpath:
   327   assumes "pathfinish g = pathstart g" "a \<in> {0 .. 1}" 
   328   shows "pathfinish(shiftpath a g) = g a" "pathstart(shiftpath a g) = g a"
   329   using assms by(auto intro!:pathfinish_shiftpath pathstart_shiftpath)
   330 
   331 lemma closed_shiftpath:
   332   assumes "pathfinish g = pathstart g" "a \<in> {0..1}"
   333   shows "pathfinish(shiftpath a g) = pathstart(shiftpath a g)"
   334   using endpoints_shiftpath[OF assms] by auto
   335 
   336 lemma path_shiftpath:
   337   assumes "path g" "pathfinish g = pathstart g" "a \<in> {0..1}"
   338   shows "path(shiftpath a g)"
   339 proof -
   340   have *: "{0 .. 1} = {0 .. 1-a} \<union> {1-a .. 1}" using assms(3) by auto
   341   have **: "\<And>x. x + a = 1 \<Longrightarrow> g (x + a - 1) = g (x + a)"
   342     using assms(2)[unfolded pathfinish_def pathstart_def] by auto
   343   show ?thesis
   344     unfolding path_def shiftpath_def *
   345     apply (rule continuous_on_union)
   346     apply (rule closed_real_atLeastAtMost)+
   347     apply (rule continuous_on_eq[of _ "g \<circ> (\<lambda>x. a + x)"]) prefer 3
   348     apply (rule continuous_on_eq[of _ "g \<circ> (\<lambda>x. a - 1 + x)"]) defer prefer 3
   349     apply (rule continuous_on_intros)+ prefer 2
   350     apply (rule continuous_on_intros)+
   351     apply (rule_tac[1-2] continuous_on_subset[OF assms(1)[unfolded path_def]])
   352     using assms(3) and **
   353     apply (auto, auto simp add: field_simps)
   354     done
   355 qed
   356 
   357 lemma shiftpath_shiftpath:
   358   assumes "pathfinish g = pathstart g" "a \<in> {0..1}" "x \<in> {0..1}" 
   359   shows "shiftpath (1 - a) (shiftpath a g) x = g x"
   360   using assms unfolding pathfinish_def pathstart_def shiftpath_def by auto
   361 
   362 lemma path_image_shiftpath:
   363   assumes "a \<in> {0..1}" "pathfinish g = pathstart g"
   364   shows "path_image(shiftpath a g) = path_image g"
   365 proof -
   366   { fix x
   367     assume as:"g 1 = g 0" "x \<in> {0..1::real}" " \<forall>y\<in>{0..1} \<inter> {x. \<not> a + x \<le> 1}. g x \<noteq> g (a + y - 1)" 
   368     then have "\<exists>y\<in>{0..1} \<inter> {x. a + x \<le> 1}. g x = g (a + y)"
   369     proof (cases "a \<le> x")
   370       case False
   371       then show ?thesis
   372         apply (rule_tac x="1 + x - a" in bexI)
   373         using as(1,2) and as(3)[THEN bspec[where x="1 + x - a"]] and assms(1)
   374         apply (auto simp add: field_simps atomize_not)
   375         done
   376     next
   377       case True
   378       then show ?thesis using as(1-2) and assms(1) apply(rule_tac x="x - a" in bexI)
   379         by(auto simp add: field_simps)
   380     qed
   381   }
   382   then show ?thesis
   383     using assms unfolding shiftpath_def path_image_def pathfinish_def pathstart_def
   384     by(auto simp add: image_iff)
   385 qed
   386 
   387 
   388 subsection {* Special case of straight-line paths. *}
   389 
   390 definition linepath :: "'a::real_normed_vector \<Rightarrow> 'a \<Rightarrow> real \<Rightarrow> 'a"
   391   where "linepath a b = (\<lambda>x. (1 - x) *\<^sub>R a + x *\<^sub>R b)"
   392 
   393 lemma pathstart_linepath[simp]: "pathstart(linepath a b) = a"
   394   unfolding pathstart_def linepath_def by auto
   395 
   396 lemma pathfinish_linepath[simp]: "pathfinish(linepath a b) = b"
   397   unfolding pathfinish_def linepath_def by auto
   398 
   399 lemma continuous_linepath_at[intro]: "continuous (at x) (linepath a b)"
   400   unfolding linepath_def by (intro continuous_intros)
   401 
   402 lemma continuous_on_linepath[intro]: "continuous_on s (linepath a b)"
   403   using continuous_linepath_at by(auto intro!: continuous_at_imp_continuous_on)
   404 
   405 lemma path_linepath[intro]: "path(linepath a b)"
   406   unfolding path_def by(rule continuous_on_linepath)
   407 
   408 lemma path_image_linepath[simp]: "path_image(linepath a b) = (closed_segment a b)"
   409   unfolding path_image_def segment linepath_def
   410   apply (rule set_eqI, rule) defer
   411   unfolding mem_Collect_eq image_iff
   412   apply(erule exE)
   413   apply(rule_tac x="u *\<^sub>R 1" in bexI)
   414   apply auto
   415   done
   416 
   417 lemma reversepath_linepath[simp]: "reversepath(linepath a b) = linepath b a"
   418   unfolding reversepath_def linepath_def
   419   by auto
   420 
   421 lemma injective_path_linepath:
   422   assumes "a \<noteq> b"
   423   shows "injective_path (linepath a b)"
   424 proof -
   425   { fix x y :: "real"
   426     assume "x *\<^sub>R b + y *\<^sub>R a = x *\<^sub>R a + y *\<^sub>R b"
   427     then have "(x - y) *\<^sub>R a = (x - y) *\<^sub>R b" by (simp add: algebra_simps)
   428     with assms have "x = y" by simp }
   429   then show ?thesis
   430     unfolding injective_path_def linepath_def
   431     by (auto simp add: algebra_simps)
   432 qed
   433 
   434 lemma simple_path_linepath[intro]: "a \<noteq> b \<Longrightarrow> simple_path(linepath a b)"
   435   by(auto intro!: injective_imp_simple_path injective_path_linepath)
   436 
   437 
   438 subsection {* Bounding a point away from a path. *}
   439 
   440 lemma not_on_path_ball:
   441   fixes g :: "real \<Rightarrow> 'a::heine_borel"
   442   assumes "path g" "z \<notin> path_image g"
   443   shows "\<exists>e > 0. ball z e \<inter> (path_image g) = {}"
   444 proof -
   445   obtain a where "a \<in> path_image g" "\<forall>y \<in> path_image g. dist z a \<le> dist z y"
   446     using distance_attains_inf[OF _ path_image_nonempty, of g z]
   447     using compact_path_image[THEN compact_imp_closed, OF assms(1)] by auto
   448   then show ?thesis
   449     apply (rule_tac x="dist z a" in exI)
   450     using assms(2)
   451     apply (auto intro!: dist_pos_lt)
   452     done
   453 qed
   454 
   455 lemma not_on_path_cball:
   456   fixes g :: "real \<Rightarrow> 'a::heine_borel"
   457   assumes "path g" "z \<notin> path_image g"
   458   shows "\<exists>e>0. cball z e \<inter> (path_image g) = {}"
   459 proof -
   460   obtain e where "ball z e \<inter> path_image g = {}" "e>0"
   461     using not_on_path_ball[OF assms] by auto
   462   moreover have "cball z (e/2) \<subseteq> ball z e" using `e>0` by auto
   463   ultimately show ?thesis apply(rule_tac x="e/2" in exI) by auto
   464 qed
   465 
   466 
   467 subsection {* Path component, considered as a "joinability" relation (from Tom Hales). *}
   468 
   469 definition "path_component s x y \<longleftrightarrow>
   470   (\<exists>g. path g \<and> path_image g \<subseteq> s \<and> pathstart g = x \<and> pathfinish g = y)"
   471 
   472 lemmas path_defs = path_def pathstart_def pathfinish_def path_image_def path_component_def 
   473 
   474 lemma path_component_mem:
   475   assumes "path_component s x y"
   476   shows "x \<in> s" "y \<in> s"
   477   using assms unfolding path_defs by auto
   478 
   479 lemma path_component_refl:
   480   assumes "x \<in> s"
   481   shows "path_component s x x"
   482   unfolding path_defs
   483   apply (rule_tac x="\<lambda>u. x" in exI)
   484   using assms apply (auto intro!:continuous_on_intros) done
   485 
   486 lemma path_component_refl_eq: "path_component s x x \<longleftrightarrow> x \<in> s"
   487   by (auto intro!: path_component_mem path_component_refl)
   488 
   489 lemma path_component_sym: "path_component s x y \<Longrightarrow> path_component s y x"
   490   using assms
   491   unfolding path_component_def
   492   apply (erule exE)
   493   apply (rule_tac x="reversepath g" in exI)
   494   apply auto
   495   done
   496 
   497 lemma path_component_trans:
   498   assumes "path_component s x y" "path_component s y z"
   499   shows "path_component s x z"
   500   using assms
   501   unfolding path_component_def
   502   apply -
   503   apply (erule exE)+
   504   apply (rule_tac x="g +++ ga" in exI)
   505   apply (auto simp add: path_image_join)
   506   done
   507 
   508 lemma path_component_of_subset: "s \<subseteq> t \<Longrightarrow>  path_component s x y \<Longrightarrow> path_component t x y"
   509   unfolding path_component_def by auto
   510 
   511 
   512 subsection {* Can also consider it as a set, as the name suggests. *}
   513 
   514 lemma path_component_set:
   515   "{y. path_component s x y} =
   516     {y. (\<exists>g. path g \<and> path_image g \<subseteq> s \<and> pathstart g = x \<and> pathfinish g = y)}"
   517   apply (rule set_eqI)
   518   unfolding mem_Collect_eq
   519   unfolding path_component_def
   520   apply auto
   521   done
   522 
   523 lemma path_component_subset: "{y. path_component s x y} \<subseteq> s"
   524   apply (rule, rule path_component_mem(2))
   525   apply auto
   526   done
   527 
   528 lemma path_component_eq_empty: "{y. path_component s x y} = {} \<longleftrightarrow> x \<notin> s"
   529   apply rule
   530   apply (drule equals0D[of _ x]) defer
   531   apply (rule equals0I)
   532   unfolding mem_Collect_eq
   533   apply (drule path_component_mem(1))
   534   using path_component_refl
   535   apply auto
   536   done
   537 
   538 
   539 subsection {* Path connectedness of a space. *}
   540 
   541 definition "path_connected s \<longleftrightarrow>
   542   (\<forall>x\<in>s. \<forall>y\<in>s. \<exists>g. path g \<and> (path_image g) \<subseteq> s \<and> pathstart g = x \<and> pathfinish g = y)"
   543 
   544 lemma path_connected_component: "path_connected s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>y\<in>s. path_component s x y)"
   545   unfolding path_connected_def path_component_def by auto
   546 
   547 lemma path_connected_component_set: "path_connected s \<longleftrightarrow> (\<forall>x\<in>s. {y. path_component s x y} = s)" 
   548   unfolding path_connected_component
   549   apply (rule, rule, rule, rule path_component_subset) 
   550   unfolding subset_eq mem_Collect_eq Ball_def
   551   apply auto
   552   done
   553 
   554 
   555 subsection {* Some useful lemmas about path-connectedness. *}
   556 
   557 lemma convex_imp_path_connected:
   558   fixes s :: "'a::real_normed_vector set"
   559   assumes "convex s" shows "path_connected s"
   560   unfolding path_connected_def
   561   apply (rule, rule, rule_tac x = "linepath x y" in exI)
   562   unfolding path_image_linepath
   563   using assms [unfolded convex_contains_segment]
   564   apply auto
   565   done
   566 
   567 lemma path_connected_imp_connected:
   568   assumes "path_connected s"
   569   shows "connected s"
   570   unfolding connected_def not_ex
   571   apply (rule, rule, rule ccontr)
   572   unfolding not_not
   573   apply (erule conjE)+
   574 proof -
   575   fix e1 e2
   576   assume as: "open e1" "open e2" "s \<subseteq> e1 \<union> e2" "e1 \<inter> e2 \<inter> s = {}" "e1 \<inter> s \<noteq> {}" "e2 \<inter> s \<noteq> {}"
   577   then obtain x1 x2 where obt:"x1\<in>e1\<inter>s" "x2\<in>e2\<inter>s" by auto
   578   then obtain g where g:"path g" "path_image g \<subseteq> s" "pathstart g = x1" "pathfinish g = x2"
   579     using assms[unfolded path_connected_def,rule_format,of x1 x2] by auto
   580   have *: "connected {0..1::real}"
   581     by (auto intro!: convex_connected convex_real_interval)
   582   have "{0..1} \<subseteq> {x \<in> {0..1}. g x \<in> e1} \<union> {x \<in> {0..1}. g x \<in> e2}"
   583     using as(3) g(2)[unfolded path_defs] by blast
   584   moreover have "{x \<in> {0..1}. g x \<in> e1} \<inter> {x \<in> {0..1}. g x \<in> e2} = {}"
   585     using as(4) g(2)[unfolded path_defs] unfolding subset_eq by auto 
   586   moreover have "{x \<in> {0..1}. g x \<in> e1} \<noteq> {} \<and> {x \<in> {0..1}. g x \<in> e2} \<noteq> {}"
   587     using g(3,4)[unfolded path_defs] using obt
   588     by (simp add: ex_in_conv [symmetric], metis zero_le_one order_refl)
   589   ultimately show False
   590     using *[unfolded connected_local not_ex, rule_format, of "{x\<in>{0..1}. g x \<in> e1}" "{x\<in>{0..1}. g x \<in> e2}"]
   591     using continuous_open_in_preimage[OF g(1)[unfolded path_def] as(1)]
   592     using continuous_open_in_preimage[OF g(1)[unfolded path_def] as(2)]
   593     by auto
   594 qed
   595 
   596 lemma open_path_component:
   597   fixes s :: "'a::real_normed_vector set" (*TODO: generalize to metric_space*)
   598   assumes "open s"
   599   shows "open {y. path_component s x y}"
   600   unfolding open_contains_ball
   601 proof
   602   fix y
   603   assume as: "y \<in> {y. path_component s x y}"
   604   then have "y \<in> s"
   605     apply -
   606     apply (rule path_component_mem(2))
   607     unfolding mem_Collect_eq
   608     apply auto
   609     done
   610   then obtain e where e:"e>0" "ball y e \<subseteq> s"
   611     using assms[unfolded open_contains_ball] by auto
   612   show "\<exists>e > 0. ball y e \<subseteq> {y. path_component s x y}"
   613     apply (rule_tac x=e in exI)
   614     apply (rule,rule `e>0`, rule)
   615     unfolding mem_ball mem_Collect_eq
   616   proof -
   617     fix z
   618     assume "dist y z < e"
   619     then show "path_component s x z"
   620       apply (rule_tac path_component_trans[of _ _ y]) defer
   621       apply (rule path_component_of_subset[OF e(2)])
   622       apply (rule convex_imp_path_connected[OF convex_ball, unfolded path_connected_component, rule_format])
   623       using `e>0` as
   624       apply auto
   625       done
   626   qed
   627 qed
   628 
   629 lemma open_non_path_component:
   630   fixes s :: "'a::real_normed_vector set" (*TODO: generalize to metric_space*)
   631   assumes "open s"
   632   shows "open(s - {y. path_component s x y})"
   633   unfolding open_contains_ball
   634 proof
   635   fix y
   636   assume as: "y\<in>s - {y. path_component s x y}"
   637   then obtain e where e:"e>0" "ball y e \<subseteq> s"
   638     using assms [unfolded open_contains_ball] by auto
   639   show "\<exists>e>0. ball y e \<subseteq> s - {y. path_component s x y}"
   640     apply (rule_tac x=e in exI)
   641     apply (rule, rule `e>0`, rule, rule) defer
   642   proof (rule ccontr)
   643     fix z
   644     assume "z \<in> ball y e" "\<not> z \<notin> {y. path_component s x y}"
   645     then have "y \<in> {y. path_component s x y}"
   646       unfolding not_not mem_Collect_eq using `e>0`
   647       apply -
   648       apply (rule path_component_trans, assumption)
   649       apply (rule path_component_of_subset[OF e(2)])
   650       apply (rule convex_imp_path_connected[OF convex_ball, unfolded path_connected_component, rule_format])
   651       apply auto
   652       done
   653     then show False using as by auto
   654   qed (insert e(2), auto)
   655 qed
   656 
   657 lemma connected_open_path_connected:
   658   fixes s :: "'a::real_normed_vector set" (*TODO: generalize to metric_space*)
   659   assumes "open s" "connected s"
   660   shows "path_connected s"
   661   unfolding path_connected_component_set
   662 proof (rule, rule, rule path_component_subset, rule)
   663   fix x y
   664   assume "x \<in> s" "y \<in> s"
   665   show "y \<in> {y. path_component s x y}"
   666   proof (rule ccontr)
   667     assume "y \<notin> {y. path_component s x y}"
   668     moreover
   669     have "{y. path_component s x y} \<inter> s \<noteq> {}"
   670       using `x\<in>s` path_component_eq_empty path_component_subset[of s x] by auto
   671     ultimately
   672     show False
   673       using `y\<in>s` open_non_path_component[OF assms(1)] open_path_component[OF assms(1)]
   674       using assms(2)[unfolded connected_def not_ex, rule_format, of"{y. path_component s x y}" "s - {y. path_component s x y}"]
   675       by auto
   676   qed
   677 qed
   678 
   679 lemma path_connected_continuous_image:
   680   assumes "continuous_on s f" "path_connected s"
   681   shows "path_connected (f ` s)"
   682   unfolding path_connected_def
   683 proof (rule, rule)
   684   fix x' y'
   685   assume "x' \<in> f ` s" "y' \<in> f ` s"
   686   then obtain x y where xy: "x\<in>s" "y\<in>s" "x' = f x" "y' = f y" by auto
   687   guess g using assms(2)[unfolded path_connected_def, rule_format, OF xy(1,2)] ..
   688   then show "\<exists>g. path g \<and> path_image g \<subseteq> f ` s \<and> pathstart g = x' \<and> pathfinish g = y'"
   689     unfolding xy
   690     apply (rule_tac x="f \<circ> g" in exI)
   691     unfolding path_defs
   692     using assms(1)
   693     apply (auto intro!: continuous_on_compose continuous_on_subset[of _ _ "g ` {0..1}"])
   694     done
   695 qed
   696 
   697 lemma homeomorphic_path_connectedness:
   698   "s homeomorphic t \<Longrightarrow> (path_connected s \<longleftrightarrow> path_connected t)"
   699   unfolding homeomorphic_def homeomorphism_def
   700   apply (erule exE|erule conjE)+  
   701   apply rule
   702   apply (drule_tac f=f in path_connected_continuous_image) prefer 3
   703   apply (drule_tac f=g in path_connected_continuous_image)
   704   apply auto
   705   done
   706 
   707 lemma path_connected_empty: "path_connected {}"
   708   unfolding path_connected_def by auto
   709 
   710 lemma path_connected_singleton: "path_connected {a}"
   711   unfolding path_connected_def pathstart_def pathfinish_def path_image_def
   712   apply (clarify, rule_tac x="\<lambda>x. a" in exI, simp add: image_constant_conv)
   713   apply (simp add: path_def continuous_on_const)
   714   done
   715 
   716 lemma path_connected_Un:
   717   assumes "path_connected s" "path_connected t" "s \<inter> t \<noteq> {}"
   718   shows "path_connected (s \<union> t)"
   719   unfolding path_connected_component
   720 proof (rule, rule)
   721   fix x y
   722   assume as: "x \<in> s \<union> t" "y \<in> s \<union> t"
   723   from assms(3) obtain z where "z \<in> s \<inter> t" by auto
   724   then show "path_component (s \<union> t) x y"
   725     using as and assms(1-2)[unfolded path_connected_component]
   726     apply - 
   727     apply (erule_tac[!] UnE)+
   728     apply (rule_tac[2-3] path_component_trans[of _ _ z])
   729     apply (auto simp add:path_component_of_subset [OF Un_upper1] path_component_of_subset[OF Un_upper2])
   730     done
   731 qed
   732 
   733 lemma path_connected_UNION:
   734   assumes "\<And>i. i \<in> A \<Longrightarrow> path_connected (S i)"
   735     and "\<And>i. i \<in> A \<Longrightarrow> z \<in> S i"
   736   shows "path_connected (\<Union>i\<in>A. S i)"
   737   unfolding path_connected_component
   738 proof clarify
   739   fix x i y j
   740   assume *: "i \<in> A" "x \<in> S i" "j \<in> A" "y \<in> S j"
   741   then have "path_component (S i) x z" and "path_component (S j) z y"
   742     using assms by (simp_all add: path_connected_component)
   743   then have "path_component (\<Union>i\<in>A. S i) x z" and "path_component (\<Union>i\<in>A. S i) z y"
   744     using *(1,3) by (auto elim!: path_component_of_subset [rotated])
   745   then show "path_component (\<Union>i\<in>A. S i) x y"
   746     by (rule path_component_trans)
   747 qed
   748 
   749 
   750 subsection {* sphere is path-connected. *}
   751 
   752 lemma path_connected_punctured_universe:
   753   assumes "2 \<le> DIM('a::euclidean_space)"
   754   shows "path_connected((UNIV::'a::euclidean_space set) - {a})"
   755 proof -
   756   let ?A = "{x::'a. \<exists>i\<in>Basis. x \<bullet> i < a \<bullet> i}"
   757   let ?B = "{x::'a. \<exists>i\<in>Basis. a \<bullet> i < x \<bullet> i}"
   758 
   759   have A: "path_connected ?A"
   760     unfolding Collect_bex_eq
   761   proof (rule path_connected_UNION)
   762     fix i :: 'a
   763     assume "i \<in> Basis"
   764     then show "(\<Sum>i\<in>Basis. (a \<bullet> i - 1)*\<^sub>R i) \<in> {x::'a. x \<bullet> i < a \<bullet> i}" by simp
   765     show "path_connected {x. x \<bullet> i < a \<bullet> i}"
   766       using convex_imp_path_connected [OF convex_halfspace_lt, of i "a \<bullet> i"]
   767       by (simp add: inner_commute)
   768   qed
   769   have B: "path_connected ?B" unfolding Collect_bex_eq
   770   proof (rule path_connected_UNION)
   771     fix i :: 'a
   772     assume "i \<in> Basis"
   773     then show "(\<Sum>i\<in>Basis. (a \<bullet> i + 1) *\<^sub>R i) \<in> {x::'a. a \<bullet> i < x \<bullet> i}" by simp
   774     show "path_connected {x. a \<bullet> i < x \<bullet> i}"
   775       using convex_imp_path_connected [OF convex_halfspace_gt, of "a \<bullet> i" i]
   776       by (simp add: inner_commute)
   777   qed
   778   obtain S :: "'a set" where "S \<subseteq> Basis" "card S = Suc (Suc 0)"
   779     using ex_card[OF assms] by auto
   780   then obtain b0 b1 :: 'a where "b0 \<in> Basis" "b1 \<in> Basis" "b0 \<noteq> b1"
   781     unfolding card_Suc_eq by auto
   782   then have "a + b0 - b1 \<in> ?A \<inter> ?B" by (auto simp: inner_simps inner_Basis)
   783   then have "?A \<inter> ?B \<noteq> {}" by fast
   784   with A B have "path_connected (?A \<union> ?B)"
   785     by (rule path_connected_Un)
   786   also have "?A \<union> ?B = {x. \<exists>i\<in>Basis. x \<bullet> i \<noteq> a \<bullet> i}"
   787     unfolding neq_iff bex_disj_distrib Collect_disj_eq ..
   788   also have "\<dots> = {x. x \<noteq> a}"
   789     unfolding euclidean_eq_iff [where 'a='a] by (simp add: Bex_def)
   790   also have "\<dots> = UNIV - {a}" by auto
   791   finally show ?thesis .
   792 qed
   793 
   794 lemma path_connected_sphere:
   795   assumes "2 \<le> DIM('a::euclidean_space)"
   796   shows "path_connected {x::'a::euclidean_space. norm(x - a) = r}"
   797 proof (rule linorder_cases [of r 0])
   798   assume "r < 0"
   799   then have "{x::'a. norm(x - a) = r} = {}" by auto
   800   then show ?thesis using path_connected_empty by simp
   801 next
   802   assume "r = 0"
   803   then show ?thesis using path_connected_singleton by simp
   804 next
   805   assume r: "0 < r"
   806   then have *: "{x::'a. norm(x - a) = r} = (\<lambda>x. a + r *\<^sub>R x) ` {x. norm x = 1}"
   807     apply -
   808     apply (rule set_eqI, rule)
   809     unfolding image_iff
   810     apply (rule_tac x="(1/r) *\<^sub>R (x - a)" in bexI)
   811     unfolding mem_Collect_eq norm_scaleR
   812     apply (auto simp add: scaleR_right_diff_distrib)
   813     done
   814   have **: "{x::'a. norm x = 1} = (\<lambda>x. (1/norm x) *\<^sub>R x) ` (UNIV - {0})"
   815     apply (rule set_eqI,rule)
   816     unfolding image_iff
   817     apply (rule_tac x=x in bexI)
   818     unfolding mem_Collect_eq
   819     apply (auto split:split_if_asm)
   820     done
   821   have "continuous_on (UNIV - {0}) (\<lambda>x::'a. 1 / norm x)"
   822     unfolding field_divide_inverse by (simp add: continuous_on_intros)
   823   then show ?thesis unfolding * ** using path_connected_punctured_universe[OF assms]
   824     by (auto intro!: path_connected_continuous_image continuous_on_intros)
   825 qed
   826 
   827 lemma connected_sphere: "2 \<le> DIM('a::euclidean_space) \<Longrightarrow> connected {x::'a. norm(x - a) = r}"
   828   using path_connected_sphere path_connected_imp_connected by auto
   829 
   830 end