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