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