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