src/HOL/HOL.thy
author wenzelm
Fri Oct 26 23:59:13 2001 +0200 (2001-10-26)
changeset 11953 f98623fdf6ef
parent 11824 f4c1882dde2c
child 11977 2e7c54b86763
permissions -rw-r--r--
atomize_conj;
clasohm@923
     1
(*  Title:      HOL/HOL.thy
clasohm@923
     2
    ID:         $Id$
wenzelm@11750
     3
    Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
wenzelm@11750
     4
*)
clasohm@923
     5
wenzelm@11750
     6
header {* The basis of Higher-Order Logic *}
clasohm@923
     7
wenzelm@7357
     8
theory HOL = CPure
paulson@11451
     9
files ("HOL_lemmas.ML") ("cladata.ML") ("blastdata.ML") ("simpdata.ML"):
clasohm@923
    10
wenzelm@2260
    11
wenzelm@11750
    12
subsection {* Primitive logic *}
wenzelm@11750
    13
wenzelm@11750
    14
subsubsection {* Core syntax *}
wenzelm@2260
    15
wenzelm@3947
    16
global
wenzelm@3947
    17
wenzelm@7357
    18
classes "term" < logic
wenzelm@7357
    19
defaultsort "term"
clasohm@923
    20
wenzelm@7357
    21
typedecl bool
clasohm@923
    22
clasohm@923
    23
arities
wenzelm@7357
    24
  bool :: "term"
wenzelm@7357
    25
  fun :: ("term", "term") "term"
clasohm@923
    26
wenzelm@11750
    27
judgment
wenzelm@11750
    28
  Trueprop      :: "bool => prop"                   ("(_)" 5)
clasohm@923
    29
wenzelm@11750
    30
consts
wenzelm@7357
    31
  Not           :: "bool => bool"                   ("~ _" [40] 40)
wenzelm@7357
    32
  True          :: bool
wenzelm@7357
    33
  False         :: bool
wenzelm@7357
    34
  If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
wenzelm@3947
    35
  arbitrary     :: 'a
clasohm@923
    36
wenzelm@11432
    37
  The           :: "('a => bool) => 'a"
wenzelm@7357
    38
  All           :: "('a => bool) => bool"           (binder "ALL " 10)
wenzelm@7357
    39
  Ex            :: "('a => bool) => bool"           (binder "EX " 10)
wenzelm@7357
    40
  Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
wenzelm@7357
    41
  Let           :: "['a, 'a => 'b] => 'b"
clasohm@923
    42
wenzelm@7357
    43
  "="           :: "['a, 'a] => bool"               (infixl 50)
wenzelm@7357
    44
  &             :: "[bool, bool] => bool"           (infixr 35)
wenzelm@7357
    45
  "|"           :: "[bool, bool] => bool"           (infixr 30)
wenzelm@7357
    46
  -->           :: "[bool, bool] => bool"           (infixr 25)
clasohm@923
    47
wenzelm@10432
    48
local
wenzelm@10432
    49
wenzelm@2260
    50
wenzelm@11750
    51
subsubsection {* Additional concrete syntax *}
wenzelm@2260
    52
wenzelm@4868
    53
nonterminals
clasohm@923
    54
  letbinds  letbind
clasohm@923
    55
  case_syn  cases_syn
clasohm@923
    56
clasohm@923
    57
syntax
wenzelm@7357
    58
  ~=            :: "['a, 'a] => bool"                    (infixl 50)
wenzelm@11432
    59
  "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
clasohm@923
    60
wenzelm@7357
    61
  "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
wenzelm@7357
    62
  ""            :: "letbind => letbinds"                 ("_")
wenzelm@7357
    63
  "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
wenzelm@7357
    64
  "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
clasohm@923
    65
wenzelm@9060
    66
  "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
wenzelm@9060
    67
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
wenzelm@7357
    68
  ""            :: "case_syn => cases_syn"               ("_")
wenzelm@9060
    69
  "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
clasohm@923
    70
clasohm@923
    71
translations
wenzelm@7238
    72
  "x ~= y"                == "~ (x = y)"
wenzelm@11432
    73
  "THE x. P"              == "The (%x. P)"
clasohm@923
    74
  "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
nipkow@1114
    75
  "let x = a in e"        == "Let a (%x. e)"
clasohm@923
    76
wenzelm@3820
    77
syntax ("" output)
wenzelm@11687
    78
  "="           :: "['a, 'a] => bool"                    (infix 50)
