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