src/HOL/HOL.thy
author haftmann
Thu, 23 Apr 2009 12:17:50 +0200
changeset 30966 55104c664185
parent 30947 dd551284a300
child 30970 3fe2e418a071
permissions -rw-r--r--
avoid local [code]
clasohm@923
     1
(*  Title:      HOL/HOL.thy
wenzelm@11750
     2
    Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
wenzelm@11750
     3
*)
clasohm@923
     4
wenzelm@11750
     5
header {* The basis of Higher-Order Logic *}
clasohm@923
     6
nipkow@15131
     7
theory HOL
haftmann@30929
     8
imports Pure "~~/src/Tools/Code_Generator"
wenzelm@23163
     9
uses
haftmann@28952
    10
  ("Tools/hologic.ML")
wenzelm@23171
    11
  "~~/src/Tools/IsaPlanner/zipper.ML"
wenzelm@23171
    12
  "~~/src/Tools/IsaPlanner/isand.ML"
wenzelm@23171
    13
  "~~/src/Tools/IsaPlanner/rw_tools.ML"
wenzelm@23171
    14
  "~~/src/Tools/IsaPlanner/rw_inst.ML"
wenzelm@30165
    15
  "~~/src/Tools/intuitionistic.ML"
wenzelm@30160
    16
  "~~/src/Tools/project_rule.ML"
haftmann@23263
    17
  "~~/src/Provers/hypsubst.ML"
haftmann@23263
    18
  "~~/src/Provers/splitter.ML"
wenzelm@23163
    19
  "~~/src/Provers/classical.ML"
wenzelm@23163
    20
  "~~/src/Provers/blast.ML"
wenzelm@23163
    21
  "~~/src/Provers/clasimp.ML"
wenzelm@30160
    22
  "~~/src/Tools/coherent.ML"
wenzelm@30160
    23
  "~~/src/Tools/eqsubst.ML"
wenzelm@23163
    24
  "~~/src/Provers/quantifier1.ML"
haftmann@28952
    25
  ("Tools/simpdata.ML")
wenzelm@25741
    26
  "~~/src/Tools/random_word.ML"
krauss@26580
    27
  "~~/src/Tools/atomize_elim.ML"
haftmann@24901
    28
  "~~/src/Tools/induct.ML"
wenzelm@27326
    29
  ("~~/src/Tools/induct_tacs.ML")
haftmann@29505
    30
  ("Tools/recfun_codegen.ML")
nipkow@15131
    31
begin
wenzelm@2260
    32
wenzelm@30165
    33
setup {* Intuitionistic.method_setup "iprover" *}
wenzelm@30165
    34
wenzelm@30165
    35
wenzelm@11750
    36
subsection {* Primitive logic *}
wenzelm@11750
    37
wenzelm@11750
    38
subsubsection {* Core syntax *}
wenzelm@2260
    39
wenzelm@14854
    40
classes type
wenzelm@12338
    41
defaultsort type
wenzelm@25494
    42
setup {* ObjectLogic.add_base_sort @{sort type} *}
haftmann@25460
    43
haftmann@25460
    44
arities
haftmann@25460
    45
  "fun" :: (type, type) type
haftmann@25460
    46
  itself :: (type) type
haftmann@25460
    47
wenzelm@3947
    48
global
wenzelm@3947
    49
wenzelm@7357
    50
typedecl bool
clasohm@923
    51
wenzelm@11750
    52
judgment
wenzelm@11750
    53
  Trueprop      :: "bool => prop"                   ("(_)" 5)
wenzelm@11750
    54
clasohm@923
    55
consts
wenzelm@7357
    56
  Not           :: "bool => bool"                   ("~ _" [40] 40)
wenzelm@7357
    57
  True          :: bool
wenzelm@7357
    58
  False         :: bool
clasohm@923
    59
wenzelm@11432
    60
  The           :: "('a => bool) => 'a"
wenzelm@7357
    61
  All           :: "('a => bool) => bool"           (binder "ALL " 10)
wenzelm@7357
    62
  Ex            :: "('a => bool) => bool"           (binder "EX " 10)
wenzelm@7357
    63
  Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
wenzelm@7357
    64
  Let           :: "['a, 'a => 'b] => 'b"
clasohm@923
    65
haftmann@22839
    66
  "op ="        :: "['a, 'a] => bool"               (infixl "=" 50)
haftmann@22839
    67
  "op &"        :: "[bool, bool] => bool"           (infixr "&" 35)
haftmann@22839
    68
  "op |"        :: "[bool, bool] => bool"           (infixr "|" 30)
haftmann@22839
    69
  "op -->"      :: "[bool, bool] => bool"           (infixr "-->" 25)
clasohm@923
    70
wenzelm@10432
    71
local
wenzelm@10432
    72
paulson@16587
    73
consts
paulson@16587
    74
  If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
clasohm@923
    75
wenzelm@19656
    76
wenzelm@11750
    77
subsubsection {* Additional concrete syntax *}
wenzelm@2260
    78
wenzelm@21210
    79
notation (output)
wenzelm@19656
    80
  "op ="  (infix "=" 50)
wenzelm@19656
    81
wenzelm@19656
    82
abbreviation
wenzelm@21404
    83
  not_equal :: "['a, 'a] => bool"  (infixl "~=" 50) where
wenzelm@19656
    84
  "x ~= y == ~ (x = y)"
wenzelm@19656
    85
wenzelm@21210
    86
notation (output)
wenzelm@19656
    87
  not_equal  (infix "~=" 50)
wenzelm@19656
    88
wenzelm@21210
    89
notation (xsymbols)
wenzelm@21404
    90
  Not  ("\<not> _" [40] 40) and
wenzelm@21404
    91
  "op &"  (infixr "\<and>" 35) and
wenzelm@21404
    92
  "op |"  (infixr "\<or>" 30) and
wenzelm@21404
    93
  "op -->"  (infixr "\<longrightarrow>" 25) and
wenzelm@19656
    94
  not_equal  (infix "\<noteq>" 50)
wenzelm@19656
    95
wenzelm@21210
    96
notation (HTML output)
wenzelm@21404
    97
  Not  ("\<not> _" [40] 40) and
wenzelm@21404
    98
  "op &"  (infixr "\<and>" 35) and
wenzelm@21404
    99
  "op |"  (infixr "\<or>" 30) and
wenzelm@19656
   100
  not_equal  (infix "\<noteq>" 50)
wenzelm@19656
   101
wenzelm@19656
   102
abbreviation (iff)
wenzelm@21404
   103
  iff :: "[bool, bool] => bool"  (infixr "<->" 25) where
wenzelm@19656
   104
  "A <-> B == A = B"
wenzelm@19656
   105
wenzelm@21210
   106
notation (xsymbols)
wenzelm@19656
   107
  iff  (infixr "\<longleftrightarrow>" 25)
wenzelm@19656
   108
wenzelm@19656
   109
wenzelm@4868
   110
nonterminals
clasohm@923
   111
  letbinds  letbind
clasohm@923
   112
  case_syn  cases_syn
clasohm@923
   113
clasohm@923
   114
syntax
wenzelm@11432
   115
  "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
clasohm@923
   116
wenzelm@7357
   117
  "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
wenzelm@7357
   118
  ""            :: "letbind => letbinds"                 ("_")
wenzelm@7357
   119
  "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
wenzelm@7357
   120
  "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
clasohm@923
   121
wenzelm@9060
   122
  "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
wenzelm@9060
   123
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
wenzelm@7357
   124
  ""            :: "case_syn => cases_syn"               ("_")
wenzelm@9060
   125
  "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
clasohm@923
   126
clasohm@923
   127
translations
nipkow@13764
   128
  "THE x. P"              == "The (%x. P)"
clasohm@923
   129
  "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
nipkow@1114
   130
  "let x = a in e"        == "Let a (%x. e)"
clasohm@923
   131
nipkow@13763
   132
print_translation {*
nipkow@13763
   133
(* To avoid eta-contraction of body: *)
nipkow@13763
   134
[("The", fn [Abs abs] =>
nipkow@13763
   135
     let val (x,t) = atomic_abs_tr' abs
nipkow@13763
   136
     in Syntax.const "_The" $ x $ t end)]
nipkow@13763
   137
*}
nipkow@13763
   138
wenzelm@12114
   139
syntax (xsymbols)
wenzelm@11687
   140
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
wenzelm@2372
   141
wenzelm@21524
   142
notation (xsymbols)
wenzelm@21524
   143
  All  (binder "\<forall>" 10) and
wenzelm@21524
   144
  Ex  (binder "\<exists>" 10) and
wenzelm@21524
   145
  Ex1  (binder "\<exists>!" 10)
wenzelm@6340
   146
wenzelm@21524
   147
notation (HTML output)
wenzelm@21524
   148
  All  (binder "\<forall>" 10) and
wenzelm@21524
   149
  Ex  (binder "\<exists>" 10) and
wenzelm@21524
   150
  Ex1  (binder "\<exists>!" 10)
wenzelm@21524
   151
wenzelm@21524
   152
notation (HOL)
wenzelm@21524
   153
  All  (binder "! " 10) and
wenzelm@21524
   154
  Ex  (binder "? " 10) and
wenzelm@21524
   155
  Ex1  (binder "?! " 10)
wenzelm@7238
   156
wenzelm@7238
   157
wenzelm@11750
   158
subsubsection {* Axioms and basic definitions *}
wenzelm@2260
   159
wenzelm@7357
   160
axioms
paulson@15380
   161
  refl:           "t = (t::'a)"
haftmann@28513
   162
  subst:          "s = t \<Longrightarrow> P s \<Longrightarrow> P t"
paulson@15380
   163
  ext:            "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
paulson@15380
   164
    -- {*Extensionality is built into the meta-logic, and this rule expresses
paulson@15380
   165
         a related property.  It is an eta-expanded version of the traditional
paulson@15380
   166
         rule, and similar to the ABS rule of HOL*}
paulson@6289
   167
wenzelm@11432
   168
  the_eq_trivial: "(THE x. x = a) = (a::'a)"
clasohm@923
   169
paulson@15380
   170
  impI:           "(P ==> Q) ==> P-->Q"
paulson@15380
   171
  mp:             "[| P-->Q;  P |] ==> Q"
paulson@15380
   172
paulson@15380
   173
clasohm@923
   174
defs
wenzelm@7357
   175
  True_def:     "True      == ((%x::bool. x) = (%x. x))"
wenzelm@7357
   176
  All_def:      "All(P)    == (P = (%x. True))"
paulson@11451
   177
  Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
wenzelm@7357
   178
  False_def:    "False     == (!P. P)"
wenzelm@7357
   179
  not_def:      "~ P       == P-->False"
wenzelm@7357
   180
  and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
wenzelm@7357
   181
  or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
wenzelm@7357
   182
  Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
clasohm@923
   183
wenzelm@7357
   184
axioms
wenzelm@7357
   185
  iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
wenzelm@7357
   186
  True_or_False:  "(P=True) | (P=False)"
clasohm@923
   187
clasohm@923
   188
defs
haftmann@24219
   189
  Let_def:      "Let s f == f(s)"
paulson@11451
   190
  if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
wenzelm@5069
   191
skalberg@14223
   192
finalconsts
skalberg@14223
   193
  "op ="
skalberg@14223
   194
  "op -->"
skalberg@14223
   195
  The
nipkow@3320
   196
haftmann@22481
   197
axiomatization
haftmann@22481
   198
  undefined :: 'a
wenzelm@19656
   199
haftmann@28682
   200
abbreviation (input)
haftmann@28682
   201
  "arbitrary \<equiv> undefined"
haftmann@22481
   202
haftmann@22481
   203
haftmann@22481
   204
subsubsection {* Generic classes and algebraic operations *}
haftmann@22481
   205
haftmann@29608
   206
class default =
haftmann@24901
   207
  fixes default :: 'a
wenzelm@4793
   208
haftmann@29608
   209
class zero = 
haftmann@25062
   210
  fixes zero :: 'a  ("0")
haftmann@20713
   211
haftmann@29608
   212
class one =
haftmann@25062
   213
  fixes one  :: 'a  ("1")
haftmann@20713
   214
haftmann@20713
   215
hide (open) const zero one
wenzelm@11750
   216
haftmann@29608
   217
class plus =
haftmann@25062
   218
  fixes plus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "+" 65)
haftmann@20590
   219
haftmann@29608
   220
class minus =
haftmann@25762
   221
  fixes minus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "-" 65)
haftmann@25762
   222
haftmann@29608
   223
class uminus =
haftmann@25062
   224
  fixes uminus :: "'a \<Rightarrow> 'a"  ("- _" [81] 80)
haftmann@20590
   225
haftmann@29608
   226
class times =
haftmann@25062
   227
  fixes times :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "*" 70)
haftmann@20590
   228
haftmann@29608
   229
class inverse =
haftmann@20590
   230
  fixes inverse :: "'a \<Rightarrow> 'a"
haftmann@25062
   231
    and divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "'/" 70)
wenzelm@21524
   232
haftmann@29608
   233
class abs =
haftmann@23878
   234
  fixes abs :: "'a \<Rightarrow> 'a"
wenzelm@25388
   235
begin
haftmann@23878
   236
wenzelm@21524
   237
notation (xsymbols)
wenzelm@21524
   238
  abs  ("\<bar>_\<bar>")
wenzelm@25388
   239
wenzelm@21524
   240
notation (HTML output)
wenzelm@21524
   241
  abs  ("\<bar>_\<bar>")
wenzelm@11750
   242
wenzelm@25388
   243
end
wenzelm@25388
   244
haftmann@29608
   245
class sgn =
haftmann@25062
   246
  fixes sgn :: "'a \<Rightarrow> 'a"
haftmann@25062
   247
haftmann@29608
   248
class ord =
haftmann@24748
   249
  fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
haftmann@24748
   250
    and less :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
haftmann@23878
   251
begin
haftmann@23878
   252
haftmann@23878
   253
notation
haftmann@23878
   254
  less_eq  ("op <=") and
haftmann@23878
   255
  less_eq  ("(_/ <= _)" [51, 51] 50) and
haftmann@23878
   256
  less  ("op <") and
haftmann@23878
   257
  less  ("(_/ < _)"  [51, 51] 50)
haftmann@23878
   258
  
haftmann@23878
   259
notation (xsymbols)
haftmann@23878
   260
  less_eq  ("op \<le>") and
haftmann@23878
   261
  less_eq  ("(_/ \<le> _)"  [51, 51] 50)
haftmann@23878
   262
haftmann@23878
   263
notation (HTML output)
haftmann@23878
   264
  less_eq  ("op \<le>") and
haftmann@23878
   265
  less_eq  ("(_/ \<le> _)"  [51, 51] 50)
haftmann@23878
   266
wenzelm@25388
   267
abbreviation (input)
wenzelm@25388
   268
  greater_eq  (infix ">=" 50) where
wenzelm@25388
   269
  "x >= y \<equiv> y <= x"
