320 |> Logic.dest_equals |> snd |
319 |> Logic.dest_equals |> snd |
321 | NONE => t) |
320 | NONE => t) |
322 | aux t = t |
321 | aux t = t |
323 in aux end |
322 in aux end |
324 |
323 |
325 fun decode_line sym_tab (Inference_Step (name, role, u, rule, deps)) ctxt = |
324 fun decode_line sym_tab (name, role, u, rule, deps) ctxt = |
326 let |
325 let |
327 val thy = Proof_Context.theory_of ctxt |
326 val thy = Proof_Context.theory_of ctxt |
328 val t = u |> prop_from_atp ctxt true sym_tab |
327 val t = u |> prop_from_atp ctxt true sym_tab |
329 |> uncombine_term thy |> infer_formula_types ctxt |
328 |> uncombine_term thy |> infer_formula_types ctxt |
330 in |
329 in |
331 (Inference_Step (name, role, t, rule, deps), |
330 ((name, role, t, rule, deps), |
332 fold Variable.declare_term (Misc_Legacy.term_frees t) ctxt) |
331 fold Variable.declare_term (Misc_Legacy.term_frees t) ctxt) |
333 end |
332 end |
334 fun decode_lines ctxt sym_tab lines = |
333 fun decode_lines ctxt sym_tab lines = |
335 fst (fold_map (decode_line sym_tab) lines ctxt) |
334 fst (fold_map (decode_line sym_tab) lines ctxt) |
336 |
335 |
337 fun replace_one_dependency (old, new) dep = |
336 fun replace_one_dependency (old, new) dep = |
338 if is_same_atp_step dep old then new else [dep] |
337 if is_same_atp_step dep old then new else [dep] |
339 fun replace_dependencies_in_line p |
338 fun replace_dependencies_in_line p (name, role, t, rule, deps) = |
340 (Inference_Step (name, role, t, rule, deps)) = |
339 (name, role, t, rule, fold (union (op =) o replace_one_dependency p) deps []) |
341 Inference_Step (name, role, t, rule, |
|
342 fold (union (op =) o replace_one_dependency p) deps []) |
|
343 |
340 |
344 (* No "real" literals means only type information (tfree_tcs, clsrel, or |
341 (* No "real" literals means only type information (tfree_tcs, clsrel, or |
345 clsarity). *) |
342 clsarity). *) |
346 fun is_only_type_information t = t aconv @{term True} |
343 fun is_only_type_information t = t aconv @{term True} |
347 |
344 |
348 fun s_maybe_not role = role <> Conjecture ? s_not |
345 fun s_maybe_not role = role <> Conjecture ? s_not |
349 |
346 |
350 fun is_same_inference (role, t) (Inference_Step (_, role', t', _, _)) = |
347 fun is_same_inference (role, t) (_, role', t', _, _) = |
351 s_maybe_not role t aconv s_maybe_not role' t' |
348 s_maybe_not role t aconv s_maybe_not role' t' |
352 |
349 |
353 (* Discard facts; consolidate adjacent lines that prove the same formula, since |
350 (* Discard facts; consolidate adjacent lines that prove the same formula, since |
354 they differ only in type information.*) |
351 they differ only in type information.*) |
355 fun add_line fact_names (Inference_Step (name as (_, ss), role, t, rule, [])) |
352 fun add_line fact_names (name as (_, ss), role, t, rule, []) lines = |
356 lines = |
|
357 (* No dependencies: fact, conjecture, or (for Vampire) internal facts or |
353 (* No dependencies: fact, conjecture, or (for Vampire) internal facts or |
358 definitions. *) |
354 definitions. *) |
359 if is_conjecture ss then |
355 if is_conjecture ss then |
360 Inference_Step (name, role, t, rule, []) :: lines |
356 (name, role, t, rule, []) :: lines |
361 else if is_fact fact_names ss then |
357 else if is_fact fact_names ss then |
362 (* Facts are not proof lines. *) |
358 (* Facts are not proof lines. *) |
363 if is_only_type_information t then |
359 if is_only_type_information t then |
364 map (replace_dependencies_in_line (name, [])) lines |
360 map (replace_dependencies_in_line (name, [])) lines |
365 else |
361 else |
366 lines |
362 lines |
367 else |
363 else |
368 map (replace_dependencies_in_line (name, [])) lines |
364 map (replace_dependencies_in_line (name, [])) lines |
369 | add_line _ (line as Inference_Step (name, role, t, _, _)) lines = |
365 | add_line _ (line as (name, role, t, _, _)) lines = |
370 (* Type information will be deleted later; skip repetition test. *) |
366 (* Type information will be deleted later; skip repetition test. *) |
371 if is_only_type_information t then |
367 if is_only_type_information t then |
372 line :: lines |
368 line :: lines |
373 (* Is there a repetition? If so, replace later line by earlier one. *) |
369 (* Is there a repetition? If so, replace later line by earlier one. *) |
374 else case take_prefix (not o is_same_inference (role, t)) lines of |
370 else case take_prefix (not o is_same_inference (role, t)) lines of |
375 (_, []) => line :: lines |
371 (_, []) => line :: lines |
376 | (pre, Inference_Step (name', _, _, _, _) :: post) => |
372 | (pre, (name', _, _, _, _) :: post) => |
377 line :: pre @ map (replace_dependencies_in_line (name', [name])) post |
373 line :: pre @ map (replace_dependencies_in_line (name', [name])) post |
378 |
374 |
379 val waldmeister_conjecture_num = "1.0.0.0" |
375 val waldmeister_conjecture_num = "1.0.0.0" |
380 |
376 |
381 val repair_waldmeister_endgame = |
377 val repair_waldmeister_endgame = |
382 let |
378 let |
383 fun do_tail (Inference_Step (name, _, t, rule, deps)) = |
379 fun do_tail (name, _, t, rule, deps) = |
384 Inference_Step (name, Negated_Conjecture, s_not t, rule, deps) |
380 (name, Negated_Conjecture, s_not t, rule, deps) |
385 fun do_body [] = [] |
381 fun do_body [] = [] |
386 | do_body ((line as Inference_Step ((num, _), _, _, _, _)) :: lines) = |
382 | do_body ((line as ((num, _), _, _, _, _)) :: lines) = |
387 if num = waldmeister_conjecture_num then map do_tail (line :: lines) |
383 if num = waldmeister_conjecture_num then map do_tail (line :: lines) |
388 else line :: do_body lines |
384 else line :: do_body lines |
389 in do_body end |
385 in do_body end |
390 |
386 |
391 (* Recursively delete empty lines (type information) from the proof. *) |
387 (* Recursively delete empty lines (type information) from the proof. *) |
392 fun add_nontrivial_line (line as Inference_Step (name, _, t, _, [])) lines = |
388 fun add_nontrivial_line (line as (name, _, t, _, [])) lines = |
393 if is_only_type_information t then delete_dependency name lines |
389 if is_only_type_information t then delete_dependency name lines |
394 else line :: lines |
390 else line :: lines |
395 | add_nontrivial_line line lines = line :: lines |
391 | add_nontrivial_line line lines = line :: lines |
396 and delete_dependency name lines = |
392 and delete_dependency name lines = |
397 fold_rev add_nontrivial_line |
393 fold_rev add_nontrivial_line |
667 |-> fold_rev (add_desired_line fact_names frees) |
663 |-> fold_rev (add_desired_line fact_names frees) |
668 |> snd |
664 |> snd |
669 val conj_name = conjecture_prefix ^ string_of_int (length hyp_ts) |
665 val conj_name = conjecture_prefix ^ string_of_int (length hyp_ts) |
670 val conjs = |
666 val conjs = |
671 atp_proof |> map_filter |
667 atp_proof |> map_filter |
672 (fn Inference_Step (name as (_, ss), _, _, _, []) => |
668 (fn (name as (_, ss), _, _, _, []) => |
673 if member (op =) ss conj_name then SOME name else NONE |
669 if member (op =) ss conj_name then SOME name else NONE |
674 | _ => NONE) |
670 | _ => NONE) |
675 val assms = |
671 val assms = |
676 atp_proof |> map_filter |
672 atp_proof |> map_filter |
677 (fn Inference_Step (name as (_, ss), _, _, _, []) => |
673 (fn (name as (_, ss), _, _, _, []) => |
678 (case resolve_conjecture ss of |
674 (case resolve_conjecture ss of |
679 [j] => |
675 [j] => |
680 if j = length hyp_ts then NONE |
676 if j = length hyp_ts then NONE |
681 else SOME (raw_label_for_name name, nth hyp_ts j) |
677 else SOME (raw_label_for_name name, nth hyp_ts j) |
682 | _ => NONE) |
678 | _ => NONE) |
683 | _ => NONE) |
679 | _ => NONE) |
684 fun dep_of_step (Inference_Step (name, _, _, _, from)) = |
680 fun dep_of_step (name, _, _, _, from) = SOME (from, name) |
685 SOME (from, name) |
|
686 val refute_graph = |
681 val refute_graph = |
687 atp_proof |> map_filter dep_of_step |> make_refute_graph |
682 atp_proof |> map_filter dep_of_step |> make_refute_graph |
688 val axioms = axioms_of_refute_graph refute_graph conjs |
683 val axioms = axioms_of_refute_graph refute_graph conjs |
689 val tainted = tainted_atoms_of_refute_graph refute_graph conjs |
684 val tainted = tainted_atoms_of_refute_graph refute_graph conjs |
690 val is_clause_tainted = exists (member (op =) tainted) |
685 val is_clause_tainted = exists (member (op =) tainted) |
691 val bot = atp_proof |> List.last |> dep_of_step |> the |> snd |
686 val bot = atp_proof |> List.last |> dep_of_step |> the |> snd |
692 val steps = |
687 val steps = |
693 Symtab.empty |
688 Symtab.empty |
694 |> fold (fn Inference_Step (name as (s, _), role, t, rule, _) => |
689 |> fold (fn (name as (s, _), role, t, rule, _) => |
695 Symtab.update_new (s, (rule, |
690 Symtab.update_new (s, (rule, |
696 t |> (if is_clause_tainted [name] then |
691 t |> (if is_clause_tainted [name] then |
697 s_maybe_not role |
692 s_maybe_not role |
698 #> fold exists_of (map Var (Term.add_vars t [])) |
693 #> fold exists_of (map Var (Term.add_vars t [])) |
699 else |
694 else |