1 (* Title: HOL/Order_Relation.thy |
1 (* Title: HOL/Order_Relation.thy |
2 Author: Tobias Nipkow |
2 Author: Tobias Nipkow |
3 Author: Andrei Popescu, TU Muenchen |
3 Author: Andrei Popescu, TU Muenchen |
4 *) |
4 *) |
5 |
5 |
6 section {* Orders as Relations *} |
6 section \<open>Orders as Relations\<close> |
7 |
7 |
8 theory Order_Relation |
8 theory Order_Relation |
9 imports Wfrec |
9 imports Wfrec |
10 begin |
10 begin |
11 |
11 |
12 subsection{* Orders on a set *} |
12 subsection\<open>Orders on a set\<close> |
13 |
13 |
14 definition "preorder_on A r \<equiv> refl_on A r \<and> trans r" |
14 definition "preorder_on A r \<equiv> refl_on A r \<and> trans r" |
15 |
15 |
16 definition "partial_order_on A r \<equiv> preorder_on A r \<and> antisym r" |
16 definition "partial_order_on A r \<equiv> preorder_on A r \<and> antisym r" |
17 |
17 |
54 lemma strict_linear_order_on_diff_Id: |
54 lemma strict_linear_order_on_diff_Id: |
55 "linear_order_on A r \<Longrightarrow> strict_linear_order_on A (r-Id)" |
55 "linear_order_on A r \<Longrightarrow> strict_linear_order_on A (r-Id)" |
56 by(simp add: order_on_defs trans_diff_Id) |
56 by(simp add: order_on_defs trans_diff_Id) |
57 |
57 |
58 |
58 |
59 subsection{* Orders on the field *} |
59 subsection\<open>Orders on the field\<close> |
60 |
60 |
61 abbreviation "Refl r \<equiv> refl_on (Field r) r" |
61 abbreviation "Refl r \<equiv> refl_on (Field r) r" |
62 |
62 |
63 abbreviation "Preorder r \<equiv> preorder_on (Field r) r" |
63 abbreviation "Preorder r \<equiv> preorder_on (Field r) r" |
64 |
64 |
113 by (simp add: total_on_def) |
113 by (simp add: total_on_def) |
114 thus "a \<in> Field(r - Id)" using 3 unfolding Field_def by blast |
114 thus "a \<in> Field(r - Id)" using 3 unfolding Field_def by blast |
115 qed |
115 qed |
116 |
116 |
117 |
117 |
118 subsection{* Orders on a type *} |
118 subsection\<open>Orders on a type\<close> |
119 |
119 |
120 abbreviation "strict_linear_order \<equiv> strict_linear_order_on UNIV" |
120 abbreviation "strict_linear_order \<equiv> strict_linear_order_on UNIV" |
121 |
121 |
122 abbreviation "linear_order \<equiv> linear_order_on UNIV" |
122 abbreviation "linear_order \<equiv> linear_order_on UNIV" |
123 |
123 |
124 abbreviation "well_order \<equiv> well_order_on UNIV" |
124 abbreviation "well_order \<equiv> well_order_on UNIV" |
125 |
125 |
126 |
126 |
127 subsection {* Order-like relations *} |
127 subsection \<open>Order-like relations\<close> |
128 |
128 |
129 text{* In this subsection, we develop basic concepts and results pertaining |
129 text\<open>In this subsection, we develop basic concepts and results pertaining |
130 to order-like relations, i.e., to reflexive and/or transitive and/or symmetric and/or |
130 to order-like relations, i.e., to reflexive and/or transitive and/or symmetric and/or |
131 total relations. We also further define upper and lower bounds operators. *} |
131 total relations. We also further define upper and lower bounds operators.\<close> |
132 |
132 |
133 |
133 |
134 subsubsection {* Auxiliaries *} |
134 subsubsection \<open>Auxiliaries\<close> |
135 |
135 |
136 lemma refl_on_domain: |
136 lemma refl_on_domain: |
137 "\<lbrakk>refl_on A r; (a,b) : r\<rbrakk> \<Longrightarrow> a \<in> A \<and> b \<in> A" |
137 "\<lbrakk>refl_on A r; (a,b) : r\<rbrakk> \<Longrightarrow> a \<in> A \<and> b \<in> A" |
138 by(auto simp add: refl_on_def) |
138 by(auto simp add: refl_on_def) |
139 |
139 |
175 IN1: "a \<in> Field r" and IN2: "b \<in> Field r" |
175 IN1: "a \<in> Field r" and IN2: "b \<in> Field r" |
176 shows "((a,b) \<in> r) = ((b,a) \<notin> r - Id)" |
176 shows "((a,b) \<in> r) = ((b,a) \<notin> r - Id)" |
177 using assms unfolding order_on_defs total_on_def antisym_def Id_def refl_on_def by force |
177 using assms unfolding order_on_defs total_on_def antisym_def Id_def refl_on_def by force |
178 |
178 |
179 |
179 |
180 subsubsection {* The upper and lower bounds operators *} |
180 subsubsection \<open>The upper and lower bounds operators\<close> |
181 |
181 |
182 text{* Here we define upper (``above") and lower (``below") bounds operators. |
182 text\<open>Here we define upper (``above") and lower (``below") bounds operators. |
183 We think of @{text "r"} as a {\em non-strict} relation. The suffix ``S" |
183 We think of @{text "r"} as a {\em non-strict} relation. The suffix ``S" |
184 at the names of some operators indicates that the bounds are strict -- e.g., |
184 at the names of some operators indicates that the bounds are strict -- e.g., |
185 @{text "underS a"} is the set of all strict lower bounds of @{text "a"} (w.r.t. @{text "r"}). |
185 @{text "underS a"} is the set of all strict lower bounds of @{text "a"} (w.r.t. @{text "r"}). |
186 Capitalization of the first letter in the name reminds that the operator acts on sets, rather |
186 Capitalization of the first letter in the name reminds that the operator acts on sets, rather |
187 than on individual elements. *} |
187 than on individual elements.\<close> |
188 |
188 |
189 definition under::"'a rel \<Rightarrow> 'a \<Rightarrow> 'a set" |
189 definition under::"'a rel \<Rightarrow> 'a \<Rightarrow> 'a set" |
190 where "under r a \<equiv> {b. (b,a) \<in> r}" |
190 where "under r a \<equiv> {b. (b,a) \<in> r}" |
191 |
191 |
192 definition underS::"'a rel \<Rightarrow> 'a \<Rightarrow> 'a set" |
192 definition underS::"'a rel \<Rightarrow> 'a \<Rightarrow> 'a set" |
211 where "AboveS r A \<equiv> {b \<in> Field r. \<forall>a \<in> A. b \<noteq> a \<and> (a,b) \<in> r}" |
211 where "AboveS r A \<equiv> {b \<in> Field r. \<forall>a \<in> A. b \<noteq> a \<and> (a,b) \<in> r}" |
212 |
212 |
213 definition ofilter :: "'a rel \<Rightarrow> 'a set \<Rightarrow> bool" |
213 definition ofilter :: "'a rel \<Rightarrow> 'a set \<Rightarrow> bool" |
214 where "ofilter r A \<equiv> (A \<le> Field r) \<and> (\<forall>a \<in> A. under r a \<le> A)" |
214 where "ofilter r A \<equiv> (A \<le> Field r) \<and> (\<forall>a \<in> A. under r a \<le> A)" |
215 |
215 |
216 text{* Note: In the definitions of @{text "Above[S]"} and @{text "Under[S]"}, |
216 text\<open>Note: In the definitions of @{text "Above[S]"} and @{text "Under[S]"}, |
217 we bounded comprehension by @{text "Field r"} in order to properly cover |
217 we bounded comprehension by @{text "Field r"} in order to properly cover |
218 the case of @{text "A"} being empty. *} |
218 the case of @{text "A"} being empty.\<close> |
219 |
219 |
220 lemma underS_subset_under: "underS r a \<le> under r a" |
220 lemma underS_subset_under: "underS r a \<le> under r a" |
221 by(auto simp add: underS_def under_def) |
221 by(auto simp add: underS_def under_def) |
222 |
222 |
223 lemma underS_notIn: "a \<notin> underS r a" |
223 lemma underS_notIn: "a \<notin> underS r a" |
305 show "(a,b) \<in> r" using assms |
305 show "(a,b) \<in> r" using assms |
306 order_on_defs[of "Field r" r] total_on_def[of "Field r" r] by blast |
306 order_on_defs[of "Field r" r] total_on_def[of "Field r" r] by blast |
307 qed |
307 qed |
308 |
308 |
309 |
309 |
310 subsection {* Variations on Well-Founded Relations *} |
310 subsection \<open>Variations on Well-Founded Relations\<close> |
311 |
311 |
312 text {* |
312 text \<open> |
313 This subsection contains some variations of the results from @{theory Wellfounded}: |
313 This subsection contains some variations of the results from @{theory Wellfounded}: |
314 \begin{itemize} |
314 \begin{itemize} |
315 \item means for slightly more direct definitions by well-founded recursion; |
315 \item means for slightly more direct definitions by well-founded recursion; |
316 \item variations of well-founded induction; |
316 \item variations of well-founded induction; |
317 \item means for proving a linear order to be a well-order. |
317 \item means for proving a linear order to be a well-order. |
318 \end{itemize} |
318 \end{itemize} |
319 *} |
319 \<close> |
320 |
320 |
321 |
321 |
322 subsubsection {* Characterizations of well-foundedness *} |
322 subsubsection \<open>Characterizations of well-foundedness\<close> |
323 |
323 |
324 text {* A transitive relation is well-founded iff it is ``locally'' well-founded, |
324 text \<open>A transitive relation is well-founded iff it is ``locally'' well-founded, |
325 i.e., iff its restriction to the lower bounds of of any element is well-founded. *} |
325 i.e., iff its restriction to the lower bounds of of any element is well-founded.\<close> |
326 |
326 |
327 lemma trans_wf_iff: |
327 lemma trans_wf_iff: |
328 assumes "trans r" |
328 assumes "trans r" |
329 shows "wf r = (\<forall>a. wf(r Int (r^-1``{a} \<times> r^-1``{a})))" |
329 shows "wf r = (\<forall>a. wf(r Int (r^-1``{a} \<times> r^-1``{a})))" |
330 proof- |
330 proof- |
360 qed |
360 qed |
361 } |
361 } |
362 ultimately show ?thesis using R_def by blast |
362 ultimately show ?thesis using R_def by blast |
363 qed |
363 qed |
364 |
364 |
365 text {* The next lemma is a variation of @{text "wf_eq_minimal"} from Wellfounded, |
365 text \<open>The next lemma is a variation of @{text "wf_eq_minimal"} from Wellfounded, |
366 allowing one to assume the set included in the field. *} |
366 allowing one to assume the set included in the field.\<close> |
367 |
367 |
368 lemma wf_eq_minimal2: |
368 lemma wf_eq_minimal2: |
369 "wf r = (\<forall>A. A <= Field r \<and> A \<noteq> {} \<longrightarrow> (\<exists>a \<in> A. \<forall>a' \<in> A. \<not> (a',a) \<in> r))" |
369 "wf r = (\<forall>A. A <= Field r \<and> A \<noteq> {} \<longrightarrow> (\<exists>a \<in> A. \<forall>a' \<in> A. \<not> (a',a) \<in> r))" |
370 proof- |
370 proof- |
371 let ?phi = "\<lambda> A. A \<noteq> {} \<longrightarrow> (\<exists>a \<in> A. \<forall>a' \<in> A. \<not> (a',a) \<in> r)" |
371 let ?phi = "\<lambda> A. A \<noteq> {} \<longrightarrow> (\<exists>a \<in> A. \<forall>a' \<in> A. \<not> (a',a) \<in> r)" |
406 qed |
406 qed |
407 finally show ?thesis by blast |
407 finally show ?thesis by blast |
408 qed |
408 qed |
409 |
409 |
410 |
410 |
411 subsubsection {* Characterizations of well-foundedness *} |
411 subsubsection \<open>Characterizations of well-foundedness\<close> |
412 |
412 |
413 text {* The next lemma and its corollary enable one to prove that |
413 text \<open>The next lemma and its corollary enable one to prove that |
414 a linear order is a well-order in a way which is more standard than |
414 a linear order is a well-order in a way which is more standard than |
415 via well-foundedness of the strict version of the relation. *} |
415 via well-foundedness of the strict version of the relation.\<close> |
416 |
416 |
417 lemma Linear_order_wf_diff_Id: |
417 lemma Linear_order_wf_diff_Id: |
418 assumes LI: "Linear_order r" |
418 assumes LI: "Linear_order r" |
419 shows "wf(r - Id) = (\<forall>A \<le> Field r. A \<noteq> {} \<longrightarrow> (\<exists>a \<in> A. \<forall>a' \<in> A. (a,a') \<in> r))" |
419 shows "wf(r - Id) = (\<forall>A \<le> Field r. A \<noteq> {} \<longrightarrow> (\<exists>a \<in> A. \<forall>a' \<in> A. (a,a') \<in> r))" |
420 proof(cases "r \<le> Id") |
420 proof(cases "r \<le> Id") |