wenzelm@11687
    79
  "~="          :: "['a, 'a] => bool"                    (infix 50)
wenzelm@2260
    80
wenzelm@2260
    81
syntax (symbols)
wenzelm@11687
    82
  Not           :: "bool => bool"                        ("\<not> _" [40] 40)
wenzelm@11687
    83
  "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
wenzelm@11687
    84
  "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
wenzelm@11687
    85
  "op -->"      :: "[bool, bool] => bool"                (infixr "\<midarrow>\<rightarrow>" 25)
wenzelm@11687
    86
  "op ~="       :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@11687
    87
  "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
wenzelm@11687
    88
  "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
wenzelm@11687
    89
  "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
wenzelm@11687
    90
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
wenzelm@9060
    91
(*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \\<orelse> _")*)
wenzelm@2372
    92
wenzelm@3820
    93
syntax (symbols output)
wenzelm@11687
    94
  "op ~="       :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@3820
    95
oheimb@6027
    96
syntax (xsymbols)
wenzelm@11687
    97
  "op -->"      :: "[bool, bool] => bool"                (infixr "\<longrightarrow>" 25)
wenzelm@2260
    98
wenzelm@6340
    99
syntax (HTML output)
wenzelm@11687
   100
  Not           :: "bool => bool"                        ("\<not> _" [40] 40)
wenzelm@6340
   101
wenzelm@7238
   102
syntax (HOL)
wenzelm@7357
   103
  "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
wenzelm@7357
   104
  "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
wenzelm@7357
   105
  "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
wenzelm@7238
   106
wenzelm@7238
   107
wenzelm@11750
   108
subsubsection {* Axioms and basic definitions *}
wenzelm@2260
   109
wenzelm@7357
   110
axioms
wenzelm@7357
   111
  eq_reflection: "(x=y) ==> (x==y)"
clasohm@923
   112
wenzelm@7357
   113
  refl:         "t = (t::'a)"
wenzelm@7357
   114
  subst:        "[| s = t; P(s) |] ==> P(t::'a)"
paulson@6289
   115
wenzelm@7357
   116
  ext:          "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
wenzelm@11750
   117
    -- {* Extensionality is built into the meta-logic, and this rule expresses *}
wenzelm@11750
   118
    -- {* a related property.  It is an eta-expanded version of the traditional *}
wenzelm@11750
   119
    -- {* rule, and similar to the ABS rule of HOL *}
paulson@6289
   120
wenzelm@11432
   121
  the_eq_trivial: "(THE x. x = a) = (a::'a)"
clasohm@923
   122
wenzelm@7357
   123
  impI:         "(P ==> Q) ==> P-->Q"
wenzelm@7357
   124
  mp:           "[| P-->Q;  P |] ==> Q"
clasohm@923
   125
clasohm@923
   126
defs
wenzelm@7357
   127
  True_def:     "True      == ((%x::bool. x) = (%x. x))"
wenzelm@7357
   128
  All_def:      "All(P)    == (P = (%x. True))"
paulson@11451
   129
  Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
wenzelm@7357
   130
  False_def:    "False     == (!P. P)"
wenzelm@7357
   131
  not_def:      "~ P       == P-->False"
wenzelm@7357
   132
  and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
wenzelm@7357
   133
  or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
wenzelm@7357
   134
  Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
clasohm@923
   135
wenzelm@7357
   136
axioms
wenzelm@7357
   137
  iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
wenzelm@7357
   138
  True_or_False:  "(P=True) | (P=False)"
clasohm@923
   139
clasohm@923
   140
defs
wenzelm@7357
   141
  Let_def:      "Let s f == f(s)"
paulson@11451
   142
  if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
wenzelm@5069
   143
paulson@11451
   144
  arbitrary_def:  "False ==> arbitrary == (THE x. False)"
wenzelm@11750
   145
    -- {* @{term arbitrary} is completely unspecified, but is made to appear as a
wenzelm@11750
   146
    definition syntactically *}
clasohm@923
   147
nipkow@3320
   148
wenzelm@11750
   149
subsubsection {* Generic algebraic operations *}
wenzelm@4868
   150
wenzelm@11750
   151
axclass zero < "term"
wenzelm@11750
   152
axclass one < "term"
wenzelm@11750
   153
axclass plus < "term"
wenzelm@11750
   154
axclass minus < "term"
wenzelm@11750
   155
axclass times < "term"
wenzelm@11750
   156
axclass inverse < "term"
wenzelm@11750
   157
wenzelm@11750
   158
global
wenzelm@11750
   159
wenzelm@11750
   160
consts
wenzelm@11750
   161
  "0"           :: "'a::zero"                       ("0")
wenzelm@11750
   162
  "1"           :: "'a::one"                        ("1")
wenzelm@11750
   163
  "+"           :: "['a::plus, 'a]  => 'a"          (infixl 65)
wenzelm@11750
   164
  -             :: "['a::minus, 'a] => 'a"          (infixl 65)
wenzelm@11750
   165
  uminus        :: "['a::minus] => 'a"              ("- _" [81] 80)
wenzelm@11750
   166
  *             :: "['a::times, 'a] => 'a"          (infixl 70)
wenzelm@11750
   167
wenzelm@11750
   168
local
wenzelm@11750
   169
wenzelm@11750
   170
typed_print_translation {*
wenzelm@11750
   171
  let
wenzelm@11750
   172
    fun tr' c = (c, fn show_sorts => fn T => fn ts =>
wenzelm@11750
   173
      if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
wenzelm@11750
   174
      else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);
wenzelm@11750
   175
  in [tr' "0", tr' "1"] end;
wenzelm@11750
   176
*} -- {* show types that are presumably too general *}
wenzelm@11750
   177
