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