| author | wenzelm | 
| Mon, 18 Jan 2016 16:03:18 +0100 | |
| changeset 62198 | 7217adc19be9 | 
| parent 61952 | 546958347e05 | 
| child 63088 | f2177f5d2aed | 
| permissions | -rw-r--r-- | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 1 | (* Title: HOL/Wellfounded.thy | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 2 | Author: Tobias Nipkow | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 3 | Author: Lawrence C Paulson | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 4 | Author: Konrad Slind | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 5 | Author: Alexander Krauss | 
| 55027 | 6 | Author: Andrei Popescu, TU Muenchen | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 7 | *) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 8 | |
| 60758 | 9 | section \<open>Well-founded Recursion\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 10 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 11 | theory Wellfounded | 
| 35727 | 12 | imports Transitive_Closure | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 13 | begin | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 14 | |
| 60758 | 15 | subsection \<open>Basic Definitions\<close> | 
| 26976 | 16 | |
| 33217 | 17 | definition wf :: "('a * 'a) set => bool" where
 | 
| 45137 | 18 | "wf r \<longleftrightarrow> (!P. (!x. (!y. (y,x):r --> P(y)) --> P(x)) --> (!x. P(x)))" | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 19 | |
| 33217 | 20 | definition wfP :: "('a => 'a => bool) => bool" where
 | 
| 45137 | 21 |   "wfP r \<longleftrightarrow> wf {(x, y). r x y}"
 | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 22 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 23 | lemma wfP_wf_eq [pred_set_conv]: "wfP (\<lambda>x y. (x, y) \<in> r) = wf r" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 24 | by (simp add: wfP_def) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 25 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 26 | lemma wfUNIVI: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 27 | "(!!P x. (ALL x. (ALL y. (y,x) : r --> P(y)) --> P(x)) ==> P(x)) ==> wf(r)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 28 | unfolding wf_def by blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 29 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 30 | lemmas wfPUNIVI = wfUNIVI [to_pred] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 31 | |
| 60758 | 32 | text\<open>Restriction to domain @{term A} and range @{term B}.  If @{term r} is
 | 
| 33 |     well-founded over their intersection, then @{term "wf r"}\<close>
 | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 34 | lemma wfI: | 
| 61943 | 35 | "[| r \<subseteq> A \<times> B; | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 36 | !!x P. [|\<forall>x. (\<forall>y. (y,x) : r --> P y) --> P x; x : A; x : B |] ==> P x |] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 37 | ==> wf r" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 38 | unfolding wf_def by blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 39 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 40 | lemma wf_induct: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 41 | "[| wf(r); | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 42 | !!x.[| ALL y. (y,x): r --> P(y) |] ==> P(x) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 43 | |] ==> P(a)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 44 | unfolding wf_def by blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 45 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 46 | lemmas wfP_induct = wf_induct [to_pred] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 47 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 48 | lemmas wf_induct_rule = wf_induct [rule_format, consumes 1, case_names less, induct set: wf] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 49 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 50 | lemmas wfP_induct_rule = wf_induct_rule [to_pred, induct set: wfP] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 51 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 52 | lemma wf_not_sym: "wf r ==> (a, x) : r ==> (x, a) ~: r" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 53 | by (induct a arbitrary: x set: wf) blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 54 | |
| 33215 
6fd85372981e
replaced (outdated) comments by explicit statements
 krauss parents: 
32960diff
changeset | 55 | lemma wf_asym: | 
| 
6fd85372981e
replaced (outdated) comments by explicit statements
 krauss parents: 
32960diff
changeset | 56 | assumes "wf r" "(a, x) \<in> r" | 
| 
6fd85372981e
replaced (outdated) comments by explicit statements
 krauss parents: 
32960diff
changeset | 57 | obtains "(x, a) \<notin> r" | 
| 
6fd85372981e
replaced (outdated) comments by explicit statements
 krauss parents: 
32960diff
changeset | 58 | by (drule wf_not_sym[OF assms]) | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 59 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 60 | lemma wf_not_refl [simp]: "wf r ==> (a, a) ~: r" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 61 | by (blast elim: wf_asym) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 62 | |
| 33215 
6fd85372981e
replaced (outdated) comments by explicit statements
 krauss parents: 
32960diff
changeset | 63 | lemma wf_irrefl: assumes "wf r" obtains "(a, a) \<notin> r" | 
| 
6fd85372981e
replaced (outdated) comments by explicit statements
 krauss parents: 
32960diff
changeset | 64 | by (drule wf_not_refl[OF assms]) | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 65 | |
| 27823 | 66 | lemma wf_wellorderI: | 
| 67 |   assumes wf: "wf {(x::'a::ord, y). x < y}"
 | |
| 68 |   assumes lin: "OFCLASS('a::ord, linorder_class)"
 | |
| 69 |   shows "OFCLASS('a::ord, wellorder_class)"
 | |
| 70 | using lin by (rule wellorder_class.intro) | |
| 61424 
c3658c18b7bc
prod_case as canonical name for product type eliminator
 haftmann parents: 
61337diff
changeset | 71 | (rule class.wellorder_axioms.intro, rule wf_induct_rule [OF wf], simp) | 
| 27823 | 72 | |
| 73 | lemma (in wellorder) wf: | |
| 74 |   "wf {(x, y). x < y}"
 | |
| 75 | unfolding wf_def by (blast intro: less_induct) | |
| 76 | ||
| 77 | ||
| 60758 | 78 | subsection \<open>Basic Results\<close> | 
| 26976 | 79 | |
| 60758 | 80 | text \<open>Point-free characterization of well-foundedness\<close> | 
| 33216 | 81 | |
| 82 | lemma wfE_pf: | |
| 83 | assumes wf: "wf R" | |
| 84 | assumes a: "A \<subseteq> R `` A" | |
| 85 |   shows "A = {}"
 | |
| 86 | proof - | |
| 87 |   { fix x
 | |
| 88 | from wf have "x \<notin> A" | |
| 89 | proof induct | |
| 90 | fix x assume "\<And>y. (y, x) \<in> R \<Longrightarrow> y \<notin> A" | |
| 91 | then have "x \<notin> R `` A" by blast | |
| 92 | with a show "x \<notin> A" by blast | |
| 93 | qed | |
| 94 | } thus ?thesis by auto | |
| 95 | qed | |
| 96 | ||
| 97 | lemma wfI_pf: | |
| 98 |   assumes a: "\<And>A. A \<subseteq> R `` A \<Longrightarrow> A = {}"
 | |
| 99 | shows "wf R" | |
| 100 | proof (rule wfUNIVI) | |
| 101 | fix P :: "'a \<Rightarrow> bool" and x | |
| 102 |   let ?A = "{x. \<not> P x}"
 | |