wenzelm@11750
   178
wenzelm@11750
   179
consts
wenzelm@11750
   180
  abs           :: "'a::minus => 'a"
wenzelm@11750
   181
  inverse       :: "'a::inverse => 'a"
wenzelm@11750
   182
  divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
wenzelm@11750
   183
wenzelm@11750
   184
syntax (xsymbols)
wenzelm@11750
   185
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
wenzelm@11750
   186
syntax (HTML output)
wenzelm@11750
   187
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
wenzelm@11750
   188
wenzelm@11750
   189
axclass plus_ac0 < plus, zero
wenzelm@11750
   190
  commute: "x + y = y + x"
wenzelm@11750
   191
  assoc:   "(x + y) + z = x + (y + z)"
wenzelm@11750
   192
  zero:    "0 + x = x"
wenzelm@11750
   193
wenzelm@11750
   194
wenzelm@11750
   195
subsection {* Theory and package setup *}
wenzelm@11750
   196
wenzelm@11750
   197
subsubsection {* Basic lemmas *}
wenzelm@4868
   198
nipkow@9736
   199
use "HOL_lemmas.ML"
wenzelm@11687
   200
theorems case_split = case_split_thm [case_names True False]
wenzelm@9869
   201
wenzelm@11750
   202
declare trans [trans]
wenzelm@11750
   203
declare impE [CPure.elim]  iffD1 [CPure.elim]  iffD2 [CPure.elim]
wenzelm@11750
   204
wenzelm@11438
   205
wenzelm@11750
   206
subsubsection {* Atomizing meta-level connectives *}
wenzelm@11750
   207
wenzelm@11750
   208
lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
wenzelm@9488
   209
proof (rule equal_intr_rule)
wenzelm@9488
   210
  assume "!!x. P x"
wenzelm@10383
   211
  show "ALL x. P x" by (rule allI)
wenzelm@9488
   212
next
wenzelm@9488
   213
  assume "ALL x. P x"
wenzelm@10383
   214
  thus "!!x. P x" by (rule allE)
wenzelm@9488
   215
qed
wenzelm@9488
   216
wenzelm@11750
   217
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
wenzelm@9488
   218
proof (rule equal_intr_rule)
wenzelm@9488
   219
  assume r: "A ==> B"
wenzelm@10383
   220
  show "A --> B" by (rule impI) (rule r)
wenzelm@9488
   221
next
wenzelm@9488
   222
  assume "A --> B" and A
wenzelm@10383
   223
  thus B by (rule mp)
wenzelm@9488
   224
qed
wenzelm@9488
   225
wenzelm@11750
   226
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
wenzelm@10432
   227
proof (rule equal_intr_rule)
wenzelm@10432
   228
  assume "x == y"
wenzelm@10432
   229
  show "x = y" by (unfold prems) (rule refl)
wenzelm@10432
   230
next
wenzelm@10432
   231
  assume "x = y"
wenzelm@10432
   232
  thus "x == y" by (rule eq_reflection)
wenzelm@10432
   233
