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