| author | oheimb | 
| Thu, 15 Feb 2001 16:00:35 +0100 | |
| changeset 11133 | 7c66f3dc7d14 | 
| parent 10806 | 2eba1c06592c | 
| child 11353 | 7f6eff7bc97a | 
| permissions | -rw-r--r-- | 
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1 | (* Title: Pure/term.ML | 
| 0 | 2 | ID: $Id$ | 
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 3 | Author: Lawrence C Paulson, Cambridge University Computer Laboratory | 
| 0 | 4 | Copyright Cambridge University 1992 | 
| 1364 
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
 clasohm parents: 
1029diff
changeset | 5 | |
| 4444 | 6 | Simply typed lambda-calculus: types, terms, and basic operations. | 
| 0 | 7 | *) | 
| 8 | ||
| 1364 
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
 clasohm parents: 
1029diff
changeset | 9 | infix 9 $; | 
| 
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
 clasohm parents: 
1029diff
changeset | 10 | infixr 5 -->; | 
| 4444 | 11 | infixr --->; | 
| 12 | infix aconv; | |
| 1364 
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
 clasohm parents: 
1029diff
changeset | 13 | |
| 4444 | 14 | signature BASIC_TERM = | 
| 15 | sig | |
| 16 | type indexname | |
| 17 | type class | |
| 18 | type sort | |
| 19 | datatype typ = | |
| 20 | Type of string * typ list | | |
| 21 | TFree of string * sort | | |
| 22 | TVar of indexname * sort | |
| 23 | val --> : typ * typ -> typ | |
| 24 | val ---> : typ list * typ -> typ | |
| 25 | val is_TVar: typ -> bool | |
| 26 | val domain_type: typ -> typ | |
| 4480 | 27 | val range_type: typ -> typ | 
| 4444 | 28 | val binder_types: typ -> typ list | 
| 29 | val body_type: typ -> typ | |
| 30 | val strip_type: typ -> typ list * typ | |
| 31 | datatype term = | |
| 32 | Const of string * typ | | |
| 33 | Free of string * typ | | |
| 34 | Var of indexname * typ | | |
| 35 | Bound of int | | |
| 36 | Abs of string * typ * term | | |
| 4493 | 37 | $ of term * term | 
| 8408 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 38 | structure Vartab : TABLE | 
| 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 39 | structure Termtab : TABLE | 
| 4444 | 40 | exception TYPE of string * typ list * term list | 
| 41 | exception TERM of string * term list | |
| 7318 | 42 | val is_Bound: term -> bool | 
| 4444 | 43 | val is_Const: term -> bool | 
| 44 | val is_Free: term -> bool | |
| 45 | val is_Var: term -> bool | |
| 6033 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 46 | val dest_Type: typ -> string * typ list | 
| 4444 | 47 | val dest_Const: term -> string * typ | 
| 48 | val dest_Free: term -> string * typ | |
| 49 | val dest_Var: term -> indexname * typ | |
| 50 | val type_of: term -> typ | |
| 51 | val type_of1: typ list * term -> typ | |
| 52 | val fastype_of: term -> typ | |
| 53 | val fastype_of1: typ list * term -> typ | |
| 10806 | 54 | val list_abs: (string * typ) list * term -> term | 
| 4444 | 55 | val strip_abs_body: term -> term | 
| 56 | val strip_abs_vars: term -> (string * typ) list | |
| 57 | val strip_qnt_body: string -> term -> term | |
| 58 | val strip_qnt_vars: string -> term -> (string * typ) list | |
| 59 | val list_comb: term * term list -> term | |
| 60 | val strip_comb: term -> term * term list | |
| 61 | val head_of: term -> term | |
| 62 | val size_of_term: term -> int | |
| 63 | val map_type_tvar: (indexname * sort -> typ) -> typ -> typ | |
| 64 | val map_type_tfree: (string * sort -> typ) -> typ -> typ | |
| 65 | val map_term_types: (typ -> typ) -> term -> term | |
| 66 | val it_term_types: (typ * 'a -> 'a) -> term * 'a -> 'a | |
| 67 | val map_typ: (class -> class) -> (string -> string) -> typ -> typ | |
| 68 | val map_term: | |
| 69 | (class -> class) -> | |
| 70 | (string -> string) -> (string -> string) -> term -> term | |
| 71 |   val foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a
 | |
| 8609 | 72 | val foldl_term_types: (term -> 'a * typ -> 'a) -> 'a * term -> 'a | 
| 4444 | 73 |   val foldl_types: ('a * typ -> 'a) -> 'a * term -> 'a
 | 
| 74 |   val foldl_aterms: ('a * term -> 'a) -> 'a * term -> 'a
 | |
| 6548 
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
 wenzelm parents: 
6033diff
changeset | 75 |   val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term
 | 
| 4444 | 76 | val dummyT: typ | 
| 77 | val logicC: class | |
| 78 | val logicS: sort | |
| 79 | val itselfT: typ -> typ | |
| 80 | val a_itselfT: typ | |
| 81 | val propT: typ | |
| 82 | val implies: term | |
| 83 | val all: typ -> term | |
| 84 | val equals: typ -> term | |
| 85 | val flexpair: typ -> term | |
| 86 | val strip_all_body: term -> term | |
| 87 | val strip_all_vars: term -> (string * typ) list | |
| 88 | val incr_bv: int * int * term -> term | |
| 89 | val incr_boundvars: int -> term -> term | |
| 90 | val add_loose_bnos: term * int * int list -> int list | |
| 91 | val loose_bnos: term -> int list | |
| 92 | val loose_bvar: term * int -> bool | |
| 93 | val loose_bvar1: term * int -> bool | |
| 94 | val subst_bounds: term list * term -> term | |
| 95 | val subst_bound: term * term -> term | |
| 96 | val subst_TVars: (indexname * typ) list -> term -> term | |
| 8408 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 97 | val subst_TVars_Vartab: typ Vartab.table -> term -> term | 
| 4444 | 98 | val betapply: term * term -> term | 
| 99 | val eq_ix: indexname * indexname -> bool | |
| 100 | val ins_ix: indexname * indexname list -> indexname list | |
| 101 | val mem_ix: indexname * indexname list -> bool | |
| 102 | val eq_sort: sort * class list -> bool | |
| 103 | val mem_sort: sort * class list list -> bool | |
| 104 | val subset_sort: sort list * class list list -> bool | |
| 105 | val eq_set_sort: sort list * sort list -> bool | |
| 106 | val ins_sort: sort * class list list -> class list list | |
| 107 | val union_sort: sort list * sort list -> sort list | |
| 7638 | 108 | val rems_sort: sort list * sort list -> sort list | 
| 4444 | 109 | val aconv: term * term -> bool | 
| 110 | val aconvs: term list * term list -> bool | |
| 111 | val mem_term: term * term list -> bool | |
| 112 | val subset_term: term list * term list -> bool | |
| 113 | val eq_set_term: term list * term list -> bool | |
| 114 | val ins_term: term * term list -> term list | |
| 115 | val union_term: term list * term list -> term list | |
| 5585 | 116 | val inter_term: term list * term list -> term list | 
| 4444 | 117 | val could_unify: term * term -> bool | 
| 118 | val subst_free: (term * term) list -> term -> term | |
| 119 | val subst_atomic: (term * term) list -> term -> term | |
| 120 | val subst_vars: (indexname * typ) list * (indexname * term) list -> term -> term | |
| 121 | val typ_subst_TVars: (indexname * typ) list -> typ -> typ | |
| 8408 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 122 | val typ_subst_TVars_Vartab : typ Vartab.table -> typ -> typ | 
| 4444 | 123 | val subst_Vars: (indexname * term) list -> term -> term | 
| 124 | val incr_tvar: int -> typ -> typ | |
| 125 | val xless: (string * int) * indexname -> bool | |
| 126 | val atless: term * term -> bool | |
| 127 | val insert_aterm: term * term list -> term list | |
| 128 | val abstract_over: term * term -> term | |
| 129 | val absfree: string * typ * term -> term | |
| 130 | val list_abs_free: (string * typ) list * term -> term | |
| 131 | val list_all_free: (string * typ) list * term -> term | |
| 132 | val list_all: (string * typ) list * term -> term | |
| 133 | val maxidx_of_typ: typ -> int | |
| 134 | val maxidx_of_typs: typ list -> int | |
| 135 | val maxidx_of_term: term -> int | |
| 4694 | 136 | val read_radixint: int * string list -> int * string list | 
| 137 | val read_int: string list -> int * string list | |
| 5986 | 138 | val oct_char: string -> string | 
| 4444 | 139 | val variant: string list -> string -> string | 
| 140 | val variantlist: string list * string list -> string list | |
| 141 | val variant_abs: string * typ * term -> string * term | |
| 142 | val rename_wrt_term: term -> (string * typ) list -> (string * typ) list | |
| 143 | val add_new_id: string list * string -> string list | |
| 144 | val add_typ_classes: typ * class list -> class list | |
| 145 | val add_typ_ixns: indexname list * typ -> indexname list | |
| 146 | val add_typ_tfree_names: typ * string list -> string list | |
| 147 | val add_typ_tfrees: typ * (string * sort) list -> (string * sort) list | |
| 148 | val typ_tfrees: typ -> (string * sort) list | |
| 149 | val add_typ_tvars: typ * (indexname * sort) list -> (indexname * sort) list | |
| 150 | val typ_tvars: typ -> (indexname * sort) list | |
| 151 | val add_typ_tycons: typ * string list -> string list | |
| 152 | val add_typ_varnames: typ * string list -> string list | |
| 153 | val add_term_classes: term * class list -> class list | |
| 154 | val add_term_consts: term * string list -> string list | |
| 155 | val add_term_frees: term * term list -> term list | |
| 156 | val term_frees: term -> term list | |
| 157 | val add_term_names: term * string list -> string list | |
| 158 | val add_term_tfree_names: term * string list -> string list | |
| 159 | val add_term_tfrees: term * (string * sort) list -> (string * sort) list | |
| 160 | val term_tfrees: term -> (string * sort) list | |
| 161 | val add_term_tvar_ixns: term * indexname list -> indexname list | |
| 162 | val add_term_tvarnames: term * string list -> string list | |
| 163 | val add_term_tvars: term * (indexname * sort) list -> (indexname * sort) list | |
| 164 | val term_tvars: term -> (indexname * sort) list | |
| 165 | val add_term_tycons: term * string list -> string list | |
| 166 | val add_term_vars: term * term list -> term list | |
| 167 | val term_vars: term -> term list | |
| 168 | val exists_Const: (string * typ -> bool) -> term -> bool | |
| 4631 | 169 | val exists_subterm: (term -> bool) -> term -> bool | 
| 4444 | 170 | val compress_type: typ -> typ | 
| 171 | val compress_term: term -> term | |
| 172 | end; | |
| 0 | 173 | |
| 4444 | 174 | signature TERM = | 
| 175 | sig | |
| 176 | include BASIC_TERM | |
| 177 | val indexname_ord: indexname * indexname -> order | |
| 178 | val typ_ord: typ * typ -> order | |
| 179 | val typs_ord: typ list * typ list -> order | |
| 180 | val term_ord: term * term -> order | |
| 181 | val terms_ord: term list * term list -> order | |
| 182 | val termless: term * term -> bool | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 183 | val dummy_patternN: string | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 184 | val no_dummy_patterns: term -> term | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 185 | val replace_dummy_patterns: int * term -> int * term | 
| 10552 | 186 | val is_replaced_dummy_pattern: indexname -> bool | 
| 4444 | 187 | end; | 
| 188 | ||
| 189 | structure Term: TERM = | |
| 1364 
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
 clasohm parents: 
