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