src/FOLP/IFOLP.ML
author paulson
Fri Feb 16 18:00:47 1996 +0100 (1996-02-16)
changeset 1512 ce37c64244c0
parent 1459 d12da312eff4
child 3836 f1a1817659e6
permissions -rw-r--r--
Elimination of fully-functorial style.
Type tactic changed to a type abbrevation (from a datatype).
Constructor tactic and function apply deleted.
clasohm@1459
     1
(*  Title:      FOLP/IFOLP.ML
clasohm@0
     2
    ID:         $Id$
clasohm@1459
     3
    Author:     Martin D Coen, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1992  University of Cambridge
clasohm@0
     5
lcp@1142
     6
Tactics and lemmas for IFOLP (Intuitionistic First-Order Logic with Proofs)
clasohm@0
     7
*)
clasohm@0
     8
clasohm@0
     9
open IFOLP;
clasohm@0
    10
clasohm@0
    11
signature IFOLP_LEMMAS = 
clasohm@0
    12
  sig
clasohm@0
    13
  val allE: thm
clasohm@0
    14
  val all_cong: thm
clasohm@0
    15
  val all_dupE: thm
clasohm@0
    16
  val all_impE: thm
clasohm@0
    17
  val box_equals: thm
clasohm@0
    18
  val conjE: thm
clasohm@0
    19
  val conj_cong: thm
clasohm@0
    20
  val conj_impE: thm
clasohm@0
    21
  val contrapos: thm
clasohm@0
    22
  val disj_cong: thm
clasohm@0
    23
  val disj_impE: thm
clasohm@0
    24
  val eq_cong: thm
clasohm@0
    25
  val ex1I: thm
clasohm@0
    26
  val ex1E: thm
clasohm@0
    27
  val ex1_equalsE: thm
clasohm@0
    28
(*  val ex1_cong: thm****)
clasohm@0
    29
  val ex_cong: thm
clasohm@0
    30
  val ex_impE: thm
clasohm@0
    31
  val iffD1: thm
clasohm@0
    32
  val iffD2: thm
clasohm@0
    33
  val iffE: thm
clasohm@0
    34
  val iffI: thm
clasohm@0
    35
  val iff_cong: thm
clasohm@0
    36
  val iff_impE: thm
clasohm@0
    37
  val iff_refl: thm
clasohm@0
    38
  val iff_sym: thm
clasohm@0
    39
  val iff_trans: thm
clasohm@0
    40
  val impE: thm
clasohm@0
    41
  val imp_cong: thm
clasohm@0
    42
  val imp_impE: thm
clasohm@0
    43
  val mp_tac: int -> tactic
clasohm@0
    44
  val notE: thm
clasohm@0
    45
  val notI: thm
clasohm@0
    46
  val not_cong: thm
clasohm@0
    47
  val not_impE: thm
clasohm@0
    48
  val not_sym: thm
clasohm@0
    49
  val not_to_imp: thm
clasohm@0
    50
  val pred1_cong: thm
clasohm@0
    51
  val pred2_cong: thm
clasohm@0
    52
  val pred3_cong: thm
clasohm@0
    53
  val pred_congs: thm list
clasohm@0
    54
  val refl: thm
clasohm@0
    55
  val rev_mp: thm
clasohm@0
    56
  val simp_equals: thm
clasohm@0
    57
  val subst: thm
clasohm@0
    58
  val ssubst: thm
clasohm@0
    59
  val subst_context: thm
clasohm@0
    60
  val subst_context2: thm
clasohm@0
    61
  val subst_context3: thm
clasohm@0
    62
  val sym: thm
clasohm@0
    63
  val trans: thm
clasohm@0
    64
  val TrueI: thm
clasohm@0
    65
  val uniq_assume_tac: int -> tactic
clasohm@0
    66
  val uniq_mp_tac: int -> tactic
clasohm@0
    67
  end;
clasohm@0
    68
clasohm@0
    69
clasohm@0
    70
structure IFOLP_Lemmas : IFOLP_LEMMAS =
clasohm@0
    71
struct
clasohm@0
    72
clasohm@0
    73
val TrueI = TrueI;
clasohm@0
    74
