src/HOL/HOL.thy
author haftmann
Thu May 17 19:49:16 2007 +0200 (2007-05-17)
changeset 22993 838c66e760b5
parent 22839 ede26eb5e549
child 23037 6c72943a71b1
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
nipkow@15131
     8
theory HOL
nipkow@15140
     9
imports CPure
haftmann@21151
    10
uses ("simpdata.ML") "Tools/res_atpset.ML"
nipkow@15131
    11
begin
wenzelm@2260
    12
wenzelm@11750
    13
subsection {* Primitive logic *}
wenzelm@11750
    14
wenzelm@11750
    15
subsubsection {* Core syntax *}
wenzelm@2260
    16
wenzelm@14854
    17
classes type
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
haftmann@20590
    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@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
haftmann@22839
    43
  "op ="        :: "['a, 'a] => bool"               (infixl "=" 50)
haftmann@22839
    44
  "op &"        :: "[bool, bool] => bool"           (infixr "&" 35)
haftmann@22839
    45
  "op |"        :: "[bool, bool] => bool"           (infixr "|" 30)
haftmann@22839
    46
  "op -->"      :: "[bool, bool] => bool"           (infixr "-->" 25)
clasohm@923
    47
wenzelm@10432
    48
local
wenzelm@10432
    49
paulson@16587
    50
consts
paulson@16587
    51
  If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
wenzelm@2260
    52
wenzelm@19656
    53
wenzelm@11750
    54
subsubsection {* Additional concrete syntax *}
wenzelm@2260
    55
wenzelm@21210
    56
notation (output)
wenzelm@19656
    57
  "op ="  (infix "=" 50)
wenzelm@19656
    58
wenzelm@19656
    59
abbreviation
wenzelm@21404
    60
  not_equal :: "['a, 'a] => bool"  (infixl "~=" 50) where
wenzelm@19656
    61
  "x ~= y == ~ (x = y)"
wenzelm@19656
    62
wenzelm@21210
    63
notation (output)
wenzelm@19656
    64
  not_equal  (infix "~=" 50)
wenzelm@19656
    65
wenzelm@21210
    66
notation (xsymbols)
wenzelm@21404
    67
  Not  ("\<not> _" [40] 40) and
wenzelm@21404
    68
  "op &"  (infixr "\<and>" 35) and
wenzelm@21404
    69
  "op |"  (infixr "\<or>" 30) and
wenzelm@21404
    70
  "op -->"  (infixr "\<longrightarrow>" 25) and
wenzelm@19656
    71
  not_equal  (infix "\<noteq>" 50)
wenzelm@19656
    72
wenzelm@21210
    73
notation (HTML output)
wenzelm@21404
    74
  Not  ("\<not> _" [40] 40) and
wenzelm@21404
    75
  "op &"  (infixr "\<and>" 35) and
wenzelm@21404
    76
  "op |"  (infixr "\<or>" 30) and
wenzelm@19656
    77
  not_equal  (infix "\<noteq>" 50)
wenzelm@19656
    78
wenzelm@19656
    79
abbreviation (iff)
wenzelm@21404
    80
  iff :: "[bool, bool] => bool"  (infixr "<->" 25) where
wenzelm@19656
    81
  "A <-> B == A = B"
wenzelm@19656
    82
wenzelm@21210
    83
notation (xsymbols)
wenzelm@19656
    84
  iff  (infixr "\<longleftrightarrow>" 25)
wenzelm@19656
    85
wenzelm@19656
    86
wenzelm@4868
    87
nonterminals
clasohm@923
    88
  letbinds  letbind
clasohm@923
    89
  case_syn  cases_syn
clasohm@923
    90
clasohm@923
    91
syntax
wenzelm@11432
    92
  "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
clasohm@923
    93
wenzelm@7357
    94
  "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
wenzelm@7357
    95
  ""            :: "letbind => letbinds"                 ("_")
wenzelm@7357
    96
  "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
wenzelm@7357
    97
  "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
clasohm@923
    98
wenzelm@9060
    99
  "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
wenzelm@9060
   100
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
wenzelm@7357
   101
  ""            :: "case_syn => cases_syn"               ("_")
wenzelm@9060
   102
  "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
clasohm@923
   103
clasohm@923
   104
translations
nipkow@13764
   105
  "THE x. P"              == "The (%x. P)"
clasohm@923
   106
  "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
nipkow@1114
   107
  "let x = a in e"        == "Let a (%x. e)"
clasohm@923
   108
nipkow@13763
   109
print_translation {*
nipkow@13763
   110
(* To avoid eta-contraction of body: *)
nipkow@13763
   111
[("The", fn [Abs abs] =>
nipkow@13763
   112
     let val (x,t) = atomic_abs_tr' abs
nipkow@13763
   113
     in Syntax.const "_The" $ x $ t end)]
nipkow@13763
   114
*}
nipkow@13763
   115
wenzelm@12114
   116
syntax (xsymbols)
wenzelm@11687
   117
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
wenzelm@21524
   118
wenzelm@21524
   119
notation (xsymbols)
wenzelm@21524
   120
  All  (binder "\<forall>" 10) and
wenzelm@21524
   121
  Ex  (binder "\<exists>" 10) and
wenzelm@21524
   122
  Ex1  (binder "\<exists>!" 10)
wenzelm@2372
   123
wenzelm@21524
   124
notation (HTML output)
wenzelm@21524
   125
  All  (binder "\<forall>" 10) and
wenzelm@21524
   126
  Ex  (binder "\<exists>" 10) and
wenzelm@21524
   127
  Ex1  (binder "\<exists>!" 10)
wenzelm@6340
   128
wenzelm@21524
   129
notation (HOL)
wenzelm@21524
   130
  All  (binder "! " 10) and
wenzelm@21524
   131
  Ex  (binder "? " 10) and
wenzelm@21524
   132
  Ex1  (binder "?! " 10)
wenzelm@7238
   133
wenzelm@7238
   134
wenzelm@11750
   135
subsubsection {* Axioms and basic definitions *}
wenzelm@2260
   136
wenzelm@7357
   137
axioms
paulson@15380
   138
  eq_reflection:  "(x=y) ==> (x==y)"
clasohm@923
   139
paulson@15380
   140
  refl:           "t = (t::'a)"
paulson@6289
   141
paulson@15380
   142
  ext:            "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
paulson@15380
   143
    -- {*Extensionality is built into the meta-logic, and this rule expresses
paulson@15380
   144
         a related property.  It is an eta-expanded version of the traditional
paulson@15380
   145
         rule, and similar to the ABS rule of HOL*}
paulson@6289
   146
wenzelm@11432
   147
  the_eq_trivial: "(THE x. x = a) = (a::'a)"
clasohm@923
   148
paulson@15380
   149
  impI:           "(P ==> Q) ==> P-->Q"
paulson@15380
   150
  mp:             "[| P-->Q;  P |] ==> Q"
paulson@15380
   151
paulson@15380
   152
clasohm@923
   153
defs
wenzelm@7357
   154
  True_def:     "True      == ((%x::bool. x) = (%x. x))"
wenzelm@7357
   155
  All_def:      "All(P)    == (P = (%x. True))"
paulson@11451
   156
  Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
wenzelm@7357
   157
  False_def:    "False     == (!P. P)"
wenzelm@7357
   158
  not_def:      "~ P       == P-->False"
wenzelm@7357
   159
  and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
wenzelm@7357
   160
  or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
wenzelm@7357
   161
  Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
clasohm@923
   162
wenzelm@7357
   163
axioms
wenzelm@7357
   164
  iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
wenzelm@7357
   165
  True_or_False:  "(P=True) | (P=False)"
clasohm@923
   166
clasohm@923
   167
defs
haftmann@22744
   168
  Let_def [code func]: "Let s f == f(s)"
paulson@11451
   169
  if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
wenzelm@5069
   170
skalberg@14223
   171
finalconsts
skalberg@14223
   172
  "op ="
skalberg@14223
   173
  "op -->"
skalberg@14223
   174
  The
skalberg@14223
   175
  arbitrary
haftmann@22481
   176
haftmann@22481
   177
axiomatization
haftmann@22481
   178
  undefined :: 'a
haftmann@22481
   179
haftmann@22744
   180
axiomatization where
haftmann@22481
   181
  undefined_fun: "undefined x = undefined"
nipkow@3320
   182
wenzelm@19656
   183
haftmann@22481
   184
subsubsection {* Generic classes and algebraic operations *}
haftmann@22481
   185
haftmann@22481
   186
class default = type +
haftmann@22481
   187
  fixes default :: "'a"
wenzelm@4868
   188
haftmann@22473
   189
class zero = type + 
wenzelm@21524
   190
  fixes zero :: "'a"  ("\<^loc>0")
haftmann@20713
   191
haftmann@22473
   192
class one = type +
wenzelm@21524
   193
  fixes one  :: "'a"  ("\<^loc>1")
haftmann@20713
   194
haftmann@20713
   195
hide (open) const zero one
haftmann@20590
   196
haftmann@22473
   197
class plus = type +
wenzelm@21524
   198
  fixes plus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "\<^loc>+" 65)
wenzelm@11750
   199
haftmann@22473
   200
class minus = type +
haftmann@20590
   201
  fixes uminus :: "'a \<Rightarrow> 'a" 
wenzelm@21524
   202
    and minus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "\<^loc>-" 65)
wenzelm@21524
   203
    and abs :: "'a \<Rightarrow> 'a"
haftmann@20590
   204
haftmann@22473
   205
class times = type +
haftmann@20713
   206
  fixes times :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "\<^loc>*" 70)
haftmann@20590
   207
haftmann@22473
   208
class inverse = type +
haftmann@20590
   209
  fixes inverse :: "'a \<Rightarrow> 'a"
wenzelm@21524
   210
    and divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "\<^loc>'/" 70)
wenzelm@21524
   211
wenzelm@21524
   212
notation
wenzelm@21524
   213
  uminus  ("- _" [81] 80)
wenzelm@21524
   214
wenzelm@21524
   215
notation (xsymbols)
wenzelm@21524
   216
  abs  ("\<bar>_\<bar>")
wenzelm@21524
   217
notation (HTML output)
wenzelm@21524
   218
  abs  ("\<bar>_\<bar>")
wenzelm@11750
   219
wenzelm@13456
   220
syntax
wenzelm@13456
   221
  "_index1"  :: index    ("\<^sub>1")
wenzelm@13456
   222
translations
wenzelm@14690
   223
  (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
wenzelm@13456
   224
wenzelm@11750
   225
typed_print_translation {*
haftmann@20713
   226
let
haftmann@20713
   227
  fun tr' c = (c, fn show_sorts => fn T => fn ts =>
haftmann@20713
   228
    if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
haftmann@20713
   229
    else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);
haftmann@22993
   230
in map tr' [@{const_syntax HOL.one}, @{const_syntax HOL.zero}] end;
wenzelm@11750
   231
*} -- {* show types that are presumably too general *}
wenzelm@11750
   232
