author | haftmann |
Sat, 19 Jul 2025 18:41:55 +0200 | |
changeset 82886 | 8d1e295aab70 |
parent 81757 | 4d15005da582 |
permissions | -rw-r--r-- |
81757
4d15005da582
tuned documentation and order of instantiated facts
Lukas Bartl
parents:
81254
diff
changeset
|
1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_instantiations.ML |
4d15005da582
tuned documentation and order of instantiated facts
Lukas Bartl
parents:
81254
diff
changeset
|
2 |
Author: Lukas Bartl, Universitaet Augsburg |
81254 | 3 |
|
4 |
Inference of Variable Instantiations with Metis. |
|
5 |
*) |
|
6 |
||
7 |
signature SLEDGEHAMMER_INSTANTIATIONS = |
|
8 |
sig |
|
9 |
type stature = ATP_Problem_Generate.stature |
|
10 |
||
11 |
val instantiate_facts : Proof.state -> bool -> Time.time -> thm -> int -> |
|
12 |
(string * stature) list -> (Pretty.T * stature) list option |
|
13 |
end; |
|
14 |
||
15 |
structure Sledgehammer_Instantiations : SLEDGEHAMMER_INSTANTIATIONS = |
|
16 |
struct |
|
17 |
||
18 |
open ATP_Util |
|
19 |
open ATP_Problem_Generate |
|
20 |
open ATP_Proof_Reconstruct |
|
21 |
open Sledgehammer_Proof_Methods |
|
22 |
open Sledgehammer_Util |
|
23 |
||
24 |
(* metis with different options, last two with extensionality *) |
|
25 |
fun metis_methods ctxt = |
|
26 |
let |
|
27 |
val ext_facts = [short_thm_name ctxt ext] |
|
28 |
in |
|
29 |
[Metis_Method (NONE, NONE, []), |
|
30 |
Metis_Method (SOME really_full_type_enc, SOME liftingN, []), |
|
31 |
Metis_Method (SOME no_typesN, SOME liftingN, ext_facts), |
|
32 |
Metis_Method (SOME full_typesN, SOME liftingN, ext_facts)] |
|
33 |
end |
|
34 |
||
35 |
(* Infer variable instantiations using metis with the given options |
|
36 |
* (cf. tac_of_metis in Sledgehammer_Proof_Methods.tac_of_proof_method) *) |
|
37 |
fun infer_thm_insts (Metis_Method (type_enc_opt, lam_trans_opt, additional_fact_names)) thms ctxt = |
|
38 |
let |
|
39 |
val additional_facts = maps (thms_of_name ctxt) additional_fact_names |
|
40 |
val ctxt = ctxt |
|
41 |
|> Config.put Metis_Tactic.verbose false |
|
42 |
|> Config.put Metis_Tactic.trace false |
|
43 |
in |
|
44 |
Metis_Tactic.metis_infer_thm_insts ((Option.map single type_enc_opt, lam_trans_opt), |
|
45 |
additional_facts @ thms) ctxt |
|
46 |
end |
|
47 |
||
48 |
(* Infer variable instantiations of theorems with timeout *) |
|
49 |
fun timed_infer_thm_insts ctxt verbose timeout chained goal subgoal fact_thms metis_method = |
|
50 |
let |
|
51 |
val thms = maps snd fact_thms |
|
52 |
val timing = Timing.start () |
|
53 |
val opt_thm_insts = |
|
54 |
try (Timeout.apply timeout (infer_thm_insts metis_method thms ctxt chained subgoal)) goal |
|
55 |
|> Option.join |
|
56 |
val {cpu = time, ...} = Timing.result timing |
|
57 |
val _ = |
|
58 |
if verbose then |
|
59 |
(let |
|
60 |
val meth_str = string_of_proof_method (map (fst o fst) fact_thms) metis_method |
|
61 |
val time_str = string_of_time time |
|
62 |
in |
|
63 |
if is_some opt_thm_insts then |
|
64 |
writeln ("Inferred variable instantiations with " ^ meth_str ^ |
|
65 |
" (" ^ time_str ^ ")") |
|
66 |
else |
|
67 |
writeln ("Could not infer variable instantiations with " ^ meth_str ^ |
|
68 |
" (tried " ^ time_str ^ ")") |
|
69 |
end) |
|
70 |
else |
|
71 |
() |
|
72 |
in |
|
73 |
opt_thm_insts |
|
74 |
end |
|
75 |
||
76 |
(* Try to infer variable instantiations of facts and instantiate them |
|
77 |
* using of-instantiations (e.g. "assms(1)[of x]") *) |
|
78 |
fun instantiate_facts state verbose timeout goal subgoal facts = |
|
79 |
let |
|
80 |
val ctxt = Proof.context_of state |
|
81 |
val {facts = chained, ...} = Proof.goal state |
|
82 |
val goal = Thm.solve_constraints goal (* avoid exceptions *) |
|
83 |
val fact_thms = AList.make (thms_of_name ctxt o fst) facts |
|
84 |
val timed_infer_thm_insts = |
|
85 |
timed_infer_thm_insts ctxt verbose timeout chained goal subgoal fact_thms |
|
86 |
fun infer_thm_insts [] = NONE |
|
87 |
| infer_thm_insts (metis_method :: metis_methods) = |
|
88 |
(case timed_infer_thm_insts metis_method of |
|
89 |
NONE => infer_thm_insts metis_methods |
|
90 |
| thm_insts => thm_insts) |
|
81757
4d15005da582
tuned documentation and order of instantiated facts
Lukas Bartl
parents:
81254
diff
changeset
|
91 |
fun instantiate_fact ((name, stature), ths) thm_insts = |
4d15005da582
tuned documentation and order of instantiated facts
Lukas Bartl
parents:
81254
diff
changeset
|
92 |
List.partition (member Thm.eq_thm ths o fst) thm_insts |
4d15005da582
tuned documentation and order of instantiated facts
Lukas Bartl
parents:
81254
diff
changeset
|
93 |
|>> map (fn (_, inst) => (Metis_Tactic.pretty_name_inst ctxt (name, inst), stature)) |
81254 | 94 |
in |
95 |
infer_thm_insts (metis_methods ctxt) |
|
81757
4d15005da582
tuned documentation and order of instantiated facts
Lukas Bartl
parents:
81254
diff
changeset
|
96 |
|> Option.map (flat o fst o fold_map instantiate_fact fact_thms) |
81254 | 97 |
|> verbose ? tap (Option.app (fn inst_facts => |
98 |
Pretty.str "Instantiated facts:" :: map fst inst_facts |
|
99 |
|> Pretty.block o Pretty.breaks |
|
100 |
|> Pretty.writeln)) |
|
101 |
end |
|
102 |
||
103 |
end; |