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