src/HOL/HOL.thy
author berghofe
Sun Sep 25 20:19:31 2005 +0200 (2005-09-25)
changeset 17639 50878db27b94
parent 17589 58eeffd73be1
child 17992 4379d46c8e13
permissions -rw-r--r--
eq_codegen now ensures that code for bool type is generated.
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
haftmann@16417
    10
uses ("cladata.ML") ("blastdata.ML") ("simpdata.ML") ("eqrule_HOL_data.ML")
paulson@15481
    11
      ("~~/src/Provers/eqsubst.ML")
avigad@16775
    12
nipkow@15131
    13
begin
wenzelm@2260
    14
wenzelm@11750
    15
subsection {* Primitive logic *}
wenzelm@11750
    16
wenzelm@11750
    17
subsubsection {* Core syntax *}
wenzelm@2260
    18
wenzelm@14854
    19
classes type
wenzelm@12338
    20
defaultsort type
wenzelm@3947
    21
wenzelm@12338
    22
global
clasohm@923
    23
wenzelm@7357
    24
typedecl bool
clasohm@923
    25
clasohm@923
    26
arities
wenzelm@12338
    27
  bool :: type
wenzelm@12338
    28
  fun :: (type, type) type
clasohm@923
    29
wenzelm@11750
    30
judgment
wenzelm@11750
    31
  Trueprop      :: "bool => prop"                   ("(_)" 5)
clasohm@923
    32
wenzelm@11750
    33
consts
wenzelm@7357
    34
  Not           :: "bool => bool"                   ("~ _" [40] 40)
wenzelm@7357
    35
  True          :: bool
wenzelm@7357
    36
  False         :: bool
wenzelm@3947
    37
  arbitrary     :: 'a
clasohm@923
    38
wenzelm@11432
    39
  The           :: "('a => bool) => 'a"
wenzelm@7357
    40
  All           :: "('a => bool) => bool"           (binder "ALL " 10)
wenzelm@7357
    41
  Ex            :: "('a => bool) => bool"           (binder "EX " 10)
wenzelm@7357
    42
  Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
wenzelm@7357
    43
  Let           :: "['a, 'a => 'b] => 'b"
clasohm@923
    44
wenzelm@7357
    45
  "="           :: "['a, 'a] => bool"               (infixl 50)
wenzelm@7357
    46
  &             :: "[bool, bool] => bool"           (infixr 35)
wenzelm@7357
    47
  "|"           :: "[bool, bool] => bool"           (infixr 30)
wenzelm@7357
    48
  -->           :: "[bool, bool] => bool"           (infixr 25)
clasohm@923
    49
wenzelm@10432
    50
local
wenzelm@10432
    51
paulson@16587
    52
consts
paulson@16587
    53
  If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
wenzelm@2260
    54
wenzelm@11750
    55
subsubsection {* Additional concrete syntax *}
wenzelm@2260
    56
wenzelm@4868
    57
nonterminals
clasohm@923
    58
  letbinds  letbind
clasohm@923
    59
  case_syn  cases_syn
clasohm@923
    60
clasohm@923
    61
syntax
wenzelm@12650
    62
  "_not_equal"  :: "['a, 'a] => bool"                    (infixl "~=" 50)
wenzelm@11432
    63
  "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
clasohm@923
    64
wenzelm@7357
    65
  "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
wenzelm@7357
    66
  ""            :: "letbind => letbinds"                 ("_")
wenzelm@7357
    67
  "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
wenzelm@7357
    68
  "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
clasohm@923
    69
wenzelm@9060
    70
  "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
wenzelm@9060
    71
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
wenzelm@7357
    72
  ""            :: "case_syn => cases_syn"               ("_")
wenzelm@9060
    73
  "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
clasohm@923
    74
clasohm@923
    75
translations
wenzelm@7238
    76
  "x ~= y"                == "~ (x = y)"
nipkow@13764
    77
  "THE x. P"              == "The (%x. P)"
clasohm@923
    78
  "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
nipkow@1114
    79
  "let x = a in e"        == "Let a (%x. e)"
clasohm@923
    80
nipkow@13763
    81
print_translation {*
nipkow@13763
    82
(* To avoid eta-contraction of body: *)
nipkow@13763
    83
[("The", fn [Abs abs] =>
nipkow@13763
    84
     let val (x,t) = atomic_abs_tr' abs
nipkow@13763
    85
     in Syntax.const "_The" $ x $ t end)]
nipkow@13763
    86
*}
nipkow@13763
    87
wenzelm@12633
    88
syntax (output)
wenzelm@11687
    89
  "="           :: "['a, 'a] => bool"                    (infix 50)
wenzelm@12650
    90
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "~=" 50)
wenzelm@2260
    91
wenzelm@12114
    92
syntax (xsymbols)
wenzelm@11687
    93
  Not           :: "bool => bool"                        ("\<not> _" [40] 40)
wenzelm@11687
    94
  "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
wenzelm@11687
    95
  "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
wenzelm@12114
    96
  "op -->"      :: "[bool, bool] => bool"                (infixr "\<longrightarrow>" 25)
wenzelm@12650
    97
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@11687
    98
  "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
wenzelm@11687
    99
  "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
wenzelm@11687
   100
  "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
wenzelm@11687
   101
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
schirmer@14361
   102
