src/Pure/logic.ML
author wenzelm
Tue Jan 15 00:09:54 2002 +0100 (2002-01-15)
changeset 12757 b76a4376cfcb
parent 12137 6123958975b8
child 12796 95bfef18da83
permissions -rw-r--r--
added mk_conjunction_list;
wenzelm@9460
     1
(*  Title:      Pure/logic.ML
clasohm@0
     2
    ID:         $Id$
wenzelm@9460
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   Cambridge University 1992
clasohm@0
     5
wenzelm@9460
     6
Abstract syntax operations of the Pure meta-logic.
clasohm@0
     7
*)
clasohm@0
     8
clasohm@0
     9
infix occs;
clasohm@0
    10
wenzelm@9460
    11
signature LOGIC =
wenzelm@4345
    12
sig
nipkow@5041
    13
  val is_all            : term -> bool
wenzelm@9460
    14
  val mk_equals         : term * term -> term
wenzelm@9460
    15
  val dest_equals       : term -> term * term
nipkow@3963
    16
  val is_equals         : term -> bool
wenzelm@9460
    17
  val mk_implies        : term * term -> term
wenzelm@9460
    18
  val dest_implies      : term -> term * term
nipkow@5041
    19
  val is_implies        : term -> bool
wenzelm@9460
    20
  val list_implies      : term list * term -> term
wenzelm@9460
    21
  val strip_imp_prems   : term -> term list
wenzelm@9460
    22
  val strip_imp_concl   : term -> term
wenzelm@9460
    23
  val strip_prems       : int * term list * term -> term list * term
wenzelm@9460
    24
  val count_prems       : term * int -> int
wenzelm@12137
    25
  val mk_conjunction    : term * term -> term
wenzelm@12757
    26
  val mk_conjunction_list: term list -> term
wenzelm@9460
    27
  val mk_flexpair       : term * term -> term
wenzelm@9460
    28
  val dest_flexpair     : term -> term * term
wenzelm@9460
    29
  val list_flexpairs    : (term*term)list * term -> term
wenzelm@9460
    30
  val rule_of           : (term*term)list * term list * term -> term
wenzelm@9460
    31
  val strip_flexpairs   : term -> (term*term)list * term
wenzelm@9460
    32
  val skip_flexpairs    : term -> term
wenzelm@9460
    33
  val strip_horn        : term -> (term*term)list * term list * term
wenzelm@9460
    34
  val mk_cond_defpair   : term list -> term * term -> string * term
wenzelm@9460
    35
  val mk_defpair        : term * term -> string * term
wenzelm@9460
    36
  val mk_type           : typ -> term
wenzelm@9460
    37
  val dest_type         : term -> typ
wenzelm@9460
    38
  val mk_inclass        : typ * class -> term
wenzelm@9460
    39
  val dest_inclass      : term -> typ * class
wenzelm@9460
    40
  val goal_const        : term
wenzelm@9460
    41
  val mk_goal           : term -> term
wenzelm@9460
    42
  val dest_goal         : term -> term
wenzelm@9460
    43
  val occs              : term * term -> bool
wenzelm@9460
    44
  val close_form        : term -> term
wenzelm@9460
    45
  val incr_indexes      : typ list * int -> term -> term
wenzelm@9460
    46
  val lift_fns          : term * int -> (term -> term) * (term -> term)
wenzelm@9460
    47
  val strip_assums_hyp  : term -> term list
wenzelm@9460
    48
  val strip_assums_concl: term -> term
wenzelm@9460
    49
  val strip_params      : term -> (string * typ) list
wenzelm@10816
    50
  val is_norm_hhf       : term -> bool
wenzelm@9667
    51
  val has_meta_prems    : term -> int -> bool
wenzelm@9460
    52
  val flatten_params    : int -> term -> term
wenzelm@9460
    53
  val auto_rename       : bool ref
wenzelm@9460
    54
  val set_rename_prefix : string -> unit
clasohm@0
    55
  val list_rename_params: string list * term -> term
