src/HOL/Multivariate_Analysis/Path_Connected.thy
author huffman
Fri Aug 12 09:17:24 2011 -0700 (2011-08-12)
changeset 44170 510ac30f44c0
parent 41959 b460124855b8
child 44531 1d477a2b1572
permissions -rw-r--r--
make Multivariate_Analysis work with separate set type
wenzelm@41959
     1
(*  Title:      HOL/Multivariate_Analysis/Path_Connected.thy
huffman@36583
     2
    Author:     Robert Himmelmann, TU Muenchen
huffman@36583
     3
*)
huffman@36583
     4
huffman@36583
     5
header {* Continuous paths and path-connected sets *}
huffman@36583
     6
huffman@36583
     7
theory Path_Connected
huffman@37674
     8
imports Convex_Euclidean_Space
huffman@36583
     9
begin
huffman@36583
    10
huffman@36583
    11
subsection {* Paths. *}
huffman@36583
    12
huffman@36583
    13
definition
huffman@36583
    14
  path :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> bool"
huffman@36583
    15
  where "path g \<longleftrightarrow> continuous_on {0 .. 1} g"
huffman@36583
    16
huffman@36583
    17
definition
huffman@36583
    18
  pathstart :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> 'a"
huffman@36583
    19
  where "pathstart g = g 0"
huffman@36583
    20
huffman@36583
    21
definition
huffman@36583
    22
  pathfinish :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> 'a"
huffman@36583
    23
  where "pathfinish g = g 1"
huffman@36583
    24
huffman@36583
    25
definition
huffman@36583
    26
  path_image :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> 'a set"
huffman@36583
    27
  where "path_image g = g ` {0 .. 1}"
huffman@36583
    28
huffman@36583
    29