(*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \<orelse> _")*)
wenzelm@2372
   103
wenzelm@12114
   104
syntax (xsymbols output)
wenzelm@12650
   105
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@3820
   106
wenzelm@6340
   107
syntax (HTML output)
kleing@14565
   108
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@11687
   109
  Not           :: "bool => bool"                        ("\<not> _" [40] 40)
kleing@14565
   110
  "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
kleing@14565
   111
  "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
kleing@14565
   112
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
kleing@14565
   113
  "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
kleing@14565
   114
  "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
kleing@14565
   115
  "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
wenzelm@6340
   116
wenzelm@7238
   117
syntax (HOL)
wenzelm@7357
   118
  "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
wenzelm@7357
   119
  "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
wenzelm@7357
   120
  "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
wenzelm@7238
   121
wenzelm@7238
   122
wenzelm@11750
   123
subsubsection {* Axioms and basic definitions *}
wenzelm@2260
   124
wenzelm@7357
   125
axioms
paulson@15380
   126
  eq_reflection:  "(x=y) ==> (x==y)"
clasohm@923
   127
paulson@15380
   128
  refl:           "t = (t::'a)"
paulson@6289
   129
paulson@15380
   130
  ext:            "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
paulson@15380
   131
    -- {*Extensionality is built into the meta-logic, and this rule expresses
paulson@15380
   132
         a related property.  It is an eta-expanded version of the traditional
paulson@15380
   133
         rule, and similar to the ABS rule of HOL*}
paulson@6289
   134
wenzelm@11432
   135
  the_eq_trivial: "(THE x. x = a) = (a::'a)"
clasohm@923
   136
paulson@15380
   137
  impI:           "(P ==> Q) ==> P-->Q"
paulson@15380
   138
  mp:             "[| P-->Q;  P |] ==> Q"
paulson@15380
   139
paulson@15380
   140
paulson@15380
   141
text{*Thanks to Stephan Merz*}
paulson@15380
   142
theorem subst:
paulson@15380
   143
  assumes eq: "s = t" and p: "P(s)"
paulson@15380
   144
  shows "P(t::'a)"
paulson@15380
   145
proof -
paulson@15380
   146
  from eq have meta: "s \<equiv> t"
paulson@15380
   147
    by (rule eq_reflection)
paulson@15380
   148
  from p show ?thesis
paulson@15380
   149
    by (unfold meta)
paulson@15380
   150
qed
clasohm@923
   151
clasohm@923
   152
defs
wenzelm@7357
   153
  True_def:     "True      == ((%x::bool. x) = (%x. x))"
wenzelm@7357
   154
  All_def:      "All(P)    == (P = (%x. True))"
paulson@11451
   155
  Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
wenzelm@7357
   156
  False_def:    "False     == (!P. P)"
wenzelm@7357
   157
  not_def:      "~ P       == P-->False"
wenzelm@7357
   158
  and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
wenzelm@7357
   159
  or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
wenzelm@7357
   160
  Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
clasohm@923
   161
wenzelm@7357
   162
axioms
wenzelm@7357
   163
  iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
wenzelm@7357
   164
  True_or_False:  "(P=True) | (P=False)"
clasohm@923
   165
clasohm@923
   166
defs
wenzelm@7357
   167
  Let_def:      "Let s f == f(s)"
paulson@11451
   168
  if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
wenzelm@5069
   169
skalberg@14223
   170
finalconsts
skalberg@14223
   171
  "op ="
skalberg@14223
   172
  "op -->"
skalberg@14223
   173
  The
skalberg@14223
   174
  arbitrary
nipkow@3320
   175
wenzelm@11750
   176
subsubsection {* Generic algebraic operations *}
wenzelm@4868
   177
wenzelm@12338
   178
axclass zero < type
wenzelm@12338
   179
axclass one < type
wenzelm@12338
   180
axclass plus < type
wenzelm@12338
   181
axclass minus < type
wenzelm@12338
   182
axclass times < type
wenzelm@12338
   183
axclass inverse < type
wenzelm@11750
   184
wenzelm@11750
   185
global
wenzelm@11750
   186
wenzelm@11750
   187
consts
wenzelm@11750
   188
  "0"           :: "'a::zero"                       ("0")
wenzelm@11750
   189
  "1"           :: "'a::one"                        ("1")
wenzelm@11750
   190
  "+"           :: "['a::plus, 'a]  => 'a"          (infixl 65)
wenzelm@11750
   191
  -             :: "['a::minus, 'a] => 'a"          (infixl 65)
wenzelm@11750
   192
  uminus        :: "['a::minus] => 'a"              ("- _" [81] 80)
wenzelm@11750
   193
  *             :: "['a::times, 'a] => 'a"          (infixl 70)
wenzelm@11750
   194
wenzelm@13456
   195
syntax
wenzelm@13456
   196
  "_index1"  :: index    ("\<^sub>1")
wenzelm@13456
   197
translations
wenzelm@14690
   198
  (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
wenzelm@13456
   199
wenzelm@11750
   200
local
wenzelm@11750
   201
wenzelm@11750
   202
typed_print_translation {*
wenzelm@11750
   203
  let
wenzelm@11750
   204
    fun tr' c = (c, fn show_sorts => fn T => fn ts =>
wenzelm@11750
   205
      if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
wenzelm@11750
   206
      else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);
wenzelm@11750
   207
  in [tr' "0", tr' "1"] end;
wenzelm@11750
   208
*} -- {* show types that are presumably too general *}
wenzelm@11750
   209
wenzelm@11750
   210
wenzelm@11750
   211
consts
wenzelm@11750
   212
  abs           :: "'a::minus => 'a"
wenzelm@11750
   213
  inverse       :: "'a::inverse => 'a"
wenzelm@11750
   214
  divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
wenzelm@11750
   215
wenzelm@11750
   216
syntax (xsymbols)
wenzelm@11750
   217
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
wenzelm@11750
   218
syntax (HTML output)
wenzelm@11750
   219
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
wenzelm@11750
   220
wenzelm@11750
   221
paulson@15411
   222
subsection {*Equality*}
paulson@15411
   223
paulson@15411
   224
lemma sym: "s=t ==> t=s"
paulson@15411
   225
apply (erule subst)
paulson@15411
   226
apply (rule refl)
paulson@15411
   227
done
paulson@15411
   228
paulson@15411
   229
(*calling "standard" reduces maxidx to 0*)
paulson@15411
   230
lemmas ssubst = sym [THEN subst, standard]
paulson@15411
   231
paulson@15411
   232
lemma trans: "[| r=s; s=t |] ==> r=t"
paulson@15411
   233
apply (erule subst , assumption)
paulson@15411
   234
done
paulson@15411
   235
paulson@15411
   236
lemma def_imp_eq:  assumes meq: "A == B" shows "A = B"
paulson@15411
   237
apply (unfold meq)
paulson@15411
   238
apply (rule refl)
paulson@15411
   239
done
paulson@15411
   240
paulson@15411
   241
(*Useful with eresolve_tac for proving equalties from known equalities.
paulson@15411
   242
        a = b
paulson@15411
   243
        |   |
paulson@15411
   244
        c = d   *)
paulson@15411
   245
lemma box_equals: "[| a=b;  a=c;  b=d |] ==> c=d"
paulson@15411
   246
apply (rule trans)
paulson@15411
   247
apply (rule trans)
paulson@15411
   248
apply (rule sym)
paulson@15411
   249
apply assumption+
paulson@15411
   250
done
paulson@15411
   251
nipkow@15524
   252
text {* For calculational reasoning: *}
nipkow@15524
   253
nipkow@15524
   254
lemma forw_subst: "a = b ==> P b ==> P a"
nipkow@15524
   255
  by (rule ssubst)
nipkow@15524
   256
nipkow@15524
   257
lemma back_subst: "P a ==> a = b ==> P b"
nipkow@15524
   258
  by (rule subst)
nipkow@15524
   259
paulson@15411
   260
paulson@15411
   261
subsection {*Congruence rules for application*}
paulson@15411
   262
paulson@15411
   263
(*similar to AP_THM in Gordon's HOL*)
paulson@15411
   264
lemma fun_cong: "(f::'a=>'b) = g ==> f(x)=g(x)"
paulson@15411
   265
apply (erule subst)
paulson@15411
   266
apply (rule refl)
paulson@15411
   267
done
paulson@15411
   268
paulson@15411
   269
(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)
paulson@15411
   270
lemma arg_cong: "x=y ==> f(x)=f(y)"
paulson@15411
   271
apply (erule subst)
paulson@15411
   272
apply (rule refl)
paulson@15411
   273
done
paulson@15411
   274
paulson@15655
   275
lemma arg_cong2: "\<lbrakk> a = b; c = d \<rbrakk> \<Longrightarrow> f a c = f b d"
paulson@15655
   276
apply (erule ssubst)+
paulson@15655
   277
apply (rule refl)
paulson@15655
   278
done
paulson@15655
   279
paulson@15655
   280
paulson@15411
   281
lemma cong: "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"
paulson@15411
   282
apply (erule subst)+
paulson@15411
   283
apply (rule refl)
paulson@15411
   284
done
paulson@15411
   285
paulson@15411
   286
paulson@15411
   287
subsection {*Equality of booleans -- iff*}
paulson@15411
   288
paulson@15411
   289
lemma iffI: assumes prems: "P ==> Q" "Q ==> P" shows "P=Q"
nipkow@17589
   290
apply (iprover intro: iff [THEN mp, THEN mp] impI prems)
paulson@15411
   291
done
paulson@15411
   292
paulson@15411
   293
lemma iffD2: "[| P=Q; Q |] ==> P"
paulson@15411
   294
apply (erule ssubst)
paulson@15411
   295
apply assumption
paulson@15411
   296
done
paulson@15411
   297
paulson@15411
   298
lemma rev_iffD2: "[| Q; P=Q |] ==> P"
paulson@15411
   299
apply (erule iffD2)
paulson@15411
   300
apply assumption
paulson@15411
   301
done
paulson@15411
   302
paulson@15411
   303
lemmas iffD1 = sym [THEN iffD2, standard]
paulson@15411
   304
lemmas rev_iffD1 = sym [THEN [2] rev_iffD2, standard]
paulson@15411
   305
paulson@15411
   306
lemma iffE:
paulson@15411
   307
  assumes major: "P=Q"
paulson@15411
   308
      and minor: "[| P --> Q; Q --> P |] ==> R"
paulson@15411
   309
  shows "R"
nipkow@17589
   310
by (iprover intro: minor impI major [THEN iffD2] major [THEN iffD1])
paulson@15411
   311
paulson@15411
   312
paulson@15411
   313
subsection {*True*}
paulson@15411
   314
paulson@15411
   315
lemma TrueI: "True"
paulson@15411
   316
apply (unfold True_def)
paulson@15411
   317
apply (rule refl)
paulson@15411
   318
done
paulson@15411
   319
paulson@15411
   320
lemma eqTrueI: "P ==> P=True"
nipkow@17589
   321
by (iprover intro: iffI TrueI)
paulson@15411
   322
paulson@15411
   323
lemma eqTrueE: "P=True ==> P"
paulson@15411
   324
apply (erule iffD2)
paulson@15411
   325
apply (rule TrueI)
paulson@15411
   326
done
paulson@15411
   327
paulson@15411
   328
paulson@15411
   329
subsection {*Universal quantifier*}
paulson@15411
   330
paulson@15411
   331
lemma allI: assumes p: "!!x::'a. P(x)" shows "ALL x. P(x)"
paulson@15411
   332
apply (unfold All_def)
nipkow@17589
   333
apply (iprover intro: ext eqTrueI p)
paulson@15411
   334
done
paulson@15411
   335
paulson@15411
   336
lemma spec: "ALL x::'a. P(x) ==> P(x)"
paulson@15411
   337
apply (unfold All_def)
paulson@15411
   338
apply (rule eqTrueE)
paulson@15411
   339
apply (erule fun_cong)
paulson@15411
   340
done
paulson@15411
   341
paulson@15411
   342
lemma allE:
paulson@15411
   343
  assumes major: "ALL x. P(x)"
paulson@15411
   344
      and minor: "P(x) ==> R"
paulson@15411
   345
  shows "R"
nipkow@17589
   346
by (iprover intro: minor major [THEN spec])
paulson@15411
   347
paulson@15411
   348
lemma all_dupE:
paulson@15411
   349
  assumes major: "ALL x. P(x)"
paulson@15411
   350
      and minor: "[| P(x); ALL x. P(x) |] ==> R"
paulson@15411
   351
  shows "R"
nipkow@17589
   352
by (iprover intro: minor major major [THEN spec])
paulson@15411
   353
paulson@15411
   354
paulson@15411
   355
subsection {*False*}
paulson@15411
   356
(*Depends upon spec; it is impossible to do propositional logic before quantifiers!*)
paulson@15411
   357
paulson@15411
   358
lemma FalseE: "False ==> P"
paulson@15411
   359
apply (unfold False_def)
paulson@15411
   360
apply (erule spec)
paulson@15411
   361
done
paulson@15411
   362
paulson@15411
   363
lemma False_neq_True: "False=True ==> P"
paulson@15411
   364
by (erule eqTrueE [THEN FalseE])
paulson@15411
   365
paulson@15411
   366
paulson@15411
   367
subsection {*Negation*}
paulson@15411
   368
paulson@15411
   369
lemma notI:
paulson@15411
   370
  assumes p: "P ==> False"
paulson@15411
   371
  shows "~P"
paulson@15411
   372
apply (unfold not_def)
nipkow@17589
   373
apply (iprover intro: impI p)
paulson@15411
   374
done
paulson@15411
   375
paulson@15411
   376
lemma False_not_True: "False ~= True"
paulson@15411
   377
apply (rule notI)
paulson@15411
   378
apply (erule False_neq_True)
paulson@15411
   379
done
paulson@15411
   380
paulson@15411
   381
lemma True_not_False: "True ~= False"
paulson@15411
   382
apply (rule notI)
paulson@15411
   383
apply (drule sym)
paulson@15411
   384
apply (erule False_neq_True)
paulson@15411
   385
done
paulson@15411
   386
paulson@15411
   387
lemma notE: "[| ~P;  P |] ==> R"
paulson@15411
   388
apply (unfold not_def)
paulson@15411
   389
apply (erule mp [THEN FalseE])
paulson@15411
   390
apply assumption
paulson@15411
   391
done
paulson@15411
   392
paulson@15411
   393
(* Alternative ~ introduction rule: [| P ==> ~ Pa; P ==> Pa |] ==> ~ P *)
paulson@15411
   394
lemmas notI2 = notE [THEN notI, standard]
paulson@15411
   395
paulson@15411
   396
paulson@15411
   397
subsection {*Implication*}
paulson@15411
   398
paulson@15411
   399
lemma impE:
paulson@15411
   400
  assumes "P-->Q" "P" "Q ==> R"
paulson@15411
   401
  shows "R"
nipkow@17589
   402
by (iprover intro: prems mp)
paulson@15411
   403
paulson@15411
   404
(* Reduces Q to P-->Q, allowing substitution in P. *)
paulson@15411
   405
lemma rev_mp: "[| P;  P --> Q |] ==> Q"
nipkow@17589
   406
by (iprover intro: mp)
paulson@15411
   407
paulson@15411
   408
lemma contrapos_nn:
paulson@15411
   409
  assumes major: "~Q"
paulson@15411
   410
      and minor: "P==>Q"
paulson@15411
   411
  shows "~P"
nipkow@17589
   412
by (iprover intro: notI minor major [THEN notE])
paulson@15411
   413
paulson@15411
   414
(*not used at all, but we already have the other 3 combinations *)
paulson@15411
   415
lemma contrapos_pn:
paulson@15411
   416
  assumes major: "Q"
paulson@15411
   417
      and minor: "P ==> ~Q"
paulson@15411
   418
  shows "~P"
nipkow@17589
   419
by (iprover intro: notI minor major notE)
paulson@15411
   420
paulson@15411
   421
lemma not_sym: "t ~= s ==> s ~= t"
paulson@15411
   422
apply (erule contrapos_nn)
paulson@15411
   423
apply (erule sym)
paulson@15411
   424
done
paulson@15411
   425
paulson@15411
   426
(*still used in HOLCF*)
paulson@15411
   427
lemma rev_contrapos:
paulson@15411
   428
  assumes pq: "P ==> Q"
paulson@15411
   429
      and nq: "~Q"
paulson@15411
   430
  shows "~P"
paulson@15411
   431
apply (rule nq [THEN contrapos_nn])
paulson@15411
   432
apply (erule pq)
paulson@15411
   433
done
paulson@15411
   434
paulson@15411
   435
subsection {*Existential quantifier*}
paulson@15411
   436
paulson@15411
   437
lemma exI: "P x ==> EX x::'a. P x"
paulson@15411
   438
apply (unfold Ex_def)
nipkow@17589
   439
apply (iprover intro: allI allE impI mp)
paulson@15411
   440
done
paulson@15411
   441
paulson@15411
   442
lemma exE:
paulson@15411
   443
  assumes major: "EX x::'a. P(x)"
paulson@15411
   444
      and minor: "!!x. P(x) ==> Q"
paulson@15411
   445
  shows "Q"
paulson@15411
   446
apply (rule major [unfolded Ex_def, THEN spec, THEN mp])
nipkow@17589
   447
apply (iprover intro: impI [THEN allI] minor)
paulson@15411
   448
done
paulson@15411
   449
paulson@15411
   450
paulson@15411
   451
subsection {*Conjunction*}
paulson@15411
   452
paulson@15411
   453
lemma conjI: "[| P; Q |] ==> P&Q"
paulson@15411
   454
apply (unfold and_def)
nipkow@17589
   455
apply (iprover intro: impI [THEN allI] mp)
paulson@15411
   456
done
paulson@15411
   457
paulson@15411
   458
lemma conjunct1: "[| P & Q |] ==> P"
paulson@15411
   459
apply (unfold and_def)
nipkow@17589
   460
apply (iprover intro: impI dest: spec mp)
paulson@15411
   461
done
paulson@15411
   462
paulson@15411
   463
lemma conjunct2: "[| P & Q |] ==> Q"
paulson@15411
   464
apply (unfold and_def)
nipkow@17589
   465
apply (iprover intro: impI dest: spec mp)
paulson@15411
   466
done
paulson@15411
   467
paulson@15411
   468
lemma conjE:
paulson@15411
   469
  assumes major: "P&Q"
paulson@15411
   470
      and minor: "[| P; Q |] ==> R"
paulson@15411
   471
  shows "R"
paulson@15411
   472
apply (rule minor)
paulson@15411
   473
apply (rule major [THEN conjunct1])
paulson@15411
   474
apply (rule major [THEN conjunct2])
paulson@15411
   475
done
paulson@15411
   476
paulson@15411
   477
lemma context_conjI:
paulson@15411
   478
  assumes prems: "P" "P ==> Q" shows "P & Q"
nipkow@17589
   479
by (iprover intro: conjI prems)
paulson@15411
   480
paulson@15411
   481
paulson@15411
   482
subsection {*Disjunction*}
paulson@15411
   483
paulson@15411
   484
lemma disjI1: "P ==> P|Q"
paulson@15411
   485
apply (unfold or_def)
nipkow@17589
   486
apply (iprover intro: allI impI mp)
paulson@15411
   487
done
paulson@15411
   488
paulson@15411
   489
lemma disjI2: "Q ==> P|Q"
paulson@15411
   490
apply (unfold or_def)
nipkow@17589
   491
apply (iprover intro: allI impI mp)
paulson@15411
   492
done
paulson@15411
   493
paulson@15411
   494
lemma disjE:
paulson@15411
   495
  assumes major: "P|Q"
paulson@15411
   496
      and minorP: "P ==> R"
paulson@15411
   497
      and minorQ: "Q ==> R"
paulson@15411
   498
  shows "R"
nipkow@17589
   499
by (iprover intro: minorP minorQ impI
paulson@15411
   500
                 major [unfolded or_def, THEN spec, THEN mp, THEN mp])
paulson@15411
   501
paulson@15411
   502
paulson@15411
   503
subsection {*Classical logic*}
paulson@15411
   504
paulson@15411
   505
paulson@15411
   506
lemma classical:
paulson@15411
   507
  assumes prem: "~P ==> P"
paulson@15411
   508
  shows "P"
paulson@15411
   509
apply (rule True_or_False [THEN disjE, THEN eqTrueE])
paulson@15411
   510
apply assumption
paulson@15411
   511
apply (rule notI [THEN prem, THEN eqTrueI])
paulson@15411
   512
apply (erule subst)
paulson@15411
   513
apply assumption
paulson@15411
   514
done
paulson@15411
   515
paulson@15411
   516
lemmas ccontr = FalseE [THEN classical, standard]
paulson@15411
   517
paulson@15411
   518
(*notE with premises exchanged; it discharges ~R so that it can be used to
paulson@15411
   519
  make elimination rules*)
paulson@15411
   520
lemma rev_notE:
paulson@15411
   521
  assumes premp: "P"
paulson@15411
   522
      and premnot: "~R ==> ~P"
paulson@15411
   523
  shows "R"
paulson@15411
   524
apply (rule ccontr)
paulson@15411
   525
apply (erule notE [OF premnot premp])
paulson@15411
   526
done
paulson@15411
   527
paulson@15411
   528
(*Double negation law*)
paulson@15411
   529
lemma notnotD: "~~P ==> P"
paulson@15411
   530
apply (rule classical)
paulson@15411
   531
apply (erule notE)
paulson@15411
   532
apply assumption
paulson@15411
   533
done
paulson@15411
   534
paulson@15411
   535
lemma contrapos_pp:
paulson@15411
   536
  assumes p1: "Q"
paulson@15411
   537
      and p2: "~P ==> ~Q"
paulson@15411
   538
  shows "P"
nipkow@17589
   539
by (iprover intro: classical p1 p2 notE)
paulson@15411
   540
paulson@15411
   541
paulson@15411
   542
subsection {*Unique existence*}
paulson@15411
   543
paulson@15411
   544
lemma ex1I:
paulson@15411
   545
  assumes prems: "P a" "!!x. P(x) ==> x=a"
paulson@15411
   546
  shows "EX! x. P(x)"
nipkow@17589
   547
by (unfold Ex1_def, iprover intro: prems exI conjI allI impI)
paulson@15411
   548
paulson@15411
   549
text{*Sometimes easier to use: the premises have no shared variables.  Safe!*}
paulson@15411
   550
lemma ex_ex1I:
paulson@15411
   551
  assumes ex_prem: "EX x. P(x)"
paulson@15411
   552
      and eq: "!!x y. [| P(x); P(y) |] ==> x=y"
paulson@15411
   553
  shows "EX! x. P(x)"
nipkow@17589
   554
by (iprover intro: ex_prem [THEN exE] ex1I eq)
paulson@15411
   555
paulson@15411
   556
lemma ex1E:
paulson@15411
   557
  assumes major: "EX! x. P(x)"
paulson@15411
   558
      and minor: "!!x. [| P(x);  ALL y. P(y) --> y=x |] ==> R"
paulson@15411
   559
  shows "R"
paulson@15411
   560
apply (rule major [unfolded Ex1_def, THEN exE])
paulson@15411
   561
apply (erule conjE)
nipkow@17589
   562
apply (iprover intro: minor)
paulson@15411
   563
done
paulson@15411
   564
paulson@15411
   565
lemma ex1_implies_ex: "EX! x. P x ==> EX x. P x"
paulson@15411
   566
apply (erule ex1E)
paulson@15411
   567
apply (rule exI)
paulson@15411
   568
apply assumption
paulson@15411
   569
done
paulson@15411
   570
paulson@15411
   571
paulson@15411
   572
subsection {*THE: definite description operator*}
paulson@15411
   573
paulson@15411
   574
lemma the_equality:
paulson@15411
   575
  assumes prema: "P a"
paulson@15411
   576
      and premx: "!!x. P x ==> x=a"
paulson@15411
   577
  shows "(THE x. P x) = a"
paulson@15411
   578
apply (rule trans [OF _ the_eq_trivial])
paulson@15411
   579
apply (rule_tac f = "The" in arg_cong)
paulson@15411
   580
apply (rule ext)
paulson@15411
   581
apply (rule iffI)
paulson@15411
   582
 apply (erule premx)
paulson@15411
   583
apply (erule ssubst, rule prema)
paulson@15411
   584
done
paulson@15411
   585
paulson@15411
   586
lemma theI:
paulson@15411
   587
  assumes "P a" and "!!x. P x ==> x=a"
paulson@15411
   588
  shows "P (THE x. P x)"
nipkow@17589
   589
by (iprover intro: prems the_equality [THEN ssubst])
paulson@15411
   590
paulson@15411
   591
lemma theI': "EX! x. P x ==> P (THE x. P x)"
paulson@15411
   592
apply (erule ex1E)
paulson@15411
   593
apply (erule theI)
paulson@15411
   594
apply (erule allE)
paulson@15411
   595
apply (erule mp)
paulson@15411
   596
apply assumption
paulson@15411
   597
done
paulson@15411
   598
paulson@15411
   599
(*Easier to apply than theI: only one occurrence of P*)
paulson@15411
   600
lemma theI2:
paulson@15411
   601
  assumes "P a" "!!x. P x ==> x=a" "!!x. P x ==> Q x"
paulson@15411
   602
  shows "Q (THE x. P x)"
nipkow@17589
   603
by (iprover intro: prems theI)
paulson@15411
   604
paulson@15411
   605
lemma the1_equality: "[| EX!x. P x; P a |] ==> (THE x. P x) = a"
paulson@15411
   606
apply (rule the_equality)
paulson@15411
   607
apply  assumption
paulson@15411
   608
apply (erule ex1E)
paulson@15411
   609
apply (erule all_dupE)
paulson@15411
   610
apply (drule mp)
paulson@15411
   611
apply  assumption
paulson@15411
   612
apply (erule ssubst)
paulson@15411
   613
apply (erule allE)
paulson@15411
   614
apply (erule mp)
paulson@15411
   615
apply assumption
paulson@15411
   616
done
paulson@15411
   617
paulson@15411
   618
lemma the_sym_eq_trivial: "(THE y. x=y) = x"
paulson@15411
   619
apply (rule the_equality)
paulson@15411
   620
apply (rule refl)
paulson@15411
   621
apply (erule sym)
paulson@15411
   622
done
paulson@15411
   623
paulson@15411
   624
paulson@15411
   625
subsection {*Classical intro rules for disjunction and existential quantifiers*}
paulson@15411
   626
paulson@15411
   627
lemma disjCI:
paulson@15411
   628
  assumes "~Q ==> P" shows "P|Q"
paulson@15411
   629
apply (rule classical)
nipkow@17589
   630
apply (iprover intro: prems disjI1 disjI2 notI elim: notE)
paulson@15411
   631
done
paulson@15411
   632
paulson@15411
   633
lemma excluded_middle: "~P | P"
nipkow@17589
   634
by (iprover intro: disjCI)
paulson@15411
   635
paulson@15411
   636
text{*case distinction as a natural deduction rule. Note that @{term "~P"}
paulson@15411
   637
   is the second case, not the first.*}
paulson@15411
   638
lemma case_split_thm:
paulson@15411
   639
  assumes prem1: "P ==> Q"
paulson@15411
   640
      and prem2: "~P ==> Q"
paulson@15411
   641
  shows "Q"
paulson@15411
   642
apply (rule excluded_middle [THEN disjE])
paulson@15411
   643
apply (erule prem2)
paulson@15411
   644
apply (erule prem1)
paulson@15411
   645
done
paulson@15411
   646
paulson@15411
   647
(*Classical implies (-->) elimination. *)
paulson@15411
   648
lemma impCE:
paulson@15411
   649
  assumes major: "P-->Q"
paulson@15411
   650
      and minor: "~P ==> R" "Q ==> R"
paulson@15411
   651
  shows "R"
paulson@15411
   652
apply (rule excluded_middle [of P, THEN disjE])
nipkow@17589
   653
apply (iprover intro: minor major [THEN mp])+
paulson@15411
   654
done
paulson@15411
   655
paulson@15411
   656
(*This version of --> elimination works on Q before P.  It works best for
paulson@15411
   657
  those cases in which P holds "almost everywhere".  Can't install as
paulson@15411
   658
  default: would break old proofs.*)
paulson@15411
   659
lemma impCE':
paulson@15411
   660
  assumes major: "P-->Q"
paulson@15411
   661
      and minor: "Q ==> R" "~P ==> R"
paulson@15411
   662
  shows "R"
paulson@15411
   663
apply (rule excluded_middle [of P, THEN disjE])
nipkow@17589
   664
apply (iprover intro: minor major [THEN mp])+
paulson@15411
   665
done
paulson@15411
   666
paulson@15411
   667
(*Classical <-> elimination. *)
paulson@15411
   668
lemma iffCE:
paulson@15411
   669
  assumes major: "P=Q"
paulson@15411
   670
      and minor: "[| P; Q |] ==> R"  "[| ~P; ~Q |] ==> R"
paulson@15411
   671
  shows "R"
paulson@15411
   672
apply (rule major [THEN iffE])
nipkow@17589
   673
apply (iprover intro: minor elim: impCE notE)
paulson@15411
   674
done
paulson@15411
   675
paulson@15411
   676
lemma exCI:
paulson@15411
   677
  assumes "ALL x. ~P(x) ==> P(a)"
paulson@15411
   678
  shows "EX x. P(x)"
paulson@15411
   679
apply (rule ccontr)
nipkow@17589
   680
apply (iprover intro: prems exI allI notI notE [of "\<exists>x. P x"])
paulson@15411
   681
done
paulson@15411
   682
paulson@15411
   683
paulson@15411
   684
wenzelm@11750
   685
subsection {* Theory and package setup *}
wenzelm@11750
   686
paulson@15411
   687
ML
paulson@15411
   688
{*
paulson@15411
   689
val eq_reflection = thm "eq_reflection"
paulson@15411
   690
val refl = thm "refl"
paulson@15411
   691
val subst = thm "subst"
paulson@15411
   692
val ext = thm "ext"
paulson@15411
   693
val impI = thm "impI"
paulson@15411
   694
val mp = thm "mp"
paulson@15411
   695
val True_def = thm "True_def"
paulson@15411
   696
val All_def = thm "All_def"
paulson@15411
   697
val Ex_def = thm "Ex_def"
paulson@15411
   698
val False_def = thm "False_def"
paulson@15411
   699
val not_def = thm "not_def"
paulson@15411
   700
val and_def = thm "and_def"
paulson@15411
   701
val or_def = thm "or_def"
paulson@15411
   702
val Ex1_def = thm "Ex1_def"
paulson@15411
   703
val iff = thm "iff"
paulson@15411
   704
val True_or_False = thm "True_or_False"
paulson@15411
   705
val Let_def = thm "Let_def"
paulson@15411
   706
val if_def = thm "if_def"
paulson@15411
   707
val sym = thm "sym"
paulson@15411
   708
val ssubst = thm "ssubst"
paulson@15411
   709
val trans = thm "trans"
paulson@15411
   710
val def_imp_eq = thm "def_imp_eq"
paulson@15411
   711
val box_equals = thm "box_equals"
paulson@15411
   712
val fun_cong = thm "fun_cong"
paulson@15411
   713
val arg_cong = thm "arg_cong"
paulson@15411
   714
val cong = thm "cong"
paulson@15411
   715
val iffI = thm "iffI"
paulson@15411
   716
val iffD2 = thm "iffD2"
paulson@15411
   717
val rev_iffD2 = thm "rev_iffD2"
paulson@15411
   718
val iffD1 = thm "iffD1"
paulson@15411
   719
val rev_iffD1 = thm "rev_iffD1"
paulson@15411
   720
val iffE = thm "iffE"
paulson@15411
   721
val TrueI = thm "TrueI"
paulson@15411
   722
val eqTrueI = thm "eqTrueI"
paulson@15411
   723
val eqTrueE = thm "eqTrueE"
paulson@15411
   724
val allI = thm "allI"
paulson@15411
   725
val spec = thm "spec"
paulson@15411
   726
val allE = thm "allE"
paulson@15411
   727
val all_dupE = thm "all_dupE"
paulson@15411
   728
val FalseE = thm "FalseE"
paulson@15411
   729
val False_neq_True = thm "False_neq_True"
paulson@15411
   730
val notI = thm "notI"
paulson@15411
   731
val False_not_True = thm "False_not_True"
paulson@15411
   732
val True_not_False = thm "True_not_False"
paulson@15411
   733
val notE = thm "notE"
paulson@15411
   734
val notI2 = thm "notI2"
paulson@15411
   735
val impE = thm "impE"
paulson@15411
   736
val rev_mp = thm "rev_mp"
paulson@15411
   737
val contrapos_nn = thm "contrapos_nn"
paulson@15411
   738
val contrapos_pn = thm "contrapos_pn"
paulson@15411
   739
val not_sym = thm "not_sym"
paulson@15411
   740
val rev_contrapos = thm "rev_contrapos"
paulson@15411
   741
val exI = thm "exI"
paulson@15411
   742
val exE = thm "exE"
paulson@15411
   743
val conjI = thm "conjI"
paulson@15411
   744
val conjunct1 = thm "conjunct1"
paulson@15411
   745
val conjunct2 = thm "conjunct2"
paulson@15411
   746
val conjE = thm "conjE"
paulson@15411
   747
val context_conjI = thm "context_conjI"
paulson@15411
   748
val disjI1 = thm "disjI1"
paulson@15411
   749
val disjI2 = thm "disjI2"
paulson@15411
   750
val disjE = thm "disjE"
paulson@15411
   751
val classical = thm "classical"
paulson@15411
   752
val ccontr = thm "ccontr"
paulson@15411
   753
val rev_notE = thm "rev_notE"
paulson@15411
   754
val notnotD = thm "notnotD"
paulson@15411
   755
val contrapos_pp = thm "contrapos_pp"
paulson@15411
   756
val ex1I = thm "ex1I"
paulson@15411
   757
val ex_ex1I = thm "ex_ex1I"
paulson@15411
   758
val ex1E = thm "ex1E"
paulson@15411
   759
val ex1_implies_ex = thm "ex1_implies_ex"
paulson@15411
   760
val the_equality = thm "the_equality"
paulson@15411
   761
val theI = thm "theI"
paulson@15411
   762
val theI' = thm "theI'"
paulson@15411
   763
val theI2 = thm "theI2"
paulson@15411
   764
val the1_equality = thm "the1_equality"
paulson@15411
   765
val the_sym_eq_trivial = thm "the_sym_eq_trivial"
paulson@15411
   766
val disjCI = thm "disjCI"
paulson@15411
   767
val excluded_middle = thm "excluded_middle"
paulson@15411
   768
val case_split_thm = thm "case_split_thm"
paulson@15411
   769
val impCE = thm "impCE"
paulson@15411
   770
val impCE = thm "impCE"
paulson@15411
   771
val iffCE = thm "iffCE"
paulson@15411
   772
val exCI = thm "exCI"
wenzelm@4868
   773
paulson@15411
   774
(* combination of (spec RS spec RS ...(j times) ... spec RS mp) *)
paulson@15411
   775
local
paulson@15411
   776
  fun wrong_prem (Const ("All", _) $ (Abs (_, _, t))) = wrong_prem t
paulson@15411
   777
  |   wrong_prem (Bound _) = true
paulson@15411
   778
  |   wrong_prem _ = false
skalberg@15570
   779
  val filter_right = List.filter (fn t => not (wrong_prem (HOLogic.dest_Trueprop (hd (Thm.prems_of t)))))
paulson@15411
   780
in
paulson@15411
   781
  fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp])
paulson@15411
   782
  fun smp_tac j = EVERY'[dresolve_tac (smp j), atac]
paulson@15411
   783
end
paulson@15411
   784
paulson@15411
   785
paulson@15411
   786
fun strip_tac i = REPEAT(resolve_tac [impI,allI] i)
paulson@15411
   787
paulson@15411
   788
(*Obsolete form of disjunctive case analysis*)
paulson@15411
   789
fun excluded_middle_tac sP =
paulson@15411
   790
    res_inst_tac [("Q",sP)] (excluded_middle RS disjE)
paulson@15411
   791
paulson@15411
   792
fun case_tac a = res_inst_tac [("P",a)] case_split_thm
paulson@15411
   793
*}
paulson@15411
   794
