author | blanchet |
Fri, 20 Sep 2013 22:39:30 +0200 | |
changeset 53762 | 06510d01a07b |
parent 53761 | 4d34e267fba9 |
child 53763 | 70d370743dc6 |
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 |
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53052
diff
changeset
|
10 |
type 'a atp_proof = 'a ATP_Proof.atp_proof |
49914 | 11 |
type stature = ATP_Problem_Generate.stature |
52555 | 12 |
type one_line_params = Sledgehammer_Print.one_line_params |
49914 | 13 |
|
14 |
type isar_params = |
|
53762 | 15 |
bool * bool * Time.time option * real * int * bool * bool |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
16 |
* string Symtab.table * (string * stature) list vector |
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53052
diff
changeset
|
17 |
* (string * term) list * int Symtab.table * string atp_proof * thm |
49914 | 18 |
|
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53052
diff
changeset
|
19 |
val lam_trans_of_atp_proof : string atp_proof -> string -> string |
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53052
diff
changeset
|
20 |
val is_typed_helper_used_in_atp_proof : string atp_proof -> bool |
49914 | 21 |
val used_facts_in_atp_proof : |
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53052
diff
changeset
|
22 |
Proof.context -> (string * stature) list vector -> string atp_proof -> |
49914 | 23 |
(string * stature) list |
24 |
val used_facts_in_unsound_atp_proof : |
|
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53052
diff
changeset
|
25 |
Proof.context -> (string * stature) list vector -> 'a atp_proof -> |
49914 | 26 |
string list option |
49883 | 27 |
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
|
28 |
Proof.context -> bool option -> isar_params -> one_line_params -> string |
49883 | 29 |
val 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
|
30 |
Proof.context -> bool option -> isar_params -> int -> one_line_params |
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
|
31 |
-> string |
49883 | 32 |
end; |
33 |
||
52374 | 34 |
structure Sledgehammer_Reconstruct : SLEDGEHAMMER_RECONSTRUCT = |
49883 | 35 |
struct |
36 |
||
37 |
open ATP_Util |
|
49914 | 38 |
open ATP_Problem |
49883 | 39 |
open ATP_Proof |
40 |
open ATP_Problem_Generate |
|
41 |
open ATP_Proof_Reconstruct |
|
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
42 |
open Sledgehammer_Util |
52555 | 43 |
open Sledgehammer_Reconstructor |
50264
a9ec48b98734
renamed sledgehammer_isar_reconstruct to sledgehammer_proof
smolkas
parents:
50262
diff
changeset
|
44 |
open Sledgehammer_Proof |
50258 | 45 |
open Sledgehammer_Annotate |
52555 | 46 |
open Sledgehammer_Print |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
47 |
open Sledgehammer_Preplay |
51130
76d68444cd59
renamed sledgehammer_shrink to sledgehammer_compress
smolkas
parents:
51129
diff
changeset
|
48 |
open Sledgehammer_Compress |
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
49 |
open Sledgehammer_Try0 |
52611
831f7479c74f
minimize dependencies (used facts) of Isar proof steps; remove unreferenced steps
smolkas
parents:
52592
diff
changeset
|
50 |
open Sledgehammer_Minimize_Isar |
49914 | 51 |
|
52 |
structure String_Redirect = ATP_Proof_Redirect( |
|
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53052
diff
changeset
|
53 |
type key = atp_step_name |
49914 | 54 |
val ord = fn ((s, _ : string list), (s', _)) => fast_string_ord (s, s') |
55 |
val string_of = fst) |
|
56 |
||
49883 | 57 |
open String_Redirect |
58 |
||
49914 | 59 |
(** fact extraction from ATP proofs **) |
60 |
||
61 |
fun find_first_in_list_vector vec key = |
|
62 |
Vector.foldl (fn (ps, NONE) => AList.lookup (op =) ps key |
|
63 |
| (_, value) => value) NONE vec |
|
64 |
||
65 |
val unprefix_fact_number = space_implode "_" o tl o space_explode "_" |
|
66 |
||
67 |
fun resolve_one_named_fact fact_names s = |
|
68 |
case try (unprefix fact_prefix) s of |
|
69 |
SOME s' => |
|
70 |
let val s' = s' |> unprefix_fact_number |> unascii_of in |
|
71 |
s' |> find_first_in_list_vector fact_names |> Option.map (pair s') |
|
72 |
end |
|
73 |
| NONE => NONE |
|
74 |
fun resolve_fact fact_names = map_filter (resolve_one_named_fact fact_names) |
|
75 |
fun is_fact fact_names = not o null o resolve_fact fact_names |
|
76 |
||
77 |
fun resolve_one_named_conjecture s = |
|
78 |
case try (unprefix conjecture_prefix) s of |
|
79 |
SOME s' => Int.fromString s' |
|
80 |
| NONE => NONE |
|
81 |
||
82 |
val resolve_conjecture = map_filter resolve_one_named_conjecture |
|
83 |
val is_conjecture = not o null o resolve_conjecture |
|
84 |
||
85 |
val ascii_of_lam_fact_prefix = ascii_of lam_fact_prefix |
|
86 |
||
87 |
(* overapproximation (good enough) *) |
|
88 |
fun is_lam_lifted s = |
|
89 |
String.isPrefix fact_prefix s andalso |
|
90 |
String.isSubstring ascii_of_lam_fact_prefix s |
|
91 |
||
92 |
val is_combinator_def = String.isPrefix (helper_prefix ^ combinator_prefix) |
|
93 |
||
94 |
fun is_axiom_used_in_proof pred = |
|
51202 | 95 |
exists (fn ((_, ss), _, _, _, []) => exists pred ss | _ => false) |
49914 | 96 |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51998
diff
changeset
|
97 |
fun lam_trans_of_atp_proof atp_proof default = |
49914 | 98 |
case (is_axiom_used_in_proof is_combinator_def atp_proof, |
99 |
is_axiom_used_in_proof is_lam_lifted atp_proof) of |
|
100 |
(false, false) => default |
|
101 |
| (false, true) => liftingN |
|
102 |
(* | (true, true) => combs_and_liftingN -- not supported by "metis" *) |
|
103 |
| (true, _) => combsN |
|
104 |
||
105 |
val is_typed_helper_name = |
|
106 |
String.isPrefix helper_prefix andf String.isSuffix typed_helper_suffix |
|
51031
63d71b247323
more robustness in Isar proof reconstruction (cf. bug report by Ondrej)
blanchet
parents:
51026
diff
changeset
|
107 |
|
49914 | 108 |
fun is_typed_helper_used_in_atp_proof atp_proof = |
109 |
is_axiom_used_in_proof is_typed_helper_name atp_proof |
|
110 |
||
111 |
fun add_non_rec_defs fact_names accum = |
|
112 |
Vector.foldl (fn (facts, facts') => |
|
113 |
union (op =) (filter (fn (_, (_, status)) => status = Non_Rec_Def) facts) |
|
114 |
facts') |
|
115 |
accum fact_names |
|
116 |
||
117 |
val isa_ext = Thm.get_name_hint @{thm ext} |
|
118 |
val isa_short_ext = Long_Name.base_name isa_ext |
|
119 |
||
120 |
fun ext_name ctxt = |
|
121 |
if Thm.eq_thm_prop (@{thm ext}, |
|
51026 | 122 |
singleton (Attrib.eval_thms ctxt) (Facts.named isa_short_ext, [])) then |
49914 | 123 |
isa_short_ext |
124 |
else |
|
125 |
isa_ext |
|
126 |
||
50675 | 127 |
val leo2_extcnf_equal_neg_rule = "extcnf_equal_neg" |
128 |
val leo2_unfold_def_rule = "unfold_def" |
|
49914 | 129 |
|
51201 | 130 |
fun add_fact ctxt fact_names ((_, ss), _, _, rule, deps) = |
51198 | 131 |
(if rule = leo2_extcnf_equal_neg_rule then |
132 |
insert (op =) (ext_name ctxt, (Global, General)) |
|
133 |
else if rule = leo2_unfold_def_rule then |
|
134 |
(* LEO 1.3.3 does not record definitions properly, leading to missing |
|
135 |
dependencies in the TSTP proof. Remove the next line once this is |
|
136 |
fixed. *) |
|
137 |
add_non_rec_defs fact_names |
|
52077 | 138 |
else if rule = agsyhol_coreN orelse rule = satallax_coreN then |
51198 | 139 |
(fn [] => |
52077 | 140 |
(* agsyHOL and Satallax don't include definitions in their |
141 |
unsatisfiable cores, so we assume the worst and include them all |
|
142 |
here. *) |
|
51198 | 143 |
[(ext_name ctxt, (Global, General))] |> add_non_rec_defs fact_names |
144 |
| facts => facts) |
|
145 |
else |
|
146 |
I) |
|
147 |
#> (if null deps then union (op =) (resolve_fact fact_names ss) else I) |
|
49914 | 148 |
|
149 |
fun used_facts_in_atp_proof ctxt fact_names atp_proof = |
|
150 |
if null atp_proof then Vector.foldl (uncurry (union (op =))) [] fact_names |
|
151 |
else fold (add_fact ctxt fact_names) atp_proof [] |
|
152 |
||
153 |
fun used_facts_in_unsound_atp_proof _ _ [] = NONE |
|
154 |
| used_facts_in_unsound_atp_proof ctxt fact_names atp_proof = |
|
155 |
let val used_facts = used_facts_in_atp_proof ctxt fact_names atp_proof in |
|
156 |
if forall (fn (_, (sc, _)) => sc = Global) used_facts andalso |
|
157 |
not (is_axiom_used_in_proof (is_conjecture o single) atp_proof) then |
|
158 |
SOME (map fst used_facts) |
|
159 |
else |
|
160 |
NONE |
|
161 |
end |
|
162 |
||
163 |
||
164 |
(** Isar proof construction and manipulation **) |
|
165 |
||
50017 | 166 |
val assume_prefix = "a" |
49914 | 167 |
val have_prefix = "f" |
168 |
val raw_prefix = "x" |
|
169 |
||
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
170 |
fun raw_label_of_name (num, ss) = |
49914 | 171 |
case resolve_conjecture ss of |
172 |
[j] => (conjecture_prefix, j) |
|
173 |
| _ => (raw_prefix ^ ascii_of num, 0) |
|
174 |
||
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
175 |
fun label_of_clause [name] = raw_label_of_name name |
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
176 |
| label_of_clause c = |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
177 |
(space_implode "___" (map (fst o raw_label_of_name) c), 0) |
50005 | 178 |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51998
diff
changeset
|
179 |
fun add_fact_of_dependencies fact_names (names as [(_, ss)]) = |
50005 | 180 |
if is_fact fact_names ss then |
181 |
apsnd (union (op =) (map fst (resolve_fact fact_names ss))) |
|
182 |
else |
|
183 |
apfst (insert (op =) (label_of_clause names)) |
|
52034
11b48e7a4e7e
correctly 'repair' the monomorphization context for SMT solvers from Sledgehammer
blanchet
parents:
52031
diff
changeset
|
184 |
| add_fact_of_dependencies _ names = |
50005 | 185 |
apfst (insert (op =) (label_of_clause names)) |
49914 | 186 |
|
187 |
fun repair_name "$true" = "c_True" |
|
188 |
| repair_name "$false" = "c_False" |
|
189 |
| repair_name "$$e" = tptp_equal (* seen in Vampire proofs *) |
|
190 |
| repair_name s = |
|
191 |
if is_tptp_equal s orelse |
|
192 |
(* seen in Vampire proofs *) |
|
193 |
(String.isPrefix "sQ" s andalso String.isSuffix "_eqProxy" s) then |
|
194 |
tptp_equal |
|
195 |
else |
|
196 |
s |
|
197 |
||
198 |
fun infer_formula_types ctxt = |
|
199 |
Type.constraint HOLogic.boolT |
|
200 |
#> Syntax.check_term |
|
201 |
(Proof_Context.set_mode Proof_Context.mode_schematic ctxt) |
|
202 |
||
203 |
val combinator_table = |
|
204 |
[(@{const_name Meson.COMBI}, @{thm Meson.COMBI_def [abs_def]}), |
|
205 |
(@{const_name Meson.COMBK}, @{thm Meson.COMBK_def [abs_def]}), |
|
206 |
(@{const_name Meson.COMBB}, @{thm Meson.COMBB_def [abs_def]}), |
|
207 |
(@{const_name Meson.COMBC}, @{thm Meson.COMBC_def [abs_def]}), |
|
208 |
(@{const_name Meson.COMBS}, @{thm Meson.COMBS_def [abs_def]})] |
|
209 |
||
210 |
fun uncombine_term thy = |
|
211 |
let |
|
212 |
fun aux (t1 $ t2) = betapply (pairself aux (t1, t2)) |
|
213 |
| aux (Abs (s, T, t')) = Abs (s, T, aux t') |
|
214 |
| aux (t as Const (x as (s, _))) = |
|
215 |
(case AList.lookup (op =) combinator_table s of |
|
216 |
SOME thm => thm |> prop_of |> specialize_type thy x |
|
217 |
|> Logic.dest_equals |> snd |
|
218 |
| NONE => t) |
|
219 |
| aux t = t |
|
220 |
in aux end |
|
221 |
||
52150
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
222 |
fun unlift_term lifted = |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
223 |
map_aterms (fn t as Const (s, _) => |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
224 |
if String.isPrefix lam_lifted_prefix s then |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
225 |
case AList.lookup (op =) lifted s of |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
226 |
SOME t => |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
227 |
(* FIXME: do something about the types *) |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
228 |
unlift_term lifted t |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
229 |
| NONE => t |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
230 |
else |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
231 |
t |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
232 |
| t => t) |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
233 |
|
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
234 |
fun decode_line ctxt lifted sym_tab (name, role, u, rule, deps) = |
51198 | 235 |
let |
236 |
val thy = Proof_Context.theory_of ctxt |
|
52125
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
237 |
val t = |
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
238 |
u |> prop_of_atp ctxt true sym_tab |
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
239 |
|> uncombine_term thy |
52150
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
240 |
|> unlift_term lifted |
52125
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
241 |
|> infer_formula_types ctxt |
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
242 |
in (name, role, t, rule, deps) end |
49914 | 243 |
|
244 |
fun replace_one_dependency (old, new) dep = |
|
245 |
if is_same_atp_step dep old then new else [dep] |
|
51201 | 246 |
fun replace_dependencies_in_line p (name, role, t, rule, deps) = |
247 |
(name, role, t, rule, fold (union (op =) o replace_one_dependency p) deps []) |
|
49914 | 248 |
|
249 |
(* No "real" literals means only type information (tfree_tcs, clsrel, or |
|
250 |
clsarity). *) |
|
251 |
fun is_only_type_information t = t aconv @{term True} |
|
252 |
||
50905 | 253 |
fun s_maybe_not role = role <> Conjecture ? s_not |
254 |
||
51201 | 255 |
fun is_same_inference (role, t) (_, role', t', _, _) = |
256 |
s_maybe_not role t aconv s_maybe_not role' t' |
|
49914 | 257 |
|
258 |
(* Discard facts; consolidate adjacent lines that prove the same formula, since |
|
259 |
they differ only in type information.*) |
|
51201 | 260 |
fun add_line fact_names (name as (_, ss), role, t, rule, []) lines = |
49914 | 261 |
(* No dependencies: fact, conjecture, or (for Vampire) internal facts or |
262 |
definitions. *) |
|
50905 | 263 |
if is_conjecture ss then |
51201 | 264 |
(name, role, t, rule, []) :: lines |
50905 | 265 |
else if is_fact fact_names ss then |
49914 | 266 |
(* Facts are not proof lines. *) |
267 |
if is_only_type_information t then |
|
268 |
map (replace_dependencies_in_line (name, [])) lines |
|
50905 | 269 |
else |
270 |
lines |
|
49914 | 271 |
else |
272 |
map (replace_dependencies_in_line (name, [])) lines |
|
51201 | 273 |
| add_line _ (line as (name, role, t, _, _)) lines = |
49914 | 274 |
(* Type information will be deleted later; skip repetition test. *) |
275 |
if is_only_type_information t then |
|
50675 | 276 |
line :: lines |
49914 | 277 |
(* Is there a repetition? If so, replace later line by earlier one. *) |
50905 | 278 |
else case take_prefix (not o is_same_inference (role, t)) lines of |
50675 | 279 |
(_, []) => line :: lines |
51201 | 280 |
| (pre, (name', _, _, _, _) :: post) => |
50675 | 281 |
line :: pre @ map (replace_dependencies_in_line (name', [name])) post |
49914 | 282 |
|
283 |
val waldmeister_conjecture_num = "1.0.0.0" |
|
284 |
||
51258 | 285 |
fun repair_waldmeister_endgame arg = |
49914 | 286 |
let |
51201 | 287 |
fun do_tail (name, _, t, rule, deps) = |
288 |
(name, Negated_Conjecture, s_not t, rule, deps) |
|
49914 | 289 |
fun do_body [] = [] |
51201 | 290 |
| do_body ((line as ((num, _), _, _, _, _)) :: lines) = |
49914 | 291 |
if num = waldmeister_conjecture_num then map do_tail (line :: lines) |
292 |
else line :: do_body lines |
|
51258 | 293 |
in do_body arg end |
49914 | 294 |
|
295 |
(* Recursively delete empty lines (type information) from the proof. *) |
|
51201 | 296 |
fun add_nontrivial_line (line as (name, _, t, _, [])) lines = |
49914 | 297 |
if is_only_type_information t then delete_dependency name lines |
298 |
else line :: lines |
|
299 |
| add_nontrivial_line line lines = line :: lines |
|
300 |
and delete_dependency name lines = |
|
301 |
fold_rev add_nontrivial_line |
|
302 |
(map (replace_dependencies_in_line (name, [])) lines) [] |
|
303 |
||
50675 | 304 |
val e_skolemize_rule = "skolemize" |
305 |
val vampire_skolemisation_rule = "skolemisation" |
|
306 |
||
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
307 |
val is_skolemize_rule = |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
308 |
member (op =) [e_skolemize_rule, vampire_skolemisation_rule] |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
309 |
|
52125
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
310 |
fun add_desired_line fact_names (name as (_, ss), role, t, rule, deps) |
51201 | 311 |
(j, lines) = |
51198 | 312 |
(j + 1, |
313 |
if is_fact fact_names ss orelse |
|
314 |
is_conjecture ss orelse |
|
315 |
is_skolemize_rule rule orelse |
|
316 |
(* the last line must be kept *) |
|
317 |
j = 0 orelse |
|
318 |
(not (is_only_type_information t) andalso |
|
319 |
null (Term.add_tvars t []) andalso |
|
320 |
length deps >= 2 andalso |
|
321 |
(* kill next to last line, which usually results in a trivial step *) |
|
322 |
j <> 1) then |
|
51201 | 323 |
(name, role, t, rule, deps) :: lines (* keep line *) |
51198 | 324 |
else |
325 |
map (replace_dependencies_in_line (name, deps)) lines) (* drop line *) |
|
49914 | 326 |
|
49883 | 327 |
|
52454 | 328 |
val add_labels_of_proof = |
329 |
steps_of_proof #> fold_isar_steps |
|
52756
1ac8a0d0ddb1
parse nonnumeric identifiers in E proofs correctly
blanchet
parents:
52697
diff
changeset
|
330 |
(byline_of_step #> (fn SOME (By ((ls, _), _)) => union (op =) ls | _ => I)) |
49914 | 331 |
|
332 |
fun kill_useless_labels_in_proof proof = |
|
333 |
let |
|
51178 | 334 |
val used_ls = add_labels_of_proof proof [] |
49914 | 335 |
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
|
336 |
fun do_assms (Assume assms) = Assume (map (apfst do_label) assms) |
52454 | 337 |
fun do_step (Prove (qs, xs, l, t, subproofs, by)) = |
338 |
Prove (qs, xs, do_label l, t, map do_proof subproofs, by) |
|
49914 | 339 |
| 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
|
340 |
and do_proof (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
|
341 |
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
|
342 |
in do_proof proof end |
49914 | 343 |
|
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
344 |
fun prefix_of_depth n = replicate_string (n + 1) |
49914 | 345 |
|
346 |
val relabel_proof = |
|
347 |
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
|
348 |
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
|
349 |
if l = no_label then |
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
350 |
old |
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
351 |
else |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
352 |
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
|
353 |
(l', (l, l') :: subst, next + 1) |
50672
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
354 |
end |
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
355 |
fun do_facts subst = |
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
356 |
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
|
357 |
fun do_assm depth (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
|
358 |
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
|
359 |
val (l, 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
|
360 |
(l, subst, next) |> fresh_label depth assume_prefix |
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
|
361 |
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
|
362 |
((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
|
363 |
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
|
364 |
fun do_assms subst depth (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
|
365 |
fold_map (do_assm depth) assms (subst, 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
|
366 |
|> apfst Assume |
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
|
367 |
|> apsnd fst |
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
|
368 |
fun do_steps _ _ _ [] = [] |
52454 | 369 |
| 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
|
370 |
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
|
371 |
val (l, 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
|
372 |
(l, subst, next) |> fresh_label depth have_prefix |
52454 | 373 |
val sub = do_proofs subst depth sub |
52626 | 374 |
val by = by |> do_byline subst |
52454 | 375 |
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
|
376 |
| 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
|
377 |
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
|
378 |
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
|
379 |
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
|
380 |
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
|
381 |
end |
52626 | 382 |
and do_byline subst byline = |
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
383 |
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
|
384 |
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
|
385 |
in do_proof [] 0 end |
49914 | 386 |
|
50004
c96e8e40d789
several improvements to Isar proof reconstruction, by Steffen Smolka (step merging in case splits, time measurements, etc.)
blanchet
parents:
49994
diff
changeset
|
387 |
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
|
388 |
let |
51178 | 389 |
fun do_qs_lfs NONE lfs = ([], lfs) |
390 |
| do_qs_lfs (SOME l0) lfs = |
|
391 |
if member (op =) lfs l0 then ([Then], lfs |> remove (op =) l0) |
|
392 |
else ([], lfs) |
|
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
393 |
fun chain_step lbl |
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
394 |
(Prove (qs, xs, l, t, subproofs, By ((lfs, gfs), method))) = |
52453 | 395 |
let val (qs', lfs) = do_qs_lfs lbl lfs in |
52454 | 396 |
Prove (qs' @ qs, xs, l, t, chain_proofs subproofs, |
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
397 |
By ((lfs, gfs), method)) |
52453 | 398 |
end |
50672
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
399 |
| 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
|
400 |
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
|
401 |
| 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
|
402 |
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
|
403 |
| 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
|
404 |
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
|
405 |
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
|
406 |
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
|
407 |
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
|
408 |
in chain_proof end |
49883 | 409 |
|
49914 | 410 |
type isar_params = |
53762 | 411 |
bool * bool * Time.time option * real * int * bool * bool |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
412 |
* string Symtab.table * (string * stature) list vector |
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53052
diff
changeset
|
413 |
* (string * term) list * int Symtab.table * string atp_proof * thm |
49914 | 414 |
|
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
|
415 |
fun isar_proof_text ctxt isar_proofs |
53761
4d34e267fba9
use configuration mechanism for low-level tracing
blanchet
parents:
53586
diff
changeset
|
416 |
(debug, verbose, preplay_timeout, isar_compress, isar_compress_degree, |
53762 | 417 |
isar_try0, isar_minimize, pool, fact_names, lifted, sym_tab, atp_proof, |
418 |
goal) |
|
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
419 |
(one_line_params as (_, _, _, _, subgoal, subgoal_count)) = |
49883 | 420 |
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
|
421 |
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
|
422 |
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
|
423 |
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
|
424 |
|> map (fn (s, T) => (Binding.name s, SOME T, NoSyn)) |
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
|
425 |
|> (fn fixes => |
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
|
426 |
ctxt |> Variable.set_body false |
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
|
427 |
|> 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
|
428 |
val one_line_proof = one_line_proof_text 0 one_line_params |
49883 | 429 |
val type_enc = |
430 |
if is_typed_helper_used_in_atp_proof atp_proof then full_typesN |
|
431 |
else partial_typesN |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51998
diff
changeset
|
432 |
val lam_trans = lam_trans_of_atp_proof atp_proof metis_default_lam_trans |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
433 |
val do_preplay = preplay_timeout <> SOME Time.zeroTime |
49883 | 434 |
|
435 |
fun isar_proof_of () = |
|
436 |
let |
|
437 |
val atp_proof = |
|
438 |
atp_proof |
|
439 |
|> clean_up_atp_proof_dependencies |
|
440 |
|> nasty_atp_proof pool |
|
441 |
|> map_term_names_in_atp_proof repair_name |
|
52150
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
442 |
|> map (decode_line ctxt lifted sym_tab) |
50905 | 443 |
|> repair_waldmeister_endgame |
49883 | 444 |
|> rpair [] |-> fold_rev (add_line fact_names) |
445 |
|> rpair [] |-> fold_rev add_nontrivial_line |
|
446 |
|> rpair (0, []) |
|
52125
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
447 |
|-> fold_rev (add_desired_line fact_names) |
49883 | 448 |
|> snd |
449 |
val conj_name = conjecture_prefix ^ string_of_int (length hyp_ts) |
|
450 |
val conjs = |
|
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
|
451 |
atp_proof |> map_filter |
51201 | 452 |
(fn (name as (_, ss), _, _, _, []) => |
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
|
453 |
if member (op =) ss conj_name then SOME name else NONE |
17488e45eb5a
proper handling of assumptions arising from the goal's being expressed in rule format, for Isar proof construction
blanchet
parents:
50005
diff
changeset
|
454 |
| _ => NONE) |
17488e45eb5a
proper handling of assumptions arising from the goal's being expressed in rule format, for Isar proof construction
blanchet
parents:
50005
diff
changeset
|
455 |
val assms = |
17488e45eb5a
proper handling of assumptions arising from the goal's being expressed in rule format, for Isar proof construction
blanchet
parents:
50005
diff
changeset
|
456 |
atp_proof |> map_filter |
51201 | 457 |
(fn (name as (_, ss), _, _, _, []) => |
50013
cceec179bdca
use original formulas for hypotheses and conclusion to avoid mismatches
blanchet
parents:
50012
diff
changeset
|
458 |
(case resolve_conjecture ss of |
cceec179bdca
use original formulas for hypotheses and conclusion to avoid mismatches
blanchet
parents:
50012
diff
changeset
|
459 |
[j] => |
cceec179bdca
use original formulas for hypotheses and conclusion to avoid mismatches
blanchet
parents:
50012
diff
changeset
|
460 |
if j = length hyp_ts then NONE |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
461 |
else SOME (raw_label_of_name name, nth hyp_ts j) |
50013
cceec179bdca
use original formulas for hypotheses and conclusion to avoid mismatches
blanchet
parents:
50012
diff
changeset
|
462 |
| _ => 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
|
463 |
| _ => NONE) |
51212
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
464 |
val bot = atp_proof |> List.last |> #1 |
51145 | 465 |
val refute_graph = |
51212
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
466 |
atp_proof |
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
467 |
|> map (fn (name, _, _, _, from) => (from, name)) |
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
468 |
|> make_refute_graph bot |
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
469 |
|> fold (Atom_Graph.default_node o rpair ()) conjs |
51145 | 470 |
val axioms = axioms_of_refute_graph refute_graph conjs |
471 |
val tainted = tainted_atoms_of_refute_graph refute_graph conjs |
|
51156 | 472 |
val is_clause_tainted = exists (member (op =) tainted) |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
473 |
val steps = |
49883 | 474 |
Symtab.empty |
51201 | 475 |
|> fold (fn (name as (s, _), role, t, rule, _) => |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
476 |
Symtab.update_new (s, (rule, |
51156 | 477 |
t |> (if is_clause_tainted [name] then |
50905 | 478 |
s_maybe_not role |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
479 |
#> fold exists_of (map Var (Term.add_vars t [])) |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
480 |
else |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
481 |
I)))) |
49883 | 482 |
atp_proof |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
483 |
fun is_clause_skolemize_rule [(s, _)] = |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
484 |
Option.map (is_skolemize_rule o fst) (Symtab.lookup steps s) = |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
485 |
SOME true |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
486 |
| is_clause_skolemize_rule _ = false |
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
487 |
(* The assumptions and conjecture are "prop"s; the other formulas are |
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
488 |
"bool"s. *) |
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
|
489 |
fun prop_of_clause [(s, ss)] = |
50016 | 490 |
(case resolve_conjecture ss of |
491 |
[j] => if j = length hyp_ts then concl_t else nth hyp_ts j |
|
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
492 |
| _ => the_default ("", @{term False}) (Symtab.lookup steps s) |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
493 |
|> snd |> HOLogic.mk_Trueprop |> close_form) |
50016 | 494 |
| prop_of_clause names = |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
495 |
let |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
496 |
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
|
497 |
in |
50018
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
498 |
case List.partition (can HOLogic.dest_not) lits of |
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
499 |
(negs as _ :: _, pos as _ :: _) => |
51212
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
500 |
s_imp (Library.foldr1 s_conj (map HOLogic.dest_not negs), |
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
501 |
Library.foldr1 s_disj pos) |
50018
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
502 |
| _ => fold (curry s_disj) lits @{term False} |
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
503 |
end |
50016 | 504 |
|> 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
|
505 |
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
|
506 |
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
|
507 |
fun maybe_show outer 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
|
508 |
(outer andalso length c = 1 andalso subset (op =) (c, conjs)) |
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
|
509 |
? cons Show |
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
|
510 |
val is_fixed = Variable.is_declared ctxt orf can Name.dest_skolem |
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
|
511 |
fun skolems_of t = |
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
|
512 |
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
|
513 |
fun do_steps outer predecessor accum [] = |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
514 |
accum |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
515 |
|> (if tainted = [] then |
52453 | 516 |
cons (Prove (if outer then [Show] else [], |
52454 | 517 |
Fix [], no_label, concl_t, [], |
518 |
By_Metis ([the predecessor], []))) |
|
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
519 |
else |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
520 |
I) |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
521 |
|> 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
|
522 |
| do_steps outer _ accum (Have (gamma, c) :: infs) = |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
523 |
let |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
524 |
val l = label_of_clause c |
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
525 |
val t = prop_of_clause c |
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
526 |
val by = |
52454 | 527 |
By_Metis |
528 |
(fold (add_fact_of_dependencies fact_names) gamma no_facts) |
|
529 |
fun prove sub by = |
|
530 |
Prove (maybe_show outer c [], Fix [], l, t, sub, by) |
|
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
531 |
fun do_rest l step = |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
532 |
do_steps outer (SOME l) (step :: accum) infs |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
533 |
in |
51156 | 534 |
if is_clause_tainted c then |
51149 | 535 |
case gamma of |
536 |
[g] => |
|
51156 | 537 |
if is_clause_skolemize_rule g andalso |
538 |
is_clause_tainted g then |
|
51149 | 539 |
let |
51178 | 540 |
val subproof = |
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
|
541 |
Proof (Fix (skolems_of (prop_of_clause g)), |
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
|
542 |
Assume [], rev accum) |
51149 | 543 |
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
|
544 |
do_steps outer (SOME l) |
52454 | 545 |
[prove [subproof] (By_Metis no_facts)] [] |
51149 | 546 |
end |
547 |
else |
|
52454 | 548 |
do_rest l (prove [] by) |
549 |
| _ => do_rest l (prove [] by) |
|
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
550 |
else |
51149 | 551 |
if is_clause_skolemize_rule c then |
52454 | 552 |
do_rest l (Prove ([], Fix (skolems_of t), l, t, [], by)) |
51149 | 553 |
else |
52454 | 554 |
do_rest l (prove [] by) |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
555 |
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
|
556 |
| do_steps outer predecessor accum (Cases cases :: infs) = |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
557 |
let |
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
558 |
fun do_case (c, infs) = |
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
559 |
do_proof false [] [(label_of_clause c, prop_of_clause c)] |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
560 |
infs |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
561 |
val c = succedent_of_cases cases |
51178 | 562 |
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
|
563 |
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
|
564 |
val step = |
52453 | 565 |
Prove (maybe_show outer c [], Fix [], l, t, |
52454 | 566 |
map do_case cases, By_Metis (the_list predecessor, [])) |
51149 | 567 |
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
|
568 |
do_steps outer (SOME l) (step :: accum) infs |
51149 | 569 |
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
|
570 |
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
|
571 |
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
|
572 |
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
|
573 |
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
|
574 |
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
|
575 |
|
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
576 |
(* 60 seconds seems like a good interpreation of "no timeout" *) |
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
577 |
val preplay_timeout = preplay_timeout |> the_default (seconds 60.0) |
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
578 |
|
51741 | 579 |
val clean_up_labels_in_proof = |
51165 | 580 |
chain_direct_proof |
581 |
#> kill_useless_labels_in_proof |
|
582 |
#> relabel_proof |
|
53761
4d34e267fba9
use configuration mechanism for low-level tracing
blanchet
parents:
53586
diff
changeset
|
583 |
val (preplay_interface as {overall_preplay_stats, ...}, isar_proof) = |
51145 | 584 |
refute_graph |
51031
63d71b247323
more robustness in Isar proof reconstruction (cf. bug report by Ondrej)
blanchet
parents:
51026
diff
changeset
|
585 |
|> redirect_graph axioms tainted bot |
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
|
586 |
|> isar_proof_of_direct_proof |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
587 |
|> relabel_proof_canonically |
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
588 |
|> `(proof_preplay_interface debug ctxt type_enc lam_trans do_preplay |
53761
4d34e267fba9
use configuration mechanism for low-level tracing
blanchet
parents:
53586
diff
changeset
|
589 |
preplay_timeout) |
52626 | 590 |
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
|
591 |
isar_proof |
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
592 |
|> compress_proof |
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
593 |
(if isar_proofs = SOME true then isar_compress else 1000.0) |
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
594 |
(if isar_proofs = SOME true then isar_compress_degree else 100) |
53762 | 595 |
preplay_interface |
52632
23393c31c7fe
added sledgehammer parameters isar_try0 and isar_minimize and their negative aliases
smolkas
parents:
52626
diff
changeset
|
596 |
|> isar_try0 ? try0 preplay_timeout preplay_interface |
23393c31c7fe
added sledgehammer parameters isar_try0 and isar_minimize and their negative aliases
smolkas
parents:
52626
diff
changeset
|
597 |
|> minimize_dependencies_and_remove_unrefed_steps isar_minimize |
23393c31c7fe
added sledgehammer parameters isar_try0 and isar_minimize and their negative aliases
smolkas
parents:
52626
diff
changeset
|
598 |
preplay_interface |
52626 | 599 |
|> `overall_preplay_stats |
600 |
||> clean_up_labels_in_proof |
|
601 |
val isar_text = string_of_proof ctxt type_enc lam_trans subgoal |
|
602 |
subgoal_count isar_proof |
|
49883 | 603 |
in |
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
604 |
case isar_text of |
49883 | 605 |
"" => |
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
|
606 |
if isar_proofs = SOME true then |
50671 | 607 |
"\nNo structured proof available (proof too simple)." |
49883 | 608 |
else |
609 |
"" |
|
610 |
| _ => |
|
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
611 |
let |
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
612 |
val msg = |
51203 | 613 |
(if verbose then |
614 |
let |
|
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52556
diff
changeset
|
615 |
val num_steps = add_proof_steps (steps_of_proof isar_proof) 0 |
51203 | 616 |
in [string_of_int num_steps ^ " step" ^ plural_s num_steps] end |
617 |
else |
|
618 |
[]) @ |
|
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52555
diff
changeset
|
619 |
(if do_preplay then |
50924 | 620 |
[(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
|
621 |
string_of_preplay_time preplay_time] |
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
622 |
else |
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
623 |
[]) |
50277 | 624 |
in |
51741 | 625 |
"\n\nStructured proof" |
626 |
^ (commas msg |> not (null msg) ? enclose " (" ")") |
|
52697
6fb98a20c349
explicit padding on command boundary for "auto" generated sendback -- do not replace the corresponding goal command, but append to it;
wenzelm
parents:
52632
diff
changeset
|
627 |
^ ":\n" ^ |
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
|
628 |
Active.sendback_markup [Markup.padding_command] isar_text |
50277 | 629 |
end |
49883 | 630 |
end |
631 |
val isar_proof = |
|
632 |
if debug then |
|
633 |
isar_proof_of () |
|
634 |
else case try isar_proof_of () of |
|
635 |
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
|
636 |
| NONE => if isar_proofs = SOME true then |
49883 | 637 |
"\nWarning: The Isar proof construction failed." |
638 |
else |
|
639 |
"" |
|
640 |
in one_line_proof ^ isar_proof end |
|
641 |
||
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
|
642 |
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
|
643 |
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
|
644 |
Played (reconstr, _) => reconstr = SMT |
51215
9ee38fc0bc81
generate Isar proof if Metis appears to be too slow
blanchet
parents:
51212
diff
changeset
|
645 |
| Trust_Playable _ => true |
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
|
646 |
| 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
|
647 |
|
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
|
648 |
fun proof_text ctxt isar_proofs isar_params num_chained |
49883 | 649 |
(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
|
650 |
(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
|
651 |
(isar_proofs = NONE andalso isar_proof_would_be_a_good_idea preplay) then |
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
|
652 |
isar_proof_text ctxt isar_proofs isar_params |
49883 | 653 |
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
|
654 |
one_line_proof_text num_chained) one_line_params |
49883 | 655 |
|
656 |
end; |