clasohm@0
    75
(*** Sequent-style elimination rules for & --> and ALL ***)
clasohm@0
    76
clasohm@0
    77
val conjE = prove_goal IFOLP.thy 
clasohm@0
    78
    "[| p:P&Q; !!x y.[| x:P; y:Q |] ==> f(x,y):R |] ==> ?a:R"
clasohm@0
    79
 (fn prems=>
clasohm@0
    80
  [ (REPEAT (resolve_tac prems 1
clasohm@0
    81
      ORELSE (resolve_tac [conjunct1, conjunct2] 1 THEN
clasohm@0
    82
              resolve_tac prems 1))) ]);
clasohm@0
    83
clasohm@0
    84
val impE = prove_goal IFOLP.thy 
clasohm@0
    85
    "[| p:P-->Q;  q:P;  !!x.x:Q ==> r(x):R |] ==> ?p:R"
clasohm@0
    86
 (fn prems=> [ (REPEAT (resolve_tac (prems@[mp]) 1)) ]);
clasohm@0
    87
clasohm@0
    88
val allE = prove_goal IFOLP.thy 
clasohm@0
    89
    "[| p:ALL x.P(x); !!y.y:P(x) ==> q(y):R |] ==> ?p:R"
clasohm@0
    90
 (fn prems=> [ (REPEAT (resolve_tac (prems@[spec]) 1)) ]);
clasohm@0
    91
clasohm@0
    92
(*Duplicates the quantifier; for use with eresolve_tac*)
clasohm@0
    93
val all_dupE = prove_goal IFOLP.thy 
clasohm@0
    94
    "[| p:ALL x.P(x);  !!y z.[| y:P(x); z:ALL x.P(x) |] ==> q(y,z):R \
clasohm@0
    95
\    |] ==> ?p:R"
clasohm@0
    96
 (fn prems=> [ (REPEAT (resolve_tac (prems@[spec]) 1)) ]);
clasohm@0
    97
clasohm@0
    98
clasohm@0
    99
(*** Negation rules, which translate between ~P and P-->False ***)
clasohm@0
   100
clasohm@0
   101
val notI = prove_goalw IFOLP.thy [not_def]  "(!!x.x:P ==> q(x):False) ==> ?p:~P"
clasohm@0
   102
 (fn prems=> [ (REPEAT (ares_tac (prems@[impI]) 1)) ]);
clasohm@0
   103
clasohm@0
   104
val notE = prove_goalw IFOLP.thy [not_def] "[| p:~P;  q:P |] ==> ?p:R"
clasohm@0
   105
 (fn prems=>
clasohm@0
   106
  [ (resolve_tac [mp RS FalseE] 1),
clasohm@0
   107
    (REPEAT (resolve_tac prems 1)) ]);
clasohm@0
   108
clasohm@0
   109
(*This is useful with the special implication rules for each kind of P. *)
clasohm@0
   110
val not_to_imp = prove_goal IFOLP.thy 
clasohm@0
   111
    "[| p:~P;  !!x.x:(P-->False) ==> q(x):Q |] ==> ?p:Q"
clasohm@0
   112
 (fn prems=> [ (REPEAT (ares_tac (prems@[impI,notE]) 1)) ]);
clasohm@0
   113
clasohm@0
   114
clasohm@0
   115
(* For substitution int an assumption P, reduce Q to P-->Q, substitute into
clasohm@0
   116
   this implication, then apply impI to move P back into the assumptions.
clasohm@0
   117
   To specify P use something like
clasohm@0
   118
      eres_inst_tac [ ("P","ALL y. ?S(x,y)") ] rev_mp 1   *)
clasohm@0
   119
val rev_mp = prove_goal IFOLP.thy "[| p:P;  q:P --> Q |] ==> ?p:Q"
clasohm@0
   120
 (fn prems=> [ (REPEAT (resolve_tac (prems@[mp]) 1)) ]);
clasohm@0
   121
clasohm@0
   122
clasohm@0
   123
(*Contrapositive of an inference rule*)
clasohm@0
   124