wenzelm@11687
   795
theorems case_split = case_split_thm [case_names True False]
wenzelm@9869
   796
wenzelm@12386
   797
wenzelm@12386
   798
subsubsection {* Intuitionistic Reasoning *}
wenzelm@12386
   799
wenzelm@12386
   800
lemma impE':
wenzelm@12937
   801
  assumes 1: "P --> Q"
wenzelm@12937
   802
    and 2: "Q ==> R"
wenzelm@12937
   803
    and 3: "P --> Q ==> P"
wenzelm@12937
   804
  shows R
wenzelm@12386
   805
proof -
wenzelm@12386
   806
  from 3 and 1 have P .
wenzelm@12386
   807
  with 1 have Q by (rule impE)
wenzelm@12386
   808
  with 2 show R .
wenzelm@12386
   809
qed
wenzelm@12386
   810
wenzelm@12386
   811
lemma allE':
wenzelm@12937
   812
  assumes 1: "ALL x. P x"
wenzelm@12937
   813
    and 2: "P x ==> ALL x. P x ==> Q"
wenzelm@12937
   814
  shows Q
wenzelm@12386
   815
proof -
wenzelm@12386
   816
  from 1 have "P x" by (rule spec)
wenzelm@12386
   817
  from this and 1 show Q by (rule 2)