qed
wenzelm@10432
   234
wenzelm@11953
   235
lemma atomize_conj [atomize]: "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
wenzelm@11953
   236
proof (rule equal_intr_rule)
wenzelm@11953
   237
  assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
wenzelm@11953
   238
  show "A & B" by (rule conjI)
wenzelm@11953
   239
next
wenzelm@11953
   240
  fix C
wenzelm@11953
   241
  assume "A & B"
wenzelm@11953
   242
  assume "A ==> B ==> PROP C"
wenzelm@11953
   243
  thus "PROP C"
wenzelm@11953
   244
  proof this
wenzelm@11953
   245
    show A by (rule conjunct1)
wenzelm@11953
   246
    show B by (rule conjunct2)
wenzelm@11953
   247
  qed
wenzelm@11953
   248
qed
wenzelm@11953
   249
wenzelm@11750
   250
wenzelm@11750
   251
subsubsection {* Classical Reasoner setup *}
wenzelm@9529
   252
wenzelm@10383
   253
use "cladata.ML"
wenzelm@10383
   254
setup hypsubst_setup
wenzelm@11770
   255
declare atomize_all [symmetric, rulify]  atomize_imp [symmetric, rulify]
wenzelm@10383
   256
setup Classical.setup
wenzelm@10383
   257
setup clasetup
wenzelm@10383
   258
wenzelm@9869
   259
use "blastdata.ML"
wenzelm@9869
   260
setup Blast.setup
wenzelm@4868
   261
wenzelm@11750
   262
wenzelm@11750
   263
subsubsection {* Simplifier setup *}
wenzelm@11750
   264
wenzelm@9869
   265
use "simpdata.ML"
wenzelm@9869
   266
setup Simplifier.setup
wenzelm@9869
   267
setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
wenzelm@9869
   268
setup Splitter.setup setup Clasimp.setup
wenzelm@9869
   269
wenzelm@11750
   270
wenzelm@11824
   271
subsubsection {* Generic cases and induction *}
wenzelm@11824
   272
wenzelm@11824
   273
constdefs
wenzelm@11824
   274
  inductive_forall :: "('a => bool) => bool"
wenzelm@11824
   275
  "inductive_forall P == \<forall>x. P x"
wenzelm@11824
   276
  inductive_implies :: "bool => bool => bool"
wenzelm@11824
   277
  "inductive_implies A B == A --> B"
wenzelm@11824
   278
  inductive_equal :: "'a => 'a => bool"
wenzelm@11824
   279
  "inductive_equal x y == x = y"
wenzelm@11824
   280
  inductive_conj :: "bool => bool => bool"
wenzelm@11824
   281
  "inductive_conj A B == A & B"
wenzelm@11824
   282
wenzelm@11824
   283
lemma inductive_forall_eq: "(!!x. P x) == Trueprop (inductive_forall (\<lambda>x. P x))"
wenzelm@11824
   284
  by (simp only: atomize_all inductive_forall_def)
wenzelm@11824
   285
wenzelm@11824
   286
lemma inductive_implies_eq: "(A ==> B) == Trueprop (inductive_implies A B)"
wenzelm@11824
   287
  by (simp only: atomize_imp inductive_implies_def)
wenzelm@11824
   288
wenzelm@11824
   289
lemma inductive_equal_eq: "(x == y) == Trueprop (inductive_equal x y)"
wenzelm@11824
   290
  by (simp only: atomize_eq inductive_equal_def)
wenzelm@11824
   291
wenzelm@11824
   292
lemma inductive_forall_conj: "inductive_forall (\<lambda>x. inductive_conj (A x) (B x)) =
wenzelm@11824
   293
    inductive_conj (inductive_forall A) (inductive_forall B)"
wenzelm@11824
   294
  by (unfold inductive_forall_def inductive_conj_def) blast
wenzelm@11824
   295
wenzelm@11824
   296
lemma inductive_implies_conj: "inductive_implies C (inductive_conj A B) =
wenzelm@11824
   297
    inductive_conj (inductive_implies C A) (inductive_implies C B)"
wenzelm@11824
   298
  by (unfold inductive_implies_def inductive_conj_def) blast
wenzelm@11824
   299
wenzelm@11824
   300
lemma inductive_conj_curry: "(inductive_conj A B ==> C) == (A ==> B ==> C)"
wenzelm@11824
   301
  by (simp only: atomize_imp atomize_eq inductive_conj_def) (rule equal_intr_rule, blast+)
