src/FOLP/hypsubst.ML
author haftmann
Mon, 05 Jul 2010 15:12:20 +0200
changeset 37715 44b27ea94a16
parent 36692 54b64d4ad524
child 37744 3daaf23b9ab4
permissions -rw-r--r--
tuned proof
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1459
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
     1
(*  Title:      FOLP/hypsubst
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
     2
    Author:     Martin D Coen, Cambridge University Computer Laboratory
1022
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
     3
    Copyright   1995  University of Cambridge
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
     4
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
     5
Original version of Provers/hypsubst.  Cannot use new version because it
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
     6
relies on the new simplifier!
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
     7
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
     8
Martin Coen's tactic for substitution in the hypotheses
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
     9
*)
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    10
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    11
signature HYPSUBST_DATA =
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    12
  sig
1459
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    13
  val dest_eq   : term -> term*term
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    14
  val imp_intr  : thm           (* (P ==> Q) ==> P-->Q *)
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    15
  val rev_mp    : thm           (* [| P;  P-->Q |] ==> Q *)
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    16
  val subst     : thm           (* [| a=b;  P(a) |] ==> P(b) *)
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    17
  val sym       : thm           (* a=b ==> b=a *)
1022
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    18
  end;
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    19
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    20
signature HYPSUBST =
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    21
  sig
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    22
  val bound_hyp_subst_tac : int -> tactic
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    23
  val hyp_subst_tac       : int -> tactic
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    24
    (*exported purely for debugging purposes*)
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    25
  val eq_var              : bool -> term -> int * thm
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    26
  val inspect_pair        : bool -> term * term -> thm
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    27
  end;
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    28
32449
696d64ed85da eliminated hard tabs;
wenzelm
parents: 26830
diff changeset
    29
functor HypsubstFun(Data: HYPSUBST_DATA): HYPSUBST =
1022
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    30
struct
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    31
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    32
local open Data in
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    33
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    34
exception EQ_VAR;
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    35
36692
54b64d4ad524 farewell to old-style mem infixes -- type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
haftmann
parents: 35762
diff changeset
    36
fun loose (i, t) = member (op =) (add_loose_bnos (t, i, [])) 0;
1022
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    37
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    38
(*It's not safe to substitute for a constant; consider 0=1.
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    39
  It's not safe to substitute for x=t[x] since x is not eliminated.
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    40
  It's not safe to substitute for a Var; what if it appears in other goals?
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    41
  It's not safe to substitute for a variable free in the premises,
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    42
    but how could we check for this?*)
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    43
fun inspect_pair bnd (t,u) =
26830
7b7139f961bd Replaced Pattern.eta_contract_atom by Envir.eta_contract.
berghofe
parents: 3537
diff changeset
    44
  case (Envir.eta_contract t, Envir.eta_contract u) of
32449
696d64ed85da eliminated hard tabs;
wenzelm
parents: 26830
diff changeset
    45
       (Bound i, _) => if loose(i,u) then raise Match
1459
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    46
                       else sym         (*eliminates t*)
32449
696d64ed85da eliminated hard tabs;
wenzelm
parents: 26830
diff changeset
    47
     | (_, Bound i) => if loose(i,t) then raise Match
1459
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    48
                       else asm_rl      (*eliminates u*)
32449
696d64ed85da eliminated hard tabs;
wenzelm
parents: 26830
diff changeset
    49
     | (Free _, _) => if bnd orelse Logic.occs(t,u) then raise Match
1459
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    50
                      else sym          (*eliminates t*)
32449
696d64ed85da eliminated hard tabs;
wenzelm
parents: 26830
diff changeset
    51
     | (_, Free _) => if bnd orelse Logic.occs(u,t) then raise Match
1459
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    52
                      else asm_rl       (*eliminates u*)
1022
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    53
     | _ => raise Match;
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    54
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    55
(*Locates a substitutable variable on the left (resp. right) of an equality
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    56
   assumption.  Returns the number of intervening assumptions, paried with
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    57
   the rule asm_rl (resp. sym). *)
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    58
fun eq_var bnd =
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    59
  let fun eq_var_aux k (Const("all",_) $ Abs(_,_,t)) = eq_var_aux k t
32449
696d64ed85da eliminated hard tabs;
wenzelm
parents: 26830
diff changeset
    60
        | eq_var_aux k (Const("==>",_) $ A $ B) =
1459
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    61
              ((k, inspect_pair bnd (dest_eq A))
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    62
                      (*Exception Match comes from inspect_pair or dest_eq*)
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    63
               handle Match => eq_var_aux (k+1) B)
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    64
        | eq_var_aux k _ = raise EQ_VAR
1022
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    65
  in  eq_var_aux 0  end;
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    66
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    67
(*Select a suitable equality assumption and substitute throughout the subgoal
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    68
  Replaces only Bound variables if bnd is true*)
3537
79ac9b475621 Removal of the tactical STATE
paulson
parents: 2728
diff changeset
    69
fun gen_hyp_subst_tac bnd = SUBGOAL(fn (Bi,i) =>
79ac9b475621 Removal of the tactical STATE
paulson
parents: 2728
diff changeset
    70
      let val n = length(Logic.strip_assums_hyp Bi) - 1
1459
d12da312eff4 expanded tabs
clasohm
parents: 1022
diff changeset
    71
          val (k,symopt) = eq_var bnd Bi
32449
696d64ed85da eliminated hard tabs;
wenzelm
parents: 26830
diff changeset
    72
      in
3537
79ac9b475621 Removal of the tactical STATE
paulson
parents: 2728
diff changeset
    73
         DETERM
79ac9b475621 Removal of the tactical STATE
paulson
parents: 2728
diff changeset
    74
           (EVERY [REPEAT_DETERM_N k (etac rev_mp i),
32449
696d64ed85da eliminated hard tabs;
wenzelm
parents: 26830
diff changeset
    75
                   etac revcut_rl i,
696d64ed85da eliminated hard tabs;
wenzelm
parents: 26830
diff changeset
    76
                   REPEAT_DETERM_N (n-k) (etac rev_mp i),
696d64ed85da eliminated hard tabs;
wenzelm
parents: 26830
diff changeset
    77
                   etac (symopt RS subst) i,
696d64ed85da eliminated hard tabs;
wenzelm
parents: 26830
diff changeset
    78
                   REPEAT_DETERM_N n (rtac imp_intr i)])
1022
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    79
      end
3537
79ac9b475621 Removal of the tactical STATE
paulson
parents: 2728
diff changeset
    80
      handle THM _ => no_tac | EQ_VAR => no_tac);
1022
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    81
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    82
(*Substitutes for Free or Bound variables*)
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    83
val hyp_subst_tac = gen_hyp_subst_tac false;
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    84
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    85
(*Substitutes for Bound variables only -- this is always safe*)
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    86
val bound_hyp_subst_tac = gen_hyp_subst_tac true;
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    87
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    88
end
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    89
end;
c4921e635bf7 Local version of (original) hypsubst: needs no simplifier
lcp
parents:
diff changeset
    90