src/HOL/Orderings.thy
author haftmann
Tue Jun 10 15:30:58 2008 +0200 (2008-06-10)
changeset 27107 4a7415c67063
parent 26796 c554b77061e5
child 27299 3447cd2e18e8
permissions -rw-r--r--
localized Least in Orderings.thy
nipkow@15524
     1
(*  Title:      HOL/Orderings.thy
nipkow@15524
     2
    ID:         $Id$
nipkow@15524
     3
    Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
nipkow@15524
     4
*)
nipkow@15524
     5
haftmann@25614
     6
header {* Abstract orderings *}
nipkow@15524
     7
nipkow@15524
     8
theory Orderings
berghofe@26796
     9
imports Code_Setup
haftmann@23263
    10
uses
haftmann@23263
    11
  "~~/src/Provers/order.ML"
nipkow@15524
    12
begin
nipkow@15524
    13
haftmann@22841
    14
subsection {* Partial orders *}
nipkow@15524
    15
haftmann@22841
    16
class order = ord +
haftmann@25062
    17
  assumes less_le: "x < y \<longleftrightarrow> x \<le> y \<and> x \<noteq> y"
haftmann@25062
    18
  and order_refl [iff]: "x \<le> x"
haftmann@25062
    19
  and order_trans: "x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z"
haftmann@25062
    20
  assumes antisym: "x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y"
haftmann@21248
    21
begin
haftmann@21248
    22
nipkow@15524
    23
text {* Reflexivity. *}
nipkow@15524
    24
haftmann@25062
    25
lemma eq_refl: "x = y \<Longrightarrow> x \<le> y"
nipkow@15524
    26
    -- {* This form is useful with the classical reasoner. *}
nipkow@23212
    27
by (erule ssubst) (rule order_refl)
nipkow@15524
    28
haftmann@25062
    29
lemma less_irrefl [iff]: "\<not> x < x"
nipkow@23212
    30
by (simp add: less_le)
nipkow@15524
    31
haftmann@25062
    32
lemma le_less: "x \<le> y \<longleftrightarrow> x < y \<or> x = y"
nipkow@15524
    33
    -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
nipkow@23212
    34
by (simp add: less_le) blast
nipkow@15524
    35
haftmann@25062
    36
lemma le_imp_less_or_eq: "x \<le> y \<Longrightarrow> x < y \<or> x = y"
nipkow@23212
    37
unfolding less_le by blast
nipkow@15524
    38
haftmann@25062
    39
lemma less_imp_le: "x < y \<Longrightarrow> x \<le> y"
nipkow@23212
    40
unfolding less_le by blast
haftmann@21248
    41
haftmann@21329
    42
haftmann@21329
    43
text {* Useful for simplification, but too risky to include by default. *}
haftmann@21329
    44
haftmann@25062
    45
lemma less_imp_not_eq: "x < y \<Longrightarrow> (x = y) \<longleftrightarrow> False"
nipkow@23212
    46
by auto
haftmann@21329
    47
haftmann@25062
    48
lemma less_imp_not_eq2: "x < y \<Longrightarrow> (y = x) \<longleftrightarrow> False"
nipkow@23212
    49
by auto
haftmann@21329
    50
haftmann@21329
    51
haftmann@21329
    52
text {* Transitivity rules for calculational reasoning *}
haftmann@21329
    53
haftmann@25062
    54
lemma neq_le_trans: "a \<noteq> b \<Longrightarrow> a \<le> b \<Longrightarrow> a < b"
nipkow@23212
    55
by (simp add: less_le)
haftmann@21329
    56
haftmann@25062
    57
lemma le_neq_trans: "a \<le> b \<Longrightarrow> a \<noteq> b \<Longrightarrow> a < b"
nipkow@23212
    58
by (simp add: less_le)
haftmann@21329
    59
nipkow@15524
    60
nipkow@15524
    61
text {* Asymmetry. *}
nipkow@15524
    62
haftmann@25062
    63
lemma less_not_sym: "x < y \<Longrightarrow> \<not> (y < x)"
nipkow@23212
    64
by (simp add: less_le antisym)
nipkow@15524
    65
haftmann@25062
    66
lemma less_asym: "x < y \<Longrightarrow> (\<not> P \<Longrightarrow> y < x) \<Longrightarrow> P"
nipkow@23212
    67
by (drule less_not_sym, erule contrapos_np) simp
nipkow@15524
    68
haftmann@25062
    69
lemma eq_iff: "x = y \<longleftrightarrow> x \<le> y \<and> y \<le> x"
nipkow@23212
    70
by (blast intro: antisym)
nipkow@15524
    71
haftmann@25062
    72
lemma antisym_conv: "y \<le> x \<Longrightarrow> x \<le> y \<longleftrightarrow> x = y"
nipkow@23212
    73
by (blast intro: antisym)
nipkow@15524
    74
haftmann@25062
    75
lemma less_imp_neq: "x < y \<Longrightarrow> x \<noteq> y"
nipkow@23212
    76
by (erule contrapos_pn, erule subst, rule less_irrefl)
haftmann@21248
    77
haftmann@21083
    78
nipkow@15524
    79
text {* Transitivity. *}
nipkow@15524
    80
haftmann@25062
    81
lemma less_trans: "x < y \<Longrightarrow> y < z \<Longrightarrow> x < z"
nipkow@23212
    82
by (simp add: less_le) (blast intro: order_trans antisym)
nipkow@15524
    83
haftmann@25062
    84
lemma le_less_trans: "x \<le> y \<Longrightarrow> y < z \<Longrightarrow> x < z"
nipkow@23212
    85
by (simp add: less_le) (blast intro: order_trans antisym)
nipkow@15524
    86
haftmann@25062
    87
lemma less_le_trans: "x < y \<Longrightarrow> y \<le> z \<Longrightarrow> x < z"
nipkow@23212
    88
by (simp add: less_le) (blast intro: order_trans antisym)
nipkow@15524
    89
nipkow@15524
    90
nipkow@15524
    91
text {* Useful for simplification, but too risky to include by default. *}
nipkow@15524
    92
haftmann@25062
    93
lemma less_imp_not_less: "x < y \<Longrightarrow> (\<not> y < x) \<longleftrightarrow> True"
nipkow@23212
    94
by (blast elim: less_asym)
nipkow@15524
    95
haftmann@25062
    96
lemma less_imp_triv: "x < y \<Longrightarrow> (y < x \<longrightarrow> P) \<longleftrightarrow> True"
nipkow@23212
    97
by (blast elim: less_asym)
nipkow@15524
    98
haftmann@21248
    99
haftmann@21083
   100
text {* Transitivity rules for calculational reasoning *}
nipkow@15524
   101
haftmann@25062
   102
lemma less_asym': "a < b \<Longrightarrow> b < a \<Longrightarrow> P"
nipkow@23212
   103
by (rule less_asym)
haftmann@21248
   104
haftmann@22916
   105
haftmann@27107
   106
text {* Least value operator *}
haftmann@27107
   107
haftmann@27107
   108
definition
haftmann@27107
   109
  Least :: "('a \<Rightarrow> bool) \<Rightarrow> 'a" (binder "LEAST " 10) where
haftmann@27107
   110
  "Least P = (THE x. P x \<and> (\<forall>y. P y \<longrightarrow> x \<le> y))"
haftmann@27107
   111
haftmann@27107
   112
lemma Least_equality:
haftmann@27107
   113
  assumes "P x"
haftmann@27107
   114
    and "\<And>y. P y \<Longrightarrow> x \<le> y"
haftmann@27107
   115
  shows "Least P = x"
haftmann@27107
   116
unfolding Least_def by (rule the_equality)
haftmann@27107
   117
  (blast intro: assms antisym)+
haftmann@27107
   118
haftmann@27107
   119
lemma LeastI2_order:
haftmann@27107
   120
  assumes "P x"
haftmann@27107
   121
    and "\<And>y. P y \<Longrightarrow> x \<le> y"
haftmann@27107
   122
    and "\<And>x. P x \<Longrightarrow> \<forall>y. P y \<longrightarrow> x \<le> y \<Longrightarrow> Q x"
