| author | wenzelm |
| Tue, 21 Sep 2021 12:08:41 +0200 | |
| changeset 74338 | 534b231ce041 |
| parent 74266 | 612b7e0d6721 |
| child 74576 | 0b43d42cfde7 |
| permissions | -rw-r--r-- |
| 20513 | 1 |
(* Title: Pure/term_subst.ML |
2 |
Author: Makarius |
|
3 |
||
| 32016 | 4 |
Efficient type/term substitution. |
| 20513 | 5 |
*) |
6 |
||
7 |
signature TERM_SUBST = |
|
8 |
sig |
|
| 32016 | 9 |
val map_atypsT_same: typ Same.operation -> typ Same.operation |
10 |
val map_types_same: typ Same.operation -> term Same.operation |
|
11 |
val map_aterms_same: term Same.operation -> term Same.operation |
|
| 74266 | 12 |
val generalizeT_same: Names.set -> int -> typ Same.operation |
13 |
val generalize_same: Names.set * Names.set -> int -> term Same.operation |
|
14 |
val generalizeT: Names.set -> int -> typ -> typ |
|
15 |
val generalize: Names.set * Names.set -> int -> term -> term |
|
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
16 |
val instantiateT_maxidx: (typ * int) TVars.table -> typ -> int -> typ * int |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
17 |
val instantiate_maxidx: (typ * int) TVars.table * (term * int) Vars.table -> |
| 20513 | 18 |
term -> int -> term * int |
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
19 |
val instantiateT_frees_same: typ TFrees.table -> typ Same.operation |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
20 |
val instantiate_frees_same: typ TFrees.table * term Frees.table -> term Same.operation |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
21 |
val instantiateT_frees: typ TFrees.table -> typ -> typ |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
22 |
val instantiate_frees: typ TFrees.table * term Frees.table -> term -> term |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
23 |
val instantiateT_same: typ TVars.table -> typ Same.operation |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
24 |
val instantiate_same: typ TVars.table * term Vars.table -> term Same.operation |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
25 |
val instantiateT: typ TVars.table -> typ -> typ |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
26 |
val instantiate: typ TVars.table * term Vars.table -> term -> term |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
27 |
val zero_var_indexes_inst: Name.context -> term list -> typ TVars.table * term Vars.table |
| 68234 | 28 |
val zero_var_indexes: term -> term |
29 |
val zero_var_indexes_list: term list -> term list |
|
| 20513 | 30 |
end; |
31 |
||
| 31977 | 32 |
structure Term_Subst: TERM_SUBST = |
| 20513 | 33 |
struct |
34 |
||
| 31980 | 35 |
(* generic mapping *) |
36 |
||
37 |
fun map_atypsT_same f = |
|
38 |
let |
|
| 32020 | 39 |
fun typ (Type (a, Ts)) = Type (a, Same.map typ Ts) |
40 |
| typ T = f T; |
|
| 31980 | 41 |
in typ end; |
42 |
||
43 |
fun map_types_same f = |
|
44 |
let |
|
45 |
fun term (Const (a, T)) = Const (a, f T) |
|
46 |
| term (Free (a, T)) = Free (a, f T) |
|
47 |
| term (Var (v, T)) = Var (v, f T) |
|
| 32020 | 48 |
| term (Bound _) = raise Same.SAME |
| 31980 | 49 |
| term (Abs (x, T, t)) = |
| 32016 | 50 |
(Abs (x, f T, Same.commit term t) |
51 |
handle Same.SAME => Abs (x, T, term t)) |
|
52 |
| term (t $ u) = (term t $ Same.commit term u handle Same.SAME => t $ term u); |
|
| 31980 | 53 |
in term end; |
54 |
||
55 |
fun map_aterms_same f = |
|
56 |
let |
|
57 |
fun term (Abs (x, T, t)) = Abs (x, T, term t) |
|
| 32016 | 58 |
| term (t $ u) = (term t $ Same.commit term u handle Same.SAME => t $ term u) |
| 31980 | 59 |
| term a = f a; |
60 |
in term end; |
|
61 |
||
62 |
||
| 20513 | 63 |
(* generalization of fixed variables *) |
64 |
||
|
74200
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
65 |
fun generalizeT_same tfrees idx ty = |
| 74266 | 66 |
if Names.is_empty tfrees then raise Same.SAME |
|
74200
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
67 |
else |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
68 |
let |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
69 |
fun gen (Type (a, Ts)) = Type (a, Same.map gen Ts) |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
70 |
| gen (TFree (a, S)) = |
| 74266 | 71 |
if Names.defined tfrees a then TVar ((a, idx), S) |
|
74200
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
72 |
else raise Same.SAME |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
73 |
| gen _ = raise Same.SAME; |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
74 |
in gen ty end; |
| 20513 | 75 |
|
|
74200
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
76 |
fun generalize_same (tfrees, frees) idx tm = |
| 74266 | 77 |
if Names.is_empty tfrees andalso Names.is_empty frees then raise Same.SAME |
|
74200
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
78 |
else |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
79 |
let |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
80 |
val genT = generalizeT_same tfrees idx; |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
81 |
fun gen (Free (x, T)) = |
| 74266 | 82 |
if Names.defined frees x then |
|
74200
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
83 |
Var (Name.clean_index (x, idx), Same.commit genT T) |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
84 |
else Free (x, genT T) |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
85 |
| gen (Var (xi, T)) = Var (xi, genT T) |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
86 |
| gen (Const (c, T)) = Const (c, genT T) |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
87 |
| gen (Bound _) = raise Same.SAME |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
88 |
| gen (Abs (x, T, t)) = |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
89 |
(Abs (x, genT T, Same.commit gen t) |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
90 |
handle Same.SAME => Abs (x, T, gen t)) |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
91 |
| gen (t $ u) = (gen t $ Same.commit gen u handle Same.SAME => t $ gen u); |
|
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
wenzelm
parents:
69023
diff
changeset
|
92 |
in gen tm end; |
| 20513 | 93 |
|
| 36766 | 94 |
fun generalizeT names i ty = Same.commit (generalizeT_same names i) ty; |
|
36620
e6bb250402b5
simplified/unified fundamental operations on types/terms/proofterms -- prefer Same.operation over "option" variant;
wenzelm
parents:
35408
diff
changeset
|
95 |
fun generalize names i tm = Same.commit (generalize_same names i) tm; |
| 20513 | 96 |
|
97 |
||
|
67698
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
45395
diff
changeset
|
98 |
(* instantiation of free variables (types before terms) *) |
|
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
45395
diff
changeset
|
99 |
|
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
100 |
fun instantiateT_frees_same instT ty = |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
101 |
if TFrees.is_empty instT then raise Same.SAME |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
102 |
else |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
103 |
let |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
104 |
fun subst (Type (a, Ts)) = Type (a, Same.map subst Ts) |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
105 |
| subst (TFree v) = |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
106 |
(case TFrees.lookup instT v of |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
107 |
SOME T => T |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
108 |
| NONE => raise Same.SAME) |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
109 |
| subst _ = raise Same.SAME; |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
110 |
in subst ty end; |
|
67698
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
45395
diff
changeset
|
111 |
|
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
112 |
fun instantiate_frees_same (instT, inst) tm = |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
113 |
if TFrees.is_empty instT andalso Frees.is_empty inst then raise Same.SAME |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
114 |
else |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
115 |
let |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
116 |
val substT = instantiateT_frees_same instT; |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
117 |
fun subst (Const (c, T)) = Const (c, substT T) |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
118 |
| subst (Free (x, T)) = |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
119 |
let val (T', same) = (substT T, false) handle Same.SAME => (T, true) in |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
120 |
(case Frees.lookup inst (x, T') of |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
121 |
SOME t => t |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
122 |
| NONE => if same then raise Same.SAME else Free (x, T')) |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
123 |
end |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
124 |
| subst (Var (xi, T)) = Var (xi, substT T) |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
125 |
| subst (Bound _) = raise Same.SAME |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
126 |
| subst (Abs (x, T, t)) = |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
127 |
(Abs (x, substT T, Same.commit subst t) |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
128 |
handle Same.SAME => Abs (x, T, subst t)) |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
129 |
| subst (t $ u) = (subst t $ Same.commit subst u handle Same.SAME => t $ subst u); |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
130 |
in subst tm end; |
|
67698
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
45395
diff
changeset
|
131 |
|
|
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
45395
diff
changeset
|
132 |
fun instantiateT_frees instT ty = Same.commit (instantiateT_frees_same instT) ty; |
|
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
45395
diff
changeset
|
133 |
fun instantiate_frees inst tm = Same.commit (instantiate_frees_same inst) tm; |
|
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
45395
diff
changeset
|
134 |
|
|
67caf783b9ee
explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents:
45395
diff
changeset
|
135 |
|
| 20513 | 136 |
(* instantiation of schematic variables (types before terms) -- recomputes maxidx *) |
137 |
||
138 |
local |
|
139 |
||
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
140 |
fun no_indexesT instT = TVars.map (fn _ => rpair ~1) instT; |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
141 |
fun no_indexes inst = Vars.map (fn _ => rpair ~1) inst; |
| 20513 | 142 |
|
|
36620
e6bb250402b5
simplified/unified fundamental operations on types/terms/proofterms -- prefer Same.operation over "option" variant;
wenzelm
parents:
35408
diff
changeset
|
143 |
fun instT_same maxidx instT ty = |
| 20513 | 144 |
let |
| 21184 | 145 |
fun maxify i = if i > ! maxidx then maxidx := i else (); |
146 |
||
| 20513 | 147 |
fun subst_typ (Type (a, Ts)) = Type (a, subst_typs Ts) |
148 |
| subst_typ (TVar ((a, i), S)) = |
|
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
149 |
(case TVars.lookup instT ((a, i), S) of |
| 20513 | 150 |
SOME (T, j) => (maxify j; T) |
| 32016 | 151 |
| NONE => (maxify i; raise Same.SAME)) |
152 |
| subst_typ _ = raise Same.SAME |
|
| 20513 | 153 |
and subst_typs (T :: Ts) = |
| 32016 | 154 |
(subst_typ T :: Same.commit subst_typs Ts |
155 |
handle Same.SAME => T :: subst_typs Ts) |
|
156 |
| subst_typs [] = raise Same.SAME; |
|
| 20513 | 157 |
in subst_typ ty end; |
158 |
||
|
36620
e6bb250402b5
simplified/unified fundamental operations on types/terms/proofterms -- prefer Same.operation over "option" variant;
wenzelm
parents:
35408
diff
changeset
|
159 |
fun inst_same maxidx (instT, inst) tm = |
| 20513 | 160 |
let |
| 21184 | 161 |
fun maxify i = if i > ! maxidx then maxidx := i else (); |
162 |
||
|
36620
e6bb250402b5
simplified/unified fundamental operations on types/terms/proofterms -- prefer Same.operation over "option" variant;
wenzelm
parents:
35408
diff
changeset
|
163 |
val substT = instT_same maxidx instT; |
| 20513 | 164 |
fun subst (Const (c, T)) = Const (c, substT T) |
165 |
| subst (Free (x, T)) = Free (x, substT T) |
|
166 |
| subst (Var ((x, i), T)) = |
|
| 32016 | 167 |
let val (T', same) = (substT T, false) handle Same.SAME => (T, true) in |
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
168 |
(case Vars.lookup inst ((x, i), T') of |
| 20513 | 169 |
SOME (t, j) => (maxify j; t) |
| 32016 | 170 |
| NONE => (maxify i; if same then raise Same.SAME else Var ((x, i), T'))) |
| 20513 | 171 |
end |
| 32016 | 172 |
| subst (Bound _) = raise Same.SAME |
| 20513 | 173 |
| subst (Abs (x, T, t)) = |
| 32016 | 174 |
(Abs (x, substT T, Same.commit subst t) |
175 |
handle Same.SAME => Abs (x, T, subst t)) |
|
176 |
| subst (t $ u) = (subst t $ Same.commit subst u handle Same.SAME => t $ subst u); |
|
| 20513 | 177 |
in subst tm end; |
178 |
||
179 |
in |
|
180 |
||
181 |
fun instantiateT_maxidx instT ty i = |
|
| 32738 | 182 |
let val maxidx = Unsynchronized.ref i |
|
36620
e6bb250402b5
simplified/unified fundamental operations on types/terms/proofterms -- prefer Same.operation over "option" variant;
wenzelm
parents:
35408
diff
changeset
|
183 |
in (Same.commit (instT_same maxidx instT) ty, ! maxidx) end; |
| 20513 | 184 |
|
185 |
fun instantiate_maxidx insts tm i = |
|
| 32738 | 186 |
let val maxidx = Unsynchronized.ref i |
|
36620
e6bb250402b5
simplified/unified fundamental operations on types/terms/proofterms -- prefer Same.operation over "option" variant;
wenzelm
parents:
35408
diff
changeset
|
187 |
in (Same.commit (inst_same maxidx insts) tm, ! maxidx) end; |
| 20513 | 188 |
|
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
189 |
fun instantiateT_same instT ty = |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
190 |
if TVars.is_empty instT then raise Same.SAME |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
191 |
else instT_same (Unsynchronized.ref ~1) (no_indexesT instT) ty; |
| 20513 | 192 |
|
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
193 |
fun instantiate_same (instT, inst) tm = |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
194 |
if TVars.is_empty instT andalso Vars.is_empty inst then raise Same.SAME |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
195 |
else inst_same (Unsynchronized.ref ~1) (no_indexesT instT, no_indexes inst) tm; |
| 20513 | 196 |
|
| 36766 | 197 |
fun instantiateT instT ty = Same.commit (instantiateT_same instT) ty; |
198 |
fun instantiate inst tm = Same.commit (instantiate_same inst) tm; |
|
199 |
||
| 20513 | 200 |
end; |
201 |
||
202 |
||
203 |
(* zero var indexes *) |
|
204 |
||
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
205 |
fun zero_var_inst ins mk (v as ((x, i), X)) (inst, used) = |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
206 |
let val (x', used') = Name.variant (if Name.is_bound x then "u" else x) used |
|
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
207 |
in if x = x' andalso i = 0 then (inst, used') else (ins (v, mk ((x', 0), X)) inst, used') end; |
| 20513 | 208 |
|
|
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
68234
diff
changeset
|
209 |
fun zero_var_indexes_inst used ts = |
| 20513 | 210 |
let |
|
45395
830c9b9b0d66
more scalable zero_var_indexes, depending on canonical order within table;
wenzelm
parents:
43326
diff
changeset
|
211 |
val (instT, _) = |
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
212 |
(TVars.empty, used) |> TVars.fold (zero_var_inst TVars.add TVar o #1) |
| 74232 | 213 |
(TVars.build (ts |> (fold o fold_types o fold_atyps) |
214 |
(fn TVar v => TVars.add (v, ()) | _ => I))); |
|
|
45395
830c9b9b0d66
more scalable zero_var_indexes, depending on canonical order within table;
wenzelm
parents:
43326
diff
changeset
|
215 |
val (inst, _) = |
|
74220
c49134ee16c1
more scalable data structure (but: rarely used many arguments);
wenzelm
parents:
74200
diff
changeset
|
216 |
(Vars.empty, used) |> Vars.fold (zero_var_inst Vars.add Var o #1) |
| 74232 | 217 |
(Vars.build (ts |> (fold o fold_aterms) |
218 |
(fn Var (xi, T) => Vars.add ((xi, instantiateT instT T), ()) | _ => I))); |
|
| 20513 | 219 |
in (instT, inst) end; |
220 |
||
|
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
68234
diff
changeset
|
221 |
fun zero_var_indexes_list ts = map (instantiate (zero_var_indexes_inst Name.context ts)) ts; |
| 68234 | 222 |
val zero_var_indexes = singleton zero_var_indexes_list; |
| 20513 | 223 |
|
224 |
end; |