wenzelm@9460
    56
  val assum_pairs       : term -> (term*term)list
wenzelm@9460
    57
  val varify            : term -> term
wenzelm@9460
    58
  val unvarify          : term -> term
wenzelm@4345
    59
end;
clasohm@0
    60
paulson@1500
    61
structure Logic : LOGIC =
clasohm@0
    62
struct
wenzelm@398
    63
wenzelm@4345
    64
clasohm@0
    65
(*** Abstract syntax operations on the meta-connectives ***)
clasohm@0
    66
nipkow@5041
    67
(** all **)
nipkow@5041
    68
nipkow@5041
    69
fun is_all (Const ("all", _) $ _) = true
nipkow@5041
    70
  | is_all _ = false;
nipkow@5041
    71
nipkow@5041
    72
clasohm@0
    73
(** equality **)
clasohm@0
    74
paulson@1835
    75
(*Make an equality.  DOES NOT CHECK TYPE OF u*)
lcp@64
    76
fun mk_equals(t,u) = equals(fastype_of t) $ t $ u;
clasohm@0
    77
clasohm@0
    78
fun dest_equals (Const("==",_) $ t $ u)  =  (t,u)
clasohm@0
    79
  | dest_equals t = raise TERM("dest_equals", [t]);
clasohm@0
    80
wenzelm@637
    81
fun is_equals (Const ("==", _) $ _ $ _) = true
wenzelm@637
    82
  | is_equals _ = false;
wenzelm@637
    83
wenzelm@637
    84
clasohm@0
    85
(** implies **)
clasohm@0
    86
clasohm@0
    87
fun mk_implies(A,B) = implies $ A $ B;
clasohm@0
    88
clasohm@0
    89
fun dest_implies (Const("==>",_) $ A $ B)  =  (A,B)
clasohm@0
    90
  | dest_implies A = raise TERM("dest_implies", [A]);
clasohm@0
    91
nipkow@5041
    92
fun is_implies (Const ("==>", _) $ _ $ _) = true
nipkow@5041
    93
  | is_implies _ = false;
nipkow@5041
    94
wenzelm@4822
    95
clasohm@0
    96
(** nested implications **)
clasohm@0
    97
clasohm@0
    98
(* [A1,...,An], B  goes to  A1==>...An==>B  *)
clasohm@0
    99
fun list_implies ([], B) = B : term
clasohm@0
   100
  | list_implies (A::AS, B) = implies $ A $ list_implies(AS,B);
clasohm@0
   101
clasohm@0
   102
(* A1==>...An==>B  goes to  [A1,...,An], where B is not an implication *)
clasohm@0
   103
fun strip_imp_prems (Const("==>", _) $ A $ B) = A :: strip_imp_prems B
clasohm@0
   104
  | strip_imp_prems _ = [];
clasohm@0
   105
clasohm@0
   106
(* A1==>...An==>B  goes to B, where B is not an implication *)
clasohm@0
   107
fun strip_imp_concl (Const("==>", _) $ A $ B) = strip_imp_concl B
clasohm@0
   108
  | strip_imp_concl A = A : term;
clasohm@0
   109
clasohm@0
   110
(*Strip and return premises: (i, [], A1==>...Ai==>B)
wenzelm@9460
   111
    goes to   ([Ai, A(i-1),...,A1] , B)         (REVERSED)
clasohm@0
   112
  if  i<0 or else i too big then raises  TERM*)
wenzelm@9460
   113
fun strip_prems (0, As, B) = (As, B)
wenzelm@9460
   114
  | strip_prems (i, As, Const("==>", _) $ A $ B) =
wenzelm@9460
   115
        strip_prems (i-1, A::As, B)
clasohm@0
   116
  | strip_prems (_, As, A) = raise TERM("strip_prems", A::As);
clasohm@0
   117
clasohm@0
   118
(*Count premises -- quicker than (length ostrip_prems) *)
clasohm@0
   119
