src/HOL/Orderings.thy
author haftmann
Fri Oct 20 18:20:22 2006 +0200 (2006-10-20)
changeset 21083 a1de02f047d0
parent 21044 9690be52ee5d
child 21091 5061e3e56484
permissions -rw-r--r--
cleaned up
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@21083
     6
header {* Abstract orderings *}
nipkow@15524
     7
nipkow@15524
     8
theory Orderings
haftmann@21044
     9
imports Code_Generator Lattice_Locales
nipkow@15524
    10
begin
nipkow@15524
    11
haftmann@21083
    12
section {* Abstract orderings *}
haftmann@21083
    13
haftmann@21083
    14
subsection {* Order signatures *}
nipkow@15524
    15
haftmann@20588
    16
class ord = eq +
haftmann@20714
    17
  constrains eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (*FIXME: class_package should do the job*)
haftmann@20588
    18
  fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
haftmann@20588
    19
  fixes less    :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
nipkow@15524
    20
wenzelm@19656
    21
const_syntax
wenzelm@19656
    22
  less  ("op <")
wenzelm@19656
    23
  less  ("(_/ < _)"  [50, 51] 50)
wenzelm@19656
    24
  less_eq  ("op <=")
wenzelm@19656
    25
  less_eq  ("(_/ <= _)" [50, 51] 50)
nipkow@15524
    26
wenzelm@19656
    27
const_syntax (xsymbols)
wenzelm@19656
    28
  less_eq  ("op \<le>")
wenzelm@19656
    29
  less_eq  ("(_/ \<le> _)"  [50, 51] 50)
wenzelm@19656
    30
wenzelm@19656
    31
const_syntax (HTML output)
wenzelm@19656
    32
  less_eq  ("op \<le>")
wenzelm@19656
    33
  less_eq  ("(_/ \<le> _)"  [50, 51] 50)
nipkow@15524
    34
haftmann@20714
    35
haftmann@20714
    36
abbreviation (in ord)
haftmann@20714
    37
  "less_eq_syn \<equiv> less_eq"
haftmann@20714
    38
  "less_syn \<equiv> less"
haftmann@20714
    39
haftmann@20714
    40
const_syntax (in ord) 
haftmann@20714
    41
  less_eq_syn  ("op \<^loc><=")
haftmann@20714
    42
  less_eq_syn  ("(_/ \<^loc><= _)" [50, 51] 50)
haftmann@20714
    43
  less_syn  ("op \<^loc><")
haftmann@20714
    44
  less_syn  ("(_/ \<^loc>< _)"  [50, 51] 50)
haftmann@20714
    45
  
haftmann@20714
    46
const_syntax (in ord) (xsymbols)
haftmann@20714
    47
  less_eq_syn  ("op \<^loc>\<le>")
haftmann@20714
    48
  less_eq_syn  ("(_/ \<^loc>\<le> _)"  [50, 51] 50)
haftmann@20714
    49
haftmann@20714
    50
const_syntax (in ord) (HTML output)
haftmann@20714
    51
  less_eq_syn  ("op \<^loc>\<le>")
haftmann@20714
    52
  less_eq_syn  ("(_/ \<^loc>\<le> _)"  [50, 51] 50)
haftmann@20714
    53
haftmann@20714
    54
wenzelm@19536
    55
abbreviation (input)
wenzelm@19536
    56
  greater  (infixl ">" 50)
haftmann@20714
    57
  "x > y \<equiv> y < x"
wenzelm@19536
    58
  greater_eq  (infixl ">=" 50)
haftmann@20714
    59
  "x >= y \<equiv> y <= x"
haftmann@20714
    60
  
wenzelm@19656
    61
const_syntax (xsymbols)
wenzelm@19656
    62
  greater_eq  (infixl "\<ge>" 50)
nipkow@15524
    63
haftmann@20714
    64
abbreviation (in ord) (input)
haftmann@20714
    65
  greater  (infix "\<^loc>>" 50)
haftmann@20714
    66
  "x \<^loc>> y \<equiv> y \<^loc>< x"
haftmann@20714
    67
  greater_eq  (infix "\<^loc>>=" 50)
haftmann@20714
    68
  "x \<^loc>>= y \<equiv> y \<^loc><= x"
haftmann@20714
    69
haftmann@20714
    70
const_syntax (in ord) (xsymbols)
haftmann@20714
    71
  greater_eq  (infixl "\<^loc>\<ge>" 50)
haftmann@20714
    72
nipkow@15524
    73
haftmann@21083
    74
subsection {* Partial orderings *}
nipkow@15524
    75
nipkow@15524
    76
axclass order < ord
nipkow@15524
    77
  order_refl [iff]: "x <= x"
nipkow@15524
    78
  order_trans: "x <= y ==> y <= z ==> x <= z"
nipkow@15524
    79
  order_antisym: "x <= y ==> y <= x ==> x = y"
nipkow@15524
    80
  order_less_le: "(x < y) = (x <= y & x ~= y)"
nipkow@15524
    81
haftmann@21083
    82
text {* Connection to locale: *}
nipkow@15524
    83
ballarin@15837
    84
interpretation order:
nipkow@15780
    85
  partial_order["op \<le> :: 'a::order \<Rightarrow> 'a \<Rightarrow> bool"]
nipkow@15524
    86
apply(rule partial_order.intro)
nipkow@15524
    87
apply(rule order_refl, erule (1) order_trans, erule (1) order_antisym)
nipkow@15524
    88
done
nipkow@15524
    89
nipkow@15524
    90
text {* Reflexivity. *}
nipkow@15524
    91
nipkow@15524
    92
lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
nipkow@15524
    93
    -- {* This form is useful with the classical reasoner. *}
nipkow@15524
    94
  apply (erule ssubst)
nipkow@15524
    95
  apply (rule order_refl)
nipkow@15524
    96
  done
nipkow@15524
    97
nipkow@15524
    98
lemma order_less_irrefl [iff]: "~ x < (x::'a::order)"
nipkow@15524
    99
  by (simp add: order_less_le)
nipkow@15524
   100
nipkow@15524
   101
lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
nipkow@15524
   102
    -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
nipkow@15524
   103
  apply (simp add: order_less_le, blast)
nipkow@15524
   104
  done
nipkow@15524
   105
nipkow@15524
   106
lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
nipkow@15524
   107
nipkow@15524
   108
lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
nipkow@15524
   109
  by (simp add: order_less_le)
nipkow@15524
   110
nipkow@15524
   111
text {* Asymmetry. *}
nipkow@15524
   112
nipkow@15524
   113
lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
nipkow@15524
   114
  by (simp add: order_less_le order_antisym)
nipkow@15524
   115
nipkow@15524
   116
lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
nipkow@15524
   117
  apply (drule order_less_not_sym)
nipkow@15524
   118
  apply (erule contrapos_np, simp)
nipkow@15524
   119
  done
nipkow@15524
   120
nipkow@15524
   121
lemma order_eq_iff: "!!x::'a::order. (x = y) = (x \<le> y & y \<le> x)"
nipkow@15524
   122
by (blast intro: order_antisym)
nipkow@15524
   123
nipkow@15524
   124
lemma order_antisym_conv: "(y::'a::order) <= x ==> (x <= y) = (x = y)"
nipkow@15524
   125
by(blast intro:order_antisym)
nipkow@15524
   126
haftmann@21083
   127
lemma less_imp_neq: "[| (x::'a::order) < y |] ==> x ~= y"
haftmann@21083
   128
  by (erule contrapos_pn, erule subst, rule order_less_irrefl)
haftmann@21083
   129
nipkow@15524
   130
text {* Transitivity. *}
nipkow@15524
   131
nipkow@15524
   132
lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
nipkow@15524
   133
  apply (simp add: order_less_le)
nipkow@15524
   134
  apply (blast intro: order_trans order_antisym)
nipkow@15524
   135
  done
nipkow@15524
   136
nipkow@15524
   137
lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
nipkow@15524
   138
  apply (simp add: order_less_le)
nipkow@15524
   139
  apply (blast intro: order_trans order_antisym)
nipkow@15524
   140
  done
nipkow@15524
   141
nipkow@15524
   142
lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
nipkow@15524
   143
  apply (simp add: order_less_le)
nipkow@15524
   144
  apply (blast intro: order_trans order_antisym)
nipkow@15524
   145
  done
nipkow@15524
   146
haftmann@21083
   147
lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y"
haftmann@21083
   148
  by (erule subst, erule ssubst, assumption)
nipkow@15524
   149
nipkow@15524
   150
text {* Useful for simplification, but too risky to include by default. *}
nipkow@15524
   151
nipkow@15524
   152
lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
nipkow@15524
   153
  by (blast elim: order_less_asym)
nipkow@15524
   154
nipkow@15524
   155
lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
nipkow@15524
   156
  by (blast elim: order_less_asym)
nipkow@15524
   157
nipkow@15524
   158
lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
nipkow@15524
   159
  by auto
nipkow@15524
   160
nipkow@15524
   161
lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
nipkow@15524
   162
  by auto
nipkow@15524
   163
haftmann@21083
   164
text {* Transitivity rules for calculational reasoning *}
nipkow@15524
   165
nipkow@15524
   166
lemma order_neq_le_trans: "a ~= b ==> (a::'a::order) <= b ==> a < b"
nipkow@15524
   167
  by (simp add: order_less_le)
nipkow@15524
   168
nipkow@15524
   169
lemma order_le_neq_trans: "(a::'a::order) <= b ==> a ~= b ==> a < b"
nipkow@15524
   170
  by (simp add: order_less_le)
nipkow@15524
   171
nipkow@15524
   172
lemma order_less_asym': "(a::'a::order) < b ==> b < a ==> P"
nipkow@15524
   173
  by (rule order_less_asym)
nipkow@15524
   174
nipkow@15524
   175
haftmann@21083
   176
subsection {* Total orderings *}
nipkow@15524
   177
nipkow@15524
   178
axclass linorder < order
nipkow@15524
   179
  linorder_linear: "x <= y | y <= x"
nipkow@15524
   180
nipkow@15524
   181
lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
nipkow@15524
   182
  apply (simp add: order_less_le)
nipkow@15524
   183
  apply (insert linorder_linear, blast)
nipkow@15524
   184
  done
nipkow@15524
   185
nipkow@15524
   186
lemma linorder_le_less_linear: "!!x::'a::linorder. x\<le>y | y<x"
nipkow@15524
   187
  by (simp add: order_le_less linorder_less_linear)
nipkow@15524
   188
nipkow@15524
   189
lemma linorder_le_cases [case_names le ge]:
nipkow@15524
   190
    "((x::'a::linorder) \<le> y ==> P) ==> (y \<le> x ==> P) ==> P"
nipkow@15524
   191
  by (insert linorder_linear, blast)
nipkow@15524
   192
nipkow@15524
   193
lemma linorder_cases [case_names less equal greater]:
nipkow@15524
   194
    "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
nipkow@15524
   195
  by (insert linorder_less_linear, blast)
nipkow@15524
   196
nipkow@15524
   197
lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
nipkow@15524
   198
  apply (simp add: order_less_le)