1029diff
changeset | 190 | struct | 
| 0 | 191 | |
| 192 | (*Indexnames can be quickly renamed by adding an offset to the integer part, | |
| 193 | for resolution.*) | |
| 194 | type indexname = string*int; | |
| 195 | ||
| 4626 | 196 | (* Types are classified by sorts. *) | 
| 0 | 197 | type class = string; | 
| 198 | type sort = class list; | |
| 199 | ||
| 200 | (* The sorts attached to TFrees and TVars specify the sort of that variable *) | |
| 201 | datatype typ = Type of string * typ list | |
| 202 | | TFree of string * sort | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 203 | | TVar of indexname * sort; | 
| 0 | 204 | |
| 6033 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 205 | (*Terms. Bound variables are indicated by depth number. | 
| 0 | 206 | Free variables, (scheme) variables and constants have names. | 
| 4626 | 207 | An term is "closed" if every bound variable of level "lev" | 
| 0 | 208 | is enclosed by at least "lev" abstractions. | 
| 209 | ||
| 210 | It is possible to create meaningless terms containing loose bound vars | |
| 211 | or type mismatches. But such terms are not allowed in rules. *) | |
| 212 | ||
| 213 | ||
| 214 | ||
| 215 | datatype term = | |
| 216 | Const of string * typ | |
| 217 | | Free of string * typ | |
| 218 | | Var of indexname * typ | |
| 219 | | Bound of int | |
| 220 | | Abs of string*typ*term | |
| 3965 | 221 | | op $ of term*term; | 
| 0 | 222 | |
| 223 | ||
| 224 | (*For errors involving type mismatches*) | |
| 225 | exception TYPE of string * typ list * term list; | |
| 226 | ||
| 227 | (*For system errors involving terms*) | |
| 228 | exception TERM of string * term list; | |
| 229 | ||
| 230 | ||
| 231 | (*Note variable naming conventions! | |
| 232 | a,b,c: string | |
| 233 | f,g,h: functions (including terms of function type) | |
| 234 | i,j,m,n: int | |
| 235 | t,u: term | |
| 236 | v,w: indexnames | |
| 237 | x,y: any | |
| 238 | A,B,C: term (denoting formulae) | |
| 239 | T,U: typ | |
| 240 | *) | |
| 241 | ||
| 242 | ||
| 6033 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 243 | (** Types **) | 
| 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 244 | |
| 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 245 | fun S --> T = Type("fun",[S,T]);
 | 
| 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 246 | |
| 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 247 | (*handy for multiple args: [T1,...,Tn]--->T gives T1-->(T2--> ... -->T)*) | 
| 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 248 | val op ---> = foldr (op -->); | 
| 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 249 | |
| 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 250 | fun dest_Type (Type x) = x | 
| 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 251 |   | dest_Type T = raise TYPE ("dest_Type", [T], []);
 | 
| 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 252 | |
| 
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
 paulson parents: 
5986diff
changeset | 253 | |
| 0 | 254 | (** Discriminators **) | 
| 255 | ||
| 7318 | 256 | fun is_Bound (Bound _) = true | 
| 257 | | is_Bound _ = false; | |
| 258 | ||
| 0 | 259 | fun is_Const (Const _) = true | 
| 260 | | is_Const _ = false; | |
| 261 | ||
| 262 | fun is_Free (Free _) = true | |
| 263 | | is_Free _ = false; | |
| 264 | ||
| 265 | fun is_Var (Var _) = true | |
| 266 | | is_Var _ = false; | |
| 267 | ||
| 268 | fun is_TVar (TVar _) = true | |
| 269 | | is_TVar _ = false; | |
| 270 | ||
| 271 | (** Destructors **) | |
| 272 | ||
| 273 | fun dest_Const (Const x) = x | |
| 274 |   | dest_Const t = raise TERM("dest_Const", [t]);
 | |
| 275 | ||
| 276 | fun dest_Free (Free x) = x | |
| 277 |   | dest_Free t = raise TERM("dest_Free", [t]);
 | |
| 278 | ||
| 279 | fun dest_Var (Var x) = x | |
| 280 |   | dest_Var t = raise TERM("dest_Var", [t]);
 | |
| 281 | ||
| 282 | ||
| 4464 | 283 | fun domain_type (Type("fun", [T,_])) = T
 | 
| 284 | and range_type  (Type("fun", [_,T])) = T;
 | |
| 4064 | 285 | |
| 0 | 286 | (* maps [T1,...,Tn]--->T to the list [T1,T2,...,Tn]*) | 
| 287 | fun binder_types (Type("fun",[S,T])) = S :: binder_types T
 | |
| 288 | | binder_types _ = []; | |
| 289 | ||
| 290 | (* maps [T1,...,Tn]--->T to T*) | |
| 291 | fun body_type (Type("fun",[S,T])) = body_type T
 | |
| 292 | | body_type T = T; | |
| 293 | ||
| 294 | (* maps [T1,...,Tn]--->T to ([T1,T2,...,Tn], T) *) | |
| 295 | fun strip_type T : typ list * typ = | |
| 296 | (binder_types T, body_type T); | |
| 297 | ||
| 298 | ||
| 299 | (*Compute the type of the term, checking that combinations are well-typed | |
| 300 | Ts = [T0,T1,...] holds types of bound variables 0, 1, ...*) | |
| 301 | fun type_of1 (Ts, Const (_,T)) = T | |
| 302 | | type_of1 (Ts, Free (_,T)) = T | |
| 303 | | type_of1 (Ts, Bound i) = (nth_elem (i,Ts) | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 304 |         handle LIST _ => raise TYPE("type_of: bound variable", [], [Bound i]))
 | 
