src/HOL/HOL.thy
author wenzelm
Wed Jul 24 00:10:52 2002 +0200 (2002-07-24)
changeset 13412 666137b488a4
parent 12937 0c4fd7529467
child 13421 8fcdf4a26468
permissions -rw-r--r--
predicate defs via locales;
clasohm@923
     1
(*  Title:      HOL/HOL.thy
clasohm@923
     2
    ID:         $Id$
wenzelm@11750
     3
    Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
wenzelm@12386
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
wenzelm@11750
     5
*)
clasohm@923
     6
wenzelm@11750
     7
header {* The basis of Higher-Order Logic *}
clasohm@923
     8
wenzelm@7357
     9
theory HOL = CPure
paulson@11451
    10
files ("HOL_lemmas.ML") ("cladata.ML") ("blastdata.ML") ("simpdata.ML"):
clasohm@923
    11
wenzelm@2260
    12
wenzelm@11750
    13
subsection {* Primitive logic *}
wenzelm@11750
    14
wenzelm@11750
    15
subsubsection {* Core syntax *}
wenzelm@2260
    16
wenzelm@12338
    17
classes type < logic
wenzelm@12338
    18
defaultsort type
wenzelm@3947
    19
wenzelm@12338
    20
global
clasohm@923
    21
wenzelm@7357
    22
typedecl bool
clasohm@923
    23
clasohm@923
    24
arities
wenzelm@12338
    25
  bool :: type
wenzelm@12338
    26
  fun :: (type, type) type
clasohm@923
    27
wenzelm@11750
    28
judgment
wenzelm@11750
    29
  Trueprop      :: "bool => prop"                   ("(_)" 5)
clasohm@923
    30
wenzelm@11750
    31
consts
wenzelm@7357
    32
  Not           :: "bool => bool"                   ("~ _" [40] 40)
wenzelm@7357
    33
  True          :: bool
wenzelm@7357
    34
  False         :: bool
wenzelm@7357
    35
  If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
wenzelm@3947
    36
  arbitrary     :: 'a
clasohm@923
    37
wenzelm@11432
    38
  The           :: "('a => bool) => 'a"
wenzelm@7357
    39
  All           :: "('a => bool) => bool"           (binder "ALL " 10)
wenzelm@7357
    40
  Ex            :: "('a => bool) => bool"           (binder "EX " 10)
wenzelm@7357
    41
  Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
wenzelm@7357
    42
  Let           :: "['a, 'a => 'b] => 'b"
clasohm@923
    43
wenzelm@7357
    44
  "="           :: "['a, 'a] => bool"               (infixl 50)
wenzelm@7357
    45
  &             :: "[bool, bool] => bool"           (infixr 35)
wenzelm@7357
    46
  "|"           :: "[bool, bool] => bool"           (infixr 30)
wenzelm@7357
    47
  -->           :: "[bool, bool] => bool"           (infixr 25)
clasohm@923
    48
wenzelm@10432
    49
local
wenzelm@10432
    50
wenzelm@2260
    51
wenzelm@11750
    52
subsubsection {* Additional concrete syntax *}
wenzelm@2260
    53
wenzelm@4868
    54
nonterminals
clasohm@923
    55
  letbinds  letbind
clasohm@923
    56
  case_syn  cases_syn
clasohm@923
    57
clasohm@923
    58
syntax
wenzelm@12650
    59
  "_not_equal"  :: "['a, 'a] => bool"                    (infixl "~=" 50)
wenzelm@11432
    60
  "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
clasohm@923
    61
wenzelm@7357
    62
  "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
wenzelm@7357
    63
  ""            :: "letbind => letbinds"                 ("_")
wenzelm@7357
    64
  "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
wenzelm@7357
    65
  "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
clasohm@923
    66
wenzelm@9060
    67
  "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
wenzelm@9060
    68
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
wenzelm@7357
    69
  ""            :: "case_syn => cases_syn"               ("_")
wenzelm@9060
    70
  "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
clasohm@923
    71
clasohm@923
    72
translations
wenzelm@7238
    73
  "x ~= y"                == "~ (x = y)"
wenzelm@11432
    74
  "THE x. P"              == "The (%x. P)"
clasohm@923
    75
  "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
nipkow@1114
    76
  "let x = a in e"        == "Let a (%x. e)"
clasohm@923
    77
wenzelm@12633
    78
syntax (output)
wenzelm@11687
    79
  "="           :: "['a, 'a] => bool"                    (infix 50)
wenzelm@12650
    80
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "~=" 50)
wenzelm@2260
    81
wenzelm@12114
    82
syntax (xsymbols)
wenzelm@11687
    83
  Not           :: "bool => bool"                        ("\<not> _" [40] 40)
wenzelm@11687
    84
  "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
wenzelm@11687
    85
  "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
wenzelm@12114
    86
  "op -->"      :: "[bool, bool] => bool"                (infixr "\<longrightarrow>" 25)
wenzelm@12650
    87
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@11687
    88
  "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
wenzelm@11687
    89
  "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
wenzelm@11687
    90
  "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
wenzelm@11687
    91
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
wenzelm@9060
    92
