author | blanchet |
Tue, 28 May 2013 08:52:41 +0200 | |
changeset 52196 | 2281f33e8da6 |
parent 52150 | 41c885784e04 |
child 52366 | ff89424b5094 |
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 |
||
8 |
signature SLEDGEHAMMER_PROOF_RECONSTRUCT = |
|
9 |
sig |
|
49914 | 10 |
type 'a proof = 'a ATP_Proof.proof |
11 |
type stature = ATP_Problem_Generate.stature |
|
12 |
||
13 |
datatype reconstructor = |
|
14 |
Metis of string * string | |
|
15 |
SMT |
|
16 |
||
17 |
datatype play = |
|
18 |
Played of reconstructor * Time.time | |
|
19 |
Trust_Playable of reconstructor * Time.time option | |
|
20 |
Failed_to_Play of reconstructor |
|
21 |
||
22 |
type minimize_command = string list -> string |
|
23 |
type one_line_params = |
|
24 |
play * string * (string * stature) list * minimize_command * int * int |
|
25 |
type isar_params = |
|
51879 | 26 |
bool * bool * Time.time option * bool * real * string Symtab.table |
52150
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
27 |
* (string * stature) list vector * (string * term) list * int Symtab.table |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
28 |
* string proof * thm |
49914 | 29 |
|
30 |
val smtN : string |
|
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
31 |
val string_of_reconstructor : reconstructor -> string |
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51998
diff
changeset
|
32 |
val lam_trans_of_atp_proof : string proof -> string -> string |
49914 | 33 |
val is_typed_helper_used_in_atp_proof : string proof -> bool |
34 |
val used_facts_in_atp_proof : |
|
35 |
Proof.context -> (string * stature) list vector -> string proof -> |
|
36 |
(string * stature) list |
|
37 |
val used_facts_in_unsound_atp_proof : |
|
38 |
Proof.context -> (string * stature) list vector -> 'a proof -> |
|
39 |
string list option |
|
40 |
val one_line_proof_text : int -> one_line_params -> string |
|
49883 | 41 |
val isar_proof_text : |
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
|
42 |
Proof.context -> bool option -> isar_params -> one_line_params -> string |
49883 | 43 |
val proof_text : |
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
|
44 |
Proof.context -> bool option -> isar_params -> int -> one_line_params |
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
45 |
-> string |
49883 | 46 |
end; |
47 |
||
48 |
structure Sledgehammer_Reconstruct : SLEDGEHAMMER_PROOF_RECONSTRUCT = |
|
49 |
struct |
|
50 |
||
51 |
open ATP_Util |
|
49914 | 52 |
open ATP_Problem |
49883 | 53 |
open ATP_Proof |
54 |
open ATP_Problem_Generate |
|
55 |
open ATP_Proof_Reconstruct |
|
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
56 |
open Sledgehammer_Util |
50264
a9ec48b98734
renamed sledgehammer_isar_reconstruct to sledgehammer_proof
smolkas
parents:
50262
diff
changeset
|
57 |
open Sledgehammer_Proof |
50258 | 58 |
open Sledgehammer_Annotate |
51130
76d68444cd59
renamed sledgehammer_shrink to sledgehammer_compress
smolkas
parents:
51129
diff
changeset
|
59 |
open Sledgehammer_Compress |
49914 | 60 |
|
61 |
structure String_Redirect = ATP_Proof_Redirect( |
|
62 |
type key = step_name |
|
63 |
val ord = fn ((s, _ : string list), (s', _)) => fast_string_ord (s, s') |
|
64 |
val string_of = fst) |
|
65 |
||
49883 | 66 |
open String_Redirect |
67 |
||
49916
412346127bfa
fixed theorem lookup code in Isar proof reconstruction
blanchet
parents:
49915
diff
changeset
|
68 |
|
49914 | 69 |
(** reconstructors **) |
70 |
||
71 |
datatype reconstructor = |
|
72 |
Metis of string * string | |
|
73 |
SMT |
|
74 |
||
75 |
datatype play = |
|
76 |
Played of reconstructor * Time.time | |
|
77 |
Trust_Playable of reconstructor * Time.time option | |
|
78 |
Failed_to_Play of reconstructor |
|
79 |
||
80 |
val smtN = "smt" |
|
81 |
||
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
82 |
fun string_of_reconstructor (Metis (type_enc, lam_trans)) = |
49914 | 83 |
metis_call type_enc lam_trans |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
84 |
| string_of_reconstructor SMT = smtN |
49914 | 85 |
|
86 |
||
87 |
(** fact extraction from ATP proofs **) |
|
88 |
||
89 |
fun find_first_in_list_vector vec key = |
|
90 |
Vector.foldl (fn (ps, NONE) => AList.lookup (op =) ps key |
|
91 |
| (_, value) => value) NONE vec |
|
92 |
||
93 |
val unprefix_fact_number = space_implode "_" o tl o space_explode "_" |
|
94 |
||
95 |
fun resolve_one_named_fact fact_names s = |
|
96 |
case try (unprefix fact_prefix) s of |
|
97 |
SOME s' => |
|
98 |
let val s' = s' |> unprefix_fact_number |> unascii_of in |
|
99 |
s' |> find_first_in_list_vector fact_names |> Option.map (pair s') |
|
100 |
end |
|
101 |
| NONE => NONE |
|
102 |
fun resolve_fact fact_names = map_filter (resolve_one_named_fact fact_names) |
|
103 |
fun is_fact fact_names = not o null o resolve_fact fact_names |
|
104 |
||
105 |
fun resolve_one_named_conjecture s = |
|
106 |
case try (unprefix conjecture_prefix) s of |
|
107 |
SOME s' => Int.fromString s' |
|
108 |
| NONE => NONE |
|
109 |
||
110 |
val resolve_conjecture = map_filter resolve_one_named_conjecture |
|
111 |
val is_conjecture = not o null o resolve_conjecture |
|
112 |
||
113 |
val ascii_of_lam_fact_prefix = ascii_of lam_fact_prefix |
|
114 |
||
115 |
(* overapproximation (good enough) *) |
|
116 |
fun is_lam_lifted s = |
|
117 |
String.isPrefix fact_prefix s andalso |
|
118 |
String.isSubstring ascii_of_lam_fact_prefix s |
|
119 |
||
120 |
val is_combinator_def = String.isPrefix (helper_prefix ^ combinator_prefix) |
|
121 |
||
122 |
fun is_axiom_used_in_proof pred = |
|
51202 | 123 |
exists (fn ((_, ss), _, _, _, []) => exists pred ss | _ => false) |
49914 | 124 |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51998
diff
changeset
|
125 |
fun lam_trans_of_atp_proof atp_proof default = |
49914 | 126 |
case (is_axiom_used_in_proof is_combinator_def atp_proof, |
127 |
is_axiom_used_in_proof is_lam_lifted atp_proof) of |
|
128 |
(false, false) => default |
|
129 |
| (false, true) => liftingN |
|
130 |
(* | (true, true) => combs_and_liftingN -- not supported by "metis" *) |
|
131 |
| (true, _) => combsN |
|
132 |
||
133 |
val is_typed_helper_name = |
|
134 |
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
|
135 |
|
49914 | 136 |
fun is_typed_helper_used_in_atp_proof atp_proof = |
137 |
is_axiom_used_in_proof is_typed_helper_name atp_proof |
|
138 |
||
139 |
fun add_non_rec_defs fact_names accum = |
|
140 |
Vector.foldl (fn (facts, facts') => |
|
141 |
union (op =) (filter (fn (_, (_, status)) => status = Non_Rec_Def) facts) |
|
142 |
facts') |
|
143 |
accum fact_names |
|
144 |
||
145 |
val isa_ext = Thm.get_name_hint @{thm ext} |
|
146 |
val isa_short_ext = Long_Name.base_name isa_ext |
|
147 |
||
148 |
fun ext_name ctxt = |
|
149 |
if Thm.eq_thm_prop (@{thm ext}, |
|
51026 | 150 |
singleton (Attrib.eval_thms ctxt) (Facts.named isa_short_ext, [])) then |
49914 | 151 |
isa_short_ext |
152 |
else |
|
153 |
isa_ext |
|
154 |
||
50675 | 155 |
val leo2_extcnf_equal_neg_rule = "extcnf_equal_neg" |
156 |
val leo2_unfold_def_rule = "unfold_def" |
|
49914 | 157 |
|
51201 | 158 |
fun add_fact ctxt fact_names ((_, ss), _, _, rule, deps) = |
51198 | 159 |
(if rule = leo2_extcnf_equal_neg_rule then |
160 |
insert (op =) (ext_name ctxt, (Global, General)) |
|
161 |
else if rule = leo2_unfold_def_rule then |
|
162 |
(* LEO 1.3.3 does not record definitions properly, leading to missing |
|
163 |
dependencies in the TSTP proof. Remove the next line once this is |
|
164 |
fixed. *) |
|
165 |
add_non_rec_defs fact_names |
|
52077 | 166 |
else if rule = agsyhol_coreN orelse rule = satallax_coreN then |
51198 | 167 |
(fn [] => |
52077 | 168 |
(* agsyHOL and Satallax don't include definitions in their |
169 |
unsatisfiable cores, so we assume the worst and include them all |
|
170 |
here. *) |
|
51198 | 171 |
[(ext_name ctxt, (Global, General))] |> add_non_rec_defs fact_names |
172 |
| facts => facts) |
|
173 |
else |
|
174 |
I) |
|
175 |
#> (if null deps then union (op =) (resolve_fact fact_names ss) else I) |
|
49914 | 176 |
|
177 |
fun used_facts_in_atp_proof ctxt fact_names atp_proof = |
|
178 |
if null atp_proof then Vector.foldl (uncurry (union (op =))) [] fact_names |
|
179 |
else fold (add_fact ctxt fact_names) atp_proof [] |
|
180 |
||
181 |
fun used_facts_in_unsound_atp_proof _ _ [] = NONE |
|
182 |
| used_facts_in_unsound_atp_proof ctxt fact_names atp_proof = |
|
183 |
let val used_facts = used_facts_in_atp_proof ctxt fact_names atp_proof in |
|
184 |
if forall (fn (_, (sc, _)) => sc = Global) used_facts andalso |
|
185 |
not (is_axiom_used_in_proof (is_conjecture o single) atp_proof) then |
|
186 |
SOME (map fst used_facts) |
|
187 |
else |
|
188 |
NONE |
|
189 |
end |
|
190 |
||
191 |
||
192 |
(** one-liner reconstructor proofs **) |
|
193 |
||
194 |
fun show_time NONE = "" |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51998
diff
changeset
|
195 |
| show_time (SOME ext_time) = " (" ^ string_of_ext_time ext_time ^ ")" |
49914 | 196 |
|
49986
90e7be285b49
took out "using only ..." comments in Sledgehammer generated metis/smt calls, until these can be generated soundly
blanchet
parents:
49983
diff
changeset
|
197 |
(* FIXME: Various bugs, esp. with "unfolding" |
49914 | 198 |
fun unusing_chained_facts _ 0 = "" |
199 |
| unusing_chained_facts used_chaineds num_chained = |
|
200 |
if length used_chaineds = num_chained then "" |
|
201 |
else if null used_chaineds then "(* using no facts *) " |
|
202 |
else "(* using only " ^ space_implode " " used_chaineds ^ " *) " |
|
49986
90e7be285b49
took out "using only ..." comments in Sledgehammer generated metis/smt calls, until these can be generated soundly
blanchet
parents:
49983
diff
changeset
|
203 |
*) |
49914 | 204 |
|
205 |
fun apply_on_subgoal _ 1 = "by " |
|
206 |
| apply_on_subgoal 1 _ = "apply " |
|
207 |
| apply_on_subgoal i n = |
|
208 |
"prefer " ^ string_of_int i ^ " " ^ apply_on_subgoal 1 n |
|
209 |
||
210 |
fun using_labels [] = "" |
|
211 |
| using_labels ls = |
|
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
212 |
"using " ^ space_implode " " (map string_of_label ls) ^ " " |
49914 | 213 |
|
214 |
fun command_call name [] = |
|
50239 | 215 |
name |> not (Symbol_Pos.is_identifier name) ? enclose "(" ")" |
49914 | 216 |
| command_call name args = "(" ^ name ^ " " ^ space_implode " " args ^ ")" |
217 |
||
218 |
fun reconstructor_command reconstr i n used_chaineds num_chained (ls, ss) = |
|
49986
90e7be285b49
took out "using only ..." comments in Sledgehammer generated metis/smt calls, until these can be generated soundly
blanchet
parents:
49983
diff
changeset
|
219 |
(* unusing_chained_facts used_chaineds num_chained ^ *) |
49914 | 220 |
using_labels ls ^ apply_on_subgoal i n ^ |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
221 |
command_call (string_of_reconstructor reconstr) ss |
49914 | 222 |
|
223 |
fun try_command_line banner time command = |
|
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50410
diff
changeset
|
224 |
banner ^ ": " ^ Active.sendback_markup command ^ show_time time ^ "." |
49914 | 225 |
|
226 |
fun minimize_line _ [] = "" |
|
227 |
| minimize_line minimize_command ss = |
|
228 |
case minimize_command ss of |
|
229 |
"" => "" |
|
230 |
| command => |
|
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50410
diff
changeset
|
231 |
"\nTo minimize: " ^ Active.sendback_markup command ^ "." |
49914 | 232 |
|
233 |
fun split_used_facts facts = |
|
234 |
facts |> List.partition (fn (_, (sc, _)) => sc = Chained) |
|
235 |
|> pairself (sort_distinct (string_ord o pairself fst)) |
|
236 |
||
237 |
type minimize_command = string list -> string |
|
238 |
type one_line_params = |
|
239 |
play * string * (string * stature) list * minimize_command * int * int |
|
240 |
||
241 |
fun one_line_proof_text num_chained |
|
242 |
(preplay, banner, used_facts, minimize_command, subgoal, |
|
243 |
subgoal_count) = |
|
244 |
let |
|
245 |
val (chained, extra) = split_used_facts used_facts |
|
246 |
val (failed, reconstr, ext_time) = |
|
247 |
case preplay of |
|
248 |
Played (reconstr, time) => (false, reconstr, (SOME (false, time))) |
|
249 |
| Trust_Playable (reconstr, time) => |
|
250 |
(false, reconstr, |
|
251 |
case time of |
|
252 |
NONE => NONE |
|
253 |
| SOME time => |
|
254 |
if time = Time.zeroTime then NONE else SOME (true, time)) |
|
255 |
| Failed_to_Play reconstr => (true, reconstr, NONE) |
|
256 |
val try_line = |
|
257 |
([], map fst extra) |
|
258 |
|> reconstructor_command reconstr subgoal subgoal_count (map fst chained) |
|
259 |
num_chained |
|
260 |
|> (if failed then |
|
261 |
enclose "One-line proof reconstruction failed: " |
|
262 |
".\n(Invoking \"sledgehammer\" with \"[strict]\" might \ |
|
263 |
\solve this.)" |
|
264 |
else |
|
265 |
try_command_line banner ext_time) |
|
266 |
in try_line ^ minimize_line minimize_command (map fst (extra @ chained)) end |
|
267 |
||
268 |
||
269 |
(** Isar proof construction and manipulation **) |
|
270 |
||
50017 | 271 |
val assume_prefix = "a" |
49914 | 272 |
val have_prefix = "f" |
273 |
val raw_prefix = "x" |
|
274 |
||
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
275 |
fun raw_label_of_name (num, ss) = |
49914 | 276 |
case resolve_conjecture ss of |
277 |
[j] => (conjecture_prefix, j) |
|
278 |
| _ => (raw_prefix ^ ascii_of num, 0) |
|
279 |
||
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
280 |
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
|
281 |
| label_of_clause c = |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
282 |
(space_implode "___" (map (fst o raw_label_of_name) c), 0) |
50005 | 283 |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51998
diff
changeset
|
284 |
fun add_fact_of_dependencies fact_names (names as [(_, ss)]) = |
50005 | 285 |
if is_fact fact_names ss then |
286 |
apsnd (union (op =) (map fst (resolve_fact fact_names ss))) |
|
287 |
else |
|
288 |
apfst (insert (op =) (label_of_clause names)) |
|
52034
11b48e7a4e7e
correctly 'repair' the monomorphization context for SMT solvers from Sledgehammer
blanchet
parents:
52031
diff
changeset
|
289 |
| add_fact_of_dependencies _ names = |
50005 | 290 |
apfst (insert (op =) (label_of_clause names)) |
49914 | 291 |
|
292 |
fun repair_name "$true" = "c_True" |
|
293 |
| repair_name "$false" = "c_False" |
|
294 |
| repair_name "$$e" = tptp_equal (* seen in Vampire proofs *) |
|
295 |
| repair_name s = |
|
296 |
if is_tptp_equal s orelse |
|
297 |
(* seen in Vampire proofs *) |
|
298 |
(String.isPrefix "sQ" s andalso String.isSuffix "_eqProxy" s) then |
|
299 |
tptp_equal |
|
300 |
else |
|
301 |
s |
|
302 |
||
303 |
fun infer_formula_types ctxt = |
|
304 |
Type.constraint HOLogic.boolT |
|
305 |
#> Syntax.check_term |
|
306 |
(Proof_Context.set_mode Proof_Context.mode_schematic ctxt) |
|
307 |
||
308 |
val combinator_table = |
|
309 |
[(@{const_name Meson.COMBI}, @{thm Meson.COMBI_def [abs_def]}), |
|
310 |
(@{const_name Meson.COMBK}, @{thm Meson.COMBK_def [abs_def]}), |
|
311 |
(@{const_name Meson.COMBB}, @{thm Meson.COMBB_def [abs_def]}), |
|
312 |
(@{const_name Meson.COMBC}, @{thm Meson.COMBC_def [abs_def]}), |
|
313 |
(@{const_name Meson.COMBS}, @{thm Meson.COMBS_def [abs_def]})] |
|
314 |
||
315 |
fun uncombine_term thy = |
|
316 |
let |
|
317 |
fun aux (t1 $ t2) = betapply (pairself aux (t1, t2)) |
|
318 |
| aux (Abs (s, T, t')) = Abs (s, T, aux t') |
|
319 |
| aux (t as Const (x as (s, _))) = |
|
320 |
(case AList.lookup (op =) combinator_table s of |
|
321 |
SOME thm => thm |> prop_of |> specialize_type thy x |
|
322 |
|> Logic.dest_equals |> snd |
|
323 |
| NONE => t) |
|
324 |
| aux t = t |
|
325 |
in aux end |
|
326 |
||
52150
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
327 |
fun unlift_term lifted = |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
328 |
map_aterms (fn t as Const (s, _) => |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
329 |
if String.isPrefix lam_lifted_prefix s then |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
330 |
case AList.lookup (op =) lifted s of |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
331 |
SOME t => |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
332 |
(* FIXME: do something about the types *) |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
333 |
unlift_term lifted t |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
334 |
| NONE => t |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
335 |
else |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
336 |
t |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
337 |
| t => t) |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
338 |
|
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
339 |
fun decode_line ctxt lifted sym_tab (name, role, u, rule, deps) = |
51198 | 340 |
let |
341 |
val thy = Proof_Context.theory_of ctxt |
|
52125
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
342 |
val t = |
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
343 |
u |> prop_of_atp ctxt true sym_tab |
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
344 |
|> uncombine_term thy |
52150
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
345 |
|> unlift_term lifted |
52125
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
346 |
|> infer_formula_types ctxt |
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
347 |
in (name, role, t, rule, deps) end |
49914 | 348 |
|
349 |
fun replace_one_dependency (old, new) dep = |
|
350 |
if is_same_atp_step dep old then new else [dep] |
|
51201 | 351 |
fun replace_dependencies_in_line p (name, role, t, rule, deps) = |
352 |
(name, role, t, rule, fold (union (op =) o replace_one_dependency p) deps []) |
|
49914 | 353 |
|
354 |
(* No "real" literals means only type information (tfree_tcs, clsrel, or |
|
355 |
clsarity). *) |
|
356 |
fun is_only_type_information t = t aconv @{term True} |
|
357 |
||
50905 | 358 |
fun s_maybe_not role = role <> Conjecture ? s_not |
359 |
||
51201 | 360 |
fun is_same_inference (role, t) (_, role', t', _, _) = |
361 |
s_maybe_not role t aconv s_maybe_not role' t' |
|
49914 | 362 |
|
363 |
(* Discard facts; consolidate adjacent lines that prove the same formula, since |
|
364 |
they differ only in type information.*) |
|
51201 | 365 |
fun add_line fact_names (name as (_, ss), role, t, rule, []) lines = |
49914 | 366 |
(* No dependencies: fact, conjecture, or (for Vampire) internal facts or |
367 |
definitions. *) |
|
50905 | 368 |
if is_conjecture ss then |
51201 | 369 |
(name, role, t, rule, []) :: lines |
50905 | 370 |
else if is_fact fact_names ss then |
49914 | 371 |
(* Facts are not proof lines. *) |
372 |
if is_only_type_information t then |
|
373 |
map (replace_dependencies_in_line (name, [])) lines |
|
50905 | 374 |
else |
375 |
lines |
|
49914 | 376 |
else |
377 |
map (replace_dependencies_in_line (name, [])) lines |
|
51201 | 378 |
| add_line _ (line as (name, role, t, _, _)) lines = |
49914 | 379 |
(* Type information will be deleted later; skip repetition test. *) |
380 |
if is_only_type_information t then |
|
50675 | 381 |
line :: lines |
49914 | 382 |
(* Is there a repetition? If so, replace later line by earlier one. *) |
50905 | 383 |
else case take_prefix (not o is_same_inference (role, t)) lines of |
50675 | 384 |
(_, []) => line :: lines |
51201 | 385 |
| (pre, (name', _, _, _, _) :: post) => |
50675 | 386 |
line :: pre @ map (replace_dependencies_in_line (name', [name])) post |
49914 | 387 |
|
388 |
val waldmeister_conjecture_num = "1.0.0.0" |
|
389 |
||
51258 | 390 |
fun repair_waldmeister_endgame arg = |
49914 | 391 |
let |
51201 | 392 |
fun do_tail (name, _, t, rule, deps) = |
393 |
(name, Negated_Conjecture, s_not t, rule, deps) |
|
49914 | 394 |
fun do_body [] = [] |
51201 | 395 |
| do_body ((line as ((num, _), _, _, _, _)) :: lines) = |
49914 | 396 |
if num = waldmeister_conjecture_num then map do_tail (line :: lines) |
397 |
else line :: do_body lines |
|
51258 | 398 |
in do_body arg end |
49914 | 399 |
|
400 |
(* Recursively delete empty lines (type information) from the proof. *) |
|
51201 | 401 |
fun add_nontrivial_line (line as (name, _, t, _, [])) lines = |
49914 | 402 |
if is_only_type_information t then delete_dependency name lines |
403 |
else line :: lines |
|
404 |
| add_nontrivial_line line lines = line :: lines |
|
405 |
and delete_dependency name lines = |
|
406 |
fold_rev add_nontrivial_line |
|
407 |
(map (replace_dependencies_in_line (name, [])) lines) [] |
|
408 |
||
50675 | 409 |
val e_skolemize_rule = "skolemize" |
410 |
val vampire_skolemisation_rule = "skolemisation" |
|
411 |
||
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
412 |
val is_skolemize_rule = |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
413 |
member (op =) [e_skolemize_rule, vampire_skolemisation_rule] |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
414 |
|
52125
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
415 |
fun add_desired_line fact_names (name as (_, ss), role, t, rule, deps) |
51201 | 416 |
(j, lines) = |
51198 | 417 |
(j + 1, |
418 |
if is_fact fact_names ss orelse |
|
419 |
is_conjecture ss orelse |
|
420 |
is_skolemize_rule rule orelse |
|
421 |
(* the last line must be kept *) |
|
422 |
j = 0 orelse |
|
423 |
(not (is_only_type_information t) andalso |
|
424 |
null (Term.add_tvars t []) andalso |
|
425 |
length deps >= 2 andalso |
|
426 |
(* kill next to last line, which usually results in a trivial step *) |
|
427 |
j <> 1) then |
|
51201 | 428 |
(name, role, t, rule, deps) :: lines (* keep line *) |
51198 | 429 |
else |
430 |
map (replace_dependencies_in_line (name, deps)) lines) (* drop line *) |
|
49914 | 431 |
|
432 |
val indent_size = 2 |
|
433 |
||
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
434 |
fun string_of_proof ctxt type_enc lam_trans i n proof = |
49883 | 435 |
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
|
436 |
val register_fixes = map Free #> fold Variable.auto_fixes |
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
|
437 |
fun add_suffix suffix (s, ctxt) = (s ^ suffix, ctxt) |
51158 | 438 |
fun of_indent ind = replicate_string (ind * indent_size) " " |
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
|
439 |
fun of_moreover ind = of_indent ind ^ "moreover\n" |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
440 |
fun of_label l = if l = no_label then "" else string_of_label l ^ ": " |
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
|
441 |
fun of_obtain qs nr = |
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
442 |
(if nr > 1 orelse (nr = 1 andalso member (op =) qs Then) then |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
443 |
"ultimately " |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
444 |
else if nr=1 orelse member (op =) qs Then then |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
445 |
"then " |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
446 |
else |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
447 |
"") ^ "obtain" |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
448 |
fun of_show_have qs = if member (op =) qs Show then "show" else "have" |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
449 |
fun of_thus_hence qs = if member (op =) qs Show then "thus" else "hence" |
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
|
450 |
fun of_prove qs nr = |
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
451 |
if nr > 1 orelse (nr = 1 andalso member (op =) qs Then) then |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
452 |
"ultimately " ^ of_show_have qs |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
453 |
else if nr=1 orelse member (op =) qs Then then |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
454 |
of_thus_hence qs |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
455 |
else |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
456 |
of_show_have qs |
51741 | 457 |
fun add_term term (s, ctxt) = |
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
|
458 |
(s ^ (annotate_types ctxt term |
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
|
459 |
|> with_vanilla_print_mode (Syntax.string_of_term ctxt) |
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
|
460 |
|> simplify_spaces |
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
|
461 |
|> maybe_quote), |
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
|
462 |
ctxt |> Variable.auto_fixes term) |
49883 | 463 |
val reconstr = Metis (type_enc, lam_trans) |
51158 | 464 |
fun of_metis ind options (ls, ss) = |
465 |
"\n" ^ of_indent (ind + 1) ^ options ^ |
|
49883 | 466 |
reconstructor_command reconstr 1 1 [] 0 |
467 |
(ls |> sort_distinct (prod_ord string_ord int_ord), |
|
468 |
ss |> sort_distinct string_ord) |
|
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
|
469 |
fun of_free (s, 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
|
470 |
maybe_quote s ^ " :: " ^ |
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
|
471 |
maybe_quote (simplify_spaces (with_vanilla_print_mode |
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
|
472 |
(Syntax.string_of_typ ctxt) 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
|
473 |
fun add_frees xs (s, ctxt) = |
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
|
474 |
(s ^ space_implode " and " (map of_free xs), ctxt |> register_fixes xs) |
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
|
475 |
fun add_fix _ [] = I |
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
|
476 |
| add_fix ind xs = add_suffix (of_indent ind ^ "fix ") |
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
|
477 |
#> add_frees xs |
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
|
478 |
#> add_suffix "\n" |
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
|
479 |
fun add_assm ind (l, 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
|
480 |
add_suffix (of_indent ind ^ "assume " ^ of_label l) |
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
|
481 |
#> add_term 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
|
482 |
#> add_suffix "\n" |
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
|
483 |
fun add_assms ind assms = fold (add_assm ind) 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
|
484 |
fun add_step_post ind l t facts options = |
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
|
485 |
add_suffix (of_label l) |
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
|
486 |
#> add_term 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
|
487 |
#> add_suffix (of_metis ind options facts ^ "\n") |
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
|
488 |
fun of_subproof ind ctxt proof = |
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 |
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
|
490 |
val ind = ind + 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
|
491 |
val s = of_proof ind ctxt proof |
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
|
492 |
val 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
|
493 |
val suffix = " }" |
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
|
494 |
in |
49883 | 495 |
replicate_string (ind * indent_size - size prefix) " " ^ prefix ^ |
496 |
String.extract (s, ind * indent_size, |
|
497 |
SOME (size s - ind * indent_size - 1)) ^ |
|
498 |
suffix ^ "\n" |
|
499 |
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
|
500 |
and of_subproofs _ _ _ [] = "" |
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
|
501 |
| of_subproofs ind ctxt qs subproofs = |
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
502 |
(if member (op =) qs Then then of_moreover ind else "") ^ |
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
|
503 |
space_implode (of_moreover ind) (map (of_subproof ind ctxt) subproofs) |
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
|
504 |
and add_step_pre ind qs subproofs (s, ctxt) = |
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 |
(s ^ of_subproofs ind ctxt qs subproofs ^ of_indent ind, ctxt) |
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 |
and add_step ind (Let (t1, t2)) = |
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 |
add_suffix (of_indent ind ^ "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
|
508 |
#> add_term t1 |
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 |
#> add_suffix " = " |
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 |
#> add_term t2 |
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 |
#> add_suffix "\n" |
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 |
| add_step ind (Prove (qs, l, t, By_Metis (subproofs, facts))) = |
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
|
513 |
add_step_pre ind qs subproofs |
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
|
514 |
#> add_suffix (of_prove qs (length subproofs) ^ " ") |
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
|
515 |
#> add_step_post ind l t facts "" |
51193
5aef949c24b7
use new skolemizer only if some skolems have two or more arguments -- otherwise the old skolemizer cannot get the arg order wrong
blanchet
parents:
51192
diff
changeset
|
516 |
| add_step ind (Obtain (qs, Fix xs, l, t, By_Metis (subproofs, facts))) = |
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
|
517 |
add_step_pre ind qs subproofs |
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
|
518 |
#> add_suffix (of_obtain qs (length subproofs) ^ " ") |
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
|
519 |
#> add_frees xs |
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
|
520 |
#> add_suffix " where " |
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
|
521 |
(* The new skolemizer puts the arguments in the same order as the ATPs |
51193
5aef949c24b7
use new skolemizer only if some skolems have two or more arguments -- otherwise the old skolemizer cannot get the arg order wrong
blanchet
parents:
51192
diff
changeset
|
522 |
(E and Vampire -- but see also "atp_proof_reconstruct.ML" regarding |
5aef949c24b7
use new skolemizer only if some skolems have two or more arguments -- otherwise the old skolemizer cannot get the arg order wrong
blanchet
parents:
51192
diff
changeset
|
523 |
Vampire). *) |
5aef949c24b7
use new skolemizer only if some skolems have two or more arguments -- otherwise the old skolemizer cannot get the arg order wrong
blanchet
parents:
51192
diff
changeset
|
524 |
#> add_step_post ind l t facts |
5aef949c24b7
use new skolemizer only if some skolems have two or more arguments -- otherwise the old skolemizer cannot get the arg order wrong
blanchet
parents:
51192
diff
changeset
|
525 |
(if exists (fn (_, T) => length (binder_types T) > 1) xs then |
5aef949c24b7
use new skolemizer only if some skolems have two or more arguments -- otherwise the old skolemizer cannot get the arg order wrong
blanchet
parents:
51192
diff
changeset
|
526 |
"using [[metis_new_skolem]] " |
5aef949c24b7
use new skolemizer only if some skolems have two or more arguments -- otherwise the old skolemizer cannot get the arg order wrong
blanchet
parents:
51192
diff
changeset
|
527 |
else |
5aef949c24b7
use new skolemizer only if some skolems have two or more arguments -- otherwise the old skolemizer cannot get the arg order wrong
blanchet
parents:
51192
diff
changeset
|
528 |
"") |
51194 | 529 |
and add_steps ind = fold (add_step ind) |
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
|
530 |
and of_proof ind ctxt (Proof (Fix xs, 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
|
531 |
("", ctxt) |
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
|
532 |
|> add_fix ind xs |
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
|
533 |
|> add_assms ind 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
|
534 |
|> add_steps ind 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
|
535 |
|> 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
|
536 |
in |
49883 | 537 |
(* One-step proofs are pointless; better use the Metis one-liner |
538 |
directly. *) |
|
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
|
539 |
case proof of |
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
|
540 |
Proof (Fix [], Assume [], [Prove (_, _, _, By_Metis ([], _))]) => "" |
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 |
| _ => (if i <> 1 then "prefer " ^ string_of_int i ^ "\n" else "") ^ |
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 |
of_indent 0 ^ "proof -\n" ^ of_proof 1 ctxt proof ^ |
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
|
543 |
of_indent 0 ^ (if n <> 1 then "next" else "qed") |
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 |
end |
49883 | 545 |
|
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
|
546 |
fun add_labels_of_step step = |
51194 | 547 |
case byline_of_step step of |
548 |
NONE => I |
|
549 |
| SOME (By_Metis (subproofs, (ls, _))) => |
|
550 |
union (op =) ls #> fold add_labels_of_proof subproofs |
|
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
|
551 |
and add_labels_of_proof proof = fold add_labels_of_step (steps_of_proof proof) |
49914 | 552 |
|
553 |
fun kill_useless_labels_in_proof proof = |
|
554 |
let |
|
51178 | 555 |
val used_ls = add_labels_of_proof proof [] |
49914 | 556 |
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
|
557 |
fun do_assms (Assume assms) = Assume (map (apfst do_label) 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
|
558 |
fun do_step (Obtain (qs, xs, l, t, By_Metis (subproofs, facts))) = |
51178 | 559 |
Obtain (qs, xs, do_label l, t, By_Metis (map do_proof subproofs, facts)) |
560 |
| do_step (Prove (qs, l, t, By_Metis (subproofs, facts))) = |
|
561 |
Prove (qs, do_label l, t, By_Metis (map do_proof subproofs, facts)) |
|
49914 | 562 |
| 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
|
563 |
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
|
564 |
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
|
565 |
in do_proof proof end |
49914 | 566 |
|
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
567 |
fun prefix_of_depth n = replicate_string (n + 1) |
49914 | 568 |
|
569 |
val relabel_proof = |
|
570 |
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
|
571 |
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
|
572 |
if l = no_label then |
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
573 |
old |
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
574 |
else |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
575 |
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
|
576 |
(l', (l, l') :: subst, next + 1) |
50672
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
577 |
end |
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
578 |
fun do_facts subst = |
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
579 |
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
|
580 |
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
|
581 |
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
|
582 |
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
|
583 |
(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
|
584 |
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
|
585 |
((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
|
586 |
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
|
587 |
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
|
588 |
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
|
589 |
|> 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
|
590 |
|> 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
|
591 |
fun do_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
|
592 |
| do_steps subst depth next (Obtain (qs, xs, l, t, by) :: steps) = |
50672
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
593 |
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
|
594 |
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
|
595 |
(l, subst, next) |> fresh_label depth have_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
|
596 |
val by = by |> do_byline subst depth |
51193
5aef949c24b7
use new skolemizer only if some skolems have two or more arguments -- otherwise the old skolemizer cannot get the arg order wrong
blanchet
parents:
51192
diff
changeset
|
597 |
in Obtain (qs, xs, l, t, 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
|
598 |
| do_steps subst depth next (Prove (qs, l, t, by) :: steps) = |
49914 | 599 |
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
|
600 |
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
|
601 |
(l, subst, next) |> fresh_label depth have_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
|
602 |
val by = by |> do_byline subst depth |
51193
5aef949c24b7
use new skolemizer only if some skolems have two or more arguments -- otherwise the old skolemizer cannot get the arg order wrong
blanchet
parents:
51192
diff
changeset
|
603 |
in Prove (qs, l, t, 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
|
604 |
| 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
|
605 |
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
|
606 |
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
|
607 |
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
|
608 |
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
|
609 |
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
|
610 |
and do_byline subst depth (By_Metis (subproofs, facts)) = |
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
|
611 |
By_Metis (do_proofs subst depth subproofs, do_facts subst facts) |
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
|
612 |
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
|
613 |
in do_proof [] 0 end |
49914 | 614 |
|
50004
c96e8e40d789
several improvements to Isar proof reconstruction, by Steffen Smolka (step merging in case splits, time measurements, etc.)
blanchet
parents:
49994
diff
changeset
|
615 |
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
|
616 |
let |
51178 | 617 |
fun do_qs_lfs NONE lfs = ([], lfs) |
618 |
| do_qs_lfs (SOME l0) lfs = |
|
619 |
if member (op =) lfs l0 then ([Then], lfs |> remove (op =) l0) |
|
620 |
else ([], lfs) |
|
621 |
fun chain_step lbl (Obtain (qs, xs, l, t, |
|
51193
5aef949c24b7
use new skolemizer only if some skolems have two or more arguments -- otherwise the old skolemizer cannot get the arg order wrong
blanchet
parents:
51192
diff
changeset
|
622 |
By_Metis (subproofs, (lfs, gfs)))) = |
51178 | 623 |
let val (qs', lfs) = do_qs_lfs lbl lfs in |
624 |
Obtain (qs' @ qs, xs, l, t, |
|
625 |
By_Metis (chain_proofs subproofs, (lfs, gfs))) |
|
626 |
end |
|
627 |
| chain_step lbl (Prove (qs, l, t, By_Metis (subproofs, (lfs, gfs)))) = |
|
628 |
let val (qs', lfs) = do_qs_lfs lbl lfs 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
|
629 |
Prove (qs' @ qs, l, t, By_Metis (chain_proofs subproofs, (lfs, gfs))) |
51178 | 630 |
end |
50672
ab5b8b5c9cbe
added "obtain" to Isar proof construction data structure
blanchet
parents:
50671
diff
changeset
|
631 |
| 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
|
632 |
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
|
633 |
| 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
|
634 |
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
|
635 |
| 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
|
636 |
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
|
637 |
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
|
638 |
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
|
639 |
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
|
640 |
in chain_proof end |
49883 | 641 |
|
49914 | 642 |
type isar_params = |
51879 | 643 |
bool * bool * Time.time option * bool * real * string Symtab.table |
52150
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
644 |
* (string * stature) list vector * (string * term) list * int Symtab.table |
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
645 |
* string proof * thm |
49914 | 646 |
|
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
647 |
fun isar_proof_text ctxt isar_proofs |
51879 | 648 |
(debug, verbose, preplay_timeout, preplay_trace, isar_compress, pool, |
52150
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
649 |
fact_names, lifted, sym_tab, atp_proof, goal) |
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
650 |
(one_line_params as (_, _, _, _, subgoal, subgoal_count)) = |
49883 | 651 |
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
|
652 |
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
|
653 |
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
|
654 |
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
|
655 |
|> 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
|
656 |
|> (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
|
657 |
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
|
658 |
|> Proof_Context.add_fixes fixes) |
49883 | 659 |
val one_line_proof = one_line_proof_text 0 one_line_params |
660 |
val type_enc = |
|
661 |
if is_typed_helper_used_in_atp_proof atp_proof then full_typesN |
|
662 |
else partial_typesN |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51998
diff
changeset
|
663 |
val lam_trans = lam_trans_of_atp_proof atp_proof metis_default_lam_trans |
50557 | 664 |
val preplay = preplay_timeout <> SOME Time.zeroTime |
49883 | 665 |
|
666 |
fun isar_proof_of () = |
|
667 |
let |
|
668 |
val atp_proof = |
|
669 |
atp_proof |
|
670 |
|> clean_up_atp_proof_dependencies |
|
671 |
|> nasty_atp_proof pool |
|
672 |
|> map_term_names_in_atp_proof repair_name |
|
52150
41c885784e04
handle lambda-lifted problems in Isar construction code
blanchet
parents:
52125
diff
changeset
|
673 |
|> map (decode_line ctxt lifted sym_tab) |
50905 | 674 |
|> repair_waldmeister_endgame |
49883 | 675 |
|> rpair [] |-> fold_rev (add_line fact_names) |
676 |
|> rpair [] |-> fold_rev add_nontrivial_line |
|
677 |
|> rpair (0, []) |
|
52125
ac7830871177
improved handling of free variables' types in Isar proofs
blanchet
parents:
52077
diff
changeset
|
678 |
|-> fold_rev (add_desired_line fact_names) |
49883 | 679 |
|> snd |
680 |
val conj_name = conjecture_prefix ^ string_of_int (length hyp_ts) |
|
681 |
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
|
682 |
atp_proof |> map_filter |
51201 | 683 |
(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
|
684 |
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
|
685 |
| _ => 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
|
686 |
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
|
687 |
atp_proof |> map_filter |
51201 | 688 |
(fn (name as (_, ss), _, _, _, []) => |
50013
cceec179bdca
use original formulas for hypotheses and conclusion to avoid mismatches
blanchet
parents:
50012
diff
changeset
|
689 |
(case resolve_conjecture ss of |
cceec179bdca
use original formulas for hypotheses and conclusion to avoid mismatches
blanchet
parents:
50012
diff
changeset
|
690 |
[j] => |
cceec179bdca
use original formulas for hypotheses and conclusion to avoid mismatches
blanchet
parents:
50012
diff
changeset
|
691 |
if j = length hyp_ts then NONE |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
692 |
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
|
693 |
| _ => 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
|
694 |
| _ => NONE) |
51212
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
695 |
val bot = atp_proof |> List.last |> #1 |
51145 | 696 |
val refute_graph = |
51212
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
697 |
atp_proof |
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
698 |
|> map (fn (name, _, _, _, from) => (from, name)) |
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
699 |
|> make_refute_graph bot |
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
700 |
|> fold (Atom_Graph.default_node o rpair ()) conjs |
51145 | 701 |
val axioms = axioms_of_refute_graph refute_graph conjs |
702 |
val tainted = tainted_atoms_of_refute_graph refute_graph conjs |
|
51156 | 703 |
val is_clause_tainted = exists (member (op =) tainted) |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
704 |
val steps = |
49883 | 705 |
Symtab.empty |
51201 | 706 |
|> fold (fn (name as (s, _), role, t, rule, _) => |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
707 |
Symtab.update_new (s, (rule, |
51156 | 708 |
t |> (if is_clause_tainted [name] then |
50905 | 709 |
s_maybe_not role |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
710 |
#> fold exists_of (map Var (Term.add_vars t [])) |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
711 |
else |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
712 |
I)))) |
49883 | 713 |
atp_proof |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
714 |
fun is_clause_skolemize_rule [(s, _)] = |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
715 |
Option.map (is_skolemize_rule o fst) (Symtab.lookup steps s) = |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
716 |
SOME true |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
717 |
| is_clause_skolemize_rule _ = false |
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
718 |
(* The assumptions and conjecture are "prop"s; the other formulas are |
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
719 |
"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
|
720 |
fun prop_of_clause [(s, ss)] = |
50016 | 721 |
(case resolve_conjecture ss of |
722 |
[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
|
723 |
| _ => the_default ("", @{term False}) (Symtab.lookup steps s) |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
724 |
|> snd |> HOLogic.mk_Trueprop |> close_form) |
50016 | 725 |
| prop_of_clause names = |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
726 |
let |
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
727 |
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
|
728 |
in |
50018
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
729 |
case List.partition (can HOLogic.dest_not) lits of |
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
730 |
(negs as _ :: _, pos as _ :: _) => |
51212
2bbcc9cc12b4
ensure all conjecture clauses are in the graph -- to prevent exceptions later
blanchet
parents:
51208
diff
changeset
|
731 |
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
|
732 |
Library.foldr1 s_disj pos) |
50018
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
733 |
| _ => fold (curry s_disj) lits @{term False} |
4ea26c74d7ea
use implications rather than disjunctions to improve readability
blanchet
parents:
50017
diff
changeset
|
734 |
end |
50016 | 735 |
|> 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
|
736 |
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
|
737 |
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
|
738 |
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
|
739 |
(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
|
740 |
? 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
|
741 |
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
|
742 |
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
|
743 |
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
|
744 |
fun do_steps outer predecessor accum [] = |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
745 |
accum |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
746 |
|> (if tainted = [] then |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
747 |
cons (Prove (if outer then [Show] else [], no_label, |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
748 |
concl_t, |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
749 |
By_Metis ([], ([the predecessor], [])))) |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
750 |
else |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
751 |
I) |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
752 |
|> 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
|
753 |
| do_steps outer _ accum (Have (gamma, c) :: infs) = |
50676
83b8a5a39709
generate "obtain" steps corresponding to skolemization inferences
blanchet
parents:
50675
diff
changeset
|
754 |
let |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
755 |
val l = label_of_clause c |
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
756 |
val t = prop_of_clause c |
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
757 |
val by = |
51178 | 758 |
By_Metis ([], |
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51998
diff
changeset
|
759 |
(fold (add_fact_of_dependencies fact_names) |
51178 | 760 |
gamma no_facts)) |
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
|
761 |
fun prove by = Prove (maybe_show outer c [], l, t, by) |
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
762 |
fun do_rest l step = |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
763 |
do_steps outer (SOME l) (step :: accum) infs |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
764 |
in |
51156 | 765 |
if is_clause_tainted c then |
51149 | 766 |
case gamma of |
767 |
[g] => |
|
51156 | 768 |
if is_clause_skolemize_rule g andalso |
769 |
is_clause_tainted g then |
|
51149 | 770 |
let |
51178 | 771 |
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
|
772 |
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
|
773 |
Assume [], rev accum) |
51149 | 774 |
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
|
775 |
do_steps outer (SOME l) |
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
|
776 |
[prove (By_Metis ([subproof], no_facts))] [] |
51149 | 777 |
end |
778 |
else |
|
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
|
779 |
do_rest l (prove by) |
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
|
780 |
| _ => do_rest l (prove by) |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
781 |
else |
51149 | 782 |
if is_clause_skolemize_rule c then |
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
|
783 |
do_rest l (Obtain ([], Fix (skolems_of t), l, t, by)) |
51149 | 784 |
else |
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
|
785 |
do_rest l (prove by) |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
786 |
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
|
787 |
| do_steps outer predecessor accum (Cases cases :: infs) = |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
788 |
let |
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
789 |
fun do_case (c, infs) = |
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
790 |
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
|
791 |
infs |
51148
2246a2e17f92
tuning -- refactoring in preparation for handling skolemization of conjecture
blanchet
parents:
51147
diff
changeset
|
792 |
val c = succedent_of_cases cases |
51178 | 793 |
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
|
794 |
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
|
795 |
val step = |
51976
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
796 |
Prove (maybe_show outer c [], l, t, |
e5303bd748f2
generate valid direct Isar proof also if the facts are contradictory
blanchet
parents:
51879
diff
changeset
|
797 |
By_Metis (map do_case cases, (the_list predecessor, []))) |
51149 | 798 |
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
|
799 |
do_steps outer (SOME l) (step :: accum) infs |
51149 | 800 |
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
|
801 |
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
|
802 |
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
|
803 |
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
|
804 |
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
|
805 |
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
|
806 |
|
51741 | 807 |
val clean_up_labels_in_proof = |
51165 | 808 |
chain_direct_proof |
809 |
#> kill_useless_labels_in_proof |
|
810 |
#> relabel_proof |
|
50924 | 811 |
val (isar_proof, (preplay_fail, preplay_time)) = |
51145 | 812 |
refute_graph |
51031
63d71b247323
more robustness in Isar proof reconstruction (cf. bug report by Ondrej)
blanchet
parents:
51026
diff
changeset
|
813 |
|> 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
|
814 |
|> isar_proof_of_direct_proof |
51130
76d68444cd59
renamed sledgehammer_shrink to sledgehammer_compress
smolkas
parents:
51129
diff
changeset
|
815 |
|> (if not preplay andalso isar_compress <= 1.0 then |
50677 | 816 |
rpair (false, (true, seconds 0.0)) |
50557 | 817 |
else |
51741 | 818 |
compress_and_preplay_proof debug ctxt type_enc lam_trans preplay |
51879 | 819 |
preplay_timeout preplay_trace |
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
|
820 |
(if isar_proofs = SOME true then isar_compress else 1000.0)) |
51741 | 821 |
|>> clean_up_labels_in_proof |
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
822 |
val isar_text = |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
823 |
string_of_proof ctxt type_enc lam_trans subgoal subgoal_count |
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51976
diff
changeset
|
824 |
isar_proof |
49883 | 825 |
in |
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
826 |
case isar_text of |
49883 | 827 |
"" => |
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
|
828 |
if isar_proofs = SOME true then |
50671 | 829 |
"\nNo structured proof available (proof too simple)." |
49883 | 830 |
else |
831 |
"" |
|
832 |
| _ => |
|
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
833 |
let |
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
834 |
val msg = |
51203 | 835 |
(if verbose then |
836 |
let |
|
837 |
val num_steps = add_metis_steps (steps_of_proof isar_proof) 0 |
|
838 |
in [string_of_int num_steps ^ " step" ^ plural_s num_steps] end |
|
839 |
else |
|
840 |
[]) @ |
|
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
841 |
(if preplay then |
50924 | 842 |
[(if preplay_fail then "may fail, " else "") ^ |
843 |
Sledgehammer_Preplay.string_of_preplay_time preplay_time] |
|
50670
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
844 |
else |
eaa540986291
properly take the existential closure of skolems
blanchet
parents:
50557
diff
changeset
|
845 |
[]) |
50277 | 846 |
in |
51741 | 847 |
"\n\nStructured proof" |
848 |
^ (commas msg |> not (null msg) ? enclose " (" ")") |
|
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50410
diff
changeset
|
849 |
^ ":\n" ^ Active.sendback_markup isar_text |
50277 | 850 |
end |
49883 | 851 |
end |
852 |
val isar_proof = |
|
853 |
if debug then |
|
854 |
isar_proof_of () |
|
855 |
else case try isar_proof_of () of |
|
856 |
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
|
857 |
| NONE => if isar_proofs = SOME true then |
49883 | 858 |
"\nWarning: The Isar proof construction failed." |
859 |
else |
|
860 |
"" |
|
861 |
in one_line_proof ^ isar_proof end |
|
862 |
||
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
|
863 |
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
|
864 |
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
|
865 |
Played (reconstr, _) => reconstr = SMT |
51215
9ee38fc0bc81
generate Isar proof if Metis appears to be too slow
blanchet
parents:
51212
diff
changeset
|
866 |
| 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
|
867 |
| 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
|
868 |
|
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
869 |
fun proof_text ctxt isar_proofs isar_params num_chained |
49883 | 870 |
(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
|
871 |
(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
|
872 |
(isar_proofs = NONE andalso isar_proof_would_be_a_good_idea preplay) then |
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49917
diff
changeset
|
873 |
isar_proof_text ctxt isar_proofs isar_params |
49883 | 874 |
else |
875 |
one_line_proof_text num_chained) one_line_params |
|
876 |
||
877 |
end; |