definition
huffman@36583
    30
  reversepath :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> (real \<Rightarrow> 'a)"
huffman@36583
    31
  where "reversepath g = (\<lambda>x. g(1 - x))"
huffman@36583
    32
huffman@36583
    33
definition
huffman@36583
    34
  joinpaths :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> (real \<Rightarrow> 'a) \<Rightarrow> (real \<Rightarrow> 'a)"
huffman@36583
    35
    (infixr "+++" 75)
huffman@36583
    36
  where "g1 +++ g2 = (\<lambda>x. if x \<le> 1/2 then g1 (2 * x) else g2 (2 * x - 1))"
huffman@36583
    37
huffman@36583
    38
definition
huffman@36583
    39
  simple_path :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> bool"
huffman@36583
    40
  where "simple_path g \<longleftrightarrow>
huffman@36583
    41
  (\<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)"
huffman@36583
    42
huffman@36583
    43
definition
huffman@36583
    44
  injective_path :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> bool"
huffman@36583
    45
  where "injective_path g \<longleftrightarrow> (\<forall>x\<in>{0..1}. \<forall>y\<in>{0..1}. g x = g y \<longrightarrow> x = y)"
huffman@36583
    46
huffman@36583
    47
subsection {* Some lemmas about these concepts. *}
huffman@36583
    48
huffman@36583
    49
lemma injective_imp_simple_path:
huffman@36583
    50
  "injective_path g \<Longrightarrow> simple_path g"
huffman@36583
    51
  unfolding injective_path_def simple_path_def by auto
huffman@36583
    52
huffman@36583
    53
lemma path_image_nonempty: "path_image g \<noteq> {}"
huffman@36583
    54
  unfolding path_image_def image_is_empty interval_eq_empty by auto 
huffman@36583
    55
huffman@36583
    56
lemma pathstart_in_path_image[intro]: "(pathstart g) \<in> path_image g"
huffman@36583
    57
  unfolding pathstart_def path_image_def by auto
huffman@36583
    58
huffman@36583
    59
lemma pathfinish_in_path_image[intro]: "(pathfinish g) \<in> path_image g"
huffman@36583
    60
  unfolding pathfinish_def path_image_def by auto
huffman@36583
    61
huffman@36583
    62
lemma connected_path_image[intro]: "path g \<Longrightarrow> connected(path_image g)"
huffman@36583
    63
  unfolding path_def path_image_def
huffman@36583
    64
  apply (erule connected_continuous_image)
huffman@36583
    65
  by(rule convex_connected, rule convex_real_interval)
huffman@36583
    66
huffman@36583
    67
lemma compact_path_image[intro]: "path g \<Longrightarrow> compact(path_image g)"
huffman@36583
    68
  unfolding path_def path_image_def
hoelzl@37489
    69
  by (erule compact_continuous_image, rule compact_interval)
huffman@36583
    70
huffman@36583
    71
lemma reversepath_reversepath[simp]: "reversepath(reversepath g) = g"
huffman@36583
    72
  unfolding reversepath_def by auto
huffman@36583
    73
huffman@36583
    74
lemma pathstart_reversepath[simp]: "pathstart(reversepath g) = pathfinish g"
huffman@36583
    75
  unfolding pathstart_def reversepath_def pathfinish_def by auto
huffman@36583
    76
huffman@36583
    77
lemma pathfinish_reversepath[simp]: "pathfinish(reversepath g) = pathstart g"
huffman@36583
    78
  unfolding pathstart_def reversepath_def pathfinish_def by auto
huffman@36583
    79
huffman@36583
    80
lemma pathstart_join[simp]: "pathstart(g1 +++ g2) = pathstart g1"
huffman@36583
    81
  unfolding pathstart_def joinpaths_def pathfinish_def by auto
huffman@36583
    82
huffman@36583
    83
lemma pathfinish_join[simp]:"pathfinish(g1 +++ g2) = pathfinish g2"
huffman@36583
    84
  unfolding pathstart_def joinpaths_def pathfinish_def by auto
huffman@36583
    85
huffman@36583
    86
lemma path_image_reversepath[simp]: "path_image(reversepath g) = path_image g" proof-
huffman@36583
    87
  have *:"\<And>g. path_image(reversepath g) \<subseteq> path_image g"
huffman@36583
    88
    unfolding path_image_def subset_eq reversepath_def Ball_def image_iff apply(rule,rule,erule bexE)  
huffman@36583
    89
    apply(rule_tac x="1 - xa" in bexI) by auto
huffman@36583
    90
  show ?thesis using *[of g] *[of "reversepath g"] unfolding reversepath_reversepath by auto qed
huffman@36583
    91
huffman@36583
    92
lemma path_reversepath[simp]: "path(reversepath g) \<longleftrightarrow> path g" proof-
huffman@36583
    93
  have *:"\<And>g. path g \<Longrightarrow> path(reversepath g)" unfolding path_def reversepath_def
huffman@36583
    94
    apply(rule continuous_on_compose[unfolded o_def, of _ "\<lambda>x. 1 - x"])
huffman@36583
    95
    apply(rule continuous_on_sub, rule continuous_on_const, rule continuous_on_id)
huffman@36583
    96
    apply(rule continuous_on_subset[of "{0..1}"], assumption) by auto
huffman@36583
    97
  show ?thesis using *[of "reversepath g"] *[of g] unfolding reversepath_reversepath by (rule iffI) qed
huffman@36583
    98
huffman@36583
    99
lemmas reversepath_simps = path_reversepath path_image_reversepath pathstart_reversepath pathfinish_reversepath
huffman@36583
   100
huffman@36583
   101
lemma path_join[simp]: assumes "pathfinish g1 = pathstart g2" shows "path (g1 +++ g2) \<longleftrightarrow>  path g1 \<and> path g2"
huffman@36583
   102
  unfolding path_def pathfinish_def pathstart_def apply rule defer apply(erule conjE) proof-
huffman@36583
   103
  assume as:"continuous_on {0..1} (g1 +++ g2)"
huffman@36583
   104
  have *:"g1 = (\<lambda>x. g1 (2 *\<^sub>R x)) \<circ> (\<lambda>x. (1/2) *\<^sub>R x)" 
huffman@36583
   105
         "g2 = (\<lambda>x. g2 (2 *\<^sub>R x - 1)) \<circ> (\<lambda>x. (1/2) *\<^sub>R (x + 1))"
huffman@36583
   106
    unfolding o_def by (auto simp add: add_divide_distrib)
huffman@36583
   107
  have "op *\<^sub>R (1 / 2) ` {0::real..1} \<subseteq> {0..1}"  "(\<lambda>x. (1 / 2) *\<^sub>R (x + 1)) ` {(0::real)..1} \<subseteq> {0..1}"
huffman@36583
   108
    by auto
huffman@36583
   109
  thus "continuous_on {0..1} g1 \<and> continuous_on {0..1} g2" apply -apply rule
huffman@36583
   110
    apply(subst *) defer apply(subst *) apply (rule_tac[!] continuous_on_compose)
huffman@36583
   111
    apply (rule continuous_on_cmul, rule continuous_on_add, rule continuous_on_id, rule continuous_on_const) defer
huffman@36583
   112
    apply (rule continuous_on_cmul, rule continuous_on_id) apply(rule_tac[!] continuous_on_eq[of _ "g1 +++ g2"]) defer prefer 3
huffman@36583
   113
    apply(rule_tac[1-2] continuous_on_subset[of "{0 .. 1}"]) apply(rule as, assumption, rule as, assumption)
huffman@36583
   114
    apply(rule) defer apply rule proof-
huffman@36583
   115
    fix x assume "x \<in> op *\<^sub>R (1 / 2) ` {0::real..1}"
huffman@36583
   116
    hence "x \<le> 1 / 2" unfolding image_iff by auto
huffman@36583
   117
    thus "(g1 +++ g2) x = g1 (2 *\<^sub>R x)" unfolding joinpaths_def by auto next
huffman@36583
   118
    fix x assume "x \<in> (\<lambda>x. (1 / 2) *\<^sub>R (x + 1)) ` {0::real..1}"
huffman@36583
   119
    hence "x \<ge> 1 / 2" unfolding image_iff by auto
huffman@36583
   120
    thus "(g1 +++ g2) x = g2 (2 *\<^sub>R x - 1)" proof(cases "x = 1 / 2")
hoelzl@37489
   121
      case True hence "x = (1/2) *\<^sub>R 1" by auto 
huffman@36583
   122
      thus ?thesis unfolding joinpaths_def using assms[unfolded pathstart_def pathfinish_def] by (auto simp add: mult_ac)
huffman@36583
   123
    qed (auto simp add:le_less joinpaths_def) qed
huffman@36583
   124
next assume as:"continuous_on {0..1} g1" "continuous_on {0..1} g2"
huffman@36583
   125
  have *:"{0 .. 1::real} = {0.. (1/2)*\<^sub>R 1} \<union> {(1/2) *\<^sub>R 1 .. 1}" by auto
nipkow@39302
   126
  have **:"op *\<^sub>R 2 ` {0..(1 / 2) *\<^sub>R 1} = {0..1::real}" apply(rule set_eqI, rule) unfolding image_iff 
huffman@36583
   127
    defer apply(rule_tac x="(1/2)*\<^sub>R x" in bexI) by auto
huffman@36583
   128
  have ***:"(\<lambda>x. 2 *\<^sub>R x - 1) ` {(1 / 2) *\<^sub>R 1..1} = {0..1::real}"
huffman@36583
   129
    apply (auto simp add: image_def)
huffman@36583
   130
    apply (rule_tac x="(x + 1) / 2" in bexI)
huffman@36583
   131
    apply (auto simp add: add_divide_distrib)
huffman@36583
   132
    done
huffman@36583
   133
  show "continuous_on {0..1} (g1 +++ g2)" unfolding * apply(rule continuous_on_union) apply (rule closed_real_atLeastAtMost)+ proof-
huffman@36583
   134
    show "continuous_on {0..(1 / 2) *\<^sub>R 1} (g1 +++ g2)" apply(rule continuous_on_eq[of _ "\<lambda>x. g1 (2 *\<^sub>R x)"]) defer
huffman@36583
   135
      unfolding o_def[THEN sym] apply(rule continuous_on_compose) apply(rule continuous_on_cmul, rule continuous_on_id)
huffman@36583
   136
      unfolding ** apply(rule as(1)) unfolding joinpaths_def by auto next
huffman@36583
   137
    show "continuous_on {(1/2)*\<^sub>R1..1} (g1 +++ g2)" apply(rule continuous_on_eq[of _ "g2 \<circ> (\<lambda>x. 2 *\<^sub>R x - 1)"]) defer
huffman@36583
   138
      apply(rule continuous_on_compose) apply(rule continuous_on_sub, rule continuous_on_cmul, rule continuous_on_id, rule continuous_on_const)
huffman@36583
   139
      unfolding *** o_def joinpaths_def apply(rule as(2)) using assms[unfolded pathstart_def pathfinish_def]
huffman@36583
   140
      by (auto simp add: mult_ac) qed qed
huffman@36583
   141
huffman@36583
   142
lemma path_image_join_subset: "path_image(g1 +++ g2) \<subseteq> (path_image g1 \<union> path_image g2)" proof
huffman@36583
   143
  fix x assume "x \<in> path_image (g1 +++ g2)"
huffman@36583
   144
  then obtain y where y:"y\<in>{0..1}" "x = (if y \<le> 1 / 2 then g1 (2 *\<^sub>R y) else g2 (2 *\<^sub>R y - 1))"
huffman@36583
   145
    unfolding path_image_def image_iff joinpaths_def by auto
huffman@36583
   146
  thus "x \<in> path_image g1 \<union> path_image g2" apply(cases "y \<le> 1/2")
huffman@36583
   147
    apply(rule_tac UnI1) defer apply(rule_tac UnI2) unfolding y(2) path_image_def using y(1)
huffman@36583
   148
    by(auto intro!: imageI) qed
huffman@36583
   149
huffman@36583
   150
lemma subset_path_image_join:
huffman@36583
   151
  assumes "path_image g1 \<subseteq> s" "path_image g2 \<subseteq> s" shows "path_image(g1 +++ g2) \<subseteq> s"
huffman@36583
   152
  using path_image_join_subset[of g1 g2] and assms by auto
huffman@36583
   153
huffman@36583
   154
lemma path_image_join:
huffman@36583
   155
  assumes "path g1" "path g2" "pathfinish g1 = pathstart g2"
huffman@36583
   156
  shows "path_image(g1 +++ g2) = (path_image g1) \<union> (path_image g2)"
huffman@36583
   157
apply(rule, rule path_image_join_subset, rule) unfolding Un_iff proof(erule disjE)
huffman@36583
   158
  fix x assume "x \<in> path_image g1"
huffman@36583
   159
  then obtain y where y:"y\<in>{0..1}" "x = g1 y" unfolding path_image_def image_iff by auto
huffman@36583
   160
  thus "x \<in> path_image (g1 +++ g2)" unfolding joinpaths_def path_image_def image_iff
huffman@36583
   161
    apply(rule_tac x="(1/2) *\<^sub>R y" in bexI) by auto next
huffman@36583
   162
  fix x assume "x \<in> path_image g2"
huffman@36583
   163
  then obtain y where y:"y\<in>{0..1}" "x = g2 y" unfolding path_image_def image_iff by auto
huffman@36583
   164
  then show "x \<in> path_image (g1 +++ g2)" unfolding joinpaths_def path_image_def image_iff
huffman@36583
   165
    apply(rule_tac x="(1/2) *\<^sub>R (y + 1)" in bexI) using assms(3)[unfolded pathfinish_def pathstart_def]
huffman@36583
   166
    by (auto simp add: add_divide_distrib) qed
huffman@36583
   167
huffman@36583
   168
lemma not_in_path_image_join:
huffman@36583
   169
  assumes "x \<notin> path_image g1" "x \<notin> path_image g2" shows "x \<notin> path_image(g1 +++ g2)"
huffman@36583
   170
  using assms and path_image_join_subset[of g1 g2] by auto
huffman@36583
   171
huffman@36583
   172
lemma simple_path_reversepath: assumes "simple_path g" shows "simple_path (reversepath g)"
huffman@36583
   173
  using assms unfolding simple_path_def reversepath_def apply- apply(rule ballI)+
huffman@36583
   174
  apply(erule_tac x="1-x" in ballE, erule_tac x="1-y" in ballE)
huffman@36583
   175
  by auto
huffman@36583
   176
huffman@36583
   177
lemma simple_path_join_loop:
huffman@36583
   178
  assumes "injective_path g1" "injective_path g2" "pathfinish g2 = pathstart g1"
huffman@36583
   179
  "(path_image g1 \<inter> path_image g2) \<subseteq> {pathstart g1,pathstart g2}"
huffman@36583
   180
  shows "simple_path(g1 +++ g2)"
huffman@36583
   181
unfolding simple_path_def proof((rule ballI)+, rule impI) let ?g = "g1 +++ g2"
huffman@36583
   182
  note inj = assms(1,2)[unfolded injective_path_def, rule_format]
huffman@36583
   183
  fix x y::"real" assume xy:"x \<in> {0..1}" "y \<in> {0..1}" "?g x = ?g y"
huffman@36583
   184
  show "x = y \<or> x = 0 \<and> y = 1 \<or> x = 1 \<and> y = 0" proof(case_tac "x \<le> 1/2",case_tac[!] "y \<le> 1/2", unfold not_le)
huffman@36583
   185
    assume as:"x \<le> 1 / 2" "y \<le> 1 / 2"
huffman@36583
   186
    hence "g1 (2 *\<^sub>R x) = g1 (2 *\<^sub>R y)" using xy(3) unfolding joinpaths_def by auto
huffman@36583
   187
    moreover have "2 *\<^sub>R x \<in> {0..1}" "2 *\<^sub>R y \<in> {0..1}" using xy(1,2) as
huffman@36583
   188
      by auto
huffman@36583
   189
    ultimately show ?thesis using inj(1)[of "2*\<^sub>R x" "2*\<^sub>R y"] by auto
huffman@36583
   190
  next assume as:"x > 1 / 2" "y > 1 / 2"
huffman@36583
   191
    hence "g2 (2 *\<^sub>R x - 1) = g2 (2 *\<^sub>R y - 1)" using xy(3) unfolding joinpaths_def by auto
huffman@36583
   192
    moreover have "2 *\<^sub>R x - 1 \<in> {0..1}" "2 *\<^sub>R y - 1 \<in> {0..1}" using xy(1,2) as by auto
huffman@36583
   193
    ultimately show ?thesis using inj(2)[of "2*\<^sub>R x - 1" "2*\<^sub>R y - 1"] by auto
huffman@36583
   194
  next assume as:"x \<le> 1 / 2" "y > 1 / 2"
huffman@36583
   195
    hence "?g x \<in> path_image g1" "?g y \<in> path_image g2" unfolding path_image_def joinpaths_def
huffman@36583
   196
      using xy(1,2) by auto
huffman@36583
   197
    moreover have "?g y \<noteq> pathstart g2" using as(2) unfolding pathstart_def joinpaths_def
huffman@36583
   198
      using inj(2)[of "2 *\<^sub>R y - 1" 0] and xy(2)
huffman@36583
   199
      by (auto simp add: field_simps)
huffman@36583
   200
    ultimately have *:"?g x = pathstart g1" using assms(4) unfolding xy(3) by auto
huffman@36583
   201
    hence "x = 0" unfolding pathstart_def joinpaths_def using as(1) and xy(1)
huffman@36583
   202
      using inj(1)[of "2 *\<^sub>R x" 0] by auto
huffman@36583
   203
    moreover have "y = 1" using * unfolding xy(3) assms(3)[THEN sym]
huffman@36583
   204
      unfolding joinpaths_def pathfinish_def using as(2) and xy(2)
huffman@36583
   205
      using inj(2)[of "2 *\<^sub>R y - 1" 1] by auto
huffman@36583
   206
    ultimately show ?thesis by auto
huffman@36583
   207
  next assume as:"x > 1 / 2" "y \<le> 1 / 2"
huffman@36583
   208
    hence "?g x \<in> path_image g2" "?g y \<in> path_image g1" unfolding path_image_def joinpaths_def
huffman@36583
   209
      using xy(1,2) by auto
huffman@36583
   210
    moreover have "?g x \<noteq> pathstart g2" using as(1) unfolding pathstart_def joinpaths_def
huffman@36583
   211
      using inj(2)[of "2 *\<^sub>R x - 1" 0] and xy(1)
huffman@36583
   212
      by (auto simp add: field_simps)
huffman@36583
   213
    ultimately have *:"?g y = pathstart g1" using assms(4) unfolding xy(3) by auto
huffman@36583
   214
    hence "y = 0" unfolding pathstart_def joinpaths_def using as(2) and xy(2)
huffman@36583
   215
      using inj(1)[of "2 *\<^sub>R y" 0] by auto
huffman@36583
   216
    moreover have "x = 1" using * unfolding xy(3)[THEN sym] assms(3)[THEN sym]
huffman@36583
   217
      unfolding joinpaths_def pathfinish_def using as(1) and xy(1)
huffman@36583
   218
      using inj(2)[of "2 *\<^sub>R x - 1" 1] by auto
huffman@36583
   219
    ultimately show ?thesis by auto qed qed
huffman@36583
   220
huffman@36583
   221
lemma injective_path_join:
huffman@36583
   222
  assumes "injective_path g1" "injective_path g2" "pathfinish g1 = pathstart g2"
huffman@36583
   223
  "(path_image g1 \<inter> path_image g2) \<subseteq> {pathstart g2}"
huffman@36583
   224
  shows "injective_path(g1 +++ g2)"
huffman@36583
   225
  unfolding injective_path_def proof(rule,rule,rule) let ?g = "g1 +++ g2"
huffman@36583
   226
  note inj = assms(1,2)[unfolded injective_path_def, rule_format]
huffman@36583
   227
  fix x y assume xy:"x \<in> {0..1}" "y \<in> {0..1}" "(g1 +++ g2) x = (g1 +++ g2) y"
huffman@36583
   228
  show "x = y" proof(cases "x \<le> 1/2", case_tac[!] "y \<le> 1/2", unfold not_le)
huffman@36583
   229
    assume "x \<le> 1 / 2" "y \<le> 1 / 2" thus ?thesis using inj(1)[of "2*\<^sub>R x" "2*\<^sub>R y"] and xy
huffman@36583
   230
      unfolding joinpaths_def by auto
huffman@36583
   231
  next assume "x > 1 / 2" "y > 1 / 2" thus ?thesis using inj(2)[of "2*\<^sub>R x - 1" "2*\<^sub>R y - 1"] and xy
huffman@36583
   232
      unfolding joinpaths_def by auto
huffman@36583
   233
  next assume as:"x \<le> 1 / 2" "y > 1 / 2" 
huffman@36583
   234
    hence "?g x \<in> path_image g1" "?g y \<in> path_image g2" unfolding path_image_def joinpaths_def
huffman@36583
   235
      using xy(1,2) by auto
huffman@36583
   236
    hence "?g x = pathfinish g1" "?g y = pathstart g2" using assms(4) unfolding assms(3) xy(3) by auto
huffman@36583
   237
    thus ?thesis using as and inj(1)[of "2 *\<^sub>R x" 1] inj(2)[of "2 *\<^sub>R y - 1" 0] and xy(1,2)
huffman@36583
   238
      unfolding pathstart_def pathfinish_def joinpaths_def
huffman@36583
   239
      by auto
huffman@36583
   240
  next assume as:"x > 1 / 2" "y \<le> 1 / 2" 
huffman@36583
   241
    hence "?g x \<in> path_image g2" "?g y \<in> path_image g1" unfolding path_image_def joinpaths_def
huffman@36583
   242
      using xy(1,2) by auto
huffman@36583
   243
    hence "?g x = pathstart g2" "?g y = pathfinish g1" using assms(4) unfolding assms(3) xy(3) by auto
huffman@36583
   244
    thus ?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)