val contrapos = prove_goal IFOLP.thy "[| p:~Q;  !!y.y:P==>q(y):Q |] ==> ?a:~P"
clasohm@0
   125
 (fn [major,minor]=> 
clasohm@0
   126
  [ (rtac (major RS notE RS notI) 1), 
clasohm@0
   127
    (etac minor 1) ]);
clasohm@0
   128
clasohm@0
   129
(** Unique assumption tactic.
clasohm@0
   130
    Ignores proof objects.
clasohm@0
   131
    Fails unless one assumption is equal and exactly one is unifiable 
clasohm@0
   132
**)
clasohm@0
   133
clasohm@0
   134
local
clasohm@0
   135
    fun discard_proof (Const("Proof",_) $ P $ _) = P;
clasohm@0
   136
in
clasohm@0
   137
val uniq_assume_tac =
clasohm@0
   138
  SUBGOAL
clasohm@0
   139
    (fn (prem,i) =>
clasohm@0
   140
      let val hyps = map discard_proof (Logic.strip_assums_hyp prem)
clasohm@0
   141
          and concl = discard_proof (Logic.strip_assums_concl prem)
clasohm@0
   142
      in  
clasohm@1459
   143
          if exists (fn hyp => hyp aconv concl) hyps
clasohm@1459
   144
          then case distinct (filter (fn hyp=> could_unify(hyp,concl)) hyps) of
clasohm@1459
   145
                   [_] => assume_tac i
clasohm@0
   146
                 |  _  => no_tac
clasohm@0
   147
          else no_tac
clasohm@0
   148
      end);
clasohm@0
   149
end;
clasohm@0
   150
clasohm@0
   151
clasohm@0
   152
(*** Modus Ponens Tactics ***)
clasohm@0
   153
clasohm@0
   154
(*Finds P-->Q and P in the assumptions, replaces implication by Q *)
clasohm@0
   155
fun mp_tac i = eresolve_tac [notE,make_elim mp] i  THEN  assume_tac i;
clasohm@0
   156
clasohm@0
   157
(*Like mp_tac but instantiates no variables*)
clasohm@0
   158
fun uniq_mp_tac i = eresolve_tac [notE,impE] i  THEN  uniq_assume_tac i;
clasohm@0
   159
clasohm@0
   160
clasohm@0
   161
(*** If-and-only-if ***)
clasohm@0
   162
clasohm@0
   163
val iffI = prove_goalw IFOLP.thy [iff_def]
clasohm@0
   164
   "[| !!x.x:P ==> q(x):Q;  !!x.x:Q ==> r(x):P |] ==> ?p:P<->Q"
clasohm@0
   165
 (fn prems=> [ (REPEAT (ares_tac (prems@[conjI, impI]) 1)) ]);
clasohm@0
   166
clasohm@0
   167
clasohm@0
   168
(*Observe use of rewrite_rule to unfold "<->" in meta-assumptions (prems) *)
clasohm@0
   169
val iffE = prove_goalw IFOLP.thy [iff_def]
clasohm@0
   170
    "[| p:P <-> Q;  !!x y.[| x:P-->Q; y:Q-->P |] ==> q(x,y):R |] ==> ?p:R"
clasohm@1459
   171
 (fn prems => [ (rtac conjE 1), (REPEAT (ares_tac prems 1)) ]);
clasohm@0
   172
clasohm@0
   173
(* Destruct rules for <-> similar to Modus Ponens *)
clasohm@0
   174
clasohm@0
   175
val iffD1 = prove_goalw IFOLP.thy [iff_def] "[| p:P <-> Q;  q:P |] ==> ?p:Q"
clasohm@0
   176
 (fn prems => [ (rtac (conjunct1 RS mp) 1), (REPEAT (ares_tac prems 1)) ]);
clasohm@0
   177
clasohm@0
   178
val iffD2 = prove_goalw IFOLP.thy [iff_def] "[| p:P <-> Q;  q:Q |] ==> ?p:P"
clasohm@0
   179
 (fn prems => [ (rtac (conjunct2 RS mp) 1), (REPEAT (ares_tac prems 1)) ]);
clasohm@0
   180
clasohm@0
   181
