author | blanchet |
Wed, 18 Jul 2012 08:44:03 +0200 | |
changeset 48302 | 6cf5e58f1185 |
parent 48300 | 9910021c80a7 |
child 48303 | f1d135d0ea69 |
permissions | -rw-r--r-- |
48234 | 1 |
(* Title: HOL/TPTP/mash_export.ML |
2 |
Author: Jasmin Blanchette, TU Muenchen |
|
3 |
Copyright 2012 |
|
4 |
||
5 |
Export Isabelle theory information for MaSh (Machine-learning for Sledgehammer). |
|
6 |
*) |
|
7 |
||
8 |
signature MASH_EXPORT = |
|
9 |
sig |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
10 |
type params = Sledgehammer_Provers.params |
48235 | 11 |
|
48299 | 12 |
val generate_commands : Proof.context -> theory -> string -> unit |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
13 |
val generate_iter_suggestions : |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
14 |
Proof.context -> params -> theory -> int -> string -> unit |
48234 | 15 |
end; |
16 |
||
17 |
structure MaSh_Export : MASH_EXPORT = |
|
18 |
struct |
|
19 |
||
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
20 |
open Sledgehammer_Filter_MaSh |
48245 | 21 |
|
48299 | 22 |
fun generate_commands ctxt thy file_name = |
48234 | 23 |
let |
24 |
val path = file_name |> Path.explode |
|
25 |
val _ = File.write path "" |
|
48299 | 26 |
val css_table = Sledgehammer_Fact.clasimpset_rule_table_of ctxt |
27 |
val facts = all_non_tautological_facts_of thy css_table |
|
48234 | 28 |
val (new_facts, old_facts) = |
29 |
facts |> List.partition (has_thy thy o snd) |
|
30 |
|>> sort (thm_ord o pairself snd) |
|
31 |
val ths = facts |> map snd |
|
32 |
val all_names = ths |> map Thm.get_name_hint |
|
33 |
fun do_fact ((_, (_, status)), th) prevs = |
|
34 |
let |
|
35 |
val name = Thm.get_name_hint th |
|
48302 | 36 |
val feats = features_of thy status [prop_of th] |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
37 |
val deps = isabelle_dependencies_of all_names th |
48234 | 38 |
val kind = Thm.legacy_get_kind th |
39 |
val name = fact_name_of name |
|
40 |
val core = |
|
48300 | 41 |
space_implode " " prevs ^ "; " ^ space_implode " " feats |
48234 | 42 |
val query = if kind <> "" then "? " ^ core ^ "\n" else "" |
48300 | 43 |
val update = |
44 |
"! " ^ name ^ ": " ^ core ^ "; " ^ space_implode " " deps ^ "\n" |
|
48234 | 45 |
val _ = File.append path (query ^ update) |
46 |
in [name] end |
|
47 |
val thy_ths = old_facts |> thms_by_thy |
|
48296
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48292
diff
changeset
|
48 |
val parents = parent_facts thy_ths thy |
48239
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
49 |
in fold do_fact new_facts parents; () end |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
50 |
|
48292 | 51 |
fun generate_iter_suggestions ctxt (params as {provers, ...}) thy max_relevant |
52 |
file_name = |
|
48239
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
53 |
let |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
54 |
val path = file_name |> Path.explode |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
55 |
val _ = File.write path "" |
48299 | 56 |
val css_table = Sledgehammer_Fact.clasimpset_rule_table_of ctxt |
57 |
val facts = all_non_tautological_facts_of thy css_table |
|
48239
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
58 |
val (new_facts, old_facts) = |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
59 |
facts |> List.partition (has_thy thy o snd) |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
60 |
|>> sort (thm_ord o pairself snd) |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
61 |
fun do_fact (fact as (_, th)) old_facts = |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
62 |
let |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
63 |
val name = Thm.get_name_hint th |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48246
diff
changeset
|
64 |
val goal = goal_of_thm thy th |
48292 | 65 |
val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1 |
48239
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
66 |
val kind = Thm.legacy_get_kind th |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
67 |
val _ = |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
68 |
if kind <> "" then |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
69 |
let |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
70 |
val suggs = |
48292 | 71 |
old_facts |
72 |
|> Sledgehammer_Filter_Iter.iterative_relevant_facts ctxt params |
|
73 |
(hd provers) max_relevant NONE hyp_ts concl_t |
|
74 |
|> map (fn ((name, _), _) => fact_name_of (name ())) |
|
75 |
|> sort string_ord |
|
48239
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
76 |
val s = fact_name_of name ^ ": " ^ space_implode " " suggs ^ "\n" |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
77 |
in File.append path s end |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
78 |
else |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
79 |
() |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
80 |
in fact :: old_facts end |
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
81 |
in fold do_fact new_facts old_facts; () end |
48234 | 82 |
|
83 |
end; |