src/HOL/Analysis/Further_Topology.thy
author paulson <lp15@cam.ac.uk>
Mon Oct 30 16:02:59 2017 +0000 (20 months ago)
changeset 66939 04678058308f
parent 66884 c2128ab11f61
child 66941 c67bb79a0ceb
permissions -rw-r--r--
New results in topology, mostly from HOL Light's moretop.ml
lp15@64122
     1
section \<open>Extending Continous Maps, Invariance of Domain, etc..\<close>
lp15@64006
     2
lp15@64006
     3
text\<open>Ported from HOL Light (moretop.ml) by L C Paulson\<close>
lp15@64006
     4
hoelzl@64289
     5
theory Further_Topology
lp15@64291
     6
  imports Equivalence_Lebesgue_Henstock_Integration Weierstrass_Theorems Polytope Complex_Transcendental
lp15@64006
     7
begin
lp15@64006
     8
lp15@64006
     9
subsection\<open>A map from a sphere to a higher dimensional sphere is nullhomotopic\<close>
lp15@64006
    10
lp15@64006
    11
lemma spheremap_lemma1:
lp15@64006
    12
  fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"
lp15@64006
    13
  assumes "subspace S" "subspace T" and dimST: "dim S < dim T"
lp15@64006
    14
      and "S \<subseteq> T"
lp15@64006
    15
      and diff_f: "f differentiable_on sphere 0 1 \<inter> S"
lp15@64006
    16
    shows "f ` (sphere 0 1 \<inter> S) \<noteq> sphere 0 1 \<inter> T"
lp15@64006
    17
proof
lp15@64006
    18
  assume fim: "f ` (sphere 0 1 \<inter> S) = sphere 0 1 \<inter> T"
lp15@64006
    19
  have inS: "\<And>x. \<lbrakk>x \<in> S; x \<noteq> 0\<rbrakk> \<Longrightarrow> (x /\<^sub>R norm x) \<in> S"
lp15@64006
    20
    using subspace_mul \<open>subspace S\<close> by blast
lp15@64006
    21
  have subS01: "(\<lambda>x. x /\<^sub>R norm x) ` (S - {0}) \<subseteq> sphere 0 1 \<inter> S"
lp15@64006
    22
    using \<open>subspace S\<close> subspace_mul by fastforce
lp15@64006
    23
  then have diff_f': "f differentiable_on (\<lambda>x. x /\<^sub>R norm x) ` (S - {0})"
lp15@64006
    24
    by (rule differentiable_on_subset [OF diff_f])
lp15@64006
    25
  define g where "g \<equiv> \<lambda>x. norm x *\<^sub>R f(inverse(norm x) *\<^sub>R x)"
lp15@64006
    26
  have gdiff: "g differentiable_on S - {0}"
lp15@64006
    27
    unfolding g_def
