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