nipkow@15524
   199
  apply (insert linorder_linear)
nipkow@15524
   200
  apply (blast intro: order_antisym)
nipkow@15524
   201
  done
nipkow@15524
   202
nipkow@15524
   203
lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
nipkow@15524
   204
  apply (simp add: order_less_le)
nipkow@15524
   205
  apply (insert linorder_linear)
nipkow@15524
   206
  apply (blast intro: order_antisym)
nipkow@15524
   207
  done
nipkow@15524
   208
nipkow@15524
   209
lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
nipkow@15524
   210
by (cut_tac x = x and y = y in linorder_less_linear, auto)
nipkow@15524
   211
nipkow@15524
   212
lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
nipkow@15524
   213
by (simp add: linorder_neq_iff, blast)
nipkow@15524
   214
nipkow@15524
   215
lemma linorder_antisym_conv1: "~ (x::'a::linorder) < y ==> (x <= y) = (x = y)"
nipkow@15524
   216
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
nipkow@15524
   217
nipkow@15524
   218
lemma linorder_antisym_conv2: "(x::'a::linorder) <= y ==> (~ x < y) = (x = y)"
nipkow@15524
   219
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
nipkow@15524
   220
nipkow@15524
   221
lemma linorder_antisym_conv3: "~ (y::'a::linorder) < x ==> (~ x < y) = (x = y)"
nipkow@15524
   222
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
nipkow@15524
   223
paulson@16796
   224
text{*Replacing the old Nat.leI*}
paulson@16796
   225
lemma leI: "~ x < y ==> y <= (x::'a::linorder)"
paulson@16796
   226
  by (simp only: linorder_not_less)
paulson@16796
   227
paulson@16796
   228
lemma leD: "y <= (x::'a::linorder) ==> ~ x < y"
paulson@16796
   229
  by (simp only: linorder_not_less)
paulson@16796
   230
paulson@16796
   231
(*FIXME inappropriate name (or delete altogether)*)
paulson@16796
   232
lemma not_leE: "~ y <= (x::'a::linorder) ==> x < y"
paulson@16796
   233
  by (simp only: linorder_not_le)
paulson@16796
   234
haftmann@21083
   235
haftmann@21083
   236
subsection {* Reasoning tools setup *}
haftmann@21083
   237
haftmann@21083
   238
