5 *) |
5 *) |
6 |
6 |
7 signature SLEDGEHAMMER_MASH = |
7 signature SLEDGEHAMMER_MASH = |
8 sig |
8 sig |
9 type stature = ATP_Problem_Generate.stature |
9 type stature = ATP_Problem_Generate.stature |
|
10 type raw_fact = Sledgehammer_Fact.raw_fact |
10 type fact = Sledgehammer_Fact.fact |
11 type fact = Sledgehammer_Fact.fact |
11 type fact_override = Sledgehammer_Fact.fact_override |
12 type fact_override = Sledgehammer_Fact.fact_override |
12 type params = Sledgehammer_Provers.params |
13 type params = Sledgehammer_Provers.params |
13 type relevance_fudge = Sledgehammer_Provers.relevance_fudge |
14 type relevance_fudge = Sledgehammer_Provers.relevance_fudge |
14 type prover_result = Sledgehammer_Provers.prover_result |
15 type prover_result = Sledgehammer_Provers.prover_result |
60 -> (string * real) list |
61 -> (string * real) list |
61 val trim_dependencies : thm -> string list -> string list option |
62 val trim_dependencies : thm -> string list -> string list option |
62 val isar_dependencies_of : |
63 val isar_dependencies_of : |
63 string Symtab.table * string Symtab.table -> thm -> string list |
64 string Symtab.table * string Symtab.table -> thm -> string list |
64 val prover_dependencies_of : |
65 val prover_dependencies_of : |
65 Proof.context -> params -> string -> int -> fact list |
66 Proof.context -> params -> string -> int -> raw_fact list |
66 -> string Symtab.table * string Symtab.table -> thm |
67 -> string Symtab.table * string Symtab.table -> thm |
67 -> bool * string list |
68 -> bool * string list |
68 val weight_mepo_facts : 'a list -> ('a * real) list |
69 val weight_mepo_facts : 'a list -> ('a * real) list |
69 val weight_mash_facts : 'a list -> ('a * real) list |
70 val weight_mash_facts : 'a list -> ('a * real) list |
70 val find_mash_suggestions : |
71 val find_mash_suggestions : |
71 int -> string list -> ('b * thm) list -> ('b * thm) list -> ('b * thm) list |
72 int -> string list -> ('b * thm) list -> ('b * thm) list -> ('b * thm) list |
72 -> ('b * thm) list * ('b * thm) list |
73 -> ('b * thm) list * ('b * thm) list |
73 val mash_suggested_facts : |
74 val mash_suggested_facts : |
74 Proof.context -> params -> string -> int -> term list -> term -> fact list |
75 Proof.context -> params -> string -> int -> term list -> term |
75 -> fact list * fact list |
76 -> raw_fact list -> fact list * fact list |
76 val mash_learn_proof : |
77 val mash_learn_proof : |
77 Proof.context -> params -> string -> term -> ('a * thm) list -> thm list |
78 Proof.context -> params -> string -> term -> ('a * thm) list -> thm list |
78 -> unit |
79 -> unit |
79 val mash_learn : |
80 val mash_learn : |
80 Proof.context -> params -> fact_override -> thm list -> bool -> unit |
81 Proof.context -> params -> fact_override -> thm list -> bool -> unit |
83 val generous_max_facts : int -> int |
84 val generous_max_facts : int -> int |
84 val mepo_weight : real |
85 val mepo_weight : real |
85 val mash_weight : real |
86 val mash_weight : real |
86 val relevant_facts : |
87 val relevant_facts : |
87 Proof.context -> params -> string -> int -> fact_override -> term list |
88 Proof.context -> params -> string -> int -> fact_override -> term list |
88 -> term -> fact list -> fact list * fact list * fact list |
89 -> term -> raw_fact list -> fact list * fact list * fact list |
89 val kill_learners : unit -> unit |
90 val kill_learners : unit -> unit |
90 val running_learners : unit -> unit |
91 val running_learners : unit -> unit |
91 end; |
92 end; |
92 |
93 |
93 structure Sledgehammer_MaSh : SLEDGEHAMMER_MASH = |
94 structure Sledgehammer_MaSh : SLEDGEHAMMER_MASH = |
529 |
530 |
530 fun run_prover_for_mash ctxt params prover facts goal = |
531 fun run_prover_for_mash ctxt params prover facts goal = |
531 let |
532 let |
532 val problem = |
533 val problem = |
533 {state = Proof.init ctxt, goal = goal, subgoal = 1, subgoal_count = 1, |
534 {state = Proof.init ctxt, goal = goal, subgoal = 1, subgoal_count = 1, |
534 facts = facts |> map (apfst (apfst (fn name => name ()))) |
535 facts = facts |> map Untranslated_Fact} |
535 |> map Untranslated_Fact} |
|
536 in |
536 in |
537 get_minimizing_isar_prover ctxt MaSh (K (K ())) prover params (K (K (K ""))) |
537 get_minimizing_isar_prover ctxt MaSh (K (K ())) prover params (K (K (K ""))) |
538 problem |
538 problem |
539 end |
539 end |
540 |
540 |
685 let |
685 let |
686 val thy = Proof_Context.theory_of ctxt |
686 val thy = Proof_Context.theory_of ctxt |
687 val goal = goal_of_thm thy th |
687 val goal = goal_of_thm thy th |
688 val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1 |
688 val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1 |
689 val facts = facts |> filter (fn (_, th') => thm_ord (th', th) = LESS) |
689 val facts = facts |> filter (fn (_, th') => thm_ord (th', th) = LESS) |
690 fun nickify ((_, stature), th) = |
690 fun nickify ((_, stature), th) = ((nickname_of_thm th, stature), th) |
691 ((fn () => nickname_of_thm th, stature), th) |
|
692 fun is_dep dep (_, th) = nickname_of_thm th = dep |
691 fun is_dep dep (_, th) = nickname_of_thm th = dep |
693 fun add_isar_dep facts dep accum = |
692 fun add_isar_dep facts dep accum = |
694 if exists (is_dep dep) accum then |
693 if exists (is_dep dep) accum then |
695 accum |
694 accum |
696 else case find_first (is_dep dep) facts of |
695 else case find_first (is_dep dep) facts of |
697 SOME ((name, status), th) => accum @ [((name, status), th)] |
696 SOME ((_, status), th) => accum @ [(("", status), th)] |
698 | NONE => accum (* shouldn't happen *) |
697 | NONE => accum (* shouldn't happen *) |
699 val facts = |
698 val facts = |
700 facts |
699 facts |
701 |> mepo_suggested_facts ctxt params prover |
700 |> mepo_suggested_facts ctxt params prover |
702 (max_facts |> the_default prover_dependency_default_max_facts) |
701 (max_facts |> the_default prover_dependency_default_max_facts) |
823 in |
822 in |
824 (access_G, MaSh.query ctxt overlord learn max_facts |
823 (access_G, MaSh.query ctxt overlord learn max_facts |
825 (parents, feats, hints)) |
824 (parents, feats, hints)) |
826 end) |
825 end) |
827 val unknown = facts |> filter_out (is_fact_in_graph access_G snd) |
826 val unknown = facts |> filter_out (is_fact_in_graph access_G snd) |
828 in find_mash_suggestions max_facts suggs facts chained unknown end |
827 in |
|
828 find_mash_suggestions max_facts suggs facts chained unknown |
|
829 |> pairself (map fact_of_raw_fact) |
|
830 end |
829 |
831 |
830 fun learn_wrt_access_graph ctxt (name, parents, feats, deps) (learns, graph) = |
832 fun learn_wrt_access_graph ctxt (name, parents, feats, deps) (learns, graph) = |
831 let |
833 let |
832 fun maybe_learn_from from (accum as (parents, graph)) = |
834 fun maybe_learn_from from (accum as (parents, graph)) = |
833 try_graph ctxt "updating graph" accum (fn () => |
835 try_graph ctxt "updating graph" accum (fn () => |
1097 fun relevant_facts ctxt (params as {learn, fact_filter, timeout, ...}) prover |
1099 fun relevant_facts ctxt (params as {learn, fact_filter, timeout, ...}) prover |
1098 max_facts ({add, only, ...} : fact_override) hyp_ts concl_t facts = |
1100 max_facts ({add, only, ...} : fact_override) hyp_ts concl_t facts = |
1099 if not (subset (op =) (the_list fact_filter, fact_filters)) then |
1101 if not (subset (op =) (the_list fact_filter, fact_filters)) then |
1100 error ("Unknown fact filter: " ^ quote (the fact_filter) ^ ".") |
1102 error ("Unknown fact filter: " ^ quote (the fact_filter) ^ ".") |
1101 else if only then |
1103 else if only then |
1102 (facts, facts, facts) |
1104 let val facts = facts |> map fact_of_raw_fact in |
|
1105 (facts, facts, facts) |
|
1106 end |
1103 else if max_facts <= 0 orelse null facts then |
1107 else if max_facts <= 0 orelse null facts then |
1104 ([], [], []) |
1108 ([], [], []) |
1105 else |
1109 else |
1106 let |
1110 let |
1107 fun maybe_learn () = |
1111 fun maybe_learn () = |
1127 (maybe_learn (); |
1131 (maybe_learn (); |
1128 if mash_can_suggest_facts ctxt then meshN else mepoN) |
1132 if mash_can_suggest_facts ctxt then meshN else mepoN) |
1129 else |
1133 else |
1130 mepoN |
1134 mepoN |
1131 val add_ths = Attrib.eval_thms ctxt add |
1135 val add_ths = Attrib.eval_thms ctxt add |
1132 val in_add = member Thm.eq_thm_prop add_ths o snd |
1136 fun in_add (_, th) = member Thm.eq_thm_prop add_ths th |
1133 fun add_and_take accepts = |
1137 fun add_and_take accepts = |
1134 (case add_ths of |
1138 (case add_ths of |
1135 [] => accepts |
1139 [] => accepts |
1136 | _ => (facts |> filter in_add) @ (accepts |> filter_out in_add)) |
1140 | _ => (facts |> filter in_add |> map fact_of_raw_fact) @ |
|
1141 (accepts |> filter_out in_add)) |
1137 |> take max_facts |
1142 |> take max_facts |
1138 fun mepo () = |
1143 fun mepo () = |
1139 mepo_suggested_facts ctxt params prover max_facts NONE hyp_ts concl_t |
1144 mepo_suggested_facts ctxt params prover max_facts NONE hyp_ts concl_t |
1140 facts |
1145 facts |
1141 |> weight_mepo_facts |
1146 |> weight_mepo_facts |