author | blanchet |
Wed, 18 Jul 2012 08:44:03 +0200 | |
changeset 48302 | 6cf5e58f1185 |
parent 48301 | e5c5037a3104 |
child 48303 | f1d135d0ea69 |
permissions | -rw-r--r-- |
48248 | 1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_filter_mash.ML |
2 |
Author: Jasmin Blanchette, TU Muenchen |
|
3 |
||
4 |
Sledgehammer's machine-learning-based relevance filter (MaSh). |
|
5 |
*) |
|
6 |
||
7 |
signature SLEDGEHAMMER_FILTER_MASH = |
|
8 |
sig |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
9 |
type status = ATP_Problem_Generate.status |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
10 |
type stature = ATP_Problem_Generate.stature |
48296
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
11 |
type fact = Sledgehammer_Fact.fact |
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
12 |
type fact_override = Sledgehammer_Fact.fact_override |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
13 |
type params = Sledgehammer_Provers.params |
48288
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
14 |
type relevance_fudge = Sledgehammer_Provers.relevance_fudge |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
15 |
type prover_result = Sledgehammer_Provers.prover_result |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
16 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
17 |
val fact_name_of : string -> string |
48299 | 18 |
val all_non_tautological_facts_of : |
19 |
theory -> status Termtab.table -> fact list |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
20 |
val theory_ord : theory * theory -> order |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
21 |
val thm_ord : thm * thm -> order |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
22 |
val thms_by_thy : ('a * thm) list -> (string * thm list) list |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
23 |
val has_thy : theory -> thm -> bool |
48296
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
24 |
val parent_facts : (string * thm list) list -> theory -> string list |
48302 | 25 |
val features_of : theory -> status -> term list -> string list |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
26 |
val isabelle_dependencies_of : string list -> thm -> string list |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
27 |
val goal_of_thm : theory -> thm -> thm |
48296
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
28 |
val run_prover : Proof.context -> params -> fact list -> thm -> prover_result |
48299 | 29 |
val generate_accessibility : Proof.context -> theory -> bool -> string -> unit |
30 |
val generate_features : Proof.context -> theory -> bool -> string -> unit |
|
31 |
val generate_isa_dependencies : |
|
32 |
Proof.context -> theory -> bool -> string -> unit |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
33 |
val generate_atp_dependencies : |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
34 |
Proof.context -> params -> theory -> bool -> string -> unit |
48302 | 35 |
val mash_RESET : unit -> unit |
36 |
val mash_ADD : string -> string list -> string list -> string list -> unit |
|
37 |
val mash_DEL : string list -> string list -> unit |
|
38 |
val mash_SUGGEST : string list -> string list -> string list |
|
48298 | 39 |
val mash_reset : unit -> unit |
40 |
val mash_can_suggest_facts : unit -> bool |
|
41 |
val mash_suggest_facts : |
|
48302 | 42 |
Proof.context -> params -> string -> int -> term list -> term -> fact list |
48298 | 43 |
-> fact list * fact list |
44 |
val mash_can_learn_thy : theory -> bool |
|
45 |
val mash_learn_thy : theory -> real -> unit |
|
46 |
val mash_learn_proof : theory -> term -> thm list -> unit |
|
48288
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
47 |
val relevant_facts : |
48292 | 48 |
Proof.context -> params -> string -> int -> fact_override -> term list |
48296
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
49 |
-> term -> fact list -> fact list |
48248 | 50 |
end; |
51 |
||
52 |
structure Sledgehammer_Filter_MaSh : SLEDGEHAMMER_FILTER_MASH = |
|
53 |
struct |
|
48249 | 54 |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
55 |
open ATP_Util |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
56 |
open ATP_Problem_Generate |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
57 |
open Sledgehammer_Util |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
58 |
open Sledgehammer_Fact |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
59 |
open Sledgehammer_Filter_Iter |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
60 |
open Sledgehammer_Provers |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
61 |
|
48301 | 62 |
val mash_dir = "mash" |
63 |
val model_file = "model" |
|
64 |
val state_file = "state" |
|
65 |
||
48302 | 66 |
fun mk_path file = |
67 |
getenv "ISABELLE_HOME_USER" ^ "/" ^ mash_dir ^ "/" ^ file |
|
68 |
|> Path.explode |
|
48249 | 69 |
|
48302 | 70 |
val fresh_fact_prefix = Long_Name.separator |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
71 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
72 |
(*** Isabelle helpers ***) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
73 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
74 |
fun escape_meta_char c = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
75 |
if Char.isAlphaNum c orelse c = #"_" orelse c = #"." orelse c = #"(" orelse |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
76 |
c = #")" orelse c = #"," then |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
77 |
String.str c |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
78 |
else |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
79 |
(* fixed width, in case more digits follow *) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
80 |
"\\" ^ stringN_of_int 3 (Char.ord c) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
81 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
82 |
val escape_meta = String.translate escape_meta_char |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
83 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
84 |
val thy_prefix = "y_" |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
85 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
86 |
val fact_name_of = escape_meta |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
87 |
val thy_name_of = prefix thy_prefix o escape_meta |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
88 |
val const_name_of = prefix const_prefix o escape_meta |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
89 |
val type_name_of = prefix type_const_prefix o escape_meta |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
90 |
val class_name_of = prefix class_prefix o escape_meta |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
91 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
92 |
val thy_name_of_thm = theory_of_thm #> Context.theory_name |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
93 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
94 |
local |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
95 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
96 |
fun has_bool @{typ bool} = true |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
97 |
| has_bool (Type (_, Ts)) = exists has_bool Ts |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
98 |
| has_bool _ = false |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
99 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
100 |
fun has_fun (Type (@{type_name fun}, _)) = true |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
101 |
| has_fun (Type (_, Ts)) = exists has_fun Ts |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
102 |
| has_fun _ = false |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
103 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
104 |
val is_conn = member (op =) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
105 |
[@{const_name Trueprop}, @{const_name HOL.conj}, @{const_name HOL.disj}, |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
106 |
@{const_name HOL.implies}, @{const_name Not}, |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
107 |
@{const_name All}, @{const_name Ex}, @{const_name Ball}, @{const_name Bex}, |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
108 |
@{const_name HOL.eq}] |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
109 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
110 |
val has_bool_arg_const = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
111 |
exists_Const (fn (c, T) => |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
112 |
not (is_conn c) andalso exists has_bool (binder_types T)) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
113 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
114 |
fun higher_inst_const thy (c, T) = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
115 |
case binder_types T of |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
116 |
[] => false |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
117 |
| Ts => length (binder_types (Sign.the_const_type thy c)) <> length Ts |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
118 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
119 |
val binders = [@{const_name All}, @{const_name Ex}] |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
120 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
121 |
in |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
122 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
123 |
fun is_fo_term thy t = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
124 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
125 |
val t = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
126 |
t |> Envir.beta_eta_contract |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
127 |
|> transform_elim_prop |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
128 |
|> Object_Logic.atomize_term thy |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
129 |
in |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
130 |
Term.is_first_order binders t andalso |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
131 |
not (exists_subterm (fn Var (_, T) => has_bool T orelse has_fun T |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
132 |
| _ => false) t orelse |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
133 |
has_bool_arg_const t orelse exists_Const (higher_inst_const thy) t) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
134 |
end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
135 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
136 |
end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
137 |
|
48302 | 138 |
fun interesting_terms_types_and_classes term_max_depth type_max_depth ts = |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
139 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
140 |
val bad_types = [@{type_name prop}, @{type_name bool}, @{type_name fun}] |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
141 |
val bad_consts = atp_widely_irrelevant_consts |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
142 |
fun do_add_type (Type (s, Ts)) = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
143 |
(not (member (op =) bad_types s) ? insert (op =) (type_name_of s)) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
144 |
#> fold do_add_type Ts |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
145 |
| do_add_type (TFree (_, S)) = union (op =) (map class_name_of S) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
146 |
| do_add_type (TVar (_, S)) = union (op =) (map class_name_of S) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
147 |
fun add_type T = type_max_depth >= 0 ? do_add_type T |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
148 |
fun mk_app s args = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
149 |
if member (op <>) args "" then s ^ "(" ^ space_implode "," args ^ ")" |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
150 |
else s |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
151 |
fun patternify ~1 _ = "" |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
152 |
| patternify depth t = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
153 |
case strip_comb t of |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
154 |
(Const (s, _), args) => |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
155 |
mk_app (const_name_of s) (map (patternify (depth - 1)) args) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
156 |
| _ => "" |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
157 |
fun add_term_patterns ~1 _ = I |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
158 |
| add_term_patterns depth t = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
159 |
insert (op =) (patternify depth t) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
160 |
#> add_term_patterns (depth - 1) t |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
161 |
val add_term = add_term_patterns term_max_depth |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
162 |
fun add_patterns t = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
163 |
let val (head, args) = strip_comb t in |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
164 |
(case head of |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
165 |
Const (s, T) => |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
166 |
not (member (op =) bad_consts s) ? (add_term t #> add_type T) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
167 |
| Free (_, T) => add_type T |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
168 |
| Var (_, T) => add_type T |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
169 |
| Abs (_, T, body) => add_type T #> add_patterns body |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
170 |
| _ => I) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
171 |
#> fold add_patterns args |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
172 |
end |
48302 | 173 |
in [] |> fold add_patterns ts |> sort string_ord end |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
174 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
175 |
fun is_likely_tautology th = |
48302 | 176 |
null (interesting_terms_types_and_classes 0 ~1 [prop_of th]) andalso |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
177 |
not (Thm.eq_thm_prop (@{thm ext}, th)) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
178 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
179 |
fun is_too_meta thy th = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
180 |
fastype_of (Object_Logic.atomize_term thy (prop_of th)) <> @{typ bool} |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
181 |
|
48299 | 182 |
fun all_non_tautological_facts_of thy css_table = |
183 |
all_facts_of thy css_table |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
184 |
|> filter_out ((is_likely_tautology orf is_too_meta thy) o snd) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
185 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
186 |
fun theory_ord p = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
187 |
if Theory.eq_thy p then EQUAL |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
188 |
else if Theory.subthy p then LESS |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
189 |
else if Theory.subthy (swap p) then GREATER |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
190 |
else EQUAL |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
191 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
192 |
val thm_ord = theory_ord o pairself theory_of_thm |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
193 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
194 |
fun thms_by_thy ths = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
195 |
ths |> map (snd #> `thy_name_of_thm) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
196 |
|> AList.group (op =) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
197 |
|> sort (int_ord o pairself (length o Theory.ancestors_of o theory_of_thm |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
198 |
o hd o snd)) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
199 |
|> map (apsnd (sort thm_ord)) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
200 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
201 |
fun has_thy thy th = (Context.theory_name thy = thy_name_of_thm th) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
202 |
|
48296
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
203 |
fun add_last_thms thy_ths thy = |
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
204 |
case AList.lookup (op =) thy_ths (Context.theory_name thy) of |
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
205 |
SOME (ths as _ :: _) => insert Thm.eq_thm (List.last ths) |
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
206 |
| _ => add_parent_thms thy_ths thy |
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
207 |
and add_parent_thms thy_ths thy = |
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
208 |
fold (add_last_thms thy_ths) (Theory.parents_of thy) |
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
209 |
|
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
210 |
fun parent_facts thy_ths thy = |
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
211 |
add_parent_thms thy_ths thy [] |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
212 |
|> map (fact_name_of o Thm.get_name_hint) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
213 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
214 |
fun is_exists (s, _) = (s = @{const_name Ex} orelse s = @{const_name Ex1}) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
215 |
|
48297 | 216 |
val term_max_depth = 1 |
217 |
val type_max_depth = 1 |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
218 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
219 |
(* TODO: Generate type classes for types? *) |
48302 | 220 |
fun features_of thy status ts = |
221 |
thy_name_of (Context.theory_name thy) :: |
|
222 |
interesting_terms_types_and_classes term_max_depth type_max_depth ts |
|
223 |
|> exists (not o is_lambda_free) ts ? cons "lambdas" |
|
224 |
|> exists (exists_Const is_exists) ts ? cons "skolems" |
|
225 |
|> exists (not o is_fo_term thy) ts ? cons "ho" |
|
226 |
|> (case status of |
|
227 |
General => I |
|
228 |
| Induction => cons "induction" |
|
229 |
| Intro => cons "intro" |
|
230 |
| Inductive => cons "inductive" |
|
231 |
| Elim => cons "elim" |
|
232 |
| Simp => cons "simp" |
|
233 |
| Def => cons "def") |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
234 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
235 |
fun isabelle_dependencies_of all_facts = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
236 |
thms_in_proof (SOME all_facts) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
237 |
#> map fact_name_of #> sort string_ord |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
238 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
239 |
val freezeT = Type.legacy_freeze_type |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
240 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
241 |
fun freeze (t $ u) = freeze t $ freeze u |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
242 |
| freeze (Abs (s, T, t)) = Abs (s, freezeT T, freeze t) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
243 |
| freeze (Var ((s, _), T)) = Free (s, freezeT T) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
244 |
| freeze (Const (s, T)) = Const (s, freezeT T) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
245 |
| freeze (Free (s, T)) = Free (s, freezeT T) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
246 |
| freeze t = t |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
247 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
248 |
fun goal_of_thm thy = prop_of #> freeze #> cterm_of thy #> Goal.init |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
249 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
250 |
fun run_prover ctxt (params as {provers, ...}) facts goal = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
251 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
252 |
val problem = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
253 |
{state = Proof.init ctxt, goal = goal, subgoal = 1, subgoal_count = 1, |
48289 | 254 |
facts = facts |> map (apfst (apfst (fn name => name ()))) |
255 |
|> map Sledgehammer_Provers.Untranslated_Fact} |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
256 |
val prover = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
257 |
Sledgehammer_Minimize.get_minimizing_prover ctxt |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
258 |
Sledgehammer_Provers.Normal (hd provers) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
259 |
in prover params (K (K (K ""))) problem end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
260 |
|
48299 | 261 |
fun generate_accessibility ctxt thy include_thy file_name = |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
262 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
263 |
val path = file_name |> Path.explode |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
264 |
val _ = File.write path "" |
48299 | 265 |
val css_table = clasimpset_rule_table_of ctxt |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
266 |
fun do_thm th prevs = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
267 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
268 |
val s = th ^ ": " ^ space_implode " " prevs ^ "\n" |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
269 |
val _ = File.append path s |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
270 |
in [th] end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
271 |
val thy_ths = |
48299 | 272 |
all_non_tautological_facts_of thy css_table |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
273 |
|> not include_thy ? filter_out (has_thy thy o snd) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
274 |
|> thms_by_thy |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
275 |
fun do_thy ths = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
276 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
277 |
val thy = theory_of_thm (hd ths) |
48296
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48293
diff
changeset
|
278 |
val parents = parent_facts thy_ths thy |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
279 |
val ths = ths |> map (fact_name_of o Thm.get_name_hint) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
280 |
in fold do_thm ths parents; () end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
281 |
in List.app (do_thy o snd) thy_ths end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
282 |
|
48299 | 283 |
fun generate_features ctxt thy include_thy file_name = |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
284 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
285 |
val path = file_name |> Path.explode |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
286 |
val _ = File.write path "" |
48299 | 287 |
val css_table = clasimpset_rule_table_of ctxt |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
288 |
val facts = |
48299 | 289 |
all_non_tautological_facts_of thy css_table |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
290 |
|> not include_thy ? filter_out (has_thy thy o snd) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
291 |
fun do_fact ((_, (_, status)), th) = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
292 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
293 |
val name = Thm.get_name_hint th |
48302 | 294 |
val feats = features_of (theory_of_thm th) status [prop_of th] |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
295 |
val s = fact_name_of name ^ ": " ^ space_implode " " feats ^ "\n" |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
296 |
in File.append path s end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
297 |
in List.app do_fact facts end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
298 |
|
48299 | 299 |
fun generate_isa_dependencies ctxt thy include_thy file_name = |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
300 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
301 |
val path = file_name |> Path.explode |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
302 |
val _ = File.write path "" |
48299 | 303 |
val css_table = clasimpset_rule_table_of ctxt |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
304 |
val ths = |
48299 | 305 |
all_non_tautological_facts_of thy css_table |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
306 |
|> not include_thy ? filter_out (has_thy thy o snd) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
307 |
|> map snd |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
308 |
val all_names = ths |> map Thm.get_name_hint |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
309 |
fun do_thm th = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
310 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
311 |
val name = Thm.get_name_hint th |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
312 |
val deps = isabelle_dependencies_of all_names th |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
313 |
val s = fact_name_of name ^ ": " ^ space_implode " " deps ^ "\n" |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
314 |
in File.append path s end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
315 |
in List.app do_thm ths end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
316 |
|
48293 | 317 |
fun generate_atp_dependencies ctxt (params as {provers, max_facts, ...}) thy |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
318 |
include_thy file_name = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
319 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
320 |
val path = file_name |> Path.explode |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
321 |
val _ = File.write path "" |
48299 | 322 |
val css_table = clasimpset_rule_table_of ctxt |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
323 |
val facts = |
48299 | 324 |
all_non_tautological_facts_of thy css_table |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
325 |
|> not include_thy ? filter_out (has_thy thy o snd) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
326 |
val ths = facts |> map snd |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
327 |
val all_names = ths |> map Thm.get_name_hint |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
328 |
fun is_dep dep (_, th) = fact_name_of (Thm.get_name_hint th) = dep |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
329 |
fun add_isa_dep facts dep accum = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
330 |
if exists (is_dep dep) accum then |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
331 |
accum |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
332 |
else case find_first (is_dep dep) facts of |
48289 | 333 |
SOME ((name, status), th) => accum @ [((name, status), th)] |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
334 |
| NONE => accum (* shouldn't happen *) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
335 |
fun fix_name ((_, stature), th) = |
48289 | 336 |
((fn () => th |> Thm.get_name_hint |> fact_name_of, stature), th) |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
337 |
fun do_thm th = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
338 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
339 |
val name = Thm.get_name_hint th |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
340 |
val goal = goal_of_thm thy th |
48292 | 341 |
val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1 |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
342 |
val deps = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
343 |
case isabelle_dependencies_of all_names th of |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
344 |
[] => [] |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
345 |
| isa_dep as [_] => isa_dep (* can hardly beat that *) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
346 |
| isa_deps => |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
347 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
348 |
val facts = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
349 |
facts |> filter (fn (_, th') => thm_ord (th', th) = LESS) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
350 |
val facts = |
48292 | 351 |
facts |> iterative_relevant_facts ctxt params (hd provers) |
48293 | 352 |
(the max_facts) NONE hyp_ts concl_t |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
353 |
|> fold (add_isa_dep facts) isa_deps |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
354 |
|> map fix_name |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
355 |
in |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
356 |
case run_prover ctxt params facts goal of |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
357 |
{outcome = NONE, used_facts, ...} => |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
358 |
used_facts |> map fst |> sort string_ord |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
359 |
| _ => isa_deps |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
360 |
end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
361 |
val s = fact_name_of name ^ ": " ^ space_implode " " deps ^ "\n" |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
362 |
in File.append path s end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
363 |
in List.app do_thm ths end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
364 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
365 |
|
48302 | 366 |
(*** Low-level communication with MaSh ***) |
367 |
||
368 |
fun mash_RESET () = (warning "MaSh RESET"; File.rm (mk_path model_file)) |
|
369 |
||
370 |
fun mash_ADD fact access feats deps = |
|
371 |
warning ("MaSh ADD " ^ fact ^ ": " ^ space_implode " " access ^ "; " ^ |
|
372 |
space_implode " " feats ^ "; " ^ space_implode " " deps) |
|
373 |
||
374 |
fun mash_DEL facts feats = |
|
375 |
warning ("MaSh DEL " ^ space_implode " " facts ^ "; " ^ |
|
376 |
space_implode " " feats) |
|
377 |
||
378 |
fun mash_SUGGEST access feats = |
|
379 |
(warning ("MaSh SUGGEST " ^ space_implode " " access ^ "; " ^ |
|
380 |
space_implode " " feats); |
|
381 |
[]) |
|
382 |
||
383 |
||
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
384 |
(*** High-level communication with MaSh ***) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48249
diff
changeset
|
385 |
|
48301 | 386 |
type mash_state = |
48302 | 387 |
{fresh : int, |
388 |
completed_thys : unit Symtab.table, |
|
48301 | 389 |
thy_facts : string list Symtab.table} |
390 |
||
391 |
val mash_zero = |
|
48302 | 392 |
{fresh = 0, |
393 |
completed_thys = Symtab.empty, |
|
48301 | 394 |
thy_facts = Symtab.empty} |
395 |
||
396 |
local |
|
397 |
||
398 |
fun mash_load (state as (true, _)) = state |
|
399 |
| mash_load _ = |
|
48302 | 400 |
let |
401 |
val path = mk_path state_file |
|
402 |
val _ = Isabelle_System.mkdir (path |> Path.dir) |
|
403 |
in |
|
404 |
(true, |
|
405 |
case try File.read_lines path of |
|
406 |
SOME (fresh_line :: comp_line :: facts_lines) => |
|
407 |
let |
|
408 |
fun comp_thys_of_line comp_line = |
|
409 |
Symtab.make (comp_line |> space_explode " " |> map (rpair ())) |
|
410 |
fun add_facts_line line = |
|
411 |
case space_explode " " line of |
|
412 |
thy :: facts => Symtab.update_new (thy, facts) |
|
413 |
| _ => I (* shouldn't happen *) |
|
414 |
in |
|
415 |
{fresh = Int.fromString fresh_line |> the_default 0, |
|
416 |
completed_thys = comp_thys_of_line comp_line, |
|
417 |
thy_facts = fold add_facts_line facts_lines Symtab.empty} |
|
418 |
end |
|
419 |
| _ => mash_zero) |
|
420 |
end |
|
48249 | 421 |
|
48302 | 422 |
fun mash_save ({fresh, completed_thys, thy_facts} : mash_state) = |
48301 | 423 |
let |
48302 | 424 |
val path = mk_path state_file |
48301 | 425 |
val comp_line = (completed_thys |> Symtab.keys |> space_implode " ") ^ "\n" |
426 |
fun fact_line_for (thy, facts) = space_implode " " (thy :: facts) ^ "\n" |
|
427 |
in |
|
48302 | 428 |
File.write path (string_of_int fresh ^ "\n" ^ comp_line); |
48301 | 429 |
Symtab.fold (fn thy_fact => fn () => |
430 |
File.append path (fact_line_for thy_fact)) thy_facts |
|
431 |
end |
|
432 |
||
48302 | 433 |
val global_state = |
434 |
Synchronized.var "Sledgehammer_Filter_MaSh.global_state" (false, mash_zero) |
|
48301 | 435 |
|
436 |
in |
|
437 |
||
438 |
fun mash_change f = |
|
48302 | 439 |
Synchronized.change global_state (mash_load ##> (f #> tap mash_save)) |
440 |
||
441 |
fun mash_peek f = Synchronized.change global_state (mash_load ##> tap f) |
|
48301 | 442 |
|
48302 | 443 |
fun mash_value () = Synchronized.change_result global_state (mash_load #> `snd) |
444 |
||
445 |
fun mash_reset () = |
|
446 |
Synchronized.change global_state (fn _ => |
|
447 |
(mash_RESET (); File.rm (mk_path state_file); (true, mash_zero))) |
|
48301 | 448 |
|
449 |
end |
|
450 |
||
451 |
fun mash_can_suggest_facts () = |
|
452 |
not (Symtab.is_empty (#thy_facts (mash_value ()))) |
|
48249 | 453 |
|
48302 | 454 |
fun accessibility_of thy thy_facts = |
455 |
let |
|
456 |
val _ = 0 |
|
457 |
in |
|
458 |
[] (*###*) |
|
459 |
end |
|
460 |
||
48298 | 461 |
fun mash_suggest_facts ctxt params prover max_facts hyp_ts concl_t facts = |
48301 | 462 |
let |
48302 | 463 |
val thy = Proof_Context.theory_of ctxt |
464 |
val access = accessibility_of thy (#thy_facts (mash_value ())) |
|
465 |
val feats = features_of thy General (concl_t :: hyp_ts) |
|
48301 | 466 |
val suggs = mash_SUGGEST access feats |
467 |
in (facts, []) end |
|
48249 | 468 |
|
48301 | 469 |
fun mash_can_learn_thy thy = |
470 |
not (Symtab.defined (#completed_thys (mash_value ())) |
|
471 |
(Context.theory_name thy)) |
|
48249 | 472 |
|
48298 | 473 |
fun mash_learn_thy thy timeout = () |
48302 | 474 |
(* ### *) |
48298 | 475 |
|
48302 | 476 |
fun mash_learn_proof thy t ths = |
477 |
mash_change (fn {fresh, completed_thys, thy_facts} => |
|
478 |
let |
|
479 |
val fact = fresh_fact_prefix ^ string_of_int fresh |
|
480 |
val access = accessibility_of thy thy_facts |
|
481 |
val feats = features_of thy General [t] |
|
482 |
val deps = ths |> map (fact_name_of o Thm.get_name_hint) |
|
483 |
in |
|
484 |
mash_ADD fact access feats deps; |
|
485 |
{fresh = fresh + 1, completed_thys = completed_thys, |
|
486 |
thy_facts = thy_facts} |
|
487 |
end) |
|
48249 | 488 |
|
48293 | 489 |
fun relevant_facts ctxt params prover max_facts |
48298 | 490 |
({add, only, ...} : fact_override) hyp_ts concl_t facts = |
48288
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
491 |
if only then |
48289 | 492 |
facts |
48293 | 493 |
else if max_facts <= 0 then |
48288
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
494 |
[] |
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
495 |
else |
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
496 |
let |
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
497 |
val add_ths = Attrib.eval_thms ctxt add |
48292 | 498 |
fun prepend_facts ths accepts = |
48288
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
499 |
((facts |> filter (member Thm.eq_thm_prop ths o snd)) @ |
48292 | 500 |
(accepts |> filter_out (member Thm.eq_thm_prop ths o snd))) |
48293 | 501 |
|> take max_facts |
48298 | 502 |
val iter_facts = |
503 |
iterative_relevant_facts ctxt params prover max_facts NONE hyp_ts |
|
504 |
concl_t facts |
|
505 |
val (mash_facts, mash_rejected) = |
|
506 |
mash_suggest_facts ctxt params prover max_facts hyp_ts concl_t facts |
|
48302 | 507 |
val mesh_facts = iter_facts (* ### *) |
48288
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
508 |
in |
48298 | 509 |
mesh_facts |
48288
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
510 |
|> not (null add_ths) ? prepend_facts add_ths |
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
511 |
end |
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48251
diff
changeset
|
512 |
|
48248 | 513 |
end; |