setup {*
haftmann@21083
   239
let
haftmann@21083
   240
haftmann@21083
   241
val order_antisym_conv = thm "order_antisym_conv"
haftmann@21083
   242
val linorder_antisym_conv1 = thm "linorder_antisym_conv1"
haftmann@21083
   243
val linorder_antisym_conv2 = thm "linorder_antisym_conv2"
haftmann@21083
   244
val linorder_antisym_conv3 = thm "linorder_antisym_conv3"
haftmann@21083
   245
haftmann@21083
   246
fun prp t thm = (#prop (rep_thm thm) = t);
nipkow@15524
   247
haftmann@21083
   248
fun prove_antisym_le sg ss ((le as Const(_,T)) $ r $ s) =
haftmann@21083
   249
  let val prems = prems_of_ss ss;
haftmann@21083
   250
      val less = Const("Orderings.less",T);
haftmann@21083
   251
      val t = HOLogic.mk_Trueprop(le $ s $ r);
haftmann@21083
   252
  in case find_first (prp t) prems of
haftmann@21083
   253
       NONE =>
haftmann@21083
   254
         let val t = HOLogic.mk_Trueprop(HOLogic.Not $ (less $ r $ s))
haftmann@21083
   255
         in case find_first (prp t) prems of
haftmann@21083
   256
              NONE => NONE
haftmann@21083
   257
            | SOME thm => SOME(mk_meta_eq(thm RS linorder_antisym_conv1))
haftmann@21083
   258
         end
haftmann@21083
   259
     | SOME thm => SOME(mk_meta_eq(thm RS order_antisym_conv))
haftmann@21083
   260
  end
haftmann@21083
   261
  handle THM _ => NONE;
nipkow@15524
   262
haftmann@21083
   263
fun prove_antisym_less sg ss (NotC $ ((less as Const(_,T)) $ r $ s)) =
haftmann@21083
   264
  let val prems = prems_of_ss ss;
haftmann@21083
   265
      val le = Const("Orderings.less_eq",T);
haftmann@21083
   266
      val t = HOLogic.mk_Trueprop(le $ r $ s);
haftmann@21083
   267
  in case find_first (prp t) prems of
haftmann@21083
   268
       NONE =>
haftmann@21083
   269
         let val t = HOLogic.mk_Trueprop(NotC $ (less $ s $ r))
haftmann@21083
   270
         in case find_first (prp t) prems of
haftmann@21083
   271
              NONE => NONE
haftmann@21083
   272
            | SOME thm => SOME(mk_meta_eq(thm RS linorder_antisym_conv3))
haftmann@21083
   273
         end
haftmann@21083
   274
     | SOME thm => SOME(mk_meta_eq(thm RS linorder_antisym_conv2))
haftmann@21083
   275
  end
haftmann@21083
   276
  handle THM _ => NONE;
nipkow@15524
   277
haftmann@21083
   278
val antisym_le = Simplifier.simproc (the_context())
haftmann@21083
   279
  "antisym le" ["(x::'a::order) <= y"] prove_antisym_le;
haftmann@21083
   280
val antisym_less = Simplifier.simproc (the_context())
haftmann@21083
   281
  "antisym less" ["~ (x::'a::linorder) < y"] prove_antisym_less;
haftmann@21083
   282
haftmann@21083
   283
in
haftmann@21083
   284
haftmann@21083
   285
 (fn thy => (Simplifier.change_simpset_of thy
haftmann@21083
   286
  (fn ss => ss addsimprocs [antisym_le, antisym_less]); thy))
haftmann@21083
   287
haftmann@21083
   288
end
haftmann@21083
   289
*}
nipkow@15524
   290
nipkow@15524
   291
ML_setup {*
nipkow@15524
   292
nipkow@15524
   293
(* The setting up of Quasi_Tac serves as a demo.  Since there is no
nipkow@15524
   294
   class for quasi orders, the tactics Quasi_Tac.trans_tac and
nipkow@15524
   295
   Quasi_Tac.quasi_tac are not of much use. *)
nipkow@15524
   296
haftmann@21044
   297
fun decomp_gen sort thy (Trueprop $ t) =
ballarin@15622
   298
  let fun of_sort t = let val T = type_of t in
ballarin@15622
   299
        (* exclude numeric types: linear arithmetic subsumes transitivity *)
ballarin@15622
   300
        T <> HOLogic.natT andalso T <> HOLogic.intT andalso
haftmann@21044
   301
        T <> HOLogic.realT andalso Sign.of_sort thy (T, sort) end
nipkow@15524
   302
  fun dec (Const ("Not", _) $ t) = (
nipkow@15524
   303
	  case dec t of
skalberg@15531
   304
	    NONE => NONE
skalberg@15531
   305
	  | SOME (t1, rel, t2) => SOME (t1, "~" ^ rel, t2))
nipkow@15524
   306
	| dec (Const ("op =",  _) $ t1 $ t2) =
nipkow@15524
   307
	    if of_sort t1
skalberg@15531
   308
	    then SOME (t1, "=", t2)
skalberg@15531
   309
	    else NONE
haftmann@19277
   310
	| dec (Const ("Orderings.less_eq",  _) $ t1 $ t2) =
nipkow@15524
   311
	    if of_sort t1
skalberg@15531
   312
	    then SOME (t1, "<=", t2)
skalberg@15531
   313
	    else NONE
haftmann@19277
   314
	| dec (Const ("Orderings.less",  _) $ t1 $ t2) =
nipkow@15524
   315
	    if of_sort t1
skalberg@15531
   316
	    then SOME (t1, "<", t2)
skalberg@15531
   317
	    else NONE
skalberg@15531
   318
	| dec _ = NONE
nipkow@15524
   319
  in dec t end;
nipkow@15524
   320
nipkow@15524
   321
structure Quasi_Tac = Quasi_Tac_Fun (
nipkow@15524
   322
  struct
nipkow@15524
   323
    val le_trans = thm "order_trans";
nipkow@15524
   324
    val le_refl = thm "order_refl";
nipkow@15524
   325
    val eqD1 = thm "order_eq_refl";
nipkow@15524
   326
    val eqD2 = thm "sym" RS thm "order_eq_refl";
nipkow@15524
   327
    val less_reflE = thm "order_less_irrefl" RS thm "notE";
nipkow@15524
   328
    val less_imp_le = thm "order_less_imp_le";
nipkow@15524
   329
    val le_neq_trans = thm "order_le_neq_trans";
nipkow@15524
   330
    val neq_le_trans = thm "order_neq_le_trans";
nipkow@15524
   331
    val less_imp_neq = thm "less_imp_neq";
nipkow@15524
   332
    val decomp_trans = decomp_gen ["Orderings.order"];
nipkow@15524
   333
    val decomp_quasi = decomp_gen ["Orderings.order"];
nipkow@15524
   334
nipkow@15524
   335
  end);  (* struct *)
nipkow@15524
   336
nipkow@15524
   337
structure Order_Tac = Order_Tac_Fun (
nipkow@15524
   338
  struct
nipkow@15524
   339
    val less_reflE = thm "order_less_irrefl" RS thm "notE";
nipkow@15524
   340
    val le_refl = thm "order_refl";
nipkow@15524
   341
    val less_imp_le = thm "order_less_imp_le";
nipkow@15524
   342
    val not_lessI = thm "linorder_not_less" RS thm "iffD2";
nipkow@15524
   343
    val not_leI = thm "linorder_not_le" RS thm "iffD2";
nipkow@15524
   344
    val not_lessD = thm "linorder_not_less" RS thm "iffD1";
nipkow@15524
   345
    val not_leD = thm "linorder_not_le" RS thm "iffD1";
nipkow@15524
   346
    val eqI = thm "order_antisym";
nipkow@15524
   347
    val eqD1 = thm "order_eq_refl";
nipkow@15524
   348
    val eqD2 = thm "sym" RS thm "order_eq_refl";
nipkow@15524
   349
    val less_trans = thm "order_less_trans";
nipkow@15524
   350
    val less_le_trans = thm "order_less_le_trans";
nipkow@15524
   351
    val le_less_trans = thm "order_le_less_trans";
nipkow@15524
   352
    val le_trans = thm "order_trans";
nipkow@15524
   353
    val le_neq_trans = thm "order_le_neq_trans";
nipkow@15524
   354
    val neq_le_trans = thm "order_neq_le_trans";
nipkow@15524
   355
    val less_imp_neq = thm "less_imp_neq";
nipkow@15524
   356
    val eq_neq_eq_imp_neq = thm "eq_neq_eq_imp_neq";
obua@16743
   357
    val not_sym = thm "not_sym";
nipkow@15524
   358
    val decomp_part = decomp_gen ["Orderings.order"];
nipkow@15524
   359
    val decomp_lin = decomp_gen ["Orderings.linorder"];
nipkow@15524
   360
nipkow@15524
   361
  end);  (* struct *)
nipkow@15524
   362
wenzelm@17876
   363
change_simpset (fn ss => ss
nipkow@15524
   364
    addSolver (mk_solver "Trans_linear" (fn _ => Order_Tac.linear_tac))
wenzelm@17876
   365
    addSolver (mk_solver "Trans_partial" (fn _ => Order_Tac.partial_tac)));
nipkow@15524
   366
  (* Adding the transitivity reasoners also as safe solvers showed a slight
nipkow@15524
   367
     speed up, but the reasoning strength appears to be not higher (at least
nipkow@15524
   368
     no breaking of additional proofs in the entire HOL distribution, as
nipkow@15524
   369
     of 5 March 2004, was observed). *)
nipkow@15524
   370
*}
nipkow@15524
   371
nipkow@15524
   372
(* Optional setup of methods *)
nipkow@15524
   373
nipkow@15524
   374
(*
nipkow@15524
   375
method_setup trans_partial =
nipkow@15524
   376
  {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (Order_Tac.partial_tac)) *}
nipkow@15524
   377
  {* transitivity reasoner for partial orders *}	
nipkow@15524
   378
method_setup trans_linear =
nipkow@15524
   379
  {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (Order_Tac.linear_tac)) *}