| 103 | assume "\<forall>x. (\<forall>y. (y, x) \<in> R \<longrightarrow> P y) \<longrightarrow> P x" | |
| 104 | then have "?A \<subseteq> R `` ?A" by blast | |
| 105 | with a show "P x" by blast | |
| 106 | qed | |
| 107 | ||
| 60758 | 108 | text\<open>Minimal-element characterization of well-foundedness\<close> | 
| 33216 | 109 | |
| 110 | lemma wfE_min: | |
| 111 | assumes wf: "wf R" and Q: "x \<in> Q" | |
| 112 | obtains z where "z \<in> Q" "\<And>y. (y, z) \<in> R \<Longrightarrow> y \<notin> Q" | |
| 113 | using Q wfE_pf[OF wf, of Q] by blast | |
| 114 | ||
| 115 | lemma wfI_min: | |
| 116 | assumes a: "\<And>x Q. x \<in> Q \<Longrightarrow> \<exists>z\<in>Q. \<forall>y. (y, z) \<in> R \<longrightarrow> y \<notin> Q" | |
| 117 | shows "wf R" | |
| 118 | proof (rule wfI_pf) | |
| 119 | fix A assume b: "A \<subseteq> R `` A" | |
| 120 |   { fix x assume "x \<in> A"
 | |
| 121 | from a[OF this] b have "False" by blast | |
| 122 | } | |
| 123 |   thus "A = {}" by blast
 | |
