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