src/HOL/HOL.thy
author wenzelm
Thu Oct 18 20:59:33 2001 +0200 (2001-10-18)
changeset 11824 f4c1882dde2c
parent 11770 b6bb7a853dd2
child 11953 f98623fdf6ef
permissions -rw-r--r--
setup generic cases and induction (from Inductive.thy);
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@11750
   235
wenzelm@11750
   236
subsubsection {* Classical Reasoner setup *}
wenzelm@9529
   237
wenzelm@10383
   238
use "cladata.ML"
wenzelm@10383
   239
setup hypsubst_setup
wenzelm@11770
   240
declare atomize_all [symmetric, rulify]  atomize_imp [symmetric, rulify]
wenzelm@10383
   241
setup Classical.setup
wenzelm@10383
   242
setup clasetup
wenzelm@10383
   243
wenzelm@9869
   244
use "blastdata.ML"
wenzelm@9869
   245
setup Blast.setup
wenzelm@4868
   246
wenzelm@11750
   247
wenzelm@11750
   248
subsubsection {* Simplifier setup *}
wenzelm@11750
   249
wenzelm@9869
   250
use "simpdata.ML"
wenzelm@9869
   251
setup Simplifier.setup
wenzelm@9869
   252
setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
wenzelm@9869
   253
setup Splitter.setup setup Clasimp.setup
wenzelm@9869
   254
wenzelm@11750
   255
wenzelm@11824
   256
subsubsection {* Generic cases and induction *}
wenzelm@11824
   257
wenzelm@11824
   258
constdefs
wenzelm@11824
   259
  inductive_forall :: "('a => bool) => bool"
wenzelm@11824
   260
  "inductive_forall P == \<forall>x. P x"
wenzelm@11824
   261
  inductive_implies :: "bool => bool => bool"
wenzelm@11824
   262
  "inductive_implies A B == A --> B"
wenzelm@11824
   263
  inductive_equal :: "'a => 'a => bool"
wenzelm@11824
   264
  "inductive_equal x y == x = y"
wenzelm@11824
   265
  inductive_conj :: "bool => bool => bool"
wenzelm@11824
   266
  "inductive_conj A B == A & B"
wenzelm@11824
   267
wenzelm@11824
   268
lemma inductive_forall_eq: "(!!x. P x) == Trueprop (inductive_forall (\<lambda>x. P x))"
wenzelm@11824
   269
  by (simp only: atomize_all inductive_forall_def)
wenzelm@11824
   270
wenzelm@11824
   271
lemma inductive_implies_eq: "(A ==> B) == Trueprop (inductive_implies A B)"
wenzelm@11824
   272
  by (simp only: atomize_imp inductive_implies_def)
wenzelm@11824
   273
wenzelm@11824
   274
lemma inductive_equal_eq: "(x == y) == Trueprop (inductive_equal x y)"
wenzelm@11824
   275
  by (simp only: atomize_eq inductive_equal_def)
wenzelm@11824
   276
wenzelm@11824
   277
lemma inductive_forall_conj: "inductive_forall (\<lambda>x. inductive_conj (A x) (B x)) =
wenzelm@11824
   278
    inductive_conj (inductive_forall A) (inductive_forall B)"
wenzelm@11824
   279
  by (unfold inductive_forall_def inductive_conj_def) blast
wenzelm@11824
   280
wenzelm@11824
   281
lemma inductive_implies_conj: "inductive_implies C (inductive_conj A B) =
wenzelm@11824
   282
    inductive_conj (inductive_implies C A) (inductive_implies C B)"
wenzelm@11824
   283
  by (unfold inductive_implies_def inductive_conj_def) blast
wenzelm@11824
   284
wenzelm@11824
   285
lemma inductive_conj_curry: "(inductive_conj A B ==> C) == (A ==> B ==> C)"
wenzelm@11824
   286
  by (simp only: atomize_imp atomize_eq inductive_conj_def) (rule equal_intr_rule, blast+)
wenzelm@11824
   287
wenzelm@11824
   288
lemmas inductive_atomize = inductive_forall_eq inductive_implies_eq inductive_equal_eq
wenzelm@11824
   289
lemmas inductive_rulify1 = inductive_atomize [symmetric, standard]
wenzelm@11824
   290
