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