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