src/HOL/Multivariate_Analysis/Brouwer_Fixpoint.thy
changeset 41958 5abc60a017e0
parent 39302 d7728f65b353
child 44282 f0de18b62d63
equal deleted inserted replaced
41957:d488ae70366d 41958:5abc60a017e0
   143     apply(rule bexI[OF _ `a\<in>?M`], rule bexI[OF _ `c\<in>?M`],rule,rule `a\<noteq>c`) proof(rule,unfold mem_Collect_eq,erule conjE)
   143     apply(rule bexI[OF _ `a\<in>?M`], rule bexI[OF _ `c\<in>?M`],rule,rule `a\<noteq>c`) proof(rule,unfold mem_Collect_eq,erule conjE)
   144     fix z assume as:"z \<in> s" "f ` (s - {z}) = t - {b}"
   144     fix z assume as:"z \<in> s" "f ` (s - {z}) = t - {b}"
   145     have inj:"inj_on f (s - {z})" apply(rule eq_card_imp_inj_on) unfolding as using as(1) and assms by auto
   145     have inj:"inj_on f (s - {z})" apply(rule eq_card_imp_inj_on) unfolding as using as(1) and assms by auto
   146     show "z = a \<or> z = c" proof(rule ccontr)
   146     show "z = a \<or> z = c" proof(rule ccontr)
   147       assume "\<not> (z = a \<or> z = c)" thus False using inj[unfolded inj_on_def,THEN bspec[where x=a],THEN bspec[where x=c]]
   147       assume "\<not> (z = a \<or> z = c)" thus False using inj[unfolded inj_on_def,THEN bspec[where x=a],THEN bspec[where x=c]]
   148 	using `a\<in>s` `c\<in>s` `f a = f c` `a\<noteq>c` by auto qed qed qed
   148         using `a\<in>s` `c\<in>s` `f a = f c` `a\<noteq>c` by auto qed qed qed
   149 
   149 
   150 subsection {* Combine this with the basic counting lemma. *}
   150 subsection {* Combine this with the basic counting lemma. *}
   151 
   151 
   152 lemma kuhn_complete_lemma:
   152 lemma kuhn_complete_lemma:
   153   assumes "finite simplices"
   153   assumes "finite simplices"
   193       b:"b\<in>insert x F" "\<forall>x\<in>F. \<forall>j. x j \<le> b j" using as(3)[OF False] using as(5) by auto
   193       b:"b\<in>insert x F" "\<forall>x\<in>F. \<forall>j. x j \<le> b j" using as(3)[OF False] using as(5) by auto
   194     have "\<exists>a\<in>insert x F. \<forall>x\<in>insert x F. \<forall>j. a j \<le> x j"
   194     have "\<exists>a\<in>insert x F. \<forall>x\<in>insert x F. \<forall>j. a j \<le> x j"
   195       using as(5)[rule_format,OF a(1) insertI1] apply- proof(erule disjE)
   195       using as(5)[rule_format,OF a(1) insertI1] apply- proof(erule disjE)
   196       assume "\<forall>j. a j \<le> x j" thus ?thesis apply(rule_tac x=a in bexI) using a by auto next
   196       assume "\<forall>j. a j \<le> x j" thus ?thesis apply(rule_tac x=a in bexI) using a by auto next
   197       assume "\<forall>j. x j \<le> a j" thus ?thesis apply(rule_tac x=x in bexI) apply(rule,rule) using a apply -
   197       assume "\<forall>j. x j \<le> a j" thus ?thesis apply(rule_tac x=x in bexI) apply(rule,rule) using a apply -
   198 	apply(erule_tac x=xa in ballE) apply(erule_tac x=j in allE)+ by auto qed moreover
   198         apply(erule_tac x=xa in ballE) apply(erule_tac x=j in allE)+ by auto qed moreover
   199     have "\<exists>b\<in>insert x F. \<forall>x\<in>insert x F. \<forall>j. x j \<le> b j"
   199     have "\<exists>b\<in>insert x F. \<forall>x\<in>insert x F. \<forall>j. x j \<le> b j"
   200       using as(5)[rule_format,OF b(1) insertI1] apply- proof(erule disjE)
   200       using as(5)[rule_format,OF b(1) insertI1] apply- proof(erule disjE)
   201       assume "\<forall>j. x j \<le> b j" thus ?thesis apply(rule_tac x=b in bexI) using b by auto next
   201       assume "\<forall>j. x j \<le> b j" thus ?thesis apply(rule_tac x=b in bexI) using b by auto next
   202       assume "\<forall>j. b j \<le> x j" thus ?thesis apply(rule_tac x=x in bexI) apply(rule,rule) using b apply -
   202       assume "\<forall>j. b j \<le> x j" thus ?thesis apply(rule_tac x=x in bexI) apply(rule,rule) using b apply -
   203 	apply(erule_tac x=xa in ballE) apply(erule_tac x=j in allE)+ by auto qed
   203         apply(erule_tac x=xa in ballE) apply(erule_tac x=j in allE)+ by auto qed
   204     ultimately show  ?thesis by auto qed qed(auto)
   204     ultimately show  ?thesis by auto qed qed(auto)
   205 
   205 
   206 lemma kle_imp_pointwise: "kle n x y \<Longrightarrow> (\<forall>j. x j \<le> y j)" unfolding kle_def by auto
   206 lemma kle_imp_pointwise: "kle n x y \<Longrightarrow> (\<forall>j. x j \<le> y j)" unfolding kle_def by auto
   207 
   207 
   208 lemma pointwise_antisym: fixes x::"nat \<Rightarrow> nat"
   208 lemma pointwise_antisym: fixes x::"nat \<Rightarrow> nat"
   229   have "\<exists>a\<in>s. \<forall>x\<in>s. \<forall>j. a j \<le> x j" apply(rule pointwise_minimal_pointwise_maximal(1)[OF assms(1-2)])
   229   have "\<exists>a\<in>s. \<forall>x\<in>s. \<forall>j. a j \<le> x j" apply(rule pointwise_minimal_pointwise_maximal(1)[OF assms(1-2)])
   230     apply(rule,rule) apply(drule_tac assms(3)[rule_format],assumption) using kle_imp_pointwise by auto
   230     apply(rule,rule) apply(drule_tac assms(3)[rule_format],assumption) using kle_imp_pointwise by auto
   231   then guess a .. note a=this show ?thesis apply(rule_tac x=a in bexI) proof fix x assume "x\<in>s"
   231   then guess a .. note a=this show ?thesis apply(rule_tac x=a in bexI) proof fix x assume "x\<in>s"
   232     show "kle n a x" using assms(3)[rule_format,OF a(1) `x\<in>s`] apply- proof(erule disjE)
   232     show "kle n a x" using assms(3)[rule_format,OF a(1) `x\<in>s`] apply- proof(erule disjE)
   233       assume "kle n x a" hence "x = a" apply- unfolding pointwise_antisym[THEN sym]
   233       assume "kle n x a" hence "x = a" apply- unfolding pointwise_antisym[THEN sym]
   234 	apply(drule kle_imp_pointwise) using a(2)[rule_format,OF `x\<in>s`] by auto
   234         apply(drule kle_imp_pointwise) using a(2)[rule_format,OF `x\<in>s`] by auto
   235       thus ?thesis using kle_refl by auto  qed qed(insert a, auto) qed
   235       thus ?thesis using kle_refl by auto  qed qed(insert a, auto) qed
   236 
   236 
   237 lemma kle_maximal: assumes "finite s" "s \<noteq> {}" "\<forall>x\<in>s. \<forall>y\<in>s. kle n x y \<or> kle n y x"
   237 lemma kle_maximal: assumes "finite s" "s \<noteq> {}" "\<forall>x\<in>s. \<forall>y\<in>s. kle n x y \<or> kle n y x"
   238   shows "\<exists>a\<in>s. \<forall>x\<in>s. kle n x a" proof-
   238   shows "\<exists>a\<in>s. \<forall>x\<in>s. kle n x a" proof-
   239   have "\<exists>a\<in>s. \<forall>x\<in>s. \<forall>j. a j \<ge> x j" apply(rule pointwise_minimal_pointwise_maximal(2)[OF assms(1-2)])
   239   have "\<exists>a\<in>s. \<forall>x\<in>s. \<forall>j. a j \<ge> x j" apply(rule pointwise_minimal_pointwise_maximal(2)[OF assms(1-2)])
   240     apply(rule,rule) apply(drule_tac assms(3)[rule_format],assumption) using kle_imp_pointwise by auto
   240     apply(rule,rule) apply(drule_tac assms(3)[rule_format],assumption) using kle_imp_pointwise by auto
   241   then guess a .. note a=this show ?thesis apply(rule_tac x=a in bexI) proof fix x assume "x\<in>s"
   241   then guess a .. note a=this show ?thesis apply(rule_tac x=a in bexI) proof fix x assume "x\<in>s"
   242     show "kle n x a" using assms(3)[rule_format,OF a(1) `x\<in>s`] apply- proof(erule disjE)
   242     show "kle n x a" using assms(3)[rule_format,OF a(1) `x\<in>s`] apply- proof(erule disjE)
   243       assume "kle n a x" hence "x = a" apply- unfolding pointwise_antisym[THEN sym]
   243       assume "kle n a x" hence "x = a" apply- unfolding pointwise_antisym[THEN sym]
   244 	apply(drule kle_imp_pointwise) using a(2)[rule_format,OF `x\<in>s`] by auto
   244         apply(drule kle_imp_pointwise) using a(2)[rule_format,OF `x\<in>s`] by auto
   245       thus ?thesis using kle_refl by auto  qed qed(insert a, auto) qed
   245       thus ?thesis using kle_refl by auto  qed qed(insert a, auto) qed
   246 
   246 
   247 lemma kle_strict_set: assumes "kle n x y" "x \<noteq> y"
   247 lemma kle_strict_set: assumes "kle n x y" "x \<noteq> y"
   248   shows "1 \<le> card {k\<in>{1..n}. x k < y k}" proof-
   248   shows "1 \<le> card {k\<in>{1..n}. x k < y k}" proof-
   249   guess i using kle_strict(2)[OF assms] ..
   249   guess i using kle_strict(2)[OF assms] ..
   313   guess kk1 using assms(1)[unfolded kle_def] .. note kk1=this
   313   guess kk1 using assms(1)[unfolded kle_def] .. note kk1=this
   314   guess kk2 using assms(2)[unfolded kle_def] .. note kk2=this
   314   guess kk2 using assms(2)[unfolded kle_def] .. note kk2=this
   315   show ?thesis unfolding kle_def apply(rule_tac x="kk1 \<union> kk2" in exI) apply(rule) defer proof
   315   show ?thesis unfolding kle_def apply(rule_tac x="kk1 \<union> kk2" in exI) apply(rule) defer proof
   316     fix i show "c i = a i + (if i \<in> kk1 \<union> kk2 then 1 else 0)" proof(cases "i\<in>kk1 \<union> kk2")
   316     fix i show "c i = a i + (if i \<in> kk1 \<union> kk2 then 1 else 0)" proof(cases "i\<in>kk1 \<union> kk2")
   317       case True hence "c i \<ge> a i + (if i \<in> kk1 \<union> kk2 then 1 else 0)"
   317       case True hence "c i \<ge> a i + (if i \<in> kk1 \<union> kk2 then 1 else 0)"
   318 	unfolding kk1[THEN conjunct2,rule_format,of i] kk2[THEN conjunct2,rule_format,of i] by auto
   318         unfolding kk1[THEN conjunct2,rule_format,of i] kk2[THEN conjunct2,rule_format,of i] by auto
   319       moreover have "c i \<le> a i + (if i \<in> kk1 \<union> kk2 then 1 else 0)" using True assms(3) by auto  
   319       moreover have "c i \<le> a i + (if i \<in> kk1 \<union> kk2 then 1 else 0)" using True assms(3) by auto  
   320       ultimately show ?thesis by auto next
   320       ultimately show ?thesis by auto next
   321       case False thus ?thesis using kk1 kk2 by auto qed qed(insert kk1 kk2, auto) qed
   321       case False thus ?thesis using kk1 kk2 by auto qed qed(insert kk1 kk2, auto) qed
   322 
   322 
   323 lemma kle_between_r: assumes "kle n a b" "kle n b c" "kle n a x" "kle n c x" shows "kle n b x"
   323 lemma kle_between_r: assumes "kle n a b" "kle n b c" "kle n a x" "kle n c x" shows "kle n b x"
   506       "\<forall>x\<in>s0. y x \<in> t" "\<forall>x\<in>UNIV - s0. y x = d" thus "x xb = d" unfolding as by auto qed auto
   506       "\<forall>x\<in>s0. y x \<in> t" "\<forall>x\<in>UNIV - s0. y x = d" thus "x xb = d" unfolding as by auto qed auto
   507   have inj:"inj_on ?l {(b,g). b\<in>t \<and> g\<in>?M s0}" unfolding inj_on_def apply(rule,rule,rule) unfolding mem_Collect_eq apply(erule splitE conjE)+ proof-
   507   have inj:"inj_on ?l {(b,g). b\<in>t \<and> g\<in>?M s0}" unfolding inj_on_def apply(rule,rule,rule) unfolding mem_Collect_eq apply(erule splitE conjE)+ proof-
   508     case goal1 note as = this(1,4-)[unfolded goal1 split_conv]
   508     case goal1 note as = this(1,4-)[unfolded goal1 split_conv]
   509     have "xa = xb" using as(1)[THEN cong[of _ _ a]] by auto
   509     have "xa = xb" using as(1)[THEN cong[of _ _ a]] by auto
   510     moreover have "ya = yb" proof(rule ext) fix x show "ya x = yb x" proof(cases "x = a") 
   510     moreover have "ya = yb" proof(rule ext) fix x show "ya x = yb x" proof(cases "x = a") 
   511 	case False thus ?thesis using as(1)[THEN cong[of _ _ x x]] by auto next
   511         case False thus ?thesis using as(1)[THEN cong[of _ _ x x]] by auto next
   512 	case True thus ?thesis using as(5,7) using as0(2) by auto qed qed 
   512         case True thus ?thesis using as(5,7) using as0(2) by auto qed qed 
   513     ultimately show ?case unfolding goal1 by auto qed
   513     ultimately show ?case unfolding goal1 by auto qed
   514   have "finite s0" using `finite s` unfolding as0 by simp
   514   have "finite s0" using `finite s` unfolding as0 by simp
   515   show ?case unfolding as0 * card_image[OF inj] using assms
   515   show ?case unfolding as0 * card_image[OF inj] using assms
   516     unfolding SetCompr_Sigma_eq apply-
   516     unfolding SetCompr_Sigma_eq apply-
   517     unfolding card_cartesian_product
   517     unfolding card_cartesian_product
   547 lemma simplex_top_face: assumes "0<p" "\<forall>x\<in>f. x (n + 1) = p"
   547 lemma simplex_top_face: assumes "0<p" "\<forall>x\<in>f. x (n + 1) = p"
   548   shows "(\<exists>s a. ksimplex p (n + 1) s \<and> a \<in> s \<and> (f = s - {a})) \<longleftrightarrow> ksimplex p n f" (is "?ls = ?rs") proof
   548   shows "(\<exists>s a. ksimplex p (n + 1) s \<and> a \<in> s \<and> (f = s - {a})) \<longleftrightarrow> ksimplex p n f" (is "?ls = ?rs") proof
   549   assume ?ls then guess s .. then guess a apply-apply(erule exE,(erule conjE)+) . note sa=this
   549   assume ?ls then guess s .. then guess a apply-apply(erule exE,(erule conjE)+) . note sa=this
   550   show ?rs unfolding ksimplex_def sa(3) apply(rule) defer apply rule defer apply(rule,rule,rule,rule) defer apply(rule,rule) proof-
   550   show ?rs unfolding ksimplex_def sa(3) apply(rule) defer apply rule defer apply(rule,rule,rule,rule) defer apply(rule,rule) proof-
   551     fix x y assume as:"x \<in>s - {a}" "y \<in>s - {a}" have xyp:"x (n + 1) = y (n + 1)"
   551     fix x y assume as:"x \<in>s - {a}" "y \<in>s - {a}" have xyp:"x (n + 1) = y (n + 1)"
   552 	using as(1)[unfolded sa(3)[THEN sym], THEN assms(2)[rule_format]]
   552         using as(1)[unfolded sa(3)[THEN sym], THEN assms(2)[rule_format]]
   553 	using as(2)[unfolded sa(3)[THEN sym], THEN assms(2)[rule_format]] by auto
   553         using as(2)[unfolded sa(3)[THEN sym], THEN assms(2)[rule_format]] by auto
   554     show "kle n x y \<or> kle n y x" proof(cases "kle (n + 1) x y")
   554     show "kle n x y \<or> kle n y x" proof(cases "kle (n + 1) x y")
   555       case True then guess k unfolding kle_def .. note k=this hence *:"n+1 \<notin> k" using xyp by auto
   555       case True then guess k unfolding kle_def .. note k=this hence *:"n+1 \<notin> k" using xyp by auto
   556       have "\<not> (\<exists>x\<in>k. x\<notin>{1..n})" apply(rule ccontr) unfolding not_not apply(erule bexE) proof-
   556       have "\<not> (\<exists>x\<in>k. x\<notin>{1..n})" apply(rule ccontr) unfolding not_not apply(erule bexE) proof-
   557 	fix x assume as:"x \<in> k" "x \<notin> {1..n}" have "x \<noteq> n+1" using as and * by auto
   557         fix x assume as:"x \<in> k" "x \<notin> {1..n}" have "x \<noteq> n+1" using as and * by auto
   558 	thus False using as and k[THEN conjunct1,unfolded subset_eq] by auto qed
   558         thus False using as and k[THEN conjunct1,unfolded subset_eq] by auto qed
   559       thus ?thesis apply-apply(rule disjI1) unfolding kle_def using k apply(rule_tac x=k in exI) by auto next
   559       thus ?thesis apply-apply(rule disjI1) unfolding kle_def using k apply(rule_tac x=k in exI) by auto next
   560       case False hence "kle (n + 1) y x" using ksimplexD(6)[OF sa(1),rule_format, of x y] using as by auto
   560       case False hence "kle (n + 1) y x" using ksimplexD(6)[OF sa(1),rule_format, of x y] using as by auto
   561       then guess k unfolding kle_def .. note k=this hence *:"n+1 \<notin> k" using xyp by auto
   561       then guess k unfolding kle_def .. note k=this hence *:"n+1 \<notin> k" using xyp by auto
   562       hence "\<not> (\<exists>x\<in>k. x\<notin>{1..n})" apply-apply(rule ccontr) unfolding not_not apply(erule bexE) proof-
   562       hence "\<not> (\<exists>x\<in>k. x\<notin>{1..n})" apply-apply(rule ccontr) unfolding not_not apply(erule bexE) proof-
   563 	fix x assume as:"x \<in> k" "x \<notin> {1..n}" have "x \<noteq> n+1" using as and * by auto
   563         fix x assume as:"x \<in> k" "x \<notin> {1..n}" have "x \<noteq> n+1" using as and * by auto
   564 	thus False using as and k[THEN conjunct1,unfolded subset_eq] by auto qed
   564         thus False using as and k[THEN conjunct1,unfolded subset_eq] by auto qed
   565       thus ?thesis apply-apply(rule disjI2) unfolding kle_def using k apply(rule_tac x=k in exI) by auto qed next
   565       thus ?thesis apply-apply(rule disjI2) unfolding kle_def using k apply(rule_tac x=k in exI) by auto qed next
   566     fix x j assume as:"x\<in>s - {a}" "j\<notin>{1..n}"
   566     fix x j assume as:"x\<in>s - {a}" "j\<notin>{1..n}"
   567     thus "x j = p" using as(1)[unfolded sa(3)[THEN sym], THEN assms(2)[rule_format]]
   567     thus "x j = p" using as(1)[unfolded sa(3)[THEN sym], THEN assms(2)[rule_format]]
   568       apply(cases "j = n+1") using sa(1)[unfolded ksimplex_def] by auto qed(insert sa ksimplexD[OF sa(1)], auto) next
   568       apply(cases "j = n+1") using sa(1)[unfolded ksimplex_def] by auto qed(insert sa ksimplexD[OF sa(1)], auto) next
   569   assume ?rs note rs=ksimplexD[OF this] guess a b apply(rule ksimplex_extrema[OF `?rs`]) . note ab = this
   569   assume ?rs note rs=ksimplexD[OF this] guess a b apply(rule ksimplex_extrema[OF `?rs`]) . note ab = this
   575     fix x j assume x:"x \<in> insert c f" thus "x j \<le> p" proof (cases "x=c")
   575     fix x j assume x:"x \<in> insert c f" thus "x j \<le> p" proof (cases "x=c")
   576       case True show ?thesis unfolding True c_def apply(cases "j=n+1") using ab(1) and rs(4) by auto 
   576       case True show ?thesis unfolding True c_def apply(cases "j=n+1") using ab(1) and rs(4) by auto 
   577     qed(insert x rs(4), auto simp add:c_def)
   577     qed(insert x rs(4), auto simp add:c_def)
   578     show "j \<notin> {1..n + 1} \<longrightarrow> x j = p" apply(cases "x=c") using x ab(1) rs(5) unfolding c_def by auto
   578     show "j \<notin> {1..n + 1} \<longrightarrow> x j = p" apply(cases "x=c") using x ab(1) rs(5) unfolding c_def by auto
   579     { fix z assume z:"z \<in> insert c f" hence "kle (n + 1) c z" apply(cases "z = c") (*defer apply(rule kle_Suc)*) proof-
   579     { fix z assume z:"z \<in> insert c f" hence "kle (n + 1) c z" apply(cases "z = c") (*defer apply(rule kle_Suc)*) proof-
   580 	case False hence "z\<in>f" using z by auto
   580         case False hence "z\<in>f" using z by auto
   581 	then guess k apply(drule_tac ab(3)[THEN bspec[where x=z], THEN conjunct1]) unfolding kle_def apply(erule exE) .
   581         then guess k apply(drule_tac ab(3)[THEN bspec[where x=z], THEN conjunct1]) unfolding kle_def apply(erule exE) .
   582 	thus "kle (n + 1) c z" unfolding kle_def apply(rule_tac x="insert (n + 1) k" in exI) unfolding c_def
   582         thus "kle (n + 1) c z" unfolding kle_def apply(rule_tac x="insert (n + 1) k" in exI) unfolding c_def
   583 	  using ab using rs(5)[rule_format,OF ab(1),of "n + 1"] assms(1) by auto qed auto } note * = this
   583           using ab using rs(5)[rule_format,OF ab(1),of "n + 1"] assms(1) by auto qed auto } note * = this
   584     fix y assume y:"y \<in> insert c f" show "kle (n + 1) x y \<or> kle (n + 1) y x" proof(cases "x = c \<or> y = c")
   584     fix y assume y:"y \<in> insert c f" show "kle (n + 1) x y \<or> kle (n + 1) y x" proof(cases "x = c \<or> y = c")
   585       case False hence **:"x\<in>f" "y\<in>f" using x y by auto
   585       case False hence **:"x\<in>f" "y\<in>f" using x y by auto
   586       show ?thesis using rs(6)[rule_format,OF **] by(auto dest: kle_Suc) qed(insert * x y, auto)
   586       show ?thesis using rs(6)[rule_format,OF **] by(auto dest: kle_Suc) qed(insert * x y, auto)
   587   qed(insert rs, auto) qed
   587   qed(insert rs, auto) qed
   588 
   588 
   633     have a:"a = a0" apply(rule ksimplex_fix_plane_p[OF assms(1-2,4-5) exta(1,2)]) unfolding exta by auto moreover
   633     have a:"a = a0" apply(rule ksimplex_fix_plane_p[OF assms(1-2,4-5) exta(1,2)]) unfolding exta by auto moreover
   634     guess b0 b1 apply(rule ksimplex_extrema_strong[OF goal1(1) assms(3)]) . note extb = this[rule_format]
   634     guess b0 b1 apply(rule ksimplex_extrema_strong[OF goal1(1) assms(3)]) . note extb = this[rule_format]
   635     have a':"a' = b0" apply(rule ksimplex_fix_plane_p[OF goal1(1-2) assms(4), of _ b1]) unfolding goal1 extb using extb(1,2) assms(5) by auto
   635     have a':"a' = b0" apply(rule ksimplex_fix_plane_p[OF goal1(1-2) assms(4), of _ b1]) unfolding goal1 extb using extb(1,2) assms(5) by auto
   636     moreover have *:"b1 = a1" unfolding kle_antisym[THEN sym, of b1 a1 n] using exta extb using goal1(3) unfolding a a' by blast moreover
   636     moreover have *:"b1 = a1" unfolding kle_antisym[THEN sym, of b1 a1 n] using exta extb using goal1(3) unfolding a a' by blast moreover
   637     have "a0 = b0" apply(rule ext) proof- case goal1 show "a0 x = b0 x"
   637     have "a0 = b0" apply(rule ext) proof- case goal1 show "a0 x = b0 x"
   638 	using *[THEN cong, of x x] unfolding exta extb apply-apply(cases "x\<in>{1..n}") by auto qed
   638         using *[THEN cong, of x x] unfolding exta extb apply-apply(cases "x\<in>{1..n}") by auto qed
   639     ultimately show "s' = s" apply-apply(rule lem[OF goal1(3) _ goal1(2) assms(2)]) by auto qed 
   639     ultimately show "s' = s" apply-apply(rule lem[OF goal1(3) _ goal1(2) assms(2)]) by auto qed 
   640   show ?thesis unfolding card_1_exists apply(rule ex1I[of _ s]) unfolding mem_Collect_eq apply(rule,rule assms(1))
   640   show ?thesis unfolding card_1_exists apply(rule ex1I[of _ s]) unfolding mem_Collect_eq apply(rule,rule assms(1))
   641     apply(rule_tac x=a in bexI) prefer 3 apply(erule conjE bexE)+ apply(rule_tac a'=b in lem) using assms(1-2) by auto qed
   641     apply(rule_tac x=a in bexI) prefer 3 apply(erule conjE bexE)+ apply(rule_tac a'=b in lem) using assms(1-2) by auto qed
   642 
   642 
   643 lemma ksimplex_replace_2:
   643 lemma ksimplex_replace_2:
   670     let ?s = "insert a3 (s - {a0})" have "ksimplex p n ?s" apply(rule ksimplexI) proof(rule_tac[2-] ballI,rule_tac[4] ballI)
   670     let ?s = "insert a3 (s - {a0})" have "ksimplex p n ?s" apply(rule ksimplexI) proof(rule_tac[2-] ballI,rule_tac[4] ballI)
   671       show "card ?s = n + 1" using ksimplexD(2-3)[OF assms(1)]
   671       show "card ?s = n + 1" using ksimplexD(2-3)[OF assms(1)]
   672         using `a3\<noteq>a0` `a3\<notin>s` `a0\<in>s` by(auto simp add:card_insert_if)
   672         using `a3\<noteq>a0` `a3\<notin>s` `a0\<in>s` by(auto simp add:card_insert_if)
   673       fix x assume x:"x \<in> insert a3 (s - {a0})"
   673       fix x assume x:"x \<in> insert a3 (s - {a0})"
   674       show "\<forall>j. x j \<le> p" proof(rule,cases "x = a3")
   674       show "\<forall>j. x j \<le> p" proof(rule,cases "x = a3")
   675 	fix j case False thus "x j\<le>p" using x ksimplexD(4)[OF assms(1)] by auto next
   675         fix j case False thus "x j\<le>p" using x ksimplexD(4)[OF assms(1)] by auto next
   676 	fix j case True show "x j\<le>p" unfolding True proof(cases "j=k") 
   676         fix j case True show "x j\<le>p" unfolding True proof(cases "j=k") 
   677 	  case False thus "a3 j \<le>p" unfolding True a3_def using `a1\<in>s` ksimplexD(4)[OF assms(1)] by auto next
   677           case False thus "a3 j \<le>p" unfolding True a3_def using `a1\<in>s` ksimplexD(4)[OF assms(1)] by auto next
   678 	  guess a4 using assms(5)[unfolded bex_simps ball_simps,rule_format,OF k(1)] .. note a4=this
   678           guess a4 using assms(5)[unfolded bex_simps ball_simps,rule_format,OF k(1)] .. note a4=this
   679 	  have "a2 k \<le> a4 k" using lem3[OF a4(1)[unfolded `a=a0`],THEN kle_imp_pointwise] by auto
   679           have "a2 k \<le> a4 k" using lem3[OF a4(1)[unfolded `a=a0`],THEN kle_imp_pointwise] by auto
   680 	  also have "\<dots> < p" using ksimplexD(4)[OF assms(1),rule_format,of a4 k] using a4 by auto
   680           also have "\<dots> < p" using ksimplexD(4)[OF assms(1),rule_format,of a4 k] using a4 by auto
   681 	  finally have *:"a0 k + 1 < p" unfolding k(2)[rule_format] by auto
   681           finally have *:"a0 k + 1 < p" unfolding k(2)[rule_format] by auto
   682 	  case True thus "a3 j \<le>p" unfolding a3_def unfolding a0a1(5)[rule_format]
   682           case True thus "a3 j \<le>p" unfolding a3_def unfolding a0a1(5)[rule_format]
   683 	    using k(1) k(2)assms(5) using * by simp qed qed
   683             using k(1) k(2)assms(5) using * by simp qed qed
   684       show "\<forall>j. j \<notin> {1..n} \<longrightarrow> x j = p" proof(rule,rule,cases "x=a3") fix j::nat assume j:"j\<notin>{1..n}"
   684       show "\<forall>j. j \<notin> {1..n} \<longrightarrow> x j = p" proof(rule,rule,cases "x=a3") fix j::nat assume j:"j\<notin>{1..n}"
   685 	{ case False thus "x j = p" using j x ksimplexD(5)[OF assms(1)] by auto }
   685         { case False thus "x j = p" using j x ksimplexD(5)[OF assms(1)] by auto }
   686 	case True show "x j = p" unfolding True a3_def using j k(1) 
   686         case True show "x j = p" unfolding True a3_def using j k(1) 
   687 	  using ksimplexD(5)[OF assms(1),rule_format,OF `a1\<in>s` j] by auto qed
   687           using ksimplexD(5)[OF assms(1),rule_format,OF `a1\<in>s` j] by auto qed
   688       fix y assume y:"y\<in>insert a3 (s - {a0})"
   688       fix y assume y:"y\<in>insert a3 (s - {a0})"
   689       have lem4:"\<And>x. x\<in>s \<Longrightarrow> x\<noteq>a0 \<Longrightarrow> kle n x a3" proof- case goal1
   689       have lem4:"\<And>x. x\<in>s \<Longrightarrow> x\<noteq>a0 \<Longrightarrow> kle n x a3" proof- case goal1
   690 	guess kk using a0a1(4)[rule_format,OF `x\<in>s`,THEN conjunct2,unfolded kle_def] 
   690         guess kk using a0a1(4)[rule_format,OF `x\<in>s`,THEN conjunct2,unfolded kle_def] 
   691           apply-apply(erule exE,erule conjE) . note kk=this
   691           apply-apply(erule exE,erule conjE) . note kk=this
   692 	have "k\<notin>kk" proof assume "k\<in>kk"
   692         have "k\<notin>kk" proof assume "k\<in>kk"
   693 	  hence "a1 k = x k + 1" using kk by auto
   693           hence "a1 k = x k + 1" using kk by auto
   694 	  hence "a0 k = x k" unfolding a0a1(5)[rule_format] using k(1) by auto
   694           hence "a0 k = x k" unfolding a0a1(5)[rule_format] using k(1) by auto
   695 	  hence "a2 k = x k + 1" unfolding k(2)[rule_format] by auto moreover
   695           hence "a2 k = x k + 1" unfolding k(2)[rule_format] by auto moreover
   696 	  have "a2 k \<le> x k" using lem3[of x,THEN kle_imp_pointwise] goal1 by auto 
   696           have "a2 k \<le> x k" using lem3[of x,THEN kle_imp_pointwise] goal1 by auto 
   697 	  ultimately show False by auto qed
   697           ultimately show False by auto qed
   698 	thus ?case unfolding kle_def apply(rule_tac x="insert k kk" in exI) using kk(1)
   698         thus ?case unfolding kle_def apply(rule_tac x="insert k kk" in exI) using kk(1)
   699 	  unfolding a3_def kle_def kk(2)[rule_format] using k(1) by auto qed
   699           unfolding a3_def kle_def kk(2)[rule_format] using k(1) by auto qed
   700       show "kle n x y \<or> kle n y x" proof(cases "y=a3")
   700       show "kle n x y \<or> kle n y x" proof(cases "y=a3")
   701 	case True show ?thesis unfolding True apply(cases "x=a3") defer apply(rule disjI1,rule lem4)
   701         case True show ?thesis unfolding True apply(cases "x=a3") defer apply(rule disjI1,rule lem4)
   702 	  using x by auto next
   702           using x by auto next
   703 	case False show ?thesis proof(cases "x=a3") case True show ?thesis unfolding True
   703         case False show ?thesis proof(cases "x=a3") case True show ?thesis unfolding True
   704 	    apply(rule disjI2,rule lem4) using y False by auto next
   704             apply(rule disjI2,rule lem4) using y False by auto next
   705 	  case False thus ?thesis apply(rule_tac ksimplexD(6)[OF assms(1),rule_format]) 
   705           case False thus ?thesis apply(rule_tac ksimplexD(6)[OF assms(1),rule_format]) 
   706 	    using x y `y\<noteq>a3` by auto qed qed qed
   706             using x y `y\<noteq>a3` by auto qed qed qed
   707     hence "insert a3 (s - {a0}) \<in> ?A" unfolding mem_Collect_eq apply-apply(rule,assumption)
   707     hence "insert a3 (s - {a0}) \<in> ?A" unfolding mem_Collect_eq apply-apply(rule,assumption)
   708       apply(rule_tac x="a3" in bexI) unfolding `a=a0` using `a3\<notin>s` by auto moreover
   708       apply(rule_tac x="a3" in bexI) unfolding `a=a0` using `a3\<notin>s` by auto moreover
   709     have "s \<in> ?A" using assms(1,2) by auto ultimately have  "?A \<supseteq> {s, insert a3 (s - {a0})}" by auto
   709     have "s \<in> ?A" using assms(1,2) by auto ultimately have  "?A \<supseteq> {s, insert a3 (s - {a0})}" by auto
   710     moreover have "?A \<subseteq> {s, insert a3 (s - {a0})}" apply(rule) unfolding mem_Collect_eq proof(erule conjE)
   710     moreover have "?A \<subseteq> {s, insert a3 (s - {a0})}" apply(rule) unfolding mem_Collect_eq proof(erule conjE)
   711       fix s' assume as:"ksimplex p n s'" and "\<exists>b\<in>s'. s' - {b} = s - {a}"
   711       fix s' assume as:"ksimplex p n s'" and "\<exists>b\<in>s'. s' - {b} = s - {a}"
   712       from this(2) guess a' .. note a'=this
   712       from this(2) guess a' .. note a'=this
   713       guess a_min a_max apply(rule ksimplex_extrema_strong[OF as assms(3)]) . note min_max=this
   713       guess a_min a_max apply(rule ksimplex_extrema_strong[OF as assms(3)]) . note min_max=this
   714       have *:"\<forall>x\<in>s' - {a'}. x k = a2 k" unfolding a' proof fix x assume x:"x\<in>s-{a}"
   714       have *:"\<forall>x\<in>s' - {a'}. x k = a2 k" unfolding a' proof fix x assume x:"x\<in>s-{a}"
   715 	hence "kle n a2 x" apply-apply(rule lem3) using `a=a0` by auto
   715         hence "kle n a2 x" apply-apply(rule lem3) using `a=a0` by auto
   716 	hence "a2 k \<le> x k" apply(drule_tac kle_imp_pointwise) by auto moreover
   716         hence "a2 k \<le> x k" apply(drule_tac kle_imp_pointwise) by auto moreover
   717 	have "x k \<le> a2 k" unfolding k(2)[rule_format] using a0a1(4)[rule_format,of x,THEN conjunct1] 
   717         have "x k \<le> a2 k" unfolding k(2)[rule_format] using a0a1(4)[rule_format,of x,THEN conjunct1] 
   718 	  unfolding kle_def using x by auto ultimately show "x k = a2 k" by auto qed
   718           unfolding kle_def using x by auto ultimately show "x k = a2 k" by auto qed
   719       have **:"a'=a_min \<or> a'=a_max" apply(rule ksimplex_fix_plane[OF a'(1) k(1) *]) using min_max by auto
   719       have **:"a'=a_min \<or> a'=a_max" apply(rule ksimplex_fix_plane[OF a'(1) k(1) *]) using min_max by auto
   720       show "s' \<in> {s, insert a3 (s - {a0})}" proof(cases "a'=a_min")
   720       show "s' \<in> {s, insert a3 (s - {a0})}" proof(cases "a'=a_min")
   721 	case True have "a_max = a1" unfolding kle_antisym[THEN sym,of a_max a1 n] apply(rule)
   721         case True have "a_max = a1" unfolding kle_antisym[THEN sym,of a_max a1 n] apply(rule)
   722 	  apply(rule a0a1(4)[rule_format,THEN conjunct2]) defer  proof(rule min_max(4)[rule_format,THEN conjunct2])
   722           apply(rule a0a1(4)[rule_format,THEN conjunct2]) defer  proof(rule min_max(4)[rule_format,THEN conjunct2])
   723 	  show "a1\<in>s'" using a' unfolding `a=a0` using a0a1 by auto
   723           show "a1\<in>s'" using a' unfolding `a=a0` using a0a1 by auto
   724 	  show "a_max \<in> s" proof(rule ccontr) assume "a_max\<notin>s"
   724           show "a_max \<in> s" proof(rule ccontr) assume "a_max\<notin>s"
   725 	    hence "a_max = a'" using a' min_max by auto
   725             hence "a_max = a'" using a' min_max by auto
   726 	    thus False unfolding True using min_max by auto qed qed
   726             thus False unfolding True using min_max by auto qed qed
   727 	hence "\<forall>i. a_max i = a1 i" by auto
   727         hence "\<forall>i. a_max i = a1 i" by auto
   728 	hence "a' = a" unfolding True `a=a0` apply-apply(subst fun_eq_iff,rule)
   728         hence "a' = a" unfolding True `a=a0` apply-apply(subst fun_eq_iff,rule)
   729 	  apply(erule_tac x=x in allE) unfolding a0a1(5)[rule_format] min_max(5)[rule_format]
   729           apply(erule_tac x=x in allE) unfolding a0a1(5)[rule_format] min_max(5)[rule_format]
   730 	proof- case goal1 thus ?case apply(cases "x\<in>{1..n}") by auto qed
   730         proof- case goal1 thus ?case apply(cases "x\<in>{1..n}") by auto qed
   731 	hence "s' = s" apply-apply(rule lem1[OF a'(2)]) using `a\<in>s` `a'\<in>s'` by auto
   731         hence "s' = s" apply-apply(rule lem1[OF a'(2)]) using `a\<in>s` `a'\<in>s'` by auto
   732 	thus ?thesis by auto next
   732         thus ?thesis by auto next
   733 	case False hence as:"a' = a_max" using ** by auto
   733         case False hence as:"a' = a_max" using ** by auto
   734 	have "a_min = a2" unfolding kle_antisym[THEN sym, of _ _ n] apply rule
   734         have "a_min = a2" unfolding kle_antisym[THEN sym, of _ _ n] apply rule
   735 	  apply(rule min_max(4)[rule_format,THEN conjunct1]) defer proof(rule lem3)
   735           apply(rule min_max(4)[rule_format,THEN conjunct1]) defer proof(rule lem3)
   736 	  show "a_min \<in> s - {a0}" unfolding a'(2)[THEN sym,unfolded `a=a0`] 
   736           show "a_min \<in> s - {a0}" unfolding a'(2)[THEN sym,unfolded `a=a0`] 
   737 	    unfolding as using min_max(1-3) by auto
   737             unfolding as using min_max(1-3) by auto
   738 	  have "a2 \<noteq> a" unfolding `a=a0` using k(2)[rule_format,of k] by auto
   738           have "a2 \<noteq> a" unfolding `a=a0` using k(2)[rule_format,of k] by auto
   739 	  hence "a2 \<in> s - {a}" using a2 by auto thus "a2 \<in> s'" unfolding a'(2)[THEN sym] by auto qed
   739           hence "a2 \<in> s - {a}" using a2 by auto thus "a2 \<in> s'" unfolding a'(2)[THEN sym] by auto qed
   740 	hence "\<forall>i. a_min i = a2 i" by auto
   740         hence "\<forall>i. a_min i = a2 i" by auto
   741 	hence "a' = a3" unfolding as `a=a0` apply-apply(subst fun_eq_iff,rule)
   741         hence "a' = a3" unfolding as `a=a0` apply-apply(subst fun_eq_iff,rule)
   742 	  apply(erule_tac x=x in allE) unfolding a0a1(5)[rule_format] min_max(5)[rule_format]
   742           apply(erule_tac x=x in allE) unfolding a0a1(5)[rule_format] min_max(5)[rule_format]
   743 	  unfolding a3_def k(2)[rule_format] unfolding a0a1(5)[rule_format] proof- case goal1
   743           unfolding a3_def k(2)[rule_format] unfolding a0a1(5)[rule_format] proof- case goal1
   744 	  show ?case unfolding goal1 apply(cases "x\<in>{1..n}") defer apply(cases "x=k")
   744           show ?case unfolding goal1 apply(cases "x\<in>{1..n}") defer apply(cases "x=k")
   745 	    using `k\<in>{1..n}` by auto qed
   745             using `k\<in>{1..n}` by auto qed
   746 	hence "s' = insert a3 (s - {a0})" apply-apply(rule lem1) defer apply assumption
   746         hence "s' = insert a3 (s - {a0})" apply-apply(rule lem1) defer apply assumption
   747 	  apply(rule a'(1)) unfolding a' `a=a0` using `a3\<notin>s` by auto
   747           apply(rule a'(1)) unfolding a' `a=a0` using `a3\<notin>s` by auto
   748 	thus ?thesis by auto qed qed
   748         thus ?thesis by auto qed qed
   749     ultimately have *:"?A = {s, insert a3 (s - {a0})}" by blast
   749     ultimately have *:"?A = {s, insert a3 (s - {a0})}" by blast
   750     have "s \<noteq> insert a3 (s - {a0})" using `a3\<notin>s` by auto
   750     have "s \<noteq> insert a3 (s - {a0})" using `a3\<notin>s` by auto
   751     hence ?thesis unfolding * by auto } moreover
   751     hence ?thesis unfolding * by auto } moreover
   752   { assume "a=a1"
   752   { assume "a=a1"
   753     have *:"\<And>P Q. (P \<or> Q) \<Longrightarrow> \<not> P \<Longrightarrow> Q" by auto
   753     have *:"\<And>P Q. (P \<or> Q) \<Longrightarrow> \<not> P \<Longrightarrow> Q" by auto
   778     let ?s = "insert a3 (s - {a1})" have "ksimplex p n ?s" apply(rule ksimplexI) proof(rule_tac[2-] ballI,rule_tac[4] ballI)
   778     let ?s = "insert a3 (s - {a1})" have "ksimplex p n ?s" apply(rule ksimplexI) proof(rule_tac[2-] ballI,rule_tac[4] ballI)
   779       show "card ?s = n+1" using ksimplexD(2-3)[OF assms(1)]
   779       show "card ?s = n+1" using ksimplexD(2-3)[OF assms(1)]
   780         using `a3\<noteq>a0` `a3\<notin>s` `a1\<in>s` by(auto simp add:card_insert_if)
   780         using `a3\<noteq>a0` `a3\<notin>s` `a1\<in>s` by(auto simp add:card_insert_if)
   781       fix x assume x:"x \<in> insert a3 (s - {a1})"
   781       fix x assume x:"x \<in> insert a3 (s - {a1})"
   782       show "\<forall>j. x j \<le> p" proof(rule,cases "x = a3")
   782       show "\<forall>j. x j \<le> p" proof(rule,cases "x = a3")
   783 	fix j case False thus "x j\<le>p" using x ksimplexD(4)[OF assms(1)] by auto next
   783         fix j case False thus "x j\<le>p" using x ksimplexD(4)[OF assms(1)] by auto next
   784 	fix j case True show "x j\<le>p" unfolding True proof(cases "j=k") 
   784         fix j case True show "x j\<le>p" unfolding True proof(cases "j=k") 
   785 	  case False thus "a3 j \<le>p" unfolding True a3_def using `a0\<in>s` ksimplexD(4)[OF assms(1)] by auto next
   785           case False thus "a3 j \<le>p" unfolding True a3_def using `a0\<in>s` ksimplexD(4)[OF assms(1)] by auto next
   786 	  guess a4 using assms(5)[unfolded bex_simps ball_simps,rule_format,OF k(1)] .. note a4=this
   786           guess a4 using assms(5)[unfolded bex_simps ball_simps,rule_format,OF k(1)] .. note a4=this
   787           case True have "a3 k \<le> a0 k" unfolding lem4[rule_format] by auto
   787           case True have "a3 k \<le> a0 k" unfolding lem4[rule_format] by auto
   788           also have "\<dots> \<le> p" using ksimplexD(4)[OF assms(1),rule_format,of a0 k] a0a1 by auto
   788           also have "\<dots> \<le> p" using ksimplexD(4)[OF assms(1),rule_format,of a0 k] a0a1 by auto
   789           finally show "a3 j \<le> p" unfolding True by auto qed qed
   789           finally show "a3 j \<le> p" unfolding True by auto qed qed
   790       show "\<forall>j. j \<notin> {1..n} \<longrightarrow> x j = p" proof(rule,rule,cases "x=a3") fix j::nat assume j:"j\<notin>{1..n}"
   790       show "\<forall>j. j \<notin> {1..n} \<longrightarrow> x j = p" proof(rule,rule,cases "x=a3") fix j::nat assume j:"j\<notin>{1..n}"
   791 	{ case False thus "x j = p" using j x ksimplexD(5)[OF assms(1)] by auto }
   791         { case False thus "x j = p" using j x ksimplexD(5)[OF assms(1)] by auto }
   792 	case True show "x j = p" unfolding True a3_def using j k(1) 
   792         case True show "x j = p" unfolding True a3_def using j k(1) 
   793 	  using ksimplexD(5)[OF assms(1),rule_format,OF `a0\<in>s` j] by auto qed
   793           using ksimplexD(5)[OF assms(1),rule_format,OF `a0\<in>s` j] by auto qed
   794       fix y assume y:"y\<in>insert a3 (s - {a1})"
   794       fix y assume y:"y\<in>insert a3 (s - {a1})"
   795       have lem4:"\<And>x. x\<in>s \<Longrightarrow> x\<noteq>a1 \<Longrightarrow> kle n a3 x" proof- case goal1 hence *:"x\<in>s - {a1}" by auto
   795       have lem4:"\<And>x. x\<in>s \<Longrightarrow> x\<noteq>a1 \<Longrightarrow> kle n a3 x" proof- case goal1 hence *:"x\<in>s - {a1}" by auto
   796         have "kle n a3 a2" proof- have "kle n a0 a1" using a0a1 by auto then guess kk unfolding kle_def ..
   796         have "kle n a3 a2" proof- have "kle n a0 a1" using a0a1 by auto then guess kk unfolding kle_def ..
   797           thus ?thesis unfolding kle_def apply(rule_tac x=kk in exI) unfolding lem4[rule_format] k(2)[rule_format]
   797           thus ?thesis unfolding kle_def apply(rule_tac x=kk in exI) unfolding lem4[rule_format] k(2)[rule_format]
   798             apply(rule)defer proof(rule) case goal1 thus ?case apply-apply(erule conjE)
   798             apply(rule)defer proof(rule) case goal1 thus ?case apply-apply(erule conjE)
   799               apply(erule_tac[!] x=j in allE) apply(cases "j\<in>kk") apply(case_tac[!] "j=k") by auto qed auto qed moreover
   799               apply(erule_tac[!] x=j in allE) apply(cases "j\<in>kk") apply(case_tac[!] "j=k") by auto qed auto qed moreover
   800         have "kle n a3 a0" unfolding kle_def lem4[rule_format] apply(rule_tac x="{k}" in exI) using k(1) by auto
   800         have "kle n a3 a0" unfolding kle_def lem4[rule_format] apply(rule_tac x="{k}" in exI) using k(1) by auto
   801         ultimately show ?case apply-apply(rule kle_between_l[of _ a0 _ a2]) using lem3[OF *]
   801         ultimately show ?case apply-apply(rule kle_between_l[of _ a0 _ a2]) using lem3[OF *]
   802           using a0a1(4)[rule_format,OF goal1(1)] by auto qed
   802           using a0a1(4)[rule_format,OF goal1(1)] by auto qed
   803       show "kle n x y \<or> kle n y x" proof(cases "y=a3")
   803       show "kle n x y \<or> kle n y x" proof(cases "y=a3")
   804 	case True show ?thesis unfolding True apply(cases "x=a3") defer apply(rule disjI2,rule lem4)
   804         case True show ?thesis unfolding True apply(cases "x=a3") defer apply(rule disjI2,rule lem4)
   805 	  using x by auto next
   805           using x by auto next
   806 	case False show ?thesis proof(cases "x=a3") case True show ?thesis unfolding True
   806         case False show ?thesis proof(cases "x=a3") case True show ?thesis unfolding True
   807 	    apply(rule disjI1,rule lem4) using y False by auto next
   807             apply(rule disjI1,rule lem4) using y False by auto next
   808 	  case False thus ?thesis apply(rule_tac ksimplexD(6)[OF assms(1),rule_format]) 
   808           case False thus ?thesis apply(rule_tac ksimplexD(6)[OF assms(1),rule_format]) 
   809 	    using x y `y\<noteq>a3` by auto qed qed qed
   809             using x y `y\<noteq>a3` by auto qed qed qed
   810     hence "insert a3 (s - {a1}) \<in> ?A" unfolding mem_Collect_eq apply-apply(rule,assumption)
   810     hence "insert a3 (s - {a1}) \<in> ?A" unfolding mem_Collect_eq apply-apply(rule,assumption)
   811       apply(rule_tac x="a3" in bexI) unfolding `a=a1` using `a3\<notin>s` by auto moreover
   811       apply(rule_tac x="a3" in bexI) unfolding `a=a1` using `a3\<notin>s` by auto moreover
   812     have "s \<in> ?A" using assms(1,2) by auto ultimately have  "?A \<supseteq> {s, insert a3 (s - {a1})}" by auto
   812     have "s \<in> ?A" using assms(1,2) by auto ultimately have  "?A \<supseteq> {s, insert a3 (s - {a1})}" by auto
   813     moreover have "?A \<subseteq> {s, insert a3 (s - {a1})}" apply(rule) unfolding mem_Collect_eq proof(erule conjE)
   813     moreover have "?A \<subseteq> {s, insert a3 (s - {a1})}" apply(rule) unfolding mem_Collect_eq proof(erule conjE)
   814       fix s' assume as:"ksimplex p n s'" and "\<exists>b\<in>s'. s' - {b} = s - {a}"
   814       fix s' assume as:"ksimplex p n s'" and "\<exists>b\<in>s'. s' - {b} = s - {a}"
   815       from this(2) guess a' .. note a'=this
   815       from this(2) guess a' .. note a'=this
   816       guess a_min a_max apply(rule ksimplex_extrema_strong[OF as assms(3)]) . note min_max=this
   816       guess a_min a_max apply(rule ksimplex_extrema_strong[OF as assms(3)]) . note min_max=this
   817       have *:"\<forall>x\<in>s' - {a'}. x k = a2 k" unfolding a' proof fix x assume x:"x\<in>s-{a}"
   817       have *:"\<forall>x\<in>s' - {a'}. x k = a2 k" unfolding a' proof fix x assume x:"x\<in>s-{a}"
   818 	hence "kle n x a2" apply-apply(rule lem3) using `a=a1` by auto
   818         hence "kle n x a2" apply-apply(rule lem3) using `a=a1` by auto
   819 	hence "x k \<le> a2 k" apply(drule_tac kle_imp_pointwise) by auto moreover
   819         hence "x k \<le> a2 k" apply(drule_tac kle_imp_pointwise) by auto moreover
   820 	{ have "a2 k \<le> a0 k" using k(2)[rule_format,of k] unfolding a0a1(5)[rule_format] using k(1) by simp
   820         { have "a2 k \<le> a0 k" using k(2)[rule_format,of k] unfolding a0a1(5)[rule_format] using k(1) by simp
   821 	  also have "\<dots> \<le> x k" using a0a1(4)[rule_format,of x,THEN conjunct1,THEN kle_imp_pointwise] x by auto
   821           also have "\<dots> \<le> x k" using a0a1(4)[rule_format,of x,THEN conjunct1,THEN kle_imp_pointwise] x by auto
   822 	  finally have "a2 k \<le> x k" . } ultimately show "x k = a2 k" by auto qed
   822           finally have "a2 k \<le> x k" . } ultimately show "x k = a2 k" by auto qed
   823       have **:"a'=a_min \<or> a'=a_max" apply(rule ksimplex_fix_plane[OF a'(1) k(1) *]) using min_max by auto
   823       have **:"a'=a_min \<or> a'=a_max" apply(rule ksimplex_fix_plane[OF a'(1) k(1) *]) using min_max by auto
   824       have "a2 \<noteq> a1" proof assume as:"a2 = a1"
   824       have "a2 \<noteq> a1" proof assume as:"a2 = a1"
   825 	show False using k(2) unfolding as apply(erule_tac x=k in allE) by auto qed
   825         show False using k(2) unfolding as apply(erule_tac x=k in allE) by auto qed
   826       hence a2':"a2 \<in> s' - {a'}" unfolding a' using a2 unfolding `a=a1` by auto
   826       hence a2':"a2 \<in> s' - {a'}" unfolding a' using a2 unfolding `a=a1` by auto
   827       show "s' \<in> {s, insert a3 (s - {a1})}" proof(cases "a'=a_min")
   827       show "s' \<in> {s, insert a3 (s - {a1})}" proof(cases "a'=a_min")
   828 	case True have "a_max \<in> s - {a1}" using min_max unfolding a'(2)[unfolded `a=a1`,THEN sym] True by auto
   828         case True have "a_max \<in> s - {a1}" using min_max unfolding a'(2)[unfolded `a=a1`,THEN sym] True by auto
   829 	hence "a_max = a2" unfolding kle_antisym[THEN sym,of a_max a2 n] apply-apply(rule)
   829         hence "a_max = a2" unfolding kle_antisym[THEN sym,of a_max a2 n] apply-apply(rule)
   830 	  apply(rule lem3,assumption) apply(rule min_max(4)[rule_format,THEN conjunct2]) using a2' by auto
   830           apply(rule lem3,assumption) apply(rule min_max(4)[rule_format,THEN conjunct2]) using a2' by auto
   831 	hence a_max:"\<forall>i. a_max i = a2 i" by auto
   831         hence a_max:"\<forall>i. a_max i = a2 i" by auto
   832 	have *:"\<forall>j. a2 j = (if j\<in>{1..n} then a3 j + 1 else a3 j)" 
   832         have *:"\<forall>j. a2 j = (if j\<in>{1..n} then a3 j + 1 else a3 j)" 
   833 	  using k(2) unfolding lem4[rule_format] a0a1(5)[rule_format] apply-apply(rule,erule_tac x=j in allE)
   833           using k(2) unfolding lem4[rule_format] a0a1(5)[rule_format] apply-apply(rule,erule_tac x=j in allE)
   834 	proof- case goal1 thus ?case apply(cases "j\<in>{1..n}",case_tac[!] "j=k") by auto qed
   834         proof- case goal1 thus ?case apply(cases "j\<in>{1..n}",case_tac[!] "j=k") by auto qed
   835 	have "\<forall>i. a_min i = a3 i" using a_max apply-apply(rule,erule_tac x=i in allE)
   835         have "\<forall>i. a_min i = a3 i" using a_max apply-apply(rule,erule_tac x=i in allE)
   836 	  unfolding min_max(5)[rule_format] *[rule_format] proof- case goal1
   836           unfolding min_max(5)[rule_format] *[rule_format] proof- case goal1
   837 	  thus ?case apply(cases "i\<in>{1..n}") by auto qed hence "a_min = a3" unfolding fun_eq_iff .
   837           thus ?case apply(cases "i\<in>{1..n}") by auto qed hence "a_min = a3" unfolding fun_eq_iff .
   838 	hence "s' = insert a3 (s - {a1})" using a' unfolding `a=a1` True by auto thus ?thesis by auto next
   838         hence "s' = insert a3 (s - {a1})" using a' unfolding `a=a1` True by auto thus ?thesis by auto next
   839 	case False hence as:"a'=a_max" using ** by auto
   839         case False hence as:"a'=a_max" using ** by auto
   840 	have "a_min = a0" unfolding kle_antisym[THEN sym,of _ _ n] apply(rule)
   840         have "a_min = a0" unfolding kle_antisym[THEN sym,of _ _ n] apply(rule)
   841 	  apply(rule min_max(4)[rule_format,THEN conjunct1]) defer apply(rule a0a1(4)[rule_format,THEN conjunct1]) proof-
   841           apply(rule min_max(4)[rule_format,THEN conjunct1]) defer apply(rule a0a1(4)[rule_format,THEN conjunct1]) proof-
   842 	  have "a_min \<in> s - {a1}" using min_max(1,3) unfolding a'(2)[THEN sym,unfolded `a=a1`] as by auto
   842           have "a_min \<in> s - {a1}" using min_max(1,3) unfolding a'(2)[THEN sym,unfolded `a=a1`] as by auto
   843 	  thus "a_min \<in> s" by auto have "a0 \<in> s - {a1}" using a0a1(1-3) by auto thus "a0 \<in> s'"
   843           thus "a_min \<in> s" by auto have "a0 \<in> s - {a1}" using a0a1(1-3) by auto thus "a0 \<in> s'"
   844 	    unfolding a'(2)[THEN sym,unfolded `a=a1`] by auto qed
   844             unfolding a'(2)[THEN sym,unfolded `a=a1`] by auto qed
   845 	hence "\<forall>i. a_max i = a1 i" unfolding a0a1(5)[rule_format] min_max(5)[rule_format] by auto
   845         hence "\<forall>i. a_max i = a1 i" unfolding a0a1(5)[rule_format] min_max(5)[rule_format] by auto
   846 	hence "s' = s" apply-apply(rule lem1[OF a'(2)]) using `a\<in>s` `a'\<in>s'` unfolding as `a=a1` unfolding fun_eq_iff by auto
   846         hence "s' = s" apply-apply(rule lem1[OF a'(2)]) using `a\<in>s` `a'\<in>s'` unfolding as `a=a1` unfolding fun_eq_iff by auto
   847 	thus ?thesis by auto qed qed 
   847         thus ?thesis by auto qed qed 
   848     ultimately have *:"?A = {s, insert a3 (s - {a1})}" by blast
   848     ultimately have *:"?A = {s, insert a3 (s - {a1})}" by blast
   849     have "s \<noteq> insert a3 (s - {a1})" using `a3\<notin>s` by auto
   849     have "s \<noteq> insert a3 (s - {a1})" using `a3\<notin>s` by auto
   850     hence ?thesis unfolding * by auto } moreover
   850     hence ?thesis unfolding * by auto } moreover
   851   { assume as:"a\<noteq>a0" "a\<noteq>a1" have "\<not> (\<forall>x\<in>s. kle n a x)" proof case goal1
   851   { assume as:"a\<noteq>a0" "a\<noteq>a1" have "\<not> (\<forall>x\<in>s. kle n a x)" proof case goal1
   852       have "a=a0" unfolding kle_antisym[THEN sym,of _ _ n] apply(rule)
   852       have "a=a0" unfolding kle_antisym[THEN sym,of _ _ n] apply(rule)
   853 	using goal1 a0a1 assms(2) by auto thus False using as by auto qed
   853         using goal1 a0a1 assms(2) by auto thus False using as by auto qed
   854     hence "\<exists>y\<in>s. \<exists>k\<in>{1..n}. \<forall>j. a j = (if j = k then y j + 1 else y j)" using  ksimplex_predecessor[OF assms(1-2)] by blast
   854     hence "\<exists>y\<in>s. \<exists>k\<in>{1..n}. \<forall>j. a j = (if j = k then y j + 1 else y j)" using  ksimplex_predecessor[OF assms(1-2)] by blast
   855     then guess u .. from this(2) guess k .. note k = this[rule_format] note u = `u\<in>s`
   855     then guess u .. from this(2) guess k .. note k = this[rule_format] note u = `u\<in>s`
   856     have "\<not> (\<forall>x\<in>s. kle n x a)" proof case goal1
   856     have "\<not> (\<forall>x\<in>s. kle n x a)" proof case goal1
   857       have "a=a1" unfolding kle_antisym[THEN sym,of _ _ n] apply(rule)
   857       have "a=a1" unfolding kle_antisym[THEN sym,of _ _ n] apply(rule)
   858 	using goal1 a0a1 assms(2) by auto thus False using as by auto qed
   858         using goal1 a0a1 assms(2) by auto thus False using as by auto qed
   859     hence "\<exists>y\<in>s. \<exists>k\<in>{1..n}. \<forall>j. y j = (if j = k then a j + 1 else a j)" using  ksimplex_successor[OF assms(1-2)] by blast
   859     hence "\<exists>y\<in>s. \<exists>k\<in>{1..n}. \<forall>j. y j = (if j = k then a j + 1 else a j)" using  ksimplex_successor[OF assms(1-2)] by blast
   860     then guess v .. from this(2) guess l .. note l = this[rule_format] note v = `v\<in>s`
   860     then guess v .. from this(2) guess l .. note l = this[rule_format] note v = `v\<in>s`
   861     def a' \<equiv> "\<lambda>j. if j = l then u j + 1 else u j"
   861     def a' \<equiv> "\<lambda>j. if j = l then u j + 1 else u j"
   862     have kl:"k \<noteq> l" proof assume "k=l" have *:"\<And>P. (if P then (1::nat) else 0) \<noteq> 2" by auto
   862     have kl:"k \<noteq> l" proof assume "k=l" have *:"\<And>P. (if P then (1::nat) else 0) \<noteq> 2" by auto
   863       thus False using ksimplexD(6)[OF assms(1),rule_format,OF u v] unfolding kle_def
   863       thus False using ksimplexD(6)[OF assms(1),rule_format,OF u v] unfolding kle_def
   864 	unfolding l(2) k(2) `k=l` apply-apply(erule disjE)apply(erule_tac[!] exE conjE)+
   864         unfolding l(2) k(2) `k=l` apply-apply(erule disjE)apply(erule_tac[!] exE conjE)+
   865 	apply(erule_tac[!] x=l in allE)+ by(auto simp add: *) qed
   865         apply(erule_tac[!] x=l in allE)+ by(auto simp add: *) qed
   866     hence aa':"a'\<noteq>a" apply-apply rule unfolding fun_eq_iff unfolding a'_def k(2)
   866     hence aa':"a'\<noteq>a" apply-apply rule unfolding fun_eq_iff unfolding a'_def k(2)
   867       apply(erule_tac x=l in allE) by auto
   867       apply(erule_tac x=l in allE) by auto
   868     have "a' \<notin> s" apply(rule) apply(drule ksimplexD(6)[OF assms(1),rule_format,OF `a\<in>s`]) proof(cases "kle n a a'")
   868     have "a' \<notin> s" apply(rule) apply(drule ksimplexD(6)[OF assms(1),rule_format,OF `a\<in>s`]) proof(cases "kle n a a'")
   869       case goal2 hence "kle n a' a" by auto thus False apply(drule_tac kle_imp_pointwise)
   869       case goal2 hence "kle n a' a" by auto thus False apply(drule_tac kle_imp_pointwise)
   870 	apply(erule_tac x=l in allE) unfolding a'_def k(2) using kl by auto next
   870         apply(erule_tac x=l in allE) unfolding a'_def k(2) using kl by auto next
   871       case True thus False apply(drule_tac kle_imp_pointwise)
   871       case True thus False apply(drule_tac kle_imp_pointwise)
   872 	apply(erule_tac x=k in allE) unfolding a'_def k(2) using kl by auto qed
   872         apply(erule_tac x=k in allE) unfolding a'_def k(2) using kl by auto qed
   873     have kle_uv:"kle n u a" "kle n u a'" "kle n a v" "kle n a' v" unfolding kle_def apply-
   873     have kle_uv:"kle n u a" "kle n u a'" "kle n a v" "kle n a' v" unfolding kle_def apply-
   874       apply(rule_tac[1] x="{k}" in exI,rule_tac[2] x="{l}" in exI)
   874       apply(rule_tac[1] x="{k}" in exI,rule_tac[2] x="{l}" in exI)
   875       apply(rule_tac[3] x="{l}" in exI,rule_tac[4] x="{k}" in exI)
   875       apply(rule_tac[3] x="{l}" in exI,rule_tac[4] x="{k}" in exI)
   876       unfolding l(2) k(2) a'_def using l(1) k(1) by auto
   876       unfolding l(2) k(2) a'_def using l(1) k(1) by auto
   877     have uxv:"\<And>x. kle n u x \<Longrightarrow> kle n x v \<Longrightarrow> (x = u) \<or> (x = a) \<or> (x = a') \<or> (x = v)"
   877     have uxv:"\<And>x. kle n u x \<Longrightarrow> kle n x v \<Longrightarrow> (x = u) \<or> (x = a) \<or> (x = a') \<or> (x = v)"
   878     proof- case goal1 thus ?case proof(cases "x k = u k", case_tac[!] "x l = u l")
   878     proof- case goal1 thus ?case proof(cases "x k = u k", case_tac[!] "x l = u l")
   879       assume as:"x l = u l" "x k = u k"
   879       assume as:"x l = u l" "x k = u k"
   880       have "x = u" unfolding fun_eq_iff
   880       have "x = u" unfolding fun_eq_iff
   881 	using goal1(2)[THEN kle_imp_pointwise,unfolded l(2)] unfolding k(2) apply-
   881         using goal1(2)[THEN kle_imp_pointwise,unfolded l(2)] unfolding k(2) apply-
   882 	using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1
   882         using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1
   883 	thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as by auto qed thus ?case by auto next
   883         thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as by auto qed thus ?case by auto next
   884       assume as:"x l \<noteq> u l" "x k = u k"
   884       assume as:"x l \<noteq> u l" "x k = u k"
   885       have "x = a'" unfolding fun_eq_iff unfolding a'_def
   885       have "x = a'" unfolding fun_eq_iff unfolding a'_def
   886 	using goal1(2)[THEN kle_imp_pointwise] unfolding l(2) k(2) apply-
   886         using goal1(2)[THEN kle_imp_pointwise] unfolding l(2) k(2) apply-
   887 	using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1
   887         using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1
   888 	thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as by auto qed thus ?case by auto next
   888         thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as by auto qed thus ?case by auto next
   889       assume as:"x l = u l" "x k \<noteq> u k"
   889       assume as:"x l = u l" "x k \<noteq> u k"
   890       have "x = a" unfolding fun_eq_iff
   890       have "x = a" unfolding fun_eq_iff
   891 	using goal1(2)[THEN kle_imp_pointwise] unfolding l(2) k(2) apply-
   891         using goal1(2)[THEN kle_imp_pointwise] unfolding l(2) k(2) apply-
   892 	using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1
   892         using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1
   893 	thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as by auto qed thus ?case by auto next
   893         thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as by auto qed thus ?case by auto next
   894       assume as:"x l \<noteq> u l" "x k \<noteq> u k"
   894       assume as:"x l \<noteq> u l" "x k \<noteq> u k"
   895       have "x = v" unfolding fun_eq_iff
   895       have "x = v" unfolding fun_eq_iff
   896 	using goal1(2)[THEN kle_imp_pointwise] unfolding l(2) k(2) apply-
   896         using goal1(2)[THEN kle_imp_pointwise] unfolding l(2) k(2) apply-
   897 	using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1
   897         using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1
   898 	thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as `k\<noteq>l` by auto qed thus ?case by auto qed qed
   898         thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as `k\<noteq>l` by auto qed thus ?case by auto qed qed
   899     have uv:"kle n u v" apply(rule kle_trans[OF kle_uv(1,3)]) using ksimplexD(6)[OF assms(1)] using u v by auto
   899     have uv:"kle n u v" apply(rule kle_trans[OF kle_uv(1,3)]) using ksimplexD(6)[OF assms(1)] using u v by auto
   900     have lem3:"\<And>x. x\<in>s \<Longrightarrow> kle n v x \<Longrightarrow> kle n a' x" apply(rule kle_between_r[of _ u _ v])
   900     have lem3:"\<And>x. x\<in>s \<Longrightarrow> kle n v x \<Longrightarrow> kle n a' x" apply(rule kle_between_r[of _ u _ v])
   901       prefer 3 apply(rule kle_trans[OF uv]) defer apply(rule ksimplexD(6)[OF assms(1),rule_format])
   901       prefer 3 apply(rule kle_trans[OF uv]) defer apply(rule ksimplexD(6)[OF assms(1),rule_format])
   902       using kle_uv `u\<in>s` by auto
   902       using kle_uv `u\<in>s` by auto
   903     have lem4:"\<And>x. x\<in>s \<Longrightarrow> kle n x u \<Longrightarrow> kle n x a'" apply(rule kle_between_l[of _ u _ v])
   903     have lem4:"\<And>x. x\<in>s \<Longrightarrow> kle n x u \<Longrightarrow> kle n x a'" apply(rule kle_between_l[of _ u _ v])
   904       prefer 4 apply(rule kle_trans[OF _ uv]) defer apply(rule ksimplexD(6)[OF assms(1),rule_format])
   904       prefer 4 apply(rule kle_trans[OF _ uv]) defer apply(rule ksimplexD(6)[OF assms(1),rule_format])
   905       using kle_uv `v\<in>s` by auto
   905       using kle_uv `v\<in>s` by auto
   906     have lem5:"\<And>x. x\<in>s \<Longrightarrow> x\<noteq>a \<Longrightarrow> kle n x a' \<or> kle n a' x" proof- case goal1 thus ?case
   906     have lem5:"\<And>x. x\<in>s \<Longrightarrow> x\<noteq>a \<Longrightarrow> kle n x a' \<or> kle n a' x" proof- case goal1 thus ?case
   907       proof(cases "kle n v x \<or> kle n x u") case True thus ?thesis using goal1 by(auto intro:lem3 lem4) next
   907       proof(cases "kle n v x \<or> kle n x u") case True thus ?thesis using goal1 by(auto intro:lem3 lem4) next
   908 	case False hence *:"kle n u x" "kle n x v" using ksimplexD(6)[OF assms(1)] using goal1 `u\<in>s` `v\<in>s` by auto
   908         case False hence *:"kle n u x" "kle n x v" using ksimplexD(6)[OF assms(1)] using goal1 `u\<in>s` `v\<in>s` by auto
   909 	show ?thesis using uxv[OF *] using kle_uv using goal1 by auto qed qed
   909         show ?thesis using uxv[OF *] using kle_uv using goal1 by auto qed qed
   910     have "ksimplex p n (insert a' (s - {a}))" apply(rule ksimplexI) proof(rule_tac[2-] ballI,rule_tac[4] ballI)
   910     have "ksimplex p n (insert a' (s - {a}))" apply(rule ksimplexI) proof(rule_tac[2-] ballI,rule_tac[4] ballI)
   911       show "card (insert a' (s - {a})) = n + 1" using ksimplexD(2-3)[OF assms(1)]
   911       show "card (insert a' (s - {a})) = n + 1" using ksimplexD(2-3)[OF assms(1)]
   912         using `a'\<noteq>a` `a'\<notin>s` `a\<in>s` by(auto simp add:card_insert_if)
   912         using `a'\<noteq>a` `a'\<notin>s` `a\<in>s` by(auto simp add:card_insert_if)
   913       fix x assume x:"x \<in> insert a' (s - {a})"
   913       fix x assume x:"x \<in> insert a' (s - {a})"
   914       show "\<forall>j. x j \<le> p" proof(rule,cases "x = a'")
   914       show "\<forall>j. x j \<le> p" proof(rule,cases "x = a'")
   915 	fix j case False thus "x j\<le>p" using x ksimplexD(4)[OF assms(1)] by auto next
   915         fix j case False thus "x j\<le>p" using x ksimplexD(4)[OF assms(1)] by auto next
   916 	fix j case True show "x j\<le>p" unfolding True proof(cases "j=l") 
   916         fix j case True show "x j\<le>p" unfolding True proof(cases "j=l") 
   917 	  case False thus "a' j \<le>p" unfolding True a'_def using `u\<in>s` ksimplexD(4)[OF assms(1)] by auto next
   917           case False thus "a' j \<le>p" unfolding True a'_def using `u\<in>s` ksimplexD(4)[OF assms(1)] by auto next
   918 	  case True have *:"a l = u l" "v l = a l + 1" using k(2)[of l] l(2)[of l] `k\<noteq>l` by auto
   918           case True have *:"a l = u l" "v l = a l + 1" using k(2)[of l] l(2)[of l] `k\<noteq>l` by auto
   919 	  have "u l + 1 \<le> p" unfolding *[THEN sym] using ksimplexD(4)[OF assms(1)] using `v\<in>s` by auto
   919           have "u l + 1 \<le> p" unfolding *[THEN sym] using ksimplexD(4)[OF assms(1)] using `v\<in>s` by auto
   920 	  thus "a' j \<le>p" unfolding a'_def True by auto qed qed
   920           thus "a' j \<le>p" unfolding a'_def True by auto qed qed
   921       show "\<forall>j. j \<notin> {1..n} \<longrightarrow> x j = p" proof(rule,rule,cases "x=a'") fix j::nat assume j:"j\<notin>{1..n}"
   921       show "\<forall>j. j \<notin> {1..n} \<longrightarrow> x j = p" proof(rule,rule,cases "x=a'") fix j::nat assume j:"j\<notin>{1..n}"
   922 	{ case False thus "x j = p" using j x ksimplexD(5)[OF assms(1)] by auto }
   922         { case False thus "x j = p" using j x ksimplexD(5)[OF assms(1)] by auto }
   923 	case True show "x j = p" unfolding True a'_def using j l(1) 
   923         case True show "x j = p" unfolding True a'_def using j l(1) 
   924 	  using ksimplexD(5)[OF assms(1),rule_format,OF `u\<in>s` j] by auto qed
   924           using ksimplexD(5)[OF assms(1),rule_format,OF `u\<in>s` j] by auto qed
   925       fix y assume y:"y\<in>insert a' (s - {a})"
   925       fix y assume y:"y\<in>insert a' (s - {a})"
   926       show "kle n x y \<or> kle n y x" proof(cases "y=a'")
   926       show "kle n x y \<or> kle n y x" proof(cases "y=a'")
   927 	case True show ?thesis unfolding True apply(cases "x=a'") defer apply(rule lem5) using x by auto next
   927         case True show ?thesis unfolding True apply(cases "x=a'") defer apply(rule lem5) using x by auto next
   928 	case False show ?thesis proof(cases "x=a'") case True show ?thesis unfolding True
   928         case False show ?thesis proof(cases "x=a'") case True show ?thesis unfolding True
   929 	    using lem5[of y] using y by auto next
   929             using lem5[of y] using y by auto next
   930 	  case False thus ?thesis apply(rule_tac ksimplexD(6)[OF assms(1),rule_format]) 
   930           case False thus ?thesis apply(rule_tac ksimplexD(6)[OF assms(1),rule_format]) 
   931 	    using x y `y\<noteq>a'` by auto qed qed qed
   931             using x y `y\<noteq>a'` by auto qed qed qed
   932     hence "insert a' (s - {a}) \<in> ?A" unfolding mem_Collect_eq apply-apply(rule,assumption)
   932     hence "insert a' (s - {a}) \<in> ?A" unfolding mem_Collect_eq apply-apply(rule,assumption)
   933       apply(rule_tac x="a'" in bexI) using aa' `a'\<notin>s` by auto moreover
   933       apply(rule_tac x="a'" in bexI) using aa' `a'\<notin>s` by auto moreover
   934     have "s \<in> ?A" using assms(1,2) by auto ultimately have  "?A \<supseteq> {s, insert a' (s - {a})}" by auto
   934     have "s \<in> ?A" using assms(1,2) by auto ultimately have  "?A \<supseteq> {s, insert a' (s - {a})}" by auto
   935     moreover have "?A \<subseteq> {s, insert a' (s - {a})}" apply(rule) unfolding mem_Collect_eq proof(erule conjE)
   935     moreover have "?A \<subseteq> {s, insert a' (s - {a})}" apply(rule) unfolding mem_Collect_eq proof(erule conjE)
   936       fix s' assume as:"ksimplex p n s'" and "\<exists>b\<in>s'. s' - {b} = s - {a}"
   936       fix s' assume as:"ksimplex p n s'" and "\<exists>b\<in>s'. s' - {b} = s - {a}"
   938       have "u\<noteq>v" unfolding fun_eq_iff unfolding l(2) k(2) by auto
   938       have "u\<noteq>v" unfolding fun_eq_iff unfolding l(2) k(2) by auto
   939       hence uv':"\<not> kle n v u" using uv using kle_antisym by auto
   939       hence uv':"\<not> kle n v u" using uv using kle_antisym by auto
   940       have "u\<noteq>a" "v\<noteq>a" unfolding fun_eq_iff k(2) l(2) by auto 
   940       have "u\<noteq>a" "v\<noteq>a" unfolding fun_eq_iff k(2) l(2) by auto 
   941       hence uvs':"u\<in>s'" "v\<in>s'" using `u\<in>s` `v\<in>s` using a'' by auto
   941       hence uvs':"u\<in>s'" "v\<in>s'" using `u\<in>s` `v\<in>s` using a'' by auto
   942       have lem6:"a \<in> s' \<or> a' \<in> s'" proof(cases "\<forall>x\<in>s'. kle n x u \<or> kle n v x")
   942       have lem6:"a \<in> s' \<or> a' \<in> s'" proof(cases "\<forall>x\<in>s'. kle n x u \<or> kle n v x")
   943 	case False then guess w unfolding ball_simps .. note w=this
   943         case False then guess w unfolding ball_simps .. note w=this
   944 	hence "kle n u w" "kle n w v" using ksimplexD(6)[OF as] uvs' by auto
   944         hence "kle n u w" "kle n w v" using ksimplexD(6)[OF as] uvs' by auto
   945 	hence "w = a' \<or> w = a" using uxv[of w] uvs' w by auto thus ?thesis using w by auto next
   945         hence "w = a' \<or> w = a" using uxv[of w] uvs' w by auto thus ?thesis using w by auto next
   946 	case True have "\<not> (\<forall>x\<in>s'. kle n x u)" unfolding ball_simps apply(rule_tac x=v in bexI)
   946         case True have "\<not> (\<forall>x\<in>s'. kle n x u)" unfolding ball_simps apply(rule_tac x=v in bexI)
   947 	  using uv `u\<noteq>v` unfolding kle_antisym[of n u v,THEN sym] using `v\<in>s'` by auto
   947           using uv `u\<noteq>v` unfolding kle_antisym[of n u v,THEN sym] using `v\<in>s'` by auto
   948 	hence "\<exists>y\<in>s'. \<exists>k\<in>{1..n}. \<forall>j. y j = (if j = k then u j + 1 else u j)" using ksimplex_successor[OF as `u\<in>s'`] by blast
   948         hence "\<exists>y\<in>s'. \<exists>k\<in>{1..n}. \<forall>j. y j = (if j = k then u j + 1 else u j)" using ksimplex_successor[OF as `u\<in>s'`] by blast
   949 	then guess w .. note w=this from this(2) guess kk .. note kk=this[rule_format]
   949         then guess w .. note w=this from this(2) guess kk .. note kk=this[rule_format]
   950 	have "\<not> kle n w u" apply-apply(rule,drule kle_imp_pointwise) 
   950         have "\<not> kle n w u" apply-apply(rule,drule kle_imp_pointwise) 
   951 	  apply(erule_tac x=kk in allE) unfolding kk by auto 
   951           apply(erule_tac x=kk in allE) unfolding kk by auto 
   952 	hence *:"kle n v w" using True[rule_format,OF w(1)] by auto
   952         hence *:"kle n v w" using True[rule_format,OF w(1)] by auto
   953 	hence False proof(cases "kk\<noteq>l") case True thus False using *[THEN kle_imp_pointwise, unfolded l(2) kk k(2)]
   953         hence False proof(cases "kk\<noteq>l") case True thus False using *[THEN kle_imp_pointwise, unfolded l(2) kk k(2)]
   954 	    apply(erule_tac x=l in allE) using `k\<noteq>l` by auto  next
   954             apply(erule_tac x=l in allE) using `k\<noteq>l` by auto  next
   955 	  case False hence "kk\<noteq>k" using `k\<noteq>l` by auto thus False using *[THEN kle_imp_pointwise, unfolded l(2) kk k(2)]
   955           case False hence "kk\<noteq>k" using `k\<noteq>l` by auto thus False using *[THEN kle_imp_pointwise, unfolded l(2) kk k(2)]
   956 	    apply(erule_tac x=k in allE) using `k\<noteq>l` by auto qed
   956             apply(erule_tac x=k in allE) using `k\<noteq>l` by auto qed
   957 	thus ?thesis by auto qed
   957         thus ?thesis by auto qed
   958       thus "s' \<in> {s, insert a' (s - {a})}" proof(cases "a\<in>s'")
   958       thus "s' \<in> {s, insert a' (s - {a})}" proof(cases "a\<in>s'")
   959 	case True hence "s' = s" apply-apply(rule lem1[OF a''(2)]) using a'' `a\<in>s` by auto
   959         case True hence "s' = s" apply-apply(rule lem1[OF a''(2)]) using a'' `a\<in>s` by auto
   960 	thus ?thesis by auto next case False hence "a'\<in>s'" using lem6 by auto
   960         thus ?thesis by auto next case False hence "a'\<in>s'" using lem6 by auto
   961 	hence "s' = insert a' (s - {a})" apply-apply(rule lem1[of _ a'' _ a'])
   961         hence "s' = insert a' (s - {a})" apply-apply(rule lem1[of _ a'' _ a'])
   962 	  unfolding a''(2)[THEN sym] using a'' using `a'\<notin>s` by auto
   962           unfolding a''(2)[THEN sym] using a'' using `a'\<notin>s` by auto
   963 	thus ?thesis by auto qed qed 
   963         thus ?thesis by auto qed qed 
   964     ultimately have *:"?A = {s, insert a' (s - {a})}" by blast
   964     ultimately have *:"?A = {s, insert a' (s - {a})}" by blast
   965     have "s \<noteq> insert a' (s - {a})" using `a'\<notin>s` by auto
   965     have "s \<noteq> insert a' (s - {a})" using `a'\<notin>s` by auto
   966     hence ?thesis unfolding * by auto } 
   966     hence ?thesis unfolding * by auto } 
   967   ultimately show ?thesis by auto qed
   967   ultimately show ?thesis by auto qed
   968 
   968 
   984     apply default+ unfolding mem_Collect_eq apply(erule disjE bexE)+ unfolding mem_Collect_eq proof-
   984     apply default+ unfolding mem_Collect_eq apply(erule disjE bexE)+ unfolding mem_Collect_eq proof-
   985     fix f s a assume as:"ksimplex p (n + 1) s" "a\<in>s" "f = s - {a}"
   985     fix f s a assume as:"ksimplex p (n + 1) s" "a\<in>s" "f = s - {a}"
   986     let ?S = "{s. ksimplex p (n + 1) s \<and> (\<exists>a\<in>s. f = s - {a})}"
   986     let ?S = "{s. ksimplex p (n + 1) s \<and> (\<exists>a\<in>s. f = s - {a})}"
   987     have S:"?S = {s'. ksimplex p (n + 1) s' \<and> (\<exists>b\<in>s'. s' - {b} = s - {a})}" unfolding as by blast
   987     have S:"?S = {s'. ksimplex p (n + 1) s' \<and> (\<exists>b\<in>s'. s' - {b} = s - {a})}" unfolding as by blast
   988     { fix j assume j:"j \<in> {1..n + 1}" "\<forall>x\<in>f. x j = 0" thus "card {s. ksimplex p (n + 1) s \<and> (\<exists>a\<in>s. f = s - {a})} = 1" unfolding S
   988     { fix j assume j:"j \<in> {1..n + 1}" "\<forall>x\<in>f. x j = 0" thus "card {s. ksimplex p (n + 1) s \<and> (\<exists>a\<in>s. f = s - {a})} = 1" unfolding S
   989 	apply-apply(rule ksimplex_replace_0) apply(rule as)+ unfolding as by auto }
   989         apply-apply(rule ksimplex_replace_0) apply(rule as)+ unfolding as by auto }
   990     { fix j assume j:"j \<in> {1..n + 1}" "\<forall>x\<in>f. x j = p" thus "card {s. ksimplex p (n + 1) s \<and> (\<exists>a\<in>s. f = s - {a})} = 1" unfolding S
   990     { fix j assume j:"j \<in> {1..n + 1}" "\<forall>x\<in>f. x j = p" thus "card {s. ksimplex p (n + 1) s \<and> (\<exists>a\<in>s. f = s - {a})} = 1" unfolding S
   991 	apply-apply(rule ksimplex_replace_1) apply(rule as)+ unfolding as by auto }
   991         apply-apply(rule ksimplex_replace_1) apply(rule as)+ unfolding as by auto }
   992     show "\<not> ((\<exists>j\<in>{1..n+1}. \<forall>x\<in>f. x j = 0) \<or> (\<exists>j\<in>{1..n+1}. \<forall>x\<in>f. x j = p)) \<Longrightarrow> card ?S = 2"
   992     show "\<not> ((\<exists>j\<in>{1..n+1}. \<forall>x\<in>f. x j = 0) \<or> (\<exists>j\<in>{1..n+1}. \<forall>x\<in>f. x j = p)) \<Longrightarrow> card ?S = 2"
   993       unfolding S apply(rule ksimplex_replace_2) apply(rule as)+ unfolding as by auto qed auto qed
   993       unfolding S apply(rule ksimplex_replace_2) apply(rule as)+ unfolding as by auto qed auto qed
   994 
   994 
   995 subsection {* Reduced labelling. *}
   995 subsection {* Reduced labelling. *}
   996 
   996 
  1056     fix f assume as:"ksimplex p n f" "reduced lab n ` f = {0..n}"
  1056     fix f assume as:"ksimplex p n f" "reduced lab n ` f = {0..n}"
  1057     have *:"\<forall>x\<in>f. \<forall>j\<in>{1..n + 1}. x j = 0 \<longrightarrow> lab x j = 0" "\<forall>x\<in>f. \<forall>j\<in>{1..n + 1}. x j = p \<longrightarrow> lab x j = 1"
  1057     have *:"\<forall>x\<in>f. \<forall>j\<in>{1..n + 1}. x j = 0 \<longrightarrow> lab x j = 0" "\<forall>x\<in>f. \<forall>j\<in>{1..n + 1}. x j = p \<longrightarrow> lab x j = 1"
  1058       using assms(2-3) using as(1)[unfolded ksimplex_def] by auto
  1058       using assms(2-3) using as(1)[unfolded ksimplex_def] by auto
  1059     have allp:"\<forall>x\<in>f. x (n + 1) = p" using assms(2) using as(1)[unfolded ksimplex_def] by auto
  1059     have allp:"\<forall>x\<in>f. x (n + 1) = p" using assms(2) using as(1)[unfolded ksimplex_def] by auto
  1060     { fix x assume "x\<in>f" hence "reduced lab (n + 1) x < n + 1" apply-apply(rule reduced_labelling_1)
  1060     { fix x assume "x\<in>f" hence "reduced lab (n + 1) x < n + 1" apply-apply(rule reduced_labelling_1)
  1061 	defer using assms(3) using as(1)[unfolded ksimplex_def] by auto
  1061         defer using assms(3) using as(1)[unfolded ksimplex_def] by auto
  1062       hence "reduced lab (n + 1) x = reduced lab n x" apply-apply(rule reduced_labelling_Suc) using reduced_labelling(1) by auto }
  1062       hence "reduced lab (n + 1) x = reduced lab n x" apply-apply(rule reduced_labelling_Suc) using reduced_labelling(1) by auto }
  1063     hence "reduced lab (n + 1) ` f = {0..n}" unfolding as(2)[THEN sym] apply- apply(rule set_eqI) unfolding image_iff by auto
  1063     hence "reduced lab (n + 1) ` f = {0..n}" unfolding as(2)[THEN sym] apply- apply(rule set_eqI) unfolding image_iff by auto
  1064     moreover guess s using as(1)[unfolded simplex_top_face[OF assms(1) allp,THEN sym]] .. then guess a ..
  1064     moreover guess s using as(1)[unfolded simplex_top_face[OF assms(1) allp,THEN sym]] .. then guess a ..
  1065     ultimately show "\<exists>s a. ksimplex p (n + 1) s \<and>
  1065     ultimately show "\<exists>s a. ksimplex p (n + 1) s \<and>
  1066       a \<in> s \<and> f = s - {a} \<and> reduced lab (n + 1) ` f = {0..n} \<and> ((\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = 0) \<or> (\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = p))" (is ?ex)
  1066       a \<in> s \<and> f = s - {a} \<and> reduced lab (n + 1) ` f = {0..n} \<and> ((\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = 0) \<or> (\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = p))" (is ?ex)
  1069       a \<in> s \<and> f = s - {a} \<and> reduced lab (n + 1) ` f = {0..n} \<and> ((\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = 0) \<or> (\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = p))" (is ?ex)
  1069       a \<in> s \<and> f = s - {a} \<and> reduced lab (n + 1) ` f = {0..n} \<and> ((\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = 0) \<or> (\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = p))" (is ?ex)
  1070     then guess s .. then guess a apply-apply(erule exE,(erule conjE)+) . note sa=this
  1070     then guess s .. then guess a apply-apply(erule exE,(erule conjE)+) . note sa=this
  1071     { fix x assume "x\<in>f" hence "reduced lab (n + 1) x \<in> reduced lab (n + 1) ` f" by auto
  1071     { fix x assume "x\<in>f" hence "reduced lab (n + 1) x \<in> reduced lab (n + 1) ` f" by auto
  1072       hence "reduced lab (n + 1) x < n + 1" using sa(4) by auto 
  1072       hence "reduced lab (n + 1) x < n + 1" using sa(4) by auto 
  1073       hence "reduced lab (n + 1) x = reduced lab n x" apply-apply(rule reduced_labelling_Suc)
  1073       hence "reduced lab (n + 1) x = reduced lab n x" apply-apply(rule reduced_labelling_Suc)
  1074 	using reduced_labelling(1) by auto }
  1074         using reduced_labelling(1) by auto }
  1075     thus part1:"reduced lab n ` f = {0..n}" unfolding sa(4)[THEN sym] apply-apply(rule set_eqI) unfolding image_iff by auto
  1075     thus part1:"reduced lab n ` f = {0..n}" unfolding sa(4)[THEN sym] apply-apply(rule set_eqI) unfolding image_iff by auto
  1076     have *:"\<forall>x\<in>f. x (n + 1) = p" proof(cases "\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = 0")
  1076     have *:"\<forall>x\<in>f. x (n + 1) = p" proof(cases "\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = 0")
  1077       case True then guess j .. hence "\<And>x. x\<in>f \<Longrightarrow> reduced lab (n + 1) x \<noteq> j - 1" apply-apply(rule reduced_labelling_0) apply assumption
  1077       case True then guess j .. hence "\<And>x. x\<in>f \<Longrightarrow> reduced lab (n + 1) x \<noteq> j - 1" apply-apply(rule reduced_labelling_0) apply assumption
  1078 	apply(rule assms(2)[rule_format]) using sa(1)[unfolded ksimplex_def] unfolding sa by auto moreover
  1078         apply(rule assms(2)[rule_format]) using sa(1)[unfolded ksimplex_def] unfolding sa by auto moreover
  1079       have "j - 1 \<in> {0..n}" using `j\<in>{1..n+1}` by auto
  1079       have "j - 1 \<in> {0..n}" using `j\<in>{1..n+1}` by auto
  1080       ultimately have False unfolding sa(4)[THEN sym] unfolding image_iff by fastsimp thus ?thesis by auto next
  1080       ultimately have False unfolding sa(4)[THEN sym] unfolding image_iff by fastsimp thus ?thesis by auto next
  1081       case False hence "\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = p" using sa(5) by fastsimp then guess j .. note j=this
  1081       case False hence "\<exists>j\<in>{1..n + 1}. \<forall>x\<in>f. x j = p" using sa(5) by fastsimp then guess j .. note j=this
  1082       thus ?thesis proof(cases "j = n+1")
  1082       thus ?thesis proof(cases "j = n+1")
  1083 	case False hence *:"j\<in>{1..n}" using j by auto
  1083         case False hence *:"j\<in>{1..n}" using j by auto
  1084 	hence "\<And>x. x\<in>f \<Longrightarrow> reduced lab n x < j" apply(rule reduced_labelling_1) proof- fix x assume "x\<in>f"
  1084         hence "\<And>x. x\<in>f \<Longrightarrow> reduced lab n x < j" apply(rule reduced_labelling_1) proof- fix x assume "x\<in>f"
  1085 	  hence "lab x j = 1" apply-apply(rule assms(3)[rule_format,OF j(1)]) 
  1085           hence "lab x j = 1" apply-apply(rule assms(3)[rule_format,OF j(1)]) 
  1086 	    using sa(1)[unfolded ksimplex_def] using j unfolding sa by auto thus "lab x j \<noteq> 0" by auto qed
  1086             using sa(1)[unfolded ksimplex_def] using j unfolding sa by auto thus "lab x j \<noteq> 0" by auto qed
  1087 	moreover have "j\<in>{0..n}" using * by auto
  1087         moreover have "j\<in>{0..n}" using * by auto
  1088 	ultimately have False unfolding part1[THEN sym] using * unfolding image_iff by auto thus ?thesis by auto qed auto qed 
  1088         ultimately have False unfolding part1[THEN sym] using * unfolding image_iff by auto thus ?thesis by auto qed auto qed 
  1089     thus "ksimplex p n f" using as unfolding simplex_top_face[OF assms(1) *,THEN sym] by auto qed qed
  1089     thus "ksimplex p n f" using as unfolding simplex_top_face[OF assms(1) *,THEN sym] by auto qed qed
  1090 
  1090 
  1091 lemma kuhn_induction_Suc:
  1091 lemma kuhn_induction_Suc:
  1092   assumes "0 < p" "\<forall>x. \<forall>j\<in>{1..Suc n}. (\<forall>j. x j \<le> p) \<and> (x j = 0) \<longrightarrow> (lab x j = 0)"
  1092   assumes "0 < p" "\<forall>x. \<forall>j\<in>{1..Suc n}. (\<forall>j. x j \<le> p) \<and> (x j = 0) \<longrightarrow> (lab x j = 0)"
  1093                   "\<forall>x. \<forall>j\<in>{1..Suc n}. (\<forall>j. x j \<le> p) \<and> (x j = p) \<longrightarrow> (lab x j = 1)"
  1093                   "\<forall>x. \<forall>j\<in>{1..Suc n}. (\<forall>j. x j \<le> p) \<and> (x j = p) \<longrightarrow> (lab x j = 1)"