val iff_refl = prove_goal IFOLP.thy "?p:P <-> P"
clasohm@0
   182
 (fn _ => [ (REPEAT (ares_tac [iffI] 1)) ]);
clasohm@0
   183
clasohm@0
   184
val iff_sym = prove_goal IFOLP.thy "p:Q <-> P ==> ?p:P <-> Q"
clasohm@0
   185
 (fn [major] =>
clasohm@0
   186
  [ (rtac (major RS iffE) 1),
clasohm@0
   187
    (rtac iffI 1),
clasohm@0
   188
    (REPEAT (eresolve_tac [asm_rl,mp] 1)) ]);
clasohm@0
   189
clasohm@0
   190
val iff_trans = prove_goal IFOLP.thy "[| p:P <-> Q; q:Q<-> R |] ==> ?p:P <-> R"
clasohm@0
   191
 (fn prems =>
clasohm@0
   192
  [ (cut_facts_tac prems 1),
clasohm@0
   193
    (rtac iffI 1),
clasohm@0
   194
    (REPEAT (eresolve_tac [asm_rl,iffE] 1 ORELSE mp_tac 1)) ]);
clasohm@0
   195
clasohm@0
   196
clasohm@0
   197
(*** Unique existence.  NOTE THAT the following 2 quantifications
clasohm@0
   198
   EX!x such that [EX!y such that P(x,y)]     (sequential)
clasohm@0
   199
   EX!x,y such that P(x,y)                    (simultaneous)
clasohm@0
   200
 do NOT mean the same thing.  The parser treats EX!x y.P(x,y) as sequential.
clasohm@0
   201
***)
clasohm@0
   202
clasohm@0
   203
val ex1I = prove_goalw IFOLP.thy [ex1_def]
clasohm@0
   204
    "[| p:P(a);  !!x u.u:P(x) ==> f(u) : x=a |] ==> ?p:EX! x. P(x)"
clasohm@0
   205
 (fn prems => [ (REPEAT (ares_tac (prems@[exI,conjI,allI,impI]) 1)) ]);
clasohm@0
   206
clasohm@0
   207
val ex1E = prove_goalw IFOLP.thy [ex1_def]
clasohm@0
   208
    "[| p:EX! x.P(x);  \
clasohm@0
   209
\       !!x u v. [| u:P(x);  v:ALL y. P(y) --> y=x |] ==> f(x,u,v):R |] ==>\
clasohm@0
   210
\    ?a : R"
clasohm@0
   211
 (fn prems =>
clasohm@0
   212
  [ (cut_facts_tac prems 1),
clasohm@0
   213
    (REPEAT (eresolve_tac [exE,conjE] 1 ORELSE ares_tac prems 1)) ]);
clasohm@0
   214
clasohm@0
   215
clasohm@0
   216
(*** <-> congruence rules for simplification ***)
clasohm@0
   217
clasohm@0
   218
(*Use iffE on a premise.  For conj_cong, imp_cong, all_cong, ex_cong*)
clasohm@0
   219
fun iff_tac prems i =
clasohm@0
   220
    resolve_tac (prems RL [iffE]) i THEN
clasohm@0
   221
    REPEAT1 (eresolve_tac [asm_rl,mp] i);
clasohm@0
   222
clasohm@0
   223
val conj_cong = prove_goal IFOLP.thy 
clasohm@0
   224
    "[| p:P <-> P';  !!x.x:P' ==> q(x):Q <-> Q' |] ==> ?p:(P&Q) <-> (P'&Q')"
clasohm@0
   225
 (fn prems =>
clasohm@0
   226
  [ (cut_facts_tac prems 1),
clasohm@0
   227
    (REPEAT  (ares_tac [iffI,conjI] 1
clasohm@0
   228
      ORELSE  eresolve_tac [iffE,conjE,mp] 1
clasohm@0
   229
      ORELSE  iff_tac prems 1)) ]);
clasohm@0
   230
clasohm@0
   231
val disj_cong = prove_goal IFOLP.thy 
clasohm@0
   232
    "[| p:P <-> P';  q:Q <-> Q' |] ==> ?p:(P|Q) <-> (P'|Q')"