huffman@36583
   245
      unfolding pathstart_def pathfinish_def joinpaths_def
huffman@36583
   246
      by auto qed qed
huffman@36583
   247
huffman@36583
   248
lemmas join_paths_simps = path_join path_image_join pathstart_join pathfinish_join
huffman@36583
   249
 
huffman@36583
   250
subsection {* Reparametrizing a closed curve to start at some chosen point. *}
huffman@36583
   251
huffman@36583
   252
definition "shiftpath a (f::real \<Rightarrow> 'a::topological_space) =
huffman@36583
   253
  (\<lambda>x. if (a + x) \<le> 1 then f(a + x) else f(a + x - 1))"
huffman@36583
   254
huffman@36583
   255
lemma pathstart_shiftpath: "a \<le> 1 \<Longrightarrow> pathstart(shiftpath a g) = g a"
huffman@36583
   256
  unfolding pathstart_def shiftpath_def by auto
huffman@36583
   257
huffman@36583
   258
lemma pathfinish_shiftpath: assumes "0 \<le> a" "pathfinish g = pathstart g"
huffman@36583
   259
  shows "pathfinish(shiftpath a g) = g a"
huffman@36583
   260
  using assms unfolding pathstart_def pathfinish_def shiftpath_def
huffman@36583
   261
  by auto
