# Theory Order_Relation

theory Order_Relation
imports Main
`(* Author: Tobias Nipkow *)header {* Orders as Relations *}theory Order_Relationimports Mainbeginsubsection{* Orders on a set *}definition "preorder_on A r ≡ refl_on A r ∧ trans r"definition "partial_order_on A r ≡ preorder_on A r ∧ antisym r"definition "linear_order_on A r ≡ partial_order_on A r ∧ total_on A r"definition "strict_linear_order_on A r ≡ trans r ∧ irrefl r ∧ total_on A r"definition "well_order_on A r ≡ linear_order_on A r ∧ wf(r - Id)"lemmas order_on_defs =  preorder_on_def partial_order_on_def linear_order_on_def  strict_linear_order_on_def well_order_on_deflemma preorder_on_empty[simp]: "preorder_on {} {}"by(simp add:preorder_on_def trans_def)lemma partial_order_on_empty[simp]: "partial_order_on {} {}"by(simp add:partial_order_on_def)lemma lnear_order_on_empty[simp]: "linear_order_on {} {}"by(simp add:linear_order_on_def)lemma well_order_on_empty[simp]: "well_order_on {} {}"by(simp add:well_order_on_def)lemma preorder_on_converse[simp]: "preorder_on A (r^-1) = preorder_on A r"by (simp add:preorder_on_def)lemma partial_order_on_converse[simp]:  "partial_order_on A (r^-1) = partial_order_on A r"by (simp add: partial_order_on_def)lemma linear_order_on_converse[simp]:  "linear_order_on A (r^-1) = linear_order_on A r"by (simp add: linear_order_on_def)lemma strict_linear_order_on_diff_Id:  "linear_order_on A r ==> strict_linear_order_on A (r-Id)"by(simp add: order_on_defs trans_diff_Id)subsection{* Orders on the field *}abbreviation "Refl r ≡ refl_on (Field r) r"abbreviation "Preorder r ≡ preorder_on (Field r) r"abbreviation "Partial_order r ≡ partial_order_on (Field r) r"abbreviation "Total r ≡ total_on (Field r) r"abbreviation "Linear_order r ≡ linear_order_on (Field r) r"abbreviation "Well_order r ≡ well_order_on (Field r) r"lemma subset_Image_Image_iff:  "[| Preorder r; A ⊆ Field r; B ⊆ Field r|] ==>   r `` A ⊆ r `` B <-> (∀a∈A.∃b∈B. (b,a):r)"unfolding preorder_on_def refl_on_def Image_defapply (simp add: subset_eq)unfolding trans_def by fastlemma subset_Image1_Image1_iff:  "[| Preorder r; a : Field r; b : Field r|] ==> r `` {a} ⊆ r `` {b} <-> (b,a):r"by(simp add:subset_Image_Image_iff)lemma Refl_antisym_eq_Image1_Image1_iff:  "[|Refl r; antisym r; a:Field r; b:Field r|] ==> r `` {a} = r `` {b} <-> a=b"by(simp add: set_eq_iff antisym_def refl_on_def) metislemma Partial_order_eq_Image1_Image1_iff:  "[|Partial_order r; a:Field r; b:Field r|] ==> r `` {a} = r `` {b} <-> a=b"by(auto simp:order_on_defs Refl_antisym_eq_Image1_Image1_iff)lemma Total_Id_Field:assumes TOT: "Total r" and NID: "¬ (r <= Id)"shows "Field r = Field(r - Id)"using mono_Field[of "r - Id" r] Diff_subset[of r Id]proof(auto)  have "r ≠ {}" using NID by fast  then obtain b and c where "b ≠ c ∧ (b,c) ∈ r" using NID by fast  hence 1: "b ≠ c ∧ {b,c} ≤ Field r" by (auto simp: Field_def)  (*  *)  fix a assume *: "a ∈ Field r"  obtain d where 2: "d ∈ Field r" and 3: "d ≠ a"  using * 1 by auto  hence "(a,d) ∈ r ∨ (d,a) ∈ r" using * TOT  by (simp add: total_on_def)  thus "a ∈ Field(r - Id)" using 3 unfolding Field_def by blastqedsubsection{* Orders on a type *}abbreviation "strict_linear_order ≡ strict_linear_order_on UNIV"abbreviation "linear_order ≡ linear_order_on UNIV"abbreviation "well_order r ≡ well_order_on UNIV"end`