src/HOL/Tools/ATP/atp_problem_generate.ML
changeset 49147 9aa0fad4e864
parent 49146 1016664b8feb
child 49148 a5ab5964065f
equal deleted inserted replaced
49146:1016664b8feb 49147:9aa0fad4e864
   887   | add_sorts_on_tfree _ = I
   887   | add_sorts_on_tfree _ = I
   888 fun add_sorts_on_tvar (TVar z) = generic_add_sorts_on_type z
   888 fun add_sorts_on_tvar (TVar z) = generic_add_sorts_on_type z
   889   | add_sorts_on_tvar _ = I
   889   | add_sorts_on_tvar _ = I
   890 
   890 
   891 fun type_class_formula type_enc class arg =
   891 fun type_class_formula type_enc class arg =
   892   AAtom (ATerm (class, arg ::
   892   AAtom (ATerm ((class, []), arg ::
   893       (case type_enc of
   893       (case type_enc of
   894          Native (First_Order, Raw_Polymorphic Without_Phantom_Type_Vars, _) =>
   894          Native (First_Order, Raw_Polymorphic Without_Phantom_Type_Vars, _) =>
   895          [ATerm (TYPE_name, [arg])]
   895          [ATerm ((TYPE_name, []), [arg])]
   896        | _ => [])))
   896        | _ => [])))
   897 fun formulas_for_types type_enc add_sorts_on_typ Ts =
   897 fun formulas_for_types type_enc add_sorts_on_typ Ts =
   898   [] |> level_of_type_enc type_enc <> No_Types ? fold add_sorts_on_typ Ts
   898   [] |> level_of_type_enc type_enc <> No_Types ? fold add_sorts_on_typ Ts
   899      |> map (fn (class, name) =>
   899      |> map (fn (class, name) =>
   900                 type_class_formula type_enc class (ATerm (name, [])))
   900                 type_class_formula type_enc class (ATerm ((name, []), [])))
   901 
   901 
   902 fun mk_aconns c phis =
   902 fun mk_aconns c phis =
   903   let val (phis', phi') = split_last phis in
   903   let val (phis', phi') = split_last phis in
   904     fold_rev (mk_aconn c) phis' phi'
   904     fold_rev (mk_aconn c) phis' phi'
   905   end
   905   end
   917       | add_formula_vars bounds (AConn (_, phis)) =
   917       | add_formula_vars bounds (AConn (_, phis)) =
   918         fold (add_formula_vars bounds) phis
   918         fold (add_formula_vars bounds) phis
   919       | add_formula_vars bounds (AAtom tm) = add_term_vars bounds tm
   919       | add_formula_vars bounds (AAtom tm) = add_term_vars bounds tm
   920   in mk_aquant AForall (add_formula_vars [] phi []) phi end
   920   in mk_aquant AForall (add_formula_vars [] phi []) phi end
   921 
   921 
   922 fun add_term_vars bounds (ATerm (name as (s, _), tms)) =
   922 fun add_term_vars bounds (ATerm ((name as (s, _), _), tms)) =
   923     (if is_tptp_variable s andalso
   923     (if is_tptp_variable s andalso
   924         not (String.isPrefix tvar_prefix s) andalso
   924         not (String.isPrefix tvar_prefix s) andalso
   925         not (member (op =) bounds name) then
   925         not (member (op =) bounds name) then
   926        insert (op =) (name, NONE)
   926        insert (op =) (name, NONE)
   927      else
   927      else
   946 fun tvar_name (x as (s, _)) = (make_schematic_type_var x, s)
   946 fun tvar_name (x as (s, _)) = (make_schematic_type_var x, s)
   947 
   947 
   948 fun ho_term_from_typ type_enc =
   948 fun ho_term_from_typ type_enc =
   949   let
   949   let
   950     fun term (Type (s, Ts)) =
   950     fun term (Type (s, Ts)) =
   951       ATerm (case (is_type_enc_higher_order type_enc, s) of
   951       ATerm ((case (is_type_enc_higher_order type_enc, s) of
   952                (true, @{type_name bool}) => `I tptp_bool_type
   952                 (true, @{type_name bool}) => `I tptp_bool_type
   953              | (true, @{type_name fun}) => `I tptp_fun_type
   953               | (true, @{type_name fun}) => `I tptp_fun_type
   954              | _ => if s = fused_infinite_type_name andalso
   954               | _ => if s = fused_infinite_type_name andalso
   955                        is_type_enc_native type_enc then
   955                         is_type_enc_native type_enc then
   956                       `I tptp_individual_type
   956                        `I tptp_individual_type
   957                     else
   957                      else
   958                       `make_fixed_type_const s,
   958                        `make_fixed_type_const s,
   959              map term Ts)
   959               []), map term Ts)
   960     | term (TFree (s, _)) = ATerm (`make_fixed_type_var s, [])
   960     | term (TFree (s, _)) = ATerm ((`make_fixed_type_var s, []), [])
   961     | term (TVar (x, _)) = ATerm (tvar_name x, [])
   961     | term (TVar (x, _)) = ATerm ((tvar_name x, []), [])
   962   in term end
   962   in term end
   963 
   963 
   964 fun ho_term_for_type_arg type_enc T =
   964 fun ho_term_for_type_arg type_enc T =
   965   if T = dummyT then NONE else SOME (ho_term_from_typ type_enc T)
   965   if T = dummyT then NONE else SOME (ho_term_from_typ type_enc T)
   966 
   966 
   968 val uncurried_alias_sep = "\000"
   968 val uncurried_alias_sep = "\000"
   969 val mangled_type_sep = "\001"
   969 val mangled_type_sep = "\001"
   970 
   970 
   971 val ascii_of_uncurried_alias_sep = ascii_of uncurried_alias_sep
   971 val ascii_of_uncurried_alias_sep = ascii_of uncurried_alias_sep
   972 
   972 
   973 fun generic_mangled_type_name f (ATerm (name, [])) = f name
   973 (* ### FIXME: insane *)
   974   | generic_mangled_type_name f (ATerm (name, tys)) =
   974 fun generic_mangled_type_name f (ATerm ((name, _), [])) = f name
       
   975   | generic_mangled_type_name f (ATerm ((name, _), tys)) =
   975     f name ^ "(" ^ space_implode "," (map (generic_mangled_type_name f) tys)
   976     f name ^ "(" ^ space_implode "," (map (generic_mangled_type_name f) tys)
   976     ^ ")"
   977     ^ ")"
   977   | generic_mangled_type_name _ _ = raise Fail "unexpected type abstraction"
   978   | generic_mangled_type_name _ _ = raise Fail "unexpected type abstraction"
   978 
   979 
   979 fun mangled_type type_enc =
   980 fun mangled_type type_enc =
   989 fun ho_type_from_ho_term type_enc pred_sym ary =
   990 fun ho_type_from_ho_term type_enc pred_sym ary =
   990   let
   991   let
   991     fun to_mangled_atype ty =
   992     fun to_mangled_atype ty =
   992       AType ((make_native_type (generic_mangled_type_name fst ty),
   993       AType ((make_native_type (generic_mangled_type_name fst ty),
   993               generic_mangled_type_name snd ty), [])
   994               generic_mangled_type_name snd ty), [])
   994     fun to_poly_atype (ATerm (name, tys)) = AType (name, map to_poly_atype tys)
   995     fun to_poly_atype (ATerm ((name, []), tys)) =
       
   996         AType (name, map to_poly_atype tys)
   995       | to_poly_atype _ = raise Fail "unexpected type abstraction"
   997       | to_poly_atype _ = raise Fail "unexpected type abstraction"
   996     val to_atype =
   998     val to_atype =
   997       if is_type_enc_polymorphic type_enc then to_poly_atype
   999       if is_type_enc_polymorphic type_enc then to_poly_atype
   998       else to_mangled_atype
  1000       else to_mangled_atype
   999     fun to_afun f1 f2 tys = AFun (f1 (hd tys), f2 (nth tys 1))
  1001     fun to_afun f1 f2 tys = AFun (f1 (hd tys), f2 (nth tys 1))
  1000     fun to_fo 0 ty = if pred_sym then bool_atype else to_atype ty
  1002     fun to_fo 0 ty = if pred_sym then bool_atype else to_atype ty
  1001       | to_fo ary (ATerm (_, tys)) = to_afun to_atype (to_fo (ary - 1)) tys
  1003       | to_fo ary (ATerm (_, tys)) = to_afun to_atype (to_fo (ary - 1)) tys
  1002       | to_fo _ _ = raise Fail "unexpected type abstraction"
  1004       | to_fo _ _ = raise Fail "unexpected type abstraction"
  1003     fun to_ho (ty as ATerm ((s, _), tys)) =
  1005     fun to_ho (ty as ATerm (((s, _), []), tys)) =
  1004         if s = tptp_fun_type then to_afun to_ho to_ho tys else to_atype ty
  1006         if s = tptp_fun_type then to_afun to_ho to_ho tys else to_atype ty
  1005       | to_ho _ = raise Fail "unexpected type abstraction"
  1007       | to_ho _ = raise Fail "unexpected type abstraction"
  1006   in if is_type_enc_higher_order type_enc then to_ho else to_fo ary end
  1008   in if is_type_enc_higher_order type_enc then to_ho else to_fo ary end
  1007 
  1009 
  1008 fun ho_type_from_typ type_enc pred_sym ary =
  1010 fun ho_type_from_typ type_enc pred_sym ary =
  1031   Scan.many1 (not o member (op =) ["(", ")", ","]) >> implode
  1033   Scan.many1 (not o member (op =) ["(", ")", ","]) >> implode
  1032 
  1034 
  1033 fun parse_mangled_type x =
  1035 fun parse_mangled_type x =
  1034   (parse_mangled_ident
  1036   (parse_mangled_ident
  1035    -- Scan.optional ($$ "(" |-- Scan.optional parse_mangled_types [] --| $$ ")")
  1037    -- Scan.optional ($$ "(" |-- Scan.optional parse_mangled_types [] --| $$ ")")
  1036                     [] >> ATerm) x
  1038                     [] >> (ATerm o apfst (rpair []))) x
  1037 and parse_mangled_types x =
  1039 and parse_mangled_types x =
  1038   (parse_mangled_type ::: Scan.repeat ($$ "," |-- parse_mangled_type)) x
  1040   (parse_mangled_type ::: Scan.repeat ($$ "," |-- parse_mangled_type)) x
  1039 
  1041 
  1040 fun unmangled_type s =
  1042 fun unmangled_type s =
  1041   s |> suffix ")" |> raw_explode
  1043   s |> suffix ")" |> raw_explode
  1729                               atype_of_type_vars type_enc)
  1731                               atype_of_type_vars type_enc)
  1730                       | _ => NONE) Ts)
  1732                       | _ => NONE) Ts)
  1731 
  1733 
  1732 fun eq_formula type_enc atomic_Ts bounds pred_sym tm1 tm2 =
  1734 fun eq_formula type_enc atomic_Ts bounds pred_sym tm1 tm2 =
  1733   (if pred_sym then AConn (AIff, [AAtom tm1, AAtom tm2])
  1735   (if pred_sym then AConn (AIff, [AAtom tm1, AAtom tm2])
  1734    else AAtom (ATerm (`I tptp_equal, [tm1, tm2])))
  1736    else AAtom (ATerm ((`I tptp_equal, []), [tm1, tm2])))
  1735   |> mk_aquant AForall bounds
  1737   |> mk_aquant AForall bounds
  1736   |> close_formula_universally
  1738   |> close_formula_universally
  1737   |> bound_tvars type_enc true atomic_Ts
  1739   |> bound_tvars type_enc true atomic_Ts
  1738 
  1740 
  1739 val helper_rank = default_rank
  1741 val helper_rank = default_rank
  1949 fun type_guard_iterm type_enc T tm =
  1951 fun type_guard_iterm type_enc T tm =
  1950   IApp (IConst (type_guard, T --> @{typ bool}, [T])
  1952   IApp (IConst (type_guard, T --> @{typ bool}, [T])
  1951         |> mangle_type_args_in_iterm type_enc, tm)
  1953         |> mangle_type_args_in_iterm type_enc, tm)
  1952 
  1954 
  1953 fun is_var_positively_naked_in_term _ (SOME false) _ accum = accum
  1955 fun is_var_positively_naked_in_term _ (SOME false) _ accum = accum
  1954   | is_var_positively_naked_in_term name _ (ATerm ((s, _), tms)) accum =
  1956   | is_var_positively_naked_in_term name _ (ATerm (((s, _), _), tms)) accum =
  1955     accum orelse (is_tptp_equal s andalso member (op =) tms (ATerm (name, [])))
  1957     accum orelse
       
  1958     (is_tptp_equal s andalso member (op =) tms (ATerm ((name, []), [])))
  1956   | is_var_positively_naked_in_term _ _ _ _ = true
  1959   | is_var_positively_naked_in_term _ _ _ _ = true
  1957 
  1960 
  1958 fun is_var_positively_naked_or_undercover_in_term thy name pos tm accum =
  1961 fun is_var_positively_naked_or_undercover_in_term thy name pos tm accum =
  1959   is_var_positively_naked_in_term name pos tm accum orelse
  1962   is_var_positively_naked_in_term name pos tm accum orelse
  1960   let
  1963   let
  1961     val var = ATerm (name, [])
  1964     val var = ATerm ((name, []), [])
  1962     fun is_undercover (ATerm (_, [])) = false
  1965     fun is_undercover (ATerm (_, [])) = false
  1963       | is_undercover (ATerm ((s, _), tms)) =
  1966       | is_undercover (ATerm (((s, _), _), tms)) =
  1964         let
  1967         let
  1965           val ary = length tms
  1968           val ary = length tms
  1966           val cover = type_arg_cover thy s ary
  1969           val cover = type_arg_cover thy s ary
  1967         in
  1970         in
  1968           exists (fn (j, tm) => tm = var andalso member (op =) cover j)
  1971           exists (fn (j, tm) => tm = var andalso member (op =) cover j)
  1989     granularity_of_type_level level <> All_Vars andalso
  1992     granularity_of_type_level level <> All_Vars andalso
  1990     should_encode_type ctxt mono level T
  1993     should_encode_type ctxt mono level T
  1991   | should_generate_tag_bound_decl _ _ _ _ _ = false
  1994   | should_generate_tag_bound_decl _ _ _ _ _ = false
  1992 
  1995 
  1993 fun mk_aterm type_enc name T_args args =
  1996 fun mk_aterm type_enc name T_args args =
  1994   ATerm (name, map_filter (ho_term_for_type_arg type_enc) T_args @ args)
  1997 (* ### FIXME
       
  1998   if is_type_enc_polymorphic type_enc then
       
  1999     ATerm ((name, map (ho_type_from_typ type_enc false 0) T_args), args)
       
  2000   else *)
       
  2001     ATerm ((name, []), map_filter (ho_term_for_type_arg type_enc) T_args @ args)
  1995 
  2002 
  1996 fun do_bound_type ctxt mono type_enc =
  2003 fun do_bound_type ctxt mono type_enc =
  1997   case type_enc of
  2004   case type_enc of
  1998     Native (_, _, level) =>
  2005     Native (_, _, level) =>
  1999     fused_type ctxt mono level 0 #> ho_type_from_typ type_enc false 0 #> SOME
  2006     fused_type ctxt mono level 0 #> ho_type_from_typ type_enc false 0 #> SOME
  2001 
  2008 
  2002 fun tag_with_type ctxt mono type_enc pos T tm =
  2009 fun tag_with_type ctxt mono type_enc pos T tm =
  2003   IConst (type_tag, T --> T, [T])
  2010   IConst (type_tag, T --> T, [T])
  2004   |> mangle_type_args_in_iterm type_enc
  2011   |> mangle_type_args_in_iterm type_enc
  2005   |> ho_term_from_iterm ctxt mono type_enc pos
  2012   |> ho_term_from_iterm ctxt mono type_enc pos
  2006   |> (fn ATerm (s, tms) => ATerm (s, tms @ [tm])
  2013   |> (fn ATerm ((s, tys), tms) => ATerm ((s, tys), tms @ [tm])
  2007        | _ => raise Fail "unexpected lambda-abstraction")
  2014        | _ => raise Fail "unexpected lambda-abstraction")
  2008 and ho_term_from_iterm ctxt mono type_enc pos =
  2015 and ho_term_from_iterm ctxt mono type_enc pos =
  2009   let
  2016   let
  2010     fun term site u =
  2017     fun term site u =
  2011       let
  2018       let
  2049         IVar (name, T)
  2056         IVar (name, T)
  2050         |> type_guard_iterm type_enc T
  2057         |> type_guard_iterm type_enc T
  2051         |> do_term pos |> AAtom |> SOME
  2058         |> do_term pos |> AAtom |> SOME
  2052       else if should_generate_tag_bound_decl ctxt mono type_enc universal T then
  2059       else if should_generate_tag_bound_decl ctxt mono type_enc universal T then
  2053         let
  2060         let
  2054           val var = ATerm (name, [])
  2061           val var = ATerm ((name, []), [])
  2055           val tagged_var = tag_with_type ctxt mono type_enc pos T var
  2062           val tagged_var = tag_with_type ctxt mono type_enc pos T var
  2056         in SOME (AAtom (ATerm (`I tptp_equal, [tagged_var, var]))) end
  2063         in SOME (AAtom (ATerm ((`I tptp_equal, []), [tagged_var, var]))) end
  2057       else
  2064       else
  2058         NONE
  2065         NONE
  2059     fun do_formula pos (AQuant (q, xs, phi)) =
  2066     fun do_formula pos (AQuant (q, xs, phi)) =
  2060         let
  2067         let
  2061           val phi = phi |> do_formula pos
  2068           val phi = phi |> do_formula pos
  2099    end)
  2106    end)
  2100   |> Formula
  2107   |> Formula
  2101 
  2108 
  2102 fun formula_line_for_class_rel_clause type_enc
  2109 fun formula_line_for_class_rel_clause type_enc
  2103         ({name, subclass, superclass, ...} : class_rel_clause) =
  2110         ({name, subclass, superclass, ...} : class_rel_clause) =
  2104   let val ty_arg = ATerm (tvar_a_name, []) in
  2111   let val ty_arg = ATerm ((tvar_a_name, []), []) in
  2105     Formula (class_rel_clause_prefix ^ ascii_of name, Axiom,
  2112     Formula (class_rel_clause_prefix ^ ascii_of name, Axiom,
  2106              AConn (AImplies,
  2113              AConn (AImplies,
  2107                     [type_class_formula type_enc subclass ty_arg,
  2114                     [type_class_formula type_enc subclass ty_arg,
  2108                      type_class_formula type_enc superclass ty_arg])
  2115                      type_class_formula type_enc superclass ty_arg])
  2109              |> mk_aquant AForall
  2116              |> mk_aquant AForall
  2110                           [(tvar_a_name, atype_of_type_vars type_enc)],
  2117                           [(tvar_a_name, atype_of_type_vars type_enc)],
  2111              NONE, isabelle_info inductiveN helper_rank)
  2118              NONE, isabelle_info inductiveN helper_rank)
  2112   end
  2119   end
  2113 
  2120 
  2114 fun formula_from_arity_atom type_enc (class, t, args) =
  2121 fun formula_from_arity_atom type_enc (class, t, args) =
  2115   ATerm (t, map (fn arg => ATerm (arg, [])) args)
  2122   ATerm ((t, []), map (fn arg => ATerm ((arg, []), [])) args)
  2116   |> type_class_formula type_enc class
  2123   |> type_class_formula type_enc class
  2117 
  2124 
  2118 fun formula_line_for_arity_clause type_enc
  2125 fun formula_line_for_arity_clause type_enc
  2119         ({name, prem_atoms, concl_atom} : arity_clause) =
  2126         ({name, prem_atoms, concl_atom} : arity_clause) =
  2120   Formula (arity_clause_prefix ^ name, Axiom,
  2127   Formula (arity_clause_prefix ^ name, Axiom,
  2316            |> close_formula_universally
  2323            |> close_formula_universally
  2317            |> bound_tvars type_enc true (atomic_types_of T),
  2324            |> bound_tvars type_enc true (atomic_types_of T),
  2318            NONE, isabelle_info inductiveN helper_rank)
  2325            NONE, isabelle_info inductiveN helper_rank)
  2319 
  2326 
  2320 fun formula_line_for_tags_mono_type ctxt mono type_enc T =
  2327 fun formula_line_for_tags_mono_type ctxt mono type_enc T =
  2321   let val x_var = ATerm (`make_bound_var "X", []) in
  2328   let val x_var = ATerm ((`make_bound_var "X", []), []) in
  2322     Formula (tags_sym_formula_prefix ^
  2329     Formula (tags_sym_formula_prefix ^
  2323              ascii_of (mangled_type type_enc T),
  2330              ascii_of (mangled_type type_enc T),
  2324              Axiom,
  2331              Axiom,
  2325              eq_formula type_enc (atomic_types_of T) [] false
  2332              eq_formula type_enc (atomic_types_of T) [] false
  2326                   (tag_with_type ctxt mono type_enc NONE T x_var) x_var,
  2333                   (tag_with_type ctxt mono type_enc NONE T x_var) x_var,
  2400       tags_sym_formula_prefix ^ s ^
  2407       tags_sym_formula_prefix ^ s ^
  2401       (if n > 1 then "_" ^ string_of_int j else "")
  2408       (if n > 1 then "_" ^ string_of_int j else "")
  2402     val (role, maybe_negate) = honor_conj_sym_role in_conj
  2409     val (role, maybe_negate) = honor_conj_sym_role in_conj
  2403     val (arg_Ts, res_T) = chop_fun ary T
  2410     val (arg_Ts, res_T) = chop_fun ary T
  2404     val bound_names = 1 upto ary |> map (`I o make_bound_var o string_of_int)
  2411     val bound_names = 1 upto ary |> map (`I o make_bound_var o string_of_int)
  2405     val bounds = bound_names |> map (fn name => ATerm (name, []))
  2412     val bounds = bound_names |> map (fn name => ATerm ((name, []), []))
  2406     val cst = mk_aterm type_enc (s, s') T_args
  2413     val cst = mk_aterm type_enc (s, s') T_args
  2407     val eq = maybe_negate oo eq_formula type_enc (atomic_types_of T) [] pred_sym
  2414     val eq = maybe_negate oo eq_formula type_enc (atomic_types_of T) [] pred_sym
  2408     val should_encode = should_encode_type ctxt mono level
  2415     val should_encode = should_encode_type ctxt mono level
  2409     val tag_with = tag_with_type ctxt mono type_enc NONE
  2416     val tag_with = tag_with_type ctxt mono type_enc NONE
  2410     val add_formula_for_res =
  2417     val add_formula_for_res =
  2584     fun do_type (AType (name, tys)) =
  2591     fun do_type (AType (name, tys)) =
  2585         do_sym name (fn () => nary_type_constr_type (length tys))
  2592         do_sym name (fn () => nary_type_constr_type (length tys))
  2586         #> fold do_type tys
  2593         #> fold do_type tys
  2587       | do_type (AFun (ty1, ty2)) = do_type ty1 #> do_type ty2
  2594       | do_type (AFun (ty1, ty2)) = do_type ty1 #> do_type ty2
  2588       | do_type (ATyAbs (_, ty)) = do_type ty
  2595       | do_type (ATyAbs (_, ty)) = do_type ty
  2589     fun do_term pred_sym (ATerm (name as (s, _), tms)) =
  2596     fun do_term pred_sym (ATerm ((name as (s, _), tys), tms)) =
  2590         do_sym name (fn _ => default_type type_enc pred_sym s (length tms))
  2597         do_sym name (fn _ => default_type type_enc pred_sym s (length tms))
  2591         #> fold (do_term false) tms
  2598         #> fold do_type tys #> fold (do_term false) tms
  2592       | do_term _ (AAbs (((_, ty), tm), args)) =
  2599       | do_term _ (AAbs (((_, ty), tm), args)) =
  2593         do_type ty #> do_term false tm #> fold (do_term false) args
  2600         do_type ty #> do_term false tm #> fold (do_term false) args
  2594     fun do_formula (AQuant (_, xs, phi)) =
  2601     fun do_formula (AQuant (_, xs, phi)) =
  2595         fold do_type (map_filter snd xs) #> do_formula phi
  2602         fold do_type (map_filter snd xs) #> do_formula phi
  2596       | do_formula (AConn (_, phis)) = fold do_formula phis
  2603       | do_formula (AConn (_, phis)) = fold do_formula phis
  2736 val type_info_default_weight = 0.8
  2743 val type_info_default_weight = 0.8
  2737 
  2744 
  2738 (* Weights are from 0.0 (most important) to 1.0 (least important). *)
  2745 (* Weights are from 0.0 (most important) to 1.0 (least important). *)
  2739 fun atp_problem_selection_weights problem =
  2746 fun atp_problem_selection_weights problem =
  2740   let
  2747   let
  2741     fun add_term_weights weight (ATerm (s, tms)) =
  2748     fun add_term_weights weight (ATerm ((s, _), tms)) =
  2742         is_tptp_user_symbol s ? Symtab.default (s, weight)
  2749         is_tptp_user_symbol s ? Symtab.default (s, weight)
  2743         #> fold (add_term_weights weight) tms
  2750         #> fold (add_term_weights weight) tms
  2744       | add_term_weights weight (AAbs ((_, tm), args)) =
  2751       | add_term_weights weight (AAbs ((_, tm), args)) =
  2745         add_term_weights weight tm #> fold (add_term_weights weight) args
  2752         add_term_weights weight tm #> fold (add_term_weights weight) args
  2746     fun add_line_weights weight (Formula (_, _, phi, _, _)) =
  2753     fun add_line_weights weight (Formula (_, _, phi, _, _)) =
  2776 (* Ugly hack: may make innocent victims (collateral damage) *)
  2783 (* Ugly hack: may make innocent victims (collateral damage) *)
  2777 fun may_be_app s args = String.isPrefix app_op_name s andalso length args = 2
  2784 fun may_be_app s args = String.isPrefix app_op_name s andalso length args = 2
  2778 fun may_be_predicator s =
  2785 fun may_be_predicator s =
  2779   member (op =) [predicator_name, prefixed_predicator_name] s
  2786   member (op =) [predicator_name, prefixed_predicator_name] s
  2780 
  2787 
  2781 fun strip_predicator (tm as ATerm (s, [tm'])) =
  2788 fun strip_predicator (tm as ATerm ((s, _), [tm'])) =
  2782     if may_be_predicator s then tm' else tm
  2789     if may_be_predicator s then tm' else tm
  2783   | strip_predicator tm = tm
  2790   | strip_predicator tm = tm
  2784 
  2791 
  2785 fun make_head_roll (ATerm (s, tms)) =
  2792 fun make_head_roll (ATerm ((s, _), tms)) =
  2786     if may_be_app s tms then make_head_roll (hd tms) ||> append (tl tms)
  2793     if may_be_app s tms then make_head_roll (hd tms) ||> append (tl tms)
  2787     else (s, tms)
  2794     else (s, tms)
  2788   | make_head_roll _ = ("", [])
  2795   | make_head_roll _ = ("", [])
  2789 
  2796 
  2790 fun strip_up_to_predicator (AQuant (_, _, phi)) = strip_up_to_predicator phi
  2797 fun strip_up_to_predicator (AQuant (_, _, phi)) = strip_up_to_predicator phi
  2807   let
  2814   let
  2808     fun add_edge s s' =
  2815     fun add_edge s s' =
  2809       Graph.default_node (s, ())
  2816       Graph.default_node (s, ())
  2810       #> Graph.default_node (s', ())
  2817       #> Graph.default_node (s', ())
  2811       #> Graph.add_edge_acyclic (s, s')
  2818       #> Graph.add_edge_acyclic (s, s')
  2812     fun add_term_deps head (ATerm (s, args)) =
  2819     fun add_term_deps head (ATerm ((s, _), args)) =
  2813         if is_tptp_user_symbol head then
  2820         if is_tptp_user_symbol head then
  2814           (if is_tptp_user_symbol s then perhaps (try (add_edge s head)) else I)
  2821           (if is_tptp_user_symbol s then perhaps (try (add_edge s head)) else I)
  2815           #> fold (add_term_deps head) args
  2822           #> fold (add_term_deps head) args
  2816         else
  2823         else
  2817           I
  2824           I
  2825             | _ => I
  2832             | _ => I
  2826           end
  2833           end
  2827         else
  2834         else
  2828           I
  2835           I
  2829       | add_intro_deps _ _ = I
  2836       | add_intro_deps _ _ = I
  2830     fun add_atom_eq_deps (SOME true) (ATerm (s, [lhs as _, rhs])) =
  2837     fun add_atom_eq_deps (SOME true) (ATerm ((s, _), [lhs as _, rhs])) =
  2831         if is_tptp_equal s then
  2838         if is_tptp_equal s then
  2832           case make_head_roll lhs of
  2839           case make_head_roll lhs of
  2833             (head, args as _ :: _) => fold (add_term_deps head) (rhs :: args)
  2840             (head, args as _ :: _) => fold (add_term_deps head) (rhs :: args)
  2834           | _ => I
  2841           | _ => I
  2835         else
  2842         else