| 124 | qed | |
| 125 | ||
| 126 | lemma wf_eq_minimal: "wf r = (\<forall>Q x. x\<in>Q --> (\<exists>z\<in>Q. \<forall>y. (y,z)\<in>r --> y\<notin>Q))" | |
| 127 | apply auto | |
| 128 | apply (erule wfE_min, assumption, blast) | |
| 129 | apply (rule wfI_min, auto) | |
| 130 | done | |
| 131 | ||
| 132 | lemmas wfP_eq_minimal = wf_eq_minimal [to_pred] | |
| 133 | ||
| 60758 | 134 | text\<open>Well-foundedness of transitive closure\<close> | 
| 33216 | 135 | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 136 | lemma wf_trancl: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 137 | assumes "wf r" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 138 | shows "wf (r^+)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 139 | proof - | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 140 |   {
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 141 | fix P and x | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 142 | assume induct_step: "!!x. (!!y. (y, x) : r^+ ==> P y) ==> P x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 143 | have "P x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 144 | proof (rule induct_step) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 145 | fix y assume "(y, x) : r^+" | 
| 60758 | 146 | with \<open>wf r\<close> show "P y" | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 147 | proof (induct x arbitrary: y) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 148 | case (less x) | 
| 60758 | 149 | note hyp = \<open>\<And>x' y'. (x', x) : r ==> (y', x') : r^+ ==> P y'\<close> | 
| 150 | from \<open>(y, x) : r^+\<close> show "P y" | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 151 | proof cases | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 152 | case base | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 153 | show "P y" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 154 | proof (rule induct_step) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 155 | fix y' assume "(y', y) : r^+" | 
| 60758 | 156 | with \<open>(y, x) : r\<close> show "P y'" by (rule hyp [of y y']) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 157 | qed | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 158 | next | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 159 | case step | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 160 | then obtain x' where "(x', x) : r" and "(y, x') : r^+" by simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 161 | then show "P y" by (rule hyp [of x' y]) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32704diff
changeset | 162 | qed | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 163 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 164 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 165 | } then show ?thesis unfolding wf_def by blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 166 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 167 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 168 | lemmas wfP_trancl = wf_trancl [to_pred] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 169 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 170 | lemma wf_converse_trancl: "wf (r^-1) ==> wf ((r^+)^-1)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 171 | apply (subst trancl_converse [symmetric]) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 172 | apply (erule wf_trancl) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 173 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 174 | |
| 60758 | 175 | text \<open>Well-foundedness of subsets\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 176 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 177 | lemma wf_subset: "[| wf(r); p<=r |] ==> wf(p)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 178 | apply (simp (no_asm_use) add: wf_eq_minimal) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 179 | apply fast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 180 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 181 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 182 | lemmas wfP_subset = wf_subset [to_pred] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 183 | |
| 60758 | 184 | text \<open>Well-foundedness of the empty relation\<close> | 
| 33216 | 185 | |
| 186 | lemma wf_empty [iff]: "wf {}"
 | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 187 | by (simp add: wf_def) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 188 | |
| 32205 | 189 | lemma wfP_empty [iff]: | 
| 190 | "wfP (\<lambda>x y. False)" | |
| 191 | proof - | |
| 192 | have "wfP bot" by (fact wf_empty [to_pred bot_empty_eq2]) | |
| 44921 | 193 | then show ?thesis by (simp add: bot_fun_def) | 
| 32205 | 194 | qed | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 195 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 196 | lemma wf_Int1: "wf r ==> wf (r Int r')" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 197 | apply (erule wf_subset) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 198 | apply (rule Int_lower1) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 199 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 200 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 201 | lemma wf_Int2: "wf r ==> wf (r' Int r)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 202 | apply (erule wf_subset) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 203 | apply (rule Int_lower2) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 204 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 205 | |
| 60758 | 206 | text \<open>Exponentiation\<close> | 
| 33216 | 207 | |
| 208 | lemma wf_exp: | |
| 209 | assumes "wf (R ^^ n)" | |
| 210 | shows "wf R" | |
| 211 | proof (rule wfI_pf) | |
| 212 | fix A assume "A \<subseteq> R `` A" | |
| 213 | then have "A \<subseteq> (R ^^ n) `` A" by (induct n) force+ | |
| 60758 | 214 | with \<open>wf (R ^^ n)\<close> | 
| 33216 | 215 |   show "A = {}" by (rule wfE_pf)
 | 
| 216 | qed | |
| 217 | ||
| 60758 | 218 | text \<open>Well-foundedness of insert\<close> | 
| 33216 | 219 | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 220 | lemma wf_insert [iff]: "wf(insert (y,x) r) = (wf(r) & (x,y) ~: r^*)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 221 | apply (rule iffI) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 222 | apply (blast elim: wf_trancl [THEN wf_irrefl] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 223 | intro: rtrancl_into_trancl1 wf_subset | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 224 | rtrancl_mono [THEN [2] rev_subsetD]) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 225 | apply (simp add: wf_eq_minimal, safe) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 226 | apply (rule allE, assumption, erule impE, blast) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 227 | apply (erule bexE) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 228 | apply (rename_tac "a", case_tac "a = x") | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 229 | prefer 2 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 230 | apply blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 231 | apply (case_tac "y:Q") | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 232 | prefer 2 apply blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 233 | apply (rule_tac x = "{z. z:Q & (z,y) : r^*}" in allE)
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 234 | apply assumption | 
| 59807 | 235 | apply (erule_tac V = "ALL Q. (EX x. x : Q) --> P Q" for P in thin_rl) | 
| 61799 | 236 | \<comment>\<open>essential for speed\<close> | 
| 60758 | 237 | txt\<open>Blast with new substOccur fails\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 238 | apply (fast intro: converse_rtrancl_into_rtrancl) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 239 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 240 | |
| 60758 | 241 | text\<open>Well-foundedness of image\<close> | 
| 33216 | 242 | |
| 55932 | 243 | lemma wf_map_prod_image: "[| wf r; inj f |] ==> wf (map_prod f f ` r)" | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 244 | apply (simp only: wf_eq_minimal, clarify) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 245 | apply (case_tac "EX p. f p : Q") | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 246 | apply (erule_tac x = "{p. f p : Q}" in allE)
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 247 | apply (fast dest: inj_onD, blast) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 248 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 249 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 250 | |
| 60758 | 251 | subsection \<open>Well-Foundedness Results for Unions\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 252 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 253 | lemma wf_union_compatible: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 254 | assumes "wf R" "wf S" | 
| 32235 
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
 krauss parents: 
32205diff
changeset | 255 | assumes "R O S \<subseteq> R" | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 256 | shows "wf (R \<union> S)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 257 | proof (rule wfI_min) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 258 | fix x :: 'a and Q | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 259 |   let ?Q' = "{x \<in> Q. \<forall>y. (y, x) \<in> R \<longrightarrow> y \<notin> Q}"
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 260 | assume "x \<in> Q" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 261 | obtain a where "a \<in> ?Q'" | 
| 60758 | 262 | by (rule wfE_min [OF \<open>wf R\<close> \<open>x \<in> Q\<close>]) blast | 
| 263 | with \<open>wf S\<close> | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 264 | obtain z where "z \<in> ?Q'" and zmin: "\<And>y. (y, z) \<in> S \<Longrightarrow> y \<notin> ?Q'" by (erule wfE_min) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 265 |   { 
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 266 | fix y assume "(y, z) \<in> S" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 267 | then have "y \<notin> ?Q'" by (rule zmin) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 268 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 269 | have "y \<notin> Q" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 270 | proof | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 271 | assume "y \<in> Q" | 
| 60758 | 272 | with \<open>y \<notin> ?Q'\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 273 | obtain w where "(w, y) \<in> R" and "w \<in> Q" by auto | 
| 60758 | 274 | from \<open>(w, y) \<in> R\<close> \<open>(y, z) \<in> S\<close> have "(w, z) \<in> R O S" by (rule relcompI) | 
| 275 | with \<open>R O S \<subseteq> R\<close> have "(w, z) \<in> R" .. | |
| 276 | with \<open>z \<in> ?Q'\<close> have "w \<notin> Q" by blast | |
| 277 | with \<open>w \<in> Q\<close> show False by contradiction | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 278 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 279 | } | 
| 60758 | 280 | with \<open>z \<in> ?Q'\<close> show "\<exists>z\<in>Q. \<forall>y. (y, z) \<in> R \<union> S \<longrightarrow> y \<notin> Q" by blast | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 281 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 282 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 283 | |
| 60758 | 284 | text \<open>Well-foundedness of indexed union with disjoint domains and ranges\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 285 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 286 | lemma wf_UN: "[| ALL i:I. wf(r i); | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 287 |          ALL i:I. ALL j:I. r i ~= r j --> Domain(r i) Int Range(r j) = {}  
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 288 | |] ==> wf(UN i:I. r i)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 289 | apply (simp only: wf_eq_minimal, clarify) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 290 | apply (rename_tac A a, case_tac "EX i:I. EX a:A. EX b:A. (b,a) : r i") | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 291 | prefer 2 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 292 | apply force | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 293 | apply clarify | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 294 | apply (drule bspec, assumption) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 295 | apply (erule_tac x="{a. a:A & (EX b:A. (b,a) : r i) }" in allE)
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 296 | apply (blast elim!: allE) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 297 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 298 | |
| 32263 | 299 | lemma wfP_SUP: | 
| 56218 
1c3f1f2431f9
elongated INFI and SUPR, to reduced risk of confusing theorems names in the future while still being consistent with INTER and UNION
 haftmann parents: 
56166diff
changeset | 300 | "\<forall>i. wfP (r i) \<Longrightarrow> \<forall>i j. r i \<noteq> r j \<longrightarrow> inf (DomainP (r i)) (RangeP (r j)) = bot \<Longrightarrow> wfP (SUPREMUM UNIV r)" | 
| 46883 
eec472dae593
tuned pred_set_conv lemmas. Skipped lemmas changing the lemmas generated by inductive_set
 noschinl parents: 
46882diff
changeset | 301 | apply (rule wf_UN[to_pred]) | 
| 46882 | 302 | apply simp_all | 
| 45970 
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
 haftmann parents: 
45139diff
changeset | 303 | done | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 304 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 305 | lemma wf_Union: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 306 | "[| ALL r:R. wf r; | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 307 |      ALL r:R. ALL s:R. r ~= s --> Domain r Int Range s = {}  
 | 
| 61952 | 308 | |] ==> wf (\<Union> R)" | 
| 56166 | 309 | using wf_UN[of R "\<lambda>i. i"] by simp | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 310 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 311 | (*Intuition: we find an (R u S)-min element of a nonempty subset A | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 312 | by case distinction. | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 313 | 1. There is a step a -R-> b with a,b : A. | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 314 |      Pick an R-min element z of the (nonempty) set {a:A | EX b:A. a -R-> b}.
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 315 | By definition, there is z':A s.t. z -R-> z'. Because z is R-min in the | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 316 | subset, z' must be R-min in A. Because z' has an R-predecessor, it cannot | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 317 | have an S-successor and is thus S-min in A as well. | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 318 | 2. There is no such step. | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 319 | Pick an S-min element of A. In this case it must be an R-min | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 320 | element of A as well. | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 321 | *) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 322 | lemma wf_Un: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 323 |      "[| wf r; wf s; Domain r Int Range s = {} |] ==> wf(r Un s)"
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 324 | using wf_union_compatible[of s r] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 325 | by (auto simp: Un_ac) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 326 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 327 | lemma wf_union_merge: | 
| 32235 
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
 krauss parents: 
32205diff
changeset | 328 | "wf (R \<union> S) = wf (R O R \<union> S O R \<union> S)" (is "wf ?A = wf ?B") | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 329 | proof | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 330 | assume "wf ?A" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 331 | with wf_trancl have wfT: "wf (?A^+)" . | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 332 | moreover have "?B \<subseteq> ?A^+" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 333 | by (subst trancl_unfold, subst trancl_unfold) blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 334 | ultimately show "wf ?B" by (rule wf_subset) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 335 | next | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 336 | assume "wf ?B" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 337 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 338 | show "wf ?A" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 339 | proof (rule wfI_min) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 340 | fix Q :: "'a set" and x | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 341 | assume "x \<in> Q" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 342 | |
| 60758 | 343 | with \<open>wf ?B\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 344 | obtain z where "z \<in> Q" and "\<And>y. (y, z) \<in> ?B \<Longrightarrow> y \<notin> Q" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 345 | by (erule wfE_min) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 346 | then have A1: "\<And>y. (y, z) \<in> R O R \<Longrightarrow> y \<notin> Q" | 
| 32235 
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
 krauss parents: 
32205diff
changeset | 347 | and A2: "\<And>y. (y, z) \<in> S O R \<Longrightarrow> y \<notin> Q" | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 348 | and A3: "\<And>y. (y, z) \<in> S \<Longrightarrow> y \<notin> Q" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 349 | by auto | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 350 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 351 | show "\<exists>z\<in>Q. \<forall>y. (y, z) \<in> ?A \<longrightarrow> y \<notin> Q" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 352 | proof (cases "\<forall>y. (y, z) \<in> R \<longrightarrow> y \<notin> Q") | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 353 | case True | 
| 60758 | 354 | with \<open>z \<in> Q\<close> A3 show ?thesis by blast | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 355 | next | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 356 | case False | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 357 | then obtain z' where "z'\<in>Q" "(z', z) \<in> R" by blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 358 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 359 | have "\<forall>y. (y, z') \<in> ?A \<longrightarrow> y \<notin> Q" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 360 | proof (intro allI impI) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 361 | fix y assume "(y, z') \<in> ?A" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 362 | then show "y \<notin> Q" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 363 | proof | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 364 | assume "(y, z') \<in> R" | 
| 60758 | 365 | then have "(y, z) \<in> R O R" using \<open>(z', z) \<in> R\<close> .. | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 366 | with A1 show "y \<notin> Q" . | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 367 | next | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 368 | assume "(y, z') \<in> S" | 
| 60758 | 369 | then have "(y, z) \<in> S O R" using \<open>(z', z) \<in> R\<close> .. | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 370 | with A2 show "y \<notin> Q" . | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 371 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 372 | qed | 
| 60758 | 373 | with \<open>z' \<in> Q\<close> show ?thesis .. | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 374 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 375 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 376 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 377 | |
| 61799 | 378 | lemma wf_comp_self: "wf R = wf (R O R)" \<comment> \<open>special case\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 379 |   by (rule wf_union_merge [where S = "{}", simplified])
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 380 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 381 | |
| 60758 | 382 | subsection \<open>Well-Foundedness of Composition\<close> | 
| 60148 | 383 | |
| 60493 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 384 | text \<open>Bachmair and Dershowitz 1986, Lemma 2. [Provided by Tjark Weber]\<close> | 
| 60148 | 385 | |
| 60493 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 386 | lemma qc_wf_relto_iff: | 
| 61799 | 387 | assumes "R O S \<subseteq> (R \<union> S)\<^sup>* O R" \<comment> \<open>R quasi-commutes over S\<close> | 
| 60493 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 388 | shows "wf (S\<^sup>* O R O S\<^sup>*) \<longleftrightarrow> wf R" (is "wf ?S \<longleftrightarrow> _") | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 389 | proof | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 390 | assume "wf ?S" | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 391 | moreover have "R \<subseteq> ?S" by auto | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 392 | ultimately show "wf R" using wf_subset by auto | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 393 | next | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 394 | assume "wf R" | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 395 | show "wf ?S" | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 396 | proof (rule wfI_pf) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 397 | fix A assume A: "A \<subseteq> ?S `` A" | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 398 | let ?X = "(R \<union> S)\<^sup>* `` A" | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 399 | have *: "R O (R \<union> S)\<^sup>* \<subseteq> (R \<union> S)\<^sup>* O R" | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 400 | proof - | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 401 |         { fix x y z assume "(y, z) \<in> (R \<union> S)\<^sup>*" and "(x, y) \<in> R"
 | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 402 | then have "(x, z) \<in> (R \<union> S)\<^sup>* O R" | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 403 | proof (induct y z) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 404 | case rtrancl_refl then show ?case by auto | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 405 | next | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 406 | case (rtrancl_into_rtrancl a b c) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 407 | then have "(x, c) \<in> ((R \<union> S)\<^sup>* O (R \<union> S)\<^sup>*) O R" using assms by blast | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 408 | then show ?case by simp | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 409 | qed } | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 410 | then show ?thesis by auto | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 411 | qed | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 412 | then have "R O S\<^sup>* \<subseteq> (R \<union> S)\<^sup>* O R" using rtrancl_Un_subset by blast | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 413 | then have "?S \<subseteq> (R \<union> S)\<^sup>* O (R \<union> S)\<^sup>* O R" by (simp add: relcomp_mono rtrancl_mono) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 414 | also have "\<dots> = (R \<union> S)\<^sup>* O R" by (simp add: O_assoc[symmetric]) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 415 | finally have "?S O (R \<union> S)\<^sup>* \<subseteq> (R \<union> S)\<^sup>* O R O (R \<union> S)\<^sup>*" by (simp add: O_assoc[symmetric] relcomp_mono) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 416 | also have "\<dots> \<subseteq> (R \<union> S)\<^sup>* O (R \<union> S)\<^sup>* O R" using * by (simp add: relcomp_mono) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 417 | finally have "?S O (R \<union> S)\<^sup>* \<subseteq> (R \<union> S)\<^sup>* O R" by (simp add: O_assoc[symmetric]) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 418 | then have "(?S O (R \<union> S)\<^sup>*) `` A \<subseteq> ((R \<union> S)\<^sup>* O R) `` A" by (simp add: Image_mono) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 419 | moreover have "?X \<subseteq> (?S O (R \<union> S)\<^sup>*) `` A" using A by (auto simp: relcomp_Image) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 420 | ultimately have "?X \<subseteq> R `` ?X" by (auto simp: relcomp_Image) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 421 |     then have "?X = {}" using \<open>wf R\<close> by (simp add: wfE_pf)
 | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 422 | moreover have "A \<subseteq> ?X" by auto | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 423 |     ultimately show "A = {}" by simp
 | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 424 | qed | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 425 | qed | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 426 | |
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 427 | corollary wf_relcomp_compatible: | 
| 60148 | 428 | assumes "wf R" and "R O S \<subseteq> S O R" | 
| 429 | shows "wf (S O R)" | |
| 60493 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 430 | proof - | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 431 | have "R O S \<subseteq> (R \<union> S)\<^sup>* O R" | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 432 | using assms by blast | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 433 | then have "wf (S\<^sup>* O R O S\<^sup>*)" | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 434 | by (simp add: assms qc_wf_relto_iff) | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 435 | then show ?thesis | 
| 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 436 | by (rule Wellfounded.wf_subset) blast | 
| 60148 | 437 | qed | 
| 438 | ||
| 439 | ||
| 60758 | 440 | subsection \<open>Acyclic relations\<close> | 
| 33217 | 441 | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 442 | lemma wf_acyclic: "wf r ==> acyclic r" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 443 | apply (simp add: acyclic_def) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 444 | apply (blast elim: wf_trancl [THEN wf_irrefl]) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 445 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 446 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 447 | lemmas wfP_acyclicP = wf_acyclic [to_pred] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 448 | |
| 60758 | 449 | text\<open>Wellfoundedness of finite acyclic relations\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 450 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 451 | lemma finite_acyclic_wf [rule_format]: "finite r ==> acyclic r --> wf r" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 452 | apply (erule finite_induct, blast) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 453 | apply (simp (no_asm_simp) only: split_tupled_all) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 454 | apply simp | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 455 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 456 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 457 | lemma finite_acyclic_wf_converse: "[|finite r; acyclic r|] ==> wf (r^-1)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 458 | apply (erule finite_converse [THEN iffD2, THEN finite_acyclic_wf]) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 459 | apply (erule acyclic_converse [THEN iffD2]) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 460 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 461 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 462 | lemma wf_iff_acyclic_if_finite: "finite r ==> wf r = acyclic r" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 463 | by (blast intro: finite_acyclic_wf wf_acyclic) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 464 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 465 | |
| 60758 | 466 | subsection \<open>@{typ nat} is well-founded\<close>
 | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 467 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 468 | lemma less_nat_rel: "op < = (\<lambda>m n. n = Suc m)^++" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 469 | proof (rule ext, rule ext, rule iffI) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 470 | fix n m :: nat | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 471 | assume "m < n" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 472 | then show "(\<lambda>m n. n = Suc m)^++ m n" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 473 | proof (induct n) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 474 | case 0 then show ?case by auto | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 475 | next | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 476 | case (Suc n) then show ?case | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 477 | by (auto simp add: less_Suc_eq_le le_less intro: tranclp.trancl_into_trancl) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 478 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 479 | next | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 480 | fix n m :: nat | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 481 | assume "(\<lambda>m n. n = Suc m)^++ m n" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 482 | then show "m < n" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 483 | by (induct n) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 484 | (simp_all add: less_Suc_eq_le reflexive le_less) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 485 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 486 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 487 | definition | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 488 | pred_nat :: "(nat * nat) set" where | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 489 |   "pred_nat = {(m, n). n = Suc m}"
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 490 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 491 | definition | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 492 | less_than :: "(nat * nat) set" where | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 493 | "less_than = pred_nat^+" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 494 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 495 | lemma less_eq: "(m, n) \<in> pred_nat^+ \<longleftrightarrow> m < n" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 496 | unfolding less_nat_rel pred_nat_def trancl_def by simp | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 497 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 498 | lemma pred_nat_trancl_eq_le: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 499 | "(m, n) \<in> pred_nat^* \<longleftrightarrow> m \<le> n" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 500 | unfolding less_eq rtrancl_eq_or_trancl by auto | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 501 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 502 | lemma wf_pred_nat: "wf pred_nat" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 503 | apply (unfold wf_def pred_nat_def, clarify) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 504 | apply (induct_tac x, blast+) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 505 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 506 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 507 | lemma wf_less_than [iff]: "wf less_than" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 508 | by (simp add: less_than_def wf_pred_nat [THEN wf_trancl]) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 509 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 510 | lemma trans_less_than [iff]: "trans less_than" | 
| 35216 | 511 | by (simp add: less_than_def) | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 512 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 513 | lemma less_than_iff [iff]: "((x,y): less_than) = (x<y)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 514 | by (simp add: less_than_def less_eq) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 515 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 516 | lemma wf_less: "wf {(x, y::nat). x < y}"
 | 
| 60493 
866f41a869e6
New WF theorem by Tjark Weber. Replaced the proof of the subsequent theorem.
 paulson <lp15@cam.ac.uk> parents: 
60148diff
changeset | 517 | by (rule Wellfounded.wellorder_class.wf) | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 518 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 519 | |
| 60758 | 520 | subsection \<open>Accessible Part\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 521 | |
| 60758 | 522 | text \<open> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 523 |  Inductive definition of the accessible part @{term "acc r"} of a
 | 
| 58623 | 524 |  relation; see also @{cite "paulin-tlca"}.
 | 
| 60758 | 525 | \<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 526 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 527 | inductive_set | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 528 |   acc :: "('a * 'a) set => 'a set"
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 529 |   for r :: "('a * 'a) set"
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 530 | where | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 531 | accI: "(!!y. (y, x) : r ==> y : acc r) ==> x : acc r" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 532 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 533 | abbreviation | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 534 |   termip :: "('a => 'a => bool) => 'a => bool" where
 | 
| 45137 | 535 | "termip r \<equiv> accp (r\<inverse>\<inverse>)" | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 536 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 537 | abbreviation | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 538 |   termi :: "('a * 'a) set => 'a set" where
 | 
| 45137 | 539 | "termi r \<equiv> acc (r\<inverse>)" | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 540 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 541 | lemmas accpI = accp.accI | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 542 | |
| 54295 | 543 | lemma accp_eq_acc [code]: | 
| 544 |   "accp r = (\<lambda>x. x \<in> Wellfounded.acc {(x, y). r x y})"
 | |
| 545 | by (simp add: acc_def) | |
| 546 | ||
| 547 | ||
| 60758 | 548 | text \<open>Induction rules\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 549 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 550 | theorem accp_induct: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 551 | assumes major: "accp r a" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 552 | assumes hyp: "!!x. accp r x ==> \<forall>y. r y x --> P y ==> P x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 553 | shows "P a" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 554 | apply (rule major [THEN accp.induct]) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 555 | apply (rule hyp) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 556 | apply (rule accp.accI) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 557 | apply fast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 558 | apply fast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 559 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 560 | |
| 61337 | 561 | lemmas accp_induct_rule = accp_induct [rule_format, induct set: accp] | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 562 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 563 | theorem accp_downward: "accp r b ==> r a b ==> accp r a" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 564 | apply (erule accp.cases) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 565 | apply fast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 566 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 567 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 568 | lemma not_accp_down: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 569 | assumes na: "\<not> accp R x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 570 | obtains z where "R z x" and "\<not> accp R z" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 571 | proof - | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 572 | assume a: "\<And>z. \<lbrakk>R z x; \<not> accp R z\<rbrakk> \<Longrightarrow> thesis" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 573 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 574 | show thesis | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 575 | proof (cases "\<forall>z. R z x \<longrightarrow> accp R z") | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 576 | case True | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 577 | hence "\<And>z. R z x \<Longrightarrow> accp R z" by auto | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 578 | hence "accp R x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 579 | by (rule accp.accI) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 580 | with na show thesis .. | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 581 | next | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 582 | case False then obtain z where "R z x" and "\<not> accp R z" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 583 | by auto | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 584 | with a show thesis . | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 585 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 586 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 587 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 588 | lemma accp_downwards_aux: "r\<^sup>*\<^sup>* b a ==> accp r a --> accp r b" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 589 | apply (erule rtranclp_induct) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 590 | apply blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 591 | apply (blast dest: accp_downward) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 592 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 593 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 594 | theorem accp_downwards: "accp r a ==> r\<^sup>*\<^sup>* b a ==> accp r b" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 595 | apply (blast dest: accp_downwards_aux) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 596 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 597 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 598 | theorem accp_wfPI: "\<forall>x. accp r x ==> wfP r" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 599 | apply (rule wfPUNIVI) | 
| 44921 | 600 | apply (rule_tac P=P in accp_induct) | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 601 | apply blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 602 | apply blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 603 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 604 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 605 | theorem accp_wfPD: "wfP r ==> accp r x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 606 | apply (erule wfP_induct_rule) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 607 | apply (rule accp.accI) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 608 | apply blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 609 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 610 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 611 | theorem wfP_accp_iff: "wfP r = (\<forall>x. accp r x)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 612 | apply (blast intro: accp_wfPI dest: accp_wfPD) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 613 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 614 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 615 | |
| 60758 | 616 | text \<open>Smaller relations have bigger accessible parts:\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 617 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 618 | lemma accp_subset: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 619 | assumes sub: "R1 \<le> R2" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 620 | shows "accp R2 \<le> accp R1" | 
| 26803 
0af0f674845d
- Explicitely passed pred_subset_eq and pred_equals_eq as an argument to the
 berghofe parents: 
26748diff
changeset | 621 | proof (rule predicate1I) | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 622 | fix x assume "accp R2 x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 623 | then show "accp R1 x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 624 | proof (induct x) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 625 | fix x | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 626 | assume ih: "\<And>y. R2 y x \<Longrightarrow> accp R1 y" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 627 | with sub show "accp R1 x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 628 | by (blast intro: accp.accI) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 629 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 630 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 631 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 632 | |
| 60758 | 633 | text \<open>This is a generalized induction theorem that works on | 
| 634 | subsets of the accessible part.\<close> | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 635 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 636 | lemma accp_subset_induct: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 637 | assumes subset: "D \<le> accp R" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 638 | and dcl: "\<And>x z. \<lbrakk>D x; R z x\<rbrakk> \<Longrightarrow> D z" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 639 | and "D x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 640 | and istep: "\<And>x. \<lbrakk>D x; (\<And>z. R z x \<Longrightarrow> P z)\<rbrakk> \<Longrightarrow> P x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 641 | shows "P x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 642 | proof - | 
| 60758 | 643 | from subset and \<open>D x\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 644 | have "accp R x" .. | 
| 60758 | 645 | then show "P x" using \<open>D x\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 646 | proof (induct x) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 647 | fix x | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 648 | assume "D x" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 649 | and "\<And>y. R y x \<Longrightarrow> D y \<Longrightarrow> P y" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 650 | with dcl and istep show "P x" by blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 651 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 652 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 653 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 654 | |
| 60758 | 655 | text \<open>Set versions of the above theorems\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 656 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 657 | lemmas acc_induct = accp_induct [to_set] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 658 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 659 | lemmas acc_induct_rule = acc_induct [rule_format, induct set: acc] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 660 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 661 | lemmas acc_downward = accp_downward [to_set] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 662 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 663 | lemmas not_acc_down = not_accp_down [to_set] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 664 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 665 | lemmas acc_downwards_aux = accp_downwards_aux [to_set] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 666 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 667 | lemmas acc_downwards = accp_downwards [to_set] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 668 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 669 | lemmas acc_wfI = accp_wfPI [to_set] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 670 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 671 | lemmas acc_wfD = accp_wfPD [to_set] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 672 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 673 | lemmas wf_acc_iff = wfP_accp_iff [to_set] | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 674 | |
| 46177 
adac34829e10
pred_subset_eq and SUP_UN_eq2 are now standard pred_set_conv rules
 berghofe parents: 
45970diff
changeset | 675 | lemmas acc_subset = accp_subset [to_set] | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 676 | |
| 46177 
adac34829e10
pred_subset_eq and SUP_UN_eq2 are now standard pred_set_conv rules
 berghofe parents: 
45970diff
changeset | 677 | lemmas acc_subset_induct = accp_subset_induct [to_set] | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 678 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 679 | |
| 60758 | 680 | subsection \<open>Tools for building wellfounded relations\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 681 | |
| 60758 | 682 | text \<open>Inverse Image\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 683 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 684 | lemma wf_inv_image [simp,intro!]: "wf(r) ==> wf(inv_image r (f::'a=>'b))" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 685 | apply (simp (no_asm_use) add: inv_image_def wf_eq_minimal) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 686 | apply clarify | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 687 | apply (subgoal_tac "EX (w::'b) . w : {w. EX (x::'a) . x: Q & (f x = w) }")
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 688 | prefer 2 apply (blast del: allE) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 689 | apply (erule allE) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 690 | apply (erule (1) notE impE) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 691 | apply blast | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 692 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 693 | |
| 60758 | 694 | text \<open>Measure functions into @{typ nat}\<close>
 | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 695 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 696 | definition measure :: "('a => nat) => ('a * 'a)set"
 | 
| 45137 | 697 | where "measure = inv_image less_than" | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 698 | |
| 46356 | 699 | lemma in_measure[simp, code_unfold]: "((x,y) : measure f) = (f x < f y)" | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 700 | by (simp add:measure_def) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 701 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 702 | lemma wf_measure [iff]: "wf (measure f)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 703 | apply (unfold measure_def) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 704 | apply (rule wf_less_than [THEN wf_inv_image]) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 705 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 706 | |
| 41720 | 707 | lemma wf_if_measure: fixes f :: "'a \<Rightarrow> nat" | 
| 708 | shows "(!!x. P x \<Longrightarrow> f(g x) < f x) \<Longrightarrow> wf {(y,x). P x \<and> y = g x}"
 | |
| 709 | apply(insert wf_measure[of f]) | |
| 710 | apply(simp only: measure_def inv_image_def less_than_def less_eq) | |
| 711 | apply(erule wf_subset) | |
| 712 | apply auto | |
| 713 | done | |
| 714 | ||
| 715 | ||
| 60758 | 716 | text\<open>Lexicographic combinations\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 717 | |
| 37767 | 718 | definition lex_prod :: "('a \<times>'a) set \<Rightarrow> ('b \<times> 'b) set \<Rightarrow> (('a \<times> 'b) \<times> ('a \<times> 'b)) set" (infixr "<*lex*>" 80) where
 | 
| 719 |   "ra <*lex*> rb = {((a, b), (a', b')). (a, a') \<in> ra \<or> a = a' \<and> (b, b') \<in> rb}"
 | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 720 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 721 | lemma wf_lex_prod [intro!]: "[| wf(ra); wf(rb) |] ==> wf(ra <*lex*> rb)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 722 | apply (unfold wf_def lex_prod_def) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 723 | apply (rule allI, rule impI) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 724 | apply (simp (no_asm_use) only: split_paired_All) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 725 | apply (drule spec, erule mp) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 726 | apply (rule allI, rule impI) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 727 | apply (drule spec, erule mp, blast) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 728 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 729 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 730 | lemma in_lex_prod[simp]: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 731 | "(((a,b),(a',b')): r <*lex*> s) = ((a,a'): r \<or> (a = a' \<and> (b, b') : s))" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 732 | by (auto simp:lex_prod_def) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 733 | |
| 60758 | 734 | text\<open>@{term "op <*lex*>"} preserves transitivity\<close>
 | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 735 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 736 | lemma trans_lex_prod [intro!]: | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 737 | "[| trans R1; trans R2 |] ==> trans (R1 <*lex*> R2)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 738 | by (unfold trans_def lex_prod_def, blast) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 739 | |
| 60758 | 740 | text \<open>lexicographic combinations with measure functions\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 741 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 742 | definition | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 743 |   mlex_prod :: "('a \<Rightarrow> nat) \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set" (infixr "<*mlex*>" 80)
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 744 | where | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 745 | "f <*mlex*> R = inv_image (less_than <*lex*> R) (%x. (f x, x))" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 746 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 747 | lemma wf_mlex: "wf R \<Longrightarrow> wf (f <*mlex*> R)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 748 | unfolding mlex_prod_def | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 749 | by auto | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 750 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 751 | lemma mlex_less: "f x < f y \<Longrightarrow> (x, y) \<in> f <*mlex*> R" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 752 | unfolding mlex_prod_def by simp | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 753 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 754 | lemma mlex_leq: "f x \<le> f y \<Longrightarrow> (x, y) \<in> R \<Longrightarrow> (x, y) \<in> f <*mlex*> R" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 755 | unfolding mlex_prod_def by auto | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 756 | |
| 60758 | 757 | text \<open>proper subset relation on finite sets\<close> | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 758 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 759 | definition finite_psubset  :: "('a set * 'a set) set"
 | 
| 45137 | 760 | where "finite_psubset = {(A,B). A < B & finite B}"
 | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 761 | |
| 28260 | 762 | lemma wf_finite_psubset[simp]: "wf(finite_psubset)" | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 763 | apply (unfold finite_psubset_def) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 764 | apply (rule wf_measure [THEN wf_subset]) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 765 | apply (simp add: measure_def inv_image_def less_than_def less_eq) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 766 | apply (fast elim!: psubset_card_mono) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 767 | done | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 768 | |
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 769 | lemma trans_finite_psubset: "trans finite_psubset" | 
| 26803 
0af0f674845d
- Explicitely passed pred_subset_eq and pred_equals_eq as an argument to the
 berghofe parents: 
26748diff
changeset | 770 | by (simp add: finite_psubset_def less_le trans_def, blast) | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 771 | |
| 28260 | 772 | lemma in_finite_psubset[simp]: "(A, B) \<in> finite_psubset = (A < B & finite B)" | 
| 773 | unfolding finite_psubset_def by auto | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 774 | |
| 60758 | 775 | text \<open>max- and min-extension of order to finite sets\<close> | 
| 28735 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 776 | |
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 777 | inductive_set max_ext :: "('a \<times> 'a) set \<Rightarrow> ('a set \<times> 'a set) set" 
 | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 778 | for R :: "('a \<times> 'a) set"
 | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 779 | where | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 780 |   max_extI[intro]: "finite X \<Longrightarrow> finite Y \<Longrightarrow> Y \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> \<exists>y\<in>Y. (x, y) \<in> R) \<Longrightarrow> (X, Y) \<in> max_ext R"
 | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 781 | |
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 782 | lemma max_ext_wf: | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 783 | assumes wf: "wf r" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 784 | shows "wf (max_ext r)" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 785 | proof (rule acc_wfI, intro allI) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 786 | fix M show "M \<in> acc (max_ext r)" (is "_ \<in> ?W") | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 787 | proof cases | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 788 | assume "finite M" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 789 | thus ?thesis | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 790 | proof (induct M) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 791 |       show "{} \<in> ?W"
 | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 792 | by (rule accI) (auto elim: max_ext.cases) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 793 | next | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 794 | fix M a assume "M \<in> ?W" "finite M" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 795 | with wf show "insert a M \<in> ?W" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 796 | proof (induct arbitrary: M) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 797 | fix M a | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 798 | assume "M \<in> ?W" and [intro]: "finite M" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 799 | assume hyp: "\<And>b M. (b, a) \<in> r \<Longrightarrow> M \<in> ?W \<Longrightarrow> finite M \<Longrightarrow> insert b M \<in> ?W" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 800 |         {
 | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 801 | fix N M :: "'a set" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 802 | assume "finite N" "finite M" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 803 | then | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 804 | have "\<lbrakk>M \<in> ?W ; (\<And>y. y \<in> N \<Longrightarrow> (y, a) \<in> r)\<rbrakk> \<Longrightarrow> N \<union> M \<in> ?W" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 805 | by (induct N arbitrary: M) (auto simp: hyp) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 806 | } | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 807 | note add_less = this | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 808 | |
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 809 | show "insert a M \<in> ?W" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 810 | proof (rule accI) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 811 | fix N assume Nless: "(N, insert a M) \<in> max_ext r" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 812 | hence asm1: "\<And>x. x \<in> N \<Longrightarrow> (x, a) \<in> r \<or> (\<exists>y \<in> M. (x, y) \<in> r)" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 813 | by (auto elim!: max_ext.cases) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 814 | |
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 815 |           let ?N1 = "{ n \<in> N. (n, a) \<in> r }"
 | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 816 |           let ?N2 = "{ n \<in> N. (n, a) \<notin> r }"
 | 
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
37767diff
changeset | 817 | have N: "?N1 \<union> ?N2 = N" by (rule set_eqI) auto | 
| 28735 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 818 | from Nless have "finite N" by (auto elim: max_ext.cases) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 819 | then have finites: "finite ?N1" "finite ?N2" by auto | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 820 | |
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 821 | have "?N2 \<in> ?W" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 822 | proof cases | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 823 |             assume [simp]: "M = {}"
 | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 824 |             have Mw: "{} \<in> ?W" by (rule accI) (auto elim: max_ext.cases)
 | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 825 | |
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 826 |             from asm1 have "?N2 = {}" by auto
 | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 827 | with Mw show "?N2 \<in> ?W" by (simp only:) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 828 | next | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 829 |             assume "M \<noteq> {}"
 | 
| 49945 | 830 | from asm1 finites have N2: "(?N2, M) \<in> max_ext r" | 
| 60758 | 831 |               by (rule_tac max_extI[OF _ _ \<open>M \<noteq> {}\<close>]) auto
 | 
| 49945 | 832 | |
| 60758 | 833 | with \<open>M \<in> ?W\<close> show "?N2 \<in> ?W" by (rule acc_downward) | 
| 28735 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 834 | qed | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 835 | with finites have "?N1 \<union> ?N2 \<in> ?W" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 836 | by (rule add_less) simp | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 837 | then show "N \<in> ?W" by (simp only: N) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 838 | qed | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 839 | qed | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 840 | qed | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 841 | next | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 842 | assume [simp]: "\<not> finite M" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 843 | show ?thesis | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 844 | by (rule accI) (auto elim: max_ext.cases) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 845 | qed | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 846 | qed | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 847 | |
| 29125 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 krauss parents: 
28845diff
changeset | 848 | lemma max_ext_additive: | 
| 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 krauss parents: 
28845diff
changeset | 849 | "(A, B) \<in> max_ext R \<Longrightarrow> (C, D) \<in> max_ext R \<Longrightarrow> | 
| 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 krauss parents: 
28845diff
changeset | 850 | (A \<union> C, B \<union> D) \<in> max_ext R" | 
| 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 krauss parents: 
28845diff
changeset | 851 | by (force elim!: max_ext.cases) | 
| 
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
 krauss parents: 
28845diff
changeset | 852 | |
| 28735 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 853 | |
| 37767 | 854 | definition min_ext :: "('a \<times> 'a) set \<Rightarrow> ('a set \<times> 'a set) set"  where
 | 
| 855 |   "min_ext r = {(X, Y) | X Y. X \<noteq> {} \<and> (\<forall>y \<in> Y. (\<exists>x \<in> X. (x, y) \<in> r))}"
 | |
| 28735 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 856 | |
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 857 | lemma min_ext_wf: | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 858 | assumes "wf r" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 859 | shows "wf (min_ext r)" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 860 | proof (rule wfI_min) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 861 | fix Q :: "'a set set" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 862 | fix x | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 863 | assume nonempty: "x \<in> Q" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 864 | show "\<exists>m \<in> Q. (\<forall> n. (n, m) \<in> min_ext r \<longrightarrow> n \<notin> Q)" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 865 | proof cases | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 866 |     assume "Q = {{}}" thus ?thesis by (simp add: min_ext_def)
 | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 867 | next | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 868 |     assume "Q \<noteq> {{}}"
 | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 869 | with nonempty | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 870 | obtain e x where "x \<in> Q" "e \<in> x" by force | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 871 | then have eU: "e \<in> \<Union>Q" by auto | 
| 60758 | 872 | with \<open>wf r\<close> | 
| 28735 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 873 | obtain z where z: "z \<in> \<Union>Q" "\<And>y. (y, z) \<in> r \<Longrightarrow> y \<notin> \<Union>Q" | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 874 | by (erule wfE_min) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 875 | from z obtain m where "m \<in> Q" "z \<in> m" by auto | 
| 60758 | 876 | from \<open>m \<in> Q\<close> | 
| 28735 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 877 | show ?thesis | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 878 | proof (rule, intro bexI allI impI) | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 879 | fix n | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 880 | assume smaller: "(n, m) \<in> min_ext r" | 
| 60758 | 881 | with \<open>z \<in> m\<close> obtain y where y: "y \<in> n" "(y, z) \<in> r" by (auto simp: min_ext_def) | 
| 28735 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 882 | then show "n \<notin> Q" using z(2) by auto | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 883 | qed | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 884 | qed | 
| 
bed31381e6b6
min_ext/max_ext lifting wellfounded relations on finite sets. Preserves wf
 krauss parents: 
28562diff
changeset | 885 | qed | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 886 | |
| 60758 | 887 | text\<open>Bounded increase must terminate:\<close> | 
| 43137 | 888 | |
| 889 | lemma wf_bounded_measure: | |
| 890 | fixes ub :: "'a \<Rightarrow> nat" and f :: "'a \<Rightarrow> nat" | |
| 43140 | 891 | assumes "!!a b. (b,a) : r \<Longrightarrow> ub b \<le> ub a & ub a \<ge> f b & f b > f a" | 
| 43137 | 892 | shows "wf r" | 
| 893 | apply(rule wf_subset[OF wf_measure[of "%a. ub a - f a"]]) | |
| 894 | apply (auto dest: assms) | |
| 895 | done | |
| 896 | ||
| 897 | lemma wf_bounded_set: | |
| 898 | fixes ub :: "'a \<Rightarrow> 'b set" and f :: "'a \<Rightarrow> 'b set" | |
| 899 | assumes "!!a b. (b,a) : r \<Longrightarrow> | |
| 43140 | 900 | finite(ub a) & ub b \<subseteq> ub a & ub a \<supseteq> f b & f b \<supset> f a" | 
| 43137 | 901 | shows "wf r" | 
| 902 | apply(rule wf_bounded_measure[of r "%a. card(ub a)" "%a. card(f a)"]) | |
| 903 | apply(drule assms) | |
| 43140 | 904 | apply (blast intro: card_mono finite_subset psubset_card_mono dest: psubset_eq[THEN iffD2]) | 
| 43137 | 905 | done | 
| 906 | ||
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 907 | |
| 54295 | 908 | hide_const (open) acc accp | 
| 909 | ||
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: diff
changeset | 910 | end |