wenzelm@11750
   233
haftmann@20944
   234
subsection {* Fundamental rules *}
haftmann@20944
   235
haftmann@20973
   236
subsubsection {* Equality *}
haftmann@20944
   237
haftmann@20944
   238
text {* Thanks to Stephan Merz *}
haftmann@20944
   239
lemma subst:
haftmann@20944
   240
  assumes eq: "s = t" and p: "P s"
haftmann@20944
   241
  shows "P t"
haftmann@20944
   242
proof -
haftmann@20944
   243
  from eq have meta: "s \<equiv> t"
haftmann@20944
   244
    by (rule eq_reflection)
haftmann@20944
   245
  from p show ?thesis
haftmann@20944
   246
    by (unfold meta)
haftmann@20944
   247
qed
paulson@15411
   248
wenzelm@18457
   249
lemma sym: "s = t ==> t = s"
wenzelm@18457
   250
  by (erule subst) (rule refl)
paulson@15411
   251
wenzelm@18457
   252
lemma ssubst: "t = s ==> P s ==> P t"
wenzelm@18457
   253
  by (drule sym) (erule subst)
paulson@15411
   254
paulson@15411
   255
lemma trans: "[| r=s; s=t |] ==> r=t"
wenzelm@18457
   256
  by (erule subst)
paulson@15411
   257
haftmann@20944
   258
lemma meta_eq_to_obj_eq: 
haftmann@20944
   259
  assumes meq: "A == B"
haftmann@20944
   260
  shows "A = B"
haftmann@20944
   261
  by (unfold meq) (rule refl)
paulson@15411
   262
wenzelm@21502
   263
text {* Useful with @{text erule} for proving equalities from known equalities. *}
haftmann@20944
   264
     (* a = b
paulson@15411
   265
        |   |
paulson@15411
   266
        c = d   *)
paulson@15411
   267
lemma box_equals: "[| a=b;  a=c;  b=d |] ==> c=d"
paulson@15411
   268
apply (rule trans)
paulson@15411
   269
apply (rule trans)
paulson@15411
   270
apply (rule sym)
paulson@15411
   271
apply assumption+
paulson@15411
   272
done
paulson@15411
   273
nipkow@15524
   274
text {* For calculational reasoning: *}
nipkow@15524
   275
nipkow@15524
   276
lemma forw_subst: "a = b ==> P b ==> P a"
nipkow@15524
   277
  by (rule ssubst)
nipkow@15524
   278
nipkow@15524
   279
lemma back_subst: "P a ==> a = b ==> P b"
nipkow@15524
   280
  by (rule subst)
nipkow@15524
   281
paulson@15411
   282
haftmann@20944
   283
subsubsection {*Congruence rules for application*}
paulson@15411
   284
paulson@15411
   285