(*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \\<orelse> _")*)
wenzelm@2372
    93
wenzelm@12114
    94
syntax (xsymbols output)
wenzelm@12650
    95
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@3820
    96
wenzelm@6340
    97
syntax (HTML output)
wenzelm@11687
    98
  Not           :: "bool => bool"                        ("\<not> _" [40] 40)
wenzelm@6340
    99
wenzelm@7238
   100
syntax (HOL)
wenzelm@7357
   101
  "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
wenzelm@7357
   102
  "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
wenzelm@7357
   103
  "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
wenzelm@7238
   104
wenzelm@7238
   105
wenzelm@11750
   106
subsubsection {* Axioms and basic definitions *}
wenzelm@2260
   107
wenzelm@7357
   108
axioms
wenzelm@7357
   109
  eq_reflection: "(x=y) ==> (x==y)"
clasohm@923
   110
wenzelm@7357
   111
  refl:         "t = (t::'a)"
wenzelm@7357
   112
  subst:        "[| s = t; P(s) |] ==> P(t::'a)"
paulson@6289
   113
wenzelm@7357
   114
  ext:          "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
wenzelm@11750
   115
    -- {* Extensionality is built into the meta-logic, and this rule expresses *}
wenzelm@11750
   116
    -- {* a related property.  It is an eta-expanded version of the traditional *}
wenzelm@11750
   117
    -- {* rule, and similar to the ABS rule of HOL *}
paulson@6289
   118
wenzelm@11432
   119
  the_eq_trivial: "(THE x. x = a) = (a::'a)"
clasohm@923
   120
wenzelm@7357
   121
  impI:         "(P ==> Q) ==> P-->Q"
wenzelm@7357
   122
  mp:           "[| P-->Q;  P |] ==> Q"
clasohm@923
   123
clasohm@923
   124
defs
wenzelm@7357
   125
  True_def:     "True      == ((%x::bool. x) = (%x. x))"
wenzelm@7357
   126
  All_def:      "All(P)    == (P = (%x. True))"
paulson@11451
   127
  Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
wenzelm@7357
   128
  False_def:    "False     == (!P. P)"
wenzelm@7357
   129
  not_def:      "~ P       == P-->False"
wenzelm@7357
   130
  and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
wenzelm@7357
   131
  or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
wenzelm@7357
   132
  Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
clasohm@923
   133
wenzelm@7357
   134
axioms
wenzelm@7357
   135
  iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
wenzelm@7357
   136
  True_or_False:  "(P=True) | (P=False)"
clasohm@923
   137
clasohm@923
   138
defs
wenzelm@7357
   139
  Let_def:      "Let s f == f(s)"
paulson@11451
   140
  if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
wenzelm@5069
   141
paulson@11451
   142
  arbitrary_def:  "False ==> arbitrary == (THE x. False)"
wenzelm@11750
   143
    -- {* @{term arbitrary} is completely unspecified, but is made to appear as a
wenzelm@11750
   144
    definition syntactically *}
clasohm@923
   145
nipkow@3320
   146
wenzelm@11750
   147
subsubsection {* Generic algebraic operations *}
wenzelm@4868
   148
wenzelm@12338
   149
axclass zero < type
wenzelm@12338
   150
axclass one < type
wenzelm@12338
   151
axclass plus < type
wenzelm@12338
   152
axclass minus < type
wenzelm@12338
   153
axclass times < type
wenzelm@12338
   154
axclass inverse < type
wenzelm@11750
   155
wenzelm@11750
   156
global
wenzelm@11750
   157
wenzelm@11750
   158
consts
wenzelm@11750
   159
  "0"           :: "'a::zero"                       ("0")
wenzelm@11750
   160
  "1"           :: "'a::one"                        ("1")
wenzelm@11750
   161
  "+"           :: "['a::plus, 'a]  => 'a"          (infixl 65)
wenzelm@11750
   162
  -             :: "['a::minus, 'a] => 'a"          (infixl 65)
wenzelm@11750
   163
  uminus        :: "['a::minus] => 'a"              ("- _" [81] 80)
wenzelm@11750
   164
  *             :: "['a::times, 'a] => 'a"          (infixl 70)
wenzelm@11750
   165
wenzelm@11750
   166
local
wenzelm@11750
   167
wenzelm@11750
   168
typed_print_translation {*
wenzelm@11750
   169
  let
wenzelm@11750
   170
    fun tr' c = (c, fn show_sorts => fn T => fn ts =>
wenzelm@11750
   171
      if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
wenzelm@11750
   172
      else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);
wenzelm@11750
   173
  in [tr' "0", tr' "1"] end;
wenzelm@11750
   174
*} -- {* show types that are presumably too general *}
wenzelm@11750
   175
wenzelm@11750
   176
wenzelm@11750
   177
consts
wenzelm@11750
   178
  abs           :: "'a::minus => 'a"
wenzelm@11750
   179
  inverse       :: "'a::inverse => 'a"
wenzelm@11750
   180
  divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
wenzelm@11750
   181
wenzelm@11750
   182
syntax (xsymbols)
wenzelm@11750
   183
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
wenzelm@11750
   184
syntax (HTML output)
wenzelm@11750
   185
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
wenzelm@11750
   186
wenzelm@11750
   187
axclass plus_ac0 < plus, zero
wenzelm@11750
   188
  commute: "x + y = y + x"
wenzelm@11750
   189
  assoc:   "(x + y) + z = x + (y + z)"
wenzelm@11750
   190
  zero:    "0 + x = x"
wenzelm@11750
   191
wenzelm@11750
   192
wenzelm@11750
   193
subsection {* Theory and package setup *}
wenzelm@11750
   194
wenzelm@11750
   195
subsubsection {* Basic lemmas *}
wenzelm@4868
   196
nipkow@9736
   197
use "HOL_lemmas.ML"
wenzelm@11687
   198
theorems case_split = case_split_thm [case_names True False]
wenzelm@9869
   199
wenzelm@12386
   200
wenzelm@12386
   201
subsubsection {* Intuitionistic Reasoning *}
wenzelm@12386
   202
wenzelm@12386
   203
lemma impE':
wenzelm@12937
   204
  assumes 1: "P --> Q"
wenzelm@12937
   205
    and 2: "Q ==> R"
wenzelm@12937
   206
    and 3: "P --> Q ==> P"
wenzelm@12937
   207
  shows R
wenzelm@12386
   208
proof -
wenzelm@12386
   209
  from 3 and 1 have P .
wenzelm@12386
   210
  with 1 have Q by (rule impE)
wenzelm@12386
   211
  with 2 show R .
wenzelm@12386
   212