| 0 | 305 | | type_of1 (Ts, Var (_,T)) = T | 
| 306 | | type_of1 (Ts, Abs (_,T,body)) = T --> type_of1(T::Ts, body) | |
| 307 | | type_of1 (Ts, f$u) = | |
| 308 | let val U = type_of1(Ts,u) | |
| 309 | and T = type_of1(Ts,f) | |
| 310 | in case T of | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 311 |             Type("fun",[T1,T2]) =>
 | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 312 | if T1=U then T2 else raise TYPE | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 313 |                     ("type_of: type mismatch in application", [T1,U], [f$u])
 | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 314 | | _ => raise TYPE | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 315 |                     ("type_of: function type is expected in application",
 | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 316 | [T,U], [f$u]) | 
| 0 | 317 | end; | 
| 318 | ||
| 319 | fun type_of t : typ = type_of1 ([],t); | |
| 320 | ||
| 321 | (*Determines the type of a term, with minimal checking*) | |
| 61 | 322 | fun fastype_of1 (Ts, f$u) = | 
| 323 | (case fastype_of1 (Ts,f) of | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 324 |         Type("fun",[_,T]) => T
 | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 325 |         | _ => raise TERM("fastype_of: expected function type", [f$u]))
 | 
| 61 | 326 | | fastype_of1 (_, Const (_,T)) = T | 
| 327 | | fastype_of1 (_, Free (_,T)) = T | |
| 328 | | fastype_of1 (Ts, Bound i) = (nth_elem(i,Ts) | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 329 |          handle LIST _ => raise TERM("fastype_of: Bound", [Bound i]))
 | 
| 61 | 330 | | fastype_of1 (_, Var (_,T)) = T | 
| 331 | | fastype_of1 (Ts, Abs (_,T,u)) = T --> fastype_of1 (T::Ts, u); | |
| 332 | ||
| 333 | fun fastype_of t : typ = fastype_of1 ([],t); | |
| 0 | 334 | |
| 335 | ||
| 10806 | 336 | val list_abs = foldr (fn ((x, T), t) => Abs (x, T, t)); | 
| 337 | ||
| 0 | 338 | (* maps (x1,...,xn)t to t *) | 
| 339 | fun strip_abs_body (Abs(_,_,t)) = strip_abs_body t | |
| 340 | | strip_abs_body u = u; | |
| 341 | ||
| 342 | (* maps (x1,...,xn)t to [x1, ..., xn] *) | |
| 343 | fun strip_abs_vars (Abs(a,T,t)) = (a,T) :: strip_abs_vars t | |
| 344 | | strip_abs_vars u = [] : (string*typ) list; | |
| 345 | ||
| 346 | ||
| 347 | fun strip_qnt_body qnt = | |
| 348 | let fun strip(tm as Const(c,_)$Abs(_,_,t)) = if c=qnt then strip t else tm | |
| 349 | | strip t = t | |
| 350 | in strip end; | |
| 351 | ||
| 352 | fun strip_qnt_vars qnt = | |
| 353 | let fun strip(Const(c,_)$Abs(a,T,t)) = if c=qnt then (a,T)::strip t else [] | |
| 354 | | strip t = [] : (string*typ) list | |
| 355 | in strip end; | |
| 356 | ||
| 357 | ||
| 358 | (* maps (f, [t1,...,tn]) to f(t1,...,tn) *) | |
| 359 | val list_comb : term * term list -> term = foldl (op $); | |
| 360 | ||
| 361 | ||
| 362 | (* maps f(t1,...,tn) to (f, [t1,...,tn]) ; naturally tail-recursive*) | |
| 363 | fun strip_comb u : term * term list = | |
| 364 | let fun stripc (f$t, ts) = stripc (f, t::ts) | |
| 365 | | stripc x = x | |
| 366 | in stripc(u,[]) end; | |
| 367 | ||
| 368 | ||
| 369 | (* maps f(t1,...,tn) to f , which is never a combination *) | |
| 370 | fun head_of (f$t) = head_of f | |
| 371 | | head_of u = u; | |
| 372 | ||
| 373 | ||
| 374 | (*Number of atoms and abstractions in a term*) | |
| 375 | fun size_of_term (Abs (_,_,body)) = 1 + size_of_term body | |
| 376 | | size_of_term (f$t) = size_of_term f + size_of_term t | |
| 377 | | size_of_term _ = 1; | |
| 378 | ||
| 949 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 379 | fun map_type_tvar f (Type(a,Ts)) = Type(a, map (map_type_tvar f) Ts) | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 380 | | map_type_tvar f (T as TFree _) = T | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 381 | | map_type_tvar f (TVar x) = f x; | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 382 | |
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 383 | fun map_type_tfree f (Type(a,Ts)) = Type(a, map (map_type_tfree f) Ts) | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 384 | | map_type_tfree f (TFree x) = f x | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 385 | | map_type_tfree f (T as TVar _) = T; | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 386 | |
| 0 | 387 | (* apply a function to all types in a term *) | 
| 388 | fun map_term_types f = | |
| 389 | let fun map(Const(a,T)) = Const(a, f T) | |
| 390 | | map(Free(a,T)) = Free(a, f T) | |
| 391 | | map(Var(v,T)) = Var(v, f T) | |
| 392 | | map(t as Bound _) = t | |
| 393 | | map(Abs(a,T,t)) = Abs(a, f T, map t) | |
| 394 | | map(f$t) = map f $ map t; | |
| 395 | in map end; | |
| 396 | ||
| 397 | (* iterate a function over all types in a term *) | |
| 398 | fun it_term_types f = | |
| 399 | let fun iter(Const(_,T), a) = f(T,a) | |
| 400 | | iter(Free(_,T), a) = f(T,a) | |
| 401 | | iter(Var(_,T), a) = f(T,a) | |
| 402 | | iter(Abs(_,T,t), a) = iter(t,f(T,a)) | |
| 403 | | iter(f$u, a) = iter(f, iter(u, a)) | |
| 404 | | iter(Bound _, a) = a | |
| 405 | in iter end | |
| 406 | ||
| 407 | ||
| 408 | (** Connectives of higher order logic **) | |
| 409 | ||
| 375 | 410 | val logicC: class = "logic"; | 
| 411 | val logicS: sort = [logicC]; | |
| 412 | ||
| 413 | fun itselfT ty = Type ("itself", [ty]);
 | |
| 414 | val a_itselfT = itselfT (TFree ("'a", logicS));
 | |
| 415 | ||
| 0 | 416 | val propT : typ = Type("prop",[]);
 | 
| 417 | ||
| 418 | val implies = Const("==>", propT-->propT-->propT);
 | |
| 419 | ||
| 420 | fun all T = Const("all", (T-->propT)-->propT);
 | |
| 421 | ||
| 422 | fun equals T = Const("==", T-->T-->propT);
 | |
| 423 | ||
| 424 | fun flexpair T = Const("=?=", T-->T-->propT);
 | |
| 425 | ||
| 426 | (* maps !!x1...xn. t to t *) | |
| 427 | fun strip_all_body (Const("all",_)$Abs(_,_,t))  =  strip_all_body t  
 | |
| 428 | | strip_all_body t = t; | |
| 429 | ||
| 430 | (* maps !!x1...xn. t to [x1, ..., xn] *) | |
| 431 | fun strip_all_vars (Const("all",_)$Abs(a,T,t))  =
 | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 432 | (a,T) :: strip_all_vars t | 
