161 handle Type.TUNIFY => NONE; |
161 handle Type.TUNIFY => NONE; |
162 in |
162 in |
163 case typs_unify of |
163 case typs_unify of |
164 SOME (typinsttab, ix2) => |
164 SOME (typinsttab, ix2) => |
165 let |
165 let |
166 (* is it right to throw away teh flexes? |
166 (* is it right to throw away the flexes? |
167 or should I be using them somehow? *) |
167 or should I be using them somehow? *) |
168 fun mk_insts (env,flexflexes) = |
168 fun mk_insts (env,flexflexes) = |
169 (Vartab.dest (Envir.type_env env), Envir.alist_of env); |
169 (Vartab.dest (Envir.type_env env), Envir.alist_of env); |
170 val initenv = Envir.Envir {asol = Vartab.empty, |
170 val initenv = Envir.Envir {asol = Vartab.empty, |
171 iTs = typinsttab, maxidx = ix2}; |
171 iTs = typinsttab, maxidx = ix2}; |
172 val useq = (Unify.unifiers (sgn,initenv,[a])) |
172 val useq = (Unify.unifiers (sgn,initenv,[a])) |
173 handle Library.LIST _ => Seq.empty |
173 handle UnequalLengths => Seq.empty |
174 | Term.TERM _ => Seq.empty; |
174 | Term.TERM _ => Seq.empty; |
175 fun clean_unify' useq () = |
175 fun clean_unify' useq () = |
176 (case (Seq.pull useq) of |
176 (case (Seq.pull useq) of |
177 NONE => NONE |
177 NONE => NONE |
178 | SOME (h,t) => SOME (mk_insts h, Seq.make (clean_unify' t))) |
178 | SOME (h,t) => SOME (mk_insts h, Seq.make (clean_unify' t))) |
179 handle Library.LIST _ => NONE |
179 handle UnequalLengths => NONE |
180 | Term.TERM _ => NONE; |
180 | Term.TERM _ => NONE; |
181 in |
181 in |
182 (Seq.make (clean_unify' useq)) |
182 (Seq.make (clean_unify' useq)) |
183 end |
183 end |
184 | NONE => Seq.empty |
184 | NONE => Seq.empty |
323 val unskolemise_term : (string,Term.typ) list -> Term.term -> Term.term |
323 val unskolemise_term : (string,Term.typ) list -> Term.term -> Term.term |
324 *) |
324 *) |
325 |
325 |
326 (* cunning version *) |
326 (* cunning version *) |
327 |
327 |
328 (* This version avoids name conflicts that might be intorduced by |
328 (* This version avoids name conflicts that might be introduced by |
329 unskolemisation, and returns a list of (string * Term.typ) * string, |
329 unskolemisation, and returns a list of (string * Term.typ) * string, |
330 where the outer string is the original name, and the inner string is |
330 where the outer string is the original name, and the inner string is |
331 the new name, and the type is the type of the free variable that was |
331 the new name, and the type is the type of the free variable that was |
332 renamed. *) |
332 renamed. *) |
333 local |
333 local |
338 let val renamedn = Term.variant names n' in |
338 let val renamedn = Term.variant names n' in |
339 (renamedn, (((renamedn, ty), n) :: renames, |
339 (renamedn, (((renamedn, ty), n) :: renames, |
340 renamedn :: names)) end |
340 renamedn :: names)) end |
341 | (SOME ((renamedn, _), _)) => (renamedn, L) |
341 | (SOME ((renamedn, _), _)) => (renamedn, L) |
342 end |
342 end |
343 handle LIST _ => (n, L); |
343 handle Fail _ => (n, L); |
344 |
344 |
345 fun unsk (L,f) (t1 $ t2) = |
345 fun unsk (L,f) (t1 $ t2) = |
346 let val (L', t1') = unsk (L, I) t1 |
346 let val (L', t1') = unsk (L, I) t1 |
347 in unsk (L', (fn x => f (t1' $ x))) t2 end |
347 in unsk (L', (fn x => f (t1' $ x))) t2 end |
348 | unsk (L,f) (Abs(n,ty,t)) = |
348 | unsk (L,f) (Abs(n,ty,t)) = |
363 let |
363 let |
364 fun fmap fv = |
364 fun fmap fv = |
365 let (n,ty) = (Term.dest_Free fv) in |
365 let (n,ty) = (Term.dest_Free fv) in |
366 SOME (fv, Free (Syntax.dest_skolem n, ty)) handle LIST _ => NONE |
366 SOME (fv, Free (Syntax.dest_skolem n, ty)) handle LIST _ => NONE |
367 end |
367 end |
368 val substfrees = mapfilter fmap (Term.term_frees t) |
368 val substfrees = List.mapPartial fmap (Term.term_frees t) |
369 in |
369 in |
370 Term.subst_free substfrees t |
370 Term.subst_free substfrees t |
371 end; *) |
371 end; *) |
372 |
372 |
373 (* true if the type t is a function *) |
373 (* true if the type t is a function *) |
377 |
377 |
378 val is_atomic_typ = not o is_fun_typ; |
378 val is_atomic_typ = not o is_fun_typ; |
379 |
379 |
380 (* get the frees in a term that are of atomic type, ie non-functions *) |
380 (* get the frees in a term that are of atomic type, ie non-functions *) |
381 val atomic_frees_of_term = |
381 val atomic_frees_of_term = |
382 filter (is_atomic_typ o snd) |
382 List.filter (is_atomic_typ o snd) |
383 o map Term.dest_Free |
383 o map Term.dest_Free |
384 o Term.term_frees; |
384 o Term.term_frees; |
385 |
385 |
386 |
386 |
387 (* read in a string and a top-level type and this will give back a term *) |
387 (* read in a string and a top-level type and this will give back a term *) |
436 | term_name_eq a b l = ((*writeln ("unchecked case:\n" ^ "a:\n" ^ (pretty_print_term a) ^ "\nb:\n" ^ (pretty_print_term b));*) NONE); |
436 | term_name_eq a b l = ((*writeln ("unchecked case:\n" ^ "a:\n" ^ (pretty_print_term a) ^ "\nb:\n" ^ (pretty_print_term b));*) NONE); |
437 |
437 |
438 (* checks to see if the term in a name-equivalent member of the list of terms. *) |
438 (* checks to see if the term in a name-equivalent member of the list of terms. *) |
439 fun get_name_eq_member a [] = NONE |
439 fun get_name_eq_member a [] = NONE |
440 | get_name_eq_member a (h :: t) = |
440 | get_name_eq_member a (h :: t) = |
441 if is_some (term_name_eq a h []) then SOME h |
441 if isSome (term_name_eq a h []) then SOME h |
442 else get_name_eq_member a t; |
442 else get_name_eq_member a t; |
443 |
443 |
444 fun name_eq_member a [] = false |
444 fun name_eq_member a [] = false |
445 | name_eq_member a (h :: t) = |
445 | name_eq_member a (h :: t) = |
446 if is_some (term_name_eq a h []) then true |
446 if isSome (term_name_eq a h []) then true |
447 else name_eq_member a t; |
447 else name_eq_member a t; |
448 |
448 |
449 (* true if term is a variable *) |
449 (* true if term is a variable *) |
450 fun is_some_kind_of_var (Free(s, ty)) = true |
450 fun is_some_kind_of_var (Free(s, ty)) = true |
451 | is_some_kind_of_var (Var(i, ty)) = true |
451 | is_some_kind_of_var (Var(i, ty)) = true |
483 term_contains1 (NONE::Bs, FVs) t t2 |
483 term_contains1 (NONE::Bs, FVs) t t2 |
484 |
484 |
485 | term_contains1 T (ah $ at) (bh $ bt) = |
485 | term_contains1 T (ah $ at) (bh $ bt) = |
486 (term_contains1 T ah (bh $ bt)) @ |
486 (term_contains1 T ah (bh $ bt)) @ |
487 (term_contains1 T at (bh $ bt)) @ |
487 (term_contains1 T at (bh $ bt)) @ |
488 (flat (map (fn inT => (term_contains1 inT at bt)) |
488 (List.concat (map (fn inT => (term_contains1 inT at bt)) |
489 (term_contains1 T ah bh))) |
489 (term_contains1 T ah bh))) |
490 |
490 |
491 | term_contains1 T a (bh $ bt) = [] |
491 | term_contains1 T a (bh $ bt) = [] |
492 |
492 |
493 | term_contains1 T (ah $ at) b = |
493 | term_contains1 T (ah $ at) b = |
660 (case (fvartabS.lookup (ntab,s)) of |
660 (case (fvartabS.lookup (ntab,s)) of |
661 NONE => ((fvartabS.update ((s,s),ntab)), v) |
661 NONE => ((fvartabS.update ((s,s),ntab)), v) |
662 | SOME _ => nt) |
662 | SOME _ => nt) |
663 | bounds_to_frees_aux T (nt as (ntab, Bound i)) = |
663 | bounds_to_frees_aux T (nt as (ntab, Bound i)) = |
664 let |
664 let |
665 val (s,ty) = Library.nth_elem (i,T) |
665 val (s,ty) = List.nth (T,i) |
666 in |
666 in |
667 (ntab, Free (s,ty)) |
667 (ntab, Free (s,ty)) |
668 end; |
668 end; |
669 |
669 |
670 |
670 |
681 Abs(s,ty,loose_bnds_to_frees_aux (bnds + 1,vars) t) |
681 Abs(s,ty,loose_bnds_to_frees_aux (bnds + 1,vars) t) |
682 | loose_bnds_to_frees_aux (bnds,vars) (a $ b) = |
682 | loose_bnds_to_frees_aux (bnds,vars) (a $ b) = |
683 (loose_bnds_to_frees_aux (bnds,vars) a) |
683 (loose_bnds_to_frees_aux (bnds,vars) a) |
684 $ (loose_bnds_to_frees_aux (bnds,vars) b) |
684 $ (loose_bnds_to_frees_aux (bnds,vars) b) |
685 | loose_bnds_to_frees_aux (bnds,vars) (t as (Bound i)) = |
685 | loose_bnds_to_frees_aux (bnds,vars) (t as (Bound i)) = |
686 if (bnds <= i) then Free (Library.nth_elem (i - bnds,vars)) |
686 if (bnds <= i) then Free (List.nth (vars,i - bnds)) |
687 else t |
687 else t |
688 | loose_bnds_to_frees_aux (bnds,vars) t = t; |
688 | loose_bnds_to_frees_aux (bnds,vars) t = t; |
689 |
689 |
690 |
690 |
691 fun loose_bnds_to_frees vars t = |
691 fun loose_bnds_to_frees vars t = |
703 SplitterData.mk_eq (Drule.standard (ObjectLogic.rulify_no_asm triv)) |
703 SplitterData.mk_eq (Drule.standard (ObjectLogic.rulify_no_asm triv)) |
704 end; |
704 end; |
705 |
705 |
706 fun thms_of_prems_in_goal i tm= |
706 fun thms_of_prems_in_goal i tm= |
707 let |
707 let |
708 val goal = (nth_elem (i-1,Thm.prems_of tm)) |
708 val goal = (List.nth (Thm.prems_of tm,i-1)) |
709 val vars = rev (strip_all_vars goal) |
709 val vars = rev (strip_all_vars goal) |
710 val prems = Logic.strip_assums_hyp (strip_all_body goal) |
710 val prems = Logic.strip_assums_hyp (strip_all_body goal) |
711 val simp_prem_thms = |
711 val simp_prem_thms = |
712 map (make_term_into_simp_thm vars (Thm.sign_of_thm tm)) prems |
712 map (make_term_into_simp_thm vars (Thm.sign_of_thm tm)) prems |
713 in |
713 in |