src/HOL/Orderings.thy
author nipkow
Thu, 10 Feb 2005 18:51:12 +0100
changeset 15524 2ef571f80a55
child 15531 08c8dad8e399
permissions -rw-r--r--
Moved oderings from HOL into the new Orderings.thy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15524
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Orderings.thy
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
     2
    ID:         $Id$
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
     3
    Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
     4
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
     5
FIXME: derive more of the min/max laws generically via semilattices
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
     6
*)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
     7
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
     8
header {* Type classes for $\le$ *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
     9
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    10
theory Orderings
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    11
imports Lattice_Locales
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    12
files ("antisym_setup.ML")
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    13
begin
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    14
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    15
subsection {* Order signatures and orders *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    16
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    17
axclass
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    18
  ord < type
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    19
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    20
syntax
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    21
  "op <"        :: "['a::ord, 'a] => bool"             ("op <")
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    22
  "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    23
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    24
global
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    25
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    26
consts
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    27
  "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    28
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    29
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    30
local
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    31
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    32
syntax (xsymbols)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    33
  "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    34
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    35
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    36
syntax (HTML output)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    37
  "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    38
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    39
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    40
text{* Syntactic sugar: *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    41
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    42
consts
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    43
  "_gt" :: "'a::ord => 'a => bool"             (infixl ">" 50)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    44
  "_ge" :: "'a::ord => 'a => bool"             (infixl ">=" 50)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    45
translations
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    46
  "x > y"  => "y < x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    47
  "x >= y" => "y <= x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    48
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    49
syntax (xsymbols)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    50
  "_ge"       :: "'a::ord => 'a => bool"             (infixl "\<ge>" 50)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    51
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    52
syntax (HTML output)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    53
  "_ge"       :: "['a::ord, 'a] => bool"             (infixl "\<ge>" 50)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    54
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    55
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    56
subsection {* Monotonicity *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    57
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    58
locale mono =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    59
  fixes f
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    60
  assumes mono: "A <= B ==> f A <= f B"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    61
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    62
lemmas monoI [intro?] = mono.intro
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    63
  and monoD [dest?] = mono.mono
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    64
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    65
constdefs
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    66
  min :: "['a::ord, 'a] => 'a"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    67
  "min a b == (if a <= b then a else b)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    68
  max :: "['a::ord, 'a] => 'a"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    69
  "max a b == (if a <= b then b else a)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    70
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    71
lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    72
  by (simp add: min_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    73
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    74
lemma min_of_mono:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    75
    "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    76
  by (simp add: min_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    77
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    78
lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    79
  by (simp add: max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    80
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    81
lemma max_of_mono:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    82
    "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    83
  by (simp add: max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    84
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    85
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    86
subsection "Orders"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    87
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    88
axclass order < ord
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    89
  order_refl [iff]: "x <= x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    90
  order_trans: "x <= y ==> y <= z ==> x <= z"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    91
  order_antisym: "x <= y ==> y <= x ==> x = y"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    92
  order_less_le: "(x < y) = (x <= y & x ~= y)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    93
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    94
text{* Connection to locale: *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    95
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    96
lemma partial_order_order:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    97
 "partial_order (op \<le> :: 'a::order \<Rightarrow> 'a \<Rightarrow> bool)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    98
apply(rule partial_order.intro)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
    99
apply(rule order_refl, erule (1) order_trans, erule (1) order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   100
done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   101
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   102
text {* Reflexivity. *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   103
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   104
lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   105
    -- {* This form is useful with the classical reasoner. *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   106
  apply (erule ssubst)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   107
  apply (rule order_refl)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   108
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   109
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   110
lemma order_less_irrefl [iff]: "~ x < (x::'a::order)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   111
  by (simp add: order_less_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   112
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   113
lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   114
    -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   115
  apply (simp add: order_less_le, blast)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   116
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   117
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   118
lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   119
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   120
lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   121
  by (simp add: order_less_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   122
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   123
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   124
text {* Asymmetry. *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   125
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   126
lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   127
  by (simp add: order_less_le order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   128
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   129
lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   130
  apply (drule order_less_not_sym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   131
  apply (erule contrapos_np, simp)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   132
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   133
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   134
lemma order_eq_iff: "!!x::'a::order. (x = y) = (x \<le> y & y \<le> x)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   135
by (blast intro: order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   136
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   137
lemma order_antisym_conv: "(y::'a::order) <= x ==> (x <= y) = (x = y)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   138
by(blast intro:order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   139
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   140
text {* Transitivity. *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   141
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   142
lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   143
  apply (simp add: order_less_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   144
  apply (blast intro: order_trans order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   145
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   146
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   147
lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   148
  apply (simp add: order_less_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   149
  apply (blast intro: order_trans order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   150
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   151
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   152
lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   153
  apply (simp add: order_less_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   154
  apply (blast intro: order_trans order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   155
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   156
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   157
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   158
text {* Useful for simplification, but too risky to include by default. *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   159
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   160
lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   161
  by (blast elim: order_less_asym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   162
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   163
lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   164
  by (blast elim: order_less_asym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   165
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   166
lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   167
  by auto
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   168
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   169
lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   170
  by auto
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   171
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   172
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   173
text {* Other operators. *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   174
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   175
lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   176
  apply (simp add: min_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   177
  apply (blast intro: order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   178
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   179
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   180
lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   181
  apply (simp add: max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   182
  apply (blast intro: order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   183
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   184
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   185
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   186
subsection {* Transitivity rules for calculational reasoning *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   187
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   188
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   189
lemma order_neq_le_trans: "a ~= b ==> (a::'a::order) <= b ==> a < b"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   190
  by (simp add: order_less_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   191
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   192
lemma order_le_neq_trans: "(a::'a::order) <= b ==> a ~= b ==> a < b"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   193
  by (simp add: order_less_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   194
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   195
lemma order_less_asym': "(a::'a::order) < b ==> b < a ==> P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   196
  by (rule order_less_asym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   197
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   198
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   199
subsection {* Least value operator *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   200
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   201
constdefs
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   202
  Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   203
  "Least P == THE x. P x & (ALL y. P y --> x <= y)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   204
    -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   205
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   206
lemma LeastI2:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   207
  "[| P (x::'a::order);
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   208
      !!y. P y ==> x <= y;
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   209
      !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   210
   ==> Q (Least P)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   211
  apply (unfold Least_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   212
  apply (rule theI2)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   213
    apply (blast intro: order_antisym)+
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   214
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   215
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   216
lemma Least_equality:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   217
    "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   218
  apply (simp add: Least_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   219
  apply (rule the_equality)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   220
  apply (auto intro!: order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   221
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   222
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   223
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   224
subsection "Linear / total orders"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   225
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   226
axclass linorder < order
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   227
  linorder_linear: "x <= y | y <= x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   228
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   229
lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   230
  apply (simp add: order_less_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   231
  apply (insert linorder_linear, blast)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   232
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   233
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   234
lemma linorder_le_less_linear: "!!x::'a::linorder. x\<le>y | y<x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   235
  by (simp add: order_le_less linorder_less_linear)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   236
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   237
lemma linorder_le_cases [case_names le ge]:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   238
    "((x::'a::linorder) \<le> y ==> P) ==> (y \<le> x ==> P) ==> P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   239
  by (insert linorder_linear, blast)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   240
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   241
lemma linorder_cases [case_names less equal greater]:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   242
    "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   243
  by (insert linorder_less_linear, blast)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   244
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   245
lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   246
  apply (simp add: order_less_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   247
  apply (insert linorder_linear)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   248
  apply (blast intro: order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   249
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   250
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   251
lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   252
  apply (simp add: order_less_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   253
  apply (insert linorder_linear)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   254
  apply (blast intro: order_antisym)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   255
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   256
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   257
lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   258
by (cut_tac x = x and y = y in linorder_less_linear, auto)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   259
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   260
lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   261
by (simp add: linorder_neq_iff, blast)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   262
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   263
lemma linorder_antisym_conv1: "~ (x::'a::linorder) < y ==> (x <= y) = (x = y)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   264
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   265
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   266
lemma linorder_antisym_conv2: "(x::'a::linorder) <= y ==> (~ x < y) = (x = y)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   267
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   268
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   269
lemma linorder_antisym_conv3: "~ (y::'a::linorder) < x ==> (~ x < y) = (x = y)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   270
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   271
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   272
use "antisym_setup.ML";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   273
setup antisym_setup
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   274
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   275
subsection {* Setup of transitivity reasoner as Solver *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   276
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   277
lemma less_imp_neq: "[| (x::'a::order) < y |] ==> x ~= y"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   278
  by (erule contrapos_pn, erule subst, rule order_less_irrefl)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   279
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   280
lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   281
  by (erule subst, erule ssubst, assumption)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   282
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   283
ML_setup {*
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   284
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   285
(* The setting up of Quasi_Tac serves as a demo.  Since there is no
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   286
   class for quasi orders, the tactics Quasi_Tac.trans_tac and
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   287
   Quasi_Tac.quasi_tac are not of much use. *)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   288
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   289
fun decomp_gen sort sign (Trueprop $ t) =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   290
  let fun of_sort t = Sign.of_sort sign (type_of t, sort)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   291
  fun dec (Const ("Not", _) $ t) = (
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   292
	  case dec t of
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   293
	    None => None
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   294
	  | Some (t1, rel, t2) => Some (t1, "~" ^ rel, t2))
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   295
	| dec (Const ("op =",  _) $ t1 $ t2) =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   296
	    if of_sort t1
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   297
	    then Some (t1, "=", t2)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   298
	    else None
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   299
	| dec (Const ("op <=",  _) $ t1 $ t2) =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   300
	    if of_sort t1
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   301
	    then Some (t1, "<=", t2)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   302
	    else None
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   303
	| dec (Const ("op <",  _) $ t1 $ t2) =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   304
	    if of_sort t1
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   305
	    then Some (t1, "<", t2)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   306
	    else None
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   307
	| dec _ = None
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   308
  in dec t end;
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   309
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   310
structure Quasi_Tac = Quasi_Tac_Fun (
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   311
  struct
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   312
    val le_trans = thm "order_trans";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   313
    val le_refl = thm "order_refl";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   314
    val eqD1 = thm "order_eq_refl";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   315
    val eqD2 = thm "sym" RS thm "order_eq_refl";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   316
    val less_reflE = thm "order_less_irrefl" RS thm "notE";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   317
    val less_imp_le = thm "order_less_imp_le";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   318
    val le_neq_trans = thm "order_le_neq_trans";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   319
    val neq_le_trans = thm "order_neq_le_trans";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   320
    val less_imp_neq = thm "less_imp_neq";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   321
    val decomp_trans = decomp_gen ["Orderings.order"];
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   322
    val decomp_quasi = decomp_gen ["Orderings.order"];
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   323
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   324
  end);  (* struct *)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   325
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   326
structure Order_Tac = Order_Tac_Fun (
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   327
  struct
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   328
    val less_reflE = thm "order_less_irrefl" RS thm "notE";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   329
    val le_refl = thm "order_refl";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   330
    val less_imp_le = thm "order_less_imp_le";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   331
    val not_lessI = thm "linorder_not_less" RS thm "iffD2";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   332
    val not_leI = thm "linorder_not_le" RS thm "iffD2";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   333
    val not_lessD = thm "linorder_not_less" RS thm "iffD1";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   334
    val not_leD = thm "linorder_not_le" RS thm "iffD1";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   335
    val eqI = thm "order_antisym";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   336
    val eqD1 = thm "order_eq_refl";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   337
    val eqD2 = thm "sym" RS thm "order_eq_refl";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   338
    val less_trans = thm "order_less_trans";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   339
    val less_le_trans = thm "order_less_le_trans";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   340
    val le_less_trans = thm "order_le_less_trans";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   341
    val le_trans = thm "order_trans";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   342
    val le_neq_trans = thm "order_le_neq_trans";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   343
    val neq_le_trans = thm "order_neq_le_trans";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   344
    val less_imp_neq = thm "less_imp_neq";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   345
    val eq_neq_eq_imp_neq = thm "eq_neq_eq_imp_neq";
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   346
    val decomp_part = decomp_gen ["Orderings.order"];
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   347
    val decomp_lin = decomp_gen ["Orderings.linorder"];
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   348
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   349
  end);  (* struct *)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   350
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   351
simpset_ref() := simpset ()
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   352
    addSolver (mk_solver "Trans_linear" (fn _ => Order_Tac.linear_tac))
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   353
    addSolver (mk_solver "Trans_partial" (fn _ => Order_Tac.partial_tac));
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   354
  (* Adding the transitivity reasoners also as safe solvers showed a slight
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   355
     speed up, but the reasoning strength appears to be not higher (at least
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   356
     no breaking of additional proofs in the entire HOL distribution, as
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   357
     of 5 March 2004, was observed). *)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   358
*}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   359
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   360
(* Optional setup of methods *)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   361
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   362
(*
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   363
method_setup trans_partial =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   364
  {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (Order_Tac.partial_tac)) *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   365
  {* transitivity reasoner for partial orders *}	
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   366
method_setup trans_linear =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   367
  {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (Order_Tac.linear_tac)) *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   368
  {* transitivity reasoner for linear orders *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   369
*)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   370
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   371
(*
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   372
declare order.order_refl [simp del] order_less_irrefl [simp del]
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   373
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   374
can currently not be removed, abel_cancel relies on it.
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   375
*)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   376
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   377
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   378
subsection "Min and max on (linear) orders"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   379
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   380
lemma min_same [simp]: "min (x::'a::order) x = x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   381
  by (simp add: min_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   382
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   383
lemma max_same [simp]: "max (x::'a::order) x = x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   384
  by (simp add: max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   385
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   386
text{* Instantiate locales: *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   387
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   388
lemma lower_semilattice_lin_min:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   389
  "lower_semilattice(op \<le>) (min :: 'a::linorder \<Rightarrow> 'a \<Rightarrow> 'a)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   390
apply(rule lower_semilattice.intro)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   391
apply(rule partial_order_order)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   392
apply(rule lower_semilattice_axioms.intro)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   393
apply(simp add:min_def linorder_not_le order_less_imp_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   394
apply(simp add:min_def linorder_not_le order_less_imp_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   395
apply(simp add:min_def linorder_not_le order_less_imp_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   396
done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   397
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   398
lemma upper_semilattice_lin_max:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   399
  "upper_semilattice(op \<le>) (max :: 'a::linorder \<Rightarrow> 'a \<Rightarrow> 'a)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   400
apply(rule upper_semilattice.intro)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   401
apply(rule partial_order_order)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   402
apply(rule upper_semilattice_axioms.intro)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   403
apply(simp add: max_def linorder_not_le order_less_imp_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   404
apply(simp add: max_def linorder_not_le order_less_imp_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   405
apply(simp add: max_def linorder_not_le order_less_imp_le)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   406
done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   407
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   408
lemma lattice_min_max: "lattice (op \<le>) (min :: 'a::linorder \<Rightarrow> 'a \<Rightarrow> 'a) max"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   409
apply(rule lattice.intro)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   410
apply(rule partial_order_order)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   411
apply(rule lower_semilattice.axioms[OF lower_semilattice_lin_min])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   412
apply(rule upper_semilattice.axioms[OF upper_semilattice_lin_max])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   413
done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   414
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   415
lemma distrib_lattice_min_max:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   416
 "distrib_lattice (op \<le>) (min :: 'a::linorder \<Rightarrow> 'a \<Rightarrow> 'a) max"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   417
apply(rule distrib_lattice.intro)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   418
apply(rule partial_order_order)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   419
apply(rule lower_semilattice.axioms[OF lower_semilattice_lin_min])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   420
apply(rule upper_semilattice.axioms[OF upper_semilattice_lin_max])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   421
apply(rule distrib_lattice_axioms.intro)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   422
apply(rule_tac x=x and y=y in linorder_le_cases)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   423
apply(rule_tac x=x and y=z in linorder_le_cases)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   424
apply(rule_tac x=y and y=z in linorder_le_cases)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   425
apply(simp add:min_def max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   426
apply(simp add:min_def max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   427
apply(rule_tac x=y and y=z in linorder_le_cases)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   428
apply(simp add:min_def max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   429
apply(simp add:min_def max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   430
apply(rule_tac x=x and y=z in linorder_le_cases)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   431
apply(rule_tac x=y and y=z in linorder_le_cases)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   432
apply(simp add:min_def max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   433
apply(simp add:min_def max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   434
apply(rule_tac x=y and y=z in linorder_le_cases)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   435
apply(simp add:min_def max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   436
apply(simp add:min_def max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   437
done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   438
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   439
lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   440
  apply(simp add:max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   441
  apply (insert linorder_linear)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   442
  apply (blast intro: order_trans)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   443
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   444
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   445
lemma le_maxI1: "(x::'a::linorder) <= max x y"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   446
by(rule upper_semilattice.sup_ge1[OF upper_semilattice_lin_max])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   447
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   448
lemma le_maxI2: "(y::'a::linorder) <= max x y"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   449
    -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   450
by(rule upper_semilattice.sup_ge2[OF upper_semilattice_lin_max])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   451
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   452
lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   453
  apply (simp add: max_def order_le_less)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   454
  apply (insert linorder_less_linear)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   455
  apply (blast intro: order_less_trans)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   456
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   457
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   458
lemma max_le_iff_conj [simp]:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   459
    "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   460
by (rule upper_semilattice.above_sup_conv[OF upper_semilattice_lin_max])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   461
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   462
lemma max_less_iff_conj [simp]:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   463
    "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   464
  apply (simp add: order_le_less max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   465
  apply (insert linorder_less_linear)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   466
  apply (blast intro: order_less_trans)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   467
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   468
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   469
lemma le_min_iff_conj [simp]:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   470
    "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   471
    -- {* @{text "[iff]"} screws up a @{text blast} in MiniML *}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   472
by (rule lower_semilattice.below_inf_conv[OF lower_semilattice_lin_min])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   473
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   474
lemma min_less_iff_conj [simp]:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   475
    "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   476
  apply (simp add: order_le_less min_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   477
  apply (insert linorder_less_linear)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   478
  apply (blast intro: order_less_trans)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   479
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   480
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   481
lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   482
  apply (simp add: min_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   483
  apply (insert linorder_linear)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   484
  apply (blast intro: order_trans)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   485
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   486
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   487
lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   488
  apply (simp add: min_def order_le_less)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   489
  apply (insert linorder_less_linear)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   490
  apply (blast intro: order_less_trans)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   491
  done
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   492
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   493
lemma max_assoc: "!!x::'a::linorder. max (max x y) z = max x (max y z)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   494
by (rule upper_semilattice.sup_assoc[OF upper_semilattice_lin_max])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   495
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   496
lemma max_commute: "!!x::'a::linorder. max x y = max y x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   497
by (rule upper_semilattice.sup_commute[OF upper_semilattice_lin_max])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   498
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   499
lemmas max_ac = max_assoc max_commute
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   500
                mk_left_commute[of max,OF max_assoc max_commute]
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   501
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   502
lemma min_assoc: "!!x::'a::linorder. min (min x y) z = min x (min y z)"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   503
by (rule lower_semilattice.inf_assoc[OF lower_semilattice_lin_min])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   504
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   505
lemma min_commute: "!!x::'a::linorder. min x y = min y x"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   506
by (rule lower_semilattice.inf_commute[OF lower_semilattice_lin_min])
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   507
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   508
lemmas min_ac = min_assoc min_commute
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   509
                mk_left_commute[of min,OF min_assoc min_commute]
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   510
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   511
lemma split_min:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   512
    "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   513
  by (simp add: min_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   514
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   515
lemma split_max:
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   516
    "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   517
  by (simp add: max_def)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   518
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   519
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   520
subsection "Bounded quantifiers"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   521
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   522
syntax
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   523
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   524
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   525
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   526
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   527
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   528
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _>_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   529
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _>_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   530
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _>=_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   531
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _>=_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   532
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   533
syntax (xsymbols)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   534
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   535
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   536
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   537
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   538
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   539
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   540
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   541
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   542
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   543
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   544
syntax (HOL)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   545
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   546
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   547
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   548
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   549
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   550
syntax (HTML output)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   551
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   552
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   553
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   554
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   555
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   556
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   557
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   558
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   559
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   560
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   561
translations
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   562
 "ALL x<y. P"   =>  "ALL x. x < y --> P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   563
 "EX x<y. P"    =>  "EX x. x < y  & P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   564
 "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   565
 "EX x<=y. P"   =>  "EX x. x <= y & P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   566
 "ALL x>y. P"   =>  "ALL x. x > y --> P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   567
 "EX x>y. P"    =>  "EX x. x > y  & P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   568
 "ALL x>=y. P"  =>  "ALL x. x >= y --> P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   569
 "EX x>=y. P"   =>  "EX x. x >= y & P"
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   570
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   571
print_translation {*
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   572
let
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   573
  fun mk v v' q n P =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   574
    if v=v' andalso not(v  mem (map fst (Term.add_frees([],n))))
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   575
    then Syntax.const q $ Syntax.mark_bound v' $ n $ P else raise Match;
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   576
  fun all_tr' [Const ("_bound",_) $ Free (v,_),
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   577
               Const("op -->",_) $ (Const ("op <",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   578
    mk v v' "_lessAll" n P
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   579
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   580
  | all_tr' [Const ("_bound",_) $ Free (v,_),
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   581
               Const("op -->",_) $ (Const ("op <=",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   582
    mk v v' "_leAll" n P
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   583
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   584
  | all_tr' [Const ("_bound",_) $ Free (v,_),
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   585
               Const("op -->",_) $ (Const ("op <",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   586
    mk v v' "_gtAll" n P
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   587
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   588
  | all_tr' [Const ("_bound",_) $ Free (v,_),
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   589
               Const("op -->",_) $ (Const ("op <=",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   590
    mk v v' "_geAll" n P;
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   591
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   592
  fun ex_tr' [Const ("_bound",_) $ Free (v,_),
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   593
               Const("op &",_) $ (Const ("op <",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   594
    mk v v' "_lessEx" n P
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   595
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   596
  | ex_tr' [Const ("_bound",_) $ Free (v,_),
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   597
               Const("op &",_) $ (Const ("op <=",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   598
    mk v v' "_leEx" n P
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   599
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   600
  | ex_tr' [Const ("_bound",_) $ Free (v,_),
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   601
               Const("op &",_) $ (Const ("op <",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   602
    mk v v' "_gtEx" n P
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   603
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   604
  | ex_tr' [Const ("_bound",_) $ Free (v,_),
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   605
               Const("op &",_) $ (Const ("op <=",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] =
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   606
    mk v v' "_geEx" n P
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   607
in
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   608
[("ALL ", all_tr'), ("EX ", ex_tr')]
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   609
end
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   610
*}
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   611
2ef571f80a55 Moved oderings from HOL into the new Orderings.thy
nipkow
parents:
diff changeset
   612
end