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