src/FOLP/IFOLP.thy
author haftmann
Wed Aug 18 12:26:48 2010 +0200 (2010-08-18)
changeset 38522 de7984a7172b
parent 36452 d37c6eed8117
child 38800 34c84817e39c
permissions -rw-r--r--
deglobalization
     1 (*  Title:      FOLP/IFOLP.thy
     2     Author:     Martin D Coen, Cambridge University Computer Laboratory
     3     Copyright   1992  University of Cambridge
     4 *)
     5 
     6 header {* Intuitionistic First-Order Logic with Proofs *}
     7 
     8 theory IFOLP
     9 imports Pure
    10 uses ("hypsubst.ML") ("intprover.ML")
    11 begin
    12 
    13 setup PureThy.old_appl_syntax_setup
    14 
    15 classes "term"
    16 default_sort "term"
    17 
    18 typedecl p
    19 typedecl o
    20 
    21 consts
    22       (*** Judgements ***)
    23  Proof          ::   "[o,p]=>prop"
    24  EqProof        ::   "[p,p,o]=>prop"    ("(3_ /= _ :/ _)" [10,10,10] 5)
    25 
    26       (*** Logical Connectives -- Type Formers ***)
    27  "op ="         ::      "['a,'a] => o"  (infixl "=" 50)
    28  True           ::      "o"
    29  False          ::      "o"
    30  Not            ::      "o => o"        ("~ _" [40] 40)
    31  "op &"         ::      "[o,o] => o"    (infixr "&" 35)
    32  "op |"         ::      "[o,o] => o"    (infixr "|" 30)
    33  "op -->"       ::      "[o,o] => o"    (infixr "-->" 25)
    34  "op <->"       ::      "[o,o] => o"    (infixr "<->" 25)
    35       (*Quantifiers*)
    36  All            ::      "('a => o) => o"        (binder "ALL " 10)
    37  Ex             ::      "('a => o) => o"        (binder "EX " 10)
    38  Ex1            ::      "('a => o) => o"        (binder "EX! " 10)
    39       (*Rewriting gadgets*)
    40  NORM           ::      "o => o"
    41  norm           ::      "'a => 'a"
    42 
    43       (*** Proof Term Formers: precedence must exceed 50 ***)
    44  tt             :: "p"
    45  contr          :: "p=>p"
    46  fst            :: "p=>p"
    47  snd            :: "p=>p"
    48  pair           :: "[p,p]=>p"           ("(1<_,/_>)")
    49  split          :: "[p, [p,p]=>p] =>p"
    50  inl            :: "p=>p"
    51  inr            :: "p=>p"
    52  when           :: "[p, p=>p, p=>p]=>p"
    53  lambda         :: "(p => p) => p"      (binder "lam " 55)
    54  "op `"         :: "[p,p]=>p"           (infixl "`" 60)
    55  alll           :: "['a=>p]=>p"         (binder "all " 55)
    56  "op ^"         :: "[p,'a]=>p"          (infixl "^" 55)
    57  exists         :: "['a,p]=>p"          ("(1[_,/_])")
    58  xsplit         :: "[p,['a,p]=>p]=>p"
    59  ideq           :: "'a=>p"
    60  idpeel         :: "[p,'a=>p]=>p"
    61  nrm            :: p
    62  NRM            :: p
    63 
    64 syntax "_Proof" :: "[p,o]=>prop"    ("(_ /: _)" [51, 10] 5)
    65 
    66 ML {*
    67 
    68 (*show_proofs:=true displays the proof terms -- they are ENORMOUS*)
    69 val show_proofs = Unsynchronized.ref false;
    70 
    71 fun proof_tr [p,P] = Const (@{const_name Proof}, dummyT) $ P $ p;
    72 
    73 fun proof_tr' [P,p] =
    74   if ! show_proofs then Const (@{syntax_const "_Proof"}, dummyT) $ p $ P
    75   else P  (*this case discards the proof term*);
    76 *}
    77 
    78 parse_translation {* [(@{syntax_const "_Proof"}, proof_tr)] *}
    79 print_translation {* [(@{const_syntax Proof}, proof_tr')] *}
    80 
    81 axioms
    82 
    83 (**** Propositional logic ****)
    84 
    85 (*Equality*)
    86 (* Like Intensional Equality in MLTT - but proofs distinct from terms *)
    87 
    88 ieqI:      "ideq(a) : a=a"
    89 ieqE:      "[| p : a=b;  !!x. f(x) : P(x,x) |] ==> idpeel(p,f) : P(a,b)"
    90 
    91 (* Truth and Falsity *)
    92 
    93 TrueI:     "tt : True"
    94 FalseE:    "a:False ==> contr(a):P"
    95 
    96 (* Conjunction *)
    97 
    98 conjI:     "[| a:P;  b:Q |] ==> <a,b> : P&Q"
    99 conjunct1: "p:P&Q ==> fst(p):P"
   100 conjunct2: "p:P&Q ==> snd(p):Q"
   101 
   102 (* Disjunction *)
   103 
   104 disjI1:    "a:P ==> inl(a):P|Q"
   105 disjI2:    "b:Q ==> inr(b):P|Q"
   106 disjE:     "[| a:P|Q;  !!x. x:P ==> f(x):R;  !!x. x:Q ==> g(x):R
   107            |] ==> when(a,f,g):R"
   108 
   109 (* Implication *)
   110 
   111 impI:      "(!!x. x:P ==> f(x):Q) ==> lam x. f(x):P-->Q"
   112 mp:        "[| f:P-->Q;  a:P |] ==> f`a:Q"
   113 
   114 (*Quantifiers*)
   115 
   116 allI:      "(!!x. f(x) : P(x)) ==> all x. f(x) : ALL x. P(x)"
   117 spec:      "(f:ALL x. P(x)) ==> f^x : P(x)"
   118 
   119 exI:       "p : P(x) ==> [x,p] : EX x. P(x)"
   120 exE:       "[| p: EX x. P(x);  !!x u. u:P(x) ==> f(x,u) : R |] ==> xsplit(p,f):R"
   121 
   122 (**** Equality between proofs ****)
   123 
   124 prefl:     "a : P ==> a = a : P"
   125 psym:      "a = b : P ==> b = a : P"
   126 ptrans:    "[| a = b : P;  b = c : P |] ==> a = c : P"
   127 
   128 idpeelB:   "[| !!x. f(x) : P(x,x) |] ==> idpeel(ideq(a),f) = f(a) : P(a,a)"
   129 
   130 fstB:      "a:P ==> fst(<a,b>) = a : P"
   131 sndB:      "b:Q ==> snd(<a,b>) = b : Q"
   132 pairEC:    "p:P&Q ==> p = <fst(p),snd(p)> : P&Q"
   133 
   134 whenBinl:  "[| a:P;  !!x. x:P ==> f(x) : Q |] ==> when(inl(a),f,g) = f(a) : Q"
   135 whenBinr:  "[| b:P;  !!x. x:P ==> g(x) : Q |] ==> when(inr(b),f,g) = g(b) : Q"
   136 plusEC:    "a:P|Q ==> when(a,%x. inl(x),%y. inr(y)) = a : P|Q"
   137 
   138 applyB:     "[| a:P;  !!x. x:P ==> b(x) : Q |] ==> (lam x. b(x)) ` a = b(a) : Q"
   139 funEC:      "f:P ==> f = lam x. f`x : P"
   140 
   141 specB:      "[| !!x. f(x) : P(x) |] ==> (all x. f(x)) ^ a = f(a) : P(a)"
   142 
   143 
   144 (**** Definitions ****)
   145 
   146 not_def:              "~P == P-->False"
   147 iff_def:         "P<->Q == (P-->Q) & (Q-->P)"
   148 
   149 (*Unique existence*)
   150 ex1_def:   "EX! x. P(x) == EX x. P(x) & (ALL y. P(y) --> y=x)"
   151 
   152 (*Rewriting -- special constants to flag normalized terms and formulae*)
   153 norm_eq: "nrm : norm(x) = x"
   154 NORM_iff:        "NRM : NORM(P) <-> P"
   155 
   156 (*** Sequent-style elimination rules for & --> and ALL ***)
   157 
   158 schematic_lemma conjE:
   159   assumes "p:P&Q"
   160     and "!!x y.[| x:P; y:Q |] ==> f(x,y):R"
   161   shows "?a:R"
   162   apply (rule assms(2))
   163    apply (rule conjunct1 [OF assms(1)])
   164   apply (rule conjunct2 [OF assms(1)])
   165   done
   166 
   167 schematic_lemma impE:
   168   assumes "p:P-->Q"
   169     and "q:P"
   170     and "!!x. x:Q ==> r(x):R"
   171   shows "?p:R"
   172   apply (rule assms mp)+
   173   done
   174 
   175 schematic_lemma allE:
   176   assumes "p:ALL x. P(x)"
   177     and "!!y. y:P(x) ==> q(y):R"
   178   shows "?p:R"
   179   apply (rule assms spec)+
   180   done
   181 
   182 (*Duplicates the quantifier; for use with eresolve_tac*)
   183 schematic_lemma all_dupE:
   184   assumes "p:ALL x. P(x)"
   185     and "!!y z.[| y:P(x); z:ALL x. P(x) |] ==> q(y,z):R"
   186   shows "?p:R"
   187   apply (rule assms spec)+
   188   done
   189 
   190 
   191 (*** Negation rules, which translate between ~P and P-->False ***)
   192 
   193 schematic_lemma notI:
   194   assumes "!!x. x:P ==> q(x):False"
   195   shows "?p:~P"
   196   unfolding not_def
   197   apply (assumption | rule assms impI)+
   198   done
   199 
   200 schematic_lemma notE: "p:~P \<Longrightarrow> q:P \<Longrightarrow> ?p:R"
   201   unfolding not_def
   202   apply (drule (1) mp)
   203   apply (erule FalseE)
   204   done
   205 
   206 (*This is useful with the special implication rules for each kind of P. *)
   207 schematic_lemma not_to_imp:
   208   assumes "p:~P"
   209     and "!!x. x:(P-->False) ==> q(x):Q"
   210   shows "?p:Q"
   211   apply (assumption | rule assms impI notE)+
   212   done
   213 
   214 (* For substitution int an assumption P, reduce Q to P-->Q, substitute into
   215    this implication, then apply impI to move P back into the assumptions.*)
   216 schematic_lemma rev_mp: "[| p:P;  q:P --> Q |] ==> ?p:Q"
   217   apply (assumption | rule mp)+
   218   done
   219 
   220 
   221 (*Contrapositive of an inference rule*)
   222 schematic_lemma contrapos:
   223   assumes major: "p:~Q"
   224     and minor: "!!y. y:P==>q(y):Q"
   225   shows "?a:~P"
   226   apply (rule major [THEN notE, THEN notI])
   227   apply (erule minor)
   228   done
   229 
   230 (** Unique assumption tactic.
   231     Ignores proof objects.
   232     Fails unless one assumption is equal and exactly one is unifiable
   233 **)
   234 
   235 ML {*
   236 local
   237   fun discard_proof (Const (@{const_name Proof}, _) $ P $ _) = P;
   238 in
   239 val uniq_assume_tac =
   240   SUBGOAL
   241     (fn (prem,i) =>
   242       let val hyps = map discard_proof (Logic.strip_assums_hyp prem)
   243           and concl = discard_proof (Logic.strip_assums_concl prem)
   244       in
   245           if exists (fn hyp => hyp aconv concl) hyps
   246           then case distinct (op =) (filter (fn hyp => Term.could_unify (hyp, concl)) hyps) of
   247                    [_] => assume_tac i
   248                  |  _  => no_tac
   249           else no_tac
   250       end);
   251 end;
   252 *}
   253 
   254 
   255 (*** Modus Ponens Tactics ***)
   256 
   257 (*Finds P-->Q and P in the assumptions, replaces implication by Q *)
   258 ML {*
   259   fun mp_tac i = eresolve_tac [@{thm notE}, make_elim @{thm mp}] i  THEN  assume_tac i
   260 *}
   261 
   262 (*Like mp_tac but instantiates no variables*)
   263 ML {*
   264   fun int_uniq_mp_tac i = eresolve_tac [@{thm notE}, @{thm impE}] i  THEN  uniq_assume_tac i
   265 *}
   266 
   267 
   268 (*** If-and-only-if ***)
   269 
   270 schematic_lemma iffI:
   271   assumes "!!x. x:P ==> q(x):Q"
   272     and "!!x. x:Q ==> r(x):P"
   273   shows "?p:P<->Q"
   274   unfolding iff_def
   275   apply (assumption | rule assms conjI impI)+
   276   done
   277 
   278 
   279 (*Observe use of rewrite_rule to unfold "<->" in meta-assumptions (prems) *)
   280   
   281 schematic_lemma iffE:
   282   assumes "p:P <-> Q"
   283     and "!!x y.[| x:P-->Q; y:Q-->P |] ==> q(x,y):R"
   284   shows "?p:R"
   285   apply (rule conjE)
   286    apply (rule assms(1) [unfolded iff_def])
   287   apply (rule assms(2))
   288    apply assumption+
   289   done
   290 
   291 (* Destruct rules for <-> similar to Modus Ponens *)
   292 
   293 schematic_lemma iffD1: "[| p:P <-> Q; q:P |] ==> ?p:Q"
   294   unfolding iff_def
   295   apply (rule conjunct1 [THEN mp], assumption+)
   296   done
   297 
   298 schematic_lemma iffD2: "[| p:P <-> Q; q:Q |] ==> ?p:P"
   299   unfolding iff_def
   300   apply (rule conjunct2 [THEN mp], assumption+)
   301   done
   302 
   303 schematic_lemma iff_refl: "?p:P <-> P"
   304   apply (rule iffI)
   305    apply assumption+
   306   done
   307 
   308 schematic_lemma iff_sym: "p:Q <-> P ==> ?p:P <-> Q"
   309   apply (erule iffE)
   310   apply (rule iffI)
   311    apply (erule (1) mp)+
   312   done
   313 
   314 schematic_lemma iff_trans: "[| p:P <-> Q; q:Q<-> R |] ==> ?p:P <-> R"
   315   apply (rule iffI)
   316    apply (assumption | erule iffE | erule (1) impE)+
   317   done
   318 
   319 (*** Unique existence.  NOTE THAT the following 2 quantifications
   320    EX!x such that [EX!y such that P(x,y)]     (sequential)
   321    EX!x,y such that P(x,y)                    (simultaneous)
   322  do NOT mean the same thing.  The parser treats EX!x y.P(x,y) as sequential.
   323 ***)
   324 
   325 schematic_lemma ex1I:
   326   assumes "p:P(a)"
   327     and "!!x u. u:P(x) ==> f(u) : x=a"
   328   shows "?p:EX! x. P(x)"
   329   unfolding ex1_def
   330   apply (assumption | rule assms exI conjI allI impI)+
   331   done
   332 
   333 schematic_lemma ex1E:
   334   assumes "p:EX! x. P(x)"
   335     and "!!x u v. [| u:P(x);  v:ALL y. P(y) --> y=x |] ==> f(x,u,v):R"
   336   shows "?a : R"
   337   apply (insert assms(1) [unfolded ex1_def])
   338   apply (erule exE conjE | assumption | rule assms(1))+
   339   apply (erule assms(2), assumption)
   340   done
   341 
   342 
   343 (*** <-> congruence rules for simplification ***)
   344 
   345 (*Use iffE on a premise.  For conj_cong, imp_cong, all_cong, ex_cong*)
   346 ML {*
   347 fun iff_tac prems i =
   348     resolve_tac (prems RL [@{thm iffE}]) i THEN
   349     REPEAT1 (eresolve_tac [asm_rl, @{thm mp}] i)
   350 *}
   351 
   352 schematic_lemma conj_cong:
   353   assumes "p:P <-> P'"
   354     and "!!x. x:P' ==> q(x):Q <-> Q'"
   355   shows "?p:(P&Q) <-> (P'&Q')"
   356   apply (insert assms(1))
   357   apply (assumption | rule iffI conjI |
   358     erule iffE conjE mp | tactic {* iff_tac @{thms assms} 1 *})+
   359   done
   360 
   361 schematic_lemma disj_cong:
   362   "[| p:P <-> P'; q:Q <-> Q' |] ==> ?p:(P|Q) <-> (P'|Q')"
   363   apply (erule iffE disjE disjI1 disjI2 | assumption | rule iffI | tactic {* mp_tac 1 *})+
   364   done
   365 
   366 schematic_lemma imp_cong:
   367   assumes "p:P <-> P'"
   368     and "!!x. x:P' ==> q(x):Q <-> Q'"
   369   shows "?p:(P-->Q) <-> (P'-->Q')"
   370   apply (insert assms(1))
   371   apply (assumption | rule iffI impI | erule iffE | tactic {* mp_tac 1 *} |
   372     tactic {* iff_tac @{thms assms} 1 *})+
   373   done
   374 
   375 schematic_lemma iff_cong:
   376   "[| p:P <-> P'; q:Q <-> Q' |] ==> ?p:(P<->Q) <-> (P'<->Q')"
   377   apply (erule iffE | assumption | rule iffI | tactic {* mp_tac 1 *})+
   378   done
   379 
   380 schematic_lemma not_cong:
   381   "p:P <-> P' ==> ?p:~P <-> ~P'"
   382   apply (assumption | rule iffI notI | tactic {* mp_tac 1 *} | erule iffE notE)+
   383   done
   384 
   385 schematic_lemma all_cong:
   386   assumes "!!x. f(x):P(x) <-> Q(x)"
   387   shows "?p:(ALL x. P(x)) <-> (ALL x. Q(x))"
   388   apply (assumption | rule iffI allI | tactic {* mp_tac 1 *} | erule allE |
   389     tactic {* iff_tac @{thms assms} 1 *})+
   390   done
   391 
   392 schematic_lemma ex_cong:
   393   assumes "!!x. f(x):P(x) <-> Q(x)"
   394   shows "?p:(EX x. P(x)) <-> (EX x. Q(x))"
   395   apply (erule exE | assumption | rule iffI exI | tactic {* mp_tac 1 *} |
   396     tactic {* iff_tac @{thms assms} 1 *})+
   397   done
   398 
   399 (*NOT PROVED
   400 bind_thm ("ex1_cong", prove_goal (the_context ())
   401     "(!!x.f(x):P(x) <-> Q(x)) ==> ?p:(EX! x.P(x)) <-> (EX! x.Q(x))"
   402  (fn prems =>
   403   [ (REPEAT   (eresolve_tac [ex1E, spec RS mp] 1 ORELSE ares_tac [iffI,ex1I] 1
   404       ORELSE   mp_tac 1
   405       ORELSE   iff_tac prems 1)) ]))
   406 *)
   407 
   408 (*** Equality rules ***)
   409 
   410 lemmas refl = ieqI
   411 
   412 schematic_lemma subst:
   413   assumes prem1: "p:a=b"
   414     and prem2: "q:P(a)"
   415   shows "?p : P(b)"
   416   apply (rule prem2 [THEN rev_mp])
   417   apply (rule prem1 [THEN ieqE])
   418   apply (rule impI)
   419   apply assumption
   420   done
   421 
   422 schematic_lemma sym: "q:a=b ==> ?c:b=a"
   423   apply (erule subst)
   424   apply (rule refl)
   425   done
   426 
   427 schematic_lemma trans: "[| p:a=b;  q:b=c |] ==> ?d:a=c"
   428   apply (erule (1) subst)
   429   done
   430 
   431 (** ~ b=a ==> ~ a=b **)
   432 schematic_lemma not_sym: "p:~ b=a ==> ?q:~ a=b"
   433   apply (erule contrapos)
   434   apply (erule sym)
   435   done
   436 
   437 (*calling "standard" reduces maxidx to 0*)
   438 lemmas ssubst = sym [THEN subst, standard]
   439 
   440 (*A special case of ex1E that would otherwise need quantifier expansion*)
   441 schematic_lemma ex1_equalsE: "[| p:EX! x. P(x);  q:P(a);  r:P(b) |] ==> ?d:a=b"
   442   apply (erule ex1E)
   443   apply (rule trans)
   444    apply (rule_tac [2] sym)
   445    apply (assumption | erule spec [THEN mp])+
   446   done
   447 
   448 (** Polymorphic congruence rules **)
   449 
   450 schematic_lemma subst_context: "[| p:a=b |]  ==>  ?d:t(a)=t(b)"
   451   apply (erule ssubst)
   452   apply (rule refl)
   453   done
   454 
   455 schematic_lemma subst_context2: "[| p:a=b;  q:c=d |]  ==>  ?p:t(a,c)=t(b,d)"
   456   apply (erule ssubst)+
   457   apply (rule refl)
   458   done
   459 
   460 schematic_lemma subst_context3: "[| p:a=b;  q:c=d;  r:e=f |]  ==>  ?p:t(a,c,e)=t(b,d,f)"
   461   apply (erule ssubst)+
   462   apply (rule refl)
   463   done
   464 
   465 (*Useful with eresolve_tac for proving equalties from known equalities.
   466         a = b
   467         |   |
   468         c = d   *)
   469 schematic_lemma box_equals: "[| p:a=b;  q:a=c;  r:b=d |] ==> ?p:c=d"
   470   apply (rule trans)
   471    apply (rule trans)
   472     apply (rule sym)
   473     apply assumption+
   474   done
   475 
   476 (*Dual of box_equals: for proving equalities backwards*)
   477 schematic_lemma simp_equals: "[| p:a=c;  q:b=d;  r:c=d |] ==> ?p:a=b"
   478   apply (rule trans)
   479    apply (rule trans)
   480     apply (assumption | rule sym)+
   481   done
   482 
   483 (** Congruence rules for predicate letters **)
   484 
   485 schematic_lemma pred1_cong: "p:a=a' ==> ?p:P(a) <-> P(a')"
   486   apply (rule iffI)
   487    apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE eresolve_tac [@{thm subst}, @{thm ssubst}] 1) *})
   488   done
   489 
   490 schematic_lemma pred2_cong: "[| p:a=a';  q:b=b' |] ==> ?p:P(a,b) <-> P(a',b')"
   491   apply (rule iffI)
   492    apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE eresolve_tac [@{thm subst}, @{thm ssubst}] 1) *})
   493   done
   494 
   495 schematic_lemma pred3_cong: "[| p:a=a';  q:b=b';  r:c=c' |] ==> ?p:P(a,b,c) <-> P(a',b',c')"
   496   apply (rule iffI)
   497    apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE eresolve_tac [@{thm subst}, @{thm ssubst}] 1) *})
   498   done
   499 
   500 lemmas pred_congs = pred1_cong pred2_cong pred3_cong
   501 
   502 (*special case for the equality predicate!*)
   503 lemmas eq_cong = pred2_cong [where P = "op =", standard]
   504 
   505 
   506 (*** Simplifications of assumed implications.
   507      Roy Dyckhoff has proved that conj_impE, disj_impE, and imp_impE
   508      used with mp_tac (restricted to atomic formulae) is COMPLETE for
   509      intuitionistic propositional logic.  See
   510    R. Dyckhoff, Contraction-free sequent calculi for intuitionistic logic
   511     (preprint, University of St Andrews, 1991)  ***)
   512 
   513 schematic_lemma conj_impE:
   514   assumes major: "p:(P&Q)-->S"
   515     and minor: "!!x. x:P-->(Q-->S) ==> q(x):R"
   516   shows "?p:R"
   517   apply (assumption | rule conjI impI major [THEN mp] minor)+
   518   done
   519 
   520 schematic_lemma disj_impE:
   521   assumes major: "p:(P|Q)-->S"
   522     and minor: "!!x y.[| x:P-->S; y:Q-->S |] ==> q(x,y):R"
   523   shows "?p:R"
   524   apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE
   525       resolve_tac [@{thm disjI1}, @{thm disjI2}, @{thm impI},
   526         @{thm major} RS @{thm mp}, @{thm minor}] 1) *})
   527   done
   528 
   529 (*Simplifies the implication.  Classical version is stronger.
   530   Still UNSAFE since Q must be provable -- backtracking needed.  *)
   531 schematic_lemma imp_impE:
   532   assumes major: "p:(P-->Q)-->S"
   533     and r1: "!!x y.[| x:P; y:Q-->S |] ==> q(x,y):Q"
   534     and r2: "!!x. x:S ==> r(x):R"
   535   shows "?p:R"
   536   apply (assumption | rule impI major [THEN mp] r1 r2)+
   537   done
   538 
   539 (*Simplifies the implication.  Classical version is stronger.
   540   Still UNSAFE since ~P must be provable -- backtracking needed.  *)
   541 schematic_lemma not_impE:
   542   assumes major: "p:~P --> S"
   543     and r1: "!!y. y:P ==> q(y):False"
   544     and r2: "!!y. y:S ==> r(y):R"
   545   shows "?p:R"
   546   apply (assumption | rule notI impI major [THEN mp] r1 r2)+
   547   done
   548 
   549 (*Simplifies the implication.   UNSAFE.  *)
   550 schematic_lemma iff_impE:
   551   assumes major: "p:(P<->Q)-->S"
   552     and r1: "!!x y.[| x:P; y:Q-->S |] ==> q(x,y):Q"
   553     and r2: "!!x y.[| x:Q; y:P-->S |] ==> r(x,y):P"
   554     and r3: "!!x. x:S ==> s(x):R"
   555   shows "?p:R"
   556   apply (assumption | rule iffI impI major [THEN mp] r1 r2 r3)+
   557   done
   558 
   559 (*What if (ALL x.~~P(x)) --> ~~(ALL x.P(x)) is an assumption? UNSAFE*)
   560 schematic_lemma all_impE:
   561   assumes major: "p:(ALL x. P(x))-->S"
   562     and r1: "!!x. q:P(x)"
   563     and r2: "!!y. y:S ==> r(y):R"
   564   shows "?p:R"
   565   apply (assumption | rule allI impI major [THEN mp] r1 r2)+
   566   done
   567 
   568 (*Unsafe: (EX x.P(x))-->S  is equivalent to  ALL x.P(x)-->S.  *)
   569 schematic_lemma ex_impE:
   570   assumes major: "p:(EX x. P(x))-->S"
   571     and r: "!!y. y:P(a)-->S ==> q(y):R"
   572   shows "?p:R"
   573   apply (assumption | rule exI impI major [THEN mp] r)+
   574   done
   575 
   576 
   577 schematic_lemma rev_cut_eq:
   578   assumes "p:a=b"
   579     and "!!x. x:a=b ==> f(x):R"
   580   shows "?p:R"
   581   apply (rule assms)+
   582   done
   583 
   584 lemma thin_refl: "!!X. [|p:x=x; PROP W|] ==> PROP W" .
   585 
   586 use "hypsubst.ML"
   587 
   588 ML {*
   589 
   590 (*** Applying HypsubstFun to generate hyp_subst_tac ***)
   591 
   592 structure Hypsubst_Data =
   593 struct
   594   (*Take apart an equality judgement; otherwise raise Match!*)
   595   fun dest_eq (Const (@{const_name Proof}, _) $
   596     (Const (@{const_name "op ="}, _)  $ t $ u) $ _) = (t, u);
   597 
   598   val imp_intr = @{thm impI}
   599 
   600   (*etac rev_cut_eq moves an equality to be the last premise. *)
   601   val rev_cut_eq = @{thm rev_cut_eq}
   602 
   603   val rev_mp = @{thm rev_mp}
   604   val subst = @{thm subst}
   605   val sym = @{thm sym}
   606   val thin_refl = @{thm thin_refl}
   607 end;
   608 
   609 structure Hypsubst = HypsubstFun(Hypsubst_Data);
   610 open Hypsubst;
   611 *}
   612 
   613 use "intprover.ML"
   614 
   615 
   616 (*** Rewrite rules ***)
   617 
   618 schematic_lemma conj_rews:
   619   "?p1 : P & True <-> P"
   620   "?p2 : True & P <-> P"
   621   "?p3 : P & False <-> False"
   622   "?p4 : False & P <-> False"
   623   "?p5 : P & P <-> P"
   624   "?p6 : P & ~P <-> False"
   625   "?p7 : ~P & P <-> False"
   626   "?p8 : (P & Q) & R <-> P & (Q & R)"
   627   apply (tactic {* fn st => IntPr.fast_tac 1 st *})+
   628   done
   629 
   630 schematic_lemma disj_rews:
   631   "?p1 : P | True <-> True"
   632   "?p2 : True | P <-> True"
   633   "?p3 : P | False <-> P"
   634   "?p4 : False | P <-> P"
   635   "?p5 : P | P <-> P"
   636   "?p6 : (P | Q) | R <-> P | (Q | R)"
   637   apply (tactic {* IntPr.fast_tac 1 *})+
   638   done
   639 
   640 schematic_lemma not_rews:
   641   "?p1 : ~ False <-> True"
   642   "?p2 : ~ True <-> False"
   643   apply (tactic {* IntPr.fast_tac 1 *})+
   644   done
   645 
   646 schematic_lemma imp_rews:
   647   "?p1 : (P --> False) <-> ~P"
   648   "?p2 : (P --> True) <-> True"
   649   "?p3 : (False --> P) <-> True"
   650   "?p4 : (True --> P) <-> P"
   651   "?p5 : (P --> P) <-> True"
   652   "?p6 : (P --> ~P) <-> ~P"
   653   apply (tactic {* IntPr.fast_tac 1 *})+
   654   done
   655 
   656 schematic_lemma iff_rews:
   657   "?p1 : (True <-> P) <-> P"
   658   "?p2 : (P <-> True) <-> P"
   659   "?p3 : (P <-> P) <-> True"
   660   "?p4 : (False <-> P) <-> ~P"
   661   "?p5 : (P <-> False) <-> ~P"
   662   apply (tactic {* IntPr.fast_tac 1 *})+
   663   done
   664 
   665 schematic_lemma quant_rews:
   666   "?p1 : (ALL x. P) <-> P"
   667   "?p2 : (EX x. P) <-> P"
   668   apply (tactic {* IntPr.fast_tac 1 *})+
   669   done
   670 
   671 (*These are NOT supplied by default!*)
   672 schematic_lemma distrib_rews1:
   673   "?p1 : ~(P|Q) <-> ~P & ~Q"
   674   "?p2 : P & (Q | R) <-> P&Q | P&R"
   675   "?p3 : (Q | R) & P <-> Q&P | R&P"
   676   "?p4 : (P | Q --> R) <-> (P --> R) & (Q --> R)"
   677   apply (tactic {* IntPr.fast_tac 1 *})+
   678   done
   679 
   680 schematic_lemma distrib_rews2:
   681   "?p1 : ~(EX x. NORM(P(x))) <-> (ALL x. ~NORM(P(x)))"
   682   "?p2 : ((EX x. NORM(P(x))) --> Q) <-> (ALL x. NORM(P(x)) --> Q)"
   683   "?p3 : (EX x. NORM(P(x))) & NORM(Q) <-> (EX x. NORM(P(x)) & NORM(Q))"
   684   "?p4 : NORM(Q) & (EX x. NORM(P(x))) <-> (EX x. NORM(Q) & NORM(P(x)))"
   685   apply (tactic {* IntPr.fast_tac 1 *})+
   686   done
   687 
   688 lemmas distrib_rews = distrib_rews1 distrib_rews2
   689 
   690 schematic_lemma P_Imp_P_iff_T: "p:P ==> ?p:(P <-> True)"
   691   apply (tactic {* IntPr.fast_tac 1 *})
   692   done
   693 
   694 schematic_lemma not_P_imp_P_iff_F: "p:~P ==> ?p:(P <-> False)"
   695   apply (tactic {* IntPr.fast_tac 1 *})
   696   done
   697 
   698 end