haftmann@27107
   123
  shows "Q (Least P)"
haftmann@27107
   124
unfolding Least_def by (rule theI2)
haftmann@27107
   125
  (blast intro: assms antisym)+
haftmann@27107
   126
haftmann@27107
   127
haftmann@26014
   128
text {* Dual order *}
haftmann@22916
   129
haftmann@26014
   130
lemma dual_order:
haftmann@25103
   131
  "order (op \<ge>) (op >)"
nipkow@23212
   132
by unfold_locales
nipkow@23212
   133
   (simp add: less_le, auto intro: antisym order_trans)
haftmann@22916
   134
haftmann@21248
   135
end
nipkow@15524
   136
haftmann@21329
   137
haftmann@21329
   138
subsection {* Linear (total) orders *}
haftmann@21329
   139
haftmann@22316
   140
class linorder = order +
haftmann@25207
   141
  assumes linear: "x \<le> y \<or> y \<le> x"
haftmann@21248
   142
begin
haftmann@21248
   143
haftmann@25062
   144
lemma less_linear: "x < y \<or> x = y \<or> y < x"
nipkow@23212
   145
unfolding less_le using less_le linear by blast
haftmann@21248
   146
haftmann@25062
   147
lemma le_less_linear: "x \<le> y \<or> y < x"
nipkow@23212
   148
by (simp add: le_less less_linear)
haftmann@21248
   149
haftmann@21248
   150
lemma le_cases [case_names le ge]:
haftmann@25062
   151
  "(x \<le> y \<Longrightarrow> P) \<Longrightarrow> (y \<le> x \<Longrightarrow> P) \<Longrightarrow> P"
nipkow@23212
   152
using linear by blast
haftmann@21248
   153
haftmann@22384
   154
lemma linorder_cases [case_names less equal greater]:
haftmann@25062
   155
  "(x < y \<Longrightarrow> P) \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> (y < x \<Longrightarrow> P) \<Longrightarrow> P"
nipkow@23212
   156
using less_linear by blast
haftmann@21248
   157
haftmann@25062
   158
lemma not_less: "\<not> x < y \<longleftrightarrow> y \<le> x"
nipkow@23212
   159
apply (simp add: less_le)
nipkow@23212
   160
using linear apply (blast intro: antisym)
nipkow@23212
   161
done
nipkow@23212
   162
nipkow@23212
   163
lemma not_less_iff_gr_or_eq:
haftmann@25062
   164
 "\<not>(x < y) \<longleftrightarrow> (x > y | x = y)"
nipkow@23212
   165
apply(simp add:not_less le_less)
nipkow@23212
   166
apply blast
nipkow@23212
   167
done
nipkow@15524
   168
haftmann@25062
   169
lemma not_le: "\<not> x \<le> y \<longleftrightarrow> y < x"
nipkow@23212
   170
apply (simp add: less_le)
nipkow@23212
   171
using linear apply (blast intro: antisym)
nipkow@23212
   172
done
nipkow@15524
   173
haftmann@25062
   174
lemma neq_iff: "x \<noteq> y \<longleftrightarrow> x < y \<or> y < x"
nipkow@23212
   175
by (cut_tac x = x and y = y in less_linear, auto)
nipkow@15524
   176
haftmann@25062
   177
lemma neqE: "x \<noteq> y \<Longrightarrow> (x < y \<Longrightarrow> R) \<Longrightarrow> (y < x \<Longrightarrow> R) \<Longrightarrow> R"
nipkow@23212
   178
by (simp add: neq_iff) blast
nipkow@15524
   179
haftmann@25062
   180
lemma antisym_conv1: "\<not> x < y \<Longrightarrow> x \<le> y \<longleftrightarrow> x = y"
nipkow@23212
   181
by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524
   182
haftmann@25062
   183
lemma antisym_conv2: "x \<le> y \<Longrightarrow> \<not> x < y \<longleftrightarrow> x = y"
nipkow@23212
   184
by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524
   185
haftmann@25062
   186
lemma antisym_conv3: "\<not> y < x \<Longrightarrow> \<not> x < y \<longleftrightarrow> x = y"
nipkow@23212
   187
by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524
   188
paulson@16796
   189
text{*Replacing the old Nat.leI*}
haftmann@25062
   190
lemma leI: "\<not> x < y \<Longrightarrow> y \<le> x"
nipkow@23212
   191
unfolding not_less .
paulson@16796
   192
haftmann@25062
   193
lemma leD: "y \<le> x \<Longrightarrow> \<not> x < y"
nipkow@23212
   194
unfolding not_less .
paulson@16796
   195
paulson@16796
   196
(*FIXME inappropriate name (or delete altogether)*)
haftmann@25062
   197
lemma not_leE: "\<not> y \<le> x \<Longrightarrow> x < y"
nipkow@23212
   198
unfolding not_le .
haftmann@21248
   199
haftmann@22916
   200
haftmann@26014
   201
text {* Dual order *}
haftmann@22916
   202
haftmann@26014
   203
lemma dual_linorder:
haftmann@25103
   204
  "linorder (op \<ge>) (op >)"
nipkow@23212
   205
by unfold_locales
nipkow@23212
   206
  (simp add: less_le, auto intro: antisym order_trans simp add: linear)
haftmann@22916
   207
haftmann@22916
   208
haftmann@23881
   209
text {* min/max *}
haftmann@23881
   210
haftmann@23881
   211
text {* for historic reasons, definitions are done in context ord *}
haftmann@23881
   212
haftmann@23881
   213
definition (in ord)
haftmann@23881
   214
  min :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where
haftmann@25062
   215
  [code unfold, code inline del]: "min a b = (if a \<le> b then a else b)"
haftmann@23881
   216
haftmann@23881
   217
definition (in ord)
haftmann@23881
   218
  max :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where
haftmann@25062
   219
  [code unfold, code inline del]: "max a b = (if a \<le> b then b else a)"
haftmann@22384
   220
haftmann@21383
   221
lemma min_le_iff_disj:
haftmann@25062
   222
  "min x y \<le> z \<longleftrightarrow> x \<le> z \<or> y \<le> z"
nipkow@23212
   223
unfolding min_def using linear by (auto intro: order_trans)
haftmann@21383
   224
haftmann@21383
   225
lemma le_max_iff_disj:
haftmann@25062
   226
  "z \<le> max x y \<longleftrightarrow> z \<le> x \<or> z \<le> y"
nipkow@23212
   227
unfolding max_def using linear by (auto intro: order_trans)
haftmann@21383
   228
haftmann@21383
   229
lemma min_less_iff_disj:
haftmann@25062
   230
  "min x y < z \<longleftrightarrow> x < z \<or> y < z"
nipkow@23212
   231
unfolding min_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   232
haftmann@21383
   233
lemma less_max_iff_disj:
haftmann@25062
   234
  "z < max x y \<longleftrightarrow> z < x \<or> z < y"
nipkow@23212
   235
unfolding max_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   236
haftmann@21383
   237
lemma min_less_iff_conj [simp]:
haftmann@25062
   238
  "z < min x y \<longleftrightarrow> z < x \<and> z < y"
nipkow@23212
   239
unfolding min_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   240
haftmann@21383
   241
lemma max_less_iff_conj [simp]:
haftmann@25062
   242
  "max x y < z \<longleftrightarrow> x < z \<and> y < z"
nipkow@23212
   243
unfolding max_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   244
paulson@24286
   245
lemma split_min [noatp]:
haftmann@25062
   246
  "P (min i j) \<longleftrightarrow> (i \<le> j \<longrightarrow> P i) \<and> (\<not> i \<le> j \<longrightarrow> P j)"
nipkow@23212
   247
by (simp add: min_def)
haftmann@21383
   248
paulson@24286
   249
lemma split_max [noatp]:
haftmann@25062
   250
  "P (max i j) \<longleftrightarrow> (i \<le> j \<longrightarrow> P j) \<and> (\<not> i \<le> j \<longrightarrow> P i)"
nipkow@23212
   251
by (simp add: max_def)
haftmann@21383
   252
haftmann@21248
   253
end
haftmann@21248
   254
haftmann@23948
   255