wenzelm@12386
   818
qed
wenzelm@12386
   819
wenzelm@12937
   820
lemma notE':
wenzelm@12937
   821
  assumes 1: "~ P"
wenzelm@12937
   822
    and 2: "~ P ==> P"
wenzelm@12937
   823
  shows R
wenzelm@12386
   824
proof -
wenzelm@12386
   825
  from 2 and 1 have P .
wenzelm@12386
   826
  with 1 show R by (rule notE)
wenzelm@12386
   827
qed
wenzelm@12386
   828
wenzelm@15801
   829
lemmas [Pure.elim!] = disjE iffE FalseE conjE exE
wenzelm@15801
   830
  and [Pure.intro!] = iffI conjI impI TrueI notI allI refl
wenzelm@15801
   831
  and [Pure.elim 2] = allE notE' impE'
wenzelm@15801
   832
  and [Pure.intro] = exI disjI2 disjI1
wenzelm@12386
   833
wenzelm@12386
   834
lemmas [trans] = trans
wenzelm@12386
   835
  and [sym] = sym not_sym
wenzelm@15801
   836
  and [Pure.elim?] = iffD1 iffD2 impE
wenzelm@11750
   837
wenzelm@11438
   838
wenzelm@11750
   839
subsubsection {* Atomizing meta-level connectives *}
wenzelm@11750
   840