qed
wenzelm@12386
   213
wenzelm@12386
   214
lemma allE':
wenzelm@12937
   215
  assumes 1: "ALL x. P x"
wenzelm@12937
   216
    and 2: "P x ==> ALL x. P x ==> Q"
wenzelm@12937
   217
  shows Q
wenzelm@12386
   218
proof -
wenzelm@12386
   219
  from 1 have "P x" by (rule spec)
wenzelm@12386
   220
  from this and 1 show Q by (rule 2)
wenzelm@12386
   221
qed
wenzelm@12386
   222
wenzelm@12937
   223
lemma notE':
wenzelm@12937
   224
  assumes 1: "~ P"
wenzelm@12937
   225
    and 2: "~ P ==> P"
wenzelm@12937
   226
  shows R
wenzelm@12386
   227
proof -
wenzelm@12386
   228
  from 2 and 1 have P .
wenzelm@12386
   229
  with 1 show R by (rule notE)
wenzelm@12386
   230
qed
wenzelm@12386
   231
wenzelm@12386
   232
lemmas [CPure.elim!] = disjE iffE FalseE conjE exE
wenzelm@12386
   233
  and [CPure.intro!] = iffI conjI impI TrueI notI allI refl
wenzelm@12386
   234
  and [CPure.elim 2] = allE notE' impE'
wenzelm@12386
   235
  and [CPure.intro] = exI disjI2 disjI1
wenzelm@12386
   236
wenzelm@12386
   237
lemmas [trans] = trans
wenzelm@12386
   238
  and [sym] = sym not_sym
wenzelm@12386
   239
  and [CPure.elim?] = iffD1 iffD2 impE
wenzelm@11750
   240
wenzelm@11438
   241
wenzelm@11750
   242
subsubsection {* Atomizing meta-level connectives *}
wenzelm@11750
   243
wenzelm@11750
   244
lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
wenzelm@12003
   245
proof
wenzelm@9488
   246
  assume "!!x. P x"
wenzelm@10383
   247
  show "ALL x. P x" by (rule allI)
wenzelm@9488
   248
next
wenzelm@9488
   249
  assume "ALL x. P x"
wenzelm@10383
   250
  thus "!!x. P x" by (rule allE)
wenzelm@9488
   251
qed
wenzelm@9488
   252
wenzelm@11750
   253
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
wenzelm@12003
   254
proof
wenzelm@9488
   255
  assume r: "A ==> B"
wenzelm@10383
   256
  show "A --> B" by (rule impI) (rule r)
wenzelm@9488
   257
next
wenzelm@9488
   258
  assume "A --> B" and A
wenzelm@10383
   259
  thus B by (rule mp)
wenzelm@9488
   260
qed
wenzelm@9488
   261
wenzelm@11750
   262
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
wenzelm@12003
   263
proof
wenzelm@10432
   264
  assume "x == y"
wenzelm@10432
   265
  show "x = y" by (unfold prems) (rule refl)
wenzelm@10432
   266
next
wenzelm@10432
   267
  assume "x = y"
wenzelm@10432
   268
  thus "x == y" by (rule eq_reflection)
wenzelm@10432
   269
qed
wenzelm@10432
   270
wenzelm@12023
   271
lemma atomize_conj [atomize]:
wenzelm@12023
   272
  "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
wenzelm@12003
   273
proof
wenzelm@11953
   274
  assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
wenzelm@11953
   275
  show "A & B" by (rule conjI)
wenzelm@11953
   276
next
wenzelm@11953
   277
  fix C
wenzelm@11953
   278
  assume "A & B"
wenzelm@11953
   279
  assume "A ==> B ==> PROP C"
wenzelm@11953
   280
  thus "PROP C"
wenzelm@11953
   281
  proof this
wenzelm@11953
   282
    show A by (rule conjunct1)
wenzelm@11953
   283
    show B by (rule conjunct2)
wenzelm@11953
   284
  qed
wenzelm@11953
   285
qed
wenzelm@11953
   286
wenzelm@12386
   287
lemmas [symmetric, rulify] = atomize_all atomize_imp
wenzelm@12386
   288
wenzelm@11750
   289
wenzelm@11750
   290
subsubsection {* Classical Reasoner setup *}
wenzelm@9529
   291
wenzelm@10383
   292
use "cladata.ML"
wenzelm@10383
   293
setup hypsubst_setup
wenzelm@11977
   294
wenzelm@12386
   295
ML_setup {*
wenzelm@12386
   296
  Context.>> (ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac));
wenzelm@12386
   297
*}
wenzelm@11977
   298
wenzelm@10383
   299
setup Classical.setup
wenzelm@10383
   300
setup clasetup
wenzelm@10383
   301
wenzelm@12386
   302
lemmas [intro?] = ext
wenzelm@12386
   303
  and [elim?] = ex1_implies_ex
wenzelm@11977
   304
wenzelm@9869
   305
use "blastdata.ML"
wenzelm@9869
   306
setup Blast.setup
wenzelm@4868
   307
wenzelm@11750
   308
wenzelm@11750
   309
subsubsection {* Simplifier setup *}
wenzelm@11750
   310
wenzelm@12281
   311
lemma meta_eq_to_obj_eq: "x == y ==> x = y"
wenzelm@12281
   312
proof -
wenzelm@12281
   313
  assume r: "x == y"
wenzelm@12281
   314
  show "x = y" by (unfold r) (rule refl)
wenzelm@12281
   315
qed
wenzelm@12281
   316
wenzelm@12281
   317
lemma eta_contract_eq: "(%s. f s) = f" ..
wenzelm@12281
   318
wenzelm@12281
   319
lemma simp_thms:
wenzelm@12937
   320
  shows not_not: "(~ ~ P) = P"
wenzelm@12937
   321
  and
berghofe@12436
   322
    "(P ~= Q) = (P = (~Q))"
