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