lemmas inductive_rulify2 =
wenzelm@11824
   291
  inductive_forall_def inductive_implies_def inductive_equal_def inductive_conj_def
wenzelm@11824
   292
lemmas inductive_conj = inductive_forall_conj inductive_implies_conj inductive_conj_curry
wenzelm@11824
   293
wenzelm@11824
   294
hide const inductive_forall inductive_implies inductive_equal inductive_conj
wenzelm@11824
   295
wenzelm@11824
   296
wenzelm@11824
   297
text {* Method setup. *}
wenzelm@11824
   298
wenzelm@11824
   299
ML {*
wenzelm@11824
   300
  structure InductMethod = InductMethodFun
wenzelm@11824
   301
  (struct
wenzelm@11824
   302
    val dest_concls = HOLogic.dest_concls;
wenzelm@11824
   303
    val cases_default = thm "case_split";
wenzelm@11824
   304
    val conjI = thm "conjI";
wenzelm@11824
   305
    val atomize = thms "inductive_atomize";
wenzelm@11824
   306
    val rulify1 = thms "inductive_rulify1";
wenzelm@11824
   307
    val rulify2 = thms "inductive_rulify2";
wenzelm@11824
   308
  end);
wenzelm@11824
   309
*}
wenzelm@11824
   310
wenzelm@11824
   311
setup InductMethod.setup
wenzelm@11824
   312
wenzelm@11824
   313
wenzelm@11750
   314
subsection {* Order signatures and orders *}
wenzelm@11750
   315
wenzelm@11750
   316
axclass
wenzelm@11750
   317
  ord < "term"
wenzelm@11750
   318
wenzelm@11750
   319
syntax
wenzelm@11750
   320
  "op <"        :: "['a::ord, 'a] => bool"             ("op <")
wenzelm@11750
   321
  "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
wenzelm@11750
   322
wenzelm@11750
   323
global
wenzelm@11750
   324
wenzelm@11750
   325
consts
wenzelm@11750
   326
  "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
wenzelm@11750
   327
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
wenzelm@11750
   328
wenzelm@11750
   329
local
wenzelm@11750
   330
wenzelm@11750
   331
syntax (symbols)
wenzelm@11750
   332
  "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
wenzelm@11750
   333
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
wenzelm@11750
   334
wenzelm@11750
   335
(*Tell blast about overloading of < and <= to reduce the risk of
wenzelm@11750
   336
  its applying a rule for the wrong type*)
wenzelm@11750
   337
ML {*
wenzelm@11750
   338
Blast.overloaded ("op <" , domain_type);
wenzelm@11750
   339
Blast.overloaded ("op <=", domain_type);
wenzelm@11750
   340
*}
wenzelm@11750
   341
wenzelm@11750
   342
wenzelm@11750
   343
subsubsection {* Monotonicity *}
wenzelm@11750
   344
wenzelm@11750
   345
constdefs
wenzelm@11750
   346
  mono :: "['a::ord => 'b::ord] => bool"
wenzelm@11750
   347
  "mono f == ALL A B. A <= B --> f A <= f B"
wenzelm@11750
   348
wenzelm@11750
   349
lemma monoI [intro?]: "(!!A B. A <= B ==> f A <= f B) ==> mono f"
wenzelm@11750
   350
  by (unfold mono_def) blast
wenzelm@11750
   351
wenzelm@11750
   352
lemma monoD [dest?]: "mono f ==> A <= B ==> f A <= f B"
wenzelm@11750
   353
  by (unfold mono_def) blast
wenzelm@11750
   354
wenzelm@11750
   355
constdefs
wenzelm@11750
   356
  min :: "['a::ord, 'a] => 'a"
wenzelm@11750
   357
  "min a b == (if a <= b then a else b)"
wenzelm@11750
   358
  max :: "['a::ord, 'a] => 'a"
wenzelm@11750
   359
  "max a b == (if a <= b then b else a)"
wenzelm@11750
   360
wenzelm@11750
   361
lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
wenzelm@11750
   362
  by (simp add: min_def)
wenzelm@11750
   363
wenzelm@11750
   364
lemma min_of_mono:
wenzelm@11750
   365
    "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
