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