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