72 -> string Symtab.table * string Symtab.table -> thm |
72 -> string Symtab.table * string Symtab.table -> thm |
73 -> bool * string list |
73 -> bool * string list |
74 val attach_parents_to_facts : |
74 val attach_parents_to_facts : |
75 ('a * thm) list -> ('a * thm) list -> (string list * ('a * thm)) list |
75 ('a * thm) list -> ('a * thm) list -> (string list * ('a * thm)) list |
76 val num_extra_feature_facts : int |
76 val num_extra_feature_facts : int |
77 val extra_feature_weight_factor : real |
77 val extra_feature_factor : real |
78 val weight_facts_smoothly : 'a list -> ('a * real) list |
78 val weight_facts_smoothly : 'a list -> ('a * real) list |
79 val weight_facts_steeply : 'a list -> ('a * real) list |
79 val weight_facts_steeply : 'a list -> ('a * real) list |
80 val find_mash_suggestions : |
80 val find_mash_suggestions : |
81 Proof.context -> int -> string list -> ('b * thm) list -> ('b * thm) list |
81 Proof.context -> int -> string list -> ('b * thm) list -> ('b * thm) list |
82 -> ('b * thm) list -> ('b * thm) list * ('b * thm) list |
82 -> ('b * thm) list -> ('b * thm) list * ('b * thm) list |
516 fun class_feature_of s = ("s" ^ s, 1.0 (* FUDGE *)) |
516 fun class_feature_of s = ("s" ^ s, 1.0 (* FUDGE *)) |
517 fun status_feature_of status = (string_of_status status, 2.0 (* FUDGE *)) |
517 fun status_feature_of status = (string_of_status status, 2.0 (* FUDGE *)) |
518 val local_feature = ("local", 8.0 (* FUDGE *)) |
518 val local_feature = ("local", 8.0 (* FUDGE *)) |
519 val lams_feature = ("lams", 2.0 (* FUDGE *)) |
519 val lams_feature = ("lams", 2.0 (* FUDGE *)) |
520 val skos_feature = ("skos", 2.0 (* FUDGE *)) |
520 val skos_feature = ("skos", 2.0 (* FUDGE *)) |
521 |
|
522 (* The following "crude" functions should be progressively phased out, since |
|
523 they create visibility edges that do not exist in Isabelle, resulting in |
|
524 failed lookups later on. *) |
|
525 |
521 |
526 fun crude_theory_ord p = |
522 fun crude_theory_ord p = |
527 if Theory.subthy p then |
523 if Theory.subthy p then |
528 if Theory.eq_thy p then EQUAL else LESS |
524 if Theory.eq_thy p then EQUAL else LESS |
529 else if Theory.subthy (swap p) then |
525 else if Theory.subthy (swap p) then |
903 map (nickname_of_thm o snd) |
899 map (nickname_of_thm o snd) |
904 #> maximal_wrt_graph access_G |
900 #> maximal_wrt_graph access_G |
905 |
901 |
906 fun is_fact_in_graph access_G = can (Graph.get_node access_G) o nickname_of_thm |
902 fun is_fact_in_graph access_G = can (Graph.get_node access_G) o nickname_of_thm |
907 |
903 |
|
904 val chained_feature_factor = 0.5 |
|
905 val extra_feature_factor = 0.1 |
908 val num_extra_feature_facts = 10 (* FUDGE *) |
906 val num_extra_feature_facts = 10 (* FUDGE *) |
909 val extra_feature_weight_factor = 0.1 |
|
910 |
907 |
911 (* FUDGE *) |
908 (* FUDGE *) |
912 fun weight_of_proximity_fact rank = |
909 fun weight_of_proximity_fact rank = |
913 Math.pow (1.3, 15.5 - 0.2 * Real.fromInt rank) + 15.0 |
910 Math.pow (1.3, 15.5 - 0.2 * Real.fromInt rank) + 15.0 |
914 |
911 |
928 | find_mash_suggestions ctxt max_facts suggs facts chained raw_unknown = |
925 | find_mash_suggestions ctxt max_facts suggs facts chained raw_unknown = |
929 let |
926 let |
930 val raw_mash = find_suggested_facts ctxt facts suggs |
927 val raw_mash = find_suggested_facts ctxt facts suggs |
931 val unknown_chained = |
928 val unknown_chained = |
932 inter (Thm.eq_thm_prop o pairself snd) chained raw_unknown |
929 inter (Thm.eq_thm_prop o pairself snd) chained raw_unknown |
933 val proximity = |
930 val proximity = facts |> take max_proximity_facts |
934 facts |> sort (crude_thm_ord o pairself snd o swap) |
|
935 |> take max_proximity_facts |
|
936 val mess = |
931 val mess = |
937 [(0.90 (* FUDGE *), (map (rpair 1.0) unknown_chained, [])), |
932 [(0.90 (* FUDGE *), (map (rpair 1.0) unknown_chained, [])), |
938 (0.08 (* FUDGE *), (weight_facts_steeply raw_mash, raw_unknown)), |
933 (0.08 (* FUDGE *), (weight_facts_steeply raw_mash, raw_unknown)), |
939 (0.02 (* FUDGE *), (weight_facts_smoothly proximity, []))] |
934 (0.02 (* FUDGE *), (weight_facts_smoothly proximity, []))] |
940 val unknown = |
935 val unknown = |
949 |
944 |
950 fun mash_suggested_facts ctxt ({overlord, ...} : params) prover max_facts hyp_ts |
945 fun mash_suggested_facts ctxt ({overlord, ...} : params) prover max_facts hyp_ts |
951 concl_t facts = |
946 concl_t facts = |
952 let |
947 let |
953 val thy = Proof_Context.theory_of ctxt |
948 val thy = Proof_Context.theory_of ctxt |
|
949 val facts = facts |> sort (crude_thm_ord o pairself snd o swap) |
954 val chained = facts |> filter (fn ((_, (scope, _)), _) => scope = Chained) |
950 val chained = facts |> filter (fn ((_, (scope, _)), _) => scope = Chained) |
|
951 val num_facts = length facts |
955 val const_tab = fold (add_const_counts o prop_of o snd) facts Symtab.empty |
952 val const_tab = fold (add_const_counts o prop_of o snd) facts Symtab.empty |
|
953 fun chained_or_extra_features_of factor (((_, stature), th), weight) = |
|
954 [prop_of th] |
|
955 |> features_of ctxt prover (theory_of_thm th) num_facts const_tab stature |
|
956 |> map (apsnd (fn r => weight * factor * r)) |
956 val (access_G, suggs) = |
957 val (access_G, suggs) = |
957 peek_state ctxt (fn {access_G, ...} => |
958 peek_state ctxt (fn {access_G, ...} => |
958 if Graph.is_empty access_G then |
959 if Graph.is_empty access_G then |
959 (access_G, []) |
960 (access_G, []) |
960 else |
961 else |
961 let |
962 let |
962 val parents = maximal_wrt_access_graph access_G facts |
963 val parents = maximal_wrt_access_graph access_G facts |
|
964 val goal_feats = |
|
965 features_of ctxt prover thy num_facts const_tab |
|
966 (Local, General) (concl_t :: hyp_ts) |
|
967 val chained_feats = |
|
968 chained |
|
969 |> map (rpair 1.0) |
|
970 |> map (chained_or_extra_features_of chained_feature_factor) |
|
971 |> rpair [] |-> fold (union (op = o pairself fst)) |
|
972 val extra_feats = |
|
973 facts |
|
974 |> take (num_extra_feature_facts - length chained) |
|
975 |> weight_facts_steeply |
|
976 |> map (chained_or_extra_features_of extra_feature_factor) |
|
977 |> rpair [] |-> fold (union (op = o pairself fst)) |
963 val feats = |
978 val feats = |
964 features_of ctxt prover thy (length facts) const_tab |
979 fold (union (op = o pairself fst)) [chained_feats, extra_feats] |
965 (Local, General) (concl_t :: hyp_ts) |
980 goal_feats |
966 val hints = |
981 val hints = |
967 chained |> filter (is_fact_in_graph access_G o snd) |
982 chained |> filter (is_fact_in_graph access_G o snd) |
968 |> map (nickname_of_thm o snd) |
983 |> map (nickname_of_thm o snd) |
969 in |
984 in |
970 (access_G, MaSh.query ctxt overlord max_facts |
985 (access_G, MaSh.query ctxt overlord max_facts |