src/HOL/Orderings.thy
author blanchet
Sun May 04 18:14:58 2014 +0200 (2014-05-04)
changeset 56846 9df717fef2bb
parent 56545 8f1e7596deb7
child 57447 87429bdecad5
permissions -rw-r--r--
renamed 'xxx_size' to 'size_xxx' for old datatype package
     1 (*  Title:      HOL/Orderings.thy
     2     Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
     3 *)
     4 
     5 header {* Abstract orderings *}
     6 
     7 theory Orderings
     8 imports HOL
     9 keywords "print_orders" :: diag
    10 begin
    11 
    12 ML_file "~~/src/Provers/order.ML"
    13 ML_file "~~/src/Provers/quasi.ML"  (* FIXME unused? *)
    14 
    15 subsection {* Abstract ordering *}
    16 
    17 locale ordering =
    18   fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<preceq>" 50)
    19    and less :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<prec>" 50)
    20   assumes strict_iff_order: "a \<prec> b \<longleftrightarrow> a \<preceq> b \<and> a \<noteq> b"
    21   assumes refl: "a \<preceq> a" -- {* not @{text iff}: makes problems due to multiple (dual) interpretations *}
    22     and antisym: "a \<preceq> b \<Longrightarrow> b \<preceq> a \<Longrightarrow> a = b"
    23     and trans: "a \<preceq> b \<Longrightarrow> b \<preceq> c \<Longrightarrow> a \<preceq> c"
    24 begin
    25 
    26 lemma strict_implies_order:
    27   "a \<prec> b \<Longrightarrow> a \<preceq> b"
    28   by (simp add: strict_iff_order)
    29 
    30 lemma strict_implies_not_eq:
    31   "a \<prec> b \<Longrightarrow> a \<noteq> b"
    32   by (simp add: strict_iff_order)
    33 
    34 lemma not_eq_order_implies_strict:
    35   "a \<noteq> b \<Longrightarrow> a \<preceq> b \<Longrightarrow> a \<prec> b"
    36   by (simp add: strict_iff_order)
    37 
    38 lemma order_iff_strict:
    39   "a \<preceq> b \<longleftrightarrow> a \<prec> b \<or> a = b"
    40   by (auto simp add: strict_iff_order refl)
    41 
    42 lemma irrefl: -- {* not @{text iff}: makes problems due to multiple (dual) interpretations *}
    43   "\<not> a \<prec> a"
    44   by (simp add: strict_iff_order)
    45 
    46 lemma asym:
    47   "a \<prec> b \<Longrightarrow> b \<prec> a \<Longrightarrow> False"
    48   by (auto simp add: strict_iff_order intro: antisym)
    49 
    50 lemma strict_trans1:
    51   "a \<preceq> b \<Longrightarrow> b \<prec> c \<Longrightarrow> a \<prec> c"
    52   by (auto simp add: strict_iff_order intro: trans antisym)
    53 
    54 lemma strict_trans2:
    55   "a \<prec> b \<Longrightarrow> b \<preceq> c \<Longrightarrow> a \<prec> c"
    56   by (auto simp add: strict_iff_order intro: trans antisym)
    57 
    58 lemma strict_trans:
    59   "a \<prec> b \<Longrightarrow> b \<prec> c \<Longrightarrow> a \<prec> c"
    60   by (auto intro: strict_trans1 strict_implies_order)
    61 
    62 end
    63 
    64 locale ordering_top = ordering +
    65   fixes top :: "'a"
    66   assumes extremum [simp]: "a \<preceq> top"
    67 begin
    68 
    69 lemma extremum_uniqueI:
    70   "top \<preceq> a \<Longrightarrow> a = top"
    71   by (rule antisym) auto
    72 
    73 lemma extremum_unique:
    74   "top \<preceq> a \<longleftrightarrow> a = top"
    75   by (auto intro: antisym)
    76 
    77 lemma extremum_strict [simp]:
    78   "\<not> (top \<prec> a)"
    79   using extremum [of a] by (auto simp add: order_iff_strict intro: asym irrefl)
    80 
    81 lemma not_eq_extremum:
    82   "a \<noteq> top \<longleftrightarrow> a \<prec> top"
    83   by (auto simp add: order_iff_strict intro: not_eq_order_implies_strict extremum)
    84 
    85 end  
    86 
    87 
    88 subsection {* Syntactic orders *}
    89 
    90 class ord =
    91   fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
    92     and less :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
    93 begin
    94 
    95 notation
    96   less_eq  ("op <=") and
    97   less_eq  ("(_/ <= _)" [51, 51] 50) and
    98   less  ("op <") and
    99   less  ("(_/ < _)"  [51, 51] 50)
   100   
   101 notation (xsymbols)
   102   less_eq  ("op \<le>") and
   103   less_eq  ("(_/ \<le> _)"  [51, 51] 50)
   104 
   105 notation (HTML output)
   106   less_eq  ("op \<le>") and
   107   less_eq  ("(_/ \<le> _)"  [51, 51] 50)
   108 
   109 abbreviation (input)
   110   greater_eq  (infix ">=" 50) where
   111   "x >= y \<equiv> y <= x"
   112 
   113 notation (input)
   114   greater_eq  (infix "\<ge>" 50)
   115 
   116 abbreviation (input)
   117   greater  (infix ">" 50) where
   118   "x > y \<equiv> y < x"
   119 
   120 end
   121 
   122 
   123 subsection {* Quasi orders *}
   124 
   125 class preorder = ord +
   126   assumes less_le_not_le: "x < y \<longleftrightarrow> x \<le> y \<and> \<not> (y \<le> x)"
   127   and order_refl [iff]: "x \<le> x"
   128   and order_trans: "x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z"
   129 begin
   130 
   131 text {* Reflexivity. *}
   132 
   133 lemma eq_refl: "x = y \<Longrightarrow> x \<le> y"
   134     -- {* This form is useful with the classical reasoner. *}
   135 by (erule ssubst) (rule order_refl)
   136 
   137 lemma less_irrefl [iff]: "\<not> x < x"
   138 by (simp add: less_le_not_le)
   139 
   140 lemma less_imp_le: "x < y \<Longrightarrow> x \<le> y"
   141 unfolding less_le_not_le by blast
   142 
   143 
   144 text {* Asymmetry. *}
   145 
   146 lemma less_not_sym: "x < y \<Longrightarrow> \<not> (y < x)"
   147 by (simp add: less_le_not_le)
   148 
   149 lemma less_asym: "x < y \<Longrightarrow> (\<not> P \<Longrightarrow> y < x) \<Longrightarrow> P"
   150 by (drule less_not_sym, erule contrapos_np) simp
   151 
   152 
   153 text {* Transitivity. *}
   154 
   155 lemma less_trans: "x < y \<Longrightarrow> y < z \<Longrightarrow> x < z"
   156 by (auto simp add: less_le_not_le intro: order_trans) 
   157 
   158 lemma le_less_trans: "x \<le> y \<Longrightarrow> y < z \<Longrightarrow> x < z"
   159 by (auto simp add: less_le_not_le intro: order_trans) 
   160 
   161 lemma less_le_trans: "x < y \<Longrightarrow> y \<le> z \<Longrightarrow> x < z"
   162 by (auto simp add: less_le_not_le intro: order_trans) 
   163 
   164 
   165 text {* Useful for simplification, but too risky to include by default. *}
   166 
   167 lemma less_imp_not_less: "x < y \<Longrightarrow> (\<not> y < x) \<longleftrightarrow> True"
   168 by (blast elim: less_asym)
   169 
   170 lemma less_imp_triv: "x < y \<Longrightarrow> (y < x \<longrightarrow> P) \<longleftrightarrow> True"
   171 by (blast elim: less_asym)
   172 
   173 
   174 text {* Transitivity rules for calculational reasoning *}
   175 
   176 lemma less_asym': "a < b \<Longrightarrow> b < a \<Longrightarrow> P"
   177 by (rule less_asym)
   178 
   179 
   180 text {* Dual order *}
   181 
   182 lemma dual_preorder:
   183   "class.preorder (op \<ge>) (op >)"
   184 proof qed (auto simp add: less_le_not_le intro: order_trans)
   185 
   186 end
   187 
   188 
   189 subsection {* Partial orders *}
   190 
   191 class order = preorder +
   192   assumes antisym: "x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y"
   193 begin
   194 
   195 lemma less_le: "x < y \<longleftrightarrow> x \<le> y \<and> x \<noteq> y"
   196   by (auto simp add: less_le_not_le intro: antisym)
   197 
   198 sublocale order!: ordering less_eq less +  dual_order!: ordering greater_eq greater
   199   by default (auto intro: antisym order_trans simp add: less_le)
   200 
   201 
   202 text {* Reflexivity. *}
   203 
   204 lemma le_less: "x \<le> y \<longleftrightarrow> x < y \<or> x = y"
   205     -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
   206 by (fact order.order_iff_strict)
   207 
   208 lemma le_imp_less_or_eq: "x \<le> y \<Longrightarrow> x < y \<or> x = y"
   209 unfolding less_le by blast
   210 
   211 
   212 text {* Useful for simplification, but too risky to include by default. *}
   213 
   214 lemma less_imp_not_eq: "x < y \<Longrightarrow> (x = y) \<longleftrightarrow> False"
   215 by auto
   216 
   217 lemma less_imp_not_eq2: "x < y \<Longrightarrow> (y = x) \<longleftrightarrow> False"
   218 by auto
   219 
   220 
   221 text {* Transitivity rules for calculational reasoning *}
   222 
   223 lemma neq_le_trans: "a \<noteq> b \<Longrightarrow> a \<le> b \<Longrightarrow> a < b"
   224 by (fact order.not_eq_order_implies_strict)
   225 
   226 lemma le_neq_trans: "a \<le> b \<Longrightarrow> a \<noteq> b \<Longrightarrow> a < b"
   227 by (rule order.not_eq_order_implies_strict)
   228 
   229 
   230 text {* Asymmetry. *}
   231 
   232 lemma eq_iff: "x = y \<longleftrightarrow> x \<le> y \<and> y \<le> x"
   233 by (blast intro: antisym)
   234 
   235 lemma antisym_conv: "y \<le> x \<Longrightarrow> x \<le> y \<longleftrightarrow> x = y"
   236 by (blast intro: antisym)
   237 
   238 lemma less_imp_neq: "x < y \<Longrightarrow> x \<noteq> y"
   239 by (fact order.strict_implies_not_eq)
   240 
   241 
   242 text {* Least value operator *}
   243 
   244 definition (in ord)
   245   Least :: "('a \<Rightarrow> bool) \<Rightarrow> 'a" (binder "LEAST " 10) where
   246   "Least P = (THE x. P x \<and> (\<forall>y. P y \<longrightarrow> x \<le> y))"
   247 
   248 lemma Least_equality:
   249   assumes "P x"
   250     and "\<And>y. P y \<Longrightarrow> x \<le> y"
   251   shows "Least P = x"
   252 unfolding Least_def by (rule the_equality)
   253   (blast intro: assms antisym)+
   254 
   255 lemma LeastI2_order:
   256   assumes "P x"
   257     and "\<And>y. P y \<Longrightarrow> x \<le> y"
   258     and "\<And>x. P x \<Longrightarrow> \<forall>y. P y \<longrightarrow> x \<le> y \<Longrightarrow> Q x"
   259   shows "Q (Least P)"
   260 unfolding Least_def by (rule theI2)
   261   (blast intro: assms antisym)+
   262 
   263 
   264 text {* Dual order *}
   265 
   266 lemma dual_order:
   267   "class.order (op \<ge>) (op >)"
   268 by (intro_locales, rule dual_preorder) (unfold_locales, rule antisym)
   269 
   270 end
   271 
   272 
   273 text {* Alternative introduction rule with bias towards strict order *}
   274 
   275 lemma order_strictI:
   276   fixes less (infix "\<sqsubset>" 50)
   277     and less_eq (infix "\<sqsubseteq>" 50)
   278   assumes less_eq_less: "\<And>a b. a \<sqsubseteq> b \<longleftrightarrow> a \<sqsubset> b \<or> a = b"
   279     assumes asym: "\<And>a b. a \<sqsubset> b \<Longrightarrow> \<not> b \<sqsubset> a"
   280   assumes irrefl: "\<And>a. \<not> a \<sqsubset> a"
   281   assumes trans: "\<And>a b c. a \<sqsubset> b \<Longrightarrow> b \<sqsubset> c \<Longrightarrow> a \<sqsubset> c"
   282   shows "class.order less_eq less"
   283 proof
   284   fix a b
   285   show "a \<sqsubset> b \<longleftrightarrow> a \<sqsubseteq> b \<and> \<not> b \<sqsubseteq> a"
   286     by (auto simp add: less_eq_less asym irrefl)
   287 next
   288   fix a
   289   show "a \<sqsubseteq> a"
   290     by (auto simp add: less_eq_less)
   291 next
   292   fix a b c
   293   assume "a \<sqsubseteq> b" and "b \<sqsubseteq> c" then show "a \<sqsubseteq> c"
   294     by (auto simp add: less_eq_less intro: trans)
   295 next
   296   fix a b
   297   assume "a \<sqsubseteq> b" and "b \<sqsubseteq> a" then show "a = b"
   298     by (auto simp add: less_eq_less asym)
   299 qed
   300 
   301 
   302 subsection {* Linear (total) orders *}
   303 
   304 class linorder = order +
   305   assumes linear: "x \<le> y \<or> y \<le> x"
   306 begin
   307 
   308 lemma less_linear: "x < y \<or> x = y \<or> y < x"
   309 unfolding less_le using less_le linear by blast
   310 
   311 lemma le_less_linear: "x \<le> y \<or> y < x"
   312 by (simp add: le_less less_linear)
   313 
   314 lemma le_cases [case_names le ge]:
   315   "(x \<le> y \<Longrightarrow> P) \<Longrightarrow> (y \<le> x \<Longrightarrow> P) \<Longrightarrow> P"
   316 using linear by blast
   317 
   318 lemma linorder_cases [case_names less equal greater]:
   319   "(x < y \<Longrightarrow> P) \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> (y < x \<Longrightarrow> P) \<Longrightarrow> P"
   320 using less_linear by blast
   321 
   322 lemma not_less: "\<not> x < y \<longleftrightarrow> y \<le> x"
   323 apply (simp add: less_le)
   324 using linear apply (blast intro: antisym)
   325 done
   326 
   327 lemma not_less_iff_gr_or_eq:
   328  "\<not>(x < y) \<longleftrightarrow> (x > y | x = y)"
   329 apply(simp add:not_less le_less)
   330 apply blast
   331 done
   332 
   333 lemma not_le: "\<not> x \<le> y \<longleftrightarrow> y < x"
   334 apply (simp add: less_le)
   335 using linear apply (blast intro: antisym)
   336 done
   337 
   338 lemma neq_iff: "x \<noteq> y \<longleftrightarrow> x < y \<or> y < x"
   339 by (cut_tac x = x and y = y in less_linear, auto)
   340 
   341 lemma neqE: "x \<noteq> y \<Longrightarrow> (x < y \<Longrightarrow> R) \<Longrightarrow> (y < x \<Longrightarrow> R) \<Longrightarrow> R"
   342 by (simp add: neq_iff) blast
   343 
   344 lemma antisym_conv1: "\<not> x < y \<Longrightarrow> x \<le> y \<longleftrightarrow> x = y"
   345 by (blast intro: antisym dest: not_less [THEN iffD1])
   346 
   347 lemma antisym_conv2: "x \<le> y \<Longrightarrow> \<not> x < y \<longleftrightarrow> x = y"
   348 by (blast intro: antisym dest: not_less [THEN iffD1])
   349 
   350 lemma antisym_conv3: "\<not> y < x \<Longrightarrow> \<not> x < y \<longleftrightarrow> x = y"
   351 by (blast intro: antisym dest: not_less [THEN iffD1])
   352 
   353 lemma leI: "\<not> x < y \<Longrightarrow> y \<le> x"
   354 unfolding not_less .
   355 
   356 lemma leD: "y \<le> x \<Longrightarrow> \<not> x < y"
   357 unfolding not_less .
   358 
   359 (*FIXME inappropriate name (or delete altogether)*)
   360 lemma not_leE: "\<not> y \<le> x \<Longrightarrow> x < y"
   361 unfolding not_le .
   362 
   363 
   364 text {* Dual order *}
   365 
   366 lemma dual_linorder:
   367   "class.linorder (op \<ge>) (op >)"
   368 by (rule class.linorder.intro, rule dual_order) (unfold_locales, rule linear)
   369 
   370 end
   371 
   372 
   373 text {* Alternative introduction rule with bias towards strict order *}
   374 
   375 lemma linorder_strictI:
   376   fixes less (infix "\<sqsubset>" 50)
   377     and less_eq (infix "\<sqsubseteq>" 50)
   378   assumes "class.order less_eq less"
   379   assumes trichotomy: "\<And>a b. a \<sqsubset> b \<or> a = b \<or> b \<sqsubset> a"
   380   shows "class.linorder less_eq less"
   381 proof -
   382   interpret order less_eq less
   383     by (fact `class.order less_eq less`)
   384   show ?thesis
   385   proof
   386     fix a b
   387     show "a \<sqsubseteq> b \<or> b \<sqsubseteq> a"
   388       using trichotomy by (auto simp add: le_less)
   389   qed
   390 qed
   391 
   392 
   393 subsection {* Reasoning tools setup *}
   394 
   395 ML {*
   396 signature ORDERS =
   397 sig
   398   val print_structures: Proof.context -> unit
   399   val order_tac: Proof.context -> thm list -> int -> tactic
   400 end;
   401 
   402 structure Orders: ORDERS =
   403 struct
   404 
   405 (* context data *)
   406 
   407 fun struct_eq ((s1: string, ts1), (s2, ts2)) =
   408   s1 = s2 andalso eq_list (op aconv) (ts1, ts2);
   409 
   410 structure Data = Generic_Data
   411 (
   412   type T = ((string * term list) * Order_Tac.less_arith) list;
   413     (* Order structures:
   414        identifier of the structure, list of operations and record of theorems
   415        needed to set up the transitivity reasoner,
   416        identifier and operations identify the structure uniquely. *)
   417   val empty = [];
   418   val extend = I;
   419   fun merge data = AList.join struct_eq (K fst) data;
   420 );
   421 
   422 fun print_structures ctxt =
   423   let
   424     val structs = Data.get (Context.Proof ctxt);
   425     fun pretty_term t = Pretty.block
   426       [Pretty.quote (Syntax.pretty_term ctxt t), Pretty.brk 1,
   427         Pretty.str "::", Pretty.brk 1,
   428         Pretty.quote (Syntax.pretty_typ ctxt (type_of t))];
   429     fun pretty_struct ((s, ts), _) = Pretty.block
   430       [Pretty.str s, Pretty.str ":", Pretty.brk 1,
   431        Pretty.enclose "(" ")" (Pretty.breaks (map pretty_term ts))];
   432   in
   433     Pretty.writeln (Pretty.big_list "order structures:" (map pretty_struct structs))
   434   end;
   435 
   436 val _ =
   437   Outer_Syntax.improper_command @{command_spec "print_orders"}
   438     "print order structures available to transitivity reasoner"
   439     (Scan.succeed (Toplevel.unknown_context o
   440       Toplevel.keep (print_structures o Toplevel.context_of)));
   441 
   442 
   443 (* tactics *)
   444 
   445 fun struct_tac ((s, ops), thms) ctxt facts =
   446   let
   447     val [eq, le, less] = ops;
   448     fun decomp thy (@{const Trueprop} $ t) =
   449           let
   450             fun excluded t =
   451               (* exclude numeric types: linear arithmetic subsumes transitivity *)
   452               let val T = type_of t
   453               in
   454                 T = HOLogic.natT orelse T = HOLogic.intT orelse T = HOLogic.realT
   455               end;
   456             fun rel (bin_op $ t1 $ t2) =
   457                   if excluded t1 then NONE
   458                   else if Pattern.matches thy (eq, bin_op) then SOME (t1, "=", t2)
   459                   else if Pattern.matches thy (le, bin_op) then SOME (t1, "<=", t2)
   460                   else if Pattern.matches thy (less, bin_op) then SOME (t1, "<", t2)
   461                   else NONE
   462               | rel _ = NONE;
   463             fun dec (Const (@{const_name Not}, _) $ t) =
   464                   (case rel t of NONE =>
   465                     NONE
   466                   | SOME (t1, rel, t2) => SOME (t1, "~" ^ rel, t2))
   467               | dec x = rel x;
   468           in dec t end
   469       | decomp _ _ = NONE;
   470   in
   471     (case s of
   472       "order" => Order_Tac.partial_tac decomp thms ctxt facts
   473     | "linorder" => Order_Tac.linear_tac decomp thms ctxt facts
   474     | _ => error ("Unknown order kind " ^ quote s ^ " encountered in transitivity reasoner"))
   475   end
   476 
   477 fun order_tac ctxt facts =
   478   FIRST' (map (fn s => CHANGED o struct_tac s ctxt facts) (Data.get (Context.Proof ctxt)));
   479 
   480 
   481 (* attributes *)
   482 
   483 fun add_struct_thm s tag =
   484   Thm.declaration_attribute
   485     (fn thm => Data.map (AList.map_default struct_eq (s, Order_Tac.empty TrueI) (Order_Tac.update tag thm)));
   486 fun del_struct s =
   487   Thm.declaration_attribute
   488     (fn _ => Data.map (AList.delete struct_eq s));
   489 
   490 val _ =
   491   Theory.setup
   492     (Attrib.setup @{binding order}
   493       (Scan.lift ((Args.add -- Args.name >> (fn (_, s) => SOME s) || Args.del >> K NONE) --|
   494         Args.colon (* FIXME || Scan.succeed true *) ) -- Scan.lift Args.name --
   495         Scan.repeat Args.term
   496         >> (fn ((SOME tag, n), ts) => add_struct_thm (n, ts) tag
   497              | ((NONE, n), ts) => del_struct (n, ts)))
   498       "theorems controlling transitivity reasoner");
   499 
   500 end;
   501 *}
   502 
   503 method_setup order = {*
   504   Scan.succeed (fn ctxt => SIMPLE_METHOD' (Orders.order_tac ctxt []))
   505 *} "transitivity reasoner"
   506 
   507 
   508 text {* Declarations to set up transitivity reasoner of partial and linear orders. *}
   509 
   510 context order
   511 begin
   512 
   513 (* The type constraint on @{term op =} below is necessary since the operation
   514    is not a parameter of the locale. *)
   515 
   516 declare less_irrefl [THEN notE, order add less_reflE: order "op = :: 'a \<Rightarrow> 'a \<Rightarrow> bool" "op <=" "op <"]
   517   
   518 declare order_refl  [order add le_refl: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   519   
   520 declare less_imp_le [order add less_imp_le: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   521   
   522 declare antisym [order add eqI: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   523 
   524 declare eq_refl [order add eqD1: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   525 
   526 declare sym [THEN eq_refl, order add eqD2: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   527 
   528 declare less_trans [order add less_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   529   
   530 declare less_le_trans [order add less_le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   531   
   532 declare le_less_trans [order add le_less_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   533 
   534 declare order_trans [order add le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   535 
   536 declare le_neq_trans [order add le_neq_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   537 
   538 declare neq_le_trans [order add neq_le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   539 
   540 declare less_imp_neq [order add less_imp_neq: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   541 
   542 declare eq_neq_eq_imp_neq [order add eq_neq_eq_imp_neq: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   543 
   544 declare not_sym [order add not_sym: order "op = :: 'a => 'a => bool" "op <=" "op <"]
   545 
   546 end
   547 
   548 context linorder
   549 begin
   550 
   551 declare [[order del: order "op = :: 'a => 'a => bool" "op <=" "op <"]]
   552 
   553 declare less_irrefl [THEN notE, order add less_reflE: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   554 
   555 declare order_refl [order add le_refl: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   556 
   557 declare less_imp_le [order add less_imp_le: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   558 
   559 declare not_less [THEN iffD2, order add not_lessI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   560 
   561 declare not_le [THEN iffD2, order add not_leI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   562 
   563 declare not_less [THEN iffD1, order add not_lessD: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   564 
   565 declare not_le [THEN iffD1, order add not_leD: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   566 
   567 declare antisym [order add eqI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   568 
   569 declare eq_refl [order add eqD1: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   570 
   571 declare sym [THEN eq_refl, order add eqD2: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   572 
   573 declare less_trans [order add less_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   574 
   575 declare less_le_trans [order add less_le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   576 
   577 declare le_less_trans [order add le_less_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   578 
   579 declare order_trans [order add le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   580 
   581 declare le_neq_trans [order add le_neq_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   582 
   583 declare neq_le_trans [order add neq_le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   584 
   585 declare less_imp_neq [order add less_imp_neq: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   586 
   587 declare eq_neq_eq_imp_neq [order add eq_neq_eq_imp_neq: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   588 
   589 declare not_sym [order add not_sym: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
   590 
   591 end
   592 
   593 setup {*
   594   map_theory_simpset (fn ctxt0 => ctxt0 addSolver
   595     mk_solver "Transitivity" (fn ctxt => Orders.order_tac ctxt (Simplifier.prems_of ctxt)))
   596   (*Adding the transitivity reasoners also as safe solvers showed a slight
   597     speed up, but the reasoning strength appears to be not higher (at least
   598     no breaking of additional proofs in the entire HOL distribution, as
   599     of 5 March 2004, was observed).*)
   600 *}
   601 
   602 ML {*
   603 local
   604   fun prp t thm = Thm.prop_of thm = t;  (* FIXME proper aconv!? *)
   605 in
   606 
   607 fun antisym_le_simproc ctxt ct =
   608   (case term_of ct of
   609     (le as Const (_, T)) $ r $ s =>
   610      (let
   611         val prems = Simplifier.prems_of ctxt;
   612         val less = Const (@{const_name less}, T);
   613         val t = HOLogic.mk_Trueprop(le $ s $ r);
   614       in
   615         (case find_first (prp t) prems of
   616           NONE =>
   617             let val t = HOLogic.mk_Trueprop(HOLogic.Not $ (less $ r $ s)) in
   618               (case find_first (prp t) prems of
   619                 NONE => NONE
   620               | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv1})))
   621              end
   622          | SOME thm => SOME (mk_meta_eq (thm RS @{thm order_class.antisym_conv})))
   623       end handle THM _ => NONE)
   624   | _ => NONE);
   625 
   626 fun antisym_less_simproc ctxt ct =
   627   (case term_of ct of
   628     NotC $ ((less as Const(_,T)) $ r $ s) =>
   629      (let
   630        val prems = Simplifier.prems_of ctxt;
   631        val le = Const (@{const_name less_eq}, T);
   632        val t = HOLogic.mk_Trueprop(le $ r $ s);
   633       in
   634         (case find_first (prp t) prems of
   635           NONE =>
   636             let val t = HOLogic.mk_Trueprop (NotC $ (less $ s $ r)) in
   637               (case find_first (prp t) prems of
   638                 NONE => NONE
   639               | SOME thm => SOME (mk_meta_eq(thm RS @{thm linorder_class.antisym_conv3})))
   640             end
   641         | SOME thm => SOME (mk_meta_eq (thm RS @{thm linorder_class.antisym_conv2})))
   642       end handle THM _ => NONE)
   643   | _ => NONE);
   644 
   645 end;
   646 *}
   647 
   648 simproc_setup antisym_le ("(x::'a::order) \<le> y") = "K antisym_le_simproc"
   649 simproc_setup antisym_less ("\<not> (x::'a::linorder) < y") = "K antisym_less_simproc"
   650 
   651 
   652 subsection {* Bounded quantifiers *}
   653 
   654 syntax
   655   "_All_less" :: "[idt, 'a, bool] => bool"    ("(3ALL _<_./ _)"  [0, 0, 10] 10)
   656   "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3EX _<_./ _)"  [0, 0, 10] 10)
   657   "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _<=_./ _)" [0, 0, 10] 10)
   658   "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _<=_./ _)" [0, 0, 10] 10)
   659 
   660   "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3ALL _>_./ _)"  [0, 0, 10] 10)
   661   "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3EX _>_./ _)"  [0, 0, 10] 10)
   662   "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _>=_./ _)" [0, 0, 10] 10)
   663   "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _>=_./ _)" [0, 0, 10] 10)
   664 
   665 syntax (xsymbols)
   666   "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
   667   "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
   668   "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
   669   "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
   670 
   671   "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
   672   "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
   673   "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
   674   "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
   675 
   676 syntax (HOL)
   677   "_All_less" :: "[idt, 'a, bool] => bool"    ("(3! _<_./ _)"  [0, 0, 10] 10)
   678   "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3? _<_./ _)"  [0, 0, 10] 10)
   679   "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3! _<=_./ _)" [0, 0, 10] 10)
   680   "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3? _<=_./ _)" [0, 0, 10] 10)
   681 
   682 syntax (HTML output)
   683   "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
   684   "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
   685   "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
   686   "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
   687 
   688   "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
   689   "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
   690   "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
   691   "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
   692 
   693 translations
   694   "ALL x<y. P"   =>  "ALL x. x < y \<longrightarrow> P"
   695   "EX x<y. P"    =>  "EX x. x < y \<and> P"
   696   "ALL x<=y. P"  =>  "ALL x. x <= y \<longrightarrow> P"
   697   "EX x<=y. P"   =>  "EX x. x <= y \<and> P"
   698   "ALL x>y. P"   =>  "ALL x. x > y \<longrightarrow> P"
   699   "EX x>y. P"    =>  "EX x. x > y \<and> P"
   700   "ALL x>=y. P"  =>  "ALL x. x >= y \<longrightarrow> P"
   701   "EX x>=y. P"   =>  "EX x. x >= y \<and> P"
   702 
   703 print_translation {*
   704 let
   705   val All_binder = Mixfix.binder_name @{const_syntax All};
   706   val Ex_binder = Mixfix.binder_name @{const_syntax Ex};
   707   val impl = @{const_syntax HOL.implies};
   708   val conj = @{const_syntax HOL.conj};
   709   val less = @{const_syntax less};
   710   val less_eq = @{const_syntax less_eq};
   711 
   712   val trans =
   713    [((All_binder, impl, less),
   714     (@{syntax_const "_All_less"}, @{syntax_const "_All_greater"})),
   715     ((All_binder, impl, less_eq),
   716     (@{syntax_const "_All_less_eq"}, @{syntax_const "_All_greater_eq"})),
   717     ((Ex_binder, conj, less),
   718     (@{syntax_const "_Ex_less"}, @{syntax_const "_Ex_greater"})),
   719     ((Ex_binder, conj, less_eq),
   720     (@{syntax_const "_Ex_less_eq"}, @{syntax_const "_Ex_greater_eq"}))];
   721 
   722   fun matches_bound v t =
   723     (case t of
   724       Const (@{syntax_const "_bound"}, _) $ Free (v', _) => v = v'
   725     | _ => false);
   726   fun contains_var v = Term.exists_subterm (fn Free (x, _) => x = v | _ => false);
   727   fun mk x c n P = Syntax.const c $ Syntax_Trans.mark_bound_body x $ n $ P;
   728 
   729   fun tr' q = (q, fn _ =>
   730     (fn [Const (@{syntax_const "_bound"}, _) $ Free (v, T),
   731         Const (c, _) $ (Const (d, _) $ t $ u) $ P] =>
   732         (case AList.lookup (op =) trans (q, c, d) of
   733           NONE => raise Match
   734         | SOME (l, g) =>
   735             if matches_bound v t andalso not (contains_var v u) then mk (v, T) l u P
   736             else if matches_bound v u andalso not (contains_var v t) then mk (v, T) g t P
   737             else raise Match)
   738       | _ => raise Match));
   739 in [tr' All_binder, tr' Ex_binder] end
   740 *}
   741 
   742 
   743 subsection {* Transitivity reasoning *}
   744 
   745 context ord
   746 begin
   747 
   748 lemma ord_le_eq_trans: "a \<le> b \<Longrightarrow> b = c \<Longrightarrow> a \<le> c"
   749   by (rule subst)
   750 
   751 lemma ord_eq_le_trans: "a = b \<Longrightarrow> b \<le> c \<Longrightarrow> a \<le> c"
   752   by (rule ssubst)
   753 
   754 lemma ord_less_eq_trans: "a < b \<Longrightarrow> b = c \<Longrightarrow> a < c"
   755   by (rule subst)
   756 
   757 lemma ord_eq_less_trans: "a = b \<Longrightarrow> b < c \<Longrightarrow> a < c"
   758   by (rule ssubst)
   759 
   760 end
   761 
   762 lemma order_less_subst2: "(a::'a::order) < b ==> f b < (c::'c::order) ==>
   763   (!!x y. x < y ==> f x < f y) ==> f a < c"
   764 proof -
   765   assume r: "!!x y. x < y ==> f x < f y"
   766   assume "a < b" hence "f a < f b" by (rule r)
   767   also assume "f b < c"
   768   finally (less_trans) show ?thesis .
   769 qed
   770 
   771 lemma order_less_subst1: "(a::'a::order) < f b ==> (b::'b::order) < c ==>
   772   (!!x y. x < y ==> f x < f y) ==> a < f c"
   773 proof -
   774   assume r: "!!x y. x < y ==> f x < f y"
   775   assume "a < f b"
   776   also assume "b < c" hence "f b < f c" by (rule r)
   777   finally (less_trans) show ?thesis .
   778 qed
   779 
   780 lemma order_le_less_subst2: "(a::'a::order) <= b ==> f b < (c::'c::order) ==>
   781   (!!x y. x <= y ==> f x <= f y) ==> f a < c"
   782 proof -
   783   assume r: "!!x y. x <= y ==> f x <= f y"
   784   assume "a <= b" hence "f a <= f b" by (rule r)
   785   also assume "f b < c"
   786   finally (le_less_trans) show ?thesis .
   787 qed
   788 
   789 lemma order_le_less_subst1: "(a::'a::order) <= f b ==> (b::'b::order) < c ==>
   790   (!!x y. x < y ==> f x < f y) ==> a < f c"
   791 proof -
   792   assume r: "!!x y. x < y ==> f x < f y"
   793   assume "a <= f b"
   794   also assume "b < c" hence "f b < f c" by (rule r)
   795   finally (le_less_trans) show ?thesis .
   796 qed
   797 
   798 lemma order_less_le_subst2: "(a::'a::order) < b ==> f b <= (c::'c::order) ==>
   799   (!!x y. x < y ==> f x < f y) ==> f a < c"
   800 proof -
   801   assume r: "!!x y. x < y ==> f x < f y"
   802   assume "a < b" hence "f a < f b" by (rule r)
   803   also assume "f b <= c"
   804   finally (less_le_trans) show ?thesis .
   805 qed
   806 
   807 lemma order_less_le_subst1: "(a::'a::order) < f b ==> (b::'b::order) <= c ==>
   808   (!!x y. x <= y ==> f x <= f y) ==> a < f c"
   809 proof -
   810   assume r: "!!x y. x <= y ==> f x <= f y"
   811   assume "a < f b"
   812   also assume "b <= c" hence "f b <= f c" by (rule r)
   813   finally (less_le_trans) show ?thesis .
   814 qed
   815 
   816 lemma order_subst1: "(a::'a::order) <= f b ==> (b::'b::order) <= c ==>
   817   (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
   818 proof -
   819   assume r: "!!x y. x <= y ==> f x <= f y"
   820   assume "a <= f b"
   821   also assume "b <= c" hence "f b <= f c" by (rule r)
   822   finally (order_trans) show ?thesis .
   823 qed
   824 
   825 lemma order_subst2: "(a::'a::order) <= b ==> f b <= (c::'c::order) ==>
   826   (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
   827 proof -
   828   assume r: "!!x y. x <= y ==> f x <= f y"
   829   assume "a <= b" hence "f a <= f b" by (rule r)
   830   also assume "f b <= c"
   831   finally (order_trans) show ?thesis .
   832 qed
   833 
   834 lemma ord_le_eq_subst: "a <= b ==> f b = c ==>
   835   (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
   836 proof -
   837   assume r: "!!x y. x <= y ==> f x <= f y"
   838   assume "a <= b" hence "f a <= f b" by (rule r)
   839   also assume "f b = c"
   840   finally (ord_le_eq_trans) show ?thesis .
   841 qed
   842 
   843 lemma ord_eq_le_subst: "a = f b ==> b <= c ==>
   844   (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
   845 proof -
   846   assume r: "!!x y. x <= y ==> f x <= f y"
   847   assume "a = f b"
   848   also assume "b <= c" hence "f b <= f c" by (rule r)
   849   finally (ord_eq_le_trans) show ?thesis .
   850 qed
   851 
   852 lemma ord_less_eq_subst: "a < b ==> f b = c ==>
   853   (!!x y. x < y ==> f x < f y) ==> f a < c"
   854 proof -
   855   assume r: "!!x y. x < y ==> f x < f y"
   856   assume "a < b" hence "f a < f b" by (rule r)
   857   also assume "f b = c"
   858   finally (ord_less_eq_trans) show ?thesis .
   859 qed
   860 
   861 lemma ord_eq_less_subst: "a = f b ==> b < c ==>
   862   (!!x y. x < y ==> f x < f y) ==> a < f c"
   863 proof -
   864   assume r: "!!x y. x < y ==> f x < f y"
   865   assume "a = f b"
   866   also assume "b < c" hence "f b < f c" by (rule r)
   867   finally (ord_eq_less_trans) show ?thesis .
   868 qed
   869 
   870 text {*
   871   Note that this list of rules is in reverse order of priorities.
   872 *}
   873 
   874 lemmas [trans] =
   875   order_less_subst2
   876   order_less_subst1
   877   order_le_less_subst2
   878   order_le_less_subst1
   879   order_less_le_subst2
   880   order_less_le_subst1
   881   order_subst2
   882   order_subst1
   883   ord_le_eq_subst
   884   ord_eq_le_subst
   885   ord_less_eq_subst
   886   ord_eq_less_subst
   887   forw_subst
   888   back_subst
   889   rev_mp
   890   mp
   891 
   892 lemmas (in order) [trans] =
   893   neq_le_trans
   894   le_neq_trans
   895 
   896 lemmas (in preorder) [trans] =
   897   less_trans
   898   less_asym'
   899   le_less_trans
   900   less_le_trans
   901   order_trans
   902 
   903 lemmas (in order) [trans] =
   904   antisym
   905 
   906 lemmas (in ord) [trans] =
   907   ord_le_eq_trans
   908   ord_eq_le_trans
   909   ord_less_eq_trans
   910   ord_eq_less_trans
   911 
   912 lemmas [trans] =
   913   trans
   914 
   915 lemmas order_trans_rules =
   916   order_less_subst2
   917   order_less_subst1
   918   order_le_less_subst2
   919   order_le_less_subst1
   920   order_less_le_subst2
   921   order_less_le_subst1
   922   order_subst2
   923   order_subst1
   924   ord_le_eq_subst
   925   ord_eq_le_subst
   926   ord_less_eq_subst
   927   ord_eq_less_subst
   928   forw_subst
   929   back_subst
   930   rev_mp
   931   mp
   932   neq_le_trans
   933   le_neq_trans
   934   less_trans
   935   less_asym'
   936   le_less_trans
   937   less_le_trans
   938   order_trans
   939   antisym
   940   ord_le_eq_trans
   941   ord_eq_le_trans
   942   ord_less_eq_trans
   943   ord_eq_less_trans
   944   trans
   945 
   946 text {* These support proving chains of decreasing inequalities
   947     a >= b >= c ... in Isar proofs. *}
   948 
   949 lemma xt1 [no_atp]:
   950   "a = b ==> b > c ==> a > c"
   951   "a > b ==> b = c ==> a > c"
   952   "a = b ==> b >= c ==> a >= c"
   953   "a >= b ==> b = c ==> a >= c"
   954   "(x::'a::order) >= y ==> y >= x ==> x = y"
   955   "(x::'a::order) >= y ==> y >= z ==> x >= z"
   956   "(x::'a::order) > y ==> y >= z ==> x > z"
   957   "(x::'a::order) >= y ==> y > z ==> x > z"
   958   "(a::'a::order) > b ==> b > a ==> P"
   959   "(x::'a::order) > y ==> y > z ==> x > z"
   960   "(a::'a::order) >= b ==> a ~= b ==> a > b"
   961   "(a::'a::order) ~= b ==> a >= b ==> a > b"
   962   "a = f b ==> b > c ==> (!!x y. x > y ==> f x > f y) ==> a > f c" 
   963   "a > b ==> f b = c ==> (!!x y. x > y ==> f x > f y) ==> f a > c"
   964   "a = f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
   965   "a >= b ==> f b = c ==> (!! x y. x >= y ==> f x >= f y) ==> f a >= c"
   966   by auto
   967 
   968 lemma xt2 [no_atp]:
   969   "(a::'a::order) >= f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
   970 by (subgoal_tac "f b >= f c", force, force)
   971 
   972 lemma xt3 [no_atp]: "(a::'a::order) >= b ==> (f b::'b::order) >= c ==>
   973     (!!x y. x >= y ==> f x >= f y) ==> f a >= c"
   974 by (subgoal_tac "f a >= f b", force, force)
   975 
   976 lemma xt4 [no_atp]: "(a::'a::order) > f b ==> (b::'b::order) >= c ==>
   977   (!!x y. x >= y ==> f x >= f y) ==> a > f c"
   978 by (subgoal_tac "f b >= f c", force, force)
   979 
   980 lemma xt5 [no_atp]: "(a::'a::order) > b ==> (f b::'b::order) >= c==>
   981     (!!x y. x > y ==> f x > f y) ==> f a > c"
   982 by (subgoal_tac "f a > f b", force, force)
   983 
   984 lemma xt6 [no_atp]: "(a::'a::order) >= f b ==> b > c ==>
   985     (!!x y. x > y ==> f x > f y) ==> a > f c"
   986 by (subgoal_tac "f b > f c", force, force)
   987 
   988 lemma xt7 [no_atp]: "(a::'a::order) >= b ==> (f b::'b::order) > c ==>
   989     (!!x y. x >= y ==> f x >= f y) ==> f a > c"
   990 by (subgoal_tac "f a >= f b", force, force)
   991 
   992 lemma xt8 [no_atp]: "(a::'a::order) > f b ==> (b::'b::order) > c ==>
   993     (!!x y. x > y ==> f x > f y) ==> a > f c"
   994 by (subgoal_tac "f b > f c", force, force)
   995 
   996 lemma xt9 [no_atp]: "(a::'a::order) > b ==> (f b::'b::order) > c ==>
   997     (!!x y. x > y ==> f x > f y) ==> f a > c"
   998 by (subgoal_tac "f a > f b", force, force)
   999 
  1000 lemmas xtrans = xt1 xt2 xt3 xt4 xt5 xt6 xt7 xt8 xt9
  1001 
  1002 (* 
  1003   Since "a >= b" abbreviates "b <= a", the abbreviation "..." stands
  1004   for the wrong thing in an Isar proof.
  1005 
  1006   The extra transitivity rules can be used as follows: 
  1007 
  1008 lemma "(a::'a::order) > z"
  1009 proof -
  1010   have "a >= b" (is "_ >= ?rhs")
  1011     sorry
  1012   also have "?rhs >= c" (is "_ >= ?rhs")
  1013     sorry
  1014   also (xtrans) have "?rhs = d" (is "_ = ?rhs")
  1015     sorry
  1016   also (xtrans) have "?rhs >= e" (is "_ >= ?rhs")
  1017     sorry
  1018   also (xtrans) have "?rhs > f" (is "_ > ?rhs")
  1019     sorry
  1020   also (xtrans) have "?rhs > z"
  1021     sorry
  1022   finally (xtrans) show ?thesis .
  1023 qed
  1024 
  1025   Alternatively, one can use "declare xtrans [trans]" and then
  1026   leave out the "(xtrans)" above.
  1027 *)
  1028 
  1029 
  1030 subsection {* Monotonicity *}
  1031 
  1032 context order
  1033 begin
  1034 
  1035 definition mono :: "('a \<Rightarrow> 'b\<Colon>order) \<Rightarrow> bool" where
  1036   "mono f \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> f x \<le> f y)"
  1037 
  1038 lemma monoI [intro?]:
  1039   fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
  1040   shows "(\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y) \<Longrightarrow> mono f"
  1041   unfolding mono_def by iprover
  1042 
  1043 lemma monoD [dest?]:
  1044   fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
  1045   shows "mono f \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
  1046   unfolding mono_def by iprover
  1047 
  1048 lemma monoE:
  1049   fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
  1050   assumes "mono f"
  1051   assumes "x \<le> y"
  1052   obtains "f x \<le> f y"
  1053 proof
  1054   from assms show "f x \<le> f y" by (simp add: mono_def)
  1055 qed
  1056 
  1057 definition antimono :: "('a \<Rightarrow> 'b\<Colon>order) \<Rightarrow> bool" where
  1058   "antimono f \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> f x \<ge> f y)"
  1059 
  1060 lemma antimonoI [intro?]:
  1061   fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
  1062   shows "(\<And>x y. x \<le> y \<Longrightarrow> f x \<ge> f y) \<Longrightarrow> antimono f"
  1063   unfolding antimono_def by iprover
  1064 
  1065 lemma antimonoD [dest?]:
  1066   fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
  1067   shows "antimono f \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<ge> f y"
  1068   unfolding antimono_def by iprover
  1069 
  1070 lemma antimonoE:
  1071   fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
  1072   assumes "antimono f"
  1073   assumes "x \<le> y"
  1074   obtains "f x \<ge> f y"
  1075 proof
  1076   from assms show "f x \<ge> f y" by (simp add: antimono_def)
  1077 qed
  1078 
  1079 definition strict_mono :: "('a \<Rightarrow> 'b\<Colon>order) \<Rightarrow> bool" where
  1080   "strict_mono f \<longleftrightarrow> (\<forall>x y. x < y \<longrightarrow> f x < f y)"
  1081 
  1082 lemma strict_monoI [intro?]:
  1083   assumes "\<And>x y. x < y \<Longrightarrow> f x < f y"
  1084   shows "strict_mono f"
  1085   using assms unfolding strict_mono_def by auto
  1086 
  1087 lemma strict_monoD [dest?]:
  1088   "strict_mono f \<Longrightarrow> x < y \<Longrightarrow> f x < f y"
  1089   unfolding strict_mono_def by auto
  1090 
  1091 lemma strict_mono_mono [dest?]:
  1092   assumes "strict_mono f"
  1093   shows "mono f"
  1094 proof (rule monoI)
  1095   fix x y
  1096   assume "x \<le> y"
  1097   show "f x \<le> f y"
  1098   proof (cases "x = y")
  1099     case True then show ?thesis by simp
  1100   next
  1101     case False with `x \<le> y` have "x < y" by simp
  1102     with assms strict_monoD have "f x < f y" by auto
  1103     then show ?thesis by simp
  1104   qed
  1105 qed
  1106 
  1107 end
  1108 
  1109 context linorder
  1110 begin
  1111 
  1112 lemma mono_invE:
  1113   fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
  1114   assumes "mono f"
  1115   assumes "f x < f y"
  1116   obtains "x \<le> y"
  1117 proof
  1118   show "x \<le> y"
  1119   proof (rule ccontr)
  1120     assume "\<not> x \<le> y"
  1121     then have "y \<le> x" by simp
  1122     with `mono f` obtain "f y \<le> f x" by (rule monoE)
  1123     with `f x < f y` show False by simp
  1124   qed
  1125 qed
  1126 
  1127 lemma strict_mono_eq:
  1128   assumes "strict_mono f"
  1129   shows "f x = f y \<longleftrightarrow> x = y"
  1130 proof
  1131   assume "f x = f y"
  1132   show "x = y" proof (cases x y rule: linorder_cases)
  1133     case less with assms strict_monoD have "f x < f y" by auto
  1134     with `f x = f y` show ?thesis by simp
  1135   next
  1136     case equal then show ?thesis .
  1137   next
  1138     case greater with assms strict_monoD have "f y < f x" by auto
  1139     with `f x = f y` show ?thesis by simp
  1140   qed
  1141 qed simp
  1142 
  1143 lemma strict_mono_less_eq:
  1144   assumes "strict_mono f"
  1145   shows "f x \<le> f y \<longleftrightarrow> x \<le> y"
  1146 proof
  1147   assume "x \<le> y"
  1148   with assms strict_mono_mono monoD show "f x \<le> f y" by auto
  1149 next
  1150   assume "f x \<le> f y"
  1151   show "x \<le> y" proof (rule ccontr)
  1152     assume "\<not> x \<le> y" then have "y < x" by simp
  1153     with assms strict_monoD have "f y < f x" by auto
  1154     with `f x \<le> f y` show False by simp
  1155   qed
  1156 qed
  1157   
  1158 lemma strict_mono_less:
  1159   assumes "strict_mono f"
  1160   shows "f x < f y \<longleftrightarrow> x < y"
  1161   using assms
  1162     by (auto simp add: less_le Orderings.less_le strict_mono_eq strict_mono_less_eq)
  1163 
  1164 end
  1165 
  1166 
  1167 subsection {* min and max -- fundamental *}
  1168 
  1169 definition (in ord) min :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where
  1170   "min a b = (if a \<le> b then a else b)"
  1171 
  1172 definition (in ord) max :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where
  1173   "max a b = (if a \<le> b then b else a)"
  1174 
  1175 lemma min_absorb1: "x \<le> y \<Longrightarrow> min x y = x"
  1176   by (simp add: min_def)
  1177 
  1178 lemma max_absorb2: "x \<le> y \<Longrightarrow> max x y = y"
  1179   by (simp add: max_def)
  1180 
  1181 lemma min_absorb2: "(y\<Colon>'a\<Colon>order) \<le> x \<Longrightarrow> min x y = y"
  1182   by (simp add:min_def)
  1183 
  1184 lemma max_absorb1: "(y\<Colon>'a\<Colon>order) \<le> x \<Longrightarrow> max x y = x"
  1185   by (simp add: max_def)
  1186 
  1187 
  1188 subsection {* (Unique) top and bottom elements *}
  1189 
  1190 class bot =
  1191   fixes bot :: 'a ("\<bottom>")
  1192 
  1193 class order_bot = order + bot +
  1194   assumes bot_least: "\<bottom> \<le> a"
  1195 begin
  1196 
  1197 sublocale bot!: ordering_top greater_eq greater bot
  1198   by default (fact bot_least)
  1199 
  1200 lemma le_bot:
  1201   "a \<le> \<bottom> \<Longrightarrow> a = \<bottom>"
  1202   by (fact bot.extremum_uniqueI)
  1203 
  1204 lemma bot_unique:
  1205   "a \<le> \<bottom> \<longleftrightarrow> a = \<bottom>"
  1206   by (fact bot.extremum_unique)
  1207 
  1208 lemma not_less_bot:
  1209   "\<not> a < \<bottom>"
  1210   by (fact bot.extremum_strict)
  1211 
  1212 lemma bot_less:
  1213   "a \<noteq> \<bottom> \<longleftrightarrow> \<bottom> < a"
  1214   by (fact bot.not_eq_extremum)
  1215 
  1216 end
  1217 
  1218 class top =
  1219   fixes top :: 'a ("\<top>")
  1220 
  1221 class order_top = order + top +
  1222   assumes top_greatest: "a \<le> \<top>"
  1223 begin
  1224 
  1225 sublocale top!: ordering_top less_eq less top
  1226   by default (fact top_greatest)
  1227 
  1228 lemma top_le:
  1229   "\<top> \<le> a \<Longrightarrow> a = \<top>"
  1230   by (fact top.extremum_uniqueI)
  1231 
  1232 lemma top_unique:
  1233   "\<top> \<le> a \<longleftrightarrow> a = \<top>"
  1234   by (fact top.extremum_unique)
  1235 
  1236 lemma not_top_less:
  1237   "\<not> \<top> < a"
  1238   by (fact top.extremum_strict)
  1239 
  1240 lemma less_top:
  1241   "a \<noteq> \<top> \<longleftrightarrow> a < \<top>"
  1242   by (fact top.not_eq_extremum)
  1243 
  1244 end
  1245 
  1246 
  1247 subsection {* Dense orders *}
  1248 
  1249 class dense_order = order +
  1250   assumes dense: "x < y \<Longrightarrow> (\<exists>z. x < z \<and> z < y)"
  1251 
  1252 class dense_linorder = linorder + dense_order
  1253 begin
  1254 
  1255 lemma dense_le:
  1256   fixes y z :: 'a
  1257   assumes "\<And>x. x < y \<Longrightarrow> x \<le> z"
  1258   shows "y \<le> z"
  1259 proof (rule ccontr)
  1260   assume "\<not> ?thesis"
  1261   hence "z < y" by simp
  1262   from dense[OF this]
  1263   obtain x where "x < y" and "z < x" by safe
  1264   moreover have "x \<le> z" using assms[OF `x < y`] .
  1265   ultimately show False by auto
  1266 qed
  1267 
  1268 lemma dense_le_bounded:
  1269   fixes x y z :: 'a
  1270   assumes "x < y"
  1271   assumes *: "\<And>w. \<lbrakk> x < w ; w < y \<rbrakk> \<Longrightarrow> w \<le> z"
  1272   shows "y \<le> z"
  1273 proof (rule dense_le)
  1274   fix w assume "w < y"
  1275   from dense[OF `x < y`] obtain u where "x < u" "u < y" by safe
  1276   from linear[of u w]
  1277   show "w \<le> z"
  1278   proof (rule disjE)
  1279     assume "u \<le> w"
  1280     from less_le_trans[OF `x < u` `u \<le> w`] `w < y`
  1281     show "w \<le> z" by (rule *)
  1282   next
  1283     assume "w \<le> u"
  1284     from `w \<le> u` *[OF `x < u` `u < y`]
  1285     show "w \<le> z" by (rule order_trans)
  1286   qed
  1287 qed
  1288 
  1289 lemma dense_ge:
  1290   fixes y z :: 'a
  1291   assumes "\<And>x. z < x \<Longrightarrow> y \<le> x"
  1292   shows "y \<le> z"
  1293 proof (rule ccontr)
  1294   assume "\<not> ?thesis"
  1295   hence "z < y" by simp
  1296   from dense[OF this]
  1297   obtain x where "x < y" and "z < x" by safe
  1298   moreover have "y \<le> x" using assms[OF `z < x`] .
  1299   ultimately show False by auto
  1300 qed
  1301 
  1302 lemma dense_ge_bounded:
  1303   fixes x y z :: 'a
  1304   assumes "z < x"
  1305   assumes *: "\<And>w. \<lbrakk> z < w ; w < x \<rbrakk> \<Longrightarrow> y \<le> w"
  1306   shows "y \<le> z"
  1307 proof (rule dense_ge)
  1308   fix w assume "z < w"
  1309   from dense[OF `z < x`] obtain u where "z < u" "u < x" by safe
  1310   from linear[of u w]
  1311   show "y \<le> w"
  1312   proof (rule disjE)
  1313     assume "w \<le> u"
  1314     from `z < w` le_less_trans[OF `w \<le> u` `u < x`]
  1315     show "y \<le> w" by (rule *)
  1316   next
  1317     assume "u \<le> w"
  1318     from *[OF `z < u` `u < x`] `u \<le> w`
  1319     show "y \<le> w" by (rule order_trans)
  1320   qed
  1321 qed
  1322 
  1323 end
  1324 
  1325 class no_top = order + 
  1326   assumes gt_ex: "\<exists>y. x < y"
  1327 
  1328 class no_bot = order + 
  1329   assumes lt_ex: "\<exists>y. y < x"
  1330 
  1331 class unbounded_dense_linorder = dense_linorder + no_top + no_bot
  1332 
  1333 
  1334 subsection {* Wellorders *}
  1335 
  1336 class wellorder = linorder +
  1337   assumes less_induct [case_names less]: "(\<And>x. (\<And>y. y < x \<Longrightarrow> P y) \<Longrightarrow> P x) \<Longrightarrow> P a"
  1338 begin
  1339 
  1340 lemma wellorder_Least_lemma:
  1341   fixes k :: 'a
  1342   assumes "P k"
  1343   shows LeastI: "P (LEAST x. P x)" and Least_le: "(LEAST x. P x) \<le> k"
  1344 proof -
  1345   have "P (LEAST x. P x) \<and> (LEAST x. P x) \<le> k"
  1346   using assms proof (induct k rule: less_induct)
  1347     case (less x) then have "P x" by simp
  1348     show ?case proof (rule classical)
  1349       assume assm: "\<not> (P (LEAST a. P a) \<and> (LEAST a. P a) \<le> x)"
  1350       have "\<And>y. P y \<Longrightarrow> x \<le> y"
  1351       proof (rule classical)
  1352         fix y
  1353         assume "P y" and "\<not> x \<le> y"
  1354         with less have "P (LEAST a. P a)" and "(LEAST a. P a) \<le> y"
  1355           by (auto simp add: not_le)
  1356         with assm have "x < (LEAST a. P a)" and "(LEAST a. P a) \<le> y"
  1357           by auto
  1358         then show "x \<le> y" by auto
  1359       qed
  1360       with `P x` have Least: "(LEAST a. P a) = x"
  1361         by (rule Least_equality)
  1362       with `P x` show ?thesis by simp
  1363     qed
  1364   qed
  1365   then show "P (LEAST x. P x)" and "(LEAST x. P x) \<le> k" by auto
  1366 qed
  1367 
  1368 -- "The following 3 lemmas are due to Brian Huffman"
  1369 lemma LeastI_ex: "\<exists>x. P x \<Longrightarrow> P (Least P)"
  1370   by (erule exE) (erule LeastI)
  1371 
  1372 lemma LeastI2:
  1373   "P a \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> Q (Least P)"
  1374   by (blast intro: LeastI)
  1375 
  1376 lemma LeastI2_ex:
  1377   "\<exists>a. P a \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> Q (Least P)"
  1378   by (blast intro: LeastI_ex)
  1379 
  1380 lemma LeastI2_wellorder:
  1381   assumes "P a"
  1382   and "\<And>a. \<lbrakk> P a; \<forall>b. P b \<longrightarrow> a \<le> b \<rbrakk> \<Longrightarrow> Q a"
  1383   shows "Q (Least P)"
  1384 proof (rule LeastI2_order)
  1385   show "P (Least P)" using `P a` by (rule LeastI)
  1386 next
  1387   fix y assume "P y" thus "Least P \<le> y" by (rule Least_le)
  1388 next
  1389   fix x assume "P x" "\<forall>y. P y \<longrightarrow> x \<le> y" thus "Q x" by (rule assms(2))
  1390 qed
  1391 
  1392 lemma not_less_Least: "k < (LEAST x. P x) \<Longrightarrow> \<not> P k"
  1393 apply (simp (no_asm_use) add: not_le [symmetric])
  1394 apply (erule contrapos_nn)
  1395 apply (erule Least_le)
  1396 done
  1397 
  1398 end
  1399 
  1400 
  1401 subsection {* Order on @{typ bool} *}
  1402 
  1403 instantiation bool :: "{order_bot, order_top, linorder}"
  1404 begin
  1405 
  1406 definition
  1407   le_bool_def [simp]: "P \<le> Q \<longleftrightarrow> P \<longrightarrow> Q"
  1408 
  1409 definition
  1410   [simp]: "(P\<Colon>bool) < Q \<longleftrightarrow> \<not> P \<and> Q"
  1411 
  1412 definition
  1413   [simp]: "\<bottom> \<longleftrightarrow> False"
  1414 
  1415 definition
  1416   [simp]: "\<top> \<longleftrightarrow> True"
  1417 
  1418 instance proof
  1419 qed auto
  1420 
  1421 end
  1422 
  1423 lemma le_boolI: "(P \<Longrightarrow> Q) \<Longrightarrow> P \<le> Q"
  1424   by simp
  1425 
  1426 lemma le_boolI': "P \<longrightarrow> Q \<Longrightarrow> P \<le> Q"
  1427   by simp
  1428 
  1429 lemma le_boolE: "P \<le> Q \<Longrightarrow> P \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
  1430   by simp
  1431 
  1432 lemma le_boolD: "P \<le> Q \<Longrightarrow> P \<longrightarrow> Q"
  1433   by simp
  1434 
  1435 lemma bot_boolE: "\<bottom> \<Longrightarrow> P"
  1436   by simp
  1437 
  1438 lemma top_boolI: \<top>
  1439   by simp
  1440 
  1441 lemma [code]:
  1442   "False \<le> b \<longleftrightarrow> True"
  1443   "True \<le> b \<longleftrightarrow> b"
  1444   "False < b \<longleftrightarrow> b"
  1445   "True < b \<longleftrightarrow> False"
  1446   by simp_all
  1447 
  1448 
  1449 subsection {* Order on @{typ "_ \<Rightarrow> _"} *}
  1450 
  1451 instantiation "fun" :: (type, ord) ord
  1452 begin
  1453 
  1454 definition
  1455   le_fun_def: "f \<le> g \<longleftrightarrow> (\<forall>x. f x \<le> g x)"
  1456 
  1457 definition
  1458   "(f\<Colon>'a \<Rightarrow> 'b) < g \<longleftrightarrow> f \<le> g \<and> \<not> (g \<le> f)"
  1459 
  1460 instance ..
  1461 
  1462 end
  1463 
  1464 instance "fun" :: (type, preorder) preorder proof
  1465 qed (auto simp add: le_fun_def less_fun_def
  1466   intro: order_trans antisym)
  1467 
  1468 instance "fun" :: (type, order) order proof
  1469 qed (auto simp add: le_fun_def intro: antisym)
  1470 
  1471 instantiation "fun" :: (type, bot) bot
  1472 begin
  1473 
  1474 definition
  1475   "\<bottom> = (\<lambda>x. \<bottom>)"
  1476 
  1477 instance ..
  1478 
  1479 end
  1480 
  1481 instantiation "fun" :: (type, order_bot) order_bot
  1482 begin
  1483 
  1484 lemma bot_apply [simp, code]:
  1485   "\<bottom> x = \<bottom>"
  1486   by (simp add: bot_fun_def)
  1487 
  1488 instance proof
  1489 qed (simp add: le_fun_def)
  1490 
  1491 end
  1492 
  1493 instantiation "fun" :: (type, top) top
  1494 begin
  1495 
  1496 definition
  1497   [no_atp]: "\<top> = (\<lambda>x. \<top>)"
  1498 
  1499 instance ..
  1500 
  1501 end
  1502 
  1503 instantiation "fun" :: (type, order_top) order_top
  1504 begin
  1505 
  1506 lemma top_apply [simp, code]:
  1507   "\<top> x = \<top>"
  1508   by (simp add: top_fun_def)
  1509 
  1510 instance proof
  1511 qed (simp add: le_fun_def)
  1512 
  1513 end
  1514 
  1515 lemma le_funI: "(\<And>x. f x \<le> g x) \<Longrightarrow> f \<le> g"
  1516   unfolding le_fun_def by simp
  1517 
  1518 lemma le_funE: "f \<le> g \<Longrightarrow> (f x \<le> g x \<Longrightarrow> P) \<Longrightarrow> P"
  1519   unfolding le_fun_def by simp
  1520 
  1521 lemma le_funD: "f \<le> g \<Longrightarrow> f x \<le> g x"
  1522   by (rule le_funE)
  1523 
  1524 
  1525 subsection {* Order on unary and binary predicates *}
  1526 
  1527 lemma predicate1I:
  1528   assumes PQ: "\<And>x. P x \<Longrightarrow> Q x"
  1529   shows "P \<le> Q"
  1530   apply (rule le_funI)
  1531   apply (rule le_boolI)
  1532   apply (rule PQ)
  1533   apply assumption
  1534   done
  1535 
  1536 lemma predicate1D:
  1537   "P \<le> Q \<Longrightarrow> P x \<Longrightarrow> Q x"
  1538   apply (erule le_funE)
  1539   apply (erule le_boolE)
  1540   apply assumption+
  1541   done
  1542 
  1543 lemma rev_predicate1D:
  1544   "P x \<Longrightarrow> P \<le> Q \<Longrightarrow> Q x"
  1545   by (rule predicate1D)
  1546 
  1547 lemma predicate2I:
  1548   assumes PQ: "\<And>x y. P x y \<Longrightarrow> Q x y"
  1549   shows "P \<le> Q"
  1550   apply (rule le_funI)+
  1551   apply (rule le_boolI)
  1552   apply (rule PQ)
  1553   apply assumption
  1554   done
  1555 
  1556 lemma predicate2D:
  1557   "P \<le> Q \<Longrightarrow> P x y \<Longrightarrow> Q x y"
  1558   apply (erule le_funE)+
  1559   apply (erule le_boolE)
  1560   apply assumption+
  1561   done
  1562 
  1563 lemma rev_predicate2D:
  1564   "P x y \<Longrightarrow> P \<le> Q \<Longrightarrow> Q x y"
  1565   by (rule predicate2D)
  1566 
  1567 lemma bot1E [no_atp]: "\<bottom> x \<Longrightarrow> P"
  1568   by (simp add: bot_fun_def)
  1569 
  1570 lemma bot2E: "\<bottom> x y \<Longrightarrow> P"
  1571   by (simp add: bot_fun_def)
  1572 
  1573 lemma top1I: "\<top> x"
  1574   by (simp add: top_fun_def)
  1575 
  1576 lemma top2I: "\<top> x y"
  1577   by (simp add: top_fun_def)
  1578 
  1579 
  1580 subsection {* Name duplicates *}
  1581 
  1582 lemmas order_eq_refl = preorder_class.eq_refl
  1583 lemmas order_less_irrefl = preorder_class.less_irrefl
  1584 lemmas order_less_imp_le = preorder_class.less_imp_le
  1585 lemmas order_less_not_sym = preorder_class.less_not_sym
  1586 lemmas order_less_asym = preorder_class.less_asym
  1587 lemmas order_less_trans = preorder_class.less_trans
  1588 lemmas order_le_less_trans = preorder_class.le_less_trans
  1589 lemmas order_less_le_trans = preorder_class.less_le_trans
  1590 lemmas order_less_imp_not_less = preorder_class.less_imp_not_less
  1591 lemmas order_less_imp_triv = preorder_class.less_imp_triv
  1592 lemmas order_less_asym' = preorder_class.less_asym'
  1593 
  1594 lemmas order_less_le = order_class.less_le
  1595 lemmas order_le_less = order_class.le_less
  1596 lemmas order_le_imp_less_or_eq = order_class.le_imp_less_or_eq
  1597 lemmas order_less_imp_not_eq = order_class.less_imp_not_eq
  1598 lemmas order_less_imp_not_eq2 = order_class.less_imp_not_eq2
  1599 lemmas order_neq_le_trans = order_class.neq_le_trans
  1600 lemmas order_le_neq_trans = order_class.le_neq_trans
  1601 lemmas order_antisym = order_class.antisym
  1602 lemmas order_eq_iff = order_class.eq_iff
  1603 lemmas order_antisym_conv = order_class.antisym_conv
  1604 
  1605 lemmas linorder_linear = linorder_class.linear
  1606 lemmas linorder_less_linear = linorder_class.less_linear
  1607 lemmas linorder_le_less_linear = linorder_class.le_less_linear
  1608 lemmas linorder_le_cases = linorder_class.le_cases
  1609 lemmas linorder_not_less = linorder_class.not_less
  1610 lemmas linorder_not_le = linorder_class.not_le
  1611 lemmas linorder_neq_iff = linorder_class.neq_iff
  1612 lemmas linorder_neqE = linorder_class.neqE
  1613 lemmas linorder_antisym_conv1 = linorder_class.antisym_conv1
  1614 lemmas linorder_antisym_conv2 = linorder_class.antisym_conv2
  1615 lemmas linorder_antisym_conv3 = linorder_class.antisym_conv3
  1616 
  1617 end
  1618