159 val rename_wrt_term: term -> (string * typ) list -> (string * typ) list |
159 val rename_wrt_term: term -> (string * typ) list -> (string * typ) list |
160 val fold_atyps: (typ -> 'a -> 'a) -> typ -> 'a -> 'a |
160 val fold_atyps: (typ -> 'a -> 'a) -> typ -> 'a -> 'a |
161 val fold_aterms: (term -> 'a -> 'a) -> term -> 'a -> 'a |
161 val fold_aterms: (term -> 'a -> 'a) -> term -> 'a -> 'a |
162 val fold_term_types: (term -> typ -> 'a -> 'a) -> term -> 'a -> 'a |
162 val fold_term_types: (term -> typ -> 'a -> 'a) -> term -> 'a -> 'a |
163 val fold_types: (typ -> 'a -> 'a) -> term -> 'a -> 'a |
163 val fold_types: (typ -> 'a -> 'a) -> term -> 'a -> 'a |
164 val foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a |
|
165 val foldl_aterms: ('a * term -> 'a) -> 'a * term -> 'a |
|
166 val foldl_term_types: (term -> 'a * typ -> 'a) -> 'a * term -> 'a |
|
167 val foldl_types: ('a * typ -> 'a) -> 'a * term -> 'a |
|
168 val add_term_names: term * string list -> string list |
164 val add_term_names: term * string list -> string list |
169 val add_term_varnames: indexname list * term -> indexname list |
165 val add_term_varnames: term -> indexname list -> indexname list |
170 val term_varnames: term -> indexname list |
166 val term_varnames: term -> indexname list |
171 val compress_type: typ -> typ |
167 val compress_type: typ -> typ |
172 val compress_term: term -> term |
168 val compress_term: term -> term |
173 val show_question_marks: bool ref |
169 val show_question_marks: bool ref |
174 end; |
170 end; |
193 val maxidx_term: term -> int -> int |
189 val maxidx_term: term -> int -> int |
194 val invent_names: string list -> string -> int -> string list |
190 val invent_names: string list -> string -> int -> string list |
195 val map_typ: (string -> string) -> (string -> string) -> typ -> typ |
191 val map_typ: (string -> string) -> (string -> string) -> typ -> typ |
196 val map_term: (string -> string) -> (string -> string) -> (string -> string) -> term -> term |
192 val map_term: (string -> string) -> (string -> string) -> (string -> string) -> term -> term |
197 val dest_abs: string * typ * term -> string * term |
193 val dest_abs: string * typ * term -> string * term |
198 (*val add_tvarsT: typ -> (indexname * sort) list -> (indexname * sort) list |
194 val add_tvarsT: typ -> (indexname * sort) list -> (indexname * sort) list |
199 val add_tvars: term -> (indexname * sort) list -> (indexname * sort) list |
195 val add_tvars: term -> (indexname * sort) list -> (indexname * sort) list |
200 val add_vars: (indexname * typ) list * term -> (indexname * typ) list |
196 val add_vars: term -> (indexname * typ) list -> (indexname * typ) list |
201 val add_frees: (string * typ) list * term -> (string * typ) list*) |
197 val add_frees: term -> (string * typ) list -> (string * typ) list |
202 val add_tvarsT: (indexname * sort) list * typ -> (indexname * sort) list |
|
203 val add_tvars: (indexname * sort) list * term -> (indexname * sort) list |
|
204 val add_vars: (indexname * typ) list * term -> (indexname * typ) list |
|
205 val add_frees: (string * typ) list * term -> (string * typ) list |
|
206 val dummy_patternN: string |
198 val dummy_patternN: string |
207 val no_dummy_patterns: term -> term |
199 val no_dummy_patterns: term -> term |
208 val replace_dummy_patterns: int * term -> int * term |
200 val replace_dummy_patterns: int * term -> int * term |
209 val is_replaced_dummy_pattern: indexname -> bool |
201 val is_replaced_dummy_pattern: indexname -> bool |
210 val show_dummy_patterns: term -> term |
202 val show_dummy_patterns: term -> term |
1195 |
1187 |
1196 (* left-ro-right traversal *) |
1188 (* left-ro-right traversal *) |
1197 |
1189 |
1198 (*fold atoms of type*) |
1190 (*fold atoms of type*) |
1199 fun fold_atyps f (Type (_, Ts)) = fold (fold_atyps f) Ts |
1191 fun fold_atyps f (Type (_, Ts)) = fold (fold_atyps f) Ts |
1200 | fold_atyps f T = f T |
1192 | fold_atyps f T = f T; |
1201 |
1193 |
1202 (*fold atoms of term*) |
1194 (*fold atoms of term*) |
1203 fun fold_aterms f (t $ u) = (fold_aterms f u) o (fold_aterms f t) |
1195 fun fold_aterms f (t $ u) = fold_aterms f t #> fold_aterms f u |
1204 | fold_aterms f (Abs (_, _, t)) = fold_aterms f t |
1196 | fold_aterms f (Abs (_, _, t)) = fold_aterms f t |
1205 | fold_aterms f t = f t; |
1197 | fold_aterms f a = f a; |
1206 |
1198 |
1207 (*fold types of term*) |
1199 (*fold types of term*) |
1208 fun fold_term_types f (t as Const (_, T)) = f t T |
1200 fun fold_term_types f (t as Const (_, T)) = f t T |
1209 | fold_term_types f (t as Free (_, T)) = f t T |
1201 | fold_term_types f (t as Free (_, T)) = f t T |
1210 | fold_term_types f (t as Var (_, T)) = f t T |
1202 | fold_term_types f (t as Var (_, T)) = f t T |
1211 | fold_term_types f (Bound _) = I |
1203 | fold_term_types f (Bound _) = I |
1212 | fold_term_types f (t as Abs (_, T, b)) = (fold_term_types f b) o (f t T) |
1204 | fold_term_types f (t as Abs (_, T, b)) = f t T #> fold_term_types f b |
1213 | fold_term_types f (t $ u) = (fold_term_types f u) o (fold_term_types f t); |
1205 | fold_term_types f (t $ u) = fold_term_types f t #> fold_term_types f u; |
1214 |
1206 |
1215 fun fold_types f = fold_term_types (fn _ => f); |
1207 fun fold_types f = fold_term_types (K f); |
1216 |
1208 |
1217 (*foldl atoms of type*) |
1209 (*collect variables*) |
1218 fun foldl_atyps f (x, Type (_, Ts)) = Library.foldl (foldl_atyps f) (x, Ts) |
1210 val add_tvarsT = fold_atyps (fn TVar v => insert (op =) v | _ => I); |
1219 | foldl_atyps f x_atom = f x_atom; |
|
1220 |
|
1221 (*foldl atoms of term*) |
|
1222 fun foldl_aterms f (x, t $ u) = foldl_aterms f (foldl_aterms f (x, t), u) |
|
1223 | foldl_aterms f (x, Abs (_, _, t)) = foldl_aterms f (x, t) |
|
1224 | foldl_aterms f x_atom = f x_atom; |
|
1225 |
|
1226 (*foldl types of term*) |
|
1227 fun foldl_term_types f (x, t as Const (_, T)) = f t (x, T) |
|
1228 | foldl_term_types f (x, t as Free (_, T)) = f t (x, T) |
|
1229 | foldl_term_types f (x, t as Var (_, T)) = f t (x, T) |
|
1230 | foldl_term_types f (x, Bound _) = x |
|
1231 | foldl_term_types f (x, t as Abs (_, T, b)) = foldl_term_types f (f t (x, T), b) |
|
1232 | foldl_term_types f (x, t $ u) = foldl_term_types f (foldl_term_types f (x, t), u); |
|
1233 |
|
1234 fun foldl_types f = foldl_term_types (fn _ => f); |
|
1235 |
|
1236 (*(*collect variables*) |
|
1237 val add_tvarsT = |
|
1238 let fun add_tvarsT' (TVar v) = insert (op =) v |
|
1239 | add_tvarsT' _ = I |
|
1240 in fold_atyps add_tvarsT' end; |
|
1241 val add_tvars = fold_types add_tvarsT; |
1211 val add_tvars = fold_types add_tvarsT; |
1242 val add_vars = |
1212 val add_vars = fold_aterms (fn Var v => insert (op =) v | _ => I); |
1243 let fun add_vars' (Var v) = insert (op =) v |
1213 val add_frees = fold_aterms (fn Free v => insert (op =) v | _ => I); |
1244 | add_vars' _ = I |
|
1245 in uncurry (fold_aterms add_vars') o swap end; |
|
1246 val add_frees = |
|
1247 let fun add_frees' (Free v) = insert (op =) v |
|
1248 | add_frees' _ = I |
|
1249 in uncurry (fold_aterms add_frees') o swap end; |
|
1250 |
1214 |
1251 (*collect variable names*) |
1215 (*collect variable names*) |
1252 val add_term_varnames = |
1216 val add_term_varnames = fold_aterms (fn Var (xi, _) => insert (op =) xi | _ => I); |
1253 let fun add_term_varnames' (Var (x, _)) xs = ins_ix (x, xs) |
1217 fun term_varnames t = add_term_varnames t []; |
1254 | add_term_varnames' _ xs = xs |
|
1255 in uncurry (fold_aterms add_term_varnames') o swap end; |
|
1256 |
|
1257 fun term_varnames t = add_term_varnames ([], t);*) |
|
1258 |
|
1259 (*collect variables*) |
|
1260 val add_tvarsT = foldl_atyps (fn (vs, TVar v) => insert (op =) v vs | (vs, _) => vs); |
|
1261 val add_tvars = foldl_types add_tvarsT; |
|
1262 val add_vars = foldl_aterms (fn (vs, Var v) => insert (op =) v vs | (vs, _) => vs); |
|
1263 val add_frees = foldl_aterms (fn (vs, Free v) => insert (op =) v vs | (vs, _) => vs); |
|
1264 |
|
1265 (*collect variable names*) |
|
1266 val add_term_varnames = foldl_aterms (fn (xs, Var (x, _)) => ins_ix (x, xs) | (xs, _) => xs); |
|
1267 fun term_varnames t = add_term_varnames ([], t); |
|
1268 |
1218 |
1269 |
1219 |
1270 |
1220 |
1271 (*** Compression of terms and types by sharing common subtrees. |
1221 (*** Compression of terms and types by sharing common subtrees. |
1272 Saves 50-75% on storage requirements. As it is a bit slow, |
1222 Saves 50-75% on storage requirements. As it is a bit slow, |