clasohm@0
   233
 (fn prems =>
clasohm@0
   234
  [ (cut_facts_tac prems 1),
clasohm@0
   235
    (REPEAT  (eresolve_tac [iffE,disjE,disjI1,disjI2] 1
clasohm@0
   236
      ORELSE  ares_tac [iffI] 1
clasohm@0
   237
      ORELSE  mp_tac 1)) ]);
clasohm@0
   238
clasohm@0
   239
val imp_cong = prove_goal IFOLP.thy 
clasohm@0
   240
    "[| p:P <-> P';  !!x.x:P' ==> q(x):Q <-> Q' |] ==> ?p:(P-->Q) <-> (P'-->Q')"
clasohm@0
   241
 (fn prems =>
clasohm@0
   242
  [ (cut_facts_tac prems 1),
clasohm@0
   243
    (REPEAT   (ares_tac [iffI,impI] 1
clasohm@1459
   244
      ORELSE  etac iffE 1
clasohm@0
   245
      ORELSE  mp_tac 1 ORELSE iff_tac prems 1)) ]);
clasohm@0
   246
clasohm@0
   247
val iff_cong = prove_goal IFOLP.thy 
clasohm@0
   248
    "[| p:P <-> P';  q:Q <-> Q' |] ==> ?p:(P<->Q) <-> (P'<->Q')"
clasohm@0
   249
 (fn prems =>
clasohm@0
   250
  [ (cut_facts_tac prems 1),
clasohm@1459
   251
    (REPEAT   (etac iffE 1
clasohm@0
   252
      ORELSE  ares_tac [iffI] 1
clasohm@0
   253
      ORELSE  mp_tac 1)) ]);
clasohm@0
   254
clasohm@0
   255
val not_cong = prove_goal IFOLP.thy 
clasohm@0
   256
    "p:P <-> P' ==> ?p:~P <-> ~P'"
clasohm@0
   257
 (fn prems =>
clasohm@0
   258
  [ (cut_facts_tac prems 1),
clasohm@0
   259
    (REPEAT   (ares_tac [iffI,notI] 1
clasohm@0
   260
      ORELSE  mp_tac 1
clasohm@0
   261
      ORELSE  eresolve_tac [iffE,notE] 1)) ]);
clasohm@0
   262
clasohm@0
   263
val all_cong = prove_goal IFOLP.thy 
clasohm@0
   264
    "(!!x.f(x):P(x) <-> Q(x)) ==> ?p:(ALL x.P(x)) <-> (ALL x.Q(x))"
clasohm@0
   265
 (fn prems =>
clasohm@0
   266
  [ (REPEAT   (ares_tac [iffI,allI] 1
clasohm@0
   267
      ORELSE   mp_tac 1
clasohm@1459
   268
      ORELSE   etac allE 1 ORELSE iff_tac prems 1)) ]);
clasohm@0
   269
clasohm@0
   270
val ex_cong = prove_goal IFOLP.thy 
clasohm@0
   271
    "(!!x.f(x):P(x) <-> Q(x)) ==> ?p:(EX x.P(x)) <-> (EX x.Q(x))"
clasohm@0
   272
 (fn prems =>
clasohm@1459
   273
  [ (REPEAT   (etac exE 1 ORELSE ares_tac [iffI,exI] 1
clasohm@0
   274
      ORELSE   mp_tac 1
clasohm@0
   275
      ORELSE   iff_tac prems 1)) ]);
clasohm@0
   276
clasohm@0
   277
(*NOT PROVED
clasohm@0
   278
val ex1_cong = prove_goal IFOLP.thy 
clasohm@0
   279
    "(!!x.f(x):P(x) <-> Q(x)) ==> ?p:(EX! x.P(x)) <-> (EX! x.Q(x))"
clasohm@0
   280
 (fn prems =>
clasohm@0
   281
  [ (REPEAT   (eresolve_tac [ex1E, spec RS mp] 1 ORELSE ares_tac [iffI,ex1I] 1
clasohm@0
   282
      ORELSE   mp_tac 1
clasohm@0
   283
      ORELSE   iff_tac prems 1)) ]);
clasohm@0
   284
*)
clasohm@0
   285