wenzelm@25388
   270
haftmann@24842
   271
notation (input)
haftmann@23878
   272
  greater_eq  (infix "\<ge>" 50)
haftmann@23878
   273
wenzelm@25388
   274
abbreviation (input)
wenzelm@25388
   275
  greater  (infix ">" 50) where
wenzelm@25388
   276
  "x > y \<equiv> y < x"
wenzelm@25388
   277
wenzelm@25388
   278
end
wenzelm@25388
   279
wenzelm@13456
   280
syntax
wenzelm@13456
   281
  "_index1"  :: index    ("\<^sub>1")
wenzelm@13456
   282
translations
wenzelm@14690
   283
  (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
wenzelm@13456
   284
wenzelm@11750
   285
typed_print_translation {*
haftmann@20713
   286
let
haftmann@20713
   287
  fun tr' c = (c, fn show_sorts => fn T => fn ts =>
haftmann@29905
   288
    if (not o null) ts orelse T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
haftmann@20713
   289
    else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);
haftmann@22993
   290
in map tr' [@{const_syntax HOL.one}, @{const_syntax HOL.zero}] end;
wenzelm@11750
   291
*} -- {* show types that are presumably too general *}
wenzelm@11750
   292
wenzelm@11750
   293
haftmann@20944
   294
subsection {* Fundamental rules *}
haftmann@20944
   295
haftmann@20973
   296
subsubsection {* Equality *}
haftmann@20944
   297
wenzelm@18457
   298
lemma sym: "s = t ==> t = s"
wenzelm@18457
   299
  by (erule subst) (rule refl)
paulson@15411
   300
wenzelm@18457
   301
lemma ssubst: "t = s ==> P s ==> P t"
wenzelm@18457
   302
  by (drule sym) (erule subst)
paulson@15411
   303
paulson@15411
   304
lemma trans: "[| r=s; s=t |] ==> r=t"
wenzelm@18457
   305
  by (erule subst)
paulson@15411
   306
haftmann@20944
   307
lemma meta_eq_to_obj_eq: 
haftmann@20944
   308
  assumes meq: "A == B"
haftmann@20944
   309
  shows "A = B"
haftmann@20944
   310
  by (unfold meq) (rule refl)
paulson@15411
   311
wenzelm@21502
   312
text {* Useful with @{text erule} for proving equalities from known equalities. *}
haftmann@20944
   313
     (* a = b
paulson@15411
   314
        |   |
paulson@15411
   315
        c = d   *)
paulson@15411
   316
lemma box_equals: "[| a=b;  a=c;  b=d |] ==> c=d"
paulson@15411
   317
apply (rule trans)
paulson@15411
   318
apply (rule trans)
paulson@15411
   319
apply (rule sym)
paulson@15411
   320
apply assumption+
paulson@15411
   321
done
paulson@15411
   322
nipkow@15524
   323
text {* For calculational reasoning: *}
nipkow@15524
   324
nipkow@15524
   325
lemma forw_subst: "a = b ==> P b ==> P a"
nipkow@15524
   326
  by (rule ssubst)
nipkow@15524
   327
nipkow@15524
   328
lemma back_subst: "P a ==> a = b ==> P b"
nipkow@15524
   329
  by (rule subst)
nipkow@15524
   330
paulson@15411
   331
haftmann@20944
   332
subsubsection {*Congruence rules for application*}
paulson@15411
   333
paulson@15411
   334
