82 unfolding wf_def by (blast intro: less_induct) |
82 unfolding wf_def by (blast intro: less_induct) |
83 |
83 |
84 |
84 |
85 subsection {* Basic Results *} |
85 subsection {* Basic Results *} |
86 |
86 |
87 text{*transitive closure of a well-founded relation is well-founded! *} |
87 text {* Point-free characterization of well-foundedness *} |
|
88 |
|
89 lemma wfE_pf: |
|
90 assumes wf: "wf R" |
|
91 assumes a: "A \<subseteq> R `` A" |
|
92 shows "A = {}" |
|
93 proof - |
|
94 { fix x |
|
95 from wf have "x \<notin> A" |
|
96 proof induct |
|
97 fix x assume "\<And>y. (y, x) \<in> R \<Longrightarrow> y \<notin> A" |
|
98 then have "x \<notin> R `` A" by blast |
|
99 with a show "x \<notin> A" by blast |
|
100 qed |
|
101 } thus ?thesis by auto |
|
102 qed |
|
103 |
|
104 lemma wfI_pf: |
|
105 assumes a: "\<And>A. A \<subseteq> R `` A \<Longrightarrow> A = {}" |
|
106 shows "wf R" |
|
107 proof (rule wfUNIVI) |
|
108 fix P :: "'a \<Rightarrow> bool" and x |
|
109 let ?A = "{x. \<not> P x}" |
|
110 assume "\<forall>x. (\<forall>y. (y, x) \<in> R \<longrightarrow> P y) \<longrightarrow> P x" |
|
111 then have "?A \<subseteq> R `` ?A" by blast |
|
112 with a show "P x" by blast |
|
113 qed |
|
114 |
|
115 text{*Minimal-element characterization of well-foundedness*} |
|
116 |
|
117 lemma wfE_min: |
|
118 assumes wf: "wf R" and Q: "x \<in> Q" |
|
119 obtains z where "z \<in> Q" "\<And>y. (y, z) \<in> R \<Longrightarrow> y \<notin> Q" |
|
120 using Q wfE_pf[OF wf, of Q] by blast |
|
121 |
|
122 lemma wfI_min: |
|
123 assumes a: "\<And>x Q. x \<in> Q \<Longrightarrow> \<exists>z\<in>Q. \<forall>y. (y, z) \<in> R \<longrightarrow> y \<notin> Q" |
|
124 shows "wf R" |
|
125 proof (rule wfI_pf) |
|
126 fix A assume b: "A \<subseteq> R `` A" |
|
127 { fix x assume "x \<in> A" |
|
128 from a[OF this] b have "False" by blast |
|
129 } |
|
130 thus "A = {}" by blast |
|
131 qed |
|
132 |
|
133 lemma wf_eq_minimal: "wf r = (\<forall>Q x. x\<in>Q --> (\<exists>z\<in>Q. \<forall>y. (y,z)\<in>r --> y\<notin>Q))" |
|
134 apply auto |
|
135 apply (erule wfE_min, assumption, blast) |
|
136 apply (rule wfI_min, auto) |
|
137 done |
|
138 |
|
139 lemmas wfP_eq_minimal = wf_eq_minimal [to_pred] |
|
140 |
|
141 text{* Well-foundedness of transitive closure *} |
|
142 |
88 lemma wf_trancl: |
143 lemma wf_trancl: |
89 assumes "wf r" |
144 assumes "wf r" |
90 shows "wf (r^+)" |
145 shows "wf (r^+)" |
91 proof - |
146 proof - |
92 { |
147 { |
122 lemma wf_converse_trancl: "wf (r^-1) ==> wf ((r^+)^-1)" |
177 lemma wf_converse_trancl: "wf (r^-1) ==> wf ((r^+)^-1)" |
123 apply (subst trancl_converse [symmetric]) |
178 apply (subst trancl_converse [symmetric]) |
124 apply (erule wf_trancl) |
179 apply (erule wf_trancl) |
125 done |
180 done |
126 |
181 |
127 |
|
128 text{*Minimal-element characterization of well-foundedness*} |
|
129 lemma wf_eq_minimal: "wf r = (\<forall>Q x. x\<in>Q --> (\<exists>z\<in>Q. \<forall>y. (y,z)\<in>r --> y\<notin>Q))" |
|
130 proof (intro iffI strip) |
|
131 fix Q :: "'a set" and x |
|
132 assume "wf r" and "x \<in> Q" |
|
133 then show "\<exists>z\<in>Q. \<forall>y. (y, z) \<in> r \<longrightarrow> y \<notin> Q" |
|
134 unfolding wf_def |
|
135 by (blast dest: spec [of _ "%x. x\<in>Q \<longrightarrow> (\<exists>z\<in>Q. \<forall>y. (y,z) \<in> r \<longrightarrow> y\<notin>Q)"]) |
|
136 next |
|
137 assume 1: "\<forall>Q x. x \<in> Q \<longrightarrow> (\<exists>z\<in>Q. \<forall>y. (y, z) \<in> r \<longrightarrow> y \<notin> Q)" |
|
138 show "wf r" |
|
139 proof (rule wfUNIVI) |
|
140 fix P :: "'a \<Rightarrow> bool" and x |
|
141 assume 2: "\<forall>x. (\<forall>y. (y, x) \<in> r \<longrightarrow> P y) \<longrightarrow> P x" |
|
142 let ?Q = "{x. \<not> P x}" |
|
143 have "x \<in> ?Q \<longrightarrow> (\<exists>z \<in> ?Q. \<forall>y. (y, z) \<in> r \<longrightarrow> y \<notin> ?Q)" |
|
144 by (rule 1 [THEN spec, THEN spec]) |
|
145 then have "\<not> P x \<longrightarrow> (\<exists>z. \<not> P z \<and> (\<forall>y. (y, z) \<in> r \<longrightarrow> P y))" by simp |
|
146 with 2 have "\<not> P x \<longrightarrow> (\<exists>z. \<not> P z \<and> P z)" by fast |
|
147 then show "P x" by simp |
|
148 qed |
|
149 qed |
|
150 |
|
151 lemma wfE_min: |
|
152 assumes "wf R" "x \<in> Q" |
|
153 obtains z where "z \<in> Q" "\<And>y. (y, z) \<in> R \<Longrightarrow> y \<notin> Q" |
|
154 using assms unfolding wf_eq_minimal by blast |
|
155 |
|
156 lemma wfI_min: |
|
157 "(\<And>x Q. x \<in> Q \<Longrightarrow> \<exists>z\<in>Q. \<forall>y. (y, z) \<in> R \<longrightarrow> y \<notin> Q) |
|
158 \<Longrightarrow> wf R" |
|
159 unfolding wf_eq_minimal by blast |
|
160 |
|
161 lemmas wfP_eq_minimal = wf_eq_minimal [to_pred] |
|
162 |
|
163 text {* Well-foundedness of subsets *} |
182 text {* Well-foundedness of subsets *} |
|
183 |
164 lemma wf_subset: "[| wf(r); p<=r |] ==> wf(p)" |
184 lemma wf_subset: "[| wf(r); p<=r |] ==> wf(p)" |
165 apply (simp (no_asm_use) add: wf_eq_minimal) |
185 apply (simp (no_asm_use) add: wf_eq_minimal) |
166 apply fast |
186 apply fast |
167 done |
187 done |
168 |
188 |
169 lemmas wfP_subset = wf_subset [to_pred] |
189 lemmas wfP_subset = wf_subset [to_pred] |
170 |
190 |
171 text {* Well-foundedness of the empty relation *} |
191 text {* Well-foundedness of the empty relation *} |
172 lemma wf_empty [iff]: "wf({})" |
192 |
|
193 lemma wf_empty [iff]: "wf {}" |
173 by (simp add: wf_def) |
194 by (simp add: wf_def) |
174 |
195 |
175 lemma wfP_empty [iff]: |
196 lemma wfP_empty [iff]: |
176 "wfP (\<lambda>x y. False)" |
197 "wfP (\<lambda>x y. False)" |
177 proof - |
198 proof - |
187 lemma wf_Int2: "wf r ==> wf (r' Int r)" |
208 lemma wf_Int2: "wf r ==> wf (r' Int r)" |
188 apply (erule wf_subset) |
209 apply (erule wf_subset) |
189 apply (rule Int_lower2) |
210 apply (rule Int_lower2) |
190 done |
211 done |
191 |
212 |
192 text{*Well-foundedness of insert*} |
213 text {* Exponentiation *} |
|
214 |
|
215 lemma wf_exp: |
|
216 assumes "wf (R ^^ n)" |
|
217 shows "wf R" |
|
218 proof (rule wfI_pf) |
|
219 fix A assume "A \<subseteq> R `` A" |
|
220 then have "A \<subseteq> (R ^^ n) `` A" by (induct n) force+ |
|
221 with `wf (R ^^ n)` |
|
222 show "A = {}" by (rule wfE_pf) |
|
223 qed |
|
224 |
|
225 text {* Well-foundedness of insert *} |
|
226 |
193 lemma wf_insert [iff]: "wf(insert (y,x) r) = (wf(r) & (x,y) ~: r^*)" |
227 lemma wf_insert [iff]: "wf(insert (y,x) r) = (wf(r) & (x,y) ~: r^*)" |
194 apply (rule iffI) |
228 apply (rule iffI) |
195 apply (blast elim: wf_trancl [THEN wf_irrefl] |
229 apply (blast elim: wf_trancl [THEN wf_irrefl] |
196 intro: rtrancl_into_trancl1 wf_subset |
230 intro: rtrancl_into_trancl1 wf_subset |
197 rtrancl_mono [THEN [2] rev_subsetD]) |
231 rtrancl_mono [THEN [2] rev_subsetD]) |
210 txt{*Blast with new substOccur fails*} |
244 txt{*Blast with new substOccur fails*} |
211 apply (fast intro: converse_rtrancl_into_rtrancl) |
245 apply (fast intro: converse_rtrancl_into_rtrancl) |
212 done |
246 done |
213 |
247 |
214 text{*Well-foundedness of image*} |
248 text{*Well-foundedness of image*} |
|
249 |
215 lemma wf_prod_fun_image: "[| wf r; inj f |] ==> wf(prod_fun f f ` r)" |
250 lemma wf_prod_fun_image: "[| wf r; inj f |] ==> wf(prod_fun f f ` r)" |
216 apply (simp only: wf_eq_minimal, clarify) |
251 apply (simp only: wf_eq_minimal, clarify) |
217 apply (case_tac "EX p. f p : Q") |
252 apply (case_tac "EX p. f p : Q") |
218 apply (erule_tac x = "{p. f p : Q}" in allE) |
253 apply (erule_tac x = "{p. f p : Q}" in allE) |
219 apply (fast dest: inj_onD, blast) |
254 apply (fast dest: inj_onD, blast) |