huffman@36583
   262
huffman@36583
   263
lemma endpoints_shiftpath:
huffman@36583
   264
  assumes "pathfinish g = pathstart g" "a \<in> {0 .. 1}" 
huffman@36583
   265
  shows "pathfinish(shiftpath a g) = g a" "pathstart(shiftpath a g) = g a"
huffman@36583
   266
  using assms by(auto intro!:pathfinish_shiftpath pathstart_shiftpath)
huffman@36583
   267
huffman@36583
   268
lemma closed_shiftpath:
huffman@36583
   269
  assumes "pathfinish g = pathstart g" "a \<in> {0..1}"
huffman@36583
   270
  shows "pathfinish(shiftpath a g) = pathstart(shiftpath a g)"
huffman@36583
   271
  using endpoints_shiftpath[OF assms] by auto
huffman@36583
   272
huffman@36583
   273
lemma path_shiftpath:
huffman@36583
   274
  assumes "path g" "pathfinish g = pathstart g" "a \<in> {0..1}"
huffman@36583
   275
  shows "path(shiftpath a g)" proof-
huffman@36583
   276
  have *:"{0 .. 1} = {0 .. 1-a} \<union> {1-a .. 1}" using assms(3) by auto
huffman@36583
   277
  have **:"\<And>x. x + a = 1 \<Longrightarrow> g (x + a - 1) = g (x + a)"
huffman@36583
   278
    using assms(2)[unfolded pathfinish_def pathstart_def] by auto
huffman@36583
   279
  show ?thesis unfolding path_def shiftpath_def * apply(rule continuous_on_union)
huffman@36583
   280
    apply(rule closed_real_atLeastAtMost)+ apply(rule continuous_on_eq[of _ "g \<circ> (\<lambda>x. a + x)"]) prefer 3
huffman@36583
   281
    apply(rule continuous_on_eq[of _ "g \<circ> (\<lambda>x. a - 1 + x)"]) defer prefer 3
huffman@36583
   282
    apply(rule continuous_on_intros)+ prefer 2 apply(rule continuous_on_intros)+
huffman@36583
   283
    apply(rule_tac[1-2] continuous_on_subset[OF assms(1)[unfolded path_def]])
