src/HOL/HOL_lemmas.ML
author paulson
Thu Sep 23 13:06:31 1999 +0200 (1999-09-23)
changeset 7584 5be4bb8e4e3f
parent 7560 19c3be2d285c
child 7618 6680b3b8944b
permissions -rw-r--r--
tidied; added lemma restrict_to_left
wenzelm@7357
     1
(*  Title:      HOL/HOL_lemmas.ML
wenzelm@7357
     2
    ID:         $Id$
wenzelm@7357
     3
    Author:     Tobias Nipkow
wenzelm@7357
     4
    Copyright   1991  University of Cambridge
wenzelm@7357
     5
wenzelm@7357
     6
Derived rules from Appendix of Mike Gordons HOL Report, Cambridge TR 68.
wenzelm@7357
     7
*)
wenzelm@7357
     8
wenzelm@7357
     9
(* ML bindings *)
wenzelm@7357
    10
wenzelm@7357
    11
val plusI = thm "plusI";
wenzelm@7357
    12
val minusI = thm "minusI";
wenzelm@7357
    13
val timesI = thm "timesI";
wenzelm@7357
    14
val powerI = thm "powerI";
wenzelm@7357
    15
val eq_reflection = thm "eq_reflection";
wenzelm@7357
    16
val refl = thm "refl";
wenzelm@7357
    17
val subst = thm "subst";
wenzelm@7357
    18
val ext = thm "ext";
wenzelm@7357
    19
val selectI = thm "selectI";
wenzelm@7357
    20
val impI = thm "impI";
wenzelm@7357
    21
val mp = thm "mp";
wenzelm@7357
    22
val True_def = thm "True_def";
wenzelm@7357
    23
val All_def = thm "All_def";
wenzelm@7357
    24
val Ex_def = thm "Ex_def";
wenzelm@7357
    25
val False_def = thm "False_def";
wenzelm@7357
    26
val not_def = thm "not_def";
wenzelm@7357
    27
val and_def = thm "and_def";
wenzelm@7357
    28
val or_def = thm "or_def";
wenzelm@7357
    29
val Ex1_def = thm "Ex1_def";
wenzelm@7357
    30
val iff = thm "iff";
wenzelm@7357
    31
val True_or_False = thm "True_or_False";
wenzelm@7357
    32
val Let_def = thm "Let_def";
wenzelm@7357
    33
val if_def = thm "if_def";
wenzelm@7357
    34
val arbitrary_def = thm "arbitrary_def";
wenzelm@7357
    35
wenzelm@7357
    36
wenzelm@7357
    37
(** Equality **)
wenzelm@7357
    38
section "=";
wenzelm@7357
    39
wenzelm@7357
    40
qed_goal "sym" (the_context ()) "s=t ==> t=s"
wenzelm@7357
    41
 (fn prems => [cut_facts_tac prems 1, etac subst 1, rtac refl 1]);
wenzelm@7357
    42
wenzelm@7357
    43
(*calling "standard" reduces maxidx to 0*)
wenzelm@7357
    44
bind_thm ("ssubst", (sym RS subst));
wenzelm@7357
    45
wenzelm@7357
    46
qed_goal "trans" (the_context ()) "[| r=s; s=t |] ==> r=t"
wenzelm@7357
    47
 (fn prems =>
wenzelm@7357
    48
        [rtac subst 1, resolve_tac prems 1, resolve_tac prems 1]);
wenzelm@7357
    49
wenzelm@7357
    50
val prems = goal (the_context ()) "(A == B) ==> A = B";
wenzelm@7357
    51
by (rewrite_goals_tac prems);
wenzelm@7357
    52
by (rtac refl 1);
wenzelm@7357
    53
qed "def_imp_eq";
wenzelm@7357
    54
wenzelm@7357
    55
(*Useful with eresolve_tac for proving equalties from known equalities.
wenzelm@7357
    56
        a = b
wenzelm@7357
    57
        |   |
wenzelm@7357
    58
        c = d   *)
wenzelm@7357
    59
Goal "[| a=b;  a=c;  b=d |] ==> c=d";
wenzelm@7357
    60
by (rtac trans 1);
wenzelm@7357
    61
by (rtac trans 1);
wenzelm@7357
    62
by (rtac sym 1);
wenzelm@7357
    63