fun count_prems (Const("==>", _) $ A $ B, n) = count_prems (B,n+1)
clasohm@0
   120
  | count_prems (_,n) = n;
clasohm@0
   121
wenzelm@4822
   122
wenzelm@12137
   123
(** conjunction **)
wenzelm@12137
   124
wenzelm@12137
   125
fun mk_conjunction (t, u) =
wenzelm@12137
   126
  Term.list_all ([("C", propT)], mk_implies (list_implies ([t, u], Bound 0), Bound 0));
wenzelm@12137
   127
wenzelm@12757
   128
fun mk_conjunction_list [] = Term.all propT $ Abs ("dummy", propT, mk_implies (Bound 0, Bound 0))
wenzelm@12757
   129
  | mk_conjunction_list ts = foldr1 mk_conjunction ts;
wenzelm@12137
   130
wenzelm@12137
   131
clasohm@0
   132
(** flex-flex constraints **)
clasohm@0
   133
lcp@64
   134
(*Make a constraint.*)
lcp@64
   135
fun mk_flexpair(t,u) = flexpair(fastype_of t) $ t $ u;
clasohm@0
   136
clasohm@0
   137
fun dest_flexpair (Const("=?=",_) $ t $ u)  =  (t,u)
clasohm@0
   138
  | dest_flexpair t = raise TERM("dest_flexpair", [t]);
clasohm@0
   139
clasohm@0
   140
(*make flexflex antecedents: ( [(a1,b1),...,(an,bn)] , C )
clasohm@0
   141
    goes to (a1=?=b1) ==>...(an=?=bn)==>C *)
clasohm@0
   142
fun list_flexpairs ([], A) = A
clasohm@0
   143
  | list_flexpairs ((t,u)::pairs, A) =
wenzelm@9460
   144
        implies $ (mk_flexpair(t,u)) $ list_flexpairs(pairs,A);
clasohm@0
   145
clasohm@0
   146
(*Make the object-rule tpairs==>As==>B   *)
clasohm@0
   147
fun rule_of (tpairs, As, B) = list_flexpairs(tpairs, list_implies(As, B));
clasohm@0
   148
wenzelm@9460
   149
(*Remove and return flexflex pairs:
wenzelm@9460
   150
    (a1=?=b1)==>...(an=?=bn)==>C  to  ( [(a1,b1),...,(an,bn)] , C )
clasohm@0
   151
  [Tail recursive in order to return a pair of results] *)
clasohm@0
   152
fun strip_flex_aux (pairs, Const("==>", _) $ (Const("=?=",_)$t$u) $ C) =
clasohm@0
   153
        strip_flex_aux ((t,u)::pairs, C)
clasohm@0
   154
  | strip_flex_aux (pairs,C) = (rev pairs, C);
clasohm@0
   155
clasohm@0
   156
fun strip_flexpairs A = strip_flex_aux([], A);
clasohm@0
   157
clasohm@0
   158
(*Discard flexflex pairs*)
clasohm@0
   159
fun skip_flexpairs (Const("==>", _) $ (Const("=?=",_)$_$_) $ C) =
wenzelm@9460
   160
        skip_flexpairs C
clasohm@0
   161
  | skip_flexpairs C = C;
clasohm@0
   162
wenzelm@9460
   163
(*strip a proof state (Horn clause):
clasohm@0
   164
   (a1==b1)==>...(am==bm)==>B1==>...Bn==>C
clasohm@0
   165
    goes to   ( [(a1,b1),...,(am,bm)] , [B1,...,Bn] , C)    *)
clasohm@0
   166
fun strip_horn A =
wenzelm@9460
   167
  let val (tpairs,horn) = strip_flexpairs A
clasohm@0
   168
  in  (tpairs, strip_imp_prems horn, strip_imp_concl horn)   end;
clasohm@0
   169
wenzelm@4822
   170
wenzelm@4822
   171
(** definitions **)
wenzelm@4822
   172
wenzelm@4822
   173