wenzelm@11750
   841
lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
wenzelm@12003
   842
proof
wenzelm@9488
   843
  assume "!!x. P x"
wenzelm@10383
   844
  show "ALL x. P x" by (rule allI)
wenzelm@9488
   845
next
wenzelm@9488
   846
  assume "ALL x. P x"
wenzelm@10383
   847
  thus "!!x. P x" by (rule allE)
wenzelm@9488
   848
qed
wenzelm@9488
   849
wenzelm@11750
   850
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
wenzelm@12003
   851
proof
wenzelm@9488
   852
  assume r: "A ==> B"
wenzelm@10383
   853
  show "A --> B" by (rule impI) (rule r)
wenzelm@9488
   854
next
wenzelm@9488
   855
  assume "A --> B" and A
wenzelm@10383
   856
  thus B by (rule mp)
wenzelm@9488
   857
qed
wenzelm@9488
   858
paulson@14749
   859
lemma atomize_not: "(A ==> False) == Trueprop (~A)"
paulson@14749
   860
proof
paulson@14749
   861
  assume r: "A ==> False"
paulson@14749
   862
  show "~A" by (rule notI) (rule r)
paulson@14749
   863
next
paulson@14749
   864
  assume "~A" and A
paulson@14749
   865
  thus False by (rule notE)
paulson@14749
   866
qed
paulson@14749
   867
wenzelm@11750
   868
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
wenzelm@12003
   869
proof
wenzelm@10432
   870
  assume "x == y"
wenzelm@10432
   871
  show "x = y" by (unfold prems) (rule refl)
wenzelm@10432
   872
next
wenzelm@10432
   873
  assume "x = y"
wenzelm@10432
   874
  thus "x == y" by (rule eq_reflection)
