src/HOL/Analysis/Path_Connected.thy
author wenzelm
Tue Jan 17 13:59:10 2017 +0100 (2017-01-17)
changeset 64911 f0e07600de47
parent 64790 ed38f9a834d8
child 65038 9391ea7daa17
permissions -rw-r--r--
isabelle update_cartouches -c -t;
hoelzl@63627
     1
(*  Title:      HOL/Analysis/Path_Connected.thy
lp15@61806
     2
    Authors:    LC Paulson and Robert Himmelmann (TU Muenchen), based on material from HOL Light
huffman@36583
     3
*)
huffman@36583
     4
wenzelm@60420
     5
section \<open>Continuous paths and path-connected sets\<close>
huffman@36583
     6
huffman@36583
     7
theory Path_Connected
hoelzl@63970
     8
imports Continuous_Extension Continuum_Not_Denumerable
huffman@36583
     9
begin
huffman@36583
    10
wenzelm@60420
    11
subsection \<open>Paths and Arcs\<close>
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>
paulson@60303
    34
     path g \<and> (\<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
paulson@60303
    36
definition arc :: "(real \<Rightarrow> 'a :: topological_space) \<Rightarrow> bool"
paulson@60303
    37
  where "arc g \<longleftrightarrow> path g \<and> inj_on g {0..1}"
huffman@36583
    38
wenzelm@49653
    39
wenzelm@60420
    40
subsection\<open>Invariance theorems\<close>
paulson@60303
    41
paulson@60303
    42
lemma path_eq: "path p \<Longrightarrow> (\<And>t. t \<in> {0..1} \<Longrightarrow> p t = q t) \<Longrightarrow> path q"
paulson@60303
    43
  using continuous_on_eq path_def by blast
paulson@60303
    44
paulson@60303
    45
lemma path_continuous_image: "path g \<Longrightarrow> continuous_on (path_image g) f \<Longrightarrow> path(f o g)"
paulson@60303
    46
  unfolding path_def path_image_def
paulson@60303
    47
  using continuous_on_compose by blast
paulson@60303
    48
paulson@60303
    49
lemma path_translation_eq:
paulson@60303
    50
  fixes g :: "real \<Rightarrow> 'a :: real_normed_vector"
paulson@60303
    51
  shows "path((\<lambda>x. a + x) o g) = path g"
paulson@60303
    52
proof -
paulson@60303
    53
  have g: "g = (\<lambda>x. -a + x) o ((\<lambda>x. a + x) o g)"
paulson@60303
    54
    by (rule ext) simp
paulson@60303
    55
  show ?thesis
paulson@60303
    56
    unfolding path_def
paulson@60303
    57
    apply safe
paulson@60303
    58
    apply (subst g)
paulson@60303
    59
    apply (rule continuous_on_compose)
paulson@60303
    60
    apply (auto intro: continuous_intros)
paulson@60303
    61
    done
paulson@60303
    62
qed
paulson@60303
    63
paulson@60303
    64
lemma path_linear_image_eq:
paulson@60303
    65
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
paulson@60303
    66
   assumes "linear f" "inj f"
paulson@60303
    67
     shows "path(f o g) = path g"
paulson@60303
    68
proof -
paulson@60303
    69
  from linear_injective_left_inverse [OF assms]
paulson@60303
    70
  obtain h where h: "linear h" "h \<circ> f = id"
paulson@60303
    71
    by blast
paulson@60303
    72
  then have g: "g = h o (f o g)"
paulson@60303
    73
    by (metis comp_assoc id_comp)
paulson@60303
    74
  show ?thesis
paulson@60303
    75
    unfolding path_def
paulson@60303
    76
    using h assms
paulson@60303
    77
    by (metis g continuous_on_compose linear_continuous_on linear_conv_bounded_linear)
paulson@60303
    78
qed
paulson@60303
    79
paulson@60303
    80
lemma pathstart_translation: "pathstart((\<lambda>x. a + x) o g) = a + pathstart g"
paulson@60303
    81
  by (simp add: pathstart_def)
paulson@60303
    82
paulson@60303
    83
lemma pathstart_linear_image_eq: "linear f \<Longrightarrow> pathstart(f o g) = f(pathstart g)"
paulson@60303
    84
  by (simp add: pathstart_def)
paulson@60303
    85
paulson@60303
    86
lemma pathfinish_translation: "pathfinish((\<lambda>x. a + x) o g) = a + pathfinish g"
paulson@60303
    87
  by (simp add: pathfinish_def)
paulson@60303
    88
paulson@60303
    89
lemma pathfinish_linear_image: "linear f \<Longrightarrow> pathfinish(f o g) = f(pathfinish g)"
paulson@60303
    90
  by (simp add: pathfinish_def)
paulson@60303
    91
paulson@60303
    92
lemma path_image_translation: "path_image((\<lambda>x. a + x) o g) = (\<lambda>x. a + x) ` (path_image g)"
paulson@60303
    93
  by (simp add: image_comp path_image_def)
paulson@60303
    94
paulson@60303
    95
lemma path_image_linear_image: "linear f \<Longrightarrow> path_image(f o g) = f ` (path_image g)"
paulson@60303
    96
  by (simp add: image_comp path_image_def)
paulson@60303
    97
paulson@60303
    98
lemma reversepath_translation: "reversepath((\<lambda>x. a + x) o g) = (\<lambda>x. a + x) o reversepath g"
paulson@60303
    99
  by (rule ext) (simp add: reversepath_def)
huffman@36583
   100
paulson@60303
   101
lemma reversepath_linear_image: "linear f \<Longrightarrow> reversepath(f o g) = f o reversepath g"
paulson@60303
   102
  by (rule ext) (simp add: reversepath_def)
paulson@60303
   103
paulson@60303
   104
lemma joinpaths_translation:
paulson@60303
   105
    "((\<lambda>x. a + x) o g1) +++ ((\<lambda>x. a + x) o g2) = (\<lambda>x. a + x) o (g1 +++ g2)"
paulson@60303
   106
  by (rule ext) (simp add: joinpaths_def)
paulson@60303
   107
paulson@60303
   108
lemma joinpaths_linear_image: "linear f \<Longrightarrow> (f o g1) +++ (f o g2) = f o (g1 +++ g2)"
paulson@60303
   109
  by (rule ext) (simp add: joinpaths_def)
paulson@60303
   110
lp15@60809
   111
lemma simple_path_translation_eq:
paulson@60303
   112
  fixes g :: "real \<Rightarrow> 'a::euclidean_space"
paulson@60303
   113
  shows "simple_path((\<lambda>x. a + x) o g) = simple_path g"
paulson@60303
   114
  by (simp add: simple_path_def path_translation_eq)
paulson@60303
   115
paulson@60303
   116
lemma simple_path_linear_image_eq:
paulson@60303
   117
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
paulson@60303
   118
  assumes "linear f" "inj f"
paulson@60303
   119
    shows "simple_path(f o g) = simple_path g"
paulson@60303
   120
  using assms inj_on_eq_iff [of f]
paulson@60303
   121
  by (auto simp: path_linear_image_eq simple_path_def path_translation_eq)
paulson@60303
   122
paulson@60303
   123
lemma arc_translation_eq:
paulson@60303
   124
  fixes g :: "real \<Rightarrow> 'a::euclidean_space"
paulson@60303
   125
  shows "arc((\<lambda>x. a + x) o g) = arc g"
paulson@60303
   126
  by (auto simp: arc_def inj_on_def path_translation_eq)
paulson@60303
   127
paulson@60303
   128
lemma arc_linear_image_eq:
paulson@60303
   129
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
paulson@60303
   130
   assumes "linear f" "inj f"
paulson@60303
   131
     shows  "arc(f o g) = arc g"
paulson@60303
   132
  using assms inj_on_eq_iff [of f]
paulson@60303
   133
  by (auto simp: arc_def inj_on_def path_linear_image_eq)
paulson@60303
   134
wenzelm@60420
   135
subsection\<open>Basic lemmas about paths\<close>
paulson@60303
   136
lp15@64788
   137
lemma continuous_on_path: "path f \<Longrightarrow> t \<subseteq> {0..1} \<Longrightarrow> continuous_on t f"
lp15@64788
   138
  using continuous_on_subset path_def by blast
lp15@64788
   139
paulson@60303
   140
lemma arc_imp_simple_path: "arc g \<Longrightarrow> simple_path g"
paulson@60303
   141
  by (simp add: arc_def inj_on_def simple_path_def)
paulson@60303
   142
paulson@60303
   143
lemma arc_imp_path: "arc g \<Longrightarrow> path g"
paulson@60303
   144
  using arc_def by blast
paulson@60303
   145
lp15@64788
   146
lemma arc_imp_inj_on: "arc g \<Longrightarrow> inj_on g {0..1}"
lp15@64788
   147
  by (auto simp: arc_def)
lp15@64788
   148
paulson@60303
   149
lemma simple_path_imp_path: "simple_path g \<Longrightarrow> path g"
paulson@60303
   150
  using simple_path_def by blast
paulson@60303
   151
paulson@60303
   152
lemma simple_path_cases: "simple_path g \<Longrightarrow> arc g \<or> pathfinish g = pathstart g"
paulson@60303
   153
  unfolding simple_path_def arc_def inj_on_def pathfinish_def pathstart_def
paulson@60303
   154
  by (force)
paulson@60303
   155
paulson@60303
   156
lemma simple_path_imp_arc: "simple_path g \<Longrightarrow> pathfinish g \<noteq> pathstart g \<Longrightarrow> arc g"
paulson@60303
   157
  using simple_path_cases by auto
paulson@60303
   158
paulson@60303
   159
lemma arc_distinct_ends: "arc g \<Longrightarrow> pathfinish g \<noteq> pathstart g"
paulson@60303
   160
  unfolding arc_def inj_on_def pathfinish_def pathstart_def
paulson@60303
   161
  by fastforce
paulson@60303
   162
paulson@60303
   163
lemma arc_simple_path: "arc g \<longleftrightarrow> simple_path g \<and> pathfinish g \<noteq> pathstart g"
paulson@60303
   164
  using arc_distinct_ends arc_imp_simple_path simple_path_cases by blast
paulson@60303
   165
paulson@60303
   166
lemma simple_path_eq_arc: "pathfinish g \<noteq> pathstart g \<Longrightarrow> (simple_path g = arc g)"
paulson@60303
   167
  by (simp add: arc_simple_path)
huffman@36583
   168
lp15@60974
   169
lemma path_image_nonempty [simp]: "path_image g \<noteq> {}"
immler@56188
   170
  unfolding path_image_def image_is_empty box_eq_empty
wenzelm@53640
   171
  by auto
huffman@36583
   172
wenzelm@53640
   173
lemma pathstart_in_path_image[intro]: "pathstart g \<in> path_image g"
wenzelm@53640
   174
  unfolding pathstart_def path_image_def
wenzelm@53640
   175
  by auto
huffman@36583
   176
wenzelm@53640
   177
lemma pathfinish_in_path_image[intro]: "pathfinish g \<in> path_image g"
wenzelm@53640
   178
  unfolding pathfinish_def path_image_def
wenzelm@53640
   179
  by auto
wenzelm@53640
   180
wenzelm@53640
   181
lemma connected_path_image[intro]: "path g \<Longrightarrow> connected (path_image g)"
huffman@36583
   182
  unfolding path_def path_image_def
paulson@60303
   183
  using connected_continuous_image connected_Icc by blast
huffman@36583
   184
wenzelm@53640
   185
lemma compact_path_image[intro]: "path g \<Longrightarrow> compact (path_image g)"
huffman@36583
   186
  unfolding path_def path_image_def
paulson@60303
   187
  using compact_continuous_image connected_Icc by blast
huffman@36583
   188
wenzelm@53640
   189
lemma reversepath_reversepath[simp]: "reversepath (reversepath g) = g"
wenzelm@53640
   190
  unfolding reversepath_def
wenzelm@53640
   191
  by auto
huffman@36583
   192
wenzelm@53640
   193
lemma pathstart_reversepath[simp]: "pathstart (reversepath g) = pathfinish g"
wenzelm@53640
   194
  unfolding pathstart_def reversepath_def pathfinish_def
wenzelm@53640
   195
  by auto
huffman@36583
   196
wenzelm@53640
   197
lemma pathfinish_reversepath[simp]: "pathfinish (reversepath g) = pathstart g"
wenzelm@53640
   198
  unfolding pathstart_def reversepath_def pathfinish_def
wenzelm@53640
   199
  by auto
huffman@36583
   200
wenzelm@49653
   201
lemma pathstart_join[simp]: "pathstart (g1 +++ g2) = pathstart g1"
wenzelm@53640
   202
  unfolding pathstart_def joinpaths_def pathfinish_def
wenzelm@53640
   203
  by auto
huffman@36583
   204
wenzelm@49653
   205
lemma pathfinish_join[simp]: "pathfinish (g1 +++ g2) = pathfinish g2"
wenzelm@53640
   206
  unfolding pathstart_def joinpaths_def pathfinish_def
wenzelm@53640
   207
  by auto
huffman@36583
   208
wenzelm@53640
   209
lemma path_image_reversepath[simp]: "path_image (reversepath g) = path_image g"
wenzelm@49653
   210
proof -
wenzelm@53640
   211
  have *: "\<And>g. path_image (reversepath g) \<subseteq> path_image g"
wenzelm@49653
   212
    unfolding path_image_def subset_eq reversepath_def Ball_def image_iff
paulson@60303
   213
    by force
wenzelm@49653
   214
  show ?thesis
wenzelm@49653
   215
    using *[of g] *[of "reversepath g"]
wenzelm@53640
   216
    unfolding reversepath_reversepath
wenzelm@53640
   217
    by auto
wenzelm@49653
   218
qed
huffman@36583
   219
wenzelm@53640
   220
lemma path_reversepath [simp]: "path (reversepath g) \<longleftrightarrow> path g"
wenzelm@49653
   221
proof -
wenzelm@49653
   222
  have *: "\<And>g. path g \<Longrightarrow> path (reversepath g)"
wenzelm@49653
   223
    unfolding path_def reversepath_def
wenzelm@49653
   224
    apply (rule continuous_on_compose[unfolded o_def, of _ "\<lambda>x. 1 - x"])
hoelzl@56371
   225
    apply (intro continuous_intros)
wenzelm@53640
   226
    apply (rule continuous_on_subset[of "{0..1}"])
wenzelm@53640
   227
    apply assumption
wenzelm@49653
   228
    apply auto
wenzelm@49653
   229
    done
wenzelm@49653
   230
  show ?thesis
wenzelm@49653
   231
    using *[of "reversepath g"] *[of g]
wenzelm@49653
   232
    unfolding reversepath_reversepath
wenzelm@49653
   233
    by (rule iffI)
wenzelm@49653
   234
qed
wenzelm@49653
   235
paulson@60303
   236
lemma arc_reversepath:
paulson@60303
   237
  assumes "arc g" shows "arc(reversepath g)"
paulson@60303
   238
proof -
paulson@60303
   239
  have injg: "inj_on g {0..1}"
paulson@60303
   240
    using assms
paulson@60303
   241
    by (simp add: arc_def)
paulson@60303
   242
  have **: "\<And>x y::real. 1-x = 1-y \<Longrightarrow> x = y"
paulson@60303
   243
    by simp
paulson@60303
   244
  show ?thesis
paulson@60303
   245
    apply (auto simp: arc_def inj_on_def path_reversepath)
paulson@60303
   246
    apply (simp add: arc_imp_path assms)
paulson@60303
   247
    apply (rule **)
paulson@60303
   248
    apply (rule inj_onD [OF injg])
paulson@60303
   249
    apply (auto simp: reversepath_def)
paulson@60303
   250
    done
paulson@60303
   251
qed
paulson@60303
   252
paulson@60303
   253
lemma simple_path_reversepath: "simple_path g \<Longrightarrow> simple_path (reversepath g)"
paulson@60303
   254
  apply (simp add: simple_path_def)
paulson@60303
   255
  apply (force simp: reversepath_def)
paulson@60303
   256
  done
paulson@60303
   257
wenzelm@49653
   258
lemmas reversepath_simps =
wenzelm@49653
   259
  path_reversepath path_image_reversepath pathstart_reversepath pathfinish_reversepath
huffman@36583
   260
wenzelm@49653
   261
lemma path_join[simp]:
wenzelm@49653
   262
  assumes "pathfinish g1 = pathstart g2"
wenzelm@49653
   263
  shows "path (g1 +++ g2) \<longleftrightarrow> path g1 \<and> path g2"
wenzelm@49653
   264
  unfolding path_def pathfinish_def pathstart_def
hoelzl@51478
   265
proof safe
hoelzl@51478
   266
  assume cont: "continuous_on {0..1} (g1 +++ g2)"
hoelzl@51478
   267
  have g1: "continuous_on {0..1} g1 \<longleftrightarrow> continuous_on {0..1} ((g1 +++ g2) \<circ> (\<lambda>x. x / 2))"
hoelzl@51478
   268
    by (intro continuous_on_cong refl) (auto simp: joinpaths_def)
hoelzl@51478
   269
  have g2: "continuous_on {0..1} g2 \<longleftrightarrow> continuous_on {0..1} ((g1 +++ g2) \<circ> (\<lambda>x. x / 2 + 1/2))"
wenzelm@53640
   270
    using assms
wenzelm@53640
   271
    by (intro continuous_on_cong refl) (auto simp: joinpaths_def pathfinish_def pathstart_def)
wenzelm@53640
   272
  show "continuous_on {0..1} g1" and "continuous_on {0..1} g2"
hoelzl@51481
   273
    unfolding g1 g2
hoelzl@56371
   274
    by (auto intro!: continuous_intros continuous_on_subset[OF cont] simp del: o_apply)
hoelzl@51478
   275
next
hoelzl@51478
   276
  assume g1g2: "continuous_on {0..1} g1" "continuous_on {0..1} g2"
hoelzl@51478
   277
  have 01: "{0 .. 1} = {0..1/2} \<union> {1/2 .. 1::real}"
huffman@36583
   278
    by auto
wenzelm@53640
   279
  {
wenzelm@53640
   280
    fix x :: real
wenzelm@53640
   281
    assume "0 \<le> x" and "x \<le> 1"
wenzelm@53640
   282
    then have "x \<in> (\<lambda>x. x * 2) ` {0..1 / 2}"
wenzelm@53640
   283
      by (intro image_eqI[where x="x/2"]) auto
wenzelm@53640
   284
  }
hoelzl@51478
   285
  note 1 = this
wenzelm@53640
   286
  {
wenzelm@53640
   287
    fix x :: real
wenzelm@53640
   288
    assume "0 \<le> x" and "x \<le> 1"
wenzelm@53640
   289
    then have "x \<in> (\<lambda>x. x * 2 - 1) ` {1 / 2..1}"
wenzelm@53640
   290
      by (intro image_eqI[where x="x/2 + 1/2"]) auto
wenzelm@53640
   291
  }
hoelzl@51478
   292
  note 2 = this
wenzelm@49653
   293
  show "continuous_on {0..1} (g1 +++ g2)"
wenzelm@53640
   294
    using assms
wenzelm@53640
   295
    unfolding joinpaths_def 01
hoelzl@56371
   296
    apply (intro continuous_on_cases closed_atLeastAtMost g1g2[THEN continuous_on_compose2] continuous_intros)
wenzelm@53640
   297
    apply (auto simp: field_simps pathfinish_def pathstart_def intro!: 1 2)
wenzelm@53640
   298
    done
wenzelm@49653
   299
qed
huffman@36583
   300
wenzelm@60420
   301
section \<open>Path Images\<close>
paulson@60303
   302
paulson@60303
   303
lemma bounded_path_image: "path g \<Longrightarrow> bounded(path_image g)"
paulson@60303
   304
  by (simp add: compact_imp_bounded compact_path_image)
paulson@60303
   305
lp15@60809
   306
lemma closed_path_image:
paulson@60303
   307
  fixes g :: "real \<Rightarrow> 'a::t2_space"
paulson@60303
   308
  shows "path g \<Longrightarrow> closed(path_image g)"
paulson@60303
   309
  by (metis compact_path_image compact_imp_closed)
paulson@60303
   310
paulson@60303
   311
lemma connected_simple_path_image: "simple_path g \<Longrightarrow> connected(path_image g)"
paulson@60303
   312
  by (metis connected_path_image simple_path_imp_path)
paulson@60303
   313
paulson@60303
   314
lemma compact_simple_path_image: "simple_path g \<Longrightarrow> compact(path_image g)"
paulson@60303
   315
  by (metis compact_path_image simple_path_imp_path)
paulson@60303
   316
paulson@60303
   317
lemma bounded_simple_path_image: "simple_path g \<Longrightarrow> bounded(path_image g)"
paulson@60303
   318
  by (metis bounded_path_image simple_path_imp_path)
paulson@60303
   319
paulson@60303
   320
lemma closed_simple_path_image:
paulson@60303
   321
  fixes g :: "real \<Rightarrow> 'a::t2_space"
paulson@60303
   322
  shows "simple_path g \<Longrightarrow> closed(path_image g)"
paulson@60303
   323
  by (metis closed_path_image simple_path_imp_path)
paulson@60303
   324
paulson@60303
   325
lemma connected_arc_image: "arc g \<Longrightarrow> connected(path_image g)"
paulson@60303
   326
  by (metis connected_path_image arc_imp_path)
paulson@60303
   327
paulson@60303
   328
lemma compact_arc_image: "arc g \<Longrightarrow> compact(path_image g)"
paulson@60303
   329
  by (metis compact_path_image arc_imp_path)
paulson@60303
   330
paulson@60303
   331
lemma bounded_arc_image: "arc g \<Longrightarrow> bounded(path_image g)"
paulson@60303
   332
  by (metis bounded_path_image arc_imp_path)
paulson@60303
   333
paulson@60303
   334
lemma closed_arc_image:
paulson@60303
   335
  fixes g :: "real \<Rightarrow> 'a::t2_space"
paulson@60303
   336
  shows "arc g \<Longrightarrow> closed(path_image g)"
paulson@60303
   337
  by (metis closed_path_image arc_imp_path)
paulson@60303
   338
wenzelm@53640
   339
lemma path_image_join_subset: "path_image (g1 +++ g2) \<subseteq> path_image g1 \<union> path_image g2"
wenzelm@53640
   340
  unfolding path_image_def joinpaths_def
wenzelm@53640
   341
  by auto
huffman@36583
   342
huffman@36583
   343
lemma subset_path_image_join:
wenzelm@53640
   344
  assumes "path_image g1 \<subseteq> s"
wenzelm@53640
   345
    and "path_image g2 \<subseteq> s"
wenzelm@53640
   346
  shows "path_image (g1 +++ g2) \<subseteq> s"
wenzelm@53640
   347
  using path_image_join_subset[of g1 g2] and assms
wenzelm@53640
   348
  by auto
huffman@36583
   349
huffman@36583
   350
lemma path_image_join:
paulson@60303
   351
    "pathfinish g1 = pathstart g2 \<Longrightarrow> path_image(g1 +++ g2) = path_image g1 \<union> path_image g2"
paulson@60303
   352
  apply (rule subset_antisym [OF path_image_join_subset])
paulson@60303
   353
  apply (auto simp: pathfinish_def pathstart_def path_image_def joinpaths_def image_def)
paulson@60303
   354
  apply (drule sym)
paulson@60303
   355
  apply (rule_tac x="xa/2" in bexI, auto)
paulson@60303
   356
  apply (rule ccontr)
paulson@60303
   357
  apply (drule_tac x="(xa+1)/2" in bspec)
paulson@60303
   358
  apply (auto simp: field_simps)
paulson@60303
   359
  apply (drule_tac x="1/2" in bspec, auto)
paulson@60303
   360
  done
huffman@36583
   361
huffman@36583
   362
lemma not_in_path_image_join:
wenzelm@53640
   363
  assumes "x \<notin> path_image g1"
wenzelm@53640
   364
    and "x \<notin> path_image g2"
wenzelm@53640
   365
  shows "x \<notin> path_image (g1 +++ g2)"
wenzelm@53640
   366
  using assms and path_image_join_subset[of g1 g2]
wenzelm@53640
   367
  by auto
huffman@36583
   368
paulson@60303
   369
lemma pathstart_compose: "pathstart(f o p) = f(pathstart p)"
paulson@60303
   370
  by (simp add: pathstart_def)
paulson@60303
   371
paulson@60303
   372
lemma pathfinish_compose: "pathfinish(f o p) = f(pathfinish p)"
paulson@60303
   373
  by (simp add: pathfinish_def)
paulson@60303
   374
paulson@60303
   375
lemma path_image_compose: "path_image (f o p) = f ` (path_image p)"
paulson@60303
   376
  by (simp add: image_comp path_image_def)
paulson@60303
   377
paulson@60303
   378
lemma path_compose_join: "f o (p +++ q) = (f o p) +++ (f o q)"
paulson@60303
   379
  by (rule ext) (simp add: joinpaths_def)
paulson@60303
   380
paulson@60303
   381
lemma path_compose_reversepath: "f o reversepath p = reversepath(f o p)"
paulson@60303
   382
  by (rule ext) (simp add: reversepath_def)
paulson@60303
   383
lp15@61762
   384
lemma joinpaths_eq:
paulson@60303
   385
  "(\<And>t. t \<in> {0..1} \<Longrightarrow> p t = p' t) \<Longrightarrow>
paulson@60303
   386
   (\<And>t. t \<in> {0..1} \<Longrightarrow> q t = q' t)
paulson@60303
   387
   \<Longrightarrow>  t \<in> {0..1} \<Longrightarrow> (p +++ q) t = (p' +++ q') t"
paulson@60303
   388
  by (auto simp: joinpaths_def)
paulson@60303
   389
paulson@60303
   390
lemma simple_path_inj_on: "simple_path g \<Longrightarrow> inj_on g {0<..<1}"
paulson@60303
   391
  by (auto simp: simple_path_def path_image_def inj_on_def less_eq_real_def Ball_def)
paulson@60303
   392
paulson@60303
   393
wenzelm@60420
   394
subsection\<open>Simple paths with the endpoints removed\<close>
paulson@60303
   395
paulson@60303
   396
lemma simple_path_endless:
paulson@60303
   397
    "simple_path c \<Longrightarrow> path_image c - {pathstart c,pathfinish c} = c ` {0<..<1}"
paulson@60303
   398
  apply (auto simp: simple_path_def path_image_def pathstart_def pathfinish_def Ball_def Bex_def image_def)
paulson@60303
   399
  apply (metis eq_iff le_less_linear)
paulson@60303
   400
  apply (metis leD linear)
paulson@60303
   401
  using less_eq_real_def zero_le_one apply blast
paulson@60303
   402
  using less_eq_real_def zero_le_one apply blast
wenzelm@49653
   403
  done
huffman@36583
   404
paulson@60303
   405
lemma connected_simple_path_endless:
paulson@60303
   406
    "simple_path c \<Longrightarrow> connected(path_image c - {pathstart c,pathfinish c})"
paulson@60303
   407
apply (simp add: simple_path_endless)
paulson@60303
   408
apply (rule connected_continuous_image)
paulson@60303
   409
apply (meson continuous_on_subset greaterThanLessThan_subseteq_atLeastAtMost_iff le_numeral_extra(3) le_numeral_extra(4) path_def simple_path_imp_path)
paulson@60303
   410
by auto
paulson@60303
   411
paulson@60303
   412
lemma nonempty_simple_path_endless:
paulson@60303
   413
    "simple_path c \<Longrightarrow> path_image c - {pathstart c,pathfinish c} \<noteq> {}"
paulson@60303
   414
  by (simp add: simple_path_endless)
paulson@60303
   415
paulson@60303
   416
wenzelm@60420
   417
subsection\<open>The operations on paths\<close>
paulson@60303
   418
paulson@60303
   419
lemma path_image_subset_reversepath: "path_image(reversepath g) \<le> path_image g"
paulson@60303
   420
  by (auto simp: path_image_def reversepath_def)
paulson@60303
   421
paulson@60303
   422
lemma path_imp_reversepath: "path g \<Longrightarrow> path(reversepath g)"
paulson@60303
   423
  apply (auto simp: path_def reversepath_def)
paulson@60303
   424
  using continuous_on_compose [of "{0..1}" "\<lambda>x. 1 - x" g]
paulson@60303
   425
  apply (auto simp: continuous_on_op_minus)
paulson@60303
   426
  done
paulson@60303
   427
paulson@61204
   428
lemma half_bounded_equal: "1 \<le> x * 2 \<Longrightarrow> x * 2 \<le> 1 \<longleftrightarrow> x = (1/2::real)"
paulson@61204
   429
  by simp
paulson@60303
   430
paulson@60303
   431
lemma continuous_on_joinpaths:
paulson@60303
   432
  assumes "continuous_on {0..1} g1" "continuous_on {0..1} g2" "pathfinish g1 = pathstart g2"
paulson@60303
   433
    shows "continuous_on {0..1} (g1 +++ g2)"
paulson@60303
   434
proof -
paulson@60303
   435
  have *: "{0..1::real} = {0..1/2} \<union> {1/2..1}"
paulson@60303
   436
    by auto
paulson@60303
   437
  have gg: "g2 0 = g1 1"
paulson@60303
   438
    by (metis assms(3) pathfinish_def pathstart_def)
paulson@61204
   439
  have 1: "continuous_on {0..1/2} (g1 +++ g2)"
paulson@60303
   440
    apply (rule continuous_on_eq [of _ "g1 o (\<lambda>x. 2*x)"])
paulson@61204
   441
    apply (rule continuous_intros | simp add: joinpaths_def assms)+
paulson@60303
   442
    done
paulson@61204
   443
  have "continuous_on {1/2..1} (g2 o (\<lambda>x. 2*x-1))"
paulson@61204
   444
    apply (rule continuous_on_subset [of "{1/2..1}"])
paulson@61204
   445
    apply (rule continuous_intros | simp add: image_affinity_atLeastAtMost_diff assms)+
paulson@61204
   446
    done
paulson@61204
   447
  then have 2: "continuous_on {1/2..1} (g1 +++ g2)"
paulson@61204
   448
    apply (rule continuous_on_eq [of "{1/2..1}" "g2 o (\<lambda>x. 2*x-1)"])
paulson@61204
   449
    apply (rule assms continuous_intros | simp add: joinpaths_def mult.commute half_bounded_equal gg)+
paulson@60303
   450
    done
paulson@60303
   451
  show ?thesis
paulson@60303
   452
    apply (subst *)
lp15@62397
   453
    apply (rule continuous_on_closed_Un)
paulson@60303
   454
    using 1 2
paulson@60303
   455
    apply auto
paulson@60303
   456
    done
paulson@60303
   457
qed
paulson@60303
   458
paulson@60303
   459
lemma path_join_imp: "\<lbrakk>path g1; path g2; pathfinish g1 = pathstart g2\<rbrakk> \<Longrightarrow> path(g1 +++ g2)"
paulson@60303
   460
  by (simp add: path_join)
paulson@60303
   461
huffman@36583
   462
lemma simple_path_join_loop:
lp15@60809
   463
  assumes "arc g1" "arc g2"
lp15@60809
   464
          "pathfinish g1 = pathstart g2"  "pathfinish g2 = pathstart g1"
paulson@60303
   465
          "path_image g1 \<inter> path_image g2 \<subseteq> {pathstart g1, pathstart g2}"
paulson@60303
   466
  shows "simple_path(g1 +++ g2)"
paulson@60303
   467
proof -
paulson@60303
   468
  have injg1: "inj_on g1 {0..1}"
paulson@60303
   469
    using assms
paulson@60303
   470
    by (simp add: arc_def)
paulson@60303
   471
  have injg2: "inj_on g2 {0..1}"
paulson@60303
   472
    using assms
paulson@60303
   473
    by (simp add: arc_def)
lp15@60809
   474
  have g12: "g1 1 = g2 0"
lp15@60809
   475
   and g21: "g2 1 = g1 0"
paulson@60303
   476
   and sb:  "g1 ` {0..1} \<inter> g2 ` {0..1} \<subseteq> {g1 0, g2 0}"
paulson@60303
   477
    using assms
paulson@60303
   478
    by (simp_all add: arc_def pathfinish_def pathstart_def path_image_def)
paulson@60303
   479
  { fix x and y::real
lp15@60809
   480
    assume xyI: "x = 1 \<longrightarrow> y \<noteq> 0"
paulson@60303
   481
       and xy: "x \<le> 1" "0 \<le> y" " y * 2 \<le> 1" "\<not> x * 2 \<le> 1" "g2 (2 * x - 1) = g1 (2 * y)"
paulson@60303
   482
    have g1im: "g1 (2 * y) \<in> g1 ` {0..1} \<inter> g2 ` {0..1}"
paulson@60303
   483
      using xy
paulson@60303
   484
      apply simp
paulson@60303
   485
      apply (rule_tac x="2 * x - 1" in image_eqI, auto)
paulson@60303
   486
      done
paulson@60303
   487
    have False
lp15@60809
   488
      using subsetD [OF sb g1im] xy
paulson@60303
   489
      apply auto
paulson@60303
   490
      apply (drule inj_onD [OF injg1])
paulson@60303
   491
      using g21 [symmetric] xyI
paulson@60303
   492
      apply (auto dest: inj_onD [OF injg2])
paulson@60303
   493
      done
paulson@60303
   494
   } note * = this
paulson@60303
   495
  { fix x and y::real
paulson@60303
   496
    assume xy: "y \<le> 1" "0 \<le> x" "\<not> y * 2 \<le> 1" "x * 2 \<le> 1" "g1 (2 * x) = g2 (2 * y - 1)"
paulson@60303
   497
    have g1im: "g1 (2 * x) \<in> g1 ` {0..1} \<inter> g2 ` {0..1}"
paulson@60303
   498
      using xy
paulson@60303
   499
      apply simp
paulson@60303
   500
      apply (rule_tac x="2 * x" in image_eqI, auto)
paulson@60303
   501
      done
paulson@60303
   502
    have "x = 0 \<and> y = 1"
lp15@60809
   503
      using subsetD [OF sb g1im] xy
paulson@60303
   504
      apply auto
paulson@60303
   505
      apply (force dest: inj_onD [OF injg1])
paulson@60303
   506
      using  g21 [symmetric]
paulson@60303
   507
      apply (auto dest: inj_onD [OF injg2])
paulson@60303
   508
      done
paulson@60303
   509
   } note ** = this
paulson@60303
   510
  show ?thesis
paulson@60303
   511
    using assms
paulson@60303
   512
    apply (simp add: arc_def simple_path_def path_join, clarify)
nipkow@62390
   513
    apply (simp add: joinpaths_def split: if_split_asm)
paulson@60303
   514
    apply (force dest: inj_onD [OF injg1])
paulson@60303
   515
    apply (metis *)
paulson@60303
   516
    apply (metis **)
paulson@60303
   517
    apply (force dest: inj_onD [OF injg2])
paulson@60303
   518
    done
paulson@60303
   519
qed
paulson@60303
   520
paulson@60303
   521
lemma arc_join:
lp15@60809
   522
  assumes "arc g1" "arc g2"
paulson@60303
   523
          "pathfinish g1 = pathstart g2"
paulson@60303
   524
          "path_image g1 \<inter> path_image g2 \<subseteq> {pathstart g2}"
paulson@60303
   525
    shows "arc(g1 +++ g2)"
paulson@60303
   526
proof -
paulson@60303
   527
  have injg1: "inj_on g1 {0..1}"
paulson@60303
   528
    using assms
paulson@60303
   529
    by (simp add: arc_def)
paulson@60303
   530
  have injg2: "inj_on g2 {0..1}"
paulson@60303
   531
    using assms
paulson@60303
   532
    by (simp add: arc_def)
paulson@60303
   533
  have g11: "g1 1 = g2 0"
paulson@60303
   534
   and sb:  "g1 ` {0..1} \<inter> g2 ` {0..1} \<subseteq> {g2 0}"
paulson@60303
   535
    using assms
paulson@60303
   536
    by (simp_all add: arc_def pathfinish_def pathstart_def path_image_def)
paulson@60303
   537
  { fix x and y::real
lp15@60809
   538
    assume xy: "x \<le> 1" "0 \<le> y" " y * 2 \<le> 1" "\<not> x * 2 \<le> 1" "g2 (2 * x - 1) = g1 (2 * y)"
paulson@60303
   539
    have g1im: "g1 (2 * y) \<in> g1 ` {0..1} \<inter> g2 ` {0..1}"
paulson@60303
   540
      using xy
paulson@60303
   541
      apply simp
paulson@60303
   542
      apply (rule_tac x="2 * x - 1" in image_eqI, auto)
paulson@60303
   543
      done
paulson@60303
   544
    have False
lp15@60809
   545
      using subsetD [OF sb g1im] xy
paulson@60303
   546
      by (auto dest: inj_onD [OF injg2])
paulson@60303
   547
   } note * = this
paulson@60303
   548
  show ?thesis
paulson@60303
   549
    apply (simp add: arc_def inj_on_def)
paulson@60303
   550
    apply (clarsimp simp add: arc_imp_path assms path_join)
nipkow@62390
   551
    apply (simp add: joinpaths_def split: if_split_asm)
paulson@60303
   552
    apply (force dest: inj_onD [OF injg1])
paulson@60303
   553
    apply (metis *)
paulson@60303
   554
    apply (metis *)
paulson@60303
   555
    apply (force dest: inj_onD [OF injg2])
paulson@60303
   556
    done
paulson@60303
   557
qed
paulson@60303
   558
paulson@60303
   559
lemma reversepath_joinpaths:
paulson@60303
   560
    "pathfinish g1 = pathstart g2 \<Longrightarrow> reversepath(g1 +++ g2) = reversepath g2 +++ reversepath g1"
paulson@60303
   561
  unfolding reversepath_def pathfinish_def pathstart_def joinpaths_def
paulson@60303
   562
  by (rule ext) (auto simp: mult.commute)
paulson@60303
   563
paulson@60303
   564
lp15@62533
   565
subsection\<open>Some reversed and "if and only if" versions of joining theorems\<close>
lp15@62533
   566
hoelzl@63594
   567
lemma path_join_path_ends:
lp15@62533
   568
  fixes g1 :: "real \<Rightarrow> 'a::metric_space"
hoelzl@63594
   569
  assumes "path(g1 +++ g2)" "path g2"
lp15@62533
   570
    shows "pathfinish g1 = pathstart g2"
lp15@62533
   571
proof (rule ccontr)
wenzelm@63040
   572
  define e where "e = dist (g1 1) (g2 0)"
lp15@62533
   573
  assume Neg: "pathfinish g1 \<noteq> pathstart g2"
lp15@62533
   574
  then have "0 < dist (pathfinish g1) (pathstart g2)"
lp15@62533
   575
    by auto
lp15@62533
   576
  then have "e > 0"
hoelzl@63594
   577
    by (metis e_def pathfinish_def pathstart_def)
hoelzl@63594
   578
  then obtain d1 where "d1 > 0"
lp15@62533
   579
       and d1: "\<And>x'. \<lbrakk>x'\<in>{0..1}; norm x' < d1\<rbrakk> \<Longrightarrow> dist (g2 x') (g2 0) < e/2"
lp15@62533
   580
    using assms(2) unfolding path_def continuous_on_iff
lp15@62533
   581
    apply (drule_tac x=0 in bspec, simp)
lp15@62533
   582
    by (metis half_gt_zero_iff norm_conv_dist)
hoelzl@63594
   583
  obtain d2 where "d2 > 0"
hoelzl@63594
   584
       and d2: "\<And>x'. \<lbrakk>x'\<in>{0..1}; dist x' (1/2) < d2\<rbrakk>
lp15@62533
   585
                      \<Longrightarrow> dist ((g1 +++ g2) x') (g1 1) < e/2"
lp15@62533
   586
    using assms(1) \<open>e > 0\<close> unfolding path_def continuous_on_iff
lp15@62533
   587
    apply (drule_tac x="1/2" in bspec, simp)
lp15@62533
   588
    apply (drule_tac x="e/2" in spec)
lp15@62533
   589
    apply (force simp: joinpaths_def)
lp15@62533
   590
    done
lp15@62533
   591
  have int01_1: "min (1/2) (min d1 d2) / 2 \<in> {0..1}"
lp15@62533
   592
    using \<open>d1 > 0\<close> \<open>d2 > 0\<close> by (simp add: min_def)
lp15@62533
   593
  have dist1: "norm (min (1 / 2) (min d1 d2) / 2) < d1"
lp15@62533
   594
    using \<open>d1 > 0\<close> \<open>d2 > 0\<close> by (simp add: min_def dist_norm)
lp15@62533
   595
  have int01_2: "1/2 + min (1/2) (min d1 d2) / 4 \<in> {0..1}"
lp15@62533
   596
    using \<open>d1 > 0\<close> \<open>d2 > 0\<close> by (simp add: min_def)
lp15@62533
   597
  have dist2: "dist (1 / 2 + min (1 / 2) (min d1 d2) / 4) (1 / 2) < d2"
lp15@62533
   598
    using \<open>d1 > 0\<close> \<open>d2 > 0\<close> by (simp add: min_def dist_norm)
lp15@62533
   599
  have [simp]: "~ min (1 / 2) (min d1 d2) \<le> 0"
lp15@62533
   600
    using \<open>d1 > 0\<close> \<open>d2 > 0\<close> by (simp add: min_def)
lp15@62533
   601
  have "dist (g2 (min (1 / 2) (min d1 d2) / 2)) (g1 1) < e/2"
lp15@62533
   602
       "dist (g2 (min (1 / 2) (min d1 d2) / 2)) (g2 0) < e/2"
lp15@62533
   603
    using d1 [OF int01_1 dist1] d2 [OF int01_2 dist2] by (simp_all add: joinpaths_def)
lp15@62533
   604
  then have "dist (g1 1) (g2 0) < e/2 + e/2"
lp15@62533
   605
    using dist_triangle_half_r e_def by blast
hoelzl@63594
   606
  then show False
lp15@62533
   607
    by (simp add: e_def [symmetric])
lp15@62533
   608
qed
lp15@62533
   609
hoelzl@63594
   610
lemma path_join_eq [simp]:
lp15@62533
   611
  fixes g1 :: "real \<Rightarrow> 'a::metric_space"
lp15@62533
   612
  assumes "path g1" "path g2"
lp15@62533
   613
    shows "path(g1 +++ g2) \<longleftrightarrow> pathfinish g1 = pathstart g2"
lp15@62533
   614
  using assms by (metis path_join_path_ends path_join_imp)
lp15@62533
   615
hoelzl@63594
   616
lemma simple_path_joinE:
lp15@62533
   617
  assumes "simple_path(g1 +++ g2)" and "pathfinish g1 = pathstart g2"
hoelzl@63594
   618
  obtains "arc g1" "arc g2"
lp15@62533
   619
          "path_image g1 \<inter> path_image g2 \<subseteq> {pathstart g1, pathstart g2}"
lp15@62533
   620
proof -
hoelzl@63594
   621
  have *: "\<And>x y. \<lbrakk>0 \<le> x; x \<le> 1; 0 \<le> y; y \<le> 1; (g1 +++ g2) x = (g1 +++ g2) y\<rbrakk>
lp15@62533
   622
               \<Longrightarrow> x = y \<or> x = 0 \<and> y = 1 \<or> x = 1 \<and> y = 0"
lp15@62533
   623
    using assms by (simp add: simple_path_def)
hoelzl@63594
   624
  have "path g1"
lp15@62533
   625
    using assms path_join simple_path_imp_path by blast
lp15@62533
   626
  moreover have "inj_on g1 {0..1}"
lp15@62533
   627
  proof (clarsimp simp: inj_on_def)
lp15@62533
   628
    fix x y
lp15@62533
   629
    assume "g1 x = g1 y" "0 \<le> x" "x \<le> 1" "0 \<le> y" "y \<le> 1"
lp15@62533
   630
    then show "x = y"
lp15@62533
   631
      using * [of "x/2" "y/2"] by (simp add: joinpaths_def split_ifs)
lp15@62533
   632
  qed
lp15@62533
   633
  ultimately have "arc g1"
lp15@62533
   634
    using assms  by (simp add: arc_def)
lp15@62533
   635
  have [simp]: "g2 0 = g1 1"
hoelzl@63594
   636
    using assms by (metis pathfinish_def pathstart_def)
lp15@62533
   637
  have "path g2"
lp15@62533
   638
    using assms path_join simple_path_imp_path by blast
lp15@62533
   639
  moreover have "inj_on g2 {0..1}"
lp15@62533
   640
  proof (clarsimp simp: inj_on_def)
lp15@62533
   641
    fix x y
lp15@62533
   642
    assume "g2 x = g2 y" "0 \<le> x" "x \<le> 1" "0 \<le> y" "y \<le> 1"
lp15@62533
   643
    then show "x = y"
lp15@62533
   644
      using * [of "(x + 1) / 2" "(y + 1) / 2"]
lp15@62533
   645
      by (force simp: joinpaths_def split_ifs divide_simps)
lp15@62533
   646
  qed
lp15@62533
   647
  ultimately have "arc g2"
lp15@62533
   648
    using assms  by (simp add: arc_def)
hoelzl@63594
   649
  have "g2 y = g1 0 \<or> g2 y = g1 1"
lp15@62533
   650
       if "g1 x = g2 y" "0 \<le> x" "x \<le> 1" "0 \<le> y" "y \<le> 1" for x y
lp15@62533
   651
      using * [of "x / 2" "(y + 1) / 2"] that
lp15@62533
   652
      by (auto simp: joinpaths_def split_ifs divide_simps)
lp15@62533
   653
  then have "path_image g1 \<inter> path_image g2 \<subseteq> {pathstart g1, pathstart g2}"
lp15@62533
   654
    by (fastforce simp: pathstart_def pathfinish_def path_image_def)
lp15@62533
   655
  with \<open>arc g1\<close> \<open>arc g2\<close> show ?thesis using that by blast
lp15@62533
   656
qed
lp15@62533
   657
lp15@62533
   658
lemma simple_path_join_loop_eq:
hoelzl@63594
   659
  assumes "pathfinish g2 = pathstart g1" "pathfinish g1 = pathstart g2"
lp15@62533
   660
    shows "simple_path(g1 +++ g2) \<longleftrightarrow>
lp15@62533
   661
             arc g1 \<and> arc g2 \<and> path_image g1 \<inter> path_image g2 \<subseteq> {pathstart g1, pathstart g2}"
lp15@62533
   662
by (metis assms simple_path_joinE simple_path_join_loop)
lp15@62533
   663
lp15@62533
   664
lemma arc_join_eq:
hoelzl@63594
   665
  assumes "pathfinish g1 = pathstart g2"
lp15@62533
   666
    shows "arc(g1 +++ g2) \<longleftrightarrow>
lp15@62533
   667
           arc g1 \<and> arc g2 \<and> path_image g1 \<inter> path_image g2 \<subseteq> {pathstart g2}"
lp15@62533
   668
           (is "?lhs = ?rhs")
hoelzl@63594
   669
proof
lp15@62533
   670
  assume ?lhs
lp15@62533
   671
  then have "simple_path(g1 +++ g2)" by (rule arc_imp_simple_path)
hoelzl@63594
   672
  then have *: "\<And>x y. \<lbrakk>0 \<le> x; x \<le> 1; 0 \<le> y; y \<le> 1; (g1 +++ g2) x = (g1 +++ g2) y\<rbrakk>
lp15@62533
   673
               \<Longrightarrow> x = y \<or> x = 0 \<and> y = 1 \<or> x = 1 \<and> y = 0"
lp15@62533
   674
    using assms by (simp add: simple_path_def)
lp15@62533
   675
  have False if "g1 0 = g2 u" "0 \<le> u" "u \<le> 1" for u
lp15@62533
   676
    using * [of 0 "(u + 1) / 2"] that assms arc_distinct_ends [OF \<open>?lhs\<close>]
lp15@62533
   677
    by (auto simp: joinpaths_def pathstart_def pathfinish_def split_ifs divide_simps)
lp15@62533
   678
  then have n1: "~ (pathstart g1 \<in> path_image g2)"
lp15@62533
   679
    unfolding pathstart_def path_image_def
lp15@62533
   680
    using atLeastAtMost_iff by blast
lp15@62533
   681
  show ?rhs using \<open>?lhs\<close>
lp15@62533
   682
    apply (rule simple_path_joinE [OF arc_imp_simple_path assms])
lp15@62533
   683
    using n1 by force
lp15@62533
   684
next
lp15@62533
   685
  assume ?rhs then show ?lhs
lp15@62533
   686
    using assms
lp15@62533
   687
    by (fastforce simp: pathfinish_def pathstart_def intro!: arc_join)
lp15@62533
   688
qed
lp15@62533
   689
hoelzl@63594
   690
lemma arc_join_eq_alt:
lp15@62533
   691
        "pathfinish g1 = pathstart g2
lp15@62533
   692
        \<Longrightarrow> (arc(g1 +++ g2) \<longleftrightarrow>
lp15@62533
   693
             arc g1 \<and> arc g2 \<and>
lp15@62533
   694
             path_image g1 \<inter> path_image g2 = {pathstart g2})"
lp15@62533
   695
using pathfinish_in_path_image by (fastforce simp: arc_join_eq)
lp15@62533
   696
lp15@62533
   697
lp15@62533
   698
subsection\<open>The joining of paths is associative\<close>
lp15@62533
   699
lp15@62533
   700
lemma path_assoc:
lp15@62533
   701
    "\<lbrakk>pathfinish p = pathstart q; pathfinish q = pathstart r\<rbrakk>
lp15@62533
   702
     \<Longrightarrow> path(p +++ (q +++ r)) \<longleftrightarrow> path((p +++ q) +++ r)"
lp15@62533
   703
by simp
lp15@62533
   704
hoelzl@63594
   705
lemma simple_path_assoc:
hoelzl@63594
   706
  assumes "pathfinish p = pathstart q" "pathfinish q = pathstart r"
lp15@62533
   707
    shows "simple_path (p +++ (q +++ r)) \<longleftrightarrow> simple_path ((p +++ q) +++ r)"
lp15@62533
   708
proof (cases "pathstart p = pathfinish r")
lp15@62533
   709
  case True show ?thesis
lp15@62533
   710
  proof
lp15@62533
   711
    assume "simple_path (p +++ q +++ r)"
lp15@62533
   712
    with assms True show "simple_path ((p +++ q) +++ r)"
hoelzl@63594
   713
      by (fastforce simp add: simple_path_join_loop_eq arc_join_eq path_image_join
lp15@62533
   714
                    dest: arc_distinct_ends [of r])
lp15@62533
   715
  next
lp15@62533
   716
    assume 0: "simple_path ((p +++ q) +++ r)"
lp15@62533
   717
    with assms True have q: "pathfinish r \<notin> path_image q"
hoelzl@63594
   718
      using arc_distinct_ends
lp15@62533
   719
      by (fastforce simp add: simple_path_join_loop_eq arc_join_eq path_image_join)
lp15@62533
   720
    have "pathstart r \<notin> path_image p"
lp15@62533
   721
      using assms
hoelzl@63594
   722
      by (metis 0 IntI arc_distinct_ends arc_join_eq_alt empty_iff insert_iff
lp15@62533
   723
              pathfinish_in_path_image pathfinish_join simple_path_joinE)
lp15@62533
   724
    with assms 0 q True show "simple_path (p +++ q +++ r)"
hoelzl@63594
   725
      by (auto simp: simple_path_join_loop_eq arc_join_eq path_image_join
lp15@62533
   726
               dest!: subsetD [OF _ IntI])
lp15@62533
   727
  qed
lp15@62533
   728
next
lp15@62533
   729
  case False
lp15@62533
   730
  { fix x :: 'a
lp15@62533
   731
    assume a: "path_image p \<inter> path_image q \<subseteq> {pathstart q}"
lp15@62533
   732
              "(path_image p \<union> path_image q) \<inter> path_image r \<subseteq> {pathstart r}"
lp15@62533
   733
              "x \<in> path_image p" "x \<in> path_image r"
lp15@62533
   734
    have "pathstart r \<in> path_image q"
lp15@62533
   735
      by (metis assms(2) pathfinish_in_path_image)
lp15@62533
   736
    with a have "x = pathstart q"
lp15@62533
   737
      by blast
lp15@62533
   738
  }
hoelzl@63594
   739
  with False assms show ?thesis
lp15@62533
   740
    by (auto simp: simple_path_eq_arc simple_path_join_loop_eq arc_join_eq path_image_join)
lp15@62533
   741
qed
lp15@62533
   742
hoelzl@63594
   743
lemma arc_assoc:
lp15@62533
   744
     "\<lbrakk>pathfinish p = pathstart q; pathfinish q = pathstart r\<rbrakk>
lp15@62533
   745
      \<Longrightarrow> arc(p +++ (q +++ r)) \<longleftrightarrow> arc((p +++ q) +++ r)"
lp15@62533
   746
by (simp add: arc_simple_path simple_path_assoc)
lp15@62533
   747
lp15@62620
   748
subsubsection\<open>Symmetry and loops\<close>
lp15@62620
   749
lp15@62620
   750
lemma path_sym:
lp15@62620
   751
    "\<lbrakk>pathfinish p = pathstart q; pathfinish q = pathstart p\<rbrakk> \<Longrightarrow> path(p +++ q) \<longleftrightarrow> path(q +++ p)"
lp15@62620
   752
  by auto
lp15@62620
   753
lp15@62620
   754
lemma simple_path_sym:
lp15@62620
   755
    "\<lbrakk>pathfinish p = pathstart q; pathfinish q = pathstart p\<rbrakk>
lp15@62620
   756
     \<Longrightarrow> simple_path(p +++ q) \<longleftrightarrow> simple_path(q +++ p)"
lp15@62620
   757
by (metis (full_types) inf_commute insert_commute simple_path_joinE simple_path_join_loop)
lp15@62620
   758
lp15@62620
   759
lemma path_image_sym:
lp15@62620
   760
    "\<lbrakk>pathfinish p = pathstart q; pathfinish q = pathstart p\<rbrakk>
lp15@62620
   761
     \<Longrightarrow> path_image(p +++ q) = path_image(q +++ p)"
lp15@62620
   762
by (simp add: path_image_join sup_commute)
lp15@62620
   763
lp15@62533
   764
paulson@61518
   765
section\<open>Choosing a subpath of an existing path\<close>
lp15@60809
   766
paulson@60303
   767
definition subpath :: "real \<Rightarrow> real \<Rightarrow> (real \<Rightarrow> 'a) \<Rightarrow> real \<Rightarrow> 'a::real_normed_vector"
paulson@60303
   768
  where "subpath a b g \<equiv> \<lambda>x. g((b - a) * x + a)"
paulson@60303
   769
lp15@61762
   770
lemma path_image_subpath_gen:
lp15@61762
   771
  fixes g :: "_ \<Rightarrow> 'a::real_normed_vector"
paulson@60303
   772
  shows "path_image(subpath u v g) = g ` (closed_segment u v)"
paulson@60303
   773
  apply (simp add: closed_segment_real_eq path_image_def subpath_def)
paulson@60303
   774
  apply (subst o_def [of g, symmetric])
paulson@60303
   775
  apply (simp add: image_comp [symmetric])
paulson@60303
   776
  done
paulson@60303
   777
lp15@61762
   778
lemma path_image_subpath:
paulson@60303
   779
  fixes g :: "real \<Rightarrow> 'a::real_normed_vector"
paulson@60303
   780
  shows "path_image(subpath u v g) = (if u \<le> v then g ` {u..v} else g ` {v..u})"
lp15@61762
   781
  by (simp add: path_image_subpath_gen closed_segment_eq_real_ivl)
paulson@60303
   782
paulson@60303
   783
lemma path_subpath [simp]:
paulson@60303
   784
  fixes g :: "real \<Rightarrow> 'a::real_normed_vector"
paulson@60303
   785
  assumes "path g" "u \<in> {0..1}" "v \<in> {0..1}"
paulson@60303
   786
    shows "path(subpath u v g)"
paulson@60303
   787
proof -
paulson@60303
   788
  have "continuous_on {0..1} (g o (\<lambda>x. ((v-u) * x+ u)))"
paulson@60303
   789
    apply (rule continuous_intros | simp)+
paulson@60303
   790
    apply (simp add: image_affinity_atLeastAtMost [where c=u])
paulson@60303
   791
    using assms
paulson@60303
   792
    apply (auto simp: path_def continuous_on_subset)
paulson@60303
   793
    done
paulson@60303
   794
  then show ?thesis
paulson@60303
   795
    by (simp add: path_def subpath_def)
wenzelm@49653
   796
qed
huffman@36583
   797
paulson@60303
   798
lemma pathstart_subpath [simp]: "pathstart(subpath u v g) = g(u)"
paulson@60303
   799
  by (simp add: pathstart_def subpath_def)
paulson@60303
   800
paulson@60303
   801
lemma pathfinish_subpath [simp]: "pathfinish(subpath u v g) = g(v)"
paulson@60303
   802
  by (simp add: pathfinish_def subpath_def)
paulson@60303
   803
paulson@60303
   804
lemma subpath_trivial [simp]: "subpath 0 1 g = g"
paulson@60303
   805
  by (simp add: subpath_def)
paulson@60303
   806
paulson@60303
   807
lemma subpath_reversepath: "subpath 1 0 g = reversepath g"
paulson@60303
   808
  by (simp add: reversepath_def subpath_def)
paulson@60303
   809
paulson@60303
   810
lemma reversepath_subpath: "reversepath(subpath u v g) = subpath v u g"
paulson@60303
   811
  by (simp add: reversepath_def subpath_def algebra_simps)
paulson@60303
   812
paulson@60303
   813
lemma subpath_translation: "subpath u v ((\<lambda>x. a + x) o g) = (\<lambda>x. a + x) o subpath u v g"
paulson@60303
   814
  by (rule ext) (simp add: subpath_def)
paulson@60303
   815
paulson@60303
   816
lemma subpath_linear_image: "linear f \<Longrightarrow> subpath u v (f o g) = f o subpath u v g"
paulson@60303
   817
  by (rule ext) (simp add: subpath_def)
paulson@60303
   818
lp15@60809
   819
lemma affine_ineq:
lp15@60809
   820
  fixes x :: "'a::linordered_idom"
lp15@61762
   821
  assumes "x \<le> 1" "v \<le> u"
paulson@60303
   822
    shows "v + x * u \<le> u + x * v"
paulson@60303
   823
proof -
paulson@60303
   824
  have "(1-x)*(u-v) \<ge> 0"
paulson@60303
   825
    using assms by auto
paulson@60303
   826
  then show ?thesis
paulson@60303
   827
    by (simp add: algebra_simps)
wenzelm@49653
   828
qed
huffman@36583
   829
lp15@61711
   830
lemma sum_le_prod1:
lp15@61711
   831
  fixes a::real shows "\<lbrakk>a \<le> 1; b \<le> 1\<rbrakk> \<Longrightarrow> a + b \<le> 1 + a * b"
lp15@61711
   832
by (metis add.commute affine_ineq less_eq_real_def mult.right_neutral)
lp15@61711
   833
lp15@60809
   834
lemma simple_path_subpath_eq:
paulson@60303
   835
  "simple_path(subpath u v g) \<longleftrightarrow>
paulson@60303
   836
     path(subpath u v g) \<and> u\<noteq>v \<and>
paulson@60303
   837
     (\<forall>x y. x \<in> closed_segment u v \<and> y \<in> closed_segment u v \<and> g x = g y
paulson@60303
   838
                \<longrightarrow> x = y \<or> x = u \<and> y = v \<or> x = v \<and> y = u)"
paulson@60303
   839
    (is "?lhs = ?rhs")
paulson@60303
   840
proof (rule iffI)
paulson@60303
   841
  assume ?lhs
paulson@60303
   842
  then have p: "path (\<lambda>x. g ((v - u) * x + u))"
lp15@60809
   843
        and sim: "(\<And>x y. \<lbrakk>x\<in>{0..1}; y\<in>{0..1}; g ((v - u) * x + u) = g ((v - u) * y + u)\<rbrakk>
paulson@60303
   844
                  \<Longrightarrow> x = y \<or> x = 0 \<and> y = 1 \<or> x = 1 \<and> y = 0)"
paulson@60303
   845
    by (auto simp: simple_path_def subpath_def)
paulson@60303
   846
  { fix x y
paulson@60303
   847
    assume "x \<in> closed_segment u v" "y \<in> closed_segment u v" "g x = g y"
paulson@60303
   848
    then have "x = y \<or> x = u \<and> y = v \<or> x = v \<and> y = u"
paulson@60303
   849
    using sim [of "(x-u)/(v-u)" "(y-u)/(v-u)"] p
lp15@60809
   850
    by (auto simp: closed_segment_real_eq image_affinity_atLeastAtMost divide_simps
nipkow@62390
   851
       split: if_split_asm)
paulson@60303
   852
  } moreover
paulson@60303
   853
  have "path(subpath u v g) \<and> u\<noteq>v"
paulson@60303
   854
    using sim [of "1/3" "2/3"] p
paulson@60303
   855
    by (auto simp: subpath_def)
paulson@60303
   856
  ultimately show ?rhs
paulson@60303
   857
    by metis
paulson@60303
   858
next
paulson@60303
   859
  assume ?rhs
lp15@60809
   860
  then
paulson@60303
   861
  have d1: "\<And>x y. \<lbrakk>g x = g y; u \<le> x; x \<le> v; u \<le> y; y \<le> v\<rbrakk> \<Longrightarrow> x = y \<or> x = u \<and> y = v \<or> x = v \<and> y = u"
paulson@60303
   862
   and d2: "\<And>x y. \<lbrakk>g x = g y; v \<le> x; x \<le> u; v \<le> y; y \<le> u\<rbrakk> \<Longrightarrow> x = y \<or> x = u \<and> y = v \<or> x = v \<and> y = u"
paulson@60303
   863
   and ne: "u < v \<or> v < u"
paulson@60303
   864
   and psp: "path (subpath u v g)"
paulson@60303
   865
    by (auto simp: closed_segment_real_eq image_affinity_atLeastAtMost)
paulson@60303
   866
  have [simp]: "\<And>x. u + x * v = v + x * u \<longleftrightarrow> u=v \<or> x=1"
paulson@60303
   867
    by algebra
paulson@60303
   868
  show ?lhs using psp ne
paulson@60303
   869
    unfolding simple_path_def subpath_def
paulson@60303
   870
    by (fastforce simp add: algebra_simps affine_ineq mult_left_mono crossproduct_eq dest: d1 d2)
paulson@60303
   871
qed
paulson@60303
   872
lp15@60809
   873
lemma arc_subpath_eq:
paulson@60303
   874
  "arc(subpath u v g) \<longleftrightarrow> path(subpath u v g) \<and> u\<noteq>v \<and> inj_on g (closed_segment u v)"
paulson@60303
   875
    (is "?lhs = ?rhs")
paulson@60303
   876
proof (rule iffI)
paulson@60303
   877
  assume ?lhs
paulson@60303
   878
  then have p: "path (\<lambda>x. g ((v - u) * x + u))"
lp15@60809
   879
        and sim: "(\<And>x y. \<lbrakk>x\<in>{0..1}; y\<in>{0..1}; g ((v - u) * x + u) = g ((v - u) * y + u)\<rbrakk>
paulson@60303
   880
                  \<Longrightarrow> x = y)"
paulson@60303
   881
    by (auto simp: arc_def inj_on_def subpath_def)
paulson@60303
   882
  { fix x y
paulson@60303
   883
    assume "x \<in> closed_segment u v" "y \<in> closed_segment u v" "g x = g y"
paulson@60303
   884
    then have "x = y"
paulson@60303
   885
    using sim [of "(x-u)/(v-u)" "(y-u)/(v-u)"] p
lp15@60809
   886
    by (force simp add: inj_on_def closed_segment_real_eq image_affinity_atLeastAtMost divide_simps
nipkow@62390
   887
       split: if_split_asm)
paulson@60303
   888
  } moreover
paulson@60303
   889
  have "path(subpath u v g) \<and> u\<noteq>v"
paulson@60303
   890
    using sim [of "1/3" "2/3"] p
paulson@60303
   891
    by (auto simp: subpath_def)
paulson@60303
   892
  ultimately show ?rhs
lp15@60809
   893
    unfolding inj_on_def
paulson@60303
   894
    by metis
paulson@60303
   895
next
paulson@60303
   896
  assume ?rhs
lp15@60809
   897
  then
paulson@60303
   898
  have d1: "\<And>x y. \<lbrakk>g x = g y; u \<le> x; x \<le> v; u \<le> y; y \<le> v\<rbrakk> \<Longrightarrow> x = y"
paulson@60303
   899
   and d2: "\<And>x y. \<lbrakk>g x = g y; v \<le> x; x \<le> u; v \<le> y; y \<le> u\<rbrakk> \<Longrightarrow> x = y"
paulson@60303
   900
   and ne: "u < v \<or> v < u"
paulson@60303
   901
   and psp: "path (subpath u v g)"
paulson@60303
   902
    by (auto simp: inj_on_def closed_segment_real_eq image_affinity_atLeastAtMost)
paulson@60303
   903
  show ?lhs using psp ne
paulson@60303
   904
    unfolding arc_def subpath_def inj_on_def
paulson@60303
   905
    by (auto simp: algebra_simps affine_ineq mult_left_mono crossproduct_eq dest: d1 d2)
paulson@60303
   906
qed
paulson@60303
   907
paulson@60303
   908
lp15@60809
   909
lemma simple_path_subpath:
paulson@60303
   910
  assumes "simple_path g" "u \<in> {0..1}" "v \<in> {0..1}" "u \<noteq> v"
paulson@60303
   911
  shows "simple_path(subpath u v g)"
paulson@60303
   912
  using assms
paulson@60303
   913
  apply (simp add: simple_path_subpath_eq simple_path_imp_path)
paulson@60303
   914
  apply (simp add: simple_path_def closed_segment_real_eq image_affinity_atLeastAtMost, fastforce)
paulson@60303
   915
  done
paulson@60303
   916
paulson@60303
   917
lemma arc_simple_path_subpath:
paulson@60303
   918
    "\<lbrakk>simple_path g; u \<in> {0..1}; v \<in> {0..1}; g u \<noteq> g v\<rbrakk> \<Longrightarrow> arc(subpath u v g)"
paulson@60303
   919
  by (force intro: simple_path_subpath simple_path_imp_arc)
paulson@60303
   920
paulson@60303
   921
lemma arc_subpath_arc:
paulson@60303
   922
    "\<lbrakk>arc g; u \<in> {0..1}; v \<in> {0..1}; u \<noteq> v\<rbrakk> \<Longrightarrow> arc(subpath u v g)"
paulson@60303
   923
  by (meson arc_def arc_imp_simple_path arc_simple_path_subpath inj_onD)
paulson@60303
   924
lp15@60809
   925
lemma arc_simple_path_subpath_interior:
paulson@60303
   926
    "\<lbrakk>simple_path g; u \<in> {0..1}; v \<in> {0..1}; u \<noteq> v; \<bar>u-v\<bar> < 1\<rbrakk> \<Longrightarrow> arc(subpath u v g)"
paulson@60303
   927
    apply (rule arc_simple_path_subpath)
paulson@60303
   928
    apply (force simp: simple_path_def)+
paulson@60303
   929
    done
paulson@60303
   930
lp15@60809
   931
lemma path_image_subpath_subset:
paulson@60303
   932
    "\<lbrakk>path g; u \<in> {0..1}; v \<in> {0..1}\<rbrakk> \<Longrightarrow> path_image(subpath u v g) \<subseteq> path_image g"
lp15@61762
   933
  apply (simp add: closed_segment_real_eq image_affinity_atLeastAtMost path_image_subpath)
paulson@60303
   934
  apply (auto simp: path_image_def)
paulson@60303
   935
  done
paulson@60303
   936
paulson@60303
   937
lemma join_subpaths_middle: "subpath (0) ((1 / 2)) p +++ subpath ((1 / 2)) 1 p = p"
paulson@60303
   938
  by (rule ext) (simp add: joinpaths_def subpath_def divide_simps)
wenzelm@53640
   939
paulson@61518
   940
subsection\<open>There is a subpath to the frontier\<close>
paulson@61518
   941
paulson@61518
   942
lemma subpath_to_frontier_explicit:
paulson@61518
   943
    fixes S :: "'a::metric_space set"
paulson@61518
   944
    assumes g: "path g" and "pathfinish g \<notin> S"
paulson@61518
   945
    obtains u where "0 \<le> u" "u \<le> 1"
paulson@61518
   946
                "\<And>x. 0 \<le> x \<and> x < u \<Longrightarrow> g x \<in> interior S"
paulson@61518
   947
                "(g u \<notin> interior S)" "(u = 0 \<or> g u \<in> closure S)"
paulson@61518
   948
proof -
paulson@61518
   949
  have gcon: "continuous_on {0..1} g"     using g by (simp add: path_def)
paulson@61518
   950
  then have com: "compact ({0..1} \<inter> {u. g u \<in> closure (- S)})"
paulson@61518
   951
    apply (simp add: Int_commute [of "{0..1}"] compact_eq_bounded_closed closed_vimage_Int [unfolded vimage_def])
paulson@61518
   952
    using compact_eq_bounded_closed apply fastforce
paulson@61518
   953
    done
paulson@61518
   954
  have "1 \<in> {u. g u \<in> closure (- S)}"
paulson@61518
   955
    using assms by (simp add: pathfinish_def closure_def)
paulson@61518
   956
  then have dis: "{0..1} \<inter> {u. g u \<in> closure (- S)} \<noteq> {}"
paulson@61518
   957
    using atLeastAtMost_iff zero_le_one by blast
paulson@61518
   958
  then obtain u where "0 \<le> u" "u \<le> 1" and gu: "g u \<in> closure (- S)"
paulson@61518
   959
                  and umin: "\<And>t. \<lbrakk>0 \<le> t; t \<le> 1; g t \<in> closure (- S)\<rbrakk> \<Longrightarrow> u \<le> t"
paulson@61518
   960
    using compact_attains_inf [OF com dis] by fastforce
paulson@61518
   961
  then have umin': "\<And>t. \<lbrakk>0 \<le> t; t \<le> 1; t < u\<rbrakk> \<Longrightarrow>  g t \<in> S"
paulson@61518
   962
    using closure_def by fastforce
paulson@61518
   963
  { assume "u \<noteq> 0"
wenzelm@61808
   964
    then have "u > 0" using \<open>0 \<le> u\<close> by auto
paulson@61518
   965
    { fix e::real assume "e > 0"
lp15@62397
   966
      obtain d where "d>0" and d: "\<And>x'. \<lbrakk>x' \<in> {0..1}; dist x' u \<le> d\<rbrakk> \<Longrightarrow> dist (g x') (g u) < e"
lp15@62397
   967
        using continuous_onE [OF gcon _ \<open>e > 0\<close>] \<open>0 \<le> _\<close> \<open>_ \<le> 1\<close> atLeastAtMost_iff by auto
lp15@62397
   968
      have *: "dist (max 0 (u - d / 2)) u \<le> d"
wenzelm@61808
   969
        using \<open>0 \<le> u\<close> \<open>u \<le> 1\<close> \<open>d > 0\<close> by (simp add: dist_real_def)
paulson@61518
   970
      have "\<exists>y\<in>S. dist y (g u) < e"
wenzelm@61808
   971
        using \<open>0 < u\<close> \<open>u \<le> 1\<close> \<open>d > 0\<close>
paulson@61518
   972
        by (force intro: d [OF _ *] umin')
paulson@61518
   973
    }
paulson@61518
   974
    then have "g u \<in> closure S"
paulson@61518
   975
      by (simp add: frontier_def closure_approachable)
paulson@61518
   976
  }
paulson@61518
   977
  then show ?thesis
paulson@61518
   978
    apply (rule_tac u=u in that)
wenzelm@61808
   979
    apply (auto simp: \<open>0 \<le> u\<close> \<open>u \<le> 1\<close> gu interior_closure umin)
wenzelm@61808
   980
    using \<open>_ \<le> 1\<close> interior_closure umin apply fastforce
paulson@61518
   981
    done
paulson@61518
   982
qed
paulson@61518
   983
paulson@61518
   984
lemma subpath_to_frontier_strong:
paulson@61518
   985
    assumes g: "path g" and "pathfinish g \<notin> S"
paulson@61518
   986
    obtains u where "0 \<le> u" "u \<le> 1" "g u \<notin> interior S"
paulson@61518
   987
                    "u = 0 \<or> (\<forall>x. 0 \<le> x \<and> x < 1 \<longrightarrow> subpath 0 u g x \<in> interior S)  \<and>  g u \<in> closure S"
paulson@61518
   988
proof -
paulson@61518
   989
  obtain u where "0 \<le> u" "u \<le> 1"
paulson@61518
   990
             and gxin: "\<And>x. 0 \<le> x \<and> x < u \<Longrightarrow> g x \<in> interior S"
paulson@61518
   991
             and gunot: "(g u \<notin> interior S)" and u0: "(u = 0 \<or> g u \<in> closure S)"
paulson@61518
   992
    using subpath_to_frontier_explicit [OF assms] by blast
paulson@61518
   993
  show ?thesis
wenzelm@61808
   994
    apply (rule that [OF \<open>0 \<le> u\<close> \<open>u \<le> 1\<close>])
paulson@61518
   995
    apply (simp add: gunot)
wenzelm@61808
   996
    using \<open>0 \<le> u\<close> u0 by (force simp: subpath_def gxin)
paulson@61518
   997
qed
paulson@61518
   998
paulson@61518
   999
lemma subpath_to_frontier:
paulson@61518
  1000
    assumes g: "path g" and g0: "pathstart g \<in> closure S" and g1: "pathfinish g \<notin> S"
paulson@61518
  1001
    obtains u where "0 \<le> u" "u \<le> 1" "g u \<in> frontier S" "(path_image(subpath 0 u g) - {g u}) \<subseteq> interior S"
paulson@61518
  1002
proof -
paulson@61518
  1003
  obtain u where "0 \<le> u" "u \<le> 1"
paulson@61518
  1004
             and notin: "g u \<notin> interior S"
paulson@61518
  1005
             and disj: "u = 0 \<or>
paulson@61518
  1006
                        (\<forall>x. 0 \<le> x \<and> x < 1 \<longrightarrow> subpath 0 u g x \<in> interior S) \<and> g u \<in> closure S"
paulson@61518
  1007
    using subpath_to_frontier_strong [OF g g1] by blast
paulson@61518
  1008
  show ?thesis
wenzelm@61808
  1009
    apply (rule that [OF \<open>0 \<le> u\<close> \<open>u \<le> 1\<close>])
paulson@61518
  1010
    apply (metis DiffI disj frontier_def g0 notin pathstart_def)
wenzelm@61808
  1011
    using \<open>0 \<le> u\<close> g0 disj
lp15@61762
  1012
    apply (simp add: path_image_subpath_gen)
paulson@61518
  1013
    apply (auto simp: closed_segment_eq_real_ivl pathstart_def pathfinish_def subpath_def)
paulson@61518
  1014
    apply (rename_tac y)
paulson@61518
  1015
    apply (drule_tac x="y/u" in spec)
nipkow@62390
  1016
    apply (auto split: if_split_asm)
paulson@61518
  1017
    done
paulson@61518
  1018
qed
paulson@61518
  1019
paulson@61518
  1020
lemma exists_path_subpath_to_frontier:
paulson@61518
  1021
    fixes S :: "'a::real_normed_vector set"
paulson@61518
  1022
    assumes "path g" "pathstart g \<in> closure S" "pathfinish g \<notin> S"
paulson@61518
  1023
    obtains h where "path h" "pathstart h = pathstart g" "path_image h \<subseteq> path_image g"
paulson@61518
  1024
                    "path_image h - {pathfinish h} \<subseteq> interior S"
paulson@61518
  1025
                    "pathfinish h \<in> frontier S"
paulson@61518
  1026
proof -
paulson@61518
  1027
  obtain u where u: "0 \<le> u" "u \<le> 1" "g u \<in> frontier S" "(path_image(subpath 0 u g) - {g u}) \<subseteq> interior S"
paulson@61518
  1028
    using subpath_to_frontier [OF assms] by blast
paulson@61518
  1029
  show ?thesis
paulson@61518
  1030
    apply (rule that [of "subpath 0 u g"])
paulson@61518
  1031
    using assms u
lp15@61762
  1032
    apply (simp_all add: path_image_subpath)
paulson@61518
  1033
    apply (simp add: pathstart_def)
paulson@61518
  1034
    apply (force simp: closed_segment_eq_real_ivl path_image_def)
paulson@61518
  1035
    done
paulson@61518
  1036
qed
paulson@61518
  1037
paulson@61518
  1038
lemma exists_path_subpath_to_frontier_closed:
paulson@61518
  1039
    fixes S :: "'a::real_normed_vector set"
paulson@61518
  1040
    assumes S: "closed S" and g: "path g" and g0: "pathstart g \<in> S" and g1: "pathfinish g \<notin> S"
paulson@61518
  1041
    obtains h where "path h" "pathstart h = pathstart g" "path_image h \<subseteq> path_image g \<inter> S"
paulson@61518
  1042
                    "pathfinish h \<in> frontier S"
paulson@61518
  1043
proof -
paulson@61518
  1044
  obtain h where h: "path h" "pathstart h = pathstart g" "path_image h \<subseteq> path_image g"
paulson@61518
  1045
                    "path_image h - {pathfinish h} \<subseteq> interior S"
paulson@61518
  1046
                    "pathfinish h \<in> frontier S"
paulson@61518
  1047
    using exists_path_subpath_to_frontier [OF g _ g1] closure_closed [OF S] g0 by auto
paulson@61518
  1048
  show ?thesis
wenzelm@61808
  1049
    apply (rule that [OF \<open>path h\<close>])
paulson@61518
  1050
    using assms h
paulson@61518
  1051
    apply auto
paulson@62087
  1052
    apply (metis Diff_single_insert frontier_subset_eq insert_iff interior_subset subset_iff)
paulson@61518
  1053
    done
paulson@61518
  1054
qed
wenzelm@49653
  1055
lp15@64788
  1056
subsection \<open>shiftpath: Reparametrizing a closed curve to start at some chosen point\<close>
huffman@36583
  1057
wenzelm@53640
  1058
definition shiftpath :: "real \<Rightarrow> (real \<Rightarrow> 'a::topological_space) \<Rightarrow> real \<Rightarrow> 'a"
wenzelm@53640
  1059
  where "shiftpath a f = (\<lambda>x. if (a + x) \<le> 1 then f (a + x) else f (a + x - 1))"
huffman@36583
  1060
wenzelm@53640
  1061
lemma pathstart_shiftpath: "a \<le> 1 \<Longrightarrow> pathstart (shiftpath a g) = g a"
huffman@36583
  1062
  unfolding pathstart_def shiftpath_def by auto
huffman@36583
  1063
wenzelm@49653
  1064
lemma pathfinish_shiftpath:
wenzelm@53640
  1065
  assumes "0 \<le> a"
wenzelm@53640
  1066
    and "pathfinish g = pathstart g"
wenzelm@53640
  1067
  shows "pathfinish (shiftpath a g) = g a"
wenzelm@53640
  1068
  using assms
wenzelm@53640
  1069
  unfolding pathstart_def pathfinish_def shiftpath_def
huffman@36583
  1070
  by auto
huffman@36583
  1071
huffman@36583
  1072
lemma endpoints_shiftpath:
wenzelm@53640
  1073
  assumes "pathfinish g = pathstart g"
wenzelm@53640
  1074
    and "a \<in> {0 .. 1}"
wenzelm@53640
  1075
  shows "pathfinish (shiftpath a g) = g a"
wenzelm@53640
  1076
    and "pathstart (shiftpath a g) = g a"
wenzelm@53640
  1077
  using assms
wenzelm@53640
  1078
  by (auto intro!: pathfinish_shiftpath pathstart_shiftpath)
huffman@36583
  1079
huffman@36583
  1080
lemma closed_shiftpath:
wenzelm@53640
  1081
  assumes "pathfinish g = pathstart g"
wenzelm@53640
  1082
    and "a \<in> {0..1}"
wenzelm@53640
  1083
  shows "pathfinish (shiftpath a g) = pathstart (shiftpath a g)"
wenzelm@53640
  1084
  using endpoints_shiftpath[OF assms]
wenzelm@53640
  1085
  by auto
huffman@36583
  1086
huffman@36583
  1087
lemma path_shiftpath:
wenzelm@53640
  1088
  assumes "path g"
wenzelm@53640
  1089
    and "pathfinish g = pathstart g"
wenzelm@53640
  1090
    and "a \<in> {0..1}"
wenzelm@53640
  1091
  shows "path (shiftpath a g)"
wenzelm@49653
  1092
proof -
wenzelm@53640
  1093
  have *: "{0 .. 1} = {0 .. 1-a} \<union> {1-a .. 1}"
wenzelm@53640
  1094
    using assms(3) by auto
wenzelm@49653
  1095
  have **: "\<And>x. x + a = 1 \<Longrightarrow> g (x + a - 1) = g (x + a)"
wenzelm@53640
  1096
    using assms(2)[unfolded pathfinish_def pathstart_def]
wenzelm@53640
  1097
    by auto
wenzelm@49653
  1098
  show ?thesis
wenzelm@49653
  1099
    unfolding path_def shiftpath_def *
lp15@62397
  1100
    apply (rule continuous_on_closed_Un)
wenzelm@49653
  1101
    apply (rule closed_real_atLeastAtMost)+
wenzelm@53640
  1102
    apply (rule continuous_on_eq[of _ "g \<circ> (\<lambda>x. a + x)"])
wenzelm@53640
  1103
    prefer 3
wenzelm@53640
  1104
    apply (rule continuous_on_eq[of _ "g \<circ> (\<lambda>x. a - 1 + x)"])
wenzelm@53640
  1105
    prefer 3
hoelzl@56371
  1106
    apply (rule continuous_intros)+
wenzelm@53640
  1107
    prefer 2
hoelzl@56371
  1108
    apply (rule continuous_intros)+
wenzelm@49653
  1109
    apply (rule_tac[1-2] continuous_on_subset[OF assms(1)[unfolded path_def]])
wenzelm@49653
  1110
    using assms(3) and **
wenzelm@53640
  1111
    apply auto
wenzelm@53640
  1112
    apply (auto simp add: field_simps)
wenzelm@49653
  1113
    done
wenzelm@49653
  1114
qed
huffman@36583
  1115
wenzelm@49653
  1116
lemma shiftpath_shiftpath:
wenzelm@53640
  1117
  assumes "pathfinish g = pathstart g"
wenzelm@53640
  1118
    and "a \<in> {0..1}"
wenzelm@53640
  1119
    and "x \<in> {0..1}"
huffman@36583
  1120
  shows "shiftpath (1 - a) (shiftpath a g) x = g x"
wenzelm@53640
  1121
  using assms
wenzelm@53640
  1122
  unfolding pathfinish_def pathstart_def shiftpath_def
wenzelm@53640
  1123
  by auto
huffman@36583
  1124
huffman@36583
  1125
lemma path_image_shiftpath:
wenzelm@53640
  1126
  assumes "a \<in> {0..1}"
wenzelm@53640
  1127
    and "pathfinish g = pathstart g"
wenzelm@53640
  1128
  shows "path_image (shiftpath a g) = path_image g"
wenzelm@49653
  1129
proof -
wenzelm@49653
  1130
  { fix x
wenzelm@53640
  1131
    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
  1132
    then have "\<exists>y\<in>{0..1} \<inter> {x. a + x \<le> 1}. g x = g (a + y)"
wenzelm@49653
  1133
    proof (cases "a \<le> x")
wenzelm@49653
  1134
      case False
wenzelm@49654
  1135
      then show ?thesis
wenzelm@49653
  1136
        apply (rule_tac x="1 + x - a" in bexI)
huffman@36583
  1137
        using as(1,2) and as(3)[THEN bspec[where x="1 + x - a"]] and assms(1)
wenzelm@49653
  1138
        apply (auto simp add: field_simps atomize_not)
wenzelm@49653
  1139
        done
wenzelm@49653
  1140
    next
wenzelm@49653
  1141
      case True
wenzelm@53640
  1142
      then show ?thesis
wenzelm@53640
  1143
        using as(1-2) and assms(1)
wenzelm@53640
  1144
        apply (rule_tac x="x - a" in bexI)
wenzelm@53640
  1145
        apply (auto simp add: field_simps)
wenzelm@53640
  1146
        done
wenzelm@49653
  1147
    qed
wenzelm@49653
  1148
  }
wenzelm@49654
  1149
  then show ?thesis
wenzelm@53640
  1150
    using assms
wenzelm@53640
  1151
    unfolding shiftpath_def path_image_def pathfinish_def pathstart_def
wenzelm@53640
  1152
    by (auto simp add: image_iff)
wenzelm@49653
  1153
qed
wenzelm@49653
  1154
lp15@64788
  1155
lemma simple_path_shiftpath:
lp15@64788
  1156
  assumes "simple_path g" "pathfinish g = pathstart g" and a: "0 \<le> a" "a \<le> 1"
lp15@64788
  1157
    shows "simple_path (shiftpath a g)"
lp15@64788
  1158
  unfolding simple_path_def
lp15@64788
  1159
proof (intro conjI impI ballI)
lp15@64788
  1160
  show "path (shiftpath a g)"
lp15@64788
  1161
    by (simp add: assms path_shiftpath simple_path_imp_path)
lp15@64788
  1162
  have *: "\<And>x y. \<lbrakk>g x = g y; x \<in> {0..1}; y \<in> {0..1}\<rbrakk> \<Longrightarrow> x = y \<or> x = 0 \<and> y = 1 \<or> x = 1 \<and> y = 0"
lp15@64788
  1163
    using assms by (simp add:  simple_path_def)
lp15@64788
  1164
  show "x = y \<or> x = 0 \<and> y = 1 \<or> x = 1 \<and> y = 0"
lp15@64788
  1165
    if "x \<in> {0..1}" "y \<in> {0..1}" "shiftpath a g x = shiftpath a g y" for x y
lp15@64788
  1166
    using that a unfolding shiftpath_def
lp15@64788
  1167
    apply (simp add: split: if_split_asm)
lp15@64788
  1168
      apply (drule *; auto)+
lp15@64788
  1169
    done
lp15@64788
  1170
qed
huffman@36583
  1171
wenzelm@60420
  1172
subsection \<open>Special case of straight-line paths\<close>
huffman@36583
  1173
wenzelm@49653
  1174
definition linepath :: "'a::real_normed_vector \<Rightarrow> 'a \<Rightarrow> real \<Rightarrow> 'a"
wenzelm@49653
  1175
  where "linepath a b = (\<lambda>x. (1 - x) *\<^sub>R a + x *\<^sub>R b)"
huffman@36583
  1176
wenzelm@53640
  1177
lemma pathstart_linepath[simp]: "pathstart (linepath a b) = a"
wenzelm@53640
  1178
  unfolding pathstart_def linepath_def
wenzelm@53640
  1179
  by auto
huffman@36583
  1180
wenzelm@53640
  1181
lemma pathfinish_linepath[simp]: "pathfinish (linepath a b) = b"
wenzelm@53640
  1182
  unfolding pathfinish_def linepath_def
wenzelm@53640
  1183
  by auto
huffman@36583
  1184
huffman@36583
  1185
lemma continuous_linepath_at[intro]: "continuous (at x) (linepath a b)"
wenzelm@53640
  1186
  unfolding linepath_def
wenzelm@53640
  1187
  by (intro continuous_intros)
huffman@36583
  1188
lp15@61762
  1189
lemma continuous_on_linepath [intro,continuous_intros]: "continuous_on s (linepath a b)"
wenzelm@53640
  1190
  using continuous_linepath_at
wenzelm@53640
  1191
  by (auto intro!: continuous_at_imp_continuous_on)
huffman@36583
  1192
lp15@62618
  1193
lemma path_linepath[iff]: "path (linepath a b)"
wenzelm@53640
  1194
  unfolding path_def
wenzelm@53640
  1195
  by (rule continuous_on_linepath)
huffman@36583
  1196
wenzelm@53640
  1197
lemma path_image_linepath[simp]: "path_image (linepath a b) = closed_segment a b"
wenzelm@49653
  1198
  unfolding path_image_def segment linepath_def
paulson@60303
  1199
  by auto
wenzelm@49653
  1200
wenzelm@53640
  1201
lemma reversepath_linepath[simp]: "reversepath (linepath a b) = linepath b a"
wenzelm@49653
  1202
  unfolding reversepath_def linepath_def
huffman@36583
  1203
  by auto
huffman@36583
  1204
lp15@61762
  1205
lemma linepath_0 [simp]: "linepath 0 b x = x *\<^sub>R b"
lp15@61762
  1206
  by (simp add: linepath_def)
lp15@61762
  1207
paulson@60303
  1208
lemma arc_linepath:
lp15@62618
  1209
  assumes "a \<noteq> b" shows [simp]: "arc (linepath a b)"
huffman@36583
  1210
proof -
wenzelm@53640
  1211
  {
wenzelm@53640
  1212
    fix x y :: "real"
huffman@36583
  1213
    assume "x *\<^sub>R b + y *\<^sub>R a = x *\<^sub>R a + y *\<^sub>R b"
wenzelm@53640
  1214
    then have "(x - y) *\<^sub>R a = (x - y) *\<^sub>R b"
wenzelm@53640
  1215
      by (simp add: algebra_simps)
wenzelm@53640
  1216
    with assms have "x = y"
wenzelm@53640
  1217
      by simp
wenzelm@53640
  1218
  }
wenzelm@49654
  1219
  then show ?thesis
lp15@60809
  1220
    unfolding arc_def inj_on_def
paulson@60303
  1221
    by (simp add:  path_linepath) (force simp: algebra_simps linepath_def)
wenzelm@49653
  1222
qed
huffman@36583
  1223
wenzelm@53640
  1224
lemma simple_path_linepath[intro]: "a \<noteq> b \<Longrightarrow> simple_path (linepath a b)"
paulson@60303
  1225
  by (simp add: arc_imp_simple_path arc_linepath)
wenzelm@49653
  1226
lp15@61711
  1227
lemma linepath_trivial [simp]: "linepath a a x = a"
lp15@61711
  1228
  by (simp add: linepath_def real_vector.scale_left_diff_distrib)
lp15@61738
  1229
lp15@64394
  1230
lemma linepath_refl: "linepath a a = (\<lambda>x. a)"
lp15@64394
  1231
  by auto
lp15@64394
  1232
lp15@61711
  1233
lemma subpath_refl: "subpath a a g = linepath (g a) (g a)"
lp15@61711
  1234
  by (simp add: subpath_def linepath_def algebra_simps)
lp15@61711
  1235
lp15@62618
  1236
lemma linepath_of_real: "(linepath (of_real a) (of_real b) x) = of_real ((1 - x)*a + x*b)"
lp15@62618
  1237
  by (simp add: scaleR_conv_of_real linepath_def)
lp15@62618
  1238
lp15@62618
  1239
lemma of_real_linepath: "of_real (linepath a b x) = linepath (of_real a) (of_real b) x"
lp15@62618
  1240
  by (metis linepath_of_real mult.right_neutral of_real_def real_scaleR_def)
lp15@62618
  1241
lp15@63881
  1242
lemma inj_on_linepath:
lp15@63881
  1243
  assumes "a \<noteq> b" shows "inj_on (linepath a b) {0..1}"
lp15@63881
  1244
proof (clarsimp simp: inj_on_def linepath_def)
lp15@63881
  1245
  fix x y
lp15@63881
  1246
  assume "(1 - x) *\<^sub>R a + x *\<^sub>R b = (1 - y) *\<^sub>R a + y *\<^sub>R b" "0 \<le> x" "x \<le> 1" "0 \<le> y" "y \<le> 1"
lp15@63881
  1247
  then have "x *\<^sub>R (a - b) = y *\<^sub>R (a - b)"
lp15@63881
  1248
    by (auto simp: algebra_simps)
lp15@63881
  1249
  then show "x=y"
lp15@63881
  1250
    using assms by auto
lp15@63881
  1251
qed
lp15@63881
  1252
lp15@62618
  1253
lp15@62618
  1254
subsection\<open>Segments via convex hulls\<close>
lp15@62618
  1255
lp15@62618
  1256
lemma segments_subset_convex_hull:
lp15@62618
  1257
    "closed_segment a b \<subseteq> (convex hull {a,b,c})"
lp15@62618
  1258
    "closed_segment a c \<subseteq> (convex hull {a,b,c})"
lp15@62618
  1259
    "closed_segment b c \<subseteq> (convex hull {a,b,c})"
lp15@62618
  1260
    "closed_segment b a \<subseteq> (convex hull {a,b,c})"
lp15@62618
  1261
    "closed_segment c a \<subseteq> (convex hull {a,b,c})"
lp15@62618
  1262
    "closed_segment c b \<subseteq> (convex hull {a,b,c})"
lp15@62618
  1263
by (auto simp: segment_convex_hull linepath_of_real  elim!: rev_subsetD [OF _ hull_mono])
lp15@62618
  1264
lp15@62618
  1265
lemma midpoints_in_convex_hull:
lp15@62618
  1266
  assumes "x \<in> convex hull s" "y \<in> convex hull s"
lp15@62618
  1267
    shows "midpoint x y \<in> convex hull s"
lp15@62618
  1268
proof -
lp15@62618
  1269
  have "(1 - inverse(2)) *\<^sub>R x + inverse(2) *\<^sub>R y \<in> convex hull s"
lp15@62618
  1270
    apply (rule convexD_alt)
lp15@62618
  1271
    using assms
lp15@62618
  1272
    apply (auto simp: convex_convex_hull)
lp15@62618
  1273
    done
lp15@62618
  1274
  then show ?thesis
lp15@62618
  1275
    by (simp add: midpoint_def algebra_simps)
lp15@62618
  1276
qed
lp15@62618
  1277
lp15@62618
  1278
lemma not_in_interior_convex_hull_3:
lp15@62618
  1279
  fixes a :: "complex"
lp15@62618
  1280
  shows "a \<notin> interior(convex hull {a,b,c})"
lp15@62618
  1281
        "b \<notin> interior(convex hull {a,b,c})"
lp15@62618
  1282
        "c \<notin> interior(convex hull {a,b,c})"
lp15@62618
  1283
  by (auto simp: card_insert_le_m1 not_in_interior_convex_hull)
lp15@62618
  1284
lp15@62618
  1285
lemma midpoint_in_closed_segment [simp]: "midpoint a b \<in> closed_segment a b"
lp15@62618
  1286
  using midpoints_in_convex_hull segment_convex_hull by blast
lp15@62618
  1287
lp15@62618
  1288
lemma midpoint_in_open_segment [simp]: "midpoint a b \<in> open_segment a b \<longleftrightarrow> a \<noteq> b"
lp15@64122
  1289
  by (simp add: open_segment_def)
lp15@64122
  1290
lp15@64122
  1291
lemma continuous_IVT_local_extremum:
lp15@64122
  1292
  fixes f :: "'a::euclidean_space \<Rightarrow> real"
lp15@64122
  1293
  assumes contf: "continuous_on (closed_segment a b) f"
lp15@64122
  1294
      and "a \<noteq> b" "f a = f b"
lp15@64122
  1295
  obtains z where "z \<in> open_segment a b"
lp15@64122
  1296
                  "(\<forall>w \<in> closed_segment a b. (f w) \<le> (f z)) \<or>
lp15@64122
  1297
                   (\<forall>w \<in> closed_segment a b. (f z) \<le> (f w))"
lp15@64122
  1298
proof -
lp15@64122
  1299
  obtain c where "c \<in> closed_segment a b" and c: "\<And>y. y \<in> closed_segment a b \<Longrightarrow> f y \<le> f c"
lp15@64122
  1300
    using continuous_attains_sup [of "closed_segment a b" f] contf by auto
lp15@64122
  1301
  obtain d where "d \<in> closed_segment a b" and d: "\<And>y. y \<in> closed_segment a b \<Longrightarrow> f d \<le> f y"
lp15@64122
  1302
    using continuous_attains_inf [of "closed_segment a b" f] contf by auto
lp15@64122
  1303
  show ?thesis
lp15@64122
  1304
  proof (cases "c \<in> open_segment a b \<or> d \<in> open_segment a b")
lp15@64122
  1305
    case True
lp15@64122
  1306
    then show ?thesis
lp15@64122
  1307
      using c d that by blast
lp15@64122
  1308
  next
lp15@64122
  1309
    case False
lp15@64122
  1310
    then have "(c = a \<or> c = b) \<and> (d = a \<or> d = b)"
lp15@64122
  1311
      by (simp add: \<open>c \<in> closed_segment a b\<close> \<open>d \<in> closed_segment a b\<close> open_segment_def)
lp15@64122
  1312
    with \<open>a \<noteq> b\<close> \<open>f a = f b\<close> c d show ?thesis
lp15@64122
  1313
      by (rule_tac z = "midpoint a b" in that) (fastforce+)
lp15@64122
  1314
  qed
lp15@64122
  1315
qed
lp15@64122
  1316
lp15@64122
  1317
text\<open>An injective map into R is also an open map w.r.T. the universe, and conversely. \<close>
lp15@64122
  1318
proposition injective_eq_1d_open_map_UNIV:
lp15@64122
  1319
  fixes f :: "real \<Rightarrow> real"
lp15@64122
  1320
  assumes contf: "continuous_on S f" and S: "is_interval S"
lp15@64122
  1321
    shows "inj_on f S \<longleftrightarrow> (\<forall>T. open T \<and> T \<subseteq> S \<longrightarrow> open(f ` T))"
lp15@64122
  1322
          (is "?lhs = ?rhs")
lp15@64122
  1323
proof safe
lp15@64122
  1324
  fix T
lp15@64122
  1325
  assume injf: ?lhs and "open T" and "T \<subseteq> S"
lp15@64122
  1326
  have "\<exists>U. open U \<and> f x \<in> U \<and> U \<subseteq> f ` T" if "x \<in> T" for x
lp15@64122
  1327
  proof -
lp15@64122
  1328
    obtain \<delta> where "\<delta> > 0" and \<delta>: "cball x \<delta> \<subseteq> T"
lp15@64122
  1329
      using \<open>open T\<close> \<open>x \<in> T\<close> open_contains_cball_eq by blast
lp15@64122
  1330
    show ?thesis
lp15@64122
  1331
    proof (intro exI conjI)
lp15@64122
  1332
      have "closed_segment (x-\<delta>) (x+\<delta>) = {x-\<delta>..x+\<delta>}"
lp15@64122
  1333
        using \<open>0 < \<delta>\<close> by (auto simp: closed_segment_eq_real_ivl)
lp15@64122
  1334
      also have "... \<subseteq> S"
lp15@64122
  1335
        using \<delta> \<open>T \<subseteq> S\<close> by (auto simp: dist_norm subset_eq)
lp15@64122
  1336
      finally have "f ` (open_segment (x-\<delta>) (x+\<delta>)) = open_segment (f (x-\<delta>)) (f (x+\<delta>))"
lp15@64122
  1337
        using continuous_injective_image_open_segment_1
lp15@64122
  1338
        by (metis continuous_on_subset [OF contf] inj_on_subset [OF injf])
lp15@64122
  1339
      then show "open (f ` {x-\<delta><..<x+\<delta>})"
lp15@64122
  1340
        using \<open>0 < \<delta>\<close> by (simp add: open_segment_eq_real_ivl)
lp15@64122
  1341
      show "f x \<in> f ` {x - \<delta><..<x + \<delta>}"
lp15@64122
  1342
        by (auto simp: \<open>\<delta> > 0\<close>)
lp15@64122
  1343
      show "f ` {x - \<delta><..<x + \<delta>} \<subseteq> f ` T"
lp15@64122
  1344
        using \<delta> by (auto simp: dist_norm subset_iff)
lp15@64122
  1345
    qed
lp15@64122
  1346
  qed
lp15@64122
  1347
  with open_subopen show "open (f ` T)"
lp15@64122
  1348
    by blast
lp15@64122
  1349
next
lp15@64122
  1350
  assume R: ?rhs
lp15@64122
  1351
  have False if xy: "x \<in> S" "y \<in> S" and "f x = f y" "x \<noteq> y" for x y
lp15@64122
  1352
  proof -
lp15@64122
  1353
    have "open (f ` open_segment x y)"
lp15@64122
  1354
      using R
lp15@64122
  1355
      by (metis S convex_contains_open_segment is_interval_convex open_greaterThanLessThan open_segment_eq_real_ivl xy)
lp15@64122
  1356
    moreover
lp15@64122
  1357
    have "continuous_on (closed_segment x y) f"
lp15@64122
  1358
      by (meson S closed_segment_subset contf continuous_on_subset is_interval_convex that)
lp15@64122
  1359
    then obtain \<xi> where "\<xi> \<in> open_segment x y"
lp15@64122
  1360
                    and \<xi>: "(\<forall>w \<in> closed_segment x y. (f w) \<le> (f \<xi>)) \<or>
lp15@64122
  1361
                            (\<forall>w \<in> closed_segment x y. (f \<xi>) \<le> (f w))"
lp15@64122
  1362
      using continuous_IVT_local_extremum [of x y f] \<open>f x = f y\<close> \<open>x \<noteq> y\<close> by blast
lp15@64122
  1363
    ultimately obtain e where "e>0" and e: "\<And>u. dist u (f \<xi>) < e \<Longrightarrow> u \<in> f ` open_segment x y"
lp15@64122
  1364
      using open_dist by (metis image_eqI)
lp15@64122
  1365
    have fin: "f \<xi> + (e/2) \<in> f ` open_segment x y" "f \<xi> - (e/2) \<in> f ` open_segment x y"
lp15@64122
  1366
      using e [of "f \<xi> + (e/2)"] e [of "f \<xi> - (e/2)"] \<open>e > 0\<close> by (auto simp: dist_norm)
lp15@64122
  1367
    show ?thesis
lp15@64122
  1368
      using \<xi> \<open>0 < e\<close> fin open_closed_segment by fastforce
lp15@64122
  1369
  qed
lp15@64122
  1370
  then show ?lhs
lp15@64122
  1371
    by (force simp: inj_on_def)
lp15@64122
  1372
qed
huffman@36583
  1373
wenzelm@60420
  1374
subsection \<open>Bounding a point away from a path\<close>
huffman@36583
  1375
huffman@36583
  1376
lemma not_on_path_ball:
huffman@36583
  1377
  fixes g :: "real \<Rightarrow> 'a::heine_borel"
wenzelm@53640
  1378
  assumes "path g"
wenzelm@53640
  1379
    and "z \<notin> path_image g"
wenzelm@53640
  1380
  shows "\<exists>e > 0. ball z e \<inter> path_image g = {}"
wenzelm@49653
  1381
proof -
wenzelm@49653
  1382
  obtain a where "a \<in> path_image g" "\<forall>y \<in> path_image g. dist z a \<le> dist z y"
hoelzl@63594
  1383
    apply (rule distance_attains_inf[OF _ path_image_nonempty, of g z])
huffman@36583
  1384
    using compact_path_image[THEN compact_imp_closed, OF assms(1)] by auto
wenzelm@49654
  1385
  then show ?thesis
wenzelm@49653
  1386
    apply (rule_tac x="dist z a" in exI)
wenzelm@49653
  1387
    using assms(2)
wenzelm@49653
  1388
    apply (auto intro!: dist_pos_lt)
wenzelm@49653
  1389
    done
wenzelm@49653
  1390
qed
huffman@36583
  1391
huffman@36583
  1392
lemma not_on_path_cball:
huffman@36583
  1393
  fixes g :: "real \<Rightarrow> 'a::heine_borel"
wenzelm@53640
  1394
  assumes "path g"
wenzelm@53640
  1395
    and "z \<notin> path_image g"
wenzelm@49653
  1396
  shows "\<exists>e>0. cball z e \<inter> (path_image g) = {}"
wenzelm@49653
  1397
proof -
wenzelm@53640
  1398
  obtain e where "ball z e \<inter> path_image g = {}" "e > 0"
wenzelm@49653
  1399
    using not_on_path_ball[OF assms] by auto
wenzelm@53640
  1400
  moreover have "cball z (e/2) \<subseteq> ball z e"
wenzelm@60420
  1401
    using \<open>e > 0\<close> by auto
wenzelm@53640
  1402
  ultimately show ?thesis
wenzelm@53640
  1403
    apply (rule_tac x="e/2" in exI)
wenzelm@53640
  1404
    apply auto
wenzelm@53640
  1405
    done
wenzelm@49653
  1406
qed
wenzelm@49653
  1407
huffman@36583
  1408
paulson@61518
  1409
section \<open>Path component, considered as a "joinability" relation (from Tom Hales)\<close>
huffman@36583
  1410
wenzelm@49653
  1411
definition "path_component s x y \<longleftrightarrow>
wenzelm@49653
  1412
  (\<exists>g. path g \<and> path_image g \<subseteq> s \<and> pathstart g = x \<and> pathfinish g = y)"
huffman@36583
  1413
lp15@61426
  1414
abbreviation
lp15@61426
  1415
   "path_component_set s x \<equiv> Collect (path_component s x)"
lp15@61426
  1416
wenzelm@53640
  1417
lemmas path_defs = path_def pathstart_def pathfinish_def path_image_def path_component_def
huffman@36583
  1418
wenzelm@49653
  1419
lemma path_component_mem:
wenzelm@49653
  1420
  assumes "path_component s x y"
wenzelm@53640
  1421
  shows "x \<in> s" and "y \<in> s"
wenzelm@53640
  1422
  using assms
wenzelm@53640
  1423
  unfolding path_defs
wenzelm@53640
  1424
  by auto
huffman@36583
  1425
wenzelm@49653
  1426
lemma path_component_refl:
wenzelm@49653
  1427
  assumes "x \<in> s"
wenzelm@49653
  1428
  shows "path_component s x x"
wenzelm@49653
  1429
  unfolding path_defs
wenzelm@49653
  1430
  apply (rule_tac x="\<lambda>u. x" in exI)
wenzelm@53640
  1431
  using assms
hoelzl@56371
  1432
  apply (auto intro!: continuous_intros)
wenzelm@53640
  1433
  done
huffman@36583
  1434
huffman@36583
  1435
lemma path_component_refl_eq: "path_component s x x \<longleftrightarrow> x \<in> s"
wenzelm@49653
  1436
  by (auto intro!: path_component_mem path_component_refl)
huffman@36583
  1437
huffman@36583
  1438
lemma path_component_sym: "path_component s x y \<Longrightarrow> path_component s y x"
wenzelm@49653
  1439
  unfolding path_component_def
wenzelm@49653
  1440
  apply (erule exE)
wenzelm@49653
  1441
  apply (rule_tac x="reversepath g" in exI)
wenzelm@49653
  1442
  apply auto
wenzelm@49653
  1443
  done
huffman@36583
  1444
wenzelm@49653
  1445
lemma path_component_trans:
lp15@61426
  1446
  assumes "path_component s x y" and "path_component s y z"
wenzelm@49653
  1447
  shows "path_component s x z"
wenzelm@49653
  1448
  using assms
wenzelm@49653
  1449
  unfolding path_component_def
wenzelm@53640
  1450
  apply (elim exE)
wenzelm@49653
  1451
  apply (rule_tac x="g +++ ga" in exI)
wenzelm@49653
  1452
  apply (auto simp add: path_image_join)
wenzelm@49653
  1453
  done
huffman@36583
  1454
wenzelm@53640
  1455
lemma path_component_of_subset: "s \<subseteq> t \<Longrightarrow> path_component s x y \<Longrightarrow> path_component t x y"
huffman@36583
  1456
  unfolding path_component_def by auto
huffman@36583
  1457
lp15@61426
  1458
lemma path_connected_linepath:
lp15@61426
  1459
    fixes s :: "'a::real_normed_vector set"
lp15@61426
  1460
    shows "closed_segment a b \<subseteq> s \<Longrightarrow> path_component s a b"
lp15@61426
  1461
  apply (simp add: path_component_def)
lp15@61426
  1462
  apply (rule_tac x="linepath a b" in exI, auto)
lp15@61426
  1463
  done
lp15@61426
  1464
wenzelm@49653
  1465
lp15@62620
  1466
subsubsection \<open>Path components as sets\<close>
huffman@36583
  1467
wenzelm@49653
  1468
lemma path_component_set:
lp15@61426
  1469
  "path_component_set s x =
wenzelm@49653
  1470
    {y. (\<exists>g. path g \<and> path_image g \<subseteq> s \<and> pathstart g = x \<and> pathfinish g = y)}"
lp15@61426
  1471
  by (auto simp: path_component_def)
huffman@36583
  1472
lp15@61426
  1473
lemma path_component_subset: "path_component_set s x \<subseteq> s"
paulson@60303
  1474
  by (auto simp add: path_component_mem(2))
huffman@36583
  1475
lp15@61426
  1476
lemma path_component_eq_empty: "path_component_set s x = {} \<longleftrightarrow> x \<notin> s"
paulson@60303
  1477
  using path_component_mem path_component_refl_eq
paulson@60303
  1478
    by fastforce
huffman@36583
  1479
lp15@61426
  1480
lemma path_component_mono:
lp15@61426
  1481
     "s \<subseteq> t \<Longrightarrow> (path_component_set s x) \<subseteq> (path_component_set t x)"
lp15@61426
  1482
  by (simp add: Collect_mono path_component_of_subset)
lp15@61426
  1483
lp15@61426
  1484
lemma path_component_eq:
lp15@61426
  1485
   "y \<in> path_component_set s x \<Longrightarrow> path_component_set s y = path_component_set s x"
lp15@61426
  1486
by (metis (no_types, lifting) Collect_cong mem_Collect_eq path_component_sym path_component_trans)
lp15@61426
  1487
wenzelm@60420
  1488
subsection \<open>Path connectedness of a space\<close>
huffman@36583
  1489
wenzelm@49653
  1490
definition "path_connected s \<longleftrightarrow>
wenzelm@53640
  1491
  (\<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
  1492
huffman@36583
  1493
lemma path_connected_component: "path_connected s \<longleftrightarrow> (\<forall>x\<in>s. \<forall>y\<in>s. path_component s x y)"
huffman@36583
  1494
  unfolding path_connected_def path_component_def by auto
huffman@36583
  1495
lp15@61426
  1496
lemma path_connected_component_set: "path_connected s \<longleftrightarrow> (\<forall>x\<in>s. path_component_set s x = s)"
lp15@61694
  1497
  unfolding path_connected_component path_component_subset
lp15@61426
  1498
  using path_component_mem by blast
lp15@61426
  1499
lp15@61426
  1500
lemma path_component_maximal:
lp15@61426
  1501
     "\<lbrakk>x \<in> t; path_connected t; t \<subseteq> s\<rbrakk> \<Longrightarrow> t \<subseteq> (path_component_set s x)"
lp15@61426
  1502
  by (metis path_component_mono path_connected_component_set)
huffman@36583
  1503
huffman@36583
  1504
lemma convex_imp_path_connected:
huffman@36583
  1505
  fixes s :: "'a::real_normed_vector set"
wenzelm@53640
  1506
  assumes "convex s"
wenzelm@53640
  1507
  shows "path_connected s"
wenzelm@49653
  1508
  unfolding path_connected_def
wenzelm@53640
  1509
  apply rule
wenzelm@53640
  1510
  apply rule
wenzelm@53640
  1511
  apply (rule_tac x = "linepath x y" in exI)
wenzelm@49653
  1512
  unfolding path_image_linepath
wenzelm@49653
  1513
  using assms [unfolded convex_contains_segment]
wenzelm@49653
  1514
  apply auto
wenzelm@49653
  1515
  done
huffman@36583
  1516
lp15@62620
  1517
lemma path_connected_UNIV [iff]: "path_connected (UNIV :: 'a::real_normed_vector set)"
lp15@62620
  1518
  by (simp add: convex_imp_path_connected)
lp15@62620
  1519
lp15@62620
  1520
lemma path_component_UNIV: "path_component_set UNIV x = (UNIV :: 'a::real_normed_vector set)"
lp15@62620
  1521
  using path_connected_component_set by auto
lp15@62620
  1522
wenzelm@49653
  1523
lemma path_connected_imp_connected:
lp15@64788
  1524
  assumes "path_connected S"
lp15@64788
  1525
  shows "connected S"
wenzelm@49653
  1526
  unfolding connected_def not_ex
wenzelm@53640
  1527
  apply rule
wenzelm@53640
  1528
  apply rule
wenzelm@53640
  1529
  apply (rule ccontr)
wenzelm@49653
  1530
  unfolding not_not
wenzelm@53640
  1531
  apply (elim conjE)
wenzelm@49653
  1532
proof -
wenzelm@49653
  1533
  fix e1 e2
lp15@64788
  1534
  assume as: "open e1" "open e2" "S \<subseteq> e1 \<union> e2" "e1 \<inter> e2 \<inter> S = {}" "e1 \<inter> S \<noteq> {}" "e2 \<inter> S \<noteq> {}"
lp15@64788
  1535
  then obtain x1 x2 where obt:"x1 \<in> e1 \<inter> S" "x2 \<in> e2 \<inter> S"
wenzelm@53640
  1536
    by auto
lp15@64788
  1537
  then obtain g where g: "path g" "path_image g \<subseteq> S" "pathstart g = x1" "pathfinish g = x2"
huffman@36583
  1538
    using assms[unfolded path_connected_def,rule_format,of x1 x2] by auto
wenzelm@49653
  1539
  have *: "connected {0..1::real}"
wenzelm@49653
  1540
    by (auto intro!: convex_connected convex_real_interval)
wenzelm@49653
  1541
  have "{0..1} \<subseteq> {x \<in> {0..1}. g x \<in> e1} \<union> {x \<in> {0..1}. g x \<in> e2}"
wenzelm@49653
  1542
    using as(3) g(2)[unfolded path_defs] by blast
wenzelm@49653
  1543
  moreover have "{x \<in> {0..1}. g x \<in> e1} \<inter> {x \<in> {0..1}. g x \<in> e2} = {}"
wenzelm@53640
  1544
    using as(4) g(2)[unfolded path_defs]
wenzelm@53640
  1545
    unfolding subset_eq
wenzelm@53640
  1546
    by auto
wenzelm@49653
  1547
  moreover have "{x \<in> {0..1}. g x \<in> e1} \<noteq> {} \<and> {x \<in> {0..1}. g x \<in> e2} \<noteq> {}"
wenzelm@53640
  1548
    using g(3,4)[unfolded path_defs]
wenzelm@53640
  1549
    using obt
huffman@36583
  1550
    by (simp add: ex_in_conv [symmetric], metis zero_le_one order_refl)
wenzelm@49653
  1551
  ultimately show False
wenzelm@53640
  1552
    using *[unfolded connected_local not_ex, rule_format,
wenzelm@53640
  1553
      of "{x\<in>{0..1}. g x \<in> e1}" "{x\<in>{0..1}. g x \<in> e2}"]
lp15@63301
  1554
    using continuous_openin_preimage_gen[OF g(1)[unfolded path_def] as(1)]
lp15@63301
  1555
    using continuous_openin_preimage_gen[OF g(1)[unfolded path_def] as(2)]
wenzelm@49653
  1556
    by auto
wenzelm@49653
  1557
qed
huffman@36583
  1558
huffman@36583
  1559
lemma open_path_component:
lp15@64788
  1560
  fixes S :: "'a::real_normed_vector set"
lp15@64788
  1561
  assumes "open S"
lp15@64788
  1562
  shows "open (path_component_set S x)"
wenzelm@49653
  1563
  unfolding open_contains_ball
wenzelm@49653
  1564
proof
wenzelm@49653
  1565
  fix y
lp15@64788
  1566
  assume as: "y \<in> path_component_set S x"
lp15@64788
  1567
  then have "y \<in> S"
wenzelm@49653
  1568
    apply -
wenzelm@49653
  1569
    apply (rule path_component_mem(2))
wenzelm@49653
  1570
    unfolding mem_Collect_eq
wenzelm@49653
  1571
    apply auto
wenzelm@49653
  1572
    done
lp15@64788
  1573
  then obtain e where e: "e > 0" "ball y e \<subseteq> S"
wenzelm@53640
  1574
    using assms[unfolded open_contains_ball]
wenzelm@53640
  1575
    by auto
lp15@64788
  1576
  show "\<exists>e > 0. ball y e \<subseteq> path_component_set S x"
wenzelm@49653
  1577
    apply (rule_tac x=e in exI)
wenzelm@60420
  1578
    apply (rule,rule \<open>e>0\<close>)
wenzelm@53640
  1579
    apply rule
wenzelm@49653
  1580
    unfolding mem_ball mem_Collect_eq
wenzelm@49653
  1581
  proof -
wenzelm@49653
  1582
    fix z
wenzelm@49653
  1583
    assume "dist y z < e"
lp15@64788
  1584
    then show "path_component S x z"
wenzelm@53640
  1585
      apply (rule_tac path_component_trans[of _ _ y])
wenzelm@53640
  1586
      defer
wenzelm@49653
  1587
      apply (rule path_component_of_subset[OF e(2)])
wenzelm@49653
  1588
      apply (rule convex_imp_path_connected[OF convex_ball, unfolded path_connected_component, rule_format])
wenzelm@60420
  1589
      using \<open>e > 0\<close> as
wenzelm@49653
  1590
      apply auto
wenzelm@49653
  1591
      done
wenzelm@49653
  1592
  qed
wenzelm@49653
  1593
qed
huffman@36583
  1594
huffman@36583
  1595
lemma open_non_path_component:
lp15@64788
  1596
  fixes S :: "'a::real_normed_vector set"
lp15@64788
  1597
  assumes "open S"
lp15@64788
  1598
  shows "open (S - path_component_set S x)"
wenzelm@49653
  1599
  unfolding open_contains_ball
wenzelm@49653
  1600
proof
wenzelm@49653
  1601
  fix y
lp15@64788
  1602
  assume as: "y \<in> S - path_component_set S x"
lp15@64788
  1603
  then obtain e where e: "e > 0" "ball y e \<subseteq> S"
wenzelm@53640
  1604
    using assms [unfolded open_contains_ball]
wenzelm@53640
  1605
    by auto
lp15@64788
  1606
  show "\<exists>e>0. ball y e \<subseteq> S - path_component_set S x"
wenzelm@49653
  1607
    apply (rule_tac x=e in exI)
wenzelm@53640
  1608
    apply rule
wenzelm@60420
  1609
    apply (rule \<open>e>0\<close>)
wenzelm@53640
  1610
    apply rule
wenzelm@53640
  1611
    apply rule
wenzelm@53640
  1612
    defer
wenzelm@49653
  1613
  proof (rule ccontr)
wenzelm@49653
  1614
    fix z
lp15@64788
  1615
    assume "z \<in> ball y e" "\<not> z \<notin> path_component_set S x"
lp15@64788
  1616
    then have "y \<in> path_component_set S x"
wenzelm@60420
  1617
      unfolding not_not mem_Collect_eq using \<open>e>0\<close>
wenzelm@49653
  1618
      apply -
wenzelm@49653
  1619
      apply (rule path_component_trans, assumption)
wenzelm@49653
  1620
      apply (rule path_component_of_subset[OF e(2)])
wenzelm@49653
  1621
      apply (rule convex_imp_path_connected[OF convex_ball, unfolded path_connected_component, rule_format])
wenzelm@49653
  1622
      apply auto
wenzelm@49653
  1623
      done
wenzelm@53640
  1624
    then show False
wenzelm@53640
  1625
      using as by auto
wenzelm@49653
  1626
  qed (insert e(2), auto)
wenzelm@49653
  1627
qed
huffman@36583
  1628
huffman@36583
  1629
lemma connected_open_path_connected:
lp15@64788
  1630
  fixes S :: "'a::real_normed_vector set"
lp15@64788
  1631
  assumes "open S"
lp15@64788
  1632
    and "connected S"
lp15@64788
  1633
  shows "path_connected S"
wenzelm@49653
  1634
  unfolding path_connected_component_set
wenzelm@49653
  1635
proof (rule, rule, rule path_component_subset, rule)
wenzelm@49653
  1636
  fix x y
lp15@64788
  1637
  assume "x \<in> S" and "y \<in> S"
lp15@64788
  1638
  show "y \<in> path_component_set S x"
wenzelm@49653
  1639
  proof (rule ccontr)
wenzelm@53640
  1640
    assume "\<not> ?thesis"
lp15@64788
  1641
    moreover have "path_component_set S x \<inter> S \<noteq> {}"
lp15@64788
  1642
      using \<open>x \<in> S\<close> path_component_eq_empty path_component_subset[of S x]
wenzelm@53640
  1643
      by auto
wenzelm@49653
  1644
    ultimately
wenzelm@49653
  1645
    show False
lp15@64788
  1646
      using \<open>y \<in> S\<close> open_non_path_component[OF assms(1)] open_path_component[OF assms(1)]
wenzelm@53640
  1647
      using assms(2)[unfolded connected_def not_ex, rule_format,
lp15@64788
  1648
        of "path_component_set S x" "S - path_component_set S x"]
wenzelm@49653
  1649
      by auto
wenzelm@49653
  1650
  qed
wenzelm@49653
  1651
qed
huffman@36583
  1652
huffman@36583
  1653
lemma path_connected_continuous_image:
lp15@64788
  1654
  assumes "continuous_on S f"
lp15@64788
  1655
    and "path_connected S"
lp15@64788
  1656
  shows "path_connected (f ` S)"
wenzelm@49653
  1657
  unfolding path_connected_def
wenzelm@49653
  1658
proof (rule, rule)
wenzelm@49653
  1659
  fix x' y'
lp15@64788
  1660
  assume "x' \<in> f ` S" "y' \<in> f ` S"
lp15@64788
  1661
  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
  1662
    by auto
lp15@64788
  1663
  from x y obtain g where "path g \<and> path_image g \<subseteq> S \<and> pathstart g = x \<and> pathfinish g = y"
wenzelm@53640
  1664
    using assms(2)[unfolded path_connected_def] by fast
lp15@64788
  1665
  then show "\<exists>g. path g \<and> path_image g \<subseteq> f ` S \<and> pathstart g = x' \<and> pathfinish g = y'"
wenzelm@53640
  1666
    unfolding x' y'
wenzelm@49653
  1667
    apply (rule_tac x="f \<circ> g" in exI)
wenzelm@49653
  1668
    unfolding path_defs
hoelzl@51481
  1669
    apply (intro conjI continuous_on_compose continuous_on_subset[OF assms(1)])
hoelzl@51481
  1670
    apply auto
wenzelm@49653
  1671
    done
wenzelm@49653
  1672
qed
huffman@36583
  1673
lp15@64788
  1674
lemma path_connected_translationI:
lp15@64788
  1675
  fixes a :: "'a :: topological_group_add"
lp15@64788
  1676
  assumes "path_connected S" shows "path_connected ((\<lambda>x. a + x) ` S)"
lp15@64788
  1677
  by (intro path_connected_continuous_image assms continuous_intros)
lp15@64788
  1678
lp15@64788
  1679
lemma path_connected_translation:
lp15@64788
  1680
  fixes a :: "'a :: topological_group_add"
lp15@64788
  1681
  shows "path_connected ((\<lambda>x. a + x) ` S) = path_connected S"
lp15@64788
  1682
proof -
lp15@64788
  1683
  have "\<forall>x y. op + (x::'a) ` op + (0 - x) ` y = y"
lp15@64788
  1684
    by (simp add: image_image)
lp15@64788
  1685
  then show ?thesis
lp15@64788
  1686
    by (metis (no_types) path_connected_translationI)
lp15@64788
  1687
qed
lp15@64788
  1688
lp15@64788
  1689
lemma path_connected_segment [simp]:
paulson@61518
  1690
    fixes a :: "'a::real_normed_vector"
paulson@61518
  1691
    shows "path_connected (closed_segment a b)"
paulson@61518
  1692
  by (simp add: convex_imp_path_connected)
paulson@61518
  1693
lp15@64788
  1694
lemma path_connected_open_segment [simp]:
paulson@61518
  1695
    fixes a :: "'a::real_normed_vector"
paulson@61518
  1696
    shows "path_connected (open_segment a b)"
paulson@61518
  1697
  by (simp add: convex_imp_path_connected)
paulson@61518
  1698
huffman@36583
  1699
lemma homeomorphic_path_connectedness:
wenzelm@53640
  1700
  "s homeomorphic t \<Longrightarrow> path_connected s \<longleftrightarrow> path_connected t"
lp15@61738
  1701
  unfolding homeomorphic_def homeomorphism_def by (metis path_connected_continuous_image)
huffman@36583
  1702
lp15@64788
  1703
lemma path_connected_empty [simp]: "path_connected {}"
huffman@36583
  1704
  unfolding path_connected_def by auto
huffman@36583
  1705
lp15@64788
  1706
lemma path_connected_singleton [simp]: "path_connected {a}"
huffman@36583
  1707
  unfolding path_connected_def pathstart_def pathfinish_def path_image_def
wenzelm@53640
  1708
  apply clarify
wenzelm@53640
  1709
  apply (rule_tac x="\<lambda>x. a" in exI)
wenzelm@53640
  1710
  apply (simp add: image_constant_conv)
huffman@36583
  1711
  apply (simp add: path_def continuous_on_const)
huffman@36583
  1712
  done
huffman@36583
  1713
wenzelm@49653
  1714
lemma path_connected_Un:
wenzelm@53640
  1715
  assumes "path_connected s"
wenzelm@53640
  1716
    and "path_connected t"
wenzelm@53640
  1717
    and "s \<inter> t \<noteq> {}"
wenzelm@49653
  1718
  shows "path_connected (s \<union> t)"
wenzelm@49653
  1719
  unfolding path_connected_component
wenzelm@49653
  1720
proof (rule, rule)
wenzelm@49653
  1721
  fix x y
wenzelm@49653
  1722
  assume as: "x \<in> s \<union> t" "y \<in> s \<union> t"
wenzelm@53640
  1723
  from assms(3) obtain z where "z \<in> s \<inter> t"
wenzelm@53640
  1724
    by auto
wenzelm@49654
  1725
  then show "path_component (s \<union> t) x y"
wenzelm@49653
  1726
    using as and assms(1-2)[unfolded path_connected_component]
wenzelm@53640
  1727
    apply -
wenzelm@49653
  1728
    apply (erule_tac[!] UnE)+
wenzelm@49653
  1729
    apply (rule_tac[2-3] path_component_trans[of _ _ z])
wenzelm@49653
  1730
    apply (auto simp add:path_component_of_subset [OF Un_upper1] path_component_of_subset[OF Un_upper2])
wenzelm@49653
  1731
    done
wenzelm@49653
  1732
qed
huffman@36583
  1733
huffman@37674
  1734
lemma path_connected_UNION:
huffman@37674
  1735
  assumes "\<And>i. i \<in> A \<Longrightarrow> path_connected (S i)"
wenzelm@49653
  1736
    and "\<And>i. i \<in> A \<Longrightarrow> z \<in> S i"
huffman@37674
  1737
  shows "path_connected (\<Union>i\<in>A. S i)"
wenzelm@49653
  1738
  unfolding path_connected_component
wenzelm@49653
  1739
proof clarify
huffman@37674
  1740
  fix x i y j
huffman@37674
  1741
  assume *: "i \<in> A" "x \<in> S i" "j \<in> A" "y \<in> S j"
wenzelm@49654
  1742
  then have "path_component (S i) x z" and "path_component (S j) z y"
huffman@37674
  1743
    using assms by (simp_all add: path_connected_component)
wenzelm@49654
  1744
  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
  1745
    using *(1,3) by (auto elim!: path_component_of_subset [rotated])
wenzelm@49654
  1746
  then show "path_component (\<Union>i\<in>A. S i) x y"
huffman@37674
  1747
    by (rule path_component_trans)
huffman@37674
  1748
qed
huffman@36583
  1749
lp15@61426
  1750
lemma path_component_path_image_pathstart:
lp15@61426
  1751
  assumes p: "path p" and x: "x \<in> path_image p"
lp15@61426
  1752
  shows "path_component (path_image p) (pathstart p) x"
lp15@61426
  1753
using x
lp15@61426
  1754
proof (clarsimp simp add: path_image_def)
lp15@61426
  1755
  fix y
lp15@61426
  1756
  assume "x = p y" and y: "0 \<le> y" "y \<le> 1"
lp15@61426
  1757
  show "path_component (p ` {0..1}) (pathstart p) (p y)"
lp15@61426
  1758
  proof (cases "y=0")
lp15@61426
  1759
    case True then show ?thesis
lp15@61426
  1760
      by (simp add: path_component_refl_eq pathstart_def)
lp15@61426
  1761
  next
lp15@61426
  1762
    case False have "continuous_on {0..1} (p o (op*y))"
lp15@61426
  1763
      apply (rule continuous_intros)+
lp15@61426
  1764
      using p [unfolded path_def] y
lp15@61426
  1765
      apply (auto simp: mult_le_one intro: continuous_on_subset [of _ p])
lp15@61426
  1766
      done
lp15@61426
  1767
    then have "path (\<lambda>u. p (y * u))"
lp15@61426
  1768
      by (simp add: path_def)
lp15@61426
  1769
    then show ?thesis
lp15@61426
  1770
      apply (simp add: path_component_def)
lp15@61426
  1771
      apply (rule_tac x = "\<lambda>u. p (y * u)" in exI)
lp15@61426
  1772
      apply (intro conjI)
lp15@61426
  1773
      using y False
lp15@61426
  1774
      apply (auto simp: mult_le_one pathstart_def pathfinish_def path_image_def)
lp15@61426
  1775
      done
lp15@61426
  1776
  qed
lp15@61426
  1777
qed
lp15@61426
  1778
lp15@61426
  1779
lemma path_connected_path_image: "path p \<Longrightarrow> path_connected(path_image p)"
lp15@61426
  1780
  unfolding path_connected_component
lp15@61426
  1781
  by (meson path_component_path_image_pathstart path_component_sym path_component_trans)
lp15@61426
  1782
lp15@64788
  1783
lemma path_connected_path_component [simp]:
lp15@61426
  1784
   "path_connected (path_component_set s x)"
lp15@61426
  1785
proof -
lp15@61426
  1786
  { fix y z
lp15@61426
  1787
    assume pa: "path_component s x y" "path_component s x z"
lp15@61426
  1788
    then have pae: "path_component_set s x = path_component_set s y"
lp15@61426
  1789
      using path_component_eq by auto
lp15@61426
  1790
    have yz: "path_component s y z"
lp15@61426
  1791
      using pa path_component_sym path_component_trans by blast
lp15@61426
  1792
    then have "\<exists>g. path g \<and> path_image g \<subseteq> path_component_set s x \<and> pathstart g = y \<and> pathfinish g = z"
lp15@61426
  1793
      apply (simp add: path_component_def, clarify)
lp15@61426
  1794
      apply (rule_tac x=g in exI)
lp15@61426
  1795
      by (simp add: pae path_component_maximal path_connected_path_image pathstart_in_path_image)
lp15@61426
  1796
  }
lp15@61426
  1797
  then show ?thesis
lp15@61426
  1798
    by (simp add: path_connected_def)
lp15@61426
  1799
qed
lp15@61426
  1800
lp15@61426
  1801
lemma path_component: "path_component s x y \<longleftrightarrow> (\<exists>t. path_connected t \<and> t \<subseteq> s \<and> x \<in> t \<and> y \<in> t)"
lp15@61426
  1802
  apply (intro iffI)
lp15@61426
  1803
  apply (metis path_connected_path_image path_defs(5) pathfinish_in_path_image pathstart_in_path_image)
lp15@61426
  1804
  using path_component_of_subset path_connected_component by blast
lp15@61426
  1805
lp15@61426
  1806
lemma path_component_path_component [simp]:
lp15@61426
  1807
   "path_component_set (path_component_set s x) x = path_component_set s x"
lp15@61426
  1808
proof (cases "x \<in> s")
lp15@61426
  1809
  case True show ?thesis
lp15@61426
  1810
    apply (rule subset_antisym)
lp15@61426
  1811
    apply (simp add: path_component_subset)
lp15@61426
  1812
    by (simp add: True path_component_maximal path_component_refl path_connected_path_component)
lp15@61426
  1813
next
lp15@61426
  1814
  case False then show ?thesis
lp15@61426
  1815
    by (metis False empty_iff path_component_eq_empty)
lp15@61426
  1816
qed
lp15@61426
  1817
lp15@61426
  1818
lemma path_component_subset_connected_component:
lp15@61426
  1819
   "(path_component_set s x) \<subseteq> (connected_component_set s x)"
lp15@61426
  1820
proof (cases "x \<in> s")
lp15@61426
  1821
  case True show ?thesis
lp15@61426
  1822
    apply (rule connected_component_maximal)
lp15@61426
  1823
    apply (auto simp: True path_component_subset path_component_refl path_connected_imp_connected path_connected_path_component)
lp15@61426
  1824
    done
lp15@61426
  1825
next
lp15@61426
  1826
  case False then show ?thesis
lp15@61426
  1827
    using path_component_eq_empty by auto
lp15@61426
  1828
qed
wenzelm@49653
  1829
lp15@62620
  1830
subsection\<open>Lemmas about path-connectedness\<close>
lp15@62620
  1831
lp15@62620
  1832
lemma path_connected_linear_image:
lp15@62620
  1833
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
lp15@62620
  1834
  assumes "path_connected s" "bounded_linear f"
lp15@62620
  1835
    shows "path_connected(f ` s)"
lp15@62620
  1836
by (auto simp: linear_continuous_on assms path_connected_continuous_image)
lp15@62620
  1837
lp15@62620
  1838
lemma is_interval_path_connected: "is_interval s \<Longrightarrow> path_connected s"
lp15@62620
  1839
  by (simp add: convex_imp_path_connected is_interval_convex)
lp15@62620
  1840
lp15@62843
  1841
lemma linear_homeomorphism_image:
lp15@62843
  1842
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@62620
  1843
  assumes "linear f" "inj f"
lp15@62843
  1844
    obtains g where "homeomorphism (f ` S) S g f"
lp15@62843
  1845
using linear_injective_left_inverse [OF assms]
lp15@62843
  1846
apply clarify
lp15@62843
  1847
apply (rule_tac g=g in that)
lp15@62843
  1848
using assms
lp15@62843
  1849
apply (auto simp: homeomorphism_def eq_id_iff [symmetric] image_comp comp_def linear_conv_bounded_linear linear_continuous_on)
lp15@62843
  1850
done
lp15@62843
  1851
lp15@62843
  1852
lemma linear_homeomorphic_image:
lp15@62843
  1853
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@62843
  1854
  assumes "linear f" "inj f"
lp15@62843
  1855
    shows "S homeomorphic f ` S"
lp15@62843
  1856
by (meson homeomorphic_def homeomorphic_sym linear_homeomorphism_image [OF assms])
lp15@62620
  1857
lp15@62620
  1858
lemma path_connected_Times:
lp15@62620
  1859
  assumes "path_connected s" "path_connected t"
lp15@62620
  1860
    shows "path_connected (s \<times> t)"
lp15@62620
  1861
proof (simp add: path_connected_def Sigma_def, clarify)
lp15@62620
  1862
  fix x1 y1 x2 y2
lp15@62620
  1863
  assume "x1 \<in> s" "y1 \<in> t" "x2 \<in> s" "y2 \<in> t"
lp15@62620
  1864
  obtain g where "path g" and g: "path_image g \<subseteq> s" and gs: "pathstart g = x1" and gf: "pathfinish g = x2"
lp15@62620
  1865
    using \<open>x1 \<in> s\<close> \<open>x2 \<in> s\<close> assms by (force simp: path_connected_def)
lp15@62620
  1866
  obtain h where "path h" and h: "path_image h \<subseteq> t" and hs: "pathstart h = y1" and hf: "pathfinish h = y2"
lp15@62620
  1867
    using \<open>y1 \<in> t\<close> \<open>y2 \<in> t\<close> assms by (force simp: path_connected_def)
lp15@62620
  1868
  have "path (\<lambda>z. (x1, h z))"
lp15@62620
  1869
    using \<open>path h\<close>
lp15@62620
  1870
    apply (simp add: path_def)
lp15@62620
  1871
    apply (rule continuous_on_compose2 [where f = h])
lp15@62620
  1872
    apply (rule continuous_intros | force)+
lp15@62620
  1873
    done
lp15@62620
  1874
  moreover have "path (\<lambda>z. (g z, y2))"
lp15@62620
  1875
    using \<open>path g\<close>
lp15@62620
  1876
    apply (simp add: path_def)
lp15@62620
  1877
    apply (rule continuous_on_compose2 [where f = g])
lp15@62620
  1878
    apply (rule continuous_intros | force)+
lp15@62620
  1879
    done
lp15@62620
  1880
  ultimately have 1: "path ((\<lambda>z. (x1, h z)) +++ (\<lambda>z. (g z, y2)))"
lp15@62620
  1881
    by (metis hf gs path_join_imp pathstart_def pathfinish_def)
lp15@62620
  1882
  have "path_image ((\<lambda>z. (x1, h z)) +++ (\<lambda>z. (g z, y2))) \<subseteq> path_image (\<lambda>z. (x1, h z)) \<union> path_image (\<lambda>z. (g z, y2))"
lp15@62620
  1883
    by (rule Path_Connected.path_image_join_subset)
lp15@62620
  1884
  also have "... \<subseteq> (\<Union>x\<in>s. \<Union>x1\<in>t. {(x, x1)})"
lp15@62620
  1885
    using g h \<open>x1 \<in> s\<close> \<open>y2 \<in> t\<close> by (force simp: path_image_def)
lp15@62620
  1886
  finally have 2: "path_image ((\<lambda>z. (x1, h z)) +++ (\<lambda>z. (g z, y2))) \<subseteq> (\<Union>x\<in>s. \<Union>x1\<in>t. {(x, x1)})" .
lp15@62620
  1887
  show "\<exists>g. path g \<and> path_image g \<subseteq> (\<Union>x\<in>s. \<Union>x1\<in>t. {(x, x1)}) \<and>
lp15@62620
  1888
            pathstart g = (x1, y1) \<and> pathfinish g = (x2, y2)"
lp15@62620
  1889
    apply (intro exI conjI)
lp15@62620
  1890
       apply (rule 1)
lp15@62620
  1891
      apply (rule 2)
lp15@62620
  1892
     apply (metis hs pathstart_def pathstart_join)
lp15@62620
  1893
    by (metis gf pathfinish_def pathfinish_join)
lp15@62620
  1894
qed
lp15@62620
  1895
lp15@62620
  1896
lemma is_interval_path_connected_1:
lp15@62620
  1897
  fixes s :: "real set"
lp15@62620
  1898
  shows "is_interval s \<longleftrightarrow> path_connected s"
lp15@62620
  1899
using is_interval_connected_1 is_interval_path_connected path_connected_imp_connected by blast
lp15@62620
  1900
lp15@62620
  1901
lp15@62948
  1902
lemma Union_path_component [simp]:
lp15@62948
  1903
   "Union {path_component_set S x |x. x \<in> S} = S"
lp15@62948
  1904
apply (rule subset_antisym)
lp15@62948
  1905
using path_component_subset apply force
lp15@62948
  1906
using path_component_refl by auto
lp15@62948
  1907
lp15@62948
  1908
lemma path_component_disjoint:
lp15@62948
  1909
   "disjnt (path_component_set S a) (path_component_set S b) \<longleftrightarrow>
lp15@62948
  1910
    (a \<notin> path_component_set S b)"
lp15@62948
  1911
apply (auto simp: disjnt_def)
lp15@62948
  1912
using path_component_eq apply fastforce
lp15@62948
  1913
using path_component_sym path_component_trans by blast
lp15@62948
  1914
lp15@62948
  1915
lemma path_component_eq_eq:
lp15@62948
  1916
   "path_component S x = path_component S y \<longleftrightarrow>
lp15@62948
  1917
        (x \<notin> S) \<and> (y \<notin> S) \<or> x \<in> S \<and> y \<in> S \<and> path_component S x y"
lp15@62948
  1918
apply (rule iffI, metis (no_types) path_component_mem(1) path_component_refl)
lp15@62948
  1919
apply (erule disjE, metis Collect_empty_eq_bot path_component_eq_empty)
lp15@62948
  1920
apply (rule ext)
lp15@62948
  1921
apply (metis path_component_trans path_component_sym)
lp15@62948
  1922
done
lp15@62948
  1923
lp15@62948
  1924
lemma path_component_unique:
lp15@62948
  1925
  assumes "x \<in> c" "c \<subseteq> S" "path_connected c"
lp15@62948
  1926
          "\<And>c'. \<lbrakk>x \<in> c'; c' \<subseteq> S; path_connected c'\<rbrakk> \<Longrightarrow> c' \<subseteq> c"
lp15@62948
  1927
   shows "path_component_set S x = c"
lp15@62948
  1928
apply (rule subset_antisym)
lp15@62948
  1929
using assms
lp15@62948
  1930
apply (metis mem_Collect_eq subsetCE path_component_eq_eq path_component_subset path_connected_path_component)
lp15@62948
  1931
by (simp add: assms path_component_maximal)
lp15@62948
  1932
lp15@62948
  1933
lemma path_component_intermediate_subset:
lp15@62948
  1934
   "path_component_set u a \<subseteq> t \<and> t \<subseteq> u
lp15@62948
  1935
        \<Longrightarrow> path_component_set t a = path_component_set u a"
lp15@62948
  1936
by (metis (no_types) path_component_mono path_component_path_component subset_antisym)
lp15@62948
  1937
lp15@62948
  1938
lemma complement_path_component_Union:
lp15@62948
  1939
  fixes x :: "'a :: topological_space"
lp15@62948
  1940
  shows "S - path_component_set S x =
lp15@62948
  1941
         \<Union>({path_component_set S y| y. y \<in> S} - {path_component_set S x})"
lp15@62948
  1942
proof -
lp15@62948
  1943
  have *: "(\<And>x. x \<in> S - {a} \<Longrightarrow> disjnt a x) \<Longrightarrow> \<Union>S - a = \<Union>(S - {a})"
lp15@62948
  1944
    for a::"'a set" and S
lp15@62948
  1945
    by (auto simp: disjnt_def)
lp15@62948
  1946
  have "\<And>y. y \<in> {path_component_set S x |x. x \<in> S} - {path_component_set S x}
lp15@62948
  1947
            \<Longrightarrow> disjnt (path_component_set S x) y"
lp15@62948
  1948
    using path_component_disjoint path_component_eq by fastforce
lp15@62948
  1949
  then have "\<Union>{path_component_set S x |x. x \<in> S} - path_component_set S x =
lp15@62948
  1950
             \<Union>({path_component_set S y |y. y \<in> S} - {path_component_set S x})"
lp15@62948
  1951
    by (meson *)
lp15@62948
  1952
  then show ?thesis by simp
lp15@62948
  1953
qed
lp15@62948
  1954
lp15@62948
  1955
wenzelm@60420
  1956
subsection \<open>Sphere is path-connected\<close>
hoelzl@37489
  1957
huffman@36583
  1958
lemma path_connected_punctured_universe:
huffman@37674
  1959
  assumes "2 \<le> DIM('a::euclidean_space)"
lp15@61426
  1960
  shows "path_connected (- {a::'a})"
wenzelm@49653
  1961
proof -
hoelzl@50526
  1962
  let ?A = "{x::'a. \<exists>i\<in>Basis. x \<bullet> i < a \<bullet> i}"
hoelzl@50526
  1963
  let ?B = "{x::'a. \<exists>i\<in>Basis. a \<bullet> i < x \<bullet> i}"
huffman@36583
  1964
wenzelm@49653
  1965
  have A: "path_connected ?A"
wenzelm@49653
  1966
    unfolding Collect_bex_eq
huffman@37674
  1967
  proof (rule path_connected_UNION)
hoelzl@50526
  1968
    fix i :: 'a
hoelzl@50526
  1969
    assume "i \<in> Basis"
wenzelm@53640
  1970
    then show "(\<Sum>i\<in>Basis. (a \<bullet> i - 1)*\<^sub>R i) \<in> {x::'a. x \<bullet> i < a \<bullet> i}"
wenzelm@53640
  1971
      by simp
hoelzl@50526
  1972
    show "path_connected {x. x \<bullet> i < a \<bullet> i}"
hoelzl@50526
  1973
      using convex_imp_path_connected [OF convex_halfspace_lt, of i "a \<bullet> i"]
hoelzl@50526
  1974
      by (simp add: inner_commute)
huffman@37674
  1975
  qed
wenzelm@53640
  1976
  have B: "path_connected ?B"
wenzelm@53640
  1977
    unfolding Collect_bex_eq
huffman@37674
  1978
  proof (rule path_connected_UNION)
hoelzl@50526
  1979
    fix i :: 'a
hoelzl@50526
  1980
    assume "i \<in> Basis"
wenzelm@53640
  1981
    then show "(\<Sum>i\<in>Basis. (a \<bullet> i + 1) *\<^sub>R i) \<in> {x::'a. a \<bullet> i < x \<bullet> i}"
wenzelm@53640
  1982
      by simp
hoelzl@50526
  1983
    show "path_connected {x. a \<bullet> i < x \<bullet> i}"
hoelzl@50526
  1984
      using convex_imp_path_connected [OF convex_halfspace_gt, of "a \<bullet> i" i]
hoelzl@50526
  1985
      by (simp add: inner_commute)
huffman@37674
  1986
  qed
wenzelm@53640
  1987
  obtain S :: "'a set" where "S \<subseteq> Basis" and "card S = Suc (Suc 0)"
wenzelm@53640
  1988
    using ex_card[OF assms]
wenzelm@53640
  1989
    by auto
wenzelm@53640
  1990
  then obtain b0 b1 :: 'a where "b0 \<in> Basis" and "b1 \<in> Basis" and "b0 \<noteq> b1"
hoelzl@50526
  1991
    unfolding card_Suc_eq by auto
wenzelm@53640
  1992
  then have "a + b0 - b1 \<in> ?A \<inter> ?B"
wenzelm@53640
  1993
    by (auto simp: inner_simps inner_Basis)
wenzelm@53640
  1994
  then have "?A \<inter> ?B \<noteq> {}"
wenzelm@53640
  1995
    by fast
huffman@37674
  1996
  with A B have "path_connected (?A \<union> ?B)"
huffman@37674
  1997
    by (rule path_connected_Un)
hoelzl@50526
  1998
  also have "?A \<union> ?B = {x. \<exists>i\<in>Basis. x \<bullet> i \<noteq> a \<bullet> i}"
huffman@37674
  1999
    unfolding neq_iff bex_disj_distrib Collect_disj_eq ..
huffman@37674
  2000
  also have "\<dots> = {x. x \<noteq> a}"
wenzelm@53640
  2001
    unfolding euclidean_eq_iff [where 'a='a]
wenzelm@53640
  2002
    by (simp add: Bex_def)
lp15@61426
  2003
  also have "\<dots> = - {a}"
wenzelm@53640
  2004
    by auto
huffman@37674
  2005
  finally show ?thesis .
huffman@37674
  2006
qed
huffman@36583
  2007
lp15@64006
  2008
corollary connected_punctured_universe:
lp15@64006
  2009
  "2 \<le> DIM('N::euclidean_space) \<Longrightarrow> connected(- {a::'N})"
lp15@64006
  2010
  by (simp add: path_connected_punctured_universe path_connected_imp_connected)
lp15@64006
  2011
huffman@37674
  2012
lemma path_connected_sphere:
lp15@64788
  2013
  fixes a :: "'a :: euclidean_space"
lp15@64788
  2014
  assumes "2 \<le> DIM('a)"
lp15@64788
  2015
  shows "path_connected(sphere a r)"
lp15@64788
  2016
proof (cases r "0::real" rule: linorder_cases)
lp15@64788
  2017
  case less
wenzelm@53640
  2018
  then show ?thesis
lp15@64788
  2019
    by (simp add: path_connected_empty)
huffman@37674
  2020
next
lp15@64788
  2021
  case equal
wenzelm@53640
  2022
  then show ?thesis
lp15@64788
  2023
    by (simp add: path_connected_singleton)
huffman@37674
  2024
next
lp15@64788
  2025
  case greater
lp15@64788
  2026
  then have eq: "(sphere (0::'a) r) = (\<lambda>x. (r / norm x) *\<^sub>R x) ` (- {0::'a})"
lp15@64788
  2027
    by (force simp: image_iff split: if_split_asm)
lp15@64788
  2028
  have "continuous_on (- {0::'a}) (\<lambda>x. (r / norm x) *\<^sub>R x)"
lp15@64788
  2029
    by (intro continuous_intros) auto
lp15@64788
  2030
  then have "path_connected ((\<lambda>x. (r / norm x) *\<^sub>R x) ` (- {0::'a}))"
lp15@64788
  2031
    by (intro path_connected_continuous_image path_connected_punctured_universe assms)
lp15@64788
  2032
  with eq have "path_connected (sphere (0::'a) r)"
lp15@64788
  2033
    by auto
lp15@64788
  2034
  then have "path_connected(op +a ` (sphere (0::'a) r))"
lp15@64788
  2035
    by (simp add: path_connected_translation)
wenzelm@53640
  2036
  then show ?thesis
lp15@64788
  2037
    by (metis add.right_neutral sphere_translation)
lp15@64788
  2038
qed
lp15@64788
  2039
lp15@64788
  2040
lemma connected_sphere:
lp15@64788
  2041
    fixes a :: "'a :: euclidean_space"
lp15@64788
  2042
    assumes "2 \<le> DIM('a)"
lp15@64788
  2043
      shows "connected(sphere a r)"
lp15@64788
  2044
  using path_connected_sphere [OF assms]
lp15@64788
  2045
  by (simp add: path_connected_imp_connected)
lp15@64788
  2046
huffman@36583
  2047
lp15@61426
  2048
corollary path_connected_complement_bounded_convex:
lp15@61426
  2049
    fixes s :: "'a :: euclidean_space set"
lp15@61426
  2050
    assumes "bounded s" "convex s" and 2: "2 \<le> DIM('a)"
lp15@61426
  2051
    shows "path_connected (- s)"
lp15@64788
  2052
proof (cases "s = {}")
lp15@61426
  2053
  case True then show ?thesis
lp15@61426
  2054
    using convex_imp_path_connected by auto
lp15@61426
  2055
next
lp15@61426
  2056
  case False
lp15@61426
  2057
  then obtain a where "a \<in> s" by auto
lp15@61426
  2058
  { fix x y assume "x \<notin> s" "y \<notin> s"
wenzelm@61808
  2059
    then have "x \<noteq> a" "y \<noteq> a" using \<open>a \<in> s\<close> by auto
lp15@61426
  2060
    then have bxy: "bounded(insert x (insert y s))"
wenzelm@61808
  2061
      by (simp add: \<open>bounded s\<close>)
lp15@61426
  2062
    then obtain B::real where B: "0 < B" and Bx: "norm (a - x) < B" and By: "norm (a - y) < B"
lp15@61426
  2063
                          and "s \<subseteq> ball a B"
lp15@61426
  2064
      using bounded_subset_ballD [OF bxy, of a] by (auto simp: dist_norm)
wenzelm@63040
  2065
    define C where "C = B / norm(x - a)"
lp15@61426
  2066
    { fix u
lp15@61426
  2067
      assume u: "(1 - u) *\<^sub>R x + u *\<^sub>R (a + C *\<^sub>R (x - a)) \<in> s" and "0 \<le> u" "u \<le> 1"
lp15@61426
  2068
      have CC: "1 \<le> 1 + (C - 1) * u"
wenzelm@61808
  2069
        using \<open>x \<noteq> a\<close> \<open>0 \<le> u\<close>
lp15@61426
  2070
        apply (simp add: C_def divide_simps norm_minus_commute)
lp15@61762
  2071
        using Bx by auto
lp15@61426
  2072
      have *: "\<And>v. (1 - u) *\<^sub>R x + u *\<^sub>R (a + v *\<^sub>R (x - a)) = a + (1 + (v - 1) * u) *\<^sub>R (x - a)"
lp15@61426
  2073
        by (simp add: algebra_simps)
lp15@61426
  2074
      have "a + ((1 / (1 + C * u - u)) *\<^sub>R x + ((u / (1 + C * u - u)) *\<^sub>R a + (C * u / (1 + C * u - u)) *\<^sub>R x)) =
lp15@61426
  2075
            (1 + (u / (1 + C * u - u))) *\<^sub>R a + ((1 / (1 + C * u - u)) + (C * u / (1 + C * u - u))) *\<^sub>R x"
lp15@61426
  2076
        by (simp add: algebra_simps)
lp15@61426
  2077
      also have "... = (1 + (u / (1 + C * u - u))) *\<^sub>R a + (1 + (u / (1 + C * u - u))) *\<^sub>R x"
lp15@61426
  2078
        using CC by (simp add: field_simps)
lp15@61426
  2079
      also have "... = x + (1 + (u / (1 + C * u - u))) *\<^sub>R a + (u / (1 + C * u - u)) *\<^sub>R x"
lp15@61426
  2080
        by (simp add: algebra_simps)
lp15@61426
  2081
      also have "... = x + ((1 / (1 + C * u - u)) *\<^sub>R a +
lp15@61426
  2082
              ((u / (1 + C * u - u)) *\<^sub>R x + (C * u / (1 + C * u - u)) *\<^sub>R a))"
lp15@61426
  2083
        using CC by (simp add: field_simps) (simp add: add_divide_distrib scaleR_add_left)
lp15@61426
  2084
      finally have xeq: "(1 - 1 / (1 + (C - 1) * u)) *\<^sub>R a + (1 / (1 + (C - 1) * u)) *\<^sub>R (a + (1 + (C - 1) * u) *\<^sub>R (x - a)) = x"
lp15@61426
  2085
        by (simp add: algebra_simps)
lp15@61426
  2086
      have False
wenzelm@61808
  2087
        using \<open>convex s\<close>
lp15@61426
  2088
        apply (simp add: convex_alt)
lp15@61426
  2089
        apply (drule_tac x=a in bspec)
wenzelm@61808
  2090
         apply (rule  \<open>a \<in> s\<close>)
lp15@61426
  2091
        apply (drule_tac x="a + (1 + (C - 1) * u) *\<^sub>R (x - a)" in bspec)
lp15@61426
  2092
         using u apply (simp add: *)
lp15@61426
  2093
        apply (drule_tac x="1 / (1 + (C - 1) * u)" in spec)
wenzelm@61808
  2094
        using \<open>x \<noteq> a\<close> \<open>x \<notin> s\<close> \<open>0 \<le> u\<close> CC
lp15@61426
  2095
        apply (auto simp: xeq)
lp15@61426
  2096
        done
lp15@61426
  2097
    }
lp15@61426
  2098
    then have pcx: "path_component (- s) x (a + C *\<^sub>R (x - a))"
lp15@61426
  2099
      by (force simp: closed_segment_def intro!: path_connected_linepath)
wenzelm@63040
  2100
    define D where "D = B / norm(y - a)"  \<comment>\<open>massive duplication with the proof above\<close>
lp15@61426
  2101
    { fix u
lp15@61426
  2102
      assume u: "(1 - u) *\<^sub>R y + u *\<^sub>R (a + D *\<^sub>R (y - a)) \<in> s" and "0 \<le> u" "u \<le> 1"
lp15@61426
  2103
      have DD: "1 \<le> 1 + (D - 1) * u"
wenzelm@61808
  2104
        using \<open>y \<noteq> a\<close> \<open>0 \<le> u\<close>
lp15@61426
  2105
        apply (simp add: D_def divide_simps norm_minus_commute)
lp15@61762
  2106
        using By by auto
lp15@61426
  2107
      have *: "\<And>v. (1 - u) *\<^sub>R y + u *\<^sub>R (a + v *\<^sub>R (y - a)) = a + (1 + (v - 1) * u) *\<^sub>R (y - a)"
lp15@61426
  2108
        by (simp add: algebra_simps)
lp15@61426
  2109
      have "a + ((1 / (1 + D * u - u)) *\<^sub>R y + ((u / (1 + D * u - u)) *\<^sub>R a + (D * u / (1 + D * u - u)) *\<^sub>R y)) =
lp15@61426
  2110
            (1 + (u / (1 + D * u - u))) *\<^sub>R a + ((1 / (1 + D * u - u)) + (D * u / (1 + D * u - u))) *\<^sub>R y"
lp15@61426
  2111
        by (simp add: algebra_simps)
lp15@61426
  2112
      also have "... = (1 + (u / (1 + D * u - u))) *\<^sub>R a + (1 + (u / (1 + D * u - u))) *\<^sub>R y"
lp15@61426
  2113
        using DD by (simp add: field_simps)
lp15@61426
  2114
      also have "... = y + (1 + (u / (1 + D * u - u))) *\<^sub>R a + (u / (1 + D * u - u)) *\<^sub>R y"
lp15@61426
  2115
        by (simp add: algebra_simps)
lp15@61426
  2116
      also have "... = y + ((1 / (1 + D * u - u)) *\<^sub>R a +
lp15@61426
  2117
              ((u / (1 + D * u - u)) *\<^sub>R y + (D * u / (1 + D * u - u)) *\<^sub>R a))"
lp15@61426
  2118
        using DD by (simp add: field_simps) (simp add: add_divide_distrib scaleR_add_left)
lp15@61426
  2119
      finally have xeq: "(1 - 1 / (1 + (D - 1) * u)) *\<^sub>R a + (1 / (1 + (D - 1) * u)) *\<^sub>R (a + (1 + (D - 1) * u) *\<^sub>R (y - a)) = y"
lp15@61426
  2120
        by (simp add: algebra_simps)
lp15@61426
  2121
      have False
wenzelm@61808
  2122
        using \<open>convex s\<close>
lp15@61426
  2123
        apply (simp add: convex_alt)
lp15@61426
  2124
        apply (drule_tac x=a in bspec)
wenzelm@61808
  2125
         apply (rule  \<open>a \<in> s\<close>)
lp15@61426
  2126
        apply (drule_tac x="a + (1 + (D - 1) * u) *\<^sub>R (y - a)" in bspec)
lp15@61426
  2127
         using u apply (simp add: *)
lp15@61426
  2128
        apply (drule_tac x="1 / (1 + (D - 1) * u)" in spec)
wenzelm@61808
  2129
        using \<open>y \<noteq> a\<close> \<open>y \<notin> s\<close> \<open>0 \<le> u\<close> DD
lp15@61426
  2130
        apply (auto simp: xeq)
lp15@61426
  2131
        done
lp15@61426
  2132
    }
lp15@61426
  2133
    then have pdy: "path_component (- s) y (a + D *\<^sub>R (y - a))"
lp15@61426
  2134
      by (force simp: closed_segment_def intro!: path_connected_linepath)
lp15@61426
  2135
    have pyx: "path_component (- s) (a + D *\<^sub>R (y - a)) (a + C *\<^sub>R (x - a))"
lp15@64788
  2136
      apply (rule path_component_of_subset [of "sphere a B"])
wenzelm@61808
  2137
       using \<open>s \<subseteq> ball a B\<close>
lp15@61426
  2138
       apply (force simp: ball_def dist_norm norm_minus_commute)
lp15@61426
  2139
      apply (rule path_connected_sphere [OF 2, of a B, simplified path_connected_component, rule_format])
lp15@64788
  2140
       using \<open>x \<noteq> a\<close>  using \<open>y \<noteq> a\<close>  B apply (auto simp: dist_norm C_def D_def)
lp15@61426
  2141
      done
lp15@61426
  2142
    have "path_component (- s) x y"
lp15@61426
  2143
      by (metis path_component_trans path_component_sym pcx pdy pyx)
lp15@61426
  2144
  }
lp15@61426
  2145
  then show ?thesis
lp15@61426
  2146
    by (auto simp: path_connected_component)
lp15@61426
  2147
qed
lp15@61426
  2148
lp15@61426
  2149
lp15@61426
  2150
lemma connected_complement_bounded_convex:
lp15@61426
  2151
    fixes s :: "'a :: euclidean_space set"
lp15@61426
  2152
    assumes "bounded s" "convex s" "2 \<le> DIM('a)"
lp15@61426
  2153
      shows  "connected (- s)"
lp15@61426
  2154
  using path_connected_complement_bounded_convex [OF assms] path_connected_imp_connected by blast
lp15@61426
  2155
lp15@61426
  2156
lemma connected_diff_ball:
lp15@61426
  2157
    fixes s :: "'a :: euclidean_space set"
lp15@61426
  2158
    assumes "connected s" "cball a r \<subseteq> s" "2 \<le> DIM('a)"
lp15@61426
  2159
      shows "connected (s - ball a r)"
lp15@61426
  2160
  apply (rule connected_diff_open_from_closed [OF ball_subset_cball])
lp15@61426
  2161
  using assms connected_sphere
lp15@61426
  2162
  apply (auto simp: cball_diff_eq_sphere dist_norm)
lp15@61426
  2163
  done
lp15@61426
  2164
lp15@62381
  2165
proposition connected_open_delete:
lp15@62381
  2166
  assumes "open S" "connected S" and 2: "2 \<le> DIM('N::euclidean_space)"
lp15@62381
  2167
    shows "connected(S - {a::'N})"
lp15@62381
  2168
proof (cases "a \<in> S")
lp15@62381
  2169
  case True
lp15@62381
  2170
  with \<open>open S\<close> obtain \<epsilon> where "\<epsilon> > 0" and \<epsilon>: "cball a \<epsilon> \<subseteq> S"
lp15@62381
  2171
    using open_contains_cball_eq by blast
lp15@62381
  2172
  have "dist a (a + \<epsilon> *\<^sub>R (SOME i. i \<in> Basis)) = \<epsilon>"
lp15@62381
  2173
    by (simp add: dist_norm SOME_Basis \<open>0 < \<epsilon>\<close> less_imp_le)
lp15@62381
  2174
  with \<epsilon> have "\<Inter>{S - ball a r |r. 0 < r \<and> r < \<epsilon>} \<subseteq> {} \<Longrightarrow> False"
lp15@62381
  2175
    apply (drule_tac c="a + scaleR (\<epsilon>) ((SOME i. i \<in> Basis))" in subsetD)
lp15@62381
  2176
    by auto
lp15@62381
  2177
  then have nonemp: "(\<Inter>{S - ball a r |r. 0 < r \<and> r < \<epsilon>}) = {} \<Longrightarrow> False"
lp15@62381
  2178
    by auto
lp15@62381
  2179
  have con: "\<And>r. r < \<epsilon> \<Longrightarrow> connected (S - ball a r)"
lp15@62381
  2180
    using \<epsilon> by (force intro: connected_diff_ball [OF \<open>connected S\<close> _ 2])
lp15@62381
  2181
  have "x \<in> \<Union>{S - ball a r |r. 0 < r \<and> r < \<epsilon>}" if "x \<in> S - {a}" for x
lp15@62381
  2182
    apply (rule UnionI [of "S - ball a (min \<epsilon> (dist a x) / 2)"])
lp15@62381
  2183
     using that \<open>0 < \<epsilon>\<close> apply (simp_all add:)
lp15@62381
  2184
    apply (rule_tac x="min \<epsilon> (dist a x) / 2" in exI)
lp15@62381
  2185
    apply auto
lp15@62381
  2186
    done
lp15@62381
  2187
  then have "S - {a} = \<Union>{S - ball a r | r. 0 < r \<and> r < \<epsilon>}"
lp15@62381
  2188
    by auto
lp15@62381
  2189
  then show ?thesis
lp15@62381
  2190
    by (auto intro: connected_Union con dest!: nonemp)
lp15@62381
  2191
next
lp15@62381
  2192
  case False then show ?thesis
lp15@62381
  2193
    by (simp add: \<open>connected S\<close>)
lp15@62381
  2194
qed
lp15@62381
  2195
lp15@62381
  2196
corollary path_connected_open_delete:
lp15@62381
  2197
  assumes "open S" "connected S" and 2: "2 \<le> DIM('N::euclidean_space)"
lp15@62381
  2198
    shows "path_connected(S - {a::'N})"
lp15@62381
  2199
by (simp add: assms connected_open_delete connected_open_path_connected open_delete)
lp15@62381
  2200
lp15@62381
  2201
corollary path_connected_punctured_ball:
lp15@62381
  2202
   "2 \<le> DIM('N::euclidean_space) \<Longrightarrow> path_connected(ball a r - {a::'N})"
lp15@62381
  2203
by (simp add: path_connected_open_delete)
lp15@62381
  2204
lp15@63151
  2205
corollary connected_punctured_ball:
lp15@62381
  2206
   "2 \<le> DIM('N::euclidean_space) \<Longrightarrow> connected(ball a r - {a::'N})"
lp15@62381
  2207
by (simp add: connected_open_delete)
lp15@62381
  2208
lp15@63151
  2209
corollary connected_open_delete_finite:
lp15@63151
  2210
  fixes S T::"'a::euclidean_space set"
lp15@63151
  2211
  assumes S: "open S" "connected S" and 2: "2 \<le> DIM('a)" and "finite T"
hoelzl@63594
  2212
  shows "connected(S - T)"
hoelzl@63594
  2213
  using \<open>finite T\<close> S
lp15@63151
  2214
proof (induct T)
lp15@63151
  2215
  case empty
lp15@63151
  2216
  show ?case using \<open>connected S\<close> by simp
lp15@63151
  2217
next
lp15@63151
  2218
  case (insert x F)
lp15@63151
  2219
  then have "connected (S-F)" by auto
lp15@63151
  2220
  moreover have "open (S - F)" using finite_imp_closed[OF \<open>finite F\<close>] \<open>open S\<close> by auto
lp15@63151
  2221
  ultimately have "connected (S - F - {x})" using connected_open_delete[OF _ _ 2] by auto
lp15@63151
  2222
  thus ?case by (metis Diff_insert)
lp15@63151
  2223
qed
lp15@63151
  2224
lp15@64788
  2225
lemma sphere_1D_doubleton_zero:
lp15@64788
  2226
  assumes 1: "DIM('a) = 1" and "r > 0"
lp15@64788
  2227
  obtains x y::"'a::euclidean_space"
lp15@64788
  2228
    where "sphere 0 r = {x,y} \<and> dist x y = 2*r"
lp15@64788
  2229
proof -
lp15@64788
  2230
  obtain b::'a where b: "Basis = {b}"
lp15@64788
  2231
    using 1 card_1_singletonE by blast
lp15@64788
  2232
  show ?thesis
lp15@64788
  2233
  proof (intro that conjI)
lp15@64788
  2234
    have "x = norm x *\<^sub>R b \<or> x = - norm x *\<^sub>R b" if "r = norm x" for x
lp15@64788
  2235
    proof -
lp15@64788
  2236
      have xb: "(x \<bullet> b) *\<^sub>R b = x"
lp15@64788
  2237
        using euclidean_representation [of x, unfolded b] by force
lp15@64788
  2238
      then have "norm ((x \<bullet> b) *\<^sub>R b) = norm x"
lp15@64788
  2239
        by simp
lp15@64788
  2240
      with b have "\<bar>x \<bullet> b\<bar> = norm x"
lp15@64788
  2241
        using norm_Basis by fastforce
lp15@64788
  2242
      with xb show ?thesis
lp15@64788
  2243
        apply (simp add: abs_if split: if_split_asm)
lp15@64788
  2244
        apply (metis add.inverse_inverse real_vector.scale_minus_left xb)
lp15@64788
  2245
        done
lp15@64788
  2246
    qed
lp15@64788
  2247
    with \<open>r > 0\<close> b show "sphere 0 r = {r *\<^sub>R b, - r *\<^sub>R b}"
lp15@64788
  2248
      by (force simp: sphere_def dist_norm)
lp15@64788
  2249
    have "dist (r *\<^sub>R b) (- r *\<^sub>R b) = norm (r *\<^sub>R b + r *\<^sub>R b)"
lp15@64788
  2250
      by (simp add: dist_norm)
lp15@64788
  2251
    also have "... = norm ((2*r) *\<^sub>R b)"
lp15@64788
  2252
      by (metis mult_2 scaleR_add_left)
lp15@64788
  2253
    also have "... = 2*r"
lp15@64788
  2254
      using \<open>r > 0\<close> b norm_Basis by fastforce
lp15@64788
  2255
    finally show "dist (r *\<^sub>R b) (- r *\<^sub>R b) = 2*r" .
lp15@64788
  2256
  qed
lp15@64788
  2257
qed
lp15@64788
  2258
lp15@64788
  2259
lemma sphere_1D_doubleton:
lp15@64788
  2260
  fixes a :: "'a :: euclidean_space"
lp15@64788
  2261
  assumes "DIM('a) = 1" and "r > 0"
lp15@64788
  2262
  obtains x y where "sphere a r = {x,y} \<and> dist x y = 2*r"
lp15@64788
  2263
proof -
lp15@64788
  2264
  have "sphere a r = op +a ` sphere 0 r"
lp15@64788
  2265
    by (metis add.right_neutral sphere_translation)
lp15@64788
  2266
  then show ?thesis
lp15@64788
  2267
    using sphere_1D_doubleton_zero [OF assms]
lp15@64788
  2268
    by (metis (mono_tags, lifting) dist_add_cancel image_empty image_insert that)
lp15@64788
  2269
qed
lp15@64788
  2270
lp15@64006
  2271
lemma psubset_sphere_Compl_connected:
lp15@64006
  2272
  fixes S :: "'a::euclidean_space set"
lp15@64006
  2273
  assumes S: "S \<subset> sphere a r" and "0 < r" and 2: "2 \<le> DIM('a)"
lp15@64006
  2274
  shows "connected(- S)"
lp15@64006
  2275
proof -
lp15@64006
  2276
  have "S \<subseteq> sphere a r"
lp15@64006
  2277
    using S by blast
lp15@64006
  2278
  obtain b where "dist a b = r" and "b \<notin> S"
lp15@64006
  2279
    using S mem_sphere by blast
lp15@64006
  2280
  have CS: "- S = {x. dist a x \<le> r \<and> (x \<notin> S)} \<union> {x. r \<le> dist a x \<and> (x \<notin> S)}"
lp15@64006
  2281
    by (auto simp: )
lp15@64006
  2282
  have "{x. dist a x \<le> r \<and> x \<notin> S} \<inter> {x. r \<le> dist a x \<and> x \<notin> S} \<noteq> {}"
lp15@64006
  2283
    using \<open>b \<notin> S\<close> \<open>dist a b = r\<close> by blast
lp15@64006
  2284
  moreover have "connected {x. dist a x \<le> r \<and> x \<notin> S}"
lp15@64006
  2285
    apply (rule connected_intermediate_closure [of "ball a r"])
lp15@64006
  2286
    using assms by auto
lp15@64006
  2287
  moreover
lp15@64006
  2288
  have "connected {x. r \<le> dist a x \<and> x \<notin> S}"
lp15@64006
  2289
    apply (rule connected_intermediate_closure [of "- cball a r"])
lp15@64006
  2290
    using assms apply (auto intro: connected_complement_bounded_convex)
lp15@64006
  2291
    apply (metis ComplI interior_cball interior_closure mem_ball not_less)
lp15@64006
  2292
    done
lp15@64006
  2293
  ultimately show ?thesis
lp15@64006
  2294
    by (simp add: CS connected_Un)
lp15@64006
  2295
qed
lp15@64006
  2296
lp15@64788
  2297
lp15@61426
  2298
subsection\<open>Relations between components and path components\<close>
lp15@61426
  2299
lp15@61426
  2300
lemma open_connected_component:
lp15@61426
  2301
  fixes s :: "'a::real_normed_vector set"
lp15@61426
  2302
  shows "open s \<Longrightarrow> open (connected_component_set s x)"
lp15@61426
  2303
    apply (simp add: open_contains_ball, clarify)
lp15@61426
  2304
    apply (rename_tac y)
lp15@61426
  2305
    apply (drule_tac x=y in bspec)
lp15@61426
  2306
     apply (simp add: connected_component_in, clarify)
lp15@61426
  2307
    apply (rule_tac x=e in exI)
lp15@61426
  2308
    by (metis mem_Collect_eq connected_component_eq connected_component_maximal centre_in_ball connected_ball)
lp15@61426
  2309
lp15@61426
  2310
corollary open_components:
lp15@61426
  2311
    fixes s :: "'a::real_normed_vector set"
lp15@61426
  2312
    shows "\<lbrakk>open u; s \<in> components u\<rbrakk> \<Longrightarrow> open s"
lp15@61426
  2313
  by (simp add: components_iff) (metis open_connected_component)
lp15@61426
  2314
lp15@61426
  2315
lemma in_closure_connected_component:
lp15@61426
  2316
  fixes s :: "'a::real_normed_vector set"
lp15@61426
  2317
  assumes x: "x \<in> s" and s: "open s"
lp15@61426
  2318
  shows "x \<in> closure (connected_component_set s y) \<longleftrightarrow>  x \<in> connected_component_set s y"
lp15@61426
  2319
proof -
lp15@61426
  2320
  { assume "x \<in> closure (connected_component_set s y)"
lp15@61426
  2321
    moreover have "x \<in> connected_component_set s x"
lp15@61426
  2322
      using x by simp
lp15@61426
  2323
    ultimately have "x \<in> connected_component_set s y"
lp15@61426
  2324
      using s by (meson Compl_disjoint closure_iff_nhds_not_empty connected_component_disjoint disjoint_eq_subset_Compl open_connected_component)
lp15@61426
  2325
  }
lp15@61426
  2326
  then show ?thesis
lp15@61426
  2327
    by (auto simp: closure_def)
lp15@61426
  2328
qed
lp15@61426
  2329
lp15@63114
  2330
lemma connected_disjoint_Union_open_pick:
lp15@63114
  2331
  assumes "pairwise disjnt B"
lp15@63114
  2332
          "\<And>S. S \<in> A \<Longrightarrow> connected S \<and> S \<noteq> {}"
lp15@63114
  2333
          "\<And>S. S \<in> B \<Longrightarrow> open S"
lp15@63114
  2334
          "\<Union>A \<subseteq> \<Union>B"
lp15@63114
  2335
          "S \<in> A"
lp15@63114
  2336
  obtains T where "T \<in> B" "S \<subseteq> T" "S \<inter> \<Union>(B - {T}) = {}"
lp15@63114
  2337
proof -
lp15@63114
  2338
  have "S \<subseteq> \<Union>B" "connected S" "S \<noteq> {}"
lp15@63114
  2339
    using assms \<open>S \<in> A\<close> by blast+
lp15@63114
  2340
  then obtain T where "T \<in> B" "S \<inter> T \<noteq> {}"
lp15@63114
  2341
    by (metis Sup_inf_eq_bot_iff inf.absorb_iff2 inf_commute)
lp15@63114
  2342
  have 1: "open T" by (simp add: \<open>T \<in> B\<close> assms)
lp15@63114
  2343
  have 2: "open (\<Union>(B-{T}))" using assms by blast
lp15@63114
  2344
  have 3: "S \<subseteq> T \<union> \<Union>(B - {T})" using \<open>S \<subseteq> \<Union>B\<close> by blast
lp15@63114
  2345
  have "T \<inter> \<Union>(B - {T}) = {}" using \<open>T \<in> B\<close> \<open>pairwise disjnt B\<close>
lp15@63114
  2346
    by (auto simp: pairwise_def disjnt_def)
lp15@63114
  2347
  then have 4: "T \<inter> \<Union>(B - {T}) \<inter> S = {}" by auto
lp15@63114
  2348
  from connectedD [OF \<open>connected S\<close> 1 2 3 4]
lp15@63114
  2349
  have "S \<inter> \<Union>(B-{T}) = {}"
lp15@63114
  2350
    by (auto simp: Int_commute \<open>S \<inter> T \<noteq> {}\<close>)
lp15@63114
  2351
  with \<open>T \<in> B\<close> have "S \<subseteq> T"
lp15@63114
  2352
    using "3" by auto
lp15@63114
  2353
  show ?thesis
lp15@63114
  2354
    using \<open>S \<inter> \<Union>(B - {T}) = {}\<close> \<open>S \<subseteq> T\<close> \<open>T \<in> B\<close> that by auto
lp15@63114
  2355
qed
lp15@63114
  2356
lp15@63114
  2357
lemma connected_disjoint_Union_open_subset:
lp15@63114
  2358
  assumes A: "pairwise disjnt A" and B: "pairwise disjnt B"
lp15@63114
  2359
      and SA: "\<And>S. S \<in> A \<Longrightarrow> open S \<and> connected S \<and> S \<noteq> {}"
lp15@63114
  2360
      and SB: "\<And>S. S \<in> B \<Longrightarrow> open S \<and> connected S \<and> S \<noteq> {}"
lp15@63114
  2361
      and eq [simp]: "\<Union>A = \<Union>B"
lp15@63114
  2362
    shows "A \<subseteq> B"
lp15@63114
  2363
proof
lp15@63114
  2364
  fix S
lp15@63114
  2365
  assume "S \<in> A"
lp15@63114
  2366
  obtain T where "T \<in> B" "S \<subseteq> T" "S \<inter> \<Union>(B - {T}) = {}"
lp15@63114
  2367
      apply (rule connected_disjoint_Union_open_pick [OF B, of A])
lp15@63114