fun mk_cond_defpair As (lhs, rhs) =
wenzelm@4822
   174
  (case Term.head_of lhs of
wenzelm@4822
   175
    Const (name, _) =>
wenzelm@4822
   176
      (Sign.base_name name ^ "_def", list_implies (As, mk_equals (lhs, rhs)))
wenzelm@4822
   177
  | _ => raise TERM ("Malformed definition: head of lhs not a constant", [lhs, rhs]));
wenzelm@4822
   178
wenzelm@4822
   179
fun mk_defpair lhs_rhs = mk_cond_defpair [] lhs_rhs;
wenzelm@4822
   180
wenzelm@4822
   181
wenzelm@398
   182
(** types as terms **)
wenzelm@398
   183
wenzelm@398
   184
fun mk_type ty = Const ("TYPE", itselfT ty);
wenzelm@398
   185
wenzelm@398
   186
fun dest_type (Const ("TYPE", Type ("itself", [ty]))) = ty
wenzelm@398
   187
  | dest_type t = raise TERM ("dest_type", [t]);
wenzelm@398
   188
wenzelm@4822
   189
wenzelm@447
   190
(** class constraints **)
wenzelm@398
   191
wenzelm@398
   192
fun mk_inclass (ty, c) =
wenzelm@398
   193
  Const (Sign.const_of_class c, itselfT ty --> propT) $ mk_type ty;
wenzelm@398
   194
wenzelm@398
   195
fun dest_inclass (t as Const (c_class, _) $ ty) =
wenzelm@398
   196
      ((dest_type ty, Sign.class_of_const c_class)
wenzelm@398
   197
        handle TERM _ => raise TERM ("dest_inclass", [t]))
wenzelm@398
   198
  | dest_inclass t = raise TERM ("dest_inclass", [t]);
wenzelm@398
   199
clasohm@0
   200
wenzelm@9460
   201
(** atomic goals **)
wenzelm@9460
   202
wenzelm@9460
   203
val goal_const = Const ("Goal", propT --> propT);
wenzelm@9460
   204
fun mk_goal t = goal_const $ t;
wenzelm@9460
   205
wenzelm@9460
   206
fun dest_goal (Const ("Goal", _) $ t) = t
wenzelm@9460
   207
  | dest_goal t = raise TERM ("dest_goal", [t]);
wenzelm@9460
   208
wenzelm@9460
   209
clasohm@0
   210
(*** Low-level term operations ***)
clasohm@0
   211
clasohm@0
   212
(*Does t occur in u?  Or is alpha-convertible to u?
clasohm@0
   213
  The term t must contain no loose bound variables*)
nipkow@4631
   214
fun t occs u = exists_subterm (fn s => t aconv s) u;
clasohm@0
   215
clasohm@0
   216
(*Close up a formula over all free variables by quantification*)
clasohm@0
   217
fun close_form A =
wenzelm@4443
   218
  list_all_free (sort_wrt fst (map dest_Free (term_frees A)), A);
clasohm@0
   219
clasohm@0
   220
clasohm@0
   221
(*** Specialized operations for resolution... ***)
clasohm@0
   222
clasohm@0
   223
(*For all variables in the term, increment indexnames and lift over the Us
clasohm@0
   224
    result is ?Gidx(B.(lev+n-1),...,B.lev) where lev is abstraction level *)
wenzelm@9460
   225
fun incr_indexes (Us: typ list, inc:int) t =
wenzelm@9460
   226
  let fun incr (Var ((a,i), T), lev) =
wenzelm@9460
   227
                Unify.combound (Var((a, i+inc), Us---> incr_tvar inc T),
wenzelm@9460
   228
                                lev, length Us)
wenzelm@9460
   229
        | incr (Abs (a,T,body), lev) =
wenzelm@9460
   230
                Abs (a, incr_tvar inc T, incr(body,lev+1))
wenzelm@9460
   231
        | incr (Const(a,T),_) = Const(a, incr_tvar inc T)
wenzelm@9460
   232
        | incr (Free(a,T),_) = Free(a, incr_tvar inc T)
