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