clasohm@0
   286
(*** Equality rules ***)
clasohm@0
   287
clasohm@0
   288
val refl = ieqI;
clasohm@0
   289
clasohm@0
   290
val subst = prove_goal IFOLP.thy "[| p:a=b;  q:P(a) |] ==> ?p : P(b)"
clasohm@0
   291
 (fn [prem1,prem2] => [ rtac (prem2 RS rev_mp) 1, (rtac (prem1 RS ieqE) 1), 
clasohm@0
   292
                        rtac impI 1, atac 1 ]);
clasohm@0
   293
clasohm@0
   294
val sym = prove_goal IFOLP.thy "q:a=b ==> ?c:b=a"
clasohm@0
   295
 (fn [major] => [ (rtac (major RS subst) 1), (rtac refl 1) ]);
clasohm@0
   296
clasohm@0
   297
val trans = prove_goal IFOLP.thy "[| p:a=b;  q:b=c |] ==> ?d:a=c"
clasohm@0
   298
 (fn [prem1,prem2] => [ (rtac (prem2 RS subst) 1), (rtac prem1 1) ]);
clasohm@0
   299
clasohm@0
   300
(** ~ b=a ==> ~ a=b **)
clasohm@0
   301
val not_sym = prove_goal IFOLP.thy "p:~ b=a ==> ?q:~ a=b"
clasohm@0
   302
 (fn [prem] => [ (rtac (prem RS contrapos) 1), (etac sym 1) ]);
clasohm@0
   303
clasohm@0
   304
(*calling "standard" reduces maxidx to 0*)
clasohm@0
   305
val ssubst = standard (sym RS subst);
clasohm@0
   306
clasohm@0
   307
(*A special case of ex1E that would otherwise need quantifier expansion*)
clasohm@0
   308
val ex1_equalsE = prove_goal IFOLP.thy
clasohm@0
   309
    "[| p:EX! x.P(x);  q:P(a);  r:P(b) |] ==> ?d:a=b"
clasohm@0
   310
 (fn prems =>
clasohm@0
   311
  [ (cut_facts_tac prems 1),
clasohm@0
   312
    (etac ex1E 1),
clasohm@0
   313
    (rtac trans 1),
clasohm@0
   314
    (rtac sym 2),
clasohm@0
   315
    (REPEAT (eresolve_tac [asm_rl, spec RS mp] 1)) ]);
clasohm@0
   316
clasohm@0
   317
(** Polymorphic congruence rules **)
clasohm@0
   318
clasohm@0
   319
val subst_context = prove_goal IFOLP.thy 
clasohm@0
   320
   "[| p:a=b |]  ==>  ?d:t(a)=t(b)"
clasohm@0
   321
 (fn prems=>
clasohm@0
   322
  [ (resolve_tac (prems RL [ssubst]) 1),
clasohm@1459
   323
    (rtac refl 1) ]);
clasohm@0
   324
clasohm@0
   325
val subst_context2 = prove_goal IFOLP.thy 
clasohm@0
   326
   "[| p:a=b;  q:c=d |]  ==>  ?p:t(a,c)=t(b,d)"
clasohm@0
   327
 (fn prems=>
clasohm@0
   328
  [ (EVERY1 (map rtac ((prems RL [ssubst]) @ [refl]))) ]);
clasohm@0
   329
clasohm@0
   330
val subst_context3 = prove_goal IFOLP.thy 
clasohm@0
   331
   "[| p:a=b;  q:c=d;  r:e=f |]  ==>  ?p:t(a,c,e)=t(b,d,f)"
clasohm@0
   332
 (fn prems=>
clasohm@0
   333
  [ (EVERY1 (map rtac ((prems RL [ssubst]) @ [refl]))) ]);
clasohm@0
   334
clasohm@0
   335
(*Useful with eresolve_tac for proving equalties from known equalities.
clasohm@1459
   336
        a = b
clasohm@1459
   337
        |   |
clasohm@1459
   338
        c = d   *)
clasohm@0
   339
val box_equals = prove_goal IFOLP.thy
clasohm@0
   340
    "[| p:a=b;  q:a=c;  r:b=d |] ==> ?p:c=d"  