nipkow@15524
   380
  {* transitivity reasoner for linear orders *}
nipkow@15524
   381
*)
nipkow@15524
   382
nipkow@15524
   383
(*
nipkow@15524
   384
declare order.order_refl [simp del] order_less_irrefl [simp del]
nipkow@15524
   385
nipkow@15524
   386
can currently not be removed, abel_cancel relies on it.
nipkow@15524
   387
*)
nipkow@15524
   388
nipkow@15524
   389
haftmann@21083
   390
subsection {* Bounded quantifiers *}
haftmann@21083
   391
haftmann@21083
   392
syntax
haftmann@21083
   393
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
haftmann@21083
   394
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
haftmann@21083
   395
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
haftmann@21083
   396
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
haftmann@21083
   397
haftmann@21083
   398
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _>_./ _)"  [0, 0, 10] 10)
haftmann@21083
   399
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _>_./ _)"  [0, 0, 10] 10)
haftmann@21083
   400
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _>=_./ _)" [0, 0, 10] 10)
haftmann@21083
   401
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _>=_./ _)" [0, 0, 10] 10)
haftmann@21083
   402
haftmann@21083
   403
syntax (xsymbols)
haftmann@21083
   404
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
haftmann@21083
   405
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
haftmann@21083
   406
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083
   407
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083
   408
haftmann@21083
   409
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
haftmann@21083
   410
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
haftmann@21083
   411
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083
   412
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083
   413
haftmann@21083
   414
syntax (HOL)
haftmann@21083
   415
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
haftmann@21083
   416
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
haftmann@21083
   417
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
haftmann@21083
   418
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
haftmann@21083
   419
haftmann@21083
   420
syntax (HTML output)
haftmann@21083
   421
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
haftmann@21083
   422
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
haftmann@21083
   423
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083
   424
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083
   425
haftmann@21083
   426
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
haftmann@21083
   427
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
haftmann@21083
   428
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083
   429
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083
   430
haftmann@21083
   431
translations
haftmann@21083
   432
  "ALL x<y. P"   =>  "ALL x. x < y \<longrightarrow> P"
haftmann@21083
   433
  "EX x<y. P"    =>  "EX x. x < y \<and> P"
haftmann@21083
   434
  "ALL x<=y. P"  =>  "ALL x. x <= y \<longrightarrow> P"
haftmann@21083
   435
  "EX x<=y. P"   =>  "EX x. x <= y \<and> P"
haftmann@21083
   436
  "ALL x>y. P"   =>  "ALL x. x > y \<longrightarrow> P"
haftmann@21083
   437
  "EX x>y. P"    =>  "EX x. x > y \<and> P"
haftmann@21083
   438
  "ALL x>=y. P"  =>  "ALL x. x >= y \<longrightarrow> P"
haftmann@21083
   439
  "EX x>=y. P"   =>  "EX x. x >= y \<and> P"
haftmann@21083
   440
haftmann@21083
   441
