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