clasohm@0
   341
 (fn prems=>
clasohm@1459
   342
  [ (rtac trans 1),
clasohm@1459
   343
    (rtac trans 1),
clasohm@1459
   344
    (rtac sym 1),
clasohm@0
   345
    (REPEAT (resolve_tac prems 1)) ]);
clasohm@0
   346
clasohm@0
   347
(*Dual of box_equals: for proving equalities backwards*)
clasohm@0
   348
val simp_equals = prove_goal IFOLP.thy
clasohm@0
   349
    "[| p:a=c;  q:b=d;  r:c=d |] ==> ?p:a=b"  
clasohm@0
   350
 (fn prems=>
clasohm@1459
   351
  [ (rtac trans 1),
clasohm@1459
   352
    (rtac trans 1),
clasohm@0
   353
    (REPEAT (resolve_tac (prems @ (prems RL [sym])) 1)) ]);
clasohm@0
   354
clasohm@0
   355
(** Congruence rules for predicate letters **)
clasohm@0
   356
clasohm@0
   357
val pred1_cong = prove_goal IFOLP.thy
clasohm@0
   358
    "p:a=a' ==> ?p:P(a) <-> P(a')"
clasohm@0
   359
 (fn prems =>
clasohm@0
   360
  [ (cut_facts_tac prems 1),
clasohm@0
   361
    (rtac iffI 1),
clasohm@0
   362
    (DEPTH_SOLVE (eresolve_tac [asm_rl, subst, ssubst] 1)) ]);
clasohm@0
   363
clasohm@0
   364
val pred2_cong = prove_goal IFOLP.thy
clasohm@0
   365
    "[| p:a=a';  q:b=b' |] ==> ?p:P(a,b) <-> P(a',b')"
clasohm@0
   366
 (fn prems =>
clasohm@0
   367
  [ (cut_facts_tac prems 1),
clasohm@0
   368
    (rtac iffI 1),
clasohm@0
   369
    (DEPTH_SOLVE (eresolve_tac [asm_rl, subst, ssubst] 1)) ]);
clasohm@0
   370
clasohm@0
   371
val pred3_cong = prove_goal IFOLP.thy
clasohm@0
   372
    "[| p:a=a';  q:b=b';  r:c=c' |] ==> ?p:P(a,b,c) <-> P(a',b',c')"
clasohm@0
   373
 (fn prems =>
clasohm@0
   374
  [ (cut_facts_tac prems 1),
clasohm@0
   375
    (rtac iffI 1),
clasohm@0
   376
    (DEPTH_SOLVE (eresolve_tac [asm_rl, subst, ssubst] 1)) ]);
clasohm@0
   377
clasohm@0
   378
(*special cases for free variables P, Q, R, S -- up to 3 arguments*)
clasohm@0
   379
clasohm@0
   380
val pred_congs = 
clasohm@0
   381
    flat (map (fn c => 
clasohm@1459
   382
               map (fn th => read_instantiate [("P",c)] th)
clasohm@1459
   383
                   [pred1_cong,pred2_cong,pred3_cong])
clasohm@1459
   384
               (explode"PQRS"));
clasohm@0
   385
clasohm@0
   386
(*special case for the equality predicate!*)
clasohm@0
   387
val eq_cong = read_instantiate [("P","op =")] pred2_cong;
clasohm@0
   388
clasohm@0
   389
clasohm@0
   390
(*** Simplifications of assumed implications.
clasohm@0
   391
     Roy Dyckhoff has proved that conj_impE, disj_impE, and imp_impE
clasohm@0
   392
     used with mp_tac (restricted to atomic formulae) is COMPLETE for 
clasohm@0
   393
     intuitionistic propositional logic.  See
clasohm@0
   394
   R. Dyckhoff, Contraction-free sequent calculi for intuitionistic logic
clasohm@0
   395
    (preprint, University of St Andrews, 1991)  ***)
clasohm@0
   396
clasohm@0
   397
val conj_impE = prove_goal IFOLP.thy 
clasohm@0
   398
    "[| p:(P&Q)-->S;  !!x.x:P-->(Q-->S) ==> q(x):R |] ==> ?p:R"
