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