685 | _ => false) ? cons args |
685 | _ => false) ? cons args |
686 fun call_sets [] [] vs = [vs] |
686 fun call_sets [] [] vs = [vs] |
687 | call_sets [] uss vs = vs :: call_sets uss [] [] |
687 | call_sets [] uss vs = vs :: call_sets uss [] [] |
688 | call_sets ([] :: _) _ _ = [] |
688 | call_sets ([] :: _) _ _ = [] |
689 | call_sets ((t :: ts) :: tss) uss vs = |
689 | call_sets ((t :: ts) :: tss) uss vs = |
690 OrdList.insert Term_Ord.term_ord t vs |> call_sets tss (ts :: uss) |
690 Ord_List.insert Term_Ord.term_ord t vs |> call_sets tss (ts :: uss) |
691 val sets = call_sets (fun_calls t [] []) [] [] |
691 val sets = call_sets (fun_calls t [] []) [] [] |
692 val indexed_sets = sets ~~ (index_seq 0 (length sets)) |
692 val indexed_sets = sets ~~ (index_seq 0 (length sets)) |
693 in |
693 in |
694 fold_rev (fn (set, j) => |
694 fold_rev (fn (set, j) => |
695 case set of |
695 case set of |
699 | [t as Free _] => cons (j, SOME t) |
699 | [t as Free _] => cons (j, SOME t) |
700 | _ => I) indexed_sets [] |
700 | _ => I) indexed_sets [] |
701 end |
701 end |
702 fun static_args_in_terms hol_ctxt x = |
702 fun static_args_in_terms hol_ctxt x = |
703 map (static_args_in_term hol_ctxt x) |
703 map (static_args_in_term hol_ctxt x) |
704 #> fold1 (OrdList.inter (prod_ord int_ord (option_ord Term_Ord.term_ord))) |
704 #> fold1 (Ord_List.inter (prod_ord int_ord (option_ord Term_Ord.term_ord))) |
705 |
705 |
706 fun overlapping_indices [] _ = [] |
706 fun overlapping_indices [] _ = [] |
707 | overlapping_indices _ [] = [] |
707 | overlapping_indices _ [] = [] |
708 | overlapping_indices (ps1 as (j1, t1) :: ps1') (ps2 as (j2, t2) :: ps2') = |
708 | overlapping_indices (ps1 as (j1, t1) :: ps1') (ps2 as (j2, t2) :: ps2') = |
709 if j1 < j2 then overlapping_indices ps1' ps2 |
709 if j1 < j2 then overlapping_indices ps1' ps2 |
842 |> map (fn (x, zs) => |
842 |> map (fn (x, zs) => |
843 (x, zs |> member (op =) ts (Const x) ? cons ([], [], x))) |
843 (x, zs |> member (op =) ts (Const x) ? cons ([], [], x))) |
844 fun generality (js, _, _) = ~(length js) |
844 fun generality (js, _, _) = ~(length js) |
845 fun is_more_specific (j1, t1, x1) (j2, t2, x2) = |
845 fun is_more_specific (j1, t1, x1) (j2, t2, x2) = |
846 x1 <> x2 andalso length j2 < length j1 andalso |
846 x1 <> x2 andalso length j2 < length j1 andalso |
847 OrdList.subset (prod_ord int_ord Term_Ord.term_ord) (j2 ~~ t2, j1 ~~ t1) |
847 Ord_List.subset (prod_ord int_ord Term_Ord.term_ord) (j2 ~~ t2, j1 ~~ t1) |
848 fun do_pass_1 _ [] [_] [_] = I |
848 fun do_pass_1 _ [] [_] [_] = I |
849 | do_pass_1 T skipped _ [] = do_pass_2 T skipped |
849 | do_pass_1 T skipped _ [] = do_pass_2 T skipped |
850 | do_pass_1 T skipped all (z :: zs) = |
850 | do_pass_1 T skipped all (z :: zs) = |
851 case filter (is_more_specific z) all |
851 case filter (is_more_specific z) all |
852 |> sort (int_ord o pairself generality) of |
852 |> sort (int_ord o pairself generality) of |