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