wenzelm@10432
   875
qed
wenzelm@10432
   876
wenzelm@12023
   877
lemma atomize_conj [atomize]:
wenzelm@12023
   878
  "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
wenzelm@12003
   879
proof
wenzelm@11953
   880
  assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
wenzelm@11953
   881
  show "A & B" by (rule conjI)
wenzelm@11953
   882
next
wenzelm@11953
   883
  fix C
wenzelm@11953
   884
  assume "A & B"
wenzelm@11953
   885
  assume "A ==> B ==> PROP C"
wenzelm@11953
   886
  thus "PROP C"
wenzelm@11953
   887
  proof this
wenzelm@11953
   888
    show A by (rule conjunct1)
wenzelm@11953
   889
    show B by (rule conjunct2)
wenzelm@11953
   890
  qed
wenzelm@11953
   891
qed
wenzelm@11953
   892
wenzelm@12386
   893
lemmas [symmetric, rulify] = atomize_all atomize_imp
wenzelm@12386
   894
wenzelm@11750
   895
wenzelm@11750
   896
subsubsection {* Classical Reasoner setup *}
wenzelm@9529
   897
wenzelm@10383
   898
use "cladata.ML"
wenzelm@10383
   899
setup hypsubst_setup
wenzelm@11977
   900
wenzelm@16121
   901
setup {*
wenzelm@16121
   902
  [ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac)]
wenzelm@12386
   903
*}
wenzelm@11977
   904
wenzelm@10383
   905
setup Classical.setup
wenzelm@10383
   906
setup clasetup
wenzelm@10383
   907
wenzelm@12386
   908
lemmas [intro?] = ext
wenzelm@12386
   909
  and [elim?] = ex1_implies_ex
wenzelm@11977
   910
wenzelm@9869
   911
use "blastdata.ML"
wenzelm@9869
   912
setup Blast.setup
wenzelm@4868
   913
wenzelm@11750
   914
wenzelm@17459
   915
subsubsection {* Simplifier setup *}
wenzelm@11750
   916
wenzelm@12281
   917
lemma meta_eq_to_obj_eq: "x == y ==> x = y"
wenzelm@12281
   918
proof -
wenzelm@12281
   919
  assume r: "x == y"
wenzelm@12281
   920
  show "x = y" by (unfold r) (rule refl)
wenzelm@12281
   921
qed
wenzelm@12281
   922
wenzelm@12281
   923
lemma eta_contract_eq: "(%s. f s) = f" ..
wenzelm@12281
   924
wenzelm@12281
   925
lemma simp_thms:
wenzelm@12937
   926
  shows not_not: "(~ ~ P) = P"
nipkow@15354
   927
  and Not_eq_iff: "((~P) = (~Q)) = (P = Q)"
wenzelm@12937
   928
  and
berghofe@12436
   929
    "(P ~= Q) = (P = (~Q))"
berghofe@12436
   930
    "(P | ~P) = True"    "(~P | P) = True"
wenzelm@12281
   931
    "(x = x) = True"
wenzelm@12281
   932
    "(~True) = False"  "(~False) = True"
berghofe@12436
   933
    "(~P) ~= P"  "P ~= (~P)"
wenzelm@12281
   934
    "(True=P) = P"  "(P=True) = P"  "(False=P) = (~P)"  "(P=False) = (~P)"
wenzelm@12281
   935
    "(True --> P) = P"  "(False --> P) = True"
wenzelm@12281
   936
    "(P --> True) = True"  "(P --> P) = True"
wenzelm@12281
   937
    "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
wenzelm@12281
   938
    "(P & True) = P"  "(True & P) = P"
wenzelm@12281
   939
    "(P & False) = False"  "(False & P) = False"
wenzelm@12281
   940
    "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
wenzelm@12281
   941
    "(P & ~P) = False"    "(~P & P) = False"
wenzelm@12281
   942
    "(P | True) = True"  "(True | P) = True"
wenzelm@12281
   943
    "(P | False) = P"  "(False | P) = P"
berghofe@12436
   944
    "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
wenzelm@12281
   945
    "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
wenzelm@12281
   946
    -- {* needed for the one-point-rule quantifier simplification procs *}
wenzelm@12281
   947
    -- {* essential for termination!! *} and
wenzelm@12281
   948
    "!!P. (EX x. x=t & P(x)) = P(t)"
wenzelm@12281
   949
    "!!P. (EX x. t=x & P(x)) = P(t)"
wenzelm@12281
   950
    "!!P. (ALL x. x=t --> P(x)) = P(t)"
wenzelm@12937
   951
    "!!P. (ALL x. t=x --> P(x)) = P(t)"
nipkow@17589
   952
  by (blast, blast, blast, blast, blast, iprover+)
wenzelm@13421
   953
wenzelm@12281
   954
lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
nipkow@17589
   955
  by iprover
wenzelm@12281
   956
wenzelm@12281
   957
lemma ex_simps:
wenzelm@12281
   958
  "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
wenzelm@12281
   959
  "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
wenzelm@12281
   960
  "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
wenzelm@12281
   961
  "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
wenzelm@12281
   962
  "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
wenzelm@12281
   963
  "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
wenzelm@12281
   964
  -- {* Miniscoping: pushing in existential quantifiers. *}
nipkow@17589
   965
  by (iprover | blast)+
wenzelm@12281
   966
wenzelm@12281
   967
lemma all_simps:
wenzelm@12281
   968
  "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
wenzelm@12281
   969
  "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
wenzelm@12281
   970
  "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
wenzelm@12281
   971
  "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
wenzelm@12281
   972
  "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
wenzelm@12281
   973
  "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
wenzelm@12281
   974
  -- {* Miniscoping: pushing in universal quantifiers. *}
nipkow@17589
   975
  by (iprover | blast)+
wenzelm@12281
   976
paulson@14201
   977
lemma disj_absorb: "(A | A) = A"
paulson@14201
   978
  by blast
paulson@14201
   979
paulson@14201
   980
lemma disj_left_absorb: "(A | (A | B)) = (A | B)"
paulson@14201
   981
  by blast
paulson@14201
   982
paulson@14201
   983
lemma conj_absorb: "(A & A) = A"
paulson@14201
   984
  by blast
paulson@14201
   985
paulson@14201
   986
lemma conj_left_absorb: "(A & (A & B)) = (A & B)"
paulson@14201
   987
  by blast
paulson@14201
   988
wenzelm@12281
   989
lemma eq_ac:
wenzelm@12937
   990
  shows eq_commute: "(a=b) = (b=a)"
wenzelm@12937
   991
    and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
nipkow@17589
   992
    and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (iprover, blast+)
nipkow@17589
   993
lemma neq_commute: "(a~=b) = (b~=a)" by iprover
wenzelm@12281
   994
wenzelm@12281
   995
lemma conj_comms:
wenzelm@12937
   996
  shows conj_commute: "(P&Q) = (Q&P)"
nipkow@17589
   997
    and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by iprover+
nipkow@17589
   998
lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by iprover
wenzelm@12281
   999
wenzelm@12281
  1000
lemma disj_comms:
wenzelm@12937
  1001
  shows disj_commute: "(P|Q) = (Q|P)"
nipkow@17589
  1002
    and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by iprover+
nipkow@17589
  1003
lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by iprover
wenzelm@12281
  1004
nipkow@17589
  1005
lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by iprover
nipkow@17589
  1006
lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by iprover
wenzelm@12281
  1007
nipkow@17589
  1008
lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by iprover
nipkow@17589
  1009
lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by iprover
wenzelm@12281
  1010
nipkow@17589
  1011
lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by iprover
nipkow@17589
  1012
lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by iprover
nipkow@17589
  1013
lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by iprover
wenzelm@12281
  1014
wenzelm@12281
  1015
text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
wenzelm@12281
  1016
lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
wenzelm@12281
  1017
lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
wenzelm@12281
  1018
wenzelm@12281
  1019
lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
wenzelm@12281
  1020
lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
wenzelm@12281
  1021
nipkow@17589
  1022
lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by iprover
wenzelm@12281
  1023
lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
wenzelm@12281
  1024
lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
wenzelm@12281
  1025
lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
wenzelm@12281
  1026
lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
wenzelm@12281
  1027
lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
wenzelm@12281
  1028
  by blast
wenzelm@12281
  1029
lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
wenzelm@12281
  1030
nipkow@17589
  1031
lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by iprover
wenzelm@12281
  1032
wenzelm@12281
  1033
wenzelm@12281
  1034
lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
wenzelm@12281
  1035
  -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
wenzelm@12281
  1036
  -- {* cases boil down to the same thing. *}
wenzelm@12281
  1037
  by blast
wenzelm@12281
  1038
wenzelm@12281
  1039
lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
wenzelm@12281
  1040
lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
nipkow@17589
  1041
lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by iprover
nipkow@17589
  1042
lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by iprover
wenzelm@12281
  1043
nipkow@17589
  1044
lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by iprover
nipkow@17589
  1045
lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by iprover
wenzelm@12281
  1046
wenzelm@12281
  1047
text {*
wenzelm@12281
  1048
  \medskip The @{text "&"} congruence rule: not included by default!
wenzelm@12281
  1049
  May slow rewrite proofs down by as much as 50\% *}
wenzelm@12281
  1050
wenzelm@12281
  1051
