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