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