lemma conj_cong:
wenzelm@12281
  1052
    "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
nipkow@17589
  1053
  by iprover
wenzelm@12281
  1054
wenzelm@12281
  1055
lemma rev_conj_cong:
wenzelm@12281
  1056
    "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
nipkow@17589
  1057
  by iprover
wenzelm@12281
  1058
wenzelm@12281
  1059
text {* The @{text "|"} congruence rule: not included by default! *}
wenzelm@12281
  1060
wenzelm@12281
  1061
lemma disj_cong:
wenzelm@12281
  1062
    "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
wenzelm@12281
  1063
  by blast
wenzelm@12281
  1064
wenzelm@12281
  1065
lemma eq_sym_conv: "(x = y) = (y = x)"
nipkow@17589
  1066
  by iprover
wenzelm@12281
  1067
wenzelm@12281
  1068
wenzelm@12281
  1069
text {* \medskip if-then-else rules *}
wenzelm@12281
  1070
wenzelm@12281
  1071
lemma if_True: "(if True then x else y) = x"
wenzelm@12281
  1072
  by (unfold if_def) blast
wenzelm@12281
  1073
wenzelm@12281
  1074
lemma if_False: "(if False then x else y) = y"
wenzelm@12281
  1075
  by (unfold if_def) blast
wenzelm@12281
  1076
wenzelm@12281
  1077
lemma if_P: "P ==> (if P then x else y) = x"
wenzelm@12281
  1078
  by (unfold if_def) blast
wenzelm@12281
  1079
wenzelm@12281
  1080
lemma if_not_P: "~P ==> (if P then x else y) = y"
wenzelm@12281
  1081
  by (unfold if_def) blast
wenzelm@12281
  1082
wenzelm@12281
  1083
lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
wenzelm@12281
  1084
  apply (rule case_split [of Q])
paulson@15481
  1085
   apply (simplesubst if_P)
paulson@15481
  1086
    prefer 3 apply (simplesubst if_not_P, blast+)
wenzelm@12281
  1087
  done
wenzelm@12281
  1088
wenzelm@12281
  1089
lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
paulson@15481
  1090
by (simplesubst split_if, blast)
wenzelm@12281
  1091
wenzelm@12281
  1092
lemmas if_splits = split_if split_if_asm
wenzelm@12281
  1093
wenzelm@12281
  1094
lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
wenzelm@12281
  1095
  by (rule split_if)
wenzelm@12281
  1096
wenzelm@12281
  1097
lemma if_cancel: "(if c then x else x) = x"
paulson@15481
  1098
by (simplesubst split_if, blast)
wenzelm@12281
  1099
wenzelm@12281
  1100
lemma if_eq_cancel: "(if x = y then y else x) = x"
paulson@15481
  1101
by (simplesubst split_if, blast)
wenzelm@12281
  1102
wenzelm@12281
  1103
lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
wenzelm@12281
  1104
  -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
wenzelm@12281
  1105
  by (rule split_if)
wenzelm@12281
  1106
wenzelm@12281
  1107
lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
wenzelm@12281
  1108
  -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
paulson@15481
  1109
  apply (simplesubst split_if, blast)
wenzelm@12281
  1110
  done
wenzelm@12281
  1111
nipkow@17589
  1112
lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) iprover
nipkow@17589
  1113
lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) iprover
wenzelm@12281
  1114
schirmer@15423
  1115
text {* \medskip let rules for simproc *}
schirmer@15423
  1116
schirmer@15423
  1117
lemma Let_folded: "f x \<equiv> g x \<Longrightarrow>  Let x f \<equiv> Let x g"
schirmer@15423
  1118
  by (unfold Let_def)
schirmer@15423
  1119
schirmer@15423
  1120
lemma Let_unfold: "f x \<equiv> g \<Longrightarrow>  Let x f \<equiv> g"
schirmer@15423
  1121
  by (unfold Let_def)
schirmer@15423
  1122
berghofe@16633
  1123
text {*
ballarin@16999
  1124
  The following copy of the implication operator is useful for
ballarin@16999
  1125
  fine-tuning congruence rules.  It instructs the simplifier to simplify
ballarin@16999
  1126
  its premise.
berghofe@16633
  1127
*}
berghofe@16633
  1128
wenzelm@17197
  1129
constdefs
wenzelm@17197
  1130
  simp_implies :: "[prop, prop] => prop"  (infixr "=simp=>" 1)
wenzelm@17197
  1131
  "simp_implies \<equiv> op ==>"
berghofe@16633
  1132
berghofe@16633
  1133
lemma simp_impliesI: 
berghofe@16633
  1134
  assumes PQ: "(PROP P \<Longrightarrow> PROP Q)"
berghofe@16633
  1135
  shows "PROP P =simp=> PROP Q"
berghofe@16633
  1136
  apply (unfold simp_implies_def)
berghofe@16633
  1137
  apply (rule PQ)
berghofe@16633
  1138
  apply assumption
berghofe@16633
  1139
  done
berghofe@16633
  1140
berghofe@16633
  1141
lemma simp_impliesE:
berghofe@16633
  1142
  assumes PQ:"PROP P =simp=> PROP Q"
berghofe@16633
  1143
  and P: "PROP P"
berghofe@16633
  1144
  and QR: "PROP Q \<Longrightarrow> PROP R"
berghofe@16633
  1145
  shows "PROP R"
berghofe@16633
  1146
  apply (rule QR)
berghofe@16633
  1147
  apply (rule PQ [unfolded simp_implies_def])
berghofe@16633
  1148
  apply (rule P)
berghofe@16633
  1149
  done
berghofe@16633
  1150
berghofe@16633
  1151
lemma simp_implies_cong:
berghofe@16633
  1152
  assumes PP' :"PROP P == PROP P'"
berghofe@16633
  1153
  and P'QQ': "PROP P' ==> (PROP Q == PROP Q')"
berghofe@16633
  1154
  shows "(PROP P =simp=> PROP Q) == (PROP P' =simp=> PROP Q')"
berghofe@16633
  1155
proof (unfold simp_implies_def, rule equal_intr_rule)
berghofe@16633
  1156
  assume PQ: "PROP P \<Longrightarrow> PROP Q"
berghofe@16633
  1157
  and P': "PROP P'"
berghofe@16633
  1158
  from PP' [symmetric] and P' have "PROP P"
berghofe@16633
  1159
    by (rule equal_elim_rule1)
berghofe@16633
  1160
  hence "PROP Q" by (rule PQ)