huffman@36583
   284
    using assms(3) and ** by(auto, auto simp add: field_simps) qed
huffman@36583
   285
huffman@36583
   286
lemma shiftpath_shiftpath: assumes "pathfinish g = pathstart g" "a \<in> {0..1}" "x \<in> {0..1}" 
huffman@36583
   287
  shows "shiftpath (1 - a) (shiftpath a g) x = g x"
huffman@36583
   288
  using assms unfolding pathfinish_def pathstart_def shiftpath_def by auto
huffman@36583
   289
huffman@36583
   290
lemma path_image_shiftpath:
huffman@36583
   291
  assumes "a \<in> {0..1}" "pathfinish g = pathstart g"
huffman@36583
   292
  shows "path_image(shiftpath a g) = path_image g" proof-
huffman@36583
   293
  { fix x 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)" 
huffman@36583
   294
    hence "\<exists>y\<in>{0..1} \<inter> {x. a + x \<le> 1}. g x = g (a + y)" proof(cases "a \<le> x")
huffman@36583
   295
      case False thus ?thesis apply(rule_tac x="1 + x - a" in bexI)
huffman@36583
   296
        using as(1,2) and as(3)[THEN bspec[where x="1 + x - a"]] and assms(1)
huffman@36583
   297
        by(auto simp add: field_simps atomize_not) next
huffman@36583
   298
      case True thus ?thesis using as(1-2) and assms(1) apply(rule_tac x="x - a" in bexI)
huffman@36583
   299
        by(auto simp add: field_simps) qed }
huffman@36583
   300
  thus ?thesis using assms unfolding shiftpath_def path_image_def pathfinish_def pathstart_def
huffman@36583
   301
    by(auto simp add: image_iff) qed
huffman@36583
   302
huffman@36583
   303
subsection {* Special case of straight-line paths. *}
huffman@36583
   304
huffman@36583
   305
definition
huffman@36583
   306
  linepath :: "'a::real_normed_vector \<Rightarrow> 'a \<Rightarrow> real \<Rightarrow> 'a" where
huffman@36583
   307
  "linepath a b = (\<lambda>x. (1 - x) *\<^sub>R a + x *\<^sub>R b)"
huffman@36583
   308
huffman@36583
   309
lemma pathstart_linepath[simp]: "pathstart(linepath a b) = a"
huffman@36583
   310
  unfolding pathstart_def linepath_def by auto
huffman@36583
   311
huffman@36583
   312
lemma pathfinish_linepath[simp]: "pathfinish(linepath a b) = b"
huffman@36583
   313
  unfolding pathfinish_def linepath_def by auto
huffman@36583
   314
huffman@36583
   315
lemma continuous_linepath_at[intro]: "continuous (at x) (linepath a b)"
huffman@36583
   316
  unfolding linepath_def by (intro continuous_intros)
huffman@36583
   317
huffman@36583
   318
lemma continuous_on_linepath[intro]: "continuous_on s (linepath a b)"
huffman@36583
   319
  using continuous_linepath_at by(auto intro!: continuous_at_imp_continuous_on)
huffman@36583
   320
huffman@36583
   321
lemma path_linepath[intro]: "path(linepath a b)"
huffman@36583
   322
  unfolding path_def by(rule continuous_on_linepath)
huffman@36583
   323
huffman@36583
   324
lemma path_image_linepath[simp]: "path_image(linepath a b) = (closed_segment a b)"
nipkow@39302
   325
  unfolding path_image_def segment linepath_def apply (rule set_eqI, rule) defer
huffman@36583
   326
  unfolding mem_Collect_eq image_iff apply(erule exE) apply(rule_tac x="u *\<^sub>R 1" in bexI)
huffman@36583
   327
  by auto
huffman@36583
   328
huffman@36583
   329
lemma reversepath_linepath[simp]:  "reversepath(linepath a b) = linepath b a"
huffman@36583
   330
  unfolding reversepath_def linepath_def by(rule ext, auto)
huffman@36583
   331
huffman@36583
   332
lemma injective_path_linepath:
huffman@36583
   333
  assumes "a \<noteq> b" shows "injective_path(linepath a b)"
huffman@36583
   334
proof -
huffman@36583
   335
  { fix x y :: "real"
huffman@36583
   336
    assume "x *\<^sub>R b + y *\<^sub>R a = x *\<^sub>R a + y *\<^sub>R b"
huffman@36583
   337
    hence "(x - y) *\<^sub>R a = (x - y) *\<^sub>R b" by (simp add: algebra_simps)
huffman@36583
   338
    with assms have "x = y" by simp }
huffman@36583
   339
  thus ?thesis unfolding injective_path_def linepath_def by(auto simp add: algebra_simps) qed
huffman@36583
   340
huffman@36583
   341
lemma simple_path_linepath[intro]: "a \<noteq> b \<Longrightarrow> simple_path(linepath a b)" by(auto intro!: injective_imp_simple_path injective_path_linepath)
huffman@36583
   342
huffman@36583
   343
subsection {* Bounding a point away from a path. *}
huffman@36583
   344
huffman@36583
   345
lemma not_on_path_ball:
huffman@36583
   346
  fixes g :: "real \<Rightarrow> 'a::heine_borel"
huffman@36583
   347
  assumes "path g" "z \<notin> path_image g"
huffman@36583
   348
  shows "\<exists>e>0. ball z e \<inter> (path_image g) = {}" proof-
huffman@36583
   349
  obtain a where "a\<in>path_image g" "\<forall>y\<in>path_image g. dist z a \<le> dist z y"
huffman@36583
   350
    using distance_attains_inf[OF _ path_image_nonempty, of g z]
huffman@36583
   351
    using compact_path_image[THEN compact_imp_closed, OF assms(1)] by auto
huffman@36583
   352
  thus ?thesis apply(rule_tac x="dist z a" in exI) using assms(2) by(auto intro!: dist_pos_lt) qed
huffman@36583
   353
huffman@36583
   354
lemma not_on_path_cball:
huffman@36583
   355
  fixes g :: "real \<Rightarrow> 'a::heine_borel"
huffman@36583
   356
  assumes "path g" "z \<notin> path_image g"
huffman@36583
   357
  shows "\<exists>e>0. cball z e \<inter> (path_image g) = {}" proof-
huffman@36583
   358
  obtain e where "ball z e \<inter> path_image g = {}" "e>0" using not_on_path_ball[OF assms] by auto
huffman@36583
   359
  moreover have "cball z (e/2) \<subseteq> ball z e" using `e>0` by auto
huffman@36583
   360
  ultimately show ?thesis apply(rule_tac x="e/2" in exI) by auto qed
huffman@36583
   361
huffman@36583
   362
subsection {* Path component, considered as a "joinability" relation (from Tom Hales). *}
huffman@36583
   363
huffman@36583
   364