berghofe@12436
   323
    "(P | ~P) = True"    "(~P | P) = True"
berghofe@12436
   324
    "((~P) = (~Q)) = (P=Q)"
wenzelm@12281
   325
    "(x = x) = True"
wenzelm@12281
   326
    "(~True) = False"  "(~False) = True"
berghofe@12436
   327
    "(~P) ~= P"  "P ~= (~P)"
wenzelm@12281
   328
    "(True=P) = P"  "(P=True) = P"  "(False=P) = (~P)"  "(P=False) = (~P)"
wenzelm@12281
   329
    "(True --> P) = P"  "(False --> P) = True"
wenzelm@12281
   330
    "(P --> True) = True"  "(P --> P) = True"
wenzelm@12281
   331
    "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
wenzelm@12281
   332
    "(P & True) = P"  "(True & P) = P"
wenzelm@12281
   333
    "(P & False) = False"  "(False & P) = False"
wenzelm@12281
   334
    "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
wenzelm@12281
   335
    "(P & ~P) = False"    "(~P & P) = False"
wenzelm@12281
   336
    "(P | True) = True"  "(True | P) = True"
wenzelm@12281
   337
    "(P | False) = P"  "(False | P) = P"
berghofe@12436
   338
    "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
wenzelm@12281
   339
    "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
wenzelm@12281
   340
    -- {* needed for the one-point-rule quantifier simplification procs *}
wenzelm@12281
   341
    -- {* essential for termination!! *} and
wenzelm@12281
   342
    "!!P. (EX x. x=t & P(x)) = P(t)"
wenzelm@12281
   343
    "!!P. (EX x. t=x & P(x)) = P(t)"
wenzelm@12281
   344
    "!!P. (ALL x. x=t --> P(x)) = P(t)"
wenzelm@12937
   345
    "!!P. (ALL x. t=x --> P(x)) = P(t)"
berghofe@12436
   346
  by (blast, blast, blast, blast, blast, rules+)
berghofe@12436
   347
 
wenzelm@12281
   348
lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
wenzelm@12354
   349
  by rules
wenzelm@12281
   350
wenzelm@12281
   351
lemma ex_simps:
wenzelm@12281
   352
  "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
wenzelm@12281
   353
  "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
wenzelm@12281
   354
  "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
wenzelm@12281
   355
  "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
wenzelm@12281
   356
  "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
wenzelm@12281
   357
  "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
wenzelm@12281
   358
  -- {* Miniscoping: pushing in existential quantifiers. *}
berghofe@12436
   359
  by (rules | blast)+
wenzelm@12281
   360
wenzelm@12281
   361
lemma all_simps:
wenzelm@12281
   362
  "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
wenzelm@12281
   363
  "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
wenzelm@12281
   364
  "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
wenzelm@12281
   365
  "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
wenzelm@12281
   366
  "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
wenzelm@12281
   367
  "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
wenzelm@12281
   368
  -- {* Miniscoping: pushing in universal quantifiers. *}
berghofe@12436
   369
  by (rules | blast)+
wenzelm@12281
   370
wenzelm@12281
   371
lemma eq_ac:
wenzelm@12937
   372
  shows eq_commute: "(a=b) = (b=a)"
wenzelm@12937
   373
    and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
wenzelm@12937
   374
    and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (rules, blast+)
berghofe@12436
   375
lemma neq_commute: "(a~=b) = (b~=a)" by rules
wenzelm@12281
   376
wenzelm@12281
   377
lemma conj_comms:
wenzelm@12937
   378
  shows conj_commute: "(P&Q) = (Q&P)"
wenzelm@12937
   379
    and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by rules+
berghofe@12436
   380
lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by rules
wenzelm@12281
   381
wenzelm@12281
   382
lemma disj_comms:
wenzelm@12937
   383
  shows disj_commute: "(P|Q) = (Q|P)"
wenzelm@12937
   384
    and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by rules+
berghofe@12436
   385
lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by rules
wenzelm@12281
   386
berghofe@12436
   387
lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by rules
berghofe@12436
   388
lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by rules
wenzelm@12281
   389
berghofe@12436
   390
lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by rules
berghofe@12436
   391
lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by rules
wenzelm@12281
   392
berghofe@12436
   393
lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by rules
berghofe@12436
   394
lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by rules
berghofe@12436
   395
lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by rules
wenzelm@12281
   396
wenzelm@12281
   397
text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
wenzelm@12281
   398
lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
wenzelm@12281
   399
lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
wenzelm@12281
   400
wenzelm@12281
   401
lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
wenzelm@12281
   402
lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
wenzelm@12281
   403
berghofe@12436
   404
lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by rules
wenzelm@12281
   405
lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
wenzelm@12281
   406
lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
wenzelm@12281
   407
lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
wenzelm@12281
   408
lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
wenzelm@12281
   409
lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
wenzelm@12281
   410
  by blast
wenzelm@12281
   411
lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
wenzelm@12281
   412
berghofe@12436
   413
lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by rules
wenzelm@12281
   414
wenzelm@12281
   415
wenzelm@12281
   416
lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
wenzelm@12281
   417
  -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
wenzelm@12281
   418
  -- {* cases boil down to the same thing. *}
wenzelm@12281
   419
  by blast
wenzelm@12281
   420
wenzelm@12281
   421
lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
wenzelm@12281
   422
lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
berghofe@12436
   423
lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by rules
berghofe@12436
   424
lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by rules
wenzelm@12281
   425
berghofe@12436
   426
lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by rules
berghofe@12436
   427
lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by rules
wenzelm@12281
   428
wenzelm@12281
   429
text {*
wenzelm@12281
   430
  \medskip The @{text "&"} congruence rule: not included by default!
wenzelm@12281
   431
  May slow rewrite proofs down by as much as 50\% *}
wenzelm@12281
   432
wenzelm@12281
   433
lemma conj_cong:
wenzelm@12281
   434
    "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
