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