author | blanchet |
Mon, 09 Dec 2013 05:06:48 +0100 | |
changeset 54699 | 65c4fd04b5b2 |
parent 54535 | 59737a43e044 |
child 54700 | 64177ce0a7bd |
permissions | -rw-r--r-- |
49883 | 1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_reconstruct.ML |
2 |
Author: Jasmin Blanchette, TU Muenchen |
|
3 |
Author: Steffen Juilf Smolka, TU Muenchen |
|
4 |
||
49914 | 5 |
Isar proof reconstruction from ATP proofs. |
49883 | 6 |
*) |
7 |
||
52374 | 8 |
signature SLEDGEHAMMER_RECONSTRUCT = |
49883 | 9 |
sig |
54495 | 10 |
type ('a, 'b) atp_step = ('a, 'b) ATP_Proof.atp_step |
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53052
diff
changeset
|
11 |
type 'a atp_proof = 'a ATP_Proof.atp_proof |
49914 | 12 |
type stature = ATP_Problem_Generate.stature |
54495 | 13 |
type one_line_params = Sledgehammer_Reconstructor.one_line_params |
49914 | 14 |
|
15 |
type isar_params = |
|
54505 | 16 |
bool * bool * string * string * Time.time option * real * bool * (term, string) atp_step list * |
17 |
thm |
|
49914 | 18 |
|
49883 | 19 |
val isar_proof_text : |
53052
a0db255af8c5
sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents:
53047
diff
changeset
|
20 |
Proof.context -> bool option -> isar_params -> one_line_params -> string |
49883 | 21 |
val proof_text : |
54500 | 22 |
Proof.context -> bool option -> (unit -> isar_params) -> int -> one_line_params -> string |
49883 | 23 |
end; |
24 |
||
52374 | 25 |
structure Sledgehammer_Reconstruct : SLEDGEHAMMER_RECONSTRUCT = |
49883 | 26 |
struct |
27 |
||
28 |
open ATP_Util |
|
49914 | 29 |
open ATP_Problem |
49883 | 30 |
open ATP_Proof |
31 |
open ATP_Problem_Generate |
|
32 |
open ATP_Proof_Reconstruct |
|
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
33 |
open Sledgehammer_Util |
52555 | 34 |
open Sledgehammer_Reconstructor |
50264
a9ec48b98734
renamed sledgehammer_isar_reconstruct to sledgehammer_proof
smolkas
parents:
50262
diff
changeset
|
35 |
open Sledgehammer_Proof |
50258 | 36 |
open Sledgehammer_Annotate |
52555 | 37 |
open Sledgehammer_Print |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
38 |
open Sledgehammer_Preplay |
51130
76d68444cd59
renamed sledgehammer_shrink to sledgehammer_compress
smolkas
parents:
51129
diff
changeset
|
39 |
open Sledgehammer_Compress |
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
40 |
open Sledgehammer_Try0 |
52611
831f7479c74f
minimize dependencies (used facts) of Isar proof steps; remove unreferenced steps
smolkas
parents:
52592
diff
changeset
|
41 |
open Sledgehammer_Minimize_Isar |
49914 | 42 |
|
43 |
structure String_Redirect = ATP_Proof_Redirect( |
|
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53052
diff
changeset
|
44 |
type key = atp_step_name |
49914 | 45 |
val ord = fn ((s, _ : string list), (s', _)) => fast_string_ord (s, s') |
46 |
val string_of = fst) |
|
47 |
||
49883 | 48 |
open String_Redirect |
49 |
||
54501 | 50 |
fun raw_label_of_num num = (num, 0) |
49914 | 51 |
|
54501 | 52 |
fun label_of_clause [(num, _)] = raw_label_of_num num |
53 |
| label_of_clause c = (space_implode "___" (map (fst o raw_label_of_num o fst) c), 0) |
|
50005 | 54 |
|
54505 | 55 |
fun add_fact_of_dependencies [(_, ss as _ :: _)] = apsnd (union (op =) ss) |
56 |
| add_fact_of_dependencies names = apfst (insert (op =) (label_of_clause names)) |
|
49914 | 57 |
|
58 |
fun replace_one_dependency (old, new) dep = |
|
59 |
if is_same_atp_step dep old then new else [dep] |
|
51201 | 60 |
fun replace_dependencies_in_line p (name, role, t, rule, deps) = |
61 |
(name, role, t, rule, fold (union (op =) o replace_one_dependency p) deps []) |
|
49914 | 62 |
|
63 |
(* No "real" literals means only type information (tfree_tcs, clsrel, or |
|
64 |
clsarity). *) |
|
65 |
fun is_only_type_information t = t aconv @{term True} |
|
66 |
||
50905 | 67 |
fun s_maybe_not role = role <> Conjecture ? s_not |
68 |
||
51201 | 69 |
fun is_same_inference (role, t) (_, role', t', _, _) = |
70 |
s_maybe_not role t aconv s_maybe_not role' t' |
|
49914 | 71 |
|
72 |
(* Discard facts; consolidate adjacent lines that prove the same formula, since |
|
73 |
they differ only in type information.*) |
|
54505 | 74 |
fun add_line (name as (_, ss), role, t, rule, []) lines = |
49914 | 75 |
(* No dependencies: fact, conjecture, or (for Vampire) internal facts or |
76 |
definitions. *) |
|
54535
59737a43e044
support Negated_Conjecture as a TPTP role as well (e.g. for SMT proofs)
blanchet
parents:
54507
diff
changeset
|
77 |
if role = Conjecture orelse role = Negated_Conjecture orelse role = Hypothesis then |
51201 | 78 |
(name, role, t, rule, []) :: lines |
54505 | 79 |
else if role = Axiom then |
49914 | 80 |
(* Facts are not proof lines. *) |
54507 | 81 |
lines |> is_only_type_information t ? map (replace_dependencies_in_line (name, [])) |
49914 | 82 |
else |
83 |
map (replace_dependencies_in_line (name, [])) lines |
|
54505 | 84 |
| add_line (line as (name, role, t, _, _)) lines = |
49914 | 85 |
(* Type information will be deleted later; skip repetition test. *) |
86 |
if is_only_type_information t then |
|
50675 | 87 |
line :: lines |
49914 | 88 |
(* Is there a repetition? If so, replace later line by earlier one. *) |
50905 | 89 |
else case take_prefix (not o is_same_inference (role, t)) lines of |
50675 | 90 |
(_, []) => line :: lines |
51201 | 91 |
| (pre, (name', _, _, _, _) :: post) => |
50675 | 92 |
line :: pre @ map (replace_dependencies_in_line (name', [name])) post |
49914 | 93 |
|
94 |
(* Recursively delete empty lines (type information) from the proof. *) |
|
51201 | 95 |
fun add_nontrivial_line (line as (name, _, t, _, [])) lines = |
54507 | 96 |
if is_only_type_information t then delete_dependency name lines else line :: lines |
49914 | 97 |
| add_nontrivial_line line lines = line :: lines |
98 |
and delete_dependency name lines = |
|
99 |
fold_rev add_nontrivial_line |
|
100 |
(map (replace_dependencies_in_line (name, [])) lines) [] |
|
101 |
||
50675 | 102 |
val e_skolemize_rule = "skolemize" |
103 |
val vampire_skolemisation_rule = "skolemisation" |
|
104 |
||
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
105 |
val is_skolemize_rule = |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
106 |
member (op =) [e_skolemize_rule, vampire_skolemisation_rule] |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
107 |
|
54505 | 108 |
fun add_desired_line (name as (_, ss), role, t, rule, deps) (j, lines) = |
51198 | 109 |
(j + 1, |
54505 | 110 |
if role <> Plain orelse is_skolemize_rule rule orelse |
51198 | 111 |
(* the last line must be kept *) |
112 |
j = 0 orelse |
|
113 |
(not (is_only_type_information t) andalso |
|
114 |
null (Term.add_tvars t []) andalso |
|
115 |
length deps >= 2 andalso |
|
116 |
(* kill next to last line, which usually results in a trivial step *) |
|
117 |
j <> 1) then |
|
51201 | 118 |
(name, role, t, rule, deps) :: lines (* keep line *) |
51198 | 119 |
else |
120 |
map (replace_dependencies_in_line (name, deps)) lines) (* drop line *) |
|
49914 | 121 |
|
49883 | 122 |
|
52454 | 123 |
val add_labels_of_proof = |
124 |
steps_of_proof #> fold_isar_steps |
|
52756
1ac8a0d0ddb1
parse nonnumeric identifiers in E proofs correctly
blanchet
parents:
52697
diff
changeset
|
125 |
(byline_of_step #> (fn SOME (By ((ls, _), _)) => union (op =) ls | _ => I)) |
49914 | 126 |
|
127 |
fun kill_useless_labels_in_proof proof = |
|
128 |
let |
|
51178 | 129 |
val used_ls = add_labels_of_proof proof [] |
49914 | 130 |
fun do_label l = if member (op =) used_ls l then l else no_label |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
131 |
fun do_assms (Assume assms) = Assume (map (apfst do_label) assms) |
52454 | 132 |
fun do_step (Prove (qs, xs, l, t, subproofs, by)) = |
54501 | 133 |
Prove (qs, xs, do_label l, t, map do_proof subproofs, by) |
49914 | 134 |
| do_step step = step |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
135 |
and do_proof (Proof (fix, assms, steps)) = |
54501 | 136 |
Proof (fix, do_assms assms, map do_step steps) |
51128
0021ea861129
introduced subblock in isar_step datatype for conjecture herbrandization
smolkas
parents:
51031
diff
changeset
|
137 |
in do_proof proof end |
49914 | 138 |
|
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
139 |
fun prefix_of_depth n = replicate_string (n + 1) |
49914 | 140 |
|
54501 | 141 |
val assume_prefix = "a" |
142 |
val have_prefix = "f" |
|
143 |
||
49914 | 144 |
val relabel_proof = |
145 |
let |
|
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
146 |
fun fresh_label depth prefix (old as (l, subst, next)) = |
50672
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
147 |
if l = no_label then |
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
148 |
old |
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
149 |
else |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
150 |
let val l' = (prefix_of_depth depth prefix, next) in |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
151 |
(l', (l, l') :: subst, next + 1) |
50672
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
152 |
end |
54507 | 153 |
fun do_facts subst = apfst (maps (the_list o AList.lookup (op =) subst)) |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
154 |
fun do_assm depth (l, t) (subst, next) = |
54507 | 155 |
let val (l, subst, next) = (l, subst, next) |> fresh_label depth assume_prefix in |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
156 |
((l, t), (subst, next)) |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
157 |
end |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
158 |
fun do_assms subst depth (Assume assms) = |
54507 | 159 |
fold_map (do_assm depth) assms (subst, 1) |>> Assume ||> fst |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
160 |
fun do_steps _ _ _ [] = [] |
52454 | 161 |
| do_steps subst depth next (Prove (qs, xs, l, t, sub, by) :: steps) = |
50672
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
162 |
let |
54507 | 163 |
val (l, subst, next) = (l, subst, next) |> fresh_label depth have_prefix |
52454 | 164 |
val sub = do_proofs subst depth sub |
52626 | 165 |
val by = by |> do_byline subst |
52454 | 166 |
in Prove (qs, xs, l, t, sub, by) :: do_steps subst depth next steps end |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
167 |
| do_steps subst depth next (step :: steps) = |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
168 |
step :: do_steps subst depth next steps |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
169 |
and do_proof subst depth (Proof (fix, assms, steps)) = |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
170 |
let val (assms, subst) = do_assms subst depth assms in |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
171 |
Proof (fix, assms, do_steps subst depth 1 steps) |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
172 |
end |
52626 | 173 |
and do_byline subst byline = |
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
174 |
map_facts_of_byline (do_facts subst) byline |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
175 |
and do_proofs subst depth = map (do_proof subst (depth + 1)) |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
176 |
in do_proof [] 0 end |
49914 | 177 |
|
50004
c96e8e40d789
several improvements to Isar proof reconstruction, by Steffen Smolka (step merging in case splits, time measurements, etc.)
blanchet
parents:
49994
diff
changeset
|
178 |
val chain_direct_proof = |
c96e8e40d789
several improvements to Isar proof reconstruction, by Steffen Smolka (step merging in case splits, time measurements, etc.)
blanchet
parents:
49994
diff
changeset
|
179 |
let |
51178 | 180 |
fun do_qs_lfs NONE lfs = ([], lfs) |
181 |
| do_qs_lfs (SOME l0) lfs = |
|
182 |
if member (op =) lfs l0 then ([Then], lfs |> remove (op =) l0) |
|
183 |
else ([], lfs) |
|
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
184 |
fun chain_step lbl |
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
185 |
(Prove (qs, xs, l, t, subproofs, By ((lfs, gfs), method))) = |
52453 | 186 |
let val (qs', lfs) = do_qs_lfs lbl lfs in |
52454 | 187 |
Prove (qs' @ qs, xs, l, t, chain_proofs subproofs, |
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
188 |
By ((lfs, gfs), method)) |
52453 | 189 |
end |
50672
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
190 |
| chain_step _ step = step |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
191 |
and chain_steps _ [] = [] |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
192 |
| chain_steps (prev as SOME _) (i :: is) = |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
193 |
chain_step prev i :: chain_steps (label_of_step i) is |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
194 |
| chain_steps _ (i :: is) = i :: chain_steps (label_of_step i) is |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
195 |
and chain_proof (Proof (fix, Assume assms, steps)) = |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
196 |
Proof (fix, Assume assms, |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
197 |
chain_steps (try (List.last #> fst) assms) steps) |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
198 |
and chain_proofs proofs = map (chain_proof) proofs |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
199 |
in chain_proof end |
49883 | 200 |
|
54505 | 201 |
fun maybe_mk_Trueprop t = t |> fastype_of t = HOLogic.boolT ? HOLogic.mk_Trueprop |
202 |
||
49914 | 203 |
type isar_params = |
54505 | 204 |
bool * bool * string * string * Time.time option * real * bool * (term, string) atp_step list * |
205 |
thm |
|
49914 | 206 |
|
53052
a0db255af8c5
sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents:
53047
diff
changeset
|
207 |
fun isar_proof_text ctxt isar_proofs |
54500 | 208 |
(debug, verbose, metis_type_enc, metis_lam_trans, preplay_timeout, isar_compress, |
54505 | 209 |
isar_try0, atp_proof, goal) |
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
210 |
(one_line_params as (_, _, _, _, subgoal, subgoal_count)) = |
49883 | 211 |
let |
52196
2281f33e8da6
redid rac7830871177 to avoid duplicate fixed variable (e.g. lemma "P (a::nat)" proof - have "!!a::int. Q a" sledgehammer [e])
blanchet
parents:
52150
diff
changeset
|
212 |
val (params, hyp_ts, concl_t) = strip_subgoal goal subgoal ctxt |
2281f33e8da6
redid rac7830871177 to avoid duplicate fixed variable (e.g. lemma "P (a::nat)" proof - have "!!a::int. Q a" sledgehammer [e])
blanchet
parents:
52150
diff
changeset
|
213 |
val (_, ctxt) = |
2281f33e8da6
redid rac7830871177 to avoid duplicate fixed variable (e.g. lemma "P (a::nat)" proof - have "!!a::int. Q a" sledgehammer [e])
blanchet
parents:
52150
diff
changeset
|
214 |
params |
2281f33e8da6
redid rac7830871177 to avoid duplicate fixed variable (e.g. lemma "P (a::nat)" proof - have "!!a::int. Q a" sledgehammer [e])
blanchet
parents:
52150
diff
changeset
|
215 |
|> map (fn (s, T) => (Binding.name s, SOME T, NoSyn)) |
54507 | 216 |
|> (fn fixes => ctxt |> Variable.set_body false |> Proof_Context.add_fixes fixes) |
53052
a0db255af8c5
sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents:
53047
diff
changeset
|
217 |
val one_line_proof = one_line_proof_text 0 one_line_params |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
218 |
val do_preplay = preplay_timeout <> SOME Time.zeroTime |
49883 | 219 |
|
220 |
fun isar_proof_of () = |
|
221 |
let |
|
222 |
val atp_proof = |
|
223 |
atp_proof |
|
54505 | 224 |
|> rpair [] |-> fold_rev add_line |
49883 | 225 |
|> rpair [] |-> fold_rev add_nontrivial_line |
226 |
|> rpair (0, []) |
|
54505 | 227 |
|-> fold_rev add_desired_line |
49883 | 228 |
|> snd |
54535
59737a43e044
support Negated_Conjecture as a TPTP role as well (e.g. for SMT proofs)
blanchet
parents:
54507
diff
changeset
|
229 |
val conjs = |
59737a43e044
support Negated_Conjecture as a TPTP role as well (e.g. for SMT proofs)
blanchet
parents:
54507
diff
changeset
|
230 |
atp_proof |> map_filter (fn (name, role, _, _, _) => |
59737a43e044
support Negated_Conjecture as a TPTP role as well (e.g. for SMT proofs)
blanchet
parents:
54507
diff
changeset
|
231 |
if role = Conjecture orelse role = Negated_Conjecture then SOME name else NONE) |
50010
17488e45eb5a
proper handling of assumptions arising from the goal's being expressed in rule format, for Isar proof construction
blanchet
parents:
50005
diff
changeset
|
232 |
val assms = |
54505 | 233 |
atp_proof |
54535
59737a43e044
support Negated_Conjecture as a TPTP role as well (e.g. for SMT proofs)
blanchet
parents:
54507
diff
changeset
|
234 |
|> map_filter (try (fn ((num, _), Hypothesis, t, _, _) => (raw_label_of_num num, t))) |
51212
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
235 |
val bot = atp_proof |> List.last |> #1 |
51145 | 236 |
val refute_graph = |
51212
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
237 |
atp_proof |
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
238 |
|> map (fn (name, _, _, _, from) => (from, name)) |
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
239 |
|> make_refute_graph bot |
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
240 |
|> fold (Atom_Graph.default_node o rpair ()) conjs |
51145 | 241 |
val axioms = axioms_of_refute_graph refute_graph conjs |
242 |
val tainted = tainted_atoms_of_refute_graph refute_graph conjs |
|
51156 | 243 |
val is_clause_tainted = exists (member (op =) tainted) |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
244 |
val steps = |
49883 | 245 |
Symtab.empty |
51201 | 246 |
|> fold (fn (name as (s, _), role, t, rule, _) => |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
247 |
Symtab.update_new (s, (rule, |
51156 | 248 |
t |> (if is_clause_tainted [name] then |
50905 | 249 |
s_maybe_not role |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
250 |
#> fold exists_of (map Var (Term.add_vars t [])) |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
251 |
else |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
252 |
I)))) |
49883 | 253 |
atp_proof |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
254 |
fun is_clause_skolemize_rule [(s, _)] = |
54505 | 255 |
Option.map (is_skolemize_rule o fst) (Symtab.lookup steps s) = SOME true |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
256 |
| is_clause_skolemize_rule _ = false |
54507 | 257 |
(* The assumptions and conjecture are "prop"s; the other formulas are "bool"s. *) |
54505 | 258 |
fun prop_of_clause [(num, _)] = |
259 |
Symtab.lookup steps num |> the |> snd |> maybe_mk_Trueprop |> close_form |
|
50016 | 260 |
| prop_of_clause names = |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
261 |
let |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
262 |
val lits = map snd (map_filter (Symtab.lookup steps o fst) names) |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
263 |
in |
50018
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
264 |
case List.partition (can HOLogic.dest_not) lits of |
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
265 |
(negs as _ :: _, pos as _ :: _) => |
54507 | 266 |
s_imp (Library.foldr1 s_conj (map HOLogic.dest_not negs), Library.foldr1 s_disj pos) |
50018
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
267 |
| _ => fold (curry s_disj) lits @{term False} |
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
268 |
end |
50016 | 269 |
|> HOLogic.mk_Trueprop |> close_form |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
270 |
fun isar_proof_of_direct_proof infs = |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
271 |
let |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
272 |
fun maybe_show outer c = |
54507 | 273 |
(outer andalso length c = 1 andalso subset (op =) (c, conjs)) ? cons Show |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
274 |
val is_fixed = Variable.is_declared ctxt orf can Name.dest_skolem |
54501 | 275 |
fun skolems_of t = Term.add_frees t [] |> filter_out (is_fixed o fst) |> rev |
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
276 |
fun do_steps outer predecessor accum [] = |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
277 |
accum |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
278 |
|> (if tainted = [] then |
54501 | 279 |
cons (Prove (if outer then [Show] else [], Fix [], no_label, concl_t, [], |
54503 | 280 |
By (([the predecessor], []), MetisM))) |
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
281 |
else |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
282 |
I) |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
283 |
|> rev |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
284 |
| do_steps outer _ accum (Have (gamma, c) :: infs) = |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
285 |
let |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
286 |
val l = label_of_clause c |
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
287 |
val t = prop_of_clause c |
54505 | 288 |
val by = By (fold add_fact_of_dependencies gamma no_facts, MetisM) |
54501 | 289 |
fun prove sub by = Prove (maybe_show outer c [], Fix [], l, t, sub, by) |
290 |
fun do_rest l step = do_steps outer (SOME l) (step :: accum) infs |
|
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
291 |
in |
51156 | 292 |
if is_clause_tainted c then |
51149 | 293 |
case gamma of |
294 |
[g] => |
|
54501 | 295 |
if is_clause_skolemize_rule g andalso is_clause_tainted g then |
51149 | 296 |
let |
51178 | 297 |
val subproof = |
54501 | 298 |
Proof (Fix (skolems_of (prop_of_clause g)), Assume [], rev accum) |
51149 | 299 |
in |
54503 | 300 |
do_steps outer (SOME l) [prove [subproof] (By (no_facts, MetisM))] [] |
51149 | 301 |
end |
302 |
else |
|
52454 | 303 |
do_rest l (prove [] by) |
304 |
| _ => do_rest l (prove [] by) |
|
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
305 |
else |
51149 | 306 |
if is_clause_skolemize_rule c then |
52454 | 307 |
do_rest l (Prove ([], Fix (skolems_of t), l, t, [], by)) |
51149 | 308 |
else |
52454 | 309 |
do_rest l (prove [] by) |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
310 |
end |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
311 |
| do_steps outer predecessor accum (Cases cases :: infs) = |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
312 |
let |
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
313 |
fun do_case (c, infs) = |
54501 | 314 |
do_proof false [] [(label_of_clause c, prop_of_clause c)] infs |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
315 |
val c = succedent_of_cases cases |
51178 | 316 |
val l = label_of_clause c |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
317 |
val t = prop_of_clause c |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
318 |
val step = |
54501 | 319 |
Prove (maybe_show outer c [], Fix [], l, t, map do_case cases, |
54503 | 320 |
By ((the_list predecessor, []), MetisM)) |
51149 | 321 |
in |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
322 |
do_steps outer (SOME l) (step :: accum) infs |
51149 | 323 |
end |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
324 |
and do_proof outer fix assms infs = |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
325 |
Proof (Fix fix, Assume assms, do_steps outer NONE [] infs) |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
326 |
in |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
327 |
do_proof true params assms infs |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
328 |
end |
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
329 |
|
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
330 |
(* 60 seconds seems like a good interpreation of "no timeout" *) |
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
331 |
val preplay_timeout = preplay_timeout |> the_default (seconds 60.0) |
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
332 |
|
51741 | 333 |
val clean_up_labels_in_proof = |
51165 | 334 |
chain_direct_proof |
335 |
#> kill_useless_labels_in_proof |
|
336 |
#> relabel_proof |
|
53761
4d34e267fba9
use configuration mechanism for low-level tracing
blanchet
parents:
53586
diff
changeset
|
337 |
val (preplay_interface as {overall_preplay_stats, ...}, isar_proof) = |
51145 | 338 |
refute_graph |
54699 | 339 |
(* |
340 |
|> tap (tracing o prefix "REFUTE: " o string_of_refute_graph) |
|
341 |
*) |
|
51031
63d71b247323
more robustness in Isar proof reconstruction (cf. bug report by Ondrej)
blanchet
parents:
51026
diff
changeset
|
342 |
|> redirect_graph axioms tainted bot |
54699 | 343 |
(* |
344 |
|> tap (tracing o prefix "DIRECT: " o string_of_direct_proof) |
|
345 |
*) |
|
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
346 |
|> isar_proof_of_direct_proof |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
347 |
|> relabel_proof_canonically |
54500 | 348 |
|> `(proof_preplay_interface debug ctxt metis_type_enc metis_lam_trans do_preplay |
53761
4d34e267fba9
use configuration mechanism for low-level tracing
blanchet
parents:
53586
diff
changeset
|
349 |
preplay_timeout) |
52626 | 350 |
val ((preplay_time, preplay_fail), isar_proof) = |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
351 |
isar_proof |
54501 | 352 |
|> compress_proof (if isar_proofs = SOME true then isar_compress else 1000.0) |
53762 | 353 |
preplay_interface |
52632
23393c31c7fe
added sledgehammer parameters isar_try0 and isar_minimize and their negative aliases
smolkas
parents:
52626
diff
changeset
|
354 |
|> isar_try0 ? try0 preplay_timeout preplay_interface |
54501 | 355 |
|> minimize_dependencies_and_remove_unrefed_steps isar_try0 preplay_interface |
52626 | 356 |
|> `overall_preplay_stats |
357 |
||> clean_up_labels_in_proof |
|
54500 | 358 |
val isar_text = |
359 |
string_of_proof ctxt metis_type_enc metis_lam_trans subgoal subgoal_count isar_proof |
|
49883 | 360 |
in |
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
361 |
case isar_text of |
49883 | 362 |
"" => |
51190
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
363 |
if isar_proofs = SOME true then |
50671 | 364 |
"\nNo structured proof available (proof too simple)." |
49883 | 365 |
else |
366 |
"" |
|
367 |
| _ => |
|
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
368 |
let |
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
369 |
val msg = |
51203 | 370 |
(if verbose then |
371 |
let |
|
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
372 |
val num_steps = add_proof_steps (steps_of_proof isar_proof) 0 |
51203 | 373 |
in [string_of_int num_steps ^ " step" ^ plural_s num_steps] end |
374 |
else |
|
375 |
[]) @ |
|
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
376 |
(if do_preplay then |
50924 | 377 |
[(if preplay_fail then "may fail, " else "") ^ |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
378 |
string_of_preplay_time preplay_time] |
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
379 |
else |
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
380 |
[]) |
50277 | 381 |
in |
54507 | 382 |
"\n\nStructured proof" ^ (commas msg |> not (null msg) ? enclose " (" ")") ^ ":\n" ^ |
383 |
Active.sendback_markup [Markup.padding_command] isar_text |
|
50277 | 384 |
end |
49883 | 385 |
end |
386 |
val isar_proof = |
|
387 |
if debug then |
|
388 |
isar_proof_of () |
|
389 |
else case try isar_proof_of () of |
|
390 |
SOME s => s |
|
51190
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
391 |
| NONE => if isar_proofs = SOME true then |
49883 | 392 |
"\nWarning: The Isar proof construction failed." |
393 |
else |
|
394 |
"" |
|
395 |
in one_line_proof ^ isar_proof end |
|
396 |
||
51187
c344cf148e8f
avoid using "smt" for minimization -- better use the prover itself, since then Sledgehammer gets to try metis again and gives the opportunity to output an Isar proof -- and show Isar proof as fallback for SMT proofs
blanchet
parents:
51179
diff
changeset
|
397 |
fun isar_proof_would_be_a_good_idea preplay = |
c344cf148e8f
avoid using "smt" for minimization -- better use the prover itself, since then Sledgehammer gets to try metis again and gives the opportunity to output an Isar proof -- and show Isar proof as fallback for SMT proofs
blanchet
parents:
51179
diff
changeset
|
398 |
case preplay of |
c344cf148e8f
avoid using "smt" for minimization -- better use the prover itself, since then Sledgehammer gets to try metis again and gives the opportunity to output an Isar proof -- and show Isar proof as fallback for SMT proofs
blanchet
parents:
51179
diff
changeset
|
399 |
Played (reconstr, _) => reconstr = SMT |
54093 | 400 |
| Trust_Playable _ => false |
51187
c344cf148e8f
avoid using "smt" for minimization -- better use the prover itself, since then Sledgehammer gets to try metis again and gives the opportunity to output an Isar proof -- and show Isar proof as fallback for SMT proofs
blanchet
parents:
51179
diff
changeset
|
401 |
| Failed_to_Play _ => true |
c344cf148e8f
avoid using "smt" for minimization -- better use the prover itself, since then Sledgehammer gets to try metis again and gives the opportunity to output an Isar proof -- and show Isar proof as fallback for SMT proofs
blanchet
parents:
51179
diff
changeset
|
402 |
|
53052
a0db255af8c5
sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents:
53047
diff
changeset
|
403 |
fun proof_text ctxt isar_proofs isar_params num_chained |
49883 | 404 |
(one_line_params as (preplay, _, _, _, _, _)) = |
51190
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
405 |
(if isar_proofs = SOME true orelse |
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
406 |
(isar_proofs = NONE andalso isar_proof_would_be_a_good_idea preplay) then |
54500 | 407 |
isar_proof_text ctxt isar_proofs (isar_params ()) |
49883 | 408 |
else |
53052
a0db255af8c5
sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents:
53047
diff
changeset
|
409 |
one_line_proof_text num_chained) one_line_params |
49883 | 410 |
|
411 |
end; |