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