lp15@64006
    28
    by (rule diff_f' derivative_intros differentiable_on_compose [where f=f] | force)+
lp15@64006
    29
  have geq: "g ` (S - {0}) = T - {0}"
lp15@64006
    30
  proof
lp15@64006
    31
    have "g ` (S - {0}) \<subseteq> T"
lp15@64006
    32
      apply (auto simp: g_def subspace_mul [OF \<open>subspace T\<close>])
lp15@64006
    33
      apply (metis (mono_tags, lifting) DiffI subS01 subspace_mul [OF \<open>subspace T\<close>] fim image_subset_iff inf_le2 singletonD)
lp15@64006
    34
      done
lp15@64006
    35
    moreover have "g ` (S - {0}) \<subseteq> UNIV - {0}"
lp15@64006
    36
    proof (clarsimp simp: g_def)
lp15@64006
    37
      fix y
lp15@64006
    38
      assume "y \<in> S" and f0: "f (y /\<^sub>R norm y) = 0"
lp15@64006
    39
      then have "y \<noteq> 0 \<Longrightarrow> y /\<^sub>R norm y \<in> sphere 0 1 \<inter> S"
lp15@64006
    40
        by (auto simp: subspace_mul [OF \<open>subspace S\<close>])
lp15@64006
    41
      then show "y = 0"
lp15@64006
    42
        by (metis fim f0 Int_iff image_iff mem_sphere_0 norm_eq_zero zero_neq_one)
lp15@64006
    43
    qed
lp15@64006
    44
    ultimately show "g ` (S - {0}) \<subseteq> T - {0}"
lp15@64006
    45
      by auto
lp15@64006
    46
  next
lp15@64006
    47
    have *: "sphere 0 1 \<inter> T \<subseteq> f ` (sphere 0 1 \<inter> S)"
lp15@64006
    48
      using fim by (simp add: image_subset_iff)
lp15@64006
    49
    have "x \<in> (\<lambda>x. norm x *\<^sub>R f (x /\<^sub>R norm x)) ` (S - {0})"
lp15@64006
    50
          if "x \<in> T" "x \<noteq> 0" for x
lp15@64006
    51
    proof -
lp15@64006
    52
      have "x /\<^sub>R norm x \<in> T"
lp15@64006
    53
        using \<open>subspace T\<close> subspace_mul that by blast
lp15@64006
    54
      then show ?thesis
lp15@64006
    55
        using * [THEN subsetD, of "x /\<^sub>R norm x"] that apply clarsimp
lp15@64006
    56
        apply (rule_tac x="norm x *\<^sub>R xa" in image_eqI, simp)
lp15@64006
    57
        apply (metis norm_eq_zero right_inverse scaleR_one scaleR_scaleR)
lp15@64006
    58
        using \<open>subspace S\<close> subspace_mul apply force
lp15@64006
    59
        done
lp15@64006
    60
    qed
lp15@64006
    61
    then have "T - {0} \<subseteq> (\<lambda>x. norm x *\<^sub>R f (x /\<^sub>R norm x)) ` (S - {0})"
lp15@64006
    62
      by force
lp15@64006
    63
    then show "T - {0} \<subseteq> g ` (S - {0})"
lp15@64006
    64
      by (simp add: g_def)
lp15@64006
    65
  qed
lp15@64006
    66
  define T' where "T' \<equiv> {y. \<forall>x \<in> T. orthogonal x y}"
lp15@64006
    67
  have "subspace T'"
lp15@64006
    68
    by (simp add: subspace_orthogonal_to_vectors T'_def)
lp15@64006
    69
  have dim_eq: "dim T' + dim T = DIM('a)"
lp15@64006
    70
    using dim_subspace_orthogonal_to_vectors [of T UNIV] \<open>subspace T\<close>
lp15@64006
    71
    by (simp add: dim_UNIV T'_def)
lp15@64006
    72
  have "\<exists>v1 v2. v1 \<in> span T \<and> (\<forall>w \<in> span T. orthogonal v2 w) \<and> x = v1 + v2" for x
lp15@64006
    73
    by (force intro: orthogonal_subspace_decomp_exists [of T x])
lp15@64006
    74
  then obtain p1 p2 where p1span: "p1 x \<in> span T"
lp15@64006
    75
                      and "\<And>w. w \<in> span T \<Longrightarrow> orthogonal (p2 x) w"
lp15@64006
    76
                      and eq: "p1 x + p2 x = x" for x
lp15@64006
    77
    by metis
lp15@64006
    78
  then have p1: "\<And>z. p1 z \<in> T" and ortho: "\<And>w. w \<in> T \<Longrightarrow> orthogonal (p2 x) w" for x
lp15@64006
    79
    using span_eq \<open>subspace T\<close> by blast+
lp15@64006
    80
  then have p2: "\<And>z. p2 z \<in> T'"
lp15@64006
    81
    by (simp add: T'_def orthogonal_commute)
lp15@64006
    82
  have p12_eq: "\<And>x y. \<lbrakk>x \<in> T; y \<in> T'\<rbrakk> \<Longrightarrow> p1(x + y) = x \<and> p2(x + y) = y"
lp15@64006
    83
  proof (rule orthogonal_subspace_decomp_unique [OF eq p1span, where T=T'])
lp15@64006
    84
    show "\<And>x y. \<lbrakk>x \<in> T; y \<in> T'\<rbrakk> \<Longrightarrow> p2 (x + y) \<in> span T'"
lp15@64006
    85
      using span_eq p2 \<open>subspace T'\<close> by blast
lp15@64006
    86
    show "\<And>a b. \<lbrakk>a \<in> T; b \<in> T'\<rbrakk> \<Longrightarrow> orthogonal a b"
lp15@64006
    87
      using T'_def by blast
lp15@64006
    88
  qed (auto simp: span_superset)
lp15@64006
    89
  then have "\<And>c x. p1 (c *\<^sub>R x) = c *\<^sub>R p1 x \<and> p2 (c *\<^sub>R x) = c *\<^sub>R p2 x"
lp15@64006
    90
    by (metis eq \<open>subspace T\<close> \<open>subspace T'\<close> p1 p2 scaleR_add_right subspace_mul)
lp15@64006
    91
  moreover have lin_add: "\<And>x y. p1 (x + y) = p1 x + p1 y \<and> p2 (x + y) = p2 x + p2 y"
lp15@64006
    92
  proof (rule orthogonal_subspace_decomp_unique [OF _ p1span, where T=T'])
lp15@64006
    93
    show "\<And>x y. p1 (x + y) + p2 (x + y) = p1 x + p1 y + (p2 x + p2 y)"
lp15@64006
    94
      by (simp add: add.assoc add.left_commute eq)
lp15@64006
    95
    show  "\<And>a b. \<lbrakk>a \<in> T; b \<in> T'\<rbrakk> \<Longrightarrow> orthogonal a b"
lp15@64006
    96
      using T'_def by blast
lp15@64006
    97
  qed (auto simp: p1span p2 span_superset subspace_add)
lp15@64006
    98
  ultimately have "linear p1" "linear p2"
lp15@64006
    99
    by unfold_locales auto
lp15@64006
   100
  have "(\<lambda>z. g (p1 z)) differentiable_on {x + y |x y. x \<in> S - {0} \<and> y \<in> T'}"
lp15@64006
   101
    apply (rule differentiable_on_compose [where f=g])
lp15@64006
   102
    apply (rule linear_imp_differentiable_on [OF \<open>linear p1\<close>])
lp15@64006
   103
    apply (rule differentiable_on_subset [OF gdiff])
lp15@64006
   104
    using p12_eq \<open>S \<subseteq> T\<close> apply auto
lp15@64006
   105
    done
lp15@64006
   106
  then have diff: "(\<lambda>x. g (p1 x) + p2 x) differentiable_on {x + y |x y. x \<in> S - {0} \<and> y \<in> T'}"
lp15@64006
   107
    by (intro derivative_intros linear_imp_differentiable_on [OF \<open>linear p2\<close>])
lp15@64006
   108
  have "dim {x + y |x y. x \<in> S - {0} \<and> y \<in> T'} \<le> dim {x + y |x y. x \<in> S  \<and> y \<in> T'}"
lp15@64006
   109
    by (blast intro: dim_subset)
lp15@64006
   110
  also have "... = dim S + dim T' - dim (S \<inter> T')"
lp15@64006
   111
    using dim_sums_Int [OF \<open>subspace S\<close> \<open>subspace T'\<close>]
lp15@64006
   112
    by (simp add: algebra_simps)
lp15@64006
   113
  also have "... < DIM('a)"
lp15@64006
   114
    using dimST dim_eq by auto
lp15@64006
   115
  finally have neg: "negligible {x + y |x y. x \<in> S - {0} \<and> y \<in> T'}"
lp15@64006
   116
    by (rule negligible_lowdim)
lp15@64006
   117
  have "negligible ((\<lambda>x. g (p1 x) + p2 x) ` {x + y |x y. x \<in> S - {0} \<and> y \<in> T'})"
lp15@64006
   118
    by (rule negligible_differentiable_image_negligible [OF order_refl neg diff])
lp15@64006
   119
  then have "negligible {x + y |x y. x \<in> g ` (S - {0}) \<and> y \<in> T'}"
lp15@64006
   120
  proof (rule negligible_subset)
lp15@64006
   121
    have "\<lbrakk>t' \<in> T'; s \<in> S; s \<noteq> 0\<rbrakk>
lp15@64006
   122
          \<Longrightarrow> g s + t' \<in> (\<lambda>x. g (p1 x) + p2 x) `
lp15@64006
   123
                         {x + t' |x t'. x \<in> S \<and> x \<noteq> 0 \<and> t' \<in> T'}" for t' s
lp15@64006
   124
      apply (rule_tac x="s + t'" in image_eqI)
lp15@64006
   125
      using \<open>S \<subseteq> T\<close> p12_eq by auto
lp15@64006
   126
    then show "{x + y |x y. x \<in> g ` (S - {0}) \<and> y \<in> T'}
lp15@64006
   127
          \<subseteq> (\<lambda>x. g (p1 x) + p2 x) ` {x + y |x y. x \<in> S - {0} \<and> y \<in> T'}"
lp15@64006
   128
      by auto
lp15@64006
   129
  qed
lp15@64006
   130
  moreover have "- T' \<subseteq> {x + y |x y. x \<in> g ` (S - {0}) \<and> y \<in> T'}"
lp15@64006
   131
  proof clarsimp
lp15@64006
   132
    fix z assume "z \<notin> T'"
lp15@64006
   133
    show "\<exists>x y. z = x + y \<and> x \<in> g ` (S - {0}) \<and> y \<in> T'"
lp15@64006
   134
      apply (rule_tac x="p1 z" in exI)
lp15@64006
   135
      apply (rule_tac x="p2 z" in exI)
lp15@64006
   136
      apply (simp add: p1 eq p2 geq)
lp15@64006
   137
      by (metis \<open>z \<notin> T'\<close> add.left_neutral eq p2)
lp15@64006
   138
  qed
lp15@64006
   139
  ultimately have "negligible (-T')"
lp15@64006
   140
    using negligible_subset by blast
lp15@64006
   141
  moreover have "negligible T'"
lp15@64006
   142
    using negligible_lowdim
lp15@64006
   143
    by (metis add.commute assms(3) diff_add_inverse2 diff_self_eq_0 dim_eq le_add1 le_antisym linordered_semidom_class.add_diff_inverse not_less0)
lp15@64006
   144
  ultimately have  "negligible (-T' \<union> T')"
lp15@64006
   145
    by (metis negligible_Un_eq)
lp15@64006
   146
  then show False
lp15@64006
   147
    using negligible_Un_eq non_negligible_UNIV by simp
lp15@64006
   148
qed
lp15@64006
   149
lp15@64006
   150
lp15@64006
   151
lemma spheremap_lemma2:
lp15@64006
   152
  fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"
lp15@64006
   153
  assumes ST: "subspace S" "subspace T" "dim S < dim T"
lp15@64006
   154
      and "S \<subseteq> T"
lp15@64006
   155
      and contf: "continuous_on (sphere 0 1 \<inter> S) f"
lp15@64006
   156
      and fim: "f ` (sphere 0 1 \<inter> S) \<subseteq> sphere 0 1 \<inter> T"
lp15@64006
   157
    shows "\<exists>c. homotopic_with (\<lambda>x. True) (sphere 0 1 \<inter> S) (sphere 0 1 \<inter> T) f (\<lambda>x. c)"
lp15@64006
   158
proof -
lp15@64006
   159
  have [simp]: "\<And>x. \<lbrakk>norm x = 1; x \<in> S\<rbrakk> \<Longrightarrow> norm (f x) = 1"
lp15@64006
   160
    using fim by (simp add: image_subset_iff)
lp15@64006
   161
  have "compact (sphere 0 1 \<inter> S)"
lp15@64006
   162
    by (simp add: \<open>subspace S\<close> closed_subspace compact_Int_closed)
lp15@64006
   163
  then obtain g where pfg: "polynomial_function g" and gim: "g ` (sphere 0 1 \<inter> S) \<subseteq> T"
lp15@64006
   164
                and g12: "\<And>x. x \<in> sphere 0 1 \<inter> S \<Longrightarrow> norm(f x - g x) < 1/2"
lp15@64006
   165
    apply (rule Stone_Weierstrass_polynomial_function_subspace [OF _ contf _ \<open>subspace T\<close>, of "1/2"])
lp15@64006
   166
    using fim apply auto
lp15@64006
   167
    done
lp15@64006
   168
  have gnz: "g x \<noteq> 0" if "x \<in> sphere 0 1 \<inter> S" for x
lp15@64006
   169
  proof -
lp15@64006
   170
    have "norm (f x) = 1"
lp15@64006
   171
      using fim that by (simp add: image_subset_iff)
lp15@64006
   172
    then show ?thesis
lp15@64006
   173
      using g12 [OF that] by auto
lp15@64006
   174
  qed
lp15@64006
   175
  have diffg: "g differentiable_on sphere 0 1 \<inter> S"
lp15@64006
   176
    by (metis pfg differentiable_on_polynomial_function)
lp15@64006
   177
  define h where "h \<equiv> \<lambda>x. inverse(norm(g x)) *\<^sub>R g x"
lp15@64006
   178
  have h: "x \<in> sphere 0 1 \<inter> S \<Longrightarrow> h x \<in> sphere 0 1 \<inter> T" for x
lp15@64006
   179
    unfolding h_def
lp15@64006
   180
    using gnz [of x]
lp15@64006
   181
    by (auto simp: subspace_mul [OF \<open>subspace T\<close>] subsetD [OF gim])
lp15@64006
   182
  have diffh: "h differentiable_on sphere 0 1 \<inter> S"
lp15@64006
   183
    unfolding h_def
lp15@64006
   184
    apply (intro derivative_intros diffg differentiable_on_compose [OF diffg])
lp15@64006
   185
    using gnz apply auto
lp15@64006
   186
    done
lp15@64006
   187
  have homfg: "homotopic_with (\<lambda>z. True) (sphere 0 1 \<inter> S) (T - {0}) f g"
lp15@64006
   188
  proof (rule homotopic_with_linear [OF contf])
lp15@64006
   189
    show "continuous_on (sphere 0 1 \<inter> S) g"
lp15@64006
   190
      using pfg by (simp add: differentiable_imp_continuous_on diffg)
lp15@64006
   191
  next
lp15@64006
   192
    have non0fg: "0 \<notin> closed_segment (f x) (g x)" if "norm x = 1" "x \<in> S" for x
lp15@64006
   193
    proof -
lp15@64006
   194
      have "f x \<in> sphere 0 1"
lp15@64006
   195
        using fim that by (simp add: image_subset_iff)
lp15@64006
   196
      moreover have "norm(f x - g x) < 1/2"
lp15@64006
   197
        apply (rule g12)
lp15@64006
   198
        using that by force
lp15@64006
   199
      ultimately show ?thesis
lp15@64006
   200
        by (auto simp: norm_minus_commute dest: segment_bound)
lp15@64006
   201
    qed
lp15@64006
   202
    show "\<And>x. x \<in> sphere 0 1 \<inter> S \<Longrightarrow> closed_segment (f x) (g x) \<subseteq> T - {0}"
lp15@64006
   203
      apply (simp add: subset_Diff_insert non0fg)
lp15@64006
   204
      apply (simp add: segment_convex_hull)
lp15@64006
   205
      apply (rule hull_minimal)
lp15@64006
   206
       using fim image_eqI gim apply force
lp15@64006
   207
      apply (rule subspace_imp_convex [OF \<open>subspace T\<close>])
lp15@64006
   208
      done
lp15@64006
   209
  qed
lp15@64006
   210
  obtain d where d: "d \<in> (sphere 0 1 \<inter> T) - h ` (sphere 0 1 \<inter> S)"
lp15@64006
   211
    using h spheremap_lemma1 [OF ST \<open>S \<subseteq> T\<close> diffh] by force
lp15@64006
   212
  then have non0hd: "0 \<notin> closed_segment (h x) (- d)" if "norm x = 1" "x \<in> S" for x
lp15@64006
   213
    using midpoint_between [of 0 "h x" "-d"] that h [of x]
lp15@64006
   214
    by (auto simp: between_mem_segment midpoint_def)
lp15@64006
   215
  have conth: "continuous_on (sphere 0 1 \<inter> S) h"
lp15@64006
   216
    using differentiable_imp_continuous_on diffh by blast
lp15@64006
   217
  have hom_hd: "homotopic_with (\<lambda>z. True) (sphere 0 1 \<inter> S) (T - {0}) h (\<lambda>x. -d)"
lp15@64006
   218
    apply (rule homotopic_with_linear [OF conth continuous_on_const])
lp15@64006
   219
    apply (simp add: subset_Diff_insert non0hd)
lp15@64006
   220
    apply (simp add: segment_convex_hull)
lp15@64006
   221
    apply (rule hull_minimal)
lp15@64006
   222
     using h d apply (force simp: subspace_neg [OF \<open>subspace T\<close>])
lp15@64006
   223
    apply (rule subspace_imp_convex [OF \<open>subspace T\<close>])
lp15@64006
   224
    done
lp15@64006
   225
  have conT0: "continuous_on (T - {0}) (\<lambda>y. inverse(norm y) *\<^sub>R y)"
lp15@64006
   226
    by (intro continuous_intros) auto
lp15@64006
   227
  have sub0T: "(\<lambda>y. y /\<^sub>R norm y) ` (T - {0}) \<subseteq> sphere 0 1 \<inter> T"
lp15@64006
   228
    by (fastforce simp: assms(2) subspace_mul)
lp15@64006
   229
  obtain c where homhc: "homotopic_with (\<lambda>z. True) (sphere 0 1 \<inter> S) (sphere 0 1 \<inter> T) h (\<lambda>x. c)"
lp15@64006
   230
    apply (rule_tac c="-d" in that)
lp15@64006
   231
    apply (rule homotopic_with_eq)
lp15@64006
   232
       apply (rule homotopic_compose_continuous_left [OF hom_hd conT0 sub0T])
lp15@64006
   233
    using d apply (auto simp: h_def)
lp15@64006
   234
    done
lp15@64006
   235
  show ?thesis
lp15@64006
   236
    apply (rule_tac x=c in exI)
lp15@64006
   237
    apply (rule homotopic_with_trans [OF _ homhc])
lp15@64006
   238
    apply (rule homotopic_with_eq)
lp15@64006
   239
       apply (rule homotopic_compose_continuous_left [OF homfg conT0 sub0T])
lp15@64006
   240
      apply (auto simp: h_def)
lp15@64006
   241
    done
lp15@64006
   242
qed
lp15@64006
   243
lp15@64006
   244
lp15@64006
   245
lemma spheremap_lemma3:
lp15@64006
   246
  assumes "bounded S" "convex S" "subspace U" and affSU: "aff_dim S \<le> dim U"
lp15@64006
   247
  obtains T where "subspace T" "T \<subseteq> U" "S \<noteq> {} \<Longrightarrow> aff_dim T = aff_dim S"
lp15@64006
   248
                  "(rel_frontier S) homeomorphic (sphere 0 1 \<inter> T)"
lp15@64006
   249
proof (cases "S = {}")
lp15@64006
   250
  case True
lp15@64006
   251
  with \<open>subspace U\<close> subspace_0 show ?thesis
lp15@64006
   252
    by (rule_tac T = "{0}" in that) auto
lp15@64006
   253
next
lp15@64006
   254
  case False
lp15@64006
   255
  then obtain a where "a \<in> S"
lp15@64006
   256
    by auto
lp15@64006
   257
  then have affS: "aff_dim S = int (dim ((\<lambda>x. -a+x) ` S))"
lp15@64006
   258
    by (metis hull_inc aff_dim_eq_dim)
lp15@64006
   259
  with affSU have "dim ((\<lambda>x. -a+x) ` S) \<le> dim U"
lp15@64006
   260
    by linarith
lp15@64006
   261
  with choose_subspace_of_subspace
lp15@64006
   262
  obtain T where "subspace T" "T \<subseteq> span U" and dimT: "dim T = dim ((\<lambda>x. -a+x) ` S)" .
lp15@64006
   263
  show ?thesis
lp15@64006
   264
  proof (rule that [OF \<open>subspace T\<close>])
lp15@64006
   265
    show "T \<subseteq> U"
lp15@64006
   266
      using span_eq \<open>subspace U\<close> \<open>T \<subseteq> span U\<close> by blast
lp15@64006
   267
    show "aff_dim T = aff_dim S"
lp15@64006
   268
      using dimT \<open>subspace T\<close> affS aff_dim_subspace by fastforce
lp15@64006
   269
    show "rel_frontier S homeomorphic sphere 0 1 \<inter> T"
lp15@64006
   270
    proof -
lp15@64006
   271
      have "aff_dim (ball 0 1 \<inter> T) = aff_dim (T)"
lp15@64006
   272
        by (metis IntI interior_ball \<open>subspace T\<close> aff_dim_convex_Int_nonempty_interior centre_in_ball empty_iff inf_commute subspace_0 subspace_imp_convex zero_less_one)
lp15@64006
   273
      then have affS_eq: "aff_dim S = aff_dim (ball 0 1 \<inter> T)"
lp15@64006
   274
        using \<open>aff_dim T = aff_dim S\<close> by simp
lp15@64006
   275
      have "rel_frontier S homeomorphic rel_frontier(ball 0 1 \<inter> T)"
lp15@64006
   276
        apply (rule homeomorphic_rel_frontiers_convex_bounded_sets [OF \<open>convex S\<close> \<open>bounded S\<close>])
lp15@64006
   277
          apply (simp add: \<open>subspace T\<close> convex_Int subspace_imp_convex)
lp15@64006
   278
         apply (simp add: bounded_Int)
lp15@64006
   279
        apply (rule affS_eq)
lp15@64006
   280
        done
lp15@64006
   281
      also have "... = frontier (ball 0 1) \<inter> T"
lp15@64006
   282
        apply (rule convex_affine_rel_frontier_Int [OF convex_ball])
lp15@64006
   283
         apply (simp add: \<open>subspace T\<close> subspace_imp_affine)
lp15@64006
   284
        using \<open>subspace T\<close> subspace_0 by force
lp15@64006
   285
      also have "... = sphere 0 1 \<inter> T"
lp15@64006
   286
        by auto
lp15@64006
   287
      finally show ?thesis .
lp15@64006
   288
    qed
lp15@64006
   289
  qed
lp15@64006
   290
qed
lp15@64006
   291
lp15@64006
   292
lp15@64006
   293
proposition inessential_spheremap_lowdim_gen:
lp15@64006
   294
  fixes f :: "'M::euclidean_space \<Rightarrow> 'a::euclidean_space"
lp15@64006
   295
  assumes "convex S" "bounded S" "convex T" "bounded T"
lp15@64006
   296
      and affST: "aff_dim S < aff_dim T"
lp15@64006
   297
      and contf: "continuous_on (rel_frontier S) f"
lp15@64006
   298
      and fim: "f ` (rel_frontier S) \<subseteq> rel_frontier T"
lp15@64006
   299
  obtains c where "homotopic_with (\<lambda>z. True) (rel_frontier S) (rel_frontier T) f (\<lambda>x. c)"
lp15@64006
   300
proof (cases "S = {}")
lp15@64006
   301
  case True
lp15@64006
   302
  then show ?thesis
lp15@64006
   303
    by (simp add: that)
lp15@64006
   304
next
lp15@64006
   305
  case False
lp15@64006
   306
  then show ?thesis
lp15@64006
   307
  proof (cases "T = {}")
lp15@64006
   308
    case True
lp15@64006
   309
    then show ?thesis
lp15@64006
   310
      using fim that by auto
lp15@64006
   311
  next
lp15@64006
   312
    case False
lp15@64006
   313
    obtain T':: "'a set"
lp15@64006
   314
      where "subspace T'" and affT': "aff_dim T' = aff_dim T"
lp15@64006
   315
        and homT: "rel_frontier T homeomorphic sphere 0 1 \<inter> T'"
lp15@64006
   316
      apply (rule spheremap_lemma3 [OF \<open>bounded T\<close> \<open>convex T\<close> subspace_UNIV, where 'b='a])
lp15@64006
   317
       apply (simp add: dim_UNIV aff_dim_le_DIM)
lp15@64006
   318
      using \<open>T \<noteq> {}\<close> by blast
lp15@64006
   319
    with homeomorphic_imp_homotopy_eqv
lp15@64006
   320
    have relT: "sphere 0 1 \<inter> T'  homotopy_eqv rel_frontier T"
lp15@64006
   321
      using homotopy_eqv_sym by blast
lp15@64006
   322
    have "aff_dim S \<le> int (dim T')"
lp15@64006
   323
      using affT' \<open>subspace T'\<close> affST aff_dim_subspace by force
lp15@64006
   324
    with spheremap_lemma3 [OF \<open>bounded S\<close> \<open>convex S\<close> \<open>subspace T'\<close>] \<open>S \<noteq> {}\<close>
lp15@64006
   325
    obtain S':: "'a set" where "subspace S'" "S' \<subseteq> T'"
lp15@64006
   326
       and affS': "aff_dim S' = aff_dim S"
lp15@64006
   327
       and homT: "rel_frontier S homeomorphic sphere 0 1 \<inter> S'"
lp15@64006
   328
        by metis
lp15@64006
   329
    with homeomorphic_imp_homotopy_eqv
lp15@64006
   330
    have relS: "sphere 0 1 \<inter> S'  homotopy_eqv rel_frontier S"
lp15@64006
   331
      using homotopy_eqv_sym by blast
lp15@64006
   332
    have dimST': "dim S' < dim T'"
lp15@64006
   333
      by (metis \<open>S' \<subseteq> T'\<close> \<open>subspace S'\<close> \<open>subspace T'\<close> affS' affST affT' less_irrefl not_le subspace_dim_equal)
lp15@64006
   334
    have "\<exists>c. homotopic_with (\<lambda>z. True) (rel_frontier S) (rel_frontier T) f (\<lambda>x. c)"
lp15@64006
   335
      apply (rule homotopy_eqv_homotopic_triviality_null_imp [OF relT contf fim])
lp15@64006
   336
      apply (rule homotopy_eqv_cohomotopic_triviality_null[OF relS, THEN iffD1, rule_format])
lp15@64006
   337
       apply (metis dimST' \<open>subspace S'\<close>  \<open>subspace T'\<close>  \<open>S' \<subseteq> T'\<close> spheremap_lemma2, blast)
lp15@64006
   338
      done
lp15@64006
   339
    with that show ?thesis by blast
lp15@64006
   340
  qed
lp15@64006
   341
qed
lp15@64006
   342
lp15@64006
   343
lemma inessential_spheremap_lowdim:
lp15@64006
   344
  fixes f :: "'M::euclidean_space \<Rightarrow> 'a::euclidean_space"
lp15@64006
   345
  assumes
lp15@64006
   346
   "DIM('M) < DIM('a)" and f: "continuous_on (sphere a r) f" "f ` (sphere a r) \<subseteq> (sphere b s)"
lp15@64006
   347
   obtains c where "homotopic_with (\<lambda>z. True) (sphere a r) (sphere b s) f (\<lambda>x. c)"
lp15@64006
   348
proof (cases "s \<le> 0")
lp15@64006
   349
  case True then show ?thesis
lp15@64006
   350
    by (meson nullhomotopic_into_contractible f contractible_sphere that)
lp15@64006
   351
next
lp15@64006
   352
  case False
lp15@64006
   353
  show ?thesis
lp15@64006
   354
  proof (cases "r \<le> 0")
lp15@64006
   355
    case True then show ?thesis
lp15@64006
   356
      by (meson f nullhomotopic_from_contractible contractible_sphere that)
lp15@64006
   357
  next
lp15@64006
   358
    case False
lp15@64006
   359
    with \<open>~ s \<le> 0\<close> have "r > 0" "s > 0" by auto
lp15@64006
   360
    show ?thesis
lp15@64006
   361
      apply (rule inessential_spheremap_lowdim_gen [of "cball a r" "cball b s" f])
lp15@64006
   362
      using  \<open>0 < r\<close> \<open>0 < s\<close> assms(1)
lp15@64006
   363
             apply (simp_all add: f aff_dim_cball)
lp15@64006
   364
      using that by blast
lp15@64006
   365
  qed
lp15@64006
   366
qed
lp15@64006
   367
lp15@64006
   368
lp15@64006
   369
lp15@64006
   370
subsection\<open> Some technical lemmas about extending maps from cell complexes.\<close>
lp15@64006
   371
lp15@64006
   372
lemma extending_maps_Union_aux:
lp15@64006
   373
  assumes fin: "finite \<F>"
lp15@64006
   374
      and "\<And>S. S \<in> \<F> \<Longrightarrow> closed S"
lp15@64006
   375
      and "\<And>S T. \<lbrakk>S \<in> \<F>; T \<in> \<F>; S \<noteq> T\<rbrakk> \<Longrightarrow> S \<inter> T \<subseteq> K"
lp15@64006
   376
      and "\<And>S. S \<in> \<F> \<Longrightarrow> \<exists>g. continuous_on S g \<and> g ` S \<subseteq> T \<and> (\<forall>x \<in> S \<inter> K. g x = h x)"
lp15@64006
   377
   shows "\<exists>g. continuous_on (\<Union>\<F>) g \<and> g ` (\<Union>\<F>) \<subseteq> T \<and> (\<forall>x \<in> \<Union>\<F> \<inter> K. g x = h x)"
lp15@64006
   378
using assms
lp15@64006
   379
proof (induction \<F>)
lp15@64006
   380
  case empty show ?case by simp
lp15@64006
   381
next
lp15@64006
   382
  case (insert S \<F>)
lp15@64006
   383
  then obtain f where contf: "continuous_on (S) f" and fim: "f ` S \<subseteq> T" and feq: "\<forall>x \<in> S \<inter> K. f x = h x"
lp15@64006
   384
    by (meson insertI1)
lp15@64006
   385
  obtain g where contg: "continuous_on (\<Union>\<F>) g" and gim: "g ` \<Union>\<F> \<subseteq> T" and geq: "\<forall>x \<in> \<Union>\<F> \<inter> K. g x = h x"
lp15@64006
   386
    using insert by auto
lp15@64006
   387
  have fg: "f x = g x" if "x \<in> T" "T \<in> \<F>" "x \<in> S" for x T
lp15@64006
   388
  proof -
lp15@64006
   389
    have "T \<inter> S \<subseteq> K \<or> S = T"
lp15@64006
   390
      using that by (metis (no_types) insert.prems(2) insertCI)
lp15@64006
   391
    then show ?thesis
lp15@64006
   392
      using UnionI feq geq \<open>S \<notin> \<F>\<close> subsetD that by fastforce
lp15@64006
   393
  qed
lp15@64006
   394
  show ?case
lp15@64006
   395
    apply (rule_tac x="\<lambda>x. if x \<in> S then f x else g x" in exI, simp)
lp15@64006
   396
    apply (intro conjI continuous_on_cases)
lp15@64006
   397
    apply (simp_all add: insert closed_Union contf contg)
lp15@64006
   398
    using fim gim feq geq
lp15@64006
   399
    apply (force simp: insert closed_Union contf contg inf_commute intro: fg)+
lp15@64006
   400
    done
lp15@64006
   401
qed
lp15@64006
   402
lp15@64006
   403
lemma extending_maps_Union:
lp15@64006
   404
  assumes fin: "finite \<F>"
lp15@64006
   405
      and "\<And>S. S \<in> \<F> \<Longrightarrow> \<exists>g. continuous_on S g \<and> g ` S \<subseteq> T \<and> (\<forall>x \<in> S \<inter> K. g x = h x)"
lp15@64006
   406
      and "\<And>S. S \<in> \<F> \<Longrightarrow> closed S"
lp15@64006
   407
      and K: "\<And>X Y. \<lbrakk>X \<in> \<F>; Y \<in> \<F>; ~ X \<subseteq> Y; ~ Y \<subseteq> X\<rbrakk> \<Longrightarrow> X \<inter> Y \<subseteq> K"
lp15@64006
   408
    shows "\<exists>g. continuous_on (\<Union>\<F>) g \<and> g ` (\<Union>\<F>) \<subseteq> T \<and> (\<forall>x \<in> \<Union>\<F> \<inter> K. g x = h x)"
lp15@64006
   409
apply (simp add: Union_maximal_sets [OF fin, symmetric])
lp15@64006
   410
apply (rule extending_maps_Union_aux)
lp15@64006
   411
apply (simp_all add: Union_maximal_sets [OF fin] assms)
lp15@64006
   412
by (metis K psubsetI)
lp15@64006
   413
lp15@64006
   414
lp15@64006
   415
lemma extend_map_lemma:
lp15@64006
   416
  assumes "finite \<F>" "\<G> \<subseteq> \<F>" "convex T" "bounded T"
lp15@64006
   417
      and poly: "\<And>X. X \<in> \<F> \<Longrightarrow> polytope X"
lp15@64006
   418
      and aff: "\<And>X. X \<in> \<F> - \<G> \<Longrightarrow> aff_dim X < aff_dim T"
lp15@64006
   419
      and face: "\<And>S T. \<lbrakk>S \<in> \<F>; T \<in> \<F>\<rbrakk> \<Longrightarrow> (S \<inter> T) face_of S \<and> (S \<inter> T) face_of T"
lp15@64006
   420
      and contf: "continuous_on (\<Union>\<G>) f" and fim: "f ` (\<Union>\<G>) \<subseteq> rel_frontier T"
lp15@64006
   421
  obtains g where "continuous_on (\<Union>\<F>) g" "g ` (\<Union>\<F>) \<subseteq> rel_frontier T" "\<And>x. x \<in> \<Union>\<G> \<Longrightarrow> g x = f x"
lp15@64006
   422
proof (cases "\<F> - \<G> = {}")
lp15@64006
   423
  case True
lp15@64006
   424
  then have "\<Union>\<F> \<subseteq> \<Union>\<G>"
lp15@64006
   425
    by (simp add: Union_mono)
lp15@64006
   426
  then show ?thesis
lp15@64006
   427
    apply (rule_tac g=f in that)
lp15@64006
   428
      using contf continuous_on_subset apply blast
lp15@64006
   429
     using fim apply blast
lp15@64006
   430
    by simp
lp15@64006
   431
next
lp15@64006
   432
  case False
lp15@64006
   433
  then have "0 \<le> aff_dim T"
lp15@64006
   434
    by (metis aff aff_dim_empty aff_dim_geq aff_dim_negative_iff all_not_in_conv not_less)
lp15@64006
   435
  then obtain i::nat where i: "int i = aff_dim T"
lp15@64006
   436
    by (metis nonneg_eq_int)
lp15@64006
   437
  have Union_empty_eq: "\<Union>{D. D = {} \<and> P D} = {}" for P :: "'a set \<Rightarrow> bool"
lp15@64006
   438
    by auto
lp15@64006
   439
  have extendf: "\<exists>g. continuous_on (\<Union>(\<G> \<union> {D. \<exists>C \<in> \<F>. D face_of C \<and> aff_dim D < i})) g \<and>
lp15@64006
   440
                     g ` (\<Union> (\<G> \<union> {D. \<exists>C \<in> \<F>. D face_of C \<and> aff_dim D < i})) \<subseteq> rel_frontier T \<and>
lp15@64006
   441
                     (\<forall>x \<in> \<Union>\<G>. g x = f x)"
lp15@64006
   442
       if "i \<le> aff_dim T" for i::nat
lp15@64006
   443
  using that
lp15@64006
   444
  proof (induction i)
lp15@64006
   445
    case 0 then show ?case
lp15@64006
   446
      apply (simp add: Union_empty_eq)
lp15@64006
   447
      apply (rule_tac x=f in exI)
lp15@64006
   448
      apply (intro conjI)
lp15@64006
   449
      using contf continuous_on_subset apply blast
lp15@64006
   450
      using fim apply blast
lp15@64006
   451
      by simp
lp15@64006
   452
  next
lp15@64006
   453
    case (Suc p)
lp15@64006
   454
    with \<open>bounded T\<close> have "rel_frontier T \<noteq> {}"
lp15@64006
   455
      by (auto simp: rel_frontier_eq_empty affine_bounded_eq_lowdim [of T])
lp15@64006
   456
    then obtain t where t: "t \<in> rel_frontier T" by auto
lp15@64006
   457
    have ple: "int p \<le> aff_dim T" using Suc.prems by force
lp15@64006
   458
    obtain h where conth: "continuous_on (\<Union>(\<G> \<union> {D. \<exists>C \<in> \<F>. D face_of C \<and> aff_dim D < p})) h"
lp15@64006
   459
               and him: "h ` (\<Union> (\<G> \<union> {D. \<exists>C \<in> \<F>. D face_of C \<and> aff_dim D < p}))
lp15@64006
   460
                         \<subseteq> rel_frontier T"
lp15@64006
   461
               and heq: "\<And>x. x \<in> \<Union>\<G> \<Longrightarrow> h x = f x"
lp15@64006
   462
      using Suc.IH [OF ple] by auto
lp15@64006
   463
    let ?Faces = "{D. \<exists>C \<in> \<F>. D face_of C \<and> aff_dim D \<le> p}"
lp15@64006
   464
    have extendh: "\<exists>g. continuous_on D g \<and>
lp15@64006
   465
                       g ` D \<subseteq> rel_frontier T \<and>
lp15@64006
   466
                       (\<forall>x \<in> D \<inter> \<Union>(\<G> \<union> {D. \<exists>C \<in> \<F>. D face_of C \<and> aff_dim D < p}). g x = h x)"
lp15@64006
   467
      if D: "D \<in> \<G> \<union> ?Faces" for D
lp15@64006
   468
    proof (cases "D \<subseteq> \<Union>(\<G> \<union> {D. \<exists>C \<in> \<F>. D face_of C \<and> aff_dim D < p})")
lp15@64006
   469
      case True
lp15@64006
   470
      then show ?thesis
lp15@64006
   471
        apply (rule_tac x=h in exI)
lp15@64006
   472
        apply (intro conjI)
lp15@64006
   473
        apply (blast intro: continuous_on_subset [OF conth])
lp15@64006
   474
        using him apply blast
lp15@64006
   475
        by simp
lp15@64006
   476
    next
lp15@64006
   477
      case False
lp15@64006
   478
      note notDsub = False
lp15@64006
   479
      show ?thesis
lp15@64006
   480
      proof (cases "\<exists>a. D = {a}")
lp15@64006
   481
        case True
lp15@64006
   482
        then obtain a where "D = {a}" by auto
lp15@64006
   483
        with notDsub t show ?thesis
lp15@64006
   484
          by (rule_tac x="\<lambda>x. t" in exI) simp
lp15@64006
   485
      next
lp15@64006
   486
        case False
lp15@64006
   487
        have "D \<noteq> {}" using notDsub by auto
lp15@64006
   488
        have Dnotin: "D \<notin> \<G> \<union> {D. \<exists>C \<in> \<F>. D face_of C \<and> aff_dim D < p}"
lp15@64006
   489
          using notDsub by auto
lp15@64006
   490
        then have "D \<notin> \<G>" by simp
lp15@64006
   491
        have "D \<in> ?Faces - {D. \<exists>C \<in> \<F>. D face_of C \<and> aff_dim D < p}"
lp15@64006
   492
          using Dnotin that by auto
lp15@64006
   493
        then obtain C where "C \<in> \<F>" "D face_of C" and affD: "aff_dim D = int p"
lp15@64006
   494
          by auto
lp15@64006
   495
        then have "bounded D"
lp15@64006
   496
          using face_of_polytope_polytope poly polytope_imp_bounded by blast
lp15@64006
   497
        then have [simp]: "\<not> affine D"
lp15@64006
   498
          using affine_bounded_eq_trivial False \<open>D \<noteq> {}\<close> \<open>bounded D\<close> by blast
lp15@64006
   499
        have "{F. F facet_of D} \<subseteq> {E. E face_of C \<and> aff_dim E < int p}"
lp15@64006
   500
          apply clarify
lp15@64006
   501
          apply (metis \<open>D face_of C\<close> affD eq_iff face_of_trans facet_of_def zle_diff1_eq)
lp15@64006
   502
          done
lp15@64006
   503
        moreover have "polyhedron D"
lp15@64006
   504
          using \<open>C \<in> \<F>\<close> \<open>D face_of C\<close> face_of_polytope_polytope poly polytope_imp_polyhedron by auto
lp15@64006
   505
        ultimately have relf_sub: "rel_frontier D \<subseteq> \<Union> {E. E face_of C \<and> aff_dim E < p}"
lp15@64006
   506
          by (simp add: rel_frontier_of_polyhedron Union_mono)
lp15@64006
   507
        then have him_relf: "h ` rel_frontier D \<subseteq> rel_frontier T"
lp15@64006
   508
          using \<open>C \<in> \<F>\<close> him by blast
lp15@64006
   509
        have "convex D"
lp15@64006
   510
          by (simp add: \<open>polyhedron D\<close> polyhedron_imp_convex)
lp15@64006
   511
        have affD_lessT: "aff_dim D < aff_dim T"
lp15@64006
   512
          using Suc.prems affD by linarith
lp15@64006
   513
        have contDh: "continuous_on (rel_frontier D) h"
lp15@64006
   514
          using \<open>C \<in> \<F>\<close> relf_sub by (blast intro: continuous_on_subset [OF conth])
lp15@64006
   515
        then have *: "(\<exists>c. homotopic_with (\<lambda>x. True) (rel_frontier D) (rel_frontier T) h (\<lambda>x. c)) =
lp15@64006
   516
                      (\<exists>g. continuous_on UNIV g \<and>  range g \<subseteq> rel_frontier T \<and>
lp15@64006
   517
                           (\<forall>x\<in>rel_frontier D. g x = h x))"
lp15@64006
   518
          apply (rule nullhomotopic_into_rel_frontier_extension [OF closed_rel_frontier])
lp15@64006
   519
          apply (simp_all add: assms rel_frontier_eq_empty him_relf)
lp15@64006
   520
          done
lp15@64006
   521
        have "(\<exists>c. homotopic_with (\<lambda>x. True) (rel_frontier D)
lp15@64006
   522
              (rel_frontier T) h (\<lambda>x. c))"
lp15@64006
   523
          by (metis inessential_spheremap_lowdim_gen
lp15@64006
   524
                 [OF \<open>convex D\<close> \<open>bounded D\<close> \<open>convex T\<close> \<open>bounded T\<close> affD_lessT contDh him_relf])
lp15@64006
   525
        then obtain g where contg: "continuous_on UNIV g"
lp15@64006
   526
                        and gim: "range g \<subseteq> rel_frontier T"
lp15@64006
   527
                        and gh: "\<And>x. x \<in> rel_frontier D \<Longrightarrow> g x = h x"
lp15@64006
   528
          by (metis *)
lp15@64006
   529
        have "D \<inter> E \<subseteq> rel_frontier D"
lp15@64006
   530
             if "E \<in> \<G> \<union> {D. Bex \<F> (op face_of D) \<and> aff_dim D < int p}" for E
lp15@64006
   531
        proof (rule face_of_subset_rel_frontier)
lp15@64006
   532
          show "D \<inter> E face_of D"
lp15@64006
   533
            using that \<open>C \<in> \<F>\<close> \<open>D face_of C\<close> face
lp15@64006
   534
            apply auto
lp15@64006
   535
            apply (meson face_of_Int_subface \<open>\<G> \<subseteq> \<F>\<close> face_of_refl_eq poly polytope_imp_convex subsetD)
lp15@64006
   536
            using face_of_Int_subface apply blast
lp15@64006
   537
            done
lp15@64006
   538
          show "D \<inter> E \<noteq> D"
lp15@64006
   539
            using that notDsub by auto
lp15@64006
   540
        qed
lp15@64006
   541
        then show ?thesis
lp15@64006
   542
          apply (rule_tac x=g in exI)
lp15@64006
   543
          apply (intro conjI ballI)
lp15@64006
   544
            using continuous_on_subset contg apply blast
lp15@64006
   545
           using gim apply blast
lp15@64006
   546
          using gh by fastforce
lp15@64006
   547
      qed
lp15@64006
   548
    qed
lp15@64006
   549
    have intle: "i < 1 + int j \<longleftrightarrow> i \<le> int j" for i j
lp15@64006
   550
      by auto
lp15@64006
   551
    have "finite \<G>"
lp15@64006
   552
      using \<open>finite \<F>\<close> \<open>\<G> \<subseteq> \<F>\<close> rev_finite_subset by blast
lp15@64006
   553
    then have fin: "finite (\<G> \<union> ?Faces)"
lp15@64006
   554
      apply simp
lp15@64006
   555
      apply (rule_tac B = "\<Union>{{D. D face_of C}| C. C \<in> \<F>}" in finite_subset)
lp15@64006
   556
       by (auto simp: \<open>finite \<F>\<close> finite_polytope_faces poly)
lp15@64006
   557
    have clo: "closed S" if "S \<in> \<G> \<union> ?Faces" for S
lp15@64006
   558
      using that \<open>\<G> \<subseteq> \<F>\<close> face_of_polytope_polytope poly polytope_imp_closed by blast
lp15@64006
   559
    have K: "X \<inter> Y \<subseteq> \<Union>(\<G> \<union> {D. \<exists>C\<in>\<F>. D face_of C \<and> aff_dim D < int p})"
lp15@64006
   560
                if "X \<in> \<G> \<union> ?Faces" "Y \<in> \<G> \<union> ?Faces" "~ Y \<subseteq> X" for X Y
lp15@64006
   561
    proof -
lp15@64006
   562
      have ff: "X \<inter> Y face_of X \<and> X \<inter> Y face_of Y"
lp15@64006
   563
        if XY: "X face_of D" "Y face_of E" and DE: "D \<in> \<F>" "E \<in> \<F>" for D E
lp15@64006
   564
        apply (rule face_of_Int_subface [OF _ _ XY])
lp15@64006
   565
        apply (auto simp: face DE)
lp15@64006
   566
        done
lp15@64006
   567
      show ?thesis
lp15@64006
   568
        using that
lp15@64006
   569
        apply auto
lp15@64006
   570
        apply (drule_tac x="X \<inter> Y" in spec, safe)
lp15@64006
   571
        using ff face_of_imp_convex [of X] face_of_imp_convex [of Y]
lp15@64006
   572
        apply (fastforce dest: face_of_aff_dim_lt)
lp15@64006
   573
        by (meson face_of_trans ff)
lp15@64006
   574
    qed
lp15@64006
   575
    obtain g where "continuous_on (\<Union>(\<G> \<union> ?Faces)) g"
lp15@64006
   576
                   "g ` \<Union>(\<G> \<union> ?Faces) \<subseteq> rel_frontier T"
lp15@64006
   577
                   "(\<forall>x \<in> \<Union>(\<G> \<union> ?Faces) \<inter>
lp15@64006
   578
                          \<Union>(\<G> \<union> {D. \<exists>C\<in>\<F>. D face_of C \<and> aff_dim D < p}). g x = h x)"
lp15@64006
   579
      apply (rule exE [OF extending_maps_Union [OF fin extendh clo K]], blast+)
lp15@64006
   580
      done
lp15@64006
   581
    then show ?case
lp15@64006
   582
      apply (simp add: intle local.heq [symmetric], blast)
lp15@64006
   583
      done
lp15@64006
   584
  qed
lp15@64006
   585
  have eq: "\<Union>(\<G> \<union> {D. \<exists>C \<in> \<F>. D face_of C \<and> aff_dim D < i}) = \<Union>\<F>"
lp15@64006
   586
  proof
lp15@64006
   587
    show "\<Union>(\<G> \<union> {D. \<exists>C\<in>\<F>. D face_of C \<and> aff_dim D < int i}) \<subseteq> \<Union>\<F>"
lp15@64006
   588
      apply (rule Union_subsetI)
lp15@64006
   589
      using \<open>\<G> \<subseteq> \<F>\<close> face_of_imp_subset  apply force
lp15@64006
   590
      done
lp15@64006
   591
    show "\<Union>\<F> \<subseteq> \<Union>(\<G> \<union> {D. \<exists>C\<in>\<F>. D face_of C \<and> aff_dim D < i})"
lp15@64006
   592
      apply (rule Union_mono)
lp15@64006
   593
      using face  apply (fastforce simp: aff i)
lp15@64006
   594
      done
lp15@64006
   595
  qed
lp15@64006
   596
  have "int i \<le> aff_dim T" by (simp add: i)
lp15@64006
   597
  then show ?thesis
lp15@64006
   598
    using extendf [of i] unfolding eq by (metis that)
lp15@64006
   599
qed
lp15@64006
   600
lp15@64006
   601
lemma extend_map_lemma_cofinite0:
lp15@64006
   602
  assumes "finite \<F>"
lp15@64006
   603
      and "pairwise (\<lambda>S T. S \<inter> T \<subseteq> K) \<F>"
lp15@64006
   604
      and "\<And>S. S \<in> \<F> \<Longrightarrow> \<exists>a g. a \<notin> U \<and> continuous_on (S - {a}) g \<and> g ` (S - {a}) \<subseteq> T \<and> (\<forall>x \<in> S \<inter> K. g x = h x)"
lp15@64006
   605
      and "\<And>S. S \<in> \<F> \<Longrightarrow> closed S"
lp15@64006
   606
    shows "\<exists>C g. finite C \<and> disjnt C U \<and> card C \<le> card \<F> \<and>
lp15@64006
   607
                 continuous_on (\<Union>\<F> - C) g \<and> g ` (\<Union>\<F> - C) \<subseteq> T
lp15@64006
   608
                  \<and> (\<forall>x \<in> (\<Union>\<F> - C) \<inter> K. g x = h x)"
lp15@64006
   609
  using assms
lp15@64006
   610
proof induction
lp15@64006
   611
  case empty then show ?case
lp15@64006
   612
    by force
lp15@64006
   613
next
lp15@64006
   614
  case (insert X \<F>)
lp15@64006
   615
  then have "closed X" and clo: "\<And>X. X \<in> \<F> \<Longrightarrow> closed X"
lp15@64006
   616
        and \<F>: "\<And>S. S \<in> \<F> \<Longrightarrow> \<exists>a g. a \<notin> U \<and> continuous_on (S - {a}) g \<and> g ` (S - {a}) \<subseteq> T \<and> (\<forall>x \<in> S \<inter> K. g x = h x)"
lp15@64006
   617
        and pwX: "\<And>Y. Y \<in> \<F> \<and> Y \<noteq> X \<longrightarrow> X \<inter> Y \<subseteq> K \<and> Y \<inter> X \<subseteq> K"
lp15@64006
   618
        and pwF: "pairwise (\<lambda> S T. S \<inter> T \<subseteq> K) \<F>"
lp15@64006
   619
    by (simp_all add: pairwise_insert)
lp15@64006
   620
  obtain C g where C: "finite C" "disjnt C U" "card C \<le> card \<F>"
lp15@64006
   621
               and contg: "continuous_on (\<Union>\<F> - C) g"
lp15@64006
   622
               and gim: "g ` (\<Union>\<F> - C) \<subseteq> T"
lp15@64006
   623
               and gh:  "\<And>x. x \<in> (\<Union>\<F> - C) \<inter> K \<Longrightarrow> g x = h x"
lp15@64006
   624
    using insert.IH [OF pwF \<F> clo] by auto
lp15@64006
   625
  obtain a f where "a \<notin> U"
lp15@64006
   626
               and contf: "continuous_on (X - {a}) f"
lp15@64006
   627
               and fim: "f ` (X - {a}) \<subseteq> T"
lp15@64006
   628
               and fh: "(\<forall>x \<in> X \<inter> K. f x = h x)"
lp15@64006
   629
    using insert.prems by (meson insertI1)
lp15@64006
   630
  show ?case
lp15@64006
   631
  proof (intro exI conjI)
lp15@64006
   632
    show "finite (insert a C)"
lp15@64006
   633
      by (simp add: C)
lp15@64006
   634
    show "disjnt (insert a C) U"
lp15@64006
   635
      using C \<open>a \<notin> U\<close> by simp
lp15@64006
   636
    show "card (insert a C) \<le> card (insert X \<F>)"
lp15@64006
   637
      by (simp add: C card_insert_if insert.hyps le_SucI)
lp15@64006
   638
    have "closed (\<Union>\<F>)"
lp15@64006
   639
      using clo insert.hyps by blast
lp15@64006
   640
    have "continuous_on (X - insert a C \<union> (\<Union>\<F> - insert a C)) (\<lambda>x. if x \<in> X then f x else g x)"
lp15@64006
   641
       apply (rule continuous_on_cases_local)
lp15@64006
   642
          apply (simp_all add: closedin_closed)
lp15@64006
   643
        using \<open>closed X\<close> apply blast
lp15@64006
   644
        using \<open>closed (\<Union>\<F>)\<close> apply blast
lp15@64006
   645
        using contf apply (force simp: elim: continuous_on_subset)
lp15@64006
   646
        using contg apply (force simp: elim: continuous_on_subset)
lp15@64006
   647
        using fh gh insert.hyps pwX by fastforce
lp15@64006
   648
    then show "continuous_on (\<Union>insert X \<F> - insert a C) (\<lambda>a. if a \<in> X then f a else g a)"
lp15@64006
   649
      by (blast intro: continuous_on_subset)
lp15@64006
   650
    show "\<forall>x\<in>(\<Union>insert X \<F> - insert a C) \<inter> K. (if x \<in> X then f x else g x) = h x"
lp15@64006
   651
      using gh by (auto simp: fh)
lp15@64006
   652
    show "(\<lambda>a. if a \<in> X then f a else g a) ` (\<Union>insert X \<F> - insert a C) \<subseteq> T"
lp15@64006
   653
      using fim gim by auto force
lp15@64006
   654
  qed
lp15@64006
   655
qed
lp15@64006
   656
lp15@64006
   657
lp15@64006
   658
lemma extend_map_lemma_cofinite1:
lp15@64006
   659
assumes "finite \<F>"
lp15@64006
   660
    and \<F>: "\<And>X. X \<in> \<F> \<Longrightarrow> \<exists>a g. a \<notin> U \<and> continuous_on (X - {a}) g \<and> g ` (X - {a}) \<subseteq> T \<and> (\<forall>x \<in> X \<inter> K. g x = h x)"
lp15@64006
   661
    and clo: "\<And>X. X \<in> \<F> \<Longrightarrow> closed X"
lp15@64006
   662
    and K: "\<And>X Y. \<lbrakk>X \<in> \<F>; Y \<in> \<F>; ~(X \<subseteq> Y); ~(Y \<subseteq> X)\<rbrakk> \<Longrightarrow> X \<inter> Y \<subseteq> K"
lp15@64006
   663
  obtains C g where "finite C" "disjnt C U" "card C \<le> card \<F>" "continuous_on (\<Union>\<F> - C) g"
lp15@64006
   664
                    "g ` (\<Union>\<F> - C) \<subseteq> T"
lp15@64006
   665
                    "\<And>x. x \<in> (\<Union>\<F> - C) \<inter> K \<Longrightarrow> g x = h x"
lp15@64006
   666
proof -
lp15@64006
   667
  let ?\<F> = "{X \<in> \<F>. \<forall>Y\<in>\<F>. \<not> X \<subset> Y}"
lp15@64006
   668
  have [simp]: "\<Union>?\<F> = \<Union>\<F>"
lp15@64006
   669
    by (simp add: Union_maximal_sets assms)
lp15@64006
   670
  have fin: "finite ?\<F>"
lp15@64006
   671
    by (force intro: finite_subset [OF _ \<open>finite \<F>\<close>])
lp15@64006
   672
  have pw: "pairwise (\<lambda> S T. S \<inter> T \<subseteq> K) ?\<F>"
lp15@64006
   673
    by (simp add: pairwise_def) (metis K psubsetI)
lp15@64006
   674
  have "card {X \<in> \<F>. \<forall>Y\<in>\<F>. \<not> X \<subset> Y} \<le> card \<F>"
lp15@64006
   675
    by (simp add: \<open>finite \<F>\<close> card_mono)
lp15@64006
   676
  moreover
lp15@64006
   677
  obtain C g where "finite C \<and> disjnt C U \<and> card C \<le> card ?\<F> \<and>
lp15@64006
   678
                 continuous_on (\<Union>?\<F> - C) g \<and> g ` (\<Union>?\<F> - C) \<subseteq> T
lp15@64006
   679
                  \<and> (\<forall>x \<in> (\<Union>?\<F> - C) \<inter> K. g x = h x)"
lp15@64006
   680
    apply (rule exE [OF extend_map_lemma_cofinite0 [OF fin pw, of U T h]])
lp15@64006
   681
      apply (fastforce intro!:  clo \<F>)+
lp15@64006
   682
    done
lp15@64006
   683
  ultimately show ?thesis
lp15@64006
   684
    by (rule_tac C=C and g=g in that) auto
lp15@64006
   685
qed
lp15@64006
   686
lp15@64006
   687
lp15@64006
   688
lemma extend_map_lemma_cofinite:
lp15@64006
   689
  assumes "finite \<F>" "\<G> \<subseteq> \<F>" and T: "convex T" "bounded T"
lp15@64006
   690
      and poly: "\<And>X. X \<in> \<F> \<Longrightarrow> polytope X"
lp15@64006
   691
      and contf: "continuous_on (\<Union>\<G>) f" and fim: "f ` (\<Union>\<G>) \<subseteq> rel_frontier T"
lp15@64006
   692
      and face: "\<And>X Y. \<lbrakk>X \<in> \<F>; Y \<in> \<F>\<rbrakk> \<Longrightarrow> (X \<inter> Y) face_of X \<and> (X \<inter> Y) face_of Y"
lp15@64006
   693
      and aff: "\<And>X. X \<in> \<F> - \<G> \<Longrightarrow> aff_dim X \<le> aff_dim T"
lp15@64006
   694
  obtains C g where
lp15@64006
   695
     "finite C" "disjnt C (\<Union>\<G>)" "card C \<le> card \<F>" "continuous_on (\<Union>\<F> - C) g"
lp15@64006
   696
     "g ` (\<Union> \<F> - C) \<subseteq> rel_frontier T" "\<And>x. x \<in> \<Union>\<G> \<Longrightarrow> g x = f x"
lp15@64006
   697
proof -
lp15@64006
   698
  define \<H> where "\<H> \<equiv> \<G> \<union> {D. \<exists>C \<in> \<F> - \<G>. D face_of C \<and> aff_dim D < aff_dim T}"
lp15@64006
   699
  have "finite \<G>"
lp15@64006
   700
    using assms finite_subset by blast
lp15@64006
   701
  moreover have "finite (\<Union>{{D. D face_of C} |C. C \<in> \<F>})"
lp15@64006
   702
    apply (rule finite_Union)
lp15@64006
   703
     apply (simp add: \<open>finite \<F>\<close>)
lp15@64006
   704
    using finite_polytope_faces poly by auto
lp15@64006
   705
  ultimately have "finite \<H>"
lp15@64006
   706
    apply (simp add: \<H>_def)
lp15@64006
   707
    apply (rule finite_subset [of _ "\<Union> {{D. D face_of C} | C. C \<in> \<F>}"], auto)
lp15@64006
   708
    done
lp15@64006
   709
  have *: "\<And>X Y. \<lbrakk>X \<in> \<H>; Y \<in> \<H>\<rbrakk> \<Longrightarrow> X \<inter> Y face_of X \<and> X \<inter> Y face_of Y"
lp15@64006
   710
    unfolding \<H>_def
lp15@64006
   711
    apply (elim UnE bexE CollectE DiffE)
lp15@64006
   712
    using subsetD [OF \<open>\<G> \<subseteq> \<F>\<close>] apply (simp_all add: face)
lp15@64006
   713
      apply (meson subsetD [OF \<open>\<G> \<subseteq> \<F>\<close>] face face_of_Int_subface face_of_imp_subset face_of_refl poly polytope_imp_convex)+
lp15@64006
   714
    done
lp15@64006
   715
  obtain h where conth: "continuous_on (\<Union>\<H>) h" and him: "h ` (\<Union>\<H>) \<subseteq> rel_frontier T"
lp15@64006
   716
             and hf: "\<And>x. x \<in> \<Union>\<G> \<Longrightarrow> h x = f x"
lp15@64006
   717
    using \<open>finite \<H>\<close>
lp15@64006
   718
    unfolding \<H>_def
lp15@64006
   719
    apply (rule extend_map_lemma [OF _ Un_upper1 T _ _ _ contf fim])
lp15@64006
   720
    using \<open>\<G> \<subseteq> \<F>\<close> face_of_polytope_polytope poly apply fastforce
lp15@64006
   721
    using * apply (auto simp: \<H>_def)
lp15@64006
   722
    done
lp15@64006
   723
  have "bounded (\<Union>\<G>)"
lp15@64006
   724
    using \<open>finite \<G>\<close> \<open>\<G> \<subseteq> \<F>\<close> poly polytope_imp_bounded by blast
lp15@64006
   725
  then have "\<Union>\<G> \<noteq> UNIV"
lp15@64006
   726
    by auto
lp15@64006
   727
  then obtain a where a: "a \<notin> \<Union>\<G>"
lp15@64006
   728
    by blast
lp15@64006
   729
  have \<F>: "\<exists>a g. a \<notin> \<Union>\<G> \<and> continuous_on (D - {a}) g \<and>
lp15@64006
   730
                  g ` (D - {a}) \<subseteq> rel_frontier T \<and> (\<forall>x \<in> D \<inter> \<Union>\<H>. g x = h x)"
lp15@64006
   731
       if "D \<in> \<F>" for D
lp15@64006
   732
  proof (cases "D \<subseteq> \<Union>\<H>")
lp15@64006
   733
    case True
lp15@64006
   734
    then show ?thesis
lp15@64006
   735
      apply (rule_tac x=a in exI)
lp15@64006
   736
      apply (rule_tac x=h in exI)
lp15@64006
   737
      using him apply (blast intro!: \<open>a \<notin> \<Union>\<G>\<close> continuous_on_subset [OF conth]) +
lp15@64006
   738
      done
lp15@64006
   739
  next
lp15@64006
   740
    case False
lp15@64006
   741
    note D_not_subset = False
lp15@64006
   742
    show ?thesis
lp15@64006
   743
    proof (cases "D \<in> \<G>")
lp15@64006
   744
      case True
lp15@64006
   745
      with D_not_subset show ?thesis
lp15@64006
   746
        by (auto simp: \<H>_def)
lp15@64006
   747
    next
lp15@64006
   748
      case False
lp15@64006
   749
      then have affD: "aff_dim D \<le> aff_dim T"
lp15@64006
   750
        by (simp add: \<open>D \<in> \<F>\<close> aff)
lp15@64006
   751
      show ?thesis
lp15@64006
   752
      proof (cases "rel_interior D = {}")
lp15@64006
   753
        case True
lp15@64006
   754
        with \<open>D \<in> \<F>\<close> poly a show ?thesis
lp15@64006
   755
          by (force simp: rel_interior_eq_empty polytope_imp_convex)
lp15@64006
   756
      next
lp15@64006
   757
        case False
lp15@64006
   758
        then obtain b where brelD: "b \<in> rel_interior D"
lp15@64006
   759
          by blast
lp15@64006
   760
        have "polyhedron D"
lp15@64006
   761
          by (simp add: poly polytope_imp_polyhedron that)
lp15@64006
   762
        have "rel_frontier D retract_of affine hull D - {b}"
lp15@64006
   763
          by (simp add: rel_frontier_retract_of_punctured_affine_hull poly polytope_imp_bounded polytope_imp_convex that brelD)
lp15@64006
   764
        then obtain r where relfD: "rel_frontier D \<subseteq> affine hull D - {b}"
lp15@64006
   765
                        and contr: "continuous_on (affine hull D - {b}) r"
lp15@64006
   766
                        and rim: "r ` (affine hull D - {b}) \<subseteq> rel_frontier D"
lp15@64006
   767
                        and rid: "\<And>x. x \<in> rel_frontier D \<Longrightarrow> r x = x"
lp15@64006
   768
          by (auto simp: retract_of_def retraction_def)
lp15@64006
   769
        show ?thesis
lp15@64006
   770
        proof (intro exI conjI ballI)
lp15@64006
   771
          show "b \<notin> \<Union>\<G>"
lp15@64006
   772
          proof clarify
lp15@64006
   773
            fix E
lp15@64006
   774
            assume "b \<in> E" "E \<in> \<G>"
lp15@64006
   775
            then have "E \<inter> D face_of E \<and> E \<inter> D face_of D"
lp15@64006
   776
              using \<open>\<G> \<subseteq> \<F>\<close> face that by auto
lp15@64006
   777
            with face_of_subset_rel_frontier \<open>E \<in> \<G>\<close> \<open>b \<in> E\<close> brelD rel_interior_subset [of D]
lp15@64006
   778
                 D_not_subset rel_frontier_def \<H>_def
lp15@64006
   779
            show False
lp15@64006
   780
              by blast
lp15@64006
   781
          qed
lp15@64006
   782
          have "r ` (D - {b}) \<subseteq> r ` (affine hull D - {b})"
lp15@64006
   783
            by (simp add: Diff_mono hull_subset image_mono)
lp15@64006
   784
          also have "... \<subseteq> rel_frontier D"
lp15@64006
   785
            by (rule rim)
lp15@64006
   786
          also have "... \<subseteq> \<Union>{E. E face_of D \<and> aff_dim E < aff_dim T}"
lp15@64006
   787
            using affD
lp15@64006
   788
            by (force simp: rel_frontier_of_polyhedron [OF \<open>polyhedron D\<close>] facet_of_def)
lp15@64006
   789
          also have "... \<subseteq> \<Union>(\<H>)"
lp15@64006
   790
            using D_not_subset \<H>_def that by fastforce
lp15@64006
   791
          finally have rsub: "r ` (D - {b}) \<subseteq> \<Union>(\<H>)" .
lp15@64006
   792
          show "continuous_on (D - {b}) (h \<circ> r)"
lp15@64006
   793
            apply (intro conjI \<open>b \<notin> \<Union>\<G>\<close> continuous_on_compose)
lp15@64006
   794
               apply (rule continuous_on_subset [OF contr])
lp15@64006
   795
            apply (simp add: Diff_mono hull_subset)
lp15@64006
   796
            apply (rule continuous_on_subset [OF conth rsub])
lp15@64006
   797
            done
lp15@64006
   798
          show "(h \<circ> r) ` (D - {b}) \<subseteq> rel_frontier T"
lp15@64006
   799
            using brelD him rsub by fastforce
lp15@64006
   800
          show "(h \<circ> r) x = h x" if x: "x \<in> D \<inter> \<Union>\<H>" for x
lp15@64006
   801
          proof -
lp15@64006
   802
            consider A where "x \<in> D" "A \<in> \<G>" "x \<in> A"
lp15@64006
   803
                 | A B where "x \<in> D" "A face_of B" "B \<in> \<F>" "B \<notin> \<G>" "aff_dim A < aff_dim T" "x \<in> A"
lp15@64006
   804
              using x by (auto simp: \<H>_def)
lp15@64006
   805
            then have xrel: "x \<in> rel_frontier D"
lp15@64006
   806
            proof cases
lp15@64006
   807
              case 1 show ?thesis
lp15@64006
   808
              proof (rule face_of_subset_rel_frontier [THEN subsetD])
lp15@64006
   809
                show "D \<inter> A face_of D"
lp15@64006
   810
                  using \<open>A \<in> \<G>\<close> \<open>\<G> \<subseteq> \<F>\<close> face \<open>D \<in> \<F>\<close> by blast
lp15@64006
   811
                show "D \<inter> A \<noteq> D"
lp15@64006
   812
                  using \<open>A \<in> \<G>\<close> D_not_subset \<H>_def by blast
lp15@64006
   813
              qed (auto simp: 1)
lp15@64006
   814
            next
lp15@64006
   815
              case 2 show ?thesis
lp15@64006
   816
              proof (rule face_of_subset_rel_frontier [THEN subsetD])
lp15@64006
   817
                show "D \<inter> A face_of D"
lp15@64006
   818
                  apply (rule face_of_Int_subface [of D B _ A, THEN conjunct1])
lp15@64006
   819
                     apply (simp_all add: 2 \<open>D \<in> \<F>\<close> face)
lp15@64006
   820
                   apply (simp add: \<open>polyhedron D\<close> polyhedron_imp_convex face_of_refl)
lp15@64006
   821
                  done
lp15@64006
   822
                show "D \<inter> A \<noteq> D"
lp15@64006
   823
                  using "2" D_not_subset \<H>_def by blast
lp15@64006
   824
              qed (auto simp: 2)
lp15@64006
   825
            qed
lp15@64006
   826
            show ?thesis
lp15@64006
   827
              by (simp add: rid xrel)
lp15@64006
   828
          qed
lp15@64006
   829
        qed
lp15@64006
   830
      qed
lp15@64006
   831
    qed
lp15@64006
   832
  qed
lp15@64006
   833
  have clo: "\<And>S. S \<in> \<F> \<Longrightarrow> closed S"
lp15@64006
   834
    by (simp add: poly polytope_imp_closed)
lp15@64006
   835
  obtain C g where "finite C" "disjnt C (\<Union>\<G>)" "card C \<le> card \<F>" "continuous_on (\<Union>\<F> - C) g"
lp15@64006
   836
                   "g ` (\<Union>\<F> - C) \<subseteq> rel_frontier T"
lp15@64006
   837
               and gh: "\<And>x. x \<in> (\<Union>\<F> - C) \<inter> \<Union>\<H> \<Longrightarrow> g x = h x"
lp15@64006
   838
  proof (rule extend_map_lemma_cofinite1 [OF \<open>finite \<F>\<close> \<F> clo])
lp15@64006
   839
    show "X \<inter> Y \<subseteq> \<Union>\<H>" if XY: "X \<in> \<F>" "Y \<in> \<F>" and "\<not> X \<subseteq> Y" "\<not> Y \<subseteq> X" for X Y
lp15@64006
   840
    proof (cases "X \<in> \<G>")
lp15@64006
   841
      case True
lp15@64006
   842
      then show ?thesis
lp15@64006
   843
        by (auto simp: \<H>_def)
lp15@64006
   844
    next
lp15@64006
   845
      case False
lp15@64006
   846
      have "X \<inter> Y \<noteq> X"
lp15@64006
   847
        using \<open>\<not> X \<subseteq> Y\<close> by blast
lp15@64006
   848
      with XY
lp15@64006
   849
      show ?thesis
lp15@64006
   850
        by (clarsimp simp: \<H>_def)
lp15@64006
   851
           (metis Diff_iff Int_iff aff antisym_conv face face_of_aff_dim_lt face_of_refl
lp15@64006
   852
                  not_le poly polytope_imp_convex)
lp15@64006
   853
    qed
lp15@64006
   854
  qed (blast)+
lp15@64006
   855
  with \<open>\<G> \<subseteq> \<F>\<close> show ?thesis
lp15@64006
   856
    apply (rule_tac C=C and g=g in that)
lp15@64006
   857
     apply (auto simp: disjnt_def hf [symmetric] \<H>_def intro!: gh)
lp15@64006
   858
    done
lp15@64006
   859
qed
lp15@64006
   860
lp15@64006
   861
text\<open>The next two proofs are similar\<close>
lp15@64006
   862
theorem extend_map_cell_complex_to_sphere:
lp15@64006
   863
  assumes "finite \<F>" and S: "S \<subseteq> \<Union>\<F>" "closed S" and T: "convex T" "bounded T"
lp15@64006
   864
      and poly: "\<And>X. X \<in> \<F> \<Longrightarrow> polytope X"
lp15@64006
   865
      and aff: "\<And>X. X \<in> \<F> \<Longrightarrow> aff_dim X < aff_dim T"
lp15@64006
   866
      and face: "\<And>X Y. \<lbrakk>X \<in> \<F>; Y \<in> \<F>\<rbrakk> \<Longrightarrow> (X \<inter> Y) face_of X \<and> (X \<inter> Y) face_of Y"
lp15@64006
   867
      and contf: "continuous_on S f" and fim: "f ` S \<subseteq> rel_frontier T"
lp15@64006
   868
  obtains g where "continuous_on (\<Union>\<F>) g"
lp15@64006
   869
     "g ` (\<Union>\<F>) \<subseteq> rel_frontier T" "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
   870
proof -
lp15@64006
   871
  obtain V g where "S \<subseteq> V" "open V" "continuous_on V g" and gim: "g ` V \<subseteq> rel_frontier T" and gf: "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
   872
    using neighbourhood_extension_into_ANR [OF contf fim _ \<open>closed S\<close>] ANR_rel_frontier_convex T by blast
lp15@64006
   873
  have "compact S"
lp15@64006
   874
    by (meson assms compact_Union poly polytope_imp_compact seq_compact_closed_subset seq_compact_eq_compact)
lp15@64006
   875
  then obtain d where "d > 0" and d: "\<And>x y. \<lbrakk>x \<in> S; y \<in> - V\<rbrakk> \<Longrightarrow> d \<le> dist x y"
lp15@64006
   876
    using separate_compact_closed [of S "-V"] \<open>open V\<close> \<open>S \<subseteq> V\<close> by force
lp15@64006
   877
  obtain \<G> where "finite \<G>" "\<Union>\<G> = \<Union>\<F>"
lp15@64006
   878
             and diaG: "\<And>X. X \<in> \<G> \<Longrightarrow> diameter X < d"
lp15@64006
   879
             and polyG: "\<And>X. X \<in> \<G> \<Longrightarrow> polytope X"
lp15@64006
   880
             and affG: "\<And>X. X \<in> \<G> \<Longrightarrow> aff_dim X \<le> aff_dim T - 1"
lp15@64006
   881
             and faceG: "\<And>X Y. \<lbrakk>X \<in> \<G>; Y \<in> \<G>\<rbrakk> \<Longrightarrow> X \<inter> Y face_of X \<and> X \<inter> Y face_of Y"
lp15@64006
   882
  proof (rule cell_complex_subdivision_exists [OF \<open>d>0\<close> \<open>finite \<F>\<close> poly _ face])
lp15@64006
   883
    show "\<And>X. X \<in> \<F> \<Longrightarrow> aff_dim X \<le> aff_dim T - 1"
lp15@64006
   884
      by (simp add: aff)
lp15@64006
   885
  qed auto
lp15@64006
   886
  obtain h where conth: "continuous_on (\<Union>\<G>) h" and him: "h ` \<Union>\<G> \<subseteq> rel_frontier T" and hg: "\<And>x. x \<in> \<Union>(\<G> \<inter> Pow V) \<Longrightarrow> h x = g x"
lp15@64006
   887
  proof (rule extend_map_lemma [of \<G> "\<G> \<inter> Pow V" T g])
lp15@64006
   888
    show "continuous_on (\<Union>(\<G> \<inter> Pow V)) g"
lp15@64006
   889
      by (metis Union_Int_subset Union_Pow_eq \<open>continuous_on V g\<close> continuous_on_subset le_inf_iff)
lp15@64006
   890
  qed (use \<open>finite \<G>\<close> T polyG affG faceG gim in fastforce)+
lp15@64006
   891
  show ?thesis
lp15@64006
   892
  proof
lp15@64006
   893
    show "continuous_on (\<Union>\<F>) h"
lp15@64006
   894
      using \<open>\<Union>\<G> = \<Union>\<F>\<close> conth by auto
lp15@64006
   895
    show "h ` \<Union>\<F> \<subseteq> rel_frontier T"
lp15@64006
   896
      using \<open>\<Union>\<G> = \<Union>\<F>\<close> him by auto
lp15@64006
   897
    show "h x = f x" if "x \<in> S" for x
lp15@64006
   898
    proof -
lp15@64006
   899
      have "x \<in> \<Union>\<G>"
lp15@64006
   900
        using \<open>\<Union>\<G> = \<Union>\<F>\<close> \<open>S \<subseteq> \<Union>\<F>\<close> that by auto
lp15@64006
   901
      then obtain X where "x \<in> X" "X \<in> \<G>" by blast
lp15@64006
   902
      then have "diameter X < d" "bounded X"
lp15@64006
   903
        by (auto simp: diaG \<open>X \<in> \<G>\<close> polyG polytope_imp_bounded)
lp15@64006
   904
      then have "X \<subseteq> V" using d [OF \<open>x \<in> S\<close>] diameter_bounded_bound [OF \<open>bounded X\<close> \<open>x \<in> X\<close>]
lp15@64006
   905
        by fastforce
lp15@64006
   906
      have "h x = g x"
lp15@64006
   907
        apply (rule hg)
lp15@64006
   908
        using \<open>X \<in> \<G>\<close> \<open>X \<subseteq> V\<close> \<open>x \<in> X\<close> by blast
lp15@64006
   909
      also have "... = f x"
lp15@64006
   910
        by (simp add: gf that)
lp15@64006
   911
      finally show "h x = f x" .
lp15@64006
   912
    qed
lp15@64006
   913
  qed
lp15@64006
   914
qed
lp15@64006
   915
lp15@64006
   916
lp15@64006
   917
theorem extend_map_cell_complex_to_sphere_cofinite:
lp15@64006
   918
  assumes "finite \<F>" and S: "S \<subseteq> \<Union>\<F>" "closed S" and T: "convex T" "bounded T"
lp15@64006
   919
      and poly: "\<And>X. X \<in> \<F> \<Longrightarrow> polytope X"
lp15@64006
   920
      and aff: "\<And>X. X \<in> \<F> \<Longrightarrow> aff_dim X \<le> aff_dim T"
lp15@64006
   921
      and face: "\<And>X Y. \<lbrakk>X \<in> \<F>; Y \<in> \<F>\<rbrakk> \<Longrightarrow> (X \<inter> Y) face_of X \<and> (X \<inter> Y) face_of Y"
lp15@64006
   922
      and contf: "continuous_on S f" and fim: "f ` S \<subseteq> rel_frontier T"
lp15@64006
   923
  obtains C g where "finite C" "disjnt C S" "continuous_on (\<Union>\<F> - C) g"
lp15@64006
   924
     "g ` (\<Union>\<F> - C) \<subseteq> rel_frontier T" "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
   925
proof -
lp15@64006
   926
  obtain V g where "S \<subseteq> V" "open V" "continuous_on V g" and gim: "g ` V \<subseteq> rel_frontier T" and gf: "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
   927
    using neighbourhood_extension_into_ANR [OF contf fim _ \<open>closed S\<close>] ANR_rel_frontier_convex T by blast
lp15@64006
   928
  have "compact S"
lp15@64006
   929
    by (meson assms compact_Union poly polytope_imp_compact seq_compact_closed_subset seq_compact_eq_compact)
lp15@64006
   930
  then obtain d where "d > 0" and d: "\<And>x y. \<lbrakk>x \<in> S; y \<in> - V\<rbrakk> \<Longrightarrow> d \<le> dist x y"
lp15@64006
   931
    using separate_compact_closed [of S "-V"] \<open>open V\<close> \<open>S \<subseteq> V\<close> by force
lp15@64006
   932
  obtain \<G> where "finite \<G>" "\<Union>\<G> = \<Union>\<F>"
lp15@64006
   933
             and diaG: "\<And>X. X \<in> \<G> \<Longrightarrow> diameter X < d"
lp15@64006
   934
             and polyG: "\<And>X. X \<in> \<G> \<Longrightarrow> polytope X"
lp15@64006
   935
             and affG: "\<And>X. X \<in> \<G> \<Longrightarrow> aff_dim X \<le> aff_dim T"
lp15@64006
   936
             and faceG: "\<And>X Y. \<lbrakk>X \<in> \<G>; Y \<in> \<G>\<rbrakk> \<Longrightarrow> X \<inter> Y face_of X \<and> X \<inter> Y face_of Y"
lp15@64006
   937
    by (rule cell_complex_subdivision_exists [OF \<open>d>0\<close> \<open>finite \<F>\<close> poly aff face]) auto
lp15@64006
   938
  obtain C h where "finite C" and dis: "disjnt C (\<Union>(\<G> \<inter> Pow V))"
lp15@64006
   939
               and card: "card C \<le> card \<G>" and conth: "continuous_on (\<Union>\<G> - C) h"
lp15@64006
   940
               and him: "h ` (\<Union>\<G> - C) \<subseteq> rel_frontier T"
lp15@64006
   941
               and hg: "\<And>x. x \<in> \<Union>(\<G> \<inter> Pow V) \<Longrightarrow> h x = g x"
lp15@64006
   942
  proof (rule extend_map_lemma_cofinite [of \<G> "\<G> \<inter> Pow V" T g])
lp15@64006
   943
    show "continuous_on (\<Union>(\<G> \<inter> Pow V)) g"
lp15@64006
   944
      by (metis Union_Int_subset Union_Pow_eq \<open>continuous_on V g\<close> continuous_on_subset le_inf_iff)
lp15@64006
   945
    show "g ` \<Union>(\<G> \<inter> Pow V) \<subseteq> rel_frontier T"
lp15@64006
   946
      using gim by force
lp15@64006
   947
  qed (auto intro: \<open>finite \<G>\<close> T polyG affG dest: faceG)
lp15@64006
   948
  have Ssub: "S \<subseteq> \<Union>(\<G> \<inter> Pow V)"
lp15@64006
   949
  proof
lp15@64006
   950
    fix x
lp15@64006
   951
    assume "x \<in> S"
lp15@64006
   952
    then have "x \<in> \<Union>\<G>"
lp15@64006
   953
      using \<open>\<Union>\<G> = \<Union>\<F>\<close> \<open>S \<subseteq> \<Union>\<F>\<close> by auto
lp15@64006
   954
    then obtain X where "x \<in> X" "X \<in> \<G>" by blast
lp15@64006
   955
    then have "diameter X < d" "bounded X"
lp15@64006
   956
      by (auto simp: diaG \<open>X \<in> \<G>\<close> polyG polytope_imp_bounded)
lp15@64006
   957
    then have "X \<subseteq> V" using d [OF \<open>x \<in> S\<close>] diameter_bounded_bound [OF \<open>bounded X\<close> \<open>x \<in> X\<close>]
lp15@64006
   958
      by fastforce
lp15@64006
   959
    then show "x \<in> \<Union>(\<G> \<inter> Pow V)"
lp15@64006
   960
      using \<open>X \<in> \<G>\<close> \<open>x \<in> X\<close> by blast
lp15@64006
   961
  qed
lp15@64006
   962
  show ?thesis
lp15@64006
   963
  proof
lp15@64006
   964
    show "continuous_on (\<Union>\<F>-C) h"
lp15@64006
   965
      using \<open>\<Union>\<G> = \<Union>\<F>\<close> conth by auto
lp15@64006
   966
    show "h ` (\<Union>\<F> - C) \<subseteq> rel_frontier T"
lp15@64006
   967
      using \<open>\<Union>\<G> = \<Union>\<F>\<close> him by auto
lp15@64006
   968
    show "h x = f x" if "x \<in> S" for x
lp15@64006
   969
    proof -
lp15@64006
   970
      have "h x = g x"
lp15@64006
   971
        apply (rule hg)
lp15@64006
   972
        using Ssub that by blast
lp15@64006
   973
      also have "... = f x"
lp15@64006
   974
        by (simp add: gf that)
lp15@64006
   975
      finally show "h x = f x" .
lp15@64006
   976
    qed
lp15@64006
   977
    show "disjnt C S"
lp15@64006
   978
      using dis Ssub  by (meson disjnt_iff subset_eq)
lp15@64006
   979
  qed (intro \<open>finite C\<close>)
lp15@64006
   980
qed
lp15@64006
   981
lp15@64006
   982
lp15@64006
   983
lp15@64006
   984
subsection\<open> Special cases and corollaries involving spheres.\<close>
lp15@64006
   985
lp15@64006
   986
lemma disjnt_Diff1: "X \<subseteq> Y' \<Longrightarrow> disjnt (X - Y) (X' - Y')"
lp15@64006
   987
  by (auto simp: disjnt_def)
lp15@64006
   988
lp15@64006
   989
proposition extend_map_affine_to_sphere_cofinite_simple:
lp15@64006
   990
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64006
   991
  assumes "compact S" "convex U" "bounded U"
lp15@64006
   992
      and aff: "aff_dim T \<le> aff_dim U"
lp15@64006
   993
      and "S \<subseteq> T" and contf: "continuous_on S f"
lp15@64006
   994
      and fim: "f ` S \<subseteq> rel_frontier U"
lp15@64006
   995
 obtains K g where "finite K" "K \<subseteq> T" "disjnt K S" "continuous_on (T - K) g"
lp15@64006
   996
                   "g ` (T - K) \<subseteq> rel_frontier U"
lp15@64006
   997
                   "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
   998
proof -
lp15@64006
   999
  have "\<exists>K g. finite K \<and> disjnt K S \<and> continuous_on (T - K) g \<and>
lp15@64006
  1000
              g ` (T - K) \<subseteq> rel_frontier U \<and> (\<forall>x \<in> S. g x = f x)"
lp15@64006
  1001
       if "affine T" "S \<subseteq> T" and aff: "aff_dim T \<le> aff_dim U"  for T
lp15@64006
  1002
  proof (cases "S = {}")
lp15@64006
  1003
    case True
lp15@64006
  1004
    show ?thesis
lp15@64006
  1005
    proof (cases "rel_frontier U = {}")
lp15@64006
  1006
      case True
lp15@64006
  1007
      with \<open>bounded U\<close> have "aff_dim U \<le> 0"
lp15@64006
  1008
        using affine_bounded_eq_lowdim rel_frontier_eq_empty by auto
lp15@64006
  1009
      with aff have "aff_dim T \<le> 0" by auto
lp15@64006
  1010
      then obtain a where "T \<subseteq> {a}"
lp15@64006
  1011
        using \<open>affine T\<close> affine_bounded_eq_lowdim affine_bounded_eq_trivial by auto
lp15@64006
  1012
      then show ?thesis
lp15@64006
  1013
        using \<open>S = {}\<close> fim
lp15@64006
  1014
        by (metis Diff_cancel contf disjnt_empty2 finite.emptyI finite_insert finite_subset)
lp15@64006
  1015
    next
lp15@64006
  1016
      case False
lp15@64006
  1017
      then obtain a where "a \<in> rel_frontier U"
lp15@64006
  1018
        by auto
lp15@64006
  1019
      then show ?thesis
lp15@64006
  1020
        using continuous_on_const [of _ a] \<open>S = {}\<close> by force
lp15@64006
  1021
    qed
lp15@64006
  1022
  next
lp15@64006
  1023
    case False
lp15@64006
  1024
    have "bounded S"
lp15@64006
  1025
      by (simp add: \<open>compact S\<close> compact_imp_bounded)
lp15@64006
  1026
    then obtain b where b: "S \<subseteq> cbox (-b) b"
lp15@64006
  1027
      using bounded_subset_cbox_symmetric by blast
lp15@64006
  1028
    define bbox where "bbox \<equiv> cbox (-(b+One)) (b+One)"
lp15@64006
  1029
    have "cbox (-b) b \<subseteq> bbox"
lp15@64006
  1030
      by (auto simp: bbox_def algebra_simps intro!: subset_box_imp)
lp15@64006
  1031
    with b \<open>S \<subseteq> T\<close> have "S \<subseteq> bbox \<inter> T"
lp15@64006
  1032
      by auto
lp15@64006
  1033
    then have Ssub: "S \<subseteq> \<Union>{bbox \<inter> T}"
lp15@64006
  1034
      by auto
lp15@64006
  1035
    then have "aff_dim (bbox \<inter> T) \<le> aff_dim U"
lp15@64006
  1036
      by (metis aff aff_dim_subset inf_commute inf_le1 order_trans)
lp15@64006
  1037
    obtain K g where K: "finite K" "disjnt K S"
lp15@64006
  1038
                 and contg: "continuous_on (\<Union>{bbox \<inter> T} - K) g"
lp15@64006
  1039
                 and gim: "g ` (\<Union>{bbox \<inter> T} - K) \<subseteq> rel_frontier U"
lp15@64006
  1040
                 and gf: "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1041
    proof (rule extend_map_cell_complex_to_sphere_cofinite
lp15@64006
  1042
              [OF _ Ssub _ \<open>convex U\<close> \<open>bounded U\<close> _ _ _ contf fim])
lp15@64006
  1043
      show "closed S"
lp15@64006
  1044
        using \<open>compact S\<close> compact_eq_bounded_closed by auto
lp15@64006
  1045
      show poly: "\<And>X. X \<in> {bbox \<inter> T} \<Longrightarrow> polytope X"
lp15@64006
  1046
        by (simp add: polytope_Int_polyhedron bbox_def polytope_interval affine_imp_polyhedron \<open>affine T\<close>)
lp15@64006
  1047
      show "\<And>X Y. \<lbrakk>X \<in> {bbox \<inter> T}; Y \<in> {bbox \<inter> T}\<rbrakk> \<Longrightarrow> X \<inter> Y face_of X \<and> X \<inter> Y face_of Y"
lp15@64006
  1048
        by (simp add:poly face_of_refl polytope_imp_convex)
lp15@64006
  1049
      show "\<And>X. X \<in> {bbox \<inter> T} \<Longrightarrow> aff_dim X \<le> aff_dim U"
lp15@64006
  1050
        by (simp add: \<open>aff_dim (bbox \<inter> T) \<le> aff_dim U\<close>)
lp15@64006
  1051
    qed auto
lp15@64006
  1052
    define fro where "fro \<equiv> \<lambda>d. frontier(cbox (-(b + d *\<^sub>R One)) (b + d *\<^sub>R One))"
lp15@64006
  1053
    obtain d where d12: "1/2 \<le> d" "d \<le> 1" and dd: "disjnt K (fro d)"
lp15@64006
  1054
    proof (rule disjoint_family_elem_disjnt [OF _ \<open>finite K\<close>])
lp15@64006
  1055
      show "infinite {1/2..1::real}"
lp15@64006
  1056
        by (simp add: infinite_Icc)
lp15@64006
  1057
      have dis1: "disjnt (fro x) (fro y)" if "x<y" for x y
lp15@64006
  1058
        by (auto simp: algebra_simps that subset_box_imp disjnt_Diff1 frontier_def fro_def)
lp15@64006
  1059
      then show "disjoint_family_on fro {1/2..1}"
lp15@64006
  1060
        by (auto simp: disjoint_family_on_def disjnt_def neq_iff)
lp15@64006
  1061
    qed auto
lp15@64006
  1062
    define c where "c \<equiv> b + d *\<^sub>R One"
lp15@64006
  1063
    have cbsub: "cbox (-b) b \<subseteq> box (-c) c"  "cbox (-b) b \<subseteq> cbox (-c) c"  "cbox (-c) c \<subseteq> bbox"
lp15@64006
  1064
      using d12 by (auto simp: algebra_simps subset_box_imp c_def bbox_def)
lp15@64006
  1065
    have clo_cbT: "closed (cbox (- c) c \<inter> T)"
lp15@64006
  1066
      by (simp add: affine_closed closed_Int closed_cbox \<open>affine T\<close>)
lp15@64006
  1067
    have cpT_ne: "cbox (- c) c \<inter> T \<noteq> {}"
lp15@64006
  1068
      using \<open>S \<noteq> {}\<close> b cbsub(2) \<open>S \<subseteq> T\<close> by fastforce
lp15@64006
  1069
    have "closest_point (cbox (- c) c \<inter> T) x \<notin> K" if "x \<in> T" "x \<notin> K" for x
lp15@64006
  1070
    proof (cases "x \<in> cbox (-c) c")
lp15@64006
  1071
      case True with that show ?thesis
lp15@64006
  1072
        by (simp add: closest_point_self)
lp15@64006
  1073
    next
lp15@64006
  1074
      case False
lp15@64006
  1075
      have int_ne: "interior (cbox (-c) c) \<inter> T \<noteq> {}"
lp15@64006
  1076
        using \<open>S \<noteq> {}\<close> \<open>S \<subseteq> T\<close> b \<open>cbox (- b) b \<subseteq> box (- c) c\<close> by force
lp15@64006
  1077
      have "convex T"
lp15@64006
  1078
        by (meson \<open>affine T\<close> affine_imp_convex)
lp15@64006
  1079
      then have "x \<in> affine hull (cbox (- c) c \<inter> T)"
lp15@64006
  1080
          by (metis Int_commute Int_iff \<open>S \<noteq> {}\<close> \<open>S \<subseteq> T\<close> cbsub(1) \<open>x \<in> T\<close> affine_hull_convex_Int_nonempty_interior all_not_in_conv b hull_inc inf.orderE interior_cbox)
lp15@64006
  1081
      then have "x \<in> affine hull (cbox (- c) c \<inter> T) - rel_interior (cbox (- c) c \<inter> T)"
lp15@64006
  1082
        by (meson DiffI False Int_iff rel_interior_subset subsetCE)
lp15@64006
  1083
      then have "closest_point (cbox (- c) c \<inter> T) x \<in> rel_frontier (cbox (- c) c \<inter> T)"
lp15@64006
  1084
        by (rule closest_point_in_rel_frontier [OF clo_cbT cpT_ne])
lp15@64006
  1085
      moreover have "(rel_frontier (cbox (- c) c \<inter> T)) \<subseteq> fro d"
lp15@64006
  1086
        apply (subst convex_affine_rel_frontier_Int [OF _  \<open>affine T\<close> int_ne])
lp15@64006
  1087
         apply (auto simp: fro_def c_def)
lp15@64006
  1088
        done
lp15@64006
  1089
      ultimately show ?thesis
lp15@64006
  1090
        using dd  by (force simp: disjnt_def)
lp15@64006
  1091
    qed
lp15@64006
  1092
    then have cpt_subset: "closest_point (cbox (- c) c \<inter> T) ` (T - K) \<subseteq> \<Union>{bbox \<inter> T} - K"
lp15@64006
  1093
      using closest_point_in_set [OF clo_cbT cpT_ne] cbsub(3) by force
lp15@64006
  1094
    show ?thesis
lp15@64006
  1095
    proof (intro conjI ballI exI)
lp15@64006
  1096
      have "continuous_on (T - K) (closest_point (cbox (- c) c \<inter> T))"
lp15@64006
  1097
        apply (rule continuous_on_closest_point)
lp15@64006
  1098
        using \<open>S \<noteq> {}\<close> cbsub(2) b that
lp15@64006
  1099
        by (auto simp: affine_imp_convex convex_Int affine_closed closed_Int closed_cbox \<open>affine T\<close>)
lp15@64006
  1100
      then show "continuous_on (T - K) (g \<circ> closest_point (cbox (- c) c \<inter> T))"
lp15@64006
  1101
        by (metis continuous_on_compose continuous_on_subset [OF contg cpt_subset])
lp15@64006
  1102
      have "(g \<circ> closest_point (cbox (- c) c \<inter> T)) ` (T - K) \<subseteq> g ` (\<Union>{bbox \<inter> T} - K)"
lp15@64006
  1103
        by (metis image_comp image_mono cpt_subset)
lp15@64006
  1104
      also have "... \<subseteq> rel_frontier U"
lp15@64006
  1105
        by (rule gim)
lp15@64006
  1106
      finally show "(g \<circ> closest_point (cbox (- c) c \<inter> T)) ` (T - K) \<subseteq> rel_frontier U" .
lp15@64006
  1107
      show "(g \<circ> closest_point (cbox (- c) c \<inter> T)) x = f x" if "x \<in> S" for x
lp15@64006
  1108
      proof -
lp15@64006
  1109
        have "(g \<circ> closest_point (cbox (- c) c \<inter> T)) x = g x"
lp15@64006
  1110
          unfolding o_def
lp15@64006
  1111
          by (metis IntI \<open>S \<subseteq> T\<close> b cbsub(2) closest_point_self subset_eq that)
lp15@64006
  1112
        also have "... = f x"
lp15@64006
  1113
          by (simp add: that gf)
lp15@64006
  1114
        finally show ?thesis .
lp15@64006
  1115
      qed
lp15@64006
  1116
    qed (auto simp: K)
lp15@64006
  1117
  qed
lp15@64006
  1118
  then obtain K g where "finite K" "disjnt K S"
lp15@64006
  1119
               and contg: "continuous_on (affine hull T - K) g"
lp15@64006
  1120
               and gim:  "g ` (affine hull T - K) \<subseteq> rel_frontier U"
lp15@64006
  1121
               and gf:   "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1122
    by (metis aff affine_affine_hull aff_dim_affine_hull
lp15@64006
  1123
              order_trans [OF \<open>S \<subseteq> T\<close> hull_subset [of T affine]])
lp15@64006
  1124
  then obtain K g where "finite K" "disjnt K S"
lp15@64006
  1125
               and contg: "continuous_on (T - K) g"
lp15@64006
  1126
               and gim:  "g ` (T - K) \<subseteq> rel_frontier U"
lp15@64006
  1127
               and gf:   "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1128
    by (rule_tac K=K and g=g in that) (auto simp: hull_inc elim: continuous_on_subset)
lp15@64006
  1129
  then show ?thesis
lp15@64006
  1130
    by (rule_tac K="K \<inter> T" and g=g in that) (auto simp: disjnt_iff Diff_Int contg)
lp15@64006
  1131
qed
lp15@64006
  1132
lp15@64006
  1133
subsection\<open>Extending maps to spheres\<close>
lp15@64006
  1134
lp15@64006
  1135
(*Up to extend_map_affine_to_sphere_cofinite_gen*)
lp15@64006
  1136
lp15@64006
  1137
lemma extend_map_affine_to_sphere1:
lp15@64006
  1138
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::topological_space"
lp15@64006
  1139
  assumes "finite K" "affine U" and contf: "continuous_on (U - K) f"
lp15@64006
  1140
      and fim: "f ` (U - K) \<subseteq> T"
lp15@64006
  1141
      and comps: "\<And>C. \<lbrakk>C \<in> components(U - S); C \<inter> K \<noteq> {}\<rbrakk> \<Longrightarrow> C \<inter> L \<noteq> {}"
lp15@64006
  1142
      and clo: "closedin (subtopology euclidean U) S" and K: "disjnt K S" "K \<subseteq> U"
lp15@64006
  1143
  obtains g where "continuous_on (U - L) g" "g ` (U - L) \<subseteq> T" "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1144
proof (cases "K = {}")
lp15@64006
  1145
  case True
lp15@64006
  1146
  then show ?thesis
lp15@64006
  1147
    by (metis Diff_empty Diff_subset contf fim continuous_on_subset image_subsetI rev_image_eqI subset_iff that)
lp15@64006
  1148
next
lp15@64006
  1149
  case False
lp15@64006
  1150
  have "S \<subseteq> U"
lp15@64006
  1151
    using clo closedin_limpt by blast
lp15@64006
  1152
  then have "(U - S) \<inter> K \<noteq> {}"
lp15@64006
  1153
    by (metis Diff_triv False Int_Diff K disjnt_def inf.absorb_iff2 inf_commute)
lp15@64006
  1154
  then have "\<Union>(components (U - S)) \<inter> K \<noteq> {}"
lp15@64006
  1155
    using Union_components by simp
lp15@64006
  1156
  then obtain C0 where C0: "C0 \<in> components (U - S)" "C0 \<inter> K \<noteq> {}"
lp15@64006
  1157
    by blast
lp15@64006
  1158
  have "convex U"
lp15@64006
  1159
    by (simp add: affine_imp_convex \<open>affine U\<close>)
lp15@64006
  1160
  then have "locally connected U"
lp15@64006
  1161
    by (rule convex_imp_locally_connected)
lp15@64006
  1162
  have "\<exists>a g. a \<in> C \<and> a \<in> L \<and> continuous_on (S \<union> (C - {a})) g \<and>
lp15@64006
  1163
              g ` (S \<union> (C - {a})) \<subseteq> T \<and> (\<forall>x \<in> S. g x = f x)"
lp15@64006
  1164
       if C: "C \<in> components (U - S)" and CK: "C \<inter> K \<noteq> {}" for C
lp15@64006
  1165
  proof -
lp15@64006
  1166
    have "C \<subseteq> U-S" "C \<inter> L \<noteq> {}"
lp15@64006
  1167
      by (simp_all add: in_components_subset comps that)
lp15@64006
  1168
    then obtain a where a: "a \<in> C" "a \<in> L" by auto
lp15@64006
  1169
    have opeUC: "openin (subtopology euclidean U) C"
lp15@64006
  1170
    proof (rule openin_trans)
lp15@64006
  1171
      show "openin (subtopology euclidean (U-S)) C"
lp15@64006
  1172
        by (simp add: \<open>locally connected U\<close> clo locally_diff_closed openin_components_locally_connected [OF _ C])
lp15@64006
  1173
      show "openin (subtopology euclidean U) (U - S)"
lp15@64006
  1174
        by (simp add: clo openin_diff)
lp15@64006
  1175
    qed
lp15@64006
  1176
    then obtain d where "C \<subseteq> U" "0 < d" and d: "cball a d \<inter> U \<subseteq> C"
lp15@64006
  1177
      using openin_contains_cball by (metis \<open>a \<in> C\<close>)
lp15@64006
  1178
    then have "ball a d \<inter> U \<subseteq> C"
lp15@64006
  1179
      by auto
lp15@64006
  1180
    obtain h k where homhk: "homeomorphism (S \<union> C) (S \<union> C) h k"
lp15@64006
  1181
                 and subC: "{x. (~ (h x = x \<and> k x = x))} \<subseteq> C"
lp15@64006
  1182
                 and bou: "bounded {x. (~ (h x = x \<and> k x = x))}"
lp15@64006
  1183
                 and hin: "\<And>x. x \<in> C \<inter> K \<Longrightarrow> h x \<in> ball a d \<inter> U"
lp15@64006
  1184
    proof (rule homeomorphism_grouping_points_exists_gen [of C "ball a d \<inter> U" "C \<inter> K" "S \<union> C"])
lp15@64006
  1185
      show "openin (subtopology euclidean C) (ball a d \<inter> U)"
lp15@66827
  1186
        by (metis open_ball \<open>C \<subseteq> U\<close> \<open>ball a d \<inter> U \<subseteq> C\<close> inf.absorb_iff2 inf.orderE inf_assoc open_openin openin_subtopology)
lp15@64006
  1187
      show "openin (subtopology euclidean (affine hull C)) C"
lp15@64006
  1188
        by (metis \<open>a \<in> C\<close> \<open>openin (subtopology euclidean U) C\<close> affine_hull_eq affine_hull_openin all_not_in_conv \<open>affine U\<close>)
lp15@64006
  1189
      show "ball a d \<inter> U \<noteq> {}"
lp15@64006
  1190
        using \<open>0 < d\<close> \<open>C \<subseteq> U\<close> \<open>a \<in> C\<close> by force
lp15@64006
  1191
      show "finite (C \<inter> K)"
lp15@64006
  1192
        by (simp add: \<open>finite K\<close>)
lp15@64006
  1193
      show "S \<union> C \<subseteq> affine hull C"
lp15@64006
  1194
        by (metis \<open>C \<subseteq> U\<close> \<open>S \<subseteq> U\<close> \<open>a \<in> C\<close> opeUC affine_hull_eq affine_hull_openin all_not_in_conv assms(2) sup.bounded_iff)
lp15@64006
  1195
      show "connected C"
lp15@64006
  1196
        by (metis C in_components_connected)
lp15@64006
  1197
    qed auto
lp15@64006
  1198
    have a_BU: "a \<in> ball a d \<inter> U"
lp15@64006
  1199
      using \<open>0 < d\<close> \<open>C \<subseteq> U\<close> \<open>a \<in> C\<close> by auto
lp15@64006
  1200
    have "rel_frontier (cball a d \<inter> U) retract_of (affine hull (cball a d \<inter> U) - {a})"
lp15@64006
  1201
      apply (rule rel_frontier_retract_of_punctured_affine_hull)
lp15@64006
  1202
        apply (auto simp: \<open>convex U\<close> convex_Int)
lp15@64006
  1203
      by (metis \<open>affine U\<close> convex_cball empty_iff interior_cball a_BU rel_interior_convex_Int_affine)
lp15@64006
  1204
    moreover have "rel_frontier (cball a d \<inter> U) = frontier (cball a d) \<inter> U"
lp15@64006
  1205
      apply (rule convex_affine_rel_frontier_Int)
lp15@64006
  1206
      using a_BU by (force simp: \<open>affine U\<close>)+
lp15@64006
  1207
    moreover have "affine hull (cball a d \<inter> U) = U"
lp15@64006
  1208
      by (metis \<open>convex U\<close> a_BU affine_hull_convex_Int_nonempty_interior affine_hull_eq \<open>affine U\<close> equals0D inf.commute interior_cball)
lp15@64006
  1209
    ultimately have "frontier (cball a d) \<inter> U retract_of (U - {a})"
lp15@64006
  1210
      by metis
lp15@64006
  1211
    then obtain r where contr: "continuous_on (U - {a}) r"
lp15@64006
  1212
                    and rim: "r ` (U - {a}) \<subseteq> sphere a d"  "r ` (U - {a}) \<subseteq> U"
lp15@64006
  1213
                    and req: "\<And>x. x \<in> sphere a d \<inter> U \<Longrightarrow> r x = x"
lp15@64006
  1214
      using \<open>affine U\<close> by (auto simp: retract_of_def retraction_def hull_same)
lp15@64006
  1215
    define j where "j \<equiv> \<lambda>x. if x \<in> ball a d then r x else x"
lp15@64006
  1216
    have kj: "\<And>x. x \<in> S \<Longrightarrow> k (j x) = x"
lp15@64006
  1217
      using \<open>C \<subseteq> U - S\<close> \<open>S \<subseteq> U\<close> \<open>ball a d \<inter> U \<subseteq> C\<close> j_def subC by auto
lp15@64006
  1218
    have Uaeq: "U - {a} = (cball a d - {a}) \<inter> U \<union> (U - ball a d)"
lp15@64006
  1219
      using \<open>0 < d\<close> by auto
lp15@64006
  1220
    have jim: "j ` (S \<union> (C - {a})) \<subseteq> (S \<union> C) - ball a d"
lp15@64006
  1221
    proof clarify
lp15@64006
  1222
      fix y  assume "y \<in> S \<union> (C - {a})"
lp15@64006
  1223
      then have "y \<in> U - {a}"
lp15@64006
  1224
        using \<open>C \<subseteq> U - S\<close> \<open>S \<subseteq> U\<close> \<open>a \<in> C\<close> by auto
lp15@64006
  1225
      then have "r y \<in> sphere a d"
lp15@64006
  1226
        using rim by auto
lp15@64006
  1227
      then show "j y \<in> S \<union> C - ball a d"
lp15@64006
  1228
        apply (simp add: j_def)
lp15@64006
  1229
        using \<open>r y \<in> sphere a d\<close> \<open>y \<in> U - {a}\<close> \<open>y \<in> S \<union> (C - {a})\<close> d rim by fastforce
lp15@64006
  1230
    qed
lp15@64006
  1231
    have contj: "continuous_on (U - {a}) j"
lp15@64006
  1232
      unfolding j_def Uaeq
lp15@64006
  1233
    proof (intro continuous_on_cases_local continuous_on_id, simp_all add: req closedin_closed Uaeq [symmetric])
lp15@64006
  1234
      show "\<exists>T. closed T \<and> (cball a d - {a}) \<inter> U = (U - {a}) \<inter> T"
lp15@64006
  1235
          apply (rule_tac x="(cball a d) \<inter> U" in exI)
lp15@64006
  1236
        using affine_closed \<open>affine U\<close> by blast
lp15@64006
  1237
      show "\<exists>T. closed T \<and> U - ball a d = (U - {a}) \<inter> T"
lp15@64006
  1238
         apply (rule_tac x="U - ball a d" in exI)
lp15@64006
  1239
        using \<open>0 < d\<close>  by (force simp: affine_closed \<open>affine U\<close> closed_Diff)
lp15@64006
  1240
      show "continuous_on ((cball a d - {a}) \<inter> U) r"
lp15@64006
  1241
        by (force intro: continuous_on_subset [OF contr])
lp15@64006
  1242
    qed
lp15@64006
  1243
    have fT: "x \<in> U - K \<Longrightarrow> f x \<in> T" for x
lp15@64006
  1244
      using fim by blast
lp15@64006
  1245
    show ?thesis
lp15@64006
  1246
    proof (intro conjI exI)
lp15@64006
  1247
      show "continuous_on (S \<union> (C - {a})) (f \<circ> k \<circ> j)"
lp15@64006
  1248
      proof (intro continuous_on_compose)
lp15@64006
  1249
        show "continuous_on (S \<union> (C - {a})) j"
lp15@64006
  1250
          apply (rule continuous_on_subset [OF contj])
lp15@64006
  1251
          using \<open>C \<subseteq> U - S\<close> \<open>S \<subseteq> U\<close> \<open>a \<in> C\<close> by force
lp15@64006
  1252
        show "continuous_on (j ` (S \<union> (C - {a}))) k"
lp15@64006
  1253
          apply (rule continuous_on_subset [OF homeomorphism_cont2 [OF homhk]])
lp15@64006
  1254
          using jim \<open>C \<subseteq> U - S\<close> \<open>S \<subseteq> U\<close> \<open>ball a d \<inter> U \<subseteq> C\<close> j_def by fastforce
lp15@64006
  1255
        show "continuous_on (k ` j ` (S \<union> (C - {a}))) f"
lp15@64006
  1256
        proof (clarify intro!: continuous_on_subset [OF contf])
lp15@64006
  1257
          fix y  assume "y \<in> S \<union> (C - {a})"
lp15@64006
  1258
          have ky: "k y \<in> S \<union> C"
lp15@64006
  1259
            using homeomorphism_image2 [OF homhk] \<open>y \<in> S \<union> (C - {a})\<close> by blast
lp15@64006
  1260
          have jy: "j y \<in> S \<union> C - ball a d"
lp15@64006
  1261
            using Un_iff \<open>y \<in> S \<union> (C - {a})\<close> jim by auto
lp15@64006
  1262
          show "k (j y) \<in> U - K"
lp15@64006
  1263
            apply safe
lp15@64006
  1264
            using \<open>C \<subseteq> U\<close> \<open>S \<subseteq> U\<close>  homeomorphism_image2 [OF homhk] jy apply blast
lp15@64006
  1265
            by (metis DiffD1 DiffD2 Int_iff Un_iff \<open>disjnt K S\<close> disjnt_def empty_iff hin homeomorphism_apply2 homeomorphism_image2 homhk imageI jy)
lp15@64006
  1266
        qed
lp15@64006
  1267
      qed
lp15@64006
  1268
      have ST: "\<And>x. x \<in> S \<Longrightarrow> (f \<circ> k \<circ> j) x \<in> T"
lp15@64006
  1269
        apply (simp add: kj)
lp15@64006
  1270
        apply (metis DiffI \<open>S \<subseteq> U\<close> \<open>disjnt K S\<close> subsetD disjnt_iff fim image_subset_iff)
lp15@64006
  1271
        done
lp15@64006
  1272
      moreover have "(f \<circ> k \<circ> j) x \<in> T" if "x \<in> C" "x \<noteq> a" "x \<notin> S" for x
lp15@64006
  1273
      proof -
lp15@64006
  1274
        have rx: "r x \<in> sphere a d"
lp15@64006
  1275
          using \<open>C \<subseteq> U\<close> rim that by fastforce
lp15@64006
  1276
        have jj: "j x \<in> S \<union> C - ball a d"
lp15@64006
  1277
          using jim that by blast
lp15@64006
  1278
        have "k (j x) = j x \<longrightarrow> k (j x) \<in> C \<or> j x \<in> C"
lp15@64006
  1279
          by (metis Diff_iff Int_iff Un_iff \<open>S \<subseteq> U\<close> subsetD d j_def jj rx sphere_cball that(1))
lp15@64006
  1280
        then have "k (j x) \<in> C"
lp15@64006
  1281
          using homeomorphism_apply2 [OF homhk, of "j x"]   \<open>C \<subseteq> U\<close> \<open>S \<subseteq> U\<close> a rx
lp15@64006
  1282
          by (metis (mono_tags, lifting) Diff_iff subsetD jj mem_Collect_eq subC)
lp15@64006
  1283
        with jj \<open>C \<subseteq> U\<close> show ?thesis
lp15@64006
  1284
          apply safe
lp15@64006
  1285
          using ST j_def apply fastforce
lp15@64006
  1286
          apply (auto simp: not_less intro!: fT)
lp15@64006
  1287
          by (metis DiffD1 DiffD2 Int_iff hin homeomorphism_apply2 [OF homhk] jj)
lp15@64006
  1288
      qed
lp15@64006
  1289
      ultimately show "(f \<circ> k \<circ> j) ` (S \<union> (C - {a})) \<subseteq> T"
lp15@64006
  1290
        by force
lp15@64006
  1291
      show "\<forall>x\<in>S. (f \<circ> k \<circ> j) x = f x" using kj by simp
lp15@64006
  1292
    qed (auto simp: a)
lp15@64006
  1293
  qed
lp15@64006
  1294
  then obtain a h where
lp15@64006
  1295
    ah: "\<And>C. \<lbrakk>C \<in> components (U - S); C \<inter> K \<noteq> {}\<rbrakk>
lp15@64006
  1296
           \<Longrightarrow> a C \<in> C \<and> a C \<in> L \<and> continuous_on (S \<union> (C - {a C})) (h C) \<and>
lp15@64006
  1297
               h C ` (S \<union> (C - {a C})) \<subseteq> T \<and> (\<forall>x \<in> S. h C x = f x)"
lp15@64006
  1298
    using that by metis
lp15@64006
  1299
  define F where "F \<equiv> {C \<in> components (U - S). C \<inter> K \<noteq> {}}"
lp15@64006
  1300
  define G where "G \<equiv> {C \<in> components (U - S). C \<inter> K = {}}"
lp15@64006
  1301
  define UF where "UF \<equiv> (\<Union>C\<in>F. C - {a C})"
lp15@64006
  1302
  have "C0 \<in> F"
lp15@64006
  1303
    by (auto simp: F_def C0)
lp15@64006
  1304
  have "finite F"
lp15@64006
  1305
  proof (subst finite_image_iff [of "\<lambda>C. C \<inter> K" F, symmetric])
lp15@64006
  1306
    show "inj_on (\<lambda>C. C \<inter> K) F"
lp15@64006
  1307
      unfolding F_def inj_on_def
lp15@64006
  1308
      using components_nonoverlap by blast
lp15@64006
  1309
    show "finite ((\<lambda>C. C \<inter> K) ` F)"
lp15@64006
  1310
      unfolding F_def
lp15@64006
  1311
      by (rule finite_subset [of _ "Pow K"]) (auto simp: \<open>finite K\<close>)
lp15@64006
  1312
  qed
lp15@64006
  1313
  obtain g where contg: "continuous_on (S \<union> UF) g"
lp15@64006
  1314
             and gh: "\<And>x i. \<lbrakk>i \<in> F; x \<in> (S \<union> UF) \<inter> (S \<union> (i - {a i}))\<rbrakk>
lp15@64006
  1315
                            \<Longrightarrow> g x = h i x"
lp15@64006
  1316
  proof (rule pasting_lemma_exists_closed [OF \<open>finite F\<close>, of "S \<union> UF" "\<lambda>C. S \<union> (C - {a C})" h])
lp15@64006
  1317
    show "S \<union> UF \<subseteq> (\<Union>C\<in>F. S \<union> (C - {a C}))"
lp15@64006
  1318
      using \<open>C0 \<in> F\<close> by (force simp: UF_def)
lp15@64006
  1319
    show "closedin (subtopology euclidean (S \<union> UF)) (S \<union> (C - {a C}))"
lp15@64006
  1320
         if "C \<in> F" for C
lp15@64006
  1321
    proof (rule closedin_closed_subset [of U "S \<union> C"])
lp15@64006
  1322
      show "closedin (subtopology euclidean U) (S \<union> C)"
lp15@64006
  1323
        apply (rule closedin_Un_complement_component [OF \<open>locally connected U\<close> clo])
lp15@64006
  1324
        using F_def that by blast
lp15@64006
  1325
    next
lp15@64006
  1326
      have "x = a C'" if "C' \<in> F"  "x \<in> C'" "x \<notin> U" for x C'
lp15@64006
  1327
      proof -
lp15@64006
  1328
        have "\<forall>A. x \<in> \<Union>A \<or> C' \<notin> A"
lp15@64006
  1329
          using \<open>x \<in> C'\<close> by blast
lp15@64006
  1330
        with that show "x = a C'"
lp15@64006
  1331
          by (metis (lifting) DiffD1 F_def Union_components mem_Collect_eq)
lp15@64006
  1332
      qed
lp15@64006
  1333
      then show "S \<union> UF \<subseteq> U"
lp15@64006
  1334
        using \<open>S \<subseteq> U\<close> by (force simp: UF_def)
lp15@64006
  1335
    next
lp15@64006
  1336
      show "S \<union> (C - {a C}) = (S \<union> C) \<inter> (S \<union> UF)"
lp15@64006
  1337
        using F_def UF_def components_nonoverlap that by auto
lp15@64006
  1338
    qed
lp15@64006
  1339
  next
lp15@64006
  1340
    show "continuous_on (S \<union> (C' - {a C'})) (h C')" if "C' \<in> F" for C'
lp15@64006
  1341
      using ah F_def that by blast
lp15@64006
  1342
    show "\<And>i j x. \<lbrakk>i \<in> F; j \<in> F;
lp15@64006
  1343
                   x \<in> (S \<union> UF) \<inter> (S \<union> (i - {a i})) \<inter> (S \<union> (j - {a j}))\<rbrakk>
lp15@64006
  1344
                  \<Longrightarrow> h i x = h j x"
lp15@64006
  1345
      using components_eq by (fastforce simp: components_eq F_def ah)
lp15@64006
  1346
  qed blast
lp15@64006
  1347
  have SU': "S \<union> \<Union>G \<union> (S \<union> UF) \<subseteq> U"
lp15@64006
  1348
    using \<open>S \<subseteq> U\<close> in_components_subset by (auto simp: F_def G_def UF_def)
lp15@64006
  1349
  have clo1: "closedin (subtopology euclidean (S \<union> \<Union>G \<union> (S \<union> UF))) (S \<union> \<Union>G)"
lp15@64006
  1350
  proof (rule closedin_closed_subset [OF _ SU'])
lp15@64006
  1351
    have *: "\<And>C. C \<in> F \<Longrightarrow> openin (subtopology euclidean U) C"
lp15@64006
  1352
      unfolding F_def
lp15@64006
  1353
      by clarify (metis (no_types, lifting) \<open>locally connected U\<close> clo closedin_def locally_diff_closed openin_components_locally_connected openin_trans topspace_euclidean_subtopology)
lp15@64006
  1354
    show "closedin (subtopology euclidean U) (U - UF)"
lp15@64006
  1355
      unfolding UF_def
lp15@64006
  1356
      by (force intro: openin_delete *)
lp15@64006
  1357
    show "S \<union> \<Union>G = (U - UF) \<inter> (S \<union> \<Union>G \<union> (S \<union> UF))"
lp15@64006
  1358
      using \<open>S \<subseteq> U\<close> apply (auto simp: F_def G_def UF_def)
lp15@64006
  1359
        apply (metis Diff_iff UnionI Union_components)
lp15@64006
  1360
       apply (metis DiffD1 UnionI Union_components)
lp15@64006
  1361
      by (metis (no_types, lifting) IntI components_nonoverlap empty_iff)
lp15@64006
  1362
  qed
lp15@64006
  1363
  have clo2: "closedin (subtopology euclidean (S \<union> \<Union>G \<union> (S \<union> UF))) (S \<union> UF)"
lp15@64006
  1364
  proof (rule closedin_closed_subset [OF _ SU'])
lp15@64006
  1365
    show "closedin (subtopology euclidean U) (\<Union>C\<in>F. S \<union> C)"
lp15@64006
  1366
      apply (rule closedin_Union)
lp15@64006
  1367
       apply (simp add: \<open>finite F\<close>)
lp15@64006
  1368
      using F_def \<open>locally connected U\<close> clo closedin_Un_complement_component by blast
lp15@64006
  1369
    show "S \<union> UF = (\<Union>C\<in>F. S \<union> C) \<inter> (S \<union> \<Union>G \<union> (S \<union> UF))"
lp15@64006
  1370
      using \<open>S \<subseteq> U\<close> apply (auto simp: F_def G_def UF_def)
lp15@64006
  1371
      using C0 apply blast
lp15@64006
  1372
      by (metis components_nonoverlap disjnt_def disjnt_iff)
lp15@64006
  1373
  qed
lp15@64006
  1374
  have SUG: "S \<union> \<Union>G \<subseteq> U - K"
lp15@64006
  1375
    using \<open>S \<subseteq> U\<close> K apply (auto simp: G_def disjnt_iff)
lp15@64006
  1376
    by (meson Diff_iff subsetD in_components_subset)
lp15@64006
  1377
  then have contf': "continuous_on (S \<union> \<Union>G) f"
lp15@64006
  1378
    by (rule continuous_on_subset [OF contf])
lp15@64006
  1379
  have contg': "continuous_on (S \<union> UF) g"
lp15@64006
  1380
    apply (rule continuous_on_subset [OF contg])
lp15@64006
  1381
    using \<open>S \<subseteq> U\<close> by (auto simp: F_def G_def)
lp15@64006
  1382
  have  "\<And>x. \<lbrakk>S \<subseteq> U; x \<in> S\<rbrakk> \<Longrightarrow> f x = g x"
lp15@64006
  1383
    by (subst gh) (auto simp: ah C0 intro: \<open>C0 \<in> F\<close>)
lp15@64006
  1384
  then have f_eq_g: "\<And>x. x \<in> S \<union> UF \<and> x \<in> S \<union> \<Union>G \<Longrightarrow> f x = g x"
lp15@64006
  1385
    using \<open>S \<subseteq> U\<close> apply (auto simp: F_def G_def UF_def dest: in_components_subset)
lp15@64006
  1386
    using components_eq by blast
lp15@64006
  1387
  have cont: "continuous_on (S \<union> \<Union>G \<union> (S \<union> UF)) (\<lambda>x. if x \<in> S \<union> \<Union>G then f x else g x)"
lp15@64006
  1388
    by (blast intro: continuous_on_cases_local [OF clo1 clo2 contf' contg' f_eq_g, of "\<lambda>x. x \<in> S \<union> \<Union>G"])
lp15@64006
  1389
  show ?thesis
lp15@64006
  1390
  proof
lp15@64006
  1391
    have UF: "\<Union>F - L \<subseteq> UF"
lp15@64006
  1392
      unfolding F_def UF_def using ah by blast
lp15@64006
  1393
    have "U - S - L = \<Union>(components (U - S)) - L"
lp15@64006
  1394
      by simp
lp15@64006
  1395
    also have "... = \<Union>F \<union> \<Union>G - L"
lp15@64006
  1396
      unfolding F_def G_def by blast
lp15@64006
  1397
    also have "... \<subseteq> UF \<union> \<Union>G"
lp15@64006
  1398
      using UF by blast
lp15@64006
  1399
    finally have "U - L \<subseteq> S \<union> \<Union>G \<union> (S \<union> UF)"
lp15@64006
  1400
      by blast
lp15@64006
  1401
    then show "continuous_on (U - L) (\<lambda>x. if x \<in> S \<union> \<Union>G then f x else g x)"
lp15@64006
  1402
      by (rule continuous_on_subset [OF cont])
lp15@64006
  1403
    have "((U - L) \<inter> {x. x \<notin> S \<and> (\<forall>xa\<in>G. x \<notin> xa)}) \<subseteq>  ((U - L) \<inter> (-S \<inter> UF))"
lp15@64006
  1404
      using \<open>U - L \<subseteq> S \<union> \<Union>G \<union> (S \<union> UF)\<close> by auto
lp15@64006
  1405
    moreover have "g ` ((U - L) \<inter> (-S \<inter> UF)) \<subseteq> T"
lp15@64006
  1406
    proof -
lp15@64006
  1407
      have "g x \<in> T" if "x \<in> U" "x \<notin> L" "x \<notin> S" "C \<in> F" "x \<in> C" "x \<noteq> a C" for x C
lp15@64006
  1408
      proof (subst gh)
lp15@64006
  1409
        show "x \<in> (S \<union> UF) \<inter> (S \<union> (C - {a C}))"
lp15@64006
  1410
          using that by (auto simp: UF_def)
lp15@64006
  1411
        show "h C x \<in> T"
lp15@64006
  1412
          using ah that by (fastforce simp add: F_def)
lp15@64006
  1413
      qed (rule that)
lp15@64006
  1414
      then show ?thesis
lp15@64006
  1415
        by (force simp: UF_def)
lp15@64006
  1416
    qed
lp15@64006
  1417
    ultimately have "g ` ((U - L) \<inter> {x. x \<notin> S \<and> (\<forall>xa\<in>G. x \<notin> xa)}) \<subseteq> T"
lp15@64006
  1418
      using image_mono order_trans by blast
lp15@64006
  1419
    moreover have "f ` ((U - L) \<inter> (S \<union> \<Union>G)) \<subseteq> T"
lp15@64006
  1420
      using fim SUG by blast
lp15@64006
  1421
    ultimately show "(\<lambda>x. if x \<in> S \<union> \<Union>G then f x else g x) ` (U - L) \<subseteq> T"
lp15@64006
  1422
       by force
lp15@64006
  1423
    show "\<And>x. x \<in> S \<Longrightarrow> (if x \<in> S \<union> \<Union>G then f x else g x) = f x"
lp15@64006
  1424
      by (simp add: F_def G_def)
lp15@64006
  1425
  qed
lp15@64006
  1426
qed
lp15@64006
  1427
lp15@64006
  1428
lp15@64006
  1429
lemma extend_map_affine_to_sphere2:
lp15@64006
  1430
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64006
  1431
  assumes "compact S" "convex U" "bounded U" "affine T" "S \<subseteq> T"
lp15@64006
  1432
      and affTU: "aff_dim T \<le> aff_dim U"
lp15@64006
  1433
      and contf: "continuous_on S f"
lp15@64006
  1434
      and fim: "f ` S \<subseteq> rel_frontier U"
lp15@64006
  1435
      and ovlap: "\<And>C. C \<in> components(T - S) \<Longrightarrow> C \<inter> L \<noteq> {}"
lp15@64006
  1436
    obtains K g where "finite K" "K \<subseteq> L" "K \<subseteq> T" "disjnt K S"
lp15@64006
  1437
                      "continuous_on (T - K) g" "g ` (T - K) \<subseteq> rel_frontier U"
lp15@64006
  1438
                      "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1439
proof -
lp15@64006
  1440
  obtain K g where K: "finite K" "K \<subseteq> T" "disjnt K S"
lp15@64006
  1441
               and contg: "continuous_on (T - K) g"
lp15@64006
  1442
               and gim: "g ` (T - K) \<subseteq> rel_frontier U"
lp15@64006
  1443
               and gf: "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1444
     using assms extend_map_affine_to_sphere_cofinite_simple by metis
lp15@64006
  1445
  have "(\<exists>y C. C \<in> components (T - S) \<and> x \<in> C \<and> y \<in> C \<and> y \<in> L)" if "x \<in> K" for x
lp15@64006
  1446
  proof -
lp15@64006
  1447
    have "x \<in> T-S"
lp15@64006
  1448
      using \<open>K \<subseteq> T\<close> \<open>disjnt K S\<close> disjnt_def that by fastforce
lp15@64006
  1449
    then obtain C where "C \<in> components(T - S)" "x \<in> C"
lp15@64006
  1450
      by (metis UnionE Union_components)
lp15@64006
  1451
    with ovlap [of C] show ?thesis
lp15@64006
  1452
      by blast
lp15@64006
  1453
  qed
lp15@64006
  1454
  then obtain \<xi> where \<xi>: "\<And>x. x \<in> K \<Longrightarrow> \<exists>C. C \<in> components (T - S) \<and> x \<in> C \<and> \<xi> x \<in> C \<and> \<xi> x \<in> L"
lp15@64006
  1455
    by metis
lp15@64006
  1456
  obtain h where conth: "continuous_on (T - \<xi> ` K) h"
lp15@64006
  1457
             and him: "h ` (T - \<xi> ` K) \<subseteq> rel_frontier U"
lp15@64006
  1458
             and hg: "\<And>x. x \<in> S \<Longrightarrow> h x = g x"
lp15@64006
  1459
  proof (rule extend_map_affine_to_sphere1 [OF \<open>finite K\<close> \<open>affine T\<close> contg gim, of S "\<xi> ` K"])
lp15@64006
  1460
    show cloTS: "closedin (subtopology euclidean T) S"
lp15@64006
  1461
      by (simp add: \<open>compact S\<close> \<open>S \<subseteq> T\<close> closed_subset compact_imp_closed)
lp15@64006
  1462
    show "\<And>C. \<lbrakk>C \<in> components (T - S); C \<inter> K \<noteq> {}\<rbrakk> \<Longrightarrow> C \<inter> \<xi> ` K \<noteq> {}"
lp15@64006
  1463
      using \<xi> components_eq by blast
lp15@64006
  1464
  qed (use K in auto)
lp15@64006
  1465
  show ?thesis
lp15@64006
  1466
  proof
lp15@64006
  1467
    show *: "\<xi> ` K \<subseteq> L"
lp15@64006
  1468
      using \<xi> by blast
lp15@64006
  1469
    show "finite (\<xi> ` K)"
lp15@64006
  1470
      by (simp add: K)
lp15@64006
  1471
    show "\<xi> ` K \<subseteq> T"
lp15@64006
  1472
      by clarify (meson \<xi> Diff_iff contra_subsetD in_components_subset)
lp15@64006
  1473
    show "continuous_on (T - \<xi> ` K) h"
lp15@64006
  1474
      by (rule conth)
lp15@64006
  1475
    show "disjnt (\<xi> ` K) S"
lp15@64006
  1476
      using K
lp15@64006
  1477
      apply (auto simp: disjnt_def)
lp15@64006
  1478
      by (metis \<xi> DiffD2 UnionI Union_components)
lp15@64006
  1479
  qed (simp_all add: him hg gf)
lp15@64006
  1480
qed
lp15@64006
  1481
lp15@64006
  1482
lp15@64006
  1483
proposition extend_map_affine_to_sphere_cofinite_gen:
lp15@64006
  1484
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64006
  1485
  assumes SUT: "compact S" "convex U" "bounded U" "affine T" "S \<subseteq> T"
lp15@64006
  1486
      and aff: "aff_dim T \<le> aff_dim U"
lp15@64006
  1487
      and contf: "continuous_on S f"
lp15@64006
  1488
      and fim: "f ` S \<subseteq> rel_frontier U"
lp15@64006
  1489
      and dis: "\<And>C. \<lbrakk>C \<in> components(T - S); bounded C\<rbrakk> \<Longrightarrow> C \<inter> L \<noteq> {}"
lp15@64006
  1490
 obtains K g where "finite K" "K \<subseteq> L" "K \<subseteq> T" "disjnt K S" "continuous_on (T - K) g"
lp15@64006
  1491
                   "g ` (T - K) \<subseteq> rel_frontier U"
lp15@64006
  1492
                   "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1493
proof (cases "S = {}")
lp15@64006
  1494
  case True
lp15@64006
  1495
  show ?thesis
lp15@64006
  1496
  proof (cases "rel_frontier U = {}")
lp15@64006
  1497
    case True
lp15@64006
  1498
    with aff have "aff_dim T \<le> 0"
lp15@64006
  1499
      apply (simp add: rel_frontier_eq_empty)
lp15@64006
  1500
      using affine_bounded_eq_lowdim \<open>bounded U\<close> order_trans by auto
lp15@64006
  1501
    with aff_dim_geq [of T] consider "aff_dim T = -1" |  "aff_dim T = 0"
lp15@64006
  1502
      by linarith
lp15@64006
  1503
    then show ?thesis
lp15@64006
  1504
    proof cases
lp15@64006
  1505
      assume "aff_dim T = -1"
lp15@64006
  1506
      then have "T = {}"
lp15@64006
  1507
        by (simp add: aff_dim_empty)
lp15@64006
  1508
      then show ?thesis
lp15@64006
  1509
        by (rule_tac K="{}" in that) auto
lp15@64006
  1510
    next
lp15@64006
  1511
      assume "aff_dim T = 0"
lp15@64006
  1512
      then obtain a where "T = {a}"
lp15@64006
  1513
        using aff_dim_eq_0 by blast
lp15@64006
  1514
      then have "a \<in> L"
lp15@64006
  1515
        using dis [of "{a}"] \<open>S = {}\<close> by (auto simp: in_components_self)
lp15@64006
  1516
      with \<open>S = {}\<close> \<open>T = {a}\<close> show ?thesis
lp15@64006
  1517
        by (rule_tac K="{a}" and g=f in that) auto
lp15@64006
  1518
    qed
lp15@64006
  1519
  next
lp15@64006
  1520
    case False
lp15@64006
  1521
    then obtain y where "y \<in> rel_frontier U"
lp15@64006
  1522
      by auto
lp15@64006
  1523
    with \<open>S = {}\<close> show ?thesis
lp15@64006
  1524
      by (rule_tac K="{}" and g="\<lambda>x. y" in that)  (auto simp: continuous_on_const)
lp15@64006
  1525
  qed
lp15@64006
  1526
next
lp15@64006
  1527
  case False
lp15@64006
  1528
  have "bounded S"
lp15@64006
  1529
    by (simp add: assms compact_imp_bounded)
lp15@64006
  1530
  then obtain b where b: "S \<subseteq> cbox (-b) b"
lp15@64006
  1531
    using bounded_subset_cbox_symmetric by blast
lp15@64006
  1532
  define LU where "LU \<equiv> L \<union> (\<Union> {C \<in> components (T - S). ~bounded C} - cbox (-(b+One)) (b+One))"
lp15@64006
  1533
  obtain K g where "finite K" "K \<subseteq> LU" "K \<subseteq> T" "disjnt K S"
lp15@64006
  1534
               and contg: "continuous_on (T - K) g"
lp15@64006
  1535
               and gim: "g ` (T - K) \<subseteq> rel_frontier U"
lp15@64006
  1536
               and gf:  "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1537
  proof (rule extend_map_affine_to_sphere2 [OF SUT aff contf fim])
lp15@64006
  1538
    show "C \<inter> LU \<noteq> {}" if "C \<in> components (T - S)" for C
lp15@64006
  1539
    proof (cases "bounded C")
lp15@64006
  1540
      case True
lp15@64006
  1541
      with dis that show ?thesis
lp15@64006
  1542
        unfolding LU_def by fastforce
lp15@64006
  1543
    next
lp15@64006
  1544
      case False
lp15@64006
  1545
      then have "\<not> bounded (\<Union>{C \<in> components (T - S). \<not> bounded C})"
lp15@64006
  1546
        by (metis (no_types, lifting) Sup_upper bounded_subset mem_Collect_eq that)
lp15@64006
  1547
      then show ?thesis
lp15@64006
  1548
        apply (clarsimp simp: LU_def Int_Un_distrib Diff_Int_distrib Int_UN_distrib)
lp15@64006
  1549
        by (metis (no_types, lifting) False Sup_upper bounded_cbox bounded_subset inf.orderE mem_Collect_eq that)
lp15@64006
  1550
    qed
lp15@64006
  1551
  qed blast
lp15@64006
  1552
  have *: False if "x \<in> cbox (- b - m *\<^sub>R One) (b + m *\<^sub>R One)"
lp15@64006
  1553
                   "x \<notin> box (- b - n *\<^sub>R One) (b + n *\<^sub>R One)"
lp15@64006
  1554
                   "0 \<le> m" "m < n" "n \<le> 1" for m n x
lp15@64006
  1555
    using that by (auto simp: mem_box algebra_simps)
lp15@64006
  1556
  have "disjoint_family_on (\<lambda>d. frontier (cbox (- b - d *\<^sub>R One) (b + d *\<^sub>R One))) {1 / 2..1}"
lp15@64006
  1557
    by (auto simp: disjoint_family_on_def neq_iff frontier_def dest: *)
lp15@64006
  1558
  then obtain d where d12: "1/2 \<le> d" "d \<le> 1"
lp15@64006
  1559
                  and ddis: "disjnt K (frontier (cbox (-(b + d *\<^sub>R One)) (b + d *\<^sub>R One)))"
lp15@64006
  1560
    using disjoint_family_elem_disjnt [of "{1/2..1::real}" K "\<lambda>d. frontier (cbox (-(b + d *\<^sub>R One)) (b + d *\<^sub>R One))"]
lp15@64006
  1561
    by (auto simp: \<open>finite K\<close>)
lp15@64006
  1562
  define c where "c \<equiv> b + d *\<^sub>R One"
lp15@64006
  1563
  have cbsub: "cbox (-b) b \<subseteq> box (-c) c"
lp15@64006
  1564
              "cbox (-b) b \<subseteq> cbox (-c) c"
lp15@64006
  1565
              "cbox (-c) c \<subseteq> cbox (-(b+One)) (b+One)"
lp15@64006
  1566
    using d12 by (simp_all add: subset_box c_def inner_diff_left inner_left_distrib)
lp15@64006
  1567
  have clo_cT: "closed (cbox (- c) c \<inter> T)"
lp15@64006
  1568
    using affine_closed \<open>affine T\<close> by blast
lp15@64006
  1569
  have cT_ne: "cbox (- c) c \<inter> T \<noteq> {}"
lp15@64006
  1570
    using \<open>S \<noteq> {}\<close> \<open>S \<subseteq> T\<close> b cbsub by fastforce
lp15@64006
  1571
  have S_sub_cc: "S \<subseteq> cbox (- c) c"
lp15@64006
  1572
    using \<open>cbox (- b) b \<subseteq> cbox (- c) c\<close> b by auto
lp15@64006
  1573
  show ?thesis
lp15@64006
  1574
  proof
lp15@64006
  1575
    show "finite (K \<inter> cbox (-(b+One)) (b+One))"
lp15@64006
  1576
      using \<open>finite K\<close> by blast
lp15@64006
  1577
    show "K \<inter> cbox (- (b + One)) (b + One) \<subseteq> L"
lp15@64006
  1578
      using \<open>K \<subseteq> LU\<close> by (auto simp: LU_def)
lp15@64006
  1579
    show "K \<inter> cbox (- (b + One)) (b + One) \<subseteq> T"
lp15@64006
  1580
      using \<open>K \<subseteq> T\<close> by auto
lp15@64006
  1581
    show "disjnt (K \<inter> cbox (- (b + One)) (b + One)) S"
lp15@64006
  1582
      using \<open>disjnt K S\<close>  by (simp add: disjnt_def disjoint_eq_subset_Compl inf.coboundedI1)
lp15@64006
  1583
    have cloTK: "closest_point (cbox (- c) c \<inter> T) x \<in> T - K"
lp15@64006
  1584
                if "x \<in> T" and Knot: "x \<in> K \<longrightarrow> x \<notin> cbox (- b - One) (b + One)" for x
lp15@64006
  1585
    proof (cases "x \<in> cbox (- c) c")
lp15@64006
  1586
      case True
lp15@64006
  1587
      with \<open>x \<in> T\<close> show ?thesis
lp15@64006
  1588
        using cbsub(3) Knot  by (force simp: closest_point_self)
lp15@64006
  1589
    next
lp15@64006
  1590
      case False
lp15@64006
  1591
      have clo_in_rf: "closest_point (cbox (- c) c \<inter> T) x \<in> rel_frontier (cbox (- c) c \<inter> T)"
lp15@64006
  1592
      proof (intro closest_point_in_rel_frontier [OF clo_cT cT_ne] DiffI notI)
lp15@64006
  1593
        have "T \<inter> interior (cbox (- c) c) \<noteq> {}"
lp15@64006
  1594
          using \<open>S \<noteq> {}\<close> \<open>S \<subseteq> T\<close> b cbsub(1) by fastforce
lp15@64006
  1595
        then show "x \<in> affine hull (cbox (- c) c \<inter> T)"
lp15@64006
  1596
          by (simp add: Int_commute affine_hull_affine_Int_nonempty_interior \<open>affine T\<close> hull_inc that(1))
lp15@64006
  1597
      next
lp15@64006
  1598
        show "False" if "x \<in> rel_interior (cbox (- c) c \<inter> T)"
lp15@64006
  1599
        proof -
lp15@64006
  1600
          have "interior (cbox (- c) c) \<inter> T \<noteq> {}"
lp15@64006
  1601
            using \<open>S \<noteq> {}\<close> \<open>S \<subseteq> T\<close> b cbsub(1) by fastforce
lp15@64006
  1602
          then have "affine hull (T \<inter> cbox (- c) c) = T"
lp15@64006
  1603
            using affine_hull_convex_Int_nonempty_interior [of T "cbox (- c) c"]
lp15@64006
  1604
            by (simp add: affine_imp_convex \<open>affine T\<close> inf_commute)
lp15@64006
  1605
          then show ?thesis
lp15@64006
  1606
            by (meson subsetD le_inf_iff rel_interior_subset that False)
lp15@64006
  1607
        qed
lp15@64006
  1608
      qed
lp15@64006
  1609
      have "closest_point (cbox (- c) c \<inter> T) x \<notin> K"
lp15@64006
  1610
      proof
lp15@64006
  1611
        assume inK: "closest_point (cbox (- c) c \<inter> T) x \<in> K"
lp15@64006
  1612
        have "\<And>x. x \<in> K \<Longrightarrow> x \<notin> frontier (cbox (- (b + d *\<^sub>R One)) (b + d *\<^sub>R One))"
lp15@64006
  1613
          by (metis ddis disjnt_iff)
lp15@64006
  1614
        then show False
lp15@64006
  1615
          by (metis DiffI Int_iff \<open>affine T\<close> cT_ne c_def clo_cT clo_in_rf closest_point_in_set
lp15@64006
  1616
                    convex_affine_rel_frontier_Int convex_box(1) empty_iff frontier_cbox inK interior_cbox)
lp15@64006
  1617
      qed
lp15@64006
  1618
      then show ?thesis
lp15@64006
  1619
        using cT_ne clo_cT closest_point_in_set by blast
lp15@64006
  1620
    qed
lp15@64006
  1621
    show "continuous_on (T - K \<inter> cbox (- (b + One)) (b + One)) (g \<circ> closest_point (cbox (-c) c \<inter> T))"
lp15@64006
  1622
      apply (intro continuous_on_compose continuous_on_closest_point continuous_on_subset [OF contg])
lp15@64006
  1623
         apply (simp_all add: clo_cT affine_imp_convex \<open>affine T\<close> convex_Int cT_ne)
lp15@64006
  1624
      using cloTK by blast
lp15@64006
  1625
    have "g (closest_point (cbox (- c) c \<inter> T) x) \<in> rel_frontier U"
lp15@64006
  1626
         if "x \<in> T" "x \<in> K \<longrightarrow> x \<notin> cbox (- b - One) (b + One)" for x
lp15@64006
  1627
      apply (rule gim [THEN subsetD])
lp15@64006
  1628
      using that cloTK by blast
lp15@64006
  1629
    then show "(g \<circ> closest_point (cbox (- c) c \<inter> T)) ` (T - K \<inter> cbox (- (b + One)) (b + One))
lp15@64006
  1630
               \<subseteq> rel_frontier U"
lp15@64006
  1631
      by force
lp15@64006
  1632
    show "\<And>x. x \<in> S \<Longrightarrow> (g \<circ> closest_point (cbox (- c) c \<inter> T)) x = f x"
lp15@64006
  1633
      by simp (metis (mono_tags, lifting) IntI \<open>S \<subseteq> T\<close> cT_ne clo_cT closest_point_refl gf subsetD S_sub_cc)
lp15@64006
  1634
  qed
lp15@64006
  1635
qed
lp15@64006
  1636
lp15@64006
  1637
lp15@64006
  1638
corollary extend_map_affine_to_sphere_cofinite:
lp15@64006
  1639
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64006
  1640
  assumes SUT: "compact S" "affine T" "S \<subseteq> T"
lp15@64006
  1641
      and aff: "aff_dim T \<le> DIM('b)" and "0 \<le> r"
lp15@64006
  1642
      and contf: "continuous_on S f"
lp15@64006
  1643
      and fim: "f ` S \<subseteq> sphere a r"
lp15@64006
  1644
      and dis: "\<And>C. \<lbrakk>C \<in> components(T - S); bounded C\<rbrakk> \<Longrightarrow> C \<inter> L \<noteq> {}"
lp15@64006
  1645
  obtains K g where "finite K" "K \<subseteq> L" "K \<subseteq> T" "disjnt K S" "continuous_on (T - K) g"
lp15@64006
  1646
                    "g ` (T - K) \<subseteq> sphere a r" "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1647
proof (cases "r = 0")
lp15@64006
  1648
  case True
lp15@64006
  1649
  with fim show ?thesis
lp15@64006
  1650
    by (rule_tac K="{}" and g = "\<lambda>x. a" in that) (auto simp: continuous_on_const)
lp15@64006
  1651
next
lp15@64006
  1652
  case False
lp15@64006
  1653
  with assms have "0 < r" by auto
lp15@64006
  1654
  then have "aff_dim T \<le> aff_dim (cball a r)"
lp15@64006
  1655
    by (simp add: aff aff_dim_cball)
lp15@64006
  1656
  then show ?thesis
lp15@64006
  1657
    apply (rule extend_map_affine_to_sphere_cofinite_gen
lp15@64006
  1658
            [OF \<open>compact S\<close> convex_cball bounded_cball \<open>affine T\<close> \<open>S \<subseteq> T\<close> _ contf])
lp15@64006
  1659
    using fim apply (auto simp: assms False that dest: dis)
lp15@64006
  1660
    done
lp15@64006
  1661
qed
lp15@64006
  1662
lp15@64006
  1663
corollary extend_map_UNIV_to_sphere_cofinite:
lp15@64006
  1664
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64006
  1665
  assumes aff: "DIM('a) \<le> DIM('b)" and "0 \<le> r"
lp15@64006
  1666
      and SUT: "compact S"
lp15@64006
  1667
      and contf: "continuous_on S f"
lp15@64006
  1668
      and fim: "f ` S \<subseteq> sphere a r"
lp15@64006
  1669
      and dis: "\<And>C. \<lbrakk>C \<in> components(- S); bounded C\<rbrakk> \<Longrightarrow> C \<inter> L \<noteq> {}"
lp15@64006
  1670
  obtains K g where "finite K" "K \<subseteq> L" "disjnt K S" "continuous_on (- K) g"
lp15@64006
  1671
                    "g ` (- K) \<subseteq> sphere a r" "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1672
apply (rule extend_map_affine_to_sphere_cofinite
lp15@64006
  1673
        [OF \<open>compact S\<close> affine_UNIV subset_UNIV _ \<open>0 \<le> r\<close> contf fim dis])
lp15@64006
  1674
 apply (auto simp: assms that Compl_eq_Diff_UNIV [symmetric])
lp15@64006
  1675
done
lp15@64006
  1676
lp15@64006
  1677
corollary extend_map_UNIV_to_sphere_no_bounded_component:
lp15@64006
  1678
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64006
  1679
  assumes aff: "DIM('a) \<le> DIM('b)" and "0 \<le> r"
lp15@64006
  1680
      and SUT: "compact S"
lp15@64006
  1681
      and contf: "continuous_on S f"
lp15@64006
  1682
      and fim: "f ` S \<subseteq> sphere a r"
lp15@64006
  1683
      and dis: "\<And>C. C \<in> components(- S) \<Longrightarrow> \<not> bounded C"
lp15@64006
  1684
  obtains g where "continuous_on UNIV g" "g ` UNIV \<subseteq> sphere a r" "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1685
apply (rule extend_map_UNIV_to_sphere_cofinite [OF aff \<open>0 \<le> r\<close> \<open>compact S\<close> contf fim, of "{}"])
lp15@64006
  1686
   apply (auto simp: that dest: dis)
lp15@64006
  1687
done
lp15@64006
  1688
lp15@64006
  1689
theorem Borsuk_separation_theorem_gen:
lp15@64006
  1690
  fixes S :: "'a::euclidean_space set"
lp15@64006
  1691
  assumes "compact S"
lp15@64006
  1692
    shows "(\<forall>c \<in> components(- S). ~bounded c) \<longleftrightarrow>
lp15@64006
  1693
           (\<forall>f. continuous_on S f \<and> f ` S \<subseteq> sphere (0::'a) 1
lp15@64006
  1694
                \<longrightarrow> (\<exists>c. homotopic_with (\<lambda>x. True) S (sphere 0 1) f (\<lambda>x. c)))"
lp15@64006
  1695
       (is "?lhs = ?rhs")
lp15@64006
  1696
proof
lp15@64006
  1697
  assume L [rule_format]: ?lhs
lp15@64006
  1698
  show ?rhs
lp15@64006
  1699
  proof clarify
lp15@64006
  1700
    fix f :: "'a \<Rightarrow> 'a"
lp15@64006
  1701
    assume contf: "continuous_on S f" and fim: "f ` S \<subseteq> sphere 0 1"
lp15@64006
  1702
    obtain g where contg: "continuous_on UNIV g" and gim: "range g \<subseteq> sphere 0 1"
lp15@64006
  1703
               and gf: "\<And>x. x \<in> S \<Longrightarrow> g x = f x"
lp15@64006
  1704
      by (rule extend_map_UNIV_to_sphere_no_bounded_component [OF _ _ \<open>compact S\<close> contf fim L]) auto
lp15@64006
  1705
    then show "\<exists>c. homotopic_with (\<lambda>x. True) S (sphere 0 1) f (\<lambda>x. c)"
lp15@64006
  1706
      using nullhomotopic_from_contractible [OF contg gim]
lp15@64006
  1707
      by (metis assms compact_imp_closed contf empty_iff fim homotopic_with_equal nullhomotopic_into_sphere_extension)
lp15@64006
  1708
  qed
lp15@64006
  1709
next
lp15@64006
  1710
  assume R [rule_format]: ?rhs
lp15@64006
  1711
  show ?lhs
lp15@64006
  1712
    unfolding components_def
lp15@64006
  1713
  proof clarify
lp15@64006
  1714
    fix a
lp15@64006
  1715
    assume "a \<notin> S" and a: "bounded (connected_component_set (- S) a)"
lp15@64006
  1716
    have cont: "continuous_on S (\<lambda>x. inverse(norm(x - a)) *\<^sub>R (x - a))"
lp15@64006
  1717
      apply (intro continuous_intros)
lp15@64006
  1718
      using \<open>a \<notin> S\<close> by auto
lp15@64006
  1719
    have im: "(\<lambda>x. inverse(norm(x - a)) *\<^sub>R (x - a)) ` S \<subseteq> sphere 0 1"
lp15@64006
  1720
      by clarsimp (metis \<open>a \<notin> S\<close> eq_iff_diff_eq_0 left_inverse norm_eq_zero)
lp15@64006
  1721
    show False
lp15@64006
  1722
      using R cont im Borsuk_map_essential_bounded_component [OF \<open>compact S\<close> \<open>a \<notin> S\<close>] a by blast
lp15@64006
  1723
  qed
lp15@64006
  1724
qed
lp15@64006
  1725
lp15@64006
  1726
lp15@64006
  1727
corollary Borsuk_separation_theorem:
lp15@64006
  1728
  fixes S :: "'a::euclidean_space set"
lp15@64006
  1729
  assumes "compact S" and 2: "2 \<le> DIM('a)"
lp15@64006
  1730
    shows "connected(- S) \<longleftrightarrow>
lp15@64006
  1731
           (\<forall>f. continuous_on S f \<and> f ` S \<subseteq> sphere (0::'a) 1
lp15@64006
  1732
                \<longrightarrow> (\<exists>c. homotopic_with (\<lambda>x. True) S (sphere 0 1) f (\<lambda>x. c)))"
lp15@64006
  1733
       (is "?lhs = ?rhs")
lp15@64006
  1734
proof
lp15@64006
  1735
  assume L: ?lhs
lp15@64006
  1736
  show ?rhs
lp15@64006
  1737
  proof (cases "S = {}")
lp15@64006
  1738
    case True
lp15@64006
  1739
    then show ?thesis by auto
lp15@64006
  1740
  next
lp15@64006
  1741
    case False
lp15@64006
  1742
    then have "(\<forall>c\<in>components (- S). \<not> bounded c)"
lp15@64006
  1743
      by (metis L assms(1) bounded_empty cobounded_imp_unbounded compact_imp_bounded in_components_maximal order_refl)
lp15@64006
  1744
    then show ?thesis
lp15@64006
  1745
      by (simp add: Borsuk_separation_theorem_gen [OF \<open>compact S\<close>])
lp15@64006
  1746
  qed
lp15@64006
  1747
next
lp15@64006
  1748
  assume R: ?rhs
lp15@64006
  1749
  then show ?lhs
lp15@64006
  1750
    apply (simp add: Borsuk_separation_theorem_gen [OF \<open>compact S\<close>, symmetric])
lp15@64006
  1751
    apply (auto simp: components_def connected_iff_eq_connected_component_set)
lp15@64006
  1752
    using connected_component_in apply fastforce
lp15@64006
  1753
    using cobounded_unique_unbounded_component [OF _ 2, of "-S"] \<open>compact S\<close> compact_eq_bounded_closed by fastforce
lp15@64006
  1754
qed
lp15@64006
  1755
lp15@64006
  1756
lp15@64006
  1757
lemma homotopy_eqv_separation:
lp15@64006
  1758
  fixes S :: "'a::euclidean_space set" and T :: "'a set"
lp15@64006
  1759
  assumes "S homotopy_eqv T" and "compact S" and "compact T"
lp15@64006
  1760
  shows "connected(- S) \<longleftrightarrow> connected(- T)"
lp15@64006
  1761
proof -
lp15@64006
  1762
  consider "DIM('a) = 1" | "2 \<le> DIM('a)"
lp15@64006
  1763
    by (metis DIM_ge_Suc0 One_nat_def Suc_1 dual_order.antisym not_less_eq_eq)
lp15@64006
  1764
  then show ?thesis
lp15@64006
  1765
  proof cases
lp15@64006
  1766
    case 1
lp15@64006
  1767
    then show ?thesis
lp15@64006
  1768
      using bounded_connected_Compl_1 compact_imp_bounded homotopy_eqv_empty1 homotopy_eqv_empty2 assms by metis
lp15@64006
  1769
  next
lp15@64006
  1770
    case 2
lp15@64006
  1771
    with assms show ?thesis
lp15@64006
  1772
      by (simp add: Borsuk_separation_theorem homotopy_eqv_cohomotopic_triviality_null)
lp15@64006
  1773
  qed
lp15@64006
  1774
qed
lp15@64006
  1775
lp15@64006
  1776
lemma Jordan_Brouwer_separation:
lp15@64006
  1777
  fixes S :: "'a::euclidean_space set" and a::'a
lp15@64006
  1778
  assumes hom: "S homeomorphic sphere a r" and "0 < r"
lp15@64006
  1779
    shows "\<not> connected(- S)"
lp15@64006
  1780
proof -
lp15@64006
  1781
  have "- sphere a r \<inter> ball a r \<noteq> {}"
lp15@64006
  1782
    using \<open>0 < r\<close> by (simp add: Int_absorb1 subset_eq)
lp15@64006
  1783
  moreover
lp15@64006
  1784
  have eq: "- sphere a r - ball a r = - cball a r"
lp15@64006
  1785
    by auto
lp15@64006
  1786
  have "- cball a r \<noteq> {}"
lp15@64006
  1787
  proof -
lp15@64006
  1788
    have "frontier (cball a r) \<noteq> {}"
lp15@64006
  1789
      using \<open>0 < r\<close> by auto
lp15@64006
  1790
    then show ?thesis
lp15@64006
  1791
      by (metis frontier_complement frontier_empty)
lp15@64006
  1792
  qed
lp15@64006
  1793
  with eq have "- sphere a r - ball a r \<noteq> {}"
lp15@64006
  1794
    by auto
lp15@64006
  1795
  moreover
lp15@64006
  1796
  have "connected (- S) = connected (- sphere a r)"
lp15@64006
  1797
  proof (rule homotopy_eqv_separation)
lp15@64006
  1798
    show "S homotopy_eqv sphere a r"
lp15@64006
  1799
      using hom homeomorphic_imp_homotopy_eqv by blast
lp15@64006
  1800
    show "compact (sphere a r)"
lp15@64006
  1801
      by simp
lp15@64006
  1802
    then show " compact S"
lp15@64006
  1803
      using hom homeomorphic_compactness by blast
lp15@64006
  1804
  qed
lp15@64006
  1805
  ultimately show ?thesis
lp15@64006
  1806
    using connected_Int_frontier [of "- sphere a r" "ball a r"] by (auto simp: \<open>0 < r\<close>)
lp15@64006
  1807
qed
lp15@64006
  1808
lp15@64006
  1809
lp15@64006
  1810
lemma Jordan_Brouwer_frontier:
lp15@64006
  1811
  fixes S :: "'a::euclidean_space set" and a::'a
lp15@64006
  1812
  assumes S: "S homeomorphic sphere a r" and T: "T \<in> components(- S)" and 2: "2 \<le> DIM('a)"
lp15@64006
  1813
    shows "frontier T = S"
lp15@64006
  1814
proof (cases r rule: linorder_cases)
lp15@64006
  1815
  assume "r < 0"
lp15@64006
  1816
  with S T show ?thesis by auto
lp15@64006
  1817
next
lp15@64006
  1818
  assume "r = 0"
lp15@64006
  1819
  with S T card_eq_SucD obtain b where "S = {b}"
lp15@64006
  1820
    by (auto simp: homeomorphic_finite [of "{a}" S])
lp15@64006
  1821
  have "components (- {b}) = { -{b}}"
lp15@64006
  1822
    using T \<open>S = {b}\<close> by (auto simp: components_eq_sing_iff connected_punctured_universe 2)
lp15@64006
  1823
  with T show ?thesis
lp15@64006
  1824
    by (metis \<open>S = {b}\<close> cball_trivial frontier_cball frontier_complement singletonD sphere_trivial)
lp15@64006
  1825
next
lp15@64006
  1826
  assume "r > 0"
lp15@64006
  1827
  have "compact S"
lp15@64006
  1828
    using homeomorphic_compactness compact_sphere S by blast
lp15@64006
  1829
  show ?thesis
lp15@64006
  1830
  proof (rule frontier_minimal_separating_closed)
lp15@64006
  1831
    show "closed S"
lp15@64006
  1832
      using \<open>compact S\<close> compact_eq_bounded_closed by blast
lp15@64006
  1833
    show "\<not> connected (- S)"
lp15@64006
  1834
      using Jordan_Brouwer_separation S \<open>0 < r\<close> by blast
lp15@64006
  1835
    obtain f g where hom: "homeomorphism S (sphere a r) f g"
lp15@64006
  1836
      using S by (auto simp: homeomorphic_def)
lp15@64006
  1837
    show "connected (- T)" if "closed T" "T \<subset> S" for T
lp15@64006
  1838
    proof -
lp15@64006
  1839
      have "f ` T \<subseteq> sphere a r"
lp15@64006
  1840
        using \<open>T \<subset> S\<close> hom homeomorphism_image1 by blast
lp15@64006
  1841
      moreover have "f ` T \<noteq> sphere a r"
lp15@64006
  1842
        using \<open>T \<subset> S\<close> hom
lp15@64006
  1843
        by (metis homeomorphism_image2 homeomorphism_of_subsets order_refl psubsetE)
lp15@64006
  1844
      ultimately have "f ` T \<subset> sphere a r" by blast
lp15@64006
  1845
      then have "connected (- f ` T)"
lp15@64006
  1846
        by (rule psubset_sphere_Compl_connected [OF _ \<open>0 < r\<close> 2])
lp15@64006
  1847
      moreover have "compact T"
lp15@64006
  1848
        using \<open>compact S\<close> bounded_subset compact_eq_bounded_closed that by blast
lp15@64006
  1849
      moreover then have "compact (f ` T)"
lp15@64006
  1850
        by (meson compact_continuous_image continuous_on_subset hom homeomorphism_def psubsetE \<open>T \<subset> S\<close>)
lp15@64006
  1851
      moreover have "T homotopy_eqv f ` T"
lp15@64006
  1852
        by (meson \<open>f ` T \<subseteq> sphere a r\<close> dual_order.strict_implies_order hom homeomorphic_def homeomorphic_imp_homotopy_eqv homeomorphism_of_subsets \<open>T \<subset> S\<close>)
lp15@64006
  1853
      ultimately show ?thesis
lp15@64006
  1854
        using homotopy_eqv_separation [of T "f`T"] by blast
lp15@64006
  1855
    qed
lp15@64006
  1856
  qed (rule T)
lp15@64006
  1857
qed
lp15@64006
  1858
lp15@64006
  1859
lemma Jordan_Brouwer_nonseparation:
lp15@64006
  1860
  fixes S :: "'a::euclidean_space set" and a::'a
lp15@64006
  1861
  assumes S: "S homeomorphic sphere a r" and "T \<subset> S" and 2: "2 \<le> DIM('a)"
lp15@64006
  1862
    shows "connected(- T)"
lp15@64006
  1863
proof -
lp15@64006
  1864
  have *: "connected(C \<union> (S - T))" if "C \<in> components(- S)" for C
lp15@64006
  1865
  proof (rule connected_intermediate_closure)
lp15@64006
  1866
    show "connected C"
lp15@64006
  1867
      using in_components_connected that by auto
lp15@64006
  1868
    have "S = frontier C"
lp15@64006
  1869
      using "2" Jordan_Brouwer_frontier S that by blast
lp15@64006
  1870
    with closure_subset show "C \<union> (S - T) \<subseteq> closure C"
lp15@64006
  1871
      by (auto simp: frontier_def)
lp15@64006
  1872
  qed auto
lp15@64006
  1873
  have "components(- S) \<noteq> {}"
lp15@64006
  1874
    by (metis S bounded_empty cobounded_imp_unbounded compact_eq_bounded_closed compact_sphere
lp15@64006
  1875
              components_eq_empty homeomorphic_compactness)
lp15@64006
  1876
  then have "- T = (\<Union>C \<in> components(- S). C \<union> (S - T))"
lp15@64006
  1877
    using Union_components [of "-S"] \<open>T \<subset> S\<close> by auto
lp15@64006
  1878
  then show ?thesis
lp15@64006
  1879
    apply (rule ssubst)
lp15@64006
  1880
    apply (rule connected_Union)
lp15@64006
  1881
    using \<open>T \<subset> S\<close> apply (auto simp: *)
lp15@64006
  1882
    done
lp15@64006
  1883
qed
lp15@64006
  1884
lp15@64122
  1885
subsection\<open> Invariance of domain and corollaries\<close>
lp15@64122
  1886
lp15@64122
  1887
lemma invariance_of_domain_ball:
lp15@64122
  1888
  fixes f :: "'a \<Rightarrow> 'a::euclidean_space"
lp15@64122
  1889
  assumes contf: "continuous_on (cball a r) f" and "0 < r"
lp15@64122
  1890
     and inj: "inj_on f (cball a r)"
lp15@64122
  1891
   shows "open(f ` ball a r)"
lp15@64122
  1892
proof (cases "DIM('a) = 1")
lp15@64122
  1893
  case True
lp15@64122
  1894
  obtain h::"'a\<Rightarrow>real" and k
lp15@64122
  1895
        where "linear h" "linear k" "h ` UNIV = UNIV" "k ` UNIV = UNIV"
lp15@64122
  1896
              "\<And>x. norm(h x) = norm x" "\<And>x. norm(k x) = norm x"
lp15@64122
  1897
              "\<And>x. k(h x) = x" "\<And>x. h(k x) = x"
lp15@64122
  1898
    apply (rule isomorphisms_UNIV_UNIV [where 'M='a and 'N=real])
lp15@64122
  1899
      using True
lp15@64122
  1900
       apply force
lp15@64122
  1901
      by (metis UNIV_I UNIV_eq_I imageI)
lp15@64122
  1902
    have cont: "continuous_on S h"  "continuous_on T k" for S T
lp15@64122
  1903
      by (simp_all add: \<open>linear h\<close> \<open>linear k\<close> linear_continuous_on linear_linear)
lp15@64122
  1904
    have "continuous_on (h ` cball a r) (h \<circ> f \<circ> k)"
lp15@64122
  1905
      apply (intro continuous_on_compose cont continuous_on_subset [OF contf])
lp15@64122
  1906
      apply (auto simp: \<open>\<And>x. k (h x) = x\<close>)
lp15@64122
  1907
      done
lp15@64122
  1908
    moreover have "is_interval (h ` cball a r)"
lp15@64122
  1909
      by (simp add: is_interval_connected_1 \<open>linear h\<close> linear_continuous_on linear_linear connected_continuous_image)
lp15@64122
  1910
    moreover have "inj_on (h \<circ> f \<circ> k) (h ` cball a r)"
lp15@64122
  1911
      using inj by (simp add: inj_on_def) (metis \<open>\<And>x. k (h x) = x\<close>)
lp15@64122
  1912
    ultimately have *: "\<And>T. \<lbrakk>open T; T \<subseteq> h ` cball a r\<rbrakk> \<Longrightarrow> open ((h \<circ> f \<circ> k) ` T)"
lp15@64122
  1913
      using injective_eq_1d_open_map_UNIV by blast
lp15@64122
  1914
    have "open ((h \<circ> f \<circ> k) ` (h ` ball a r))"
lp15@64122
  1915
      by (rule *) (auto simp: \<open>linear h\<close> \<open>range h = UNIV\<close> open_surjective_linear_image)
lp15@64122
  1916
    then have "open ((h \<circ> f) ` ball a r)"
lp15@64122
  1917
      by (simp add: image_comp \<open>\<And>x. k (h x) = x\<close> cong: image_cong)
lp15@64122
  1918
    then show ?thesis
lp15@64122
  1919
      apply (simp add: image_comp [symmetric])
lp15@64122
  1920
      apply (metis open_bijective_linear_image_eq \<open>linear h\<close> \<open>\<And>x. k (h x) = x\<close> \<open>range h = UNIV\<close> bijI inj_on_def)
lp15@64122
  1921
      done
lp15@64122
  1922
next
lp15@64122
  1923
  case False
lp15@64122
  1924
  then have 2: "DIM('a) \<ge> 2"
lp15@64122
  1925
    by (metis DIM_ge_Suc0 One_nat_def Suc_1 antisym not_less_eq_eq)
lp15@64122
  1926
  have fimsub: "f ` ball a r \<subseteq> - f ` sphere a r"
lp15@64122
  1927
    using inj  by clarsimp (metis inj_onD less_eq_real_def mem_cball order_less_irrefl)
lp15@64122
  1928
  have hom: "f ` sphere a r homeomorphic sphere a r"
lp15@64122
  1929
    by (meson compact_sphere contf continuous_on_subset homeomorphic_compact homeomorphic_sym inj inj_on_subset sphere_cball)
lp15@64122
  1930
  then have nconn: "\<not> connected (- f ` sphere a r)"
lp15@64122
  1931
    by (rule Jordan_Brouwer_separation) (auto simp: \<open>0 < r\<close>)
lp15@64122
  1932
  obtain C where C: "C \<in> components (- f ` sphere a r)" and "bounded C"
lp15@64122
  1933
    apply (rule cobounded_has_bounded_component [OF _ nconn])
lp15@64122
  1934
      apply (simp_all add: 2)
lp15@64122
  1935
    by (meson compact_imp_bounded compact_continuous_image_eq compact_sphere contf inj sphere_cball)
lp15@64122
  1936
  moreover have "f ` (ball a r) = C"
lp15@64122
  1937
  proof
lp15@64122
  1938
    have "C \<noteq> {}"
lp15@64122
  1939
      by (rule in_components_nonempty [OF C])
lp15@64122
  1940
    show "C \<subseteq> f ` ball a r"
lp15@64122
  1941
    proof (rule ccontr)
lp15@64122
  1942
      assume nonsub: "\<not> C \<subseteq> f ` ball a r"
lp15@64122
  1943
      have "- f ` cball a r \<subseteq> C"
lp15@64122
  1944
      proof (rule components_maximal [OF C])
lp15@64122
  1945
        have "f ` cball a r homeomorphic cball a r"
lp15@64122
  1946
          using compact_cball contf homeomorphic_compact homeomorphic_sym inj by blast
lp15@64122
  1947
        then show "connected (- f ` cball a r)"
lp15@64122
  1948
          by (auto intro: connected_complement_homeomorphic_convex_compact 2)
lp15@64122
  1949
        show "- f ` cball a r \<subseteq> - f ` sphere a r"
lp15@64122
  1950
          by auto
lp15@64122
  1951
        then show "C \<inter> - f ` cball a r \<noteq> {}"
lp15@64122
  1952
          using \<open>C \<noteq> {}\<close> in_components_subset [OF C] nonsub
lp15@64122
  1953
          using image_iff by fastforce
lp15@64122
  1954
      qed
lp15@64122
  1955
      then have "bounded (- f ` cball a r)"
lp15@64122
  1956
        using bounded_subset \<open>bounded C\<close> by auto
lp15@64122
  1957
      then have "\<not> bounded (f ` cball a r)"
lp15@64122
  1958
        using cobounded_imp_unbounded by blast
lp15@64122
  1959
      then show "False"
lp15@64122
  1960
        using compact_continuous_image [OF contf] compact_cball compact_imp_bounded by blast
lp15@64122
  1961
    qed
lp15@64122
  1962
    with \<open>C \<noteq> {}\<close> have "C \<inter> f ` ball a r \<noteq> {}"
lp15@64122
  1963
      by (simp add: inf.absorb_iff1)
lp15@64122
  1964
    then show "f ` ball a r \<subseteq> C"
lp15@64122
  1965
      by (metis components_maximal [OF C _ fimsub] connected_continuous_image ball_subset_cball connected_ball contf continuous_on_subset)
lp15@64122
  1966
  qed
lp15@64122
  1967
  moreover have "open (- f ` sphere a r)"
lp15@64122
  1968
    using hom compact_eq_bounded_closed compact_sphere homeomorphic_compactness by blast
lp15@64122
  1969
  ultimately show ?thesis
lp15@64122
  1970
    using open_components by blast
lp15@64122
  1971
qed
lp15@64122
  1972
lp15@64122
  1973
lp15@64122
  1974
text\<open>Proved by L. E. J. Brouwer (1912)\<close>
lp15@64122
  1975
theorem invariance_of_domain:
lp15@64122
  1976
  fixes f :: "'a \<Rightarrow> 'a::euclidean_space"
lp15@64122
  1977
  assumes "continuous_on S f" "open S" "inj_on f S"
lp15@64122
  1978
    shows "open(f ` S)"
lp15@64122
  1979
  unfolding open_subopen [of "f`S"]
lp15@64122
  1980
proof clarify
lp15@64122
  1981
  fix a
lp15@64122
  1982
  assume "a \<in> S"
lp15@64122
  1983
  obtain \<delta> where "\<delta> > 0" and \<delta>: "cball a \<delta> \<subseteq> S"
lp15@64122
  1984
    using \<open>open S\<close> \<open>a \<in> S\<close> open_contains_cball_eq by blast
lp15@64122
  1985
  show "\<exists>T. open T \<and> f a \<in> T \<and> T \<subseteq> f ` S"
lp15@64122
  1986
  proof (intro exI conjI)
lp15@64122
  1987
    show "open (f ` (ball a \<delta>))"
lp15@64122
  1988
      by (meson \<delta> \<open>0 < \<delta>\<close> assms continuous_on_subset inj_on_subset invariance_of_domain_ball)
lp15@64122
  1989
    show "f a \<in> f ` ball a \<delta>"
lp15@64122
  1990
      by (simp add: \<open>0 < \<delta>\<close>)
lp15@64122
  1991
    show "f ` ball a \<delta> \<subseteq> f ` S"
lp15@64122
  1992
      using \<delta> ball_subset_cball by blast
lp15@64122
  1993
  qed
lp15@64122
  1994
qed
lp15@64122
  1995
lp15@64122
  1996
lemma inv_of_domain_ss0:
lp15@64122
  1997
  fixes f :: "'a \<Rightarrow> 'a::euclidean_space"
lp15@64122
  1998
  assumes contf: "continuous_on U f" and injf: "inj_on f U" and fim: "f ` U \<subseteq> S"
lp15@64122
  1999
      and "subspace S" and dimS: "dim S = DIM('b::euclidean_space)"
lp15@64122
  2000
      and ope: "openin (subtopology euclidean S) U"
lp15@64122
  2001
    shows "openin (subtopology euclidean S) (f ` U)"
lp15@64122
  2002
proof -
lp15@64122
  2003
  have "U \<subseteq> S"
lp15@64122
  2004
    using ope openin_imp_subset by blast
lp15@64122
  2005
  have "(UNIV::'b set) homeomorphic S"
lp15@64122
  2006
    by (simp add: \<open>subspace S\<close> dimS dim_UNIV homeomorphic_subspaces)
lp15@64122
  2007
  then obtain h k where homhk: "homeomorphism (UNIV::'b set) S h k"
lp15@64122
  2008
    using homeomorphic_def by blast
lp15@64122
  2009
  have homkh: "homeomorphism S (k ` S) k h"
lp15@64122
  2010
    using homhk homeomorphism_image2 homeomorphism_sym by fastforce
lp15@64122
  2011
  have "open ((k \<circ> f \<circ> h) ` k ` U)"
lp15@64122
  2012
  proof (rule invariance_of_domain)
lp15@64122
  2013
    show "continuous_on (k ` U) (k \<circ> f \<circ> h)"
lp15@64122
  2014
    proof (intro continuous_intros)
lp15@64122
  2015
      show "continuous_on (k ` U) h"
lp15@64122
  2016
        by (meson continuous_on_subset [OF homeomorphism_cont1 [OF homhk]] top_greatest)
lp15@64122
  2017
      show "continuous_on (h ` k ` U) f"
lp15@64122
  2018
        apply (rule continuous_on_subset [OF contf], clarify)
lp15@64122
  2019
        apply (metis homhk homeomorphism_def ope openin_imp_subset rev_subsetD)
lp15@64122
  2020
        done
lp15@64122
  2021
      show "continuous_on (f ` h ` k ` U) k"
lp15@64122
  2022
        apply (rule continuous_on_subset [OF homeomorphism_cont2 [OF homhk]])
lp15@64122
  2023
        using fim homhk homeomorphism_apply2 ope openin_subset by fastforce
lp15@64122
  2024
    qed
lp15@64122
  2025
    have ope_iff: "\<And>T. open T \<longleftrightarrow> openin (subtopology euclidean (k ` S)) T"
lp15@64122
  2026
      using homhk homeomorphism_image2 open_openin by fastforce
lp15@64122
  2027
    show "open (k ` U)"
lp15@64122
  2028
      by (simp add: ope_iff homeomorphism_imp_open_map [OF homkh ope])
lp15@64122
  2029
    show "inj_on (k \<circ> f \<circ> h) (k ` U)"
lp15@64122
  2030
      apply (clarsimp simp: inj_on_def)
lp15@64122
  2031
      by (metis subsetD fim homeomorphism_apply2 [OF homhk] image_subset_iff inj_on_eq_iff injf \<open>U \<subseteq> S\<close>)
lp15@64122
  2032
  qed
lp15@64122
  2033
  moreover
lp15@64122
  2034
  have eq: "f ` U = h ` (k \<circ> f \<circ> h \<circ> k) ` U"
lp15@64122
  2035
    apply (auto simp: image_comp [symmetric])
lp15@64122
  2036
    apply (metis homkh \<open>U \<subseteq> S\<close> fim homeomorphism_image2 homeomorphism_of_subsets homhk imageI subset_UNIV)
lp15@64122
  2037
    by (metis \<open>U \<subseteq> S\<close> subsetD fim homeomorphism_def homhk image_eqI)
lp15@64122
  2038
  ultimately show ?thesis
lp15@64122
  2039
    by (metis (no_types, hide_lams) homeomorphism_imp_open_map homhk image_comp open_openin subtopology_UNIV)
lp15@64122
  2040
qed
lp15@64122
  2041
lp15@64122
  2042
lemma inv_of_domain_ss1:
lp15@64122
  2043
  fixes f :: "'a \<Rightarrow> 'a::euclidean_space"
lp15@64122
  2044
  assumes contf: "continuous_on U f" and injf: "inj_on f U" and fim: "f ` U \<subseteq> S"
lp15@64122
  2045
      and "subspace S"
lp15@64122
  2046
      and ope: "openin (subtopology euclidean S) U"
lp15@64122
  2047
    shows "openin (subtopology euclidean S) (f ` U)"
lp15@64122
  2048
proof -
lp15@64122
  2049
  define S' where "S' \<equiv> {y. \<forall>x \<in> S. orthogonal x y}"
lp15@64122
  2050
  have "subspace S'"
lp15@64122
  2051
    by (simp add: S'_def subspace_orthogonal_to_vectors)
lp15@64122
  2052
  define g where "g \<equiv> \<lambda>z::'a*'a. ((f \<circ> fst)z, snd z)"
lp15@64122
  2053
  have "openin (subtopology euclidean (S \<times> S')) (g ` (U \<times> S'))"
lp15@64122
  2054
  proof (rule inv_of_domain_ss0)
lp15@64122
  2055
    show "continuous_on (U \<times> S') g"
lp15@64122
  2056
      apply (simp add: g_def)
lp15@64122
  2057
      apply (intro continuous_intros continuous_on_compose2 [OF contf continuous_on_fst], auto)
lp15@64122
  2058
      done
lp15@64122
  2059
    show "g ` (U \<times> S') \<subseteq> S \<times> S'"
lp15@64122
  2060
      using fim  by (auto simp: g_def)
lp15@64122
  2061
    show "inj_on g (U \<times> S')"
lp15@64122
  2062
      using injf by (auto simp: g_def inj_on_def)
lp15@64122
  2063
    show "subspace (S \<times> S')"
lp15@64122
  2064
      by (simp add: \<open>subspace S'\<close> \<open>subspace S\<close> subspace_Times)
lp15@64122
  2065
    show "openin (subtopology euclidean (S \<times> S')) (U \<times> S')"
lp15@64122
  2066
      by (simp add: openin_Times [OF ope])
lp15@64122
  2067
    have "dim (S \<times> S') = dim S + dim S'"
lp15@64122
  2068
      by (simp add: \<open>subspace S'\<close> \<open>subspace S\<close> dim_Times)
lp15@64122
  2069
    also have "... = DIM('a)"
lp15@64122
  2070
      using dim_subspace_orthogonal_to_vectors [OF \<open>subspace S\<close> subspace_UNIV]
lp15@64122
  2071
      by (simp add: add.commute S'_def)
lp15@64122
  2072
    finally show "dim (S \<times> S') = DIM('a)" .
lp15@64122
  2073
  qed
lp15@64122
  2074
  moreover have "g ` (U \<times> S') = f ` U \<times> S'"
lp15@64122
  2075
    by (auto simp: g_def image_iff)
lp15@64122
  2076
  moreover have "0 \<in> S'"
lp15@64122
  2077
    using \<open>subspace S'\<close> subspace_affine by blast
lp15@64122
  2078
  ultimately show ?thesis
lp15@64122
  2079
    by (auto simp: openin_Times_eq)
lp15@64122
  2080
qed
lp15@64122
  2081
lp15@64122
  2082
lp15@64122
  2083
corollary invariance_of_domain_subspaces:
lp15@64122
  2084
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64122
  2085
  assumes ope: "openin (subtopology euclidean U) S"
lp15@64122
  2086
      and "subspace U" "subspace V" and VU: "dim V \<le> dim U"
lp15@64122
  2087
      and contf: "continuous_on S f" and fim: "f ` S \<subseteq> V"
lp15@64122
  2088
      and injf: "inj_on f S"
lp15@64122
  2089
    shows "openin (subtopology euclidean V) (f ` S)"
lp15@64122
  2090
proof -
lp15@64122
  2091
  obtain V' where "subspace V'" "V' \<subseteq> U" "dim V' = dim V"
lp15@64122
  2092
    using choose_subspace_of_subspace [OF VU]
lp15@64122
  2093
    by (metis span_eq \<open>subspace U\<close>)
lp15@64122
  2094
  then have "V homeomorphic V'"
lp15@64122
  2095
    by (simp add: \<open>subspace V\<close> homeomorphic_subspaces)
lp15@64122
  2096
  then obtain h k where homhk: "homeomorphism V V' h k"
lp15@64122
  2097
    using homeomorphic_def by blast
lp15@64122
  2098
  have eq: "f ` S = k ` (h \<circ> f) ` S"
lp15@64122
  2099
  proof -
lp15@64122
  2100
    have "k ` h ` f ` S = f ` S"
lp15@64122
  2101
      by (meson fim homeomorphism_def homeomorphism_of_subsets homhk subset_refl)
lp15@64122
  2102
    then show ?thesis
lp15@64122
  2103
      by (simp add: image_comp)
lp15@64122
  2104
  qed
lp15@64122
  2105
  show ?thesis
lp15@64122
  2106
    unfolding eq
lp15@64122
  2107
  proof (rule homeomorphism_imp_open_map)
lp15@64122
  2108
    show homkh: "homeomorphism V' V k h"
lp15@64122
  2109
      by (simp add: homeomorphism_symD homhk)
lp15@64122
  2110
    have hfV': "(h \<circ> f) ` S \<subseteq> V'"
lp15@64122
  2111
      using fim homeomorphism_image1 homhk by fastforce
lp15@64122
  2112
    moreover have "openin (subtopology euclidean U) ((h \<circ> f) ` S)"
lp15@64122
  2113
    proof (rule inv_of_domain_ss1)
lp15@64122
  2114
      show "continuous_on S (h \<circ> f)"
lp15@64122
  2115
        by (meson contf continuous_on_compose continuous_on_subset fim homeomorphism_cont1 homhk)
lp15@64122
  2116
      show "inj_on (h \<circ> f) S"
lp15@64122
  2117
        apply (clarsimp simp: inj_on_def)
lp15@64122
  2118
        by (metis fim homeomorphism_apply2 [OF homkh] image_subset_iff inj_onD injf)
lp15@64122
  2119
      show "(h \<circ> f) ` S \<subseteq> U"
lp15@64122
  2120
        using \<open>V' \<subseteq> U\<close> hfV' by auto
lp15@64122
  2121
      qed (auto simp: assms)
lp15@64122
  2122
    ultimately show "openin (subtopology euclidean V') ((h \<circ> f) ` S)"
lp15@64122
  2123
      using openin_subset_trans \<open>V' \<subseteq> U\<close> by force
lp15@64122
  2124
  qed
lp15@64122
  2125
qed
lp15@64122
  2126
lp15@64122
  2127
corollary invariance_of_dimension_subspaces:
lp15@64122
  2128
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64122
  2129
  assumes ope: "openin (subtopology euclidean U) S"
lp15@64122
  2130
      and "subspace U" "subspace V"
lp15@64122
  2131
      and contf: "continuous_on S f" and fim: "f ` S \<subseteq> V"
lp15@64122
  2132
      and injf: "inj_on f S" and "S \<noteq> {}"
lp15@64122
  2133
    shows "dim U \<le> dim V"
lp15@64122
  2134
proof -
lp15@64122
  2135
  have "False" if "dim V < dim U"
lp15@64122
  2136
  proof -
lp15@64122
  2137
    obtain T where "subspace T" "T \<subseteq> U" "dim T = dim V"
lp15@64122
  2138
      using choose_subspace_of_subspace [of "dim V" U]
lp15@64122
  2139
      by (metis span_eq \<open>subspace U\<close> \<open>dim V < dim U\<close> linear not_le)
lp15@64122
  2140
    then have "V homeomorphic T"
lp15@64122
  2141
      by (simp add: \<open>subspace V\<close> homeomorphic_subspaces)
lp15@64122
  2142
    then obtain h k where homhk: "homeomorphism V T h k"
lp15@64122
  2143
      using homeomorphic_def  by blast
lp15@64122
  2144
    have "continuous_on S (h \<circ> f)"
lp15@64122
  2145
      by (meson contf continuous_on_compose continuous_on_subset fim homeomorphism_cont1 homhk)
lp15@64122
  2146
    moreover have "(h \<circ> f) ` S \<subseteq> U"
lp15@64122
  2147
      using \<open>T \<subseteq> U\<close> fim homeomorphism_image1 homhk by fastforce
lp15@64122
  2148
    moreover have "inj_on (h \<circ> f) S"
lp15@64122
  2149
      apply (clarsimp simp: inj_on_def)
lp15@64122
  2150
      by (metis fim homeomorphism_apply1 homhk image_subset_iff inj_onD injf)
lp15@64122
  2151
    ultimately have ope_hf: "openin (subtopology euclidean U) ((h \<circ> f) ` S)"
lp15@64122
  2152
      using invariance_of_domain_subspaces [OF ope \<open>subspace U\<close> \<open>subspace U\<close>] by auto
lp15@64122
  2153
    have "(h \<circ> f) ` S \<subseteq> T"
lp15@64122
  2154
      using fim homeomorphism_image1 homhk by fastforce
lp15@64122
  2155
    then show ?thesis
lp15@64122
  2156
      by (metis dim_openin \<open>dim T = dim V\<close> ope_hf \<open>subspace U\<close> \<open>S \<noteq> {}\<close> dim_subset image_is_empty not_le that)
lp15@64122
  2157
  qed
lp15@64122
  2158
  then show ?thesis
lp15@64122
  2159
    using not_less by blast
lp15@64122
  2160
qed
lp15@64122
  2161
lp15@64122
  2162
corollary invariance_of_domain_affine_sets:
lp15@64122
  2163
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64122
  2164
  assumes ope: "openin (subtopology euclidean U) S"
lp15@64122
  2165
      and aff: "affine U" "affine V" "aff_dim V \<le> aff_dim U"
lp15@64122
  2166
      and contf: "continuous_on S f" and fim: "f ` S \<subseteq> V"
lp15@64122
  2167
      and injf: "inj_on f S"
lp15@64122
  2168
    shows "openin (subtopology euclidean V) (f ` S)"
lp15@64122
  2169
proof (cases "S = {}")
lp15@64122
  2170
  case True
lp15@64122
  2171
  then show ?thesis by auto
lp15@64122
  2172
next
lp15@64122
  2173
  case False
lp15@64122
  2174
  obtain a b where "a \<in> S" "a \<in> U" "b \<in> V"
lp15@64122
  2175
    using False fim ope openin_contains_cball by fastforce
lp15@64122
  2176
  have "openin (subtopology euclidean (op + (- b) ` V)) ((op + (- b) \<circ> f \<circ> op + a) ` op + (- a) ` S)"
lp15@64122
  2177
  proof (rule invariance_of_domain_subspaces)
lp15@64122
  2178
    show "openin (subtopology euclidean (op + (- a) ` U)) (op + (- a) ` S)"
lp15@64122
  2179
      by (metis ope homeomorphism_imp_open_map homeomorphism_translation translation_galois)
lp15@64122
  2180
    show "subspace (op + (- a) ` U)"
lp15@64122
  2181
      by (simp add: \<open>a \<in> U\<close> affine_diffs_subspace \<open>affine U\<close>)
lp15@64122
  2182
    show "subspace (op + (- b) ` V)"
lp15@64122
  2183
      by (simp add: \<open>b \<in> V\<close> affine_diffs_subspace \<open>affine V\<close>)
lp15@64122
  2184
    show "dim (op + (- b) ` V) \<le> dim (op + (- a) ` U)"
lp15@64122
  2185
      by (metis \<open>a \<in> U\<close> \<open>b \<in> V\<close> aff_dim_eq_dim affine_hull_eq aff of_nat_le_iff)
lp15@64122
  2186
    show "continuous_on (op + (- a) ` S) (op + (- b) \<circ> f \<circ> op + a)"
lp15@64122
  2187
      by (metis contf continuous_on_compose homeomorphism_cont2 homeomorphism_translation translation_galois)
lp15@64122
  2188
    show "(op + (- b) \<circ> f \<circ> op + a) ` op + (- a) ` S \<subseteq> op + (- b) ` V"
lp15@64122
  2189
      using fim by auto
lp15@64122
  2190
    show "inj_on (op + (- b) \<circ> f \<circ> op + a) (op + (- a) ` S)"
lp15@64122
  2191
      by (auto simp: inj_on_def) (meson inj_onD injf)
lp15@64122
  2192
  qed
lp15@64122
  2193
  then show ?thesis
lp15@64122
  2194
    by (metis (no_types, lifting) homeomorphism_imp_open_map homeomorphism_translation image_comp translation_galois)
lp15@64122
  2195
qed
lp15@64122
  2196
lp15@64122
  2197
corollary invariance_of_dimension_affine_sets:
lp15@64122
  2198
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64122
  2199
  assumes ope: "openin (subtopology euclidean U) S"
lp15@64122
  2200
      and aff: "affine U" "affine V"
lp15@64122
  2201
      and contf: "continuous_on S f" and fim: "f ` S \<subseteq> V"
lp15@64122
  2202
      and injf: "inj_on f S" and "S \<noteq> {}"
lp15@64122
  2203
    shows "aff_dim U \<le> aff_dim V"
lp15@64122
  2204
proof -
lp15@64122
  2205
  obtain a b where "a \<in> S" "a \<in> U" "b \<in> V"
lp15@64122
  2206
    using \<open>S \<noteq> {}\<close> fim ope openin_contains_cball by fastforce
lp15@64122
  2207
  have "dim (op + (- a) ` U) \<le> dim (op + (- b) ` V)"
lp15@64122
  2208
  proof (rule invariance_of_dimension_subspaces)
lp15@64122
  2209
    show "openin (subtopology euclidean (op + (- a) ` U)) (op + (- a) ` S)"
lp15@64122
  2210
      by (metis ope homeomorphism_imp_open_map homeomorphism_translation translation_galois)
lp15@64122
  2211
    show "subspace (op + (- a) ` U)"
lp15@64122
  2212
      by (simp add: \<open>a \<in> U\<close> affine_diffs_subspace \<open>affine U\<close>)
lp15@64122
  2213
    show "subspace (op + (- b) ` V)"
lp15@64122
  2214
      by (simp add: \<open>b \<in> V\<close> affine_diffs_subspace \<open>affine V\<close>)
lp15@64122
  2215
    show "continuous_on (op + (- a) ` S) (op + (- b) \<circ> f \<circ> op + a)"
lp15@64122
  2216
      by (metis contf continuous_on_compose homeomorphism_cont2 homeomorphism_translation translation_galois)
lp15@64122
  2217
    show "(op + (- b) \<circ> f \<circ> op + a) ` op + (- a) ` S \<subseteq> op + (- b) ` V"
lp15@64122
  2218
      using fim by auto
lp15@64122
  2219
    show "inj_on (op + (- b) \<circ> f \<circ> op + a) (op + (- a) ` S)"
lp15@64122
  2220
      by (auto simp: inj_on_def) (meson inj_onD injf)
lp15@64122
  2221
  qed (use \<open>S \<noteq> {}\<close> in auto)
lp15@64122
  2222
  then show ?thesis
lp15@64122
  2223
    by (metis \<open>a \<in> U\<close> \<open>b \<in> V\<close> aff_dim_eq_dim affine_hull_eq aff of_nat_le_iff)
lp15@64122
  2224
qed
lp15@64122
  2225
lp15@64122
  2226
corollary invariance_of_dimension:
lp15@64122
  2227
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64122
  2228
  assumes contf: "continuous_on S f" and "open S"
lp15@64122
  2229
      and injf: "inj_on f S" and "S \<noteq> {}"
lp15@64122
  2230
    shows "DIM('a) \<le> DIM('b)"
lp15@64122
  2231
  using invariance_of_dimension_subspaces [of UNIV S UNIV f] assms
lp15@64122
  2232
  by auto
lp15@64122
  2233
lp15@64122
  2234
lp15@64122
  2235
corollary continuous_injective_image_subspace_dim_le:
lp15@64122
  2236
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64122
  2237
  assumes "subspace S" "subspace T"
lp15@64122
  2238
      and contf: "continuous_on S f" and fim: "f ` S \<subseteq> T"
lp15@64122
  2239
      and injf: "inj_on f S"
lp15@64122
  2240
    shows "dim S \<le> dim T"
lp15@64122
  2241
  apply (rule invariance_of_dimension_subspaces [of S S _ f])
lp15@64122
  2242
  using assms by (auto simp: subspace_affine)
lp15@64122
  2243
lp15@64122
  2244
lemma invariance_of_dimension_convex_domain:
lp15@64122
  2245
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64122
  2246
  assumes "convex S"
lp15@64122
  2247
      and contf: "continuous_on S f" and fim: "f ` S \<subseteq> affine hull T"
lp15@64122
  2248
      and injf: "inj_on f S"
lp15@64122
  2249
    shows "aff_dim S \<le> aff_dim T"
lp15@64122
  2250
proof (cases "S = {}")
lp15@64122
  2251
  case True
lp15@64122
  2252
  then show ?thesis by (simp add: aff_dim_geq)
lp15@64122
  2253
next
lp15@64122
  2254
  case False
lp15@64122
  2255
  have "aff_dim (affine hull S) \<le> aff_dim (affine hull T)"
lp15@64122
  2256
  proof (rule invariance_of_dimension_affine_sets)
lp15@64122
  2257
    show "openin (subtopology euclidean (affine hull S)) (rel_interior S)"
lp15@64122
  2258
      by (simp add: openin_rel_interior)
lp15@64122
  2259
    show "continuous_on (rel_interior S) f"
lp15@64122
  2260
      using contf continuous_on_subset rel_interior_subset by blast
lp15@64122
  2261
    show "f ` rel_interior S \<subseteq> affine hull T"
lp15@64122
  2262
      using fim rel_interior_subset by blast
lp15@64122
  2263
    show "inj_on f (rel_interior S)"
lp15@64122
  2264
      using inj_on_subset injf rel_interior_subset by blast
lp15@64122
  2265
    show "rel_interior S \<noteq> {}"
lp15@64122
  2266
      by (simp add: False \<open>convex S\<close> rel_interior_eq_empty)
lp15@64122
  2267
  qed auto
lp15@64122
  2268
  then show ?thesis
lp15@64122
  2269
    by simp
lp15@64122
  2270
qed
lp15@64122
  2271
lp15@64122
  2272
lp15@64122
  2273
lemma homeomorphic_convex_sets_le:
lp15@64122
  2274
  assumes "convex S" "S homeomorphic T"
lp15@64122
  2275
  shows "aff_dim S \<le> aff_dim T"
lp15@64122
  2276
proof -
lp15@64122
  2277
  obtain h k where homhk: "homeomorphism S T h k"
lp15@64122
  2278
    using homeomorphic_def assms  by blast
lp15@64122
  2279
  show ?thesis
lp15@64122
  2280
  proof (rule invariance_of_dimension_convex_domain [OF \<open>convex S\<close>])
lp15@64122
  2281
    show "continuous_on S h"
lp15@64122
  2282
      using homeomorphism_def homhk by blast
lp15@64122
  2283
    show "h ` S \<subseteq> affine hull T"
lp15@64122
  2284
      by (metis homeomorphism_def homhk hull_subset)
lp15@64122
  2285
    show "inj_on h S"
lp15@64122
  2286
      by (meson homeomorphism_apply1 homhk inj_on_inverseI)
lp15@64122
  2287
  qed
lp15@64122
  2288
qed
lp15@64122
  2289
lp15@64122
  2290
lemma homeomorphic_convex_sets:
lp15@64122
  2291
  assumes "convex S" "convex T" "S homeomorphic T"
lp15@64122
  2292
  shows "aff_dim S = aff_dim T"
lp15@64122
  2293
  by (meson assms dual_order.antisym homeomorphic_convex_sets_le homeomorphic_sym)
lp15@64122
  2294
lp15@64122
  2295
lemma homeomorphic_convex_compact_sets_eq:
lp15@64122
  2296
  assumes "convex S" "compact S" "convex T" "compact T"
lp15@64122
  2297
  shows "S homeomorphic T \<longleftrightarrow> aff_dim S = aff_dim T"
lp15@64122
  2298
  by (meson assms homeomorphic_convex_compact_sets homeomorphic_convex_sets)
lp15@64122
  2299
lp15@64122
  2300
lemma invariance_of_domain_gen:
lp15@64122
  2301
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64122
  2302
  assumes "open S" "continuous_on S f" "inj_on f S" "DIM('b) \<le> DIM('a)"
lp15@64122
  2303
    shows "open(f ` S)"
lp15@64122
  2304
  using invariance_of_domain_subspaces [of UNIV S UNIV f] assms by auto
lp15@64122
  2305
lp15@64122
  2306
lemma injective_into_1d_imp_open_map_UNIV:
lp15@64122
  2307
  fixes f :: "'a::euclidean_space \<Rightarrow> real"
lp15@64122
  2308
  assumes "open T" "continuous_on S f" "inj_on f S" "T \<subseteq> S"
lp15@64122
  2309
    shows "open (f ` T)"
lp15@64122
  2310
  apply (rule invariance_of_domain_gen [OF \<open>open T\<close>])
lp15@64122
  2311
  using assms apply (auto simp: elim: continuous_on_subset subset_inj_on)
lp15@64122
  2312
  done
lp15@64122
  2313
lp15@64122
  2314
lemma continuous_on_inverse_open:
lp15@64122
  2315
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64122
  2316
  assumes "open S" "continuous_on S f" "DIM('b) \<le> DIM('a)" and gf: "\<And>x. x \<in> S \<Longrightarrow> g(f x) = x"
lp15@64122
  2317
    shows "continuous_on (f ` S) g"
lp15@64122
  2318
proof (clarsimp simp add: continuous_openin_preimage_eq)
lp15@64122
  2319
  fix T :: "'a set"
lp15@64122
  2320
  assume "open T"
lp15@66884
  2321
  have eq: "f ` S \<inter> g -` T = f ` (S \<inter> T)"
lp15@64122
  2322
    by (auto simp: gf)
lp15@66884
  2323
  show "openin (subtopology euclidean (f ` S)) (f ` S \<inter> g -` T)"
lp15@64122
  2324
    apply (subst eq)
lp15@64122
  2325
    apply (rule open_openin_trans)
lp15@64122
  2326
      apply (rule invariance_of_domain_gen)
lp15@64122
  2327
    using assms
lp15@64122
  2328
         apply auto
lp15@64122
  2329
    using inj_on_inverseI apply auto[1]
lp15@64122
  2330
    by (metis \<open>open T\<close> continuous_on_subset inj_onI inj_on_subset invariance_of_domain_gen openin_open openin_open_eq)
lp15@64122
  2331
qed
lp15@64122
  2332
lp15@64122
  2333
lemma invariance_of_domain_homeomorphism:
lp15@64122
  2334
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64122
  2335
  assumes "open S" "continuous_on S f" "DIM('b) \<le> DIM('a)" "inj_on f S"
lp15@64122
  2336
  obtains g where "homeomorphism S (f ` S) f g"
lp15@64122
  2337
proof
lp15@64122
  2338
  show "homeomorphism S (f ` S) f (inv_into S f)"
lp15@64122
  2339
    by (simp add: assms continuous_on_inverse_open homeomorphism_def)
lp15@64122
  2340
qed
lp15@64122
  2341
lp15@64122
  2342
corollary invariance_of_domain_homeomorphic:
lp15@64122
  2343
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64122
  2344
  assumes "open S" "continuous_on S f" "DIM('b) \<le> DIM('a)" "inj_on f S"
lp15@64122
  2345
  shows "S homeomorphic (f ` S)"
lp15@64122
  2346
  using invariance_of_domain_homeomorphism [OF assms]
lp15@64122
  2347
  by (meson homeomorphic_def)
lp15@64122
  2348
lp15@64287
  2349
lemma continuous_image_subset_interior:
lp15@64287
  2350
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@64287
  2351
  assumes "continuous_on S f" "inj_on f S" "DIM('b) \<le> DIM('a)"
lp15@64287
  2352
  shows "f ` (interior S) \<subseteq> interior(f ` S)"
lp15@64287
  2353
  apply (rule interior_maximal)
lp15@64287
  2354
   apply (simp add: image_mono interior_subset)
lp15@64287
  2355
  apply (rule invariance_of_domain_gen)
lp15@64287
  2356
  using assms
lp15@64287
  2357
     apply (auto simp: subset_inj_on interior_subset continuous_on_subset)
lp15@64287
  2358
  done
lp15@64287
  2359
lp15@64287
  2360
lemma homeomorphic_interiors_same_dimension:
lp15@64287
  2361
  fixes S :: "'a::euclidean_space set" and T :: "'b::euclidean_space set"
lp15@64287
  2362
  assumes "S homeomorphic T" and dimeq: "DIM('a) = DIM('b)"
lp15@64287
  2363
  shows "(interior S) homeomorphic (interior T)"
lp15@64287
  2364
  using assms [unfolded homeomorphic_minimal]
lp15@64287
  2365
  unfolding homeomorphic_def