definition "path_component s x y \<longleftrightarrow> (\<exists>g. path g \<and> path_image g \<subseteq> s \<and> pathstart g = x \<and> pathfinish g = y)"
huffman@36583
   365
huffman@36583
   366
lemmas path_defs = path_def pathstart_def pathfinish_def path_image_def path_component_def 
huffman@36583
   367
huffman@36583
   368
lemma path_component_mem: assumes "path_component s x y" shows "x \<in> s" "y \<in> s"
huffman@36583
   369
  using assms unfolding path_defs by auto
huffman@36583
   370
huffman@36583
   371
lemma path_component_refl: assumes "x \<in> s" shows "path_component s x x"
huffman@36583
   372
  unfolding path_defs apply(rule_tac x="\<lambda>u. x" in exI) using assms 
huffman@36583
   373
  by(auto intro!:continuous_on_intros)
huffman@36583
   374
huffman@36583
   375
lemma path_component_refl_eq: "path_component s x x \<longleftrightarrow> x \<in> s"
huffman@36583
   376
  by(auto intro!: path_component_mem path_component_refl)
huffman@36583
   377
huffman@36583
   378
lemma path_component_sym: "path_component s x y \<Longrightarrow> path_component s y x"
huffman@36583
   379
  using assms unfolding path_component_def apply(erule exE) apply(rule_tac x="reversepath g" in exI)
huffman@36583
   380
  by auto
huffman@36583
   381
huffman@36583
   382
lemma path_component_trans: assumes "path_component s x y" "path_component s y z" shows "path_component s x z"
huffman@36583
   383
  using assms unfolding path_component_def apply- apply(erule exE)+ apply(rule_tac x="g +++ ga" in exI) by(auto simp add: path_image_join)
huffman@36583
   384
huffman@36583
   385
lemma path_component_of_subset: "s \<subseteq> t \<Longrightarrow>  path_component s x y \<Longrightarrow> path_component t x y"
huffman@36583
   386
  unfolding path_component_def by auto
huffman@36583
   387
huffman@36583
   388
subsection {* Can also consider it as a set, as the name suggests. *}
huffman@36583
   389
huffman@44170
   390
lemma path_component_set: "{y. path_component s x y} = { y. (\<exists>g. path g \<and> path_image g \<subseteq> s \<and> pathstart g = x \<and> pathfinish g = y )}"
huffman@44170
   391
  apply(rule set_eqI) unfolding mem_Collect_eq unfolding path_component_def by auto
huffman@36583
   392
huffman@44170
   393
lemma path_component_subset: "{y. path_component s x y} \<subseteq> s"
huffman@44170
   394
  apply(rule, rule path_component_mem(2)) by auto
huffman@36583
   395
huffman@44170
   396
lemma path_component_eq_empty: "{y. path_component s x y} = {} \<longleftrightarrow> x \<notin> s"
huffman@44170
   397
  apply rule apply(drule equals0D[of _ x]) defer apply(rule equals0I) unfolding mem_Collect_eq
huffman@36583
   398
  apply(drule path_component_mem(1)) using path_component_refl by auto
huffman@36583
   399
huffman@36583
   400
subsection {* Path connectedness of a space. *}
huffman@36583
   401
huffman@36583
   402
definition "path_connected s \<longleftrightarrow> (\<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)"
huffman@36583
   403
huffman@36583
   404
lemma path_connected_component: "path_connected s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>y\<in>s. path_component s x y)"
huffman@36583
   405
  unfolding path_connected_def path_component_def by auto
huffman@36583
   406
huffman@44170
   407
lemma path_connected_component_set: "path_connected s \<longleftrightarrow> (\<forall>x\<in>s. {y. path_component s x y} = s)" 
huffman@36583
   408
  unfolding path_connected_component apply(rule, rule, rule, rule path_component_subset) 
huffman@44170
   409
  unfolding subset_eq mem_Collect_eq Ball_def by auto
huffman@36583
   410
huffman@36583
   411
subsection {* Some useful lemmas about path-connectedness. *}
huffman@36583
   412
huffman@36583
   413
lemma convex_imp_path_connected:
huffman@36583
   414
  fixes s :: "'a::real_normed_vector set"
huffman@36583
   415
  assumes "convex s" shows "path_connected s"
huffman@36583
   416
  unfolding path_connected_def apply(rule,rule,rule_tac x="linepath x y" in exI)
huffman@36583
   417
  unfolding path_image_linepath using assms[unfolded convex_contains_segment] by auto
huffman@36583
   418
huffman@36583
   419
lemma path_connected_imp_connected: assumes "path_connected s" shows "connected s"
huffman@36583
   420
  unfolding connected_def not_ex apply(rule,rule,rule ccontr) unfolding not_not apply(erule conjE)+ proof-
huffman@36583
   421
  fix e1 e2 assume as:"open e1" "open e2" "s \<subseteq> e1 \<union> e2" "e1 \<inter> e2 \<inter> s = {}" "e1 \<inter> s \<noteq> {}" "e2 \<inter> s \<noteq> {}"
huffman@36583
   422
  then obtain x1 x2 where obt:"x1\<in>e1\<inter>s" "x2\<in>e2\<inter>s" by auto
huffman@36583
   423
  then obtain g where g:"path g" "path_image g \<subseteq> s" "pathstart g = x1" "pathfinish g = x2"
huffman@36583
   424
    using assms[unfolded path_connected_def,rule_format,of x1 x2] by auto
huffman@36583
   425
  have *:"connected {0..1::real}" by(auto intro!: convex_connected convex_real_interval)
huffman@36583
   426
  have "{0..1} \<subseteq> {x \<in> {0..1}. g x \<in> e1} \<union> {x \<in> {0..1}. g x \<in> e2}" using as(3) g(2)[unfolded path_defs] by blast
huffman@36583
   427
  moreover have "{x \<in> {0..1}. g x \<in> e1} \<inter> {x \<in> {0..1}. g x \<in> e2} = {}" using as(4) g(2)[unfolded path_defs] unfolding subset_eq by auto 
huffman@36583
   428
  moreover have "{x \<in> {0..1}. g x \<in> e1} \<noteq> {} \<and> {x \<in> {0..1}. g x \<in> e2} \<noteq> {}" using g(3,4)[unfolded path_defs] using obt
huffman@36583
   429
    by (simp add: ex_in_conv [symmetric], metis zero_le_one order_refl)
huffman@36583
   430
  ultimately show False 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}"]
huffman@36583
   431
    using continuous_open_in_preimage[OF g(1)[unfolded path_def] as(1)]
huffman@36583
   432
    using continuous_open_in_preimage[OF g(1)[unfolded path_def] as(2)] by auto qed
huffman@36583
   433
huffman@36583
   434
lemma open_path_component:
huffman@36583
   435
  fixes s :: "'a::real_normed_vector set" (*TODO: generalize to metric_space*)
huffman@44170
   436
  assumes "open s" shows "open {y. path_component s x y}"