wenzelm@12354
   435
  by rules
wenzelm@12281
   436
wenzelm@12281
   437
lemma rev_conj_cong:
wenzelm@12281
   438
    "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
wenzelm@12354
   439
  by rules
wenzelm@12281
   440
wenzelm@12281
   441
text {* The @{text "|"} congruence rule: not included by default! *}
wenzelm@12281
   442
wenzelm@12281
   443
lemma disj_cong:
wenzelm@12281
   444
    "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
wenzelm@12281
   445
  by blast
wenzelm@12281
   446
wenzelm@12281
   447
lemma eq_sym_conv: "(x = y) = (y = x)"
wenzelm@12354
   448
  by rules
wenzelm@12281
   449
wenzelm@12281
   450
wenzelm@12281
   451
text {* \medskip if-then-else rules *}
wenzelm@12281
   452
wenzelm@12281
   453
lemma if_True: "(if True then x else y) = x"
wenzelm@12281
   454
  by (unfold if_def) blast
wenzelm@12281
   455
wenzelm@12281
   456
lemma if_False: "(if False then x else y) = y"
wenzelm@12281
   457
  by (unfold if_def) blast
wenzelm@12281
   458
wenzelm@12281
   459
lemma if_P: "P ==> (if P then x else y) = x"
wenzelm@12281
   460
  by (unfold if_def) blast
wenzelm@12281
   461
wenzelm@12281
   462
lemma if_not_P: "~P ==> (if P then x else y) = y"
wenzelm@12281
   463
  by (unfold if_def) blast
wenzelm@12281
   464
wenzelm@12281
   465
lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
wenzelm@12281
   466
  apply (rule case_split [of Q])
wenzelm@12281
   467
   apply (subst if_P)
wenzelm@12281
   468
    prefer 3 apply (subst if_not_P)
wenzelm@12281
   469
     apply blast+
wenzelm@12281
   470
  done
wenzelm@12281
   471
wenzelm@12281
   472
lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
wenzelm@12281
   473
  apply (subst split_if)
wenzelm@12281
   474
  apply blast
wenzelm@12281
   475
  done
wenzelm@12281
   476
wenzelm@12281
   477
lemmas if_splits = split_if split_if_asm
wenzelm@12281
   478
wenzelm@12281
   479
lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
wenzelm@12281
   480
  by (rule split_if)
wenzelm@12281
   481
wenzelm@12281
   482
lemma if_cancel: "(if c then x else x) = x"
wenzelm@12281
   483
  apply (subst split_if)
wenzelm@12281
   484
  apply blast
wenzelm@12281
   485
  done
wenzelm@12281
   486
wenzelm@12281
   487
lemma if_eq_cancel: "(if x = y then y else x) = x"
wenzelm@12281
   488
  apply (subst split_if)
wenzelm@12281
   489
  apply blast
wenzelm@12281
   490
  done
wenzelm@12281
   491
wenzelm@12281
   492
lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
wenzelm@12281
   493
  -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
wenzelm@12281
   494
  by (rule split_if)
wenzelm@12281
   495
wenzelm@12281
   496
lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
wenzelm@12281
   497
  -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
wenzelm@12281
   498
  apply (subst split_if)
wenzelm@12281
   499
  apply blast
wenzelm@12281
   500
  done
wenzelm@12281
   501
berghofe@12436
   502
lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) rules
berghofe@12436
   503
lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) rules
wenzelm@12281
   504
wenzelm@9869
   505
use "simpdata.ML"
wenzelm@9869
   506
setup Simplifier.setup
wenzelm@9869
   507
setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
wenzelm@9869
   508
setup Splitter.setup setup Clasimp.setup
wenzelm@9869
   509
wenzelm@11750
   510
wenzelm@11824
   511
subsubsection {* Generic cases and induction *}
wenzelm@11824
   512
wenzelm@11824
   513
constdefs
wenzelm@11989
   514
  induct_forall :: "('a => bool) => bool"
wenzelm@11989
   515
  "induct_forall P == \<forall>x. P x"
wenzelm@11989
   516
  induct_implies :: "bool => bool => bool"
wenzelm@11989
   517
  "induct_implies A B == A --> B"
wenzelm@11989
   518
  induct_equal :: "'a => 'a => bool"
wenzelm@11989
   519
  "induct_equal x y == x = y"
wenzelm@11989
   520
  induct_conj :: "bool => bool => bool"
wenzelm@11989
   521
  "induct_conj A B == A & B"
wenzelm@11824
   522
wenzelm@11989
   523
lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
wenzelm@11989
   524
  by (simp only: atomize_all induct_forall_def)
wenzelm@11824
   525
wenzelm@11989
   526
lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
wenzelm@11989
   527
  by (simp only: atomize_imp induct_implies_def)
wenzelm@11824
   528
wenzelm@11989
   529
lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
wenzelm@11989
   530
  by (simp only: atomize_eq induct_equal_def)
wenzelm@11824
   531
wenzelm@11989
   532
lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
wenzelm@11989
   533
    induct_conj (induct_forall A) (induct_forall B)"
wenzelm@12354
   534
  by (unfold induct_forall_def induct_conj_def) rules
wenzelm@11824
   535
wenzelm@11989
   536
lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
wenzelm@11989
   537
    induct_conj (induct_implies C A) (induct_implies C B)"
wenzelm@12354
   538
  by (unfold induct_implies_def induct_conj_def) rules
wenzelm@11989
   539
wenzelm@11989
   540
lemma induct_conj_curry: "(induct_conj A B ==> C) == (A ==> B ==> C)"
wenzelm@12354
   541
  by (simp only: atomize_imp atomize_eq induct_conj_def) (rules intro: equal_intr_rule)
wenzelm@11824
   542
wenzelm@11989
   543
lemma induct_impliesI: "(A ==> B) ==> induct_implies A B"
wenzelm@11989
   544
  by (simp add: induct_implies_def)
