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