wenzelm@11750
   366
  by (simp add: min_def)
wenzelm@11750
   367
wenzelm@11750
   368
lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
wenzelm@11750
   369
  by (simp add: max_def)
wenzelm@11750
   370
wenzelm@11750
   371
lemma max_of_mono:
wenzelm@11750
   372
    "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
wenzelm@11750
   373
  by (simp add: max_def)
wenzelm@11750
   374
wenzelm@11750
   375
wenzelm@11750
   376
subsubsection "Orders"
wenzelm@11750
   377
wenzelm@11750
   378
axclass order < ord
wenzelm@11750
   379
  order_refl [iff]: "x <= x"
wenzelm@11750
   380
  order_trans: "x <= y ==> y <= z ==> x <= z"
wenzelm@11750
   381
  order_antisym: "x <= y ==> y <= x ==> x = y"
wenzelm@11750
   382
  order_less_le: "(x < y) = (x <= y & x ~= y)"
wenzelm@11750
   383
wenzelm@11750
   384
wenzelm@11750
   385
text {* Reflexivity. *}
wenzelm@11750
   386
wenzelm@11750
   387
lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
wenzelm@11750
   388
    -- {* This form is useful with the classical reasoner. *}
wenzelm@11750
   389
  apply (erule ssubst)
wenzelm@11750
   390
  apply (rule order_refl)
wenzelm@11750
   391
  done
wenzelm@11750
   392
wenzelm@11750
   393
lemma order_less_irrefl [simp]: "~ x < (x::'a::order)"
wenzelm@11750
   394
  by (simp add: order_less_le)
wenzelm@11750
   395
wenzelm@11750
   396
lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
wenzelm@11750
   397
    -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
wenzelm@11750
   398
  apply (simp add: order_less_le)
wenzelm@11750
   399
  apply (blast intro!: order_refl)
wenzelm@11750
   400
  done
wenzelm@11750
   401
wenzelm@11750
   402
lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
wenzelm@11750
   403
wenzelm@11750
   404
lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
wenzelm@11750
   405
  by (simp add: order_less_le)
wenzelm@11750
   406
wenzelm@11750
   407
wenzelm@11750
   408
text {* Asymmetry. *}
wenzelm@11750
   409
wenzelm@11750
   410
lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
wenzelm@11750
   411
  by (simp add: order_less_le order_antisym)
wenzelm@11750
   412
wenzelm@11750
   413
lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
wenzelm@11750
   414
  apply (drule order_less_not_sym)
wenzelm@11750
   415
  apply (erule contrapos_np)
wenzelm@11750
   416
  apply simp
wenzelm@11750
   417
  done
wenzelm@11750
   418
wenzelm@11750
   419
wenzelm@11750
   420
text {* Transitivity. *}
wenzelm@11750
   421
wenzelm@11750
   422
lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
wenzelm@11750
   423
  apply (simp add: order_less_le)
wenzelm@11750
   424
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   425
  done
wenzelm@11750
   426
wenzelm@11750
   427
lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
wenzelm@11750
   428
  apply (simp add: order_less_le)
wenzelm@11750
   429
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   430
  done
wenzelm@11750
   431
wenzelm@11750
   432
lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
wenzelm@11750
   433
  apply (simp add: order_less_le)
wenzelm@11750
   434
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   435
  done
wenzelm@11750
   436
wenzelm@11750
   437
wenzelm@11750
   438
text {* Useful for simplification, but too risky to include by default. *}
wenzelm@11750
   439
wenzelm@11750
   440
lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
wenzelm@11750
   441
  by (blast elim: order_less_asym)
wenzelm@11750
   442
wenzelm@11750
   443
lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
wenzelm@11750
   444
  by (blast elim: order_less_asym)
wenzelm@11750
   445
wenzelm@11750
   446
lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
wenzelm@11750
   447
  by auto
wenzelm@11750
   448
wenzelm@11750
   449
lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
wenzelm@11750
   450
  by auto
wenzelm@11750
   451
wenzelm@11750
   452
wenzelm@11750
   453
text {* Other operators. *}
wenzelm@11750
   454
wenzelm@11750
   455
lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
wenzelm@11750
   456
  apply (simp add: min_def)