by (REPEAT (assume_tac 1)) ;
wenzelm@7357
    64
qed "box_equals";
wenzelm@7357
    65
wenzelm@7357
    66
wenzelm@7357
    67
(** Congruence rules for meta-application **)
wenzelm@7357
    68
section "Congruence";
wenzelm@7357
    69
wenzelm@7357
    70
(*similar to AP_THM in Gordon's HOL*)
wenzelm@7357
    71
qed_goal "fun_cong" (the_context ()) "(f::'a=>'b) = g ==> f(x)=g(x)"
wenzelm@7357
    72
  (fn [prem] => [rtac (prem RS subst) 1, rtac refl 1]);
wenzelm@7357
    73
wenzelm@7357
    74
(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)
wenzelm@7357
    75
qed_goal "arg_cong" (the_context ()) "x=y ==> f(x)=f(y)"
wenzelm@7357
    76
 (fn [prem] => [rtac (prem RS subst) 1, rtac refl 1]);
wenzelm@7357
    77
wenzelm@7357
    78
qed_goal "cong" (the_context ())
wenzelm@7357
    79
   "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"
wenzelm@7357
    80
 (fn [prem1,prem2] =>
wenzelm@7357
    81
   [rtac (prem1 RS subst) 1, rtac (prem2 RS subst) 1, rtac refl 1]);
wenzelm@7357
    82
wenzelm@7357
    83
wenzelm@7357
    84
(** Equality of booleans -- iff **)
wenzelm@7357
    85
section "iff";
wenzelm@7357
    86
wenzelm@7357
    87
val prems = Goal
wenzelm@7357
    88
   "[| P ==> Q;  Q ==> P |] ==> P=Q";
wenzelm@7357
    89
by (REPEAT (ares_tac (prems@[impI, iff RS mp RS mp]) 1));
wenzelm@7357
    90
qed "iffI";
wenzelm@7357
    91
wenzelm@7357
    92
qed_goal "iffD2" (the_context ()) "[| P=Q; Q |] ==> P"
wenzelm@7357
    93
 (fn prems =>
wenzelm@7357
    94
        [rtac ssubst 1, resolve_tac prems 1, resolve_tac prems 1]);
wenzelm@7357
    95
wenzelm@7357
    96
qed_goal "rev_iffD2" (the_context ()) "!!P. [| Q; P=Q |] ==> P"
wenzelm@7357
    97
 (fn _ => [etac iffD2 1, assume_tac 1]);
wenzelm@7357
    98
wenzelm@7357
    99
bind_thm ("iffD1", sym RS iffD2);
wenzelm@7357
   100
bind_thm ("rev_iffD1", sym RSN (2, rev_iffD2));
wenzelm@7357
   101
wenzelm@7357
   102
qed_goal "iffE" (the_context ())
wenzelm@7357
   103
    "[| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R"
wenzelm@7357
   104
 (fn [p1,p2] => [REPEAT(ares_tac([p1 RS iffD2, p1 RS iffD1, p2, impI])1)]);
wenzelm@7357
   105
wenzelm@7357
   106
wenzelm@7357
   107
(** True **)
wenzelm@7357
   108
section "True";
wenzelm@7357
   109
wenzelm@7357
   110
qed_goalw "TrueI" (the_context ()) [True_def] "True"
wenzelm@7357
   111
  (fn _ => [(rtac refl 1)]);
wenzelm@7357
   112
wenzelm@7357
   113
qed_goal "eqTrueI" (the_context ()) "P ==> P=True" 
wenzelm@7357
   114
 (fn prems => [REPEAT(resolve_tac ([iffI,TrueI]@prems) 1)]);
wenzelm@7357
   115
wenzelm@7357
   116
qed_goal "eqTrueE" (the_context ()) "P=True ==> P" 
wenzelm@7357
   117
 (fn prems => [REPEAT(resolve_tac (prems@[TrueI,iffD2]) 1)]);
wenzelm@7357
   118
wenzelm@7357
   119
wenzelm@7357
   120
(** Universal quantifier **)
wenzelm@7357
   121
section "!";
wenzelm@7357
   122
wenzelm@7357
   123
qed_goalw "allI" (the_context ()) [All_def] "(!!x::'a. P(x)) ==> !x. P(x)"
wenzelm@7357
   124
 (fn prems => [(resolve_tac (prems RL [eqTrueI RS ext]) 1)]);
wenzelm@7357
   125
wenzelm@7357
   126
qed_goalw "spec" (the_context ()) [All_def] "! x::'a. P(x) ==> P(x)"
wenzelm@7357
   127
 (fn prems => [rtac eqTrueE 1, resolve_tac (prems RL [fun_cong]) 1]);
wenzelm@7357
   128
wenzelm@7357
   129
val major::prems= goal (the_context ()) "[| !x. P(x);  P(x) ==> R |] ==> R";
wenzelm@7357
   130
by (REPEAT (resolve_tac (prems @ [major RS spec]) 1)) ;
wenzelm@7357
   131
qed "allE";
wenzelm@7357
   132
wenzelm@7357
   133
val prems = goal (the_context ()) 
wenzelm@7357
   134
    "[| ! x. P(x);  [| P(x); ! x. P(x) |] ==> R |] ==> R";
wenzelm@7357
   135
by (REPEAT (resolve_tac (prems @ (prems RL [spec])) 1)) ;
wenzelm@7357
   136
qed "all_dupE";
wenzelm@7357
   137
wenzelm@7357
   138
wenzelm@7357
   139
(** False ** Depends upon spec; it is impossible to do propositional logic
wenzelm@7357
   140
             before quantifiers! **)
wenzelm@7357
   141
section "False";
wenzelm@7357
   142
wenzelm@7357
   143
qed_goalw "FalseE" (the_context ()) [False_def] "False ==> P"
wenzelm@7357
   144
 (fn [major] => [rtac (major RS spec) 1]);
wenzelm@7357
   145
wenzelm@7357
   146
qed_goal "False_neq_True" (the_context ()) "False=True ==> P"
wenzelm@7357
   147
 (fn [prem] => [rtac (prem RS eqTrueE RS FalseE) 1]);
wenzelm@7357
   148
wenzelm@7357
   149
wenzelm@7357
   150
(** Negation **)
wenzelm@7357
   151
section "~";
wenzelm@7357
   152
wenzelm@7357
   153
qed_goalw "notI" (the_context ()) [not_def] "(P ==> False) ==> ~P"
wenzelm@7357
   154
 (fn prems=> [rtac impI 1, eresolve_tac prems 1]);
wenzelm@7357
   155
wenzelm@7357
   156
qed_goal "False_not_True" (the_context ()) "False ~= True"
wenzelm@7357
   157
  (fn _ => [rtac notI 1, etac False_neq_True 1]);
wenzelm@7357
   158
wenzelm@7357
   159
qed_goal "True_not_False" (the_context ()) "True ~= False"
wenzelm@7357
   160
  (fn _ => [rtac notI 1, dtac sym 1, etac False_neq_True 1]);
wenzelm@7357
   161
wenzelm@7357
   162
qed_goalw "notE" (the_context ()) [not_def] "[| ~P;  P |] ==> R"
wenzelm@7357
   163
 (fn prems => [rtac (prems MRS mp RS FalseE) 1]);
wenzelm@7357
   164
wenzelm@7357
   165
bind_thm ("classical2", notE RS notI);
wenzelm@7357
   166
wenzelm@7357
   167
qed_goal "rev_notE" (the_context ()) "!!P R. [| P; ~P |] ==> R"
wenzelm@7357
   168
 (fn _ => [REPEAT (ares_tac [notE] 1)]);
wenzelm@7357
   169
wenzelm@7357
   170
wenzelm@7357
   171
(** Implication **)
wenzelm@7357
   172
section "-->";
wenzelm@7357
   173
wenzelm@7357
   174
val prems = Goal "[| P-->Q;  P;  Q ==> R |] ==> R";
wenzelm@7357
   175
by (REPEAT (resolve_tac (prems@[mp]) 1));
wenzelm@7357
   176
qed "impE";
wenzelm@7357
   177
wenzelm@7357
   178
(* Reduces Q to P-->Q, allowing substitution in P. *)
wenzelm@7357
   179
Goal "[| P;  P --> Q |] ==> Q";
wenzelm@7357
   180
by (REPEAT (ares_tac [mp] 1)) ;
wenzelm@7357
   181
qed "rev_mp";
wenzelm@7357
   182
wenzelm@7357
   183
val [major,minor] = Goal "[| ~Q;  P==>Q |] ==> ~P";
wenzelm@7357
   184
by (rtac (major RS notE RS notI) 1);
wenzelm@7357
   185
by (etac minor 1) ;
wenzelm@7357
   186
qed "contrapos";
wenzelm@7357
   187
wenzelm@7357
   188
val [major,minor] = Goal "[| P==>Q; ~Q |] ==> ~P";
wenzelm@7357
   189
by (rtac (minor RS contrapos) 1);
wenzelm@7357
   190
by (etac major 1) ;
wenzelm@7357
   191
qed "rev_contrapos";
wenzelm@7357
   192
wenzelm@7357
   193
(* ~(?t = ?s) ==> ~(?s = ?t) *)
wenzelm@7357
   194
bind_thm("not_sym", sym COMP rev_contrapos);
wenzelm@7357
   195
wenzelm@7357
   196
wenzelm@7357
   197
(** Existential quantifier **)
wenzelm@7357
   198
section "?";
wenzelm@7357
   199
wenzelm@7357
   200
qed_goalw "exI" (the_context ()) [Ex_def] "P x ==> ? x::'a. P x"
wenzelm@7357
   201
 (fn prems => [rtac selectI 1, resolve_tac prems 1]);
wenzelm@7357
   202
wenzelm@7357
   203
qed_goalw "exE" (the_context ()) [Ex_def]
wenzelm@7357
   204
  "[| ? x::'a. P(x); !!x. P(x) ==> Q |] ==> Q"
wenzelm@7357
   205
  (fn prems => [REPEAT(resolve_tac prems 1)]);
wenzelm@7357
   206
wenzelm@7357
   207
wenzelm@7357
   208
(** Conjunction **)
wenzelm@7357
   209
section "&";
wenzelm@7357
   210
wenzelm@7357
   211
qed_goalw "conjI" (the_context ()) [and_def] "[| P; Q |] ==> P&Q"
wenzelm@7357
   212
 (fn prems =>
wenzelm@7357
   213
  [REPEAT (resolve_tac (prems@[allI,impI]) 1 ORELSE etac (mp RS mp) 1)]);
wenzelm@7357
   214
wenzelm@7357
   215
qed_goalw "conjunct1" (the_context ()) [and_def] "[| P & Q |] ==> P"
wenzelm@7357
   216
 (fn prems =>
wenzelm@7357
   217
   [resolve_tac (prems RL [spec] RL [mp]) 1, REPEAT(ares_tac [impI] 1)]);
wenzelm@7357
   218
wenzelm@7357
   219
qed_goalw "conjunct2" (the_context ()) [and_def] "[| P & Q |] ==> Q"
wenzelm@7357
   220
 (fn prems =>
wenzelm@7357
   221
   [resolve_tac (prems RL [spec] RL [mp]) 1, REPEAT(ares_tac [impI] 1)]);
wenzelm@7357
   222
wenzelm@7357
   223
qed_goal "conjE" (the_context ()) "[| P&Q;  [| P; Q |] ==> R |] ==> R"
wenzelm@7357
   224
 (fn prems =>
wenzelm@7357
   225
         [cut_facts_tac prems 1, resolve_tac prems 1,
wenzelm@7357
   226
          etac conjunct1 1, etac conjunct2 1]);
wenzelm@7357
   227
wenzelm@7357
   228
qed_goal "context_conjI" (the_context ())  "[| P; P ==> Q |] ==> P & Q"
wenzelm@7357
   229
 (fn prems => [REPEAT(resolve_tac (conjI::prems) 1)]);
wenzelm@7357
   230
wenzelm@7357
   231
wenzelm@7357
   232
(** Disjunction *)
wenzelm@7357
   233
section "|";
wenzelm@7357
   234
wenzelm@7357
   235
qed_goalw "disjI1" (the_context ()) [or_def] "P ==> P|Q"
wenzelm@7357
   236
 (fn [prem] => [REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]);
wenzelm@7357
   237
wenzelm@7357
   238
qed_goalw "disjI2" (the_context ()) [or_def] "Q ==> P|Q"
wenzelm@7357
   239
 (fn [prem] => [REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]);
wenzelm@7357
   240
wenzelm@7357
   241
qed_goalw "disjE" (the_context ()) [or_def] "[| P | Q; P ==> R; Q ==> R |] ==> R"
wenzelm@7357
   242
 (fn [a1,a2,a3] =>
wenzelm@7357
   243
        [rtac (mp RS mp) 1, rtac spec 1, rtac a1 1,
wenzelm@7357
   244
         rtac (a2 RS impI) 1, assume_tac 1, rtac (a3 RS impI) 1, assume_tac 1]);
wenzelm@7357
   245
wenzelm@7357
   246
wenzelm@7357
   247
(** CCONTR -- classical logic **)
wenzelm@7357
   248
section "classical logic";
wenzelm@7357
   249
wenzelm@7357
   250
qed_goalw "classical" (the_context ()) [not_def]  "(~P ==> P) ==> P"
wenzelm@7357
   251
 (fn [prem] =>
wenzelm@7357
   252
   [rtac (True_or_False RS (disjE RS eqTrueE)) 1,  assume_tac 1,
wenzelm@7357
   253
    rtac (impI RS prem RS eqTrueI) 1,
wenzelm@7357
   254
    etac subst 1,  assume_tac 1]);
wenzelm@7357
   255
wenzelm@7357
   256
val ccontr = FalseE RS classical;
wenzelm@7357
   257
wenzelm@7357
   258
(*Double negation law*)
wenzelm@7357
   259
Goal "~~P ==> P";
wenzelm@7357
   260
by (rtac classical 1);
wenzelm@7357
   261
by (etac notE 1);
wenzelm@7357
   262
by (assume_tac 1);
wenzelm@7357
   263
qed "notnotD";
wenzelm@7357
   264
wenzelm@7357
   265
val [p1,p2] = Goal "[| Q; ~ P ==> ~ Q |] ==> P";
wenzelm@7357
   266
by (rtac classical 1);
wenzelm@7357
   267
by (dtac p2 1);
wenzelm@7357
   268
by (etac notE 1);
wenzelm@7357
   269
by (rtac p1 1);
wenzelm@7357
   270
qed "contrapos2";
wenzelm@7357
   271
wenzelm@7357
   272
val [p1,p2] = Goal "[| P;  Q ==> ~ P |] ==> ~ Q";
wenzelm@7357
   273
by (rtac notI 1);
wenzelm@7357
   274
by (dtac p2 1);
wenzelm@7357
   275
by (etac notE 1);
wenzelm@7357
   276
by (rtac p1 1);
wenzelm@7357
   277
qed "swap2";
wenzelm@7357
   278
wenzelm@7357
   279
(** Unique existence **)
wenzelm@7357
   280
section "?!";
wenzelm@7357
   281
wenzelm@7357
   282
qed_goalw "ex1I" (the_context ()) [Ex1_def]
wenzelm@7357
   283
            "[| P(a);  !!x. P(x) ==> x=a |] ==> ?! x. P(x)"
wenzelm@7357
   284
 (fn prems =>
wenzelm@7357
   285
  [REPEAT (ares_tac (prems@[exI,conjI,allI,impI]) 1)]);
wenzelm@7357
   286
wenzelm@7357
   287
(*Sometimes easier to use: the premises have no shared variables.  Safe!*)
wenzelm@7357
   288
val [ex,eq] = Goal
wenzelm@7357
   289
    "[| ? x. P(x);  !!x y. [| P(x); P(y) |] ==> x=y |] ==> ?! x. P(x)";
wenzelm@7357
   290
by (rtac (ex RS exE) 1);
wenzelm@7357
   291
by (REPEAT (ares_tac [ex1I,eq] 1)) ;
wenzelm@7357
   292
qed "ex_ex1I";
wenzelm@7357
   293
wenzelm@7357
   294
qed_goalw "ex1E" (the_context ()) [Ex1_def]
wenzelm@7357
   295
    "[| ?! x. P(x);  !!x. [| P(x);  ! y. P(y) --> y=x |] ==> R |] ==> R"
wenzelm@7357
   296
 (fn major::prems =>
wenzelm@7357
   297
  [rtac (major RS exE) 1, REPEAT (etac conjE 1 ORELSE ares_tac prems 1)]);
wenzelm@7357
   298
wenzelm@7357
   299
Goal "?! x. P x ==> ? x. P x";
wenzelm@7357
   300
by (etac ex1E 1);
wenzelm@7357
   301
by (rtac exI 1);
wenzelm@7357
   302
by (assume_tac 1);
wenzelm@7357
   303
qed "ex1_implies_ex";
wenzelm@7357
   304
wenzelm@7357
   305
wenzelm@7357
   306
(** Select: Hilbert's Epsilon-operator **)
wenzelm@7357
   307
section "@";
wenzelm@7357
   308
wenzelm@7357
   309
(*Easier to apply than selectI: conclusion has only one occurrence of P*)
wenzelm@7357
   310
val prems = Goal
wenzelm@7357
   311
    "[| P a;  !!x. P x ==> Q x |] ==> Q (@x. P x)";
wenzelm@7357
   312
by (resolve_tac prems 1);
wenzelm@7357
   313
by (rtac selectI 1);
wenzelm@7357
   314
by (resolve_tac prems 1) ;
wenzelm@7357
   315
qed "selectI2";
wenzelm@7357
   316
wenzelm@7357
   317
(*Easier to apply than selectI2 if witness ?a comes from an EX-formula*)
wenzelm@7357
   318
qed_goal "selectI2EX" (the_context ())
wenzelm@7357
   319
  "[| ? a. P a; !!x. P x ==> Q x |] ==> Q (Eps P)"
wenzelm@7357
   320
(fn [major,minor] => [rtac (major RS exE) 1, etac selectI2 1, etac minor 1]);
wenzelm@7357
   321
wenzelm@7357
   322
val prems = Goal
wenzelm@7357
   323
    "[| P a;  !!x. P x ==> x=a |] ==> (@x. P x) = a";
wenzelm@7357
   324
by (rtac selectI2 1);
wenzelm@7357
   325
by (REPEAT (ares_tac prems 1)) ;
wenzelm@7357
   326
qed "select_equality";
wenzelm@7357
   327
wenzelm@7357
   328
Goalw [Ex1_def] "[| ?!x. P x; P a |] ==> (@x. P x) = a";
wenzelm@7357
   329
by (rtac select_equality 1);
wenzelm@7357
   330
by (atac 1);
wenzelm@7357
   331
by (etac exE 1);
wenzelm@7357
   332
by (etac conjE 1);
wenzelm@7357
   333
by (rtac allE 1);
wenzelm@7357
   334
by (atac 1);
wenzelm@7357
   335
by (etac impE 1);
wenzelm@7357
   336
by (atac 1);
wenzelm@7357
   337
by (etac ssubst 1);
wenzelm@7357
   338
by (etac allE 1);
wenzelm@7357
   339
by (etac mp 1);
wenzelm@7357
   340
by (atac 1);
wenzelm@7357
   341
qed "select1_equality";
wenzelm@7357
   342
wenzelm@7357
   343
Goal "P (@ x. P x) =  (? x. P x)";
wenzelm@7357
   344
by (rtac iffI 1);
wenzelm@7357
   345
by (etac exI 1);
wenzelm@7357
   346
by (etac exE 1);
wenzelm@7357
   347
by (etac selectI 1);
wenzelm@7357
   348
qed "select_eq_Ex";
wenzelm@7357
   349
wenzelm@7357
   350
Goal "(@y. y=x) = x";
wenzelm@7357
   351
by (rtac select_equality 1);
wenzelm@7357
   352
by (rtac refl 1);
wenzelm@7357
   353
by (atac 1);
wenzelm@7357
   354
qed "Eps_eq";
wenzelm@7357
   355
wenzelm@7357
   356
Goal "(Eps (op = x)) = x";
wenzelm@7357
   357
by (rtac select_equality 1);
wenzelm@7357
   358
by (rtac refl 1);
wenzelm@7357
   359
by (etac sym 1);
wenzelm@7357
   360
qed "Eps_sym_eq";
wenzelm@7357
   361
wenzelm@7357
   362
(** Classical intro rules for disjunction and existential quantifiers *)
wenzelm@7357
   363
section "classical intro rules";
wenzelm@7357
   364
wenzelm@7357
   365
val prems= Goal "(~Q ==> P) ==> P|Q";
wenzelm@7357
   366
by (rtac classical 1);
wenzelm@7357
   367
by (REPEAT (ares_tac (prems@[disjI1,notI]) 1));
wenzelm@7357
   368
by (REPEAT (ares_tac (prems@[disjI2,notE]) 1)) ;
wenzelm@7357
   369
qed "disjCI";
wenzelm@7357
   370
wenzelm@7357
   371
Goal "~P | P";
wenzelm@7357
   372
by (REPEAT (ares_tac [disjCI] 1)) ;
wenzelm@7357
   373
qed "excluded_middle";
wenzelm@7357
   374
wenzelm@7357
   375
(*For disjunctive case analysis*)
wenzelm@7357
   376
fun excluded_middle_tac sP =
wenzelm@7357
   377
    res_inst_tac [("Q",sP)] (excluded_middle RS disjE);
wenzelm@7357
   378
wenzelm@7357
   379
(*Classical implies (-->) elimination. *)
wenzelm@7357
   380
val major::prems = Goal "[| P-->Q; ~P ==> R; Q ==> R |] ==> R";
wenzelm@7357
   381
by (rtac (excluded_middle RS disjE) 1);
wenzelm@7357
   382
by (REPEAT (DEPTH_SOLVE_1 (ares_tac (prems @ [major RS mp]) 1)));
wenzelm@7357
   383
qed "impCE";
wenzelm@7357
   384
wenzelm@7357
   385
(*This version of --> elimination works on Q before P.  It works best for
wenzelm@7357
   386
  those cases in which P holds "almost everywhere".  Can't install as
wenzelm@7357
   387
  default: would break old proofs.*)
wenzelm@7357
   388
val major::prems = Goal
wenzelm@7357
   389
    "[| P-->Q;  Q ==> R;  ~P ==> R |] ==> R";
wenzelm@7357
   390
by (resolve_tac [excluded_middle RS disjE] 1);
wenzelm@7357
   391
by (DEPTH_SOLVE (ares_tac (prems@[major RS mp]) 1)) ;
wenzelm@7357
   392
qed "impCE'";
wenzelm@7357
   393
wenzelm@7357
   394
(*Classical <-> elimination. *)
wenzelm@7357
   395
val major::prems = Goal
wenzelm@7357
   396
    "[| P=Q;  [| P; Q |] ==> R;  [| ~P; ~Q |] ==> R |] ==> R";
wenzelm@7357
   397
by (rtac (major RS iffE) 1);
wenzelm@7357
   398
by (REPEAT (DEPTH_SOLVE_1 
wenzelm@7357
   399
	    (eresolve_tac ([asm_rl,impCE,notE]@prems) 1)));
wenzelm@7357
   400
qed "iffCE";
wenzelm@7357
   401
wenzelm@7357
   402
val prems = Goal "(! x. ~P(x) ==> P(a)) ==> ? x. P(x)";
wenzelm@7357
   403
by (rtac ccontr 1);
wenzelm@7357
   404
by (REPEAT (ares_tac (prems@[exI,allI,notI,notE]) 1))  ;
wenzelm@7357
   405
qed "exCI";
wenzelm@7357
   406
wenzelm@7357
   407
wenzelm@7357
   408
(* case distinction *)
wenzelm@7357
   409
wenzelm@7357
   410
qed_goal "case_split_thm" (the_context ()) "[| P ==> Q; ~P ==> Q |] ==> Q"
wenzelm@7357
   411
  (fn [p1,p2] => [rtac (excluded_middle RS disjE) 1,
wenzelm@7357
   412
                  etac p2 1, etac p1 1]);
wenzelm@7357
   413
wenzelm@7357
   414
fun case_tac a = res_inst_tac [("P",a)] case_split_thm;
wenzelm@7357
   415
wenzelm@7357
   416
wenzelm@7357
   417
(** Standard abbreviations **)
wenzelm@7357
   418
wenzelm@7357
   419
(*Apply an equality or definition ONCE.
wenzelm@7357
   420
  Fails unless the substitution has an effect*)
wenzelm@7357
   421
fun stac th = 
wenzelm@7357
   422
  let val th' = th RS def_imp_eq handle THM _ => th
wenzelm@7357
   423
  in  CHANGED_GOAL (rtac (th' RS ssubst))
wenzelm@7357
   424
  end;
wenzelm@7357
   425
oheimb@7490
   426
(* combination of (spec RS spec RS ...(j times) ... spec RS mp *) 
oheimb@7490
   427
local
oheimb@7490
   428
  fun wrong_prem (Const ("All", _) $ (Abs (_, _, t))) = wrong_prem t
oheimb@7490
   429
  |   wrong_prem (Bound _) = true
oheimb@7490
   430
  |   wrong_prem _ = false;
oheimb@7533
   431
  val filter_right = filter (fn t => not (wrong_prem (HOLogic.dest_Trueprop (hd (Thm.prems_of t)))));
oheimb@7490
   432
in
oheimb@7490
   433
  fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp]);
oheimb@7490
   434
  fun smp_tac j = EVERY'[dresolve_tac (smp j), atac]
oheimb@7490
   435
end;
oheimb@7490
   436
oheimb@7490
   437
wenzelm@7357
   438
fun strip_tac i = REPEAT(resolve_tac [impI,allI] i); 
wenzelm@7357
   439
wenzelm@7357
   440
(** strip ! and --> from proved goal while preserving !-bound var names **)
wenzelm@7357
   441
wenzelm@7357
   442
local
wenzelm@7357
   443
wenzelm@7357
   444
(* Use XXX to avoid forall_intr failing because of duplicate variable name *)
wenzelm@7357
   445
val myspec = read_instantiate [("P","?XXX")] spec;
wenzelm@7357
   446
val _ $ (_ $ (vx as Var(_,vxT))) = concl_of myspec;
wenzelm@7357
   447
val cvx = cterm_of (#sign(rep_thm myspec)) vx;
wenzelm@7357
   448
val aspec = forall_intr cvx myspec;
wenzelm@7357
   449
wenzelm@7357
   450
in
wenzelm@7357
   451
wenzelm@7357
   452
fun RSspec th =
wenzelm@7357
   453
  (case concl_of th of
wenzelm@7357
   454
     _ $ (Const("All",_) $ Abs(a,_,_)) =>
wenzelm@7357
   455
         let val ca = cterm_of (#sign(rep_thm th)) (Var((a,0),vxT))
wenzelm@7357
   456
         in th RS forall_elim ca aspec end
wenzelm@7357
   457
  | _ => raise THM("RSspec",0,[th]));
wenzelm@7357
   458
wenzelm@7357
   459
fun RSmp th =
wenzelm@7357
   460
  (case concl_of th of
wenzelm@7357
   461
     _ $ (Const("op -->",_)$_$_) => th RS mp
wenzelm@7357
   462
  | _ => raise THM("RSmp",0,[th]));
wenzelm@7357
   463
wenzelm@7357
   464
fun normalize_thm funs =
wenzelm@7357
   465
  let fun trans [] th = th
wenzelm@7357
   466
	| trans (f::fs) th = (trans funs (f th)) handle THM _ => trans fs th
wenzelm@7357
   467
  in zero_var_indexes o trans funs end;
wenzelm@7357
   468
wenzelm@7357
   469
fun qed_spec_mp name =
wenzelm@7357
   470
  let val thm = normalize_thm [RSspec,RSmp] (result())
wenzelm@7357
   471
  in ThmDatabase.ml_store_thm(name, thm) end;
wenzelm@7357
   472
wenzelm@7357
   473
fun qed_goal_spec_mp name thy s p = 
wenzelm@7357
   474
	bind_thm (name, normalize_thm [RSspec,RSmp] (prove_goal thy s p));
wenzelm@7357
   475
wenzelm@7357
   476
fun qed_goalw_spec_mp name thy defs s p = 
wenzelm@7357
   477
	bind_thm (name, normalize_thm [RSspec,RSmp] (prove_goalw thy defs s p));
wenzelm@7357
   478
wenzelm@7357
   479
end;
wenzelm@7357
   480
wenzelm@7357
   481
wenzelm@7357
   482
(* attributes *)
wenzelm@7357
   483
wenzelm@7357
   484
local
wenzelm@7357
   485
wenzelm@7357
   486
fun gen_rulify x =
wenzelm@7357
   487
  Attrib.no_args (Drule.rule_attribute (fn _ => (normalize_thm [RSspec, RSmp]))) x;
wenzelm@7357
   488
wenzelm@7357
   489
in
wenzelm@7357
   490
wenzelm@7357
   491
val attrib_setup =
wenzelm@7357
   492
 [Attrib.add_attributes
wenzelm@7357
   493
  [("rulify", (gen_rulify, gen_rulify), "put theorem into standard rule form")]];
wenzelm@7357
   494
wenzelm@7357
   495
end;