huffman@36583
   437
  unfolding open_contains_ball proof
huffman@44170
   438
  fix y assume as:"y \<in> {y. path_component s x y}"
huffman@44170
   439
  hence "y\<in>s" apply- apply(rule path_component_mem(2)) unfolding mem_Collect_eq by auto
huffman@36583
   440
  then obtain e where e:"e>0" "ball y e \<subseteq> s" using assms[unfolded open_contains_ball] by auto
huffman@44170
   441
  show "\<exists>e>0. ball y e \<subseteq> {y. path_component s x y}" apply(rule_tac x=e in exI) apply(rule,rule `e>0`,rule) unfolding mem_ball mem_Collect_eq proof-
huffman@36583
   442
    fix z assume "dist y z < e" thus "path_component s x z" apply(rule_tac path_component_trans[of _ _ y]) defer 
huffman@36583
   443
      apply(rule path_component_of_subset[OF e(2)]) apply(rule convex_imp_path_connected[OF convex_ball, unfolded path_connected_component, rule_format]) using `e>0`
huffman@44170
   444
      using as by auto qed qed
huffman@36583
   445
huffman@36583
   446
lemma open_non_path_component:
huffman@36583
   447
  fixes s :: "'a::real_normed_vector set" (*TODO: generalize to metric_space*)
huffman@44170
   448
  assumes "open s" shows "open(s - {y. path_component s x y})"
huffman@36583
   449
  unfolding open_contains_ball proof
huffman@44170
   450
  fix y assume as:"y\<in>s - {y. path_component s x y}"
huffman@36583
   451
  then obtain e where e:"e>0" "ball y e \<subseteq> s" using assms[unfolded open_contains_ball] by auto
huffman@44170
   452
  show "\<exists>e>0. ball y e \<subseteq> s - {y. path_component s x y}" apply(rule_tac x=e in exI) apply(rule,rule `e>0`,rule,rule) defer proof(rule ccontr)
huffman@44170
   453
    fix z assume "z\<in>ball y e" "\<not> z \<notin> {y. path_component s x y}"
huffman@44170
   454
    hence "y \<in> {y. path_component s x y}" unfolding not_not mem_Collect_eq using `e>0`
huffman@36583
   455
      apply- apply(rule path_component_trans,assumption) apply(rule path_component_of_subset[OF e(2)])
huffman@36583
   456
      apply(rule convex_imp_path_connected[OF convex_ball, unfolded path_connected_component, rule_format]) by auto
huffman@36583
   457
    thus False using as by auto qed(insert e(2), auto) qed
huffman@36583
   458
huffman@36583
   459
lemma connected_open_path_connected:
huffman@36583
   460
  fixes s :: "'a::real_normed_vector set" (*TODO: generalize to metric_space*)
huffman@36583
   461
  assumes "open s" "connected s" shows "path_connected s"
huffman@36583
   462
  unfolding path_connected_component_set proof(rule,rule,rule path_component_subset, rule)
huffman@44170
   463
  fix x y assume "x \<in> s" "y \<in> s" show "y \<in> {y. path_component s x y}" proof(rule ccontr)
huffman@44170
   464
    assume "y \<notin> {y. path_component s x y}" moreover
huffman@44170
   465
    have "{y. path_component s x y} \<inter> s \<noteq> {}" using `x\<in>s` path_component_eq_empty path_component_subset[of s x] by auto
huffman@36583
   466
    ultimately show False using `y\<in>s` open_non_path_component[OF assms(1)] open_path_component[OF assms(1)]
huffman@44170
   467
    using assms(2)[unfolded connected_def not_ex, rule_format, of"{y. path_component s x y}" "s - {y. path_component s x y}"] by auto
huffman@36583
   468
qed qed
huffman@36583
   469
huffman@36583
   470
lemma path_connected_continuous_image:
huffman@36583
   471
  assumes "continuous_on s f" "path_connected s" shows "path_connected (f ` s)"
huffman@36583
   472
  unfolding path_connected_def proof(rule,rule)
huffman@36583
   473
  fix x' y' assume "x' \<in> f ` s" "y' \<in> f ` s"
huffman@36583
   474
  then obtain x y where xy:"x\<in>s" "y\<in>s" "x' = f x" "y' = f y" by auto
huffman@36583
   475
  guess g using assms(2)[unfolded path_connected_def,rule_format,OF xy(1,2)] ..
huffman@36583
   476
  thus "\<exists>g. path g \<and> path_image g \<subseteq> f ` s \<and> pathstart g = x' \<and> pathfinish g = y'"
huffman@36583
   477
    unfolding xy apply(rule_tac x="f \<circ> g" in exI) unfolding path_defs
huffman@36583
   478
    using assms(1) by(auto intro!: continuous_on_compose continuous_on_subset[of _ _ "g ` {0..1}"]) qed
huffman@36583
   479
huffman@36583
   480
lemma homeomorphic_path_connectedness:
huffman@36583
   481
  "s homeomorphic t \<Longrightarrow> (path_connected s \<longleftrightarrow> path_connected t)"
huffman@36583
   482
  unfolding homeomorphic_def homeomorphism_def apply(erule exE|erule conjE)+ apply rule
huffman@36583
   483
  apply(drule_tac f=f in path_connected_continuous_image) prefer 3
huffman@36583
   484
  apply(drule_tac f=g in path_connected_continuous_image) by auto
huffman@36583
   485
huffman@36583
   486
lemma path_connected_empty: "path_connected {}"
huffman@36583
   487
  unfolding path_connected_def by auto
huffman@36583
   488
huffman@36583
   489
lemma path_connected_singleton: "path_connected {a}"
huffman@36583
   490
  unfolding path_connected_def pathstart_def pathfinish_def path_image_def
huffman@36583
   491
  apply (clarify, rule_tac x="\<lambda>x. a" in exI, simp add: image_constant_conv)
huffman@36583
   492
  apply (simp add: path_def continuous_on_const)
huffman@36583
   493
  done
huffman@36583
   494
huffman@36583
   495
lemma path_connected_Un: assumes "path_connected s" "path_connected t" "s \<inter> t \<noteq> {}"
huffman@36583
   496
  shows "path_connected (s \<union> t)" unfolding path_connected_component proof(rule,rule)
huffman@36583
   497
  fix x y assume as:"x \<in> s \<union> t" "y \<in> s \<union> t" 
huffman@36583
   498
  from assms(3) obtain z where "z \<in> s \<inter> t" by auto
huffman@36583
   499
  thus "path_component (s \<union> t) x y" using as using assms(1-2)[unfolded path_connected_component] apply- 
huffman@36583
   500
    apply(erule_tac[!] UnE)+ apply(rule_tac[2-3] path_component_trans[of _ _ z])
huffman@36583
   501
    by(auto simp add:path_component_of_subset [OF Un_upper1] path_component_of_subset[OF Un_upper2]) qed
huffman@36583
   502
huffman@37674
   503