wenzelm@9460
   233
        | incr (f$t, lev) = incr(f,lev) $ incr(t,lev)
wenzelm@9460
   234
        | incr (t,lev) = t
clasohm@0
   235
  in  incr(t,0)  end;
clasohm@0
   236
clasohm@0
   237
(*Make lifting functions from subgoal and increment.
clasohm@0
   238
    lift_abs operates on tpairs (unification constraints)
clasohm@0
   239
    lift_all operates on propositions     *)
clasohm@0
   240
fun lift_fns (B,inc) =
clasohm@0
   241
  let fun lift_abs (Us, Const("==>", _) $ _ $ B) u = lift_abs (Us,B) u
wenzelm@9460
   242
        | lift_abs (Us, Const("all",_)$Abs(a,T,t)) u =
wenzelm@9460
   243
              Abs(a, T, lift_abs (T::Us, t) u)
wenzelm@9460
   244
        | lift_abs (Us, _) u = incr_indexes(rev Us, inc) u
clasohm@0
   245
      fun lift_all (Us, Const("==>", _) $ A $ B) u =
wenzelm@9460
   246
              implies $ A $ lift_all (Us,B) u
wenzelm@9460
   247
        | lift_all (Us, Const("all",_)$Abs(a,T,t)) u =
wenzelm@9460
   248
              all T $ Abs(a, T, lift_all (T::Us,t) u)
wenzelm@9460
   249
        | lift_all (Us, _) u = incr_indexes(rev Us, inc) u;
clasohm@0
   250
  in  (lift_abs([],B), lift_all([],B))  end;
clasohm@0
   251
clasohm@0
   252
(*Strips assumptions in goal, yielding list of hypotheses.   *)
clasohm@0
   253
fun strip_assums_hyp (Const("==>", _) $ H $ B) = H :: strip_assums_hyp B
clasohm@0
   254
  | strip_assums_hyp (Const("all",_)$Abs(a,T,t)) = strip_assums_hyp t
clasohm@0
   255
  | strip_assums_hyp B = [];
clasohm@0
   256
clasohm@0
   257
(*Strips assumptions in goal, yielding conclusion.   *)
clasohm@0
   258
fun strip_assums_concl (Const("==>", _) $ H $ B) = strip_assums_concl B
clasohm@0
   259
  | strip_assums_concl (Const("all",_)$Abs(a,T,t)) = strip_assums_concl t
clasohm@0
   260
  | strip_assums_concl B = B;
clasohm@0
   261
clasohm@0
   262
(*Make a list of all the parameters in a subgoal, even if nested*)
clasohm@0
   263
fun strip_params (Const("==>", _) $ H $ B) = strip_params B
clasohm@0
   264
  | strip_params (Const("all",_)$Abs(a,T,t)) = (a,T) :: strip_params t
clasohm@0
   265
  | strip_params B = [];
clasohm@0
   266
wenzelm@10816
   267
(*test for HHF normal form*)
wenzelm@10816
   268
fun is_norm_hhf (Const ("==>", _) $ _ $ (Const ("all", _) $ _)) = false
wenzelm@10816
   269
  | is_norm_hhf (t $ u) = is_norm_hhf t andalso is_norm_hhf u
wenzelm@10816
   270
  | is_norm_hhf (Abs (_, _, t)) = is_norm_hhf t
wenzelm@10816
   271
  | is_norm_hhf _ = true;
wenzelm@10816
   272
wenzelm@9667
   273
(*test for meta connectives in prems of a 'subgoal'*)
wenzelm@9667
   274
fun has_meta_prems prop i =
wenzelm@9667
   275
  let
wenzelm@9667
   276
    fun is_meta (Const ("==>", _) $ _ $ _) = true
wenzelm@10442
   277
      | is_meta (Const ("==", _) $ _ $ _) = true
wenzelm@9667
   278
      | is_meta (Const ("all", _) $ _) = true