wenzelm@11750
   457
  apply (blast intro: order_antisym)
wenzelm@11750
   458
  done
wenzelm@11750
   459
wenzelm@11750
   460
lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
wenzelm@11750
   461
  apply (simp add: max_def)
wenzelm@11750
   462
  apply (blast intro: order_antisym)
wenzelm@11750
   463
  done
wenzelm@11750
   464
wenzelm@11750
   465
wenzelm@11750
   466
subsubsection {* Least value operator *}
wenzelm@11750
   467
wenzelm@11750
   468
constdefs
wenzelm@11750
   469
  Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
wenzelm@11750
   470
  "Least P == THE x. P x & (ALL y. P y --> x <= y)"
wenzelm@11750
   471
    -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
wenzelm@11750
   472
wenzelm@11750
   473
lemma LeastI2:
wenzelm@11750
   474
  "[| P (x::'a::order);
wenzelm@11750
   475
      !!y. P y ==> x <= y;
wenzelm@11750
   476
      !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
wenzelm@11750
   477
   ==> Q (Least P)";
wenzelm@11750
   478
  apply (unfold Least_def)
wenzelm@11750
   479
  apply (rule theI2)
wenzelm@11750
   480
    apply (blast intro: order_antisym)+
wenzelm@11750
   481
  done
wenzelm@11750
   482
wenzelm@11750
   483
lemma Least_equality:
wenzelm@11750
   484
    "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k";
wenzelm@11750
   485
  apply (simp add: Least_def)
wenzelm@11750
   486
  apply (rule the_equality)
wenzelm@11750
   487
  apply (auto intro!: order_antisym)
wenzelm@11750
   488
  done
wenzelm@11750
   489
wenzelm@11750
   490
wenzelm@11750
   491
subsubsection "Linear / total orders"
wenzelm@11750
   492
wenzelm@11750
   493
axclass linorder < order
wenzelm@11750
   494
  linorder_linear: "x <= y | y <= x"
wenzelm@11750
   495
wenzelm@11750
   496
lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
wenzelm@11750
   497
  apply (simp add: order_less_le)
wenzelm@11750
   498
  apply (insert linorder_linear)
wenzelm@11750
   499
  apply blast
wenzelm@11750
   500
  done
wenzelm@11750
   501
wenzelm@11750
   502
lemma linorder_cases [case_names less equal greater]:
wenzelm@11750
   503
    "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
wenzelm@11750
   504
  apply (insert linorder_less_linear)
wenzelm@11750
   505
  apply blast
wenzelm@11750
   506
  done
wenzelm@11750
   507
wenzelm@11750
   508
lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
wenzelm@11750
   509
  apply (simp add: order_less_le)
wenzelm@11750
   510
  apply (insert linorder_linear)
wenzelm@11750
   511
  apply (blast intro: order_antisym)
wenzelm@11750
   512
  done
wenzelm@11750
   513
wenzelm@11750
   514
lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
wenzelm@11750
   515
  apply (simp add: order_less_le)
wenzelm@11750
   516
  apply (insert linorder_linear)
wenzelm@11750
   517
  apply (blast intro: order_antisym)
wenzelm@11750
   518
  done
wenzelm@11750
   519
wenzelm@11750
   520
lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
wenzelm@11750
   521
  apply (cut_tac x = x and y = y in linorder_less_linear)
wenzelm@11750
   522
  apply auto
wenzelm@11750
   523
  done
wenzelm@11750
   524
wenzelm@11750
   525
lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
wenzelm@11750
   526
  apply (simp add: linorder_neq_iff)
wenzelm@11750
   527
  apply blast
wenzelm@11750
   528
  done
wenzelm@11750
   529
wenzelm@11750
   530
wenzelm@11750
   531
subsubsection "Min and max on (linear) orders"
wenzelm@11750
   532
wenzelm@11750
   533
lemma min_same [simp]: "min (x::'a::order) x = x"
wenzelm@11750
   534
  by (simp add: min_def)
wenzelm@11750
   535
wenzelm@11750
   536
lemma max_same [simp]: "max (x::'a::order) x = x"
wenzelm@11750
   537
  by (simp add: max_def)
wenzelm@11750
   538