wenzelm@11824
   302
wenzelm@11824
   303
lemmas inductive_atomize = inductive_forall_eq inductive_implies_eq inductive_equal_eq
wenzelm@11824
   304
lemmas inductive_rulify1 = inductive_atomize [symmetric, standard]
wenzelm@11824
   305
lemmas inductive_rulify2 =
wenzelm@11824
   306
  inductive_forall_def inductive_implies_def inductive_equal_def inductive_conj_def
wenzelm@11824
   307
lemmas inductive_conj = inductive_forall_conj inductive_implies_conj inductive_conj_curry
wenzelm@11824
   308
wenzelm@11824
   309
hide const inductive_forall inductive_implies inductive_equal inductive_conj
wenzelm@11824
   310
wenzelm@11824
   311
wenzelm@11824
   312
text {* Method setup. *}
wenzelm@11824
   313
wenzelm@11824
   314
ML {*
wenzelm@11824
   315
  structure InductMethod = InductMethodFun
wenzelm@11824
   316
  (struct
wenzelm@11824
   317
    val dest_concls = HOLogic.dest_concls;
wenzelm@11824
   318
    val cases_default = thm "case_split";
wenzelm@11824
   319
    val conjI = thm "conjI";
wenzelm@11824
   320
    val atomize = thms "inductive_atomize";
wenzelm@11824
   321
    val rulify1 = thms "inductive_rulify1";
wenzelm@11824
   322
    val rulify2 = thms "inductive_rulify2";
wenzelm@11824
   323
  end);
wenzelm@11824
   324
*}
wenzelm@11824
   325
wenzelm@11824
   326
setup InductMethod.setup
wenzelm@11824
   327
wenzelm@11824
   328
wenzelm@11750
   329
subsection {* Order signatures and orders *}
wenzelm@11750
   330
wenzelm@11750
   331
axclass
wenzelm@11750
   332
  ord < "term"
wenzelm@11750
   333
wenzelm@11750
   334
syntax
wenzelm@11750
   335
  "op <"        :: "['a::ord, 'a] => bool"             ("op <")
wenzelm@11750
   336
  "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
wenzelm@11750
   337
wenzelm@11750
   338
global
wenzelm@11750
   339
wenzelm@11750
   340
consts
wenzelm@11750
   341
  "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
wenzelm@11750
   342
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
wenzelm@11750
   343
wenzelm@11750
   344
local
wenzelm@11750
   345
wenzelm@11750
   346
syntax (symbols)
wenzelm@11750
   347
  "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
wenzelm@11750
   348
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
wenzelm@11750
   349
wenzelm@11750
   350
(*Tell blast about overloading of < and <= to reduce the risk of
wenzelm@11750
   351
  its applying a rule for the wrong type*)
wenzelm@11750
   352
ML {*
wenzelm@11750
   353
Blast.overloaded ("op <" , domain_type);
wenzelm@11750
   354
Blast.overloaded ("op <=", domain_type);
wenzelm@11750
   355
*}
wenzelm@11750
   356
wenzelm@11750
   357
wenzelm@11750
   358
subsubsection {* Monotonicity *}
wenzelm@11750
   359
wenzelm@11750
   360
constdefs
wenzelm@11750
   361
  mono :: "['a::ord => 'b::ord] => bool"
wenzelm@11750
   362
  "mono f == ALL A B. A <= B --> f A <= f B"
wenzelm@11750
   363
wenzelm@11750
   364
lemma monoI [intro?]: "(!!A B. A <= B ==> f A <= f B) ==> mono f"
wenzelm@11750
   365
  by (unfold mono_def) blast
wenzelm@11750
   366
wenzelm@11750
   367
lemma monoD [dest?]: "mono f ==> A <= B ==> f A <= f B"
wenzelm@11750
   368
  by (unfold mono_def) blast
wenzelm@11750
   369
wenzelm@11750
   370
constdefs
wenzelm@11750
   371
  min :: "['a::ord, 'a] => 'a"
wenzelm@11750
   372
  "min a b == (if a <= b then a else b)"
wenzelm@11750
   373
  max :: "['a::ord, 'a] => 'a"
wenzelm@11750
   374
  "max a b == (if a <= b then b else a)"
wenzelm@11750
   375
wenzelm@11750
   376
lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
wenzelm@11750
   377
  by (simp add: min_def)