haftmann@21083
   256
subsection {* Reasoning tools setup *}
haftmann@21083
   257
haftmann@21091
   258
ML {*
haftmann@21091
   259
ballarin@24641
   260
signature ORDERS =
ballarin@24641
   261
sig
ballarin@24641
   262
  val print_structures: Proof.context -> unit
ballarin@24641
   263
  val setup: theory -> theory
ballarin@24704
   264
  val order_tac: thm list -> Proof.context -> int -> tactic
ballarin@24641
   265
end;
haftmann@21091
   266
ballarin@24641
   267
structure Orders: ORDERS =
haftmann@21248
   268
struct
ballarin@24641
   269
ballarin@24641
   270
(** Theory and context data **)
ballarin@24641
   271
ballarin@24641
   272
fun struct_eq ((s1: string, ts1), (s2, ts2)) =
ballarin@24641
   273
  (s1 = s2) andalso eq_list (op aconv) (ts1, ts2);
ballarin@24641
   274
ballarin@24641
   275
structure Data = GenericDataFun
ballarin@24641
   276
(
ballarin@24641
   277
  type T = ((string * term list) * Order_Tac.less_arith) list;
ballarin@24641
   278
    (* Order structures:
ballarin@24641
   279
       identifier of the structure, list of operations and record of theorems
ballarin@24641
   280
       needed to set up the transitivity reasoner,
ballarin@24641
   281
       identifier and operations identify the structure uniquely. *)
ballarin@24641
   282
  val empty = [];
ballarin@24641
   283
  val extend = I;
ballarin@24641
   284
  fun merge _ = AList.join struct_eq (K fst);
ballarin@24641
   285
);
ballarin@24641
   286
ballarin@24641
   287
fun print_structures ctxt =
ballarin@24641
   288
  let
ballarin@24641
   289
    val structs = Data.get (Context.Proof ctxt);
ballarin@24641
   290
    fun pretty_term t = Pretty.block
wenzelm@24920
   291
      [Pretty.quote (Syntax.pretty_term ctxt t), Pretty.brk 1,
ballarin@24641
   292
        Pretty.str "::", Pretty.brk 1,
wenzelm@24920
   293
        Pretty.quote (Syntax.pretty_typ ctxt (type_of t))];
ballarin@24641
   294
    fun pretty_struct ((s, ts), _) = Pretty.block
ballarin@24641
   295
      [Pretty.str s, Pretty.str ":", Pretty.brk 1,
ballarin@24641
   296
       Pretty.enclose "(" ")" (Pretty.breaks (map pretty_term ts))];
ballarin@24641
   297
  in
ballarin@24641
   298
    Pretty.writeln (Pretty.big_list "Order structures:" (map pretty_struct structs))
ballarin@24641
   299
  end;
ballarin@24641
   300
ballarin@24641
   301
ballarin@24641
   302
(** Method **)
haftmann@21091
   303
ballarin@24704
   304
fun struct_tac ((s, [eq, le, less]), thms) prems =
ballarin@24641
   305
  let
ballarin@24641
   306
    fun decomp thy (Trueprop $ t) =
ballarin@24641
   307
      let
ballarin@24641
   308
        fun excluded t =
ballarin@24641
   309
          (* exclude numeric types: linear arithmetic subsumes transitivity *)
ballarin@24641
   310
          let val T = type_of t
ballarin@24641
   311
          in
ballarin@24641
   312
	    T = HOLogic.natT orelse T = HOLogic.intT orelse T = HOLogic.realT
ballarin@24641
   313
          end;
ballarin@24741
   314
	fun rel (bin_op $ t1 $ t2) =
ballarin@24641
   315
              if excluded t1 then NONE
ballarin@24641
   316
              else if Pattern.matches thy (eq, bin_op) then SOME (t1, "=", t2)
ballarin@24641
   317
              else if Pattern.matches thy (le, bin_op) then SOME (t1, "<=", t2)
ballarin@24641
   318
              else if Pattern.matches thy (less, bin_op) then SOME (t1, "<", t2)
ballarin@24641
   319
              else NONE
ballarin@24741
   320
	  | rel _ = NONE;
ballarin@24741
   321
	fun dec (Const (@{const_name Not}, _) $ t) = (case rel t
ballarin@24741
   322
	      of NONE => NONE
ballarin@24741
   323
	       | SOME (t1, rel, t2) => SOME (t1, "~" ^ rel, t2))
ballarin@24741
   324
          | dec x = rel x;
ballarin@24641
   325
      in dec t end;
ballarin@24641
   326
  in
ballarin@24641
   327
    case s of
ballarin@24704
   328
      "order" => Order_Tac.partial_tac decomp thms prems
ballarin@24704
   329
    | "linorder" => Order_Tac.linear_tac decomp thms prems
ballarin@24641
   330
    | _ => error ("Unknown kind of order `" ^ s ^ "' encountered in transitivity reasoner.")
ballarin@24641
   331
  end
ballarin@24641
   332
ballarin@24704
   333
fun order_tac prems ctxt =
ballarin@24704
   334
  FIRST' (map (fn s => CHANGED o struct_tac s prems) (Data.get (Context.Proof ctxt)));
ballarin@24641
   335
ballarin@24641
   336
ballarin@24641
   337
(** Attribute **)
ballarin@24641
   338
ballarin@24641
   339
fun add_struct_thm s tag =
ballarin@24641
   340
  Thm.declaration_attribute
ballarin@24641
   341
    (fn thm => Data.map (AList.map_default struct_eq (s, Order_Tac.empty TrueI) (Order_Tac.update tag thm)));
ballarin@24641
   342
fun del_struct s =
ballarin@24641
   343
  Thm.declaration_attribute
ballarin@24641
   344
    (fn _ => Data.map (AList.delete struct_eq s));
ballarin@24641
   345
ballarin@24641
   346
val attribute = Attrib.syntax
ballarin@24641
   347
     (Scan.lift ((Args.add -- Args.name >> (fn (_, s) => SOME s) ||
ballarin@24641
   348
          Args.del >> K NONE) --| Args.colon (* FIXME ||
ballarin@24641
   349
        Scan.succeed true *) ) -- Scan.lift Args.name --
ballarin@24641
   350
      Scan.repeat Args.term
ballarin@24641
   351
      >> (fn ((SOME tag, n), ts) => add_struct_thm (n, ts) tag
ballarin@24641
   352
           | ((NONE, n), ts) => del_struct (n, ts)));
ballarin@24641
   353
ballarin@24641
   354
ballarin@24641
   355
(** Diagnostic command **)
ballarin@24641
   356
ballarin@24641
   357
val print = Toplevel.unknown_context o
ballarin@24641
   358
  Toplevel.keep (Toplevel.node_case
ballarin@24641
   359
    (Context.cases (print_structures o ProofContext.init) print_structures)
ballarin@24641
   360
    (print_structures o Proof.context_of));
ballarin@24641
   361
wenzelm@24867
   362
val _ =
ballarin@24641
   363
  OuterSyntax.improper_command "print_orders"
ballarin@24641
   364
    "print order structures available to transitivity reasoner" OuterKeyword.diag
ballarin@24641
   365
    (Scan.succeed (Toplevel.no_timing o print));
ballarin@24641
   366
ballarin@24641
   367
ballarin@24641
   368
(** Setup **)
ballarin@24641
   369
wenzelm@24867
   370
val setup =
wenzelm@24867
   371
  Method.add_methods
wenzelm@24867
   372
    [("order", Method.ctxt_args (Method.SIMPLE_METHOD' o order_tac []), "transitivity reasoner")] #>
wenzelm@24867
   373
  Attrib.add_attributes [("order", attribute, "theorems controlling transitivity reasoner")];
haftmann@21091
   374
haftmann@21091
   375
end;
ballarin@24641
   376
haftmann@21091
   377
*}
haftmann@21091
   378
ballarin@24641
   379
setup Orders.setup
ballarin@24641
   380
ballarin@24641
   381
ballarin@24641
   382
text {* Declarations to set up transitivity reasoner of partial and linear orders. *}
ballarin@24641
   383
haftmann@25076
   384
context order
haftmann@25076
   385
begin
haftmann@25076
   386
ballarin@24641
   387
(* The type constraint on @{term op =} below is necessary since the operation
ballarin@24641
   388
   is not a parameter of the locale. *)
haftmann@25076
   389
haftmann@25076
   390
lemmas
haftmann@25076
   391
  [order add less_reflE: order "op = :: 'a \<Rightarrow> 'a \<Rightarrow> bool" "op <=" "op <"] =
ballarin@24641
   392
  less_irrefl [THEN notE]
haftmann@25076
   393
lemmas
haftmann@25062
   394
  [order add le_refl: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   395
  order_refl
haftmann@25076
   396
lemmas
haftmann@25062
   397
  [order add less_imp_le: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   398
  less_imp_le
haftmann@25076
   399
lemmas
haftmann@25062
   400
  [order add eqI: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   401
  antisym
haftmann@25076
   402
lemmas
haftmann@25062
   403
  [order add eqD1: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   404
  eq_refl
haftmann@25076
   405
lemmas
haftmann@25062
   406
  [order add eqD2: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   407
  sym [THEN eq_refl]
haftmann@25076
   408
lemmas
haftmann@25062
   409
  [order add less_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   410
  less_trans
haftmann@25076
   411
lemmas
haftmann@25062
   412
  [order add less_le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   413
  less_le_trans
haftmann@25076
   414
lemmas
haftmann@25062
   415
  [order add le_less_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   416
  le_less_trans
haftmann@25076
   417
lemmas
haftmann@25062
   418
  [order add le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   419
  order_trans
haftmann@25076
   420
lemmas
haftmann@25062
   421
  [order add le_neq_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   422
  le_neq_trans
haftmann@25076
   423
lemmas
haftmann@25062
   424
  [order add neq_le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   425
  neq_le_trans
haftmann@25076
   426
lemmas
haftmann@25062
   427
  [order add less_imp_neq: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   428
  less_imp_neq
haftmann@25076
   429
lemmas
haftmann@25062
   430
  [order add eq_neq_eq_imp_neq: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   431
   eq_neq_eq_imp_neq
haftmann@25076
   432
lemmas
haftmann@25062
   433
  [order add not_sym: order "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   434
  not_sym
ballarin@24641
   435
haftmann@25076
   436
end
haftmann@25076
   437
haftmann@25076
   438
context linorder
haftmann@25076
   439
begin
ballarin@24641
   440
haftmann@25076
   441
lemmas
haftmann@25076
   442
  [order del: order "op = :: 'a => 'a => bool" "op <=" "op <"] = _
haftmann@25076
   443
haftmann@25076
   444
lemmas
haftmann@25062
   445
  [order add less_reflE: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   446
  less_irrefl [THEN notE]
haftmann@25076
   447
lemmas
haftmann@25062
   448
  [order add le_refl: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   449
  order_refl
haftmann@25076
   450
lemmas
haftmann@25062
   451
  [order add less_imp_le: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   452
  less_imp_le
haftmann@25076
   453
lemmas
haftmann@25062
   454
  [order add not_lessI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   455
  not_less [THEN iffD2]
haftmann@25076
   456
lemmas
haftmann@25062
   457
  [order add not_leI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   458
  not_le [THEN iffD2]
haftmann@25076
   459
lemmas
haftmann@25062
   460
  [order add not_lessD: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   461
  not_less [THEN iffD1]
haftmann@25076
   462
lemmas
haftmann@25062
   463
  [order add not_leD: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   464
  not_le [THEN iffD1]
haftmann@25076
   465
lemmas
haftmann@25062
   466
  [order add eqI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   467
  antisym
haftmann@25076
   468
lemmas
haftmann@25062
   469
  [order add eqD1: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   470
  eq_refl
haftmann@25076
   471
lemmas
haftmann@25062
   472
  [order add eqD2: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   473
  sym [THEN eq_refl]
haftmann@25076
   474
lemmas
haftmann@25062
   475
  [order add less_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   476
  less_trans
haftmann@25076
   477
lemmas
haftmann@25062
   478
  [order add less_le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   479
  less_le_trans
haftmann@25076
   480
lemmas
haftmann@25062
   481
  [order add le_less_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   482
  le_less_trans
haftmann@25076
   483
lemmas
haftmann@25062
   484
  [order add le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   485
  order_trans
haftmann@25076
   486
lemmas
haftmann@25062
   487
  [order add le_neq_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   488
  le_neq_trans
haftmann@25076
   489
lemmas
haftmann@25062
   490
  [order add neq_le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   491
  neq_le_trans
haftmann@25076
   492
lemmas
haftmann@25062
   493
  [order add less_imp_neq: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   494
  less_imp_neq
haftmann@25076
   495
lemmas
haftmann@25062
   496
  [order add eq_neq_eq_imp_neq: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   497
  eq_neq_eq_imp_neq
haftmann@25076
   498
lemmas
haftmann@25062
   499
  [order add not_sym: linorder "op = :: 'a => 'a => bool" "op <=" "op <"] =
ballarin@24641
   500
  not_sym
ballarin@24641
   501
haftmann@25076
   502
end
haftmann@25076
   503
ballarin@24641
   504
haftmann@21083
   505
setup {*
haftmann@21083
   506
let
haftmann@21083
   507
haftmann@21083
   508
fun prp t thm = (#prop (rep_thm thm) = t);
nipkow@15524
   509
haftmann@21083
   510
fun prove_antisym_le sg ss ((le as Const(_,T)) $ r $ s) =
haftmann@21083
   511
  let val prems = prems_of_ss ss;
haftmann@22916
   512
      val less = Const (@{const_name less}, T);
haftmann@21083
   513
      val t = HOLogic.mk_Trueprop(le $ s $ r);
haftmann@21083
   514
  in case find_first (prp t) prems of
haftmann@21083
   515
       NONE =>
haftmann@21083
   516
         let val t = HOLogic.mk_Trueprop(HOLogic.Not $ (less $ r $ s))
haftmann@21083
   517
         in case find_first (prp t) prems of
haftmann@21083
   518
              NONE => NONE
haftmann@24422
   519
            | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv1}))
haftmann@21083
   520
         end
haftmann@24422
   521
     | SOME thm => SOME(mk_meta_eq(thm RS @{thm order_class.antisym_conv}))
haftmann@21083
   522
  end
haftmann@21083
   523
  handle THM _ => NONE;
nipkow@15524
   524
haftmann@21083
   525
fun prove_antisym_less sg ss (NotC $ ((less as Const(_,T)) $ r $ s)) =
haftmann@21083
   526
  let val prems = prems_of_ss ss;
haftmann@22916
   527
      val le = Const (@{const_name less_eq}, T);
haftmann@21083
   528
      val t = HOLogic.mk_Trueprop(le $ r $ s);
haftmann@21083
   529
  in case find_first (prp t) prems of
haftmann@21083
   530
       NONE =>
haftmann@21083
   531
         let val t = HOLogic.mk_Trueprop(NotC $ (less $ s $ r))
haftmann@21083
   532
         in case find_first (prp t) prems of
haftmann@21083
   533
              NONE => NONE
haftmann@24422
   534
            | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv3}))
haftmann@21083
   535
         end
haftmann@24422
   536
     | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv2}))
haftmann@21083
   537
  end
haftmann@21083
   538
  handle THM _ => NONE;
nipkow@15524
   539
haftmann@21248
   540
fun add_simprocs procs thy =
wenzelm@26496
   541
  Simplifier.map_simpset (fn ss => ss
haftmann@21248
   542
    addsimprocs (map (fn (name, raw_ts, proc) =>
wenzelm@26496
   543
      Simplifier.simproc thy name raw_ts proc) procs)) thy;
wenzelm@26496
   544
fun add_solver name tac =
wenzelm@26496
   545
  Simplifier.map_simpset (fn ss => ss addSolver
wenzelm@26496
   546
    mk_solver' name (fn ss => tac (Simplifier.prems_of_ss ss) (Simplifier.the_context ss)));
haftmann@21083
   547
haftmann@21083
   548
in
haftmann@21248
   549
  add_simprocs [
haftmann@21248
   550
       ("antisym le", ["(x::'a::order) <= y"], prove_antisym_le),
haftmann@21248
   551
       ("antisym less", ["~ (x::'a::linorder) < y"], prove_antisym_less)
haftmann@21248
   552
     ]
ballarin@24641
   553
  #> add_solver "Transitivity" Orders.order_tac
haftmann@21248
   554
  (* Adding the transitivity reasoners also as safe solvers showed a slight
haftmann@21248
   555
     speed up, but the reasoning strength appears to be not higher (at least
haftmann@21248
   556
     no breaking of additional proofs in the entire HOL distribution, as
haftmann@21248
   557
     of 5 March 2004, was observed). *)
haftmann@21083
   558
end
haftmann@21083
   559
*}
nipkow@15524
   560
nipkow@15524
   561
haftmann@24422
   562
subsection {* Name duplicates *}
haftmann@24422
   563
haftmann@24422
   564
lemmas order_less_le = less_le
haftmann@24422
   565
lemmas order_eq_refl = order_class.eq_refl
haftmann@24422
   566
lemmas order_less_irrefl = order_class.less_irrefl
haftmann@24422
   567
lemmas order_le_less = order_class.le_less
haftmann@24422
   568
lemmas order_le_imp_less_or_eq = order_class.le_imp_less_or_eq
haftmann@24422
   569
lemmas order_less_imp_le = order_class.less_imp_le
haftmann@24422
   570
lemmas order_less_imp_not_eq = order_class.less_imp_not_eq
haftmann@24422
   571
lemmas order_less_imp_not_eq2 = order_class.less_imp_not_eq2
haftmann@24422
   572
lemmas order_neq_le_trans = order_class.neq_le_trans
haftmann@24422
   573
lemmas order_le_neq_trans = order_class.le_neq_trans
haftmann@24422
   574
haftmann@24422
   575
lemmas order_antisym = antisym
haftmann@24422
   576
lemmas order_less_not_sym = order_class.less_not_sym
haftmann@24422
   577
lemmas order_less_asym = order_class.less_asym
haftmann@24422
   578
lemmas order_eq_iff = order_class.eq_iff
haftmann@24422
   579
lemmas order_antisym_conv = order_class.antisym_conv
haftmann@24422
   580
lemmas order_less_trans = order_class.less_trans
haftmann@24422
   581
lemmas order_le_less_trans = order_class.le_less_trans
haftmann@24422
   582
lemmas order_less_le_trans = order_class.less_le_trans
haftmann@24422
   583
lemmas order_less_imp_not_less = order_class.less_imp_not_less
haftmann@24422
   584
lemmas order_less_imp_triv = order_class.less_imp_triv
haftmann@24422
   585
lemmas order_less_asym' = order_class.less_asym'
haftmann@24422
   586
haftmann@24422
   587
lemmas linorder_linear = linear
haftmann@24422
   588
lemmas linorder_less_linear = linorder_class.less_linear
haftmann@24422
   589
lemmas linorder_le_less_linear = linorder_class.le_less_linear
haftmann@24422
   590
lemmas linorder_le_cases = linorder_class.le_cases
haftmann@24422
   591
lemmas linorder_not_less = linorder_class.not_less
haftmann@24422
   592
lemmas linorder_not_le = linorder_class.not_le
haftmann@24422
   593
lemmas linorder_neq_iff = linorder_class.neq_iff
haftmann@24422
   594
lemmas linorder_neqE = linorder_class.neqE
haftmann@24422
   595
lemmas linorder_antisym_conv1 = linorder_class.antisym_conv1
haftmann@24422
   596
lemmas linorder_antisym_conv2 = linorder_class.antisym_conv2
haftmann@24422
   597
lemmas linorder_antisym_conv3 = linorder_class.antisym_conv3
haftmann@24422
   598
haftmann@24422
   599
haftmann@21083
   600
subsection {* Bounded quantifiers *}
haftmann@21083
   601
haftmann@21083
   602
syntax
wenzelm@21180
   603
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3ALL _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   604
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3EX _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   605
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _<=_./ _)" [0, 0, 10] 10)
wenzelm@21180
   606
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _<=_./ _)" [0, 0, 10] 10)
haftmann@21083
   607
wenzelm@21180
   608
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3ALL _>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   609
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3EX _>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   610
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _>=_./ _)" [0, 0, 10] 10)
wenzelm@21180
   611
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _>=_./ _)" [0, 0, 10] 10)
haftmann@21083
   612
haftmann@21083
   613
syntax (xsymbols)
wenzelm@21180
   614
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   615
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   616
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   617
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083
   618
wenzelm@21180
   619
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   620
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   621
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   622
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083
   623
haftmann@21083
   624
syntax (HOL)
wenzelm@21180
   625
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3! _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   626
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3? _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   627
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3! _<=_./ _)" [0, 0, 10] 10)
wenzelm@21180
   628
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3? _<=_./ _)" [0, 0, 10] 10)
haftmann@21083
   629
haftmann@21083
   630
syntax (HTML output)
wenzelm@21180
   631
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   632
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   633
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   634
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083
   635
wenzelm@21180
   636
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   637
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   638
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   639
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083
   640
haftmann@21083
   641
translations
haftmann@21083
   642
  "ALL x<y. P"   =>  "ALL x. x < y \<longrightarrow> P"
haftmann@21083
   643
  "EX x<y. P"    =>  "EX x. x < y \<and> P"
haftmann@21083
   644
  "ALL x<=y. P"  =>  "ALL x. x <= y \<longrightarrow> P"
haftmann@21083
   645
  "EX x<=y. P"   =>  "EX x. x <= y \<and> P"
haftmann@21083
   646
  "ALL x>y. P"   =>  "ALL x. x > y \<longrightarrow> P"
haftmann@21083
   647
  "EX x>y. P"    =>  "EX x. x > y \<and> P"
haftmann@21083
   648
  "ALL x>=y. P"  =>  "ALL x. x >= y \<longrightarrow> P"
haftmann@21083
   649
  "EX x>=y. P"   =>  "EX x. x >= y \<and> P"
haftmann@21083
   650
haftmann@21083
   651
print_translation {*
haftmann@21083
   652
let
haftmann@22916
   653
  val All_binder = Syntax.binder_name @{const_syntax All};
haftmann@22916
   654
  val Ex_binder = Syntax.binder_name @{const_syntax Ex};
wenzelm@22377
   655
  val impl = @{const_syntax "op -->"};
wenzelm@22377
   656
  val conj = @{const_syntax "op &"};
haftmann@22916
   657
  val less = @{const_syntax less};
haftmann@22916
   658
  val less_eq = @{const_syntax less_eq};
wenzelm@21180
   659
wenzelm@21180
   660
  val trans =
wenzelm@21524
   661
   [((All_binder, impl, less), ("_All_less", "_All_greater")),
wenzelm@21524
   662
    ((All_binder, impl, less_eq), ("_All_less_eq", "_All_greater_eq")),
wenzelm@21524
   663
    ((Ex_binder, conj, less), ("_Ex_less", "_Ex_greater")),
wenzelm@21524
   664
    ((Ex_binder, conj, less_eq), ("_Ex_less_eq", "_Ex_greater_eq"))];
wenzelm@21180
   665
krauss@22344
   666
  fun matches_bound v t = 
krauss@22344
   667
     case t of (Const ("_bound", _) $ Free (v', _)) => (v = v')
krauss@22344
   668
              | _ => false
krauss@22344
   669
  fun contains_var v = Term.exists_subterm (fn Free (x, _) => x = v | _ => false)
krauss@22344
   670
  fun mk v c n P = Syntax.const c $ Syntax.mark_bound v $ n $ P
wenzelm@21180
   671
wenzelm@21180
   672
  fun tr' q = (q,
wenzelm@21180
   673
    fn [Const ("_bound", _) $ Free (v, _), Const (c, _) $ (Const (d, _) $ t $ u) $ P] =>
wenzelm@21180
   674
      (case AList.lookup (op =) trans (q, c, d) of
wenzelm@21180
   675
        NONE => raise Match
wenzelm@21180
   676
      | SOME (l, g) =>
krauss@22344
   677
          if matches_bound v t andalso not (contains_var v u) then mk v l u P
krauss@22344
   678
          else if matches_bound v u andalso not (contains_var v t) then mk v g t P
krauss@22344
   679
          else raise Match)
wenzelm@21180
   680
     | _ => raise Match);
wenzelm@21524
   681
in [tr' All_binder, tr' Ex_binder] end
haftmann@21083
   682
*}
haftmann@21083
   683
haftmann@21083
   684
haftmann@21383
   685
subsection {* Transitivity reasoning *}
haftmann@21383
   686
haftmann@25193
   687
context ord
haftmann@25193
   688
begin
haftmann@21383
   689
haftmann@25193
   690
lemma ord_le_eq_trans: "a \<le> b \<Longrightarrow> b = c \<Longrightarrow> a \<le> c"
haftmann@25193
   691
  by (rule subst)
haftmann@21383
   692
haftmann@25193
   693
lemma ord_eq_le_trans: "a = b \<Longrightarrow> b \<le> c \<Longrightarrow> a \<le> c"
haftmann@25193
   694
  by (rule ssubst)
haftmann@21383
   695
haftmann@25193
   696
lemma ord_less_eq_trans: "a < b \<Longrightarrow> b = c \<Longrightarrow> a < c"
haftmann@25193
   697
  by (rule subst)
haftmann@25193
   698
haftmann@25193
   699
lemma ord_eq_less_trans: "a = b \<Longrightarrow> b < c \<Longrightarrow> a < c"
haftmann@25193
   700
  by (rule ssubst)
haftmann@25193
   701
haftmann@25193
   702
end
haftmann@21383
   703
haftmann@21383
   704
lemma order_less_subst2: "(a::'a::order) < b ==> f b < (c::'c::order) ==>
haftmann@21383
   705
  (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383
   706
proof -
haftmann@21383
   707
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   708
  assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383
   709
  also assume "f b < c"
haftmann@21383
   710
  finally (order_less_trans) show ?thesis .
haftmann@21383
   711
qed
haftmann@21383
   712
haftmann@21383
   713
lemma order_less_subst1: "(a::'a::order) < f b ==> (b::'b::order) < c ==>
haftmann@21383
   714
  (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383
   715
proof -
haftmann@21383
   716
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   717
  assume "a < f b"
haftmann@21383
   718
  also assume "b < c" hence "f b < f c" by (rule r)
haftmann@21383
   719
  finally (order_less_trans) show ?thesis .
haftmann@21383
   720
qed
haftmann@21383
   721
haftmann@21383
   722
lemma order_le_less_subst2: "(a::'a::order) <= b ==> f b < (c::'c::order) ==>
haftmann@21383
   723
  (!!x y. x <= y ==> f x <= f y) ==> f a < c"
haftmann@21383
   724
proof -
haftmann@21383
   725
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   726
  assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383
   727
  also assume "f b < c"
haftmann@21383
   728
  finally (order_le_less_trans) show ?thesis .
haftmann@21383
   729
qed
haftmann@21383
   730
haftmann@21383
   731
lemma order_le_less_subst1: "(a::'a::order) <= f b ==> (b::'b::order) < c ==>
haftmann@21383
   732
  (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383
   733
proof -
haftmann@21383
   734
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   735
  assume "a <= f b"
haftmann@21383
   736
  also assume "b < c" hence "f b < f c" by (rule r)
haftmann@21383
   737
  finally (order_le_less_trans) show ?thesis .
haftmann@21383
   738
qed
haftmann@21383
   739
haftmann@21383
   740
lemma order_less_le_subst2: "(a::'a::order) < b ==> f b <= (c::'c::order) ==>
haftmann@21383
   741
  (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383
   742
proof -
haftmann@21383
   743
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   744
  assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383
   745
  also assume "f b <= c"
haftmann@21383
   746
  finally (order_less_le_trans) show ?thesis .
haftmann@21383
   747
qed
haftmann@21383
   748
haftmann@21383
   749
lemma order_less_le_subst1: "(a::'a::order) < f b ==> (b::'b::order) <= c ==>
haftmann@21383
   750
  (!!x y. x <= y ==> f x <= f y) ==> a < f c"
haftmann@21383
   751
proof -
haftmann@21383
   752
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   753
  assume "a < f b"
haftmann@21383
   754
  also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@21383
   755
  finally (order_less_le_trans) show ?thesis .
haftmann@21383
   756
qed
haftmann@21383
   757
haftmann@21383
   758
lemma order_subst1: "(a::'a::order) <= f b ==> (b::'b::order) <= c ==>
haftmann@21383
   759
  (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
haftmann@21383
   760
proof -
haftmann@21383
   761
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   762
  assume "a <= f b"
haftmann@21383
   763
  also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@21383
   764
  finally (order_trans) show ?thesis .
haftmann@21383
   765
qed
haftmann@21383
   766
haftmann@21383
   767
lemma order_subst2: "(a::'a::order) <= b ==> f b <= (c::'c::order) ==>
haftmann@21383
   768
  (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
haftmann@21383
   769
proof -
haftmann@21383
   770
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   771
  assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383
   772
  also assume "f b <= c"
haftmann@21383
   773
  finally (order_trans) show ?thesis .
haftmann@21383
   774
qed
haftmann@21383
   775
haftmann@21383
   776
lemma ord_le_eq_subst: "a <= b ==> f b = c ==>
haftmann@21383
   777
  (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
haftmann@21383
   778
proof -
haftmann@21383
   779
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   780
  assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383
   781
  also assume "f b = c"
haftmann@21383
   782
  finally (ord_le_eq_trans) show ?thesis .
haftmann@21383
   783
qed
haftmann@21383
   784
haftmann@21383
   785
lemma ord_eq_le_subst: "a = f b ==> b <= c ==>
haftmann@21383
   786
  (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
haftmann@21383
   787
proof -
haftmann@21383
   788
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   789
  assume "a = f b"
haftmann@21383
   790
  also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@21383
   791
  finally (ord_eq_le_trans) show ?thesis .
haftmann@21383
   792
qed
haftmann@21383
   793
haftmann@21383
   794
lemma ord_less_eq_subst: "a < b ==> f b = c ==>
haftmann@21383
   795
  (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383
   796
proof -
haftmann@21383
   797
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   798
  assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383
   799
  also assume "f b = c"
haftmann@21383
   800
  finally (ord_less_eq_trans) show ?thesis .
haftmann@21383
   801
qed
haftmann@21383
   802
haftmann@21383
   803
lemma ord_eq_less_subst: "a = f b ==> b < c ==>
haftmann@21383
   804
  (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383
   805
proof -
haftmann@21383
   806
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   807
  assume "a = f b"
haftmann@21383
   808
  also assume "b < c" hence "f b < f c" by (rule r)
haftmann@21383
   809
  finally (ord_eq_less_trans) show ?thesis .
haftmann@21383
   810
qed
haftmann@21383
   811
haftmann@21383
   812
text {*
haftmann@21383
   813
  Note that this list of rules is in reverse order of priorities.
haftmann@21383
   814
*}
haftmann@21383
   815
haftmann@21383
   816
lemmas order_trans_rules [trans] =
haftmann@21383
   817
  order_less_subst2
haftmann@21383
   818
  order_less_subst1
haftmann@21383
   819
  order_le_less_subst2
haftmann@21383
   820
  order_le_less_subst1
haftmann@21383
   821
  order_less_le_subst2
haftmann@21383
   822
  order_less_le_subst1
haftmann@21383
   823
  order_subst2
haftmann@21383
   824
  order_subst1
haftmann@21383
   825
  ord_le_eq_subst
haftmann@21383
   826
  ord_eq_le_subst
haftmann@21383
   827
  ord_less_eq_subst
haftmann@21383
   828
  ord_eq_less_subst
haftmann@21383
   829
  forw_subst
haftmann@21383
   830
  back_subst
haftmann@21383
   831
  rev_mp
haftmann@21383
   832
  mp
haftmann@21383
   833
  order_neq_le_trans
haftmann@21383
   834
  order_le_neq_trans
haftmann@21383
   835
  order_less_trans
haftmann@21383
   836
  order_less_asym'
haftmann@21383
   837
  order_le_less_trans
haftmann@21383
   838
  order_less_le_trans
haftmann@21383
   839
  order_trans
haftmann@21383
   840
  order_antisym
haftmann@21383
   841
  ord_le_eq_trans
haftmann@21383
   842
  ord_eq_le_trans
haftmann@21383
   843
  ord_less_eq_trans
haftmann@21383
   844
  ord_eq_less_trans
haftmann@21383
   845
  trans
haftmann@21383
   846
haftmann@21083
   847
wenzelm@21180
   848
(* FIXME cleanup *)
wenzelm@21180
   849
haftmann@21083
   850
text {* These support proving chains of decreasing inequalities
haftmann@21083
   851
    a >= b >= c ... in Isar proofs. *}
haftmann@21083
   852
haftmann@21083
   853
lemma xt1:
haftmann@21083
   854
  "a = b ==> b > c ==> a > c"
haftmann@21083
   855
  "a > b ==> b = c ==> a > c"
haftmann@21083
   856
  "a = b ==> b >= c ==> a >= c"
haftmann@21083
   857
  "a >= b ==> b = c ==> a >= c"
haftmann@21083
   858
  "(x::'a::order) >= y ==> y >= x ==> x = y"
haftmann@21083
   859
  "(x::'a::order) >= y ==> y >= z ==> x >= z"
haftmann@21083
   860
  "(x::'a::order) > y ==> y >= z ==> x > z"
haftmann@21083
   861
  "(x::'a::order) >= y ==> y > z ==> x > z"
wenzelm@23417
   862
  "(a::'a::order) > b ==> b > a ==> P"
haftmann@21083
   863
  "(x::'a::order) > y ==> y > z ==> x > z"
haftmann@21083
   864
  "(a::'a::order) >= b ==> a ~= b ==> a > b"
haftmann@21083
   865
  "(a::'a::order) ~= b ==> a >= b ==> a > b"
haftmann@21083
   866
  "a = f b ==> b > c ==> (!!x y. x > y ==> f x > f y) ==> a > f c" 
haftmann@21083
   867
  "a > b ==> f b = c ==> (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
   868
  "a = f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
haftmann@21083
   869
  "a >= b ==> f b = c ==> (!! x y. x >= y ==> f x >= f y) ==> f a >= c"
haftmann@25076
   870
  by auto
haftmann@21083
   871
haftmann@21083
   872
lemma xt2:
haftmann@21083
   873
  "(a::'a::order) >= f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
haftmann@21083
   874
by (subgoal_tac "f b >= f c", force, force)
haftmann@21083
   875
haftmann@21083
   876
lemma xt3: "(a::'a::order) >= b ==> (f b::'b::order) >= c ==> 
haftmann@21083
   877
    (!!x y. x >= y ==> f x >= f y) ==> f a >= c"
haftmann@21083
   878
by (subgoal_tac "f a >= f b", force, force)
haftmann@21083
   879
haftmann@21083
   880
lemma xt4: "(a::'a::order) > f b ==> (b::'b::order) >= c ==>
haftmann@21083
   881
  (!!x y. x >= y ==> f x >= f y) ==> a > f c"
haftmann@21083
   882
by (subgoal_tac "f b >= f c", force, force)
haftmann@21083
   883
haftmann@21083
   884
lemma xt5: "(a::'a::order) > b ==> (f b::'b::order) >= c==>
haftmann@21083
   885
    (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
   886
by (subgoal_tac "f a > f b", force, force)
haftmann@21083
   887
haftmann@21083
   888
lemma xt6: "(a::'a::order) >= f b ==> b > c ==>
haftmann@21083
   889
    (!!x y. x > y ==> f x > f y) ==> a > f c"
haftmann@21083
   890
by (subgoal_tac "f b > f c", force, force)
haftmann@21083
   891
haftmann@21083
   892
lemma xt7: "(a::'a::order) >= b ==> (f b::'b::order) > c ==>
haftmann@21083
   893
    (!!x y. x >= y ==> f x >= f y) ==> f a > c"
haftmann@21083
   894
by (subgoal_tac "f a >= f b", force, force)
haftmann@21083
   895
haftmann@21083
   896
lemma xt8: "(a::'a::order) > f b ==> (b::'b::order) > c ==>
haftmann@21083
   897
    (!!x y. x > y ==> f x > f y) ==> a > f c"
haftmann@21083
   898
by (subgoal_tac "f b > f c", force, force)
haftmann@21083
   899
haftmann@21083
   900
lemma xt9: "(a::'a::order) > b ==> (f b::'b::order) > c ==>
haftmann@21083
   901
    (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
   902
by (subgoal_tac "f a > f b", force, force)
haftmann@21083
   903
haftmann@21083
   904
lemmas xtrans = xt1 xt2 xt3 xt4 xt5 xt6 xt7 xt8 xt9
haftmann@21083
   905
haftmann@21083
   906
(* 
haftmann@21083
   907
  Since "a >= b" abbreviates "b <= a", the abbreviation "..." stands
haftmann@21083
   908
  for the wrong thing in an Isar proof.
haftmann@21083
   909
haftmann@21083
   910
  The extra transitivity rules can be used as follows: 
haftmann@21083
   911
haftmann@21083
   912
lemma "(a::'a::order) > z"
haftmann@21083
   913
proof -
haftmann@21083
   914
  have "a >= b" (is "_ >= ?rhs")
haftmann@21083
   915
    sorry
haftmann@21083
   916
  also have "?rhs >= c" (is "_ >= ?rhs")
haftmann@21083
   917
    sorry
haftmann@21083
   918
  also (xtrans) have "?rhs = d" (is "_ = ?rhs")
haftmann@21083
   919
    sorry
haftmann@21083
   920
  also (xtrans) have "?rhs >= e" (is "_ >= ?rhs")
haftmann@21083
   921
    sorry
haftmann@21083
   922
  also (xtrans) have "?rhs > f" (is "_ > ?rhs")
haftmann@21083
   923
    sorry
haftmann@21083
   924
  also (xtrans) have "?rhs > z"
haftmann@21083
   925
    sorry
haftmann@21083
   926
  finally (xtrans) show ?thesis .
haftmann@21083
   927
qed
haftmann@21083
   928
haftmann@21083
   929
  Alternatively, one can use "declare xtrans [trans]" and then
haftmann@21083
   930
  leave out the "(xtrans)" above.
haftmann@21083
   931
*)
haftmann@21083
   932
haftmann@21546
   933
subsection {* Order on bool *}
haftmann@21546
   934
haftmann@26324
   935
instantiation bool :: order
haftmann@25510
   936
begin
haftmann@25510
   937
haftmann@25510
   938
definition
haftmann@25510
   939
  le_bool_def [code func del]: "P \<le> Q \<longleftrightarrow> P \<longrightarrow> Q"
haftmann@25510
   940
haftmann@25510
   941
definition
haftmann@25510
   942
  less_bool_def [code func del]: "(P\<Colon>bool) < Q \<longleftrightarrow> P \<le> Q \<and> P \<noteq> Q"
haftmann@25510
   943
haftmann@25510
   944
instance
haftmann@22916
   945
  by intro_classes (auto simp add: le_bool_def less_bool_def)
haftmann@25510
   946
haftmann@25510
   947
end
haftmann@21546
   948
haftmann@21546
   949
lemma le_boolI: "(P \<Longrightarrow> Q) \<Longrightarrow> P \<le> Q"
nipkow@23212
   950
by (simp add: le_bool_def)
haftmann@21546
   951
haftmann@21546
   952
lemma le_boolI': "P \<longrightarrow> Q \<Longrightarrow> P \<le> Q"
nipkow@23212
   953
by (simp add: le_bool_def)
haftmann@21546
   954
haftmann@21546
   955
lemma le_boolE: "P \<le> Q \<Longrightarrow> P \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
nipkow@23212
   956
by (simp add: le_bool_def)
haftmann@21546
   957
haftmann@21546
   958
lemma le_boolD: "P \<le> Q \<Longrightarrow> P \<longrightarrow> Q"
nipkow@23212
   959
by (simp add: le_bool_def)
haftmann@21546
   960
haftmann@22348
   961
lemma [code func]:
haftmann@22348
   962
  "False \<le> b \<longleftrightarrow> True"
haftmann@22348
   963
  "True \<le> b \<longleftrightarrow> b"
haftmann@22348
   964
  "False < b \<longleftrightarrow> b"
haftmann@22348
   965
  "True < b \<longleftrightarrow> False"
haftmann@22348
   966
  unfolding le_bool_def less_bool_def by simp_all
haftmann@22348
   967
haftmann@22424
   968
haftmann@23881
   969
subsection {* Order on functions *}
haftmann@23881
   970
haftmann@25510
   971
instantiation "fun" :: (type, ord) ord
haftmann@25510
   972
begin
haftmann@25510
   973
haftmann@25510
   974
definition
haftmann@25510
   975
  le_fun_def [code func del]: "f \<le> g \<longleftrightarrow> (\<forall>x. f x \<le> g x)"
haftmann@23881
   976
haftmann@25510
   977
definition
haftmann@25510
   978
  less_fun_def [code func del]: "(f\<Colon>'a \<Rightarrow> 'b) < g \<longleftrightarrow> f \<le> g \<and> f \<noteq> g"
haftmann@25510
   979
haftmann@25510
   980
instance ..
haftmann@25510
   981
haftmann@25510
   982
end
haftmann@23881
   983
haftmann@23881
   984
instance "fun" :: (type, order) order
haftmann@23881
   985
  by default
berghofe@26796
   986
    (auto simp add: le_fun_def less_fun_def
berghofe@26796
   987
       intro: order_trans order_antisym intro!: ext)
haftmann@23881
   988
haftmann@23881
   989
lemma le_funI: "(\<And>x. f x \<le> g x) \<Longrightarrow> f \<le> g"
haftmann@23881
   990
  unfolding le_fun_def by simp
haftmann@23881
   991
haftmann@23881
   992
lemma le_funE: "f \<le> g \<Longrightarrow> (f x \<le> g x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@23881
   993
  unfolding le_fun_def by simp
haftmann@23881
   994
haftmann@23881
   995
lemma le_funD: "f \<le> g \<Longrightarrow> f x \<le> g x"
haftmann@23881
   996
  unfolding le_fun_def by simp
haftmann@23881
   997
haftmann@23881
   998
text {*
haftmann@23881
   999
  Handy introduction and elimination rules for @{text "\<le>"}
haftmann@23881
  1000
  on unary and binary predicates
haftmann@23881
  1001
*}
haftmann@23881
  1002
berghofe@26796
  1003
lemma predicate1I:
haftmann@23881
  1004
  assumes PQ: "\<And>x. P x \<Longrightarrow> Q x"
haftmann@23881
  1005
  shows "P \<le> Q"
haftmann@23881
  1006
  apply (rule le_funI)
haftmann@23881
  1007
  apply (rule le_boolI)
haftmann@23881
  1008
  apply (rule PQ)
haftmann@23881
  1009
  apply assumption
haftmann@23881
  1010
  done
haftmann@23881
  1011
haftmann@23881
  1012
lemma predicate1D [Pure.dest, dest]: "P \<le> Q \<Longrightarrow> P x \<Longrightarrow> Q x"
haftmann@23881
  1013
  apply (erule le_funE)
haftmann@23881
  1014
  apply (erule le_boolE)
haftmann@23881
  1015
  apply assumption+
haftmann@23881
  1016
  done
haftmann@23881
  1017
haftmann@23881
  1018
lemma predicate2I [Pure.intro!, intro!]:
haftmann@23881
  1019
  assumes PQ: "\<And>x y. P x y \<Longrightarrow> Q x y"
haftmann@23881
  1020
  shows "P \<le> Q"
haftmann@23881
  1021
  apply (rule le_funI)+
haftmann@23881
  1022
  apply (rule le_boolI)
haftmann@23881
  1023
  apply (rule PQ)
haftmann@23881
  1024
  apply assumption
haftmann@23881
  1025
  done
haftmann@23881
  1026
haftmann@23881
  1027
lemma predicate2D [Pure.dest, dest]: "P \<le> Q \<Longrightarrow> P x y \<Longrightarrow> Q x y"
haftmann@23881
  1028
  apply (erule le_funE)+
haftmann@23881
  1029
  apply (erule le_boolE)
haftmann@23881
  1030
  apply assumption+
haftmann@23881
  1031
  done
haftmann@23881
  1032
haftmann@23881
  1033
lemma rev_predicate1D: "P x ==> P <= Q ==> Q x"
haftmann@23881
  1034
  by (rule predicate1D)
haftmann@23881
  1035
haftmann@23881
  1036
lemma rev_predicate2D: "P x y ==> P <= Q ==> Q x y"
haftmann@23881
  1037
  by (rule predicate2D)
haftmann@23881
  1038
haftmann@23881
  1039
haftmann@23881
  1040
subsection {* Monotonicity, least value operator and min/max *}
haftmann@21083
  1041
haftmann@25076
  1042
context order
haftmann@25076
  1043
begin
haftmann@25076
  1044
haftmann@25076
  1045
definition
haftmann@25076
  1046
  mono :: "('a \<Rightarrow> 'b\<Colon>order) \<Rightarrow> bool"
haftmann@25076
  1047
where
haftmann@25076
  1048
  "mono f \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> f x \<le> f y)"
haftmann@25076
  1049
haftmann@25076
  1050
lemma monoI [intro?]:
haftmann@25076
  1051
  fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
haftmann@25076
  1052
  shows "(\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y) \<Longrightarrow> mono f"
haftmann@25076
  1053
  unfolding mono_def by iprover
haftmann@21216
  1054
haftmann@25076
  1055
lemma monoD [dest?]:
haftmann@25076
  1056
  fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
haftmann@25076
  1057
  shows "mono f \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
haftmann@25076
  1058
  unfolding mono_def by iprover
haftmann@25076
  1059
haftmann@25076
  1060
end
haftmann@25076
  1061
haftmann@25076
  1062
context linorder
haftmann@25076
  1063
begin
haftmann@25076
  1064
haftmann@25076
  1065
lemma min_of_mono:
haftmann@25076
  1066
  fixes f :: "'a \<Rightarrow> 'b\<Colon>linorder"
wenzelm@25377
  1067
  shows "mono f \<Longrightarrow> min (f m) (f n) = f (min m n)"
haftmann@25076
  1068
  by (auto simp: mono_def Orderings.min_def min_def intro: Orderings.antisym)
haftmann@25076
  1069
haftmann@25076
  1070
lemma max_of_mono:
haftmann@25076
  1071
  fixes f :: "'a \<Rightarrow> 'b\<Colon>linorder"
wenzelm@25377
  1072
  shows "mono f \<Longrightarrow> max (f m) (f n) = f (max m n)"
haftmann@25076
  1073
  by (auto simp: mono_def Orderings.max_def max_def intro: Orderings.antisym)
haftmann@25076
  1074
haftmann@25076
  1075
end
haftmann@21083
  1076
haftmann@21383
  1077
lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
nipkow@23212
  1078
by (simp add: min_def)
haftmann@21383
  1079
haftmann@21383
  1080
lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
nipkow@23212
  1081
by (simp add: max_def)
haftmann@21383
  1082
haftmann@21383
  1083
lemma min_leastR: "(\<And>x\<Colon>'a\<Colon>order. least \<le> x) \<Longrightarrow> min x least = least"
nipkow@23212
  1084
apply (simp add: min_def)
nipkow@23212
  1085
apply (blast intro: order_antisym)
nipkow@23212
  1086
done
haftmann@21383
  1087
haftmann@21383
  1088
lemma max_leastR: "(\<And>x\<Colon>'a\<Colon>order. least \<le> x) \<Longrightarrow> max x least = x"
nipkow@23212
  1089
apply (simp add: max_def)
nipkow@23212
  1090
apply (blast intro: order_antisym)
nipkow@23212
  1091
done
haftmann@21383
  1092
nipkow@15524
  1093
end