src/Pure/envir.ML
author wenzelm
Wed, 21 Jan 2009 23:21:44 +0100
changeset 29606 fedb8be05f24
parent 29269 5c25a2012975
child 30146 a77fc0209723
permissions -rw-r--r--
removed Ids;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
247
bc10568855ee added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents: 0
diff changeset
     1
(*  Title:      Pure/envir.ML
bc10568855ee added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents: 0
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
10485
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
     3
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
     4
Environments.  The type of a term variable / sort of a type variable is
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
     5
part of its name. The lookup function must apply type substitutions,
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
     6
since they may change the identity of a variable.
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
247
bc10568855ee added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents: 0
diff changeset
     9
signature ENVIR =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
sig
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    11
  type tenv
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    12
  datatype env = Envir of {asol: tenv, iTs: Type.tyenv, maxidx: int}
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    13
  val type_env: env -> Type.tyenv
26638
1d5d42d8fd66 added insert_sorts (from thm.ML);
wenzelm
parents: 26328
diff changeset
    14
  val insert_sorts: env -> sort list -> sort list
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
    15
  exception SAME
10485
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
    16
  val genvars: string -> env * typ list -> env * term list
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
    17
  val genvar: string -> env * typ -> env * term
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    18
  val lookup: env * (indexname * typ) -> term option
16652
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
    19
  val lookup': tenv * (indexname * typ) -> term option
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    20
  val update: ((indexname * typ) * term) * env -> env
10485
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
    21
  val empty: int -> env
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
    22
  val is_empty: env -> bool
19861
620d90091788 tuned Seq/Envir/Unify interfaces;
wenzelm
parents: 19422
diff changeset
    23
  val above: env -> int -> bool
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    24
  val vupdate: ((indexname * typ) * term) * env -> env
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    25
  val alist_of: env -> (indexname * (typ * term)) list
10485
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
    26
  val norm_term: env -> term -> term
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
    27
  val norm_term_same: env -> term -> term
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    28
  val norm_type: Type.tyenv -> typ -> typ
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    29
  val norm_type_same: Type.tyenv -> typ -> typ
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    30
  val norm_types_same: Type.tyenv -> typ list -> typ list
10485
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
    31
  val beta_norm: term -> term
12231
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
    32
  val head_norm: env -> term -> term
18937
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
    33
  val eta_contract: term -> term
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
    34
  val beta_eta_contract: term -> term
12231
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
    35
  val fastype: env -> typ list -> term -> typ
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    36
  val typ_subst_TVars: Type.tyenv -> typ -> typ
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    37
  val subst_TVars: Type.tyenv -> term -> term
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    38
  val subst_Vars: tenv -> term -> term
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    39
  val subst_vars: Type.tyenv * tenv -> term -> term
19422
bba26da0f227 expand_atom: Type.raw_match;
wenzelm
parents: 18937
diff changeset
    40
  val expand_atom: typ -> typ * term -> term
21695
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
    41
  val expand_term: (term -> (typ * term) option) -> term -> term
21795
d7dcc3dfa7e9 added expand_term_frees;
wenzelm
parents: 21695
diff changeset
    42
  val expand_term_frees: ((string * typ) * term) list -> term -> term
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    44
1500
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
    45
structure Envir : ENVIR =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
(*updating can destroy environment in 2 ways!!
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
   (1) variables out of range   (2) circular assignments
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
*)
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    51
type tenv = (typ * term) Vartab.table
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    52
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
datatype env = Envir of
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    54
    {maxidx: int,      (*maximum index of vars*)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    55
     asol: tenv,       (*table of assignments to Vars*)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    56
     iTs: Type.tyenv}  (*table of assignments to TVars*)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
12496
0a9bd5034e05 added type_env function;
wenzelm
parents: 12231
diff changeset
    58
fun type_env (Envir {iTs, ...}) = iTs;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
26638
1d5d42d8fd66 added insert_sorts (from thm.ML);
wenzelm
parents: 26328
diff changeset
    60
(*NB: type unification may invent new sorts*)
1d5d42d8fd66 added insert_sorts (from thm.ML);
wenzelm
parents: 26328
diff changeset
    61
val insert_sorts = Vartab.fold (fn (_, (_, T)) => Sorts.insert_typ T) o type_env;
1d5d42d8fd66 added insert_sorts (from thm.ML);
wenzelm
parents: 26328
diff changeset
    62
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
(*Generate a list of distinct variables.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
  Increments index to make them distinct from ALL present variables. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
fun genvars name (Envir{maxidx, asol, iTs}, Ts) : env * term list =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
  let fun genvs (_, [] : typ list) : term list = []
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
        | genvs (n, [T]) = [ Var((name, maxidx+1), T) ]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
        | genvs (n, T::Ts) =
247
bc10568855ee added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents: 0
diff changeset
    69
            Var((name ^ radixstring(26,"a",n), maxidx+1), T)
bc10568855ee added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents: 0
diff changeset
    70
            :: genvs(n+1,Ts)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
  in  (Envir{maxidx=maxidx+1, asol=asol, iTs=iTs}, genvs (0,Ts))  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    73
(*Generate a variable.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
fun genvar name (env,T) : env * term =
247
bc10568855ee added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents: 0
diff changeset
    75
  let val (env',[v]) = genvars name (env,[T])
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
  in  (env',v)  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    78
fun var_clash ixn T T' = raise TYPE ("Variable " ^
22678
23963361278c Term.string_of_vname;
wenzelm
parents: 22174
diff changeset
    79
  quote (Term.string_of_vname ixn) ^ " has two distinct types",
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    80
  [T', T], []);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    82
fun gen_lookup f asol (xname, T) =
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17224
diff changeset
    83
  (case Vartab.lookup asol xname of
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    84
     NONE => NONE
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    85
   | SOME (U, t) => if f (T, U) then SOME t
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    86
       else var_clash xname T U);
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    87
16652
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
    88
(* When dealing with environments produced by matching instead *)
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
    89
(* of unification, there is no need to chase assigned TVars.   *)
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
    90
(* In this case, we can simply ignore the type substitution    *)
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
    91
(* and use = instead of eq_type.                               *)
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    92
16652
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
    93
fun lookup' (asol, p) = gen_lookup op = asol p;
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    94
16652
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
    95
fun lookup2 (iTs, asol) p =
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
    96
  if Vartab.is_empty iTs then lookup' (asol, p)
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
    97
  else gen_lookup (Type.eq_type iTs) asol p;
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    98
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
    99
fun lookup (Envir {asol, iTs, ...}, p) = lookup2 (iTs, asol) p;
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   100
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   101
fun update (((xname, T), t), Envir {maxidx, asol, iTs}) =
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17224
diff changeset
   102
  Envir{maxidx=maxidx, asol=Vartab.update_new (xname, (T, t)) asol, iTs=iTs};
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
5289
41b949f3b8ac fixed comment;
wenzelm
parents: 2191
diff changeset
   104
(*The empty environment.  New variables will start with the given index+1.*)
8407
d522ad1809e9 Envir now uses Vartab instead of association lists.
berghofe
parents: 5289
diff changeset
   105
fun empty m = Envir{maxidx=m, asol=Vartab.empty, iTs=Vartab.empty};
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   106
2142
20f208ff085d Deleted Olist constructor. Replaced minidx by "above" function
paulson
parents: 1500
diff changeset
   107
(*Test for empty environment*)
8407
d522ad1809e9 Envir now uses Vartab instead of association lists.
berghofe
parents: 5289
diff changeset
   108
fun is_empty (Envir {asol, iTs, ...}) = Vartab.is_empty asol andalso Vartab.is_empty iTs;
247
bc10568855ee added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents: 0
diff changeset
   109
2142
20f208ff085d Deleted Olist constructor. Replaced minidx by "above" function
paulson
parents: 1500
diff changeset
   110
(*Determine if the least index updated exceeds lim*)
19861
620d90091788 tuned Seq/Envir/Unify interfaces;
wenzelm
parents: 19422
diff changeset
   111
fun above (Envir {asol, iTs, ...}) lim =
620d90091788 tuned Seq/Envir/Unify interfaces;
wenzelm
parents: 19422
diff changeset
   112
  (case Vartab.min_key asol of SOME (_, i) => i > lim | NONE => true) andalso
620d90091788 tuned Seq/Envir/Unify interfaces;
wenzelm
parents: 19422
diff changeset
   113
  (case Vartab.min_key iTs of SOME (_, i) => i > lim | NONE => true);
247
bc10568855ee added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents: 0
diff changeset
   114
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   115
(*Update, checking Var-Var assignments: try to suppress higher indexes*)
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   116
fun vupdate ((aU as (a, U), t), env as Envir {iTs, ...}) = case t of
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   117
      Var (nT as (name', T)) =>
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   118
        if a = name' then env     (*cycle!*)
29269
5c25a2012975 moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
wenzelm
parents: 26638
diff changeset
   119
        else if TermOrd.indexname_ord (a, name') = LESS then
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   120
           (case lookup (env, nT) of  (*if already assigned, chase*)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   121
                NONE => update ((nT, Var (a, T)), env)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   122
              | SOME u => vupdate ((aU, u), env))
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   123
        else update ((aU, t), env)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   124
    | _ => update ((aU, t), env);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   125
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   126
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   127
(*Convert environment to alist*)
8407
d522ad1809e9 Envir now uses Vartab instead of association lists.
berghofe
parents: 5289
diff changeset
   128
fun alist_of (Envir{asol,...}) = Vartab.dest asol;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   129
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   130
1500
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
   131
(*** Beta normal form for terms (not eta normal form).
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
   132
     Chases variables in env;  Does not exploit sharing of variable bindings
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
   133
     Does not check types, so could loop. ***)
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
   134
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
   135
(*raised when norm has no effect on a term, to do sharing instead of copying*)
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
   136
exception SAME;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   137
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   138
fun norm_term1 same (asol,t) : term =
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   139
  let fun norm (Var wT) =
16652
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
   140
            (case lookup' (asol, wT) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 12496
diff changeset
   141
                SOME u => (norm u handle SAME => u)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 12496
diff changeset
   142
              | NONE   => raise SAME)
10485
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   143
        | norm (Abs(a,T,body)) =  Abs(a, T, norm body)
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   144
        | norm (Abs(_,_,body) $ t) = normh(subst_bound (t, body))
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   145
        | norm (f $ t) =
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   146
            ((case norm f of
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   147
               Abs(_,_,body) => normh(subst_bound (t, body))
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   148
             | nf => nf $ (norm t handle SAME => t))
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   149
            handle SAME => f $ norm t)
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   150
        | norm _ =  raise SAME
2191
58383908f177 Speedups involving norm
paulson
parents: 2181
diff changeset
   151
      and normh t = norm t handle SAME => t
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   152
  in (if same then norm else normh) t end
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   153
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   154
fun normT iTs (Type (a, Ts)) = Type (a, normTs iTs Ts)
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   155
  | normT iTs (TFree _) = raise SAME
26328
b2d6f520172c Type.lookup now curried
haftmann
parents: 25471
diff changeset
   156
  | normT iTs (TVar vS) = (case Type.lookup iTs vS of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 12496
diff changeset
   157
          SOME U => normTh iTs U
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 12496
diff changeset
   158
        | NONE => raise SAME)
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   159
and normTh iTs T = ((normT iTs T) handle SAME => T)
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   160
and normTs iTs [] = raise SAME
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   161
  | normTs iTs (T :: Ts) =
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   162
      ((normT iTs T :: (normTs iTs Ts handle SAME => Ts))
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   163
       handle SAME => T :: normTs iTs Ts);
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   164
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   165
fun norm_term2 same (asol, iTs, t) : term =
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   166
  let fun norm (Const (a, T)) = Const(a, normT iTs T)
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   167
        | norm (Free (a, T)) = Free(a, normT iTs T)
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   168
        | norm (Var (w, T)) =
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   169
            (case lookup2 (iTs, asol) (w, T) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 12496
diff changeset
   170
                SOME u => normh u
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 12496
diff changeset
   171
              | NONE   => Var(w, normT iTs T))
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   172
        | norm (Abs (a, T, body)) =
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   173
               (Abs (a, normT iTs T, normh body) handle SAME => Abs (a, T, norm body))
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   174
        | norm (Abs(_, _, body) $ t) = normh (subst_bound (t, body))
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   175
        | norm (f $ t) =
10485
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   176
            ((case norm f of
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   177
               Abs(_, _, body) => normh (subst_bound (t, body))
10485
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   178
             | nf => nf $ normh t)
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   179
            handle SAME => f $ norm t)
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   180
        | norm _ =  raise SAME
1500
b2de3b3277b8 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
   181
      and normh t = (norm t) handle SAME => t
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   182
  in (if same then norm else normh) t end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   183
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   184
fun gen_norm_term same (env as Envir{asol,iTs,...}) t : term =
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   185
  if Vartab.is_empty iTs then norm_term1 same (asol, t)
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   186
  else norm_term2 same (asol, iTs, t);
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   187
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   188
val norm_term = gen_norm_term false;
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   189
val norm_term_same = gen_norm_term true;
10485
f1576723371f added beta_norm;
wenzelm
parents: 8407
diff changeset
   190
25471
ca009b7ce693 Optimized beta_norm: only tries to normalize term when it contains
berghofe
parents: 24670
diff changeset
   191
fun beta_norm t = if Term.has_abs t then norm_term (empty 0) t else t;
719
e3e1d1a6d408 Pure/envir/norm_term: replaced equality test for [] by null
lcp
parents: 247
diff changeset
   192
12496
0a9bd5034e05 added type_env function;
wenzelm
parents: 12231
diff changeset
   193
fun norm_type iTs = normTh iTs;
0a9bd5034e05 added type_env function;
wenzelm
parents: 12231
diff changeset
   194
fun norm_type_same iTs =
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   195
  if Vartab.is_empty iTs then raise SAME else normT iTs;
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   196
12496
0a9bd5034e05 added type_env function;
wenzelm
parents: 12231
diff changeset
   197
fun norm_types_same iTs =
11513
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   198
  if Vartab.is_empty iTs then raise SAME else normTs iTs;
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   199
2f6fe5b01521 - exported SAME exception
berghofe
parents: 10485
diff changeset
   200
12231
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   201
(*Put a term into head normal form for unification.*)
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   202
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   203
fun head_norm env t =
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   204
  let
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   205
    fun hnorm (Var vT) = (case lookup (env, vT) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 12496
diff changeset
   206
          SOME u => head_norm env u
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 12496
diff changeset
   207
        | NONE => raise SAME)
12231
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   208
      | hnorm (Abs (a, T, body)) =  Abs (a, T, hnorm body)
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   209
      | hnorm (Abs (_, _, body) $ t) =
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   210
          head_norm env (subst_bound (t, body))
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   211
      | hnorm (f $ t) = (case hnorm f of
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   212
          Abs (_, _, body) => head_norm env (subst_bound (t, body))
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   213
        | nf => nf $ t)
20670
115262dd18e2 tuned eta_contract;
wenzelm
parents: 20548
diff changeset
   214
          | hnorm _ =  raise SAME
12231
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   215
  in hnorm t handle SAME => t end;
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   216
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   217
18937
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
   218
(*Eta-contract a term (fully)*)
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
   219
22174
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   220
local
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   221
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   222
fun decr lev (Bound i) = if i >= lev then Bound (i - 1) else raise SAME
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   223
  | decr lev (Abs (a, T, body)) = Abs (a, T, decr (lev + 1) body)
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   224
  | decr lev (t $ u) = (decr lev t $ decrh lev u handle SAME => t $ decr lev u)
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   225
  | decr _ _ = raise SAME
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   226
and decrh lev t = (decr lev t handle SAME => t);
20670
115262dd18e2 tuned eta_contract;
wenzelm
parents: 20548
diff changeset
   227
22174
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   228
fun eta (Abs (a, T, body)) =
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   229
    ((case eta body of
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   230
        body' as (f $ Bound 0) =>
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   231
          if loose_bvar1 (f, 0) then Abs (a, T, body')
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   232
          else decrh 0 f
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   233
     | body' => Abs (a, T, body')) handle SAME =>
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   234
        (case body of
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   235
          f $ Bound 0 =>
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   236
            if loose_bvar1 (f, 0) then raise SAME
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   237
            else decrh 0 f
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   238
        | _ => raise SAME))
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   239
  | eta (t $ u) = (eta t $ etah u handle SAME => t $ eta u)
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   240
  | eta _ = raise SAME
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   241
and etah t = (eta t handle SAME => t);
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   242
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   243
in
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   244
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   245
fun eta_contract t =
24670
9aae962b1d56 Term.has_abs;
wenzelm
parents: 22678
diff changeset
   246
  if Term.has_abs t then etah t else t;
18937
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
   247
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
   248
val beta_eta_contract = eta_contract o beta_norm;
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
   249
22174
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   250
end;
f2bf6bcd4a98 tuned eta_contract;
wenzelm
parents: 21795
diff changeset
   251
18937
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
   252
12231
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   253
(*finds type of term without checking that combinations are consistent
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   254
  Ts holds types of bound variables*)
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   255
fun fastype (Envir {iTs, ...}) =
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   256
let val funerr = "fastype: expected function type";
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   257
    fun fast Ts (f $ u) =
20670
115262dd18e2 tuned eta_contract;
wenzelm
parents: 20548
diff changeset
   258
        (case fast Ts f of
115262dd18e2 tuned eta_contract;
wenzelm
parents: 20548
diff changeset
   259
           Type ("fun", [_, T]) => T
115262dd18e2 tuned eta_contract;
wenzelm
parents: 20548
diff changeset
   260
         | TVar ixnS =>
26328
b2d6f520172c Type.lookup now curried
haftmann
parents: 25471
diff changeset
   261
                (case Type.lookup iTs ixnS of
20670
115262dd18e2 tuned eta_contract;
wenzelm
parents: 20548
diff changeset
   262
                   SOME (Type ("fun", [_, T])) => T
115262dd18e2 tuned eta_contract;
wenzelm
parents: 20548
diff changeset
   263
                 | _ => raise TERM (funerr, [f $ u]))
115262dd18e2 tuned eta_contract;
wenzelm
parents: 20548
diff changeset
   264
         | _ => raise TERM (funerr, [f $ u]))
12231
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   265
      | fast Ts (Const (_, T)) = T
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   266
      | fast Ts (Free (_, T)) = T
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   267
      | fast Ts (Bound i) =
20670
115262dd18e2 tuned eta_contract;
wenzelm
parents: 20548
diff changeset
   268
        (List.nth (Ts, i)
115262dd18e2 tuned eta_contract;
wenzelm
parents: 20548
diff changeset
   269
         handle Subscript => raise TERM ("fastype: Bound", [Bound i]))
115262dd18e2 tuned eta_contract;
wenzelm
parents: 20548
diff changeset
   270
      | fast Ts (Var (_, T)) = T
12231
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   271
      | fast Ts (Abs (_, T, u)) = T --> fast (T :: Ts) u
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   272
in fast end;
4a25f04bea61 Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents: 11513
diff changeset
   273
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   274
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   275
(*Substitute for type Vars in a type*)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   276
fun typ_subst_TVars iTs T = if Vartab.is_empty iTs then T else
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   277
  let fun subst(Type(a, Ts)) = Type(a, map subst Ts)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   278
        | subst(T as TFree _) = T
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   279
        | subst(T as TVar ixnS) =
26328
b2d6f520172c Type.lookup now curried
haftmann
parents: 25471
diff changeset
   280
            (case Type.lookup iTs ixnS of NONE => T | SOME(U) => U)
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   281
  in subst T end;
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   282
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   283
(*Substitute for type Vars in a term*)
20548
8ef25fe585a8 renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
wenzelm
parents: 20098
diff changeset
   284
val subst_TVars = map_types o typ_subst_TVars;
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   285
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   286
(*Substitute for Vars in a term *)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   287
fun subst_Vars itms t = if Vartab.is_empty itms then t else
18937
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
   288
  let fun subst (v as Var ixnT) = the_default v (lookup' (itms, ixnT))
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   289
        | subst (Abs (a, T, t)) = Abs (a, T, subst t)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   290
        | subst (f $ t) = subst f $ subst t
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   291
        | subst t = t
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   292
  in subst t end;
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   293
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   294
(*Substitute for type/term Vars in a term *)
16652
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
   295
fun subst_vars (iTs, itms) =
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   296
  if Vartab.is_empty iTs then subst_Vars itms else
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   297
  let fun subst (Const (a, T)) = Const(a, typ_subst_TVars iTs T)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   298
        | subst (Free (a, T)) = Free (a, typ_subst_TVars iTs T)
16652
4ecf94235ec7 Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents: 15797
diff changeset
   299
        | subst (Var (ixn, T)) = (case lookup' (itms, (ixn, T)) of
15797
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   300
            NONE   => Var (ixn, typ_subst_TVars iTs T)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   301
          | SOME t => t)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   302
        | subst (b as Bound _) = b
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   303
        | subst (Abs (a, T, t)) = Abs(a, typ_subst_TVars iTs T, subst t)
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   304
        | subst (f $ t) = subst f $ subst t
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   305
  in subst end;
a63605582573 - Eliminated nodup_vars check.
berghofe
parents: 15570
diff changeset
   306
18937
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
   307
21795
d7dcc3dfa7e9 added expand_term_frees;
wenzelm
parents: 21695
diff changeset
   308
(* expand defined atoms -- with local beta reduction *)
18937
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
   309
19422
bba26da0f227 expand_atom: Type.raw_match;
wenzelm
parents: 18937
diff changeset
   310
fun expand_atom T (U, u) =
bba26da0f227 expand_atom: Type.raw_match;
wenzelm
parents: 18937
diff changeset
   311
  subst_TVars (Type.raw_match (U, T) Vartab.empty) u
18937
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
   312
  handle Type.TYPE_MATCH => raise TYPE ("expand_atom: ill-typed replacement", [T, U], [u]);
0eb35519f0f3 added (beta_)eta_contract (from pattern.ML);
wenzelm
parents: 17412
diff changeset
   313
21795
d7dcc3dfa7e9 added expand_term_frees;
wenzelm
parents: 21695
diff changeset
   314
fun expand_term get =
21695
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   315
  let
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   316
    fun expand tm =
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   317
      let
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   318
        val (head, args) = Term.strip_comb tm;
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   319
        val args' = map expand args;
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   320
        fun comb head' = Term.list_comb (head', args');
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   321
      in
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   322
        (case head of
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   323
          Abs (x, T, t) => comb (Abs (x, T, expand t))
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   324
        | _ =>
21795
d7dcc3dfa7e9 added expand_term_frees;
wenzelm
parents: 21695
diff changeset
   325
            (case get head of
21695
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   326
              SOME def => Term.betapplys (expand_atom (Term.fastype_of head) def, args')
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   327
            | NONE => comb head)
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   328
        | _ => comb head)
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   329
      end;
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   330
  in expand end;
6c07cc87fe2b added expand_term;
wenzelm
parents: 20670
diff changeset
   331
21795
d7dcc3dfa7e9 added expand_term_frees;
wenzelm
parents: 21695
diff changeset
   332
fun expand_term_frees defs =
d7dcc3dfa7e9 added expand_term_frees;
wenzelm
parents: 21695
diff changeset
   333
  let
d7dcc3dfa7e9 added expand_term_frees;
wenzelm
parents: 21695
diff changeset
   334
    val eqs = map (fn ((x, U), u) => (x, (U, u))) defs;
d7dcc3dfa7e9 added expand_term_frees;
wenzelm
parents: 21695
diff changeset
   335
    val get = fn Free (x, _) => AList.lookup (op =) eqs x | _ => NONE;
d7dcc3dfa7e9 added expand_term_frees;
wenzelm
parents: 21695
diff changeset
   336
  in expand_term get end;
d7dcc3dfa7e9 added expand_term_frees;
wenzelm
parents: 21695
diff changeset
   337
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   338
end;