10 type params = Sledgehammer_Provers.params |
10 type params = Sledgehammer_Provers.params |
11 |
11 |
12 val generate_accessibility : |
12 val generate_accessibility : |
13 Proof.context -> theory list -> bool -> string -> unit |
13 Proof.context -> theory list -> bool -> string -> unit |
14 val generate_features : |
14 val generate_features : |
15 Proof.context -> string -> theory list -> bool -> string -> unit |
15 Proof.context -> string -> theory list -> string -> unit |
16 val generate_isar_dependencies : |
16 val generate_isar_dependencies : |
17 Proof.context -> theory list -> bool -> string -> unit |
17 Proof.context -> theory list -> bool -> string -> unit |
18 val generate_prover_dependencies : |
18 val generate_prover_dependencies : |
19 Proof.context -> params -> int * int option -> theory list -> bool -> string |
19 Proof.context -> params -> int * int option -> theory list -> bool -> string |
20 -> unit |
20 -> unit |
21 val generate_isar_commands : |
21 val generate_isar_commands : |
22 Proof.context -> string -> (int * int option) * int -> theory list -> string |
22 Proof.context -> string -> (int * int option) * int -> theory list -> bool |
23 -> unit |
23 -> string -> unit |
24 val generate_prover_commands : |
24 val generate_prover_commands : |
25 Proof.context -> params -> (int * int option) * int -> theory list -> string |
25 Proof.context -> params -> (int * int option) * int -> theory list -> bool |
26 -> unit |
26 -> string -> unit |
27 val generate_mepo_suggestions : |
27 val generate_mepo_suggestions : |
28 Proof.context -> params -> (int * int option) * int -> theory list -> int |
28 Proof.context -> params -> (int * int option) * int -> theory list -> bool |
29 -> string -> unit |
29 -> int -> string -> unit |
30 val generate_mesh_suggestions : int -> string -> string -> string -> unit |
30 val generate_mesh_suggestions : int -> string -> string -> string -> unit |
31 end; |
31 end; |
32 |
32 |
33 structure MaSh_Export : MASH_EXPORT = |
33 structure MaSh_Export : MASH_EXPORT = |
34 struct |
34 struct |
49 let val css = Sledgehammer_Fact.clasimpset_rule_table_of ctxt in |
49 let val css = Sledgehammer_Fact.clasimpset_rule_table_of ctxt in |
50 Sledgehammer_Fact.all_facts ctxt true false Symtab.empty [] [] css |
50 Sledgehammer_Fact.all_facts ctxt true false Symtab.empty [] [] css |
51 |> sort (crude_thm_ord o pairself snd) |
51 |> sort (crude_thm_ord o pairself snd) |
52 end |
52 end |
53 |
53 |
54 fun generate_accessibility ctxt thys include_thys file_name = |
54 fun filter_accessible_from th = filter (fn (_, th') => thm_less (th', th)) |
|
55 |
|
56 fun generate_accessibility ctxt thys linearize file_name = |
55 let |
57 let |
56 val path = file_name |> Path.explode |
58 val path = file_name |> Path.explode |
57 val _ = File.write path "" |
59 val _ = File.write path "" |
58 fun do_fact fact prevs = |
60 fun do_fact (parents, fact) prevs = |
59 let |
61 let |
60 val s = encode_str fact ^ ": " ^ encode_strs prevs ^ "\n" |
62 val parents = if linearize then prevs else parents |
|
63 val s = encode_str fact ^ ": " ^ encode_strs parents ^ "\n" |
61 val _ = File.append path s |
64 val _ = File.append path s |
62 in [fact] end |
65 in [fact] end |
63 val facts = |
66 val facts = |
64 all_facts ctxt |
67 all_facts ctxt |
65 |> not include_thys ? filter_out (has_thys thys o snd) |
68 |> filter_out (has_thys thys o snd) |
66 |> map (snd #> nickname_of_thm) |
69 |> attach_parents_to_facts [] |
|
70 |> map (apsnd (nickname_of_thm o snd)) |
67 in fold do_fact facts []; () end |
71 in fold do_fact facts []; () end |
68 |
72 |
69 fun generate_features ctxt prover thys include_thys file_name = |
73 fun generate_features ctxt prover thys file_name = |
70 let |
74 let |
71 val path = file_name |> Path.explode |
75 val path = file_name |> Path.explode |
72 val _ = File.write path "" |
76 val _ = File.write path "" |
73 val facts = |
77 val facts = all_facts ctxt |> filter_out (has_thys thys o snd) |
74 all_facts ctxt |
|
75 |> not include_thys ? filter_out (has_thys thys o snd) |
|
76 fun do_fact ((_, stature), th) = |
78 fun do_fact ((_, stature), th) = |
77 let |
79 let |
78 val name = nickname_of_thm th |
80 val name = nickname_of_thm th |
79 val feats = |
81 val feats = |
80 features_of ctxt prover (theory_of_thm th) stature [prop_of th] |
82 features_of ctxt prover (theory_of_thm th) stature [prop_of th] |
107 case trim_dependencies deps of |
109 case trim_dependencies deps of |
108 SOME deps => (marker, deps) |
110 SOME deps => (marker, deps) |
109 | NONE => (omitted_marker, []) |
111 | NONE => (omitted_marker, []) |
110 end |
112 end |
111 |
113 |
112 fun generate_isar_or_prover_dependencies ctxt params_opt range thys include_thys |
114 fun generate_isar_or_prover_dependencies ctxt params_opt range thys linearize |
113 file_name = |
115 file_name = |
114 let |
116 let |
115 val path = file_name |> Path.explode |
117 val path = file_name |> Path.explode |
116 val facts = |
118 val facts = all_facts ctxt |> filter_out (has_thys thys o snd) |
117 all_facts ctxt |> not include_thys ? filter_out (has_thys thys o snd) |
|
118 val name_tabs = build_name_tables nickname_of_thm facts |
119 val name_tabs = build_name_tables nickname_of_thm facts |
119 fun do_fact (j, (_, th)) = |
120 fun do_fact (j, (_, th)) = |
120 if in_range range j then |
121 if in_range range j then |
121 let |
122 let |
122 val name = nickname_of_thm th |
123 val name = nickname_of_thm th |
123 val _ = tracing ("Fact " ^ string_of_int j ^ ": " ^ name) |
124 val _ = tracing ("Fact " ^ string_of_int j ^ ": " ^ name) |
|
125 val access_facts = |
|
126 if linearize then take (j - 1) facts |
|
127 else facts |> filter_accessible_from th |
124 val (marker, deps) = |
128 val (marker, deps) = |
125 smart_dependencies_of ctxt params_opt facts name_tabs th NONE |
129 smart_dependencies_of ctxt params_opt access_facts name_tabs th NONE |
126 in encode_str name ^ ": " ^ marker ^ " " ^ encode_strs deps ^ "\n" end |
130 in encode_str name ^ ": " ^ marker ^ " " ^ encode_strs deps ^ "\n" end |
127 else |
131 else |
128 "" |
132 "" |
129 val lines = Par_List.map do_fact (tag_list 1 facts) |
133 val lines = Par_List.map do_fact (tag_list 1 facts) |
130 in File.write_list path lines end |
134 in File.write_list path lines end |
140 Thm.legacy_get_kind th = "" orelse |
144 Thm.legacy_get_kind th = "" orelse |
141 null isar_deps orelse |
145 null isar_deps orelse |
142 is_blacklisted_or_something ctxt ho_atp (Thm.get_name_hint th) |
146 is_blacklisted_or_something ctxt ho_atp (Thm.get_name_hint th) |
143 |
147 |
144 fun generate_isar_or_prover_commands ctxt prover params_opt (range, step) thys |
148 fun generate_isar_or_prover_commands ctxt prover params_opt (range, step) thys |
145 file_name = |
149 linearize file_name = |
146 let |
150 let |
147 val ho_atp = Sledgehammer_Provers.is_ho_atp ctxt prover |
151 val ho_atp = Sledgehammer_Provers.is_ho_atp ctxt prover |
148 val path = file_name |> Path.explode |
152 val path = file_name |> Path.explode |
149 val facts = all_facts ctxt |
153 val facts = all_facts ctxt |
150 val (new_facts, old_facts) = facts |> List.partition (has_thys thys o snd) |
154 val (new_facts, old_facts) = facts |> List.partition (has_thys thys o snd) |
151 val name_tabs = build_name_tables nickname_of_thm facts |
155 val name_tabs = build_name_tables nickname_of_thm facts |
152 fun do_fact (j, ((name, ((_, stature), th)), prevs)) = |
156 fun do_fact (j, ((name, (parents, ((_, stature), th))), prevs)) = |
153 if in_range range j then |
157 if in_range range j then |
154 let |
158 let |
155 val _ = tracing ("Fact " ^ string_of_int j ^ ": " ^ name) |
159 val _ = tracing ("Fact " ^ string_of_int j ^ ": " ^ name) |
156 val feats = |
160 val feats = |
157 features_of ctxt prover (theory_of_thm th) stature [prop_of th] |
161 features_of ctxt prover (theory_of_thm th) stature [prop_of th] |
158 val isar_deps = isar_dependencies_of name_tabs th |
162 val isar_deps = isar_dependencies_of name_tabs th |
|
163 val access_facts = |
|
164 (if linearize then take (j - 1) new_facts |
|
165 else new_facts |> filter_accessible_from th) @ old_facts |
159 val (marker, deps) = |
166 val (marker, deps) = |
160 smart_dependencies_of ctxt params_opt facts name_tabs th |
167 smart_dependencies_of ctxt params_opt access_facts name_tabs th |
161 (SOME isar_deps) |
168 (SOME isar_deps) |
|
169 val parents = if linearize then prevs else parents |
162 val core = |
170 val core = |
163 encode_str name ^ ": " ^ encode_strs prevs ^ "; " ^ |
171 encode_str name ^ ": " ^ encode_strs parents ^ "; " ^ |
164 encode_features (sort_wrt fst feats) |
172 encode_features (sort_wrt fst feats) |
165 val query = |
173 val query = |
166 if is_bad_query ctxt ho_atp step j th isar_deps then "" |
174 if is_bad_query ctxt ho_atp step j th isar_deps then "" |
167 else "? " ^ core ^ "\n" |
175 else "? " ^ core ^ "\n" |
168 val update = |
176 val update = |
169 "! " ^ core ^ "; " ^ marker ^ " " ^ encode_strs deps ^ "\n" |
177 "! " ^ core ^ "; " ^ marker ^ " " ^ encode_strs deps ^ "\n" |
170 in query ^ update end |
178 in query ^ update end |
171 else |
179 else |
172 "" |
180 "" |
173 val parents = |
181 val new_facts = |
|
182 new_facts |> attach_parents_to_facts old_facts |
|
183 |> map (`(nickname_of_thm o snd o snd)) |
|
184 val hd_prevs = |
174 map (nickname_of_thm o snd) (the_list (try List.last old_facts)) |
185 map (nickname_of_thm o snd) (the_list (try List.last old_facts)) |
175 val new_facts = new_facts |> map (`(nickname_of_thm o snd)) |
186 val prevss = fst (split_last (hd_prevs :: map (single o fst) new_facts)) |
176 val prevss = fst (split_last (parents :: map (single o fst) new_facts)) |
|
177 val lines = Par_List.map do_fact (tag_list 1 (new_facts ~~ prevss)) |
187 val lines = Par_List.map do_fact (tag_list 1 (new_facts ~~ prevss)) |
178 in File.write_list path lines end |
188 in File.write_list path lines end |
179 |
189 |
180 fun generate_isar_commands ctxt prover = |
190 fun generate_isar_commands ctxt prover = |
181 generate_isar_or_prover_commands ctxt prover NONE |
191 generate_isar_or_prover_commands ctxt prover NONE |
182 |
192 |
183 fun generate_prover_commands ctxt (params as {provers = prover :: _, ...}) = |
193 fun generate_prover_commands ctxt (params as {provers = prover :: _, ...}) = |
184 generate_isar_or_prover_commands ctxt prover (SOME params) |
194 generate_isar_or_prover_commands ctxt prover (SOME params) |
185 |
195 |
186 fun generate_mepo_suggestions ctxt (params as {provers = prover :: _, ...}) |
196 fun generate_mepo_suggestions ctxt (params as {provers = prover :: _, ...}) |
187 (range, step) thys max_suggs file_name = |
197 (range, step) thys linearize max_suggs file_name = |
188 let |
198 let |
189 val ho_atp = Sledgehammer_Provers.is_ho_atp ctxt prover |
199 val ho_atp = Sledgehammer_Provers.is_ho_atp ctxt prover |
190 val path = file_name |> Path.explode |
200 val path = file_name |> Path.explode |
191 val facts = all_facts ctxt |
201 val facts = all_facts ctxt |
192 val (new_facts, old_facts) = facts |> List.partition (has_thys thys o snd) |
202 val (new_facts, old_facts) = facts |> List.partition (has_thys thys o snd) |