(*similar to AP_THM in Gordon's HOL*)
paulson@15411
   335
lemma fun_cong: "(f::'a=>'b) = g ==> f(x)=g(x)"
paulson@15411
   336
apply (erule subst)
paulson@15411
   337
apply (rule refl)
paulson@15411
   338
done
paulson@15411
   339
paulson@15411
   340
(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)
paulson@15411
   341
lemma arg_cong: "x=y ==> f(x)=f(y)"
paulson@15411
   342
apply (erule subst)
paulson@15411
   343
apply (rule refl)
paulson@15411
   344
done
paulson@15411
   345
paulson@15655
   346
lemma arg_cong2: "\<lbrakk> a = b; c = d \<rbrakk> \<Longrightarrow> f a c = f b d"
paulson@15655
   347
apply (erule ssubst)+
paulson@15655
   348
apply (rule refl)
paulson@15655
   349
done
paulson@15655
   350
paulson@15411
   351
lemma cong: "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"
paulson@15411
   352
apply (erule subst)+
paulson@15411
   353
apply (rule refl)
paulson@15411
   354
done
paulson@15411
   355
paulson@15411
   356
haftmann@20944
   357
subsubsection {*Equality of booleans -- iff*}
paulson@15411
   358
wenzelm@21504
   359
lemma iffI: assumes "P ==> Q" and "Q ==> P" shows "P=Q"
wenzelm@21504
   360
  by (iprover intro: iff [THEN mp, THEN mp] impI assms)
paulson@15411
   361
paulson@15411
   362
lemma iffD2: "[| P=Q; Q |] ==> P"
wenzelm@18457
   363
  by (erule ssubst)
paulson@15411
   364
paulson@15411
   365
lemma rev_iffD2: "[| Q; P=Q |] ==> P"
wenzelm@18457
   366
  by (erule iffD2)
paulson@15411
   367
wenzelm@21504
   368
lemma iffD1: "Q = P \<Longrightarrow> Q \<Longrightarrow> P"
wenzelm@21504
   369
  by (drule sym) (rule iffD2)
wenzelm@21504
   370
wenzelm@21504
   371
lemma rev_iffD1: "Q \<Longrightarrow> Q = P \<Longrightarrow> P"
wenzelm@21504
   372
  by (drule sym) (rule rev_iffD2)
paulson@15411
   373
paulson@15411
   374
lemma iffE:
paulson@15411
   375
  assumes major: "P=Q"
wenzelm@21504
   376
    and minor: "[| P --> Q; Q --> P |] ==> R"
wenzelm@18457
   377
  shows R
wenzelm@18457
   378
  by (iprover intro: minor impI major [THEN iffD2] major [THEN iffD1])
paulson@15411
   379
paulson@15411
   380
haftmann@20944
   381
subsubsection {*True*}
paulson@15411
   382
paulson@15411
   383
lemma TrueI: "True"
wenzelm@21504
   384
  unfolding True_def by (rule refl)
paulson@15411
   385
wenzelm@21504
   386
lemma eqTrueI: "P ==> P = True"
wenzelm@18457
   387
  by (iprover intro: iffI TrueI)
paulson@15411
   388
wenzelm@21504
   389
lemma eqTrueE: "P = True ==> P"
wenzelm@21504
   390
  by (erule iffD2) (rule TrueI)
paulson@15411
   391
paulson@15411
   392
haftmann@20944
   393
subsubsection {*Universal quantifier*}
paulson@15411
   394
wenzelm@21504
   395
lemma allI: assumes "!!x::'a. P(x)" shows "ALL x. P(x)"
wenzelm@21504
   396
  unfolding All_def by (iprover intro: ext eqTrueI assms)
paulson@15411
   397
paulson@15411
   398
lemma spec: "ALL x::'a. P(x) ==> P(x)"
paulson@15411
   399
apply (unfold All_def)
paulson@15411
   400
apply (rule eqTrueE)
paulson@15411
   401
apply (erule fun_cong)
paulson@15411
   402
done
paulson@15411
   403
paulson@15411
   404
lemma allE:
paulson@15411
   405
  assumes major: "ALL x. P(x)"
wenzelm@21504
   406
    and minor: "P(x) ==> R"
wenzelm@21504
   407
  shows R
wenzelm@21504
   408
  by (iprover intro: minor major [THEN spec])
paulson@15411
   409
paulson@15411
   410
lemma all_dupE:
paulson@15411
   411
  assumes major: "ALL x. P(x)"
wenzelm@21504
   412
    and minor: "[| P(x); ALL x. P(x) |] ==> R"
wenzelm@21504
   413
  shows R
wenzelm@21504
   414
  by (iprover intro: minor major major [THEN spec])
paulson@15411
   415
paulson@15411
   416
wenzelm@21504
   417
subsubsection {* False *}
wenzelm@21504
   418
wenzelm@21504
   419
text {*
wenzelm@21504
   420
  Depends upon @{text spec}; it is impossible to do propositional
wenzelm@21504
   421
  logic before quantifiers!
wenzelm@21504
   422
*}
paulson@15411
   423
paulson@15411
   424
lemma FalseE: "False ==> P"
wenzelm@21504
   425
  apply (unfold False_def)
wenzelm@21504
   426
  apply (erule spec)
wenzelm@21504
   427
  done
paulson@15411
   428
wenzelm@21504
   429
lemma False_neq_True: "False = True ==> P"
wenzelm@21504
   430
  by (erule eqTrueE [THEN FalseE])
paulson@15411
   431
paulson@15411
   432
wenzelm@21504
   433
subsubsection {* Negation *}
paulson@15411
   434
paulson@15411
   435
lemma notI:
wenzelm@21504
   436
  assumes "P ==> False"
paulson@15411
   437
  shows "~P"
wenzelm@21504
   438
  apply (unfold not_def)
wenzelm@21504
   439
  apply (iprover intro: impI assms)
wenzelm@21504
   440
  done
paulson@15411
   441
paulson@15411
   442
lemma False_not_True: "False ~= True"
wenzelm@21504
   443
  apply (rule notI)
wenzelm@21504
   444
  apply (erule False_neq_True)
wenzelm@21504
   445
  done
paulson@15411
   446
paulson@15411
   447
lemma True_not_False: "True ~= False"
wenzelm@21504
   448
  apply (rule notI)
wenzelm@21504
   449
  apply (drule sym)
wenzelm@21504
   450
  apply (erule False_neq_True)
wenzelm@21504
   451
  done
paulson@15411
   452
paulson@15411
   453
lemma notE: "[| ~P;  P |] ==> R"
wenzelm@21504
   454
  apply (unfold not_def)
wenzelm@21504
   455
  apply (erule mp [THEN FalseE])
wenzelm@21504
   456
  apply assumption
wenzelm@21504
   457
  done
paulson@15411
   458
wenzelm@21504
   459
lemma notI2: "(P \<Longrightarrow> \<not> Pa) \<Longrightarrow> (P \<Longrightarrow> Pa) \<Longrightarrow> \<not> P"
wenzelm@21504
   460
  by (erule notE [THEN notI]) (erule meta_mp)
paulson@15411
   461
paulson@15411
   462
haftmann@20944
   463
subsubsection {*Implication*}
paulson@15411
   464
paulson@15411
   465
lemma impE:
paulson@15411
   466
  assumes "P-->Q" "P" "Q ==> R"
paulson@15411
   467
  shows "R"
wenzelm@23553
   468
by (iprover intro: assms mp)
paulson@15411
   469
paulson@15411
   470
(* Reduces Q to P-->Q, allowing substitution in P. *)
paulson@15411
   471
lemma rev_mp: "[| P;  P --> Q |] ==> Q"
nipkow@17589
   472
by (iprover intro: mp)
paulson@15411
   473
paulson@15411
   474
lemma contrapos_nn:
paulson@15411
   475
  assumes major: "~Q"
paulson@15411
   476
      and minor: "P==>Q"
paulson@15411
   477
  shows "~P"
nipkow@17589
   478
by (iprover intro: notI minor major [THEN notE])
paulson@15411
   479
paulson@15411
   480
(*not used at all, but we already have the other 3 combinations *)
paulson@15411
   481
lemma contrapos_pn:
paulson@15411
   482
  assumes major: "Q"
paulson@15411
   483
      and minor: "P ==> ~Q"
paulson@15411
   484
  shows "~P"
nipkow@17589
   485
by (iprover intro: notI minor major notE)
paulson@15411
   486
paulson@15411
   487
lemma not_sym: "t ~= s ==> s ~= t"
haftmann@21250
   488
  by (erule contrapos_nn) (erule sym)
haftmann@21250
   489
haftmann@21250
   490
lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y"
haftmann@21250
   491
  by (erule subst, erule ssubst, assumption)
paulson@15411
   492
paulson@15411
   493
(*still used in HOLCF*)
paulson@15411
   494
lemma rev_contrapos:
paulson@15411
   495
  assumes pq: "P ==> Q"
paulson@15411
   496
      and nq: "~Q"
paulson@15411
   497
  shows "~P"
paulson@15411
   498
apply (rule nq [THEN contrapos_nn])
paulson@15411
   499
apply (erule pq)
paulson@15411
   500
done
paulson@15411
   501
haftmann@20944
   502
subsubsection {*Existential quantifier*}
paulson@15411
   503
paulson@15411
   504
lemma exI: "P x ==> EX x::'a. P x"
paulson@15411
   505
apply (unfold Ex_def)
nipkow@17589
   506
apply (iprover intro: allI allE impI mp)
paulson@15411
   507
done
paulson@15411
   508
paulson@15411
   509
lemma exE:
paulson@15411
   510
  assumes major: "EX x::'a. P(x)"
paulson@15411
   511
      and minor: "!!x. P(x) ==> Q"
paulson@15411
   512
  shows "Q"
paulson@15411
   513
apply (rule major [unfolded Ex_def, THEN spec, THEN mp])
nipkow@17589
   514
apply (iprover intro: impI [THEN allI] minor)
paulson@15411
   515
done
paulson@15411
   516
paulson@15411
   517
haftmann@20944
   518
subsubsection {*Conjunction*}
paulson@15411
   519
paulson@15411
   520
lemma conjI: "[| P; Q |] ==> P&Q"
paulson@15411
   521
apply (unfold and_def)
nipkow@17589
   522
apply (iprover intro: impI [THEN allI] mp)
paulson@15411
   523
done
paulson@15411
   524
paulson@15411
   525
lemma conjunct1: "[| P & Q |] ==> P"
paulson@15411
   526
apply (unfold and_def)
nipkow@17589
   527
apply (iprover intro: impI dest: spec mp)
paulson@15411
   528
done
paulson@15411
   529
paulson@15411
   530
lemma conjunct2: "[| P & Q |] ==> Q"
paulson@15411
   531
apply (unfold and_def)
nipkow@17589
   532
apply (iprover intro: impI dest: spec mp)
paulson@15411
   533
done
paulson@15411
   534
paulson@15411
   535
lemma conjE:
paulson@15411
   536
  assumes major: "P&Q"
paulson@15411
   537
      and minor: "[| P; Q |] ==> R"
paulson@15411
   538
  shows "R"
paulson@15411
   539
apply (rule minor)
paulson@15411
   540
apply (rule major [THEN conjunct1])
paulson@15411
   541
apply (rule major [THEN conjunct2])
paulson@15411
   542
done
paulson@15411
   543
paulson@15411
   544
lemma context_conjI:
wenzelm@23553
   545
  assumes "P" "P ==> Q" shows "P & Q"
wenzelm@23553
   546
by (iprover intro: conjI assms)
paulson@15411
   547
paulson@15411
   548
haftmann@20944
   549
subsubsection {*Disjunction*}
paulson@15411
   550
paulson@15411
   551
lemma disjI1: "P ==> P|Q"
paulson@15411
   552
apply (unfold or_def)
nipkow@17589
   553
apply (iprover intro: allI impI mp)
paulson@15411
   554
done
paulson@15411
   555
paulson@15411
   556
lemma disjI2: "Q ==> P|Q"
paulson@15411
   557
apply (unfold or_def)
nipkow@17589
   558
apply (iprover intro: allI impI mp)
paulson@15411
   559
done
paulson@15411
   560
paulson@15411
   561
lemma disjE:
paulson@15411
   562
  assumes major: "P|Q"
paulson@15411
   563
      and minorP: "P ==> R"
paulson@15411
   564
      and minorQ: "Q ==> R"
paulson@15411
   565
  shows "R"
nipkow@17589
   566
by (iprover intro: minorP minorQ impI
paulson@15411
   567
                 major [unfolded or_def, THEN spec, THEN mp, THEN mp])
paulson@15411
   568
paulson@15411
   569
haftmann@20944
   570
subsubsection {*Classical logic*}
paulson@15411
   571
paulson@15411
   572
lemma classical:
paulson@15411
   573
  assumes prem: "~P ==> P"
paulson@15411
   574
  shows "P"
paulson@15411
   575
apply (rule True_or_False [THEN disjE, THEN eqTrueE])
paulson@15411
   576
apply assumption
paulson@15411
   577
apply (rule notI [THEN prem, THEN eqTrueI])
paulson@15411
   578
apply (erule subst)
paulson@15411
   579
apply assumption
paulson@15411
   580
done
paulson@15411
   581
paulson@15411
   582
lemmas ccontr = FalseE [THEN classical, standard]
paulson@15411
   583
paulson@15411
   584
(*notE with premises exchanged; it discharges ~R so that it can be used to
paulson@15411
   585
  make elimination rules*)
paulson@15411
   586
lemma rev_notE:
paulson@15411
   587
  assumes premp: "P"
paulson@15411
   588
      and premnot: "~R ==> ~P"
paulson@15411
   589
  shows "R"
paulson@15411
   590
apply (rule ccontr)
paulson@15411
   591
apply (erule notE [OF premnot premp])
paulson@15411
   592
done
paulson@15411
   593
paulson@15411
   594
(*Double negation law*)
paulson@15411
   595
lemma notnotD: "~~P ==> P"
paulson@15411
   596
apply (rule classical)
paulson@15411
   597
apply (erule notE)
paulson@15411
   598
apply assumption
paulson@15411
   599
done
paulson@15411
   600
paulson@15411
   601
lemma contrapos_pp:
paulson@15411
   602
  assumes p1: "Q"
paulson@15411
   603
      and p2: "~P ==> ~Q"
paulson@15411
   604
  shows "P"
nipkow@17589
   605
by (iprover intro: classical p1 p2 notE)
paulson@15411
   606
paulson@15411
   607
haftmann@20944
   608
subsubsection {*Unique existence*}
paulson@15411
   609
paulson@15411
   610
lemma ex1I:
wenzelm@23553
   611
  assumes "P a" "!!x. P(x) ==> x=a"
paulson@15411
   612
  shows "EX! x. P(x)"
wenzelm@23553
   613
by (unfold Ex1_def, iprover intro: assms exI conjI allI impI)
paulson@15411
   614
paulson@15411
   615
text{*Sometimes easier to use: the premises have no shared variables.  Safe!*}
paulson@15411
   616
lemma ex_ex1I:
paulson@15411
   617
  assumes ex_prem: "EX x. P(x)"
paulson@15411
   618
      and eq: "!!x y. [| P(x); P(y) |] ==> x=y"
paulson@15411
   619
  shows "EX! x. P(x)"
nipkow@17589
   620
by (iprover intro: ex_prem [THEN exE] ex1I eq)
paulson@15411
   621
paulson@15411
   622
lemma ex1E:
paulson@15411
   623
  assumes major: "EX! x. P(x)"
paulson@15411
   624
      and minor: "!!x. [| P(x);  ALL y. P(y) --> y=x |] ==> R"
paulson@15411
   625
  shows "R"
paulson@15411
   626
apply (rule major [unfolded Ex1_def, THEN exE])
paulson@15411
   627
apply (erule conjE)
nipkow@17589
   628
apply (iprover intro: minor)
paulson@15411
   629
done
paulson@15411
   630
paulson@15411
   631
lemma ex1_implies_ex: "EX! x. P x ==> EX x. P x"
paulson@15411
   632
apply (erule ex1E)
paulson@15411
   633
apply (rule exI)
paulson@15411
   634
apply assumption
paulson@15411
   635
done
paulson@15411
   636
paulson@15411
   637
haftmann@20944
   638
subsubsection {*THE: definite description operator*}
paulson@15411
   639
paulson@15411
   640
lemma the_equality:
paulson@15411
   641
  assumes prema: "P a"
paulson@15411
   642
      and premx: "!!x. P x ==> x=a"
paulson@15411
   643
  shows "(THE x. P x) = a"
paulson@15411
   644
apply (rule trans [OF _ the_eq_trivial])
paulson@15411
   645
apply (rule_tac f = "The" in arg_cong)
paulson@15411
   646
apply (rule ext)
paulson@15411
   647
apply (rule iffI)
paulson@15411
   648
 apply (erule premx)
paulson@15411
   649
apply (erule ssubst, rule prema)
paulson@15411
   650
done
paulson@15411
   651
paulson@15411
   652
lemma theI:
paulson@15411
   653
  assumes "P a" and "!!x. P x ==> x=a"
paulson@15411
   654
  shows "P (THE x. P x)"
wenzelm@23553
   655
by (iprover intro: assms the_equality [THEN ssubst])
paulson@15411
   656
paulson@15411
   657
lemma theI': "EX! x. P x ==> P (THE x. P x)"
paulson@15411
   658
apply (erule ex1E)
paulson@15411
   659
apply (erule theI)
paulson@15411
   660
apply (erule allE)
paulson@15411
   661
apply (erule mp)
paulson@15411
   662
apply assumption
paulson@15411
   663
done
paulson@15411
   664
paulson@15411
   665
(*Easier to apply than theI: only one occurrence of P*)
paulson@15411
   666
lemma theI2:
paulson@15411
   667
  assumes "P a" "!!x. P x ==> x=a" "!!x. P x ==> Q x"
paulson@15411
   668
  shows "Q (THE x. P x)"
wenzelm@23553
   669
by (iprover intro: assms theI)
paulson@15411
   670
nipkow@24553
   671
lemma the1I2: assumes "EX! x. P x" "\<And>x. P x \<Longrightarrow> Q x" shows "Q (THE x. P x)"
nipkow@24553
   672
by(iprover intro:assms(2) theI2[where P=P and Q=Q] ex1E[OF assms(1)]
nipkow@24553
   673
           elim:allE impE)
nipkow@24553
   674
wenzelm@18697
   675
lemma the1_equality [elim?]: "[| EX!x. P x; P a |] ==> (THE x. P x) = a"
paulson@15411
   676
apply (rule the_equality)
paulson@15411
   677
apply  assumption
paulson@15411
   678
apply (erule ex1E)
paulson@15411
   679
apply (erule all_dupE)
paulson@15411
   680
apply (drule mp)
paulson@15411
   681
apply  assumption
paulson@15411
   682
apply (erule ssubst)
paulson@15411
   683
apply (erule allE)
paulson@15411
   684
apply (erule mp)
paulson@15411
   685
apply assumption
paulson@15411
   686
done
paulson@15411
   687
paulson@15411
   688
lemma the_sym_eq_trivial: "(THE y. x=y) = x"
paulson@15411
   689
apply (rule the_equality)
paulson@15411
   690
apply (rule refl)
paulson@15411
   691
apply (erule sym)
paulson@15411
   692
done
paulson@15411
   693
paulson@15411
   694
haftmann@20944
   695
subsubsection {*Classical intro rules for disjunction and existential quantifiers*}
paulson@15411
   696
paulson@15411
   697
lemma disjCI:
paulson@15411
   698
  assumes "~Q ==> P" shows "P|Q"
paulson@15411
   699
apply (rule classical)
wenzelm@23553
   700
apply (iprover intro: assms disjI1 disjI2 notI elim: notE)
paulson@15411
   701
done
paulson@15411
   702
paulson@15411
   703
lemma excluded_middle: "~P | P"
nipkow@17589
   704
by (iprover intro: disjCI)
paulson@15411
   705
haftmann@20944
   706
text {*
haftmann@20944
   707
  case distinction as a natural deduction rule.
haftmann@20944
   708
  Note that @{term "~P"} is the second case, not the first
haftmann@20944
   709
*}
wenzelm@27126
   710
lemma case_split [case_names True False]:
paulson@15411
   711
  assumes prem1: "P ==> Q"
paulson@15411
   712
      and prem2: "~P ==> Q"
paulson@15411
   713
  shows "Q"
paulson@15411
   714
apply (rule excluded_middle [THEN disjE])
paulson@15411
   715
apply (erule prem2)
paulson@15411
   716
apply (erule prem1)
paulson@15411
   717
done
wenzelm@27126
   718
paulson@15411
   719
(*Classical implies (-->) elimination. *)
paulson@15411
   720
lemma impCE:
paulson@15411
   721
  assumes major: "P-->Q"
paulson@15411
   722
      and minor: "~P ==> R" "Q ==> R"
paulson@15411
   723
  shows "R"
paulson@15411
   724
apply (rule excluded_middle [of P, THEN disjE])
nipkow@17589
   725
apply (iprover intro: minor major [THEN mp])+
paulson@15411
   726
done
paulson@15411
   727
paulson@15411
   728
(*This version of --> elimination works on Q before P.  It works best for
paulson@15411
   729
  those cases in which P holds "almost everywhere".  Can't install as
paulson@15411
   730
  default: would break old proofs.*)
paulson@15411
   731
lemma impCE':
paulson@15411
   732
  assumes major: "P-->Q"
paulson@15411
   733
      and minor: "Q ==> R" "~P ==> R"
paulson@15411
   734
  shows "R"
paulson@15411
   735
apply (rule excluded_middle [of P, THEN disjE])
nipkow@17589
   736
apply (iprover intro: minor major [THEN mp])+
paulson@15411
   737
done
paulson@15411
   738
paulson@15411
   739
(*Classical <-> elimination. *)
paulson@15411
   740
lemma iffCE:
paulson@15411
   741
  assumes major: "P=Q"
paulson@15411
   742
      and minor: "[| P; Q |] ==> R"  "[| ~P; ~Q |] ==> R"
paulson@15411
   743
  shows "R"
paulson@15411
   744
apply (rule major [THEN iffE])
nipkow@17589
   745
apply (iprover intro: minor elim: impCE notE)
paulson@15411
   746
done
paulson@15411
   747
paulson@15411
   748
lemma exCI:
paulson@15411
   749
  assumes "ALL x. ~P(x) ==> P(a)"
paulson@15411
   750
  shows "EX x. P(x)"
paulson@15411
   751
apply (rule ccontr)
wenzelm@23553
   752
apply (iprover intro: assms exI allI notI notE [of "\<exists>x. P x"])
paulson@15411
   753
done
paulson@15411
   754
paulson@15411
   755
wenzelm@12386
   756
subsubsection {* Intuitionistic Reasoning *}
wenzelm@12386
   757
wenzelm@12386
   758
lemma impE':
wenzelm@12937
   759
  assumes 1: "P --> Q"
wenzelm@12937
   760
    and 2: "Q ==> R"
wenzelm@12937
   761
    and 3: "P --> Q ==> P"
wenzelm@12937
   762
  shows R
wenzelm@12386
   763
proof -
wenzelm@12386
   764
  from 3 and 1 have P .
wenzelm@12386
   765
  with 1 have Q by (rule impE)
wenzelm@12386
   766
  with 2 show R .
wenzelm@12386
   767
qed
wenzelm@12386
   768
wenzelm@12386
   769
lemma allE':
wenzelm@12937
   770
  assumes 1: "ALL x. P x"
wenzelm@12937
   771
    and 2: "P x ==> ALL x. P x ==> Q"
wenzelm@12937
   772
  shows Q
wenzelm@12386
   773
proof -
wenzelm@12386
   774
  from 1 have "P x" by (rule spec)
wenzelm@12386
   775
  from this and 1 show Q by (rule 2)
wenzelm@12386
   776
qed
wenzelm@12386
   777
wenzelm@12937
   778
lemma notE':
wenzelm@12937
   779
  assumes 1: "~ P"
wenzelm@12937
   780
    and 2: "~ P ==> P"
wenzelm@12937
   781
  shows R
wenzelm@12386
   782
proof -
wenzelm@12386
   783
  from 2 and 1 have P .
wenzelm@12386
   784
  with 1 show R by (rule notE)
wenzelm@12386
   785
qed
wenzelm@12386
   786
dixon@22444
   787
lemma TrueE: "True ==> P ==> P" .
dixon@22444
   788
lemma notFalseE: "~ False ==> P ==> P" .
dixon@22444
   789
dixon@22467
   790
lemmas [Pure.elim!] = disjE iffE FalseE conjE exE TrueE notFalseE
wenzelm@15801
   791
  and [Pure.intro!] = iffI conjI impI TrueI notI allI refl
wenzelm@15801
   792
  and [Pure.elim 2] = allE notE' impE'
wenzelm@15801
   793
  and [Pure.intro] = exI disjI2 disjI1
wenzelm@12386
   794
wenzelm@12386
   795
lemmas [trans] = trans
wenzelm@12386
   796
  and [sym] = sym not_sym
wenzelm@15801
   797
  and [Pure.elim?] = iffD1 iffD2 impE
wenzelm@11438
   798
haftmann@28952
   799
use "Tools/hologic.ML"
wenzelm@23553
   800
wenzelm@11750
   801
wenzelm@11750
   802
subsubsection {* Atomizing meta-level connectives *}
wenzelm@11750
   803
haftmann@28513
   804
axiomatization where
haftmann@28513
   805
  eq_reflection: "x = y \<Longrightarrow> x \<equiv> y" (*admissible axiom*)
haftmann@28513
   806
wenzelm@11750
   807
lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
wenzelm@12003
   808
proof
wenzelm@9488
   809
  assume "!!x. P x"
wenzelm@23389
   810
  then show "ALL x. P x" ..
wenzelm@9488
   811
next
wenzelm@9488
   812
  assume "ALL x. P x"
wenzelm@23553
   813
  then show "!!x. P x" by (rule allE)
wenzelm@9488
   814
qed
wenzelm@9488
   815
wenzelm@11750
   816
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
wenzelm@12003
   817
proof
wenzelm@9488
   818
  assume r: "A ==> B"
wenzelm@10383
   819
  show "A --> B" by (rule impI) (rule r)
wenzelm@9488
   820
next
wenzelm@9488
   821
  assume "A --> B" and A
wenzelm@23553
   822
  then show B by (rule mp)
wenzelm@9488
   823
qed
wenzelm@9488
   824
paulson@14749
   825
lemma atomize_not: "(A ==> False) == Trueprop (~A)"
paulson@14749
   826
proof
paulson@14749
   827
  assume r: "A ==> False"
paulson@14749
   828
  show "~A" by (rule notI) (rule r)
paulson@14749
   829
next
paulson@14749
   830
  assume "~A" and A
wenzelm@23553
   831
  then show False by (rule notE)
paulson@14749
   832
qed
paulson@14749
   833
wenzelm@11750
   834
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
wenzelm@12003
   835
proof
wenzelm@10432
   836
  assume "x == y"
wenzelm@23553
   837
  show "x = y" by (unfold `x == y`) (rule refl)
wenzelm@10432
   838
next
wenzelm@10432
   839
  assume "x = y"
wenzelm@23553
   840
  then show "x == y" by (rule eq_reflection)
wenzelm@10432
   841
qed
wenzelm@10432
   842
wenzelm@28856
   843
lemma atomize_conj [atomize]: "(A &&& B) == Trueprop (A & B)"
wenzelm@12003
   844
proof
wenzelm@28856
   845
  assume conj: "A &&& B"
wenzelm@19121
   846
  show "A & B"
wenzelm@19121
   847
  proof (rule conjI)
wenzelm@19121
   848
    from conj show A by (rule conjunctionD1)
wenzelm@19121
   849
    from conj show B by (rule conjunctionD2)
wenzelm@19121
   850
  qed
wenzelm@11953
   851
next
wenzelm@19121
   852
  assume conj: "A & B"
wenzelm@28856
   853
  show "A &&& B"
wenzelm@19121
   854
  proof -
wenzelm@19121
   855
    from conj show A ..
wenzelm@19121
   856
    from conj show B ..
wenzelm@11953
   857
  qed
wenzelm@11953
   858
qed
wenzelm@11953
   859
wenzelm@12386
   860
lemmas [symmetric, rulify] = atomize_all atomize_imp
wenzelm@18832
   861
  and [symmetric, defn] = atomize_all atomize_imp atomize_eq
wenzelm@12386
   862
wenzelm@11750
   863
krauss@26580
   864
subsubsection {* Atomizing elimination rules *}
krauss@26580
   865
krauss@26580
   866
setup AtomizeElim.setup
krauss@26580
   867
krauss@26580
   868
lemma atomize_exL[atomize_elim]: "(!!x. P x ==> Q) == ((EX x. P x) ==> Q)"
krauss@26580
   869
  by rule iprover+
krauss@26580
   870
krauss@26580
   871
lemma atomize_conjL[atomize_elim]: "(A ==> B ==> C) == (A & B ==> C)"
krauss@26580
   872
  by rule iprover+
krauss@26580
   873
krauss@26580
   874
lemma atomize_disjL[atomize_elim]: "((A ==> C) ==> (B ==> C) ==> C) == ((A | B ==> C) ==> C)"
krauss@26580
   875
  by rule iprover+
krauss@26580
   876
krauss@26580
   877
lemma atomize_elimL[atomize_elim]: "(!!B. (A ==> B) ==> B) == Trueprop A" ..
krauss@26580
   878
krauss@26580
   879
haftmann@20944
   880
subsection {* Package setup *}
haftmann@20944
   881
wenzelm@11750
   882
subsubsection {* Classical Reasoner setup *}
wenzelm@9529
   883
wenzelm@26411
   884
lemma imp_elim: "P --> Q ==> (~ R ==> P) ==> (Q ==> R) ==> R"
wenzelm@26411
   885
  by (rule classical) iprover
wenzelm@26411
   886
wenzelm@26411
   887
lemma swap: "~ P ==> (~ R ==> P) ==> R"
wenzelm@26411
   888
  by (rule classical) iprover
wenzelm@26411
   889
haftmann@20944
   890
lemma thin_refl:
haftmann@20944
   891
  "\<And>X. \<lbrakk> x=x; PROP W \<rbrakk> \<Longrightarrow> PROP W" .
haftmann@20944
   892
haftmann@21151
   893
ML {*
haftmann@21151
   894
structure Hypsubst = HypsubstFun(
haftmann@21151
   895
struct
haftmann@21151
   896
  structure Simplifier = Simplifier
wenzelm@21218
   897
  val dest_eq = HOLogic.dest_eq
haftmann@21151
   898
  val dest_Trueprop = HOLogic.dest_Trueprop
haftmann@21151
   899
  val dest_imp = HOLogic.dest_imp
wenzelm@26411
   900
  val eq_reflection = @{thm eq_reflection}
wenzelm@26411
   901
  val rev_eq_reflection = @{thm meta_eq_to_obj_eq}
wenzelm@26411
   902
  val imp_intr = @{thm impI}
wenzelm@26411
   903
  val rev_mp = @{thm rev_mp}
wenzelm@26411
   904
  val subst = @{thm subst}
wenzelm@26411
   905
  val sym = @{thm sym}
wenzelm@22129
   906
  val thin_refl = @{thm thin_refl};
krauss@27572
   907
  val prop_subst = @{lemma "PROP P t ==> PROP prop (x = t ==> PROP P x)"
krauss@27572
   908
                     by (unfold prop_def) (drule eq_reflection, unfold)}
haftmann@21151
   909
end);
wenzelm@21671
   910
open Hypsubst;
haftmann@21151
   911
haftmann@21151
   912
structure Classical = ClassicalFun(
haftmann@21151
   913
struct
wenzelm@26411
   914
  val imp_elim = @{thm imp_elim}
wenzelm@26411
   915
  val not_elim = @{thm notE}
wenzelm@26411
   916
  val swap = @{thm swap}
wenzelm@26411
   917
  val classical = @{thm classical}
haftmann@21151
   918
  val sizef = Drule.size_of_thm
haftmann@21151
   919
  val hyp_subst_tacs = [Hypsubst.hyp_subst_tac]
haftmann@21151
   920
end);
haftmann@21151
   921
haftmann@21151
   922
structure BasicClassical: BASIC_CLASSICAL = Classical; 
wenzelm@21671
   923
open BasicClassical;
wenzelm@22129
   924
wenzelm@27338
   925
ML_Antiquote.value "claset"
wenzelm@27338
   926
  (Scan.succeed "Classical.local_claset_of (ML_Context.the_local_context ())");
wenzelm@24035
   927
wenzelm@24035
   928
structure ResAtpset = NamedThmsFun(val name = "atp" val description = "ATP rules");
paulson@24286
   929
blanchet@29806
   930
structure ResBlacklist = NamedThmsFun(val name = "noatp" val description = "theorems blacklisted for ATP");
haftmann@21151
   931
*}
haftmann@21151
   932
wenzelm@25388
   933
text {*ResBlacklist holds theorems blacklisted to sledgehammer. 
paulson@24286
   934
  These theorems typically produce clauses that are prolific (match too many equality or
wenzelm@25388
   935
  membership literals) and relate to seldom-used facts. Some duplicate other rules.*}
paulson@24286
   936
haftmann@21009
   937
setup {*
haftmann@21009
   938
let
haftmann@21009
   939
  (*prevent substitution on bool*)
haftmann@21009
   940
  fun hyp_subst_tac' i thm = if i <= Thm.nprems_of thm andalso
haftmann@21009
   941
    Term.exists_Const (fn ("op =", Type (_, [T, _])) => T <> Type ("bool", []) | _ => false)
haftmann@21009
   942
      (nth (Thm.prems_of thm) (i - 1)) then Hypsubst.hyp_subst_tac i thm else no_tac thm;
haftmann@21009
   943
in
haftmann@21151
   944
  Hypsubst.hypsubst_setup
haftmann@21151
   945
  #> ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac)
haftmann@21151
   946
  #> Classical.setup
haftmann@21151
   947
  #> ResAtpset.setup
paulson@24286
   948
  #> ResBlacklist.setup
haftmann@21009
   949
end
haftmann@21009
   950
*}
haftmann@21009
   951
haftmann@21009
   952
declare iffI [intro!]
haftmann@21009
   953
  and notI [intro!]
haftmann@21009
   954
  and impI [intro!]
haftmann@21009
   955
  and disjCI [intro!]
haftmann@21009
   956
  and conjI [intro!]
haftmann@21009
   957
  and TrueI [intro!]
haftmann@21009
   958
  and refl [intro!]
haftmann@21009
   959
haftmann@21009
   960
declare iffCE [elim!]
haftmann@21009
   961
  and FalseE [elim!]
haftmann@21009
   962
  and impCE [elim!]
haftmann@21009
   963
  and disjE [elim!]
haftmann@21009
   964
  and conjE [elim!]
haftmann@21009
   965
  and conjE [elim!]
haftmann@21009
   966
haftmann@21009
   967
declare ex_ex1I [intro!]
haftmann@21009
   968
  and allI [intro!]
haftmann@21009
   969
  and the_equality [intro]
haftmann@21009
   970
  and exI [intro]
haftmann@21009
   971
haftmann@21009
   972
declare exE [elim!]
haftmann@21009
   973
  allE [elim]
haftmann@21009
   974
wenzelm@22377
   975
ML {* val HOL_cs = @{claset} *}
wenzelm@11977
   976
wenzelm@20223
   977
lemma contrapos_np: "~ Q ==> (~ P ==> Q) ==> P"
wenzelm@20223
   978
  apply (erule swap)
wenzelm@20223
   979
  apply (erule (1) meta_mp)
wenzelm@20223
   980
  done
wenzelm@10383
   981
wenzelm@18689
   982
declare ex_ex1I [rule del, intro! 2]
wenzelm@18689
   983
  and ex1I [intro]
wenzelm@18689
   984
wenzelm@12386
   985
lemmas [intro?] = ext
wenzelm@12386
   986
  and [elim?] = ex1_implies_ex
wenzelm@11977
   987
haftmann@20944
   988
(*Better then ex1E for classical reasoner: needs no quantifier duplication!*)
haftmann@20973
   989
lemma alt_ex1E [elim!]:
haftmann@20944
   990
  assumes major: "\<exists>!x. P x"
haftmann@20944
   991
      and prem: "\<And>x. \<lbrakk> P x; \<forall>y y'. P y \<and> P y' \<longrightarrow> y = y' \<rbrakk> \<Longrightarrow> R"
haftmann@20944
   992
  shows R
haftmann@20944
   993
apply (rule ex1E [OF major])
haftmann@20944
   994
apply (rule prem)
wenzelm@22129
   995
apply (tactic {* ares_tac @{thms allI} 1 *})+
wenzelm@22129
   996
apply (tactic {* etac (Classical.dup_elim @{thm allE}) 1 *})
wenzelm@22129
   997
apply iprover
wenzelm@22129
   998
done
haftmann@20944
   999
haftmann@21151
  1000
ML {*
wenzelm@25388
  1001
structure Blast = BlastFun
wenzelm@25388
  1002
(
haftmann@21151
  1003
  type claset = Classical.claset
haftmann@22744
  1004
  val equality_name = @{const_name "op ="}
haftmann@22993
  1005
  val not_name = @{const_name Not}
wenzelm@26411
  1006
  val notE = @{thm notE}
wenzelm@26411
  1007
  val ccontr = @{thm ccontr}
haftmann@21151
  1008
  val contr_tac = Classical.contr_tac
haftmann@21151
  1009
  val dup_intr = Classical.dup_intr
haftmann@21151
  1010
  val hyp_subst_tac = Hypsubst.blast_hyp_subst_tac
haftmann@21151
  1011
  val rep_cs = Classical.rep_cs
haftmann@21151
  1012
  val cla_modifiers = Classical.cla_modifiers
haftmann@21151
  1013
  val cla_meth' = Classical.cla_meth'
wenzelm@25388
  1014
);
wenzelm@21671
  1015
val blast_tac = Blast.blast_tac;
haftmann@20944
  1016
*}
haftmann@20944
  1017
haftmann@21151
  1018
setup Blast.setup
haftmann@21151
  1019
haftmann@20944
  1020
haftmann@20944
  1021
subsubsection {* Simplifier *}
wenzelm@12281
  1022
wenzelm@12281
  1023
lemma eta_contract_eq: "(%s. f s) = f" ..
wenzelm@12281
  1024
wenzelm@12281
  1025
lemma simp_thms:
wenzelm@12937
  1026
  shows not_not: "(~ ~ P) = P"
nipkow@15354
  1027
  and Not_eq_iff: "((~P) = (~Q)) = (P = Q)"
wenzelm@12937
  1028
  and
berghofe@12436
  1029
    "(P ~= Q) = (P = (~Q))"
berghofe@12436
  1030
    "(P | ~P) = True"    "(~P | P) = True"
wenzelm@12281
  1031
    "(x = x) = True"
haftmann@20944
  1032
  and not_True_eq_False: "(\<not> True) = False"
haftmann@20944
  1033
  and not_False_eq_True: "(\<not> False) = True"
haftmann@20944
  1034
  and
berghofe@12436
  1035
    "(~P) ~= P"  "P ~= (~P)"
haftmann@20944
  1036
    "(True=P) = P"
haftmann@20944
  1037
  and eq_True: "(P = True) = P"
haftmann@20944
  1038
  and "(False=P) = (~P)"
haftmann@20944
  1039
  and eq_False: "(P = False) = (\<not> P)"
haftmann@20944
  1040
  and
wenzelm@12281
  1041
    "(True --> P) = P"  "(False --> P) = True"
wenzelm@12281
  1042
    "(P --> True) = True"  "(P --> P) = True"
wenzelm@12281
  1043
    "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
wenzelm@12281
  1044
    "(P & True) = P"  "(True & P) = P"
wenzelm@12281
  1045
    "(P & False) = False"  "(False & P) = False"
wenzelm@12281
  1046
    "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
wenzelm@12281
  1047
    "(P & ~P) = False"    "(~P & P) = False"
wenzelm@12281
  1048
    "(P | True) = True"  "(True | P) = True"
wenzelm@12281
  1049
    "(P | False) = P"  "(False | P) = P"
berghofe@12436
  1050
    "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
wenzelm@12281
  1051
    "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
wenzelm@12281
  1052
    -- {* needed for the one-point-rule quantifier simplification procs *}
wenzelm@12281
  1053
    -- {* essential for termination!! *} and
wenzelm@12281
  1054
    "!!P. (EX x. x=t & P(x)) = P(t)"
wenzelm@12281
  1055
    "!!P. (EX x. t=x & P(x)) = P(t)"
wenzelm@12281
  1056
    "!!P. (ALL x. x=t --> P(x)) = P(t)"
wenzelm@12937
  1057
    "!!P. (ALL x. t=x --> P(x)) = P(t)"
nipkow@17589
  1058
  by (blast, blast, blast, blast, blast, iprover+)
wenzelm@13421
  1059
paulson@14201
  1060
lemma disj_absorb: "(A | A) = A"
paulson@14201
  1061
  by blast
paulson@14201
  1062
paulson@14201
  1063
lemma disj_left_absorb: "(A | (A | B)) = (A | B)"
paulson@14201
  1064
  by blast
paulson@14201
  1065
paulson@14201
  1066
lemma conj_absorb: "(A & A) = A"
paulson@14201
  1067
  by blast
paulson@14201
  1068
paulson@14201
  1069
lemma conj_left_absorb: "(A & (A & B)) = (A & B)"
paulson@14201
  1070
  by blast
paulson@14201
  1071
wenzelm@12281
  1072
lemma eq_ac:
wenzelm@12937
  1073
  shows eq_commute: "(a=b) = (b=a)"
wenzelm@12937
  1074
    and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
nipkow@17589
  1075
    and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (iprover, blast+)
nipkow@17589
  1076
lemma neq_commute: "(a~=b) = (b~=a)" by iprover
wenzelm@12281
  1077
wenzelm@12281
  1078
lemma conj_comms:
wenzelm@12937
  1079
  shows conj_commute: "(P&Q) = (Q&P)"
nipkow@17589
  1080
    and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by iprover+
nipkow@17589
  1081
lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by iprover
wenzelm@12281
  1082
paulson@19174
  1083
lemmas conj_ac = conj_commute conj_left_commute conj_assoc
paulson@19174
  1084
wenzelm@12281
  1085
lemma disj_comms:
wenzelm@12937
  1086
  shows disj_commute: "(P|Q) = (Q|P)"
nipkow@17589
  1087
    and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by iprover+
nipkow@17589
  1088
lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by iprover
wenzelm@12281
  1089
paulson@19174
  1090
lemmas disj_ac = disj_commute disj_left_commute disj_assoc
paulson@19174
  1091
nipkow@17589
  1092
lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by iprover
nipkow@17589
  1093
lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by iprover
wenzelm@12281
  1094
nipkow@17589
  1095
lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by iprover
nipkow@17589
  1096
lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by iprover
wenzelm@12281
  1097
nipkow@17589
  1098
lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by iprover
nipkow@17589
  1099
lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by iprover
nipkow@17589
  1100
lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by iprover
wenzelm@12281
  1101
wenzelm@12281
  1102
text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
wenzelm@12281
  1103
lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
wenzelm@12281
  1104
lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
wenzelm@12281
  1105
wenzelm@12281
  1106
lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
wenzelm@12281
  1107
lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
wenzelm@12281
  1108
haftmann@21151
  1109
lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
haftmann@21151
  1110
  by iprover
haftmann@21151
  1111
nipkow@17589
  1112
lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by iprover
wenzelm@12281
  1113
lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
wenzelm@12281
  1114
lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
wenzelm@12281
  1115
lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
wenzelm@12281
  1116
lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
wenzelm@12281
  1117
lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
wenzelm@12281
  1118
  by blast
wenzelm@12281
  1119
lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
wenzelm@12281
  1120
nipkow@17589
  1121
lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by iprover
wenzelm@12281
  1122
wenzelm@12281
  1123
wenzelm@12281
  1124
lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
wenzelm@12281
  1125
  -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
wenzelm@12281
  1126
  -- {* cases boil down to the same thing. *}
wenzelm@12281
  1127
  by blast
wenzelm@12281
  1128
wenzelm@12281
  1129
lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
wenzelm@12281
  1130
lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
nipkow@17589
  1131
lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by iprover
nipkow@17589
  1132
lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by iprover
chaieb@23403
  1133
lemma all_not_ex: "(ALL x. P x) = (~ (EX x. ~ P x ))" by blast
wenzelm@12281
  1134
paulson@24286
  1135
declare All_def [noatp]
paulson@24286
  1136
nipkow@17589
  1137
lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by iprover
nipkow@17589
  1138
lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by iprover
wenzelm@12281
  1139
wenzelm@12281
  1140
text {*
wenzelm@12281
  1141
  \medskip The @{text "&"} congruence rule: not included by default!
wenzelm@12281
  1142
  May slow rewrite proofs down by as much as 50\% *}
wenzelm@12281
  1143
wenzelm@12281
  1144
lemma conj_cong:
wenzelm@12281
  1145
    "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
nipkow@17589
  1146
  by iprover
wenzelm@12281
  1147
wenzelm@12281
  1148
lemma rev_conj_cong:
wenzelm@12281
  1149
    "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
nipkow@17589
  1150
  by iprover
wenzelm@12281
  1151
wenzelm@12281
  1152
text {* The @{text "|"} congruence rule: not included by default! *}
wenzelm@12281
  1153
wenzelm@12281
  1154
lemma disj_cong:
wenzelm@12281
  1155
    "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
wenzelm@12281
  1156
  by blast
wenzelm@12281
  1157
wenzelm@12281
  1158
wenzelm@12281
  1159
text {* \medskip if-then-else rules *}
wenzelm@12281
  1160
wenzelm@12281
  1161
lemma if_True: "(if True then x else y) = x"
wenzelm@12281
  1162
  by (unfold if_def) blast
wenzelm@12281
  1163
wenzelm@12281
  1164
lemma if_False: "(if False then x else y) = y"
wenzelm@12281
  1165
  by (unfold if_def) blast
wenzelm@12281
  1166
wenzelm@12281
  1167
lemma if_P: "P ==> (if P then x else y) = x"
wenzelm@12281
  1168
  by (unfold if_def) blast
wenzelm@12281
  1169
wenzelm@12281
  1170
lemma if_not_P: "~P ==> (if P then x else y) = y"
wenzelm@12281
  1171
  by (unfold if_def) blast
wenzelm@12281
  1172
wenzelm@12281
  1173
lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
wenzelm@12281
  1174
  apply (rule case_split [of Q])
paulson@15481
  1175
   apply (simplesubst if_P)
paulson@15481
  1176
    prefer 3 apply (simplesubst if_not_P, blast+)
wenzelm@12281
  1177
  done
wenzelm@12281
  1178
wenzelm@12281
  1179
lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
paulson@15481
  1180
by (simplesubst split_if, blast)
wenzelm@12281
  1181
paulson@24286
  1182
lemmas if_splits [noatp] = split_if split_if_asm
wenzelm@12281
  1183
wenzelm@12281
  1184
lemma if_cancel: "(if c then x else x) = x"
paulson@15481
  1185
by (simplesubst split_if, blast)
wenzelm@12281
  1186
wenzelm@12281
  1187
lemma if_eq_cancel: "(if x = y then y else x) = x"
paulson@15481
  1188
by (simplesubst split_if, blast)
wenzelm@12281
  1189
wenzelm@12281
  1190
lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
wenzelm@19796
  1191
  -- {* This form is useful for expanding @{text "if"}s on the RIGHT of the @{text "==>"} symbol. *}
wenzelm@12281
  1192
  by (rule split_if)
wenzelm@12281
  1193
wenzelm@12281
  1194
lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
wenzelm@19796
  1195
  -- {* And this form is useful for expanding @{text "if"}s on the LEFT. *}
paulson@15481
  1196
  apply (simplesubst split_if, blast)
wenzelm@12281
  1197
  done
wenzelm@12281
  1198
nipkow@17589
  1199
lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) iprover
nipkow@17589
  1200
lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) iprover
wenzelm@12281
  1201
schirmer@15423
  1202
text {* \medskip let rules for simproc *}
schirmer@15423
  1203
schirmer@15423
  1204
lemma Let_folded: "f x \<equiv> g x \<Longrightarrow>  Let x f \<equiv> Let x g"
schirmer@15423
  1205
  by (unfold Let_def)
schirmer@15423
  1206
schirmer@15423
  1207
lemma Let_unfold: "f x \<equiv> g \<Longrightarrow>  Let x f \<equiv> g"
schirmer@15423
  1208
  by (unfold Let_def)
schirmer@15423
  1209
berghofe@16633
  1210
text {*
ballarin@16999
  1211
  The following copy of the implication operator is useful for
ballarin@16999
  1212
  fine-tuning congruence rules.  It instructs the simplifier to simplify
ballarin@16999
  1213
  its premise.
berghofe@16633
  1214
*}
berghofe@16633
  1215
wenzelm@17197
  1216
constdefs
wenzelm@17197
  1217
  simp_implies :: "[prop, prop] => prop"  (infixr "=simp=>" 1)
haftmann@28562
  1218
  [code del]: "simp_implies \<equiv> op ==>"
berghofe@16633
  1219
wenzelm@18457
  1220
lemma simp_impliesI:
berghofe@16633
  1221
  assumes PQ: "(PROP P \<Longrightarrow> PROP Q)"
