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