print_translation {*
haftmann@21083
   442
let
haftmann@21083
   443
  fun mk v v' c n P =
haftmann@21083
   444
    if v = v' andalso not (member (op =) (map fst (Term.add_frees n [])) v)
haftmann@21083
   445
    then Syntax.const c $ Syntax.mark_bound v' $ n $ P else raise Match;
haftmann@21083
   446
  fun mk_all "\\<^const>Scratch.less" f =
haftmann@21083
   447
        f ("_lessAll", "_gtAll")
haftmann@21083
   448
    | mk_all "\\<^const>Scratch.less_eq" f =
haftmann@21083
   449
        f ("_leAll", "_geAll")
haftmann@21083
   450
  fun mk_ex "\\<^const>Scratch.less" f =
haftmann@21083
   451
        f ("_lessEx", "_gtEx")
haftmann@21083
   452
    | mk_ex "\\<^const>Scratch.less_eq" f =
haftmann@21083
   453
        f ("_leEx", "_geEx");
haftmann@21083
   454
  fun tr_all' [Const ("_bound", _) $ Free (v, _), Const("op -->", _)
haftmann@21083
   455
          $ (Const (c, _) $ (Const ("_bound", _) $ Free (v', _)) $ n) $ P] =
haftmann@21083
   456
        mk v v' (mk_all c fst) n P
haftmann@21083
   457
    | tr_all' [Const ("_bound", _) $ Free (v, _), Const("op -->", _)
haftmann@21083
   458
          $ (Const (c, _) $ n $ (Const ("_bound", _) $ Free (v', _))) $ P] =
haftmann@21083
   459
        mk v v' (mk_all c snd) n P;
haftmann@21083
   460
  fun tr_ex' [Const ("_bound", _) $ Free (v, _), Const("op &", _)
haftmann@21083
   461
          $ (Const (c, _) $ (Const ("_bound", _) $ Free (v', _)) $ n) $ P] =
haftmann@21083
   462
        mk v v' (mk_ex c fst) n P
haftmann@21083
   463
    | tr_ex' [Const ("_bound", _) $ Free (v, _), Const("op &", _)
haftmann@21083
   464
          $ (Const (c, _) $ n $ (Const ("_bound", _) $ Free (v', _))) $ P] =
haftmann@21083
   465
        mk v v' (mk_ex c snd) n P;
haftmann@21083
   466
in
haftmann@21083
   467
  [("ALL ", tr_all'), ("EX ", tr_ex')]
haftmann@21083
   468
end
haftmann@21083
   469
*}
haftmann@21083
   470
haftmann@21083
   471
haftmann@21083
   472
subsection {* Transitivity reasoning on decreasing inequalities *}
haftmann@21083
   473
haftmann@21083
   474
text {* These support proving chains of decreasing inequalities
haftmann@21083
   475
    a >= b >= c ... in Isar proofs. *}
haftmann@21083
   476
haftmann@21083
   477
lemma xt1:
haftmann@21083
   478
  "a = b ==> b > c ==> a > c"
haftmann@21083
   479
  "a > b ==> b = c ==> a > c"
haftmann@21083
   480
  "a = b ==> b >= c ==> a >= c"
haftmann@21083
   481
  "a >= b ==> b = c ==> a >= c"
haftmann@21083
   482
  "(x::'a::order) >= y ==> y >= x ==> x = y"
haftmann@21083
   483
  "(x::'a::order) >= y ==> y >= z ==> x >= z"
haftmann@21083
   484
  "(x::'a::order) > y ==> y >= z ==> x > z"
haftmann@21083
   485
  "(x::'a::order) >= y ==> y > z ==> x > z"
haftmann@21083
   486
  "(a::'a::order) > b ==> b > a ==> ?P"
haftmann@21083
   487
  "(x::'a::order) > y ==> y > z ==> x > z"
haftmann@21083
   488
  "(a::'a::order) >= b ==> a ~= b ==> a > b"
haftmann@21083
   489
  "(a::'a::order) ~= b ==> a >= b ==> a > b"
haftmann@21083
   490
  "a = f b ==> b > c ==> (!!x y. x > y ==> f x > f y) ==> a > f c" 
haftmann@21083
   491
  "a > b ==> f b = c ==> (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
   492
  "a = f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
haftmann@21083
   493
  "a >= b ==> f b = c ==> (!! x y. x >= y ==> f x >= f y) ==> f a >= c"
haftmann@21083
   494
by auto
haftmann@21083
   495
haftmann@21083
   496
lemma xt2:
haftmann@21083
   497
  "(a::'a::order) >= f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
haftmann@21083
   498
by (subgoal_tac "f b >= f c", force, force)
haftmann@21083
   499
haftmann@21083
   500
lemma xt3: "(a::'a::order) >= b ==> (f b::'b::order) >= c ==> 
haftmann@21083
   501
    (!!x y. x >= y ==> f x >= f y) ==> f a >= c"
haftmann@21083
   502
by (subgoal_tac "f a >= f b", force, force)
haftmann@21083
   503
haftmann@21083
   504
lemma xt4: "(a::'a::order) > f b ==> (b::'b::order) >= c ==>
haftmann@21083
   505
  (!!x y. x >= y ==> f x >= f y) ==> a > f c"
haftmann@21083
   506
by (subgoal_tac "f b >= f c", force, force)
haftmann@21083
   507
haftmann@21083
   508
lemma xt5: "(a::'a::order) > b ==> (f b::'b::order) >= c==>
haftmann@21083
   509
    (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
   510
by (subgoal_tac "f a > f b", force, force)
haftmann@21083
   511
haftmann@21083
   512
lemma xt6: "(a::'a::order) >= f b ==> b > c ==>
haftmann@21083
   513
    (!!x y. x > y ==> f x > f y) ==> a > f c"
haftmann@21083
   514
by (subgoal_tac "f b > f c", force, force)
haftmann@21083
   515
haftmann@21083
   516
lemma xt7: "(a::'a::order) >= b ==> (f b::'b::order) > c ==>
haftmann@21083
   517
    (!!x y. x >= y ==> f x >= f y) ==> f a > c"
haftmann@21083
   518
by (subgoal_tac "f a >= f b", force, force)
haftmann@21083
   519
haftmann@21083
   520
lemma xt8: "(a::'a::order) > f b ==> (b::'b::order) > c ==>
haftmann@21083
   521
    (!!x y. x > y ==> f x > f y) ==> a > f c"
haftmann@21083
   522
by (subgoal_tac "f b > f c", force, force)
haftmann@21083
   523
haftmann@21083
   524
lemma xt9: "(a::'a::order) > b ==> (f b::'b::order) > c ==>
haftmann@21083
   525
    (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
   526
by (subgoal_tac "f a > f b", force, force)
haftmann@21083
   527
haftmann@21083
   528
lemmas xtrans = xt1 xt2 xt3 xt4 xt5 xt6 xt7 xt8 xt9
haftmann@21083
   529
haftmann@21083
   530
(* 
haftmann@21083
   531
  Since "a >= b" abbreviates "b <= a", the abbreviation "..." stands
haftmann@21083
   532
  for the wrong thing in an Isar proof.
haftmann@21083
   533
haftmann@21083
   534
  The extra transitivity rules can be used as follows: 
haftmann@21083
   535
haftmann@21083
   536
lemma "(a::'a::order) > z"
haftmann@21083
   537
proof -
haftmann@21083
   538
  have "a >= b" (is "_ >= ?rhs")
haftmann@21083
   539
    sorry
haftmann@21083
   540
  also have "?rhs >= c" (is "_ >= ?rhs")
haftmann@21083
   541
    sorry
haftmann@21083
   542
  also (xtrans) have "?rhs = d" (is "_ = ?rhs")
haftmann@21083
   543
    sorry
haftmann@21083
   544
  also (xtrans) have "?rhs >= e" (is "_ >= ?rhs")
haftmann@21083
   545
    sorry
haftmann@21083
   546
  also (xtrans) have "?rhs > f" (is "_ > ?rhs")
haftmann@21083
   547
    sorry
haftmann@21083
   548
  also (xtrans) have "?rhs > z"
haftmann@21083
   549
    sorry
haftmann@21083
   550
  finally (xtrans) show ?thesis .
haftmann@21083
   551
qed
haftmann@21083
   552
haftmann@21083
   553
  Alternatively, one can use "declare xtrans [trans]" and then
haftmann@21083
   554
  leave out the "(xtrans)" above.
haftmann@21083
   555
*)
haftmann@21083
   556
haftmann@21083
   557
haftmann@21083
   558
subsection {* Least value operator, monotonicity and min/max *}
haftmann@21083
   559
 
haftmann@21083
   560
(*FIXME: derive more of the min/max laws generically via semilattices*)
haftmann@21083
   561
haftmann@21083
   562
constdefs
haftmann@21083
   563
  Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
haftmann@21083
   564
  "Least P == THE x. P x & (ALL y. P y --> x <= y)"
haftmann@21083
   565
    -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
haftmann@21083
   566
haftmann@21083
   567
lemma LeastI2_order:
haftmann@21083
   568
  "[| P (x::'a::order);
haftmann@21083
   569
      !!y. P y ==> x <= y;
haftmann@21083
   570
      !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
haftmann@21083
   571
   ==> Q (Least P)"
haftmann@21083
   572
  apply (unfold Least_def)
haftmann@21083
   573
  apply (rule theI2)
haftmann@21083
   574
    apply (blast intro: order_antisym)+
haftmann@21083
   575
  done
haftmann@21083
   576
haftmann@21083
   577
lemma Least_equality:
haftmann@21083
   578
    "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
haftmann@21083
   579
  apply (simp add: Least_def)
haftmann@21083
   580
  apply (rule the_equality)
haftmann@21083
   581
  apply (auto intro!: order_antisym)
haftmann@21083
   582
  done
haftmann@21083
   583
haftmann@21083
   584
locale mono =
haftmann@21083
   585
  fixes f
haftmann@21083
   586
  assumes mono: "A <= B ==> f A <= f B"
haftmann@21083
   587
haftmann@21083
   588
lemmas monoI [intro?] = mono.intro
haftmann@21083
   589
  and monoD [dest?] = mono.mono
haftmann@21083
   590
haftmann@21083
   591
constdefs
haftmann@21083
   592
  min :: "['a::ord, 'a] => 'a"
haftmann@21083
   593
  "min a b == (if a <= b then a else b)"
haftmann@21083
   594
  max :: "['a::ord, 'a] => 'a"
haftmann@21083
   595
  "max a b == (if a <= b then b else a)"
haftmann@21083
   596
haftmann@21083
   597
lemma min_leastR: "(\<And>x\<Colon>'a\<Colon>order. least \<le> x) \<Longrightarrow> min x least = least"
haftmann@21083
   598
  apply (simp add: min_def)
haftmann@21083
   599
  apply (blast intro: order_antisym)
haftmann@21083
   600
  done
haftmann@21083
   601
haftmann@21083
   602
lemma max_leastR: "(\<And>x\<Colon>'a\<Colon>order. least \<le> x) \<Longrightarrow> max x least = x"
haftmann@21083
   603
  apply (simp add: max_def)
haftmann@21083
   604
  apply (blast intro: order_antisym)
haftmann@21083
   605
  done
haftmann@21083
   606
haftmann@21083
   607
lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
haftmann@21083
   608
  by (simp add: min_def)
haftmann@21083
   609
haftmann@21083
   610
lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
haftmann@21083
   611
  by (simp add: max_def)
haftmann@21083
   612
haftmann@21083
   613
lemma min_of_mono:
haftmann@21083
   614
    "(!!x y. (f x <= f y) = (x <= y)) ==> min (f m) (f n) = f (min m n)"
haftmann@21083
   615
  by (simp add: min_def)
haftmann@21083
   616
haftmann@21083
   617
lemma max_of_mono:
haftmann@21083
   618
    "(!!x y. (f x <= f y) = (x <= y)) ==> max (f m) (f n) = f (max m n)"
haftmann@21083
   619
  by (simp add: max_def)
nipkow@15524
   620
nipkow@15524
   621
text{* Instantiate locales: *}
nipkow@15524
   622
ballarin@15837
   623
interpretation min_max:
nipkow@15780
   624
  lower_semilattice["op \<le>" "min :: 'a::linorder \<Rightarrow> 'a \<Rightarrow> 'a"]
ballarin@19984
   625
apply unfold_locales
nipkow@15524
   626
apply(simp add:min_def linorder_not_le order_less_imp_le)
nipkow@15524
   627
apply(simp add:min_def linorder_not_le order_less_imp_le)
nipkow@15524
   628
apply(simp add:min_def linorder_not_le order_less_imp_le)
nipkow@15524
   629
done
nipkow@15524
   630
ballarin@15837
   631
interpretation min_max:
nipkow@15780
   632
  upper_semilattice["op \<le>" "max :: 'a::linorder \<Rightarrow> 'a \<Rightarrow> 'a"]
ballarin@19984
   633
apply unfold_locales
nipkow@15524
   634
apply(simp add: max_def linorder_not_le order_less_imp_le)
nipkow@15524
   635
apply(simp add: max_def linorder_not_le order_less_imp_le)
nipkow@15524
   636
apply(simp add: max_def linorder_not_le order_less_imp_le)
nipkow@15524
   637
done
nipkow@15524
   638
ballarin@15837
   639
interpretation min_max:
nipkow@15780
   640
  lattice["op \<le>" "min :: 'a::linorder \<Rightarrow> 'a \<Rightarrow> 'a" "max"]
ballarin@19984
   641
  by unfold_locales
nipkow@15524
   642
ballarin@15837
   643
interpretation min_max:
nipkow@15780
   644
  distrib_lattice["op \<le>" "min :: 'a::linorder \<Rightarrow> 'a \<Rightarrow> 'a" "max"]
ballarin@19984
   645
apply unfold_locales
nipkow@15524
   646
apply(rule_tac x=x and y=y in linorder_le_cases)
nipkow@15524
   647
apply(rule_tac x=x and y=z in linorder_le_cases)
nipkow@15524
   648
apply(rule_tac x=y and y=z in linorder_le_cases)
nipkow@15524
   649
apply(simp add:min_def max_def)
nipkow@15524
   650
apply(simp add:min_def max_def)
nipkow@15524
   651
apply(rule_tac x=y and y=z in linorder_le_cases)
nipkow@15524
   652
apply(simp add:min_def max_def)
nipkow@15524
   653
apply(simp add:min_def max_def)
nipkow@15524
   654
apply(rule_tac x=x and y=z in linorder_le_cases)
nipkow@15524
   655
apply(rule_tac x=y and y=z in linorder_le_cases)
nipkow@15524
   656
apply(simp add:min_def max_def)
nipkow@15524
   657
apply(simp add:min_def max_def)
nipkow@15524
   658
apply(rule_tac x=y and y=z in linorder_le_cases)
nipkow@15524
   659
apply(simp add:min_def max_def)
nipkow@15524
   660
apply(simp add:min_def max_def)
nipkow@15524
   661
done
nipkow@15524
   662
nipkow@15524
   663
lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
nipkow@15524
   664
  apply(simp add:max_def)
nipkow@15524
   665
  apply (insert linorder_linear)
nipkow@15524
   666
  apply (blast intro: order_trans)
nipkow@15524
   667
  done
nipkow@15524
   668
nipkow@15780
   669
lemmas le_maxI1 = min_max.sup_ge1
nipkow@15780
   670
lemmas le_maxI2 = min_max.sup_ge2
nipkow@15524
   671
nipkow@15524
   672
lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
nipkow@15524
   673
  apply (simp add: max_def order_le_less)
nipkow@15524
   674
  apply (insert linorder_less_linear)
nipkow@15524
   675
  apply (blast intro: order_less_trans)
nipkow@15524
   676
  done
nipkow@15524
   677
nipkow@15524
   678
lemma max_less_iff_conj [simp]:
nipkow@15524
   679
    "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
nipkow@15524
   680
  apply (simp add: order_le_less max_def)
nipkow@15524
   681
  apply (insert linorder_less_linear)
nipkow@15524
   682
  apply (blast intro: order_less_trans)
nipkow@15524
   683
  done
nipkow@15791
   684
nipkow@15524
   685
lemma min_less_iff_conj [simp]:
nipkow@15524
   686
    "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
nipkow@15524
   687
  apply (simp add: order_le_less min_def)
nipkow@15524
   688
  apply (insert linorder_less_linear)
nipkow@15524
   689
  apply (blast intro: order_less_trans)
nipkow@15524
   690
  done
nipkow@15524
   691
nipkow@15524
   692
lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
nipkow@15524
   693
  apply (simp add: min_def)
nipkow@15524
   694
  apply (insert linorder_linear)
nipkow@15524
   695
  apply (blast intro: order_trans)
nipkow@15524
   696
  done
nipkow@15524
   697
nipkow@15524
   698
lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
nipkow@15524
   699
  apply (simp add: min_def order_le_less)
nipkow@15524
   700
  apply (insert linorder_less_linear)
nipkow@15524
   701
  apply (blast intro: order_less_trans)
nipkow@15524
   702
  done
nipkow@15524
   703
nipkow@15780
   704
lemmas max_ac = min_max.sup_assoc min_max.sup_commute
nipkow@15780
   705
               mk_left_commute[of max,OF min_max.sup_assoc min_max.sup_commute]
nipkow@15524
   706
nipkow@15780
   707
lemmas min_ac = min_max.inf_assoc min_max.inf_commute
nipkow@15780
   708
               mk_left_commute[of min,OF min_max.inf_assoc min_max.inf_commute]
nipkow@15524
   709
nipkow@15524
   710
lemma split_min:
nipkow@15524
   711
    "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
nipkow@15524
   712
  by (simp add: min_def)
nipkow@15524
   713
nipkow@15524
   714
lemma split_max:
nipkow@15524
   715
    "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
nipkow@15524
   716
  by (simp add: max_def)
nipkow@15524
   717
nipkow@15524
   718
end