berghofe@16633
  1161
  with P'QQ' [OF P'] show "PROP Q'" by (rule equal_elim_rule1)
berghofe@16633
  1162
next
berghofe@16633
  1163
  assume P'Q': "PROP P' \<Longrightarrow> PROP Q'"
berghofe@16633
  1164
  and P: "PROP P"
berghofe@16633
  1165
  from PP' and P have P': "PROP P'" by (rule equal_elim_rule1)
berghofe@16633
  1166
  hence "PROP Q'" by (rule P'Q')
berghofe@16633
  1167
  with P'QQ' [OF P', symmetric] show "PROP Q"
berghofe@16633
  1168
    by (rule equal_elim_rule1)
berghofe@16633
  1169
qed
berghofe@16633
  1170
wenzelm@17459
  1171
wenzelm@17459
  1172
text {* \medskip Actual Installation of the Simplifier. *}
paulson@14201
  1173
wenzelm@9869
  1174
use "simpdata.ML"
wenzelm@9869
  1175
setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
wenzelm@9869
  1176
setup Splitter.setup setup Clasimp.setup
wenzelm@9869
  1177
paulson@15481
  1178
wenzelm@17459
  1179
text {* \medskip Lucas Dixon's eqstep tactic. *}
paulson@15481
  1180
paulson@15481
  1181
use "~~/src/Provers/eqsubst.ML";
paulson@15481
  1182
use "eqrule_HOL_data.ML";
wenzelm@17459
  1183
setup EQSubstTac.setup
paulson@15481
  1184
wenzelm@17459
  1185
wenzelm@17459
  1186
subsubsection {* Code generator setup *}
wenzelm@17459
  1187
wenzelm@17459
  1188
types_code
wenzelm@17459
  1189
  "bool"  ("bool")
wenzelm@17459
  1190
attach (term_of) {*
wenzelm@17459
  1191
fun term_of_bool b = if b then HOLogic.true_const else HOLogic.false_const;
wenzelm@17459
  1192
*}
wenzelm@17459
  1193
attach (test) {*
wenzelm@17459
  1194
fun gen_bool i = one_of [false, true];
wenzelm@17459
  1195
*}
wenzelm@17459
  1196
wenzelm@17459
  1197
consts_code
wenzelm@17459
  1198
  "True"    ("true")
wenzelm@17459
  1199
  "False"   ("false")
wenzelm@17459
  1200
  "Not"     ("not")
wenzelm@17459
  1201
  "op |"    ("(_ orelse/ _)")
wenzelm@17459
  1202
  "op &"    ("(_ andalso/ _)")
wenzelm@17459
  1203
  "HOL.If"      ("(if _/ then _/ else _)")
wenzelm@17459
  1204
wenzelm@17459
  1205
ML {*
wenzelm@17459
  1206
local
wenzelm@17459
  1207
wenzelm@17459
  1208
fun eq_codegen thy defs gr dep thyname b t =
wenzelm@17459
  1209
    (case strip_comb t of
wenzelm@17459
  1210
       (Const ("op =", Type (_, [Type ("fun", _), _])), _) => NONE
wenzelm@17459
  1211
     | (Const ("op =", _), [t, u]) =>
wenzelm@17459
  1212
          let
wenzelm@17459
  1213
            val (gr', pt) = Codegen.invoke_codegen thy defs dep thyname false (gr, t);
berghofe@17639
  1214
            val (gr'', pu) = Codegen.invoke_codegen thy defs dep thyname false (gr', u);
berghofe@17639
  1215
            val (gr''', _) = Codegen.invoke_tycodegen thy defs dep thyname false (gr'', HOLogic.boolT)
wenzelm@17459
  1216
          in
berghofe@17639
  1217
            SOME (gr''', Codegen.parens
wenzelm@17459
  1218
              (Pretty.block [pt, Pretty.str " =", Pretty.brk 1, pu]))
wenzelm@17459
  1219
          end
wenzelm@17459
  1220
     | (t as Const ("op =", _), ts) => SOME (Codegen.invoke_codegen
wenzelm@17459
  1221
         thy defs dep thyname b (gr, Codegen.eta_expand t ts 2))
wenzelm@17459
  1222
     | _ => NONE);
wenzelm@17459
  1223
wenzelm@17459
  1224
in
wenzelm@17459
  1225
wenzelm@17459
  1226
val eq_codegen_setup = [Codegen.add_codegen "eq_codegen" eq_codegen];
wenzelm@17459
  1227
wenzelm@17459
  1228
end;
wenzelm@17459
  1229
*}
wenzelm@17459
  1230
wenzelm@17459
  1231
setup eq_codegen_setup
paulson@15481
  1232
paulson@15481
  1233
paulson@15481
  1234
subsection {* Other simple lemmas *}
paulson@15481
  1235
paulson@15411
  1236
declare disj_absorb [simp] conj_absorb [simp]
paulson@14201
  1237
nipkow@13723
  1238
lemma ex1_eq[iff]: "EX! x. x = t" "EX! x. t = x"
nipkow@13723
  1239
by blast+
nipkow@13723
  1240
paulson@15481
  1241
berghofe@13638
  1242
theorem choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
berghofe@13638
  1243
  apply (rule iffI)
berghofe@13638
  1244
  apply (rule_tac a = "%x. THE y. P x y" in ex1I)
berghofe@13638
  1245
  apply (fast dest!: theI')
berghofe@13638
  1246
  apply (fast intro: ext the1_equality [symmetric])
berghofe@13638
  1247
  apply (erule ex1E)
berghofe@13638
  1248
  apply (rule allI)
berghofe@13638
  1249
  apply (rule ex1I)
berghofe@13638
  1250
  apply (erule spec)
berghofe@13638
  1251
  apply (erule_tac x = "%z. if z = x then y else f z" in allE)
berghofe@13638
  1252
  apply (erule impE)
berghofe@13638
  1253
  apply (rule allI)
berghofe@13638
  1254
  apply (rule_tac P = "xa = x" in case_split_thm)
paulson@14208
  1255
  apply (drule_tac [3] x = x in fun_cong, simp_all)
berghofe@13638
  1256
  done
berghofe@13638
  1257
nipkow@13438
  1258
text{*Needs only HOL-lemmas:*}
nipkow@13438
  1259
lemma mk_left_commute:
nipkow@13438
  1260
  assumes a: "\<And>x y z. f (f x y) z = f x (f y z)" and
nipkow@13438
  1261
          c: "\<And>x y. f x y = f y x"
nipkow@13438
  1262
  shows "f x (f y z) = f y (f x z)"
nipkow@13438
  1263
by(rule trans[OF trans[OF c a] arg_cong[OF c, of "f y"]])
nipkow@13438
  1264
wenzelm@11750
  1265
paulson@15481
  1266
subsection {* Generic cases and induction *}
wenzelm@11824
  1267
wenzelm@11824
  1268
constdefs
wenzelm@11989
  1269
  induct_forall :: "('a => bool) => bool"
wenzelm@11989
  1270
  "induct_forall P == \<forall>x. P x"
wenzelm@11989
  1271
  induct_implies :: "bool => bool => bool"
wenzelm@11989
  1272
  "induct_implies A B == A --> B"
wenzelm@11989
  1273
  induct_equal :: "'a => 'a => bool"
wenzelm@11989
  1274
  "induct_equal x y == x = y"
wenzelm@11989
  1275
  induct_conj :: "bool => bool => bool"
wenzelm@11989
  1276
  "induct_conj A B == A & B"
wenzelm@11824
  1277
wenzelm@11989
  1278
lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
wenzelm@11989
  1279
  by (simp only: atomize_all induct_forall_def)
wenzelm@11824
  1280
wenzelm@11989
  1281
lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
wenzelm@11989
  1282
  by (simp only: atomize_imp induct_implies_def)
wenzelm@11824
  1283
wenzelm@11989
  1284
lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
wenzelm@11989
  1285
  by (simp only: atomize_eq induct_equal_def)
wenzelm@11824
  1286
wenzelm@11989
  1287
lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
wenzelm@11989
  1288
    induct_conj (induct_forall A) (induct_forall B)"
nipkow@17589
  1289
  by (unfold induct_forall_def induct_conj_def) iprover
wenzelm@11824
  1290
wenzelm@11989
  1291
lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
wenzelm@11989
  1292
    induct_conj (induct_implies C A) (induct_implies C B)"
nipkow@17589
  1293
  by (unfold induct_implies_def induct_conj_def) iprover
wenzelm@11989
  1294
berghofe@13598
  1295
lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
berghofe@13598
  1296
proof
berghofe@13598
  1297
  assume r: "induct_conj A B ==> PROP C" and A B
berghofe@13598
  1298
  show "PROP C" by (rule r) (simp! add: induct_conj_def)
berghofe@13598
  1299
next
berghofe@13598
  1300
  assume r: "A ==> B ==> PROP C" and "induct_conj A B"
berghofe@13598
  1301
  show "PROP C" by (rule r) (simp! add: induct_conj_def)+
berghofe@13598
  1302
qed
wenzelm@11824
  1303
wenzelm@11989
  1304
lemma induct_impliesI: "(A ==> B) ==> induct_implies A B"
wenzelm@11989
  1305
  by (simp add: induct_implies_def)
wenzelm@11824
  1306
wenzelm@12161
  1307
lemmas induct_atomize = atomize_conj induct_forall_eq induct_implies_eq induct_equal_eq
wenzelm@12161
  1308
lemmas induct_rulify1 [symmetric, standard] = induct_forall_eq induct_implies_eq induct_equal_eq
wenzelm@12161
  1309
lemmas induct_rulify2 = induct_forall_def induct_implies_def induct_equal_def induct_conj_def
wenzelm@11989
  1310
lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
wenzelm@11824
  1311
wenzelm@11989
  1312
hide const induct_forall induct_implies induct_equal induct_conj
wenzelm@11824
  1313
wenzelm@11824
  1314
wenzelm@11824
  1315
text {* Method setup. *}
wenzelm@11824
  1316
wenzelm@11824
  1317
ML {*
wenzelm@11824
  1318
  structure InductMethod = InductMethodFun
wenzelm@11824
  1319
  (struct
paulson@15411
  1320
    val dest_concls = HOLogic.dest_concls
paulson@15411
  1321
    val cases_default = thm "case_split"
paulson@15411
  1322
    val local_impI = thm "induct_impliesI"
paulson@15411
  1323
    val conjI = thm "conjI"
paulson@15411
  1324
    val atomize = thms "induct_atomize"
paulson@15411
  1325
    val rulify1 = thms "induct_rulify1"
paulson@15411
  1326
    val rulify2 = thms "induct_rulify2"
paulson@15411
  1327
    val localize = [Thm.symmetric (thm "induct_implies_def")]
wenzelm@11824
  1328
  end);
wenzelm@11824
  1329
*}
wenzelm@11824
  1330
wenzelm@11824
  1331
setup InductMethod.setup
wenzelm@11824
  1332
paulson@17404
  1333
subsubsection{*Tags, for the ATP Linkup*}
paulson@17404
  1334
paulson@17404
  1335
constdefs
paulson@17404
  1336
  tag :: "bool => bool"
paulson@17404
  1337
   "tag P == P"
paulson@17404
  1338
paulson@17404
  1339
text{*These label the distinguished literals of introduction and elimination
paulson@17404
  1340
rules.*}
paulson@17404
  1341
paulson@17404
  1342
lemma tagI: "P ==> tag P"
paulson@17404
  1343
by (simp add: tag_def)
paulson@17404
  1344
paulson@17404
  1345
lemma tagD: "tag P ==> P"
paulson@17404
  1346
by (simp add: tag_def)
paulson@17404
  1347
paulson@17404
  1348
text{*Applications of "tag" to True and False must go!*}
paulson@17404
  1349
paulson@17404
  1350
lemma tag_True: "tag True = True"
paulson@17404
  1351
by (simp add: tag_def)
paulson@17404
  1352
paulson@17404
  1353
lemma tag_False: "tag False = False"
paulson@17404
  1354
by (simp add: tag_def)
wenzelm@11824
  1355
kleing@14357
  1356
end
paulson@15411
  1357