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