clasohm@0
   399
 (fn major::prems=>
clasohm@0
   400
  [ (REPEAT (ares_tac ([conjI, impI, major RS mp]@prems) 1)) ]);
clasohm@0
   401
clasohm@0
   402
val disj_impE = prove_goal IFOLP.thy 
clasohm@0
   403
    "[| p:(P|Q)-->S;  !!x y.[| x:P-->S; y:Q-->S |] ==> q(x,y):R |] ==> ?p:R"
clasohm@0
   404
 (fn major::prems=>
clasohm@0
   405
  [ (DEPTH_SOLVE (ares_tac ([disjI1, disjI2, impI, major RS mp]@prems) 1)) ]);
clasohm@0
   406
clasohm@0
   407
(*Simplifies the implication.  Classical version is stronger. 
clasohm@0
   408
  Still UNSAFE since Q must be provable -- backtracking needed.  *)
clasohm@0
   409
val imp_impE = prove_goal IFOLP.thy 
clasohm@0
   410
    "[| p:(P-->Q)-->S;  !!x y.[| x:P; y:Q-->S |] ==> q(x,y):Q;  !!x.x:S ==> r(x):R |] ==> \
clasohm@0
   411
\    ?p:R"
clasohm@0
   412
 (fn major::prems=>
clasohm@0
   413
  [ (REPEAT (ares_tac ([impI, major RS mp]@prems) 1)) ]);
clasohm@0
   414
clasohm@0
   415
(*Simplifies the implication.  Classical version is stronger. 
clasohm@0
   416
  Still UNSAFE since ~P must be provable -- backtracking needed.  *)
clasohm@0
   417
val not_impE = prove_goal IFOLP.thy
clasohm@0
   418
    "[| p:~P --> S;  !!y.y:P ==> q(y):False;  !!y.y:S ==> r(y):R |] ==> ?p:R"
clasohm@0
   419
 (fn major::prems=>
clasohm@0
   420
  [ (REPEAT (ares_tac ([notI, impI, major RS mp]@prems) 1)) ]);
clasohm@0
   421
clasohm@0
   422
(*Simplifies the implication.   UNSAFE.  *)
clasohm@0
   423
val iff_impE = prove_goal IFOLP.thy 
clasohm@0
   424
    "[| p:(P<->Q)-->S;  !!x y.[| x:P; y:Q-->S |] ==> q(x,y):Q;  \
clasohm@0
   425
\       !!x y.[| x:Q; y:P-->S |] ==> r(x,y):P;  !!x.x:S ==> s(x):R |] ==> ?p:R"
clasohm@0
   426
 (fn major::prems=>
clasohm@0
   427
  [ (REPEAT (ares_tac ([iffI, impI, major RS mp]@prems) 1)) ]);
clasohm@0
   428
clasohm@0
   429
(*What if (ALL x.~~P(x)) --> ~~(ALL x.P(x)) is an assumption? UNSAFE*)
clasohm@0
   430
val all_impE = prove_goal IFOLP.thy 
clasohm@0
   431
    "[| p:(ALL x.P(x))-->S;  !!x.q:P(x);  !!y.y:S ==> r(y):R |] ==> ?p:R"
clasohm@0
   432
 (fn major::prems=>
clasohm@0
   433
  [ (REPEAT (ares_tac ([allI, impI, major RS mp]@prems) 1)) ]);
clasohm@0
   434
clasohm@0
   435
(*Unsafe: (EX x.P(x))-->S  is equivalent to  ALL x.P(x)-->S.  *)
clasohm@0
   436
val ex_impE = prove_goal IFOLP.thy 
clasohm@0
   437
    "[| p:(EX x.P(x))-->S;  !!y.y:P(a)-->S ==> q(y):R |] ==> ?p:R"
clasohm@0
   438
 (fn major::prems=>
clasohm@0
   439
  [ (REPEAT (ares_tac ([exI, impI, major RS mp]@prems) 1)) ]);
clasohm@0
   440
clasohm@0
   441
end;
clasohm@0
   442
clasohm@0
   443
open IFOLP_Lemmas;
clasohm@0
   444