Changed handling of flex-flex constraints: now stored in separate
authorberghofe
Mon Oct 21 17:04:47 2002 +0200 (2002-10-21)
changeset 13658c9ad3e64ddcf
parent 13657 c1637d60a846
child 13659 3cf622f6b0b2
Changed handling of flex-flex constraints: now stored in separate
tpairs field of theorem record.
src/Pure/display.ML
src/Pure/thm.ML
     1.1 --- a/src/Pure/display.ML	Mon Oct 21 17:00:45 2002 +0200
     1.2 +++ b/src/Pure/display.ML	Mon Oct 21 17:04:47 2002 +0200
     1.3 @@ -28,6 +28,7 @@
     1.4  signature DISPLAY =
     1.5  sig
     1.6    include BASIC_DISPLAY
     1.7 +  val pretty_flexpair: (term -> Pretty.T) -> term * term -> Pretty.T
     1.8    val pretty_thm_aux: (sort -> Pretty.T) * (term -> Pretty.T) -> bool -> thm -> Pretty.T
     1.9    val pretty_thm_no_quote: thm -> Pretty.T
    1.10    val pretty_thm: thm -> Pretty.T
    1.11 @@ -66,20 +67,25 @@
    1.12  fun pretty_tag (name, args) = Pretty.strs (name :: map quote args);
    1.13  val pretty_tags = Pretty.list "[" "]" o map pretty_tag;
    1.14  
    1.15 +fun pretty_flexpair pretty_term (t, u) = Pretty.block
    1.16 +  [pretty_term t, Pretty.str " =?=", Pretty.brk 1, pretty_term u];
    1.17 +
    1.18  fun pretty_thm_aux (pretty_sort, pretty_term) quote th =
    1.19    let
    1.20 -    val {hyps, prop, der = (ora, _), ...} = rep_thm th;
    1.21 +    val {hyps, tpairs, prop, der = (ora, _), ...} = rep_thm th;
    1.22      val xshyps = Thm.extra_shyps th;
    1.23      val (_, tags) = Thm.get_name_tags th;
    1.24  
    1.25 -    val prt_term = (if quote then Pretty.quote else I) o pretty_term;
    1.26 +    val q = if quote then Pretty.quote else I;
    1.27 +    val prt_term = q o pretty_term;
    1.28  
    1.29 -    val hlen = length xshyps + length hyps;
    1.30 +    val hlen = length xshyps + length hyps + length tpairs;
    1.31      val hsymbs =
    1.32        if hlen = 0 andalso not ora then []
    1.33        else if ! show_hyps then
    1.34          [Pretty.brk 2, Pretty.list "[" "]"
    1.35 -          (map prt_term hyps @ map pretty_sort xshyps @
    1.36 +          (map (q o pretty_flexpair pretty_term) tpairs @ map prt_term hyps @
    1.37 +           map pretty_sort xshyps @
    1.38              (if ora then [Pretty.str "!"] else []))]
    1.39        else [Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^
    1.40          (if ora then "!" else "") ^ "]")];
    1.41 @@ -307,15 +313,15 @@
    1.42        Pretty.blk (0, [Pretty.str (begin_goal ^ " " ^ string_of_int n ^ ". "), prt_term A]);
    1.43      fun pretty_subgoals As = map pretty_subgoal (1 upto length As ~~ As);
    1.44  
    1.45 -    val pretty_ffpairs = pretty_list "flex-flex pairs:" (prt_term o Logic.mk_flexpair);
    1.46 +    val pretty_ffpairs = pretty_list "flex-flex pairs:" (pretty_flexpair prt_term);
    1.47  
    1.48      val pretty_consts = pretty_list "constants:" prt_consts o consts_of;
    1.49      val pretty_vars = pretty_list "variables:" prt_vars o vars_of;
    1.50      val pretty_varsT = pretty_list "type variables:" prt_varsT o varsT_of;
    1.51  
    1.52  
    1.53 -    val {prop, ...} = rep_thm state;
    1.54 -    val (tpairs, As, B) = Logic.strip_horn prop;
    1.55 +    val {prop, tpairs, ...} = rep_thm state;
    1.56 +    val (As, B) = Logic.strip_horn prop;
    1.57      val ngoals = length As;
    1.58  
    1.59      fun pretty_gs (types, sorts) =
     2.1 --- a/src/Pure/thm.ML	Mon Oct 21 17:00:45 2002 +0200
     2.2 +++ b/src/Pure/thm.ML	Mon Oct 21 17:04:47 2002 +0200
     2.3 @@ -42,10 +42,10 @@
     2.4    type thm
     2.5    val rep_thm           : thm -> {sign: Sign.sg, der: bool * Proofterm.proof, maxidx: int,
     2.6                                    shyps: sort list, hyps: term list, 
     2.7 -                                  prop: term}
     2.8 +                                  tpairs: (term * term) list, prop: term}
     2.9    val crep_thm          : thm -> {sign: Sign.sg, der: bool * Proofterm.proof, maxidx: int,
    2.10                                    shyps: sort list, hyps: cterm list, 
    2.11 -                                  prop: cterm}
    2.12 +                                  tpairs: (cterm * cterm) list, prop: cterm}
    2.13    exception THM of string * int * thm list
    2.14    type 'a attribute 	(* = 'a * thm -> 'a * thm *)
    2.15    val eq_thm		: thm * thm -> bool
    2.16 @@ -130,6 +130,7 @@
    2.17    val cterm_first_order_match : cterm * cterm ->
    2.18      (indexname * ctyp) list * (cterm * cterm) list
    2.19    val cterm_incr_indexes : int -> cterm -> cterm
    2.20 +  val terms_of_tpairs   : (term * term) list -> term list
    2.21  end;
    2.22  
    2.23  structure Thm: THM =
    2.24 @@ -288,17 +289,24 @@
    2.25    maxidx: int,                 (*maximum index of any Var or TVar*)
    2.26    shyps: sort list,            (*sort hypotheses*)
    2.27    hyps: term list,             (*hypotheses*)
    2.28 +  tpairs: (term * term) list,  (*flex-flex pairs*)
    2.29    prop: term};                 (*conclusion*)
    2.30  
    2.31 -fun rep_thm (Thm {sign_ref, der, maxidx, shyps, hyps, prop}) =
    2.32 +fun terms_of_tpairs tpairs = flat (map (op @ o pairself single) tpairs);
    2.33 +
    2.34 +fun attach_tpairs tpairs prop =
    2.35 +  Logic.list_implies (map Logic.mk_equals tpairs, prop);
    2.36 +
    2.37 +fun rep_thm (Thm {sign_ref, der, maxidx, shyps, hyps, tpairs, prop}) =
    2.38    {sign = Sign.deref sign_ref, der = der, maxidx = maxidx,
    2.39 -    shyps = shyps, hyps = hyps, prop = prop};
    2.40 +    shyps = shyps, hyps = hyps, tpairs = tpairs, prop = prop};
    2.41  
    2.42  (*Version of rep_thm returning cterms instead of terms*)
    2.43 -fun crep_thm (Thm {sign_ref, der, maxidx, shyps, hyps, prop}) =
    2.44 +fun crep_thm (Thm {sign_ref, der, maxidx, shyps, hyps, tpairs, prop}) =
    2.45    let fun ctermf max t = Cterm{sign_ref=sign_ref, t=t, T=propT, maxidx=max};
    2.46    in {sign = Sign.deref sign_ref, der = der, maxidx = maxidx, shyps = shyps,
    2.47        hyps = map (ctermf ~1) hyps,
    2.48 +      tpairs = map (pairself (ctermf maxidx)) tpairs,
    2.49        prop = ctermf maxidx prop}
    2.50    end;
    2.51  
    2.52 @@ -314,14 +322,15 @@
    2.53  
    2.54  fun eq_thm (th1, th2) =
    2.55    let
    2.56 -    val {sign = sg1, shyps = shyps1, hyps = hyps1, prop = prop1, ...} =
    2.57 +    val {sign = sg1, shyps = shyps1, hyps = hyps1, tpairs = tpairs1, prop = prop1, ...} =
    2.58        rep_thm th1;
    2.59 -    val {sign = sg2, shyps = shyps2, hyps = hyps2, prop = prop2, ...} =
    2.60 +    val {sign = sg2, shyps = shyps2, hyps = hyps2, tpairs = tpairs2, prop = prop2, ...} =
    2.61        rep_thm th2;
    2.62    in
    2.63      Sign.joinable (sg1, sg2) andalso
    2.64      eq_set_sort (shyps1, shyps2) andalso
    2.65      aconvs (hyps1, hyps2) andalso
    2.66 +    aconvs (terms_of_tpairs tpairs1, terms_of_tpairs tpairs2) andalso
    2.67      prop1 aconv prop2
    2.68    end;
    2.69  
    2.70 @@ -337,28 +346,28 @@
    2.71  (*transfer thm to super theory (non-destructive)*)
    2.72  fun transfer_sg sign' thm =
    2.73    let
    2.74 -    val Thm {sign_ref, der, maxidx, shyps, hyps, prop} = thm;
    2.75 +    val Thm {sign_ref, der, maxidx, shyps, hyps, tpairs, prop} = thm;
    2.76      val sign = Sign.deref sign_ref;
    2.77    in
    2.78      if Sign.eq_sg (sign, sign') then thm
    2.79      else if Sign.subsig (sign, sign') then
    2.80        Thm {sign_ref = Sign.self_ref sign', der = der, maxidx = maxidx,
    2.81 -        shyps = shyps, hyps = hyps, prop = prop}
    2.82 +        shyps = shyps, hyps = hyps, tpairs = tpairs, prop = prop}
    2.83      else raise THM ("transfer: not a super theory", 0, [thm])
    2.84    end;
    2.85  
    2.86  val transfer = transfer_sg o Theory.sign_of;
    2.87  
    2.88  (*maps object-rule to tpairs*)
    2.89 -fun tpairs_of (Thm {prop, ...}) = #1 (Logic.strip_flexpairs prop);
    2.90 +fun tpairs_of (Thm {tpairs, ...}) = tpairs;
    2.91  
    2.92  (*maps object-rule to premises*)
    2.93  fun prems_of (Thm {prop, ...}) =
    2.94 -  Logic.strip_imp_prems (Logic.skip_flexpairs prop);
    2.95 +  Logic.strip_imp_prems prop;
    2.96  
    2.97  (*counts premises in a rule*)
    2.98  fun nprems_of (Thm {prop, ...}) =
    2.99 -  Logic.count_prems (Logic.skip_flexpairs prop, 0);
   2.100 +  Logic.count_prems (prop, 0);
   2.101  
   2.102  fun major_prem_of thm =
   2.103    (case prems_of thm of
   2.104 @@ -408,8 +417,8 @@
   2.105  fun add_insts_sorts ((iTs, is), Ss) =
   2.106    add_typs_sorts (map snd iTs, add_terms_sorts (map snd is, Ss));
   2.107  
   2.108 -fun add_thm_sorts (Thm {hyps, prop, ...}, Ss) =
   2.109 -  add_terms_sorts (hyps, add_term_sorts (prop, Ss));
   2.110 +fun add_thm_sorts (Thm {hyps, tpairs, prop, ...}, Ss) =
   2.111 +  add_terms_sorts (hyps @ terms_of_tpairs tpairs, add_term_sorts (prop, Ss));
   2.112  
   2.113  fun add_thms_shyps ([], Ss) = Ss
   2.114    | add_thms_shyps (Thm {shyps, ...} :: ths, Ss) =
   2.115 @@ -426,7 +435,7 @@
   2.116  fun all_sorts_nonempty sign_ref = is_some (Sign.univ_witness (Sign.deref sign_ref));
   2.117  
   2.118  (*preserve sort contexts of rule premises and substituted types*)
   2.119 -fun fix_shyps thms Ts (thm as Thm {sign_ref, der, maxidx, hyps, prop, ...}) =
   2.120 +fun fix_shyps thms Ts (thm as Thm {sign_ref, der, maxidx, hyps, tpairs, prop, ...}) =
   2.121    Thm
   2.122     {sign_ref = sign_ref,
   2.123      der = der,             (*no new derivation, as other rules call this*)
   2.124 @@ -434,14 +443,14 @@
   2.125      shyps =
   2.126        if all_sorts_nonempty sign_ref then []
   2.127        else add_thm_sorts (thm, add_typs_sorts (Ts, add_thms_shyps (thms, []))),
   2.128 -    hyps = hyps, prop = prop}
   2.129 +    hyps = hyps, tpairs = tpairs, prop = prop}
   2.130  
   2.131  
   2.132  (* strip_shyps *)
   2.133  
   2.134  (*remove extra sorts that are non-empty by virtue of type signature information*)
   2.135  fun strip_shyps (thm as Thm {shyps = [], ...}) = thm
   2.136 -  | strip_shyps (thm as Thm {sign_ref, der, maxidx, shyps, hyps, prop}) =
   2.137 +  | strip_shyps (thm as Thm {sign_ref, der, maxidx, shyps, hyps, tpairs, prop}) =
   2.138        let
   2.139          val sign = Sign.deref sign_ref;
   2.140  
   2.141 @@ -451,7 +460,7 @@
   2.142        in
   2.143          Thm {sign_ref = sign_ref, der = der, maxidx = maxidx,
   2.144               shyps = Term.rems_sort (shyps, map #2 witnessed_shyps),
   2.145 -             hyps = hyps, prop = prop}
   2.146 +             hyps = hyps, tpairs = tpairs, prop = prop}
   2.147        end;
   2.148  
   2.149  
   2.150 @@ -475,6 +484,7 @@
   2.151                      maxidx = maxidx_of_term t,
   2.152                      shyps = [], 
   2.153                      hyps = [], 
   2.154 +                    tpairs = [],
   2.155                      prop = t}))
   2.156              | None => get_ax thys)
   2.157            end;
   2.158 @@ -499,10 +509,12 @@
   2.159  fun get_name_tags (Thm {hyps, prop, der = (_, prf), ...}) =
   2.160    Pt.get_name_tags hyps prop prf;
   2.161  
   2.162 -fun put_name_tags x (Thm {sign_ref, der = (ora, prf), maxidx, shyps, hyps, prop}) =
   2.163 -  Thm {sign_ref = sign_ref,
   2.164 -    der = (ora, Pt.thm_proof (Sign.deref sign_ref) x hyps prop prf),
   2.165 -    maxidx = maxidx, shyps = shyps, hyps = hyps, prop = prop};
   2.166 +fun put_name_tags x (Thm {sign_ref, der = (ora, prf), maxidx,
   2.167 +      shyps, hyps, tpairs = [], prop}) = Thm {sign_ref = sign_ref,
   2.168 +        der = (ora, Pt.thm_proof (Sign.deref sign_ref) x hyps prop prf),
   2.169 +        maxidx = maxidx, shyps = shyps, hyps = hyps, tpairs = [], prop = prop}
   2.170 +  | put_name_tags _ thm =
   2.171 +      raise THM ("put_name_tags: unsolved flex-flex constraints", 0, [thm]);
   2.172  
   2.173  val name_of_thm = #1 o get_name_tags;
   2.174  val tags_of_thm = #2 o get_name_tags;
   2.175 @@ -512,12 +524,13 @@
   2.176  
   2.177  (*Compression of theorems -- a separate rule, not integrated with the others,
   2.178    as it could be slow.*)
   2.179 -fun compress (Thm {sign_ref, der, maxidx, shyps, hyps, prop}) = 
   2.180 +fun compress (Thm {sign_ref, der, maxidx, shyps, hyps, tpairs, prop}) = 
   2.181      Thm {sign_ref = sign_ref, 
   2.182           der = der,     (*No derivation recorded!*)
   2.183           maxidx = maxidx,
   2.184           shyps = shyps, 
   2.185           hyps = map Term.compress_term hyps, 
   2.186 +         tpairs = map (pairself Term.compress_term) tpairs,
   2.187           prop = Term.compress_term prop};
   2.188  
   2.189  
   2.190 @@ -527,14 +540,18 @@
   2.191  (*Check that term does not contain same var with different typing/sorting.
   2.192    If this check must be made, recalculate maxidx in hope of preventing its
   2.193    recurrence.*)
   2.194 -fun nodup_vars (thm as Thm{sign_ref, der, maxidx, shyps, hyps, prop}) s =
   2.195 -  Thm {sign_ref = sign_ref, 
   2.196 -         der = der,     
   2.197 -         maxidx = maxidx_of_term prop,
   2.198 -         shyps = shyps, 
   2.199 -         hyps = hyps, 
   2.200 -         prop = Sign.nodup_vars prop}
   2.201 -  handle TYPE(msg,Ts,ts) => raise TYPE(s^": "^msg,Ts,ts);
   2.202 +fun nodup_vars (thm as Thm{sign_ref, der, maxidx, shyps, hyps, tpairs, prop}) s =
   2.203 +  let
   2.204 +    val prop' = attach_tpairs tpairs prop;
   2.205 +    val _ = Sign.nodup_vars prop'
   2.206 +  in Thm {sign_ref = sign_ref,
   2.207 +          der = der,
   2.208 +          maxidx = maxidx_of_term prop',
   2.209 +          shyps = shyps,
   2.210 +          hyps = hyps,
   2.211 +          tpairs = tpairs,
   2.212 +          prop = prop}
   2.213 +  end handle TYPE(msg,Ts,ts) => raise TYPE(s^": "^msg,Ts,ts);
   2.214  
   2.215  
   2.216  (** 'primitive' rules **)
   2.217 @@ -555,6 +572,7 @@
   2.218                 maxidx = ~1, 
   2.219                 shyps  = add_term_sorts(prop,[]), 
   2.220                 hyps   = [prop], 
   2.221 +               tpairs = [],
   2.222                 prop   = prop}
   2.223    end;
   2.224  
   2.225 @@ -565,7 +583,7 @@
   2.226    -------
   2.227    A ==> B
   2.228  *)
   2.229 -fun implies_intr cA (thB as Thm{sign_ref,der,maxidx,hyps,shyps,prop}) : thm =
   2.230 +fun implies_intr cA (thB as Thm{sign_ref,der,maxidx,hyps,shyps,tpairs,prop}) : thm =
   2.231    let val Cterm {sign_ref=sign_refA, t=A, T, maxidx=maxidxA} = cA
   2.232    in  if T<>propT then
   2.233          raise THM("implies_intr: assumptions must have type prop", 0, [thB])
   2.234 @@ -575,6 +593,7 @@
   2.235               maxidx = Int.max(maxidxA, maxidx),
   2.236               shyps = add_term_sorts (A, shyps),
   2.237               hyps = disch(hyps,A),
   2.238 +             tpairs = tpairs,
   2.239               prop = implies$A$prop}
   2.240        handle TERM _ =>
   2.241          raise THM("implies_intr: incompatible signatures", 0, [thB])
   2.242 @@ -587,8 +606,8 @@
   2.243          B
   2.244  *)
   2.245  fun implies_elim thAB thA : thm =
   2.246 -    let val Thm{maxidx=maxA, der=derA, hyps=hypsA, shyps=shypsA, prop=propA, ...} = thA
   2.247 -        and Thm{der, maxidx, hyps, shyps, prop, ...} = thAB;
   2.248 +    let val Thm{maxidx=maxA, der=derA, hyps=hypsA, shyps=shypsA, tpairs=tpairsA, prop=propA, ...} = thA
   2.249 +        and Thm{der, maxidx, hyps, shyps, tpairs, prop, ...} = thAB;
   2.250          fun err(a) = raise THM("implies_elim: "^a, 0, [thAB,thA])
   2.251      in  case prop of
   2.252              imp$A$B =>
   2.253 @@ -599,6 +618,7 @@
   2.254                        maxidx = Int.max(maxA,maxidx),
   2.255                        shyps = union_sort (shypsA, shyps),
   2.256                        hyps = union_term(hypsA,hyps),  (*dups suppressed*)
   2.257 +                      tpairs = tpairsA @ tpairs,
   2.258                        prop = B}
   2.259                  else err("major premise")
   2.260            | _ => err("major premise")
   2.261 @@ -609,21 +629,23 @@
   2.262    -----
   2.263    !!x.A
   2.264  *)
   2.265 -fun forall_intr cx (th as Thm{sign_ref,der,maxidx,hyps,prop,...}) =
   2.266 +fun forall_intr cx (th as Thm{sign_ref,der,maxidx,hyps,tpairs,prop,...}) =
   2.267    let val x = term_of cx;
   2.268 -      fun result(a,T) = fix_shyps [th] []
   2.269 +      fun result a T = fix_shyps [th] []
   2.270          (Thm{sign_ref = sign_ref, 
   2.271               der = Pt.infer_derivs' (Pt.forall_intr_proof x a) der,
   2.272               maxidx = maxidx,
   2.273               shyps = [],
   2.274               hyps = hyps,
   2.275 +             tpairs = tpairs,
   2.276               prop = all(T) $ Abs(a, T, abstract_over (x,prop))})
   2.277 +      fun check_occs x ts =
   2.278 +        if exists (apl(x, Logic.occs)) ts
   2.279 +        then raise THM("forall_intr: variable free in assumptions", 0, [th])
   2.280 +        else ()
   2.281    in  case x of
   2.282 -        Free(a,T) =>
   2.283 -          if exists (apl(x, Logic.occs)) hyps
   2.284 -          then  raise THM("forall_intr: variable free in assumptions", 0, [th])
   2.285 -          else  result(a,T)
   2.286 -      | Var((a,_),T) => result(a,T)
   2.287 +        Free(a,T) => (check_occs x (hyps @ terms_of_tpairs tpairs); result a T)
   2.288 +      | Var((a,_),T) => (check_occs x (terms_of_tpairs tpairs); result a T)
   2.289        | _ => raise THM("forall_intr: not a variable", 0, [th])
   2.290    end;
   2.291  
   2.292 @@ -632,7 +654,7 @@
   2.293    ------
   2.294    A[t/x]
   2.295  *)
   2.296 -fun forall_elim ct (th as Thm{sign_ref,der,maxidx,hyps,prop,...}) : thm =
   2.297 +fun forall_elim ct (th as Thm{sign_ref,der,maxidx,hyps,tpairs,prop,...}) : thm =
   2.298    let val Cterm {sign_ref=sign_reft, t, T, maxidx=maxt} = ct
   2.299    in  case prop of
   2.300          Const("all",Type("fun",[Type("fun",[qary,_]),_])) $ A =>
   2.301 @@ -644,6 +666,7 @@
   2.302                           maxidx = Int.max(maxidx, maxt),
   2.303                           shyps = [],
   2.304                           hyps = hyps,  
   2.305 +                         tpairs = tpairs,
   2.306                           prop = betapply(A,t)})
   2.307                 in if maxt >= 0 andalso maxidx >= 0
   2.308                    then nodup_vars thm "forall_elim" 
   2.309 @@ -665,6 +688,7 @@
   2.310           shyps = add_term_sorts (t, []),
   2.311           hyps = [], 
   2.312           maxidx = maxidx,
   2.313 +         tpairs = [],
   2.314           prop = Logic.mk_equals(t,t)}
   2.315    end;
   2.316  
   2.317 @@ -673,7 +697,7 @@
   2.318    ----
   2.319    u==t
   2.320  *)
   2.321 -fun symmetric (th as Thm{sign_ref,der,maxidx,shyps,hyps,prop}) =
   2.322 +fun symmetric (th as Thm{sign_ref,der,maxidx,shyps,hyps,tpairs,prop}) =
   2.323    case prop of
   2.324        (eq as Const("==", Type (_, [T, _]))) $ t $ u =>
   2.325          (*no fix_shyps*)
   2.326 @@ -682,6 +706,7 @@
   2.327                maxidx = maxidx,
   2.328                shyps = shyps,
   2.329                hyps = hyps,
   2.330 +              tpairs = tpairs,
   2.331                prop = eq$u$t}
   2.332      | _ => raise THM("symmetric", 0, [th]);
   2.333  
   2.334 @@ -691,8 +716,8 @@
   2.335        t1==t2
   2.336  *)
   2.337  fun transitive th1 th2 =
   2.338 -  let val Thm{der=der1, maxidx=max1, hyps=hyps1, shyps=shyps1, prop=prop1,...} = th1
   2.339 -      and Thm{der=der2, maxidx=max2, hyps=hyps2, shyps=shyps2, prop=prop2,...} = th2;
   2.340 +  let val Thm{der=der1, maxidx=max1, hyps=hyps1, shyps=shyps1, tpairs=tpairs1, prop=prop1,...} = th1
   2.341 +      and Thm{der=der2, maxidx=max2, hyps=hyps2, shyps=shyps2, tpairs=tpairs2, prop=prop2,...} = th2;
   2.342        fun err(msg) = raise THM("transitive: "^msg, 0, [th1,th2])
   2.343    in case (prop1,prop2) of
   2.344         ((eq as Const("==", Type (_, [T, _]))) $ t1 $ u, Const("==",_) $ u' $ t2) =>
   2.345 @@ -703,6 +728,7 @@
   2.346                       maxidx = Int.max(max1,max2), 
   2.347                       shyps = union_sort (shyps1, shyps2),
   2.348                       hyps = union_term(hyps1,hyps2),
   2.349 +                     tpairs = tpairs1 @ tpairs2,
   2.350                       prop = eq$t1$t2}
   2.351                   in if max1 >= 0 andalso max2 >= 0
   2.352                      then nodup_vars thm "transitive" 
   2.353 @@ -722,6 +748,7 @@
   2.354       maxidx = maxidx,
   2.355       shyps = add_term_sorts (t, []),
   2.356       hyps = [],
   2.357 +     tpairs = [],
   2.358       prop = Logic.mk_equals (t, if full then Envir.beta_norm t
   2.359         else case t of
   2.360            Abs(_, _, bodt) $ u => subst_bound (u, bodt)
   2.361 @@ -736,6 +763,7 @@
   2.362       maxidx = maxidx,
   2.363       shyps = add_term_sorts (t, []),
   2.364       hyps = [],
   2.365 +     tpairs = [],
   2.366       prop = Logic.mk_equals (t, Pattern.eta_contract t)}
   2.367    end;
   2.368  
   2.369 @@ -745,7 +773,7 @@
   2.370    ------------
   2.371    %x.t == %x.u
   2.372  *)
   2.373 -fun abstract_rule a cx (th as Thm{sign_ref,der,maxidx,hyps,shyps,prop}) =
   2.374 +fun abstract_rule a cx (th as Thm{sign_ref,der,maxidx,hyps,shyps,tpairs,prop}) =
   2.375    let val x = term_of cx;
   2.376        val (t,u) = Logic.dest_equals prop
   2.377              handle TERM _ =>
   2.378 @@ -756,14 +784,16 @@
   2.379                 maxidx = maxidx, 
   2.380                 shyps = add_typ_sorts (T, shyps), 
   2.381                 hyps = hyps,
   2.382 +               tpairs = tpairs,
   2.383                 prop = Logic.mk_equals(Abs(a, T, abstract_over (x,t)),
   2.384                                        Abs(a, T, abstract_over (x,u)))}
   2.385 +      fun check_occs x ts =
   2.386 +         if exists (apl(x, Logic.occs)) ts
   2.387 +         then raise THM("abstract_rule: variable free in assumptions", 0, [th])
   2.388 +         else ()
   2.389    in  case x of
   2.390 -        Free(_,T) =>
   2.391 -         if exists (apl(x, Logic.occs)) hyps
   2.392 -         then raise THM("abstract_rule: variable free in assumptions", 0, [th])
   2.393 -         else result T
   2.394 -      | Var(_,T) => result T
   2.395 +        Free(_,T) => (check_occs x (hyps @ terms_of_tpairs tpairs); result T)
   2.396 +      | Var(_,T) => (check_occs x (terms_of_tpairs tpairs); result T)
   2.397        | _ => raise THM("abstract_rule: not a variable", 0, [th])
   2.398    end;
   2.399  
   2.400 @@ -774,9 +804,9 @@
   2.401  *)
   2.402  fun combination th1 th2 =
   2.403    let val Thm{der=der1, maxidx=max1, shyps=shyps1, hyps=hyps1, 
   2.404 -              prop=prop1,...} = th1
   2.405 +              tpairs=tpairs1, prop=prop1,...} = th1
   2.406        and Thm{der=der2, maxidx=max2, shyps=shyps2, hyps=hyps2, 
   2.407 -              prop=prop2,...} = th2
   2.408 +              tpairs=tpairs2, prop=prop2,...} = th2
   2.409        fun chktypes fT tT =
   2.410              (case fT of
   2.411                  Type("fun",[T1,T2]) => 
   2.412 @@ -796,6 +826,7 @@
   2.413                              maxidx = Int.max(max1,max2), 
   2.414                              shyps = union_sort(shyps1,shyps2),
   2.415                              hyps = union_term(hyps1,hyps2),
   2.416 +                            tpairs = tpairs1 @ tpairs2,
   2.417                              prop = Logic.mk_equals(f$t, g$u)}
   2.418            in if max1 >= 0 andalso max2 >= 0
   2.419               then nodup_vars thm "combination" 
   2.420 @@ -812,9 +843,9 @@
   2.421  *)
   2.422  fun equal_intr th1 th2 =
   2.423    let val Thm{der=der1, maxidx=max1, shyps=shyps1, hyps=hyps1, 
   2.424 -              prop=prop1,...} = th1
   2.425 +              tpairs=tpairs1, prop=prop1,...} = th1
   2.426        and Thm{der=der2, maxidx=max2, shyps=shyps2, hyps=hyps2, 
   2.427 -              prop=prop2,...} = th2;
   2.428 +              tpairs=tpairs2, prop=prop2,...} = th2;
   2.429        fun err(msg) = raise THM("equal_intr: "^msg, 0, [th1,th2])
   2.430    in case (prop1,prop2) of
   2.431         (Const("==>",_) $ A $ B, Const("==>",_) $ B' $ A')  =>
   2.432 @@ -826,6 +857,7 @@
   2.433                    maxidx = Int.max(max1,max2),
   2.434                    shyps = union_sort(shyps1,shyps2),
   2.435                    hyps = union_term(hyps1,hyps2),
   2.436 +                  tpairs = tpairs1 @ tpairs2,
   2.437                    prop = Logic.mk_equals(A,B)}
   2.438            else err"not equal"
   2.439       | _ =>  err"premises"
   2.440 @@ -838,8 +870,8 @@
   2.441        B
   2.442  *)
   2.443  fun equal_elim th1 th2 =
   2.444 -  let val Thm{der=der1, maxidx=max1, hyps=hyps1, prop=prop1,...} = th1
   2.445 -      and Thm{der=der2, maxidx=max2, hyps=hyps2, prop=prop2,...} = th2;
   2.446 +  let val Thm{der=der1, maxidx=max1, hyps=hyps1, tpairs=tpairs1, prop=prop1,...} = th1
   2.447 +      and Thm{der=der2, maxidx=max2, hyps=hyps2, tpairs=tpairs2, prop=prop2,...} = th2;
   2.448        fun err(msg) = raise THM("equal_elim: "^msg, 0, [th1,th2])
   2.449    in  case prop1  of
   2.450         Const("==",_) $ A $ B =>
   2.451 @@ -850,6 +882,7 @@
   2.452                     maxidx = Int.max(max1,max2),
   2.453                     shyps = [],
   2.454                     hyps = union_term(hyps1,hyps2),
   2.455 +                   tpairs = tpairs1 @ tpairs2,
   2.456                     prop = B})
   2.457       | _ =>  err"major premise"
   2.458    end;
   2.459 @@ -860,13 +893,14 @@
   2.460  
   2.461  (*Discharge all hypotheses.  Need not verify cterms or call fix_shyps.
   2.462    Repeated hypotheses are discharged only once;  fold cannot do this*)
   2.463 -fun implies_intr_hyps (Thm{sign_ref, der, maxidx, shyps, hyps=A::As, prop}) =
   2.464 +fun implies_intr_hyps (Thm{sign_ref, der, maxidx, shyps, hyps=A::As, tpairs, prop}) =
   2.465        implies_intr_hyps (*no fix_shyps*)
   2.466              (Thm{sign_ref = sign_ref, 
   2.467                   der = Pt.infer_derivs' (Pt.implies_intr_proof A) der,
   2.468                   maxidx = maxidx, 
   2.469                   shyps = shyps,
   2.470                   hyps = disch(As,A),  
   2.471 +                 tpairs = tpairs,
   2.472                   prop = implies$A$prop})
   2.473    | implies_intr_hyps th = th;
   2.474  
   2.475 @@ -874,24 +908,24 @@
   2.476    Instantiates the theorem and deletes trivial tpairs.
   2.477    Resulting sequence may contain multiple elements if the tpairs are
   2.478      not all flex-flex. *)
   2.479 -fun flexflex_rule (th as Thm{sign_ref, der, maxidx, hyps, prop,...}) =
   2.480 +fun flexflex_rule (th as Thm{sign_ref, der, maxidx, hyps, tpairs, prop, ...}) =
   2.481    let fun newthm env =
   2.482            if Envir.is_empty env then th
   2.483            else
   2.484 -          let val (tpairs,horn) =
   2.485 -                        Logic.strip_flexpairs (Envir.norm_term env prop)
   2.486 +          let val ntpairs = map (pairself (Envir.norm_term env)) tpairs;
   2.487 +              val newprop = Envir.norm_term env prop;
   2.488                  (*Remove trivial tpairs, of the form t=t*)
   2.489 -              val distpairs = filter (not o op aconv) tpairs
   2.490 -              val newprop = Logic.list_flexpairs(distpairs, horn)
   2.491 +              val distpairs = filter (not o op aconv) ntpairs
   2.492            in  fix_shyps [th] (env_codT env)
   2.493                  (Thm{sign_ref = sign_ref, 
   2.494                       der = Pt.infer_derivs' (Pt.norm_proof' env) der,
   2.495 -                     maxidx = maxidx_of_term newprop, 
   2.496 +                     maxidx = maxidx_of_terms (newprop ::
   2.497 +                       terms_of_tpairs distpairs),
   2.498                       shyps = [], 
   2.499                       hyps = hyps,
   2.500 +                     tpairs = distpairs,
   2.501                       prop = newprop})
   2.502            end;
   2.503 -      val (tpairs,_) = Logic.strip_flexpairs prop
   2.504    in Seq.map newthm
   2.505              (Unify.smash_unifiers(Sign.deref sign_ref, Envir.empty maxidx, tpairs))
   2.506    end;
   2.507 @@ -935,18 +969,21 @@
   2.508    Instantiates distinct Vars by terms of same type.
   2.509    No longer normalizes the new theorem! *)
   2.510  fun instantiate ([], []) th = th
   2.511 -  | instantiate (vcTs,ctpairs) (th as Thm{sign_ref,der,maxidx,hyps,shyps,prop}) =
   2.512 +  | instantiate (vcTs,ctpairs) (th as Thm{sign_ref,der,maxidx,hyps,shyps,tpairs=dpairs,prop}) =
   2.513    let val (newsign_ref,tpairs) = foldr add_ctpair (ctpairs, (sign_ref,[]));
   2.514        val (newsign_ref,vTs) = foldr add_ctyp (vcTs, (newsign_ref,[]));
   2.515 -      val newprop = subst_atomic tpairs
   2.516 -	             (Type.inst_term_tvars
   2.517 -		      (Sign.tsig_of (Sign.deref newsign_ref),vTs) prop)
   2.518 +      val tsig = Sign.tsig_of (Sign.deref newsign_ref);
   2.519 +      fun subst t = subst_atomic tpairs (Type.inst_term_tvars (tsig, vTs) t);
   2.520 +      val newprop = subst prop;
   2.521 +      val newdpairs = map (pairself subst) dpairs;
   2.522        val newth =
   2.523              (Thm{sign_ref = newsign_ref, 
   2.524                   der = Pt.infer_derivs' (Pt.instantiate vTs tpairs) der,
   2.525 -                 maxidx = maxidx_of_term newprop, 
   2.526 +                 maxidx = maxidx_of_terms (newprop ::
   2.527 +                   terms_of_tpairs newdpairs), 
   2.528                   shyps = add_insts_sorts ((vTs, tpairs), shyps),
   2.529                   hyps = hyps,
   2.530 +                 tpairs = newdpairs,
   2.531                   prop = newprop})
   2.532    in  if not(instl_ok(map #1 tpairs))
   2.533        then raise THM("instantiate: variables not distinct", 0, [th])
   2.534 @@ -972,6 +1009,7 @@
   2.535               maxidx = maxidx, 
   2.536               shyps = [], 
   2.537               hyps = [],
   2.538 +             tpairs = [],
   2.539               prop = implies$A$A})
   2.540    end;
   2.541  
   2.542 @@ -988,22 +1026,26 @@
   2.543              maxidx = maxidx, 
   2.544              shyps = [], 
   2.545              hyps = [], 
   2.546 +            tpairs = [],
   2.547              prop = t})
   2.548    end;
   2.549  
   2.550  
   2.551  (* Replace all TFrees not fixed or in the hyps by new TVars *)
   2.552 -fun varifyT' fixed (Thm{sign_ref,der,maxidx,shyps,hyps,prop}) =
   2.553 +fun varifyT' fixed (Thm{sign_ref,der,maxidx,shyps,hyps,tpairs,prop}) =
   2.554    let
   2.555      val tfrees = foldr add_term_tfree_names (hyps, fixed);
   2.556 -    val (prop', al) = Type.varify (prop, tfrees);
   2.557 +    val prop1 = attach_tpairs tpairs prop;
   2.558 +    val (prop2, al) = Type.varify (prop1, tfrees);
   2.559 +    val (ts, prop3) = Logic.strip_prems (length tpairs, [], prop2)
   2.560    in let val thm = (*no fix_shyps*)
   2.561      Thm{sign_ref = sign_ref, 
   2.562          der = Pt.infer_derivs' (Pt.varify_proof prop tfrees) der,
   2.563          maxidx = Int.max(0,maxidx), 
   2.564          shyps = shyps, 
   2.565          hyps = hyps,
   2.566 -        prop = prop'}
   2.567 +        tpairs = rev (map Logic.dest_equals ts),
   2.568 +        prop = prop3}
   2.569       in (nodup_vars thm "varifyT", al) end
   2.570  (* this nodup_vars check can be removed if thms are guaranteed not to contain
   2.571  duplicate TVars with different sorts *)
   2.572 @@ -1012,51 +1054,52 @@
   2.573  val varifyT = #1 o varifyT' [];
   2.574  
   2.575  (* Replace all TVars by new TFrees *)
   2.576 -fun freezeT(Thm{sign_ref,der,maxidx,shyps,hyps,prop}) =
   2.577 -  let val (prop',_) = Type.freeze_thaw prop
   2.578 +fun freezeT(Thm{sign_ref,der,maxidx,shyps,hyps,tpairs,prop}) =
   2.579 +  let
   2.580 +    val prop1 = attach_tpairs tpairs prop;
   2.581 +    val (prop2, _) = Type.freeze_thaw prop1;
   2.582 +    val (ts, prop3) = Logic.strip_prems (length tpairs, [], prop2)
   2.583    in (*no fix_shyps*)
   2.584      Thm{sign_ref = sign_ref, 
   2.585 -        der = Pt.infer_derivs' (Pt.freezeT prop) der,
   2.586 -        maxidx = maxidx_of_term prop',
   2.587 +        der = Pt.infer_derivs' (Pt.freezeT prop1) der,
   2.588 +        maxidx = maxidx_of_term prop2,
   2.589          shyps = shyps,
   2.590          hyps = hyps,
   2.591 -        prop = prop'}
   2.592 +        tpairs = rev (map Logic.dest_equals ts),
   2.593 +        prop = prop3}
   2.594    end;
   2.595  
   2.596  
   2.597  (*** Inference rules for tactics ***)
   2.598  
   2.599  (*Destruct proof state into constraints, other goals, goal(i), rest *)
   2.600 -fun dest_state (state as Thm{prop,...}, i) =
   2.601 -  let val (tpairs,horn) = Logic.strip_flexpairs prop
   2.602 -  in  case  Logic.strip_prems(i, [], horn) of
   2.603 -          (B::rBs, C) => (tpairs, rev rBs, B, C)
   2.604 -        | _ => raise THM("dest_state", i, [state])
   2.605 -  end
   2.606 +fun dest_state (state as Thm{prop,tpairs,...}, i) =
   2.607 +  (case  Logic.strip_prems(i, [], prop) of
   2.608 +      (B::rBs, C) => (tpairs, rev rBs, B, C)
   2.609 +    | _ => raise THM("dest_state", i, [state]))
   2.610    handle TERM _ => raise THM("dest_state", i, [state]);
   2.611  
   2.612  (*Increment variables and parameters of orule as required for
   2.613    resolution with goal i of state. *)
   2.614  fun lift_rule (state, i) orule =
   2.615    let val Thm{shyps=sshyps, prop=sprop, maxidx=smax, sign_ref=ssign_ref,...} = state
   2.616 -      val (Bi::_, _) = Logic.strip_prems(i, [], Logic.skip_flexpairs sprop)
   2.617 +      val (Bi::_, _) = Logic.strip_prems(i, [], sprop)
   2.618          handle TERM _ => raise THM("lift_rule", i, [orule,state])
   2.619        val ct_Bi = Cterm {sign_ref=ssign_ref, maxidx=smax, T=propT, t=Bi}
   2.620        val (lift_abs,lift_all) = Logic.lift_fns(Bi,smax+1)
   2.621 -      val (Thm{sign_ref, der, maxidx,shyps,hyps,prop}) = orule
   2.622 -      val (tpairs,As,B) = Logic.strip_horn prop
   2.623 +      val (Thm{sign_ref, der, maxidx,shyps,hyps,tpairs,prop}) = orule
   2.624 +      val (As, B) = Logic.strip_horn prop
   2.625    in  (*no fix_shyps*)
   2.626        Thm{sign_ref = merge_thm_sgs(state,orule),
   2.627            der = Pt.infer_derivs' (Pt.lift_proof Bi (smax+1) prop) der,
   2.628            maxidx = maxidx+smax+1,
   2.629            shyps=union_sort(sshyps,shyps), 
   2.630            hyps=hyps, 
   2.631 -          prop = Logic.rule_of (map (pairself lift_abs) tpairs,
   2.632 -                                map lift_all As,    
   2.633 -                                lift_all B)}
   2.634 +          tpairs = map (pairself lift_abs) tpairs,
   2.635 +          prop = Logic.list_implies (map lift_all As, lift_all B)}
   2.636    end;
   2.637  
   2.638 -fun incr_indexes i (thm as Thm {sign_ref, der, maxidx, shyps, hyps, prop}) =
   2.639 +fun incr_indexes i (thm as Thm {sign_ref, der, maxidx, shyps, hyps, tpairs, prop}) =
   2.640    if i < 0 then raise THM ("negative increment", 0, [thm]) else
   2.641    if i = 0 then thm else
   2.642      Thm {sign_ref = sign_ref,
   2.643 @@ -1065,6 +1108,7 @@
   2.644           maxidx = maxidx + i,
   2.645           shyps = shyps,
   2.646           hyps = hyps,
   2.647 +         tpairs = map (pairself (Logic.incr_indexes ([], i))) tpairs,
   2.648           prop = Logic.incr_indexes ([], i) prop};
   2.649  
   2.650  (*Solve subgoal Bi of proof state B1...Bn/C by assumption. *)
   2.651 @@ -1080,11 +1124,13 @@
   2.652                 maxidx = maxidx,
   2.653                 shyps = [],
   2.654                 hyps = hyps,
   2.655 +               tpairs = if Envir.is_empty env then tpairs else
   2.656 +                 map (pairself (Envir.norm_term env)) tpairs,
   2.657                 prop = 
   2.658                 if Envir.is_empty env then (*avoid wasted normalizations*)
   2.659 -                   Logic.rule_of (tpairs, Bs, C)
   2.660 +                   Logic.list_implies (Bs, C)
   2.661                 else (*normalize the new rule fully*)
   2.662 -                   Envir.norm_term env (Logic.rule_of (tpairs, Bs, C))});
   2.663 +                   Envir.norm_term env (Logic.list_implies (Bs, C))});
   2.664        fun addprfs [] _ = Seq.empty
   2.665          | addprfs ((t,u)::apairs) n = Seq.make (fn()=> Seq.pull
   2.666               (Seq.mapp (newth n)
   2.667 @@ -1106,13 +1152,14 @@
   2.668                       maxidx = maxidx,
   2.669                       shyps = [],
   2.670                       hyps = hyps,
   2.671 -                     prop = Logic.rule_of(tpairs, Bs, C)}))
   2.672 +                     tpairs = tpairs,
   2.673 +                     prop = Logic.list_implies (Bs, C)}))
   2.674    end;
   2.675  
   2.676  
   2.677  (*For rotate_tac: fast rotation of assumptions of subgoal i*)
   2.678  fun rotate_rule k i state =
   2.679 -  let val Thm{sign_ref,der,maxidx,hyps,prop,shyps} = state;
   2.680 +  let val Thm{sign_ref,der,maxidx,hyps,prop,shyps,...} = state;
   2.681        val (tpairs, Bs, Bi, C) = dest_state(state,i)
   2.682        val params = Term.strip_all_vars Bi
   2.683        and rest   = Term.strip_all_body Bi
   2.684 @@ -1132,7 +1179,8 @@
   2.685  	  maxidx = maxidx,
   2.686  	  shyps = shyps,
   2.687  	  hyps = hyps,
   2.688 -	  prop = Logic.rule_of (tpairs, Bs @ [Bi'], C)}
   2.689 +          tpairs = tpairs,
   2.690 +	  prop = Logic.list_implies (Bs @ [Bi'], C)}
   2.691    end;
   2.692  
   2.693  
   2.694 @@ -1140,7 +1188,7 @@
   2.695    unchanged.  Does nothing if k=0 or if k equals n-j, where n is the
   2.696    number of premises.  Useful with etac and underlies tactic/defer_tac*)
   2.697  fun permute_prems j k rl =
   2.698 -  let val Thm{sign_ref,der,maxidx,hyps,prop,shyps} = rl
   2.699 +  let val Thm{sign_ref,der,maxidx,hyps,tpairs,prop,shyps} = rl
   2.700        val prems  = Logic.strip_imp_prems prop
   2.701        and concl  = Logic.strip_imp_concl prop
   2.702        val moved_prems = List.drop(prems, j)
   2.703 @@ -1159,6 +1207,7 @@
   2.704  	  maxidx = maxidx,
   2.705  	  shyps = shyps,
   2.706  	  hyps = hyps,
   2.707 +          tpairs = tpairs,
   2.708  	  prop = prop'}
   2.709    end;
   2.710  
   2.711 @@ -1170,7 +1219,7 @@
   2.712    The names in cs, if distinct, are used for the innermost parameters;
   2.713     preceding parameters may be renamed to make all params distinct.*)
   2.714  fun rename_params_rule (cs, i) state =
   2.715 -  let val Thm{sign_ref,der,maxidx,hyps,...} = state
   2.716 +  let val Thm{sign_ref,der,maxidx,hyps,shyps,...} = state
   2.717        val (tpairs, Bs, Bi, C) = dest_state(state,i)
   2.718        val iparams = map #1 (Logic.strip_params Bi)
   2.719        val short = length iparams - length cs
   2.720 @@ -1186,19 +1235,19 @@
   2.721     | [] => (case cs inter_string freenames of
   2.722         a::_ => (warning ("Can't rename.  Bound/Free variable clash: " ^ a); 
   2.723  		state)
   2.724 -     | [] => fix_shyps [state] []
   2.725 -                (Thm{sign_ref = sign_ref,
   2.726 -                     der = der,
   2.727 -                     maxidx = maxidx,
   2.728 -                     shyps = [],
   2.729 -                     hyps = hyps,
   2.730 -                     prop = Logic.rule_of(tpairs, Bs@[newBi], C)}))
   2.731 +     | [] => Thm{sign_ref = sign_ref,
   2.732 +                 der = der,
   2.733 +                 maxidx = maxidx,
   2.734 +                 shyps = shyps,
   2.735 +                 hyps = hyps,
   2.736 +                 tpairs = tpairs,
   2.737 +                 prop = Logic.list_implies (Bs @ [newBi], C)})
   2.738    end;
   2.739  
   2.740  
   2.741  (*** Preservation of bound variable names ***)
   2.742  
   2.743 -fun rename_boundvars pat obj (thm as Thm {sign_ref, der, maxidx, hyps, shyps, prop}) =
   2.744 +fun rename_boundvars pat obj (thm as Thm {sign_ref, der, maxidx, hyps, shyps, tpairs, prop}) =
   2.745    (case Term.rename_abs pat obj prop of
   2.746      None => thm
   2.747    | Some prop' => Thm
   2.748 @@ -1207,6 +1256,7 @@
   2.749         maxidx = maxidx,
   2.750         hyps = hyps,
   2.751         shyps = shyps,
   2.752 +       tpairs = tpairs,
   2.753         prop = prop'});
   2.754  
   2.755  
   2.756 @@ -1288,7 +1338,7 @@
   2.757                          (eres_flg, orule, nsubgoal) =
   2.758   let val Thm{der=sder, maxidx=smax, shyps=sshyps, hyps=shyps, ...} = state
   2.759       and Thm{der=rder, maxidx=rmax, shyps=rshyps, hyps=rhyps, 
   2.760 -             prop=rprop,...} = orule
   2.761 +             tpairs=rtpairs, prop=rprop,...} = orule
   2.762           (*How many hyps to skip over during normalization*)
   2.763       and nlift = Logic.count_prems(strip_all_body Bi,
   2.764                                     if eres_flg then ~1 else 0)
   2.765 @@ -1298,18 +1348,18 @@
   2.766       fun addth A (As, oldAs, rder', n) ((env as Envir.Envir {maxidx, ...}, tpairs), thq) =
   2.767         let val normt = Envir.norm_term env;
   2.768             (*perform minimal copying here by examining env*)
   2.769 -           val normp =
   2.770 -             if Envir.is_empty env then (tpairs, Bs @ As, C)
   2.771 +           val (ntpairs, normp) =
   2.772 +             if Envir.is_empty env then (tpairs, (Bs @ As, C))
   2.773               else
   2.774               let val ntps = map (pairself normt) tpairs
   2.775               in if Envir.above (smax, env) then
   2.776                    (*no assignments in state; normalize the rule only*)
   2.777                    if lifted
   2.778 -                  then (ntps, Bs @ map (norm_term_skip env nlift) As, C)
   2.779 -                  else (ntps, Bs @ map normt As, C)
   2.780 +                  then (ntps, (Bs @ map (norm_term_skip env nlift) As, C))
   2.781 +                  else (ntps, (Bs @ map normt As, C))
   2.782                  else if match then raise COMPOSE
   2.783                  else (*normalize the new rule fully*)
   2.784 -                  (ntps, map normt (Bs @ As), normt C)
   2.785 +                  (ntps, (map normt (Bs @ As), normt C))
   2.786               end
   2.787             val th = (*tuned fix_shyps*)
   2.788               Thm{sign_ref = sign_ref,
   2.789 @@ -1323,10 +1373,10 @@
   2.790                   maxidx = maxidx,
   2.791                   shyps = add_env_sorts (env, union_sort(rshyps,sshyps)),
   2.792                   hyps = union_term(rhyps,shyps),
   2.793 -                 prop = Logic.rule_of normp}
   2.794 +                 tpairs = ntpairs,
   2.795 +                 prop = Logic.list_implies normp}
   2.796          in  Seq.cons(th, thq)  end  handle COMPOSE => thq;
   2.797 -     val (rtpairs,rhorn) = Logic.strip_flexpairs(rprop);
   2.798 -     val (rAs,B) = Logic.strip_prems(nsubgoal, [], rhorn)
   2.799 +     val (rAs,B) = Logic.strip_prems(nsubgoal, [], rprop)
   2.800         handle TERM _ => raise THM("bicompose: rule", 0, [orule,state]);
   2.801       (*Modify assumptions, deleting n-th if n>0 for e-resolution*)
   2.802       fun newAs(As0, n, dpairs, tpairs) =
   2.803 @@ -1420,6 +1470,7 @@
   2.804              maxidx = maxidx,
   2.805              shyps = [], 
   2.806              hyps = [], 
   2.807 +            tpairs = [],
   2.808              prop = prop})
   2.809        end
   2.810    end;