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