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