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