(*similar to AP_THM in Gordon's HOL*)
paulson@15411
   286
lemma fun_cong: "(f::'a=>'b) = g ==> f(x)=g(x)"
paulson@15411
   287
apply (erule subst)
paulson@15411
   288
apply (rule refl)
paulson@15411
   289
done
paulson@15411
   290
paulson@15411
   291
(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)
paulson@15411
   292
lemma arg_cong: "x=y ==> f(x)=f(y)"
paulson@15411
   293
apply (erule subst)
paulson@15411
   294
apply (rule refl)
paulson@15411
   295
done
paulson@15411
   296
paulson@15655
   297
lemma arg_cong2: "\<lbrakk> a = b; c = d \<rbrakk> \<Longrightarrow> f a c = f b d"
paulson@15655
   298
apply (erule ssubst)+
paulson@15655
   299
apply (rule refl)
paulson@15655
   300
done
paulson@15655
   301
paulson@15411
   302
lemma cong: "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"
paulson@15411
   303
apply (erule subst)+
paulson@15411
   304
apply (rule refl)
paulson@15411
   305
done
paulson@15411
   306
paulson@15411
   307
haftmann@20944
   308
subsubsection {*Equality of booleans -- iff*}
paulson@15411
   309
wenzelm@21504
   310
lemma iffI: assumes "P ==> Q" and "Q ==> P" shows "P=Q"
wenzelm@21504
   311
  by (iprover intro: iff [THEN mp, THEN mp] impI assms)
paulson@15411
   312
paulson@15411
   313
lemma iffD2: "[| P=Q; Q |] ==> P"
wenzelm@18457
   314
  by (erule ssubst)
paulson@15411
   315
paulson@15411
   316
lemma rev_iffD2: "[| Q; P=Q |] ==> P"
wenzelm@18457
   317
  by (erule iffD2)
paulson@15411
   318
wenzelm@21504
   319
lemma iffD1: "Q = P \<Longrightarrow> Q \<Longrightarrow> P"
wenzelm@21504
   320
  by (drule sym) (rule iffD2)
wenzelm@21504
   321
wenzelm@21504
   322
lemma rev_iffD1: "Q \<Longrightarrow> Q = P \<Longrightarrow> P"
wenzelm@21504
   323
  by (drule sym) (rule rev_iffD2)
paulson@15411
   324
paulson@15411
   325
lemma iffE:
paulson@15411
   326
  assumes major: "P=Q"
wenzelm@21504
   327
    and minor: "[| P --> Q; Q --> P |] ==> R"
wenzelm@18457
   328
  shows R
wenzelm@18457
   329
  by (iprover intro: minor impI major [THEN iffD2] major [THEN iffD1])
paulson@15411
   330
paulson@15411
   331
haftmann@20944
   332
subsubsection {*True*}
paulson@15411
   333
paulson@15411
   334
lemma TrueI: "True"
wenzelm@21504
   335
  unfolding True_def by (rule refl)
paulson@15411
   336
wenzelm@21504
   337
lemma eqTrueI: "P ==> P = True"
wenzelm@18457
   338
  by (iprover intro: iffI TrueI)
paulson@15411
   339
wenzelm@21504
   340
lemma eqTrueE: "P = True ==> P"
wenzelm@21504
   341
  by (erule iffD2) (rule TrueI)
paulson@15411
   342
paulson@15411
   343
haftmann@20944
   344
subsubsection {*Universal quantifier*}
paulson@15411
   345
wenzelm@21504
   346
lemma allI: assumes "!!x::'a. P(x)" shows "ALL x. P(x)"
wenzelm@21504
   347
  unfolding All_def by (iprover intro: ext eqTrueI assms)
paulson@15411
   348
paulson@15411
   349
lemma spec: "ALL x::'a. P(x) ==> P(x)"
paulson@15411
   350
apply (unfold All_def)
paulson@15411
   351
apply (rule eqTrueE)
paulson@15411
   352
apply (erule fun_cong)
paulson@15411
   353
done
paulson@15411
   354
paulson@15411
   355
lemma allE:
paulson@15411
   356
  assumes major: "ALL x. P(x)"
wenzelm@21504
   357
    and minor: "P(x) ==> R"
wenzelm@21504
   358
  shows R
wenzelm@21504
   359
  by (iprover intro: minor major [THEN spec])
paulson@15411
   360
paulson@15411
   361
lemma all_dupE:
paulson@15411
   362
  assumes major: "ALL x. P(x)"
wenzelm@21504
   363
    and minor: "[| P(x); ALL x. P(x) |] ==> R"
wenzelm@21504
   364
  shows R
wenzelm@21504
   365
  by (iprover intro: minor major major [THEN spec])
paulson@15411
   366
paulson@15411
   367
wenzelm@21504
   368
subsubsection {* False *}
wenzelm@21504
   369
wenzelm@21504
   370
text {*
wenzelm@21504
   371
  Depends upon @{text spec}; it is impossible to do propositional
wenzelm@21504
   372
  logic before quantifiers!
wenzelm@21504
   373
*}
paulson@15411
   374
paulson@15411
   375
lemma FalseE: "False ==> P"
wenzelm@21504
   376
  apply (unfold False_def)
wenzelm@21504
   377
  apply (erule spec)
wenzelm@21504
   378
  done
paulson@15411
   379
wenzelm@21504
   380
lemma False_neq_True: "False = True ==> P"
wenzelm@21504
   381
  by (erule eqTrueE [THEN FalseE])
paulson@15411
   382
paulson@15411
   383
wenzelm@21504
   384
subsubsection {* Negation *}
paulson@15411
   385
paulson@15411
   386
lemma notI:
wenzelm@21504
   387
  assumes "P ==> False"
paulson@15411
   388
  shows "~P"
wenzelm@21504
   389
  apply (unfold not_def)
wenzelm@21504
   390
  apply (iprover intro: impI assms)
wenzelm@21504
   391
  done
paulson@15411
   392
paulson@15411
   393
lemma False_not_True: "False ~= True"
wenzelm@21504
   394
  apply (rule notI)
wenzelm@21504
   395
  apply (erule False_neq_True)
wenzelm@21504
   396
  done
paulson@15411
   397
paulson@15411
   398
lemma True_not_False: "True ~= False"
wenzelm@21504
   399
  apply (rule notI)
wenzelm@21504
   400
  apply (drule sym)
wenzelm@21504
   401
  apply (erule False_neq_True)
wenzelm@21504
   402
  done
paulson@15411
   403
paulson@15411
   404
lemma notE: "[| ~P;  P |] ==> R"
wenzelm@21504
   405
  apply (unfold not_def)
wenzelm@21504
   406
  apply (erule mp [THEN FalseE])
wenzelm@21504
   407
  apply assumption
wenzelm@21504
   408
  done
paulson@15411
   409
wenzelm@21504
   410
lemma notI2: "(P \<Longrightarrow> \<not> Pa) \<Longrightarrow> (P \<Longrightarrow> Pa) \<Longrightarrow> \<not> P"
wenzelm@21504
   411
  by (erule notE [THEN notI]) (erule meta_mp)
paulson@15411
   412
paulson@15411
   413
haftmann@20944
   414
subsubsection {*Implication*}
paulson@15411
   415
paulson@15411
   416
lemma impE:
paulson@15411
   417
  assumes "P-->Q" "P" "Q ==> R"
paulson@15411
   418
  shows "R"
nipkow@17589
   419
by (iprover intro: prems mp)
paulson@15411
   420
paulson@15411
   421
(* Reduces Q to P-->Q, allowing substitution in P. *)
paulson@15411
   422
lemma rev_mp: "[| P;  P --> Q |] ==> Q"
nipkow@17589
   423
by (iprover intro: mp)
paulson@15411
   424
paulson@15411
   425
lemma contrapos_nn:
paulson@15411
   426
  assumes major: "~Q"
paulson@15411
   427
      and minor: "P==>Q"
paulson@15411
   428
  shows "~P"
nipkow@17589
   429
by (iprover intro: notI minor major [THEN notE])
paulson@15411
   430
paulson@15411
   431
(*not used at all, but we already have the other 3 combinations *)
paulson@15411
   432
lemma contrapos_pn:
paulson@15411
   433
  assumes major: "Q"
paulson@15411
   434
      and minor: "P ==> ~Q"
paulson@15411
   435
  shows "~P"
nipkow@17589
   436
by (iprover intro: notI minor major notE)
paulson@15411
   437
paulson@15411
   438
lemma not_sym: "t ~= s ==> s ~= t"
haftmann@21250
   439
  by (erule contrapos_nn) (erule sym)
haftmann@21250
   440
haftmann@21250
   441
lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y"
haftmann@21250
   442
  by (erule subst, erule ssubst, assumption)
paulson@15411
   443
paulson@15411
   444
(*still used in HOLCF*)
paulson@15411
   445
lemma rev_contrapos:
paulson@15411
   446
  assumes pq: "P ==> Q"
paulson@15411
   447
      and nq: "~Q"
paulson@15411
   448
  shows "~P"
paulson@15411
   449
apply (rule nq [THEN contrapos_nn])
paulson@15411
   450
apply (erule pq)
paulson@15411
   451
done
paulson@15411
   452
haftmann@20944
   453
subsubsection {*Existential quantifier*}
paulson@15411
   454
paulson@15411
   455
lemma exI: "P x ==> EX x::'a. P x"
paulson@15411
   456
apply (unfold Ex_def)
nipkow@17589
   457
apply (iprover intro: allI allE impI mp)
paulson@15411
   458
done
paulson@15411
   459
paulson@15411
   460
lemma exE:
paulson@15411
   461
  assumes major: "EX x::'a. P(x)"
paulson@15411
   462
      and minor: "!!x. P(x) ==> Q"
paulson@15411
   463
  shows "Q"
paulson@15411
   464
apply (rule major [unfolded Ex_def, THEN spec, THEN mp])
nipkow@17589
   465
apply (iprover intro: impI [THEN allI] minor)
paulson@15411
   466
done
paulson@15411
   467
paulson@15411
   468
haftmann@20944
   469
subsubsection {*Conjunction*}
paulson@15411
   470
paulson@15411
   471
lemma conjI: "[| P; Q |] ==> P&Q"
paulson@15411
   472
apply (unfold and_def)
nipkow@17589
   473
apply (iprover intro: impI [THEN allI] mp)
paulson@15411
   474
done
paulson@15411
   475
paulson@15411
   476
lemma conjunct1: "[| P & Q |] ==> P"
paulson@15411
   477
apply (unfold and_def)
nipkow@17589
   478
apply (iprover intro: impI dest: spec mp)
paulson@15411
   479
done
paulson@15411
   480
paulson@15411
   481
lemma conjunct2: "[| P & Q |] ==> Q"
paulson@15411
   482
apply (unfold and_def)
nipkow@17589
   483
apply (iprover intro: impI dest: spec mp)
paulson@15411
   484
done
paulson@15411
   485
paulson@15411
   486
lemma conjE:
paulson@15411
   487
  assumes major: "P&Q"
paulson@15411
   488
      and minor: "[| P; Q |] ==> R"
paulson@15411
   489
  shows "R"
paulson@15411
   490
apply (rule minor)
paulson@15411
   491
apply (rule major [THEN conjunct1])
paulson@15411
   492
apply (rule major [THEN conjunct2])
paulson@15411
   493
done
paulson@15411
   494
paulson@15411
   495
lemma context_conjI:
paulson@15411
   496
  assumes prems: "P" "P ==> Q" shows "P & Q"
nipkow@17589
   497
by (iprover intro: conjI prems)
paulson@15411
   498
paulson@15411
   499
haftmann@20944
   500
subsubsection {*Disjunction*}
paulson@15411
   501
paulson@15411
   502
lemma disjI1: "P ==> P|Q"
paulson@15411
   503
apply (unfold or_def)
nipkow@17589
   504
apply (iprover intro: allI impI mp)
paulson@15411
   505
done
paulson@15411
   506
paulson@15411
   507
lemma disjI2: "Q ==> P|Q"
paulson@15411
   508
apply (unfold or_def)
nipkow@17589
   509
apply (iprover intro: allI impI mp)
paulson@15411
   510
done
paulson@15411
   511
paulson@15411
   512
lemma disjE:
paulson@15411
   513
  assumes major: "P|Q"
paulson@15411
   514
      and minorP: "P ==> R"
paulson@15411
   515
      and minorQ: "Q ==> R"
paulson@15411
   516
  shows "R"
nipkow@17589
   517
by (iprover intro: minorP minorQ impI
paulson@15411
   518
                 major [unfolded or_def, THEN spec, THEN mp, THEN mp])
paulson@15411
   519
paulson@15411
   520
haftmann@20944
   521
subsubsection {*Classical logic*}
paulson@15411
   522
paulson@15411
   523
lemma classical:
paulson@15411
   524
  assumes prem: "~P ==> P"
paulson@15411
   525
  shows "P"
paulson@15411
   526
apply (rule True_or_False [THEN disjE, THEN eqTrueE])
paulson@15411
   527
apply assumption
paulson@15411
   528
apply (rule notI [THEN prem, THEN eqTrueI])
paulson@15411
   529
apply (erule subst)
paulson@15411
   530
apply assumption
paulson@15411
   531
done
paulson@15411
   532
paulson@15411
   533
lemmas ccontr = FalseE [THEN classical, standard]
paulson@15411
   534
paulson@15411
   535
(*notE with premises exchanged; it discharges ~R so that it can be used to
paulson@15411
   536
  make elimination rules*)
paulson@15411
   537
lemma rev_notE:
paulson@15411
   538
  assumes premp: "P"
paulson@15411
   539
      and premnot: "~R ==> ~P"
paulson@15411
   540
  shows "R"
paulson@15411
   541
apply (rule ccontr)
paulson@15411
   542
apply (erule notE [OF premnot premp])
paulson@15411
   543
done
paulson@15411
   544
paulson@15411
   545
(*Double negation law*)
paulson@15411
   546
lemma notnotD: "~~P ==> P"
paulson@15411
   547
apply (rule classical)
paulson@15411
   548
apply (erule notE)
paulson@15411
   549
apply assumption
paulson@15411
   550
done
paulson@15411
   551
paulson@15411
   552
lemma contrapos_pp:
paulson@15411
   553
  assumes p1: "Q"
paulson@15411
   554
      and p2: "~P ==> ~Q"
paulson@15411
   555
  shows "P"
nipkow@17589
   556
by (iprover intro: classical p1 p2 notE)
paulson@15411
   557
paulson@15411
   558
haftmann@20944
   559
subsubsection {*Unique existence*}
paulson@15411
   560
paulson@15411
   561
lemma ex1I:
paulson@15411
   562
  assumes prems: "P a" "!!x. P(x) ==> x=a"
paulson@15411
   563
  shows "EX! x. P(x)"
nipkow@17589
   564
by (unfold Ex1_def, iprover intro: prems exI conjI allI impI)
paulson@15411
   565
paulson@15411
   566
text{*Sometimes easier to use: the premises have no shared variables.  Safe!*}
paulson@15411
   567
lemma ex_ex1I:
paulson@15411
   568
  assumes ex_prem: "EX x. P(x)"
paulson@15411
   569
      and eq: "!!x y. [| P(x); P(y) |] ==> x=y"
paulson@15411
   570
  shows "EX! x. P(x)"
nipkow@17589
   571
by (iprover intro: ex_prem [THEN exE] ex1I eq)
paulson@15411
   572
paulson@15411
   573
lemma ex1E:
paulson@15411
   574
  assumes major: "EX! x. P(x)"
paulson@15411
   575
      and minor: "!!x. [| P(x);  ALL y. P(y) --> y=x |] ==> R"
paulson@15411
   576
  shows "R"
paulson@15411
   577
apply (rule major [unfolded Ex1_def, THEN exE])
paulson@15411
   578
apply (erule conjE)
nipkow@17589
   579
apply (iprover intro: minor)
paulson@15411
   580
done
paulson@15411
   581
paulson@15411
   582
lemma ex1_implies_ex: "EX! x. P x ==> EX x. P x"
paulson@15411
   583
apply (erule ex1E)
paulson@15411
   584
apply (rule exI)
paulson@15411
   585
apply assumption
paulson@15411
   586
done
paulson@15411
   587
paulson@15411
   588
haftmann@20944
   589
subsubsection {*THE: definite description operator*}
paulson@15411
   590
paulson@15411
   591
lemma the_equality:
paulson@15411
   592
  assumes prema: "P a"
paulson@15411
   593
      and premx: "!!x. P x ==> x=a"
paulson@15411
   594
  shows "(THE x. P x) = a"
paulson@15411
   595
apply (rule trans [OF _ the_eq_trivial])
paulson@15411
   596
apply (rule_tac f = "The" in arg_cong)
paulson@15411
   597
apply (rule ext)
paulson@15411
   598
apply (rule iffI)
paulson@15411
   599
 apply (erule premx)
paulson@15411
   600
apply (erule ssubst, rule prema)
paulson@15411
   601
done
paulson@15411
   602
paulson@15411
   603
lemma theI:
paulson@15411
   604
  assumes "P a" and "!!x. P x ==> x=a"
paulson@15411
   605
  shows "P (THE x. P x)"
nipkow@17589
   606
by (iprover intro: prems the_equality [THEN ssubst])
paulson@15411
   607
paulson@15411
   608
lemma theI': "EX! x. P x ==> P (THE x. P x)"
paulson@15411
   609
apply (erule ex1E)
paulson@15411
   610
apply (erule theI)
paulson@15411
   611
apply (erule allE)
paulson@15411
   612
apply (erule mp)
paulson@15411
   613
apply assumption
paulson@15411
   614
done
paulson@15411
   615
paulson@15411
   616
(*Easier to apply than theI: only one occurrence of P*)
paulson@15411
   617
lemma theI2:
paulson@15411
   618
  assumes "P a" "!!x. P x ==> x=a" "!!x. P x ==> Q x"
paulson@15411
   619
  shows "Q (THE x. P x)"
nipkow@17589
   620
by (iprover intro: prems theI)
paulson@15411
   621
wenzelm@18697
   622
lemma the1_equality [elim?]: "[| EX!x. P x; P a |] ==> (THE x. P x) = a"
paulson@15411
   623
apply (rule the_equality)
paulson@15411
   624
apply  assumption
paulson@15411
   625
apply (erule ex1E)
paulson@15411
   626
apply (erule all_dupE)
paulson@15411
   627
apply (drule mp)
paulson@15411
   628
apply  assumption
paulson@15411
   629
apply (erule ssubst)
paulson@15411
   630
apply (erule allE)
paulson@15411
   631
apply (erule mp)
paulson@15411
   632
apply assumption
paulson@15411
   633
done
paulson@15411
   634
paulson@15411
   635
lemma the_sym_eq_trivial: "(THE y. x=y) = x"
paulson@15411
   636
apply (rule the_equality)
paulson@15411
   637
apply (rule refl)
paulson@15411
   638
apply (erule sym)
paulson@15411
   639
done
paulson@15411
   640
paulson@15411
   641
haftmann@20944
   642
subsubsection {*Classical intro rules for disjunction and existential quantifiers*}
paulson@15411
   643
paulson@15411
   644
lemma disjCI:
paulson@15411
   645
  assumes "~Q ==> P" shows "P|Q"
paulson@15411
   646
apply (rule classical)
nipkow@17589
   647
apply (iprover intro: prems disjI1 disjI2 notI elim: notE)
paulson@15411
   648
done
paulson@15411
   649
paulson@15411
   650
lemma excluded_middle: "~P | P"
nipkow@17589
   651
by (iprover intro: disjCI)
paulson@15411
   652
haftmann@20944
   653
text {*
haftmann@20944
   654
  case distinction as a natural deduction rule.
haftmann@20944
   655
  Note that @{term "~P"} is the second case, not the first
haftmann@20944
   656
*}
paulson@15411
   657
lemma case_split_thm:
paulson@15411
   658
  assumes prem1: "P ==> Q"
paulson@15411
   659
      and prem2: "~P ==> Q"
paulson@15411
   660
  shows "Q"
paulson@15411
   661
apply (rule excluded_middle [THEN disjE])
paulson@15411
   662
apply (erule prem2)
paulson@15411
   663
apply (erule prem1)
paulson@15411
   664
done
haftmann@20944
   665
lemmas case_split = case_split_thm [case_names True False]
paulson@15411
   666
paulson@15411
   667
(*Classical implies (-->) elimination. *)
paulson@15411
   668
lemma impCE:
paulson@15411
   669
  assumes major: "P-->Q"
paulson@15411
   670
      and minor: "~P ==> R" "Q ==> R"
paulson@15411
   671
  shows "R"
paulson@15411
   672
apply (rule excluded_middle [of P, THEN disjE])
nipkow@17589
   673
apply (iprover intro: minor major [THEN mp])+
paulson@15411
   674
done
paulson@15411
   675
paulson@15411
   676
(*This version of --> elimination works on Q before P.  It works best for
paulson@15411
   677
  those cases in which P holds "almost everywhere".  Can't install as
paulson@15411
   678
  default: would break old proofs.*)
paulson@15411
   679
lemma impCE':
paulson@15411
   680
  assumes major: "P-->Q"
paulson@15411
   681
      and minor: "Q ==> R" "~P ==> R"
paulson@15411
   682
  shows "R"
paulson@15411
   683
apply (rule excluded_middle [of P, THEN disjE])
nipkow@17589
   684
apply (iprover intro: minor major [THEN mp])+
paulson@15411
   685
done
paulson@15411
   686
paulson@15411
   687
(*Classical <-> elimination. *)
paulson@15411
   688
lemma iffCE:
paulson@15411
   689
  assumes major: "P=Q"
paulson@15411
   690
      and minor: "[| P; Q |] ==> R"  "[| ~P; ~Q |] ==> R"
paulson@15411
   691
  shows "R"
paulson@15411
   692
apply (rule major [THEN iffE])
nipkow@17589
   693
apply (iprover intro: minor elim: impCE notE)
paulson@15411
   694
done
paulson@15411
   695
paulson@15411
   696
lemma exCI:
paulson@15411
   697
  assumes "ALL x. ~P(x) ==> P(a)"
paulson@15411
   698
  shows "EX x. P(x)"
paulson@15411
   699
apply (rule ccontr)
nipkow@17589
   700
apply (iprover intro: prems exI allI notI notE [of "\<exists>x. P x"])
paulson@15411
   701
done
paulson@15411
   702
paulson@15411
   703
wenzelm@12386
   704
subsubsection {* Intuitionistic Reasoning *}
wenzelm@12386
   705
wenzelm@12386
   706
lemma impE':
wenzelm@12937
   707
  assumes 1: "P --> Q"
wenzelm@12937
   708
    and 2: "Q ==> R"
wenzelm@12937
   709
    and 3: "P --> Q ==> P"
wenzelm@12937
   710
  shows R
wenzelm@12386
   711
proof -
wenzelm@12386
   712
  from 3 and 1 have P .
wenzelm@12386
   713
  with 1 have Q by (rule impE)
wenzelm@12386
   714
  with 2 show R .
wenzelm@12386
   715
qed
wenzelm@12386
   716
wenzelm@12386
   717
lemma allE':
wenzelm@12937
   718
  assumes 1: "ALL x. P x"
wenzelm@12937
   719
    and 2: "P x ==> ALL x. P x ==> Q"
wenzelm@12937
   720
  shows Q
wenzelm@12386
   721
proof -
wenzelm@12386
   722
  from 1 have "P x" by (rule spec)
wenzelm@12386
   723
  from this and 1 show Q by (rule 2)
wenzelm@12386
   724
qed
wenzelm@12386
   725
wenzelm@12937
   726
lemma notE':
wenzelm@12937
   727
  assumes 1: "~ P"
wenzelm@12937
   728
    and 2: "~ P ==> P"
wenzelm@12937
   729
  shows R
wenzelm@12386
   730
proof -
wenzelm@12386
   731
  from 2 and 1 have P .
wenzelm@12386
   732
  with 1 show R by (rule notE)
wenzelm@12386
   733
qed
wenzelm@12386
   734
dixon@22444
   735
lemma TrueE: "True ==> P ==> P" .
dixon@22444
   736
lemma notFalseE: "~ False ==> P ==> P" .
dixon@22444
   737
dixon@22467
   738
lemmas [Pure.elim!] = disjE iffE FalseE conjE exE TrueE notFalseE
wenzelm@15801
   739
  and [Pure.intro!] = iffI conjI impI TrueI notI allI refl
wenzelm@15801
   740
  and [Pure.elim 2] = allE notE' impE'
wenzelm@15801
   741
  and [Pure.intro] = exI disjI2 disjI1
wenzelm@12386
   742
wenzelm@12386
   743
lemmas [trans] = trans
wenzelm@12386
   744
  and [sym] = sym not_sym
wenzelm@15801
   745
  and [Pure.elim?] = iffD1 iffD2 impE
wenzelm@11750
   746
wenzelm@11438
   747
wenzelm@11750
   748
subsubsection {* Atomizing meta-level connectives *}
wenzelm@11750
   749
wenzelm@11750
   750
lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
wenzelm@12003
   751
proof
wenzelm@9488
   752
  assume "!!x. P x"
wenzelm@10383
   753
  show "ALL x. P x" by (rule allI)
wenzelm@9488
   754
next
wenzelm@9488
   755
  assume "ALL x. P x"
wenzelm@10383
   756
  thus "!!x. P x" by (rule allE)
wenzelm@9488
   757
qed
wenzelm@9488
   758
wenzelm@11750
   759
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
wenzelm@12003
   760
proof
wenzelm@9488
   761
  assume r: "A ==> B"
wenzelm@10383
   762
  show "A --> B" by (rule impI) (rule r)
wenzelm@9488
   763
next
wenzelm@9488
   764
  assume "A --> B" and A
wenzelm@10383
   765
  thus B by (rule mp)
wenzelm@9488
   766
qed
wenzelm@9488
   767
paulson@14749
   768
lemma atomize_not: "(A ==> False) == Trueprop (~A)"
paulson@14749
   769
proof
paulson@14749
   770
  assume r: "A ==> False"
paulson@14749
   771
  show "~A" by (rule notI) (rule r)
paulson@14749
   772
next
paulson@14749
   773
  assume "~A" and A
paulson@14749
   774
  thus False by (rule notE)
paulson@14749
   775
qed
paulson@14749
   776
wenzelm@11750
   777
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
wenzelm@12003
   778
proof
wenzelm@10432
   779
  assume "x == y"
wenzelm@10432
   780
  show "x = y" by (unfold prems) (rule refl)
wenzelm@10432
   781
next
wenzelm@10432
   782
  assume "x = y"
wenzelm@10432
   783
  thus "x == y" by (rule eq_reflection)
wenzelm@10432
   784
qed
wenzelm@10432
   785
wenzelm@12023
   786
lemma atomize_conj [atomize]:
wenzelm@19121
   787
  includes meta_conjunction_syntax
wenzelm@19121
   788
  shows "(A && B) == Trueprop (A & B)"
wenzelm@12003
   789
proof
wenzelm@19121
   790
  assume conj: "A && B"
wenzelm@19121
   791
  show "A & B"
wenzelm@19121
   792
  proof (rule conjI)
wenzelm@19121
   793
    from conj show A by (rule conjunctionD1)
wenzelm@19121
   794
    from conj show B by (rule conjunctionD2)
wenzelm@19121
   795
  qed
wenzelm@11953
   796
next
wenzelm@19121
   797
  assume conj: "A & B"
wenzelm@19121
   798
  show "A && B"
wenzelm@19121
   799
  proof -
wenzelm@19121
   800
    from conj show A ..
wenzelm@19121
   801
    from conj show B ..
wenzelm@11953
   802
  qed
wenzelm@11953
   803
qed
wenzelm@11953
   804
wenzelm@12386
   805
lemmas [symmetric, rulify] = atomize_all atomize_imp
wenzelm@18832
   806
  and [symmetric, defn] = atomize_all atomize_imp atomize_eq
wenzelm@12386
   807
wenzelm@11750
   808
haftmann@20944
   809
subsection {* Package setup *}
haftmann@20944
   810
wenzelm@11750
   811
subsubsection {* Classical Reasoner setup *}
wenzelm@9529
   812
haftmann@20944
   813
lemma thin_refl:
haftmann@20944
   814
  "\<And>X. \<lbrakk> x=x; PROP W \<rbrakk> \<Longrightarrow> PROP W" .
haftmann@20944
   815
haftmann@21151
   816
ML {*
haftmann@21151
   817
structure Hypsubst = HypsubstFun(
haftmann@21151
   818
struct
haftmann@21151
   819
  structure Simplifier = Simplifier
wenzelm@21218
   820
  val dest_eq = HOLogic.dest_eq
haftmann@21151
   821
  val dest_Trueprop = HOLogic.dest_Trueprop
haftmann@21151
   822
  val dest_imp = HOLogic.dest_imp
wenzelm@22129
   823
  val eq_reflection = @{thm HOL.eq_reflection}
haftmann@22218
   824
  val rev_eq_reflection = @{thm HOL.meta_eq_to_obj_eq}
wenzelm@22129
   825
  val imp_intr = @{thm HOL.impI}
wenzelm@22129
   826
  val rev_mp = @{thm HOL.rev_mp}
wenzelm@22129
   827
  val subst = @{thm HOL.subst}
wenzelm@22129
   828
  val sym = @{thm HOL.sym}
wenzelm@22129
   829
  val thin_refl = @{thm thin_refl};
haftmann@21151
   830
end);
wenzelm@21671
   831
open Hypsubst;
haftmann@21151
   832
haftmann@21151
   833
structure Classical = ClassicalFun(
haftmann@21151
   834
struct
wenzelm@22129
   835
  val mp = @{thm HOL.mp}
wenzelm@22129
   836
  val not_elim = @{thm HOL.notE}
wenzelm@22129
   837
  val classical = @{thm HOL.classical}
haftmann@21151
   838
  val sizef = Drule.size_of_thm
haftmann@21151
   839
  val hyp_subst_tacs = [Hypsubst.hyp_subst_tac]
haftmann@21151
   840
end);
haftmann@21151
   841
haftmann@21151
   842
structure BasicClassical: BASIC_CLASSICAL = Classical; 
wenzelm@21671
   843
open BasicClassical;
wenzelm@22129
   844
wenzelm@22129
   845
ML_Context.value_antiq "claset"
wenzelm@22129
   846
  (Scan.succeed ("claset", "Classical.local_claset_of (ML_Context.the_local_context ())"));
haftmann@21151
   847
*}
haftmann@21151
   848
haftmann@21009
   849
setup {*
haftmann@21009
   850
let
haftmann@21009
   851
  (*prevent substitution on bool*)
haftmann@21009
   852
  fun hyp_subst_tac' i thm = if i <= Thm.nprems_of thm andalso
haftmann@21009
   853
    Term.exists_Const (fn ("op =", Type (_, [T, _])) => T <> Type ("bool", []) | _ => false)
haftmann@21009
   854
      (nth (Thm.prems_of thm) (i - 1)) then Hypsubst.hyp_subst_tac i thm else no_tac thm;
haftmann@21009
   855
in
haftmann@21151
   856
  Hypsubst.hypsubst_setup
haftmann@21151
   857
  #> ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac)
haftmann@21151
   858
  #> Classical.setup
haftmann@21151
   859
  #> ResAtpset.setup
haftmann@21009
   860
end
haftmann@21009
   861
*}
haftmann@21009
   862
haftmann@21009
   863
declare iffI [intro!]
haftmann@21009
   864
  and notI [intro!]
haftmann@21009
   865
  and impI [intro!]
haftmann@21009
   866
  and disjCI [intro!]
haftmann@21009
   867
  and conjI [intro!]
haftmann@21009
   868
  and TrueI [intro!]
haftmann@21009
   869
  and refl [intro!]
haftmann@21009
   870
haftmann@21009
   871
declare iffCE [elim!]
haftmann@21009
   872
  and FalseE [elim!]
haftmann@21009
   873
  and impCE [elim!]
haftmann@21009
   874
  and disjE [elim!]
haftmann@21009
   875
  and conjE [elim!]
haftmann@21009
   876
  and conjE [elim!]
haftmann@21009
   877
haftmann@21009
   878
declare ex_ex1I [intro!]
haftmann@21009
   879
  and allI [intro!]
haftmann@21009
   880
  and the_equality [intro]
haftmann@21009
   881
  and exI [intro]
haftmann@21009
   882
haftmann@21009
   883
declare exE [elim!]
haftmann@21009
   884
  allE [elim]
haftmann@21009
   885
wenzelm@22377
   886
ML {* val HOL_cs = @{claset} *}
mengj@19162
   887
wenzelm@20223
   888
lemma contrapos_np: "~ Q ==> (~ P ==> Q) ==> P"
wenzelm@20223
   889
  apply (erule swap)
wenzelm@20223
   890
  apply (erule (1) meta_mp)
wenzelm@20223
   891
  done
wenzelm@10383
   892
wenzelm@18689
   893
declare ex_ex1I [rule del, intro! 2]
wenzelm@18689
   894
  and ex1I [intro]
wenzelm@18689
   895
wenzelm@12386
   896
lemmas [intro?] = ext
wenzelm@12386
   897
  and [elim?] = ex1_implies_ex
wenzelm@11977
   898
haftmann@20944
   899
(*Better then ex1E for classical reasoner: needs no quantifier duplication!*)
haftmann@20973
   900
lemma alt_ex1E [elim!]:
haftmann@20944
   901
  assumes major: "\<exists>!x. P x"
haftmann@20944
   902
      and prem: "\<And>x. \<lbrakk> P x; \<forall>y y'. P y \<and> P y' \<longrightarrow> y = y' \<rbrakk> \<Longrightarrow> R"
haftmann@20944
   903
  shows R
haftmann@20944
   904
apply (rule ex1E [OF major])
haftmann@20944
   905
apply (rule prem)
wenzelm@22129
   906
apply (tactic {* ares_tac @{thms allI} 1 *})+
wenzelm@22129
   907
apply (tactic {* etac (Classical.dup_elim @{thm allE}) 1 *})
wenzelm@22129
   908
apply iprover
wenzelm@22129
   909
done
haftmann@20944
   910
haftmann@21151
   911
ML {*
haftmann@21151
   912
structure Blast = BlastFun(
haftmann@21151
   913
struct
haftmann@21151
   914
  type claset = Classical.claset
haftmann@22744
   915
  val equality_name = @{const_name "op ="}
haftmann@22993
   916
  val not_name = @{const_name Not}
wenzelm@22129
   917
  val notE = @{thm HOL.notE}
wenzelm@22129
   918
  val ccontr = @{thm HOL.ccontr}
haftmann@21151
   919
  val contr_tac = Classical.contr_tac
haftmann@21151
   920
  val dup_intr = Classical.dup_intr
haftmann@21151
   921
  val hyp_subst_tac = Hypsubst.blast_hyp_subst_tac
wenzelm@21671
   922
  val claset = Classical.claset
haftmann@21151
   923
  val rep_cs = Classical.rep_cs
haftmann@21151
   924
  val cla_modifiers = Classical.cla_modifiers
haftmann@21151
   925
  val cla_meth' = Classical.cla_meth'
haftmann@21151
   926
end);
wenzelm@21671
   927
val Blast_tac = Blast.Blast_tac;
wenzelm@21671
   928
val blast_tac = Blast.blast_tac;
haftmann@20944
   929
*}
haftmann@20944
   930
haftmann@21151
   931
setup Blast.setup
haftmann@21151
   932
haftmann@20944
   933
haftmann@20944
   934
subsubsection {* Simplifier *}
wenzelm@12281
   935
wenzelm@12281
   936
lemma eta_contract_eq: "(%s. f s) = f" ..
wenzelm@12281
   937
wenzelm@12281
   938
lemma simp_thms:
wenzelm@12937
   939
  shows not_not: "(~ ~ P) = P"
nipkow@15354
   940
  and Not_eq_iff: "((~P) = (~Q)) = (P = Q)"
wenzelm@12937
   941
  and
berghofe@12436
   942
    "(P ~= Q) = (P = (~Q))"
berghofe@12436
   943
    "(P | ~P) = True"    "(~P | P) = True"
wenzelm@12281
   944
    "(x = x) = True"
haftmann@20944
   945
  and not_True_eq_False: "(\<not> True) = False"
haftmann@20944
   946
  and not_False_eq_True: "(\<not> False) = True"
haftmann@20944
   947
  and
berghofe@12436
   948
    "(~P) ~= P"  "P ~= (~P)"
haftmann@20944
   949
    "(True=P) = P"
haftmann@20944
   950
  and eq_True: "(P = True) = P"
haftmann@20944
   951
  and "(False=P) = (~P)"
haftmann@20944
   952
  and eq_False: "(P = False) = (\<not> P)"
haftmann@20944
   953
  and
wenzelm@12281
   954
    "(True --> P) = P"  "(False --> P) = True"
wenzelm@12281
   955
    "(P --> True) = True"  "(P --> P) = True"
wenzelm@12281
   956
    "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
wenzelm@12281
   957
    "(P & True) = P"  "(True & P) = P"
wenzelm@12281
   958
    "(P & False) = False"  "(False & P) = False"
wenzelm@12281
   959
    "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
wenzelm@12281
   960
    "(P & ~P) = False"    "(~P & P) = False"
wenzelm@12281
   961
    "(P | True) = True"  "(True | P) = True"
wenzelm@12281
   962
    "(P | False) = P"  "(False | P) = P"
berghofe@12436
   963
    "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
wenzelm@12281
   964
    "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
wenzelm@12281
   965
    -- {* needed for the one-point-rule quantifier simplification procs *}
wenzelm@12281
   966
    -- {* essential for termination!! *} and
wenzelm@12281
   967
    "!!P. (EX x. x=t & P(x)) = P(t)"
wenzelm@12281
   968
    "!!P. (EX x. t=x & P(x)) = P(t)"
wenzelm@12281
   969
    "!!P. (ALL x. x=t --> P(x)) = P(t)"
wenzelm@12937
   970
    "!!P. (ALL x. t=x --> P(x)) = P(t)"
nipkow@17589
   971
  by (blast, blast, blast, blast, blast, iprover+)
wenzelm@13421
   972
paulson@14201
   973
lemma disj_absorb: "(A | A) = A"
paulson@14201
   974
  by blast
paulson@14201
   975
paulson@14201
   976
lemma disj_left_absorb: "(A | (A | B)) = (A | B)"
paulson@14201
   977
  by blast
paulson@14201
   978
paulson@14201
   979
lemma conj_absorb: "(A & A) = A"
paulson@14201
   980
  by blast
paulson@14201
   981
paulson@14201
   982
lemma conj_left_absorb: "(A & (A & B)) = (A & B)"
paulson@14201
   983
  by blast
paulson@14201
   984
wenzelm@12281
   985
lemma eq_ac:
wenzelm@12937
   986
  shows eq_commute: "(a=b) = (b=a)"
wenzelm@12937
   987
    and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
nipkow@17589
   988
    and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (iprover, blast+)
nipkow@17589
   989
lemma neq_commute: "(a~=b) = (b~=a)" by iprover
wenzelm@12281
   990
wenzelm@12281
   991
lemma conj_comms:
wenzelm@12937
   992
  shows conj_commute: "(P&Q) = (Q&P)"
nipkow@17589
   993
    and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by iprover+
nipkow@17589
   994
lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by iprover
wenzelm@12281
   995
paulson@19174
   996
lemmas conj_ac = conj_commute conj_left_commute conj_assoc
paulson@19174
   997
wenzelm@12281
   998
lemma disj_comms:
wenzelm@12937
   999
  shows disj_commute: "(P|Q) = (Q|P)"
nipkow@17589
  1000
    and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by iprover+
nipkow@17589
  1001
lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by iprover
wenzelm@12281
  1002
paulson@19174
  1003
lemmas disj_ac = disj_commute disj_left_commute disj_assoc
paulson@19174
  1004
nipkow@17589
  1005
lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by iprover
nipkow@17589
  1006
lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by iprover
wenzelm@12281
  1007
nipkow@17589
  1008
lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by iprover
nipkow@17589
  1009
lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by iprover
wenzelm@12281
  1010
nipkow@17589
  1011
lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by iprover
nipkow@17589
  1012
lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by iprover
nipkow@17589
  1013
lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by iprover
wenzelm@12281
  1014
wenzelm@12281
  1015
text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
wenzelm@12281
  1016
lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
wenzelm@12281
  1017
lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
wenzelm@12281
  1018
wenzelm@12281
  1019
lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
wenzelm@12281
  1020
lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
wenzelm@12281
  1021
haftmann@21151
  1022
lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
haftmann@21151
  1023
  by iprover
haftmann@21151
  1024
nipkow@17589
  1025
lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by iprover
wenzelm@12281
  1026
lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
wenzelm@12281
  1027
lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
wenzelm@12281
  1028
lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
wenzelm@12281
  1029
lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
wenzelm@12281
  1030
lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
wenzelm@12281
  1031
  by blast
wenzelm@12281
  1032
lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
wenzelm@12281
  1033
nipkow@17589
  1034
lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by iprover
wenzelm@12281
  1035
wenzelm@12281
  1036
wenzelm@12281
  1037
lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
wenzelm@12281
  1038
  -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
wenzelm@12281
  1039
  -- {* cases boil down to the same thing. *}
wenzelm@12281
  1040
  by blast
wenzelm@12281
  1041
wenzelm@12281
  1042
lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
wenzelm@12281
  1043
lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
nipkow@17589
  1044
lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by iprover
nipkow@17589
  1045
lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by iprover
wenzelm@12281
  1046
nipkow@17589
  1047
lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by iprover
nipkow@17589
  1048
lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by iprover
wenzelm@12281
  1049
wenzelm@12281
  1050
text {*
wenzelm@12281
  1051
  \medskip The @{text "&"} congruence rule: not included by default!
wenzelm@12281
  1052
  May slow rewrite proofs down by as much as 50\% *}
wenzelm@12281
  1053
wenzelm@12281
  1054
lemma conj_cong:
wenzelm@12281
  1055
    "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
nipkow@17589
  1056
  by iprover
wenzelm@12281
  1057
wenzelm@12281
  1058
lemma rev_conj_cong:
wenzelm@12281
  1059
    "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
nipkow@17589
  1060
  by iprover
wenzelm@12281
  1061
wenzelm@12281
  1062
text {* The @{text "|"} congruence rule: not included by default! *}
wenzelm@12281
  1063
wenzelm@12281
  1064
lemma disj_cong:
wenzelm@12281
  1065
    "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
wenzelm@12281
  1066
  by blast
wenzelm@12281
  1067
wenzelm@12281
  1068
wenzelm@12281
  1069
text {* \medskip if-then-else rules *}
wenzelm@12281
  1070
wenzelm@12281
  1071
lemma if_True: "(if True then x else y) = x"
wenzelm@12281
  1072
  by (unfold if_def) blast
wenzelm@12281
  1073
wenzelm@12281
  1074
lemma if_False: "(if False then x else y) = y"
wenzelm@12281
  1075
  by (unfold if_def) blast
wenzelm@12281
  1076
wenzelm@12281
  1077
lemma if_P: "P ==> (if P then x else y) = x"
wenzelm@12281
  1078
  by (unfold if_def) blast
wenzelm@12281
  1079
wenzelm@12281
  1080
lemma if_not_P: "~P ==> (if P then x else y) = y"
wenzelm@12281
  1081
  by (unfold if_def) blast
wenzelm@12281
  1082
wenzelm@12281
  1083
lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
wenzelm@12281
  1084
  apply (rule case_split [of Q])
paulson@15481
  1085
   apply (simplesubst if_P)
paulson@15481
  1086
    prefer 3 apply (simplesubst if_not_P, blast+)
wenzelm@12281
  1087
  done
wenzelm@12281
  1088
wenzelm@12281
  1089
lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
paulson@15481
  1090
by (simplesubst split_if, blast)
wenzelm@12281
  1091
wenzelm@12281
  1092
lemmas if_splits = split_if split_if_asm
wenzelm@12281
  1093
wenzelm@12281
  1094
lemma if_cancel: "(if c then x else x) = x"
paulson@15481
  1095
by (simplesubst split_if, blast)
wenzelm@12281
  1096
wenzelm@12281
  1097
lemma if_eq_cancel: "(if x = y then y else x) = x"
paulson@15481
  1098
by (simplesubst split_if, blast)
wenzelm@12281
  1099
wenzelm@12281
  1100
lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
wenzelm@19796
  1101
  -- {* This form is useful for expanding @{text "if"}s on the RIGHT of the @{text "==>"} symbol. *}
wenzelm@12281
  1102
  by (rule split_if)
wenzelm@12281
  1103
wenzelm@12281
  1104
lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
wenzelm@19796
  1105
  -- {* And this form is useful for expanding @{text "if"}s on the LEFT. *}
paulson@15481
  1106
  apply (simplesubst split_if, blast)
wenzelm@12281
  1107
  done
wenzelm@12281
  1108
nipkow@17589
  1109
lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) iprover
nipkow@17589
  1110
lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) iprover
wenzelm@12281
  1111
schirmer@15423
  1112
text {* \medskip let rules for simproc *}
schirmer@15423
  1113
schirmer@15423
  1114
lemma Let_folded: "f x \<equiv> g x \<Longrightarrow>  Let x f \<equiv> Let x g"
schirmer@15423
  1115
  by (unfold Let_def)
schirmer@15423
  1116
schirmer@15423
  1117
lemma Let_unfold: "f x \<equiv> g \<Longrightarrow>  Let x f \<equiv> g"
schirmer@15423
  1118
  by (unfold Let_def)
schirmer@15423
  1119
berghofe@16633
  1120
text {*
ballarin@16999
  1121
  The following copy of the implication operator is useful for
ballarin@16999
  1122
  fine-tuning congruence rules.  It instructs the simplifier to simplify
ballarin@16999
  1123
  its premise.
berghofe@16633
  1124
*}
berghofe@16633
  1125
wenzelm@17197
  1126
constdefs
wenzelm@17197
  1127
  simp_implies :: "[prop, prop] => prop"  (infixr "=simp=>" 1)
wenzelm@17197
  1128
  "simp_implies \<equiv> op ==>"
berghofe@16633
  1129
wenzelm@18457
  1130
lemma simp_impliesI:
berghofe@16633
  1131
  assumes PQ: "(PROP P \<Longrightarrow> PROP Q)"
