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