# HG changeset patch # User krauss # Date 1226507002 -3600 # Node ID bed31381e6b62fab4dfb6d07179068edd0953dda # Parent 19277c7a160c32144f9c342f9922da8384ea3d24 min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf diff -r 19277c7a160c -r bed31381e6b6 src/HOL/Wellfounded.thy --- a/src/HOL/Wellfounded.thy Mon Nov 10 19:42:22 2008 +0100 +++ b/src/HOL/Wellfounded.thy Wed Nov 12 17:23:22 2008 +0100 @@ -769,6 +769,114 @@ lemma in_finite_psubset[simp]: "(A, B) \ finite_psubset = (A < B & finite B)" unfolding finite_psubset_def by auto +text {* max- and min-extension of order to finite sets *} + +inductive_set max_ext :: "('a \ 'a) set \ ('a set \ 'a set) set" +for R :: "('a \ 'a) set" +where + max_extI[intro]: "finite X \ finite Y \ Y \ {} \ (\x. x \ X \ \y\Y. (x, y) \ R) \ (X, Y) \ max_ext R" + +lemma max_ext_wf: + assumes wf: "wf r" + shows "wf (max_ext r)" +proof (rule acc_wfI, intro allI) + fix M show "M \ acc (max_ext r)" (is "_ \ ?W") + proof cases + assume "finite M" + thus ?thesis + proof (induct M) + show "{} \ ?W" + by (rule accI) (auto elim: max_ext.cases) + next + fix M a assume "M \ ?W" "finite M" + with wf show "insert a M \ ?W" + proof (induct arbitrary: M) + fix M a + assume "M \ ?W" and [intro]: "finite M" + assume hyp: "\b M. (b, a) \ r \ M \ ?W \ finite M \ insert b M \ ?W" + { + fix N M :: "'a set" + assume "finite N" "finite M" + then + have "\M \ ?W ; (\y. y \ N \ (y, a) \ r)\ \ N \ M \ ?W" + by (induct N arbitrary: M) (auto simp: hyp) + } + note add_less = this + + show "insert a M \ ?W" + proof (rule accI) + fix N assume Nless: "(N, insert a M) \ max_ext r" + hence asm1: "\x. x \ N \ (x, a) \ r \ (\y \ M. (x, y) \ r)" + by (auto elim!: max_ext.cases) + + let ?N1 = "{ n \ N. (n, a) \ r }" + let ?N2 = "{ n \ N. (n, a) \ r }" + have N: "?N1 \ ?N2 = N" by (rule set_ext) auto + from Nless have "finite N" by (auto elim: max_ext.cases) + then have finites: "finite ?N1" "finite ?N2" by auto + + have "?N2 \ ?W" + proof cases + assume [simp]: "M = {}" + have Mw: "{} \ ?W" by (rule accI) (auto elim: max_ext.cases) + + from asm1 have "?N2 = {}" by auto + with Mw show "?N2 \ ?W" by (simp only:) + next + assume "M \ {}" + have N2: "(?N2, M) \ max_ext r" + by (rule max_extI[OF _ _ `M \ {}`]) (insert asm1, auto intro: finites) + + with `M \ ?W` show "?N2 \ ?W" by (rule acc_downward) + qed + with finites have "?N1 \ ?N2 \ ?W" + by (rule add_less) simp + then show "N \ ?W" by (simp only: N) + qed + qed + qed + next + assume [simp]: "\ finite M" + show ?thesis + by (rule accI) (auto elim: max_ext.cases) + qed +qed + + +definition + min_ext :: "('a \ 'a) set \ ('a set \ 'a set) set" +where + [code del]: "min_ext r = {(X, Y) | X Y. X \ {} \ (\y \ Y. (\x \ X. (x, y) \ r))}" + +lemma min_ext_wf: + assumes "wf r" + shows "wf (min_ext r)" +proof (rule wfI_min) + fix Q :: "'a set set" + fix x + assume nonempty: "x \ Q" + show "\m \ Q. (\ n. (n, m) \ min_ext r \ n \ Q)" + proof cases + assume "Q = {{}}" thus ?thesis by (simp add: min_ext_def) + next + assume "Q \ {{}}" + with nonempty + obtain e x where "x \ Q" "e \ x" by force + then have eU: "e \ \Q" by auto + with `wf r` + obtain z where z: "z \ \Q" "\y. (y, z) \ r \ y \ \Q" + by (erule wfE_min) + from z obtain m where "m \ Q" "z \ m" by auto + from `m \ Q` + show ?thesis + proof (rule, intro bexI allI impI) + fix n + assume smaller: "(n, m) \ min_ext r" + with `z \ m` obtain y where y: "y \ n" "(y, z) \ r" by (auto simp: min_ext_def) + then show "n \ Q" using z(2) by auto + qed + qed +qed text {*Wellfoundedness of @{text same_fst}*} @@ -777,8 +885,7 @@ where "same_fst P R == {((x',y'),(x,y)) . x'=x & P x & (y',y) : R x}" --{*For @{text rec_def} declarations where the first n parameters - stay unchanged in the recursive call. - See @{text "Library/While_Combinator.thy"} for an application.*} + stay unchanged in the recursive call. *} lemma same_fstI [intro!]: "[| P x; (y',y) : R x |] ==> ((x,y'),(x,y)) : same_fst P R"