wenzelm@11824
   545
wenzelm@12161
   546
lemmas induct_atomize = atomize_conj induct_forall_eq induct_implies_eq induct_equal_eq
wenzelm@12161
   547
lemmas induct_rulify1 [symmetric, standard] = induct_forall_eq induct_implies_eq induct_equal_eq
wenzelm@12161
   548
lemmas induct_rulify2 = induct_forall_def induct_implies_def induct_equal_def induct_conj_def
wenzelm@11989
   549
lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
wenzelm@11824
   550
wenzelm@11989
   551
hide const induct_forall induct_implies induct_equal induct_conj
wenzelm@11824
   552
wenzelm@11824
   553
wenzelm@11824
   554
text {* Method setup. *}
wenzelm@11824
   555
wenzelm@11824
   556
ML {*
wenzelm@11824
   557
  structure InductMethod = InductMethodFun
wenzelm@11824
   558
  (struct
wenzelm@11824
   559
    val dest_concls = HOLogic.dest_concls;
wenzelm@11824
   560
    val cases_default = thm "case_split";
wenzelm@11989
   561
    val local_impI = thm "induct_impliesI";
wenzelm@11824
   562
    val conjI = thm "conjI";
wenzelm@11989
   563
    val atomize = thms "induct_atomize";
wenzelm@11989
   564
    val rulify1 = thms "induct_rulify1";
wenzelm@11989
   565
    val rulify2 = thms "induct_rulify2";
wenzelm@12240
   566
    val localize = [Thm.symmetric (thm "induct_implies_def")];
wenzelm@11824
   567
  end);
wenzelm@11824
   568
*}
wenzelm@11824
   569
wenzelm@11824
   570
setup InductMethod.setup
wenzelm@11824
   571
wenzelm@11824
   572
wenzelm@11750
   573
subsection {* Order signatures and orders *}
wenzelm@11750
   574
wenzelm@11750
   575
axclass
wenzelm@12338
   576
  ord < type
wenzelm@11750
   577
wenzelm@11750
   578
syntax
wenzelm@11750
   579
  "op <"        :: "['a::ord, 'a] => bool"             ("op <")
wenzelm@11750
   580
  "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
wenzelm@11750
   581
wenzelm@11750
   582
global
wenzelm@11750
   583
wenzelm@11750
   584
consts
wenzelm@11750
   585
  "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
wenzelm@11750
   586
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
wenzelm@11750
   587
wenzelm@11750
   588
local
wenzelm@11750
   589
wenzelm@12114
   590
syntax (xsymbols)
wenzelm@11750
   591
  "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
wenzelm@11750
   592
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
wenzelm@11750
   593
wenzelm@11750
   594
(*Tell blast about overloading of < and <= to reduce the risk of
wenzelm@11750
   595
  its applying a rule for the wrong type*)
wenzelm@11750
   596
ML {*
wenzelm@11750
   597
Blast.overloaded ("op <" , domain_type);
wenzelm@11750
   598
Blast.overloaded ("op <=", domain_type);
wenzelm@11750
   599
*}
wenzelm@11750
   600
wenzelm@11750
   601
wenzelm@11750
   602
subsubsection {* Monotonicity *}
wenzelm@11750
   603
wenzelm@13412
   604
locale mono =
wenzelm@13412
   605
  fixes f
wenzelm@13412
   606
  assumes mono: "A <= B ==> f A <= f B"
wenzelm@11750
   607
wenzelm@13412
   608
lemmas monoI [intro?] = mono.intro [OF mono_axioms.intro]
wenzelm@13412
   609
  and monoD [dest?] = mono.mono
wenzelm@11750
   610
wenzelm@13412
   611
lemma mono_def: "mono f == ALL A B. A <= B --> f A <= f B"
wenzelm@13412
   612
  -- compatibility
wenzelm@13412
   613
  by (simp only: atomize_eq mono_def mono_axioms_def)
wenzelm@13412
   614
wenzelm@11750
   615
wenzelm@11750
   616
constdefs
wenzelm@11750
   617
  min :: "['a::ord, 'a] => 'a"
wenzelm@11750
   618
  "min a b == (if a <= b then a else b)"
wenzelm@11750
   619
  max :: "['a::ord, 'a] => 'a"
wenzelm@11750
   620
  "max a b == (if a <= b then b else a)"
wenzelm@11750
   621
wenzelm@11750
   622
lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
wenzelm@11750
   623
  by (simp add: min_def)
wenzelm@11750
   624
wenzelm@11750
   625
lemma min_of_mono:
wenzelm@11750
   626
    "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
wenzelm@11750
   627
  by (simp add: min_def)
wenzelm@11750
   628
wenzelm@11750
   629
lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
wenzelm@11750
   630
  by (simp add: max_def)
wenzelm@11750
   631
wenzelm@11750
   632
lemma max_of_mono:
wenzelm@11750
   633
    "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
wenzelm@11750
   634
  by (simp add: max_def)
wenzelm@11750
   635
wenzelm@11750
   636
wenzelm@11750
   637
subsubsection "Orders"
wenzelm@11750
   638
wenzelm@11750
   639
axclass order < ord
wenzelm@11750
   640
  order_refl [iff]: "x <= x"
wenzelm@11750
   641
  order_trans: "x <= y ==> y <= z ==> x <= z"
wenzelm@11750
   642
  order_antisym: "x <= y ==> y <= x ==> x = y"
wenzelm@11750
   643
  order_less_le: "(x < y) = (x <= y & x ~= y)"
wenzelm@11750
   644
wenzelm@11750
   645
wenzelm@11750
   646
text {* Reflexivity. *}
wenzelm@11750
   647
wenzelm@11750
   648
lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
wenzelm@11750
   649
    -- {* This form is useful with the classical reasoner. *}
wenzelm@11750
   650
  apply (erule ssubst)