berghofe@16633
  1132
  shows "PROP P =simp=> PROP Q"
berghofe@16633
  1133
  apply (unfold simp_implies_def)
berghofe@16633
  1134
  apply (rule PQ)
berghofe@16633
  1135
  apply assumption
berghofe@16633
  1136
  done
berghofe@16633
  1137
berghofe@16633
  1138
lemma simp_impliesE:
berghofe@16633
  1139
  assumes PQ:"PROP P =simp=> PROP Q"
berghofe@16633
  1140
  and P: "PROP P"
berghofe@16633
  1141
  and QR: "PROP Q \<Longrightarrow> PROP R"
berghofe@16633
  1142
  shows "PROP R"
berghofe@16633
  1143
  apply (rule QR)
berghofe@16633
  1144
  apply (rule PQ [unfolded simp_implies_def])
berghofe@16633
  1145
  apply (rule P)
berghofe@16633
  1146
  done
berghofe@16633
  1147
berghofe@16633
  1148
lemma simp_implies_cong:
berghofe@16633
  1149
  assumes PP' :"PROP P == PROP P'"
berghofe@16633
  1150
  and P'QQ': "PROP P' ==> (PROP Q == PROP Q')"
berghofe@16633
  1151
  shows "(PROP P =simp=> PROP Q) == (PROP P' =simp=> PROP Q')"
