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