wenzelm@9667
   279
      | is_meta _ = false;
wenzelm@9667
   280
    val horn = skip_flexpairs prop;
wenzelm@9667
   281
  in
wenzelm@9667
   282
    (case strip_prems (i, [], horn) of
wenzelm@9667
   283
      (B :: _, _) => exists is_meta (strip_assums_hyp B)
wenzelm@9667
   284
    | _ => false) handle TERM _ => false
wenzelm@9667
   285
  end;
wenzelm@9483
   286
clasohm@0
   287
(*Removes the parameters from a subgoal and renumber bvars in hypotheses,
wenzelm@9460
   288
    where j is the total number of parameters (precomputed)
clasohm@0
   289
  If n>0 then deletes assumption n. *)
wenzelm@9460
   290
fun remove_params j n A =
clasohm@0
   291
    if j=0 andalso n<=0 then A  (*nothing left to do...*)
clasohm@0
   292
    else case A of
wenzelm@9460
   293
        Const("==>", _) $ H $ B =>
wenzelm@9460
   294
          if n=1 then                           (remove_params j (n-1) B)
wenzelm@9460
   295
          else implies $ (incr_boundvars j H) $ (remove_params j (n-1) B)
clasohm@0
   296
      | Const("all",_)$Abs(a,T,t) => remove_params (j-1) n t
clasohm@0
   297
      | _ => if n>0 then raise TERM("remove_params", [A])
clasohm@0
   298
             else A;
clasohm@0
   299
clasohm@0
   300
(** Auto-renaming of parameters in subgoals **)
clasohm@0
   301
clasohm@0
   302
val auto_rename = ref false
clasohm@0
   303
and rename_prefix = ref "ka";
clasohm@0
   304
clasohm@0
   305
(*rename_prefix is not exported; it is set by this function.*)
clasohm@0
   306
fun set_rename_prefix a =
wenzelm@4693
   307
    if a<>"" andalso forall Symbol.is_letter (Symbol.explode a)
clasohm@0
   308
    then  (rename_prefix := a;  auto_rename := true)
clasohm@0
   309
    else  error"rename prefix must be nonempty and consist of letters";
clasohm@0
   310
clasohm@0
   311
(*Makes parameters in a goal have distinctive names (not guaranteed unique!)
clasohm@0
   312
  A name clash could cause the printer to rename bound vars;
clasohm@0
   313
    then res_inst_tac would not work properly.*)
clasohm@0
   314
fun rename_vars (a, []) = []
clasohm@0
   315
  | rename_vars (a, (_,T)::vars) =
clasohm@0
   316
        (a,T) :: rename_vars (bump_string a, vars);
clasohm@0
   317
clasohm@0
   318
(*Move all parameters to the front of the subgoal, renaming them apart;
clasohm@0
   319
  if n>0 then deletes assumption n. *)
clasohm@0
   320
fun flatten_params n A =
clasohm@0
   321
    let val params = strip_params A;
wenzelm@9460
   322
        val vars = if !auto_rename
wenzelm@9460
   323
                   then rename_vars (!rename_prefix, params)