berghofe@16633
  1222
  shows "PROP P =simp=> PROP Q"
berghofe@16633
  1223
  apply (unfold simp_implies_def)
berghofe@16633
  1224
  apply (rule PQ)
berghofe@16633
  1225
  apply assumption
berghofe@16633
  1226
  done
berghofe@16633
  1227
berghofe@16633
  1228
lemma simp_impliesE:
wenzelm@25388
  1229
  assumes PQ: "PROP P =simp=> PROP Q"
berghofe@16633
  1230
  and P: "PROP P"
berghofe@16633
  1231
  and QR: "PROP Q \<Longrightarrow> PROP R"
berghofe@16633
  1232
  shows "PROP R"
berghofe@16633
  1233
  apply (rule QR)
berghofe@16633
  1234
  apply (rule PQ [unfolded simp_implies_def])
berghofe@16633
  1235
  apply (rule P)
berghofe@16633
  1236
  done
berghofe@16633
  1237
berghofe@16633
  1238
lemma simp_implies_cong:
berghofe@16633
  1239
  assumes PP' :"PROP P == PROP P'"
berghofe@16633
  1240
  and P'QQ': "PROP P' ==> (PROP Q == PROP Q')"
berghofe@16633
  1241
  shows "(PROP P =simp=> PROP Q) == (PROP P' =simp=> PROP Q')"
berghofe@16633
  1242
proof (unfold simp_implies_def, rule equal_intr_rule)
berghofe@16633
  1243
  assume PQ: "PROP P \<Longrightarrow> PROP Q"
berghofe@16633
  1244
  and P': "PROP P'"
berghofe@16633
  1245
  from PP' [symmetric] and P' have "PROP P"
berghofe@16633
  1246
    by (rule equal_elim_rule1)
wenzelm@23553
  1247
  then have "PROP Q" by (rule PQ)