berghofe@16633
  1152
proof (unfold simp_implies_def, rule equal_intr_rule)
berghofe@16633
  1153
  assume PQ: "PROP P \<Longrightarrow> PROP Q"
berghofe@16633
  1154
  and P': "PROP P'"
berghofe@16633
  1155
  from PP' [symmetric] and P' have "PROP P"
berghofe@16633
  1156
    by (rule equal_elim_rule1)
berghofe@16633
  1157
  hence "PROP Q" by (rule PQ)
berghofe@16633
  1158
  with P'QQ' [OF P'] show "PROP Q'" by (rule equal_elim_rule1)
berghofe@16633
  1159
next
berghofe@16633
  1160
  assume P'Q': "PROP P' \<Longrightarrow> PROP Q'"
berghofe@16633
  1161
  and P: "PROP P"
berghofe@16633
  1162
  from PP' and P have P': "PROP P'" by (rule equal_elim_rule1)
berghofe@16633
  1163
  hence "PROP Q'" by (rule P'Q')
berghofe@16633
  1164
  with P'QQ' [OF P', symmetric] show "PROP Q"
berghofe@16633
  1165
    by (rule equal_elim_rule1)
berghofe@16633
  1166
qed
berghofe@16633
  1167
haftmann@20944
  1168
lemma uncurry:
haftmann@20944
  1169
  assumes "P \<longrightarrow> Q \<longrightarrow> R"
haftmann@20944
  1170
  shows "P \<and> Q \<longrightarrow> R"
haftmann@20944
  1171
  using prems by blast
haftmann@20944
  1172
haftmann@20944
  1173
lemma iff_allI:
haftmann@20944
  1174
  assumes "\<And>x. P x = Q x"
haftmann@20944
  1175
  shows "(\<forall>x. P x) = (\<forall>x. Q x)"
haftmann@20944
  1176
  using prems by blast
haftmann@20944
  1177
haftmann@20944
  1178
lemma iff_exI:
haftmann@20944
  1179
  assumes "\<And>x. P x = Q x"
haftmann@20944
  1180
  shows "(\<exists>x. P x) = (\<exists>x. Q x)"
haftmann@20944
  1181
  using prems by blast
haftmann@20944
  1182
haftmann@20944
  1183
lemma all_comm:
haftmann@20944
  1184
  "(\<forall>x y. P x y) = (\<forall>y x. P x y)"
haftmann@20944
  1185
  by blast
haftmann@20944
  1186
haftmann@20944
  1187
lemma ex_comm:
haftmann@20944
  1188
  "(\<exists>x y. P x y) = (\<exists>y x. P x y)"
haftmann@20944
  1189
  by blast
haftmann@20944
  1190
wenzelm@9869
  1191
use "simpdata.ML"
wenzelm@21671
  1192
ML {* open Simpdata *}
wenzelm@21671
  1193
haftmann@21151
  1194
setup {*
haftmann@21151
  1195
  Simplifier.method_setup Splitter.split_modifiers
haftmann@21547
  1196
  #> (fn thy => (change_simpset_of thy (fn _ => Simpdata.simpset_simprocs); thy))
haftmann@21151
  1197
  #> Splitter.setup
haftmann@21151
  1198
  #> Clasimp.setup
haftmann@21151
  1199
  #> EqSubst.setup
haftmann@21151
  1200
*}
haftmann@21151
  1201
haftmann@21151
  1202
lemma True_implies_equals: "(True \<Longrightarrow> PROP P) \<equiv> PROP P"
haftmann@21151
  1203
proof
haftmann@21151
  1204
  assume prem: "True \<Longrightarrow> PROP P"
haftmann@21151
  1205
  from prem [OF TrueI] show "PROP P" . 
haftmann@21151
  1206
next
haftmann@21151
  1207
  assume "PROP P"
haftmann@21151
  1208
  show "PROP P" .
haftmann@21151
  1209
qed
haftmann@21151
  1210
haftmann@21151
  1211
lemma ex_simps:
haftmann@21151
  1212
  "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
haftmann@21151
  1213
  "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
haftmann@21151
  1214
  "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
haftmann@21151
  1215
  "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
haftmann@21151
  1216
  "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
haftmann@21151
  1217
  "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
haftmann@21151
  1218
  -- {* Miniscoping: pushing in existential quantifiers. *}
haftmann@21151
  1219
  by (iprover | blast)+
haftmann@21151
  1220
haftmann@21151
  1221
lemma all_simps:
haftmann@21151
  1222
  "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
haftmann@21151
  1223
  "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
haftmann@21151
  1224
  "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
haftmann@21151
  1225
  "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
haftmann@21151
  1226
  "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
haftmann@21151
  1227
  "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
haftmann@21151
  1228
  -- {* Miniscoping: pushing in universal quantifiers. *}
haftmann@21151
  1229
  by (iprover | blast)+
paulson@15481
  1230
wenzelm@21671
  1231
lemmas [simp] =
wenzelm@21671
  1232
  triv_forall_equality (*prunes params*)
wenzelm@21671
  1233
  True_implies_equals  (*prune asms `True'*)
wenzelm@21671
  1234
  if_True
wenzelm@21671
  1235
  if_False
wenzelm@21671
  1236
  if_cancel
wenzelm@21671
  1237
  if_eq_cancel
wenzelm@21671
  1238
  imp_disjL
haftmann@20973
  1239
  (*In general it seems wrong to add distributive laws by default: they
haftmann@20973
  1240
    might cause exponential blow-up.  But imp_disjL has been in for a while
haftmann@20973
  1241
    and cannot be removed without affecting existing proofs.  Moreover,
haftmann@20973
  1242
    rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the
haftmann@20973
  1243
    grounds that it allows simplification of R in the two cases.*)
wenzelm@21671
  1244
  conj_assoc
wenzelm@21671
  1245
  disj_assoc
wenzelm@21671
  1246
  de_Morgan_conj
wenzelm@21671
  1247
  de_Morgan_disj
wenzelm@21671
  1248
  imp_disj1
wenzelm@21671
  1249
  imp_disj2
wenzelm@21671
  1250
  not_imp
wenzelm@21671
  1251
  disj_not1
wenzelm@21671
  1252
  not_all
wenzelm@21671
  1253
  not_ex
wenzelm@21671
  1254
  cases_simp
wenzelm@21671
  1255
  the_eq_trivial
wenzelm@21671
  1256
  the_sym_eq_trivial
wenzelm@21671
  1257
  ex_simps
wenzelm@21671
  1258
  all_simps
wenzelm@21671
  1259
  simp_thms
wenzelm@21671
  1260
wenzelm@21671
  1261
lemmas [cong] = imp_cong simp_implies_cong
wenzelm@21671
  1262
lemmas [split] = split_if
haftmann@20973
  1263
wenzelm@22377
  1264
ML {* val HOL_ss = @{simpset} *}
haftmann@20973
  1265
haftmann@20944
  1266
text {* Simplifies x assuming c and y assuming ~c *}
haftmann@20944
  1267
lemma if_cong:
haftmann@20944
  1268
  assumes "b = c"
haftmann@20944
  1269
      and "c \<Longrightarrow> x = u"
haftmann@20944
  1270
      and "\<not> c \<Longrightarrow> y = v"
haftmann@20944
  1271
  shows "(if b then x else y) = (if c then u else v)"
haftmann@20944
  1272
  unfolding if_def using prems by simp
haftmann@20944
  1273
haftmann@20944
  1274
text {* Prevents simplification of x and y:
haftmann@20944
  1275
  faster and allows the execution of functional programs. *}
haftmann@20944
  1276
lemma if_weak_cong [cong]:
haftmann@20944
  1277
  assumes "b = c"
haftmann@20944
  1278
  shows "(if b then x else y) = (if c then x else y)"
haftmann@20944
  1279
  using prems by (rule arg_cong)
haftmann@20944
  1280
haftmann@20944
  1281
text {* Prevents simplification of t: much faster *}
haftmann@20944
  1282
lemma let_weak_cong:
haftmann@20944
  1283
  assumes "a = b"
haftmann@20944
  1284
  shows "(let x = a in t x) = (let x = b in t x)"
haftmann@20944
  1285
  using prems by (rule arg_cong)
haftmann@20944
  1286
haftmann@20944
  1287
text {* To tidy up the result of a simproc.  Only the RHS will be simplified. *}
haftmann@20944
  1288
lemma eq_cong2:
haftmann@20944
  1289
  assumes "u = u'"
haftmann@20944
  1290
  shows "(t \<equiv> u) \<equiv> (t \<equiv> u')"
haftmann@20944
  1291
  using prems by simp
haftmann@20944
  1292
haftmann@20944
  1293
lemma if_distrib:
haftmann@20944
  1294
  "f (if c then x else y) = (if c then f x else f y)"
haftmann@20944
  1295
  by simp
haftmann@20944
  1296
haftmann@20944
  1297
text {* This lemma restricts the effect of the rewrite rule u=v to the left-hand
wenzelm@21502
  1298
  side of an equality.  Used in @{text "{Integ,Real}/simproc.ML"} *}
haftmann@20944
  1299
lemma restrict_to_left:
haftmann@20944
  1300
  assumes "x = y"
haftmann@20944
  1301
  shows "(x = z) = (y = z)"
haftmann@20944
  1302
  using prems by simp
haftmann@20944
  1303
wenzelm@17459
  1304
haftmann@20944
  1305
subsubsection {* Generic cases and induction *}
wenzelm@17459
  1306
haftmann@20944
  1307
text {* Rule projections: *}
berghofe@18887
  1308
haftmann@20944
  1309
ML {*
haftmann@20944
  1310
structure ProjectRule = ProjectRuleFun
haftmann@20944
  1311
(struct
wenzelm@22129
  1312
  val conjunct1 = @{thm conjunct1};
wenzelm@22129
  1313
  val conjunct2 = @{thm conjunct2};
wenzelm@22129
  1314
  val mp = @{thm mp};
haftmann@20944
  1315
end)
wenzelm@17459
  1316
*}
wenzelm@17459
  1317
wenzelm@11824
  1318
constdefs
wenzelm@18457
  1319
  induct_forall where "induct_forall P == \<forall>x. P x"
wenzelm@18457
  1320
  induct_implies where "induct_implies A B == A \<longrightarrow> B"
wenzelm@18457
  1321
  induct_equal where "induct_equal x y == x = y"
wenzelm@18457
  1322
  induct_conj where "induct_conj A B == A \<and> B"
wenzelm@11824
  1323
wenzelm@11989
  1324
lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
wenzelm@18457
  1325
  by (unfold atomize_all induct_forall_def)
wenzelm@11824
  1326
wenzelm@11989
  1327
lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
wenzelm@18457
  1328
  by (unfold atomize_imp induct_implies_def)
wenzelm@11824
  1329
wenzelm@11989
  1330
lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
wenzelm@18457
  1331
  by (unfold atomize_eq induct_equal_def)
wenzelm@18457
  1332
wenzelm@18457
  1333
lemma induct_conj_eq:
wenzelm@18457
  1334
  includes meta_conjunction_syntax
wenzelm@18457
  1335
  shows "(A && B) == Trueprop (induct_conj A B)"
wenzelm@18457
  1336
  by (unfold atomize_conj induct_conj_def)
wenzelm@18457
  1337
wenzelm@18457
  1338
lemmas induct_atomize = induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq
wenzelm@18457
  1339
lemmas induct_rulify [symmetric, standard] = induct_atomize
wenzelm@18457
  1340
lemmas induct_rulify_fallback =
wenzelm@18457
  1341
  induct_forall_def induct_implies_def induct_equal_def induct_conj_def
wenzelm@18457
  1342
wenzelm@11824
  1343
wenzelm@11989
  1344
lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
wenzelm@11989
  1345
    induct_conj (induct_forall A) (induct_forall B)"
nipkow@17589
  1346
  by (unfold induct_forall_def induct_conj_def) iprover
wenzelm@11824
  1347
wenzelm@11989
  1348
lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
wenzelm@11989
  1349
    induct_conj (induct_implies C A) (induct_implies C B)"
nipkow@17589
  1350
  by (unfold induct_implies_def induct_conj_def) iprover
wenzelm@11989
  1351
berghofe@13598
  1352
lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
berghofe@13598
  1353
proof
berghofe@13598
  1354
  assume r: "induct_conj A B ==> PROP C" and A B
wenzelm@18457
  1355
  show "PROP C" by (rule r) (simp add: induct_conj_def `A` `B`)
berghofe@13598
  1356
next
berghofe@13598
  1357
  assume r: "A ==> B ==> PROP C" and "induct_conj A B"
wenzelm@18457
  1358
  show "PROP C" by (rule r) (simp_all add: `induct_conj A B` [unfolded induct_conj_def])
berghofe@13598
  1359
qed
wenzelm@11824
  1360
wenzelm@11989
  1361
lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
wenzelm@11824
  1362
wenzelm@11989
  1363
hide const induct_forall induct_implies induct_equal induct_conj
wenzelm@11824
  1364
wenzelm@11824
  1365
text {* Method setup. *}
wenzelm@11824
  1366
wenzelm@11824
  1367
ML {*
wenzelm@11824
  1368
  structure InductMethod = InductMethodFun
wenzelm@11824
  1369
  (struct
wenzelm@22129
  1370
    val cases_default = @{thm case_split}
wenzelm@22129
  1371
    val atomize = @{thms induct_atomize}
wenzelm@22129
  1372
    val rulify = @{thms induct_rulify}
wenzelm@22129
  1373
    val rulify_fallback = @{thms induct_rulify_fallback}
wenzelm@11824
  1374
  end);
wenzelm@11824
  1375
*}
wenzelm@11824
  1376
wenzelm@11824
  1377
setup InductMethod.setup
wenzelm@11824
  1378
wenzelm@18457
  1379
haftmann@20944
  1380
haftmann@20944
  1381
subsection {* Other simple lemmas and lemma duplicates *}
haftmann@20944
  1382
haftmann@20944
  1383
lemma ex1_eq [iff]: "EX! x. x = t" "EX! x. t = x"
haftmann@20944
  1384
  by blast+
haftmann@20944
  1385
haftmann@20944
  1386
lemma choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
haftmann@20944
  1387
  apply (rule iffI)
haftmann@20944
  1388
  apply (rule_tac a = "%x. THE y. P x y" in ex1I)
haftmann@20944
  1389
  apply (fast dest!: theI')
haftmann@20944
  1390
  apply (fast intro: ext the1_equality [symmetric])
haftmann@20944
  1391
  apply (erule ex1E)
haftmann@20944
  1392
  apply (rule allI)
haftmann@20944
  1393
  apply (rule ex1I)
haftmann@20944
  1394
  apply (erule spec)
haftmann@20944
  1395
  apply (erule_tac x = "%z. if z = x then y else f z" in allE)
haftmann@20944
  1396
  apply (erule impE)
haftmann@20944
  1397
  apply (rule allI)
haftmann@20944
  1398
  apply (rule_tac P = "xa = x" in case_split_thm)
haftmann@20944
  1399
  apply (drule_tac [3] x = x in fun_cong, simp_all)
haftmann@20944
  1400
  done
haftmann@20944
  1401
haftmann@20944
  1402
lemma mk_left_commute:
haftmann@21547
  1403
  fixes f (infix "\<otimes>" 60)
haftmann@21547
  1404
  assumes a: "\<And>x y z. (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)" and
haftmann@21547
  1405
          c: "\<And>x y. x \<otimes> y = y \<otimes> x"
haftmann@21547
  1406
  shows "x \<otimes> (y \<otimes> z) = y \<otimes> (x \<otimes> z)"
haftmann@20944
  1407
  by (rule trans [OF trans [OF c a] arg_cong [OF c, of "f y"]])
haftmann@20944
  1408
haftmann@22218
  1409
lemmas eq_sym_conv = eq_commute
haftmann@22218
  1410
wenzelm@21671
  1411
wenzelm@21671
  1412
subsection {* Basic ML bindings *}
wenzelm@21671
  1413
wenzelm@21671
  1414
ML {*
wenzelm@22129
  1415
val FalseE = @{thm FalseE}
wenzelm@22129
  1416
val Let_def = @{thm Let_def}
wenzelm@22129
  1417
val TrueI = @{thm TrueI}
wenzelm@22129
  1418
val allE = @{thm allE}
wenzelm@22129
  1419
val allI = @{thm allI}
wenzelm@22129
  1420
val all_dupE = @{thm all_dupE}
wenzelm@22129
  1421
val arg_cong = @{thm arg_cong}
wenzelm@22129
  1422
val box_equals = @{thm box_equals}
wenzelm@22129
  1423
val ccontr = @{thm ccontr}
wenzelm@22129
  1424
val classical = @{thm classical}
wenzelm@22129
  1425
val conjE = @{thm conjE}
wenzelm@22129
  1426
val conjI = @{thm conjI}
wenzelm@22129
  1427
val conjunct1 = @{thm conjunct1}
wenzelm@22129
  1428
val conjunct2 = @{thm conjunct2}
wenzelm@22129
  1429
val disjCI = @{thm disjCI}
wenzelm@22129
  1430
val disjE = @{thm disjE}
wenzelm@22129
  1431
val disjI1 = @{thm disjI1}
wenzelm@22129
  1432
val disjI2 = @{thm disjI2}
wenzelm@22129
  1433
val eq_reflection = @{thm eq_reflection}
wenzelm@22129
  1434
val ex1E = @{thm ex1E}
wenzelm@22129
  1435
val ex1I = @{thm ex1I}
wenzelm@22129
  1436
val ex1_implies_ex = @{thm ex1_implies_ex}
wenzelm@22129
  1437
val exE = @{thm exE}
wenzelm@22129
  1438
val exI = @{thm exI}
wenzelm@22129
  1439
val excluded_middle = @{thm excluded_middle}
wenzelm@22129
  1440
val ext = @{thm ext}
wenzelm@22129
  1441
val fun_cong = @{thm fun_cong}
wenzelm@22129
  1442
val iffD1 = @{thm iffD1}
wenzelm@22129
  1443
val iffD2 = @{thm iffD2}
wenzelm@22129
  1444
val iffI = @{thm iffI}
wenzelm@22129
  1445
val impE = @{thm impE}
wenzelm@22129
  1446
val impI = @{thm impI}
wenzelm@22129
  1447
val meta_eq_to_obj_eq = @{thm meta_eq_to_obj_eq}
wenzelm@22129
  1448
val mp = @{thm mp}
wenzelm@22129
  1449
val notE = @{thm notE}
wenzelm@22129
  1450
val notI = @{thm notI}
wenzelm@22129
  1451
val not_all = @{thm not_all}
wenzelm@22129
  1452
val not_ex = @{thm not_ex}
wenzelm@22129
  1453
val not_iff = @{thm not_iff}
wenzelm@22129
  1454
val not_not = @{thm not_not}
wenzelm@22129
  1455
val not_sym = @{thm not_sym}
wenzelm@22129
  1456
val refl = @{thm refl}
wenzelm@22129
  1457
val rev_mp = @{thm rev_mp}
wenzelm@22129
  1458
val spec = @{thm spec}
wenzelm@22129
  1459
val ssubst = @{thm ssubst}
wenzelm@22129
  1460
val subst = @{thm subst}
wenzelm@22129
  1461
val sym = @{thm sym}
wenzelm@22129
  1462
val trans = @{thm trans}
wenzelm@21671
  1463
*}
wenzelm@21671
  1464
wenzelm@21671
  1465
haftmann@22839
  1466
subsection {* Legacy tactics and ML bindings *}
wenzelm@21671
  1467
wenzelm@21671
  1468
ML {*
wenzelm@21671
  1469
fun strip_tac i = REPEAT (resolve_tac [impI, allI] i);
wenzelm@21671
  1470
wenzelm@21671
  1471
(* combination of (spec RS spec RS ...(j times) ... spec RS mp) *)
wenzelm@21671
  1472
local
wenzelm@21671
  1473
  fun wrong_prem (Const ("All", _) $ (Abs (_, _, t))) = wrong_prem t
wenzelm@21671
  1474
    | wrong_prem (Bound _) = true
wenzelm@21671
  1475
    | wrong_prem _ = false;
wenzelm@21671
  1476
  val filter_right = filter (not o wrong_prem o HOLogic.dest_Trueprop o hd o Thm.prems_of);
wenzelm@21671
  1477
in
wenzelm@21671
  1478
  fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp]);
wenzelm@21671
  1479
  fun smp_tac j = EVERY'[dresolve_tac (smp j), atac];
wenzelm@21671
  1480
end;
haftmann@22839
  1481
haftmann@22839
  1482
val all_conj_distrib = thm "all_conj_distrib";
haftmann@22839
  1483
val all_simps = thms "all_simps";
haftmann@22839
  1484
val atomize_not = thm "atomize_not";
haftmann@22839
  1485
val case_split = thm "case_split_thm";
haftmann@22839
  1486
val case_split_thm = thm "case_split_thm"
haftmann@22839
  1487
val cases_simp = thm "cases_simp";
haftmann@22839
  1488
val choice_eq = thm "choice_eq"
haftmann@22839
  1489
val cong = thm "cong"
haftmann@22839
  1490
val conj_comms = thms "conj_comms";
haftmann@22839
  1491
val conj_cong = thm "conj_cong";
haftmann@22839
  1492
val de_Morgan_conj = thm "de_Morgan_conj";
haftmann@22839
  1493
val de_Morgan_disj = thm "de_Morgan_disj";
haftmann@22839
  1494
val disj_assoc = thm "disj_assoc";
haftmann@22839
  1495
val disj_comms = thms "disj_comms";
haftmann@22839
  1496
val disj_cong = thm "disj_cong";
haftmann@22839
  1497
val eq_ac = thms "eq_ac";
haftmann@22839
  1498
val eq_cong2 = thm "eq_cong2"
haftmann@22839
  1499
val Eq_FalseI = thm "Eq_FalseI";
haftmann@22839
  1500
val Eq_TrueI = thm "Eq_TrueI";
haftmann@22839
  1501
val Ex1_def = thm "Ex1_def"
haftmann@22839
  1502
val ex_disj_distrib = thm "ex_disj_distrib";
haftmann@22839
  1503
val ex_simps = thms "ex_simps";
haftmann@22839
  1504
val if_cancel = thm "if_cancel";
haftmann@22839
  1505
val if_eq_cancel = thm "if_eq_cancel";
haftmann@22839
  1506
val if_False = thm "if_False";
haftmann@22839
  1507
val iff_conv_conj_imp = thm "iff_conv_conj_imp";
haftmann@22839
  1508
val iff = thm "iff"
haftmann@22839
  1509
val if_splits = thms "if_splits";
haftmann@22839
  1510
val if_True = thm "if_True";
haftmann@22839
  1511
val if_weak_cong = thm "if_weak_cong"
haftmann@22839
  1512
val imp_all = thm "imp_all";
haftmann@22839
  1513
val imp_cong = thm "imp_cong";
haftmann@22839
  1514
val imp_conjL = thm "imp_conjL";
haftmann@22839
  1515
val imp_conjR = thm "imp_conjR";
haftmann@22839
  1516
val imp_conv_disj = thm "imp_conv_disj";
haftmann@22839
  1517
val simp_implies_def = thm "simp_implies_def";
haftmann@22839
  1518
val simp_thms = thms "simp_thms";
haftmann@22839
  1519
val split_if = thm "split_if";
haftmann@22839
  1520
val the1_equality = thm "the1_equality"
haftmann@22839
  1521
val theI = thm "theI"
haftmann@22839
  1522
val theI' = thm "theI'"
haftmann@22839
  1523
val True_implies_equals = thm "True_implies_equals";
wenzelm@21671
  1524
*}
wenzelm@21671
  1525
kleing@14357
  1526
end