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