berghofe@16633
  1248
  with P'QQ' [OF P'] show "PROP Q'" by (rule equal_elim_rule1)
berghofe@16633
  1249
next
berghofe@16633
  1250
  assume P'Q': "PROP P' \<Longrightarrow> PROP Q'"
berghofe@16633
  1251
  and P: "PROP P"
berghofe@16633
  1252
  from PP' and P have P': "PROP P'" by (rule equal_elim_rule1)
wenzelm@23553
  1253
  then have "PROP Q'" by (rule P'Q')
berghofe@16633
  1254
  with P'QQ' [OF P', symmetric] show "PROP Q"
berghofe@16633
  1255
    by (rule equal_elim_rule1)
berghofe@16633
  1256
qed
berghofe@16633
  1257
haftmann@20944
  1258
lemma uncurry:
haftmann@20944
  1259
  assumes "P \<longrightarrow> Q \<longrightarrow> R"
haftmann@20944
  1260
  shows "P \<and> Q \<longrightarrow> R"
wenzelm@23553
  1261
  using assms by blast
haftmann@20944
  1262
haftmann@20944
  1263
lemma iff_allI:
haftmann@20944
  1264
  assumes "\<And>x. P x = Q x"
haftmann@20944
  1265
  shows "(\<forall>x. P x) = (\<forall>x. Q x)"
wenzelm@23553
  1266
  using assms by blast
haftmann@20944
  1267
haftmann@20944
  1268
lemma iff_exI:
haftmann@20944
  1269
  assumes "\<And>x. P x = Q x"
haftmann@20944
  1270
  shows "(\<exists>x. P x) = (\<exists>x. Q x)"
wenzelm@23553
  1271
  using assms by blast
haftmann@20944
  1272
haftmann@20944
  1273
lemma all_comm:
haftmann@20944
  1274
  "(\<forall>x y. P x y) = (\<forall>y x. P x y)"
haftmann@20944
  1275
  by blast
haftmann@20944
  1276
haftmann@20944
  1277
lemma ex_comm:
haftmann@20944
  1278
  "(\<exists>x y. P x y) = (\<exists>y x. P x y)"
haftmann@20944
  1279
  by blast
haftmann@20944
  1280
haftmann@28952
  1281
use "Tools/simpdata.ML"
wenzelm@21671
  1282
ML {* open Simpdata *}
wenzelm@21671
  1283
haftmann@21151
  1284
setup {*
haftmann@21151
  1285
  Simplifier.method_setup Splitter.split_modifiers
wenzelm@26496
  1286
  #> Simplifier.map_simpset (K Simpdata.simpset_simprocs)
haftmann@21151
  1287
  #> Splitter.setup
wenzelm@26496
  1288
  #> clasimp_setup
haftmann@21151
  1289
  #> EqSubst.setup
haftmann@21151
  1290
*}
haftmann@21151
  1291
wenzelm@24035
  1292
text {* Simproc for proving @{text "(y = x) == False"} from premise @{text "~(x = y)"}: *}
wenzelm@24035
  1293
wenzelm@24035
  1294
simproc_setup neq ("x = y") = {* fn _ =>
wenzelm@24035
  1295
let
wenzelm@24035
  1296
  val neq_to_EQ_False = @{thm not_sym} RS @{thm Eq_FalseI};
wenzelm@24035
  1297
  fun is_neq eq lhs rhs thm =
wenzelm@24035
  1298
    (case Thm.prop_of thm of
wenzelm@24035
  1299
      _ $ (Not $ (eq' $ l' $ r')) =>
wenzelm@24035
  1300
        Not = HOLogic.Not andalso eq' = eq andalso
wenzelm@24035
  1301
        r' aconv lhs andalso l' aconv rhs
wenzelm@24035
  1302
    | _ => false);
wenzelm@24035
  1303
  fun proc ss ct =
wenzelm@24035
  1304
    (case Thm.term_of ct of
wenzelm@24035
  1305
      eq $ lhs $ rhs =>
wenzelm@24035
  1306
        (case find_first (is_neq eq lhs rhs) (Simplifier.prems_of_ss ss) of
wenzelm@24035
  1307
          SOME thm => SOME (thm RS neq_to_EQ_False)
wenzelm@24035
  1308
        | NONE => NONE)
wenzelm@24035
  1309
     | _ => NONE);
wenzelm@24035
  1310
in proc end;
wenzelm@24035
  1311
*}
wenzelm@24035
  1312
wenzelm@24035
  1313
simproc_setup let_simp ("Let x f") = {*
wenzelm@24035
  1314
let
wenzelm@24035
  1315
  val (f_Let_unfold, x_Let_unfold) =
haftmann@28741
  1316
    let val [(_ $ (f $ x) $ _)] = prems_of @{thm Let_unfold}
wenzelm@24035
  1317
    in (cterm_of @{theory} f, cterm_of @{theory} x) end
wenzelm@24035
  1318
  val (f_Let_folded, x_Let_folded) =
haftmann@28741
  1319
    let val [(_ $ (f $ x) $ _)] = prems_of @{thm Let_folded}
wenzelm@24035
  1320
    in (cterm_of @{theory} f, cterm_of @{theory} x) end;
wenzelm@24035
  1321
  val g_Let_folded =
haftmann@28741
  1322
    let val [(_ $ _ $ (g $ _))] = prems_of @{thm Let_folded}
haftmann@28741
  1323
    in cterm_of @{theory} g end;
haftmann@28741
  1324
  fun count_loose (Bound i) k = if i >= k then 1 else 0
haftmann@28741
  1325
    | count_loose (s $ t) k = count_loose s k + count_loose t k
haftmann@28741
  1326
    | count_loose (Abs (_, _, t)) k = count_loose  t (k + 1)
haftmann@28741
  1327
    | count_loose _ _ = 0;
haftmann@28741
  1328
  fun is_trivial_let (Const (@{const_name Let}, _) $ x $ t) =
haftmann@28741
  1329
   case t
haftmann@28741
  1330
    of Abs (_, _, t') => count_loose t' 0 <= 1
haftmann@28741
  1331
     | _ => true;
haftmann@28741
  1332
in fn _ => fn ss => fn ct => if is_trivial_let (Thm.term_of ct)
haftmann@28741
  1333
  then SOME @{thm Let_def} (*no or one ocurrenc of bound variable*)
haftmann@28741
  1334
  else let (*Norbert Schirmer's case*)
haftmann@28741
  1335
    val ctxt = Simplifier.the_context ss;
haftmann@28741
  1336
    val thy = ProofContext.theory_of ctxt;
haftmann@28741
  1337
    val t = Thm.term_of ct;
haftmann@28741
  1338
    val ([t'], ctxt') = Variable.import_terms false [t] ctxt;
haftmann@28741
  1339
  in Option.map (hd o Variable.export ctxt' ctxt o single)
haftmann@28741
  1340
    (case t' of Const (@{const_name Let},_) $ x $ f => (* x and f are already in normal form *)
haftmann@28741
  1341
      if is_Free x orelse is_Bound x orelse is_Const x
haftmann@28741
  1342
      then SOME @{thm Let_def}
haftmann@28741
  1343
      else
haftmann@28741
  1344
        let
haftmann@28741
  1345
          val n = case f of (Abs (x, _, _)) => x | _ => "x";
haftmann@28741
  1346
          val cx = cterm_of thy x;
haftmann@28741
  1347
          val {T = xT, ...} = rep_cterm cx;
haftmann@28741
  1348
          val cf = cterm_of thy f;
haftmann@28741
  1349
          val fx_g = Simplifier.rewrite ss (Thm.capply cf cx);
haftmann@28741
  1350
          val (_ $ _ $ g) = prop_of fx_g;
haftmann@28741
  1351
          val g' = abstract_over (x,g);
haftmann@28741
  1352
        in (if (g aconv g')
haftmann@28741
  1353
             then
haftmann@28741
  1354
                let
haftmann@28741
  1355
                  val rl =
haftmann@28741
  1356
                    cterm_instantiate [(f_Let_unfold, cf), (x_Let_unfold, cx)] @{thm Let_unfold};
haftmann@28741
  1357
                in SOME (rl OF [fx_g]) end
haftmann@28741
  1358
             else if Term.betapply (f, x) aconv g then NONE (*avoid identity conversion*)
haftmann@28741
  1359
             else let
haftmann@28741
  1360
                   val abs_g'= Abs (n,xT,g');
haftmann@28741
  1361
                   val g'x = abs_g'$x;
haftmann@28741
  1362
                   val g_g'x = symmetric (beta_conversion false (cterm_of thy g'x));
haftmann@28741
  1363
                   val rl = cterm_instantiate
haftmann@28741
  1364
                             [(f_Let_folded, cterm_of thy f), (x_Let_folded, cx),
haftmann@28741
  1365
                              (g_Let_folded, cterm_of thy abs_g')]
haftmann@28741
  1366
                             @{thm Let_folded};
haftmann@28741
  1367
                 in SOME (rl OF [transitive fx_g g_g'x])
haftmann@28741
  1368
                 end)
haftmann@28741
  1369
        end
haftmann@28741
  1370
    | _ => NONE)
haftmann@28741
  1371
  end
haftmann@28741
  1372
end *}
wenzelm@24035
  1373
haftmann@21151
  1374
lemma True_implies_equals: "(True \<Longrightarrow> PROP P) \<equiv> PROP P"
haftmann@21151
  1375
proof
wenzelm@23389
  1376
  assume "True \<Longrightarrow> PROP P"
wenzelm@23389
  1377
  from this [OF TrueI] show "PROP P" .
haftmann@21151
  1378
next
haftmann@21151
  1379
  assume "PROP P"
wenzelm@23389
  1380
  then show "PROP P" .
haftmann@21151
  1381
qed
haftmann@21151
  1382
haftmann@21151
  1383
lemma ex_simps:
haftmann@21151
  1384
  "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
haftmann@21151
  1385
  "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
haftmann@21151
  1386
  "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
haftmann@21151
  1387
  "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
haftmann@21151
  1388
  "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
haftmann@21151
  1389
  "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
haftmann@21151
  1390
  -- {* Miniscoping: pushing in existential quantifiers. *}
haftmann@21151
  1391
  by (iprover | blast)+
haftmann@21151
  1392
haftmann@21151
  1393
lemma all_simps:
haftmann@21151
  1394
  "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
haftmann@21151
  1395
  "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
haftmann@21151
  1396
  "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
haftmann@21151
  1397
  "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
haftmann@21151
  1398
  "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
haftmann@21151
  1399
  "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
haftmann@21151
  1400
  -- {* Miniscoping: pushing in universal quantifiers. *}
haftmann@21151
  1401
  by (iprover | blast)+
paulson@15481
  1402
wenzelm@21671
  1403
lemmas [simp] =
wenzelm@21671
  1404
  triv_forall_equality (*prunes params*)
wenzelm@21671
  1405
  True_implies_equals  (*prune asms `True'*)
wenzelm@21671
  1406
  if_True
wenzelm@21671
  1407
  if_False
wenzelm@21671
  1408
  if_cancel
wenzelm@21671
  1409
  if_eq_cancel
wenzelm@21671
  1410
  imp_disjL
haftmann@20973
  1411
  (*In general it seems wrong to add distributive laws by default: they
haftmann@20973
  1412
    might cause exponential blow-up.  But imp_disjL has been in for a while
haftmann@20973
  1413
    and cannot be removed without affecting existing proofs.  Moreover,
haftmann@20973
  1414
    rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the
haftmann@20973
  1415
    grounds that it allows simplification of R in the two cases.*)
wenzelm@21671
  1416
  conj_assoc
wenzelm@21671
  1417
  disj_assoc
wenzelm@21671
  1418
  de_Morgan_conj
wenzelm@21671
  1419
  de_Morgan_disj
wenzelm@21671
  1420
  imp_disj1
wenzelm@21671
  1421
  imp_disj2
wenzelm@21671
  1422
  not_imp
wenzelm@21671
  1423
  disj_not1
wenzelm@21671
  1424
  not_all
wenzelm@21671
  1425
  not_ex
wenzelm@21671
  1426
  cases_simp
wenzelm@21671
  1427
  the_eq_trivial
wenzelm@21671
  1428
  the_sym_eq_trivial
wenzelm@21671
  1429
  ex_simps
wenzelm@21671
  1430
  all_simps
wenzelm@21671
  1431
  simp_thms
wenzelm@21671
  1432
wenzelm@21671
  1433
lemmas [cong] = imp_cong simp_implies_cong
wenzelm@21671
  1434
lemmas [split] = split_if
haftmann@20973
  1435
wenzelm@22377
  1436
ML {* val HOL_ss = @{simpset} *}
haftmann@20973
  1437
haftmann@20944
  1438
text {* Simplifies x assuming c and y assuming ~c *}
haftmann@20944
  1439
lemma if_cong:
haftmann@20944
  1440
  assumes "b = c"
haftmann@20944
  1441
      and "c \<Longrightarrow> x = u"
haftmann@20944
  1442
      and "\<not> c \<Longrightarrow> y = v"
haftmann@20944
  1443
  shows "(if b then x else y) = (if c then u else v)"
wenzelm@23553
  1444
  unfolding if_def using assms by simp
haftmann@20944
  1445
haftmann@20944
  1446
text {* Prevents simplification of x and y:
haftmann@20944
  1447
  faster and allows the execution of functional programs. *}
haftmann@20944
  1448
lemma if_weak_cong [cong]:
haftmann@20944
  1449
  assumes "b = c"
haftmann@20944
  1450
  shows "(if b then x else y) = (if c then x else y)"
wenzelm@23553
  1451
  using assms by (rule arg_cong)
haftmann@20944
  1452
haftmann@20944
  1453
text {* Prevents simplification of t: much faster *}
haftmann@20944
  1454
lemma let_weak_cong:
haftmann@20944
  1455
  assumes "a = b"
haftmann@20944
  1456
  shows "(let x = a in t x) = (let x = b in t x)"
wenzelm@23553
  1457
  using assms by (rule arg_cong)
haftmann@20944
  1458
haftmann@20944
  1459
text {* To tidy up the result of a simproc.  Only the RHS will be simplified. *}
haftmann@20944
  1460
lemma eq_cong2:
haftmann@20944
  1461
  assumes "u = u'"
haftmann@20944
  1462
  shows "(t \<equiv> u) \<equiv> (t \<equiv> u')"
wenzelm@23553
  1463
  using assms by simp
haftmann@20944
  1464
haftmann@20944
  1465
lemma if_distrib:
haftmann@20944
  1466
  "f (if c then x else y) = (if c then f x else f y)"
haftmann@20944
  1467
  by simp
haftmann@20944
  1468
haftmann@20944
  1469
text {* This lemma restricts the effect of the rewrite rule u=v to the left-hand
wenzelm@21502
  1470
  side of an equality.  Used in @{text "{Integ,Real}/simproc.ML"} *}
haftmann@20944
  1471
lemma restrict_to_left:
haftmann@20944
  1472
  assumes "x = y"
haftmann@20944
  1473
  shows "(x = z) = (y = z)"
wenzelm@23553
  1474
  using assms by simp
haftmann@20944
  1475
haftmann@20944
  1476
haftmann@20944
  1477
subsubsection {* Generic cases and induction *}
haftmann@20944
  1478
haftmann@20944
  1479
text {* Rule projections: *}
haftmann@20944
  1480
haftmann@20944
  1481
ML {*
haftmann@20944
  1482
structure ProjectRule = ProjectRuleFun
wenzelm@25388
  1483
(
wenzelm@27126
  1484
  val conjunct1 = @{thm conjunct1}
wenzelm@27126
  1485
  val conjunct2 = @{thm conjunct2}
wenzelm@27126
  1486
  val mp = @{thm mp}
wenzelm@25388
  1487
)
haftmann@20944
  1488
*}
haftmann@20944
  1489
haftmann@20944
  1490
constdefs
haftmann@20944
  1491
  induct_forall where "induct_forall P == \<forall>x. P x"
haftmann@20944
  1492
  induct_implies where "induct_implies A B == A \<longrightarrow> B"
haftmann@20944
  1493
  induct_equal where "induct_equal x y == x = y"
haftmann@20944
  1494
  induct_conj where "induct_conj A B == A \<and> B"
haftmann@20944
  1495
haftmann@20944
  1496
lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
haftmann@20944
  1497
  by (unfold atomize_all induct_forall_def)
haftmann@20944
  1498
haftmann@20944
  1499
lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
haftmann@20944
  1500
  by (unfold atomize_imp induct_implies_def)
haftmann@20944
  1501
haftmann@20944
  1502
lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
haftmann@20944
  1503
  by (unfold atomize_eq induct_equal_def)
haftmann@20944
  1504
wenzelm@28856
  1505
lemma induct_conj_eq: "(A &&& B) == Trueprop (induct_conj A B)"
haftmann@20944
  1506
  by (unfold atomize_conj induct_conj_def)
haftmann@20944
  1507
haftmann@20944
  1508
lemmas induct_atomize = induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq
haftmann@20944
  1509
lemmas induct_rulify [symmetric, standard] = induct_atomize
haftmann@20944
  1510
lemmas induct_rulify_fallback =
haftmann@20944
  1511
  induct_forall_def induct_implies_def induct_equal_def induct_conj_def
haftmann@20944
  1512
haftmann@20944
  1513
haftmann@20944
  1514
lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
haftmann@20944
  1515
    induct_conj (induct_forall A) (induct_forall B)"
haftmann@20944
  1516
  by (unfold induct_forall_def induct_conj_def) iprover
haftmann@20944
  1517
haftmann@20944
  1518
lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
haftmann@20944
  1519
    induct_conj (induct_implies C A) (induct_implies C B)"
haftmann@20944
  1520
  by (unfold induct_implies_def induct_conj_def) iprover
haftmann@20944
  1521
haftmann@20944
  1522
lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
haftmann@20944
  1523
proof
haftmann@20944
  1524
  assume r: "induct_conj A B ==> PROP C" and A B
haftmann@20944
  1525
  show "PROP C" by (rule r) (simp add: induct_conj_def `A` `B`)
haftmann@20944
  1526
next
haftmann@20944
  1527
  assume r: "A ==> B ==> PROP C" and "induct_conj A B"
haftmann@20944
  1528
  show "PROP C" by (rule r) (simp_all add: `induct_conj A B` [unfolded induct_conj_def])
haftmann@20944
  1529
qed
haftmann@20944
  1530
haftmann@20944
  1531
lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
haftmann@20944
  1532
haftmann@20944
  1533
hide const induct_forall induct_implies induct_equal induct_conj
haftmann@20944
  1534
haftmann@20944
  1535
text {* Method setup. *}
haftmann@20944
  1536
haftmann@20944
  1537
ML {*
wenzelm@27126
  1538
structure Induct = InductFun
wenzelm@27126
  1539
(
wenzelm@27126
  1540
  val cases_default = @{thm case_split}
wenzelm@27126
  1541
  val atomize = @{thms induct_atomize}
wenzelm@27126
  1542
  val rulify = @{thms induct_rulify}
wenzelm@27126
  1543
  val rulify_fallback = @{thms induct_rulify_fallback}
wenzelm@27126
  1544
)
haftmann@20944
  1545
*}
haftmann@20944
  1546
wenzelm@24830
  1547
setup Induct.setup
wenzelm@17459
  1548
wenzelm@27326
  1549
use "~~/src/Tools/induct_tacs.ML"
wenzelm@27126
  1550
setup InductTacs.setup
wenzelm@27126
  1551
haftmann@20944
  1552
berghofe@28325
  1553
subsubsection {* Coherent logic *}
berghofe@28325
  1554
berghofe@28325
  1555
ML {*
berghofe@28325
  1556
structure Coherent = CoherentFun
berghofe@28325
  1557
(
berghofe@28325
  1558
  val atomize_elimL = @{thm atomize_elimL}
berghofe@28325
  1559
  val atomize_exL = @{thm atomize_exL}
berghofe@28325
  1560
  val atomize_conjL = @{thm atomize_conjL}
berghofe@28325
  1561
  val atomize_disjL = @{thm atomize_disjL}
berghofe@28325
  1562
  val operator_names =
berghofe@28325
  1563
    [@{const_name "op |"}, @{const_name "op &"}, @{const_name "Ex"}]
berghofe@28325
  1564
);
berghofe@28325
  1565
*}
berghofe@28325
  1566
berghofe@28325
  1567
setup Coherent.setup
berghofe@28325
  1568
berghofe@28325
  1569
haftmann@20944
  1570
subsection {* Other simple lemmas and lemma duplicates *}
haftmann@20944
  1571
haftmann@24166
  1572
lemma Let_0 [simp]: "Let 0 f = f 0"
haftmann@24166
  1573
  unfolding Let_def ..
haftmann@24166
  1574
haftmann@24166
  1575
lemma Let_1 [simp]: "Let 1 f = f 1"
haftmann@24166
  1576
  unfolding Let_def ..
haftmann@24166
  1577
haftmann@20944
  1578
lemma ex1_eq [iff]: "EX! x. x = t" "EX! x. t = x"
haftmann@20944
  1579
  by blast+
haftmann@20944
  1580
haftmann@20944
  1581
lemma choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
haftmann@20944
  1582
  apply (rule iffI)
haftmann@20944
  1583
  apply (rule_tac a = "%x. THE y. P x y" in ex1I)
haftmann@20944
  1584
  apply (fast dest!: theI')
haftmann@20944
  1585
  apply (fast intro: ext the1_equality [symmetric])
haftmann@20944
  1586
  apply (erule ex1E)
haftmann@20944
  1587
  apply (rule allI)
haftmann@20944
  1588
  apply (rule ex1I)
haftmann@20944
  1589
  apply (erule spec)
haftmann@20944
  1590
  apply (erule_tac x = "%z. if z = x then y else f z" in allE)
haftmann@20944
  1591
  apply (erule impE)
haftmann@20944
  1592
  apply (rule allI)
wenzelm@27126
  1593
  apply (case_tac "xa = x")
haftmann@20944
  1594
  apply (drule_tac [3] x = x in fun_cong, simp_all)
haftmann@20944
  1595
  done
haftmann@20944
  1596
haftmann@20944
  1597
lemma mk_left_commute:
haftmann@21547
  1598
  fixes f (infix "\<otimes>" 60)
haftmann@21547
  1599
  assumes a: "\<And>x y z. (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)" and
haftmann@21547
  1600
          c: "\<And>x y. x \<otimes> y = y \<otimes> x"
haftmann@21547
  1601
  shows "x \<otimes> (y \<otimes> z) = y \<otimes> (x \<otimes> z)"
haftmann@20944
  1602
  by (rule trans [OF trans [OF c a] arg_cong [OF c, of "f y"]])
haftmann@20944
  1603
haftmann@22218
  1604
lemmas eq_sym_conv = eq_commute
haftmann@22218
  1605
chaieb@23037
  1606
lemma nnf_simps:
chaieb@23037
  1607
  "(\<not>(P \<and> Q)) = (\<not> P \<or> \<not> Q)" "(\<not> (P \<or> Q)) = (\<not> P \<and> \<not>Q)" "(P \<longrightarrow> Q) = (\<not>P \<or> Q)" 
chaieb@23037
  1608
  "(P = Q) = ((P \<and> Q) \<or> (\<not>P \<and> \<not> Q))" "(\<not>(P = Q)) = ((P \<and> \<not> Q) \<or> (\<not>P \<and> Q))" 
chaieb@23037
  1609
  "(\<not> \<not>(P)) = P"
chaieb@23037
  1610
by blast+
chaieb@23037
  1611
wenzelm@21671
  1612
wenzelm@21671
  1613
subsection {* Basic ML bindings *}
wenzelm@21671
  1614
wenzelm@21671
  1615
ML {*
wenzelm@22129
  1616
val FalseE = @{thm FalseE}
wenzelm@22129
  1617
val Let_def = @{thm Let_def}
wenzelm@22129
  1618
val TrueI = @{thm TrueI}
wenzelm@22129
  1619
val allE = @{thm allE}
wenzelm@22129
  1620
val allI = @{thm allI}
wenzelm@22129
  1621
val all_dupE = @{thm all_dupE}
wenzelm@22129
  1622
val arg_cong = @{thm arg_cong}
wenzelm@22129
  1623
val box_equals = @{thm box_equals}
wenzelm@22129
  1624
val ccontr = @{thm ccontr}
wenzelm@22129
  1625
val classical = @{thm classical}
wenzelm@22129
  1626
val conjE = @{thm conjE}
wenzelm@22129
  1627
val conjI = @{thm conjI}
wenzelm@22129
  1628
val conjunct1 = @{thm conjunct1}
wenzelm@22129
  1629
val conjunct2 = @{thm conjunct2}
wenzelm@22129
  1630
val disjCI = @{thm disjCI}
wenzelm@22129
  1631
val disjE = @{thm disjE}
wenzelm@22129
  1632
val disjI1 = @{thm disjI1}
wenzelm@22129
  1633
val disjI2 = @{thm disjI2}
wenzelm@22129
  1634
val eq_reflection = @{thm eq_reflection}
wenzelm@22129
  1635
val ex1E = @{thm ex1E}
wenzelm@22129
  1636
val ex1I = @{thm ex1I}
wenzelm@22129
  1637
val ex1_implies_ex = @{thm ex1_implies_ex}
wenzelm@22129
  1638
val exE = @{thm exE}
wenzelm@22129
  1639
val exI = @{thm exI}
wenzelm@22129
  1640
val excluded_middle = @{thm excluded_middle}
wenzelm@22129
  1641
val ext = @{thm ext}
wenzelm@22129
  1642
val fun_cong = @{thm fun_cong}
wenzelm@22129
  1643
val iffD1 = @{thm iffD1}
wenzelm@22129
  1644
val iffD2 = @{thm iffD2}
wenzelm@22129
  1645
val iffI = @{thm iffI}
wenzelm@22129
  1646
val impE = @{thm impE}
wenzelm@22129
  1647
val impI = @{thm impI}
wenzelm@22129
  1648
val meta_eq_to_obj_eq = @{thm meta_eq_to_obj_eq}
wenzelm@22129
  1649
val mp = @{thm mp}
wenzelm@22129
  1650
val notE = @{thm notE}
wenzelm@22129
  1651
val notI = @{thm notI}
wenzelm@22129
  1652
val not_all = @{thm not_all}
wenzelm@22129
  1653
val not_ex = @{thm not_ex}
wenzelm@22129
  1654
val not_iff = @{thm not_iff}
wenzelm@22129
  1655
val not_not = @{thm not_not}
wenzelm@22129
  1656
val not_sym = @{thm not_sym}
wenzelm@22129
  1657
val refl = @{thm refl}
wenzelm@22129
  1658
val rev_mp = @{thm rev_mp}
wenzelm@22129
  1659
val spec = @{thm spec}
wenzelm@22129
  1660
val ssubst = @{thm ssubst}
wenzelm@22129
  1661
val subst = @{thm subst}
wenzelm@22129
  1662
val sym = @{thm sym}
wenzelm@22129
  1663
val trans = @{thm trans}
wenzelm@21671
  1664
*}
wenzelm@21671
  1665
wenzelm@21671
  1666
haftmann@30929
  1667
subsection {* Code generator setup *}
haftmann@28400
  1668
haftmann@30929
  1669
subsubsection {* SML code generator setup *}
haftmann@30929
  1670
haftmann@30929
  1671
use "Tools/recfun_codegen.ML"
haftmann@30929
  1672
haftmann@30929
  1673
setup {*
haftmann@30929
  1674
  Codegen.setup
haftmann@30929
  1675
  #> RecfunCodegen.setup
haftmann@30929
  1676
*}
haftmann@30929
  1677
haftmann@30929
  1678
types_code
haftmann@30929
  1679
  "bool"  ("bool")
haftmann@30929
  1680
attach (term_of) {*
haftmann@30929
  1681
fun term_of_bool b = if b then HOLogic.true_const else HOLogic.false_const;
haftmann@30929
  1682
*}
haftmann@30929
  1683
attach (test) {*
haftmann@30929
  1684
fun gen_bool i =
haftmann@30929
  1685
  let val b = one_of [false, true]
haftmann@30929
  1686
  in (b, fn () => term_of_bool b) end;
haftmann@30929
  1687
*}
haftmann@30929
  1688
  "prop"  ("bool")
haftmann@30929
  1689
attach (term_of) {*
haftmann@30929
  1690
fun term_of_prop b =
haftmann@30929
  1691
  HOLogic.mk_Trueprop (if b then HOLogic.true_const else HOLogic.false_const);
haftmann@30929
  1692
*}
haftmann@30929
  1693
haftmann@30929
  1694
consts_code
haftmann@30929
  1695
  "Trueprop" ("(_)")
haftmann@30929
  1696
  "True"    ("true")
haftmann@30929
  1697
  "False"   ("false")
haftmann@30929
  1698
  "Not"     ("Bool.not")
haftmann@30929
  1699
  "op |"    ("(_ orelse/ _)")
haftmann@30929
  1700
  "op &"    ("(_ andalso/ _)")
haftmann@30929
  1701
  "If"      ("(if _/ then _/ else _)")
haftmann@30929
  1702
haftmann@30929
  1703
setup {*
haftmann@30929
  1704
let
haftmann@30929
  1705
haftmann@30929
  1706
fun eq_codegen thy defs dep thyname b t gr =
haftmann@30929
  1707
    (case strip_comb t of
haftmann@30929
  1708
       (Const ("op =", Type (_, [Type ("fun", _), _])), _) => NONE
haftmann@30929
  1709
     | (Const ("op =", _), [t, u]) =>
haftmann@30929
  1710
          let
haftmann@30929
  1711
            val (pt, gr') = Codegen.invoke_codegen thy defs dep thyname false t gr;
haftmann@30929
  1712
            val (pu, gr'') = Codegen.invoke_codegen thy defs dep thyname false u gr';
haftmann@30929
  1713
            val (_, gr''') = Codegen.invoke_tycodegen thy defs dep thyname false HOLogic.boolT gr'';
haftmann@30929
  1714
          in
haftmann@30929
  1715
            SOME (Codegen.parens
haftmann@30929
  1716
              (Pretty.block [pt, Codegen.str " =", Pretty.brk 1, pu]), gr''')
haftmann@30929
  1717
          end
haftmann@30929
  1718
     | (t as Const ("op =", _), ts) => SOME (Codegen.invoke_codegen
haftmann@30929
  1719
         thy defs dep thyname b (Codegen.eta_expand t ts 2) gr)
haftmann@30929
  1720
     | _ => NONE);
haftmann@30929
  1721
haftmann@30929
  1722
in
haftmann@30929
  1723
  Codegen.add_codegen "eq_codegen" eq_codegen
haftmann@30929
  1724
end
haftmann@30929
  1725
*}
haftmann@30929
  1726
haftmann@30929
  1727
subsubsection {* Equality *}
haftmann@24844
  1728
haftmann@29608
  1729
class eq =
haftmann@26513
  1730
  fixes eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
haftmann@28400
  1731
  assumes eq_equals: "eq x y \<longleftrightarrow> x = y"
haftmann@26513
  1732
begin
haftmann@26513
  1733
haftmann@30929
  1734
lemma eq [code unfold, code inline del]: "eq = (op =)"
haftmann@28346
  1735
  by (rule ext eq_equals)+
haftmann@28346
  1736
haftmann@28346
  1737
lemma eq_refl: "eq x x \<longleftrightarrow> True"
haftmann@28346
  1738
  unfolding eq by rule+
haftmann@28346
  1739
haftmann@30966
  1740
lemma equals_eq [code inline]: "(op =) \<equiv> eq"
haftmann@30929
  1741
  by (rule eq_reflection) (rule ext, rule ext, rule sym, rule eq_equals)
haftmann@30929
  1742
haftmann@30929
  1743
declare equals_eq [symmetric, code post]
haftmann@30929
  1744
haftmann@26513
  1745
end
haftmann@26513
  1746
haftmann@30966
  1747
declare equals_eq [code]
haftmann@30966
  1748
haftmann@30966
  1749
haftmann@30929
  1750
subsubsection {* Generic code generator foundation *}
haftmann@28513
  1751
haftmann@30929
  1752
text {* Datatypes *}
haftmann@30929
  1753
haftmann@30929
  1754
code_datatype True False
haftmann@30929
  1755
haftmann@30929
  1756
code_datatype "TYPE('a\<Colon>{})"
haftmann@30929
  1757
haftmann@30929
  1758
code_datatype Trueprop "prop"
haftmann@30929
  1759
haftmann@30929
  1760
text {* Code equations *}
haftmann@30929
  1761
haftmann@30929
  1762
lemma [code]:
haftmann@30929
  1763
  shows "(True \<Longrightarrow> PROP P) \<equiv> PROP P" 
haftmann@30929
  1764
    and "(False \<Longrightarrow> Q) \<equiv> Trueprop True" 
haftmann@30929
  1765
    and "(PROP P \<Longrightarrow> True) \<equiv> Trueprop True" 
haftmann@30929
  1766
    and "(Q \<Longrightarrow> False) \<equiv> Trueprop (\<not> Q)" by (auto intro!: equal_intr_rule)
haftmann@30929
  1767
haftmann@30929
  1768
lemma [code]:
haftmann@30929
  1769
  shows "False \<and> x \<longleftrightarrow> False"
haftmann@30929
  1770
    and "True \<and> x \<longleftrightarrow> x"
haftmann@30929
  1771
    and "x \<and> False \<longleftrightarrow> False"
haftmann@30929
  1772
    and "x \<and> True \<longleftrightarrow> x" by simp_all
haftmann@30929
  1773
haftmann@30929
  1774
lemma [code]:
haftmann@30929
  1775
  shows "False \<or> x \<longleftrightarrow> x"
haftmann@30929
  1776
    and "True \<or> x \<longleftrightarrow> True"
haftmann@30929
  1777
    and "x \<or> False \<longleftrightarrow> x"
haftmann@30929
  1778
    and "x \<or> True \<longleftrightarrow> True" by simp_all
haftmann@30929
  1779
haftmann@30929
  1780
lemma [code]:
haftmann@30929
  1781
  shows "\<not> True \<longleftrightarrow> False"
haftmann@30929
  1782
    and "\<not> False \<longleftrightarrow> True" by (rule HOL.simp_thms)+
haftmann@30929
  1783
haftmann@30929
  1784
lemmas [code] = Let_def if_True if_False
haftmann@30929
  1785
haftmann@30929
  1786
lemmas [code, code unfold, symmetric, code post] = imp_conv_disj
haftmann@30929
  1787
haftmann@30929
  1788
text {* Equality *}
haftmann@30929
  1789
haftmann@30929
  1790
declare simp_thms(6) [code nbe]
haftmann@30929
  1791
haftmann@30929
  1792
hide (open) const eq
haftmann@30929
  1793
hide const eq
haftmann@28513
  1794
haftmann@28513
  1795
setup {*
haftmann@30929
  1796
  Code_Unit.add_const_alias @{thm equals_eq}
haftmann@28513
  1797
*}
haftmann@28513
  1798
haftmann@30929
  1799
text {* Cases *}
haftmann@30929
  1800
haftmann@30929
  1801
lemma Let_case_cert:
haftmann@30929
  1802
  assumes "CASE \<equiv> (\<lambda>x. Let x f)"
haftmann@30929
  1803
  shows "CASE x \<equiv> f x"
haftmann@30929
  1804
  using assms by simp_all
haftmann@30929
  1805
haftmann@30929
  1806
lemma If_case_cert:
haftmann@30929
  1807
  assumes "CASE \<equiv> (\<lambda>b. If b f g)"
haftmann@30929
  1808
  shows "(CASE True \<equiv> f) &&& (CASE False \<equiv> g)"
haftmann@30929
  1809
  using assms by simp_all
haftmann@30929
  1810
haftmann@30929
  1811
setup {*
haftmann@30929
  1812
  Code.add_case @{thm Let_case_cert}
haftmann@30929
  1813
  #> Code.add_case @{thm If_case_cert}
haftmann@30929
  1814
  #> Code.add_undefined @{const_name undefined}
haftmann@30929
  1815
*}
haftmann@30929
  1816
haftmann@30929
  1817
code_abort undefined
haftmann@30929
  1818
haftmann@30929
  1819
subsubsection {* Generic code generator preprocessor *}
haftmann@30929
  1820
haftmann@30929
  1821
setup {*
haftmann@30929
  1822
  Code.map_pre (K HOL_basic_ss)
haftmann@30929
  1823
  #> Code.map_post (K HOL_basic_ss)
haftmann@30929
  1824
*}
haftmann@30929
  1825
haftmann@30929
  1826
subsubsection {* Generic code generator target languages *}
haftmann@30929
  1827
haftmann@30929
  1828
text {* type bool *}
haftmann@30929
  1829
haftmann@30929
  1830
code_type bool
haftmann@30929
  1831
  (SML "bool")
haftmann@30929
  1832
  (OCaml "bool")
haftmann@30929
  1833
  (Haskell "Bool")
haftmann@30929
  1834
haftmann@30929
  1835
code_const True and False and Not and "op &" and "op |" and If
haftmann@30929
  1836
  (SML "true" and "false" and "not"
haftmann@30929
  1837
    and infixl 1 "andalso" and infixl 0 "orelse"
haftmann@30929
  1838
    and "!(if (_)/ then (_)/ else (_))")
haftmann@30929
  1839
  (OCaml "true" and "false" and "not"
haftmann@30929
  1840
    and infixl 4 "&&" and infixl 2 "||"
haftmann@30929
  1841
    and "!(if (_)/ then (_)/ else (_))")
haftmann@30929
  1842
  (Haskell "True" and "False" and "not"
haftmann@30929
  1843
    and infixl 3 "&&" and infixl 2 "||"
haftmann@30929
  1844
    and "!(if (_)/ then (_)/ else (_))")
haftmann@30929
  1845
haftmann@30929
  1846
code_reserved SML
haftmann@30929
  1847
  bool true false not
haftmann@30929
  1848
haftmann@30929
  1849
code_reserved OCaml
haftmann@30929
  1850
  bool not
haftmann@30929
  1851
haftmann@30929
  1852
text {* using built-in Haskell equality *}
haftmann@30929
  1853
haftmann@30929
  1854
code_class eq
haftmann@30929
  1855
  (Haskell "Eq")
haftmann@30929
  1856
haftmann@30929
  1857
code_const "eq_class.eq"
haftmann@30929
  1858
  (Haskell infixl 4 "==")
haftmann@30929
  1859
haftmann@30929
  1860
code_const "op ="
haftmann@30929
  1861
  (Haskell infixl 4 "==")
haftmann@30929
  1862
haftmann@30929
  1863
text {* undefined *}
haftmann@30929
  1864
haftmann@30929
  1865
code_const undefined
haftmann@30929
  1866
  (SML "!(raise/ Fail/ \"undefined\")")
haftmann@30929
  1867
  (OCaml "failwith/ \"undefined\"")
haftmann@30929
  1868
  (Haskell "error/ \"undefined\"")
haftmann@30929
  1869
haftmann@30929
  1870
subsubsection {* Evaluation and normalization by evaluation *}
haftmann@30929
  1871
haftmann@30929
  1872
setup {*
haftmann@30929
  1873
  Value.add_evaluator ("SML", Codegen.eval_term o ProofContext.theory_of)
haftmann@30929
  1874
*}
haftmann@30929
  1875
haftmann@30929
  1876
ML {*
haftmann@30929
  1877
structure Eval_Method =
haftmann@30929
  1878
struct
haftmann@30929
  1879
haftmann@30929
  1880
val eval_ref : (unit -> bool) option ref = ref NONE;
haftmann@30929
  1881
haftmann@30929
  1882
end;
haftmann@30929
  1883
*}
haftmann@30929
  1884
haftmann@30929
  1885
oracle eval_oracle = {* fn ct =>
haftmann@30929
  1886
  let
haftmann@30929
  1887
    val thy = Thm.theory_of_cterm ct;
haftmann@30929
  1888
    val t = Thm.term_of ct;
haftmann@30929
  1889
    val dummy = @{cprop True};
haftmann@30929
  1890
  in case try HOLogic.dest_Trueprop t
haftmann@30947
  1891
   of SOME t' => if Code_ML.eval NONE
haftmann@30929
  1892
         ("Eval_Method.eval_ref", Eval_Method.eval_ref) thy t' [] 
haftmann@30929
  1893
       then Thm.capply (Thm.capply @{cterm "op \<equiv> \<Colon> prop \<Rightarrow> prop \<Rightarrow> prop"} ct) dummy
haftmann@30929
  1894
       else dummy
haftmann@30929
  1895
    | NONE => dummy
haftmann@30929
  1896
  end
haftmann@30929
  1897
*}
haftmann@30929
  1898
haftmann@30929
  1899
ML {*
haftmann@30929
  1900
fun gen_eval_method conv ctxt = SIMPLE_METHOD'
haftmann@30929
  1901
  (CONVERSION (Conv.params_conv (~1) (K (Conv.concl_conv (~1) conv)) ctxt)
haftmann@30929
  1902
    THEN' rtac TrueI)
haftmann@30929
  1903
*}
haftmann@30929
  1904
haftmann@30929
  1905
method_setup eval = {* Scan.succeed (gen_eval_method eval_oracle) *}
haftmann@30929
  1906
  "solve goal by evaluation"
haftmann@30929
  1907
haftmann@30929
  1908
method_setup evaluation = {* Scan.succeed (gen_eval_method Codegen.evaluation_conv) *}
haftmann@30929
  1909
  "solve goal by evaluation"
haftmann@30929
  1910
haftmann@30929
  1911
method_setup normalization = {*
haftmann@30929
  1912
  Scan.succeed (K (SIMPLE_METHOD' (CONVERSION Nbe.norm_conv THEN' (fn k => TRY (rtac TrueI k)))))
haftmann@30929
  1913
*} "solve goal by normalization"
haftmann@30929
  1914
haftmann@30929
  1915
subsubsection {* Quickcheck *}
haftmann@30929
  1916
haftmann@30929
  1917
setup {*
haftmann@30929
  1918
  Quickcheck.add_generator ("SML", Codegen.test_term)
haftmann@30929
  1919
*}
haftmann@30929
  1920
haftmann@30929
  1921
quickcheck_params [size = 5, iterations = 50]
haftmann@30929
  1922
haftmann@23247
  1923
blanchet@30309
  1924
subsection {* Nitpick hooks *}
blanchet@30309
  1925
blanchet@30309
  1926
text {* This will be relocated once Nitpick is moved to HOL. *}
blanchet@30309
  1927
blanchet@29800
  1928
ML {*
blanchet@30254
  1929
structure Nitpick_Const_Def_Thms = NamedThmsFun
blanchet@30254
  1930
(
blanchet@30254
  1931
  val name = "nitpick_const_def"
blanchet@30254
  1932
  val description = "alternative definitions of constants as needed by Nitpick"
blanchet@30254
  1933
)
blanchet@29803
  1934
structure Nitpick_Const_Simp_Thms = NamedThmsFun
blanchet@29800
  1935
(
blanchet@29803
  1936
  val name = "nitpick_const_simp"
blanchet@29806
  1937
  val description = "equational specification of constants as needed by Nitpick"
blanchet@29800
  1938
)
blanchet@29803
  1939
structure Nitpick_Const_Psimp_Thms = NamedThmsFun
blanchet@29800
  1940
(
blanchet@29803
  1941
  val name = "nitpick_const_psimp"
blanchet@29806
  1942
  val description = "partial equational specification of constants as needed by Nitpick"
blanchet@29800
  1943
)
blanchet@29805
  1944
structure Nitpick_Ind_Intro_Thms = NamedThmsFun
blanchet@29805
  1945
(
blanchet@29805
  1946
  val name = "nitpick_ind_intro"
blanchet@29806
  1947
  val description = "introduction rules for (co)inductive predicates as needed by Nitpick"
blanchet@29805
  1948
)
blanchet@29800
  1949
*}
blanchet@30254
  1950
setup {* Nitpick_Const_Def_Thms.setup
blanchet@30254
  1951
         #> Nitpick_Const_Simp_Thms.setup
blanchet@29805
  1952
         #> Nitpick_Const_Psimp_Thms.setup
blanchet@29805
  1953
         #> Nitpick_Ind_Intro_Thms.setup *}
blanchet@29800
  1954
haftmann@22839
  1955
subsection {* Legacy tactics and ML bindings *}
wenzelm@21671
  1956
wenzelm@21671
  1957
ML {*
wenzelm@21671
  1958
fun strip_tac i = REPEAT (resolve_tac [impI, allI] i);
wenzelm@21671
  1959
wenzelm@21671
  1960
(* combination of (spec RS spec RS ...(j times) ... spec RS mp) *)
wenzelm@21671
  1961
local
wenzelm@21671
  1962
  fun wrong_prem (Const ("All", _) $ (Abs (_, _, t))) = wrong_prem t
wenzelm@21671
  1963
    | wrong_prem (Bound _) = true
wenzelm@21671
  1964
    | wrong_prem _ = false;
wenzelm@21671
  1965
  val filter_right = filter (not o wrong_prem o HOLogic.dest_Trueprop o hd o Thm.prems_of);
wenzelm@21671
  1966
in
wenzelm@21671
  1967
  fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp]);
wenzelm@21671
  1968
  fun smp_tac j = EVERY'[dresolve_tac (smp j), atac];
wenzelm@21671
  1969
end;
haftmann@22839
  1970
haftmann@22839
  1971
val all_conj_distrib = thm "all_conj_distrib";
haftmann@22839
  1972
val all_simps = thms "all_simps";
haftmann@22839
  1973
val atomize_not = thm "atomize_not";
wenzelm@24830
  1974
val case_split = thm "case_split";
haftmann@22839
  1975
val cases_simp = thm "cases_simp";
haftmann@22839
  1976
val choice_eq = thm "choice_eq"
haftmann@22839
  1977
val cong = thm "cong"
haftmann@22839
  1978
val conj_comms = thms "conj_comms";
haftmann@22839
  1979
val conj_cong = thm "conj_cong";
haftmann@22839
  1980
val de_Morgan_conj = thm "de_Morgan_conj";
haftmann@22839
  1981
val de_Morgan_disj = thm "de_Morgan_disj";
haftmann@22839
  1982
val disj_assoc = thm "disj_assoc";
haftmann@22839
  1983
val disj_comms = thms "disj_comms";
haftmann@22839
  1984
val disj_cong = thm "disj_cong";
haftmann@22839
  1985
val eq_ac = thms "eq_ac";
haftmann@22839
  1986
val eq_cong2 = thm "eq_cong2"
haftmann@22839
  1987
val Eq_FalseI = thm "Eq_FalseI";
haftmann@22839
  1988
val Eq_TrueI = thm "Eq_TrueI";
haftmann@22839
  1989
val Ex1_def = thm "Ex1_def"
haftmann@22839
  1990
val ex_disj_distrib = thm "ex_disj_distrib";
haftmann@22839
  1991
val ex_simps = thms "ex_simps";
haftmann@22839
  1992
val if_cancel = thm "if_cancel";
haftmann@22839
  1993
val if_eq_cancel = thm "if_eq_cancel";
haftmann@22839
  1994
val if_False = thm "if_False";
haftmann@22839
  1995
val iff_conv_conj_imp = thm "iff_conv_conj_imp";
haftmann@22839
  1996
val iff = thm "iff"
haftmann@22839
  1997
val if_splits = thms "if_splits";
haftmann@22839
  1998
val if_True = thm "if_True";
haftmann@22839
  1999
val if_weak_cong = thm "if_weak_cong"
haftmann@22839
  2000
val imp_all = thm "imp_all";
haftmann@22839
  2001
val imp_cong = thm "imp_cong";
haftmann@22839
  2002
val imp_conjL = thm "imp_conjL";
haftmann@22839
  2003
val imp_conjR = thm "imp_conjR";
haftmann@22839
  2004
val imp_conv_disj = thm "imp_conv_disj";
haftmann@22839
  2005
val simp_implies_def = thm "simp_implies_def";
haftmann@22839
  2006
val simp_thms = thms "simp_thms";
haftmann@22839
  2007
val split_if = thm "split_if";
haftmann@22839
  2008
val the1_equality = thm "the1_equality"
haftmann@22839
  2009
val theI = thm "theI"
haftmann@22839
  2010
val theI' = thm "theI'"
haftmann@22839
  2011
val True_implies_equals = thm "True_implies_equals";
chaieb@23037
  2012
val nnf_conv = Simplifier.rewrite (HOL_basic_ss addsimps simp_thms @ @{thms "nnf_simps"})
chaieb@23037
  2013
wenzelm@21671
  2014
*}
wenzelm@21671
  2015
kleing@14357
  2016
end