lemma path_connected_UNION:
huffman@37674
   504
  assumes "\<And>i. i \<in> A \<Longrightarrow> path_connected (S i)"
huffman@37674
   505
  assumes "\<And>i. i \<in> A \<Longrightarrow> z \<in> S i"
huffman@37674
   506
  shows "path_connected (\<Union>i\<in>A. S i)"
huffman@37674
   507
unfolding path_connected_component proof(clarify)
huffman@37674
   508
  fix x i y j
huffman@37674
   509
  assume *: "i \<in> A" "x \<in> S i" "j \<in> A" "y \<in> S j"
huffman@37674
   510
  hence "path_component (S i) x z" and "path_component (S j) z y"
huffman@37674
   511
    using assms by (simp_all add: path_connected_component)
huffman@37674
   512
  hence "path_component (\<Union>i\<in>A. S i) x z" and "path_component (\<Union>i\<in>A. S i) z y"
huffman@37674
   513
    using *(1,3) by (auto elim!: path_component_of_subset [COMP swap_prems_rl])
huffman@37674
   514
  thus "path_component (\<Union>i\<in>A. S i) x y"
huffman@37674
   515
    by (rule path_component_trans)
huffman@37674
   516
qed
huffman@36583
   517
huffman@37674
   518
subsection {* sphere is path-connected. *}
hoelzl@37489
   519
huffman@36583
   520
lemma path_connected_punctured_universe:
huffman@37674
   521
  assumes "2 \<le> DIM('a::euclidean_space)"
huffman@37674
   522
  shows "path_connected((UNIV::'a::euclidean_space set) - {a})"
huffman@37674
   523
proof-
huffman@37674
   524
  let ?A = "{x::'a. \<exists>i\<in>{..<DIM('a)}. x $$ i < a $$ i}"
huffman@37674
   525
  let ?B = "{x::'a. \<exists>i\<in>{..<DIM('a)}. a $$ i < x $$ i}"
huffman@36583
   526
huffman@37674
   527
  have A: "path_connected ?A" unfolding Collect_bex_eq
huffman@37674
   528
  proof (rule path_connected_UNION)
huffman@37674
   529
    fix i assume "i \<in> {..<DIM('a)}"
huffman@37674
   530
    thus "(\<chi>\<chi> i. a $$ i - 1) \<in> {x::'a. x $$ i < a $$ i}" by simp
huffman@37674
   531
    show "path_connected {x. x $$ i < a $$ i}" unfolding euclidean_component_def
huffman@37674
   532
      by (rule convex_imp_path_connected [OF convex_halfspace_lt])
huffman@37674
   533
  qed
huffman@37674
   534
  have B: "path_connected ?B" unfolding Collect_bex_eq
huffman@37674
   535
  proof (rule path_connected_UNION)
huffman@37674
   536
    fix i assume "i \<in> {..<DIM('a)}"
huffman@37674
   537
    thus "(\<chi>\<chi> i. a $$ i + 1) \<in> {x::'a. a $$ i < x $$ i}" by simp
huffman@37674
   538
    show "path_connected {x. a $$ i < x $$ i}" unfolding euclidean_component_def
huffman@37674
   539
      by (rule convex_imp_path_connected [OF convex_halfspace_gt])
huffman@37674
   540
  qed
huffman@37674
   541
  from assms have "1 < DIM('a)" by auto
huffman@37674
   542
  hence "a + basis 0 - basis 1 \<in> ?A \<inter> ?B" by auto
huffman@37674
   543
  hence "?A \<inter> ?B \<noteq> {}" by fast
huffman@37674
   544
  with A B have "path_connected (?A \<union> ?B)"
huffman@37674
   545
    by (rule path_connected_Un)
huffman@37674
   546
  also have "?A \<union> ?B = {x. \<exists>i\<in>{..<DIM('a)}. x $$ i \<noteq> a $$ i}"
huffman@37674
   547
    unfolding neq_iff bex_disj_distrib Collect_disj_eq ..
huffman@37674
   548
  also have "\<dots> = {x. x \<noteq> a}"
huffman@37674
   549
    unfolding Bex_def euclidean_eq [where 'a='a] by simp
huffman@37674
   550
  also have "\<dots> = UNIV - {a}" by auto
huffman@37674
   551
  finally show ?thesis .
huffman@37674
   552
qed
huffman@36583
   553
huffman@37674
   554
lemma path_connected_sphere:
huffman@37674
   555
  assumes "2 \<le> DIM('a::euclidean_space)"
huffman@37674
   556
  shows "path_connected {x::'a::euclidean_space. norm(x - a) = r}"
huffman@37674
   557
proof (rule linorder_cases [of r 0])
huffman@37674
   558
  assume "r < 0" hence "{x::'a. norm(x - a) = r} = {}" by auto
huffman@37674
   559
  thus ?thesis using path_connected_empty by simp
huffman@37674
   560
next
huffman@37674
   561
  assume "r = 0"
huffman@37674
   562
  thus ?thesis using path_connected_singleton by simp
huffman@37674
   563
next
huffman@37674
   564
  assume r: "0 < r"
nipkow@39302
   565
  hence *:"{x::'a. norm(x - a) = r} = (\<lambda>x. a + r *\<^sub>R x) ` {x. norm x = 1}" apply -apply(rule set_eqI,rule)
huffman@36583
   566
    unfolding image_iff apply(rule_tac x="(1/r) *\<^sub>R (x - a)" in bexI) unfolding mem_Collect_eq norm_scaleR by (auto simp add: scaleR_right_diff_distrib)
nipkow@39302
   567
  have **:"{x::'a. norm x = 1} = (\<lambda>x. (1/norm x) *\<^sub>R x) ` (UNIV - {0})" apply(rule set_eqI,rule)
huffman@36583
   568
    unfolding image_iff apply(rule_tac x=x in bexI) unfolding mem_Collect_eq by(auto split:split_if_asm)
huffman@37674
   569
  have "continuous_on (UNIV - {0}) (\<lambda>x::'a. 1 / norm x)" unfolding o_def continuous_on_eq_continuous_within
huffman@36583
   570
    apply(rule, rule continuous_at_within_inv[unfolded o_def inverse_eq_divide]) apply(rule continuous_at_within)
huffman@36583
   571
    apply(rule continuous_at_norm[unfolded o_def]) by auto
huffman@36583
   572
  thus ?thesis unfolding * ** using path_connected_punctured_universe[OF assms]
huffman@37674
   573
    by(auto intro!: path_connected_continuous_image continuous_on_intros)
huffman@37674
   574
qed
huffman@36583
   575
huffman@37674
   576
lemma connected_sphere: "2 \<le> DIM('a::euclidean_space) \<Longrightarrow> connected {x::'a. norm(x - a) = r}"
huffman@36583
   577
  using path_connected_sphere path_connected_imp_connected by auto
huffman@36583
   578
huffman@36583
   579
end