author | blanchet |
Thu, 16 Sep 2010 11:59:45 +0200 | |
changeset 39453 | 1740a2d6bef9 |
parent 39452 | 70a57e40f795 |
child 39454 | acb25e9cf6fb |
permissions | -rw-r--r-- |
38988 | 1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_reconstruct.ML |
38027 | 2 |
Author: Lawrence C. Paulson, Cambridge University Computer Laboratory |
3 |
Author: Claire Quigley, Cambridge University Computer Laboratory |
|
36392 | 4 |
Author: Jasmin Blanchette, TU Muenchen |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
5 |
|
33310 | 6 |
Transfer of proofs from external provers. |
7 |
*) |
|
8 |
||
38988 | 9 |
signature SLEDGEHAMMER_RECONSTRUCT = |
24425
ca97c6f3d9cd
Returning both a "one-line" proof and a structured proof
paulson
parents:
24387
diff
changeset
|
10 |
sig |
38988 | 11 |
type locality = Sledgehammer_Filter.locality |
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36231
diff
changeset
|
12 |
type minimize_command = string list -> string |
38818
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
13 |
type metis_params = |
39327 | 14 |
string * bool * minimize_command * string * (string * locality) list vector |
15 |
* thm * int |
|
38818
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
16 |
type isar_params = |
38040
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
17 |
string Symtab.table * bool * int * Proof.context * int list list |
38818
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
18 |
type text_result = string * (string * locality) list |
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
19 |
|
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
20 |
val metis_proof_text : metis_params -> text_result |
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
21 |
val isar_proof_text : isar_params -> metis_params -> text_result |
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
22 |
val proof_text : bool -> isar_params -> metis_params -> text_result |
24425
ca97c6f3d9cd
Returning both a "one-line" proof and a structured proof
paulson
parents:
24387
diff
changeset
|
23 |
end; |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
24 |
|
38988 | 25 |
structure Sledgehammer_Reconstruct : SLEDGEHAMMER_RECONSTRUCT = |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
26 |
struct |
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
27 |
|
38028 | 28 |
open ATP_Problem |
39452 | 29 |
open ATP_Proof |
37578
9367cb36b1c4
renamed "Sledgehammer_FOL_Clauses" to "Metis_Clauses", so that Metis doesn't depend on Sledgehammer
blanchet
parents:
37577
diff
changeset
|
30 |
open Metis_Clauses |
36478
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
31 |
open Sledgehammer_Util |
38988 | 32 |
open Sledgehammer_Filter |
38282
319c59682c51
move Sledgehammer's HOL -> FOL translation to separate file (sledgehammer_translate.ML)
blanchet
parents:
38105
diff
changeset
|
33 |
open Sledgehammer_Translate |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
34 |
|
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36231
diff
changeset
|
35 |
type minimize_command = string list -> string |
38818
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
36 |
type metis_params = |
39327 | 37 |
string * bool * minimize_command * string * (string * locality) list vector |
38 |
* thm * int |
|
38818
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
39 |
type isar_params = |
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
40 |
string Symtab.table * bool * int * Proof.context * int list list |
61cf050f8b2e
improve SPASS hack, when a clause comes from several facts
blanchet
parents:
38752
diff
changeset
|
41 |
type text_result = string * (string * locality) list |
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36231
diff
changeset
|
42 |
|
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
43 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
44 |
(** Soft-core proof reconstruction: Metis one-liner **) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
45 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
46 |
fun string_for_label (s, num) = s ^ string_of_int num |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
47 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
48 |
fun metis_using [] = "" |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
49 |
| metis_using ls = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
50 |
"using " ^ space_implode " " (map string_for_label ls) ^ " " |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
51 |
fun metis_apply _ 1 = "by " |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
52 |
| metis_apply 1 _ = "apply " |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
53 |
| metis_apply i _ = "prefer " ^ string_of_int i ^ " apply " |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
54 |
fun metis_name full_types = if full_types then "metisFT" else "metis" |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
55 |
fun metis_call full_types [] = metis_name full_types |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
56 |
| metis_call full_types ss = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
57 |
"(" ^ metis_name full_types ^ " " ^ space_implode " " ss ^ ")" |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
58 |
fun metis_command full_types i n (ls, ss) = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
59 |
metis_using ls ^ metis_apply i n ^ metis_call full_types ss |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
60 |
fun metis_line banner full_types i n ss = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
61 |
banner ^ ": " ^ |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
62 |
Markup.markup Markup.sendback (metis_command full_types i n ([], ss)) ^ "." |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
63 |
fun minimize_line _ [] = "" |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
64 |
| minimize_line minimize_command ss = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
65 |
case minimize_command ss of |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
66 |
"" => "" |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
67 |
| command => |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
68 |
"\nTo minimize the number of lemmas, try this: " ^ |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
69 |
Markup.markup Markup.sendback command ^ "." |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
70 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
71 |
fun resolve_axiom axiom_names (Str (_, s)) = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
72 |
(case strip_prefix_and_unascii axiom_prefix s of |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
73 |
SOME s' => (case find_first_in_list_vector axiom_names s' of |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
74 |
SOME x => [(s', x)] |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
75 |
| NONE => []) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
76 |
| NONE => []) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
77 |
| resolve_axiom axiom_names (Num num) = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
78 |
case Int.fromString num of |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
79 |
SOME j => |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
80 |
if j > 0 andalso j <= Vector.length axiom_names then |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
81 |
Vector.sub (axiom_names, j - 1) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
82 |
else |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
83 |
[] |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
84 |
| NONE => [] |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
85 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
86 |
fun add_fact axiom_names (Inference (name, _, [])) = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
87 |
append (resolve_axiom axiom_names name) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
88 |
| add_fact _ _ = I |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
89 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
90 |
fun used_facts_in_tstplike_proof axiom_names = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
91 |
atp_proof_from_tstplike_string Symtab.empty |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
92 |
#> rpair [] #-> fold (add_fact axiom_names) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
93 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
94 |
fun used_facts axiom_names = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
95 |
used_facts_in_tstplike_proof axiom_names |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
96 |
#> List.partition (curry (op =) Chained o snd) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
97 |
#> pairself (sort_distinct (string_ord o pairself fst)) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
98 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
99 |
fun metis_proof_text (banner, full_types, minimize_command, |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
100 |
tstplike_proof, axiom_names, goal, i) = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
101 |
let |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
102 |
val (chained_lemmas, other_lemmas) = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
103 |
used_facts axiom_names tstplike_proof |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
104 |
val n = Logic.count_prems (prop_of goal) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
105 |
in |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
106 |
(metis_line banner full_types i n (map fst other_lemmas) ^ |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
107 |
minimize_line minimize_command (map fst (other_lemmas @ chained_lemmas)), |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
108 |
other_lemmas @ chained_lemmas) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
109 |
end |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
110 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
111 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
112 |
(** Hard-core proof reconstruction: structured Isar proofs **) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
113 |
|
38014 | 114 |
(* Simple simplifications to ensure that sort annotations don't leave a trail of |
115 |
spurious "True"s. *) |
|
116 |
fun s_not @{const False} = @{const True} |
|
117 |
| s_not @{const True} = @{const False} |
|
118 |
| s_not (@{const Not} $ t) = t |
|
119 |
| s_not t = @{const Not} $ t |
|
120 |
fun s_conj (@{const True}, t2) = t2 |
|
121 |
| s_conj (t1, @{const True}) = t1 |
|
122 |
| s_conj p = HOLogic.mk_conj p |
|
123 |
fun s_disj (@{const False}, t2) = t2 |
|
124 |
| s_disj (t1, @{const False}) = t1 |
|
125 |
| s_disj p = HOLogic.mk_disj p |
|
126 |
fun s_imp (@{const True}, t2) = t2 |
|
127 |
| s_imp (t1, @{const False}) = s_not t1 |
|
128 |
| s_imp p = HOLogic.mk_imp p |
|
129 |
fun s_iff (@{const True}, t2) = t2 |
|
130 |
| s_iff (t1, @{const True}) = t1 |
|
131 |
| s_iff (t1, t2) = HOLogic.eq_const HOLogic.boolT $ t1 $ t2 |
|
132 |
||
39425 | 133 |
fun forall_of v t = HOLogic.all_const (fastype_of v) $ lambda v t |
134 |
fun exists_of v t = HOLogic.exists_const (fastype_of v) $ lambda v t |
|
135 |
||
39452 | 136 |
fun negate_term (Const (@{const_name All}, T) $ Abs (s, T', t')) = |
137 |
Const (@{const_name Ex}, T) $ Abs (s, T', negate_term t') |
|
138 |
| negate_term (Const (@{const_name Ex}, T) $ Abs (s, T', t')) = |
|
139 |
Const (@{const_name All}, T) $ Abs (s, T', negate_term t') |
|
140 |
| negate_term (@{const HOL.implies} $ t1 $ t2) = |
|
141 |
@{const HOL.conj} $ t1 $ negate_term t2 |
|
142 |
| negate_term (@{const HOL.conj} $ t1 $ t2) = |
|
143 |
@{const HOL.disj} $ negate_term t1 $ negate_term t2 |
|
144 |
| negate_term (@{const HOL.disj} $ t1 $ t2) = |
|
145 |
@{const HOL.conj} $ negate_term t1 $ negate_term t2 |
|
146 |
| negate_term (@{const Not} $ t) = t |
|
147 |
| negate_term t = @{const Not} $ t |
|
39368 | 148 |
|
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
149 |
val indent_size = 2 |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
150 |
val no_label = ("", ~1) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
151 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
152 |
val raw_prefix = "X" |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
153 |
val assum_prefix = "A" |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
154 |
val fact_prefix = "F" |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
155 |
|
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
156 |
fun resolve_conjecture conjecture_shape (Str (num, s)) = |
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
157 |
let |
39373 | 158 |
val k = case try (unprefix conjecture_prefix) s of |
159 |
SOME s => Int.fromString s |> the_default ~1 |
|
160 |
| NONE => case Int.fromString num of |
|
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
161 |
SOME j => find_index (exists (curry (op =) j)) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
162 |
conjecture_shape |
39373 | 163 |
| NONE => ~1 |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
164 |
in if k >= 0 then [k] else [] end |
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
165 |
| resolve_conjecture conjecture_shape (Num num) = |
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
166 |
resolve_conjecture conjecture_shape (Str (num, "")) (* HACK *) |
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
167 |
|
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
168 |
val is_axiom = not o null oo resolve_axiom |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
169 |
val is_conjecture = not o null oo resolve_conjecture |
36291
b4c2043cc96c
added Isar proof reconstruction support for SPASS -- which means all provers can now yield Isar proofs;
blanchet
parents:
36288
diff
changeset
|
170 |
|
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
171 |
fun raw_label_for_name conjecture_shape name = |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
172 |
case resolve_conjecture conjecture_shape name of |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
173 |
[j] => (conjecture_prefix, j) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
174 |
| _ => case Int.fromString (step_num name) of |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
175 |
SOME j => (raw_prefix, j) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
176 |
| NONE => (raw_prefix ^ step_num name, 0) |
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
177 |
|
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
178 |
(**** INTERPRETATION OF TSTP SYNTAX TREES ****) |
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
179 |
|
37991 | 180 |
exception FO_TERM of string fo_term list |
37994
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37991
diff
changeset
|
181 |
exception FORMULA of (string, string fo_term) formula list |
37991 | 182 |
exception SAME of unit |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
183 |
|
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
184 |
(* Type variables are given the basic sort "HOL.type". Some will later be |
37991 | 185 |
constrained by information from type literals, or by type inference. *) |
186 |
fun type_from_fo_term tfrees (u as ATerm (a, us)) = |
|
187 |
let val Ts = map (type_from_fo_term tfrees) us in |
|
38748 | 188 |
case strip_prefix_and_unascii type_const_prefix a of |
37991 | 189 |
SOME b => Type (invert_const b, Ts) |
190 |
| NONE => |
|
191 |
if not (null us) then |
|
192 |
raise FO_TERM [u] (* only "tconst"s have type arguments *) |
|
38748 | 193 |
else case strip_prefix_and_unascii tfree_prefix a of |
37991 | 194 |
SOME b => |
195 |
let val s = "'" ^ b in |
|
196 |
TFree (s, AList.lookup (op =) tfrees s |> the_default HOLogic.typeS) |
|
197 |
end |
|
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
198 |
| NONE => |
38748 | 199 |
case strip_prefix_and_unascii tvar_prefix a of |
37991 | 200 |
SOME b => TVar (("'" ^ b, 0), HOLogic.typeS) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
201 |
| NONE => |
37991 | 202 |
(* Variable from the ATP, say "X1" *) |
203 |
Type_Infer.param 0 (a, HOLogic.typeS) |
|
204 |
end |
|
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
205 |
|
38014 | 206 |
(* Type class literal applied to a type. Returns triple of polarity, class, |
207 |
type. *) |
|
208 |
fun type_constraint_from_term pos tfrees (u as ATerm (a, us)) = |
|
38748 | 209 |
case (strip_prefix_and_unascii class_prefix a, |
38014 | 210 |
map (type_from_fo_term tfrees) us) of |
211 |
(SOME b, [T]) => (pos, b, T) |
|
212 |
| _ => raise FO_TERM [u] |
|
213 |
||
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38066
diff
changeset
|
214 |
(** Accumulate type constraints in a formula: negative type literals **) |
38014 | 215 |
fun add_var (key, z) = Vartab.map_default (key, []) (cons z) |
216 |
fun add_type_constraint (false, cl, TFree (a ,_)) = add_var ((a, ~1), cl) |
|
217 |
| add_type_constraint (false, cl, TVar (ix, _)) = add_var (ix, cl) |
|
218 |
| add_type_constraint _ = I |
|
219 |
||
38490 | 220 |
fun repair_atp_variable_name f s = |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
221 |
let |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
222 |
fun subscript_name s n = s ^ nat_subscript n |
38488 | 223 |
val s = String.map f s |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
224 |
in |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
225 |
case space_explode "_" s of |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
226 |
[_] => (case take_suffix Char.isDigit (String.explode s) of |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
227 |
(cs1 as _ :: _, cs2 as _ :: _) => |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
228 |
subscript_name (String.implode cs1) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
229 |
(the (Int.fromString (String.implode cs2))) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
230 |
| (_, _) => s) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
231 |
| [s1, s2] => (case Int.fromString s2 of |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
232 |
SOME n => subscript_name s1 n |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
233 |
| NONE => s) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
234 |
| _ => s |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
235 |
end |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
236 |
|
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
237 |
(* First-order translation. No types are known for variables. "HOLogic.typeT" |
38014 | 238 |
should allow them to be inferred. *) |
239 |
fun raw_term_from_pred thy full_types tfrees = |
|
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
240 |
let |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37624
diff
changeset
|
241 |
fun aux opt_T extra_us u = |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
242 |
case u of |
37991 | 243 |
ATerm ("hBOOL", [u1]) => aux (SOME @{typ bool}) [] u1 |
244 |
| ATerm ("hAPP", [u1, u2]) => aux opt_T (u2 :: extra_us) u1 |
|
245 |
| ATerm (a, us) => |
|
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
246 |
if a = type_wrapper_name then |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
247 |
case us of |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37624
diff
changeset
|
248 |
[typ_u, term_u] => |
37991 | 249 |
aux (SOME (type_from_fo_term tfrees typ_u)) extra_us term_u |
250 |
| _ => raise FO_TERM us |
|
38748 | 251 |
else case strip_prefix_and_unascii const_prefix a of |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
252 |
SOME "equal" => |
39106 | 253 |
let val ts = map (aux NONE []) us in |
254 |
if length ts = 2 andalso hd ts aconv List.last ts then |
|
255 |
(* Vampire is keen on producing these. *) |
|
256 |
@{const True} |
|
257 |
else |
|
258 |
list_comb (Const (@{const_name HOL.eq}, HOLogic.typeT), ts) |
|
259 |
end |
|
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
260 |
| SOME b => |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
261 |
let |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
262 |
val c = invert_const b |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
263 |
val num_type_args = num_type_args thy c |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37624
diff
changeset
|
264 |
val (type_us, term_us) = |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37624
diff
changeset
|
265 |
chop (if full_types then 0 else num_type_args) us |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37624
diff
changeset
|
266 |
(* Extra args from "hAPP" come after any arguments given directly to |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37624
diff
changeset
|
267 |
the constant. *) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37624
diff
changeset
|
268 |
val term_ts = map (aux NONE []) term_us |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37624
diff
changeset
|
269 |
val extra_ts = map (aux NONE []) extra_us |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
270 |
val t = |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
271 |
Const (c, if full_types then |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
272 |
case opt_T of |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37624
diff
changeset
|
273 |
SOME T => map fastype_of term_ts ---> T |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
274 |
| NONE => |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
275 |
if num_type_args = 0 then |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
276 |
Sign.const_instance thy (c, []) |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
277 |
else |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
278 |
raise Fail ("no type information for " ^ quote c) |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
279 |
else |
37998 | 280 |
Sign.const_instance thy (c, |
281 |
map (type_from_fo_term tfrees) type_us)) |
|
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37624
diff
changeset
|
282 |
in list_comb (t, term_ts @ extra_ts) end |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
283 |
| NONE => (* a free or schematic variable *) |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
284 |
let |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37624
diff
changeset
|
285 |
val ts = map (aux NONE []) (us @ extra_us) |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
286 |
val T = map fastype_of ts ---> HOLogic.typeT |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
287 |
val t = |
38748 | 288 |
case strip_prefix_and_unascii fixed_var_prefix a of |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
289 |
SOME b => Free (b, T) |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
290 |
| NONE => |
38748 | 291 |
case strip_prefix_and_unascii schematic_var_prefix a of |
36967
3c804030474b
fix bug in Isar proof reconstruction step relabeling + don't try to infer the sorts of TVars, since this often fails miserably
blanchet
parents:
36924
diff
changeset
|
292 |
SOME b => Var ((b, 0), T) |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
293 |
| NONE => |
39452 | 294 |
if is_atp_variable a then |
38490 | 295 |
Var ((repair_atp_variable_name Char.toLower a, 0), T) |
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38015
diff
changeset
|
296 |
else |
38488 | 297 |
(* Skolem constants? *) |
38490 | 298 |
Var ((repair_atp_variable_name Char.toUpper a, 0), T) |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
299 |
in list_comb (t, ts) end |
38014 | 300 |
in aux (SOME HOLogic.boolT) [] end |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
301 |
|
38014 | 302 |
fun term_from_pred thy full_types tfrees pos (u as ATerm (s, _)) = |
303 |
if String.isPrefix class_prefix s then |
|
304 |
add_type_constraint (type_constraint_from_term pos tfrees u) |
|
305 |
#> pair @{const True} |
|
306 |
else |
|
307 |
pair (raw_term_from_pred thy full_types tfrees u) |
|
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
308 |
|
36555
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
309 |
val combinator_table = |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
310 |
[(@{const_name COMBI}, @{thm COMBI_def_raw}), |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
311 |
(@{const_name COMBK}, @{thm COMBK_def_raw}), |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
312 |
(@{const_name COMBB}, @{thm COMBB_def_raw}), |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
313 |
(@{const_name COMBC}, @{thm COMBC_def_raw}), |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
314 |
(@{const_name COMBS}, @{thm COMBS_def_raw})] |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
315 |
|
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
316 |
fun uncombine_term (t1 $ t2) = betapply (pairself uncombine_term (t1, t2)) |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
317 |
| uncombine_term (Abs (s, T, t')) = Abs (s, T, uncombine_term t') |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
318 |
| uncombine_term (t as Const (x as (s, _))) = |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
319 |
(case AList.lookup (op =) combinator_table s of |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
320 |
SOME thm => thm |> prop_of |> specialize_type @{theory} x |> Logic.dest_equals |> snd |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
321 |
| NONE => t) |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
322 |
| uncombine_term t = t |
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
323 |
|
37991 | 324 |
(* Update schematic type variables with detected sort constraints. It's not |
325 |
totally clear when this code is necessary. *) |
|
38014 | 326 |
fun repair_tvar_sorts (t, tvar_tab) = |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
327 |
let |
37991 | 328 |
fun do_type (Type (a, Ts)) = Type (a, map do_type Ts) |
329 |
| do_type (TVar (xi, s)) = |
|
330 |
TVar (xi, the_default s (Vartab.lookup tvar_tab xi)) |
|
331 |
| do_type (TFree z) = TFree z |
|
332 |
fun do_term (Const (a, T)) = Const (a, do_type T) |
|
333 |
| do_term (Free (a, T)) = Free (a, do_type T) |
|
334 |
| do_term (Var (xi, T)) = Var (xi, do_type T) |
|
335 |
| do_term (t as Bound _) = t |
|
336 |
| do_term (Abs (a, T, t)) = Abs (a, do_type T, do_term t) |
|
337 |
| do_term (t1 $ t2) = do_term t1 $ do_term t2 |
|
338 |
in t |> not (Vartab.is_empty tvar_tab) ? do_term end |
|
339 |
||
39425 | 340 |
fun quantify_over_var quant_of var_s t = |
341 |
let |
|
342 |
val vars = [] |> Term.add_vars t |> filter (fn ((s, _), _) => s = var_s) |
|
343 |
|> map Var |
|
344 |
in fold_rev quant_of vars t end |
|
37991 | 345 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38066
diff
changeset
|
346 |
(* Interpret an ATP formula as a HOL term, extracting sort constraints as they |
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38066
diff
changeset
|
347 |
appear in the formula. *) |
38014 | 348 |
fun prop_from_formula thy full_types tfrees phi = |
349 |
let |
|
350 |
fun do_formula pos phi = |
|
37991 | 351 |
case phi of |
38014 | 352 |
AQuant (_, [], phi) => do_formula pos phi |
37991 | 353 |
| AQuant (q, x :: xs, phi') => |
38014 | 354 |
do_formula pos (AQuant (q, xs, phi')) |
39425 | 355 |
#>> quantify_over_var (case q of |
356 |
AForall => forall_of |
|
357 |
| AExists => exists_of) |
|
358 |
(repair_atp_variable_name Char.toLower x) |
|
38014 | 359 |
| AConn (ANot, [phi']) => do_formula (not pos) phi' #>> s_not |
37991 | 360 |
| AConn (c, [phi1, phi2]) => |
38014 | 361 |
do_formula (pos |> c = AImplies ? not) phi1 |
362 |
##>> do_formula pos phi2 |
|
363 |
#>> (case c of |
|
364 |
AAnd => s_conj |
|
365 |
| AOr => s_disj |
|
366 |
| AImplies => s_imp |
|
38038 | 367 |
| AIf => s_imp o swap |
368 |
| AIff => s_iff |
|
369 |
| ANotIff => s_not o s_iff) |
|
38034 | 370 |
| AAtom tm => term_from_pred thy full_types tfrees pos tm |
37991 | 371 |
| _ => raise FORMULA [phi] |
38014 | 372 |
in repair_tvar_sorts (do_formula true phi Vartab.empty) end |
37991 | 373 |
|
36556
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
374 |
fun check_formula ctxt = |
39288 | 375 |
Type.constraint HOLogic.boolT |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
376 |
#> Syntax.check_term (ProofContext.set_mode ProofContext.mode_schematic ctxt) |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
377 |
|
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
378 |
|
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
379 |
(**** Translation of TSTP files to Isar Proofs ****) |
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
380 |
|
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
381 |
fun unvarify_term (Var ((s, 0), T)) = Free (s, T) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
382 |
| unvarify_term t = raise TERM ("unvarify_term: non-Var", [t]) |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
383 |
|
39368 | 384 |
fun decode_line full_types tfrees (Definition (name, phi1, phi2)) ctxt = |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
385 |
let |
37991 | 386 |
val thy = ProofContext.theory_of ctxt |
387 |
val t1 = prop_from_formula thy full_types tfrees phi1 |
|
36551 | 388 |
val vars = snd (strip_comb t1) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
389 |
val frees = map unvarify_term vars |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
390 |
val unvarify_args = subst_atomic (vars ~~ frees) |
37991 | 391 |
val t2 = prop_from_formula thy full_types tfrees phi2 |
36551 | 392 |
val (t1, t2) = |
393 |
HOLogic.eq_const HOLogic.typeT $ t1 $ t2 |
|
36556
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
394 |
|> unvarify_args |> uncombine_term |> check_formula ctxt |
36555
8ff45c2076da
expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents:
36551
diff
changeset
|
395 |
|> HOLogic.dest_eq |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
396 |
in |
39368 | 397 |
(Definition (name, t1, t2), |
36551 | 398 |
fold Variable.declare_term (maps OldTerm.term_frees [t1, t2]) ctxt) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
399 |
end |
39368 | 400 |
| decode_line full_types tfrees (Inference (name, u, deps)) ctxt = |
36551 | 401 |
let |
37991 | 402 |
val thy = ProofContext.theory_of ctxt |
403 |
val t = u |> prop_from_formula thy full_types tfrees |
|
37998 | 404 |
|> uncombine_term |> check_formula ctxt |
36551 | 405 |
in |
39368 | 406 |
(Inference (name, t, deps), |
36551 | 407 |
fold Variable.declare_term (OldTerm.term_frees t) ctxt) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
408 |
end |
36967
3c804030474b
fix bug in Isar proof reconstruction step relabeling + don't try to infer the sorts of TVars, since this often fails miserably
blanchet
parents:
36924
diff
changeset
|
409 |
fun decode_lines ctxt full_types tfrees lines = |
3c804030474b
fix bug in Isar proof reconstruction step relabeling + don't try to infer the sorts of TVars, since this often fails miserably
blanchet
parents:
36924
diff
changeset
|
410 |
fst (fold_map (decode_line full_types tfrees) lines ctxt) |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
411 |
|
38035 | 412 |
fun is_same_inference _ (Definition _) = false |
413 |
| is_same_inference t (Inference (_, t', _)) = t aconv t' |
|
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
414 |
|
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
415 |
(* No "real" literals means only type information (tfree_tcs, clsrel, or |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
416 |
clsarity). *) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
417 |
val is_only_type_information = curry (op aconv) HOLogic.true_const |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
418 |
|
39373 | 419 |
fun replace_one_dependency (old, new) dep = |
39452 | 420 |
if is_same_step (dep, old) then new else [dep] |
39373 | 421 |
fun replace_dependencies_in_line _ (line as Definition _) = line |
422 |
| replace_dependencies_in_line p (Inference (name, t, deps)) = |
|
423 |
Inference (name, t, fold (union (op =) o replace_one_dependency p) deps []) |
|
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
424 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38066
diff
changeset
|
425 |
(* Discard axioms; consolidate adjacent lines that prove the same formula, since |
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38066
diff
changeset
|
426 |
they differ only in type information.*) |
36551 | 427 |
fun add_line _ _ (line as Definition _) lines = line :: lines |
39368 | 428 |
| add_line conjecture_shape axiom_names (Inference (name, t, [])) lines = |
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38066
diff
changeset
|
429 |
(* No dependencies: axiom, conjecture, or (for Vampire) internal axioms or |
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38066
diff
changeset
|
430 |
definitions. *) |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
431 |
if is_axiom axiom_names name then |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
432 |
(* Axioms are not proof lines. *) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
433 |
if is_only_type_information t then |
39373 | 434 |
map (replace_dependencies_in_line (name, [])) lines |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
435 |
(* Is there a repetition? If so, replace later line by earlier one. *) |
38035 | 436 |
else case take_prefix (not o is_same_inference t) lines of |
39373 | 437 |
(_, []) => lines (* no repetition of proof line *) |
39368 | 438 |
| (pre, Inference (name', _, _) :: post) => |
39373 | 439 |
pre @ map (replace_dependencies_in_line (name', [name])) post |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
440 |
else if is_conjecture conjecture_shape name then |
39368 | 441 |
Inference (name, negate_term t, []) :: lines |
36551 | 442 |
else |
39373 | 443 |
map (replace_dependencies_in_line (name, [])) lines |
39368 | 444 |
| add_line _ _ (Inference (name, t, deps)) lines = |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
445 |
(* Type information will be deleted later; skip repetition test. *) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
446 |
if is_only_type_information t then |
39368 | 447 |
Inference (name, t, deps) :: lines |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
448 |
(* Is there a repetition? If so, replace later line by earlier one. *) |
38035 | 449 |
else case take_prefix (not o is_same_inference t) lines of |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
450 |
(* FIXME: Doesn't this code risk conflating proofs involving different |
38035 | 451 |
types? *) |
39368 | 452 |
(_, []) => Inference (name, t, deps) :: lines |
453 |
| (pre, Inference (name', t', _) :: post) => |
|
454 |
Inference (name, t', deps) :: |
|
39373 | 455 |
pre @ map (replace_dependencies_in_line (name', [name])) post |
22044
6c0702a96076
More compact proof reconstruction: lines having fewer than !min_deps dependences are folded
paulson
parents:
22012
diff
changeset
|
456 |
|
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
457 |
(* Recursively delete empty lines (type information) from the proof. *) |
39368 | 458 |
fun add_nontrivial_line (Inference (name, t, [])) lines = |
39373 | 459 |
if is_only_type_information t then delete_dependency name lines |
39368 | 460 |
else Inference (name, t, []) :: lines |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
461 |
| add_nontrivial_line line lines = line :: lines |
39373 | 462 |
and delete_dependency name lines = |
463 |
fold_rev add_nontrivial_line |
|
464 |
(map (replace_dependencies_in_line (name, [])) lines) [] |
|
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
465 |
|
37323 | 466 |
(* ATPs sometimes reuse free variable names in the strangest ways. Removing |
467 |
offending lines often does the trick. *) |
|
36560
45c1870f234f
fixed definition of "bad frees" so that it actually works
blanchet
parents:
36559
diff
changeset
|
468 |
fun is_bad_free frees (Free x) = not (member (op =) frees x) |
45c1870f234f
fixed definition of "bad frees" so that it actually works
blanchet
parents:
36559
diff
changeset
|
469 |
| is_bad_free _ _ = false |
22470
0d52e5157124
No label on "show"; tries to remove dependencies more cleanly
paulson
parents:
22428
diff
changeset
|
470 |
|
39368 | 471 |
fun add_desired_line _ _ _ _ (line as Definition (name, _, _)) (j, lines) = |
39373 | 472 |
(j, line :: map (replace_dependencies_in_line (name, [])) lines) |
38282
319c59682c51
move Sledgehammer's HOL -> FOL translation to separate file (sledgehammer_translate.ML)
blanchet
parents:
38105
diff
changeset
|
473 |
| add_desired_line isar_shrink_factor conjecture_shape axiom_names frees |
39368 | 474 |
(Inference (name, t, deps)) (j, lines) = |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
475 |
(j + 1, |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
476 |
if is_axiom axiom_names name orelse |
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
477 |
is_conjecture conjecture_shape name orelse |
39373 | 478 |
(* the last line must be kept *) |
479 |
j = 0 orelse |
|
36570
9bebcb40599f
identify axioms/conjectures more reliably in ATP proofs (an empty dependency list doesn't always indicate an axiom or conjecture!)
blanchet
parents:
36567
diff
changeset
|
480 |
(not (is_only_type_information t) andalso |
9bebcb40599f
identify axioms/conjectures more reliably in ATP proofs (an empty dependency list doesn't always indicate an axiom or conjecture!)
blanchet
parents:
36567
diff
changeset
|
481 |
null (Term.add_tvars t []) andalso |
9bebcb40599f
identify axioms/conjectures more reliably in ATP proofs (an empty dependency list doesn't always indicate an axiom or conjecture!)
blanchet
parents:
36567
diff
changeset
|
482 |
not (exists_subterm (is_bad_free frees) t) andalso |
39373 | 483 |
length deps >= 2 andalso j mod isar_shrink_factor = 0 andalso |
484 |
(* kill next to last line, which usually results in a trivial step *) |
|
485 |
j <> 1) then |
|
39368 | 486 |
Inference (name, t, deps) :: lines (* keep line *) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
487 |
else |
39373 | 488 |
map (replace_dependencies_in_line (name, deps)) lines) (* drop line *) |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
489 |
|
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
490 |
(** Isar proof construction and manipulation **) |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
491 |
|
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
492 |
fun merge_fact_sets (ls1, ss1) (ls2, ss2) = |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
493 |
(union (op =) ls1 ls2, union (op =) ss1 ss2) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
494 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
495 |
type label = string * int |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
496 |
type facts = label list * string list |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
497 |
|
39452 | 498 |
datatype isar_qualifier = Show | Then | Moreover | Ultimately |
36291
b4c2043cc96c
added Isar proof reconstruction support for SPASS -- which means all provers can now yield Isar proofs;
blanchet
parents:
36288
diff
changeset
|
499 |
|
39452 | 500 |
datatype isar_step = |
36478
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
501 |
Fix of (string * typ) list | |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
502 |
Let of term * term | |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
503 |
Assume of label * term | |
39452 | 504 |
Have of isar_qualifier list * label * term * byline |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
505 |
and byline = |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
506 |
ByMetis of facts | |
39452 | 507 |
CaseSplit of isar_step list list * facts |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
508 |
|
36574 | 509 |
fun smart_case_split [] facts = ByMetis facts |
510 |
| smart_case_split proofs facts = CaseSplit (proofs, facts) |
|
511 |
||
39373 | 512 |
fun add_fact_from_dependency conjecture_shape axiom_names name = |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
513 |
if is_axiom axiom_names name then |
39368 | 514 |
apsnd (union (op =) (map fst (resolve_axiom axiom_names name))) |
36475
05209b869a6b
new Isar proof construction code: stringfy axiom names correctly
blanchet
parents:
36474
diff
changeset
|
515 |
else |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
516 |
apfst (insert (op =) (raw_label_for_name conjecture_shape name)) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
517 |
|
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
518 |
fun step_for_line _ _ _ (Definition (_, t1, t2)) = Let (t1, t2) |
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
519 |
| step_for_line conjecture_shape _ _ (Inference (name, t, [])) = |
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
520 |
Assume (raw_label_for_name conjecture_shape name, t) |
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
521 |
| step_for_line conjecture_shape axiom_names j (Inference (name, t, deps)) = |
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
522 |
Have (if j = 1 then [Show] else [], |
39425 | 523 |
raw_label_for_name conjecture_shape name, |
524 |
fold_rev forall_of (map Var (Term.add_vars t [])) t, |
|
39373 | 525 |
ByMetis (fold (add_fact_from_dependency conjecture_shape axiom_names) |
526 |
deps ([], []))) |
|
36291
b4c2043cc96c
added Isar proof reconstruction support for SPASS -- which means all provers can now yield Isar proofs;
blanchet
parents:
36288
diff
changeset
|
527 |
|
39452 | 528 |
fun isar_proof_from_tstplike_proof pool ctxt full_types tfrees isar_shrink_factor |
529 |
tstplike_proof conjecture_shape axiom_names params frees = |
|
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
530 |
let |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
531 |
val lines = |
39452 | 532 |
tstplike_proof |
533 |
|> atp_proof_from_tstplike_string pool |
|
36967
3c804030474b
fix bug in Isar proof reconstruction step relabeling + don't try to infer the sorts of TVars, since this often fails miserably
blanchet
parents:
36924
diff
changeset
|
534 |
|> decode_lines ctxt full_types tfrees |
38282
319c59682c51
move Sledgehammer's HOL -> FOL translation to separate file (sledgehammer_translate.ML)
blanchet
parents:
38105
diff
changeset
|
535 |
|> rpair [] |-> fold_rev (add_line conjecture_shape axiom_names) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
536 |
|> rpair [] |-> fold_rev add_nontrivial_line |
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
537 |
|> rpair (0, []) |-> fold_rev (add_desired_line isar_shrink_factor |
38282
319c59682c51
move Sledgehammer's HOL -> FOL translation to separate file (sledgehammer_translate.ML)
blanchet
parents:
38105
diff
changeset
|
538 |
conjecture_shape axiom_names frees) |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
539 |
|> snd |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
540 |
in |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
541 |
(if null params then [] else [Fix params]) @ |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
542 |
map2 (step_for_line conjecture_shape axiom_names) (length lines downto 1) |
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
543 |
lines |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
544 |
end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
545 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
546 |
(* When redirecting proofs, we keep information about the labels seen so far in |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
547 |
the "backpatches" data structure. The first component indicates which facts |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
548 |
should be associated with forthcoming proof steps. The second component is a |
37322
0347b1a16682
fix bug in direct Isar proofs, which was exhibited by the "BigO" example
blanchet
parents:
37319
diff
changeset
|
549 |
pair ("assum_ls", "drop_ls"), where "assum_ls" are the labels that should |
0347b1a16682
fix bug in direct Isar proofs, which was exhibited by the "BigO" example
blanchet
parents:
37319
diff
changeset
|
550 |
become assumptions and "drop_ls" are the labels that should be dropped in a |
0347b1a16682
fix bug in direct Isar proofs, which was exhibited by the "BigO" example
blanchet
parents:
37319
diff
changeset
|
551 |
case split. *) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
552 |
type backpatches = (label * facts) list * (label list * label list) |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
553 |
|
36556
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
554 |
fun used_labels_of_step (Have (_, _, _, by)) = |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
555 |
(case by of |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
556 |
ByMetis (ls, _) => ls |
36556
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
557 |
| CaseSplit (proofs, (ls, _)) => |
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
558 |
fold (union (op =) o used_labels_of) proofs ls) |
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
559 |
| used_labels_of_step _ = [] |
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
560 |
and used_labels_of proof = fold (union (op =) o used_labels_of_step) proof [] |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
561 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
562 |
fun new_labels_of_step (Fix _) = [] |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
563 |
| new_labels_of_step (Let _) = [] |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
564 |
| new_labels_of_step (Assume (l, _)) = [l] |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
565 |
| new_labels_of_step (Have (_, l, _, _)) = [l] |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
566 |
val new_labels_of = maps new_labels_of_step |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
567 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
568 |
val join_proofs = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
569 |
let |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
570 |
fun aux _ [] = NONE |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
571 |
| aux proof_tail (proofs as (proof1 :: _)) = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
572 |
if exists null proofs then |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
573 |
NONE |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
574 |
else if forall (curry (op =) (hd proof1) o hd) (tl proofs) then |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
575 |
aux (hd proof1 :: proof_tail) (map tl proofs) |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
576 |
else case hd proof1 of |
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
577 |
Have ([], l, t, _) => (* FIXME: should we really ignore the "by"? *) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
578 |
if forall (fn Have ([], l', t', _) :: _ => (l, t) = (l', t') |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
579 |
| _ => false) (tl proofs) andalso |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
580 |
not (exists (member (op =) (maps new_labels_of proofs)) |
36556
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
581 |
(used_labels_of proof_tail)) then |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
582 |
SOME (l, t, map rev proofs, proof_tail) |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
583 |
else |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
584 |
NONE |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
585 |
| _ => NONE |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
586 |
in aux [] o map rev end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
587 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
588 |
fun case_split_qualifiers proofs = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
589 |
case length proofs of |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
590 |
0 => [] |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
591 |
| 1 => [Then] |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
592 |
| _ => [Ultimately] |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
593 |
|
39372
2fd8a9a7080d
first step in generalizing to nonnumeric proof step names (e.g. remote Vampire 0.6)
blanchet
parents:
39370
diff
changeset
|
594 |
fun redirect_proof hyp_ts concl_t proof = |
33310 | 595 |
let |
37324
d77250dd2416
fix bugs in Sledgehammer's Isar proof "redirection" code
blanchet
parents:
37323
diff
changeset
|
596 |
(* The first pass outputs those steps that are independent of the negated |
d77250dd2416
fix bugs in Sledgehammer's Isar proof "redirection" code
blanchet
parents:
37323
diff
changeset
|
597 |
conjecture. The second pass flips the proof by contradiction to obtain a |
d77250dd2416
fix bugs in Sledgehammer's Isar proof "redirection" code
blanchet
parents:
37323
diff
changeset
|
598 |
direct proof, introducing case splits when an inference depends on |
d77250dd2416
fix bugs in Sledgehammer's Isar proof "redirection" code
blanchet
parents:
37323
diff
changeset
|
599 |
several facts that depend on the negated conjecture. *) |
39372
2fd8a9a7080d
first step in generalizing to nonnumeric proof step names (e.g. remote Vampire 0.6)
blanchet
parents:
39370
diff
changeset
|
600 |
val concl_l = (conjecture_prefix, length hyp_ts) |
38040
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
601 |
fun first_pass ([], contra) = ([], contra) |
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
602 |
| first_pass ((step as Fix _) :: proof, contra) = |
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
603 |
first_pass (proof, contra) |>> cons step |
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
604 |
| first_pass ((step as Let _) :: proof, contra) = |
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
605 |
first_pass (proof, contra) |>> cons step |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
606 |
| first_pass ((step as Assume (l as (_, j), _)) :: proof, contra) = |
39372
2fd8a9a7080d
first step in generalizing to nonnumeric proof step names (e.g. remote Vampire 0.6)
blanchet
parents:
39370
diff
changeset
|
607 |
if l = concl_l then first_pass (proof, contra ||> cons step) |
2fd8a9a7080d
first step in generalizing to nonnumeric proof step names (e.g. remote Vampire 0.6)
blanchet
parents:
39370
diff
changeset
|
608 |
else first_pass (proof, contra) |>> cons (Assume (l, nth hyp_ts j)) |
38040
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
609 |
| first_pass (Have (qs, l, t, ByMetis (ls, ss)) :: proof, contra) = |
39372
2fd8a9a7080d
first step in generalizing to nonnumeric proof step names (e.g. remote Vampire 0.6)
blanchet
parents:
39370
diff
changeset
|
610 |
let val step = Have (qs, l, t, ByMetis (ls, ss)) in |
38040
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
611 |
if exists (member (op =) (fst contra)) ls then |
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
612 |
first_pass (proof, contra |>> cons l ||> cons step) |
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
613 |
else |
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
614 |
first_pass (proof, contra) |>> cons step |
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
615 |
end |
174568533593
fix bug in the SPASS Flotter hack, when a conjecture FOF is translated to several CNF clauses
blanchet
parents:
38039
diff
changeset
|
616 |
| first_pass _ = raise Fail "malformed proof" |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
617 |
val (proof_top, (contra_ls, contra_proof)) = |
39372
2fd8a9a7080d
first step in generalizing to nonnumeric proof step names (e.g. remote Vampire 0.6)
blanchet
parents:
39370
diff
changeset
|
618 |
first_pass (proof, ([concl_l], [])) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
619 |
val backpatch_label = the_default ([], []) oo AList.lookup (op =) o fst |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
620 |
fun backpatch_labels patches ls = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
621 |
fold merge_fact_sets (map (backpatch_label patches) ls) ([], []) |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
622 |
fun second_pass end_qs ([], assums, patches) = |
37324
d77250dd2416
fix bugs in Sledgehammer's Isar proof "redirection" code
blanchet
parents:
37323
diff
changeset
|
623 |
([Have (end_qs, no_label, concl_t, |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
624 |
ByMetis (backpatch_labels patches (map snd assums)))], patches) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
625 |
| second_pass end_qs (Assume (l, t) :: proof, assums, patches) = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
626 |
second_pass end_qs (proof, (t, l) :: assums, patches) |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
627 |
| second_pass end_qs (Have (qs, l, t, ByMetis (ls, ss)) :: proof, assums, |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
628 |
patches) = |
39373 | 629 |
(if member (op =) (snd (snd patches)) l andalso |
630 |
not (member (op =) (fst (snd patches)) l) andalso |
|
631 |
not (AList.defined (op =) (fst patches) l) then |
|
632 |
second_pass end_qs (proof, assums, patches ||> apsnd (append ls)) |
|
633 |
else case List.partition (member (op =) contra_ls) ls of |
|
634 |
([contra_l], co_ls) => |
|
635 |
if member (op =) qs Show then |
|
636 |
second_pass end_qs (proof, assums, |
|
637 |
patches |>> cons (contra_l, (co_ls, ss))) |
|
638 |
else |
|
639 |
second_pass end_qs |
|
640 |
(proof, assums, |
|
641 |
patches |>> cons (contra_l, (l :: co_ls, ss))) |
|
642 |
|>> cons (if member (op =) (fst (snd patches)) l then |
|
643 |
Assume (l, negate_term t) |
|
644 |
else |
|
645 |
Have (qs, l, negate_term t, |
|
646 |
ByMetis (backpatch_label patches l))) |
|
647 |
| (contra_ls as _ :: _, co_ls) => |
|
648 |
let |
|
649 |
val proofs = |
|
650 |
map_filter |
|
651 |
(fn l => |
|
652 |
if l = concl_l then |
|
653 |
NONE |
|
654 |
else |
|
655 |
let |
|
656 |
val drop_ls = filter (curry (op <>) l) contra_ls |
|
657 |
in |
|
658 |
second_pass [] |
|
659 |
(proof, assums, |
|
660 |
patches ||> apfst (insert (op =) l) |
|
661 |
||> apsnd (union (op =) drop_ls)) |
|
662 |
|> fst |> SOME |
|
663 |
end) contra_ls |
|
664 |
val (assumes, facts) = |
|
665 |
if member (op =) (fst (snd patches)) l then |
|
666 |
([Assume (l, negate_term t)], (l :: co_ls, ss)) |
|
667 |
else |
|
668 |
([], (co_ls, ss)) |
|
669 |
in |
|
670 |
(case join_proofs proofs of |
|
671 |
SOME (l, t, proofs, proof_tail) => |
|
672 |
Have (case_split_qualifiers proofs @ |
|
673 |
(if null proof_tail then end_qs else []), l, t, |
|
674 |
smart_case_split proofs facts) :: proof_tail |
|
675 |
| NONE => |
|
676 |
[Have (case_split_qualifiers proofs @ end_qs, no_label, |
|
677 |
concl_t, smart_case_split proofs facts)], |
|
678 |
patches) |
|
679 |
|>> append assumes |
|
680 |
end |
|
681 |
| _ => raise Fail "malformed proof") |
|
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
682 |
| second_pass _ _ = raise Fail "malformed proof" |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
683 |
val proof_bottom = |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
684 |
second_pass [Show] (contra_proof, [], ([], ([], []))) |> fst |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
685 |
in proof_top @ proof_bottom end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
686 |
|
38490 | 687 |
(* FIXME: Still needed? Probably not. *) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
688 |
val kill_duplicate_assumptions_in_proof = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
689 |
let |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
690 |
fun relabel_facts subst = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
691 |
apfst (map (fn l => AList.lookup (op =) subst l |> the_default l)) |
36491
6769f8eacaac
unskolemize formulas in proof reconstruction + detect newer SPASS versions to avoid truncating identifiers if not necessary (truncating confuses proof reconstruction)
blanchet
parents:
36488
diff
changeset
|
692 |
fun do_step (step as Assume (l, t)) (proof, subst, assums) = |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
693 |
(case AList.lookup (op aconv) assums t of |
36967
3c804030474b
fix bug in Isar proof reconstruction step relabeling + don't try to infer the sorts of TVars, since this often fails miserably
blanchet
parents:
36924
diff
changeset
|
694 |
SOME l' => (proof, (l, l') :: subst, assums) |
36491
6769f8eacaac
unskolemize formulas in proof reconstruction + detect newer SPASS versions to avoid truncating identifiers if not necessary (truncating confuses proof reconstruction)
blanchet
parents:
36488
diff
changeset
|
695 |
| NONE => (step :: proof, subst, (t, l) :: assums)) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
696 |
| do_step (Have (qs, l, t, by)) (proof, subst, assums) = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
697 |
(Have (qs, l, t, |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
698 |
case by of |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
699 |
ByMetis facts => ByMetis (relabel_facts subst facts) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
700 |
| CaseSplit (proofs, facts) => |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
701 |
CaseSplit (map do_proof proofs, relabel_facts subst facts)) :: |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
702 |
proof, subst, assums) |
36491
6769f8eacaac
unskolemize formulas in proof reconstruction + detect newer SPASS versions to avoid truncating identifiers if not necessary (truncating confuses proof reconstruction)
blanchet
parents:
36488
diff
changeset
|
703 |
| do_step step (proof, subst, assums) = (step :: proof, subst, assums) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
704 |
and do_proof proof = fold do_step proof ([], [], []) |> #1 |> rev |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
705 |
in do_proof end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
706 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
707 |
val then_chain_proof = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
708 |
let |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
709 |
fun aux _ [] = [] |
36491
6769f8eacaac
unskolemize formulas in proof reconstruction + detect newer SPASS versions to avoid truncating identifiers if not necessary (truncating confuses proof reconstruction)
blanchet
parents:
36488
diff
changeset
|
710 |
| aux _ ((step as Assume (l, _)) :: proof) = step :: aux l proof |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
711 |
| aux l' (Have (qs, l, t, by) :: proof) = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
712 |
(case by of |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
713 |
ByMetis (ls, ss) => |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
714 |
Have (if member (op =) ls l' then |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
715 |
(Then :: qs, l, t, |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
716 |
ByMetis (filter_out (curry (op =) l') ls, ss)) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
717 |
else |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
718 |
(qs, l, t, ByMetis (ls, ss))) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
719 |
| CaseSplit (proofs, facts) => |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
720 |
Have (qs, l, t, CaseSplit (map (aux no_label) proofs, facts))) :: |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
721 |
aux l proof |
36491
6769f8eacaac
unskolemize formulas in proof reconstruction + detect newer SPASS versions to avoid truncating identifiers if not necessary (truncating confuses proof reconstruction)
blanchet
parents:
36488
diff
changeset
|
722 |
| aux _ (step :: proof) = step :: aux no_label proof |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
723 |
in aux no_label end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
724 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
725 |
fun kill_useless_labels_in_proof proof = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
726 |
let |
36556
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
727 |
val used_ls = used_labels_of proof |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
728 |
fun do_label l = if member (op =) used_ls l then l else no_label |
36556
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
729 |
fun do_step (Assume (l, t)) = Assume (do_label l, t) |
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
730 |
| do_step (Have (qs, l, t, by)) = |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
731 |
Have (qs, do_label l, t, |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
732 |
case by of |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
733 |
CaseSplit (proofs, facts) => |
36556
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
734 |
CaseSplit (map (map do_step) proofs, facts) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
735 |
| _ => by) |
36556
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
736 |
| do_step step = step |
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36555
diff
changeset
|
737 |
in map do_step proof end |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
738 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
739 |
fun prefix_for_depth n = replicate_string (n + 1) |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
740 |
|
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
741 |
val relabel_proof = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
742 |
let |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
743 |
fun aux _ _ _ [] = [] |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
744 |
| aux subst depth (next_assum, next_fact) (Assume (l, t) :: proof) = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
745 |
if l = no_label then |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
746 |
Assume (l, t) :: aux subst depth (next_assum, next_fact) proof |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
747 |
else |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
748 |
let val l' = (prefix_for_depth depth assum_prefix, next_assum) in |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
749 |
Assume (l', t) :: |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
750 |
aux ((l, l') :: subst) depth (next_assum + 1, next_fact) proof |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
751 |
end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
752 |
| aux subst depth (next_assum, next_fact) (Have (qs, l, t, by) :: proof) = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
753 |
let |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
754 |
val (l', subst, next_fact) = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
755 |
if l = no_label then |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
756 |
(l, subst, next_fact) |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
757 |
else |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
758 |
let |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
759 |
val l' = (prefix_for_depth depth fact_prefix, next_fact) |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
760 |
in (l', (l, l') :: subst, next_fact + 1) end |
36570
9bebcb40599f
identify axioms/conjectures more reliably in ATP proofs (an empty dependency list doesn't always indicate an axiom or conjecture!)
blanchet
parents:
36567
diff
changeset
|
761 |
val relabel_facts = |
39370
f8292d3020db
use same hack as in "Async_Manager" to work around Proof General bug
blanchet
parents:
39368
diff
changeset
|
762 |
apfst (maps (the_list o AList.lookup (op =) subst)) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
763 |
val by = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
764 |
case by of |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
765 |
ByMetis facts => ByMetis (relabel_facts facts) |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
766 |
| CaseSplit (proofs, facts) => |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
767 |
CaseSplit (map (aux subst (depth + 1) (1, 1)) proofs, |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
768 |
relabel_facts facts) |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
769 |
in |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
770 |
Have (qs, l', t, by) :: |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
771 |
aux subst depth (next_assum, next_fact) proof |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
772 |
end |
36491
6769f8eacaac
unskolemize formulas in proof reconstruction + detect newer SPASS versions to avoid truncating identifiers if not necessary (truncating confuses proof reconstruction)
blanchet
parents:
36488
diff
changeset
|
773 |
| aux subst depth nextp (step :: proof) = |
6769f8eacaac
unskolemize formulas in proof reconstruction + detect newer SPASS versions to avoid truncating identifiers if not necessary (truncating confuses proof reconstruction)
blanchet
parents:
36488
diff
changeset
|
774 |
step :: aux subst depth nextp proof |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
775 |
in aux [] 0 (1, 1) end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
776 |
|
39115
a00da1674c1c
turned show_no_free_types into proper configuration option show_free_types, with flipped polarity;
wenzelm
parents:
39106
diff
changeset
|
777 |
fun string_for_proof ctxt0 full_types i n = |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
778 |
let |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39115
diff
changeset
|
779 |
val ctxt = ctxt0 |
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39115
diff
changeset
|
780 |
|> Config.put show_free_types false |
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39115
diff
changeset
|
781 |
|> Config.put show_types true |
37319
42268dc7d6c4
show types in Isar proofs, but not for free variables;
blanchet
parents:
37172
diff
changeset
|
782 |
fun fix_print_mode f x = |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39115
diff
changeset
|
783 |
Print_Mode.setmp (filter (curry (op =) Symbol.xsymbolsN) |
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39115
diff
changeset
|
784 |
(print_mode_value ())) f x |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
785 |
fun do_indent ind = replicate_string (ind * indent_size) " " |
36478
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
786 |
fun do_free (s, T) = |
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
787 |
maybe_quote s ^ " :: " ^ |
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
788 |
maybe_quote (fix_print_mode (Syntax.string_of_typ ctxt) T) |
36570
9bebcb40599f
identify axioms/conjectures more reliably in ATP proofs (an empty dependency list doesn't always indicate an axiom or conjecture!)
blanchet
parents:
36567
diff
changeset
|
789 |
fun do_label l = if l = no_label then "" else string_for_label l ^ ": " |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
790 |
fun do_have qs = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
791 |
(if member (op =) qs Moreover then "moreover " else "") ^ |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
792 |
(if member (op =) qs Ultimately then "ultimately " else "") ^ |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
793 |
(if member (op =) qs Then then |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
794 |
if member (op =) qs Show then "thus" else "hence" |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
795 |
else |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
796 |
if member (op =) qs Show then "show" else "have") |
36478
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
797 |
val do_term = maybe_quote o fix_print_mode (Syntax.string_of_term ctxt) |
36570
9bebcb40599f
identify axioms/conjectures more reliably in ATP proofs (an empty dependency list doesn't always indicate an axiom or conjecture!)
blanchet
parents:
36567
diff
changeset
|
798 |
fun do_facts (ls, ss) = |
38698
d19c3a7ce38b
clean handling of whether a fact is chained or not;
blanchet
parents:
38696
diff
changeset
|
799 |
metis_command full_types 1 1 |
d19c3a7ce38b
clean handling of whether a fact is chained or not;
blanchet
parents:
38696
diff
changeset
|
800 |
(ls |> sort_distinct (prod_ord string_ord int_ord), |
d19c3a7ce38b
clean handling of whether a fact is chained or not;
blanchet
parents:
38696
diff
changeset
|
801 |
ss |> sort_distinct string_ord) |
36478
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
802 |
and do_step ind (Fix xs) = |
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
803 |
do_indent ind ^ "fix " ^ space_implode " and " (map do_free xs) ^ "\n" |
36486
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
804 |
| do_step ind (Let (t1, t2)) = |
c2d7e2dff59e
support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents:
36485
diff
changeset
|
805 |
do_indent ind ^ "let " ^ do_term t1 ^ " = " ^ do_term t2 ^ "\n" |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
806 |
| do_step ind (Assume (l, t)) = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
807 |
do_indent ind ^ "assume " ^ do_label l ^ do_term t ^ "\n" |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
808 |
| do_step ind (Have (qs, l, t, ByMetis facts)) = |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
809 |
do_indent ind ^ do_have qs ^ " " ^ |
36479 | 810 |
do_label l ^ do_term t ^ " " ^ do_facts facts ^ "\n" |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
811 |
| do_step ind (Have (qs, l, t, CaseSplit (proofs, facts))) = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
812 |
space_implode (do_indent ind ^ "moreover\n") |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
813 |
(map (do_block ind) proofs) ^ |
36479 | 814 |
do_indent ind ^ do_have qs ^ " " ^ do_label l ^ do_term t ^ " " ^ |
36478
1aba777a367f
fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents:
36477
diff
changeset
|
815 |
do_facts facts ^ "\n" |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
816 |
and do_steps prefix suffix ind steps = |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
817 |
let val s = implode (map (do_step ind) steps) in |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
818 |
replicate_string (ind * indent_size - size prefix) " " ^ prefix ^ |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
819 |
String.extract (s, ind * indent_size, |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
820 |
SOME (size s - ind * indent_size - 1)) ^ |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
821 |
suffix ^ "\n" |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
822 |
end |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
823 |
and do_block ind proof = do_steps "{ " " }" (ind + 1) proof |
36564
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
824 |
(* One-step proofs are pointless; better use the Metis one-liner |
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
825 |
directly. *) |
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
826 |
and do_proof [Have (_, _, _, ByMetis _)] = "" |
96f767f546e7
be more discriminate: some one-line Isar proofs are silly
blanchet
parents:
36563
diff
changeset
|
827 |
| do_proof proof = |
36480
1e01a7162435
polish Isar proofs: don't mention facts twice, and don't show one-liner "structured" proofs
blanchet
parents:
36479
diff
changeset
|
828 |
(if i <> 1 then "prefer " ^ string_of_int i ^ "\n" else "") ^ |
39452 | 829 |
do_indent 0 ^ "proof -\n" ^ do_steps "" "" 1 proof ^ do_indent 0 ^ |
830 |
(if n <> 1 then "next" else "qed") |
|
36488
32c92af68ec9
remove Sledgehammer's "sorts" option to annotate variables with sorts in proof;
blanchet
parents:
36486
diff
changeset
|
831 |
in do_proof end |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
832 |
|
37479
f6b1ee5b420b
try to improve Sledgehammer/Metis's behavior in full_types mode, e.g. by handing True, False, and If better
blanchet
parents:
37410
diff
changeset
|
833 |
fun isar_proof_text (pool, debug, isar_shrink_factor, ctxt, conjecture_shape) |
39452 | 834 |
(other_params as (_, full_types, _, tstplike_proof, |
835 |
axiom_names, goal, i)) = |
|
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
836 |
let |
36909
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
837 |
val (params, hyp_ts, concl_t) = strip_subgoal goal i |
7d5587f6d5f7
made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents:
36607
diff
changeset
|
838 |
val frees = fold Term.add_frees (concl_t :: hyp_ts) [] |
36967
3c804030474b
fix bug in Isar proof reconstruction step relabeling + don't try to infer the sorts of TVars, since this often fails miserably
blanchet
parents:
36924
diff
changeset
|
839 |
val tfrees = fold Term.add_tfrees (concl_t :: hyp_ts) [] |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
840 |
val n = Logic.count_prems (prop_of goal) |
37479
f6b1ee5b420b
try to improve Sledgehammer/Metis's behavior in full_types mode, e.g. by handing True, False, and If better
blanchet
parents:
37410
diff
changeset
|
841 |
val (one_line_proof, lemma_names) = metis_proof_text other_params |
36283
25e69e93954d
failure of reconstructing the Isar proof (e.g., exception) should not prevent Sledgehammer from showing the short one-liner proof -- but in "debug" mode we do want to know what the exception is
blanchet
parents:
36281
diff
changeset
|
842 |
fun isar_proof_for () = |
39452 | 843 |
case isar_proof_from_tstplike_proof pool ctxt full_types tfrees |
844 |
isar_shrink_factor tstplike_proof conjecture_shape axiom_names |
|
845 |
params frees |
|
39372
2fd8a9a7080d
first step in generalizing to nonnumeric proof step names (e.g. remote Vampire 0.6)
blanchet
parents:
39370
diff
changeset
|
846 |
|> redirect_proof hyp_ts concl_t |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
847 |
|> kill_duplicate_assumptions_in_proof |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
848 |
|> then_chain_proof |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
849 |
|> kill_useless_labels_in_proof |
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
850 |
|> relabel_proof |
37479
f6b1ee5b420b
try to improve Sledgehammer/Metis's behavior in full_types mode, e.g. by handing True, False, and If better
blanchet
parents:
37410
diff
changeset
|
851 |
|> string_for_proof ctxt full_types i n of |
38599 | 852 |
"" => "\nNo structured proof available." |
853 |
| proof => "\n\nStructured proof:\n" ^ Markup.markup Markup.sendback proof |
|
35868
491a97039ce1
renamed "e_full" and "vampire_full" to "e_isar" and "vampire_isar";
blanchet
parents:
35865
diff
changeset
|
854 |
val isar_proof = |
36402
1b20805974c7
introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents:
36396
diff
changeset
|
855 |
if debug then |
36283
25e69e93954d
failure of reconstructing the Isar proof (e.g., exception) should not prevent Sledgehammer from showing the short one-liner proof -- but in "debug" mode we do want to know what the exception is
blanchet
parents:
36281
diff
changeset
|
856 |
isar_proof_for () |
25e69e93954d
failure of reconstructing the Isar proof (e.g., exception) should not prevent Sledgehammer from showing the short one-liner proof -- but in "debug" mode we do want to know what the exception is
blanchet
parents:
36281
diff
changeset
|
857 |
else |
25e69e93954d
failure of reconstructing the Isar proof (e.g., exception) should not prevent Sledgehammer from showing the short one-liner proof -- but in "debug" mode we do want to know what the exception is
blanchet
parents:
36281
diff
changeset
|
858 |
try isar_proof_for () |
38599 | 859 |
|> the_default "\nWarning: The Isar proof construction failed." |
36283
25e69e93954d
failure of reconstructing the Isar proof (e.g., exception) should not prevent Sledgehammer from showing the short one-liner proof -- but in "debug" mode we do want to know what the exception is
blanchet
parents:
36281
diff
changeset
|
860 |
in (one_line_proof ^ isar_proof, lemma_names) end |
21978
72c21698a055
Contains old Tools/ATP/AtpCommunication.ML, plus proof reconstruction
paulson
parents:
diff
changeset
|
861 |
|
36557 | 862 |
fun proof_text isar_proof isar_params other_params = |
863 |
(if isar_proof then isar_proof_text isar_params else metis_proof_text) |
|
864 |
other_params |
|
36223
217ca1273786
make Sledgehammer's minimizer also minimize Isar proofs
blanchet
parents:
36140
diff
changeset
|
865 |
|
31038 | 866 |
end; |