wenzelm@11750
   651
  apply (rule order_refl)
wenzelm@11750
   652
  done
wenzelm@11750
   653
wenzelm@11750
   654
lemma order_less_irrefl [simp]: "~ x < (x::'a::order)"
wenzelm@11750
   655
  by (simp add: order_less_le)
wenzelm@11750
   656
wenzelm@11750
   657
lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
wenzelm@11750
   658
    -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
wenzelm@11750
   659
  apply (simp add: order_less_le)
wenzelm@12256
   660
  apply blast
wenzelm@11750
   661
  done
wenzelm@11750
   662
wenzelm@11750
   663
lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
wenzelm@11750
   664
wenzelm@11750
   665
lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
wenzelm@11750
   666
  by (simp add: order_less_le)
wenzelm@11750
   667
wenzelm@11750
   668
wenzelm@11750
   669
text {* Asymmetry. *}
wenzelm@11750
   670
wenzelm@11750
   671
lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
wenzelm@11750
   672
  by (simp add: order_less_le order_antisym)
wenzelm@11750
   673
wenzelm@11750
   674
lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
wenzelm@11750
   675
  apply (drule order_less_not_sym)
wenzelm@11750
   676
  apply (erule contrapos_np)
wenzelm@11750
   677
  apply simp
wenzelm@11750
   678
  done
wenzelm@11750
   679
wenzelm@11750
   680
wenzelm@11750
   681
text {* Transitivity. *}
wenzelm@11750
   682
wenzelm@11750
   683
lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
wenzelm@11750
   684
  apply (simp add: order_less_le)
wenzelm@11750
   685
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   686
  done
wenzelm@11750
   687
wenzelm@11750
   688
lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
wenzelm@11750
   689
  apply (simp add: order_less_le)
wenzelm@11750
   690
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   691
  done
wenzelm@11750
   692
wenzelm@11750
   693
lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
wenzelm@11750
   694
  apply (simp add: order_less_le)
wenzelm@11750
   695
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   696
  done
wenzelm@11750
   697
wenzelm@11750
   698
wenzelm@11750
   699
text {* Useful for simplification, but too risky to include by default. *}
wenzelm@11750
   700
wenzelm@11750
   701
lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
wenzelm@11750
   702
  by (blast elim: order_less_asym)
wenzelm@11750
   703
wenzelm@11750
   704
lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
wenzelm@11750
   705
  by (blast elim: order_less_asym)
wenzelm@11750
   706
wenzelm@11750
   707
lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
wenzelm@11750
   708
  by auto
wenzelm@11750
   709
wenzelm@11750
   710
lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
wenzelm@11750
   711
  by auto
wenzelm@11750
   712
wenzelm@11750
   713
wenzelm@11750
   714
text {* Other operators. *}
wenzelm@11750
   715
wenzelm@11750
   716
lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
wenzelm@11750
   717
  apply (simp add: min_def)
wenzelm@11750
   718
  apply (blast intro: order_antisym)
wenzelm@11750
   719
  done
wenzelm@11750
   720
wenzelm@11750
   721
lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
wenzelm@11750
   722
  apply (simp add: max_def)
wenzelm@11750
   723
  apply (blast intro: order_antisym)
wenzelm@11750
   724
  done
wenzelm@11750
   725
wenzelm@11750
   726
wenzelm@11750
   727
subsubsection {* Least value operator *}
wenzelm@11750
   728
wenzelm@11750
   729
constdefs
wenzelm@11750
   730
  Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
wenzelm@11750
   731
  "Least P == THE x. P x & (ALL y. P y --> x <= y)"
wenzelm@11750
   732
    -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
wenzelm@11750
   733
wenzelm@11750
   734
lemma LeastI2:
wenzelm@11750
   735
  "[| P (x::'a::order);
wenzelm@11750
   736
      !!y. P y ==> x <= y;
wenzelm@11750
   737
      !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
wenzelm@12281
   738
   ==> Q (Least P)"
wenzelm@11750
   739
  apply (unfold Least_def)
wenzelm@11750
   740
  apply (rule theI2)
wenzelm@11750
   741
    apply (blast intro: order_antisym)+
wenzelm@11750
   742
  done
wenzelm@11750
   743
wenzelm@11750
   744
lemma Least_equality:
wenzelm@12281
   745
    "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
wenzelm@11750
   746
  apply (simp add: Least_def)
wenzelm@11750
   747
  apply (rule the_equality)
wenzelm@11750
   748
  apply (auto intro!: order_antisym)
wenzelm@11750
   749
  done
wenzelm@11750
   750
wenzelm@11750
   751
wenzelm@11750
   752
subsubsection "Linear / total orders"
wenzelm@11750
   753
wenzelm@11750
   754
axclass linorder < order
wenzelm@11750
   755
  linorder_linear: "x <= y | y <= x"
wenzelm@11750
   756
wenzelm@11750
   757
lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
wenzelm@11750
   758
  apply (simp add: order_less_le)
wenzelm@11750
   759
  apply (insert linorder_linear)
wenzelm@11750
   760
  apply blast
wenzelm@11750
   761
  done
wenzelm@11750
   762
wenzelm@11750
   763
lemma linorder_cases [case_names less equal greater]:
wenzelm@11750
   764
    "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
wenzelm@11750
   765
  apply (insert linorder_less_linear)
wenzelm@11750
   766
  apply blast
wenzelm@11750
   767
  done
wenzelm@11750
   768
wenzelm@11750
   769
lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
wenzelm@11750
   770
  apply (simp add: order_less_le)
wenzelm@11750
   771
  apply (insert linorder_linear)
wenzelm@11750
   772
  apply (blast intro: order_antisym)
wenzelm@11750
   773
  done
wenzelm@11750
   774
wenzelm@11750
   775
lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
wenzelm@11750
   776
  apply (simp add: order_less_le)
