# HG changeset patch # User hoelzl # Date 1258480350 -3600 # Node ID 4c414d0835ab3128a0b0300c95e24d9874999660 # Parent 5fd36780760b955523add38da5eb8c832afd0e93 Added derivation and Brouwer's fixpoint theorem in Multivariate Analysis (translated by Robert Himmelmann from HOL-light) diff -r 5fd36780760b -r 4c414d0835ab src/HOL/IsaMakefile --- a/src/HOL/IsaMakefile Tue Nov 17 18:25:05 2009 +0100 +++ b/src/HOL/IsaMakefile Tue Nov 17 18:52:30 2009 +0100 @@ -1058,7 +1058,9 @@ Multivariate_Analysis/Finite_Cartesian_Product.thy \ Multivariate_Analysis/Euclidean_Space.thy \ Multivariate_Analysis/Topology_Euclidean_Space.thy \ - Multivariate_Analysis/Convex_Euclidean_Space.thy + Multivariate_Analysis/Convex_Euclidean_Space.thy \ + Multivariate_Analysis/Brouwer_Fixpoint.thy \ + Multivariate_Analysis/Derivative.thy @cd Multivariate_Analysis; $(ISABELLE_TOOL) usedir -b -g true $(OUT)/HOL HOL-Multivariate_Analysis diff -r 5fd36780760b -r 4c414d0835ab src/HOL/Multivariate_Analysis/Brouwer_Fixpoint.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Multivariate_Analysis/Brouwer_Fixpoint.thy Tue Nov 17 18:52:30 2009 +0100 @@ -0,0 +1,1983 @@ + +(* ========================================================================= *) +(* Results connected with topological dimension. *) +(* *) +(* At the moment this is just Brouwer's fixpoint theorem. The proof is from *) +(* Kuhn: "some combinatorial lemmas in topology", IBM J. v4. (1960) p. 518 *) +(* See "http://www.research.ibm.com/journal/rd/045/ibmrd0405K.pdf". *) +(* *) +(* The script below is quite messy, but at least we avoid formalizing any *) +(* topological machinery; we don't even use barycentric subdivision; this is *) +(* the big advantage of Kuhn's proof over the usual Sperner's lemma one. *) +(* *) +(* (c) Copyright, John Harrison 1998-2008 *) +(* ========================================================================= *) + +(* Author: John Harrison + Translated to from HOL light: Robert Himmelmann, TU Muenchen *) + +header {* Results connected with topological dimension. *} + +theory Brouwer_Fixpoint + imports Convex_Euclidean_Space +begin + +declare norm_scaleR[simp] + +lemma brouwer_compactness_lemma: + assumes "compact s" "continuous_on s f" "\ (\x\s. (f x = (0::real^'n::finite)))" + obtains d where "0 < d" "\x\s. d \ norm(f x)" proof(cases "s={}") case False + have "continuous_on s (norm \ f)" by(rule continuous_on_intros continuous_on_norm assms(2))+ + then obtain x where x:"x\s" "\y\s. (norm \ f) x \ (norm \ f) y" + using continuous_attains_inf[OF assms(1), of "norm \ f"] and False unfolding o_def by auto + have "(norm \ f) x > 0" using assms(3) and x(1) by auto + thus ?thesis apply(rule that) using x(2) unfolding o_def by auto qed(rule that[of 1], auto) + +lemma kuhn_labelling_lemma: + assumes "(\x::real^'n. P x \ P (f x))" "\x. P x \ (\i::'n. Q i \ 0 \ x$i \ x$i \ 1)" + shows "\l. (\x i. l x i \ (1::nat)) \ + (\x i. P x \ Q i \ (x$i = 0) \ (l x i = 0)) \ + (\x i. P x \ Q i \ (x$i = 1) \ (l x i = 1)) \ + (\x i. P x \ Q i \ (l x i = 0) \ x$i \ f(x)$i) \ + (\x i. P x \ Q i \ (l x i = 1) \ f(x)$i \ x$i)" proof- + have and_forall_thm:"\P Q. (\x. P x) \ (\x. Q x) \ (\x. P x \ Q x)" by auto + have *:"\x y::real. 0 \ x \ x \ 1 \ 0 \ y \ y \ 1 \ (x \ 1 \ x \ y \ x \ 0 \ y \ x)" by auto + show ?thesis unfolding and_forall_thm apply(subst choice_iff[THEN sym])+ proof(rule,rule) case goal1 + let ?R = "\y. (P x \ Q xa \ x $ xa = 0 \ y = (0::nat)) \ + (P x \ Q xa \ x $ xa = 1 \ y = 1) \ (P x \ Q xa \ y = 0 \ x $ xa \ f x $ xa) \ (P x \ Q xa \ y = 1 \ f x $ xa \ x $ xa)" + { assume "P x" "Q xa" hence "0 \ f x $ xa \ f x $ xa \ 1" using assms(2)[rule_format,of "f x" xa] + apply(drule_tac assms(1)[rule_format]) by auto } + hence "?R 0 \ ?R 1" by auto thus ?case by auto qed qed + +subsection {* The key "counting" observation, somewhat abstracted. *} + +lemma setsum_Un_disjoint':assumes "finite A" "finite B" "A \ B = {}" "A \ B = C" + shows "setsum g C = setsum g A + setsum g B" + using setsum_Un_disjoint[OF assms(1-3)] and assms(4) by auto + +lemma kuhn_counting_lemma: assumes "finite faces" "finite simplices" + "\f\faces. bnd f \ (card {s \ simplices. face f s} = 1)" + "\f\faces. \ bnd f \ (card {s \ simplices. face f s} = 2)" + "\s\simplices. compo s \ (card {f \ faces. face f s \ compo' f} = 1)" + "\s\simplices. \ compo s \ (card {f \ faces. face f s \ compo' f} = 0) \ + (card {f \ faces. face f s \ compo' f} = 2)" + "odd(card {f \ faces. compo' f \ bnd f})" + shows "odd(card {s \ simplices. compo s})" proof- + have "\x. {f\faces. compo' f \ bnd f \ face f x} \ {f\faces. compo' f \ \bnd f \ face f x} = {f\faces. compo' f \ face f x}" + "\x. {f \ faces. compo' f \ bnd f \ face f x} \ {f \ faces. compo' f \ \ bnd f \ face f x} = {}" by auto + hence lem1:"setsum (\s. (card {f \ faces. face f s \ compo' f})) simplices = + setsum (\s. card {f \ {f \ faces. compo' f \ bnd f}. face f s}) simplices + + setsum (\s. card {f \ {f \ faces. compo' f \ \ (bnd f)}. face f s}) simplices" + unfolding setsum_addf[THEN sym] apply- apply(rule setsum_cong2) + using assms(1) by(auto simp add: card_Un_Int, auto simp add:conj_commute) + have lem2:"setsum (\j. card {f \ {f \ faces. compo' f \ bnd f}. face f j}) simplices = + 1 * card {f \ faces. compo' f \ bnd f}" + "setsum (\j. card {f \ {f \ faces. compo' f \ \ bnd f}. face f j}) simplices = + 2 * card {f \ faces. compo' f \ \ bnd f}" + apply(rule_tac[!] setsum_multicount) using assms by auto + have lem3:"setsum (\s. card {f \ faces. face f s \ compo' f}) simplices = + setsum (\s. card {f \ faces. face f s \ compo' f}) {s \ simplices. compo s}+ + setsum (\s. card {f \ faces. face f s \ compo' f}) {s \ simplices. \ compo s}" + apply(rule setsum_Un_disjoint') using assms(2) by auto + have lem4:"setsum (\s. card {f \ faces. face f s \ compo' f}) {s \ simplices. compo s} + = setsum (\s. 1) {s \ simplices. compo s}" + apply(rule setsum_cong2) using assms(5) by auto + have lem5: "setsum (\s. card {f \ faces. face f s \ compo' f}) {s \ simplices. \ compo s} = + setsum (\s. card {f \ faces. face f s \ compo' f}) + {s \ simplices. (\ compo s) \ (card {f \ faces. face f s \ compo' f} = 0)} + + setsum (\s. card {f \ faces. face f s \ compo' f}) + {s \ simplices. (\ compo s) \ (card {f \ faces. face f s \ compo' f} = 2)}" + apply(rule setsum_Un_disjoint') using assms(2,6) by auto + have *:"int (\s\{s \ simplices. compo s}. card {f \ faces. face f s \ compo' f}) = + int (card {f \ faces. compo' f \ bnd f} + 2 * card {f \ faces. compo' f \ \ bnd f}) - + int (card {s \ simplices. \ compo s \ card {f \ faces. face f s \ compo' f} = 2} * 2)" + using lem1[unfolded lem3 lem2 lem5] by auto + have even_minus_odd:"\x y. even x \ odd (y::int) \ odd (x - y)" using assms by auto + have odd_minus_even:"\x y. odd x \ even (y::int) \ odd (x - y)" using assms by auto + show ?thesis unfolding even_nat_def unfolding card_def and lem4[THEN sym] and *[unfolded card_def] + unfolding card_def[THEN sym] apply(rule odd_minus_even) unfolding zadd_int[THEN sym] apply(rule odd_plus_even) + apply(rule assms(7)[unfolded even_nat_def]) unfolding int_mult by auto qed + +subsection {* The odd/even result for faces of complete vertices, generalized. *} + +lemma card_1_exists: "card s = 1 \ (\!x. x \ s)" unfolding One_nat_def + apply rule apply(drule card_eq_SucD) defer apply(erule ex1E) proof- + fix x assume as:"x \ s" "\y. y \ s \ y = x" + have *:"s = insert x {}" apply- apply(rule set_ext,rule) unfolding singleton_iff + apply(rule as(2)[rule_format]) using as(1) by auto + show "card s = Suc 0" unfolding * using card_insert by auto qed auto + +lemma card_2_exists: "card s = 2 \ (\x\s. \y\s. x \ y \ (\z\s. (z = x) \ (z = y)))" proof + assume "card s = 2" then obtain x y where obt:"s = {x, y}" "x\y" unfolding numeral_2_eq_2 apply - apply(erule exE conjE|drule card_eq_SucD)+ by auto + show "\x\s. \y\s. x \ y \ (\z\s. z = x \ z = y)" using obt by auto next + assume "\x\s. \y\s. x \ y \ (\z\s. z = x \ z = y)" then guess x .. from this(2) guess y .. + with `x\s` have *:"s = {x, y}" "x\y" by auto + from this(2) show "card s = 2" unfolding * by auto qed + +lemma image_lemma_0: assumes "card {a\s. f ` (s - {a}) = t - {b}} = n" + shows "card {s'. \a\s. (s' = s - {a}) \ (f ` s' = t - {b})} = n" proof- + have *:"{s'. \a\s. (s' = s - {a}) \ (f ` s' = t - {b})} = (\a. s - {a}) ` {a\s. f ` (s - {a}) = t - {b}}" by auto + show ?thesis unfolding * unfolding assms[THEN sym] apply(rule card_image) unfolding inj_on_def + apply(rule,rule,rule) unfolding mem_Collect_eq by auto qed + +lemma image_lemma_1: assumes "finite s" "finite t" "card s = card t" "f ` s = t" "b \ t" + shows "card {s'. \a\s. s' = s - {a} \ f ` s' = t - {b}} = 1" proof- + obtain a where a:"b = f a" "a\s" using assms(4-5) by auto + have inj:"inj_on f s" apply(rule eq_card_imp_inj_on) using assms(1-4) by auto + have *:"{a \ s. f ` (s - {a}) = t - {b}} = {a}" apply(rule set_ext) unfolding singleton_iff + apply(rule,rule inj[unfolded inj_on_def,rule_format]) unfolding a using a(2) and assms and inj[unfolded inj_on_def] by auto + show ?thesis apply(rule image_lemma_0) unfolding * by auto qed + +lemma image_lemma_2: assumes "finite s" "finite t" "card s = card t" "f ` s \ t" "f ` s \ t" "b \ t" + shows "(card {s'. \a\s. (s' = s - {a}) \ f ` s' = t - {b}} = 0) \ + (card {s'. \a\s. (s' = s - {a}) \ f ` s' = t - {b}} = 2)" proof(cases "{a\s. f ` (s - {a}) = t - {b}} = {}") + case True thus ?thesis apply-apply(rule disjI1, rule image_lemma_0) using assms(1) by(auto simp add:card_0_eq) +next let ?M = "{a\s. f ` (s - {a}) = t - {b}}" + case False then obtain a where "a\?M" by auto hence a:"a\s" "f ` (s - {a}) = t - {b}" by auto + have "f a \ t - {b}" using a and assms by auto + hence "\c \ s - {a}. f a = f c" unfolding image_iff[symmetric] and a by auto + then obtain c where c:"c \ s" "a \ c" "f a = f c" by auto + hence *:"f ` (s - {c}) = f ` (s - {a})" apply-apply(rule set_ext,rule) proof- + fix x assume "x \ f ` (s - {a})" then obtain y where y:"f y = x" "y\s- {a}" by auto + thus "x \ f ` (s - {c})" unfolding image_iff apply(rule_tac x="if y = c then a else y" in bexI) using c a by auto qed auto + have "c\?M" unfolding mem_Collect_eq and * using a and c(1) by auto + show ?thesis apply(rule disjI2, rule image_lemma_0) unfolding card_2_exists + apply(rule bexI[OF _ `a\?M`], rule bexI[OF _ `c\?M`],rule,rule `a\c`) proof(rule,unfold mem_Collect_eq,erule conjE) + fix z assume as:"z \ s" "f ` (s - {z}) = t - {b}" + have inj:"inj_on f (s - {z})" apply(rule eq_card_imp_inj_on) unfolding as using as(1) and assms by auto + show "z = a \ z = c" proof(rule ccontr) + assume "\ (z = a \ z = c)" thus False using inj[unfolded inj_on_def,THEN bspec[where x=a],THEN bspec[where x=c]] + using `a\s` `c\s` `f a = f c` `a\c` by auto qed qed qed + +subsection {* Combine this with the basic counting lemma. *} + +lemma kuhn_complete_lemma: + assumes "finite simplices" + "\f s. face f s \ (\a\s. f = s - {a})" "\s\simplices. card s = n + 2" "\s\simplices. (rl ` s) \ {0..n+1}" + "\f\ {f. \s\simplices. face f s}. bnd f \ (card {s\simplices. face f s} = 1)" + "\f\ {f. \s\simplices. face f s}. \bnd f \ (card {s\simplices. face f s} = 2)" + "odd(card {f\{f. \s\simplices. face f s}. rl ` f = {0..n} \ bnd f})" + shows "odd (card {s\simplices. (rl ` s = {0..n+1})})" + apply(rule kuhn_counting_lemma) defer apply(rule assms)+ prefer 3 apply(rule assms) proof(rule_tac[1-2] ballI impI)+ + have *:"{f. \s\simplices. \a\s. f = s - {a}} = (\s\simplices. {f. \a\s. (f = s - {a})})" by auto + have **: "\s\simplices. card s = n + 2 \ finite s" using assms(3) by (auto intro: card_ge_0_finite) + show "finite {f. \s\simplices. face f s}" unfolding assms(2)[rule_format] and * + apply(rule finite_UN_I[OF assms(1)]) using ** by auto + have *:"\ P f s. s\simplices \ (f \ {f. \s\simplices. \a\s. f = s - {a}}) \ + (\a\s. (f = s - {a})) \ P f \ (\a\s. (f = s - {a}) \ P f)" by auto + fix s assume s:"s\simplices" let ?S = "{f \ {f. \s\simplices. face f s}. face f s \ rl ` f = {0..n}}" + have "{0..n + 1} - {n + 1} = {0..n}" by auto + hence S:"?S = {s'. \a\s. s' = s - {a} \ rl ` s' = {0..n + 1} - {n + 1}}" apply- apply(rule set_ext) + unfolding assms(2)[rule_format] mem_Collect_eq and *[OF s, unfolded mem_Collect_eq, where P="\x. rl ` x = {0..n}"] by auto + show "rl ` s = {0..n+1} \ card ?S = 1" "rl ` s \ {0..n+1} \ card ?S = 0 \ card ?S = 2" unfolding S + apply(rule_tac[!] image_lemma_1 image_lemma_2) using ** assms(4) and s by auto qed + +subsection {*We use the following notion of ordering rather than pointwise indexing. *} + +definition "kle n x y \ (\k\{1..n::nat}. (\j. y(j) = x(j) + (if j \ k then (1::nat) else 0)))" + +lemma kle_refl[intro]: "kle n x x" unfolding kle_def by auto + +lemma kle_antisym: "kle n x y \ kle n y x \ (x = y)" + unfolding kle_def apply rule apply(rule ext) by auto + +lemma pointwise_minimal_pointwise_maximal: fixes s::"(nat\nat) set" + assumes "finite s" "s \ {}" "\x\s. \y\s. (\j. x j \ y j) \ (\j. y j \ x j)" + shows "\a\s. \x\s. \j. a j \ x j" "\a\s. \x\s. \j. x j \ a j" + using assms unfolding atomize_conj apply- proof(induct s rule:finite_induct) + fix x and F::"(nat\nat) set" assume as:"finite F" "x \ F" + "\F \ {}; \x\F. \y\F. (\j. x j \ y j) \ (\j. y j \ x j)\ + \ (\a\F. \x\F. \j. a j \ x j) \ (\a\F. \x\F. \j. x j \ a j)" "insert x F \ {}" + "\xa\insert x F. \y\insert x F. (\j. xa j \ y j) \ (\j. y j \ xa j)" + show "(\a\insert x F. \x\insert x F. \j. a j \ x j) \ (\a\insert x F. \x\insert x F. \j. x j \ a j)" proof(cases "F={}") + case True thus ?thesis apply-apply(rule,rule_tac[!] x=x in bexI) by auto next + case False obtain a b where a:"a\insert x F" "\x\F. \j. a j \ x j" and + b:"b\insert x F" "\x\F. \j. x j \ b j" using as(3)[OF False] using as(5) by auto + have "\a\insert x F. \x\insert x F. \j. a j \ x j" + using as(5)[rule_format,OF a(1) insertI1] apply- proof(erule disjE) + assume "\j. a j \ x j" thus ?thesis apply(rule_tac x=a in bexI) using a by auto next + assume "\j. x j \ a j" thus ?thesis apply(rule_tac x=x in bexI) apply(rule,rule) using a apply - + apply(erule_tac x=xa in ballE) apply(erule_tac x=j in allE)+ by auto qed moreover + have "\b\insert x F. \x\insert x F. \j. x j \ b j" + using as(5)[rule_format,OF b(1) insertI1] apply- proof(erule disjE) + assume "\j. x j \ b j" thus ?thesis apply(rule_tac x=b in bexI) using b by auto next + assume "\j. b j \ x j" thus ?thesis apply(rule_tac x=x in bexI) apply(rule,rule) using b apply - + apply(erule_tac x=xa in ballE) apply(erule_tac x=j in allE)+ by auto qed + ultimately show ?thesis by auto qed qed(auto) + +lemma kle_imp_pointwise: "kle n x y \ (\j. x j \ y j)" unfolding kle_def by auto + +lemma pointwise_antisym: fixes x::"nat \ nat" + shows "(\j. x j \ y j) \ (\j. y j \ x j) \ (x = y)" + apply(rule, rule ext,erule conjE) apply(erule_tac x=xa in allE)+ by auto + +lemma kle_trans: assumes "kle n x y" "kle n y z" "kle n x z \ kle n z x" shows "kle n x z" + using assms apply- apply(erule disjE) apply assumption proof- case goal1 + hence "x=z" apply- apply(rule ext) apply(drule kle_imp_pointwise)+ + apply(erule_tac x=xa in allE)+ by auto thus ?case by auto qed + +lemma kle_strict: assumes "kle n x y" "x \ y" + shows "\j. x j \ y j" "\k. 1 \ k \ k \ n \ x(k) < y(k)" + apply(rule kle_imp_pointwise[OF assms(1)]) proof- + guess k using assms(1)[unfolded kle_def] .. note k = this + show "\k. 1 \ k \ k \ n \ x(k) < y(k)" proof(cases "k={}") + case True hence "x=y" apply-apply(rule ext) using k by auto + thus ?thesis using assms(2) by auto next + case False hence "(SOME k'. k' \ k) \ k" apply-apply(rule someI_ex) by auto + thus ?thesis apply(rule_tac x="SOME k'. k' \ k" in exI) using k by auto qed qed + +lemma kle_minimal: assumes "finite s" "s \ {}" "\x\s. \y\s. kle n x y \ kle n y x" + shows "\a\s. \x\s. kle n a x" proof- + have "\a\s. \x\s. \j. a j \ x j" apply(rule pointwise_minimal_pointwise_maximal(1)[OF assms(1-2)]) + apply(rule,rule) apply(drule_tac assms(3)[rule_format],assumption) using kle_imp_pointwise by auto + then guess a .. note a=this show ?thesis apply(rule_tac x=a in bexI) proof fix x assume "x\s" + show "kle n a x" using assms(3)[rule_format,OF a(1) `x\s`] apply- proof(erule disjE) + assume "kle n x a" hence "x = a" apply- unfolding pointwise_antisym[THEN sym] + apply(drule kle_imp_pointwise) using a(2)[rule_format,OF `x\s`] by auto + thus ?thesis using kle_refl by auto qed qed(insert a, auto) qed + +lemma kle_maximal: assumes "finite s" "s \ {}" "\x\s. \y\s. kle n x y \ kle n y x" + shows "\a\s. \x\s. kle n x a" proof- + have "\a\s. \x\s. \j. a j \ x j" apply(rule pointwise_minimal_pointwise_maximal(2)[OF assms(1-2)]) + apply(rule,rule) apply(drule_tac assms(3)[rule_format],assumption) using kle_imp_pointwise by auto + then guess a .. note a=this show ?thesis apply(rule_tac x=a in bexI) proof fix x assume "x\s" + show "kle n x a" using assms(3)[rule_format,OF a(1) `x\s`] apply- proof(erule disjE) + assume "kle n a x" hence "x = a" apply- unfolding pointwise_antisym[THEN sym] + apply(drule kle_imp_pointwise) using a(2)[rule_format,OF `x\s`] by auto + thus ?thesis using kle_refl by auto qed qed(insert a, auto) qed + +lemma kle_strict_set: assumes "kle n x y" "x \ y" + shows "1 \ card {k\{1..n}. x k < y k}" proof- + guess i using kle_strict(2)[OF assms] .. + hence "card {i} \ card {k\{1..n}. x k < y k}" apply- apply(rule card_mono) by auto + thus ?thesis by auto qed + +lemma kle_range_combine: + assumes "kle n x y" "kle n y z" "kle n x z \ kle n z x" + "m1 \ card {k\{1..n}. x k < y k}" + "m2 \ card {k\{1..n}. y k < z k}" + shows "kle n x z \ m1 + m2 \ card {k\{1..n}. x k < z k}" + apply(rule,rule kle_trans[OF assms(1-3)]) proof- + have "\j. x j < y j \ x j < z j" apply(rule less_le_trans) using kle_imp_pointwise[OF assms(2)] by auto moreover + have "\j. y j < z j \ x j < z j" apply(rule le_less_trans) using kle_imp_pointwise[OF assms(1)] by auto ultimately + have *:"{k\{1..n}. x k < y k} \ {k\{1..n}. y k < z k} = {k\{1..n}. x k < z k}" by auto + have **:"{k \ {1..n}. x k < y k} \ {k \ {1..n}. y k < z k} = {}" unfolding disjoint_iff_not_equal + apply(rule,rule,unfold mem_Collect_eq,rule ccontr) apply(erule conjE)+ proof- + fix i j assume as:"i \ {1..n}" "x i < y i" "j \ {1..n}" "y j < z j" "\ i \ j" + guess kx using assms(1)[unfolded kle_def] .. note kx=this + have "x i < y i" using as by auto hence "i \ kx" using as(1) kx apply(rule_tac ccontr) by auto + hence "x i + 1 = y i" using kx by auto moreover + guess ky using assms(2)[unfolded kle_def] .. note ky=this + have "y i < z i" using as by auto hence "i \ ky" using as(1) ky apply(rule_tac ccontr) by auto + hence "y i + 1 = z i" using ky by auto ultimately + have "z i = x i + 2" by auto + thus False using assms(3) unfolding kle_def by(auto simp add: split_if_eq1) qed + have fin:"\P. finite {x\{1..n::nat}. P x}" by auto + have "m1 + m2 \ card {k\{1..n}. x k < y k} + card {k\{1..n}. y k < z k}" using assms(4-5) by auto + also have "\ \ card {k\{1..n}. x k < z k}" unfolding card_Un_Int[OF fin fin] unfolding * ** by auto + finally show " m1 + m2 \ card {k \ {1..n}. x k < z k}" by auto qed + +lemma kle_range_combine_l: + assumes "kle n x y" "kle n y z" "kle n x z \ kle n z x" "m \ card {k\{1..n}. y(k) < z(k)}" + shows "kle n x z \ m \ card {k\{1..n}. x(k) < z(k)}" + using kle_range_combine[OF assms(1-3) _ assms(4), of 0] by auto + +lemma kle_range_combine_r: + assumes "kle n x y" "kle n y z" "kle n x z \ kle n z x" "m \ card {k\{1..n}. x k < y k}" + shows "kle n x z \ m \ card {k\{1..n}. x(k) < z(k)}" + using kle_range_combine[OF assms(1-3) assms(4), of 0] by auto + +lemma kle_range_induct: + assumes "card s = Suc m" "\x\s. \y\s. kle n x y \ kle n y x" + shows "\x\s. \y\s. kle n x y \ m \ card {k\{1..n}. x k < y k}" proof- +have "finite s" "s\{}" using assms(1) by (auto intro: card_ge_0_finite) +thus ?thesis using assms apply- proof(induct m arbitrary: s) + case 0 thus ?case using kle_refl by auto next + case (Suc m) then obtain a where a:"a\s" "\x\s. kle n a x" using kle_minimal[of s n] by auto + show ?case proof(cases "s \ {a}") case False + hence "card (s - {a}) = Suc m" "s - {a} \ {}" using card_Diff_singleton[OF _ a(1)] Suc(4) `finite s` by auto + then obtain x b where xb:"x\s - {a}" "b\s - {a}" "kle n x b" "m \ card {k \ {1..n}. x k < b k}" + using Suc(1)[of "s - {a}"] using Suc(5) `finite s` by auto + have "1 \ card {k \ {1..n}. a k < x k}" "m \ card {k \ {1..n}. x k < b k}" + apply(rule kle_strict_set) apply(rule a(2)[rule_format]) using a and xb by auto + thus ?thesis apply(rule_tac x=a in bexI, rule_tac x=b in bexI) + using kle_range_combine[OF a(2)[rule_format] xb(3) Suc(5)[rule_format], of 1 "m"] using a(1) xb(1-2) by auto next + case True hence "s = {a}" using Suc(3) by auto hence "card s = 1" by auto + hence False using Suc(4) `finite s` by auto thus ?thesis by auto qed qed qed + +lemma kle_Suc: "kle n x y \ kle (n + 1) x y" + unfolding kle_def apply(erule exE) apply(rule_tac x=k in exI) by auto + +lemma kle_trans_1: assumes "kle n x y" shows "x j \ y j" "y j \ x j + 1" + using assms[unfolded kle_def] by auto + +lemma kle_trans_2: assumes "kle n a b" "kle n b c" "\j. c j \ a j + 1" shows "kle n a c" proof- + guess kk1 using assms(1)[unfolded kle_def] .. note kk1=this + guess kk2 using assms(2)[unfolded kle_def] .. note kk2=this + show ?thesis unfolding kle_def apply(rule_tac x="kk1 \ kk2" in exI) apply(rule) defer proof + fix i show "c i = a i + (if i \ kk1 \ kk2 then 1 else 0)" proof(cases "i\kk1 \ kk2") + case True hence "c i \ a i + (if i \ kk1 \ kk2 then 1 else 0)" + unfolding kk1[THEN conjunct2,rule_format,of i] kk2[THEN conjunct2,rule_format,of i] by auto + moreover have "c i \ a i + (if i \ kk1 \ kk2 then 1 else 0)" using True assms(3) by auto + ultimately show ?thesis by auto next + case False thus ?thesis using kk1 kk2 by auto qed qed(insert kk1 kk2, auto) qed + +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" + apply(rule kle_trans_2[OF assms(2,4)]) proof have *:"\c b x::nat. x \ c + 1 \ c \ b \ x \ b + 1" by auto + fix j show "x j \ b j + 1" apply(rule *)using kle_trans_1[OF assms(1),of j] kle_trans_1[OF assms(3), of j] by auto qed + +lemma kle_between_l: assumes "kle n a b" "kle n b c" "kle n x a" "kle n x c" shows "kle n x b" + apply(rule kle_trans_2[OF assms(3,1)]) proof have *:"\c b x::nat. c \ x + 1 \ b \ c \ b \ x + 1" by auto + fix j show "b j \ x j + 1" apply(rule *) using kle_trans_1[OF assms(2),of j] kle_trans_1[OF assms(4), of j] by auto qed + +lemma kle_adjacent: + assumes "\j. b j = (if j = k then a(j) + 1 else a j)" "kle n a x" "kle n x b" + shows "(x = a) \ (x = b)" proof(cases "x k = a k") + case True show ?thesis apply(rule disjI1,rule ext) proof- fix j + have "x j \ a j" using kle_imp_pointwise[OF assms(3),THEN spec[where x=j]] + unfolding assms(1)[rule_format] apply-apply(cases "j=k") using True by auto + thus "x j = a j" using kle_imp_pointwise[OF assms(2),THEN spec[where x=j]] by auto qed next + case False show ?thesis apply(rule disjI2,rule ext) proof- fix j + have "x j \ b j" using kle_imp_pointwise[OF assms(2),THEN spec[where x=j]] + unfolding assms(1)[rule_format] apply-apply(cases "j=k") using False by auto + thus "x j = b j" using kle_imp_pointwise[OF assms(3),THEN spec[where x=j]] by auto qed qed + +subsection {* kuhn's notion of a simplex (a reformulation to avoid so much indexing). *} + +definition "ksimplex p n (s::(nat \ nat) set) \ + (card s = n + 1 \ + (\x\s. \j. x(j) \ p) \ + (\x\s. \j. j\{1..n} \ (x j = p)) \ + (\x\s. \y\s. kle n x y \ kle n y x))" + +lemma ksimplexI:"card s = n + 1 \ \x\s. \j. x j \ p \ \x\s. \j. j \ {1..?n} \ x j = ?p \ \x\s. \y\s. kle n x y \ kle n y x \ ksimplex p n s" + unfolding ksimplex_def by auto + +lemma ksimplex_eq: "ksimplex p n (s::(nat \ nat) set) \ + (card s = n + 1 \ finite s \ + (\x\s. \j. x(j) \ p) \ + (\x\s. \j. j\{1..n} \ (x j = p)) \ + (\x\s. \y\s. kle n x y \ kle n y x))" + unfolding ksimplex_def by (auto intro: card_ge_0_finite) + +lemma ksimplex_extrema: assumes "ksimplex p n s" obtains a b where "a \ s" "b \ s" + "\x\s. kle n a x \ kle n x b" "\i. b(i) = (if i \ {1..n} then a(i) + 1 else a(i))" proof(cases "n=0") + case True obtain x where *:"s = {x}" using assms[unfolded ksimplex_eq True,THEN conjunct1] + unfolding add_0_left card_1_exists by auto + show ?thesis apply(rule that[of x x]) unfolding * True by auto next + note assm = assms[unfolded ksimplex_eq] + case False have "s\{}" using assm by auto + obtain a where a:"a\s" "\x\s. kle n a x" using `s\{}` assm using kle_minimal[of s n] by auto + obtain b where b:"b\s" "\x\s. kle n x b" using `s\{}` assm using kle_maximal[of s n] by auto + obtain c d where c_d:"c\s" "d\s" "kle n c d" "n \ card {k \ {1..n}. c k < d k}" + using kle_range_induct[of s n n] using assm by auto + have "kle n c b \ n \ card {k \ {1..n}. c k < b k}" apply(rule kle_range_combine_r[where y=d]) using c_d a b by auto + hence "kle n a b \ n \ card {k\{1..n}. a(k) < b(k)}" apply-apply(rule kle_range_combine_l[where y=c]) using a `c\s` `b\s` by auto + moreover have "card {1..n} \ card {k\{1..n}. a(k) < b(k)}" apply(rule card_mono) by auto + ultimately have *:"{k\{1 .. n}. a k < b k} = {1..n}" apply- apply(rule card_subset_eq) by auto + show ?thesis apply(rule that[OF a(1) b(1)]) defer apply(subst *[THEN sym]) unfolding mem_Collect_eq proof + guess k using a(2)[rule_format,OF b(1),unfolded kle_def] .. note k=this + fix i show "b i = (if i \ {1..n} \ a i < b i then a i + 1 else a i)" proof(cases "i \ {1..n}") + case True thus ?thesis unfolding k[THEN conjunct2,rule_format] by auto next + case False have "a i = p" using assm and False `a\s` by auto + moreover have "b i = p" using assm and False `b\s` by auto + ultimately show ?thesis by auto qed qed(insert a(2) b(2) assm,auto) qed + +lemma ksimplex_extrema_strong: + assumes "ksimplex p n s" "n \ 0" obtains a b where "a \ s" "b \ s" "a \ b" + "\x\s. kle n a x \ kle n x b" "\i. b(i) = (if i \ {1..n} then a(i) + 1 else a(i))" proof- + obtain a b where ab:"a \ s" "b \ s" "\x\s. kle n a x \ kle n x b" "\i. b(i) = (if i \ {1..n} then a(i) + 1 else a(i))" + apply(rule ksimplex_extrema[OF assms(1)]) by auto + have "a \ b" apply(rule ccontr) unfolding not_not apply(drule cong[of _ _ 1 1]) using ab(4) assms(2) by auto + thus ?thesis apply(rule_tac that[of a b]) using ab by auto qed + +lemma ksimplexD: + assumes "ksimplex p n s" + shows "card s = n + 1" "finite s" "card s = n + 1" "\x\s. \j. x j \ p" "\x\s. \j. j \ {1..?n} \ x j = p" + "\x\s. \y\s. kle n x y \ kle n y x" using assms unfolding ksimplex_eq by auto + +lemma ksimplex_successor: + assumes "ksimplex p n s" "a \ s" + shows "(\x\s. kle n x a) \ (\y\s. \k\{1..n}. \j. y(j) = (if j = k then a(j) + 1 else a(j)))" +proof(cases "\x\s. kle n x a") case True thus ?thesis by auto next note assm = ksimplexD[OF assms(1)] + case False then obtain b where b:"b\s" "\ kle n b a" "\x\{x \ s. \ kle n x a}. kle n b x" + using kle_minimal[of "{x\s. \ kle n x a}" n] and assm by auto + hence **:"1 \ card {k\{1..n}. a k < b k}" apply- apply(rule kle_strict_set) using assm(6) and `a\s` by(auto simp add:kle_refl) + + let ?kle1 = "{x \ s. \ kle n x a}" have "card ?kle1 > 0" apply(rule ccontr) using assm(2) and False by auto + hence sizekle1: "card ?kle1 = Suc (card ?kle1 - 1)" using assm(2) by auto + obtain c d where c_d: "c \ s" "\ kle n c a" "d \ s" "\ kle n d a" "kle n c d" "card ?kle1 - 1 \ card {k \ {1..n}. c k < d k}" + using kle_range_induct[OF sizekle1, of n] using assm by auto + + let ?kle2 = "{x \ s. kle n x a}" + have "card ?kle2 > 0" apply(rule ccontr) using assm(6)[rule_format,of a a] and `a\s` and assm(2) by auto + hence sizekle2:"card ?kle2 = Suc (card ?kle2 - 1)" using assm(2) by auto + obtain e f where e_f: "e \ s" "kle n e a" "f \ s" "kle n f a" "kle n e f" "card ?kle2 - 1 \ card {k \ {1..n}. e k < f k}" + using kle_range_induct[OF sizekle2, of n] using assm by auto + + have "card {k\{1..n}. a k < b k} = 1" proof(rule ccontr) case goal1 + hence as:"card {k\{1..n}. a k < b k} \ 2" using ** by auto + have *:"finite ?kle2" "finite ?kle1" "?kle2 \ ?kle1 = s" "?kle2 \ ?kle1 = {}" using assm(2) by auto + have "(card ?kle2 - 1) + 2 + (card ?kle1 - 1) = card ?kle2 + card ?kle1" using sizekle1 sizekle2 by auto + also have "\ = n + 1" unfolding card_Un_Int[OF *(1-2)] *(3-) using assm(3) by auto + finally have n:"(card ?kle2 - 1) + (2 + (card ?kle1 - 1)) = n + 1" by auto + have "kle n e a \ card {x \ s. kle n x a} - 1 \ card {k \ {1..n}. e k < a k}" + apply(rule kle_range_combine_r[where y=f]) using e_f using `a\s` assm(6) by auto + moreover have "kle n b d \ card {x \ s. \ kle n x a} - 1 \ card {k \ {1..n}. b k < d k}" + apply(rule kle_range_combine_l[where y=c]) using c_d using assm(6) and b by auto + hence "kle n a d \ 2 + (card {x \ s. \ kle n x a} - 1) \ card {k \ {1..n}. a k < d k}" apply- + apply(rule kle_range_combine[where y=b]) using as and b assm(6) `a\s` `d\s` apply- by blast+ + ultimately have "kle n e d \ (card ?kle2 - 1) + (2 + (card ?kle1 - 1)) \ card {k\{1..n}. e k < d k}" apply- + apply(rule kle_range_combine[where y=a]) using assm(6)[rule_format,OF `e\s` `d\s`] apply - by blast+ + moreover have "card {k \ {1..n}. e k < d k} \ card {1..n}" apply(rule card_mono) by auto + ultimately show False unfolding n by auto qed + then guess k unfolding card_1_exists .. note k=this[unfolded mem_Collect_eq] + + show ?thesis apply(rule disjI2) apply(rule_tac x=b in bexI,rule_tac x=k in bexI) proof + fix j::nat have "kle n a b" using b and assm(6)[rule_format, OF `a\s` `b\s`] by auto + then guess kk unfolding kle_def .. note kk_raw=this note kk=this[THEN conjunct2,rule_format] + have kkk:"k\kk" apply(rule ccontr) using k(1) unfolding kk by auto + show "b j = (if j = k then a j + 1 else a j)" proof(cases "j\kk") + case True hence "j=k" apply-apply(rule k(2)[rule_format]) using kk_raw kkk by auto + thus ?thesis unfolding kk using kkk by auto next + case False hence "j\k" using k(2)[rule_format, of j k] using kk_raw kkk by auto + thus ?thesis unfolding kk using kkk using False by auto qed qed(insert k(1) `b\s`, auto) qed + +lemma ksimplex_predecessor: + assumes "ksimplex p n s" "a \ s" + shows "(\x\s. kle n a x) \ (\y\s. \k\{1..n}. \j. a(j) = (if j = k then y(j) + 1 else y(j)))" +proof(cases "\x\s. kle n a x") case True thus ?thesis by auto next note assm = ksimplexD[OF assms(1)] + case False then obtain b where b:"b\s" "\ kle n a b" "\x\{x \ s. \ kle n a x}. kle n x b" + using kle_maximal[of "{x\s. \ kle n a x}" n] and assm by auto + hence **:"1 \ card {k\{1..n}. a k > b k}" apply- apply(rule kle_strict_set) using assm(6) and `a\s` by(auto simp add:kle_refl) + + let ?kle1 = "{x \ s. \ kle n a x}" have "card ?kle1 > 0" apply(rule ccontr) using assm(2) and False by auto + hence sizekle1:"card ?kle1 = Suc (card ?kle1 - 1)" using assm(2) by auto + obtain c d where c_d: "c \ s" "\ kle n a c" "d \ s" "\ kle n a d" "kle n d c" "card ?kle1 - 1 \ card {k \ {1..n}. c k > d k}" + using kle_range_induct[OF sizekle1, of n] using assm by auto + + let ?kle2 = "{x \ s. kle n a x}" + have "card ?kle2 > 0" apply(rule ccontr) using assm(6)[rule_format,of a a] and `a\s` and assm(2) by auto + hence sizekle2:"card ?kle2 = Suc (card ?kle2 - 1)" using assm(2) by auto + obtain e f where e_f: "e \ s" "kle n a e" "f \ s" "kle n a f" "kle n f e" "card ?kle2 - 1 \ card {k \ {1..n}. e k > f k}" + using kle_range_induct[OF sizekle2, of n] using assm by auto + + have "card {k\{1..n}. a k > b k} = 1" proof(rule ccontr) case goal1 + hence as:"card {k\{1..n}. a k > b k} \ 2" using ** by auto + have *:"finite ?kle2" "finite ?kle1" "?kle2 \ ?kle1 = s" "?kle2 \ ?kle1 = {}" using assm(2) by auto + have "(card ?kle2 - 1) + 2 + (card ?kle1 - 1) = card ?kle2 + card ?kle1" using sizekle1 sizekle2 by auto + also have "\ = n + 1" unfolding card_Un_Int[OF *(1-2)] *(3-) using assm(3) by auto + finally have n:"(card ?kle1 - 1) + 2 + (card ?kle2 - 1) = n + 1" by auto + have "kle n a e \ card {x \ s. kle n a x} - 1 \ card {k \ {1..n}. e k > a k}" + apply(rule kle_range_combine_l[where y=f]) using e_f using `a\s` assm(6) by auto + moreover have "kle n d b \ card {x \ s. \ kle n a x} - 1 \ card {k \ {1..n}. b k > d k}" + apply(rule kle_range_combine_r[where y=c]) using c_d using assm(6) and b by auto + hence "kle n d a \ (card {x \ s. \ kle n a x} - 1) + 2 \ card {k \ {1..n}. a k > d k}" apply- + apply(rule kle_range_combine[where y=b]) using as and b assm(6) `a\s` `d\s` by blast+ + ultimately have "kle n d e \ (card ?kle1 - 1 + 2) + (card ?kle2 - 1) \ card {k\{1..n}. e k > d k}" apply- + apply(rule kle_range_combine[where y=a]) using assm(6)[rule_format,OF `e\s` `d\s`] apply - by blast+ + moreover have "card {k \ {1..n}. e k > d k} \ card {1..n}" apply(rule card_mono) by auto + ultimately show False unfolding n by auto qed + then guess k unfolding card_1_exists .. note k=this[unfolded mem_Collect_eq] + + show ?thesis apply(rule disjI2) apply(rule_tac x=b in bexI,rule_tac x=k in bexI) proof + fix j::nat have "kle n b a" using b and assm(6)[rule_format, OF `a\s` `b\s`] by auto + then guess kk unfolding kle_def .. note kk_raw=this note kk=this[THEN conjunct2,rule_format] + have kkk:"k\kk" apply(rule ccontr) using k(1) unfolding kk by auto + show "a j = (if j = k then b j + 1 else b j)" proof(cases "j\kk") + case True hence "j=k" apply-apply(rule k(2)[rule_format]) using kk_raw kkk by auto + thus ?thesis unfolding kk using kkk by auto next + case False hence "j\k" using k(2)[rule_format, of j k] using kk_raw kkk by auto + thus ?thesis unfolding kk using kkk using False by auto qed qed(insert k(1) `b\s`, auto) qed + +subsection {* The lemmas about simplices that we need. *} + +lemma card_funspace': assumes "finite s" "finite t" "card s = m" "card t = n" + shows "card {f. (\x\s. f x \ t) \ (\x\UNIV - s. f x = d)} = n ^ m" (is "card (?M s) = _") + using assms apply - proof(induct m arbitrary: s) + have *:"{f. \x. f x = d} = {\x. d}" apply(rule set_ext,rule)unfolding mem_Collect_eq apply(rule,rule ext) by auto + case 0 thus ?case by(auto simp add: *) next + case (Suc m) guess a using card_eq_SucD[OF Suc(4)] .. then guess s0 + apply(erule_tac exE) apply(erule conjE)+ . note as0 = this + have **:"card s0 = m" using as0 using Suc(2) Suc(4) by auto + let ?l = "(\(b,g) x. if x = a then b else g x)" have *:"?M (insert a s0) = ?l ` {(b,g). b\t \ g\?M s0}" + apply(rule set_ext,rule) unfolding mem_Collect_eq image_iff apply(erule conjE) + apply(rule_tac x="(x a, \y. if y\s0 then x y else d)" in bexI) apply(rule ext) prefer 3 apply rule defer + apply(erule bexE,rule) unfolding mem_Collect_eq apply(erule splitE)+ apply(erule conjE)+ proof- + fix x xa xb xc y assume as:"x = (\(b, g) x. if x = a then b else g x) xa" "xb \ UNIV - insert a s0" "xa = (xc, y)" "xc \ t" + "\x\s0. y x \ t" "\x\UNIV - s0. y x = d" thus "x xb = d" unfolding as by auto qed auto + have inj:"inj_on ?l {(b,g). b\t \ g\?M s0}" unfolding inj_on_def apply(rule,rule,rule) unfolding mem_Collect_eq apply(erule splitE conjE)+ proof- + case goal1 note as = this(1,4-)[unfolded goal1 split_conv] + have "xa = xb" using as(1)[THEN cong[of _ _ a]] by auto + moreover have "ya = yb" proof(rule ext) fix x show "ya x = yb x" proof(cases "x = a") + case False thus ?thesis using as(1)[THEN cong[of _ _ x x]] by auto next + case True thus ?thesis using as(5,7) using as0(2) by auto qed qed + ultimately show ?case unfolding goal1 by auto qed + have "finite s0" using `finite s` unfolding as0 by simp + show ?case unfolding as0 * card_image[OF inj] using assms + unfolding SetCompr_Sigma_eq apply- + unfolding card_cartesian_product + using Suc(1)[OF `finite s0` `finite t` ** `card t = n`] by auto +qed + +lemma card_funspace: assumes "finite s" "finite t" + shows "card {f. (\x\s. f x \ t) \ (\x\UNIV - s. f x = d)} = (card t) ^ (card s)" + using assms by (auto intro: card_funspace') + +lemma finite_funspace: assumes "finite s" "finite t" + shows "finite {f. (\x\s. f x \ t) \ (\x\UNIV - s. f x = d)}" (is "finite ?S") +proof (cases "card t > 0") + case True + have "card ?S = (card t) ^ (card s)" + using assms by (auto intro!: card_funspace) + thus ?thesis using True by (auto intro: card_ge_0_finite) +next + case False hence "t = {}" using `finite t` by auto + show ?thesis + proof (cases "s = {}") + have *:"{f. \x. f x = d} = {\x. d}" by (auto intro: ext) + case True thus ?thesis using `t = {}` by (auto simp: *) + next + case False thus ?thesis using `t = {}` by simp + qed +qed + +lemma finite_simplices: "finite {s. ksimplex p n s}" + apply(rule finite_subset[of _ "{s. s\{f. (\i\{1..n}. f i \ {0..p}) \ (\i\UNIV-{1..n}. f i = p)}}"]) + unfolding ksimplex_def defer apply(rule finite_Collect_subsets) apply(rule finite_funspace) by auto + +lemma simplex_top_face: assumes "0x\f. x (n + 1) = p" + shows "(\s a. ksimplex p (n + 1) s \ a \ s \ (f = s - {a})) \ ksimplex p n f" (is "?ls = ?rs") proof + assume ?ls then guess s .. then guess a apply-apply(erule exE,(erule conjE)+) . note sa=this + show ?rs unfolding ksimplex_def sa(3) apply(rule) defer apply rule defer apply(rule,rule,rule,rule) defer apply(rule,rule) proof- + fix x y assume as:"x \s - {a}" "y \s - {a}" have xyp:"x (n + 1) = y (n + 1)" + using as(1)[unfolded sa(3)[THEN sym], THEN assms(2)[rule_format]] + using as(2)[unfolded sa(3)[THEN sym], THEN assms(2)[rule_format]] by auto + show "kle n x y \ kle n y x" proof(cases "kle (n + 1) x y") + case True then guess k unfolding kle_def .. note k=this hence *:"n+1 \ k" using xyp by auto + have "\ (\x\k. x\{1..n})" apply(rule ccontr) unfolding not_not apply(erule bexE) proof- + fix x assume as:"x \ k" "x \ {1..n}" have "x \ n+1" using as and * by auto + thus False using as and k[THEN conjunct1,unfolded subset_eq] by auto qed + thus ?thesis apply-apply(rule disjI1) unfolding kle_def using k apply(rule_tac x=k in exI) by auto next + case False hence "kle (n + 1) y x" using ksimplexD(6)[OF sa(1),rule_format, of x y] using as by auto + then guess k unfolding kle_def .. note k=this hence *:"n+1 \ k" using xyp by auto + hence "\ (\x\k. x\{1..n})" apply-apply(rule ccontr) unfolding not_not apply(erule bexE) proof- + fix x assume as:"x \ k" "x \ {1..n}" have "x \ n+1" using as and * by auto + thus False using as and k[THEN conjunct1,unfolded subset_eq] by auto qed + thus ?thesis apply-apply(rule disjI2) unfolding kle_def using k apply(rule_tac x=k in exI) by auto qed next + fix x j assume as:"x\s - {a}" "j\{1..n}" + thus "x j = p" using as(1)[unfolded sa(3)[THEN sym], THEN assms(2)[rule_format]] + apply(cases "j = n+1") using sa(1)[unfolded ksimplex_def] by auto qed(insert sa ksimplexD[OF sa(1)], auto) next + assume ?rs note rs=ksimplexD[OF this] guess a b apply(rule ksimplex_extrema[OF `?rs`]) . note ab = this + def c \ "\i. if i = (n + 1) then p - 1 else a i" + have "c\f" apply(rule ccontr) unfolding not_not apply(drule assms(2)[rule_format]) unfolding c_def using assms(1) by auto + thus ?ls apply(rule_tac x="insert c f" in exI,rule_tac x=c in exI) unfolding ksimplex_def conj_assoc + apply(rule conjI) defer apply(rule conjI) defer apply(rule conjI) defer apply(rule conjI) defer + proof(rule_tac[3-5] ballI allI)+ + fix x j assume x:"x \ insert c f" thus "x j \ p" proof (cases "x=c") + case True show ?thesis unfolding True c_def apply(cases "j=n+1") using ab(1) and rs(4) by auto + qed(insert x rs(4), auto simp add:c_def) + show "j \ {1..n + 1} \ x j = p" apply(cases "x=c") using x ab(1) rs(5) unfolding c_def by auto + { fix z assume z:"z \ insert c f" hence "kle (n + 1) c z" apply(cases "z = c") (*defer apply(rule kle_Suc)*) proof- + case False hence "z\f" using z by auto + then guess k apply(drule_tac ab(3)[THEN bspec[where x=z], THEN conjunct1]) unfolding kle_def apply(erule exE) . + thus "kle (n + 1) c z" unfolding kle_def apply(rule_tac x="insert (n + 1) k" in exI) unfolding c_def + using ab using rs(5)[rule_format,OF ab(1),of "n + 1"] assms(1) by auto qed auto } note * = this + fix y assume y:"y \ insert c f" show "kle (n + 1) x y \ kle (n + 1) y x" proof(cases "x = c \ y = c") + case False hence **:"x\f" "y\f" using x y by auto + show ?thesis using rs(6)[rule_format,OF **] by(auto dest: kle_Suc) qed(insert * x y, auto) + qed(insert rs, auto) qed + +lemma ksimplex_fix_plane: + assumes "a \ s" "j\{1..n::nat}" "\x\s - {a}. x j = q" "a0 \ s" "a1 \ s" + "\i. a1 i = ((if i\{1..n} then a0 i + 1 else a0 i)::nat)" + shows "(a = a0) \ (a = a1)" proof- have *:"\P A x y. \x\A. P x \ x\A \ y\A \ P x \ P y" by auto + show ?thesis apply(rule ccontr) using *[OF assms(3), of a0 a1] unfolding assms(6)[THEN spec[where x=j]] + using assms(1-2,4-5) by auto qed + +lemma ksimplex_fix_plane_0: + assumes "a \ s" "j\{1..n::nat}" "\x\s - {a}. x j = 0" "a0 \ s" "a1 \ s" + "\i. a1 i = ((if i\{1..n} then a0 i + 1 else a0 i)::nat)" + shows "a = a1" apply(rule ccontr) using ksimplex_fix_plane[OF assms] + using assms(3)[THEN bspec[where x=a1]] using assms(2,5) + unfolding assms(6)[THEN spec[where x=j]] by simp + +lemma ksimplex_fix_plane_p: + assumes "ksimplex p n s" "a \ s" "j\{1..n}" "\x\s - {a}. x j = p" "a0 \ s" "a1 \ s" + "\i. a1 i = (if i\{1..n} then a0 i + 1 else a0 i)" + shows "a = a0" proof(rule ccontr) note s = ksimplexD[OF assms(1),rule_format] + assume as:"a \ a0" hence *:"a0 \ s - {a}" using assms(5) by auto + hence "a1 = a" using ksimplex_fix_plane[OF assms(2-)] by auto + thus False using as using assms(3,5) and assms(7)[rule_format,of j] + unfolding assms(4)[rule_format,OF *] using s(4)[OF assms(6), of j] by auto qed + +lemma ksimplex_replace_0: + assumes "ksimplex p n s" "a \ s" "n \ 0" "j\{1..n}" "\x\s - {a}. x j = 0" + shows "card {s'. ksimplex p n s' \ (\b\s'. s' - {b} = s - {a})} = 1" proof- + have *:"\s' a a'. s' - {a'} = s - {a} \ a' = a \ a' \ s' \ a \ s \ (s' = s)" by auto + have **:"\s' a'. ksimplex p n s' \ a' \ s' \ s' - {a'} = s - {a} \ s' = s" proof- case goal1 + guess a0 a1 apply(rule ksimplex_extrema_strong[OF assms(1,3)]) . note exta = this[rule_format] + have a:"a = a1" apply(rule ksimplex_fix_plane_0[OF assms(2,4-5)]) using exta(1-2,5) by auto moreover + guess b0 b1 apply(rule ksimplex_extrema_strong[OF goal1(1) assms(3)]) . note extb = this[rule_format] + have a':"a' = b1" apply(rule ksimplex_fix_plane_0[OF goal1(2) assms(4), of b0]) unfolding goal1(3) using assms extb goal1 by auto moreover + have "b0 = a0" unfolding kle_antisym[THEN sym, of b0 a0 n] using exta extb using goal1(3) unfolding a a' by blast + hence "b1 = a1" apply-apply(rule ext) unfolding exta(5) extb(5) by auto ultimately + show "s' = s" apply-apply(rule *[of _ a1 b1]) using exta(1-2) extb(1-2) goal1 by auto qed + show ?thesis unfolding card_1_exists apply-apply(rule ex1I[of _ s]) + unfolding mem_Collect_eq defer apply(erule conjE bexE)+ apply(rule_tac a'=b in **) using assms(1,2) by auto qed + +lemma ksimplex_replace_1: + assumes "ksimplex p n s" "a \ s" "n \ 0" "j\{1..n}" "\x\s - {a}. x j = p" + shows "card {s'. ksimplex p n s' \ (\b\s'. s' - {b} = s - {a})} = 1" proof- + have lem:"\a a' s'. s' - {a'} = s - {a} \ a' = a \ a' \ s' \ a \ s \ s' = s" by auto + have lem:"\s' a'. ksimplex p n s' \ a'\s' \ s' - {a'} = s - {a} \ s' = s" proof- case goal1 + guess a0 a1 apply(rule ksimplex_extrema_strong[OF assms(1,3)]) . note exta = this[rule_format] + have a:"a = a0" apply(rule ksimplex_fix_plane_p[OF assms(1-2,4-5) exta(1,2)]) unfolding exta by auto moreover + guess b0 b1 apply(rule ksimplex_extrema_strong[OF goal1(1) assms(3)]) . note extb = this[rule_format] + 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 + 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 + have "a0 = b0" apply(rule ext) proof- case goal1 show "a0 x = b0 x" + using *[THEN cong, of x x] unfolding exta extb apply-apply(cases "x\{1..n}") by auto qed + ultimately show "s' = s" apply-apply(rule lem[OF goal1(3) _ goal1(2) assms(2)]) by auto qed + show ?thesis unfolding card_1_exists apply(rule ex1I[of _ s]) unfolding mem_Collect_eq apply(rule,rule assms(1)) + 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 + +lemma ksimplex_replace_2: + assumes "ksimplex p n s" "a \ s" "n \ 0" "~(\j\{1..n}. \x\s - {a}. x j = 0)" "~(\j\{1..n}. \x\s - {a}. x j = p)" + shows "card {s'. ksimplex p n s' \ (\b\s'. s' - {b} = s - {a})} = 2" (is "card ?A = 2") proof- + have lem1:"\a a' s s'. s' - {a'} = s - {a} \ a' = a \ a' \ s' \ a \ s \ s' = s" by auto + have lem2:"\a b. a\s \ b\a \ s \ insert b (s - {a})" proof case goal1 + hence "a\insert b (s - {a})" by auto hence "a\ s - {a}" unfolding insert_iff using goal1 by auto + thus False by auto qed + guess a0 a1 apply(rule ksimplex_extrema_strong[OF assms(1,3)]) . note a0a1=this + { assume "a=a0" + have *:"\P Q. (P \ Q) \ \ P \ Q" by auto + have "\x\s. \ kle n x a0" apply(rule_tac x=a1 in bexI) proof assume as:"kle n a1 a0" + show False using kle_imp_pointwise[OF as,THEN spec[where x=1]] unfolding a0a1(5)[THEN spec[where x=1]] + using assms(3) by auto qed(insert a0a1,auto) + hence "\y\s. \k\{1..n}. \j. y j = (if j = k then a0 j + 1 else a0 j)" + apply(rule_tac *[OF ksimplex_successor[OF assms(1-2),unfolded `a=a0`]]) by auto + then guess a2 .. from this(2) guess k .. note k=this note a2=`a2\s` + def a3 \ "\j. if j = k then a1 j + 1 else a1 j" + have "a3 \ s" proof assume "a3\s" hence "kle n a3 a1" using a0a1(4) by auto + thus False apply(drule_tac kle_imp_pointwise) unfolding a3_def + apply(erule_tac x=k in allE) by auto qed + hence "a3 \ a0" "a3 \ a1" using a0a1 by auto + have "a2 \ a0" using k(2)[THEN spec[where x=k]] by auto + have lem3:"\x. x\(s - {a0}) \ kle n a2 x" proof(rule ccontr) case goal1 hence as:"x\s" "x\a0" by auto + have "kle n a2 x \ kle n x a2" using ksimplexD(6)[OF assms(1)] and as `a2\s` by auto moreover + have "kle n a0 x" using a0a1(4) as by auto + ultimately have "x = a0 \ x = a2" apply-apply(rule kle_adjacent[OF k(2)]) using goal1(2) by auto + hence "x = a2" using as by auto thus False using goal1(2) using kle_refl by auto qed + let ?s = "insert a3 (s - {a0})" have "ksimplex p n ?s" apply(rule ksimplexI) proof(rule_tac[2-] ballI,rule_tac[4] ballI) + show "card ?s = n + 1" using ksimplexD(2-3)[OF assms(1)] + using `a3\a0` `a3\s` `a0\s` by(auto simp add:card_insert_if) + fix x assume x:"x \ insert a3 (s - {a0})" + show "\j. x j \ p" proof(rule,cases "x = a3") + fix j case False thus "x j\p" using x ksimplexD(4)[OF assms(1)] by auto next + fix j case True show "x j\p" unfolding True proof(cases "j=k") + case False thus "a3 j \p" unfolding True a3_def using `a1\s` ksimplexD(4)[OF assms(1)] by auto next + guess a4 using assms(5)[unfolded bex_simps ball_simps,rule_format,OF k(1)] .. note a4=this + have "a2 k \ a4 k" using lem3[OF a4(1)[unfolded `a=a0`],THEN kle_imp_pointwise] by auto + also have "\ < p" using ksimplexD(4)[OF assms(1),rule_format,of a4 k] using a4 by auto + finally have *:"a0 k + 1 < p" unfolding k(2)[rule_format] by auto + case True thus "a3 j \p" unfolding a3_def unfolding a0a1(5)[rule_format] + using k(1) k(2)assms(5) using * by simp qed qed + show "\j. j \ {1..n} \ x j = p" proof(rule,rule,cases "x=a3") fix j::nat assume j:"j\{1..n}" + { case False thus "x j = p" using j x ksimplexD(5)[OF assms(1)] by auto } + case True show "x j = p" unfolding True a3_def using j k(1) + using ksimplexD(5)[OF assms(1),rule_format,OF `a1\s` j] by auto qed + fix y assume y:"y\insert a3 (s - {a0})" + have lem4:"\x. x\s \ x\a0 \ kle n x a3" proof- case goal1 + guess kk using a0a1(4)[rule_format,OF `x\s`,THEN conjunct2,unfolded kle_def] + apply-apply(erule exE,erule conjE) . note kk=this + have "k\kk" proof assume "k\kk" + hence "a1 k = x k + 1" using kk by auto + hence "a0 k = x k" unfolding a0a1(5)[rule_format] using k(1) by auto + hence "a2 k = x k + 1" unfolding k(2)[rule_format] by auto moreover + have "a2 k \ x k" using lem3[of x,THEN kle_imp_pointwise] goal1 by auto + ultimately show False by auto qed + thus ?case unfolding kle_def apply(rule_tac x="insert k kk" in exI) using kk(1) + unfolding a3_def kle_def kk(2)[rule_format] using k(1) by auto qed + show "kle n x y \ kle n y x" proof(cases "y=a3") + case True show ?thesis unfolding True apply(cases "x=a3") defer apply(rule disjI1,rule lem4) + using x by auto next + case False show ?thesis proof(cases "x=a3") case True show ?thesis unfolding True + apply(rule disjI2,rule lem4) using y False by auto next + case False thus ?thesis apply(rule_tac ksimplexD(6)[OF assms(1),rule_format]) + using x y `y\a3` by auto qed qed qed + hence "insert a3 (s - {a0}) \ ?A" unfolding mem_Collect_eq apply-apply(rule,assumption) + apply(rule_tac x="a3" in bexI) unfolding `a=a0` using `a3\s` by auto moreover + have "s \ ?A" using assms(1,2) by auto ultimately have "?A \ {s, insert a3 (s - {a0})}" by auto + moreover have "?A \ {s, insert a3 (s - {a0})}" apply(rule) unfolding mem_Collect_eq proof(erule conjE) + fix s' assume as:"ksimplex p n s'" and "\b\s'. s' - {b} = s - {a}" + from this(2) guess a' .. note a'=this + guess a_min a_max apply(rule ksimplex_extrema_strong[OF as assms(3)]) . note min_max=this + have *:"\x\s' - {a'}. x k = a2 k" unfolding a' proof fix x assume x:"x\s-{a}" + hence "kle n a2 x" apply-apply(rule lem3) using `a=a0` by auto + hence "a2 k \ x k" apply(drule_tac kle_imp_pointwise) by auto moreover + have "x k \ a2 k" unfolding k(2)[rule_format] using a0a1(4)[rule_format,of x,THEN conjunct1] + unfolding kle_def using x by auto ultimately show "x k = a2 k" by auto qed + have **:"a'=a_min \ a'=a_max" apply(rule ksimplex_fix_plane[OF a'(1) k(1) *]) using min_max by auto + show "s' \ {s, insert a3 (s - {a0})}" proof(cases "a'=a_min") + case True have "a_max = a1" unfolding kle_antisym[THEN sym,of a_max a1 n] apply(rule) + apply(rule a0a1(4)[rule_format,THEN conjunct2]) defer proof(rule min_max(4)[rule_format,THEN conjunct2]) + show "a1\s'" using a' unfolding `a=a0` using a0a1 by auto + show "a_max \ s" proof(rule ccontr) assume "a_max\s" + hence "a_max = a'" using a' min_max by auto + thus False unfolding True using min_max by auto qed qed + hence "\i. a_max i = a1 i" by auto + hence "a' = a" unfolding True `a=a0` apply-apply(subst expand_fun_eq,rule) + apply(erule_tac x=x in allE) unfolding a0a1(5)[rule_format] min_max(5)[rule_format] + proof- case goal1 thus ?case apply(cases "x\{1..n}") by auto qed + hence "s' = s" apply-apply(rule lem1[OF a'(2)]) using `a\s` `a'\s'` by auto + thus ?thesis by auto next + case False hence as:"a' = a_max" using ** by auto + have "a_min = a2" unfolding kle_antisym[THEN sym, of _ _ n] apply rule + apply(rule min_max(4)[rule_format,THEN conjunct1]) defer proof(rule lem3) + show "a_min \ s - {a0}" unfolding a'(2)[THEN sym,unfolded `a=a0`] + unfolding as using min_max(1-3) by auto + have "a2 \ a" unfolding `a=a0` using k(2)[rule_format,of k] by auto + hence "a2 \ s - {a}" using a2 by auto thus "a2 \ s'" unfolding a'(2)[THEN sym] by auto qed + hence "\i. a_min i = a2 i" by auto + hence "a' = a3" unfolding as `a=a0` apply-apply(subst expand_fun_eq,rule) + apply(erule_tac x=x in allE) unfolding a0a1(5)[rule_format] min_max(5)[rule_format] + unfolding a3_def k(2)[rule_format] unfolding a0a1(5)[rule_format] proof- case goal1 + show ?case unfolding goal1 apply(cases "x\{1..n}") defer apply(cases "x=k") + using `k\{1..n}` by auto qed + hence "s' = insert a3 (s - {a0})" apply-apply(rule lem1) defer apply assumption + apply(rule a'(1)) unfolding a' `a=a0` using `a3\s` by auto + thus ?thesis by auto qed qed + ultimately have *:"?A = {s, insert a3 (s - {a0})}" by blast + have "s \ insert a3 (s - {a0})" using `a3\s` by auto + hence ?thesis unfolding * by auto } moreover + { assume "a=a1" + have *:"\P Q. (P \ Q) \ \ P \ Q" by auto + have "\x\s. \ kle n a1 x" apply(rule_tac x=a0 in bexI) proof assume as:"kle n a1 a0" + show False using kle_imp_pointwise[OF as,THEN spec[where x=1]] unfolding a0a1(5)[THEN spec[where x=1]] + using assms(3) by auto qed(insert a0a1,auto) + hence "\y\s. \k\{1..n}. \j. a1 j = (if j = k then y j + 1 else y j)" + apply(rule_tac *[OF ksimplex_predecessor[OF assms(1-2),unfolded `a=a1`]]) by auto + then guess a2 .. from this(2) guess k .. note k=this note a2=`a2\s` + def a3 \ "\j. if j = k then a0 j - 1 else a0 j" + have "a2 \ a1" using k(2)[THEN spec[where x=k]] by auto + have lem3:"\x. x\(s - {a1}) \ kle n x a2" proof(rule ccontr) case goal1 hence as:"x\s" "x\a1" by auto + have "kle n a2 x \ kle n x a2" using ksimplexD(6)[OF assms(1)] and as `a2\s` by auto moreover + have "kle n x a1" using a0a1(4) as by auto + ultimately have "x = a2 \ x = a1" apply-apply(rule kle_adjacent[OF k(2)]) using goal1(2) by auto + hence "x = a2" using as by auto thus False using goal1(2) using kle_refl by auto qed + have "a0 k \ 0" proof- + guess a4 using assms(4)[unfolded bex_simps ball_simps,rule_format,OF `k\{1..n}`] .. note a4=this + have "a4 k \ a2 k" using lem3[OF a4(1)[unfolded `a=a1`],THEN kle_imp_pointwise] by auto + moreover have "a4 k > 0" using a4 by auto ultimately have "a2 k > 0" by auto + hence "a1 k > 1" unfolding k(2)[rule_format] by simp + thus ?thesis unfolding a0a1(5)[rule_format] using k(1) by simp qed + hence lem4:"\j. a0 j = (if j=k then a3 j + 1 else a3 j)" unfolding a3_def by simp + have "\ kle n a0 a3" apply(rule ccontr) unfolding not_not apply(drule kle_imp_pointwise) + unfolding lem4[rule_format] apply(erule_tac x=k in allE) by auto + hence "a3 \ s" using a0a1(4) by auto + hence "a3 \ a1" "a3 \ a0" using a0a1 by auto + let ?s = "insert a3 (s - {a1})" have "ksimplex p n ?s" apply(rule ksimplexI) proof(rule_tac[2-] ballI,rule_tac[4] ballI) + show "card ?s = n+1" using ksimplexD(2-3)[OF assms(1)] + using `a3\a0` `a3\s` `a1\s` by(auto simp add:card_insert_if) + fix x assume x:"x \ insert a3 (s - {a1})" + show "\j. x j \ p" proof(rule,cases "x = a3") + fix j case False thus "x j\p" using x ksimplexD(4)[OF assms(1)] by auto next + fix j case True show "x j\p" unfolding True proof(cases "j=k") + case False thus "a3 j \p" unfolding True a3_def using `a0\s` ksimplexD(4)[OF assms(1)] by auto next + guess a4 using assms(5)[unfolded bex_simps ball_simps,rule_format,OF k(1)] .. note a4=this + case True have "a3 k \ a0 k" unfolding lem4[rule_format] by auto + also have "\ \ p" using ksimplexD(4)[OF assms(1),rule_format,of a0 k] a0a1 by auto + finally show "a3 j \ p" unfolding True by auto qed qed + show "\j. j \ {1..n} \ x j = p" proof(rule,rule,cases "x=a3") fix j::nat assume j:"j\{1..n}" + { case False thus "x j = p" using j x ksimplexD(5)[OF assms(1)] by auto } + case True show "x j = p" unfolding True a3_def using j k(1) + using ksimplexD(5)[OF assms(1),rule_format,OF `a0\s` j] by auto qed + fix y assume y:"y\insert a3 (s - {a1})" + have lem4:"\x. x\s \ x\a1 \ kle n a3 x" proof- case goal1 hence *:"x\s - {a1}" by auto + have "kle n a3 a2" proof- have "kle n a0 a1" using a0a1 by auto then guess kk unfolding kle_def .. + thus ?thesis unfolding kle_def apply(rule_tac x=kk in exI) unfolding lem4[rule_format] k(2)[rule_format] + apply(rule)defer proof(rule) case goal1 thus ?case apply-apply(erule conjE) + apply(erule_tac[!] x=j in allE) apply(cases "j\kk") apply(case_tac[!] "j=k") by auto qed auto qed moreover + have "kle n a3 a0" unfolding kle_def lem4[rule_format] apply(rule_tac x="{k}" in exI) using k(1) by auto + ultimately show ?case apply-apply(rule kle_between_l[of _ a0 _ a2]) using lem3[OF *] + using a0a1(4)[rule_format,OF goal1(1)] by auto qed + show "kle n x y \ kle n y x" proof(cases "y=a3") + case True show ?thesis unfolding True apply(cases "x=a3") defer apply(rule disjI2,rule lem4) + using x by auto next + case False show ?thesis proof(cases "x=a3") case True show ?thesis unfolding True + apply(rule disjI1,rule lem4) using y False by auto next + case False thus ?thesis apply(rule_tac ksimplexD(6)[OF assms(1),rule_format]) + using x y `y\a3` by auto qed qed qed + hence "insert a3 (s - {a1}) \ ?A" unfolding mem_Collect_eq apply-apply(rule,assumption) + apply(rule_tac x="a3" in bexI) unfolding `a=a1` using `a3\s` by auto moreover + have "s \ ?A" using assms(1,2) by auto ultimately have "?A \ {s, insert a3 (s - {a1})}" by auto + moreover have "?A \ {s, insert a3 (s - {a1})}" apply(rule) unfolding mem_Collect_eq proof(erule conjE) + fix s' assume as:"ksimplex p n s'" and "\b\s'. s' - {b} = s - {a}" + from this(2) guess a' .. note a'=this + guess a_min a_max apply(rule ksimplex_extrema_strong[OF as assms(3)]) . note min_max=this + have *:"\x\s' - {a'}. x k = a2 k" unfolding a' proof fix x assume x:"x\s-{a}" + hence "kle n x a2" apply-apply(rule lem3) using `a=a1` by auto + hence "x k \ a2 k" apply(drule_tac kle_imp_pointwise) by auto moreover + { have "a2 k \ a0 k" using k(2)[rule_format,of k] unfolding a0a1(5)[rule_format] using k(1) by simp + also have "\ \ x k" using a0a1(4)[rule_format,of x,THEN conjunct1,THEN kle_imp_pointwise] x by auto + finally have "a2 k \ x k" . } ultimately show "x k = a2 k" by auto qed + have **:"a'=a_min \ a'=a_max" apply(rule ksimplex_fix_plane[OF a'(1) k(1) *]) using min_max by auto + have "a2 \ a1" proof assume as:"a2 = a1" + show False using k(2) unfolding as apply(erule_tac x=k in allE) by auto qed + hence a2':"a2 \ s' - {a'}" unfolding a' using a2 unfolding `a=a1` by auto + show "s' \ {s, insert a3 (s - {a1})}" proof(cases "a'=a_min") + case True have "a_max \ s - {a1}" using min_max unfolding a'(2)[unfolded `a=a1`,THEN sym] True by auto + hence "a_max = a2" unfolding kle_antisym[THEN sym,of a_max a2 n] apply-apply(rule) + apply(rule lem3,assumption) apply(rule min_max(4)[rule_format,THEN conjunct2]) using a2' by auto + hence a_max:"\i. a_max i = a2 i" by auto + have *:"\j. a2 j = (if j\{1..n} then a3 j + 1 else a3 j)" + using k(2) unfolding lem4[rule_format] a0a1(5)[rule_format] apply-apply(rule,erule_tac x=j in allE) + proof- case goal1 thus ?case apply(cases "j\{1..n}",case_tac[!] "j=k") by auto qed + have "\i. a_min i = a3 i" using a_max apply-apply(rule,erule_tac x=i in allE) + unfolding min_max(5)[rule_format] *[rule_format] proof- case goal1 + thus ?case apply(cases "i\{1..n}") by auto qed hence "a_min = a3" unfolding expand_fun_eq . + hence "s' = insert a3 (s - {a1})" using a' unfolding `a=a1` True by auto thus ?thesis by auto next + case False hence as:"a'=a_max" using ** by auto + have "a_min = a0" unfolding kle_antisym[THEN sym,of _ _ n] apply(rule) + apply(rule min_max(4)[rule_format,THEN conjunct1]) defer apply(rule a0a1(4)[rule_format,THEN conjunct1]) proof- + have "a_min \ s - {a1}" using min_max(1,3) unfolding a'(2)[THEN sym,unfolded `a=a1`] as by auto + thus "a_min \ s" by auto have "a0 \ s - {a1}" using a0a1(1-3) by auto thus "a0 \ s'" + unfolding a'(2)[THEN sym,unfolded `a=a1`] by auto qed + hence "\i. a_max i = a1 i" unfolding a0a1(5)[rule_format] min_max(5)[rule_format] by auto + hence "s' = s" apply-apply(rule lem1[OF a'(2)]) using `a\s` `a'\s'` unfolding as `a=a1` unfolding expand_fun_eq by auto + thus ?thesis by auto qed qed + ultimately have *:"?A = {s, insert a3 (s - {a1})}" by blast + have "s \ insert a3 (s - {a1})" using `a3\s` by auto + hence ?thesis unfolding * by auto } moreover + { assume as:"a\a0" "a\a1" have "\ (\x\s. kle n a x)" proof case goal1 + have "a=a0" unfolding kle_antisym[THEN sym,of _ _ n] apply(rule) + using goal1 a0a1 assms(2) by auto thus False using as by auto qed + hence "\y\s. \k\{1..n}. \j. a j = (if j = k then y j + 1 else y j)" using ksimplex_predecessor[OF assms(1-2)] by blast + then guess u .. from this(2) guess k .. note k = this[rule_format] note u = `u\s` + have "\ (\x\s. kle n x a)" proof case goal1 + have "a=a1" unfolding kle_antisym[THEN sym,of _ _ n] apply(rule) + using goal1 a0a1 assms(2) by auto thus False using as by auto qed + hence "\y\s. \k\{1..n}. \j. y j = (if j = k then a j + 1 else a j)" using ksimplex_successor[OF assms(1-2)] by blast + then guess v .. from this(2) guess l .. note l = this[rule_format] note v = `v\s` + def a' \ "\j. if j = l then u j + 1 else u j" + have kl:"k \ l" proof assume "k=l" have *:"\P. (if P then (1::nat) else 0) \ 2" by auto + thus False using ksimplexD(6)[OF assms(1),rule_format,OF u v] unfolding kle_def + unfolding l(2) k(2) `k=l` apply-apply(erule disjE)apply(erule_tac[!] exE conjE)+ + apply(erule_tac[!] x=l in allE)+ by(auto simp add: *) qed + hence aa':"a'\a" apply-apply rule unfolding expand_fun_eq unfolding a'_def k(2) + apply(erule_tac x=l in allE) by auto + have "a' \ s" apply(rule) apply(drule ksimplexD(6)[OF assms(1),rule_format,OF `a\s`]) proof(cases "kle n a a'") + case goal2 hence "kle n a' a" by auto thus False apply(drule_tac kle_imp_pointwise) + apply(erule_tac x=l in allE) unfolding a'_def k(2) using kl by auto next + case True thus False apply(drule_tac kle_imp_pointwise) + apply(erule_tac x=k in allE) unfolding a'_def k(2) using kl by auto qed + have kle_uv:"kle n u a" "kle n u a'" "kle n a v" "kle n a' v" unfolding kle_def apply- + apply(rule_tac[1] x="{k}" in exI,rule_tac[2] x="{l}" in exI) + apply(rule_tac[3] x="{l}" in exI,rule_tac[4] x="{k}" in exI) + unfolding l(2) k(2) a'_def using l(1) k(1) by auto + have uxv:"\x. kle n u x \ kle n x v \ (x = u) \ (x = a) \ (x = a') \ (x = v)" + proof- case goal1 thus ?case proof(cases "x k = u k", case_tac[!] "x l = u l") + assume as:"x l = u l" "x k = u k" + have "x = u" unfolding expand_fun_eq + using goal1(2)[THEN kle_imp_pointwise,unfolded l(2)] unfolding k(2) apply- + using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1 + thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as by auto qed thus ?case by auto next + assume as:"x l \ u l" "x k = u k" + have "x = a'" unfolding expand_fun_eq unfolding a'_def + using goal1(2)[THEN kle_imp_pointwise] unfolding l(2) k(2) apply- + using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1 + thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as by auto qed thus ?case by auto next + assume as:"x l = u l" "x k \ u k" + have "x = a" unfolding expand_fun_eq + using goal1(2)[THEN kle_imp_pointwise] unfolding l(2) k(2) apply- + using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1 + thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as by auto qed thus ?case by auto next + assume as:"x l \ u l" "x k \ u k" + have "x = v" unfolding expand_fun_eq + using goal1(2)[THEN kle_imp_pointwise] unfolding l(2) k(2) apply- + using goal1(1)[THEN kle_imp_pointwise] apply-apply rule apply(erule_tac x=xa in allE)+ proof- case goal1 + thus ?case apply(cases "x=l") apply(case_tac[!] "x=k") using as `k\l` by auto qed thus ?case by auto qed qed + 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 + have lem3:"\x. x\s \ kle n v x \ kle n a' x" apply(rule kle_between_r[of _ u _ v]) + prefer 3 apply(rule kle_trans[OF uv]) defer apply(rule ksimplexD(6)[OF assms(1),rule_format]) + using kle_uv `u\s` by auto + have lem4:"\x. x\s \ kle n x u \ kle n x a'" apply(rule kle_between_l[of _ u _ v]) + prefer 4 apply(rule kle_trans[OF _ uv]) defer apply(rule ksimplexD(6)[OF assms(1),rule_format]) + using kle_uv `v\s` by auto + have lem5:"\x. x\s \ x\a \ kle n x a' \ kle n a' x" proof- case goal1 thus ?case + proof(cases "kle n v x \ kle n x u") case True thus ?thesis using goal1 by(auto intro:lem3 lem4) next + case False hence *:"kle n u x" "kle n x v" using ksimplexD(6)[OF assms(1)] using goal1 `u\s` `v\s` by auto + show ?thesis using uxv[OF *] using kle_uv using goal1 by auto qed qed + have "ksimplex p n (insert a' (s - {a}))" apply(rule ksimplexI) proof(rule_tac[2-] ballI,rule_tac[4] ballI) + show "card (insert a' (s - {a})) = n + 1" using ksimplexD(2-3)[OF assms(1)] + using `a'\a` `a'\s` `a\s` by(auto simp add:card_insert_if) + fix x assume x:"x \ insert a' (s - {a})" + show "\j. x j \ p" proof(rule,cases "x = a'") + fix j case False thus "x j\p" using x ksimplexD(4)[OF assms(1)] by auto next + fix j case True show "x j\p" unfolding True proof(cases "j=l") + case False thus "a' j \p" unfolding True a'_def using `u\s` ksimplexD(4)[OF assms(1)] by auto next + case True have *:"a l = u l" "v l = a l + 1" using k(2)[of l] l(2)[of l] `k\l` by auto + have "u l + 1 \ p" unfolding *[THEN sym] using ksimplexD(4)[OF assms(1)] using `v\s` by auto + thus "a' j \p" unfolding a'_def True by auto qed qed + show "\j. j \ {1..n} \ x j = p" proof(rule,rule,cases "x=a'") fix j::nat assume j:"j\{1..n}" + { case False thus "x j = p" using j x ksimplexD(5)[OF assms(1)] by auto } + case True show "x j = p" unfolding True a'_def using j l(1) + using ksimplexD(5)[OF assms(1),rule_format,OF `u\s` j] by auto qed + fix y assume y:"y\insert a' (s - {a})" + show "kle n x y \ kle n y x" proof(cases "y=a'") + case True show ?thesis unfolding True apply(cases "x=a'") defer apply(rule lem5) using x by auto next + case False show ?thesis proof(cases "x=a'") case True show ?thesis unfolding True + using lem5[of y] using y by auto next + case False thus ?thesis apply(rule_tac ksimplexD(6)[OF assms(1),rule_format]) + using x y `y\a'` by auto qed qed qed + hence "insert a' (s - {a}) \ ?A" unfolding mem_Collect_eq apply-apply(rule,assumption) + apply(rule_tac x="a'" in bexI) using aa' `a'\s` by auto moreover + have "s \ ?A" using assms(1,2) by auto ultimately have "?A \ {s, insert a' (s - {a})}" by auto + moreover have "?A \ {s, insert a' (s - {a})}" apply(rule) unfolding mem_Collect_eq proof(erule conjE) + fix s' assume as:"ksimplex p n s'" and "\b\s'. s' - {b} = s - {a}" + from this(2) guess a'' .. note a''=this + have "u\v" unfolding expand_fun_eq unfolding l(2) k(2) by auto + hence uv':"\ kle n v u" using uv using kle_antisym by auto + have "u\a" "v\a" unfolding expand_fun_eq k(2) l(2) by auto + hence uvs':"u\s'" "v\s'" using `u\s` `v\s` using a'' by auto + have lem6:"a \ s' \ a' \ s'" proof(cases "\x\s'. kle n x u \ kle n v x") + case False then guess w unfolding ball_simps .. note w=this + hence "kle n u w" "kle n w v" using ksimplexD(6)[OF as] uvs' by auto + hence "w = a' \ w = a" using uxv[of w] uvs' w by auto thus ?thesis using w by auto next + case True have "\ (\x\s'. kle n x u)" unfolding ball_simps apply(rule_tac x=v in bexI) + using uv `u\v` unfolding kle_antisym[of n u v,THEN sym] using `v\s'` by auto + hence "\y\s'. \k\{1..n}. \j. y j = (if j = k then u j + 1 else u j)" using ksimplex_successor[OF as `u\s'`] by blast + then guess w .. note w=this from this(2) guess kk .. note kk=this[rule_format] + have "\ kle n w u" apply-apply(rule,drule kle_imp_pointwise) + apply(erule_tac x=kk in allE) unfolding kk by auto + hence *:"kle n v w" using True[rule_format,OF w(1)] by auto + hence False proof(cases "kk\l") case True thus False using *[THEN kle_imp_pointwise, unfolded l(2) kk k(2)] + apply(erule_tac x=l in allE) using `k\l` by auto next + case False hence "kk\k" using `k\l` by auto thus False using *[THEN kle_imp_pointwise, unfolded l(2) kk k(2)] + apply(erule_tac x=k in allE) using `k\l` by auto qed + thus ?thesis by auto qed + thus "s' \ {s, insert a' (s - {a})}" proof(cases "a\s'") + case True hence "s' = s" apply-apply(rule lem1[OF a''(2)]) using a'' `a\s` by auto + thus ?thesis by auto next case False hence "a'\s'" using lem6 by auto + hence "s' = insert a' (s - {a})" apply-apply(rule lem1[of _ a'' _ a']) + unfolding a''(2)[THEN sym] using a'' using `a'\s` by auto + thus ?thesis by auto qed qed + ultimately have *:"?A = {s, insert a' (s - {a})}" by blast + have "s \ insert a' (s - {a})" using `a'\s` by auto + hence ?thesis unfolding * by auto } + ultimately show ?thesis by auto qed + +subsection {* Hence another step towards concreteness. *} + +lemma kuhn_simplex_lemma: + assumes "\s. ksimplex p (n + 1) s \ (rl ` s \{0..n+1})" + "odd (card{f. \s a. ksimplex p (n + 1) s \ a \ s \ (f = s - {a}) \ + (rl ` f = {0 .. n}) \ ((\j\{1..n+1}.\x\f. x j = 0) \ (\j\{1..n+1}.\x\f. x j = p))})" + shows "odd(card {s\{s. ksimplex p (n + 1) s}. rl ` s = {0..n+1} })" proof- + have *:"\x y. x = y \ odd (card x) \ odd (card y)" by auto + have *:"odd(card {f\{f. \s\{s. ksimplex p (n + 1) s}. (\a\s. f = s - {a})}. + (rl ` f = {0..n}) \ + ((\j\{1..n+1}. \x\f. x j = 0) \ + (\j\{1..n+1}. \x\f. x j = p))})" apply(rule *[OF _ assms(2)]) by auto + show ?thesis apply(rule kuhn_complete_lemma[OF finite_simplices]) prefer 6 apply(rule *) apply(rule,rule,rule) + apply(subst ksimplex_def) defer apply(rule,rule assms(1)[rule_format]) unfolding mem_Collect_eq apply assumption + apply default+ unfolding mem_Collect_eq apply(erule disjE bexE)+ defer apply(erule disjE bexE)+ defer + apply default+ unfolding mem_Collect_eq apply(erule disjE bexE)+ unfolding mem_Collect_eq proof- + fix f s a assume as:"ksimplex p (n + 1) s" "a\s" "f = s - {a}" + let ?S = "{s. ksimplex p (n + 1) s \ (\a\s. f = s - {a})}" + have S:"?S = {s'. ksimplex p (n + 1) s' \ (\b\s'. s' - {b} = s - {a})}" unfolding as by blast + { fix j assume j:"j \ {1..n + 1}" "\x\f. x j = 0" thus "card {s. ksimplex p (n + 1) s \ (\a\s. f = s - {a})} = 1" unfolding S + apply-apply(rule ksimplex_replace_0) apply(rule as)+ unfolding as by auto } + { fix j assume j:"j \ {1..n + 1}" "\x\f. x j = p" thus "card {s. ksimplex p (n + 1) s \ (\a\s. f = s - {a})} = 1" unfolding S + apply-apply(rule ksimplex_replace_1) apply(rule as)+ unfolding as by auto } + show "\ ((\j\{1..n+1}. \x\f. x j = 0) \ (\j\{1..n+1}. \x\f. x j = p)) \ card ?S = 2" + unfolding S apply(rule ksimplex_replace_2) apply(rule as)+ unfolding as by auto qed auto qed + +subsection {* Reduced labelling. *} + +definition "reduced label (n::nat) (x::nat\nat) = + (SOME k. k \ n \ (\i. 1\i \ i label x i = 0) \ (k = n \ label x (k + 1) \ (0::nat)))" + +lemma reduced_labelling: shows "reduced label n x \ n" (is ?t1) and + "\i. 1\i \ i < reduced label n x + 1 \ (label x i = 0)" (is ?t2) + "(reduced label n x = n) \ (label x (reduced label n x + 1) \ 0)" (is ?t3) proof- + have num_WOP:"\P k. P (k::nat) \ \n. P n \ (\m P m)" + apply(drule ex_has_least_nat[where m="\x. x"]) apply(erule exE,rule_tac x=x in exI) by auto + have *:"n \ n \ (label x (n + 1) \ 0 \ n = n)" by auto + then guess N apply(drule_tac num_WOP[of "\j. j\n \ (label x (j+1) \ 0 \ n = j)"]) apply(erule exE) . note N=this + have N':"N \ n" "\i. 1 \ i \ i < N + 1 \ label x i = 0" "N = n \ label x (N + 1) \ 0" defer proof(rule,rule) + fix i assume i:"1\i \ i nat" + assumes "r \ n" "\i. 1 \ i \ i < r + 1 \ (label x i = 0)" "(r = n) \ (label x (r + 1) \ 0)" + shows "reduced label n x = r" apply(rule le_antisym) apply(rule_tac[!] ccontr) unfolding not_le + using reduced_labelling[of label n x] using assms by auto + +lemma reduced_labelling_0: assumes "j\{1..n}" "label x j = 0" shows "reduced label n x \ j - 1" + using reduced_labelling[of label n x] using assms by fastsimp + +lemma reduced_labelling_1: assumes "j\{1..n}" "label x j \ 0" shows "reduced label n x < j" + using assms and reduced_labelling[of label n x] apply(erule_tac x=j in allE) by auto + +lemma reduced_labelling_Suc: + assumes "reduced lab (n + 1) x \ n + 1" shows "reduced lab (n + 1) x = reduced lab n x" + apply(subst eq_commute) apply(rule reduced_labelling_unique) + using reduced_labelling[of lab "n+1" x] and assms by auto + +lemma complete_face_top: + assumes "\x\f. \j\{1..n+1}. x j = 0 \ lab x j = 0" + "\x\f. \j\{1..n+1}. x j = p \ lab x j = 1" + shows "((reduced lab (n + 1)) ` f = {0..n}) \ ((\j\{1..n+1}. \x\f. x j = 0) \ (\j\{1..n+1}. \x\f. x j = p)) \ + ((reduced lab (n + 1)) ` f = {0..n}) \ (\x\f. x (n + 1) = p)" (is "?l = ?r") proof + assume ?l (is "?as \ (?a \ ?b)") thus ?r apply-apply(rule,erule conjE,assumption) proof(cases ?a) + case True then guess j .. note j=this {fix x assume x:"x\f" + have "reduced lab (n+1) x \ j - 1" using j apply-apply(rule reduced_labelling_0) defer apply(rule assms(1)[rule_format]) using x by auto } + moreover have "j - 1 \ {0..n}" using j by auto + then guess y unfolding `?l`[THEN conjunct1,THEN sym] and image_iff .. note y = this + ultimately have False by auto thus "\x\f. x (n + 1) = p" by auto next + + case False hence ?b using `?l` by blast then guess j .. note j=this {fix x assume x:"x\f" + have "reduced lab (n+1) x < j" using j apply-apply(rule reduced_labelling_1) using assms(2)[rule_format,of x j] and x by auto } note * = this + have "j = n + 1" proof(rule ccontr) case goal1 hence "j < n + 1" using j by auto moreover + have "n \ {0..n}" by auto then guess y unfolding `?l`[THEN conjunct1,THEN sym] image_iff .. + ultimately show False using *[of y] by auto qed + thus "\x\f. x (n + 1) = p" using j by auto qed qed(auto) + +subsection {* Hence we get just about the nice induction. *} + +lemma kuhn_induction: + assumes "0 < p" "\x. \j\{1..n+1}. (\j. x j \ p) \ (x j = 0) \ (lab x j = 0)" + "\x. \j\{1..n+1}. (\j. x j \ p) \ (x j = p) \ (lab x j = 1)" + "odd (card {f. ksimplex p n f \ ((reduced lab n) ` f = {0..n})})" + shows "odd (card {s. ksimplex p (n+1) s \((reduced lab (n+1)) ` s = {0..n+1})})" proof- + have *:"\s t. odd (card s) \ s = t \ odd (card t)" "\s f. (\x. f x \ n +1 ) \ f ` s \ {0..n+1}" by auto + show ?thesis apply(rule kuhn_simplex_lemma[unfolded mem_Collect_eq]) apply(rule,rule,rule *,rule reduced_labelling) + apply(rule *(1)[OF assms(4)]) apply(rule set_ext) unfolding mem_Collect_eq apply(rule,erule conjE) defer apply(rule) proof-(*(rule,rule)*) + fix f assume as:"ksimplex p n f" "reduced lab n ` f = {0..n}" + have *:"\x\f. \j\{1..n + 1}. x j = 0 \ lab x j = 0" "\x\f. \j\{1..n + 1}. x j = p \ lab x j = 1" + using assms(2-3) using as(1)[unfolded ksimplex_def] by auto + have allp:"\x\f. x (n + 1) = p" using assms(2) using as(1)[unfolded ksimplex_def] by auto + { fix x assume "x\f" hence "reduced lab (n + 1) x < n + 1" apply-apply(rule reduced_labelling_1) + defer using assms(3) using as(1)[unfolded ksimplex_def] by auto + hence "reduced lab (n + 1) x = reduced lab n x" apply-apply(rule reduced_labelling_Suc) using reduced_labelling(1) by auto } + hence "reduced lab (n + 1) ` f = {0..n}" unfolding as(2)[THEN sym] apply- apply(rule set_ext) unfolding image_iff by auto + moreover guess s using as(1)[unfolded simplex_top_face[OF assms(1) allp,THEN sym]] .. then guess a .. + ultimately show "\s a. ksimplex p (n + 1) s \ + a \ s \ f = s - {a} \ reduced lab (n + 1) ` f = {0..n} \ ((\j\{1..n + 1}. \x\f. x j = 0) \ (\j\{1..n + 1}. \x\f. x j = p))" (is ?ex) + apply(rule_tac x=s in exI,rule_tac x=a in exI) unfolding complete_face_top[OF *] using allp as(1) by auto + next fix f assume as:"\s a. ksimplex p (n + 1) s \ + a \ s \ f = s - {a} \ reduced lab (n + 1) ` f = {0..n} \ ((\j\{1..n + 1}. \x\f. x j = 0) \ (\j\{1..n + 1}. \x\f. x j = p))" (is ?ex) + then guess s .. then guess a apply-apply(erule exE,(erule conjE)+) . note sa=this + { fix x assume "x\f" hence "reduced lab (n + 1) x \ reduced lab (n + 1) ` f" by auto + hence "reduced lab (n + 1) x < n + 1" using sa(4) by auto + hence "reduced lab (n + 1) x = reduced lab n x" apply-apply(rule reduced_labelling_Suc) + using reduced_labelling(1) by auto } + thus part1:"reduced lab n ` f = {0..n}" unfolding sa(4)[THEN sym] apply-apply(rule set_ext) unfolding image_iff by auto + have *:"\x\f. x (n + 1) = p" proof(cases "\j\{1..n + 1}. \x\f. x j = 0") + case True then guess j .. hence "\x. x\f \ reduced lab (n + 1) x \ j - 1" apply-apply(rule reduced_labelling_0) apply assumption + apply(rule assms(2)[rule_format]) using sa(1)[unfolded ksimplex_def] unfolding sa by auto moreover + have "j - 1 \ {0..n}" using `j\{1..n+1}` by auto + ultimately have False unfolding sa(4)[THEN sym] unfolding image_iff by fastsimp thus ?thesis by auto next + case False hence "\j\{1..n + 1}. \x\f. x j = p" using sa(5) by fastsimp then guess j .. note j=this + thus ?thesis proof(cases "j = n+1") + case False hence *:"j\{1..n}" using j by auto + hence "\x. x\f \ reduced lab n x < j" apply(rule reduced_labelling_1) proof- fix x assume "x\f" + hence "lab x j = 1" apply-apply(rule assms(3)[rule_format,OF j(1)]) + using sa(1)[unfolded ksimplex_def] using j unfolding sa by auto thus "lab x j \ 0" by auto qed + moreover have "j\{0..n}" using * by auto + ultimately have False unfolding part1[THEN sym] using * unfolding image_iff by auto thus ?thesis by auto qed auto qed + thus "ksimplex p n f" using as unfolding simplex_top_face[OF assms(1) *,THEN sym] by auto qed qed + +lemma kuhn_induction_Suc: + assumes "0 < p" "\x. \j\{1..Suc n}. (\j. x j \ p) \ (x j = 0) \ (lab x j = 0)" + "\x. \j\{1..Suc n}. (\j. x j \ p) \ (x j = p) \ (lab x j = 1)" + "odd (card {f. ksimplex p n f \ ((reduced lab n) ` f = {0..n})})" + shows "odd (card {s. ksimplex p (Suc n) s \((reduced lab (Suc n)) ` s = {0..Suc n})})" + using assms unfolding Suc_eq_plus1 by(rule kuhn_induction) + +subsection {* And so we get the final combinatorial result. *} + +lemma ksimplex_0: "ksimplex p 0 s \ s = {(\x. p)}" (is "?l = ?r") proof + assume l:?l guess a using ksimplexD(3)[OF l, unfolded add_0] unfolding card_1_exists .. note a=this + have "a = (\x. p)" using ksimplexD(5)[OF l, rule_format, OF a(1)] by(rule,auto) thus ?r using a by auto next + assume r:?r show ?l unfolding r ksimplex_eq by auto qed + +lemma reduce_labelling_0[simp]: "reduced lab 0 x = 0" apply(rule reduced_labelling_unique) by auto + +lemma kuhn_combinatorial: + assumes "0 < p" "\x j. (\j. x(j) \ p) \ 1 \ j \ j \ n \ (x j = 0) \ (lab x j = 0)" + "\x j. (\j. x(j) \ p) \ 1 \ j \ j \ n \ (x j = p) \ (lab x j = 1)" + shows " odd (card {s. ksimplex p n s \ ((reduced lab n) ` s = {0..n})})" using assms proof(induct n) + let ?M = "\n. {s. ksimplex p n s \ ((reduced lab n) ` s = {0..n})}" + { case 0 have *:"?M 0 = {{(\x. p)}}" unfolding ksimplex_0 by auto show ?case unfolding * by auto } + case (Suc n) have "odd (card (?M n))" apply(rule Suc(1)[OF Suc(2)]) using Suc(3-) by auto + thus ?case apply-apply(rule kuhn_induction_Suc) using Suc(2-) by auto qed + +lemma kuhn_lemma: assumes "0 < (p::nat)" "0 < (n::nat)" + "\x. (\i\{1..n}. x i \ p) \ (\i\{1..n}. (label x i = (0::nat)) \ (label x i = 1))" + "\x. (\i\{1..n}. x i \ p) \ (\i\{1..n}. (x i = 0) \ (label x i = 0))" + "\x. (\i\{1..n}. x i \ p) \ (\i\{1..n}. (x i = p) \ (label x i = 1))" + obtains q where "\i\{1..n}. q i < p" + "\i\{1..n}. \r s. (\j\{1..n}. q(j) \ r(j) \ r(j) \ q(j) + 1) \ + (\j\{1..n}. q(j) \ s(j) \ s(j) \ q(j) + 1) \ + ~(label r i = label s i)" proof- + let ?A = "{s. ksimplex p n s \ reduced label n ` s = {0..n}}" have "n\0" using assms by auto + have conjD:"\P Q. P \ Q \ P" "\P Q. P \ Q \ Q" by auto + have "odd (card ?A)" apply(rule kuhn_combinatorial[of p n label]) using assms by auto + hence "card ?A \ 0" apply-apply(rule ccontr) by auto hence "?A \ {}" unfolding card_eq_0_iff by auto + then obtain s where "s\?A" by auto note s=conjD[OF this[unfolded mem_Collect_eq]] + guess a b apply(rule ksimplex_extrema_strong[OF s(1) `n\0`]) . note ab=this + show ?thesis apply(rule that[of a]) proof(rule_tac[!] ballI) fix i assume "i\{1..n}" + hence "a i + 1 \ p" apply-apply(rule order_trans[of _ "b i"]) apply(subst ab(5)[THEN spec[where x=i]]) + using s(1)[unfolded ksimplex_def] defer apply- apply(erule conjE)+ apply(drule_tac bspec[OF _ ab(2)])+ by auto + thus "a i < p" by auto + case goal2 hence "i \ reduced label n ` s" using s by auto then guess u unfolding image_iff .. note u=this + from goal2 have "i - 1 \ reduced label n ` s" using s by auto then guess v unfolding image_iff .. note v=this + show ?case apply(rule_tac x=u in exI, rule_tac x=v in exI) apply(rule conjI) defer apply(rule conjI) defer 2 proof(rule_tac[1-2] ballI) + show "label u i \ label v i" using reduced_labelling[of label n u] reduced_labelling[of label n v] + unfolding u(2)[THEN sym] v(2)[THEN sym] using goal2 by auto + fix j assume j:"j\{1..n}" show "a j \ u j \ u j \ a j + 1" "a j \ v j \ v j \ a j + 1" + using conjD[OF ab(4)[rule_format, OF u(1)]] and conjD[OF ab(4)[rule_format, OF v(1)]] apply- + apply(drule_tac[!] kle_imp_pointwise)+ apply(erule_tac[!] x=j in allE)+ unfolding ab(5)[rule_format] using j + by auto qed qed qed + +subsection {* The main result for the unit cube. *} + +lemma kuhn_labelling_lemma': + assumes "(\x::nat\real. P x \ P (f x))" "\x. P x \ (\i::nat. Q i \ 0 \ x i \ x i \ 1)" + shows "\l. (\x i. l x i \ (1::nat)) \ + (\x i. P x \ Q i \ (x i = 0) \ (l x i = 0)) \ + (\x i. P x \ Q i \ (x i = 1) \ (l x i = 1)) \ + (\x i. P x \ Q i \ (l x i = 0) \ x i \ f(x) i) \ + (\x i. P x \ Q i \ (l x i = 1) \ f(x) i \ x i)" proof- + have and_forall_thm:"\P Q. (\x. P x) \ (\x. Q x) \ (\x. P x \ Q x)" by auto + have *:"\x y::real. 0 \ x \ x \ 1 \ 0 \ y \ y \ 1 \ (x \ 1 \ x \ y \ x \ 0 \ y \ x)" by auto + show ?thesis unfolding and_forall_thm apply(subst choice_iff[THEN sym])+ proof(rule,rule) case goal1 + let ?R = "\y. (P x \ Q xa \ x xa = 0 \ y = (0::nat)) \ + (P x \ Q xa \ x xa = 1 \ y = 1) \ (P x \ Q xa \ y = 0 \ x xa \ (f x) xa) \ (P x \ Q xa \ y = 1 \ (f x) xa \ x xa)" + { assume "P x" "Q xa" hence "0 \ (f x) xa \ (f x) xa \ 1" using assms(2)[rule_format,of "f x" xa] + apply(drule_tac assms(1)[rule_format]) by auto } + hence "?R 0 \ ?R 1" by auto thus ?case by auto qed qed + +lemma brouwer_cube: fixes f::"real^'n::finite \ real^'n::finite" + assumes "continuous_on {0..1} f" "f ` {0..1} \ {0..1}" + shows "\x\{0..1}. f x = x" apply(rule ccontr) proof- + def n \ "CARD('n)" have n:"1 \ n" "0 < n" "n \ 0" unfolding n_def by auto + assume "\ (\x\{0..1}. f x = x)" hence *:"\ (\x\{0..1}. f x - x = 0)" by auto + guess d apply(rule brouwer_compactness_lemma[OF compact_interval _ *]) + apply(rule continuous_on_intros assms)+ . note d=this[rule_format] + have *:"\x. x \ {0..1} \ f x \ {0..1}" "\x. x \ {0..1::real^'n} \ (\i. True \ 0 \ x $ i \ x $ i \ 1)" + using assms(2)[unfolded image_subset_iff Ball_def] unfolding mem_interval by auto + guess label using kuhn_labelling_lemma[OF *] apply-apply(erule exE,(erule conjE)+) . note label = this[rule_format] + have lem1:"\x\{0..1}.\y\{0..1}.\i. label x i \ label y i + \ abs(f x $ i - x $ i) \ norm(f y - f x) + norm(y - x)" proof(rule,rule,rule,rule) + fix x y assume xy:"x\{0..1::real^'n}" "y\{0..1::real^'n}" fix i::'n assume i:"label x i \ label y i" + have *:"\x y fx fy::real. (x \ fx \ fy \ y \ fx \ x \ y \ fy) + \ abs(fx - x) \ abs(fy - fx) + abs(y - x)" by auto + have "\(f x - x) $ i\ \ abs((f y - f x)$i) + abs((y - x)$i)" unfolding vector_minus_component + apply(rule *) apply(cases "label x i = 0") apply(rule disjI1,rule) prefer 3 proof(rule disjI2,rule) + assume lx:"label x i = 0" hence ly:"label y i = 1" using i label(1)[of y i] by auto + show "x $ i \ f x $ i" apply(rule label(4)[rule_format]) using xy lx by auto + show "f y $ i \ y $ i" apply(rule label(5)[rule_format]) using xy ly by auto next + assume "label x i \ 0" hence l:"label x i = 1" "label y i = 0" + using i label(1)[of x i] label(1)[of y i] by auto + show "f x $ i \ x $ i" apply(rule label(5)[rule_format]) using xy l by auto + show "y $ i \ f y $ i" apply(rule label(4)[rule_format]) using xy l by auto qed + also have "\ \ norm (f y - f x) + norm (y - x)" apply(rule add_mono) by(rule component_le_norm)+ + finally show "\f x $ i - x $ i\ \ norm (f y - f x) + norm (y - x)" unfolding vector_minus_component . qed + have "\e>0. \x\{0..1}. \y\{0..1}. \z\{0..1}. \i. + norm(x - z) < e \ norm(y - z) < e \ label x i \ label y i \ abs((f(z) - z)$i) < d / (real n)" proof- + have d':"d / real n / 8 > 0" apply(rule divide_pos_pos)+ using d(1) unfolding n_def by auto + have *:"uniformly_continuous_on {0..1} f" by(rule compact_uniformly_continuous[OF assms(1) compact_interval]) + guess e using *[unfolded uniformly_continuous_on_def,rule_format,OF d'] apply-apply(erule exE,(erule conjE)+) . + note e=this[rule_format,unfolded vector_dist_norm] + show ?thesis apply(rule_tac x="min (e/2) (d/real n/8)" in exI) apply(rule) defer + apply(rule,rule,rule,rule,rule) apply(erule conjE)+ proof- + show "0 < min (e / 2) (d / real n / 8)" using d' e by auto + fix x y z i assume as:"x \ {0..1}" "y \ {0..1}" "z \ {0..1}" "norm (x - z) < min (e / 2) (d / real n / 8)" + "norm (y - z) < min (e / 2) (d / real n / 8)" "label x i \ label y i" + have *:"\z fz x fx n1 n2 n3 n4 d4 d::real. abs(fx - x) \ n1 + n2 \ abs(fx - fz) \ n3 \ abs(x - z) \ n4 \ + n1 < d4 \ n2 < 2 * d4 \ n3 < d4 \ n4 < d4 \ (8 * d4 = d) \ abs(fz - z) < d" by auto + show "\(f z - z) $ i\ < d / real n" unfolding vector_minus_component proof(rule *) + show "\f x $ i - x $ i\ \ norm (f y -f x) + norm (y - x)" apply(rule lem1[rule_format]) using as by auto + show "\f x $ i - f z $ i\ \ norm (f x - f z)" "\x $ i - z $ i\ \ norm (x - z)" + unfolding vector_minus_component[THEN sym] by(rule component_le_norm)+ + have tria:"norm (y - x) \ norm (y - z) + norm (x - z)" using dist_triangle[of y x z,unfolded vector_dist_norm] + unfolding norm_minus_commute by auto + also have "\ < e / 2 + e / 2" apply(rule add_strict_mono) using as(4,5) by auto + finally show "norm (f y - f x) < d / real n / 8" apply- apply(rule e(2)) using as by auto + have "norm (y - z) + norm (x - z) < d / real n / 8 + d / real n / 8" apply(rule add_strict_mono) using as by auto + thus "norm (y - x) < 2 * (d / real n / 8)" using tria by auto + show "norm (f x - f z) < d / real n / 8" apply(rule e(2)) using as e(1) by auto qed(insert as, auto) qed qed + then guess e apply-apply(erule exE,(erule conjE)+) . note e=this[rule_format] + guess p using real_arch_simple[of "1 + real n / e"] .. note p=this + have "1 + real n / e > 0" apply(rule add_pos_pos) defer apply(rule divide_pos_pos) using e(1) n by auto + hence "p > 0" using p by auto + guess b using ex_bij_betw_nat_finite_1[OF finite_UNIV[where 'a='n]] .. note b=this + def b' \ "inv_into {1..n} b" + have b':"bij_betw b' UNIV {1..n}" using bij_betw_inv_into[OF b] unfolding b'_def n_def by auto + have bb'[simp]:"\i. b (b' i) = i" unfolding b'_def apply(rule f_inv_into_f) unfolding n_def using b + unfolding bij_betw_def by auto + have b'b[simp]:"\i. i\{1..n} \ b' (b i) = i" unfolding b'_def apply(rule inv_into_f_eq) + using b unfolding n_def bij_betw_def by auto + have *:"\x::nat. x=0 \ x=1 \ x\1" by auto + have q1:"0 < p" "0 < n" "\x. (\i\{1..n}. x i \ p) \ + (\i\{1..n}. (label (\ i. real (x (b' i)) / real p) \ b) i = 0 \ (label (\ i. real (x (b' i)) / real p) \ b) i = 1)" + unfolding * using `p>0` `n>0` using label(1) by auto + have q2:"\x. (\i\{1..n}. x i \ p) \ (\i\{1..n}. x i = 0 \ (label (\ i. real (x (b' i)) / real p) \ b) i = 0)" + "\x. (\i\{1..n}. x i \ p) \ (\i\{1..n}. x i = p \ (label (\ i. real (x (b' i)) / real p) \ b) i = 1)" + apply(rule,rule,rule,rule) defer proof(rule,rule,rule,rule) fix x i + assume as:"\i\{1..n}. x i \ p" "i \ {1..n}" + { assume "x i = p \ x i = 0" + have "(\ i. real (x (b' i)) / real p) \ {0..1}" unfolding mem_interval Cart_lambda_beta proof(rule,rule) + fix j::'n have j:"b' j \ {1..n}" using b' unfolding n_def bij_betw_def by auto + show "0 $ j \ real (x (b' j)) / real p" unfolding zero_index + apply(rule divide_nonneg_pos) using `p>0` using as(1)[rule_format,OF j] by auto + show "real (x (b' j)) / real p \ 1 $ j" unfolding one_index divide_le_eq_1 + using as(1)[rule_format,OF j] by auto qed } note cube=this + { assume "x i = p" thus "(label (\ i. real (x (b' i)) / real p) \ b) i = 1" unfolding o_def + apply-apply(rule label(3)) using cube using as `p>0` by auto } + { assume "x i = 0" thus "(label (\ i. real (x (b' i)) / real p) \ b) i = 0" unfolding o_def + apply-apply(rule label(2)) using cube using as `p>0` by auto } qed + guess q apply(rule kuhn_lemma[OF q1 q2]) . note q=this + def z \ "\ i. real (q (b' i)) / real p" + have "\i. d / real n \ abs((f z - z)$i)" proof(rule ccontr) + have "\i. q (b' i) \ {0..i. q (b' i) \ {0..p}" apply-apply(rule,erule_tac x=i in allE) by auto + hence "z\{0..1}" unfolding z_def mem_interval unfolding one_index zero_index Cart_lambda_beta + apply-apply(rule,rule) apply(rule divide_nonneg_pos) using `p>0` unfolding divide_le_eq_1 by auto + hence d_fz_z:"d \ norm (f z - z)" apply(drule_tac d) . + case goal1 hence as:"\i. \f z $ i - z $ i\ < d / real n" using `n>0` by(auto simp add:not_le) + have "norm (f z - z) \ (\i\UNIV. \f z $ i - z $ i\)" unfolding vector_minus_component[THEN sym] by(rule norm_le_l1) + also have "\ < (\(i::'n)\UNIV. d / real n)" apply(rule setsum_strict_mono) using as by auto + also have "\ = d" unfolding real_eq_of_nat n_def using n by auto + finally show False using d_fz_z by auto qed then guess i .. note i=this + have *:"b' i \ {1..n}" using b'[unfolded bij_betw_def] by auto + guess r using q(2)[rule_format,OF *] .. then guess s apply-apply(erule exE,(erule conjE)+) . note rs=this[rule_format] + have b'_im:"\i. b' i \ {1..n}" using b' unfolding bij_betw_def by auto + def r' \ "\ i. real (r (b' i)) / real p" + have "\i. r (b' i) \ p" apply(rule order_trans) apply(rule rs(1)[OF b'_im,THEN conjunct2]) + using q(1)[rule_format,OF b'_im] by(auto simp add: Suc_le_eq) + hence "r' \ {0..1::real^'n}" unfolding r'_def mem_interval Cart_lambda_beta one_index zero_index + apply-apply(rule,rule,rule divide_nonneg_pos) + using rs(1)[OF b'_im] q(1)[rule_format,OF b'_im] `p>0` by auto + def s' \ "\ i. real (s (b' i)) / real p" + have "\i. s (b' i) \ p" apply(rule order_trans) apply(rule rs(2)[OF b'_im,THEN conjunct2]) + using q(1)[rule_format,OF b'_im] by(auto simp add: Suc_le_eq) + hence "s' \ {0..1::real^'n}" unfolding s'_def mem_interval Cart_lambda_beta one_index zero_index + apply-apply(rule,rule,rule divide_nonneg_pos) + using rs(1)[OF b'_im] q(1)[rule_format,OF b'_im] `p>0` by auto + have "z\{0..1}" unfolding z_def mem_interval Cart_lambda_beta one_index zero_index + apply(rule,rule,rule divide_nonneg_pos) using q(1)[rule_format,OF b'_im] `p>0` by(auto intro:less_imp_le) + have *:"\x. 1 + real x = real (Suc x)" by auto + { have "(\i\UNIV. \real (r (b' i)) - real (q (b' i))\) \ (\(i::'n)\UNIV. 1)" + apply(rule setsum_mono) using rs(1)[OF b'_im] by(auto simp add:* field_simps) + also have "\ < e * real p" using p `e>0` `p>0` unfolding n_def real_of_nat_def + by(auto simp add:field_simps) + finally have "(\i\UNIV. \real (r (b' i)) - real (q (b' i))\) < e * real p" . } moreover + { have "(\i\UNIV. \real (s (b' i)) - real (q (b' i))\) \ (\(i::'n)\UNIV. 1)" + apply(rule setsum_mono) using rs(2)[OF b'_im] by(auto simp add:* field_simps) + also have "\ < e * real p" using p `e>0` `p>0` unfolding n_def real_of_nat_def + by(auto simp add:field_simps) + finally have "(\i\UNIV. \real (s (b' i)) - real (q (b' i))\) < e * real p" . } ultimately + have "norm (r' - z) < e" "norm (s' - z) < e" unfolding r'_def s'_def z_def apply- + apply(rule_tac[!] le_less_trans[OF norm_le_l1]) using `p>0` + by(auto simp add:field_simps setsum_divide_distrib[THEN sym]) + hence "\(f z - z) $ i\ < d / real n" apply-apply(rule e(2)[OF `r'\{0..1}` `s'\{0..1}` `z\{0..1}`]) + using rs(3) unfolding r'_def[symmetric] s'_def[symmetric] o_def bb' by auto + thus False using i by auto qed + +subsection {* Retractions. *} + +definition "retraction s t (r::real^'n::finite\real^'n) \ + t \ s \ continuous_on s r \ (r ` s \ t) \ (\x\t. r x = x)" + +definition retract_of (infixl "retract'_of" 12) where + "(t retract_of s) \ (\r. retraction s t r)" + +lemma retraction_idempotent: "retraction s t r \ x \ s \ r(r x) = r x" + unfolding retraction_def by auto + +subsection {*preservation of fixpoints under (more general notion of) retraction. *} + +lemma invertible_fixpoint_property: fixes s::"(real^'n::finite) set" and t::"(real^'m::finite) set" + assumes "continuous_on t i" "i ` t \ s" "continuous_on s r" "r ` s \ t" "\y\t. r (i y) = y" + "\f. continuous_on s f \ f ` s \ s \ (\x\s. f x = x)" "continuous_on t g" "g ` t \ t" + obtains y where "y\t" "g y = y" proof- + have "\x\s. (i \ g \ r) x = x" apply(rule assms(6)[rule_format],rule) + apply(rule continuous_on_compose assms)+ apply((rule continuous_on_subset)?,rule assms)+ + using assms(2,4,8) unfolding image_compose by(auto,blast) + then guess x .. note x = this hence *:"g (r x) \ t" using assms(4,8) by auto + have "r ((i \ g \ r) x) = r x" using x by auto + thus ?thesis apply(rule_tac that[of "r x"]) using x unfolding o_def + unfolding assms(5)[rule_format,OF *] using assms(4) by auto qed + +lemma homeomorphic_fixpoint_property: + fixes s::"(real^'n::finite) set" and t::"(real^'m::finite) set" assumes "s homeomorphic t" + shows "(\f. continuous_on s f \ f ` s \ s \ (\x\s. f x = x)) \ + (\g. continuous_on t g \ g ` t \ t \ (\y\t. g y = y))" proof- + guess r using assms[unfolded homeomorphic_def homeomorphism_def] .. then guess i .. + thus ?thesis apply- apply rule apply(rule_tac[!] allI impI)+ + apply(rule_tac g=g in invertible_fixpoint_property[of t i s r]) prefer 10 + apply(rule_tac g=f in invertible_fixpoint_property[of s r t i]) by auto qed + +lemma retract_fixpoint_property: + assumes "t retract_of s" "\f. continuous_on s f \ f ` s \ s \ (\x\s. f x = x)" "continuous_on t g" "g ` t \ t" + obtains y where "y \ t" "g y = y" proof- guess h using assms(1) unfolding retract_of_def .. + thus ?thesis unfolding retraction_def apply- + apply(rule invertible_fixpoint_property[OF continuous_on_id _ _ _ _ assms(2), of t h g]) prefer 7 + apply(rule_tac y=y in that) using assms by auto qed + +subsection {*So the Brouwer theorem for any set with nonempty interior. *} + +lemma brouwer_weak: fixes f::"real^'n::finite \ real^'n::finite" + assumes "compact s" "convex s" "interior s \ {}" "continuous_on s f" "f ` s \ s" + obtains x where "x \ s" "f x = x" proof- + have *:"interior {0..1::real^'n} \ {}" unfolding interior_closed_interval interval_eq_empty by auto + have *:"{0..1::real^'n} homeomorphic s" using homeomorphic_convex_compact[OF convex_interval(1) compact_interval * assms(2,1,3)] . + have "\f. continuous_on {0..1} f \ f ` {0..1} \ {0..1} \ (\x\{0..1::real^'n}. f x = x)" using brouwer_cube by auto + thus ?thesis unfolding homeomorphic_fixpoint_property[OF *] apply(erule_tac x=f in allE) + apply(erule impE) defer apply(erule bexE) apply(rule_tac x=y in that) using assms by auto qed + +subsection {* And in particular for a closed ball. *} + +lemma brouwer_ball: fixes f::"real^'n::finite \ real^'n::finite" + assumes "0 < e" "continuous_on (cball a e) f" "f ` (cball a e) \ (cball a e)" + obtains x where "x \ cball a e" "f x = x" + using brouwer_weak[OF compact_cball convex_cball,of a e f] unfolding interior_cball ball_eq_empty + using assms by auto + +text {*Still more general form; could derive this directly without using the + rather involved HOMEOMORPHIC_CONVEX_COMPACT theorem, just using + a scaling and translation to put the set inside the unit cube. *} + +lemma brouwer: fixes f::"real^'n::finite \ real^'n::finite" + assumes "compact s" "convex s" "s \ {}" "continuous_on s f" "f ` s \ s" + obtains x where "x \ s" "f x = x" proof- + have "\e>0. s \ cball 0 e" using compact_imp_bounded[OF assms(1)] unfolding bounded_pos + apply(erule_tac exE,rule_tac x=b in exI) by(auto simp add: vector_dist_norm) + then guess e apply-apply(erule exE,(erule conjE)+) . note e=this + have "\x\ cball 0 e. (f \ closest_point s) x = x" + apply(rule_tac brouwer_ball[OF e(1), of 0 "f \ closest_point s"]) apply(rule continuous_on_compose ) + apply(rule continuous_on_closest_point[OF assms(2) compact_imp_closed[OF assms(1)] assms(3)]) + apply(rule continuous_on_subset[OF assms(4)]) + using closest_point_in_set[OF compact_imp_closed[OF assms(1)] assms(3)] apply - defer + using assms(5)[unfolded subset_eq] using e(2)[unfolded subset_eq mem_cball] by(auto simp add:vector_dist_norm) + then guess x .. note x=this + have *:"closest_point s x = x" apply(rule closest_point_self) + apply(rule assms(5)[unfolded subset_eq,THEN bspec[where x="x"],unfolded image_iff]) + apply(rule_tac x="closest_point s x" in bexI) using x unfolding o_def + using closest_point_in_set[OF compact_imp_closed[OF assms(1)] assms(3), of x] by auto + show thesis apply(rule_tac x="closest_point s x" in that) unfolding x(2)[unfolded o_def] + apply(rule closest_point_in_set[OF compact_imp_closed[OF assms(1)] assms(3)]) using * by auto qed + +text {*So we get the no-retraction theorem. *} + +lemma no_retraction_cball: assumes "0 < e" + shows "\ (frontier(cball a e) retract_of (cball a e))" proof case goal1 + have *:"\xa. a - (2 *\<^sub>R a - xa) = -(a - xa)" using scaleR_left_distrib[of 1 1 a] by auto + guess x apply(rule retract_fixpoint_property[OF goal1, of "\x. scaleR 2 a - x"]) + apply(rule,rule,erule conjE) apply(rule brouwer_ball[OF assms]) apply assumption+ + apply(rule_tac x=x in bexI) apply assumption+ apply(rule continuous_on_intros)+ + unfolding frontier_cball subset_eq Ball_def image_iff apply(rule,rule,erule bexE) + unfolding vector_dist_norm apply(simp add: * norm_minus_commute) . note x = this + hence "scaleR 2 a = scaleR 1 x + scaleR 1 x" by(auto simp add:group_simps) + hence "a = x" unfolding scaleR_left_distrib[THEN sym] by auto + thus False using x using assms by auto qed + +subsection {*Bijections between intervals. *} + +definition "interval_bij = (\ (a,b) (u,v) (x::real^'n::finite). + (\ i. u$i + (x$i - a$i) / (b$i - a$i) * (v$i - u$i))::real^'n)" + +lemma interval_bij_affine: + "interval_bij (a,b) (u,v) = (\x. (\ i. (v$i - u$i) / (b$i - a$i) * x$i) + + (\ i. u$i - (v$i - u$i) / (b$i - a$i) * a$i))" + apply rule unfolding Cart_eq interval_bij_def vector_component_simps + by(auto simp add:group_simps field_simps add_divide_distrib[THEN sym]) + +lemma continuous_interval_bij: + "continuous (at x) (interval_bij (a,b::real^'n::finite) (u,v))" + unfolding interval_bij_affine apply(rule continuous_intros) + apply(rule linear_continuous_at) unfolding linear_conv_bounded_linear[THEN sym] + unfolding linear_def unfolding Cart_eq unfolding Cart_lambda_beta defer + apply(rule continuous_intros) by(auto simp add:field_simps add_divide_distrib[THEN sym]) + +lemma continuous_on_interval_bij: "continuous_on s (interval_bij (a,b) (u,v))" + apply(rule continuous_at_imp_continuous_on) by(rule, rule continuous_interval_bij) + +(** move this **) +lemma divide_nonneg_nonneg:assumes "a \ 0" "b \ 0" shows "0 \ a / (b::real)" + apply(cases "b=0") defer apply(rule divide_nonneg_pos) using assms by auto + +lemma in_interval_interval_bij: assumes "x \ {a..b}" "{u..v} \ {}" + shows "interval_bij (a,b) (u,v) x \ {u..v::real^'n::finite}" + unfolding interval_bij_def split_conv mem_interval Cart_lambda_beta proof(rule,rule) + fix i::'n have "{a..b} \ {}" using assms by auto + hence *:"a$i \ b$i" "u$i \ v$i" using assms(2) unfolding interval_eq_empty not_ex apply- + apply(erule_tac[!] x=i in allE)+ by auto + have x:"a$i\x$i" "x$i\b$i" using assms(1)[unfolded mem_interval] by auto + have "0 \ (x $ i - a $ i) / (b $ i - a $ i) * (v $ i - u $ i)" + apply(rule mult_nonneg_nonneg) apply(rule divide_nonneg_nonneg) + using * x by(auto simp add:field_simps) + thus "u $ i \ u $ i + (x $ i - a $ i) / (b $ i - a $ i) * (v $ i - u $ i)" using * by auto + have "((x $ i - a $ i) / (b $ i - a $ i)) * (v $ i - u $ i) \ 1 * (v $ i - u $ i)" + apply(rule mult_right_mono) unfolding divide_le_eq_1 using * x by auto + thus "u $ i + (x $ i - a $ i) / (b $ i - a $ i) * (v $ i - u $ i) \ v $ i" using * by auto qed + +lemma interval_bij_bij: assumes "\i. a$i < b$i \ u$i < v$i" + shows "interval_bij (a,b) (u,v) (interval_bij (u,v) (a,b) x) = x" + unfolding interval_bij_def split_conv Cart_eq Cart_lambda_beta + apply(rule,insert assms,erule_tac x=i in allE) by auto + +subsection {*Fashoda meet theorem. *} + +lemma infnorm_2: "infnorm (x::real^2) = max (abs(x$1)) (abs(x$2))" + unfolding infnorm_def UNIV_2 apply(rule Sup_eq) by auto + +lemma infnorm_eq_1_2: "infnorm (x::real^2) = 1 \ + (abs(x$1) \ 1 \ abs(x$2) \ 1 \ (x$1 = -1 \ x$1 = 1 \ x$2 = -1 \ x$2 = 1))" + unfolding infnorm_2 by auto + +lemma infnorm_eq_1_imp: assumes "infnorm (x::real^2) = 1" shows "abs(x$1) \ 1" "abs(x$2) \ 1" + using assms unfolding infnorm_eq_1_2 by auto + +lemma fashoda_unit: fixes f g::"real^1 \ real^2" + assumes "f ` {- 1..1} \ {- 1..1}" "g ` {- 1..1} \ {- 1..1}" + "continuous_on {- 1..1} f" "continuous_on {- 1..1} g" + "f (- 1)$1 = - 1" "f 1$1 = 1" "g (- 1) $2 = -1" "g 1 $2 = 1" + shows "\s\{- 1..1}. \t\{- 1..1}. f s = g t" proof(rule ccontr) + case goal1 note as = this[unfolded bex_simps,rule_format] + def sqprojection \ "\z::real^2. (inverse (infnorm z)) *\<^sub>R z" + def negatex \ "\x::real^2. (vector [-(x$1), x$2])::real^2" + have lem1:"\z::real^2. infnorm(negatex z) = infnorm z" + unfolding negatex_def infnorm_2 vector_2 by auto + have lem2:"\z. z\0 \ infnorm(sqprojection z) = 1" unfolding sqprojection_def + unfolding infnorm_mul[unfolded smult_conv_scaleR] unfolding abs_inverse real_abs_infnorm + unfolding infnorm_eq_0[THEN sym] by auto + let ?F = "(\w::real^2. (f \ vec1 \ (\x. x$1)) w - (g \ vec1 \ (\x. x$2)) w)" + have *:"\i. vec1 ` (\x::real^2. x $ i) ` {- 1..1} = {- 1..1::real^1}" + apply(rule set_ext) unfolding image_iff Bex_def mem_interval apply rule defer + apply(rule_tac x="dest_vec1 x" in exI) apply rule apply(rule_tac x="vec (dest_vec1 x)" in exI) + by(auto simp add: dest_vec1_def[THEN sym]) + { fix x assume "x \ (\w. (f \ vec1 \ (\x. x $ 1)) w - (g \ vec1 \ (\x. x $ 2)) w) ` {- 1..1::real^2}" + then guess w unfolding image_iff .. note w = this + hence "x \ 0" using as[of "vec1 (w$1)" "vec1 (w$2)"] unfolding mem_interval by auto} note x0=this + have 21:"\i::2. i\1 \ i=2" using UNIV_2 by auto + have 1:"{- 1<..<1::real^2} \ {}" unfolding interval_eq_empty by auto + have 2:"continuous_on {- 1..1} (negatex \ sqprojection \ ?F)" apply(rule continuous_on_intros continuous_on_component continuous_on_vec1)+ + prefer 2 apply(rule continuous_on_intros continuous_on_component continuous_on_vec1)+ unfolding * + apply(rule assms)+ apply(rule continuous_on_compose,subst sqprojection_def) + apply(rule continuous_on_mul ) apply(rule continuous_at_imp_continuous_on,rule) apply(rule continuous_at_inv[unfolded o_def]) + apply(rule continuous_at_infnorm) unfolding infnorm_eq_0 defer apply(rule continuous_on_id) apply(rule linear_continuous_on) proof- + show "bounded_linear negatex" apply(rule bounded_linearI') unfolding Cart_eq proof(rule_tac[!] allI) fix i::2 and x y::"real^2" and c::real + show "negatex (x + y) $ i = (negatex x + negatex y) $ i" "negatex (c *s x) $ i = (c *s negatex x) $ i" + apply-apply(case_tac[!] "i\1") prefer 3 apply(drule_tac[1-2] 21) + unfolding negatex_def by(auto simp add:vector_2 ) qed qed(insert x0, auto) + have 3:"(negatex \ sqprojection \ ?F) ` {- 1..1} \ {- 1..1}" unfolding subset_eq apply rule proof- + case goal1 then guess y unfolding image_iff .. note y=this have "?F y \ 0" apply(rule x0) using y(1) by auto + hence *:"infnorm (sqprojection (?F y)) = 1" unfolding y o_def apply- by(rule lem2[rule_format]) + have "infnorm x = 1" unfolding *[THEN sym] y o_def by(rule lem1[rule_format]) + thus "x\{- 1..1}" unfolding mem_interval infnorm_2 apply- apply rule + proof-case goal1 thus ?case apply(cases "i=1") defer apply(drule 21) by auto qed qed + guess x apply(rule brouwer_weak[of "{- 1..1::real^2}" "negatex \ sqprojection \ ?F"]) + apply(rule compact_interval convex_interval)+ unfolding interior_closed_interval + apply(rule 1 2 3)+ . note x=this + have "?F x \ 0" apply(rule x0) using x(1) by auto + hence *:"infnorm (sqprojection (?F x)) = 1" unfolding o_def by(rule lem2[rule_format]) + have nx:"infnorm x = 1" apply(subst x(2)[THEN sym]) unfolding *[THEN sym] o_def by(rule lem1[rule_format]) + have "\x i. x \ 0 \ (0 < (sqprojection x)$i \ 0 < x$i)" "\x i. x \ 0 \ ((sqprojection x)$i < 0 \ x$i < 0)" + apply- apply(rule_tac[!] allI impI)+ proof- fix x::"real^2" and i::2 assume x:"x\0" + have "inverse (infnorm x) > 0" using x[unfolded infnorm_pos_lt[THEN sym]] by auto + thus "(0 < sqprojection x $ i) = (0 < x $ i)" "(sqprojection x $ i < 0) = (x $ i < 0)" + unfolding sqprojection_def vector_component_simps Cart_nth.scaleR real_scaleR_def + unfolding zero_less_mult_iff mult_less_0_iff by(auto simp add:field_simps) qed + note lem3 = this[rule_format] + have x1:"vec1 (x $ 1) \ {- 1..1::real^1}" "vec1 (x $ 2) \ {- 1..1::real^1}" using x(1) unfolding mem_interval by auto + hence nz:"f (vec1 (x $ 1)) - g (vec1 (x $ 2)) \ 0" unfolding right_minus_eq apply-apply(rule as) by auto + have "x $ 1 = -1 \ x $ 1 = 1 \ x $ 2 = -1 \ x $ 2 = 1" using nx unfolding infnorm_eq_1_2 by auto + thus False proof- fix P Q R S + presume "P \ Q \ R \ S" "P\False" "Q\False" "R\False" "S\False" thus False by auto + next assume as:"x$1 = 1" hence "vec1 (x$1) = 1" unfolding Cart_eq by auto + hence *:"f (vec1 (x $ 1)) $ 1 = 1" using assms(6) by auto + have "sqprojection (f (vec1 (x$1)) - g (vec1 (x$2))) $ 1 < 0" + using x(2)[unfolded o_def Cart_eq,THEN spec[where x=1]] + unfolding as negatex_def vector_2 by auto moreover + from x1 have "g (vec1 (x $ 2)) \ {- 1..1}" apply-apply(rule assms(2)[unfolded subset_eq,rule_format]) by auto + ultimately show False unfolding lem3[OF nz] vector_component_simps * mem_interval + apply(erule_tac x=1 in allE) by auto + next assume as:"x$1 = -1" hence "vec1 (x$1) = - 1" unfolding Cart_eq by auto + hence *:"f (vec1 (x $ 1)) $ 1 = - 1" using assms(5) by auto + have "sqprojection (f (vec1 (x$1)) - g (vec1 (x$2))) $ 1 > 0" + using x(2)[unfolded o_def Cart_eq,THEN spec[where x=1]] + unfolding as negatex_def vector_2 by auto moreover + from x1 have "g (vec1 (x $ 2)) \ {- 1..1}" apply-apply(rule assms(2)[unfolded subset_eq,rule_format]) by auto + ultimately show False unfolding lem3[OF nz] vector_component_simps * mem_interval + apply(erule_tac x=1 in allE) by auto + next assume as:"x$2 = 1" hence "vec1 (x$2) = 1" unfolding Cart_eq by auto + hence *:"g (vec1 (x $ 2)) $ 2 = 1" using assms(8) by auto + have "sqprojection (f (vec1 (x$1)) - g (vec1 (x$2))) $ 2 > 0" + using x(2)[unfolded o_def Cart_eq,THEN spec[where x=2]] + unfolding as negatex_def vector_2 by auto moreover + from x1 have "f (vec1 (x $ 1)) \ {- 1..1}" apply-apply(rule assms(1)[unfolded subset_eq,rule_format]) by auto + ultimately show False unfolding lem3[OF nz] vector_component_simps * mem_interval + apply(erule_tac x=2 in allE) by auto + next assume as:"x$2 = -1" hence "vec1 (x$2) = - 1" unfolding Cart_eq by auto + hence *:"g (vec1 (x $ 2)) $ 2 = - 1" using assms(7) by auto + have "sqprojection (f (vec1 (x$1)) - g (vec1 (x$2))) $ 2 < 0" + using x(2)[unfolded o_def Cart_eq,THEN spec[where x=2]] + unfolding as negatex_def vector_2 by auto moreover + from x1 have "f (vec1 (x $ 1)) \ {- 1..1}" apply-apply(rule assms(1)[unfolded subset_eq,rule_format]) by auto + ultimately show False unfolding lem3[OF nz] vector_component_simps * mem_interval + apply(erule_tac x=2 in allE) by auto qed(auto) qed + +lemma fashoda_unit_path: fixes f ::"real^1 \ real^2" and g ::"real^1 \ real^2" + assumes "path f" "path g" "path_image f \ {- 1..1}" "path_image g \ {- 1..1}" + "(pathstart f)$1 = -1" "(pathfinish f)$1 = 1" "(pathstart g)$2 = -1" "(pathfinish g)$2 = 1" + obtains z where "z \ path_image f" "z \ path_image g" proof- + note assms=assms[unfolded path_def pathstart_def pathfinish_def path_image_def] + def iscale \ "\z::real^1. inverse 2 *\<^sub>R (z + 1)" + have isc:"iscale ` {- 1..1} \ {0..1}" unfolding iscale_def by(auto simp add:dest_vec1_add dest_vec1_neg) + have "\s\{- 1..1}. \t\{- 1..1}. (f \ iscale) s = (g \ iscale) t" proof(rule fashoda_unit) + show "(f \ iscale) ` {- 1..1} \ {- 1..1}" "(g \ iscale) ` {- 1..1} \ {- 1..1}" + using isc and assms(3-4) unfolding image_compose by auto + have *:"continuous_on {- 1..1} iscale" unfolding iscale_def by(rule continuous_on_intros)+ + show "continuous_on {- 1..1} (f \ iscale)" "continuous_on {- 1..1} (g \ iscale)" + apply-apply(rule_tac[!] continuous_on_compose[OF *]) apply(rule_tac[!] continuous_on_subset[OF _ isc]) + by(rule assms)+ have *:"(1 / 2) *\<^sub>R (1 + (1::real^1)) = 1" unfolding Cart_eq by auto + show "(f \ iscale) (- 1) $ 1 = - 1" "(f \ iscale) 1 $ 1 = 1" "(g \ iscale) (- 1) $ 2 = -1" "(g \ iscale) 1 $ 2 = 1" + unfolding o_def iscale_def using assms by(auto simp add:*) qed + then guess s .. from this(2) guess t .. note st=this + show thesis apply(rule_tac z="f (iscale s)" in that) + using st `s\{- 1..1}` unfolding o_def path_image_def image_iff apply- + apply(rule_tac x="iscale s" in bexI) prefer 3 apply(rule_tac x="iscale t" in bexI) + using isc[unfolded subset_eq, rule_format] by auto qed + +lemma fashoda: fixes b::"real^2" + assumes "path f" "path g" "path_image f \ {a..b}" "path_image g \ {a..b}" + "(pathstart f)$1 = a$1" "(pathfinish f)$1 = b$1" + "(pathstart g)$2 = a$2" "(pathfinish g)$2 = b$2" + obtains z where "z \ path_image f" "z \ path_image g" proof- + fix P Q S presume "P \ Q \ S" "P \ thesis" "Q \ thesis" "S \ thesis" thus thesis by auto +next have "{a..b} \ {}" using assms(3) using path_image_nonempty by auto + hence "a \ b" unfolding interval_eq_empty vector_less_eq_def by(auto simp add: not_less) + thus "a$1 = b$1 \ a$2 = b$2 \ (a$1 < b$1 \ a$2 < b$2)" unfolding vector_less_eq_def forall_2 by auto +next assume as:"a$1 = b$1" have "\z\path_image g. z$2 = (pathstart f)$2" apply(rule connected_ivt_component) + apply(rule connected_path_image assms)+apply(rule pathstart_in_path_image,rule pathfinish_in_path_image) + unfolding assms using assms(3)[unfolded path_image_def subset_eq,rule_format,of "f 0"] + unfolding pathstart_def by(auto simp add: vector_less_eq_def) then guess z .. note z=this + have "z \ {a..b}" using z(1) assms(4) unfolding path_image_def by blast + hence "z = f 0" unfolding Cart_eq forall_2 unfolding z(2) pathstart_def + using assms(3)[unfolded path_image_def subset_eq mem_interval,rule_format,of "f 0" 1] + unfolding mem_interval apply(erule_tac x=1 in allE) using as by auto + thus thesis apply-apply(rule that[OF _ z(1)]) unfolding path_image_def by auto +next assume as:"a$2 = b$2" have "\z\path_image f. z$1 = (pathstart g)$1" apply(rule connected_ivt_component) + apply(rule connected_path_image assms)+apply(rule pathstart_in_path_image,rule pathfinish_in_path_image) + unfolding assms using assms(4)[unfolded path_image_def subset_eq,rule_format,of "g 0"] + unfolding pathstart_def by(auto simp add: vector_less_eq_def) then guess z .. note z=this + have "z \ {a..b}" using z(1) assms(3) unfolding path_image_def by blast + hence "z = g 0" unfolding Cart_eq forall_2 unfolding z(2) pathstart_def + using assms(4)[unfolded path_image_def subset_eq mem_interval,rule_format,of "g 0" 2] + unfolding mem_interval apply(erule_tac x=2 in allE) using as by auto + thus thesis apply-apply(rule that[OF z(1)]) unfolding path_image_def by auto +next assume as:"a $ 1 < b $ 1 \ a $ 2 < b $ 2" + have int_nem:"{- 1..1::real^2} \ {}" unfolding interval_eq_empty by auto + guess z apply(rule fashoda_unit_path[of "interval_bij (a,b) (- 1,1) \ f" "interval_bij (a,b) (- 1,1) \ g"]) + unfolding path_def path_image_def pathstart_def pathfinish_def + apply(rule_tac[1-2] continuous_on_compose) apply(rule assms[unfolded path_def] continuous_on_interval_bij)+ + unfolding subset_eq apply(rule_tac[1-2] ballI) + proof- fix x assume "x \ (interval_bij (a, b) (- 1, 1) \ f) ` {0..1}" + then guess y unfolding image_iff .. note y=this + show "x \ {- 1..1}" unfolding y o_def apply(rule in_interval_interval_bij) + using y(1) using assms(3)[unfolded path_image_def subset_eq] int_nem by auto + next fix x assume "x \ (interval_bij (a, b) (- 1, 1) \ g) ` {0..1}" + then guess y unfolding image_iff .. note y=this + show "x \ {- 1..1}" unfolding y o_def apply(rule in_interval_interval_bij) + using y(1) using assms(4)[unfolded path_image_def subset_eq] int_nem by auto + next show "(interval_bij (a, b) (- 1, 1) \ f) 0 $ 1 = -1" + "(interval_bij (a, b) (- 1, 1) \ f) 1 $ 1 = 1" + "(interval_bij (a, b) (- 1, 1) \ g) 0 $ 2 = -1" + "(interval_bij (a, b) (- 1, 1) \ g) 1 $ 2 = 1" unfolding interval_bij_def Cart_lambda_beta vector_component_simps o_def split_conv + unfolding assms[unfolded pathstart_def pathfinish_def] using as by auto qed note z=this + from z(1) guess zf unfolding image_iff .. note zf=this + from z(2) guess zg unfolding image_iff .. note zg=this + have *:"\i. (- 1) $ i < (1::real^2) $ i \ a $ i < b $ i" unfolding forall_2 using as by auto + show thesis apply(rule_tac z="interval_bij (- 1,1) (a,b) z" in that) + apply(subst zf) defer apply(subst zg) unfolding o_def interval_bij_bij[OF *] path_image_def + using zf(1) zg(1) by auto qed + +subsection {*Some slightly ad hoc lemmas I use below*} + +lemma segment_vertical: fixes a::"real^2" assumes "a$1 = b$1" + shows "x \ closed_segment a b \ (x$1 = a$1 \ x$1 = b$1 \ + (a$2 \ x$2 \ x$2 \ b$2 \ b$2 \ x$2 \ x$2 \ a$2))" (is "_ = ?R") +proof- + let ?L = "\u. (x $ 1 = (1 - u) * a $ 1 + u * b $ 1 \ x $ 2 = (1 - u) * a $ 2 + u * b $ 2) \ 0 \ u \ u \ 1" + { presume "?L \ ?R" "?R \ ?L" thus ?thesis unfolding closed_segment_def mem_Collect_eq + unfolding Cart_eq forall_2 smult_conv_scaleR[THEN sym] vector_component_simps by blast } + { assume ?L then guess u apply-apply(erule exE)apply(erule conjE)+ . note u=this + { fix b a assume "b + u * a > a + u * b" + hence "(1 - u) * b > (1 - u) * a" by(auto simp add:field_simps) + hence "b \ a" apply(drule_tac mult_less_imp_less_left) using u by auto + hence "u * a \ u * b" apply-apply(rule mult_left_mono[OF _ u(3)]) + using u(3-4) by(auto simp add:field_simps) } note * = this + { fix a b assume "u * b > u * a" hence "(1 - u) * a \ (1 - u) * b" apply-apply(rule mult_left_mono) + apply(drule mult_less_imp_less_left) using u by auto + hence "a + u * b \ b + u * a" by(auto simp add:field_simps) } note ** = this + thus ?R unfolding u assms using u by(auto simp add:field_simps not_le intro:* **) } + { assume ?R thus ?L proof(cases "x$2 = b$2") + case True thus ?L apply(rule_tac x="(x$2 - a$2) / (b$2 - a$2)" in exI) unfolding assms True + using `?R` by(auto simp add:field_simps) + next case False thus ?L apply(rule_tac x="1 - (x$2 - b$2) / (a$2 - b$2)" in exI) unfolding assms using `?R` + by(auto simp add:field_simps) + qed } qed + +lemma segment_horizontal: fixes a::"real^2" assumes "a$2 = b$2" + shows "x \ closed_segment a b \ (x$2 = a$2 \ x$2 = b$2 \ + (a$1 \ x$1 \ x$1 \ b$1 \ b$1 \ x$1 \ x$1 \ a$1))" (is "_ = ?R") +proof- + let ?L = "\u. (x $ 1 = (1 - u) * a $ 1 + u * b $ 1 \ x $ 2 = (1 - u) * a $ 2 + u * b $ 2) \ 0 \ u \ u \ 1" + { presume "?L \ ?R" "?R \ ?L" thus ?thesis unfolding closed_segment_def mem_Collect_eq + unfolding Cart_eq forall_2 smult_conv_scaleR[THEN sym] vector_component_simps by blast } + { assume ?L then guess u apply-apply(erule exE)apply(erule conjE)+ . note u=this + { fix b a assume "b + u * a > a + u * b" + hence "(1 - u) * b > (1 - u) * a" by(auto simp add:field_simps) + hence "b \ a" apply(drule_tac mult_less_imp_less_left) using u by auto + hence "u * a \ u * b" apply-apply(rule mult_left_mono[OF _ u(3)]) + using u(3-4) by(auto simp add:field_simps) } note * = this + { fix a b assume "u * b > u * a" hence "(1 - u) * a \ (1 - u) * b" apply-apply(rule mult_left_mono) + apply(drule mult_less_imp_less_left) using u by auto + hence "a + u * b \ b + u * a" by(auto simp add:field_simps) } note ** = this + thus ?R unfolding u assms using u by(auto simp add:field_simps not_le intro:* **) } + { assume ?R thus ?L proof(cases "x$1 = b$1") + case True thus ?L apply(rule_tac x="(x$1 - a$1) / (b$1 - a$1)" in exI) unfolding assms True + using `?R` by(auto simp add:field_simps) + next case False thus ?L apply(rule_tac x="1 - (x$1 - b$1) / (a$1 - b$1)" in exI) unfolding assms using `?R` + by(auto simp add:field_simps) + qed } qed + +subsection {*useful Fashoda corollary pointed out to me by Tom Hales. *} + +lemma fashoda_interlace: fixes a::"real^2" + assumes "path f" "path g" + "path_image f \ {a..b}" "path_image g \ {a..b}" + "(pathstart f)$2 = a$2" "(pathfinish f)$2 = a$2" + "(pathstart g)$2 = a$2" "(pathfinish g)$2 = a$2" + "(pathstart f)$1 < (pathstart g)$1" "(pathstart g)$1 < (pathfinish f)$1" + "(pathfinish f)$1 < (pathfinish g)$1" + obtains z where "z \ path_image f" "z \ path_image g" +proof- + have "{a..b} \ {}" using path_image_nonempty using assms(3) by auto + note ab=this[unfolded interval_eq_empty not_ex forall_2 not_less] + have "pathstart f \ {a..b}" "pathfinish f \ {a..b}" "pathstart g \ {a..b}" "pathfinish g \ {a..b}" + using pathstart_in_path_image pathfinish_in_path_image using assms(3-4) by auto + note startfin = this[unfolded mem_interval forall_2] + let ?P1 = "linepath (vector[a$1 - 2, a$2 - 2]) (vector[(pathstart f)$1,a$2 - 2]) +++ + linepath(vector[(pathstart f)$1,a$2 - 2])(pathstart f) +++ f +++ + linepath(pathfinish f)(vector[(pathfinish f)$1,a$2 - 2]) +++ + linepath(vector[(pathfinish f)$1,a$2 - 2])(vector[b$1 + 2,a$2 - 2])" + let ?P2 = "linepath(vector[(pathstart g)$1, (pathstart g)$2 - 3])(pathstart g) +++ g +++ + linepath(pathfinish g)(vector[(pathfinish g)$1,a$2 - 1]) +++ + linepath(vector[(pathfinish g)$1,a$2 - 1])(vector[b$1 + 1,a$2 - 1]) +++ + linepath(vector[b$1 + 1,a$2 - 1])(vector[b$1 + 1,b$2 + 3])" + let ?a = "vector[a$1 - 2, a$2 - 3]" + let ?b = "vector[b$1 + 2, b$2 + 3]" + have P1P2:"path_image ?P1 = path_image (linepath (vector[a$1 - 2, a$2 - 2]) (vector[(pathstart f)$1,a$2 - 2])) \ + path_image (linepath(vector[(pathstart f)$1,a$2 - 2])(pathstart f)) \ path_image f \ + path_image (linepath(pathfinish f)(vector[(pathfinish f)$1,a$2 - 2])) \ + path_image (linepath(vector[(pathfinish f)$1,a$2 - 2])(vector[b$1 + 2,a$2 - 2]))" + "path_image ?P2 = path_image(linepath(vector[(pathstart g)$1, (pathstart g)$2 - 3])(pathstart g)) \ path_image g \ + path_image(linepath(pathfinish g)(vector[(pathfinish g)$1,a$2 - 1])) \ + path_image(linepath(vector[(pathfinish g)$1,a$2 - 1])(vector[b$1 + 1,a$2 - 1])) \ + path_image(linepath(vector[b$1 + 1,a$2 - 1])(vector[b$1 + 1,b$2 + 3]))" using assms(1-2) + by(auto simp add: pathstart_join pathfinish_join path_image_join path_image_linepath path_join path_linepath) + have abab: "{a..b} \ {?a..?b}" by(auto simp add:vector_less_eq_def forall_2 vector_2) + guess z apply(rule fashoda[of ?P1 ?P2 ?a ?b]) + unfolding pathstart_join pathfinish_join pathstart_linepath pathfinish_linepath vector_2 proof- + show "path ?P1" "path ?P2" using assms by(auto simp add: pathstart_join pathfinish_join path_join) + have "path_image ?P1 \ {?a .. ?b}" unfolding P1P2 path_image_linepath apply(rule Un_least)+ defer 3 + apply(rule_tac[1-4] convex_interval(1)[unfolded convex_contains_segment,rule_format]) + unfolding mem_interval forall_2 vector_2 using ab startfin abab assms(3) + using assms(9-) unfolding assms by(auto simp add:field_simps) + thus "path_image ?P1 \ {?a .. ?b}" . + have "path_image ?P2 \ {?a .. ?b}" unfolding P1P2 path_image_linepath apply(rule Un_least)+ defer 2 + apply(rule_tac[1-4] convex_interval(1)[unfolded convex_contains_segment,rule_format]) + unfolding mem_interval forall_2 vector_2 using ab startfin abab assms(4) + using assms(9-) unfolding assms by(auto simp add:field_simps) + thus "path_image ?P2 \ {?a .. ?b}" . + show "a $ 1 - 2 = a $ 1 - 2" "b $ 1 + 2 = b $ 1 + 2" "pathstart g $ 2 - 3 = a $ 2 - 3" "b $ 2 + 3 = b $ 2 + 3" + by(auto simp add: assms) + qed note z=this[unfolded P1P2 path_image_linepath] + show thesis apply(rule that[of z]) proof- + have "(z \ closed_segment (vector [a $ 1 - 2, a $ 2 - 2]) (vector [pathstart f $ 1, a $ 2 - 2]) \ + z \ closed_segment (vector [pathstart f $ 1, a $ 2 - 2]) (pathstart f)) \ + z \ closed_segment (pathfinish f) (vector [pathfinish f $ 1, a $ 2 - 2]) \ + z \ closed_segment (vector [pathfinish f $ 1, a $ 2 - 2]) (vector [b $ 1 + 2, a $ 2 - 2]) \ + (((z \ closed_segment (vector [pathstart g $ 1, pathstart g $ 2 - 3]) (pathstart g)) \ + z \ closed_segment (pathfinish g) (vector [pathfinish g $ 1, a $ 2 - 1])) \ + z \ closed_segment (vector [pathfinish g $ 1, a $ 2 - 1]) (vector [b $ 1 + 1, a $ 2 - 1])) \ + z \ closed_segment (vector [b $ 1 + 1, a $ 2 - 1]) (vector [b $ 1 + 1, b $ 2 + 3]) \ False" + apply(simp only: segment_vertical segment_horizontal vector_2) proof- case goal1 note as=this + have "pathfinish f \ {a..b}" using assms(3) pathfinish_in_path_image[of f] by auto + hence "1 + b $ 1 \ pathfinish f $ 1 \ False" unfolding mem_interval forall_2 by auto + hence "z$1 \ pathfinish f$1" using as(2) using assms ab by(auto simp add:field_simps) + moreover have "pathstart f \ {a..b}" using assms(3) pathstart_in_path_image[of f] by auto + hence "1 + b $ 1 \ pathstart f $ 1 \ False" unfolding mem_interval forall_2 by auto + hence "z$1 \ pathstart f$1" using as(2) using assms ab by(auto simp add:field_simps) + ultimately have *:"z$2 = a$2 - 2" using goal1(1) by auto + have "z$1 \ pathfinish g$1" using as(2) using assms ab by(auto simp add:field_simps *) + moreover have "pathstart g \ {a..b}" using assms(4) pathstart_in_path_image[of g] by auto + note this[unfolded mem_interval forall_2] + hence "z$1 \ pathstart g$1" using as(1) using assms ab by(auto simp add:field_simps *) + ultimately have "a $ 2 - 1 \ z $ 2 \ z $ 2 \ b $ 2 + 3 \ b $ 2 + 3 \ z $ 2 \ z $ 2 \ a $ 2 - 1" + using as(2) unfolding * assms by(auto simp add:field_simps) + thus False unfolding * using ab by auto + qed hence "z \ path_image f \ z \ path_image g" using z unfolding Un_iff by blast + hence z':"z\{a..b}" using assms(3-4) by auto + have "a $ 2 = z $ 2 \ (z $ 1 = pathstart f $ 1 \ z $ 1 = pathfinish f $ 1) \ (z = pathstart f \ z = pathfinish f)" + unfolding Cart_eq forall_2 assms by auto + with z' show "z\path_image f" using z(1) unfolding Un_iff mem_interval forall_2 apply- + apply(simp only: segment_vertical segment_horizontal vector_2) unfolding assms by auto + have "a $ 2 = z $ 2 \ (z $ 1 = pathstart g $ 1 \ z $ 1 = pathfinish g $ 1) \ (z = pathstart g \ z = pathfinish g)" + unfolding Cart_eq forall_2 assms by auto + with z' show "z\path_image g" using z(2) unfolding Un_iff mem_interval forall_2 apply- + apply(simp only: segment_vertical segment_horizontal vector_2) unfolding assms by auto + qed qed + +(** The Following still needs to be translated. Maybe I will do that later. + +(* ------------------------------------------------------------------------- *) +(* Complement in dimension N >= 2 of set homeomorphic to any interval in *) +(* any dimension is (path-)connected. This naively generalizes the argument *) +(* in Ryuji Maehara's paper "The Jordan curve theorem via the Brouwer *) +(* fixed point theorem", American Mathematical Monthly 1984. *) +(* ------------------------------------------------------------------------- *) + +let RETRACTION_INJECTIVE_IMAGE_INTERVAL = prove + (`!p:real^M->real^N a b. + ~(interval[a,b] = {}) /\ + p continuous_on interval[a,b] /\ + (!x y. x IN interval[a,b] /\ y IN interval[a,b] /\ p x = p y ==> x = y) + ==> ?f. f continuous_on (:real^N) /\ + IMAGE f (:real^N) SUBSET (IMAGE p (interval[a,b])) /\ + (!x. x IN (IMAGE p (interval[a,b])) ==> f x = x)`, + REPEAT STRIP_TAC THEN + FIRST_ASSUM(MP_TAC o GEN_REWRITE_RULE I [INJECTIVE_ON_LEFT_INVERSE]) THEN + DISCH_THEN(X_CHOOSE_TAC `q:real^N->real^M`) THEN + SUBGOAL_THEN `(q:real^N->real^M) continuous_on + (IMAGE p (interval[a:real^M,b]))` + ASSUME_TAC THENL + [MATCH_MP_TAC CONTINUOUS_ON_INVERSE THEN ASM_REWRITE_TAC[COMPACT_INTERVAL]; + ALL_TAC] THEN + MP_TAC(ISPECL [`q:real^N->real^M`; + `IMAGE (p:real^M->real^N) + (interval[a,b])`; + `a:real^M`; `b:real^M`] + TIETZE_CLOSED_INTERVAL) THEN + ASM_SIMP_TAC[COMPACT_INTERVAL; COMPACT_CONTINUOUS_IMAGE; + COMPACT_IMP_CLOSED] THEN + ANTS_TAC THENL [ASM SET_TAC[]; ALL_TAC] THEN + DISCH_THEN(X_CHOOSE_THEN `r:real^N->real^M` STRIP_ASSUME_TAC) THEN + EXISTS_TAC `(p:real^M->real^N) o (r:real^N->real^M)` THEN + REWRITE_TAC[SUBSET; FORALL_IN_IMAGE; o_THM; IN_UNIV] THEN + CONJ_TAC THENL [ALL_TAC; ASM SET_TAC[]] THEN + MATCH_MP_TAC CONTINUOUS_ON_COMPOSE THEN ASM_REWRITE_TAC[] THEN + FIRST_X_ASSUM(MATCH_MP_TAC o MATCH_MP(REWRITE_RULE[IMP_CONJ] + CONTINUOUS_ON_SUBSET)) THEN ASM SET_TAC[]);; + +let UNBOUNDED_PATH_COMPONENTS_COMPLEMENT_HOMEOMORPHIC_INTERVAL = prove + (`!s:real^N->bool a b:real^M. + s homeomorphic (interval[a,b]) + ==> !x. ~(x IN s) ==> ~bounded(path_component((:real^N) DIFF s) x)`, + REPEAT GEN_TAC THEN REWRITE_TAC[homeomorphic; homeomorphism] THEN + REWRITE_TAC[LEFT_IMP_EXISTS_THM] THEN + MAP_EVERY X_GEN_TAC [`p':real^N->real^M`; `p:real^M->real^N`] THEN + DISCH_TAC THEN + SUBGOAL_THEN + `!x y. x IN interval[a,b] /\ y IN interval[a,b] /\ + (p:real^M->real^N) x = p y ==> x = y` + ASSUME_TAC THENL [ASM_MESON_TAC[]; ALL_TAC] THEN + FIRST_X_ASSUM(MP_TAC o funpow 4 CONJUNCT2) THEN + DISCH_THEN(CONJUNCTS_THEN2 (SUBST1_TAC o SYM) ASSUME_TAC) THEN + ASM_CASES_TAC `interval[a:real^M,b] = {}` THEN + ASM_REWRITE_TAC[IMAGE_CLAUSES; DIFF_EMPTY; PATH_COMPONENT_UNIV; + NOT_BOUNDED_UNIV] THEN + ABBREV_TAC `s = (:real^N) DIFF (IMAGE p (interval[a:real^M,b]))` THEN + X_GEN_TAC `c:real^N` THEN REPEAT STRIP_TAC THEN + SUBGOAL_THEN `(c:real^N) IN s` ASSUME_TAC THENL [ASM SET_TAC[]; ALL_TAC] THEN + SUBGOAL_THEN `bounded((path_component s c) UNION + (IMAGE (p:real^M->real^N) (interval[a,b])))` + MP_TAC THENL + [ASM_SIMP_TAC[BOUNDED_UNION; COMPACT_IMP_BOUNDED; COMPACT_IMP_BOUNDED; + COMPACT_CONTINUOUS_IMAGE; COMPACT_INTERVAL]; + ALL_TAC] THEN + DISCH_THEN(MP_TAC o SPEC `c:real^N` o MATCH_MP BOUNDED_SUBSET_BALL) THEN + REWRITE_TAC[UNION_SUBSET] THEN + DISCH_THEN(X_CHOOSE_THEN `B:real` STRIP_ASSUME_TAC) THEN + MP_TAC(ISPECL [`p:real^M->real^N`; `a:real^M`; `b:real^M`] + RETRACTION_INJECTIVE_IMAGE_INTERVAL) THEN + ASM_REWRITE_TAC[SUBSET; IN_UNIV] THEN + DISCH_THEN(X_CHOOSE_THEN `r:real^N->real^N` MP_TAC) THEN + DISCH_THEN(CONJUNCTS_THEN2 ASSUME_TAC + (CONJUNCTS_THEN2 MP_TAC ASSUME_TAC)) THEN + REWRITE_TAC[FORALL_IN_IMAGE; IN_UNIV] THEN DISCH_TAC THEN + ABBREV_TAC `q = \z:real^N. if z IN path_component s c then r(z) else z` THEN + SUBGOAL_THEN + `(q:real^N->real^N) continuous_on + (closure(path_component s c) UNION ((:real^N) DIFF (path_component s c)))` + MP_TAC THENL + [EXPAND_TAC "q" THEN MATCH_MP_TAC CONTINUOUS_ON_CASES THEN + REWRITE_TAC[CLOSED_CLOSURE; CONTINUOUS_ON_ID; GSYM OPEN_CLOSED] THEN + REPEAT CONJ_TAC THENL + [MATCH_MP_TAC OPEN_PATH_COMPONENT THEN EXPAND_TAC "s" THEN + ASM_SIMP_TAC[GSYM CLOSED_OPEN; COMPACT_IMP_CLOSED; + COMPACT_CONTINUOUS_IMAGE; COMPACT_INTERVAL]; + ASM_MESON_TAC[CONTINUOUS_ON_SUBSET; SUBSET_UNIV]; + ALL_TAC] THEN + X_GEN_TAC `z:real^N` THEN + REWRITE_TAC[SET_RULE `~(z IN (s DIFF t) /\ z IN t)`] THEN + STRIP_TAC THEN FIRST_X_ASSUM MATCH_MP_TAC THEN + MP_TAC(ISPECL + [`path_component s (z:real^N)`; `path_component s (c:real^N)`] + OPEN_INTER_CLOSURE_EQ_EMPTY) THEN + ASM_REWRITE_TAC[GSYM DISJOINT; PATH_COMPONENT_DISJOINT] THEN ANTS_TAC THENL + [MATCH_MP_TAC OPEN_PATH_COMPONENT THEN EXPAND_TAC "s" THEN + ASM_SIMP_TAC[GSYM CLOSED_OPEN; COMPACT_IMP_CLOSED; + COMPACT_CONTINUOUS_IMAGE; COMPACT_INTERVAL]; + REWRITE_TAC[DISJOINT; EXTENSION; IN_INTER; NOT_IN_EMPTY] THEN + DISCH_THEN(MP_TAC o SPEC `z:real^N`) THEN ASM_REWRITE_TAC[] THEN + GEN_REWRITE_TAC (LAND_CONV o ONCE_DEPTH_CONV) [IN] THEN + REWRITE_TAC[PATH_COMPONENT_REFL_EQ] THEN ASM SET_TAC[]]; + ALL_TAC] THEN + SUBGOAL_THEN + `closure(path_component s c) UNION ((:real^N) DIFF (path_component s c)) = + (:real^N)` + SUBST1_TAC THENL + [MATCH_MP_TAC(SET_RULE `s SUBSET t ==> t UNION (UNIV DIFF s) = UNIV`) THEN + REWRITE_TAC[CLOSURE_SUBSET]; + DISCH_TAC] THEN + MP_TAC(ISPECL + [`(\x. &2 % c - x) o + (\x. c + B / norm(x - c) % (x - c)) o (q:real^N->real^N)`; + `cball(c:real^N,B)`] + BROUWER) THEN + REWRITE_TAC[NOT_IMP; GSYM CONJ_ASSOC; COMPACT_CBALL; CONVEX_CBALL] THEN + ASM_SIMP_TAC[CBALL_EQ_EMPTY; REAL_LT_IMP_LE; REAL_NOT_LT] THEN + SUBGOAL_THEN `!x. ~((q:real^N->real^N) x = c)` ASSUME_TAC THENL + [X_GEN_TAC `x:real^N` THEN EXPAND_TAC "q" THEN + REWRITE_TAC[NORM_EQ_0; VECTOR_SUB_EQ] THEN COND_CASES_TAC THEN + ASM SET_TAC[PATH_COMPONENT_REFL_EQ]; + ALL_TAC] THEN + REPEAT CONJ_TAC THENL + [MATCH_MP_TAC CONTINUOUS_ON_COMPOSE THEN + SIMP_TAC[CONTINUOUS_ON_SUB; CONTINUOUS_ON_ID; CONTINUOUS_ON_CONST] THEN + MATCH_MP_TAC CONTINUOUS_ON_COMPOSE THEN CONJ_TAC THENL + [ASM_MESON_TAC[CONTINUOUS_ON_SUBSET; SUBSET_UNIV]; ALL_TAC] THEN + MATCH_MP_TAC CONTINUOUS_ON_ADD THEN REWRITE_TAC[CONTINUOUS_ON_CONST] THEN + MATCH_MP_TAC CONTINUOUS_ON_MUL THEN + SIMP_TAC[CONTINUOUS_ON_SUB; CONTINUOUS_ON_ID; CONTINUOUS_ON_CONST] THEN + REWRITE_TAC[o_DEF; real_div; LIFT_CMUL] THEN + MATCH_MP_TAC CONTINUOUS_ON_CMUL THEN + MATCH_MP_TAC(REWRITE_RULE[o_DEF] CONTINUOUS_ON_INV) THEN + ASM_REWRITE_TAC[FORALL_IN_IMAGE; NORM_EQ_0; VECTOR_SUB_EQ] THEN + SUBGOAL_THEN + `(\x:real^N. lift(norm(x - c))) = (lift o norm) o (\x. x - c)` + SUBST1_TAC THENL [REWRITE_TAC[o_DEF]; ALL_TAC] THEN + MATCH_MP_TAC CONTINUOUS_ON_COMPOSE THEN + ASM_SIMP_TAC[CONTINUOUS_ON_SUB; CONTINUOUS_ON_ID; CONTINUOUS_ON_CONST; + CONTINUOUS_ON_LIFT_NORM]; + REWRITE_TAC[SUBSET; FORALL_IN_IMAGE; IN_CBALL; o_THM; dist] THEN + X_GEN_TAC `x:real^N` THEN DISCH_TAC THEN + REWRITE_TAC[VECTOR_ARITH `c - (&2 % c - (c + x)) = x`] THEN + REWRITE_TAC[NORM_MUL; REAL_ABS_DIV; REAL_ABS_NORM] THEN + ASM_SIMP_TAC[REAL_DIV_RMUL; NORM_EQ_0; VECTOR_SUB_EQ] THEN + ASM_REAL_ARITH_TAC; + REWRITE_TAC[NOT_EXISTS_THM; TAUT `~(c /\ b) <=> c ==> ~b`] THEN + REWRITE_TAC[IN_CBALL; o_THM; dist] THEN + X_GEN_TAC `x:real^N` THEN DISCH_TAC THEN + REWRITE_TAC[VECTOR_ARITH `&2 % c - (c + x') = x <=> --x' = x - c`] THEN + ASM_CASES_TAC `(x:real^N) IN path_component s c` THENL + [MATCH_MP_TAC(NORM_ARITH `norm(y) < B /\ norm(x) = B ==> ~(--x = y)`) THEN + REWRITE_TAC[NORM_MUL; REAL_ABS_DIV; REAL_ABS_NORM] THEN + ASM_SIMP_TAC[REAL_DIV_RMUL; NORM_EQ_0; VECTOR_SUB_EQ] THEN + ASM_SIMP_TAC[REAL_ARITH `&0 < B ==> abs B = B`] THEN + UNDISCH_TAC `path_component s c SUBSET ball(c:real^N,B)` THEN + REWRITE_TAC[SUBSET; IN_BALL] THEN ASM_MESON_TAC[dist; NORM_SUB]; + EXPAND_TAC "q" THEN REWRITE_TAC[] THEN ASM_REWRITE_TAC[] THEN + REWRITE_TAC[VECTOR_ARITH `--(c % x) = x <=> (&1 + c) % x = vec 0`] THEN + ASM_REWRITE_TAC[DE_MORGAN_THM; VECTOR_SUB_EQ; VECTOR_MUL_EQ_0] THEN + SUBGOAL_THEN `~(x:real^N = c)` ASSUME_TAC THENL + [ASM_MESON_TAC[PATH_COMPONENT_REFL; IN]; ALL_TAC] THEN + ASM_REWRITE_TAC[] THEN + MATCH_MP_TAC(REAL_ARITH `&0 < x ==> ~(&1 + x = &0)`) THEN + ASM_SIMP_TAC[REAL_LT_DIV; NORM_POS_LT; VECTOR_SUB_EQ]]]);; + +let PATH_CONNECTED_COMPLEMENT_HOMEOMORPHIC_INTERVAL = prove + (`!s:real^N->bool a b:real^M. + 2 <= dimindex(:N) /\ s homeomorphic interval[a,b] + ==> path_connected((:real^N) DIFF s)`, + REPEAT STRIP_TAC THEN REWRITE_TAC[PATH_CONNECTED_IFF_PATH_COMPONENT] THEN + FIRST_ASSUM(MP_TAC o MATCH_MP + UNBOUNDED_PATH_COMPONENTS_COMPLEMENT_HOMEOMORPHIC_INTERVAL) THEN + ASM_REWRITE_TAC[SET_RULE `~(x IN s) <=> x IN (UNIV DIFF s)`] THEN + ABBREV_TAC `t = (:real^N) DIFF s` THEN + DISCH_TAC THEN MAP_EVERY X_GEN_TAC [`x:real^N`; `y:real^N`] THEN + STRIP_TAC THEN FIRST_ASSUM(MP_TAC o MATCH_MP HOMEOMORPHIC_COMPACTNESS) THEN + REWRITE_TAC[COMPACT_INTERVAL] THEN + DISCH_THEN(MP_TAC o MATCH_MP COMPACT_IMP_BOUNDED) THEN + REWRITE_TAC[BOUNDED_POS; LEFT_IMP_EXISTS_THM] THEN + X_GEN_TAC `B:real` THEN STRIP_TAC THEN + SUBGOAL_THEN `(?u:real^N. u IN path_component t x /\ B < norm(u)) /\ + (?v:real^N. v IN path_component t y /\ B < norm(v))` + STRIP_ASSUME_TAC THENL + [ASM_MESON_TAC[BOUNDED_POS; REAL_NOT_LE]; ALL_TAC] THEN + MATCH_MP_TAC PATH_COMPONENT_TRANS THEN EXISTS_TAC `u:real^N` THEN + CONJ_TAC THENL [ASM_MESON_TAC[IN]; ALL_TAC] THEN + MATCH_MP_TAC PATH_COMPONENT_SYM THEN + MATCH_MP_TAC PATH_COMPONENT_TRANS THEN EXISTS_TAC `v:real^N` THEN + CONJ_TAC THENL [ASM_MESON_TAC[IN]; ALL_TAC] THEN + MATCH_MP_TAC PATH_COMPONENT_OF_SUBSET THEN + EXISTS_TAC `(:real^N) DIFF cball(vec 0,B)` THEN CONJ_TAC THENL + [EXPAND_TAC "t" THEN MATCH_MP_TAC(SET_RULE + `s SUBSET t ==> (u DIFF t) SUBSET (u DIFF s)`) THEN + ASM_REWRITE_TAC[SUBSET; IN_CBALL_0]; + MP_TAC(ISPEC `cball(vec 0:real^N,B)` + PATH_CONNECTED_COMPLEMENT_BOUNDED_CONVEX) THEN + ASM_REWRITE_TAC[BOUNDED_CBALL; CONVEX_CBALL] THEN + REWRITE_TAC[PATH_CONNECTED_IFF_PATH_COMPONENT] THEN + DISCH_THEN MATCH_MP_TAC THEN + ASM_REWRITE_TAC[IN_DIFF; IN_UNIV; IN_CBALL_0; REAL_NOT_LE]]);; + +(* ------------------------------------------------------------------------- *) +(* In particular, apply all these to the special case of an arc. *) +(* ------------------------------------------------------------------------- *) + +let RETRACTION_ARC = prove + (`!p. arc p + ==> ?f. f continuous_on (:real^N) /\ + IMAGE f (:real^N) SUBSET path_image p /\ + (!x. x IN path_image p ==> f x = x)`, + REWRITE_TAC[arc; path; path_image] THEN REPEAT STRIP_TAC THEN + MATCH_MP_TAC RETRACTION_INJECTIVE_IMAGE_INTERVAL THEN + ASM_REWRITE_TAC[INTERVAL_EQ_EMPTY_1; DROP_VEC; REAL_NOT_LT; REAL_POS]);; + +let PATH_CONNECTED_ARC_COMPLEMENT = prove + (`!p. 2 <= dimindex(:N) /\ arc p + ==> path_connected((:real^N) DIFF path_image p)`, + REWRITE_TAC[arc; path] THEN REPEAT STRIP_TAC THEN SIMP_TAC[path_image] THEN + MP_TAC(ISPECL [`path_image p:real^N->bool`; `vec 0:real^1`; `vec 1:real^1`] + PATH_CONNECTED_COMPLEMENT_HOMEOMORPHIC_INTERVAL) THEN + ASM_REWRITE_TAC[path_image] THEN DISCH_THEN MATCH_MP_TAC THEN + ONCE_REWRITE_TAC[HOMEOMORPHIC_SYM] THEN + MATCH_MP_TAC HOMEOMORPHIC_COMPACT THEN + EXISTS_TAC `p:real^1->real^N` THEN ASM_REWRITE_TAC[COMPACT_INTERVAL]);; + +let CONNECTED_ARC_COMPLEMENT = prove + (`!p. 2 <= dimindex(:N) /\ arc p + ==> connected((:real^N) DIFF path_image p)`, + SIMP_TAC[PATH_CONNECTED_ARC_COMPLEMENT; PATH_CONNECTED_IMP_CONNECTED]);; *) + +end + diff -r 5fd36780760b -r 4c414d0835ab src/HOL/Multivariate_Analysis/Derivative.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Multivariate_Analysis/Derivative.thy Tue Nov 17 18:52:30 2009 +0100 @@ -0,0 +1,1332 @@ +(* Title: HOL/Library/Convex_Euclidean_Space.thy + Author: John Harrison + Translated to from HOL light: Robert Himmelmann, TU Muenchen *) + +header {* Multivariate calculus in Euclidean space. *} + +theory Derivative + imports Brouwer_Fixpoint RealVector +begin + + +(* Because I do not want to type this all the time *) +lemmas linear_linear = linear_conv_bounded_linear[THEN sym] + +subsection {* Derivatives *} + +text {* The definition is slightly tricky since we make it work over + nets of a particular form. This lets us prove theorems generally and use + "at a" or "at a within s" for restriction to a set (1-sided on R etc.) *} + +definition has_derivative :: "('a::real_normed_vector \ 'b::real_normed_vector) \ ('a \ 'b) \ ('a net \ bool)" +(infixl "(has'_derivative)" 12) where + "(f has_derivative f') net \ bounded_linear f' \ ((\y. (1 / (norm (y - netlimit net))) *\<^sub>R + (f y - (f (netlimit net) + f'(y - netlimit net)))) ---> 0) net" + +lemma derivative_linear[dest]:"(f has_derivative f') net \ bounded_linear f'" + unfolding has_derivative_def by auto + +lemma FDERIV_conv_has_derivative:"FDERIV f (x::'a::{real_normed_vector,perfect_space}) :> f' = (f has_derivative f') (at x)" (is "?l = ?r") proof + assume ?l note as = this[unfolded fderiv_def] + show ?r unfolding has_derivative_def Lim_at apply-apply(rule,rule as[THEN conjunct1]) proof(rule,rule) + fix e::real assume "e>0" + guess d using as[THEN conjunct2,unfolded LIM_def,rule_format,OF`e>0`] .. + thus "\d>0. \xa. 0 < dist xa x \ dist xa x < d \ + dist ((1 / norm (xa - netlimit (at x))) *\<^sub>R (f xa - (f (netlimit (at x)) + f' (xa - netlimit (at x))))) (0) < e" + apply(rule_tac x=d in exI) apply(erule conjE,rule,assumption) apply rule apply(erule_tac x="xa - x" in allE) + unfolding vector_dist_norm netlimit_at[of x] by(auto simp add:group_simps) qed next + assume ?r note as = this[unfolded has_derivative_def] + show ?l unfolding fderiv_def LIM_def apply-apply(rule,rule as[THEN conjunct1]) proof(rule,rule) + fix e::real assume "e>0" + guess d using as[THEN conjunct2,unfolded Lim_at,rule_format,OF`e>0`] .. + thus "\s>0. \xa. xa \ 0 \ dist xa 0 < s \ dist (norm (f (x + xa) - f x - f' xa) / norm xa) 0 < e" apply- + apply(rule_tac x=d in exI) apply(erule conjE,rule,assumption) apply rule apply(erule_tac x="xa + x" in allE) + unfolding vector_dist_norm netlimit_at[of x] by(auto simp add:group_simps) qed qed + +subsection {* These are the only cases we'll care about, probably. *} + +lemma has_derivative_within: "(f has_derivative f') (at x within s) \ + bounded_linear f' \ ((\y. (1 / norm(y - x)) *\<^sub>R (f y - (f x + f' (y - x)))) ---> 0) (at x within s)" + unfolding has_derivative_def and Lim by(auto simp add:netlimit_within) + +lemma has_derivative_at: "(f has_derivative f') (at x) \ + bounded_linear f' \ ((\y. (1 / (norm(y - x))) *\<^sub>R (f y - (f x + f' (y - x)))) ---> 0) (at x)" + apply(subst within_UNIV[THEN sym]) unfolding has_derivative_within unfolding within_UNIV by auto + +subsection {* More explicit epsilon-delta forms. *} + +lemma has_derivative_within': + "(f has_derivative f')(at x within s) \ bounded_linear f' \ + (\e>0. \d>0. \x'\s. 0 < norm(x' - x) \ norm(x' - x) < d + \ norm(f x' - f x - f'(x' - x)) / norm(x' - x) < e)" + unfolding has_derivative_within Lim_within vector_dist_norm + unfolding diff_0_right norm_mul by(simp add: group_simps) + +lemma has_derivative_at': + "(f has_derivative f') (at x) \ bounded_linear f' \ + (\e>0. \d>0. \x'. 0 < norm(x' - x) \ norm(x' - x) < d + \ norm(f x' - f x - f'(x' - x)) / norm(x' - x) < e)" + apply(subst within_UNIV[THEN sym]) unfolding has_derivative_within' by auto + +lemma has_derivative_at_within: "(f has_derivative f') (at x) \ (f has_derivative f') (at x within s)" + unfolding has_derivative_within' has_derivative_at' by meson + +lemma has_derivative_within_open: + "a \ s \ open s \ ((f has_derivative f') (at a within s) \ (f has_derivative f') (at a))" + unfolding has_derivative_within has_derivative_at using Lim_within_open by auto + +subsection {* Derivatives on real = Derivatives on real^1 *} + +lemma dist_vec1_0[simp]: "dist(vec1 (x::real)) 0 = norm x" unfolding vector_dist_norm by(auto simp add:vec1_dest_vec1_simps) + +lemma bounded_linear_vec1_dest_vec1: fixes f::"real \ real" + shows "linear (vec1 \ f \ dest_vec1) = bounded_linear f" (is "?l = ?r") proof- + { assume ?l guess K using linear_bounded[OF `?l`] .. + hence "\K. \x. \f x\ \ \x\ * K" apply(rule_tac x=K in exI) + unfolding vec1_dest_vec1_simps by (auto simp add:field_simps) } + thus ?thesis unfolding linear_def bounded_linear_def additive_def bounded_linear_axioms_def o_def + unfolding vec1_dest_vec1_simps by auto qed + +lemma has_derivative_within_vec1_dest_vec1: fixes f::"real\real" shows + "((vec1 \ f \ dest_vec1) has_derivative (vec1 \ f' \ dest_vec1)) (at (vec1 x) within vec1 ` s) + = (f has_derivative f') (at x within s)" + unfolding has_derivative_within unfolding bounded_linear_vec1_dest_vec1[unfolded linear_conv_bounded_linear] + unfolding o_def Lim_within Ball_def unfolding forall_vec1 + unfolding vec1_dest_vec1_simps dist_vec1_0 image_iff by auto + +lemma has_derivative_at_vec1_dest_vec1: fixes f::"real\real" shows + "((vec1 \ f \ dest_vec1) has_derivative (vec1 \ f' \ dest_vec1)) (at (vec1 x)) = (f has_derivative f') (at x)" + using has_derivative_within_vec1_dest_vec1[where s=UNIV, unfolded range_vec1 within_UNIV] by auto + +lemma bounded_linear_vec1: fixes f::"'a::real_normed_vector\real" + shows "bounded_linear f = bounded_linear (vec1 \ f)" + unfolding bounded_linear_def additive_def bounded_linear_axioms_def o_def + unfolding vec1_dest_vec1_simps by auto + +lemma bounded_linear_dest_vec1: fixes f::"real\'a::real_normed_vector" + shows "bounded_linear f = bounded_linear (f \ dest_vec1)" + unfolding bounded_linear_def additive_def bounded_linear_axioms_def o_def + unfolding vec1_dest_vec1_simps by auto + +lemma has_derivative_at_vec1: fixes f::"'a::real_normed_vector\real" shows + "(f has_derivative f') (at x) = ((vec1 \ f) has_derivative (vec1 \ f')) (at x)" + unfolding has_derivative_at unfolding bounded_linear_vec1[unfolded linear_conv_bounded_linear] + unfolding o_def Lim_at unfolding vec1_dest_vec1_simps dist_vec1_0 by auto + +lemma has_derivative_within_dest_vec1:fixes f::"real\'a::real_normed_vector" shows + "((f \ dest_vec1) has_derivative (f' \ dest_vec1)) (at (vec1 x) within vec1 ` s) = (f has_derivative f') (at x within s)" + unfolding has_derivative_within bounded_linear_dest_vec1 unfolding o_def Lim_within Ball_def + unfolding vec1_dest_vec1_simps dist_vec1_0 image_iff by auto + +lemma has_derivative_at_dest_vec1:fixes f::"real\'a::real_normed_vector" shows + "((f \ dest_vec1) has_derivative (f' \ dest_vec1)) (at (vec1 x)) = (f has_derivative f') (at x)" + using has_derivative_within_dest_vec1[where s=UNIV] by(auto simp add:within_UNIV) + +lemma derivative_is_linear: fixes f::"real^'a::finite \ real^'b::finite" shows + "(f has_derivative f') net \ linear f'" + unfolding has_derivative_def and linear_conv_bounded_linear by auto + + +subsection {* Combining theorems. *} + +lemma (in bounded_linear) has_derivative: "(f has_derivative f) net" + unfolding has_derivative_def apply(rule,rule bounded_linear_axioms) + unfolding diff by(simp add: Lim_const) + +lemma has_derivative_id: "((\x. x) has_derivative (\h. h)) net" + apply(rule bounded_linear.has_derivative) using bounded_linear_ident[unfolded id_def] by simp + +lemma has_derivative_const: "((\x. c) has_derivative (\h. 0)) net" + unfolding has_derivative_def apply(rule,rule bounded_linear_zero) by(simp add: Lim_const) + +lemma (in bounded_linear) cmul: shows "bounded_linear (\x. (c::real) *\<^sub>R f x)" proof + guess K using pos_bounded .. + thus "\K. \x. norm ((c::real) *\<^sub>R f x) \ norm x * K" apply(rule_tac x="abs c * K" in exI) proof + fix x case goal1 + hence "abs c * norm (f x) \ abs c * (norm x * K)" apply-apply(erule conjE,erule_tac x=x in allE) + apply(rule mult_left_mono) by auto + thus ?case by(auto simp add:field_simps) + qed qed(auto simp add: scaleR.add_right add scaleR) + +lemma has_derivative_cmul: assumes "(f has_derivative f') net" shows "((\x. c *\<^sub>R f(x)) has_derivative (\h. c *\<^sub>R f'(h))) net" + unfolding has_derivative_def apply(rule,rule bounded_linear.cmul) + using assms[unfolded has_derivative_def] using Lim_cmul[OF assms[unfolded has_derivative_def,THEN conjunct2]] + unfolding scaleR_right_diff_distrib scaleR_right_distrib by auto + +lemma has_derivative_cmul_eq: assumes "c \ 0" + shows "(((\x. c *\<^sub>R f(x)) has_derivative (\h. c *\<^sub>R f'(h))) net \ (f has_derivative f') net)" + apply(rule) defer apply(rule has_derivative_cmul,assumption) + apply(drule has_derivative_cmul[where c="1/c"]) using assms by auto + +lemma has_derivative_neg: + "(f has_derivative f') net \ ((\x. -(f x)) has_derivative (\h. -(f' h))) net" + apply(drule has_derivative_cmul[where c="-1"]) by auto + +lemma has_derivative_neg_eq: "((\x. -(f x)) has_derivative (\h. -(f' h))) net \ (f has_derivative f') net" + apply(rule, drule_tac[!] has_derivative_neg) by auto + +lemma has_derivative_add: assumes "(f has_derivative f') net" "(g has_derivative g') net" + shows "((\x. f(x) + g(x)) has_derivative (\h. f'(h) + g'(h))) net" proof- + note as = assms[unfolded has_derivative_def] + show ?thesis unfolding has_derivative_def apply(rule,rule bounded_linear_add) + using Lim_add[OF as(1)[THEN conjunct2] as(2)[THEN conjunct2]] and as + by(auto simp add:group_simps scaleR_right_diff_distrib scaleR_right_distrib) qed + +lemma has_derivative_add_const:"(f has_derivative f') net \ ((\x. f x + c) has_derivative f') net" + apply(drule has_derivative_add) apply(rule has_derivative_const) by auto + +lemma has_derivative_sub: + "(f has_derivative f') net \ (g has_derivative g') net \ ((\x. f(x) - g(x)) has_derivative (\h. f'(h) - g'(h))) net" + apply(drule has_derivative_add) apply(drule has_derivative_neg,assumption) by(simp add:group_simps) + +lemma has_derivative_setsum: assumes "finite s" "\a\s. ((f a) has_derivative (f' a)) net" + shows "((\x. setsum (\a. f a x) s) has_derivative (\h. setsum (\a. f' a h) s)) net" + apply(induct_tac s rule:finite_subset_induct[where A=s]) apply(rule assms(1)) +proof- fix x F assume as:"finite F" "x \ F" "x\s" "((\x. \a\F. f a x) has_derivative (\h. \a\F. f' a h)) net" + thus "((\xa. \a\insert x F. f a xa) has_derivative (\h. \a\insert x F. f' a h)) net" + unfolding setsum_insert[OF as(1,2)] apply-apply(rule has_derivative_add) apply(rule assms(2)[rule_format]) by auto +qed(auto intro!: has_derivative_const) + +lemma has_derivative_setsum_numseg: + "\i. m \ i \ i \ n \ ((f i) has_derivative (f' i)) net \ + ((\x. setsum (\i. f i x) {m..n::nat}) has_derivative (\h. setsum (\i. f' i h) {m..n})) net" + apply(rule has_derivative_setsum) by auto + +subsection {* somewhat different results for derivative of scalar multiplier. *} + +lemma has_derivative_vmul_component: fixes c::"real^'a::finite \ real^'b::finite" and v::"real^'c::finite" + assumes "(c has_derivative c') net" + shows "((\x. c(x)$k *\<^sub>R v) has_derivative (\x. (c' x)$k *\<^sub>R v)) net" proof- + have *:"\y. (c y $ k *\<^sub>R v - (c (netlimit net) $ k *\<^sub>R v + c' (y - netlimit net) $ k *\<^sub>R v)) = + (c y $ k - (c (netlimit net) $ k + c' (y - netlimit net) $ k)) *\<^sub>R v" + unfolding scaleR_left_diff_distrib scaleR_left_distrib by auto + show ?thesis unfolding has_derivative_def and * and linear_conv_bounded_linear[symmetric] + apply(rule,rule linear_vmul_component[of c' k v, unfolded smult_conv_scaleR]) defer + apply(subst vector_smult_lzero[THEN sym, of v]) unfolding scaleR_scaleR smult_conv_scaleR apply(rule Lim_vmul) + using assms[unfolded has_derivative_def] unfolding Lim o_def apply- apply(cases "trivial_limit net") + apply(rule,assumption,rule disjI2,rule,rule) proof- + have *:"\x. x - vec 0 = (x::real^'n)" by auto + have **:"\d x. d * (c x $ k - (c (netlimit net) $ k + c' (x - netlimit net) $ k)) = (d *\<^sub>R (c x - (c (netlimit net) + c' (x - netlimit net) ))) $k" by(auto simp add:field_simps) + fix e assume "\ trivial_limit net" "0 < (e::real)" + then obtain A where A:"A\Rep_net net" "\x\A. dist ((1 / norm (x - netlimit net)) *\<^sub>R (c x - (c (netlimit net) + c' (x - netlimit net)))) 0 < e" + using assms[unfolded has_derivative_def Lim] unfolding eventually_def by auto + show "eventually (\x. dist (1 / norm (x - netlimit net) * (c x $ k - (c (netlimit net) $ k + c' (x - netlimit net) $ k))) 0 < e) net" + unfolding eventually_def apply(rule_tac x=A in bexI) apply rule proof- + case goal1 thus ?case apply -apply(drule A(2)[rule_format]) unfolding vector_dist_norm vec1_vec apply(rule le_less_trans) prefer 2 apply assumption unfolding * ** and norm_vec1[unfolded vec1_vec] + using component_le_norm[of "(1 / norm (x - netlimit net)) *\<^sub>R (c x - (c (netlimit net) + c' (x - netlimit net))) - 0" k] by auto + qed(insert A, auto) qed(insert assms[unfolded has_derivative_def], auto simp add:linear_conv_bounded_linear) qed + +lemma has_derivative_vmul_within: fixes c::"real \ real" and v::"real^'a::finite" + assumes "(c has_derivative c') (at x within s)" + shows "((\x. (c x) *\<^sub>R v) has_derivative (\x. (c' x) *\<^sub>R v)) (at x within s)" proof- + have *:"\c. (\x. (vec1 \ c \ dest_vec1) x $ 1 *\<^sub>R v) = (\x. (c x) *\<^sub>R v) \ dest_vec1" unfolding o_def by auto + show ?thesis using has_derivative_vmul_component[of "vec1 \ c \ dest_vec1" "vec1 \ c' \ dest_vec1" "at (vec1 x) within vec1 ` s" 1 v] + unfolding * and has_derivative_within_vec1_dest_vec1 unfolding has_derivative_within_dest_vec1 using assms by auto qed + +lemma has_derivative_vmul_at: fixes c::"real \ real" and v::"real^'a::finite" + assumes "(c has_derivative c') (at x)" + shows "((\x. (c x) *\<^sub>R v) has_derivative (\x. (c' x) *\<^sub>R v)) (at x)" + using has_derivative_vmul_within[where s=UNIV] and assms by(auto simp add: within_UNIV) + +lemma has_derivative_lift_dot: + assumes "(f has_derivative f') net" + shows "((\x. inner v (f x)) has_derivative (\t. inner v (f' t))) net" proof- + show ?thesis using assms unfolding has_derivative_def apply- apply(erule conjE,rule) + apply(rule bounded_linear_compose[of _ f']) apply(rule inner.bounded_linear_right,assumption) + apply(drule Lim_inner[where a=v]) unfolding o_def + by(auto simp add:inner.scaleR_right inner.add_right inner.diff_right) qed + +lemmas has_derivative_intros = has_derivative_sub has_derivative_add has_derivative_cmul has_derivative_id has_derivative_const + has_derivative_neg has_derivative_vmul_component has_derivative_vmul_at has_derivative_vmul_within has_derivative_cmul + bounded_linear.has_derivative has_derivative_lift_dot + +subsection {* limit transformation for derivatives. *} + +lemma has_derivative_transform_within: + assumes "0 < d" "x \ s" "\x'\s. dist x' x < d \ f x' = g x'" "(f has_derivative f') (at x within s)" + shows "(g has_derivative f') (at x within s)" + using assms(4) unfolding has_derivative_within apply- apply(erule conjE,rule,assumption) + apply(rule Lim_transform_within[OF assms(1)]) defer apply assumption + apply(rule,rule) apply(drule assms(3)[rule_format]) using assms(3)[rule_format, OF assms(2)] by auto + +lemma has_derivative_transform_at: + assumes "0 < d" "\x'. dist x' x < d \ f x' = g x'" "(f has_derivative f') (at x)" + shows "(g has_derivative f') (at x)" + apply(subst within_UNIV[THEN sym]) apply(rule has_derivative_transform_within[OF assms(1)]) + using assms(2-3) unfolding within_UNIV by auto + +lemma has_derivative_transform_within_open: + assumes "open s" "x \ s" "\y\s. f y = g y" "(f has_derivative f') (at x)" + shows "(g has_derivative f') (at x)" + using assms(4) unfolding has_derivative_at apply- apply(erule conjE,rule,assumption) + apply(rule Lim_transform_within_open[OF assms(1,2)]) defer apply assumption + apply(rule,rule) apply(drule assms(3)[rule_format]) using assms(3)[rule_format, OF assms(2)] by auto + +subsection {* differentiability. *} + +definition differentiable :: "('a::real_normed_vector \ 'b::real_normed_vector) \ 'a net \ bool" (infixr "differentiable" 30) where + "f differentiable net \ (\f'. (f has_derivative f') net)" + +definition differentiable_on :: "('a::real_normed_vector \ 'b::real_normed_vector) \ 'a set \ bool" (infixr "differentiable'_on" 30) where + "f differentiable_on s \ (\x\s. f differentiable (at x within s))" + +lemma differentiableI: "(f has_derivative f') net \ f differentiable net" + unfolding differentiable_def by auto + +lemma differentiable_at_withinI: "f differentiable (at x) \ f differentiable (at x within s)" + unfolding differentiable_def using has_derivative_at_within by blast + +lemma differentiable_within_open: assumes "a \ s" "open s" shows + "f differentiable (at a within s) \ (f differentiable (at a))" + unfolding differentiable_def has_derivative_within_open[OF assms] by auto + +lemma differentiable_at_imp_differentiable_on: "(\x\(s::(real^'n::finite) set). f differentiable at x) \ f differentiable_on s" + unfolding differentiable_on_def by(auto intro!: differentiable_at_withinI) + +lemma differentiable_on_eq_differentiable_at: "open s \ (f differentiable_on s \ (\x\s. f differentiable at x))" + unfolding differentiable_on_def by(auto simp add: differentiable_within_open) + +lemma differentiable_transform_within: + assumes "0 < d" "x \ s" "\x'\s. dist x' x < d \ f x' = g x'" "f differentiable (at x within s)" + shows "g differentiable (at x within s)" + using assms(4) unfolding differentiable_def by(auto intro!: has_derivative_transform_within[OF assms(1-3)]) + +lemma differentiable_transform_at: + assumes "0 < d" "\x'. dist x' x < d \ f x' = g x'" "f differentiable at x" + shows "g differentiable at x" + using assms(3) unfolding differentiable_def using has_derivative_transform_at[OF assms(1-2)] by auto + +subsection {* Frechet derivative and Jacobian matrix. *} + +definition "frechet_derivative f net = (SOME f'. (f has_derivative f') net)" + +lemma frechet_derivative_works: + "f differentiable net \ (f has_derivative (frechet_derivative f net)) net" + unfolding frechet_derivative_def differentiable_def and some_eq_ex[of "\ f' . (f has_derivative f') net"] .. + +lemma linear_frechet_derivative: fixes f::"real^'a::finite \ real^'b::finite" + shows "f differentiable net \ linear(frechet_derivative f net)" + unfolding frechet_derivative_works has_derivative_def unfolding linear_conv_bounded_linear by auto + +definition "jacobian f net = matrix(frechet_derivative f net)" + +lemma jacobian_works: "(f::(real^'a::finite) \ (real^'b::finite)) differentiable net \ (f has_derivative (\h. (jacobian f net) *v h)) net" + apply rule unfolding jacobian_def apply(simp only: matrix_works[OF linear_frechet_derivative]) defer + apply(rule differentiableI) apply assumption unfolding frechet_derivative_works by assumption + +subsection {* Differentiability implies continuity. *} + +lemma Lim_mul_norm_within: fixes f::"'a::real_normed_vector \ 'b::real_normed_vector" + shows "(f ---> 0) (at a within s) \ ((\x. norm(x - a) *\<^sub>R f(x)) ---> 0) (at a within s)" + unfolding Lim_within apply(rule,rule) apply(erule_tac x=e in allE,erule impE,assumption,erule exE,erule conjE) + apply(rule_tac x="min d 1" in exI) apply rule defer apply(rule,erule_tac x=x in ballE) unfolding vector_dist_norm diff_0_right norm_mul + by(auto intro!: mult_strict_mono[of _ "1::real", unfolded mult_1_left]) + +lemma differentiable_imp_continuous_within: assumes "f differentiable (at x within s)" + shows "continuous (at x within s) f" proof- + from assms guess f' unfolding differentiable_def has_derivative_within .. note f'=this + then interpret bounded_linear f' by auto + have *:"\xa. x\xa \ (f' \ (\y. y - x)) xa + norm (xa - x) *\<^sub>R ((1 / norm (xa - x)) *\<^sub>R (f xa - (f x + f' (xa - x)))) - ((f' \ (\y. y - x)) x + 0) = f xa - f x" + using zero by auto + have **:"continuous (at x within s) (f' \ (\y. y - x))" + apply(rule continuous_within_compose) apply(rule continuous_intros)+ + by(rule linear_continuous_within[OF f'[THEN conjunct1]]) + show ?thesis unfolding continuous_within using f'[THEN conjunct2, THEN Lim_mul_norm_within] + apply-apply(drule Lim_add) apply(rule **[unfolded continuous_within]) unfolding Lim_within and vector_dist_norm + apply(rule,rule) apply(erule_tac x=e in allE) apply(erule impE|assumption)+ apply(erule exE,rule_tac x=d in exI) + by(auto simp add:zero * elim!:allE) qed + +lemma differentiable_imp_continuous_at: "f differentiable at x \ continuous (at x) f" + by(rule differentiable_imp_continuous_within[of _ x UNIV, unfolded within_UNIV]) + +lemma differentiable_imp_continuous_on: "f differentiable_on s \ continuous_on s f" + unfolding differentiable_on_def continuous_on_eq_continuous_within + using differentiable_imp_continuous_within by blast + +lemma has_derivative_within_subset: + "(f has_derivative f') (at x within s) \ t \ s \ (f has_derivative f') (at x within t)" + unfolding has_derivative_within using Lim_within_subset by blast + +lemma differentiable_within_subset: + "f differentiable (at x within t) \ s \ t \ f differentiable (at x within s)" + unfolding differentiable_def using has_derivative_within_subset by blast + +lemma differentiable_on_subset: "f differentiable_on t \ s \ t \ f differentiable_on s" + unfolding differentiable_on_def using differentiable_within_subset by blast + +lemma differentiable_on_empty: "f differentiable_on {}" + unfolding differentiable_on_def by auto + +subsection {* Several results are easier using a "multiplied-out" variant. *) +(* (I got this idea from Dieudonne's proof of the chain rule). *} + +lemma has_derivative_within_alt: + "(f has_derivative f') (at x within s) \ bounded_linear f' \ + (\e>0. \d>0. \y\s. norm(y - x) < d \ norm(f(y) - f(x) - f'(y - x)) \ e * norm(y - x))" (is "?lhs \ ?rhs") +proof assume ?lhs thus ?rhs unfolding has_derivative_within apply-apply(erule conjE,rule,assumption) + unfolding Lim_within apply(rule,erule_tac x=e in allE,rule,erule impE,assumption) + apply(erule exE,rule_tac x=d in exI) apply(erule conjE,rule,assumption,rule,rule) proof- + fix x y e d assume as:"0 < e" "0 < d" "norm (y - x) < d" "\xa\s. 0 < dist xa x \ dist xa x < d \ + dist ((1 / norm (xa - x)) *\<^sub>R (f xa - (f x + f' (xa - x)))) 0 < e" "y \ s" "bounded_linear f'" + then interpret bounded_linear f' by auto + show "norm (f y - f x - f' (y - x)) \ e * norm (y - x)" proof(cases "y=x") + case True thus ?thesis using `bounded_linear f'` by(auto simp add: zero) next + case False hence "norm (f y - (f x + f' (y - x))) < e * norm (y - x)" using as(4)[rule_format, OF `y\s`] + unfolding vector_dist_norm diff_0_right norm_mul using as(3) + using pos_divide_less_eq[OF False[unfolded dist_nz], unfolded vector_dist_norm] + by(auto simp add:linear_0 linear_sub group_simps) + thus ?thesis by(auto simp add:group_simps) qed qed next + assume ?rhs thus ?lhs unfolding has_derivative_within Lim_within apply-apply(erule conjE,rule,assumption) + apply(rule,erule_tac x="e/2" in allE,rule,erule impE) defer apply(erule exE,rule_tac x=d in exI) + apply(erule conjE,rule,assumption,rule,rule) unfolding vector_dist_norm diff_0_right norm_scaleR + apply(erule_tac x=xa in ballE,erule impE) proof- + fix e d y assume "bounded_linear f'" "0 < e" "0 < d" "y \ s" "0 < norm (y - x) \ norm (y - x) < d" + "norm (f y - f x - f' (y - x)) \ e / 2 * norm (y - x)" + thus "\1 / norm (y - x)\ * norm (f y - (f x + f' (y - x))) < e" + apply(rule_tac le_less_trans[of _ "e/2"]) by(auto intro!:mult_imp_div_pos_le simp add:group_simps) qed auto qed + +lemma has_derivative_at_alt: + "(f has_derivative f') (at (x::real^'n::finite)) \ bounded_linear f' \ + (\e>0. \d>0. \y. norm(y - x) < d \ norm(f y - f x - f'(y - x)) \ e * norm(y - x))" + using has_derivative_within_alt[where s=UNIV] unfolding within_UNIV by auto + +subsection {* The chain rule. *} + +lemma diff_chain_within: + assumes "(f has_derivative f') (at x within s)" "(g has_derivative g') (at (f x) within (f ` s))" + shows "((g o f) has_derivative (g' o f'))(at x within s)" + unfolding has_derivative_within_alt apply(rule,rule bounded_linear_compose[unfolded o_def[THEN sym]]) + apply(rule assms(2)[unfolded has_derivative_def,THEN conjE],assumption) + apply(rule assms(1)[unfolded has_derivative_def,THEN conjE],assumption) proof(rule,rule) + note assms = assms[unfolded has_derivative_within_alt] + fix e::real assume "0 0" using `e>0` B2 apply-apply(rule divide_pos_pos) by auto + guess d1 using assms(1)[THEN conjunct2, rule_format, OF *] .. note d1 = this + have *:"e / 2 / (1 + B1) > 0" using `e>0` B1 apply-apply(rule divide_pos_pos) by auto + guess de using assms(2)[THEN conjunct2, rule_format, OF *] .. note de = this + guess d2 using assms(1)[THEN conjunct2, rule_format, OF zero_less_one] .. note d2 = this + + def d0 \ "(min d1 d2)/2" have d0:"d0>0" "d0 < d1" "d0 < d2" unfolding d0_def using d1 d2 by auto + def d \ "(min d0 (de / (B1 + 1))) / 2" have "de * 2 / (B1 + 1) > de / (B1 + 1)" apply(rule divide_strict_right_mono) using B1 de by auto + hence d:"d>0" "d < d1" "d < d2" "d < (de / (B1 + 1))" unfolding d_def using d0 d1 d2 de B1 by(auto intro!: divide_pos_pos simp add:min_less_iff_disj not_less) + + show "\d>0. \y\s. norm (y - x) < d \ norm ((g \ f) y - (g \ f) x - (g' \ f') (y - x)) \ e * norm (y - x)" apply(rule_tac x=d in exI) + proof(rule,rule `d>0`,rule,rule) + fix y assume as:"y \ s" "norm (y - x) < d" + hence 1:"norm (f y - f x - f' (y - x)) \ min (norm (y - x)) (e / 2 / B2 * norm (y - x))" using d1 d2 d by auto + + have "norm (f y - f x) \ norm (f y - f x - f' (y - x)) + norm (f' (y - x))" + using norm_triangle_sub[of "f y - f x" "f' (y - x)"] by(auto simp add:group_simps) + also have "\ \ norm (f y - f x - f' (y - x)) + B1 * norm (y - x)" apply(rule add_left_mono) using B1 by(auto simp add:group_simps) + also have "\ \ min (norm (y - x)) (e / 2 / B2 * norm (y - x)) + B1 * norm (y - x)" apply(rule add_right_mono) using d1 d2 d as by auto + also have "\ \ norm (y - x) + B1 * norm (y - x)" by auto + also have "\ = norm (y - x) * (1 + B1)" by(auto simp add:field_simps) + finally have 3:"norm (f y - f x) \ norm (y - x) * (1 + B1)" by auto + + hence "norm (f y - f x) \ d * (1 + B1)" apply- apply(rule order_trans,assumption,rule mult_right_mono) using as B1 by auto + also have "\ < de" using d B1 by(auto simp add:field_simps) + finally have "norm (g (f y) - g (f x) - g' (f y - f x)) \ e / 2 / (1 + B1) * norm (f y - f x)" + apply-apply(rule de[THEN conjunct2,rule_format]) using `y\s` using d as by auto + also have "\ = (e / 2) * (1 / (1 + B1) * norm (f y - f x))" by auto + also have "\ \ e / 2 * norm (y - x)" apply(rule mult_left_mono) using `e>0` and 3 using B1 and `e>0` by(auto simp add:divide_le_eq) + finally have 4:"norm (g (f y) - g (f x) - g' (f y - f x)) \ e / 2 * norm (y - x)" by auto + + interpret g': bounded_linear g' using assms(2) by auto + interpret f': bounded_linear f' using assms(1) by auto + have "norm (- g' (f' (y - x)) + g' (f y - f x)) = norm (g' (f y - f x - f' (y - x)))" + by(auto simp add:group_simps f'.diff g'.diff g'.add) + also have "\ \ B2 * norm (f y - f x - f' (y - x))" using B2 by(auto simp add:group_simps) + also have "\ \ B2 * (e / 2 / B2 * norm (y - x))" apply(rule mult_left_mono) using as d1 d2 d B2 by auto + also have "\ \ e / 2 * norm (y - x)" using B2 by auto + finally have 5:"norm (- g' (f' (y - x)) + g' (f y - f x)) \ e / 2 * norm (y - x)" by auto + + have "norm (g (f y) - g (f x) - g' (f y - f x)) + norm (g (f y) - g (f x) - g' (f' (y - x)) - (g (f y) - g (f x) - g' (f y - f x))) \ e * norm (y - x)" using 5 4 by auto + thus "norm ((g \ f) y - (g \ f) x - (g' \ f') (y - x)) \ e * norm (y - x)" unfolding o_def apply- apply(rule order_trans, rule norm_triangle_sub) by assumption qed qed + +lemma diff_chain_at: + "(f has_derivative f') (at x) \ (g has_derivative g') (at (f x)) \ ((g o f) has_derivative (g' o f')) (at x)" + using diff_chain_within[of f f' x UNIV g g'] using has_derivative_within_subset[of g g' "f x" UNIV "range f"] unfolding within_UNIV by auto + +subsection {* Composition rules stated just for differentiability. *} + +lemma differentiable_const[intro]: "(\z. c) differentiable (net::'a::real_normed_vector net)" + unfolding differentiable_def using has_derivative_const by auto + +lemma differentiable_id[intro]: "(\z. z) differentiable (net::'a::real_normed_vector net)" + unfolding differentiable_def using has_derivative_id by auto + +lemma differentiable_cmul[intro]: "f differentiable net \ (\x. c *\<^sub>R f(x)) differentiable (net::'a::real_normed_vector net)" + unfolding differentiable_def apply(erule exE, drule has_derivative_cmul) by auto + +lemma differentiable_neg[intro]: "f differentiable net \ (\z. -(f z)) differentiable (net::'a::real_normed_vector net)" + unfolding differentiable_def apply(erule exE, drule has_derivative_neg) by auto + +lemma differentiable_add: "f differentiable net \ g differentiable net + \ (\z. f z + g z) differentiable (net::'a::real_normed_vector net)" + unfolding differentiable_def apply(erule exE)+ apply(rule_tac x="\z. f' z + f'a z" in exI) + apply(rule has_derivative_add) by auto + +lemma differentiable_sub: "f differentiable net \ g differentiable net + \ (\z. f z - g z) differentiable (net::'a::real_normed_vector net)" + unfolding differentiable_def apply(erule exE)+ apply(rule_tac x="\z. f' z - f'a z" in exI) + apply(rule has_derivative_sub) by auto + +lemma differentiable_setsum: fixes f::"'a \ (real^'n::finite \real^'n)" + assumes "finite s" "\a\s. (f a) differentiable net" + shows "(\x. setsum (\a. f a x) s) differentiable net" proof- + guess f' using bchoice[OF assms(2)[unfolded differentiable_def]] .. + thus ?thesis unfolding differentiable_def apply- apply(rule,rule has_derivative_setsum[where f'=f'],rule assms(1)) by auto qed + +lemma differentiable_setsum_numseg: fixes f::"_ \ (real^'n::finite \real^'n)" + shows "\i. m \ i \ i \ n \ (f i) differentiable net \ (\x. setsum (\a. f a x) {m::nat..n}) differentiable net" + apply(rule differentiable_setsum) using finite_atLeastAtMost[of n m] by auto + +lemma differentiable_chain_at: + "f differentiable (at x) \ g differentiable (at(f x)) \ (g o f) differentiable (at x)" + unfolding differentiable_def by(meson diff_chain_at) + +lemma differentiable_chain_within: + "f differentiable (at x within s) \ g differentiable (at(f x) within (f ` s)) + \ (g o f) differentiable (at x within s)" + unfolding differentiable_def by(meson diff_chain_within) + +subsection {* Uniqueness of derivative. *) +(* *) +(* The general result is a bit messy because we need approachability of the *) +(* limit point from any direction. But OK for nontrivial intervals etc. *} + +lemma frechet_derivative_unique_within: fixes f::"real^'a::finite \ real^'b::finite" + assumes "(f has_derivative f') (at x within s)" "(f has_derivative f'') (at x within s)" + "(\i::'a::finite. \e>0. \d. 0 < abs(d) \ abs(d) < e \ (x + d *\<^sub>R basis i) \ s)" shows "f' = f''" proof- + note as = assms(1,2)[unfolded has_derivative_def] + then interpret f': bounded_linear f' by auto from as interpret f'': bounded_linear f'' by auto + have "x islimpt s" unfolding islimpt_approachable proof(rule,rule) + guess a using UNIV_witness[where 'a='a] .. + fix e::real assume "00`,of a] .. + thus "\x'\s. x' \ x \ dist x' x < e" apply(rule_tac x="x + d*\<^sub>R basis a" in bexI) + using basis_nonzero[of a] norm_basis[of a] unfolding vector_dist_norm by auto qed + hence *:"netlimit (at x within s) = x" apply-apply(rule netlimit_within) unfolding trivial_limit_within by simp + show ?thesis apply(rule linear_eq_stdbasis) unfolding linear_conv_bounded_linear + apply(rule as(1,2)[THEN conjunct1])+ proof(rule,rule ccontr) + fix i::'a def e \ "norm (f' (basis i) - f'' (basis i))" + assume "f' (basis i) \ f'' (basis i)" hence "e>0" unfolding e_def by auto + guess d using Lim_sub[OF as(1,2)[THEN conjunct2], unfolded * Lim_within,rule_format,OF `e>0`] .. note d=this + guess c using assms(3)[rule_format,OF d[THEN conjunct1],of i] .. note c=this + have *:"norm (- ((1 / \c\) *\<^sub>R f' (c *\<^sub>R basis i)) + (1 / \c\) *\<^sub>R f'' (c *\<^sub>R basis i)) = norm ((1 / abs c) *\<^sub>R (- (f' (c *\<^sub>R basis i)) + f'' (c *\<^sub>R basis i)))" + unfolding scaleR_right_distrib by auto + also have "\ = norm ((1 / abs c) *\<^sub>R (c *\<^sub>R (- (f' (basis i)) + f'' (basis i))))" + unfolding f'.scaleR f''.scaleR unfolding scaleR_right_distrib scaleR_minus_right by auto + also have "\ = e" unfolding e_def norm_mul using c[THEN conjunct1] using norm_minus_cancel[of "f' (basis i) - f'' (basis i)"] by(auto simp add:group_simps) + finally show False using c using d[THEN conjunct2,rule_format,of "x + c *\<^sub>R basis i"] using norm_basis[of i] unfolding vector_dist_norm + unfolding f'.scaleR f''.scaleR f'.add f''.add f'.diff f''.diff scaleR_scaleR scaleR_right_diff_distrib scaleR_right_distrib by auto qed qed + +lemma frechet_derivative_unique_at: fixes f::"real^'a::finite \ real^'b::finite" + shows "(f has_derivative f') (at x) \ (f has_derivative f'') (at x) \ f' = f''" + apply(rule frechet_derivative_unique_within[of f f' x UNIV f'']) unfolding within_UNIV apply(assumption)+ + apply(rule,rule,rule) apply(rule_tac x="e/2" in exI) by auto + +lemma "isCont f x = continuous (at x) f" unfolding isCont_def LIM_def + unfolding continuous_at Lim_at unfolding dist_nz by auto + +lemma frechet_derivative_unique_within_closed_interval: fixes f::"real^'a::finite \ real^'b::finite" + assumes "\i. a$i < b$i" "x \ {a..b}" (is "x\?I") and + "(f has_derivative f' ) (at x within {a..b})" and + "(f has_derivative f'') (at x within {a..b})" + shows "f' = f''" apply(rule frechet_derivative_unique_within) apply(rule assms(3,4))+ proof(rule,rule,rule) + fix e::real and i::'a assume "e>0" + thus "\d. 0 < \d\ \ \d\ < e \ x + d *\<^sub>R basis i \ {a..b}" proof(cases "x$i=a$i") + case True thus ?thesis apply(rule_tac x="(min (b$i - a$i) e) / 2" in exI) + using assms(1)[THEN spec[where x=i]] and `e>0` and assms(2) + unfolding mem_interval by(auto simp add:field_simps) next + note * = assms(2)[unfolded mem_interval,THEN spec[where x=i]] + case False moreover have "a $ i < x $ i" using False * by auto + moreover { have "a $ i * 2 + min (x $ i - a $ i) e \ a$i *2 + x$i - a$i" by auto + also have "\ = a$i + x$i" by auto also have "\ \ 2 * x$i" using * by auto + finally have "a $ i * 2 + min (x $ i - a $ i) e \ x $ i * 2" by auto } + moreover have "min (x $ i - a $ i) e \ 0" using * and `e>0` by auto + hence "x $ i * 2 \ b $ i * 2 + min (x $ i - a $ i) e" using * by auto + ultimately show ?thesis apply(rule_tac x="- (min (x$i - a$i) e) / 2" in exI) + using assms(1)[THEN spec[where x=i]] and `e>0` and assms(2) + unfolding mem_interval by(auto simp add:field_simps) qed qed + +lemma frechet_derivative_unique_within_open_interval: fixes f::"real^'a::finite \ real^'b::finite" + assumes "x \ {a<..0" + note * = assms(1)[unfolded mem_interval,THEN spec[where x=i]] + have "a $ i < x $ i" using * by auto + moreover { have "a $ i * 2 + min (x $ i - a $ i) e \ a$i *2 + x$i - a$i" by auto + also have "\ = a$i + x$i" by auto also have "\ < 2 * x$i" using * by auto + finally have "a $ i * 2 + min (x $ i - a $ i) e < x $ i * 2" by auto } + moreover have "min (x $ i - a $ i) e \ 0" using * and `e>0` by auto + hence "x $ i * 2 < b $ i * 2 + min (x $ i - a $ i) e" using * by auto + ultimately show "\d. 0 < \d\ \ \d\ < e \ x + d *\<^sub>R basis i \ {a<..0` and assms(1) unfolding mem_interval by(auto simp add:field_simps) qed + +lemma frechet_derivative_at: fixes f::"real^'a::finite \ real^'b::finite" + shows "(f has_derivative f') (at x) \ (f' = frechet_derivative f (at x))" + apply(rule frechet_derivative_unique_at[of f],assumption) + unfolding frechet_derivative_works[THEN sym] using differentiable_def by auto + +lemma frechet_derivative_within_closed_interval: fixes f::"real^'a::finite \ real^'b::finite" + assumes "\i. a$i < b$i" "x \ {a..b}" "(f has_derivative f') (at x within {a.. b})" + shows "frechet_derivative f (at x within {a.. b}) = f'" + apply(rule frechet_derivative_unique_within_closed_interval[where f=f]) + apply(rule assms(1,2))+ unfolding frechet_derivative_works[THEN sym] + unfolding differentiable_def using assms(3) by auto + +subsection {* Component of the differential must be zero if it exists at a local *) +(* maximum or minimum for that corresponding component. *} + +lemma differential_zero_maxmin_component: fixes f::"real^'a::finite \ real^'b::finite" + assumes "0 < e" "((\y \ ball x e. (f y)$k \ (f x)$k) \ (\y\ball x e. (f x)$k \ (f y)$k))" + "f differentiable (at x)" shows "jacobian f (at x) $ k = 0" proof(rule ccontr) + def D \ "jacobian f (at x)" assume "jacobian f (at x) $ k \ 0" + then obtain j where j:"D$k$j \ 0" unfolding Cart_eq D_def by auto + hence *:"abs (jacobian f (at x) $ k $ j) / 2 > 0" unfolding D_def by auto + note as = assms(3)[unfolded jacobian_works has_derivative_at_alt] + guess e' using as[THEN conjunct2,rule_format,OF *] .. note e' = this + guess d using real_lbound_gt_zero[OF assms(1) e'[THEN conjunct1]] .. note d = this + { fix c assume "abs c \ d" + hence *:"norm (x + c *\<^sub>R basis j - x) < e'" using norm_basis[of j] d by auto + have "\(f (x + c *\<^sub>R basis j) - f x - D *v (c *\<^sub>R basis j)) $ k\ \ norm (f (x + c *\<^sub>R basis j) - f x - D *v (c *\<^sub>R basis j))" by(rule component_le_norm) + also have "\ \ \D $ k $ j\ / 2 * \c\" using e'[THEN conjunct2,rule_format,OF *] and norm_basis[of j] unfolding D_def[symmetric] by auto + finally have "\(f (x + c *\<^sub>R basis j) - f x - D *v (c *\<^sub>R basis j)) $ k\ \ \D $ k $ j\ / 2 * \c\" by simp + hence "\f (x + c *\<^sub>R basis j) $ k - f x $ k - c * D $ k $ j\ \ \D $ k $ j\ / 2 * \c\" + unfolding vector_component_simps matrix_vector_mul_component unfolding smult_conv_scaleR[symmetric] + unfolding dot_rmult dot_basis unfolding smult_conv_scaleR by simp } note * = this + have "x + d *\<^sub>R basis j \ ball x e" "x - d *\<^sub>R basis j \ ball x e" + unfolding mem_ball vector_dist_norm using norm_basis[of j] d by auto + hence **:"((f (x - d *\<^sub>R basis j))$k \ (f x)$k \ (f (x + d *\<^sub>R basis j))$k \ (f x)$k) \ + ((f (x - d *\<^sub>R basis j))$k \ (f x)$k \ (f (x + d *\<^sub>R basis j))$k \ (f x)$k)" using assms(2) by auto + have ***:"\y y1 y2 d dx::real. (y1\y\y2\y) \ (y\y1\y\y2) \ d < abs dx \ abs(y1 - y - - dx) \ d \ (abs (y2 - y - dx) \ d) \ False" by arith + show False apply(rule ***[OF **, where dx="d * D $ k $ j" and d="\D $ k $ j\ / 2 * \d\"]) + using *[of "-d"] and *[of d] and d[THEN conjunct1] and j unfolding mult_minus_left + unfolding abs_mult diff_minus_eq_add scaleR.minus_left unfolding group_simps by auto qed + +subsection {* In particular if we have a mapping into R^1. *} + +lemma differential_zero_maxmin: fixes f::"real^'a::finite \ real" + assumes "x \ s" "open s" "(f has_derivative f') (at x)" + "(\y\s. f y \ f x) \ (\y\s. f x \ f y)" + shows "f' = (\v. 0)" proof- + note deriv = assms(3)[unfolded has_derivative_at_vec1] + obtain e where e:"e>0" "ball x e \ s" using assms(2)[unfolded open_contains_ball] and assms(1) by auto + hence **:"(jacobian (vec1 \ f) (at x)) $ 1 = 0" using differential_zero_maxmin_component[of e x "\x. vec1 (f x)" 1] + unfolding dest_vec1_def[THEN sym] vec1_dest_vec1 using assms(4) and assms(3)[unfolded has_derivative_at_vec1 o_def] + unfolding differentiable_def o_def by auto + have *:"jacobian (vec1 \ f) (at x) = matrix (vec1 \ f')" unfolding jacobian_def and frechet_derivative_at[OF deriv] .. + have "vec1 \ f' = (\x. 0)" apply(rule) unfolding matrix_works[OF derivative_is_linear[OF deriv],THEN sym] + unfolding Cart_eq matrix_vector_mul_component using **[unfolded *] by auto + thus ?thesis apply-apply(rule,subst vec1_eq[THEN sym]) unfolding o_def apply(drule fun_cong) by auto qed + +subsection {* The traditional Rolle theorem in one dimension. *} + +lemma vec1_le[simp]:fixes a::real shows "vec1 a \ vec1 b \ a \ b" + unfolding vector_less_eq_def by auto +lemma vec1_less[simp]:fixes a::real shows "vec1 a < vec1 b \ a < b" + unfolding vector_less_def by auto + +lemma rolle: fixes f::"real\real" + assumes "a < b" "f a = f b" "continuous_on {a..b} f" + "\x\{a<..x\{a<..v. 0)" proof- + have "\x\{a<..y\{a<.. f y) \ (\y\{a<.. f x))" proof- + have "(a + b) / 2 \ {a .. b}" using assms(1) by auto hence *:"{a .. b}\{}" by auto + guess d using continuous_attains_sup[OF compact_real_interval * assms(3)] .. note d=this + guess c using continuous_attains_inf[OF compact_real_interval * assms(3)] .. note c=this + show ?thesis proof(cases "d\{a<.. c\{a<.. "(a + b) /2" + case False hence "f d = f c" using d c assms(2) by auto + hence "\x. x\{a..b} \ f x = f d" using c d apply- apply(erule_tac x=x in ballE)+ by auto + thus ?thesis apply(rule_tac x=e in bexI) unfolding e_def using assms(1) by auto qed qed + then guess x .. note x=this + hence "f' x \ dest_vec1 = (\v. 0)" apply(rule_tac differential_zero_maxmin[of "vec1 x" "vec1 ` {a<.. dest_vec1" "(f' x) \ dest_vec1"]) + unfolding vec1_interval defer apply(rule open_interval) + apply(rule assms(4)[unfolded has_derivative_at_dest_vec1[THEN sym],THEN bspec[where x=x]],assumption) + unfolding o_def apply(erule disjE,rule disjI2) by(auto simp add: vector_less_def dest_vec1_def) + thus ?thesis apply(rule_tac x=x in bexI) unfolding o_def apply rule + apply(drule_tac x="vec1 v" in fun_cong) unfolding vec1_dest_vec1 using x(1) by auto qed + +subsection {* One-dimensional mean value theorem. *} + +lemma mvt: fixes f::"real \ real" + assumes "a < b" "continuous_on {a .. b} f" "\x\{a<..x\{a<..x\{a<..xa. f' x xa - (f b - f a) / (b - a) * xa) = (\v. 0)" + apply(rule rolle[OF assms(1), of "\x. f x - (f b - f a) / (b - a) * x"]) defer + apply(rule continuous_on_intros assms(2) continuous_on_cmul[where 'b=real, unfolded real_scaleR_def])+ proof + fix x assume x:"x \ {a<..x. f x - (f b - f a) / (b - a) * x) has_derivative (\xa. f' x xa - (f b - f a) / (b - a) * xa)) (at x)" + by(rule has_derivative_intros assms(3)[rule_format,OF x] + has_derivative_cmul[where 'b=real, unfolded real_scaleR_def])+ + qed(insert assms(1), auto simp add:field_simps) + then guess x .. thus ?thesis apply(rule_tac x=x in bexI) apply(drule fun_cong[of _ _ "b - a"]) by auto qed + +lemma mvt_simple: fixes f::"real \ real" + assumes "ax\{a..b}. (f has_derivative f' x) (at x within {a..b})" + shows "\x\{a<.. {a<.. real" + assumes "a \ b" "\x\{a..b}. (f has_derivative f'(x)) (at x within {a..b})" + shows "\x\{a..b}. f b - f a = f' x (b - a)" proof(cases "a = b") + interpret bounded_linear "f' b" using assms(2) assms(1) by auto + case True thus ?thesis apply(rule_tac x=a in bexI) + using assms(2)[THEN bspec[where x=a]] unfolding has_derivative_def + unfolding True using zero by auto next + case False thus ?thesis using mvt_simple[OF _ assms(2)] using assms(1) by auto qed + +subsection {* A nice generalization (see Havin's proof of 5.19 from Rudin's book). *} + +lemma inner_eq_dot: fixes a::"real^'n::finite" + shows "a \ b = inner a b" unfolding inner_vector_def dot_def by auto + +lemma mvt_general: fixes f::"real\real^'n::finite" + assumes "ax\{a<..x\{a<.. norm(f'(x) (b - a))" proof- + have "\x\{a<.. (f b - f a) \ f) b - (op \ (f b - f a) \ f) a = (f b - f a) \ f' x (b - a)" + apply(rule mvt) apply(rule assms(1))unfolding inner_eq_dot apply(rule continuous_on_inner continuous_on_intros assms(2))+ + unfolding o_def apply(rule,rule has_derivative_lift_dot) using assms(3) by auto + then guess x .. note x=this + show ?thesis proof(cases "f a = f b") + case False have "norm (f b - f a) * norm (f b - f a) = norm (f b - f a)^2" by(simp add:class_semiring.semiring_rules) + also have "\ = (f b - f a) \ (f b - f a)" unfolding norm_pow_2 .. + also have "\ = (f b - f a) \ f' x (b - a)" using x by auto + also have "\ \ norm (f b - f a) * norm (f' x (b - a))" by(rule norm_cauchy_schwarz) + finally show ?thesis using False x(1) by(auto simp add: real_mult_left_cancel) next + case True thus ?thesis using assms(1) apply(rule_tac x="(a + b) /2" in bexI) by auto qed qed + +subsection {* Still more general bound theorem. *} + +lemma differentiable_bound: fixes f::"real^'a::finite \ real^'b::finite" + assumes "convex s" "\x\s. (f has_derivative f'(x)) (at x within s)" "\x\s. onorm(f' x) \ B" and x:"x\s" and y:"y\s" + shows "norm(f x - f y) \ B * norm(x - y)" proof- + let ?p = "\u. x + u *\<^sub>R (y - x)" + have *:"\u. u\{0..1} \ x + u *\<^sub>R (y - x) \ s" + using assms(1)[unfolded convex_alt,rule_format,OF x y] unfolding scaleR_left_diff_distrib scaleR_right_diff_distrib by(auto simp add:group_simps) + hence 1:"continuous_on {0..1} (f \ ?p)" apply- apply(rule continuous_on_intros continuous_on_vmul)+ + unfolding continuous_on_eq_continuous_within apply(rule,rule differentiable_imp_continuous_within) + unfolding differentiable_def apply(rule_tac x="f' xa" in exI) + apply(rule has_derivative_within_subset) apply(rule assms(2)[rule_format]) by auto + have 2:"\u\{0<..<1}. ((f \ ?p) has_derivative f' (x + u *\<^sub>R (y - x)) \ (\u. 0 + u *\<^sub>R (y - x))) (at u)" proof rule case goal1 + let ?u = "x + u *\<^sub>R (y - x)" + have "(f \ ?p has_derivative (f' ?u) \ (\u. 0 + u *\<^sub>R (y - x))) (at u within {0<..<1})" + apply(rule diff_chain_within) apply(rule has_derivative_intros)+ + apply(rule has_derivative_within_subset) apply(rule assms(2)[rule_format]) using goal1 * by auto + thus ?case unfolding has_derivative_within_open[OF goal1 open_interval_real] by auto qed + guess u using mvt_general[OF zero_less_one 1 2] .. note u = this + have **:"\x y. x\s \ norm (f' x y) \ B * norm y" proof- case goal1 + have "norm (f' x y) \ onorm (f' x) * norm y" + using onorm(1)[OF derivative_is_linear[OF assms(2)[rule_format,OF goal1]]] by assumption + also have "\ \ B * norm y" apply(rule mult_right_mono) + using assms(3)[rule_format,OF goal1] by(auto simp add:field_simps) + finally show ?case by simp qed + have "norm (f x - f y) = norm ((f \ (\u. x + u *\<^sub>R (y - x))) 1 - (f \ (\u. x + u *\<^sub>R (y - x))) 0)" + by(auto simp add:norm_minus_commute) + also have "\ \ norm (f' (x + u *\<^sub>R (y - x)) (y - x))" using u by auto + also have "\ \ B * norm(y - x)" apply(rule **) using * and u by auto + finally show ?thesis by(auto simp add:norm_minus_commute) qed + +lemma onorm_vec1: fixes f::"real \ real" + shows "onorm (\x. vec1 (f (dest_vec1 x))) = onorm f" proof- + have "\x::real^1. norm x = 1 \ x\{vec1 -1, vec1 (1::real)}" unfolding forall_vec1 unfolding norm_vec1 by auto + hence 1:"{x. norm x = 1} = {vec1 -1, vec1 (1::real)}" by(auto simp add:norm_vec1) + have 2:"{norm (vec1 (f (dest_vec1 x))) |x. norm x = 1} = (\x. norm (vec1 (f (dest_vec1 x)))) ` {x. norm x=1}" by auto + + have "\x::real. norm x = 1 \ x\{-1, 1}" by auto hence 3:"{x. norm x = 1} = {-1, (1::real)}" by auto + have 4:"{norm (f x) |x. norm x = 1} = (\x. norm (f x)) ` {x. norm x=1}" by auto + show ?thesis unfolding onorm_def 1 2 3 4 by(simp add:Sup_finite_Max norm_vec1) qed + +lemma differentiable_bound_real: fixes f::"real \ real" + assumes "convex s" "\x\s. (f has_derivative f' x) (at x within s)" "\x\s. onorm(f' x) \ B" and x:"x\s" and y:"y\s" + shows "norm(f x - f y) \ B * norm(x - y)" + using differentiable_bound[of "vec1 ` s" "vec1 \ f \ dest_vec1" "\x. vec1 \ (f' (dest_vec1 x)) \ dest_vec1" B "vec1 x" "vec1 y"] + unfolding Ball_def forall_vec1 unfolding has_derivative_within_vec1_dest_vec1 image_iff + unfolding convex_vec1 unfolding o_def vec1_dest_vec1_simps onorm_vec1 using assms by auto + +subsection {* In particular. *} + +lemma has_derivative_zero_constant: fixes f::"real\real" + assumes "convex s" "\x\s. (f has_derivative (\h. 0)) (at x within s)" + shows "\c. \x\s. f x = c" proof(cases "s={}") + case False then obtain x where "x\s" by auto + have "\y. y\s \ f x = f y" proof- case goal1 + thus ?case using differentiable_bound_real[OF assms(1-2), of 0 x y] and `x\s` + unfolding onorm_vec1[of "\x. 0", THEN sym] onorm_const norm_vec1 by auto qed + thus ?thesis apply(rule_tac x="f x" in exI) by auto qed auto + +lemma has_derivative_zero_unique: fixes f::"real\real" + assumes "convex s" "a \ s" "f a = c" "\x\s. (f has_derivative (\h. 0)) (at x within s)" "x\s" + shows "f x = c" using has_derivative_zero_constant[OF assms(1,4)] using assms(2-3,5) by auto + +subsection {* Differentiability of inverse function (most basic form). *} + +lemma has_derivative_inverse_basic: fixes f::"real^'b::finite \ real^'c::finite" + assumes "(f has_derivative f') (at (g y))" "bounded_linear g'" "g' \ f' = id" "continuous (at y) g" + "open t" "y \ t" "\z\t. f(g z) = z" + shows "(g has_derivative g') (at y)" proof- + interpret f': bounded_linear f' using assms unfolding has_derivative_def by auto + interpret g': bounded_linear g' using assms by auto + guess C using bounded_linear.pos_bounded[OF assms(2)] .. note C = this +(* have fgid:"\x. g' (f' x) = x" using assms(3) unfolding o_def id_def apply()*) + have lem1:"\e>0. \d>0. \z. norm(z - y) < d \ norm(g z - g y - g'(z - y)) \ e * norm(g z - g y)" proof(rule,rule) case goal1 + have *:"e / C > 0" apply(rule divide_pos_pos) using `e>0` C by auto + guess d0 using assms(1)[unfolded has_derivative_at_alt,THEN conjunct2,rule_format,OF *] .. note d0=this + guess d1 using assms(4)[unfolded continuous_at Lim_at,rule_format,OF d0[THEN conjunct1]] .. note d1=this + guess d2 using assms(5)[unfolded open_dist,rule_format,OF assms(6)] .. note d2=this + guess d using real_lbound_gt_zero[OF d1[THEN conjunct1] d2[THEN conjunct1]] .. note d=this + thus ?case apply(rule_tac x=d in exI) apply rule defer proof(rule,rule) + fix z assume as:"norm (z - y) < d" hence "z\t" using d2 d unfolding vector_dist_norm by auto + have "norm (g z - g y - g' (z - y)) \ norm (g' (f (g z) - y - f' (g z - g y)))" + unfolding g'.diff f'.diff unfolding assms(3)[unfolded o_def id_def, THEN fun_cong] + unfolding assms(7)[rule_format,OF `z\t`] apply(subst norm_minus_cancel[THEN sym]) by auto + also have "\ \ norm(f (g z) - y - f' (g z - g y)) * C" by(rule C[THEN conjunct2,rule_format]) + also have "\ \ (e / C) * norm (g z - g y) * C" apply(rule mult_right_mono) + apply(rule d0[THEN conjunct2,rule_format,unfolded assms(7)[rule_format,OF `y\t`]]) apply(cases "z=y") defer + apply(rule d1[THEN conjunct2, unfolded vector_dist_norm,rule_format]) using as d C d0 by auto + also have "\ \ e * norm (g z - g y)" using C by(auto simp add:field_simps) + finally show "norm (g z - g y - g' (z - y)) \ e * norm (g z - g y)" by simp qed auto qed + have *:"(0::real) < 1 / 2" by auto guess d using lem1[rule_format,OF *] .. note d=this def B\"C*2" + have "B>0" unfolding B_def using C by auto + have lem2:"\z. norm(z - y) < d \ norm(g z - g y) \ B * norm(z - y)" proof(rule,rule) case goal1 + have "norm (g z - g y) \ norm(g' (z - y)) + norm ((g z - g y) - g'(z - y))" by(rule norm_triangle_sub) + also have "\ \ norm(g' (z - y)) + 1 / 2 * norm (g z - g y)" apply(rule add_left_mono) using d and goal1 by auto + also have "\ \ norm (z - y) * C + 1 / 2 * norm (g z - g y)" apply(rule add_right_mono) using C by auto + finally show ?case unfolding B_def by(auto simp add:field_simps) qed + show ?thesis unfolding has_derivative_at_alt proof(rule,rule assms,rule,rule) case goal1 + hence *:"e/B >0" apply-apply(rule divide_pos_pos) using `B>0` by auto + guess d' using lem1[rule_format,OF *] .. note d'=this + guess k using real_lbound_gt_zero[OF d[THEN conjunct1] d'[THEN conjunct1]] .. note k=this + show ?case apply(rule_tac x=k in exI,rule) defer proof(rule,rule) fix z assume as:"norm(z - y) < k" + hence "norm (g z - g y - g' (z - y)) \ e / B * norm(g z - g y)" using d' k by auto + also have "\ \ e * norm(z - y)" unfolding mult_frac_num pos_divide_le_eq[OF `B>0`] + using lem2[THEN spec[where x=z]] using k as using `e>0` by(auto simp add:field_simps) + finally show "norm (g z - g y - g' (z - y)) \ e * norm (z - y)" by simp qed(insert k, auto) qed qed + +subsection {* Simply rewrite that based on the domain point x. *} + +lemma has_derivative_inverse_basic_x: fixes f::"real^'b::finite \ real^'c::finite" + assumes "(f has_derivative f') (at x)" "bounded_linear g'" "g' o f' = id" + "continuous (at (f x)) g" "g(f x) = x" "open t" "f x \ t" "\y\t. f(g y) = y" + shows "(g has_derivative g') (at (f(x)))" + apply(rule has_derivative_inverse_basic) using assms by auto + +subsection {* This is the version in Dieudonne', assuming continuity of f and g. *} + +lemma has_derivative_inverse_dieudonne: fixes f::"real^'a::finite \ real^'b::finite" + assumes "open s" "open (f ` s)" "continuous_on s f" "continuous_on (f ` s) g" "\x\s. g(f x) = x" + (**) "x\s" "(f has_derivative f') (at x)" "bounded_linear g'" "g' o f' = id" + shows "(g has_derivative g') (at (f x))" + apply(rule has_derivative_inverse_basic_x[OF assms(7-9) _ _ assms(2)]) + using assms(3-6) unfolding continuous_on_eq_continuous_at[OF assms(1)] continuous_on_eq_continuous_at[OF assms(2)] by auto + +subsection {* Here's the simplest way of not assuming much about g. *} + +lemma has_derivative_inverse: fixes f::"real^'a::finite \ real^'b::finite" + assumes "compact s" "x \ s" "f x \ interior(f ` s)" "continuous_on s f" + "\y\s. g(f y) = y" "(f has_derivative f') (at x)" "bounded_linear g'" "g' \ f' = id" + shows "(g has_derivative g') (at (f x))" proof- + { fix y assume "y\interior (f ` s)" + then obtain x where "x\s" and *:"y = f x" unfolding image_iff using interior_subset by auto + have "f (g y) = y" unfolding * and assms(5)[rule_format,OF `x\s`] .. } note * = this + show ?thesis apply(rule has_derivative_inverse_basic_x[OF assms(6-8)]) + apply(rule continuous_on_interior[OF _ assms(3)]) apply(rule continuous_on_inverse[OF assms(4,1)]) + apply(rule assms(2,5) assms(5)[rule_format] open_interior assms(3))+ by(rule, rule *, assumption) qed + +subsection {* Proving surjectivity via Brouwer fixpoint theorem. *} + +lemma brouwer_surjective: fixes f::"real^'n::finite \ real^'n" + assumes "compact t" "convex t" "t \ {}" "continuous_on t f" + "\x\s. \y\t. x + (y - f y) \ t" "x\s" + shows "\y\t. f y = x" proof- + have *:"\x y. f y = x \ x + (y - f y) = y" by(auto simp add:group_simps) + show ?thesis unfolding * apply(rule brouwer[OF assms(1-3), of "\y. x + (y - f y)"]) + apply(rule continuous_on_intros assms)+ using assms(4-6) by auto qed + +lemma brouwer_surjective_cball: fixes f::"real^'n::finite \ real^'n" + assumes "0 < e" "continuous_on (cball a e) f" + "\x\s. \y\cball a e. x + (y - f y) \ cball a e" "x\s" + shows "\y\cball a e. f y = x" apply(rule brouwer_surjective) apply(rule compact_cball convex_cball)+ + unfolding cball_eq_empty using assms by auto + +text {* See Sussmann: "Multidifferential calculus", Theorem 2.1.1 *} + +lemma sussmann_open_mapping: fixes f::"real^'a::finite \ real^'b::finite" + assumes "open s" "continuous_on s f" "x \ s" + "(f has_derivative f') (at x)" "bounded_linear g'" "f' \ g' = id" + (**) "t \ s" "x \ interior t" + shows "f x \ interior (f ` t)" proof- + interpret f':bounded_linear f' using assms unfolding has_derivative_def by auto + interpret g':bounded_linear g' using assms by auto + guess B using bounded_linear.pos_bounded[OF assms(5)] .. note B=this hence *:"1/(2*B)>0" by(auto intro!: divide_pos_pos) + guess e0 using assms(4)[unfolded has_derivative_at_alt,THEN conjunct2,rule_format,OF *] .. note e0=this + guess e1 using assms(8)[unfolded mem_interior_cball] .. note e1=this + have *:"0z\cball (f x) (e/2). \y\cball (f x) e. f (x + g' (y - f x)) = z" + apply(rule,rule brouwer_surjective_cball[where s="cball (f x) (e/2)"]) + prefer 3 apply(rule,rule) proof- + show "continuous_on (cball (f x) e) (\y. f (x + g' (y - f x)))" unfolding g'.diff + apply(rule continuous_on_compose[of _ _ f, unfolded o_def]) + apply(rule continuous_on_intros linear_continuous_on[OF assms(5)])+ + apply(rule continuous_on_subset[OF assms(2)]) apply(rule,unfold image_iff,erule bexE) proof- + fix y z assume as:"y \cball (f x) e" "z = x + (g' y - g' (f x))" + have "dist x z = norm (g' (f x) - g' y)" unfolding as(2) and vector_dist_norm by auto + also have "\ \ norm (f x - y) * B" unfolding g'.diff[THEN sym] using B by auto + also have "\ \ e * B" using as(1)[unfolded mem_cball vector_dist_norm] using B by auto + also have "\ \ e1" using e unfolding less_divide_eq using B by auto + finally have "z\cball x e1" unfolding mem_cball by force + thus "z \ s" using e1 assms(7) by auto qed next + fix y z assume as:"y \ cball (f x) (e / 2)" "z \ cball (f x) e" + have "norm (g' (z - f x)) \ norm (z - f x) * B" using B by auto + also have "\ \ e * B" apply(rule mult_right_mono) using as(2)[unfolded mem_cball vector_dist_norm] and B unfolding norm_minus_commute by auto + also have "\ < e0" using e and B unfolding less_divide_eq by auto + finally have *:"norm (x + g' (z - f x) - x) < e0" by auto + have **:"f x + f' (x + g' (z - f x) - x) = z" using assms(6)[unfolded o_def id_def,THEN cong] by auto + have "norm (f x - (y + (z - f (x + g' (z - f x))))) \ norm (f (x + g' (z - f x)) - z) + norm (f x - y)" + using norm_triangle_ineq[of "f (x + g'(z - f x)) - z" "f x - y"] by(auto simp add:group_simps) + also have "\ \ 1 / (B * 2) * norm (g' (z - f x)) + norm (f x - y)" using e0[THEN conjunct2,rule_format,OF *] unfolding group_simps ** by auto + also have "\ \ 1 / (B * 2) * norm (g' (z - f x)) + e/2" using as(1)[unfolded mem_cball vector_dist_norm] by auto + also have "\ \ 1 / (B * 2) * B * norm (z - f x) + e/2" using * and B by(auto simp add:field_simps) + also have "\ \ 1 / 2 * norm (z - f x) + e/2" by auto + also have "\ \ e/2 + e/2" apply(rule add_right_mono) using as(2)[unfolded mem_cball vector_dist_norm] unfolding norm_minus_commute by auto + finally show "y + (z - f (x + g' (z - f x))) \ cball (f x) e" unfolding mem_cball vector_dist_norm by auto + qed(insert e, auto) note lem = this + show ?thesis unfolding mem_interior apply(rule_tac x="e/2" in exI) + apply(rule,rule divide_pos_pos) prefer 3 proof + fix y assume "y \ ball (f x) (e/2)" hence *:"y\cball (f x) (e/2)" by auto + guess z using lem[rule_format,OF *] .. note z=this + hence "norm (g' (z - f x)) \ norm (z - f x) * B" using B by(auto simp add:field_simps) + also have "\ \ e * B" apply(rule mult_right_mono) using z(1) unfolding mem_cball vector_dist_norm norm_minus_commute using B by auto + also have "\ \ e1" using e B unfolding less_divide_eq by auto + finally have "x + g'(z - f x) \ t" apply- apply(rule e1[THEN conjunct2,unfolded subset_eq,rule_format]) + unfolding mem_cball vector_dist_norm by auto + thus "y \ f ` t" using z by auto qed(insert e, auto) qed + +text {* Hence the following eccentric variant of the inverse function theorem. *) +(* This has no continuity assumptions, but we do need the inverse function. *) +(* We could put f' o g = I but this happens to fit with the minimal linear *) +(* algebra theory I've set up so far. *} + +lemma has_derivative_inverse_strong: fixes f::"real^'n::finite \ real^'n" + assumes "open s" "x \ s" "continuous_on s f" + "\x\s. g(f x) = x" "(f has_derivative f') (at x)" "f' o g' = id" + shows "(g has_derivative g') (at (f x))" proof- + have linf:"bounded_linear f'" using assms(5) unfolding has_derivative_def by auto + hence ling:"bounded_linear g'" unfolding linear_conv_bounded_linear[THEN sym] + apply- apply(rule right_inverse_linear) using assms(6) by auto + moreover have "g' \ f' = id" using assms(6) linf ling unfolding linear_conv_bounded_linear[THEN sym] + using linear_inverse_left by auto + moreover have *:"\t\s. x\interior t \ f x \ interior (f ` t)" apply(rule,rule,rule,rule sussmann_open_mapping ) + apply(rule assms ling)+ by auto + have "continuous (at (f x)) g" unfolding continuous_at Lim_at proof(rule,rule) + fix e::real assume "e>0" + hence "f x \ interior (f ` (ball x e \ s))" using *[rule_format,of "ball x e \ s"] `x\s` + by(auto simp add: interior_open[OF open_ball] interior_open[OF assms(1)]) + then guess d unfolding mem_interior .. note d=this + show "\d>0. \y. 0 < dist y (f x) \ dist y (f x) < d \ dist (g y) (g (f x)) < e" + apply(rule_tac x=d in exI) apply(rule,rule d[THEN conjunct1]) proof(rule,rule) case goal1 + hence "g y \ g ` f ` (ball x e \ s)" using d[THEN conjunct2,unfolded subset_eq,THEN bspec[where x=y]] + by(auto simp add:dist_commute) + hence "g y \ ball x e \ s" using assms(4) by auto + thus "dist (g y) (g (f x)) < e" using assms(4)[rule_format,OF `x\s`] by(auto simp add:dist_commute) qed qed + moreover have "f x \ interior (f ` s)" apply(rule sussmann_open_mapping) + apply(rule assms ling)+ using interior_open[OF assms(1)] and `x\s` by auto + moreover have "\y. y \ interior (f ` s) \ f (g y) = y" proof- case goal1 + hence "y\f ` s" using interior_subset by auto then guess z unfolding image_iff .. + thus ?case using assms(4) by auto qed + ultimately show ?thesis apply- apply(rule has_derivative_inverse_basic_x[OF assms(5)]) using assms by auto qed + +subsection {* A rewrite based on the other domain. *} + +lemma has_derivative_inverse_strong_x: fixes f::"real^'n::finite \ real^'n" + assumes "open s" "g y \ s" "continuous_on s f" + "\x\s. g(f x) = x" "(f has_derivative f') (at (g y))" "f' o g' = id" "f(g y) = y" + shows "(g has_derivative g') (at y)" + using has_derivative_inverse_strong[OF assms(1-6)] unfolding assms(7) by simp + +subsection {* On a region. *} + +lemma has_derivative_inverse_on: fixes f::"real^'n::finite \ real^'n" + assumes "open s" "\x\s. (f has_derivative f'(x)) (at x)" "\x\s. g(f x) = x" "f'(x) o g'(x) = id" "x\s" + shows "(g has_derivative g'(x)) (at (f x))" + apply(rule has_derivative_inverse_strong[where g'="g' x" and f=f]) apply(rule assms)+ + unfolding continuous_on_eq_continuous_at[OF assms(1)] + apply(rule,rule differentiable_imp_continuous_at) unfolding differentiable_def using assms by auto + +subsection {* Invertible derivative continous at a point implies local injectivity. *) +(* It's only for this we need continuity of the derivative, except of course *) +(* if we want the fact that the inverse derivative is also continuous. So if *) +(* we know for some other reason that the inverse function exists, it's OK. *} + +lemma bounded_linear_sub: "bounded_linear f \ bounded_linear g ==> bounded_linear (\x. f x - g x)" + using bounded_linear_add[of f "\x. - g x"] bounded_linear_minus[of g] by(auto simp add:group_simps) + +lemma has_derivative_locally_injective: fixes f::"real^'n::finite \ real^'m::finite" + assumes "a \ s" "open s" "bounded_linear g'" "g' o f'(a) = id" + "\x\s. (f has_derivative f'(x)) (at x)" + "\e>0. \d>0. \x. dist a x < d \ onorm(\v. f' x v - f' a v) < e" + obtains t where "a \ t" "open t" "\x\t. \x'\t. (f x' = f x) \ (x' = x)" proof- + interpret bounded_linear g' using assms by auto + note f'g' = assms(4)[unfolded id_def o_def,THEN cong] + have "g' (f' a 1) = 1" using f'g' by auto + hence *:"0 < onorm g'" unfolding onorm_pos_lt[OF assms(3)[unfolded linear_linear]] by fastsimp + def k \ "1 / onorm g' / 2" have *:"k>0" unfolding k_def using * by auto + guess d1 using assms(6)[rule_format,OF *] .. note d1=this + from `open s` obtain d2 where "d2>0" "ball a d2 \ s" using `a\s` .. + obtain d2 where "d2>0" "ball a d2 \ s" using assms(2,1) .. + guess d2 using assms(2)[unfolded open_contains_ball,rule_format,OF `a\s`] .. note d2=this + guess d using real_lbound_gt_zero[OF d1[THEN conjunct1] d2[THEN conjunct1]] .. note d = this + show ?thesis proof show "a\ball a d" using d by auto + show "\x\ball a d. \x'\ball a d. f x' = f x \ x' = x" proof(intro strip) + fix x y assume as:"x\ball a d" "y\ball a d" "f x = f y" + def ph \ "\w. w - g'(f w - f x)" have ph':"ph = g' \ (\w. f' a w - (f w - f x))" + unfolding ph_def o_def unfolding diff using f'g' by(auto simp add:group_simps) + have "norm (ph x - ph y) \ (1/2) * norm (x - y)" + apply(rule differentiable_bound[OF convex_ball _ _ as(1-2), where f'="\x v. v - g'(f' x v)"]) + apply(rule_tac[!] ballI) proof- fix u assume u:"u \ ball a d" hence "u\s" using d d2 by auto + have *:"(\v. v - g' (f' u v)) = g' \ (\w. f' a w - f' u w)" unfolding o_def and diff using f'g' by auto + show "(ph has_derivative (\v. v - g' (f' u v))) (at u within ball a d)" + unfolding ph' * apply(rule diff_chain_within) defer apply(rule bounded_linear.has_derivative[OF assms(3)]) + apply(rule has_derivative_intros) defer apply(rule has_derivative_sub[where g'="\x.0",unfolded diff_0_right]) + apply(rule has_derivative_at_within) using assms(5) and `u\s` `a\s` + by(auto intro!: has_derivative_intros derivative_linear) + have **:"bounded_linear (\x. f' u x - f' a x)" "bounded_linear (\x. f' a x - f' u x)" apply(rule_tac[!] bounded_linear_sub) + apply(rule_tac[!] derivative_linear) using assms(5) `u\s` `a\s` by auto + have "onorm (\v. v - g' (f' u v)) \ onorm g' * onorm (\w. f' a w - f' u w)" unfolding * apply(rule onorm_compose) + unfolding linear_conv_bounded_linear by(rule assms(3) **)+ + also have "\ \ onorm g' * k" apply(rule mult_left_mono) + using d1[THEN conjunct2,rule_format,of u] using onorm_neg[OF **(1)[unfolded linear_linear]] + using d and u and onorm_pos_le[OF assms(3)[unfolded linear_linear]] by(auto simp add:group_simps) + also have "\ \ 1/2" unfolding k_def by auto + finally show "onorm (\v. v - g' (f' u v)) \ 1 / 2" by assumption qed + moreover have "norm (ph y - ph x) = norm (y - x)" apply(rule arg_cong[where f=norm]) + unfolding ph_def using diff unfolding as by auto + ultimately show "x = y" unfolding norm_minus_commute by auto qed qed auto qed + +subsection {* Uniformly convergent sequence of derivatives. *} + +lemma has_derivative_sequence_lipschitz_lemma: fixes f::"nat \ real^'m::finite \ real^'n::finite" + assumes "convex s" "\n. \x\s. ((f n) has_derivative (f' n x)) (at x within s)" + "\n\N. \x\s. \h. norm(f' n x h - g' x h) \ e * norm(h)" + shows "\m\N. \n\N. \x\s. \y\s. norm((f m x - f n x) - (f m y - f n y)) \ 2 * e * norm(x - y)" proof(default)+ + fix m n x y assume as:"N\m" "N\n" "x\s" "y\s" + show "norm((f m x - f n x) - (f m y - f n y)) \ 2 * e * norm(x - y)" + apply(rule differentiable_bound[where f'="\x h. f' m x h - f' n x h", OF assms(1) _ _ as(3-4)]) apply(rule_tac[!] ballI) proof- + fix x assume "x\s" show "((\a. f m a - f n a) has_derivative (\h. f' m x h - f' n x h)) (at x within s)" + by(rule has_derivative_intros assms(2)[rule_format] `x\s`)+ + { fix h have "norm (f' m x h - f' n x h) \ norm (f' m x h - g' x h) + norm (f' n x h - g' x h)" + using norm_triangle_ineq[of "f' m x h - g' x h" "- f' n x h + g' x h"] unfolding norm_minus_commute by(auto simp add:group_simps) + also have "\ \ e * norm h+ e * norm h" using assms(3)[rule_format,OF `N\m` `x\s`, of h] assms(3)[rule_format,OF `N\n` `x\s`, of h] + by(auto simp add:field_simps) + finally have "norm (f' m x h - f' n x h) \ 2 * e * norm h" by auto } + thus "onorm (\h. f' m x h - f' n x h) \ 2 * e" apply-apply(rule onorm(2)) apply(rule linear_compose_sub) + unfolding linear_conv_bounded_linear using assms(2)[rule_format,OF `x\s`, THEN derivative_linear] by auto qed qed + +lemma has_derivative_sequence_lipschitz: fixes f::"nat \ real^'m::finite \ real^'n::finite" + assumes "convex s" "\n. \x\s. ((f n) has_derivative (f' n x)) (at x within s)" + "\e>0. \N. \n\N. \x\s. \h. norm(f' n x h - g' x h) \ e * norm(h)" "0 < e" + shows "\e>0. \N. \m\N. \n\N. \x\s. \y\s. norm((f m x - f n x) - (f m y - f n y)) \ e * norm(x - y)" proof(rule,rule) + case goal1 have *:"2 * (1/2* e) = e" "1/2 * e >0" using `e>0` by auto + guess N using assms(3)[rule_format,OF *(2)] .. + thus ?case apply(rule_tac x=N in exI) apply(rule has_derivative_sequence_lipschitz_lemma[where e="1/2 *e", unfolded *]) using assms by auto qed + +lemma has_derivative_sequence: fixes f::"nat\real^'m::finite\real^'n::finite" + assumes "convex s" "\n. \x\s. ((f n) has_derivative (f' n x)) (at x within s)" + "\e>0. \N. \n\N. \x\s. \h. norm(f' n x h - g' x h) \ e * norm(h)" + "x0 \ s" "((\n. f n x0) ---> l) sequentially" + shows "\g. \x\s. ((\n. f n x) ---> g x) sequentially \ (g has_derivative g'(x)) (at x within s)" proof- + have lem1:"\e>0. \N. \m\N. \n\N. \x\s. \y\s. norm((f m x - f n x) - (f m y - f n y)) \ e * norm(x - y)" + apply(rule has_derivative_sequence_lipschitz[where e="42::nat"]) apply(rule assms)+ by auto + have "\g. \x\s. ((\n. f n x) ---> g x) sequentially" apply(rule bchoice) unfolding convergent_eq_cauchy proof + fix x assume "x\s" show "Cauchy (\n. f n x)" proof(cases "x=x0") + case True thus ?thesis using convergent_imp_cauchy[OF assms(5)] by auto next + case False show ?thesis unfolding Cauchy_def proof(rule,rule) + fix e::real assume "e>0" hence *:"e/2>0" "e/2/norm(x-x0)>0" using False by(auto intro!:divide_pos_pos) + guess M using convergent_imp_cauchy[OF assms(5), unfolded Cauchy_def, rule_format,OF *(1)] .. note M=this + guess N using lem1[rule_format,OF *(2)] .. note N = this + show " \M. \m\M. \n\M. dist (f m x) (f n x) < e" apply(rule_tac x="max M N" in exI) proof(default+) + fix m n assume as:"max M N \m" "max M N\n" + have "dist (f m x) (f n x) \ norm (f m x0 - f n x0) + norm (f m x - f n x - (f m x0 - f n x0))" + unfolding vector_dist_norm by(rule norm_triangle_sub) + also have "\ \ norm (f m x0 - f n x0) + e / 2" using N[rule_format,OF _ _ `x\s` `x0\s`, of m n] and as and False by auto + also have "\ < e / 2 + e / 2" apply(rule add_strict_right_mono) using as and M[rule_format] unfolding vector_dist_norm by auto + finally show "dist (f m x) (f n x) < e" by auto qed qed qed qed + then guess g .. note g = this + have lem2:"\e>0. \N. \n\N. \x\s. \y\s. norm((f n x - f n y) - (g x - g y)) \ e * norm(x - y)" proof(rule,rule) + fix e::real assume *:"e>0" guess N using lem1[rule_format,OF *] .. note N=this + show "\N. \n\N. \x\s. \y\s. norm (f n x - f n y - (g x - g y)) \ e * norm (x - y)" apply(rule_tac x=N in exI) proof(default+) + fix n x y assume as:"N \ n" "x \ s" "y \ s" + have "eventually (\xa. norm (f n x - f n y - (f xa x - f xa y)) \ e * norm (x - y)) sequentially" + unfolding eventually_sequentially apply(rule_tac x=N in exI) proof(rule,rule) + fix m assume "N\m" thus "norm (f n x - f n y - (f m x - f m y)) \ e * norm (x - y)" + using N[rule_format, of n m x y] and as by(auto simp add:group_simps) qed + thus "norm (f n x - f n y - (g x - g y)) \ e * norm (x - y)" apply- + apply(rule Lim_norm_ubound[OF trivial_limit_sequentially, where f="\m. (f n x - f n y) - (f m x - f m y)"]) + apply(rule Lim_sub Lim_const g[rule_format] as)+ by assumption qed qed + show ?thesis unfolding has_derivative_within_alt apply(rule_tac x=g in exI) + apply(rule,rule,rule g[rule_format],assumption) proof fix x assume "x\s" + have lem3:"\u. ((\n. f' n x u) ---> g' x u) sequentially" unfolding Lim_sequentially proof(rule,rule,rule) + fix u and e::real assume "e>0" show "\N. \n\N. dist (f' n x u) (g' x u) < e" proof(cases "u=0") + case True guess N using assms(3)[rule_format,OF `e>0`] .. note N=this + show ?thesis apply(rule_tac x=N in exI) unfolding True + using N[rule_format,OF _ `x\s`,of _ 0] and `e>0` by auto next + case False hence *:"e / 2 / norm u > 0" using `e>0` by(auto intro!: divide_pos_pos) + guess N using assms(3)[rule_format,OF *] .. note N=this + show ?thesis apply(rule_tac x=N in exI) proof(rule,rule) case goal1 + show ?case unfolding vector_dist_norm using N[rule_format,OF goal1 `x\s`, of u] False `e>0` + by (auto simp add:field_simps) qed qed qed + show "bounded_linear (g' x)" unfolding linear_linear linear_def apply(rule,rule,rule) defer proof(rule,rule) + fix x' y z::"real^'m" and c::real + note lin = assms(2)[rule_format,OF `x\s`,THEN derivative_linear] + show "g' x (c *s x') = c *s g' x x'" apply(rule Lim_unique[OF trivial_limit_sequentially]) + apply(rule lem3[rule_format]) unfolding smult_conv_scaleR + unfolding lin[unfolded bounded_linear_def bounded_linear_axioms_def,THEN conjunct2,THEN conjunct1,rule_format] + apply(rule Lim_cmul) by(rule lem3[rule_format]) + show "g' x (y + z) = g' x y + g' x z" apply(rule Lim_unique[OF trivial_limit_sequentially]) + apply(rule lem3[rule_format]) unfolding lin[unfolded bounded_linear_def additive_def,THEN conjunct1,rule_format] + apply(rule Lim_add) by(rule lem3[rule_format])+ qed + show "\e>0. \d>0. \y\s. norm (y - x) < d \ norm (g y - g x - g' x (y - x)) \ e * norm (y - x)" proof(rule,rule) case goal1 + have *:"e/3>0" using goal1 by auto guess N1 using assms(3)[rule_format,OF *] .. note N1=this + guess N2 using lem2[rule_format,OF *] .. note N2=this + guess d1 using assms(2)[unfolded has_derivative_within_alt, rule_format,OF `x\s`, of "max N1 N2",THEN conjunct2,rule_format,OF *] .. note d1=this + show ?case apply(rule_tac x=d1 in exI) apply(rule,rule d1[THEN conjunct1]) proof(rule,rule) + fix y assume as:"y \ s" "norm (y - x) < d1" let ?N ="max N1 N2" + have "norm (g y - g x - (f ?N y - f ?N x)) \ e /3 * norm (y - x)" apply(subst norm_minus_cancel[THEN sym]) + using N2[rule_format, OF _ `y\s` `x\s`, of ?N] by auto moreover + have "norm (f ?N y - f ?N x - f' ?N x (y - x)) \ e / 3 * norm (y - x)" using d1 and as by auto ultimately + have "norm (g y - g x - f' ?N x (y - x)) \ 2 * e / 3 * norm (y - x)" + using norm_triangle_le[of "g y - g x - (f ?N y - f ?N x)" "f ?N y - f ?N x - f' ?N x (y - x)" "2 * e / 3 * norm (y - x)"] + by (auto simp add:group_simps) moreover + have " norm (f' ?N x (y - x) - g' x (y - x)) \ e / 3 * norm (y - x)" using N1 `x\s` by auto + ultimately show "norm (g y - g x - g' x (y - x)) \ e * norm (y - x)" + using norm_triangle_le[of "g y - g x - f' (max N1 N2) x (y - x)" "f' (max N1 N2) x (y - x) - g' x (y - x)"] by(auto simp add:group_simps) + qed qed qed qed + +subsection {* Can choose to line up antiderivatives if we want. *} + +lemma has_antiderivative_sequence: fixes f::"nat\ real^'m::finite \ real^'n::finite" + assumes "convex s" "\n. \x\s. ((f n) has_derivative (f' n x)) (at x within s)" + "\e>0. \N. \n\N. \x\s. \h. norm(f' n x h - g' x h) \ e * norm h" + shows "\g. \x\s. (g has_derivative g'(x)) (at x within s)" proof(cases "s={}") + case False then obtain a where "a\s" by auto have *:"\P Q. \g. \x\s. P g x \ Q g x \ \g. \x\s. Q g x" by auto + show ?thesis apply(rule *) apply(rule has_derivative_sequence[OF assms(1) _ assms(3), of "\n x. f n x + (f 0 a - f n a)"]) + apply(rule,rule) apply(rule has_derivative_add_const, rule assms(2)[rule_format], assumption) + apply(rule `a\s`) by(auto intro!: Lim_const) qed auto + +lemma has_antiderivative_limit: fixes g'::"real^'m::finite \ real^'m::finite \ real^'n::finite" + assumes "convex s" "\e>0. \f f'. \x\s. (f has_derivative (f' x)) (at x within s) \ (\h. norm(f' x h - g' x h) \ e * norm(h))" + shows "\g. \x\s. (g has_derivative g'(x)) (at x within s)" proof- + have *:"\n. \f f'. \x\s. (f has_derivative (f' x)) (at x within s) \ (\h. norm(f' x h - g' x h) \ inverse (real (Suc n)) * norm(h))" + apply(rule) using assms(2) apply(erule_tac x="inverse (real (Suc n))" in allE) by auto + guess f using *[THEN choice] .. note * = this guess f' using *[THEN choice] .. note f=this + show ?thesis apply(rule has_antiderivative_sequence[OF assms(1), of f f']) defer proof(rule,rule) + fix e::real assume "00`] .. note N=this + show "\N. \n\N. \x\s. \h. norm (f' n x h - g' x h) \ e * norm h" apply(rule_tac x=N in exI) proof(default+) case goal1 + have *:"inverse (real (Suc n)) \ e" apply(rule order_trans[OF _ N[THEN less_imp_le]]) + using goal1(1) by(auto simp add:field_simps) + show ?case using f[rule_format,THEN conjunct2,OF goal1(2), of n, THEN spec[where x=h]] + apply(rule order_trans) using N * apply(cases "h=0") by auto qed qed(insert f,auto) qed + +subsection {* Differentiation of a series. *} + +definition sums_seq :: "(nat \ 'a::real_normed_vector) \ 'a \ (nat set) \ bool" +(infixl "sums'_seq" 12) where "(f sums_seq l) s \ ((\n. setsum f (s \ {0..n})) ---> l) sequentially" + +lemma has_derivative_series: fixes f::"nat \ real^'m::finite \ real^'n::finite" + assumes "convex s" "\n. \x\s. ((f n) has_derivative (f' n x)) (at x within s)" + "\e>0. \N. \n\N. \x\s. \h. norm(setsum (\i. f' i x h) (k \ {0..n}) - g' x h) \ e * norm(h)" + "x\s" "((\n. f n x) sums_seq l) k" + shows "\g. \x\s. ((\n. f n x) sums_seq (g x)) k \ (g has_derivative g'(x)) (at x within s)" + unfolding sums_seq_def apply(rule has_derivative_sequence[OF assms(1) _ assms(3)]) apply(rule,rule) + apply(rule has_derivative_setsum) defer apply(rule,rule assms(2)[rule_format],assumption) + using assms(4-5) unfolding sums_seq_def by auto + +subsection {* Derivative with composed bilinear function. *} + +lemma has_derivative_bilinear_within: fixes h::"real^'m::finite \ real^'n::finite \ real^'p::finite" and f::"real^'q::finite \ real^'m" + assumes "(f has_derivative f') (at x within s)" "(g has_derivative g') (at x within s)" "bounded_bilinear h" + shows "((\x. h (f x) (g x)) has_derivative (\d. h (f x) (g' d) + h (f' d) (g x))) (at x within s)" proof- + have "(g ---> g x) (at x within s)" apply(rule differentiable_imp_continuous_within[unfolded continuous_within]) + using assms(2) unfolding differentiable_def by auto moreover + interpret f':bounded_linear f' using assms unfolding has_derivative_def by auto + interpret g':bounded_linear g' using assms unfolding has_derivative_def by auto + interpret h:bounded_bilinear h using assms by auto + have "((\y. f' (y - x)) ---> 0) (at x within s)" unfolding f'.zero[THEN sym] + apply(rule Lim_linear[of "\y. y - x" 0 "at x within s" f']) using Lim_sub[OF Lim_within_id Lim_const, of x x s] + unfolding id_def using assms(1) unfolding has_derivative_def by auto + hence "((\y. f x + f' (y - x)) ---> f x) (at x within s)" + using Lim_add[OF Lim_const, of "\y. f' (y - x)" 0 "at x within s" "f x"] by auto ultimately + have *:"((\x'. h (f x + f' (x' - x)) ((1/(norm (x' - x))) *\<^sub>R (g x' - (g x + g' (x' - x)))) + + h ((1/ (norm (x' - x))) *\<^sub>R (f x' - (f x + f' (x' - x)))) (g x')) ---> h (f x) 0 + h 0 (g x)) (at x within s)" + apply-apply(rule Lim_add) apply(rule_tac[!] Lim_bilinear[OF _ _ assms(3)]) using assms(1-2) unfolding has_derivative_within by auto + guess B using bounded_bilinear.pos_bounded[OF assms(3)] .. note B=this + guess C using f'.pos_bounded .. note C=this + guess D using g'.pos_bounded .. note D=this + have bcd:"B * C * D > 0" using B C D by (auto intro!: mult_pos_pos) + have **:"((\y. (1/(norm(y - x))) *\<^sub>R (h (f'(y - x)) (g'(y - x)))) ---> 0) (at x within s)" unfolding Lim_within proof(rule,rule) case goal1 + hence "e/(B*C*D)>0" using B C D by(auto intro!:divide_pos_pos mult_pos_pos) + thus ?case apply(rule_tac x="e/(B*C*D)" in exI,rule) proof(rule,rule,erule conjE) + fix y assume as:"y \ s" "0 < dist y x" "dist y x < e / (B * C * D)" + have "norm (h (f' (y - x)) (g' (y - x))) \ norm (f' (y - x)) * norm (g' (y - x)) * B" using B by auto + also have "\ \ (norm (y - x) * C) * (D * norm (y - x)) * B" apply(rule mult_right_mono) + apply(rule pordered_semiring_class.mult_mono) using B C D by (auto simp add: field_simps intro!:mult_nonneg_nonneg) + also have "\ = (B * C * D * norm (y - x)) * norm (y - x)" by(auto simp add:field_simps) + also have "\ < e * norm (y - x)" apply(rule mult_strict_right_mono) + using as(3)[unfolded vector_dist_norm] and as(2) unfolding pos_less_divide_eq[OF bcd] by (auto simp add:field_simps) + finally show "dist ((1 / norm (y - x)) *\<^sub>R h (f' (y - x)) (g' (y - x))) 0 < e" + unfolding vector_dist_norm apply-apply(cases "y = x") by(auto simp add:field_simps) qed qed + have "bounded_linear (\d. h (f x) (g' d) + h (f' d) (g x))" unfolding linear_linear linear_def + unfolding smult_conv_scaleR unfolding g'.add f'.scaleR f'.add g'.scaleR + unfolding h.add_right h.add_left scaleR_right_distrib h.scaleR_left h.scaleR_right by auto + thus ?thesis using Lim_add[OF * **] unfolding has_derivative_within + unfolding smult_conv_scaleR unfolding g'.add f'.scaleR f'.add g'.scaleR f'.diff g'.diff + h.add_right h.add_left scaleR_right_distrib h.scaleR_left h.scaleR_right h.diff_right h.diff_left + scaleR_right_diff_distrib h.zero_right h.zero_left by(auto simp add:field_simps) qed + +lemma has_derivative_bilinear_at: fixes h::"real^'m::finite \ real^'n::finite \ real^'p::finite" and f::"real^'p::finite \ real^'m" + assumes "(f has_derivative f') (at x)" "(g has_derivative g') (at x)" "bounded_bilinear h" + shows "((\x. h (f x) (g x)) has_derivative (\d. h (f x) (g' d) + h (f' d) (g x))) (at x)" + using has_derivative_bilinear_within[of f f' x UNIV g g' h] unfolding within_UNIV using assms by auto + +subsection {* Considering derivative R(^1)->R^n as a vector. *} + +definition has_vector_derivative :: "(real \ 'b::real_normed_vector) \ ('b) \ (real net \ bool)" +(infixl "has'_vector'_derivative" 12) where + "(f has_vector_derivative f') net \ (f has_derivative (\x. x *\<^sub>R f')) net" + +definition "vector_derivative f net \ (SOME f'. (f has_vector_derivative f') net)" + +lemma vector_derivative_works: fixes f::"real \ 'a::real_normed_vector" + shows "f differentiable net \ (f has_vector_derivative (vector_derivative f net)) net" (is "?l = ?r") +proof assume ?l guess f' using `?l`[unfolded differentiable_def] .. note f' = this + then interpret bounded_linear f' by auto + thus ?r unfolding vector_derivative_def has_vector_derivative_def + apply-apply(rule someI_ex,rule_tac x="f' 1" in exI) + using f' unfolding scaleR[THEN sym] by auto +next assume ?r thus ?l unfolding vector_derivative_def has_vector_derivative_def differentiable_def by auto qed + +lemma vector_derivative_unique_at: fixes f::"real\real^'n::finite" + assumes "(f has_vector_derivative f') (at x)" "(f has_vector_derivative f'') (at x)" shows "f' = f''" proof- + have *:"(\x. x *\<^sub>R f') \ dest_vec1 = (\x. x *\<^sub>R f'') \ dest_vec1" apply(rule frechet_derivative_unique_at) + using assms[unfolded has_vector_derivative_def] unfolding has_derivative_at_dest_vec1[THEN sym] by auto + show ?thesis proof(rule ccontr) assume "f' \ f''" moreover + hence "((\x. x *\<^sub>R f') \ dest_vec1) (vec1 1) = ((\x. x *\<^sub>R f'') \ dest_vec1) (vec1 1)" using * by auto + ultimately show False unfolding o_def vec1_dest_vec1 by auto qed qed + +lemma vector_derivative_unique_within_closed_interval: fixes f::"real \ real^'n::finite" + assumes "a < b" "x \ {a..b}" + "(f has_vector_derivative f') (at x within {a..b})" + "(f has_vector_derivative f'') (at x within {a..b})" shows "f' = f''" proof- + have *:"(\x. x *\<^sub>R f') \ dest_vec1 = (\x. x *\<^sub>R f'') \ dest_vec1" + apply(rule frechet_derivative_unique_within_closed_interval[of "vec1 a" "vec1 b"]) + using assms(3-)[unfolded has_vector_derivative_def] + unfolding has_derivative_within_dest_vec1[THEN sym] vec1_interval using assms(1-2) by auto + show ?thesis proof(rule ccontr) assume "f' \ f''" moreover + hence "((\x. x *\<^sub>R f') \ dest_vec1) (vec1 1) = ((\x. x *\<^sub>R f'') \ dest_vec1) (vec1 1)" using * by auto + ultimately show False unfolding o_def vec1_dest_vec1 by auto qed qed + +lemma vector_derivative_at: fixes f::"real \ real^'a::finite" shows + "(f has_vector_derivative f') (at x) \ vector_derivative f (at x) = f'" + apply(rule vector_derivative_unique_at) defer apply assumption + unfolding vector_derivative_works[THEN sym] differentiable_def + unfolding has_vector_derivative_def by auto + +lemma vector_derivative_within_closed_interval: fixes f::"real \ real^'a::finite" + assumes "a < b" "x \ {a..b}" "(f has_vector_derivative f') (at x within {a..b})" + shows "vector_derivative f (at x within {a..b}) = f'" + apply(rule vector_derivative_unique_within_closed_interval) + using vector_derivative_works[unfolded differentiable_def] + using assms by(auto simp add:has_vector_derivative_def) + +lemma has_vector_derivative_within_subset: fixes f::"real \ real^'a::finite" shows + "(f has_vector_derivative f') (at x within s) \ t \ s \ (f has_vector_derivative f') (at x within t)" + unfolding has_vector_derivative_def apply(rule has_derivative_within_subset) by auto + +lemma has_vector_derivative_const: fixes c::"real^'n::finite" shows + "((\x. c) has_vector_derivative 0) net" + unfolding has_vector_derivative_def using has_derivative_const by auto + +lemma has_vector_derivative_id: "((\x::real. x) has_vector_derivative 1) net" + unfolding has_vector_derivative_def using has_derivative_id by auto + +lemma has_vector_derivative_cmul: fixes f::"real \ real^'a::finite" + shows "(f has_vector_derivative f') net \ ((\x. c *\<^sub>R f x) has_vector_derivative (c *\<^sub>R f')) net" + unfolding has_vector_derivative_def apply(drule has_derivative_cmul) by(auto simp add:group_simps) + +lemma has_vector_derivative_cmul_eq: fixes f::"real \ real^'a::finite" assumes "c \ 0" + shows "(((\x. c *\<^sub>R f x) has_vector_derivative (c *\<^sub>R f')) net \ (f has_vector_derivative f') net)" + apply rule apply(drule has_vector_derivative_cmul[where c="1/c"]) defer + apply(rule has_vector_derivative_cmul) using assms by auto + +lemma has_vector_derivative_neg: + "(f has_vector_derivative f') net \ ((\x. -(f x)) has_vector_derivative (- f')) net" + unfolding has_vector_derivative_def apply(drule has_derivative_neg) by auto + +lemma has_vector_derivative_add: + assumes "(f has_vector_derivative f') net" "(g has_vector_derivative g') net" + shows "((\x. f(x) + g(x)) has_vector_derivative (f' + g')) net" + using has_derivative_add[OF assms[unfolded has_vector_derivative_def]] + unfolding has_vector_derivative_def unfolding scaleR_right_distrib by auto + +lemma has_vector_derivative_sub: + assumes "(f has_vector_derivative f') net" "(g has_vector_derivative g') net" + shows "((\x. f(x) - g(x)) has_vector_derivative (f' - g')) net" + using has_derivative_sub[OF assms[unfolded has_vector_derivative_def]] + unfolding has_vector_derivative_def scaleR_right_diff_distrib by auto + +lemma has_vector_derivative_bilinear_within: fixes h::"real^'m::finite \ real^'n::finite \ real^'p::finite" + assumes "(f has_vector_derivative f') (at x within s)" "(g has_vector_derivative g') (at x within s)" "bounded_bilinear h" + shows "((\x. h (f x) (g x)) has_vector_derivative (h (f x) g' + h f' (g x))) (at x within s)" proof- + interpret bounded_bilinear h using assms by auto + show ?thesis using has_derivative_bilinear_within[OF assms(1-2)[unfolded has_vector_derivative_def has_derivative_within_dest_vec1[THEN sym]], where h=h] + unfolding o_def vec1_dest_vec1 has_vector_derivative_def + unfolding has_derivative_within_dest_vec1[unfolded o_def, where f="\x. h (f x) (g x)" and f'="\d. h (f x) (d *\<^sub>R g') + h (d *\<^sub>R f') (g x)"] + using assms(3) unfolding scaleR_right scaleR_left scaleR_right_distrib by auto qed + +lemma has_vector_derivative_bilinear_at: fixes h::"real^'m::finite \ real^'n::finite \ real^'p::finite" + assumes "(f has_vector_derivative f') (at x)" "(g has_vector_derivative g') (at x)" "bounded_bilinear h" + shows "((\x. h (f x) (g x)) has_vector_derivative (h (f x) g' + h f' (g x))) (at x)" + apply(rule has_vector_derivative_bilinear_within[where s=UNIV, unfolded within_UNIV]) using assms by auto + +lemma has_vector_derivative_at_within: "(f has_vector_derivative f') (at x) \ (f has_vector_derivative f') (at x within s)" + unfolding has_vector_derivative_def apply(rule has_derivative_at_within) by auto + +lemma has_vector_derivative_transform_within: + assumes "0 < d" "x \ s" "\x'\s. dist x' x < d \ f x' = g x'" "(f has_vector_derivative f') (at x within s)" + shows "(g has_vector_derivative f') (at x within s)" + using assms unfolding has_vector_derivative_def by(rule has_derivative_transform_within) + +lemma has_vector_derivative_transform_at: + assumes "0 < d" "\x'. dist x' x < d \ f x' = g x'" "(f has_vector_derivative f') (at x)" + shows "(g has_vector_derivative f') (at x)" + using assms unfolding has_vector_derivative_def by(rule has_derivative_transform_at) + +lemma has_vector_derivative_transform_within_open: + assumes "open s" "x \ s" "\y\s. f y = g y" "(f has_vector_derivative f') (at x)" + shows "(g has_vector_derivative f') (at x)" + using assms unfolding has_vector_derivative_def by(rule has_derivative_transform_within_open) + +lemma vector_diff_chain_at: + assumes "(f has_vector_derivative f') (at x)" "(g has_vector_derivative g') (at (f x))" + shows "((g \ f) has_vector_derivative (f' *\<^sub>R g')) (at x)" + using assms(2) unfolding has_vector_derivative_def apply- apply(drule diff_chain_at[OF assms(1)[unfolded has_vector_derivative_def]]) + unfolding o_def scaleR.scaleR_left by auto + +lemma vector_diff_chain_within: + assumes "(f has_vector_derivative f') (at x within s)" "(g has_vector_derivative g') (at (f x) within f ` s)" + shows "((g o f) has_vector_derivative (f' *\<^sub>R g')) (at x within s)" + using assms(2) unfolding has_vector_derivative_def apply- apply(drule diff_chain_within[OF assms(1)[unfolded has_vector_derivative_def]]) + unfolding o_def scaleR.scaleR_left by auto + +end + diff -r 5fd36780760b -r 4c414d0835ab src/HOL/Multivariate_Analysis/Multivariate_Analysis.thy --- a/src/HOL/Multivariate_Analysis/Multivariate_Analysis.thy Tue Nov 17 18:25:05 2009 +0100 +++ b/src/HOL/Multivariate_Analysis/Multivariate_Analysis.thy Tue Nov 17 18:52:30 2009 +0100 @@ -1,5 +1,5 @@ theory Multivariate_Analysis -imports Convex_Euclidean_Space Determinants +imports Determinants Derivative begin end