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