wenzelm@9460
   324
                   else ListPair.zip (variantlist(map #1 params,[]),
wenzelm@9460
   325
                                      map #2 params)
clasohm@0
   326
    in  list_all (vars, remove_params (length vars) n A)
clasohm@0
   327
    end;
clasohm@0
   328
clasohm@0
   329
(*Makes parameters in a goal have the names supplied by the list cs.*)
clasohm@0
   330
fun list_rename_params (cs, Const("==>", _) $ A $ B) =
clasohm@0
   331
      implies $ A $ list_rename_params (cs, B)
wenzelm@9460
   332
  | list_rename_params (c::cs, Const("all",_)$Abs(_,T,t)) =
clasohm@0
   333
      all T $ Abs(c, T, list_rename_params (cs, t))
clasohm@0
   334
  | list_rename_params (cs, B) = B;
clasohm@0
   335
paulson@9684
   336
(*Strips assumptions in goal yielding  ( [HPn,...,HP1], [xm,...,x1], B ).
paulson@9684
   337
  Where HPi has the form (Hi,nparams_i) and x1...xm are the parameters.
paulson@9684
   338
  We need nparams_i only when the parameters aren't flattened; then we
paulson@9684
   339
    must call incr_boundvars to make up the difference.  See assum_pairs.
paulson@9684
   340
  Without this refinement we can get the wrong answer, e.g. by
wenzelm@10816
   341
        Goal "!!f. EX B. Q(f,B) ==> (!!y. P(f,y))";
wenzelm@10816
   342
        by (etac exE 1);
paulson@9684
   343
 *)
paulson@9684
   344
fun strip_assums_aux (HPs, params, Const("==>", _) $ H $ B) =
paulson@9684
   345
        strip_assums_aux ((H,length params)::HPs, params, B)
paulson@9684
   346
  | strip_assums_aux (HPs, params, Const("all",_)$Abs(a,T,t)) =
paulson@9684
   347
        strip_assums_aux (HPs, (a,T)::params, t)
paulson@9684
   348
  | strip_assums_aux (HPs, params, B) = (HPs, params, B);
clasohm@0
   349
clasohm@0
   350
fun strip_assums A = strip_assums_aux ([],[],A);
clasohm@0
   351
clasohm@0
   352
clasohm@0
   353
(*Produces disagreement pairs, one for each assumption proof, in order.
clasohm@0
   354
  A is the first premise of the lifted rule, and thus has the form
clasohm@0
   355
    H1 ==> ... Hk ==> B   and the pairs are (H1,B),...,(Hk,B) *)
clasohm@0
   356
fun assum_pairs A =
paulson@9684
   357
  let val (HPs, params, B) = strip_assums A
paulson@9684
   358
      val nparams = length params
clasohm@0
   359
      val D = Unify.rlist_abs(params, B)
wenzelm@10816
   360
      fun incr_hyp(H,np) =
wenzelm@10816
   361
          Unify.rlist_abs(params, incr_boundvars (nparams-np) H)
wenzelm@9460
   362
      fun pairrev ([],pairs) = pairs
paulson@9684
   363
        | pairrev ((H,np)::HPs, pairs) =
paulson@9684
   364
            pairrev(HPs,  (incr_hyp(H,np),D) :: pairs)
wenzelm@10816
   365
  in  pairrev (HPs,[])
clasohm@0
   366
  end;
clasohm@0
   367
clasohm@0
   368
(*Converts Frees to Vars and TFrees to TVars so that axioms can be written
clasohm@0
   369
  without (?) everywhere*)
clasohm@0
   370
fun varify (Const(a,T)) = Const(a, Type.varifyT T)
clasohm@0
   371
  | varify (Free(a,T)) = Var((a,0), Type.varifyT T)
clasohm@0
   372
  | varify (Var(ixn,T)) = Var(ixn, Type.varifyT T)
clasohm@0
   373
  | varify (Abs (a,T,body)) = Abs (a, Type.varifyT T, varify body)
clasohm@0
   374
  | varify (f$t) = varify f $ varify t
clasohm@0
   375
  | varify t = t;
clasohm@0
   376
lcp@546
   377
(*Inverse of varify.  Converts axioms back to their original form.*)
lcp@585
   378
fun unvarify (Const(a,T))    = Const(a, Type.unvarifyT T)
lcp@585
   379
  | unvarify (Var((a,0), T)) = Free(a, Type.unvarifyT T)
lcp@585
   380
  | unvarify (Var(ixn,T))    = Var(ixn, Type.unvarifyT T)  (*non-0 index!*)
lcp@585
   381
  | unvarify (Abs (a,T,body)) = Abs (a, Type.unvarifyT T, unvarify body)
lcp@546
   382
  | unvarify (f$t) = unvarify f $ unvarify t
lcp@546
   383
  | unvarify t = t;
lcp@546
   384
clasohm@0
   385
end;