wenzelm@11750
   378
wenzelm@11750
   379
lemma min_of_mono:
wenzelm@11750
   380
    "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
wenzelm@11750
   381
  by (simp add: min_def)
wenzelm@11750
   382
wenzelm@11750
   383
lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
wenzelm@11750
   384
  by (simp add: max_def)
wenzelm@11750
   385
wenzelm@11750
   386
lemma max_of_mono:
wenzelm@11750
   387
    "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
wenzelm@11750
   388
  by (simp add: max_def)
wenzelm@11750
   389
wenzelm@11750
   390
wenzelm@11750
   391
subsubsection "Orders"
wenzelm@11750
   392
wenzelm@11750
   393
axclass order < ord
wenzelm@11750
   394
  order_refl [iff]: "x <= x"
wenzelm@11750
   395
  order_trans: "x <= y ==> y <= z ==> x <= z"
wenzelm@11750
   396
  order_antisym: "x <= y ==> y <= x ==> x = y"
wenzelm@11750
   397
  order_less_le: "(x < y) = (x <= y & x ~= y)"
wenzelm@11750
   398
wenzelm@11750
   399
wenzelm@11750
   400
text {* Reflexivity. *}
wenzelm@11750
   401
wenzelm@11750
   402
lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
wenzelm@11750
   403
    -- {* This form is useful with the classical reasoner. *}
wenzelm@11750
   404
  apply (erule ssubst)
wenzelm@11750
   405
  apply (rule order_refl)
wenzelm@11750
   406
  done
wenzelm@11750
   407
wenzelm@11750
   408
lemma order_less_irrefl [simp]: "~ x < (x::'a::order)"
wenzelm@11750
   409
  by (simp add: order_less_le)
wenzelm@11750
   410
wenzelm@11750
   411
lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
wenzelm@11750
   412
    -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
wenzelm@11750
   413
  apply (simp add: order_less_le)
wenzelm@11750
   414
  apply (blast intro!: order_refl)
wenzelm@11750
   415
  done
wenzelm@11750
   416
wenzelm@11750
   417
lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
wenzelm@11750
   418
wenzelm@11750
   419
lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
wenzelm@11750
   420
  by (simp add: order_less_le)
wenzelm@11750
   421
wenzelm@11750
   422
wenzelm@11750
   423
text {* Asymmetry. *}
wenzelm@11750
   424
wenzelm@11750
   425
lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
wenzelm@11750
   426
  by (simp add: order_less_le order_antisym)
wenzelm@11750
   427
wenzelm@11750
   428
lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
wenzelm@11750
   429
  apply (drule order_less_not_sym)
wenzelm@11750
   430
  apply (erule contrapos_np)
wenzelm@11750
   431
  apply simp
wenzelm@11750
   432
  done
wenzelm@11750
   433
wenzelm@11750
   434
wenzelm@11750
   435
text {* Transitivity. *}
wenzelm@11750
   436
wenzelm@11750
   437
lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
wenzelm@11750
   438
  apply (simp add: order_less_le)
wenzelm@11750
   439
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   440
  done
wenzelm@11750
   441
wenzelm@11750
   442
lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
wenzelm@11750
   443
  apply (simp add: order_less_le)
wenzelm@11750
   444
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   445
  done
wenzelm@11750
   446
wenzelm@11750
   447
lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
wenzelm@11750
   448
  apply (simp add: order_less_le)
wenzelm@11750
   449
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   450
  done
wenzelm@11750
   451
wenzelm@11750
   452
wenzelm@11750
   453
text {* Useful for simplification, but too risky to include by default. *}
wenzelm@11750
   454
wenzelm@11750
   455
lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
wenzelm@11750
   456
  by (blast elim: order_less_asym)
wenzelm@11750
   457
wenzelm@11750
   458
lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
wenzelm@11750
   459
  by (blast elim: order_less_asym)
wenzelm@11750
   460
wenzelm@11750
   461
lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
wenzelm@11750
   462
  by auto
wenzelm@11750
   463
wenzelm@11750
   464
lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
wenzelm@11750
   465
  by auto
wenzelm@11750
   466
wenzelm@11750
   467
wenzelm@11750
   468
text {* Other operators. *}
wenzelm@11750
   469
wenzelm@11750
   470
lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
wenzelm@11750
   471
  apply (simp add: min_def)
wenzelm@11750
   472
  apply (blast intro: order_antisym)