wenzelm@11750
   539
lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
wenzelm@11750
   540
  apply (simp add: max_def)
wenzelm@11750
   541
  apply (insert linorder_linear)
wenzelm@11750
   542
  apply (blast intro: order_trans)
wenzelm@11750
   543
  done
wenzelm@11750
   544
wenzelm@11750
   545
lemma le_maxI1: "(x::'a::linorder) <= max x y"
wenzelm@11750
   546
  by (simp add: le_max_iff_disj)
wenzelm@11750
   547
wenzelm@11750
   548
lemma le_maxI2: "(y::'a::linorder) <= max x y"
wenzelm@11750
   549
    -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
wenzelm@11750
   550
  by (simp add: le_max_iff_disj)
wenzelm@11750
   551
wenzelm@11750
   552
lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
wenzelm@11750
   553
  apply (simp add: max_def order_le_less)
wenzelm@11750
   554
  apply (insert linorder_less_linear)
wenzelm@11750
   555
  apply (blast intro: order_less_trans)
wenzelm@11750
   556
  done
wenzelm@11750
   557
wenzelm@11750
   558
lemma max_le_iff_conj [simp]:
wenzelm@11750
   559
    "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
wenzelm@11750
   560
  apply (simp add: max_def)
wenzelm@11750
   561
  apply (insert linorder_linear)
wenzelm@11750
   562
  apply (blast intro: order_trans)
wenzelm@11750
   563
  done
wenzelm@11750
   564
wenzelm@11750
   565
lemma max_less_iff_conj [simp]:
wenzelm@11750
   566
    "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
wenzelm@11750
   567
  apply (simp add: order_le_less max_def)
wenzelm@11750
   568
  apply (insert linorder_less_linear)
wenzelm@11750
   569
  apply (blast intro: order_less_trans)
wenzelm@11750
   570
  done
wenzelm@11750
   571
wenzelm@11750
   572
lemma le_min_iff_conj [simp]:
wenzelm@11750
   573
    "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
wenzelm@11750
   574
    -- {* @{text "[iff]"} screws up a Q{text blast} in MiniML *}
wenzelm@11750
   575
  apply (simp add: min_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 min_less_iff_conj [simp]:
wenzelm@11750
   581
    "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
wenzelm@11750
   582
  apply (simp add: order_le_less min_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 min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
wenzelm@11750
   588
  apply (simp add: min_def)
wenzelm@11750
   589
  apply (insert linorder_linear)
wenzelm@11750
   590
  apply (blast intro: order_trans)
wenzelm@11750
   591
  done
wenzelm@11750
   592
wenzelm@11750
   593
lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
wenzelm@11750
   594
  apply (simp add: min_def order_le_less)
wenzelm@11750
   595
  apply (insert linorder_less_linear)
wenzelm@11750
   596
  apply (blast intro: order_less_trans)
wenzelm@11750
   597
  done
wenzelm@11750
   598
wenzelm@11750
   599
lemma split_min:
wenzelm@11750
   600
    "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
wenzelm@11750
   601
  by (simp add: min_def)
wenzelm@11750
   602
wenzelm@11750
   603
lemma split_max:
wenzelm@11750
   604
    "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
wenzelm@11750
   605
  by (simp add: max_def)
wenzelm@11750
   606
wenzelm@11750
   607
wenzelm@11750
   608
subsubsection "Bounded quantifiers"
wenzelm@11750
   609
wenzelm@11750
   610
syntax
wenzelm@11750
   611
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   612
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   613
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   614
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   615
wenzelm@11750
   616
syntax (symbols)
wenzelm@11750
   617
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   618
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   619
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@11750
   620
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@11750
   621
wenzelm@11750
   622
syntax (HOL)
wenzelm@11750
   623
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   624
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   625
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   626
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   627
wenzelm@11750
   628
translations
wenzelm@11750
   629
 "ALL x<y. P"   =>  "ALL x. x < y --> P"
wenzelm@11750
   630
 "EX x<y. P"    =>  "EX x. x < y  & P"
wenzelm@11750
   631
 "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
wenzelm@11750
   632
 "EX x<=y. P"   =>  "EX x. x <= y & P"
wenzelm@11750
   633
clasohm@923
   634
end