
haftmann@28685: (*  Title:      HOL/Orderings.thy
nipkow@15524:     Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
nipkow@15524: *)
nipkow@15524: 
haftmann@25614: header {* Abstract orderings *}
nipkow@15524: 
nipkow@15524: theory Orderings
haftmann@35301: imports HOL
wenzelm@32215: uses
wenzelm@32215:   "~~/src/Provers/order.ML"
wenzelm@32215:   "~~/src/Provers/quasi.ML"  (* FIXME unused? *)
nipkow@15524: begin
nipkow@15524: 
haftmann@35092: subsection {* Syntactic orders *}
haftmann@35092: 
haftmann@35092: class ord =
haftmann@35092:   fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
haftmann@35092:     and less :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
haftmann@35092: begin
haftmann@35092: 
haftmann@35092: notation
haftmann@35092:   less_eq  ("op <=") and
haftmann@35092:   less_eq  ("(_/ <= _)" [51, 51] 50) and
haftmann@35092:   less  ("op <") and
haftmann@35092:   less  ("(_/ < _)"  [51, 51] 50)
haftmann@35092:   
haftmann@35092: notation (xsymbols)
haftmann@35092:   less_eq  ("op \<le>") and
haftmann@35092:   less_eq  ("(_/ \<le> _)"  [51, 51] 50)
haftmann@35092: 
haftmann@35092: notation (HTML output)
haftmann@35092:   less_eq  ("op \<le>") and
haftmann@35092:   less_eq  ("(_/ \<le> _)"  [51, 51] 50)
haftmann@35092: 
haftmann@35092: abbreviation (input)
haftmann@35092:   greater_eq  (infix ">=" 50) where
haftmann@35092:   "x >= y \<equiv> y <= x"
haftmann@35092: 
haftmann@35092: notation (input)
haftmann@35092:   greater_eq  (infix "\<ge>" 50)
haftmann@35092: 
haftmann@35092: abbreviation (input)
haftmann@35092:   greater  (infix ">" 50) where
haftmann@35092:   "x > y \<equiv> y < x"
haftmann@35092: 
haftmann@35092: end
haftmann@35092: 
haftmann@35092: 
haftmann@27682: subsection {* Quasi orders *}
nipkow@15524: 
haftmann@27682: class preorder = ord +
haftmann@27682:   assumes less_le_not_le: "x < y \<longleftrightarrow> x \<le> y \<and> \<not> (y \<le> x)"
haftmann@25062:   and order_refl [iff]: "x \<le> x"
haftmann@25062:   and order_trans: "x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z"
haftmann@21248: begin
haftmann@21248: 
nipkow@15524: text {* Reflexivity. *}
nipkow@15524: 
haftmann@25062: lemma eq_refl: "x = y \<Longrightarrow> x \<le> y"
nipkow@15524:     -- {* This form is useful with the classical reasoner. *}
nipkow@23212: by (erule ssubst) (rule order_refl)
nipkow@15524: 
haftmann@25062: lemma less_irrefl [iff]: "\<not> x < x"
haftmann@27682: by (simp add: less_le_not_le)
haftmann@27682: 
haftmann@27682: lemma less_imp_le: "x < y \<Longrightarrow> x \<le> y"
haftmann@27682: unfolding less_le_not_le by blast
haftmann@27682: 
haftmann@27682: 
haftmann@27682: text {* Asymmetry. *}
haftmann@27682: 
haftmann@27682: lemma less_not_sym: "x < y \<Longrightarrow> \<not> (y < x)"
haftmann@27682: by (simp add: less_le_not_le)
haftmann@27682: 
haftmann@27682: lemma less_asym: "x < y \<Longrightarrow> (\<not> P \<Longrightarrow> y < x) \<Longrightarrow> P"
haftmann@27682: by (drule less_not_sym, erule contrapos_np) simp
haftmann@27682: 
haftmann@27682: 
haftmann@27682: text {* Transitivity. *}
haftmann@27682: 
haftmann@27682: lemma less_trans: "x < y \<Longrightarrow> y < z \<Longrightarrow> x < z"
haftmann@27682: by (auto simp add: less_le_not_le intro: order_trans) 
haftmann@27682: 
haftmann@27682: lemma le_less_trans: "x \<le> y \<Longrightarrow> y < z \<Longrightarrow> x < z"
haftmann@27682: by (auto simp add: less_le_not_le intro: order_trans) 
haftmann@27682: 
haftmann@27682: lemma less_le_trans: "x < y \<Longrightarrow> y \<le> z \<Longrightarrow> x < z"
haftmann@27682: by (auto simp add: less_le_not_le intro: order_trans) 
haftmann@27682: 
haftmann@27682: 
haftmann@27682: text {* Useful for simplification, but too risky to include by default. *}
haftmann@27682: 
haftmann@27682: lemma less_imp_not_less: "x < y \<Longrightarrow> (\<not> y < x) \<longleftrightarrow> True"
haftmann@27682: by (blast elim: less_asym)
haftmann@27682: 
haftmann@27682: lemma less_imp_triv: "x < y \<Longrightarrow> (y < x \<longrightarrow> P) \<longleftrightarrow> True"
haftmann@27682: by (blast elim: less_asym)
haftmann@27682: 
haftmann@27682: 
haftmann@27682: text {* Transitivity rules for calculational reasoning *}
haftmann@27682: 
haftmann@27682: lemma less_asym': "a < b \<Longrightarrow> b < a \<Longrightarrow> P"
haftmann@27682: by (rule less_asym)
haftmann@27682: 
haftmann@27682: 
haftmann@27682: text {* Dual order *}
haftmann@27682: 
haftmann@27682: lemma dual_preorder:
haftmann@27682:   "preorder (op \<ge>) (op >)"
haftmann@28823: proof qed (auto simp add: less_le_not_le intro: order_trans)
haftmann@27682: 
haftmann@27682: end
haftmann@27682: 
haftmann@27682: 
haftmann@27682: subsection {* Partial orders *}
haftmann@27682: 
haftmann@27682: class order = preorder +
haftmann@27682:   assumes antisym: "x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y"
haftmann@27682: begin
haftmann@27682: 
haftmann@27682: text {* Reflexivity. *}
haftmann@27682: 
haftmann@27682: lemma less_le: "x < y \<longleftrightarrow> x \<le> y \<and> x \<noteq> y"
haftmann@27682: by (auto simp add: less_le_not_le intro: antisym)
nipkow@15524: 
haftmann@25062: lemma le_less: "x \<le> y \<longleftrightarrow> x < y \<or> x = y"
nipkow@15524:     -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
nipkow@23212: by (simp add: less_le) blast
nipkow@15524: 
haftmann@25062: lemma le_imp_less_or_eq: "x \<le> y \<Longrightarrow> x < y \<or> x = y"
nipkow@23212: unfolding less_le by blast
nipkow@15524: 
haftmann@21329: 
haftmann@21329: text {* Useful for simplification, but too risky to include by default. *}
haftmann@21329: 
haftmann@25062: lemma less_imp_not_eq: "x < y \<Longrightarrow> (x = y) \<longleftrightarrow> False"
nipkow@23212: by auto
haftmann@21329: 
haftmann@25062: lemma less_imp_not_eq2: "x < y \<Longrightarrow> (y = x) \<longleftrightarrow> False"
nipkow@23212: by auto
haftmann@21329: 
haftmann@21329: 
haftmann@21329: text {* Transitivity rules for calculational reasoning *}
haftmann@21329: 
haftmann@25062: lemma neq_le_trans: "a \<noteq> b \<Longrightarrow> a \<le> b \<Longrightarrow> a < b"
nipkow@23212: by (simp add: less_le)
haftmann@21329: 
haftmann@25062: lemma le_neq_trans: "a \<le> b \<Longrightarrow> a \<noteq> b \<Longrightarrow> a < b"
nipkow@23212: by (simp add: less_le)
haftmann@21329: 
nipkow@15524: 
nipkow@15524: text {* Asymmetry. *}
nipkow@15524: 
haftmann@25062: lemma eq_iff: "x = y \<longleftrightarrow> x \<le> y \<and> y \<le> x"
nipkow@23212: by (blast intro: antisym)
nipkow@15524: 
haftmann@25062: lemma antisym_conv: "y \<le> x \<Longrightarrow> x \<le> y \<longleftrightarrow> x = y"
nipkow@23212: by (blast intro: antisym)
nipkow@15524: 
haftmann@25062: lemma less_imp_neq: "x < y \<Longrightarrow> x \<noteq> y"
nipkow@23212: by (erule contrapos_pn, erule subst, rule less_irrefl)
haftmann@21248: 
haftmann@21083: 
haftmann@27107: text {* Least value operator *}
haftmann@27107: 
haftmann@27299: definition (in ord)
haftmann@27107:   Least :: "('a \<Rightarrow> bool) \<Rightarrow> 'a" (binder "LEAST " 10) where
haftmann@27107:   "Least P = (THE x. P x \<and> (\<forall>y. P y \<longrightarrow> x \<le> y))"
haftmann@27107: 
haftmann@27107: lemma Least_equality:
haftmann@27107:   assumes "P x"
haftmann@27107:     and "\<And>y. P y \<Longrightarrow> x \<le> y"
haftmann@27107:   shows "Least P = x"
haftmann@27107: unfolding Least_def by (rule the_equality)
haftmann@27107:   (blast intro: assms antisym)+
haftmann@27107: 
haftmann@27107: lemma LeastI2_order:
haftmann@27107:   assumes "P x"
haftmann@27107:     and "\<And>y. P y \<Longrightarrow> x \<le> y"
haftmann@27107:     and "\<And>x. P x \<Longrightarrow> \<forall>y. P y \<longrightarrow> x \<le> y \<Longrightarrow> Q x"
haftmann@27107:   shows "Q (Least P)"
haftmann@27107: unfolding Least_def by (rule theI2)
haftmann@27107:   (blast intro: assms antisym)+
haftmann@27107: 
haftmann@27107: 
haftmann@26014: text {* Dual order *}
haftmann@22916: 
haftmann@26014: lemma dual_order:
haftmann@25103:   "order (op \<ge>) (op >)"
haftmann@27682: by (intro_locales, rule dual_preorder) (unfold_locales, rule antisym)
haftmann@22916: 
haftmann@21248: end
nipkow@15524: 
haftmann@21329: 
haftmann@21329: subsection {* Linear (total) orders *}
haftmann@21329: 
haftmann@22316: class linorder = order +
haftmann@25207:   assumes linear: "x \<le> y \<or> y \<le> x"
haftmann@21248: begin
haftmann@21248: 
haftmann@25062: lemma less_linear: "x < y \<or> x = y \<or> y < x"
nipkow@23212: unfolding less_le using less_le linear by blast
haftmann@21248: 
haftmann@25062: lemma le_less_linear: "x \<le> y \<or> y < x"
nipkow@23212: by (simp add: le_less less_linear)
haftmann@21248: 
haftmann@21248: lemma le_cases [case_names le ge]:
haftmann@25062:   "(x \<le> y \<Longrightarrow> P) \<Longrightarrow> (y \<le> x \<Longrightarrow> P) \<Longrightarrow> P"
nipkow@23212: using linear by blast
haftmann@21248: 
haftmann@22384: lemma linorder_cases [case_names less equal greater]:
haftmann@25062:   "(x < y \<Longrightarrow> P) \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> (y < x \<Longrightarrow> P) \<Longrightarrow> P"
nipkow@23212: using less_linear by blast
haftmann@21248: 
haftmann@25062: lemma not_less: "\<not> x < y \<longleftrightarrow> y \<le> x"
nipkow@23212: apply (simp add: less_le)
nipkow@23212: using linear apply (blast intro: antisym)
nipkow@23212: done
nipkow@23212: 
nipkow@23212: lemma not_less_iff_gr_or_eq:
haftmann@25062:  "\<not>(x < y) \<longleftrightarrow> (x > y | x = y)"
nipkow@23212: apply(simp add:not_less le_less)
nipkow@23212: apply blast
nipkow@23212: done
nipkow@15524: 
haftmann@25062: lemma not_le: "\<not> x \<le> y \<longleftrightarrow> y < x"
nipkow@23212: apply (simp add: less_le)
nipkow@23212: using linear apply (blast intro: antisym)
nipkow@23212: done
nipkow@15524: 
haftmann@25062: lemma neq_iff: "x \<noteq> y \<longleftrightarrow> x < y \<or> y < x"
nipkow@23212: by (cut_tac x = x and y = y in less_linear, auto)
nipkow@15524: 
haftmann@25062: lemma neqE: "x \<noteq> y \<Longrightarrow> (x < y \<Longrightarrow> R) \<Longrightarrow> (y < x \<Longrightarrow> R) \<Longrightarrow> R"
nipkow@23212: by (simp add: neq_iff) blast
nipkow@15524: 
haftmann@25062: lemma antisym_conv1: "\<not> x < y \<Longrightarrow> x \<le> y \<longleftrightarrow> x = y"
nipkow@23212: by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524: 
haftmann@25062: lemma antisym_conv2: "x \<le> y \<Longrightarrow> \<not> x < y \<longleftrightarrow> x = y"
nipkow@23212: by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524: 
haftmann@25062: lemma antisym_conv3: "\<not> y < x \<Longrightarrow> \<not> x < y \<longleftrightarrow> x = y"
nipkow@23212: by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524: 
haftmann@25062: lemma leI: "\<not> x < y \<Longrightarrow> y \<le> x"
nipkow@23212: unfolding not_less .
paulson@16796: 
haftmann@25062: lemma leD: "y \<le> x \<Longrightarrow> \<not> x < y"
nipkow@23212: unfolding not_less .
paulson@16796: 
paulson@16796: (*FIXME inappropriate name (or delete altogether)*)
haftmann@25062: lemma not_leE: "\<not> y \<le> x \<Longrightarrow> x < y"
nipkow@23212: unfolding not_le .
haftmann@21248: 
haftmann@22916: 
haftmann@26014: text {* Dual order *}
haftmann@22916: 
haftmann@26014: lemma dual_linorder:
haftmann@25103:   "linorder (op \<ge>) (op >)"
haftmann@27682: by (rule linorder.intro, rule dual_order) (unfold_locales, rule linear)
haftmann@22916: 
haftmann@22916: 
haftmann@23881: text {* min/max *}
haftmann@23881: 
haftmann@27299: definition (in ord) min :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where
haftmann@28516:   [code del]: "min a b = (if a \<le> b then a else b)"
haftmann@23881: 
haftmann@27299: definition (in ord) max :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where
haftmann@28516:   [code del]: "max a b = (if a \<le> b then b else a)"
haftmann@22384: 
haftmann@21383: lemma min_le_iff_disj:
haftmann@25062:   "min x y \<le> z \<longleftrightarrow> x \<le> z \<or> y \<le> z"
nipkow@23212: unfolding min_def using linear by (auto intro: order_trans)
haftmann@21383: 
haftmann@21383: lemma le_max_iff_disj:
haftmann@25062:   "z \<le> max x y \<longleftrightarrow> z \<le> x \<or> z \<le> y"
nipkow@23212: unfolding max_def using linear by (auto intro: order_trans)
haftmann@21383: 
haftmann@21383: lemma min_less_iff_disj:
haftmann@25062:   "min x y < z \<longleftrightarrow> x < z \<or> y < z"
nipkow@23212: unfolding min_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383: 
haftmann@21383: lemma less_max_iff_disj:
haftmann@25062:   "z < max x y \<longleftrightarrow> z < x \<or> z < y"
nipkow@23212: unfolding max_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383: 
haftmann@21383: lemma min_less_iff_conj [simp]:
haftmann@25062:   "z < min x y \<longleftrightarrow> z < x \<and> z < y"
nipkow@23212: unfolding min_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383: 
haftmann@21383: lemma max_less_iff_conj [simp]:
haftmann@25062:   "max x y < z \<longleftrightarrow> x < z \<and> y < z"
nipkow@23212: unfolding max_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383: 
paulson@24286: lemma split_min [noatp]:
haftmann@25062:   "P (min i j) \<longleftrightarrow> (i \<le> j \<longrightarrow> P i) \<and> (\<not> i \<le> j \<longrightarrow> P j)"
nipkow@23212: by (simp add: min_def)
haftmann@21383: 
paulson@24286: lemma split_max [noatp]:
haftmann@25062:   "P (max i j) \<longleftrightarrow> (i \<le> j \<longrightarrow> P j) \<and> (\<not> i \<le> j \<longrightarrow> P i)"
nipkow@23212: by (simp add: max_def)
haftmann@21383: 
haftmann@21248: end
haftmann@21248: 
haftmann@28516: text {* Explicit dictionaries for code generation *}
haftmann@28516: 
haftmann@31998: lemma min_ord_min [code, code_unfold, code_inline del]:
haftmann@28516:   "min = ord.min (op \<le>)"
haftmann@28516:   by (rule ext)+ (simp add: min_def ord.min_def)
haftmann@28516: 
haftmann@28516: declare ord.min_def [code]
haftmann@28516: 
haftmann@31998: lemma max_ord_max [code, code_unfold, code_inline del]:
haftmann@28516:   "max = ord.max (op \<le>)"
haftmann@28516:   by (rule ext)+ (simp add: max_def ord.max_def)
haftmann@28516: 
haftmann@28516: declare ord.max_def [code]
haftmann@28516: 
haftmann@23948: 
haftmann@21083: subsection {* Reasoning tools setup *}
haftmann@21083: 
haftmann@21091: ML {*
haftmann@21091: 
ballarin@24641: signature ORDERS =
ballarin@24641: sig
ballarin@24641:   val print_structures: Proof.context -> unit
ballarin@24641:   val setup: theory -> theory
wenzelm@32215:   val order_tac: Proof.context -> thm list -> int -> tactic
ballarin@24641: end;
haftmann@21091: 
ballarin@24641: structure Orders: ORDERS =
haftmann@21248: struct
ballarin@24641: 
ballarin@24641: (** Theory and context data **)
ballarin@24641: 
ballarin@24641: fun struct_eq ((s1: string, ts1), (s2, ts2)) =
ballarin@24641:   (s1 = s2) andalso eq_list (op aconv) (ts1, ts2);
ballarin@24641: 
wenzelm@33519: structure Data = Generic_Data
ballarin@24641: (
ballarin@24641:   type T = ((string * term list) * Order_Tac.less_arith) list;
ballarin@24641:     (* Order structures:
ballarin@24641:        identifier of the structure, list of operations and record of theorems
ballarin@24641:        needed to set up the transitivity reasoner,
ballarin@24641:        identifier and operations identify the structure uniquely. *)
ballarin@24641:   val empty = [];
ballarin@24641:   val extend = I;
wenzelm@33519:   fun merge data = AList.join struct_eq (K fst) data;
ballarin@24641: );
ballarin@24641: 
ballarin@24641: fun print_structures ctxt =
ballarin@24641:   let
ballarin@24641:     val structs = Data.get (Context.Proof ctxt);
ballarin@24641:     fun pretty_term t = Pretty.block
wenzelm@24920:       [Pretty.quote (Syntax.pretty_term ctxt t), Pretty.brk 1,
ballarin@24641:         Pretty.str "::", Pretty.brk 1,
wenzelm@24920:         Pretty.quote (Syntax.pretty_typ ctxt (type_of t))];
ballarin@24641:     fun pretty_struct ((s, ts), _) = Pretty.block
ballarin@24641:       [Pretty.str s, Pretty.str ":", Pretty.brk 1,
ballarin@24641:        Pretty.enclose "(" ")" (Pretty.breaks (map pretty_term ts))];
ballarin@24641:   in
ballarin@24641:     Pretty.writeln (Pretty.big_list "Order structures:" (map pretty_struct structs))
ballarin@24641:   end;
ballarin@24641: 
ballarin@24641: 
ballarin@24641: (** Method **)
haftmann@21091: 
wenzelm@32215: fun struct_tac ((s, [eq, le, less]), thms) ctxt prems =
ballarin@24641:   let
berghofe@30107:     fun decomp thy (@{const Trueprop} $ t) =
ballarin@24641:       let
ballarin@24641:         fun excluded t =
ballarin@24641:           (* exclude numeric types: linear arithmetic subsumes transitivity *)
ballarin@24641:           let val T = type_of t
ballarin@24641:           in
wenzelm@32960:             T = HOLogic.natT orelse T = HOLogic.intT orelse T = HOLogic.realT
ballarin@24641:           end;
wenzelm@32960:         fun rel (bin_op $ t1 $ t2) =
ballarin@24641:               if excluded t1 then NONE
ballarin@24641:               else if Pattern.matches thy (eq, bin_op) then SOME (t1, "=", t2)
ballarin@24641:               else if Pattern.matches thy (le, bin_op) then SOME (t1, "<=", t2)
ballarin@24641:               else if Pattern.matches thy (less, bin_op) then SOME (t1, "<", t2)
ballarin@24641:               else NONE
wenzelm@32960:           | rel _ = NONE;
wenzelm@32960:         fun dec (Const (@{const_name Not}, _) $ t) = (case rel t
wenzelm@32960:               of NONE => NONE
wenzelm@32960:                | SOME (t1, rel, t2) => SOME (t1, "~" ^ rel, t2))
ballarin@24741:           | dec x = rel x;
berghofe@30107:       in dec t end
berghofe@30107:       | decomp thy _ = NONE;
ballarin@24641:   in
ballarin@24641:     case s of
wenzelm@32215:       "order" => Order_Tac.partial_tac decomp thms ctxt prems
wenzelm@32215:     | "linorder" => Order_Tac.linear_tac decomp thms ctxt prems
ballarin@24641:     | _ => error ("Unknown kind of order `" ^ s ^ "' encountered in transitivity reasoner.")
ballarin@24641:   end
ballarin@24641: 
wenzelm@32215: fun order_tac ctxt prems =
wenzelm@32215:   FIRST' (map (fn s => CHANGED o struct_tac s ctxt prems) (Data.get (Context.Proof ctxt)));
ballarin@24641: 
ballarin@24641: 
ballarin@24641: (** Attribute **)
ballarin@24641: 
ballarin@24641: fun add_struct_thm s tag =
ballarin@24641:   Thm.declaration_attribute
ballarin@24641:     (fn thm => Data.map (AList.map_default struct_eq (s, Order_Tac.empty TrueI) (Order_Tac.update tag thm)));
ballarin@24641: fun del_struct s =
ballarin@24641:   Thm.declaration_attribute
ballarin@24641:     (fn _ => Data.map (AList.delete struct_eq s));
ballarin@24641: 
wenzelm@30722: val attrib_setup =
wenzelm@30722:   Attrib.setup @{binding order}
wenzelm@30722:     (Scan.lift ((Args.add -- Args.name >> (fn (_, s) => SOME s) || Args.del >> K NONE) --|
wenzelm@30722:       Args.colon (* FIXME || Scan.succeed true *) ) -- Scan.lift Args.name --
wenzelm@30722:       Scan.repeat Args.term
wenzelm@30722:       >> (fn ((SOME tag, n), ts) => add_struct_thm (n, ts) tag
wenzelm@30722:            | ((NONE, n), ts) => del_struct (n, ts)))
wenzelm@30722:     "theorems controlling transitivity reasoner";
ballarin@24641: 
ballarin@24641: 
ballarin@24641: (** Diagnostic command **)
ballarin@24641: 
wenzelm@24867: val _ =
ballarin@24641:   OuterSyntax.improper_command "print_orders"
ballarin@24641:     "print order structures available to transitivity reasoner" OuterKeyword.diag
wenzelm@30806:     (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_context o
wenzelm@30806:         Toplevel.keep (print_structures o Toplevel.context_of)));
ballarin@24641: 
ballarin@24641: 
ballarin@24641: (** Setup **)
ballarin@24641: 
wenzelm@24867: val setup =
wenzelm@32215:   Method.setup @{binding order} (Scan.succeed (fn ctxt => SIMPLE_METHOD' (order_tac ctxt [])))
wenzelm@30722:     "transitivity reasoner" #>
wenzelm@30722:   attrib_setup;
haftmann@21091: 
haftmann@21091: end;
ballarin@24641: 
haftmann@21091: *}
haftmann@21091: 
ballarin@24641: setup Orders.setup
ballarin@24641: 
ballarin@24641: 
ballarin@24641: text {* Declarations to set up transitivity reasoner of partial and linear orders. *}
ballarin@24641: 
haftmann@25076: context order
haftmann@25076: begin
haftmann@25076: 
ballarin@24641: (* The type constraint on @{term op =} below is necessary since the operation
ballarin@24641:    is not a parameter of the locale. *)
haftmann@25076: 
haftmann@27689: declare less_irrefl [THEN notE, order add less_reflE: order "op = :: 'a \<Rightarrow> 'a \<Rightarrow> bool" "op <=" "op <"]
haftmann@27689:   
haftmann@27689: declare order_refl  [order add le_refl: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689:   
haftmann@27689: declare less_imp_le [order add less_imp_le: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689:   
haftmann@27689: declare antisym [order add eqI: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare eq_refl [order add eqD1: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare sym [THEN eq_refl, order add eqD2: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare less_trans [order add less_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689:   
haftmann@27689: declare less_le_trans [order add less_le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689:   
haftmann@27689: declare le_less_trans [order add le_less_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare order_trans [order add le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare le_neq_trans [order add le_neq_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare neq_le_trans [order add neq_le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare less_imp_neq [order add less_imp_neq: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare eq_neq_eq_imp_neq [order add eq_neq_eq_imp_neq: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare not_sym [order add not_sym: order "op = :: 'a => 'a => bool" "op <=" "op <"]
ballarin@24641: 
haftmann@25076: end
haftmann@25076: 
haftmann@25076: context linorder
haftmann@25076: begin
ballarin@24641: 
haftmann@27689: declare [[order del: order "op = :: 'a => 'a => bool" "op <=" "op <"]]
haftmann@27689: 
haftmann@27689: declare less_irrefl [THEN notE, order add less_reflE: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare order_refl [order add le_refl: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare less_imp_le [order add less_imp_le: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare not_less [THEN iffD2, order add not_lessI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare not_le [THEN iffD2, order add not_leI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare not_less [THEN iffD1, order add not_lessD: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare not_le [THEN iffD1, order add not_leD: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare antisym [order add eqI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare eq_refl [order add eqD1: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@25076: 
haftmann@27689: declare sym [THEN eq_refl, order add eqD2: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare less_trans [order add less_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare less_le_trans [order add less_le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare le_less_trans [order add le_less_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare order_trans [order add le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare le_neq_trans [order add le_neq_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare neq_le_trans [order add neq_le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare less_imp_neq [order add less_imp_neq: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare eq_neq_eq_imp_neq [order add eq_neq_eq_imp_neq: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689: 
haftmann@27689: declare not_sym [order add not_sym: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
ballarin@24641: 
haftmann@25076: end
haftmann@25076: 
ballarin@24641: 
haftmann@21083: setup {*
haftmann@21083: let
haftmann@21083: 
haftmann@21083: fun prp t thm = (#prop (rep_thm thm) = t);
nipkow@15524: 
haftmann@21083: fun prove_antisym_le sg ss ((le as Const(_,T)) $ r $ s) =
haftmann@21083:   let val prems = prems_of_ss ss;
haftmann@22916:       val less = Const (@{const_name less}, T);
haftmann@21083:       val t = HOLogic.mk_Trueprop(le $ s $ r);
haftmann@21083:   in case find_first (prp t) prems of
haftmann@21083:        NONE =>
haftmann@21083:          let val t = HOLogic.mk_Trueprop(HOLogic.Not $ (less $ r $ s))
haftmann@21083:          in case find_first (prp t) prems of
haftmann@21083:               NONE => NONE
haftmann@24422:             | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv1}))
haftmann@21083:          end
haftmann@24422:      | SOME thm => SOME(mk_meta_eq(thm RS @{thm order_class.antisym_conv}))
haftmann@21083:   end
haftmann@21083:   handle THM _ => NONE;
nipkow@15524: 
haftmann@21083: fun prove_antisym_less sg ss (NotC $ ((less as Const(_,T)) $ r $ s)) =
haftmann@21083:   let val prems = prems_of_ss ss;
haftmann@22916:       val le = Const (@{const_name less_eq}, T);
haftmann@21083:       val t = HOLogic.mk_Trueprop(le $ r $ s);
haftmann@21083:   in case find_first (prp t) prems of
haftmann@21083:        NONE =>
haftmann@21083:          let val t = HOLogic.mk_Trueprop(NotC $ (less $ s $ r))
haftmann@21083:          in case find_first (prp t) prems of
haftmann@21083:               NONE => NONE
haftmann@24422:             | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv3}))
haftmann@21083:          end
haftmann@24422:      | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv2}))
haftmann@21083:   end
haftmann@21083:   handle THM _ => NONE;
nipkow@15524: 
haftmann@21248: fun add_simprocs procs thy =
wenzelm@26496:   Simplifier.map_simpset (fn ss => ss
haftmann@21248:     addsimprocs (map (fn (name, raw_ts, proc) =>
wenzelm@26496:       Simplifier.simproc thy name raw_ts proc) procs)) thy;
wenzelm@26496: fun add_solver name tac =
wenzelm@26496:   Simplifier.map_simpset (fn ss => ss addSolver
wenzelm@32215:     mk_solver' name (fn ss => tac (Simplifier.the_context ss) (Simplifier.prems_of_ss ss)));
haftmann@21083: 
haftmann@21083: in
haftmann@21248:   add_simprocs [
haftmann@21248:        ("antisym le", ["(x::'a::order) <= y"], prove_antisym_le),
haftmann@21248:        ("antisym less", ["~ (x::'a::linorder) < y"], prove_antisym_less)
haftmann@21248:      ]
ballarin@24641:   #> add_solver "Transitivity" Orders.order_tac
haftmann@21248:   (* Adding the transitivity reasoners also as safe solvers showed a slight
haftmann@21248:      speed up, but the reasoning strength appears to be not higher (at least
haftmann@21248:      no breaking of additional proofs in the entire HOL distribution, as
haftmann@21248:      of 5 March 2004, was observed). *)
haftmann@21083: end
haftmann@21083: *}
nipkow@15524: 
nipkow@15524: 
haftmann@21083: subsection {* Bounded quantifiers *}
haftmann@21083: 
haftmann@21083: syntax
wenzelm@21180:   "_All_less" :: "[idt, 'a, bool] => bool"    ("(3ALL _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3EX _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _<=_./ _)" [0, 0, 10] 10)
wenzelm@21180:   "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _<=_./ _)" [0, 0, 10] 10)
haftmann@21083: 
wenzelm@21180:   "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3ALL _>_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3EX _>_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _>=_./ _)" [0, 0, 10] 10)
wenzelm@21180:   "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _>=_./ _)" [0, 0, 10] 10)
haftmann@21083: 
haftmann@21083: syntax (xsymbols)
wenzelm@21180:   "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@21180:   "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083: 
wenzelm@21180:   "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
wenzelm@21180:   "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083: 
haftmann@21083: syntax (HOL)
wenzelm@21180:   "_All_less" :: "[idt, 'a, bool] => bool"    ("(3! _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3? _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3! _<=_./ _)" [0, 0, 10] 10)
wenzelm@21180:   "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3? _<=_./ _)" [0, 0, 10] 10)
haftmann@21083: 
haftmann@21083: syntax (HTML output)
wenzelm@21180:   "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@21180:   "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083: 
wenzelm@21180:   "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180:   "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
wenzelm@21180:   "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083: 
haftmann@21083: translations
haftmann@21083:   "ALL x<y. P"   =>  "ALL x. x < y \<longrightarrow> P"
haftmann@21083:   "EX x<y. P"    =>  "EX x. x < y \<and> P"
haftmann@21083:   "ALL x<=y. P"  =>  "ALL x. x <= y \<longrightarrow> P"
haftmann@21083:   "EX x<=y. P"   =>  "EX x. x <= y \<and> P"
haftmann@21083:   "ALL x>y. P"   =>  "ALL x. x > y \<longrightarrow> P"
haftmann@21083:   "EX x>y. P"    =>  "EX x. x > y \<and> P"
haftmann@21083:   "ALL x>=y. P"  =>  "ALL x. x >= y \<longrightarrow> P"
haftmann@21083:   "EX x>=y. P"   =>  "EX x. x >= y \<and> P"
haftmann@21083: 
haftmann@21083: print_translation {*
haftmann@21083: let
haftmann@22916:   val All_binder = Syntax.binder_name @{const_syntax All};
haftmann@22916:   val Ex_binder = Syntax.binder_name @{const_syntax Ex};
wenzelm@22377:   val impl = @{const_syntax "op -->"};
wenzelm@22377:   val conj = @{const_syntax "op &"};
haftmann@22916:   val less = @{const_syntax less};
haftmann@22916:   val less_eq = @{const_syntax less_eq};
wenzelm@21180: 
wenzelm@21180:   val trans =
wenzelm@35115:    [((All_binder, impl, less),
wenzelm@35115:     (@{syntax_const "_All_less"}, @{syntax_const "_All_greater"})),
wenzelm@35115:     ((All_binder, impl, less_eq),
wenzelm@35115:     (@{syntax_const "_All_less_eq"}, @{syntax_const "_All_greater_eq"})),
wenzelm@35115:     ((Ex_binder, conj, less),
wenzelm@35115:     (@{syntax_const "_Ex_less"}, @{syntax_const "_Ex_greater"})),
wenzelm@35115:     ((Ex_binder, conj, less_eq),
wenzelm@35115:     (@{syntax_const "_Ex_less_eq"}, @{syntax_const "_Ex_greater_eq"}))];
wenzelm@21180: 
wenzelm@35115:   fun matches_bound v t =
wenzelm@35115:     (case t of
wenzelm@35364:       Const (@{syntax_const "_bound"}, _) $ Free (v', _) => v = v'
wenzelm@35115:     | _ => false);
wenzelm@35115:   fun contains_var v = Term.exists_subterm (fn Free (x, _) => x = v | _ => false);
wenzelm@35115:   fun mk v c n P = Syntax.const c $ Syntax.mark_bound v $ n $ P;
wenzelm@21180: 
wenzelm@21180:   fun tr' q = (q,
wenzelm@35364:     fn [Const (@{syntax_const "_bound"}, _) $ Free (v, _),
wenzelm@35364:         Const (c, _) $ (Const (d, _) $ t $ u) $ P] =>
wenzelm@35115:         (case AList.lookup (op =) trans (q, c, d) of
wenzelm@35115:           NONE => raise Match
wenzelm@35115:         | SOME (l, g) =>
wenzelm@35115:             if matches_bound v t andalso not (contains_var v u) then mk v l u P
wenzelm@35115:             else if matches_bound v u andalso not (contains_var v t) then mk v g t P
wenzelm@35115:             else raise Match)
wenzelm@21180:      | _ => raise Match);
wenzelm@21524: in [tr' All_binder, tr' Ex_binder] end
haftmann@21083: *}
haftmann@21083: 
haftmann@21083: 
haftmann@21383: subsection {* Transitivity reasoning *}
haftmann@21383: 
haftmann@25193: context ord
haftmann@25193: begin
haftmann@21383: 
haftmann@25193: lemma ord_le_eq_trans: "a \<le> b \<Longrightarrow> b = c \<Longrightarrow> a \<le> c"
haftmann@25193:   by (rule subst)
haftmann@21383: 
haftmann@25193: lemma ord_eq_le_trans: "a = b \<Longrightarrow> b \<le> c \<Longrightarrow> a \<le> c"
haftmann@25193:   by (rule ssubst)
haftmann@21383: 
haftmann@25193: lemma ord_less_eq_trans: "a < b \<Longrightarrow> b = c \<Longrightarrow> a < c"
haftmann@25193:   by (rule subst)
haftmann@25193: 
haftmann@25193: lemma ord_eq_less_trans: "a = b \<Longrightarrow> b < c \<Longrightarrow> a < c"
haftmann@25193:   by (rule ssubst)
haftmann@25193: 
haftmann@25193: end
haftmann@21383: 
haftmann@21383: lemma order_less_subst2: "(a::'a::order) < b ==> f b < (c::'c::order) ==>
haftmann@21383:   (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383:   assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383:   also assume "f b < c"
haftmann@34250:   finally (less_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: lemma order_less_subst1: "(a::'a::order) < f b ==> (b::'b::order) < c ==>
haftmann@21383:   (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383:   assume "a < f b"
haftmann@21383:   also assume "b < c" hence "f b < f c" by (rule r)
haftmann@34250:   finally (less_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: lemma order_le_less_subst2: "(a::'a::order) <= b ==> f b < (c::'c::order) ==>
haftmann@21383:   (!!x y. x <= y ==> f x <= f y) ==> f a < c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383:   assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383:   also assume "f b < c"
haftmann@34250:   finally (le_less_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: lemma order_le_less_subst1: "(a::'a::order) <= f b ==> (b::'b::order) < c ==>
haftmann@21383:   (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383:   assume "a <= f b"
haftmann@21383:   also assume "b < c" hence "f b < f c" by (rule r)
haftmann@34250:   finally (le_less_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: lemma order_less_le_subst2: "(a::'a::order) < b ==> f b <= (c::'c::order) ==>
haftmann@21383:   (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383:   assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383:   also assume "f b <= c"
haftmann@34250:   finally (less_le_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: lemma order_less_le_subst1: "(a::'a::order) < f b ==> (b::'b::order) <= c ==>
haftmann@21383:   (!!x y. x <= y ==> f x <= f y) ==> a < f c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383:   assume "a < f b"
haftmann@21383:   also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@34250:   finally (less_le_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: lemma order_subst1: "(a::'a::order) <= f b ==> (b::'b::order) <= c ==>
haftmann@21383:   (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383:   assume "a <= f b"
haftmann@21383:   also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@21383:   finally (order_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: lemma order_subst2: "(a::'a::order) <= b ==> f b <= (c::'c::order) ==>
haftmann@21383:   (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383:   assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383:   also assume "f b <= c"
haftmann@21383:   finally (order_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: lemma ord_le_eq_subst: "a <= b ==> f b = c ==>
haftmann@21383:   (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383:   assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383:   also assume "f b = c"
haftmann@21383:   finally (ord_le_eq_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: lemma ord_eq_le_subst: "a = f b ==> b <= c ==>
haftmann@21383:   (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383:   assume "a = f b"
haftmann@21383:   also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@21383:   finally (ord_eq_le_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: lemma ord_less_eq_subst: "a < b ==> f b = c ==>
haftmann@21383:   (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383:   assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383:   also assume "f b = c"
haftmann@21383:   finally (ord_less_eq_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: lemma ord_eq_less_subst: "a = f b ==> b < c ==>
haftmann@21383:   (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383: proof -
haftmann@21383:   assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383:   assume "a = f b"
haftmann@21383:   also assume "b < c" hence "f b < f c" by (rule r)
haftmann@21383:   finally (ord_eq_less_trans) show ?thesis .
haftmann@21383: qed
haftmann@21383: 
haftmann@21383: text {*
haftmann@21383:   Note that this list of rules is in reverse order of priorities.
haftmann@21383: *}
haftmann@21383: 
haftmann@27682: lemmas [trans] =
haftmann@21383:   order_less_subst2
haftmann@21383:   order_less_subst1
haftmann@21383:   order_le_less_subst2
haftmann@21383:   order_le_less_subst1
haftmann@21383:   order_less_le_subst2
haftmann@21383:   order_less_le_subst1
haftmann@21383:   order_subst2
haftmann@21383:   order_subst1
haftmann@21383:   ord_le_eq_subst
haftmann@21383:   ord_eq_le_subst
haftmann@21383:   ord_less_eq_subst
haftmann@21383:   ord_eq_less_subst
haftmann@21383:   forw_subst
haftmann@21383:   back_subst
haftmann@21383:   rev_mp
haftmann@21383:   mp
haftmann@27682: 
haftmann@27682: lemmas (in order) [trans] =
haftmann@27682:   neq_le_trans
haftmann@27682:   le_neq_trans
haftmann@27682: 
haftmann@27682: lemmas (in preorder) [trans] =
haftmann@27682:   less_trans
haftmann@27682:   less_asym'
haftmann@27682:   le_less_trans
haftmann@27682:   less_le_trans
haftmann@21383:   order_trans
haftmann@27682: 
haftmann@27682: lemmas (in order) [trans] =
haftmann@27682:   antisym
haftmann@27682: 
haftmann@27682: lemmas (in ord) [trans] =
haftmann@27682:   ord_le_eq_trans
haftmann@27682:   ord_eq_le_trans
haftmann@27682:   ord_less_eq_trans
haftmann@27682:   ord_eq_less_trans
haftmann@27682: 
haftmann@27682: lemmas [trans] =
haftmann@27682:   trans
haftmann@27682: 
haftmann@27682: lemmas order_trans_rules =
haftmann@27682:   order_less_subst2
haftmann@27682:   order_less_subst1
haftmann@27682:   order_le_less_subst2
haftmann@27682:   order_le_less_subst1
haftmann@27682:   order_less_le_subst2
haftmann@27682:   order_less_le_subst1
haftmann@27682:   order_subst2
haftmann@27682:   order_subst1
haftmann@27682:   ord_le_eq_subst
haftmann@27682:   ord_eq_le_subst
haftmann@27682:   ord_less_eq_subst
haftmann@27682:   ord_eq_less_subst
haftmann@27682:   forw_subst
haftmann@27682:   back_subst
haftmann@27682:   rev_mp
haftmann@27682:   mp
haftmann@27682:   neq_le_trans
haftmann@27682:   le_neq_trans
haftmann@27682:   less_trans
haftmann@27682:   less_asym'
haftmann@27682:   le_less_trans
haftmann@27682:   less_le_trans
haftmann@27682:   order_trans
haftmann@27682:   antisym
haftmann@21383:   ord_le_eq_trans
haftmann@21383:   ord_eq_le_trans
haftmann@21383:   ord_less_eq_trans
haftmann@21383:   ord_eq_less_trans
haftmann@21383:   trans
haftmann@21383: 
haftmann@21083: text {* These support proving chains of decreasing inequalities
haftmann@21083:     a >= b >= c ... in Isar proofs. *}
haftmann@21083: 
haftmann@21083: lemma xt1:
haftmann@21083:   "a = b ==> b > c ==> a > c"
haftmann@21083:   "a > b ==> b = c ==> a > c"
haftmann@21083:   "a = b ==> b >= c ==> a >= c"
haftmann@21083:   "a >= b ==> b = c ==> a >= c"
haftmann@21083:   "(x::'a::order) >= y ==> y >= x ==> x = y"
haftmann@21083:   "(x::'a::order) >= y ==> y >= z ==> x >= z"
haftmann@21083:   "(x::'a::order) > y ==> y >= z ==> x > z"
haftmann@21083:   "(x::'a::order) >= y ==> y > z ==> x > z"
wenzelm@23417:   "(a::'a::order) > b ==> b > a ==> P"
haftmann@21083:   "(x::'a::order) > y ==> y > z ==> x > z"
haftmann@21083:   "(a::'a::order) >= b ==> a ~= b ==> a > b"
haftmann@21083:   "(a::'a::order) ~= b ==> a >= b ==> a > b"
haftmann@21083:   "a = f b ==> b > c ==> (!!x y. x > y ==> f x > f y) ==> a > f c" 
haftmann@21083:   "a > b ==> f b = c ==> (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083:   "a = f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
haftmann@21083:   "a >= b ==> f b = c ==> (!! x y. x >= y ==> f x >= f y) ==> f a >= c"
haftmann@25076:   by auto
haftmann@21083: 
haftmann@21083: lemma xt2:
haftmann@21083:   "(a::'a::order) >= f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
haftmann@21083: by (subgoal_tac "f b >= f c", force, force)
haftmann@21083: 
haftmann@21083: lemma xt3: "(a::'a::order) >= b ==> (f b::'b::order) >= c ==> 
haftmann@21083:     (!!x y. x >= y ==> f x >= f y) ==> f a >= c"
haftmann@21083: by (subgoal_tac "f a >= f b", force, force)
haftmann@21083: 
haftmann@21083: lemma xt4: "(a::'a::order) > f b ==> (b::'b::order) >= c ==>
haftmann@21083:   (!!x y. x >= y ==> f x >= f y) ==> a > f c"
haftmann@21083: by (subgoal_tac "f b >= f c", force, force)
haftmann@21083: 
haftmann@21083: lemma xt5: "(a::'a::order) > b ==> (f b::'b::order) >= c==>
haftmann@21083:     (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083: by (subgoal_tac "f a > f b", force, force)
haftmann@21083: 
haftmann@21083: lemma xt6: "(a::'a::order) >= f b ==> b > c ==>
haftmann@21083:     (!!x y. x > y ==> f x > f y) ==> a > f c"
haftmann@21083: by (subgoal_tac "f b > f c", force, force)
haftmann@21083: 
haftmann@21083: lemma xt7: "(a::'a::order) >= b ==> (f b::'b::order) > c ==>
haftmann@21083:     (!!x y. x >= y ==> f x >= f y) ==> f a > c"
haftmann@21083: by (subgoal_tac "f a >= f b", force, force)
haftmann@21083: 
haftmann@21083: lemma xt8: "(a::'a::order) > f b ==> (b::'b::order) > c ==>
haftmann@21083:     (!!x y. x > y ==> f x > f y) ==> a > f c"
haftmann@21083: by (subgoal_tac "f b > f c", force, force)
haftmann@21083: 
haftmann@21083: lemma xt9: "(a::'a::order) > b ==> (f b::'b::order) > c ==>
haftmann@21083:     (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083: by (subgoal_tac "f a > f b", force, force)
haftmann@21083: 
haftmann@21083: lemmas xtrans = xt1 xt2 xt3 xt4 xt5 xt6 xt7 xt8 xt9
haftmann@21083: 
haftmann@21083: (* 
haftmann@21083:   Since "a >= b" abbreviates "b <= a", the abbreviation "..." stands
haftmann@21083:   for the wrong thing in an Isar proof.
haftmann@21083: 
haftmann@21083:   The extra transitivity rules can be used as follows: 
haftmann@21083: 
haftmann@21083: lemma "(a::'a::order) > z"
haftmann@21083: proof -
haftmann@21083:   have "a >= b" (is "_ >= ?rhs")
haftmann@21083:     sorry
haftmann@21083:   also have "?rhs >= c" (is "_ >= ?rhs")
haftmann@21083:     sorry
haftmann@21083:   also (xtrans) have "?rhs = d" (is "_ = ?rhs")
haftmann@21083:     sorry
haftmann@21083:   also (xtrans) have "?rhs >= e" (is "_ >= ?rhs")
haftmann@21083:     sorry
haftmann@21083:   also (xtrans) have "?rhs > f" (is "_ > ?rhs")
haftmann@21083:     sorry
haftmann@21083:   also (xtrans) have "?rhs > z"
haftmann@21083:     sorry
haftmann@21083:   finally (xtrans) show ?thesis .
haftmann@21083: qed
haftmann@21083: 
haftmann@21083:   Alternatively, one can use "declare xtrans [trans]" and then
haftmann@21083:   leave out the "(xtrans)" above.
haftmann@21083: *)
haftmann@21083: 
haftmann@23881: 
haftmann@23881: subsection {* Monotonicity, least value operator and min/max *}
haftmann@21083: 
haftmann@25076: context order
haftmann@25076: begin
haftmann@25076: 
haftmann@30298: definition mono :: "('a \<Rightarrow> 'b\<Colon>order) \<Rightarrow> bool" where
haftmann@25076:   "mono f \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> f x \<le> f y)"
haftmann@25076: 
haftmann@25076: lemma monoI [intro?]:
haftmann@25076:   fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
haftmann@25076:   shows "(\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y) \<Longrightarrow> mono f"
haftmann@25076:   unfolding mono_def by iprover
haftmann@21216: 
haftmann@25076: lemma monoD [dest?]:
haftmann@25076:   fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
haftmann@25076:   shows "mono f \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
haftmann@25076:   unfolding mono_def by iprover
haftmann@25076: 
haftmann@30298: definition strict_mono :: "('a \<Rightarrow> 'b\<Colon>order) \<Rightarrow> bool" where
haftmann@30298:   "strict_mono f \<longleftrightarrow> (\<forall>x y. x < y \<longrightarrow> f x < f y)"
haftmann@30298: 
haftmann@30298: lemma strict_monoI [intro?]:
haftmann@30298:   assumes "\<And>x y. x < y \<Longrightarrow> f x < f y"
haftmann@30298:   shows "strict_mono f"
haftmann@30298:   using assms unfolding strict_mono_def by auto
haftmann@30298: 
haftmann@30298: lemma strict_monoD [dest?]:
haftmann@30298:   "strict_mono f \<Longrightarrow> x < y \<Longrightarrow> f x < f y"
haftmann@30298:   unfolding strict_mono_def by auto
haftmann@30298: 
haftmann@30298: lemma strict_mono_mono [dest?]:
haftmann@30298:   assumes "strict_mono f"
haftmann@30298:   shows "mono f"
haftmann@30298: proof (rule monoI)
haftmann@30298:   fix x y
haftmann@30298:   assume "x \<le> y"
haftmann@30298:   show "f x \<le> f y"
haftmann@30298:   proof (cases "x = y")
haftmann@30298:     case True then show ?thesis by simp
haftmann@30298:   next
haftmann@30298:     case False with `x \<le> y` have "x < y" by simp
haftmann@30298:     with assms strict_monoD have "f x < f y" by auto
haftmann@30298:     then show ?thesis by simp
haftmann@30298:   qed
haftmann@30298: qed
haftmann@30298: 
haftmann@25076: end
haftmann@25076: 
haftmann@25076: context linorder
haftmann@25076: begin
haftmann@25076: 
haftmann@30298: lemma strict_mono_eq:
haftmann@30298:   assumes "strict_mono f"
haftmann@30298:   shows "f x = f y \<longleftrightarrow> x = y"
haftmann@30298: proof
haftmann@30298:   assume "f x = f y"
haftmann@30298:   show "x = y" proof (cases x y rule: linorder_cases)
haftmann@30298:     case less with assms strict_monoD have "f x < f y" by auto
haftmann@30298:     with `f x = f y` show ?thesis by simp
haftmann@30298:   next
haftmann@30298:     case equal then show ?thesis .
haftmann@30298:   next
haftmann@30298:     case greater with assms strict_monoD have "f y < f x" by auto
haftmann@30298:     with `f x = f y` show ?thesis by simp
haftmann@30298:   qed
haftmann@30298: qed simp
haftmann@30298: 
haftmann@30298: lemma strict_mono_less_eq:
haftmann@30298:   assumes "strict_mono f"
haftmann@30298:   shows "f x \<le> f y \<longleftrightarrow> x \<le> y"
haftmann@30298: proof
haftmann@30298:   assume "x \<le> y"
haftmann@30298:   with assms strict_mono_mono monoD show "f x \<le> f y" by auto
haftmann@30298: next
haftmann@30298:   assume "f x \<le> f y"
haftmann@30298:   show "x \<le> y" proof (rule ccontr)
haftmann@30298:     assume "\<not> x \<le> y" then have "y < x" by simp
haftmann@30298:     with assms strict_monoD have "f y < f x" by auto
haftmann@30298:     with `f x \<le> f y` show False by simp
haftmann@30298:   qed
haftmann@30298: qed
haftmann@30298:   
haftmann@30298: lemma strict_mono_less:
haftmann@30298:   assumes "strict_mono f"
haftmann@30298:   shows "f x < f y \<longleftrightarrow> x < y"
haftmann@30298:   using assms
haftmann@30298:     by (auto simp add: less_le Orderings.less_le strict_mono_eq strict_mono_less_eq)
haftmann@30298: 
haftmann@25076: lemma min_of_mono:
haftmann@25076:   fixes f :: "'a \<Rightarrow> 'b\<Colon>linorder"
wenzelm@25377:   shows "mono f \<Longrightarrow> min (f m) (f n) = f (min m n)"
haftmann@25076:   by (auto simp: mono_def Orderings.min_def min_def intro: Orderings.antisym)
haftmann@25076: 
haftmann@25076: lemma max_of_mono:
haftmann@25076:   fixes f :: "'a \<Rightarrow> 'b\<Colon>linorder"
wenzelm@25377:   shows "mono f \<Longrightarrow> max (f m) (f n) = f (max m n)"
haftmann@25076:   by (auto simp: mono_def Orderings.max_def max_def intro: Orderings.antisym)
haftmann@25076: 
haftmann@25076: end
haftmann@21083: 
haftmann@21383: lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
nipkow@23212: by (simp add: min_def)
haftmann@21383: 
haftmann@21383: lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
nipkow@23212: by (simp add: max_def)
haftmann@21383: 
haftmann@21383: lemma min_leastR: "(\<And>x\<Colon>'a\<Colon>order. least \<le> x) \<Longrightarrow> min x least = least"
nipkow@23212: apply (simp add: min_def)
haftmann@34250: apply (blast intro: antisym)
nipkow@23212: done
haftmann@21383: 
haftmann@21383: lemma max_leastR: "(\<And>x\<Colon>'a\<Colon>order. least \<le> x) \<Longrightarrow> max x least = x"
nipkow@23212: apply (simp add: max_def)
haftmann@34250: apply (blast intro: antisym)
nipkow@23212: done
haftmann@21383: 
haftmann@27823: 
haftmann@28685: subsection {* Top and bottom elements *}
haftmann@28685: 
haftmann@28685: class top = preorder +
haftmann@28685:   fixes top :: 'a
haftmann@28685:   assumes top_greatest [simp]: "x \<le> top"
haftmann@28685: 
haftmann@28685: class bot = preorder +
haftmann@28685:   fixes bot :: 'a
haftmann@28685:   assumes bot_least [simp]: "bot \<le> x"
haftmann@28685: 
haftmann@28685: 
haftmann@27823: subsection {* Dense orders *}
haftmann@27823: 
haftmann@35028: class dense_linorder = linorder + 
haftmann@27823:   assumes gt_ex: "\<exists>y. x < y" 
haftmann@27823:   and lt_ex: "\<exists>y. y < x"
haftmann@27823:   and dense: "x < y \<Longrightarrow> (\<exists>z. x < z \<and> z < y)"
haftmann@27823: 
haftmann@27823: 
haftmann@27823: subsection {* Wellorders *}
haftmann@27823: 
haftmann@27823: class wellorder = linorder +
haftmann@27823:   assumes less_induct [case_names less]: "(\<And>x. (\<And>y. y < x \<Longrightarrow> P y) \<Longrightarrow> P x) \<Longrightarrow> P a"
haftmann@27823: begin
haftmann@27823: 
haftmann@27823: lemma wellorder_Least_lemma:
haftmann@27823:   fixes k :: 'a
haftmann@27823:   assumes "P k"
haftmann@34250:   shows LeastI: "P (LEAST x. P x)" and Least_le: "(LEAST x. P x) \<le> k"
haftmann@27823: proof -
haftmann@27823:   have "P (LEAST x. P x) \<and> (LEAST x. P x) \<le> k"
haftmann@27823:   using assms proof (induct k rule: less_induct)
haftmann@27823:     case (less x) then have "P x" by simp
haftmann@27823:     show ?case proof (rule classical)
haftmann@27823:       assume assm: "\<not> (P (LEAST a. P a) \<and> (LEAST a. P a) \<le> x)"
haftmann@27823:       have "\<And>y. P y \<Longrightarrow> x \<le> y"
haftmann@27823:       proof (rule classical)
haftmann@27823:         fix y
haftmann@27823:         assume "P y" and "\<not> x \<le> y" 
haftmann@27823:         with less have "P (LEAST a. P a)" and "(LEAST a. P a) \<le> y"
haftmann@27823:           by (auto simp add: not_le)
haftmann@27823:         with assm have "x < (LEAST a. P a)" and "(LEAST a. P a) \<le> y"
haftmann@27823:           by auto
haftmann@27823:         then show "x \<le> y" by auto
haftmann@27823:       qed
haftmann@27823:       with `P x` have Least: "(LEAST a. P a) = x"
haftmann@27823:         by (rule Least_equality)
haftmann@27823:       with `P x` show ?thesis by simp
haftmann@27823:     qed
haftmann@27823:   qed
haftmann@27823:   then show "P (LEAST x. P x)" and "(LEAST x. P x) \<le> k" by auto
haftmann@27823: qed
haftmann@27823: 
haftmann@27823: -- "The following 3 lemmas are due to Brian Huffman"
haftmann@27823: lemma LeastI_ex: "\<exists>x. P x \<Longrightarrow> P (Least P)"
haftmann@27823:   by (erule exE) (erule LeastI)
haftmann@27823: 
haftmann@27823: lemma LeastI2:
haftmann@27823:   "P a \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> Q (Least P)"
haftmann@27823:   by (blast intro: LeastI)
haftmann@27823: 
haftmann@27823: lemma LeastI2_ex:
haftmann@27823:   "\<exists>a. P a \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> Q (Least P)"
haftmann@27823:   by (blast intro: LeastI_ex)
haftmann@27823: 
haftmann@27823: lemma not_less_Least: "k < (LEAST x. P x) \<Longrightarrow> \<not> P k"
haftmann@27823: apply (simp (no_asm_use) add: not_le [symmetric])
haftmann@27823: apply (erule contrapos_nn)
haftmann@27823: apply (erule Least_le)
haftmann@27823: done
haftmann@27823: 
haftmann@27823: end  
haftmann@27823: 
haftmann@28685: 
haftmann@28685: subsection {* Order on bool *}
haftmann@28685: 
haftmann@28685: instantiation bool :: "{order, top, bot}"
haftmann@28685: begin
haftmann@28685: 
haftmann@28685: definition
haftmann@28685:   le_bool_def [code del]: "P \<le> Q \<longleftrightarrow> P \<longrightarrow> Q"
haftmann@28685: 
haftmann@28685: definition
haftmann@28685:   less_bool_def [code del]: "(P\<Colon>bool) < Q \<longleftrightarrow> \<not> P \<and> Q"
haftmann@28685: 
haftmann@28685: definition
haftmann@28685:   top_bool_eq: "top = True"
haftmann@28685: 
haftmann@28685: definition
haftmann@28685:   bot_bool_eq: "bot = False"
haftmann@28685: 
haftmann@28685: instance proof
haftmann@34250: qed (auto simp add: bot_bool_eq top_bool_eq less_bool_def, auto simp add: le_bool_def)
haftmann@28685: 
nipkow@15524: end
haftmann@28685: 
haftmann@28685: lemma le_boolI: "(P \<Longrightarrow> Q) \<Longrightarrow> P \<le> Q"
haftmann@32899:   by (simp add: le_bool_def)
haftmann@28685: 
haftmann@28685: lemma le_boolI': "P \<longrightarrow> Q \<Longrightarrow> P \<le> Q"
haftmann@32899:   by (simp add: le_bool_def)
haftmann@28685: 
haftmann@28685: lemma le_boolE: "P \<le> Q \<Longrightarrow> P \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
haftmann@32899:   by (simp add: le_bool_def)
haftmann@28685: 
haftmann@28685: lemma le_boolD: "P \<le> Q \<Longrightarrow> P \<longrightarrow> Q"
haftmann@32899:   by (simp add: le_bool_def)
haftmann@32899: 
haftmann@32899: lemma bot_boolE: "bot \<Longrightarrow> P"
haftmann@32899:   by (simp add: bot_bool_eq)
haftmann@32899: 
haftmann@32899: lemma top_boolI: top
haftmann@32899:   by (simp add: top_bool_eq)
haftmann@28685: 
haftmann@28685: lemma [code]:
haftmann@28685:   "False \<le> b \<longleftrightarrow> True"
haftmann@28685:   "True \<le> b \<longleftrightarrow> b"
haftmann@28685:   "False < b \<longleftrightarrow> b"
haftmann@28685:   "True < b \<longleftrightarrow> False"
haftmann@28685:   unfolding le_bool_def less_bool_def by simp_all
haftmann@28685: 
haftmann@28685: 
haftmann@28685: subsection {* Order on functions *}
haftmann@28685: 
haftmann@28685: instantiation "fun" :: (type, ord) ord
haftmann@28685: begin
haftmann@28685: 
haftmann@28685: definition
haftmann@28685:   le_fun_def [code del]: "f \<le> g \<longleftrightarrow> (\<forall>x. f x \<le> g x)"
haftmann@28685: 
haftmann@28685: definition
haftmann@28685:   less_fun_def [code del]: "(f\<Colon>'a \<Rightarrow> 'b) < g \<longleftrightarrow> f \<le> g \<and> \<not> (g \<le> f)"
haftmann@28685: 
haftmann@28685: instance ..
haftmann@28685: 
haftmann@28685: end
haftmann@28685: 
haftmann@28685: instance "fun" :: (type, preorder) preorder proof
haftmann@28685: qed (auto simp add: le_fun_def less_fun_def
haftmann@34250:   intro: order_trans antisym intro!: ext)
haftmann@28685: 
haftmann@28685: instance "fun" :: (type, order) order proof
haftmann@34250: qed (auto simp add: le_fun_def intro: antisym ext)
haftmann@28685: 
haftmann@28685: instantiation "fun" :: (type, top) top
haftmann@28685: begin
haftmann@28685: 
haftmann@28685: definition
haftmann@28685:   top_fun_eq: "top = (\<lambda>x. top)"
haftmann@28685: 
haftmann@28685: instance proof
haftmann@28685: qed (simp add: top_fun_eq le_fun_def)
haftmann@28685: 
haftmann@28685: end
haftmann@28685: 
haftmann@28685: instantiation "fun" :: (type, bot) bot
haftmann@28685: begin
haftmann@28685: 
haftmann@28685: definition
haftmann@28685:   bot_fun_eq: "bot = (\<lambda>x. bot)"
haftmann@28685: 
haftmann@28685: instance proof
haftmann@28685: qed (simp add: bot_fun_eq le_fun_def)
haftmann@28685: 
haftmann@28685: end
haftmann@28685: 
haftmann@28685: lemma le_funI: "(\<And>x. f x \<le> g x) \<Longrightarrow> f \<le> g"
haftmann@28685:   unfolding le_fun_def by simp
haftmann@28685: 
haftmann@28685: lemma le_funE: "f \<le> g \<Longrightarrow> (f x \<le> g x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@28685:   unfolding le_fun_def by simp
haftmann@28685: 
haftmann@28685: lemma le_funD: "f \<le> g \<Longrightarrow> f x \<le> g x"
haftmann@28685:   unfolding le_fun_def by simp
haftmann@28685: 
haftmann@34250: 
haftmann@34250: subsection {* Name duplicates *}
haftmann@34250: 
haftmann@34250: lemmas order_eq_refl = preorder_class.eq_refl
haftmann@34250: lemmas order_less_irrefl = preorder_class.less_irrefl
haftmann@34250: lemmas order_less_imp_le = preorder_class.less_imp_le
haftmann@34250: lemmas order_less_not_sym = preorder_class.less_not_sym
haftmann@34250: lemmas order_less_asym = preorder_class.less_asym
haftmann@34250: lemmas order_less_trans = preorder_class.less_trans
haftmann@34250: lemmas order_le_less_trans = preorder_class.le_less_trans
haftmann@34250: lemmas order_less_le_trans = preorder_class.less_le_trans
haftmann@34250: lemmas order_less_imp_not_less = preorder_class.less_imp_not_less
haftmann@34250: lemmas order_less_imp_triv = preorder_class.less_imp_triv
haftmann@34250: lemmas order_less_asym' = preorder_class.less_asym'
haftmann@34250: 
haftmann@34250: lemmas order_less_le = order_class.less_le
haftmann@34250: lemmas order_le_less = order_class.le_less
haftmann@34250: lemmas order_le_imp_less_or_eq = order_class.le_imp_less_or_eq
haftmann@34250: lemmas order_less_imp_not_eq = order_class.less_imp_not_eq
haftmann@34250: lemmas order_less_imp_not_eq2 = order_class.less_imp_not_eq2
haftmann@34250: lemmas order_neq_le_trans = order_class.neq_le_trans
haftmann@34250: lemmas order_le_neq_trans = order_class.le_neq_trans
haftmann@34250: lemmas order_antisym = order_class.antisym
haftmann@34250: lemmas order_eq_iff = order_class.eq_iff
haftmann@34250: lemmas order_antisym_conv = order_class.antisym_conv
haftmann@34250: 
haftmann@34250: lemmas linorder_linear = linorder_class.linear
haftmann@34250: lemmas linorder_less_linear = linorder_class.less_linear
haftmann@34250: lemmas linorder_le_less_linear = linorder_class.le_less_linear
haftmann@34250: lemmas linorder_le_cases = linorder_class.le_cases
haftmann@34250: lemmas linorder_not_less = linorder_class.not_less
haftmann@34250: lemmas linorder_not_le = linorder_class.not_le
haftmann@34250: lemmas linorder_neq_iff = linorder_class.neq_iff
haftmann@34250: lemmas linorder_neqE = linorder_class.neqE
haftmann@34250: lemmas linorder_antisym_conv1 = linorder_class.antisym_conv1
haftmann@34250: lemmas linorder_antisym_conv2 = linorder_class.antisym_conv2
haftmann@34250: lemmas linorder_antisym_conv3 = linorder_class.antisym_conv3
haftmann@34250: 
haftmann@28685: end