wenzelm@11750
   473
  done
wenzelm@11750
   474
wenzelm@11750
   475
lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
wenzelm@11750
   476
  apply (simp add: max_def)
wenzelm@11750
   477
  apply (blast intro: order_antisym)
wenzelm@11750
   478
  done
wenzelm@11750
   479
wenzelm@11750
   480
wenzelm@11750
   481
subsubsection {* Least value operator *}
wenzelm@11750
   482
wenzelm@11750
   483
constdefs
wenzelm@11750
   484
  Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
wenzelm@11750
   485
  "Least P == THE x. P x & (ALL y. P y --> x <= y)"
wenzelm@11750
   486
    -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
wenzelm@11750
   487
wenzelm@11750
   488
lemma LeastI2:
wenzelm@11750
   489
  "[| P (x::'a::order);
wenzelm@11750
   490
      !!y. P y ==> x <= y;
wenzelm@11750
   491
      !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
wenzelm@11750
   492
   ==> Q (Least P)";
wenzelm@11750
   493
  apply (unfold Least_def)
wenzelm@11750
   494
  apply (rule theI2)
wenzelm@11750
   495
    apply (blast intro: order_antisym)+
wenzelm@11750
   496
  done
wenzelm@11750
   497
wenzelm@11750
   498
lemma Least_equality:
wenzelm@11750
   499
    "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k";
wenzelm@11750
   500
  apply (simp add: Least_def)
wenzelm@11750
   501
  apply (rule the_equality)
wenzelm@11750
   502
  apply (auto intro!: order_antisym)
wenzelm@11750
   503
  done
wenzelm@11750
   504
wenzelm@11750
   505
wenzelm@11750
   506
subsubsection "Linear / total orders"
wenzelm@11750
   507
wenzelm@11750
   508
axclass linorder < order
wenzelm@11750
   509
  linorder_linear: "x <= y | y <= x"
wenzelm@11750
   510
wenzelm@11750
   511
lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
wenzelm@11750
   512
  apply (simp add: order_less_le)
wenzelm@11750
   513
  apply (insert linorder_linear)
wenzelm@11750
   514
  apply blast
wenzelm@11750
   515
  done
wenzelm@11750
   516
wenzelm@11750
   517
lemma linorder_cases [case_names less equal greater]:
wenzelm@11750
   518
    "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
wenzelm@11750
   519
  apply (insert linorder_less_linear)
wenzelm@11750
   520
  apply blast
wenzelm@11750
   521
  done
wenzelm@11750
   522
wenzelm@11750
   523
lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
wenzelm@11750
   524
  apply (simp add: order_less_le)
wenzelm@11750
   525
  apply (insert linorder_linear)
wenzelm@11750
   526
  apply (blast intro: order_antisym)
wenzelm@11750
   527
  done
wenzelm@11750
   528
wenzelm@11750
   529
lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
wenzelm@11750
   530
  apply (simp add: order_less_le)
wenzelm@11750
   531
  apply (insert linorder_linear)
wenzelm@11750
   532
  apply (blast intro: order_antisym)
wenzelm@11750
   533
  done
wenzelm@11750
   534
wenzelm@11750
   535
lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
wenzelm@11750
   536
  apply (cut_tac x = x and y = y in linorder_less_linear)
wenzelm@11750
   537
  apply auto
wenzelm@11750
   538
  done
wenzelm@11750
   539
wenzelm@11750
   540
lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
wenzelm@11750
   541
  apply (simp add: linorder_neq_iff)
wenzelm@11750
   542
  apply blast
wenzelm@11750
   543
  done
wenzelm@11750
   544
wenzelm@11750
   545
wenzelm@11750
   546
subsubsection "Min and max on (linear) orders"
wenzelm@11750
   547
wenzelm@11750
   548
lemma min_same [simp]: "min (x::'a::order) x = x"
wenzelm@11750
   549
  by (simp add: min_def)
wenzelm@11750
   550
wenzelm@11750
   551
lemma max_same [simp]: "max (x::'a::order) x = x"
wenzelm@11750
   552
  by (simp add: max_def)
wenzelm@11750
   553
wenzelm@11750
   554
lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
wenzelm@11750
   555
  apply (simp add: max_def)
wenzelm@11750
   556
  apply (insert linorder_linear)
wenzelm@11750
   557
  apply (blast intro: order_trans)
wenzelm@11750
   558
  done
wenzelm@11750
   559