wenzelm@11750
   777
  apply (insert linorder_linear)
wenzelm@11750
   778
  apply (blast intro: order_antisym)
wenzelm@11750
   779
  done
wenzelm@11750
   780
wenzelm@11750
   781
lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
wenzelm@11750
   782
  apply (cut_tac x = x and y = y in linorder_less_linear)
wenzelm@11750
   783
  apply auto
wenzelm@11750
   784
  done
wenzelm@11750
   785
wenzelm@11750
   786
lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
wenzelm@11750
   787
  apply (simp add: linorder_neq_iff)
wenzelm@11750
   788
  apply blast
wenzelm@11750
   789
  done
wenzelm@11750
   790
wenzelm@11750
   791
wenzelm@11750
   792
subsubsection "Min and max on (linear) orders"
wenzelm@11750
   793
wenzelm@11750
   794
lemma min_same [simp]: "min (x::'a::order) x = x"
wenzelm@11750
   795
  by (simp add: min_def)
wenzelm@11750
   796
wenzelm@11750
   797
lemma max_same [simp]: "max (x::'a::order) x = x"
wenzelm@11750
   798
  by (simp add: max_def)
wenzelm@11750
   799
wenzelm@11750
   800
lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
wenzelm@11750
   801
  apply (simp add: max_def)
wenzelm@11750
   802
  apply (insert linorder_linear)
wenzelm@11750
   803
  apply (blast intro: order_trans)
wenzelm@11750
   804
  done
wenzelm@11750
   805
wenzelm@11750
   806
lemma le_maxI1: "(x::'a::linorder) <= max x y"
wenzelm@11750
   807
  by (simp add: le_max_iff_disj)
wenzelm@11750
   808
wenzelm@11750
   809
lemma le_maxI2: "(y::'a::linorder) <= max x y"
wenzelm@11750
   810
    -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
wenzelm@11750
   811
  by (simp add: le_max_iff_disj)
wenzelm@11750
   812
wenzelm@11750
   813
lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
wenzelm@11750
   814
  apply (simp add: max_def order_le_less)
wenzelm@11750
   815
  apply (insert linorder_less_linear)
wenzelm@11750
   816
  apply (blast intro: order_less_trans)
wenzelm@11750
   817
  done
wenzelm@11750
   818
wenzelm@11750
   819
lemma max_le_iff_conj [simp]:
wenzelm@11750
   820
    "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
wenzelm@11750
   821
  apply (simp add: max_def)
wenzelm@11750
   822
  apply (insert linorder_linear)
wenzelm@11750
   823
  apply (blast intro: order_trans)
wenzelm@11750
   824
  done
wenzelm@11750
   825
wenzelm@11750
   826
lemma max_less_iff_conj [simp]:
wenzelm@11750
   827
    "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
wenzelm@11750
   828
  apply (simp add: order_le_less max_def)
wenzelm@11750
   829
  apply (insert linorder_less_linear)
wenzelm@11750
   830
  apply (blast intro: order_less_trans)
wenzelm@11750
   831
  done
wenzelm@11750
   832
wenzelm@11750
   833
lemma le_min_iff_conj [simp]:
wenzelm@11750
   834
    "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
wenzelm@12892
   835
    -- {* @{text "[iff]"} screws up a @{text blast} in MiniML *}
wenzelm@11750
   836
  apply (simp add: min_def)
wenzelm@11750
   837
  apply (insert linorder_linear)
wenzelm@11750
   838
  apply (blast intro: order_trans)
wenzelm@11750
   839
  done
wenzelm@11750
   840
wenzelm@11750
   841
lemma min_less_iff_conj [simp]:
wenzelm@11750
   842
    "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
wenzelm@11750
   843
  apply (simp add: order_le_less min_def)
wenzelm@11750
   844
  apply (insert linorder_less_linear)
wenzelm@11750
   845
  apply (blast intro: order_less_trans)
wenzelm@11750
   846
  done
wenzelm@11750
   847
wenzelm@11750
   848
lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
wenzelm@11750
   849
  apply (simp add: min_def)
wenzelm@11750
   850
  apply (insert linorder_linear)
wenzelm@11750
   851
  apply (blast intro: order_trans)
wenzelm@11750
   852
  done
wenzelm@11750
   853
wenzelm@11750
   854
lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
wenzelm@11750
   855
  apply (simp add: min_def order_le_less)
wenzelm@11750
   856
  apply (insert linorder_less_linear)
wenzelm@11750
   857
  apply (blast intro: order_less_trans)
wenzelm@11750
   858
  done
wenzelm@11750
   859
wenzelm@11750
   860
lemma split_min:
wenzelm@11750
   861
    "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
wenzelm@11750
   862
  by (simp add: min_def)
wenzelm@11750
   863
wenzelm@11750
   864
lemma split_max:
wenzelm@11750
   865
    "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
wenzelm@11750
   866
  by (simp add: max_def)
wenzelm@11750
   867
wenzelm@11750
   868
wenzelm@11750
   869
subsubsection "Bounded quantifiers"
wenzelm@11750
   870
wenzelm@11750
   871
syntax
wenzelm@11750
   872
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   873
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   874
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   875
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   876
wenzelm@12114
   877
syntax (xsymbols)
wenzelm@11750
   878
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   879
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   880
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@11750
   881
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@11750
   882
wenzelm@11750
   883
syntax (HOL)
wenzelm@11750
   884
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   885
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
   886
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   887
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
   888
wenzelm@11750
   889
translations
wenzelm@11750
   890
 "ALL x<y. P"   =>  "ALL x. x < y --> P"
wenzelm@11750
   891
 "EX x<y. P"    =>  "EX x. x < y  & P"
wenzelm@11750
   892
 "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
wenzelm@11750
   893
 "EX x<=y. P"   =>  "EX x. x <= y & P"
wenzelm@11750
   894
clasohm@923
   895
end