| 0 | 433 | | strip_all_vars t = [] : (string*typ) list; | 
| 434 | ||
| 435 | (*increments a term's non-local bound variables | |
| 436 | required when moving a term within abstractions | |
| 437 | inc is increment for bound variables | |
| 438 | lev is level at which a bound variable is considered 'loose'*) | |
| 439 | fun incr_bv (inc, lev, u as Bound i) = if i>=lev then Bound(i+inc) else u | |
| 440 | | incr_bv (inc, lev, Abs(a,T,body)) = | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 441 | Abs(a, T, incr_bv(inc,lev+1,body)) | 
| 0 | 442 | | incr_bv (inc, lev, f$t) = | 
| 443 | incr_bv(inc,lev,f) $ incr_bv(inc,lev,t) | |
| 444 | | incr_bv (inc, lev, u) = u; | |
| 445 | ||
| 446 | fun incr_boundvars 0 t = t | |
| 447 | | incr_boundvars inc t = incr_bv(inc,0,t); | |
| 448 | ||
| 449 | ||
| 450 | (*Accumulate all 'loose' bound vars referring to level 'lev' or beyond. | |
| 451 | (Bound 0) is loose at level 0 *) | |
| 452 | fun add_loose_bnos (Bound i, lev, js) = | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 453 | if i<lev then js else (i-lev) ins_int js | 
| 0 | 454 | | add_loose_bnos (Abs (_,_,t), lev, js) = add_loose_bnos (t, lev+1, js) | 
| 455 | | add_loose_bnos (f$t, lev, js) = | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 456 | add_loose_bnos (f, lev, add_loose_bnos (t, lev, js)) | 
| 0 | 457 | | add_loose_bnos (_, _, js) = js; | 
| 458 | ||
| 459 | fun loose_bnos t = add_loose_bnos (t, 0, []); | |
| 460 | ||
| 461 | (* loose_bvar(t,k) iff t contains a 'loose' bound variable referring to | |
| 462 | level k or beyond. *) | |
| 463 | fun loose_bvar(Bound i,k) = i >= k | |
| 464 | | loose_bvar(f$t, k) = loose_bvar(f,k) orelse loose_bvar(t,k) | |
| 465 | | loose_bvar(Abs(_,_,t),k) = loose_bvar(t,k+1) | |
| 466 | | loose_bvar _ = false; | |
| 467 | ||
| 2792 | 468 | fun loose_bvar1(Bound i,k) = i = k | 
| 469 | | loose_bvar1(f$t, k) = loose_bvar1(f,k) orelse loose_bvar1(t,k) | |
| 470 | | loose_bvar1(Abs(_,_,t),k) = loose_bvar1(t,k+1) | |
| 471 | | loose_bvar1 _ = false; | |
| 0 | 472 | |
| 473 | (*Substitute arguments for loose bound variables. | |
| 474 | Beta-reduction of arg(n-1)...arg0 into t replacing (Bound i) with (argi). | |
| 4626 | 475 | Note that for ((%x y. c) a b), the bound vars in c are x=1 and y=0 | 
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 476 | and the appropriate call is subst_bounds([b,a], c) . | 
| 0 | 477 | Loose bound variables >=n are reduced by "n" to | 
| 478 | compensate for the disappearance of lambdas. | |
| 479 | *) | |
| 480 | fun subst_bounds (args: term list, t) : term = | |
| 481 | let val n = length args; | |
| 482 | fun subst (t as Bound i, lev) = | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 483 | (if i<lev then t (*var is locally bound*) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 484 | else incr_boundvars lev (List.nth(args, i-lev)) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 485 | handle Subscript => Bound(i-n) (*loose: change it*)) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 486 | | subst (Abs(a,T,body), lev) = Abs(a, T, subst(body,lev+1)) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 487 | | subst (f$t, lev) = subst(f,lev) $ subst(t,lev) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 488 | | subst (t,lev) = t | 
| 0 | 489 | in case args of [] => t | _ => subst (t,0) end; | 
| 490 | ||
| 2192 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 491 | (*Special case: one argument*) | 
| 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 492 | fun subst_bound (arg, t) : term = | 
| 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 493 | let fun subst (t as Bound i, lev) = | 
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 494 | if i<lev then t (*var is locally bound*) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 495 | else if i=lev then incr_boundvars lev arg | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 496 | else Bound(i-1) (*loose: change it*) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 497 | | subst (Abs(a,T,body), lev) = Abs(a, T, subst(body,lev+1)) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 498 | | subst (f$t, lev) = subst(f,lev) $ subst(t,lev) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 499 | | subst (t,lev) = t | 
| 2192 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 500 | in subst (t,0) end; | 
| 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 501 | |
| 0 | 502 | (*beta-reduce if possible, else form application*) | 
| 2192 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 503 | fun betapply (Abs(_,_,t), u) = subst_bound (u,t) | 
| 0 | 504 | | betapply (f,u) = f$u; | 
| 505 | ||
| 2192 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 506 | (** Equality, membership and insertion of indexnames (string*ints) **) | 
| 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 507 | |
| 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 508 | (*optimized equality test for indexnames. Yields a huge gain under Poly/ML*) | 
| 2959 | 509 | fun eq_ix ((a, i):indexname, (a',i'):indexname) = (a=a') andalso i=i'; | 
| 2192 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 510 | |
| 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 511 | (*membership in a list, optimized version for indexnames*) | 
| 2959 | 512 | fun mem_ix (_, []) = false | 
| 2192 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 513 | | mem_ix (x, y :: ys) = eq_ix(x,y) orelse mem_ix (x, ys); | 
| 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 514 | |
| 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 515 | (*insertion into list, optimized version for indexnames*) | 
| 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 516 | fun ins_ix (x,xs) = if mem_ix (x, xs) then xs else x :: xs; | 
| 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 517 | |
| 0 | 518 | (*Tests whether 2 terms are alpha-convertible and have same type. | 
| 4626 | 519 | Note that constants may have more than one type.*) | 
| 0 | 520 | fun (Const(a,T)) aconv (Const(b,U)) = a=b andalso T=U | 
| 2752 | 521 | | (Free(a,T)) aconv (Free(b,U)) = a=b andalso T=U | 
| 522 | | (Var(v,T)) aconv (Var(w,U)) = eq_ix(v,w) andalso T=U | |
| 523 | | (Bound i) aconv (Bound j) = i=j | |
| 0 | 524 | | (Abs(_,T,t)) aconv (Abs(_,U,u)) = t aconv u andalso T=U | 
| 2752 | 525 | | (f$t) aconv (g$u) = (f aconv g) andalso (t aconv u) | 
| 0 | 526 | | _ aconv _ = false; | 
| 527 | ||
| 2176 | 528 | (** Membership, insertion, union for terms **) | 
| 529 | ||
| 530 | fun mem_term (_, []) = false | |
| 531 | | mem_term (t, t'::ts) = t aconv t' orelse mem_term(t,ts); | |
| 532 | ||
| 2182 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 533 | fun subset_term ([], ys) = true | 
| 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 534 | | subset_term (x :: xs, ys) = mem_term (x, ys) andalso subset_term(xs, ys); | 
| 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 535 | |
| 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 536 | fun eq_set_term (xs, ys) = | 
| 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 537 | xs = ys orelse (subset_term (xs, ys) andalso subset_term (ys, xs)); | 
| 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 538 | |
| 2176 | 539 | fun ins_term(t,ts) = if mem_term(t,ts) then ts else t :: ts; | 
| 540 | ||
| 541 | fun union_term (xs, []) = xs | |
| 542 | | union_term ([], ys) = ys | |
| 543 | | union_term ((x :: xs), ys) = union_term (xs, ins_term (x, ys)); | |
| 544 | ||
| 5585 | 545 | fun inter_term ([], ys) = [] | 
| 546 | | inter_term (x::xs, ys) = | |
| 547 | if mem_term (x,ys) then x :: inter_term(xs,ys) else inter_term(xs,ys); | |
| 548 | ||
| 2176 | 549 | (** Equality, membership and insertion of sorts (string lists) **) | 
| 550 | ||
| 551 | fun eq_sort ([]:sort, []) = true | |
| 552 | | eq_sort ((s::ss), (t::ts)) = s=t andalso eq_sort(ss,ts) | |
| 553 | | eq_sort (_, _) = false; | |
| 554 | ||
| 555 | fun mem_sort (_:sort, []) = false | |
| 556 | | mem_sort (S, S'::Ss) = eq_sort (S, S') orelse mem_sort(S,Ss); | |
| 557 | ||
| 558 | fun ins_sort(S,Ss) = if mem_sort(S,Ss) then Ss else S :: Ss; | |
| 559 | ||
| 560 | fun union_sort (xs, []) = xs | |
| 561 | | union_sort ([], ys) = ys | |
| 562 | | union_sort ((x :: xs), ys) = union_sort (xs, ins_sort (x, ys)); | |
| 563 | ||
| 2182 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 564 | fun subset_sort ([], ys) = true | 
| 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 565 | | subset_sort (x :: xs, ys) = mem_sort (x, ys) andalso subset_sort(xs, ys); | 
| 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 566 | |
| 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 567 | fun eq_set_sort (xs, ys) = | 
| 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 568 | xs = ys orelse (subset_sort (xs, ys) andalso subset_sort (ys, xs)); | 
| 
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
 paulson parents: 
2176diff
changeset | 569 | |
| 7638 | 570 | val rems_sort = gen_rems eq_sort; | 
| 571 | ||
| 0 | 572 | (*are two term lists alpha-convertible in corresponding elements?*) | 
| 573 | fun aconvs ([],[]) = true | |
| 574 | | aconvs (t::ts, u::us) = t aconv u andalso aconvs(ts,us) | |
| 575 | | aconvs _ = false; | |
| 576 | ||
| 577 | (*A fast unification filter: true unless the two terms cannot be unified. | |
| 578 | Terms must be NORMAL. Treats all Vars as distinct. *) | |
| 579 | fun could_unify (t,u) = | |
| 580 | let fun matchrands (f$t, g$u) = could_unify(t,u) andalso matchrands(f,g) | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 581 | | matchrands _ = true | 
| 0 | 582 | in case (head_of t , head_of u) of | 
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 583 | (_, Var _) => true | 
| 0 | 584 | | (Var _, _) => true | 
| 585 | | (Const(a,_), Const(b,_)) => a=b andalso matchrands(t,u) | |
| 586 | | (Free(a,_), Free(b,_)) => a=b andalso matchrands(t,u) | |
| 587 | | (Bound i, Bound j) => i=j andalso matchrands(t,u) | |
| 588 | | (Abs _, _) => true (*because of possible eta equality*) | |
| 589 | | (_, Abs _) => true | |
| 590 | | _ => false | |
| 591 | end; | |
| 592 | ||
| 593 | (*Substitute new for free occurrences of old in a term*) | |
| 594 | fun subst_free [] = (fn t=>t) | |
| 595 | | subst_free pairs = | |
| 596 | let fun substf u = | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 597 | case gen_assoc (op aconv) (pairs, u) of | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 598 | Some u' => u' | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 599 | | None => (case u of Abs(a,T,t) => Abs(a, T, substf t) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 600 | | t$u' => substf t $ substf u' | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 601 | | _ => u) | 
| 0 | 602 | in substf end; | 
| 603 | ||
| 604 | (*a total, irreflexive ordering on index names*) | |
| 605 | fun xless ((a,i), (b,j): indexname) = i<j orelse (i=j andalso a<b); | |
| 606 | ||
| 607 | ||
| 608 | (*Abstraction of the term "body" over its occurrences of v, | |
| 609 | which must contain no loose bound variables. | |
| 610 | The resulting term is ready to become the body of an Abs.*) | |
| 611 | fun abstract_over (v,body) = | |
| 612 | let fun abst (lev,u) = if (v aconv u) then (Bound lev) else | |
| 613 | (case u of | |
| 614 | Abs(a,T,t) => Abs(a, T, abst(lev+1, t)) | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 615 | | f$rand => abst(lev,f) $ abst(lev,rand) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 616 | | _ => u) | 
| 0 | 617 | in abst(0,body) end; | 
| 618 | ||
| 619 | ||
| 620 | (*Form an abstraction over a free variable.*) | |
| 621 | fun absfree (a,T,body) = Abs(a, T, abstract_over (Free(a,T), body)); | |
| 622 | ||
| 623 | (*Abstraction over a list of free variables*) | |
| 624 | fun list_abs_free ([ ] , t) = t | |
| 625 | | list_abs_free ((a,T)::vars, t) = | |
| 626 | absfree(a, T, list_abs_free(vars,t)); | |
| 627 | ||
| 628 | (*Quantification over a list of free variables*) | |
| 629 | fun list_all_free ([], t: term) = t | |
| 630 | | list_all_free ((a,T)::vars, t) = | |
| 631 | (all T) $ (absfree(a, T, list_all_free(vars,t))); | |
| 632 | ||
| 633 | (*Quantification over a list of variables (already bound in body) *) | |
| 634 | fun list_all ([], t) = t | |
| 635 | | list_all ((a,T)::vars, t) = | |
| 636 | (all T) $ (Abs(a, T, list_all(vars,t))); | |
| 637 | ||
| 638 | (*Replace the ATOMIC term ti by ui; instl = [(t1,u1), ..., (tn,un)]. | |
| 639 | A simultaneous substitution: [ (a,b), (b,a) ] swaps a and b. *) | |
| 640 | fun subst_atomic [] t = t : term | |
| 641 | | subst_atomic (instl: (term*term) list) t = | |
| 642 | let fun subst (Abs(a,T,body)) = Abs(a, T, subst body) | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 643 | | subst (f$t') = subst f $ subst t' | 
| 9721 | 644 | | subst t = if_none (assoc(instl,t)) t | 
| 0 | 645 | in subst t end; | 
| 646 | ||
| 728 
9a973c3ba350
Pure/term: commented typ_subst_TVars, subst_TVars, subst_Vars, subst_vars
 lcp parents: 
375diff
changeset | 647 | (*Substitute for type Vars in a type*) | 
| 0 | 648 | fun typ_subst_TVars iTs T = if null iTs then T else | 
| 649 | let fun subst(Type(a,Ts)) = Type(a, map subst Ts) | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 650 | | subst(T as TFree _) = T | 
| 9721 | 651 | | subst(T as TVar(ixn,_)) = if_none (assoc(iTs,ixn)) T | 
| 0 | 652 | in subst T end; | 
| 653 | ||
| 728 
9a973c3ba350
Pure/term: commented typ_subst_TVars, subst_TVars, subst_Vars, subst_vars
 lcp parents: 
375diff
changeset | 654 | (*Substitute for type Vars in a term*) | 
| 0 | 655 | val subst_TVars = map_term_types o typ_subst_TVars; | 
| 656 | ||
| 728 
9a973c3ba350
Pure/term: commented typ_subst_TVars, subst_TVars, subst_Vars, subst_vars
 lcp parents: 
375diff
changeset | 657 | (*Substitute for Vars in a term; see also envir/norm_term*) | 
| 0 | 658 | fun subst_Vars itms t = if null itms then t else | 
| 9721 | 659 | let fun subst(v as Var(ixn,_)) = if_none (assoc(itms,ixn)) v | 
| 0 | 660 | | subst(Abs(a,T,t)) = Abs(a,T,subst t) | 
| 661 | | subst(f$t) = subst f $ subst t | |
| 662 | | subst(t) = t | |
| 663 | in subst t end; | |
| 664 | ||
| 728 
9a973c3ba350
Pure/term: commented typ_subst_TVars, subst_TVars, subst_Vars, subst_vars
 lcp parents: 
375diff
changeset | 665 | (*Substitute for type/term Vars in a term; see also envir/norm_term*) | 
| 0 | 666 | fun subst_vars(iTs,itms) = if null iTs then subst_Vars itms else | 
| 667 | let fun subst(Const(a,T)) = Const(a,typ_subst_TVars iTs T) | |
| 668 | | subst(Free(a,T)) = Free(a,typ_subst_TVars iTs T) | |
| 669 | | subst(v as Var(ixn,T)) = (case assoc(itms,ixn) of | |
| 670 | None => Var(ixn,typ_subst_TVars iTs T) | |
| 671 | | Some t => t) | |
| 672 | | subst(b as Bound _) = b | |
| 673 | | subst(Abs(a,T,t)) = Abs(a,typ_subst_TVars iTs T,subst t) | |
| 674 | | subst(f$t) = subst f $ subst t | |
| 675 | in subst end; | |
| 676 | ||
| 677 | ||
| 678 | (*Computing the maximum index of a typ*) | |
| 2146 | 679 | fun maxidx_of_typ(Type(_,Ts)) = maxidx_of_typs Ts | 
| 0 | 680 | | maxidx_of_typ(TFree _) = ~1 | 
| 2146 | 681 | | maxidx_of_typ(TVar((_,i),_)) = i | 
| 682 | and maxidx_of_typs [] = ~1 | |
| 683 | | maxidx_of_typs (T::Ts) = Int.max(maxidx_of_typ T, maxidx_of_typs Ts); | |
| 0 | 684 | |
| 685 | ||
| 686 | (*Computing the maximum index of a term*) | |
| 687 | fun maxidx_of_term (Const(_,T)) = maxidx_of_typ T | |
| 688 | | maxidx_of_term (Bound _) = ~1 | |
| 689 | | maxidx_of_term (Free(_,T)) = maxidx_of_typ T | |
| 2146 | 690 | | maxidx_of_term (Var ((_,i), T)) = Int.max(i, maxidx_of_typ T) | 
| 691 | | maxidx_of_term (Abs (_,T,u)) = Int.max(maxidx_of_term u, maxidx_of_typ T) | |
| 692 | | maxidx_of_term (f$t) = Int.max(maxidx_of_term f, maxidx_of_term t); | |
| 0 | 693 | |
| 694 | ||
| 695 | (* Increment the index of all Poly's in T by k *) | |
| 949 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 696 | fun incr_tvar k = map_type_tvar (fn ((a,i),S) => TVar((a,i+k),S)); | 
| 0 | 697 | |
| 698 | ||
| 699 | (**** Syntax-related declarations ****) | |
| 700 | ||
| 701 | ||
| 4626 | 702 | (*Dummy type for parsing and printing. Will be replaced during type inference. *) | 
| 0 | 703 | val dummyT = Type("dummy",[]);
 | 
| 704 | ||
| 4694 | 705 | (*read a numeral of the given radix, normally 10*) | 
| 706 | fun read_radixint (radix: int, cs) : int * string list = | |
| 0 | 707 | let val zero = ord"0" | 
| 708 | val limit = zero+radix | |
| 709 | fun scan (num,[]) = (num,[]) | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 710 | | scan (num, c::cs) = | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 711 | if zero <= ord c andalso ord c < limit | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 712 | then scan(radix*num + ord c - zero, cs) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 713 | else (num, c::cs) | 
| 0 | 714 | in scan(0,cs) end; | 
| 715 | ||
| 5986 | 716 | fun read_int cs = read_radixint (10, cs); | 
| 717 | ||
| 718 | fun octal s = #1 (read_radixint (8, explode s)); | |
| 719 | val oct_char = chr o octal; | |
| 0 | 720 | |
| 721 | ||
| 722 | (*** Printing ***) | |
| 723 | ||
| 724 | ||
| 725 | (*Makes a variant of the name c distinct from the names in bs. | |
| 726 | First attaches the suffix "a" and then increments this. *) | |
| 727 | fun variant bs c : string = | |
| 2138 
056dead45ae8
Changed some mem calls to mem_string for greater efficiency (not that it could matter)
 paulson parents: 
1460diff
changeset | 728 | let fun vary2 c = if (c mem_string bs) then vary2 (bump_string c) else c | 
| 
056dead45ae8
Changed some mem calls to mem_string for greater efficiency (not that it could matter)
 paulson parents: 
1460diff
changeset | 729 | fun vary1 c = if (c mem_string bs) then vary2 (c ^ "a") else c | 
| 0 | 730 | in vary1 (if c="" then "u" else c) end; | 
| 731 | ||
| 732 | (*Create variants of the list of names, with priority to the first ones*) | |
| 733 | fun variantlist ([], used) = [] | |
| 734 | | variantlist(b::bs, used) = | |
| 735 | let val b' = variant used b | |
| 736 | in b' :: variantlist (bs, b'::used) end; | |
| 737 | ||
| 4017 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 738 | |
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 739 | |
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 740 | (** Consts etc. **) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 741 | |
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 742 | fun add_typ_classes (Type (_, Ts), cs) = foldr add_typ_classes (Ts, cs) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 743 | | add_typ_classes (TFree (_, S), cs) = S union cs | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 744 | | add_typ_classes (TVar (_, S), cs) = S union cs; | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 745 | |
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 746 | fun add_typ_tycons (Type (c, Ts), cs) = foldr add_typ_tycons (Ts, c ins cs) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 747 | | add_typ_tycons (_, cs) = cs; | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 748 | |
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 749 | val add_term_classes = it_term_types add_typ_classes; | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 750 | val add_term_tycons = it_term_types add_typ_tycons; | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 751 | |
| 9319 | 752 | fun add_term_consts (Const (c, _), cs) = c ins_string cs | 
| 4017 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 753 | | add_term_consts (t $ u, cs) = add_term_consts (t, add_term_consts (u, cs)) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 754 | | add_term_consts (Abs (_, _, t), cs) = add_term_consts (t, cs) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 755 | | add_term_consts (_, cs) = cs; | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 756 | |
| 4185 | 757 | fun exists_Const P t = let | 
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 758 | fun ex (Const c ) = P c | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 759 | | ex (t $ u ) = ex t orelse ex u | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 760 | | ex (Abs (_, _, t)) = ex t | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 761 | | ex _ = false | 
| 4185 | 762 | in ex t end; | 
| 4017 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 763 | |
| 4631 | 764 | fun exists_subterm P = | 
| 765 | let fun ex t = P t orelse | |
| 766 | (case t of | |
| 767 | u $ v => ex u orelse ex v | |
| 768 | | Abs(_, _, u) => ex u | |
| 769 | | _ => false) | |
| 770 | in ex end; | |
| 771 | ||
| 4017 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 772 | (*map classes, tycons*) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 773 | fun map_typ f g (Type (c, Ts)) = Type (g c, map (map_typ f g) Ts) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 774 | | map_typ f _ (TFree (x, S)) = TFree (x, map f S) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 775 | | map_typ f _ (TVar (xi, S)) = TVar (xi, map f S); | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 776 | |
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 777 | (*map classes, tycons, consts*) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 778 | fun map_term f g h (Const (c, T)) = Const (h c, map_typ f g T) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 779 | | map_term f g _ (Free (x, T)) = Free (x, map_typ f g T) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 780 | | map_term f g _ (Var (xi, T)) = Var (xi, map_typ f g T) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 781 | | map_term _ _ _ (t as Bound _) = t | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 782 | | map_term f g h (Abs (x, T, t)) = Abs (x, map_typ f g T, map_term f g h t) | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 783 | | map_term f g h (t $ u) = map_term f g h t $ map_term f g h u; | 
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 784 | |
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 785 | |
| 
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
 wenzelm parents: 
3965diff
changeset | 786 | |
| 0 | 787 | (** TFrees and TVars **) | 
| 788 | ||
| 789 | (*maps (bs,v) to v'::bs this reverses the identifiers bs*) | |
| 790 | fun add_new_id (bs, c) : string list = variant bs c :: bs; | |
| 791 | ||
| 792 | (*Accumulates the names in the term, suppressing duplicates. | |
| 793 | Includes Frees and Consts. For choosing unambiguous bound var names.*) | |
| 10666 | 794 | fun add_term_names (Const(a,_), bs) = NameSpace.base a ins_string bs | 
| 2176 | 795 | | add_term_names (Free(a,_), bs) = a ins_string bs | 
| 0 | 796 | | add_term_names (f$u, bs) = add_term_names (f, add_term_names(u, bs)) | 
| 797 | | add_term_names (Abs(_,_,t), bs) = add_term_names(t,bs) | |
| 798 | | add_term_names (_, bs) = bs; | |
| 799 | ||
| 800 | (*Accumulates the TVars in a type, suppressing duplicates. *) | |
| 801 | fun add_typ_tvars(Type(_,Ts),vs) = foldr add_typ_tvars (Ts,vs) | |
| 802 | | add_typ_tvars(TFree(_),vs) = vs | |
| 803 | | add_typ_tvars(TVar(v),vs) = v ins vs; | |
| 804 | ||
| 805 | (*Accumulates the TFrees in a type, suppressing duplicates. *) | |
| 806 | fun add_typ_tfree_names(Type(_,Ts),fs) = foldr add_typ_tfree_names (Ts,fs) | |
| 2176 | 807 | | add_typ_tfree_names(TFree(f,_),fs) = f ins_string fs | 
| 0 | 808 | | add_typ_tfree_names(TVar(_),fs) = fs; | 
| 809 | ||
| 810 | fun add_typ_tfrees(Type(_,Ts),fs) = foldr add_typ_tfrees (Ts,fs) | |
| 811 | | add_typ_tfrees(TFree(f),fs) = f ins fs | |
| 812 | | add_typ_tfrees(TVar(_),fs) = fs; | |
| 813 | ||
| 949 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 814 | fun add_typ_varnames(Type(_,Ts),nms) = foldr add_typ_varnames (Ts,nms) | 
| 2176 | 815 | | add_typ_varnames(TFree(nm,_),nms) = nm ins_string nms | 
| 816 | | add_typ_varnames(TVar((nm,_),_),nms) = nm ins_string nms; | |
| 949 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 817 | |
| 0 | 818 | (*Accumulates the TVars in a term, suppressing duplicates. *) | 
| 819 | val add_term_tvars = it_term_types add_typ_tvars; | |
| 820 | ||
| 821 | (*Accumulates the TFrees in a term, suppressing duplicates. *) | |
| 822 | val add_term_tfrees = it_term_types add_typ_tfrees; | |
| 823 | val add_term_tfree_names = it_term_types add_typ_tfree_names; | |
| 824 | ||
| 949 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 825 | val add_term_tvarnames = it_term_types add_typ_varnames; | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 826 | |
| 0 | 827 | (*Non-list versions*) | 
| 828 | fun typ_tfrees T = add_typ_tfrees(T,[]); | |
| 829 | fun typ_tvars T = add_typ_tvars(T,[]); | |
| 830 | fun term_tfrees t = add_term_tfrees(t,[]); | |
| 831 | fun term_tvars t = add_term_tvars(t,[]); | |
| 832 | ||
| 949 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 833 | (*special code to enforce left-to-right collection of TVar-indexnames*) | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 834 | |
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 835 | fun add_typ_ixns(ixns,Type(_,Ts)) = foldl add_typ_ixns (ixns,Ts) | 
| 2176 | 836 | | add_typ_ixns(ixns,TVar(ixn,_)) = if mem_ix (ixn, ixns) then ixns | 
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 837 | else ixns@[ixn] | 
| 949 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 838 | | add_typ_ixns(ixns,TFree(_)) = ixns; | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 839 | |
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 840 | fun add_term_tvar_ixns(Const(_,T),ixns) = add_typ_ixns(ixns,T) | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 841 | | add_term_tvar_ixns(Free(_,T),ixns) = add_typ_ixns(ixns,T) | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 842 | | add_term_tvar_ixns(Var(_,T),ixns) = add_typ_ixns(ixns,T) | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 843 | | add_term_tvar_ixns(Bound _,ixns) = ixns | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 844 | | add_term_tvar_ixns(Abs(_,T,t),ixns) = | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 845 | add_term_tvar_ixns(t,add_typ_ixns(ixns,T)) | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 846 | | add_term_tvar_ixns(f$t,ixns) = | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 847 | add_term_tvar_ixns(t,add_term_tvar_ixns(f,ixns)); | 
| 
83c588d6fee9
Changed treatment of during type inference internally generated type
 nipkow parents: 
728diff
changeset | 848 | |
| 0 | 849 | (** Frees and Vars **) | 
| 850 | ||
| 851 | (*a partial ordering (not reflexive) for atomic terms*) | |
| 852 | fun atless (Const (a,_), Const (b,_)) = a<b | |
| 853 | | atless (Free (a,_), Free (b,_)) = a<b | |
| 854 | | atless (Var(v,_), Var(w,_)) = xless(v,w) | |
| 855 | | atless (Bound i, Bound j) = i<j | |
| 856 | | atless _ = false; | |
| 857 | ||
| 858 | (*insert atomic term into partially sorted list, suppressing duplicates (?)*) | |
| 859 | fun insert_aterm (t,us) = | |
| 860 | let fun inserta [] = [t] | |
| 861 | | inserta (us as u::us') = | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 862 | if atless(t,u) then t::us | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 863 | else if t=u then us (*duplicate*) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 864 | else u :: inserta(us') | 
| 0 | 865 | in inserta us end; | 
| 866 | ||
| 867 | (*Accumulates the Vars in the term, suppressing duplicates*) | |
| 868 | fun add_term_vars (t, vars: term list) = case t of | |
| 869 | Var _ => insert_aterm(t,vars) | |
| 870 | | Abs (_,_,body) => add_term_vars(body,vars) | |
| 871 | | f$t => add_term_vars (f, add_term_vars(t, vars)) | |
| 872 | | _ => vars; | |
| 873 | ||
| 874 | fun term_vars t = add_term_vars(t,[]); | |
| 875 | ||
| 876 | (*Accumulates the Frees in the term, suppressing duplicates*) | |
| 877 | fun add_term_frees (t, frees: term list) = case t of | |
| 878 | Free _ => insert_aterm(t,frees) | |
| 879 | | Abs (_,_,body) => add_term_frees(body,frees) | |
| 880 | | f$t => add_term_frees (f, add_term_frees(t, frees)) | |
| 881 | | _ => frees; | |
| 882 | ||
| 883 | fun term_frees t = add_term_frees(t,[]); | |
| 884 | ||
| 885 | (*Given an abstraction over P, replaces the bound variable by a Free variable | |
| 886 | having a unique name. *) | |
| 887 | fun variant_abs (a,T,P) = | |
| 888 | let val b = variant (add_term_names(P,[])) a | |
| 2192 
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
 paulson parents: 
2182diff
changeset | 889 | in (b, subst_bound (Free(b,T), P)) end; | 
| 0 | 890 | |
| 891 | (* renames and reverses the strings in vars away from names *) | |
| 892 | fun rename_aTs names vars : (string*typ)list = | |
| 893 | let fun rename_aT (vars,(a,T)) = | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 894 | (variant (map #1 vars @ names) a, T) :: vars | 
| 0 | 895 | in foldl rename_aT ([],vars) end; | 
| 896 | ||
| 897 | fun rename_wrt_term t = rename_aTs (add_term_names(t,[])); | |
| 1364 
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
 clasohm parents: 
1029diff
changeset | 898 | |
| 1417 | 899 | |
| 4286 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 900 | (* left-ro-right traversal *) | 
| 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 901 | |
| 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 902 | (*foldl atoms of type*) | 
| 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 903 | fun foldl_atyps f (x, Type (_, Ts)) = foldl (foldl_atyps f) (x, Ts) | 
| 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 904 | | foldl_atyps f x_atom = f x_atom; | 
| 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 905 | |
| 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 906 | (*foldl atoms of term*) | 
| 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 907 | fun foldl_aterms f (x, t $ u) = foldl_aterms f (foldl_aterms f (x, t), u) | 
| 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 908 | | foldl_aterms f (x, Abs (_, _, t)) = foldl_aterms f (x, t) | 
| 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 909 | | foldl_aterms f x_atom = f x_atom; | 
| 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 910 | |
| 6548 
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
 wenzelm parents: 
6033diff
changeset | 911 | fun foldl_map_aterms f (x, t $ u) = | 
| 
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
 wenzelm parents: 
6033diff
changeset | 912 | let val (x', t') = foldl_map_aterms f (x, t); val (x'', u') = foldl_map_aterms f (x', u); | 
| 
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
 wenzelm parents: 
6033diff
changeset | 913 | in (x'', t' $ u') end | 
| 
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
 wenzelm parents: 
6033diff
changeset | 914 | | foldl_map_aterms f (x, Abs (a, T, t)) = | 
| 
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
 wenzelm parents: 
6033diff
changeset | 915 | let val (x', t') = foldl_map_aterms f (x, t) in (x', Abs (a, T, t')) end | 
| 
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
 wenzelm parents: 
6033diff
changeset | 916 | | foldl_map_aterms f x_atom = f x_atom; | 
| 
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
 wenzelm parents: 
6033diff
changeset | 917 | |
| 4286 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 918 | (*foldl types of term*) | 
| 8609 | 919 | fun foldl_term_types f (x, t as Const (_, T)) = f t (x, T) | 
| 920 | | foldl_term_types f (x, t as Free (_, T)) = f t (x, T) | |
| 921 | | foldl_term_types f (x, t as Var (_, T)) = f t (x, T) | |
| 922 | | foldl_term_types f (x, Bound _) = x | |
| 923 | | foldl_term_types f (x, t as Abs (_, T, b)) = foldl_term_types f (f t (x, T), b) | |
| 924 | | foldl_term_types f (x, t $ u) = foldl_term_types f (foldl_term_types f (x, t), u); | |
| 925 | ||
| 926 | fun foldl_types f = foldl_term_types (fn _ => f); | |
| 4286 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 927 | |
| 
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
 wenzelm parents: 
4188diff
changeset | 928 | |
| 1417 | 929 | |
| 4444 | 930 | (** type and term orders **) | 
| 931 | ||
| 932 | fun indexname_ord ((x, i), (y, j)) = | |
| 933 | (case int_ord (i, j) of EQUAL => string_ord (x, y) | ord => ord); | |
| 934 | ||
| 935 | ||
| 936 | (* typ_ord *) | |
| 937 | ||
| 938 | (*assumes that TFrees / TVars with the same name have same sorts*) | |
| 939 | fun typ_ord (Type (a, Ts), Type (b, Us)) = | |
| 940 | (case string_ord (a, b) of EQUAL => typs_ord (Ts, Us) | ord => ord) | |
| 941 | | typ_ord (Type _, _) = GREATER | |
| 942 | | typ_ord (TFree _, Type _) = LESS | |
| 943 | | typ_ord (TFree (a, _), TFree (b, _)) = string_ord (a, b) | |
| 944 | | typ_ord (TFree _, TVar _) = GREATER | |
| 945 | | typ_ord (TVar _, Type _) = LESS | |
| 946 | | typ_ord (TVar _, TFree _) = LESS | |
| 947 | | typ_ord (TVar (xi, _), TVar (yj, _)) = indexname_ord (xi, yj) | |
| 948 | and typs_ord Ts_Us = list_ord typ_ord Ts_Us; | |
| 949 | ||
| 950 | ||
| 951 | (* term_ord *) | |
| 952 | ||
| 953 | (*a linear well-founded AC-compatible ordering for terms: | |
| 954 | s < t <=> 1. size(s) < size(t) or | |
| 955 | 2. size(s) = size(t) and s=f(...) and t=g(...) and f<g or | |
| 956 | 3. size(s) = size(t) and s=f(s1..sn) and t=f(t1..tn) and | |
| 957 | (s1..sn) < (t1..tn) (lexicographically)*) | |
| 958 | ||
| 959 | fun dest_hd (Const (a, T)) = (((a, 0), T), 0) | |
| 960 | | dest_hd (Free (a, T)) = (((a, 0), T), 1) | |
| 961 | | dest_hd (Var v) = (v, 2) | |
| 962 |   | dest_hd (Bound i) = ((("", i), dummyT), 3)
 | |
| 963 |   | dest_hd (Abs (_, T, _)) = ((("", 0), T), 4);
 | |
| 964 | ||
| 965 | fun term_ord (Abs (_, T, t), Abs(_, U, u)) = | |
| 966 | (case term_ord (t, u) of EQUAL => typ_ord (T, U) | ord => ord) | |
| 967 | | term_ord (t, u) = | |
| 968 | (case int_ord (size_of_term t, size_of_term u) of | |
| 969 | EQUAL => | |
| 970 | let val (f, ts) = strip_comb t and (g, us) = strip_comb u in | |
| 971 | (case hd_ord (f, g) of EQUAL => terms_ord (ts, us) | ord => ord) | |
| 972 | end | |
| 973 | | ord => ord) | |
| 974 | and hd_ord (f, g) = | |
| 975 | prod_ord (prod_ord indexname_ord typ_ord) int_ord (dest_hd f, dest_hd g) | |
| 976 | and terms_ord (ts, us) = list_ord term_ord (ts, us); | |
| 977 | ||
| 978 | fun termless tu = (term_ord tu = LESS); | |
| 979 | ||
| 8408 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 980 | structure Vartab = TableFun(type key = indexname val ord = indexname_ord); | 
| 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 981 | structure Termtab = TableFun(type key = term val ord = term_ord); | 
| 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 982 | |
| 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 983 | (*Substitute for type Vars in a type, version using Vartab*) | 
| 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 984 | fun typ_subst_TVars_Vartab iTs T = if Vartab.is_empty iTs then T else | 
| 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 985 | let fun subst(Type(a, Ts)) = Type(a, map subst Ts) | 
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 986 | | subst(T as TFree _) = T | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 987 | | subst(T as TVar(ixn, _)) = | 
| 8408 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 988 | (case Vartab.lookup (iTs, ixn) of None => T | Some(U) => U) | 
| 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 989 | in subst T end; | 
| 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 990 | |
| 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 991 | (*Substitute for type Vars in a term, version using Vartab*) | 
| 
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
 berghofe parents: 
7638diff
changeset | 992 | val subst_TVars_Vartab = map_term_types o typ_subst_TVars_Vartab; | 
| 4444 | 993 | |
| 994 | ||
| 1426 | 995 | (*** Compression of terms and types by sharing common subtrees. | 
| 996 | Saves 50-75% on storage requirements. As it is fairly slow, | |
| 997 | it is called only for axioms, stored theorems, etc. ***) | |
| 1417 | 998 | |
| 999 | (** Sharing of types **) | |
| 1000 | ||
| 1001 | fun atomic_tag (Type (a,_)) = if a<>"fun" then a else raise Match | |
| 1002 | | atomic_tag (TFree (a,_)) = a | |
| 1003 | | atomic_tag (TVar ((a,_),_)) = a; | |
| 1004 | ||
| 1005 | fun type_tag (Type("fun",[S,T])) = atomic_tag S ^ type_tag T
 | |
| 1006 | | type_tag T = atomic_tag T; | |
| 1007 | ||
| 4487 | 1008 | val memo_types = ref (Symtab.empty : typ list Symtab.table); | 
| 1417 | 1009 | |
| 4188 
1025a27b08f9
changed libraray function find to find_index_eq, currying it
 oheimb parents: 
4185diff
changeset | 1010 | (* special case of library/find_first *) | 
| 1417 | 1011 | fun find_type (T, []: typ list) = None | 
| 1012 | | find_type (T, T'::Ts) = | |
| 1013 | if T=T' then Some T' | |
| 1014 | else find_type (T, Ts); | |
| 1015 | ||
| 1016 | fun compress_type T = | |
| 1017 | let val tag = type_tag T | |
| 6963 | 1018 | val tylist = Symtab.lookup_multi (!memo_types, tag) | 
| 1417 | 1019 | in | 
| 1020 | case find_type (T,tylist) of | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1021 | Some T' => T' | 
| 1417 | 1022 | | None => | 
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1023 | let val T' = | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1024 | case T of | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1025 | Type (a,Ts) => Type (a, map compress_type Ts) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1026 | | _ => T | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1027 | in memo_types := Symtab.update ((tag, T'::tylist), !memo_types); | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1028 | T | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1029 | end | 
| 1417 | 1030 | end | 
| 1031 | handle Match => | |
| 1032 | let val Type (a,Ts) = T | |
| 1033 | in Type (a, map compress_type Ts) end; | |
| 1034 | ||
| 1035 | (** Sharing of atomic terms **) | |
| 1036 | ||
| 4487 | 1037 | val memo_terms = ref (Symtab.empty : term list Symtab.table); | 
| 1417 | 1038 | |
| 4188 
1025a27b08f9
changed libraray function find to find_index_eq, currying it
 oheimb parents: 
4185diff
changeset | 1039 | (* special case of library/find_first *) | 
| 1417 | 1040 | fun find_term (t, []: term list) = None | 
| 1041 | | find_term (t, t'::ts) = | |
| 1042 | if t=t' then Some t' | |
| 1043 | else find_term (t, ts); | |
| 1044 | ||
| 1045 | fun const_tag (Const (a,_)) = a | |
| 1046 | | const_tag (Free (a,_)) = a | |
| 1047 | | const_tag (Var ((a,i),_)) = a | |
| 1048 | | const_tag (t as Bound _) = ".B."; | |
| 1049 | ||
| 1050 | fun share_term (t $ u) = share_term t $ share_term u | |
| 1051 | | share_term (Abs (a,T,u)) = Abs (a, T, share_term u) | |
| 1052 | | share_term t = | |
| 1053 | let val tag = const_tag t | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1054 | val ts = Symtab.lookup_multi (!memo_terms, tag) | 
| 1417 | 1055 | in | 
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1056 | case find_term (t,ts) of | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1057 | Some t' => t' | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1058 | | None => (memo_terms := Symtab.update ((tag, t::ts), !memo_terms); | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1059 | t) | 
| 1417 | 1060 | end; | 
| 1061 | ||
| 1062 | val compress_term = share_term o map_term_types compress_type; | |
| 1063 | ||
| 4444 | 1064 | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1065 | (* dummy patterns *) | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1066 | |
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1067 | val dummy_patternN = "dummy_pattern"; | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1068 | |
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1069 | fun is_dummy_pattern (Const ("dummy_pattern", _)) = true
 | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1070 | | is_dummy_pattern _ = false; | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1071 | |
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1072 | fun no_dummy_patterns tm = | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1073 | if not (foldl_aterms (fn (b, t) => b orelse is_dummy_pattern t) (false, tm)) then tm | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1074 |   else raise TERM ("Illegal occurrence of '_' dummy pattern", [tm]);
 | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1075 | |
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1076 | val replace_dummy_patterns = foldl_map_aterms (fn (i, t) => | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1077 |   if is_dummy_pattern t then (i + 1, Var (("_dummy_", i), fastype_of t)) else (i, t));
 | 
| 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1078 | |
| 10552 | 1079 | fun is_replaced_dummy_pattern ("_dummy_", _) = true
 | 
| 1080 | | is_replaced_dummy_pattern _ = false; | |
| 9536 
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
 wenzelm parents: 
9319diff
changeset | 1081 | |
| 1364 
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
 clasohm parents: 
1029diff
changeset | 1082 | end; | 
| 
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
 clasohm parents: 
1029diff
changeset | 1083 | |
| 4444 | 1084 | |
| 1085 | structure BasicTerm: BASIC_TERM = Term; | |
| 1086 | open BasicTerm; |