wenzelm@11750
   560
lemma le_maxI1: "(x::'a::linorder) <= max x y"
wenzelm@11750
   561
  by (simp add: le_max_iff_disj)
wenzelm@11750
   562
wenzelm@11750
   563
lemma le_maxI2: "(y::'a::linorder) <= max x y"
wenzelm@11750
   564
    -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
wenzelm@11750
   565
  by (simp add: le_max_iff_disj)
wenzelm@11750
   566
wenzelm@11750
   567
lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
wenzelm@11750
   568
  apply (simp add: max_def order_le_less)
wenzelm@11750
   569
  apply (insert linorder_less_linear)
wenzelm@11750
   570
  apply (blast intro: order_less_trans)
wenzelm@11750
   571
  done
wenzelm@11750
   572
wenzelm@11750
   573
lemma max_le_iff_conj [simp]:
wenzelm@11750
   574
    "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
wenzelm@11750
   575
  apply (simp add: max_def)
wenzelm@11750
   576
  apply (insert linorder_linear)
wenzelm@11750
   577
  apply (blast intro: order_trans)
wenzelm@11750
   578
  done
wenzelm@11750
   579
wenzelm@11750
   580
lemma max_less_iff_conj [simp]:
wenzelm@11750
   581
    "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
wenzelm@11750
   582
  apply (simp add: order_le_less max_def)
wenzelm@11750
   583
  apply (insert linorder_less_linear)
wenzelm@11750
   584
  apply (blast intro: order_less_trans)
wenzelm@11750
   585
  done
wenzelm@11750
   586
wenzelm@11750
   587
lemma le_min_iff_conj [simp]:
wenzelm@11750
   588
    "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
wenzelm@11750
   589
    -- {* @{text "[iff]"} screws up a Q{text blast} in MiniML *}
wenzelm@11750
   590
  apply (simp add: min_def)
wenzelm@11750
   591
  apply (insert linorder_linear)
wenzelm@11750
   592
  apply (blast intro: order_trans)
wenzelm@11750
   593
  done
wenzelm@11750
   594
wenzelm@11750
   595
lemma min_less_iff_conj [simp]:
wenzelm@11750
   596
    "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
wenzelm@11750
   597
  apply (simp add: order_le_less min_def)
wenzelm@11750
   598
  apply (insert linorder_less_linear)
wenzelm@11750
   599
  apply (blast intro: order_less_trans)
wenzelm@11750
   600
  done
wenzelm@11750
   601
wenzelm@11750
   602
lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
wenzelm@11750
   603
  apply (simp add: min_def)
wenzelm@11750
   604
  apply (insert linorder_linear)
wenzelm@11750
   605
  apply (blast intro: order_trans)
wenzelm@11750
   606
  done
wenzelm@11750
   607
wenzelm@11750
   608
lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
wenzelm@11750
   609
  apply (simp add: min_def order_le_less)
wenzelm@11750
   610
  apply (insert linorder_less_linear)
wenzelm@11750
   611
  apply (blast intro: order_less_trans)
wenzelm@11750
   612
  done
wenzelm@11750
   613
wenzelm@11750
   614
lemma split_min:
wenzelm@11750
   615
    "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
wenzelm@11750
   616
  by (simp add: min_def)
wenzelm@11750
   617
wenzelm@11750
   618
lemma split_max:
wenzelm@11750
   619
    "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
wenzelm@11750
   620
  by (simp add: max_def)
wenzelm@11750
   621
wenzelm@11750
   622
wenzelm@11750
   623
subsubsection "Bounded quantifiers"
wenzelm@11750
   624
wenzelm@11750
   625
syntax
wenzelm@11750
   626
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   627
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   628
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   629
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   630
wenzelm@11750
   631
syntax (symbols)
wenzelm@11750
   632
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   633
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   634
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@11750
   635
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@11750
   636
wenzelm@11750
   637
syntax (HOL)
wenzelm@11750
   638
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   639
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   640
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   641
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   642
wenzelm@11750
   643
translations
wenzelm@11750
   644
 "ALL x<y. P"   =>  "ALL x. x < y --> P"
wenzelm@11750
   645
 "EX x<y. P"    =>  "EX x. x < y  & P"
wenzelm@11750
   646
 "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
wenzelm@11750
   647
 "EX x<=y. P"   =>  "EX x. x <= y & P"
wenzelm@11750
   648
clasohm@923
   649
end