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